@gravito/flux 2.0.0 → 3.0.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/bun.d.cts +1 -1
- package/dist/bun.d.ts +1 -1
- package/dist/{chunk-LULCFPIK.js → chunk-3JGQYHUN.js} +4 -2
- package/dist/chunk-3JGQYHUN.js.map +1 -0
- package/dist/{chunk-X3NC7HS4.cjs → chunk-5OXXH442.cjs} +10 -8
- package/dist/chunk-5OXXH442.cjs.map +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -5
- package/dist/index.d.ts +39 -5
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +2 -2
- package/dist/index.node.d.cts +59 -66
- package/dist/index.node.d.ts +59 -66
- package/dist/index.node.js +1 -1
- package/dist/types-CZwYGpou.d.cts +353 -0
- package/dist/types-CZwYGpou.d.ts +353 -0
- package/package.json +3 -3
- package/dist/chunk-LULCFPIK.js.map +0 -1
- package/dist/chunk-X3NC7HS4.cjs.map +0 -1
- package/dist/types-cnIU1O3n.d.cts +0 -250
- package/dist/types-cnIU1O3n.d.ts +0 -250
package/dist/types-cnIU1O3n.d.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Core type definitions for @gravito/flux
|
|
3
|
-
*
|
|
4
|
-
* Platform-agnostic workflow engine types.
|
|
5
|
-
*
|
|
6
|
-
* @module @gravito/flux
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Workflow execution status
|
|
10
|
-
*/
|
|
11
|
-
type WorkflowStatus = 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'suspended' | 'rolling_back' | 'rolled_back';
|
|
12
|
-
/**
|
|
13
|
-
* Result of Flux.wait()
|
|
14
|
-
*/
|
|
15
|
-
interface FluxWaitResult {
|
|
16
|
-
__kind: 'flux_wait';
|
|
17
|
-
signal: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Step execution result
|
|
21
|
-
*/
|
|
22
|
-
interface StepResult<T = unknown> {
|
|
23
|
-
success: boolean;
|
|
24
|
-
data?: T;
|
|
25
|
-
error?: Error;
|
|
26
|
-
duration: number;
|
|
27
|
-
suspended?: boolean;
|
|
28
|
-
waitingFor?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Step execution history entry
|
|
32
|
-
*/
|
|
33
|
-
interface StepExecution {
|
|
34
|
-
name: string;
|
|
35
|
-
status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'suspended' | 'compensated' | 'compensating';
|
|
36
|
-
startedAt?: Date;
|
|
37
|
-
completedAt?: Date;
|
|
38
|
-
suspendedAt?: Date;
|
|
39
|
-
compensatedAt?: Date;
|
|
40
|
-
waitingFor?: string;
|
|
41
|
-
duration?: number;
|
|
42
|
-
output?: any;
|
|
43
|
-
error?: string;
|
|
44
|
-
retries: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Step definition
|
|
48
|
-
*/
|
|
49
|
-
interface StepDefinition<TInput = any, TData = any> {
|
|
50
|
-
/** Step name (unique within workflow) */
|
|
51
|
-
name: string;
|
|
52
|
-
/** Step handler function */
|
|
53
|
-
handler: (ctx: WorkflowContext<TInput, TData>) => Promise<void | FluxWaitResult> | void | FluxWaitResult;
|
|
54
|
-
/** Compensation handler to undo effects */
|
|
55
|
-
compensate?: (ctx: WorkflowContext<TInput, TData>) => Promise<void> | void;
|
|
56
|
-
/** Number of retries on failure */
|
|
57
|
-
retries?: number;
|
|
58
|
-
/** Timeout in milliseconds */
|
|
59
|
-
timeout?: number;
|
|
60
|
-
/** Condition to skip this step */
|
|
61
|
-
when?: (ctx: WorkflowContext<TInput, TData>) => boolean;
|
|
62
|
-
/** Mark as commit step (always executes even on replay) */
|
|
63
|
-
commit?: boolean;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Workflow execution context
|
|
67
|
-
*
|
|
68
|
-
* Passed to each step handler with accumulated data.
|
|
69
|
-
*/
|
|
70
|
-
interface WorkflowContext<TInput = unknown, TData = Record<string, unknown>> {
|
|
71
|
-
/** Unique workflow instance ID */
|
|
72
|
-
readonly id: string;
|
|
73
|
-
/** Workflow definition name */
|
|
74
|
-
readonly name: string;
|
|
75
|
-
/** Original input data */
|
|
76
|
-
readonly input: TInput;
|
|
77
|
-
/** Accumulated step data (mutable) */
|
|
78
|
-
data: TData;
|
|
79
|
-
/** Current workflow status */
|
|
80
|
-
readonly status: WorkflowStatus;
|
|
81
|
-
/** Current step index */
|
|
82
|
-
readonly currentStep: number;
|
|
83
|
-
/** Step execution history */
|
|
84
|
-
readonly history: StepExecution[];
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Serializable workflow state for persistence
|
|
88
|
-
*/
|
|
89
|
-
interface WorkflowState<TInput = any, TData = any> {
|
|
90
|
-
id: string;
|
|
91
|
-
name: string;
|
|
92
|
-
status: WorkflowStatus;
|
|
93
|
-
input: TInput;
|
|
94
|
-
data: TData;
|
|
95
|
-
currentStep: number;
|
|
96
|
-
history: StepExecution[];
|
|
97
|
-
createdAt: Date;
|
|
98
|
-
updatedAt: Date;
|
|
99
|
-
completedAt?: Date;
|
|
100
|
-
error?: string;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Workflow definition (immutable blueprint)
|
|
104
|
-
*/
|
|
105
|
-
interface WorkflowDefinition<TInput = unknown, TData = Record<string, unknown>> {
|
|
106
|
-
/** Workflow name */
|
|
107
|
-
name: string;
|
|
108
|
-
/** Step definitions in order */
|
|
109
|
-
steps: StepDefinition<TInput, TData>[];
|
|
110
|
-
/** Input schema validator (optional) */
|
|
111
|
-
validateInput?: (input: unknown) => input is TInput;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Workflow descriptor (serializable metadata)
|
|
115
|
-
*/
|
|
116
|
-
interface WorkflowDescriptor {
|
|
117
|
-
name: string;
|
|
118
|
-
steps: StepDescriptor[];
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Step descriptor (serializable metadata)
|
|
122
|
-
*/
|
|
123
|
-
interface StepDescriptor {
|
|
124
|
-
name: string;
|
|
125
|
-
commit: boolean;
|
|
126
|
-
retries?: number;
|
|
127
|
-
timeout?: number;
|
|
128
|
-
hasCondition: boolean;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Workflow storage adapter interface
|
|
132
|
-
*/
|
|
133
|
-
interface WorkflowStorage {
|
|
134
|
-
/**
|
|
135
|
-
* Save workflow state
|
|
136
|
-
*/
|
|
137
|
-
save(state: WorkflowState): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Load workflow state by ID
|
|
140
|
-
*/
|
|
141
|
-
load(id: string): Promise<WorkflowState | null>;
|
|
142
|
-
/**
|
|
143
|
-
* List workflow states with optional filter
|
|
144
|
-
*/
|
|
145
|
-
list(filter?: WorkflowFilter): Promise<WorkflowState[]>;
|
|
146
|
-
/**
|
|
147
|
-
* Delete workflow state
|
|
148
|
-
*/
|
|
149
|
-
delete(id: string): Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Initialize storage (create tables, etc.)
|
|
152
|
-
*/
|
|
153
|
-
init?(): Promise<void>;
|
|
154
|
-
/**
|
|
155
|
-
* Cleanup storage resources
|
|
156
|
-
*/
|
|
157
|
-
close?(): Promise<void>;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Workflow filter options
|
|
161
|
-
*/
|
|
162
|
-
interface WorkflowFilter {
|
|
163
|
-
name?: string;
|
|
164
|
-
status?: WorkflowStatus | WorkflowStatus[];
|
|
165
|
-
limit?: number;
|
|
166
|
-
offset?: number;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Logger interface for FluxEngine
|
|
170
|
-
*
|
|
171
|
-
* Implement this to create custom loggers.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* const engine = new FluxEngine({
|
|
176
|
-
* logger: new FluxConsoleLogger()
|
|
177
|
-
* })
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
interface FluxLogger {
|
|
181
|
-
debug(message: string, ...args: unknown[]): void;
|
|
182
|
-
info(message: string, ...args: unknown[]): void;
|
|
183
|
-
warn(message: string, ...args: unknown[]): void;
|
|
184
|
-
error(message: string, ...args: unknown[]): void;
|
|
185
|
-
}
|
|
186
|
-
type FluxTraceEventType = 'workflow:start' | 'workflow:complete' | 'workflow:error' | 'workflow:rollback_start' | 'workflow:rollback_complete' | 'step:start' | 'step:complete' | 'step:error' | 'step:skipped' | 'step:retry' | 'step:suspend' | 'step:compensate' | 'signal:received';
|
|
187
|
-
interface FluxTraceEvent {
|
|
188
|
-
type: FluxTraceEventType;
|
|
189
|
-
timestamp: number;
|
|
190
|
-
workflowId: string;
|
|
191
|
-
workflowName: string;
|
|
192
|
-
stepName?: string;
|
|
193
|
-
stepIndex?: number;
|
|
194
|
-
commit?: boolean;
|
|
195
|
-
retries?: number;
|
|
196
|
-
maxRetries?: number;
|
|
197
|
-
duration?: number;
|
|
198
|
-
error?: string;
|
|
199
|
-
status?: WorkflowStatus | StepExecution['status'];
|
|
200
|
-
input?: unknown;
|
|
201
|
-
data?: Record<string, unknown>;
|
|
202
|
-
meta?: Record<string, unknown>;
|
|
203
|
-
}
|
|
204
|
-
interface FluxTraceSink {
|
|
205
|
-
emit(event: FluxTraceEvent): void | Promise<void>;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Workflow engine configuration
|
|
209
|
-
*/
|
|
210
|
-
interface FluxConfig {
|
|
211
|
-
/** Storage adapter */
|
|
212
|
-
storage?: WorkflowStorage;
|
|
213
|
-
/** Logger instance */
|
|
214
|
-
logger?: FluxLogger;
|
|
215
|
-
/** Trace sink for workflow events */
|
|
216
|
-
trace?: FluxTraceSink;
|
|
217
|
-
/** Default retry count for steps */
|
|
218
|
-
defaultRetries?: number;
|
|
219
|
-
/** Default timeout for steps (ms) */
|
|
220
|
-
defaultTimeout?: number;
|
|
221
|
-
/** Enable parallel execution for independent steps */
|
|
222
|
-
parallel?: boolean;
|
|
223
|
-
/** Event handlers */
|
|
224
|
-
on?: {
|
|
225
|
-
stepStart?: (step: string, ctx: WorkflowContext) => void;
|
|
226
|
-
stepComplete?: (step: string, ctx: WorkflowContext, result: StepResult) => void;
|
|
227
|
-
stepError?: (step: string, ctx: WorkflowContext, error: Error) => void;
|
|
228
|
-
workflowComplete?: (ctx: WorkflowContext) => void;
|
|
229
|
-
workflowError?: (ctx: WorkflowContext, error: Error) => void;
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Workflow execution result
|
|
234
|
-
*/
|
|
235
|
-
interface FluxResult<TData = Record<string, unknown>> {
|
|
236
|
-
/** Workflow instance ID */
|
|
237
|
-
id: string;
|
|
238
|
-
/** Final status */
|
|
239
|
-
status: WorkflowStatus;
|
|
240
|
-
/** Accumulated data from all steps */
|
|
241
|
-
data: TData;
|
|
242
|
-
/** Step execution history */
|
|
243
|
-
history: StepExecution[];
|
|
244
|
-
/** Total execution duration (ms) */
|
|
245
|
-
duration: number;
|
|
246
|
-
/** Error if failed */
|
|
247
|
-
error?: Error;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export type { FluxWaitResult as F, StepDefinition as S, WorkflowDefinition as W, FluxConfig as a, FluxLogger as b, FluxResult as c, FluxTraceEvent as d, FluxTraceEventType as e, FluxTraceSink as f, StepDescriptor as g, StepExecution as h, StepResult as i, WorkflowContext as j, WorkflowDescriptor as k, WorkflowFilter as l, WorkflowState as m, WorkflowStatus as n, WorkflowStorage as o };
|