@rivetkit/workflow-engine 2.1.5 → 2.1.6-rc.1
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-MMWB37UG.js} +449 -209
- package/dist/tsup/chunk-MMWB37UG.js.map +1 -0
- package/dist/tsup/{chunk-KQO2TD7T.cjs → chunk-SHICGAKC.cjs} +448 -208
- package/dist/tsup/chunk-SHICGAKC.cjs.map +1 -0
- package/dist/tsup/index.cjs +2 -4
- package/dist/tsup/index.cjs.map +1 -1
- package/dist/tsup/index.d.cts +85 -25
- package/dist/tsup/index.d.ts +85 -25
- package/dist/tsup/index.js +5 -7
- package/dist/tsup/testing.cjs +35 -25
- 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 +19 -9
- package/dist/tsup/testing.js.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +298 -114
- package/src/driver.ts +5 -0
- package/src/error-utils.ts +87 -0
- package/src/errors.ts +1 -0
- package/src/index.ts +84 -55
- package/src/keys.ts +26 -0
- package/src/location.ts +4 -1
- package/src/storage.ts +62 -21
- 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
|
-
|
|
653
|
-
|
|
686
|
+
* Only deletes iterations in the range [fromIteration, keepFrom) where
|
|
687
|
+
* keepFrom = currentIteration - historySize. This avoids re-scanning
|
|
688
|
+
* already-deleted iterations.
|
|
689
|
+
*/
|
|
690
|
+
private collectLoopPruning;
|
|
691
|
+
/**
|
|
692
|
+
* Flush storage with optional pending deletions so pruning
|
|
693
|
+
* happens alongside the state write.
|
|
654
694
|
*/
|
|
655
|
-
private
|
|
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.
|
|
@@ -895,4 +955,4 @@ declare const Loop: {
|
|
|
895
955
|
|
|
896
956
|
declare function runWorkflow<TInput, TOutput>(workflowId: string, workflowFn: WorkflowFunction<TInput, TOutput>, input: TInput, driver: EngineDriver, options?: RunWorkflowOptions): WorkflowHandle<TOutput>;
|
|
897
957
|
|
|
898
|
-
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError,
|
|
958
|
+
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, 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
|
-
|
|
653
|
-
|
|
686
|
+
* Only deletes iterations in the range [fromIteration, keepFrom) where
|
|
687
|
+
* keepFrom = currentIteration - historySize. This avoids re-scanning
|
|
688
|
+
* already-deleted iterations.
|
|
689
|
+
*/
|
|
690
|
+
private collectLoopPruning;
|
|
691
|
+
/**
|
|
692
|
+
* Flush storage with optional pending deletions so pruning
|
|
693
|
+
* happens alongside the state write.
|
|
654
694
|
*/
|
|
655
|
-
private
|
|
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.
|
|
@@ -895,4 +955,4 @@ declare const Loop: {
|
|
|
895
955
|
|
|
896
956
|
declare function runWorkflow<TInput, TOutput>(workflowId: string, workflowFn: WorkflowFunction<TInput, TOutput>, input: TInput, driver: EngineDriver, options?: RunWorkflowOptions): WorkflowHandle<TOutput>;
|
|
897
957
|
|
|
898
|
-
export { type BranchConfig, type BranchOutput, type BranchStatus, type BranchStatusType, CancelledError, CriticalError,
|
|
958
|
+
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, 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,
|
|
@@ -43,13 +42,11 @@ import {
|
|
|
43
42
|
resolveName,
|
|
44
43
|
runWorkflow,
|
|
45
44
|
setEntry
|
|
46
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-MMWB37UG.js";
|
|
47
46
|
export {
|
|
48
47
|
CancelledError,
|
|
49
48
|
CriticalError,
|
|
50
|
-
|
|
51
|
-
DEFAULT_LOOP_HISTORY_EVERY,
|
|
52
|
-
DEFAULT_LOOP_HISTORY_KEEP,
|
|
49
|
+
DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL,
|
|
53
50
|
DEFAULT_MAX_RETRIES,
|
|
54
51
|
DEFAULT_RETRY_BACKOFF_BASE,
|
|
55
52
|
DEFAULT_RETRY_BACKOFF_MAX,
|
|
@@ -74,6 +71,7 @@ export {
|
|
|
74
71
|
createStorage,
|
|
75
72
|
deleteEntriesWithPrefix,
|
|
76
73
|
emptyLocation,
|
|
74
|
+
extractErrorInfo,
|
|
77
75
|
flush,
|
|
78
76
|
generateId,
|
|
79
77
|
getEntry,
|
package/dist/tsup/testing.cjs
CHANGED
|
@@ -46,8 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
var _chunkKQO2TD7Tcjs = require('./chunk-KQO2TD7T.cjs');
|
|
49
|
+
var _chunkSHICGAKCcjs = require('./chunk-SHICGAKC.cjs');
|
|
51
50
|
|
|
52
51
|
// src/testing.ts
|
|
53
52
|
var InMemoryWorkflowMessageDriver = class {
|
|
@@ -88,14 +87,16 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
89
|
async completeMessage(messageId) {
|
|
91
|
-
const index = this.#messages.findIndex(
|
|
90
|
+
const index = this.#messages.findIndex(
|
|
91
|
+
(message) => message.id === messageId
|
|
92
|
+
);
|
|
92
93
|
if (index !== -1) {
|
|
93
94
|
this.#messages.splice(index, 1);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
async waitForMessages(messageNames, abortSignal) {
|
|
97
98
|
if (abortSignal.aborted) {
|
|
98
|
-
throw new (0,
|
|
99
|
+
throw new (0, _chunkSHICGAKCcjs.EvictedError)();
|
|
99
100
|
}
|
|
100
101
|
const nameSet = messageNames.length > 0 ? new Set(messageNames) : void 0;
|
|
101
102
|
if (this.#messages.some(
|
|
@@ -116,10 +117,12 @@ var InMemoryWorkflowMessageDriver = class {
|
|
|
116
117
|
},
|
|
117
118
|
abortSignal,
|
|
118
119
|
onAbort: () => {
|
|
119
|
-
waiter.reject(new (0,
|
|
120
|
+
waiter.reject(new (0, _chunkSHICGAKCcjs.EvictedError)());
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
|
-
abortSignal.addEventListener("abort", waiter.onAbort, {
|
|
123
|
+
abortSignal.addEventListener("abort", waiter.onAbort, {
|
|
124
|
+
once: true
|
|
125
|
+
});
|
|
123
126
|
this.#waiters.add(waiter);
|
|
124
127
|
});
|
|
125
128
|
}
|
|
@@ -154,48 +157,56 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
154
157
|
__init4() {this.workerPollInterval = 100}
|
|
155
158
|
__init5() {this.messageDriver = this.#inMemoryMessageDriver}
|
|
156
159
|
async get(key) {
|
|
157
|
-
await
|
|
158
|
-
const entry = this.kv.get(
|
|
160
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
161
|
+
const entry = this.kv.get(_chunkSHICGAKCcjs.keyToHex.call(void 0, key));
|
|
159
162
|
return _nullishCoalesce((entry == null ? void 0 : entry.value), () => ( null));
|
|
160
163
|
}
|
|
161
164
|
async set(key, value) {
|
|
162
|
-
await
|
|
163
|
-
this.kv.set(
|
|
165
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
166
|
+
this.kv.set(_chunkSHICGAKCcjs.keyToHex.call(void 0, key), { key, value });
|
|
164
167
|
}
|
|
165
168
|
async delete(key) {
|
|
166
|
-
await
|
|
167
|
-
this.kv.delete(
|
|
169
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
170
|
+
this.kv.delete(_chunkSHICGAKCcjs.keyToHex.call(void 0, key));
|
|
168
171
|
}
|
|
169
172
|
async deletePrefix(prefix) {
|
|
170
|
-
await
|
|
173
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
174
|
+
for (const [hexKey, entry] of this.kv) {
|
|
175
|
+
if (_chunkSHICGAKCcjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
176
|
+
this.kv.delete(hexKey);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async deleteRange(start, end) {
|
|
181
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
171
182
|
for (const [hexKey, entry] of this.kv) {
|
|
172
|
-
if (
|
|
183
|
+
if (_chunkSHICGAKCcjs.compareKeys.call(void 0, entry.key, start) >= 0 && _chunkSHICGAKCcjs.compareKeys.call(void 0, entry.key, end) < 0) {
|
|
173
184
|
this.kv.delete(hexKey);
|
|
174
185
|
}
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
async list(prefix) {
|
|
178
|
-
await
|
|
189
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
179
190
|
const results = [];
|
|
180
191
|
for (const entry of this.kv.values()) {
|
|
181
|
-
if (
|
|
192
|
+
if (_chunkSHICGAKCcjs.keyStartsWith.call(void 0, entry.key, prefix)) {
|
|
182
193
|
results.push({ key: entry.key, value: entry.value });
|
|
183
194
|
}
|
|
184
195
|
}
|
|
185
|
-
return results.sort((a, b) =>
|
|
196
|
+
return results.sort((a, b) => _chunkSHICGAKCcjs.compareKeys.call(void 0, a.key, b.key));
|
|
186
197
|
}
|
|
187
198
|
async batch(writes) {
|
|
188
|
-
await
|
|
199
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
189
200
|
for (const { key, value } of writes) {
|
|
190
|
-
this.kv.set(
|
|
201
|
+
this.kv.set(_chunkSHICGAKCcjs.keyToHex.call(void 0, key), { key, value });
|
|
191
202
|
}
|
|
192
203
|
}
|
|
193
204
|
async setAlarm(workflowId, wakeAt) {
|
|
194
|
-
await
|
|
205
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
195
206
|
this.alarms.set(workflowId, wakeAt);
|
|
196
207
|
}
|
|
197
208
|
async clearAlarm(workflowId) {
|
|
198
|
-
await
|
|
209
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, this.latency);
|
|
199
210
|
this.alarms.delete(workflowId);
|
|
200
211
|
}
|
|
201
212
|
async waitForMessages(messageNames, abortSignal) {
|
|
@@ -206,7 +217,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
206
217
|
}
|
|
207
218
|
while (true) {
|
|
208
219
|
if (abortSignal.aborted) {
|
|
209
|
-
throw new (0,
|
|
220
|
+
throw new (0, _chunkSHICGAKCcjs.EvictedError)();
|
|
210
221
|
}
|
|
211
222
|
const messages = await this.messageDriver.receiveMessages({
|
|
212
223
|
names: messageNames.length > 0 ? messageNames : void 0,
|
|
@@ -216,7 +227,7 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
216
227
|
if (messages.length > 0) {
|
|
217
228
|
return;
|
|
218
229
|
}
|
|
219
|
-
await
|
|
230
|
+
await _chunkSHICGAKCcjs.sleep.call(void 0, Math.max(1, this.latency));
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
233
|
/**
|
|
@@ -311,6 +322,5 @@ var InMemoryDriver = (_class = class {constructor() { _class.prototype.__init.ca
|
|
|
311
322
|
|
|
312
323
|
|
|
313
324
|
|
|
314
|
-
|
|
315
|
-
exports.CancelledError = _chunkKQO2TD7Tcjs.CancelledError; exports.CriticalError = _chunkKQO2TD7Tcjs.CriticalError; exports.DEFAULT_LOOP_COMMIT_INTERVAL = _chunkKQO2TD7Tcjs.DEFAULT_LOOP_COMMIT_INTERVAL; exports.DEFAULT_LOOP_HISTORY_EVERY = _chunkKQO2TD7Tcjs.DEFAULT_LOOP_HISTORY_EVERY; exports.DEFAULT_LOOP_HISTORY_KEEP = _chunkKQO2TD7Tcjs.DEFAULT_LOOP_HISTORY_KEEP; exports.DEFAULT_MAX_RETRIES = _chunkKQO2TD7Tcjs.DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = _chunkKQO2TD7Tcjs.DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = _chunkKQO2TD7Tcjs.DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_STEP_TIMEOUT = _chunkKQO2TD7Tcjs.DEFAULT_STEP_TIMEOUT; exports.EntryInProgressError = _chunkKQO2TD7Tcjs.EntryInProgressError; exports.EvictedError = _chunkKQO2TD7Tcjs.EvictedError; exports.HistoryDivergedError = _chunkKQO2TD7Tcjs.HistoryDivergedError; exports.InMemoryDriver = InMemoryDriver; exports.JoinError = _chunkKQO2TD7Tcjs.JoinError; exports.Loop = _chunkKQO2TD7Tcjs.Loop; exports.MessageWaitError = _chunkKQO2TD7Tcjs.MessageWaitError; exports.RaceError = _chunkKQO2TD7Tcjs.RaceError; exports.RollbackCheckpointError = _chunkKQO2TD7Tcjs.RollbackCheckpointError; exports.RollbackError = _chunkKQO2TD7Tcjs.RollbackError; exports.SleepError = _chunkKQO2TD7Tcjs.SleepError; exports.StepExhaustedError = _chunkKQO2TD7Tcjs.StepExhaustedError; exports.StepFailedError = _chunkKQO2TD7Tcjs.StepFailedError; exports.WorkflowContextImpl = _chunkKQO2TD7Tcjs.WorkflowContextImpl; exports.appendLoopIteration = _chunkKQO2TD7Tcjs.appendLoopIteration; exports.appendName = _chunkKQO2TD7Tcjs.appendName; exports.createEntry = _chunkKQO2TD7Tcjs.createEntry; exports.createHistorySnapshot = _chunkKQO2TD7Tcjs.createHistorySnapshot; exports.createStorage = _chunkKQO2TD7Tcjs.createStorage; exports.deleteEntriesWithPrefix = _chunkKQO2TD7Tcjs.deleteEntriesWithPrefix; exports.emptyLocation = _chunkKQO2TD7Tcjs.emptyLocation; exports.flush = _chunkKQO2TD7Tcjs.flush; exports.generateId = _chunkKQO2TD7Tcjs.generateId; exports.getEntry = _chunkKQO2TD7Tcjs.getEntry; exports.getOrCreateMetadata = _chunkKQO2TD7Tcjs.getOrCreateMetadata; exports.isLocationPrefix = _chunkKQO2TD7Tcjs.isLocationPrefix; exports.isLoopIterationMarker = _chunkKQO2TD7Tcjs.isLoopIterationMarker; exports.loadMetadata = _chunkKQO2TD7Tcjs.loadMetadata; exports.loadStorage = _chunkKQO2TD7Tcjs.loadStorage; exports.locationToKey = _chunkKQO2TD7Tcjs.locationToKey; exports.locationsEqual = _chunkKQO2TD7Tcjs.locationsEqual; exports.parentLocation = _chunkKQO2TD7Tcjs.parentLocation; exports.registerName = _chunkKQO2TD7Tcjs.registerName; exports.resolveName = _chunkKQO2TD7Tcjs.resolveName; exports.runWorkflow = _chunkKQO2TD7Tcjs.runWorkflow; exports.setEntry = _chunkKQO2TD7Tcjs.setEntry;
|
|
325
|
+
exports.CancelledError = _chunkSHICGAKCcjs.CancelledError; exports.CriticalError = _chunkSHICGAKCcjs.CriticalError; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = _chunkSHICGAKCcjs.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_MAX_RETRIES = _chunkSHICGAKCcjs.DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = _chunkSHICGAKCcjs.DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = _chunkSHICGAKCcjs.DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_STEP_TIMEOUT = _chunkSHICGAKCcjs.DEFAULT_STEP_TIMEOUT; exports.EntryInProgressError = _chunkSHICGAKCcjs.EntryInProgressError; exports.EvictedError = _chunkSHICGAKCcjs.EvictedError; exports.HistoryDivergedError = _chunkSHICGAKCcjs.HistoryDivergedError; exports.InMemoryDriver = InMemoryDriver; exports.JoinError = _chunkSHICGAKCcjs.JoinError; exports.Loop = _chunkSHICGAKCcjs.Loop; exports.MessageWaitError = _chunkSHICGAKCcjs.MessageWaitError; exports.RaceError = _chunkSHICGAKCcjs.RaceError; exports.RollbackCheckpointError = _chunkSHICGAKCcjs.RollbackCheckpointError; exports.RollbackError = _chunkSHICGAKCcjs.RollbackError; exports.SleepError = _chunkSHICGAKCcjs.SleepError; exports.StepExhaustedError = _chunkSHICGAKCcjs.StepExhaustedError; exports.StepFailedError = _chunkSHICGAKCcjs.StepFailedError; exports.WorkflowContextImpl = _chunkSHICGAKCcjs.WorkflowContextImpl; exports.appendLoopIteration = _chunkSHICGAKCcjs.appendLoopIteration; exports.appendName = _chunkSHICGAKCcjs.appendName; exports.createEntry = _chunkSHICGAKCcjs.createEntry; exports.createHistorySnapshot = _chunkSHICGAKCcjs.createHistorySnapshot; exports.createStorage = _chunkSHICGAKCcjs.createStorage; exports.deleteEntriesWithPrefix = _chunkSHICGAKCcjs.deleteEntriesWithPrefix; exports.emptyLocation = _chunkSHICGAKCcjs.emptyLocation; exports.extractErrorInfo = _chunkSHICGAKCcjs.extractErrorInfo; exports.flush = _chunkSHICGAKCcjs.flush; exports.generateId = _chunkSHICGAKCcjs.generateId; exports.getEntry = _chunkSHICGAKCcjs.getEntry; exports.getOrCreateMetadata = _chunkSHICGAKCcjs.getOrCreateMetadata; exports.isLocationPrefix = _chunkSHICGAKCcjs.isLocationPrefix; exports.isLoopIterationMarker = _chunkSHICGAKCcjs.isLoopIterationMarker; exports.loadMetadata = _chunkSHICGAKCcjs.loadMetadata; exports.loadStorage = _chunkSHICGAKCcjs.loadStorage; exports.locationToKey = _chunkSHICGAKCcjs.locationToKey; exports.locationsEqual = _chunkSHICGAKCcjs.locationsEqual; exports.parentLocation = _chunkSHICGAKCcjs.parentLocation; exports.registerName = _chunkSHICGAKCcjs.registerName; exports.resolveName = _chunkSHICGAKCcjs.resolveName; exports.runWorkflow = _chunkSHICGAKCcjs.runWorkflow; exports.setEntry = _chunkSHICGAKCcjs.setEntry;
|
|
316
326
|
//# sourceMappingURL=testing.cjs.map
|