@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/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
5
5
|
import { readSearchAttributes } from "@dudousxd/nestjs-durable-core";
|
|
6
6
|
|
|
7
7
|
// src/decorators.ts
|
|
8
|
-
import { DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, WORKFLOW_NAME_KEY } from "@dudousxd/nestjs-durable-core";
|
|
8
|
+
import { DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, WORKFLOW_NAME_KEY, parseDuration, runCompletedEvent, runFailedEvent } from "@dudousxd/nestjs-durable-core";
|
|
9
9
|
import "reflect-metadata";
|
|
10
10
|
|
|
11
11
|
// src/origin.ts
|
|
@@ -229,24 +229,108 @@ function onErrorCodesOf(method) {
|
|
|
229
229
|
__name(onErrorCodesOf, "onErrorCodesOf");
|
|
230
230
|
var ON_EVENT_METADATA = Symbol("nestjs-durable:on-event");
|
|
231
231
|
function OnDurableEvent(...events) {
|
|
232
|
+
return (target) => addEventSubscriptions(target, events);
|
|
233
|
+
}
|
|
234
|
+
__name(OnDurableEvent, "OnDurableEvent");
|
|
235
|
+
function OnWorkflowCompleted(workflow, options) {
|
|
236
|
+
return onWorkflowSettled(runCompletedEvent(workflow), options?.where, options);
|
|
237
|
+
}
|
|
238
|
+
__name(OnWorkflowCompleted, "OnWorkflowCompleted");
|
|
239
|
+
function OnWorkflowFailed(workflow, options) {
|
|
240
|
+
const statuses = options?.statuses;
|
|
241
|
+
const where = options?.where;
|
|
242
|
+
const accepts = statuses || where ? (event) => (!statuses || statuses.includes(event.status)) && (!where || where(event)) : void 0;
|
|
243
|
+
return onWorkflowSettled(runFailedEvent(workflow), accepts, options);
|
|
244
|
+
}
|
|
245
|
+
__name(OnWorkflowFailed, "OnWorkflowFailed");
|
|
246
|
+
var ON_EVENT_BATCH_METADATA = Symbol("nestjs-durable:on-event-batch");
|
|
247
|
+
function onWorkflowSettled(event, where, options) {
|
|
248
|
+
const subscription = {
|
|
249
|
+
event,
|
|
250
|
+
where,
|
|
251
|
+
input: options?.input
|
|
252
|
+
};
|
|
253
|
+
const batch = subscriberEventBatch(event, options);
|
|
232
254
|
return (target) => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
255
|
+
addEventSubscriptions(target, [
|
|
256
|
+
subscription
|
|
257
|
+
]);
|
|
258
|
+
if (!batch) return;
|
|
259
|
+
const existing = Reflect.getMetadata(ON_EVENT_BATCH_METADATA, target);
|
|
260
|
+
if (existing && !sameEventBatch(existing, batch)) {
|
|
261
|
+
throw new Error(`${target.name ?? "workflow"}: two lifecycle subscriptions declare different debounce/batch settings; a workflow coalesces all its triggers one way`);
|
|
262
|
+
}
|
|
263
|
+
Reflect.defineMetadata(ON_EVENT_BATCH_METADATA, batch, target);
|
|
238
264
|
};
|
|
239
265
|
}
|
|
240
|
-
__name(
|
|
266
|
+
__name(onWorkflowSettled, "onWorkflowSettled");
|
|
267
|
+
function subscriberEventBatch(event, options) {
|
|
268
|
+
if (options?.debounce && options.batch) {
|
|
269
|
+
throw new Error(`${event}: a subscription takes debounce or batch, not both`);
|
|
270
|
+
}
|
|
271
|
+
if (options?.debounce) {
|
|
272
|
+
return {
|
|
273
|
+
mode: "debounce",
|
|
274
|
+
windowMs: parseDuration(options.debounce.windowMs),
|
|
275
|
+
...options.debounce.key ? {
|
|
276
|
+
key: options.debounce.key
|
|
277
|
+
} : {}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (options?.batch) {
|
|
281
|
+
return {
|
|
282
|
+
mode: "batch",
|
|
283
|
+
maxSize: options.batch.maxSize,
|
|
284
|
+
windowMs: parseDuration(options.batch.windowMs),
|
|
285
|
+
...options.batch.key ? {
|
|
286
|
+
key: options.batch.key
|
|
287
|
+
} : {}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
__name(subscriberEventBatch, "subscriberEventBatch");
|
|
293
|
+
function sameEventBatch(a, b) {
|
|
294
|
+
return a.mode === b.mode && a.windowMs === b.windowMs && a.key?.toString() === b.key?.toString() && (a.mode !== "batch" || b.mode !== "batch" || a.maxSize === b.maxSize);
|
|
295
|
+
}
|
|
296
|
+
__name(sameEventBatch, "sameEventBatch");
|
|
297
|
+
function eventBatchOf(meta, target) {
|
|
298
|
+
const declared = meta.debounce ? {
|
|
299
|
+
mode: "debounce",
|
|
300
|
+
windowMs: parseDuration(meta.debounce)
|
|
301
|
+
} : meta.batch ? {
|
|
302
|
+
mode: "batch",
|
|
303
|
+
maxSize: meta.batch.maxSize,
|
|
304
|
+
windowMs: parseDuration(meta.batch.within)
|
|
305
|
+
} : void 0;
|
|
306
|
+
const fromSubscription = Reflect.getMetadata(ON_EVENT_BATCH_METADATA, target);
|
|
307
|
+
if (declared && fromSubscription && !sameEventBatch(declared, fromSubscription)) {
|
|
308
|
+
throw new Error(`workflow ${meta.name}: @Workflow declares ${declared.mode} but a lifecycle subscription declares a different ${fromSubscription.mode}; declare it in one place`);
|
|
309
|
+
}
|
|
310
|
+
return fromSubscription ?? declared;
|
|
311
|
+
}
|
|
312
|
+
__name(eventBatchOf, "eventBatchOf");
|
|
313
|
+
function addEventSubscriptions(target, entries) {
|
|
314
|
+
const existing = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
315
|
+
Reflect.defineMetadata(ON_EVENT_METADATA, [
|
|
316
|
+
...existing,
|
|
317
|
+
...entries
|
|
318
|
+
], target);
|
|
319
|
+
}
|
|
320
|
+
__name(addEventSubscriptions, "addEventSubscriptions");
|
|
241
321
|
var OnEvent = OnDurableEvent;
|
|
242
322
|
function getOnEvents(meta, target) {
|
|
243
323
|
const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
324
|
+
const names = /* @__PURE__ */ new Set();
|
|
244
325
|
return [
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
326
|
+
...meta.onEvent ?? [],
|
|
327
|
+
...fromDecorator
|
|
328
|
+
].filter((entry) => {
|
|
329
|
+
if (typeof entry !== "string") return true;
|
|
330
|
+
if (names.has(entry)) return false;
|
|
331
|
+
names.add(entry);
|
|
332
|
+
return true;
|
|
333
|
+
});
|
|
250
334
|
}
|
|
251
335
|
__name(getOnEvents, "getOnEvents");
|
|
252
336
|
|
|
@@ -562,6 +646,9 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
562
646
|
} : {}
|
|
563
647
|
};
|
|
564
648
|
const body = workflowIo(meta).wrap((ctx, input) => instance.run(ctx, input));
|
|
649
|
+
const subscribes = [
|
|
650
|
+
...new Set(getOnEvents(meta, instance.constructor).map((entry) => typeof entry === "string" ? entry : entry.event))
|
|
651
|
+
];
|
|
565
652
|
runtime.registerWorkflow(meta.name, body, {
|
|
566
653
|
...announced,
|
|
567
654
|
...meta.requires !== void 0 ? {
|
|
@@ -575,6 +662,9 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
575
662
|
code,
|
|
576
663
|
workflow
|
|
577
664
|
})
|
|
665
|
+
} : {},
|
|
666
|
+
...subscribes.length > 0 ? {
|
|
667
|
+
subscribes
|
|
578
668
|
} : {}
|
|
579
669
|
});
|
|
580
670
|
for (const [name, fn] of handlers) runtime.registerWorkflow(name, fn, announced);
|
|
@@ -825,9 +915,9 @@ function unavailableRunGateway() {
|
|
|
825
915
|
__name(unavailableRunGateway, "unavailableRunGateway");
|
|
826
916
|
|
|
827
917
|
// src/durable.module.ts
|
|
828
|
-
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as
|
|
829
|
-
import { Inject as
|
|
830
|
-
import { DiscoveryModule, ModuleRef } from "@nestjs/core";
|
|
918
|
+
import { DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL8, RunGateway as RunGateway2, STATE_STORE, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL4, TRANSPORT, TRANSPORT_CANONICAL as TRANSPORT_CANONICAL3, WorkflowEngine as WorkflowEngine6 } from "@dudousxd/nestjs-durable-core";
|
|
919
|
+
import { Inject as Inject9, Injectable as Injectable13, Module } from "@nestjs/common";
|
|
920
|
+
import { DiscoveryModule, ModuleRef as ModuleRef2 } from "@nestjs/core";
|
|
831
921
|
|
|
832
922
|
// src/durable-step.registrar.ts
|
|
833
923
|
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL2, TRANSPORT_CANONICAL } from "@dudousxd/nestjs-durable-core";
|
|
@@ -1165,8 +1255,10 @@ import { SUMMARY_CHILD_LIMIT, childIdsOf, pageFan, resolveTenantToken as resolve
|
|
|
1165
1255
|
import { Injectable as Injectable6 } from "@nestjs/common";
|
|
1166
1256
|
|
|
1167
1257
|
// src/run-request-responder.ts
|
|
1168
|
-
import { resolveWireTenant } from "@dudousxd/nestjs-durable-core";
|
|
1258
|
+
import { lifecycleKindOf, resolveWireTenant } from "@dudousxd/nestjs-durable-core";
|
|
1169
1259
|
var UNSUPPORTED_RUN_REQUEST = "unsupported-request";
|
|
1260
|
+
var BAD_RUN_REQUEST = "bad-request";
|
|
1261
|
+
var TENANT_REPUBLISH_MAX_LIMIT = 1e3;
|
|
1170
1262
|
var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
1171
1263
|
"getRunDetail",
|
|
1172
1264
|
"getFanMembers",
|
|
@@ -1180,8 +1272,47 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
|
1180
1272
|
"continue",
|
|
1181
1273
|
"retryWithInput",
|
|
1182
1274
|
"redispatch",
|
|
1183
|
-
"waitingFor"
|
|
1275
|
+
"waitingFor",
|
|
1276
|
+
"republishLifecycle",
|
|
1277
|
+
"workflowLifecycle"
|
|
1184
1278
|
]);
|
|
1279
|
+
function wireDate(value) {
|
|
1280
|
+
if (value === void 0 || value === null) return void 0;
|
|
1281
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
1282
|
+
if (Number.isNaN(date.getTime())) throw new Error(`invalid date ${String(value)}`);
|
|
1283
|
+
return date;
|
|
1284
|
+
}
|
|
1285
|
+
__name(wireDate, "wireDate");
|
|
1286
|
+
function scopeRunLinks(detail, tenant) {
|
|
1287
|
+
const own = /* @__PURE__ */ __name((link) => link.namespace === tenant, "own");
|
|
1288
|
+
const bare = /* @__PURE__ */ __name((link) => {
|
|
1289
|
+
if (own(link)) return link;
|
|
1290
|
+
const { status: _status, namespace: _namespace, ...rest2 } = link;
|
|
1291
|
+
return rest2;
|
|
1292
|
+
}, "bare");
|
|
1293
|
+
const awaitedBy = detail.awaitedBy?.filter(own);
|
|
1294
|
+
const { awaitedBy: _awaitedBy, ...rest } = detail;
|
|
1295
|
+
const source = detail.triggeredBy;
|
|
1296
|
+
return {
|
|
1297
|
+
...rest,
|
|
1298
|
+
...source ? {
|
|
1299
|
+
triggeredBy: own(source) ? source : {
|
|
1300
|
+
runId: source.runId,
|
|
1301
|
+
kind: source.kind
|
|
1302
|
+
}
|
|
1303
|
+
} : {},
|
|
1304
|
+
...awaitedBy && awaitedBy.length > 0 ? {
|
|
1305
|
+
awaitedBy
|
|
1306
|
+
} : {},
|
|
1307
|
+
...detail.waitsFor ? {
|
|
1308
|
+
waitsFor: detail.waitsFor.map(bare)
|
|
1309
|
+
} : {},
|
|
1310
|
+
...detail.lifecycleDeliveries ? {
|
|
1311
|
+
lifecycleDeliveries: detail.lifecycleDeliveries.map(bare)
|
|
1312
|
+
} : {}
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
__name(scopeRunLinks, "scopeRunLinks");
|
|
1185
1316
|
var RunRequestResponder = class {
|
|
1186
1317
|
static {
|
|
1187
1318
|
__name(this, "RunRequestResponder");
|
|
@@ -1237,18 +1368,7 @@ var RunRequestResponder = class {
|
|
|
1237
1368
|
tenant
|
|
1238
1369
|
};
|
|
1239
1370
|
const { body } = msg;
|
|
1240
|
-
if (!KNOWN_KINDS.has(body.kind))
|
|
1241
|
-
return {
|
|
1242
|
-
requestId: msg.requestId,
|
|
1243
|
-
result: {
|
|
1244
|
-
ok: false,
|
|
1245
|
-
error: {
|
|
1246
|
-
message: `the control plane does not support the ${String(body.kind)} run request`,
|
|
1247
|
-
code: UNSUPPORTED_RUN_REQUEST
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1371
|
+
if (!KNOWN_KINDS.has(body.kind)) return unsupported(msg.requestId, String(body.kind));
|
|
1252
1372
|
if (body.kind === "listRuns") {
|
|
1253
1373
|
const data = await this.gateway.listRuns({
|
|
1254
1374
|
...body.query,
|
|
@@ -1299,12 +1419,65 @@ var RunRequestResponder = class {
|
|
|
1299
1419
|
}
|
|
1300
1420
|
};
|
|
1301
1421
|
}
|
|
1422
|
+
if (body.kind === "workflowLifecycle") {
|
|
1423
|
+
if (!this.gateway.workflowLifecycle) return unsupported(msg.requestId, body.kind);
|
|
1424
|
+
const data = await this.gateway.workflowLifecycle(body.workflow, {
|
|
1425
|
+
namespace: msg.tenant
|
|
1426
|
+
});
|
|
1427
|
+
return {
|
|
1428
|
+
requestId: msg.requestId,
|
|
1429
|
+
result: {
|
|
1430
|
+
ok: true,
|
|
1431
|
+
data
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
if (body.kind === "republishLifecycle" && !("runId" in body.target)) {
|
|
1436
|
+
if (!this.gateway.republishLifecycle) return unsupported(msg.requestId, body.kind);
|
|
1437
|
+
const { since, until, limit, ...rest } = body.target;
|
|
1438
|
+
if (limit !== void 0 && (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 1)) {
|
|
1439
|
+
return badRequest(msg.requestId, `limit must be a positive integer, got ${JSON.stringify(limit)}`);
|
|
1440
|
+
}
|
|
1441
|
+
const refused = await this.refuseSubscriber(rest.workflow, rest.kind, rest.subscriber, msg.tenant);
|
|
1442
|
+
if (refused) return badRequest(msg.requestId, refused);
|
|
1443
|
+
const target = {
|
|
1444
|
+
...rest,
|
|
1445
|
+
namespace: msg.tenant,
|
|
1446
|
+
limit: Math.min(limit ?? TENANT_REPUBLISH_MAX_LIMIT, TENANT_REPUBLISH_MAX_LIMIT),
|
|
1447
|
+
...since !== void 0 ? {
|
|
1448
|
+
since: wireDate(since)
|
|
1449
|
+
} : {},
|
|
1450
|
+
...until !== void 0 ? {
|
|
1451
|
+
until: wireDate(until)
|
|
1452
|
+
} : {}
|
|
1453
|
+
};
|
|
1454
|
+
try {
|
|
1455
|
+
const data = await this.gateway.republishLifecycle(target);
|
|
1456
|
+
return {
|
|
1457
|
+
requestId: msg.requestId,
|
|
1458
|
+
result: {
|
|
1459
|
+
ok: true,
|
|
1460
|
+
data
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
} catch (err) {
|
|
1464
|
+
return {
|
|
1465
|
+
requestId: msg.requestId,
|
|
1466
|
+
result: {
|
|
1467
|
+
ok: false,
|
|
1468
|
+
error: {
|
|
1469
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1302
1475
|
if (body.kind === "waitingFor") {
|
|
1303
1476
|
const all = await this.gateway.waitingFor(body.runIds);
|
|
1304
|
-
const owned = await Promise.all(Object.entries(all).map(async ([
|
|
1305
|
-
const owner = this.gateway.getRun ? await this.gateway.getRun(
|
|
1477
|
+
const owned = await Promise.all(Object.entries(all).map(async ([runId2, waiting]) => {
|
|
1478
|
+
const owner = this.gateway.getRun ? await this.gateway.getRun(runId2) : (await this.gateway.getRunDetail(runId2))?.run;
|
|
1306
1479
|
return owner && owner.namespace === msg.tenant ? [
|
|
1307
|
-
|
|
1480
|
+
runId2,
|
|
1308
1481
|
waiting
|
|
1309
1482
|
] : void 0;
|
|
1310
1483
|
}));
|
|
@@ -1320,8 +1493,12 @@ var RunRequestResponder = class {
|
|
|
1320
1493
|
}
|
|
1321
1494
|
};
|
|
1322
1495
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1496
|
+
if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
|
|
1497
|
+
return unsupported(msg.requestId, body.kind);
|
|
1498
|
+
}
|
|
1499
|
+
const runId = runIdOf(body);
|
|
1500
|
+
const detail = body.kind === "getRunDetail" || !this.gateway.getRun ? await this.gateway.getRunDetail(runId, body.kind === "getRunDetail" ? body.options : void 0) : void 0;
|
|
1501
|
+
const run = detail !== void 0 ? detail?.run ?? null : await this.gateway.getRun?.(runId);
|
|
1325
1502
|
if (run && run.namespace !== msg.tenant) {
|
|
1326
1503
|
return {
|
|
1327
1504
|
requestId: msg.requestId,
|
|
@@ -1335,11 +1512,12 @@ var RunRequestResponder = class {
|
|
|
1335
1512
|
};
|
|
1336
1513
|
}
|
|
1337
1514
|
if (body.kind === "getRunDetail") {
|
|
1515
|
+
const data = detail ? await this.scopeLifecycle(detail, msg.tenant) : detail;
|
|
1338
1516
|
return {
|
|
1339
1517
|
requestId: msg.requestId,
|
|
1340
1518
|
result: {
|
|
1341
1519
|
ok: true,
|
|
1342
|
-
data
|
|
1520
|
+
data
|
|
1343
1521
|
}
|
|
1344
1522
|
};
|
|
1345
1523
|
}
|
|
@@ -1362,6 +1540,11 @@ var RunRequestResponder = class {
|
|
|
1362
1540
|
}
|
|
1363
1541
|
};
|
|
1364
1542
|
}
|
|
1543
|
+
if (body.kind === "republishLifecycle" && "runId" in body.target && run) {
|
|
1544
|
+
const kind = lifecycleKindOf(run.status);
|
|
1545
|
+
const refused = kind ? await this.refuseSubscriber(run.workflow, kind, body.target.subscriber, msg.tenant) : void 0;
|
|
1546
|
+
if (refused) return badRequest(msg.requestId, refused);
|
|
1547
|
+
}
|
|
1365
1548
|
try {
|
|
1366
1549
|
const data = await this.callVerb(body);
|
|
1367
1550
|
return {
|
|
@@ -1383,8 +1566,71 @@ var RunRequestResponder = class {
|
|
|
1383
1566
|
};
|
|
1384
1567
|
}
|
|
1385
1568
|
}
|
|
1569
|
+
/**
|
|
1570
|
+
* `detail` scoped to `tenant` (see {@link scopeRunLinks}), with its lifecycle links
|
|
1571
|
+
* (`workflowLifecycle`, `lifecycleSubscribers`) narrowed to the subscriptions of `tenant`'s
|
|
1572
|
+
* namespace, as the `workflowLifecycle` verb answers them.
|
|
1573
|
+
*/
|
|
1574
|
+
async scopeLifecycle(input, tenant) {
|
|
1575
|
+
const detail = scopeRunLinks(input, tenant);
|
|
1576
|
+
if (detail.workflowLifecycle === void 0 && detail.lifecycleSubscribers === void 0) {
|
|
1577
|
+
return detail;
|
|
1578
|
+
}
|
|
1579
|
+
const { workflowLifecycle: _links, lifecycleSubscribers: _subscribers, ...rest } = detail;
|
|
1580
|
+
const links = await this.gateway.workflowLifecycle?.(detail.run.workflow, {
|
|
1581
|
+
namespace: tenant
|
|
1582
|
+
});
|
|
1583
|
+
if (!links) return rest;
|
|
1584
|
+
const kind = lifecycleKindOf(detail.run.status);
|
|
1585
|
+
const subscribers = kind ? [
|
|
1586
|
+
...new Set(links.startsOnSettle.filter((l) => l.kind === kind).map((l) => l.workflow))
|
|
1587
|
+
] : [];
|
|
1588
|
+
const linked = links.startsOnSettle.length > 0 || links.startedBy.length > 0;
|
|
1589
|
+
return {
|
|
1590
|
+
...rest,
|
|
1591
|
+
...subscribers.length > 0 ? {
|
|
1592
|
+
lifecycleSubscribers: subscribers
|
|
1593
|
+
} : {},
|
|
1594
|
+
...linked ? {
|
|
1595
|
+
workflowLifecycle: links
|
|
1596
|
+
} : {}
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Why a tenant republish naming `subscriber` is refused, or undefined when it may go ahead: the
|
|
1601
|
+
* subscriber must be owed the event of `workflow` settling (as `kind`, when given) by a run of
|
|
1602
|
+
* the tenant's namespace (the gateway's `lifecycleSubscribers`, else the tenant's
|
|
1603
|
+
* `workflowLifecycle` links), so a tenant cannot have the event owed to an arbitrary name. Without
|
|
1604
|
+
* `subscriber` there is nothing to check.
|
|
1605
|
+
*/
|
|
1606
|
+
async refuseSubscriber(workflow, kind, subscriber, tenant) {
|
|
1607
|
+
if (subscriber === void 0) return void 0;
|
|
1608
|
+
const kinds = kind ? [
|
|
1609
|
+
kind
|
|
1610
|
+
] : [
|
|
1611
|
+
"completed",
|
|
1612
|
+
"failed"
|
|
1613
|
+
];
|
|
1614
|
+
let subscribes = false;
|
|
1615
|
+
if (this.gateway.lifecycleSubscribers) {
|
|
1616
|
+
for (const k of kinds) {
|
|
1617
|
+
const subscribers = await this.gateway.lifecycleSubscribers(workflow, k, tenant);
|
|
1618
|
+
subscribes ||= subscribers.includes(subscriber);
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
const links = await this.gateway.workflowLifecycle?.(workflow, {
|
|
1622
|
+
namespace: tenant
|
|
1623
|
+
});
|
|
1624
|
+
subscribes = links?.startsOnSettle.some((link) => link.workflow === subscriber && kinds.includes(link.kind)) ?? false;
|
|
1625
|
+
}
|
|
1626
|
+
if (subscribes) return void 0;
|
|
1627
|
+
const events = kind ? `run.${kind}:${workflow}` : `run.completed:${workflow} or run.failed:${workflow}`;
|
|
1628
|
+
return `subscriber ${subscriber} does not subscribe to ${events} in namespace ${tenant}`;
|
|
1629
|
+
}
|
|
1386
1630
|
callVerb(body) {
|
|
1387
1631
|
switch (body.kind) {
|
|
1632
|
+
case "republishLifecycle":
|
|
1633
|
+
return this.gateway.republishLifecycle?.(body.target) ?? Promise.reject(new Error("republishLifecycle is not supported"));
|
|
1388
1634
|
case "cancel":
|
|
1389
1635
|
return this.gateway.cancel(body.runId, body.opts);
|
|
1390
1636
|
case "retry":
|
|
@@ -1398,6 +1644,37 @@ var RunRequestResponder = class {
|
|
|
1398
1644
|
}
|
|
1399
1645
|
}
|
|
1400
1646
|
};
|
|
1647
|
+
function runIdOf(body) {
|
|
1648
|
+
if (body.kind !== "republishLifecycle") return body.runId;
|
|
1649
|
+
return "runId" in body.target ? body.target.runId : "";
|
|
1650
|
+
}
|
|
1651
|
+
__name(runIdOf, "runIdOf");
|
|
1652
|
+
function badRequest(requestId, message) {
|
|
1653
|
+
return {
|
|
1654
|
+
requestId,
|
|
1655
|
+
result: {
|
|
1656
|
+
ok: false,
|
|
1657
|
+
error: {
|
|
1658
|
+
message,
|
|
1659
|
+
code: BAD_RUN_REQUEST
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
__name(badRequest, "badRequest");
|
|
1665
|
+
function unsupported(requestId, kind) {
|
|
1666
|
+
return {
|
|
1667
|
+
requestId,
|
|
1668
|
+
result: {
|
|
1669
|
+
ok: false,
|
|
1670
|
+
error: {
|
|
1671
|
+
message: `the control plane does not support the ${kind} run request`,
|
|
1672
|
+
code: UNSUPPORTED_RUN_REQUEST
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
__name(unsupported, "unsupported");
|
|
1401
1678
|
|
|
1402
1679
|
// src/proxy-run-gateway.ts
|
|
1403
1680
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
@@ -1663,6 +1940,42 @@ var ProxyRunGateway = class {
|
|
|
1663
1940
|
runId
|
|
1664
1941
|
});
|
|
1665
1942
|
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Republished on the control plane: a one-run target is checked against this tenant like
|
|
1945
|
+
* `retry`, a by-workflow one is read over this tenant's namespace only. A control plane too old to
|
|
1946
|
+
* know the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error rather than a timeout.
|
|
1947
|
+
*/
|
|
1948
|
+
republishLifecycle(target) {
|
|
1949
|
+
return this.requestNewVerb({
|
|
1950
|
+
kind: "republishLifecycle",
|
|
1951
|
+
target
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
/** Answered by the control plane's engine; same version-skew error as {@link republishLifecycle}. */
|
|
1955
|
+
workflowLifecycle(workflow) {
|
|
1956
|
+
return this.requestNewVerb({
|
|
1957
|
+
kind: "workflowLifecycle",
|
|
1958
|
+
workflow
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* A verb with no fallback on an older control plane: its unsupported-request error, or the empty
|
|
1963
|
+
* `ok: true` reply the oldest responders send for an unknown verb, becomes a
|
|
1964
|
+
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
1965
|
+
*/
|
|
1966
|
+
async requestNewVerb(body) {
|
|
1967
|
+
const notSupported = /* @__PURE__ */ __name(() => new RunGatewayError(`${body.kind} is not supported by this server: the control plane is older than this tenant`, UNSUPPORTED_RUN_REQUEST), "notSupported");
|
|
1968
|
+
if (this.knownUnsupported(body.kind)) throw notSupported();
|
|
1969
|
+
let data;
|
|
1970
|
+
try {
|
|
1971
|
+
data = await this.request(body);
|
|
1972
|
+
} catch (err) {
|
|
1973
|
+
if (!isUnsupported(err)) throw err;
|
|
1974
|
+
}
|
|
1975
|
+
if (data !== void 0 && data !== null) return data;
|
|
1976
|
+
this.unsupportedUntil.set(body.kind, Date.now() + this.capabilityTtlMs);
|
|
1977
|
+
throw notSupported();
|
|
1978
|
+
}
|
|
1666
1979
|
subscribe(runId, onEvent) {
|
|
1667
1980
|
const unsubscribe = this.transport.onTenantEvent?.(this.tenant, (evt) => {
|
|
1668
1981
|
if (evt.event.runId === runId) onEvent(evt.event);
|
|
@@ -1684,8 +1997,8 @@ ProxyRunGateway = _ts_decorate6([
|
|
|
1684
1997
|
], ProxyRunGateway);
|
|
1685
1998
|
|
|
1686
1999
|
// src/retention-poller.ts
|
|
1687
|
-
import { DURABLE_OPTIONS_CANONICAL as
|
|
1688
|
-
import { Inject as
|
|
2000
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL5, STATE_STORE_CANONICAL, TERMINAL_RUN_STATUSES, parseDuration as parseDuration2 } from "@dudousxd/nestjs-durable-core";
|
|
2001
|
+
import { Inject as Inject5, Injectable as Injectable8, Optional as Optional2 } from "@nestjs/common";
|
|
1689
2002
|
|
|
1690
2003
|
// src/settle-within.ts
|
|
1691
2004
|
async function settleWithin(p, timeoutMs) {
|
|
@@ -1710,7 +2023,10 @@ async function settleWithin(p, timeoutMs) {
|
|
|
1710
2023
|
}
|
|
1711
2024
|
__name(settleWithin, "settleWithin");
|
|
1712
2025
|
|
|
1713
|
-
// src/
|
|
2026
|
+
// src/sweep-leases.ts
|
|
2027
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL4 } from "@dudousxd/nestjs-durable-core";
|
|
2028
|
+
import { Inject as Inject4, Injectable as Injectable7, Logger, Optional } from "@nestjs/common";
|
|
2029
|
+
import { ModuleRef } from "@nestjs/core";
|
|
1714
2030
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
1715
2031
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1716
2032
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -1737,6 +2053,110 @@ function _ts_param4(paramIndex, decorator) {
|
|
|
1737
2053
|
};
|
|
1738
2054
|
}
|
|
1739
2055
|
__name(_ts_param4, "_ts_param");
|
|
2056
|
+
var SweepLeases = class {
|
|
2057
|
+
static {
|
|
2058
|
+
__name(this, "SweepLeases");
|
|
2059
|
+
}
|
|
2060
|
+
moduleRef;
|
|
2061
|
+
options;
|
|
2062
|
+
logger = new Logger("nestjs-durable");
|
|
2063
|
+
/** Set by {@link onModuleInit} (before any poller's bootstrap). `null`: no `@nestjs/locks`. */
|
|
2064
|
+
locks = null;
|
|
2065
|
+
leases = /* @__PURE__ */ new Map();
|
|
2066
|
+
constructor(moduleRef, options) {
|
|
2067
|
+
this.moduleRef = moduleRef;
|
|
2068
|
+
this.options = options;
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Run `fn` if this pod holds (or now takes) the lease of `sweep`; otherwise skip it and resolve
|
|
2072
|
+
* `undefined`. Without `@nestjs/locks` it always runs `fn`.
|
|
2073
|
+
*/
|
|
2074
|
+
async run(sweep, fn) {
|
|
2075
|
+
const locks = this.locks;
|
|
2076
|
+
if (!locks) return fn();
|
|
2077
|
+
if (!await this.holds(locks, sweep)) return void 0;
|
|
2078
|
+
return fn();
|
|
2079
|
+
}
|
|
2080
|
+
async holds(locks, sweep) {
|
|
2081
|
+
if (this.leases.get(sweep)?.held) return true;
|
|
2082
|
+
this.leases.delete(sweep);
|
|
2083
|
+
let lock;
|
|
2084
|
+
try {
|
|
2085
|
+
lock = await locks.acquire(this.key(sweep));
|
|
2086
|
+
} catch (error) {
|
|
2087
|
+
this.logger.warn(`could not take the ${sweep} sweep lease; skipping this tick: ${String(error)}`);
|
|
2088
|
+
return false;
|
|
2089
|
+
}
|
|
2090
|
+
if (!lock) return false;
|
|
2091
|
+
this.leases.set(sweep, lock);
|
|
2092
|
+
return true;
|
|
2093
|
+
}
|
|
2094
|
+
key(sweep) {
|
|
2095
|
+
const ns = this.options?.namespace;
|
|
2096
|
+
return ns ? `durable:${sweep}:${ns}` : `durable:${sweep}`;
|
|
2097
|
+
}
|
|
2098
|
+
/** Detects `Locks` once, and logs which mode is active. Nest awaits it before any bootstrap hook. */
|
|
2099
|
+
async onModuleInit() {
|
|
2100
|
+
this.locks = await this.detect();
|
|
2101
|
+
this.logger.log(this.locks ? "fleet-wide sweeps (retention, stalled-run pager, buffered-signal cleanup, expired signal-id cleanup) run on one pod at a time, through @nestjs/locks" : "fleet-wide sweeps run on every driving pod (import LocksModule from @nestjs/locks to run them on one)");
|
|
2102
|
+
}
|
|
2103
|
+
async detect() {
|
|
2104
|
+
let locks = null;
|
|
2105
|
+
if (this.moduleRef) {
|
|
2106
|
+
try {
|
|
2107
|
+
const specifier = "@nestjs/locks";
|
|
2108
|
+
const mod = await import(specifier);
|
|
2109
|
+
if (mod.Locks) {
|
|
2110
|
+
locks = this.moduleRef.get(mod.Locks, {
|
|
2111
|
+
strict: false
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
} catch {
|
|
2115
|
+
locks = null;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
return locks;
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
SweepLeases = _ts_decorate7([
|
|
2122
|
+
Injectable7(),
|
|
2123
|
+
_ts_param4(0, Optional()),
|
|
2124
|
+
_ts_param4(1, Optional()),
|
|
2125
|
+
_ts_param4(1, Inject4(DURABLE_OPTIONS_CANONICAL4)),
|
|
2126
|
+
_ts_metadata7("design:type", Function),
|
|
2127
|
+
_ts_metadata7("design:paramtypes", [
|
|
2128
|
+
typeof ModuleRef === "undefined" ? Object : ModuleRef,
|
|
2129
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2130
|
+
])
|
|
2131
|
+
], SweepLeases);
|
|
2132
|
+
|
|
2133
|
+
// src/retention-poller.ts
|
|
2134
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
2135
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2136
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2137
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2138
|
+
} else {
|
|
2139
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
2140
|
+
if (d = decorators[i]) {
|
|
2141
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2146
|
+
}
|
|
2147
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
2148
|
+
function _ts_metadata8(metadataKey, metadataValue) {
|
|
2149
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2150
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2154
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2155
|
+
return function(target, key) {
|
|
2156
|
+
decorator(target, key, paramIndex);
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
__name(_ts_param5, "_ts_param");
|
|
1740
2160
|
var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
|
|
1741
2161
|
var DEFAULT_BATCH_SIZE = 1e3;
|
|
1742
2162
|
var MAX_BATCHES_PER_POLICY = 100;
|
|
@@ -1750,7 +2170,7 @@ function validateRetention(retention) {
|
|
|
1750
2170
|
if (policy.maxAge == null && policy.maxCount == null) {
|
|
1751
2171
|
throw new Error("durable retention: each policy must set maxAge and/or maxCount");
|
|
1752
2172
|
}
|
|
1753
|
-
if (policy.maxAge != null)
|
|
2173
|
+
if (policy.maxAge != null) parseDuration2(policy.maxAge);
|
|
1754
2174
|
for (const status of policy.statuses) {
|
|
1755
2175
|
if (!TERMINAL_RUN_STATUSES.includes(status)) {
|
|
1756
2176
|
throw new Error(`durable retention: status "${status}" is not terminal; only ${TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
@@ -1779,14 +2199,16 @@ var RetentionPoller = class {
|
|
|
1779
2199
|
}
|
|
1780
2200
|
store;
|
|
1781
2201
|
options;
|
|
2202
|
+
leases;
|
|
1782
2203
|
timer;
|
|
1783
2204
|
sweeping = false;
|
|
1784
2205
|
stopping = false;
|
|
1785
2206
|
/** The sweep in flight, so shutdown can wait for it before the store closes. */
|
|
1786
2207
|
current;
|
|
1787
|
-
constructor(store, options) {
|
|
2208
|
+
constructor(store, options, leases = new SweepLeases()) {
|
|
1788
2209
|
this.store = store;
|
|
1789
2210
|
this.options = options;
|
|
2211
|
+
this.leases = leases;
|
|
1790
2212
|
}
|
|
1791
2213
|
/** Non-null once past the `isDrivingOperator` guard (which requires `options.store` to be set). */
|
|
1792
2214
|
requireStore() {
|
|
@@ -1805,7 +2227,7 @@ var RetentionPoller = class {
|
|
|
1805
2227
|
return;
|
|
1806
2228
|
}
|
|
1807
2229
|
void this.sweep();
|
|
1808
|
-
const intervalMs = retention.sweepInterval != null ?
|
|
2230
|
+
const intervalMs = retention.sweepInterval != null ? parseDuration2(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
|
|
1809
2231
|
if (intervalMs > 0) {
|
|
1810
2232
|
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
1811
2233
|
this.timer.unref?.();
|
|
@@ -1848,37 +2270,42 @@ var RetentionPoller = class {
|
|
|
1848
2270
|
if (!retention || typeof prune !== "function") return;
|
|
1849
2271
|
this.sweeping = true;
|
|
1850
2272
|
try {
|
|
1851
|
-
|
|
1852
|
-
const now = Date.now();
|
|
1853
|
-
for (const policy of retention.policies) {
|
|
1854
|
-
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
1855
|
-
if (this.stopping) return;
|
|
1856
|
-
const deleted = await prune.call(store, policy, now, batchSize);
|
|
1857
|
-
if (deleted < batchSize) break;
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
2273
|
+
await this.leases.run("retention", () => this.prune(retention, store, prune));
|
|
1860
2274
|
} catch (error) {
|
|
1861
2275
|
console.error("[nestjs-durable] retention sweep failed; retrying next interval:", error);
|
|
1862
2276
|
} finally {
|
|
1863
2277
|
this.sweeping = false;
|
|
1864
2278
|
}
|
|
1865
2279
|
}
|
|
2280
|
+
async prune(retention, store, prune) {
|
|
2281
|
+
const batchSize = retention.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
2282
|
+
const now = Date.now();
|
|
2283
|
+
for (const policy of retention.policies) {
|
|
2284
|
+
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
2285
|
+
if (this.stopping) return;
|
|
2286
|
+
const deleted = await prune.call(store, policy, now, batchSize);
|
|
2287
|
+
if (deleted < batchSize) break;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
1866
2291
|
};
|
|
1867
|
-
RetentionPoller =
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2292
|
+
RetentionPoller = _ts_decorate8([
|
|
2293
|
+
Injectable8(),
|
|
2294
|
+
_ts_param5(0, Inject5(STATE_STORE_CANONICAL)),
|
|
2295
|
+
_ts_param5(1, Inject5(DURABLE_OPTIONS_CANONICAL5)),
|
|
2296
|
+
_ts_param5(2, Optional2()),
|
|
2297
|
+
_ts_metadata8("design:type", Function),
|
|
2298
|
+
_ts_metadata8("design:paramtypes", [
|
|
1873
2299
|
Object,
|
|
1874
|
-
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2300
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
2301
|
+
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
1875
2302
|
])
|
|
1876
2303
|
], RetentionPoller);
|
|
1877
2304
|
|
|
1878
2305
|
// src/store-run-gateway.ts
|
|
1879
|
-
import { STATE_STORE_CANONICAL as STATE_STORE_CANONICAL2, SUMMARY_CHILD_LIMIT as SUMMARY_CHILD_LIMIT2, WorkflowEngine as WorkflowEngine2, aggregatesCheckpoints, childIdsOf as childIdsOf2, etagMatches, fanPageEtag, indexWaitersByRun, listSignalWaitersOfRuns, mergeRunFacetRows, pageFan as pageFan2, pageFanFromStore, resolveRunWaiting, runDetailEtag, summarizeRunFromStore, summarizeTimeline as summarizeTimeline2 } from "@dudousxd/nestjs-durable-core";
|
|
1880
|
-
import { Inject as
|
|
1881
|
-
function
|
|
2306
|
+
import { LIFECYCLE_REGISTRY_WORKFLOW, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL2, SUMMARY_CHILD_LIMIT as SUMMARY_CHILD_LIMIT2, WorkflowEngine as WorkflowEngine2, aggregatesCheckpoints, childIdsOf as childIdsOf2, etagMatches, extendEtag, fanPageEtag, indexWaitersByRun, lifecycleDeliveriesOf, lifecycleKindOf as lifecycleKindOf2, lifecycleSourceOf, lifecycleTraceparentOf, listSignalWaitersOfRuns, mergeRunFacetRows, pageFan as pageFan2, pageFanFromStore, readRunsByIds, resolveRunWaiting, runDetailEtag, runWaitPrefix, runWaitTargetOf, summarizeRunFromStore, summarizeTimeline as summarizeTimeline2, traceIdOfTraceparent } from "@dudousxd/nestjs-durable-core";
|
|
2307
|
+
import { Inject as Inject6, Injectable as Injectable9 } from "@nestjs/common";
|
|
2308
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1882
2309
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1883
2310
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1884
2311
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1891,19 +2318,46 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
1891
2318
|
}
|
|
1892
2319
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1893
2320
|
}
|
|
1894
|
-
__name(
|
|
1895
|
-
function
|
|
2321
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
2322
|
+
function _ts_metadata9(metadataKey, metadataValue) {
|
|
1896
2323
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1897
2324
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1898
2325
|
}
|
|
1899
2326
|
}
|
|
1900
|
-
__name(
|
|
1901
|
-
function
|
|
2327
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2328
|
+
function _ts_param6(paramIndex, decorator) {
|
|
1902
2329
|
return function(target, key) {
|
|
1903
2330
|
decorator(target, key, paramIndex);
|
|
1904
2331
|
};
|
|
1905
2332
|
}
|
|
1906
|
-
__name(
|
|
2333
|
+
__name(_ts_param6, "_ts_param");
|
|
2334
|
+
function detailExtras(links) {
|
|
2335
|
+
const { lifecycleSubscribers, lifecycleDeliveries, waitsFor, awaitedBy, triggeredBy } = links;
|
|
2336
|
+
if (!lifecycleSubscribers && !lifecycleDeliveries && !waitsFor && !awaitedBy && !triggeredBy) {
|
|
2337
|
+
return void 0;
|
|
2338
|
+
}
|
|
2339
|
+
return {
|
|
2340
|
+
lifecycleSubscribers,
|
|
2341
|
+
lifecycleDeliveries,
|
|
2342
|
+
waitsFor,
|
|
2343
|
+
awaitedBy,
|
|
2344
|
+
triggeredBy
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
__name(detailExtras, "detailExtras");
|
|
2348
|
+
function withoutRegistry(query) {
|
|
2349
|
+
if (query.workflow === LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(LIFECYCLE_REGISTRY_WORKFLOW)) {
|
|
2350
|
+
return query;
|
|
2351
|
+
}
|
|
2352
|
+
return {
|
|
2353
|
+
...query,
|
|
2354
|
+
excludeWorkflows: [
|
|
2355
|
+
...query.excludeWorkflows ?? [],
|
|
2356
|
+
LIFECYCLE_REGISTRY_WORKFLOW
|
|
2357
|
+
]
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
__name(withoutRegistry, "withoutRegistry");
|
|
1907
2361
|
var StoreRunGateway = class {
|
|
1908
2362
|
static {
|
|
1909
2363
|
__name(this, "StoreRunGateway");
|
|
@@ -1922,6 +2376,7 @@ var StoreRunGateway = class {
|
|
|
1922
2376
|
async getRunDetail(runId, options) {
|
|
1923
2377
|
const run = await this.store.getRun(runId);
|
|
1924
2378
|
if (!run) return null;
|
|
2379
|
+
const links = await this.lifecycleLinks(run);
|
|
1925
2380
|
const over = options?.summarizeFansOver;
|
|
1926
2381
|
if (over === void 0) {
|
|
1927
2382
|
const [timeline2, children] = await Promise.all([
|
|
@@ -1931,12 +2386,13 @@ var StoreRunGateway = class {
|
|
|
1931
2386
|
return {
|
|
1932
2387
|
run,
|
|
1933
2388
|
timeline: timeline2,
|
|
1934
|
-
children
|
|
2389
|
+
children,
|
|
2390
|
+
...links
|
|
1935
2391
|
};
|
|
1936
2392
|
}
|
|
1937
2393
|
if (aggregatesCheckpoints(this.store)) {
|
|
1938
2394
|
const stats = await this.store.checkpointStats(runId);
|
|
1939
|
-
const etag = runDetailEtag(run, stats, over);
|
|
2395
|
+
const etag = extendEtag(runDetailEtag(run, stats, over), detailExtras(links));
|
|
1940
2396
|
if (etagMatches(options?.ifNoneMatch, etag)) {
|
|
1941
2397
|
return {
|
|
1942
2398
|
run,
|
|
@@ -1949,7 +2405,8 @@ var StoreRunGateway = class {
|
|
|
1949
2405
|
return {
|
|
1950
2406
|
run,
|
|
1951
2407
|
...await summarizeRunFromStore(this.store, runId, over, stats),
|
|
1952
|
-
etag
|
|
2408
|
+
etag,
|
|
2409
|
+
...links
|
|
1953
2410
|
};
|
|
1954
2411
|
}
|
|
1955
2412
|
const full = await this.store.listCheckpoints(runId);
|
|
@@ -1960,9 +2417,108 @@ var StoreRunGateway = class {
|
|
|
1960
2417
|
timeline,
|
|
1961
2418
|
children: ids.slice(0, SUMMARY_CHILD_LIMIT2),
|
|
1962
2419
|
fans,
|
|
1963
|
-
childCount: ids.length
|
|
2420
|
+
childCount: ids.length,
|
|
2421
|
+
...links
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
/**
|
|
2425
|
+
* What a run detail reads beyond the run row and its checkpoints: what this run's settling
|
|
2426
|
+
* started, the subscribers its lifecycle event goes to (of its namespace) and where it stands for
|
|
2427
|
+
* each, what started it, its workflow's lifecycle links, and the `ctx.waitForRun` waits on either
|
|
2428
|
+
* side of it with the other run's status. A few reads per detail: the run's own waiters while it
|
|
2429
|
+
* is suspended, the waiters on it (one prefix read), and one batched read of every linked run.
|
|
2430
|
+
*/
|
|
2431
|
+
async lifecycleLinks(run) {
|
|
2432
|
+
const triggered = await this.engine.triggeredRuns(run);
|
|
2433
|
+
const source = lifecycleSourceOf(run);
|
|
2434
|
+
const kind = lifecycleKindOf2(run.status);
|
|
2435
|
+
const subscribers = kind ? await this.engine.lifecycleSubscribers(run.workflow, kind, run.namespace || "default") : [];
|
|
2436
|
+
const workflowLifecycle = await this.engine.workflowLifecycle(run.workflow);
|
|
2437
|
+
const linked = workflowLifecycle.startsOnSettle.length > 0 || workflowLifecycle.startedBy.length > 0;
|
|
2438
|
+
const deliveries = kind ? lifecycleDeliveriesOf(run, {
|
|
2439
|
+
subscribers,
|
|
2440
|
+
live: new Set(subscribers),
|
|
2441
|
+
coalesced: this.engine.coalescedSubscribers(run)
|
|
2442
|
+
}) : [];
|
|
2443
|
+
const [own, onIt] = await Promise.all([
|
|
2444
|
+
run.status === "suspended" ? listSignalWaitersOfRuns(this.store, [
|
|
2445
|
+
run.id
|
|
2446
|
+
]) : [],
|
|
2447
|
+
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters(runWaitPrefix(run.id))
|
|
2448
|
+
]);
|
|
2449
|
+
const waitsFor = own.flatMap((w) => {
|
|
2450
|
+
const target = runWaitTargetOf(w);
|
|
2451
|
+
return target !== void 0 ? [
|
|
2452
|
+
{
|
|
2453
|
+
runId: target,
|
|
2454
|
+
seq: w.seq
|
|
2455
|
+
}
|
|
2456
|
+
] : [];
|
|
2457
|
+
});
|
|
2458
|
+
const awaitedBy = onIt.filter((w) => runWaitTargetOf(w) === run.id).map((w) => ({
|
|
2459
|
+
runId: w.runId,
|
|
2460
|
+
seq: w.seq
|
|
2461
|
+
}));
|
|
2462
|
+
const started = deliveries.flatMap((d) => d.state === "started" && d.runId !== void 0 ? [
|
|
2463
|
+
d.runId
|
|
2464
|
+
] : []);
|
|
2465
|
+
const { runs } = await readRunsByIds(this.store, [
|
|
2466
|
+
...source ? [
|
|
2467
|
+
source.runId
|
|
2468
|
+
] : [],
|
|
2469
|
+
...started,
|
|
2470
|
+
...waitsFor.map((l) => l.runId),
|
|
2471
|
+
...awaitedBy.map((l) => l.runId)
|
|
2472
|
+
]);
|
|
2473
|
+
const withRun = /* @__PURE__ */ __name((link) => {
|
|
2474
|
+
const other = link.runId !== void 0 ? runs.get(link.runId) : void 0;
|
|
2475
|
+
return other ? {
|
|
2476
|
+
...link,
|
|
2477
|
+
status: other.status,
|
|
2478
|
+
namespace: other.namespace
|
|
2479
|
+
} : link;
|
|
2480
|
+
}, "withRun");
|
|
2481
|
+
const sourceRun = source ? runs.get(source.runId) : void 0;
|
|
2482
|
+
const traceId = traceIdOfTraceparent(lifecycleTraceparentOf(sourceRun?.tags));
|
|
2483
|
+
return {
|
|
2484
|
+
...triggered.length > 0 ? {
|
|
2485
|
+
triggered
|
|
2486
|
+
} : {},
|
|
2487
|
+
...source ? {
|
|
2488
|
+
triggeredBy: {
|
|
2489
|
+
...source,
|
|
2490
|
+
...sourceRun ? {
|
|
2491
|
+
status: sourceRun.status,
|
|
2492
|
+
namespace: sourceRun.namespace
|
|
2493
|
+
} : {},
|
|
2494
|
+
...traceId ? {
|
|
2495
|
+
traceId
|
|
2496
|
+
} : {}
|
|
2497
|
+
}
|
|
2498
|
+
} : {},
|
|
2499
|
+
...subscribers.length > 0 ? {
|
|
2500
|
+
lifecycleSubscribers: subscribers
|
|
2501
|
+
} : {},
|
|
2502
|
+
...linked ? {
|
|
2503
|
+
workflowLifecycle
|
|
2504
|
+
} : {},
|
|
2505
|
+
...deliveries.length > 0 ? {
|
|
2506
|
+
lifecycleDeliveries: deliveries.map((d) => d.state === "started" ? withRun(d) : d)
|
|
2507
|
+
} : {},
|
|
2508
|
+
...waitsFor.length > 0 ? {
|
|
2509
|
+
waitsFor: waitsFor.map(withRun)
|
|
2510
|
+
} : {},
|
|
2511
|
+
...awaitedBy.length > 0 ? {
|
|
2512
|
+
awaitedBy: awaitedBy.map(withRun)
|
|
2513
|
+
} : {}
|
|
1964
2514
|
};
|
|
1965
2515
|
}
|
|
2516
|
+
workflowLifecycle(workflow, opts) {
|
|
2517
|
+
return this.engine.workflowLifecycle(workflow, opts);
|
|
2518
|
+
}
|
|
2519
|
+
lifecycleSubscribers(workflow, kind, namespace) {
|
|
2520
|
+
return this.engine.lifecycleSubscribers(workflow, kind, namespace);
|
|
2521
|
+
}
|
|
1966
2522
|
getRun(runId) {
|
|
1967
2523
|
return this.store.getRun(runId);
|
|
1968
2524
|
}
|
|
@@ -1989,7 +2545,7 @@ var StoreRunGateway = class {
|
|
|
1989
2545
|
return pageFan2(await this.store.listCheckpoints(runId), group, query);
|
|
1990
2546
|
}
|
|
1991
2547
|
async listRuns(query) {
|
|
1992
|
-
const runs = await this.store.listRuns(query);
|
|
2548
|
+
const runs = await this.store.listRuns(withoutRegistry(query));
|
|
1993
2549
|
const waiterByRun = indexWaitersByRun(await listSignalWaitersOfRuns(this.store, runs.filter((run) => run.status === "suspended").map((run) => run.id)));
|
|
1994
2550
|
return runs.map((run) => {
|
|
1995
2551
|
const waiting = resolveRunWaiting(run, waiterByRun);
|
|
@@ -2006,8 +2562,9 @@ var StoreRunGateway = class {
|
|
|
2006
2562
|
* listing — correct, but the unbounded read this exists to avoid, so it is the last resort.
|
|
2007
2563
|
*/
|
|
2008
2564
|
async runFacets(query) {
|
|
2009
|
-
|
|
2010
|
-
|
|
2565
|
+
const scoped = withoutRegistry(query);
|
|
2566
|
+
if (this.store.runFacets) return this.store.runFacets(scoped);
|
|
2567
|
+
const runs = await this.store.listRuns(scoped);
|
|
2011
2568
|
return mergeRunFacetRows(runs.map((r) => ({
|
|
2012
2569
|
status: r.status,
|
|
2013
2570
|
origin: r.origin,
|
|
@@ -2022,7 +2579,7 @@ var StoreRunGateway = class {
|
|
|
2022
2579
|
* still works without it.
|
|
2023
2580
|
*/
|
|
2024
2581
|
async runValueFacets(axis, query, opts) {
|
|
2025
|
-
return this.store.runValueFacets?.(axis, query, opts) ?? [];
|
|
2582
|
+
return this.store.runValueFacets?.(axis, withoutRegistry(query), opts) ?? [];
|
|
2026
2583
|
}
|
|
2027
2584
|
/**
|
|
2028
2585
|
* Bulk-resolve what each of `runIds` is currently parked on — for a consumer with its own filtered/
|
|
@@ -2075,17 +2632,20 @@ var StoreRunGateway = class {
|
|
|
2075
2632
|
redispatchPending(runId) {
|
|
2076
2633
|
return this.engine.redispatchPending(runId);
|
|
2077
2634
|
}
|
|
2635
|
+
republishLifecycle(target) {
|
|
2636
|
+
return this.engine.republishLifecycle(target);
|
|
2637
|
+
}
|
|
2078
2638
|
subscribe(runId, onEvent) {
|
|
2079
2639
|
return this.engine.subscribe((event) => {
|
|
2080
2640
|
if (event.runId === runId) onEvent(event);
|
|
2081
2641
|
});
|
|
2082
2642
|
}
|
|
2083
2643
|
};
|
|
2084
|
-
StoreRunGateway =
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2644
|
+
StoreRunGateway = _ts_decorate9([
|
|
2645
|
+
Injectable9(),
|
|
2646
|
+
_ts_param6(0, Inject6(STATE_STORE_CANONICAL2)),
|
|
2647
|
+
_ts_metadata9("design:type", Function),
|
|
2648
|
+
_ts_metadata9("design:paramtypes", [
|
|
2089
2649
|
typeof StateStore === "undefined" ? Object : StateStore,
|
|
2090
2650
|
typeof WorkflowEngine2 === "undefined" ? Object : WorkflowEngine2
|
|
2091
2651
|
])
|
|
@@ -2133,9 +2693,9 @@ var TenantEventRepublisher = class {
|
|
|
2133
2693
|
};
|
|
2134
2694
|
|
|
2135
2695
|
// src/timer-poller.ts
|
|
2136
|
-
import { DURABLE_OPTIONS_CANONICAL as
|
|
2137
|
-
import { Inject as
|
|
2138
|
-
function
|
|
2696
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, WorkflowEngine as WorkflowEngine3, runSchedules, workflowName as workflowName3 } from "@dudousxd/nestjs-durable-core";
|
|
2697
|
+
import { Inject as Inject7, Injectable as Injectable10, Optional as Optional3 } from "@nestjs/common";
|
|
2698
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
2139
2699
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2140
2700
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2141
2701
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2148,33 +2708,35 @@ function _ts_decorate9(decorators, target, key, desc) {
|
|
|
2148
2708
|
}
|
|
2149
2709
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2150
2710
|
}
|
|
2151
|
-
__name(
|
|
2152
|
-
function
|
|
2711
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
2712
|
+
function _ts_metadata10(metadataKey, metadataValue) {
|
|
2153
2713
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2154
2714
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2155
2715
|
}
|
|
2156
2716
|
}
|
|
2157
|
-
__name(
|
|
2158
|
-
function
|
|
2717
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2718
|
+
function _ts_param7(paramIndex, decorator) {
|
|
2159
2719
|
return function(target, key) {
|
|
2160
2720
|
decorator(target, key, paramIndex);
|
|
2161
2721
|
};
|
|
2162
2722
|
}
|
|
2163
|
-
__name(
|
|
2723
|
+
__name(_ts_param7, "_ts_param");
|
|
2164
2724
|
var TimerPoller = class {
|
|
2165
2725
|
static {
|
|
2166
2726
|
__name(this, "TimerPoller");
|
|
2167
2727
|
}
|
|
2168
2728
|
engine;
|
|
2169
2729
|
options;
|
|
2730
|
+
leases;
|
|
2170
2731
|
timer;
|
|
2171
2732
|
polling = false;
|
|
2172
2733
|
/** The sweep in flight, so shutdown can wait for it instead of racing the store's close. */
|
|
2173
2734
|
current;
|
|
2174
2735
|
unsubscribeEnqueued;
|
|
2175
|
-
constructor(engine, options) {
|
|
2736
|
+
constructor(engine, options, leases = new SweepLeases()) {
|
|
2176
2737
|
this.engine = engine;
|
|
2177
2738
|
this.options = options;
|
|
2739
|
+
this.leases = leases;
|
|
2178
2740
|
}
|
|
2179
2741
|
async onApplicationBootstrap() {
|
|
2180
2742
|
for (const s of this.options.schedules ?? []) workflowName3(s.workflow);
|
|
@@ -2247,8 +2809,10 @@ var TimerPoller = class {
|
|
|
2247
2809
|
await this.sweep("recoverIncomplete", () => this.engine.recoverIncomplete());
|
|
2248
2810
|
await this.sweep("resumeDueTimers", () => this.engine.resumeDueTimers());
|
|
2249
2811
|
await this.sweep("sweepTimeouts", () => this.engine.sweepTimeouts());
|
|
2250
|
-
await this.sweep("sweepStalled", async () => this.engine.sweepStalled?.());
|
|
2251
|
-
await this.sweep("sweepBufferedSignals", async () => this.engine.sweepBufferedSignals?.());
|
|
2812
|
+
await this.sweep("sweepStalled", () => this.leases.run("stalled-pager", async () => this.engine.sweepStalled?.()));
|
|
2813
|
+
await this.sweep("sweepBufferedSignals", () => this.leases.run("buffered-signals", async () => this.engine.sweepBufferedSignals?.()));
|
|
2814
|
+
await this.sweep("sweepExpiredSignalIds", () => this.leases.run("signal-ids", async () => this.engine.sweepExpiredSignalIds?.()));
|
|
2815
|
+
await this.sweep("sweepLifecycleEvents", async () => this.engine.sweepLifecycleEvents?.());
|
|
2252
2816
|
const schedules = this.options.schedules;
|
|
2253
2817
|
if (schedules && schedules.length > 0) {
|
|
2254
2818
|
await this.sweep("schedules", () => runSchedules(this.engine, schedules, Date.now()));
|
|
@@ -2267,13 +2831,15 @@ var TimerPoller = class {
|
|
|
2267
2831
|
}
|
|
2268
2832
|
}
|
|
2269
2833
|
};
|
|
2270
|
-
TimerPoller =
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2834
|
+
TimerPoller = _ts_decorate10([
|
|
2835
|
+
Injectable10(),
|
|
2836
|
+
_ts_param7(1, Inject7(DURABLE_OPTIONS_CANONICAL6)),
|
|
2837
|
+
_ts_param7(2, Optional3()),
|
|
2838
|
+
_ts_metadata10("design:type", Function),
|
|
2839
|
+
_ts_metadata10("design:paramtypes", [
|
|
2275
2840
|
typeof WorkflowEngine3 === "undefined" ? Object : WorkflowEngine3,
|
|
2276
|
-
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2841
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
2842
|
+
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
2277
2843
|
])
|
|
2278
2844
|
], TimerPoller);
|
|
2279
2845
|
|
|
@@ -2283,8 +2849,8 @@ var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
|
2283
2849
|
var RUN_GATEWAY = RunGateway;
|
|
2284
2850
|
|
|
2285
2851
|
// src/workflow.registrar.ts
|
|
2286
|
-
import { DURABLE_OPTIONS_CANONICAL as
|
|
2287
|
-
import { Inject as
|
|
2852
|
+
import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL7, RemoteWorkflowExecutor, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, WorkflowEngine as WorkflowEngine4, bindWorkflowClass, sanitizeQueueToken, tenantGroup, workflowName as workflowName4 } from "@dudousxd/nestjs-durable-core";
|
|
2853
|
+
import { Inject as Inject8, Injectable as Injectable11 } from "@nestjs/common";
|
|
2288
2854
|
import { DiscoveryService as DiscoveryService4, MetadataScanner as MetadataScanner4 } from "@nestjs/core";
|
|
2289
2855
|
|
|
2290
2856
|
// src/step-interceptor.ts
|
|
@@ -2302,7 +2868,7 @@ function isStepInterceptor(target) {
|
|
|
2302
2868
|
__name(isStepInterceptor, "isStepInterceptor");
|
|
2303
2869
|
|
|
2304
2870
|
// src/workflow.registrar.ts
|
|
2305
|
-
function
|
|
2871
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2306
2872
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2307
2873
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2308
2874
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2315,19 +2881,19 @@ function _ts_decorate10(decorators, target, key, desc) {
|
|
|
2315
2881
|
}
|
|
2316
2882
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2317
2883
|
}
|
|
2318
|
-
__name(
|
|
2319
|
-
function
|
|
2884
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
2885
|
+
function _ts_metadata11(metadataKey, metadataValue) {
|
|
2320
2886
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2321
2887
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2322
2888
|
}
|
|
2323
2889
|
}
|
|
2324
|
-
__name(
|
|
2325
|
-
function
|
|
2890
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
2891
|
+
function _ts_param8(paramIndex, decorator) {
|
|
2326
2892
|
return function(target, key) {
|
|
2327
2893
|
decorator(target, key, paramIndex);
|
|
2328
2894
|
};
|
|
2329
2895
|
}
|
|
2330
|
-
__name(
|
|
2896
|
+
__name(_ts_param8, "_ts_param");
|
|
2331
2897
|
var UNSERVED_ROUTES_RECHECK_MS = 3e4;
|
|
2332
2898
|
var WorkflowRegistrar = class {
|
|
2333
2899
|
static {
|
|
@@ -2391,15 +2957,8 @@ var WorkflowRegistrar = class {
|
|
|
2391
2957
|
if (origin === void 0) unattributed.push(meta.name);
|
|
2392
2958
|
const io = workflowIo(meta);
|
|
2393
2959
|
const body = io.wrap((ctx, input) => workflow.run(ctx, input));
|
|
2394
|
-
const eventBatch = meta.debounce ? {
|
|
2395
|
-
mode: "debounce",
|
|
2396
|
-
windowMs: parseDuration2(meta.debounce)
|
|
2397
|
-
} : meta.batch ? {
|
|
2398
|
-
mode: "batch",
|
|
2399
|
-
maxSize: meta.batch.maxSize,
|
|
2400
|
-
windowMs: parseDuration2(meta.batch.within)
|
|
2401
|
-
} : void 0;
|
|
2402
2960
|
const workflowCtor = workflow.constructor;
|
|
2961
|
+
const eventBatch = eventBatchOf(meta, workflowCtor);
|
|
2403
2962
|
const onError = onErrorHandlersOf(meta, workflow, this.metadataScanner);
|
|
2404
2963
|
for (const [name, fn] of onError.handlers) {
|
|
2405
2964
|
this.engine.register(name, meta.version, fn, {
|
|
@@ -2521,13 +3080,13 @@ var WorkflowRegistrar = class {
|
|
|
2521
3080
|
});
|
|
2522
3081
|
}
|
|
2523
3082
|
};
|
|
2524
|
-
WorkflowRegistrar =
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
3083
|
+
WorkflowRegistrar = _ts_decorate11([
|
|
3084
|
+
Injectable11(),
|
|
3085
|
+
_ts_param8(3, Inject8(STATE_STORE_CANONICAL3)),
|
|
3086
|
+
_ts_param8(4, Inject8(DURABLE_OPTIONS_CANONICAL7)),
|
|
3087
|
+
_ts_param8(5, Inject8(IN_APP_WORKER_BINDING)),
|
|
3088
|
+
_ts_metadata11("design:type", Function),
|
|
3089
|
+
_ts_metadata11("design:paramtypes", [
|
|
2531
3090
|
typeof DiscoveryService4 === "undefined" ? Object : DiscoveryService4,
|
|
2532
3091
|
typeof MetadataScanner4 === "undefined" ? Object : MetadataScanner4,
|
|
2533
3092
|
typeof WorkflowEngine4 === "undefined" ? Object : WorkflowEngine4,
|
|
@@ -2540,8 +3099,8 @@ WorkflowRegistrar = _ts_decorate10([
|
|
|
2540
3099
|
// src/workflow.service.ts
|
|
2541
3100
|
import { randomUUID } from "node:crypto";
|
|
2542
3101
|
import { WorkflowEngine as WorkflowEngine5 } from "@dudousxd/nestjs-durable-core";
|
|
2543
|
-
import { Injectable as
|
|
2544
|
-
function
|
|
3102
|
+
import { Injectable as Injectable12 } from "@nestjs/common";
|
|
3103
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2545
3104
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2546
3105
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2547
3106
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2554,13 +3113,13 @@ function _ts_decorate11(decorators, target, key, desc) {
|
|
|
2554
3113
|
}
|
|
2555
3114
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2556
3115
|
}
|
|
2557
|
-
__name(
|
|
2558
|
-
function
|
|
3116
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
3117
|
+
function _ts_metadata12(metadataKey, metadataValue) {
|
|
2559
3118
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2560
3119
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2561
3120
|
}
|
|
2562
3121
|
}
|
|
2563
|
-
__name(
|
|
3122
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
2564
3123
|
var WorkflowService = class {
|
|
2565
3124
|
static {
|
|
2566
3125
|
__name(this, "WorkflowService");
|
|
@@ -2585,9 +3144,13 @@ var WorkflowService = class {
|
|
|
2585
3144
|
waitForRun(runId, opts) {
|
|
2586
3145
|
return this.engine.waitForRun(runId, opts);
|
|
2587
3146
|
}
|
|
2588
|
-
/**
|
|
2589
|
-
signal(
|
|
2590
|
-
|
|
3147
|
+
/**
|
|
3148
|
+
* Deliver an external signal (e.g. from a webhook) to the run waiting on `token`, or buffer it for
|
|
3149
|
+
* the next wait on it. With `{ id }`, a re-send with the same token and id is dropped (resolves
|
|
3150
|
+
* `null`): see {@link SignalOptions}.
|
|
3151
|
+
*/
|
|
3152
|
+
signal(token, payload, opts) {
|
|
3153
|
+
return this.engine.signal(token, payload, opts);
|
|
2591
3154
|
}
|
|
2592
3155
|
signalWithStart(workflow, input, runId, signal, opts) {
|
|
2593
3156
|
return this.engine.signalWithStart(workflow, input, runId, signal, opts);
|
|
@@ -2605,17 +3168,33 @@ var WorkflowService = class {
|
|
|
2605
3168
|
publishEvent(name, payload, opts) {
|
|
2606
3169
|
return this.engine.publishEvent(name, payload, opts);
|
|
2607
3170
|
}
|
|
3171
|
+
/**
|
|
3172
|
+
* The runs started by `runId` settling, through `@OnWorkflowCompleted` / `@OnWorkflowFailed` (or
|
|
3173
|
+
* an `onEvent` on `runCompletedEvent(...)`). Only subscribers registered on this engine are
|
|
3174
|
+
* considered. For the reverse link, `lifecycleSourceOf(run)` reads it from the run itself.
|
|
3175
|
+
*/
|
|
3176
|
+
triggeredRuns(runId) {
|
|
3177
|
+
return this.engine.triggeredRuns(runId);
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* Publish settled runs' lifecycle events again: to a subscriber registered after they settled, or
|
|
3181
|
+
* one restricted by `subscriber`. Subscribers already started for a run are not started again.
|
|
3182
|
+
* See `WorkflowEngine.republishLifecycle`.
|
|
3183
|
+
*/
|
|
3184
|
+
republishLifecycle(target) {
|
|
3185
|
+
return this.engine.republishLifecycle(target);
|
|
3186
|
+
}
|
|
2608
3187
|
};
|
|
2609
|
-
WorkflowService =
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
3188
|
+
WorkflowService = _ts_decorate12([
|
|
3189
|
+
Injectable12(),
|
|
3190
|
+
_ts_metadata12("design:type", Function),
|
|
3191
|
+
_ts_metadata12("design:paramtypes", [
|
|
2613
3192
|
typeof WorkflowEngine5 === "undefined" ? Object : WorkflowEngine5
|
|
2614
3193
|
])
|
|
2615
3194
|
], WorkflowService);
|
|
2616
3195
|
|
|
2617
3196
|
// src/durable.module.ts
|
|
2618
|
-
function
|
|
3197
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
2619
3198
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2620
3199
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2621
3200
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2628,19 +3207,19 @@ function _ts_decorate12(decorators, target, key, desc) {
|
|
|
2628
3207
|
}
|
|
2629
3208
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2630
3209
|
}
|
|
2631
|
-
__name(
|
|
2632
|
-
function
|
|
3210
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
3211
|
+
function _ts_metadata13(metadataKey, metadataValue) {
|
|
2633
3212
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2634
3213
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2635
3214
|
}
|
|
2636
3215
|
}
|
|
2637
|
-
__name(
|
|
2638
|
-
function
|
|
3216
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
3217
|
+
function _ts_param9(paramIndex, decorator) {
|
|
2639
3218
|
return function(target, key) {
|
|
2640
3219
|
decorator(target, key, paramIndex);
|
|
2641
3220
|
};
|
|
2642
3221
|
}
|
|
2643
|
-
__name(
|
|
3222
|
+
__name(_ts_param9, "_ts_param");
|
|
2644
3223
|
function resolveAccessor(moduleRef) {
|
|
2645
3224
|
try {
|
|
2646
3225
|
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
@@ -2828,13 +3407,13 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
|
|
|
2828
3407
|
this.unsubscribe?.();
|
|
2829
3408
|
}
|
|
2830
3409
|
};
|
|
2831
|
-
RunGatewayBootstrap =
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
3410
|
+
RunGatewayBootstrap = _ts_decorate13([
|
|
3411
|
+
Injectable13(),
|
|
3412
|
+
_ts_param9(1, Inject9(TRANSPORT_CANONICAL3)),
|
|
3413
|
+
_ts_param9(3, Inject9(STATE_STORE_CANONICAL4)),
|
|
3414
|
+
_ts_param9(4, Inject9(DURABLE_OPTIONS_CANONICAL8)),
|
|
3415
|
+
_ts_metadata13("design:type", Function),
|
|
3416
|
+
_ts_metadata13("design:paramtypes", [
|
|
2838
3417
|
typeof WorkflowEngine6 === "undefined" ? Object : WorkflowEngine6,
|
|
2839
3418
|
Object,
|
|
2840
3419
|
typeof RunGateway2 === "undefined" ? Object : RunGateway2,
|
|
@@ -2849,13 +3428,13 @@ var DurableModule = class _DurableModule {
|
|
|
2849
3428
|
static forRoot(options) {
|
|
2850
3429
|
_DurableModule.assertValid(options);
|
|
2851
3430
|
return _DurableModule.build({
|
|
2852
|
-
provide:
|
|
3431
|
+
provide: DURABLE_OPTIONS_CANONICAL8,
|
|
2853
3432
|
useValue: resolveTopology(options)
|
|
2854
3433
|
});
|
|
2855
3434
|
}
|
|
2856
3435
|
static forRootAsync(options) {
|
|
2857
3436
|
return _DurableModule.build({
|
|
2858
|
-
provide:
|
|
3437
|
+
provide: DURABLE_OPTIONS_CANONICAL8,
|
|
2859
3438
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
2860
3439
|
const resolved = await options.useFactory(...args);
|
|
2861
3440
|
_DurableModule.assertValid(resolved);
|
|
@@ -2891,7 +3470,7 @@ var DurableModule = class _DurableModule {
|
|
|
2891
3470
|
provide: STATE_STORE_CANONICAL4,
|
|
2892
3471
|
useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
|
|
2893
3472
|
inject: [
|
|
2894
|
-
|
|
3473
|
+
DURABLE_OPTIONS_CANONICAL8
|
|
2895
3474
|
]
|
|
2896
3475
|
},
|
|
2897
3476
|
{
|
|
@@ -2902,7 +3481,7 @@ var DurableModule = class _DurableModule {
|
|
|
2902
3481
|
// registered NO step handlers and its own steps parked in `wait` with no consumer.
|
|
2903
3482
|
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
|
|
2904
3483
|
inject: [
|
|
2905
|
-
|
|
3484
|
+
DURABLE_OPTIONS_CANONICAL8
|
|
2906
3485
|
]
|
|
2907
3486
|
},
|
|
2908
3487
|
// Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
|
|
@@ -2916,7 +3495,7 @@ var DurableModule = class _DurableModule {
|
|
|
2916
3495
|
},
|
|
2917
3496
|
{
|
|
2918
3497
|
provide: DURABLE_OPTIONS,
|
|
2919
|
-
useExisting:
|
|
3498
|
+
useExisting: DURABLE_OPTIONS_CANONICAL8
|
|
2920
3499
|
},
|
|
2921
3500
|
{
|
|
2922
3501
|
// Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
|
|
@@ -2959,8 +3538,12 @@ var DurableModule = class _DurableModule {
|
|
|
2959
3538
|
stalledAfterMs: options.stalledAfterMs,
|
|
2960
3539
|
timerBatchSize: options.timerBatchSize,
|
|
2961
3540
|
eventBufferTtlMs: options.eventBufferTtlMs,
|
|
3541
|
+
signalIdTtl: options.signalIdTtl,
|
|
2962
3542
|
blockedPollMs: options.blockedPollMs,
|
|
2963
3543
|
trackStepStart: options.trackStepStart,
|
|
3544
|
+
stickyRuns: options.stickyRuns,
|
|
3545
|
+
stickyIdleMs: options.stickyIdleMs,
|
|
3546
|
+
routeReplies: options.routeReplies,
|
|
2964
3547
|
instanceId: options.instanceId,
|
|
2965
3548
|
namespace: options.namespace,
|
|
2966
3549
|
webhookUrl: options.webhookUrl,
|
|
@@ -2985,16 +3568,17 @@ var DurableModule = class _DurableModule {
|
|
|
2985
3568
|
return engine;
|
|
2986
3569
|
}, "useFactory"),
|
|
2987
3570
|
inject: [
|
|
2988
|
-
|
|
3571
|
+
DURABLE_OPTIONS_CANONICAL8,
|
|
2989
3572
|
STATE_STORE_CANONICAL4,
|
|
2990
3573
|
TRANSPORT_CANONICAL3,
|
|
2991
|
-
|
|
3574
|
+
ModuleRef2
|
|
2992
3575
|
]
|
|
2993
3576
|
},
|
|
2994
3577
|
WorkflowService,
|
|
2995
3578
|
EntityService,
|
|
2996
3579
|
WorkflowRegistrar,
|
|
2997
3580
|
DurableStepRegistrar,
|
|
3581
|
+
SweepLeases,
|
|
2998
3582
|
TimerPoller,
|
|
2999
3583
|
RetentionPoller,
|
|
3000
3584
|
// Tenant run gateway: bound EXACTLY once — the store-backed `StoreRunGateway` for an operator,
|
|
@@ -3012,7 +3596,7 @@ var DurableModule = class _DurableModule {
|
|
|
3012
3596
|
return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, options.tenantToken) : unavailableRunGateway();
|
|
3013
3597
|
}, "useFactory"),
|
|
3014
3598
|
inject: [
|
|
3015
|
-
|
|
3599
|
+
DURABLE_OPTIONS_CANONICAL8,
|
|
3016
3600
|
STATE_STORE_CANONICAL4,
|
|
3017
3601
|
WorkflowEngine6
|
|
3018
3602
|
]
|
|
@@ -3033,19 +3617,20 @@ var DurableModule = class _DurableModule {
|
|
|
3033
3617
|
STATE_STORE_CANONICAL4,
|
|
3034
3618
|
TRANSPORT,
|
|
3035
3619
|
TRANSPORT_CANONICAL3,
|
|
3036
|
-
|
|
3620
|
+
DURABLE_OPTIONS_CANONICAL8,
|
|
3037
3621
|
RunGateway2
|
|
3038
3622
|
]
|
|
3039
3623
|
};
|
|
3040
3624
|
}
|
|
3041
3625
|
};
|
|
3042
|
-
DurableModule =
|
|
3626
|
+
DurableModule = _ts_decorate13([
|
|
3043
3627
|
Module({})
|
|
3044
3628
|
], DurableModule);
|
|
3045
3629
|
|
|
3046
3630
|
// src/index.ts
|
|
3047
|
-
import { hmacTenantVerifier, prevCronFireMs, readSearchAttributes as readSearchAttributes2, RunGateway as RunGateway3, runSchedules as runSchedules2, scheduledRunId, scheduleRunIdAt, signTenantToken, WorkflowEngine as WorkflowEngine7 } from "@dudousxd/nestjs-durable-core";
|
|
3631
|
+
import { hmacTenantVerifier, LIFECYCLE_PENDING_TAG, lifecycleRunId, lifecycleSourceOf as lifecycleSourceOf2, prevCronFireMs, readSearchAttributes as readSearchAttributes2, RunGateway as RunGateway3, runCompletedEvent as runCompletedEvent2, runFailedEvent as runFailedEvent2, runSchedules as runSchedules2, scheduledRunId, scheduleRunIdAt, signTenantToken, triggeredRunsOf, WorkflowEngine as WorkflowEngine7 } from "@dudousxd/nestjs-durable-core";
|
|
3048
3632
|
export {
|
|
3633
|
+
BAD_RUN_REQUEST,
|
|
3049
3634
|
CONTEXT_ACCESSOR,
|
|
3050
3635
|
DEAD_LETTER_METADATA,
|
|
3051
3636
|
DURABLE_STEP_METADATA,
|
|
@@ -3064,12 +3649,16 @@ export {
|
|
|
3064
3649
|
IN_APP_WORKER_RUNNERS,
|
|
3065
3650
|
IN_APP_WORKER_RUNTIME,
|
|
3066
3651
|
InAppWorkerBootstrap,
|
|
3652
|
+
LIFECYCLE_PENDING_TAG,
|
|
3067
3653
|
ON_ERROR_METADATA,
|
|
3654
|
+
ON_EVENT_BATCH_METADATA,
|
|
3068
3655
|
ON_EVENT_METADATA,
|
|
3069
3656
|
On,
|
|
3070
3657
|
OnDurableEvent,
|
|
3071
3658
|
OnError,
|
|
3072
3659
|
OnEvent,
|
|
3660
|
+
OnWorkflowCompleted,
|
|
3661
|
+
OnWorkflowFailed,
|
|
3073
3662
|
ProxyRunGateway,
|
|
3074
3663
|
RUN_GATEWAY,
|
|
3075
3664
|
RUN_REDIS_WORKER,
|
|
@@ -3080,6 +3669,7 @@ export {
|
|
|
3080
3669
|
Step,
|
|
3081
3670
|
StepInterceptor,
|
|
3082
3671
|
StoreRunGateway,
|
|
3672
|
+
TENANT_REPUBLISH_MAX_LIMIT,
|
|
3083
3673
|
TenantEventRepublisher,
|
|
3084
3674
|
ThinStepRegistrar,
|
|
3085
3675
|
ThinWorkerBootstrap,
|
|
@@ -3091,6 +3681,7 @@ export {
|
|
|
3091
3681
|
WorkflowService,
|
|
3092
3682
|
attributesOf,
|
|
3093
3683
|
entityConfigFor,
|
|
3684
|
+
eventBatchOf,
|
|
3094
3685
|
getDurableStepMeta,
|
|
3095
3686
|
getEntityMeta,
|
|
3096
3687
|
getOnEvents,
|
|
@@ -3101,14 +3692,19 @@ export {
|
|
|
3101
3692
|
isDrivingOperator,
|
|
3102
3693
|
isOperatorRole,
|
|
3103
3694
|
isStepInterceptor,
|
|
3695
|
+
lifecycleRunId,
|
|
3696
|
+
lifecycleSourceOf2 as lifecycleSourceOf,
|
|
3104
3697
|
onErrorCodesOf,
|
|
3105
3698
|
prevCronFireMs,
|
|
3106
3699
|
readSearchAttributes2 as readSearchAttributes,
|
|
3700
|
+
runCompletedEvent2 as runCompletedEvent,
|
|
3701
|
+
runFailedEvent2 as runFailedEvent,
|
|
3107
3702
|
runSchedules2 as runSchedules,
|
|
3108
3703
|
scheduleRunIdAt,
|
|
3109
3704
|
scheduledRunId,
|
|
3110
3705
|
signTenantToken,
|
|
3111
3706
|
thinWorkerProviders,
|
|
3707
|
+
triggeredRunsOf,
|
|
3112
3708
|
unavailableRunGateway
|
|
3113
3709
|
};
|
|
3114
3710
|
//# sourceMappingURL=index.js.map
|