@dudousxd/nestjs-durable 0.64.0 → 0.66.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 +752 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +216 -23
- package/dist/index.d.ts +216 -23
- package/dist/index.js +605 -212
- 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,7 +63,7 @@ __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,
|
|
@@ -79,7 +79,7 @@ __export(src_exports, {
|
|
|
79
79
|
UNSUPPORTED_RUN_REQUEST: () => UNSUPPORTED_RUN_REQUEST,
|
|
80
80
|
WORKFLOW_METADATA: () => WORKFLOW_METADATA,
|
|
81
81
|
Workflow: () => Workflow,
|
|
82
|
-
WorkflowEngine: () =>
|
|
82
|
+
WorkflowEngine: () => import_nestjs_durable_core22.WorkflowEngine,
|
|
83
83
|
WorkflowService: () => WorkflowService,
|
|
84
84
|
attributesOf: () => attributesOf,
|
|
85
85
|
entityConfigFor: () => entityConfigFor,
|
|
@@ -89,26 +89,26 @@ __export(src_exports, {
|
|
|
89
89
|
getEntityMeta: () => getEntityMeta,
|
|
90
90
|
getOnEvents: () => getOnEvents,
|
|
91
91
|
getWorkflowMeta: () => getWorkflowMeta,
|
|
92
|
-
hmacTenantVerifier: () =>
|
|
92
|
+
hmacTenantVerifier: () => import_nestjs_durable_core22.hmacTenantVerifier,
|
|
93
93
|
inAppWorkerProviders: () => inAppWorkerProviders,
|
|
94
94
|
isDeadLetterHandler: () => isDeadLetterHandler,
|
|
95
95
|
isDrivingOperator: () => isDrivingOperator,
|
|
96
96
|
isOperatorRole: () => isOperatorRole,
|
|
97
97
|
isStepInterceptor: () => isStepInterceptor,
|
|
98
|
-
lifecycleRunId: () =>
|
|
99
|
-
lifecycleSourceOf: () =>
|
|
98
|
+
lifecycleRunId: () => import_nestjs_durable_core22.lifecycleRunId,
|
|
99
|
+
lifecycleSourceOf: () => import_nestjs_durable_core22.lifecycleSourceOf,
|
|
100
100
|
onErrorCodesOf: () => onErrorCodesOf,
|
|
101
|
-
prevCronFireMs: () =>
|
|
102
|
-
readSearchAttributes: () =>
|
|
103
|
-
runCompletedEvent: () =>
|
|
104
|
-
runFailedEvent: () =>
|
|
105
|
-
runSchedules: () =>
|
|
106
|
-
scheduleRunIdAt: () =>
|
|
107
|
-
scheduledRunId: () =>
|
|
108
|
-
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
109
|
tenantScheduleAnnouncement: () => tenantScheduleAnnouncement,
|
|
110
110
|
thinWorkerProviders: () => thinWorkerProviders,
|
|
111
|
-
triggeredRunsOf: () =>
|
|
111
|
+
triggeredRunsOf: () => import_nestjs_durable_core22.triggeredRunsOf,
|
|
112
112
|
unavailableRunGateway: () => unavailableRunGateway
|
|
113
113
|
});
|
|
114
114
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -239,6 +239,8 @@ function Workflow(options) {
|
|
|
239
239
|
deadLetterWorkflow: options.deadLetterWorkflow,
|
|
240
240
|
onError: options.onError,
|
|
241
241
|
tags: options.tags,
|
|
242
|
+
// The typed callbacks are stored erased: the engine calls them with the parsed input, which is
|
|
243
|
+
// exactly the type `S` gave them (see `workflowIo`).
|
|
242
244
|
singleton: options.singleton,
|
|
243
245
|
concurrency: options.concurrency,
|
|
244
246
|
executionTimeout: options.executionTimeout,
|
|
@@ -811,95 +813,217 @@ var DurableStartClient = class {
|
|
|
811
813
|
options;
|
|
812
814
|
deps;
|
|
813
815
|
accessor;
|
|
816
|
+
requests;
|
|
814
817
|
tenant;
|
|
815
818
|
tenantToken;
|
|
816
|
-
|
|
819
|
+
policies = /* @__PURE__ */ new Map();
|
|
820
|
+
warnedCoalescing = /* @__PURE__ */ new Set();
|
|
821
|
+
constructor(options, deps, accessor, requests) {
|
|
817
822
|
this.options = options;
|
|
818
823
|
this.deps = deps;
|
|
819
824
|
this.accessor = accessor;
|
|
825
|
+
this.requests = requests;
|
|
820
826
|
this.tenant = options.partition ?? "default";
|
|
821
827
|
this.tenantToken = resolveTenantTokenSource(options.tenantToken);
|
|
822
828
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
829
|
+
/**
|
|
830
|
+
* Apply `policy` to every start of `workflow` from this process (see
|
|
831
|
+
* {@link TenantWorkflowStartPolicy}). Called by `ThinWorkflowRegistrar` at boot.
|
|
832
|
+
*/
|
|
833
|
+
declareWorkflow(workflow, policy) {
|
|
834
|
+
this.policies.set(workflow, policy);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
838
|
+
* evaluates the singleton key and the default quota against the parsed input. A per-start `concurrency` wins over the
|
|
839
|
+
* workflow's.
|
|
840
|
+
*/
|
|
841
|
+
async applyPolicy(workflow, input, opts) {
|
|
842
|
+
const policy = this.policies.get(workflow);
|
|
843
|
+
if (!policy) return opts?.concurrency !== void 0 ? {
|
|
844
|
+
concurrency: opts.concurrency
|
|
845
|
+
} : {};
|
|
846
|
+
const keyInput = policy.parseInput ? await policy.parseInput(input) : input;
|
|
847
|
+
await policy.validateInput?.(keyInput);
|
|
848
|
+
const concurrency = await (0, import_nestjs_durable_core3.resolveConcurrency)(opts?.concurrency, policy.concurrency, keyInput);
|
|
849
|
+
const singleton = policy.singleton ? {
|
|
850
|
+
key: policy.singleton.key(keyInput),
|
|
851
|
+
...policy.singleton.limit !== void 0 ? {
|
|
852
|
+
limit: policy.singleton.limit
|
|
853
|
+
} : {},
|
|
854
|
+
...policy.singleton.maxQueueDepth !== void 0 ? {
|
|
855
|
+
maxQueueDepth: policy.singleton.maxQueueDepth
|
|
856
|
+
} : {}
|
|
857
|
+
} : void 0;
|
|
858
|
+
return {
|
|
859
|
+
...singleton ? {
|
|
860
|
+
singleton
|
|
861
|
+
} : {},
|
|
862
|
+
...concurrency ? {
|
|
863
|
+
concurrency
|
|
864
|
+
} : {}
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
/** The wire `tenant`: the signed token when configured, else the partition. */
|
|
868
|
+
async wireTenant() {
|
|
869
|
+
return this.tenantToken !== void 0 ? await (0, import_nestjs_durable_core3.resolveTenantToken)(this.tenantToken) : this.tenant;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* The customer tenant a start claims: an explicit `tenantId` (`null` = none), else the request's
|
|
873
|
+
* tenant when tenancy is on.
|
|
874
|
+
*/
|
|
875
|
+
claimedTenant(opts) {
|
|
876
|
+
return opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
|
|
826
877
|
id: opts.tenantId,
|
|
827
|
-
|
|
878
|
+
...opts.tenantKind !== void 0 ? {
|
|
879
|
+
kind: opts.tenantKind
|
|
880
|
+
} : {}
|
|
828
881
|
} : currentTenant(this.options.tenancy, this.accessor);
|
|
882
|
+
}
|
|
883
|
+
async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
|
|
884
|
+
const message = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
|
|
829
885
|
await startRun(this.options.connection, {
|
|
830
886
|
// The signed token (when configured) rides in the `tenant` field, as on every run request; an
|
|
831
887
|
// operator with `verifyTenant` derives the run's namespace from it.
|
|
832
|
-
tenant:
|
|
833
|
-
|
|
834
|
-
input,
|
|
835
|
-
runId,
|
|
888
|
+
tenant: await this.wireTenant(),
|
|
889
|
+
...message,
|
|
836
890
|
// Option B: DO NOT pass `namespace` — the start-run queue stays the shared
|
|
837
891
|
// `durable-start-run` the operator consumes; tenant rides only as message data.
|
|
838
892
|
...this.options.prefix !== void 0 ? {
|
|
839
893
|
prefix: this.options.prefix
|
|
840
894
|
} : {},
|
|
895
|
+
...this.deps !== void 0 ? {
|
|
896
|
+
deps: this.deps
|
|
897
|
+
} : {}
|
|
898
|
+
});
|
|
899
|
+
const startAtMs = message.startAt;
|
|
900
|
+
return {
|
|
901
|
+
runId,
|
|
902
|
+
status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* The start-run a start of `name` sends (everything but the wire `tenant`): the start options the
|
|
907
|
+
* control plane applies (version pin, priority, delayed start, quota), the singleton key and the
|
|
908
|
+
* customer tenant this run claims. Applies the workflow's declared policy first, so a rejected
|
|
909
|
+
* input throws before anything is published, as `engine.start` does.
|
|
910
|
+
*/
|
|
911
|
+
async startMessage(name, input, runId, opts) {
|
|
912
|
+
const tenant = this.claimedTenant(opts);
|
|
913
|
+
const policy = await this.applyPolicy(name, input, opts);
|
|
914
|
+
const startAt = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
|
|
915
|
+
return {
|
|
916
|
+
workflow: name,
|
|
917
|
+
input,
|
|
918
|
+
runId,
|
|
841
919
|
...opts?.tags !== void 0 ? {
|
|
842
920
|
tags: opts.tags
|
|
843
921
|
} : {},
|
|
844
922
|
...opts?.searchAttributes !== void 0 ? {
|
|
845
923
|
searchAttributes: opts.searchAttributes
|
|
846
924
|
} : {},
|
|
847
|
-
// The start options the control plane applies (version pin, priority, delayed start, quota).
|
|
848
925
|
...opts?.version !== void 0 ? {
|
|
849
926
|
version: opts.version
|
|
850
927
|
} : {},
|
|
851
928
|
...opts?.priority !== void 0 ? {
|
|
852
929
|
priority: opts.priority
|
|
853
930
|
} : {},
|
|
854
|
-
...
|
|
855
|
-
startAt
|
|
931
|
+
...startAt !== void 0 ? {
|
|
932
|
+
startAt
|
|
856
933
|
} : {},
|
|
857
|
-
...
|
|
858
|
-
concurrency:
|
|
934
|
+
...policy.concurrency !== void 0 ? {
|
|
935
|
+
concurrency: policy.concurrency
|
|
936
|
+
} : {},
|
|
937
|
+
...policy.singleton !== void 0 ? {
|
|
938
|
+
singleton: policy.singleton
|
|
859
939
|
} : {},
|
|
860
940
|
...tenant ? {
|
|
861
941
|
tenantId: tenant.id,
|
|
862
942
|
...tenant.kind !== void 0 ? {
|
|
863
943
|
tenantKind: tenant.kind
|
|
864
944
|
} : {}
|
|
865
|
-
} : {},
|
|
866
|
-
...this.deps !== void 0 ? {
|
|
867
|
-
deps: this.deps
|
|
868
945
|
} : {}
|
|
869
|
-
}
|
|
870
|
-
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
/** The control plane's run requests, or a clear error naming what is missing. */
|
|
949
|
+
runRequests(method) {
|
|
950
|
+
const requests = this.requests?.();
|
|
951
|
+
if (!requests) {
|
|
952
|
+
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).`);
|
|
953
|
+
}
|
|
954
|
+
return requests;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Signal the run of this tenant's partition waiting on `token`, through the control plane.
|
|
958
|
+
* Resolves the resumed run, or null when no run of this partition waits on it: unlike
|
|
959
|
+
* `engine.signal` on a control plane, a tenant's signal is NOT buffered for a wait opened later
|
|
960
|
+
* (another partition's run could open it). Use `signalWithStart` to signal a run that may not wait
|
|
961
|
+
* yet. `opts.id` deduplicates like `engine.signal`.
|
|
962
|
+
*/
|
|
963
|
+
async signal(token, payload, opts) {
|
|
964
|
+
return this.runRequests("signal").signal(token, payload, opts);
|
|
965
|
+
}
|
|
966
|
+
async signalWithStart(workflow, input, runId, signal, opts) {
|
|
967
|
+
const requests = this.runRequests("signalWithStart");
|
|
968
|
+
const start = await this.startMessage((0, import_nestjs_durable_core3.workflowName)(workflow), input, runId, opts);
|
|
969
|
+
const result = await requests.signalWithStart(start, signal);
|
|
871
970
|
return {
|
|
872
|
-
runId
|
|
873
|
-
status: startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > Date.now() ? "suspended" : "pending"
|
|
971
|
+
runId: result.runId
|
|
874
972
|
};
|
|
875
973
|
}
|
|
974
|
+
/**
|
|
975
|
+
* Publish event `name` from this tenant. Starts this app's own `onEvent` subscribers (each one
|
|
976
|
+
* whose `where` accepts the payload, with its `input` mapping) as runs of this partition, by the
|
|
977
|
+
* start path ({@link start}, run id `evt:<id>:<workflow>`), and has the control plane resume the
|
|
978
|
+
* runs of this partition waiting on it (`ctx.waitForEvent`). Resolves how many runs it started or
|
|
979
|
+
* resumed; a subscriber that throws is warned about and skipped. Unlike a control plane's
|
|
980
|
+
* `publishEvent`, an event nobody received is not buffered (there is no `buffer` option), and
|
|
981
|
+
* a subscriber's `debounce`/`batch` is not applied (it starts once per event, with a warning).
|
|
982
|
+
*/
|
|
983
|
+
async publishEvent(name, payload, opts) {
|
|
984
|
+
const requests = this.runRequests("publishEvent");
|
|
985
|
+
const eventId = opts?.id ?? globalThis.crypto.randomUUID();
|
|
986
|
+
let started = 0;
|
|
987
|
+
for (const [workflow, policy] of this.policies) {
|
|
988
|
+
try {
|
|
989
|
+
const subscriptions = (policy.onEvent ?? []).map(import_nestjs_durable_core3.toEventSubscription).filter((sub) => sub.event === name);
|
|
990
|
+
const { accepted, errors } = (0, import_nestjs_durable_core3.acceptingSubscription)(subscriptions, payload);
|
|
991
|
+
if (!accepted) {
|
|
992
|
+
if (errors.length > 0) throw errors[0];
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (policy.coalesces && !this.warnedCoalescing.has(workflow)) {
|
|
996
|
+
this.warnedCoalescing.add(workflow);
|
|
997
|
+
console.warn(`[nestjs-durable] ${workflow} debounces/batches its events, which a tenant's publishEvent does not apply: it starts once per event.`);
|
|
998
|
+
}
|
|
999
|
+
const input = accepted.input ? accepted.input(payload) : payload;
|
|
1000
|
+
await this.start(workflow, input, `evt:${eventId}:${workflow}`);
|
|
1001
|
+
started += 1;
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
console.warn(`[nestjs-durable] event ${name}: subscriber ${workflow} not started:`, error);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const resumed = await requests.publishEvent(name, payload, {
|
|
1007
|
+
id: eventId
|
|
1008
|
+
});
|
|
1009
|
+
return started + resumed;
|
|
1010
|
+
}
|
|
876
1011
|
cancel(_runId) {
|
|
877
1012
|
return tenantUnsupported("cancel");
|
|
878
1013
|
}
|
|
879
1014
|
deleteRun(_runId) {
|
|
880
1015
|
return tenantUnsupported("deleteRun");
|
|
881
1016
|
}
|
|
882
|
-
// — everything below rejects: a tenant worker holds no store/driver
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// of a cryptic `this.engine.X is not a function` — the facade is honest about what it cannot do.
|
|
887
|
-
// Params mirror the WorkflowEngine surface being faced; every method rejects without reading them.
|
|
1017
|
+
// — everything below rejects: a tenant worker holds no store/driver. —
|
|
1018
|
+
// `resume`/`waitForRun` need the store or driver a tenant does not have. They exist so a mistaken
|
|
1019
|
+
// call fails with a CLEAR, named tenant error instead of a cryptic `this.engine.X is not a
|
|
1020
|
+
// function`. Params mirror the WorkflowEngine surface; every method rejects without reading them.
|
|
888
1021
|
resume(_runId) {
|
|
889
1022
|
return tenantUnsupported("resume");
|
|
890
1023
|
}
|
|
891
1024
|
waitForRun(_runId, _opts) {
|
|
892
1025
|
return tenantUnsupported("waitForRun");
|
|
893
1026
|
}
|
|
894
|
-
signal(_token, _payload) {
|
|
895
|
-
return tenantUnsupported("signal");
|
|
896
|
-
}
|
|
897
|
-
signalWithStart(_workflow, _input, _runId, _signal, _opts) {
|
|
898
|
-
return tenantUnsupported("signalWithStart");
|
|
899
|
-
}
|
|
900
|
-
publishEvent(_name, _payload, _opts) {
|
|
901
|
-
return tenantUnsupported("publishEvent");
|
|
902
|
-
}
|
|
903
1027
|
};
|
|
904
1028
|
DurableStartClient = _ts_decorate([
|
|
905
1029
|
(0, import_common.Injectable)(),
|
|
@@ -907,7 +1031,8 @@ DurableStartClient = _ts_decorate([
|
|
|
907
1031
|
_ts_metadata("design:paramtypes", [
|
|
908
1032
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
909
1033
|
typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
|
|
910
|
-
typeof ContextAccessor === "undefined" ? Object : ContextAccessor
|
|
1034
|
+
typeof ContextAccessor === "undefined" ? Object : ContextAccessor,
|
|
1035
|
+
Function
|
|
911
1036
|
])
|
|
912
1037
|
], DurableStartClient);
|
|
913
1038
|
function tenantUnsupported(method) {
|
|
@@ -916,8 +1041,8 @@ function tenantUnsupported(method) {
|
|
|
916
1041
|
__name(tenantUnsupported, "tenantUnsupported");
|
|
917
1042
|
|
|
918
1043
|
// src/durable-worker.module.ts
|
|
919
|
-
var
|
|
920
|
-
var
|
|
1044
|
+
var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
|
|
1045
|
+
var import_common3 = require("@nestjs/common");
|
|
921
1046
|
var import_core = require("@nestjs/core");
|
|
922
1047
|
|
|
923
1048
|
// src/schema-parse.ts
|
|
@@ -1028,8 +1153,99 @@ function scanSteps(discovery, scanner, register) {
|
|
|
1028
1153
|
}
|
|
1029
1154
|
__name(scanSteps, "scanSteps");
|
|
1030
1155
|
|
|
1031
|
-
// src/
|
|
1156
|
+
// src/entity.ts
|
|
1032
1157
|
var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
|
|
1158
|
+
var import_common2 = require("@nestjs/common");
|
|
1159
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
1160
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1161
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1162
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1163
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1164
|
+
} else {
|
|
1165
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1166
|
+
if (d = decorators[i]) {
|
|
1167
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1172
|
+
}
|
|
1173
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1174
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
1175
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1176
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
1180
|
+
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
1181
|
+
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
1182
|
+
function Entity(options) {
|
|
1183
|
+
return (target) => {
|
|
1184
|
+
Reflect.defineMetadata(ENTITY_METADATA, options, target);
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
__name(Entity, "Entity");
|
|
1188
|
+
function On(op) {
|
|
1189
|
+
return (target, propertyKey) => {
|
|
1190
|
+
const ctor = target.constructor;
|
|
1191
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1192
|
+
ops.set(op, propertyKey);
|
|
1193
|
+
Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
__name(On, "On");
|
|
1197
|
+
function getEntityMeta(target) {
|
|
1198
|
+
return Reflect.getMetadata(ENTITY_METADATA, target);
|
|
1199
|
+
}
|
|
1200
|
+
__name(getEntityMeta, "getEntityMeta");
|
|
1201
|
+
function entityConfigFor(ctor) {
|
|
1202
|
+
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1203
|
+
const Cls = ctor;
|
|
1204
|
+
const handlers = {};
|
|
1205
|
+
for (const [op, method] of ops) {
|
|
1206
|
+
handlers[op] = (state, arg) => {
|
|
1207
|
+
Object.setPrototypeOf(state, Cls.prototype);
|
|
1208
|
+
const fn = state[method];
|
|
1209
|
+
if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
|
|
1210
|
+
return fn.call(state, arg);
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
return {
|
|
1214
|
+
initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
|
|
1215
|
+
handlers
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
__name(entityConfigFor, "entityConfigFor");
|
|
1219
|
+
var EntityService = class {
|
|
1220
|
+
static {
|
|
1221
|
+
__name(this, "EntityService");
|
|
1222
|
+
}
|
|
1223
|
+
engine;
|
|
1224
|
+
constructor(engine) {
|
|
1225
|
+
this.engine = engine;
|
|
1226
|
+
}
|
|
1227
|
+
/** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
|
|
1228
|
+
signal(name, key, op, arg) {
|
|
1229
|
+
return this.engine.signalEntity(name, key, op, arg);
|
|
1230
|
+
}
|
|
1231
|
+
/** Read an entity's current durable state (or undefined if it has none yet). */
|
|
1232
|
+
getState(name, key) {
|
|
1233
|
+
return this.engine.getEntityState(name, key);
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
EntityService = _ts_decorate2([
|
|
1237
|
+
(0, import_common2.Injectable)(),
|
|
1238
|
+
_ts_metadata2("design:type", Function),
|
|
1239
|
+
_ts_metadata2("design:paramtypes", [
|
|
1240
|
+
typeof import_nestjs_durable_core5.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core5.WorkflowEngine
|
|
1241
|
+
])
|
|
1242
|
+
], EntityService);
|
|
1243
|
+
|
|
1244
|
+
// src/runtime-registration.ts
|
|
1245
|
+
var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
|
|
1246
|
+
|
|
1247
|
+
// src/on-error-handlers.ts
|
|
1248
|
+
var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
|
|
1033
1249
|
function onErrorHandlersOf(meta, instance, scanner) {
|
|
1034
1250
|
const handlers = [];
|
|
1035
1251
|
const routes = [];
|
|
@@ -1050,7 +1266,7 @@ function onErrorHandlersOf(meta, instance, scanner) {
|
|
|
1050
1266
|
for (const r of meta.onError ?? []) {
|
|
1051
1267
|
routes.push({
|
|
1052
1268
|
code: r.code === void 0 || typeof r.code === "string" ? r.code : r.code.code,
|
|
1053
|
-
workflow: (0,
|
|
1269
|
+
workflow: (0, import_nestjs_durable_core6.workflowName)(r.workflow)
|
|
1054
1270
|
});
|
|
1055
1271
|
}
|
|
1056
1272
|
return {
|
|
@@ -1066,10 +1282,8 @@ function workflowIo(meta) {
|
|
|
1066
1282
|
const parseOutput = meta.output && schemaParser(meta.output, "output", `workflow "${meta.name}" output`);
|
|
1067
1283
|
const validateInput = meta.validateInput;
|
|
1068
1284
|
return {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
await validateInput?.(parsed);
|
|
1072
|
-
} : void 0,
|
|
1285
|
+
parseInput: parseInput || void 0,
|
|
1286
|
+
validateParsed: validateInput,
|
|
1073
1287
|
wrap: /* @__PURE__ */ __name((body) => !parseInput && !parseOutput ? body : async (ctx, input) => {
|
|
1074
1288
|
const output = await body(ctx, parseInput ? await parseInput(input) : input);
|
|
1075
1289
|
return parseOutput ? parseOutput(output) : output;
|
|
@@ -1079,7 +1293,7 @@ function workflowIo(meta) {
|
|
|
1079
1293
|
__name(workflowIo, "workflowIo");
|
|
1080
1294
|
|
|
1081
1295
|
// src/runtime-registration.ts
|
|
1082
|
-
function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
1296
|
+
function registerOnRuntime(runtime, scanner, meta, instance, origin, deadLetter) {
|
|
1083
1297
|
const { handlers, routes } = onErrorHandlersOf(meta, instance, scanner);
|
|
1084
1298
|
const announced = {
|
|
1085
1299
|
version: meta.version,
|
|
@@ -1107,20 +1321,61 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
|
|
|
1107
1321
|
} : {},
|
|
1108
1322
|
...subscribes.length > 0 ? {
|
|
1109
1323
|
subscribes
|
|
1324
|
+
} : {},
|
|
1325
|
+
...announcedOptions(meta),
|
|
1326
|
+
...deadLetter !== void 0 ? {
|
|
1327
|
+
deadLetter
|
|
1110
1328
|
} : {}
|
|
1111
1329
|
});
|
|
1112
1330
|
for (const [name, fn] of handlers) runtime.registerWorkflow(name, fn, announced);
|
|
1113
1331
|
}
|
|
1114
1332
|
__name(registerOnRuntime, "registerOnRuntime");
|
|
1333
|
+
function announcedOptions(meta) {
|
|
1334
|
+
const options = {};
|
|
1335
|
+
if (meta.tags !== void 0 && meta.tags.length > 0) options.tags = [
|
|
1336
|
+
...meta.tags
|
|
1337
|
+
];
|
|
1338
|
+
if (meta.executionTimeout !== void 0) {
|
|
1339
|
+
options.executionTimeoutMs = (0, import_nestjs_durable_core7.parseDuration)(meta.executionTimeout);
|
|
1340
|
+
}
|
|
1341
|
+
if (meta.singleton !== void 0) {
|
|
1342
|
+
options.singleton = {
|
|
1343
|
+
...meta.singleton.limit !== void 0 ? {
|
|
1344
|
+
limit: meta.singleton.limit
|
|
1345
|
+
} : {},
|
|
1346
|
+
...meta.singleton.maxQueueDepth !== void 0 ? {
|
|
1347
|
+
maxQueueDepth: meta.singleton.maxQueueDepth
|
|
1348
|
+
} : {}
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
return Object.keys(options).length > 0 ? {
|
|
1352
|
+
options
|
|
1353
|
+
} : {};
|
|
1354
|
+
}
|
|
1355
|
+
__name(announcedOptions, "announcedOptions");
|
|
1356
|
+
|
|
1357
|
+
// src/step-interceptor.ts
|
|
1358
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
1359
|
+
var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
|
|
1360
|
+
function StepInterceptor() {
|
|
1361
|
+
return (target) => {
|
|
1362
|
+
Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
__name(StepInterceptor, "StepInterceptor");
|
|
1366
|
+
function isStepInterceptor(target) {
|
|
1367
|
+
return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
|
|
1368
|
+
}
|
|
1369
|
+
__name(isStepInterceptor, "isStepInterceptor");
|
|
1115
1370
|
|
|
1116
1371
|
// src/tokens.ts
|
|
1117
|
-
var
|
|
1372
|
+
var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
|
|
1118
1373
|
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
1119
1374
|
var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
|
|
1120
|
-
var RUN_GATEWAY =
|
|
1375
|
+
var RUN_GATEWAY = import_nestjs_durable_core8.RunGateway;
|
|
1121
1376
|
|
|
1122
1377
|
// src/durable-worker.module.ts
|
|
1123
|
-
function
|
|
1378
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1124
1379
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1125
1380
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1126
1381
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1133,19 +1388,29 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
1133
1388
|
}
|
|
1134
1389
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1135
1390
|
}
|
|
1136
|
-
__name(
|
|
1137
|
-
function
|
|
1391
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1392
|
+
function _ts_metadata3(metadataKey, metadataValue) {
|
|
1138
1393
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1139
1394
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1140
1395
|
}
|
|
1141
1396
|
}
|
|
1142
|
-
__name(
|
|
1397
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
1143
1398
|
function _ts_param(paramIndex, decorator) {
|
|
1144
1399
|
return function(target, key) {
|
|
1145
1400
|
decorator(target, key, paramIndex);
|
|
1146
1401
|
};
|
|
1147
1402
|
}
|
|
1148
1403
|
__name(_ts_param, "_ts_param");
|
|
1404
|
+
function deadLetterHandlerOf(instance, scanner) {
|
|
1405
|
+
for (const name of scanner.getAllMethodNames(Object.getPrototypeOf(instance))) {
|
|
1406
|
+
const method = instance[name];
|
|
1407
|
+
if (typeof method === "function" && isDeadLetterHandler(method)) {
|
|
1408
|
+
return (ctx, input) => method.call(instance, ctx, input);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return void 0;
|
|
1412
|
+
}
|
|
1413
|
+
__name(deadLetterHandlerOf, "deadLetterHandlerOf");
|
|
1149
1414
|
var RUN_REDIS_WORKER = Symbol("nestjs-durable:run-redis-worker");
|
|
1150
1415
|
var DURABLE_WORKER_RUNTIME = Symbol("nestjs-durable:worker-runtime");
|
|
1151
1416
|
var DURABLE_WORKER_RUNNERS = Symbol("nestjs-durable:worker-runners");
|
|
@@ -1173,21 +1438,80 @@ var ThinWorkflowRegistrar = class {
|
|
|
1173
1438
|
const runtime = this.runtime;
|
|
1174
1439
|
if (runtime === null || !isPureThinWorker(this.options)) return;
|
|
1175
1440
|
const starter = this.starter;
|
|
1441
|
+
this.assertNoEntities();
|
|
1442
|
+
this.useInterceptors(runtime);
|
|
1443
|
+
const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(this.options.deadLetterWorkflow) : void 0;
|
|
1176
1444
|
scanWorkflows(this.discovery, (meta, instance, origin) => {
|
|
1177
|
-
|
|
1178
|
-
(
|
|
1445
|
+
const inline = deadLetterHandlerOf(instance, this.metadataScanner);
|
|
1446
|
+
if (inline && meta.deadLetterWorkflow) {
|
|
1447
|
+
throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
|
|
1448
|
+
}
|
|
1449
|
+
const deadLetter = inline ? `${meta.name}.dlq` : meta.deadLetterWorkflow ? (0, import_nestjs_durable_core9.workflowName)(meta.deadLetterWorkflow) : fallback;
|
|
1450
|
+
registerOnRuntime(runtime, this.metadataScanner, meta, instance, origin, deadLetter);
|
|
1451
|
+
if (inline) {
|
|
1452
|
+
runtime.registerWorkflow(`${meta.name}.dlq`, inline, {
|
|
1453
|
+
version: meta.version,
|
|
1454
|
+
...origin !== void 0 ? {
|
|
1455
|
+
origin
|
|
1456
|
+
} : {}
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
const declare = starter.declareWorkflow;
|
|
1460
|
+
if (typeof declare === "function") {
|
|
1461
|
+
const io = workflowIo(meta);
|
|
1462
|
+
const policy = {
|
|
1463
|
+
validateInput: io.validateParsed,
|
|
1464
|
+
parseInput: io.parseInput,
|
|
1465
|
+
singleton: meta.singleton,
|
|
1466
|
+
concurrency: meta.concurrency,
|
|
1467
|
+
onEvent: getOnEvents(meta, instance.constructor),
|
|
1468
|
+
coalesces: eventBatchOf(meta, instance.constructor) !== void 0
|
|
1469
|
+
};
|
|
1470
|
+
declare.call(starter, meta.name, policy);
|
|
1471
|
+
}
|
|
1472
|
+
(0, import_nestjs_durable_core9.bindWorkflowClass)(instance.constructor, {
|
|
1179
1473
|
start: /* @__PURE__ */ __name((name, input, runId, opts) => starter.start(name, input, runId, opts), "start")
|
|
1180
1474
|
});
|
|
1181
1475
|
});
|
|
1182
1476
|
}
|
|
1477
|
+
/**
|
|
1478
|
+
* `@Entity` providers are refused on a tenant, at boot: an entity's state is a run on the store
|
|
1479
|
+
* and its `@On` handlers run inside the engine that owns that store (`EntityService` and
|
|
1480
|
+
* `ctx.callEntity`/`signalEntity` read and serialize it there). A tenant has no store and no
|
|
1481
|
+
* engine, so an entity declared here would never run. Declare it on the control plane.
|
|
1482
|
+
*/
|
|
1483
|
+
assertNoEntities() {
|
|
1484
|
+
const entities = this.discovery.getProviders().map((w) => w.instance).filter((i) => !!i && typeof i === "object" && !!getEntityMeta(i.constructor)).map((i) => getEntityMeta(i.constructor)?.name);
|
|
1485
|
+
if (entities.length === 0) return;
|
|
1486
|
+
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.`);
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* `@StepInterceptor()` providers wrap every step this tenant runs (each `ctx.step` its workers
|
|
1490
|
+
* execute), as `engine.use` does on an engine. A `@durable-worker` too old to take interceptors
|
|
1491
|
+
* says so instead of dropping them silently.
|
|
1492
|
+
*/
|
|
1493
|
+
useInterceptors(runtime) {
|
|
1494
|
+
for (const wrapper of this.discovery.getProviders()) {
|
|
1495
|
+
const instance = wrapper.instance;
|
|
1496
|
+
if (!instance || typeof instance !== "object" || !isStepInterceptor(instance.constructor)) {
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
const interceptor = instance;
|
|
1500
|
+
if (typeof runtime.use !== "function") {
|
|
1501
|
+
console.warn(`[nestjs-durable] @StepInterceptor ${instance.constructor.name} is not applied: this @dudousxd/durable-worker predates step interceptors on a tenant; upgrade it.`);
|
|
1502
|
+
continue;
|
|
1503
|
+
}
|
|
1504
|
+
runtime.use((invocation, next) => interceptor.intercept(invocation, next));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1183
1507
|
};
|
|
1184
|
-
ThinWorkflowRegistrar =
|
|
1185
|
-
(0,
|
|
1186
|
-
_ts_param(2, (0,
|
|
1187
|
-
_ts_param(3, (0,
|
|
1188
|
-
_ts_param(4, (0,
|
|
1189
|
-
|
|
1190
|
-
|
|
1508
|
+
ThinWorkflowRegistrar = _ts_decorate3([
|
|
1509
|
+
(0, import_common3.Injectable)(),
|
|
1510
|
+
_ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1511
|
+
_ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1512
|
+
_ts_param(4, (0, import_common3.Inject)(import_nestjs_durable_core9.WorkflowEngine)),
|
|
1513
|
+
_ts_metadata3("design:type", Function),
|
|
1514
|
+
_ts_metadata3("design:paramtypes", [
|
|
1191
1515
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1192
1516
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1193
1517
|
Object,
|
|
@@ -1215,12 +1539,12 @@ var ThinStepRegistrar = class {
|
|
|
1215
1539
|
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => runtime.registerStep(meta.name, handler));
|
|
1216
1540
|
}
|
|
1217
1541
|
};
|
|
1218
|
-
ThinStepRegistrar =
|
|
1219
|
-
(0,
|
|
1220
|
-
_ts_param(2, (0,
|
|
1221
|
-
_ts_param(3, (0,
|
|
1222
|
-
|
|
1223
|
-
|
|
1542
|
+
ThinStepRegistrar = _ts_decorate3([
|
|
1543
|
+
(0, import_common3.Injectable)(),
|
|
1544
|
+
_ts_param(2, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1545
|
+
_ts_param(3, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1546
|
+
_ts_metadata3("design:type", Function),
|
|
1547
|
+
_ts_metadata3("design:paramtypes", [
|
|
1224
1548
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1225
1549
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1226
1550
|
Object,
|
|
@@ -1280,15 +1604,15 @@ var ThinWorkerBootstrap = class {
|
|
|
1280
1604
|
await Promise.allSettled(this.runners.map((h) => h.close()));
|
|
1281
1605
|
}
|
|
1282
1606
|
};
|
|
1283
|
-
ThinWorkerBootstrap =
|
|
1284
|
-
(0,
|
|
1285
|
-
_ts_param(0, (0,
|
|
1286
|
-
_ts_param(1, (0,
|
|
1287
|
-
_ts_param(2, (0,
|
|
1288
|
-
_ts_param(3, (0,
|
|
1289
|
-
_ts_param(4, (0,
|
|
1290
|
-
|
|
1291
|
-
|
|
1607
|
+
ThinWorkerBootstrap = _ts_decorate3([
|
|
1608
|
+
(0, import_common3.Injectable)(),
|
|
1609
|
+
_ts_param(0, (0, import_common3.Inject)(DURABLE_WORKER_RUNTIME)),
|
|
1610
|
+
_ts_param(1, (0, import_common3.Inject)(import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL)),
|
|
1611
|
+
_ts_param(2, (0, import_common3.Inject)(RUN_REDIS_WORKER)),
|
|
1612
|
+
_ts_param(3, (0, import_common3.Inject)(DURABLE_WORKER_RUNNERS)),
|
|
1613
|
+
_ts_param(4, (0, import_common3.Inject)(TENANT_AUTH)),
|
|
1614
|
+
_ts_metadata3("design:type", Function),
|
|
1615
|
+
_ts_metadata3("design:paramtypes", [
|
|
1292
1616
|
Object,
|
|
1293
1617
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
1294
1618
|
typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
|
|
@@ -1299,7 +1623,7 @@ ThinWorkerBootstrap = _ts_decorate2([
|
|
|
1299
1623
|
async function tenantScheduleAnnouncement(options, tenantToken) {
|
|
1300
1624
|
let tenant;
|
|
1301
1625
|
try {
|
|
1302
|
-
tenant = tenantToken !== void 0 ? await (0,
|
|
1626
|
+
tenant = tenantToken !== void 0 ? await (0, import_nestjs_durable_core9.resolveTenantToken)(tenantToken) : options.partition ?? "default";
|
|
1303
1627
|
} catch (error) {
|
|
1304
1628
|
console.warn(`[nestjs-durable] this worker announces no schedules: its tenantToken failed (${error instanceof Error ? error.message : String(error)})`);
|
|
1305
1629
|
return {};
|
|
@@ -1307,15 +1631,24 @@ async function tenantScheduleAnnouncement(options, tenantToken) {
|
|
|
1307
1631
|
return {
|
|
1308
1632
|
schedules: {
|
|
1309
1633
|
tenant,
|
|
1310
|
-
items: (options.schedules ?? []).map(announcedSchedule)
|
|
1634
|
+
items: await Promise.all((options.schedules ?? []).map(announcedSchedule))
|
|
1311
1635
|
}
|
|
1312
1636
|
};
|
|
1313
1637
|
}
|
|
1314
1638
|
__name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
|
|
1315
|
-
function
|
|
1639
|
+
async function scheduleKeyInput(parseInput, input) {
|
|
1640
|
+
if (!parseInput) return input;
|
|
1641
|
+
try {
|
|
1642
|
+
return await parseInput(input);
|
|
1643
|
+
} catch {
|
|
1644
|
+
return input;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
__name(scheduleKeyInput, "scheduleKeyInput");
|
|
1648
|
+
async function announcedSchedule(s) {
|
|
1316
1649
|
const item = {
|
|
1317
1650
|
key: s.key,
|
|
1318
|
-
workflow: (0,
|
|
1651
|
+
workflow: (0, import_nestjs_durable_core9.workflowName)(s.workflow)
|
|
1319
1652
|
};
|
|
1320
1653
|
if (s.input !== void 0) item.input = s.input;
|
|
1321
1654
|
if (s.everyMs !== void 0) item.everyMs = s.everyMs;
|
|
@@ -1324,6 +1657,20 @@ function announcedSchedule(s) {
|
|
|
1324
1657
|
if (s.paused === true) item.paused = true;
|
|
1325
1658
|
if (s.overlap !== void 0) item.overlap = s.overlap;
|
|
1326
1659
|
if (s.jitter !== void 0 && s.jitter > 0) item.jitterMs = s.jitter;
|
|
1660
|
+
const meta = typeof s.workflow === "function" ? getWorkflowMeta(s.workflow) : void 0;
|
|
1661
|
+
const singleton = meta?.singleton;
|
|
1662
|
+
if (meta && singleton) {
|
|
1663
|
+
const parseInput = workflowIo(meta).parseInput;
|
|
1664
|
+
item.singleton = {
|
|
1665
|
+
key: singleton.key(await scheduleKeyInput(parseInput, s.input)),
|
|
1666
|
+
...singleton.limit !== void 0 ? {
|
|
1667
|
+
limit: singleton.limit
|
|
1668
|
+
} : {},
|
|
1669
|
+
...singleton.maxQueueDepth !== void 0 ? {
|
|
1670
|
+
maxQueueDepth: singleton.maxQueueDepth
|
|
1671
|
+
} : {}
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1327
1674
|
return item;
|
|
1328
1675
|
}
|
|
1329
1676
|
__name(announcedSchedule, "announcedSchedule");
|
|
@@ -1346,7 +1693,7 @@ function thinWorkerProviders() {
|
|
|
1346
1693
|
workflowGroup: options.partition ?? ""
|
|
1347
1694
|
}) : null, "useFactory"),
|
|
1348
1695
|
inject: [
|
|
1349
|
-
|
|
1696
|
+
import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
|
|
1350
1697
|
]
|
|
1351
1698
|
},
|
|
1352
1699
|
{
|
|
@@ -1416,13 +1763,13 @@ function unavailableRunGateway() {
|
|
|
1416
1763
|
__name(unavailableRunGateway, "unavailableRunGateway");
|
|
1417
1764
|
|
|
1418
1765
|
// src/durable.module.ts
|
|
1419
|
-
var
|
|
1766
|
+
var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
|
|
1420
1767
|
var import_common13 = require("@nestjs/common");
|
|
1421
1768
|
var import_core6 = require("@nestjs/core");
|
|
1422
1769
|
|
|
1423
1770
|
// src/durable-step.registrar.ts
|
|
1424
|
-
var
|
|
1425
|
-
var
|
|
1771
|
+
var import_nestjs_durable_core10 = require("@dudousxd/nestjs-durable-core");
|
|
1772
|
+
var import_common4 = require("@nestjs/common");
|
|
1426
1773
|
var import_core2 = require("@nestjs/core");
|
|
1427
1774
|
|
|
1428
1775
|
// src/role.ts
|
|
@@ -1436,7 +1783,7 @@ function isDrivingOperator(options) {
|
|
|
1436
1783
|
__name(isDrivingOperator, "isDrivingOperator");
|
|
1437
1784
|
|
|
1438
1785
|
// src/durable-step.registrar.ts
|
|
1439
|
-
function
|
|
1786
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1440
1787
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1441
1788
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1442
1789
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1449,13 +1796,13 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1449
1796
|
}
|
|
1450
1797
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1451
1798
|
}
|
|
1452
|
-
__name(
|
|
1453
|
-
function
|
|
1799
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1800
|
+
function _ts_metadata4(metadataKey, metadataValue) {
|
|
1454
1801
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1455
1802
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1456
1803
|
}
|
|
1457
1804
|
}
|
|
1458
|
-
__name(
|
|
1805
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1459
1806
|
function _ts_param2(paramIndex, decorator) {
|
|
1460
1807
|
return function(target, key) {
|
|
1461
1808
|
decorator(target, key, paramIndex);
|
|
@@ -1487,12 +1834,12 @@ var DurableStepRegistrar = class {
|
|
|
1487
1834
|
scanSteps(this.discovery, this.metadataScanner, (meta, handler) => transport.handle(meta.name, handler, this.options.partition));
|
|
1488
1835
|
}
|
|
1489
1836
|
};
|
|
1490
|
-
DurableStepRegistrar =
|
|
1491
|
-
(0,
|
|
1492
|
-
_ts_param2(2, (0,
|
|
1493
|
-
_ts_param2(3, (0,
|
|
1494
|
-
|
|
1495
|
-
|
|
1837
|
+
DurableStepRegistrar = _ts_decorate4([
|
|
1838
|
+
(0, import_common4.Injectable)(),
|
|
1839
|
+
_ts_param2(2, (0, import_common4.Inject)(import_nestjs_durable_core10.TRANSPORT_CANONICAL)),
|
|
1840
|
+
_ts_param2(3, (0, import_common4.Inject)(import_nestjs_durable_core10.DURABLE_OPTIONS_CANONICAL)),
|
|
1841
|
+
_ts_metadata4("design:type", Function),
|
|
1842
|
+
_ts_metadata4("design:paramtypes", [
|
|
1496
1843
|
typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
|
|
1497
1844
|
typeof import_core2.MetadataScanner === "undefined" ? Object : import_core2.MetadataScanner,
|
|
1498
1845
|
Object,
|
|
@@ -1500,96 +1847,8 @@ DurableStepRegistrar = _ts_decorate3([
|
|
|
1500
1847
|
])
|
|
1501
1848
|
], DurableStepRegistrar);
|
|
1502
1849
|
|
|
1503
|
-
// src/entity.ts
|
|
1504
|
-
var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
|
|
1505
|
-
var import_common4 = require("@nestjs/common");
|
|
1506
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
1507
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
1508
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1509
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1510
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1511
|
-
} else {
|
|
1512
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1513
|
-
if (d = decorators[i]) {
|
|
1514
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1519
|
-
}
|
|
1520
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
1521
|
-
function _ts_metadata4(metadataKey, metadataValue) {
|
|
1522
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1523
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
__name(_ts_metadata4, "_ts_metadata");
|
|
1527
|
-
var ENTITY_METADATA = Symbol("nestjs-durable:entity");
|
|
1528
|
-
var ENTITY_ON_METADATA = Symbol("nestjs-durable:entity-on");
|
|
1529
|
-
function Entity(options) {
|
|
1530
|
-
return (target) => {
|
|
1531
|
-
Reflect.defineMetadata(ENTITY_METADATA, options, target);
|
|
1532
|
-
};
|
|
1533
|
-
}
|
|
1534
|
-
__name(Entity, "Entity");
|
|
1535
|
-
function On(op) {
|
|
1536
|
-
return (target, propertyKey) => {
|
|
1537
|
-
const ctor = target.constructor;
|
|
1538
|
-
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1539
|
-
ops.set(op, propertyKey);
|
|
1540
|
-
Reflect.defineMetadata(ENTITY_ON_METADATA, ops, ctor);
|
|
1541
|
-
};
|
|
1542
|
-
}
|
|
1543
|
-
__name(On, "On");
|
|
1544
|
-
function getEntityMeta(target) {
|
|
1545
|
-
return Reflect.getMetadata(ENTITY_METADATA, target);
|
|
1546
|
-
}
|
|
1547
|
-
__name(getEntityMeta, "getEntityMeta");
|
|
1548
|
-
function entityConfigFor(ctor) {
|
|
1549
|
-
const ops = Reflect.getMetadata(ENTITY_ON_METADATA, ctor) ?? /* @__PURE__ */ new Map();
|
|
1550
|
-
const Cls = ctor;
|
|
1551
|
-
const handlers = {};
|
|
1552
|
-
for (const [op, method] of ops) {
|
|
1553
|
-
handlers[op] = (state, arg) => {
|
|
1554
|
-
Object.setPrototypeOf(state, Cls.prototype);
|
|
1555
|
-
const fn = state[method];
|
|
1556
|
-
if (typeof fn !== "function") throw new Error(`entity handler "${method}" is not a method`);
|
|
1557
|
-
return fn.call(state, arg);
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
return {
|
|
1561
|
-
initialState: /* @__PURE__ */ __name(() => new Cls(), "initialState"),
|
|
1562
|
-
handlers
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
__name(entityConfigFor, "entityConfigFor");
|
|
1566
|
-
var EntityService = class {
|
|
1567
|
-
static {
|
|
1568
|
-
__name(this, "EntityService");
|
|
1569
|
-
}
|
|
1570
|
-
engine;
|
|
1571
|
-
constructor(engine) {
|
|
1572
|
-
this.engine = engine;
|
|
1573
|
-
}
|
|
1574
|
-
/** Send an operation to an entity (fire-and-forget; ordered + exactly-once per key). */
|
|
1575
|
-
signal(name, key, op, arg) {
|
|
1576
|
-
return this.engine.signalEntity(name, key, op, arg);
|
|
1577
|
-
}
|
|
1578
|
-
/** Read an entity's current durable state (or undefined if it has none yet). */
|
|
1579
|
-
getState(name, key) {
|
|
1580
|
-
return this.engine.getEntityState(name, key);
|
|
1581
|
-
}
|
|
1582
|
-
};
|
|
1583
|
-
EntityService = _ts_decorate4([
|
|
1584
|
-
(0, import_common4.Injectable)(),
|
|
1585
|
-
_ts_metadata4("design:type", Function),
|
|
1586
|
-
_ts_metadata4("design:paramtypes", [
|
|
1587
|
-
typeof import_nestjs_durable_core9.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core9.WorkflowEngine
|
|
1588
|
-
])
|
|
1589
|
-
], EntityService);
|
|
1590
|
-
|
|
1591
1850
|
// src/in-app-worker.ts
|
|
1592
|
-
var
|
|
1851
|
+
var import_nestjs_durable_core11 = require("@dudousxd/nestjs-durable-core");
|
|
1593
1852
|
var import_common5 = require("@nestjs/common");
|
|
1594
1853
|
var import_core3 = require("@nestjs/core");
|
|
1595
1854
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
@@ -1694,7 +1953,7 @@ var InAppWorkerBootstrap = class {
|
|
|
1694
1953
|
};
|
|
1695
1954
|
InAppWorkerBootstrap = _ts_decorate5([
|
|
1696
1955
|
(0, import_common5.Injectable)(),
|
|
1697
|
-
_ts_param3(2, (0, import_common5.Inject)(
|
|
1956
|
+
_ts_param3(2, (0, import_common5.Inject)(import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL)),
|
|
1698
1957
|
_ts_param3(3, (0, import_common5.Inject)(IN_APP_WORKER_RUNTIME)),
|
|
1699
1958
|
_ts_param3(4, (0, import_common5.Inject)(IN_APP_RUN_REDIS_WORKER)),
|
|
1700
1959
|
_ts_param3(5, (0, import_common5.Inject)(IN_APP_WORKER_RUNNERS)),
|
|
@@ -1714,8 +1973,8 @@ function inAppWorkerProviders() {
|
|
|
1714
1973
|
provide: IN_APP_WORKER_BINDING,
|
|
1715
1974
|
useFactory: /* @__PURE__ */ __name((transport, options) => inAppWorkerBinding(transport, options), "useFactory"),
|
|
1716
1975
|
inject: [
|
|
1717
|
-
|
|
1718
|
-
|
|
1976
|
+
import_nestjs_durable_core11.TRANSPORT_CANONICAL,
|
|
1977
|
+
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
|
|
1719
1978
|
]
|
|
1720
1979
|
},
|
|
1721
1980
|
{
|
|
@@ -1735,7 +1994,7 @@ function inAppWorkerProviders() {
|
|
|
1735
1994
|
workflowGroup: options.partition ?? ""
|
|
1736
1995
|
}) : null, "useFactory"),
|
|
1737
1996
|
inject: [
|
|
1738
|
-
|
|
1997
|
+
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
|
|
1739
1998
|
]
|
|
1740
1999
|
},
|
|
1741
2000
|
{
|
|
@@ -1752,11 +2011,11 @@ function inAppWorkerProviders() {
|
|
|
1752
2011
|
__name(inAppWorkerProviders, "inAppWorkerProviders");
|
|
1753
2012
|
|
|
1754
2013
|
// src/proxy-run-gateway.ts
|
|
1755
|
-
var
|
|
2014
|
+
var import_nestjs_durable_core13 = require("@dudousxd/nestjs-durable-core");
|
|
1756
2015
|
var import_common6 = require("@nestjs/common");
|
|
1757
2016
|
|
|
1758
2017
|
// src/run-request-responder.ts
|
|
1759
|
-
var
|
|
2018
|
+
var import_nestjs_durable_core12 = require("@dudousxd/nestjs-durable-core");
|
|
1760
2019
|
var UNSUPPORTED_RUN_REQUEST = "unsupported-request";
|
|
1761
2020
|
var BAD_RUN_REQUEST = "bad-request";
|
|
1762
2021
|
var TENANT_REPUBLISH_MAX_LIMIT = 1e3;
|
|
@@ -1777,7 +2036,9 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
|
1777
2036
|
"republishLifecycle",
|
|
1778
2037
|
"workflowLifecycle",
|
|
1779
2038
|
"signal",
|
|
1780
|
-
"schedule"
|
|
2039
|
+
"schedule",
|
|
2040
|
+
"signalWithStart",
|
|
2041
|
+
"publishEvent"
|
|
1781
2042
|
]);
|
|
1782
2043
|
function wireDate(value) {
|
|
1783
2044
|
if (value === void 0 || value === null) return void 0;
|
|
@@ -1853,7 +2114,8 @@ var RunRequestResponder = class {
|
|
|
1853
2114
|
});
|
|
1854
2115
|
}
|
|
1855
2116
|
async handle(wire) {
|
|
1856
|
-
const
|
|
2117
|
+
const verified = await (0, import_nestjs_durable_core12.verifyWireTenant)(wire.tenant, this.verifyTenant);
|
|
2118
|
+
const tenant = verified?.tenant ?? null;
|
|
1857
2119
|
if (tenant === null) {
|
|
1858
2120
|
return {
|
|
1859
2121
|
requestId: wire.requestId,
|
|
@@ -2031,7 +2293,18 @@ var RunRequestResponder = class {
|
|
|
2031
2293
|
}
|
|
2032
2294
|
};
|
|
2033
2295
|
}
|
|
2034
|
-
return this.answer(msg.requestId, () => signal.call(this.gateway, body.token, body.payload));
|
|
2296
|
+
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));
|
|
2297
|
+
}
|
|
2298
|
+
if (body.kind === "signalWithStart") {
|
|
2299
|
+
return this.signalWithStart(msg.requestId, body, msg.tenant, verified);
|
|
2300
|
+
}
|
|
2301
|
+
if (body.kind === "publishEvent") {
|
|
2302
|
+
const { publishEventForTenant } = this.gateway;
|
|
2303
|
+
if (!publishEventForTenant) return unsupported(msg.requestId, body.kind);
|
|
2304
|
+
if (typeof body.name !== "string" || body.name === "") {
|
|
2305
|
+
return badRequest(msg.requestId, "publishEvent needs an event name");
|
|
2306
|
+
}
|
|
2307
|
+
return this.answer(msg.requestId, () => publishEventForTenant.call(this.gateway, body.name, body.payload, msg.tenant));
|
|
2035
2308
|
}
|
|
2036
2309
|
if (body.kind === "republishLifecycle" && !this.gateway.republishLifecycle) {
|
|
2037
2310
|
return unsupported(msg.requestId, body.kind);
|
|
@@ -2081,7 +2354,7 @@ var RunRequestResponder = class {
|
|
|
2081
2354
|
};
|
|
2082
2355
|
}
|
|
2083
2356
|
if (body.kind === "republishLifecycle" && "runId" in body.target && run) {
|
|
2084
|
-
const kind = (0,
|
|
2357
|
+
const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(run.status);
|
|
2085
2358
|
const refused = kind ? await this.refuseSubscriber(run.workflow, kind, body.target.subscriber, msg.tenant) : void 0;
|
|
2086
2359
|
if (refused) return badRequest(msg.requestId, refused);
|
|
2087
2360
|
}
|
|
@@ -2106,6 +2379,50 @@ var RunRequestResponder = class {
|
|
|
2106
2379
|
};
|
|
2107
2380
|
}
|
|
2108
2381
|
}
|
|
2382
|
+
/**
|
|
2383
|
+
* A tenant's `signalWithStart`: the run it names must be the requester's when it exists, and so
|
|
2384
|
+
* must a run already waiting on the token; anything else is refused `cross-tenant` before the
|
|
2385
|
+
* gateway is called. The run is started in the requester's namespace (a customer tenant it claims
|
|
2386
|
+
* is kept only when its verified token grants it, as for a start-run).
|
|
2387
|
+
*/
|
|
2388
|
+
async signalWithStart(requestId, body, tenant, verified) {
|
|
2389
|
+
const { signalWithStartForTenant, signalWaiter } = this.gateway;
|
|
2390
|
+
if (!signalWithStartForTenant) return unsupported(requestId, body.kind);
|
|
2391
|
+
const start = body.start;
|
|
2392
|
+
if (!start || typeof start.runId !== "string" || start.runId === "" || typeof start.workflow !== "string" || start.workflow === "" || typeof body.signal?.token !== "string" || body.signal.token === "") {
|
|
2393
|
+
return badRequest(requestId, "signalWithStart needs a workflow, a run id and a signal token");
|
|
2394
|
+
}
|
|
2395
|
+
const crossTenant = {
|
|
2396
|
+
requestId,
|
|
2397
|
+
result: {
|
|
2398
|
+
ok: false,
|
|
2399
|
+
error: {
|
|
2400
|
+
message: "run belongs to another tenant",
|
|
2401
|
+
code: "cross-tenant"
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
const existing = await this.runOf(start.runId);
|
|
2406
|
+
if (existing && existing.namespace !== tenant) return crossTenant;
|
|
2407
|
+
const waiterRunId = signalWaiter ? await signalWaiter.call(this.gateway, body.signal.token) : null;
|
|
2408
|
+
const waiter = waiterRunId ? await this.runOf(waiterRunId) : null;
|
|
2409
|
+
if (waiter && waiter.namespace !== tenant) return crossTenant;
|
|
2410
|
+
const claim = start.tenantId !== void 0 ? (0, import_nestjs_durable_core12.grantsClientTenant)(verified, start.tenantId) ? {
|
|
2411
|
+
tenantId: start.tenantId,
|
|
2412
|
+
...start.tenantKind !== void 0 ? {
|
|
2413
|
+
tenantKind: start.tenantKind
|
|
2414
|
+
} : {}
|
|
2415
|
+
} : {
|
|
2416
|
+
tenantId: null
|
|
2417
|
+
} : {};
|
|
2418
|
+
return this.answer(requestId, () => signalWithStartForTenant.call(this.gateway, {
|
|
2419
|
+
...start,
|
|
2420
|
+
tenant
|
|
2421
|
+
}, tenant, claim, {
|
|
2422
|
+
token: body.signal.token,
|
|
2423
|
+
payload: body.signal.payload
|
|
2424
|
+
}));
|
|
2425
|
+
}
|
|
2109
2426
|
/** The run alone (`getRun`, else from its detail), or null when it does not exist. */
|
|
2110
2427
|
async runOf(runId) {
|
|
2111
2428
|
return this.gateway.getRun ? this.gateway.getRun(runId) : (await this.gateway.getRunDetail(runId))?.run ?? null;
|
|
@@ -2147,7 +2464,7 @@ var RunRequestResponder = class {
|
|
|
2147
2464
|
namespace: tenant
|
|
2148
2465
|
});
|
|
2149
2466
|
if (!links) return rest;
|
|
2150
|
-
const kind = (0,
|
|
2467
|
+
const kind = (0, import_nestjs_durable_core12.lifecycleKindOf)(detail.run.status);
|
|
2151
2468
|
const subscribers = kind ? [
|
|
2152
2469
|
...new Set(links.startsOnSettle.filter((l) => l.kind === kind).map((l) => l.workflow))
|
|
2153
2470
|
] : [];
|
|
@@ -2274,6 +2591,10 @@ var RunGatewayError = class extends Error {
|
|
|
2274
2591
|
this.code = code;
|
|
2275
2592
|
}
|
|
2276
2593
|
};
|
|
2594
|
+
function unsupportedVerb(kind) {
|
|
2595
|
+
return new RunGatewayError(`${kind} is not supported by this server: the control plane is older than this tenant`, UNSUPPORTED_RUN_REQUEST);
|
|
2596
|
+
}
|
|
2597
|
+
__name(unsupportedVerb, "unsupportedVerb");
|
|
2277
2598
|
var UnsupportedRunRequestError = class UnsupportedRunRequestError2 extends RunGatewayError {
|
|
2278
2599
|
static {
|
|
2279
2600
|
__name(this, "UnsupportedRunRequestError");
|
|
@@ -2324,12 +2645,12 @@ var ProxyRunGateway = class {
|
|
|
2324
2645
|
} catch (err) {
|
|
2325
2646
|
return Promise.reject(err);
|
|
2326
2647
|
}
|
|
2327
|
-
return send(filter ? (0,
|
|
2648
|
+
return send(filter ? (0, import_nestjs_durable_core13.scopeTenantQuery)(query, filter) : query);
|
|
2328
2649
|
}
|
|
2329
2650
|
/** `run` when the request may see it, else null (an invisible run reads like a missing one). */
|
|
2330
2651
|
visible(run, filter = this.restrictive()) {
|
|
2331
2652
|
if (!run) return null;
|
|
2332
|
-
return !filter || (0,
|
|
2653
|
+
return !filter || (0, import_nestjs_durable_core13.tenantVisible)(run, filter) ? run : null;
|
|
2333
2654
|
}
|
|
2334
2655
|
/** Run a control call unless the request may not act on `runId` (then `null`, like a missing run).
|
|
2335
2656
|
* Sent at once when nothing narrows the request. */
|
|
@@ -2365,7 +2686,7 @@ var ProxyRunGateway = class {
|
|
|
2365
2686
|
request(body) {
|
|
2366
2687
|
const source = this.tenantToken;
|
|
2367
2688
|
if (typeof source !== "function") return this.send(source ?? this.tenant, body);
|
|
2368
|
-
return (0,
|
|
2689
|
+
return (0, import_nestjs_durable_core13.resolveTenantToken)(source).then((tenant) => this.send(tenant, body));
|
|
2369
2690
|
}
|
|
2370
2691
|
send(tenant, body) {
|
|
2371
2692
|
return new Promise((resolve, reject) => {
|
|
@@ -2415,12 +2736,12 @@ var ProxyRunGateway = class {
|
|
|
2415
2736
|
if (detail && filter && !this.visible(detail.run, filter)) return null;
|
|
2416
2737
|
const over = options?.summarizeFansOver;
|
|
2417
2738
|
if (over === void 0 || !detail || detail.fans !== void 0) return detail;
|
|
2418
|
-
const { timeline, fans } = (0,
|
|
2419
|
-
const ids = (0,
|
|
2739
|
+
const { timeline, fans } = (0, import_nestjs_durable_core13.summarizeTimeline)(detail.timeline, over);
|
|
2740
|
+
const ids = (0, import_nestjs_durable_core13.childIdsOf)(detail.timeline);
|
|
2420
2741
|
return {
|
|
2421
2742
|
...detail,
|
|
2422
2743
|
timeline,
|
|
2423
|
-
children: ids.slice(0,
|
|
2744
|
+
children: ids.slice(0, import_nestjs_durable_core13.SUMMARY_CHILD_LIMIT),
|
|
2424
2745
|
fans,
|
|
2425
2746
|
childCount: ids.length
|
|
2426
2747
|
};
|
|
@@ -2446,7 +2767,7 @@ var ProxyRunGateway = class {
|
|
|
2446
2767
|
kind: "getRunDetail",
|
|
2447
2768
|
runId
|
|
2448
2769
|
});
|
|
2449
|
-
return detail ? (0,
|
|
2770
|
+
return detail ? (0, import_nestjs_durable_core13.pageFan)(detail.timeline, group, query) : null;
|
|
2450
2771
|
}
|
|
2451
2772
|
/**
|
|
2452
2773
|
* The run alone, without its timeline. Read from the full detail when the control plane is too old
|
|
@@ -2579,7 +2900,7 @@ var ProxyRunGateway = class {
|
|
|
2579
2900
|
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
2580
2901
|
*/
|
|
2581
2902
|
async requestNewVerb(body) {
|
|
2582
|
-
const notSupported = /* @__PURE__ */ __name(() =>
|
|
2903
|
+
const notSupported = /* @__PURE__ */ __name(() => unsupportedVerb(body.kind), "notSupported");
|
|
2583
2904
|
if (this.knownUnsupported(body.kind)) throw notSupported();
|
|
2584
2905
|
let data;
|
|
2585
2906
|
try {
|
|
@@ -2591,6 +2912,62 @@ var ProxyRunGateway = class {
|
|
|
2591
2912
|
this.unsupportedUntil.set(body.kind, Date.now() + this.capabilityTtlMs);
|
|
2592
2913
|
throw notSupported();
|
|
2593
2914
|
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Signal the run of this tenant's namespace waiting on `token` (`engine.signal`). Resolves null
|
|
2917
|
+
* when no run of this namespace waits on it: the control plane does NOT buffer a tenant's signal
|
|
2918
|
+
* for a wait opened later (another namespace's run could open it). A control plane that predates
|
|
2919
|
+
* the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error.
|
|
2920
|
+
*/
|
|
2921
|
+
async signal(token, payload, opts) {
|
|
2922
|
+
if (this.knownUnsupported("signal")) throw unsupportedVerb("signal");
|
|
2923
|
+
let data;
|
|
2924
|
+
try {
|
|
2925
|
+
data = await this.request(opts === void 0 ? {
|
|
2926
|
+
kind: "signal",
|
|
2927
|
+
token,
|
|
2928
|
+
payload
|
|
2929
|
+
} : {
|
|
2930
|
+
kind: "signal",
|
|
2931
|
+
token,
|
|
2932
|
+
payload,
|
|
2933
|
+
opts
|
|
2934
|
+
});
|
|
2935
|
+
} catch (err) {
|
|
2936
|
+
if (!isUnsupported(err)) throw err;
|
|
2937
|
+
}
|
|
2938
|
+
if (data !== void 0) return data;
|
|
2939
|
+
this.unsupportedUntil.set("signal", Date.now() + this.capabilityTtlMs);
|
|
2940
|
+
throw unsupportedVerb("signal");
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* `engine.signalWithStart` for this tenant: the control plane starts `start` in this tenant's
|
|
2944
|
+
* namespace unless its run exists, then signals it (buffered until the run waits, when the token
|
|
2945
|
+
* names the run id). See the responder for the authorization rule.
|
|
2946
|
+
*/
|
|
2947
|
+
signalWithStart(start, signal) {
|
|
2948
|
+
return this.requestNewVerb({
|
|
2949
|
+
kind: "signalWithStart",
|
|
2950
|
+
start,
|
|
2951
|
+
signal
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
/**
|
|
2955
|
+
* Resume the runs of this tenant's namespace waiting on event `name` (`ctx.waitForEvent`).
|
|
2956
|
+
* Resolves how many it resumed. The tenant's own `onEvent` subscribers are started by the caller
|
|
2957
|
+
* (`DurableStartClient.publishEvent`), not here.
|
|
2958
|
+
*/
|
|
2959
|
+
publishEvent(name, payload, opts) {
|
|
2960
|
+
return this.requestNewVerb({
|
|
2961
|
+
kind: "publishEvent",
|
|
2962
|
+
name,
|
|
2963
|
+
payload,
|
|
2964
|
+
...opts?.id !== void 0 ? {
|
|
2965
|
+
opts: {
|
|
2966
|
+
id: opts.id
|
|
2967
|
+
}
|
|
2968
|
+
} : {}
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2594
2971
|
subscribe(runId, onEvent) {
|
|
2595
2972
|
const unsubscribe = this.transport.onTenantEvent?.(this.tenant, (evt) => {
|
|
2596
2973
|
if (evt.event.runId === runId) onEvent(evt.event);
|
|
@@ -2613,7 +2990,7 @@ ProxyRunGateway = _ts_decorate6([
|
|
|
2613
2990
|
], ProxyRunGateway);
|
|
2614
2991
|
|
|
2615
2992
|
// src/retention-poller.ts
|
|
2616
|
-
var
|
|
2993
|
+
var import_nestjs_durable_core15 = require("@dudousxd/nestjs-durable-core");
|
|
2617
2994
|
var import_common8 = require("@nestjs/common");
|
|
2618
2995
|
|
|
2619
2996
|
// src/settle-within.ts
|
|
@@ -2640,7 +3017,7 @@ async function settleWithin(p, timeoutMs) {
|
|
|
2640
3017
|
__name(settleWithin, "settleWithin");
|
|
2641
3018
|
|
|
2642
3019
|
// src/sweep-leases.ts
|
|
2643
|
-
var
|
|
3020
|
+
var import_nestjs_durable_core14 = require("@dudousxd/nestjs-durable-core");
|
|
2644
3021
|
var import_common7 = require("@nestjs/common");
|
|
2645
3022
|
var import_core4 = require("@nestjs/core");
|
|
2646
3023
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
@@ -2738,7 +3115,7 @@ SweepLeases = _ts_decorate7([
|
|
|
2738
3115
|
(0, import_common7.Injectable)(),
|
|
2739
3116
|
_ts_param4(0, (0, import_common7.Optional)()),
|
|
2740
3117
|
_ts_param4(1, (0, import_common7.Optional)()),
|
|
2741
|
-
_ts_param4(1, (0, import_common7.Inject)(
|
|
3118
|
+
_ts_param4(1, (0, import_common7.Inject)(import_nestjs_durable_core14.DURABLE_OPTIONS_CANONICAL)),
|
|
2742
3119
|
_ts_metadata7("design:type", Function),
|
|
2743
3120
|
_ts_metadata7("design:paramtypes", [
|
|
2744
3121
|
typeof import_core4.ModuleRef === "undefined" ? Object : import_core4.ModuleRef,
|
|
@@ -2786,10 +3163,10 @@ function validateRetention(retention) {
|
|
|
2786
3163
|
if (policy.maxAge == null && policy.maxCount == null) {
|
|
2787
3164
|
throw new Error("durable retention: each policy must set maxAge and/or maxCount");
|
|
2788
3165
|
}
|
|
2789
|
-
if (policy.maxAge != null) (0,
|
|
3166
|
+
if (policy.maxAge != null) (0, import_nestjs_durable_core15.parseDuration)(policy.maxAge);
|
|
2790
3167
|
for (const status of policy.statuses) {
|
|
2791
|
-
if (!
|
|
2792
|
-
throw new Error(`durable retention: status "${status}" is not terminal; only ${
|
|
3168
|
+
if (!import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.includes(status)) {
|
|
3169
|
+
throw new Error(`durable retention: status "${status}" is not terminal; only ${import_nestjs_durable_core15.TERMINAL_RUN_STATUSES.join(", ")} can be pruned`);
|
|
2793
3170
|
}
|
|
2794
3171
|
const key = `${scopeKey}|${status}`;
|
|
2795
3172
|
if (seen.has(key)) {
|
|
@@ -2843,7 +3220,7 @@ var RetentionPoller = class {
|
|
|
2843
3220
|
return;
|
|
2844
3221
|
}
|
|
2845
3222
|
void this.sweep();
|
|
2846
|
-
const intervalMs = retention.sweepInterval != null ? (0,
|
|
3223
|
+
const intervalMs = retention.sweepInterval != null ? (0, import_nestjs_durable_core15.parseDuration)(retention.sweepInterval) : DEFAULT_SWEEP_INTERVAL_MS;
|
|
2847
3224
|
if (intervalMs > 0) {
|
|
2848
3225
|
this.timer = setInterval(() => void this.sweep(), intervalMs);
|
|
2849
3226
|
this.timer.unref?.();
|
|
@@ -2907,8 +3284,8 @@ var RetentionPoller = class {
|
|
|
2907
3284
|
};
|
|
2908
3285
|
RetentionPoller = _ts_decorate8([
|
|
2909
3286
|
(0, import_common8.Injectable)(),
|
|
2910
|
-
_ts_param5(0, (0, import_common8.Inject)(
|
|
2911
|
-
_ts_param5(1, (0, import_common8.Inject)(
|
|
3287
|
+
_ts_param5(0, (0, import_common8.Inject)(import_nestjs_durable_core15.STATE_STORE_CANONICAL)),
|
|
3288
|
+
_ts_param5(1, (0, import_common8.Inject)(import_nestjs_durable_core15.DURABLE_OPTIONS_CANONICAL)),
|
|
2912
3289
|
_ts_param5(2, (0, import_common8.Optional)()),
|
|
2913
3290
|
_ts_metadata8("design:type", Function),
|
|
2914
3291
|
_ts_metadata8("design:paramtypes", [
|
|
@@ -2919,7 +3296,7 @@ RetentionPoller = _ts_decorate8([
|
|
|
2919
3296
|
], RetentionPoller);
|
|
2920
3297
|
|
|
2921
3298
|
// src/store-run-gateway.ts
|
|
2922
|
-
var
|
|
3299
|
+
var import_nestjs_durable_core16 = require("@dudousxd/nestjs-durable-core");
|
|
2923
3300
|
var import_common9 = require("@nestjs/common");
|
|
2924
3301
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
2925
3302
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2962,14 +3339,14 @@ function detailExtras(links) {
|
|
|
2962
3339
|
}
|
|
2963
3340
|
__name(detailExtras, "detailExtras");
|
|
2964
3341
|
function withoutRegistry(query) {
|
|
2965
|
-
if (query.workflow ===
|
|
3342
|
+
if (query.workflow === import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW || query.workflows?.includes(import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW)) {
|
|
2966
3343
|
return query;
|
|
2967
3344
|
}
|
|
2968
3345
|
return {
|
|
2969
3346
|
...query,
|
|
2970
3347
|
excludeWorkflows: [
|
|
2971
3348
|
...query.excludeWorkflows ?? [],
|
|
2972
|
-
|
|
3349
|
+
import_nestjs_durable_core16.LIFECYCLE_REGISTRY_WORKFLOW
|
|
2973
3350
|
]
|
|
2974
3351
|
};
|
|
2975
3352
|
}
|
|
@@ -3020,10 +3397,10 @@ var StoreRunGateway = class {
|
|
|
3020
3397
|
...links
|
|
3021
3398
|
};
|
|
3022
3399
|
}
|
|
3023
|
-
if ((0,
|
|
3400
|
+
if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
|
|
3024
3401
|
const stats = await this.store.checkpointStats(runId);
|
|
3025
|
-
const etag = (0,
|
|
3026
|
-
if ((0,
|
|
3402
|
+
const etag = (0, import_nestjs_durable_core16.extendEtag)((0, import_nestjs_durable_core16.runDetailEtag)(run, stats, over), detailExtras(links));
|
|
3403
|
+
if ((0, import_nestjs_durable_core16.etagMatches)(options?.ifNoneMatch, etag)) {
|
|
3027
3404
|
return {
|
|
3028
3405
|
run,
|
|
3029
3406
|
timeline: [],
|
|
@@ -3034,18 +3411,18 @@ var StoreRunGateway = class {
|
|
|
3034
3411
|
}
|
|
3035
3412
|
return {
|
|
3036
3413
|
run,
|
|
3037
|
-
...await (0,
|
|
3414
|
+
...await (0, import_nestjs_durable_core16.summarizeRunFromStore)(this.store, runId, over, stats),
|
|
3038
3415
|
etag,
|
|
3039
3416
|
...links
|
|
3040
3417
|
};
|
|
3041
3418
|
}
|
|
3042
3419
|
const full = await this.store.listCheckpoints(runId);
|
|
3043
|
-
const { timeline, fans } = (0,
|
|
3044
|
-
const ids = (0,
|
|
3420
|
+
const { timeline, fans } = (0, import_nestjs_durable_core16.summarizeTimeline)(full, over);
|
|
3421
|
+
const ids = (0, import_nestjs_durable_core16.childIdsOf)(full);
|
|
3045
3422
|
return {
|
|
3046
3423
|
run,
|
|
3047
3424
|
timeline,
|
|
3048
|
-
children: ids.slice(0,
|
|
3425
|
+
children: ids.slice(0, import_nestjs_durable_core16.SUMMARY_CHILD_LIMIT),
|
|
3049
3426
|
fans,
|
|
3050
3427
|
childCount: ids.length,
|
|
3051
3428
|
...links
|
|
@@ -3060,24 +3437,24 @@ var StoreRunGateway = class {
|
|
|
3060
3437
|
*/
|
|
3061
3438
|
async lifecycleLinks(run) {
|
|
3062
3439
|
const triggered = await this.engine.triggeredRuns(run);
|
|
3063
|
-
const source = (0,
|
|
3064
|
-
const kind = (0,
|
|
3440
|
+
const source = (0, import_nestjs_durable_core16.lifecycleSourceOf)(run);
|
|
3441
|
+
const kind = (0, import_nestjs_durable_core16.lifecycleKindOf)(run.status);
|
|
3065
3442
|
const subscribers = kind ? await this.engine.lifecycleSubscribers(run.workflow, kind, run.namespace || "default") : [];
|
|
3066
3443
|
const workflowLifecycle = await this.engine.workflowLifecycle(run.workflow);
|
|
3067
3444
|
const linked = workflowLifecycle.startsOnSettle.length > 0 || workflowLifecycle.startedBy.length > 0;
|
|
3068
|
-
const deliveries = kind ? (0,
|
|
3445
|
+
const deliveries = kind ? (0, import_nestjs_durable_core16.lifecycleDeliveriesOf)(run, {
|
|
3069
3446
|
subscribers,
|
|
3070
3447
|
live: new Set(subscribers),
|
|
3071
3448
|
coalesced: this.engine.coalescedSubscribers(run)
|
|
3072
3449
|
}) : [];
|
|
3073
3450
|
const [own, onIt] = await Promise.all([
|
|
3074
|
-
run.status === "suspended" ? (0,
|
|
3451
|
+
run.status === "suspended" ? (0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, [
|
|
3075
3452
|
run.id
|
|
3076
3453
|
]) : [],
|
|
3077
|
-
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0,
|
|
3454
|
+
run.workflow.startsWith("__") ? [] : this.store.listSignalWaiters((0, import_nestjs_durable_core16.runWaitPrefix)(run.id))
|
|
3078
3455
|
]);
|
|
3079
3456
|
const waitsFor = own.flatMap((w) => {
|
|
3080
|
-
const target = (0,
|
|
3457
|
+
const target = (0, import_nestjs_durable_core16.runWaitTargetOf)(w);
|
|
3081
3458
|
return target !== void 0 ? [
|
|
3082
3459
|
{
|
|
3083
3460
|
runId: target,
|
|
@@ -3085,14 +3462,14 @@ var StoreRunGateway = class {
|
|
|
3085
3462
|
}
|
|
3086
3463
|
] : [];
|
|
3087
3464
|
});
|
|
3088
|
-
const awaitedBy = onIt.filter((w) => (0,
|
|
3465
|
+
const awaitedBy = onIt.filter((w) => (0, import_nestjs_durable_core16.runWaitTargetOf)(w) === run.id).map((w) => ({
|
|
3089
3466
|
runId: w.runId,
|
|
3090
3467
|
seq: w.seq
|
|
3091
3468
|
}));
|
|
3092
3469
|
const started = deliveries.flatMap((d) => d.state === "started" && d.runId !== void 0 ? [
|
|
3093
3470
|
d.runId
|
|
3094
3471
|
] : []);
|
|
3095
|
-
const { runs } = await (0,
|
|
3472
|
+
const { runs } = await (0, import_nestjs_durable_core16.readRunsByIds)(this.store, [
|
|
3096
3473
|
...source ? [
|
|
3097
3474
|
source.runId
|
|
3098
3475
|
] : [],
|
|
@@ -3109,7 +3486,7 @@ var StoreRunGateway = class {
|
|
|
3109
3486
|
} : link;
|
|
3110
3487
|
}, "withRun");
|
|
3111
3488
|
const sourceRun = source ? runs.get(source.runId) : void 0;
|
|
3112
|
-
const traceId = (0,
|
|
3489
|
+
const traceId = (0, import_nestjs_durable_core16.traceIdOfTraceparent)((0, import_nestjs_durable_core16.lifecycleTraceparentOf)(sourceRun?.tags));
|
|
3113
3490
|
return {
|
|
3114
3491
|
...triggered.length > 0 ? {
|
|
3115
3492
|
triggered
|
|
@@ -3154,12 +3531,12 @@ var StoreRunGateway = class {
|
|
|
3154
3531
|
}
|
|
3155
3532
|
async getFanMembers(runId, group, query) {
|
|
3156
3533
|
if (!await this.visibleRun(runId)) return null;
|
|
3157
|
-
if ((0,
|
|
3534
|
+
if ((0, import_nestjs_durable_core16.aggregatesCheckpoints)(this.store)) {
|
|
3158
3535
|
const stats = await this.store.checkpointStats(runId, {
|
|
3159
3536
|
group
|
|
3160
3537
|
});
|
|
3161
|
-
const etag = (0,
|
|
3162
|
-
if ((0,
|
|
3538
|
+
const etag = (0, import_nestjs_durable_core16.fanPageEtag)(group, stats, query);
|
|
3539
|
+
if ((0, import_nestjs_durable_core16.etagMatches)(query.ifNoneMatch, etag)) {
|
|
3163
3540
|
return {
|
|
3164
3541
|
items: [],
|
|
3165
3542
|
total: 0,
|
|
@@ -3168,17 +3545,17 @@ var StoreRunGateway = class {
|
|
|
3168
3545
|
};
|
|
3169
3546
|
}
|
|
3170
3547
|
return {
|
|
3171
|
-
...await (0,
|
|
3548
|
+
...await (0, import_nestjs_durable_core16.pageFanFromStore)(this.store, runId, group, query, stats),
|
|
3172
3549
|
etag
|
|
3173
3550
|
};
|
|
3174
3551
|
}
|
|
3175
|
-
return (0,
|
|
3552
|
+
return (0, import_nestjs_durable_core16.pageFan)(await this.store.listCheckpoints(runId), group, query);
|
|
3176
3553
|
}
|
|
3177
3554
|
async listRuns(query) {
|
|
3178
3555
|
const runs = await this.store.listRuns(this.scoped(withoutRegistry(query)));
|
|
3179
|
-
const waiterByRun = (0,
|
|
3556
|
+
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)));
|
|
3180
3557
|
return runs.map((run) => {
|
|
3181
|
-
const waiting = (0,
|
|
3558
|
+
const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
|
|
3182
3559
|
return waiting ? {
|
|
3183
3560
|
...run,
|
|
3184
3561
|
waiting
|
|
@@ -3195,7 +3572,7 @@ var StoreRunGateway = class {
|
|
|
3195
3572
|
const scoped = this.scoped(withoutRegistry(query));
|
|
3196
3573
|
if (this.store.runFacets) return this.store.runFacets(scoped);
|
|
3197
3574
|
const runs = await this.store.listRuns(scoped);
|
|
3198
|
-
return (0,
|
|
3575
|
+
return (0, import_nestjs_durable_core16.mergeRunFacetRows)(runs.map((r) => ({
|
|
3199
3576
|
status: r.status,
|
|
3200
3577
|
origin: r.origin,
|
|
3201
3578
|
count: 1
|
|
@@ -3230,13 +3607,13 @@ var StoreRunGateway = class {
|
|
|
3230
3607
|
"suspended"
|
|
3231
3608
|
]
|
|
3232
3609
|
})),
|
|
3233
|
-
(0,
|
|
3610
|
+
(0, import_nestjs_durable_core16.listSignalWaitersOfRuns)(this.store, runIds)
|
|
3234
3611
|
]);
|
|
3235
|
-
const waiterByRun = (0,
|
|
3612
|
+
const waiterByRun = (0, import_nestjs_durable_core16.indexWaitersByRun)(waiters);
|
|
3236
3613
|
const result = {};
|
|
3237
3614
|
for (const run of suspended) {
|
|
3238
3615
|
if (!idSet.has(run.id)) continue;
|
|
3239
|
-
const waiting = (0,
|
|
3616
|
+
const waiting = (0, import_nestjs_durable_core16.resolveRunWaiting)(run, waiterByRun);
|
|
3240
3617
|
if (waiting) result[run.id] = waiting;
|
|
3241
3618
|
}
|
|
3242
3619
|
return result;
|
|
@@ -3279,8 +3656,14 @@ var StoreRunGateway = class {
|
|
|
3279
3656
|
if (action === "trigger") return this.engine.schedules.trigger(id);
|
|
3280
3657
|
return Promise.reject(new Error(`unknown schedule action ${String(action)}`));
|
|
3281
3658
|
}
|
|
3282
|
-
signal(token, payload) {
|
|
3283
|
-
return this.engine.signal(token, payload);
|
|
3659
|
+
signal(token, payload, opts) {
|
|
3660
|
+
return this.engine.signal(token, payload, opts);
|
|
3661
|
+
}
|
|
3662
|
+
signalWithStartForTenant(start, namespace, clientTenant, signal) {
|
|
3663
|
+
return this.engine.signalWithStartForTenant(start, namespace, clientTenant, signal);
|
|
3664
|
+
}
|
|
3665
|
+
publishEventForTenant(name, payload, namespace) {
|
|
3666
|
+
return this.engine.publishEventForTenant(name, payload, namespace);
|
|
3284
3667
|
}
|
|
3285
3668
|
async signalWaiter(token) {
|
|
3286
3669
|
const waiter = (await this.store.listSignalWaiters(token)).find((w) => w.token === token);
|
|
@@ -3328,11 +3711,11 @@ var StoreRunGateway = class {
|
|
|
3328
3711
|
};
|
|
3329
3712
|
StoreRunGateway = _ts_decorate9([
|
|
3330
3713
|
(0, import_common9.Injectable)(),
|
|
3331
|
-
_ts_param6(0, (0, import_common9.Inject)(
|
|
3714
|
+
_ts_param6(0, (0, import_common9.Inject)(import_nestjs_durable_core16.STATE_STORE_CANONICAL)),
|
|
3332
3715
|
_ts_metadata9("design:type", Function),
|
|
3333
3716
|
_ts_metadata9("design:paramtypes", [
|
|
3334
3717
|
typeof StateStore === "undefined" ? Object : StateStore,
|
|
3335
|
-
typeof
|
|
3718
|
+
typeof import_nestjs_durable_core16.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core16.WorkflowEngine
|
|
3336
3719
|
])
|
|
3337
3720
|
], StoreRunGateway);
|
|
3338
3721
|
|
|
@@ -3379,7 +3762,7 @@ var TenantEventRepublisher = class {
|
|
|
3379
3762
|
|
|
3380
3763
|
// src/timer-poller.ts
|
|
3381
3764
|
var durableCore = __toESM(require("@dudousxd/nestjs-durable-core"), 1);
|
|
3382
|
-
var
|
|
3765
|
+
var import_nestjs_durable_core17 = require("@dudousxd/nestjs-durable-core");
|
|
3383
3766
|
var import_common10 = require("@nestjs/common");
|
|
3384
3767
|
function _ts_decorate10(decorators, target, key, desc) {
|
|
3385
3768
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3438,7 +3821,7 @@ var TimerPoller = class {
|
|
|
3438
3821
|
this.leases = leases;
|
|
3439
3822
|
}
|
|
3440
3823
|
async onApplicationBootstrap() {
|
|
3441
|
-
for (const s of this.options.schedules ?? []) (0,
|
|
3824
|
+
for (const s of this.options.schedules ?? []) (0, import_nestjs_durable_core17.workflowName)(s.workflow);
|
|
3442
3825
|
if (!isDrivingOperator(this.options)) return;
|
|
3443
3826
|
this.engine.consumeRuns?.();
|
|
3444
3827
|
this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
|
|
@@ -3635,7 +4018,7 @@ var TimerPoller = class {
|
|
|
3635
4018
|
}));
|
|
3636
4019
|
const schedules = this.options.schedules;
|
|
3637
4020
|
if (schedules && schedules.length > 0) {
|
|
3638
|
-
note(await this.sweep("schedules", () => (0,
|
|
4021
|
+
note(await this.sweep("schedules", () => (0, import_nestjs_durable_core17.runSchedules)(this.engine, schedules, Date.now())));
|
|
3639
4022
|
}
|
|
3640
4023
|
const announced = this.announcedSchedules();
|
|
3641
4024
|
if (announced) {
|
|
@@ -3656,7 +4039,7 @@ var TimerPoller = class {
|
|
|
3656
4039
|
note(await this.sweep("persistedSchedules", () => this.engine.schedules.tick()));
|
|
3657
4040
|
} else if (announced) {
|
|
3658
4041
|
note(await this.sweep("announcedScheduleFires", () => this.engine.schedules.tick(Date.now(), {
|
|
3659
|
-
tag:
|
|
4042
|
+
tag: import_nestjs_durable_core17.ANNOUNCED_SCHEDULE_TAG
|
|
3660
4043
|
})));
|
|
3661
4044
|
}
|
|
3662
4045
|
return worked;
|
|
@@ -3673,36 +4056,20 @@ var TimerPoller = class {
|
|
|
3673
4056
|
};
|
|
3674
4057
|
TimerPoller = _ts_decorate10([
|
|
3675
4058
|
(0, import_common10.Injectable)(),
|
|
3676
|
-
_ts_param7(1, (0, import_common10.Inject)(
|
|
4059
|
+
_ts_param7(1, (0, import_common10.Inject)(import_nestjs_durable_core17.DURABLE_OPTIONS_CANONICAL)),
|
|
3677
4060
|
_ts_param7(2, (0, import_common10.Optional)()),
|
|
3678
4061
|
_ts_metadata10("design:type", Function),
|
|
3679
4062
|
_ts_metadata10("design:paramtypes", [
|
|
3680
|
-
typeof
|
|
4063
|
+
typeof import_nestjs_durable_core17.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core17.WorkflowEngine,
|
|
3681
4064
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
3682
4065
|
typeof SweepLeases === "undefined" ? Object : SweepLeases
|
|
3683
4066
|
])
|
|
3684
4067
|
], TimerPoller);
|
|
3685
4068
|
|
|
3686
4069
|
// src/workflow.registrar.ts
|
|
3687
|
-
var
|
|
4070
|
+
var import_nestjs_durable_core18 = require("@dudousxd/nestjs-durable-core");
|
|
3688
4071
|
var import_common11 = require("@nestjs/common");
|
|
3689
4072
|
var import_core5 = require("@nestjs/core");
|
|
3690
|
-
|
|
3691
|
-
// src/step-interceptor.ts
|
|
3692
|
-
var import_reflect_metadata3 = require("reflect-metadata");
|
|
3693
|
-
var STEP_INTERCEPTOR_METADATA = Symbol("nestjs-durable:step-interceptor");
|
|
3694
|
-
function StepInterceptor() {
|
|
3695
|
-
return (target) => {
|
|
3696
|
-
Reflect.defineMetadata(STEP_INTERCEPTOR_METADATA, true, target);
|
|
3697
|
-
};
|
|
3698
|
-
}
|
|
3699
|
-
__name(StepInterceptor, "StepInterceptor");
|
|
3700
|
-
function isStepInterceptor(target) {
|
|
3701
|
-
return Reflect.getMetadata(STEP_INTERCEPTOR_METADATA, target) === true;
|
|
3702
|
-
}
|
|
3703
|
-
__name(isStepInterceptor, "isStepInterceptor");
|
|
3704
|
-
|
|
3705
|
-
// src/workflow.registrar.ts
|
|
3706
4073
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
3707
4074
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3708
4075
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -3810,7 +4177,8 @@ var WorkflowRegistrar = class {
|
|
|
3810
4177
|
concurrency: meta.concurrency,
|
|
3811
4178
|
executionTimeout: meta.executionTimeout,
|
|
3812
4179
|
requires: meta.requires,
|
|
3813
|
-
validateInput: io.
|
|
4180
|
+
validateInput: io.validateParsed,
|
|
4181
|
+
parseInput: io.parseInput,
|
|
3814
4182
|
searchAttributesSchema: meta.searchAttributes,
|
|
3815
4183
|
onEvent: getOnEvents(meta, workflowCtor),
|
|
3816
4184
|
eventBatch,
|
|
@@ -3825,11 +4193,11 @@ var WorkflowRegistrar = class {
|
|
|
3825
4193
|
// so a turn dispatched under the wrong token would never be consumed. Absent → the inline fast
|
|
3826
4194
|
// path (unchanged).
|
|
3827
4195
|
...this.inAppWorker ? {
|
|
3828
|
-
group: (0,
|
|
3829
|
-
executor: new
|
|
4196
|
+
group: (0, import_nestjs_durable_core18.tenantGroup)((0, import_nestjs_durable_core18.sanitizeQueueToken)(meta.name), this.inAppWorker.partition),
|
|
4197
|
+
executor: new import_nestjs_durable_core18.RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
|
|
3830
4198
|
} : {}
|
|
3831
4199
|
});
|
|
3832
|
-
(0,
|
|
4200
|
+
(0, import_nestjs_durable_core18.bindWorkflowClass)(workflowCtor, {
|
|
3833
4201
|
start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
|
|
3834
4202
|
waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
|
|
3835
4203
|
});
|
|
@@ -3844,7 +4212,7 @@ var WorkflowRegistrar = class {
|
|
|
3844
4212
|
});
|
|
3845
4213
|
deadLetterByWorkflow.set(meta.name, dlqName);
|
|
3846
4214
|
} else if (meta.deadLetterWorkflow) {
|
|
3847
|
-
deadLetterByWorkflow.set(meta.name, (0,
|
|
4215
|
+
deadLetterByWorkflow.set(meta.name, (0, import_nestjs_durable_core18.workflowName)(meta.deadLetterWorkflow));
|
|
3848
4216
|
}
|
|
3849
4217
|
});
|
|
3850
4218
|
this.reportUnattributed(unattributed);
|
|
@@ -3892,39 +4260,47 @@ var WorkflowRegistrar = class {
|
|
|
3892
4260
|
* a `dlq:<runId>` id, so re-recovery never double-dispatches.
|
|
3893
4261
|
*/
|
|
3894
4262
|
installDeadLetterRouting(byWorkflow) {
|
|
3895
|
-
const fallback = this.options.deadLetterWorkflow ? (0,
|
|
4263
|
+
const fallback = this.options.deadLetterWorkflow ? (0, import_nestjs_durable_core18.workflowName)(this.options.deadLetterWorkflow) : void 0;
|
|
3896
4264
|
if (byWorkflow.size === 0 && !fallback) return;
|
|
3897
4265
|
this.engine.onDead((run) => {
|
|
3898
|
-
|
|
3899
|
-
if (!target) return;
|
|
3900
|
-
void this.engine.start(
|
|
3901
|
-
target,
|
|
3902
|
-
{
|
|
3903
|
-
deadRunId: run.id,
|
|
3904
|
-
workflow: run.workflow,
|
|
3905
|
-
input: run.input,
|
|
3906
|
-
error: run.error
|
|
3907
|
-
},
|
|
3908
|
-
`dlq:${run.id}`,
|
|
3909
|
-
// Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
|
|
3910
|
-
// that tenant's worker group (`target@<tenant>`), not the bare group.
|
|
3911
|
-
{
|
|
3912
|
-
namespace: run.namespace
|
|
3913
|
-
}
|
|
3914
|
-
).catch(() => void 0);
|
|
4266
|
+
void this.routeDead(run, byWorkflow, fallback).catch(() => void 0);
|
|
3915
4267
|
});
|
|
3916
4268
|
}
|
|
4269
|
+
/** {@link installDeadLetterRouting}'s routing of one dead run. */
|
|
4270
|
+
async routeDead(run, byWorkflow, fallback) {
|
|
4271
|
+
let target = byWorkflow.get(run.workflow);
|
|
4272
|
+
if (!target && fallback) {
|
|
4273
|
+
if (await this.engine.announcedDeadLetter?.(run).catch(() => void 0)) return;
|
|
4274
|
+
target = fallback;
|
|
4275
|
+
}
|
|
4276
|
+
if (!target) return;
|
|
4277
|
+
await this.engine.start(
|
|
4278
|
+
target,
|
|
4279
|
+
{
|
|
4280
|
+
deadRunId: run.id,
|
|
4281
|
+
workflow: run.workflow,
|
|
4282
|
+
input: run.input,
|
|
4283
|
+
error: run.error
|
|
4284
|
+
},
|
|
4285
|
+
`dlq:${run.id}`,
|
|
4286
|
+
// Route the dead-letter handler to the dead run's OWN tenant so an operator dispatches it to
|
|
4287
|
+
// that tenant's worker group (`target@<tenant>`), not the bare group.
|
|
4288
|
+
{
|
|
4289
|
+
namespace: run.namespace
|
|
4290
|
+
}
|
|
4291
|
+
).catch(() => void 0);
|
|
4292
|
+
}
|
|
3917
4293
|
};
|
|
3918
4294
|
WorkflowRegistrar = _ts_decorate11([
|
|
3919
4295
|
(0, import_common11.Injectable)(),
|
|
3920
|
-
_ts_param8(3, (0, import_common11.Inject)(
|
|
3921
|
-
_ts_param8(4, (0, import_common11.Inject)(
|
|
4296
|
+
_ts_param8(3, (0, import_common11.Inject)(import_nestjs_durable_core18.STATE_STORE_CANONICAL)),
|
|
4297
|
+
_ts_param8(4, (0, import_common11.Inject)(import_nestjs_durable_core18.DURABLE_OPTIONS_CANONICAL)),
|
|
3922
4298
|
_ts_param8(5, (0, import_common11.Inject)(IN_APP_WORKER_BINDING)),
|
|
3923
4299
|
_ts_metadata11("design:type", Function),
|
|
3924
4300
|
_ts_metadata11("design:paramtypes", [
|
|
3925
4301
|
typeof import_core5.DiscoveryService === "undefined" ? Object : import_core5.DiscoveryService,
|
|
3926
4302
|
typeof import_core5.MetadataScanner === "undefined" ? Object : import_core5.MetadataScanner,
|
|
3927
|
-
typeof
|
|
4303
|
+
typeof import_nestjs_durable_core18.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core18.WorkflowEngine,
|
|
3928
4304
|
Object,
|
|
3929
4305
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
3930
4306
|
Object
|
|
@@ -3933,7 +4309,7 @@ WorkflowRegistrar = _ts_decorate11([
|
|
|
3933
4309
|
|
|
3934
4310
|
// src/workflow.service.ts
|
|
3935
4311
|
var import_node_crypto = require("crypto");
|
|
3936
|
-
var
|
|
4312
|
+
var import_nestjs_durable_core19 = require("@dudousxd/nestjs-durable-core");
|
|
3937
4313
|
var import_common12 = require("@nestjs/common");
|
|
3938
4314
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
3939
4315
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4024,7 +4400,7 @@ WorkflowService = _ts_decorate12([
|
|
|
4024
4400
|
(0, import_common12.Injectable)(),
|
|
4025
4401
|
_ts_metadata12("design:type", Function),
|
|
4026
4402
|
_ts_metadata12("design:paramtypes", [
|
|
4027
|
-
typeof
|
|
4403
|
+
typeof import_nestjs_durable_core19.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core19.WorkflowEngine
|
|
4028
4404
|
])
|
|
4029
4405
|
], WorkflowService);
|
|
4030
4406
|
|
|
@@ -4253,15 +4629,15 @@ var RunGatewayBootstrap = class RunGatewayBootstrap2 {
|
|
|
4253
4629
|
};
|
|
4254
4630
|
RunGatewayBootstrap = _ts_decorate13([
|
|
4255
4631
|
(0, import_common13.Injectable)(),
|
|
4256
|
-
_ts_param9(1, (0, import_common13.Inject)(
|
|
4257
|
-
_ts_param9(3, (0, import_common13.Inject)(
|
|
4258
|
-
_ts_param9(4, (0, import_common13.Inject)(
|
|
4632
|
+
_ts_param9(1, (0, import_common13.Inject)(import_nestjs_durable_core20.TRANSPORT_CANONICAL)),
|
|
4633
|
+
_ts_param9(3, (0, import_common13.Inject)(import_nestjs_durable_core20.STATE_STORE_CANONICAL)),
|
|
4634
|
+
_ts_param9(4, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
|
|
4259
4635
|
_ts_param9(5, (0, import_common13.Inject)(TENANT_AUTH)),
|
|
4260
4636
|
_ts_metadata13("design:type", Function),
|
|
4261
4637
|
_ts_metadata13("design:paramtypes", [
|
|
4262
|
-
typeof
|
|
4638
|
+
typeof import_nestjs_durable_core20.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core20.WorkflowEngine,
|
|
4263
4639
|
Object,
|
|
4264
|
-
typeof
|
|
4640
|
+
typeof import_nestjs_durable_core20.RunGateway === "undefined" ? Object : import_nestjs_durable_core20.RunGateway,
|
|
4265
4641
|
Object,
|
|
4266
4642
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
4267
4643
|
typeof ResolvedTenantAuth === "undefined" ? Object : ResolvedTenantAuth
|
|
@@ -4284,7 +4660,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
|
|
|
4284
4660
|
if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
|
|
4285
4661
|
const runtime = await resolveContextRuntime();
|
|
4286
4662
|
if (!canRestoreTenant(runtime)) return;
|
|
4287
|
-
this.unregister = (0,
|
|
4663
|
+
this.unregister = (0, import_nestjs_durable_core20.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
|
|
4288
4664
|
}
|
|
4289
4665
|
onModuleDestroy() {
|
|
4290
4666
|
this.unregister?.();
|
|
@@ -4292,7 +4668,7 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
|
|
|
4292
4668
|
};
|
|
4293
4669
|
DurableTenancyBridge = _ts_decorate13([
|
|
4294
4670
|
(0, import_common13.Injectable)(),
|
|
4295
|
-
_ts_param9(0, (0, import_common13.Inject)(
|
|
4671
|
+
_ts_param9(0, (0, import_common13.Inject)(import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL)),
|
|
4296
4672
|
_ts_metadata13("design:type", Function),
|
|
4297
4673
|
_ts_metadata13("design:paramtypes", [
|
|
4298
4674
|
typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
|
|
@@ -4304,17 +4680,17 @@ var DurableModule = class _DurableModule {
|
|
|
4304
4680
|
__name(this, "DurableModule");
|
|
4305
4681
|
}
|
|
4306
4682
|
static forRoot(options) {
|
|
4307
|
-
(0,
|
|
4683
|
+
(0, import_nestjs_durable_core20.sealDurableCopies)();
|
|
4308
4684
|
_DurableModule.assertValid(options);
|
|
4309
4685
|
return _DurableModule.build({
|
|
4310
|
-
provide:
|
|
4686
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4311
4687
|
useValue: resolveTopology(options)
|
|
4312
4688
|
});
|
|
4313
4689
|
}
|
|
4314
4690
|
static forRootAsync(options) {
|
|
4315
|
-
(0,
|
|
4691
|
+
(0, import_nestjs_durable_core20.sealDurableCopies)();
|
|
4316
4692
|
return _DurableModule.build({
|
|
4317
|
-
provide:
|
|
4693
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4318
4694
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
4319
4695
|
const resolved = await options.useFactory(...args);
|
|
4320
4696
|
_DurableModule.assertValid(resolved);
|
|
@@ -4337,21 +4713,21 @@ var DurableModule = class _DurableModule {
|
|
|
4337
4713
|
providers: [
|
|
4338
4714
|
optionsProvider,
|
|
4339
4715
|
{
|
|
4340
|
-
provide:
|
|
4716
|
+
provide: import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4341
4717
|
useFactory: /* @__PURE__ */ __name((options) => options.store !== void 0 ? scopedStore(options.store, options) : null, "useFactory"),
|
|
4342
4718
|
inject: [
|
|
4343
|
-
|
|
4719
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4344
4720
|
]
|
|
4345
4721
|
},
|
|
4346
4722
|
{
|
|
4347
|
-
provide:
|
|
4723
|
+
provide: import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4348
4724
|
// With a POOL (`transports`) and no singular `transport`, the canonical transport is the
|
|
4349
4725
|
// pool's PRIMARY — the same one the engine dispatches on first. Leaving it null starved
|
|
4350
4726
|
// the step registrar / in-app worker of a transport, so a pool-configured operator
|
|
4351
4727
|
// registered NO step handlers and its own steps parked in `wait` with no consumer.
|
|
4352
4728
|
useFactory: /* @__PURE__ */ __name((options) => options.transport ?? options.transports?.[0]?.transport ?? null, "useFactory"),
|
|
4353
4729
|
inject: [
|
|
4354
|
-
|
|
4730
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4355
4731
|
]
|
|
4356
4732
|
},
|
|
4357
4733
|
{
|
|
@@ -4361,36 +4737,53 @@ var DurableModule = class _DurableModule {
|
|
|
4361
4737
|
tenantToken: resolveTenantTokenSource(options.tenantToken, moduleRef)
|
|
4362
4738
|
}), "useFactory"),
|
|
4363
4739
|
inject: [
|
|
4364
|
-
|
|
4740
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4365
4741
|
import_core6.ModuleRef
|
|
4366
4742
|
]
|
|
4367
4743
|
},
|
|
4368
4744
|
// Deprecated tokens that published releases still import resolve to the same instances:
|
|
4369
4745
|
{
|
|
4370
|
-
provide:
|
|
4371
|
-
useExisting:
|
|
4746
|
+
provide: import_nestjs_durable_core20.STATE_STORE,
|
|
4747
|
+
useExisting: import_nestjs_durable_core20.STATE_STORE_CANONICAL
|
|
4372
4748
|
},
|
|
4373
4749
|
{
|
|
4374
|
-
provide:
|
|
4375
|
-
useExisting:
|
|
4750
|
+
provide: import_nestjs_durable_core20.TRANSPORT,
|
|
4751
|
+
useExisting: import_nestjs_durable_core20.TRANSPORT_CANONICAL
|
|
4376
4752
|
},
|
|
4377
4753
|
{
|
|
4378
|
-
provide:
|
|
4379
|
-
useExisting:
|
|
4754
|
+
provide: import_nestjs_durable_core20.DURABLE_OPTIONS,
|
|
4755
|
+
useExisting: import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL
|
|
4380
4756
|
},
|
|
4381
4757
|
{
|
|
4382
4758
|
// Shared token, bound EXACTLY once: a real engine for the operator role, or a store-less
|
|
4383
4759
|
// `DurableStartClient` facade for a thin worker (no `store`) — either way, `WorkflowService`
|
|
4384
4760
|
// and app code call `engine.start(...)` unchanged.
|
|
4385
|
-
provide:
|
|
4761
|
+
provide: import_nestjs_durable_core20.WorkflowEngine,
|
|
4386
4762
|
useFactory: /* @__PURE__ */ __name(async (options, store, transport, moduleRef, auth) => {
|
|
4387
4763
|
if (options.store === void 0) {
|
|
4388
|
-
return new DurableStartClient(
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4764
|
+
return new DurableStartClient(
|
|
4765
|
+
{
|
|
4766
|
+
...options,
|
|
4767
|
+
...auth.tenantToken !== void 0 ? {
|
|
4768
|
+
tenantToken: auth.tenantToken
|
|
4769
|
+
} : {}
|
|
4770
|
+
},
|
|
4771
|
+
void 0,
|
|
4772
|
+
resolveAccessor(moduleRef),
|
|
4773
|
+
// `signal`/`signalWithStart`/`publishEvent` go to the control plane as run requests,
|
|
4774
|
+
// over the one `ProxyRunGateway` bound under `RunGateway` (it owns the reply
|
|
4775
|
+
// subscription). Resolved lazily: that gateway is built after this facade.
|
|
4776
|
+
() => {
|
|
4777
|
+
try {
|
|
4778
|
+
const gateway = moduleRef.get(import_nestjs_durable_core20.RunGateway, {
|
|
4779
|
+
strict: false
|
|
4780
|
+
});
|
|
4781
|
+
return gateway instanceof ProxyRunGateway ? gateway : void 0;
|
|
4782
|
+
} catch {
|
|
4783
|
+
return void 0;
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
);
|
|
4394
4787
|
}
|
|
4395
4788
|
if (!store) {
|
|
4396
4789
|
throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
|
|
@@ -4409,7 +4802,7 @@ var DurableModule = class _DurableModule {
|
|
|
4409
4802
|
if (t) deferTransportConsumers(t);
|
|
4410
4803
|
}
|
|
4411
4804
|
}
|
|
4412
|
-
const engine = new
|
|
4805
|
+
const engine = new import_nestjs_durable_core20.WorkflowEngine({
|
|
4413
4806
|
store,
|
|
4414
4807
|
transport: transport ?? void 0,
|
|
4415
4808
|
transports: options.transports,
|
|
@@ -4458,9 +4851,9 @@ var DurableModule = class _DurableModule {
|
|
|
4458
4851
|
return engine;
|
|
4459
4852
|
}, "useFactory"),
|
|
4460
4853
|
inject: [
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4854
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4855
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4856
|
+
import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4464
4857
|
import_core6.ModuleRef,
|
|
4465
4858
|
TENANT_AUTH
|
|
4466
4859
|
]
|
|
@@ -4476,7 +4869,7 @@ var DurableModule = class _DurableModule {
|
|
|
4476
4869
|
// or (for a thin worker, no `store`) a `ProxyRunGateway` over `transport` when given, else a
|
|
4477
4870
|
// gateway whose every method rejects with a clear tenant error.
|
|
4478
4871
|
{
|
|
4479
|
-
provide:
|
|
4872
|
+
provide: import_nestjs_durable_core20.RunGateway,
|
|
4480
4873
|
useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
|
|
4481
4874
|
if (options.store !== void 0) {
|
|
4482
4875
|
if (!store) {
|
|
@@ -4487,9 +4880,9 @@ var DurableModule = class _DurableModule {
|
|
|
4487
4880
|
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();
|
|
4488
4881
|
}, "useFactory"),
|
|
4489
4882
|
inject: [
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4883
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4884
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4885
|
+
import_nestjs_durable_core20.WorkflowEngine,
|
|
4493
4886
|
TENANT_AUTH,
|
|
4494
4887
|
import_core6.ModuleRef
|
|
4495
4888
|
]
|
|
@@ -4506,13 +4899,13 @@ var DurableModule = class _DurableModule {
|
|
|
4506
4899
|
exports: [
|
|
4507
4900
|
WorkflowService,
|
|
4508
4901
|
EntityService,
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4902
|
+
import_nestjs_durable_core20.WorkflowEngine,
|
|
4903
|
+
import_nestjs_durable_core20.STATE_STORE,
|
|
4904
|
+
import_nestjs_durable_core20.STATE_STORE_CANONICAL,
|
|
4905
|
+
import_nestjs_durable_core20.TRANSPORT,
|
|
4906
|
+
import_nestjs_durable_core20.TRANSPORT_CANONICAL,
|
|
4907
|
+
import_nestjs_durable_core20.DURABLE_OPTIONS_CANONICAL,
|
|
4908
|
+
import_nestjs_durable_core20.RunGateway
|
|
4516
4909
|
]
|
|
4517
4910
|
};
|
|
4518
4911
|
}
|
|
@@ -4522,7 +4915,7 @@ DurableModule = _ts_decorate13([
|
|
|
4522
4915
|
], DurableModule);
|
|
4523
4916
|
|
|
4524
4917
|
// src/federated-app-gateway.ts
|
|
4525
|
-
var
|
|
4918
|
+
var import_nestjs_durable_core21 = require("@dudousxd/nestjs-durable-core");
|
|
4526
4919
|
var FederatedAppGateway = class {
|
|
4527
4920
|
static {
|
|
4528
4921
|
__name(this, "FederatedAppGateway");
|
|
@@ -4537,7 +4930,7 @@ var FederatedAppGateway = class {
|
|
|
4537
4930
|
tailing = false;
|
|
4538
4931
|
constructor(options) {
|
|
4539
4932
|
this.options = options;
|
|
4540
|
-
this.reads = new StoreRunGateway(options.store, new
|
|
4933
|
+
this.reads = new StoreRunGateway(options.store, new import_nestjs_durable_core21.WorkflowEngine({
|
|
4541
4934
|
store: options.store
|
|
4542
4935
|
}));
|
|
4543
4936
|
this.timeoutMs = options.timeoutMs ?? 1e4;
|
|
@@ -4782,7 +5175,7 @@ function federatedAppGateway(options) {
|
|
|
4782
5175
|
__name(federatedAppGateway, "federatedAppGateway");
|
|
4783
5176
|
|
|
4784
5177
|
// src/index.ts
|
|
4785
|
-
var
|
|
5178
|
+
var import_nestjs_durable_core22 = require("@dudousxd/nestjs-durable-core");
|
|
4786
5179
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4787
5180
|
0 && (module.exports = {
|
|
4788
5181
|
BAD_RUN_REQUEST,
|