@workflow/core 5.0.0-beta.37 → 5.0.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/capabilities.d.ts +5 -0
  2. package/dist/capabilities.d.ts.map +1 -1
  3. package/dist/capabilities.js +20 -2
  4. package/dist/context-violation-error.d.ts.map +1 -1
  5. package/dist/context-violation-error.js +4 -2
  6. package/dist/private.d.ts +21 -5
  7. package/dist/private.d.ts.map +1 -1
  8. package/dist/private.js +67 -7
  9. package/dist/replay-payload-cache.d.ts +11 -0
  10. package/dist/replay-payload-cache.d.ts.map +1 -1
  11. package/dist/replay-payload-cache.js +21 -4
  12. package/dist/runtime/compute-instance.d.ts +12 -0
  13. package/dist/runtime/compute-instance.d.ts.map +1 -0
  14. package/dist/runtime/compute-instance.js +13 -0
  15. package/dist/runtime/constants.d.ts +18 -0
  16. package/dist/runtime/constants.d.ts.map +1 -1
  17. package/dist/runtime/constants.js +42 -1
  18. package/dist/runtime/helpers.d.ts +103 -31
  19. package/dist/runtime/helpers.d.ts.map +1 -1
  20. package/dist/runtime/helpers.js +138 -61
  21. package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
  22. package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
  23. package/dist/runtime/replay-recovery-reporter.js +64 -0
  24. package/dist/runtime/resume-hook.d.ts +22 -2
  25. package/dist/runtime/resume-hook.d.ts.map +1 -1
  26. package/dist/runtime/resume-hook.js +281 -47
  27. package/dist/runtime/start.d.ts.map +1 -1
  28. package/dist/runtime/start.js +50 -3
  29. package/dist/runtime/step-executor.d.ts +17 -13
  30. package/dist/runtime/step-executor.d.ts.map +1 -1
  31. package/dist/runtime/step-executor.js +36 -24
  32. package/dist/runtime/suspension-handler.d.ts +13 -8
  33. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  34. package/dist/runtime/suspension-handler.js +60 -18
  35. package/dist/runtime/world.d.ts +10 -5
  36. package/dist/runtime/world.d.ts.map +1 -1
  37. package/dist/runtime/world.js +128 -21
  38. package/dist/runtime.d.ts +1 -1
  39. package/dist/runtime.d.ts.map +1 -1
  40. package/dist/runtime.js +622 -67
  41. package/dist/serialization/codec-devalue.d.ts.map +1 -1
  42. package/dist/serialization/codec-devalue.js +9 -2
  43. package/dist/serialization/codec.d.ts +17 -0
  44. package/dist/serialization/codec.d.ts.map +1 -1
  45. package/dist/serialization/codec.js +1 -1
  46. package/dist/serialization/hardened.d.ts +155 -0
  47. package/dist/serialization/hardened.d.ts.map +1 -0
  48. package/dist/serialization/hardened.js +523 -0
  49. package/dist/serialization/index.d.ts +2 -1
  50. package/dist/serialization/index.d.ts.map +1 -1
  51. package/dist/serialization/index.js +1 -1
  52. package/dist/serialization/reducers/class.d.ts.map +1 -1
  53. package/dist/serialization/reducers/class.js +11 -6
  54. package/dist/serialization/reducers/common.d.ts +1 -1
  55. package/dist/serialization/reducers/common.d.ts.map +1 -1
  56. package/dist/serialization/reducers/common.js +100 -61
  57. package/dist/serialization/reducers/step-function.d.ts.map +1 -1
  58. package/dist/serialization/reducers/step-function.js +25 -9
  59. package/dist/serialization.d.ts +13 -9
  60. package/dist/serialization.d.ts.map +1 -1
  61. package/dist/serialization.js +150 -49
  62. package/dist/set-attributes.d.ts.map +1 -1
  63. package/dist/set-attributes.js +5 -1
  64. package/dist/step/context-storage.d.ts +1 -1
  65. package/dist/step/context-storage.d.ts.map +1 -1
  66. package/dist/step/context-storage.js +6 -4
  67. package/dist/step/writable-stream.d.ts.map +1 -1
  68. package/dist/step/writable-stream.js +3 -2
  69. package/dist/step.d.ts.map +1 -1
  70. package/dist/step.js +9 -2
  71. package/dist/telemetry/semantic-conventions.d.ts +43 -2
  72. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  73. package/dist/telemetry/semantic-conventions.js +32 -1
  74. package/dist/version.d.ts +1 -1
  75. package/dist/version.js +2 -2
  76. package/dist/workflow/hook.d.ts.map +1 -1
  77. package/dist/workflow/hook.js +38 -1
  78. package/dist/workflow.d.ts +1 -1
  79. package/dist/workflow.d.ts.map +1 -1
  80. package/dist/workflow.js +6 -2
  81. package/package.json +7 -12
  82. package/dist/runtime/world-target.d.ts +0 -11
  83. package/dist/runtime/world-target.d.ts.map +0 -1
  84. package/dist/runtime/world-target.js +0 -15
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVwbGF5LXJlY292ZXJ5LXJlcG9ydGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3J1bnRpbWUvcmVwbGF5LXJlY292ZXJ5LXJlcG9ydGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBOzs7Ozs7O0dBT0c7QUFDSCxNQUFNLE9BQU8sc0JBQXNCO0lBSUo7SUFIckIsTUFBTSxHQUFHLEtBQUssQ0FBQztJQUNmLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFFekIsWUFBNkIsZUFBdUI7UUFBdkIsb0JBQWUsR0FBZixlQUFlLENBQVE7SUFBRyxDQUFDO0lBRXhEOzs7Ozs7Ozs7T0FTRztJQUNILE1BQU0sQ0FBQyxLQUFLO1FBQ1YsT0FBTyxJQUFJLDJCQUEyQixFQUFFLENBQUM7SUFDM0MsQ0FBQztJQUVELFFBQVE7UUFDTixJQUFJLENBQUMsTUFBTSxHQUFHLElBQUksQ0FBQztJQUNyQixDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsS0FBSyxDQUFDLGVBQWUsQ0FDbkIsTUFBcUMsRUFDckMsTUFBNkQ7UUFFN0QsSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLElBQUksSUFBSSxDQUFDLFFBQVE7WUFBRSxPQUFPLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUV6RCxJQUFJLENBQUMsUUFBUSxHQUFHLElBQUksQ0FBQztRQUNyQixJQUFJLENBQUM7WUFDSCxPQUFPLE1BQU0sTUFBTSxDQUFDO2dCQUNsQixHQUFHLE1BQU07Z0JBQ1QscUJBQXFCLEVBQUUsSUFBSSxDQUFD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GUgYWN0aXZhdGUoKTogdm9pZCB7XG4gICAgLy8gRGVsaWJlcmF0ZWx5IGVtcHR5OiBub3RoaW5nIHRvIHJlcG9ydCwgc28gbm90aGluZyBjYW4gYXJtLlxuICB9XG59XG4iXX0=
@@ -11,6 +11,26 @@ import { type PayloadKey } from '../serialization.js';
11
11
  * @param token - The unique token identifying the hook
