@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.cjs
CHANGED
|
@@ -29,8 +29,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
30
|
|
|
31
31
|
// src/index.ts
|
|
32
|
-
var
|
|
33
|
-
__export(
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
BAD_RUN_REQUEST: () => BAD_RUN_REQUEST,
|
|
34
35
|
CONTEXT_ACCESSOR: () => CONTEXT_ACCESSOR,
|
|
35
36
|
DEAD_LETTER_METADATA: () => DEAD_LETTER_METADATA,
|
|
36
37
|
DURABLE_STEP_METADATA: () => DURABLE_STEP_METADATA,
|
|
@@ -49,22 +50,27 @@ __export(index_exports, {
|
|
|
49
50
|
IN_APP_WORKER_RUNNERS: () => IN_APP_WORKER_RUNNERS,
|
|
50
51
|
IN_APP_WORKER_RUNTIME: () => IN_APP_WORKER_RUNTIME,
|
|
51
52
|
InAppWorkerBootstrap: () => InAppWorkerBootstrap,
|
|
53
|
+
LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core20.LIFECYCLE_PENDING_TAG,
|
|
52
54
|
ON_ERROR_METADATA: () => ON_ERROR_METADATA,
|
|
55
|
+
ON_EVENT_BATCH_METADATA: () => ON_EVENT_BATCH_METADATA,
|
|
53
56
|
ON_EVENT_METADATA: () => ON_EVENT_METADATA,
|
|
54
57
|
On: () => On,
|
|
55
58
|
OnDurableEvent: () => OnDurableEvent,
|
|
56
59
|
OnError: () => OnError,
|
|
57
60
|
OnEvent: () => OnEvent,
|
|
61
|
+
OnWorkflowCompleted: () => OnWorkflowCompleted,
|
|
62
|
+
OnWorkflowFailed: () => OnWorkflowFailed,
|
|
58
63
|
ProxyRunGateway: () => ProxyRunGateway,
|
|
59
64
|
RUN_GATEWAY: () => RUN_GATEWAY,
|
|
60
65
|
RUN_REDIS_WORKER: () => RUN_REDIS_WORKER,
|
|
61
|
-
RunGateway: () =>
|
|
66
|
+
RunGateway: () => import_nestjs_durable_core20.RunGateway,
|
|
62
67
|
RunGatewayError: () => RunGatewayError,
|
|
63
68
|
RunRequestResponder: () => RunRequestResponder,
|
|
64
69
|
STEP_INTERCEPTOR_METADATA: () => STEP_INTERCEPTOR_METADATA,
|
|
65
70
|
Step: () => Step,
|
|
66
71
|
StepInterceptor: () => StepInterceptor,
|
|
67
72
|
StoreRunGateway: () => StoreRunGateway,
|
|
73
|
+
TENANT_REPUBLISH_MAX_LIMIT: () => TENANT_REPUBLISH_MAX_LIMIT,
|
|
68
74
|
TenantEventRepublisher: () => TenantEventRepublisher,
|
|
69
75
|
ThinStepRegistrar: () => ThinStepRegistrar,
|
|
70
76
|
ThinWorkerBootstrap: () => ThinWorkerBootstrap,
|
|
@@ -72,31 +78,37 @@ __export(index_exports, {
|
|
|
72
78
|
UNSUPPORTED_RUN_REQUEST: () => UNSUPPORTED_RUN_REQUEST,
|
|
73
79
|
WORKFLOW_METADATA: () => WORKFLOW_METADATA,
|
|
74
80
|
Workflow: () => Workflow,
|
|
75
|
-
WorkflowEngine: () =>
|
|
81
|
+
WorkflowEngine: () => import_nestjs_durable_core20.WorkflowEngine,
|
|
76
82
|
WorkflowService: () => WorkflowService,
|
|
77
83
|
attributesOf: () => attributesOf,
|
|
78
84
|
entityConfigFor: () => entityConfigFor,
|
|
85
|
+
eventBatchOf: () => eventBatchOf,
|
|
79
86
|
getDurableStepMeta: () => getDurableStepMeta,
|
|
80
87
|
getEntityMeta: () => getEntityMeta,
|
|
81
88
|
getOnEvents: () => getOnEvents,
|
|
82
89
|
getWorkflowMeta: () => getWorkflowMeta,
|
|
83
|
-
hmacTenantVerifier: () =>
|
|
90
|
+
hmacTenantVerifier: () => import_nestjs_durable_core20.hmacTenantVerifier,
|
|
84
91
|
inAppWorkerProviders: () => inAppWorkerProviders,
|
|
85
92
|
isDeadLetterHandler: () => isDeadLetterHandler,
|
|
86
93
|
isDrivingOperator: () => isDrivingOperator,
|
|
87
94
|
isOperatorRole: () => isOperatorRole,
|
|
88
95
|
isStepInterceptor: () => isStepInterceptor,
|
|
96
|
+
lifecycleRunId: () => import_nestjs_durable_core20.lifecycleRunId,
|
|
97
|
+
lifecycleSourceOf: () => import_nestjs_durable_core20.lifecycleSourceOf,
|
|
89
98
|
onErrorCodesOf: () => onErrorCodesOf,
|
|
90
|
-
prevCronFireMs: () =>
|
|
91
|
-
readSearchAttributes: () =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
prevCronFireMs: () => import_nestjs_durable_core20.prevCronFireMs,
|
|
100
|
+
readSearchAttributes: () => import_nestjs_durable_core20.readSearchAttributes,
|
|
101
|
+
runCompletedEvent: () => import_nestjs_durable_core20.runCompletedEvent,
|
|
102
|
+
runFailedEvent: () => import_nestjs_durable_core20.runFailedEvent,
|
|
103
|
+
runSchedules: () => import_nestjs_durable_core20.runSchedules,
|
|
104
|
+
scheduleRunIdAt: () => import_nestjs_durable_core20.scheduleRunIdAt,
|
|
105
|
+
scheduledRunId: () => import_nestjs_durable_core20.scheduledRunId,
|
|
106
|
+
signTenantToken: () => import_nestjs_durable_core20.signTenantToken,
|
|
96
107
|
thinWorkerProviders: () => thinWorkerProviders,
|
|
108
|
+
triggeredRunsOf: () => import_nestjs_durable_core20.triggeredRunsOf,
|
|
97
109
|
unavailableRunGateway: () => unavailableRunGateway
|
|
98
110
|
});
|
|
99
|
-
module.exports = __toCommonJS(
|
|
111
|
+
module.exports = __toCommonJS(src_exports);
|
|
100
112
|
|
|
101
113
|
// src/attributes-of.ts
|
|
102
114
|
var import_nestjs_durable_core2 = require("@dudousxd/nestjs-durable-core");
|
|
@@ -326,24 +338,108 @@ function onErrorCodesOf(method) {
|
|
|
326
338
|
__name(onErrorCodesOf, "onErrorCodesOf");
|
|
327
339
|
var ON_EVENT_METADATA = Symbol("nestjs-durable:on-event");
|
|
328
340
|
function OnDurableEvent(...events) {
|
|
341
|
+
return (target) => addEventSubscriptions(target, events);
|
|
342
|
+
}
|
|
343
|
+
__name(OnDurableEvent, "OnDurableEvent");
|
|
344
|
+
function OnWorkflowCompleted(workflow, options) {
|
|
345
|
+
return onWorkflowSettled((0, import_nestjs_durable_core.runCompletedEvent)(workflow), options?.where, options);
|
|
346
|
+
}
|
|
347
|
+
__name(OnWorkflowCompleted, "OnWorkflowCompleted");
|
|
348
|
+
function OnWorkflowFailed(workflow, options) {
|
|
349
|
+
const statuses = options?.statuses;
|
|
350
|
+
const where = options?.where;
|
|
351
|
+
const accepts = statuses || where ? (event) => (!statuses || statuses.includes(event.status)) && (!where || where(event)) : void 0;
|
|
352
|
+
return onWorkflowSettled((0, import_nestjs_durable_core.runFailedEvent)(workflow), accepts, options);
|
|
353
|
+
}
|
|
354
|
+
__name(OnWorkflowFailed, "OnWorkflowFailed");
|
|
355
|
+
var ON_EVENT_BATCH_METADATA = Symbol("nestjs-durable:on-event-batch");
|
|
356
|
+
function onWorkflowSettled(event, where, options) {
|
|
357
|
+
const subscription = {
|
|
358
|
+
event,
|
|
359
|
+
where,
|
|
360
|
+
input: options?.input
|
|
361
|
+
};
|
|
362
|
+
const batch = subscriberEventBatch(event, options);
|
|
329
363
|
return (target) => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
364
|
+
addEventSubscriptions(target, [
|
|
365
|
+
subscription
|
|
366
|
+
]);
|
|
367
|
+
if (!batch) return;
|
|
368
|
+
const existing = Reflect.getMetadata(ON_EVENT_BATCH_METADATA, target);
|
|
369
|
+
if (existing && !sameEventBatch(existing, batch)) {
|
|
370
|
+
throw new Error(`${target.name ?? "workflow"}: two lifecycle subscriptions declare different debounce/batch settings; a workflow coalesces all its triggers one way`);
|
|
371
|
+
}
|
|
372
|
+
Reflect.defineMetadata(ON_EVENT_BATCH_METADATA, batch, target);
|
|
335
373
|
};
|
|
336
374
|
}
|
|
337
|
-
__name(
|
|
375
|
+
__name(onWorkflowSettled, "onWorkflowSettled");
|
|
376
|
+
function subscriberEventBatch(event, options) {
|
|
377
|
+
if (options?.debounce && options.batch) {
|
|
378
|
+
throw new Error(`${event}: a subscription takes debounce or batch, not both`);
|
|
379
|
+
}
|
|
380
|
+
if (options?.debounce) {
|
|
381
|
+
return {
|
|
382
|
+
mode: "debounce",
|
|
383
|
+
windowMs: (0, import_nestjs_durable_core.parseDuration)(options.debounce.windowMs),
|
|
384
|
+
...options.debounce.key ? {
|
|
385
|
+
key: options.debounce.key
|
|
386
|
+
} : {}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (options?.batch) {
|
|
390
|
+
return {
|
|
391
|
+
mode: "batch",
|
|
392
|
+
maxSize: options.batch.maxSize,
|
|
393
|
+
windowMs: (0, import_nestjs_durable_core.parseDuration)(options.batch.windowMs),
|
|
394
|
+
...options.batch.key ? {
|
|
395
|
+
key: options.batch.key
|
|
396
|
+
} : {}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
}
|
|
401
|
+
__name(subscriberEventBatch, "subscriberEventBatch");
|
|
402
|
+
function sameEventBatch(a, b) {
|
|
403
|
+
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);
|
|
404
|
+
}
|
|
405
|
+
__name(sameEventBatch, "sameEventBatch");
|
|
406
|
+
function eventBatchOf(meta, target) {
|
|
407
|
+
const declared = meta.debounce ? {
|
|
408
|
+
mode: "debounce",
|
|
409
|
+
windowMs: (0, import_nestjs_durable_core.parseDuration)(meta.debounce)
|
|
410
|
+
} : meta.batch ? {
|
|
411
|
+
mode: "batch",
|
|
412
|
+
maxSize: meta.batch.maxSize,
|
|
413
|
+
windowMs: (0, import_nestjs_durable_core.parseDuration)(meta.batch.within)
|
|
414
|
+
} : void 0;
|
|
415
|
+
const fromSubscription = Reflect.getMetadata(ON_EVENT_BATCH_METADATA, target);
|
|
416
|
+
if (declared && fromSubscription && !sameEventBatch(declared, fromSubscription)) {
|
|
417
|
+
throw new Error(`workflow ${meta.name}: @Workflow declares ${declared.mode} but a lifecycle subscription declares a different ${fromSubscription.mode}; declare it in one place`);
|
|
418
|
+
}
|
|
419
|
+
return fromSubscription ?? declared;
|
|
420
|
+
}
|
|
421
|
+
__name(eventBatchOf, "eventBatchOf");
|
|
422
|
+
function addEventSubscriptions(target, entries) {
|
|
423
|
+
const existing = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
424
|
+
Reflect.defineMetadata(ON_EVENT_METADATA, [
|
|
425
|
+
...existing,
|
|
426
|
+
...entries
|
|
427
|
+
], target);
|
|
428
|
+
}
|
|
429
|
+
__name(addEventSubscriptions, "addEventSubscriptions");
|
|
338
430
|
var OnEvent = OnDurableEvent;
|
|
339
431
|
function getOnEvents(meta, target) {
|
|
340
432
|
const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
433
|
+
const names = /* @__PURE__ */ new Set();
|
|
341
434
|
return [
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
435
|
+
...meta.onEvent ?? [],
|
|
436
|
+
...fromDecorator
|
|
437
|
+
].filter((entry) => {
|
|
438
|
+
if (typeof entry !== "string") return true;
|
|
439
|
+
if (names.has(entry)) return false;
|
|
440
|
+
names.add(entry);
|
|
441
|
+
return true;
|
|
442
|
+
});
|
|
347
443
|
}
|
|
348
444
|
__name(getOnEvents, "getOnEvents");
|
|
349
445
|
|
|
@@ -659,6 +755,9 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
659
755
|
} : {}
|
|
660
756
|
};
|
|
661
757
|
const body = workflowIo(meta).wrap((ctx, input) => instance.run(ctx, input));
|
|
758
|
+
const subscribes = [
|
|
759
|
+
...new Set(getOnEvents(meta, instance.constructor).map((entry) => typeof entry === "string" ? entry : entry.event))
|
|
760
|
+
];
|
|
662
761
|
runtime.registerWorkflow(meta.name, body, {
|
|
663
762
|
...announced,
|
|
664
763
|
...meta.requires !== void 0 ? {
|
|
@@ -672,6 +771,9 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
672
771
|
code,
|
|
673
772
|
workflow
|
|
674
773
|
})
|
|
774
|
+
} : {},
|
|
775
|
+
...subscribes.length > 0 ? {
|
|
776
|
+
subscribes
|
|
675
777
|
} : {}
|
|
676
778
|
});
|
|
677
779
|
for (const [name, fn] of handlers) runtime.registerWorkflow(name, fn, announced);
|
|
@@ -922,9 +1024,9 @@ function unavailableRunGateway() {
|
|
|
922
1024
|
__name(unavailableRunGateway, "unavailableRunGateway");
|
|
923
1025
|
|
|
924
1026
|
// src/durable.module.ts
|
|
925
|
-
var
|
|
926
|
-
var
|
|
927
|
-
var
|
|
1027
|
+
var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
1028
|
+
var import_common13 = require("@nestjs/common");
|
|
1029
|
+
var import_core6 = require("@nestjs/core");
|
|
928
1030
|
|
|
929
1031
|
// src/durable-step.registrar.ts
|
|
930
1032
|
var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
|
|
@@ -1264,6 +1366,8 @@ var import_common6 = require("@nestjs/common");
|
|
|
1264
1366
|
// src/run-request-responder.ts
|
|
1265
1367
|
var import_nestjs_durable_core10 = require("@dudousxd/nestjs-durable-core");
|
|
1266
1368
|
var UNSUPPORTED_RUN_REQUEST = "unsupported-request";
|
|
1369
|
+
var BAD_RUN_REQUEST = "bad-request";
|
|
1370
|
+
var TENANT_REPUBLISH_MAX_LIMIT = 1e3;
|
|
1267
1371
|
var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
1268
1372
|
"getRunDetail",
|
|
1269
1373
|
"getFanMembers",
|
|
@@ -1277,8 +1381,47 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
|
1277
1381
|
"continue",
|
|
1278
1382
|
"retryWithInput",
|
|
1279
1383
|
"redispatch",
|
|
1280
|
-
"waitingFor"
|
|
1384
|
+
"waitingFor",
|
|
1385
|
+
"republishLifecycle",
|
|
1386
|
+
"workflowLifecycle"
|
|
1281
1387
|
]);
|
|
1388
|
+
function wireDate(value) {
|
|
1389
|
+
if (value === void 0 || value === null) return void 0;
|
|
1390
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
1391
|
+
if (Number.isNaN(date.getTime())) throw new Error(`invalid date ${String(value)}`);
|
|
1392
|
+
return date;
|
|
1393
|
+
}
|
|
1394
|
+
__name(wireDate, "wireDate");
|
|
1395
|
+
function scopeRunLinks(detail, tenant) {
|
|
1396
|
+
const own = /* @__PURE__ */ __name((link) => link.namespace === tenant, "own");
|
|
1397
|
+
const bare = /* @__PURE__ */ __name((link) => {
|
|
1398
|
+
if (own(link)) return link;
|
|
1399
|
+
const { status: _status, namespace: _namespace, ...rest2 } = link;
|
|
1400
|
+
return rest2;
|
|
1401
|
+
}, "bare");
|
|
1402
|
+
const awaitedBy = detail.awaitedBy?.filter(own);
|
|
1403
|
+
const { awaitedBy: _awaitedBy, ...rest } = detail;
|
|
1404
|
+
const source = detail.triggeredBy;
|
|
1405
|
+
return {
|
|
1406
|
+
...rest,
|
|
1407
|
+
...source ? {
|
|
1408
|
+
triggeredBy: own(source) ? source : {
|
|
1409
|
+
runId: source.runId,
|
|
1410
|
+
kind: source.kind
|
|
1411
|
+
}
|
|
1412
|
+
} : {},
|
|
1413
|
+
...awaitedBy && awaitedBy.length > 0 ? {
|
|
1414
|
+
awaitedBy
|
|
1415
|
+
} : {},
|
|
1416
|
+
...detail.waitsFor ? {
|
|
1417
|
+
waitsFor: detail.waitsFor.map(bare)
|
|
1418
|
+
} : {},
|
|
1419
|
+
...detail.lifecycleDeliveries ? {
|
|
1420
|
+
lifecycleDeliveries: detail.lifecycleDeliveries.map(bare)
|
|
1421
|
+
} : {}
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
__name(scopeRunLinks, "scopeRunLinks");
|
|
1282
1425
|
var RunRequestResponder = class {
|
|
1283
1426
|
static {
|
|
1284
1427
|
__name(this, "RunRequestResponder");
|
|
@@ -1334,18 +1477,7 @@ var RunRequestResponder = class {
|
|
|
1334
1477
|
tenant
|
|
1335
1478
|
};
|
|
1336
1479
|
const { body } = msg;
|
|
1337
|
-
if (!KNOWN_KINDS.has(body.kind))
|
|
1338
|
-
return {
|
|
1339
|
-
requestId: msg.requestId,
|
|
1340
|
-
result: {
|
|
1341
|
-
ok: false,
|
|
1342
|
-
error: {
|
|
1343
|
-
message: `the control plane does not support the ${String(body.kind)} run request`,
|
|
1344
|
-
code: UNSUPPORTED_RUN_REQUEST
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
};
|
|
1348
|
-
}
|
|
1480
|
+
if (!KNOWN_KINDS.has(body.kind)) return unsupported(msg.requestId, String(body.kind));
|
|
1349
1481
|
if (body.kind === "listRuns") {
|
|
1350
1482
|
const data = await this.gateway.listRuns({
|
|
1351
1483
|
...body.query,
|
|
@@ -1396,12 +1528,65 @@ var RunRequestResponder = class {
|
|
|
1396
1528
|
}
|
|
1397
1529
|
};
|
|
1398
1530
|
}
|
|
1531
|
+
if (body.kind === "workflowLifecycle") {
|
|
1532
|
+
if (!this.gateway.workflowLifecycle) return unsupported(msg.requestId, body.kind);
|
|
1533
|
+
const data = await this.gateway.workflowLifecycle(body.workflow, {
|
|
1534
|
+
namespace: msg.tenant
|
|
1535
|
+
});
|
|
1536
|
+
return {
|
|
1537
|
+
requestId: msg.requestId,
|
|
1538
|
+
result: {
|
|
1539
|
+
ok: true,
|
|
1540
|
+
data
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
if (body.kind === "republishLifecycle" && !("runId" in body.target)) {
|
|
1545
|
+
if (!this.gateway.republishLifecycle) return unsupported(msg.requestId, body.kind);
|
|
1546
|
+
const { since, until, limit, ...rest } = body.target;
|
|
1547
|
+
if (limit !== void 0 && (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 1)) {
|
|
1548
|
+
return badRequest(msg.requestId, `limit must be a positive integer, got ${JSON.stringify(limit)}`);
|
|
1549
|
+
}
|
|
1550
|
+
const refused = await this.refuseSubscriber(rest.workflow, rest.kind, rest.subscriber, msg.tenant);
|
|
1551
|
+
if (refused) return badRequest(msg.requestId, refused);
|
|
1552
|
+
const target = {
|
|
1553
|
+
...rest,
|
|
1554
|
+
namespace: msg.tenant,
|
|
1555
|
+
limit: Math.min(limit ?? TENANT_REPUBLISH_MAX_LIMIT, TENANT_REPUBLISH_MAX_LIMIT),
|
|
1556
|
+
...since !== void 0 ? {
|
|
1557
|
+
since: wireDate(since)
|
|
1558
|
+
} : {},
|
|
1559
|
+
...until !== void 0 ? {
|
|
1560
|
+
until: wireDate(until)
|
|
1561
|
+
} : {}
|
|
1562
|
+
};
|
|
1563
|
+
try {
|
|
1564
|
+
const data = await this.gateway.republishLifecycle(target);
|
|
1565
|
+
return {
|
|
1566
|
+
requestId: msg.requestId,
|
|
1567
|
+
result: {
|
|
1568
|
+
ok: true,
|
|
1569
|
+
data
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
} catch (err) {
|
|
1573
|
+
return {
|
|
1574
|
+
requestId: msg.requestId,
|
|
1575
|
+
result: {
|
|
1576
|
+
ok: false,
|
|
1577
|
+
error: {
|
|
1578
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1399
1584
|
if (body.kind === "waitingFor") {
|
|
1400
1585
|
const all = await this.gateway.waitingFor(body.runIds);
|
|
1401
|
-
const owned = await Promise.all(Object.entries(all).map(async ([
|
|
1402
|
-
const owner = this.gateway.getRun ? await this.gateway.getRun(
|
|
1586
|
+
const owned = await Promise.all(Object.entries(all).map(async ([runId2, waiting]) => {
|
|
1587
|
+
const owner = this.gateway.getRun ? await this.gateway.getRun(runId2) : (await this.gateway.getRunDetail(runId2))?.run;
|
|
1403
1588
|
return owner && owner.namespace === msg.tenant ? [
|
|
1404
|
-
|
|
1589
|
+
runId2,
|
|
1405
1590
|
waiting
|
|
1406
1591
|
] : void 0;
|
|
1407
1592
|
}));
|
|
@@ -1417,8 +1602,12 @@ var RunRequestResponder = class {
|
|
|
1417
1602
|
}
|
|
1418
1603
|
};
|
|
1419
1604
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1605
|
+
if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
|
|
1606
|
+
return unsupported(msg.requestId, body.kind);
|
|
1607
|
+
}
|
|
1608
|
+
const runId = runIdOf(body);
|
|
1609
|
+
const detail = body.kind === "getRunDetail" || !this.gateway.getRun ? await this.gateway.getRunDetail(runId, body.kind === "getRunDetail" ? body.options : void 0) : void 0;
|
|
1610
|
+
const run = detail !== void 0 ? detail?.run ?? null : await this.gateway.getRun?.(runId);
|
|
1422
1611
|
if (run && run.namespace !== msg.tenant) {
|
|
1423
1612
|
return {
|
|
1424
1613
|
requestId: msg.requestId,
|
|
@@ -1432,11 +1621,12 @@ var RunRequestResponder = class {
|
|
|
1432
1621
|
};
|
|
1433
1622
|
}
|
|
1434
1623
|
if (body.kind === "getRunDetail") {
|
|
1624
|
+
const data = detail ? await this.scopeLifecycle(detail, msg.tenant) : detail;
|
|
1435
1625
|
return {
|
|
1436
1626
|
requestId: msg.requestId,
|
|
1437
1627
|
result: {
|
|
1438
1628
|
ok: true,
|
|
1439
|
-
data
|
|
1629
|
+
data
|
|
1440
1630
|
}
|
|
1441
1631
|
};
|
|
1442
1632
|
}
|
|
@@ -1459,6 +1649,11 @@ var RunRequestResponder = class {
|
|
|
1459
1649
|
}
|
|
1460
1650
|
};
|
|
1461
1651
|
}
|
|
1652
|
+
if (body.kind === "republishLifecycle" && "runId" in body.target && run) {
|
|
1653
|
+
const kind = (0, import_nestjs_durable_core10.lifecycleKindOf)(run.status);
|
|
1654
|
+
const refused = kind ? await this.refuseSubscriber(run.workflow, kind, body.target.subscriber, msg.tenant) : void 0;
|
|
1655
|
+
if (refused) return badRequest(msg.requestId, refused);
|
|
1656
|
+
}
|
|
1462
1657
|
try {
|
|
1463
1658
|
const data = await this.callVerb(body);
|
|
1464
1659
|
return {
|
|
@@ -1480,8 +1675,71 @@ var RunRequestResponder = class {
|
|
|
1480
1675
|
};
|
|
1481
1676
|
}
|
|
1482
1677
|
}
|
|
1678
|
+
/**
|
|
1679
|
+
* `detail` scoped to `tenant` (see {@link scopeRunLinks}), with its lifecycle links
|
|
1680
|
+
* (`workflowLifecycle`, `lifecycleSubscribers`) narrowed to the subscriptions of `tenant`'s
|
|
1681
|
+
* namespace, as the `workflowLifecycle` verb answers them.
|
|
1682
|
+
*/
|
|
1683
|
+
async scopeLifecycle(input, tenant) {
|
|
1684
|
+
const detail = scopeRunLinks(input, tenant);
|
|
1685
|
+
if (detail.workflowLifecycle === void 0 && detail.lifecycleSubscribers === void 0) {
|
|
1686
|
+
return detail;
|
|
1687
|
+
}
|
|
1688
|
+
const { workflowLifecycle: _links, lifecycleSubscribers: _subscribers, ...rest } = detail;
|
|
1689
|
+
const links = await this.gateway.workflowLifecycle?.(detail.run.workflow, {
|
|
1690
|
+
namespace: tenant
|
|
1691
|
+
});
|
|
1692
|
+
if (!links) return rest;
|
|
1693
|
+
const kind = (0, import_nestjs_durable_core10.lifecycleKindOf)(detail.run.status);
|
|
1694
|
+
const subscribers = kind ? [
|
|
1695
|
+
...new Set(links.startsOnSettle.filter((l) => l.kind === kind).map((l) => l.workflow))
|
|
1696
|
+
] : [];
|
|
1697
|
+
const linked = links.startsOnSettle.length > 0 || links.startedBy.length > 0;
|
|
1698
|
+
return {
|
|
1699
|
+
...rest,
|
|
1700
|
+
...subscribers.length > 0 ? {
|
|
1701
|
+
lifecycleSubscribers: subscribers
|
|
1702
|
+
} : {},
|
|
1703
|
+
...linked ? {
|
|
1704
|
+
workflowLifecycle: links
|
|
1705
|
+
} : {}
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Why a tenant republish naming `subscriber` is refused, or undefined when it may go ahead: the
|
|
1710
|
+
* subscriber must be owed the event of `workflow` settling (as `kind`, when given) by a run of
|
|
1711
|
+
* the tenant's namespace (the gateway's `lifecycleSubscribers`, else the tenant's
|
|
1712
|
+
* `workflowLifecycle` links), so a tenant cannot have the event owed to an arbitrary name. Without
|
|
1713
|
+
* `subscriber` there is nothing to check.
|
|
1714
|
+
*/
|
|
1715
|
+
async refuseSubscriber(workflow, kind, subscriber, tenant) {
|
|
1716
|
+
if (subscriber === void 0) return void 0;
|
|
1717
|
+
const kinds = kind ? [
|
|
1718
|
+
kind
|
|
1719
|
+
] : [
|
|
1720
|
+
"completed",
|
|
1721
|
+
"failed"
|
|
1722
|
+
];
|
|
1723
|
+
let subscribes = false;
|
|
1724
|
+
if (this.gateway.lifecycleSubscribers) {
|
|
1725
|
+
for (const k of kinds) {
|
|
1726
|
+
const subscribers = await this.gateway.lifecycleSubscribers(workflow, k, tenant);
|
|
1727
|
+
subscribes ||= subscribers.includes(subscriber);
|
|
1728
|
+
}
|
|
1729
|
+
} else {
|
|
1730
|
+
const links = await this.gateway.workflowLifecycle?.(workflow, {
|
|
1731
|
+
namespace: tenant
|
|
1732
|
+
});
|
|
1733
|
+
subscribes = links?.startsOnSettle.some((link) => link.workflow === subscriber && kinds.includes(link.kind)) ?? false;
|
|
1734
|
+
}
|
|
1735
|
+
if (subscribes) return void 0;
|
|
1736
|
+
const events = kind ? `run.${kind}:${workflow}` : `run.completed:${workflow} or run.failed:${workflow}`;
|
|
1737
|
+
return `subscriber ${subscriber} does not subscribe to ${events} in namespace ${tenant}`;
|
|
1738
|
+
}
|
|
1483
1739
|
callVerb(body) {
|
|
1484
1740
|
switch (body.kind) {
|
|
1741
|
+
case "republishLifecycle":
|
|
1742
|
+
return this.gateway.republishLifecycle?.(body.target) ?? Promise.reject(new Error("republishLifecycle is not supported"));
|
|
1485
1743
|
case "cancel":
|
|
1486
1744
|
return this.gateway.cancel(body.runId, body.opts);
|
|
1487
1745
|
case "retry":
|
|
@@ -1495,6 +1753,37 @@ var RunRequestResponder = class {
|
|
|
1495
1753
|
}
|
|
1496
1754
|
}
|
|
1497
1755
|
};
|
|
1756
|
+
function runIdOf(body) {
|
|
1757
|
+
if (body.kind !== "republishLifecycle") return body.runId;
|
|
1758
|
+
return "runId" in body.target ? body.target.runId : "";
|
|
1759
|
+
}
|
|
1760
|
+
__name(runIdOf, "runIdOf");
|
|
1761
|
+
function badRequest(requestId, message) {
|
|
1762
|
+
return {
|
|
1763
|
+
requestId,
|
|
1764
|
+
result: {
|
|
1765
|
+
ok: false,
|
|
1766
|
+
error: {
|
|
1767
|
+
message,
|
|
1768
|
+
code: BAD_RUN_REQUEST
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
__name(badRequest, "badRequest");
|
|
1774
|
+
function unsupported(requestId, kind) {
|
|
1775
|
+
return {
|
|
1776
|
+
requestId,
|
|
1777
|
+
result: {
|
|
1778
|
+
ok: false,
|
|
1779
|
+
error: {
|
|
1780
|
+
message: `the control plane does not support the ${kind} run request`,
|
|
1781
|
+
code: UNSUPPORTED_RUN_REQUEST
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
__name(unsupported, "unsupported");
|
|
1498
1787
|
|
|
1499
1788
|
// src/proxy-run-gateway.ts
|
|
1500
1789
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
@@ -1760,6 +2049,42 @@ var ProxyRunGateway = class {
|
|
|
1760
2049
|
runId
|
|
1761
2050
|
});
|
|
1762
2051
|
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Republished on the control plane: a one-run target is checked against this tenant like
|
|
2054
|
+
* `retry`, a by-workflow one is read over this tenant's namespace only. A control plane too old to
|
|
2055
|
+
* know the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error rather than a timeout.
|
|
2056
|
+
*/
|
|
2057
|
+
republishLifecycle(target) {
|
|
2058
|
+
return this.requestNewVerb({
|
|
2059
|
+
kind: "republishLifecycle",
|
|
2060
|
+
target
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
/** Answered by the control plane's engine; same version-skew error as {@link republishLifecycle}. */
|
|
2064
|
+
workflowLifecycle(workflow) {
|
|
2065
|
+
return this.requestNewVerb({
|
|
2066
|
+
kind: "workflowLifecycle",
|
|
2067
|
+
workflow
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* A verb with no fallback on an older control plane: its unsupported-request error, or the empty
|
|
2072
|
+
* `ok: true` reply the oldest responders send for an unknown verb, becomes a
|
|
2073
|
+
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
2074
|
+
*/
|
|
2075
|
+
async requestNewVerb(body) {
|
|
2076
|
+
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");
|
|
2077
|
+
if (this.knownUnsupported(body.kind)) throw notSupported();
|
|
2078
|
+
let data;
|
|
2079
|
+
try {
|
|
2080
|
+
data = await this.request(body);
|
|
2081
|
+
} catch (err) {
|
|
2082
|
+
if (!isUnsupported(err)) throw err;
|
|
2083
|
+
}
|
|
2084
|
+
if (data !== void 0 && data !== null) return data;
|
|
2085
|
+
this.unsupportedUntil.set(body.kind, Date.now() + this.capabilityTtlMs);
|
|
2086
|
+
throw notSupported();
|
|
2087
|
+
}
|
|
1763
2088
|
subscribe(runId, onEvent) {
|
|
1764
2089
|
const unsubscribe = this.transport.onTenantEvent?.(this.tenant, (evt) => {
|
|
1765
2090
|
if (evt.event.runId === runId) onEvent(evt.event);
|
|
@@ -1781,8 +2106,8 @@ ProxyRunGateway = _ts_decorate6([
|
|
|
1781
2106
|
], ProxyRunGateway);
|
|
1782
2107
|
|
|
1783
2108
|
// src/retention-poller.ts
|
|
1784
|
-
var
|
|
1785
|
-
var
|
|
2109
|
+
var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
|
|
2110
|
+
var import_common8 = require("@nestjs/common");
|
|
1786
2111
|
|
|
1787
2112
|
// src/settle-within.ts
|
|
1788
2113
|
async function settleWithin(p, timeoutMs) {
|
|
@@ -1807,7 +2132,10 @@ async function settleWithin(p, timeoutMs) {
|
|
|
1807
2132
|
}
|
|
1808
2133
|
__name(settleWithin, "settleWithin");
|
|
1809
2134
|
|
|
1810
|
-
// src/
|
|
2135
|
+
// src/sweep-leases.ts
|
|
2136
|
+
var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
|
|
2137
|
+
var import_common7 = require("@nestjs/common");
|
|
2138
|
+
var import_core4 = require("@nestjs/core");
|
|
1811
2139
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
1812
2140
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1813
2141
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -1834,6 +2162,110 @@ function _ts_param4(paramIndex, decorator) {
|
|
|
1834
2162
|
};
|
|
1835
2163
|
}
|
|
1836
2164
|
__name(_ts_param4, "_ts_param");
|
|
2165
|
+
var SweepLeases = class {
|
|
2166
|
+
static {
|
|
2167
|
+
__name(this, "SweepLeases");
|
|
2168
|
+
}
|
|
2169
|
+
moduleRef;
|
|
2170
|
+
options;
|
|
2171
|
+
logger = new import_common7.Logger("nestjs-durable");
|
|
2172
|
+
/** Set by {@link onModuleInit} (before any poller's bootstrap). `null`: no `@nestjs/locks`. */
|
|
2173
|
+
locks = null;
|
|
2174
|
+
leases = /* @__PURE__ */ new Map();
|
|
2175
|
+
constructor(moduleRef, options) {
|
|
2176
|
+
this.moduleRef = moduleRef;
|
|
2177
|
+
this.options = options;
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Run `fn` if this pod holds (or now takes) the lease of `sweep`; otherwise skip it and resolve
|
|
2181
|
+
* `undefined`. Without `@nestjs/locks` it always runs `fn`.
|
|
2182
|
+
*/
|
|
2183
|
+
async run(sweep, fn) {
|
|
2184
|
+
const locks = this.locks;
|
|
2185
|
+
if (!locks) return fn();
|
|
2186
|
+
if (!await this.holds(locks, sweep)) return void 0;
|
|
2187
|
+
return fn();
|
|
2188
|
+
}
|
|
2189
|
+
async holds(locks, sweep) {
|
|
2190
|
+
if (this.leases.get(sweep)?.held) return true;
|
|
2191
|
+
this.leases.delete(sweep);
|
|
2192
|
+
let lock;
|
|
2193
|
+
try {
|
|
2194
|
+
lock = await locks.acquire(this.key(sweep));
|
|
2195
|
+
} catch (error) {
|
|
2196
|
+
this.logger.warn(`could not take the ${sweep} sweep lease; skipping this tick: ${String(error)}`);
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
if (!lock) return false;
|
|
2200
|
+
this.leases.set(sweep, lock);
|
|
2201
|
+
return true;
|
|
2202
|
+
}
|
|
2203
|
+
key(sweep) {
|
|
2204
|
+
const ns = this.options?.namespace;
|
|
2205
|
+
return ns ? `durable:${sweep}:${ns}` : `durable:${sweep}`;
|
|
2206
|
+
}
|
|
2207
|
+
/** Detects `Locks` once, and logs which mode is active. Nest awaits it before any bootstrap hook. */
|
|
2208
|
+
async onModuleInit() {
|
|
2209
|
+
this.locks = await this.detect();
|
|
2210
|
+
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)");
|
|
2211
|
+
}
|
|
2212
|
+
async detect() {
|
|
2213
|
+
let locks = null;
|
|
2214
|
+
if (this.moduleRef) {
|
|
2215
|
+
try {
|
|
2216
|
+
const specifier = "@nestjs/locks";
|
|
2217
|
+
const mod = await import(specifier);
|
|
2218
|
+
if (mod.Locks) {
|
|
2219
|
+
locks = this.moduleRef.get(mod.Locks, {
|
|
2220
|
+
strict: false
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
} catch {
|
|
2224
|
+
locks = null;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return locks;
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
SweepLeases = _ts_decorate7([
|
|
2231
|
+
(0, import_common7.Injectable)(),
|
|
2232
|
+
_ts_param4(0, (0, import_common7.Optional)()),
|
|
2233
|
+
_ts_param4(1, (0, import_common7.Optional)()),
|
|
2234
|
+
_ts_param4(1, (0, import_common7.Inject)(import_nestjs_durable_core12.DURABLE_OPTIONS_CANONICAL)),
|
|
2235
|
+
_ts_metadata7("design:type", Function),
|
|
2236
|
+
_ts_metadata7("design:paramtypes", [
|
|
2237
|
+
typeof import_core4.ModuleRef === "undefined" ? Object : import_core4.ModuleRef,
|
|
2238
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2239
|
+
])
|
|
2240
|
+
], SweepLeases);
|
|
2241
|
+
|
|
2242
|
+
// src/retention-poller.ts
|
|
2243
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
2244
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2245
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2246
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2247
|
+
} else {
|
|
2248
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
2249
|
+
if (d = decorators[i]) {
|
|
2250
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2255
|
+
}
|
|
2256
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
2257
|
+
function _ts_metadata8(metadataKey, metadataValue) {
|
|
2258
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2259
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2263
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2264
|
+
return function(target, key) {
|
|
2265
|
+
decorator(target, key, paramIndex);
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
__name(_ts_param5, "_ts_param");
|
|
1837
2269
|
var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
|
|
1838
2270
|
var DEFAULT_BATCH_SIZE = 1e3;
|
|
1839
2271
|
var MAX_BATCHES_PER_POLICY = 100;
|
|
@@ -1847,10 +2279,10 @@ function validateRetention(retention) {
|
|
|
1847
2279
|
if (policy.maxAge == null && policy.maxCount == null) {
|
|
1848
2280
|
throw new Error("durable retention: each policy must set maxAge and/or maxCount");
|
|
1849
2281
|
}
|
|
1850
|
-
if (policy.maxAge != null) (0,
|
|
2282
|
+
if (policy.maxAge != null) (0, import_nestjs_durable_core13.parseDuration)(policy.maxAge);
|
|
1851
2283
|
for (const status of policy.statuses) {
|
|
1852
|
-
if (!
|
|
1853
|
-
throw new Error(`durable retention: status "${status}" is not terminal; only ${
|
|
2284
|
+
if (!import_nestjs_durable_core13.TERMINAL_RUN_STATUSES.includes(status)) {
|
|
2285
|
+
throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core13.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
1854
2286
|
}
|
|
1855
2287
|
const key = `${scopeKey}|${status}`;
|
|
1856
2288
|
if (seen.has(key)) {
|
|
@@ -1876,14 +2308,16 @@ var RetentionPoller = class {
|
|
|
1876
2308
|
}
|
|
1877
2309
|
store;
|
|
1878
2310
|
options;
|
|
2311
|
+
leases;
|
|
1879
2312
|
timer;
|
|
1880
2313
|
sweeping = false;
|
|
1881
2314
|
stopping = false;
|
|
1882
2315
|
/** The sweep in flight, so shutdown can wait for it before the store closes. */
|
|
1883
2316
|
current;
|
|
1884
|
-
constructor(store, options) {
|
|
2317
|
+
constructor(store, options, leases = new SweepLeases()) {
|
|
1885
2318
|
this.store = store;
|
|
1886
2319
|
this.options = options;
|
|
2320
|
+
this.leases = leases;
|
|
1887
2321
|
}
|
|
1888
2322
|
/** Non-null once past the `isDrivingOperator` guard (which requires `options.store` to be set). */
|
|
1889
2323
|
requireStore() {
|
|
@@ -1902,7 +2336,7 @@ var RetentionPoller = class {
|
|
|
1902
2336
|
return;
|
|
1903
2337
|
}
|
|
1904
2338
|
void this.sweep();
|
|
1905
|
-
const intervalMs = retention.sweepInterval != null ? (0,
|
|
2339
|
+
const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core13.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
|
|
1906
2340
|
if (intervalMs > 0) {
|
|
1907
2341
|
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
1908
2342
|
this.timer.unref?.();
|
|
@@ -1945,37 +2379,42 @@ var RetentionPoller = class {
|
|
|
1945
2379
|
if (!retention || typeof prune !== "function") return;
|
|
1946
2380
|
this.sweeping = true;
|
|
1947
2381
|
try {
|
|
1948
|
-
|
|
1949
|
-
const now = Date.now();
|
|
1950
|
-
for (const policy of retention.policies) {
|
|
1951
|
-
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
1952
|
-
if (this.stopping) return;
|
|
1953
|
-
const deleted = await prune.call(store, policy, now, batchSize);
|
|
1954
|
-
if (deleted < batchSize) break;
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
2382
|
+
await this.leases.run("retention", () => this.prune(retention, store, prune));
|
|
1957
2383
|
} catch (error) {
|
|
1958
2384
|
console.error("[nestjs-durable] retention sweep failed; retrying next interval:", error);
|
|
1959
2385
|
} finally {
|
|
1960
2386
|
this.sweeping = false;
|
|
1961
2387
|
}
|
|
1962
2388
|
}
|
|
2389
|
+
async prune(retention, store, prune) {
|
|
2390
|
+
const batchSize = retention.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
2391
|
+
const now = Date.now();
|
|
2392
|
+
for (const policy of retention.policies) {
|
|
2393
|
+
for (let batch = 0; batch < MAX_BATCHES_PER_POLICY; batch++) {
|
|
2394
|
+
if (this.stopping) return;
|
|
2395
|
+
const deleted = await prune.call(store, policy, now, batchSize);
|
|
2396
|
+
if (deleted < batchSize) break;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
1963
2400
|
};
|
|
1964
|
-
RetentionPoller =
|
|
1965
|
-
(0,
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
2401
|
+
RetentionPoller = _ts_decorate8([
|
|
2402
|
+
(0, import_common8.Injectable)(),
|
|
2403
|
+
_ts_param5(0, (0, import_common8.Inject)(import_nestjs_durable_core13.STATE_STORE_CANONICAL)),
|
|
2404
|
+
_ts_param5(1, (0, import_common8.Inject)(import_nestjs_durable_core13.DURABLE_OPTIONS_CANONICAL)),
|
|
2405
|
+
_ts_param5(2, (0, import_common8.Optional)()),
|
|
2406
|
+
_ts_metadata8("design:type", Function),
|
|
2407
|
+
_ts_metadata8("design:paramtypes", [
|
|
1970
2408
|
Object,
|
|
1971
|
-
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2409
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
2410
|
+
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
1972
2411
|
])
|
|
1973
2412
|
], RetentionPoller);
|
|
1974
2413
|
|
|
1975
2414
|
// src/store-run-gateway.ts
|
|
1976
|
-
var
|
|
1977
|
-
var
|
|
1978
|
-
function
|
|
2415
|
+
var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
|
|
2416
|
+
var import_common9 = require("@nestjs/common");
|
|
2417
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1979
2418
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1980
2419
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1981
2420
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1988,19 +2427,46 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
1988
2427
|
}
|
|
1989
2428
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1990
2429
|
}
|
|
1991
|
-
__name(
|
|
1992
|
-
function
|
|
2430
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
2431
|
+
function _ts_metadata9(metadataKey, metadataValue) {
|
|
1993
2432
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1994
2433
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1995
2434
|
}
|
|
1996
2435
|
}
|
|
1997
|
-
__name(
|
|
1998
|
-
function
|
|
2436
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2437
|
+
function _ts_param6(paramIndex, decorator) {
|
|
1999
2438
|
return function(target, key) {
|
|
2000
2439
|
decorator(target, key, paramIndex);
|
|
2001
2440
|
};
|
|
2002
2441
|
}
|
|
2003
|
-
__name(
|
|
2442
|
+
__name(_ts_param6, "_ts_param");
|
|
2443
|
+
function detailExtras(links) {
|
|
2444
|
+
const { lifecycleSubscribers, lifecycleDeliveries, waitsFor, awaitedBy, triggeredBy } = links;
|
|
2445
|
+
if (!lifecycleSubscribers && !lifecycleDeliveries && !waitsFor && !awaitedBy && !triggeredBy) {
|
|
2446
|
+
return void 0;
|
|
2447
|
+
}
|
|
2448
|
+
return {
|
|
2449
|
+
lifecycleSubscribers,
|
|
2450
|
+
lifecycleDeliveries,
|
|
2451
|
+
waitsFor,
|
|
2452
|
+
awaitedBy,
|
|
2453
|
+
triggeredBy
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
__name(detailExtras, "detailExtras");
|
|
2457
|
+
function withoutRegistry(query) {
|
|
2458
|
+
if (query.workflow === import_nestjs_durable_core14.LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(import_nestjs_durable_core14.LIFECYCLE_REGISTRY_WORKFLOW)) {
|
|
2459
|
+
return query;
|
|
2460
|
+
}
|
|
2461
|
+
return {
|
|
2462
|
+
...query,
|
|
2463
|
+
excludeWorkflows: [
|
|
2464
|
+
...query.excludeWorkflows ?? [],
|
|
2465
|
+
import_nestjs_durable_core14.LIFECYCLE_REGISTRY_WORKFLOW
|
|
2466
|
+
]
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
__name(withoutRegistry, "withoutRegistry");
|
|
2004
2470
|
var StoreRunGateway = class {
|
|
2005
2471
|
static {
|
|
2006
2472
|
__name(this, "StoreRunGateway");
|
|
@@ -2019,6 +2485,7 @@ var StoreRunGateway = class {
|
|
|
2019
2485
|
async getRunDetail(runId, options) {
|
|
2020
2486
|
const run = await this.store.getRun(runId);
|
|
2021
2487
|
if (!run) return null;
|
|
2488
|
+
const links = await this.lifecycleLinks(run);
|
|
2022
2489
|
const over = options?.summarizeFansOver;
|
|
2023
2490
|
if (over === void 0) {
|
|
2024
2491
|
const [timeline2, children] = await Promise.all([
|
|
@@ -2028,13 +2495,14 @@ var StoreRunGateway = class {
|
|
|
2028
2495
|
return {
|
|
2029
2496
|
run,
|
|
2030
2497
|
timeline: timeline2,
|
|
2031
|
-
children
|
|
2498
|
+
children,
|
|
2499
|
+
...links
|
|
2032
2500
|
};
|
|
2033
2501
|
}
|
|
2034
|
-
if ((0,
|
|
2502
|
+
if ((0, import_nestjs_durable_core14.aggregatesCheckpoints)(this.store)) {
|
|
2035
2503
|
const stats = await this.store.checkpointStats(runId);
|
|
2036
|
-
const etag = (0,
|
|
2037
|
-
if ((0,
|
|
2504
|
+
const etag = (0, import_nestjs_durable_core14.extendEtag)((0, import_nestjs_durable_core14.runDetailEtag)(run, stats, over), detailExtras(links));
|
|
2505
|
+
if ((0, import_nestjs_durable_core14.etagMatches)(options?.ifNoneMatch, etag)) {
|
|
2038
2506
|
return {
|
|
2039
2507
|
run,
|
|
2040
2508
|
timeline: [],
|
|
@@ -2045,32 +2513,132 @@ var StoreRunGateway = class {
|
|
|
2045
2513
|
}
|
|
2046
2514
|
return {
|
|
2047
2515
|
run,
|
|
2048
|
-
...await (0,
|
|
2049
|
-
etag
|
|
2516
|
+
...await (0, import_nestjs_durable_core14.summarizeRunFromStore)(this.store, runId, over, stats),
|
|
2517
|
+
etag,
|
|
2518
|
+
...links
|
|
2050
2519
|
};
|
|
2051
2520
|
}
|
|
2052
2521
|
const full = await this.store.listCheckpoints(runId);
|
|
2053
|
-
const { timeline, fans } = (0,
|
|
2054
|
-
const ids = (0,
|
|
2522
|
+
const { timeline, fans } = (0, import_nestjs_durable_core14.summarizeTimeline)(full, over);
|
|
2523
|
+
const ids = (0, import_nestjs_durable_core14.childIdsOf)(full);
|
|
2055
2524
|
return {
|
|
2056
2525
|
run,
|
|
2057
2526
|
timeline,
|
|
2058
|
-
children: ids.slice(0,
|
|
2527
|
+
children: ids.slice(0, import_nestjs_durable_core14.SUMMARY_CHILD_LIMIT),
|
|
2059
2528
|
fans,
|
|
2060
|
-
childCount: ids.length
|
|
2529
|
+
childCount: ids.length,
|
|
2530
|
+
...links
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* What a run detail reads beyond the run row and its checkpoints: what this run's settling
|
|
2535
|
+
* started, the subscribers its lifecycle event goes to (of its namespace) and where it stands for
|
|
2536
|
+
* each, what started it, its workflow's lifecycle links, and the `ctx.waitForRun` waits on either
|
|
2537
|
+
* side of it with the other run's status. A few reads per detail: the run's own waiters while it
|
|
2538
|
+
* is suspended, the waiters on it (one prefix read), and one batched read of every linked run.
|
|
2539
|
+
*/
|
|
2540
|
+
async lifecycleLinks(run) {
|
|
2541
|
+
const triggered = await this.engine.triggeredRuns(run);
|
|
2542
|
+
const source = (0, import_nestjs_durable_core14.lifecycleSourceOf)(run);
|
|
2543
|
+
const kind = (0, import_nestjs_durable_core14.lifecycleKindOf)(run.status);
|
|
2544
|
+
const subscribers = kind ? await this.engine.lifecycleSubscribers(run.workflow, kind, run.namespace || "default") : [];
|
|
2545
|
+
const workflowLifecycle = await this.engine.workflowLifecycle(run.workflow);
|
|
2546
|
+
const linked = workflowLifecycle.startsOnSettle.length > 0 || workflowLifecycle.startedBy.length > 0;
|
|
2547
|
+
const deliveries = kind ? (0, import_nestjs_durable_core14.lifecycleDeliveriesOf)(run, {
|
|
2548
|
+
subscribers,
|
|
2549
|
+
live: new Set(subscribers),
|
|
2550
|
+
coalesced: this.engine.coalescedSubscribers(run)
|
|
2551
|
+
}) : [];
|
|
2552
|
+
const [own, onIt] = await Promise.all([
|
|
2553
|
+
run.status === "suspended" ? (0, import_nestjs_durable_core14.listSignalWaitersOfRuns)(this.store, [
|
|
2554
|
+
run.id
|
|
2555
|
+
]) : [],
|
|
2556
|
+
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0, import_nestjs_durable_core14.runWaitPrefix)(run.id))
|
|
2557
|
+
]);
|
|
2558
|
+
const waitsFor = own.flatMap((w) => {
|
|
2559
|
+
const target = (0, import_nestjs_durable_core14.runWaitTargetOf)(w);
|
|
2560
|
+
return target !== void 0 ? [
|
|
2561
|
+
{
|
|
2562
|
+
runId: target,
|
|
2563
|
+
seq: w.seq
|
|
2564
|
+
}
|
|
2565
|
+
] : [];
|
|
2566
|
+
});
|
|
2567
|
+
const awaitedBy = onIt.filter((w) => (0, import_nestjs_durable_core14.runWaitTargetOf)(w) === run.id).map((w) => ({
|
|
2568
|
+
runId: w.runId,
|
|
2569
|
+
seq: w.seq
|
|
2570
|
+
}));
|
|
2571
|
+
const started = deliveries.flatMap((d) => d.state === "started" && d.runId !== void 0 ? [
|
|
2572
|
+
d.runId
|
|
2573
|
+
] : []);
|
|
2574
|
+
const { runs } = await (0, import_nestjs_durable_core14.readRunsByIds)(this.store, [
|
|
2575
|
+
...source ? [
|
|
2576
|
+
source.runId
|
|
2577
|
+
] : [],
|
|
2578
|
+
...started,
|
|
2579
|
+
...waitsFor.map((l) => l.runId),
|
|
2580
|
+
...awaitedBy.map((l) => l.runId)
|
|
2581
|
+
]);
|
|
2582
|
+
const withRun = /* @__PURE__ */ __name((link) => {
|
|
2583
|
+
const other = link.runId !== void 0 ? runs.get(link.runId) : void 0;
|
|
2584
|
+
return other ? {
|
|
2585
|
+
...link,
|
|
2586
|
+
status: other.status,
|
|
2587
|
+
namespace: other.namespace
|
|
2588
|
+
} : link;
|
|
2589
|
+
}, "withRun");
|
|
2590
|
+
const sourceRun = source ? runs.get(source.runId) : void 0;
|
|
2591
|
+
const traceId = (0, import_nestjs_durable_core14.traceIdOfTraceparent)((0, import_nestjs_durable_core14.lifecycleTraceparentOf)(sourceRun?.tags));
|
|
2592
|
+
return {
|
|
2593
|
+
...triggered.length > 0 ? {
|
|
2594
|
+
triggered
|
|
2595
|
+
} : {},
|
|
2596
|
+
...source ? {
|
|
2597
|
+
triggeredBy: {
|
|
2598
|
+
...source,
|
|
2599
|
+
...sourceRun ? {
|
|
2600
|
+
status: sourceRun.status,
|
|
2601
|
+
namespace: sourceRun.namespace
|
|
2602
|
+
} : {},
|
|
2603
|
+
...traceId ? {
|
|
2604
|
+
traceId
|
|
2605
|
+
} : {}
|
|
2606
|
+
}
|
|
2607
|
+
} : {},
|
|
2608
|
+
...subscribers.length > 0 ? {
|
|
2609
|
+
lifecycleSubscribers: subscribers
|
|
2610
|
+
} : {},
|
|
2611
|
+
...linked ? {
|
|
2612
|
+
workflowLifecycle
|
|
2613
|
+
} : {},
|
|
2614
|
+
...deliveries.length > 0 ? {
|
|
2615
|
+
lifecycleDeliveries: deliveries.map((d) => d.state === "started" ? withRun(d) : d)
|
|
2616
|
+
} : {},
|
|
2617
|
+
...waitsFor.length > 0 ? {
|
|
2618
|
+
waitsFor: waitsFor.map(withRun)
|
|
2619
|
+
} : {},
|
|
2620
|
+
...awaitedBy.length > 0 ? {
|
|
2621
|
+
awaitedBy: awaitedBy.map(withRun)
|
|
2622
|
+
} : {}
|
|
2061
2623
|
};
|
|
2062
2624
|
}
|
|
2625
|
+
workflowLifecycle(workflow, opts) {
|
|
2626
|
+
return this.engine.workflowLifecycle(workflow, opts);
|
|
2627
|
+
}
|
|
2628
|
+
lifecycleSubscribers(workflow, kind, namespace) {
|
|
2629
|
+
return this.engine.lifecycleSubscribers(workflow, kind, namespace);
|
|
2630
|
+
}
|
|
2063
2631
|
getRun(runId) {
|
|
2064
2632
|
return this.store.getRun(runId);
|
|
2065
2633
|
}
|
|
2066
2634
|
async getFanMembers(runId, group, query) {
|
|
2067
2635
|
if (!await this.store.getRun(runId)) return null;
|
|
2068
|
-
if ((0,
|
|
2636
|
+
if ((0, import_nestjs_durable_core14.aggregatesCheckpoints)(this.store)) {
|
|
2069
2637
|
const stats = await this.store.checkpointStats(runId, {
|
|
2070
2638
|
group
|
|
2071
2639
|
});
|
|
2072
|
-
const etag = (0,
|
|
2073
|
-
if ((0,
|
|
2640
|
+
const etag = (0, import_nestjs_durable_core14.fanPageEtag)(group, stats, query);
|
|
2641
|
+
if ((0, import_nestjs_durable_core14.etagMatches)(query.ifNoneMatch, etag)) {
|
|
2074
2642
|
return {
|
|
2075
2643
|
items: [],
|
|
2076
2644
|
total: 0,
|
|
@@ -2079,17 +2647,17 @@ var StoreRunGateway = class {
|
|
|
2079
2647
|
};
|
|
2080
2648
|
}
|
|
2081
2649
|
return {
|
|
2082
|
-
...await (0,
|
|
2650
|
+
...await (0, import_nestjs_durable_core14.pageFanFromStore)(this.store, runId, group, query, stats),
|
|
2083
2651
|
etag
|
|
2084
2652
|
};
|
|
2085
2653
|
}
|
|
2086
|
-
return (0,
|
|
2654
|
+
return (0, import_nestjs_durable_core14.pageFan)(await this.store.listCheckpoints(runId), group, query);
|
|
2087
2655
|
}
|
|
2088
2656
|
async listRuns(query) {
|
|
2089
|
-
const runs = await this.store.listRuns(query);
|
|
2090
|
-
const waiterByRun = (0,
|
|
2657
|
+
const runs = await this.store.listRuns(withoutRegistry(query));
|
|
2658
|
+
const waiterByRun = (0, import_nestjs_durable_core14.indexWaitersByRun)(await (0, import_nestjs_durable_core14.listSignalWaitersOfRuns)(this.store, runs.filter((run) => run.status === "suspended").map((run) => run.id)));
|
|
2091
2659
|
return runs.map((run) => {
|
|
2092
|
-
const waiting = (0,
|
|
2660
|
+
const waiting = (0, import_nestjs_durable_core14.resolveRunWaiting)(run, waiterByRun);
|
|
2093
2661
|
return waiting ? {
|
|
2094
2662
|
...run,
|
|
2095
2663
|
waiting
|
|
@@ -2103,9 +2671,10 @@ var StoreRunGateway = class {
|
|
|
2103
2671
|
* listing — correct, but the unbounded read this exists to avoid, so it is the last resort.
|
|
2104
2672
|
*/
|
|
2105
2673
|
async runFacets(query) {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2674
|
+
const scoped = withoutRegistry(query);
|
|
2675
|
+
if (this.store.runFacets) return this.store.runFacets(scoped);
|
|
2676
|
+
const runs = await this.store.listRuns(scoped);
|
|
2677
|
+
return (0, import_nestjs_durable_core14.mergeRunFacetRows)(runs.map((r) => ({
|
|
2109
2678
|
status: r.status,
|
|
2110
2679
|
origin: r.origin,
|
|
2111
2680
|
count: 1
|
|
@@ -2119,7 +2688,7 @@ var StoreRunGateway = class {
|
|
|
2119
2688
|
* still works without it.
|
|
2120
2689
|
*/
|
|
2121
2690
|
async runValueFacets(axis, query, opts) {
|
|
2122
|
-
return this.store.runValueFacets?.(axis, query, opts) ?? [];
|
|
2691
|
+
return this.store.runValueFacets?.(axis, withoutRegistry(query), opts) ?? [];
|
|
2123
2692
|
}
|
|
2124
2693
|
/**
|
|
2125
2694
|
* Bulk-resolve what each of `runIds` is currently parked on — for a consumer with its own filtered/
|
|
@@ -2140,13 +2709,13 @@ var StoreRunGateway = class {
|
|
|
2140
2709
|
"suspended"
|
|
2141
2710
|
]
|
|
2142
2711
|
}),
|
|
2143
|
-
(0,
|
|
2712
|
+
(0, import_nestjs_durable_core14.listSignalWaitersOfRuns)(this.store, runIds)
|
|
2144
2713
|
]);
|
|
2145
|
-
const waiterByRun = (0,
|
|
2714
|
+
const waiterByRun = (0, import_nestjs_durable_core14.indexWaitersByRun)(waiters);
|
|
2146
2715
|
const result = {};
|
|
2147
2716
|
for (const run of suspended) {
|
|
2148
2717
|
if (!idSet.has(run.id)) continue;
|
|
2149
|
-
const waiting = (0,
|
|
2718
|
+
const waiting = (0, import_nestjs_durable_core14.resolveRunWaiting)(run, waiterByRun);
|
|
2150
2719
|
if (waiting) result[run.id] = waiting;
|
|
2151
2720
|
}
|
|
2152
2721
|
return result;
|
|
@@ -2172,19 +2741,22 @@ var StoreRunGateway = class {
|
|
|
2172
2741
|
redispatchPending(runId) {
|
|
2173
2742
|
return this.engine.redispatchPending(runId);
|
|
2174
2743
|
}
|
|
2744
|
+
republishLifecycle(target) {
|
|
2745
|
+
return this.engine.republishLifecycle(target);
|
|
2746
|
+
}
|
|
2175
2747
|
subscribe(runId, onEvent) {
|
|
2176
2748
|
return this.engine.subscribe((event) => {
|
|
2177
2749
|
if (event.runId === runId) onEvent(event);
|
|
2178
2750
|
});
|
|
2179
2751
|
}
|
|
2180
2752
|
};
|
|
2181
|
-
StoreRunGateway =
|
|
2182
|
-
(0,
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2753
|
+
StoreRunGateway = _ts_decorate9([
|
|
2754
|
+
(0, import_common9.Injectable)(),
|
|
2755
|
+
_ts_param6(0, (0, import_common9.Inject)(import_nestjs_durable_core14.STATE_STORE_CANONICAL)),
|
|
2756
|
+
_ts_metadata9("design:type", Function),
|
|
2757
|
+
_ts_metadata9("design:paramtypes", [
|
|
2186
2758
|
typeof StateStore === "undefined" ? Object : StateStore,
|
|
2187
|
-
typeof
|
|
2759
|
+
typeof import_nestjs_durable_core14.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core14.WorkflowEngine
|
|
2188
2760
|
])
|
|
2189
2761
|
], StoreRunGateway);
|
|
2190
2762
|
|
|
@@ -2230,9 +2802,9 @@ var TenantEventRepublisher = class {
|
|
|
2230
2802
|
};
|
|
2231
2803
|
|
|
2232
2804
|
// src/timer-poller.ts
|
|
2233
|
-
var
|
|
2234
|
-
var
|
|
2235
|
-
function
|
|
2805
|
+
var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
|
|
2806
|
+
var import_common10 = require("@nestjs/common");
|
|
2807
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
2236
2808
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2237
2809
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2238
2810
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2245,36 +2817,38 @@ function _ts_decorate9(decorators, target, key, desc) {
|
|
|
2245
2817
|
}
|
|
2246
2818
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2247
2819
|
}
|
|
2248
|
-
__name(
|
|
2249
|
-
function
|
|
2820
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
2821
|
+
function _ts_metadata10(metadataKey, metadataValue) {
|
|
2250
2822
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2251
2823
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2252
2824
|
}
|
|
2253
2825
|
}
|
|
2254
|
-
__name(
|
|
2255
|
-
function
|
|
2826
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2827
|
+
function _ts_param7(paramIndex, decorator) {
|
|
2256
2828
|
return function(target, key) {
|
|
2257
2829
|
decorator(target, key, paramIndex);
|
|
2258
2830
|
};
|
|
2259
2831
|
}
|
|
2260
|
-
__name(
|
|
2832
|
+
__name(_ts_param7, "_ts_param");
|
|
2261
2833
|
var TimerPoller = class {
|
|
2262
2834
|
static {
|
|
2263
2835
|
__name(this, "TimerPoller");
|
|
2264
2836
|
}
|
|
2265
2837
|
engine;
|
|
2266
2838
|
options;
|
|
2839
|
+
leases;
|
|
2267
2840
|
timer;
|
|
2268
2841
|
polling = false;
|
|
2269
2842
|
/** The sweep in flight, so shutdown can wait for it instead of racing the store's close. */
|
|
2270
2843
|
current;
|
|
2271
2844
|
unsubscribeEnqueued;
|
|
2272
|
-
constructor(engine, options) {
|
|
2845
|
+
constructor(engine, options, leases = new SweepLeases()) {
|
|
2273
2846
|
this.engine = engine;
|
|
2274
2847
|
this.options = options;
|
|
2848
|
+
this.leases = leases;
|
|
2275
2849
|
}
|
|
2276
2850
|
async onApplicationBootstrap() {
|
|
2277
|
-
for (const s of this.options.schedules ?? []) (0,
|
|
2851
|
+
for (const s of this.options.schedules ?? []) (0, import_nestjs_durable_core15.workflowName)(s.workflow);
|
|
2278
2852
|
if (!isDrivingOperator(this.options)) return;
|
|
2279
2853
|
this.engine.consumeRuns?.();
|
|
2280
2854
|
this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
|
|
@@ -2344,11 +2918,13 @@ var TimerPoller = class {
|
|
|
2344
2918
|
await this.sweep("recoverIncomplete", () => this.engine.recoverIncomplete());
|
|
2345
2919
|
await this.sweep("resumeDueTimers", () => this.engine.resumeDueTimers());
|
|
2346
2920
|
await this.sweep("sweepTimeouts", () => this.engine.sweepTimeouts());
|
|
2347
|
-
await this.sweep("sweepStalled", async () => this.engine.sweepStalled?.());
|
|
2348
|
-
await this.sweep("sweepBufferedSignals", async () => this.engine.sweepBufferedSignals?.());
|
|
2921
|
+
await this.sweep("sweepStalled", () => this.leases.run("stalled-pager", async () => this.engine.sweepStalled?.()));
|
|
2922
|
+
await this.sweep("sweepBufferedSignals", () => this.leases.run("buffered-signals", async () => this.engine.sweepBufferedSignals?.()));
|
|
2923
|
+
await this.sweep("sweepExpiredSignalIds", () => this.leases.run("signal-ids", async () => this.engine.sweepExpiredSignalIds?.()));
|
|
2924
|
+
await this.sweep("sweepLifecycleEvents", async () => this.engine.sweepLifecycleEvents?.());
|
|
2349
2925
|
const schedules = this.options.schedules;
|
|
2350
2926
|
if (schedules && schedules.length > 0) {
|
|
2351
|
-
await this.sweep("schedules", () => (0,
|
|
2927
|
+
await this.sweep("schedules", () => (0, import_nestjs_durable_core15.runSchedules)(this.engine, schedules, Date.now()));
|
|
2352
2928
|
}
|
|
2353
2929
|
if (this.options.persistedSchedules) {
|
|
2354
2930
|
await this.sweep("persistedSchedules", () => this.engine.schedules.tick());
|
|
@@ -2364,25 +2940,27 @@ var TimerPoller = class {
|
|
|
2364
2940
|
}
|
|
2365
2941
|
}
|
|
2366
2942
|
};
|
|
2367
|
-
TimerPoller =
|
|
2368
|
-
(0,
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
typeof
|
|
2943
|
+
TimerPoller = _ts_decorate10([
|
|
2944
|
+
(0, import_common10.Injectable)(),
|
|
2945
|
+
_ts_param7(1, (0, import_common10.Inject)(import_nestjs_durable_core15.DURABLE_OPTIONS_CANONICAL)),
|
|
2946
|
+
_ts_param7(2, (0, import_common10.Optional)()),
|
|
2947
|
+
_ts_metadata10("design:type", Function),
|
|
2948
|
+
_ts_metadata10("design:paramtypes", [
|
|
2949
|
+
typeof import_nestjs_durable_core15.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core15.WorkflowEngine,
|
|
2950
|
+
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
2951
|
+
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
2374
2952
|
])
|
|
2375
2953
|
], TimerPoller);
|
|
2376
2954
|
|
|
2377
2955
|
// src/tokens.ts
|
|
2378
|
-
var
|
|
2956
|
+
var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
|
|
2379
2957
|
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
2380
|
-
var RUN_GATEWAY =
|
|
2958
|
+
var RUN_GATEWAY = import_nestjs_durable_core16.RunGateway;
|
|
2381
2959
|
|
|
2382
2960
|
// src/workflow.registrar.ts
|
|
2383
|
-
var
|
|
2384
|
-
var
|
|
2385
|
-
var
|
|
2961
|
+
var import_nestjs_durable_core17 = require("@dudousxd/nestjs-durable-core");
|
|
2962
|
+
var import_common11 = require("@nestjs/common");
|
|
2963
|
+
var import_core5 = require("@nestjs/core");
|
|
2386
2964
|
|
|
2387
2965
|
// src/step-interceptor.ts
|
|
2388
2966
|
var import_reflect_metadata3 = require("reflect-metadata");
|
|
@@ -2399,7 +2977,7 @@ function isStepInterceptor(target) {
|
|
|
2399
2977
|
__name(isStepInterceptor, "isStepInterceptor");
|
|
2400
2978
|
|
|
2401
2979
|
// src/workflow.registrar.ts
|
|
2402
|
-
function
|
|
2980
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2403
2981
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2404
2982
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2405
2983
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2412,19 +2990,19 @@ function _ts_decorate10(decorators, target, key, desc) {
|
|
|
2412
2990
|
}
|
|
2413
2991
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2414
2992
|
}
|
|
2415
|
-
__name(
|
|
2416
|
-
function
|
|
2993
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
2994
|
+
function _ts_metadata11(metadataKey, metadataValue) {
|
|
2417
2995
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2418
2996
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2419
2997
|
}
|
|
2420
2998
|
}
|
|
2421
|
-
__name(
|
|
2422
|
-
function
|
|
2999
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
3000
|
+
function _ts_param8(paramIndex, decorator) {
|
|
2423
3001
|
return function(target, key) {
|
|
2424
3002
|
decorator(target, key, paramIndex);
|
|
2425
3003
|
};
|
|
2426
3004
|
}
|
|
2427
|
-
__name(
|
|
3005
|
+
__name(_ts_param8, "_ts_param");
|
|
2428
3006
|
var UNSERVED_ROUTES_RECHECK_MS = 3e4;
|
|
2429
3007
|
var WorkflowRegistrar = class {
|
|
2430
3008
|
static {
|
|
@@ -2488,15 +3066,8 @@ var WorkflowRegistrar = class {
|
|
|
2488
3066
|
if (origin === void 0) unattributed.push(meta.name);
|
|
2489
3067
|
const io = workflowIo(meta);
|
|
2490
3068
|
const body = io.wrap((ctx, input) => workflow.run(ctx, input));
|
|
2491
|
-
const eventBatch = meta.debounce ? {
|
|
2492
|
-
mode: "debounce",
|
|
2493
|
-
windowMs: (0, import_nestjs_durable_core16.parseDuration)(meta.debounce)
|
|
2494
|
-
} : meta.batch ? {
|
|
2495
|
-
mode: "batch",
|
|
2496
|
-
maxSize: meta.batch.maxSize,
|
|
2497
|
-
windowMs: (0, import_nestjs_durable_core16.parseDuration)(meta.batch.within)
|
|
2498
|
-
} : void 0;
|
|
2499
3069
|
const workflowCtor = workflow.constructor;
|
|
3070
|
+
const eventBatch = eventBatchOf(meta, workflowCtor);
|
|
2500
3071
|
const onError = onErrorHandlersOf(meta, workflow, this.metadataScanner);
|
|
2501
3072
|
for (const [name, fn] of onError.handlers) {
|
|
2502
3073
|
this.engine.register(name, meta.version, fn, {
|
|
@@ -2528,11 +3099,11 @@ var WorkflowRegistrar = class {
|
|
|
2528
3099
|
// so a turn dispatched under the wrong token would never be consumed. Absent → the inline fast
|
|
2529
3100
|
// path (unchanged).
|
|
2530
3101
|
...this.inAppWorker ? {
|
|
2531
|
-
group: (0,
|
|
2532
|
-
executor: new
|
|
3102
|
+
group: (0, import_nestjs_durable_core17.tenantGroup)((0, import_nestjs_durable_core17.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
|
|
3103
|
+
executor: new import_nestjs_durable_core17.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
|
|
2533
3104
|
} : {}
|
|
2534
3105
|
});
|
|
2535
|
-
(0,
|
|
3106
|
+
(0, import_nestjs_durable_core17.bindWorkflowClass)(workflowCtor, {
|
|
2536
3107
|
start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
|
|
2537
3108
|
waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
|
|
2538
3109
|
});
|
|
@@ -2547,7 +3118,7 @@ var WorkflowRegistrar = class {
|
|
|
2547
3118
|
});
|
|
2548
3119
|
deadLetterByWorkflow.set(meta.name, dlqName);
|
|
2549
3120
|
} else if (meta.deadLetterWorkflow) {
|
|
2550
|
-
deadLetterByWorkflow.set(meta.name, (0,
|
|
3121
|
+
deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core17.workflowName)(meta.deadLetterWorkflow));
|
|
2551
3122
|
}
|
|
2552
3123
|
});
|
|
2553
3124
|
this.reportUnattributed(unattributed);
|
|
@@ -2595,7 +3166,7 @@ var WorkflowRegistrar = class {
|
|
|
2595
3166
|
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
2596
3167
|
*/
|
|
2597
3168
|
installDeadLetterRouting(byWorkflow) {
|
|
2598
|
-
const fallback = this.options.deadLetterWorkflow ? (0,
|
|
3169
|
+
const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core17.workflowName)(this.options.deadLetterWorkflow) : void 0;
|
|
2599
3170
|
if (byWorkflow.size === 0 && !fallback) return;
|
|
2600
3171
|
this.engine.onDead((run) => {
|
|
2601
3172
|
const target = byWorkflow.get(run.workflow) ?? fallback;
|
|
@@ -2618,16 +3189,16 @@ var WorkflowRegistrar = class {
|
|
|
2618
3189
|
});
|
|
2619
3190
|
}
|
|
2620
3191
|
};
|
|
2621
|
-
WorkflowRegistrar =
|
|
2622
|
-
(0,
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
typeof
|
|
2629
|
-
typeof
|
|
2630
|
-
typeof
|
|
3192
|
+
WorkflowRegistrar = _ts_decorate11([
|
|
3193
|
+
(0, import_common11.Injectable)(),
|
|
3194
|
+
_ts_param8(3, (0, import_common11.Inject)(import_nestjs_durable_core17.STATE_STORE_CANONICAL)),
|
|
3195
|
+
_ts_param8(4, (0, import_common11.Inject)(import_nestjs_durable_core17.DURABLE_OPTIONS_CANONICAL)),
|
|
3196
|
+
_ts_param8(5, (0, import_common11.Inject)(IN_APP_WORKER_BINDING)),
|
|
3197
|
+
_ts_metadata11("design:type", Function),
|
|
3198
|
+
_ts_metadata11("design:paramtypes", [
|
|
3199
|
+
typeof import_core5.DiscoveryService === "undefined" ? Object : import_core5.DiscoveryService,
|
|
3200
|
+
typeof import_core5.MetadataScanner === "undefined" ? Object : import_core5.MetadataScanner,
|
|
3201
|
+
typeof import_nestjs_durable_core17.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core17.WorkflowEngine,
|
|
2631
3202
|
Object,
|
|
2632
3203
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
2633
3204
|
Object
|
|
@@ -2636,9 +3207,9 @@ WorkflowRegistrar = _ts_decorate10([
|
|
|
2636
3207
|
|
|
2637
3208
|
// src/workflow.service.ts
|
|
2638
3209
|
var import_node_crypto = require("crypto");
|
|
2639
|
-
var
|
|
2640
|
-
var
|
|
2641
|
-
function
|
|
3210
|
+
var import_nestjs_durable_core18 = require("@dudousxd/nestjs-durable-core");
|
|
3211
|
+
var import_common12 = require("@nestjs/common");
|
|
3212
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2642
3213
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2643
3214
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2644
3215
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2651,13 +3222,13 @@ function _ts_decorate11(decorators, target, key, desc) {
|
|
|
2651
3222
|
}
|
|
2652
3223
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2653
3224
|
}
|
|
2654
|
-
__name(
|
|
2655
|
-
function
|
|
3225
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
3226
|
+
function _ts_metadata12(metadataKey, metadataValue) {
|
|
2656
3227
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2657
3228
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2658
3229
|
}
|
|
2659
3230
|
}
|
|
2660
|
-
__name(
|
|
3231
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
2661
3232
|
var WorkflowService = class {
|
|
2662
3233
|
static {
|
|
2663
3234
|
__name(this, "WorkflowService");
|
|
@@ -2682,9 +3253,13 @@ var WorkflowService = class {
|
|
|
2682
3253
|
waitForRun(runId, opts) {
|
|
2683
3254
|
return this.engine.waitForRun(runId, opts);
|
|
2684
3255
|
}
|
|
2685
|
-
/**
|
|
2686
|
-
signal(
|
|
2687
|
-
|
|
3256
|
+
/**
|
|
3257
|
+
* Deliver an external signal (e.g. from a webhook) to the run waiting on `token`, or buffer it for
|
|
3258
|
+
* the next wait on it. With `{ id }`, a re-send with the same token and id is dropped (resolves
|
|
3259
|
+
* `null`): see {@link SignalOptions}.
|
|
3260
|
+
*/
|
|
3261
|
+
signal(token, payload, opts) {
|
|
3262
|
+
return this.engine.signal(token, payload, opts);
|
|
2688
3263
|
}
|
|
2689
3264
|
signalWithStart(workflow, input, runId, signal, opts) {
|
|
2690
3265
|
return this.engine.signalWithStart(workflow, input, runId, signal, opts);
|
|
@@ -2702,17 +3277,33 @@ var WorkflowService = class {
|
|
|
2702
3277
|
publishEvent(name, payload, opts) {
|
|
2703
3278
|
return this.engine.publishEvent(name, payload, opts);
|
|
2704
3279
|
}
|
|
3280
|
+
/**
|
|
3281
|
+
* The runs started by `runId` settling, through `@OnWorkflowCompleted` / `@OnWorkflowFailed` (or
|
|
3282
|
+
* an `onEvent` on `runCompletedEvent(...)`). Only subscribers registered on this engine are
|
|
3283
|
+
* considered. For the reverse link, `lifecycleSourceOf(run)` reads it from the run itself.
|
|
3284
|
+
*/
|
|
3285
|
+
triggeredRuns(runId) {
|
|
3286
|
+
return this.engine.triggeredRuns(runId);
|
|
3287
|
+
}
|
|
3288
|
+
/**
|
|
3289
|
+
* Publish settled runs' lifecycle events again: to a subscriber registered after they settled, or
|
|
3290
|
+
* one restricted by `subscriber`. Subscribers already started for a run are not started again.
|
|
3291
|
+
* See `WorkflowEngine.republishLifecycle`.
|
|
3292
|
+
*/
|
|
3293
|
+
republishLifecycle(target) {
|
|
3294
|
+
return this.engine.republishLifecycle(target);
|
|
3295
|
+
}
|
|
2705
3296
|
};
|
|
2706
|
-
WorkflowService =
|
|
2707
|
-
(0,
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
typeof
|
|
3297
|
+
WorkflowService = _ts_decorate12([
|
|
3298
|
+
(0, import_common12.Injectable)(),
|
|
3299
|
+
_ts_metadata12("design:type", Function),
|
|
3300
|
+
_ts_metadata12("design:paramtypes", [
|
|
3301
|
+
typeof import_nestjs_durable_core18.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core18.WorkflowEngine
|
|
2711
3302
|
])
|
|
2712
3303
|
], WorkflowService);
|
|
2713
3304
|
|
|
2714
3305
|
// src/durable.module.ts
|
|
2715
|
-
function
|
|
3306
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
2716
3307
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2717
3308
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2718
3309
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2725,19 +3316,19 @@ function _ts_decorate12(decorators, target, key, desc) {
|
|
|
2725
3316
|
}
|
|
2726
3317
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2727
3318
|
}
|
|
2728
|
-
__name(
|
|
2729
|
-
function
|
|
3319
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
3320
|
+
function _ts_metadata13(metadataKey, metadataValue) {
|
|
2730
3321
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2731
3322
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2732
3323
|
}
|
|
2733
3324
|
}
|
|
2734
|
-
__name(
|
|
2735
|
-
function
|
|
3325
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
3326
|
+
function _ts_param9(paramIndex, decorator) {
|
|
2736
3327
|
return function(target, key) {
|
|
2737
3328
|
decorator(target, key, paramIndex);
|
|
2738
3329
|
};
|
|
2739
3330
|
}
|
|
2740
|
-
__name(
|
|
3331
|
+
__name(_ts_param9, "_ts_param");
|
|
2741
3332
|
function resolveAccessor(moduleRef) {
|
|
2742
3333
|
try {
|
|
2743
3334
|
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
@@ -2925,16 +3516,16 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
|
|
|
2925
3516
|
this.unsubscribe?.();
|
|
2926
3517
|
}
|
|
2927
3518
|
};
|
|
2928
|
-
RunGatewayBootstrap =
|
|
2929
|
-
(0,
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
typeof
|
|
3519
|
+
RunGatewayBootstrap = _ts_decorate13([
|
|
3520
|
+
(0, import_common13.Injectable)(),
|
|
3521
|
+
_ts_param9(1, (0, import_common13.Inject)(import_nestjs_durable_core19.TRANSPORT_CANONICAL)),
|
|
3522
|
+
_ts_param9(3, (0, import_common13.Inject)(import_nestjs_durable_core19.STATE_STORE_CANONICAL)),
|
|
3523
|
+
_ts_param9(4, (0, import_common13.Inject)(import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL)),
|
|
3524
|
+
_ts_metadata13("design:type", Function),
|
|
3525
|
+
_ts_metadata13("design:paramtypes", [
|
|
3526
|
+
typeof import_nestjs_durable_core19.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core19.WorkflowEngine,
|
|
2936
3527
|
Object,
|
|
2937
|
-
typeof
|
|
3528
|
+
typeof import_nestjs_durable_core19.RunGateway === "undefined" ? Object : import_nestjs_durable_core19.RunGateway,
|
|
2938
3529
|
Object,
|
|
2939
3530
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions
|
|
2940
3531
|
])
|
|
@@ -2946,13 +3537,13 @@ var DurableModule = class _DurableModule {
|
|
|
2946
3537
|
static forRoot(options) {
|
|
2947
3538
|
_DurableModule.assertValid(options);
|
|
2948
3539
|
return _DurableModule.build({
|
|
2949
|
-
provide:
|
|
3540
|
+
provide: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
|
|
2950
3541
|
useValue: resolveTopology(options)
|
|
2951
3542
|
});
|
|
2952
3543
|
}
|
|
2953
3544
|
static forRootAsync(options) {
|
|
2954
3545
|
return _DurableModule.build({
|
|
2955
|
-
provide:
|
|
3546
|
+
provide: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
|
|
2956
3547
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
2957
3548
|
const resolved = await options.useFactory(...args);
|
|
2958
3549
|
_DurableModule.assertValid(resolved);
|
|
@@ -2980,46 +3571,46 @@ var DurableModule = class _DurableModule {
|
|
|
2980
3571
|
module: _DurableModule,
|
|
2981
3572
|
global: true,
|
|
2982
3573
|
imports: [
|
|
2983
|
-
|
|
3574
|
+
import_core6.DiscoveryModule
|
|
2984
3575
|
],
|
|
2985
3576
|
providers: [
|
|
2986
3577
|
optionsProvider,
|
|
2987
3578
|
{
|
|
2988
|
-
provide:
|
|
3579
|
+
provide: import_nestjs_durable_core19.STATE_STORE_CANONICAL,
|
|
2989
3580
|
useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
|
|
2990
3581
|
inject: [
|
|
2991
|
-
|
|
3582
|
+
import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
|
|
2992
3583
|
]
|
|
2993
3584
|
},
|
|
2994
3585
|
{
|
|
2995
|
-
provide:
|
|
3586
|
+
provide: import_nestjs_durable_core19.TRANSPORT_CANONICAL,
|
|
2996
3587
|
// With a POOL (`transports`) and no singular `transport`, the canonical transport is the
|
|
2997
3588
|
// pool's PRIMARY — the same one the engine dispatches on first. Leaving it null starved
|
|
2998
3589
|
// the step registrar / in-app worker of a transport, so a pool-configured operator
|
|
2999
3590
|
// registered NO step handlers and its own steps parked in `wait` with no consumer.
|
|
3000
3591
|
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
|
|
3001
3592
|
inject: [
|
|
3002
|
-
|
|
3593
|
+
import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
|
|
3003
3594
|
]
|
|
3004
3595
|
},
|
|
3005
3596
|
// Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
|
|
3006
3597
|
{
|
|
3007
|
-
provide:
|
|
3008
|
-
useExisting:
|
|
3598
|
+
provide: import_nestjs_durable_core19.STATE_STORE,
|
|
3599
|
+
useExisting: import_nestjs_durable_core19.STATE_STORE_CANONICAL
|
|
3009
3600
|
},
|
|
3010
3601
|
{
|
|
3011
|
-
provide:
|
|
3012
|
-
useExisting:
|
|
3602
|
+
provide: import_nestjs_durable_core19.TRANSPORT,
|
|
3603
|
+
useExisting: import_nestjs_durable_core19.TRANSPORT_CANONICAL
|
|
3013
3604
|
},
|
|
3014
3605
|
{
|
|
3015
|
-
provide:
|
|
3016
|
-
useExisting:
|
|
3606
|
+
provide: import_nestjs_durable_core19.DURABLE_OPTIONS,
|
|
3607
|
+
useExisting: import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL
|
|
3017
3608
|
},
|
|
3018
3609
|
{
|
|
3019
3610
|
// Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
|
|
3020
3611
|
// `DurableStartClient` facade for a thin worker (no `store`) — either way, `WorkflowService`
|
|
3021
3612
|
// and app code call `engine.start(...)` unchanged.
|
|
3022
|
-
provide:
|
|
3613
|
+
provide: import_nestjs_durable_core19.WorkflowEngine,
|
|
3023
3614
|
useFactory: /* @__PURE__ */ __name(async (options, store, transport, moduleRef) => {
|
|
3024
3615
|
if (options.store === void 0) {
|
|
3025
3616
|
return new DurableStartClient(options);
|
|
@@ -3040,7 +3631,7 @@ var DurableModule = class _DurableModule {
|
|
|
3040
3631
|
if (t) deferTransportConsumers(t);
|
|
3041
3632
|
}
|
|
3042
3633
|
}
|
|
3043
|
-
const engine = new
|
|
3634
|
+
const engine = new import_nestjs_durable_core19.WorkflowEngine({
|
|
3044
3635
|
store,
|
|
3045
3636
|
transport: transport ?? void 0,
|
|
3046
3637
|
transports: options.transports,
|
|
@@ -3056,8 +3647,12 @@ var DurableModule = class _DurableModule {
|
|
|
3056
3647
|
stalledAfterMs: options.stalledAfterMs,
|
|
3057
3648
|
timerBatchSize: options.timerBatchSize,
|
|
3058
3649
|
eventBufferTtlMs: options.eventBufferTtlMs,
|
|
3650
|
+
signalIdTtl: options.signalIdTtl,
|
|
3059
3651
|
blockedPollMs: options.blockedPollMs,
|
|
3060
3652
|
trackStepStart: options.trackStepStart,
|
|
3653
|
+
stickyRuns: options.stickyRuns,
|
|
3654
|
+
stickyIdleMs: options.stickyIdleMs,
|
|
3655
|
+
routeReplies: options.routeReplies,
|
|
3061
3656
|
instanceId: options.instanceId,
|
|
3062
3657
|
namespace: options.namespace,
|
|
3063
3658
|
webhookUrl: options.webhookUrl,
|
|
@@ -3082,23 +3677,24 @@ var DurableModule = class _DurableModule {
|
|
|
3082
3677
|
return engine;
|
|
3083
3678
|
}, "useFactory"),
|
|
3084
3679
|
inject: [
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3680
|
+
import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
|
|
3681
|
+
import_nestjs_durable_core19.STATE_STORE_CANONICAL,
|
|
3682
|
+
import_nestjs_durable_core19.TRANSPORT_CANONICAL,
|
|
3683
|
+
import_core6.ModuleRef
|
|
3089
3684
|
]
|
|
3090
3685
|
},
|
|
3091
3686
|
WorkflowService,
|
|
3092
3687
|
EntityService,
|
|
3093
3688
|
WorkflowRegistrar,
|
|
3094
3689
|
DurableStepRegistrar,
|
|
3690
|
+
SweepLeases,
|
|
3095
3691
|
TimerPoller,
|
|
3096
3692
|
RetentionPoller,
|
|
3097
3693
|
// Tenant run gateway: bound EXACTLY once — the store-backed `StoreRunGateway` for an operator,
|
|
3098
3694
|
// or (for a thin worker, no `store`) a `ProxyRunGateway` over `transport` when given, else a
|
|
3099
3695
|
// gateway whose every method rejects with a clear tenant error.
|
|
3100
3696
|
{
|
|
3101
|
-
provide:
|
|
3697
|
+
provide: import_nestjs_durable_core19.RunGateway,
|
|
3102
3698
|
useFactory: /* @__PURE__ */ __name((options, store, engine) => {
|
|
3103
3699
|
if (options.store !== void 0) {
|
|
3104
3700
|
if (!store) {
|
|
@@ -3109,9 +3705,9 @@ var DurableModule = class _DurableModule {
|
|
|
3109
3705
|
return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, options.tenantToken) : unavailableRunGateway();
|
|
3110
3706
|
}, "useFactory"),
|
|
3111
3707
|
inject: [
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3708
|
+
import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
|
|
3709
|
+
import_nestjs_durable_core19.STATE_STORE_CANONICAL,
|
|
3710
|
+
import_nestjs_durable_core19.WorkflowEngine
|
|
3115
3711
|
]
|
|
3116
3712
|
},
|
|
3117
3713
|
RunGatewayBootstrap,
|
|
@@ -3125,25 +3721,26 @@ var DurableModule = class _DurableModule {
|
|
|
3125
3721
|
exports: [
|
|
3126
3722
|
WorkflowService,
|
|
3127
3723
|
EntityService,
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3724
|
+
import_nestjs_durable_core19.WorkflowEngine,
|
|
3725
|
+
import_nestjs_durable_core19.STATE_STORE,
|
|
3726
|
+
import_nestjs_durable_core19.STATE_STORE_CANONICAL,
|
|
3727
|
+
import_nestjs_durable_core19.TRANSPORT,
|
|
3728
|
+
import_nestjs_durable_core19.TRANSPORT_CANONICAL,
|
|
3729
|
+
import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
|
|
3730
|
+
import_nestjs_durable_core19.RunGateway
|
|
3135
3731
|
]
|
|
3136
3732
|
};
|
|
3137
3733
|
}
|
|
3138
3734
|
};
|
|
3139
|
-
DurableModule =
|
|
3140
|
-
(0,
|
|
3735
|
+
DurableModule = _ts_decorate13([
|
|
3736
|
+
(0, import_common13.Module)({})
|
|
3141
3737
|
], DurableModule);
|
|
3142
3738
|
|
|
3143
3739
|
// src/index.ts
|
|
3144
|
-
var
|
|
3740
|
+
var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
|
|
3145
3741
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3146
3742
|
0 && (module.exports = {
|
|
3743
|
+
BAD_RUN_REQUEST,
|
|
3147
3744
|
CONTEXT_ACCESSOR,
|
|
3148
3745
|
DEAD_LETTER_METADATA,
|
|
3149
3746
|
DURABLE_STEP_METADATA,
|
|
@@ -3162,12 +3759,16 @@ var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
|
3162
3759
|
IN_APP_WORKER_RUNNERS,
|
|
3163
3760
|
IN_APP_WORKER_RUNTIME,
|
|
3164
3761
|
InAppWorkerBootstrap,
|
|
3762
|
+
LIFECYCLE_PENDING_TAG,
|
|
3165
3763
|
ON_ERROR_METADATA,
|
|
3764
|
+
ON_EVENT_BATCH_METADATA,
|
|
3166
3765
|
ON_EVENT_METADATA,
|
|
3167
3766
|
On,
|
|
3168
3767
|
OnDurableEvent,
|
|
3169
3768
|
OnError,
|
|
3170
3769
|
OnEvent,
|
|
3770
|
+
OnWorkflowCompleted,
|
|
3771
|
+
OnWorkflowFailed,
|
|
3171
3772
|
ProxyRunGateway,
|
|
3172
3773
|
RUN_GATEWAY,
|
|
3173
3774
|
RUN_REDIS_WORKER,
|
|
@@ -3178,6 +3779,7 @@ var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
|
3178
3779
|
Step,
|
|
3179
3780
|
StepInterceptor,
|
|
3180
3781
|
StoreRunGateway,
|
|
3782
|
+
TENANT_REPUBLISH_MAX_LIMIT,
|
|
3181
3783
|
TenantEventRepublisher,
|
|
3182
3784
|
ThinStepRegistrar,
|
|
3183
3785
|
ThinWorkerBootstrap,
|
|
@@ -3189,6 +3791,7 @@ var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
|
3189
3791
|
WorkflowService,
|
|
3190
3792
|
attributesOf,
|
|
3191
3793
|
entityConfigFor,
|
|
3794
|
+
eventBatchOf,
|
|
3192
3795
|
getDurableStepMeta,
|
|
3193
3796
|
getEntityMeta,
|
|
3194
3797
|
getOnEvents,
|
|
@@ -3199,14 +3802,19 @@ var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
|
3199
3802
|
isDrivingOperator,
|
|
3200
3803
|
isOperatorRole,
|
|
3201
3804
|
isStepInterceptor,
|
|
3805
|
+
lifecycleRunId,
|
|
3806
|
+
lifecycleSourceOf,
|
|
3202
3807
|
onErrorCodesOf,
|
|
3203
3808
|
prevCronFireMs,
|
|
3204
3809
|
readSearchAttributes,
|
|
3810
|
+
runCompletedEvent,
|
|
3811
|
+
runFailedEvent,
|
|
3205
3812
|
runSchedules,
|
|
3206
3813
|
scheduleRunIdAt,
|
|
3207
3814
|
scheduledRunId,
|
|
3208
3815
|
signTenantToken,
|
|
3209
3816
|
thinWorkerProviders,
|
|
3817
|
+
triggeredRunsOf,
|
|
3210
3818
|
unavailableRunGateway
|
|
3211
3819
|
});
|
|
3212
3820
|
//# sourceMappingURL=index.cjs.map
|