@dudousxd/nestjs-durable-core 0.37.0 → 0.38.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 +30 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1122,6 +1122,15 @@ interface WorkflowCtx {
|
|
|
1122
1122
|
random(): Promise<number>;
|
|
1123
1123
|
/** Deterministic UUID v4: recorded once, then replayed. Use instead of `crypto.randomUUID()`. */
|
|
1124
1124
|
uuid(): Promise<string>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Merge `attrs` into THIS run's {@link WorkflowRun.searchAttributes} — the indexed metadata the
|
|
1127
|
+
* dashboard and {@link RunQuery} filter on. Shallow merge: keys you don't pass are kept. Durable +
|
|
1128
|
+
* exactly-once — recorded at this position on the first run and SKIPPED on replay, so it does one
|
|
1129
|
+
* write, not one per turn. Use this instead of injecting the {@link StateStore} to mutate the run
|
|
1130
|
+
* you're executing (`@Inject(state-store)` + `store.updateRun(ctx.runId, …)` becomes
|
|
1131
|
+
* `ctx.upsertSearchAttributes(…)`).
|
|
1132
|
+
*/
|
|
1133
|
+
upsertSearchAttributes(attrs: SearchAttributes): Promise<void>;
|
|
1125
1134
|
}
|
|
1126
1135
|
/** Result of executing or resuming a workflow run. */
|
|
1127
1136
|
interface RunResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -1122,6 +1122,15 @@ interface WorkflowCtx {
|
|
|
1122
1122
|
random(): Promise<number>;
|
|
1123
1123
|
/** Deterministic UUID v4: recorded once, then replayed. Use instead of `crypto.randomUUID()`. */
|
|
1124
1124
|
uuid(): Promise<string>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Merge `attrs` into THIS run's {@link WorkflowRun.searchAttributes} — the indexed metadata the
|
|
1127
|
+
* dashboard and {@link RunQuery} filter on. Shallow merge: keys you don't pass are kept. Durable +
|
|
1128
|
+
* exactly-once — recorded at this position on the first run and SKIPPED on replay, so it does one
|
|
1129
|
+
* write, not one per turn. Use this instead of injecting the {@link StateStore} to mutate the run
|
|
1130
|
+
* you're executing (`@Inject(state-store)` + `store.updateRun(ctx.runId, …)` becomes
|
|
1131
|
+
* `ctx.upsertSearchAttributes(…)`).
|
|
1132
|
+
*/
|
|
1133
|
+
upsertSearchAttributes(attrs: SearchAttributes): Promise<void>;
|
|
1125
1134
|
}
|
|
1126
1135
|
/** Result of executing or resuming a workflow run. */
|
|
1127
1136
|
interface RunResult {
|
package/dist/index.js
CHANGED
|
@@ -1362,9 +1362,28 @@ function createWorkflowCtx(host, runId, compensations, workflow = "") {
|
|
|
1362
1362
|
const now = /* @__PURE__ */ __name(() => step("now", async () => host.clock()), "now");
|
|
1363
1363
|
const random = /* @__PURE__ */ __name(() => step("random", async () => Math.random()), "random");
|
|
1364
1364
|
const uuid = /* @__PURE__ */ __name(() => step("uuid", async () => globalThis.crypto.randomUUID()), "uuid");
|
|
1365
|
+
const upsertSearchAttributes = /* @__PURE__ */ __name(async (attrs) => {
|
|
1366
|
+
const current = pos.next();
|
|
1367
|
+
const existing = await readCheckpoint(current);
|
|
1368
|
+
if (existing) {
|
|
1369
|
+
if (existing.name !== "searchAttributes") {
|
|
1370
|
+
throw new NonDeterminismError(runId, current, "searchAttributes", existing.name);
|
|
1371
|
+
}
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
await host.upsertSearchAttributes(runId, attrs);
|
|
1375
|
+
await writeCheckpoint(instantCheckpoint({
|
|
1376
|
+
runId,
|
|
1377
|
+
seq: current,
|
|
1378
|
+
name: "searchAttributes",
|
|
1379
|
+
kind: "local",
|
|
1380
|
+
output: attrs
|
|
1381
|
+
}));
|
|
1382
|
+
}, "upsertSearchAttributes");
|
|
1365
1383
|
return {
|
|
1366
1384
|
runId,
|
|
1367
1385
|
step,
|
|
1386
|
+
upsertSearchAttributes,
|
|
1368
1387
|
transaction,
|
|
1369
1388
|
callEntity,
|
|
1370
1389
|
signalEntity,
|
|
@@ -3093,6 +3112,17 @@ var WorkflowEngine = class {
|
|
|
3093
3112
|
priority
|
|
3094
3113
|
}).catch(() => void 0));
|
|
3095
3114
|
}, "startChild"),
|
|
3115
|
+
// Shallow-merge into the run's searchAttributes (the ctx primitive makes this exactly-once).
|
|
3116
|
+
upsertSearchAttributes: /* @__PURE__ */ __name(async (runId, attrs) => {
|
|
3117
|
+
const run = await this.store.getRun(runId);
|
|
3118
|
+
await this.store.updateRun(runId, {
|
|
3119
|
+
searchAttributes: {
|
|
3120
|
+
...run?.searchAttributes ?? {},
|
|
3121
|
+
...attrs
|
|
3122
|
+
},
|
|
3123
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
3124
|
+
});
|
|
3125
|
+
}, "upsertSearchAttributes"),
|
|
3096
3126
|
signalEntity: /* @__PURE__ */ __name((name, key, op, arg, reply) => {
|
|
3097
3127
|
queueMicrotask(() => void this.entities.dispatch(name, key, op, arg, reply).catch(() => void 0));
|
|
3098
3128
|
}, "signalEntity"),
|