12
12
  */
13
13
  export declare function getHookByToken(token: string): Promise<Hook>;
14
+ /**
15
+ * The result of {@link resumeHook}: a {@link Hook} augmented with an optional
16
+ * resilience signal.
17
+ *
18
+ * On the parallel fast path, `resumeHook()` writes the `hook_received` event and
19
+ * dispatches the workflow queue message concurrently. When the direct event
20
+ * write fails *transiently* — a 429/5xx, a transport error, or an expected
21
+ * `(runId, resumeId)` conflict with its own re-ensuring consumer — but the queue
22
+ * dispatch succeeds, the resume is still guaranteed: the queue consumer
23
+ * idempotently materializes the `hook_received` event from the payload carried
24
+ * on the message before replay. In that recovered case the returned hook carries
25
+ * `resilientResume: true`.
26
+ *
27
+ * On the happy path (the direct write landed) and on the sequential fallback
28
+ * path, the flag is absent (`undefined`). Callers that don't care about the
29
+ * distinction can treat the result as a plain {@link Hook}.
30
+ */
31
+ export type ResumedHook = Hook & {
32
+ resilientResume?: boolean;
33
+ };
14
34
  /**
15
35
  * Resumes a workflow run by sending a payload to a hook identified by its token.
16
36
  *
@@ -19,7 +39,7 @@ export declare function getHookByToken(token: string): Promise<Hook>;
19
39
  *
20
40
  * @param tokenOrHook - The unique token identifying the hook, or the hook object itself
21
41
  * @param payload - The data payload to send to the hook
22
- * @returns Promise resolving to the hook
42
+ * @returns Promise resolving to the {@link ResumedHook}
23
43
  * @throws {HookNotFoundError} If the Hook does not exist or its run has ended
24
44
  *
25
45
  * @example
@@ -40,7 +60,7 @@ export declare function getHookByToken(token: string): Promise<Hook>;
40
60
  * }
41
61
  * ```
42
62
  */
43
- export declare function resumeHook<T = any>(tokenOrHook: string | Hook, payload: T, encryptionKeyOverride?: PayloadKey): Promise<Hook>;
63
+ export declare function resumeHook<T = any>(tokenOrHook: string | Hook, payload: T, encryptionKeyOverride?: PayloadKey): Promise<ResumedHook>;
44
64
  /**
45
65
  * Resumes a webhook by sending a {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request}
46
66
  * object to a hook identified by its token.
@@ -1 +1 @@
1
- {"version":3,"file":"resume-hook.d.ts","sourceRoot":"","sources":["../../src/runtime/resume-hook.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,IAAI,EASV,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAC;AAkH7B;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,UAAU,CAAC,CAAC,GAAG,GAAG,EACtC,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,OAAO,EAAE,CAAC,EACV,qBAAqB,CAAC,EAAE,UAAU,GACjC,OAAO,CAAC,IAAI,CAAC,CAqMf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CA0DnB"}
1
+ {"version":3,"file":"resume-hook.d.ts","sourceRoot":"","sources":["../../src/runtime/resume-hook.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,IAAI,EAUV,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAC;AAwJ7B;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,WAAW,GAAG,I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