@dudousxd/nestjs-durable 0.43.0 → 0.43.2

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.d.cts CHANGED
@@ -708,6 +708,12 @@ declare class DurableStartClient {
708
708
  * fake so no real Redis is needed.
709
709
  */
710
710
  declare const RUN_REDIS_WORKER: unique symbol;
711
+ /**
712
+ * The store-less {@link DurableWorkerRuntime} a pure thin worker registers its bodies on — `null` in
713
+ * every other role. A Symbol rather than the class itself: the class lives in an optional peer, and
714
+ * using it as a DI token would drag that peer into the package's static import graph.
715
+ */
716
+ declare const DURABLE_WORKER_RUNTIME: unique symbol;
711
717
  /** The list of started {@link RunningWorker} handles (the single handle {@link ThinWorkerBootstrap}
712
718
  * starts), closed on shutdown. */
713
719
  declare const DURABLE_WORKER_RUNNERS: unique symbol;
@@ -724,7 +730,7 @@ declare class ThinWorkflowRegistrar implements OnModuleInit {
724
730
  private readonly discovery;
725
731
  private readonly runtime;
726
732
  private readonly options;
727
- constructor(discovery: DiscoveryService, runtime: DurableWorkerRuntime, options: DurableModuleOptions);
733
+ constructor(discovery: DiscoveryService, runtime: DurableWorkerRuntime | null, options: DurableModuleOptions);
728
734
  onModuleInit(): void;
729
735
  }
730
736
  /**
@@ -738,7 +744,7 @@ declare class ThinStepRegistrar implements OnModuleInit {
738
744
  private readonly metadataScanner;
739
745
  private readonly runtime;
740
746
  private readonly options;
741
- constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, runtime: DurableWorkerRuntime, options: DurableModuleOptions);
747
+ constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, runtime: DurableWorkerRuntime | null, options: DurableModuleOptions);
742
748
  onModuleInit(): void;
743
749
  }
744
750
  /**
@@ -757,7 +763,7 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
757
763
  private readonly runRedisWorker;
758
764
  private readonly runnersSink;
759
765
  private readonly runners;
760
- constructor(runtime: DurableWorkerRuntime, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
766
+ constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
761
767
  onApplicationBootstrap(): Promise<void>;
762
768
  onApplicationShutdown(): Promise<void>;
763
769
  }
@@ -864,7 +870,7 @@ declare class InAppWorkerBootstrap implements OnModuleInit, OnApplicationBootstr
864
870
  private readonly runRedisWorker;
865
871
  private readonly runnersSink;
866
872
  private readonly runners;
867
- constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, options: DurableModuleOptions, runtime: DurableWorkerRuntime, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
873
+ constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, options: DurableModuleOptions, runtime: DurableWorkerRuntime | null, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
868
874
  onModuleInit(): void;
869
875
  onApplicationBootstrap(): Promise<void>;
870
876
  onApplicationShutdown(): Promise<void>;
@@ -1150,4 +1156,4 @@ declare class WorkflowService {
1150
1156
  }): Promise<number>;
1151
1157
  }
1152
1158
 
1153
- export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
1159
+ export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.d.ts CHANGED
@@ -708,6 +708,12 @@ declare class DurableStartClient {
708
708
  * fake so no real Redis is needed.
709
709
  */
710
710
  declare const RUN_REDIS_WORKER: unique symbol;
711
+ /**
712
+ * The store-less {@link DurableWorkerRuntime} a pure thin worker registers its bodies on — `null` in
713
+ * every other role. A Symbol rather than the class itself: the class lives in an optional peer, and
714
+ * using it as a DI token would drag that peer into the package's static import graph.
715
+ */
716
+ declare const DURABLE_WORKER_RUNTIME: unique symbol;
711
717
  /** The list of started {@link RunningWorker} handles (the single handle {@link ThinWorkerBootstrap}
712
718
  * starts), closed on shutdown. */
713
719
  declare const DURABLE_WORKER_RUNNERS: unique symbol;
@@ -724,7 +730,7 @@ declare class ThinWorkflowRegistrar implements OnModuleInit {
724
730
  private readonly discovery;
725
731
  private readonly runtime;
726
732
  private readonly options;
727
- constructor(discovery: DiscoveryService, runtime: DurableWorkerRuntime, options: DurableModuleOptions);
733
+ constructor(discovery: DiscoveryService, runtime: DurableWorkerRuntime | null, options: DurableModuleOptions);
728
734
  onModuleInit(): void;
729
735
  }
730
736
  /**
@@ -738,7 +744,7 @@ declare class ThinStepRegistrar implements OnModuleInit {
738
744
  private readonly metadataScanner;
739
745
  private readonly runtime;
740
746
  private readonly options;
741
- constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, runtime: DurableWorkerRuntime, options: DurableModuleOptions);
747
+ constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, runtime: DurableWorkerRuntime | null, options: DurableModuleOptions);
742
748
  onModuleInit(): void;
743
749
  }
744
750
  /**
@@ -757,7 +763,7 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
757
763
  private readonly runRedisWorker;
758
764
  private readonly runnersSink;
759
765
  private readonly runners;
760
- constructor(runtime: DurableWorkerRuntime, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
766
+ constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
761
767
  onApplicationBootstrap(): Promise<void>;
762
768
  onApplicationShutdown(): Promise<void>;
763
769
  }
@@ -864,7 +870,7 @@ declare class InAppWorkerBootstrap implements OnModuleInit, OnApplicationBootstr
864
870
  private readonly runRedisWorker;
865
871
  private readonly runnersSink;
866
872
  private readonly runners;
867
- constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, options: DurableModuleOptions, runtime: DurableWorkerRuntime, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
873
+ constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, options: DurableModuleOptions, runtime: DurableWorkerRuntime | null, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
868
874
  onModuleInit(): void;
869
875
  onApplicationBootstrap(): Promise<void>;
870
876
  onApplicationShutdown(): Promise<void>;
@@ -1150,4 +1156,4 @@ declare class WorkflowService {
1150
1156
  }): Promise<number>;
1151
1157
  }
1152
1158
 
1153
- export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
1159
+ export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.js CHANGED
@@ -1,11 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
3
 
10
4
  // src/attributes-of.ts
11
5
  import { readSearchAttributes } from "@dudousxd/nestjs-durable-core";
@@ -244,9 +238,29 @@ function attributesOf(workflow, run) {
244
238
  __name(attributesOf, "attributesOf");
245
239
 
246
240
  // src/durable-start-client.ts
247
- import { startRun } from "@dudousxd/durable-worker";
248
241
  import { workflowName } from "@dudousxd/nestjs-durable-core";
249
242
  import { Injectable } from "@nestjs/common";
243
+
244
+ // src/worker-sdk.ts
245
+ async function workerSdk() {
246
+ try {
247
+ return await import("@dudousxd/durable-worker");
248
+ } catch (cause) {
249
+ throw new Error("@dudousxd/durable-worker is not installed. It is an optional peer needed only by the roles that run workflow bodies (`connection` set on DurableModule.forRoot) \u2014 install it, or drop `connection`.", {
250
+ cause
251
+ });
252
+ }
253
+ }
254
+ __name(workerSdk, "workerSdk");
255
+ var startRun = /* @__PURE__ */ __name(async (connection, options) => (await workerSdk()).startRun(connection, options), "startRun");
256
+ var runRedisWorker = /* @__PURE__ */ __name(async (options) => (await workerSdk()).runRedisWorker(options), "runRedisWorker");
257
+ async function createWorkerRuntime(options) {
258
+ const { DurableWorkerRuntime: Runtime } = await workerSdk();
259
+ return new Runtime(options);
260
+ }
261
+ __name(createWorkerRuntime, "createWorkerRuntime");
262
+
263
+ // src/durable-start-client.ts
250
264
  function _ts_decorate(decorators, target, key, desc) {
251
265
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
252
266
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -339,7 +353,6 @@ function tenantUnsupported(method) {
339
353
  __name(tenantUnsupported, "tenantUnsupported");
340
354
 
341
355
  // src/durable-worker.module.ts
342
- import { DurableWorkerRuntime, runRedisWorker as defaultRunRedisWorker } from "@dudousxd/durable-worker";
343
356
  import { DURABLE_OPTIONS_CANONICAL } from "@dudousxd/nestjs-durable-core";
344
357
  import { Inject, Injectable as Injectable2 } from "@nestjs/common";
345
358
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
@@ -400,6 +413,7 @@ function _ts_param(paramIndex, decorator) {
400
413
  }
401
414
  __name(_ts_param, "_ts_param");
402
415
  var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
416
+ var DURABLE_WORKER_RUNTIME = Symbol("nestjs-durable:worker-runtime");
403
417
  var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
404
418
  function isPureThinWorker(options) {
405
419
  return options.store === void 0 && options.connection !== void 0;
@@ -418,8 +432,9 @@ var ThinWorkflowRegistrar = class {
418
432
  this.options = options;
419
433
  }
420
434
  onModuleInit() {
421
- if (!isPureThinWorker(this.options)) return;
422
- scanWorkflows(this.discovery, (meta, instance, origin) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input), {
435
+ const runtime = this.runtime;
436
+ if (runtime === null || !isPureThinWorker(this.options)) return;
437
+ scanWorkflows(this.discovery, (meta, instance, origin) => runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input), {
423
438
  version: meta.version,
424
439
  ...meta.requires !== void 0 ? {
425
440
  requires: meta.requires
@@ -432,11 +447,12 @@ var ThinWorkflowRegistrar = class {
432
447
  };
433
448
  ThinWorkflowRegistrar = _ts_decorate2([
434
449
  Injectable2(),
450
+ _ts_param(1, Inject(DURABLE_WORKER_RUNTIME)),
435
451
  _ts_param(2, Inject(DURABLE_OPTIONS_CANONICAL)),
436
452
  _ts_metadata2("design:type", Function),
437
453
  _ts_metadata2("design:paramtypes", [
438
454
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
439
- typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime,
455
+ Object,
440
456
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
441
457
  ])
442
458
  ], ThinWorkflowRegistrar);
@@ -455,18 +471,20 @@ var ThinStepRegistrar = class {
455
471
  this.options = options;
456
472
  }
457
473
  onModuleInit() {
458
- if (!isPureThinWorker(this.options)) return;
459
- scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
474
+ const runtime = this.runtime;
475
+ if (runtime === null || !isPureThinWorker(this.options)) return;
476
+ scanSteps(this.discovery, this.metadataScanner, (meta, handler) => runtime.registerStep(meta.name, handler));
460
477
  }
461
478
  };
462
479
  ThinStepRegistrar = _ts_decorate2([
463
480
  Injectable2(),
481
+ _ts_param(2, Inject(DURABLE_WORKER_RUNTIME)),
464
482
  _ts_param(3, Inject(DURABLE_OPTIONS_CANONICAL)),
465
483
  _ts_metadata2("design:type", Function),
466
484
  _ts_metadata2("design:paramtypes", [
467
485
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
468
486
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
469
- typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime,
487
+ Object,
470
488
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
471
489
  ])
472
490
  ], ThinStepRegistrar);
@@ -479,17 +497,18 @@ var ThinWorkerBootstrap = class {
479
497
  runRedisWorker;
480
498
  runnersSink;
481
499
  runners = [];
482
- constructor(runtime, options, runRedisWorker, runnersSink) {
500
+ constructor(runtime, options, runRedisWorker2, runnersSink) {
483
501
  this.runtime = runtime;
484
502
  this.options = options;
485
- this.runRedisWorker = runRedisWorker;
503
+ this.runRedisWorker = runRedisWorker2;
486
504
  this.runnersSink = runnersSink;
487
505
  }
488
506
  async onApplicationBootstrap() {
489
507
  const options = this.options;
490
- if (!isPureThinWorker(options) || options.connection === void 0) return;
508
+ const runtime = this.runtime;
509
+ if (runtime === null || !isPureThinWorker(options) || options.connection === void 0) return;
491
510
  const handle = await this.runRedisWorker({
492
- runtime: this.runtime,
511
+ runtime,
493
512
  connection: options.connection,
494
513
  ...options.partition !== void 0 ? {
495
514
  partition: options.partition
@@ -513,12 +532,13 @@ var ThinWorkerBootstrap = class {
513
532
  };
514
533
  ThinWorkerBootstrap = _ts_decorate2([
515
534
  Injectable2(),
535
+ _ts_param(0, Inject(DURABLE_WORKER_RUNTIME)),
516
536
  _ts_param(1, Inject(DURABLE_OPTIONS_CANONICAL)),
517
537
  _ts_param(2, Inject(RUN_REDIS_WORKER)),
518
538
  _ts_param(3, Inject(DURABLE_WORKER_RUNNERS)),
519
539
  _ts_metadata2("design:type", Function),
520
540
  _ts_metadata2("design:paramtypes", [
521
- typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime,
541
+ Object,
522
542
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
523
543
  typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
524
544
  Array
@@ -527,7 +547,7 @@ ThinWorkerBootstrap = _ts_decorate2([
527
547
  function thinWorkerProviders() {
528
548
  return [
529
549
  {
530
- provide: DurableWorkerRuntime,
550
+ provide: DURABLE_WORKER_RUNTIME,
531
551
  // The runtime's `WorkflowWorker` falls back to its own `group` ctor param as the WORKFLOW's
532
552
  // `workflowPartition` for any `ctx.step` call (see `workflow-context.ts`'s `resolveCallGroup`)
533
553
  // — that fallback MUST equal this module's own `partition`, or a dispatched step's decision
@@ -535,16 +555,20 @@ function thinWorkerProviders() {
535
555
  // to. Explicit `''` (never
536
556
  // `undefined`) so it does NOT fall through to `WorkflowWorker`'s unrelated `'workflows'`
537
557
  // default parameter.
538
- useFactory: /* @__PURE__ */ __name((options) => new DurableWorkerRuntime({
558
+ //
559
+ // The role gate lives HERE, not just in the consumers: constructing the runtime resolves the
560
+ // optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
561
+ // reach this branch at all.
562
+ useFactory: /* @__PURE__ */ __name((options) => isPureThinWorker(options) ? createWorkerRuntime({
539
563
  workflowGroup: options.partition ?? ""
540
- }), "useFactory"),
564
+ }) : null, "useFactory"),
541
565
  inject: [
542
566
  DURABLE_OPTIONS_CANONICAL
543
567
  ]
544
568
  },
545
569
  {
546
570
  provide: RUN_REDIS_WORKER,
547
- useValue: defaultRunRedisWorker
571
+ useValue: runRedisWorker
548
572
  },
549
573
  {
550
574
  provide: DURABLE_WORKER_RUNNERS,
@@ -764,7 +788,6 @@ EntityService = _ts_decorate4([
764
788
  ], EntityService);
765
789
 
766
790
  // src/in-app-worker.ts
767
- import { DurableWorkerRuntime as DurableWorkerRuntime2, runRedisWorker as defaultRunRedisWorker2 } from "@dudousxd/durable-worker";
768
791
  import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL3, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL2 } from "@dudousxd/nestjs-durable-core";
769
792
  import { Inject as Inject3, Injectable as Injectable5 } from "@nestjs/common";
770
793
  import { DiscoveryService as DiscoveryService3, MetadataScanner as MetadataScanner3 } from "@nestjs/core";
@@ -817,17 +840,18 @@ var InAppWorkerBootstrap = class {
817
840
  runRedisWorker;
818
841
  runnersSink;
819
842
  runners = [];
820
- constructor(discovery, metadataScanner, options, runtime, runRedisWorker, runnersSink) {
843
+ constructor(discovery, metadataScanner, options, runtime, runRedisWorker2, runnersSink) {
821
844
  this.discovery = discovery;
822
845
  this.metadataScanner = metadataScanner;
823
846
  this.options = options;
824
847
  this.runtime = runtime;
825
- this.runRedisWorker = runRedisWorker;
848
+ this.runRedisWorker = runRedisWorker2;
826
849
  this.runnersSink = runnersSink;
827
850
  }
828
851
  onModuleInit() {
829
- if (!isCoLocatedWorker(this.options)) return;
830
- scanWorkflows(this.discovery, (meta, instance, origin) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input), {
852
+ const runtime = this.runtime;
853
+ if (runtime === null || !isCoLocatedWorker(this.options)) return;
854
+ scanWorkflows(this.discovery, (meta, instance, origin) => runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input), {
831
855
  version: meta.version,
832
856
  ...meta.requires !== void 0 ? {
833
857
  requires: meta.requires
@@ -836,13 +860,14 @@ var InAppWorkerBootstrap = class {
836
860
  origin
837
861
  } : {}
838
862
  }));
839
- scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
863
+ scanSteps(this.discovery, this.metadataScanner, (meta, handler) => runtime.registerStep(meta.name, handler));
840
864
  }
841
865
  async onApplicationBootstrap() {
842
866
  const options = this.options;
843
- if (!isCoLocatedWorker(options) || options.connection === void 0) return;
867
+ const runtime = this.runtime;
868
+ if (runtime === null || !isCoLocatedWorker(options) || options.connection === void 0) return;
844
869
  const handle = await this.runRedisWorker({
845
- runtime: this.runtime,
870
+ runtime,
846
871
  connection: options.connection,
847
872
  ...options.partition !== void 0 ? {
848
873
  partition: options.partition
@@ -875,7 +900,7 @@ InAppWorkerBootstrap = _ts_decorate5([
875
900
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
876
901
  typeof MetadataScanner3 === "undefined" ? Object : MetadataScanner3,
877
902
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
878
- typeof DurableWorkerRuntime2 === "undefined" ? Object : DurableWorkerRuntime2,
903
+ Object,
879
904
  typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
880
905
  Array
881
906
  ])
@@ -899,16 +924,20 @@ function inAppWorkerProviders() {
899
924
  // to. Explicit `''` (never
900
925
  // `undefined`) so it does NOT fall through to `WorkflowWorker`'s unrelated `'workflows'`
901
926
  // default parameter.
902
- useFactory: /* @__PURE__ */ __name((options) => new DurableWorkerRuntime2({
927
+ //
928
+ // The role gate lives HERE, not just in the consumer: constructing the runtime resolves the
929
+ // optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
930
+ // reach this branch at all.
931
+ useFactory: /* @__PURE__ */ __name((options) => isCoLocatedWorker(options) ? createWorkerRuntime({
903
932
  workflowGroup: options.partition ?? ""
904
- }), "useFactory"),
933
+ }) : null, "useFactory"),
905
934
  inject: [
906
935
  DURABLE_OPTIONS_CANONICAL3
907
936
  ]
908
937
  },
909
938
  {
910
939
  provide: IN_APP_RUN_REDIS_WORKER,
911
- useValue: defaultRunRedisWorker2
940
+ useValue: runRedisWorker
912
941
  },
913
942
  {
914
943
  provide: IN_APP_WORKER_RUNNERS,
@@ -1169,6 +1198,15 @@ var RetentionPoller = class {
1169
1198
  onModuleDestroy() {
1170
1199
  if (this.timer) clearInterval(this.timer);
1171
1200
  }
1201
+ /**
1202
+ * Prune one round.
1203
+ *
1204
+ * Never rejects, for the same reason {@link TimerPoller.poll} does not: it is awaited inside
1205
+ * `onApplicationBootstrap` (so a rejection propagates into the host's `bootstrap()` and kills the
1206
+ * process) and fired as `void` on the interval (so a rejection is an unhandled one, also fatal).
1207
+ * Pruning history is the least urgent thing this package does — a `pruneTerminalRuns` that fails
1208
+ * on a locked table must cost this sweep and nothing more.
1209
+ */
1172
1210
  async sweep() {
1173
1211
  if (this.sweeping) return;
1174
1212
  const retention = this.options.retention;
@@ -1185,6 +1223,8 @@ var RetentionPoller = class {
1185
1223
  if (deleted < batchSize) break;
1186
1224
  }
1187
1225
  }
1226
+ } catch (error) {
1227
+ console.error("[nestjs-durable] retention sweep failed; retrying next interval:", error);
1188
1228
  } finally {
1189
1229
  this.sweeping = false;
1190
1230
  }
@@ -1579,7 +1619,11 @@ var TimerPoller = class {
1579
1619
  }
1580
1620
  async onApplicationBootstrap() {
1581
1621
  if (!isDrivingOperator(this.options)) return;
1582
- this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => void this.engine.runOne(runId));
1622
+ this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
1623
+ void this.engine.runOne(runId).catch((error) => {
1624
+ console.error(`[nestjs-durable] could not run enqueued run ${runId}:`, error);
1625
+ });
1626
+ });
1583
1627
  await this.poll();
1584
1628
  const intervalMs = this.options.timerPollMs ?? 1e3;
1585
1629
  if (intervalMs > 0) {
@@ -1591,22 +1635,45 @@ var TimerPoller = class {
1591
1635
  if (this.timer) clearInterval(this.timer);
1592
1636
  this.unsubscribeEnqueued?.();
1593
1637
  }
1638
+ /**
1639
+ * One sweep of the engine's recovery work.
1640
+ *
1641
+ * **This method never rejects, and that is a hard requirement rather than defensiveness.** It has
1642
+ * exactly two callers and a rejection out of either one kills the process: on boot it is awaited
1643
+ * inside `onApplicationBootstrap`, so the rejection propagates through `NestApplication.init()`
1644
+ * into the host's `bootstrap()`; on the interval it is a fire-and-forget `void`, so it surfaces as
1645
+ * an unhandled rejection. Both are fatal, and both re-occur on the next boot with the same state,
1646
+ * so a single unrecoverable run crash-loops every worker in the deployment — taking down every
1647
+ * other workflow with it. A poll that goes wrong must cost this tick, not the pod.
1648
+ *
1649
+ * Each sweep is isolated separately because they are independent: a store that fails
1650
+ * `recoverIncomplete` says nothing about whether durable timers should still fire, and skipping
1651
+ * the rest of the tick would silently widen one subsystem's outage into all of them.
1652
+ */
1594
1653
  async poll() {
1595
1654
  if (this.polling) return;
1596
1655
  this.polling = true;
1597
1656
  try {
1598
- await this.engine.runPending();
1599
- await this.engine.recoverIncomplete();
1600
- await this.engine.resumeDueTimers();
1601
- await this.engine.sweepTimeouts();
1657
+ await this.sweep("runPending", () => this.engine.runPending());
1658
+ await this.sweep("recoverIncomplete", () => this.engine.recoverIncomplete());
1659
+ await this.sweep("resumeDueTimers", () => this.engine.resumeDueTimers());
1660
+ await this.sweep("sweepTimeouts", () => this.engine.sweepTimeouts());
1602
1661
  const schedules = this.options.schedules;
1603
1662
  if (schedules && schedules.length > 0) {
1604
- await runSchedules(this.engine, schedules, Date.now());
1663
+ await this.sweep("schedules", () => runSchedules(this.engine, schedules, Date.now()));
1605
1664
  }
1606
1665
  } finally {
1607
1666
  this.polling = false;
1608
1667
  }
1609
1668
  }
1669
+ /** Run one sweep, absorbing and reporting its failure — see {@link poll}. */
1670
+ async sweep(name, run) {
1671
+ try {
1672
+ await run();
1673
+ } catch (error) {
1674
+ console.error(`[nestjs-durable] timer poll: ${name} failed; continuing:`, error);
1675
+ }
1676
+ }
1610
1677
  };
1611
1678
  TimerPoller = _ts_decorate9([
1612
1679
  Injectable9(),
@@ -1630,15 +1697,15 @@ import { DiscoveryService as DiscoveryService4, MetadataScanner as MetadataScann
1630
1697
 
1631
1698
  // src/input-validation.ts
1632
1699
  function classValidatorInput(cls) {
1633
- let cv;
1634
- let ct;
1635
- try {
1636
- cv = __require("class-validator");
1637
- ct = __require("class-transformer");
1638
- } catch {
1639
- throw new Error('@Workflow({ inputSchema }) needs the optional peers "class-validator" and "class-transformer" \u2014 install them, or pass a `validateInput` function instead.');
1640
- }
1641
1700
  return async (input) => {
1701
+ let cv;
1702
+ let ct;
1703
+ try {
1704
+ cv = await import("class-validator");
1705
+ ct = await import("class-transformer");
1706
+ } catch {
1707
+ throw new Error('@Workflow({ inputSchema }) needs the optional peers "class-validator" and "class-transformer" \u2014 install them, or pass a `validateInput` function instead.');
1708
+ }
1642
1709
  const instance = ct.plainToInstance(cls, input);
1643
1710
  const errors = await cv.validate(instance, {
1644
1711
  whitelist: true
@@ -2326,6 +2393,7 @@ export {
2326
2393
  DEAD_LETTER_METADATA,
2327
2394
  DURABLE_STEP_METADATA,
2328
2395
  DURABLE_WORKER_RUNNERS,
2396
+ DURABLE_WORKER_RUNTIME,
2329
2397
  DeadLetter,
2330
2398
  DurableModule,
2331
2399
  DurableStartClient,