@yieldstar/core 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/base/durable-value.d.ts +71 -0
  2. package/dist/base/durable-value.d.ts.map +1 -0
  3. package/dist/base/durable-value.test.d.ts +2 -0
  4. package/dist/base/durable-value.test.d.ts.map +1 -0
  5. package/dist/base/effect.d.ts +136 -0
  6. package/dist/base/effect.d.ts.map +1 -0
  7. package/dist/base/errors.d.ts +23 -0
  8. package/dist/base/errors.d.ts.map +1 -0
  9. package/dist/base/errors.test.d.ts +2 -0
  10. package/dist/base/errors.test.d.ts.map +1 -0
  11. package/dist/base/event.d.ts +6 -1
  12. package/dist/base/event.d.ts.map +1 -1
  13. package/dist/base/execution.d.ts +255 -0
  14. package/dist/base/execution.d.ts.map +1 -0
  15. package/dist/base/heap.d.ts +15 -3
  16. package/dist/base/heap.d.ts.map +1 -1
  17. package/dist/base/invoker.d.ts +47 -2
  18. package/dist/base/invoker.d.ts.map +1 -1
  19. package/dist/base/runtime.d.ts +27 -4
  20. package/dist/base/runtime.d.ts.map +1 -1
  21. package/dist/base/step.d.ts +21 -5
  22. package/dist/base/step.d.ts.map +1 -1
  23. package/dist/base/store.d.ts +135 -21
  24. package/dist/base/store.d.ts.map +1 -1
  25. package/dist/base/workflow.d.ts +15 -0
  26. package/dist/base/workflow.d.ts.map +1 -1
  27. package/dist/index.d.ts +23 -6
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1653 -172
  30. package/dist/lib/effect-state.d.ts +78 -0
  31. package/dist/lib/effect-state.d.ts.map +1 -0
  32. package/dist/lib/execution-dispatcher.d.ts +112 -0
  33. package/dist/lib/execution-dispatcher.d.ts.map +1 -0
  34. package/dist/lib/execution-state.d.ts +248 -0
  35. package/dist/lib/execution-state.d.ts.map +1 -0
  36. package/dist/lib/execution-state.test.d.ts +2 -0
  37. package/dist/lib/execution-state.test.d.ts.map +1 -0
  38. package/dist/lib/wait-for-outcome.d.ts +15 -0
  39. package/dist/lib/wait-for-outcome.d.ts.map +1 -0
  40. package/dist/lib/workflow-runner.d.ts +14 -9
  41. package/dist/lib/workflow-runner.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/base/durable-value.test.ts +285 -0
  44. package/src/base/durable-value.ts +442 -0
  45. package/src/base/effect.ts +165 -0
  46. package/src/base/errors.test.ts +210 -0
  47. package/src/base/errors.ts +72 -0
  48. package/src/base/event.ts +6 -1
  49. package/src/base/execution.ts +315 -0
  50. package/src/base/heap.ts +17 -3
  51. package/src/base/invoker.ts +60 -2
  52. package/src/base/runtime.ts +28 -7
  53. package/src/base/step.ts +29 -7
  54. package/src/base/store.ts +339 -49
  55. package/src/base/workflow.ts +15 -0
  56. package/src/index.ts +138 -3
  57. package/src/lib/effect-state.ts +254 -0
  58. package/src/lib/execution-dispatcher.ts +408 -0
  59. package/src/lib/execution-state.test.ts +249 -0
  60. package/src/lib/execution-state.ts +650 -0
  61. package/src/lib/wait-for-outcome.ts +40 -0
  62. package/src/lib/workflow-runner.ts +75 -43
  63. package/src/base/scheduler.ts +0 -8
  64. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,71 @@
