@dudousxd/nestjs-durable 0.37.0 → 0.39.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
@@ -56,7 +56,7 @@ __export(index_exports, {
56
56
  ThinWorkflowRegistrar: () => ThinWorkflowRegistrar,
57
57
  WORKFLOW_METADATA: () => WORKFLOW_METADATA,
58
58
  Workflow: () => Workflow,
59
- WorkflowEngine: () => import_nestjs_durable_core14.WorkflowEngine,
59
+ WorkflowEngine: () => import_nestjs_durable_core15.WorkflowEngine,
60
60
  WorkflowService: () => WorkflowService,
61
61
  attributesOf: () => attributesOf,
62
62
  entityConfigFor: () => entityConfigFor,
@@ -69,7 +69,7 @@ __export(index_exports, {
69
69
  isDrivingOperator: () => isDrivingOperator,
70
70
  isOperatorRole: () => isOperatorRole,
71
71
  isStepInterceptor: () => isStepInterceptor,
72
- readSearchAttributes: () => import_nestjs_durable_core14.readSearchAttributes,
72
+ readSearchAttributes: () => import_nestjs_durable_core15.readSearchAttributes,
73
73
  thinWorkerProviders: () => thinWorkerProviders,
74
74
  unavailableRunGateway: () => unavailableRunGateway
75
75
  });
@@ -552,7 +552,7 @@ function unavailableRunGateway() {
552
552
  __name(unavailableRunGateway, "unavailableRunGateway");
553
553
 
554
554
  // src/durable.module.ts
555
- var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
555
+ var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
556
556
  var import_common12 = require("@nestjs/common");
557
557
  var import_core5 = require("@nestjs/core");
558
558
 
@@ -611,7 +611,7 @@ var DurableStepRegistrar = class {
611
611
  if (!isDrivingOperator(this.options)) return;
612
612
  if (!supportsHandle(this.transport)) return;
613
613
  const transport = this.transport;
614
- scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler));
614
+ scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler, this.options.partition));
615
615
  }
616
616
  };
