@dudousxd/nestjs-durable 0.64.0 → 0.65.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
@@ -38,7 +38,7 @@ __export(src_exports, {
38
38
  DURABLE_WORKER_RUNNERS: () => DURABLE_WORKER_RUNNERS,
39
39
  DURABLE_WORKER_RUNTIME: () => DURABLE_WORKER_RUNTIME,
40
40
  DeadLetter: () => DeadLetter,
41
- DuplicateDurableCopyError: () => import_nestjs_durable_core21.DuplicateDurableCopyError,
41
+ DuplicateDurableCopyError: () => import_nestjs_durable_core22.DuplicateDurableCopyError,
42
42
  DurableModule: () => DurableModule,
43
43
  DurableStartClient: () => DurableStartClient,
44
44
  ENTITY_METADATA: () => ENTITY_METADATA,
@@ -51,7 +51,7 @@ __export(src_exports, {
51
51
  IN_APP_WORKER_RUNNERS: () => IN_APP_WORKER_RUNNERS,
52
52
  IN_APP_WORKER_RUNTIME: () => IN_APP_WORKER_RUNTIME,
53
53
  InAppWorkerBootstrap: () => InAppWorkerBootstrap,
54
- LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core21.LIFECYCLE_PENDING_TAG,
54
+ LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core22.LIFECYCLE_PENDING_TAG,
55
55
  ON_ERROR_METADATA: () => ON_ERROR_METADATA,
56
56
  ON_EVENT_BATCH_METADATA: () => ON_EVENT_BATCH_METADATA,
57
57
  ON_EVENT_METADATA: () => ON_EVENT_METADATA,
@@ -63,7 +63,7 @@ __export(src_exports, {
63
63
  ProxyRunGateway: () => ProxyRunGateway,
64
64
  RUN_GATEWAY: () => RUN_GATEWAY,
65
65
  RUN_REDIS_WORKER: () => RUN_REDIS_WORKER,
66
- RunGateway: () => import_nestjs_durable_core21.RunGateway,
66
+ RunGateway: () => import_nestjs_durable_core22.RunGateway,
67
67
  RunGatewayError: () => RunGatewayError,
68
68
  RunRequestResponder: () => RunRequestResponder,
69
69
  STEP_INTERCEPTOR_METADATA: () => STEP_INTERCEPTOR_METADATA,
@@ -79,7 +79,7 @@ __export(src_exports, {
79
79
  UNSUPPORTED_RUN_REQUEST: () => UNSUPPORTED_RUN_REQUEST,
80
80
  WORKFLOW_METADATA: () => WORKFLOW_METADATA,
81
81
  Workflow: () => Workflow,
82
- WorkflowEngine: () => import_nestjs_durable_core21.WorkflowEngine,
82
+ WorkflowEngine: () => import_nestjs_durable_core22.WorkflowEngine,
83
83
  WorkflowService: () => WorkflowService,
84
84
  attributesOf: () => attributesOf,
85
85
  entityConfigFor: () => entityConfigFor,
@@ -89,26 +89,26 @@ __export(src_exports, {
89
89
  getEntityMeta: () => getEntityMeta,
90
90
  getOnEvents: () => getOnEvents,
91
91
  getWorkflowMeta: () => getWorkflowMeta,
92
- hmacTenantVerifier: () => import_nestjs_durable_core21.hmacTenantVerifier,
92
+ hmacTenantVerifier: () => import_nestjs_durable_core22.hmacTenantVerifier,
93
93
  inAppWorkerProviders: () => inAppWorkerProviders,
94
94
  isDeadLetterHandler: () => isDeadLetterHandler,
95
95
  isDrivingOperator: () => isDrivingOperator,
96
96
  isOperatorRole: () => isOperatorRole,
97
97
  isStepInterceptor: () => isStepInterceptor,
98
- lifecycleRunId: () => import_nestjs_durable_core21.lifecycleRunId,
99
- lifecycleSourceOf: () => import_nestjs_durable_core21.lifecycleSourceOf,
98
+ lifecycleRunId: () => import_nestjs_durable_core22.lifecycleRunId,
99
+ lifecycleSourceOf: () => import_nestjs_durable_core22.lifecycleSourceOf,
100
100
  onErrorCodesOf: () => onErrorCodesOf,
101
- prevCronFireMs: () => import_nestjs_durable_core21.prevCronFireMs,
102
- readSearchAttributes: () => import_nestjs_durable_core21.readSearchAttributes,
103
- runCompletedEvent: () => import_nestjs_durable_core21.runCompletedEvent,
104
- runFailedEvent: () => import_nestjs_durable_core21.runFailedEvent,
105
- runSchedules: () => import_nestjs_durable_core21.runSchedules,
106
- scheduleRunIdAt: () => import_nestjs_durable_core21.scheduleRunIdAt,
107
- scheduledRunId: () => import_nestjs_durable_core21.scheduledRunId,
108
- signTenantToken: () => import_nestjs_durable_core21.signTenantToken,
101
+ prevCronFireMs: () => import_nestjs_durable_core22.prevCronFireMs,
102
+ readSearchAttributes: () => import_nestjs_durable_core22.readSearchAttributes,
103
+ runCompletedEvent: () => import_nestjs_durable_core22.runCompletedEvent,
104
+ runFailedEvent: () => import_nestjs_durable_core22.runFailedEvent,
105
+ runSchedules: () => import_nestjs_durable_core22.runSchedules,
106
+ scheduleRunIdAt: () => import_nestjs_durable_core22.scheduleRunIdAt,
107
+ scheduledRunId: () => import_nestjs_durable_core22.scheduledRunId,
108
+ signTenantToken: () => import_nestjs_durable_core22.signTenantToken,
109
109
  tenantScheduleAnnouncement: () => tenantScheduleAnnouncement,
110
110
  thinWorkerProviders: () => thinWorkerProviders,
111
- triggeredRunsOf: () => import_nestjs_durable_core21.triggeredRunsOf,
111
+ triggeredRunsOf: () => import_nestjs_durable_core22.triggeredRunsOf,
112
112
  unavailableRunGateway: () => unavailableRunGateway
113
113
  });
114
114
  module.exports = __toCommonJS(src_exports);
@@ -811,95 +811,216 @@ var DurableStartClient = class {
811
811
  options;
812
812
  deps;
813
813
  accessor;
814
+ requests;
814
815
  tenant;
815
816
  tenantToken;
816
- constructor(options, deps, accessor) {
817
+ policies = /* @__PURE__ */ new Map();
818
+ warnedCoalescing = /* @__PURE__ */ new Set();
819
+ constructor(options, deps, accessor, requests) {
817
820
  this.options = options;
818
821
  this.deps = deps;
819
822
  this.accessor = accessor;
823
+ this.requests = requests;
820
824
  this.tenant = options.partition ?? "default";
821
825
  this.tenantToken = resolveTenantTokenSource(options.tenantToken);
822
826
  }
823
- async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
824
- const name = (0, import_nestjs_durable_core3.workflowName)(workflow);
825
- const tenant = opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
827
+ /**
828
+ * Apply `policy` to every start of `workflow` from this process (see
829
+ * {@link TenantWorkflowStartPolicy}). Called by `ThinWorkflowRegistrar` at boot.
830
+ */
831
+ declareWorkflow(workflow, policy) {
832
+ this.policies.set(workflow, policy);
833
+ }
834
+ /**
835
+ * 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
837
+ * workflow's.
838
+ */
839
+ async applyPolicy(workflow, input, opts) {
840
+ const policy = this.policies.get(workflow);
841
+ if (!policy) return opts?.concurrency !== void 0 ? {
842
+ concurrency: opts.concurrency
843
+ } : {};
844
+ await policy.validateInput?.(input);
845
+ const concurrency = await (0, import_nestjs_durable_core3.resolveConcurrency)(opts?.concurrency, policy.concurrency, input);
846
+ const singleton = policy.singleton ? {
847
+ key: policy.singleton.key(input),
848
+ ...policy.singleton.limit !== void 0 ? {
849
+ limit: policy.singleton.limit
850
+ } : {},
851
+ ...policy.singleton.maxQueueDepth !== void 0 ? {
852
+ maxQueueDepth: policy.singleton.maxQueueDepth
853
+ } : {}
854
+ } : void 0;
855
+ return {
856
+ ...singleton ? {
857
+ singleton
858
+ } : {},
859
+ ...concurrency ? {
860
+ concurrency
861
+ } : {}
862
+ };
863
+ }
864
+ /** The wire `tenant`: the signed token when configured, else the partition. */
865
+ async wireTenant() {
866
+ return this.tenantToken !== void 0 ? await (0, import_nestjs_durable_core3.resolveTenantToken)(this.tenantToken) : this.tenant;
867
+ }
868
+ /**
869
+ * The customer tenant a start claims: an explicit `tenantId` (`null` = none), else the request's
870
+ * tenant when tenancy is on.
871
+ */
872
+ claimedTenant(opts) {
873
+ return opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
826
874
  id: opts.tenantId,
827
- kind: opts.tenantKind
875
+ ...opts.tenantKind !== void 0 ? {
876
+ kind: opts.tenantKind
877
+ } : {}
828
878
  } : currentTenant(this.options.tenancy, this.accessor);
879
+ }
880
+ async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
881
+ const message = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
829
882
  await startRun(this.options.connection, {
830
883
  // The signed token (when configured) rides in the `tenant` field, as on every run request; an
831
884
  // operator with `verifyTenant` derives the run's namespace from it.
832
- tenant: this.tenantToken !== void 0 ? await (0, import_nestjs_durable_core3.resolveTenantToken)(this.tenantToken) : this.tenant,
833
- workflow: name,
834
- input,
835
- runId,
885
+ tenant: await this.wireTenant(),
886
+ ...message,
836
887
  // Option B: DO NOT pass `namespace` — the start-run queue stays the shared
837
888
  // `durable-start-run` the operator consumes; tenant rides only as message data.
838
889
  ...this.options.prefix !== void 0 ? {
839
890
  prefix: this.options.prefix
840
891
  } : {},
892
+ ...this.deps !== void 0 ? {
893
+ deps: this.deps
894
+ } : {}
895
+ });
896
+ const startAtMs = message.startAt;
897
+ return {
898
+ runId,
899
+ status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
900
+ };
901
+ }
902
+ /**
903
+ * The start-run a start of `name` sends (everything but the wire `tenant`): the start options the
904
+ * control plane applies (version pin, priority, delayed start, quota), the singleton key and the
905
+ * customer tenant this run claims. Applies the workflow's declared policy first, so a rejected
906
+ * input throws before anything is published, as `engine.start` does.
907
+ */
908
+ async startMessage(name, input, runId, opts) {
909
+ const tenant = this.claimedTenant(opts);
910
+ const policy = await this.applyPolicy(name, input, opts);
911
+ const startAt = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
912
+ return {
913
+ workflow: name,
914
+ input,
915
+ runId,
841
916
  ...opts?.tags !== void 0 ? {
842
917
  tags: opts.tags
843
918
  } : {},
844
919
  ...opts?.searchAttributes !== void 0 ? {
845
920
  searchAttributes: opts.searchAttributes
846
921
  } : {},
847
- // The start options the control plane applies (version pin, priority, delayed start, quota).
848
922
  ...opts?.version !== void 0 ? {
849
923
  version: opts.version
850
924
  } : {},
851
925
  ...opts?.priority !== void 0 ? {
852
926
  priority: opts.priority
853
927
  } : {},
854
- ...opts?.startAt !== void 0 ? {
855
- startAt: opts.startAt
928
+ ...startAt !== void 0 ? {
929
+ startAt
930
+ } : {},
931
+ ...policy.concurrency !== void 0 ? {
932
+ concurrency: policy.concurrency
856
933
  } : {},
857
- ...opts?.concurrency !== void 0 ? {
858
- concurrency: opts.concurrency
934
+ ...policy.singleton !== void 0 ? {
935
+ singleton: policy.singleton
859
936
  } : {},
860
937
  ...tenant ? {
861
938
  tenantId: tenant.id,
862
939
  ...tenant.kind !== void 0 ? {
863
940
  tenantKind: tenant.kind
864
941
  } : {}
865
- } : {},
866
- ...this.deps !== void 0 ? {
867
- deps: this.deps
868
942
  } : {}
869
- });
870
- const startAtMs = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
943
+ };
944
+ }
945
+ /** The control plane's run requests, or a clear error naming what is missing. */
946
+ runRequests(method) {
947
+ const requests = this.requests?.();
948
+ if (!requests) {
949
+ throw new Error(`${method}() on a tenant is sent to the control plane as a run request, which needs \`transport\` on DurableModule.forRoot (the tenant's BullMQTransport).`);
950
+ }
951
+ return requests;
952
+ }
953
+ /**
954
+ * Signal the run of this tenant's partition waiting on `token`, through the control plane.
955
+ * Resolves the resumed run, or null when no run of this partition waits on it: unlike
956
+ * `engine.signal` on a control plane, a tenant's signal is NOT buffered for a wait opened later
957
+ * (another partition's run could open it). Use `signalWithStart` to signal a run that may not wait
958
+ * yet. `opts.id` deduplicates like `engine.signal`.
959
+ */
960
+ async signal(token, payload, opts) {
961
+ return this.runRequests("signal").signal(token, payload, opts);
962
+ }
963
+ async signalWithStart(workflow, input, runId, signal, opts) {
964
+ const requests = this.runRequests("signalWithStart");
965
+ const start = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
966
+ const result = await requests.signalWithStart(start, signal);
871
967
  return {
872
- runId,
873
- status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
968
+ runId: result.runId
874
969
  };
875
970
  }
971
+ /**
972
+ * Publish event `name` from this tenant. Starts this app's own `onEvent` subscribers (each one
973
+ * whose `where` accepts the payload, with its `input` mapping) as runs of this partition, by the
974
+ * start path ({@link start}, run id `evt:<id>:<workflow>`), and has the control plane resume the
975
+ * runs of this partition waiting on it (`ctx.waitForEvent`). Resolves how many runs it started or
976
+ * resumed; a subscriber that throws is warned about and skipped. Unlike a control plane's
977
+ * `publishEvent`, an event nobody received is not buffered (there is no `buffer` option), and
978
+ * a subscriber's `debounce`/`batch` is not applied (it starts once per event, with a warning).
979
+ */
980
+ async publishEvent(name, payload, opts) {
981
+ const requests = this.runRequests("publishEvent");
982
+ const eventId = opts?.id ?? globalThis.crypto.randomUUID();
983
+ let started = 0;
984
+ for (const [workflow, policy] of this.policies) {
985
+ try {
986
+ const subscriptions = (policy.onEvent ?? []).map(import_nestjs_durable_core3.toEventSubscription).filter((sub) => sub.event === name);
987
+ const { accepted, errors } = (0, import_nestjs_durable_core3.acceptingSubscription)(subscriptions, payload);
988
+ if (!accepted) {
989
+ if (errors.length > 0) throw errors[0];
990
+ continue;
991
+ }
992
+ if (policy.coalesces && !this.warnedCoalescing.has(workflow)) {
993
+ this.warnedCoalescing.add(workflow);
994
+ console.warn(`[nestjs-durable] ${workflow} debounces/batches its events, which a tenant's publishEvent does not apply: it starts once per event.`);
995
+ }
996
+ const input = accepted.input ? accepted.input(payload) : payload;
997
+ await this.start(workflow, input, `evt:${eventId}:${workflow}`);
998
+ started += 1;
999
+ } catch (error) {
1000
+ console.warn(`[nestjs-durable] event ${name}: subscriber ${workflow} not started:`, error);
1001
+ }
1002
+ }
1003
+ const resumed = await requests.publishEvent(name, payload, {
1004
+ id: eventId
1005
+ });
1006
+ return started + resumed;
1007
+ }
876
1008
  cancel(_runId) {
877
1009
  return tenantUnsupported("cancel");
878
1010
  }
879
1011
  deleteRun(_runId) {
880
1012
  return tenantUnsupported("deleteRun");
881
1013
  }
882
- // — everything below rejects: a tenant worker holds no store/driver, only the start channel. —
883
- // The remaining WorkflowEngine surface WorkflowService delegates to (resume/waitForRun/signal/
884
- // signalWithStart/publishEvent) all need the store or driver a tenant does not have. A tenant only
885
- // ever calls `start`; these exist so a mistaken call fails with a CLEAR, named tenant error instead
886
- // of a cryptic `this.engine.X is not a function` — the facade is honest about what it cannot do.
887
- // Params mirror the WorkflowEngine surface being faced; every method rejects without reading them.
1014
+ // — everything below rejects: a tenant worker holds no store/driver. —
1015
+ // `resume`/`waitForRun` need the store or driver a tenant does not have. They exist so a mistaken
1016
+ // call fails with a CLEAR, named tenant error instead of a cryptic `this.engine.X is not a
1017
+ // function`. Params mirror the WorkflowEngine surface; every method rejects without reading them.
888
1018
  resume(_runId) {
889
1019
  return tenantUnsupported("resume");
890
1020
  }
891
1021
  waitForRun(_runId, _opts) {
892
1022
  return tenantUnsupported("waitForRun");
893
1023
  }
894
- signal(_token, _payload) {
895
- return tenantUnsupported("signal");
896
- }
897
- signalWithStart(_workflow, _input, _runId, _signal, _opts) {
898
- return tenantUnsupported("signalWithStart");
899
- }
900
- publishEvent(_name, _payload, _opts) {
901
- return tenantUnsupported("publishEvent");
902
- }
903
1024
  };
904
1025
  DurableStartClient = _ts_decorate([
905
1026
  (0, import_common.Injectable)(),
@@ -907,7 +1028,8 @@ DurableStartClient = _ts_decorate([
907
1028
  _ts_metadata("design:paramtypes", [
908
1029
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
909
1030
  typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
910
- typeof ContextAccessor === "undefined" ? Object : ContextAccessor
1031
+ typeof ContextAccessor === "undefined" ? Object : ContextAccessor,
1032
+ Function
911
1033
  ])
912
1034
  ], DurableStartClient);
913
1035
  function tenantUnsupported(method) {
@@ -916,8 +1038,8 @@ function tenantUnsupported(method) {
916
1038
  __name(tenantUnsupported, "tenantUnsupported");
917
1039
 
918
1040
  // src/durable-worker.module.ts
919
- var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
920
- var import_common2 = require("@nestjs/common");
1041
+ var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
1042
+ var import_common3 = require("@nestjs/common");
921
1043
  var import_core = require("@nestjs/core");
922
1044
 
923
1045
  // src/schema-parse.ts
@@ -1028,8 +1150,99 @@ function scanSteps(discovery, scanner, register) {
1028
1150
  }
1029
1151
  __name(scanSteps, "scanSteps");
1030
1152
 
1031
- // src/on-error-handlers.ts
1153
+ // src/entity.ts
1032
1154
  var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
1155
+ var import_common2 = require("@nestjs/common");
1156
+ var import_reflect_metadata2 = require("reflect-metadata");
1157
+ function _ts_decorate2(decorators, target, key, desc) {
1158
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1159
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1160
+ r = Reflect.decorate(decorators, target, key, desc);
1161
+ } else {
1162
+ for (var i = decorators.length - 1; i >= 0; i--) {
1163
+ if (d = decorators[i]) {
1164
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1165
+ }
1166
+ }
1167
+ }
1168
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1169
+ }
1170
+ __name(_ts_decorate2, "_ts_decorate");
1171
+ function _ts_metadata2(metadataKey, metadataValue) {
1172
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1173
+ return Reflect.metadata(metadataKey, metadataValue);
1174
+ }
1175
+ }
1176
+ __name(_ts_metadata2, "_ts_metadata");
1177
+ var ENTITY_METADATA = Symbol("nestjs-durable:entity");
1178
+ var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
1179
+ function Entity(options) {
1180
+ return (target) => {
1181
+ Reflect.defineMetadata(ENTITY_METADATA, options, target);
1182
+ };
1183
+ }
1184
+ __name(Entity, "Entity");
1185
+ function On(op) {
1186
+ return (target, propertyKey) => {
1187
+ const ctor = target.constructor;
1188
+ const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
1189
+ ops.set(op, propertyKey);
1190
+ Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
1191
+ };
1192
+ }
1193
+ __name(On, "On");
1194
+ function getEntityMeta(target) {
1195
+ return Reflect.getMetadata(ENTITY_METADATA, target);
1196
+ }
1197
+ __name(getEntityMeta, "getEntityMeta");
1198
+ function entityConfigFor(ctor) {
1199
+ const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
1200
+ const Cls = ctor;
1201
+ const handlers = {};
1202
+ for (const [op, method] of ops) {
1203
+ handlers[op] = (state, arg) => {
1204
+ Object.setPrototypeOf(state, Cls.prototype);
1205
+ const fn = state[method];
1206
+ if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
1207
+ return fn.call(state, arg);
1208
+ };
1209
+ }
1210
+ return {
1211
+ initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
1212
+ handlers
1213
+ };
1214
+ }
1215
+ __name(entityConfigFor, "entityConfigFor");
1216
+ var EntityService = class {
1217
+ static {
1218
+ __name(this, "EntityService");
1219
+ }
1220
+ engine;
1221
+ constructor(engine) {
1222
+ this.engine = engine;
1223
+ }
1224
+ /** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
1225
+ signal(name, key, op, arg) {
1226
+ return this.engine.signalEntity(name, key, op, arg);
1227
+ }
1228
+ /** Read an entity's current durable state (or undefined if it has none yet). */
1229
+ getState(name, key) {
1230
+ return this.engine.getEntityState(name, key);
1231
+ }
1232
+ };
1233
+ EntityService = _ts_decorate2([
1234
+ (0, import_common2.Injectable)(),
1235
+ _ts_metadata2("design:type", Function),
1236
+ _ts_metadata2("design:paramtypes", [
1237
+ typeof import_nestjs_durable_core5.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core5.WorkflowEngine
1238
+ ])
1239
+ ], EntityService);
1240
+
1241
+ // src/runtime-registration.ts
1242
+ var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
1243
+
1244
+ // src/on-error-handlers.ts
1245
+ var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
1033
1246
  function onErrorHandlersOf(meta, instance, scanner) {
1034
1247
  const handlers = [];
1035
1248
  const routes = [];
@@ -1050,7 +1263,7 @@ function onErrorHandlersOf(meta, instance, scanner) {
1050
1263
  for (const r of meta.onError ?? []) {
1051
1264
  routes.push({
1052
1265
  code: r.code === void 0 || typeof r.code === "string" ? r.code : r.code.code,
1053
- workflow: (0, import_nestjs_durable_core5.workflowName)(r.workflow)
1266
+ workflow: (0, import_nestjs_durable_core6.workflowName)(r.workflow)
1054
1267
  });
1055
1268
  }
1056
1269
  return {
@@ -1079,7 +1292,7 @@ function workflowIo(meta) {
1079
1292
  __name(workflowIo, "workflowIo");
1080
1293
 
1081
1294
  // src/runtime-registration.ts
1082
- function registerOnRuntime(runtime, scanner, meta, instance, origin) {
1295
+ function registerOnRuntime(runtime, scanner, meta, instance, origin, deadLetter) {
1083
1296
  const { handlers, routes } = onErrorHandlersOf(meta, instance, scanner);
1084
1297
  const announced = {
1085
1298
  version: meta.version,
@@ -1107,20 +1320,61 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
1107
1320
  } : {},
1108
1321
  ...subscribes.length > 0 ? {
1109
1322
  subscribes
1323
+ } : {},
1324
+ ...announcedOptions(meta),
1325
+ ...deadLetter !== void 0 ? {
1326
+ deadLetter
1110
1327
  } : {}
1111
1328
  });
1112
1329
  for (const [name, fn] of handlers) runtime.registerWorkflow(name, fn, announced);
1113
1330
  }
1114
1331
  __name(registerOnRuntime, "registerOnRuntime");
1332
+ function announcedOptions(meta) {
1333
+ const options = {};
1334
+ if (meta.tags !== void 0 && meta.tags.length > 0) options.tags = [
1335
+ ...meta.tags
1336
+ ];
1337
+ if (meta.executionTimeout !== void 0) {
1338
+ options.executionTimeoutMs = (0, import_nestjs_durable_core7.parseDuration)(meta.executionTimeout);
1339
+ }
1340
+ if (meta.singleton !== void 0) {
1341
+ options.singleton = {
1342
+ ...meta.singleton.limit !== void 0 ? {
1343
+ limit: meta.singleton.limit
1344
+ } : {},
1345
+ ...meta.singleton.maxQueueDepth !== void 0 ? {
1346
+ maxQueueDepth: meta.singleton.maxQueueDepth
1347
+ } : {}
1348
+ };
1349
+ }
1350
+ return Object.keys(options).length > 0 ? {
1351
+ options
1352
+ } : {};
1353
+ }
1354
+ __name(announcedOptions, "announcedOptions");
1355
+
1356
+ // src/step-interceptor.ts
1357
+ var import_reflect_metadata3 = require("reflect-metadata");
1358
+ var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
1359
+ function StepInterceptor() {
1360
+ return (target) => {
1361
+ Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
1362
+ };
1363
+ }
1364
+ __name(StepInterceptor, "StepInterceptor");
1365
+ function isStepInterceptor(target) {
1366
+ return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
1367
+ }
1368
+ __name(isStepInterceptor, "isStepInterceptor");
1115
1369
 
1116
1370
  // src/tokens.ts
1117
- var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
1371
+ var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
1118
1372
  var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
1119
1373
  var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
1120
- var RUN_GATEWAY = import_nestjs_durable_core6.RunGateway;
1374
+ var RUN_GATEWAY = import_nestjs_durable_core8.RunGateway;
1121
1375
 
1122
1376
  // src/durable-worker.module.ts
1123
- function _ts_decorate2(decorators, target, key, desc) {
1377
+ function _ts_decorate3(decorators, target, key, desc) {
1124
1378
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1125
1379
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1126
1380
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1133,19 +1387,29 @@ function _ts_decorate2(decorators, target, key, desc) {
1133
1387
  }
1134
1388
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1135
1389
  }
1136
- __name(_ts_decorate2, "_ts_decorate");
1137
- function _ts_metadata2(metadataKey, metadataValue) {
1390
+ __name(_ts_decorate3, "_ts_decorate");
1391
+ function _ts_metadata3(metadataKey, metadataValue) {
1138
1392
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1139
1393
  return Reflect.metadata(metadataKey, metadataValue);
1140
1394
  }
1141
1395
  }
1142
- __name(_ts_metadata2, "_ts_metadata");
1396
+ __name(_ts_metadata3, "_ts_metadata");
1143
1397
  function _ts_param(paramIndex, decorator) {
1144
1398
  return function(target, key) {
1145
1399
  decorator(target, key, paramIndex);
1146
1400
  };
1147
1401
  }
1148
1402
  __name(_ts_param, "_ts_param");
1403
+ function deadLetterHandlerOf(instance, scanner) {
1404
+ for (const name of scanner.getAllMethodNames(Object.getPrototypeOf(instance))) {
1405
+ const method = instance[name];
1406
+ if (typeof method === "function" && isDeadLetterHandler(method)) {
1407
+ return (ctx, input) => method.call(instance, ctx, input);
1408
+ }
1409
+ }
1410
+ return void 0;
1411
+ }
1412
+ __name(deadLetterHandlerOf, "deadLetterHandlerOf");
1149
1413
  var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
1150
1414
  var DURABLE_WORKER_RUNTIME = Symbol("nestjs-durable:worker-runtime");
1151
1415
  var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
@@ -1173,21 +1437,78 @@ var ThinWorkflowRegistrar = class {
1173
1437
  const runtime = this.runtime;
1174
1438
  if (runtime === null || !isPureThinWorker(this.options)) return;
1175
1439
  const starter = this.starter;
1440
+ this.assertNoEntities();
1441
+ this.useInterceptors(runtime);
1442
+ const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(this.options.deadLetterWorkflow) : void 0;
1176
1443
  scanWorkflows(this.discovery, (meta, instance, origin) => {
1177
- registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin);
1178
- (0, import_nestjs_durable_core7.bindWorkflowClass)(instance.constructor, {
1444
+ const inline = deadLetterHandlerOf(instance, this.metadataScanner);
1445
+ if (inline && meta.deadLetterWorkflow) {
1446
+ throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
1447
+ }
1448
+ const deadLetter = inline ? `${meta.name}.dlq` : meta.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(meta.deadLetterWorkflow) : fallback;
1449
+ registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin, deadLetter);
1450
+ if (inline) {
1451
+ runtime.registerWorkflow(`${meta.name}.dlq`, inline, {
1452
+ version: meta.version,
1453
+ ...origin !== void 0 ? {
1454
+ origin
1455
+ } : {}
1456
+ });
1457
+ }
1458
+ const declare = starter.declareWorkflow;
1459
+ if (typeof declare === "function") {
1460
+ const policy = {
1461
+ validateInput: workflowIo(meta).validateAtStart,
1462
+ singleton: meta.singleton,
1463
+ concurrency: meta.concurrency,
1464
+ onEvent: getOnEvents(meta, instance.constructor),
1465
+ coalesces: eventBatchOf(meta, instance.constructor) !== void 0
1466
+ };
1467
+ declare.call(starter, meta.name, policy);
1468
+ }
1469
+ (0, import_nestjs_durable_core9.bindWorkflowClass)(instance.constructor, {
1179
1470
  start: /* @__PURE__ */ __name((name, input, runId, opts) => starter.start(name, input, runId, opts), "start")
1180
1471
  });
1181
1472
  });
1182
1473
  }
1474
+ /**
1475
+ * `@Entity` providers are refused on a tenant, at boot: an entity's state is a run on the store
1476
+ * and its `@On` handlers run inside the engine that owns that store (`EntityService` and
1477
+ * `ctx.callEntity`/`signalEntity` read and serialize it there). A tenant has no store and no
1478
+ * engine, so an entity declared here would never run. Declare it on the control plane.
1479
+ */
1480
+ assertNoEntities() {
1481
+ const entities = this.discovery.getProviders().map((w) => w.instance).filter((i) => !!i && typeof i === "object" && !!getEntityMeta(i.constructor)).map((i) => getEntityMeta(i.constructor)?.name);
1482
+ if (entities.length === 0) return;
1483
+ throw new Error(`@Entity ${entities.join(", ")} cannot be declared on a DurableModule tenant (connection, no store): an entity's state and handlers live in the engine that owns the store. Declare it on the control plane.`);
1484
+ }
1485
+ /**
1486
+ * `@StepInterceptor()` providers wrap every step this tenant runs (each `ctx.step` its workers
1487
+ * execute), as `engine.use` does on an engine. A `@durable-worker` too old to take interceptors
1488
+ * says so instead of dropping them silently.
1489
+ */
1490
+ useInterceptors(runtime) {
1491
+ for (const wrapper of this.discovery.getProviders()) {
1492
+ const instance = wrapper.instance;
1493
+ if (!instance || typeof instance !== "object" || !isStepInterceptor(instance.constructor)) {
1494
+ continue;
1495
+ }
1496
+ const interceptor = instance;
1497
+ if (typeof runtime.use !== "function") {
1498
+ console.warn(`[nestjs-durable] @StepInterceptor ${instance.constructor.name} is not applied: this @dudousxd/durable-worker predates step interceptors on a tenant; upgrade it.`);
1499
+ continue;
1500
+ }
1501
+ runtime.use((invocation, next) => interceptor.intercept(invocation, next));
1502
+ }
1503
+ }
1183
1504
  };
1184
- ThinWorkflowRegistrar = _ts_decorate2([
1185
- (0, import_common2.Injectable)(),
1186
- _ts_param(2, (0, import_common2.Inject)(DURABLE_WORKER_RUNTIME)),
1187
- _ts_param(3, (0, import_common2.Inject)(import_nestjs_durable_core7.DURABLE_OPTIONS_CANONICAL)),
1188
- _ts_param(4, (0, import_common2.Inject)(import_nestjs_durable_core7.WorkflowEngine)),
1189
- _ts_metadata2("design:type", Function),
1190
- _ts_metadata2("design:paramtypes", [
1505
+ ThinWorkflowRegistrar = _ts_decorate3([
1506
+ (0, import_common3.Injectable)(),
1507
+ _ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
1508
+ _ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
1509
+ _ts_param(4, (0, import_common3.Inject)(import_nestjs_durable_core9.WorkflowEngine)),
1510
+ _ts_metadata3("design:type", Function),
1511
+ _ts_metadata3("design:paramtypes", [
1191
1512
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
1192
1513
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
1193
1514
  Object,
@@ -1215,12 +1536,12 @@ var ThinStepRegistrar = class {
1215
1536
  scanSteps(this.discovery, this.metadataScanner, (meta, handler) => runtime.registerStep(meta.name, handler));
1216
1537
  }
1217
1538
  };
1218
- ThinStepRegistrar = _ts_decorate2([
1219
- (0, import_common2.Injectable)(),
1220
- _ts_param(2, (0, import_common2.Inject)(DURABLE_WORKER_RUNTIME)),
1221
- _ts_param(3, (0, import_common2.Inject)(import_nestjs_durable_core7.DURABLE_OPTIONS_CANONICAL)),
1222
- _ts_metadata2("design:type", Function),
1223
- _ts_metadata2("design:paramtypes", [
1539
+ ThinStepRegistrar = _ts_decorate3([
1540
+ (0, import_common3.Injectable)(),
1541
+ _ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
1542
+ _ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
1543
+ _ts_metadata3("design:type", Function),
1544
+ _ts_metadata3("design:paramtypes", [
1224
1545
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
1225
1546
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
1226
1547
  Object,
@@ -1280,15 +1601,15 @@ var ThinWorkerBootstrap = class {
1280
1601
  await Promise.allSettled(this.runners.map((h) => h.close()));
1281
1602
  }
1282
1603
  };
1283
- ThinWorkerBootstrap = _ts_decorate2([
1284
- (0, import_common2.Injectable)(),
1285
- _ts_param(0, (0, import_common2.Inject)(DURABLE_WORKER_RUNTIME)),
1286
- _ts_param(1, (0, import_common2.Inject)(import_nestjs_durable_core7.DURABLE_OPTIONS_CANONICAL)),
1287
- _ts_param(2, (0, import_common2.Inject)(RUN_REDIS_WORKER)),
1288
- _ts_param(3, (0, import_common2.Inject)(DURABLE_WORKER_RUNNERS)),
1289
- _ts_param(4, (0, import_common2.Inject)(TENANT_AUTH)),
1290
- _ts_metadata2("design:type", Function),
1291
- _ts_metadata2("design:paramtypes", [
1604
+ ThinWorkerBootstrap = _ts_decorate3([
1605
+ (0, import_common3.Injectable)(),
1606
+ _ts_param(0, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
1607
+ _ts_param(1, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
1608
+ _ts_param(2, (0, import_common3.Inject)(RUN_REDIS_WORKER)),
1609
+ _ts_param(3, (0, import_common3.Inject)(DURABLE_WORKER_RUNNERS)),
1610
+ _ts_param(4, (0, import_common3.Inject)(TENANT_AUTH)),
1611
+ _ts_metadata3("design:type", Function),
1612
+ _ts_metadata3("design:paramtypes", [
1292
1613
  Object,
1293
1614
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
1294
1615
  typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
@@ -1299,7 +1620,7 @@ ThinWorkerBootstrap = _ts_decorate2([
1299
1620
  async function tenantScheduleAnnouncement(options, tenantToken) {
1300
1621
  let tenant;
1301
1622
  try {
1302
- tenant = tenantToken !== void 0 ? await (0, import_nestjs_durable_core7.resolveTenantToken)(tenantToken) : options.partition ?? "default";
1623
+ tenant = tenantToken !== void 0 ? await (0, import_nestjs_durable_core9.resolveTenantToken)(tenantToken) : options.partition ?? "default";
1303
1624
  } catch (error) {
1304
1625
  console.warn(`[nestjs-durable] this worker announces no schedules: its tenantToken failed (${error instanceof Error ? error.message : String(error)})`);
1305
1626
  return {};
@@ -1315,7 +1636,7 @@ __name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
1315
1636
  function announcedSchedule(s) {
1316
1637
  const item = {
1317
1638
  key: s.key,
1318
- workflow: (0, import_nestjs_durable_core7.workflowName)(s.workflow)
1639
+ workflow: (0, import_nestjs_durable_core9.workflowName)(s.workflow)
1319
1640
  };
1320
1641
  if (s.input !== void 0) item.input = s.input;
1321
1642
  if (s.everyMs !== void 0) item.everyMs = s.everyMs;
@@ -1324,6 +1645,18 @@ function announcedSchedule(s) {
1324
1645
  if (s.paused === true) item.paused = true;
1325
1646
  if (s.overlap !== void 0) item.overlap = s.overlap;
1326
1647
  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) {
1650
+ item.singleton = {
1651
+ key: singleton.key(s.input),
1652
+ ...singleton.limit !== void 0 ? {
1653
+ limit: singleton.limit
1654
+ } : {},
1655
+ ...singleton.maxQueueDepth !== void 0 ? {
1656
+ maxQueueDepth: singleton.maxQueueDepth
1657
+ } : {}
1658
+ };
1659
+ }
1327
1660
  return item;
1328
1661
  }
1329
1662
  __name(announcedSchedule, "announcedSchedule");
@@ -1346,7 +1679,7 @@ function thinWorkerProviders() {
1346
1679
  workflowGroup: options.partition ?? ""
1347
1680
  }) : null, "useFactory"),
1348
1681
  inject: [
1349
- import_nestjs_durable_core7.DURABLE_OPTIONS_CANONICAL
1682
+ import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
1350
1683
  ]
1351
1684
  },
1352
1685
  {
@@ -1416,13 +1749,13 @@ function unavailableRunGateway() {
1416
1749
  __name(unavailableRunGateway, "unavailableRunGateway");
1417
1750
 
1418
1751
  // src/durable.module.ts
1419
- var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
1752
+ var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
1420
1753
  var import_common13 = require("@nestjs/common");
1421
1754
  var import_core6 = require("@nestjs/core");
1422
1755
 
1423
1756
  // src/durable-step.registrar.ts
1424
- var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
1425
- var import_common3 = require("@nestjs/common");
1757
+ var import_nestjs_durable_core10 = require("@dudousxd/nestjs-durable-core");
1758
+ var import_common4 = require("@nestjs/common");
1426
1759
  var import_core2 = require("@nestjs/core");
1427
1760
 
1428
1761
  // src/role.ts
@@ -1436,7 +1769,7 @@ function isDrivingOperator(options) {
1436
1769
  __name(isDrivingOperator, "isDrivingOperator");
1437
1770
 
1438
1771
  // src/durable-step.registrar.ts
1439
- function _ts_decorate3(decorators, target, key, desc) {
1772
+ function _ts_decorate4(decorators, target, key, desc) {
1440
1773
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1441
1774
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1442
1775
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1449,13 +1782,13 @@ function _ts_decorate3(decorators, target, key, desc) {
1449
1782
  }
1450
1783
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1451
1784
  }
1452
- __name(_ts_decorate3, "_ts_decorate");
1453
- function _ts_metadata3(metadataKey, metadataValue) {
1785
+ __name(_ts_decorate4, "_ts_decorate");
1786
+ function _ts_metadata4(metadataKey, metadataValue) {
1454
1787
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1455
1788
  return Reflect.metadata(metadataKey, metadataValue);
1456
1789
  }
1457
1790
  }
1458
- __name(_ts_metadata3, "_ts_metadata");
1791
+ __name(_ts_metadata4, "_ts_metadata");
1459
1792
  function _ts_param2(paramIndex, decorator) {
1460
1793
  return function(target, key) {
1461
1794
  decorator(target, key, paramIndex);
@@ -1487,12 +1820,12 @@ var DurableStepRegistrar = class {
1487
1820
  scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler, this.options.partition));
1488
1821
  }
1489
1822
  };
1490
- DurableStepRegistrar = _ts_decorate3([
1491
- (0, import_common3.Injectable)(),
1492
- _ts_param2(2, (0, import_common3.Inject)(import_nestjs_durable_core8.TRANSPORT_CANONICAL)),
1493
- _ts_param2(3, (0, import_common3.Inject)(import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL)),
1494
- _ts_metadata3("design:type", Function),
1495
- _ts_metadata3("design:paramtypes", [
1823
+ DurableStepRegistrar = _ts_decorate4([
1824
+ (0, import_common4.Injectable)(),
1825
+ _ts_param2(2, (0, import_common4.Inject)(import_nestjs_durable_core10.TRANSPORT_CANONICAL)),
1826
+ _ts_param2(3, (0, import_common4.Inject)(import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL)),
1827
+ _ts_metadata4("design:type", Function),
1828
+ _ts_metadata4("design:paramtypes", [
1496
1829
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
1497
1830
  typeof import_core2.MetadataScanner === "undefined" ? Object : import_core2.MetadataScanner,
1498
1831
  Object,
@@ -1500,96 +1833,8 @@ DurableStepRegistrar = _ts_decorate3([
1500
1833
  ])
1501
1834
  ], DurableStepRegistrar);
1502
1835
 
1503
- // src/entity.ts
1504
- var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
1505
- var import_common4 = require("@nestjs/common");
1506
- var import_reflect_metadata2 = require("reflect-metadata");
1507
- function _ts_decorate4(decorators, target, key, desc) {
1508
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1509
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1510
- r = Reflect.decorate(decorators, target, key, desc);
1511
- } else {
1512
- for (var i = decorators.length - 1; i >= 0; i--) {
1513
- if (d = decorators[i]) {
1514
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1515
- }
1516
- }
1517
- }
1518
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1519
- }
1520
- __name(_ts_decorate4, "_ts_decorate");
1521
- function _ts_metadata4(metadataKey, metadataValue) {
1522
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1523
- return Reflect.metadata(metadataKey, metadataValue);
1524
- }
1525
- }
1526
- __name(_ts_metadata4, "_ts_metadata");
1527
- var ENTITY_METADATA = Symbol("nestjs-durable:entity");
1528
- var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
1529
- function Entity(options) {
1530
- return (target) => {
1531
- Reflect.defineMetadata(ENTITY_METADATA, options, target);
1532
- };
1533
- }
1534
- __name(Entity, "Entity");
1535
- function On(op) {
1536
- return (target, propertyKey) => {
1537
- const ctor = target.constructor;
1538
- const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
1539
- ops.set(op, propertyKey);
1540
- Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
1541
- };
1542
- }
1543
- __name(On, "On");
1544
- function getEntityMeta(target) {
1545
- return Reflect.getMetadata(ENTITY_METADATA, target);
1546
- }
1547
- __name(getEntityMeta, "getEntityMeta");
1548
- function entityConfigFor(ctor) {
1549
- const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
1550
- const Cls = ctor;
1551
- const handlers = {};
1552
- for (const [op, method] of ops) {
1553
- handlers[op] = (state, arg) => {
1554
- Object.setPrototypeOf(state, Cls.prototype);
1555
- const fn = state[method];
1556
- if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
1557
- return fn.call(state, arg);
1558
- };
1559
- }
1560
- return {
1561
- initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
1562
- handlers
1563
- };
1564
- }
1565
- __name(entityConfigFor, "entityConfigFor");
1566
- var EntityService = class {
1567
- static {
1568
- __name(this, "EntityService");
1569
- }
1570
- engine;
1571
- constructor(engine) {
1572
- this.engine = engine;
1573
- }
1574
- /** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
1575
- signal(name, key, op, arg) {
1576
- return this.engine.signalEntity(name, key, op, arg);
1577
- }
1578
- /** Read an entity's current durable state (or undefined if it has none yet). */
1579
- getState(name, key) {
1580
- return this.engine.getEntityState(name, key);
1581
- }
1582
- };
1583
- EntityService = _ts_decorate4([
1584
- (0, import_common4.Injectable)(),
1585
- _ts_metadata4("design:type", Function),
1586
- _ts_metadata4("design:paramtypes", [
1587
- typeof import_nestjs_durable_core9.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core9.WorkflowEngine
1588
- ])
1589
- ], EntityService);
1590
-
1591
1836
  // src/in-app-worker.ts
1592
- var import_nestjs_durable_core10 = require("@dudousxd/nestjs-durable-core");
1837
+ var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
1593
1838
  var import_common5 = require("@nestjs/common");
1594
1839
  var import_core3 = require("@nestjs/core");
1595
1840
  function _ts_decorate5(decorators, target, key, desc) {
@@ -1694,7 +1939,7 @@ var InAppWorkerBootstrap = class {
1694
1939
  };
1695
1940
  InAppWorkerBootstrap = _ts_decorate5([
1696
1941
  (0, import_common5.Injectable)(),
1697
- _ts_param3(2, (0, import_common5.Inject)(import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL)),
1942
+ _ts_param3(2, (0, import_common5.Inject)(import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL)),
1698
1943
  _ts_param3(3, (0, import_common5.Inject)(IN_APP_WORKER_RUNTIME)),
1699
1944
  _ts_param3(4, (0, import_common5.Inject)(IN_APP_RUN_REDIS_WORKER)),
1700
1945
  _ts_param3(5, (0, import_common5.Inject)(IN_APP_WORKER_RUNNERS)),
@@ -1714,8 +1959,8 @@ function inAppWorkerProviders() {
1714
1959
  provide: IN_APP_WORKER_BINDING,
1715
1960
  useFactory: /* @__PURE__ */ __name((transport, options) => inAppWorkerBinding(transport, options), "useFactory"),
1716
1961
  inject: [
1717
- import_nestjs_durable_core10.TRANSPORT_CANONICAL,
1718
- import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL
1962
+ import_nestjs_durable_core11.TRANSPORT_CANONICAL,
1963
+ import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
1719
1964
  ]
1720
1965
  },
1721
1966
  {
@@ -1735,7 +1980,7 @@ function inAppWorkerProviders() {
1735
1980
  workflowGroup: options.partition ?? ""
1736
1981
  }) : null, "useFactory"),
1737
1982
  inject: [
1738
- import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL
1983
+ import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
1739
1984
  ]
1740
1985
  },
1741
1986
  {
@@ -1752,11 +1997,11 @@ function inAppWorkerProviders() {
1752
1997
  __name(inAppWorkerProviders, "inAppWorkerProviders");
1753
1998
 
1754
1999
  // src/proxy-run-gateway.ts
1755
- var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
2000
+ var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
1756
2001
  var import_common6 = require("@nestjs/common");
1757
2002
 
1758
2003
  // src/run-request-responder.ts
1759
- var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
2004
+ var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
1760
2005
  var UNSUPPORTED_RUN_REQUEST = "unsupported-request";
1761
2006
  var BAD_RUN_REQUEST = "bad-request";
1762
2007
  var TENANT_REPUBLISH_MAX_LIMIT = 1e3;
@@ -1777,7 +2022,9 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
1777
2022
  "republishLifecycle",
1778
2023
  "workflowLifecycle",
1779
2024
  "signal",
1780
- "schedule"
2025
+ "schedule",
2026
+ "signalWithStart",
2027
+ "publishEvent"
1781
2028
  ]);
1782
2029
  function wireDate(value) {
1783
2030
  if (value === void 0 || value === null) return void 0;
@@ -1853,7 +2100,8 @@ var RunRequestResponder = class {
1853
2100
  });
1854
2101
  }
1855
2102
  async handle(wire) {
1856
- const tenant = await (0, import_nestjs_durable_core11.resolveWireTenant)(wire.tenant, this.verifyTenant);
2103
+ const verified = await (0, import_nestjs_durable_core12.verifyWireTenant)(wire.tenant, this.verifyTenant);
2104
+ const tenant = verified?.tenant ?? null;
1857
2105
  if (tenant === null) {
1858
2106
  return {
1859
2107
  requestId: wire.requestId,
@@ -2031,7 +2279,18 @@ var RunRequestResponder = class {
2031
2279
  }
2032
2280
  };
2033
2281
  }
2034
- return this.answer(msg.requestId, () => signal.call(this.gateway, body.token, body.payload));
2282
+ return this.answer(msg.requestId, () => body.opts === void 0 ? signal.call(this.gateway, body.token, body.payload) : signal.call(this.gateway, body.token, body.payload, body.opts));
2283
+ }
2284
+ if (body.kind === "signalWithStart") {
2285
+ return this.signalWithStart(msg.requestId, body, msg.tenant, verified);
2286
+ }
2287
+ if (body.kind === "publishEvent") {
2288
+ const { publishEventForTenant } = this.gateway;
2289
+ if (!publishEventForTenant) return unsupported(msg.requestId, body.kind);
2290
+ if (typeof body.name !== "string" || body.name === "") {
2291
+ return badRequest(msg.requestId, "publishEvent needs an event name");
2292
+ }
2293
+ return this.answer(msg.requestId, () => publishEventForTenant.call(this.gateway, body.name, body.payload, msg.tenant));
2035
2294
  }
2036
2295
  if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
2037
2296
  return unsupported(msg.requestId, body.kind);
@@ -2081,7 +2340,7 @@ var RunRequestResponder = class {
2081
2340
  };
2082
2341
  }
2083
2342
  if (body.kind === "republishLifecycle" && "runId" in body.target && run) {
2084
- const kind = (0, import_nestjs_durable_core11.lifecycleKindOf)(run.status);
2343
+ const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(run.status);
2085
2344
  const refused = kind ? await this.refuseSubscriber(run.workflow, kind, body.target.subscriber, msg.tenant) : void 0;
2086
2345
  if (refused) return badRequest(msg.requestId, refused);
2087
2346
  }
@@ -2106,6 +2365,50 @@ var RunRequestResponder = class {
2106
2365
  };
2107
2366
  }
2108
2367
  }
2368
+ /**
2369
+ * A tenant's `signalWithStart`: the run it names must be the requester's when it exists, and so
2370
+ * must a run already waiting on the token; anything else is refused `cross-tenant` before the
2371
+ * gateway is called. The run is started in the requester's namespace (a customer tenant it claims
2372
+ * is kept only when its verified token grants it, as for a start-run).
2373
+ */
2374
+ async signalWithStart(requestId, body, tenant, verified) {
2375
+ const { signalWithStartForTenant, signalWaiter } = this.gateway;
2376
+ if (!signalWithStartForTenant) return unsupported(requestId, body.kind);
2377
+ const start = body.start;
2378
+ if (!start || typeof start.runId !== "string" || start.runId === "" || typeof start.workflow !== "string" || start.workflow === "" || typeof body.signal?.token !== "string" || body.signal.token === "") {
2379
+ return badRequest(requestId, "signalWithStart needs a workflow, a run id and a signal token");
2380
+ }
2381
+ const crossTenant = {
2382
+ requestId,
2383
+ result: {
2384
+ ok: false,
2385
+ error: {
2386
+ message: "run belongs to another tenant",
2387
+ code: "cross-tenant"
2388
+ }
2389
+ }
2390
+ };
2391
+ const existing = await this.runOf(start.runId);
2392
+ if (existing && existing.namespace !== tenant) return crossTenant;
2393
+ const waiterRunId = signalWaiter ? await signalWaiter.call(this.gateway, body.signal.token) : null;
2394
+ const waiter = waiterRunId ? await this.runOf(waiterRunId) : null;
2395
+ if (waiter && waiter.namespace !== tenant) return crossTenant;
2396
+ const claim = start.tenantId !== void 0 ? (0, import_nestjs_durable_core12.grantsClientTenant)(verified, start.tenantId) ? {
2397
+ tenantId: start.tenantId,
2398
+ ...start.tenantKind !== void 0 ? {
2399
+ tenantKind: start.tenantKind
2400
+ } : {}
2401
+ } : {
2402
+ tenantId: null
2403
+ } : {};
2404
+ return this.answer(requestId, () => signalWithStartForTenant.call(this.gateway, {
2405
+ ...start,
2406
+ tenant
2407
+ }, tenant, claim, {
2408
+ token: body.signal.token,
2409
+ payload: body.signal.payload
2410
+ }));
2411
+ }
2109
2412
  /** The run alone (`getRun`, else from its detail), or null when it does not exist. */
2110
2413
  async runOf(runId) {
2111
2414
  return this.gateway.getRun ? this.gateway.getRun(runId) : (await this.gateway.getRunDetail(runId))?.run ?? null;
@@ -2147,7 +2450,7 @@ var RunRequestResponder = class {
2147
2450
  namespace: tenant
2148
2451
  });
2149
2452
  if (!links) return rest;
2150
- const kind = (0, import_nestjs_durable_core11.lifecycleKindOf)(detail.run.status);
2453
+ const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(detail.run.status);
2151
2454
  const subscribers = kind ? [
2152
2455
  ...new Set(links.startsOnSettle.filter((l) => l.kind === kind).map((l) => l.workflow))
2153
2456
  ] : [];
@@ -2274,6 +2577,10 @@ var RunGatewayError = class extends Error {
2274
2577
  this.code = code;
2275
2578
  }
2276
2579
  };
2580
+ function unsupportedVerb(kind) {
2581
+ return new RunGatewayError(`${kind} is not supported by this server: the control plane is older than this tenant`, UNSUPPORTED_RUN_REQUEST);
2582
+ }
2583
+ __name(unsupportedVerb, "unsupportedVerb");
2277
2584
  var UnsupportedRunRequestError = class UnsupportedRunRequestError2 extends RunGatewayError {
2278
2585
  static {
2279
2586
  __name(this, "UnsupportedRunRequestError");
@@ -2324,12 +2631,12 @@ var ProxyRunGateway = class {
2324
2631
  } catch (err) {
2325
2632
  return Promise.reject(err);
2326
2633
  }
2327
- return send(filter ? (0, import_nestjs_durable_core12.scopeTenantQuery)(query, filter) : query);
2634
+ return send(filter ? (0, import_nestjs_durable_core13.scopeTenantQuery)(query, filter) : query);
2328
2635
  }
2329
2636
  /** `run` when the request may see it, else null (an invisible run reads like a missing one). */
2330
2637
  visible(run, filter = this.restrictive()) {
2331
2638
  if (!run) return null;
2332
- return !filter || (0, import_nestjs_durable_core12.tenantVisible)(run, filter) ? run : null;
2639
+ return !filter || (0, import_nestjs_durable_core13.tenantVisible)(run, filter) ? run : null;
2333
2640
  }
2334
2641
  /** Run a control call unless the request may not act on `runId` (then `null`, like a missing run).
2335
2642
  * Sent at once when nothing narrows the request. */
@@ -2365,7 +2672,7 @@ var ProxyRunGateway = class {
2365
2672
  request(body) {
2366
2673
  const source = this.tenantToken;
2367
2674
  if (typeof source !== "function") return this.send(source ?? this.tenant, body);
2368
- return (0, import_nestjs_durable_core12.resolveTenantToken)(source).then((tenant) => this.send(tenant, body));
2675
+ return (0, import_nestjs_durable_core13.resolveTenantToken)(source).then((tenant) => this.send(tenant, body));
2369
2676
  }
2370
2677
  send(tenant, body) {
2371
2678
  return new Promise((resolve, reject) => {
@@ -2415,12 +2722,12 @@ var ProxyRunGateway = class {
2415
2722
  if (detail && filter && !this.visible(detail.run, filter)) return null;
2416
2723
  const over = options?.summarizeFansOver;
2417
2724
  if (over === void 0 || !detail || detail.fans !== void 0) return detail;
2418
- const { timeline, fans } = (0, import_nestjs_durable_core12.summarizeTimeline)(detail.timeline, over);
2419
- const ids = (0, import_nestjs_durable_core12.childIdsOf)(detail.timeline);
2725
+ const { timeline, fans } = (0, import_nestjs_durable_core13.summarizeTimeline)(detail.timeline, over);
2726
+ const ids = (0, import_nestjs_durable_core13.childIdsOf)(detail.timeline);
2420
2727
  return {
2421
2728
  ...detail,
2422
2729
  timeline,
2423
- children: ids.slice(0, import_nestjs_durable_core12.SUMMARY_CHILD_LIMIT),
2730
+ children: ids.slice(0, import_nestjs_durable_core13.SUMMARY_CHILD_LIMIT),
2424
2731
  fans,
2425
2732
  childCount: ids.length
2426
2733
  };
@@ -2446,7 +2753,7 @@ var ProxyRunGateway = class {
2446
2753
  kind: "getRunDetail",
2447
2754
  runId
2448
2755
  });
2449
- return detail ? (0, import_nestjs_durable_core12.pageFan)(detail.timeline, group, query) : null;
2756
+ return detail ? (0, import_nestjs_durable_core13.pageFan)(detail.timeline, group, query) : null;
2450
2757
  }
2451
2758
  /**
2452
2759
  * The run alone, without its timeline. Read from the full detail when the control plane is too old
@@ -2579,7 +2886,7 @@ var ProxyRunGateway = class {
2579
2886
  * {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
2580
2887
  */
2581
2888
  async requestNewVerb(body) {
2582
- const notSupported = /* @__PURE__ */ __name(() => new RunGatewayError(`${body.kind} is not supported by this server: the control plane is older than this tenant`, UNSUPPORTED_RUN_REQUEST), "notSupported");
2889
+ const notSupported = /* @__PURE__ */ __name(() => unsupportedVerb(body.kind), "notSupported");
2583
2890
  if (this.knownUnsupported(body.kind)) throw notSupported();
2584
2891
  let data;
2585
2892
  try {
@@ -2591,6 +2898,62 @@ var ProxyRunGateway = class {
2591
2898
  this.unsupportedUntil.set(body.kind, Date.now() + this.capabilityTtlMs);
2592
2899
  throw notSupported();
2593
2900
  }
2901
+ /**
2902
+ * Signal the run of this tenant's namespace waiting on `token` (`engine.signal`). Resolves null
2903
+ * when no run of this namespace waits on it: the control plane does NOT buffer a tenant's signal
2904
+ * for a wait opened later (another namespace's run could open it). A control plane that predates
2905
+ * the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error.
2906
+ */
2907
+ async signal(token, payload, opts) {
2908
+ if (this.knownUnsupported("signal")) throw unsupportedVerb("signal");
2909
+ let data;
2910
+ try {
2911
+ data = await this.request(opts === void 0 ? {
2912
+ kind: "signal",
2913
+ token,
2914
+ payload
2915
+ } : {
2916
+ kind: "signal",
2917
+ token,
2918
+ payload,
2919
+ opts
2920
+ });
2921
+ } catch (err) {
2922
+ if (!isUnsupported(err)) throw err;
2923
+ }
2924
+ if (data !== void 0) return data;
2925
+ this.unsupportedUntil.set("signal", Date.now() + this.capabilityTtlMs);
2926
+ throw unsupportedVerb("signal");
2927
+ }
2928
+ /**
2929
+ * `engine.signalWithStart` for this tenant: the control plane starts `start` in this tenant's
2930
+ * namespace unless its run exists, then signals it (buffered until the run waits, when the token
2931
+ * names the run id). See the responder for the authorization rule.
2932
+ */
2933
+ signalWithStart(start, signal) {
2934
+ return this.requestNewVerb({
2935
+ kind: "signalWithStart",
2936
+ start,
2937
+ signal
2938
+ });
2939
+ }
2940
+ /**
2941
+ * Resume the runs of this tenant's namespace waiting on event `name` (`ctx.waitForEvent`).
2942
+ * Resolves how many it resumed. The tenant's own `onEvent` subscribers are started by the caller
2943
+ * (`DurableStartClient.publishEvent`), not here.
2944
+ */
2945
+ publishEvent(name, payload, opts) {
2946
+ return this.requestNewVerb({
2947
+ kind: "publishEvent",
2948
+ name,
2949
+ payload,
2950
+ ...opts?.id !== void 0 ? {
2951
+ opts: {
2952
+ id: opts.id
2953
+ }
2954
+ } : {}
2955
+ });
2956
+ }
2594
2957
  subscribe(runId, onEvent) {
2595
2958
  const unsubscribe = this.transport.onTenantEvent?.(this.tenant, (evt) => {
2596
2959
  if (evt.event.runId === runId) onEvent(evt.event);
@@ -2613,7 +2976,7 @@ ProxyRunGateway = _ts_decorate6([
2613
2976
  ], ProxyRunGateway);
2614
2977
 
2615
2978
  // src/retention-poller.ts
2616
- var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
2979
+ var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
2617
2980
  var import_common8 = require("@nestjs/common");
2618
2981
 
2619
2982
  // src/settle-within.ts
@@ -2640,7 +3003,7 @@ async function settleWithin(p, timeoutMs) {
2640
3003
  __name(settleWithin, "settleWithin");
2641
3004
 
2642
3005
  // src/sweep-leases.ts
2643
- var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
3006
+ var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
2644
3007
  var import_common7 = require("@nestjs/common");
2645
3008
  var import_core4 = require("@nestjs/core");
2646
3009
  function _ts_decorate7(decorators, target, key, desc) {
@@ -2738,7 +3101,7 @@ SweepLeases = _ts_decorate7([
2738
3101
  (0, import_common7.Injectable)(),
2739
3102
  _ts_param4(0, (0, import_common7.Optional)()),
2740
3103
  _ts_param4(1, (0, import_common7.Optional)()),
2741
- _ts_param4(1, (0, import_common7.Inject)(import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL)),
3104
+ _ts_param4(1, (0, import_common7.Inject)(import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL)),
2742
3105
  _ts_metadata7("design:type", Function),
2743
3106
  _ts_metadata7("design:paramtypes", [
2744
3107
  typeof import_core4.ModuleRef === "undefined" ? Object : import_core4.ModuleRef,
@@ -2786,10 +3149,10 @@ function validateRetention(retention) {
2786
3149
  if (policy.maxAge == null && policy.maxCount == null) {
2787
3150
  throw new Error("durable retention: each policy must set maxAge and/or maxCount");
2788
3151
  }
2789
- if (policy.maxAge != null) (0, import_nestjs_durable_core14.parseDuration)(policy.maxAge);
3152
+ if (policy.maxAge != null) (0, import_nestjs_durable_core15.parseDuration)(policy.maxAge);
2790
3153
  for (const status of policy.statuses) {
2791
- if (!import_nestjs_durable_core14.TERMINAL_RUN_STATUSES.includes(status)) {
2792
- throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core14.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
3154
+ if (!import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.includes(status)) {
3155
+ throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
2793
3156
  }
2794
3157
  const key = `${scopeKey}|${status}`;
2795
3158
  if (seen.has(key)) {
@@ -2843,7 +3206,7 @@ var RetentionPoller = class {
2843
3206
  return;
2844
3207
  }
2845
3208
  void this.sweep();
2846
- const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core14.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
3209
+ const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core15.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
2847
3210
  if (intervalMs > 0) {
2848
3211
  this.timer = setInterval(() => void this.sweep(), intervalMs);
2849
3212
  this.timer.unref?.();
@@ -2907,8 +3270,8 @@ var RetentionPoller = class {
2907
3270
  };
2908
3271
  RetentionPoller = _ts_decorate8([
2909
3272
  (0, import_common8.Injectable)(),
2910
- _ts_param5(0, (0, import_common8.Inject)(import_nestjs_durable_core14.STATE_STORE_CANONICAL)),
2911
- _ts_param5(1, (0, import_common8.Inject)(import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL)),
3273
+ _ts_param5(0, (0, import_common8.Inject)(import_nestjs_durable_core15.STATE_STORE_CANONICAL)),
3274
+ _ts_param5(1, (0, import_common8.Inject)(import_nestjs_durable_core15.DURABLE_OPTIONS_CANONICAL)),
2912
3275
  _ts_param5(2, (0, import_common8.Optional)()),
2913
3276
  _ts_metadata8("design:type", Function),
2914
3277
  _ts_metadata8("design:paramtypes", [
@@ -2919,7 +3282,7 @@ RetentionPoller = _ts_decorate8([
2919
3282
  ], RetentionPoller);
2920
3283
 
2921
3284
  // src/store-run-gateway.ts
2922
- var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
3285
+ var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
2923
3286
  var import_common9 = require("@nestjs/common");
2924
3287
  function _ts_decorate9(decorators, target, key, desc) {
2925
3288
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2962,14 +3325,14 @@ function detailExtras(links) {
2962
3325
  }
2963
3326
  __name(detailExtras, "detailExtras");
2964
3327
  function withoutRegistry(query) {
2965
- if (query.workflow === import_nestjs_durable_core15.LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(import_nestjs_durable_core15.LIFECYCLE_REGISTRY_WORKFLOW)) {
3328
+ if (query.workflow === import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW)) {
2966
3329
  return query;
2967
3330
  }
2968
3331
  return {
2969
3332
  ...query,
2970
3333
  excludeWorkflows: [
2971
3334
  ...query.excludeWorkflows ?? [],
2972
- import_nestjs_durable_core15.LIFECYCLE_REGISTRY_WORKFLOW
3335
+ import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW
2973
3336
  ]
2974
3337
  };
2975
3338
  }
@@ -3020,10 +3383,10 @@ var StoreRunGateway = class {
3020
3383
  ...links
3021
3384
  };
3022
3385
  }
3023
- if ((0, import_nestjs_durable_core15.aggregatesCheckpoints)(this.store)) {
3386
+ if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
3024
3387
  const stats = await this.store.checkpointStats(runId);
3025
- const etag = (0, import_nestjs_durable_core15.extendEtag)((0, import_nestjs_durable_core15.runDetailEtag)(run, stats, over), detailExtras(links));
3026
- if ((0, import_nestjs_durable_core15.etagMatches)(options?.ifNoneMatch, etag)) {
3388
+ const etag = (0, import_nestjs_durable_core16.extendEtag)((0, import_nestjs_durable_core16.runDetailEtag)(run, stats, over), detailExtras(links));
3389
+ if ((0, import_nestjs_durable_core16.etagMatches)(options?.ifNoneMatch, etag)) {
3027
3390
  return {
3028
3391
  run,
3029
3392
  timeline: [],
@@ -3034,18 +3397,18 @@ var StoreRunGateway = class {
3034
3397
  }
3035
3398
  return {
3036
3399
  run,
3037
- ...await (0, import_nestjs_durable_core15.summarizeRunFromStore)(this.store, runId, over, stats),
3400
+ ...await (0, import_nestjs_durable_core16.summarizeRunFromStore)(this.store, runId, over, stats),
3038
3401
  etag,
3039
3402
  ...links
3040
3403
  };
3041
3404
  }
3042
3405
  const full = await this.store.listCheckpoints(runId);
3043
- const { timeline, fans } = (0, import_nestjs_durable_core15.summarizeTimeline)(full, over);
3044
- const ids = (0, import_nestjs_durable_core15.childIdsOf)(full);
3406
+ const { timeline, fans } = (0, import_nestjs_durable_core16.summarizeTimeline)(full, over);
3407
+ const ids = (0, import_nestjs_durable_core16.childIdsOf)(full);
3045
3408
  return {
3046
3409
  run,
3047
3410
  timeline,
3048
- children: ids.slice(0, import_nestjs_durable_core15.SUMMARY_CHILD_LIMIT),
3411
+ children: ids.slice(0, import_nestjs_durable_core16.SUMMARY_CHILD_LIMIT),
3049
3412
  fans,
3050
3413
  childCount: ids.length,
3051
3414
  ...links
@@ -3060,24 +3423,24 @@ var StoreRunGateway = class {
3060
3423
  */
3061
3424
  async lifecycleLinks(run) {
3062
3425
  const triggered = await this.engine.triggeredRuns(run);
3063
- const source = (0, import_nestjs_durable_core15.lifecycleSourceOf)(run);
3064
- const kind = (0, import_nestjs_durable_core15.lifecycleKindOf)(run.status);
3426
+ const source = (0, import_nestjs_durable_core16.lifecycleSourceOf)(run);
3427
+ const kind = (0, import_nestjs_durable_core16.lifecycleKindOf)(run.status);
3065
3428
  const subscribers = kind ? await this.engine.lifecycleSubscribers(run.workflow, kind, run.namespace || "default") : [];
3066
3429
  const workflowLifecycle = await this.engine.workflowLifecycle(run.workflow);
3067
3430
  const linked = workflowLifecycle.startsOnSettle.length > 0 || workflowLifecycle.startedBy.length > 0;
3068
- const deliveries = kind ? (0, import_nestjs_durable_core15.lifecycleDeliveriesOf)(run, {
3431
+ const deliveries = kind ? (0, import_nestjs_durable_core16.lifecycleDeliveriesOf)(run, {
3069
3432
  subscribers,
3070
3433
  live: new Set(subscribers),
3071
3434
  coalesced: this.engine.coalescedSubscribers(run)
3072
3435
  }) : [];
3073
3436
  const [own, onIt] = await Promise.all([
3074
- run.status === "suspended" ? (0, import_nestjs_durable_core15.listSignalWaitersOfRuns)(this.store, [
3437
+ run.status === "suspended" ? (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, [
3075
3438
  run.id
3076
3439
  ]) : [],
3077
- run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0, import_nestjs_durable_core15.runWaitPrefix)(run.id))
3440
+ run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0, import_nestjs_durable_core16.runWaitPrefix)(run.id))
3078
3441
  ]);
3079
3442
  const waitsFor = own.flatMap((w) => {
3080
- const target = (0, import_nestjs_durable_core15.runWaitTargetOf)(w);
3443
+ const target = (0, import_nestjs_durable_core16.runWaitTargetOf)(w);
3081
3444
  return target !== void 0 ? [
3082
3445
  {
3083
3446
  runId: target,
@@ -3085,14 +3448,14 @@ var StoreRunGateway = class {
3085
3448
  }
3086
3449
  ] : [];
3087
3450
  });
3088
- const awaitedBy = onIt.filter((w) => (0, import_nestjs_durable_core15.runWaitTargetOf)(w) === run.id).map((w) => ({
3451
+ const awaitedBy = onIt.filter((w) => (0, import_nestjs_durable_core16.runWaitTargetOf)(w) === run.id).map((w) => ({
3089
3452
  runId: w.runId,
3090
3453
  seq: w.seq
3091
3454
  }));
3092
3455
  const started = deliveries.flatMap((d) => d.state === "started" && d.runId !== void 0 ? [
3093
3456
  d.runId
3094
3457
  ] : []);
3095
- const { runs } = await (0, import_nestjs_durable_core15.readRunsByIds)(this.store, [
3458
+ const { runs } = await (0, import_nestjs_durable_core16.readRunsByIds)(this.store, [
3096
3459
  ...source ? [
3097
3460
  source.runId
3098
3461
  ] : [],
@@ -3109,7 +3472,7 @@ var StoreRunGateway = class {
3109
3472
  } : link;
3110
3473
  }, "withRun");
3111
3474
  const sourceRun = source ? runs.get(source.runId) : void 0;
3112
- const traceId = (0, import_nestjs_durable_core15.traceIdOfTraceparent)((0, import_nestjs_durable_core15.lifecycleTraceparentOf)(sourceRun?.tags));
3475
+ const traceId = (0, import_nestjs_durable_core16.traceIdOfTraceparent)((0, import_nestjs_durable_core16.lifecycleTraceparentOf)(sourceRun?.tags));
3113
3476
  return {
3114
3477
  ...triggered.length > 0 ? {
3115
3478
  triggered
@@ -3154,12 +3517,12 @@ var StoreRunGateway = class {
3154
3517
  }
3155
3518
  async getFanMembers(runId, group, query) {
3156
3519
  if (!await this.visibleRun(runId)) return null;
3157
- if ((0, import_nestjs_durable_core15.aggregatesCheckpoints)(this.store)) {
3520
+ if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
3158
3521
  const stats = await this.store.checkpointStats(runId, {
3159
3522
  group
3160
3523
  });
3161
- const etag = (0, import_nestjs_durable_core15.fanPageEtag)(group, stats, query);
3162
- if ((0, import_nestjs_durable_core15.etagMatches)(query.ifNoneMatch, etag)) {
3524
+ const etag = (0, import_nestjs_durable_core16.fanPageEtag)(group, stats, query);
3525
+ if ((0, import_nestjs_durable_core16.etagMatches)(query.ifNoneMatch, etag)) {
3163
3526
  return {
3164
3527
  items: [],
3165
3528
  total: 0,
@@ -3168,17 +3531,17 @@ var StoreRunGateway = class {
3168
3531
  };
3169
3532
  }
3170
3533
  return {
3171
- ...await (0, import_nestjs_durable_core15.pageFanFromStore)(this.store, runId, group, query, stats),
3534
+ ...await (0, import_nestjs_durable_core16.pageFanFromStore)(this.store, runId, group, query, stats),
3172
3535
  etag
3173
3536
  };
3174
3537
  }
3175
- return (0, import_nestjs_durable_core15.pageFan)(await this.store.listCheckpoints(runId), group, query);
3538
+ return (0, import_nestjs_durable_core16.pageFan)(await this.store.listCheckpoints(runId), group, query);
3176
3539
  }
3177
3540
  async listRuns(query) {
3178
3541
  const runs = await this.store.listRuns(this.scoped(withoutRegistry(query)));
3179
- const waiterByRun = (0, import_nestjs_durable_core15.indexWaitersByRun)(await (0, import_nestjs_durable_core15.listSignalWaitersOfRuns)(this.store, runs.filter((run) => run.status === "suspended").map((run) => run.id)));
3542
+ const waiterByRun = (0, import_nestjs_durable_core16.indexWaitersByRun)(await (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, runs.filter((run) => run.status === "suspended").map((run) => run.id)));
3180
3543
  return runs.map((run) => {
3181
- const waiting = (0, import_nestjs_durable_core15.resolveRunWaiting)(run, waiterByRun);
3544
+ const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
3182
3545
  return waiting ? {
3183
3546
  ...run,
3184
3547
  waiting
@@ -3195,7 +3558,7 @@ var StoreRunGateway = class {
3195
3558
  const scoped = this.scoped(withoutRegistry(query));
3196
3559
  if (this.store.runFacets) return this.store.runFacets(scoped);
3197
3560
  const runs = await this.store.listRuns(scoped);
3198
- return (0, import_nestjs_durable_core15.mergeRunFacetRows)(runs.map((r) => ({
3561
+ return (0, import_nestjs_durable_core16.mergeRunFacetRows)(runs.map((r) => ({
3199
3562
  status: r.status,
3200
3563
  origin: r.origin,
3201
3564
  count: 1
@@ -3230,13 +3593,13 @@ var StoreRunGateway = class {
3230
3593
  "suspended"
3231
3594
  ]
3232
3595
  })),
3233
- (0, import_nestjs_durable_core15.listSignalWaitersOfRuns)(this.store, runIds)
3596
+ (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, runIds)
3234
3597
  ]);
3235
- const waiterByRun = (0, import_nestjs_durable_core15.indexWaitersByRun)(waiters);
3598
+ const waiterByRun = (0, import_nestjs_durable_core16.indexWaitersByRun)(waiters);
3236
3599
  const result = {};
3237
3600
  for (const run of suspended) {
3238
3601
  if (!idSet.has(run.id)) continue;
3239
- const waiting = (0, import_nestjs_durable_core15.resolveRunWaiting)(run, waiterByRun);
3602
+ const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
3240
3603
  if (waiting) result[run.id] = waiting;
3241
3604
  }
3242
3605
  return result;
@@ -3279,8 +3642,14 @@ var StoreRunGateway = class {
3279
3642
  if (action === "trigger") return this.engine.schedules.trigger(id);
3280
3643
  return Promise.reject(new Error(`unknown schedule action ${String(action)}`));
3281
3644
  }
3282
- signal(token, payload) {
3283
- return this.engine.signal(token, payload);
3645
+ signal(token, payload, opts) {
3646
+ return this.engine.signal(token, payload, opts);
3647
+ }
3648
+ signalWithStartForTenant(start, namespace, clientTenant, signal) {
3649
+ return this.engine.signalWithStartForTenant(start, namespace, clientTenant, signal);
3650
+ }
3651
+ publishEventForTenant(name, payload, namespace) {
3652
+ return this.engine.publishEventForTenant(name, payload, namespace);
3284
3653
  }
3285
3654
  async signalWaiter(token) {
3286
3655
  const waiter = (await this.store.listSignalWaiters(token)).find((w) => w.token === token);
@@ -3328,11 +3697,11 @@ var StoreRunGateway = class {
3328
3697
  };
3329
3698
  StoreRunGateway = _ts_decorate9([
3330
3699
  (0, import_common9.Injectable)(),
3331
- _ts_param6(0, (0, import_common9.Inject)(import_nestjs_durable_core15.STATE_STORE_CANONICAL)),
3700
+ _ts_param6(0, (0, import_common9.Inject)(import_nestjs_durable_core16.STATE_STORE_CANONICAL)),
3332
3701
  _ts_metadata9("design:type", Function),
3333
3702
  _ts_metadata9("design:paramtypes", [
3334
3703
  typeof StateStore === "undefined" ? Object : StateStore,
3335
- typeof import_nestjs_durable_core15.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core15.WorkflowEngine
3704
+ typeof import_nestjs_durable_core16.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core16.WorkflowEngine
3336
3705
  ])
3337
3706
  ], StoreRunGateway);
3338
3707
 
@@ -3379,7 +3748,7 @@ var TenantEventRepublisher = class {
3379
3748
 
3380
3749
  // src/timer-poller.ts
3381
3750
  var durableCore = __toESM(require("@dudousxd/nestjs-durable-core"), 1);
3382
- var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
3751
+ var import_nestjs_durable_core17 = require("@dudousxd/nestjs-durable-core");
3383
3752
  var import_common10 = require("@nestjs/common");
3384
3753
  function _ts_decorate10(decorators, target, key, desc) {
3385
3754
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3438,7 +3807,7 @@ var TimerPoller = class {
3438
3807
  this.leases = leases;
3439
3808
  }
3440
3809
  async onApplicationBootstrap() {
3441
- for (const s of this.options.schedules ?? []) (0, import_nestjs_durable_core16.workflowName)(s.workflow);
3810
+ for (const s of this.options.schedules ?? []) (0, import_nestjs_durable_core17.workflowName)(s.workflow);
3442
3811
  if (!isDrivingOperator(this.options)) return;
3443
3812
  this.engine.consumeRuns?.();
3444
3813
  this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
@@ -3635,7 +4004,7 @@ var TimerPoller = class {
3635
4004
  }));
3636
4005
  const schedules = this.options.schedules;
3637
4006
  if (schedules && schedules.length > 0) {
3638
- note(await this.sweep("schedules", () => (0, import_nestjs_durable_core16.runSchedules)(this.engine, schedules, Date.now())));
4007
+ note(await this.sweep("schedules", () => (0, import_nestjs_durable_core17.runSchedules)(this.engine, schedules, Date.now())));
3639
4008
  }
3640
4009
  const announced = this.announcedSchedules();
3641
4010
  if (announced) {
@@ -3656,7 +4025,7 @@ var TimerPoller = class {
3656
4025
  note(await this.sweep("persistedSchedules", () => this.engine.schedules.tick()));
3657
4026
  } else if (announced) {
3658
4027
  note(await this.sweep("announcedScheduleFires", () => this.engine.schedules.tick(Date.now(), {
3659
- tag: import_nestjs_durable_core16.ANNOUNCED_SCHEDULE_TAG
4028
+ tag: import_nestjs_durable_core17.ANNOUNCED_SCHEDULE_TAG
3660
4029
  })));
3661
4030
  }
3662
4031
  return worked;
@@ -3673,36 +4042,20 @@ var TimerPoller = class {
3673
4042
  };
3674
4043
  TimerPoller = _ts_decorate10([
3675
4044
  (0, import_common10.Injectable)(),
3676
- _ts_param7(1, (0, import_common10.Inject)(import_nestjs_durable_core16.DURABLE_OPTIONS_CANONICAL)),
4045
+ _ts_param7(1, (0, import_common10.Inject)(import_nestjs_durable_core17.DURABLE_OPTIONS_CANONICAL)),
3677
4046
  _ts_param7(2, (0, import_common10.Optional)()),
3678
4047
  _ts_metadata10("design:type", Function),
3679
4048
  _ts_metadata10("design:paramtypes", [
3680
- typeof import_nestjs_durable_core16.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core16.WorkflowEngine,
4049
+ typeof import_nestjs_durable_core17.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core17.WorkflowEngine,
3681
4050
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
3682
4051
  typeof SweepLeases === "undefined" ? Object : SweepLeases
3683
4052
  ])
3684
4053
  ], TimerPoller);
3685
4054
 
3686
4055
  // src/workflow.registrar.ts
3687
- var import_nestjs_durable_core17 = require("@dudousxd/nestjs-durable-core");
4056
+ var import_nestjs_durable_core18 = require("@dudousxd/nestjs-durable-core");
3688
4057
  var import_common11 = require("@nestjs/common");
3689
4058
  var import_core5 = require("@nestjs/core");
3690
-
3691
- // src/step-interceptor.ts
3692
- var import_reflect_metadata3 = require("reflect-metadata");
3693
- var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
3694
- function StepInterceptor() {
3695
- return (target) => {
3696
- Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
3697
- };
3698
- }
3699
- __name(StepInterceptor, "StepInterceptor");
3700
- function isStepInterceptor(target) {
3701
- return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
3702
- }
3703
- __name(isStepInterceptor, "isStepInterceptor");
3704
-
3705
- // src/workflow.registrar.ts
3706
4059
  function _ts_decorate11(decorators, target, key, desc) {
3707
4060
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3708
4061
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -3825,11 +4178,11 @@ var WorkflowRegistrar = class {
3825
4178
  // so a turn dispatched under the wrong token would never be consumed. Absent → the inline fast
3826
4179
  // path (unchanged).
3827
4180
  ...this.inAppWorker ? {
3828
- group: (0, import_nestjs_durable_core17.tenantGroup)((0, import_nestjs_durable_core17.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
3829
- executor: new import_nestjs_durable_core17.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
4181
+ group: (0, import_nestjs_durable_core18.tenantGroup)((0, import_nestjs_durable_core18.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
4182
+ executor: new import_nestjs_durable_core18.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
3830
4183
  } : {}
3831
4184
  });
3832
- (0, import_nestjs_durable_core17.bindWorkflowClass)(workflowCtor, {
4185
+ (0, import_nestjs_durable_core18.bindWorkflowClass)(workflowCtor, {
3833
4186
  start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
3834
4187
  waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
3835
4188
  });
@@ -3844,7 +4197,7 @@ var WorkflowRegistrar = class {
3844
4197
  });
3845
4198
  deadLetterByWorkflow.set(meta.name, dlqName);
3846
4199
  } else if (meta.deadLetterWorkflow) {
3847
- deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core17.workflowName)(meta.deadLetterWorkflow));
4200
+ deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core18.workflowName)(meta.deadLetterWorkflow));
3848
4201
  }
3849
4202
  });
3850
4203
  this.reportUnattributed(unattributed);
@@ -3892,39 +4245,47 @@ var WorkflowRegistrar = class {
3892
4245
  * a `dlq:<runId>` id, so re-recovery never double-dispatches.
3893
4246
  */
3894
4247
  installDeadLetterRouting(byWorkflow) {
3895
- const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core17.workflowName)(this.options.deadLetterWorkflow) : void 0;
4248
+ const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core18.workflowName)(this.options.deadLetterWorkflow) : void 0;
3896
4249
  if (byWorkflow.size === 0 && !fallback) return;
3897
4250
  this.engine.onDead((run) => {
3898
- const target = byWorkflow.get(run.workflow) ?? fallback;
3899
- if (!target) return;
3900
- void this.engine.start(
3901
- target,
3902
- {
3903
- deadRunId: run.id,
3904
- workflow: run.workflow,
3905
- input: run.input,
3906
- error: run.error
3907
- },
3908
- `dlq:${run.id}`,
3909
- // Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
3910
- // that tenant's worker group (`target@<tenant>`), not the bare group.
3911
- {
3912
- namespace: run.namespace
3913
- }
3914
- ).catch(() => void 0);
4251
+ void this.routeDead(run, byWorkflow, fallback).catch(() => void 0);
3915
4252
  });
3916
4253
  }
4254
+ /** {@link installDeadLetterRouting}'s routing of one dead run. */
4255
+ async routeDead(run, byWorkflow, fallback) {
4256
+ let target = byWorkflow.get(run.workflow);
4257
+ if (!target && fallback) {
4258
+ if (await this.engine.announcedDeadLetter?.(run).catch(() => void 0)) return;
4259
+ target = fallback;
4260
+ }
4261
+ if (!target) return;
4262
+ await this.engine.start(
4263
+ target,
4264
+ {
4265
+ deadRunId: run.id,
4266
+ workflow: run.workflow,
4267
+ input: run.input,
4268
+ error: run.error
4269
+ },
4270
+ `dlq:${run.id}`,
4271
+ // Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
4272
+ // that tenant's worker group (`target@<tenant>`), not the bare group.
4273
+ {
4274
+ namespace: run.namespace
4275
+ }
4276
+ ).catch(() => void 0);
4277
+ }
3917
4278
  };
3918
4279
  WorkflowRegistrar = _ts_decorate11([
3919
4280
  (0, import_common11.Injectable)(),
3920
- _ts_param8(3, (0, import_common11.Inject)(import_nestjs_durable_core17.STATE_STORE_CANONICAL)),
3921
- _ts_param8(4, (0, import_common11.Inject)(import_nestjs_durable_core17.DURABLE_OPTIONS_CANONICAL)),
4281
+ _ts_param8(3, (0, import_common11.Inject)(import_nestjs_durable_core18.STATE_STORE_CANONICAL)),
4282
+ _ts_param8(4, (0, import_common11.Inject)(import_nestjs_durable_core18.DURABLE_OPTIONS_CANONICAL)),
3922
4283
  _ts_param8(5, (0, import_common11.Inject)(IN_APP_WORKER_BINDING)),
3923
4284
  _ts_metadata11("design:type", Function),
3924
4285
  _ts_metadata11("design:paramtypes", [
3925
4286
  typeof import_core5.DiscoveryService === "undefined" ? Object : import_core5.DiscoveryService,
3926
4287
  typeof import_core5.MetadataScanner === "undefined" ? Object : import_core5.MetadataScanner,
3927
- typeof import_nestjs_durable_core17.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core17.WorkflowEngine,
4288
+ typeof import_nestjs_durable_core18.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core18.WorkflowEngine,
3928
4289
  Object,
3929
4290
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
3930
4291
  Object
@@ -3933,7 +4294,7 @@ WorkflowRegistrar = _ts_decorate11([
3933
4294
 
3934
4295
  // src/workflow.service.ts
3935
4296
  var import_node_crypto = require("crypto");
3936
- var import_nestjs_durable_core18 = require("@dudousxd/nestjs-durable-core");
4297
+ var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
3937
4298
  var import_common12 = require("@nestjs/common");
3938
4299
  function _ts_decorate12(decorators, target, key, desc) {
3939
4300
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -4024,7 +4385,7 @@ WorkflowService = _ts_decorate12([
4024
4385
  (0, import_common12.Injectable)(),
4025
4386
  _ts_metadata12("design:type", Function),
4026
4387
  _ts_metadata12("design:paramtypes", [
4027
- typeof import_nestjs_durable_core18.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core18.WorkflowEngine
4388
+ typeof import_nestjs_durable_core19.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core19.WorkflowEngine
4028
4389
  ])
4029
4390
  ], WorkflowService);
4030
4391
 
@@ -4253,15 +4614,15 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
4253
4614
  };
4254
4615
  RunGatewayBootstrap = _ts_decorate13([
4255
4616
  (0, import_common13.Injectable)(),
4256
- _ts_param9(1, (0, import_common13.Inject)(import_nestjs_durable_core19.TRANSPORT_CANONICAL)),
4257
- _ts_param9(3, (0, import_common13.Inject)(import_nestjs_durable_core19.STATE_STORE_CANONICAL)),
4258
- _ts_param9(4, (0, import_common13.Inject)(import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL)),
4617
+ _ts_param9(1, (0, import_common13.Inject)(import_nestjs_durable_core20.TRANSPORT_CANONICAL)),
4618
+ _ts_param9(3, (0, import_common13.Inject)(import_nestjs_durable_core20.STATE_STORE_CANONICAL)),
4619
+ _ts_param9(4, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
4259
4620
  _ts_param9(5, (0, import_common13.Inject)(TENANT_AUTH)),
4260
4621
  _ts_metadata13("design:type", Function),
4261
4622
  _ts_metadata13("design:paramtypes", [
4262
- typeof import_nestjs_durable_core19.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core19.WorkflowEngine,
4623
+ typeof import_nestjs_durable_core20.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core20.WorkflowEngine,
4263
4624
  Object,
4264
- typeof import_nestjs_durable_core19.RunGateway === "undefined" ? Object : import_nestjs_durable_core19.RunGateway,
4625
+ typeof import_nestjs_durable_core20.RunGateway === "undefined" ? Object : import_nestjs_durable_core20.RunGateway,
4265
4626
  Object,
4266
4627
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
4267
4628
  typeof ResolvedTenantAuth === "undefined" ? Object : ResolvedTenantAuth
@@ -4284,7 +4645,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
4284
4645
  if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
4285
4646
  const runtime = await resolveContextRuntime();
4286
4647
  if (!canRestoreTenant(runtime)) return;
4287
- this.unregister = (0, import_nestjs_durable_core19.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
4648
+ this.unregister = (0, import_nestjs_durable_core20.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
4288
4649
  }
4289
4650
  onModuleDestroy() {
4290
4651
  this.unregister?.();
@@ -4292,7 +4653,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
4292
4653
  };
4293
4654
  DurableTenancyBridge = _ts_decorate13([
4294
4655
  (0, import_common13.Injectable)(),
4295
- _ts_param9(0, (0, import_common13.Inject)(import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL)),
4656
+ _ts_param9(0, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
4296
4657
  _ts_metadata13("design:type", Function),
4297
4658
  _ts_metadata13("design:paramtypes", [
4298
4659
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
@@ -4304,17 +4665,17 @@ var DurableModule = class _DurableModule {
4304
4665
  __name(this, "DurableModule");
4305
4666
  }
4306
4667
  static forRoot(options) {
4307
- (0, import_nestjs_durable_core19.sealDurableCopies)();
4668
+ (0, import_nestjs_durable_core20.sealDurableCopies)();
4308
4669
  _DurableModule.assertValid(options);
4309
4670
  return _DurableModule.build({
4310
- provide: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4671
+ provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4311
4672
  useValue: resolveTopology(options)
4312
4673
  });
4313
4674
  }
4314
4675
  static forRootAsync(options) {
4315
- (0, import_nestjs_durable_core19.sealDurableCopies)();
4676
+ (0, import_nestjs_durable_core20.sealDurableCopies)();
4316
4677
  return _DurableModule.build({
4317
- provide: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4678
+ provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4318
4679
  useFactory: /* @__PURE__ */ __name(async (...args) => {
4319
4680
  const resolved = await options.useFactory(...args);
4320
4681
  _DurableModule.assertValid(resolved);
@@ -4337,21 +4698,21 @@ var DurableModule = class _DurableModule {
4337
4698
  providers: [
4338
4699
  optionsProvider,
4339
4700
  {
4340
- provide: import_nestjs_durable_core19.STATE_STORE_CANONICAL,
4701
+ provide: import_nestjs_durable_core20.STATE_STORE_CANONICAL,
4341
4702
  useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
4342
4703
  inject: [
4343
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
4704
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
4344
4705
  ]
4345
4706
  },
4346
4707
  {
4347
- provide: import_nestjs_durable_core19.TRANSPORT_CANONICAL,
4708
+ provide: import_nestjs_durable_core20.TRANSPORT_CANONICAL,
4348
4709
  // With a POOL (`transports`) and no singular `transport`, the canonical transport is the
4349
4710
  // pool's PRIMARY — the same one the engine dispatches on first. Leaving it null starved
4350
4711
  // the step registrar / in-app worker of a transport, so a pool-configured operator
4351
4712
  // registered NO step handlers and its own steps parked in `wait` with no consumer.
4352
4713
  useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
4353
4714
  inject: [
4354
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
4715
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
4355
4716
  ]
4356
4717
  },
4357
4718
  {
@@ -4361,36 +4722,53 @@ var DurableModule = class _DurableModule {
4361
4722
  tenantToken: resolveTenantTokenSource(options.tenantToken, moduleRef)
4362
4723
  }), "useFactory"),
4363
4724
  inject: [
4364
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4725
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4365
4726
  import_core6.ModuleRef
4366
4727
  ]
4367
4728
  },
4368
4729
  // Deprecated tokens that published releases still import resolve to the same instances:
4369
4730
  {
4370
- provide: import_nestjs_durable_core19.STATE_STORE,
4371
- useExisting: import_nestjs_durable_core19.STATE_STORE_CANONICAL
4731
+ provide: import_nestjs_durable_core20.STATE_STORE,
4732
+ useExisting: import_nestjs_durable_core20.STATE_STORE_CANONICAL
4372
4733
  },
4373
4734
  {
4374
- provide: import_nestjs_durable_core19.TRANSPORT,
4375
- useExisting: import_nestjs_durable_core19.TRANSPORT_CANONICAL
4735
+ provide: import_nestjs_durable_core20.TRANSPORT,
4736
+ useExisting: import_nestjs_durable_core20.TRANSPORT_CANONICAL
4376
4737
  },
4377
4738
  {
4378
- provide: import_nestjs_durable_core19.DURABLE_OPTIONS,
4379
- useExisting: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
4739
+ provide: import_nestjs_durable_core20.DURABLE_OPTIONS,
4740
+ useExisting: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
4380
4741
  },
4381
4742
  {
4382
4743
  // Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
4383
4744
  // `DurableStartClient` facade for a thin worker (no `store`) — either way, `WorkflowService`
4384
4745
  // and app code call `engine.start(...)` unchanged.
4385
- provide: import_nestjs_durable_core19.WorkflowEngine,
4746
+ provide: import_nestjs_durable_core20.WorkflowEngine,
4386
4747
  useFactory: /* @__PURE__ */ __name(async (options, store, transport, moduleRef, auth) => {
4387
4748
  if (options.store === void 0) {
4388
- return new DurableStartClient({
4389
- ...options,
4390
- ...auth.tenantToken !== void 0 ? {
4391
- tenantToken: auth.tenantToken
4392
- } : {}
4393
- }, void 0, resolveAccessor(moduleRef));
4749
+ return new DurableStartClient(
4750
+ {
4751
+ ...options,
4752
+ ...auth.tenantToken !== void 0 ? {
4753
+ tenantToken: auth.tenantToken
4754
+ } : {}
4755
+ },
4756
+ void 0,
4757
+ resolveAccessor(moduleRef),
4758
+ // `signal`/`signalWithStart`/`publishEvent` go to the control plane as run requests,
4759
+ // over the one `ProxyRunGateway` bound under `RunGateway` (it owns the reply
4760
+ // subscription). Resolved lazily: that gateway is built after this facade.
4761
+ () => {
4762
+ try {
4763
+ const gateway = moduleRef.get(import_nestjs_durable_core20.RunGateway, {
4764
+ strict: false
4765
+ });
4766
+ return gateway instanceof ProxyRunGateway ? gateway : void 0;
4767
+ } catch {
4768
+ return void 0;
4769
+ }
4770
+ }
4771
+ );
4394
4772
  }
4395
4773
  if (!store) {
4396
4774
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
@@ -4409,7 +4787,7 @@ var DurableModule = class _DurableModule {
4409
4787
  if (t) deferTransportConsumers(t);
4410
4788
  }
4411
4789
  }
4412
- const engine = new import_nestjs_durable_core19.WorkflowEngine({
4790
+ const engine = new import_nestjs_durable_core20.WorkflowEngine({
4413
4791
  store,
4414
4792
  transport: transport ?? void 0,
4415
4793
  transports: options.transports,
@@ -4458,9 +4836,9 @@ var DurableModule = class _DurableModule {
4458
4836
  return engine;
4459
4837
  }, "useFactory"),
4460
4838
  inject: [
4461
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4462
- import_nestjs_durable_core19.STATE_STORE_CANONICAL,
4463
- import_nestjs_durable_core19.TRANSPORT_CANONICAL,
4839
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4840
+ import_nestjs_durable_core20.STATE_STORE_CANONICAL,
4841
+ import_nestjs_durable_core20.TRANSPORT_CANONICAL,
4464
4842
  import_core6.ModuleRef,
4465
4843
  TENANT_AUTH
4466
4844
  ]
@@ -4476,7 +4854,7 @@ var DurableModule = class _DurableModule {
4476
4854
  // or (for a thin worker, no `store`) a `ProxyRunGateway` over `transport` when given, else a
4477
4855
  // gateway whose every method rejects with a clear tenant error.
4478
4856
  {
4479
- provide: import_nestjs_durable_core19.RunGateway,
4857
+ provide: import_nestjs_durable_core20.RunGateway,
4480
4858
  useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
4481
4859
  if (options.store !== void 0) {
4482
4860
  if (!store) {
@@ -4487,9 +4865,9 @@ var DurableModule = class _DurableModule {
4487
4865
  return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, auth.tenantToken, options.tenancy === false ? void 0 : () => tenantFilterNow(options.tenancy, resolveAccessor(moduleRef))) : unavailableRunGateway();
4488
4866
  }, "useFactory"),
4489
4867
  inject: [
4490
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4491
- import_nestjs_durable_core19.STATE_STORE_CANONICAL,
4492
- import_nestjs_durable_core19.WorkflowEngine,
4868
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4869
+ import_nestjs_durable_core20.STATE_STORE_CANONICAL,
4870
+ import_nestjs_durable_core20.WorkflowEngine,
4493
4871
  TENANT_AUTH,
4494
4872
  import_core6.ModuleRef
4495
4873
  ]
@@ -4506,13 +4884,13 @@ var DurableModule = class _DurableModule {
4506
4884
  exports: [
4507
4885
  WorkflowService,
4508
4886
  EntityService,
4509
- import_nestjs_durable_core19.WorkflowEngine,
4510
- import_nestjs_durable_core19.STATE_STORE,
4511
- import_nestjs_durable_core19.STATE_STORE_CANONICAL,
4512
- import_nestjs_durable_core19.TRANSPORT,
4513
- import_nestjs_durable_core19.TRANSPORT_CANONICAL,
4514
- import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4515
- import_nestjs_durable_core19.RunGateway
4887
+ import_nestjs_durable_core20.WorkflowEngine,
4888
+ import_nestjs_durable_core20.STATE_STORE,
4889
+ import_nestjs_durable_core20.STATE_STORE_CANONICAL,
4890
+ import_nestjs_durable_core20.TRANSPORT,
4891
+ import_nestjs_durable_core20.TRANSPORT_CANONICAL,
4892
+ import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
4893
+ import_nestjs_durable_core20.RunGateway
4516
4894
  ]
4517
4895
  };
4518
4896
  }
@@ -4522,7 +4900,7 @@ DurableModule = _ts_decorate13([
4522
4900
  ], DurableModule);
4523
4901
 
4524
4902
  // src/federated-app-gateway.ts
4525
- var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4903
+ var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
4526
4904
  var FederatedAppGateway = class {
4527
4905
  static {
4528
4906
  __name(this, "FederatedAppGateway");
@@ -4537,7 +4915,7 @@ var FederatedAppGateway = class {
4537
4915
  tailing = false;
4538
4916
  constructor(options) {
4539
4917
  this.options = options;
4540
- this.reads = new StoreRunGateway(options.store, new import_nestjs_durable_core20.WorkflowEngine({
4918
+ this.reads = new StoreRunGateway(options.store, new import_nestjs_durable_core21.WorkflowEngine({
4541
4919
  store: options.store
4542
4920
  }));
4543
4921
  this.timeoutMs = options.timeoutMs ?? 1e4;
@@ -4782,7 +5160,7 @@ function federatedAppGateway(options) {
4782
5160
  __name(federatedAppGateway, "federatedAppGateway");
4783
5161
 
4784
5162
  // src/index.ts
4785
- var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
5163
+ var import_nestjs_durable_core22 = require("@dudousxd/nestjs-durable-core");
4786
5164
  // Annotate the CommonJS export names for ESM import in node:
4787
5165
  0 && (module.exports = {
4788
5166
  BAD_RUN_REQUEST,