@yieldstar/core 0.5.0 → 0.6.0
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.
- package/dist/base/durable-value.d.ts +71 -0
- package/dist/base/durable-value.d.ts.map +1 -0
- package/dist/base/durable-value.test.d.ts +2 -0
- package/dist/base/durable-value.test.d.ts.map +1 -0
- package/dist/base/effect.d.ts +136 -0
- package/dist/base/effect.d.ts.map +1 -0
- package/dist/base/errors.d.ts +23 -0
- package/dist/base/errors.d.ts.map +1 -0
- package/dist/base/errors.test.d.ts +2 -0
- package/dist/base/errors.test.d.ts.map +1 -0
- package/dist/base/event.d.ts +6 -1
- package/dist/base/event.d.ts.map +1 -1
- package/dist/base/execution.d.ts +244 -0
- package/dist/base/execution.d.ts.map +1 -0
- package/dist/base/heap.d.ts +15 -3
- package/dist/base/heap.d.ts.map +1 -1
- package/dist/base/invoker.d.ts +47 -2
- package/dist/base/invoker.d.ts.map +1 -1
- package/dist/base/runtime.d.ts +27 -4
- package/dist/base/runtime.d.ts.map +1 -1
- package/dist/base/step.d.ts +21 -5
- package/dist/base/step.d.ts.map +1 -1
- package/dist/base/store.d.ts +135 -21
- package/dist/base/store.d.ts.map +1 -1
- package/dist/base/workflow.d.ts +15 -0
- package/dist/base/workflow.d.ts.map +1 -1
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1647 -172
- package/dist/lib/effect-state.d.ts +78 -0
- package/dist/lib/effect-state.d.ts.map +1 -0
- package/dist/lib/execution-dispatcher.d.ts +102 -0
- package/dist/lib/execution-dispatcher.d.ts.map +1 -0
- package/dist/lib/execution-state.d.ts +248 -0
- package/dist/lib/execution-state.d.ts.map +1 -0
- package/dist/lib/execution-state.test.d.ts +2 -0
- package/dist/lib/execution-state.test.d.ts.map +1 -0
- package/dist/lib/wait-for-outcome.d.ts +15 -0
- package/dist/lib/wait-for-outcome.d.ts.map +1 -0
- package/dist/lib/workflow-runner.d.ts +14 -9
- package/dist/lib/workflow-runner.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/base/durable-value.test.ts +285 -0
- package/src/base/durable-value.ts +442 -0
- package/src/base/effect.ts +165 -0
- package/src/base/errors.test.ts +210 -0
- package/src/base/errors.ts +72 -0
- package/src/base/event.ts +6 -1
- package/src/base/execution.ts +303 -0
- package/src/base/heap.ts +17 -3
- package/src/base/invoker.ts +60 -2
- package/src/base/runtime.ts +28 -7
- package/src/base/step.ts +29 -7
- package/src/base/store.ts +339 -49
- package/src/base/workflow.ts +15 -0
- package/src/index.ts +137 -3
- package/src/lib/effect-state.ts +254 -0
- package/src/lib/execution-dispatcher.ts +393 -0
- package/src/lib/execution-state.test.ts +249 -0
- package/src/lib/execution-state.ts +650 -0
- package/src/lib/wait-for-outcome.ts +40 -0
- package/src/lib/workflow-runner.ts +75 -43
- package/src/base/scheduler.ts +0 -8
- 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.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,GACT,KAAK,GACL,YAAY,EAAE,GACd,aAAa,CAAC;AAElB,MAAM,MAAM,aAAa,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,KAAK,GACL,CAAC,GACD,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9B,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,GACrB,CAAC,SAAS,QAAQ,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAC7D,KAAK,GACL;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;AAErF,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C,MAAM,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 @@
|
|
|
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
|
+
}
|
|
136
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/base/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GACjB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC3C;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,yBAAyB,CAAA;CAAE,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC3C;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,6CAA6C;IAC7C,MAAM,EAAE,YAAY,CAAC;IACrB,iBAAiB,EAAE,YAAY,CAAC;CACjC,CAAC;AAEN,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EA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;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,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 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/base/errors.test.ts"],"names":[],"mappings":""}
|
package/dist/base/event.d.ts
CHANGED
|
@@ -25,7 +25,12 @@ export type WorkflowEvent<Params extends EventParams = EventParams, Context exte
|
|
|
25
25
|
params: Params;
|
|
26
26
|
context: Context;
|
|
27
27
|
};
|
|
28
|
-
|
|
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
|
package/dist/base/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/base/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;AACrD,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACjD,MAAM,MAAM,sBAAsB,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAE5D,MAAM,MAAM,YAAY,CACtB,UAAU,SAAS,MAAM,EACzB,MAAM,SAAS,WAAW,GAAG,WAAW,IACtC,MAAM,SAAS,IAAI,GACnB;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,GACD;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEN,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,IAAI;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EA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AAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEN,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,IAAI;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,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,244 @@
|
|
|
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
|
+
* Returned by a fenced write whose lease is no longer current: a higher token
|
|
60
|
+
* has been issued, or the lease has ended. The write changed nothing, and its
|
|
61
|
+
* holder must stop.
|
|
62
|
+
*/
|
|
63
|
+
export type LeaseLost = {
|
|
64
|
+
status: "lost";
|
|
65
|
+
};
|
|
66
|
+
export declare function isLeaseLost(value: unknown): value is LeaseLost;
|
|
67
|
+
/**
|
|
68
|
+
* What a delivery reports once its durable work is finished:
|
|
69
|
+
* - `completed`: the workflow returned a result;
|
|
70
|
+
* - `suspended`: the unfinished step is recorded, and `wakeAt`, when present,
|
|
71
|
+
* is the earliest time a paused step needs the execution to run again;
|
|
72
|
+
* - `failed`: workflow code threw an uncaught error.
|
|
73
|
+
*
|
|
74
|
+
* Infrastructure errors are never outcomes: the delivery rejects instead.
|
|
75
|
+
*/
|
|
76
|
+
export type WorkflowRunOutcome = {
|
|
77
|
+
status: "completed";
|
|
78
|
+
result: unknown;
|
|
79
|
+
} | {
|
|
80
|
+
status: "suspended";
|
|
81
|
+
wakeAt?: number;
|
|
82
|
+
} | {
|
|
83
|
+
status: "failed";
|
|
84
|
+
error: Error;
|
|
85
|
+
};
|
|
86
|
+
export type ExecutionAdmissionRequest = {
|
|
87
|
+
executionId?: string;
|
|
88
|
+
workflowId: string;
|
|
89
|
+
params: EventParams;
|
|
90
|
+
context: EventContext;
|
|
91
|
+
};
|
|
92
|
+
export type ExecutionAdmissionResult = {
|
|
93
|
+
status: "accepted";
|
|
94
|
+
executionId: string;
|
|
95
|
+
} | {
|
|
96
|
+
status: "rejected";
|
|
97
|
+
code: ExecutionAdmissionErrorCode;
|
|
98
|
+
message: string;
|
|
99
|
+
};
|
|
100
|
+
export type WorkflowStartErrorCode = "INVALID_START_PARAMETERS" | "START_REQUEST_MISMATCH";
|
|
101
|
+
export type ExecutionStartRequest = {
|
|
102
|
+
/** Identifies the request: the calling execution and its step key. */
|
|
103
|
+
requestId: {
|
|
104
|
+
executionId: string;
|
|
105
|
+
stepKey: string;
|
|
106
|
+
};
|
|
107
|
+
workflowId: string;
|
|
108
|
+
params?: DurableObject;
|
|
109
|
+
};
|
|
110
|
+
export type ExecutionStartResult = {
|
|
111
|
+
status: "accepted";
|
|
112
|
+
executionId: string;
|
|
113
|
+
} | {
|
|
114
|
+
status: "rejected";
|
|
115
|
+
code: WorkflowStartErrorCode;
|
|
116
|
+
message: string;
|
|
117
|
+
};
|
|
118
|
+
export type ExecutionWakeResult = {
|
|
119
|
+
status: "requested";
|
|
120
|
+
} | {
|
|
121
|
+
status: "ignored";
|
|
122
|
+
} | {
|
|
123
|
+
status: "rejected";
|
|
124
|
+
code: "EXECUTION_NOT_FOUND";
|
|
125
|
+
message: string;
|
|
126
|
+
};
|
|
127
|
+
export type ExecutionAcknowledgeResult = {
|
|
128
|
+
status: "suspended";
|
|
129
|
+
} | ExecutionOutcome | LeaseLost;
|
|
130
|
+
export type ExecutionRenewResult = {
|
|
131
|
+
status: "renewed";
|
|
132
|
+
lease: ExecutionLease;
|
|
133
|
+
} | LeaseLost;
|
|
134
|
+
export type ExecutionReleaseResult = {
|
|
135
|
+
status: "released";
|
|
136
|
+
} | LeaseLost;
|
|
137
|
+
export interface ExecutionClient {
|
|
138
|
+
/**
|
|
139
|
+
* Creates the execution record with status `admitted` and makes it due
|
|
140
|
+
* immediately, all-or-nothing. Execution IDs are never reused.
|
|
141
|
+
*/
|
|
142
|
+
admit(request: ExecutionAdmissionRequest): Promise<ExecutionAdmissionResult>;
|
|
143
|
+
get(executionId: string): Promise<ExecutionRecord | undefined>;
|
|
144
|
+
/**
|
|
145
|
+
* Starts a workflow on behalf of the execution and step named by
|
|
146
|
+
* `requestId`, idempotently by that ID. A new start admits the target with
|
|
147
|
+
* the caller's context and a parent link to the caller, and records the
|
|
148
|
+
* start request, all-or-nothing. A repeated request returns the first
|
|
149
|
+
* target's ID if its workflow ID and canonical params match, and
|
|
150
|
+
* `START_REQUEST_MISMATCH` otherwise, whatever the target's status. Invalid
|
|
151
|
+
* params return `INVALID_START_PARAMETERS` and admit nothing. Not fenced.
|
|
152
|
+
*/
|
|
153
|
+
start(request: ExecutionStartRequest): Promise<ExecutionStartResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Requests a wake from outside a delivery, such as a store commit. Wakes not
|
|
156
|
+
* covered by a claimed delivery merge into one due time: the earliest.
|
|
157
|
+
*/
|
|
158
|
+
requestWake(request: {
|
|
159
|
+
executionId: string;
|
|
160
|
+
wakeAt: number;
|
|
161
|
+
}): Promise<ExecutionWakeResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Leases up to `limit` executions whose due time is at or before the runtime
|
|
164
|
+
* clock and that have no live lease, earliest due first. Each lease lasts
|
|
165
|
+
* `duration` milliseconds and carries a token greater than every earlier
|
|
166
|
+
* token for its execution. An execution has at most one live lease at a
|
|
167
|
+
* time, across every client sharing the backend.
|
|
168
|
+
*/
|
|
169
|
+
claimDue(request: {
|
|
170
|
+
limit: number;
|
|
171
|
+
duration: number;
|
|
172
|
+
}): Promise<ExecutionLease[]>;
|
|
173
|
+
/**
|
|
174
|
+
* Extends a lease to `duration` milliseconds from now. Returns `lost` if a
|
|
175
|
+
* higher token has been issued or the lease has ended. An expired lease
|
|
176
|
+
* that has not been claimed again is still current.
|
|
177
|
+
*/
|
|
178
|
+
renew(request: {
|
|
179
|
+
lease: ExecutionLease;
|
|
180
|
+
duration: number;
|
|
181
|
+
}): Promise<ExecutionRenewResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Ends a lease without acknowledging an outcome. The delivery counts as
|
|
184
|
+
* unacknowledged, so the execution becomes claimable again only after the
|
|
185
|
+
* redelivery delay. Returns `lost` for a stale lease.
|
|
186
|
+
*/
|
|
187
|
+
release(request: {
|
|
188
|
+
lease: ExecutionLease;
|
|
189
|
+
}): Promise<ExecutionReleaseResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Records a delivery's outcome and ends its lease, all-or-nothing. A
|
|
192
|
+
* `suspended` outcome clears the wakes the lease covered, leaving the
|
|
193
|
+
* execution due at the earliest of `wakeAt` and any wake requested since the
|
|
194
|
+
* claim. A stale lease returns `lost` and changes nothing.
|
|
195
|
+
*/
|
|
196
|
+
acknowledge(request: {
|
|
197
|
+
lease: ExecutionLease;
|
|
198
|
+
outcome: WorkflowRunOutcome;
|
|
199
|
+
}): Promise<ExecutionAcknowledgeResult>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Thrown by the driver when a fenced write returns `lost`: another claim has
|
|
203
|
+
* taken over the execution, so this delivery must stop without acknowledging.
|
|
204
|
+
*/
|
|
205
|
+
export declare class LeaseLostError extends Error {
|
|
206
|
+
readonly executionId: string;
|
|
207
|
+
constructor(executionId: string);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Thrown by the driver when the current holder writes a step record that
|
|
211
|
+
* already exists with a different value. The recorded value stands: the
|
|
212
|
+
* delivery ends as a retry, and the next delivery replays the recorded value.
|
|
213
|
+
*/
|
|
214
|
+
export declare class StepConflictError extends Error {
|
|
215
|
+
readonly executionId: string;
|
|
216
|
+
readonly stepKey: string;
|
|
217
|
+
constructor(executionId: string, stepKey: string);
|
|
218
|
+
}
|
|
219
|
+
export declare class ExecutionAdmissionError extends Error {
|
|
220
|
+
readonly code: ExecutionAdmissionErrorCode;
|
|
221
|
+
constructor(code: ExecutionAdmissionErrorCode, message: string);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Thrown to workflow code by `step.start` when the runtime rejects the start.
|
|
225
|
+
* The rejection is recorded as the step's result, so replay throws it again.
|
|
226
|
+
*/
|
|
227
|
+
export declare class WorkflowStartError extends Error {
|
|
228
|
+
readonly code: WorkflowStartErrorCode;
|
|
229
|
+
constructor(code: WorkflowStartErrorCode, message: string);
|
|
230
|
+
}
|
|
231
|
+
declare const INFRASTRUCTURE_ERROR: unique symbol;
|
|
232
|
+
/**
|
|
233
|
+
* Wraps a failure of the runtime rather than of workflow code, such as a heap
|
|
234
|
+
* or store client rejecting. A delivery that hits one rejects without
|
|
235
|
+
* resuming workflow code, and is not acknowledged.
|
|
236
|
+
*/
|
|
237
|
+
export declare class InfrastructureError extends Error {
|
|
238
|
+
readonly [INFRASTRUCTURE_ERROR] = true;
|
|
239
|
+
constructor(cause: unknown);
|
|
240
|
+
static is(value: unknown): value is InfrastructureError;
|
|
241
|
+
}
|
|
242
|
+
export declare function isTerminalExecutionStatus(status: ExecutionStatus): status is "completed" | "failed";
|
|
243
|
+
export {};
|
|
244
|
+
//# 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;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACxC;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,YAAY,CA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A2B,CAAC;gBAE/B,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM;CAK/D;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAK1D;AAED,QAAA,MAAM,oBAAoB,eAA8C,CAAC;AAEzE;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,CAAC,oBAAoB,CAAC,QAAQ;gBAE3B,KAAK,EAAE,OAAO;IAK1B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB;CAOxD;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,eAAe,GACtB,MAAM,IAAI,WAAW,GAAG,QAAQ,CAElC"}
|
package/dist/base/heap.d.ts
CHANGED
|
@@ -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
|
-
|
|
26
|
+
lease: ExecutionLease;
|
|
15
27
|
stepKey: string;
|
|
16
28
|
stepAttempt: number;
|
|
17
|
-
|
|
29
|
+
done: boolean;
|
|
18
30
|
stepResponseJson: string;
|
|
19
|
-
}): Promise<
|
|
31
|
+
}): Promise<HeapRecord | LeaseLost>;
|
|
20
32
|
}
|
|
21
33
|
//# sourceMappingURL=heap.d.ts.map
|
package/dist/base/heap.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/base/invoker.d.ts
CHANGED
|
@@ -1,7 +1,52 @@
|
|
|
1
1
|
import type { EventEmitter } from "node:events";
|
|
2
|
-
import type {
|
|
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
|
-
|
|
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,
|
|
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"}
|