@rivetkit/workflow-engine 0.0.0-fix-ws-size.7d55b4f → 0.0.0-http-body-streaming.064e07d

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.
@@ -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: _nullishCoalesce(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: _nullishCoalesce(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}`
@@ -1574,8 +1607,12 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
1574
1607
  });
1575
1608
  }
1576
1609
  if (writes.length > 0) {
1577
- for (const chunk of splitBatchWrites(writes)) {
1578
- await driver.batch(chunk);
1610
+ if (driver.atomicBatch) {
1611
+ await driver.batch(writes);
1612
+ } else {
1613
+ for (const chunk of splitBatchWrites(writes)) {
1614
+ await driver.batch(chunk);
1615
+ }
1579
1616
  }
1580
1617
  }
1581
1618
  if (pendingDeletions) {
@@ -3488,6 +3525,65 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3488
3525
  setEntry(this.storage, location, entry);
3489
3526
  await this.flushStorage();
3490
3527
  }
3528
+ // === Version ===
3529
+ async getVersion(name, latest) {
3530
+ this.assertNotInProgress();
3531
+ this.checkEvicted();
3532
+ this.entryInProgress = true;
3533
+ try {
3534
+ return await this.executeGetVersion(name, latest);
3535
+ } finally {
3536
+ this.entryInProgress = false;
3537
+ }
3538
+ }
3539
+ async executeGetVersion(name, latest) {
3540
+ if (!Number.isInteger(latest) || latest < 1) {
3541
+ throw new Error(
3542
+ `getVersion("${name}", ${latest}): latest must be an integer >= 1`
3543
+ );
3544
+ }
3545
+ this.checkDuplicateName(name);
3546
+ const location = appendName(this.storage, this.currentLocation, name);
3547
+ const key = locationToKey(this.storage, location);
3548
+ const existing = this.storage.history.entries.get(key);
3549
+ this.markVisited(key);
3550
+ this.stopRollbackIfMissing(existing);
3551
+ if (existing) {
3552
+ if (existing.kind.type !== "version_check") {
3553
+ throw new HistoryDivergedError(
3554
+ `Expected version_check at ${key}, found ${existing.kind.type}`
3555
+ );
3556
+ }
3557
+ return existing.kind.data.resolved;
3558
+ }
3559
+ const resolved = this.hasUnvisitedUnderCurrentScope(key) ? 1 : latest;
3560
+ const entry = createEntry(location, {
3561
+ type: "version_check",
3562
+ data: { resolved, latest }
3563
+ });
3564
+ setEntry(this.storage, location, entry);
3565
+ await this.flushStorage();
3566
+ return resolved;
3567
+ }
3568
+ /**
3569
+ * Returns true if any history entry under the current location scope
3570
+ * (other than `excludeKey`) has not yet been visited this run. Used by
3571
+ * getVersion to detect an old in-flight instance whose scope was already
3572
+ * executed by code that predates a version gate.
3573
+ */
3574
+ hasUnvisitedUnderCurrentScope(excludeKey) {
3575
+ const prefix = locationToKey(this.storage, this.currentLocation);
3576
+ for (const key of this.storage.history.entries.keys()) {
3577
+ if (key === excludeKey) {
3578
+ continue;
3579
+ }
3580
+ const isUnderPrefix = prefix === "" ? true : key.startsWith(`${prefix}/`) || key === prefix;
3581
+ if (isUnderPrefix && !this.visitedKeys.has(key)) {
3582
+ return true;
3583
+ }
3584
+ }
3585
+ return false;
3586
+ }
3491
3587
  }, _class);
3492
3588
 
3493
3589
  // src/utils.ts
@@ -4225,4 +4321,4 @@ async function executeWorkflow(workflowId, workflowFn, input, driver, messageDri
4225
4321
 
4226
4322
 
4227
4323
  exports.extractErrorInfo = extractErrorInfo; exports.CriticalError = CriticalError; exports.RollbackError = RollbackError; exports.RollbackCheckpointError = RollbackCheckpointError; exports.SleepError = SleepError; exports.MessageWaitError = MessageWaitError; exports.EvictedError = EvictedError; exports.HistoryDivergedError = HistoryDivergedError; exports.StepExhaustedError = StepExhaustedError; exports.StepFailedError = StepFailedError; exports.JoinError = JoinError; exports.RaceError = RaceError; exports.CancelledError = CancelledError; exports.EntryInProgressError = EntryInProgressError; exports.keyStartsWith = keyStartsWith; exports.compareKeys = compareKeys; exports.keyToHex = keyToHex; exports.isLoopIterationMarker = isLoopIterationMarker; exports.registerName = registerName; exports.resolveName = resolveName; exports.locationToKey = locationToKey; exports.appendName = appendName; exports.appendLoopIteration = appendLoopIteration; exports.emptyLocation = emptyLocation; exports.parentLocation = parentLocation; exports.isLocationPrefix = isLocationPrefix; exports.locationsEqual = locationsEqual; exports.createStorage = createStorage; exports.createHistorySnapshot = createHistorySnapshot; exports.generateId = generateId; exports.createEntry = createEntry; exports.getOrCreateMetadata = getOrCreateMetadata; exports.loadStorage = loadStorage; exports.loadMetadata = loadMetadata; exports.flush = flush; exports.deleteEntriesWithPrefix = deleteEntriesWithPrefix; exports.getEntry = getEntry; exports.setEntry = setEntry; exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_STEP_TIMEOUT = DEFAULT_STEP_TIMEOUT; exports.WorkflowContextImpl = WorkflowContextImpl; exports.sleep = sleep; exports.Loop = Loop; exports.runWorkflow = runWorkflow; exports.replayWorkflowFromStep = replayWorkflowFromStep;
4228
- //# sourceMappingURL=chunk-GQWOLYBA.cjs.map
4324
+ //# sourceMappingURL=chunk-KLHCG2KY.cjs.map