@dudousxd/nestjs-durable 0.19.0 → 0.21.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 +176 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +154 -46
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -293,7 +293,7 @@ DurableWorkerModule = _ts_decorate([
|
|
|
293
293
|
], DurableWorkerModule);
|
|
294
294
|
|
|
295
295
|
// src/durable.module.ts
|
|
296
|
-
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as
|
|
296
|
+
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL5, STATE_STORE, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, TRANSPORT, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL2, WorkflowEngine as WorkflowEngine5 } from "@dudousxd/nestjs-durable-core";
|
|
297
297
|
import { Module as Module2 } from "@nestjs/common";
|
|
298
298
|
import { DiscoveryModule as DiscoveryModule2, ModuleRef } from "@nestjs/core";
|
|
299
299
|
|
|
@@ -435,8 +435,8 @@ EntityService = _ts_decorate3([
|
|
|
435
435
|
])
|
|
436
436
|
], EntityService);
|
|
437
437
|
|
|
438
|
-
// src/
|
|
439
|
-
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL2,
|
|
438
|
+
// src/retention-poller.ts
|
|
439
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL2, STATE_STORE_CANONICAL, TERMINAL_RUN_STATUSES } from "@dudousxd/nestjs-durable-core";
|
|
440
440
|
import { Inject as Inject3, Injectable as Injectable4 } from "@nestjs/common";
|
|
441
441
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
442
442
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -455,6 +455,112 @@ function _ts_param3(paramIndex, decorator) {
|
|
|
455
455
|
};
|
|
456
456
|
}
|
|
457
457
|
__name(_ts_param3, "_ts_param");
|
|
458
|
+
var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
|
|
459
|
+
var DEFAULT_BATCH_SIZE = 1e3;
|
|
460
|
+
var MAX_BATCHES_PER_POLICY = 100;
|
|
461
|
+
function validateRetention(retention) {
|
|
462
|
+
const seen = /* @__PURE__ */ new Set();
|
|
463
|
+
for (const policy of retention.policies) {
|
|
464
|
+
if (policy.statuses.length === 0) {
|
|
465
|
+
throw new Error("durable retention: each policy must list at least one status");
|
|
466
|
+
}
|
|
467
|
+
if (policy.maxAgeMs == null && policy.maxCount == null) {
|
|
468
|
+
throw new Error("durable retention: each policy must set maxAgeMs and/or maxCount");
|
|
469
|
+
}
|
|
470
|
+
for (const status of policy.statuses) {
|
|
471
|
+
if (!TERMINAL_RUN_STATUSES.includes(status)) {
|
|
472
|
+
throw new Error(`durable retention: status "${status}" is not terminal; only ${TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
473
|
+
}
|
|
474
|
+
if (seen.has(status)) {
|
|
475
|
+
throw new Error(`durable retention: status "${status}" appears in more than one policy; status sets must be disjoint`);
|
|
476
|
+
}
|
|
477
|
+
seen.add(status);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
__name(validateRetention, "validateRetention");
|
|
482
|
+
var RetentionPoller = class {
|
|
483
|
+
static {
|
|
484
|
+
__name(this, "RetentionPoller");
|
|
485
|
+
}
|
|
486
|
+
store;
|
|
487
|
+
options;
|
|
488
|
+
timer;
|
|
489
|
+
sweeping = false;
|
|
490
|
+
constructor(store, options) {
|
|
491
|
+
this.store = store;
|
|
492
|
+
this.options = options;
|
|
493
|
+
}
|
|
494
|
+
async onApplicationBootstrap() {
|
|
495
|
+
if (this.options.worker === false) return;
|
|
496
|
+
const retention = this.options.retention;
|
|
497
|
+
if (!retention || retention.policies.length === 0) return;
|
|
498
|
+
validateRetention(retention);
|
|
499
|
+
if (typeof this.store.pruneTerminalRuns !== "function") {
|
|
500
|
+
console.warn("[nestjs-durable] `retention` is configured but the store adapter does not implement pruneTerminalRuns; retention is disabled.");
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
await this.sweep();
|
|
504
|
+
const intervalMs = retention.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS;
|
|
505
|
+
if (intervalMs > 0) {
|
|
506
|
+
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
507
|
+
this.timer.unref?.();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
onModuleDestroy() {
|
|
511
|
+
if (this.timer) clearInterval(this.timer);
|
|
512
|
+
}
|
|
513
|
+
async sweep() {
|
|
514
|
+
if (this.sweeping) return;
|
|
515
|
+
const retention = this.options.retention;
|
|
516
|
+
const prune = this.store.pruneTerminalRuns;
|
|
517
|
+
if (!retention || typeof prune !== "function") return;
|
|
518
|
+
this.sweeping = true;
|
|
519
|
+
try {
|
|
520
|
+
const batchSize = retention.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
521
|
+
const now = Date.now();
|
|
522
|
+
for (const policy of retention.policies) {
|
|
523
|
+
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
524
|
+
const deleted = await prune.call(this.store, policy, now, batchSize);
|
|
525
|
+
if (deleted < batchSize) break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
} finally {
|
|
529
|
+
this.sweeping = false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
RetentionPoller = _ts_decorate4([
|
|
534
|
+
Injectable4(),
|
|
535
|
+
_ts_param3(0, Inject3(STATE_STORE_CANONICAL)),
|
|
536
|
+
_ts_param3(1, Inject3(DURABLE_OPTIONS_CANONICAL2)),
|
|
537
|
+
_ts_metadata4("design:type", Function),
|
|
538
|
+
_ts_metadata4("design:paramtypes", [
|
|
539
|
+
typeof StateStore === "undefined" ? Object : StateStore,
|
|
540
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
541
|
+
])
|
|
542
|
+
], RetentionPoller);
|
|
543
|
+
|
|
544
|
+
// src/timer-poller.ts
|
|
545
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL3, WorkflowEngine as WorkflowEngine2, runSchedules } from "@dudousxd/nestjs-durable-core";
|
|
546
|
+
import { Inject as Inject4, Injectable as Injectable5 } from "@nestjs/common";
|
|
547
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
548
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
549
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
550
|
+
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;
|
|
551
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
552
|
+
}
|
|
553
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
554
|
+
function _ts_metadata5(k, v) {
|
|
555
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
556
|
+
}
|
|
557
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
558
|
+
function _ts_param4(paramIndex, decorator) {
|
|
559
|
+
return function(target, key) {
|
|
560
|
+
decorator(target, key, paramIndex);
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
__name(_ts_param4, "_ts_param");
|
|
458
564
|
var TimerPoller = class {
|
|
459
565
|
static {
|
|
460
566
|
__name(this, "TimerPoller");
|
|
@@ -499,11 +605,11 @@ var TimerPoller = class {
|
|
|
499
605
|
}
|
|
500
606
|
}
|
|
501
607
|
};
|
|
502
|
-
TimerPoller =
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
608
|
+
TimerPoller = _ts_decorate5([
|
|
609
|
+
Injectable5(),
|
|
610
|
+
_ts_param4(1, Inject4(DURABLE_OPTIONS_CANONICAL3)),
|
|
611
|
+
_ts_metadata5("design:type", Function),
|
|
612
|
+
_ts_metadata5("design:paramtypes", [
|
|
507
613
|
typeof WorkflowEngine2 === "undefined" ? Object : WorkflowEngine2,
|
|
508
614
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
509
615
|
])
|
|
@@ -513,8 +619,8 @@ TimerPoller = _ts_decorate4([
|
|
|
513
619
|
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
514
620
|
|
|
515
621
|
// src/workflow.registrar.ts
|
|
516
|
-
import { DURABLE_OPTIONS_CANONICAL as
|
|
517
|
-
import { Inject as
|
|
622
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL4, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL2, WorkflowEngine as WorkflowEngine3, parseDuration, workflowName } from "@dudousxd/nestjs-durable-core";
|
|
623
|
+
import { Inject as Inject5, Injectable as Injectable6 } from "@nestjs/common";
|
|
518
624
|
import { DiscoveryService as DiscoveryService3, MetadataScanner as MetadataScanner3 } from "@nestjs/core";
|
|
519
625
|
|
|
520
626
|
// src/input-validation.ts
|
|
@@ -557,23 +663,23 @@ function isStepInterceptor(target) {
|
|
|
557
663
|
__name(isStepInterceptor, "isStepInterceptor");
|
|
558
664
|
|
|
559
665
|
// src/workflow.registrar.ts
|
|
560
|
-
function
|
|
666
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
561
667
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
562
668
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
563
669
|
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;
|
|
564
670
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
565
671
|
}
|
|
566
|
-
__name(
|
|
567
|
-
function
|
|
672
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
673
|
+
function _ts_metadata6(k, v) {
|
|
568
674
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
569
675
|
}
|
|
570
|
-
__name(
|
|
571
|
-
function
|
|
676
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
677
|
+
function _ts_param5(paramIndex, decorator) {
|
|
572
678
|
return function(target, key) {
|
|
573
679
|
decorator(target, key, paramIndex);
|
|
574
680
|
};
|
|
575
681
|
}
|
|
576
|
-
__name(
|
|
682
|
+
__name(_ts_param5, "_ts_param");
|
|
577
683
|
var WorkflowRegistrar = class {
|
|
578
684
|
static {
|
|
579
685
|
__name(this, "WorkflowRegistrar");
|
|
@@ -686,12 +792,12 @@ var WorkflowRegistrar = class {
|
|
|
686
792
|
});
|
|
687
793
|
}
|
|
688
794
|
};
|
|
689
|
-
WorkflowRegistrar =
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
795
|
+
WorkflowRegistrar = _ts_decorate6([
|
|
796
|
+
Injectable6(),
|
|
797
|
+
_ts_param5(3, Inject5(STATE_STORE_CANONICAL2)),
|
|
798
|
+
_ts_param5(4, Inject5(DURABLE_OPTIONS_CANONICAL4)),
|
|
799
|
+
_ts_metadata6("design:type", Function),
|
|
800
|
+
_ts_metadata6("design:paramtypes", [
|
|
695
801
|
typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
|
|
696
802
|
typeof MetadataScanner3 === "undefined" ? Object : MetadataScanner3,
|
|
697
803
|
typeof WorkflowEngine3 === "undefined" ? Object : WorkflowEngine3,
|
|
@@ -703,18 +809,18 @@ WorkflowRegistrar = _ts_decorate5([
|
|
|
703
809
|
// src/workflow.service.ts
|
|
704
810
|
import { randomUUID } from "node:crypto";
|
|
705
811
|
import { WorkflowEngine as WorkflowEngine4 } from "@dudousxd/nestjs-durable-core";
|
|
706
|
-
import { Injectable as
|
|
707
|
-
function
|
|
812
|
+
import { Injectable as Injectable7 } from "@nestjs/common";
|
|
813
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
708
814
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
709
815
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
710
816
|
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;
|
|
711
817
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
712
818
|
}
|
|
713
|
-
__name(
|
|
714
|
-
function
|
|
819
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
820
|
+
function _ts_metadata7(k, v) {
|
|
715
821
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
716
822
|
}
|
|
717
|
-
__name(
|
|
823
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
718
824
|
var WorkflowService = class {
|
|
719
825
|
static {
|
|
720
826
|
__name(this, "WorkflowService");
|
|
@@ -754,22 +860,22 @@ var WorkflowService = class {
|
|
|
754
860
|
return this.engine.publishEvent(name, payload, opts);
|
|
755
861
|
}
|
|
756
862
|
};
|
|
757
|
-
WorkflowService =
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
863
|
+
WorkflowService = _ts_decorate7([
|
|
864
|
+
Injectable7(),
|
|
865
|
+
_ts_metadata7("design:type", Function),
|
|
866
|
+
_ts_metadata7("design:paramtypes", [
|
|
761
867
|
typeof WorkflowEngine4 === "undefined" ? Object : WorkflowEngine4
|
|
762
868
|
])
|
|
763
869
|
], WorkflowService);
|
|
764
870
|
|
|
765
871
|
// src/durable.module.ts
|
|
766
|
-
function
|
|
872
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
767
873
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
768
874
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
769
875
|
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;
|
|
770
876
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
771
877
|
}
|
|
772
|
-
__name(
|
|
878
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
773
879
|
function resolveAccessor(moduleRef) {
|
|
774
880
|
try {
|
|
775
881
|
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
@@ -815,13 +921,13 @@ var DurableModule = class _DurableModule {
|
|
|
815
921
|
}
|
|
816
922
|
static forRoot(options) {
|
|
817
923
|
return _DurableModule.build({
|
|
818
|
-
provide:
|
|
924
|
+
provide: DURABLE_OPTIONS_CANONICAL5,
|
|
819
925
|
useValue: options
|
|
820
926
|
});
|
|
821
927
|
}
|
|
822
928
|
static forRootAsync(options) {
|
|
823
929
|
return _DurableModule.build({
|
|
824
|
-
provide:
|
|
930
|
+
provide: DURABLE_OPTIONS_CANONICAL5,
|
|
825
931
|
useFactory: options.useFactory,
|
|
826
932
|
inject: options.inject ?? []
|
|
827
933
|
});
|
|
@@ -836,23 +942,23 @@ var DurableModule = class _DurableModule {
|
|
|
836
942
|
providers: [
|
|
837
943
|
optionsProvider,
|
|
838
944
|
{
|
|
839
|
-
provide:
|
|
945
|
+
provide: STATE_STORE_CANONICAL3,
|
|
840
946
|
useFactory: /* @__PURE__ */ __name((options) => options.store, "useFactory"),
|
|
841
947
|
inject: [
|
|
842
|
-
|
|
948
|
+
DURABLE_OPTIONS_CANONICAL5
|
|
843
949
|
]
|
|
844
950
|
},
|
|
845
951
|
{
|
|
846
952
|
provide: TRANSPORT_CANONICAL2,
|
|
847
953
|
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? null, "useFactory"),
|
|
848
954
|
inject: [
|
|
849
|
-
|
|
955
|
+
DURABLE_OPTIONS_CANONICAL5
|
|
850
956
|
]
|
|
851
957
|
},
|
|
852
958
|
// Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
|
|
853
959
|
{
|
|
854
960
|
provide: STATE_STORE,
|
|
855
|
-
useExisting:
|
|
961
|
+
useExisting: STATE_STORE_CANONICAL3
|
|
856
962
|
},
|
|
857
963
|
{
|
|
858
964
|
provide: TRANSPORT,
|
|
@@ -860,7 +966,7 @@ var DurableModule = class _DurableModule {
|
|
|
860
966
|
},
|
|
861
967
|
{
|
|
862
968
|
provide: DURABLE_OPTIONS,
|
|
863
|
-
useExisting:
|
|
969
|
+
useExisting: DURABLE_OPTIONS_CANONICAL5
|
|
864
970
|
},
|
|
865
971
|
{
|
|
866
972
|
provide: WorkflowEngine5,
|
|
@@ -878,6 +984,7 @@ var DurableModule = class _DurableModule {
|
|
|
878
984
|
leaseMs: opts.leaseMs,
|
|
879
985
|
admission: opts.admission,
|
|
880
986
|
maxRecoveryAttempts: opts.maxRecoveryAttempts,
|
|
987
|
+
remoteAdvanceSilenceMs: opts.remoteAdvanceSilenceMs,
|
|
881
988
|
instanceId: opts.instanceId,
|
|
882
989
|
webhookUrl: opts.webhookUrl,
|
|
883
990
|
traceparent: opts.traceparent,
|
|
@@ -896,9 +1003,9 @@ var DurableModule = class _DurableModule {
|
|
|
896
1003
|
return engine;
|
|
897
1004
|
}, "useFactory"),
|
|
898
1005
|
inject: [
|
|
899
|
-
|
|
1006
|
+
STATE_STORE_CANONICAL3,
|
|
900
1007
|
TRANSPORT_CANONICAL2,
|
|
901
|
-
|
|
1008
|
+
DURABLE_OPTIONS_CANONICAL5,
|
|
902
1009
|
ModuleRef
|
|
903
1010
|
]
|
|
904
1011
|
},
|
|
@@ -906,22 +1013,23 @@ var DurableModule = class _DurableModule {
|
|
|
906
1013
|
EntityService,
|
|
907
1014
|
WorkflowRegistrar,
|
|
908
1015
|
DurableStepRegistrar,
|
|
909
|
-
TimerPoller
|
|
1016
|
+
TimerPoller,
|
|
1017
|
+
RetentionPoller
|
|
910
1018
|
],
|
|
911
1019
|
exports: [
|
|
912
1020
|
WorkflowService,
|
|
913
1021
|
EntityService,
|
|
914
1022
|
WorkflowEngine5,
|
|
915
1023
|
STATE_STORE,
|
|
916
|
-
|
|
1024
|
+
STATE_STORE_CANONICAL3,
|
|
917
1025
|
TRANSPORT,
|
|
918
1026
|
TRANSPORT_CANONICAL2,
|
|
919
|
-
|
|
1027
|
+
DURABLE_OPTIONS_CANONICAL5
|
|
920
1028
|
]
|
|
921
1029
|
};
|
|
922
1030
|
}
|
|
923
1031
|
};
|
|
924
|
-
DurableModule =
|
|
1032
|
+
DurableModule = _ts_decorate8([
|
|
925
1033
|
Module2({})
|
|
926
1034
|
], DurableModule);
|
|
927
1035
|
export {
|