@dudousxd/nestjs-durable-core 0.67.1 → 0.68.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
@@ -45,6 +45,8 @@ __export(index_exports, {
45
45
  LEGACY_V1_PROTOCOL: () => LEGACY_V1_PROTOCOL,
46
46
  NonDeterminismError: () => NonDeterminismError,
47
47
  QueueController: () => QueueController,
48
+ RUN_VALUE_FACET_LIMIT: () => RUN_VALUE_FACET_LIMIT,
49
+ RUN_VALUE_FACET_SCAN: () => RUN_VALUE_FACET_SCAN,
48
50
  RemoteStepError: () => RemoteStepError,
49
51
  RemoteStepTimeout: () => RemoteStepTimeout,
50
52
  RemoteWorkflowExecutor: () => RemoteWorkflowExecutor,
@@ -67,6 +69,8 @@ __export(index_exports, {
67
69
  applyAttributeQuery: () => applyAttributeQuery,
68
70
  attributeColumnFor: () => attributeColumnFor,
69
71
  attributeOperand: () => attributeOperand,
72
+ attributePredicateOperands: () => attributePredicateOperands,
73
+ axisIsRunColumn: () => axisIsRunColumn,
70
74
  bindWorkflowClass: () => bindWorkflowClass,
71
75
  breakpointToken: () => breakpointToken,
72
76
  buildWorkflowDirectory: () => buildWorkflowDirectory,
@@ -100,6 +104,7 @@ __export(index_exports, {
100
104
  log: () => log,
101
105
  matchesAttributes: () => matchesAttributes,
102
106
  mergeRunFacetRows: () => mergeRunFacetRows,
107
+ mergeRunValueFacetRows: () => mergeRunValueFacetRows,
103
108
  missingCapabilities: () => missingCapabilities,
104
109
  negotiate: () => negotiate,
105
110
  normalizeAttributeRows: () => normalizeAttributeRows,
@@ -118,6 +123,7 @@ __export(index_exports, {
118
123
  runInWorkflowCtx: () => runInWorkflowCtx,
119
124
  runSchedules: () => runSchedules,
120
125
  runStepHandler: () => runStepHandler,
126
+ runValueFacetsFromRuns: () => runValueFacetsFromRuns,
121
127
  sanitizeQueueToken: () => sanitizeQueueToken,
122
128
  scheduledRunId: () => scheduledRunId,
123
129
  sqlComparator: () => sqlComparator,
@@ -6133,6 +6139,76 @@ function mergeRunFacetRows(rows) {
6133
6139
  }
6134
6140
  __name(mergeRunFacetRows, "mergeRunFacetRows");
6135
6141
 
6142
+ // src/run-value-facets.ts
6143
+ var RUN_VALUE_FACET_LIMIT = 100;
6144
+ var RUN_VALUE_FACET_SCAN = 5e3;
6145
+ function axisIsRunColumn(axis) {
6146
+ return axis.field === "workflow" || axis.field === "status" || axis.field === "origin" || axis.field === "namespace";
6147
+ }
6148
+ __name(axisIsRunColumn, "axisIsRunColumn");
6149
+ function valuesOf(run, axis) {
6150
+ switch (axis.field) {
6151
+ case "workflow":
6152
+ return [
6153
+ run.workflow
6154
+ ];
6155
+ case "status":
6156
+ return [
6157
+ run.status
6158
+ ];
6159
+ case "origin":
6160
+ return [
6161
+ facetOrigin(run.origin)
6162
+ ];
6163
+ case "namespace":
6164
+ return run.namespace === void 0 ? [] : [
6165
+ run.namespace
6166
+ ];
6167
+ case "tag":
6168
+ return run.tags ?? [];
6169
+ case "attributeKey":
6170
+ return Object.keys(run.searchAttributes ?? {});
6171
+ case "attributeValue": {
6172
+ const value = run.searchAttributes?.[axis.key];
6173
+ return value === void 0 ? [] : [
6174
+ String(value)
6175
+ ];
6176
+ }
6177
+ }
6178
+ }
6179
+ __name(valuesOf, "valuesOf");
6180
+ function mergeRunValueFacetRows(rows, opts) {
6181
+ const counts = /* @__PURE__ */ new Map();
6182
+ for (const row of rows) {
6183
+ const value = row.value ?? null;
6184
+ counts.set(value, (counts.get(value) ?? 0) + Number(row.count));
6185
+ }
6186
+ const merged = [
6187
+ ...counts
6188
+ ].map(([value, count]) => ({
6189
+ value,
6190
+ count
6191
+ })).filter((row) => row.count > 0).sort((a, b) => {
6192
+ if (b.count !== a.count) return b.count - a.count;
6193
+ if (a.value === null) return 1;
6194
+ if (b.value === null) return -1;
6195
+ return a.value.localeCompare(b.value);
6196
+ });
6197
+ return merged.slice(0, opts?.limit ?? RUN_VALUE_FACET_LIMIT);
6198
+ }
6199
+ __name(mergeRunValueFacetRows, "mergeRunValueFacetRows");
6200
+ function runValueFacetsFromRuns(runs, axis, opts) {
6201
+ const rows = [];
6202
+ for (const run of runs) {
6203
+ for (const value of valuesOf(run, axis)) rows.push({
6204
+ value,
6205
+ count: 1
6206
+ });
6207
+ }
6208
+ return mergeRunValueFacetRows(rows, opts);
6209
+ }
6210
+ __name(runValueFacetsFromRuns, "runValueFacetsFromRuns");
6211
+
6136
6212
  // src/run-gateway.ts
6137
6213
  var RunGateway = class {
6138
6214
  static {
@@ -6154,11 +6230,21 @@ var CodecStateStore = class {
6154
6230
  * of resolving to a silently wrong empty result.
6155
6231
  */
6156
6232
  runFacets;
6233
+ /**
6234
+ * Forwarded verbatim, and safe to: the axes a value facet enumerates are searchable metadata
6235
+ * (workflow, status, origin, namespace, tags, search attributes), none of which the codec encodes.
6236
+ * Bound the same conditional way as {@link runFacets} so absence is reported, not faked.
6237
+ */
6238
+ runValueFacets;
6157
6239
  constructor(inner, codec) {
6158
6240
  this.inner = inner;
6159
6241
  this.codec = codec;
6160
6242
  const facets = inner.runFacets;
6161
6243
  if (facets) this.runFacets = (query) => facets.call(inner, query);
6244
+ const valueFacets = inner.runValueFacets;
6245
+ if (valueFacets) {
6246
+ this.runValueFacets = (axis, query, opts) => valueFacets.call(inner, axis, query, opts);
6247
+ }
6162
6248
  }
6163
6249
  enc(v) {
6164
6250
  return v === void 0 ? void 0 : this.codec.encode(v);
@@ -6513,8 +6599,10 @@ async function runSchedules(engine, schedules, nowMs, opts) {
6513
6599
  __name(runSchedules, "runSchedules");
6514
6600
 
6515
6601
  // src/search-attributes.ts
6516
- function compare(actual, op, expected) {
6517
- switch (op) {
6602
+ function compare(actual, filter) {
6603
+ if (filter.op === "in") return filter.values.some((v) => actual === v);
6604
+ const expected = filter.value;
6605
+ switch (filter.op) {
6518
6606
  case "eq":
6519
6607
  return actual === expected;
6520
6608
  case "ne":
@@ -6533,7 +6621,7 @@ __name(compare, "compare");
6533
6621
  function matchesAttributes(attributes, filters) {
6534
6622
  if (!filters?.length) return true;
6535
6623
  if (!attributes) return false;
6536
- return filters.every((f) => f.key in attributes && compare(attributes[f.key], f.op, f.value));
6624
+ return filters.every((f) => f.key in attributes && compare(attributes[f.key], f));
6537
6625
  }
6538
6626
  __name(matchesAttributes, "matchesAttributes");
6539
6627
  function applyAttributeQuery(rows, query) {
@@ -6599,6 +6687,30 @@ function attributeOperand(filter) {
6599
6687
  return filter.value;
6600
6688
  }
6601
6689
  __name(attributeOperand, "attributeOperand");
6690
+ function attributePredicateOperands(filter) {
6691
+ if (filter.op === "in") {
6692
+ return filter.values.map((value) => {
6693
+ const scalar = {
6694
+ key: filter.key,
6695
+ op: "eq",
6696
+ value
6697
+ };
6698
+ return {
6699
+ column: attributeColumnFor(scalar),
6700
+ comparator: "=",
6701
+ operand: attributeOperand(scalar)
6702
+ };
6703
+ });
6704
+ }
6705
+ return [
6706
+ {
6707
+ column: attributeColumnFor(filter),
6708
+ comparator: sqlComparator(filter.op),
6709
+ operand: attributeOperand(filter)
6710
+ }
6711
+ ];
6712
+ }
6713
+ __name(attributePredicateOperands, "attributePredicateOperands");
6602
6714
 
6603
6715
  // src/search-attributes-schema.ts
6604
6716
  function readSearchAttributes(schema, run) {
@@ -6826,33 +6938,27 @@ var InMemoryStateStore = class {
6826
6938
  const byRun = this.attributeIndex.get(f.key);
6827
6939
  const out = /* @__PURE__ */ new Set();
6828
6940
  if (!byRun) return out;
6829
- const numeric = typeof f.value === "number";
6830
- const operand = typeof f.value === "boolean" ? f.value ? "true" : "false" : f.value;
6941
+ const comparisons = attributePredicateOperands(f);
6831
6942
  for (const row of byRun.values()) {
6832
- const actual = numeric ? row.numValue : row.strValue;
6833
- if (actual == null) continue;
6834
- let ok = false;
6835
- switch (f.op) {
6836
- case "eq":
6837
- ok = actual === operand;
6838
- break;
6839
- case "ne":
6840
- ok = actual !== operand;
6841
- break;
6842
- case "gt":
6843
- ok = actual > operand;
6844
- break;
6845
- case "gte":
6846
- ok = actual >= operand;
6847
- break;
6848
- case "lt":
6849
- ok = actual < operand;
6850
- break;
6851
- case "lte":
6852
- ok = actual <= operand;
6853
- break;
6854
- }
6855
- if (ok) out.add(row.runId);
6943
+ const matched = comparisons.some(({ column, comparator, operand }) => {
6944
+ const actual = column === "numValue" ? row.numValue : row.strValue;
6945
+ if (actual == null) return false;
6946
+ switch (comparator) {
6947
+ case "=":
6948
+ return actual === operand;
6949
+ case "<>":
6950
+ return actual !== operand;
6951
+ case ">":
6952
+ return actual > operand;
6953
+ case ">=":
6954
+ return actual >= operand;
6955
+ case "<":
6956
+ return actual < operand;
6957
+ default:
6958
+ return actual <= operand;
6959
+ }
6960
+ });
6961
+ if (matched) out.add(row.runId);
6856
6962
  }
6857
6963
  return out;
6858
6964
  }
@@ -6863,12 +6969,20 @@ var InMemoryStateStore = class {
6863
6969
  ...this.runs.values()
6864
6970
  ];
6865
6971
  if (query.workflow) runs = runs.filter((r) => r.workflow === query.workflow);
6972
+ if (query.workflows) runs = runs.filter((r) => query.workflows?.includes(r.workflow));
6866
6973
  if (query.status) runs = runs.filter((r) => r.status === query.status);
6867
6974
  if (query.statuses) runs = runs.filter((r) => query.statuses?.includes(r.status));
6868
6975
  if (query.tag) runs = runs.filter((r) => r.tags?.includes(query.tag));
6976
+ if (query.tags) runs = runs.filter((r) => r.tags?.some((t) => query.tags?.includes(t)));
6869
6977
  if (query.namespace !== void 0) runs = runs.filter((r) => r.namespace === query.namespace);
6978
+ if (query.namespaces) {
6979
+ runs = runs.filter((r) => r.namespace !== void 0 && query.namespaces?.includes(r.namespace));
6980
+ }
6870
6981
  if (query.origin === null) runs = runs.filter((r) => r.origin == null);
6871
6982
  else if (query.origin !== void 0) runs = runs.filter((r) => r.origin === query.origin);
6983
+ if (query.origins) {
6984
+ runs = runs.filter((r) => query.origins?.includes(r.origin ?? null));
6985
+ }
6872
6986
  if (query.attributes?.length) {
6873
6987
  let candidates = null;
6874
6988
  for (const f of query.attributes) {
@@ -6905,6 +7019,16 @@ var InMemoryStateStore = class {
6905
7019
  count: 1
6906
7020
  })));
6907
7021
  }
7022
+ /** Counted over the newest `scan` matching runs for EVERY axis, not just `tag`: this store holds
7023
+ * its runs in a Map with no index to group by, so the bound that the SQL stores need only for tags
7024
+ * is the honest one to apply here throughout. */
7025
+ async runValueFacets(axis, query, opts) {
7026
+ const runs = await this.listRuns({
7027
+ ...query,
7028
+ limit: opts?.scan ?? RUN_VALUE_FACET_SCAN
7029
+ });
7030
+ return runValueFacetsFromRuns(runs, axis, opts);
7031
+ }
6908
7032
  async listCheckpoints(runId) {
6909
7033
  const rows = [
6910
7034
  ...this.checkpoints.values()
@@ -7006,6 +7130,8 @@ var InMemoryTransport = class {
7006
7130
  LEGACY_V1_PROTOCOL,
7007
7131
  NonDeterminismError,
7008
7132
  QueueController,
7133
+ RUN_VALUE_FACET_LIMIT,
7134
+ RUN_VALUE_FACET_SCAN,
7009
7135
  RemoteStepError,
7010
7136
  RemoteStepTimeout,
7011
7137
  RemoteWorkflowExecutor,
@@ -7028,6 +7154,8 @@ var InMemoryTransport = class {
7028
7154
  applyAttributeQuery,
7029
7155
  attributeColumnFor,
7030
7156
  attributeOperand,
7157
+ attributePredicateOperands,
7158
+ axisIsRunColumn,
7031
7159
  bindWorkflowClass,
7032
7160
  breakpointToken,
7033
7161
  buildWorkflowDirectory,
@@ -7061,6 +7189,7 @@ var InMemoryTransport = class {
7061
7189
  log,
7062
7190
  matchesAttributes,
7063
7191
  mergeRunFacetRows,
7192
+ mergeRunValueFacetRows,
7064
7193
  missingCapabilities,
7065
7194
  negotiate,
7066
7195
  normalizeAttributeRows,
@@ -7079,6 +7208,7 @@ var InMemoryTransport = class {
7079
7208
  runInWorkflowCtx,
7080
7209
  runSchedules,
7081
7210
  runStepHandler,
7211
+ runValueFacetsFromRuns,
7082
7212
  sanitizeQueueToken,
7083
7213
  scheduledRunId,
7084
7214
  sqlComparator,