@workflow/core 5.0.0-beta.9 → 5.0.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.
- package/README.md +41 -0
- package/dist/attribute-changes.d.ts +4 -5
- package/dist/attribute-changes.d.ts.map +1 -1
- package/dist/attribute-changes.js +12 -4
- package/dist/capabilities.d.ts +35 -2
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +74 -5
- package/dist/capture-stack.d.ts +1 -1
- package/dist/capture-stack.js +2 -2
- 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 +15 -0
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +72 -4
- package/dist/context-violation-error.d.ts +5 -5
- package/dist/context-violation-error.d.ts.map +1 -1
- package/dist/context-violation-error.js +8 -6
- package/dist/create-hook.d.ts +109 -7
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/define-hook.js +2 -2
- package/dist/describe-error.d.ts +7 -7
- package/dist/describe-error.d.ts.map +1 -1
- package/dist/describe-error.js +46 -7
- package/dist/encryption.d.ts +32 -4
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +85 -10
- package/dist/events-consumer.d.ts +300 -0
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +672 -42
- package/dist/flushable-stream.d.ts +97 -1
- package/dist/flushable-stream.d.ts.map +1 -1
- package/dist/flushable-stream.js +286 -10
- package/dist/global.d.ts +38 -2
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +21 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/log-format.d.ts +6 -2
- package/dist/log-format.d.ts.map +1 -1
- package/dist/log-format.js +60 -15
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +13 -7
- package/dist/private.d.ts +258 -9
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +640 -7
- package/dist/replay-divergence.d.ts +25 -0
- package/dist/replay-divergence.d.ts.map +1 -0
- package/dist/replay-divergence.js +61 -0
- package/dist/replay-payload-cache.d.ts +64 -0
- package/dist/replay-payload-cache.d.ts.map +1 -0
- package/dist/replay-payload-cache.js +158 -0
- package/dist/runtime/compute-instance.d.ts +13 -0
- package/dist/runtime/compute-instance.d.ts.map +1 -0
- package/dist/runtime/compute-instance.js +14 -0
- package/dist/runtime/constants.d.ts +298 -5
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +500 -17
- 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 +100 -0
- package/dist/runtime/deployment-guard.d.ts.map +1 -0
- package/dist/runtime/deployment-guard.js +159 -0
- package/dist/runtime/dynamic-workflow.d.ts +182 -0
- package/dist/runtime/dynamic-workflow.d.ts.map +1 -0
- package/dist/runtime/dynamic-workflow.js +382 -0
- package/dist/runtime/get-port-lazy.d.ts +15 -0
- package/dist/runtime/get-port-lazy.d.ts.map +1 -1
- package/dist/runtime/get-port-lazy.js +75 -6
- package/dist/runtime/get-world-lazy.d.ts +5 -14
- package/dist/runtime/get-world-lazy.d.ts.map +1 -1
- package/dist/runtime/get-world-lazy.js +19 -29
- package/dist/runtime/helpers.d.ts +445 -29
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +717 -62
- package/dist/runtime/hook-wake.d.ts +122 -0
- package/dist/runtime/hook-wake.d.ts.map +1 -0
- package/dist/runtime/hook-wake.js +225 -0
- package/dist/runtime/invocations.d.ts +35 -0
- package/dist/runtime/invocations.d.ts.map +1 -0
- package/dist/runtime/invocations.js +172 -0
- package/dist/runtime/lifecycle-hooks.d.ts +93 -0
- package/dist/runtime/lifecycle-hooks.d.ts.map +1 -0
- package/dist/runtime/lifecycle-hooks.js +178 -0
- package/dist/runtime/open-hook-wait-state.d.ts +55 -0
- package/dist/runtime/open-hook-wait-state.d.ts.map +1 -0
- package/dist/runtime/open-hook-wait-state.js +93 -0
- package/dist/runtime/quickjs-assets.generated.d.ts +21 -0
- package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
- package/dist/runtime/quickjs-assets.generated.js +37 -0
- package/dist/runtime/quickjs-entrypoint.d.ts +130 -0
- package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/quickjs-entrypoint.js +2411 -0
- package/dist/runtime/quickjs-log-view.d.ts +152 -0
- package/dist/runtime/quickjs-log-view.d.ts.map +1 -0
- package/dist/runtime/quickjs-log-view.js +266 -0
- package/dist/runtime/quickjs-runtime.d.ts +299 -0
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
- package/dist/runtime/quickjs-runtime.js +2844 -0
- package/dist/runtime/quickjs-serde.d.ts +107 -0
- package/dist/runtime/quickjs-serde.d.ts.map +1 -0
- package/dist/runtime/quickjs-serde.js +2234 -0
- package/dist/runtime/quickjs-snapshot-codec.d.ts +74 -0
- package/dist/runtime/quickjs-snapshot-codec.d.ts.map +1 -0
- package/dist/runtime/quickjs-snapshot-codec.js +159 -0
- package/dist/runtime/replay-budget.d.ts +17 -18
- package/dist/runtime/replay-budget.d.ts.map +1 -1
- package/dist/runtime/replay-budget.js +33 -81
- 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 +93 -8
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +709 -110
- package/dist/runtime/resume-latency.d.ts +150 -0
- package/dist/runtime/resume-latency.d.ts.map +1 -0
- package/dist/runtime/resume-latency.js +155 -0
- 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-spec-version.d.ts +16 -0
- package/dist/runtime/run-spec-version.d.ts.map +1 -0
- package/dist/runtime/run-spec-version.js +19 -0
- package/dist/runtime/run.d.ts +72 -7
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +295 -58
- package/dist/runtime/runs.d.ts +54 -3
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +148 -21
- package/dist/runtime/start.d.ts +164 -3
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +736 -89
- package/dist/runtime/step-executor.d.ts +186 -5
- package/dist/runtime/step-executor.d.ts.map +1 -1
- package/dist/runtime/step-executor.js +759 -125
- package/dist/runtime/step-latency.d.ts +221 -0
- package/dist/runtime/step-latency.d.ts.map +1 -0
- package/dist/runtime/step-latency.js +215 -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 +71 -0
- package/dist/runtime/suspension-handler.d.ts +279 -10
- package/dist/runtime/suspension-handler.d.ts.map +1 -1
- package/dist/runtime/suspension-handler.js +1442 -169
- package/dist/runtime/unserializable-step.d.ts +34 -0
- package/dist/runtime/unserializable-step.d.ts.map +1 -0
- package/dist/runtime/unserializable-step.js +52 -0
- package/dist/runtime/vm-mode.d.ts +88 -0
- package/dist/runtime/vm-mode.d.ts.map +1 -0
- package/dist/runtime/vm-mode.js +140 -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 +106 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -0
- package/dist/runtime/wait-continuation.js +136 -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 +32 -0
- package/dist/runtime/world-compatibility.d.ts.map +1 -0
- package/dist/runtime/world-compatibility.js +44 -0
- package/dist/runtime/world-init.d.ts +17 -42
- package/dist/runtime/world-init.d.ts.map +1 -1
- package/dist/runtime/world-init.js +18 -43
- package/dist/runtime/world.d.ts +14 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +75 -19
- package/dist/runtime.d.ts +11 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +4117 -446
- 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 +3 -3
- package/dist/serialization/client.d.ts.map +1 -1
- package/dist/serialization/client.js +8 -4
- package/dist/serialization/codec-devalue-vm.d.ts +16 -0
- package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
- package/dist/serialization/codec-devalue-vm.js +148 -0
- package/dist/serialization/codec-devalue.d.ts +1 -1
- package/dist/serialization/codec-devalue.d.ts.map +1 -1
- package/dist/serialization/codec-devalue.js +24 -6
- package/dist/serialization/codec.d.ts +37 -2
- package/dist/serialization/codec.d.ts.map +1 -1
- package/dist/serialization/codec.js +2 -2
- package/dist/serialization/compression.d.ts +130 -0
- package/dist/serialization/compression.d.ts.map +1 -0
- package/dist/serialization/compression.js +316 -0
- package/dist/serialization/encryption.d.ts +119 -17
- package/dist/serialization/encryption.d.ts.map +1 -1
- package/dist/serialization/encryption.js +152 -17
- package/dist/serialization/errors.d.ts +13 -0
- package/dist/serialization/errors.d.ts.map +1 -1
- package/dist/serialization/errors.js +20 -2
- package/dist/serialization/format.d.ts +6 -6
- package/dist/serialization/format.js +7 -7
- package/dist/serialization/hardened.d.ts +164 -0
- package/dist/serialization/hardened.d.ts.map +1 -0
- package/dist/serialization/hardened.js +554 -0
- package/dist/serialization/index.d.ts +10 -8
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/index.js +10 -8
- 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.map +1 -1
- package/dist/serialization/reducers/class.js +11 -6
- 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 +661 -0
- package/dist/serialization/reducers/common.d.ts +1 -1
- package/dist/serialization/reducers/common.d.ts.map +1 -1
- package/dist/serialization/reducers/common.js +227 -66
- 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.map +1 -1
- package/dist/serialization/reducers/step-function.js +25 -9
- package/dist/serialization/step.d.ts +4 -4
- package/dist/serialization/step.d.ts.map +1 -1
- package/dist/serialization/step.js +9 -5
- package/dist/serialization/types.d.ts +75 -1
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +15 -1
- package/dist/serialization/workflow-vm.d.ts +29 -0
- package/dist/serialization/workflow-vm.d.ts.map +1 -0
- package/dist/serialization/workflow-vm.js +74 -0
- package/dist/serialization-format.d.ts +64 -8
- package/dist/serialization-format.d.ts.map +1 -1
- package/dist/serialization-format.js +239 -73
- package/dist/serialization.d.ts +319 -34
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +1961 -321
- package/dist/set-attributes.d.ts +7 -7
- package/dist/set-attributes.d.ts.map +1 -1
- package/dist/set-attributes.js +42 -21
- package/dist/set-error-stack.d.ts +12 -0
- package/dist/set-error-stack.d.ts.map +1 -0
- package/dist/set-error-stack.js +30 -0
- package/dist/source-map.d.ts +25 -0
- package/dist/source-map.d.ts.map +1 -1
- package/dist/source-map.js +113 -7
- package/dist/step/context-storage.d.ts +50 -3
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +7 -5
- package/dist/step/writable-stream.d.ts +3 -3
- package/dist/step/writable-stream.d.ts.map +1 -1
- package/dist/step/writable-stream.js +53 -19
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +142 -28
- package/dist/symbols.d.ts +35 -1
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +36 -2
- package/dist/telemetry/semantic-conventions.d.ts +509 -2
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +363 -3
- package/dist/telemetry.d.ts +91 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +244 -17
- package/dist/test-support/orchestrator-context.d.ts +25 -0
- package/dist/test-support/orchestrator-context.d.ts.map +1 -0
- package/dist/test-support/orchestrator-context.js +107 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +76 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -15
- 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 +84 -14
- package/dist/vm/script-cache.d.ts +26 -0
- package/dist/vm/script-cache.d.ts.map +1 -0
- package/dist/vm/script-cache.js +131 -0
- package/dist/vm/uint8array-base64.js +1 -1
- package/dist/workflow/abort-controller.d.ts +2 -2
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +75 -21
- 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 +65 -0
- package/dist/workflow/create-hook.d.ts.map +1 -1
- package/dist/workflow/create-hook.js +24 -3
- package/dist/workflow/get-workflow-metadata.js +2 -2
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +403 -53
- package/dist/workflow/index.d.ts +1 -1
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +2 -2
- package/dist/workflow/set-attributes.d.ts +19 -21
- package/dist/workflow/set-attributes.d.ts.map +1 -1
- package/dist/workflow/set-attributes.js +23 -25
- package/dist/workflow/sleep.d.ts.map +1 -1
- package/dist/workflow/sleep.js +42 -13
- package/dist/workflow/world-init-stub.d.ts +3 -3
- package/dist/workflow/world-init-stub.js +4 -4
- package/dist/workflow.d.ts +89 -3
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +920 -568
- package/docs/api-reference/create-hook.mdx +170 -10
- package/docs/api-reference/create-webhook.mdx +16 -15
- package/docs/api-reference/define-hook.mdx +41 -33
- package/docs/api-reference/fatal-error.mdx +30 -8
- package/docs/api-reference/fetch.mdx +14 -10
- package/docs/api-reference/get-step-metadata.mdx +2 -2
- package/docs/api-reference/get-workflow-metadata.mdx +3 -3
- package/docs/api-reference/get-writable.mdx +7 -7
- package/docs/api-reference/index.mdx +3 -3
- package/docs/api-reference/retryable-error.mdx +1 -1
- package/docs/api-reference/set-attributes.mdx +63 -0
- package/docs/api-reference/sleep.mdx +4 -4
- package/docs/foundations/cancellation.mdx +31 -32
- package/docs/foundations/errors-and-retries.mdx +54 -11
- package/docs/foundations/hooks.mdx +187 -36
- package/docs/foundations/idempotency.mdx +267 -12
- package/docs/foundations/index.mdx +1 -26
- package/docs/foundations/serialization.mdx +22 -22
- package/docs/foundations/starting-workflows.mdx +104 -30
- package/docs/foundations/streaming.mdx +108 -60
- package/docs/foundations/versioning.mdx +4 -4
- package/docs/foundations/workflows-and-steps.mdx +10 -10
- package/docs/how-it-works/cancellation.mdx +63 -63
- package/docs/how-it-works/code-transform.mdx +82 -66
- package/docs/how-it-works/encryption.mdx +30 -26
- package/docs/how-it-works/event-sourcing.mdx +132 -35
- package/docs/how-it-works/framework-integrations.mdx +96 -337
- package/docs/how-it-works/understanding-directives.mdx +22 -22
- package/package.json +29 -15
- 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 -779
- package/docs/api-reference/experimental-set-attributes.mdx +0 -63
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invocation-scoped, one-shot reporter for a replay-divergence recovery.
|
|
3
|
+
*
|
|
4
|
+
* The reporter stays dormant until replay reaches a valid deterministic
|
|
5
|
+
* boundary. The first subsequent event write carries the telemetry for free.
|
|
6
|
+
* A recovered invocation with no natural event write intentionally reports
|
|
7
|
+
* nothing.
|
|
8
|
+
*/
|
|
9
|
+
export class ReplayRecoveryReporter {
|
|
10
|
+
divergenceCount;
|
|
11
|
+
active = false;
|
|
12
|
+
reported = false;
|
|
13
|
+
constructor(divergenceCount) {
|
|
14
|
+
this.divergenceCount = divergenceCount;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A reporter for an invocation that never diverged: `activate()` cannot arm
|
|
18
|
+
* it, so `withEventCreate` always passes writes through untouched. Lets every
|
|
19
|
+
* call site hold a non-optional reporter instead of branching on one.
|
|
20
|
+
*
|
|
21
|
+
* Structurally inert rather than a zero-count reporter on purpose: the
|
|
22
|
+
* server rejects a count below 1 as out-of-range and emits a
|
|
23
|
+
* `telemetry_rejected` metric, so a reporter that *can* report zero is a
|
|
24
|
+
* live footgun.
|
|
25
|
+
*/
|
|
26
|
+
static inert() {
|
|
27
|
+
return new InertReplayRecoveryReporter();
|
|
28
|
+
}
|
|
29
|
+
activate() {
|
|
30
|
+
this.active = true;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decorate one natural event write with recovery telemetry.
|
|
34
|
+
*
|
|
35
|
+
* The claim is taken synchronously, so concurrent suspension writes cannot
|
|
36
|
+
* all carry the same count. A failed request releases it for a later natural
|
|
37
|
+
* write in the same invocation.
|
|
38
|
+
*/
|
|
39
|
+
async withEventCreate(params, create) {
|
|
40
|
+
if (!this.active || this.reported)
|
|
41
|
+
return create(params);
|
|
42
|
+
this.reported = true;
|
|
43
|
+
try {
|
|
44
|
+
return await create({
|
|
45
|
+
...params,
|
|
46
|
+
replayDivergenceCount: this.divergenceCount,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.reported = false;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** See {@link ReplayRecoveryReporter.inert}. */
|
|
56
|
+
class InertReplayRecoveryReporter extends ReplayRecoveryReporter {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(0);
|
|
59
|
+
}
|
|
60
|
+
activate() {
|
|
61
|
+
// Deliberately empty: nothing to report, so nothing can arm.
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVwbGF5LXJlY292ZXJ5LXJlcG9ydGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3J1bnRpbWUvcmVwbGF5LXJlY292ZXJ5LXJlcG9ydGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBOzs7Ozs7O0dBT0c7QUFDSCxNQUFNLE9BQU8sc0JBQXNCO0lBSUo7SUFIckIsTUFBTSxHQUFHLEtBQUssQ0FBQztJQUNmLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFFekIsWUFBNkIsZUFBdUI7UUFBdkIsb0JBQWUsR0FBZixlQUFlLENBQVE7SUFBRyxDQUFDO0lBRXhEOzs7Ozs7Ozs7T0FTRztJQUNILE1BQU0sQ0FBQyxLQUFLO1FBQ1YsT0FBTyxJQUFJL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FpdCBjcmVhdGUoe1xuICAgICAgICAuLi5wYXJhbXMsXG4gICAgICAgIHJlcGxheURpdmVyZ2VuY2VDb3VudDogdGhpcy5kaXZlcmdlbmNlQ291bnQsXG4gICAgICB9KTtcbiAgICB9IGNhdGNoIChlcnJvcikge1xuICAgICAgdGhpcy5yZXBvcnRlZCA9IGZhbHNlO1xuICAgICAgdGhyb3cgZXJyb3I7XG4gICAgfVxuICB9XG59XG5cbi8qKiBTZWUge0BsaW5rIFJlcGxheVJlY292ZXJ5UmVwb3J0ZXIuaW5lcnR9LiAqL1xuY2xhc3MgSW5lcnRSZXBsYXlSZWNvdmVyeVJlcG9ydGVyIGV4dGVuZHMgUmVwbGF5UmVjb3ZlcnlSZXBvcnRlciB7XG4gIGNvbnN0cnVjdG9yKCkge1xuICAgIHN1cGVyKDApO1xuICB9XG5cbiAgb3ZlcnJpZGUgYWN0aXZhdGUoKTogdm9pZCB7XG4gICAgLy8gRGVsaWJlcmF0ZWx5IGVtcHR5OiBub3RoaW5nIHRvIHJlcG9ydCwgc28gbm90aGluZyBjYW4gYXJtLlxuICB9XG59XG4iXX0=
|
|
@@ -1,23 +1,107 @@
|
|
|
1
|
-
import { type Hook } from '@workflow/world';
|
|
2
|
-
import { type
|
|
1
|
+
import { type Hook as WorldHook } from '@workflow/world';
|
|
2
|
+
import { type PayloadKey } from '../serialization.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A hook record with its serialized `metadata` omitted: everything a resume
|
|
5
|
+
* actually reads. Resuming never looks at metadata, so the resume path accepts
|
|
6
|
+
* both a raw {@link WorldHook} straight out of a World and a {@link Hook}
|
|
7
|
+
* whose `metadata` is a Promise.
|
|
8
|
+
*/
|
|
9
|
+
type ResumableHook = Omit<WorldHook, 'metadata'>;
|
|
10
|
+
/**
|
|
11
|
+
* A hook as returned by {@link getHookByToken} and {@link resumeHook}: the
|
|
12
|
+
* World's {@link WorldHook} record with its user-defined `metadata` hydrated
|
|
13
|
+
* lazily.
|
|
14
|
+
*
|
|
15
|
+
* `metadata` is a getter that returns a Promise — the same shape as
|
|
16
|
+
* `Run.returnValue` — so looking a hook up by token costs exactly one read.
|
|
17
|
+
* Hydrating metadata is a decrypting READ that needs the owning run's payload
|
|
18
|
+
* keys, and resolving those can cost a run fetch plus a `run-key` API round
|
|
19
|
+
* trip (~350ms). Deferring that to first access keeps the lookup fast for the
|
|
20
|
+
* many callers that only need `runId`/`token` — most importantly hook
|
|
21
|
+
* resumption, which never reads metadata at all.
|
|
22
|
+
*
|
|
23
|
+
* The promise is memoized: hydration (and the key resolution behind it) runs at
|
|
24
|
+
* most once per hook object. Awaiting it on a hook that stored no metadata
|
|
25
|
+
* resolves `undefined` and performs no I/O.
|
|
26
|
+
*
|
|
27
|
+
* Like `Run.returnValue`, the accessor is non-enumerable, so it is absent from
|
|
28
|
+
* `{ ...hook }` and `JSON.stringify(hook)` — read it explicitly and include the
|
|
29
|
+
* awaited value if you need to forward it.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const hook = await getHookByToken(token);
|
|
35
|
+
* console.log(hook.runId); // no metadata work
|
|
36
|
+
* const metadata = (await hook.metadata) as { allowedUserId?: string } | undefined;
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface Hook extends ResumableHook {
|
|
40
|
+
/**
|
|
41
|
+
* The hook's user-defined metadata, hydrated on first access and memoized.
|
|
42
|
+
* Resolves `undefined` when the hook carries no metadata.
|
|
43
|
+
*/
|
|
44
|
+
readonly metadata: Promise<unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the hook by token to find the associated workflow run.
|
|
48
|
+
*
|
|
49
|
+
* This is a single read. The returned hook's `metadata` is a getter that
|
|
50
|
+
* resolves a Promise (see {@link Hook}), so the run fetch and
|
|
51
|
+
* `run-key` round trip that hydrating it can require are only paid by callers
|
|
52
|
+
* that actually await it:
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const hook = await getHookByToken(token);
|
|
56
|
+
* const metadata = await hook.metadata;
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* A Hook kept by minimum retention remains available here after its run ends,
|
|
60
|
+
* but cannot be resumed.
|
|
7
61
|
*
|
|
8
62
|
* @param token - The unique token identifying the hook
|
|
9
63
|
*/
|
|
10
64
|
export declare function getHookByToken(token: string): Promise<Hook>;
|
|
65
|
+
/**
|
|
66
|
+
* The result of {@link resumeHook}: a {@link Hook} augmented
|
|
67
|
+
* with an optional resilience signal.
|
|
68
|
+
*
|
|
69
|
+
* `resilientResume` is retained for source compatibility and is never set.
|
|
70
|
+
* `resumeHook()` now requires the durable `hook_received` write and workflow
|
|
71
|
+
* wake to both succeed before it resolves. Treat the result as a plain
|
|
72
|
+
* {@link Hook}.
|
|
73
|
+
*/
|
|
74
|
+
export type ResumedHook = Hook & {
|
|
75
|
+
resilientResume?: boolean;
|
|
76
|
+
};
|
|
11
77
|
/**
|
|
12
78
|
* Resumes a workflow run by sending a payload to a hook identified by its token.
|
|
13
79
|
*
|
|
14
80
|
* This function is called externally (e.g., from an API route or server action)
|
|
15
81
|
* to send data to a hook and resume the associated workflow run.
|
|
16
82
|
*
|
|
83
|
+
* On an invoke-capable World, the serialized input is delivered to the run's
|
|
84
|
+
* executor, which inspects it, writes `hook_received`, then responds. Resolving
|
|
85
|
+
* means the executor accepted and persisted it, not that user code consumed it.
|
|
86
|
+
* Other Worlds write the event here and then await queue acceptance of its wake.
|
|
87
|
+
* On the existing path, a failure after the event write may leave a committed
|
|
88
|
+
* event whose wake was not accepted. On the invoke path, a transport failure
|
|
89
|
+
* leaves the executor's outcome unknown; do not retry by directly writing an
|
|
90
|
+
* event. Event and response persistence may be separate backend operations.
|
|
91
|
+
*
|
|
92
|
+
* Prefer passing the token string over a cached {@link Hook} object. A token
|
|
93
|
+
* is looked up fresh, so the live backend can attest its atomic resume claim
|
|
94
|
+
* and the durable write becomes idempotent-on-retry (transport retries of the
|
|
95
|
+
* same write converge on one event). A supplied Hook object may carry a stale
|
|
96
|
+
* attestation, so it is deliberately ignored and the write is claim-less —
|
|
97
|
+
* meaning a lost response cannot be retried safely: retrying at the
|
|
98
|
+
* application level mints a fresh claim and can commit a second
|
|
99
|
+
* `hook_received`.
|
|
100
|
+
*
|
|
17
101
|
* @param tokenOrHook - The unique token identifying the hook, or the hook object itself
|
|
18
102
|
* @param payload - The data payload to send to the hook
|
|
19
|
-
* @returns Promise resolving to the
|
|
20
|
-
* @throws
|
|
103
|
+
* @returns Promise resolving to the {@link ResumedHook}
|
|
104
|
+
* @throws {HookNotFoundError} If the Hook does not exist or its run has ended
|
|
21
105
|
*
|
|
22
106
|
* @example
|
|
23
107
|
*
|
|
@@ -37,7 +121,7 @@ export declare function getHookByToken(token: string): Promise<Hook>;
|
|
|
37
121
|
* }
|
|
38
122
|
* ```
|
|
39
123
|
*/
|
|
40
|
-
export declare function resumeHook<T = any>(tokenOrHook: string |
|
|
124
|
+
export declare function resumeHook<T = any>(tokenOrHook: string | ResumableHook, payload: T, encryptionKeyOverride?: PayloadKey): Promise<ResumedHook>;
|
|
41
125
|
/**
|
|
42
126
|
* Resumes a webhook by sending a {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request}
|
|
43
127
|
* object to a hook identified by its token.
|
|
@@ -74,4 +158,5 @@ export declare function resumeHook<T = any>(tokenOrHook: string | Hook, payload:
|
|
|
74
158
|
* ```
|
|
75
159
|
*/
|
|
76
160
|
export declare function resumeWebhook(token: string, request: Request): Promise<Response>;
|
|
161
|
+
export {};
|
|
77
162
|
//# sourceMappingURL=resume-hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resume-hook.d.ts","sourceRoot":"","sources":["../../src/runtime/resume-hook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resume-hook.d.ts","sourceRoot":"","sources":["../../src/runtime/resume-hook.ts"],"names":[],"mappings":"AAQA,OAAO,EASL,KAAK,IAAI,IAAI,SAAS,EACvB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAC;AA6B7B;;;;;GAKG;AACH,KAAK,aAAa,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,IAAK,SAAQ,aAAa;IACzC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACrC;AAiLD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjE;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAsB,UAAU,CAAC,CAAC,GAAG,GAAG,EACtC,WAAW,EAAE,MAAM,GAAG,aAAa,EACnC,OAAO,EAAE,CAAC,EACV,qBAAqB,CAAC,EAAE,UAAU,GACjC,OAAO,CAAC,WAAW,CAAC,CAoBtB;AA2lBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAuFnB"}
|