@dudousxd/nestjs-durable-core 0.66.0 → 0.67.1

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
@@ -89,6 +89,7 @@ __export(index_exports, {
89
89
  eventNameOf: () => eventNameOf,
90
90
  eventPrefix: () => eventPrefix,
91
91
  eventToken: () => eventToken,
92
+ facetOrigin: () => facetOrigin,
92
93
  hasDurableExecutionWrappers: () => hasDurableExecutionWrappers,
93
94
  heartbeatStatus: () => heartbeatStatus,
94
95
  indexWaitersByRun: () => indexWaitersByRun,
@@ -98,6 +99,7 @@ __export(index_exports, {
98
99
  isWorkflowControlFlowSignal: () => isWorkflowControlFlowSignal,
99
100
  log: () => log,
100
101
  matchesAttributes: () => matchesAttributes,
102
+ mergeRunFacetRows: () => mergeRunFacetRows,
101
103
  missingCapabilities: () => missingCapabilities,
102
104
  negotiate: () => negotiate,
103
105
  normalizeAttributeRows: () => normalizeAttributeRows,
@@ -1883,12 +1885,10 @@ var SingletonGate = class {
1883
1885
  ]
1884
1886
  })).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id));
1885
1887
  for (const next of gated.slice(0, cfg.limit ?? 1)) {
1886
- if (next.wakeAt != null) {
1887
- await this.deps.store.updateRun(next.id, {
1888
- wakeAt: void 0,
1889
- updatedAt: /* @__PURE__ */ new Date()
1890
- }).catch(() => void 0);
1891
- }
1888
+ await this.deps.store.updateRun(next.id, {
1889
+ wakeAt: this.deps.clock(),
1890
+ updatedAt: /* @__PURE__ */ new Date()
1891
+ }).catch(() => void 0);
1892
1892
  this.deps.dispatch(next.id);
1893
1893
  }
1894
1894
  }
@@ -6106,6 +6106,33 @@ var TERMINAL_RUN_STATUSES = [
6106
6106
  "dead"
6107
6107
  ];
6108
6108
 
6109
+ // src/run-facets.ts
6110
+ function facetOrigin(origin) {
6111
+ return origin?.trim() ? origin : null;
6112
+ }
6113
+ __name(facetOrigin, "facetOrigin");
6114
+ function mergeRunFacetRows(rows) {
6115
+ const cells = /* @__PURE__ */ new Map();
6116
+ for (const row of rows) {
6117
+ const origin = facetOrigin(row.origin);
6118
+ const key = JSON.stringify([
6119
+ row.status,
6120
+ origin
6121
+ ]);
6122
+ const cell = cells.get(key);
6123
+ if (cell) cell.count += row.count;
6124
+ else cells.set(key, {
6125
+ status: row.status,
6126
+ origin,
6127
+ count: row.count
6128
+ });
6129
+ }
6130
+ return [
6131
+ ...cells.values()
6132
+ ];
6133
+ }
6134
+ __name(mergeRunFacetRows, "mergeRunFacetRows");
6135
+
6109
6136
  // src/run-gateway.ts
6110
6137
  var RunGateway = class {
6111
6138
  static {
@@ -6120,9 +6147,18 @@ var CodecStateStore = class {
6120
6147
  }
6121
6148
  inner;
6122
6149
  codec;
6150
+ /**
6151
+ * Forwarded verbatim — a facet cell counts `status`/`origin`, neither of which the codec touches
6152
+ * (it encodes payloads: input/output/error). Bound as a PROPERTY, and only when the inner store
6153
+ * actually aggregates, so `store.runFacets?.()` still reports absence through the wrapper instead
6154
+ * of resolving to a silently wrong empty result.
6155
+ */
6156
+ runFacets;
6123
6157
  constructor(inner, codec) {
6124
6158
  this.inner = inner;
6125
6159
  this.codec = codec;
6160
+ const facets = inner.runFacets;
6161
+ if (facets) this.runFacets = (query) => facets.call(inner, query);
6126
6162
  }
6127
6163
  enc(v) {
6128
6164
  return v === void 0 ? void 0 : this.codec.encode(v);
@@ -6820,7 +6856,9 @@ var InMemoryStateStore = class {
6820
6856
  }
6821
6857
  return out;
6822
6858
  }
6823
- async listRuns(query) {
6859
+ /** Every run satisfying `query`'s predicates, unsorted and unpaged — the shared body of
6860
+ * {@link listRuns} (which then sorts + pages it) and {@link runFacets} (which groups it). */
6861
+ matching(query) {
6824
6862
  let runs = [
6825
6863
  ...this.runs.values()
6826
6864
  ];
@@ -6829,7 +6867,8 @@ var InMemoryStateStore = class {
6829
6867
  if (query.statuses) runs = runs.filter((r) => query.statuses?.includes(r.status));
6830
6868
  if (query.tag) runs = runs.filter((r) => r.tags?.includes(query.tag));
6831
6869
  if (query.namespace !== void 0) runs = runs.filter((r) => r.namespace === query.namespace);
6832
- if (query.origin !== void 0) runs = runs.filter((r) => r.origin === query.origin);
6870
+ if (query.origin === null) runs = runs.filter((r) => r.origin == null);
6871
+ else if (query.origin !== void 0) runs = runs.filter((r) => r.origin === query.origin);
6833
6872
  if (query.attributes?.length) {
6834
6873
  let candidates = null;
6835
6874
  for (const f of query.attributes) {
@@ -6848,6 +6887,10 @@ var InMemoryStateStore = class {
6848
6887
  this.lastAttributeCandidates = ids.size;
6849
6888
  runs = runs.filter((r) => ids.has(r.id));
6850
6889
  }
6890
+ return runs;
6891
+ }
6892
+ async listRuns(query) {
6893
+ const runs = this.matching(query);
6851
6894
  runs.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
6852
6895
  const offset = query.offset ?? 0;
6853
6896
  const limit = query.limit ?? runs.length;
@@ -6855,6 +6898,13 @@ var InMemoryStateStore = class {
6855
6898
  ...r
6856
6899
  }));
6857
6900
  }
6901
+ async runFacets(query) {
6902
+ return mergeRunFacetRows(this.matching(query).map((run) => ({
6903
+ status: run.status,
6904
+ origin: run.origin,
6905
+ count: 1
6906
+ })));
6907
+ }
6858
6908
  async listCheckpoints(runId) {
6859
6909
  const rows = [
6860
6910
  ...this.checkpoints.values()
@@ -7000,6 +7050,7 @@ var InMemoryTransport = class {
7000
7050
  eventNameOf,
7001
7051
  eventPrefix,
7002
7052
  eventToken,
7053
+ facetOrigin,
7003
7054
  hasDurableExecutionWrappers,
7004
7055
  heartbeatStatus,
7005
7056
  indexWaitersByRun,
@@ -7009,6 +7060,7 @@ var InMemoryTransport = class {
7009
7060
  isWorkflowControlFlowSignal,
7010
7061
  log,
7011
7062
  matchesAttributes,
7063
+ mergeRunFacetRows,
7012
7064
  missingCapabilities,
7013
7065
  negotiate,
7014
7066
  normalizeAttributeRows,