@dudousxd/nestjs-durable 0.18.1 → 0.20.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 +294 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -2
- package/dist/index.d.ts +102 -2
- package/dist/index.js +287 -89
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -87,15 +87,44 @@ function getOnEvents(meta, target) {
|
|
|
87
87
|
}
|
|
88
88
|
__name(getOnEvents, "getOnEvents");
|
|
89
89
|
|
|
90
|
-
// src/durable.module.ts
|
|
91
|
-
import {
|
|
92
|
-
import { Module } from "@nestjs/common";
|
|
93
|
-
import { DiscoveryModule,
|
|
90
|
+
// src/durable-worker.module.ts
|
|
91
|
+
import { DurableWorkerRuntime, runRedisWorker as defaultRunRedisWorker } from "@dudousxd/durable-worker";
|
|
92
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
93
|
+
import { DiscoveryModule, DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
94
94
|
|
|
95
|
-
// src/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
// src/discovery-helpers.ts
|
|
96
|
+
function scanWorkflows(discovery, register) {
|
|
97
|
+
for (const wrapper of discovery.getProviders()) {
|
|
98
|
+
const { instance } = wrapper;
|
|
99
|
+
if (!instance || typeof instance !== "object") continue;
|
|
100
|
+
const meta = getWorkflowMeta(instance.constructor);
|
|
101
|
+
if (!meta) continue;
|
|
102
|
+
const workflow = instance;
|
|
103
|
+
if (typeof workflow.run !== "function") {
|
|
104
|
+
throw new Error(`@Workflow ${meta.name} must define a run(ctx, input) method`);
|
|
105
|
+
}
|
|
106
|
+
register(meta, workflow);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
__name(scanWorkflows, "scanWorkflows");
|
|
110
|
+
function scanSteps(discovery, scanner, register) {
|
|
111
|
+
for (const wrapper of discovery.getProviders()) {
|
|
112
|
+
const { instance } = wrapper;
|
|
113
|
+
if (!instance || typeof instance !== "object") continue;
|
|
114
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
115
|
+
for (const methodName of scanner.getAllMethodNames(prototype)) {
|
|
116
|
+
const method = instance[methodName];
|
|
117
|
+
if (typeof method !== "function") continue;
|
|
118
|
+
const meta = getDurableStepMeta(method);
|
|
119
|
+
if (!meta) continue;
|
|
120
|
+
const handler = /* @__PURE__ */ __name((input, log) => method.call(instance, input, log), "handler");
|
|
121
|
+
register(meta, handler);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
__name(scanSteps, "scanSteps");
|
|
126
|
+
|
|
127
|
+
// src/durable-worker.module.ts
|
|
99
128
|
function _ts_decorate(decorators, target, key, desc) {
|
|
100
129
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
101
130
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -113,6 +142,182 @@ function _ts_param(paramIndex, decorator) {
|
|
|
113
142
|
};
|
|
114
143
|
}
|
|
115
144
|
__name(_ts_param, "_ts_param");
|
|
145
|
+
var DURABLE_WORKER_OPTIONS = Symbol("nestjs-durable:worker-options");
|
|
146
|
+
var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
|
|
147
|
+
var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
|
|
148
|
+
var ThinWorkflowRegistrar = class {
|
|
149
|
+
static {
|
|
150
|
+
__name(this, "ThinWorkflowRegistrar");
|
|
151
|
+
}
|
|
152
|
+
discovery;
|
|
153
|
+
runtime;
|
|
154
|
+
constructor(discovery, runtime) {
|
|
155
|
+
this.discovery = discovery;
|
|
156
|
+
this.runtime = runtime;
|
|
157
|
+
}
|
|
158
|
+
onModuleInit() {
|
|
159
|
+
scanWorkflows(this.discovery, (meta, instance) => this.runtime.registerWorkflow(meta.name, (ctx, input) => instance.run(ctx, input)));
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
ThinWorkflowRegistrar = _ts_decorate([
|
|
163
|
+
Injectable(),
|
|
164
|
+
_ts_metadata("design:type", Function),
|
|
165
|
+
_ts_metadata("design:paramtypes", [
|
|
166
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
167
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime
|
|
168
|
+
])
|
|
169
|
+
], ThinWorkflowRegistrar);
|
|
170
|
+
var ThinStepRegistrar = class {
|
|
171
|
+
static {
|
|
172
|
+
__name(this, "ThinStepRegistrar");
|
|
173
|
+
}
|
|
174
|
+
discovery;
|
|
175
|
+
metadataScanner;
|
|
176
|
+
runtime;
|
|
177
|
+
constructor(discovery, metadataScanner, runtime) {
|
|
178
|
+
this.discovery = discovery;
|
|
179
|
+
this.metadataScanner = metadataScanner;
|
|
180
|
+
this.runtime = runtime;
|
|
181
|
+
}
|
|
182
|
+
onModuleInit() {
|
|
183
|
+
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => this.runtime.registerStep(meta.name, handler));
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
ThinStepRegistrar = _ts_decorate([
|
|
187
|
+
Injectable(),
|
|
188
|
+
_ts_metadata("design:type", Function),
|
|
189
|
+
_ts_metadata("design:paramtypes", [
|
|
190
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
191
|
+
typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
|
|
192
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime
|
|
193
|
+
])
|
|
194
|
+
], ThinStepRegistrar);
|
|
195
|
+
var ThinWorkerBootstrap = class {
|
|
196
|
+
static {
|
|
197
|
+
__name(this, "ThinWorkerBootstrap");
|
|
198
|
+
}
|
|
199
|
+
runtime;
|
|
200
|
+
options;
|
|
201
|
+
runRedisWorker;
|
|
202
|
+
runnersSink;
|
|
203
|
+
runners = [];
|
|
204
|
+
constructor(runtime, options, runRedisWorker, runnersSink) {
|
|
205
|
+
this.runtime = runtime;
|
|
206
|
+
this.options = options;
|
|
207
|
+
this.runRedisWorker = runRedisWorker;
|
|
208
|
+
this.runnersSink = runnersSink;
|
|
209
|
+
}
|
|
210
|
+
async onApplicationBootstrap() {
|
|
211
|
+
for (const group of this.options.groups) {
|
|
212
|
+
const handle = await this.runRedisWorker({
|
|
213
|
+
runtime: this.runtime,
|
|
214
|
+
group,
|
|
215
|
+
connection: this.options.connection,
|
|
216
|
+
...this.options.prefix !== void 0 ? {
|
|
217
|
+
prefix: this.options.prefix
|
|
218
|
+
} : {},
|
|
219
|
+
...this.options.instanceId !== void 0 ? {
|
|
220
|
+
instanceId: this.options.instanceId
|
|
221
|
+
} : {}
|
|
222
|
+
});
|
|
223
|
+
this.runners.push(handle);
|
|
224
|
+
this.runnersSink.push(handle);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async onApplicationShutdown() {
|
|
228
|
+
await Promise.allSettled(this.runners.map((h) => h.close()));
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
ThinWorkerBootstrap = _ts_decorate([
|
|
232
|
+
Injectable(),
|
|
233
|
+
_ts_param(1, Inject(DURABLE_WORKER_OPTIONS)),
|
|
234
|
+
_ts_param(2, Inject(RUN_REDIS_WORKER)),
|
|
235
|
+
_ts_param(3, Inject(DURABLE_WORKER_RUNNERS)),
|
|
236
|
+
_ts_metadata("design:type", Function),
|
|
237
|
+
_ts_metadata("design:paramtypes", [
|
|
238
|
+
typeof DurableWorkerRuntime === "undefined" ? Object : DurableWorkerRuntime,
|
|
239
|
+
typeof DurableWorkerModuleOptions === "undefined" ? Object : DurableWorkerModuleOptions,
|
|
240
|
+
typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
|
|
241
|
+
Array
|
|
242
|
+
])
|
|
243
|
+
], ThinWorkerBootstrap);
|
|
244
|
+
var DurableWorkerModule = class _DurableWorkerModule {
|
|
245
|
+
static {
|
|
246
|
+
__name(this, "DurableWorkerModule");
|
|
247
|
+
}
|
|
248
|
+
static forRoot(options) {
|
|
249
|
+
return _DurableWorkerModule.build({
|
|
250
|
+
provide: DURABLE_WORKER_OPTIONS,
|
|
251
|
+
useValue: options
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
static forRootAsync(options) {
|
|
255
|
+
return _DurableWorkerModule.build({
|
|
256
|
+
provide: DURABLE_WORKER_OPTIONS,
|
|
257
|
+
useFactory: options.useFactory,
|
|
258
|
+
inject: options.inject ?? []
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
static build(optionsProvider) {
|
|
262
|
+
return {
|
|
263
|
+
module: _DurableWorkerModule,
|
|
264
|
+
imports: [
|
|
265
|
+
DiscoveryModule
|
|
266
|
+
],
|
|
267
|
+
providers: [
|
|
268
|
+
optionsProvider,
|
|
269
|
+
{
|
|
270
|
+
provide: DurableWorkerRuntime,
|
|
271
|
+
useFactory: /* @__PURE__ */ __name(() => new DurableWorkerRuntime(), "useFactory")
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
provide: RUN_REDIS_WORKER,
|
|
275
|
+
useValue: defaultRunRedisWorker
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
provide: DURABLE_WORKER_RUNNERS,
|
|
279
|
+
useValue: []
|
|
280
|
+
},
|
|
281
|
+
ThinWorkflowRegistrar,
|
|
282
|
+
ThinStepRegistrar,
|
|
283
|
+
ThinWorkerBootstrap
|
|
284
|
+
],
|
|
285
|
+
exports: [
|
|
286
|
+
DurableWorkerRuntime
|
|
287
|
+
]
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
DurableWorkerModule = _ts_decorate([
|
|
292
|
+
Module({})
|
|
293
|
+
], DurableWorkerModule);
|
|
294
|
+
|
|
295
|
+
// src/durable.module.ts
|
|
296
|
+
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL4, STATE_STORE, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL2, TRANSPORT, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL2, WorkflowEngine as WorkflowEngine5 } from "@dudousxd/nestjs-durable-core";
|
|
297
|
+
import { Module as Module2 } from "@nestjs/common";
|
|
298
|
+
import { DiscoveryModule as DiscoveryModule2, ModuleRef } from "@nestjs/core";
|
|
299
|
+
|
|
300
|
+
// src/durable-step.registrar.ts
|
|
301
|
+
import { DURABLE_OPTIONS_CANONICAL, TRANSPORT_CANONICAL } from "@dudousxd/nestjs-durable-core";
|
|
302
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
303
|
+
import { DiscoveryService as DiscoveryService2, MetadataScanner as MetadataScanner2 } from "@nestjs/core";
|
|
304
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
305
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
306
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
307
|
+
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;
|
|
308
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
309
|
+
}
|
|
310
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
311
|
+
function _ts_metadata2(k, v) {
|
|
312
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
313
|
+
}
|
|
314
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
315
|
+
function _ts_param2(paramIndex, decorator) {
|
|
316
|
+
return function(target, key) {
|
|
317
|
+
decorator(target, key, paramIndex);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
__name(_ts_param2, "_ts_param");
|
|
116
321
|
function supportsHandle(transport) {
|
|
117
322
|
return typeof transport?.handle === "function";
|
|
118
323
|
}
|
|
@@ -135,28 +340,17 @@ var DurableStepRegistrar = class {
|
|
|
135
340
|
if (this.options.worker === false) return;
|
|
136
341
|
if (!supportsHandle(this.transport)) return;
|
|
137
342
|
const transport = this.transport;
|
|
138
|
-
|
|
139
|
-
const { instance } = wrapper;
|
|
140
|
-
if (!instance || typeof instance !== "object") continue;
|
|
141
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
142
|
-
for (const methodName of this.metadataScanner.getAllMethodNames(prototype)) {
|
|
143
|
-
const method = instance[methodName];
|
|
144
|
-
if (typeof method !== "function") continue;
|
|
145
|
-
const meta = getDurableStepMeta(method);
|
|
146
|
-
if (!meta) continue;
|
|
147
|
-
transport.handle(meta.name, (input, log) => instance[methodName](input, log));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
343
|
+
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler));
|
|
150
344
|
}
|
|
151
345
|
};
|
|
152
|
-
DurableStepRegistrar =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
typeof
|
|
159
|
-
typeof
|
|
346
|
+
DurableStepRegistrar = _ts_decorate2([
|
|
347
|
+
Injectable2(),
|
|
348
|
+
_ts_param2(2, Inject2(TRANSPORT_CANONICAL)),
|
|
349
|
+
_ts_param2(3, Inject2(DURABLE_OPTIONS_CANONICAL)),
|
|
350
|
+
_ts_metadata2("design:type", Function),
|
|
351
|
+
_ts_metadata2("design:paramtypes", [
|
|
352
|
+
typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
|
|
353
|
+
typeof MetadataScanner2 === "undefined" ? Object : MetadataScanner2,
|
|
160
354
|
Object,
|
|
161
355
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
162
356
|
])
|
|
@@ -164,19 +358,19 @@ DurableStepRegistrar = _ts_decorate([
|
|
|
164
358
|
|
|
165
359
|
// src/entity.ts
|
|
166
360
|
import { WorkflowEngine } from "@dudousxd/nestjs-durable-core";
|
|
167
|
-
import { Injectable as
|
|
361
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
168
362
|
import "reflect-metadata";
|
|
169
|
-
function
|
|
363
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
170
364
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
171
365
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
172
366
|
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;
|
|
173
367
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
174
368
|
}
|
|
175
|
-
__name(
|
|
176
|
-
function
|
|
369
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
370
|
+
function _ts_metadata3(k, v) {
|
|
177
371
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
178
372
|
}
|
|
179
|
-
__name(
|
|
373
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
180
374
|
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
181
375
|
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
182
376
|
function Entity(options) {
|
|
@@ -233,34 +427,34 @@ var EntityService = class {
|
|
|
233
427
|
return this.engine.getEntityState(name, key);
|
|
234
428
|
}
|
|
235
429
|
};
|
|
236
|
-
EntityService =
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
430
|
+
EntityService = _ts_decorate3([
|
|
431
|
+
Injectable3(),
|
|
432
|
+
_ts_metadata3("design:type", Function),
|
|
433
|
+
_ts_metadata3("design:paramtypes", [
|
|
240
434
|
typeof WorkflowEngine === "undefined" ? Object : WorkflowEngine
|
|
241
435
|
])
|
|
242
436
|
], EntityService);
|
|
243
437
|
|
|
244
438
|
// src/timer-poller.ts
|
|
245
439
|
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL2, WorkflowEngine as WorkflowEngine2, runSchedules } from "@dudousxd/nestjs-durable-core";
|
|
246
|
-
import { Inject as
|
|
247
|
-
function
|
|
440
|
+
import { Inject as Inject3, Injectable as Injectable4 } from "@nestjs/common";
|
|
441
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
248
442
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
249
443
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
250
444
|
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;
|
|
251
445
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
252
446
|
}
|
|
253
|
-
__name(
|
|
254
|
-
function
|
|
447
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
448
|
+
function _ts_metadata4(k, v) {
|
|
255
449
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
256
450
|
}
|
|
257
|
-
__name(
|
|
258
|
-
function
|
|
451
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
452
|
+
function _ts_param3(paramIndex, decorator) {
|
|
259
453
|
return function(target, key) {
|
|
260
454
|
decorator(target, key, paramIndex);
|
|
261
455
|
};
|
|
262
456
|
}
|
|
263
|
-
__name(
|
|
457
|
+
__name(_ts_param3, "_ts_param");
|
|
264
458
|
var TimerPoller = class {
|
|
265
459
|
static {
|
|
266
460
|
__name(this, "TimerPoller");
|
|
@@ -305,11 +499,11 @@ var TimerPoller = class {
|
|
|
305
499
|
}
|
|
306
500
|
}
|
|
307
501
|
};
|
|
308
|
-
TimerPoller =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
502
|
+
TimerPoller = _ts_decorate4([
|
|
503
|
+
Injectable4(),
|
|
504
|
+
_ts_param3(1, Inject3(DURABLE_OPTIONS_CANONICAL2)),
|
|
505
|
+
_ts_metadata4("design:type", Function),
|
|
506
|
+
_ts_metadata4("design:paramtypes", [
|
|
313
507
|
typeof WorkflowEngine2 === "undefined" ? Object : WorkflowEngine2,
|
|
314
508
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
315
509
|
])
|
|
@@ -320,8 +514,8 @@ var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
|
320
514
|
|
|
321
515
|
// src/workflow.registrar.ts
|
|
322
516
|
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL3, STATE_STORE_CANONICAL, WorkflowEngine as WorkflowEngine3, parseDuration, workflowName } from "@dudousxd/nestjs-durable-core";
|
|
323
|
-
import { Inject as
|
|
324
|
-
import { DiscoveryService as
|
|
517
|
+
import { Inject as Inject4, Injectable as Injectable5 } from "@nestjs/common";
|
|
518
|
+
import { DiscoveryService as DiscoveryService3, MetadataScanner as MetadataScanner3 } from "@nestjs/core";
|
|
325
519
|
|
|
326
520
|
// src/input-validation.ts
|
|
327
521
|
function classValidatorInput(cls) {
|
|
@@ -363,23 +557,23 @@ function isStepInterceptor(target) {
|
|
|
363
557
|
__name(isStepInterceptor, "isStepInterceptor");
|
|
364
558
|
|
|
365
559
|
// src/workflow.registrar.ts
|
|
366
|
-
function
|
|
560
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
367
561
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
368
562
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
369
563
|
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;
|
|
370
564
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
371
565
|
}
|
|
372
|
-
__name(
|
|
373
|
-
function
|
|
566
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
567
|
+
function _ts_metadata5(k, v) {
|
|
374
568
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
375
569
|
}
|
|
376
|
-
__name(
|
|
377
|
-
function
|
|
570
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
571
|
+
function _ts_param4(paramIndex, decorator) {
|
|
378
572
|
return function(target, key) {
|
|
379
573
|
decorator(target, key, paramIndex);
|
|
380
574
|
};
|
|
381
575
|
}
|
|
382
|
-
__name(
|
|
576
|
+
__name(_ts_param4, "_ts_param");
|
|
383
577
|
var WorkflowRegistrar = class {
|
|
384
578
|
static {
|
|
385
579
|
__name(this, "WorkflowRegistrar");
|
|
@@ -426,14 +620,9 @@ var WorkflowRegistrar = class {
|
|
|
426
620
|
const entityMeta = getEntityMeta(instance.constructor);
|
|
427
621
|
if (entityMeta) {
|
|
428
622
|
this.engine.registerEntity(entityMeta.name, entityConfigFor(instance.constructor));
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
const meta = getWorkflowMeta(instance.constructor);
|
|
432
|
-
if (!meta) continue;
|
|
433
|
-
const workflow = instance;
|
|
434
|
-
if (typeof workflow.run !== "function") {
|
|
435
|
-
throw new Error(`@Workflow ${meta.name} must define a run(ctx, input) method`);
|
|
436
623
|
}
|
|
624
|
+
}
|
|
625
|
+
scanWorkflows(this.discovery, (meta, workflow) => {
|
|
437
626
|
const validateInput = meta.validateInput ?? (meta.inputSchema ? classValidatorInput(meta.inputSchema) : void 0);
|
|
438
627
|
const eventBatch = meta.debounce ? {
|
|
439
628
|
mode: "debounce",
|
|
@@ -443,15 +632,16 @@ var WorkflowRegistrar = class {
|
|
|
443
632
|
maxSize: meta.batch.maxSize,
|
|
444
633
|
windowMs: parseDuration(meta.batch.within)
|
|
445
634
|
} : void 0;
|
|
635
|
+
const workflowCtor = workflow.constructor;
|
|
446
636
|
this.engine.register(meta.name, meta.version, (ctx, input) => workflow.run(ctx, input), {
|
|
447
637
|
tags: meta.tags,
|
|
448
638
|
singleton: meta.singleton,
|
|
449
639
|
executionTimeout: meta.executionTimeout,
|
|
450
640
|
validateInput,
|
|
451
|
-
onEvent: getOnEvents(meta,
|
|
641
|
+
onEvent: getOnEvents(meta, workflowCtor),
|
|
452
642
|
eventBatch
|
|
453
643
|
});
|
|
454
|
-
const inline = this.findDeadLetterHandler(
|
|
644
|
+
const inline = this.findDeadLetterHandler(workflow);
|
|
455
645
|
if (inline && meta.deadLetterWorkflow) {
|
|
456
646
|
throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
|
|
457
647
|
}
|
|
@@ -462,7 +652,7 @@ var WorkflowRegistrar = class {
|
|
|
462
652
|
} else if (meta.deadLetterWorkflow) {
|
|
463
653
|
deadLetterByWorkflow.set(meta.name, workflowName(meta.deadLetterWorkflow));
|
|
464
654
|
}
|
|
465
|
-
}
|
|
655
|
+
});
|
|
466
656
|
this.installDeadLetterRouting(deadLetterByWorkflow);
|
|
467
657
|
}
|
|
468
658
|
/** Returns the instance's `@DeadLetter()` method bound to the instance, or undefined if none. */
|
|
@@ -496,14 +686,14 @@ var WorkflowRegistrar = class {
|
|
|
496
686
|
});
|
|
497
687
|
}
|
|
498
688
|
};
|
|
499
|
-
WorkflowRegistrar =
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
typeof
|
|
506
|
-
typeof
|
|
689
|
+
WorkflowRegistrar = _ts_decorate5([
|
|
690
|
+
Injectable5(),
|
|
691
|
+
_ts_param4(3, Inject4(STATE_STORE_CANONICAL)),
|
|
692
|
+
_ts_param4(4, Inject4(DURABLE_OPTIONS_CANONICAL3)),
|
|
693
|
+
_ts_metadata5("design:type", Function),
|
|
694
|
+
_ts_metadata5("design:paramtypes", [
|
|
695
|
+
typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
|
|
696
|
+
typeof MetadataScanner3 === "undefined" ? Object : MetadataScanner3,
|
|
507
697
|
typeof WorkflowEngine3 === "undefined" ? Object : WorkflowEngine3,
|
|
508
698
|
typeof StateStore === "undefined" ? Object : StateStore,
|
|
509
699
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
@@ -513,18 +703,18 @@ WorkflowRegistrar = _ts_decorate4([
|
|
|
513
703
|
// src/workflow.service.ts
|
|
514
704
|
import { randomUUID } from "node:crypto";
|
|
515
705
|
import { WorkflowEngine as WorkflowEngine4 } from "@dudousxd/nestjs-durable-core";
|
|
516
|
-
import { Injectable as
|
|
517
|
-
function
|
|
706
|
+
import { Injectable as Injectable6 } from "@nestjs/common";
|
|
707
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
518
708
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
519
709
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
520
710
|
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;
|
|
521
711
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
522
712
|
}
|
|
523
|
-
__name(
|
|
524
|
-
function
|
|
713
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
714
|
+
function _ts_metadata6(k, v) {
|
|
525
715
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
526
716
|
}
|
|
527
|
-
__name(
|
|
717
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
528
718
|
var WorkflowService = class {
|
|
529
719
|
static {
|
|
530
720
|
__name(this, "WorkflowService");
|
|
@@ -564,22 +754,22 @@ var WorkflowService = class {
|
|
|
564
754
|
return this.engine.publishEvent(name, payload, opts);
|
|
565
755
|
}
|
|
566
756
|
};
|
|
567
|
-
WorkflowService =
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
757
|
+
WorkflowService = _ts_decorate6([
|
|
758
|
+
Injectable6(),
|
|
759
|
+
_ts_metadata6("design:type", Function),
|
|
760
|
+
_ts_metadata6("design:paramtypes", [
|
|
571
761
|
typeof WorkflowEngine4 === "undefined" ? Object : WorkflowEngine4
|
|
572
762
|
])
|
|
573
763
|
], WorkflowService);
|
|
574
764
|
|
|
575
765
|
// src/durable.module.ts
|
|
576
|
-
function
|
|
766
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
577
767
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
578
768
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
579
769
|
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;
|
|
580
770
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
581
771
|
}
|
|
582
|
-
__name(
|
|
772
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
583
773
|
function resolveAccessor(moduleRef) {
|
|
584
774
|
try {
|
|
585
775
|
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
@@ -641,7 +831,7 @@ var DurableModule = class _DurableModule {
|
|
|
641
831
|
module: _DurableModule,
|
|
642
832
|
global: true,
|
|
643
833
|
imports: [
|
|
644
|
-
|
|
834
|
+
DiscoveryModule2
|
|
645
835
|
],
|
|
646
836
|
providers: [
|
|
647
837
|
optionsProvider,
|
|
@@ -688,6 +878,7 @@ var DurableModule = class _DurableModule {
|
|
|
688
878
|
leaseMs: opts.leaseMs,
|
|
689
879
|
admission: opts.admission,
|
|
690
880
|
maxRecoveryAttempts: opts.maxRecoveryAttempts,
|
|
881
|
+
remoteAdvanceSilenceMs: opts.remoteAdvanceSilenceMs,
|
|
691
882
|
instanceId: opts.instanceId,
|
|
692
883
|
webhookUrl: opts.webhookUrl,
|
|
693
884
|
traceparent: opts.traceparent,
|
|
@@ -731,16 +922,19 @@ var DurableModule = class _DurableModule {
|
|
|
731
922
|
};
|
|
732
923
|
}
|
|
733
924
|
};
|
|
734
|
-
DurableModule =
|
|
735
|
-
|
|
925
|
+
DurableModule = _ts_decorate7([
|
|
926
|
+
Module2({})
|
|
736
927
|
], DurableModule);
|
|
737
928
|
export {
|
|
738
929
|
CONTEXT_ACCESSOR,
|
|
739
930
|
DEAD_LETTER_METADATA,
|
|
740
931
|
DURABLE_STEP_METADATA,
|
|
932
|
+
DURABLE_WORKER_OPTIONS,
|
|
933
|
+
DURABLE_WORKER_RUNNERS,
|
|
741
934
|
DeadLetter,
|
|
742
935
|
DurableModule,
|
|
743
936
|
DurableStep,
|
|
937
|
+
DurableWorkerModule,
|
|
744
938
|
ENTITY_METADATA,
|
|
745
939
|
ENTITY_ON_METADATA,
|
|
746
940
|
Entity,
|
|
@@ -748,8 +942,12 @@ export {
|
|
|
748
942
|
ON_EVENT_METADATA,
|
|
749
943
|
On,
|
|
750
944
|
OnEvent,
|
|
945
|
+
RUN_REDIS_WORKER,
|
|
751
946
|
STEP_INTERCEPTOR_METADATA,
|
|
752
947
|
StepInterceptor,
|
|
948
|
+
ThinStepRegistrar,
|
|
949
|
+
ThinWorkerBootstrap,
|
|
950
|
+
ThinWorkflowRegistrar,
|
|
753
951
|
WORKFLOW_METADATA,
|
|
754
952
|
Workflow,
|
|
755
953
|
WorkflowService,
|