/** * @since 1.0.0 */ import * as Cause from "effect/Cause"; import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import * as Layer from "effect/Layer"; import type { Pipeable } from "effect/Pipeable"; import * as PrimaryKey from "effect/PrimaryKey"; import type * as Schedule from "effect/Schedule"; import * as Schema from "effect/Schema"; import type * as AST from "effect/SchemaAST"; import * as Scope from "effect/Scope"; import type { WorkflowEngine, WorkflowInstance } from "./WorkflowEngine.js"; /** * @since 1.0.0 * @category Symbols */ export declare const TypeId: unique symbol; /** * @since 1.0.0 */ export declare namespace Workflow { /** * Extracts the type of the Payload of a `Workflow`. * * @since 1.0.0 * @category Type-level Utils */ type Payload> = W extends Workflow ? Payload["Type"] : never; /** * Extracts the type of the Success of a `Workflow`. * * @since 1.0.0 * @category Type-level Utils */ type Success> = W extends Workflow ? Success["Type"] : never; /** * Extracts the type of the Error of a `Workflow`. * * @since 1.0.0 * @category Type-level Utils */ type Error> = W extends Workflow ? Error["Type"] : never; } /** * @since 1.0.0 * @category Symbols */ export type TypeId = typeof TypeId; /** * @since 1.0.0 * @category Models */ export interface Workflow { readonly [TypeId]: TypeId; readonly name: Name; readonly payloadSchema: Payload; readonly successSchema: Success; readonly errorSchema: Error; readonly annotations: Context.Context; /** * Add an annotation to the workflow. */ annotate(tag: Context.Tag, value: S): Workflow; /** * Add the annotations from a Context object to the workflow. */ annotateContext(context: Context.Context): Workflow; /** * Execute the workflow with the given payload. */ readonly execute: (payload: [keyof Payload["fields"]] extends [never] ? void : Schema.Simplify>, options?: { readonly discard?: Discard; }) => Effect.Effect; /** * Poll a workflow execution for its current status. * * If the workflow has not run yet, it will return `undefined`, otherwise it * will return the current `Workflow.Result`. */ readonly poll: (executionId: string) => Effect.Effect | undefined, never, WorkflowEngine | Success["Context"] | Error["Context"]>; /** * Interrupt a workflow execution for the given execution ID. */ readonly interrupt: (executionId: string) => Effect.Effect; /** * Manually resume a workflow execution for the given execution ID. */ readonly resume: (executionId: string) => Effect.Effect; /** * Create a layer that registers the workflow and provides an effect to * execute it. */ readonly toLayer: (execute: (payload: Payload["Type"], executionId: string) => Effect.Effect) => Layer.Layer | Scope.Scope> | Payload["Context"] | Success["Context"] | Error["Context"]>; /** * For the given payload, compute the deterministic execution ID. */ readonly executionId: (payload: Schema.Simplify>) => Effect.Effect; /** * Add compensation logic to an effect inside a Workflow. The compensation finalizer will be * called if the entire workflow fails, allowing you to perform cleanup or * other actions based on the success value and the cause of the workflow failure. * * NOTE: Compensation will not work for nested activities. Compensation * finalizers are only registered for top-level effects in the workflow. */ readonly withCompensation: { (compensation: (value: A, cause: Cause.Cause) => Effect.Effect): (effect: Effect.Effect) => Effect.Effect | Scope.Scope>; (effect: Effect.Effect, compensation: (value: A, cause: Cause.Cause) => Effect.Effect): Effect.Effect | Scope.Scope>; }; } /** * @since 1.0.0 */ export interface AnyStructSchema extends Pipeable { readonly [Schema.TypeId]: any; readonly make: any; readonly Type: any; readonly Encoded: any; readonly Context: any; readonly ast: AST.AST; readonly fields: Schema.Struct.Fields; readonly annotations: any; } /** * @since 1.0.0 * @category constructors */ export interface AnyTaggedRequestSchema extends AnyStructSchema { readonly _tag: string; readonly Type: PrimaryKey.PrimaryKey; readonly success: Schema.Schema.Any; readonly failure: Schema.Schema.All; } /** * @since 1.0.0 * @category Models */ export interface Execution { readonly _: unique symbol; readonly name: Name; } /** * @since 1.0.0 * @category Models */ export interface Any { readonly [TypeId]: TypeId; readonly name: string; readonly payloadSchema: AnyStructSchema; readonly successSchema: Schema.Schema.Any; readonly errorSchema: Schema.Schema.All; readonly annotations: Context.Context; readonly executionId: (payload: any) => Effect.Effect; } /** * @since 1.0.0 * @category Models */ export type Requirements = Workflows extends Workflow ? _Payload["Context"] | _Success["Context"] | _Error["Context"] : never; /** * @since 1.0.0 * @category Constructors */ export declare const make: (options: { readonly name: Name; readonly payload: Payload; readonly idempotencyKey: (payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type : Payload["Type"]) => string; readonly success?: Success; readonly error?: Error; readonly suspendedRetrySchedule?: Schedule.Schedule | undefined; readonly annotations?: Context.Context; }) => Workflow : Payload, Success, Error>; /** * @since 1.0.0 * @category Constructors */ export declare const fromTaggedRequest: (schema: S, options?: { readonly suspendedRetrySchedule?: Schedule.Schedule | undefined; }) => Workflow; /** * @since 1.0.0 * @category Result */ export declare const ResultTypeId: unique symbol; /** * @since 1.0.0 * @category Result */ export type ResultTypeId = typeof ResultTypeId; /** * @since 1.0.0 * @category Result */ export declare const isResult: (u: unknown) => u is Result; /** * @since 1.0.0 * @category Result */ export type Result = Complete | Suspended; /** * @since 1.0.0 * @category Result */ export type ResultEncoded = CompleteEncoded | typeof Suspended.Encoded; declare const Complete_base: new = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A_1 as P extends "_tag" ? never : P]: A_1[P]; }>) => Readonly & { readonly _tag: "Complete"; }; /** * @since 1.0.0 * @category Result */ export declare class Complete extends Complete_base<{ readonly exit: Exit.Exit; }> { /** * @since 1.0.0 */ readonly [ResultTypeId]: ResultTypeId; /** * @since 1.0.0 */ static SchemaFromSelf(_options: { readonly success: Success; readonly error: Error; }): Schema.Schema>; /** * @since 1.0.0 */ static SchemaEncoded(options: { readonly success: Success; readonly error: Error; }): Schema.Struct<{ _tag: Schema.tag<"Complete">; exit: Schema.Exit; }>; /** * @since 1.0.0 */ static Schema(options: { readonly success: Success; readonly error: Error; }): Schema.Schema, CompleteEncoded>; } /** * @since 1.0.0 * @category Result */ export interface CompleteEncoded { readonly _tag: "Complete"; readonly exit: Schema.ExitEncoded; } declare const Suspended_base: Schema.TaggedClass; } & { cause: Schema.optional>; }>; /** * @since 1.0.0 * @category Result */ export declare class Suspended extends Suspended_base { /** * @since 1.0.0 */ readonly [ResultTypeId]: ResultTypeId; } /** * @since 1.0.0 * @category Result */ export declare const Result: (options: { readonly success: Success; readonly error: Error; }) => Schema.Schema, ResultEncoded, Success["Context"] | Error["Context"]>; /** * @since 1.0.0 * @category Result */ export declare const intoResult: (effect: Effect.Effect) => Effect.Effect, never, Exclude | WorkflowInstance>; /** * @since 1.0.0 * @category Result */ export declare const wrapActivityResult: (effect: Effect.Effect, isSuspend: (value: A) => boolean) => Effect.Effect; /** * Accesses the workflow scope. * * The workflow scope is only closed when the workflow execution fully * completes. * * @since 1.0.0 * @category Scope */ export declare const scope: Effect.Effect; /** * Provides the workflow scope to the given effect. * * The workflow scope is only closed when the workflow execution fully * completes. * * @since 1.0.0 * @category Scope */ export declare const provideScope: (effect: Effect.Effect) => Effect.Effect | WorkflowInstance>; /** * @since 1.0.0 * @category Scope */ export declare const addFinalizer: (f: (exit: Exit.Exit) => Effect.Effect) => Effect.Effect; /** * Add compensation logic to an effect inside a Workflow. The compensation finalizer will be * called if the entire workflow fails, allowing you to perform cleanup or * other actions based on the success value and the cause of the workflow failure. * * NOTE: Compensation will not work for nested activities. Compensation * finalizers are only registered for top-level effects in the workflow. * * @since 1.0.0 * @category Compensation */ export declare const withCompensation: { /** * Add compensation logic to an effect inside a Workflow. The compensation finalizer will be * called if the entire workflow fails, allowing you to perform cleanup or * other actions based on the success value and the cause of the workflow failure. * * NOTE: Compensation will not work for nested activities. Compensation * finalizers are only registered for top-level effects in the workflow. * * @since 1.0.0 * @category Compensation */ (compensation: (value: A, cause: Cause.Cause) => Effect.Effect): (effect: Effect.Effect) => Effect.Effect; /** * Add compensation logic to an effect inside a Workflow. The compensation finalizer will be * called if the entire workflow fails, allowing you to perform cleanup or * other actions based on the success value and the cause of the workflow failure. * * NOTE: Compensation will not work for nested activities. Compensation * finalizers are only registered for top-level effects in the workflow. * * @since 1.0.0 * @category Compensation */ (effect: Effect.Effect, compensation: (value: A, cause: Cause.Cause) => Effect.Effect): Effect.Effect; }; /** * @since 1.0.0 */ export declare const suspend: (instance: WorkflowInstance["Type"]) => Effect.Effect; declare const CaptureDefects_base: Context.ReferenceClass; /** * If you set this annotation to `true` for a workflow, it will capture defects * and include them in the result of the workflow or it's activities. * * By default, this is set to `true`, meaning that defects will be captured. * * @since 1.0.0 * @category Annotations */ export declare class CaptureDefects extends CaptureDefects_base { } declare const SuspendOnFailure_base: Context.ReferenceClass; /** * If you set this annotation to `true` for a workflow, it will suspend if it * encounters any kind of error. * * You can then manually resume the workflow later with * `Workflow.resume(executionId)`. * * @since 1.0.0 * @category Annotations */ export declare class SuspendOnFailure extends SuspendOnFailure_base { } export {}; //# sourceMappingURL=Workflow.d.ts.map