@dudousxd/nestjs-durable 0.0.0-beta-20260701163515
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/LICENSE +21 -0
- package/dist/index.cjs +1345 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +718 -0
- package/dist/index.d.ts +718 -0
- package/dist/index.js +1286 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
- package/skills/durable-determinism/SKILL.md +144 -0
- package/skills/durable-setup/SKILL.md +189 -0
- package/skills/durable-signals-and-timers/SKILL.md +181 -0
- package/skills/durable-testing/SKILL.md +146 -0
- package/skills/durable-workflows/SKILL.md +183 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1286 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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
|
+
|
|
10
|
+
// src/decorators.ts
|
|
11
|
+
import { WORKFLOW_NAME_KEY } from "@dudousxd/nestjs-durable-core";
|
|
12
|
+
import "reflect-metadata";
|
|
13
|
+
var WORKFLOW_METADATA = Symbol("nestjs-durable:workflow");
|
|
14
|
+
function Workflow(options) {
|
|
15
|
+
return (target) => {
|
|
16
|
+
const meta = {
|
|
17
|
+
name: options.name,
|
|
18
|
+
version: options.version ?? "1",
|
|
19
|
+
deadLetterWorkflow: options.deadLetterWorkflow,
|
|
20
|
+
tags: options.tags,
|
|
21
|
+
singleton: options.singleton,
|
|
22
|
+
executionTimeout: options.executionTimeout,
|
|
23
|
+
inputSchema: options.inputSchema,
|
|
24
|
+
validateInput: options.validateInput,
|
|
25
|
+
onEvent: options.onEvent,
|
|
26
|
+
debounce: options.debounce,
|
|
27
|
+
batch: options.batch
|
|
28
|
+
};
|
|
29
|
+
Reflect.defineMetadata(WORKFLOW_METADATA, meta, target);
|
|
30
|
+
Object.defineProperty(target, WORKFLOW_NAME_KEY, {
|
|
31
|
+
value: options.name,
|
|
32
|
+
configurable: true
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
__name(Workflow, "Workflow");
|
|
37
|
+
function getWorkflowMeta(target) {
|
|
38
|
+
return Reflect.getMetadata(WORKFLOW_METADATA, target);
|
|
39
|
+
}
|
|
40
|
+
__name(getWorkflowMeta, "getWorkflowMeta");
|
|
41
|
+
var DURABLE_STEP_METADATA = Symbol("nestjs-durable:step-handler");
|
|
42
|
+
function Step(name) {
|
|
43
|
+
return (_target, _propertyKey, descriptor) => {
|
|
44
|
+
const meta = {
|
|
45
|
+
name
|
|
46
|
+
};
|
|
47
|
+
Reflect.defineMetadata(DURABLE_STEP_METADATA, meta, descriptor.value);
|
|
48
|
+
return descriptor;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
__name(Step, "Step");
|
|
52
|
+
var DurableStep = Step;
|
|
53
|
+
function getDurableStepMeta(method) {
|
|
54
|
+
return Reflect.getMetadata(DURABLE_STEP_METADATA, method);
|
|
55
|
+
}
|
|
56
|
+
__name(getDurableStepMeta, "getDurableStepMeta");
|
|
57
|
+
var DEAD_LETTER_METADATA = Symbol("nestjs-durable:dead-letter");
|
|
58
|
+
function DeadLetter() {
|
|
59
|
+
return (_target, _propertyKey, descriptor) => {
|
|
60
|
+
Reflect.defineMetadata(DEAD_LETTER_METADATA, true, descriptor.value);
|
|
61
|
+
return descriptor;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
__name(DeadLetter, "DeadLetter");
|
|
65
|
+
function isDeadLetterHandler(method) {
|
|
66
|
+
return Reflect.getMetadata(DEAD_LETTER_METADATA, method) === true;
|
|
67
|
+
}
|
|
68
|
+
__name(isDeadLetterHandler, "isDeadLetterHandler");
|
|
69
|
+
var ON_EVENT_METADATA = Symbol("nestjs-durable:on-event");
|
|
70
|
+
function OnEvent(...events) {
|
|
71
|
+
return (target) => {
|
|
72
|
+
const existing = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
73
|
+
Reflect.defineMetadata(ON_EVENT_METADATA, [
|
|
74
|
+
...existing,
|
|
75
|
+
...events
|
|
76
|
+
], target);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
__name(OnEvent, "OnEvent");
|
|
80
|
+
function getOnEvents(meta, target) {
|
|
81
|
+
const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
82
|
+
return [
|
|
83
|
+
.../* @__PURE__ */ new Set([
|
|
84
|
+
...meta.onEvent ?? [],
|
|
85
|
+
...fromDecorator
|
|
86
|
+
])
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
__name(getOnEvents, "getOnEvents");
|
|
90
|
+
|
|
91
|
+
// src/durable-worker.module.ts
|
|
92
|
+
import { DurableWorkerRuntime, runRedisWorker as defaultRunRedisWorker } from "@dudousxd/durable-worker";
|
|
93
|
+
import { tenantGroup } from "@dudousxd/nestjs-durable-core";
|
|
94
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
95
|
+
import { DiscoveryModule, DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
96
|
+
|
|
97
|
+
// src/discovery-helpers.ts
|
|
98
|
+
function scanWorkflows(discovery, register) {
|
|
99
|
+
for (const wrapper of discovery.getProviders()) {
|
|
100
|
+
const { instance } = wrapper;
|
|
101
|
+
if (!instance || typeof instance !== "object") continue;
|
|
102
|
+
const meta = getWorkflowMeta(instance.constructor);
|
|
103
|
+
if (!meta) continue;
|
|
104
|
+
const workflow = instance;
|
|
105
|
+
if (typeof workflow.run !== "function") {
|
|
106
|
+
throw new Error(`@Workflow ${meta.name} must define a run(ctx, input) method`);
|
|
107
|
+
}
|
|
108
|
+
register(meta, workflow);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
__name(scanWorkflows, "scanWorkflows");
|
|
112
|
+
function scanSteps(discovery, scanner, register) {
|
|
113
|
+
for (const wrapper of discovery.getProviders()) {
|
|
114
|
+
const { instance } = wrapper;
|
|
115
|
+
if (!instance || typeof instance !== "object") continue;
|
|
116
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
117
|
+
for (const methodName of scanner.getAllMethodNames(prototype)) {
|
|
118
|
+
const method = instance[methodName];
|
|
119
|
+
if (typeof method !== "function") continue;
|
|
120
|
+
const meta = getDurableStepMeta(method);
|
|
121
|
+
if (!meta) continue;
|
|
122
|
+
const handler = /* @__PURE__ */ __name((input, log) => method.call(instance, input, log), "handler");
|
|
123
|
+
register(meta, handler);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
__name(scanSteps, "scanSteps");
|
|
128
|
+
|
|
129
|
+
// src/durable-worker.module.ts
|
|
130
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
131
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
132
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
133
|
+
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;
|
|
134
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
135
|
+
}
|
|
136
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
137
|
+
function _ts_metadata(k, v) {
|
|
138
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
139
|
+
}
|
|
140
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
141
|
+
function _ts_param(paramIndex, decorator) {
|
|
142
|
+
return function(target, key) {
|
|
143
|
+
decorator(target, key, paramIndex);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
__name(_ts_param, "_ts_param");
|
|
147
|
+
var DURABLE_WORKER_OPTIONS = Symbol("nestjs-durable:worker-options");
|
|
148
|
+
var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
|
|
149
|
+
var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
|
|
150
|
+
var ThinWorkflowRegistrar = class {
|
|
151
|
+
static {
|
|
152
|
+
__name(this, "ThinWorkflowRegistrar");
|
|
153
|
+
}
|
|
154
|
+
discovery;
|
|
155
|
+
runtime;
|
|
156
|
+
constructor(discovery, runtime) {
|
|
157
|
+
this.discovery = discovery;
|
|
158
|
+
this.runtime = runtime;
|
|
159
|
+
}
|
|
160
|
+
onModuleInit() {
|
|
161
|
+
scanWorkflows(this.discovery, (meta, instance) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input)));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
ThinWorkflowRegistrar = _ts_decorate([
|
|
165
|
+
Injectable(),
|
|
166
|
+
_ts_metadata("design:type", Function),
|
|
167
|
+
_ts_metadata("design:paramtypes", [
|
|
168
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
169
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime
|
|
170
|
+
])
|
|
171
|
+
], ThinWorkflowRegistrar);
|
|
172
|
+
var ThinStepRegistrar = class {
|
|
173
|
+
static {
|
|
174
|
+
__name(this, "ThinStepRegistrar");
|
|
175
|
+
}
|
|
176
|
+
discovery;
|
|
177
|
+
metadataScanner;
|
|
178
|
+
runtime;
|
|
179
|
+
constructor(discovery, metadataScanner, runtime) {
|
|
180
|
+
this.discovery = discovery;
|
|
181
|
+
this.metadataScanner = metadataScanner;
|
|
182
|
+
this.runtime = runtime;
|
|
183
|
+
}
|
|
184
|
+
onModuleInit() {
|
|
185
|
+
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
ThinStepRegistrar = _ts_decorate([
|
|
189
|
+
Injectable(),
|
|
190
|
+
_ts_metadata("design:type", Function),
|
|
191
|
+
_ts_metadata("design:paramtypes", [
|
|
192
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
193
|
+
typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
|
|
194
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime
|
|
195
|
+
])
|
|
196
|
+
], ThinStepRegistrar);
|
|
197
|
+
var ThinWorkerBootstrap = class {
|
|
198
|
+
static {
|
|
199
|
+
__name(this, "ThinWorkerBootstrap");
|
|
200
|
+
}
|
|
201
|
+
runtime;
|
|
202
|
+
options;
|
|
203
|
+
runRedisWorker;
|
|
204
|
+
runnersSink;
|
|
205
|
+
runners = [];
|
|
206
|
+
constructor(runtime, options, runRedisWorker, runnersSink) {
|
|
207
|
+
this.runtime = runtime;
|
|
208
|
+
this.options = options;
|
|
209
|
+
this.runRedisWorker = runRedisWorker;
|
|
210
|
+
this.runnersSink = runnersSink;
|
|
211
|
+
}
|
|
212
|
+
async onApplicationBootstrap() {
|
|
213
|
+
for (const group of this.options.groups) {
|
|
214
|
+
const handle = await this.runRedisWorker({
|
|
215
|
+
runtime: this.runtime,
|
|
216
|
+
group: tenantGroup(group, this.options.tenant),
|
|
217
|
+
connection: this.options.connection,
|
|
218
|
+
...this.options.prefix !== void 0 ? {
|
|
219
|
+
prefix: this.options.prefix
|
|
220
|
+
} : {},
|
|
221
|
+
...this.options.instanceId !== void 0 ? {
|
|
222
|
+
instanceId: this.options.instanceId
|
|
223
|
+
} : {},
|
|
224
|
+
...(this.options.concurrencyByGroup?.[group] ?? this.options.concurrency) !== void 0 ? {
|
|
225
|
+
concurrency: this.options.concurrencyByGroup?.[group] ?? this.options.concurrency
|
|
226
|
+
} : {}
|
|
227
|
+
});
|
|
228
|
+
this.runners.push(handle);
|
|
229
|
+
this.runnersSink.push(handle);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async onApplicationShutdown() {
|
|
233
|
+
await Promise.allSettled(this.runners.map((h) => h.close()));
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
ThinWorkerBootstrap = _ts_decorate([
|
|
237
|
+
Injectable(),
|
|
238
|
+
_ts_param(1, Inject(DURABLE_WORKER_OPTIONS)),
|
|
239
|
+
_ts_param(2, Inject(RUN_REDIS_WORKER)),
|
|
240
|
+
_ts_param(3, Inject(DURABLE_WORKER_RUNNERS)),
|
|
241
|
+
_ts_metadata("design:type", Function),
|
|
242
|
+
_ts_metadata("design:paramtypes", [
|
|
243
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime,
|
|
244
|
+
typeof DurableWorkerModuleOptions === "undefined" ? Object : DurableWorkerModuleOptions,
|
|
245
|
+
typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
|
|
246
|
+
Array
|
|
247
|
+
])
|
|
248
|
+
], ThinWorkerBootstrap);
|
|
249
|
+
var DurableWorkerModule = class _DurableWorkerModule {
|
|
250
|
+
static {
|
|
251
|
+
__name(this, "DurableWorkerModule");
|
|
252
|
+
}
|
|
253
|
+
static forRoot(options) {
|
|
254
|
+
return _DurableWorkerModule.build({
|
|
255
|
+
provide: DURABLE_WORKER_OPTIONS,
|
|
256
|
+
useValue: options
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
static forRootAsync(options) {
|
|
260
|
+
return _DurableWorkerModule.build({
|
|
261
|
+
provide: DURABLE_WORKER_OPTIONS,
|
|
262
|
+
useFactory: options.useFactory,
|
|
263
|
+
inject: options.inject ?? []
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
static build(optionsProvider) {
|
|
267
|
+
return {
|
|
268
|
+
module: _DurableWorkerModule,
|
|
269
|
+
imports: [
|
|
270
|
+
DiscoveryModule
|
|
271
|
+
],
|
|
272
|
+
providers: [
|
|
273
|
+
optionsProvider,
|
|
274
|
+
{
|
|
275
|
+
provide: DurableWorkerRuntime,
|
|
276
|
+
useFactory: /* @__PURE__ */ __name(() => new DurableWorkerRuntime(), "useFactory")
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
provide: RUN_REDIS_WORKER,
|
|
280
|
+
useValue: defaultRunRedisWorker
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
provide: DURABLE_WORKER_RUNNERS,
|
|
284
|
+
useValue: []
|
|
285
|
+
},
|
|
286
|
+
ThinWorkflowRegistrar,
|
|
287
|
+
ThinStepRegistrar,
|
|
288
|
+
ThinWorkerBootstrap
|
|
289
|
+
],
|
|
290
|
+
exports: [
|
|
291
|
+
DurableWorkerRuntime
|
|
292
|
+
]
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
DurableWorkerModule = _ts_decorate([
|
|
297
|
+
Module({})
|
|
298
|
+
], DurableWorkerModule);
|
|
299
|
+
|
|
300
|
+
// src/durable.module.ts
|
|
301
|
+
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, STATE_STORE, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, TRANSPORT, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL3, WorkflowEngine as WorkflowEngine5 } from "@dudousxd/nestjs-durable-core";
|
|
302
|
+
import { Module as Module2 } from "@nestjs/common";
|
|
303
|
+
import { DiscoveryModule as DiscoveryModule2, ModuleRef } from "@nestjs/core";
|
|
304
|
+
|
|
305
|
+
// src/durable-step.registrar.ts
|
|
306
|
+
import { DURABLE_OPTIONS_CANONICAL, TRANSPORT_CANONICAL } from "@dudousxd/nestjs-durable-core";
|
|
307
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
308
|
+
import { DiscoveryService as DiscoveryService2, MetadataScanner as MetadataScanner2 } from "@nestjs/core";
|
|
309
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
310
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
311
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
312
|
+
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;
|
|
313
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
314
|
+
}
|
|
315
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
316
|
+
function _ts_metadata2(k, v) {
|
|
317
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
318
|
+
}
|
|
319
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
320
|
+
function _ts_param2(paramIndex, decorator) {
|
|
321
|
+
return function(target, key) {
|
|
322
|
+
decorator(target, key, paramIndex);
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
__name(_ts_param2, "_ts_param");
|
|
326
|
+
function supportsHandle(transport) {
|
|
327
|
+
return typeof transport?.handle === "function";
|
|
328
|
+
}
|
|
329
|
+
__name(supportsHandle, "supportsHandle");
|
|
330
|
+
var DurableStepRegistrar = class {
|
|
331
|
+
static {
|
|
332
|
+
__name(this, "DurableStepRegistrar");
|
|
333
|
+
}
|
|
334
|
+
discovery;
|
|
335
|
+
metadataScanner;
|
|
336
|
+
transport;
|
|
337
|
+
options;
|
|
338
|
+
constructor(discovery, metadataScanner, transport, options) {
|
|
339
|
+
this.discovery = discovery;
|
|
340
|
+
this.metadataScanner = metadataScanner;
|
|
341
|
+
this.transport = transport;
|
|
342
|
+
this.options = options;
|
|
343
|
+
}
|
|
344
|
+
onModuleInit() {
|
|
345
|
+
if (this.options.worker === false) return;
|
|
346
|
+
if (!supportsHandle(this.transport)) return;
|
|
347
|
+
const transport = this.transport;
|
|
348
|
+
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler));
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
DurableStepRegistrar = _ts_decorate2([
|
|
352
|
+
Injectable2(),
|
|
353
|
+
_ts_param2(2, Inject2(TRANSPORT_CANONICAL)),
|
|
354
|
+
_ts_param2(3, Inject2(DURABLE_OPTIONS_CANONICAL)),
|
|
355
|
+
_ts_metadata2("design:type", Function),
|
|
356
|
+
_ts_metadata2("design:paramtypes", [
|
|
357
|
+
typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
|
|
358
|
+
typeof MetadataScanner2 === "undefined" ? Object : MetadataScanner2,
|
|
359
|
+
Object,
|
|
360
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
361
|
+
])
|
|
362
|
+
], DurableStepRegistrar);
|
|
363
|
+
|
|
364
|
+
// src/entity.ts
|
|
365
|
+
import { WorkflowEngine } from "@dudousxd/nestjs-durable-core";
|
|
366
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
367
|
+
import "reflect-metadata";
|
|
368
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
369
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
370
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
371
|
+
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;
|
|
372
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
373
|
+
}
|
|
374
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
375
|
+
function _ts_metadata3(k, v) {
|
|
376
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
377
|
+
}
|
|
378
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
379
|
+
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
380
|
+
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
381
|
+
function Entity(options) {
|
|
382
|
+
return (target) => {
|
|
383
|
+
Reflect.defineMetadata(ENTITY_METADATA, options, target);
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
__name(Entity, "Entity");
|
|
387
|
+
function On(op) {
|
|
388
|
+
return (target, propertyKey) => {
|
|
389
|
+
const ctor = target.constructor;
|
|
390
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
391
|
+
ops.set(op, propertyKey);
|
|
392
|
+
Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
__name(On, "On");
|
|
396
|
+
function getEntityMeta(target) {
|
|
397
|
+
return Reflect.getMetadata(ENTITY_METADATA, target);
|
|
398
|
+
}
|
|
399
|
+
__name(getEntityMeta, "getEntityMeta");
|
|
400
|
+
function entityConfigFor(ctor) {
|
|
401
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
402
|
+
const Cls = ctor;
|
|
403
|
+
const handlers = {};
|
|
404
|
+
for (const [op, method] of ops) {
|
|
405
|
+
handlers[op] = (state, arg) => {
|
|
406
|
+
Object.setPrototypeOf(state, Cls.prototype);
|
|
407
|
+
const fn = state[method];
|
|
408
|
+
if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
|
|
409
|
+
return fn.call(state, arg);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
|
|
414
|
+
handlers
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
__name(entityConfigFor, "entityConfigFor");
|
|
418
|
+
var EntityService = class {
|
|
419
|
+
static {
|
|
420
|
+
__name(this, "EntityService");
|
|
421
|
+
}
|
|
422
|
+
engine;
|
|
423
|
+
constructor(engine) {
|
|
424
|
+
this.engine = engine;
|
|
425
|
+
}
|
|
426
|
+
/** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
|
|
427
|
+
signal(name, key, op, arg) {
|
|
428
|
+
return this.engine.signalEntity(name, key, op, arg);
|
|
429
|
+
}
|
|
430
|
+
/** Read an entity's current durable state (or undefined if it has none yet). */
|
|
431
|
+
getState(name, key) {
|
|
432
|
+
return this.engine.getEntityState(name, key);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
EntityService = _ts_decorate3([
|
|
436
|
+
Injectable3(),
|
|
437
|
+
_ts_metadata3("design:type", Function),
|
|
438
|
+
_ts_metadata3("design:paramtypes", [
|
|
439
|
+
typeof WorkflowEngine === "undefined" ? Object : WorkflowEngine
|
|
440
|
+
])
|
|
441
|
+
], EntityService);
|
|
442
|
+
|
|
443
|
+
// src/in-app-worker.ts
|
|
444
|
+
import { DurableWorkerRuntime as DurableWorkerRuntime2, runRedisWorker as defaultRunRedisWorker2 } from "@dudousxd/durable-worker";
|
|
445
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL2, RemoteWorkflowExecutor, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL2 } from "@dudousxd/nestjs-durable-core";
|
|
446
|
+
import { Inject as Inject3, Injectable as Injectable4 } from "@nestjs/common";
|
|
447
|
+
import { DiscoveryService as DiscoveryService3, MetadataScanner as MetadataScanner3 } from "@nestjs/core";
|
|
448
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
449
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
450
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
451
|
+
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;
|
|
452
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
453
|
+
}
|
|
454
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
455
|
+
function _ts_metadata4(k, v) {
|
|
456
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
457
|
+
}
|
|
458
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
459
|
+
function _ts_param3(paramIndex, decorator) {
|
|
460
|
+
return function(target, key) {
|
|
461
|
+
decorator(target, key, paramIndex);
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
__name(_ts_param3, "_ts_param");
|
|
465
|
+
var IN_APP_WORKER_OPTIONS = Symbol("nestjs-durable:in-app-worker-options");
|
|
466
|
+
var IN_APP_WORKER_BINDING = Symbol("nestjs-durable:in-app-worker-binding");
|
|
467
|
+
var IN_APP_WORKER_RUNTIME = Symbol("nestjs-durable:in-app-worker-runtime");
|
|
468
|
+
var IN_APP_RUN_REDIS_WORKER = Symbol("nestjs-durable:in-app-run-redis-worker");
|
|
469
|
+
var IN_APP_WORKER_RUNNERS = Symbol("nestjs-durable:in-app-worker-runners");
|
|
470
|
+
function inAppWorkerBinding(transport, options) {
|
|
471
|
+
if (!options) return null;
|
|
472
|
+
if (!transport?.dispatchWorkflowTask || !transport.onDecision) {
|
|
473
|
+
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.");
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
group: options.group,
|
|
477
|
+
executor: new RemoteWorkflowExecutor(transport, options.group)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
__name(inAppWorkerBinding, "inAppWorkerBinding");
|
|
481
|
+
var InAppWorkerBootstrap = class {
|
|
482
|
+
static {
|
|
483
|
+
__name(this, "InAppWorkerBootstrap");
|
|
484
|
+
}
|
|
485
|
+
discovery;
|
|
486
|
+
metadataScanner;
|
|
487
|
+
options;
|
|
488
|
+
runtime;
|
|
489
|
+
runRedisWorker;
|
|
490
|
+
runnersSink;
|
|
491
|
+
runners = [];
|
|
492
|
+
constructor(discovery, metadataScanner, options, runtime, runRedisWorker, runnersSink) {
|
|
493
|
+
this.discovery = discovery;
|
|
494
|
+
this.metadataScanner = metadataScanner;
|
|
495
|
+
this.options = options;
|
|
496
|
+
this.runtime = runtime;
|
|
497
|
+
this.runRedisWorker = runRedisWorker;
|
|
498
|
+
this.runnersSink = runnersSink;
|
|
499
|
+
}
|
|
500
|
+
onModuleInit() {
|
|
501
|
+
if (!this.options) return;
|
|
502
|
+
scanWorkflows(this.discovery, (meta, instance) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input)));
|
|
503
|
+
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
|
|
504
|
+
}
|
|
505
|
+
async onApplicationBootstrap() {
|
|
506
|
+
if (!this.options) return;
|
|
507
|
+
const handle = await this.runRedisWorker({
|
|
508
|
+
runtime: this.runtime,
|
|
509
|
+
group: this.options.group,
|
|
510
|
+
connection: this.options.connection,
|
|
511
|
+
...this.options.prefix !== void 0 ? {
|
|
512
|
+
prefix: this.options.prefix
|
|
513
|
+
} : {},
|
|
514
|
+
...this.options.instanceId !== void 0 ? {
|
|
515
|
+
instanceId: this.options.instanceId
|
|
516
|
+
} : {},
|
|
517
|
+
...this.options.concurrency !== void 0 ? {
|
|
518
|
+
concurrency: this.options.concurrency
|
|
519
|
+
} : {}
|
|
520
|
+
});
|
|
521
|
+
this.runners.push(handle);
|
|
522
|
+
this.runnersSink.push(handle);
|
|
523
|
+
}
|
|
524
|
+
async onApplicationShutdown() {
|
|
525
|
+
await Promise.allSettled(this.runners.map((handle) => handle.close()));
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
InAppWorkerBootstrap = _ts_decorate4([
|
|
529
|
+
Injectable4(),
|
|
530
|
+
_ts_param3(2, Inject3(IN_APP_WORKER_OPTIONS)),
|
|
531
|
+
_ts_param3(3, Inject3(IN_APP_WORKER_RUNTIME)),
|
|
532
|
+
_ts_param3(4, Inject3(IN_APP_RUN_REDIS_WORKER)),
|
|
533
|
+
_ts_param3(5, Inject3(IN_APP_WORKER_RUNNERS)),
|
|
534
|
+
_ts_metadata4("design:type", Function),
|
|
535
|
+
_ts_metadata4("design:paramtypes", [
|
|
536
|
+
typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
|
|
537
|
+
typeof MetadataScanner3 === "undefined" ? Object : MetadataScanner3,
|
|
538
|
+
Object,
|
|
539
|
+
typeof DurableWorkerRuntime2 === "undefined" ? Object : DurableWorkerRuntime2,
|
|
540
|
+
typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
|
|
541
|
+
Array
|
|
542
|
+
])
|
|
543
|
+
], InAppWorkerBootstrap);
|
|
544
|
+
function inAppWorkerProviders() {
|
|
545
|
+
return [
|
|
546
|
+
{
|
|
547
|
+
provide: IN_APP_WORKER_BINDING,
|
|
548
|
+
useFactory: /* @__PURE__ */ __name((transport, options) => inAppWorkerBinding(transport, options.inAppWorker ?? null), "useFactory"),
|
|
549
|
+
inject: [
|
|
550
|
+
TRANSPORT_CANONICAL2,
|
|
551
|
+
DURABLE_OPTIONS_CANONICAL2
|
|
552
|
+
]
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
provide: IN_APP_WORKER_OPTIONS,
|
|
556
|
+
useFactory: /* @__PURE__ */ __name((options) => options.inAppWorker ?? null, "useFactory"),
|
|
557
|
+
inject: [
|
|
558
|
+
DURABLE_OPTIONS_CANONICAL2
|
|
559
|
+
]
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
provide: IN_APP_WORKER_RUNTIME,
|
|
563
|
+
useFactory: /* @__PURE__ */ __name(() => new DurableWorkerRuntime2(), "useFactory")
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
provide: IN_APP_RUN_REDIS_WORKER,
|
|
567
|
+
useValue: defaultRunRedisWorker2
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
provide: IN_APP_WORKER_RUNNERS,
|
|
571
|
+
useValue: []
|
|
572
|
+
},
|
|
573
|
+
InAppWorkerBootstrap
|
|
574
|
+
];
|
|
575
|
+
}
|
|
576
|
+
__name(inAppWorkerProviders, "inAppWorkerProviders");
|
|
577
|
+
|
|
578
|
+
// src/retention-poller.ts
|
|
579
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL3, STATE_STORE_CANONICAL, TERMINAL_RUN_STATUSES, parseDuration } from "@dudousxd/nestjs-durable-core";
|
|
580
|
+
import { Inject as Inject4, Injectable as Injectable5 } from "@nestjs/common";
|
|
581
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
582
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
583
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
584
|
+
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;
|
|
585
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
586
|
+
}
|
|
587
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
588
|
+
function _ts_metadata5(k, v) {
|
|
589
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
590
|
+
}
|
|
591
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
592
|
+
function _ts_param4(paramIndex, decorator) {
|
|
593
|
+
return function(target, key) {
|
|
594
|
+
decorator(target, key, paramIndex);
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
__name(_ts_param4, "_ts_param");
|
|
598
|
+
var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
|
|
599
|
+
var DEFAULT_BATCH_SIZE = 1e3;
|
|
600
|
+
var MAX_BATCHES_PER_POLICY = 100;
|
|
601
|
+
function validateRetention(retention) {
|
|
602
|
+
const seen = /* @__PURE__ */ new Set();
|
|
603
|
+
for (const policy of retention.policies) {
|
|
604
|
+
if (policy.statuses.length === 0) {
|
|
605
|
+
throw new Error("durable retention: each policy must list at least one status");
|
|
606
|
+
}
|
|
607
|
+
if (policy.maxAge == null && policy.maxCount == null) {
|
|
608
|
+
throw new Error("durable retention: each policy must set maxAge and/or maxCount");
|
|
609
|
+
}
|
|
610
|
+
if (policy.maxAge != null) parseDuration(policy.maxAge);
|
|
611
|
+
for (const status of policy.statuses) {
|
|
612
|
+
if (!TERMINAL_RUN_STATUSES.includes(status)) {
|
|
613
|
+
throw new Error(`durable retention: status "${status}" is not terminal; only ${TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
614
|
+
}
|
|
615
|
+
if (seen.has(status)) {
|
|
616
|
+
throw new Error(`durable retention: status "${status}" appears in more than one policy; status sets must be disjoint`);
|
|
617
|
+
}
|
|
618
|
+
seen.add(status);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
__name(validateRetention, "validateRetention");
|
|
623
|
+
var RetentionPoller = class {
|
|
624
|
+
static {
|
|
625
|
+
__name(this, "RetentionPoller");
|
|
626
|
+
}
|
|
627
|
+
store;
|
|
628
|
+
options;
|
|
629
|
+
timer;
|
|
630
|
+
sweeping = false;
|
|
631
|
+
constructor(store, options) {
|
|
632
|
+
this.store = store;
|
|
633
|
+
this.options = options;
|
|
634
|
+
}
|
|
635
|
+
async onApplicationBootstrap() {
|
|
636
|
+
if (this.options.worker === false) return;
|
|
637
|
+
const retention = this.options.retention;
|
|
638
|
+
if (!retention || retention.policies.length === 0) return;
|
|
639
|
+
validateRetention(retention);
|
|
640
|
+
if (typeof this.store.pruneTerminalRuns !== "function") {
|
|
641
|
+
console.warn("[nestjs-durable] `retention` is configured but the store adapter does not implement pruneTerminalRuns; retention is disabled.");
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
await this.sweep();
|
|
645
|
+
const intervalMs = retention.sweepInterval != null ? parseDuration(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
|
|
646
|
+
if (intervalMs > 0) {
|
|
647
|
+
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
648
|
+
this.timer.unref?.();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
onModuleDestroy() {
|
|
652
|
+
if (this.timer) clearInterval(this.timer);
|
|
653
|
+
}
|
|
654
|
+
async sweep() {
|
|
655
|
+
if (this.sweeping) return;
|
|
656
|
+
const retention = this.options.retention;
|
|
657
|
+
const prune = this.store.pruneTerminalRuns;
|
|
658
|
+
if (!retention || typeof prune !== "function") return;
|
|
659
|
+
this.sweeping = true;
|
|
660
|
+
try {
|
|
661
|
+
const batchSize = retention.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
662
|
+
const now = Date.now();
|
|
663
|
+
for (const policy of retention.policies) {
|
|
664
|
+
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
665
|
+
const deleted = await prune.call(this.store, policy, now, batchSize);
|
|
666
|
+
if (deleted < batchSize) break;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
} finally {
|
|
670
|
+
this.sweeping = false;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
RetentionPoller = _ts_decorate5([
|
|
675
|
+
Injectable5(),
|
|
676
|
+
_ts_param4(0, Inject4(STATE_STORE_CANONICAL)),
|
|
677
|
+
_ts_param4(1, Inject4(DURABLE_OPTIONS_CANONICAL3)),
|
|
678
|
+
_ts_metadata5("design:type", Function),
|
|
679
|
+
_ts_metadata5("design:paramtypes", [
|
|
680
|
+
typeof StateStore === "undefined" ? Object : StateStore,
|
|
681
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
682
|
+
])
|
|
683
|
+
], RetentionPoller);
|
|
684
|
+
|
|
685
|
+
// src/timer-poller.ts
|
|
686
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL4, WorkflowEngine as WorkflowEngine2, runSchedules } from "@dudousxd/nestjs-durable-core";
|
|
687
|
+
import { Inject as Inject5, Injectable as Injectable6 } from "@nestjs/common";
|
|
688
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
689
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
690
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
691
|
+
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;
|
|
692
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
693
|
+
}
|
|
694
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
695
|
+
function _ts_metadata6(k, v) {
|
|
696
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
697
|
+
}
|
|
698
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
699
|
+
function _ts_param5(paramIndex, decorator) {
|
|
700
|
+
return function(target, key) {
|
|
701
|
+
decorator(target, key, paramIndex);
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
__name(_ts_param5, "_ts_param");
|
|
705
|
+
var TimerPoller = class {
|
|
706
|
+
static {
|
|
707
|
+
__name(this, "TimerPoller");
|
|
708
|
+
}
|
|
709
|
+
engine;
|
|
710
|
+
options;
|
|
711
|
+
timer;
|
|
712
|
+
polling = false;
|
|
713
|
+
unsubscribeEnqueued;
|
|
714
|
+
constructor(engine, options) {
|
|
715
|
+
this.engine = engine;
|
|
716
|
+
this.options = options;
|
|
717
|
+
}
|
|
718
|
+
async onApplicationBootstrap() {
|
|
719
|
+
const drive = this.options.drive ?? this.options.worker !== false;
|
|
720
|
+
if (!drive) return;
|
|
721
|
+
this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => void this.engine.runOne(runId));
|
|
722
|
+
await this.poll();
|
|
723
|
+
const intervalMs = this.options.timerPollMs ?? 1e3;
|
|
724
|
+
if (intervalMs > 0) {
|
|
725
|
+
this.timer = setInterval(() => void this.poll(), intervalMs);
|
|
726
|
+
this.timer.unref?.();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
onModuleDestroy() {
|
|
730
|
+
if (this.timer) clearInterval(this.timer);
|
|
731
|
+
this.unsubscribeEnqueued?.();
|
|
732
|
+
}
|
|
733
|
+
async poll() {
|
|
734
|
+
if (this.polling) return;
|
|
735
|
+
this.polling = true;
|
|
736
|
+
try {
|
|
737
|
+
await this.engine.runPending();
|
|
738
|
+
await this.engine.recoverIncomplete();
|
|
739
|
+
await this.engine.resumeDueTimers();
|
|
740
|
+
await this.engine.sweepTimeouts();
|
|
741
|
+
const schedules = this.options.schedules;
|
|
742
|
+
if (schedules && schedules.length > 0) {
|
|
743
|
+
await runSchedules(this.engine, schedules, Date.now());
|
|
744
|
+
}
|
|
745
|
+
} finally {
|
|
746
|
+
this.polling = false;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
TimerPoller = _ts_decorate6([
|
|
751
|
+
Injectable6(),
|
|
752
|
+
_ts_param5(1, Inject5(DURABLE_OPTIONS_CANONICAL4)),
|
|
753
|
+
_ts_metadata6("design:type", Function),
|
|
754
|
+
_ts_metadata6("design:paramtypes", [
|
|
755
|
+
typeof WorkflowEngine2 === "undefined" ? Object : WorkflowEngine2,
|
|
756
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
757
|
+
])
|
|
758
|
+
], TimerPoller);
|
|
759
|
+
|
|
760
|
+
// src/tokens.ts
|
|
761
|
+
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
762
|
+
|
|
763
|
+
// src/workflow.registrar.ts
|
|
764
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL5, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL2, WorkflowEngine as WorkflowEngine3, parseDuration as parseDuration2, workflowName } from "@dudousxd/nestjs-durable-core";
|
|
765
|
+
import { Inject as Inject6, Injectable as Injectable7 } from "@nestjs/common";
|
|
766
|
+
import { DiscoveryService as DiscoveryService4, MetadataScanner as MetadataScanner4 } from "@nestjs/core";
|
|
767
|
+
|
|
768
|
+
// src/input-validation.ts
|
|
769
|
+
function classValidatorInput(cls) {
|
|
770
|
+
let cv;
|
|
771
|
+
let ct;
|
|
772
|
+
try {
|
|
773
|
+
cv = __require("class-validator");
|
|
774
|
+
ct = __require("class-transformer");
|
|
775
|
+
} catch {
|
|
776
|
+
throw new Error('@Workflow({ inputSchema }) needs the optional peers "class-validator" and "class-transformer" \u2014 install them, or pass a `validateInput` function instead.');
|
|
777
|
+
}
|
|
778
|
+
return async (input) => {
|
|
779
|
+
const instance = ct.plainToInstance(cls, input);
|
|
780
|
+
const errors = await cv.validate(instance, {
|
|
781
|
+
whitelist: true
|
|
782
|
+
});
|
|
783
|
+
if (errors.length > 0) {
|
|
784
|
+
const message = errors.map((e) => Object.values(e.constraints ?? {
|
|
785
|
+
_: e.property
|
|
786
|
+
}).join(", ")).join("; ");
|
|
787
|
+
throw new Error(`invalid input for workflow: ${message}`);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
__name(classValidatorInput, "classValidatorInput");
|
|
792
|
+
|
|
793
|
+
// src/step-interceptor.ts
|
|
794
|
+
import "reflect-metadata";
|
|
795
|
+
var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
|
|
796
|
+
function StepInterceptor() {
|
|
797
|
+
return (target) => {
|
|
798
|
+
Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
__name(StepInterceptor, "StepInterceptor");
|
|
802
|
+
function isStepInterceptor(target) {
|
|
803
|
+
return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
|
|
804
|
+
}
|
|
805
|
+
__name(isStepInterceptor, "isStepInterceptor");
|
|
806
|
+
|
|
807
|
+
// src/workflow.registrar.ts
|
|
808
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
809
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
810
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
811
|
+
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;
|
|
812
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
813
|
+
}
|
|
814
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
815
|
+
function _ts_metadata7(k, v) {
|
|
816
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
817
|
+
}
|
|
818
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
819
|
+
function _ts_param6(paramIndex, decorator) {
|
|
820
|
+
return function(target, key) {
|
|
821
|
+
decorator(target, key, paramIndex);
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
__name(_ts_param6, "_ts_param");
|
|
825
|
+
var WorkflowRegistrar = class {
|
|
826
|
+
static {
|
|
827
|
+
__name(this, "WorkflowRegistrar");
|
|
828
|
+
}
|
|
829
|
+
discovery;
|
|
830
|
+
metadataScanner;
|
|
831
|
+
engine;
|
|
832
|
+
store;
|
|
833
|
+
options;
|
|
834
|
+
inAppWorker;
|
|
835
|
+
constructor(discovery, metadataScanner, engine, store, options, inAppWorker) {
|
|
836
|
+
this.discovery = discovery;
|
|
837
|
+
this.metadataScanner = metadataScanner;
|
|
838
|
+
this.engine = engine;
|
|
839
|
+
this.store = store;
|
|
840
|
+
this.options = options;
|
|
841
|
+
this.inAppWorker = inAppWorker;
|
|
842
|
+
}
|
|
843
|
+
async onApplicationBootstrap() {
|
|
844
|
+
const drive = this.options.drive ?? this.options.worker !== false;
|
|
845
|
+
if (!drive) return;
|
|
846
|
+
await this.engine.recoverIncomplete();
|
|
847
|
+
}
|
|
848
|
+
/** On deploy/shutdown: stop picking up new runs and wait for in-flight ones to settle, then close
|
|
849
|
+
* the transport(s) so the broker workers stop consuming and connections are released. Closing
|
|
850
|
+
* AFTER the drain keeps the transport alive while in-flight runs dispatch/await their remote steps. */
|
|
851
|
+
async onApplicationShutdown() {
|
|
852
|
+
await this.engine.drain(this.options.shutdownTimeoutMs);
|
|
853
|
+
const transports = [
|
|
854
|
+
this.options.transport,
|
|
855
|
+
...(this.options.transports ?? []).map((t) => t.transport)
|
|
856
|
+
];
|
|
857
|
+
await Promise.allSettled(transports.map((t) => t?.close?.()));
|
|
858
|
+
}
|
|
859
|
+
async onModuleInit() {
|
|
860
|
+
if (this.options.autoSchema !== false) {
|
|
861
|
+
await this.store.ensureSchema?.();
|
|
862
|
+
}
|
|
863
|
+
const deadLetterByWorkflow = /* @__PURE__ */ new Map();
|
|
864
|
+
for (const wrapper of this.discovery.getProviders()) {
|
|
865
|
+
const { instance } = wrapper;
|
|
866
|
+
if (!instance || typeof instance !== "object") continue;
|
|
867
|
+
if (isStepInterceptor(instance.constructor)) {
|
|
868
|
+
const interceptor = instance;
|
|
869
|
+
this.engine.use((invocation, next) => interceptor.intercept(invocation, next));
|
|
870
|
+
}
|
|
871
|
+
const entityMeta = getEntityMeta(instance.constructor);
|
|
872
|
+
if (entityMeta) {
|
|
873
|
+
this.engine.registerEntity(entityMeta.name, entityConfigFor(instance.constructor));
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
scanWorkflows(this.discovery, (meta, workflow) => {
|
|
877
|
+
const validateInput = meta.validateInput ?? (meta.inputSchema ? classValidatorInput(meta.inputSchema) : void 0);
|
|
878
|
+
const eventBatch = meta.debounce ? {
|
|
879
|
+
mode: "debounce",
|
|
880
|
+
windowMs: parseDuration2(meta.debounce)
|
|
881
|
+
} : meta.batch ? {
|
|
882
|
+
mode: "batch",
|
|
883
|
+
maxSize: meta.batch.maxSize,
|
|
884
|
+
windowMs: parseDuration2(meta.batch.within)
|
|
885
|
+
} : void 0;
|
|
886
|
+
const workflowCtor = workflow.constructor;
|
|
887
|
+
this.engine.register(meta.name, meta.version, (ctx, input) => workflow.run(ctx, input), {
|
|
888
|
+
tags: meta.tags,
|
|
889
|
+
singleton: meta.singleton,
|
|
890
|
+
executionTimeout: meta.executionTimeout,
|
|
891
|
+
validateInput,
|
|
892
|
+
onEvent: getOnEvents(meta, workflowCtor),
|
|
893
|
+
eventBatch,
|
|
894
|
+
// Uniform dispatch (opt-in): when an in-app worker is configured, register the body GROUP-SERVED
|
|
895
|
+
// so the engine dispatches its turns to the app's own group instead of running it inline; the
|
|
896
|
+
// co-located worker consumer replays the same body. Absent → the inline fast path (unchanged).
|
|
897
|
+
...this.inAppWorker ? {
|
|
898
|
+
group: this.inAppWorker.group,
|
|
899
|
+
executor: this.inAppWorker.executor
|
|
900
|
+
} : {}
|
|
901
|
+
});
|
|
902
|
+
const inline = this.findDeadLetterHandler(workflow);
|
|
903
|
+
if (inline && meta.deadLetterWorkflow) {
|
|
904
|
+
throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
|
|
905
|
+
}
|
|
906
|
+
if (inline) {
|
|
907
|
+
const dlqName = `${meta.name}.dlq`;
|
|
908
|
+
this.engine.register(dlqName, meta.version, inline);
|
|
909
|
+
deadLetterByWorkflow.set(meta.name, dlqName);
|
|
910
|
+
} else if (meta.deadLetterWorkflow) {
|
|
911
|
+
deadLetterByWorkflow.set(meta.name, workflowName(meta.deadLetterWorkflow));
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
this.installDeadLetterRouting(deadLetterByWorkflow);
|
|
915
|
+
}
|
|
916
|
+
/** Returns the instance's `@DeadLetter()` method bound to the instance, or undefined if none. */
|
|
917
|
+
findDeadLetterHandler(instance) {
|
|
918
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
919
|
+
for (const methodName of this.metadataScanner.getAllMethodNames(prototype)) {
|
|
920
|
+
const method = instance[methodName];
|
|
921
|
+
if (typeof method === "function" && isDeadLetterHandler(method)) {
|
|
922
|
+
return (ctx, input) => method.call(instance, ctx, input);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return void 0;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Installs a single onDead listener that routes a dead run to its workflow's handler (from the
|
|
929
|
+
* map) or the module-level `deadLetterWorkflow` default. The handler is started idempotently with
|
|
930
|
+
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
931
|
+
*/
|
|
932
|
+
installDeadLetterRouting(byWorkflow) {
|
|
933
|
+
const fallback = this.options.deadLetterWorkflow ? workflowName(this.options.deadLetterWorkflow) : void 0;
|
|
934
|
+
if (byWorkflow.size === 0 && !fallback) return;
|
|
935
|
+
this.engine.onDead((run) => {
|
|
936
|
+
const target = byWorkflow.get(run.workflow) ?? fallback;
|
|
937
|
+
if (!target) return;
|
|
938
|
+
void this.engine.start(
|
|
939
|
+
target,
|
|
940
|
+
{
|
|
941
|
+
deadRunId: run.id,
|
|
942
|
+
workflow: run.workflow,
|
|
943
|
+
input: run.input,
|
|
944
|
+
error: run.error
|
|
945
|
+
},
|
|
946
|
+
`dlq:${run.id}`,
|
|
947
|
+
// Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
|
|
948
|
+
// that tenant's worker group (`target@<tenant>`), not the bare group.
|
|
949
|
+
{
|
|
950
|
+
namespace: run.namespace
|
|
951
|
+
}
|
|
952
|
+
).catch(() => void 0);
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
WorkflowRegistrar = _ts_decorate7([
|
|
957
|
+
Injectable7(),
|
|
958
|
+
_ts_param6(3, Inject6(STATE_STORE_CANONICAL2)),
|
|
959
|
+
_ts_param6(4, Inject6(DURABLE_OPTIONS_CANONICAL5)),
|
|
960
|
+
_ts_param6(5, Inject6(IN_APP_WORKER_BINDING)),
|
|
961
|
+
_ts_metadata7("design:type", Function),
|
|
962
|
+
_ts_metadata7("design:paramtypes", [
|
|
963
|
+
typeof DiscoveryService4 === "undefined" ? Object : DiscoveryService4,
|
|
964
|
+
typeof MetadataScanner4 === "undefined" ? Object : MetadataScanner4,
|
|
965
|
+
typeof WorkflowEngine3 === "undefined" ? Object : WorkflowEngine3,
|
|
966
|
+
typeof StateStore === "undefined" ? Object : StateStore,
|
|
967
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
968
|
+
Object
|
|
969
|
+
])
|
|
970
|
+
], WorkflowRegistrar);
|
|
971
|
+
|
|
972
|
+
// src/workflow.service.ts
|
|
973
|
+
import { randomUUID } from "node:crypto";
|
|
974
|
+
import { WorkflowEngine as WorkflowEngine4 } from "@dudousxd/nestjs-durable-core";
|
|
975
|
+
import { Injectable as Injectable8 } from "@nestjs/common";
|
|
976
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
977
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
978
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
979
|
+
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;
|
|
980
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
981
|
+
}
|
|
982
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
983
|
+
function _ts_metadata8(k, v) {
|
|
984
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
985
|
+
}
|
|
986
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
987
|
+
var WorkflowService = class {
|
|
988
|
+
static {
|
|
989
|
+
__name(this, "WorkflowService");
|
|
990
|
+
}
|
|
991
|
+
engine;
|
|
992
|
+
constructor(engine) {
|
|
993
|
+
this.engine = engine;
|
|
994
|
+
}
|
|
995
|
+
start(workflow, input, runId = randomUUID(), opts) {
|
|
996
|
+
return this.engine.start(workflow, input, runId, opts);
|
|
997
|
+
}
|
|
998
|
+
resume(runId) {
|
|
999
|
+
return this.engine.resume(runId);
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Resolve once a run settles — terminal (completed/failed/cancelled/dead) or suspended. `start`
|
|
1003
|
+
* only enqueues (a worker runs the body), so pair them when a request needs the outcome:
|
|
1004
|
+
* `const { runId } = await svc.start(...); const result = await svc.waitForRun(runId)`.
|
|
1005
|
+
*/
|
|
1006
|
+
waitForRun(runId, opts) {
|
|
1007
|
+
return this.engine.waitForRun(runId, opts);
|
|
1008
|
+
}
|
|
1009
|
+
/** Deliver an external signal (e.g. from a webhook) to the run waiting on `token`. */
|
|
1010
|
+
signal(token, payload) {
|
|
1011
|
+
return this.engine.signal(token, payload);
|
|
1012
|
+
}
|
|
1013
|
+
signalWithStart(workflow, input, runId, signal, opts) {
|
|
1014
|
+
return this.engine.signalWithStart(workflow, input, runId, signal, opts);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
|
|
1018
|
+
* starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
|
|
1019
|
+
* payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
|
|
1020
|
+
* touched (resumed + started).
|
|
1021
|
+
*/
|
|
1022
|
+
publishEvent(name, payload, opts) {
|
|
1023
|
+
return this.engine.publishEvent(name, payload, opts);
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
WorkflowService = _ts_decorate8([
|
|
1027
|
+
Injectable8(),
|
|
1028
|
+
_ts_metadata8("design:type", Function),
|
|
1029
|
+
_ts_metadata8("design:paramtypes", [
|
|
1030
|
+
typeof WorkflowEngine4 === "undefined" ? Object : WorkflowEngine4
|
|
1031
|
+
])
|
|
1032
|
+
], WorkflowService);
|
|
1033
|
+
|
|
1034
|
+
// src/durable.module.ts
|
|
1035
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1036
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1037
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1038
|
+
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;
|
|
1039
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1040
|
+
}
|
|
1041
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1042
|
+
function resolveAccessor(moduleRef) {
|
|
1043
|
+
try {
|
|
1044
|
+
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
1045
|
+
strict: false
|
|
1046
|
+
});
|
|
1047
|
+
} catch {
|
|
1048
|
+
return void 0;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
__name(resolveAccessor, "resolveAccessor");
|
|
1052
|
+
function carrierFromAccessor(accessor) {
|
|
1053
|
+
const carrier = {};
|
|
1054
|
+
const traceId = accessor.traceId();
|
|
1055
|
+
if (traceId !== void 0) carrier.traceId = traceId;
|
|
1056
|
+
const tenantId = accessor.tenantId();
|
|
1057
|
+
if (tenantId !== void 0) carrier.tenantId = tenantId;
|
|
1058
|
+
const userRef = accessor.userRef();
|
|
1059
|
+
if (userRef !== void 0) carrier.userRef = userRef;
|
|
1060
|
+
return carrier;
|
|
1061
|
+
}
|
|
1062
|
+
__name(carrierFromAccessor, "carrierFromAccessor");
|
|
1063
|
+
function isContextRuntime(x) {
|
|
1064
|
+
return !!x && typeof x.deserialize === "function";
|
|
1065
|
+
}
|
|
1066
|
+
__name(isContextRuntime, "isContextRuntime");
|
|
1067
|
+
async function resolveContextRuntime() {
|
|
1068
|
+
try {
|
|
1069
|
+
const specifier = "@dudousxd/nestjs-context";
|
|
1070
|
+
const mod = await import(specifier);
|
|
1071
|
+
return isContextRuntime(mod.Context) ? mod.Context : void 0;
|
|
1072
|
+
} catch {
|
|
1073
|
+
return void 0;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
__name(resolveContextRuntime, "resolveContextRuntime");
|
|
1077
|
+
function isControlPlane(x) {
|
|
1078
|
+
return !!x && typeof x.publishControl === "function" && typeof x.onControl === "function";
|
|
1079
|
+
}
|
|
1080
|
+
__name(isControlPlane, "isControlPlane");
|
|
1081
|
+
function isScopeableStore(store) {
|
|
1082
|
+
return typeof store.withScope === "function";
|
|
1083
|
+
}
|
|
1084
|
+
__name(isScopeableStore, "isScopeableStore");
|
|
1085
|
+
function scopedStore(options) {
|
|
1086
|
+
if (options.scopeReads !== true || options.namespace === void 0) return options.store;
|
|
1087
|
+
if (!isScopeableStore(options.store)) return options.store;
|
|
1088
|
+
return options.store.withScope({
|
|
1089
|
+
namespace: options.namespace
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
__name(scopedStore, "scopedStore");
|
|
1093
|
+
var DurableModule = class _DurableModule {
|
|
1094
|
+
static {
|
|
1095
|
+
__name(this, "DurableModule");
|
|
1096
|
+
}
|
|
1097
|
+
static forRoot(options) {
|
|
1098
|
+
return _DurableModule.build({
|
|
1099
|
+
provide: DURABLE_OPTIONS_CANONICAL6,
|
|
1100
|
+
useValue: options
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
static forRootAsync(options) {
|
|
1104
|
+
return _DurableModule.build({
|
|
1105
|
+
provide: DURABLE_OPTIONS_CANONICAL6,
|
|
1106
|
+
useFactory: options.useFactory,
|
|
1107
|
+
inject: options.inject ?? []
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
static build(optionsProvider) {
|
|
1111
|
+
return {
|
|
1112
|
+
module: _DurableModule,
|
|
1113
|
+
global: true,
|
|
1114
|
+
imports: [
|
|
1115
|
+
DiscoveryModule2
|
|
1116
|
+
],
|
|
1117
|
+
providers: [
|
|
1118
|
+
optionsProvider,
|
|
1119
|
+
{
|
|
1120
|
+
provide: STATE_STORE_CANONICAL3,
|
|
1121
|
+
useFactory: /* @__PURE__ */ __name((options) => scopedStore(options), "useFactory"),
|
|
1122
|
+
inject: [
|
|
1123
|
+
DURABLE_OPTIONS_CANONICAL6
|
|
1124
|
+
]
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
provide: TRANSPORT_CANONICAL3,
|
|
1128
|
+
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? null, "useFactory"),
|
|
1129
|
+
inject: [
|
|
1130
|
+
DURABLE_OPTIONS_CANONICAL6
|
|
1131
|
+
]
|
|
1132
|
+
},
|
|
1133
|
+
// Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
|
|
1134
|
+
{
|
|
1135
|
+
provide: STATE_STORE,
|
|
1136
|
+
useExisting: STATE_STORE_CANONICAL3
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
provide: TRANSPORT,
|
|
1140
|
+
useExisting: TRANSPORT_CANONICAL3
|
|
1141
|
+
},
|
|
1142
|
+
{
|
|
1143
|
+
provide: DURABLE_OPTIONS,
|
|
1144
|
+
useExisting: DURABLE_OPTIONS_CANONICAL6
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
provide: WorkflowEngine5,
|
|
1148
|
+
useFactory: /* @__PURE__ */ __name(async (store, transport, opts, moduleRef) => {
|
|
1149
|
+
const primary = transport ?? opts.transports?.[0]?.transport;
|
|
1150
|
+
const accessor = resolveAccessor(moduleRef);
|
|
1151
|
+
const context = opts.context ?? (accessor ? () => carrierFromAccessor(accessor) : void 0);
|
|
1152
|
+
const runtime = accessor ? await resolveContextRuntime() : void 0;
|
|
1153
|
+
const rehydrate = runtime && ((carrier, fn) => carrier && Object.keys(carrier).length > 0 ? runtime.deserialize(carrier, fn) : fn());
|
|
1154
|
+
const engine = new WorkflowEngine5({
|
|
1155
|
+
store,
|
|
1156
|
+
transport: transport ?? void 0,
|
|
1157
|
+
transports: opts.transports,
|
|
1158
|
+
controlPlane: opts.controlPlane ?? (isControlPlane(primary) ? primary : void 0),
|
|
1159
|
+
leaseMs: opts.leaseMs,
|
|
1160
|
+
admission: opts.admission,
|
|
1161
|
+
maxRecoveryAttempts: opts.maxRecoveryAttempts,
|
|
1162
|
+
remoteAdvanceSilenceMs: opts.remoteAdvanceSilenceMs,
|
|
1163
|
+
instanceId: opts.instanceId,
|
|
1164
|
+
namespace: opts.namespace,
|
|
1165
|
+
remoteByConvention: opts.remoteByConvention,
|
|
1166
|
+
webhookUrl: opts.webhookUrl,
|
|
1167
|
+
traceparent: opts.traceparent,
|
|
1168
|
+
context,
|
|
1169
|
+
rehydrate: rehydrate || void 0,
|
|
1170
|
+
compensationRetries: opts.compensationRetries,
|
|
1171
|
+
// A non-worker, non-driving (plain API/dashboard) instance must not run workflows:
|
|
1172
|
+
// enqueue-only, leaving each `pending` run in the store for a DRIVING instance's poll.
|
|
1173
|
+
// Workers AND driving control planes (`drive:true` — see `DurableControlPlaneModule`)
|
|
1174
|
+
// get the engine's default in-process dispatcher: for a worker that executes the body
|
|
1175
|
+
// locally, and for a driving-only control plane that has no local registration, the
|
|
1176
|
+
// SAME default dispatcher routes it out remotely via `remoteByConvention` instead.
|
|
1177
|
+
runDispatcher: opts.worker === false && opts.drive !== true ? {
|
|
1178
|
+
dispatch: /* @__PURE__ */ __name(() => {
|
|
1179
|
+
}, "dispatch")
|
|
1180
|
+
} : void 0
|
|
1181
|
+
});
|
|
1182
|
+
for (const queue of opts.queues ?? []) engine.registerQueue(queue);
|
|
1183
|
+
return engine;
|
|
1184
|
+
}, "useFactory"),
|
|
1185
|
+
inject: [
|
|
1186
|
+
STATE_STORE_CANONICAL3,
|
|
1187
|
+
TRANSPORT_CANONICAL3,
|
|
1188
|
+
DURABLE_OPTIONS_CANONICAL6,
|
|
1189
|
+
ModuleRef
|
|
1190
|
+
]
|
|
1191
|
+
},
|
|
1192
|
+
WorkflowService,
|
|
1193
|
+
EntityService,
|
|
1194
|
+
WorkflowRegistrar,
|
|
1195
|
+
DurableStepRegistrar,
|
|
1196
|
+
TimerPoller,
|
|
1197
|
+
RetentionPoller,
|
|
1198
|
+
// In-app worker (uniform dispatch, opt-in): inert when `inAppWorker` is unset — the binding
|
|
1199
|
+
// resolves to null and the bootstrap no-ops, so a plain DurableModule is unchanged.
|
|
1200
|
+
...inAppWorkerProviders()
|
|
1201
|
+
],
|
|
1202
|
+
exports: [
|
|
1203
|
+
WorkflowService,
|
|
1204
|
+
EntityService,
|
|
1205
|
+
WorkflowEngine5,
|
|
1206
|
+
STATE_STORE,
|
|
1207
|
+
STATE_STORE_CANONICAL3,
|
|
1208
|
+
TRANSPORT,
|
|
1209
|
+
TRANSPORT_CANONICAL3,
|
|
1210
|
+
DURABLE_OPTIONS_CANONICAL6
|
|
1211
|
+
]
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
DurableModule = _ts_decorate9([
|
|
1216
|
+
Module2({})
|
|
1217
|
+
], DurableModule);
|
|
1218
|
+
var DurableControlPlaneModule = class {
|
|
1219
|
+
static {
|
|
1220
|
+
__name(this, "DurableControlPlaneModule");
|
|
1221
|
+
}
|
|
1222
|
+
static forRoot(options) {
|
|
1223
|
+
return DurableModule.forRoot({
|
|
1224
|
+
...options,
|
|
1225
|
+
worker: false,
|
|
1226
|
+
drive: true
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
static forRootAsync(options) {
|
|
1230
|
+
return DurableModule.forRootAsync({
|
|
1231
|
+
...options,
|
|
1232
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => ({
|
|
1233
|
+
...await options.useFactory(...args),
|
|
1234
|
+
worker: false,
|
|
1235
|
+
drive: true
|
|
1236
|
+
}), "useFactory")
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
DurableControlPlaneModule = _ts_decorate9([
|
|
1241
|
+
Module2({})
|
|
1242
|
+
], DurableControlPlaneModule);
|
|
1243
|
+
export {
|
|
1244
|
+
CONTEXT_ACCESSOR,
|
|
1245
|
+
DEAD_LETTER_METADATA,
|
|
1246
|
+
DURABLE_STEP_METADATA,
|
|
1247
|
+
DURABLE_WORKER_OPTIONS,
|
|
1248
|
+
DURABLE_WORKER_RUNNERS,
|
|
1249
|
+
DeadLetter,
|
|
1250
|
+
DurableControlPlaneModule,
|
|
1251
|
+
DurableModule,
|
|
1252
|
+
DurableStep,
|
|
1253
|
+
DurableWorkerModule,
|
|
1254
|
+
ENTITY_METADATA,
|
|
1255
|
+
ENTITY_ON_METADATA,
|
|
1256
|
+
Entity,
|
|
1257
|
+
EntityService,
|
|
1258
|
+
IN_APP_RUN_REDIS_WORKER,
|
|
1259
|
+
IN_APP_WORKER_BINDING,
|
|
1260
|
+
IN_APP_WORKER_OPTIONS,
|
|
1261
|
+
IN_APP_WORKER_RUNNERS,
|
|
1262
|
+
IN_APP_WORKER_RUNTIME,
|
|
1263
|
+
InAppWorkerBootstrap,
|
|
1264
|
+
ON_EVENT_METADATA,
|
|
1265
|
+
On,
|
|
1266
|
+
OnEvent,
|
|
1267
|
+
RUN_REDIS_WORKER,
|
|
1268
|
+
STEP_INTERCEPTOR_METADATA,
|
|
1269
|
+
Step,
|
|
1270
|
+
StepInterceptor,
|
|
1271
|
+
ThinStepRegistrar,
|
|
1272
|
+
ThinWorkerBootstrap,
|
|
1273
|
+
ThinWorkflowRegistrar,
|
|
1274
|
+
WORKFLOW_METADATA,
|
|
1275
|
+
Workflow,
|
|
1276
|
+
WorkflowService,
|
|
1277
|
+
entityConfigFor,
|
|
1278
|
+
getDurableStepMeta,
|
|
1279
|
+
getEntityMeta,
|
|
1280
|
+
getOnEvents,
|
|
1281
|
+
getWorkflowMeta,
|
|
1282
|
+
inAppWorkerProviders,
|
|
1283
|
+
isDeadLetterHandler,
|
|
1284
|
+
isStepInterceptor
|
|
1285
|
+
};
|
|
1286
|
+
//# sourceMappingURL=index.js.map
|