@dudousxd/nestjs-durable-core 0.28.0 → 0.28.2

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
@@ -2103,7 +2103,12 @@ var WorkflowEngine = class {
2103
2103
  for (const w of await this.store.listSignalWaiters("child:")) {
2104
2104
  if (w.runId === parentRunId) childIds.add(w.token.slice("child:".length));
2105
2105
  }
2106
- for (const cp of await this.store.listCheckpoints(parentRunId)) {
2106
+ const prefixes = [
2107
+ "signal:child:",
2108
+ "spawn:"
2109
+ ];
2110
+ const childCheckpoints = this.store.listCheckpointsByNamePrefix ? await this.store.listCheckpointsByNamePrefix(parentRunId, prefixes) : (await this.store.listCheckpoints(parentRunId)).filter((cp) => prefixes.some((p) => cp.name.startsWith(p)));
2111
+ for (const cp of childCheckpoints) {
2107
2112
  if (cp.name.startsWith("signal:child:")) childIds.add(cp.name.slice("signal:child:".length));
2108
2113
  if (cp.name.startsWith("spawn:") && typeof cp.output === "string") childIds.add(cp.output);
2109
2114
  }
@@ -2894,9 +2899,12 @@ var WorkflowEngine = class {
2894
2899
  */
2895
2900
  async getEvent(runId, key) {
2896
2901
  const name = `event:${key}`;
2897
- const checkpoints = await this.store.listCheckpoints(runId);
2902
+ if (this.store.getLatestCheckpointByName) {
2903
+ const latest2 = await this.store.getLatestCheckpointByName(runId, name);
2904
+ return latest2?.output;
2905
+ }
2898
2906
  let latest;
2899
- for (const cp of checkpoints) if (cp.name === name) latest = cp.output;
2907
+ for (const cp of await this.store.listCheckpoints(runId)) if (cp.name === name) latest = cp.output;
2900
2908
  return latest;
2901
2909
  }
2902
2910
  /**
@@ -3349,6 +3357,19 @@ var CodecStateStore = class {
3349
3357
  async listCheckpoints(runId) {
3350
3358
  return (await this.inner.listCheckpoints(runId)).map((c) => this.decCp(c));
3351
3359
  }
3360
+ async getLatestCheckpointByName(runId, name) {
3361
+ if (this.inner.getLatestCheckpointByName) {
3362
+ const cp = await this.inner.getLatestCheckpointByName(runId, name);
3363
+ return cp ? this.decCp(cp) : void 0;
3364
+ }
3365
+ let latest;
3366
+ for (const cp of await this.inner.listCheckpoints(runId)) if (cp.name === name) latest = cp;
3367
+ return latest ? this.decCp(latest) : void 0;
3368
+ }
3369
+ async listCheckpointsByNamePrefix(runId, prefixes) {
3370
+ const matches = this.inner.listCheckpointsByNamePrefix ? await this.inner.listCheckpointsByNamePrefix(runId, prefixes) : (await this.inner.listCheckpoints(runId)).filter((cp) => prefixes.some((p) => cp.name.startsWith(p)));
3371
+ return matches.map((c) => this.decCp(c));
3372
+ }
3352
3373
  };
3353
3374
 
3354
3375
  // src/metrics.ts
@@ -3373,11 +3394,16 @@ function collectMetrics(engine) {
3373
3394
  };
3374
3395
  const wf = /* @__PURE__ */ __name((name) => {
3375
3396
  const k = name ?? "unknown";
3376
- return m.byWorkflow[k] ??= {
3377
- started: 0,
3378
- completed: 0,
3379
- failed: 0
3380
- };
3397
+ let entry = m.byWorkflow[k];
3398
+ if (!entry) {
3399
+ entry = {
3400
+ started: 0,
3401
+ completed: 0,
3402
+ failed: 0
3403
+ };
3404
+ m.byWorkflow[k] = entry;
3405
+ }
3406
+ return entry;
3381
3407
  }, "wf");
3382
3408
  const stop = engine.subscribe((e) => {
3383
3409
  switch (e.type) {
@@ -3603,9 +3629,9 @@ function attributeOperand(filter) {
3603
3629
  __name(attributeOperand, "attributeOperand");
3604
3630
 
3605
3631
  // src/tokens.ts
3606
- var STATE_STORE = Symbol("nestjs-durable:STATE_STORE");
3607
- var TRANSPORT = Symbol("nestjs-durable:TRANSPORT");
3608
- var DURABLE_OPTIONS = Symbol("nestjs-durable:DURABLE_OPTIONS");
3632
+ var STATE_STORE = Symbol.for("nestjs-durable:STATE_STORE");
3633
+ var TRANSPORT = Symbol.for("nestjs-durable:TRANSPORT");
3634
+ var DURABLE_OPTIONS = Symbol.for("nestjs-durable:DURABLE_OPTIONS");
3609
3635
 
3610
3636
  // src/testing/in-memory-state-store.ts
3611
3637
  var InMemoryStateStore = class {
@@ -3624,6 +3650,13 @@ var InMemoryStateStore = class {
3624
3650
  attributeIndex = /* @__PURE__ */ new Map();
3625
3651
  /** Test/observability hook: how many candidate runs the last attribute query's index produced. */
3626
3652
  lastAttributeCandidates = 0;
3653
+ /**
3654
+ * Test/observability hook: how many checkpoint rows the LAST checkpoint read materialized (the rows
3655
+ * actually returned to the caller). `listCheckpoints` returns all rows for the run; the targeted
3656
+ * {@link getLatestCheckpointByName} / {@link listCheckpointsByNamePrefix} return only the matches —
3657
+ * so this lets the benchmark contrast "fetch N, scan in JS" against "fetch the k that match".
3658
+ */
3659
+ lastCheckpointRowsRead = 0;
3627
3660
  key(runId, seq) {
3628
3661
  return `${runId}:${seq}`;
3629
3662
  }
@@ -3830,11 +3863,33 @@ var InMemoryStateStore = class {
3830
3863
  }));
3831
3864
  }
3832
3865
  async listCheckpoints(runId) {
3833
- return [
3866
+ const rows = [
3834
3867
  ...this.checkpoints.values()
3835
3868
  ].filter((cp) => cp.runId === runId).sort((a, b) => a.seq - b.seq).map((cp) => ({
3836
3869
  ...cp
3837
3870
  }));
3871
+ this.lastCheckpointRowsRead = rows.length;
3872
+ return rows;
3873
+ }
3874
+ async getLatestCheckpointByName(runId, name) {
3875
+ let latest;
3876
+ for (const cp of this.checkpoints.values()) {
3877
+ if (cp.runId !== runId || cp.name !== name) continue;
3878
+ if (!latest || cp.seq > latest.seq) latest = cp;
3879
+ }
3880
+ this.lastCheckpointRowsRead = latest ? 1 : 0;
3881
+ return latest ? {
3882
+ ...latest
3883
+ } : void 0;
3884
+ }
3885
+ async listCheckpointsByNamePrefix(runId, prefixes) {
3886
+ const rows = [
3887
+ ...this.checkpoints.values()
3888
+ ].filter((cp) => cp.runId === runId && prefixes.some((p) => cp.name.startsWith(p))).sort((a, b) => a.seq - b.seq).map((cp) => ({
3889
+ ...cp
3890
+ }));
3891
+ this.lastCheckpointRowsRead = rows.length;
3892
+ return rows;
3838
3893
  }
3839
3894
  };
3840
3895