@dudousxd/nestjs-durable-core 0.29.0 → 0.30.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/dist/index.cjs +272 -212
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -15
- package/dist/index.d.ts +31 -15
- package/dist/index.js +272 -212
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -226,6 +226,14 @@ interface StateStore {
|
|
|
226
226
|
createRun(run: WorkflowRun): Promise<void>;
|
|
227
227
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
228
228
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
229
|
+
/**
|
|
230
|
+
* Hard-delete a run and all of its rows — the run plus its checkpoints, signal waiters, and
|
|
231
|
+
* normalized search-attribute rows. Unlike a cancelled run (which stays as terminal history), a
|
|
232
|
+
* deleted run is GONE: it no longer appears in {@link getRun} or {@link listRuns}. This removes
|
|
233
|
+
* exactly the one run — the engine's {@link WorkflowEngine.deleteRun} handles the child cascade.
|
|
234
|
+
* No-op if the run doesn't exist. (Token-keyed buffered signals are transient and left alone.)
|
|
235
|
+
*/
|
|
236
|
+
deleteRun(runId: string): Promise<void>;
|
|
229
237
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
230
238
|
/**
|
|
231
239
|
* Persist a checkpoint and advance the run atomically. Durable semantics depend on this
|
|
@@ -1232,6 +1240,8 @@ declare class WorkflowEngine {
|
|
|
1232
1240
|
private readonly trackStepStart;
|
|
1233
1241
|
/** Where a freshly-started run executes — in-process by default (see {@link RunDispatcher}). */
|
|
1234
1242
|
private readonly runDispatcher;
|
|
1243
|
+
/** Per-key serialization for singleton workflows (admission, back-pressure, notify-on-release). */
|
|
1244
|
+
private readonly singletons;
|
|
1235
1245
|
/** Every registered workflow, keyed by `name@version` — so old versions stay runnable. */
|
|
1236
1246
|
private readonly workflows;
|
|
1237
1247
|
/** The newest registered version per workflow name — used to `start` new runs. */
|
|
@@ -1499,6 +1509,17 @@ declare class WorkflowEngine {
|
|
|
1499
1509
|
cancelWhere(filter: Omit<RunQuery, 'limit' | 'offset'>, opts?: {
|
|
1500
1510
|
compensate?: boolean;
|
|
1501
1511
|
}): Promise<RunResult[]>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Hard-delete a run and its entire subtree. Unlike {@link cancel} (which marks a run `cancelled`
|
|
1514
|
+
* but keeps it as history), delete REMOVES the run and all its rows (checkpoints, signal waiters,
|
|
1515
|
+
* search-attribute rows) — it vanishes from {@link getRun} and {@link listRuns}. Use it to purge a
|
|
1516
|
+
* finished run whose data is being deleted (e.g. a pipeline run whose result rows are cleared).
|
|
1517
|
+
*
|
|
1518
|
+
* Cascades depth-first via {@link getRunChildren} so children are gone before the parent (no
|
|
1519
|
+
* orphaned child runs). Prefer {@link cancel} first for a live run — deleting one mid-flight orphans
|
|
1520
|
+
* its worker (its next checkpoint write fails). Returns the number of runs deleted (0 if absent).
|
|
1521
|
+
*/
|
|
1522
|
+
deleteRun(runId: string): Promise<number>;
|
|
1502
1523
|
/**
|
|
1503
1524
|
* Cascade cancellation to a run's children — both awaited (`ctx.child`, found via its live
|
|
1504
1525
|
* `child:<id>` waiter) and fire-and-forget (`ctx.startChild`, found via its `spawn:<id>`
|
|
@@ -1552,21 +1573,6 @@ declare class WorkflowEngine {
|
|
|
1552
1573
|
private completeStep;
|
|
1553
1574
|
/** Checkpoint a step that failed terminally, so the failure point is visible (not just the run). */
|
|
1554
1575
|
private failStep;
|
|
1555
|
-
/**
|
|
1556
|
-
* Whether `run` may run now under its singleton key: it's among the `limit` oldest in-flight runs
|
|
1557
|
-
* (running or suspended) sharing the key, by `(createdAt, id)` order. A consistent store gives every
|
|
1558
|
-
* instance the same ordering, so admission is race-free + FIFO.
|
|
1559
|
-
*/
|
|
1560
|
-
private admitSingleton;
|
|
1561
|
-
/**
|
|
1562
|
-
* Notify-on-release: a singleton run just settled (freeing a slot), so wake the gated waiters that
|
|
1563
|
-
* can now be admitted — immediately, instead of letting them sleep until their ~1s retry timer.
|
|
1564
|
-
* Dispatches up to `limit` of the oldest gated (`suspended` + same singleton tag) waiters by
|
|
1565
|
-
* `(createdAt, id)`; each re-checks admission in `runExecution` and runs only if it actually wins a
|
|
1566
|
-
* slot, so this never breaks the FIFO + race-free guarantees (the durable timer remains the
|
|
1567
|
-
* cross-instance / crash fallback — this just removes the poll latency on the happy path).
|
|
1568
|
-
*/
|
|
1569
|
-
private wakeNextSingletons;
|
|
1570
1576
|
private execute;
|
|
1571
1577
|
/**
|
|
1572
1578
|
* Advance a remote (cross-SDK) workflow one turn: hand its history to the executor (which dispatches
|
|
@@ -1574,6 +1580,14 @@ declare class WorkflowEngine {
|
|
|
1574
1580
|
* {@link runExecution}'s settle/suspend; the lease is held by {@link execute}. The result that lands
|
|
1575
1581
|
* us back here (a remote step finished, a timer fired) goes through `resume` like any TS workflow.
|
|
1576
1582
|
*/
|
|
1583
|
+
/**
|
|
1584
|
+
* Apply a terminal/suspended transition once: persist the new run status, emit the matching
|
|
1585
|
+
* lifecycle event, and (on completion/failure) wake a waiting parent. Both the TS and remote
|
|
1586
|
+
* executors funnel their completed/failed/suspended outcomes through here so a status update can
|
|
1587
|
+
* never drift from its event or `notifyParent` call. Does NOT touch the run lock — each executor
|
|
1588
|
+
* keeps its own lease handling (the TS executor's `finally`, the remote path's caller).
|
|
1589
|
+
*/
|
|
1590
|
+
private settleRun;
|
|
1577
1591
|
private runRemoteExecution;
|
|
1578
1592
|
/** The run's resolved durable ops as replay inputs: completed/failed steps + elapsed timers. */
|
|
1579
1593
|
private remoteHistory;
|
|
@@ -1794,6 +1808,7 @@ declare class CodecStateStore implements StateStore {
|
|
|
1794
1808
|
createRun(run: WorkflowRun): Promise<void>;
|
|
1795
1809
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
1796
1810
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
1811
|
+
deleteRun(runId: string): Promise<void>;
|
|
1797
1812
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
1798
1813
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
1799
1814
|
transaction<T>(work: (tx: {
|
|
@@ -2030,6 +2045,7 @@ declare class InMemoryStateStore implements StateStore {
|
|
|
2030
2045
|
createRun(run: WorkflowRun): Promise<void>;
|
|
2031
2046
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
2032
2047
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
2048
|
+
deleteRun(runId: string): Promise<void>;
|
|
2033
2049
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
2034
2050
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
2035
2051
|
listIncompleteRuns(): Promise<WorkflowRun[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -226,6 +226,14 @@ interface StateStore {
|
|
|
226
226
|
createRun(run: WorkflowRun): Promise<void>;
|
|
227
227
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
228
228
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
229
|
+
/**
|
|
230
|
+
* Hard-delete a run and all of its rows — the run plus its checkpoints, signal waiters, and
|
|
231
|
+
* normalized search-attribute rows. Unlike a cancelled run (which stays as terminal history), a
|
|
232
|
+
* deleted run is GONE: it no longer appears in {@link getRun} or {@link listRuns}. This removes
|
|
233
|
+
* exactly the one run — the engine's {@link WorkflowEngine.deleteRun} handles the child cascade.
|
|
234
|
+
* No-op if the run doesn't exist. (Token-keyed buffered signals are transient and left alone.)
|
|
235
|
+
*/
|
|
236
|
+
deleteRun(runId: string): Promise<void>;
|
|
229
237
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
230
238
|
/**
|
|
231
239
|
* Persist a checkpoint and advance the run atomically. Durable semantics depend on this
|
|
@@ -1232,6 +1240,8 @@ declare class WorkflowEngine {
|
|
|
1232
1240
|
private readonly trackStepStart;
|
|
1233
1241
|
/** Where a freshly-started run executes — in-process by default (see {@link RunDispatcher}). */
|
|
1234
1242
|
private readonly runDispatcher;
|
|
1243
|
+
/** Per-key serialization for singleton workflows (admission, back-pressure, notify-on-release). */
|
|
1244
|
+
private readonly singletons;
|
|
1235
1245
|
/** Every registered workflow, keyed by `name@version` — so old versions stay runnable. */
|
|
1236
1246
|
private readonly workflows;
|
|
1237
1247
|
/** The newest registered version per workflow name — used to `start` new runs. */
|
|
@@ -1499,6 +1509,17 @@ declare class WorkflowEngine {
|
|
|
1499
1509
|
cancelWhere(filter: Omit<RunQuery, 'limit' | 'offset'>, opts?: {
|
|
1500
1510
|
compensate?: boolean;
|
|
1501
1511
|
}): Promise<RunResult[]>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Hard-delete a run and its entire subtree. Unlike {@link cancel} (which marks a run `cancelled`
|
|
1514
|
+
* but keeps it as history), delete REMOVES the run and all its rows (checkpoints, signal waiters,
|
|
1515
|
+
* search-attribute rows) — it vanishes from {@link getRun} and {@link listRuns}. Use it to purge a
|
|
1516
|
+
* finished run whose data is being deleted (e.g. a pipeline run whose result rows are cleared).
|
|
1517
|
+
*
|
|
1518
|
+
* Cascades depth-first via {@link getRunChildren} so children are gone before the parent (no
|
|
1519
|
+
* orphaned child runs). Prefer {@link cancel} first for a live run — deleting one mid-flight orphans
|
|
1520
|
+
* its worker (its next checkpoint write fails). Returns the number of runs deleted (0 if absent).
|
|
1521
|
+
*/
|
|
1522
|
+
deleteRun(runId: string): Promise<number>;
|
|
1502
1523
|
/**
|
|
1503
1524
|
* Cascade cancellation to a run's children — both awaited (`ctx.child`, found via its live
|
|
1504
1525
|
* `child:<id>` waiter) and fire-and-forget (`ctx.startChild`, found via its `spawn:<id>`
|
|
@@ -1552,21 +1573,6 @@ declare class WorkflowEngine {
|
|
|
1552
1573
|
private completeStep;
|
|
1553
1574
|
/** Checkpoint a step that failed terminally, so the failure point is visible (not just the run). */
|
|
1554
1575
|
private failStep;
|
|
1555
|
-
/**
|
|
1556
|
-
* Whether `run` may run now under its singleton key: it's among the `limit` oldest in-flight runs
|
|
1557
|
-
* (running or suspended) sharing the key, by `(createdAt, id)` order. A consistent store gives every
|
|
1558
|
-
* instance the same ordering, so admission is race-free + FIFO.
|
|
1559
|
-
*/
|
|
1560
|
-
private admitSingleton;
|
|
1561
|
-
/**
|
|
1562
|
-
* Notify-on-release: a singleton run just settled (freeing a slot), so wake the gated waiters that
|
|
1563
|
-
* can now be admitted — immediately, instead of letting them sleep until their ~1s retry timer.
|
|
1564
|
-
* Dispatches up to `limit` of the oldest gated (`suspended` + same singleton tag) waiters by
|
|
1565
|
-
* `(createdAt, id)`; each re-checks admission in `runExecution` and runs only if it actually wins a
|
|
1566
|
-
* slot, so this never breaks the FIFO + race-free guarantees (the durable timer remains the
|
|
1567
|
-
* cross-instance / crash fallback — this just removes the poll latency on the happy path).
|
|
1568
|
-
*/
|
|
1569
|
-
private wakeNextSingletons;
|
|
1570
1576
|
private execute;
|
|
1571
1577
|
/**
|
|
1572
1578
|
* Advance a remote (cross-SDK) workflow one turn: hand its history to the executor (which dispatches
|
|
@@ -1574,6 +1580,14 @@ declare class WorkflowEngine {
|
|
|
1574
1580
|
* {@link runExecution}'s settle/suspend; the lease is held by {@link execute}. The result that lands
|
|
1575
1581
|
* us back here (a remote step finished, a timer fired) goes through `resume` like any TS workflow.
|
|
1576
1582
|
*/
|
|
1583
|
+
/**
|
|
1584
|
+
* Apply a terminal/suspended transition once: persist the new run status, emit the matching
|
|
1585
|
+
* lifecycle event, and (on completion/failure) wake a waiting parent. Both the TS and remote
|
|
1586
|
+
* executors funnel their completed/failed/suspended outcomes through here so a status update can
|
|
1587
|
+
* never drift from its event or `notifyParent` call. Does NOT touch the run lock — each executor
|
|
1588
|
+
* keeps its own lease handling (the TS executor's `finally`, the remote path's caller).
|
|
1589
|
+
*/
|
|
1590
|
+
private settleRun;
|
|
1577
1591
|
private runRemoteExecution;
|
|
1578
1592
|
/** The run's resolved durable ops as replay inputs: completed/failed steps + elapsed timers. */
|
|
1579
1593
|
private remoteHistory;
|
|
@@ -1794,6 +1808,7 @@ declare class CodecStateStore implements StateStore {
|
|
|
1794
1808
|
createRun(run: WorkflowRun): Promise<void>;
|
|
1795
1809
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
1796
1810
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
1811
|
+
deleteRun(runId: string): Promise<void>;
|
|
1797
1812
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
1798
1813
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
1799
1814
|
transaction<T>(work: (tx: {
|
|
@@ -2030,6 +2045,7 @@ declare class InMemoryStateStore implements StateStore {
|
|
|
2030
2045
|
createRun(run: WorkflowRun): Promise<void>;
|
|
2031
2046
|
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
2032
2047
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
2048
|
+
deleteRun(runId: string): Promise<void>;
|
|
2033
2049
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
2034
2050
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
2035
2051
|
listIncompleteRuns(): Promise<WorkflowRun[]>;
|