@dudousxd/nestjs-durable 0.61.0 → 0.63.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,19 +38,20 @@ __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_core20.DuplicateDurableCopyError,
41
+ DuplicateDurableCopyError: () => import_nestjs_durable_core21.DuplicateDurableCopyError,
42
42
  DurableModule: () => DurableModule,
43
43
  DurableStartClient: () => DurableStartClient,
44
44
  ENTITY_METADATA: () => ENTITY_METADATA,
45
45
  ENTITY_ON_METADATA: () => ENTITY_ON_METADATA,
46
46
  Entity: () => Entity,
47
47
  EntityService: () => EntityService,
48
+ FederatedAppGateway: () => FederatedAppGateway,
48
49
  IN_APP_RUN_REDIS_WORKER: () => IN_APP_RUN_REDIS_WORKER,
49
50
  IN_APP_WORKER_BINDING: () => IN_APP_WORKER_BINDING,
50
51
  IN_APP_WORKER_RUNNERS: () => IN_APP_WORKER_RUNNERS,
51
52
  IN_APP_WORKER_RUNTIME: () => IN_APP_WORKER_RUNTIME,
52
53
  InAppWorkerBootstrap: () => InAppWorkerBootstrap,
53
- LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core20.LIFECYCLE_PENDING_TAG,
54
+ LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core21.LIFECYCLE_PENDING_TAG,
54
55
  ON_ERROR_METADATA: () => ON_ERROR_METADATA,
55
56
  ON_EVENT_BATCH_METADATA: () => ON_EVENT_BATCH_METADATA,
56
57
  ON_EVENT_METADATA: () => ON_EVENT_METADATA,
