@dudousxd/nestjs-durable-core 0.92.0 → 0.94.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 +355 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -5
- package/dist/index.d.ts +115 -5
- package/dist/index.js +347 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
DURABLE_OPTIONS_CANONICAL: () => DURABLE_OPTIONS_CANONICAL,
|
|
39
39
|
DURABLE_STEP_CONFIG: () => DURABLE_STEP_CONFIG,
|
|
40
40
|
DURABLE_STEP_NAME: () => DURABLE_STEP_NAME,
|
|
41
|
+
DuplicateDurableCopyError: () => DuplicateDurableCopyError,
|
|
41
42
|
DurableWorkflow: () => DurableWorkflow,
|
|
42
43
|
ENGINE_MINTED_TAG_PREFIXES: () => ENGINE_MINTED_TAG_PREFIXES,
|
|
43
44
|
ENTITY_WORKFLOW: () => ENTITY_WORKFLOW,
|
|
@@ -81,6 +82,7 @@ __export(index_exports, {
|
|
|
81
82
|
RemoteStepTimeout: () => RemoteStepTimeout,
|
|
82
83
|
RemoteWorkflowExecutor: () => RemoteWorkflowExecutor,
|
|
83
84
|
RemoteWorkflowTimeout: () => RemoteWorkflowTimeout,
|
|
85
|
+
RunAppStamper: () => RunAppStamper,
|
|
84
86
|
RunGateway: () => RunGateway,
|
|
85
87
|
SINGLETON_ACTIVE_STATUSES: () => SINGLETON_ACTIVE_STATUSES,
|
|
86
88
|
SINGLETON_ADMITTED_TAG: () => SINGLETON_ADMITTED_TAG,
|
|
@@ -114,6 +116,7 @@ __export(index_exports, {
|
|
|
114
116
|
applyAttributeQuery: () => applyAttributeQuery,
|
|
115
117
|
assertConcurrency: () => assertConcurrency,
|
|
116
118
|
assertRoutes: () => assertRoutes,
|
|
119
|
+
assertSingleDurableCopy: () => assertSingleDurableCopy,
|
|
117
120
|
attributeColumnFor: () => attributeColumnFor,
|
|
118
121
|
attributeOperand: () => attributeOperand,
|
|
119
122
|
attributePredicateOperands: () => attributePredicateOperands,
|
|
@@ -136,6 +139,7 @@ __export(index_exports, {
|
|
|
136
139
|
codeOf: () => codeOf,
|
|
137
140
|
collectMetrics: () => collectMetrics,
|
|
138
141
|
concurrencyTag: () => concurrencyTag,
|
|
142
|
+
controlPlaneAttribution: () => controlPlaneAttribution,
|
|
139
143
|
controlPlaneDescriptor: () => controlPlaneDescriptor,
|
|
140
144
|
countRuns: () => countRuns,
|
|
141
145
|
coveredTokens: () => coveredTokens,
|
|
@@ -147,6 +151,7 @@ __export(index_exports, {
|
|
|
147
151
|
describeWorker: () => describeWorker,
|
|
148
152
|
descriptorHash: () => descriptorHash,
|
|
149
153
|
detailsOf: () => detailsOf,
|
|
154
|
+
durableCopies: () => durableCopies,
|
|
150
155
|
error: () => error,
|
|
151
156
|
etagMatches: () => etagMatches,
|
|
152
157
|
eventMatchOf: () => eventMatchOf,
|
|
@@ -244,6 +249,7 @@ __export(index_exports, {
|
|
|
244
249
|
runOutsideWorkflowCtx: () => runOutsideWorkflowCtx,
|
|
245
250
|
runSchedules: () => runSchedules,
|
|
246
251
|
runStepHandler: () => runStepHandler,
|
|
252
|
+
runTraceId: () => runTraceId,
|
|
247
253
|
runValueFacetsFromRuns: () => runValueFacetsFromRuns,
|
|
248
254
|
runWaitPrefix: () => runWaitPrefix,
|
|
249
255
|
runWaitTargetOf: () => runWaitTargetOf,
|
|
@@ -253,6 +259,7 @@ __export(index_exports, {
|
|
|
253
259
|
scheduledRunId: () => scheduledRunId,
|
|
254
260
|
scopeBufferedEvent: () => scopeBufferedEvent,
|
|
255
261
|
scopeTenantQuery: () => scopeTenantQuery,
|
|
262
|
+
sealDurableCopies: () => sealDurableCopies,
|
|
256
263
|
settleResultsWithPlainCalls: () => settleResultsWithPlainCalls,
|
|
257
264
|
signTenantToken: () => signTenantToken,
|
|
258
265
|
singletonAdmissionDenialPatch: () => singletonAdmissionDenialPatch,
|
|
@@ -268,6 +275,7 @@ __export(index_exports, {
|
|
|
268
275
|
summarizeFan: () => summarizeFan,
|
|
269
276
|
summarizeRunFromStore: () => summarizeRunFromStore,
|
|
270
277
|
summarizeTimeline: () => summarizeTimeline,
|
|
278
|
+
tenantAppOf: () => tenantAppOf,
|
|
271
279
|
tenantGroup: () => tenantGroup,
|
|
272
280
|
tenantIdsFor: () => tenantIdsFor,
|
|
273
281
|
tenantVisible: () => tenantVisible,
|
|
@@ -384,16 +392,16 @@ var QueueController = class {
|
|
|
384
392
|
* A bare item (no waiterId) is compared on its hints directly.
|
|
385
393
|
*/
|
|
386
394
|
isNext(waiterId, item) {
|
|
387
|
-
const
|
|
395
|
+
const self2 = (waiterId != null ? this.waiters.get(waiterId) : void 0) ?? {
|
|
388
396
|
priority: item?.priority ?? 0,
|
|
389
397
|
key: item?.key,
|
|
390
398
|
seq: Number.POSITIVE_INFINITY
|
|
391
399
|
};
|
|
392
|
-
let best =
|
|
400
|
+
let best = self2;
|
|
393
401
|
for (const w of this.waiters.values()) {
|
|
394
402
|
if (this.better(w, best)) best = w;
|
|
395
403
|
}
|
|
396
|
-
return best ===
|
|
404
|
+
return best === self2;
|
|
397
405
|
}
|
|
398
406
|
/** Strict "a should be admitted before b" comparison under the active policy. */
|
|
399
407
|
better(a, b) {
|
|
@@ -847,6 +855,113 @@ function parseDuration(duration) {
|
|
|
847
855
|
}
|
|
848
856
|
__name(parseDuration, "parseDuration");
|
|
849
857
|
|
|
858
|
+
// src/copy-guard.ts
|
|
859
|
+
var import_node_fs = require("fs");
|
|
860
|
+
var import_node_path = require("path");
|
|
861
|
+
var import_node_url = require("url");
|
|
862
|
+
|
|
863
|
+
// src/origin.ts
|
|
864
|
+
var CORE_ORIGIN = "@dudousxd/nestjs-durable-core";
|
|
865
|
+
|
|
866
|
+
// src/copy-guard.ts
|
|
867
|
+
var DURABLE_COPIES_KEY = Symbol.for("@dudousxd/nestjs-durable.copies");
|
|
868
|
+
var DUPLICATE_COPY_DOCS = "https://davidecarvalho.github.io/aviary/docs/durable/troubleshooting#two-copies-of-dudousxdnestjs-durable-core";
|
|
869
|
+
var DUPLICATE_COPY_FIX = `Make every package resolve one copy: declare the same peer dependency versions in the app as in the workspace packages that depend on ${CORE_ORIGIN} (or pin them with pnpm overrides), reinstall, and check that \`pnpm why ${CORE_ORIGIN}\` shows a single variant.`;
|
|
870
|
+
var DuplicateDurableCopyError = class extends Error {
|
|
871
|
+
static {
|
|
872
|
+
__name(this, "DuplicateDurableCopyError");
|
|
873
|
+
}
|
|
874
|
+
copies;
|
|
875
|
+
constructor(copies) {
|
|
876
|
+
super(duplicateCopyMessage(copies));
|
|
877
|
+
this.name = "DuplicateDurableCopyError";
|
|
878
|
+
this.copies = copies;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
function duplicateCopyMessage(copies) {
|
|
882
|
+
const list2 = copies.map((c) => ` - ${c.version} at ${c.root}`).join("\n");
|
|
883
|
+
return [
|
|
884
|
+
`${CORE_ORIGIN} is loaded ${copies.length} times, from different installs:`,
|
|
885
|
+
list2,
|
|
886
|
+
"Each copy has its own WorkflowEngine class, so code from one copy cannot resolve the engine the other copy registered (Nest cannot inject `WorkflowEngine`, `instanceof` checks fail, and workflows registered on one engine are unknown to the other).",
|
|
887
|
+
DUPLICATE_COPY_FIX,
|
|
888
|
+
`See ${DUPLICATE_COPY_DOCS}`
|
|
889
|
+
].join("\n");
|
|
890
|
+
}
|
|
891
|
+
__name(duplicateCopyMessage, "duplicateCopyMessage");
|
|
892
|
+
function durableCopyRegistry() {
|
|
893
|
+
const slot = globalThis;
|
|
894
|
+
const existing = slot[DURABLE_COPIES_KEY];
|
|
895
|
+
if (existing?.copies instanceof Map) return existing;
|
|
896
|
+
const fresh = {
|
|
897
|
+
copies: /* @__PURE__ */ new Map(),
|
|
898
|
+
booted: false
|
|
899
|
+
};
|
|
900
|
+
slot[DURABLE_COPIES_KEY] = fresh;
|
|
901
|
+
return fresh;
|
|
902
|
+
}
|
|
903
|
+
__name(durableCopyRegistry, "durableCopyRegistry");
|
|
904
|
+
function durableCopies(registry = durableCopyRegistry()) {
|
|
905
|
+
return [
|
|
906
|
+
...registry.copies.values()
|
|
907
|
+
];
|
|
908
|
+
}
|
|
909
|
+
__name(durableCopies, "durableCopies");
|
|
910
|
+
function registerDurableCopy(copy, registry = durableCopyRegistry()) {
|
|
911
|
+
if (registry.copies.has(copy.root)) return;
|
|
912
|
+
registry.copies.set(copy.root, copy);
|
|
913
|
+
if (registry.booted) assertSingleDurableCopy(registry);
|
|
914
|
+
}
|
|
915
|
+
__name(registerDurableCopy, "registerDurableCopy");
|
|
916
|
+
function assertSingleDurableCopy(registry = durableCopyRegistry()) {
|
|
917
|
+
const copies = durableCopies(registry);
|
|
918
|
+
if (copies.length > 1) throw new DuplicateDurableCopyError(copies);
|
|
919
|
+
}
|
|
920
|
+
__name(assertSingleDurableCopy, "assertSingleDurableCopy");
|
|
921
|
+
function sealDurableCopies(registry = durableCopyRegistry()) {
|
|
922
|
+
assertSingleDurableCopy(registry);
|
|
923
|
+
registry.booted = true;
|
|
924
|
+
}
|
|
925
|
+
__name(sealDurableCopies, "sealDurableCopies");
|
|
926
|
+
function thisCopy() {
|
|
927
|
+
let start;
|
|
928
|
+
try {
|
|
929
|
+
start = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(__importMetaUrl));
|
|
930
|
+
} catch {
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
let dir = start;
|
|
934
|
+
for (; ; ) {
|
|
935
|
+
try {
|
|
936
|
+
const pkg = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.join)(dir, "package.json"), "utf8"));
|
|
937
|
+
if (pkg.name === CORE_ORIGIN) {
|
|
938
|
+
return {
|
|
939
|
+
version: typeof pkg.version === "string" ? pkg.version : "unknown",
|
|
940
|
+
root: realPath(dir)
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
} catch {
|
|
944
|
+
}
|
|
945
|
+
const parent = (0, import_node_path.dirname)(dir);
|
|
946
|
+
if (parent === dir) return {
|
|
947
|
+
version: "unknown",
|
|
948
|
+
root: realPath(start)
|
|
949
|
+
};
|
|
950
|
+
dir = parent;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
__name(thisCopy, "thisCopy");
|
|
954
|
+
function realPath(path) {
|
|
955
|
+
try {
|
|
956
|
+
return (0, import_node_fs.realpathSync)(path);
|
|
957
|
+
} catch {
|
|
958
|
+
return path;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
__name(realPath, "realPath");
|
|
962
|
+
var self = thisCopy();
|
|
963
|
+
if (self !== null) registerDurableCopy(self);
|
|
964
|
+
|
|
850
965
|
// src/backoff.ts
|
|
851
966
|
function backoffDelay(attempt, options) {
|
|
852
967
|
const base = options?.backoffMs ?? 0;
|
|
@@ -2152,9 +2267,6 @@ async function assertConcurrency(store, workflow, quota) {
|
|
|
2152
2267
|
}
|
|
2153
2268
|
__name(assertConcurrency, "assertConcurrency");
|
|
2154
2269
|
|
|
2155
|
-
// src/origin.ts
|
|
2156
|
-
var CORE_ORIGIN = "@dudousxd/nestjs-durable-core";
|
|
2157
|
-
|
|
2158
2270
|
// src/entities.ts
|
|
2159
2271
|
var NUDGE = {
|
|
2160
2272
|
nudge: true
|
|
@@ -3831,13 +3943,7 @@ async function runSchedules(engine, schedules, nowMs, opts) {
|
|
|
3831
3943
|
] : due;
|
|
3832
3944
|
const candidates = windows.filter((id) => !settled.get(s.key)?.has(id));
|
|
3833
3945
|
if (candidates.length === 0) continue;
|
|
3834
|
-
if (s.overlap === "skip" && s
|
|
3835
|
-
const prevBucket = Math.floor(nowMs / s.everyMs) - 1;
|
|
3836
|
-
if (prevBucket >= 0) {
|
|
3837
|
-
const prev = await engine.getRun(`sched:${s.key}:${prevBucket}`);
|
|
3838
|
-
if (prev && (prev.status === "running" || prev.status === "suspended")) continue;
|
|
3839
|
-
}
|
|
3840
|
-
}
|
|
3946
|
+
if (s.overlap === "skip" && await overlapping(engine, s, nowMs)) continue;
|
|
3841
3947
|
if (!(s.jitter && s.jitter > 0)) jitterFireAt.get(engine)?.delete(s.key);
|
|
3842
3948
|
const firing = s.jitter && s.jitter > 0 ? jitterDue(engine, s, candidates, nowMs, random) : candidates;
|
|
3843
3949
|
if (firing.length === 0) continue;
|
|
@@ -3845,16 +3951,97 @@ async function runSchedules(engine, schedules, nowMs, opts) {
|
|
|
3845
3951
|
if (engine.isDraining?.()) break;
|
|
3846
3952
|
const existing = await engine.getRun(runId);
|
|
3847
3953
|
remember(settled, s.key, runId);
|
|
3848
|
-
if (existing)
|
|
3954
|
+
if (existing) {
|
|
3955
|
+
if (s.overlap === "skip" && !isTerminal(existing.status)) {
|
|
3956
|
+
noteInFlight(engine, s.key, runId);
|
|
3957
|
+
break;
|
|
3958
|
+
}
|
|
3959
|
+
continue;
|
|
3960
|
+
}
|
|
3849
3961
|
await engine.start(workflowName(s.workflow), s.input, runId, {
|
|
3850
3962
|
namespace: s.namespace
|
|
3851
3963
|
});
|
|
3852
3964
|
ids.push(runId);
|
|
3965
|
+
if (s.overlap === "skip") {
|
|
3966
|
+
noteInFlight(engine, s.key, runId);
|
|
3967
|
+
break;
|
|
3968
|
+
}
|
|
3853
3969
|
}
|
|
3854
3970
|
}
|
|
3855
3971
|
return ids;
|
|
3856
3972
|
}
|
|
3857
3973
|
__name(runSchedules, "runSchedules");
|
|
3974
|
+
var IN_FLIGHT = [
|
|
3975
|
+
"pending",
|
|
3976
|
+
"running",
|
|
3977
|
+
"suspended",
|
|
3978
|
+
"blocked",
|
|
3979
|
+
"cancelling"
|
|
3980
|
+
];
|
|
3981
|
+
function isTerminal(status) {
|
|
3982
|
+
return TERMINAL_RUN_STATUSES.includes(status);
|
|
3983
|
+
}
|
|
3984
|
+
__name(isTerminal, "isTerminal");
|
|
3985
|
+
var inFlightRuns = /* @__PURE__ */ new WeakMap();
|
|
3986
|
+
function inFlightFor(engine, key) {
|
|
3987
|
+
let byKey = inFlightRuns.get(engine);
|
|
3988
|
+
if (byKey === void 0) {
|
|
3989
|
+
byKey = /* @__PURE__ */ new Map();
|
|
3990
|
+
inFlightRuns.set(engine, byKey);
|
|
3991
|
+
}
|
|
3992
|
+
let ids = byKey.get(key);
|
|
3993
|
+
if (ids === void 0) {
|
|
3994
|
+
ids = /* @__PURE__ */ new Set();
|
|
3995
|
+
byKey.set(key, ids);
|
|
3996
|
+
}
|
|
3997
|
+
return ids;
|
|
3998
|
+
}
|
|
3999
|
+
__name(inFlightFor, "inFlightFor");
|
|
4000
|
+
function noteInFlight(engine, key, runId) {
|
|
4001
|
+
const ids = inFlightFor(engine, key);
|
|
4002
|
+
ids.add(runId);
|
|
4003
|
+
if (ids.size > 64) ids.delete(ids.values().next().value);
|
|
4004
|
+
}
|
|
4005
|
+
__name(noteInFlight, "noteInFlight");
|
|
4006
|
+
async function overlapping(engine, s, nowMs) {
|
|
4007
|
+
const known = inFlightFor(engine, s.key);
|
|
4008
|
+
for (const runId of [
|
|
4009
|
+
...known
|
|
4010
|
+
].reverse()) {
|
|
4011
|
+
const run2 = await engine.getRun(runId);
|
|
4012
|
+
if (run2 && !isTerminal(run2.status)) return true;
|
|
4013
|
+
known.delete(runId);
|
|
4014
|
+
}
|
|
4015
|
+
if (engine.listRuns) {
|
|
4016
|
+
const prefix = `sched:${s.key}:`;
|
|
4017
|
+
const runs = await engine.listRuns({
|
|
4018
|
+
workflow: workflowName(s.workflow),
|
|
4019
|
+
statuses: IN_FLIGHT
|
|
4020
|
+
});
|
|
4021
|
+
const blocking = runs.filter((r) => r.id.startsWith(prefix) && !isTerminal(r.status));
|
|
4022
|
+
for (const r of blocking) noteInFlight(engine, s.key, r.id);
|
|
4023
|
+
return blocking.length > 0;
|
|
4024
|
+
}
|
|
4025
|
+
const prev = previousWindowRunId(s, nowMs);
|
|
4026
|
+
if (prev === void 0) return false;
|
|
4027
|
+
const run = await engine.getRun(prev);
|
|
4028
|
+
if (!run || isTerminal(run.status)) return false;
|
|
4029
|
+
noteInFlight(engine, s.key, prev);
|
|
4030
|
+
return true;
|
|
4031
|
+
}
|
|
4032
|
+
__name(overlapping, "overlapping");
|
|
4033
|
+
function previousWindowRunId(s, nowMs) {
|
|
4034
|
+
if (s.cron != null) {
|
|
4035
|
+
const current = prevCronFireMs(s.cron, nowMs, s.timezone);
|
|
4036
|
+
return `sched:${s.key}:${prevCronFireMs(s.cron, current - 1, s.timezone)}`;
|
|
4037
|
+
}
|
|
4038
|
+
if (s.everyMs != null) {
|
|
4039
|
+
const bucket = Math.floor(nowMs / s.everyMs) - 1;
|
|
4040
|
+
return bucket >= 0 ? `sched:${s.key}:${bucket}` : void 0;
|
|
4041
|
+
}
|
|
4042
|
+
return void 0;
|
|
4043
|
+
}
|
|
4044
|
+
__name(previousWindowRunId, "previousWindowRunId");
|
|
3858
4045
|
var settledRunIds = /* @__PURE__ */ new WeakMap();
|
|
3859
4046
|
function settledIdsFor(engine) {
|
|
3860
4047
|
let memo = settledRunIds.get(engine);
|
|
@@ -9438,6 +9625,14 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
9438
9625
|
getRun(runId) {
|
|
9439
9626
|
return this.visibleRun(runId);
|
|
9440
9627
|
}
|
|
9628
|
+
/**
|
|
9629
|
+
* The runs matching `query`, narrowed to the ones the caller may see (with tenancy on, another
|
|
9630
|
+
* tenant's runs are left out, like {@link getRun}). Pair it with `workflow` / `statuses` to bound
|
|
9631
|
+
* the scan on a large store. `overlap: 'skip'` schedules use it to find their in-flight runs.
|
|
9632
|
+
*/
|
|
9633
|
+
listRuns(query) {
|
|
9634
|
+
return this.store.listRuns(this.scopeRunQuery(query));
|
|
9635
|
+
}
|
|
9441
9636
|
/** A run's full checkpoint timeline, ordered by seq (what the testing kit's `captureHistory`
|
|
9442
9637
|
* reads, next to {@link getRun}). Empty for a run the caller may not see. */
|
|
9443
9638
|
async listCheckpoints(runId) {
|
|
@@ -16216,6 +16411,144 @@ function collectMetrics(engine) {
|
|
|
16216
16411
|
}
|
|
16217
16412
|
__name(collectMetrics, "collectMetrics");
|
|
16218
16413
|
|
|
16414
|
+
// src/run-app.ts
|
|
16415
|
+
var import_node_crypto2 = require("crypto");
|
|
16416
|
+
function runTraceId(runId) {
|
|
16417
|
+
const hex = (0, import_node_crypto2.createHash)("sha256").update(`durable:run:${runId}`).digest("hex").slice(0, 32);
|
|
16418
|
+
return /^0+$/.test(hex) ? `${hex.slice(0, 31)}1` : hex;
|
|
16419
|
+
}
|
|
16420
|
+
__name(runTraceId, "runTraceId");
|
|
16421
|
+
function tenantAppOf(namespace, own = []) {
|
|
16422
|
+
if (namespace === void 0 || namespace === "" || namespace === "default") return void 0;
|
|
16423
|
+
const mine = Array.isArray(own) ? own.includes(namespace) : own.has(namespace);
|
|
16424
|
+
return mine ? void 0 : namespace;
|
|
16425
|
+
}
|
|
16426
|
+
__name(tenantAppOf, "tenantAppOf");
|
|
16427
|
+
function positive(value, fallback) {
|
|
16428
|
+
return value !== void 0 && Number.isFinite(value) ? Math.max(1, value) : fallback;
|
|
16429
|
+
}
|
|
16430
|
+
__name(positive, "positive");
|
|
16431
|
+
var FAILED = Symbol("failed");
|
|
16432
|
+
var RunAppStamper = class {
|
|
16433
|
+
static {
|
|
16434
|
+
__name(this, "RunAppStamper");
|
|
16435
|
+
}
|
|
16436
|
+
#lookup;
|
|
16437
|
+
#own;
|
|
16438
|
+
#max;
|
|
16439
|
+
#timeoutMs;
|
|
16440
|
+
/** runId → app (`null`: the control plane's own run). */
|
|
16441
|
+
#apps = /* @__PURE__ */ new Map();
|
|
16442
|
+
/** runId → the last queued event of that run, while one is waiting on a read. */
|
|
16443
|
+
#tails = /* @__PURE__ */ new Map();
|
|
16444
|
+
constructor(options) {
|
|
16445
|
+
this.#lookup = (runId) => options.namespaceOf(runId);
|
|
16446
|
+
this.#own = new Set(options.own ?? []);
|
|
16447
|
+
this.#max = positive(options.cacheSize, 1e4);
|
|
16448
|
+
this.#timeoutMs = positive(options.lookupTimeoutMs, 5e3);
|
|
16449
|
+
}
|
|
16450
|
+
/** Call `forward` with `event` stamped with its app (when it has one), now or once it is known. */
|
|
16451
|
+
stamp(event, forward) {
|
|
16452
|
+
const runId = event.runId;
|
|
16453
|
+
const tail = this.#tails.get(runId);
|
|
16454
|
+
if (tail === void 0) {
|
|
16455
|
+
const known = this.#known(event);
|
|
16456
|
+
if (known !== void 0) {
|
|
16457
|
+
this.#forward(event, known, forward);
|
|
16458
|
+
return;
|
|
16459
|
+
}
|
|
16460
|
+
}
|
|
16461
|
+
const next = (tail ?? Promise.resolve()).then(async () => {
|
|
16462
|
+
try {
|
|
16463
|
+
let app = this.#known(event);
|
|
16464
|
+
if (app === void 0) {
|
|
16465
|
+
const namespace = await this.#read(runId);
|
|
16466
|
+
if (namespace === FAILED) {
|
|
16467
|
+
app = null;
|
|
16468
|
+
} else {
|
|
16469
|
+
app = tenantAppOf(namespace, this.#own) ?? null;
|
|
16470
|
+
this.#remember(runId, app);
|
|
16471
|
+
}
|
|
16472
|
+
}
|
|
16473
|
+
this.#forward(event, app, forward);
|
|
16474
|
+
} catch {
|
|
16475
|
+
}
|
|
16476
|
+
});
|
|
16477
|
+
this.#tails.set(runId, next);
|
|
16478
|
+
void next.then(() => {
|
|
16479
|
+
if (this.#tails.get(runId) === next) this.#tails.delete(runId);
|
|
16480
|
+
});
|
|
16481
|
+
}
|
|
16482
|
+
#forward(event, app, forward) {
|
|
16483
|
+
try {
|
|
16484
|
+
forward(this.#with(event, app));
|
|
16485
|
+
} finally {
|
|
16486
|
+
if (event.type === "run.completed" || event.type === "run.failed") {
|
|
16487
|
+
this.#apps.delete(event.runId);
|
|
16488
|
+
}
|
|
16489
|
+
}
|
|
16490
|
+
}
|
|
16491
|
+
/** The run's namespace, or {@link FAILED} when the read threw or did not answer in time. */
|
|
16492
|
+
async #read(runId) {
|
|
16493
|
+
let timer;
|
|
16494
|
+
const timeout = new Promise((resolve) => {
|
|
16495
|
+
timer = setTimeout(() => resolve(FAILED), this.#timeoutMs);
|
|
16496
|
+
timer.unref?.();
|
|
16497
|
+
});
|
|
16498
|
+
try {
|
|
16499
|
+
return await Promise.race([
|
|
16500
|
+
Promise.resolve().then(() => this.#lookup(runId)).catch(() => FAILED),
|
|
16501
|
+
timeout
|
|
16502
|
+
]);
|
|
16503
|
+
} finally {
|
|
16504
|
+
clearTimeout(timer);
|
|
16505
|
+
}
|
|
16506
|
+
}
|
|
16507
|
+
/** The app of `event`'s run when it is known without a read (`null`: no app). */
|
|
16508
|
+
#known(event) {
|
|
16509
|
+
if (event.namespace !== void 0) {
|
|
16510
|
+
const app = tenantAppOf(event.namespace, this.#own) ?? null;
|
|
16511
|
+
this.#remember(event.runId, app);
|
|
16512
|
+
return app;
|
|
16513
|
+
}
|
|
16514
|
+
return this.#apps.get(event.runId);
|
|
16515
|
+
}
|
|
16516
|
+
/** A tenant's event carries its app, and its partition as `namespace` (step events have none). */
|
|
16517
|
+
#with(event, app) {
|
|
16518
|
+
if (app === null) return event;
|
|
16519
|
+
return event.namespace === void 0 ? {
|
|
16520
|
+
...event,
|
|
16521
|
+
namespace: app,
|
|
16522
|
+
app
|
|
16523
|
+
} : {
|
|
16524
|
+
...event,
|
|
16525
|
+
app
|
|
16526
|
+
};
|
|
16527
|
+
}
|
|
16528
|
+
#remember(runId, app) {
|
|
16529
|
+
if (this.#apps.has(runId)) this.#apps.delete(runId);
|
|
16530
|
+
else if (this.#apps.size >= this.#max) {
|
|
16531
|
+
const oldest = this.#apps.keys().next().value;
|
|
16532
|
+
if (oldest !== void 0) this.#apps.delete(oldest);
|
|
16533
|
+
}
|
|
16534
|
+
this.#apps.set(runId, app);
|
|
16535
|
+
}
|
|
16536
|
+
};
|
|
16537
|
+
function controlPlaneAttribution(options, getRun) {
|
|
16538
|
+
if (options?.topology !== "control-plane") return void 0;
|
|
16539
|
+
const own = [
|
|
16540
|
+
options.namespace,
|
|
16541
|
+
options.partition
|
|
16542
|
+
].filter((ns) => typeof ns === "string" && ns !== "");
|
|
16543
|
+
return {
|
|
16544
|
+
namespaceOf: /* @__PURE__ */ __name(async (runId) => (await getRun(runId))?.namespace, "namespaceOf"),
|
|
16545
|
+
...own.length > 0 ? {
|
|
16546
|
+
own
|
|
16547
|
+
} : {}
|
|
16548
|
+
};
|
|
16549
|
+
}
|
|
16550
|
+
__name(controlPlaneAttribution, "controlPlaneAttribution");
|
|
16551
|
+
|
|
16219
16552
|
// src/search-attributes.ts
|
|
16220
16553
|
function compare(actual, filter) {
|
|
16221
16554
|
if (filter.op === "in") return filter.values.some((v) => actual === v);
|
|
@@ -17303,6 +17636,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17303
17636
|
DURABLE_OPTIONS_CANONICAL,
|
|
17304
17637
|
DURABLE_STEP_CONFIG,
|
|
17305
17638
|
DURABLE_STEP_NAME,
|
|
17639
|
+
DuplicateDurableCopyError,
|
|
17306
17640
|
DurableWorkflow,
|
|
17307
17641
|
ENGINE_MINTED_TAG_PREFIXES,
|
|
17308
17642
|
ENTITY_WORKFLOW,
|
|
@@ -17346,6 +17680,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17346
17680
|
RemoteStepTimeout,
|
|
17347
17681
|
RemoteWorkflowExecutor,
|
|
17348
17682
|
RemoteWorkflowTimeout,
|
|
17683
|
+
RunAppStamper,
|
|
17349
17684
|
RunGateway,
|
|
17350
17685
|
SINGLETON_ACTIVE_STATUSES,
|
|
17351
17686
|
SINGLETON_ADMITTED_TAG,
|
|
@@ -17379,6 +17714,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17379
17714
|
applyAttributeQuery,
|
|
17380
17715
|
assertConcurrency,
|
|
17381
17716
|
assertRoutes,
|
|
17717
|
+
assertSingleDurableCopy,
|
|
17382
17718
|
attributeColumnFor,
|
|
17383
17719
|
attributeOperand,
|
|
17384
17720
|
attributePredicateOperands,
|
|
@@ -17401,6 +17737,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17401
17737
|
codeOf,
|
|
17402
17738
|
collectMetrics,
|
|
17403
17739
|
concurrencyTag,
|
|
17740
|
+
controlPlaneAttribution,
|
|
17404
17741
|
controlPlaneDescriptor,
|
|
17405
17742
|
countRuns,
|
|
17406
17743
|
coveredTokens,
|
|
@@ -17412,6 +17749,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17412
17749
|
describeWorker,
|
|
17413
17750
|
descriptorHash,
|
|
17414
17751
|
detailsOf,
|
|
17752
|
+
durableCopies,
|
|
17415
17753
|
error,
|
|
17416
17754
|
etagMatches,
|
|
17417
17755
|
eventMatchOf,
|
|
@@ -17509,6 +17847,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17509
17847
|
runOutsideWorkflowCtx,
|
|
17510
17848
|
runSchedules,
|
|
17511
17849
|
runStepHandler,
|
|
17850
|
+
runTraceId,
|
|
17512
17851
|
runValueFacetsFromRuns,
|
|
17513
17852
|
runWaitPrefix,
|
|
17514
17853
|
runWaitTargetOf,
|
|
@@ -17518,6 +17857,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17518
17857
|
scheduledRunId,
|
|
17519
17858
|
scopeBufferedEvent,
|
|
17520
17859
|
scopeTenantQuery,
|
|
17860
|
+
sealDurableCopies,
|
|
17521
17861
|
settleResultsWithPlainCalls,
|
|
17522
17862
|
signTenantToken,
|
|
17523
17863
|
singletonAdmissionDenialPatch,
|
|
@@ -17533,6 +17873,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
17533
17873
|
summarizeFan,
|
|
17534
17874
|
summarizeRunFromStore,
|
|
17535
17875
|
summarizeTimeline,
|
|
17876
|
+
tenantAppOf,
|
|
17536
17877
|
tenantGroup,
|
|
17537
17878
|
tenantIdsFor,
|
|
17538
17879
|
tenantVisible,
|