@workflow/core 5.0.0-beta.4 → 5.0.0-beta.40
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/attribute-changes.d.ts +7 -0
- package/dist/attribute-changes.d.ts.map +1 -0
- package/dist/attribute-changes.js +25 -0
- package/dist/capabilities.d.ts +33 -1
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +71 -4
- package/dist/capture-stack.d.ts +16 -0
- package/dist/capture-stack.d.ts.map +1 -0
- package/dist/capture-stack.js +21 -0
- package/dist/class-serialization.d.ts +32 -0
- package/dist/class-serialization.d.ts.map +1 -1
- package/dist/class-serialization.js +37 -1
- package/dist/classify-error.d.ts +26 -3
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +109 -6
- package/dist/context-errors.d.ts +27 -0
- package/dist/context-errors.d.ts.map +1 -0
- package/dist/context-errors.js +101 -0
- package/dist/context-violation-error.d.ts +97 -0
- package/dist/context-violation-error.d.ts.map +1 -0
- package/dist/context-violation-error.js +149 -0
- package/dist/correlation-id.d.ts +109 -0
- package/dist/correlation-id.d.ts.map +1 -0
- package/dist/correlation-id.js +139 -0
- package/dist/create-hook.d.ts +62 -4
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +4 -3
- package/dist/define-hook.d.ts.map +1 -1
- package/dist/define-hook.js +20 -5
- package/dist/describe-error.d.ts +70 -0
- package/dist/describe-error.d.ts.map +1 -0
- package/dist/describe-error.js +189 -0
- package/dist/encryption.d.ts +37 -3
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +97 -31
- package/dist/events-consumer.d.ts +26 -1
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +105 -18
- package/dist/flushable-stream.d.ts +65 -10
- package/dist/flushable-stream.d.ts.map +1 -1
- package/dist/flushable-stream.js +131 -18
- package/dist/global.d.ts +37 -1
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +21 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/log-format.d.ts +25 -0
- package/dist/log-format.d.ts.map +1 -0
- package/dist/log-format.js +250 -0
- package/dist/logger.d.ts +29 -30
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +82 -32
- package/dist/private.d.ts +178 -9
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +273 -9
- package/dist/replay-payload-cache.d.ts +68 -0
- package/dist/replay-payload-cache.d.ts.map +1 -0
- package/dist/replay-payload-cache.js +160 -0
- package/dist/runtime/compute-instance.d.ts +12 -0
- package/dist/runtime/compute-instance.d.ts.map +1 -0
- package/dist/runtime/compute-instance.js +13 -0
- package/dist/runtime/constants.d.ts +237 -0
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +405 -15
- package/dist/runtime/count-step-started-events.d.ts +52 -0
- package/dist/runtime/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/count-step-started-events.js +72 -0
- package/dist/runtime/deployment-guard.d.ts +99 -0
- package/dist/runtime/deployment-guard.d.ts.map +1 -0
- package/dist/runtime/deployment-guard.js +154 -0
- package/dist/runtime/get-port-lazy.d.ts +25 -0
- package/dist/runtime/get-port-lazy.d.ts.map +1 -0
- package/dist/runtime/get-port-lazy.js +92 -0
- package/dist/runtime/get-world-lazy.d.ts +23 -0
- package/dist/runtime/get-world-lazy.d.ts.map +1 -0
- package/dist/runtime/get-world-lazy.js +46 -0
- package/dist/runtime/helpers.d.ts +219 -10
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +414 -40
- package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
- package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
- package/dist/runtime/quickjs-assets.generated.js +30 -0
- package/dist/runtime/quickjs-entrypoint.d.ts +124 -0
- package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/quickjs-entrypoint.js +1429 -0
- package/dist/runtime/quickjs-runtime.d.ts +193 -0
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
- package/dist/runtime/quickjs-runtime.js +1944 -0
- package/dist/runtime/replay-budget.d.ts +98 -0
- package/dist/runtime/replay-budget.d.ts.map +1 -0
- package/dist/runtime/replay-budget.js +192 -0
- package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
- package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
- package/dist/runtime/replay-recovery-reporter.js +64 -0
- package/dist/runtime/resume-hook.d.ts +27 -4
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +448 -76
- package/dist/runtime/run-id-time.d.ts +19 -0
- package/dist/runtime/run-id-time.d.ts.map +1 -0
- package/dist/runtime/run-id-time.js +42 -0
- package/dist/runtime/run.d.ts +8 -2
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +62 -15
- package/dist/runtime/runs.d.ts +54 -3
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +117 -10
- package/dist/runtime/start.d.ts +70 -1
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +312 -54
- package/dist/runtime/step-executor.d.ts +177 -0
- package/dist/runtime/step-executor.d.ts.map +1 -0
- package/dist/runtime/step-executor.js +949 -0
- package/dist/runtime/step-latency.d.ts +197 -0
- package/dist/runtime/step-latency.d.ts.map +1 -0
- package/dist/runtime/step-latency.js +207 -0
- package/dist/runtime/step-ownership.d.ts +72 -0
- package/dist/runtime/step-ownership.d.ts.map +1 -0
- package/dist/runtime/step-ownership.js +114 -0
- package/dist/runtime/step-single-flight.d.ts +12 -0
- package/dist/runtime/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/step-single-flight.js +69 -0
- package/dist/runtime/suspension-handler.d.ts +102 -7
- package/dist/runtime/suspension-handler.d.ts.map +1 -1
- package/dist/runtime/suspension-handler.js +439 -140
- package/dist/runtime/vm-mode.d.ts +44 -0
- package/dist/runtime/vm-mode.d.ts.map +1 -0
- package/dist/runtime/vm-mode.js +62 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
- package/dist/runtime/vm-serde-bundle.generated.js +16 -0
- package/dist/runtime/wait-continuation.d.ts +84 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -0
- package/dist/runtime/wait-continuation.js +105 -0
- package/dist/runtime/wait-until.d.ts +18 -0
- package/dist/runtime/wait-until.d.ts.map +1 -0
- package/dist/runtime/wait-until.js +42 -0
- package/dist/runtime/world-compatibility.d.ts +5 -0
- package/dist/runtime/world-compatibility.d.ts.map +1 -0
- package/dist/runtime/world-compatibility.js +12 -0
- package/dist/runtime/world-init.d.ts +50 -0
- package/dist/runtime/world-init.d.ts.map +1 -0
- package/dist/runtime/world-init.js +50 -0
- package/dist/runtime/world.d.ts +14 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +101 -26
- package/dist/runtime.d.ts +17 -12
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3078 -327
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +1 -1
- package/dist/sealed-box.d.ts +167 -0
- package/dist/sealed-box.d.ts.map +1 -0
- package/dist/sealed-box.js +571 -0
- package/dist/serialization/client.d.ts +17 -0
- package/dist/serialization/client.d.ts.map +1 -0
- package/dist/serialization/client.js +48 -0
- package/dist/serialization/codec-devalue-vm.d.ts +9 -0
- package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
- package/dist/serialization/codec-devalue-vm.js +137 -0
- package/dist/serialization/codec-devalue.d.ts +14 -0
- package/dist/serialization/codec-devalue.d.ts.map +1 -0
- package/dist/serialization/codec-devalue.js +105 -0
- package/dist/serialization/codec.d.ts +125 -0
- package/dist/serialization/codec.d.ts.map +1 -0
- package/dist/serialization/codec.js +17 -0
- package/dist/serialization/compression.d.ts +104 -0
- package/dist/serialization/compression.d.ts.map +1 -0
- package/dist/serialization/compression.js +260 -0
- package/dist/serialization/encryption.d.ts +134 -0
- package/dist/serialization/encryption.d.ts.map +1 -0
- package/dist/serialization/encryption.js +186 -0
- package/dist/serialization/errors.d.ts +34 -0
- package/dist/serialization/errors.d.ts.map +1 -0
- package/dist/serialization/errors.js +59 -0
- package/dist/serialization/format.d.ts +60 -0
- package/dist/serialization/format.d.ts.map +1 -0
- package/dist/serialization/format.js +97 -0
- package/dist/serialization/hardened.d.ts +155 -0
- package/dist/serialization/hardened.d.ts.map +1 -0
- package/dist/serialization/hardened.js +523 -0
- package/dist/serialization/index.d.ts +20 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +22 -0
- package/dist/serialization/reducers/class-vm.d.ts +20 -0
- package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/class-vm.js +77 -0
- package/dist/serialization/reducers/class.d.ts +11 -0
- package/dist/serialization/reducers/class.d.ts.map +1 -0
- package/dist/serialization/reducers/class.js +73 -0
- package/dist/serialization/reducers/common-vm.d.ts +15 -0
- package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/common-vm.js +579 -0
- package/dist/serialization/reducers/common.d.ts +16 -0
- package/dist/serialization/reducers/common.d.ts.map +1 -0
- package/dist/serialization/reducers/common.js +478 -0
- package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
- package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/step-function-vm.js +97 -0
- package/dist/serialization/reducers/step-function.d.ts +35 -0
- package/dist/serialization/reducers/step-function.d.ts.map +1 -0
- package/dist/serialization/reducers/step-function.js +104 -0
- package/dist/serialization/step.d.ts +17 -0
- package/dist/serialization/step.d.ts.map +1 -0
- package/dist/serialization/step.js +48 -0
- package/dist/serialization/types.d.ts +273 -0
- package/dist/serialization/types.d.ts.map +1 -0
- package/dist/serialization/types.js +35 -0
- package/dist/serialization/vm-bundle-entry.d.ts +12 -0
- package/dist/serialization/vm-bundle-entry.d.ts.map +1 -0
- package/dist/serialization/vm-bundle-entry.js +58 -0
- package/dist/serialization/workflow-vm.d.ts +24 -0
- package/dist/serialization/workflow-vm.d.ts.map +1 -0
- package/dist/serialization/workflow-vm.js +66 -0
- package/dist/serialization/workflow.d.ts +29 -0
- package/dist/serialization/workflow.d.ts.map +1 -0
- package/dist/serialization/workflow.js +54 -0
- package/dist/serialization-format.d.ts +60 -4
- package/dist/serialization-format.d.ts.map +1 -1
- package/dist/serialization-format.js +276 -56
- package/dist/serialization.d.ts +374 -221
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +2300 -783
- package/dist/set-attributes.d.ts +13 -0
- package/dist/set-attributes.d.ts.map +1 -0
- package/dist/set-attributes.js +60 -0
- package/dist/sleep.d.ts.map +1 -1
- package/dist/sleep.js +3 -2
- package/dist/source-map.d.ts +25 -0
- package/dist/source-map.d.ts.map +1 -1
- package/dist/source-map.js +148 -10
- package/dist/step/context-storage.d.ts +61 -2
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +7 -5
- package/dist/step/get-closure-vars.d.ts.map +1 -1
- package/dist/step/get-closure-vars.js +3 -2
- package/dist/step/get-step-metadata.d.ts.map +1 -1
- package/dist/step/get-step-metadata.js +3 -2
- package/dist/step/get-workflow-metadata.d.ts.map +1 -1
- package/dist/step/get-workflow-metadata.js +3 -2
- package/dist/step/writable-stream.d.ts.map +1 -1
- package/dist/step/writable-stream.js +71 -7
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +226 -30
- package/dist/symbols.d.ts +54 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +55 -1
- package/dist/telemetry/semantic-conventions.d.ts +242 -2
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +173 -1
- package/dist/telemetry.d.ts +73 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +153 -16
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +23 -1
- package/dist/util.d.ts +16 -6
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +25 -16
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/vm/index.d.ts.map +1 -1
- package/dist/vm/index.js +77 -9
- package/dist/vm/script-cache.d.ts +28 -0
- package/dist/vm/script-cache.d.ts.map +1 -0
- package/dist/vm/script-cache.js +140 -0
- package/dist/workflow/abort-controller.d.ts +65 -0
- package/dist/workflow/abort-controller.d.ts.map +1 -0
- package/dist/workflow/abort-controller.js +314 -0
- package/dist/workflow/attribute-dispatcher.d.ts +6 -0
- package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
- package/dist/workflow/attribute-dispatcher.js +48 -0
- package/dist/workflow/create-hook.d.ts.map +1 -1
- package/dist/workflow/create-hook.js +25 -3
- package/dist/workflow/define-hook.d.ts +1 -1
- package/dist/workflow/define-hook.d.ts.map +1 -1
- package/dist/workflow/define-hook.js +8 -4
- package/dist/workflow/get-workflow-metadata.d.ts.map +1 -1
- package/dist/workflow/get-workflow-metadata.js +14 -3
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +303 -37
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +5 -3
- package/dist/workflow/set-attributes.d.ts +68 -0
- package/dist/workflow/set-attributes.d.ts.map +1 -0
- package/dist/workflow/set-attributes.js +60 -0
- package/dist/workflow/sleep.d.ts.map +1 -1
- package/dist/workflow/sleep.js +58 -9
- package/dist/workflow/world-init-stub.d.ts +15 -0
- package/dist/workflow/world-init-stub.d.ts.map +1 -0
- package/dist/workflow/world-init-stub.js +15 -0
- package/dist/workflow.d.ts +69 -3
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +791 -554
- package/docs/api-reference/create-hook.mdx +79 -0
- package/docs/api-reference/create-webhook.mdx +1 -0
- package/docs/api-reference/define-hook.mdx +26 -24
- package/docs/api-reference/fatal-error.mdx +29 -7
- package/docs/api-reference/fetch.mdx +8 -4
- package/docs/api-reference/index.mdx +3 -0
- package/docs/api-reference/set-attributes.mdx +61 -0
- package/docs/api-reference/sleep.mdx +1 -1
- package/docs/foundations/cancellation.mdx +459 -0
- package/docs/foundations/errors-and-retries.mdx +7 -3
- package/docs/foundations/hooks.mdx +29 -0
- package/docs/foundations/idempotency.mdx +243 -11
- package/docs/foundations/index.mdx +1 -23
- package/docs/foundations/meta.json +3 -1
- package/docs/foundations/serialization.mdx +77 -41
- package/docs/foundations/starting-workflows.mdx +79 -2
- package/docs/foundations/streaming.mdx +14 -23
- package/docs/foundations/versioning.mdx +263 -0
- package/docs/how-it-works/cancellation.mdx +287 -0
- package/docs/how-it-works/code-transform.mdx +21 -17
- package/docs/how-it-works/encryption.mdx +5 -5
- package/docs/how-it-works/event-sourcing.mdx +6 -6
- package/docs/how-it-works/framework-integrations.mdx +96 -337
- package/docs/how-it-works/meta.json +2 -1
- package/package.json +31 -13
- package/dist/runtime/step-handler.d.ts +0 -2
- package/dist/runtime/step-handler.d.ts.map +0 -1
- package/dist/runtime/step-handler.js +0 -678
package/dist/private.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utils used by the bundler when transforming code
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { WorldCapabilities } from '@workflow/world';
|
|
5
|
+
import type { CorrelationIdGenerator } from './correlation-id.js';
|
|
5
6
|
import type { EventsConsumer } from './events-consumer.js';
|
|
6
7
|
import type { QueueItem } from './global.js';
|
|
8
|
+
import type { ReplayPayloadCache } from './replay-payload-cache.js';
|
|
7
9
|
import type { Serializable } from './schemas.js';
|
|
10
|
+
import type { PayloadKey } from './serialization/encryption.js';
|
|
8
11
|
export type StepFunction<Args extends Serializable[] = any[], Result extends Serializable | unknown = unknown> = ((...args: Args) => Promise<Result>) & {
|
|
9
12
|
maxRetries?: number;
|
|
10
13
|
stepId?: string;
|
|
@@ -25,8 +28,19 @@ export declare function registerStepFunction(stepId: string, stepFn: StepFunctio
|
|
|
25
28
|
export declare function getStepFunction(stepId: string): StepFunction | undefined;
|
|
26
29
|
export interface WorkflowOrchestratorContext {
|
|
27
30
|
runId: string;
|
|
28
|
-
encryptionKey:
|
|
31
|
+
encryptionKey: PayloadKey | undefined;
|
|
32
|
+
worldCapabilities?: WorldCapabilities;
|
|
29
33
|
globalThis: typeof globalThis;
|
|
34
|
+
/**
|
|
35
|
+
* Increments when a suspension is accepted and on every retained-session
|
|
36
|
+
* resume. STEP suspension signals capture it when scheduled and no-op if
|
|
37
|
+
* it moved (see step.ts) — this drops same-boundary sibling signals and
|
|
38
|
+
* timers queued at boundary N that would fire after the session resumed
|
|
39
|
+
* into boundary N+1. Sleep/hook/attribute signals are intentionally
|
|
40
|
+
* unguarded: their presence makes the boundary unretainable, so a late
|
|
41
|
+
* signal correctly demotes the session (workflow.ts `onWorkflowError`).
|
|
42
|
+
*/
|
|
43
|
+
suspensionGeneration: number;
|
|
30
44
|
eventsConsumer: EventsConsumer;
|
|
31
45
|
/**
|
|
32
46
|
* Map of pending invocations keyed by correlationId.
|
|
@@ -34,7 +48,12 @@ export interface WorkflowOrchestratorContext {
|
|
|
34
48
|
*/
|
|
35
49
|
invocationsQueue: Map<string, QueueItem>;
|
|
36
50
|
onWorkflowError: (error: Error) => void;
|
|
37
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Mints a correlation id body for one entity family. Every entity a replay
|
|
53
|
+
* creates draws from here, and the family is what keeps a disagreement about
|
|
54
|
+
* one family's count from renumbering another's.
|
|
55
|
+
*/
|
|
56
|
+
generateCorrelationId: CorrelationIdGenerator;
|
|
38
57
|
generateNanoid: () => string;
|
|
39
58
|
/**
|
|
40
59
|
* Sequential promise queue that ensures all event-driven promise resolutions
|
|
@@ -46,18 +65,168 @@ export interface WorkflowOrchestratorContext {
|
|
|
46
65
|
promiseQueue: Promise<void>;
|
|
47
66
|
/**
|
|
48
67
|
* Counter of in-flight async data delivery operations (step result
|
|
49
|
-
* hydration, hook payload hydration). Suspensions
|
|
50
|
-
* to reach 0 before firing, to avoid preempting data
|
|
68
|
+
* hydration, hook payload hydration, abort signal hydration). Suspensions
|
|
69
|
+
* must wait for this to reach 0 before firing, to avoid preempting data
|
|
70
|
+
* delivery — e.g. dehydrating a step's arguments while an abort that should
|
|
71
|
+
* be reflected in those arguments is still hydrating its reason.
|
|
51
72
|
*/
|
|
52
73
|
pendingDeliveries: number;
|
|
74
|
+
/**
|
|
75
|
+
* Ordered registry of in-flight "branch-deciding" deliveries — the
|
|
76
|
+
* resolutions a workflow typically `Promise.race`s on, or awaits from
|
|
77
|
+
* independent concurrent branches: hook payloads (`hook_received`), wait
|
|
78
|
+
* completions (`wait_completed`), and step results (`step_completed` /
|
|
79
|
+
* `step_failed`). Keyed by the delivery's position (index) in the consumed
|
|
80
|
+
* event log.
|
|
81
|
+
*
|
|
82
|
+
* The problem: each of these resolutions reaches workflow code after a
|
|
83
|
+
* different, workload-dependent number of microtask hops. A buffered hook
|
|
84
|
+
* payload is observed via the async hook iterator (`yield await this`),
|
|
85
|
+
* costing extra hops; a `wait_completed` resolves with fewer, and a reused
|
|
86
|
+
* sleep can resolve in an entirely earlier loop iteration; a step result is
|
|
87
|
+
* gated on hydration whose cost varies between replays of the SAME
|
|
88
|
+
* invocation — the first replay pays the full decrypt/decompress/revive,
|
|
89
|
+
* while later replays sharing the invocation's `ReplayPayloadCache`
|
|
90
|
+
* memo-hit small primitive results and resolve in one or two hops. Either
|
|
91
|
+
* way, the resolution that the committed event log ordered first can lose a
|
|
92
|
+
* `Promise.race` (or a `useStep` ULID allocation) to a faster- or
|
|
93
|
+
* already-resolved competitor, diverging from the log and surfacing as
|
|
94
|
+
* `CorruptedEventLogError`.
|
|
95
|
+
*
|
|
96
|
+
* The fix is a strict, deterministic delivery order anchored on
|
|
97
|
+
* event-log position: a delivery does not resolve to the workflow until
|
|
98
|
+
* every relevant earlier-in-log delivery has been delivered. Because the
|
|
99
|
+
* gate is "the earlier delivery resolved", not "won a timing race", the
|
|
100
|
+
* outcome is independent of microtask hops, hydration/decryption time,
|
|
101
|
+
* and `Promise.race` argument order. Which earlier kinds a delivery defers
|
|
102
|
+
* behind is spelled out on {@link awaitEarlierDeliveries}.
|
|
103
|
+
*
|
|
104
|
+
* Index is used rather than the `eventId` string because `eventId` is an
|
|
105
|
+
* opaque, world-assigned value not guaranteed to sort in creation order
|
|
106
|
+
* (only the bundled ULID worlds happen to).
|
|
107
|
+
*
|
|
108
|
+
* Optional so older/out-of-tree contexts (and lightweight test harnesses)
|
|
109
|
+
* that do not initialize it degrade gracefully to the previous behavior.
|
|
110
|
+
*/
|
|
111
|
+
pendingDeliveryBarriers?: Map<number, DeliveryBarrierEntry>;
|
|
112
|
+
/**
|
|
113
|
+
* Invocation-scoped cache of prepared serialized payloads and immutable final
|
|
114
|
+
* values. Prepared bytes survive fresh replay VMs; object graphs do not.
|
|
115
|
+
*/
|
|
116
|
+
replayPayloadCache: ReplayPayloadCache;
|
|
117
|
+
}
|
|
118
|
+
/** The kind of branch-deciding delivery a barrier represents. */
|
|
119
|
+
export type DeliveryKind = 'hook' | 'wait' | 'step';
|
|
120
|
+
interface DeliveryBarrierEntry {
|
|
121
|
+
kind: DeliveryKind;
|
|
122
|
+
/** Resolves once this delivery has resolved to the workflow. */
|
|
123
|
+
delivered: Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Whether this delivery is committed to reaching the workflow without any
|
|
126
|
+
* further action by workflow code. True for wait completions and step
|
|
127
|
+
* results, which always resolve from their own chain, and for a hook payload
|
|
128
|
+
* that already had a waiting consumer when it was consumed.
|
|
129
|
+
*
|
|
130
|
+
* False for a BUFFERED hook payload no consumer has claimed yet: it is
|
|
131
|
+
* delivered by `claim()`, i.e. whenever the workflow next reads the hook —
|
|
132
|
+
* which may be causally *after* a later-in-log delivery. `arm()` flips it
|
|
133
|
+
* once a consumer takes the payload.
|
|
134
|
+
*/
|
|
135
|
+
armed: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Awaits, in strict event-log order, every still-registered delivery that is
|
|
139
|
+
* earlier in the log than `eventIndex` and that a delivery of `kind` defers
|
|
140
|
+
* behind (see {@link DEFER_BEHIND}), so that this resolution is handed to the
|
|
141
|
+
* workflow only after all relevant earlier-in-log deliveries have been. This
|
|
142
|
+
* is what keeps a `Promise.race` — or the ULID a follow-up `useStep` draws on
|
|
143
|
+
* a concurrent branch — deterministic and aligned with the committed event
|
|
144
|
+
* log, independent of microtask-hop counts, hydration time, or race-argument
|
|
145
|
+
* order. When this delivery does have to wait, it also yields a macrotask
|
|
146
|
+
* afterwards so the earlier delivery's consumer can run to its own next
|
|
147
|
+
* suspension point first; see the comment at that `await` for why ordering the
|
|
148
|
+
* `resolve()` calls alone is not enough.
|
|
149
|
+
*
|
|
150
|
+
* One asymmetry: a STEP result additionally skips any earlier delivery that
|
|
151
|
+
* will not resolve on its own, i.e. one blocked (directly or transitively) on
|
|
152
|
+
* a buffered hook payload no consumer has claimed. Such a payload is delivered
|
|
153
|
+
* only when the workflow next reads the hook, and reaching that read very
|
|
154
|
+
* commonly requires the step result itself (`await stepX()` before the read).
|
|
155
|
+
* Gating the step on it would stall the workflow until the barrier's idle
|
|
156
|
+
* safety net fires, which then releases every delivery queued behind that
|
|
157
|
+
* payload at once — losing exactly the race this ordering exists to protect.
|
|
158
|
+
* Waits and hooks keep gating on unclaimed payloads: for them, waiting for the
|
|
159
|
+
* claim IS the ordering guarantee (a `wait_completed` must not preempt a
|
|
160
|
+
* payload the log ordered first).
|
|
161
|
+
*/
|
|
162
|
+
export declare function awaitEarlierDeliveries(ctx: WorkflowOrchestratorContext, eventIndex: number | undefined, kind: DeliveryKind): Promise<void>;
|
|
163
|
+
/** Handle for a registered branch-deciding delivery barrier. */
|
|
164
|
+
export interface DeliveryBarrier {
|
|
165
|
+
/**
|
|
166
|
+
* Mark this delivery as delivered to the workflow. Resolves its
|
|
167
|
+
* `delivered` promise so any later-in-log delivery gated on it (via
|
|
168
|
+
* {@link awaitEarlierDeliveries}) may proceed, and removes it from the
|
|
169
|
+
* registry. Idempotent.
|
|
170
|
+
*/
|
|
171
|
+
markDelivered: () => void;
|
|
172
|
+
/**
|
|
173
|
+
* Mark this delivery as committed to happening, for a barrier registered
|
|
174
|
+
* unarmed (a buffered hook payload) once a consumer has claimed it. From
|
|
175
|
+
* then on a later step result may be ordered behind it. Idempotent.
|
|
176
|
+
*/
|
|
177
|
+
arm: () => void;
|
|
53
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Register a branch-deciding delivery at its event-log index so that later
|
|
181
|
+
* deliveries can be ordered strictly after it. Returns an inert handle when
|
|
182
|
+
* `pendingDeliveryBarriers` is not initialized.
|
|
183
|
+
*
|
|
184
|
+
* Pass `armed: false` for a delivery whose resolution waits on workflow code
|
|
185
|
+
* asking for it (a buffered hook payload); call `arm()` when it does.
|
|
186
|
+
*
|
|
187
|
+
* To guarantee a later delivery gated on this one can never hang when this
|
|
188
|
+
* delivery is abandoned (the workflow took a different branch or is
|
|
189
|
+
* suspending and never observes it), the barrier auto-resolves at idle.
|
|
190
|
+
*
|
|
191
|
+
* INVARIANT required of every call site: a barrier that is ever `armed` must
|
|
192
|
+
* be paired with a delivery chain that runs unconditionally — attached when
|
|
193
|
+
* the event is consumed (waits, step results, waiting-consumer hook payloads,
|
|
194
|
+
* aborts), or by the `claim()` whose invocation is what arms it (buffered
|
|
195
|
+
* hook payloads). The idle check ({@link scheduleWhenIdle}) refuses to
|
|
196
|
+
* observe idle while an armed, self-resolving barrier is undelivered, and the
|
|
197
|
+
* safety net below is itself idle-gated — so an armed barrier with no
|
|
198
|
+
* unconditional chain would livelock every idle check in the run, including
|
|
199
|
+
* its own retirement.
|
|
200
|
+
*/
|
|
201
|
+
export declare function registerDeliveryBarrier(ctx: WorkflowOrchestratorContext, eventIndex: number | undefined, kind: DeliveryKind, options?: {
|
|
202
|
+
armed?: boolean;
|
|
203
|
+
}): DeliveryBarrier;
|
|
54
204
|
/**
|
|
55
205
|
* Schedule a callback to fire only after all pending data deliveries
|
|
56
206
|
* (step results, hook payloads) and async deserialization have completed.
|
|
57
|
-
* Uses a polling loop: setTimeout(0) → check pendingDeliveries
|
|
58
|
-
* if
|
|
59
|
-
* delivery pattern where each hook
|
|
60
|
-
* async work to the promiseQueue.
|
|
207
|
+
* Uses a polling loop: setTimeout(0) → check pendingDeliveries and the
|
|
208
|
+
* barrier registry → if anything is still in flight, wait for promiseQueue →
|
|
209
|
+
* repeat. This handles the multi-round delivery pattern where each hook
|
|
210
|
+
* payload delivery cycle appends new async work to the promiseQueue.
|
|
211
|
+
*
|
|
212
|
+
* "In flight" is two distinct windows, each with its own guard:
|
|
213
|
+
* `pendingDeliveries > 0` covers hydration inside the serial queue slots, and
|
|
214
|
+
* {@link hasParkedCommittedDelivery} covers the detached gap between a slot
|
|
215
|
+
* releasing that counter and the delivery's `resolve()` actually running —
|
|
216
|
+
* deliberately outside `pendingDeliveries` (see step.ts), and invisible to it.
|
|
217
|
+
*
|
|
218
|
+
* The initial `setTimeout(0)` macrotask is load-bearing and must NOT be
|
|
219
|
+
* downgraded to a microtask (`queueMicrotask`/`Promise.resolve().then`).
|
|
220
|
+
* `pendingDeliveries` only guards the host-side hydration window; between a
|
|
221
|
+
* delivery's `resolve()` and the workflow VM body running its continuation to
|
|
222
|
+
* register the next subscriber, `pendingDeliveries` is already 0 even though
|
|
223
|
+
* the VM is mid-reaction. Node does not guarantee a microtask scheduled in
|
|
224
|
+
* the host context settles after the cross-VM promise chain (resolve in host
|
|
225
|
+
* → workflow code in VM → subscribe back in host); the macrotask boundary
|
|
226
|
+
* gives that chain time to run, so the suspension does not preempt a sibling
|
|
227
|
+
* delivery still in flight. Empirically, replacing it with `queueMicrotask`
|
|
228
|
+
* breaks hook/sleep `Promise.race` ordering (CorruptedEventLogError).
|
|
61
229
|
*/
|
|
62
230
|
export declare function scheduleWhenIdle(ctx: WorkflowOrchestratorContext, fn: () => void): void;
|
|
231
|
+
export {};
|
|
63
232
|
//# sourceMappingURL=private.d.ts.map
|
package/dist/private.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private.d.ts","sourceRoot":"","sources":["../src/private.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"private.d.ts","sourceRoot":"","sources":["../src/private.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,MAAM,YAAY,CACtB,IAAI,SAAS,YAAY,EAAE,GAAG,GAAG,EAAE,EACnC,MAAM,SAAS,YAAY,GAAG,OAAO,GAAG,OAAO,IAC7C,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAsEF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,QAGxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAoBxE;AAOD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,UAAU,GAAG,SAAS,CAAC;IACtC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B;;;;;;;;OAQG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACxC;;;;OAIG;IACH,qBAAqB,EAAE,sBAAsB,CAAC;IAC9C,cAAc,EAAE,MAAM,MAAM,CAAC;IAC7B;;;;;;OAMG;IACH,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B;;;;;;OAMG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC5D;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC;AAED,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,gEAAgE;IAChE,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;;;;;;;;OAUG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AA8FD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,2BAA2B,EAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B;;;;OAIG;IACH,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,2BAA2B,EAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAChC,eAAe,CAuCjB;AA6CD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,2BAA2B,EAChC,EAAE,EAAE,MAAM,IAAI,GACb,IAAI,CAcN"}
|