1
+ export type DurableValue = null | boolean | number | string | undefined | Error | DurableValue[] | DurableObject;
2
+ export type DurableObject = {
3
+ [key: string]: DurableValue;
4
+ };
5
+ /**
6
+ * Compile-time check for a value that will be recorded. Unlike an index
7
+ * signature, it accepts interfaces. The codec still validates every value at
8
+ * runtime.
9
+ */
10
+ export type Durable<T> = T extends string | number | boolean | null | undefined | Error ? T : T extends readonly (infer U)[] ? readonly Durable<U>[] : T extends Function | Date | Map<any, any> | Set<any> | bigint ? never : {
11
+ [K in keyof T]: Durable<T[K]>;
12
+ };
13
+ /**
14
+ * `unknown` when `T` is a durable value, and `Otherwise` when it is not.
15
+ * Intersect a parameter with it to check a type inferred from the rest of
16
+ * that parameter: the check takes no part in inference, so literal widening
17
+ * and union inference are unchanged. `Otherwise` should restate the
18
+ * parameter with `Durable<T>` in place of `T`, so the error names the
19
+ * offending property.
20
+ */
21
+ export type IfDurable<T, Otherwise> = [T] extends [Durable<T>] ? unknown : Otherwise;
22
+ export type DurableValueEncoding = {
23
+ status: "encoded";
24
+ canonical: string;
25
+ } | {
26
+ status: "invalid";
27
+ message: string;
28
+ };
29
+ export type DurableDecoding = {
30
+ status: "decoded";
31
+ value: DurableValue;
32
+ } | {
33
+ status: "invalid";
34
+ message: string;
35
+ };
36
+ export interface DurableValueCodec {
37
+ /**
38
+ * Validates `value` recursively and returns its canonical JSON: object keys
39
+ * sorted by UTF-16 code unit and `-0` written as `0`, so equal values always
40
+ * encode to the same string. `undefined`, errors and plain objects with an
41
+ * own `$type` key are written as tagged objects. Never throws for an invalid
42
+ * value.
43
+ */
44
+ encode(value: unknown): DurableValueEncoding;
45
+ /**
46
+ * Reads an encoding back into the value that was encoded. Errors are revived
47
+ * as the class registered under their `name`, without calling its
48
+ * constructor. Never throws for an invalid encoding.
49
+ */
50
+ decode(canonical: string): DurableDecoding;
51
+ }
52
+ export declare class DurableValueError extends Error {
53
+ }
54
+ export declare const durableValueCodec: DurableValueCodec;
55
+ /**
56
+ * Encodes a thrown value: as thrown when it is a `DurableValue`, and as
57
+ * `Error(String(value))` otherwise. Always succeeds.
58
+ */
59
+ export declare function encodeThrownValue(value: unknown): string;
60
+ /**
61
+ * Whether `value` is an object with the default object prototype or `null`.
62
+ * It says nothing about the object's properties.
63
+ */
64
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
65
+ /**
66
+ * Decodes a value already parsed from an encoding's JSON, so that adapters can
67
+ * embed encodings in a larger JSON document. Throws `DurableValueError` for an
68
+ * invalid encoding.
69
+ */
70
+ export declare function decodeParsedValue(parsed: unknown, path?: string): DurableValue;
71
+ //# sourceMappingURL=durable-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-value.d.ts","sourceRoot":"","sources":["../../src/base/durable-value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M,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAAC;IAE7C;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAAC;CAC5C;AAED,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C,eAAO,MAAM,iBAAiB,EAAE,iBAwB/B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUxD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9E;AAkLD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,SAAM,GAAG,YAAY,CAuC3E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=durable-value.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-value.test.d.ts","sourceRoot":"","sources":["../../src/base/durable-value.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,136 @@
1
+ import type { DurableObject, DurableValue } from "./durable-value";
2
+ export type EffectBeginRequest = {
3
+ operation: string;
4
+ /** Identifies the external operation across every execution and runtime. */
5
+ effectId: string;
6
+ input: DurableObject;
7
+ /** The execution and step that are beginning the effect. */
8
+ executionId: string;
9
+ stepKey: string;
10
+ };
11
+ export type EffectBeginResult = {
12
+ status: "new";
13
+ } | {
14
+ status: "pending";
15
+ } | {
16
+ status: "settled";
17
+ result: DurableValue;
18
+ } | {
19
+ status: "rejected";
20
+ code: "EFFECT_REQUEST_MISMATCH";
21
+ };
22
+ export type EffectSettleRequest = {
23
+ operation: string;
24
+ effectId: string;
25
+ result: DurableValue;
26
+ };
27
+ export type EffectSettleResult = {
28
+ status: "settled";
29
+ result: DurableValue;
30
+ } | {
31
+ status: "conflict";
32
+ /** The first result, which stays settled. */
33
+ result: DurableValue;
34
+ conflictingResult: DurableValue;
35
+ };
36
+ export type EffectWatchRequest = {
37
+ effectId: string;
38
+ executionId: string;
39
+ stepKey: string;
40
+ };
41
+ /** A settlement that reported a different result from the settled one. */
42
+ export type EffectConflictReport = {
43
+ result: DurableValue;
44
+ conflictingResult: DurableValue;
45
+ reportedAt: number;
46
+ };
47
+ export type EffectRecord = {
48
+ effectId: string;
49
+ operation: string;
50
+ input: DurableObject;
51
+ status: "pending" | "settled";
52
+ /** Present, possibly as `undefined`, only when `status` is `settled`. */
53
+ result?: DurableValue;
54
+ conflicts: EffectConflictReport[];
55
+ };
56
+ /**
57
+ * The runtime's record of external effects, keyed by effect ID (RFC 005).
58
+ * Effect records are never deleted, including when an execution that began
59
+ * one is cancelled or pruned.
60
+ *
61
+ * `begin`, `settle` and `watch` are not fenced: a stale lease holder's calls
62
+ * are accepted, and are safe because each is idempotent by effect ID. A
63
+ * client throws `EffectClientInvariantError` for a request the driver should
64
+ * never make, such as one with invalid values or for an unknown effect, and
65
+ * for stored data it cannot read. Any other rejection means the client may be
66
+ * unavailable.
67
+ */
68
+ export interface EffectClient {
69
+ /**
70
+ * Creates a pending effect before returning `new`. For an existing effect,
71
+ * returns its current state when `operation` and the canonical encoding of
72
+ * `input` match, and `EFFECT_REQUEST_MISMATCH` otherwise, leaving the
73
+ * effect unchanged.
74
+ */
75
+ begin(request: EffectBeginRequest): Promise<EffectBeginResult>;
76
+ /**
77
+ * Settles a pending effect with `result` and wakes every execution watching
78
+ * it, all-or-nothing. Settling an effect again with an equal result returns
79
+ * the settled result; a different result keeps the first, returns
80
+ * `conflict` and stores a permanent conflict report.
81
+ */
82
+ settle(request: EffectSettleRequest): Promise<EffectSettleResult>;
83
+ /**
84
+ * Registers the step as a waiter on the effect, so settlement wakes its
85
+ * execution. Repeating it keeps one registration. If the effect is already
86
+ * settled, wakes the execution now. The waiter is deleted by the heap write
87
+ * that records the step's result.
88
+ */
89
+ watch(request: EffectWatchRequest): Promise<void>;
90
+ /** For operators: the effect, its result and any conflict reports. */
91
+ getEffect(effectId: string): Promise<EffectRecord | undefined>;
92
+ }
93
+ /**
94
+ * Thrown by an `EffectClient` when a request or its stored data breaks the
95
+ * client's invariants. The driver requests another delivery instead of
96
+ * recording a step.
97
+ */
98
+ export declare class EffectClientInvariantError extends Error {
99
+ readonly code: "EFFECT_RUNTIME_INVARIANT";
100
+ constructor(message: string, options?: ErrorOptions);
101
+ }
102
+ export type WorkflowEffectErrorCode = "INVALID_EFFECT_REQUEST" | "EFFECT_REQUEST_MISMATCH";
103
+ /** The codes with which `step.effect` requests another delivery. */
104
+ export type EffectDeliveryErrorCode = "EFFECT_CLIENT_UNAVAILABLE" | "EFFECT_HANDLER_INVALID" | "EFFECT_RUNTIME_INVARIANT";
105
+ /**
106
+ * The cause of the infrastructure error with which `step.effect` ends a
107
+ * delivery without recording its step. It never reaches workflow code: the
108
+ * delivery is not acknowledged, and the execution is delivered again.
109
+ *
110
+ * - `EFFECT_CLIENT_UNAVAILABLE`: an `EffectClient` call failed, and may
111
+ * recover without intervention.
112
+ * - `EFFECT_HANDLER_INVALID`: `lookup` or `perform` returned a malformed
113
+ * response or a value that is not durable.
114
+ * - `EFFECT_RUNTIME_INVARIANT`: the `EffectClient` threw
115
+ * `EffectClientInvariantError` or answered with a malformed response.
116
+ */
117
+ export declare class EffectDeliveryError extends Error {
118
+ readonly code: EffectDeliveryErrorCode;
119
+ readonly effectId: string;
120
+ readonly stepKey: string;
121
+ constructor(code: EffectDeliveryErrorCode, params: {
122
+ effectId: string;
123
+ stepKey: string;
124
+ message: string;
125
+ }, options?: ErrorOptions);
126
+ }
127
+ /**
128
+ * Thrown to workflow code by `step.effect` for an invalid request or one that
129
+ * does not match the recorded effect. It is recorded as the step's error, so
130
+ * replay throws it again.
131
+ */
132
+ export declare class WorkflowEffectError extends Error {
133
+ readonly code: WorkflowEffectErrorCode;
134
+ constructor(code: WorkflowEffectErrorCode, message: string);
135
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,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGvB,IAAI,EAAE,uBAAuB,EAC7B,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAC9D,OAAO,CAAC,EAAE,YAAY;CAQzB;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D"}
@@ -0,0 +1,23 @@
1
+ export type WorkflowValueErrorCode = "INVALID_STEP_VALUE" | "STEP_SCHEMA_INVALID";
2
+ /** The `stepKey` of a `WorkflowValueError` raised by an invalid workflow result. */
3
+ export declare const WORKFLOW_RESULT_STEP_KEY = "$$workflow-result$$";
4
+ /**
5
+ * Thrown to workflow code when a step produces a value the durable value codec
6
+ * rejects, or a step's schema rejects its decoded value. It is recorded as the
7
+ * step's error, so replay throws it again.
8
+ */
9
+ export declare class WorkflowValueError extends Error {
10
+ readonly code: WorkflowValueErrorCode;
11
+ readonly stepKey: string;
12
+ constructor(code: WorkflowValueErrorCode, stepKey: string, message: string);
13
+ }
14
+ export type ErrorClass = abstract new (...args: any[]) => Error;
15
+ /**
16
+ * Registers the class that decoding revives errors named `name` as, replacing
17
+ * any class registered under that name. Registration is per process: a worker
18
+ * that has not registered a class revives its errors as plain `Error`s with
19
+ * the same name, message, code, cause and fields.
20
+ */
21
+ export declare function registerErrorClass(name: string, errorClass: ErrorClass): void;
22
+ export declare function registeredErrorClass(name: string): ErrorClass | undefined;
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/base/errors.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,GAAG,qBAAqB,CAAC;AAElF,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,wBAAwB,CAAC;AAE9D;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM3E;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAIhE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAW7E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEzE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/base/errors.test.ts"],"names":[],"mappings":""}
@@ -25,7 +25,12 @@ export type WorkflowEvent<Params extends EventParams = EventParams, Context exte
25
25
  params: Params;
26
26
  context: Context;
27
27
  };
