@rivetkit/workflow-engine 3.0.1-preview.2 → 3.0.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/tsup/{chunk-OQDLVTH2.js → chunk-JMOI2OHA.js} +25 -27
- package/dist/tsup/chunk-JMOI2OHA.js.map +1 -0
- package/dist/tsup/{chunk-AO3IZAQ4.cjs → chunk-L4MA54VF.cjs} +25 -27
- package/dist/tsup/chunk-L4MA54VF.cjs.map +1 -0
- package/dist/tsup/index.cjs +2 -2
- package/dist/tsup/index.js +1 -1
- package/dist/tsup/testing.cjs +25 -25
- package/dist/tsup/testing.js +1 -1
- package/package.json +1 -1
- package/src/storage.ts +27 -40
- package/dist/tsup/chunk-AO3IZAQ4.cjs.map +0 -1
- package/dist/tsup/chunk-OQDLVTH2.js.map +0 -1
package/dist/tsup/testing.cjs
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
var
|
|
50
|
+
var _chunkL4MA54VFcjs = require('./chunk-L4MA54VF.cjs');
|
|
51
51
|
|
|
52
52
|
// src/testing.ts
|
|
53
53
|
var InMemoryWorkflowMessageDriver = class {
|
|
@@ -97,7 +97,7 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
97
97
|
}
|
|
98
98
|
async waitForMessages(messageNames, abortSignal) {
|
|
99
99
|
if (abortSignal.aborted) {
|
|
100
|
-
throw new (0,
|
|
100
|
+
throw new (0, _chunkL4MA54VFcjs.EvictedError)();
|
|
101
101
|
}
|
|
102
102
|
const nameSet = messageNames.length > 0 ? new Set(messageNames) : void 0;
|
|
103
103
|
if (this.#messages.some(
|
|
@@ -118,7 +118,7 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
118
118
|
},
|
|
119
119
|
abortSignal,
|
|
120
120
|
onAbort: () => {
|
|
121
|
-
waiter.reject(new (0,
|
|
121
|
+
waiter.reject(new (0, _chunkL4MA54VFcjs.EvictedError)());
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
abortSignal.addEventListener("abort", waiter.onAbort, {
|
|
@@ -158,62 +158,62 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
158
158
|
__init4() {this.workerPollInterval = 100}
|
|
159
159
|
__init5() {this.messageDriver = this.#inMemoryMessageDriver}
|
|
160
160
|
async get(key) {
|
|
161
|
-
await
|
|
162
|
-
const entry = this.kv.get(
|
|
161
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
162
|
+
const entry = this.kv.get(_chunkL4MA54VFcjs.keyToHex.call(void 0, key));
|
|
163
163
|
return _nullishCoalesce((entry == null ? void 0 : entry.value), () => ( null));
|
|
164
164
|
}
|
|
165
165
|
async set(key, value) {
|
|
166
|
-
await
|
|
167
|
-
this.kv.set(
|
|
166
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
167
|
+
this.kv.set(_chunkL4MA54VFcjs.keyToHex.call(void 0, key), { key, value });
|
|
168
168
|
}
|
|
169
169
|
async delete(key) {
|
|
170
|
-
await
|
|
171
|
-
this.kv.delete(
|
|
170
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
171
|
+
this.kv.delete(_chunkL4MA54VFcjs.keyToHex.call(void 0, key));
|
|
172
172
|
}
|
|
173
173
|
async batchDelete(keys) {
|
|
174
|
-
await
|
|
174
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
175
175
|
for (const key of keys) {
|
|
176
|
-
this.kv.delete(
|
|
176
|
+
this.kv.delete(_chunkL4MA54VFcjs.keyToHex.call(void 0, key));
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
async deletePrefix(prefix) {
|
|
180
|
-
await
|
|
180
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
181
181
|
for (const [hexKey, entry] of this.kv) {
|
|
182
|
-
if (
|
|
182
|
+
if (_chunkL4MA54VFcjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
183
183
|
this.kv.delete(hexKey);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
async deleteRange(start, end) {
|
|
188
|
-
await
|
|
188
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
189
189
|
for (const [hexKey, entry] of this.kv) {
|
|
190
|
-
if (
|
|
190
|
+
if (_chunkL4MA54VFcjs.compareKeys.call(void 0, entry.key, start) >= 0 && _chunkL4MA54VFcjs.compareKeys.call(void 0, entry.key, end) < 0) {
|
|
191
191
|
this.kv.delete(hexKey);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
async list(prefix) {
|
|
196
|
-
await
|
|
196
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
197
197
|
const results = [];
|
|
198
198
|
for (const entry of this.kv.values()) {
|
|
199
|
-
if (
|
|
199
|
+
if (_chunkL4MA54VFcjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
200
200
|
results.push({ key: entry.key, value: entry.value });
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
return results.sort((a, b) =>
|
|
203
|
+
return results.sort((a, b) => _chunkL4MA54VFcjs.compareKeys.call(void 0, a.key, b.key));
|
|
204
204
|
}
|
|
205
205
|
async batch(writes) {
|
|
206
|
-
await
|
|
206
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
207
207
|
for (const { key, value } of writes) {
|
|
208
|
-
this.kv.set(
|
|
208
|
+
this.kv.set(_chunkL4MA54VFcjs.keyToHex.call(void 0, key), { key, value });
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
async setAlarm(workflowId, wakeAt) {
|
|
212
|
-
await
|
|
212
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
213
213
|
this.alarms.set(workflowId, wakeAt);
|
|
214
214
|
}
|
|
215
215
|
async clearAlarm(workflowId) {
|
|
216
|
-
await
|
|
216
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, this.latency);
|
|
217
217
|
this.alarms.delete(workflowId);
|
|
218
218
|
}
|
|
219
219
|
async waitForMessages(messageNames, abortSignal) {
|
|
@@ -224,7 +224,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
224
224
|
}
|
|
225
225
|
while (true) {
|
|
226
226
|
if (abortSignal.aborted) {
|
|
227
|
-
throw new (0,
|
|
227
|
+
throw new (0, _chunkL4MA54VFcjs.EvictedError)();
|
|
228
228
|
}
|
|
229
229
|
const messages = await this.messageDriver.receiveMessages({
|
|
230
230
|
names: messageNames.length > 0 ? messageNames : void 0,
|
|
@@ -234,7 +234,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
234
234
|
if (messages.length > 0) {
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
|
-
await
|
|
237
|
+
await _chunkL4MA54VFcjs.sleep.call(void 0, Math.max(1, this.latency));
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
@@ -330,5 +330,5 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
330
330
|
|
|
331
331
|
|
|
332
332
|
|
|
333
|
-
exports.CancelledError =
|
|
333
|
+
exports.CancelledError = _chunkL4MA54VFcjs.CancelledError; exports.CriticalError = _chunkL4MA54VFcjs.CriticalError; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = _chunkL4MA54VFcjs.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_MAX_RETRIES = _chunkL4MA54VFcjs.DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = _chunkL4MA54VFcjs.DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = _chunkL4MA54VFcjs.DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_STEP_TIMEOUT = _chunkL4MA54VFcjs.DEFAULT_STEP_TIMEOUT; exports.EntryInProgressError = _chunkL4MA54VFcjs.EntryInProgressError; exports.EvictedError = _chunkL4MA54VFcjs.EvictedError; exports.HistoryDivergedError = _chunkL4MA54VFcjs.HistoryDivergedError; exports.InMemoryDriver = InMemoryDriver; exports.JoinError = _chunkL4MA54VFcjs.JoinError; exports.Loop = _chunkL4MA54VFcjs.Loop; exports.MessageWaitError = _chunkL4MA54VFcjs.MessageWaitError; exports.RaceError = _chunkL4MA54VFcjs.RaceError; exports.RollbackCheckpointError = _chunkL4MA54VFcjs.RollbackCheckpointError; exports.RollbackError = _chunkL4MA54VFcjs.RollbackError; exports.SleepError = _chunkL4MA54VFcjs.SleepError; exports.StepExhaustedError = _chunkL4MA54VFcjs.StepExhaustedError; exports.StepFailedError = _chunkL4MA54VFcjs.StepFailedError; exports.WorkflowContextImpl = _chunkL4MA54VFcjs.WorkflowContextImpl; exports.appendLoopIteration = _chunkL4MA54VFcjs.appendLoopIteration; exports.appendName = _chunkL4MA54VFcjs.appendName; exports.createEntry = _chunkL4MA54VFcjs.createEntry; exports.createHistorySnapshot = _chunkL4MA54VFcjs.createHistorySnapshot; exports.createStorage = _chunkL4MA54VFcjs.createStorage; exports.deleteEntriesWithPrefix = _chunkL4MA54VFcjs.deleteEntriesWithPrefix; exports.emptyLocation = _chunkL4MA54VFcjs.emptyLocation; exports.extractErrorInfo = _chunkL4MA54VFcjs.extractErrorInfo; exports.flush = _chunkL4MA54VFcjs.flush; exports.generateId = _chunkL4MA54VFcjs.generateId; exports.getEntry = _chunkL4MA54VFcjs.getEntry; exports.getOrCreateMetadata = _chunkL4MA54VFcjs.getOrCreateMetadata; exports.isLocationPrefix = _chunkL4MA54VFcjs.isLocationPrefix; exports.isLoopIterationMarker = _chunkL4MA54VFcjs.isLoopIterationMarker; exports.loadMetadata = _chunkL4MA54VFcjs.loadMetadata; exports.loadStorage = _chunkL4MA54VFcjs.loadStorage; exports.locationToKey = _chunkL4MA54VFcjs.locationToKey; exports.locationsEqual = _chunkL4MA54VFcjs.locationsEqual; exports.parentLocation = _chunkL4MA54VFcjs.parentLocation; exports.registerName = _chunkL4MA54VFcjs.registerName; exports.replayWorkflowFromStep = _chunkL4MA54VFcjs.replayWorkflowFromStep; exports.resolveName = _chunkL4MA54VFcjs.resolveName; exports.runWorkflow = _chunkL4MA54VFcjs.runWorkflow; exports.setEntry = _chunkL4MA54VFcjs.setEntry;
|
|
334
334
|
//# sourceMappingURL=testing.cjs.map
|
package/dist/tsup/testing.js
CHANGED
package/package.json
CHANGED
package/src/storage.ts
CHANGED
|
@@ -408,26 +408,32 @@ async function runDeletes(
|
|
|
408
408
|
driver: EngineDriver,
|
|
409
409
|
deletions: PendingDeletions,
|
|
410
410
|
): Promise<boolean> {
|
|
411
|
-
const
|
|
411
|
+
const metadataOps = splitBatchDeletes(deletions.keys).map(
|
|
412
|
+
(chunk) => () => driver.batchDelete(chunk),
|
|
413
|
+
);
|
|
414
|
+
const historyOps = [
|
|
412
415
|
...deletions.prefixes.map(
|
|
413
416
|
(prefix) => () => driver.deletePrefix(prefix),
|
|
414
417
|
),
|
|
415
418
|
...deletions.ranges.map(
|
|
416
419
|
(range) => () => driver.deleteRange(range.start, range.end),
|
|
417
420
|
),
|
|
418
|
-
...splitBatchDeletes(deletions.keys).map(
|
|
419
|
-
(chunk) => () => driver.batchDelete(chunk),
|
|
420
|
-
),
|
|
421
421
|
];
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
422
|
+
// Keep history discoverable until its metadata is removed, including after a restart.
|
|
423
|
+
for (const ops of [metadataOps, historyOps]) {
|
|
424
|
+
for (let i = 0; i < ops.length; i += MAX_CONCURRENT_DELETES) {
|
|
425
|
+
const results = await Promise.allSettled(
|
|
426
|
+
ops
|
|
427
|
+
.slice(i, i + MAX_CONCURRENT_DELETES)
|
|
428
|
+
.map((op) => Promise.resolve().then(op)),
|
|
429
|
+
);
|
|
430
|
+
const failed = results.find(
|
|
431
|
+
(result) => result.status === "rejected",
|
|
432
|
+
);
|
|
433
|
+
if (failed?.status === "rejected") throw failed.reason;
|
|
434
|
+
}
|
|
429
435
|
}
|
|
430
|
-
return
|
|
436
|
+
return metadataOps.length > 0 || historyOps.length > 0;
|
|
431
437
|
}
|
|
432
438
|
|
|
433
439
|
/**
|
|
@@ -440,40 +446,21 @@ export async function deleteEntriesWithPrefix(
|
|
|
440
446
|
prefixLocation: Location,
|
|
441
447
|
onHistoryUpdated?: () => void,
|
|
442
448
|
): Promise<void> {
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
await runDeletes(driver,
|
|
447
|
-
|
|
448
|
-
if (deletions.keys.length > 0 && onHistoryUpdated) {
|
|
449
|
-
onHistoryUpdated();
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Remove entries matching a location prefix from memory and collect
|
|
455
|
-
* the driver-level deletion operations. The returned PendingDeletions
|
|
456
|
-
* can be applied immediately or batched with a flush.
|
|
457
|
-
*/
|
|
458
|
-
export function collectDeletionsForPrefix(
|
|
459
|
-
storage: Storage,
|
|
460
|
-
prefixLocation: Location,
|
|
461
|
-
): PendingDeletions {
|
|
462
|
-
const pending: PendingDeletions = {
|
|
449
|
+
const entries = [...storage.history.entries].filter(([, entry]) =>
|
|
450
|
+
isLocationPrefix(prefixLocation, entry.location),
|
|
451
|
+
);
|
|
452
|
+
await runDeletes(driver, {
|
|
463
453
|
prefixes: [buildHistoryPrefix(prefixLocation)],
|
|
464
|
-
keys: [],
|
|
454
|
+
keys: entries.map(([, entry]) => buildEntryMetadataKey(entry.id)),
|
|
465
455
|
ranges: [],
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (isLocationPrefix(prefixLocation, entry.location)) {
|
|
470
|
-
pending.keys.push(buildEntryMetadataKey(entry.id));
|
|
456
|
+
});
|
|
457
|
+
for (const [key, entry] of entries) {
|
|
458
|
+
if (storage.history.entries.get(key) === entry) {
|
|
471
459
|
storage.entryMetadata.delete(entry.id);
|
|
472
460
|
storage.history.entries.delete(key);
|
|
473
461
|
}
|
|
474
462
|
}
|
|
475
|
-
|
|
476
|
-
return pending;
|
|
463
|
+
if (entries.length > 0 && onHistoryUpdated) onHistoryUpdated();
|
|
477
464
|
}
|
|
478
465
|
|
|
479
466
|
/**
|