awaitly 2.0.0 → 3.0.0
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/di-Biw_plBn.d.cts +15 -0
- package/dist/di-DxyH2N3i.d.ts +15 -0
- package/dist/durable.cjs +4670 -0
- package/dist/durable.cjs.map +1 -0
- package/dist/durable.d.cts +9 -0
- package/dist/durable.d.ts +9 -0
- package/dist/durable.js +4610 -0
- package/dist/durable.js.map +1 -0
- package/dist/{di-BbFFfO8y.d.ts → duration-BjVn3QpB.d.cts} +1 -15
- package/dist/{di-BDlT7InM.d.cts → duration-BjVn3QpB.d.ts} +1 -15
- package/dist/engine.cjs +4501 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +113 -0
- package/dist/engine.d.ts +113 -0
- package/dist/engine.js +4474 -0
- package/dist/engine.js.map +1 -0
- package/dist/{errors-DtXvrCiO.d.cts → errors-sDSeaZBO.d.cts} +1 -1
- package/dist/{errors-DtXvrCiO.d.ts → errors-sDSeaZBO.d.ts} +1 -1
- package/dist/guards-CwQZro1F.d.ts +72 -0
- package/dist/guards-DhhOJZda.d.cts +72 -0
- package/dist/hitl-BnnnLzh2.d.cts +468 -0
- package/dist/hitl-pYfkQMv_.d.ts +468 -0
- package/dist/hitl.cjs +646 -0
- package/dist/hitl.cjs.map +1 -0
- package/dist/hitl.d.cts +440 -0
- package/dist/hitl.d.ts +440 -0
- package/dist/hitl.js +605 -0
- package/dist/hitl.js.map +1 -0
- package/dist/index-Bew12SZ8.d.ts +417 -0
- package/dist/index-Bwt-iz50.d.cts +417 -0
- package/dist/{types-B8NfNRGX.d.ts → index-Cv4K_3sZ.d.ts} +2 -1162
- package/dist/{types-BZ2f4MRR.d.cts → index-ICmfQi08.d.cts} +2 -1162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1527
- package/dist/index.d.ts +11 -1527
- package/dist/persistence.cjs +552 -0
- package/dist/persistence.cjs.map +1 -0
- package/dist/persistence.d.cts +254 -0
- package/dist/persistence.d.ts +254 -0
- package/dist/persistence.js +499 -0
- package/dist/persistence.js.map +1 -0
- package/dist/reliability.cjs +1651 -0
- package/dist/reliability.cjs.map +1 -0
- package/dist/reliability.d.cts +1442 -0
- package/dist/reliability.d.ts +1442 -0
- package/dist/reliability.js +1589 -0
- package/dist/reliability.js.map +1 -0
- package/dist/result.d.cts +1 -1
- package/dist/result.d.ts +1 -1
- package/dist/run.cjs +2283 -0
- package/dist/run.cjs.map +1 -0
- package/dist/run.d.cts +90 -0
- package/dist/run.d.ts +90 -0
- package/dist/run.js +2247 -0
- package/dist/run.js.map +1 -0
- package/dist/saga.cjs +3699 -0
- package/dist/saga.cjs.map +1 -0
- package/dist/saga.d.cts +162 -0
- package/dist/saga.d.ts +162 -0
- package/dist/saga.js +3670 -0
- package/dist/saga.js.map +1 -0
- package/dist/store-contract-BI98VYmX.d.ts +66 -0
- package/dist/store-contract-C2HyR_o6.d.cts +66 -0
- package/dist/streaming.cjs +895 -0
- package/dist/streaming.cjs.map +1 -0
- package/dist/streaming.d.cts +594 -0
- package/dist/streaming.d.ts +594 -0
- package/dist/streaming.js +832 -0
- package/dist/streaming.js.map +1 -0
- package/dist/testing.d.cts +4 -2
- package/dist/testing.d.ts +4 -2
- package/dist/types-BDTxgKKc.d.ts +845 -0
- package/dist/types-C9Y71dua.d.cts +845 -0
- package/dist/types-d8q8iQlk.d.cts +323 -0
- package/dist/types-sObbY4mX.d.ts +323 -0
- package/dist/webhook.cjs +461 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +497 -0
- package/dist/webhook.d.ts +497 -0
- package/dist/webhook.js +422 -0
- package/dist/webhook.js.map +1 -0
- package/dist/workflow.cjs +2 -2614
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +12 -3023
- package/dist/workflow.d.ts +12 -3023
- package/dist/workflow.js +2 -2535
- package/dist/workflow.js.map +1 -1
- package/package.json +46 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { R as ResumeState, j as ResumeStateEntry } from './types-C9Y71dua.cjs';
|
|
2
|
+
export { J as JSONValue, M as MemoryCacheOptions, m as SerializedCause, n as SnapshotDecodeError, o as SnapshotFormatError, p as SnapshotMismatchError, S as SnapshotStore, q as SnapshotWarning, h as StepResult, b as WorkflowSnapshot, u as assertValidSnapshot, z as createMemoryCache, B as deserializeCauseNew, v as isWorkflowSnapshot, w as looksLikeWorkflowSnapshot, x as mergeSnapshots, D as serializeError, F as serializeThrown, y as validateSnapshot } from './types-C9Y71dua.cjs';
|
|
3
|
+
export { c as isResumeState } from './guards-DhhOJZda.cjs';
|
|
4
|
+
export { P as PersistedWorkflowState, S as SerializedResumeState, a as StoreLoadResult, b as StoreSaveInput, d as deserializeResumeState, i as isSerializedResumeState, s as serializeResumeState, t as toResumeState } from './store-contract-C2HyR_o6.cjs';
|
|
5
|
+
export { W as WorkflowLock } from './index-Bwt-iz50.cjs';
|
|
6
|
+
import { R as Result } from './index-ICmfQi08.cjs';
|
|
7
|
+
import './types-d8q8iQlk.cjs';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import './errors-sDSeaZBO.cjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Workflow Versioning and Migration
|
|
13
|
+
*
|
|
14
|
+
* Handle schema changes when resuming workflows that were persisted
|
|
15
|
+
* with older step shapes.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { createVersionedWorkflow } from 'awaitly';
|
|
20
|
+
*
|
|
21
|
+
* const workflow = createVersionedWorkflow(
|
|
22
|
+
* { fetchUser, chargeCard },
|
|
23
|
+
* {
|
|
24
|
+
* version: 2,
|
|
25
|
+
* migrations: {
|
|
26
|
+
* 1: (state) => migrateV1ToV2(state),
|
|
27
|
+
* },
|
|
28
|
+
* resumeState: loadState(runId),
|
|
29
|
+
* }
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Version number type.
|
|
36
|
+
*/
|
|
37
|
+
type Version = number;
|
|
38
|
+
/**
|
|
39
|
+
* Migration function that transforms state from one version to the next.
|
|
40
|
+
*/
|
|
41
|
+
type MigrationFn = (state: ResumeState) => ResumeState | Promise<ResumeState>;
|
|
42
|
+
/**
|
|
43
|
+
* Map of migrations keyed by the source version.
|
|
44
|
+
* Migration at key N transforms state from version N to version N+1.
|
|
45
|
+
*/
|
|
46
|
+
type Migrations = Record<Version, MigrationFn>;
|
|
47
|
+
/**
|
|
48
|
+
* Versioned state includes the version number.
|
|
49
|
+
*/
|
|
50
|
+
interface VersionedState {
|
|
51
|
+
version: Version;
|
|
52
|
+
state: ResumeState;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for versioned workflow.
|
|
56
|
+
*/
|
|
57
|
+
interface VersionedWorkflowConfig {
|
|
58
|
+
/**
|
|
59
|
+
* Current workflow version.
|
|
60
|
+
*/
|
|
61
|
+
version: Version;
|
|
62
|
+
/**
|
|
63
|
+
* Migrations for upgrading old states.
|
|
64
|
+
* Key is the source version, value transforms to next version.
|
|
65
|
+
*/
|
|
66
|
+
migrations?: Migrations;
|
|
67
|
+
/**
|
|
68
|
+
* Strict mode - fail if state version is higher than current.
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
strictVersioning?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error when version migration fails.
|
|
75
|
+
*/
|
|
76
|
+
interface MigrationError {
|
|
77
|
+
type: "MIGRATION_ERROR";
|
|
78
|
+
fromVersion: Version;
|
|
79
|
+
toVersion: Version;
|
|
80
|
+
cause: unknown;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error when state version is incompatible.
|
|
84
|
+
*/
|
|
85
|
+
interface VersionIncompatibleError {
|
|
86
|
+
type: "VERSION_INCOMPATIBLE";
|
|
87
|
+
stateVersion: Version;
|
|
88
|
+
currentVersion: Version;
|
|
89
|
+
reason: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Type guard for MigrationError.
|
|
93
|
+
*/
|
|
94
|
+
declare function isMigrationError(error: unknown): error is MigrationError;
|
|
95
|
+
/**
|
|
96
|
+
* Type guard for VersionIncompatibleError.
|
|
97
|
+
*/
|
|
98
|
+
declare function isVersionIncompatibleError(error: unknown): error is VersionIncompatibleError;
|
|
99
|
+
/**
|
|
100
|
+
* Create a versioned resume state loader.
|
|
101
|
+
*
|
|
102
|
+
* This wraps a state loader to automatically apply migrations
|
|
103
|
+
* when loading older state versions.
|
|
104
|
+
*
|
|
105
|
+
* @param config - Versioning configuration
|
|
106
|
+
* @returns A function that loads and migrates state
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const loadVersionedState = createVersionedStateLoader({
|
|
111
|
+
* version: 3,
|
|
112
|
+
* migrations: {
|
|
113
|
+
* 1: migrateV1ToV2,
|
|
114
|
+
* 2: migrateV2ToV3,
|
|
115
|
+
* },
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // In workflow
|
|
119
|
+
* const workflow = createWorkflow(deps, {
|
|
120
|
+
* resumeState: () => loadVersionedState(savedState),
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function createVersionedStateLoader(config: VersionedWorkflowConfig): (versionedState: VersionedState | null | undefined) => Promise<Result<ResumeState | undefined, MigrationError | VersionIncompatibleError>>;
|
|
125
|
+
/**
|
|
126
|
+
* Create versioned state from current resume state.
|
|
127
|
+
*
|
|
128
|
+
* Use this when saving state to storage.
|
|
129
|
+
*
|
|
130
|
+
* @param state - The current resume state
|
|
131
|
+
* @param version - The current workflow version
|
|
132
|
+
* @returns A versioned state object
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const collector = createResumeStateCollector();
|
|
137
|
+
* // ... run workflow ...
|
|
138
|
+
*
|
|
139
|
+
* const versionedState = createVersionedState(collector.getResumeState(), 2);
|
|
140
|
+
* await db.saveWorkflowState(workflowId, versionedState);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function createVersionedState(state: ResumeState, version: Version): VersionedState;
|
|
144
|
+
/**
|
|
145
|
+
* Parse versioned state from JSON.
|
|
146
|
+
*
|
|
147
|
+
* Handles the serialization/deserialization of ResumeState with Map.
|
|
148
|
+
*
|
|
149
|
+
* @param json - The JSON string or parsed object
|
|
150
|
+
* @returns The versioned state or null if invalid
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const json = await db.loadWorkflowState(workflowId);
|
|
155
|
+
* const versionedState = parseVersionedState(json);
|
|
156
|
+
* if (versionedState) {
|
|
157
|
+
* const loader = createVersionedStateLoader(config);
|
|
158
|
+
* const state = await loader(versionedState);
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
interface SerializedVersionedState {
|
|
163
|
+
version: number;
|
|
164
|
+
state: {
|
|
165
|
+
steps: Array<[string, ResumeStateEntry]>;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
declare function parseVersionedState(json: string | SerializedVersionedState | null | undefined): VersionedState | null;
|
|
169
|
+
/**
|
|
170
|
+
* Serialize versioned state to JSON.
|
|
171
|
+
*
|
|
172
|
+
* Converts the Map to an array for JSON serialization.
|
|
173
|
+
*
|
|
174
|
+
* @param state - The versioned state
|
|
175
|
+
* @returns JSON string
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const json = stringifyVersionedState(versionedState);
|
|
180
|
+
* await db.saveWorkflowState(workflowId, json);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function stringifyVersionedState(state: VersionedState): string;
|
|
184
|
+
/**
|
|
185
|
+
* Create a migration that renames step keys.
|
|
186
|
+
*
|
|
187
|
+
* @param renames - Map of old key to new key
|
|
188
|
+
* @returns A migration function
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const migrations = {
|
|
193
|
+
* 1: createKeyRenameMigration({
|
|
194
|
+
* 'user:fetch': 'user:load',
|
|
195
|
+
* 'order:create': 'order:submit',
|
|
196
|
+
* }),
|
|
197
|
+
* };
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function createKeyRenameMigration(renames: Record<string, string>): MigrationFn;
|
|
201
|
+
/**
|
|
202
|
+
* Create a migration that removes specific step keys.
|
|
203
|
+
*
|
|
204
|
+
* @param keysToRemove - Array of keys to remove
|
|
205
|
+
* @returns A migration function
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const migrations = {
|
|
210
|
+
* 1: createKeyRemoveMigration(['deprecated:step', 'old:cache']),
|
|
211
|
+
* };
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function createKeyRemoveMigration(keysToRemove: string[]): MigrationFn;
|
|
215
|
+
/**
|
|
216
|
+
* Create a migration that transforms step values.
|
|
217
|
+
*
|
|
218
|
+
* @param transforms - Map of key to transform function
|
|
219
|
+
* @returns A migration function
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const migrations = {
|
|
224
|
+
* 1: createValueTransformMigration({
|
|
225
|
+
* 'user:fetch': (entry) => ({
|
|
226
|
+
* ...entry,
|
|
227
|
+
* result: entry.result.ok
|
|
228
|
+
* ? ok({ ...entry.result.value, newField: 'default' })
|
|
229
|
+
* : entry.result,
|
|
230
|
+
* }),
|
|
231
|
+
* }),
|
|
232
|
+
* };
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function createValueTransformMigration(transforms: Record<string, (entry: ResumeStateEntry) => ResumeStateEntry>): MigrationFn;
|
|
236
|
+
/**
|
|
237
|
+
* Compose multiple migrations into a single migration.
|
|
238
|
+
*
|
|
239
|
+
* @param migrations - Array of migration functions
|
|
240
|
+
* @returns A single migration function that applies all migrations in order
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const migrations = {
|
|
245
|
+
* 1: composeMigrations([
|
|
246
|
+
* createKeyRenameMigration({ 'old': 'new' }),
|
|
247
|
+
* createKeyRemoveMigration(['deprecated']),
|
|
248
|
+
* ]),
|
|
249
|
+
* };
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function composeMigrations(migrations: MigrationFn[]): MigrationFn;
|
|
253
|
+
|
|
254
|
+
export { type MigrationError, type MigrationFn, type Migrations, ResumeState, type Version, type VersionIncompatibleError, type VersionedState, type VersionedWorkflowConfig, composeMigrations, createKeyRemoveMigration, createKeyRenameMigration, createValueTransformMigration, createVersionedState, createVersionedStateLoader, isMigrationError, isVersionIncompatibleError, parseVersionedState, stringifyVersionedState };
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { R as ResumeState, j as ResumeStateEntry } from './types-BDTxgKKc.js';
|
|
2
|
+
export { J as JSONValue, M as MemoryCacheOptions, m as SerializedCause, n as SnapshotDecodeError, o as SnapshotFormatError, p as SnapshotMismatchError, S as SnapshotStore, q as SnapshotWarning, h as StepResult, b as WorkflowSnapshot, u as assertValidSnapshot, z as createMemoryCache, B as deserializeCauseNew, v as isWorkflowSnapshot, w as looksLikeWorkflowSnapshot, x as mergeSnapshots, D as serializeError, F as serializeThrown, y as validateSnapshot } from './types-BDTxgKKc.js';
|
|
3
|
+
export { c as isResumeState } from './guards-CwQZro1F.js';
|
|
4
|
+
export { P as PersistedWorkflowState, S as SerializedResumeState, a as StoreLoadResult, b as StoreSaveInput, d as deserializeResumeState, i as isSerializedResumeState, s as serializeResumeState, t as toResumeState } from './store-contract-BI98VYmX.js';
|
|
5
|
+
export { W as WorkflowLock } from './index-Bew12SZ8.js';
|
|
6
|
+
import { R as Result } from './index-Cv4K_3sZ.js';
|
|
7
|
+
import './types-sObbY4mX.js';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import './errors-sDSeaZBO.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Workflow Versioning and Migration
|
|
13
|
+
*
|
|
14
|
+
* Handle schema changes when resuming workflows that were persisted
|
|
15
|
+
* with older step shapes.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { createVersionedWorkflow } from 'awaitly';
|
|
20
|
+
*
|
|
21
|
+
* const workflow = createVersionedWorkflow(
|
|
22
|
+
* { fetchUser, chargeCard },
|
|
23
|
+
* {
|
|
24
|
+
* version: 2,
|
|
25
|
+
* migrations: {
|
|
26
|
+
* 1: (state) => migrateV1ToV2(state),
|
|
27
|
+
* },
|
|
28
|
+
* resumeState: loadState(runId),
|
|
29
|
+
* }
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Version number type.
|
|
36
|
+
*/
|
|
37
|
+
type Version = number;
|
|
38
|
+
/**
|
|
39
|
+
* Migration function that transforms state from one version to the next.
|
|
40
|
+
*/
|
|
41
|
+
type MigrationFn = (state: ResumeState) => ResumeState | Promise<ResumeState>;
|
|
42
|
+
/**
|
|
43
|
+
* Map of migrations keyed by the source version.
|
|
44
|
+
* Migration at key N transforms state from version N to version N+1.
|
|
45
|
+
*/
|
|
46
|
+
type Migrations = Record<Version, MigrationFn>;
|
|
47
|
+
/**
|
|
48
|
+
* Versioned state includes the version number.
|
|
49
|
+
*/
|
|
50
|
+
interface VersionedState {
|
|
51
|
+
version: Version;
|
|
52
|
+
state: ResumeState;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for versioned workflow.
|
|
56
|
+
*/
|
|
57
|
+
interface VersionedWorkflowConfig {
|
|
58
|
+
/**
|
|
59
|
+
* Current workflow version.
|
|
60
|
+
*/
|
|
61
|
+
version: Version;
|
|
62
|
+
/**
|
|
63
|
+
* Migrations for upgrading old states.
|
|
64
|
+
* Key is the source version, value transforms to next version.
|
|
65
|
+
*/
|
|
66
|
+
migrations?: Migrations;
|
|
67
|
+
/**
|
|
68
|
+
* Strict mode - fail if state version is higher than current.
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
strictVersioning?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error when version migration fails.
|
|
75
|
+
*/
|
|
76
|
+
interface MigrationError {
|
|
77
|
+
type: "MIGRATION_ERROR";
|
|
78
|
+
fromVersion: Version;
|
|
79
|
+
toVersion: Version;
|
|
80
|
+
cause: unknown;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error when state version is incompatible.
|
|
84
|
+
*/
|
|
85
|
+
interface VersionIncompatibleError {
|
|
86
|
+
type: "VERSION_INCOMPATIBLE";
|
|
87
|
+
stateVersion: Version;
|
|
88
|
+
currentVersion: Version;
|
|
89
|
+
reason: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Type guard for MigrationError.
|
|
93
|
+
*/
|
|
94
|
+
declare function isMigrationError(error: unknown): error is MigrationError;
|
|
95
|
+
/**
|
|
96
|
+
* Type guard for VersionIncompatibleError.
|
|
97
|
+
*/
|
|
98
|
+
declare function isVersionIncompatibleError(error: unknown): error is VersionIncompatibleError;
|
|
99
|
+
/**
|
|
100
|
+
* Create a versioned resume state loader.
|
|
101
|
+
*
|
|
102
|
+
* This wraps a state loader to automatically apply migrations
|
|
103
|
+
* when loading older state versions.
|
|
104
|
+
*
|
|
105
|
+
* @param config - Versioning configuration
|
|
106
|
+
* @returns A function that loads and migrates state
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const loadVersionedState = createVersionedStateLoader({
|
|
111
|
+
* version: 3,
|
|
112
|
+
* migrations: {
|
|
113
|
+
* 1: migrateV1ToV2,
|
|
114
|
+
* 2: migrateV2ToV3,
|
|
115
|
+
* },
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // In workflow
|
|
119
|
+
* const workflow = createWorkflow(deps, {
|
|
120
|
+
* resumeState: () => loadVersionedState(savedState),
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function createVersionedStateLoader(config: VersionedWorkflowConfig): (versionedState: VersionedState | null | undefined) => Promise<Result<ResumeState | undefined, MigrationError | VersionIncompatibleError>>;
|
|
125
|
+
/**
|
|
126
|
+
* Create versioned state from current resume state.
|
|
127
|
+
*
|
|
128
|
+
* Use this when saving state to storage.
|
|
129
|
+
*
|
|
130
|
+
* @param state - The current resume state
|
|
131
|
+
* @param version - The current workflow version
|
|
132
|
+
* @returns A versioned state object
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const collector = createResumeStateCollector();
|
|
137
|
+
* // ... run workflow ...
|
|
138
|
+
*
|
|
139
|
+
* const versionedState = createVersionedState(collector.getResumeState(), 2);
|
|
140
|
+
* await db.saveWorkflowState(workflowId, versionedState);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function createVersionedState(state: ResumeState, version: Version): VersionedState;
|
|
144
|
+
/**
|
|
145
|
+
* Parse versioned state from JSON.
|
|
146
|
+
*
|
|
147
|
+
* Handles the serialization/deserialization of ResumeState with Map.
|
|
148
|
+
*
|
|
149
|
+
* @param json - The JSON string or parsed object
|
|
150
|
+
* @returns The versioned state or null if invalid
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const json = await db.loadWorkflowState(workflowId);
|
|
155
|
+
* const versionedState = parseVersionedState(json);
|
|
156
|
+
* if (versionedState) {
|
|
157
|
+
* const loader = createVersionedStateLoader(config);
|
|
158
|
+
* const state = await loader(versionedState);
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
interface SerializedVersionedState {
|
|
163
|
+
version: number;
|
|
164
|
+
state: {
|
|
165
|
+
steps: Array<[string, ResumeStateEntry]>;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
declare function parseVersionedState(json: string | SerializedVersionedState | null | undefined): VersionedState | null;
|
|
169
|
+
/**
|
|
170
|
+
* Serialize versioned state to JSON.
|
|
171
|
+
*
|
|
172
|
+
* Converts the Map to an array for JSON serialization.
|
|
173
|
+
*
|
|
174
|
+
* @param state - The versioned state
|
|
175
|
+
* @returns JSON string
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const json = stringifyVersionedState(versionedState);
|
|
180
|
+
* await db.saveWorkflowState(workflowId, json);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function stringifyVersionedState(state: VersionedState): string;
|
|
184
|
+
/**
|
|
185
|
+
* Create a migration that renames step keys.
|
|
186
|
+
*
|
|
187
|
+
* @param renames - Map of old key to new key
|
|
188
|
+
* @returns A migration function
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const migrations = {
|
|
193
|
+
* 1: createKeyRenameMigration({
|
|
194
|
+
* 'user:fetch': 'user:load',
|
|
195
|
+
* 'order:create': 'order:submit',
|
|
196
|
+
* }),
|
|
197
|
+
* };
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function createKeyRenameMigration(renames: Record<string, string>): MigrationFn;
|
|
201
|
+
/**
|
|
202
|
+
* Create a migration that removes specific step keys.
|
|
203
|
+
*
|
|
204
|
+
* @param keysToRemove - Array of keys to remove
|
|
205
|
+
* @returns A migration function
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const migrations = {
|
|
210
|
+
* 1: createKeyRemoveMigration(['deprecated:step', 'old:cache']),
|
|
211
|
+
* };
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function createKeyRemoveMigration(keysToRemove: string[]): MigrationFn;
|
|
215
|
+
/**
|
|
216
|
+
* Create a migration that transforms step values.
|
|
217
|
+
*
|
|
218
|
+
* @param transforms - Map of key to transform function
|
|
219
|
+
* @returns A migration function
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const migrations = {
|
|
224
|
+
* 1: createValueTransformMigration({
|
|
225
|
+
* 'user:fetch': (entry) => ({
|
|
226
|
+
* ...entry,
|
|
227
|
+
* result: entry.result.ok
|
|
228
|
+
* ? ok({ ...entry.result.value, newField: 'default' })
|
|
229
|
+
* : entry.result,
|
|
230
|
+
* }),
|
|
231
|
+
* }),
|
|
232
|
+
* };
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function createValueTransformMigration(transforms: Record<string, (entry: ResumeStateEntry) => ResumeStateEntry>): MigrationFn;
|
|
236
|
+
/**
|
|
237
|
+
* Compose multiple migrations into a single migration.
|
|
238
|
+
*
|
|
239
|
+
* @param migrations - Array of migration functions
|
|
240
|
+
* @returns A single migration function that applies all migrations in order
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const migrations = {
|
|
245
|
+
* 1: composeMigrations([
|
|
246
|
+
* createKeyRenameMigration({ 'old': 'new' }),
|
|
247
|
+
* createKeyRemoveMigration(['deprecated']),
|
|
248
|
+
* ]),
|
|
249
|
+
* };
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function composeMigrations(migrations: MigrationFn[]): MigrationFn;
|
|
253
|
+
|
|
254
|
+
export { type MigrationError, type MigrationFn, type Migrations, ResumeState, type Version, type VersionIncompatibleError, type VersionedState, type VersionedWorkflowConfig, composeMigrations, createKeyRemoveMigration, createKeyRenameMigration, createValueTransformMigration, createVersionedState, createVersionedStateLoader, isMigrationError, isVersionIncompatibleError, parseVersionedState, stringifyVersionedState };
|