28
- export type MiddlewareEvent<Params extends EventParams = EventParams, Context extends MiddlewareEventContext = MiddlewareEventContext> = ExecutionEvent<Params> & {
28
+ /**
29
+ * The event a trigger route passes through middleware before admission.
30
+ * `executionId` is absent when the caller lets the runtime choose one.
31
+ */
32
+ export type MiddlewareEvent<Params extends EventParams = EventParams, Context extends MiddlewareEventContext = MiddlewareEventContext> = Omit<ExecutionEvent<Params>, "executionId" | "context"> & {
33
+ executionId?: string;
29
34
  context: Context;
30
35
  };
31
36
  //# sourceMappingURL=event.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/base/event.ts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C,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,aAAa,CACvB,MAAM,SAAS,WAAW,GAAG,WAAW,EACxC,OAAO,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,IAC3D;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,CACzB,MAAM,SAAS,WAAW,GAAG,WAAW,EACxC,OAAO,SAAS,sBAAsB,GAAG,sBAAsB,IAC7D,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC,GAAG;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC"}
@@ -0,0 +1,255 @@
1
+ import type { DurableObject } from "./durable-value";
2
+ import type { EventContext, EventParams } from "./event";
3
+ export type ExecutionStatus = "admitted" | "running" | "suspended" | "completed" | "failed";
4
+ export type ExecutionOutcome = {
5
+ status: "completed";
6
+ result: unknown;
7
+ } | {
8
+ status: "failed";
9
+ error: Error;
10
+ };
11
+ /** The execution and step that started an execution with `step.start`. */
12
+ export type ExecutionParent = {
13
+ executionId: string;
14
+ stepKey: string;
15
+ };
16
+ /**
17
+ * The durable record of one workflow execution. Admission creates it and
18
+ * stores the event once; every delivery reads the event from here.
19
+ *
20
+ * - `admitted`: no delivery has been acknowledged yet.
21
+ * - `running`: the execution has a live lease. When the lease ends without a
22
+ * terminal acknowledgement, the status returns to `suspended` if any
23
+ * earlier delivery was acknowledged as suspended, and to `admitted`
24
+ * otherwise.
25
+ * - `suspended`: the latest acknowledged delivery suspended the workflow.
26
+ * - `completed` and `failed` are terminal. `outcome` is present only in these
27
+ * states.
28
+ *
29
+ * `parent` is present, and immutable, only on executions admitted by `start`.
30
+ */
31
+ export interface ExecutionRecord {
32
+ executionId: string;
33
+ workflowId: string;
34
+ params: EventParams;
35
+ context: EventContext;
36
+ status: ExecutionStatus;
37
+ outcome?: ExecutionOutcome;
38
+ admittedAt: number;
39
+ updatedAt: number;
40
+ /** Consecutive deliveries that ended without an acknowledgement. */
41
+ unacknowledgedDeliveryCount: number;
42
+ parent?: ExecutionParent;
43
+ }
44
+ export type ExecutionAdmissionErrorCode = "EXECUTION_ID_CONFLICT" | "INVALID_EXECUTION_EVENT";
45
+ /**
46
+ * A lease on one execution, granted by `claimDue`. `token` is a fencing token:
47
+ * every claim of the execution issues a token greater than every earlier one,
48
+ * and only the current token's fenced writes are accepted. It also identifies
49
+ * the wakes the delivery covers. `expiresAt` is read from the runtime clock;
50
+ * clocks decide only when the execution becomes claimable again, never whose
51
+ * writes count.
52
+ */
53
+ export type ExecutionLease = {
54
+ executionId: string;
55
+ token: number;
56
+ expiresAt: number;
57
+ };
58
+ /**
59
+ * Limits a claim to the executions that match. The claim applies it in the same
60
+ * atomic step, so an execution that does not match is not leased and gains no
61
+ * redelivery delay.
62
+ */
63
+ export type ExecutionClaimFilter = {
64
+ /** Claims only executions whose ID is in this list. An empty list claims nothing. */
65
+ executionIds?: readonly string[];
66
+ };
67
+ /**
68
+ * Returned by a fenced write whose lease is no longer current: a higher token
69
+ * has been issued, or the lease has ended. The write changed nothing, and its
70
+ * holder must stop.
71
+ */
72
+ export type LeaseLost = {
73
+ status: "lost";
74
+ };
75
+ export declare function isLeaseLost(value: unknown): value is LeaseLost;
76
+ /**
77
+ * What a delivery reports once its durable work is finished:
78
+ * - `completed`: the workflow returned a result;
79
+ * - `suspended`: the unfinished step is recorded, and `wakeAt`, when present,
80
+ * is the earliest time a paused step needs the execution to run again;
81
+ * - `failed`: workflow code threw an uncaught error.
82
+ *
83
+ * Infrastructure errors are never outcomes: the delivery rejects instead.
84
+ */
85
+ export type WorkflowRunOutcome = {
86
+ status: "completed";
87
+ result: unknown;
88
+ } | {
89
+ status: "suspended";
90
+ wakeAt?: number;
91
+ } | {
92
+ status: "failed";
93
+ error: Error;
94
+ };
95
+ export type ExecutionAdmissionRequest = {
96
+ executionId?: string;
97
+ workflowId: string;
98
+ params: EventParams;
99
+ context: EventContext;
100
+ };
101
+ export type ExecutionAdmissionResult = {
102
+ status: "accepted";
103
+ executionId: string;
104
+ } | {
105
+ status: "rejected";
106
+ code: ExecutionAdmissionErrorCode;
107
+ message: string;
108
+ };
109
+ export type WorkflowStartErrorCode = "INVALID_START_PARAMETERS" | "START_REQUEST_MISMATCH";
110
+ export type ExecutionStartRequest = {
111
+ /** Identifies the request: the calling execution and its step key. */
112
+ requestId: {
113
+ executionId: string;
114
+ stepKey: string;
115
+ };
116
+ workflowId: string;
117
+ params?: DurableObject;
118
+ };
119
+ export type ExecutionStartResult = {
120
+ status: "accepted";
121
+ executionId: string;
122
+ } | {
123
+ status: "rejected";
124
+ code: WorkflowStartErrorCode;
125
+ message: string;
126
+ };
127
+ export type ExecutionWakeResult = {
128
+ status: "requested";
129
+ } | {
130
+ status: "ignored";
131
+ } | {
132
+ status: "rejected";
133
+ code: "EXECUTION_NOT_FOUND";
134
+ message: string;
135
+ };
136
+ export type ExecutionAcknowledgeResult = {
137
+ status: "suspended";
138
+ } | ExecutionOutcome | LeaseLost;
139
+ export type ExecutionRenewResult = {
140
+ status: "renewed";
141
+ lease: ExecutionLease;
142
+ } | LeaseLost;
143
+ export type ExecutionReleaseResult = {
144
+ status: "released";
145
+ } | LeaseLost;
146
+ export interface ExecutionClient {
147
+ /**
148
+ * Creates the execution record with status `admitted` and makes it due
149
+ * immediately, all-or-nothing. Execution IDs are never reused.
150
+ */
151
+ admit(request: ExecutionAdmissionRequest): Promise<ExecutionAdmissionResult>;
152
+ get(executionId: string): Promise<ExecutionRecord | undefined>;
153
+ /**
154
+ * Starts a workflow on behalf of the execution and step named by
155
+ * `requestId`, idempotently by that ID. A new start admits the target with
156
+ * the caller's context and a parent link to the caller, and records the
157
+ * start request, all-or-nothing. A repeated request returns the first
158
+ * target's ID if its workflow ID and canonical params match, and
159
+ * `START_REQUEST_MISMATCH` otherwise, whatever the target's status. Invalid
160
+ * params return `INVALID_START_PARAMETERS` and admit nothing. Not fenced.
161
+ */
162
+ start(request: ExecutionStartRequest): Promise<ExecutionStartResult>;
163
+ /**
164
+ * Requests a wake from outside a delivery, such as a store commit. Wakes not
165
+ * covered by a claimed delivery merge into one due time: the earliest.
166
+ */
167
+ requestWake(request: {
168
+ executionId: string;
169
+ wakeAt: number;
170
+ }): Promise<ExecutionWakeResult>;
171
+ /**
172
+ * Leases up to `limit` executions whose due time is at or before the runtime
173
+ * clock and that have no live lease, earliest due first. Each lease lasts
174
+ * `duration` milliseconds and carries a token greater than every earlier
175
+ * token for its execution. An execution has at most one live lease at a
176
+ * time, across every client sharing the backend.
177
+ */
178
+ claimDue(request: {
179
+ limit: number;
180
+ duration: number;
181
+ /** When absent, any execution whose due time has passed may be claimed. */
182
+ filter?: ExecutionClaimFilter;
183
+ }): Promise<ExecutionLease[]>;
184
+ /**
185
+ * Extends a lease to `duration` milliseconds from now. Returns `lost` if a
186
+ * higher token has been issued or the lease has ended. An expired lease
187
+ * that has not been claimed again is still current.
188
+ */
189
+ renew(request: {
190
+ lease: ExecutionLease;
191
+ duration: number;
192
+ }): Promise<ExecutionRenewResult>;
193
+ /**
194
+ * Ends a lease without acknowledging an outcome. The delivery counts as
195
+ * unacknowledged, so the execution becomes claimable again only after the
196
+ * redelivery delay. Returns `lost` for a stale lease.
197
+ */
198
+ release(request: {
199
+ lease: ExecutionLease;
200
+ }): Promise<ExecutionReleaseResult>;
201
+ /**
202
+ * Records a delivery's outcome and ends its lease, all-or-nothing. A
203
+ * `suspended` outcome clears the wakes the lease covered, leaving the
204
+ * execution due at the earliest of `wakeAt` and any wake requested since the
205
+ * claim. A stale lease returns `lost` and changes nothing.
206
+ */
207
+ acknowledge(request: {
208
+ lease: ExecutionLease;
209
+ outcome: WorkflowRunOutcome;
210
+ }): Promise<ExecutionAcknowledgeResult>;
211
+ }
212
+ /**
213
+ * Thrown by the driver when a fenced write returns `lost`: another claim has
214
+ * taken over the execution, so this delivery must stop without acknowledging.
215
+ */
216
+ export declare class LeaseLostError extends Error {
217
+ readonly executionId: string;
218
+ constructor(executionId: string);
219
+ }
220
+ /**
221
+ * Thrown by the driver when the current holder writes a step record that
222
+ * already exists with a different value. The recorded value stands: the
223
+ * delivery ends as a retry, and the next delivery replays the recorded value.
224
+ */
225
+ export declare class StepConflictError extends Error {
226
+ readonly executionId: string;
227
+ readonly stepKey: string;
228
+ constructor(executionId: string, stepKey: string);
229
+ }
230
+ export declare class ExecutionAdmissionError extends Error {
231
+ readonly code: ExecutionAdmissionErrorCode;
232
+ constructor(code: ExecutionAdmissionErrorCode, message: string);
233
+ }
234
+ /**
235
+ * Thrown to workflow code by `step.start` when the runtime rejects the start.
236
+ * The rejection is recorded as the step's result, so replay throws it again.
237
+ */
238
+ export declare class WorkflowStartError extends Error {
239
+ readonly code: WorkflowStartErrorCode;
240
+ constructor(code: WorkflowStartErrorCode, message: string);
241
+ }
242
+ declare const INFRASTRUCTURE_ERROR: unique symbol;
243
+ /**
244
+ * Wraps a failure of the runtime rather than of workflow code, such as a heap
245
+ * or store client rejecting. A delivery that hits one rejects without
246
+ * resuming workflow code, and is not acknowledged.
247
+ */
248
+ export declare class InfrastructureError extends Error {
249
+ readonly [INFRASTRUCTURE_ERROR] = true;
250
+ constructor(cause: unknown);
251
+ static is(value: unknown): value is InfrastructureError;
252
+ }
253
+ export declare function isTerminalExecutionStatus(status: ExecutionStatus): status is "completed" | "failed";
254
+ export {};
255
+ //# sourceMappingURL=execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/base/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;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AO,GAAG,KAAK,IAAI,mBAAmB;CAOxD;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,eAAe,GACtB,MAAM,IAAI,WAAW,GAAG,QAAQ,CAElC"}
@@ -1,3 +1,4 @@
1
+ import type { ExecutionLease, LeaseLost } from "./execution";
1
2
  export type HeapRecord = {
2
3
  stepResponseJson: string;
3
4
  meta: {
@@ -10,12 +11,23 @@ export declare abstract class HeapClient {
10
11
  executionId: string;
11
12
  stepKey: string;
12
13
  }): Promise<HeapRecord | null>;
14
+ /**
15
+ * Records one attempt of a step, fenced by `lease`. The token check and the
16
+ * write are atomic: if the lease is not current, nothing changes and the
17
+ * write returns `lost`. A `done` record also deletes the step's store
18
+ * and effect waiters in the same write.
19
+ *
20
+ * Records are keyed by execution, step key and attempt, and never change
21
+ * once written. Rewriting an existing record succeeds without changing it,
22
+ * and resolves with the record as stored, which may hold a different value
23
+ * from the one written: callers compare it to detect a conflicting write.
24
+ */
13
25
  abstract writeStep(params: {
14
- executionId: string;
26
+ lease: ExecutionLease;
15
27
  stepKey: string;
16
28
  stepAttempt: number;
17
- stepDone: boolean;
29
+ done: boolean;
18
30
  stepResponseJson: string;
19
- }): Promise<void>;
31
+ }): Promise<HeapRecord | LeaseLost>;
20
32
  }
