Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.2 kB · 64 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import * as Effect from "effect/Effect";import * as Exit from "effect/Exit";import * as Option from "effect/Option";import { deploymentFailure, isDeploymentFailure, TemporarilyUnavailable, type DeploymentCode, type DeploymentFailure,} from "./deployment-errors.ts";import { domainErrorCode, type DomainErrorCode, type DomainFailure,} from "./domain-errors.ts";import type { RegistryFailure } from "./installation-errors.ts";
// Only declared codes cross native Workflow persistence/retry boundaries.// Provider bodies, RPC causes and credentials never become Workflow history.export async function runDeploymentEffect<A>( program: Effect.Effect<A, DeploymentFailure | RegistryFailure>,): Promise<A> { const exit = await Effect.runPromiseExit(program); if (Exit.isSuccess(exit)) return exit.value; const error = Exit.findErrorOption(exit); throw Option.isSome(error) && isDeploymentFailure(error.value) ? deploymentFailure(error.value.code) : new TemporarilyUnavailable();}
export async function runDeploymentStep( program: Effect.Effect<unknown, DeploymentFailure | RegistryFailure>,): Promise< | { complete: true; errorCode: null } | { complete: false; errorCode: DeploymentCode }> { try { await runDeploymentEffect(program); return { complete: true, errorCode: null }; } catch (error) { if (isDeploymentFailure(error) && error.code !== "temporarily_unavailable") return { complete: false, errorCode: error.code }; throw new Error("temporarily_unavailable"); }}
export function domainExitCode( exit: Exit.Failure<unknown, unknown>,): DomainErrorCode { const error = Exit.findErrorOption(exit); return Option.isSome(error) ? domainErrorCode(error.value) : "temporarily_unavailable";}
export async function runDomainStep( program: Effect.Effect<void, DomainFailure | RegistryFailure>,): Promise<{ error: DomainErrorCode | null }> { const exit = await Effect.runPromiseExit(program); if (Exit.isSuccess(exit)) return { error: null }; const code = domainExitCode(exit); if (code === "temporarily_unavailable") throw new Error(code); return { error: code };}