@dudousxd/nestjs-durable-core 0.1.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.
Files changed (45) hide show
  1. package/dist/duration.d.ts +6 -0
  2. package/dist/duration.d.ts.map +1 -0
  3. package/dist/duration.js +42 -0
  4. package/dist/duration.js.map +1 -0
  5. package/dist/engine.d.ts +115 -0
  6. package/dist/engine.d.ts.map +1 -0
  7. package/dist/engine.js +588 -0
  8. package/dist/engine.js.map +1 -0
  9. package/dist/errors.d.ts +34 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +59 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/index.d.ts +11 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +30 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/interfaces.d.ts +249 -0
  18. package/dist/interfaces.d.ts.map +1 -0
  19. package/dist/interfaces.js +3 -0
  20. package/dist/interfaces.js.map +1 -0
  21. package/dist/protocol.d.ts +12 -0
  22. package/dist/protocol.d.ts.map +1 -0
  23. package/dist/protocol.js +35 -0
  24. package/dist/protocol.js.map +1 -0
  25. package/dist/remote-step-factory.d.ts +15 -0
  26. package/dist/remote-step-factory.d.ts.map +1 -0
  27. package/dist/remote-step-factory.js +15 -0
  28. package/dist/remote-step-factory.js.map +1 -0
  29. package/dist/scheduler.d.ts +19 -0
  30. package/dist/scheduler.d.ts.map +1 -0
  31. package/dist/scheduler.js +24 -0
  32. package/dist/scheduler.js.map +1 -0
  33. package/dist/testing/in-memory-state-store.d.ts +25 -0
  34. package/dist/testing/in-memory-state-store.d.ts.map +1 -0
  35. package/dist/testing/in-memory-state-store.js +88 -0
  36. package/dist/testing/in-memory-state-store.js.map +1 -0
  37. package/dist/testing/in-memory-transport.d.ts +16 -0
  38. package/dist/testing/in-memory-transport.d.ts.map +1 -0
  39. package/dist/testing/in-memory-transport.js +29 -0
  40. package/dist/testing/in-memory-transport.js.map +1 -0
  41. package/dist/tokens.d.ts +8 -0
  42. package/dist/tokens.d.ts.map +1 -0
  43. package/dist/tokens.js +11 -0
  44. package/dist/tokens.js.map +1 -0
  45. package/package.json +31 -0
