@dudousxd/nestjs-durable-core 0.85.8 → 0.85.9
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 +222 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +95 -2
- package/dist/index.d.ts +95 -2
- package/dist/index.js +222 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5014,6 +5014,7 @@ var ANNOUNCED_ROUTES_TTL_MS = 5e3;
|
|
|
5014
5014
|
var VERSION_UNDECLARED_TAG = "version:undeclared";
|
|
5015
5015
|
var versionKey = /* @__PURE__ */ __name((name, version) => `${name}@${version}`, "versionKey");
|
|
5016
5016
|
var STEP_FAN_CHUNK = 200;
|
|
5017
|
+
var FAN_REREAD_CHUNK = 1e3;
|
|
5017
5018
|
var PARENT_NOTIFY_ATTEMPTS = 4;
|
|
5018
5019
|
var PARENT_NOTIFY_BACKOFF_MS = 250;
|
|
5019
5020
|
var LEASE_RECHECK_MAX_MS = 2e3;
|
|
@@ -7450,8 +7451,7 @@ var WorkflowEngine = class {
|
|
|
7450
7451
|
*/
|
|
7451
7452
|
async redriveSettledSteps(runId, seqs) {
|
|
7452
7453
|
for (const seq of seqs) {
|
|
7453
|
-
|
|
7454
|
-
if (cp && (cp.status === "completed" || cp.status === "failed")) {
|
|
7454
|
+
if (await this.stepSettled(runId, seq)) {
|
|
7455
7455
|
if (this.settledHere.has(`${runId}:${seq}`)) return;
|
|
7456
7456
|
const nowMs = this.clock();
|
|
7457
7457
|
if (!await this.store.tryLockRun(runId, this.instanceId, nowMs + this.leaseMs, nowMs)) {
|
|
@@ -7467,6 +7467,17 @@ var WorkflowEngine = class {
|
|
|
7467
7467
|
}
|
|
7468
7468
|
}
|
|
7469
7469
|
}
|
|
7470
|
+
/** Whether the step at `seq` is settled: a `COUNT` when the store has one, else its checkpoint. */
|
|
7471
|
+
async stepSettled(runId, seq) {
|
|
7472
|
+
if (this.store.countCheckpoints) {
|
|
7473
|
+
return await this.store.countCheckpoints(runId, seq, seq, [
|
|
7474
|
+
"completed",
|
|
7475
|
+
"failed"
|
|
7476
|
+
]) > 0;
|
|
7477
|
+
}
|
|
7478
|
+
const cp = await this.store.getCheckpoint(runId, seq);
|
|
7479
|
+
return cp?.status === "completed" || cp?.status === "failed";
|
|
7480
|
+
}
|
|
7470
7481
|
/**
|
|
7471
7482
|
* {@link redriveSettledSteps} for a step fan: once the turn that suspended on it released its lease,
|
|
7472
7483
|
* re-drive the run if no step of the fan is still `pending` — the last result landed on another
|
|
@@ -8938,7 +8949,7 @@ ${run.workflowVersion}`;
|
|
|
8938
8949
|
}
|
|
8939
8950
|
const wfPlan = await this.planRoute(tenantGroup(sanitizeQueueToken(remote.group), void 0), registered.requires);
|
|
8940
8951
|
if (wfPlan?.status === "blocked") return this.parkBlocked(run, wfPlan);
|
|
8941
|
-
const checkpoints = await this.
|
|
8952
|
+
const checkpoints = await this.replayCheckpoints(run.id);
|
|
8942
8953
|
await this.deliverFinishedChildren(run.id, checkpoints);
|
|
8943
8954
|
await this.deliverFinishedChildWaiters(run.id, checkpoints);
|
|
8944
8955
|
const handoff = liveHandoff(run.id, checkpoints);
|
|
@@ -9214,6 +9225,37 @@ ${run.workflowVersion}`;
|
|
|
9214
9225
|
* throttle for {@link rearmStepLease}, the step-scoped sibling of {@link decisionDeadlineRearms}. */
|
|
9215
9226
|
stepLeaseRearms = /* @__PURE__ */ new Map();
|
|
9216
9227
|
/**
|
|
9228
|
+
* {@link stepLeaseRearms} for the steps of a fan this instance sent, by run: one entry per sent
|
|
9229
|
+
* block of consecutive seqs instead of one per step, since they share the lease stamped at send.
|
|
9230
|
+
*/
|
|
9231
|
+
fanLeaseRearms = /* @__PURE__ */ new Map();
|
|
9232
|
+
noteFanLease(runId, seqs, lease) {
|
|
9233
|
+
if (this.remoteRedispatchMs == null || seqs.length === 0) return;
|
|
9234
|
+
let from = seqs[0];
|
|
9235
|
+
let to = from;
|
|
9236
|
+
for (const seq of seqs) {
|
|
9237
|
+
if (seq < from) from = seq;
|
|
9238
|
+
if (seq > to) to = seq;
|
|
9239
|
+
}
|
|
9240
|
+
if (to - from + 1 !== seqs.length) return;
|
|
9241
|
+
if (this.fanLeaseRearms.size > 1024) this.fanLeaseRearms.clear();
|
|
9242
|
+
const blocks = this.fanLeaseRearms.get(runId) ?? [];
|
|
9243
|
+
blocks.push({
|
|
9244
|
+
from,
|
|
9245
|
+
to,
|
|
9246
|
+
lookAgainAt: lease - Math.ceil(this.remoteRedispatchMs / 2)
|
|
9247
|
+
});
|
|
9248
|
+
this.fanLeaseRearms.set(runId, blocks);
|
|
9249
|
+
}
|
|
9250
|
+
fanLeaseLookAgainAt(runId, seq, now) {
|
|
9251
|
+
const blocks = this.fanLeaseRearms.get(runId);
|
|
9252
|
+
if (!blocks) return void 0;
|
|
9253
|
+
const live = blocks.filter((b) => now < b.lookAgainAt);
|
|
9254
|
+
if (live.length === 0) this.fanLeaseRearms.delete(runId);
|
|
9255
|
+
else if (live.length < blocks.length) this.fanLeaseRearms.set(runId, live);
|
|
9256
|
+
return live.find((b) => seq >= b.from && seq <= b.to)?.lookAgainAt;
|
|
9257
|
+
}
|
|
9258
|
+
/**
|
|
9217
9259
|
* A step-scoped heartbeat for a durably-suspended remote step: push its LEASE forward so a worker
|
|
9218
9260
|
* that is still working on it is never presumed dead and double-dispatched. The durable counterpart
|
|
9219
9261
|
* of {@link callRemoteInMemory}'s in-memory `heartbeatResets` rearm (which only exists on the
|
|
@@ -9242,7 +9284,7 @@ ${run.workflowVersion}`;
|
|
|
9242
9284
|
if (this.remoteRedispatchMs == null) return;
|
|
9243
9285
|
const id = stepId(runId, seq);
|
|
9244
9286
|
const now = this.clock();
|
|
9245
|
-
const lookAgainAt = this.stepLeaseRearms.get(id);
|
|
9287
|
+
const lookAgainAt = this.stepLeaseRearms.get(id) ?? this.fanLeaseLookAgainAt(runId, seq, now);
|
|
9246
9288
|
if (lookAgainAt !== void 0 && now < lookAgainAt) return;
|
|
9247
9289
|
try {
|
|
9248
9290
|
const cp = await this.store.getCheckpoint(runId, seq);
|
|
@@ -9565,7 +9607,7 @@ ${run.workflowVersion}`;
|
|
|
9565
9607
|
return this.singletonWaitResult(run);
|
|
9566
9608
|
}
|
|
9567
9609
|
const compensations = [];
|
|
9568
|
-
const snapshot = await this.
|
|
9610
|
+
const snapshot = await this.replayCheckpoints(run.id);
|
|
9569
9611
|
await this.deliverFinishedChildren(run.id, snapshot);
|
|
9570
9612
|
const replay = /* @__PURE__ */ new Map();
|
|
9571
9613
|
for (const cp of snapshot) replay.set(cp.seq, cp);
|
|
@@ -9895,7 +9937,7 @@ ${run.workflowVersion}`;
|
|
|
9895
9937
|
}), "callRemote"),
|
|
9896
9938
|
callRemoteAll: /* @__PURE__ */ __name((runId, positions, step, inputs, opts) => this.callRemoteAll(runId, positions, step, inputs, opts, {
|
|
9897
9939
|
namespace: parentNamespace
|
|
9898
|
-
}), "callRemoteAll"),
|
|
9940
|
+
}, replay), "callRemoteAll"),
|
|
9899
9941
|
// Defer so a fast child can't reentrantly resume a still-running parent. Stamp the child with
|
|
9900
9942
|
// the PARENT run's namespace (not this engine's) so a child belongs to the tenant/partition of
|
|
9901
9943
|
// the run it was spawned from — even when an operator (namespace: undefined, drives every
|
|
@@ -10252,7 +10294,7 @@ ${run.workflowVersion}`;
|
|
|
10252
10294
|
* concurrently with this one finds them already sent instead of sending them again. The join
|
|
10253
10295
|
* barrier ({@link stepFanStillRunning}) then wakes the parent once per wave, not once per result.
|
|
10254
10296
|
*/
|
|
10255
|
-
async callRemoteAll(runId, positions, step, inputs, opts, routing) {
|
|
10297
|
+
async callRemoteAll(runId, positions, step, inputs, opts, routing, replay) {
|
|
10256
10298
|
if (step.timeoutMs) {
|
|
10257
10299
|
throw new Error(`ctx.all: step "${step.name}" has a liveness timeoutMs; a step fan needs durable steps`);
|
|
10258
10300
|
}
|
|
@@ -10263,10 +10305,7 @@ ${run.workflowVersion}`;
|
|
|
10263
10305
|
const first = positions[0];
|
|
10264
10306
|
const last = positions[positions.length - 1];
|
|
10265
10307
|
const group = stepFanGroup(first, positions.length, opts.mode);
|
|
10266
|
-
const bySeq =
|
|
10267
|
-
for (const cp of await this.store.listCheckpoints(runId)) {
|
|
10268
|
-
if (cp.seq >= first && cp.seq <= last) bySeq.set(cp.seq, cp);
|
|
10269
|
-
}
|
|
10308
|
+
const bySeq = await this.fanCheckpoints(runId, positions, replay);
|
|
10270
10309
|
const outputs = new Array(inputs.length);
|
|
10271
10310
|
const failures = [];
|
|
10272
10311
|
const unsent = [];
|
|
@@ -10323,7 +10362,13 @@ ${run.workflowVersion}`;
|
|
|
10323
10362
|
}
|
|
10324
10363
|
if (inFlight === 0 && highest >= 0) this.turnSettledFans.get(runId)?.set(first, highest);
|
|
10325
10364
|
const batch = inFlight > 0 ? [] : opts.concurrency === void 0 ? unsent : unsent.slice(0, opts.concurrency);
|
|
10326
|
-
if (batch.length > 0)
|
|
10365
|
+
if (batch.length > 0) {
|
|
10366
|
+
const lease = await this.sendStepFan(runId, positions, step, inputs, batch, group, opts, routing);
|
|
10367
|
+
if (lease !== void 0) {
|
|
10368
|
+
const at = this.stepLeaseWakeAt(lease);
|
|
10369
|
+
wakeAt = Math.min(wakeAt ?? at, at);
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10327
10372
|
if (inFlight + batch.length > 0) {
|
|
10328
10373
|
this.awaitedStepFans.get(runId)?.push({
|
|
10329
10374
|
from: first,
|
|
@@ -10353,6 +10398,34 @@ ${run.workflowVersion}`;
|
|
|
10353
10398
|
return outputs;
|
|
10354
10399
|
}
|
|
10355
10400
|
/**
|
|
10401
|
+
* The checkpoints of a step fan's seqs, by seq. A settled one is taken from the turn's snapshot
|
|
10402
|
+
* (`replay`), since nothing but a turn of the run changes it once settled; one the snapshot holds
|
|
10403
|
+
* `pending`, or does not hold, is read again, as {@link callRemote} does for a single step: its
|
|
10404
|
+
* result may have landed since. The fan's last turn so reads nothing it already read.
|
|
10405
|
+
*/
|
|
10406
|
+
async fanCheckpoints(runId, positions, replay) {
|
|
10407
|
+
const bySeq = /* @__PURE__ */ new Map();
|
|
10408
|
+
const reread = [];
|
|
10409
|
+
for (const seq of positions) {
|
|
10410
|
+
const cp = replay?.get(seq);
|
|
10411
|
+
if (cp && (cp.status === "completed" || cp.status === "failed")) bySeq.set(seq, cp);
|
|
10412
|
+
else reread.push(seq);
|
|
10413
|
+
}
|
|
10414
|
+
if (reread.length === 0) return bySeq;
|
|
10415
|
+
if (reread.length === positions.length || !this.store.getCheckpoints) {
|
|
10416
|
+
const wanted = new Set(reread);
|
|
10417
|
+
for (const cp of await this.store.listCheckpoints(runId)) {
|
|
10418
|
+
if (wanted.has(cp.seq)) bySeq.set(cp.seq, cp);
|
|
10419
|
+
}
|
|
10420
|
+
return bySeq;
|
|
10421
|
+
}
|
|
10422
|
+
for (let at = 0; at < reread.length; at += FAN_REREAD_CHUNK) {
|
|
10423
|
+
const read = await this.store.getCheckpoints(runId, reread.slice(at, at + FAN_REREAD_CHUNK));
|
|
10424
|
+
for (const cp of read) bySeq.set(cp.seq, cp);
|
|
10425
|
+
}
|
|
10426
|
+
return bySeq;
|
|
10427
|
+
}
|
|
10428
|
+
/**
|
|
10356
10429
|
* Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
|
|
10357
10430
|
* {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
|
|
10358
10431
|
* batch, where the store and transport have them.
|
|
@@ -10361,6 +10434,7 @@ ${run.workflowVersion}`;
|
|
|
10361
10434
|
const workerGroup = stepGroup(step, routing?.namespace);
|
|
10362
10435
|
await this.ensureRoutable(workerGroup, step.requires);
|
|
10363
10436
|
const enqueuedAt = /* @__PURE__ */ new Date();
|
|
10437
|
+
const lease = this.remoteRedispatchMs == null ? void 0 : this.clock() + this.remoteRedispatchMs;
|
|
10364
10438
|
const checkpoints = batch.map((i) => {
|
|
10365
10439
|
const seq = positions[i];
|
|
10366
10440
|
return {
|
|
@@ -10376,7 +10450,10 @@ ${run.workflowVersion}`;
|
|
|
10376
10450
|
parallelGroup: group,
|
|
10377
10451
|
enqueuedAt,
|
|
10378
10452
|
startedAt: enqueuedAt,
|
|
10379
|
-
finishedAt: enqueuedAt
|
|
10453
|
+
finishedAt: enqueuedAt,
|
|
10454
|
+
...lease !== void 0 ? {
|
|
10455
|
+
wakeAt: lease
|
|
10456
|
+
} : {}
|
|
10380
10457
|
};
|
|
10381
10458
|
});
|
|
10382
10459
|
if (this.store.saveCheckpoints) {
|
|
@@ -10409,20 +10486,36 @@ ${run.workflowVersion}`;
|
|
|
10409
10486
|
kind: "remote"
|
|
10410
10487
|
});
|
|
10411
10488
|
}
|
|
10489
|
+
if (lease !== void 0) {
|
|
10490
|
+
this.noteFanLease(runId, checkpoints.map((cp) => cp.seq), lease);
|
|
10491
|
+
}
|
|
10492
|
+
return lease;
|
|
10412
10493
|
}
|
|
10413
10494
|
/** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
|
|
10414
10495
|
noteSettledHere(key) {
|
|
10415
10496
|
this.noteRecent(this.settledHere, key);
|
|
10416
10497
|
}
|
|
10417
|
-
/**
|
|
10498
|
+
/**
|
|
10499
|
+
* Record `key` in a "happened here recently" map and drop the entries older than a lease. A key is
|
|
10500
|
+
* re-inserted at the end, so the map stays in the order its keys were noted and the stale ones are
|
|
10501
|
+
* all at its front: pruning stops at the first fresh entry instead of walking the whole map.
|
|
10502
|
+
*/
|
|
10418
10503
|
noteRecent(map, key) {
|
|
10419
10504
|
const now = this.clock();
|
|
10505
|
+
map.delete(key);
|
|
10420
10506
|
map.set(key, now);
|
|
10421
|
-
if (map.size < 1024) return;
|
|
10422
10507
|
for (const [k, at] of map) {
|
|
10423
|
-
if (now - at
|
|
10508
|
+
if (now - at <= this.leaseMs) break;
|
|
10509
|
+
map.delete(k);
|
|
10424
10510
|
}
|
|
10425
10511
|
}
|
|
10512
|
+
/**
|
|
10513
|
+
* The run's checkpoints as a turn replays them: {@link StateStore.listCheckpointsForReplay} when
|
|
10514
|
+
* the store has it (no input on a completed row), else {@link StateStore.listCheckpoints}.
|
|
10515
|
+
*/
|
|
10516
|
+
replayCheckpoints(runId) {
|
|
10517
|
+
return this.store.listCheckpointsForReplay ? this.store.listCheckpointsForReplay(runId) : this.store.listCheckpoints(runId);
|
|
10518
|
+
}
|
|
10426
10519
|
/** {@link StateStore.saveCheckpointIfPending}, or a plain save on a store without it. */
|
|
10427
10520
|
async savePendingCheckpoint(checkpoint) {
|
|
10428
10521
|
if (this.store.saveCheckpointIfPending) return this.store.saveCheckpointIfPending(checkpoint);
|
|
@@ -10449,11 +10542,59 @@ ${run.workflowVersion}`;
|
|
|
10449
10542
|
});
|
|
10450
10543
|
}
|
|
10451
10544
|
/**
|
|
10545
|
+
* Settle steps of one run at distinct seqs from their results ({@link StepSettlement}s, `settled[i]`
|
|
10546
|
+
* being the `pending` row `settlements[i]` settles): one
|
|
10547
|
+
* {@link StateStore.settleCheckpointsIfPending} call when the store has it, which writes only what
|
|
10548
|
+
* a result changes, else the whole rows through {@link savePendingCheckpoints}. Never rejects as a
|
|
10549
|
+
* whole, the same way.
|
|
10550
|
+
*/
|
|
10551
|
+
async settlePendingCheckpoints(settlements, settled) {
|
|
10552
|
+
const settle = this.store.settleCheckpointsIfPending?.bind(this.store);
|
|
10553
|
+
if (!settle) {
|
|
10554
|
+
return this.savePendingCheckpoints(settlements.map((s, i) => ({
|
|
10555
|
+
...settled[i],
|
|
10556
|
+
...s
|
|
10557
|
+
})));
|
|
10558
|
+
}
|
|
10559
|
+
if (settlements.length > 1) {
|
|
10560
|
+
try {
|
|
10561
|
+
const wrote = await settle(settlements);
|
|
10562
|
+
return settlements.map((_, i) => wrote[i] === true);
|
|
10563
|
+
} catch {
|
|
10564
|
+
}
|
|
10565
|
+
}
|
|
10566
|
+
const one = await Promise.allSettled(settlements.map((s) => settle([
|
|
10567
|
+
s
|
|
10568
|
+
])));
|
|
10569
|
+
return one.map((s) => s.status === "fulfilled" ? s.value[0] === true : {
|
|
10570
|
+
error: s.reason
|
|
10571
|
+
});
|
|
10572
|
+
}
|
|
10573
|
+
/**
|
|
10452
10574
|
* The checkpoints of one run at distinct `seqs`, each as its own outcome: one
|
|
10453
10575
|
* {@link StateStore.getCheckpoints} call when the store has it, else one read each. The batch
|
|
10454
10576
|
* call rejecting falls back to one read each, so a failing read fails only its own entry.
|
|
10455
10577
|
*/
|
|
10456
10578
|
async readCheckpoints(runId, seqs) {
|
|
10579
|
+
const forSettle = this.store.settleCheckpointsIfPending ? this.store.getCheckpointsForSettle?.bind(this.store) : void 0;
|
|
10580
|
+
if (forSettle) {
|
|
10581
|
+
if (seqs.length > 1) {
|
|
10582
|
+
try {
|
|
10583
|
+
const bySeq = new Map((await forSettle(runId, seqs)).map((cp) => [
|
|
10584
|
+
cp.seq,
|
|
10585
|
+
cp
|
|
10586
|
+
]));
|
|
10587
|
+
return seqs.map((seq) => ({
|
|
10588
|
+
status: "fulfilled",
|
|
10589
|
+
value: bySeq.get(seq) ?? null
|
|
10590
|
+
}));
|
|
10591
|
+
} catch {
|
|
10592
|
+
}
|
|
10593
|
+
}
|
|
10594
|
+
return Promise.allSettled(seqs.map(async (seq) => (await forSettle(runId, [
|
|
10595
|
+
seq
|
|
10596
|
+
]))[0] ?? null));
|
|
10597
|
+
}
|
|
10457
10598
|
if (seqs.length > 1 && this.store.getCheckpoints) {
|
|
10458
10599
|
try {
|
|
10459
10600
|
const bySeq = new Map((await this.store.getCheckpoints(runId, seqs)).map((cp) => [
|
|
@@ -10602,10 +10743,11 @@ ${run.workflowVersion}`;
|
|
|
10602
10743
|
const run = await this.store.getRun(runId);
|
|
10603
10744
|
if (run && (run.status === "cancelled" || run.status === "completed")) return outcomes;
|
|
10604
10745
|
const finishedAt = /* @__PURE__ */ new Date();
|
|
10605
|
-
const
|
|
10746
|
+
const settlements = pending.map(({ index, cp }) => {
|
|
10606
10747
|
const result = results[index];
|
|
10607
10748
|
return {
|
|
10608
|
-
|
|
10749
|
+
runId,
|
|
10750
|
+
seq: cp.seq,
|
|
10609
10751
|
status: result.status,
|
|
10610
10752
|
output: result.status === "completed" ? result.output : cp.output,
|
|
10611
10753
|
error: result.error,
|
|
@@ -10614,7 +10756,7 @@ ${run.workflowVersion}`;
|
|
|
10614
10756
|
finishedAt
|
|
10615
10757
|
};
|
|
10616
10758
|
});
|
|
10617
|
-
const claims = await this.
|
|
10759
|
+
const claims = await this.settlePendingCheckpoints(settlements, pending.map(({ cp }) => cp));
|
|
10618
10760
|
const settled = [];
|
|
10619
10761
|
claims.forEach((claim, k) => {
|
|
10620
10762
|
const { index, cp } = pending[k];
|
|
@@ -10628,7 +10770,7 @@ ${run.workflowVersion}`;
|
|
|
10628
10770
|
};
|
|
10629
10771
|
});
|
|
10630
10772
|
for (const { cp, result } of settled) {
|
|
10631
|
-
this.noteSettledHere(`${runId}:${result.seq}`);
|
|
10773
|
+
if (!parseStepFanGroup(cp.parallelGroup)) this.noteSettledHere(`${runId}:${result.seq}`);
|
|
10632
10774
|
const startedAt = result.startedAt ? new Date(result.startedAt) : cp.startedAt;
|
|
10633
10775
|
this.emit({
|
|
10634
10776
|
type: result.status === "completed" ? "step.completed" : "step.failed",
|
|
@@ -11527,8 +11669,16 @@ var CodecStateStore = class {
|
|
|
11527
11669
|
saveCheckpointIfPending;
|
|
11528
11670
|
/** Encodes each checkpoint like {@link saveCheckpoint}. Bound only when the inner store has it. */
|
|
11529
11671
|
saveCheckpointsIfPending;
|
|
11672
|
+
/** Encodes each settlement's payloads like {@link saveCheckpoint}. Bound only when the inner store
|
|
11673
|
+
* has it, so the engine's whole-row fallback still kicks in through the wrapper. */
|
|
11674
|
+
settleCheckpointsIfPending;
|
|
11530
11675
|
/** Encodes each checkpoint written. Bound only when the inner store has it. */
|
|
11531
11676
|
saveCheckpoints;
|
|
11677
|
+
/** Decodes each checkpoint read like {@link listCheckpoints}. Bound only when the inner store has
|
|
11678
|
+
* it, so the engine's full-read fallback still kicks in through the wrapper. */
|
|
11679
|
+
listCheckpointsForReplay;
|
|
11680
|
+
/** Decodes each checkpoint read. Bound only when the inner store has it. */
|
|
11681
|
+
getCheckpointsForSettle;
|
|
11532
11682
|
/** Decodes each checkpoint read. Bound only when the inner store has it. */
|
|
11533
11683
|
getCheckpoints;
|
|
11534
11684
|
/** Forwarded verbatim — a count reads no payload. Bound only when the inner store has it. */
|
|
@@ -11581,8 +11731,14 @@ var CodecStateStore = class {
|
|
|
11581
11731
|
if (saveIfPending) this.saveCheckpointIfPending = (cp) => saveIfPending.call(inner, this.encCp(cp));
|
|
11582
11732
|
const saveManyIfPending = inner.saveCheckpointsIfPending;
|
|
11583
11733
|
if (saveManyIfPending) this.saveCheckpointsIfPending = (cps) => saveManyIfPending.call(inner, cps.map((cp) => this.encCp(cp)));
|
|
11734
|
+
const settleMany = inner.settleCheckpointsIfPending;
|
|
11735
|
+
if (settleMany) this.settleCheckpointsIfPending = (settlements) => settleMany.call(inner, settlements.map((s) => this.encSettlement(s)));
|
|
11584
11736
|
const saveMany = inner.saveCheckpoints;
|
|
11585
11737
|
if (saveMany) this.saveCheckpoints = (cps) => saveMany.call(inner, cps.map((cp) => this.encCp(cp)));
|
|
11738
|
+
const listForReplay = inner.listCheckpointsForReplay;
|
|
11739
|
+
if (listForReplay) this.listCheckpointsForReplay = async (runId) => (await listForReplay.call(inner, runId)).map((cp) => this.decCp(cp));
|
|
11740
|
+
const getForSettle = inner.getCheckpointsForSettle;
|
|
11741
|
+
if (getForSettle) this.getCheckpointsForSettle = async (runId, seqs) => (await getForSettle.call(inner, runId, seqs)).map((cp) => this.decCp(cp));
|
|
11586
11742
|
const getMany = inner.getCheckpoints;
|
|
11587
11743
|
if (getMany) this.getCheckpoints = async (runId, seqs) => (await getMany.call(inner, runId, seqs)).map((cp) => this.decCp(cp));
|
|
11588
11744
|
const countCps = inner.countCheckpoints;
|
|
@@ -11674,6 +11830,21 @@ var CodecStateStore = class {
|
|
|
11674
11830
|
}
|
|
11675
11831
|
return next;
|
|
11676
11832
|
}
|
|
11833
|
+
encSettlement(settlement) {
|
|
11834
|
+
const next = {
|
|
11835
|
+
...settlement,
|
|
11836
|
+
output: this.enc(settlement.output)
|
|
11837
|
+
};
|
|
11838
|
+
if (this.extended) {
|
|
11839
|
+
if (settlement.events !== void 0) {
|
|
11840
|
+
next.events = this.enc(settlement.events);
|
|
11841
|
+
}
|
|
11842
|
+
if (settlement.error !== void 0) {
|
|
11843
|
+
next.error = this.enc(settlement.error);
|
|
11844
|
+
}
|
|
11845
|
+
}
|
|
11846
|
+
return next;
|
|
11847
|
+
}
|
|
11677
11848
|
decCp(cp) {
|
|
11678
11849
|
if (!cp) return cp;
|
|
11679
11850
|
const next = {
|
|
@@ -12233,6 +12404,18 @@ var InMemoryStateStore = class {
|
|
|
12233
12404
|
] : [];
|
|
12234
12405
|
});
|
|
12235
12406
|
}
|
|
12407
|
+
async getCheckpointsForSettle(runId, seqs) {
|
|
12408
|
+
return [
|
|
12409
|
+
...new Set(seqs)
|
|
12410
|
+
].sort((a, b) => a - b).flatMap((seq) => {
|
|
12411
|
+
const cp = this.checkpoints.get(this.key(runId, seq));
|
|
12412
|
+
if (!cp) return [];
|
|
12413
|
+
const { input: _input, ...rest } = cp;
|
|
12414
|
+
return [
|
|
12415
|
+
rest
|
|
12416
|
+
];
|
|
12417
|
+
});
|
|
12418
|
+
}
|
|
12236
12419
|
async saveCheckpoint(checkpoint) {
|
|
12237
12420
|
this.checkpoints.set(this.key(checkpoint.runId, checkpoint.seq), {
|
|
12238
12421
|
...checkpoint
|
|
@@ -12263,6 +12446,18 @@ var InMemoryStateStore = class {
|
|
|
12263
12446
|
return true;
|
|
12264
12447
|
});
|
|
12265
12448
|
}
|
|
12449
|
+
async settleCheckpointsIfPending(settlements) {
|
|
12450
|
+
return settlements.map((settlement) => {
|
|
12451
|
+
const key = this.key(settlement.runId, settlement.seq);
|
|
12452
|
+
const cp = this.checkpoints.get(key);
|
|
12453
|
+
if (cp?.status !== "pending") return false;
|
|
12454
|
+
this.checkpoints.set(key, {
|
|
12455
|
+
...cp,
|
|
12456
|
+
...settlement
|
|
12457
|
+
});
|
|
12458
|
+
return true;
|
|
12459
|
+
});
|
|
12460
|
+
}
|
|
12266
12461
|
async listOrphanedRuns(nowMs, limit, namespace, ownedBy) {
|
|
12267
12462
|
return [
|
|
12268
12463
|
...this.runs.values()
|
|
@@ -12579,6 +12774,13 @@ var InMemoryStateStore = class {
|
|
|
12579
12774
|
this.checkpointRowsRead += rows.length;
|
|
12580
12775
|
return rows;
|
|
12581
12776
|
}
|
|
12777
|
+
async listCheckpointsForReplay(runId) {
|
|
12778
|
+
return (await this.listCheckpoints(runId)).map((cp) => {
|
|
12779
|
+
if (cp.status !== "completed") return cp;
|
|
12780
|
+
const { input: _input, ...rest } = cp;
|
|
12781
|
+
return rest;
|
|
12782
|
+
});
|
|
12783
|
+
}
|
|
12582
12784
|
runCheckpoints(runId) {
|
|
12583
12785
|
return [
|
|
12584
12786
|
...this.checkpoints.values()
|