@dudousxd/nestjs-durable 0.53.0 → 0.55.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 +832 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +207 -28
- package/dist/index.d.ts +207 -28
- package/dist/index.js +750 -154
- package/dist/index.js.map +1 -1
- package/dist/migrate-from-nestjs-workflows.cjs +766 -0
- package/dist/migrate-from-nestjs-workflows.cjs.map +1 -0
- package/dist/migrate-from-nestjs-workflows.d.cts +125 -0
- package/dist/migrate-from-nestjs-workflows.d.ts +125 -0
- package/dist/migrate-from-nestjs-workflows.js +741 -0
- package/dist/migrate-from-nestjs-workflows.js.map +1 -0
- package/dist/outbox.cjs +243 -0
- package/dist/outbox.cjs.map +1 -0
- package/dist/outbox.d.cts +117 -0
- package/dist/outbox.d.ts +117 -0
- package/dist/outbox.js +213 -0
- package/dist/outbox.js.map +1 -0
- package/package.json +53 -11
- package/skills/durable-signals-and-timers/SKILL.md +4 -2
- package/skills/durable-workflows/SKILL.md +8 -2
package/dist/outbox.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/outbox/durable-outbox.ts
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { FatalError, WorkflowEngine, workflowName } from "@dudousxd/nestjs-durable-core";
|
|
7
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
8
|
+
import { NonRetryableMessageError, OnOutboxMessage, Outbox } from "@nestjs/outbox";
|
|
9
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
12
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
} else {
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
if (d = decorators[i]) {
|
|
16
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
}
|
|
22
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
23
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
25
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
29
|
+
function _ts_param(paramIndex, decorator) {
|
|
30
|
+
return function(target, key) {
|
|
31
|
+
decorator(target, key, paramIndex);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
__name(_ts_param, "_ts_param");
|
|
35
|
+
var DURABLE_OUTBOX_TOPIC = "nestjs-durable";
|
|
36
|
+
var DURABLE_OUTBOX_CONSUMER = "nestjs-durable";
|
|
37
|
+
var OPTIONS = Symbol("DURABLE_OUTBOX_OPTIONS");
|
|
38
|
+
var DurableOutbox = class {
|
|
39
|
+
static {
|
|
40
|
+
__name(this, "DurableOutbox");
|
|
41
|
+
}
|
|
42
|
+
outbox;
|
|
43
|
+
options;
|
|
44
|
+
constructor(outbox, options) {
|
|
45
|
+
this.outbox = outbox;
|
|
46
|
+
this.options = options;
|
|
47
|
+
}
|
|
48
|
+
async start(tx, workflow, input, opts = {}) {
|
|
49
|
+
const { runId = randomUUID(), key, startAt, ...rest } = opts;
|
|
50
|
+
const wireOpts = {
|
|
51
|
+
...rest,
|
|
52
|
+
...startAt !== void 0 ? {
|
|
53
|
+
startAt: startAt instanceof Date ? startAt.getTime() : startAt
|
|
54
|
+
} : {}
|
|
55
|
+
};
|
|
56
|
+
const payload = {
|
|
57
|
+
v: 1,
|
|
58
|
+
kind: "start",
|
|
59
|
+
workflow: workflowName(workflow),
|
|
60
|
+
input,
|
|
61
|
+
runId,
|
|
62
|
+
...Object.keys(wireOpts).length > 0 ? {
|
|
63
|
+
opts: wireOpts
|
|
64
|
+
} : {}
|
|
65
|
+
};
|
|
66
|
+
await this.outbox.add(tx, {
|
|
67
|
+
topic: this.options.topic,
|
|
68
|
+
payload,
|
|
69
|
+
key: key ?? null
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
runId
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Write a "deliver this signal" message through `tx`: after commit, the payload is delivered to
|
|
77
|
+
* the run waiting on `token` (`ctx.waitForSignal(token)`), or buffered for it like
|
|
78
|
+
* `WorkflowService.signal`.
|
|
79
|
+
*/
|
|
80
|
+
async signal(tx, token, payload, opts = {}) {
|
|
81
|
+
const message = {
|
|
82
|
+
v: 1,
|
|
83
|
+
kind: "signal",
|
|
84
|
+
token,
|
|
85
|
+
payload
|
|
86
|
+
};
|
|
87
|
+
await this.outbox.add(tx, {
|
|
88
|
+
topic: this.options.topic,
|
|
89
|
+
payload: message,
|
|
90
|
+
key: opts.key === void 0 ? token : opts.key,
|
|
91
|
+
...opts.id !== void 0 ? {
|
|
92
|
+
id: opts.id
|
|
93
|
+
} : {}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Poll the relay now (after your transaction commits) instead of waiting for its interval. */
|
|
97
|
+
notify() {
|
|
98
|
+
this.outbox.notify();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
DurableOutbox = _ts_decorate([
|
|
102
|
+
Injectable(),
|
|
103
|
+
_ts_param(1, Inject(OPTIONS)),
|
|
104
|
+
_ts_metadata("design:type", Function),
|
|
105
|
+
_ts_metadata("design:paramtypes", [
|
|
106
|
+
typeof Outbox === "undefined" ? Object : Outbox,
|
|
107
|
+
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
|
|
108
|
+
])
|
|
109
|
+
], DurableOutbox);
|
|
110
|
+
async function applyDurableOutboxMessage(engine, message) {
|
|
111
|
+
if (!message || message.v !== 1) {
|
|
112
|
+
throw new NonRetryableMessageError(`unsupported durable outbox payload: ${JSON.stringify(message)?.slice(0, 200)}`);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
if (message.kind === "start") {
|
|
116
|
+
await engine.start(message.workflow, message.input, message.runId, message.opts);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (message.kind === "signal") {
|
|
120
|
+
await engine.signal(message.token, message.payload);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error instanceof FatalError) {
|
|
125
|
+
throw new NonRetryableMessageError(error.message, {
|
|
126
|
+
cause: error
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
throw new NonRetryableMessageError(`unknown durable outbox message kind: ${message.kind}`);
|
|
132
|
+
}
|
|
133
|
+
__name(applyDurableOutboxMessage, "applyDurableOutboxMessage");
|
|
134
|
+
var DurableOutboxHandler = class {
|
|
135
|
+
static {
|
|
136
|
+
__name(this, "DurableOutboxHandler");
|
|
137
|
+
}
|
|
138
|
+
engine;
|
|
139
|
+
constructor(engine) {
|
|
140
|
+
this.engine = engine;
|
|
141
|
+
}
|
|
142
|
+
handle(payload, _ctx) {
|
|
143
|
+
return applyDurableOutboxMessage(this.engine, payload);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
DurableOutboxHandler = _ts_decorate([
|
|
147
|
+
Injectable(),
|
|
148
|
+
_ts_metadata("design:type", Function),
|
|
149
|
+
_ts_metadata("design:paramtypes", [
|
|
150
|
+
typeof WorkflowEngine === "undefined" ? Object : WorkflowEngine
|
|
151
|
+
])
|
|
152
|
+
], DurableOutboxHandler);
|
|
153
|
+
function handlerFor(options) {
|
|
154
|
+
const derived = class extends DurableOutboxHandler {
|
|
155
|
+
static {
|
|
156
|
+
__name(this, "derived");
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
Object.defineProperty(derived, "name", {
|
|
160
|
+
value: DurableOutboxHandler.name
|
|
161
|
+
});
|
|
162
|
+
const handle = /* @__PURE__ */ __name(function(payload, ctx) {
|
|
163
|
+
return DurableOutboxHandler.prototype.handle.call(this, payload, ctx);
|
|
164
|
+
}, "handle");
|
|
165
|
+
const descriptor = {
|
|
166
|
+
value: handle,
|
|
167
|
+
writable: true,
|
|
168
|
+
configurable: true
|
|
169
|
+
};
|
|
170
|
+
OnOutboxMessage(options.topic, {
|
|
171
|
+
consumer: options.consumer
|
|
172
|
+
})(derived.prototype, "handle", descriptor);
|
|
173
|
+
Object.defineProperty(derived.prototype, "handle", descriptor);
|
|
174
|
+
return derived;
|
|
175
|
+
}
|
|
176
|
+
__name(handlerFor, "handlerFor");
|
|
177
|
+
var DurableOutboxModule = class _DurableOutboxModule {
|
|
178
|
+
static {
|
|
179
|
+
__name(this, "DurableOutboxModule");
|
|
180
|
+
}
|
|
181
|
+
static forRoot(options = {}) {
|
|
182
|
+
const resolved = {
|
|
183
|
+
topic: options.topic ?? DURABLE_OUTBOX_TOPIC,
|
|
184
|
+
consumer: options.consumer ?? DURABLE_OUTBOX_CONSUMER
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
module: _DurableOutboxModule,
|
|
188
|
+
providers: [
|
|
189
|
+
{
|
|
190
|
+
provide: OPTIONS,
|
|
191
|
+
useValue: resolved
|
|
192
|
+
},
|
|
193
|
+
DurableOutbox,
|
|
194
|
+
handlerFor(resolved)
|
|
195
|
+
],
|
|
196
|
+
exports: [
|
|
197
|
+
DurableOutbox
|
|
198
|
+
]
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
DurableOutboxModule = _ts_decorate([
|
|
203
|
+
Module({})
|
|
204
|
+
], DurableOutboxModule);
|
|
205
|
+
export {
|
|
206
|
+
DURABLE_OUTBOX_CONSUMER,
|
|
207
|
+
DURABLE_OUTBOX_TOPIC,
|
|
208
|
+
DurableOutbox,
|
|
209
|
+
DurableOutboxHandler,
|
|
210
|
+
DurableOutboxModule,
|
|
211
|
+
applyDurableOutboxMessage
|
|
212
|
+
};
|
|
213
|
+
//# sourceMappingURL=outbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/outbox/durable-outbox.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport {\n FatalError,\n type StartOptions,\n type WorkflowClass,\n WorkflowEngine,\n type WorkflowInputOf,\n type WorkflowRef,\n workflowName,\n} from '@dudousxd/nestjs-durable-core';\nimport { type DynamicModule, Inject, Injectable, Module } from '@nestjs/common';\nimport {\n NonRetryableMessageError,\n OnOutboxMessage,\n Outbox,\n type OutboxHandlerContext,\n} from '@nestjs/outbox';\n\n/** Default outbox topic the durable messages are written to. */\nexport const DURABLE_OUTBOX_TOPIC = 'nestjs-durable';\n/** Default inbox consumer name of the handler that starts/signals runs. */\nexport const DURABLE_OUTBOX_CONSUMER = 'nestjs-durable';\n\n/** Options for {@link DurableOutboxModule.forRoot}. */\nexport interface DurableOutboxModuleOptions {\n /** The outbox topic durable's messages use. Default {@link DURABLE_OUTBOX_TOPIC}. */\n topic?: string;\n /**\n * The `@OnOutboxMessage` consumer name its inbox entries are recorded under. Keep it stable: a new\n * name makes every past message look new. Default {@link DURABLE_OUTBOX_CONSUMER}.\n */\n consumer?: string;\n}\n\n/** `StartOptions` as they travel in an outbox message: JSON-safe (`startAt` as epoch ms). */\ntype WireStartOptions = Omit<StartOptions, 'startAt'> & { startAt?: number };\n\n/** The payload of a durable outbox message. Versioned so a later shape can coexist. */\nexport type DurableOutboxPayload =\n | {\n v: 1;\n kind: 'start';\n workflow: string;\n input: unknown;\n runId: string;\n opts?: WireStartOptions;\n }\n | { v: 1; kind: 'signal'; token: string; payload: unknown };\n\n/** {@link DurableOutbox.start} options: `StartOptions` plus the run id. */\nexport interface DurableOutboxStartOptions extends StartOptions {\n /**\n * The run's id. Optional: when omitted, a random id is chosen NOW and written into the message,\n * so every redelivery starts the same run (the engine's start is idempotent by run id).\n */\n runId?: string;\n /** Outbox ordering key (messages sharing it publish in order). */\n key?: string;\n}\n\n/** {@link DurableOutbox.signal} options. */\nexport interface DurableOutboxSignalOptions {\n /** Outbox ordering key; defaults to the token, so signals to one token arrive in order. */\n key?: string | null;\n /** The outbox message id (dedupe key of the inbox). Default: the fresh UUIDv7 `Outbox.add` assigns. */\n id?: string;\n}\n\nconst OPTIONS = Symbol('DURABLE_OUTBOX_OPTIONS');\n\ninterface ResolvedOptions {\n topic: string;\n consumer: string;\n}\n\n/**\n * Starts and signals durable runs INSIDE the application's database transaction, through\n * `@nestjs/outbox`: the message commits or rolls back with your business writes, and the relay\n * delivers it to the engine after commit.\n *\n * ```ts\n * await db.transaction(async (tx) => {\n * await tx.insert(orders).values(order);\n * await durableOutbox.start(tx, CheckoutWorkflow, { orderId: order.id }, { runId: `checkout:${order.id}` });\n * });\n * ```\n */\n@Injectable()\nexport class DurableOutbox<Tx = unknown> {\n constructor(\n private readonly outbox: Outbox<Tx>,\n @Inject(OPTIONS) private readonly options: ResolvedOptions,\n ) {}\n\n /**\n * Write a \"start this run\" message through `tx`. Resolves the run id (yours, or the one chosen\n * here). A workflow class is written by its registered NAME, so the message stays serializable\n * and is delivered to whichever instance runs the relay.\n */\n start<C extends WorkflowClass>(\n tx: Tx,\n workflow: C,\n input: WorkflowInputOf<C>,\n opts?: DurableOutboxStartOptions,\n ): Promise<{ runId: string }>;\n start(\n tx: Tx,\n workflow: string,\n input: unknown,\n opts?: DurableOutboxStartOptions,\n ): Promise<{ runId: string }>;\n async start(\n tx: Tx,\n workflow: WorkflowRef,\n input: unknown,\n opts: DurableOutboxStartOptions = {},\n ): Promise<{ runId: string }> {\n const { runId = randomUUID(), key, startAt, ...rest } = opts;\n const wireOpts: WireStartOptions = {\n ...rest,\n ...(startAt !== undefined\n ? { startAt: startAt instanceof Date ? startAt.getTime() : startAt }\n : {}),\n };\n const payload: DurableOutboxPayload = {\n v: 1,\n kind: 'start',\n workflow: workflowName(workflow),\n input,\n runId,\n ...(Object.keys(wireOpts).length > 0 ? { opts: wireOpts } : {}),\n };\n await this.outbox.add(tx, { topic: this.options.topic, payload, key: key ?? null });\n return { runId };\n }\n\n /**\n * Write a \"deliver this signal\" message through `tx`: after commit, the payload is delivered to\n * the run waiting on `token` (`ctx.waitForSignal(token)`), or buffered for it like\n * `WorkflowService.signal`.\n */\n async signal(\n tx: Tx,\n token: string,\n payload: unknown,\n opts: DurableOutboxSignalOptions = {},\n ): Promise<void> {\n const message: DurableOutboxPayload = { v: 1, kind: 'signal', token, payload };\n await this.outbox.add(tx, {\n topic: this.options.topic,\n payload: message,\n key: opts.key === undefined ? token : opts.key,\n ...(opts.id !== undefined ? { id: opts.id } : {}),\n });\n }\n\n /** Poll the relay now (after your transaction commits) instead of waiting for its interval. */\n notify(): void {\n this.outbox.notify();\n }\n}\n\n/**\n * Applies a durable outbox message to the engine. Exported for tests and for a remote consumer that\n * receives the envelope over a broker; the module's `@OnOutboxMessage` handler calls it.\n *\n * A start is idempotent by run id (an existing run is a no-op success), so a redelivery never starts\n * a second run. An input the workflow rejects (a `FatalError` such as `SchemaValidationError`), an\n * unknown payload shape, dead-letters at once instead of being retried.\n */\nexport async function applyDurableOutboxMessage(\n engine: WorkflowEngine,\n message: DurableOutboxPayload,\n): Promise<void> {\n if (!message || message.v !== 1) {\n throw new NonRetryableMessageError(\n `unsupported durable outbox payload: ${JSON.stringify(message)?.slice(0, 200)}`,\n );\n }\n try {\n if (message.kind === 'start') {\n await engine.start(\n message.workflow,\n message.input,\n message.runId,\n message.opts as StartOptions,\n );\n return;\n }\n if (message.kind === 'signal') {\n await engine.signal(message.token, message.payload);\n return;\n }\n } catch (error) {\n if (error instanceof FatalError) {\n throw new NonRetryableMessageError(error.message, { cause: error });\n }\n throw error;\n }\n throw new NonRetryableMessageError(\n `unknown durable outbox message kind: ${(message as { kind?: unknown }).kind}`,\n );\n}\n\n/** The consumer side; one fresh subclass per registration carries that registration's topic. */\n@Injectable()\nexport class DurableOutboxHandler {\n constructor(private readonly engine: WorkflowEngine) {}\n\n handle(payload: DurableOutboxPayload, _ctx?: OutboxHandlerContext): Promise<void> {\n return applyDurableOutboxMessage(this.engine, payload);\n }\n}\n\nfunction handlerFor(options: ResolvedOptions): typeof DurableOutboxHandler {\n const derived = class extends DurableOutboxHandler {};\n Object.defineProperty(derived, 'name', { value: DurableOutboxHandler.name });\n // Re-declare the method on the subclass so the `@OnOutboxMessage` metadata (stored on the function\n // object) belongs to THIS registration only, never to the shared base method.\n const handle = function (\n this: DurableOutboxHandler,\n payload: DurableOutboxPayload,\n ctx?: OutboxHandlerContext,\n ) {\n return DurableOutboxHandler.prototype.handle.call(this, payload, ctx);\n };\n const descriptor: PropertyDescriptor = { value: handle, writable: true, configurable: true };\n OnOutboxMessage(options.topic, { consumer: options.consumer })(\n derived.prototype,\n 'handle',\n descriptor,\n );\n Object.defineProperty(derived.prototype, 'handle', descriptor);\n return derived;\n}\n\n/**\n * Wires durable runs to `@nestjs/outbox`. Import it next to `OutboxModule.forRoot()` (which owns the\n * store, relay, retries and dead letters) and `DurableModule.forRoot()`.\n */\n@Module({})\nexport class DurableOutboxModule {\n static forRoot(options: DurableOutboxModuleOptions = {}): DynamicModule {\n const resolved: ResolvedOptions = {\n topic: options.topic ?? DURABLE_OUTBOX_TOPIC,\n consumer: options.consumer ?? DURABLE_OUTBOX_CONSUMER,\n };\n return {\n module: DurableOutboxModule,\n providers: [{ provide: OPTIONS, useValue: resolved }, DurableOutbox, handlerFor(resolved)],\n exports: [DurableOutbox],\n };\n }\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAC3B,SACEC,YAGAC,gBAGAC,oBACK;AACP,SAA6BC,QAAQC,YAAYC,cAAc;AAC/D,SACEC,0B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,UAAUrD,QAAQqD;EAAS,CAAA,EAC1DX,QAAQK,WACR,UACAE,UAAAA;AAEF9B,SAAOwB,eAAeD,QAAQK,WAAW,UAAUE,UAAAA;AACnD,SAAOP;AACT;AApBSD;AA2BF,IAAMa,sBAAN,MAAMA,qBAAAA;SAAAA;;;EACX,OAAOC,QAAQvD,UAAsC,CAAC,GAAkB;AACtE,UAAMwD,WAA4B;MAChCjC,OAAOvB,QAAQuB,SAAS7B;MACxB2D,UAAUrD,QAAQqD,YAAY1D;IAChC;AACA,WAAO;MACL8D,QAAQH;MACRI,WAAW;QAAC;UAAEC,SAAS/D;UAASgE,UAAUJ;QAAS;QAAG1D;QAAe2C,WAAWe,QAAAA;;MAChFK,SAAS;QAAC/D;;IACZ;EACF;AACF;;;;","names":["randomUUID","FatalError","WorkflowEngine","workflowName","Inject","Injectable","Module","NonRetryableMessageError","OnOutboxMessage","Outbox","DURABLE_OUTBOX_TOPIC","DURABLE_OUTBOX_CONSUMER","OPTIONS","Symbol","DurableOutbox","outbox","options","start","tx","workflow","input","opts","runId","randomUUID","key","startAt","rest","wireOpts","undefined","Date","getTime","payload","v","kind","workflowName","Object","keys","length","add","topic","signal","token","message","id","notify","applyDurableOutboxMessage","engine","NonRetryableMessageError","JSON","stringify","slice","error","FatalError","cause","DurableOutboxHandler","handle","_ctx","handlerFor","derived","defineProperty","value","name","ctx","prototype","call","descriptor","writable","configurable","OnOutboxMessage","consumer","DurableOutboxModule","forRoot","resolved","module","providers","provide","useValue","exports"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-durable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "Durable workflows for NestJS — module, decorators, discovery and boot recovery",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -27,8 +27,12 @@
|
|
|
27
27
|
"@dudousxd/durable-worker": ">=0.1.0 <1.0.0",
|
|
28
28
|
"@dudousxd/nestjs-context": ">=0.1.0 <1.0.0",
|
|
29
29
|
"@dudousxd/nestjs-durable-core": ">=0.1.0 <1.0.0",
|
|
30
|
+
"@dudousxd/nestjs-durable-workflows-gateway": ">=0.1.0 <1.0.0",
|
|
30
31
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
31
32
|
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
33
|
+
"@nestjs/locks": ">=0.0.6 <0.1.0",
|
|
34
|
+
"@nestjs/outbox": ">=0.1.4 <0.2.0",
|
|
35
|
+
"@nestjs/workflows": ">=0.0.5 <0.1.0",
|
|
32
36
|
"class-transformer": "^0.5.0",
|
|
33
37
|
"class-validator": "^0.14.0",
|
|
34
38
|
"reflect-metadata": "^0.2.0",
|
|
@@ -41,6 +45,18 @@
|
|
|
41
45
|
"@dudousxd/nestjs-context": {
|
|
42
46
|
"optional": true
|
|
43
47
|
},
|
|
48
|
+
"@dudousxd/nestjs-durable-workflows-gateway": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@nestjs/locks": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@nestjs/outbox": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"@nestjs/workflows": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
44
60
|
"class-transformer": {
|
|
45
61
|
"optional": true
|
|
46
62
|
},
|
|
@@ -52,28 +68,34 @@
|
|
|
52
68
|
}
|
|
53
69
|
},
|
|
54
70
|
"devDependencies": {
|
|
55
|
-
"@
|
|
71
|
+
"@dudousxd/nestjs-diagnostics": "0.5.0",
|
|
56
72
|
"@nestjs/common": "12.0.1",
|
|
57
73
|
"@nestjs/core": "12.0.1",
|
|
58
74
|
"@nestjs/event-emitter": "12.0.0",
|
|
75
|
+
"@nestjs/locks": "0.0.6",
|
|
76
|
+
"@nestjs/outbox": "0.1.4",
|
|
59
77
|
"@nestjs/platform-express": "12.0.1",
|
|
60
78
|
"@nestjs/testing": "12.0.1",
|
|
79
|
+
"@nestjs/workflows": "0.0.5",
|
|
80
|
+
"@tanstack/intent": "0.4.0",
|
|
81
|
+
"@testcontainers/redis": "10.18.0",
|
|
82
|
+
"@types/supertest": "6.0.3",
|
|
61
83
|
"class-transformer": "0.5.1",
|
|
62
84
|
"class-validator": "0.14.2",
|
|
63
85
|
"eventemitter2": "6.4.9",
|
|
64
86
|
"reflect-metadata": "0.2.2",
|
|
65
87
|
"rxjs": "7.8.2",
|
|
88
|
+
"supertest": "7.2.2",
|
|
89
|
+
"tsup": "8.3.5",
|
|
66
90
|
"typescript": "5.9.3",
|
|
67
91
|
"zod": "3.25.76",
|
|
68
|
-
"
|
|
69
|
-
"@dudousxd/nestjs-
|
|
70
|
-
"@
|
|
71
|
-
"@dudousxd/durable-
|
|
72
|
-
"@dudousxd/nestjs-durable-
|
|
73
|
-
"@dudousxd/nestjs-durable-
|
|
74
|
-
"@dudousxd/nestjs-durable-
|
|
75
|
-
"@dudousxd/nestjs-durable-transport-bullmq": "0.23.4",
|
|
76
|
-
"@dudousxd/nestjs-durable-transport-event-emitter": "^0.5.3"
|
|
92
|
+
"@dudousxd/durable-worker": "0.13.0",
|
|
93
|
+
"@dudousxd/nestjs-durable-core": "^0.88.0",
|
|
94
|
+
"@dudousxd/nestjs-durable-dashboard": "0.55.0",
|
|
95
|
+
"@dudousxd/nestjs-durable-testing": "^0.25.0",
|
|
96
|
+
"@dudousxd/nestjs-durable-transport-bullmq": "0.24.0",
|
|
97
|
+
"@dudousxd/nestjs-durable-transport-event-emitter": "^0.5.3",
|
|
98
|
+
"@dudousxd/nestjs-durable-workflows-gateway": "0.1.0"
|
|
77
99
|
},
|
|
78
100
|
"module": "./dist/index.js",
|
|
79
101
|
"exports": {
|
|
@@ -86,6 +108,26 @@
|
|
|
86
108
|
"types": "./dist/index.d.cts",
|
|
87
109
|
"default": "./dist/index.cjs"
|
|
88
110
|
}
|
|
111
|
+
},
|
|
112
|
+
"./migrate-from-nestjs-workflows": {
|
|
113
|
+
"import": {
|
|
114
|
+
"types": "./dist/migrate-from-nestjs-workflows.d.ts",
|
|
115
|
+
"default": "./dist/migrate-from-nestjs-workflows.js"
|
|
116
|
+
},
|
|
117
|
+
"require": {
|
|
118
|
+
"types": "./dist/migrate-from-nestjs-workflows.d.cts",
|
|
119
|
+
"default": "./dist/migrate-from-nestjs-workflows.cjs"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"./outbox": {
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/outbox.d.ts",
|
|
125
|
+
"default": "./dist/outbox.js"
|
|
126
|
+
},
|
|
127
|
+
"require": {
|
|
128
|
+
"types": "./dist/outbox.d.cts",
|
|
129
|
+
"default": "./dist/outbox.cjs"
|
|
130
|
+
}
|
|
89
131
|
}
|
|
90
132
|
},
|
|
91
133
|
"scripts": {
|
|
@@ -81,7 +81,8 @@ export class ApprovalController {
|
|
|
81
81
|
`workflows.signal(token, payload)`. One token, one waiting run.
|
|
82
82
|
- `ctx.waitForEvent<T>(name, { match?, timeoutMs? })` waits on a named event with optional `match`
|
|
83
83
|
filtering; `workflows.publishEvent(name, payload)` fans out to every run whose `match` the payload
|
|
84
|
-
satisfies (and starts any `@OnEvent` workflows
|
|
84
|
+
satisfies (and starts any `@OnEvent` workflows whose `where` accepts the payload, with
|
|
85
|
+
`input(payload)` as the run's input when the entry maps it). Returns how many runs it touched.
|
|
85
86
|
|
|
86
87
|
```ts
|
|
87
88
|
const order = await ctx.waitForEvent<Order>('order.paid', { match: { orderId: id } });
|
|
@@ -91,7 +92,8 @@ const order = await ctx.waitForEvent<Order>('order.paid', { match: { orderId: id
|
|
|
91
92
|
### Event-triggered workflow starts
|
|
92
93
|
|
|
93
94
|
`@Workflow({ onEvent })` or `@OnEvent(...)` start a **fresh run** whenever the event is published —
|
|
94
|
-
the payload becomes the run's input
|
|
95
|
+
the payload becomes the run's input, or `input(payload)` when the entry maps it; an entry
|
|
96
|
+
`{ event, where, input }` starts only when `where(payload)` accepts it. `debounce` / `batch` coalesce bursts.
|
|
95
97
|
|
|
96
98
|
```ts
|
|
97
99
|
import { Workflow, OnEvent } from '@dudousxd/nestjs-durable';
|
|
@@ -160,8 +160,14 @@ const results = await ctx.allSettled(this.lines.validateLine, lines, { concurren
|
|
|
160
160
|
const rejected = results.filter((r) => r.status === 'rejected');
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
Prefer it to `Promise.all` past a handful of steps:
|
|
164
|
-
workflow, which makes a fan of N steps cost O(N²)
|
|
163
|
+
Prefer it to `Promise.all` past a handful of steps: without a warm sticky continuation every
|
|
164
|
+
result of a `Promise.all` replays the workflow, which makes a fan of N steps cost O(N²)
|
|
165
|
+
checkpoint reads. By default the sticky cache (`stickyRuns`, 1000 bodies) keeps a body parked on
|
|
166
|
+
dispatched `ctx.step` calls in memory, so its next turn on the same instance continues instead of
|
|
167
|
+
replaying and per-step cost stays flat; it falls back to replay when the turn runs on another
|
|
168
|
+
instance, another turn settled the run since, a cancel or retry, an eviction, a `ctx` call made
|
|
169
|
+
while detached, a non-step suspension (sleep/signal/child/fan), or a registered execution wrapper. `ctx.all`
|
|
170
|
+
still wakes once per settled wave instead of once per result. Prefer it to a child-workflow
|
|
165
171
|
`ctx.all` when each item is just a step: a child costs a whole run (row, turn, lease, signal).
|
|
166
172
|
|
|
167
173
|
How the step fan behaves (`AllStepsOptions`):
|