@dudousxd/nestjs-durable-core 0.29.1 → 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 CHANGED
@@ -2179,6 +2179,26 @@ var WorkflowEngine = class {
2179
2179
  return results;
2180
2180
  }
2181
2181
  /**
2182
+ * Hard-delete a run and its entire subtree. Unlike {@link cancel} (which marks a run `cancelled`
2183
+ * but keeps it as history), delete REMOVES the run and all its rows (checkpoints, signal waiters,
2184
+ * search-attribute rows) — it vanishes from {@link getRun} and {@link listRuns}. Use it to purge a
2185
+ * finished run whose data is being deleted (e.g. a pipeline run whose result rows are cleared).
2186
+ *
2187
+ * Cascades depth-first via {@link getRunChildren} so children are gone before the parent (no
2188
+ * orphaned child runs). Prefer {@link cancel} first for a live run — deleting one mid-flight orphans
2189
+ * its worker (its next checkpoint write fails). Returns the number of runs deleted (0 if absent).
2190
+ */
2191
+ async deleteRun(runId) {
2192
+ const run = await this.store.getRun(runId);
2193
+ if (!run) return 0;
2194
+ let deleted = 0;
2195
+ for (const childId of await this.getRunChildren(runId)) {
2196
+ deleted += await this.deleteRun(childId);
2197
+ }
2198
+ await this.store.deleteRun(runId);
2199
+ return deleted + 1;
2200
+ }
2201
+ /**
2182
2202
  * Cascade cancellation to a run's children — both awaited (`ctx.child`, found via its live
2183
2203
  * `child:<id>` waiter) and fire-and-forget (`ctx.startChild`, found via its `spawn:<id>`
2184
2204
  * checkpoint). Recursive, so a whole subtree is cancelled; the terminal guard in `cancel` stops it
@@ -3338,6 +3358,9 @@ var CodecStateStore = class {
3338
3358
  async getRun(runId) {
3339
3359
  return this.decRun(await this.inner.getRun(runId));
3340
3360
  }
3361
+ deleteRun(runId) {
3362
+ return this.inner.deleteRun(runId);
3363
+ }
3341
3364
  async getCheckpoint(runId, seq) {
3342
3365
  return this.decCp(await this.inner.getCheckpoint(runId, seq));
3343
3366
  }
@@ -3732,6 +3755,16 @@ var InMemoryStateStore = class {
3732
3755
  ...run
3733
3756
  } : null;
3734
3757
  }
3758
+ async deleteRun(runId) {
3759
+ this.runs.delete(runId);
3760
+ for (const [key, cp] of this.checkpoints) {
3761
+ if (cp.runId === runId) this.checkpoints.delete(key);
3762
+ }
3763
+ for (const [token, waiter] of this.signalWaiters) {
3764
+ if (waiter.runId === runId) this.signalWaiters.delete(token);
3765
+ }
3766
+ this.reindexAttributes(runId, void 0);
3767
+ }
3735
3768
  async getCheckpoint(runId, seq) {
3736
3769
  const cp = this.checkpoints.get(this.key(runId, seq));
3737
3770
  return cp ? {