@dudousxd/nestjs-durable 0.22.0 → 0.23.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
@@ -34,6 +34,12 @@ __export(index_exports, {
34
34
  ENTITY_ON_METADATA: () => ENTITY_ON_METADATA,
35
35
  Entity: () => Entity,
36
36
  EntityService: () => EntityService,
37
+ IN_APP_RUN_REDIS_WORKER: () => IN_APP_RUN_REDIS_WORKER,
38
+ IN_APP_WORKER_BINDING: () => IN_APP_WORKER_BINDING,
39
+ IN_APP_WORKER_OPTIONS: () => IN_APP_WORKER_OPTIONS,
40
+ IN_APP_WORKER_RUNNERS: () => IN_APP_WORKER_RUNNERS,
41
+ IN_APP_WORKER_RUNTIME: () => IN_APP_WORKER_RUNTIME,
42
+ InAppWorkerBootstrap: () => InAppWorkerBootstrap,
37
43
  ON_EVENT_METADATA: () => ON_EVENT_METADATA,
38
44
  On: () => On,
39
45
  OnEvent: () => OnEvent,
@@ -51,6 +57,7 @@ __export(index_exports, {
51
57
  getEntityMeta: () => getEntityMeta,
52
58
  getOnEvents: () => getOnEvents,
53
59
  getWorkflowMeta: () => getWorkflowMeta,
60
+ inAppWorkerProviders: () => inAppWorkerProviders,
54
61
  isDeadLetterHandler: () => isDeadLetterHandler,
55
62
  isStepInterceptor: () => isStepInterceptor
56
63
  });
@@ -342,9 +349,9 @@ DurableWorkerModule = _ts_decorate([
342
349
  ], DurableWorkerModule);
343
350
 
344
351
  // src/durable.module.ts
345
- var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
346
- var import_common8 = require("@nestjs/common");
347
- var import_core4 = require("@nestjs/core");
352
+ var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
353
+ var import_common9 = require("@nestjs/common");
354
+ var import_core5 = require("@nestjs/core");
348
355
 
349
356
  // src/durable-step.registrar.ts
350
357
  var import_nestjs_durable_core2 = require("@dudousxd/nestjs-durable-core");
@@ -484,9 +491,11 @@ EntityService = _ts_decorate3([
484
491
  ])
485
492
  ], EntityService);
486
493
 
487
- // src/retention-poller.ts
494
+ // src/in-app-worker.ts
495
+ var import_durable_worker2 = require("@dudousxd/durable-worker");
488
496
  var import_nestjs_durable_core4 = require("@dudousxd/nestjs-durable-core");
489
497
  var import_common4 = require("@nestjs/common");
498
+ var import_core3 = require("@nestjs/core");
490
499
  function _ts_decorate4(decorators, target, key, desc) {
491
500
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
492
501
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -504,6 +513,136 @@ function _ts_param3(paramIndex, decorator) {
504
513
  };
505
514
  }
506
515
  __name(_ts_param3, "_ts_param");
