1import * as Context from "effect/Context";
2import type * as Effect from "effect/Effect";
3import type {
4 WorkflowCronSchedule,
5 WorkflowProps,
6 WorkflowStepContextData,
7 WorkflowStepEvent,
8 WorkflowTaskOptions,
9 WorkflowWaitForEventOptions,
10} from "./Workflow.ts";
11
12/**
13 * Service that carries the current workflow event payload.
14 * `yield* WorkflowEvent` inside a workflow body to access it.
15 */
16export class WorkflowEvent extends Context.Service<
17 WorkflowEvent,
18 {
19 payload: unknown;
20 timestamp: Date;
21 instanceId: string;
22 workflowName: string;
23 /**
24 * Present when Cloudflare created this instance from a native
25 * {@link WorkflowProps.schedules} cron expression. Absent for
26 * instances started with `create` / `createBatch`.
27 */
28 schedule?: WorkflowCronSchedule;
29 }
30>()("Cloudflare.Workflows.WorkflowEvent") {}
31
32/**
33 * Runtime information for the current `task` attempt.
34 */
35export class WorkflowStepContext extends Context.Service<
36 WorkflowStepContext,
37 WorkflowStepContextData
38>()("Cloudflare.WorkflowStepContext") {}
39
40/**
41 * Internal service that wraps the Cloudflare `WorkflowStep` object.
42 * Not accessed directly by users -- use `task`, `sleep`, `sleepUntil`, and
43 * `waitForEvent` instead.
44 */
45export class WorkflowStep extends Context.Service<
46 WorkflowStep,
47 {
48 do<T, E>(options: WorkflowTaskOptions<T, any, any, E>): Effect.Effect<T, E>;
49 sleep(name: string, duration: string | number): Effect.Effect<void>;
50 sleepUntil(name: string, timestamp: Date | number): Effect.Effect<void>;
51 waitForEvent<T>(
52 name: string,
53 options: WorkflowWaitForEventOptions,
54 ): Effect.Effect<WorkflowStepEvent<T>>;
55 }
56>()("Cloudflare.Workflows.WorkflowStep") {}