@dudousxd/nestjs-durable-core 0.49.4 → 0.50.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 +46 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -8
- package/dist/index.d.ts +191 -8
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -71,6 +71,7 @@ __export(index_exports, {
|
|
|
71
71
|
normalizeAttributeRows: () => normalizeAttributeRows,
|
|
72
72
|
parseDuration: () => parseDuration,
|
|
73
73
|
prevCronFireMs: () => prevCronFireMs,
|
|
74
|
+
readSearchAttributes: () => readSearchAttributes,
|
|
74
75
|
resolveRunWaiting: () => resolveRunWaiting,
|
|
75
76
|
runInWorkflowCtx: () => runInWorkflowCtx,
|
|
76
77
|
runSchedules: () => runSchedules,
|
|
@@ -1185,6 +1186,11 @@ function normalizeChildOptions(options) {
|
|
|
1185
1186
|
} : options ?? {};
|
|
1186
1187
|
}
|
|
1187
1188
|
__name(normalizeChildOptions, "normalizeChildOptions");
|
|
1189
|
+
function formatIssuePath(path) {
|
|
1190
|
+
if (!path || path.length === 0) return "(root)";
|
|
1191
|
+
return path.map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
1192
|
+
}
|
|
1193
|
+
__name(formatIssuePath, "formatIssuePath");
|
|
1188
1194
|
function resolveStepPolicy(config, opts) {
|
|
1189
1195
|
const policy = {};
|
|
1190
1196
|
const retries = opts?.retries ?? config?.retries;
|
|
@@ -1215,7 +1221,7 @@ var Position = class Position2 {
|
|
|
1215
1221
|
this.seq -= 1;
|
|
1216
1222
|
}
|
|
1217
1223
|
};
|
|
1218
|
-
function createWorkflowCtx(host, runId, compensations, workflow = "") {
|
|
1224
|
+
function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttributesSchema) {
|
|
1219
1225
|
const { store, replay } = host;
|
|
1220
1226
|
const pos = new Position();
|
|
1221
1227
|
const readCheckpoint = /* @__PURE__ */ __name((seq) => {
|
|
@@ -1684,6 +1690,24 @@ function createWorkflowCtx(host, runId, compensations, workflow = "") {
|
|
|
1684
1690
|
}
|
|
1685
1691
|
return;
|
|
1686
1692
|
}
|
|
1693
|
+
if (searchAttributesSchema) {
|
|
1694
|
+
const run = await store.getRun(runId);
|
|
1695
|
+
const merged = {
|
|
1696
|
+
...run?.searchAttributes ?? {},
|
|
1697
|
+
...attrs
|
|
1698
|
+
};
|
|
1699
|
+
const result = searchAttributesSchema["~standard"].validate(merged);
|
|
1700
|
+
if (result instanceof Promise) {
|
|
1701
|
+
throw new Error(`workflow "${workflow}": ctx.upsertSearchAttributes schema validation must be synchronous (the searchAttributes schema's \`~standard.validate\` returned a Promise) \u2014 replay-determinism requires a sync validator; drop any async refinement from the schema passed to @Workflow({ searchAttributes }).`);
|
|
1702
|
+
}
|
|
1703
|
+
if (result.issues) {
|
|
1704
|
+
const offendingKeys = [
|
|
1705
|
+
...new Set(result.issues.map((issue) => formatIssuePath(issue.path)))
|
|
1706
|
+
];
|
|
1707
|
+
const details = result.issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`).join("; ");
|
|
1708
|
+
throw new Error(`workflow "${workflow}": ctx.upsertSearchAttributes rejected by its searchAttributes schema \u2014 offending key(s) ${offendingKeys.join(", ")} \u2014 ${details}`);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1687
1711
|
await host.upsertSearchAttributes(runId, attrs);
|
|
1688
1712
|
await writeCheckpoint(instantCheckpoint({
|
|
1689
1713
|
runId,
|
|
@@ -2039,6 +2063,7 @@ var WorkflowEngine = class {
|
|
|
2039
2063
|
singleton: opts?.singleton,
|
|
2040
2064
|
executionTimeoutMs: opts?.executionTimeout != null ? parseDuration(opts.executionTimeout) : void 0,
|
|
2041
2065
|
validateInput: opts?.validateInput,
|
|
2066
|
+
searchAttributesSchema: opts?.searchAttributesSchema,
|
|
2042
2067
|
onEvent: opts?.onEvent,
|
|
2043
2068
|
eventBatch: opts?.eventBatch,
|
|
2044
2069
|
// A real, retained in-process body — so `workflowBody` can hand it to an in-app worker, and so
|
|
@@ -3738,7 +3763,7 @@ var WorkflowEngine = class {
|
|
|
3738
3763
|
const snapshot = await this.store.listCheckpoints(run.id);
|
|
3739
3764
|
const replay = /* @__PURE__ */ new Map();
|
|
3740
3765
|
for (const cp of snapshot) replay.set(cp.seq, cp);
|
|
3741
|
-
const ctx = createWorkflowCtx(this.ctxHostFor(replay, run.namespace), run.id, compensations, run.workflow);
|
|
3766
|
+
const ctx = createWorkflowCtx(this.ctxHostFor(replay, run.namespace), run.id, compensations, run.workflow, registered?.searchAttributesSchema);
|
|
3742
3767
|
try {
|
|
3743
3768
|
const output = await runInWorkflowCtx(ctx, () => fn(ctx, run.input));
|
|
3744
3769
|
if (this.cancelRequested.has(run.id)) {
|
|
@@ -4494,12 +4519,17 @@ var TERMINAL_RUN_STATUSES = [
|
|
|
4494
4519
|
// src/run-waiting.ts
|
|
4495
4520
|
var WEBHOOK_PREFIX = "wh:";
|
|
4496
4521
|
var CHILD_PREFIX = "child:";
|
|
4522
|
+
var BREAKPOINT_PREFIX = "bp:";
|
|
4497
4523
|
var EVENT_PREFIX = "event:";
|
|
4498
4524
|
function classifyWaiterToken(token) {
|
|
4499
4525
|
if (token.startsWith(WEBHOOK_PREFIX)) return {
|
|
4500
4526
|
on: "webhook",
|
|
4501
4527
|
name: token
|
|
4502
4528
|
};
|
|
4529
|
+
if (token.startsWith(BREAKPOINT_PREFIX)) return {
|
|
4530
|
+
on: "breakpoint",
|
|
4531
|
+
name: "breakpoint"
|
|
4532
|
+
};
|
|
4503
4533
|
if (token.startsWith(CHILD_PREFIX)) return {
|
|
4504
4534
|
on: "child",
|
|
4505
4535
|
name: token.slice(CHILD_PREFIX.length)
|
|
@@ -4920,6 +4950,19 @@ function attributeOperand(filter) {
|
|
|
4920
4950
|
}
|
|
4921
4951
|
__name(attributeOperand, "attributeOperand");
|
|
4922
4952
|
|
|
4953
|
+
// src/search-attributes-schema.ts
|
|
4954
|
+
function readSearchAttributes(schema, run) {
|
|
4955
|
+
const result = schema["~standard"].validate(run.searchAttributes ?? {});
|
|
4956
|
+
if (result instanceof Promise) {
|
|
4957
|
+
throw new Error("readSearchAttributes: schema validation must be synchronous (the searchAttributes schema's `~standard.validate` returned a Promise) \u2014 async Standard Schema validators are not supported.");
|
|
4958
|
+
}
|
|
4959
|
+
if (result.issues) {
|
|
4960
|
+
return {};
|
|
4961
|
+
}
|
|
4962
|
+
return result.value;
|
|
4963
|
+
}
|
|
4964
|
+
__name(readSearchAttributes, "readSearchAttributes");
|
|
4965
|
+
|
|
4923
4966
|
// src/tokens.ts
|
|
4924
4967
|
var STATE_STORE = Symbol.for("nestjs-durable:STATE_STORE");
|
|
4925
4968
|
var TRANSPORT = Symbol.for("nestjs-durable:TRANSPORT");
|
|
@@ -5296,6 +5339,7 @@ var InMemoryTransport = class {
|
|
|
5296
5339
|
normalizeAttributeRows,
|
|
5297
5340
|
parseDuration,
|
|
5298
5341
|
prevCronFireMs,
|
|
5342
|
+
readSearchAttributes,
|
|
5299
5343
|
resolveRunWaiting,
|
|
5300
5344
|
runInWorkflowCtx,
|
|
5301
5345
|
runSchedules,
|