@rivetkit/workflow-engine 2.3.3-rc.1 → 2.3.3-rc.2
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/schemas/v1.ts +25 -0
- package/dist/tsup/{chunk-GQWOLYBA.cjs → chunk-OCUQRGRS.cjs} +93 -1
- package/dist/tsup/chunk-OCUQRGRS.cjs.map +1 -0
- package/dist/tsup/{chunk-KA2T56AJ.js → chunk-Z3WC5MXC.js} +93 -1
- package/dist/tsup/chunk-Z3WC5MXC.js.map +1 -0
- package/dist/tsup/index.cjs +2 -2
- package/dist/tsup/index.d.cts +24 -1
- package/dist/tsup/index.d.ts +24 -1
- package/dist/tsup/index.js +1 -1
- package/dist/tsup/testing.cjs +23 -23
- package/dist/tsup/testing.js +1 -1
- package/package.json +1 -1
- package/schemas/serde.ts +16 -0
- package/schemas/v1.bare +10 -1
- package/schemas/versioned.ts +1 -0
- package/src/context.ts +93 -0
- package/src/types.ts +17 -2
- package/dist/tsup/chunk-GQWOLYBA.cjs.map +0 -1
- package/dist/tsup/chunk-KA2T56AJ.js.map +0 -1
|
@@ -670,6 +670,16 @@ function writeRemovedEntry(bc, x) {
|
|
|
670
670
|
bare.writeString(bc, x.originalType);
|
|
671
671
|
write1(bc, x.originalName);
|
|
672
672
|
}
|
|
673
|
+
function readVersionCheckEntry(bc) {
|
|
674
|
+
return {
|
|
675
|
+
resolved: bare.readU32(bc),
|
|
676
|
+
latest: bare.readU32(bc)
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
function writeVersionCheckEntry(bc, x) {
|
|
680
|
+
bare.writeU32(bc, x.resolved);
|
|
681
|
+
bare.writeU32(bc, x.latest);
|
|
682
|
+
}
|
|
673
683
|
function readEntryKind(bc) {
|
|
674
684
|
const offset = bc.offset;
|
|
675
685
|
const tag = bare.readU8(bc);
|
|
@@ -690,6 +700,8 @@ function readEntryKind(bc) {
|
|
|
690
700
|
return { tag: "RaceEntry", val: readRaceEntry(bc) };
|
|
691
701
|
case 7:
|
|
692
702
|
return { tag: "RemovedEntry", val: readRemovedEntry(bc) };
|
|
703
|
+
case 8:
|
|
704
|
+
return { tag: "VersionCheckEntry", val: readVersionCheckEntry(bc) };
|
|
693
705
|
default: {
|
|
694
706
|
bc.offset = offset;
|
|
695
707
|
throw new bare.BareError(offset, "invalid tag");
|
|
@@ -738,6 +750,11 @@ function writeEntryKind(bc, x) {
|
|
|
738
750
|
writeRemovedEntry(bc, x.val);
|
|
739
751
|
break;
|
|
740
752
|
}
|
|
753
|
+
case "VersionCheckEntry": {
|
|
754
|
+
bare.writeU8(bc, 8);
|
|
755
|
+
writeVersionCheckEntry(bc, x.val);
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
741
758
|
}
|
|
742
759
|
}
|
|
743
760
|
function readEntry(bc) {
|
|
@@ -1182,6 +1199,14 @@ function entryKindToBare(kind) {
|
|
|
1182
1199
|
originalName: kind.data.originalName ?? null
|
|
1183
1200
|
}
|
|
1184
1201
|
};
|
|
1202
|
+
case "version_check":
|
|
1203
|
+
return {
|
|
1204
|
+
tag: "VersionCheckEntry",
|
|
1205
|
+
val: {
|
|
1206
|
+
resolved: kind.data.resolved,
|
|
1207
|
+
latest: kind.data.latest
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1185
1210
|
}
|
|
1186
1211
|
}
|
|
1187
1212
|
function entryKindFromBare(kind) {
|
|
@@ -1263,6 +1288,14 @@ function entryKindFromBare(kind) {
|
|
|
1263
1288
|
originalName: kind.val.originalName ?? void 0
|
|
1264
1289
|
}
|
|
1265
1290
|
};
|
|
1291
|
+
case "VersionCheckEntry":
|
|
1292
|
+
return {
|
|
1293
|
+
type: "version_check",
|
|
1294
|
+
data: {
|
|
1295
|
+
resolved: kind.val.resolved,
|
|
1296
|
+
latest: kind.val.latest
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1266
1299
|
default:
|
|
1267
1300
|
throw new Error(
|
|
1268
1301
|
`Unknown entry kind: ${kind.tag}`
|
|
@@ -3488,6 +3521,65 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
|
|
|
3488
3521
|
setEntry(this.storage, location, entry);
|
|
3489
3522
|
await this.flushStorage();
|
|
3490
3523
|
}
|
|
3524
|
+
// === Version ===
|
|
3525
|
+
async getVersion(name, latest) {
|
|
3526
|
+
this.assertNotInProgress();
|
|
3527
|
+
this.checkEvicted();
|
|
3528
|
+
this.entryInProgress = true;
|
|
3529
|
+
try {
|
|
3530
|
+
return await this.executeGetVersion(name, latest);
|
|
3531
|
+
} finally {
|
|
3532
|
+
this.entryInProgress = false;
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
async executeGetVersion(name, latest) {
|
|
3536
|
+
if (!Number.isInteger(latest) || latest < 1) {
|
|
3537
|
+
throw new Error(
|
|
3538
|
+
`getVersion("${name}", ${latest}): latest must be an integer >= 1`
|
|
3539
|
+
);
|
|
3540
|
+
}
|
|
3541
|
+
this.checkDuplicateName(name);
|
|
3542
|
+
const location = appendName(this.storage, this.currentLocation, name);
|
|
3543
|
+
const key = locationToKey(this.storage, location);
|
|
3544
|
+
const existing = this.storage.history.entries.get(key);
|
|
3545
|
+
this.markVisited(key);
|
|
3546
|
+
this.stopRollbackIfMissing(existing);
|
|
3547
|
+
if (existing) {
|
|
3548
|
+
if (existing.kind.type !== "version_check") {
|
|
3549
|
+
throw new HistoryDivergedError(
|
|
3550
|
+
`Expected version_check at ${key}, found ${existing.kind.type}`
|
|
3551
|
+
);
|
|
3552
|
+
}
|
|
3553
|
+
return existing.kind.data.resolved;
|
|
3554
|
+
}
|
|
3555
|
+
const resolved = this.hasUnvisitedUnderCurrentScope(key) ? 1 : latest;
|
|
3556
|
+
const entry = createEntry(location, {
|
|
3557
|
+
type: "version_check",
|
|
3558
|
+
data: { resolved, latest }
|
|
3559
|
+
});
|
|
3560
|
+
setEntry(this.storage, location, entry);
|
|
3561
|
+
await this.flushStorage();
|
|
3562
|
+
return resolved;
|
|
3563
|
+
}
|
|
3564
|
+
/**
|
|
3565
|
+
* Returns true if any history entry under the current location scope
|
|
3566
|
+
* (other than `excludeKey`) has not yet been visited this run. Used by
|
|
3567
|
+
* getVersion to detect an old in-flight instance whose scope was already
|
|
3568
|
+
* executed by code that predates a version gate.
|
|
3569
|
+
*/
|
|
3570
|
+
hasUnvisitedUnderCurrentScope(excludeKey) {
|
|
3571
|
+
const prefix = locationToKey(this.storage, this.currentLocation);
|
|
3572
|
+
for (const key of this.storage.history.entries.keys()) {
|
|
3573
|
+
if (key === excludeKey) {
|
|
3574
|
+
continue;
|
|
3575
|
+
}
|
|
3576
|
+
const isUnderPrefix = prefix === "" ? true : key.startsWith(`${prefix}/`) || key === prefix;
|
|
3577
|
+
if (isUnderPrefix && !this.visitedKeys.has(key)) {
|
|
3578
|
+
return true;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
return false;
|
|
3582
|
+
}
|
|
3491
3583
|
};
|
|
3492
3584
|
|
|
3493
3585
|
// src/utils.ts
|
|
@@ -4225,4 +4317,4 @@ export {
|
|
|
4225
4317
|
runWorkflow,
|
|
4226
4318
|
replayWorkflowFromStep
|
|
4227
4319
|
};
|
|
4228
|
-
//# sourceMappingURL=chunk-
|
|
4320
|
+
//# sourceMappingURL=chunk-Z3WC5MXC.js.map
|