@dudousxd/nestjs-durable 0.65.0 → 0.67.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
@@ -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.validateInput?.(input);
845
- const concurrency = await (0, import_nestjs_durable_core3.resolveConcurrency)(opts?.concurrency, policy.concurrency, input);
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(input),
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
- validateAtStart: parseInput || validateInput ? async (input) => {
1283
- const parsed = parseInput ? await parseInput(input) : input;
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: workflowIo(meta).validateAtStart,
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 announcedSchedule(s) {
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 singleton = typeof s.workflow === "function" ? getWorkflowMeta(s.workflow)?.singleton : void 0;
1649
- if (singleton) {
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
  } : {},
@@ -1676,7 +1690,12 @@ function thinWorkerProviders() {
1676
1690
  // optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
1677
1691
  // reach this branch at all.
1678
1692
  useFactory: /* @__PURE__ */ __name((options) => isPureThinWorker(options) ? createWorkerRuntime({
1679
- workflowGroup: options.partition ?? ""
1693
+ workflowGroup: options.partition ?? "",
1694
+ // The worker unwinds a failed turn's `localStep` undos itself, so it takes the
1695
+ // module's `compensationRetries` as the engine does.
1696
+ ...options.compensationRetries !== void 0 ? {
1697
+ compensationRetries: options.compensationRetries
1698
+ } : {}
1680
1699
  }) : null, "useFactory"),
1681
1700
  inject: [
1682
1701
  import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
@@ -1977,7 +1996,12 @@ function inAppWorkerProviders() {
1977
1996
  // optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
1978
1997
  // reach this branch at all.
1979
1998
  useFactory: /* @__PURE__ */ __name((options) => isCoLocatedWorker(options) ? createWorkerRuntime({
1980
- workflowGroup: options.partition ?? ""
1999
+ workflowGroup: options.partition ?? "",
2000
+ // The worker unwinds a failed turn's `localStep` undos itself, so it takes the
2001
+ // module's `compensationRetries` as the engine does.
2002
+ ...options.compensationRetries !== void 0 ? {
2003
+ compensationRetries: options.compensationRetries
2004
+ } : {}
1981
2005
  }) : null, "useFactory"),
1982
2006
  inject: [
1983
2007
  import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
@@ -4163,7 +4187,8 @@ var WorkflowRegistrar = class {
4163
4187
  concurrency: meta.concurrency,
4164
4188
  executionTimeout: meta.executionTimeout,
4165
4189
  requires: meta.requires,
4166
- validateInput: io.validateAtStart,
4190
+ validateInput: io.validateParsed,
4191
+ parseInput: io.parseInput,
4167
4192
  searchAttributesSchema: meta.searchAttributes,
4168
4193
  onEvent: getOnEvents(meta, workflowCtor),
4169
4194
  eventBatch,