package/dist/errors.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowSuspended = exports.RemoteStepTimeout = exports.SignalTimeoutError = exports.FatalError = void 0;
4
+ /**
5
+ * Thrown inside a step to signal an unrecoverable failure: the engine will NOT retry it,
6
+ * regardless of the step's `retries` setting, and fails the run immediately. Use it for
7
+ * business errors that retrying cannot fix (e.g. a declined card, invalid input).
8
+ */
9
+ class FatalError extends Error {
10
+ code;
11
+ constructor(message, code) {
12
+ super(message);
13
+ this.name = 'FatalError';
14
+ this.code = code;
15
+ }
16
+ }
17
+ exports.FatalError = FatalError;
18
+ /**
19
+ * Internal control signal thrown to suspend a run (e.g. on a durable sleep). Not an error the
20
+ * user should throw or catch; the engine uses it to stop execution and persist `wakeAt`.
21
+ */
22
+ class SignalTimeoutError extends Error {
23
+ token;
24
+ timeoutMs;
25
+ constructor(token, timeoutMs) {
26
+ super(`timed out after ${timeoutMs}ms waiting for signal "${token}"`);
27
+ this.name = 'SignalTimeoutError';
28
+ this.token = token;
29
+ this.timeoutMs = timeoutMs;
30
+ }
31
+ }
32
+ exports.SignalTimeoutError = SignalTimeoutError;
33
+ /**
34
+ * Thrown when a remote step produces no result and no heartbeat within its `timeoutMs` window —
35
+ * i.e. the worker is presumed dead. Subject to the step's `retries` (it's retryable), so the engine
36
+ * re-dispatches before giving up.
37
+ */
38
+ class RemoteStepTimeout extends Error {
39
+ stepId;
40
+ timeoutMs;
41
+ constructor(stepId, timeoutMs) {
42
+ super(`remote step ${stepId} produced no result/heartbeat within ${timeoutMs}ms`);
43
+ this.name = 'RemoteStepTimeout';
44
+ this.stepId = stepId;
45
+ this.timeoutMs = timeoutMs;
46
+ }
47
+ }
48
+ exports.RemoteStepTimeout = RemoteStepTimeout;
49
+ class WorkflowSuspended extends Error {
50
+ /** Epoch ms to auto-resume (durable sleep), or undefined when waiting on an external signal. */
51
+ wakeAt;
52
+ constructor(wakeAt) {
53
+ super('workflow suspended');
54
+ this.name = 'WorkflowSuspended';
55
+ this.wakeAt = wakeAt;
56
+ }
57
+ }
58
+ exports.WorkflowSuspended = WorkflowSuspended;
59
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAU;IACvB,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAPD,gCAOC;AAED;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAClC,KAAK,CAAS;IACd,SAAS,CAAS;IAC3B,YAAY,KAAa,EAAE,SAAiB;QAC1C,KAAK,CAAC,mBAAmB,SAAS,0BAA0B,KAAK,GAAG,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AATD,gDASC;AAED;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IACjC,MAAM,CAAS;IACf,SAAS,CAAS;IAC3B,YAAY,MAAc,EAAE,SAAiB;QAC3C,KAAK,CAAC,eAAe,MAAM,wCAAwC,SAAS,IAAI,CAAC,CAAC;QAClF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AATD,8CASC;AAED,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,gGAAgG;IACvF,MAAM,CAAU;IACzB,YAAY,MAAe;QACzB,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AARD,8CAQC"}
@@ -0,0 +1,11 @@
1
+ export * from './duration';
2
+ export * from './engine';
3
+ export * from './errors';
4
+ export * from './interfaces';
5
+ export * from './protocol';
6
+ export * from './remote-step-factory';
7
+ export * from './scheduler';
8
+ export * from './tokens';
9
+ export { InMemoryStateStore } from './testing/in-memory-state-store';
10
+ export { InMemoryTransport } from './testing/in-memory-transport';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.InMemoryTransport = exports.InMemoryStateStore = void 0;
18
+ __exportStar(require("./duration"), exports);
19
+ __exportStar(require("./engine"), exports);
20
+ __exportStar(require("./errors"), exports);
21
+ __exportStar(require("./interfaces"), exports);
22
+ __exportStar(require("./protocol"), exports);
23
+ __exportStar(require("./remote-step-factory"), exports);
24
+ __exportStar(require("./scheduler"), exports);
25
+ __exportStar(require("./tokens"), exports);
26
+ var in_memory_state_store_1 = require("./testing/in-memory-state-store");
27
+ Object.defineProperty(exports, "InMemoryStateStore", { enumerable: true, get: function () { return in_memory_state_store_1.InMemoryStateStore; } });
28
+ var in_memory_transport_1 = require("./testing/in-memory-transport");
29
+ Object.defineProperty(exports, "InMemoryTransport", { enumerable: true, get: function () { return in_memory_transport_1.InMemoryTransport; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,+CAA6B;AAC7B,6CAA2B;AAC3B,wDAAsC;AACtC,8CAA4B;AAC5B,2CAAyB;AACzB,yEAAqE;AAA5D,2HAAA,kBAAkB,OAAA;AAC3B,qEAAkE;AAAzD,wHAAA,iBAAiB,OAAA"}
@@ -0,0 +1,249 @@
1
+ import type { z } from 'zod';
2
+ /**
3
+ * Core type contracts for nestjs-durable.
4
+ *
5
+ * These are intentionally framework-agnostic: `@dudousxd/nestjs-durable-core` knows only
6
+ * these interfaces, never a concrete transport, store or ORM. Adapters implement them.
7
+ */
8
+ export type RunStatus = 'running' | 'suspended' | 'completed' | 'failed' | 'cancelled';
9
+ /** One execution of a workflow. The unit of durability and the unit shown in the dashboard. */
10
+ export interface WorkflowRun {
11
+ id: string;
12
+ /** Registered workflow name, e.g. `checkout`. */
13
+ workflow: string;
14
+ /** Code version at start; old runs must resume on the version they began on. */
15
+ workflowVersion: string;
16
+ status: RunStatus;
17
+ /** Serialized workflow input (the args the run was started with). */
18
+ input: unknown;
19
+ /** Serialized workflow output, once `completed`. */
20
+ output?: unknown;
21
+ /** Structured error, once `failed`. */
22
+ error?: StepError;
23
+ /** When `suspended` on a durable sleep: epoch ms at which the run becomes due to resume. */
24
+ wakeAt?: number;
25
+ /** Recovery lease owner (engine instance id) while a run is being resumed. */
26
+ lockedBy?: string;
27
+ /** Recovery lease expiry (epoch ms); another instance may take over once it passes. */
28
+ lockedUntil?: number;
29
+ createdAt: Date;
30
+ updatedAt: Date;
31
+ }
32
+ export type StepKind = 'local' | 'remote' | 'sleep' | 'signal';
33
+ /**
34
+ * The recorded result of a single step at a deterministic logical position (`seq`).
35
+ * On replay, a present checkpoint means the step is NOT re-executed — its `output` is returned.
36
+ */
37
+ export interface StepCheckpoint {
38
+ runId: string;
39
+ /** Deterministic logical position of the step within the run. */
40
+ seq: number;
41
+ /** Registered step name (matches the remote handler name for remote steps). */
42
+ name: string;
43
+ kind: StepKind;
44
+ /** Stable id passed to remote workers so they can dedupe a re-delivered task. */
45
+ stepId: string;
46
+ status: 'completed' | 'failed';
47
+ output?: unknown;
48
+ error?: StepError;
49
+ attempts: number;
50
+ /** For remote steps: which worker group ran it. */
51
+ workerGroup?: string;
52
+ /** For sleep steps: epoch ms the sleep elapses at. */
53
+ wakeAt?: number;
54
+ startedAt: Date;
55
+ finishedAt: Date;
56
+ }
57
+ export interface StepError {
58
+ message: string;
59
+ /** Optional machine-readable code, e.g. `declined`, `timeout`. */
60
+ code?: string;
61
+ /** Whether the engine should treat this as retryable. */
62
+ retryable?: boolean;
63
+ stack?: string;
64
+ }
65
+ export interface StateStore {
66
+ /**
67
+ * Provision the tables/collections this store needs, idempotently. Called on boot when the
68
+ * module's `autoSchema` is on. Optional: stores that need no setup (in-memory) omit it.
69
+ */
70
+ ensureSchema?(): Promise<void>;
71
+ createRun(run: WorkflowRun): Promise<void>;
72
+ updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
73
+ getRun(runId: string): Promise<WorkflowRun | null>;
74
+ getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
75
+ /**
76
+ * Persist a checkpoint and advance the run atomically. Durable semantics depend on this
77
+ * being a single transaction; stores without transactions cannot give the strong guarantee.
78
+ */
79
+ saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
80
+ /** Used by recovery on boot to find runs to resume (crashed, left `running`). */
81
+ listIncompleteRuns(): Promise<WorkflowRun[]>;
82
+ /** Suspended runs whose durable timer is due (`wakeAt <= nowMs`), ready to resume. */
83
+ listDueTimers(nowMs: number): Promise<WorkflowRun[]>;
84
+ /**
85
+ * Atomically acquire the recovery lease on a run for `owner` until `leaseUntilMs`, but only if
86
+ * it is currently unlocked or its lease has expired (`<= nowMs`). Returns whether it was
87
+ * acquired — so concurrent engine instances never recover the same run twice.
88
+ */
89
+ tryLockRun(runId: string, owner: string, leaseUntilMs: number, nowMs: number): Promise<boolean>;
90
+ /** Release a run's recovery lease so another instance can pick it up (e.g. once it suspends). */
91
+ releaseRunLock(runId: string): Promise<void>;
92
+ /** Record that a run is suspended waiting for an external signal `token`. */
93
+ putSignalWaiter(waiter: SignalWaiter): Promise<void>;
94
+ /** Atomically take (and remove) the run waiting on `token`, if any. */
95
+ takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
96
+ listRuns(query: RunQuery): Promise<WorkflowRun[]>;
97
+ listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
98
+ }
99
+ export interface RunQuery {
100
+ workflow?: string;
101
+ status?: RunStatus;
102
+ limit?: number;
103
+ offset?: number;
104
+ }
105
+ /** Binds an external signal `token` to the suspended run/step position waiting for it. */
106
+ export interface SignalWaiter {
107
+ token: string;
108
+ runId: string;
109
+ seq: number;
110
+ }
111
+ /** A unit of work dispatched to a remote worker. This is the documented wire payload. */
112
+ export interface RemoteTask {
113
+ runId: string;
114
+ seq: number;
115
+ /** Handler name the worker registered, e.g. `payments.charge-card`. */
116
+ name: string;
117
+ stepId: string;
118
+ /** Worker group expected to handle this task. */
119
+ group: string;
120
+ input: unknown;
121
+ /** W3C traceparent so the worker can continue the distributed trace. */
122
+ traceparent?: string;
123
+ attempt: number;
124
+ }
125
+ export interface StepResult {
126
+ runId: string;
127
+ seq: number;
128
+ stepId: string;
129
+ status: 'completed' | 'failed';
130
+ output?: unknown;
131
+ error?: StepError;
132
+ }
133
+ export interface Heartbeat {
134
+ runId: string;
135
+ seq: number;
136
+ stepId: string;
137
+ group: string;
138
+ }
139
+ export interface Transport {
140
+ /** engine → worker */
141
+ dispatch(task: RemoteTask): Promise<void>;
142
+ /** worker → engine: a step finished (ok or error). */
143
+ onResult(handler: (result: StepResult) => Promise<void>): void;
144
+ /** worker → engine: liveness signal for an in-flight long step. */
145
+ onHeartbeat(handler: (beat: Heartbeat) => Promise<void>): void;
146
+ }
147
+ export type BackoffStrategy = 'fixed' | 'exp';
148
+ export interface StepOptions {
149
+ /** Max attempts before the step (and run) fails. */
150
+ retries?: number;
151
+ backoff?: BackoffStrategy;
152
+ /** Base delay in ms for backoff. */
153
+ backoffMs?: number;
154
+ /**
155
+ * Liveness window for a **remote** step (`ctx.call`): if the worker produces no result and no
156
+ * heartbeat within this many ms, the engine presumes it dead and fails the dispatch with a
157
+ * `RemoteStepTimeout` (retryable — it re-dispatches per `retries`). Each heartbeat resets the
158
+ * window. Ignored for local steps. Omit to wait indefinitely.
159
+ */
160
+ timeoutMs?: number;
161
+ /**
162
+ * Saga compensation: if this step completes but the run later **fails**, the engine runs the
163
+ * registered `compensate` callbacks in reverse order (undo what was done). Local steps only.
164
+ * Idempotency note: a step is already deduplicated by its deterministic `stepId` (runId:seq) —
165
+ * remote workers can use it as the idempotency key, so there's no separate key option.
166
+ */
167
+ compensate?: () => Promise<void>;
168
+ }
169
+ /**
170
+ * A typed handle to a step that runs on a remote worker. The `name` string is the contract:
171
+ * the worker registers a handler under the same name. `input`/`output` validate at the boundary.
172
+ */
173
+ export interface RemoteStepDef<TInput = unknown, TOutput = unknown> extends StepOptions {
174
+ name: string;
175
+ /** Worker group expected to handle this step. */
176
+ group: string;
177
+ input: z.ZodType<TInput>;
178
+ output: z.ZodType<TOutput>;
179
+ /** Branding so `ctx.call` can infer types. */
180
+ readonly __remote: true;
181
+ }
182
+ /**
183
+ * The context handed to a workflow function. Every interaction with the outside world goes
184
+ * through it so the engine can checkpoint — the workflow body itself stays deterministic.
185
+ */
186
+ export interface WorkflowCtx {
187
+ readonly runId: string;
188
+ /** Run a local durable step: executed once, then its result is checkpointed and replayed. */
189
+ step<TOutput>(name: string, fn: () => Promise<TOutput>, options?: StepOptions): Promise<TOutput>;
190
+ /** Dispatch a typed remote step and await its checkpointed result. */
191
+ call<TInput, TOutput>(step: RemoteStepDef<TInput, TOutput>, input: TInput): Promise<TOutput>;
192
+ /**
193
+ * Durable sleep: suspends the run for `duration` (e.g. `'30s'`, `'2h'`, `'7 days'`, or ms as a
194
+ * number) without consuming resources, resuming automatically once the timer is due — even
195
+ * across restarts.
196
+ */
197
+ sleep(duration: string | number): Promise<void>;
198
+ /**
199
+ * Suspend the run until an external `engine.signal(token, payload)` arrives (e.g. a webhook or
200
+ * human approval), then resume with the payload. Waits indefinitely by default — no compute
201
+ * consumed. Pass `{ timeoutMs }` to bound the wait: if the deadline passes first the call throws
202
+ * a `SignalTimeoutError` (catch it in the workflow to branch).
203
+ */
204
+ waitForSignal<TPayload>(token: string, opts?: {
205
+ timeoutMs?: number;
206
+ }): Promise<TPayload>;
207
+ /**
208
+ * An external task with **async completion**: run `dispatch` once (checkpointed — e.g. send to a
209
+ * queue, kick off a non-durable worker or a foreign service like a Python process), then suspend
210
+ * with zero compute until `engine.completeTask(runId, name, result)` (or `failTask`) reports back,
211
+ * and resume with the result. The durable, first-class counterpart of the hand-rolled
212
+ * "dispatch over SQS → wait for COMPLETE_PHASE → signal" pattern. `name` must be unique per run.
213
+ */
214
+ task<TResult>(name: string, dispatch: () => Promise<void>, options?: StepOptions): Promise<TResult>;
215
+ /**
216
+ * Run another registered workflow as a **tracked child**: starts it once and suspends — zero
217
+ * compute — until the child reaches a terminal state, then resumes with the child's output (or
218
+ * throws a FatalError if the child failed). `childId` defaults to a deterministic id derived from
219
+ * this run and the call position, so it's stable across replay.
220
+ */
221
+ child<TOutput>(workflow: string, input: unknown, childId?: string): Promise<TOutput>;
222
+ }
223
+ /** Result of executing or resuming a workflow run. */
224
+ export interface RunResult {
225
+ runId: string;
226
+ status: RunStatus;
227
+ output?: unknown;
228
+ error?: StepError;
229
+ }
230
+ export type EngineEventType = 'run.started' | 'run.completed' | 'run.failed' | 'run.suspended' | 'step.completed' | 'step.failed';
231
+ /**
232
+ * A lifecycle event emitted by the engine. The observability surfaces (dashboard, OTel, the
233
+ * Telescope integration) all subscribe to these rather than reaching into the store.
234
+ */
235
+ export interface EngineEvent {
236
+ type: EngineEventType;
237
+ runId: string;
238
+ workflow?: string;
239
+ seq?: number;
240
+ name?: string;
241
+ kind?: StepKind;
242
+ output?: unknown;
243
+ error?: StepError;
244
+ /** Wall-clock duration of the unit that just finished (step or run), when known. */
245
+ durationMs?: number;
246
+ at: Date;
247
+ }
248
+ export type EngineListener = (event: EngineEvent) => void;
249
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;GAKG;AAMH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEvF,+FAA+F;AAC/F,MAAM,WAAW,WAAW;I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ACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,IAAI,CAAC;CACV;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { RemoteTask, StepResult } from './interfaces';
2
+ /** Canonical step id — the stable identity of a step within a run, used for dedupe and
3
+ * correlation. The format is part of the cross-language wire contract (Python builds the same). */
4
+ export declare function stepId(runId: string, seq: number): string;
5
+ export type StepHandler = (input: unknown) => Promise<unknown> | unknown;
6
+ /**
7
+ * Run `handler` for `task` and produce the wire-format {@link StepResult}. Pure (no transport,
8
+ * no I/O beyond the handler), so every transport — and any language port — can share the exact
9
+ * same completed / failed / no-handler contract instead of re-deriving it.
10
+ */
11
+ export declare function runStepHandler(task: RemoteTask, handler: StepHandler | undefined): Promise<StepResult>;
12
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE3D;oGACoG;AACpG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAEzE;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,WAAW,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAkBrB"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stepId = stepId;
4
+ exports.runStepHandler = runStepHandler;
5
+ /** Canonical step id — the stable identity of a step within a run, used for dedupe and
6
+ * correlation. The format is part of the cross-language wire contract (Python builds the same). */
7
+ function stepId(runId, seq) {
8
+ return `${runId}:${seq}`;
9
+ }
10
+ /**
11
+ * Run `handler` for `task` and produce the wire-format {@link StepResult}. Pure (no transport,
12
+ * no I/O beyond the handler), so every transport — and any language port — can share the exact
13
+ * same completed / failed / no-handler contract instead of re-deriving it.
14
+ */
15
+ async function runStepHandler(task, handler) {
16
+ const base = { runId: task.runId, seq: task.seq, stepId: task.stepId };
17
+ if (!handler) {
18
+ return {
19
+ ...base,
20
+ status: 'failed',
21
+ error: { message: `no handler for ${task.name}`, retryable: false },
22
+ };
23
+ }
24
+ try {
25
+ return { ...base, status: 'completed', output: await handler(task.input) };
26
+ }
27
+ catch (err) {
28
+ return {
29
+ ...base,
30
+ status: 'failed',
31
+ error: { message: err instanceof Error ? err.message : String(err) },
32
+ };
33
+ }
34
+ }
35
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";;AAIA,wBAEC;AASD,wCAqBC;AAlCD;oGACoG;AACpG,SAAgB,MAAM,CAAC,KAAa,EAAE,GAAW;IAC/C,OAAO,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC;AAC3B,CAAC;AAID;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAClC,IAAgB,EAChB,OAAgC;IAEhC,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,EAAE,OAAO,EAAE,kBAAkB,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;SACpE,CAAC;IACJ,CAAC;IACD,IAAI,CAAC;QACH,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IAC7E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;SACrE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { z } from 'zod';
2
+ import type { RemoteStepDef, StepOptions } from './interfaces';
3
+ export interface RemoteStepConfig<TInput, TOutput> extends StepOptions {
4
+ name: string;
5
+ /** Worker group expected to handle this step. Defaults to the `name` prefix before the first dot. */
6
+ group?: string;
7
+ input: z.ZodType<TInput>;
8
+ output: z.ZodType<TOutput>;
9
+ }
10
+ /**
11
+ * Defines a typed handle to a step that runs on a remote worker. Call it from a workflow with
12
+ * `ctx.call(step, input)`; a worker registers a handler under the same `name`.
13
+ */
14
+ export declare function remoteStep<TInput, TOutput>(config: RemoteStepConfig<TInput, TOutput>): RemoteStepDef<TInput, TOutput>;
15
+ //# sourceMappingURL=remote-step-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-step-factory.d.ts","sourceRoot":"","sources":["../src/remote-step-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/D,MAAM,WAAW,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAE,SAAQ,WAAW;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EACxC,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAMhC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remoteStep = remoteStep;
4
+ /**
5
+ * Defines a typed handle to a step that runs on a remote worker. Call it from a workflow with
6
+ * `ctx.call(step, input)`; a worker registers a handler under the same `name`.
7
+ */
8
+ function remoteStep(config) {
9
+ return {
10
+ ...config,
11
+ group: config.group ?? config.name.split('.')[0] ?? config.name,
12
+ __remote: true,
13
+ };
14
+ }
15
+ //# sourceMappingURL=remote-step-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-step-factory.js","sourceRoot":"","sources":["../src/remote-step-factory.ts"],"names":[],"mappings":";;AAeA,gCAQC;AAZD;;;GAGG;AACH,SAAgB,UAAU,CACxB,MAAyC;IAEzC,OAAO;QACL,GAAG,MAAM;QACT,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI;QAC/D,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { WorkflowEngine } from './engine';
2
+ export interface ScheduledWorkflow {
3
+ /** Stable key identifying this schedule — part of the deterministic run id. */
4
+ key: string;
5
+ workflow: string;
6
+ input?: unknown;
7
+ /** Start one run every `everyMs`. */
8
+ everyMs: number;
9
+ }
10
+ /** Deterministic run id for a schedule's current time window — stable within that window. */
11
+ export declare function scheduledRunId(key: string, everyMs: number, nowMs: number): string;
12
+ /**
13
+ * Start each schedule's current-window run. The run id is the time bucket and `engine.start` is
14
+ * idempotent, so firing this on an interval — or racing two instances on the same tick — starts
15
+ * **each window exactly once**. Wire it to a `setInterval`, the durable timer poller, or
16
+ * `@nestjs/schedule`. Returns the run ids for the current windows.
17
+ */
18
+ export declare function runSchedules(engine: Pick<WorkflowEngine, 'start'>, schedules: readonly ScheduledWorkflow[], nowMs: number): Promise<string[]>;
19
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElF;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,EACrC,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scheduledRunId = scheduledRunId;
4
+ exports.runSchedules = runSchedules;
5
+ /** Deterministic run id for a schedule's current time window — stable within that window. */
6
+ function scheduledRunId(key, everyMs, nowMs) {
7
+ return `sched:${key}:${Math.floor(nowMs / everyMs)}`;
8
+ }
9
+ /**
10
+ * Start each schedule's current-window run. The run id is the time bucket and `engine.start` is
11
+ * idempotent, so firing this on an interval — or racing two instances on the same tick — starts
12
+ * **each window exactly once**. Wire it to a `setInterval`, the durable timer poller, or
13
+ * `@nestjs/schedule`. Returns the run ids for the current windows.
14
+ */
15
+ async function runSchedules(engine, schedules, nowMs) {
16
+ const ids = [];
17
+ for (const s of schedules) {
18
+ const runId = scheduledRunId(s.key, s.everyMs, nowMs);
19
+ await engine.start(s.workflow, s.input, runId);
20
+ ids.push(runId);
21
+ }
22
+ return ids;
23
+ }
24
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";;AAYA,wCAEC;AAQD,oCAYC;AAvBD,6FAA6F;AAC7F,SAAgB,cAAc,CAAC,GAAW,EAAE,OAAe,EAAE,KAAa;IACxE,OAAO,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAChC,MAAqC,EACrC,SAAuC,EACvC,KAAa;IAEb,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC/C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { RunQuery, SignalWaiter, StateStore, StepCheckpoint, WorkflowRun } from '../interfaces';
2
+ /**
3
+ * A non-durable, in-process `StateStore` for tests and local development.
4
+ * The shipped `@dudousxd/nestjs-durable-store` package re-exports an equivalent.
5
+ */
6
+ export declare class InMemoryStateStore implements StateStore {
7
+ private readonly runs;
8
+ private readonly checkpoints;
9
+ private readonly signalWaiters;
10
+ private key;
11
+ createRun(run: WorkflowRun): Promise<void>;
12
+ updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
13
+ getRun(runId: string): Promise<WorkflowRun | null>;
14
+ getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
15
+ saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
16
+ listIncompleteRuns(): Promise<WorkflowRun[]>;
17
+ listDueTimers(nowMs: number): Promise<WorkflowRun[]>;
18
+ tryLockRun(runId: string, owner: string, leaseUntilMs: number, nowMs: number): Promise<boolean>;
19
+ releaseRunLock(runId: string): Promise<void>;
20
+ putSignalWaiter(waiter: SignalWaiter): Promise<void>;
21
+ takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
22
+ listRuns(query: RunQuery): Promise<WorkflowRun[]>;
23
+ listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
24
+ }
25
+ //# sourceMappingURL=in-memory-state-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-state-store.d.ts","sourceRoot":"","sources":["../../src/testing/in-memory-state-store.ts"],"names":[],"mappings":"AAAA,OAAO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