@@ -62,7 +63,7 @@ __export(src_exports, {
62
63
  ProxyRunGateway: () => ProxyRunGateway,
63
64
  RUN_GATEWAY: () => RUN_GATEWAY,
64
65
  RUN_REDIS_WORKER: () => RUN_REDIS_WORKER,
65
- RunGateway: () => import_nestjs_durable_core20.RunGateway,
66
+ RunGateway: () => import_nestjs_durable_core21.RunGateway,
66
67
  RunGatewayError: () => RunGatewayError,
67
68
  RunRequestResponder: () => RunRequestResponder,
68
69
  STEP_INTERCEPTOR_METADATA: () => STEP_INTERCEPTOR_METADATA,
@@ -77,34 +78,35 @@ __export(src_exports, {
77
78
  UNSUPPORTED_RUN_REQUEST: () => UNSUPPORTED_RUN_REQUEST,
78
79
  WORKFLOW_METADATA: () => WORKFLOW_METADATA,
79
80
  Workflow: () => Workflow,
80
- WorkflowEngine: () => import_nestjs_durable_core20.WorkflowEngine,
81
+ WorkflowEngine: () => import_nestjs_durable_core21.WorkflowEngine,
81
82
  WorkflowService: () => WorkflowService,
82
83
  attributesOf: () => attributesOf,
83
84
  entityConfigFor: () => entityConfigFor,
84
85
  eventBatchOf: () => eventBatchOf,
86
+ federatedAppGateway: () => federatedAppGateway,
85
87
  getDurableStepMeta: () => getDurableStepMeta,
86
88
  getEntityMeta: () => getEntityMeta,
87
89
  getOnEvents: () => getOnEvents,
88
90
  getWorkflowMeta: () => getWorkflowMeta,
89
- hmacTenantVerifier: () => import_nestjs_durable_core20.hmacTenantVerifier,
91
+ hmacTenantVerifier: () => import_nestjs_durable_core21.hmacTenantVerifier,
90
92
  inAppWorkerProviders: () => inAppWorkerProviders,
91
93
  isDeadLetterHandler: () => isDeadLetterHandler,
92
94
  isDrivingOperator: () => isDrivingOperator,
93
95
  isOperatorRole: () => isOperatorRole,
94
96
  isStepInterceptor: () => isStepInterceptor,
95
- lifecycleRunId: () => import_nestjs_durable_core20.lifecycleRunId,
96
- lifecycleSourceOf: () => import_nestjs_durable_core20.lifecycleSourceOf,
97
+ lifecycleRunId: () => import_nestjs_durable_core21.lifecycleRunId,
98
+ lifecycleSourceOf: () => import_nestjs_durable_core21.lifecycleSourceOf,
97
99
  onErrorCodesOf: () => onErrorCodesOf,
98
- prevCronFireMs: () => import_nestjs_durable_core20.prevCronFireMs,
99
- readSearchAttributes: () => import_nestjs_durable_core20.readSearchAttributes,
100
- runCompletedEvent: () => import_nestjs_durable_core20.runCompletedEvent,
101
- runFailedEvent: () => import_nestjs_durable_core20.runFailedEvent,
102
- runSchedules: () => import_nestjs_durable_core20.runSchedules,
103
- scheduleRunIdAt: () => import_nestjs_durable_core20.scheduleRunIdAt,
104
- scheduledRunId: () => import_nestjs_durable_core20.scheduledRunId,
105
- signTenantToken: () => import_nestjs_durable_core20.signTenantToken,
100
+ prevCronFireMs: () => import_nestjs_durable_core21.prevCronFireMs,
101
+ readSearchAttributes: () => import_nestjs_durable_core21.readSearchAttributes,
102
+ runCompletedEvent: () => import_nestjs_durable_core21.runCompletedEvent,
103
+ runFailedEvent: () => import_nestjs_durable_core21.runFailedEvent,
104
+ runSchedules: () => import_nestjs_durable_core21.runSchedules,
105
+ scheduleRunIdAt: () => import_nestjs_durable_core21.scheduleRunIdAt,
106
+ scheduledRunId: () => import_nestjs_durable_core21.scheduledRunId,
107
+ signTenantToken: () => import_nestjs_durable_core21.signTenantToken,
106
108
  thinWorkerProviders: () => thinWorkerProviders,
107
- triggeredRunsOf: () => import_nestjs_durable_core20.triggeredRunsOf,
109
+ triggeredRunsOf: () => import_nestjs_durable_core21.triggeredRunsOf,
108
110
  unavailableRunGateway: () => unavailableRunGateway
109
111
  });
110
112
  module.exports = __toCommonJS(src_exports);
@@ -840,6 +842,19 @@ var DurableStartClient = class {
840
842
  ...opts?.searchAttributes !== void 0 ? {
841
843
  searchAttributes: opts.searchAttributes
842
844
  } : {},
845
+ // The start options the control plane applies (version pin, priority, delayed start, quota).
846
+ ...opts?.version !== void 0 ? {
847
+ version: opts.version
848
+ } : {},
849
+ ...opts?.priority !== void 0 ? {
850
+ priority: opts.priority
851
+ } : {},
852
+ ...opts?.startAt !== void 0 ? {
853
+ startAt: opts.startAt
854
+ } : {},
855
+ ...opts?.concurrency !== void 0 ? {
856
+ concurrency: opts.concurrency
857
+ } : {},
843
858
  ...tenant ? {
844
859
  tenantId: tenant.id,
845
860
  ...tenant.kind !== void 0 ? {
@@ -850,9 +865,10 @@ var DurableStartClient = class {
850
865
  deps: this.deps
851
866
  } : {}
852
867
  });
868
+ const startAtMs = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
853
869
  return {
854
870
  runId,
855
- status: "pending"
871
+ status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
856
872
  };
857
873
  }
858
874
  cancel(_runId) {
@@ -1137,28 +1153,38 @@ var ThinWorkflowRegistrar = class {
1137
1153
  metadataScanner;
1138
1154
  runtime;
1139
1155
  options;
1140
- constructor(discovery, metadataScanner, runtime, options) {
1156
+ starter;
1157
+ constructor(discovery, metadataScanner, runtime, options, starter) {
1141
1158
  this.discovery = discovery;
1142
1159
  this.metadataScanner = metadataScanner;
1143
1160
  this.runtime = runtime;
1144
1161
  this.options = options;
1162
+ this.starter = starter;
1145
1163
  }
1146
1164
  onModuleInit() {
1147
1165
  const runtime = this.runtime;
1148
1166
  if (runtime === null || !isPureThinWorker(this.options)) return;
1149
- scanWorkflows(this.discovery, (meta, instance, origin) => registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin));
1167
+ const starter = this.starter;
1168
+ scanWorkflows(this.discovery, (meta, instance, origin) => {
1169
+ registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin);
1170
+ (0, import_nestjs_durable_core6.bindWorkflowClass)(instance.constructor, {
1171
+ start: /* @__PURE__ */ __name((name, input, runId, opts) => starter.start(name, input, runId, opts), "start")
1172
+ });
1173
+ });
1150
1174
  }
1151
1175
  };
1152
1176
  ThinWorkflowRegistrar = _ts_decorate2([
1153
1177
  (0, import_common2.Injectable)(),
1154
1178
  _ts_param(2, (0, import_common2.Inject)(DURABLE_WORKER_RUNTIME)),
1155
1179
  _ts_param(3, (0, import_common2.Inject)(import_nestjs_durable_core6.DURABLE_OPTIONS_CANONICAL)),
1180
+ _ts_param(4, (0, import_common2.Inject)(import_nestjs_durable_core6.WorkflowEngine)),
1156
1181
  _ts_metadata2("design:type", Function),
1157
1182
  _ts_metadata2("design:paramtypes", [
1158
1183
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
1159
1184
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
1160
1185
  Object,
1161
- typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
1186
+ typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
1187
+ typeof WorkflowStartClient === "undefined" ? Object : WorkflowStartClient
1162
1188
  ])
1163
1189
  ], ThinWorkflowRegistrar);
1164
1190
  var ThinStepRegistrar = class {
@@ -1698,7 +1724,9 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
1698
1724
  "redispatch",
1699
1725
  "waitingFor",
1700
1726
  "republishLifecycle",
1701
- "workflowLifecycle"
1727
+ "workflowLifecycle",
1728
+ "signal",
1729
+ "schedule"
1702
1730
  ]);
1703
1731
  function wireDate(value) {
1704
1732
  if (value === void 0 || value === null) return void 0;
@@ -1917,6 +1945,43 @@ var RunRequestResponder = class {
1917
1945
  }
1918
1946
  };
1919
1947
  }
