@dudousxd/nestjs-durable 0.15.0 → 0.16.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/LICENSE +21 -0
- package/dist/index.cjs +790 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +411 -0
- package/dist/index.d.ts +411 -8
- package/dist/index.js +744 -21
- package/dist/index.js.map +1 -1
- package/package.json +21 -7
- package/dist/context-accessor.d.ts +0 -31
- package/dist/context-accessor.d.ts.map +0 -1
- package/dist/context-accessor.js +0 -3
- package/dist/context-accessor.js.map +0 -1
- package/dist/decorators.d.ts +0 -146
- package/dist/decorators.d.ts.map +0 -1
- package/dist/decorators.js +0 -103
- package/dist/decorators.js.map +0 -1
- package/dist/durable-step.registrar.d.ts +0 -30
- package/dist/durable-step.registrar.d.ts.map +0 -1
- package/dist/durable-step.registrar.js +0 -85
- package/dist/durable-step.registrar.js.map +0 -1
- package/dist/durable.module.d.ts +0 -108
- package/dist/durable.module.d.ts.map +0 -1
- package/dist/durable.module.js +0 -207
- package/dist/durable.module.js.map +0 -1
- package/dist/entity.d.ts +0 -43
- package/dist/entity.d.ts.map +0 -1
- package/dist/entity.js +0 -94
- package/dist/entity.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/input-validation.d.ts +0 -9
- package/dist/input-validation.d.ts.map +0 -1
- package/dist/input-validation.js +0 -30
- package/dist/input-validation.js.map +0 -1
- package/dist/step-interceptor.d.ts +0 -20
- package/dist/step-interceptor.d.ts.map +0 -1
- package/dist/step-interceptor.js +0 -22
- package/dist/step-interceptor.js.map +0 -1
- package/dist/timer-poller.d.ts +0 -20
- package/dist/timer-poller.d.ts.map +0 -1
- package/dist/timer-poller.js +0 -81
- package/dist/timer-poller.js.map +0 -1
- package/dist/tokens.d.ts +0 -13
- package/dist/tokens.d.ts.map +0 -1
- package/dist/tokens.js +0 -16
- package/dist/tokens.js.map +0 -1
- package/dist/workflow.registrar.d.ts +0 -33
- package/dist/workflow.registrar.d.ts.map +0 -1
- package/dist/workflow.registrar.js +0 -169
- package/dist/workflow.registrar.js.map +0 -1
- package/dist/workflow.service.d.ts +0 -55
- package/dist/workflow.service.d.ts.map +0 -1
- package/dist/workflow.service.js +0 -58
- package/dist/workflow.service.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step-interceptor.d.ts","sourceRoot":"","sources":["../src/step-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,kBAAkB,CAAC;AAE1B,eAAO,MAAM,yBAAyB,eAA4C,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,cAAc,CAIhD;AAGD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAE3D"}
|
package/dist/step-interceptor.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STEP_INTERCEPTOR_METADATA = void 0;
|
|
4
|
-
exports.StepInterceptor = StepInterceptor;
|
|
5
|
-
exports.isStepInterceptor = isStepInterceptor;
|
|
6
|
-
require("reflect-metadata");
|
|
7
|
-
exports.STEP_INTERCEPTOR_METADATA = Symbol('nestjs-durable:step-interceptor');
|
|
8
|
-
/**
|
|
9
|
-
* Marks an `@Injectable()` class as a durable step interceptor. The module discovers it on boot and
|
|
10
|
-
* registers its `intercept` method with the engine (so it can inject loggers/tracers/etc.). First
|
|
11
|
-
* declared is outermost. Interceptors fire only when a step actually executes, never on replay.
|
|
12
|
-
*/
|
|
13
|
-
function StepInterceptor() {
|
|
14
|
-
return (target) => {
|
|
15
|
-
Reflect.defineMetadata(exports.STEP_INTERCEPTOR_METADATA, true, target);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
// biome-ignore lint/complexity/noBannedTypes: matches reflect-metadata's class target type
|
|
19
|
-
function isStepInterceptor(target) {
|
|
20
|
-
return Reflect.getMetadata(exports.STEP_INTERCEPTOR_METADATA, target) === true;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=step-interceptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step-interceptor.js","sourceRoot":"","sources":["../src/step-interceptor.ts"],"names":[],"mappings":";;;AAoBA,0CAIC;AAGD,8CAEC;AA5BD,4BAA0B;AAEb,QAAA,yBAAyB,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAC;AAYnF;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,CAAC,cAAc,CAAC,iCAAyB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC;AAED,2FAA2F;AAC3F,SAAgB,iBAAiB,CAAC,MAAgB;IAChD,OAAO,OAAO,CAAC,WAAW,CAAC,iCAAyB,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;AACzE,CAAC"}
|
package/dist/timer-poller.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { WorkflowEngine } from '@dudousxd/nestjs-durable-core';
|
|
2
|
-
import { type OnApplicationBootstrap, type OnModuleDestroy } from '@nestjs/common';
|
|
3
|
-
import type { DurableModuleOptions } from './durable.module';
|
|
4
|
-
/**
|
|
5
|
-
* Resumes suspended runs whose durable timer (`ctx.sleep`) is due, and fires any configured
|
|
6
|
-
* recurring `schedules` — once on boot, then on an interval. Set `timerPollMs` to `0` to disable
|
|
7
|
-
* the interval (e.g. when an external scheduler drives `WorkflowEngine.resumeDueTimers`).
|
|
8
|
-
*/
|
|
9
|
-
export declare class TimerPoller implements OnApplicationBootstrap, OnModuleDestroy {
|
|
10
|
-
private readonly engine;
|
|
11
|
-
private readonly options;
|
|
12
|
-
private timer?;
|
|
13
|
-
private polling;
|
|
14
|
-
private unsubscribeEnqueued?;
|
|
15
|
-
constructor(engine: WorkflowEngine, options: DurableModuleOptions);
|
|
16
|
-
onApplicationBootstrap(): Promise<void>;
|
|
17
|
-
onModuleDestroy(): void;
|
|
18
|
-
private poll;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=timer-poller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer-poller.d.ts","sourceRoot":"","sources":["../src/timer-poller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAgB,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;GAIG;AACH,qBACa,WAAY,YAAW,sBAAsB,EAAE,eAAe;IAMvE,OAAO,CAAC,QAAQ,CAAC,MAAM;IACE,OAAO,CAAC,QAAQ,CAAC,OAAO;IANnD,OAAO,CAAC,KAAK,CAAC,CAAiC;IAC/C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,mBAAmB,CAAC,CAAa;gBAGtB,MAAM,EAAE,cAAc,EACG,OAAO,EAAE,oBAAoB;IAGnE,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAe7C,eAAe,IAAI,IAAI;YAKT,IAAI;CAmBnB"}
|
package/dist/timer-poller.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.TimerPoller = void 0;
|
|
16
|
-
const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
/**
|
|
19
|
-
* Resumes suspended runs whose durable timer (`ctx.sleep`) is due, and fires any configured
|
|
20
|
-
* recurring `schedules` — once on boot, then on an interval. Set `timerPollMs` to `0` to disable
|
|
21
|
-
* the interval (e.g. when an external scheduler drives `WorkflowEngine.resumeDueTimers`).
|
|
22
|
-
*/
|
|
23
|
-
let TimerPoller = class TimerPoller {
|
|
24
|
-
engine;
|
|
25
|
-
options;
|
|
26
|
-
timer;
|
|
27
|
-
polling = false;
|
|
28
|
-
unsubscribeEnqueued;
|
|
29
|
-
constructor(engine, options) {
|
|
30
|
-
this.engine = engine;
|
|
31
|
-
this.options = options;
|
|
32
|
-
}
|
|
33
|
-
async onApplicationBootstrap() {
|
|
34
|
-
// Only the worker role drives suspended runs forward. A dashboard-only instance
|
|
35
|
-
// (`worker: false`) must not resume timers — leave that to the workers.
|
|
36
|
-
if (this.options.worker === false)
|
|
37
|
-
return;
|
|
38
|
-
// Low-latency dispatch: when a run is enqueued elsewhere (e.g. an API pod), pick it up at once
|
|
39
|
-
// over the control plane instead of waiting for the next poll tick. Leasing dedups across workers.
|
|
40
|
-
this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => void this.engine.runOne(runId));
|
|
41
|
-
await this.poll();
|
|
42
|
-
const intervalMs = this.options.timerPollMs ?? 1_000;
|
|
43
|
-
if (intervalMs > 0) {
|
|
44
|
-
this.timer = setInterval(() => void this.poll(), intervalMs);
|
|
45
|
-
this.timer.unref?.();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
onModuleDestroy() {
|
|
49
|
-
if (this.timer)
|
|
50
|
-
clearInterval(this.timer);
|
|
51
|
-
this.unsubscribeEnqueued?.();
|
|
52
|
-
}
|
|
53
|
-
async poll() {
|
|
54
|
-
if (this.polling)
|
|
55
|
-
return; // never overlap two sweeps
|
|
56
|
-
this.polling = true;
|
|
57
|
-
try {
|
|
58
|
-
// Pick up runs enqueued elsewhere (an API pod's `start`, or another worker) still `pending`,
|
|
59
|
-
// reclaim runs orphaned by a crashed worker (lease expired — a live worker renews its lease so
|
|
60
|
-
// only dead ones are reclaimed), then resume due timers and sweep execution timeouts.
|
|
61
|
-
await this.engine.runPending();
|
|
62
|
-
await this.engine.recoverIncomplete();
|
|
63
|
-
await this.engine.resumeDueTimers();
|
|
64
|
-
await this.engine.sweepTimeouts();
|
|
65
|
-
const schedules = this.options.schedules;
|
|
66
|
-
if (schedules && schedules.length > 0) {
|
|
67
|
-
await (0, nestjs_durable_core_1.runSchedules)(this.engine, schedules, Date.now());
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
this.polling = false;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
exports.TimerPoller = TimerPoller;
|
|
76
|
-
exports.TimerPoller = TimerPoller = __decorate([
|
|
77
|
-
(0, common_1.Injectable)(),
|
|
78
|
-
__param(1, (0, common_1.Inject)(nestjs_durable_core_1.DURABLE_OPTIONS)),
|
|
79
|
-
__metadata("design:paramtypes", [nestjs_durable_core_1.WorkflowEngine, Object])
|
|
80
|
-
], TimerPoller);
|
|
81
|
-
//# sourceMappingURL=timer-poller.js.map
|
package/dist/timer-poller.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer-poller.js","sourceRoot":"","sources":["../src/timer-poller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA8F;AAC9F,2CAKwB;AAGxB;;;;GAIG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAW;IAMH;IACyB;IANpC,KAAK,CAAkC;IACvC,OAAO,GAAG,KAAK,CAAC;IAChB,mBAAmB,CAAc;IAEzC,YACmB,MAAsB,EACG,OAA6B;QADtD,WAAM,GAAN,MAAM,CAAgB;QACG,YAAO,GAAP,OAAO,CAAsB;IACtE,CAAC;IAEJ,KAAK,CAAC,sBAAsB;QAC1B,gFAAgF;QAChF,wEAAwE;QACxE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK;YAAE,OAAO;QAC1C,+FAA+F;QAC/F,mGAAmG;QACnG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7F,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;QACrD,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;YAC7D,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED,eAAe;QACb,IAAI,IAAI,CAAC,KAAK;YAAE,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC;IAC/B,CAAC;IAEO,KAAK,CAAC,IAAI;QAChB,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,CAAC,2BAA2B;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC;YACH,6FAA6F;YAC7F,+FAA+F;YAC/F,sFAAsF;YACtF,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YACpC,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAClC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YACzC,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAA,kCAAY,EAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAA;AAjDY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,qCAAe,CAAC,CAAA;qCADC,oCAAc;GAN9B,WAAW,CAiDvB"}
|
package/dist/tokens.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-lib injection token for the current-request context accessor, owned by
|
|
3
|
-
* `@dudousxd/nestjs-context`. We do NOT import nestjs-context (it is an OPTIONAL
|
|
4
|
-
* peer dependency) — instead we share its well-known token by value so DI
|
|
5
|
-
* resolves the same provider when nestjs-context is installed and present.
|
|
6
|
-
*
|
|
7
|
-
* `Symbol.for(key)` uses the global symbol registry, so this resolves to the
|
|
8
|
-
* SAME symbol instance as nestjs-context's `tokens.ts` (and the identical token
|
|
9
|
-
* declared by `@dudousxd/nestjs-authz`) without any import. The key MUST stay
|
|
10
|
-
* byte-identical with nestjs-context's export.
|
|
11
|
-
*/
|
|
12
|
-
export declare const CONTEXT_ACCESSOR: unique symbol;
|
|
13
|
-
//# sourceMappingURL=tokens.d.ts.map
|
package/dist/tokens.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,eAAkD,CAAC"}
|
package/dist/tokens.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONTEXT_ACCESSOR = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Cross-lib injection token for the current-request context accessor, owned by
|
|
6
|
-
* `@dudousxd/nestjs-context`. We do NOT import nestjs-context (it is an OPTIONAL
|
|
7
|
-
* peer dependency) — instead we share its well-known token by value so DI
|
|
8
|
-
* resolves the same provider when nestjs-context is installed and present.
|
|
9
|
-
*
|
|
10
|
-
* `Symbol.for(key)` uses the global symbol registry, so this resolves to the
|
|
11
|
-
* SAME symbol instance as nestjs-context's `tokens.ts` (and the identical token
|
|
12
|
-
* declared by `@dudousxd/nestjs-authz`) without any import. The key MUST stay
|
|
13
|
-
* byte-identical with nestjs-context's export.
|
|
14
|
-
*/
|
|
15
|
-
exports.CONTEXT_ACCESSOR = Symbol.for('@dudousxd/nestjs-context:accessor');
|
|
16
|
-
//# sourceMappingURL=tokens.js.map
|
package/dist/tokens.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type StateStore, WorkflowEngine } from '@dudousxd/nestjs-durable-core';
|
|
2
|
-
import { type OnApplicationBootstrap, type OnApplicationShutdown, type OnModuleInit } from '@nestjs/common';
|
|
3
|
-
import { DiscoveryService, MetadataScanner } from '@nestjs/core';
|
|
4
|
-
import type { DurableModuleOptions } from './durable.module';
|
|
5
|
-
/**
|
|
6
|
-
* Ensures the schema (auto-schema) and registers `@Workflow` providers on init, resumes runs left
|
|
7
|
-
* incomplete by a previous process once booted, and drains in-flight runs on shutdown.
|
|
8
|
-
*
|
|
9
|
-
* For the shutdown drain to fire, enable Nest's shutdown hooks: `app.enableShutdownHooks()`.
|
|
10
|
-
*/
|
|
11
|
-
export declare class WorkflowRegistrar implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
|
|
12
|
-
private readonly discovery;
|
|
13
|
-
private readonly metadataScanner;
|
|
14
|
-
private readonly engine;
|
|
15
|
-
private readonly store;
|
|
16
|
-
private readonly options;
|
|
17
|
-
constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, engine: WorkflowEngine, store: StateStore, options: DurableModuleOptions);
|
|
18
|
-
onApplicationBootstrap(): Promise<void>;
|
|
19
|
-
/** On deploy/shutdown: stop picking up new runs and wait for in-flight ones to settle, then close
|
|
20
|
-
* the transport(s) so the broker workers stop consuming and connections are released. Closing
|
|
21
|
-
* AFTER the drain keeps the transport alive while in-flight runs dispatch/await their remote steps. */
|
|
22
|
-
onApplicationShutdown(): Promise<void>;
|
|
23
|
-
onModuleInit(): Promise<void>;
|
|
24
|
-
/** Returns the instance's `@DeadLetter()` method bound to the instance, or undefined if none. */
|
|
25
|
-
private findDeadLetterHandler;
|
|
26
|
-
/**
|
|
27
|
-
* Installs a single onDead listener that routes a dead run to its workflow's handler (from the
|
|
28
|
-
* map) or the module-level `deadLetterWorkflow` default. The handler is started idempotently with
|
|
29
|
-
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
30
|
-
*/
|
|
31
|
-
private installDeadLetterRouting;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=workflow.registrar.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.registrar.d.ts","sourceRoot":"","sources":["../src/workflow.registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EAEf,cAAc,EAIf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAW7D;;;;;GAKG;AACH,qBACa,iBACX,YAAW,YAAY,EAAE,sBAAsB,EAAE,qBAAqB;IAGpE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACF,OAAO,CAAC,QAAQ,CAAC,KAAK;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAJhC,SAAS,EAAE,gBAAgB,EAC3B,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,cAAc,EACD,KAAK,EAAE,UAAU,EACb,OAAO,EAAE,oBAAoB;IAGnE,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAO7C;;4GAEwG;IAClG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAwEnC,iGAAiG;IACjG,OAAO,CAAC,qBAAqB;IAW7B;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CAiBjC"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.WorkflowRegistrar = void 0;
|
|
16
|
-
const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const core_1 = require("@nestjs/core");
|
|
19
|
-
const decorators_1 = require("./decorators");
|
|
20
|
-
const entity_1 = require("./entity");
|
|
21
|
-
const input_validation_1 = require("./input-validation");
|
|
22
|
-
const step_interceptor_1 = require("./step-interceptor");
|
|
23
|
-
/**
|
|
24
|
-
* Ensures the schema (auto-schema) and registers `@Workflow` providers on init, resumes runs left
|
|
25
|
-
* incomplete by a previous process once booted, and drains in-flight runs on shutdown.
|
|
26
|
-
*
|
|
27
|
-
* For the shutdown drain to fire, enable Nest's shutdown hooks: `app.enableShutdownHooks()`.
|
|
28
|
-
*/
|
|
29
|
-
let WorkflowRegistrar = class WorkflowRegistrar {
|
|
30
|
-
discovery;
|
|
31
|
-
metadataScanner;
|
|
32
|
-
engine;
|
|
33
|
-
store;
|
|
34
|
-
options;
|
|
35
|
-
constructor(discovery, metadataScanner, engine, store, options) {
|
|
36
|
-
this.discovery = discovery;
|
|
37
|
-
this.metadataScanner = metadataScanner;
|
|
38
|
-
this.engine = engine;
|
|
39
|
-
this.store = store;
|
|
40
|
-
this.options = options;
|
|
41
|
-
}
|
|
42
|
-
async onApplicationBootstrap() {
|
|
43
|
-
// Only the worker role recovers runs left incomplete by a crash/deploy. A dashboard-only
|
|
44
|
-
// instance (`worker: false`) must not pick up and re-run workflows — leave that to the workers.
|
|
45
|
-
if (this.options.worker === false)
|
|
46
|
-
return;
|
|
47
|
-
await this.engine.recoverIncomplete();
|
|
48
|
-
}
|
|
49
|
-
/** On deploy/shutdown: stop picking up new runs and wait for in-flight ones to settle, then close
|
|
50
|
-
* the transport(s) so the broker workers stop consuming and connections are released. Closing
|
|
51
|
-
* AFTER the drain keeps the transport alive while in-flight runs dispatch/await their remote steps. */
|
|
52
|
-
async onApplicationShutdown() {
|
|
53
|
-
await this.engine.drain(this.options.shutdownTimeoutMs);
|
|
54
|
-
const transports = [
|
|
55
|
-
this.options.transport,
|
|
56
|
-
...(this.options.transports ?? []).map((t) => t.transport),
|
|
57
|
-
];
|
|
58
|
-
await Promise.allSettled(transports.map((t) => t?.close?.()));
|
|
59
|
-
}
|
|
60
|
-
async onModuleInit() {
|
|
61
|
-
if (this.options.autoSchema !== false) {
|
|
62
|
-
await this.store.ensureSchema?.();
|
|
63
|
-
}
|
|
64
|
-
// Maps a workflow name to the workflow its dead runs route to. Built from each `@Workflow`'s
|
|
65
|
-
// inline `@DeadLetter()` method (preferred) or its `deadLetterWorkflow` reference; the
|
|
66
|
-
// module-level `deadLetterWorkflow` is the fallback applied in the onDead listener below.
|
|
67
|
-
const deadLetterByWorkflow = new Map();
|
|
68
|
-
for (const wrapper of this.discovery.getProviders()) {
|
|
69
|
-
const { instance } = wrapper;
|
|
70
|
-
if (!instance || typeof instance !== 'object')
|
|
71
|
-
continue;
|
|
72
|
-
if ((0, step_interceptor_1.isStepInterceptor)(instance.constructor)) {
|
|
73
|
-
const interceptor = instance;
|
|
74
|
-
this.engine.use((invocation, next) => interceptor.intercept(invocation, next));
|
|
75
|
-
}
|
|
76
|
-
const entityMeta = (0, entity_1.getEntityMeta)(instance.constructor);
|
|
77
|
-
if (entityMeta) {
|
|
78
|
-
this.engine.registerEntity(entityMeta.name, (0, entity_1.entityConfigFor)(instance.constructor));
|
|
79
|
-
continue; // an @Entity is not a @Workflow
|
|
80
|
-
}
|
|
81
|
-
const meta = (0, decorators_1.getWorkflowMeta)(instance.constructor);
|
|
82
|
-
if (!meta)
|
|
83
|
-
continue;
|
|
84
|
-
const workflow = instance;
|
|
85
|
-
if (typeof workflow.run !== 'function') {
|
|
86
|
-
throw new Error(`@Workflow ${meta.name} must define a run(ctx, input) method`);
|
|
87
|
-
}
|
|
88
|
-
// Input validation: a custom `validateInput` wins; otherwise build one from the class-validator
|
|
89
|
-
// `inputSchema` DTO (lazy — class-validator is only required if a workflow uses inputSchema).
|
|
90
|
-
const validateInput = meta.validateInput ??
|
|
91
|
-
(meta.inputSchema ? (0, input_validation_1.classValidatorInput)(meta.inputSchema) : undefined);
|
|
92
|
-
const eventBatch = meta.debounce
|
|
93
|
-
? { mode: 'debounce', windowMs: (0, nestjs_durable_core_1.parseDuration)(meta.debounce) }
|
|
94
|
-
: meta.batch
|
|
95
|
-
? {
|
|
96
|
-
mode: 'batch',
|
|
97
|
-
maxSize: meta.batch.maxSize,
|
|
98
|
-
windowMs: (0, nestjs_durable_core_1.parseDuration)(meta.batch.within),
|
|
99
|
-
}
|
|
100
|
-
: undefined;
|
|
101
|
-
this.engine.register(meta.name, meta.version, (ctx, input) => workflow.run(ctx, input), {
|
|
102
|
-
tags: meta.tags,
|
|
103
|
-
singleton: meta.singleton,
|
|
104
|
-
executionTimeout: meta.executionTimeout,
|
|
105
|
-
validateInput,
|
|
106
|
-
onEvent: (0, decorators_1.getOnEvents)(meta, instance.constructor),
|
|
107
|
-
eventBatch,
|
|
108
|
-
});
|
|
109
|
-
const inline = this.findDeadLetterHandler(instance);
|
|
110
|
-
if (inline && meta.deadLetterWorkflow) {
|
|
111
|
-
// Two dead-letter targets for one workflow is ambiguous config, not a precedence question —
|
|
112
|
-
// fail fast at boot rather than silently picking one.
|
|
113
|
-
throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
|
|
114
|
-
}
|
|
115
|
-
if (inline) {
|
|
116
|
-
// The inline handler is itself a durable workflow, registered as `<name>.dlq`, so it gets
|
|
117
|
-
// checkpointing and a dashboard run linked to the dead run via the `dlq:<runId>` id.
|
|
118
|
-
const dlqName = `${meta.name}.dlq`;
|
|
119
|
-
this.engine.register(dlqName, meta.version, inline);
|
|
120
|
-
deadLetterByWorkflow.set(meta.name, dlqName);
|
|
121
|
-
}
|
|
122
|
-
else if (meta.deadLetterWorkflow) {
|
|
123
|
-
deadLetterByWorkflow.set(meta.name, (0, nestjs_durable_core_1.workflowName)(meta.deadLetterWorkflow));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
this.installDeadLetterRouting(deadLetterByWorkflow);
|
|
127
|
-
}
|
|
128
|
-
/** Returns the instance's `@DeadLetter()` method bound to the instance, or undefined if none. */
|
|
129
|
-
findDeadLetterHandler(instance) {
|
|
130
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
131
|
-
for (const methodName of this.metadataScanner.getAllMethodNames(prototype)) {
|
|
132
|
-
const method = instance[methodName];
|
|
133
|
-
if (typeof method === 'function' && (0, decorators_1.isDeadLetterHandler)(method)) {
|
|
134
|
-
return (ctx, input) => method.call(instance, ctx, input);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Installs a single onDead listener that routes a dead run to its workflow's handler (from the
|
|
141
|
-
* map) or the module-level `deadLetterWorkflow` default. The handler is started idempotently with
|
|
142
|
-
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
143
|
-
*/
|
|
144
|
-
installDeadLetterRouting(byWorkflow) {
|
|
145
|
-
const fallback = this.options.deadLetterWorkflow
|
|
146
|
-
? (0, nestjs_durable_core_1.workflowName)(this.options.deadLetterWorkflow)
|
|
147
|
-
: undefined;
|
|
148
|
-
if (byWorkflow.size === 0 && !fallback)
|
|
149
|
-
return;
|
|
150
|
-
this.engine.onDead((run) => {
|
|
151
|
-
const target = byWorkflow.get(run.workflow) ?? fallback;
|
|
152
|
-
if (!target)
|
|
153
|
-
return;
|
|
154
|
-
void this.engine
|
|
155
|
-
.start(target, { deadRunId: run.id, workflow: run.workflow, input: run.input, error: run.error }, `dlq:${run.id}`)
|
|
156
|
-
.catch(() => undefined);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
exports.WorkflowRegistrar = WorkflowRegistrar;
|
|
161
|
-
exports.WorkflowRegistrar = WorkflowRegistrar = __decorate([
|
|
162
|
-
(0, common_1.Injectable)(),
|
|
163
|
-
__param(3, (0, common_1.Inject)(nestjs_durable_core_1.STATE_STORE)),
|
|
164
|
-
__param(4, (0, common_1.Inject)(nestjs_durable_core_1.DURABLE_OPTIONS)),
|
|
165
|
-
__metadata("design:paramtypes", [core_1.DiscoveryService,
|
|
166
|
-
core_1.MetadataScanner,
|
|
167
|
-
nestjs_durable_core_1.WorkflowEngine, Object, Object])
|
|
168
|
-
], WorkflowRegistrar);
|
|
169
|
-
//# sourceMappingURL=workflow.registrar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.registrar.js","sourceRoot":"","sources":["../src/workflow.registrar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEASuC;AACvC,2CAMwB;AACxB,uCAAiE;AACj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ACd,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC/C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAgB,EAAE,EAAE;YACtC,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;YACxD,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,KAAK,IAAI,CAAC,MAAM;iBACb,KAAK,CACJ,MAAM,EACN,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EACjF,OAAO,GAAG,CAAC,EAAE,EAAE,CAChB;iBACA,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxIY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,iCAAW,CAAC,CAAA;IACnB,WAAA,IAAA,eAAM,EAAC,qCAAe,CAAC,CAAA;qCAJI,uBAAgB;QACV,sBAAe;QACxB,oCAAc;GAN9B,iBAAiB,CAwI7B"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { type RunResult, type StartOptions, type WorkflowClass, WorkflowEngine, type WorkflowInputOf } from '@dudousxd/nestjs-durable-core';
|
|
2
|
-
/** Public entry point for starting and resuming workflow runs. */
|
|
3
|
-
export declare class WorkflowService {
|
|
4
|
-
private readonly engine;
|
|
5
|
-
constructor(engine: WorkflowEngine);
|
|
6
|
-
/**
|
|
7
|
-
* Enqueue a workflow run — it creates the run (`pending`) and returns `{ runId, status: 'pending' }`
|
|
8
|
-
* immediately; a worker executes the body (so the caller never blocks on workflow logic). Use
|
|
9
|
-
* {@link waitForRun} when you need the outcome. Pass the workflow's **class**
|
|
10
|
-
* (`start(CheckoutWorkflow, input)`) for a typed input + refactor-safety, or a **name** string for a
|
|
11
|
-
* cross-runtime workflow. `runId` defaults to a random id; pass your own to make the start idempotent
|
|
12
|
-
* (a redelivery returns the existing run). `opts.tags` are merged with the workflow's static
|
|
13
|
-
* `@Workflow({ tags })`; `opts.searchAttributes` stamp typed, queryable run data.
|
|
14
|
-
*/
|
|
15
|
-
start<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
16
|
-
start(workflow: string, input: unknown, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
17
|
-
resume(runId: string): Promise<RunResult>;
|
|
18
|
-
/**
|
|
19
|
-
* Resolve once a run settles — terminal (completed/failed/cancelled/dead) or suspended. `start`
|
|
20
|
-
* only enqueues (a worker runs the body), so pair them when a request needs the outcome:
|
|
21
|
-
* `const { runId } = await svc.start(...); const result = await svc.waitForRun(runId)`.
|
|
22
|
-
*/
|
|
23
|
-
waitForRun(runId: string, opts?: {
|
|
24
|
-
timeoutMs?: number;
|
|
25
|
-
}): Promise<RunResult>;
|
|
26
|
-
/** Deliver an external signal (e.g. from a webhook) to the run waiting on `token`. */
|
|
27
|
-
signal(token: string, payload: unknown): Promise<RunResult | null>;
|
|
28
|
-
/**
|
|
29
|
-
* Ensure a run exists for `runId`, then deliver a signal to it — race-free (the signal is buffered
|
|
30
|
-
* until the run reaches its `waitForSignal`). The durable-entity / accumulator pattern: one
|
|
31
|
-
* long-lived run per key fed events by many calls. See {@link WorkflowEngine.signalWithStart}.
|
|
32
|
-
*/
|
|
33
|
-
signalWithStart<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId: string, signal: {
|
|
34
|
-
token: string;
|
|
35
|
-
payload?: unknown;
|
|
36
|
-
}, opts?: StartOptions): Promise<{
|
|
37
|
-
runId: string;
|
|
38
|
-
}>;
|
|
39
|
-
signalWithStart(workflow: string, input: unknown, runId: string, signal: {
|
|
40
|
-
token: string;
|
|
41
|
-
payload?: unknown;
|
|
42
|
-
}, opts?: StartOptions): Promise<{
|
|
43
|
-
runId: string;
|
|
44
|
-
}>;
|
|
45
|
-
/**
|
|
46
|
-
* Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
|
|
47
|
-
* starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
|
|
48
|
-
* payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
|
|
49
|
-
* touched (resumed + started).
|
|
50
|
-
*/
|
|
51
|
-
publishEvent(name: string, payload: unknown, opts?: {
|
|
52
|
-
id?: string;
|
|
53
|
-
}): Promise<number>;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=workflow.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.service.d.ts","sourceRoot":"","sources":["../src/workflow.service.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAGvC,kEAAkE;AAClE,qBACa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAEnD;;;;;;;;OAQG;IACH,KAAK,CAAC,CAAC,SAAS,aAAa,EAC3B,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC,SAAS,CAAC;IACrB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC;IAUhG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAIzC;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAI5E,sFAAsF;IACtF,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAIlE;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,aAAa,EACrC,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,EAC5C,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,eAAe,CACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,EAC5C,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAW7B;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAGtF"}
|
package/dist/workflow.service.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.WorkflowService = void 0;
|
|
13
|
-
const node_crypto_1 = require("node:crypto");
|
|
14
|
-
const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
|
|
15
|
-
const common_1 = require("@nestjs/common");
|
|
16
|
-
/** Public entry point for starting and resuming workflow runs. */
|
|
17
|
-
let WorkflowService = class WorkflowService {
|
|
18
|
-
engine;
|
|
19
|
-
constructor(engine) {
|
|
20
|
-
this.engine = engine;
|
|
21
|
-
}
|
|
22
|
-
start(workflow, input, runId = (0, node_crypto_1.randomUUID)(), opts) {
|
|
23
|
-
return this.engine.start(workflow, input, runId, opts);
|
|
24
|
-
}
|
|
25
|
-
resume(runId) {
|
|
26
|
-
return this.engine.resume(runId);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Resolve once a run settles — terminal (completed/failed/cancelled/dead) or suspended. `start`
|
|
30
|
-
* only enqueues (a worker runs the body), so pair them when a request needs the outcome:
|
|
31
|
-
* `const { runId } = await svc.start(...); const result = await svc.waitForRun(runId)`.
|
|
32
|
-
*/
|
|
33
|
-
waitForRun(runId, opts) {
|
|
34
|
-
return this.engine.waitForRun(runId, opts);
|
|
35
|
-
}
|
|
36
|
-
/** Deliver an external signal (e.g. from a webhook) to the run waiting on `token`. */
|
|
37
|
-
signal(token, payload) {
|
|
38
|
-
return this.engine.signal(token, payload);
|
|
39
|
-
}
|
|
40
|
-
signalWithStart(workflow, input, runId, signal, opts) {
|
|
41
|
-
return this.engine.signalWithStart(workflow, input, runId, signal, opts);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
|
|
45
|
-
* starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
|
|
46
|
-
* payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
|
|
47
|
-
* touched (resumed + started).
|
|
48
|
-
*/
|
|
49
|
-
publishEvent(name, payload, opts) {
|
|
50
|
-
return this.engine.publishEvent(name, payload, opts);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
exports.WorkflowService = WorkflowService;
|
|
54
|
-
exports.WorkflowService = WorkflowService = __decorate([
|
|
55
|
-
(0, common_1.Injectable)(),
|
|
56
|
-
__metadata("design:paramtypes", [nestjs_durable_core_1.WorkflowEngine])
|
|
57
|
-
], WorkflowService);
|
|
58
|
-
//# sourceMappingURL=workflow.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.service.js","sourceRoot":"","sources":["../src/workflow.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAyC;AACzC,uEAMuC;AACvC,2CAA4C;AAE5C,kEAAkE;AAE3D,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAkBvD,KAAK,CACH,QAAgB,EAChB,KAAc,EACd,QAAgB,IAAA,wBAAU,GAAE,EAC5B,IAAmB;QAEnB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,O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