@dudousxd/nestjs-durable 0.63.0 → 0.65.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 +820 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +213 -14
- package/dist/index.d.ts +213 -14
- package/dist/index.js +684 -223
- package/dist/index.js.map +1 -1
- package/dist/migrate-from-nestjs-workflows.cjs +8 -2
- package/dist/migrate-from-nestjs-workflows.cjs.map +1 -1
- package/dist/migrate-from-nestjs-workflows.js +8 -2
- package/dist/migrate-from-nestjs-workflows.js.map +1 -1
- package/package.json +4 -4
- package/skills/durable-setup/SKILL.md +5 -1
- package/skills/durable-signals-and-timers/SKILL.md +12 -3
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
DURABLE_WORKER_RUNNERS: () => DURABLE_WORKER_RUNNERS,
|
|
39
39
|
DURABLE_WORKER_RUNTIME: () => DURABLE_WORKER_RUNTIME,
|
|
40
40
|
DeadLetter: () => DeadLetter,
|
|
41
|
-
DuplicateDurableCopyError: () =>
|
|
41
|
+
DuplicateDurableCopyError: () => import_nestjs_durable_core22.DuplicateDurableCopyError,
|
|
42
42
|
DurableModule: () => DurableModule,
|
|
43
43
|
DurableStartClient: () => DurableStartClient,
|
|
44
44
|
ENTITY_METADATA: () => ENTITY_METADATA,
|
|
@@ -51,7 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
IN_APP_WORKER_RUNNERS: () => IN_APP_WORKER_RUNNERS,
|
|
52
52
|
IN_APP_WORKER_RUNTIME: () => IN_APP_WORKER_RUNTIME,
|
|
53
53
|
InAppWorkerBootstrap: () => InAppWorkerBootstrap,
|
|
54
|
-
LIFECYCLE_PENDING_TAG: () =>
|
|
54
|
+
LIFECYCLE_PENDING_TAG: () => import_nestjs_durable_core22.LIFECYCLE_PENDING_TAG,
|
|
55
55
|
ON_ERROR_METADATA: () => ON_ERROR_METADATA,
|
|
56
56
|
ON_EVENT_BATCH_METADATA: () => ON_EVENT_BATCH_METADATA,
|
|
57
57
|
ON_EVENT_METADATA: () => ON_EVENT_METADATA,
|
|
@@ -63,13 +63,14 @@ __export(src_exports, {
|
|
|
63
63
|
ProxyRunGateway: () => ProxyRunGateway,
|
|
64
64
|
RUN_GATEWAY: () => RUN_GATEWAY,
|
|
65
65
|
RUN_REDIS_WORKER: () => RUN_REDIS_WORKER,
|
|
66
|
-
RunGateway: () =>
|
|
66
|
+
RunGateway: () => import_nestjs_durable_core22.RunGateway,
|
|
67
67
|
RunGatewayError: () => RunGatewayError,
|
|
68
68
|
RunRequestResponder: () => RunRequestResponder,
|
|
69
69
|
STEP_INTERCEPTOR_METADATA: () => STEP_INTERCEPTOR_METADATA,
|
|
70
70
|
Step: () => Step,
|
|
71
71
|
StepInterceptor: () => StepInterceptor,
|
|
72
72
|
StoreRunGateway: () => StoreRunGateway,
|
|
73
|
+
TENANT_AUTH: () => TENANT_AUTH,
|
|
73
74
|
TENANT_REPUBLISH_MAX_LIMIT: () => TENANT_REPUBLISH_MAX_LIMIT,
|
|
74
75
|
TenantEventRepublisher: () => TenantEventRepublisher,
|
|
75
76
|
ThinStepRegistrar: () => ThinStepRegistrar,
|
|
@@ -78,7 +79,7 @@ __export(src_exports, {
|
|
|
78
79
|
UNSUPPORTED_RUN_REQUEST: () => UNSUPPORTED_RUN_REQUEST,
|
|
79
80
|
WORKFLOW_METADATA: () => WORKFLOW_METADATA,
|
|
80
81
|
Workflow: () => Workflow,
|
|
81
|
-
WorkflowEngine: () =>
|
|
82
|
+
WorkflowEngine: () => import_nestjs_durable_core22.WorkflowEngine,
|
|
82
83
|
WorkflowService: () => WorkflowService,
|
|
83
84
|
attributesOf: () => attributesOf,
|
|
84
85
|
entityConfigFor: () => entityConfigFor,
|
|
@@ -88,25 +89,26 @@ __export(src_exports, {
|
|
|
88
89
|
getEntityMeta: () => getEntityMeta,
|
|
89
90
|
getOnEvents: () => getOnEvents,
|
|
90
91
|
getWorkflowMeta: () => getWorkflowMeta,
|
|
91
|
-
hmacTenantVerifier: () =>
|
|
92
|
+
hmacTenantVerifier: () => import_nestjs_durable_core22.hmacTenantVerifier,
|
|
92
93
|
inAppWorkerProviders: () => inAppWorkerProviders,
|
|
93
94
|
isDeadLetterHandler: () => isDeadLetterHandler,
|
|
94
95
|
isDrivingOperator: () => isDrivingOperator,
|
|
95
96
|
isOperatorRole: () => isOperatorRole,
|
|
96
97
|
isStepInterceptor: () => isStepInterceptor,
|
|
97
|
-
lifecycleRunId: () =>
|
|
98
|
-
lifecycleSourceOf: () =>
|
|
98
|
+
lifecycleRunId: () => import_nestjs_durable_core22.lifecycleRunId,
|
|
99
|
+
lifecycleSourceOf: () => import_nestjs_durable_core22.lifecycleSourceOf,
|
|
99
100
|
onErrorCodesOf: () => onErrorCodesOf,
|
|
100
|
-
prevCronFireMs: () =>
|
|
101
|
-
readSearchAttributes: () =>
|
|
102
|
-
runCompletedEvent: () =>
|
|
103
|
-
runFailedEvent: () =>
|
|
104
|
-
runSchedules: () =>
|
|
105
|
-
scheduleRunIdAt: () =>
|
|
106
|
-
scheduledRunId: () =>
|
|
107
|
-
signTenantToken: () =>
|
|
101
|
+
prevCronFireMs: () => import_nestjs_durable_core22.prevCronFireMs,
|
|
102
|
+
readSearchAttributes: () => import_nestjs_durable_core22.readSearchAttributes,
|
|
103
|
+
runCompletedEvent: () => import_nestjs_durable_core22.runCompletedEvent,
|
|
104
|
+
runFailedEvent: () => import_nestjs_durable_core22.runFailedEvent,
|
|
105
|
+
runSchedules: () => import_nestjs_durable_core22.runSchedules,
|
|
106
|
+
scheduleRunIdAt: () => import_nestjs_durable_core22.scheduleRunIdAt,
|
|
107
|
+
scheduledRunId: () => import_nestjs_durable_core22.scheduledRunId,
|
|
108
|
+
signTenantToken: () => import_nestjs_durable_core22.signTenantToken,
|
|
109
|
+
tenantScheduleAnnouncement: () => tenantScheduleAnnouncement,
|
|
108
110
|
thinWorkerProviders: () => thinWorkerProviders,
|
|
109
|
-
triggeredRunsOf: () =>
|
|
111
|
+
triggeredRunsOf: () => import_nestjs_durable_core22.triggeredRunsOf,
|
|
110
112
|
unavailableRunGateway: () => unavailableRunGateway
|
|
111
113
|
});
|
|
112
114
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -809,95 +811,216 @@ var DurableStartClient = class {
|
|
|
809
811
|
options;
|
|
810
812
|
deps;
|
|
811
813
|
accessor;
|
|
814
|
+
requests;
|
|
812
815
|
tenant;
|
|
813
816
|
tenantToken;
|
|
814
|
-
|
|
817
|
+
policies = /* @__PURE__ */ new Map();
|
|
818
|
+
warnedCoalescing = /* @__PURE__ */ new Set();
|
|
819
|
+
constructor(options, deps, accessor, requests) {
|
|
815
820
|
this.options = options;
|
|
816
821
|
this.deps = deps;
|
|
817
822
|
this.accessor = accessor;
|
|
823
|
+
this.requests = requests;
|
|
818
824
|
this.tenant = options.partition ?? "default";
|
|
819
825
|
this.tenantToken = resolveTenantTokenSource(options.tenantToken);
|
|
820
826
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
827
|
+
/**
|
|
828
|
+
* Apply `policy` to every start of `workflow` from this process (see
|
|
829
|
+
* {@link TenantWorkflowStartPolicy}). Called by `ThinWorkflowRegistrar` at boot.
|
|
830
|
+
*/
|
|
831
|
+
declareWorkflow(workflow, policy) {
|
|
832
|
+
this.policies.set(workflow, policy);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
836
|
+
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
837
|
+
* workflow's.
|
|
838
|
+
*/
|
|
839
|
+
async applyPolicy(workflow, input, opts) {
|
|
840
|
+
const policy = this.policies.get(workflow);
|
|
841
|
+
if (!policy) return opts?.concurrency !== void 0 ? {
|
|
842
|
+
concurrency: opts.concurrency
|
|
843
|
+
} : {};
|
|
844
|
+
await policy.validateInput?.(input);
|
|
845
|
+
const concurrency = await (0, import_nestjs_durable_core3.resolveConcurrency)(opts?.concurrency, policy.concurrency, input);
|
|
846
|
+
const singleton = policy.singleton ? {
|
|
847
|
+
key: policy.singleton.key(input),
|
|
848
|
+
...policy.singleton.limit !== void 0 ? {
|
|
849
|
+
limit: policy.singleton.limit
|
|
850
|
+
} : {},
|
|
851
|
+
...policy.singleton.maxQueueDepth !== void 0 ? {
|
|
852
|
+
maxQueueDepth: policy.singleton.maxQueueDepth
|
|
853
|
+
} : {}
|
|
854
|
+
} : void 0;
|
|
855
|
+
return {
|
|
856
|
+
...singleton ? {
|
|
857
|
+
singleton
|
|
858
|
+
} : {},
|
|
859
|
+
...concurrency ? {
|
|
860
|
+
concurrency
|
|
861
|
+
} : {}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
/** The wire `tenant`: the signed token when configured, else the partition. */
|
|
865
|
+
async wireTenant() {
|
|
866
|
+
return this.tenantToken !== void 0 ? await (0, import_nestjs_durable_core3.resolveTenantToken)(this.tenantToken) : this.tenant;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* The customer tenant a start claims: an explicit `tenantId` (`null` = none), else the request's
|
|
870
|
+
* tenant when tenancy is on.
|
|
871
|
+
*/
|
|
872
|
+
claimedTenant(opts) {
|
|
873
|
+
return opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
|
|
824
874
|
id: opts.tenantId,
|
|
825
|
-
|
|
875
|
+
...opts.tenantKind !== void 0 ? {
|
|
876
|
+
kind: opts.tenantKind
|
|
877
|
+
} : {}
|
|
826
878
|
} : currentTenant(this.options.tenancy, this.accessor);
|
|
879
|
+
}
|
|
880
|
+
async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
|
|
881
|
+
const message = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
|
|
827
882
|
await startRun(this.options.connection, {
|
|
828
883
|
// The signed token (when configured) rides in the `tenant` field, as on every run request; an
|
|
829
884
|
// operator with `verifyTenant` derives the run's namespace from it.
|
|
830
|
-
tenant:
|
|
831
|
-
|
|
832
|
-
input,
|
|
833
|
-
runId,
|
|
885
|
+
tenant: await this.wireTenant(),
|
|
886
|
+
...message,
|
|
834
887
|
// Option B: DO NOT pass `namespace` — the start-run queue stays the shared
|
|
835
888
|
// `durable-start-run` the operator consumes; tenant rides only as message data.
|
|
836
889
|
...this.options.prefix !== void 0 ? {
|
|
837
890
|
prefix: this.options.prefix
|
|
838
891
|
} : {},
|
|
892
|
+
...this.deps !== void 0 ? {
|
|
893
|
+
deps: this.deps
|
|
894
|
+
} : {}
|
|
895
|
+
});
|
|
896
|
+
const startAtMs = message.startAt;
|
|
897
|
+
return {
|
|
898
|
+
runId,
|
|
899
|
+
status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* The start-run a start of `name` sends (everything but the wire `tenant`): the start options the
|
|
904
|
+
* control plane applies (version pin, priority, delayed start, quota), the singleton key and the
|
|
905
|
+
* customer tenant this run claims. Applies the workflow's declared policy first, so a rejected
|
|
906
|
+
* input throws before anything is published, as `engine.start` does.
|
|
907
|
+
*/
|
|
908
|
+
async startMessage(name, input, runId, opts) {
|
|
909
|
+
const tenant = this.claimedTenant(opts);
|
|
910
|
+
const policy = await this.applyPolicy(name, input, opts);
|
|
911
|
+
const startAt = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
|
|
912
|
+
return {
|
|
913
|
+
workflow: name,
|
|
914
|
+
input,
|
|
915
|
+
runId,
|
|
839
916
|
...opts?.tags !== void 0 ? {
|
|
840
917
|
tags: opts.tags
|
|
841
918
|
} : {},
|
|
842
919
|
...opts?.searchAttributes !== void 0 ? {
|
|
843
920
|
searchAttributes: opts.searchAttributes
|
|
844
921
|
} : {},
|
|
845
|
-
// The start options the control plane applies (version pin, priority, delayed start, quota).
|
|
846
922
|
...opts?.version !== void 0 ? {
|
|
847
923
|
version: opts.version
|
|
848
924
|
} : {},
|
|
849
925
|
...opts?.priority !== void 0 ? {
|
|
850
926
|
priority: opts.priority
|
|
851
927
|
} : {},
|
|
852
|
-
...
|
|
853
|
-
startAt
|
|
928
|
+
...startAt !== void 0 ? {
|
|
929
|
+
startAt
|
|
930
|
+
} : {},
|
|
931
|
+
...policy.concurrency !== void 0 ? {
|
|
932
|
+
concurrency: policy.concurrency
|
|
854
933
|
} : {},
|
|
855
|
-
...
|
|
856
|
-
|
|
934
|
+
...policy.singleton !== void 0 ? {
|
|
935
|
+
singleton: policy.singleton
|
|
857
936
|
} : {},
|
|
858
937
|
...tenant ? {
|
|
859
938
|
tenantId: tenant.id,
|
|
860
939
|
...tenant.kind !== void 0 ? {
|
|
861
940
|
tenantKind: tenant.kind
|
|
862
941
|
} : {}
|
|
863
|
-
} : {},
|
|
864
|
-
...this.deps !== void 0 ? {
|
|
865
|
-
deps: this.deps
|
|
866
942
|
} : {}
|
|
867
|
-
}
|
|
868
|
-
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
/** The control plane's run requests, or a clear error naming what is missing. */
|
|
946
|
+
runRequests(method) {
|
|
947
|
+
const requests = this.requests?.();
|
|
948
|
+
if (!requests) {
|
|
949
|
+
throw new Error(`${method}() on a tenant is sent to the control plane as a run request, which needs \`transport\` on DurableModule.forRoot (the tenant's BullMQTransport).`);
|
|
950
|
+
}
|
|
951
|
+
return requests;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Signal the run of this tenant's partition waiting on `token`, through the control plane.
|
|
955
|
+
* Resolves the resumed run, or null when no run of this partition waits on it: unlike
|
|
956
|
+
* `engine.signal` on a control plane, a tenant's signal is NOT buffered for a wait opened later
|
|
957
|
+
* (another partition's run could open it). Use `signalWithStart` to signal a run that may not wait
|
|
958
|
+
* yet. `opts.id` deduplicates like `engine.signal`.
|
|
959
|
+
*/
|
|
960
|
+
async signal(token, payload, opts) {
|
|
961
|
+
return this.runRequests("signal").signal(token, payload, opts);
|
|
962
|
+
}
|
|
963
|
+
async signalWithStart(workflow, input, runId, signal, opts) {
|
|
964
|
+
const requests = this.runRequests("signalWithStart");
|
|
965
|
+
const start = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
|
|
966
|
+
const result = await requests.signalWithStart(start, signal);
|
|
869
967
|
return {
|
|
870
|
-
runId
|
|
871
|
-
status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
|
|
968
|
+
runId: result.runId
|
|
872
969
|
};
|
|
873
970
|
}
|
|
971
|
+
/**
|
|
972
|
+
* Publish event `name` from this tenant. Starts this app's own `onEvent` subscribers (each one
|
|
973
|
+
* whose `where` accepts the payload, with its `input` mapping) as runs of this partition, by the
|
|
974
|
+
* start path ({@link start}, run id `evt:<id>:<workflow>`), and has the control plane resume the
|
|
975
|
+
* runs of this partition waiting on it (`ctx.waitForEvent`). Resolves how many runs it started or
|
|
976
|
+
* resumed; a subscriber that throws is warned about and skipped. Unlike a control plane's
|
|
977
|
+
* `publishEvent`, an event nobody received is not buffered (there is no `buffer` option), and
|
|
978
|
+
* a subscriber's `debounce`/`batch` is not applied (it starts once per event, with a warning).
|
|
979
|
+
*/
|
|
980
|
+
async publishEvent(name, payload, opts) {
|
|
981
|
+
const requests = this.runRequests("publishEvent");
|
|
982
|
+
const eventId = opts?.id ?? globalThis.crypto.randomUUID();
|
|
983
|
+
let started = 0;
|
|
984
|
+
for (const [workflow, policy] of this.policies) {
|
|
985
|
+
try {
|
|
986
|
+
const subscriptions = (policy.onEvent ?? []).map(import_nestjs_durable_core3.toEventSubscription).filter((sub) => sub.event === name);
|
|
987
|
+
const { accepted, errors } = (0, import_nestjs_durable_core3.acceptingSubscription)(subscriptions, payload);
|
|
988
|
+
if (!accepted) {
|
|
989
|
+
if (errors.length > 0) throw errors[0];
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
if (policy.coalesces && !this.warnedCoalescing.has(workflow)) {
|
|
993
|
+
this.warnedCoalescing.add(workflow);
|
|
994
|
+
console.warn(`[nestjs-durable] ${workflow} debounces/batches its events, which a tenant's publishEvent does not apply: it starts once per event.`);
|
|
995
|
+
}
|
|
996
|
+
const input = accepted.input ? accepted.input(payload) : payload;
|
|
997
|
+
await this.start(workflow, input, `evt:${eventId}:${workflow}`);
|
|
998
|
+
started += 1;
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
console.warn(`[nestjs-durable] event ${name}: subscriber ${workflow} not started:`, error);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
const resumed = await requests.publishEvent(name, payload, {
|
|
1004
|
+
id: eventId
|
|
1005
|
+
});
|
|
1006
|
+
return started + resumed;
|
|
1007
|
+
}
|
|
874
1008
|
cancel(_runId) {
|
|
875
1009
|
return tenantUnsupported("cancel");
|
|
876
1010
|
}
|
|
877
1011
|
deleteRun(_runId) {
|
|
878
1012
|
return tenantUnsupported("deleteRun");
|
|
879
1013
|
}
|
|
880
|
-
// — everything below rejects: a tenant worker holds no store/driver
|
|
881
|
-
//
|
|
882
|
-
//
|
|
883
|
-
//
|
|
884
|
-
// of a cryptic `this.engine.X is not a function` — the facade is honest about what it cannot do.
|
|
885
|
-
// Params mirror the WorkflowEngine surface being faced; every method rejects without reading them.
|
|
1014
|
+
// — everything below rejects: a tenant worker holds no store/driver. —
|
|
1015
|
+
// `resume`/`waitForRun` need the store or driver a tenant does not have. They exist so a mistaken
|
|
1016
|
+
// call fails with a CLEAR, named tenant error instead of a cryptic `this.engine.X is not a
|
|
1017
|
+
// function`. Params mirror the WorkflowEngine surface; every method rejects without reading them.
|
|
886
1018
|
resume(_runId) {
|
|
887
1019
|
return tenantUnsupported("resume");
|
|
888
1020
|
}
|
|
889
1021
|
waitForRun(_runId, _opts) {
|
|
890
1022
|
return tenantUnsupported("waitForRun");
|
|
891
1023
|
}
|
|
892
|
-
signal(_token, _payload) {
|
|
893
|
-
return tenantUnsupported("signal");
|
|
894
|
-
}
|
|
895
|
-
signalWithStart(_workflow, _input, _runId, _signal, _opts) {
|
|
896
|
-
return tenantUnsupported("signalWithStart");
|
|
897
|
-
}
|
|
898
|
-
publishEvent(_name, _payload, _opts) {
|
|
899
|
-
return tenantUnsupported("publishEvent");
|
|
900
|
-
}
|
|
901
1024
|
};
|
|
902
1025
|
DurableStartClient = _ts_decorate([
|
|
903
1026
|
(0, import_common.Injectable)(),
|
|
@@ -905,7 +1028,8 @@ DurableStartClient = _ts_decorate([
|
|
|
905
1028
|
_ts_metadata("design:paramtypes", [
|
|
906
1029
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
907
1030
|
typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
|
|
908
|
-
typeof ContextAccessor === "undefined" ? Object : ContextAccessor
|
|
1031
|
+
typeof ContextAccessor === "undefined" ? Object : ContextAccessor,
|
|
1032
|
+
Function
|
|
909
1033
|
])
|
|
910
1034
|
], DurableStartClient);
|
|
911
1035
|
function tenantUnsupported(method) {
|
|
@@ -914,8 +1038,8 @@ function tenantUnsupported(method) {
|
|
|
914
1038
|
__name(tenantUnsupported, "tenantUnsupported");
|
|
915
1039
|
|
|
916
1040
|
// src/durable-worker.module.ts
|
|
917
|
-
var
|
|
918
|
-
var
|
|
1041
|
+
var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
|
|
1042
|
+
var import_common3 = require("@nestjs/common");
|
|
919
1043
|
var import_core = require("@nestjs/core");
|
|
920
1044
|
|
|
921
1045
|
// src/schema-parse.ts
|
|
@@ -1026,8 +1150,99 @@ function scanSteps(discovery, scanner, register) {
|
|
|
1026
1150
|
}
|
|
1027
1151
|
__name(scanSteps, "scanSteps");
|
|
1028
1152
|
|
|
1029
|
-
// src/
|
|
1153
|
+
// src/entity.ts
|
|
1030
1154
|
var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
|
|
1155
|
+
var import_common2 = require("@nestjs/common");
|
|
1156
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
1157
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1158
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1159
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1160
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1161
|
+
} else {
|
|
1162
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1163
|
+
if (d = decorators[i]) {
|
|
1164
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1169
|
+
}
|
|
1170
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1171
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
1172
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1173
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
1177
|
+
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
1178
|
+
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
1179
|
+
function Entity(options) {
|
|
1180
|
+
return (target) => {
|
|
1181
|
+
Reflect.defineMetadata(ENTITY_METADATA, options, target);
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
__name(Entity, "Entity");
|
|
1185
|
+
function On(op) {
|
|
1186
|
+
return (target, propertyKey) => {
|
|
1187
|
+
const ctor = target.constructor;
|
|
1188
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1189
|
+
ops.set(op, propertyKey);
|
|
1190
|
+
Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
__name(On, "On");
|
|
1194
|
+
function getEntityMeta(target) {
|
|
1195
|
+
return Reflect.getMetadata(ENTITY_METADATA, target);
|
|
1196
|
+
}
|
|
1197
|
+
__name(getEntityMeta, "getEntityMeta");
|
|
1198
|
+
function entityConfigFor(ctor) {
|
|
1199
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1200
|
+
const Cls = ctor;
|
|
1201
|
+
const handlers = {};
|
|
1202
|
+
for (const [op, method] of ops) {
|
|
1203
|
+
handlers[op] = (state, arg) => {
|
|
1204
|
+
Object.setPrototypeOf(state, Cls.prototype);
|
|
1205
|
+
const fn = state[method];
|
|
1206
|
+
if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
|
|
1207
|
+
return fn.call(state, arg);
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
return {
|
|
1211
|
+
initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
|
|
1212
|
+
handlers
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
__name(entityConfigFor, "entityConfigFor");
|
|
1216
|
+
var EntityService = class {
|
|
1217
|
+
static {
|
|
1218
|
+
__name(this, "EntityService");
|
|
1219
|
+
}
|
|
1220
|
+
engine;
|
|
1221
|
+
constructor(engine) {
|
|
1222
|
+
this.engine = engine;
|
|
1223
|
+
}
|
|
1224
|
+
/** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
|
|
1225
|
+
signal(name, key, op, arg) {
|
|
1226
|
+
return this.engine.signalEntity(name, key, op, arg);
|
|
1227
|
+
}
|
|
1228
|
+
/** Read an entity's current durable state (or undefined if it has none yet). */
|
|
1229
|
+
getState(name, key) {
|
|
1230
|
+
return this.engine.getEntityState(name, key);
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
EntityService = _ts_decorate2([
|
|
1234
|
+
(0, import_common2.Injectable)(),
|
|
1235
|
+
_ts_metadata2("design:type", Function),
|
|
1236
|
+
_ts_metadata2("design:paramtypes", [
|
|
1237
|
+
typeof import_nestjs_durable_core5.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core5.WorkflowEngine
|
|
1238
|
+
])
|
|
1239
|
+
], EntityService);
|
|
1240
|
+
|
|
1241
|
+
// src/runtime-registration.ts
|
|
1242
|
+
var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
|
|
1243
|
+
|
|
1244
|
+
// src/on-error-handlers.ts
|
|
1245
|
+
var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
|
|
1031
1246
|
function onErrorHandlersOf(meta, instance, scanner) {
|
|
1032
1247
|
const handlers = [];
|
|
1033
1248
|
const routes = [];
|
|
@@ -1048,7 +1263,7 @@ function onErrorHandlersOf(meta, instance, scanner) {
|
|
|
1048
1263
|
for (const r of meta.onError ?? []) {
|
|
1049
1264
|
routes.push({
|
|
1050
1265
|
code: r.code === void 0 || typeof r.code === "string" ? r.code : r.code.code,
|
|
1051
|
-
workflow: (0,
|
|
1266
|
+
workflow: (0, import_nestjs_durable_core6.workflowName)(r.workflow)
|
|
1052
1267
|
});
|
|
1053
1268
|
}
|
|
1054
1269
|
return {
|
|
@@ -1077,7 +1292,7 @@ function workflowIo(meta) {
|
|
|
1077
1292
|
__name(workflowIo, "workflowIo");
|
|
1078
1293
|
|
|
1079
1294
|
// src/runtime-registration.ts
|
|
1080
|
-
function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
1295
|
+
function registerOnRuntime(runtime, scanner, meta, instance, origin, deadLetter) {
|
|
1081
1296
|
const { handlers, routes } = onErrorHandlersOf(meta, instance, scanner);
|
|
1082
1297
|
const announced = {
|
|
1083
1298
|
version: meta.version,
|
|
@@ -1105,14 +1320,61 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
1105
1320
|
} : {},
|
|
1106
1321
|
...subscribes.length > 0 ? {
|
|
1107
1322
|
subscribes
|
|
1323
|
+
} : {},
|
|
1324
|
+
...announcedOptions(meta),
|
|
1325
|
+
...deadLetter !== void 0 ? {
|
|
1326
|
+
deadLetter
|
|
1108
1327
|
} : {}
|
|
1109
1328
|
});
|
|
1110
1329
|
for (const [name, fn] of handlers) runtime.registerWorkflow(name, fn, announced);
|
|
1111
1330
|
}
|
|
1112
1331
|
__name(registerOnRuntime, "registerOnRuntime");
|
|
1332
|
+
function announcedOptions(meta) {
|
|
1333
|
+
const options = {};
|
|
1334
|
+
if (meta.tags !== void 0 && meta.tags.length > 0) options.tags = [
|
|
1335
|
+
...meta.tags
|
|
1336
|
+
];
|
|
1337
|
+
if (meta.executionTimeout !== void 0) {
|
|
1338
|
+
options.executionTimeoutMs = (0, import_nestjs_durable_core7.parseDuration)(meta.executionTimeout);
|
|
1339
|
+
}
|
|
1340
|
+
if (meta.singleton !== void 0) {
|
|
1341
|
+
options.singleton = {
|
|
1342
|
+
...meta.singleton.limit !== void 0 ? {
|
|
1343
|
+
limit: meta.singleton.limit
|
|
1344
|
+
} : {},
|
|
1345
|
+
...meta.singleton.maxQueueDepth !== void 0 ? {
|
|
1346
|
+
maxQueueDepth: meta.singleton.maxQueueDepth
|
|
1347
|
+
} : {}
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
return Object.keys(options).length > 0 ? {
|
|
1351
|
+
options
|
|
1352
|
+
} : {};
|
|
1353
|
+
}
|
|
1354
|
+
__name(announcedOptions, "announcedOptions");
|
|
1355
|
+
|
|
1356
|
+
// src/step-interceptor.ts
|
|
1357
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
1358
|
+
var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
|
|
1359
|
+
function StepInterceptor() {
|
|
1360
|
+
return (target) => {
|
|
1361
|
+
Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
__name(StepInterceptor, "StepInterceptor");
|
|
1365
|
+
function isStepInterceptor(target) {
|
|
1366
|
+
return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
|
|
1367
|
+
}
|
|
1368
|
+
__name(isStepInterceptor, "isStepInterceptor");
|
|
1369
|
+
|
|
1370
|
+
// src/tokens.ts
|
|
1371
|
+
var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
|
|
1372
|
+
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
1373
|
+
var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
|
|
1374
|
+
var RUN_GATEWAY = import_nestjs_durable_core8.RunGateway;
|
|
1113
1375
|
|
|
1114
1376
|
// src/durable-worker.module.ts
|
|
1115
|
-
function
|
|
1377
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1116
1378
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1117
1379
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1118
1380
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1125,19 +1387,29 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
1125
1387
|
}
|
|
1126
1388
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1127
1389
|
}
|
|
1128
|
-
__name(
|
|
1129
|
-
function
|
|
1390
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1391
|
+
function _ts_metadata3(metadataKey, metadataValue) {
|
|
1130
1392
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1131
1393
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1132
1394
|
}
|
|
1133
1395
|
}
|
|
1134
|
-
__name(
|
|
1396
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
1135
1397
|
function _ts_param(paramIndex, decorator) {
|
|
1136
1398
|
return function(target, key) {
|
|
1137
1399
|
decorator(target, key, paramIndex);
|
|
1138
1400
|
};
|
|
1139
1401
|
}
|
|
1140
1402
|
__name(_ts_param, "_ts_param");
|
|
1403
|
+
function deadLetterHandlerOf(instance, scanner) {
|
|
1404
|
+
for (const name of scanner.getAllMethodNames(Object.getPrototypeOf(instance))) {
|
|
1405
|
+
const method = instance[name];
|
|
1406
|
+
if (typeof method === "function" && isDeadLetterHandler(method)) {
|
|
1407
|
+
return (ctx, input) => method.call(instance, ctx, input);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
return void 0;
|
|
1411
|
+
}
|
|
1412
|
+
__name(deadLetterHandlerOf, "deadLetterHandlerOf");
|
|
1141
1413
|
var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
|
|
1142
1414
|
var DURABLE_WORKER_RUNTIME = Symbol("nestjs-durable:worker-runtime");
|
|
1143
1415
|
var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
|
|
@@ -1165,21 +1437,78 @@ var ThinWorkflowRegistrar = class {
|
|
|
1165
1437
|
const runtime = this.runtime;
|
|
1166
1438
|
if (runtime === null || !isPureThinWorker(this.options)) return;
|
|
1167
1439
|
const starter = this.starter;
|
|
1440
|
+
this.assertNoEntities();
|
|
1441
|
+
this.useInterceptors(runtime);
|
|
1442
|
+
const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(this.options.deadLetterWorkflow) : void 0;
|
|
1168
1443
|
scanWorkflows(this.discovery, (meta, instance, origin) => {
|
|
1169
|
-
|
|
1170
|
-
(
|
|
1444
|
+
const inline = deadLetterHandlerOf(instance, this.metadataScanner);
|
|
1445
|
+
if (inline && meta.deadLetterWorkflow) {
|
|
1446
|
+
throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
|
|
1447
|
+
}
|
|
1448
|
+
const deadLetter = inline ? `${meta.name}.dlq` : meta.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(meta.deadLetterWorkflow) : fallback;
|
|
1449
|
+
registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin, deadLetter);
|
|
1450
|
+
if (inline) {
|
|
1451
|
+
runtime.registerWorkflow(`${meta.name}.dlq`, inline, {
|
|
1452
|
+
version: meta.version,
|
|
1453
|
+
...origin !== void 0 ? {
|
|
1454
|
+
origin
|
|
1455
|
+
} : {}
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
const declare = starter.declareWorkflow;
|
|
1459
|
+
if (typeof declare === "function") {
|
|
1460
|
+
const policy = {
|
|
1461
|
+
validateInput: workflowIo(meta).validateAtStart,
|
|
1462
|
+
singleton: meta.singleton,
|
|
1463
|
+
concurrency: meta.concurrency,
|
|
1464
|
+
onEvent: getOnEvents(meta, instance.constructor),
|
|
1465
|
+
coalesces: eventBatchOf(meta, instance.constructor) !== void 0
|
|
1466
|
+
};
|
|
1467
|
+
declare.call(starter, meta.name, policy);
|
|
1468
|
+
}
|
|
1469
|
+
(0, import_nestjs_durable_core9.bindWorkflowClass)(instance.constructor, {
|
|
1171
1470
|
start: /* @__PURE__ */ __name((name, input, runId, opts) => starter.start(name, input, runId, opts), "start")
|
|
1172
1471
|
});
|
|
1173
1472
|
});
|
|
1174
1473
|
}
|
|
1474
|
+
/**
|
|
1475
|
+
* `@Entity` providers are refused on a tenant, at boot: an entity's state is a run on the store
|
|
1476
|
+
* and its `@On` handlers run inside the engine that owns that store (`EntityService` and
|
|
1477
|
+
* `ctx.callEntity`/`signalEntity` read and serialize it there). A tenant has no store and no
|
|
1478
|
+
* engine, so an entity declared here would never run. Declare it on the control plane.
|
|
1479
|
+
*/
|
|
1480
|
+
assertNoEntities() {
|
|
1481
|
+
const entities = this.discovery.getProviders().map((w) => w.instance).filter((i) => !!i && typeof i === "object" && !!getEntityMeta(i.constructor)).map((i) => getEntityMeta(i.constructor)?.name);
|
|
1482
|
+
if (entities.length === 0) return;
|
|
1483
|
+
throw new Error(`@Entity ${entities.join(", ")} cannot be declared on a DurableModule tenant (connection, no store): an entity's state and handlers live in the engine that owns the store. Declare it on the control plane.`);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* `@StepInterceptor()` providers wrap every step this tenant runs (each `ctx.step` its workers
|
|
1487
|
+
* execute), as `engine.use` does on an engine. A `@durable-worker` too old to take interceptors
|
|
1488
|
+
* says so instead of dropping them silently.
|
|
1489
|
+
*/
|
|
1490
|
+
useInterceptors(runtime) {
|
|
1491
|
+
for (const wrapper of this.discovery.getProviders()) {
|
|
1492
|
+
const instance = wrapper.instance;
|
|
1493
|
+
if (!instance || typeof instance !== "object" || !isStepInterceptor(instance.constructor)) {
|
|
1494
|
+
continue;
|
|
1495
|
+
}
|
|
1496
|
+
const interceptor = instance;
|
|
1497
|
+
if (typeof runtime.use !== "function") {
|
|
1498
|
+
console.warn(`[nestjs-durable] @StepInterceptor ${instance.constructor.name} is not applied: this @dudousxd/durable-worker predates step interceptors on a tenant; upgrade it.`);
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1501
|
+
runtime.use((invocation, next) => interceptor.intercept(invocation, next));
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1175
1504
|
};
|
|
1176
|
-
ThinWorkflowRegistrar =
|
|
1177
|
-
(0,
|
|
1178
|
-
_ts_param(2, (0,
|
|
1179
|
-
_ts_param(3, (0,
|
|
1180
|
-
_ts_param(4, (0,
|
|
1181
|
-
|
|
1182
|
-
|
|
1505
|
+
ThinWorkflowRegistrar = _ts_decorate3([
|
|
1506
|
+
(0, import_common3.Injectable)(),
|
|
1507
|
+
_ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1508
|
+
_ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1509
|
+
_ts_param(4, (0, import_common3.Inject)(import_nestjs_durable_core9.WorkflowEngine)),
|
|
1510
|
+
_ts_metadata3("design:type", Function),
|
|
1511
|
+
_ts_metadata3("design:paramtypes", [
|
|
1183
1512
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1184
1513
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1185
1514
|
Object,
|
|
@@ -1207,12 +1536,12 @@ var ThinStepRegistrar = class {
|
|
|
1207
1536
|
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => runtime.registerStep(meta.name, handler));
|
|
1208
1537
|
}
|
|
1209
1538
|
};
|
|
1210
|
-
ThinStepRegistrar =
|
|
1211
|
-
(0,
|
|
1212
|
-
_ts_param(2, (0,
|
|
1213
|
-
_ts_param(3, (0,
|
|
1214
|
-
|
|
1215
|
-
|
|
1539
|
+
ThinStepRegistrar = _ts_decorate3([
|
|
1540
|
+
(0, import_common3.Injectable)(),
|
|
1541
|
+
_ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1542
|
+
_ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1543
|
+
_ts_metadata3("design:type", Function),
|
|
1544
|
+
_ts_metadata3("design:paramtypes", [
|
|
1216
1545
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1217
1546
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1218
1547
|
Object,
|
|
@@ -1227,18 +1556,25 @@ var ThinWorkerBootstrap = class {
|
|
|
1227
1556
|
options;
|
|
1228
1557
|
runRedisWorker;
|
|
1229
1558
|
runnersSink;
|
|
1559
|
+
auth;
|
|
1230
1560
|
runners = [];
|
|
1231
|
-
constructor(runtime, options, runRedisWorker2, runnersSink) {
|
|
1561
|
+
constructor(runtime, options, runRedisWorker2, runnersSink, auth) {
|
|
1232
1562
|
this.runtime = runtime;
|
|
1233
1563
|
this.options = options;
|
|
1234
1564
|
this.runRedisWorker = runRedisWorker2;
|
|
1235
1565
|
this.runnersSink = runnersSink;
|
|
1566
|
+
this.auth = auth;
|
|
1236
1567
|
}
|
|
1237
1568
|
async onApplicationBootstrap() {
|
|
1238
1569
|
const options = this.options;
|
|
1239
1570
|
const runtime = this.runtime;
|
|
1240
1571
|
if (runtime === null || !isPureThinWorker(options) || options.connection === void 0) return;
|
|
1241
|
-
if (options.consumers === false)
|
|
1572
|
+
if (options.consumers === false) {
|
|
1573
|
+
if ((options.schedules?.length ?? 0) > 0) {
|
|
1574
|
+
console.warn("[nestjs-durable] `schedules` on a tenant with `consumers: false` are not announced: a tenant announces its schedules on its worker descriptor, so declare them on the processes that run its workers.");
|
|
1575
|
+
}
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1242
1578
|
const handle = await this.runRedisWorker({
|
|
1243
1579
|
runtime,
|
|
1244
1580
|
connection: options.connection,
|
|
@@ -1253,7 +1589,10 @@ var ThinWorkerBootstrap = class {
|
|
|
1253
1589
|
} : {},
|
|
1254
1590
|
...options.concurrency !== void 0 ? {
|
|
1255
1591
|
concurrency: options.concurrency
|
|
1256
|
-
} : {}
|
|
1592
|
+
} : {},
|
|
1593
|
+
// Announce the app's schedules (an empty list too) so the control plane adopts, updates and
|
|
1594
|
+
// withdraws them: a tenant has no store to fire them from.
|
|
1595
|
+
...await tenantScheduleAnnouncement(options, this.auth.tenantToken)
|
|
1257
1596
|
});
|
|
1258
1597
|
this.runners.push(handle);
|
|
1259
1598
|
this.runnersSink.push(handle);
|
|
@@ -1262,20 +1601,65 @@ var ThinWorkerBootstrap = class {
|
|
|
1262
1601
|
await Promise.allSettled(this.runners.map((h) => h.close()));
|
|
1263
1602
|
}
|
|
1264
1603
|
};
|
|
1265
|
-
ThinWorkerBootstrap =
|
|
1266
|
-
(0,
|
|
1267
|
-
_ts_param(0, (0,
|
|
1268
|
-
_ts_param(1, (0,
|
|
1269
|
-
_ts_param(2, (0,
|
|
1270
|
-
_ts_param(3, (0,
|
|
1271
|
-
|
|
1272
|
-
|
|
1604
|
+
ThinWorkerBootstrap = _ts_decorate3([
|
|
1605
|
+
(0, import_common3.Injectable)(),
|
|
1606
|
+
_ts_param(0, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1607
|
+
_ts_param(1, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1608
|
+
_ts_param(2, (0, import_common3.Inject)(RUN_REDIS_WORKER)),
|
|
1609
|
+
_ts_param(3, (0, import_common3.Inject)(DURABLE_WORKER_RUNNERS)),
|
|
1610
|
+
_ts_param(4, (0, import_common3.Inject)(TENANT_AUTH)),
|
|
1611
|
+
_ts_metadata3("design:type", Function),
|
|
1612
|
+
_ts_metadata3("design:paramtypes", [
|
|
1273
1613
|
Object,
|
|
1274
1614
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
1275
1615
|
typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
|
|
1276
|
-
Array
|
|
1616
|
+
Array,
|
|
1617
|
+
typeof ResolvedTenantAuth === "undefined" ? Object : ResolvedTenantAuth
|
|
1277
1618
|
])
|
|
1278
1619
|
], ThinWorkerBootstrap);
|
|
1620
|
+
async function tenantScheduleAnnouncement(options, tenantToken) {
|
|
1621
|
+
let tenant;
|
|
1622
|
+
try {
|
|
1623
|
+
tenant = tenantToken !== void 0 ? await (0, import_nestjs_durable_core9.resolveTenantToken)(tenantToken) : options.partition ?? "default";
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
console.warn(`[nestjs-durable] this worker announces no schedules: its tenantToken failed (${error instanceof Error ? error.message : String(error)})`);
|
|
1626
|
+
return {};
|
|
1627
|
+
}
|
|
1628
|
+
return {
|
|
1629
|
+
schedules: {
|
|
1630
|
+
tenant,
|
|
1631
|
+
items: (options.schedules ?? []).map(announcedSchedule)
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
__name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
|
|
1636
|
+
function announcedSchedule(s) {
|
|
1637
|
+
const item = {
|
|
1638
|
+
key: s.key,
|
|
1639
|
+
workflow: (0, import_nestjs_durable_core9.workflowName)(s.workflow)
|
|
1640
|
+
};
|
|
1641
|
+
if (s.input !== void 0) item.input = s.input;
|
|
1642
|
+
if (s.everyMs !== void 0) item.everyMs = s.everyMs;
|
|
1643
|
+
if (s.cron !== void 0) item.cron = s.cron;
|
|
1644
|
+
if (s.timezone !== void 0) item.timezone = s.timezone;
|
|
1645
|
+
if (s.paused === true) item.paused = true;
|
|
1646
|
+
if (s.overlap !== void 0) item.overlap = s.overlap;
|
|
1647
|
+
if (s.jitter !== void 0 && s.jitter > 0) item.jitterMs = s.jitter;
|
|
1648
|
+
const singleton = typeof s.workflow === "function" ? getWorkflowMeta(s.workflow)?.singleton : void 0;
|
|
1649
|
+
if (singleton) {
|
|
1650
|
+
item.singleton = {
|
|
1651
|
+
key: singleton.key(s.input),
|
|
1652
|
+
...singleton.limit !== void 0 ? {
|
|
1653
|
+
limit: singleton.limit
|
|
1654
|
+
} : {},
|
|
1655
|
+
...singleton.maxQueueDepth !== void 0 ? {
|
|
1656
|
+
maxQueueDepth: singleton.maxQueueDepth
|
|
1657
|
+
} : {}
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
return item;
|
|
1661
|
+
}
|
|
1662
|
+
__name(announcedSchedule, "announcedSchedule");
|
|
1279
1663
|
function thinWorkerProviders() {
|
|
1280
1664
|
return [
|
|
1281
1665
|
{
|
|
@@ -1295,7 +1679,7 @@ function thinWorkerProviders() {
|
|
|
1295
1679
|
workflowGroup: options.partition ?? ""
|
|
1296
1680
|
}) : null, "useFactory"),
|
|
1297
1681
|
inject: [
|
|
1298
|
-
|
|
1682
|
+
import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
|
|
1299
1683
|
]
|
|
1300
1684
|
},
|
|
1301
1685
|
{
|
|
@@ -1365,13 +1749,13 @@ function unavailableRunGateway() {
|
|
|
1365
1749
|
__name(unavailableRunGateway, "unavailableRunGateway");
|
|
1366
1750
|
|
|
1367
1751
|
// src/durable.module.ts
|
|
1368
|
-
var
|
|
1752
|
+
var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
|
|
1369
1753
|
var import_common13 = require("@nestjs/common");
|
|
1370
1754
|
var import_core6 = require("@nestjs/core");
|
|
1371
1755
|
|
|
1372
1756
|
// src/durable-step.registrar.ts
|
|
1373
|
-
var
|
|
1374
|
-
var
|
|
1757
|
+
var import_nestjs_durable_core10 = require("@dudousxd/nestjs-durable-core");
|
|
1758
|
+
var import_common4 = require("@nestjs/common");
|
|
1375
1759
|
var import_core2 = require("@nestjs/core");
|
|
1376
1760
|
|
|
1377
1761
|
// src/role.ts
|
|
@@ -1385,7 +1769,7 @@ function isDrivingOperator(options) {
|
|
|
1385
1769
|
__name(isDrivingOperator, "isDrivingOperator");
|
|
1386
1770
|
|
|
1387
1771
|
// src/durable-step.registrar.ts
|
|
1388
|
-
function
|
|
1772
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1389
1773
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1390
1774
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1391
1775
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1398,13 +1782,13 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1398
1782
|
}
|
|
1399
1783
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1400
1784
|
}
|
|
1401
|
-
__name(
|
|
1402
|
-
function
|
|
1785
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1786
|
+
function _ts_metadata4(metadataKey, metadataValue) {
|
|
1403
1787
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1404
1788
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1405
1789
|
}
|
|
1406
1790
|
}
|
|
1407
|
-
__name(
|
|
1791
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1408
1792
|
function _ts_param2(paramIndex, decorator) {
|
|
1409
1793
|
return function(target, key) {
|
|
1410
1794
|
decorator(target, key, paramIndex);
|
|
@@ -1436,12 +1820,12 @@ var DurableStepRegistrar = class {
|
|
|
1436
1820
|
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler, this.options.partition));
|
|
1437
1821
|
}
|
|
1438
1822
|
};
|
|
1439
|
-
DurableStepRegistrar =
|
|
1440
|
-
(0,
|
|
1441
|
-
_ts_param2(2, (0,
|
|
1442
|
-
_ts_param2(3, (0,
|
|
1443
|
-
|
|
1444
|
-
|
|
1823
|
+
DurableStepRegistrar = _ts_decorate4([
|
|
1824
|
+
(0, import_common4.Injectable)(),
|
|
1825
|
+
_ts_param2(2, (0, import_common4.Inject)(import_nestjs_durable_core10.TRANSPORT_CANONICAL)),
|
|
1826
|
+
_ts_param2(3, (0, import_common4.Inject)(import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL)),
|
|
1827
|
+
_ts_metadata4("design:type", Function),
|
|
1828
|
+
_ts_metadata4("design:paramtypes", [
|
|
1445
1829
|
typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
|
|
1446
1830
|
typeof import_core2.MetadataScanner === "undefined" ? Object : import_core2.MetadataScanner,
|
|
1447
1831
|
Object,
|
|
@@ -1449,96 +1833,8 @@ DurableStepRegistrar = _ts_decorate3([
|
|
|
1449
1833
|
])
|
|
1450
1834
|
], DurableStepRegistrar);
|
|
1451
1835
|
|
|
1452
|
-
// src/entity.ts
|
|
1453
|
-
var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
|
|
1454
|
-
var import_common4 = require("@nestjs/common");
|
|
1455
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
1456
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
1457
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1458
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1459
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1460
|
-
} else {
|
|
1461
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1462
|
-
if (d = decorators[i]) {
|
|
1463
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1468
|
-
}
|
|
1469
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
1470
|
-
function _ts_metadata4(metadataKey, metadataValue) {
|
|
1471
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1472
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
__name(_ts_metadata4, "_ts_metadata");
|
|
1476
|
-
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
1477
|
-
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
1478
|
-
function Entity(options) {
|
|
1479
|
-
return (target) => {
|
|
1480
|
-
Reflect.defineMetadata(ENTITY_METADATA, options, target);
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
__name(Entity, "Entity");
|
|
1484
|
-
function On(op) {
|
|
1485
|
-
return (target, propertyKey) => {
|
|
1486
|
-
const ctor = target.constructor;
|
|
1487
|
-
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1488
|
-
ops.set(op, propertyKey);
|
|
1489
|
-
Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
__name(On, "On");
|
|
1493
|
-
function getEntityMeta(target) {
|
|
1494
|
-
return Reflect.getMetadata(ENTITY_METADATA, target);
|
|
1495
|
-
}
|
|
1496
|
-
__name(getEntityMeta, "getEntityMeta");
|
|
1497
|
-
function entityConfigFor(ctor) {
|
|
1498
|
-
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1499
|
-
const Cls = ctor;
|
|
1500
|
-
const handlers = {};
|
|
1501
|
-
for (const [op, method] of ops) {
|
|
1502
|
-
handlers[op] = (state, arg) => {
|
|
1503
|
-
Object.setPrototypeOf(state, Cls.prototype);
|
|
1504
|
-
const fn = state[method];
|
|
1505
|
-
if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
|
|
1506
|
-
return fn.call(state, arg);
|
|
1507
|
-
};
|
|
1508
|
-
}
|
|
1509
|
-
return {
|
|
1510
|
-
initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
|
|
1511
|
-
handlers
|
|
1512
|
-
};
|
|
1513
|
-
}
|
|
1514
|
-
__name(entityConfigFor, "entityConfigFor");
|
|
1515
|
-
var EntityService = class {
|
|
1516
|
-
static {
|
|
1517
|
-
__name(this, "EntityService");
|
|
1518
|
-
}
|
|
1519
|
-
engine;
|
|
1520
|
-
constructor(engine) {
|
|
1521
|
-
this.engine = engine;
|
|
1522
|
-
}
|
|
1523
|
-
/** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
|
|
1524
|
-
signal(name, key, op, arg) {
|
|
1525
|
-
return this.engine.signalEntity(name, key, op, arg);
|
|
1526
|
-
}
|
|
1527
|
-
/** Read an entity's current durable state (or undefined if it has none yet). */
|
|
1528
|
-
getState(name, key) {
|
|
1529
|
-
return this.engine.getEntityState(name, key);
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
EntityService = _ts_decorate4([
|
|
1533
|
-
(0, import_common4.Injectable)(),
|
|
1534
|
-
_ts_metadata4("design:type", Function),
|
|
1535
|
-
_ts_metadata4("design:paramtypes", [
|
|
1536
|
-
typeof import_nestjs_durable_core8.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core8.WorkflowEngine
|
|
1537
|
-
])
|
|
1538
|
-
], EntityService);
|
|
1539
|
-
|
|
1540
1836
|
// src/in-app-worker.ts
|
|
1541
|
-
var
|
|
1837
|
+
var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
|
|
1542
1838
|
var import_common5 = require("@nestjs/common");
|
|
1543
1839
|
var import_core3 = require("@nestjs/core");
|
|
1544
1840
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
@@ -1643,7 +1939,7 @@ var InAppWorkerBootstrap = class {
|
|
|
1643
1939
|
};
|
|
1644
1940
|
InAppWorkerBootstrap = _ts_decorate5([
|
|
1645
1941
|
(0, import_common5.Injectable)(),
|
|
1646
|
-
_ts_param3(2, (0, import_common5.Inject)(
|
|
1942
|
+
_ts_param3(2, (0, import_common5.Inject)(import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL)),
|
|
1647
1943
|
_ts_param3(3, (0, import_common5.Inject)(IN_APP_WORKER_RUNTIME)),
|
|
1648
1944
|
_ts_param3(4, (0, import_common5.Inject)(IN_APP_RUN_REDIS_WORKER)),
|
|
1649
1945
|
_ts_param3(5, (0, import_common5.Inject)(IN_APP_WORKER_RUNNERS)),
|
|
@@ -1663,8 +1959,8 @@ function inAppWorkerProviders() {
|
|
|
1663
1959
|
provide: IN_APP_WORKER_BINDING,
|
|
1664
1960
|
useFactory: /* @__PURE__ */ __name((transport, options) => inAppWorkerBinding(transport, options), "useFactory"),
|
|
1665
1961
|
inject: [
|
|
1666
|
-
|
|
1667
|
-
|
|
1962
|
+
import_nestjs_durable_core11.TRANSPORT_CANONICAL,
|
|
1963
|
+
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
|
|
1668
1964
|
]
|
|
1669
1965
|
},
|
|
1670
1966
|
{
|
|
@@ -1684,7 +1980,7 @@ function inAppWorkerProviders() {
|
|
|
1684
1980
|
workflowGroup: options.partition ?? ""
|
|
1685
1981
|
}) : null, "useFactory"),
|
|
1686
1982
|
inject: [
|
|
1687
|
-
|
|
1983
|
+
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
|
|
1688
1984
|
]
|
|
1689
1985
|
},
|
|
1690
1986
|
{
|
|
@@ -1701,11 +1997,11 @@ function inAppWorkerProviders() {
|
|
|
1701
1997
|
__name(inAppWorkerProviders, "inAppWorkerProviders");
|
|
1702
1998
|
|
|
1703
1999
|
// src/proxy-run-gateway.ts
|
|
1704
|
-
var
|
|
2000
|
+
var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
|
|
1705
2001
|
var import_common6 = require("@nestjs/common");
|
|
1706
2002
|
|
|
1707
2003
|
// src/run-request-responder.ts
|
|
1708
|
-
var
|
|
2004
|
+
var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
|
|
1709
2005
|
var UNSUPPORTED_RUN_REQUEST = "unsupported-request";
|
|
1710
2006
|
var BAD_RUN_REQUEST = "bad-request";
|
|
1711
2007
|
var TENANT_REPUBLISH_MAX_LIMIT = 1e3;
|
|
@@ -1726,7 +2022,9 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
|
1726
2022
|
"republishLifecycle",
|
|
1727
2023
|
"workflowLifecycle",
|
|
1728
2024
|
"signal",
|
|
1729
|
-
"schedule"
|
|
2025
|
+
"schedule",
|
|
2026
|
+
"signalWithStart",
|
|
2027
|
+
"publishEvent"
|
|
1730
2028
|
]);
|
|
1731
2029
|
function wireDate(value) {
|
|
1732
2030
|
if (value === void 0 || value === null) return void 0;
|
|
@@ -1802,7 +2100,8 @@ var RunRequestResponder = class {
|
|
|
1802
2100
|
});
|
|
1803
2101
|
}
|
|
1804
2102
|
async handle(wire) {
|
|
1805
|
-
const
|
|
2103
|
+
const verified = await (0, import_nestjs_durable_core12.verifyWireTenant)(wire.tenant, this.verifyTenant);
|
|
2104
|
+
const tenant = verified?.tenant ?? null;
|
|
1806
2105
|
if (tenant === null) {
|
|
1807
2106
|
return {
|
|
1808
2107
|
requestId: wire.requestId,
|
|
@@ -1980,7 +2279,18 @@ var RunRequestResponder = class {
|
|
|
1980
2279
|
}
|
|
1981
2280
|
};
|
|
1982
2281
|
}
|
|
1983
|
-
return this.answer(msg.requestId, () => signal.call(this.gateway, body.token, body.payload));
|
|
2282
|
+
return this.answer(msg.requestId, () => body.opts === void 0 ? signal.call(this.gateway, body.token, body.payload) : signal.call(this.gateway, body.token, body.payload, body.opts));
|
|
2283
|
+
}
|
|
2284
|
+
if (body.kind === "signalWithStart") {
|
|
2285
|
+
return this.signalWithStart(msg.requestId, body, msg.tenant, verified);
|
|
2286
|
+
}
|
|
2287
|
+
if (body.kind === "publishEvent") {
|
|
2288
|
+
const { publishEventForTenant } = this.gateway;
|
|
2289
|
+
if (!publishEventForTenant) return unsupported(msg.requestId, body.kind);
|
|
2290
|
+
if (typeof body.name !== "string" || body.name === "") {
|
|
2291
|
+
return badRequest(msg.requestId, "publishEvent needs an event name");
|
|
2292
|
+
}
|
|
2293
|
+
return this.answer(msg.requestId, () => publishEventForTenant.call(this.gateway, body.name, body.payload, msg.tenant));
|
|
1984
2294
|
}
|
|
1985
2295
|
if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
|
|
1986
2296
|
return unsupported(msg.requestId, body.kind);
|
|
@@ -2030,7 +2340,7 @@ var RunRequestResponder = class {
|
|
|
2030
2340
|
};
|
|
2031
2341
|
}
|
|
2032
2342
|
if (body.kind === "republishLifecycle" && "runId" in body.target && run) {
|
|
2033
|
-
const kind = (0,
|
|
2343
|
+
const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(run.status);
|
|
2034
2344
|
const refused = kind ? await this.refuseSubscriber(run.workflow, kind, body.target.subscriber, msg.tenant) : void 0;
|
|
2035
2345
|
if (refused) return badRequest(msg.requestId, refused);
|
|
2036
2346
|
}
|
|
@@ -2055,6 +2365,50 @@ var RunRequestResponder = class {
|
|
|
2055
2365
|
};
|
|
2056
2366
|
}
|
|
2057
2367
|
}
|
|
2368
|
+
/**
|
|
2369
|
+
* A tenant's `signalWithStart`: the run it names must be the requester's when it exists, and so
|
|
2370
|
+
* must a run already waiting on the token; anything else is refused `cross-tenant` before the
|
|
2371
|
+
* gateway is called. The run is started in the requester's namespace (a customer tenant it claims
|
|
2372
|
+
* is kept only when its verified token grants it, as for a start-run).
|
|
2373
|
+
*/
|
|
2374
|
+
async signalWithStart(requestId, body, tenant, verified) {
|
|
2375
|
+
const { signalWithStartForTenant, signalWaiter } = this.gateway;
|
|
2376
|
+
if (!signalWithStartForTenant) return unsupported(requestId, body.kind);
|
|
2377
|
+
const start = body.start;
|
|
2378
|
+
if (!start || typeof start.runId !== "string" || start.runId === "" || typeof start.workflow !== "string" || start.workflow === "" || typeof body.signal?.token !== "string" || body.signal.token === "") {
|
|
2379
|
+
return badRequest(requestId, "signalWithStart needs a workflow, a run id and a signal token");
|
|
2380
|
+
}
|
|
2381
|
+
const crossTenant = {
|
|
2382
|
+
requestId,
|
|
2383
|
+
result: {
|
|
2384
|
+
ok: false,
|
|
2385
|
+
error: {
|
|
2386
|
+
message: "run belongs to another tenant",
|
|
2387
|
+
code: "cross-tenant"
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
const existing = await this.runOf(start.runId);
|
|
2392
|
+
if (existing && existing.namespace !== tenant) return crossTenant;
|
|
2393
|
+
const waiterRunId = signalWaiter ? await signalWaiter.call(this.gateway, body.signal.token) : null;
|
|
2394
|
+
const waiter = waiterRunId ? await this.runOf(waiterRunId) : null;
|
|
2395
|
+
if (waiter && waiter.namespace !== tenant) return crossTenant;
|
|
2396
|
+
const claim = start.tenantId !== void 0 ? (0, import_nestjs_durable_core12.grantsClientTenant)(verified, start.tenantId) ? {
|
|
2397
|
+
tenantId: start.tenantId,
|
|
2398
|
+
...start.tenantKind !== void 0 ? {
|
|
2399
|
+
tenantKind: start.tenantKind
|
|
2400
|
+
} : {}
|
|
2401
|
+
} : {
|
|
2402
|
+
tenantId: null
|
|
2403
|
+
} : {};
|
|
2404
|
+
return this.answer(requestId, () => signalWithStartForTenant.call(this.gateway, {
|
|
2405
|
+
...start,
|
|
2406
|
+
tenant
|
|
2407
|
+
}, tenant, claim, {
|
|
2408
|
+
token: body.signal.token,
|
|
2409
|
+
payload: body.signal.payload
|
|
2410
|
+
}));
|
|
2411
|
+
}
|
|
2058
2412
|
/** The run alone (`getRun`, else from its detail), or null when it does not exist. */
|
|
2059
2413
|
async runOf(runId) {
|
|
2060
2414
|
return this.gateway.getRun ? this.gateway.getRun(runId) : (await this.gateway.getRunDetail(runId))?.run ?? null;
|
|
@@ -2096,7 +2450,7 @@ var RunRequestResponder = class {
|
|
|
2096
2450
|
namespace: tenant
|
|
2097
2451
|
});
|
|
2098
2452
|
if (!links) return rest;
|
|
2099
|
-
const kind = (0,
|
|
2453
|
+
const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(detail.run.status);
|
|
2100
2454
|
const subscribers = kind ? [
|
|
2101
2455
|
...new Set(links.startsOnSettle.filter((l) => l.kind === kind).map((l) => l.workflow))
|
|
2102
2456
|
] : [];
|
|
@@ -2223,6 +2577,10 @@ var RunGatewayError = class extends Error {
|
|
|
2223
2577
|
this.code = code;
|
|
2224
2578
|
}
|
|
2225
2579
|
};
|
|
2580
|
+
function unsupportedVerb(kind) {
|
|
2581
|
+
return new RunGatewayError(`${kind} is not supported by this server: the control plane is older than this tenant`, UNSUPPORTED_RUN_REQUEST);
|
|
2582
|
+
}
|
|
2583
|
+
__name(unsupportedVerb, "unsupportedVerb");
|
|
2226
2584
|
var UnsupportedRunRequestError = class UnsupportedRunRequestError2 extends RunGatewayError {
|
|
2227
2585
|
static {
|
|
2228
2586
|
__name(this, "UnsupportedRunRequestError");
|
|
@@ -2273,12 +2631,12 @@ var ProxyRunGateway = class {
|
|
|
2273
2631
|
} catch (err) {
|
|
2274
2632
|
return Promise.reject(err);
|
|
2275
2633
|
}
|
|
2276
|
-
return send(filter ? (0,
|
|
2634
|
+
return send(filter ? (0, import_nestjs_durable_core13.scopeTenantQuery)(query, filter) : query);
|
|
2277
2635
|
}
|
|
2278
2636
|
/** `run` when the request may see it, else null (an invisible run reads like a missing one). */
|
|
2279
2637
|
visible(run, filter = this.restrictive()) {
|
|
2280
2638
|
if (!run) return null;
|
|
2281
|
-
return !filter || (0,
|
|
2639
|
+
return !filter || (0, import_nestjs_durable_core13.tenantVisible)(run, filter) ? run : null;
|
|
2282
2640
|
}
|
|
2283
2641
|
/** Run a control call unless the request may not act on `runId` (then `null`, like a missing run).
|
|
2284
2642
|
* Sent at once when nothing narrows the request. */
|
|
@@ -2314,7 +2672,7 @@ var ProxyRunGateway = class {
|
|
|
2314
2672
|
request(body) {
|
|
2315
2673
|
const source = this.tenantToken;
|
|
2316
2674
|
if (typeof source !== "function") return this.send(source ?? this.tenant, body);
|
|
2317
|
-
return (0,
|
|
2675
|
+
return (0, import_nestjs_durable_core13.resolveTenantToken)(source).then((tenant) => this.send(tenant, body));
|
|
2318
2676
|
}
|
|
2319
2677
|
send(tenant, body) {
|
|
2320
2678
|
return new Promise((resolve, reject) => {
|
|
@@ -2364,12 +2722,12 @@ var ProxyRunGateway = class {
|
|
|
2364
2722
|
if (detail && filter && !this.visible(detail.run, filter)) return null;
|
|
2365
2723
|
const over = options?.summarizeFansOver;
|
|
2366
2724
|
if (over === void 0 || !detail || detail.fans !== void 0) return detail;
|
|
2367
|
-
const { timeline, fans } = (0,
|
|
2368
|
-
const ids = (0,
|
|
2725
|
+
const { timeline, fans } = (0, import_nestjs_durable_core13.summarizeTimeline)(detail.timeline, over);
|
|
2726
|
+
const ids = (0, import_nestjs_durable_core13.childIdsOf)(detail.timeline);
|
|
2369
2727
|
return {
|
|
2370
2728
|
...detail,
|
|
2371
2729
|
timeline,
|
|
2372
|
-
children: ids.slice(0,
|
|
2730
|
+
children: ids.slice(0, import_nestjs_durable_core13.SUMMARY_CHILD_LIMIT),
|
|
2373
2731
|
fans,
|
|
2374
2732
|
childCount: ids.length
|
|
2375
2733
|
};
|
|
@@ -2395,7 +2753,7 @@ var ProxyRunGateway = class {
|
|
|
2395
2753
|
kind: "getRunDetail",
|
|
2396
2754
|
runId
|
|
2397
2755
|
});
|
|
2398
|
-
return detail ? (0,
|
|
2756
|
+
return detail ? (0, import_nestjs_durable_core13.pageFan)(detail.timeline, group, query) : null;
|
|
2399
2757
|
}
|
|
2400
2758
|
/**
|
|
2401
2759
|
* The run alone, without its timeline. Read from the full detail when the control plane is too old
|
|
@@ -2528,7 +2886,7 @@ var ProxyRunGateway = class {
|
|
|
2528
2886
|
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
2529
2887
|
*/
|
|
2530
2888
|
async requestNewVerb(body) {
|
|
2531
|
-
const notSupported = /* @__PURE__ */ __name(() =>
|
|
2889
|
+
const notSupported = /* @__PURE__ */ __name(() => unsupportedVerb(body.kind), "notSupported");
|
|
2532
2890
|
if (this.knownUnsupported(body.kind)) throw notSupported();
|
|
2533
2891
|
let data;
|
|
2534
2892
|
try {
|
|
@@ -2540,6 +2898,62 @@ var ProxyRunGateway = class {
|
|
|
2540
2898
|
this.unsupportedUntil.set(body.kind, Date.now() + this.capabilityTtlMs);
|
|
2541
2899
|
throw notSupported();
|
|
2542
2900
|
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Signal the run of this tenant's namespace waiting on `token` (`engine.signal`). Resolves null
|
|
2903
|
+
* when no run of this namespace waits on it: the control plane does NOT buffer a tenant's signal
|
|
2904
|
+
* for a wait opened later (another namespace's run could open it). A control plane that predates
|
|
2905
|
+
* the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error.
|
|
2906
|
+
*/
|
|
2907
|
+
async signal(token, payload, opts) {
|
|
2908
|
+
if (this.knownUnsupported("signal")) throw unsupportedVerb("signal");
|
|
2909
|
+
let data;
|
|
2910
|
+
try {
|
|
2911
|
+
data = await this.request(opts === void 0 ? {
|
|
2912
|
+
kind: "signal",
|
|
2913
|
+
token,
|
|
2914
|
+
payload
|
|
2915
|
+
} : {
|
|
2916
|
+
kind: "signal",
|
|
2917
|
+
token,
|
|
2918
|
+
payload,
|
|
2919
|
+
opts
|
|
2920
|
+
});
|
|
2921
|
+
} catch (err) {
|
|
2922
|
+
if (!isUnsupported(err)) throw err;
|
|
2923
|
+
}
|
|
2924
|
+
if (data !== void 0) return data;
|
|
2925
|
+
this.unsupportedUntil.set("signal", Date.now() + this.capabilityTtlMs);
|
|
2926
|
+
throw unsupportedVerb("signal");
|
|
2927
|
+
}
|
|
2928
|
+
/**
|
|
2929
|
+
* `engine.signalWithStart` for this tenant: the control plane starts `start` in this tenant's
|
|
2930
|
+
* namespace unless its run exists, then signals it (buffered until the run waits, when the token
|
|
2931
|
+
* names the run id). See the responder for the authorization rule.
|
|
2932
|
+
*/
|
|
2933
|
+
signalWithStart(start, signal) {
|
|
2934
|
+
return this.requestNewVerb({
|
|
2935
|
+
kind: "signalWithStart",
|
|
2936
|
+
start,
|
|
2937
|
+
signal
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
2941
|
+
* Resume the runs of this tenant's namespace waiting on event `name` (`ctx.waitForEvent`).
|
|
2942
|
+
* Resolves how many it resumed. The tenant's own `onEvent` subscribers are started by the caller
|
|
2943
|
+
* (`DurableStartClient.publishEvent`), not here.
|
|
2944
|
+
*/
|
|
2945
|
+
publishEvent(name, payload, opts) {
|
|
2946
|
+
return this.requestNewVerb({
|
|
2947
|
+
kind: "publishEvent",
|
|
2948
|
+
name,
|
|
2949
|
+
payload,
|
|
2950
|
+
...opts?.id !== void 0 ? {
|
|
2951
|
+
opts: {
|
|
2952
|
+
id: opts.id
|
|
2953
|
+
}
|
|
2954
|
+
} : {}
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2543
2957
|
subscribe(runId, onEvent) {
|
|
2544
2958
|
const unsubscribe = this.transport.onTenantEvent?.(this.tenant, (evt) => {
|
|
2545
2959
|
if (evt.event.runId === runId) onEvent(evt.event);
|
|
@@ -2562,7 +2976,7 @@ ProxyRunGateway = _ts_decorate6([
|
|
|
2562
2976
|
], ProxyRunGateway);
|
|
2563
2977
|
|
|
2564
2978
|
// src/retention-poller.ts
|
|
2565
|
-
var
|
|
2979
|
+
var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
|
|
2566
2980
|
var import_common8 = require("@nestjs/common");
|
|
2567
2981
|
|
|
2568
2982
|
// src/settle-within.ts
|
|
@@ -2589,7 +3003,7 @@ async function settleWithin(p, timeoutMs) {
|
|
|
2589
3003
|
__name(settleWithin, "settleWithin");
|
|
2590
3004
|
|
|
2591
3005
|
// src/sweep-leases.ts
|
|
2592
|
-
var
|
|
3006
|
+
var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
|
|
2593
3007
|
var import_common7 = require("@nestjs/common");
|
|
2594
3008
|
var import_core4 = require("@nestjs/core");
|
|
2595
3009
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
@@ -2687,7 +3101,7 @@ SweepLeases = _ts_decorate7([
|
|
|
2687
3101
|
(0, import_common7.Injectable)(),
|
|
2688
3102
|
_ts_param4(0, (0, import_common7.Optional)()),
|
|
2689
3103
|
_ts_param4(1, (0, import_common7.Optional)()),
|
|
2690
|
-
_ts_param4(1, (0, import_common7.Inject)(
|
|
3104
|
+
_ts_param4(1, (0, import_common7.Inject)(import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL)),
|
|
2691
3105
|
_ts_metadata7("design:type", Function),
|
|
2692
3106
|
_ts_metadata7("design:paramtypes", [
|
|
2693
3107
|
typeof import_core4.ModuleRef === "undefined" ? Object : import_core4.ModuleRef,
|
|
@@ -2735,10 +3149,10 @@ function validateRetention(retention) {
|
|
|
2735
3149
|
if (policy.maxAge == null && policy.maxCount == null) {
|
|
2736
3150
|
throw new Error("durable retention: each policy must set maxAge and/or maxCount");
|
|
2737
3151
|
}
|
|
2738
|
-
if (policy.maxAge != null) (0,
|
|
3152
|
+
if (policy.maxAge != null) (0, import_nestjs_durable_core15.parseDuration)(policy.maxAge);
|
|
2739
3153
|
for (const status of policy.statuses) {
|
|
2740
|
-
if (!
|
|
2741
|
-
throw new Error(`durable retention: status "${status}" is not terminal; only ${
|
|
3154
|
+
if (!import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.includes(status)) {
|
|
3155
|
+
throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
2742
3156
|
}
|
|
2743
3157
|
const key = `${scopeKey}|${status}`;
|
|
2744
3158
|
if (seen.has(key)) {
|
|
@@ -2792,7 +3206,7 @@ var RetentionPoller = class {
|
|
|
2792
3206
|
return;
|
|
2793
3207
|
}
|
|
2794
3208
|
void this.sweep();
|
|
2795
|
-
const intervalMs = retention.sweepInterval != null ? (0,
|
|
3209
|
+
const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core15.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
|
|
2796
3210
|
if (intervalMs > 0) {
|
|
2797
3211
|
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
2798
3212
|
this.timer.unref?.();
|
|
@@ -2856,8 +3270,8 @@ var RetentionPoller = class {
|
|
|
2856
3270
|
};
|
|
2857
3271
|
RetentionPoller = _ts_decorate8([
|
|
2858
3272
|
(0, import_common8.Injectable)(),
|
|
2859
|
-
_ts_param5(0, (0, import_common8.Inject)(
|
|
2860
|
-
_ts_param5(1, (0, import_common8.Inject)(
|
|
3273
|
+
_ts_param5(0, (0, import_common8.Inject)(import_nestjs_durable_core15.STATE_STORE_CANONICAL)),
|
|
3274
|
+
_ts_param5(1, (0, import_common8.Inject)(import_nestjs_durable_core15.DURABLE_OPTIONS_CANONICAL)),
|
|
2861
3275
|
_ts_param5(2, (0, import_common8.Optional)()),
|
|
2862
3276
|
_ts_metadata8("design:type", Function),
|
|
2863
3277
|
_ts_metadata8("design:paramtypes", [
|
|
@@ -2868,7 +3282,7 @@ RetentionPoller = _ts_decorate8([
|
|
|
2868
3282
|
], RetentionPoller);
|
|
2869
3283
|
|
|
2870
3284
|
// src/store-run-gateway.ts
|
|
2871
|
-
var
|
|
3285
|
+
var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
|
|
2872
3286
|
var import_common9 = require("@nestjs/common");
|
|
2873
3287
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
2874
3288
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2911,14 +3325,14 @@ function detailExtras(links) {
|
|
|
2911
3325
|
}
|
|
2912
3326
|
__name(detailExtras, "detailExtras");
|
|
2913
3327
|
function withoutRegistry(query) {
|
|
2914
|
-
if (query.workflow ===
|
|
3328
|
+
if (query.workflow === import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW)) {
|
|
2915
3329
|
return query;
|
|
2916
3330
|
}
|
|
2917
3331
|
return {
|
|
2918
3332
|
...query,
|
|
2919
3333
|
excludeWorkflows: [
|
|
2920
3334
|
...query.excludeWorkflows ?? [],
|
|
2921
|
-
|
|
3335
|
+
import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW
|
|
2922
3336
|
]
|
|
2923
3337
|
};
|
|
2924
3338
|
}
|
|
@@ -2969,10 +3383,10 @@ var StoreRunGateway = class {
|
|
|
2969
3383
|
...links
|
|
2970
3384
|
};
|
|
2971
3385
|
}
|
|
2972
|
-
if ((0,
|
|
3386
|
+
if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
|
|
2973
3387
|
const stats = await this.store.checkpointStats(runId);
|
|
2974
|
-
const etag = (0,
|
|
2975
|
-
if ((0,
|
|
3388
|
+
const etag = (0, import_nestjs_durable_core16.extendEtag)((0, import_nestjs_durable_core16.runDetailEtag)(run, stats, over), detailExtras(links));
|
|
3389
|
+
if ((0, import_nestjs_durable_core16.etagMatches)(options?.ifNoneMatch, etag)) {
|
|
2976
3390
|
return {
|
|
2977
3391
|
run,
|
|
2978
3392
|
timeline: [],
|
|
@@ -2983,18 +3397,18 @@ var StoreRunGateway = class {
|
|
|
2983
3397
|
}
|
|
2984
3398
|
return {
|
|
2985
3399
|
run,
|
|
2986
|
-
...await (0,
|
|
3400
|
+
...await (0, import_nestjs_durable_core16.summarizeRunFromStore)(this.store, runId, over, stats),
|
|
2987
3401
|
etag,
|
|
2988
3402
|
...links
|
|
2989
3403
|
};
|
|
2990
3404
|
}
|
|
2991
3405
|
const full = await this.store.listCheckpoints(runId);
|
|
2992
|
-
const { timeline, fans } = (0,
|
|
2993
|
-
const ids = (0,
|
|
3406
|
+
const { timeline, fans } = (0, import_nestjs_durable_core16.summarizeTimeline)(full, over);
|
|
3407
|
+
const ids = (0, import_nestjs_durable_core16.childIdsOf)(full);
|
|
2994
3408
|
return {
|
|
2995
3409
|
run,
|
|
2996
3410
|
timeline,
|
|
2997
|
-
children: ids.slice(0,
|
|
3411
|
+
children: ids.slice(0, import_nestjs_durable_core16.SUMMARY_CHILD_LIMIT),
|
|
2998
3412
|
fans,
|
|
2999
3413
|
childCount: ids.length,
|
|
3000
3414
|
...links
|
|
@@ -3009,24 +3423,24 @@ var StoreRunGateway = class {
|
|
|
3009
3423
|
*/
|
|
3010
3424
|
async lifecycleLinks(run) {
|
|
3011
3425
|
const triggered = await this.engine.triggeredRuns(run);
|
|
3012
|
-
const source = (0,
|
|
3013
|
-
const kind = (0,
|
|
3426
|
+
const source = (0, import_nestjs_durable_core16.lifecycleSourceOf)(run);
|
|
3427
|
+
const kind = (0, import_nestjs_durable_core16.lifecycleKindOf)(run.status);
|
|
3014
3428
|
const subscribers = kind ? await this.engine.lifecycleSubscribers(run.workflow, kind, run.namespace || "default") : [];
|
|
3015
3429
|
const workflowLifecycle = await this.engine.workflowLifecycle(run.workflow);
|
|
3016
3430
|
const linked = workflowLifecycle.startsOnSettle.length > 0 || workflowLifecycle.startedBy.length > 0;
|
|
3017
|
-
const deliveries = kind ? (0,
|
|
3431
|
+
const deliveries = kind ? (0, import_nestjs_durable_core16.lifecycleDeliveriesOf)(run, {
|
|
3018
3432
|
subscribers,
|
|
3019
3433
|
live: new Set(subscribers),
|
|
3020
3434
|
coalesced: this.engine.coalescedSubscribers(run)
|
|
3021
3435
|
}) : [];
|
|
3022
3436
|
const [own, onIt] = await Promise.all([
|
|
3023
|
-
run.status === "suspended" ? (0,
|
|
3437
|
+
run.status === "suspended" ? (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, [
|
|
3024
3438
|
run.id
|
|
3025
3439
|
]) : [],
|
|
3026
|
-
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0,
|
|
3440
|
+
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0, import_nestjs_durable_core16.runWaitPrefix)(run.id))
|
|
3027
3441
|
]);
|
|
3028
3442
|
const waitsFor = own.flatMap((w) => {
|
|
3029
|
-
const target = (0,
|
|
3443
|
+
const target = (0, import_nestjs_durable_core16.runWaitTargetOf)(w);
|
|
3030
3444
|
return target !== void 0 ? [
|
|
3031
3445
|
{
|
|
3032
3446
|
runId: target,
|
|
@@ -3034,14 +3448,14 @@ var StoreRunGateway = class {
|
|
|
3034
3448
|
}
|
|
3035
3449
|
] : [];
|
|
3036
3450
|
});
|
|
3037
|
-
const awaitedBy = onIt.filter((w) => (0,
|
|
3451
|
+
const awaitedBy = onIt.filter((w) => (0, import_nestjs_durable_core16.runWaitTargetOf)(w) === run.id).map((w) => ({
|
|
3038
3452
|
runId: w.runId,
|
|
3039
3453
|
seq: w.seq
|
|
3040
3454
|
}));
|
|
3041
3455
|
const started = deliveries.flatMap((d) => d.state === "started" && d.runId !== void 0 ? [
|
|
3042
3456
|
d.runId
|
|
3043
3457
|
] : []);
|
|
3044
|
-
const { runs } = await (0,
|
|
3458
|
+
const { runs } = await (0, import_nestjs_durable_core16.readRunsByIds)(this.store, [
|
|
3045
3459
|
...source ? [
|
|
3046
3460
|
source.runId
|
|
3047
3461
|
] : [],
|
|
@@ -3058,7 +3472,7 @@ var StoreRunGateway = class {
|
|
|
3058
3472
|
} : link;
|
|
3059
3473
|
}, "withRun");
|
|
3060
3474
|
const sourceRun = source ? runs.get(source.runId) : void 0;
|
|
3061
|
-
const traceId = (0,
|
|
3475
|
+
const traceId = (0, import_nestjs_durable_core16.traceIdOfTraceparent)((0, import_nestjs_durable_core16.lifecycleTraceparentOf)(sourceRun?.tags));
|
|
3062
3476
|
return {
|
|
3063
3477
|
...triggered.length > 0 ? {
|
|
3064
3478
|
triggered
|
|
@@ -3103,12 +3517,12 @@ var StoreRunGateway = class {
|
|
|
3103
3517
|
}
|
|
3104
3518
|
async getFanMembers(runId, group, query) {
|
|
3105
3519
|
if (!await this.visibleRun(runId)) return null;
|
|
3106
|
-
if ((0,
|
|
3520
|
+
if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
|
|
3107
3521
|
const stats = await this.store.checkpointStats(runId, {
|
|
3108
3522
|
group
|
|
3109
3523
|
});
|
|
3110
|
-
const etag = (0,
|
|
3111
|
-
if ((0,
|
|
3524
|
+
const etag = (0, import_nestjs_durable_core16.fanPageEtag)(group, stats, query);
|
|
3525
|
+
if ((0, import_nestjs_durable_core16.etagMatches)(query.ifNoneMatch, etag)) {
|
|
3112
3526
|
return {
|
|
3113
3527
|
items: [],
|
|
3114
3528
|
total: 0,
|
|
@@ -3117,17 +3531,17 @@ var StoreRunGateway = class {
|
|
|
3117
3531
|
};
|
|
3118
3532
|
}
|
|
3119
3533
|
return {
|
|
3120
|
-
...await (0,
|
|
3534
|
+
...await (0, import_nestjs_durable_core16.pageFanFromStore)(this.store, runId, group, query, stats),
|
|
3121
3535
|
etag
|
|
3122
3536
|
};
|
|
3123
3537
|
}
|
|
3124
|
-
return (0,
|
|
3538
|
+
return (0, import_nestjs_durable_core16.pageFan)(await this.store.listCheckpoints(runId), group, query);
|
|
3125
3539
|
}
|
|
3126
3540
|
async listRuns(query) {
|
|
3127
3541
|
const runs = await this.store.listRuns(this.scoped(withoutRegistry(query)));
|
|
3128
|
-
const waiterByRun = (0,
|
|
3542
|
+
const waiterByRun = (0, import_nestjs_durable_core16.indexWaitersByRun)(await (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, runs.filter((run) => run.status === "suspended").map((run) => run.id)));
|
|
3129
3543
|
return runs.map((run) => {
|
|
3130
|
-
const waiting = (0,
|
|
3544
|
+
const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
|
|
3131
3545
|
return waiting ? {
|
|
3132
3546
|
...run,
|
|
3133
3547
|
waiting
|
|
@@ -3144,7 +3558,7 @@ var StoreRunGateway = class {
|
|
|
3144
3558
|
const scoped = this.scoped(withoutRegistry(query));
|
|
3145
3559
|
if (this.store.runFacets) return this.store.runFacets(scoped);
|
|
3146
3560
|
const runs = await this.store.listRuns(scoped);
|
|
3147
|
-
return (0,
|
|
3561
|
+
return (0, import_nestjs_durable_core16.mergeRunFacetRows)(runs.map((r) => ({
|
|
3148
3562
|
status: r.status,
|
|
3149
3563
|
origin: r.origin,
|
|
3150
3564
|
count: 1
|
|
@@ -3179,13 +3593,13 @@ var StoreRunGateway = class {
|
|
|
3179
3593
|
"suspended"
|
|
3180
3594
|
]
|
|
3181
3595
|
})),
|
|
3182
|
-
(0,
|
|
3596
|
+
(0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, runIds)
|
|
3183
3597
|
]);
|
|
3184
|
-
const waiterByRun = (0,
|
|
3598
|
+
const waiterByRun = (0, import_nestjs_durable_core16.indexWaitersByRun)(waiters);
|
|
3185
3599
|
const result = {};
|
|
3186
3600
|
for (const run of suspended) {
|
|
3187
3601
|
if (!idSet.has(run.id)) continue;
|
|
3188
|
-
const waiting = (0,
|
|
3602
|
+
const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
|
|
3189
3603
|
if (waiting) result[run.id] = waiting;
|
|
3190
3604
|
}
|
|
3191
3605
|
return result;
|
|
@@ -3228,8 +3642,14 @@ var StoreRunGateway = class {
|
|
|
3228
3642
|
if (action === "trigger") return this.engine.schedules.trigger(id);
|
|
3229
3643
|
return Promise.reject(new Error(`unknown schedule action ${String(action)}`));
|
|
3230
3644
|
}
|
|
3231
|
-
signal(token, payload) {
|
|
3232
|
-
return this.engine.signal(token, payload);
|
|
3645
|
+
signal(token, payload, opts) {
|
|
3646
|
+
return this.engine.signal(token, payload, opts);
|
|
3647
|
+
}
|
|
3648
|
+
signalWithStartForTenant(start, namespace, clientTenant, signal) {
|
|
3649
|
+
return this.engine.signalWithStartForTenant(start, namespace, clientTenant, signal);
|
|
3650
|
+
}
|
|
3651
|
+
publishEventForTenant(name, payload, namespace) {
|
|
3652
|
+
return this.engine.publishEventForTenant(name, payload, namespace);
|
|
3233
3653
|
}
|
|
3234
3654
|
async signalWaiter(token) {
|
|
3235
3655
|
const waiter = (await this.store.listSignalWaiters(token)).find((w) => w.token === token);
|
|
@@ -3277,11 +3697,11 @@ var StoreRunGateway = class {
|
|
|
3277
3697
|
};
|
|
3278
3698
|
StoreRunGateway = _ts_decorate9([
|
|
3279
3699
|
(0, import_common9.Injectable)(),
|
|
3280
|
-
_ts_param6(0, (0, import_common9.Inject)(
|
|
3700
|
+
_ts_param6(0, (0, import_common9.Inject)(import_nestjs_durable_core16.STATE_STORE_CANONICAL)),
|
|
3281
3701
|
_ts_metadata9("design:type", Function),
|
|
3282
3702
|
_ts_metadata9("design:paramtypes", [
|
|
3283
3703
|
typeof StateStore === "undefined" ? Object : StateStore,
|
|
3284
|
-
typeof
|
|
3704
|
+
typeof import_nestjs_durable_core16.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core16.WorkflowEngine
|
|
3285
3705
|
])
|
|
3286
3706
|
], StoreRunGateway);
|
|
3287
3707
|
|
|
@@ -3328,7 +3748,7 @@ var TenantEventRepublisher = class {
|
|
|
3328
3748
|
|
|
3329
3749
|
// src/timer-poller.ts
|
|
3330
3750
|
var durableCore = __toESM(require("@dudousxd/nestjs-durable-core"), 1);
|
|
3331
|
-
var
|
|
3751
|
+
var import_nestjs_durable_core17 = require("@dudousxd/nestjs-durable-core");
|
|
3332
3752
|
var import_common10 = require("@nestjs/common");
|
|
3333
3753
|
function _ts_decorate10(decorators, target, key, desc) {
|
|
3334
3754
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3379,13 +3799,15 @@ var TimerPoller = class {
|
|
|
3379
3799
|
endWait;
|
|
3380
3800
|
/** When the owed-lifecycle listing last succeeded (see {@link owedSweepDue}). */
|
|
3381
3801
|
owedSweptAt;
|
|
3802
|
+
/** When the tenant schedule announcements were last reconciled (see {@link announcedSchedules}). */
|
|
3803
|
+
announcedSyncedAt;
|
|
3382
3804
|
constructor(engine, options, leases = new SweepLeases()) {
|
|
3383
3805
|
this.engine = engine;
|
|
3384
3806
|
this.options = options;
|
|
3385
3807
|
this.leases = leases;
|
|
3386
3808
|
}
|
|
3387
3809
|
async onApplicationBootstrap() {
|
|
3388
|
-
for (const s of this.options.schedules ?? []) (0,
|
|
3810
|
+
for (const s of this.options.schedules ?? []) (0, import_nestjs_durable_core17.workflowName)(s.workflow);
|
|
3389
3811
|
if (!isDrivingOperator(this.options)) return;
|
|
3390
3812
|
this.engine.consumeRuns?.();
|
|
3391
3813
|
this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
|
|
@@ -3468,7 +3890,8 @@ var TimerPoller = class {
|
|
|
3468
3890
|
try {
|
|
3469
3891
|
const now = Date.now();
|
|
3470
3892
|
const stored = await this.engine.nextDueAt(now + wait, {
|
|
3471
|
-
persistedSchedules: this.options.persistedSchedules === true
|
|
3893
|
+
persistedSchedules: this.options.persistedSchedules === true,
|
|
3894
|
+
announcedSchedules: this.announcedSchedules() !== void 0
|
|
3472
3895
|
});
|
|
3473
3896
|
const schedules = this.options.schedules;
|
|
3474
3897
|
const scheduled = schedules && schedules.length > 0 && nextScheduleFireAt2 ? nextScheduleFireAt2(this.engine, schedules, now) : void 0;
|
|
@@ -3485,6 +3908,22 @@ var TimerPoller = class {
|
|
|
3485
3908
|
}
|
|
3486
3909
|
}
|
|
3487
3910
|
/**
|
|
3911
|
+
* The tenant schedule adoption settings when it is on (see
|
|
3912
|
+
* {@link DurableModuleOptions.announcedSchedules}), else undefined: off by option, on a core
|
|
3913
|
+
* without it, or on a store that does not persist schedules.
|
|
3914
|
+
*/
|
|
3915
|
+
announcedSchedules() {
|
|
3916
|
+
const option = this.options.announcedSchedules;
|
|
3917
|
+
if (option === false) return void 0;
|
|
3918
|
+
if (typeof this.engine.syncAnnouncedSchedules !== "function") return void 0;
|
|
3919
|
+
if (this.engine.schedules?.supported !== true) return void 0;
|
|
3920
|
+
const settings = typeof option === "object" ? option : {};
|
|
3921
|
+
return {
|
|
3922
|
+
syncMs: settings.syncMs ?? 15e3,
|
|
3923
|
+
graceMs: settings.graceMs
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
/**
|
|
3488
3927
|
* Whether this poll lists the owed lifecycle runs: until a sweep that listed them succeeded, then
|
|
3489
3928
|
* once per `owedLifecycleSweepMs` (a clock that went back lists them again).
|
|
3490
3929
|
*/
|
|
@@ -3565,10 +4004,29 @@ var TimerPoller = class {
|
|
|
3565
4004
|
}));
|
|
3566
4005
|
const schedules = this.options.schedules;
|
|
3567
4006
|
if (schedules && schedules.length > 0) {
|
|
3568
|
-
note(await this.sweep("schedules", () => (0,
|
|
4007
|
+
note(await this.sweep("schedules", () => (0, import_nestjs_durable_core17.runSchedules)(this.engine, schedules, Date.now())));
|
|
4008
|
+
}
|
|
4009
|
+
const announced = this.announcedSchedules();
|
|
4010
|
+
if (announced) {
|
|
4011
|
+
const at = Date.now();
|
|
4012
|
+
const last = this.announcedSyncedAt;
|
|
4013
|
+
if (last === void 0 || at < last || at - last >= announced.syncMs) {
|
|
4014
|
+
await this.sweep("announcedSchedules", () => this.leases.run("announced-schedules", async () => {
|
|
4015
|
+
await this.engine.syncAnnouncedSchedules({
|
|
4016
|
+
...announced.graceMs !== void 0 ? {
|
|
4017
|
+
graceMs: announced.graceMs
|
|
4018
|
+
} : {}
|
|
4019
|
+
});
|
|
4020
|
+
this.announcedSyncedAt = at;
|
|
4021
|
+
}));
|
|
4022
|
+
}
|
|
3569
4023
|
}
|
|
3570
4024
|
if (this.options.persistedSchedules) {
|
|
3571
4025
|
note(await this.sweep("persistedSchedules", () => this.engine.schedules.tick()));
|
|
4026
|
+
} else if (announced) {
|
|
4027
|
+
note(await this.sweep("announcedScheduleFires", () => this.engine.schedules.tick(Date.now(), {
|
|
4028
|
+
tag: import_nestjs_durable_core17.ANNOUNCED_SCHEDULE_TAG
|
|
4029
|
+
})));
|
|
3572
4030
|
}
|
|
3573
4031
|
return worked;
|
|
3574
4032
|
}
|
|
@@ -3584,41 +4042,20 @@ var TimerPoller = class {
|
|
|
3584
4042
|
};
|
|
3585
4043
|
TimerPoller = _ts_decorate10([
|
|
3586
4044
|
(0, import_common10.Injectable)(),
|
|
3587
|
-
_ts_param7(1, (0, import_common10.Inject)(
|
|
4045
|
+
_ts_param7(1, (0, import_common10.Inject)(import_nestjs_durable_core17.DURABLE_OPTIONS_CANONICAL)),
|
|
3588
4046
|
_ts_param7(2, (0, import_common10.Optional)()),
|
|
3589
4047
|
_ts_metadata10("design:type", Function),
|
|
3590
4048
|
_ts_metadata10("design:paramtypes", [
|
|
3591
|
-
typeof
|
|
4049
|
+
typeof import_nestjs_durable_core17.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core17.WorkflowEngine,
|
|
3592
4050
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
3593
4051
|
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
3594
4052
|
])
|
|
3595
4053
|
], TimerPoller);
|
|
3596
4054
|
|
|
3597
|
-
// src/tokens.ts
|
|
3598
|
-
var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
|
|
3599
|
-
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
3600
|
-
var RUN_GATEWAY = import_nestjs_durable_core16.RunGateway;
|
|
3601
|
-
|
|
3602
4055
|
// src/workflow.registrar.ts
|
|
3603
|
-
var
|
|
4056
|
+
var import_nestjs_durable_core18 = require("@dudousxd/nestjs-durable-core");
|
|
3604
4057
|
var import_common11 = require("@nestjs/common");
|
|
3605
4058
|
var import_core5 = require("@nestjs/core");
|
|
3606
|
-
|
|
3607
|
-
// src/step-interceptor.ts
|
|
3608
|
-
var import_reflect_metadata3 = require("reflect-metadata");
|
|
3609
|
-
var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
|
|
3610
|
-
function StepInterceptor() {
|
|
3611
|
-
return (target) => {
|
|
3612
|
-
Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
|
|
3613
|
-
};
|
|
3614
|
-
}
|
|
3615
|
-
__name(StepInterceptor, "StepInterceptor");
|
|
3616
|
-
function isStepInterceptor(target) {
|
|
3617
|
-
return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
|
|
3618
|
-
}
|
|
3619
|
-
__name(isStepInterceptor, "isStepInterceptor");
|
|
3620
|
-
|
|
3621
|
-
// src/workflow.registrar.ts
|
|
3622
4059
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
3623
4060
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3624
4061
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -3741,11 +4178,11 @@ var WorkflowRegistrar = class {
|
|
|
3741
4178
|
// so a turn dispatched under the wrong token would never be consumed. Absent → the inline fast
|
|
3742
4179
|
// path (unchanged).
|
|
3743
4180
|
...this.inAppWorker ? {
|
|
3744
|
-
group: (0,
|
|
3745
|
-
executor: new
|
|
4181
|
+
group: (0, import_nestjs_durable_core18.tenantGroup)((0, import_nestjs_durable_core18.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
|
|
4182
|
+
executor: new import_nestjs_durable_core18.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
|
|
3746
4183
|
} : {}
|
|
3747
4184
|
});
|
|
3748
|
-
(0,
|
|
4185
|
+
(0, import_nestjs_durable_core18.bindWorkflowClass)(workflowCtor, {
|
|
3749
4186
|
start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
|
|
3750
4187
|
waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
|
|
3751
4188
|
});
|
|
@@ -3760,7 +4197,7 @@ var WorkflowRegistrar = class {
|
|
|
3760
4197
|
});
|
|
3761
4198
|
deadLetterByWorkflow.set(meta.name, dlqName);
|
|
3762
4199
|
} else if (meta.deadLetterWorkflow) {
|
|
3763
|
-
deadLetterByWorkflow.set(meta.name, (0,
|
|
4200
|
+
deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core18.workflowName)(meta.deadLetterWorkflow));
|
|
3764
4201
|
}
|
|
3765
4202
|
});
|
|
3766
4203
|
this.reportUnattributed(unattributed);
|
|
@@ -3808,39 +4245,47 @@ var WorkflowRegistrar = class {
|
|
|
3808
4245
|
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
3809
4246
|
*/
|
|
3810
4247
|
installDeadLetterRouting(byWorkflow) {
|
|
3811
|
-
const fallback = this.options.deadLetterWorkflow ? (0,
|
|
4248
|
+
const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core18.workflowName)(this.options.deadLetterWorkflow) : void 0;
|
|
3812
4249
|
if (byWorkflow.size === 0 && !fallback) return;
|
|
3813
4250
|
this.engine.onDead((run) => {
|
|
3814
|
-
|
|
3815
|
-
if (!target) return;
|
|
3816
|
-
void this.engine.start(
|
|
3817
|
-
target,
|
|
3818
|
-
{
|
|
3819
|
-
deadRunId: run.id,
|
|
3820
|
-
workflow: run.workflow,
|
|
3821
|
-
input: run.input,
|
|
3822
|
-
error: run.error
|
|
3823
|
-
},
|
|
3824
|
-
`dlq:${run.id}`,
|
|
3825
|
-
// Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
|
|
3826
|
-
// that tenant's worker group (`target@<tenant>`), not the bare group.
|
|
3827
|
-
{
|
|
3828
|
-
namespace: run.namespace
|
|
3829
|
-
}
|
|
3830
|
-
).catch(() => void 0);
|
|
4251
|
+
void this.routeDead(run, byWorkflow, fallback).catch(() => void 0);
|
|
3831
4252
|
});
|
|
3832
4253
|
}
|
|
4254
|
+
/** {@link installDeadLetterRouting}'s routing of one dead run. */
|
|
4255
|
+
async routeDead(run, byWorkflow, fallback) {
|
|
4256
|
+
let target = byWorkflow.get(run.workflow);
|
|
4257
|
+
if (!target && fallback) {
|
|
4258
|
+
if (await this.engine.announcedDeadLetter?.(run).catch(() => void 0)) return;
|
|
4259
|
+
target = fallback;
|
|
4260
|
+
}
|
|
4261
|
+
if (!target) return;
|
|
4262
|
+
await this.engine.start(
|
|
4263
|
+
target,
|
|
4264
|
+
{
|
|
4265
|
+
deadRunId: run.id,
|
|
4266
|
+
workflow: run.workflow,
|
|
4267
|
+
input: run.input,
|
|
4268
|
+
error: run.error
|
|
4269
|
+
},
|
|
4270
|
+
`dlq:${run.id}`,
|
|
4271
|
+
// Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
|
|
4272
|
+
// that tenant's worker group (`target@<tenant>`), not the bare group.
|
|
4273
|
+
{
|
|
4274
|
+
namespace: run.namespace
|
|
4275
|
+
}
|
|
4276
|
+
).catch(() => void 0);
|
|
4277
|
+
}
|
|
3833
4278
|
};
|
|
3834
4279
|
WorkflowRegistrar = _ts_decorate11([
|
|
3835
4280
|
(0, import_common11.Injectable)(),
|
|
3836
|
-
_ts_param8(3, (0, import_common11.Inject)(
|
|
3837
|
-
_ts_param8(4, (0, import_common11.Inject)(
|
|
4281
|
+
_ts_param8(3, (0, import_common11.Inject)(import_nestjs_durable_core18.STATE_STORE_CANONICAL)),
|
|
4282
|
+
_ts_param8(4, (0, import_common11.Inject)(import_nestjs_durable_core18.DURABLE_OPTIONS_CANONICAL)),
|
|
3838
4283
|
_ts_param8(5, (0, import_common11.Inject)(IN_APP_WORKER_BINDING)),
|
|
3839
4284
|
_ts_metadata11("design:type", Function),
|
|
3840
4285
|
_ts_metadata11("design:paramtypes", [
|
|
3841
4286
|
typeof import_core5.DiscoveryService === "undefined" ? Object : import_core5.DiscoveryService,
|
|
3842
4287
|
typeof import_core5.MetadataScanner === "undefined" ? Object : import_core5.MetadataScanner,
|
|
3843
|
-
typeof
|
|
4288
|
+
typeof import_nestjs_durable_core18.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core18.WorkflowEngine,
|
|
3844
4289
|
Object,
|
|
3845
4290
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
3846
4291
|
Object
|
|
@@ -3849,7 +4294,7 @@ WorkflowRegistrar = _ts_decorate11([
|
|
|
3849
4294
|
|
|
3850
4295
|
// src/workflow.service.ts
|
|
3851
4296
|
var import_node_crypto = require("crypto");
|
|
3852
|
-
var
|
|
4297
|
+
var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
3853
4298
|
var import_common12 = require("@nestjs/common");
|
|
3854
4299
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
3855
4300
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3940,7 +4385,7 @@ WorkflowService = _ts_decorate12([
|
|
|
3940
4385
|
(0, import_common12.Injectable)(),
|
|
3941
4386
|
_ts_metadata12("design:type", Function),
|
|
3942
4387
|
_ts_metadata12("design:paramtypes", [
|
|
3943
|
-
typeof
|
|
4388
|
+
typeof import_nestjs_durable_core19.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core19.WorkflowEngine
|
|
3944
4389
|
])
|
|
3945
4390
|
], WorkflowService);
|
|
3946
4391
|
|
|
@@ -4117,7 +4562,6 @@ function resolveTopologyPreset(options) {
|
|
|
4117
4562
|
};
|
|
4118
4563
|
}
|
|
4119
4564
|
__name(resolveTopologyPreset, "resolveTopologyPreset");
|
|
4120
|
-
var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
|
|
4121
4565
|
var RunGatewayBootstrap = class RunGatewayBootstrap2 {
|
|
4122
4566
|
static {
|
|
4123
4567
|
__name(this, "RunGatewayBootstrap");
|
|
@@ -4170,15 +4614,15 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
|
|
|
4170
4614
|
};
|
|
4171
4615
|
RunGatewayBootstrap = _ts_decorate13([
|
|
4172
4616
|
(0, import_common13.Injectable)(),
|
|
4173
|
-
_ts_param9(1, (0, import_common13.Inject)(
|
|
4174
|
-
_ts_param9(3, (0, import_common13.Inject)(
|
|
4175
|
-
_ts_param9(4, (0, import_common13.Inject)(
|
|
4617
|
+
_ts_param9(1, (0, import_common13.Inject)(import_nestjs_durable_core20.TRANSPORT_CANONICAL)),
|
|
4618
|
+
_ts_param9(3, (0, import_common13.Inject)(import_nestjs_durable_core20.STATE_STORE_CANONICAL)),
|
|
4619
|
+
_ts_param9(4, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
|
|
4176
4620
|
_ts_param9(5, (0, import_common13.Inject)(TENANT_AUTH)),
|
|
4177
4621
|
_ts_metadata13("design:type", Function),
|
|
4178
4622
|
_ts_metadata13("design:paramtypes", [
|
|
4179
|
-
typeof
|
|
4623
|
+
typeof import_nestjs_durable_core20.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core20.WorkflowEngine,
|
|
4180
4624
|
Object,
|
|
4181
|
-
typeof
|
|
4625
|
+
typeof import_nestjs_durable_core20.RunGateway === "undefined" ? Object : import_nestjs_durable_core20.RunGateway,
|
|
4182
4626
|
Object,
|
|
4183
4627
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
4184
4628
|
typeof ResolvedTenantAuth === "undefined" ? Object : ResolvedTenantAuth
|
|
@@ -4201,7 +4645,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
|
|
|
4201
4645
|
if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
|
|
4202
4646
|
const runtime = await resolveContextRuntime();
|
|
4203
4647
|
if (!canRestoreTenant(runtime)) return;
|
|
4204
|
-
this.unregister = (0,
|
|
4648
|
+
this.unregister = (0, import_nestjs_durable_core20.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
|
|
4205
4649
|
}
|
|
4206
4650
|
onModuleDestroy() {
|
|
4207
4651
|
this.unregister?.();
|
|
@@ -4209,7 +4653,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
|
|
|
4209
4653
|
};
|
|
4210
4654
|
DurableTenancyBridge = _ts_decorate13([
|
|
4211
4655
|
(0, import_common13.Injectable)(),
|
|
4212
|
-
_ts_param9(0, (0, import_common13.Inject)(
|
|
4656
|
+
_ts_param9(0, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
|
|
4213
4657
|
_ts_metadata13("design:type", Function),
|
|
4214
4658
|
_ts_metadata13("design:paramtypes", [
|
|
4215
4659
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
@@ -4221,17 +4665,17 @@ var DurableModule = class _DurableModule {
|
|
|
4221
4665
|
__name(this, "DurableModule");
|
|
4222
4666
|
}
|
|
4223
4667
|
static forRoot(options) {
|
|
4224
|
-
(0,
|
|
4668
|
+
(0, import_nestjs_durable_core20.sealDurableCopies)();
|
|
4225
4669
|
_DurableModule.assertValid(options);
|
|
4226
4670
|
return _DurableModule.build({
|
|
4227
|
-
provide:
|
|
4671
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4228
4672
|
useValue: resolveTopology(options)
|
|
4229
4673
|
});
|
|
4230
4674
|
}
|
|
4231
4675
|
static forRootAsync(options) {
|
|
4232
|
-
(0,
|
|
4676
|
+
(0, import_nestjs_durable_core20.sealDurableCopies)();
|
|
4233
4677
|
return _DurableModule.build({
|
|
4234
|
-
provide:
|
|
4678
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4235
4679
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
4236
4680
|
const resolved = await options.useFactory(...args);
|
|
4237
4681
|
_DurableModule.assertValid(resolved);
|
|
@@ -4254,21 +4698,21 @@ var DurableModule = class _DurableModule {
|
|
|
4254
4698
|
providers: [
|
|
4255
4699
|
optionsProvider,
|
|
4256
4700
|
{
|
|
4257
|
-
provide:
|
|
4701
|
+
provide: import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4258
4702
|
useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
|
|
4259
4703
|
inject: [
|
|
4260
|
-
|
|
4704
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4261
4705
|
]
|
|
4262
4706
|
},
|
|
4263
4707
|
{
|
|
4264
|
-
provide:
|
|
4708
|
+
provide: import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4265
4709
|
// With a POOL (`transports`) and no singular `transport`, the canonical transport is the
|
|
4266
4710
|
// pool's PRIMARY — the same one the engine dispatches on first. Leaving it null starved
|
|
4267
4711
|
// the step registrar / in-app worker of a transport, so a pool-configured operator
|
|
4268
4712
|
// registered NO step handlers and its own steps parked in `wait` with no consumer.
|
|
4269
4713
|
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
|
|
4270
4714
|
inject: [
|
|
4271
|
-
|
|
4715
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4272
4716
|
]
|
|
4273
4717
|
},
|
|
4274
4718
|
{
|
|
@@ -4278,36 +4722,53 @@ var DurableModule = class _DurableModule {
|
|
|
4278
4722
|
tenantToken: resolveTenantTokenSource(options.tenantToken, moduleRef)
|
|
4279
4723
|
}), "useFactory"),
|
|
4280
4724
|
inject: [
|
|
4281
|
-
|
|
4725
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4282
4726
|
import_core6.ModuleRef
|
|
4283
4727
|
]
|
|
4284
4728
|
},
|
|
4285
4729
|
// Deprecated tokens that published releases still import resolve to the same instances:
|
|
4286
4730
|
{
|
|
4287
|
-
provide:
|
|
4288
|
-
useExisting:
|
|
4731
|
+
provide: import_nestjs_durable_core20.STATE_STORE,
|
|
4732
|
+
useExisting: import_nestjs_durable_core20.STATE_STORE_CANONICAL
|
|
4289
4733
|
},
|
|
4290
4734
|
{
|
|
4291
|
-
provide:
|
|
4292
|
-
useExisting:
|
|
4735
|
+
provide: import_nestjs_durable_core20.TRANSPORT,
|
|
4736
|
+
useExisting: import_nestjs_durable_core20.TRANSPORT_CANONICAL
|
|
4293
4737
|
},
|
|
4294
4738
|
{
|
|
4295
|
-
provide:
|
|
4296
|
-
useExisting:
|
|
4739
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS,
|
|
4740
|
+
useExisting: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4297
4741
|
},
|
|
4298
4742
|
{
|
|
4299
4743
|
// Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
|
|
4300
4744
|
// `DurableStartClient` facade for a thin worker (no `store`) — either way, `WorkflowService`
|
|
4301
4745
|
// and app code call `engine.start(...)` unchanged.
|
|
4302
|
-
provide:
|
|
4746
|
+
provide: import_nestjs_durable_core20.WorkflowEngine,
|
|
4303
4747
|
useFactory: /* @__PURE__ */ __name(async (options, store, transport, moduleRef, auth) => {
|
|
4304
4748
|
if (options.store === void 0) {
|
|
4305
|
-
return new DurableStartClient(
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4749
|
+
return new DurableStartClient(
|
|
4750
|
+
{
|
|
4751
|
+
...options,
|
|
4752
|
+
...auth.tenantToken !== void 0 ? {
|
|
4753
|
+
tenantToken: auth.tenantToken
|
|
4754
|
+
} : {}
|
|
4755
|
+
},
|
|
4756
|
+
void 0,
|
|
4757
|
+
resolveAccessor(moduleRef),
|
|
4758
|
+
// `signal`/`signalWithStart`/`publishEvent` go to the control plane as run requests,
|
|
4759
|
+
// over the one `ProxyRunGateway` bound under `RunGateway` (it owns the reply
|
|
4760
|
+
// subscription). Resolved lazily: that gateway is built after this facade.
|
|
4761
|
+
() => {
|
|
4762
|
+
try {
|
|
4763
|
+
const gateway = moduleRef.get(import_nestjs_durable_core20.RunGateway, {
|
|
4764
|
+
strict: false
|
|
4765
|
+
});
|
|
4766
|
+
return gateway instanceof ProxyRunGateway ? gateway : void 0;
|
|
4767
|
+
} catch {
|
|
4768
|
+
return void 0;
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
);
|
|
4311
4772
|
}
|
|
4312
4773
|
if (!store) {
|
|
4313
4774
|
throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
|
|
@@ -4326,7 +4787,7 @@ var DurableModule = class _DurableModule {
|
|
|
4326
4787
|
if (t) deferTransportConsumers(t);
|
|
4327
4788
|
}
|
|
4328
4789
|
}
|
|
4329
|
-
const engine = new
|
|
4790
|
+
const engine = new import_nestjs_durable_core20.WorkflowEngine({
|
|
4330
4791
|
store,
|
|
4331
4792
|
transport: transport ?? void 0,
|
|
4332
4793
|
transports: options.transports,
|
|
@@ -4375,9 +4836,9 @@ var DurableModule = class _DurableModule {
|
|
|
4375
4836
|
return engine;
|
|
4376
4837
|
}, "useFactory"),
|
|
4377
4838
|
inject: [
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4839
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4840
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4841
|
+
import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4381
4842
|
import_core6.ModuleRef,
|
|
4382
4843
|
TENANT_AUTH
|
|
4383
4844
|
]
|
|
@@ -4393,7 +4854,7 @@ var DurableModule = class _DurableModule {
|
|
|
4393
4854
|
// or (for a thin worker, no `store`) a `ProxyRunGateway` over `transport` when given, else a
|
|
4394
4855
|
// gateway whose every method rejects with a clear tenant error.
|
|
4395
4856
|
{
|
|
4396
|
-
provide:
|
|
4857
|
+
provide: import_nestjs_durable_core20.RunGateway,
|
|
4397
4858
|
useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
|
|
4398
4859
|
if (options.store !== void 0) {
|
|
4399
4860
|
if (!store) {
|
|
@@ -4404,9 +4865,9 @@ var DurableModule = class _DurableModule {
|
|
|
4404
4865
|
return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, auth.tenantToken, options.tenancy === false ? void 0 : () => tenantFilterNow(options.tenancy, resolveAccessor(moduleRef))) : unavailableRunGateway();
|
|
4405
4866
|
}, "useFactory"),
|
|
4406
4867
|
inject: [
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4868
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4869
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4870
|
+
import_nestjs_durable_core20.WorkflowEngine,
|
|
4410
4871
|
TENANT_AUTH,
|
|
4411
4872
|
import_core6.ModuleRef
|
|
4412
4873
|
]
|
|
@@ -4423,13 +4884,13 @@ var DurableModule = class _DurableModule {
|
|
|
4423
4884
|
exports: [
|
|
4424
4885
|
WorkflowService,
|
|
4425
4886
|
EntityService,
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4887
|
+
import_nestjs_durable_core20.WorkflowEngine,
|
|
4888
|
+
import_nestjs_durable_core20.STATE_STORE,
|
|
4889
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4890
|
+
import_nestjs_durable_core20.TRANSPORT,
|
|
4891
|
+
import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4892
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4893
|
+
import_nestjs_durable_core20.RunGateway
|
|
4433
4894
|
]
|
|
4434
4895
|
};
|
|
4435
4896
|
}
|
|
@@ -4439,7 +4900,7 @@ DurableModule = _ts_decorate13([
|
|
|
4439
4900
|
], DurableModule);
|
|
4440
4901
|
|
|
4441
4902
|
// src/federated-app-gateway.ts
|
|
4442
|
-
var
|
|
4903
|
+
var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
|
|
4443
4904
|
var FederatedAppGateway = class {
|
|
4444
4905
|
static {
|
|
4445
4906
|
__name(this, "FederatedAppGateway");
|
|
@@ -4454,7 +4915,7 @@ var FederatedAppGateway = class {
|
|
|
4454
4915
|
tailing = false;
|
|
4455
4916
|
constructor(options) {
|
|
4456
4917
|
this.options = options;
|
|
4457
|
-
this.reads = new StoreRunGateway(options.store, new
|
|
4918
|
+
this.reads = new StoreRunGateway(options.store, new import_nestjs_durable_core21.WorkflowEngine({
|
|
4458
4919
|
store: options.store
|
|
4459
4920
|
}));
|
|
4460
4921
|
this.timeoutMs = options.timeoutMs ?? 1e4;
|
|
@@ -4699,7 +5160,7 @@ function federatedAppGateway(options) {
|
|
|
4699
5160
|
__name(federatedAppGateway, "federatedAppGateway");
|
|
4700
5161
|
|
|
4701
5162
|
// src/index.ts
|
|
4702
|
-
var
|
|
5163
|
+
var import_nestjs_durable_core22 = require("@dudousxd/nestjs-durable-core");
|
|
4703
5164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4704
5165
|
0 && (module.exports = {
|
|
4705
5166
|
BAD_RUN_REQUEST,
|
|
@@ -4741,6 +5202,7 @@ var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
|
|
|
4741
5202
|
Step,
|
|
4742
5203
|
StepInterceptor,
|
|
4743
5204
|
StoreRunGateway,
|
|
5205
|
+
TENANT_AUTH,
|
|
4744
5206
|
TENANT_REPUBLISH_MAX_LIMIT,
|
|
4745
5207
|
TenantEventRepublisher,
|
|
4746
5208
|
ThinStepRegistrar,
|
|
@@ -4776,6 +5238,7 @@ var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
|
|
|
4776
5238
|
scheduleRunIdAt,
|
|
4777
5239
|
scheduledRunId,
|
|
4778
5240
|
signTenantToken,
|
|
5241
|
+
tenantScheduleAnnouncement,
|
|
4779
5242
|
thinWorkerProviders,
|
|
4780
5243
|
triggeredRunsOf,
|
|
4781
5244
|
unavailableRunGateway
|