1948
+ if (body.kind === "schedule") {
1949
+ const { getSchedule, scheduleAction } = this.gateway;
1950
+ if (!getSchedule || !scheduleAction) return unsupported(msg.requestId, body.kind);
1951
+ if (body.action !== "pause" && body.action !== "resume" && body.action !== "trigger") {
1952
+ return badRequest(msg.requestId, `unknown schedule action ${JSON.stringify(body.action)}`);
1953
+ }
1954
+ const schedule = await getSchedule.call(this.gateway, body.id);
1955
+ if (!schedule || schedule.namespace !== msg.tenant) {
1956
+ return {
1957
+ requestId: msg.requestId,
1958
+ result: {
1959
+ ok: false,
1960
+ error: {
1961
+ message: `schedule "${body.id}" not found`,
1962
+ code: "not-found"
1963
+ }
1964
+ }
1965
+ };
1966
+ }
1967
+ return this.answer(msg.requestId, () => scheduleAction.call(this.gateway, body.id, body.action));
1968
+ }
1969
+ if (body.kind === "signal") {
1970
+ const { signal, signalWaiter } = this.gateway;
1971
+ if (!signal || !signalWaiter) return unsupported(msg.requestId, body.kind);
1972
+ const waiterRunId = await signalWaiter.call(this.gateway, body.token);
1973
+ const waiter = waiterRunId ? await this.runOf(waiterRunId) : null;
1974
+ if (!waiter || waiter.namespace !== msg.tenant) {
1975
+ return {
1976
+ requestId: msg.requestId,
1977
+ result: {
1978
+ ok: true,
1979
+ data: null
1980
+ }
1981
+ };
1982
+ }
1983
+ return this.answer(msg.requestId, () => signal.call(this.gateway, body.token, body.payload));
1984
+ }
1920
1985
  if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
