Workflow
Annotations
CaptureDefects
Signature
declare class CaptureDefects extends any {
constructor();
}SuspendOnFailure
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).
Signature
declare class SuspendOnFailure extends any {
constructor();
}Compensation
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.
Signature
declare const withCompensation: {
<A, R2>(
compensation: (value: A, cause: Cause<unknown>) => Effect<void, never, R2>,
): <E, R>(effect: Effect<A, E, R>) => Effect<A, E, WorkflowInstance | Scope | R2 | R>;
<A, E, R, R2>(
effect: Effect<A, E, R>,
compensation: (value: A, cause: Cause<unknown>) => Effect<void, never, R2>,
): Effect<A, E, WorkflowInstance | Scope | R | R2>;
};Constructors
AnyTaggedRequestSchema interface
Signature
interface AnyTaggedRequestSchema extends AnyStructSchema {
[key: number]: any;
readonly _tag: string;
readonly failure: All;
readonly success: Any;
readonly Type: PrimaryKey;
}Constructors
fromTaggedRequest
Signature
declare function fromTaggedRequest<S extends AnyTaggedRequestSchema>(
schema: S,
options?: {
readonly suspendedRetrySchedule?: Schedule<any, unknown, never, never>;
},
): Workflow<S["_tag"], S, S["success"], S["failure"]>;Signature
declare function make<
Name extends string,
Payload extends Fields | AnyStructSchema,
Success extends Any = Void,
Error extends All = Never,
>(options: {
readonly annotations?: Context<never>;
readonly error?: Error;
readonly idempotencyKey: (
payload: Payload extends Fields
? View<Payload, "Type", TypeOptionalKeys<Payload>, TypeMutableKeys<Payload>>
: Payload["Type"],
) => string;
readonly name: Name;
readonly payload: Payload;
readonly success?: Success;
readonly suspendedRetrySchedule?: Schedule<any, unknown, never, never>;
}): Workflow<Name, Payload extends Fields ? Struct<Payload> : Payload, Success, Error>;Models
Signature
interface Any {
readonly [TypeId]: typeof TypeId;
readonly annotations: Context<never>;
readonly errorSchema: All;
readonly executionId: (payload: any) => Effect<string>;
readonly name: string;
readonly payloadSchema: AnyStructSchema;
readonly successSchema: Any;
}Signature
interface Execution<Name extends string> {
readonly _: typeof _;
readonly name: Name;
}Requirements type
Signature
type Requirements<Workflows extends Any> =
Workflows extends Workflow<infer _Name, infer _Payload, infer _Success, infer _Error>
? _Payload["Context"] | _Success["Context"] | _Error["Context"]
: never;Signature
interface Workflow<
Name extends string,
Payload extends AnyStructSchema,
Success extends Schema.Schema.Any,
Error extends Schema.Schema.All,
> {
readonly [TypeId]: typeof TypeId;
readonly annotations: Context<never>;
readonly errorSchema: Error;
readonly execute: <Discard extends boolean = false>(
payload: [keyof Payload["fields"]] extends [never]
? void
: Simplify<Constructor<Payload["fields"]>>,
options?: {
readonly discard?: Discard;
},
) => Effect<
Discard extends true ? string : Success["Type"],
Discard extends true ? never : Error["Type"],
WorkflowEngine | Payload["Context"] | Success["Context"] | Error["Context"]
>;
readonly executionId: (payload: Simplify<Constructor<Payload["fields"]>>) => Effect<string>;
readonly interrupt: (executionId: string) => Effect<void, never, WorkflowEngine>;
readonly name: Name;
readonly payloadSchema: Payload;
readonly poll: (
executionId: string,
) => Effect<
Result<Success["Type"], Error["Type"]> | undefined,
never,
WorkflowEngine | Success["Context"] | Error["Context"]
>;
readonly resume: (executionId: string) => Effect<void, never, WorkflowEngine>;
readonly successSchema: Success;
readonly toLayer: <R>(
execute: (
payload: Payload["Type"],
executionId: string,
) => Effect<Success["Type"], Error["Type"], R>,
) => Layer<
never,
never,
| WorkflowEngine
| Payload["Context"]
| Success["Context"]
| Error["Context"]
| Exclude<R, WorkflowEngine | WorkflowInstance | Scope | Execution<Name>>
>;
readonly withCompensation: {
<A, R2>(
compensation: (value: A, cause: Cause<Error["Type"]>) => Effect<void, never, R2>,
): <E, R>(
effect: Effect<A, E, R>,
) => Effect<A, E, WorkflowInstance | Scope | Execution<Name> | R2 | R>;
<A, E, R, R2>(
effect: Effect<A, E, R>,
compensation: (value: A, cause: Cause<Error["Type"]>) => Effect<void, never, R2>,
): Effect<A, E, WorkflowInstance | Scope | Execution<Name> | R | R2>;
};
annotate<I, S>(tag: Tag<I, S>, value: S): Workflow<Name, Payload, Success, Error>;
annotateContext<I>(context: Context<I>): Workflow<Name, Payload, Success, Error>;
}Other
AnyStructSchema interface
Signature
interface AnyStructSchema extends Pipeable {
[key: number]: any;
readonly annotations: any;
readonly ast: AST;
readonly Context: any;
readonly Encoded: any;
readonly fields: Fields;
readonly make: any;
readonly Type: any;
}Signature
declare function suspend(instance: any): Effect<never>;Result
Signature
declare class Complete<A, E> extends Readonly<{
readonly exit: Exit<A, E>;
}> & {
readonly _tag: "Complete";
} & Pipeable {
constructor<A, E>(args: {
readonly exit: Exit<A, E>;
});
readonly [ResultTypeId]: typeof ResultTypeId;
static Schema<Success extends Any, Error extends All>(options: {
readonly error: Error;
readonly success: Success;
}): any;
static SchemaEncoded<Success extends Any, Error extends All>(options: {
readonly error: Error;
readonly success: Success;
}): Struct<{
readonly _tag: tag<"Complete">;
readonly exit: Exit<Constraint, Constraint, Constraint>;
}>;
static SchemaFromSelf<Success extends Any, Error extends All>(_options: {
readonly error: Error;
readonly success: Success;
}): Schema<Complete<Success["Type"], Error["Type"]>>;
}CompleteEncoded interface
Signature
interface CompleteEncoded<A, E> {
readonly _tag: "Complete";
readonly exit: ExitEncoded<A, E, unknown>;
}intoResult
Signature
declare function intoResult<A, E, R>(
effect: Effect<A, E, R>,
): Effect<Result<A, E>, never, WorkflowInstance | Exclude<R, Scope>>;Signature
declare function isResult<A = unknown, E = unknown>(u: unknown): u is Result<A, E>;Signature
declare const Result: <Success extends Any, Error extends All>(options: {
readonly error: Error;
readonly success: Success;
}) => any;Signature
type Result<A, E> = Complete<A, E> | Suspended;ResultEncoded type
Signature
type ResultEncoded<A, E> = CompleteEncoded<A, E> | typeof Suspended.Encoded;ResultTypeId
Signature
declare const ResultTypeId: unique symbol;ResultTypeId type
Signature
type ResultTypeId = typeof ResultTypeId;Signature
declare class Suspended extends {
readonly _tag: "Suspended";
readonly cause?: Cause<unknown>;
} {
constructor(...args: [props?: {
readonly _tag?: "Suspended";
readonly cause?: Cause<unknown>;
}, options?: MakeOptions]);
readonly [ResultTypeId]: typeof ResultTypeId;
}wrapActivityResult
Signature
declare function wrapActivityResult<A, E, R>(
effect: Effect<A, E, R>,
isSuspend: (value: A) => boolean,
): Effect<A, E, WorkflowInstance | R>;Scope
addFinalizer
Signature
declare const addFinalizer: <R>(
f: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, R>,
) => Effect.Effect<void, never, WorkflowInstance | R>;provideScope
Provides the workflow scope to the given effect.
The workflow scope is only closed when the workflow execution fully completes.
Signature
declare function provideScope<A, E, R>(
effect: Effect<A, E, R>,
): Effect<A, E, WorkflowInstance | Exclude<R, Scope>>;Accesses the workflow scope.
The workflow scope is only closed when the workflow execution fully completes.
Signature
declare const scope: Effect.Effect<Scope.Scope, never, WorkflowInstance>;
If you set this annotation to
truefor 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.