@workflow/core 5.2.3 → 5.4.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/README.md +27 -0
- package/dist/capabilities.d.ts +2 -0
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +7 -1
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +3 -2
- package/dist/create-hook.d.ts +15 -0
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/events-consumer.d.ts +98 -6
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +198 -13
- package/dist/flushable-stream.js +11 -2
- package/dist/global.d.ts +6 -0
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +65 -35
- package/dist/private.d.ts +41 -2
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +39 -4
- package/dist/replay-payload-cache.d.ts +13 -2
- package/dist/replay-payload-cache.d.ts.map +1 -1
- package/dist/replay-payload-cache.js +20 -10
- package/dist/runtime/after-terminal-write.d.ts +33 -0
- package/dist/runtime/after-terminal-write.d.ts.map +1 -0
- package/dist/runtime/after-terminal-write.js +23 -0
- package/dist/runtime/child-run-completion-notify.d.ts +36 -0
- package/dist/runtime/child-run-completion-notify.d.ts.map +1 -0
- package/dist/runtime/child-run-completion-notify.js +97 -0
- package/dist/runtime/child-run-completion.d.ts +45 -0
- package/dist/runtime/child-run-completion.d.ts.map +1 -0
- package/dist/runtime/child-run-completion.js +192 -0
- package/dist/runtime/constants.d.ts +161 -176
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +194 -273
- package/dist/runtime/delivery.d.ts +270 -0
- package/dist/runtime/delivery.d.ts.map +1 -0
- package/dist/runtime/delivery.js +325 -0
- package/dist/runtime/deployment-guard.d.ts +8 -1
- package/dist/runtime/deployment-guard.d.ts.map +1 -1
- package/dist/runtime/deployment-guard.js +12 -6
- package/dist/runtime/get-port-lazy.d.ts.map +1 -1
- package/dist/runtime/get-port-lazy.js +77 -14
- package/dist/runtime/helpers.d.ts +50 -4
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +88 -10
- package/dist/runtime/hook-creation.d.ts +45 -0
- package/dist/runtime/hook-creation.d.ts.map +1 -0
- package/dist/runtime/hook-creation.js +98 -0
- package/dist/runtime/hook-wake.d.ts +16 -14
- package/dist/runtime/hook-wake.d.ts.map +1 -1
- package/dist/runtime/hook-wake.js +31 -18
- package/dist/runtime/invocations.d.ts.map +1 -1
- package/dist/runtime/invocations.js +9 -3
- package/dist/runtime/out-of-band-observation.d.ts +28 -17
- package/dist/runtime/out-of-band-observation.d.ts.map +1 -1
- package/dist/runtime/out-of-band-observation.js +12 -3
- package/dist/runtime/quickjs-delivery-shared.d.ts +126 -0
- package/dist/runtime/quickjs-delivery-shared.d.ts.map +1 -0
- package/dist/runtime/quickjs-delivery-shared.js +176 -0
- package/dist/runtime/quickjs-log-view.d.ts +17 -0
- package/dist/runtime/quickjs-log-view.d.ts.map +1 -1
- package/dist/runtime/quickjs-log-view.js +31 -1
- package/dist/runtime/quickjs-pending-ops.d.ts +181 -0
- package/dist/runtime/quickjs-pending-ops.d.ts.map +1 -0
- package/dist/runtime/quickjs-pending-ops.js +633 -0
- package/dist/runtime/quickjs-runtime.d.ts +30 -5
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +546 -169
- package/dist/runtime/quickjs-serde.d.ts.map +1 -1
- package/dist/runtime/quickjs-serde.js +96 -5
- package/dist/runtime/replay-budget.d.ts +8 -1
- package/dist/runtime/replay-budget.d.ts.map +1 -1
- package/dist/runtime/replay-budget.js +12 -8
- package/dist/runtime/resume-hook.d.ts +15 -10
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +211 -65
- package/dist/runtime/run-spec-routing.d.ts +52 -0
- package/dist/runtime/run-spec-routing.d.ts.map +1 -0
- package/dist/runtime/run-spec-routing.js +78 -0
- package/dist/runtime/run-spec-version.d.ts +8 -4
- package/dist/runtime/run-spec-version.d.ts.map +1 -1
- package/dist/runtime/run-spec-version.js +11 -7
- package/dist/runtime/run.d.ts +29 -3
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +116 -11
- package/dist/runtime/runs.d.ts +58 -2
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +228 -30
- package/dist/runtime/spec8/constants.d.ts +177 -0
- package/dist/runtime/spec8/constants.d.ts.map +1 -0
- package/dist/runtime/spec8/constants.js +232 -0
- package/dist/runtime/spec8/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/spec8/count-step-started-events.js +72 -0
- package/dist/runtime/spec8/delivery.d.ts +6 -0
- package/dist/runtime/spec8/delivery.d.ts.map +1 -0
- package/dist/runtime/spec8/delivery.js +4250 -0
- package/dist/runtime/spec8/inline-steps-in-flight.d.ts +58 -0
- package/dist/runtime/spec8/inline-steps-in-flight.d.ts.map +1 -0
- package/dist/runtime/spec8/inline-steps-in-flight.js +104 -0
- package/dist/runtime/spec8/open-hook-wait-state.d.ts.map +1 -0
- package/dist/runtime/spec8/open-hook-wait-state.js +93 -0
- package/dist/runtime/{quickjs-entrypoint.d.ts → spec8/quickjs-entrypoint.d.ts} +0 -20
- package/dist/runtime/spec8/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/spec8/quickjs-entrypoint.js +1779 -0
- package/dist/runtime/{step-executor.d.ts → spec8/step-executor.d.ts} +11 -7
- package/dist/runtime/spec8/step-executor.d.ts.map +1 -0
- package/dist/runtime/spec8/step-executor.js +1134 -0
- package/dist/runtime/{step-ownership.d.ts → spec8/step-ownership.d.ts} +1 -1
- package/dist/runtime/spec8/step-ownership.d.ts.map +1 -0
- package/dist/runtime/spec8/step-ownership.js +114 -0
- package/dist/runtime/spec8/step-single-flight.d.ts +34 -0
- package/dist/runtime/spec8/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/spec8/step-single-flight.js +36 -0
- package/dist/runtime/{suspension-handler.d.ts → spec8/suspension-handler.d.ts} +68 -24
- package/dist/runtime/spec8/suspension-handler.d.ts.map +1 -0
- package/dist/runtime/spec8/suspension-handler.js +1291 -0
- package/dist/runtime/spec9/consume-after-commit.d.ts +33 -0
- package/dist/runtime/spec9/consume-after-commit.d.ts.map +1 -0
- package/dist/runtime/spec9/consume-after-commit.js +13 -0
- package/dist/runtime/spec9/consumed-position.d.ts +38 -0
- package/dist/runtime/spec9/consumed-position.d.ts.map +1 -0
- package/dist/runtime/spec9/consumed-position.js +48 -0
- package/dist/runtime/spec9/creator-rules.d.ts +220 -0
- package/dist/runtime/spec9/creator-rules.d.ts.map +1 -0
- package/dist/runtime/spec9/creator-rules.js +357 -0
- package/dist/runtime/spec9/deadline.d.ts +18 -0
- package/dist/runtime/spec9/deadline.d.ts.map +1 -0
- package/dist/runtime/spec9/deadline.js +27 -0
- package/dist/runtime/spec9/delivery.d.ts +17 -0
- package/dist/runtime/spec9/delivery.d.ts.map +1 -0
- package/dist/runtime/spec9/delivery.js +3837 -0
- package/dist/runtime/spec9/fence-refusals.d.ts +20 -0
- package/dist/runtime/spec9/fence-refusals.d.ts.map +1 -0
- package/dist/runtime/spec9/fence-refusals.js +55 -0
- package/dist/runtime/spec9/in-band-writer.d.ts +275 -0
- package/dist/runtime/spec9/in-band-writer.d.ts.map +1 -0
- package/dist/runtime/spec9/in-band-writer.js +831 -0
- package/dist/runtime/spec9/live-feed.d.ts +151 -0
- package/dist/runtime/spec9/live-feed.d.ts.map +1 -0
- package/dist/runtime/spec9/live-feed.js +311 -0
- package/dist/runtime/spec9/log-state.d.ts +137 -0
- package/dist/runtime/spec9/log-state.d.ts.map +1 -0
- package/dist/runtime/spec9/log-state.js +176 -0
- package/dist/runtime/spec9/quickjs-entrypoint.d.ts +185 -0
- package/dist/runtime/spec9/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/spec9/quickjs-entrypoint.js +2332 -0
- package/dist/runtime/spec9/read-deadline.d.ts +46 -0
- package/dist/runtime/spec9/read-deadline.d.ts.map +1 -0
- package/dist/runtime/spec9/read-deadline.js +88 -0
- package/dist/runtime/spec9/run-ahead.d.ts +65 -0
- package/dist/runtime/spec9/run-ahead.d.ts.map +1 -0
- package/dist/runtime/spec9/run-ahead.js +102 -0
- package/dist/runtime/spec9/step-delivery.d.ts +111 -0
- package/dist/runtime/spec9/step-delivery.d.ts.map +1 -0
- package/dist/runtime/spec9/step-delivery.js +149 -0
- package/dist/runtime/spec9/step-executor.d.ts +217 -0
- package/dist/runtime/spec9/step-executor.d.ts.map +1 -0
- package/dist/runtime/spec9/step-executor.js +782 -0
- package/dist/runtime/spec9/step-handler.d.ts +92 -0
- package/dist/runtime/spec9/step-handler.d.ts.map +1 -0
- package/dist/runtime/spec9/step-handler.js +375 -0
- package/dist/runtime/spec9/step-message.d.ts +42 -0
- package/dist/runtime/spec9/step-message.d.ts.map +1 -0
- package/dist/runtime/spec9/step-message.js +81 -0
- package/dist/runtime/spec9/step-retention.d.ts +44 -0
- package/dist/runtime/spec9/step-retention.d.ts.map +1 -0
- package/dist/runtime/spec9/step-retention.js +51 -0
- package/dist/runtime/spec9/step-single-flight.d.ts +19 -0
- package/dist/runtime/spec9/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/spec9/step-single-flight.js +24 -0
- package/dist/runtime/spec9/step-wait-creation.d.ts +162 -0
- package/dist/runtime/spec9/step-wait-creation.d.ts.map +1 -0
- package/dist/runtime/spec9/step-wait-creation.js +450 -0
- package/dist/runtime/spec9/suspension-handler.d.ts +125 -0
- package/dist/runtime/spec9/suspension-handler.d.ts.map +1 -0
- package/dist/runtime/spec9/suspension-handler.js +327 -0
- package/dist/runtime/spec9/wait-timer.d.ts +143 -0
- package/dist/runtime/spec9/wait-timer.d.ts.map +1 -0
- package/dist/runtime/spec9/wait-timer.js +173 -0
- package/dist/runtime/start-hook-binding.d.ts +50 -0
- package/dist/runtime/start-hook-binding.d.ts.map +1 -0
- package/dist/runtime/start-hook-binding.js +85 -0
- package/dist/runtime/start-hook-delivery.d.ts +47 -0
- package/dist/runtime/start-hook-delivery.d.ts.map +1 -0
- package/dist/runtime/start-hook-delivery.js +94 -0
- package/dist/runtime/start-hook-holder.d.ts +50 -0
- package/dist/runtime/start-hook-holder.d.ts.map +1 -0
- package/dist/runtime/start-hook-holder.js +149 -0
- package/dist/runtime/start.d.ts +76 -4
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +451 -62
- package/dist/runtime/step-latency.d.ts +3 -3
- package/dist/runtime/step-latency.js +1 -1
- package/dist/runtime/step-single-flight.d.ts +4 -8
- package/dist/runtime/step-single-flight.d.ts.map +1 -1
- package/dist/runtime/step-single-flight.js +23 -36
- package/dist/runtime/step-streams.d.ts +6 -0
- package/dist/runtime/step-streams.d.ts.map +1 -0
- package/dist/runtime/step-streams.js +40 -0
- package/dist/runtime/suspension-hooks.d.ts +84 -0
- package/dist/runtime/suspension-hooks.d.ts.map +1 -0
- package/dist/runtime/suspension-hooks.js +310 -0
- package/dist/runtime/wait-continuation.d.ts +27 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -1
- package/dist/runtime/wait-continuation.js +27 -2
- package/dist/runtime/world-compatibility.d.ts +22 -3
- package/dist/runtime/world-compatibility.d.ts.map +1 -1
- package/dist/runtime/world-compatibility.js +37 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +2 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +118 -4154
- package/dist/serialization/abort-stream.d.ts +11 -0
- package/dist/serialization/abort-stream.d.ts.map +1 -0
- package/dist/serialization/abort-stream.js +86 -0
- package/dist/serialization/reducers/common-vm.d.ts.map +1 -1
- package/dist/serialization/reducers/common-vm.js +39 -2
- package/dist/serialization/reducers/common.d.ts.map +1 -1
- package/dist/serialization/reducers/common.js +26 -3
- package/dist/serialization/types.d.ts +10 -1
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +1 -1
- package/dist/serialization.d.ts +21 -5
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +136 -79
- package/dist/set-attributes.d.ts.map +1 -1
- package/dist/set-attributes.js +9 -14
- package/dist/step/context-storage.d.ts +2 -0
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +1 -1
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +23 -16
- package/dist/telemetry/semantic-conventions.d.ts +218 -3
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +161 -2
- package/dist/test-support/append-only-world.d.ts +437 -0
- package/dist/test-support/append-only-world.d.ts.map +1 -0
- package/dist/test-support/append-only-world.js +816 -0
- package/dist/test-support/fence-snapshot.d.ts +11 -0
- package/dist/test-support/fence-snapshot.d.ts.map +1 -0
- package/dist/test-support/fence-snapshot.js +12 -0
- package/dist/test-support/load-events.d.ts +8 -0
- package/dist/test-support/load-events.d.ts.map +1 -0
- package/dist/test-support/load-events.js +27 -0
- package/dist/test-support/orchestrator-harness.d.ts +502 -0
- package/dist/test-support/orchestrator-harness.d.ts.map +1 -0
- package/dist/test-support/orchestrator-harness.js +116 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +7 -5
- package/dist/workflow/hook.d.ts +5 -0
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +83 -19
- package/dist/workflow.d.ts +45 -16
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +111 -50
- package/docs/api-reference/create-hook.mdx +8 -0
- package/docs/api-reference/create-webhook.mdx +1 -1
- package/docs/api-reference/fetch.mdx +2 -0
- package/docs/foundations/errors-and-retries.mdx +6 -0
- package/docs/foundations/hooks.mdx +3 -1
- package/docs/foundations/idempotency.mdx +190 -60
- package/docs/foundations/starting-workflows.mdx +3 -7
- package/docs/how-it-works/event-sourcing.mdx +6 -0
- package/package.json +5 -5
- package/dist/runtime/count-step-started-events.d.ts.map +0 -1
- package/dist/runtime/count-step-started-events.js +0 -72
- package/dist/runtime/open-hook-wait-state.d.ts.map +0 -1
- package/dist/runtime/open-hook-wait-state.js +0 -93
- package/dist/runtime/quickjs-entrypoint.d.ts.map +0 -1
- package/dist/runtime/quickjs-entrypoint.js +0 -2314
- package/dist/runtime/step-executor.d.ts.map +0 -1
- package/dist/runtime/step-executor.js +0 -1156
- package/dist/runtime/step-ownership.d.ts.map +0 -1
- package/dist/runtime/step-ownership.js +0 -114
- package/dist/runtime/suspension-handler.d.ts.map +0 -1
- package/dist/runtime/suspension-handler.js +0 -1562
- /package/dist/runtime/{count-step-started-events.d.ts → spec8/count-step-started-events.d.ts} +0 -0
- /package/dist/runtime/{open-hook-wait-state.d.ts → spec8/open-hook-wait-state.d.ts} +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Event, EventResult } from '@workflow/world';
|
|
2
|
+
/**
|
|
3
|
+
* How the orchestrator takes in a write of its own that resolves a promise in
|
|
4
|
+
* the workflow (a `wait_completed`, an inline step's `step_completed` or
|
|
5
|
+
* `step_failed`).
|
|
6
|
+
*
|
|
7
|
+
* Such a write can land above an out-of-band event the orchestrator has not
|
|
8
|
+
* seen yet: a background step's outcome, a `hook_received`, a
|
|
9
|
+
* `run_cancelled`. Every later replay consumes that lower event first, and
|
|
10
|
+
* resolution order is observable (correlation ids are minted in call order,
|
|
11
|
+
* and the deterministic clock follows the consumed event). So the VM consumes
|
|
12
|
+
* its own resolving event only after the write committed, and only after the
|
|
13
|
+
* events the write's skipped-slot report names, in position order:
|
|
14
|
+
*
|
|
15
|
+
* - report empty: consume the own event now;
|
|
16
|
+
* - report present and complete: merge it, then the own event;
|
|
17
|
+
* - report incomplete or truncated (`hasMore`): reload the log before
|
|
18
|
+
* continuing.
|
|
19
|
+
*
|
|
20
|
+
* There is no optimistic fast path that consumes the own event before the
|
|
21
|
+
* commit. The plan describes a structural check that would allow one, and a
|
|
22
|
+
* later refinement that would allow it while hooks, sleeps or background
|
|
23
|
+
* steps are open (single-orchestrator plan, section 4.5, "Later refinement,
|
|
24
|
+
* not needed now"). Neither is built.
|
|
25
|
+
*/
|
|
26
|
+
export type ConsumeAfterCommit = {
|
|
27
|
+
type: 'merged';
|
|
28
|
+
added: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'reload';
|
|
31
|
+
};
|
|
32
|
+
export declare function consumeOwnResolvingWrite(log: Event[], result: EventResult): ConsumeAfterCommit;
|
|
33
|
+
//# sourceMappingURL=consume-after-commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consume-after-commit.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec9/consume-after-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,KAAK,EAAE,EACZ,MAAM,EAAE,WAAW,GAClB,kBAAkB,CAWpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mergeReportedEvents } from '../helpers.js';
|
|
2
|
+
export function consumeOwnResolvingWrite(log, result) {
|
|
3
|
+
if (result.hasMore === true) {
|
|
4
|
+
return { type: 'reload' };
|
|
5
|
+
}
|
|
6
|
+
const own = result.event;
|
|
7
|
+
if (!own)
|
|
8
|
+
return { type: 'reload' };
|
|
9
|
+
const reported = (result.events ?? []).filter((event) => event.eventId !== own.eventId);
|
|
10
|
+
const added = mergeReportedEvents(log, [...reported, own]);
|
|
11
|
+
return { type: 'merged', added };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3VtZS1hZnRlci1jb21taXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcnVudGltZS9zcGVjOS9jb25zdW1lLWFmdGVyLWNvbW1pdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxlQUFlLENBQUM7QUE4QnBELE1BQU0sVUFBVSx3QkFBd0IsQ0FDdEMsR0FBWSxFQUNaLE1BQW1CO0lBRW5CLElBQUksTUFBTSxDQUFDLE9BQU8sS0FBSyxJQUFJLEVBQUUsQ0FBQztRQUM1QixPQUFPLEVBQUUsSUFBSSxFQUFFLFFBQVEsRUFBRSxDQUFDO0lBQzVCLENBQUM7SUFDRCxNQUFNLEdBQUcsR0FBRyxNQUFNLENBQUMsS0FBSyxDQUFDO0lBQ3pCLElBQUksQ0FBQyxHQUFHO1FBQUUsT0FBTyxFQUFFLElBQUksRUFBRSxRQUFRLEVBQUUsQ0FBQztJQUNwQyxNQUFNLFFBQVEsR0FBRyxDQUFDLE1BQU0sQ0FBQyxNQUFNLElBQUksRUFBRSxDQUFDLENBQUMsTUFBTSxDQUMzQyxDQUFDLEtBQUssRUFBRSxFQUFFLENBQUMsS0FBSyxDQUFDLE9BQU8sS0FBSyxHQUFHLENBQUMsT0FBTyxDQUN6QyxDQUFDO0lBQ0YsTUFBTSxLQUFLLEdBQUcsbUJBQW1CLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxRQUFRLEVBQUUsR0FBRyxDQUFDLENBQUMsQ0FBQztJQUMzRCxPQUFPLEVBQUUsSUFBSSxFQUFFLFFBQVEsRUFBRSxLQUFLLEVBQUUsQ0FB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c3VsdFxuKTogQ29uc3VtZUFmdGVyQ29tbWl0IHtcbiAgaWYgKHJlc3VsdC5oYXNNb3JlID09PSB0cnVlKSB7XG4gICAgcmV0dXJuIHsgdHlwZTogJ3JlbG9hZCcgfTtcbiAgfVxuICBjb25zdCBvd24gPSByZXN1bHQuZXZlbnQ7XG4gIGlmICghb3duKSByZXR1cm4geyB0eXBlOiAncmVsb2FkJyB9O1xuICBjb25zdCByZXBvcnRlZCA9IChyZXN1bHQuZXZlbnRzID8/IFtdKS5maWx0ZXIoXG4gICAgKGV2ZW50KSA9PiBldmVudC5ldmVudElkICE9PSBvd24uZXZlbnRJZFxuICApO1xuICBjb25zdCBhZGRlZCA9IG1lcmdlUmVwb3J0ZWRFdmVudHMobG9nLCBbLi4ucmVwb3J0ZWQsIG93bl0pO1xuICByZXR1cm4geyB0eXBlOiAnbWVyZ2VkJywgYWRkZWQgfTtcbn1cbiJdfQ==
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { World } from '@workflow/world';
|
|
2
|
+
/**
|
|
3
|
+
* The last position each run's orchestrator consumed in this process, so a
|
|
4
|
+
* wake that finds nothing new can be acknowledged without a replay.
|
|
5
|
+
*
|
|
6
|
+
* Every out-of-band writer sends an unkeyed wake after it commits, and a live
|
|
7
|
+
* orchestrator often consumes the event over the live feed before the wake is
|
|
8
|
+
* delivered. That delivery then has nothing to do. It reads the log tail
|
|
9
|
+
* (one small read), and when the tail slot equals the position recorded here
|
|
10
|
+
* and no recorded timer is due, it exits. A miss (another process ran the
|
|
11
|
+
* orchestrator, or this one restarted) costs only the normal replay.
|
|
12
|
+
*
|
|
13
|
+
* Recorded only after a delivery finished cleanly: its writes committed and
|
|
14
|
+
* it scheduled what it had to (step messages, timers). A position recorded
|
|
15
|
+
* before that would let a wake skip work the crashed delivery never did.
|
|
16
|
+
*/
|
|
17
|
+
export interface ConsumedPosition {
|
|
18
|
+
/** Highest slot the orchestrator had consumed when it suspended. */
|
|
19
|
+
slot: number;
|
|
20
|
+
/** Earliest `resumeAt` among the run's open waits, epoch ms. */
|
|
21
|
+
nextTimerAtMs?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function recordConsumedPosition(world: World, runId: string, position: ConsumedPosition): void;
|
|
24
|
+
export declare function hasConsumedPosition(world: World, runId: string): boolean;
|
|
25
|
+
export declare function forgetConsumedPosition(world: World, runId: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a delivery for `runId` whose log tail is at `tailSlot` has nothing
|
|
28
|
+
* to do.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isNoopDelivery(params: {
|
|
31
|
+
world: World;
|
|
32
|
+
runId: string;
|
|
33
|
+
tailSlot: number | undefined;
|
|
34
|
+
nowMs: number;
|
|
35
|
+
}): boolean;
|
|
36
|
+
/** Test hook. */
|
|
37
|
+
export declare function __resetConsumedPositionsForTests(world: World): void;
|
|
38
|
+
//# sourceMappingURL=consumed-position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumed-position.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec9/consumed-position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAiBD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,gBAAgB,GACzB,IAAI,CAQN;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAExE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAExE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAQV;AAED,iBAAiB;AACjB,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAEnE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const MAX_ENTRIES = 10_000;
|
|
2
|
+
// Held per World instance: a position is only meaningful against the log of
|
|
3
|
+
// the World it was read from.
|
|
4
|
+
// per-copy-ok: a second copy of this module only misses positions the first
|
|
5
|
+
// recorded, which costs a normal replay and never skips work.
|
|
6
|
+
const positionsByWorld = new WeakMap();
|
|
7
|
+
function positionsFor(world) {
|
|
8
|
+
let positions = positionsByWorld.get(world);
|
|
9
|
+
if (!positions) {
|
|
10
|
+
positions = new Map();
|
|
11
|
+
positionsByWorld.set(world, positions);
|
|
12
|
+
}
|
|
13
|
+
return positions;
|
|
14
|
+
}
|
|
15
|
+
export function recordConsumedPosition(world, runId, position) {
|
|
16
|
+
const positions = positionsFor(world);
|
|
17
|
+
positions.delete(runId);
|
|
18
|
+
positions.set(runId, position);
|
|
19
|
+
if (positions.size > MAX_ENTRIES) {
|
|
20
|
+
const oldest = positions.keys().next().value;
|
|
21
|
+
if (oldest !== undefined)
|
|
22
|
+
positions.delete(oldest);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function hasConsumedPosition(world, runId) {
|
|
26
|
+
return positionsFor(world).has(runId);
|
|
27
|
+
}
|
|
28
|
+
export function forgetConsumedPosition(world, runId) {
|
|
29
|
+
positionsFor(world).delete(runId);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether a delivery for `runId` whose log tail is at `tailSlot` has nothing
|
|
33
|
+
* to do.
|
|
34
|
+
*/
|
|
35
|
+
export function isNoopDelivery(params) {
|
|
36
|
+
const recorded = positionsFor(params.world).get(params.runId);
|
|
37
|
+
if (!recorded || params.tailSlot === undefined)
|
|
38
|
+
return false;
|
|
39
|
+
if (params.tailSlot !== recorded.slot)
|
|
40
|
+
return false;
|
|
41
|
+
return (recorded.nextTimerAtMs === undefined ||
|
|
42
|
+
recorded.nextTimerAtMs > params.nowMs);
|
|
43
|
+
}
|
|
44
|
+
/** Test hook. */
|
|
45
|
+
export function __resetConsumedPositionsForTests(world) {
|
|
46
|
+
positionsFor(world).clear();
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3VtZWQtcG9zaXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcnVudGltZS9zcGVjOS9jb25zdW1lZC1wb3NpdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUF3QkEsTUFBTSxXQUFXLEdBQUcsTUFBTSxDQUFDO0FBQzNCLDRFQUE0RTtBQUM1RSw4QkFBOEI7QUFDOUIsNEVBQTRFO0FBQzVFLDhEQUE4RDtBQUM5RCxNQUFNLGdCQUFnQixHQUFHLElBQUksT0FBTyxFQUF5QyxDQUFDO0FBQzlFLFNBQVMsWUFBWSxDQUFDLEtBQWE7SUFDakMsSUFBSSxTQUFTLEdBQUcsZ0JBQWdCLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQzVDLElBQUksQ0FBQyxTQUFTLEVBQUUsQ0FBQztRQUNmLFNBQVMsR0FBRyxJQUFJLEdBQUcsRUFBRSxDQUFDO1FBQ3RCLGdCQUFnQixDQUFDLEdBQUcsQ0FBQyxLQUFLLEVBQUUsU0FBUyxDQUFDLENBQUM7SUFDekMsQ0FBQztJQUNELE9BQU8sU0FBUyxDQUFDO0FBQ25CLENBQUM7QUFFRCxNQUFNLFVBQVUsc0JBQXNCLENBQ3BDLEtBQVksRUFDWixLQUFhLEV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3QgaG9vay4gKi9cbmV4cG9ydCBmdW5jdGlvbiBfX3Jlc2V0Q29uc3VtZWRQb3NpdGlvbnNGb3JUZXN0cyh3b3JsZDogV29ybGQpOiB2b2lkIHtcbiAgcG9zaXRpb25zRm9yKHdvcmxkKS5jbGVhcigpO1xufVxuIl19
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { type Event } from '@workflow/world';
|
|
2
|
+
/**
|
|
3
|
+
* How far inside the queue's dedupe window for a step key
|
|
4
|
+
* ({@link STEP_RESEND_MAX_AGE_MS}) the re-send rule stops: room for the
|
|
5
|
+
* clocks of the sender and the queue to differ, and for a re-send that
|
|
6
|
+
* starts just inside the bound to reach the queue.
|
|
7
|
+
*/
|
|
8
|
+
export declare const STEP_RESEND_DEDUPE_MARGIN_MS: number;
|
|
9
|
+
/**
|
|
10
|
+
* How old a step's last send may be for an orchestrator delivery to send its
|
|
11
|
+
* message again: {@link STEP_RESEND_DEDUPE_MARGIN_MS} inside the shortest
|
|
12
|
+
* time every World deduplicates a step's stable idempotency key
|
|
13
|
+
* (`QUEUE_MIN_STEP_KEY_DEDUPE_WINDOW_MS` in `@workflow/world`;
|
|
14
|
+
* `stepDispatchIdempotencyKey`). A send this young is deduped against the
|
|
15
|
+
* step's first message while that message lives, so a re-send never creates
|
|
16
|
+
* a second live message, which would be a second owner of the step's body.
|
|
17
|
+
* Nothing on the write path refuses a second `step_started` of a step that
|
|
18
|
+
* is still running, so this bound is what keeps a re-send from duplicating
|
|
19
|
+
* one. A re-send that reaches the queue after the step's message ended is
|
|
20
|
+
* marked (`stepResent`), and its first delivery reads the log and finds the
|
|
21
|
+
* step's outcome.
|
|
22
|
+
*/
|
|
23
|
+
export declare const STEP_RESEND_MAX_AGE_MS: number;
|
|
24
|
+
/** What {@link stepsToReenqueue} decided for one orchestrator delivery. */
|
|
25
|
+
export interface StepResends {
|
|
26
|
+
/** Steps whose message to send again, in log order. */
|
|
27
|
+
resend: string[];
|
|
28
|
+
/** Steps it would re-send but whose last send is past the age bound. */
|
|
29
|
+
tooOld: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Background steps this orchestrator delivery must enqueue again.
|
|
33
|
+
*
|
|
34
|
+
* A background step's message is enqueued once, right after its
|
|
35
|
+
* `step_created` commits. A delivery that dies between the commit and the
|
|
36
|
+
* enqueue leaves the step with no message, and nothing in the log says so.
|
|
37
|
+
* So every orchestrator delivery that is not the first delivery of its
|
|
38
|
+
* message (`deliveryCount` above 1: a redelivery after a crash, a lapsed
|
|
39
|
+
* lease or a rejection, a handoff continuation, a coalesced re-run, or a
|
|
40
|
+
* World that reports no count) re-sends every background step that has a
|
|
41
|
+
* `step_created` and no `step_started`, whichever delivery created it, once
|
|
42
|
+
* per invocation (see {@link invocationResends}). The queue guarantees such
|
|
43
|
+
* a delivery happens after any delivery that died: the dead delivery's
|
|
44
|
+
* message is redelivered, or coalesced into a running delivery, whose re-run
|
|
45
|
+
* reports the next count. A re-send keeps the step's stable idempotency key,
|
|
46
|
+
* so one whose first message still lives is deduped; a step created more
|
|
47
|
+
* than {@link STEP_RESEND_MAX_AGE_MS} ago is left alone (`tooOld`), because
|
|
48
|
+
* past the dedupe window a second message would be a second owner of its
|
|
49
|
+
* body.
|
|
50
|
+
*
|
|
51
|
+
* Inline steps are never enqueued here, with one exception: an inline step
|
|
52
|
+
* whose last event is the `step_retrying` that moved it to the background.
|
|
53
|
+
* The orchestrator delivery that ran the failed attempt writes it and stamps
|
|
54
|
+
* it with its own message (`creatorMessageId`, see
|
|
55
|
+
* {@link withRetryCreator}). A delivery that dies between that write and the
|
|
56
|
+
* enqueue of the step's retry message leaves the step with no message, and
|
|
57
|
+
* the orchestrator never runs it inline again (its retry belongs to its own
|
|
58
|
+
* message), so the same rule as a background step's creation closes the
|
|
59
|
+
* window: any orchestrator delivery that is not its message's first re-sends
|
|
60
|
+
* it, whichever delivery wrote the `step_retrying`, within the same age bound
|
|
61
|
+
* counted from that write. A `step_retrying` the step's own message wrote (a
|
|
62
|
+
* later attempt) carries no creator: that message stays unacknowledged until
|
|
63
|
+
* the step ends, so no orchestrator re-sends it. Nor does one from a log
|
|
64
|
+
* written before the stamp existed.
|
|
65
|
+
*
|
|
66
|
+
* `recovery` is a delivery of a message a World sent after it lost its
|
|
67
|
+
* queue (`reenqueueActiveRuns` with `queueLost`, world-local after a
|
|
68
|
+
* restart): every step message died with the queue, along with its dedupe
|
|
69
|
+
* state, so the delivery also re-sends steps that started and have no
|
|
70
|
+
* outcome, inline steps whose retry moved to the background included, and
|
|
71
|
+
* applies no age bound.
|
|
72
|
+
*/
|
|
73
|
+
export declare function stepsToReenqueue(params: {
|
|
74
|
+
events: readonly Event[];
|
|
75
|
+
deliveryCount: number | undefined;
|
|
76
|
+
nowMs: number;
|
|
77
|
+
recovery?: boolean;
|
|
78
|
+
/** Steps this invocation already re-sent, or found too old. */
|
|
79
|
+
exclude?: {
|
|
80
|
+
has(correlationId: string): boolean;
|
|
81
|
+
};
|
|
82
|
+
}): StepResends;
|
|
83
|
+
/**
|
|
84
|
+
* Whether an orchestrator delivery passes the re-send gate of
|
|
85
|
+
* {@link stepsToReenqueue}: it is not the first delivery of its message, or
|
|
86
|
+
* the World cannot say, or it is a recovery delivery.
|
|
87
|
+
*/
|
|
88
|
+
export declare function passesResendGate(params: {
|
|
89
|
+
deliveryCount: number | undefined;
|
|
90
|
+
recovery?: boolean;
|
|
91
|
+
}): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* What one invocation re-sent (see {@link stepsToReenqueue}), so its later
|
|
94
|
+
* passes and coalesced re-runs do not send it again.
|
|
95
|
+
*/
|
|
96
|
+
export interface InvocationResends {
|
|
97
|
+
/** Steps whose message this invocation re-sent. */
|
|
98
|
+
readonly sent: Set<string>;
|
|
99
|
+
/** Steps it left alone because their last send is past the age bound. */
|
|
100
|
+
readonly tooOld: Set<string>;
|
|
101
|
+
/** Whether a delivery of this invocation already ran the re-send pass. */
|
|
102
|
+
swept: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The re-send state of the invocation a delivery runs in. Coalesced re-runs
|
|
106
|
+
* of a delivery share the function invocation that ran it, which a World
|
|
107
|
+
* reports as `invocationStartedAt` (see `Queue.createQueueHandler`): they
|
|
108
|
+
* share this state, keyed by run, message and invocation start. Without
|
|
109
|
+
* `invocationStartedAt` every delivery is an invocation of its own. Bounded:
|
|
110
|
+
* the oldest invocation is forgotten past {@link MAX_TRACKED_INVOCATIONS}.
|
|
111
|
+
*/
|
|
112
|
+
export declare function invocationResends(params: {
|
|
113
|
+
runId: string;
|
|
114
|
+
messageId: string;
|
|
115
|
+
invocationStartedAt: number | undefined;
|
|
116
|
+
}): InvocationResends;
|
|
117
|
+
/**
|
|
118
|
+
* `data` with this orchestrator delivery's message (`messageId`) stamped as
|
|
119
|
+
* the creator when it is a `step_retrying`: the write that moves an inline
|
|
120
|
+
* step's retry to the background, which any later orchestrator delivery that
|
|
121
|
+
* is not its message's first may re-send (see {@link stepsToReenqueue}). Any
|
|
122
|
+
* other event is returned as is.
|
|
123
|
+
*/
|
|
124
|
+
export declare function withRetryCreator<T extends {
|
|
125
|
+
eventType: string;
|
|
126
|
+
eventData?: unknown;
|
|
127
|
+
}>(data: T, messageId: string | undefined): T;
|
|
128
|
+
/**
|
|
129
|
+
* The wait chains whose timers this orchestrator delivery arms, each named
|
|
130
|
+
* by its creator: the message whose delivery wrote the chain's
|
|
131
|
+
* `wait_created` events (`creatorMessageId`). A delivery that creates
|
|
132
|
+
* several waits arms only the earliest (see {@link waitTimersToArm}), so the
|
|
133
|
+
* rest of its chain waits for whoever completes that one.
|
|
134
|
+
*
|
|
135
|
+
* A delivery owns:
|
|
136
|
+
*
|
|
137
|
+
* - its own message's chain: the waits its message created (on a
|
|
138
|
+
* redelivery, in an earlier delivery of it), and those it is about to
|
|
139
|
+
* write;
|
|
140
|
+
* - the chain of every wait whose `wait_completed` it committed
|
|
141
|
+
* (`completedWaits`), whatever message it is. The delivery that completes
|
|
142
|
+
* a wait is the only one that knows the chain needs its next timer: the
|
|
143
|
+
* completing delivery may be a hook or step wake into which the queue
|
|
144
|
+
* coalesced the wait's timer, and a coalesced timer is never delivered;
|
|
145
|
+
* - on a redelivery of a timer message (`timerFor`, a crash or a rejected
|
|
146
|
+
* delivery), that timer's chain: an earlier delivery of the message may
|
|
147
|
+
* have completed the wait and died before it armed the next one.
|
|
148
|
+
*
|
|
149
|
+
* Every other delivery leaves a chain alone, so timer messages do not pile
|
|
150
|
+
* up across suspensions. A late or duplicate timer finds its wait completed
|
|
151
|
+
* and arms nothing.
|
|
152
|
+
*/
|
|
153
|
+
export declare function ownedWaitChains(params: {
|
|
154
|
+
events: readonly Event[];
|
|
155
|
+
messageId: string;
|
|
156
|
+
/** Waits whose `wait_completed` this delivery committed. */
|
|
157
|
+
completedWaits: Iterable<string>;
|
|
158
|
+
/** The wait a timer delivery is for. */
|
|
159
|
+
timerFor: string | undefined;
|
|
160
|
+
/** Whether this delivery is a redelivery of its message. */
|
|
161
|
+
redelivery: boolean;
|
|
162
|
+
}): Set<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Whether this orchestrator delivery may arm the timer of the open wait
|
|
165
|
+
* `correlationId`: the wait is in a chain it owns
|
|
166
|
+
* ({@link ownedWaitChains}), it is about to write the wait, or it is the
|
|
167
|
+
* wait's own timer delivery, which arrived before the wait was due (a timer
|
|
168
|
+
* is delivered a little early under clock skew) and re-arms what is left.
|
|
169
|
+
*/
|
|
170
|
+
export declare function schedulesWaitTimer(params: {
|
|
171
|
+
wait: Event | undefined;
|
|
172
|
+
correlationId: string;
|
|
173
|
+
timerFor: string | undefined;
|
|
174
|
+
ownedChains: ReadonlySet<string>;
|
|
175
|
+
}): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* The timers a delivery sends before it commits the `wait_completed` of each
|
|
178
|
+
* wait in `completing`: for each, the earliest open wait of its chain that
|
|
179
|
+
* is not being completed too. A chain's next timer is otherwise armed only
|
|
180
|
+
* by a delivery that holds the completion in memory (`ownedWaitChains`), so
|
|
181
|
+
* a delivery that commits the completion and fails before the send would
|
|
182
|
+
* leave the chain with no timer: its redelivery no longer knows it
|
|
183
|
+
* completed the wait, and the queue may coalesce that redelivery into a
|
|
184
|
+
* delivery that owns no chain. Sent first, the timer is either out before
|
|
185
|
+
* the completion commits, or the send failed, nothing committed, and the
|
|
186
|
+
* redelivery finds the wait still open and due and decides again. A
|
|
187
|
+
* duplicate timer is deduplicated by its hop's key, or finds its wait open
|
|
188
|
+
* and re-arms what is left, or completed and arms nothing.
|
|
189
|
+
*
|
|
190
|
+
* A timer delivery completing its own wait counts like any other: the
|
|
191
|
+
* redelivery of a timer owns its chain (`ownedWaitChains`), but a
|
|
192
|
+
* redelivery the queue coalesces into another delivery is never made. A
|
|
193
|
+
* wait with no recorded creator is left out: no delivery owns its chain.
|
|
194
|
+
*/
|
|
195
|
+
export declare function chainTimersBeforeCompletion<W extends {
|
|
196
|
+
correlationId: string;
|
|
197
|
+
resumeAtMs: number;
|
|
198
|
+
event?: Event;
|
|
199
|
+
}>(params: {
|
|
200
|
+
openWaits: readonly W[];
|
|
201
|
+
completing: Iterable<string>;
|
|
202
|
+
}): W[];
|
|
203
|
+
/**
|
|
204
|
+
* The waits whose timers to arm, out of the open waits a delivery may arm
|
|
205
|
+
* ({@link schedulesWaitTimer}): the earliest of each chain, and the wait a
|
|
206
|
+
* timer delivery is for (`timerFor`). A wait not in the log yet is in the
|
|
207
|
+
* chain of `messageId`.
|
|
208
|
+
*
|
|
209
|
+
* A delivery that completes a wait of a chain sends the chain's next timer
|
|
210
|
+
* before the completion commits ({@link chainTimersBeforeCompletion}), so a
|
|
211
|
+
* failure after the commit leaves the chain armed.
|
|
212
|
+
*/
|
|
213
|
+
export declare function waitTimersToArm<W extends {
|
|
214
|
+
correlationId: string;
|
|
215
|
+
resumeAtMs: number;
|
|
216
|
+
event?: Event;
|
|
217
|
+
}>(waits: readonly W[], messageId: string, timerFor: string | undefined): W[];
|
|
218
|
+
/** The message whose invocation wrote `wait`'s `wait_created`, if recorded. */
|
|
219
|
+
export declare function waitCreatorMessageId(wait: Event | undefined): string | undefined;
|
|
220
|
+
//# sourceMappingURL=creator-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"creator-rules.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec9/creator-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EAEX,MAAM,iBAAiB,CAAC;AAGzB;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+DAA+D;IAC/D,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACnD,GAAG,WAAW,CAwFd;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAEV;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3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