1921
1986
  return unsupported(msg.requestId, body.kind);
1922
1987
  }
@@ -1990,6 +2055,32 @@ var RunRequestResponder = class {
1990
2055
  };
1991
2056
  }
1992
2057
  }
2058
+ /** The run alone (`getRun`, else from its detail), or null when it does not exist. */
2059
+ async runOf(runId) {
2060
+ return this.gateway.getRun ? this.gateway.getRun(runId) : (await this.gateway.getRunDetail(runId))?.run ?? null;
2061
+ }
2062
+ /** `call`'s result as an `ok` reply, or its rejection as an error reply. */
2063
+ async answer(requestId, call) {
2064
+ try {
2065
+ return {
2066
+ requestId,
2067
+ result: {
2068
+ ok: true,
2069
+ data: await call()
2070
+ }
2071
+ };
2072
+ } catch (err) {
2073
+ return {
2074
+ requestId,
2075
+ result: {
2076
+ ok: false,
2077
+ error: {
2078
+ message: err instanceof Error ? err.message : String(err)
2079
+ }
2080
+ }
2081
+ };
2082
+ }
2083
+ }
1993
2084
  /**
1994
2085
  * `detail` scoped to `tenant` (see {@link scopeRunLinks}), with its lifecycle links
1995
2086
  * (`workflowLifecycle`, `lifecycleSubscribers`) narrowed to the subscriptions of `tenant`'s
@@ -3123,6 +3214,27 @@ var StoreRunGateway = class {
3123
3214
  republishLifecycle(target) {
3124
3215
  return this.engine.republishLifecycle(target);
3125
3216
  }
3217
+ /** The persisted schedules (`[]` when the store does not persist them). */
3218
+ async listSchedules(query) {
3219
+ return this.engine.schedules?.supported ? this.engine.schedules.list(query) : [];
3220
+ }
3221
+ async getSchedule(id) {
3222
+ if (!this.engine.schedules?.supported) return null;
3223
+ return await this.engine.schedules.get(id) ?? null;
3224
+ }
3225
+ scheduleAction(id, action) {
3226
+ if (action === "pause") return this.engine.schedules.pause(id);
3227
+ if (action === "resume") return this.engine.schedules.resume(id);
3228
+ if (action === "trigger") return this.engine.schedules.trigger(id);
3229
+ return Promise.reject(new Error(`unknown schedule action ${String(action)}`));
3230
+ }
3231
+ signal(token, payload) {
3232
+ return this.engine.signal(token, payload);
3233
+ }
3234
+ async signalWaiter(token) {
3235
+ const waiter = (await this.store.listSignalWaiters(token)).find((w) => w.token === token);
3236
+ return waiter?.runId ?? null;
3237
+ }
3126
3238
  /**
3127
3239
  * Stream `runId`'s events. With tenancy, a run the caller may not see streams nothing; events of a
3128
3240
  * run that does not exist yet are held until its row shows whose it is.
@@ -4326,8 +4438,268 @@ DurableModule = _ts_decorate13([
4326
4438
  (0, import_common13.Module)({})
4327
4439
  ], DurableModule);
4328
4440
 
4329
- // src/index.ts
4441
+ // src/federated-app-gateway.ts
4330
4442
  var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4443
+ var FederatedAppGateway = class {
4444
+ static {
4445
+ __name(this, "FederatedAppGateway");
4446
+ }
4447
+ options;
4448
+ reads;
4449
+ pending = /* @__PURE__ */ new Map();
4450
+ listening = false;
4451
+ timeoutMs;
4452
+ /** Live-tail listeners by run id, fed by ONE subscription to the app's control channel. */
4453
+ tails = /* @__PURE__ */ new Map();
4454
+ tailing = false;
4455
+ constructor(options) {
4456
+ this.options = options;
4457
+ this.reads = new StoreRunGateway(options.store, new import_nestjs_durable_core20.WorkflowEngine({
4458
+ store: options.store
4459
+ }));
4460
+ this.timeoutMs = options.timeoutMs ?? 1e4;
4461
+ }
4462
+ topology() {
4463
+ return {
4464
+ role: "control-plane"
4465
+ };
4466
+ }
4467
+ getRunDetail(runId, options) {
4468
+ return this.reads.getRunDetail(runId, options);
4469
+ }
4470
+ getFanMembers(runId, group, query) {
4471
+ return this.reads.getFanMembers(runId, group, query);
4472
+ }
4473
+ getRun(runId) {
4474
+ return this.reads.getRun(runId);
4475
+ }
4476
+ listRuns(query) {
4477
+ return this.reads.listRuns(query);
4478
+ }
4479
+ runFacets(query) {
4480
+ return this.reads.runFacets(query);
4481
+ }
4482
+ runValueFacets(axis, query, opts) {
4483
+ return this.reads.runValueFacets(axis, query, opts);
4484
+ }
4485
+ waitingFor(runIds) {
4486
+ return this.reads.waitingFor(runIds);
4487
+ }
4488
+ workflowLifecycle(workflow, opts) {
4489
+ return this.reads.workflowLifecycle(workflow, opts);
4490
+ }
4491
+ lifecycleSubscribers(workflow, kind, namespace) {
4492
+ return this.reads.lifecycleSubscribers(workflow, kind, namespace);
4493
+ }
4494
+ /** The app's worker groups, read from its broker (read-only). `[]` when the transport can't. */
4495
+ async workerHealth() {
4496
+ const { transport } = this.options;
4497
+ if (!transport.listWorkerGroups || !transport.groupHealth) return [];
4498
+ const groups = await transport.listWorkerGroups();
4499
+ return Promise.all(groups.map((group) => transport.groupHealth?.(group)));
4500
+ }
4501
+ listSchedules(query) {
4502
+ return this.reads.listSchedules(query);
4503
+ }
4504
+ getSchedule(id) {
4505
+ return this.reads.getSchedule(id);
4506
+ }
4507
+ signalWaiter(token) {
4508
+ return this.reads.signalWaiter(token);
4509
+ }
4510
+ cancel(runId, opts) {
4511
+ return this.onRun(runId, (namespace) => this.request(namespace, opts === void 0 ? {
4512
+ kind: "cancel",
4513
+ runId
4514
+ } : {
4515
+ kind: "cancel",
4516
+ runId,
4517
+ opts
4518
+ }));
4519
+ }
4520
+ retry(runId) {
4521
+ return this.onRun(runId, (namespace) => this.request(namespace, {
4522
+ kind: "retry",
4523
+ runId
4524
+ }));
4525
+ }
4526
+ continue(runId) {
4527
+ return this.onRun(runId, (namespace) => this.request(namespace, {
4528
+ kind: "continue",
4529
+ runId
4530
+ }));
4531
+ }
4532
+ retryWithInput(runId, input) {
4533
+ return this.onRun(runId, (namespace) => this.request(namespace, {
4534
+ kind: "retryWithInput",
4535
+ runId,
4536
+ input
4537
+ }));
4538
+ }
4539
+ redispatchPending(runId) {
4540
+ return this.onRun(runId, (namespace) => this.request(namespace, {
4541
+ kind: "redispatch",
4542
+ runId
4543
+ }));
4544
+ }
4545
+ async republishLifecycle(target) {
4546
+ let namespace;
4547
+ if ("runId" in target) {
4548
+ const run = await this.reads.getRun(target.runId);
4549
+ if (!run) throw new Error(`run ${target.runId} not found`);
4550
+ namespace = run.namespace || "default";
4551
+ } else {
4552
+ namespace = target.namespace;
4553
+ if (namespace === void 0) {
4554
+ throw Object.assign(new Error("republish by workflow needs a namespace on a federated app"), {
4555
+ code: "bad-request"
4556
+ });
4557
+ }
4558
+ }
4559
+ return this.request(namespace, {
4560
+ kind: "republishLifecycle",
4561
+ target
4562
+ });
4563
+ }
4564
+ /**
4565
+ * Pause, resume or trigger one of the app's persisted schedules, executed by the app. A schedule
4566
+ * that does not exist rejects with a `ScheduleNotFoundError`, as the engine's own client does.
4567
+ */
4568
+ async scheduleAction(id, action) {
4569
+ const schedule = await this.reads.getSchedule(id);
4570
+ if (!schedule) throw scheduleNotFound(id);
4571
+ try {
4572
+ return await this.request(schedule.namespace, {
4573
+ kind: "schedule",
4574
+ id,
4575
+ action
4576
+ });
4577
+ } catch (err) {
4578
+ if (err instanceof RunGatewayError && err.code === "not-found") throw scheduleNotFound(id);
4579
+ throw err;
4580
+ }
4581
+ }
4582
+ /**
4583
+ * Deliver `payload` to the app's run waiting on `token`, by the app. Null when no run of the app
4584
+ * waits on it yet: unlike the engine's own `signal`, nothing is buffered for a later wait.
4585
+ */
4586
+ async signal(token, payload) {
4587
+ const runId = await this.reads.signalWaiter(token);
4588
+ if (!runId) return null;
4589
+ return this.onRun(runId, (namespace) => this.request(namespace, {
4590
+ kind: "signal",
4591
+ token,
4592
+ payload
4593
+ }));
4594
+ }
4595
+ /**
4596
+ * The app's live events for `runId`, from the control channel its engines broadcast every event on
4597
+ * (see {@link FederatedAppGatewayOptions.controlPlane}). Nothing when there is none.
4598
+ */
4599
+ subscribe(runId, onEvent) {
4600
+ const control = this.controlPlane();
4601
+ if (!control) return () => void 0;
4602
+ if (!this.tailing) {
4603
+ this.tailing = true;
4604
+ control.onControl((msg) => this.deliver(msg));
4605
+ }
4606
+ let listeners = this.tails.get(runId);
4607
+ if (!listeners) {
4608
+ listeners = /* @__PURE__ */ new Set();
4609
+ this.tails.set(runId, listeners);
4610
+ }
4611
+ listeners.add(onEvent);
4612
+ return () => {
4613
+ const current = this.tails.get(runId);
4614
+ current?.delete(onEvent);
4615
+ if (current?.size === 0) this.tails.delete(runId);
4616
+ };
4617
+ }
4618
+ controlPlane() {
4619
+ if (this.options.controlPlane) return this.options.controlPlane;
4620
+ const candidate = this.options.transport;
4621
+ return typeof candidate.onControl === "function" ? this.options.transport : void 0;
4622
+ }
4623
+ deliver(msg) {
4624
+ if (this.tails.size === 0) return;
4625
+ const events = msg.kind === "event" ? [
4626
+ msg.event
4627
+ ] : msg.kind === "events" ? msg.events : [];
4628
+ for (const event of events) {
4629
+ const listeners = this.tails.get(event.runId);
4630
+ if (!listeners) continue;
4631
+ const live = {
4632
+ ...event,
4633
+ at: new Date(event.at)
4634
+ };
4635
+ for (const listener of listeners) listener(live);
4636
+ }
4637
+ }
4638
+ /** `act` with the namespace of `runId`, or null when the app has no such run. */
4639
+ async onRun(runId, act) {
4640
+ const run = await this.reads.getRun(runId);
4641
+ if (!run) return null;
4642
+ return act(run.namespace || "default");
4643
+ }
4644
+ /** Send `body` to the app as a run request from `namespace`, and wait for its reply. */
4645
+ async request(namespace, body) {
4646
+ const { transport, tenantToken } = this.options;
4647
+ if (!transport.dispatchRunRequest || !transport.onRunReply) {
4648
+ throw new Error("a federated app needs a transport that carries run requests (e.g. BullMQTransport)");
4649
+ }
4650
+ this.listen();
4651
+ const tenant = tenantToken ? await tenantToken(namespace) : namespace;
4652
+ return new Promise((resolve, reject) => {
4653
+ const requestId = globalThis.crypto.randomUUID();
4654
+ const timer = setTimeout(() => {
4655
+ this.pending.delete(requestId);
4656
+ reject(new Error(`the app did not answer ${body.kind} within ${this.timeoutMs}ms`));
4657
+ }, this.timeoutMs);
4658
+ this.pending.set(requestId, {
4659
+ resolve: /* @__PURE__ */ __name((data) => resolve(data), "resolve"),
4660
+ reject,
4661
+ timer
4662
+ });
4663
+ transport.dispatchRunRequest?.({
4664
+ requestId,
4665
+ tenant,
4666
+ body
4667
+ })?.catch((error) => {
4668
+ const entry = this.pending.get(requestId);
4669
+ if (!entry) return;
4670
+ clearTimeout(entry.timer);
4671
+ this.pending.delete(requestId);
4672
+ entry.reject(error instanceof Error ? error : new Error(String(error)));
4673
+ });
4674
+ });
4675
+ }
4676
+ listen() {
4677
+ if (this.listening) return;
4678
+ this.listening = true;
4679
+ this.options.transport.onRunReply?.((reply) => this.handleReply(reply));
4680
+ }
4681
+ handleReply(reply) {
4682
+ const entry = this.pending.get(reply.requestId);
4683
+ if (!entry) return;
4684
+ clearTimeout(entry.timer);
4685
+ this.pending.delete(reply.requestId);
4686
+ if (reply.result.ok) entry.resolve(reply.result.data);
4687
+ else entry.reject(new RunGatewayError(reply.result.error.message, reply.result.error.code));
4688
+ }
4689
+ };
4690
+ function scheduleNotFound(id) {
4691
+ return Object.assign(new Error(`schedule "${id}" not found`), {
4692
+ name: "ScheduleNotFoundError"
4693
+ });
4694
+ }
4695
+ __name(scheduleNotFound, "scheduleNotFound");
4696
+ function federatedAppGateway(options) {
4697
+ return new FederatedAppGateway(options);
4698
+ }
4699
+ __name(federatedAppGateway, "federatedAppGateway");
4700
+
4701
+ // src/index.ts
4702
+ var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
4331
4703
  // Annotate the CommonJS export names for ESM import in node:
4332
4704
  0 && (module.exports = {
4333
4705
  BAD_RUN_REQUEST,
@@ -4344,6 +4716,7 @@ var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4344
4716
  ENTITY_ON_METADATA,
4345
4717
  Entity,
4346
4718
  EntityService,
4719
+ FederatedAppGateway,
4347
4720
  IN_APP_RUN_REDIS_WORKER,
4348
4721
  IN_APP_WORKER_BINDING,
4349
4722
  IN_APP_WORKER_RUNNERS,
@@ -4381,6 +4754,7 @@ var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4381
4754
  attributesOf,
4382
4755
  entityConfigFor,
4383
4756
  eventBatchOf,
4757
+ federatedAppGateway,
4384
4758
  getDurableStepMeta,
4385
4759
  getEntityMeta,
4386
4760
  getOnEvents,