@dudousxd/nestjs-durable 0.65.0 → 0.66.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 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -13
- package/dist/index.d.ts +42 -13
- package/dist/index.js +30 -15
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -239,6 +239,8 @@ function Workflow(options) {
|
|
|
239
239
|
deadLetterWorkflow: options.deadLetterWorkflow,
|
|
240
240
|
onError: options.onError,
|
|
241
241
|
tags: options.tags,
|
|
242
|
+
// The typed callbacks are stored erased: the engine calls them with the parsed input, which is
|
|
243
|
+
// exactly the type `S` gave them (see `workflowIo`).
|
|
242
244
|
singleton: options.singleton,
|
|
243
245
|
concurrency: options.concurrency,
|
|
244
246
|
executionTimeout: options.executionTimeout,
|
|
@@ -833,7 +835,7 @@ var DurableStartClient = class {
|
|
|
833
835
|
}
|
|
834
836
|
/**
|
|
835
837
|
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
836
|
-
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
838
|
+
* evaluates the singleton key and the default quota against the parsed input. A per-start `concurrency` wins over the
|
|
837
839
|
* workflow's.
|
|
838
840
|
*/
|
|
839
841
|
async applyPolicy(workflow, input, opts) {
|
|
@@ -841,10 +843,11 @@ var DurableStartClient = class {
|
|
|
841
843
|
if (!policy) return opts?.concurrency !== void 0 ? {
|
|
842
844
|
concurrency: opts.concurrency
|
|
843
845
|
} : {};
|
|
844
|
-
await policy.
|
|
845
|
-
|
|
846
|
+
const keyInput = policy.parseInput ? await policy.parseInput(input) : input;
|
|
847
|
+
await policy.validateInput?.(keyInput);
|
|
848
|
+
const concurrency = await (0, import_nestjs_durable_core3.resolveConcurrency)(opts?.concurrency, policy.concurrency, keyInput);
|
|
846
849
|
const singleton = policy.singleton ? {
|
|
847
|
-
key: policy.singleton.key(
|
|
850
|
+
key: policy.singleton.key(keyInput),
|
|
848
851
|
...policy.singleton.limit !== void 0 ? {
|
|
849
852
|
limit: policy.singleton.limit
|
|
850
853
|
} : {},
|
|
@@ -1279,10 +1282,8 @@ function workflowIo(meta) {
|
|
|
1279
1282
|
const parseOutput = meta.output && schemaParser(meta.output, "output", `workflow "${meta.name}" output`);
|
|
1280
1283
|
const validateInput = meta.validateInput;
|
|
1281
1284
|
return {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
await validateInput?.(parsed);
|
|
1285
|
-
} : void 0,
|
|
1285
|
+
parseInput: parseInput || void 0,
|
|
1286
|
+
validateParsed: validateInput,
|
|
1286
1287
|
wrap: /* @__PURE__ */ __name((body) => !parseInput && !parseOutput ? body : async (ctx, input) => {
|
|
1287
1288
|
const output = await body(ctx, parseInput ? await parseInput(input) : input);
|
|
1288
1289
|
return parseOutput ? parseOutput(output) : output;
|
|
@@ -1457,8 +1458,10 @@ var ThinWorkflowRegistrar = class {
|
|
|
1457
1458
|
}
|
|
1458
1459
|
const declare = starter.declareWorkflow;
|
|
1459
1460
|
if (typeof declare === "function") {
|
|
1461
|
+
const io = workflowIo(meta);
|
|
1460
1462
|
const policy = {
|
|
1461
|
-
validateInput:
|
|
1463
|
+
validateInput: io.validateParsed,
|
|
1464
|
+
parseInput: io.parseInput,
|
|
1462
1465
|
singleton: meta.singleton,
|
|
1463
1466
|
concurrency: meta.concurrency,
|
|
1464
1467
|
onEvent: getOnEvents(meta, instance.constructor),
|
|
@@ -1628,12 +1631,21 @@ async function tenantScheduleAnnouncement(options, tenantToken) {
|
|
|
1628
1631
|
return {
|
|
1629
1632
|
schedules: {
|
|
1630
1633
|
tenant,
|
|
1631
|
-
items: (options.schedules ?? []).map(announcedSchedule)
|
|
1634
|
+
items: await Promise.all((options.schedules ?? []).map(announcedSchedule))
|
|
1632
1635
|
}
|
|
1633
1636
|
};
|
|
1634
1637
|
}
|
|
1635
1638
|
__name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
|
|
1636
|
-
function
|
|
1639
|
+
async function scheduleKeyInput(parseInput, input) {
|
|
1640
|
+
if (!parseInput) return input;
|
|
1641
|
+
try {
|
|
1642
|
+
return await parseInput(input);
|
|
1643
|
+
} catch {
|
|
1644
|
+
return input;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
__name(scheduleKeyInput, "scheduleKeyInput");
|
|
1648
|
+
async function announcedSchedule(s) {
|
|
1637
1649
|
const item = {
|
|
1638
1650
|
key: s.key,
|
|
1639
1651
|
workflow: (0, import_nestjs_durable_core9.workflowName)(s.workflow)
|
|
@@ -1645,10 +1657,12 @@ function announcedSchedule(s) {
|
|
|
1645
1657
|
if (s.paused === true) item.paused = true;
|
|
1646
1658
|
if (s.overlap !== void 0) item.overlap = s.overlap;
|
|
1647
1659
|
if (s.jitter !== void 0 && s.jitter > 0) item.jitterMs = s.jitter;
|
|
1648
|
-
const
|
|
1649
|
-
|
|
1660
|
+
const meta = typeof s.workflow === "function" ? getWorkflowMeta(s.workflow) : void 0;
|
|
1661
|
+
const singleton = meta?.singleton;
|
|
1662
|
+
if (meta && singleton) {
|
|
1663
|
+
const parseInput = workflowIo(meta).parseInput;
|
|
1650
1664
|
item.singleton = {
|
|
1651
|
-
key: singleton.key(s.input),
|
|
1665
|
+
key: singleton.key(await scheduleKeyInput(parseInput, s.input)),
|
|
1652
1666
|
...singleton.limit !== void 0 ? {
|
|
1653
1667
|
limit: singleton.limit
|
|
1654
1668
|
} : {},
|
|
@@ -4163,7 +4177,8 @@ var WorkflowRegistrar = class {
|
|
|
4163
4177
|
concurrency: meta.concurrency,
|
|
4164
4178
|
executionTimeout: meta.executionTimeout,
|
|
4165
4179
|
requires: meta.requires,
|
|
4166
|
-
validateInput: io.
|
|
4180
|
+
validateInput: io.validateParsed,
|
|
4181
|
+
parseInput: io.parseInput,
|
|
4167
4182
|
searchAttributesSchema: meta.searchAttributes,
|
|
4168
4183
|
onEvent: getOnEvents(meta, workflowCtor),
|
|
4169
4184
|
eventBatch,
|