@dudousxd/nestjs-durable-core 0.67.0 → 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 +163 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +195 -11
- package/dist/index.d.ts +195 -11
- package/dist/index.js +157 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -1885,12 +1891,10 @@ var SingletonGate = class {
|
|
|
1885
1891
|
]
|
|
1886
1892
|
})).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id));
|
|
1887
1893
|
for (const next of gated.slice(0, cfg.limit ?? 1)) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
}).catch(() => void 0);
|
|
1893
|
-
}
|
|
1894
|
+
await this.deps.store.updateRun(next.id, {
|
|
1895
|
+
wakeAt: this.deps.clock(),
|
|
1896
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1897
|
+
}).catch(() => void 0);
|
|
1894
1898
|
this.deps.dispatch(next.id);
|
|
1895
1899
|
}
|
|
1896
1900
|
}
|
|
@@ -6135,6 +6139,76 @@ function mergeRunFacetRows(rows) {
|
|
|
6135
6139
|
}
|
|
6136
6140
|
__name(mergeRunFacetRows, "mergeRunFacetRows");
|
|
6137
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
|
+
|
|
6138
6212
|
// src/run-gateway.ts
|
|
6139
6213
|
var RunGateway = class {
|
|
6140
6214
|
static {
|
|
@@ -6156,11 +6230,21 @@ var CodecStateStore = class {
|
|
|
6156
6230
|
* of resolving to a silently wrong empty result.
|
|
6157
6231
|
*/
|
|
6158
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;
|
|
6159
6239
|
constructor(inner, codec) {
|
|
6160
6240
|
this.inner = inner;
|
|
6161
6241
|
this.codec = codec;
|
|
6162
6242
|
const facets = inner.runFacets;
|
|
6163
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
|
+
}
|
|
6164
6248
|
}
|
|
6165
6249
|
enc(v) {
|
|
6166
6250
|
return v === void 0 ? void 0 : this.codec.encode(v);
|
|
@@ -6515,8 +6599,10 @@ async function runSchedules(engine, schedules, nowMs, opts) {
|
|
|
6515
6599
|
__name(runSchedules, "runSchedules");
|
|
6516
6600
|
|
|
6517
6601
|
// src/search-attributes.ts
|
|
6518
|
-
function compare(actual,
|
|
6519
|
-
|
|
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) {
|
|
6520
6606
|
case "eq":
|
|
6521
6607
|
return actual === expected;
|
|
6522
6608
|
case "ne":
|
|
@@ -6535,7 +6621,7 @@ __name(compare, "compare");
|
|
|
6535
6621
|
function matchesAttributes(attributes, filters) {
|
|
6536
6622
|
if (!filters?.length) return true;
|
|
6537
6623
|
if (!attributes) return false;
|
|
6538
|
-
return filters.every((f) => f.key in attributes && compare(attributes[f.key], f
|
|
6624
|
+
return filters.every((f) => f.key in attributes && compare(attributes[f.key], f));
|
|
6539
6625
|
}
|
|
6540
6626
|
__name(matchesAttributes, "matchesAttributes");
|
|
6541
6627
|
function applyAttributeQuery(rows, query) {
|
|
@@ -6601,6 +6687,30 @@ function attributeOperand(filter) {
|
|
|
6601
6687
|
return filter.value;
|
|
6602
6688
|
}
|
|
6603
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");
|
|
6604
6714
|
|
|
6605
6715
|
// src/search-attributes-schema.ts
|
|
6606
6716
|
function readSearchAttributes(schema, run) {
|
|
@@ -6828,33 +6938,27 @@ var InMemoryStateStore = class {
|
|
|
6828
6938
|
const byRun = this.attributeIndex.get(f.key);
|
|
6829
6939
|
const out = /* @__PURE__ */ new Set();
|
|
6830
6940
|
if (!byRun) return out;
|
|
6831
|
-
const
|
|
6832
|
-
const operand = typeof f.value === "boolean" ? f.value ? "true" : "false" : f.value;
|
|
6941
|
+
const comparisons = attributePredicateOperands(f);
|
|
6833
6942
|
for (const row of byRun.values()) {
|
|
6834
|
-
const
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
case "lte":
|
|
6854
|
-
ok = actual <= operand;
|
|
6855
|
-
break;
|
|
6856
|
-
}
|
|
6857
|
-
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);
|
|
6858
6962
|
}
|
|
6859
6963
|
return out;
|
|
6860
6964
|
}
|
|
@@ -6865,12 +6969,20 @@ var InMemoryStateStore = class {
|
|
|
6865
6969
|
...this.runs.values()
|
|
6866
6970
|
];
|
|
6867
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));
|
|
6868
6973
|
if (query.status) runs = runs.filter((r) => r.status === query.status);
|
|
6869
6974
|
if (query.statuses) runs = runs.filter((r) => query.statuses?.includes(r.status));
|
|
6870
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)));
|
|
6871
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
|
+
}
|
|
6872
6981
|
if (query.origin === null) runs = runs.filter((r) => r.origin == null);
|
|
6873
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
|
+
}
|
|
6874
6986
|
if (query.attributes?.length) {
|
|
6875
6987
|
let candidates = null;
|
|
6876
6988
|
for (const f of query.attributes) {
|
|
@@ -6907,6 +7019,16 @@ var InMemoryStateStore = class {
|
|
|
6907
7019
|
count: 1
|
|
6908
7020
|
})));
|
|
6909
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
|
+
}
|
|
6910
7032
|
async listCheckpoints(runId) {
|
|
6911
7033
|
const rows = [
|
|
6912
7034
|
...this.checkpoints.values()
|
|
@@ -7008,6 +7130,8 @@ var InMemoryTransport = class {
|
|
|
7008
7130
|
LEGACY_V1_PROTOCOL,
|
|
7009
7131
|
NonDeterminismError,
|
|
7010
7132
|
QueueController,
|
|
7133
|
+
RUN_VALUE_FACET_LIMIT,
|
|
7134
|
+
RUN_VALUE_FACET_SCAN,
|
|
7011
7135
|
RemoteStepError,
|
|
7012
7136
|
RemoteStepTimeout,
|
|
7013
7137
|
RemoteWorkflowExecutor,
|
|
@@ -7030,6 +7154,8 @@ var InMemoryTransport = class {
|
|
|
7030
7154
|
applyAttributeQuery,
|
|
7031
7155
|
attributeColumnFor,
|
|
7032
7156
|
attributeOperand,
|
|
7157
|
+
attributePredicateOperands,
|
|
7158
|
+
axisIsRunColumn,
|
|
7033
7159
|
bindWorkflowClass,
|
|
7034
7160
|
breakpointToken,
|
|
7035
7161
|
buildWorkflowDirectory,
|
|
@@ -7063,6 +7189,7 @@ var InMemoryTransport = class {
|
|
|
7063
7189
|
log,
|
|
7064
7190
|
matchesAttributes,
|
|
7065
7191
|
mergeRunFacetRows,
|
|
7192
|
+
mergeRunValueFacetRows,
|
|
7066
7193
|
missingCapabilities,
|
|
7067
7194
|
negotiate,
|
|
7068
7195
|
normalizeAttributeRows,
|
|
@@ -7081,6 +7208,7 @@ var InMemoryTransport = class {
|
|
|
7081
7208
|
runInWorkflowCtx,
|
|
7082
7209
|
runSchedules,
|
|
7083
7210
|
runStepHandler,
|
|
7211
|
+
runValueFacetsFromRuns,
|
|
7084
7212
|
sanitizeQueueToken,
|
|
7085
7213
|
scheduledRunId,
|
|
7086
7214
|
sqlComparator,
|