617
617
  DurableStepRegistrar = _ts_decorate3([
@@ -1486,11 +1486,12 @@ TimerPoller = _ts_decorate9([
1486
1486
  ], TimerPoller);
1487
1487
 
1488
1488
  // src/tokens.ts
1489
+ var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
1489
1490
  var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
1490
- var RUN_GATEWAY = Symbol.for("nestjs-durable:run-gateway");
1491
+ var RUN_GATEWAY = import_nestjs_durable_core11.RunGateway;
1491
1492
 
1492
1493
  // src/workflow.registrar.ts
1493
- var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
1494
+ var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
1494
1495
  var import_common10 = require("@nestjs/common");
1495
1496
  var import_core4 = require("@nestjs/core");
1496
1497
 
@@ -1612,11 +1613,11 @@ var WorkflowRegistrar = class {
1612
1613
  const validateInput = meta.validateInput ?? (meta.inputSchema ? classValidatorInput(meta.inputSchema) : void 0);
1613
1614
  const eventBatch = meta.debounce ? {
1614
1615
  mode: "debounce",
1615
- windowMs: (0, import_nestjs_durable_core11.parseDuration)(meta.debounce)
1616
+ windowMs: (0, import_nestjs_durable_core12.parseDuration)(meta.debounce)
1616
1617
  } : meta.batch ? {
1617
1618
  mode: "batch",
1618
1619
  maxSize: meta.batch.maxSize,
1619
- windowMs: (0, import_nestjs_durable_core11.parseDuration)(meta.batch.within)
1620
+ windowMs: (0, import_nestjs_durable_core12.parseDuration)(meta.batch.within)
1620
1621
  } : void 0;
1621
1622
  const workflowCtor = workflow.constructor;
1622
1623
  this.engine.register(meta.name, meta.version, (ctx, input) => workflow.run(ctx, input), {
@@ -1638,11 +1639,11 @@ var WorkflowRegistrar = class {
1638
1639
  // so a turn dispatched under the wrong token would never be consumed. Absent → the inline fast
1639
1640
  // path (unchanged).
1640
1641
  ...this.inAppWorker ? {
1641
- group: (0, import_nestjs_durable_core11.tenantGroup)((0, import_nestjs_durable_core11.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
1642
- executor: new import_nestjs_durable_core11.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
1642
+ group: (0, import_nestjs_durable_core12.tenantGroup)((0, import_nestjs_durable_core12.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
1643
+ executor: new import_nestjs_durable_core12.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
1643
1644
  } : {}
1644
1645
  });
1645
- (0, import_nestjs_durable_core11.bindWorkflowClass)(workflowCtor, {
1646
+ (0, import_nestjs_durable_core12.bindWorkflowClass)(workflowCtor, {
1646
1647
  start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
1647
1648
  waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
1648
1649
  });
@@ -1655,7 +1656,7 @@ var WorkflowRegistrar = class {
1655
1656
  this.engine.register(dlqName, meta.version, inline);
1656
1657
  deadLetterByWorkflow.set(meta.name, dlqName);
1657
1658
  } else if (meta.deadLetterWorkflow) {
1658
- deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core11.workflowName)(meta.deadLetterWorkflow));
1659
+ deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core12.workflowName)(meta.deadLetterWorkflow));
1659
1660
  }
1660
1661
  });
1661
1662
  this.installDeadLetterRouting(deadLetterByWorkflow);
@@ -1677,7 +1678,7 @@ var WorkflowRegistrar = class {
1677
1678
  * a `dlq:<runId>` id, so re-recovery never double-dispatches.
1678
1679
  */
1679
1680
  installDeadLetterRouting(byWorkflow) {
1680
- const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core11.workflowName)(this.options.deadLetterWorkflow) : void 0;
1681
+ const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core12.workflowName)(this.options.deadLetterWorkflow) : void 0;
1681
1682
  if (byWorkflow.size === 0 && !fallback) return;
1682
1683
  this.engine.onDead((run) => {
1683
1684
  const target = byWorkflow.get(run.workflow) ?? fallback;
@@ -1702,14 +1703,14 @@ var WorkflowRegistrar = class {
1702
1703
  };
1703
1704
  WorkflowRegistrar = _ts_decorate10([
1704
1705
  (0, import_common10.Injectable)(),
1705
- _ts_param7(3, (0, import_common10.Inject)(import_nestjs_durable_core11.STATE_STORE_CANONICAL)),
1706
- _ts_param7(4, (0, import_common10.Inject)(import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL)),
1706
+ _ts_param7(3, (0, import_common10.Inject)(import_nestjs_durable_core12.STATE_STORE_CANONICAL)),
1707
+ _ts_param7(4, (0, import_common10.Inject)(import_nestjs_durable_core12.DURABLE_OPTIONS_CANONICAL)),
1707
1708
  _ts_param7(5, (0, import_common10.Inject)(IN_APP_WORKER_BINDING)),
1708
1709
  _ts_metadata10("design:type", Function),
1709
1710
  _ts_metadata10("design:paramtypes", [
1710
1711
  typeof import_core4.DiscoveryService === "undefined" ? Object : import_core4.DiscoveryService,
1711
1712
  typeof import_core4.MetadataScanner === "undefined" ? Object : import_core4.MetadataScanner,
1712
- typeof import_nestjs_durable_core11.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core11.WorkflowEngine,
1713
+ typeof import_nestjs_durable_core12.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core12.WorkflowEngine,
1713
1714
  Object,
1714
1715
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
1715
1716
  Object
@@ -1718,7 +1719,7 @@ WorkflowRegistrar = _ts_decorate10([
1718
1719
 
1719
1720
  // src/workflow.service.ts
1720
1721
  var import_node_crypto = require("crypto");
1721
- var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
1722
+ var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
1722
1723
  var import_common11 = require("@nestjs/common");
1723
1724
  function _ts_decorate11(decorators, target, key, desc) {
1724
1725
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1778,7 +1779,7 @@ WorkflowService = _ts_decorate11([
1778
1779
  (0, import_common11.Injectable)(),
1779
1780
  _ts_metadata11("design:type", Function),
1780
1781
  _ts_metadata11("design:paramtypes", [
1781
- typeof import_nestjs_durable_core12.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core12.WorkflowEngine
1782
+ typeof import_nestjs_durable_core13.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core13.WorkflowEngine
1782
1783
  ])
1783
1784
  ], WorkflowService);
1784
1785
 
@@ -1895,13 +1896,32 @@ tenant maps 1:1 onto partition (the worker queue-routing suffix) \u2014 set only
1895
1896
  }
1896
1897
  __name(assertValidTopology, "assertValidTopology");
1897
1898
  function resolveTopology(options) {
1899
+ return servingPartition(resolveTopologyPreset(options));
1900
+ }
1901
+ __name(resolveTopology, "resolveTopology");
1902
+ function servingPartition(options) {
1903
+ if (options.partition !== void 0 || options.namespace === void 0) return options;
1904
+ return {
1905
+ ...options,
1906
+ partition: options.namespace
1907
+ };
1908
+ }
1909
+ __name(servingPartition, "servingPartition");
1910
+ function resolveTopologyPreset(options) {
1898
1911
  const topology = options.topology;
1899
1912
  if (topology === void 0) return options;
1900
1913
  if (topology.role === "control-plane") {
1901
- if (topology.tenant === void 0 || options.namespace !== void 0) return options;
1914
+ if (topology.tenant === void 0) return options;
1902
1915
  return {
1903
1916
  ...options,
1904
- namespace: topology.tenant
1917
+ // An explicit `namespace` is already validated equal to `tenant` (assertValidTopology), so
1918
+ // keeping it is a no-op rather than a conflict.
1919
+ namespace: options.namespace ?? topology.tenant,
1920
+ // The tenant is ALSO this node's worker-routing suffix: its engine now dispatches a run's steps
1921
+ // to `<name>@<tenant>` (core's `stepGroup`), so its own co-located worker must SUBSCRIBE those
1922
+ // same tokens. Without this the node would dispatch into queues it is not itself listening on.
1923
+ // `partition` is user-forbidden on this role (assertValidTopology), so we own it here.
1924
+ partition: topology.tenant
1905
1925
  };
1906
1926
  }
1907
1927
  if (options.partition !== void 0) return options;
@@ -1910,7 +1930,7 @@ function resolveTopology(options) {
1910
1930
  partition: topology.tenant
1911
1931
  };
1912
1932
  }
1913
- __name(resolveTopology, "resolveTopology");
1933
+ __name(resolveTopologyPreset, "resolveTopologyPreset");
1914
1934
  var RunGatewayBootstrap = class RunGatewayBootstrap2 {
1915
1935
  static {
1916
1936
  __name(this, "RunGatewayBootstrap");
@@ -1953,15 +1973,14 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
1953
1973
  };
1954
1974
  RunGatewayBootstrap = _ts_decorate12([
1955
1975
  (0, import_common12.Injectable)(),
1956
- _ts_param8(1, (0, import_common12.Inject)(import_nestjs_durable_core13.TRANSPORT_CANONICAL)),
1957
- _ts_param8(2, (0, import_common12.Inject)(RUN_GATEWAY)),
1958
- _ts_param8(3, (0, import_common12.Inject)(import_nestjs_durable_core13.STATE_STORE_CANONICAL)),
1959
- _ts_param8(4, (0, import_common12.Inject)(import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL)),
1976
+ _ts_param8(1, (0, import_common12.Inject)(import_nestjs_durable_core14.TRANSPORT_CANONICAL)),
1977
+ _ts_param8(3, (0, import_common12.Inject)(import_nestjs_durable_core14.STATE_STORE_CANONICAL)),
1978
+ _ts_param8(4, (0, import_common12.Inject)(import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL)),
1960
1979
  _ts_metadata12("design:type", Function),
1961
1980
  _ts_metadata12("design:paramtypes", [
1962
- typeof import_nestjs_durable_core13.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core13.WorkflowEngine,
1981
+ typeof import_nestjs_durable_core14.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core14.WorkflowEngine,
1963
1982
  Object,
1964
- typeof RunGateway === "undefined" ? Object : RunGateway,
1983
+ typeof import_nestjs_durable_core14.RunGateway === "undefined" ? Object : import_nestjs_durable_core14.RunGateway,
1965
1984
  Object,
1966
1985
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
1967
1986
  ])
@@ -1973,13 +1992,13 @@ var DurableModule = class _DurableModule {
1973
1992
  static forRoot(options) {
1974
1993
  _DurableModule.assertValid(options);
1975
1994
  return _DurableModule.build({
1976
- provide: import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL,
1995
+ provide: import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL,
1977
1996
  useValue: resolveTopology(options)
1978
1997
  });
1979
1998
  }
1980
1999
  static forRootAsync(options) {
1981
2000
  return _DurableModule.build({
1982
- provide: import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL,
2001
+ provide: import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL,
1983
2002
  useFactory: /* @__PURE__ */ __name(async (...args) => {
1984
2003
  const resolved = await options.useFactory(...args);
1985
2004
  _DurableModule.assertValid(resolved);
@@ -2012,41 +2031,41 @@ var DurableModule = class _DurableModule {
2012
2031
  providers: [
2013
2032
  optionsProvider,
2014
2033
  {
2015
- provide: import_nestjs_durable_core13.STATE_STORE_CANONICAL,
2034
+ provide: import_nestjs_durable_core14.STATE_STORE_CANONICAL,
2016
2035
  useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
2017
2036
  inject: [
2018
- import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL
2037
+ import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL
2019
2038
  ]
2020
2039
  },
2021
2040
  {
2022
- provide: import_nestjs_durable_core13.TRANSPORT_CANONICAL,
2041
+ provide: import_nestjs_durable_core14.TRANSPORT_CANONICAL,
2023
2042
  // With a POOL (`transports`) and no singular `transport`, the canonical transport is the
2024
2043
  // pool's PRIMARY — the same one the engine dispatches on first. Leaving it null starved
2025
2044
  // the step registrar / in-app worker of a transport, so a pool-configured operator
2026
2045
  // registered NO step handlers and its own steps parked in `wait` with no consumer.
2027
2046
  useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
2028
2047
  inject: [
2029
- import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL
2048
+ import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL
2030
2049
  ]
2031
2050
  },
2032
2051
  // Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
2033
2052
  {
2034
- provide: import_nestjs_durable_core13.STATE_STORE,
2035
- useExisting: import_nestjs_durable_core13.STATE_STORE_CANONICAL
2053
+ provide: import_nestjs_durable_core14.STATE_STORE,
2054
+ useExisting: import_nestjs_durable_core14.STATE_STORE_CANONICAL
2036
2055
  },
2037
2056
  {
2038
- provide: import_nestjs_durable_core13.TRANSPORT,
2039
- useExisting: import_nestjs_durable_core13.TRANSPORT_CANONICAL
2057
+ provide: import_nestjs_durable_core14.TRANSPORT,
2058
+ useExisting: import_nestjs_durable_core14.TRANSPORT_CANONICAL
2040
2059
  },
2041
2060
  {
2042
- provide: import_nestjs_durable_core13.DURABLE_OPTIONS,
2043
- useExisting: import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL
2061
+ provide: import_nestjs_durable_core14.DURABLE_OPTIONS,
2062
+ useExisting: import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL
2044
2063
  },
2045
2064
  {
2046
2065
  // Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
2047
2066
  // `DurableStartClient` facade for a thin worker (no `store`) — either way, `WorkflowService`
2048
2067
  // and app code call `engine.start(...)` unchanged.
2049
- provide: import_nestjs_durable_core13.WorkflowEngine,
2068
+ provide: import_nestjs_durable_core14.WorkflowEngine,
2050
2069
  useFactory: /* @__PURE__ */ __name(async (options, store, transport, moduleRef) => {
2051
2070
  if (options.store === void 0) {
2052
2071
  return new DurableStartClient(options);
@@ -2059,7 +2078,7 @@ var DurableModule = class _DurableModule {
2059
2078
  const context = options.context ?? (accessor ? () => carrierFromAccessor(accessor) : void 0);
2060
2079
  const runtime = accessor ? await resolveContextRuntime() : void 0;
2061
2080
  const rehydrate = runtime && ((carrier, fn) => carrier && Object.keys(carrier).length > 0 ? runtime.deserialize(carrier, fn) : fn());
2062
- const engine = new import_nestjs_durable_core13.WorkflowEngine({
2081
+ const engine = new import_nestjs_durable_core14.WorkflowEngine({
2063
2082
  store,
2064
2083
  transport: transport ?? void 0,
2065
2084
  transports: options.transports,
@@ -2090,9 +2109,9 @@ var DurableModule = class _DurableModule {
2090
2109
  return engine;
2091
2110
  }, "useFactory"),
2092
2111
  inject: [
2093
- import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL,
2094
- import_nestjs_durable_core13.STATE_STORE_CANONICAL,
2095
- import_nestjs_durable_core13.TRANSPORT_CANONICAL,
2112
+ import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL,
2113
+ import_nestjs_durable_core14.STATE_STORE_CANONICAL,
2114
+ import_nestjs_durable_core14.TRANSPORT_CANONICAL,
2096
2115
  import_core5.ModuleRef
2097
2116
  ]
2098
2117
  },
@@ -2106,7 +2125,7 @@ var DurableModule = class _DurableModule {
2106
2125
  // or (for a thin worker, no `store`) a `ProxyRunGateway` over `transport` when given, else a
2107
2126
  // gateway whose every method rejects with a clear tenant error.
2108
2127
  {
2109
- provide: RUN_GATEWAY,
2128
+ provide: import_nestjs_durable_core14.RunGateway,
2110
2129
  useFactory: /* @__PURE__ */ __name((options, store, engine) => {
2111
2130
  if (options.store !== void 0) {
2112
2131
  if (!store) {
@@ -2117,9 +2136,9 @@ var DurableModule = class _DurableModule {
2117
2136
  return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs) : unavailableRunGateway();
2118
2137
  }, "useFactory"),
2119
2138
  inject: [
2120
- import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL,
2121
- import_nestjs_durable_core13.STATE_STORE_CANONICAL,
2122
- import_nestjs_durable_core13.WorkflowEngine
2139
+ import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL,
2140
+ import_nestjs_durable_core14.STATE_STORE_CANONICAL,
2141
+ import_nestjs_durable_core14.WorkflowEngine
2123
2142
  ]
2124
2143
  },
2125
2144
  RunGatewayBootstrap,
@@ -2133,13 +2152,13 @@ var DurableModule = class _DurableModule {
2133
2152
  exports: [
2134
2153
  WorkflowService,
2135
2154
  EntityService,
2136
- import_nestjs_durable_core13.WorkflowEngine,
2137
- import_nestjs_durable_core13.STATE_STORE,
2138
- import_nestjs_durable_core13.STATE_STORE_CANONICAL,
2139
- import_nestjs_durable_core13.TRANSPORT,
2140
- import_nestjs_durable_core13.TRANSPORT_CANONICAL,
2141
- import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL,
2142
- RUN_GATEWAY
2155
+ import_nestjs_durable_core14.WorkflowEngine,
2156
+ import_nestjs_durable_core14.STATE_STORE,
2157
+ import_nestjs_durable_core14.STATE_STORE_CANONICAL,
2158
+ import_nestjs_durable_core14.TRANSPORT,
2159
+ import_nestjs_durable_core14.TRANSPORT_CANONICAL,
2160
+ import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL,
2161
+ import_nestjs_durable_core14.RunGateway
2143
2162
  ]
2144
2163
  };
2145
2164
  }
@@ -2149,7 +2168,7 @@ DurableModule = _ts_decorate12([
2149
2168
  ], DurableModule);
2150
2169
 
2151
2170
  // src/index.ts
2152
- var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
2171
+ var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
2153
2172
  // Annotate the CommonJS export names for ESM import in node:
2154
2173
  0 && (module.exports = {
2155
2174
  CONTEXT_ACCESSOR,