@rivetkit/workflow-engine 2.1.6 → 2.1.8
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-JTLDEP6X.js → chunk-4ME2JBMC.js} +542 -210
- package/dist/tsup/chunk-4ME2JBMC.js.map +1 -0
- package/dist/tsup/{chunk-KQO2TD7T.cjs → chunk-OYYWSC77.cjs} +539 -207
- package/dist/tsup/chunk-OYYWSC77.cjs.map +1 -0
- package/dist/tsup/index.cjs +2 -2
- package/dist/tsup/index.cjs.map +1 -1
- package/dist/tsup/index.d.cts +93 -25
- package/dist/tsup/index.d.ts +93 -25
- package/dist/tsup/index.js +7 -7
- package/dist/tsup/testing.cjs +35 -23
- package/dist/tsup/testing.cjs.map +1 -1
- package/dist/tsup/testing.d.cts +2 -1
- package/dist/tsup/testing.d.ts +2 -1
- package/dist/tsup/testing.js +21 -9
- package/dist/tsup/testing.js.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +289 -113
- package/src/driver.ts +5 -0
- package/src/error-utils.ts +87 -0
- package/src/errors.ts +1 -0
- package/src/index.ts +214 -55
- package/src/keys.ts +26 -0
- package/src/location.ts +4 -1
- package/src/storage.ts +73 -20
- package/src/testing.ts +25 -4
- package/src/types.ts +48 -11
- package/dist/tsup/chunk-JTLDEP6X.js.map +0 -1
- package/dist/tsup/chunk-KQO2TD7T.cjs.map +0 -1
package/dist/tsup/index.d.cts
CHANGED
|
@@ -249,6 +249,43 @@ interface WorkflowError {
|
|
|
249
249
|
/** Custom error properties (for structured errors) */
|
|
250
250
|
metadata?: Record<string, unknown>;
|
|
251
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Error event emitted while a workflow is running.
|
|
254
|
+
*/
|
|
255
|
+
interface WorkflowStepErrorEvent {
|
|
256
|
+
workflowId: string;
|
|
257
|
+
stepName: string;
|
|
258
|
+
attempt: number;
|
|
259
|
+
maxRetries: number;
|
|
260
|
+
remainingRetries: number;
|
|
261
|
+
willRetry: boolean;
|
|
262
|
+
retryDelay?: number;
|
|
263
|
+
retryAt?: number;
|
|
264
|
+
error: WorkflowError;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Error event emitted when a rollback handler fails.
|
|
268
|
+
*/
|
|
269
|
+
interface WorkflowRollbackErrorEvent {
|
|
270
|
+
workflowId: string;
|
|
271
|
+
stepName: string;
|
|
272
|
+
error: WorkflowError;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Error event emitted for workflow-level failures outside individual steps.
|
|
276
|
+
*/
|
|
277
|
+
interface WorkflowRunErrorEvent {
|
|
278
|
+
workflowId: string;
|
|
279
|
+
error: WorkflowError;
|
|
280
|
+
}
|
|
281
|
+
type WorkflowErrorEvent = {
|
|
282
|
+
step: WorkflowStepErrorEvent;
|
|
283
|
+
} | {
|
|
284
|
+
rollback: WorkflowRollbackErrorEvent;
|
|
285
|
+
} | {
|
|
286
|
+
workflow: WorkflowRunErrorEvent;
|
|
287
|
+
};
|
|
288
|
+
type WorkflowErrorHandler = (event: WorkflowErrorEvent) => void | Promise<void>;
|
|
252
289
|
/**
|
|
253
290
|
* Complete storage state for a workflow.
|
|
254
291
|
*/
|
|
@@ -333,11 +370,10 @@ interface LoopConfig<S, T> {
|
|
|
333
370
|
name: string;
|
|
334
371
|
state?: S;
|
|
335
372
|
run: (ctx: WorkflowContextInterface, state: S) => LoopIterationResult<S, T>;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
historyKeep?: number;
|
|
373
|
+
/** Prune old loop iterations every N iterations. Default: 20. */
|
|
374
|
+
historyPruneInterval?: number;
|
|
375
|
+
/** Number of past iterations to retain when pruning. Defaults to historyPruneInterval. */
|
|
376
|
+
historySize?: number;
|
|
341
377
|
}
|
|
342
378
|
/**
|
|
343
379
|
* Configuration for a branch in join/race.
|
|
@@ -384,6 +420,7 @@ interface RunWorkflowOptions {
|
|
|
384
420
|
mode?: WorkflowRunMode;
|
|
385
421
|
logger?: Logger;
|
|
386
422
|
onHistoryUpdated?: (history: WorkflowHistorySnapshot) => void;
|
|
423
|
+
onError?: WorkflowErrorHandler;
|
|
387
424
|
}
|
|
388
425
|
type WorkflowFunction<TInput = unknown, TOutput = unknown> = (ctx: WorkflowContextInterface, input: TInput) => Promise<TOutput>;
|
|
389
426
|
/**
|
|
@@ -489,6 +526,10 @@ interface EngineDriver {
|
|
|
489
526
|
* Delete all keys with a given prefix.
|
|
490
527
|
*/
|
|
491
528
|
deletePrefix(prefix: Uint8Array): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Delete all keys in the half-open range [start, end).
|
|
531
|
+
*/
|
|
532
|
+
deleteRange(start: Uint8Array, end: Uint8Array): Promise<void>;
|
|
492
533
|
/**
|
|
493
534
|
* List all key-value pairs with a given prefix.
|
|
494
535
|
*
|
|
@@ -534,9 +575,7 @@ interface EngineDriver {
|
|
|
534
575
|
declare const DEFAULT_MAX_RETRIES = 3;
|
|
535
576
|
declare const DEFAULT_RETRY_BACKOFF_BASE = 100;
|
|
536
577
|
declare const DEFAULT_RETRY_BACKOFF_MAX = 30000;
|
|
537
|
-
declare const
|
|
538
|
-
declare const DEFAULT_LOOP_HISTORY_EVERY = 20;
|
|
539
|
-
declare const DEFAULT_LOOP_HISTORY_KEEP = 20;
|
|
578
|
+
declare const DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = 20;
|
|
540
579
|
declare const DEFAULT_STEP_TIMEOUT = 30000;
|
|
541
580
|
/**
|
|
542
581
|
* Internal representation of a rollback handler.
|
|
@@ -566,8 +605,9 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
566
605
|
private usedNamesInExecution;
|
|
567
606
|
private pendingCompletableMessageIds;
|
|
568
607
|
private historyNotifier?;
|
|
608
|
+
private onError?;
|
|
569
609
|
private logger?;
|
|
570
|
-
constructor(workflowId: string, storage: Storage, driver: EngineDriver, messageDriver: WorkflowMessageDriver, location?: Location, abortController?: AbortController, mode?: "forward" | "rollback", rollbackActions?: RollbackAction[], rollbackCheckpointSet?: boolean, historyNotifier?: () => void, logger?: Logger);
|
|
610
|
+
constructor(workflowId: string, storage: Storage, driver: EngineDriver, messageDriver: WorkflowMessageDriver, location?: Location, abortController?: AbortController, mode?: "forward" | "rollback", rollbackActions?: RollbackAction[], rollbackCheckpointSet?: boolean, historyNotifier?: () => void, onError?: WorkflowErrorHandler, logger?: Logger, visitedKeys?: Set<string>);
|
|
571
611
|
get abortSignal(): AbortSignal;
|
|
572
612
|
get queue(): WorkflowQueue;
|
|
573
613
|
isEvicted(): boolean;
|
|
@@ -582,6 +622,8 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
582
622
|
* Log a debug message using the configured logger.
|
|
583
623
|
*/
|
|
584
624
|
private log;
|
|
625
|
+
private notifyError;
|
|
626
|
+
private notifyStepError;
|
|
585
627
|
/**
|
|
586
628
|
* Mark a key as visited.
|
|
587
629
|
*/
|
|
@@ -639,20 +681,18 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
639
681
|
loop<S, T>(nameOrConfig: string | LoopConfig<S, T>, run?: (ctx: WorkflowContextInterface) => LoopIterationResult<undefined, T>): Promise<T>;
|
|
640
682
|
private executeLoop;
|
|
641
683
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* Loop locations always end with a NameIndex (number) because loops are
|
|
645
|
-
* created via appendName(). Even for nested loops, the innermost loop's
|
|
646
|
-
* location ends with its name index:
|
|
684
|
+
* Collect pending deletions for loop history pruning.
|
|
647
685
|
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
* This function removes iterations older than (currentIteration - historyKeep)
|
|
653
|
-
* every historyEvery iterations.
|
|
686
|
+
* Only deletes iterations in the range [fromIteration, keepFrom) where
|
|
687
|
+
* keepFrom = currentIteration - historySize. This avoids re-scanning
|
|
688
|
+
* already-deleted iterations.
|
|
654
689
|
*/
|
|
655
|
-
private
|
|
690
|
+
private collectLoopPruning;
|
|
691
|
+
/**
|
|
692
|
+
* Flush storage with optional pending deletions so pruning
|
|
693
|
+
* happens alongside the state write.
|
|
694
|
+
*/
|
|
695
|
+
private flushStorageWithDeletions;
|
|
656
696
|
sleep(name: string, durationMs: number): Promise<void>;
|
|
657
697
|
sleepUntil(name: string, timestampMs: number): Promise<void>;
|
|
658
698
|
private executeSleep;
|
|
@@ -757,7 +797,8 @@ declare class StepFailedError extends Error {
|
|
|
757
797
|
readonly stepName: string;
|
|
758
798
|
readonly originalError: unknown;
|
|
759
799
|
readonly attempts: number;
|
|
760
|
-
|
|
800
|
+
readonly retryAt: number;
|
|
801
|
+
constructor(stepName: string, originalError: unknown, attempts: number, retryAt: number);
|
|
761
802
|
}
|
|
762
803
|
/**
|
|
763
804
|
* Join had branch failures.
|
|
@@ -793,6 +834,11 @@ declare class EntryInProgressError extends Error {
|
|
|
793
834
|
constructor();
|
|
794
835
|
}
|
|
795
836
|
|
|
837
|
+
/**
|
|
838
|
+
* Extract structured error information from an error.
|
|
839
|
+
*/
|
|
840
|
+
declare function extractErrorInfo(error: unknown): WorkflowError;
|
|
841
|
+
|
|
796
842
|
/**
|
|
797
843
|
* Check if a path segment is a loop iteration marker.
|
|
798
844
|
*/
|
|
@@ -865,9 +911,23 @@ declare function loadStorage(driver: EngineDriver): Promise<Storage>;
|
|
|
865
911
|
*/
|
|
866
912
|
declare function loadMetadata(storage: Storage, driver: EngineDriver, entryId: string): Promise<EntryMetadata>;
|
|
867
913
|
/**
|
|
868
|
-
*
|
|
914
|
+
* Pending deletions collected by collectLoopPruning to be included
|
|
915
|
+
* in the next flush alongside the state write.
|
|
916
|
+
*/
|
|
917
|
+
interface PendingDeletions {
|
|
918
|
+
prefixes: Uint8Array[];
|
|
919
|
+
keys: Uint8Array[];
|
|
920
|
+
ranges: {
|
|
921
|
+
start: Uint8Array;
|
|
922
|
+
end: Uint8Array;
|
|
923
|
+
}[];
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Flush all dirty data to the driver. Optionally includes pending
|
|
927
|
+
* deletions so that history pruning happens alongside the
|
|
928
|
+
* state write.
|
|
869
929
|
*/
|
|
870
|
-
declare function flush(storage: Storage, driver: EngineDriver, onHistoryUpdated?: () => void): Promise<void>;
|
|
930
|
+
declare function flush(storage: Storage, driver: EngineDriver, onHistoryUpdated?: () => void, pendingDeletions?: PendingDeletions): Promise<void>;
|
|
871
931
|
/**
|
|
872
932
|
* Delete entries with a given location prefix (used for loop forgetting).
|
|
873
933
|
* Also cleans up associated metadata from both memory and driver.
|
|
@@ -894,5 +954,13 @@ declare const Loop: {
|
|
|
894
954
|
};
|
|
895
955
|
|
|
896
956
|
declare function runWorkflow<TInput, TOutput>(workflowId: string, workflowFn: WorkflowFunction<TInput, TOutput>, input: TInput, driver: EngineDriver, options?: RunWorkflowOptions): WorkflowHandle<TOutput>;
|
|
957
|
+
/**
|
|
958
|
+
* Remove a step and every later workflow entry, then schedule the workflow to
|
|
959
|
+
* start again immediately. Omitting `entryId` replays the workflow from the
|
|
960
|
+
* beginning.
|
|
961
|
+
*/
|
|
962
|
+
declare function replayWorkflowFromStep(workflowId: string, driver: EngineDriver, entryId?: string, options?: {
|
|
963
|
+
scheduleAlarm?: boolean;
|
|
964
|
+
}): Promise<WorkflowHistorySnapshot>;
|
|
897
965
|
|
|
898
|
-
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError,
|
|
966
|
+
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError, DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_BACKOFF_BASE, DEFAULT_RETRY_BACKOFF_MAX, DEFAULT_STEP_TIMEOUT, type EngineDriver, type Entry, EntryInProgressError, type EntryKind, type EntryKindType, type EntryMetadata, type EntryStatus, EvictedError, type History, HistoryDivergedError, type JoinEntry, JoinError, type KVEntry, type KVWrite, type Location, Loop, type LoopConfig, type LoopEntry, type LoopIterationMarker, type LoopResult, type Message, type MessageEntry, MessageWaitError, type NameIndex, type PathSegment, type RaceEntry, RaceError, type RemovedEntry, type RollbackCheckpointEntry, RollbackCheckpointError, type RollbackContextInterface, RollbackError, type RunWorkflowOptions, type SleepEntry, SleepError, type SleepState, type StepConfig, type StepEntry, StepExhaustedError, StepFailedError, type Storage, WorkflowContextImpl, type WorkflowContextInterface, type WorkflowEntryMetadataSnapshot, type WorkflowError, type WorkflowErrorEvent, type WorkflowErrorHandler, type WorkflowFunction, type WorkflowHandle, type WorkflowHistoryEntry, type WorkflowHistorySnapshot, type WorkflowMessageDriver, type WorkflowQueue, type WorkflowQueueMessage, type WorkflowQueueNextBatchOptions, type WorkflowQueueNextOptions, type WorkflowResult, type WorkflowRollbackErrorEvent, type WorkflowRunErrorEvent, type WorkflowRunMode, type WorkflowState, type WorkflowStepErrorEvent, appendLoopIteration, appendName, createEntry, createHistorySnapshot, createStorage, deleteEntriesWithPrefix, emptyLocation, extractErrorInfo, flush, generateId, getEntry, getOrCreateMetadata, isLocationPrefix, isLoopIterationMarker, loadMetadata, loadStorage, locationToKey, locationsEqual, parentLocation, registerName, replayWorkflowFromStep, resolveName, runWorkflow, setEntry };
|
package/dist/tsup/index.d.ts
CHANGED
|
@@ -249,6 +249,43 @@ interface WorkflowError {
|
|
|
249
249
|
/** Custom error properties (for structured errors) */
|
|
250
250
|
metadata?: Record<string, unknown>;
|
|
251
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Error event emitted while a workflow is running.
|
|
254
|
+
*/
|
|
255
|
+
interface WorkflowStepErrorEvent {
|
|
256
|
+
workflowId: string;
|
|
257
|
+
stepName: string;
|
|
258
|
+
attempt: number;
|
|
259
|
+
maxRetries: number;
|
|
260
|
+
remainingRetries: number;
|
|
261
|
+
willRetry: boolean;
|
|
262
|
+
retryDelay?: number;
|
|
263
|
+
retryAt?: number;
|
|
264
|
+
error: WorkflowError;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Error event emitted when a rollback handler fails.
|
|
268
|
+
*/
|
|
269
|
+
interface WorkflowRollbackErrorEvent {
|
|
270
|
+
workflowId: string;
|
|
271
|
+
stepName: string;
|
|
272
|
+
error: WorkflowError;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Error event emitted for workflow-level failures outside individual steps.
|
|
276
|
+
*/
|
|
277
|
+
interface WorkflowRunErrorEvent {
|
|
278
|
+
workflowId: string;
|
|
279
|
+
error: WorkflowError;
|
|
280
|
+
}
|
|
281
|
+
type WorkflowErrorEvent = {
|
|
282
|
+
step: WorkflowStepErrorEvent;
|
|
283
|
+
} | {
|
|
284
|
+
rollback: WorkflowRollbackErrorEvent;
|
|
285
|
+
} | {
|
|
286
|
+
workflow: WorkflowRunErrorEvent;
|
|
287
|
+
};
|
|
288
|
+
type WorkflowErrorHandler = (event: WorkflowErrorEvent) => void | Promise<void>;
|
|
252
289
|
/**
|
|
253
290
|
* Complete storage state for a workflow.
|
|
254
291
|
*/
|
|
@@ -333,11 +370,10 @@ interface LoopConfig<S, T> {
|
|
|
333
370
|
name: string;
|
|
334
371
|
state?: S;
|
|
335
372
|
run: (ctx: WorkflowContextInterface, state: S) => LoopIterationResult<S, T>;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
historyKeep?: number;
|
|
373
|
+
/** Prune old loop iterations every N iterations. Default: 20. */
|
|
374
|
+
historyPruneInterval?: number;
|
|
375
|
+
/** Number of past iterations to retain when pruning. Defaults to historyPruneInterval. */
|
|
376
|
+
historySize?: number;
|
|
341
377
|
}
|
|
342
378
|
/**
|
|
343
379
|
* Configuration for a branch in join/race.
|
|
@@ -384,6 +420,7 @@ interface RunWorkflowOptions {
|
|
|
384
420
|
mode?: WorkflowRunMode;
|
|
385
421
|
logger?: Logger;
|
|
386
422
|
onHistoryUpdated?: (history: WorkflowHistorySnapshot) => void;
|
|
423
|
+
onError?: WorkflowErrorHandler;
|
|
387
424
|
}
|
|
388
425
|
type WorkflowFunction<TInput = unknown, TOutput = unknown> = (ctx: WorkflowContextInterface, input: TInput) => Promise<TOutput>;
|
|
389
426
|
/**
|
|
@@ -489,6 +526,10 @@ interface EngineDriver {
|
|
|
489
526
|
* Delete all keys with a given prefix.
|
|
490
527
|
*/
|
|
491
528
|
deletePrefix(prefix: Uint8Array): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Delete all keys in the half-open range [start, end).
|
|
531
|
+
*/
|
|
532
|
+
deleteRange(start: Uint8Array, end: Uint8Array): Promise<void>;
|
|
492
533
|
/**
|
|
493
534
|
* List all key-value pairs with a given prefix.
|
|
494
535
|
*
|
|
@@ -534,9 +575,7 @@ interface EngineDriver {
|
|
|
534
575
|
declare const DEFAULT_MAX_RETRIES = 3;
|
|
535
576
|
declare const DEFAULT_RETRY_BACKOFF_BASE = 100;
|
|
536
577
|
declare const DEFAULT_RETRY_BACKOFF_MAX = 30000;
|
|
537
|
-
declare const
|
|
538
|
-
declare const DEFAULT_LOOP_HISTORY_EVERY = 20;
|
|
539
|
-
declare const DEFAULT_LOOP_HISTORY_KEEP = 20;
|
|
578
|
+
declare const DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = 20;
|
|
540
579
|
declare const DEFAULT_STEP_TIMEOUT = 30000;
|
|
541
580
|
/**
|
|
542
581
|
* Internal representation of a rollback handler.
|
|
@@ -566,8 +605,9 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
566
605
|
private usedNamesInExecution;
|
|
567
606
|
private pendingCompletableMessageIds;
|
|
568
607
|
private historyNotifier?;
|
|
608
|
+
private onError?;
|
|
569
609
|
private logger?;
|
|
570
|
-
constructor(workflowId: string, storage: Storage, driver: EngineDriver, messageDriver: WorkflowMessageDriver, location?: Location, abortController?: AbortController, mode?: "forward" | "rollback", rollbackActions?: RollbackAction[], rollbackCheckpointSet?: boolean, historyNotifier?: () => void, logger?: Logger);
|
|
610
|
+
constructor(workflowId: string, storage: Storage, driver: EngineDriver, messageDriver: WorkflowMessageDriver, location?: Location, abortController?: AbortController, mode?: "forward" | "rollback", rollbackActions?: RollbackAction[], rollbackCheckpointSet?: boolean, historyNotifier?: () => void, onError?: WorkflowErrorHandler, logger?: Logger, visitedKeys?: Set<string>);
|
|
571
611
|
get abortSignal(): AbortSignal;
|
|
572
612
|
get queue(): WorkflowQueue;
|
|
573
613
|
isEvicted(): boolean;
|
|
@@ -582,6 +622,8 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
582
622
|
* Log a debug message using the configured logger.
|
|
583
623
|
*/
|
|
584
624
|
private log;
|
|
625
|
+
private notifyError;
|
|
626
|
+
private notifyStepError;
|
|
585
627
|
/**
|
|
586
628
|
* Mark a key as visited.
|
|
587
629
|
*/
|
|
@@ -639,20 +681,18 @@ declare class WorkflowContextImpl implements WorkflowContextInterface {
|
|
|
639
681
|
loop<S, T>(nameOrConfig: string | LoopConfig<S, T>, run?: (ctx: WorkflowContextInterface) => LoopIterationResult<undefined, T>): Promise<T>;
|
|
640
682
|
private executeLoop;
|
|
641
683
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* Loop locations always end with a NameIndex (number) because loops are
|
|
645
|
-
* created via appendName(). Even for nested loops, the innermost loop's
|
|
646
|
-
* location ends with its name index:
|
|
684
|
+
* Collect pending deletions for loop history pruning.
|
|
647
685
|
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
* This function removes iterations older than (currentIteration - historyKeep)
|
|
653
|
-
* every historyEvery iterations.
|
|
686
|
+
* Only deletes iterations in the range [fromIteration, keepFrom) where
|
|
687
|
+
* keepFrom = currentIteration - historySize. This avoids re-scanning
|
|
688
|
+
* already-deleted iterations.
|
|
654
689
|
*/
|
|
655
|
-
private
|
|
690
|
+
private collectLoopPruning;
|
|
691
|
+
/**
|
|
692
|
+
* Flush storage with optional pending deletions so pruning
|
|
693
|
+
* happens alongside the state write.
|
|
694
|
+
*/
|
|
695
|
+
private flushStorageWithDeletions;
|
|
656
696
|
sleep(name: string, durationMs: number): Promise<void>;
|
|
657
697
|
sleepUntil(name: string, timestampMs: number): Promise<void>;
|
|
658
698
|
private executeSleep;
|
|
@@ -757,7 +797,8 @@ declare class StepFailedError extends Error {
|
|
|
757
797
|
readonly stepName: string;
|
|
758
798
|
readonly originalError: unknown;
|
|
759
799
|
readonly attempts: number;
|
|
760
|
-
|
|
800
|
+
readonly retryAt: number;
|
|
801
|
+
constructor(stepName: string, originalError: unknown, attempts: number, retryAt: number);
|
|
761
802
|
}
|
|
762
803
|
/**
|
|
763
804
|
* Join had branch failures.
|
|
@@ -793,6 +834,11 @@ declare class EntryInProgressError extends Error {
|
|
|
793
834
|
constructor();
|
|
794
835
|
}
|
|
795
836
|
|
|
837
|
+
/**
|
|
838
|
+
* Extract structured error information from an error.
|
|
839
|
+
*/
|
|
840
|
+
declare function extractErrorInfo(error: unknown): WorkflowError;
|
|
841
|
+
|
|
796
842
|
/**
|
|
797
843
|
* Check if a path segment is a loop iteration marker.
|
|
798
844
|
*/
|
|
@@ -865,9 +911,23 @@ declare function loadStorage(driver: EngineDriver): Promise<Storage>;
|
|
|
865
911
|
*/
|
|
866
912
|
declare function loadMetadata(storage: Storage, driver: EngineDriver, entryId: string): Promise<EntryMetadata>;
|
|
867
913
|
/**
|
|
868
|
-
*
|
|
914
|
+
* Pending deletions collected by collectLoopPruning to be included
|
|
915
|
+
* in the next flush alongside the state write.
|
|
916
|
+
*/
|
|
917
|
+
interface PendingDeletions {
|
|
918
|
+
prefixes: Uint8Array[];
|
|
919
|
+
keys: Uint8Array[];
|
|
920
|
+
ranges: {
|
|
921
|
+
start: Uint8Array;
|
|
922
|
+
end: Uint8Array;
|
|
923
|
+
}[];
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Flush all dirty data to the driver. Optionally includes pending
|
|
927
|
+
* deletions so that history pruning happens alongside the
|
|
928
|
+
* state write.
|
|
869
929
|
*/
|
|
870
|
-
declare function flush(storage: Storage, driver: EngineDriver, onHistoryUpdated?: () => void): Promise<void>;
|
|
930
|
+
declare function flush(storage: Storage, driver: EngineDriver, onHistoryUpdated?: () => void, pendingDeletions?: PendingDeletions): Promise<void>;
|
|
871
931
|
/**
|
|
872
932
|
* Delete entries with a given location prefix (used for loop forgetting).
|
|
873
933
|
* Also cleans up associated metadata from both memory and driver.
|
|
@@ -894,5 +954,13 @@ declare const Loop: {
|
|
|
894
954
|
};
|
|
895
955
|
|
|
896
956
|
declare function runWorkflow<TInput, TOutput>(workflowId: string, workflowFn: WorkflowFunction<TInput, TOutput>, input: TInput, driver: EngineDriver, options?: RunWorkflowOptions): WorkflowHandle<TOutput>;
|
|
957
|
+
/**
|
|
958
|
+
* Remove a step and every later workflow entry, then schedule the workflow to
|
|
959
|
+
* start again immediately. Omitting `entryId` replays the workflow from the
|
|
960
|
+
* beginning.
|
|
961
|
+
*/
|
|
962
|
+
declare function replayWorkflowFromStep(workflowId: string, driver: EngineDriver, entryId?: string, options?: {
|
|
963
|
+
scheduleAlarm?: boolean;
|
|
964
|
+
}): Promise<WorkflowHistorySnapshot>;
|
|
897
965
|
|
|
898
|
-
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError,
|
|
966
|
+
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError, DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_BACKOFF_BASE, DEFAULT_RETRY_BACKOFF_MAX, DEFAULT_STEP_TIMEOUT, type EngineDriver, type Entry, EntryInProgressError, type EntryKind, type EntryKindType, type EntryMetadata, type EntryStatus, EvictedError, type History, HistoryDivergedError, type JoinEntry, JoinError, type KVEntry, type KVWrite, type Location, Loop, type LoopConfig, type LoopEntry, type LoopIterationMarker, type LoopResult, type Message, type MessageEntry, MessageWaitError, type NameIndex, type PathSegment, type RaceEntry, RaceError, type RemovedEntry, type RollbackCheckpointEntry, RollbackCheckpointError, type RollbackContextInterface, RollbackError, type RunWorkflowOptions, type SleepEntry, SleepError, type SleepState, type StepConfig, type StepEntry, StepExhaustedError, StepFailedError, type Storage, WorkflowContextImpl, type WorkflowContextInterface, type WorkflowEntryMetadataSnapshot, type WorkflowError, type WorkflowErrorEvent, type WorkflowErrorHandler, type WorkflowFunction, type WorkflowHandle, type WorkflowHistoryEntry, type WorkflowHistorySnapshot, type WorkflowMessageDriver, type WorkflowQueue, type WorkflowQueueMessage, type WorkflowQueueNextBatchOptions, type WorkflowQueueNextOptions, type WorkflowResult, type WorkflowRollbackErrorEvent, type WorkflowRunErrorEvent, type WorkflowRunMode, type WorkflowState, type WorkflowStepErrorEvent, appendLoopIteration, appendName, createEntry, createHistorySnapshot, createStorage, deleteEntriesWithPrefix, emptyLocation, extractErrorInfo, flush, generateId, getEntry, getOrCreateMetadata, isLocationPrefix, isLoopIterationMarker, loadMetadata, loadStorage, locationToKey, locationsEqual, parentLocation, registerName, replayWorkflowFromStep, resolveName, runWorkflow, setEntry };
|
package/dist/tsup/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CancelledError,
|
|
3
3
|
CriticalError,
|
|
4
|
-
|
|
5
|
-
DEFAULT_LOOP_HISTORY_EVERY,
|
|
6
|
-
DEFAULT_LOOP_HISTORY_KEEP,
|
|
4
|
+
DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL,
|
|
7
5
|
DEFAULT_MAX_RETRIES,
|
|
8
6
|
DEFAULT_RETRY_BACKOFF_BASE,
|
|
9
7
|
DEFAULT_RETRY_BACKOFF_MAX,
|
|
@@ -28,6 +26,7 @@ import {
|
|
|
28
26
|
createStorage,
|
|
29
27
|
deleteEntriesWithPrefix,
|
|
30
28
|
emptyLocation,
|
|
29
|
+
extractErrorInfo,
|
|
31
30
|
flush,
|
|
32
31
|
generateId,
|
|
33
32
|
getEntry,
|
|
@@ -40,16 +39,15 @@ import {
|
|
|
40
39
|
locationsEqual,
|
|
41
40
|
parentLocation,
|
|
42
41
|
registerName,
|
|
42
|
+
replayWorkflowFromStep,
|
|
43
43
|
resolveName,
|
|
44
44
|
runWorkflow,
|
|
45
45
|
setEntry
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-4ME2JBMC.js";
|
|
47
47
|
export {
|
|
48
48
|
CancelledError,
|
|
49
49
|
CriticalError,
|
|
50
|
-
|
|
51
|
-
DEFAULT_LOOP_HISTORY_EVERY,
|
|
52
|
-
DEFAULT_LOOP_HISTORY_KEEP,
|
|
50
|
+
DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL,
|
|
53
51
|
DEFAULT_MAX_RETRIES,
|
|
54
52
|
DEFAULT_RETRY_BACKOFF_BASE,
|
|
55
53
|
DEFAULT_RETRY_BACKOFF_MAX,
|
|
@@ -74,6 +72,7 @@ export {
|
|
|
74
72
|
createStorage,
|
|
75
73
|
deleteEntriesWithPrefix,
|
|
76
74
|
emptyLocation,
|
|
75
|
+
extractErrorInfo,
|
|
77
76
|
flush,
|
|
78
77
|
generateId,
|
|
79
78
|
getEntry,
|
|
@@ -86,6 +85,7 @@ export {
|
|
|
86
85
|
locationsEqual,
|
|
87
86
|
parentLocation,
|
|
88
87
|
registerName,
|
|
88
|
+
replayWorkflowFromStep,
|
|
89
89
|
resolveName,
|
|
90
90
|
runWorkflow,
|
|
91
91
|
setEntry
|
package/dist/tsup/testing.cjs
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
var
|
|
50
|
+
var _chunkOYYWSC77cjs = require('./chunk-OYYWSC77.cjs');
|
|
51
51
|
|
|
52
52
|
// src/testing.ts
|
|
53
53
|
var InMemoryWorkflowMessageDriver = class {
|
|
@@ -88,14 +88,16 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
async completeMessage(messageId) {
|
|
91
|
-
const index = this.#messages.findIndex(
|
|
91
|
+
const index = this.#messages.findIndex(
|
|
92
|
+
(message) => message.id === messageId
|
|
93
|
+
);
|
|
92
94
|
if (index !== -1) {
|
|
93
95
|
this.#messages.splice(index, 1);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
async waitForMessages(messageNames, abortSignal) {
|
|
97
99
|
if (abortSignal.aborted) {
|
|
98
|
-
throw new (0,
|
|
100
|
+
throw new (0, _chunkOYYWSC77cjs.EvictedError)();
|
|
99
101
|
}
|
|
100
102
|
const nameSet = messageNames.length > 0 ? new Set(messageNames) : void 0;
|
|
101
103
|
if (this.#messages.some(
|
|
@@ -116,10 +118,12 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
116
118
|
},
|
|
117
119
|
abortSignal,
|
|
118
120
|
onAbort: () => {
|
|
119
|
-
waiter.reject(new (0,
|
|
121
|
+
waiter.reject(new (0, _chunkOYYWSC77cjs.EvictedError)());
|
|
120
122
|
}
|
|
121
123
|
};
|
|
122
|
-
abortSignal.addEventListener("abort", waiter.onAbort, {
|
|
124
|
+
abortSignal.addEventListener("abort", waiter.onAbort, {
|
|
125
|
+
once: true
|
|
126
|
+
});
|
|
123
127
|
this.#waiters.add(waiter);
|
|
124
128
|
});
|
|
125
129
|
}
|
|
@@ -154,48 +158,56 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
154
158
|
__init4() {this.workerPollInterval = 100}
|
|
155
159
|
__init5() {this.messageDriver = this.#inMemoryMessageDriver}
|
|
156
160
|
async get(key) {
|
|
157
|
-
await
|
|
158
|
-
const entry = this.kv.get(
|
|
161
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
162
|
+
const entry = this.kv.get(_chunkOYYWSC77cjs.keyToHex.call(void 0, key));
|
|
159
163
|
return _nullishCoalesce((entry == null ? void 0 : entry.value), () => ( null));
|
|
160
164
|
}
|
|
161
165
|
async set(key, value) {
|
|
162
|
-
await
|
|
163
|
-
this.kv.set(
|
|
166
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
167
|
+
this.kv.set(_chunkOYYWSC77cjs.keyToHex.call(void 0, key), { key, value });
|
|
164
168
|
}
|
|
165
169
|
async delete(key) {
|
|
166
|
-
await
|
|
167
|
-
this.kv.delete(
|
|
170
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
171
|
+
this.kv.delete(_chunkOYYWSC77cjs.keyToHex.call(void 0, key));
|
|
168
172
|
}
|
|
169
173
|
async deletePrefix(prefix) {
|
|
170
|
-
await
|
|
174
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
175
|
+
for (const [hexKey, entry] of this.kv) {
|
|
176
|
+
if (_chunkOYYWSC77cjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
177
|
+
this.kv.delete(hexKey);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async deleteRange(start, end) {
|
|
182
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
171
183
|
for (const [hexKey, entry] of this.kv) {
|
|
172
|
-
if (
|
|
184
|
+
if (_chunkOYYWSC77cjs.compareKeys.call(void 0, entry.key, start) >= 0 && _chunkOYYWSC77cjs.compareKeys.call(void 0, entry.key, end) < 0) {
|
|
173
185
|
this.kv.delete(hexKey);
|
|
174
186
|
}
|
|
175
187
|
}
|
|
176
188
|
}
|
|
177
189
|
async list(prefix) {
|
|
178
|
-
await
|
|
190
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
179
191
|
const results = [];
|
|
180
192
|
for (const entry of this.kv.values()) {
|
|
181
|
-
if (
|
|
193
|
+
if (_chunkOYYWSC77cjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
182
194
|
results.push({ key: entry.key, value: entry.value });
|
|
183
195
|
}
|
|
184
196
|
}
|
|
185
|
-
return results.sort((a, b) =>
|
|
197
|
+
return results.sort((a, b) => _chunkOYYWSC77cjs.compareKeys.call(void 0, a.key, b.key));
|
|
186
198
|
}
|
|
187
199
|
async batch(writes) {
|
|
188
|
-
await
|
|
200
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
189
201
|
for (const { key, value } of writes) {
|
|
190
|
-
this.kv.set(
|
|
202
|
+
this.kv.set(_chunkOYYWSC77cjs.keyToHex.call(void 0, key), { key, value });
|
|
191
203
|
}
|
|
192
204
|
}
|
|
193
205
|
async setAlarm(workflowId, wakeAt) {
|
|
194
|
-
await
|
|
206
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
195
207
|
this.alarms.set(workflowId, wakeAt);
|
|
196
208
|
}
|
|
197
209
|
async clearAlarm(workflowId) {
|
|
198
|
-
await
|
|
210
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, this.latency);
|
|
199
211
|
this.alarms.delete(workflowId);
|
|
200
212
|
}
|
|
201
213
|
async waitForMessages(messageNames, abortSignal) {
|
|
@@ -206,7 +218,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
206
218
|
}
|
|
207
219
|
while (true) {
|
|
208
220
|
if (abortSignal.aborted) {
|
|
209
|
-
throw new (0,
|
|
221
|
+
throw new (0, _chunkOYYWSC77cjs.EvictedError)();
|
|
210
222
|
}
|
|
211
223
|
const messages = await this.messageDriver.receiveMessages({
|
|
212
224
|
names: messageNames.length > 0 ? messageNames : void 0,
|
|
@@ -216,7 +228,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
216
228
|
if (messages.length > 0) {
|
|
217
229
|
return;
|
|
218
230
|
}
|
|
219
|
-
await
|
|
231
|
+
await _chunkOYYWSC77cjs.sleep.call(void 0, Math.max(1, this.latency));
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
/**
|
|
@@ -312,5 +324,5 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
312
324
|
|
|
313
325
|
|
|
314
326
|
|
|
315
|
-
exports.CancelledError =
|
|
327
|
+
exports.CancelledError = _chunkOYYWSC77cjs.CancelledError; exports.CriticalError = _chunkOYYWSC77cjs.CriticalError; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = _chunkOYYWSC77cjs.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_MAX_RETRIES = _chunkOYYWSC77cjs.DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = _chunkOYYWSC77cjs.DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = _chunkOYYWSC77cjs.DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_STEP_TIMEOUT = _chunkOYYWSC77cjs.DEFAULT_STEP_TIMEOUT; exports.EntryInProgressError = _chunkOYYWSC77cjs.EntryInProgressError; exports.EvictedError = _chunkOYYWSC77cjs.EvictedError; exports.HistoryDivergedError = _chunkOYYWSC77cjs.HistoryDivergedError; exports.InMemoryDriver = InMemoryDriver; exports.JoinError = _chunkOYYWSC77cjs.JoinError; exports.Loop = _chunkOYYWSC77cjs.Loop; exports.MessageWaitError = _chunkOYYWSC77cjs.MessageWaitError; exports.RaceError = _chunkOYYWSC77cjs.RaceError; exports.RollbackCheckpointError = _chunkOYYWSC77cjs.RollbackCheckpointError; exports.RollbackError = _chunkOYYWSC77cjs.RollbackError; exports.SleepError = _chunkOYYWSC77cjs.SleepError; exports.StepExhaustedError = _chunkOYYWSC77cjs.StepExhaustedError; exports.StepFailedError = _chunkOYYWSC77cjs.StepFailedError; exports.WorkflowContextImpl = _chunkOYYWSC77cjs.WorkflowContextImpl; exports.appendLoopIteration = _chunkOYYWSC77cjs.appendLoopIteration; exports.appendName = _chunkOYYWSC77cjs.appendName; exports.createEntry = _chunkOYYWSC77cjs.createEntry; exports.createHistorySnapshot = _chunkOYYWSC77cjs.createHistorySnapshot; exports.createStorage = _chunkOYYWSC77cjs.createStorage; exports.deleteEntriesWithPrefix = _chunkOYYWSC77cjs.deleteEntriesWithPrefix; exports.emptyLocation = _chunkOYYWSC77cjs.emptyLocation; exports.extractErrorInfo = _chunkOYYWSC77cjs.extractErrorInfo; exports.flush = _chunkOYYWSC77cjs.flush; exports.generateId = _chunkOYYWSC77cjs.generateId; exports.getEntry = _chunkOYYWSC77cjs.getEntry; exports.getOrCreateMetadata = _chunkOYYWSC77cjs.getOrCreateMetadata; exports.isLocationPrefix = _chunkOYYWSC77cjs.isLocationPrefix; exports.isLoopIterationMarker = _chunkOYYWSC77cjs.isLoopIterationMarker; exports.loadMetadata = _chunkOYYWSC77cjs.loadMetadata; exports.loadStorage = _chunkOYYWSC77cjs.loadStorage; exports.locationToKey = _chunkOYYWSC77cjs.locationToKey; exports.locationsEqual = _chunkOYYWSC77cjs.locationsEqual; exports.parentLocation = _chunkOYYWSC77cjs.parentLocation; exports.registerName = _chunkOYYWSC77cjs.registerName; exports.replayWorkflowFromStep = _chunkOYYWSC77cjs.replayWorkflowFromStep; exports.resolveName = _chunkOYYWSC77cjs.resolveName; exports.runWorkflow = _chunkOYYWSC77cjs.runWorkflow; exports.setEntry = _chunkOYYWSC77cjs.setEntry;
|
|
316
328
|
//# sourceMappingURL=testing.cjs.map
|