@gravito/flux 1.0.0-beta.2 → 1.0.0-beta.3
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/README.zh-TW.md +189 -0
- package/assets/flux-branching.svg +84 -0
- package/dist/bun.cjs +7 -0
- package/dist/bun.cjs.map +1 -0
- package/dist/{storage/BunSQLiteStorage.d.ts → bun.d.cts} +8 -5
- package/dist/bun.d.ts +72 -5
- package/dist/bun.js +2 -2
- package/dist/bun.js.map +1 -0
- package/dist/chunk-J37UUMLM.js +858 -0
- package/dist/chunk-J37UUMLM.js.map +1 -0
- package/dist/chunk-RPECIW7O.cjs +858 -0
- package/dist/chunk-RPECIW7O.cjs.map +1 -0
- package/dist/chunk-SJSPR4ZU.cjs +173 -0
- package/dist/chunk-SJSPR4ZU.cjs.map +1 -0
- package/dist/{chunk-qjdtqchy.js → chunk-ZAMVC732.js} +35 -7
- package/dist/chunk-ZAMVC732.js.map +1 -0
- package/dist/index.cjs +121 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +40 -35
- package/dist/index.js +102 -460
- package/dist/index.js.map +1 -0
- package/dist/index.node.cjs +28 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.d.cts +499 -0
- package/dist/index.node.d.ts +494 -13
- package/dist/index.node.js +28 -0
- package/dist/index.node.js.map +1 -0
- package/dist/{types.d.ts → types-DvVHBmP6.d.cts} +59 -18
- package/dist/types-DvVHBmP6.d.ts +235 -0
- package/package.json +26 -22
- package/dist/builder/WorkflowBuilder.d.ts +0 -96
- package/dist/builder/WorkflowBuilder.d.ts.map +0 -1
- package/dist/builder/index.d.ts +0 -2
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/bun.d.ts.map +0 -1
- package/dist/core/ContextManager.d.ts +0 -40
- package/dist/core/ContextManager.d.ts.map +0 -1
- package/dist/core/StateMachine.d.ts +0 -43
- package/dist/core/StateMachine.d.ts.map +0 -1
- package/dist/core/StepExecutor.d.ts +0 -34
- package/dist/core/StepExecutor.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/engine/FluxEngine.d.ts +0 -66
- package/dist/engine/FluxEngine.d.ts.map +0 -1
- package/dist/engine/index.d.ts +0 -2
- package/dist/engine/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.node.d.ts.map +0 -1
- package/dist/logger/FluxLogger.d.ts +0 -40
- package/dist/logger/FluxLogger.d.ts.map +0 -1
- package/dist/logger/index.d.ts +0 -2
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/node/index.mjs +0 -619
- package/dist/orbit/OrbitFlux.d.ts +0 -107
- package/dist/orbit/OrbitFlux.d.ts.map +0 -1
- package/dist/orbit/index.d.ts +0 -2
- package/dist/orbit/index.d.ts.map +0 -1
- package/dist/storage/BunSQLiteStorage.d.ts.map +0 -1
- package/dist/storage/MemoryStorage.d.ts +0 -28
- package/dist/storage/MemoryStorage.d.ts.map +0 -1
- package/dist/storage/index.d.ts +0 -3
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkRPECIW7Ocjs = require('./chunk-RPECIW7O.cjs');
|
|
14
|
+
require('./chunk-SJSPR4ZU.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.ContextManager = _chunkRPECIW7Ocjs.ContextManager; exports.FluxConsoleLogger = _chunkRPECIW7Ocjs.FluxConsoleLogger; exports.FluxEngine = _chunkRPECIW7Ocjs.FluxEngine; exports.FluxSilentLogger = _chunkRPECIW7Ocjs.FluxSilentLogger; exports.JsonFileTraceSink = _chunkRPECIW7Ocjs.JsonFileTraceSink; exports.MemoryStorage = _chunkRPECIW7Ocjs.MemoryStorage; exports.OrbitFlux = _chunkRPECIW7Ocjs.OrbitFlux; exports.StateMachine = _chunkRPECIW7Ocjs.StateMachine; exports.StepExecutor = _chunkRPECIW7Ocjs.StepExecutor; exports.WorkflowBuilder = _chunkRPECIW7Ocjs.WorkflowBuilder; exports.createWorkflow = _chunkRPECIW7Ocjs.createWorkflow;
|
|
28
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/index.node.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,8nBAAC","file":"/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/index.node.cjs"}
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { i as WorkflowContext, W as WorkflowDefinition, j as WorkflowDescriptor, F as FluxConfig, b as FluxResult, l as WorkflowState, n as WorkflowStorage, k as WorkflowFilter, e as FluxTraceSink, c as FluxTraceEvent, m as WorkflowStatus, S as StepDefinition, g as StepExecution, h as StepResult, a as FluxLogger } from './types-DvVHBmP6.cjs';
|
|
2
|
+
export { d as FluxTraceEventType, f as StepDescriptor } from './types-DvVHBmP6.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Workflow Builder - Fluent API for defining workflows
|
|
6
|
+
*
|
|
7
|
+
* Type-safe, chainable workflow definition.
|
|
8
|
+
*
|
|
9
|
+
* @module @gravito/flux/builder
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Step options
|
|
14
|
+
*/
|
|
15
|
+
interface StepOptions {
|
|
16
|
+
retries?: number;
|
|
17
|
+
timeout?: number;
|
|
18
|
+
when?: (ctx: WorkflowContext) => boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Workflow Builder
|
|
22
|
+
*
|
|
23
|
+
* Provides fluent API for defining workflows with type inference.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const workflow = createWorkflow('order-process')
|
|
28
|
+
* .input<{ orderId: string }>()
|
|
29
|
+
* .step('validate', async (ctx) => {
|
|
30
|
+
* ctx.data.order = await fetchOrder(ctx.input.orderId)
|
|
31
|
+
* })
|
|
32
|
+
* .step('process', async (ctx) => {
|
|
33
|
+
* await processOrder(ctx.data.order)
|
|
34
|
+
* })
|
|
35
|
+
* .commit('notify', async (ctx) => {
|
|
36
|
+
* await sendEmail(ctx.data.order.email)
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class WorkflowBuilder<TInput = unknown, TData = Record<string, unknown>> {
|
|
41
|
+
private _name;
|
|
42
|
+
private _steps;
|
|
43
|
+
private _validateInput?;
|
|
44
|
+
constructor(name: string);
|
|
45
|
+
/**
|
|
46
|
+
* Define input type
|
|
47
|
+
*
|
|
48
|
+
* This method is used for TypeScript type inference.
|
|
49
|
+
*/
|
|
50
|
+
input<T>(): WorkflowBuilder<T, TData>;
|
|
51
|
+
/**
|
|
52
|
+
* Define workflow data (state) type
|
|
53
|
+
*
|
|
54
|
+
* This method is used for TypeScript type inference.
|
|
55
|
+
*/
|
|
56
|
+
data<T>(): WorkflowBuilder<TInput, T>;
|
|
57
|
+
/**
|
|
58
|
+
* Add input validator
|
|
59
|
+
*/
|
|
60
|
+
validate(validator: (input: unknown) => input is TInput): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add a step to the workflow
|
|
63
|
+
*/
|
|
64
|
+
step(name: string, handler: (ctx: WorkflowContext<TInput, TData>) => Promise<void> | void, options?: StepOptions): this;
|
|
65
|
+
/**
|
|
66
|
+
* Add a commit step (always executes, even on replay)
|
|
67
|
+
*
|
|
68
|
+
* Commit steps are for side effects that should not be skipped,
|
|
69
|
+
* such as database writes or external API calls.
|
|
70
|
+
*/
|
|
71
|
+
commit(name: string, handler: (ctx: WorkflowContext<TInput, TData>) => Promise<void> | void, options?: StepOptions): this;
|
|
72
|
+
/**
|
|
73
|
+
* Build the workflow definition
|
|
74
|
+
*/
|
|
75
|
+
build(): WorkflowDefinition<TInput, TData>;
|
|
76
|
+
/**
|
|
77
|
+
* Describe workflow (serializable metadata)
|
|
78
|
+
*/
|
|
79
|
+
describe(): WorkflowDescriptor;
|
|
80
|
+
/**
|
|
81
|
+
* Get workflow name
|
|
82
|
+
*/
|
|
83
|
+
get name(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get step count
|
|
86
|
+
*/
|
|
87
|
+
get stepCount(): number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a new workflow builder
|
|
91
|
+
*
|
|
92
|
+
* @param name - Unique workflow name
|
|
93
|
+
* @returns WorkflowBuilder instance
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const uploadFlow = createWorkflow('image-upload')
|
|
98
|
+
* .input<{ file: Buffer }>()
|
|
99
|
+
* .step('resize', async (ctx) => {
|
|
100
|
+
* ctx.data.resized = await sharp(ctx.input.file).resize(200).toBuffer()
|
|
101
|
+
* })
|
|
102
|
+
* .commit('save', async (ctx) => {
|
|
103
|
+
* await storage.put(ctx.data.resized)
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function createWorkflow(name: string): WorkflowBuilder;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @fileoverview Flux Engine - Main workflow execution engine
|
|
111
|
+
*
|
|
112
|
+
* Orchestrates workflow execution with storage and event handling.
|
|
113
|
+
*
|
|
114
|
+
* @module @gravito/flux
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Flux Engine
|
|
119
|
+
*
|
|
120
|
+
* Main workflow execution engine.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const engine = new FluxEngine({ storage: new MemoryStorage() })
|
|
125
|
+
*
|
|
126
|
+
* const workflow = createWorkflow('process-order')
|
|
127
|
+
* .input<{ orderId: string }>()
|
|
128
|
+
* .step('fetch', async (ctx) => { ... })
|
|
129
|
+
* .step('validate', async (ctx) => { ... })
|
|
130
|
+
* .commit('save', async (ctx) => { ... })
|
|
131
|
+
*
|
|
132
|
+
* const result = await engine.execute(workflow, { orderId: '123' })
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare class FluxEngine {
|
|
136
|
+
private storage;
|
|
137
|
+
private executor;
|
|
138
|
+
private contextManager;
|
|
139
|
+
private config;
|
|
140
|
+
constructor(config?: FluxConfig);
|
|
141
|
+
/**
|
|
142
|
+
* Execute a workflow with input data
|
|
143
|
+
*
|
|
144
|
+
* @param workflow - Workflow builder or definition
|
|
145
|
+
* @param input - Input data for the workflow
|
|
146
|
+
* @returns Execution result
|
|
147
|
+
*/
|
|
148
|
+
execute<TInput, TData = any>(workflow: WorkflowBuilder<TInput, TData> | WorkflowDefinition<TInput, TData>, input: TInput): Promise<FluxResult<TData>>;
|
|
149
|
+
/**
|
|
150
|
+
* Resume a paused or failed workflow
|
|
151
|
+
*
|
|
152
|
+
* @param workflowId - Workflow instance ID
|
|
153
|
+
* @returns Execution result or null if not found
|
|
154
|
+
*/
|
|
155
|
+
resume<TInput, TData = any>(workflow: WorkflowBuilder<TInput, TData> | WorkflowDefinition<TInput, TData>, workflowId: string, options?: {
|
|
156
|
+
fromStep?: number | string;
|
|
157
|
+
}): Promise<FluxResult<TData> | null>;
|
|
158
|
+
/**
|
|
159
|
+
* Retry a specific step (replays from that step onward)
|
|
160
|
+
*/
|
|
161
|
+
retryStep<TInput, TData = any>(workflow: WorkflowBuilder<TInput, TData> | WorkflowDefinition<TInput, TData>, workflowId: string, stepName: string): Promise<FluxResult<TData> | null>;
|
|
162
|
+
/**
|
|
163
|
+
* Get workflow state by ID
|
|
164
|
+
*/
|
|
165
|
+
get<TInput = any, TData = any>(workflowId: string): Promise<WorkflowState<TInput, TData> | null>;
|
|
166
|
+
/**
|
|
167
|
+
* Save workflow state manually (e.g., for external updates)
|
|
168
|
+
*/
|
|
169
|
+
saveState<TInput, TData>(state: WorkflowState<TInput, TData>): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* List workflows
|
|
172
|
+
*/
|
|
173
|
+
list(filter?: Parameters<WorkflowStorage['list']>[0]): Promise<WorkflowState<any, any>[]>;
|
|
174
|
+
/**
|
|
175
|
+
* Initialize engine (init storage)
|
|
176
|
+
*/
|
|
177
|
+
init(): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Shutdown engine (cleanup)
|
|
180
|
+
*/
|
|
181
|
+
close(): Promise<void>;
|
|
182
|
+
private resolveDefinition;
|
|
183
|
+
private resolveStartIndex;
|
|
184
|
+
private resetHistoryFrom;
|
|
185
|
+
private runFrom;
|
|
186
|
+
private emitTrace;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @fileoverview In-memory storage adapter
|
|
191
|
+
*
|
|
192
|
+
* Simple storage for development and testing.
|
|
193
|
+
*
|
|
194
|
+
* @module @gravito/flux/storage
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Memory Storage
|
|
199
|
+
*
|
|
200
|
+
* In-memory storage adapter for development and testing.
|
|
201
|
+
* Data is not persisted across restarts.
|
|
202
|
+
*/
|
|
203
|
+
declare class MemoryStorage implements WorkflowStorage {
|
|
204
|
+
private store;
|
|
205
|
+
save(state: WorkflowState): Promise<void>;
|
|
206
|
+
load(id: string): Promise<WorkflowState | null>;
|
|
207
|
+
list(filter?: WorkflowFilter): Promise<WorkflowState[]>;
|
|
208
|
+
delete(id: string): Promise<void>;
|
|
209
|
+
init(): Promise<void>;
|
|
210
|
+
close(): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Get store size (for testing)
|
|
213
|
+
*/
|
|
214
|
+
size(): number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @fileoverview JSON file trace sink (NDJSON)
|
|
219
|
+
*
|
|
220
|
+
* Writes trace events to a newline-delimited JSON file.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
interface JsonFileTraceSinkOptions {
|
|
224
|
+
path: string;
|
|
225
|
+
reset?: boolean;
|
|
226
|
+
}
|
|
227
|
+
declare class JsonFileTraceSink implements FluxTraceSink {
|
|
228
|
+
private path;
|
|
229
|
+
private ready;
|
|
230
|
+
constructor(options: JsonFileTraceSinkOptions);
|
|
231
|
+
private init;
|
|
232
|
+
emit(event: FluxTraceEvent): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @fileoverview Context Manager for workflow execution
|
|
237
|
+
*
|
|
238
|
+
* Manages workflow context lifecycle and state snapshots.
|
|
239
|
+
*
|
|
240
|
+
* @module @gravito/flux/core
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Context Manager
|
|
245
|
+
*
|
|
246
|
+
* Creates and manages workflow execution contexts.
|
|
247
|
+
*/
|
|
248
|
+
declare class ContextManager {
|
|
249
|
+
/**
|
|
250
|
+
* Create a new workflow context
|
|
251
|
+
*/
|
|
252
|
+
create<TInput, TData = any>(name: string, input: TInput, stepCount: number): WorkflowContext<TInput, TData>;
|
|
253
|
+
/**
|
|
254
|
+
* Restore context from saved state
|
|
255
|
+
*/
|
|
256
|
+
restore<TInput, TData = any>(state: WorkflowState<TInput, TData>): WorkflowContext<TInput, TData>;
|
|
257
|
+
/**
|
|
258
|
+
* Convert context to serializable state
|
|
259
|
+
*/
|
|
260
|
+
toState<TInput, TData>(ctx: WorkflowContext<TInput, TData>): WorkflowState<TInput, TData>;
|
|
261
|
+
/**
|
|
262
|
+
* Update context status (returns new context for immutability)
|
|
263
|
+
*/
|
|
264
|
+
updateStatus<TInput, TData>(ctx: WorkflowContext<TInput, TData>, status: WorkflowStatus): WorkflowContext<TInput, TData>;
|
|
265
|
+
/**
|
|
266
|
+
* Advance to next step
|
|
267
|
+
*/
|
|
268
|
+
advanceStep<TInput, TData>(ctx: WorkflowContext<TInput, TData>): WorkflowContext<TInput, TData>;
|
|
269
|
+
/**
|
|
270
|
+
* Update step name in history
|
|
271
|
+
*/
|
|
272
|
+
setStepName<TInput, TData>(ctx: WorkflowContext<TInput, TData>, index: number, name: string): void;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @fileoverview State Machine for workflow status transitions
|
|
277
|
+
*
|
|
278
|
+
* Pure state machine with no runtime dependencies.
|
|
279
|
+
*
|
|
280
|
+
* @module @gravito/flux/core
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* State Machine for workflow status management
|
|
285
|
+
*
|
|
286
|
+
* Provides validated state transitions using EventTarget for events.
|
|
287
|
+
*/
|
|
288
|
+
declare class StateMachine extends EventTarget {
|
|
289
|
+
private _status;
|
|
290
|
+
/**
|
|
291
|
+
* Current status
|
|
292
|
+
*/
|
|
293
|
+
get status(): WorkflowStatus;
|
|
294
|
+
/**
|
|
295
|
+
* Check if transition to target status is allowed
|
|
296
|
+
*/
|
|
297
|
+
canTransition(to: WorkflowStatus): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Transition to a new status
|
|
300
|
+
*
|
|
301
|
+
* @throws {Error} If transition is not allowed
|
|
302
|
+
*/
|
|
303
|
+
transition(to: WorkflowStatus): void;
|
|
304
|
+
/**
|
|
305
|
+
* Force set status (for replay/restore)
|
|
306
|
+
*/
|
|
307
|
+
forceStatus(status: WorkflowStatus): void;
|
|
308
|
+
/**
|
|
309
|
+
* Check if workflow is in terminal state
|
|
310
|
+
*/
|
|
311
|
+
isTerminal(): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Check if workflow can be executed
|
|
314
|
+
*/
|
|
315
|
+
canExecute(): boolean;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @fileoverview Step Executor for workflow steps
|
|
320
|
+
*
|
|
321
|
+
* Handles step execution with retry and timeout support.
|
|
322
|
+
*
|
|
323
|
+
* @module @gravito/flux/core
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Step Executor
|
|
328
|
+
*
|
|
329
|
+
* Executes individual workflow steps with retry and timeout support.
|
|
330
|
+
*/
|
|
331
|
+
declare class StepExecutor {
|
|
332
|
+
private defaultRetries;
|
|
333
|
+
private defaultTimeout;
|
|
334
|
+
private onRetry?;
|
|
335
|
+
constructor(options?: {
|
|
336
|
+
defaultRetries?: number;
|
|
337
|
+
defaultTimeout?: number;
|
|
338
|
+
onRetry?: (step: StepDefinition<any, any>, ctx: WorkflowContext<any, any>, error: Error, attempt: number, maxRetries: number) => void | Promise<void>;
|
|
339
|
+
});
|
|
340
|
+
/**
|
|
341
|
+
* Execute a step with retry and timeout
|
|
342
|
+
*/
|
|
343
|
+
execute<TInput, TData>(step: StepDefinition<TInput, TData>, ctx: WorkflowContext<TInput, TData>, execution: StepExecution): Promise<StepResult>;
|
|
344
|
+
/**
|
|
345
|
+
* Execute handler with timeout
|
|
346
|
+
*/
|
|
347
|
+
private executeWithTimeout;
|
|
348
|
+
/**
|
|
349
|
+
* Sleep helper
|
|
350
|
+
*/
|
|
351
|
+
private sleep;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @fileoverview Console Logger for FluxEngine
|
|
356
|
+
*
|
|
357
|
+
* Default logger implementation using console.
|
|
358
|
+
*
|
|
359
|
+
* @module @gravito/flux
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Console Logger
|
|
364
|
+
*
|
|
365
|
+
* Default logger that outputs to console.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const engine = new FluxEngine({
|
|
370
|
+
* logger: new FluxConsoleLogger()
|
|
371
|
+
* })
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
declare class FluxConsoleLogger implements FluxLogger {
|
|
375
|
+
private prefix;
|
|
376
|
+
constructor(prefix?: string);
|
|
377
|
+
debug(message: string, ...args: unknown[]): void;
|
|
378
|
+
info(message: string, ...args: unknown[]): void;
|
|
379
|
+
warn(message: string, ...args: unknown[]): void;
|
|
380
|
+
error(message: string, ...args: unknown[]): void;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Silent Logger
|
|
384
|
+
*
|
|
385
|
+
* Logger that outputs nothing (for testing or production).
|
|
386
|
+
*/
|
|
387
|
+
declare class FluxSilentLogger implements FluxLogger {
|
|
388
|
+
debug(): void;
|
|
389
|
+
info(): void;
|
|
390
|
+
warn(): void;
|
|
391
|
+
error(): void;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @fileoverview OrbitFlux - Gravito PlanetCore Integration
|
|
396
|
+
*
|
|
397
|
+
* Integrates FluxEngine with Gravito's PlanetCore for seamless workflow management.
|
|
398
|
+
*
|
|
399
|
+
* @module @gravito/flux
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Minimal PlanetCore interface for type compatibility
|
|
404
|
+
* (Avoids importing @gravito/core sources which causes rootDir issues)
|
|
405
|
+
*/
|
|
406
|
+
interface PlanetCore {
|
|
407
|
+
logger: {
|
|
408
|
+
debug(message: string, ...args: unknown[]): void;
|
|
409
|
+
info(message: string, ...args: unknown[]): void;
|
|
410
|
+
warn(message: string, ...args: unknown[]): void;
|
|
411
|
+
error(message: string, ...args: unknown[]): void;
|
|
412
|
+
};
|
|
413
|
+
services: {
|
|
414
|
+
set(key: string, value: unknown): void;
|
|
415
|
+
get<T>(key: string): T | undefined;
|
|
416
|
+
};
|
|
417
|
+
hooks: {
|
|
418
|
+
doAction(name: string, payload?: unknown): void;
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* GravitoOrbit interface
|
|
423
|
+
*/
|
|
424
|
+
interface GravitoOrbit {
|
|
425
|
+
install(core: PlanetCore): void | Promise<void>;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* OrbitFlux configuration options
|
|
429
|
+
*/
|
|
430
|
+
interface OrbitFluxOptions {
|
|
431
|
+
/**
|
|
432
|
+
* Storage driver: 'memory' | 'sqlite' | custom WorkflowStorage
|
|
433
|
+
* @default 'memory'
|
|
434
|
+
*/
|
|
435
|
+
storage?: 'memory' | 'sqlite' | WorkflowStorage;
|
|
436
|
+
/**
|
|
437
|
+
* SQLite database path (only used if storage is 'sqlite')
|
|
438
|
+
* @default ':memory:'
|
|
439
|
+
*/
|
|
440
|
+
dbPath?: string;
|
|
441
|
+
/**
|
|
442
|
+
* Service name in core.services
|
|
443
|
+
* @default 'flux'
|
|
444
|
+
*/
|
|
445
|
+
exposeAs?: string;
|
|
446
|
+
/**
|
|
447
|
+
* Custom logger
|
|
448
|
+
*/
|
|
449
|
+
logger?: FluxLogger;
|
|
450
|
+
/**
|
|
451
|
+
* Default retry count for steps
|
|
452
|
+
* @default 3
|
|
453
|
+
*/
|
|
454
|
+
defaultRetries?: number;
|
|
455
|
+
/**
|
|
456
|
+
* Default timeout for steps (ms)
|
|
457
|
+
* @default 30000
|
|
458
|
+
*/
|
|
459
|
+
defaultTimeout?: number;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* OrbitFlux - Gravito Workflow Integration
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* import { OrbitFlux } from '@gravito/flux'
|
|
467
|
+
*
|
|
468
|
+
* const core = await PlanetCore.boot({
|
|
469
|
+
* orbits: [
|
|
470
|
+
* new OrbitFlux({ storage: 'sqlite', dbPath: './data/workflows.db' })
|
|
471
|
+
* ]
|
|
472
|
+
* })
|
|
473
|
+
*
|
|
474
|
+
* // Access via services
|
|
475
|
+
* const flux = core.services.get<FluxEngine>('flux')
|
|
476
|
+
* await flux.execute(myWorkflow, input)
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
declare class OrbitFlux implements GravitoOrbit {
|
|
480
|
+
private options;
|
|
481
|
+
private engine?;
|
|
482
|
+
constructor(options?: OrbitFluxOptions);
|
|
483
|
+
/**
|
|
484
|
+
* Create OrbitFlux with configuration
|
|
485
|
+
*/
|
|
486
|
+
static configure(options?: OrbitFluxOptions): OrbitFlux;
|
|
487
|
+
/**
|
|
488
|
+
* Install into PlanetCore
|
|
489
|
+
*
|
|
490
|
+
* @param core - The PlanetCore instance
|
|
491
|
+
*/
|
|
492
|
+
install(core: PlanetCore): Promise<void>;
|
|
493
|
+
/**
|
|
494
|
+
* Get the FluxEngine instance
|
|
495
|
+
*/
|
|
496
|
+
getEngine(): FluxEngine | undefined;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export { ContextManager, FluxConfig, FluxConsoleLogger, FluxEngine, FluxLogger, FluxResult, FluxSilentLogger, FluxTraceEvent, FluxTraceSink, JsonFileTraceSink, MemoryStorage, OrbitFlux, type OrbitFluxOptions, StateMachine, StepDefinition, StepExecution, StepExecutor, StepResult, WorkflowBuilder, WorkflowContext, WorkflowDefinition, WorkflowDescriptor, WorkflowFilter, WorkflowState, WorkflowStatus, WorkflowStorage, createWorkflow };
|