21
33
  //# sourceMappingURL=heap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["../../src/base/heap.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C,CAAC;AAEF,8BAAsB,UAAU;IAC9B,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC;QAClB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,IAAI,CAAC;CAClB"}
1
+ {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["../../src/base/heap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C,CAAC;AAEF,8BAAsB,UAAU;IAC9B,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAE9B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE;QACzB,KAAK,EAAE,cAAc,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,EAAE,OAAO,CAAC;QACd,gBAAgB,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CACpC"}
@@ -1,7 +1,52 @@
1
1
  import type { EventEmitter } from "node:events";
2
- import type { ExecutionEvent } from "./event";
2
+ import type { WorkflowEvent } from "./event";
3
+ import type { ExecutionLease, WorkflowRunOutcome } from "./execution";
4
+ export type DeliveryOptions = {
5
+ /** Every fenced write the delivery makes carries this lease. */
6
+ lease: ExecutionLease;
7
+ /**
8
+ * Aborted when the delivery must stop: the dispatcher aborts it, with a
9
+ * `LeaseLostError` as its reason, when a renewal returns `lost`. The driver
10
+ * checks it before each step function and each fenced write, and ends an
11
+ * aborted delivery without running more workflow code.
12
+ */
13
+ signal: AbortSignal;
14
+ };
3
15
  export type WorkflowInvoker = {
16
+ /**
17
+ * @deprecated The execution record is the source of truth for outcomes.
18
+ * The dispatcher still emits terminal outcomes here as an in-process fast
19
+ * path; no guarantee depends on it.
20
+ */
4
21
  workflowEndEmitter: EventEmitter;
5
- execute(event: ExecutionEvent): Promise<void>;
22
+ /**
23
+ * Runs one delivery of an execution and resolves with its outcome. Rejects,
24
+ * without an outcome, when the delivery hits an infrastructure error or the
25
+ * worker exits before replying. Once `options.signal` aborts, the delivery runs
26
+ * no more workflow code and makes no more fenced writes; it rejects with an
27
+ * `InfrastructureError` whose cause is the signal's reason. An invoker that
28
+ * can stop a step function already running, as the worker invoker does by
29
+ * killing its worker, should do so and reject at once. The dispatcher
30
+ * abandons a delivery that has not settled within its `abortGracePeriod`
31
+ * of the abort, and frees its slot.
32
+ *
33
+ * A worker that exits before replying rejects with a `WorkerExitedError`:
34
+ * the dispatcher then leaves the lease to expire, because the worker's last
35
+ * writes may still be landing. Every other rejection is a retry reply, and
36
+ * the dispatcher releases the lease.
37
+ */
38
+ deliver(event: WorkflowEvent, options: DeliveryOptions): Promise<WorkflowRunOutcome>;
6
39
  };
40
+ declare const WORKER_EXITED: unique symbol;
41
+ /**
42
+ * Rejects a delivery whose worker exited, or was killed, before replying.
43
+ * The dispatcher does not release the lease: it expires, and the execution is
44
+ * delivered again after the redelivery delay.
45
+ */
46
+ export declare class WorkerExitedError extends Error {
47
+ readonly [WORKER_EXITED] = true;
48
+ constructor(message: string);
49
+ static is(value: unknown): value is WorkerExitedError;
50
+ }
51
+ export {};
7
52
  //# sourceMappingURL=invoker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoker.d.ts","sourceRoot":"","sources":["../../src/base/invoker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,EAAE,YAAY,CAAC;IACjC,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC"}
1
+ {"version":3,"file":"invoker.d.ts","sourceRoot":"","sources":["../../src/base/invoker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,MAAM,eAAe,GAAG;IAC5B,gEAAgE;IAChE,KAAK,EAAE,cAAc,CAAC;IACtB;;;;;OAKG;IACH,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;OAIG;IACH,kBAAkB,EAAE,YAAY,CAAC;IACjC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACtF,CAAC;AAEF,QAAA,MAAM,aAAa,eAAuC,CAAC;AAE3D;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,CAAC,aAAa,CAAC,QAAQ;gBAEpB,OAAO,EAAE,MAAM;IAK3B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB;CAOtD"}