516
+ var IN_APP_WORKER_OPTIONS = Symbol("nestjs-durable:in-app-worker-options");
517
+ var IN_APP_WORKER_BINDING = Symbol("nestjs-durable:in-app-worker-binding");
518
+ var IN_APP_WORKER_RUNTIME = Symbol("nestjs-durable:in-app-worker-runtime");
519
+ var IN_APP_RUN_REDIS_WORKER = Symbol("nestjs-durable:in-app-run-redis-worker");
520
+ var IN_APP_WORKER_RUNNERS = Symbol("nestjs-durable:in-app-worker-runners");
521
+ function inAppWorkerBinding(transport, options) {
522
+ if (!options) return null;
523
+ if (!transport?.dispatchWorkflowTask || !transport.onDecision) {
524
+ throw new Error("inAppWorker requires a transport that carries workflow tasks (dispatchWorkflowTask + onDecision), e.g. BullMQTransport. An in-process transport cannot serve a group-served workflow.");
525
+ }
526
+ return {
527
+ group: options.group,
528
+ executor: new import_nestjs_durable_core4.RemoteWorkflowExecutor(transport, options.group)
529
+ };
530
+ }
531
+ __name(inAppWorkerBinding, "inAppWorkerBinding");
532
+ var InAppWorkerBootstrap = class {
533
+ static {
534
+ __name(this, "InAppWorkerBootstrap");
535
+ }
536
+ discovery;
537
+ metadataScanner;
538
+ options;
539
+ runtime;
540
+ runRedisWorker;
541
+ runnersSink;
542
+ runners = [];
543
+ constructor(discovery, metadataScanner, options, runtime, runRedisWorker, runnersSink) {
544
+ this.discovery = discovery;
545
+ this.metadataScanner = metadataScanner;
546
+ this.options = options;
547
+ this.runtime = runtime;
548
+ this.runRedisWorker = runRedisWorker;
549
+ this.runnersSink = runnersSink;
550
+ }
551
+ onModuleInit() {
552
+ if (!this.options) return;
553
+ scanWorkflows(this.discovery, (meta, instance) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input)));
554
+ scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
555
+ }
556
+ async onApplicationBootstrap() {
557
+ if (!this.options) return;
558
+ const handle = await this.runRedisWorker({
559
+ runtime: this.runtime,
560
+ group: this.options.group,
561
+ connection: this.options.connection,
562
+ ...this.options.prefix !== void 0 ? {
563
+ prefix: this.options.prefix
564
+ } : {},
565
+ ...this.options.instanceId !== void 0 ? {
566
+ instanceId: this.options.instanceId
567
+ } : {}
568
+ });
569
+ this.runners.push(handle);
570
+ this.runnersSink.push(handle);
571
+ }
572
+ async onApplicationShutdown() {
573
+ await Promise.allSettled(this.runners.map((handle) => handle.close()));
574
+ }
575
+ };
576
+ InAppWorkerBootstrap = _ts_decorate4([
577
+ (0, import_common4.Injectable)(),
578
+ _ts_param3(2, (0, import_common4.Inject)(IN_APP_WORKER_OPTIONS)),
579
+ _ts_param3(3, (0, import_common4.Inject)(IN_APP_WORKER_RUNTIME)),
580
+ _ts_param3(4, (0, import_common4.Inject)(IN_APP_RUN_REDIS_WORKER)),
581
+ _ts_param3(5, (0, import_common4.Inject)(IN_APP_WORKER_RUNNERS)),
582
+ _ts_metadata4("design:type", Function),
583
+ _ts_metadata4("design:paramtypes", [
584
+ typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
585
+ typeof import_core3.MetadataScanner === "undefined" ? Object : import_core3.MetadataScanner,
586
+ Object,
587
+ typeof import_durable_worker2.DurableWorkerRuntime === "undefined" ? Object : import_durable_worker2.DurableWorkerRuntime,
588
+ typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
589
+ Array
590
+ ])
591
+ ], InAppWorkerBootstrap);
592
+ function inAppWorkerProviders() {
593
+ return [
594
+ {
595
+ provide: IN_APP_WORKER_BINDING,
596
+ useFactory: /* @__PURE__ */ __name((transport, options) => inAppWorkerBinding(transport, options.inAppWorker ?? null), "useFactory"),
597
+ inject: [
598
+ import_nestjs_durable_core4.TRANSPORT_CANONICAL,
599
+ import_nestjs_durable_core4.DURABLE_OPTIONS_CANONICAL
600
+ ]
601
+ },
602
+ {
603
+ provide: IN_APP_WORKER_OPTIONS,
604
+ useFactory: /* @__PURE__ */ __name((options) => options.inAppWorker ?? null, "useFactory"),
605
+ inject: [
606
+ import_nestjs_durable_core4.DURABLE_OPTIONS_CANONICAL
607
+ ]
608
+ },
609
+ {
610
+ provide: IN_APP_WORKER_RUNTIME,
611
+ useFactory: /* @__PURE__ */ __name(() => new import_durable_worker2.DurableWorkerRuntime(), "useFactory")
612
+ },
613
+ {
614
+ provide: IN_APP_RUN_REDIS_WORKER,
615
+ useValue: import_durable_worker2.runRedisWorker
616
+ },
617
+ {
618
+ provide: IN_APP_WORKER_RUNNERS,
619
+ useValue: []
620
+ },
621
+ InAppWorkerBootstrap
622
+ ];
623
+ }
624
+ __name(inAppWorkerProviders, "inAppWorkerProviders");
625
+
626
+ // src/retention-poller.ts
627
+ var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
628
+ var import_common5 = require("@nestjs/common");
629
+ function _ts_decorate5(decorators, target, key, desc) {
630
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
631
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
632
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
633
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
634
+ }
635
+ __name(_ts_decorate5, "_ts_decorate");
636
+ function _ts_metadata5(k, v) {
637
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
638
+ }
639
+ __name(_ts_metadata5, "_ts_metadata");
640
+ function _ts_param4(paramIndex, decorator) {
641
+ return function(target, key) {
642
+ decorator(target, key, paramIndex);
643
+ };
644
+ }
645
+ __name(_ts_param4, "_ts_param");
507
646
  var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
508
647
  var DEFAULT_BATCH_SIZE = 1e3;
509
648
  var MAX_BATCHES_PER_POLICY = 100;
@@ -516,10 +655,10 @@ function validateRetention(retention) {
516
655
  if (policy.maxAge == null && policy.maxCount == null) {
517
656
  throw new Error("durable retention: each policy must set maxAge and/or maxCount");
518
657
  }
519
- if (policy.maxAge != null) (0, import_nestjs_durable_core4.parseDuration)(policy.maxAge);
658
+ if (policy.maxAge != null) (0, import_nestjs_durable_core5.parseDuration)(policy.maxAge);
520
659
  for (const status of policy.statuses) {
521
- if (!import_nestjs_durable_core4.TERMINAL_RUN_STATUSES.includes(status)) {
522
- throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core4.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
660
+ if (!import_nestjs_durable_core5.TERMINAL_RUN_STATUSES.includes(status)) {
661
+ throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core5.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
523
662
  }
524
663
  if (seen.has(status)) {
525
664
  throw new Error(`durable retention: status "${status}" appears in more than one policy; status sets must be disjoint`);
@@ -551,7 +690,7 @@ var RetentionPoller = class {
551
690
  return;
552
691
  }
553
692
  await this.sweep();
554
- const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core4.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
693
+ const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core5.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
555
694
  if (intervalMs > 0) {
556
695
  this.timer = setInterval(() => void this.sweep(), intervalMs);
557
696
  this.timer.unref?.();
@@ -580,37 +719,37 @@ var RetentionPoller = class {
580
719
  }
581
720
  }
582
721
  };
583
- RetentionPoller = _ts_decorate4([
584
- (0, import_common4.Injectable)(),
585
- _ts_param3(0, (0, import_common4.Inject)(import_nestjs_durable_core4.STATE_STORE_CANONICAL)),
586
- _ts_param3(1, (0, import_common4.Inject)(import_nestjs_durable_core4.DURABLE_OPTIONS_CANONICAL)),
587
- _ts_metadata4("design:type", Function),
588
- _ts_metadata4("design:paramtypes", [
722
+ RetentionPoller = _ts_decorate5([
723
+ (0, import_common5.Injectable)(),
724
+ _ts_param4(0, (0, import_common5.Inject)(import_nestjs_durable_core5.STATE_STORE_CANONICAL)),
725
+ _ts_param4(1, (0, import_common5.Inject)(import_nestjs_durable_core5.DURABLE_OPTIONS_CANONICAL)),
726
+ _ts_metadata5("design:type", Function),
727
+ _ts_metadata5("design:paramtypes", [
589
728
  typeof StateStore === "undefined" ? Object : StateStore,
590
729
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
591
730
  ])
592
731
  ], RetentionPoller);
593
732
 
594
733
  // src/timer-poller.ts
595
- var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
596
- var import_common5 = require("@nestjs/common");
597
- function _ts_decorate5(decorators, target, key, desc) {
734
+ var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
735
+ var import_common6 = require("@nestjs/common");
736
+ function _ts_decorate6(decorators, target, key, desc) {
598
737
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
599
738
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
600
739
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
601
740
  return c > 3 && r && Object.defineProperty(target, key, r), r;
602
741
  }
603
- __name(_ts_decorate5, "_ts_decorate");
604
- function _ts_metadata5(k, v) {
742
+ __name(_ts_decorate6, "_ts_decorate");
743
+ function _ts_metadata6(k, v) {
605
744
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
606
745
  }
607
- __name(_ts_metadata5, "_ts_metadata");
608
- function _ts_param4(paramIndex, decorator) {
746
+ __name(_ts_metadata6, "_ts_metadata");
747
+ function _ts_param5(paramIndex, decorator) {
609
748
  return function(target, key) {
610
749
  decorator(target, key, paramIndex);
611
750
  };
612
751
  }
613
- __name(_ts_param4, "_ts_param");
752
+ __name(_ts_param5, "_ts_param");
614
753
  var TimerPoller = class {
615
754
  static {
616
755
  __name(this, "TimerPoller");
@@ -648,19 +787,19 @@ var TimerPoller = class {
648
787
  await this.engine.sweepTimeouts();
649
788
  const schedules = this.options.schedules;
650
789
  if (schedules && schedules.length > 0) {
651
- await (0, import_nestjs_durable_core5.runSchedules)(this.engine, schedules, Date.now());
790
+ await (0, import_nestjs_durable_core6.runSchedules)(this.engine, schedules, Date.now());
652
791
  }
653
792
  } finally {
654
793
  this.polling = false;
655
794
  }
656
795
  }
657
796
  };
658
- TimerPoller = _ts_decorate5([
659
- (0, import_common5.Injectable)(),
660
- _ts_param4(1, (0, import_common5.Inject)(import_nestjs_durable_core5.DURABLE_OPTIONS_CANONICAL)),
661
- _ts_metadata5("design:type", Function),
662
- _ts_metadata5("design:paramtypes", [
663
- typeof import_nestjs_durable_core5.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core5.WorkflowEngine,
797
+ TimerPoller = _ts_decorate6([
798
+ (0, import_common6.Injectable)(),
799
+ _ts_param5(1, (0, import_common6.Inject)(import_nestjs_durable_core6.DURABLE_OPTIONS_CANONICAL)),
800
+ _ts_metadata6("design:type", Function),
801
+ _ts_metadata6("design:paramtypes", [
802
+ typeof import_nestjs_durable_core6.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core6.WorkflowEngine,
664
803
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
665
804
  ])
666
805
  ], TimerPoller);
@@ -669,9 +808,9 @@ TimerPoller = _ts_decorate5([
669
808
  var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
670
809
 
671
810
  // src/workflow.registrar.ts
672
- var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
673
- var import_common6 = require("@nestjs/common");
674
- var import_core3 = require("@nestjs/core");
811
+ var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
812
+ var import_common7 = require("@nestjs/common");
813
+ var import_core4 = require("@nestjs/core");
675
814
 
676
815
  // src/input-validation.ts
677
816
  function classValidatorInput(cls) {
@@ -713,23 +852,23 @@ function isStepInterceptor(target) {
713
852
  __name(isStepInterceptor, "isStepInterceptor");
714
853
 
715
854
  // src/workflow.registrar.ts
716
- function _ts_decorate6(decorators, target, key, desc) {
855
+ function _ts_decorate7(decorators, target, key, desc) {
717
856
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
718
857
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
719
858
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
720
859
  return c > 3 && r && Object.defineProperty(target, key, r), r;
721
860
  }
722
- __name(_ts_decorate6, "_ts_decorate");
723
- function _ts_metadata6(k, v) {
861
+ __name(_ts_decorate7, "_ts_decorate");
862
+ function _ts_metadata7(k, v) {
724
863
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
725
864
  }
726
- __name(_ts_metadata6, "_ts_metadata");
727
- function _ts_param5(paramIndex, decorator) {
865
+ __name(_ts_metadata7, "_ts_metadata");
866
+ function _ts_param6(paramIndex, decorator) {
728
867
  return function(target, key) {
729
868
  decorator(target, key, paramIndex);
730
869
  };
731
870
  }
732
- __name(_ts_param5, "_ts_param");
871
+ __name(_ts_param6, "_ts_param");
733
872
  var WorkflowRegistrar = class {
734
873
  static {
735
874
  __name(this, "WorkflowRegistrar");
@@ -739,12 +878,14 @@ var WorkflowRegistrar = class {
739
878
  engine;
740
879
  store;
741
880
  options;
742
- constructor(discovery, metadataScanner, engine, store, options) {
881
+ inAppWorker;
882
+ constructor(discovery, metadataScanner, engine, store, options, inAppWorker) {
743
883
  this.discovery = discovery;
744
884
  this.metadataScanner = metadataScanner;
745
885
  this.engine = engine;
746
886
  this.store = store;
747
887
  this.options = options;
888
+ this.inAppWorker = inAppWorker;
748
889
  }
749
890
  async onApplicationBootstrap() {
750
891
  if (this.options.worker === false) return;
@@ -782,11 +923,11 @@ var WorkflowRegistrar = class {
782
923
  const validateInput = meta.validateInput ?? (meta.inputSchema ? classValidatorInput(meta.inputSchema) : void 0);
783
924
  const eventBatch = meta.debounce ? {
784
925
  mode: "debounce",
785
- windowMs: (0, import_nestjs_durable_core6.parseDuration)(meta.debounce)
926
+ windowMs: (0, import_nestjs_durable_core7.parseDuration)(meta.debounce)
786
927
  } : meta.batch ? {
787
928
  mode: "batch",
788
929
  maxSize: meta.batch.maxSize,
789
- windowMs: (0, import_nestjs_durable_core6.parseDuration)(meta.batch.within)
930
+ windowMs: (0, import_nestjs_durable_core7.parseDuration)(meta.batch.within)
790
931
  } : void 0;
791
932
  const workflowCtor = workflow.constructor;
792
933
  this.engine.register(meta.name, meta.version, (ctx, input) => workflow.run(ctx, input), {
@@ -795,7 +936,14 @@ var WorkflowRegistrar = class {
795
936
  executionTimeout: meta.executionTimeout,
796
937
  validateInput,
797
938
  onEvent: getOnEvents(meta, workflowCtor),
798
- eventBatch
939
+ eventBatch,
940
+ // Uniform dispatch (opt-in): when an in-app worker is configured, register the body GROUP-SERVED
941
+ // so the engine dispatches its turns to the app's own group instead of running it inline; the
942
+ // co-located worker consumer replays the same body. Absent → the inline fast path (unchanged).
943
+ ...this.inAppWorker ? {
944
+ group: this.inAppWorker.group,
945
+ executor: this.inAppWorker.executor
946
+ } : {}
799
947
  });
800
948
  const inline = this.findDeadLetterHandler(workflow);
801
949
  if (inline && meta.deadLetterWorkflow) {
@@ -806,7 +954,7 @@ var WorkflowRegistrar = class {
806
954
  this.engine.register(dlqName, meta.version, inline);
807
955
  deadLetterByWorkflow.set(meta.name, dlqName);
808
956
  } else if (meta.deadLetterWorkflow) {
809
- deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core6.workflowName)(meta.deadLetterWorkflow));
957
+ deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core7.workflowName)(meta.deadLetterWorkflow));
810
958
  }
811
959
  });
812
960
  this.installDeadLetterRouting(deadLetterByWorkflow);
@@ -828,7 +976,7 @@ var WorkflowRegistrar = class {
828
976
  * a `dlq:<runId>` id, so re-recovery never double-dispatches.
829
977
  */
830
978
  installDeadLetterRouting(byWorkflow) {
831
- const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core6.workflowName)(this.options.deadLetterWorkflow) : void 0;
979
+ const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core7.workflowName)(this.options.deadLetterWorkflow) : void 0;
832
980
  if (byWorkflow.size === 0 && !fallback) return;
833
981
  this.engine.onDead((run) => {
834
982
  const target = byWorkflow.get(run.workflow) ?? fallback;
@@ -842,35 +990,37 @@ var WorkflowRegistrar = class {
842
990
  });
843
991
  }
844
992
  };
845
- WorkflowRegistrar = _ts_decorate6([
846
- (0, import_common6.Injectable)(),
847
- _ts_param5(3, (0, import_common6.Inject)(import_nestjs_durable_core6.STATE_STORE_CANONICAL)),
848
- _ts_param5(4, (0, import_common6.Inject)(import_nestjs_durable_core6.DURABLE_OPTIONS_CANONICAL)),
849
- _ts_metadata6("design:type", Function),
850
- _ts_metadata6("design:paramtypes", [
851
- typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
852
- typeof import_core3.MetadataScanner === "undefined" ? Object : import_core3.MetadataScanner,
853
- typeof import_nestjs_durable_core6.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core6.WorkflowEngine,
993
+ WorkflowRegistrar = _ts_decorate7([
994
+ (0, import_common7.Injectable)(),
995
+ _ts_param6(3, (0, import_common7.Inject)(import_nestjs_durable_core7.STATE_STORE_CANONICAL)),
996
+ _ts_param6(4, (0, import_common7.Inject)(import_nestjs_durable_core7.DURABLE_OPTIONS_CANONICAL)),
997
+ _ts_param6(5, (0, import_common7.Inject)(IN_APP_WORKER_BINDING)),
998
+ _ts_metadata7("design:type", Function),
999
+ _ts_metadata7("design:paramtypes", [
1000
+ typeof import_core4.DiscoveryService === "undefined" ? Object : import_core4.DiscoveryService,
1001
+ typeof import_core4.MetadataScanner === "undefined" ? Object : import_core4.MetadataScanner,
1002
+ typeof import_nestjs_durable_core7.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core7.WorkflowEngine,
854
1003
  typeof StateStore === "undefined" ? Object : StateStore,
855
- typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
1004
+ typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
1005
+ Object
856
1006
  ])
857
1007
  ], WorkflowRegistrar);
858
1008
 
859
1009
  // src/workflow.service.ts
860
1010
  var import_node_crypto = require("crypto");
861
- var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
862
- var import_common7 = require("@nestjs/common");
863
- function _ts_decorate7(decorators, target, key, desc) {
1011
+ var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
1012
+ var import_common8 = require("@nestjs/common");
1013
+ function _ts_decorate8(decorators, target, key, desc) {
864
1014
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
865
1015
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
866
1016
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
867
1017
  return c > 3 && r && Object.defineProperty(target, key, r), r;
868
1018
  }
869
- __name(_ts_decorate7, "_ts_decorate");
870
- function _ts_metadata7(k, v) {
1019
+ __name(_ts_decorate8, "_ts_decorate");
1020
+ function _ts_metadata8(k, v) {
871
1021
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
872
1022
  }
873
- __name(_ts_metadata7, "_ts_metadata");
1023
+ __name(_ts_metadata8, "_ts_metadata");
874
1024
  var WorkflowService = class {
875
1025
  static {
876
1026
  __name(this, "WorkflowService");
@@ -910,22 +1060,22 @@ var WorkflowService = class {
910
1060
  return this.engine.publishEvent(name, payload, opts);
911
1061
  }
912
1062
  };
913
- WorkflowService = _ts_decorate7([
914
- (0, import_common7.Injectable)(),
915
- _ts_metadata7("design:type", Function),
916
- _ts_metadata7("design:paramtypes", [
917
- typeof import_nestjs_durable_core7.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core7.WorkflowEngine
1063
+ WorkflowService = _ts_decorate8([
1064
+ (0, import_common8.Injectable)(),
1065
+ _ts_metadata8("design:type", Function),
1066
+ _ts_metadata8("design:paramtypes", [
1067
+ typeof import_nestjs_durable_core8.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core8.WorkflowEngine
918
1068
  ])
919
1069
  ], WorkflowService);
920
1070
 
921
1071
  // src/durable.module.ts
922
- function _ts_decorate8(decorators, target, key, desc) {
1072
+ function _ts_decorate9(decorators, target, key, desc) {
923
1073
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
924
1074
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
925
1075
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
926
1076
  return c > 3 && r && Object.defineProperty(target, key, r), r;
927
1077
  }
928
- __name(_ts_decorate8, "_ts_decorate");
1078
+ __name(_ts_decorate9, "_ts_decorate");
929
1079
  function resolveAccessor(moduleRef) {
930
1080
  try {
931
1081
  return moduleRef.get(CONTEXT_ACCESSOR, {
@@ -971,13 +1121,13 @@ var DurableModule = class _DurableModule {
971
1121
  }
972
1122
  static forRoot(options) {
973
1123
  return _DurableModule.build({
974
- provide: import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL,
1124
+ provide: import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL,
975
1125
  useValue: options
976
1126
  });
977
1127
  }
978
1128
  static forRootAsync(options) {
979
1129
  return _DurableModule.build({
980
- provide: import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL,
1130
+ provide: import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL,
981
1131
  useFactory: options.useFactory,
982
1132
  inject: options.inject ?? []
983
1133
  });
@@ -987,46 +1137,46 @@ var DurableModule = class _DurableModule {
987
1137
  module: _DurableModule,
988
1138
  global: true,
989
1139
  imports: [
990
- import_core4.DiscoveryModule
1140
+ import_core5.DiscoveryModule
991
1141
  ],
992
1142
  providers: [
993
1143
  optionsProvider,
994
1144
  {
995
- provide: import_nestjs_durable_core8.STATE_STORE_CANONICAL,
1145
+ provide: import_nestjs_durable_core9.STATE_STORE_CANONICAL,
996
1146
  useFactory: /* @__PURE__ */ __name((options) => options.store, "useFactory"),
997
1147
  inject: [
998
- import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL
1148
+ import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
999
1149
  ]
1000
1150
  },
1001
1151
  {
1002
- provide: import_nestjs_durable_core8.TRANSPORT_CANONICAL,
1152
+ provide: import_nestjs_durable_core9.TRANSPORT_CANONICAL,
1003
1153
  useFactory: /* @__PURE__ */ __name((options) => options.transport ?? null, "useFactory"),
1004
1154
  inject: [
1005
- import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL
1155
+ import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
1006
1156
  ]
1007
1157
  },
1008
1158
  // Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
1009
1159
  {
1010
- provide: import_nestjs_durable_core8.STATE_STORE,
1011
- useExisting: import_nestjs_durable_core8.STATE_STORE_CANONICAL
1160
+ provide: import_nestjs_durable_core9.STATE_STORE,
1161
+ useExisting: import_nestjs_durable_core9.STATE_STORE_CANONICAL
1012
1162
  },
1013
1163
  {
1014
- provide: import_nestjs_durable_core8.TRANSPORT,
1015
- useExisting: import_nestjs_durable_core8.TRANSPORT_CANONICAL
1164
+ provide: import_nestjs_durable_core9.TRANSPORT,
1165
+ useExisting: import_nestjs_durable_core9.TRANSPORT_CANONICAL
1016
1166
  },
1017
1167
  {
1018
- provide: import_nestjs_durable_core8.DURABLE_OPTIONS,
1019
- useExisting: import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL
1168
+ provide: import_nestjs_durable_core9.DURABLE_OPTIONS,
1169
+ useExisting: import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
1020
1170
  },
1021
1171
  {
1022
- provide: import_nestjs_durable_core8.WorkflowEngine,
1172
+ provide: import_nestjs_durable_core9.WorkflowEngine,
1023
1173
  useFactory: /* @__PURE__ */ __name(async (store, transport, opts, moduleRef) => {
1024
1174
  const primary = transport ?? opts.transports?.[0]?.transport;
1025
1175
  const accessor = resolveAccessor(moduleRef);
1026
1176
  const context = opts.context ?? (accessor ? () => carrierFromAccessor(accessor) : void 0);
1027
1177
  const runtime = accessor ? await resolveContextRuntime() : void 0;
1028
1178
  const rehydrate = runtime && ((carrier, fn) => carrier && Object.keys(carrier).length > 0 ? runtime.deserialize(carrier, fn) : fn());
1029
- const engine = new import_nestjs_durable_core8.WorkflowEngine({
1179
+ const engine = new import_nestjs_durable_core9.WorkflowEngine({
1030
1180
  store,
1031
1181
  transport: transport ?? void 0,
1032
1182
  transports: opts.transports,
@@ -1053,10 +1203,10 @@ var DurableModule = class _DurableModule {
1053
1203
  return engine;
1054
1204
  }, "useFactory"),
1055
1205
  inject: [
1056
- import_nestjs_durable_core8.STATE_STORE_CANONICAL,
1057
- import_nestjs_durable_core8.TRANSPORT_CANONICAL,
1058
- import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL,
1059
- import_core4.ModuleRef
1206
+ import_nestjs_durable_core9.STATE_STORE_CANONICAL,
1207
+ import_nestjs_durable_core9.TRANSPORT_CANONICAL,
1208
+ import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL,
1209
+ import_core5.ModuleRef
1060
1210
  ]
1061
1211
  },
1062
1212
  WorkflowService,
@@ -1064,23 +1214,26 @@ var DurableModule = class _DurableModule {
1064
1214
  WorkflowRegistrar,
1065
1215
  DurableStepRegistrar,
1066
1216
  TimerPoller,
1067
- RetentionPoller
1217
+ RetentionPoller,
1218
+ // In-app worker (uniform dispatch, opt-in): inert when `inAppWorker` is unset — the binding
1219
+ // resolves to null and the bootstrap no-ops, so a plain DurableModule is unchanged.
1220
+ ...inAppWorkerProviders()
1068
1221
  ],
1069
1222
  exports: [
1070
1223
  WorkflowService,
1071
1224
  EntityService,
1072
- import_nestjs_durable_core8.WorkflowEngine,
1073
- import_nestjs_durable_core8.STATE_STORE,
1074
- import_nestjs_durable_core8.STATE_STORE_CANONICAL,
1075
- import_nestjs_durable_core8.TRANSPORT,
1076
- import_nestjs_durable_core8.TRANSPORT_CANONICAL,
1077
- import_nestjs_durable_core8.DURABLE_OPTIONS_CANONICAL
1225
+ import_nestjs_durable_core9.WorkflowEngine,
1226
+ import_nestjs_durable_core9.STATE_STORE,
1227
+ import_nestjs_durable_core9.STATE_STORE_CANONICAL,
1228
+ import_nestjs_durable_core9.TRANSPORT,
1229
+ import_nestjs_durable_core9.TRANSPORT_CANONICAL,
1230
+ import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
1078
1231
  ]
1079
1232
  };
1080
1233
  }
1081
1234
  };
1082
- DurableModule = _ts_decorate8([
1083
- (0, import_common8.Module)({})
1235
+ DurableModule = _ts_decorate9([
1236
+ (0, import_common9.Module)({})
1084
1237
  ], DurableModule);
1085
1238
  // Annotate the CommonJS export names for ESM import in node:
1086
1239
  0 && (module.exports = {
@@ -1097,6 +1250,12 @@ DurableModule = _ts_decorate8([
1097
1250
  ENTITY_ON_METADATA,
1098
1251
  Entity,
1099
1252
  EntityService,
1253
+ IN_APP_RUN_REDIS_WORKER,
1254
+ IN_APP_WORKER_BINDING,
1255
+ IN_APP_WORKER_OPTIONS,
1256
+ IN_APP_WORKER_RUNNERS,
1257
+ IN_APP_WORKER_RUNTIME,
1258
+ InAppWorkerBootstrap,
1100
1259
  ON_EVENT_METADATA,
1101
1260
  On,
1102
1261
  OnEvent,
@@ -1114,6 +1273,7 @@ DurableModule = _ts_decorate8([
1114
1273
  getEntityMeta,
1115
1274
  getOnEvents,
1116
1275
  getWorkflowMeta,
1276
+ inAppWorkerProviders,
1117
1277
  isDeadLetterHandler,
1118
1278
  isStepInterceptor
1119
1279
  });