@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
package/README.zh-TW.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
> Gravito 的高效能工作流程引擎,跨平台、型別安全的狀態機,強調可追蹤、可重播與可靠重試。
|
|
4
4
|
|
|
5
|
+
## 定位與價值
|
|
6
|
+
|
|
7
|
+
- **工作流標準化**:在框架內用同一套模型描述流程,而不是每個服務自行手寫流程。
|
|
8
|
+
- **可靠性與可觀測**:狀態機 + 重試 + trace sink,讓流程可追蹤、可審計、可恢復。
|
|
9
|
+
- **可抽離與可複用**:Flux 可獨立於框架使用,讓 workflow 本身成為可移植的 workflow as code。
|
|
10
|
+
|
|
11
|
+
## API 語意(input / step / commit)
|
|
12
|
+
|
|
13
|
+
- `input<T>()`:定義輸入資料型別,提供型別推斷與編輯器提示。
|
|
14
|
+
- `step(name, handler, options)`:一般步驟,會依序執行,可設定重試/逾時/條件。
|
|
15
|
+
- `commit(name, handler, options)`:具副作用的步驟(寫庫、扣款、通知),在重播或重跑時語意更明確。
|
|
16
|
+
|
|
17
|
+
## 最佳實務與注意事項
|
|
18
|
+
|
|
19
|
+
- **儲存介面**:Memory 僅適合開發與測試,正式環境請使用持久化 storage。
|
|
20
|
+
- **版本變更**:workflow 定義改動時,既有流程的重跑需評估相容性。
|
|
21
|
+
- **重試策略**:外部依賴錯誤才重試,業務邏輯錯誤建議直接 fail。
|
|
22
|
+
- **Step vs Commit**:有副作用的操作應放在 commit,確保重播一致性。
|
|
23
|
+
|
|
5
24
|
## 核心特色
|
|
6
25
|
|
|
7
26
|
- **純狀態機模型** - 以明確狀態描述流程,讓每一步清晰可控
|
|
@@ -142,6 +161,75 @@ const engine = new FluxEngine({
|
|
|
142
161
|
})
|
|
143
162
|
```
|
|
144
163
|
|
|
164
|
+
## 重跑指定步驟
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const first = await engine.execute(flow, { orderId: 'ORD-001' })
|
|
168
|
+
await engine.retryStep(flow, first.id, 'charge')
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 與隊列搭配的應用
|
|
172
|
+
|
|
173
|
+
隊列消費者只負責觸發 Flux,Flux 會把任務拆成多步驟 workflow。當某一步失敗時,只重試該步,不會重跑已完成的步驟。
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
queue.on('message', async (job) => {
|
|
177
|
+
await flux.execute(orderFlow, job.data)
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
搭配持久化 storage,已完成的步驟會被保留,避免重複執行。
|
|
182
|
+
|
|
183
|
+
### Kafka 完整案例(事件 → 消費者 → Flux)
|
|
184
|
+
|
|
185
|
+
**1) 事件觸發:把任務丟進 Kafka**
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { Kafka } from 'kafkajs'
|
|
189
|
+
|
|
190
|
+
const kafka = new Kafka({ clientId: 'orders', brokers: ['localhost:9092'] })
|
|
191
|
+
const producer = kafka.producer()
|
|
192
|
+
|
|
193
|
+
await producer.connect()
|
|
194
|
+
await producer.send({
|
|
195
|
+
topic: 'order.created',
|
|
196
|
+
messages: [
|
|
197
|
+
{ key: 'ORD-001', value: JSON.stringify({ orderId: 'ORD-001', userId: 'u_1' }) },
|
|
198
|
+
],
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**2) 消費者接到任務後交給 Flux**
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { Kafka } from 'kafkajs'
|
|
206
|
+
import { createWorkflow, FluxEngine, MemoryStorage } from '@gravito/flux'
|
|
207
|
+
|
|
208
|
+
const orderFlow = createWorkflow('order-flow')
|
|
209
|
+
.input<{ orderId: string; userId: string }>()
|
|
210
|
+
.step('validate', async (ctx) => {
|
|
211
|
+
ctx.data.validated = true
|
|
212
|
+
})
|
|
213
|
+
.step('reserve', async (ctx) => {
|
|
214
|
+
ctx.data.reserved = true
|
|
215
|
+
})
|
|
216
|
+
.commit('notify', async () => {})
|
|
217
|
+
|
|
218
|
+
const flux = new FluxEngine({ storage: new MemoryStorage() })
|
|
219
|
+
|
|
220
|
+
const kafka = new Kafka({ clientId: 'orders-worker', brokers: ['localhost:9092'] })
|
|
221
|
+
const consumer = kafka.consumer({ groupId: 'order-workers' })
|
|
222
|
+
|
|
223
|
+
await consumer.connect()
|
|
224
|
+
await consumer.subscribe({ topic: 'order.created' })
|
|
225
|
+
await consumer.run({
|
|
226
|
+
eachMessage: async ({ message }) => {
|
|
227
|
+
const payload = JSON.parse(message.value?.toString() ?? '{}')
|
|
228
|
+
await flux.execute(orderFlow, payload)
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
```
|
|
232
|
+
|
|
145
233
|
## 分支流程(多支點)
|
|
146
234
|
|
|
147
235
|
```typescript
|
|
@@ -176,6 +264,54 @@ const flow = createWorkflow('event-routing')
|
|
|
176
264
|
})
|
|
177
265
|
```
|
|
178
266
|
|
|
267
|
+
## 多節點任務(類似 n8n)
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const flow = createWorkflow('multi-node')
|
|
271
|
+
.input<{ type: 'email' | 'slack' | 'webhook'; payload: unknown }>()
|
|
272
|
+
.step('classify', async (ctx) => {
|
|
273
|
+
ctx.data.route = ctx.input.type
|
|
274
|
+
})
|
|
275
|
+
.step(
|
|
276
|
+
'send-email',
|
|
277
|
+
async (ctx) => {
|
|
278
|
+
await email.send(ctx.input.payload)
|
|
279
|
+
},
|
|
280
|
+
{ when: (ctx) => ctx.data.route === 'email' }
|
|
281
|
+
)
|
|
282
|
+
.step(
|
|
283
|
+
'send-slack',
|
|
284
|
+
async (ctx) => {
|
|
285
|
+
await slack.send(ctx.input.payload)
|
|
286
|
+
},
|
|
287
|
+
{ when: (ctx) => ctx.data.route === 'slack' }
|
|
288
|
+
)
|
|
289
|
+
.step(
|
|
290
|
+
'call-webhook',
|
|
291
|
+
async (ctx) => {
|
|
292
|
+
await webhook.post(ctx.input.payload)
|
|
293
|
+
},
|
|
294
|
+
{ when: (ctx) => ctx.data.route === 'webhook' }
|
|
295
|
+
)
|
|
296
|
+
.commit('audit', async (ctx) => {
|
|
297
|
+
await audit.save(ctx.data)
|
|
298
|
+
})
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
<img
|
|
302
|
+
src="./assets/flux-branching.svg"
|
|
303
|
+
alt="Flux branching diagram"
|
|
304
|
+
style="max-width: 720px; width: 100%; height: auto; display: block; margin: 12px 0;"
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
上圖對應 `when` 條件:只會走符合條件的分支,未符合者會被標記為 skipped。
|
|
308
|
+
|
|
309
|
+
### 可執行分支範例
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
bun run examples/branching.ts
|
|
313
|
+
```
|
|
314
|
+
|
|
179
315
|
## 本地開發視覺化
|
|
180
316
|
|
|
181
317
|
```typescript
|
|
@@ -201,6 +337,59 @@ bun run dev:viewer
|
|
|
201
337
|
|
|
202
338
|
透過 `FluxTraceSink` 可以把事件流送到你自己的監控、排程或分析模組,建立完整的執行查詢、重播與告警能力。
|
|
203
339
|
|
|
340
|
+
## 以微服務或 AWS Lambda 部署
|
|
341
|
+
|
|
342
|
+
Flux 可抽離成無狀態 workflow runner。把 workflow 定義與 input 交給函式執行,再將狀態與 trace 寫入外部儲存即可:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { FluxEngine, JsonFileTraceSink, MemoryStorage, createWorkflow } from '@gravito/flux'
|
|
346
|
+
|
|
347
|
+
const workflow = createWorkflow('lambda-flow')
|
|
348
|
+
.input<{ orderId: string }>()
|
|
349
|
+
.step('prepare', async (ctx) => {
|
|
350
|
+
ctx.data.ready = true
|
|
351
|
+
})
|
|
352
|
+
.commit('notify', async () => {})
|
|
353
|
+
|
|
354
|
+
const engine = new FluxEngine({
|
|
355
|
+
storage: new MemoryStorage(),
|
|
356
|
+
trace: new JsonFileTraceSink({ path: '/tmp/flux-trace.ndjson', reset: false }),
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
export const handler = async (event: { orderId: string }) => {
|
|
360
|
+
const result = await engine.execute(workflow, { orderId: event.orderId })
|
|
361
|
+
return { status: result.status, id: result.id }
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### 其他雲端函式範例
|
|
366
|
+
|
|
367
|
+
GCP Cloud Functions(HTTP,需安裝對應套件並確認最新版本):
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
import type { HttpFunction } from '@google-cloud/functions-framework'
|
|
371
|
+
|
|
372
|
+
export const runFlux: HttpFunction = async (req, res) => {
|
|
373
|
+
const payload = req.body ?? {}
|
|
374
|
+
const result = await engine.execute(workflow, payload)
|
|
375
|
+
res.json({ status: result.status, id: result.id })
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Azure Functions(HTTP Trigger,需安裝對應套件並確認最新版本):
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
import type { AzureFunction, Context, HttpRequest } from '@azure/functions'
|
|
383
|
+
|
|
384
|
+
const httpTrigger: AzureFunction = async (context: Context, req: HttpRequest) => {
|
|
385
|
+
const payload = req.body ?? {}
|
|
386
|
+
const result = await engine.execute(workflow, payload)
|
|
387
|
+
context.res = { status: 200, body: { status: result.status, id: result.id } }
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export default httpTrigger
|
|
391
|
+
```
|
|
392
|
+
|
|
204
393
|
## 儲存介面
|
|
205
394
|
|
|
206
395
|
### MemoryStorage
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 240" role="img" aria-label="Flux branching diagram">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="fluxNode" x1="0" x2="1">
|
|
4
|
+
<stop offset="0%" stop-color="#141c2b" />
|
|
5
|
+
<stop offset="100%" stop-color="#0b1220" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="glow-blue" x1="0" x2="1">
|
|
8
|
+
<stop offset="0%" stop-color="#38bdf8" />
|
|
9
|
+
<stop offset="100%" stop-color="#60a5fa" />
|
|
10
|
+
</linearGradient>
|
|
11
|
+
<linearGradient id="glow-violet" x1="0" x2="1">
|
|
12
|
+
<stop offset="0%" stop-color="#a78bfa" />
|
|
13
|
+
<stop offset="100%" stop-color="#8b5cf6" />
|
|
14
|
+
</linearGradient>
|
|
15
|
+
<linearGradient id="glow-amber" x1="0" x2="1">
|
|
16
|
+
<stop offset="0%" stop-color="#fbbf24" />
|
|
17
|
+
<stop offset="100%" stop-color="#f59e0b" />
|
|
18
|
+
</linearGradient>
|
|
19
|
+
<linearGradient id="glow-emerald" x1="0" x2="1">
|
|
20
|
+
<stop offset="0%" stop-color="#34d399" />
|
|
21
|
+
<stop offset="100%" stop-color="#10b981" />
|
|
22
|
+
</linearGradient>
|
|
23
|
+
<linearGradient id="glow-rose" x1="0" x2="1">
|
|
24
|
+
<stop offset="0%" stop-color="#fb7185" />
|
|
25
|
+
<stop offset="100%" stop-color="#f43f5e" />
|
|
26
|
+
</linearGradient>
|
|
27
|
+
<filter id="nodeShadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
28
|
+
<feDropShadow dx="0" dy="8" stdDeviation="10" flood-color="#0b1120" flood-opacity="0.6" />
|
|
29
|
+
</filter>
|
|
30
|
+
<marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
|
31
|
+
<path d="M 0 0 L 10 5 L 0 10 z" fill="#60a5fa" />
|
|
32
|
+
</marker>
|
|
33
|
+
</defs>
|
|
34
|
+
|
|
35
|
+
<!-- classify -->
|
|
36
|
+
<g filter="url(#nodeShadow)">
|
|
37
|
+
<rect x="30" y="100" width="160" height="50" rx="14" fill="url(#fluxNode)" stroke="#1f2937" />
|
|
38
|
+
<rect x="42" y="112" width="26" height="26" rx="8" fill="url(#glow-blue)" />
|
|
39
|
+
<path d="M52 119h6l4 6-4 6h-6l-4-6z" fill="#0f172a" />
|
|
40
|
+
<text x="120" y="130" fill="#e2e8f0" font-size="12" text-anchor="middle">classify</text>
|
|
41
|
+
</g>
|
|
42
|
+
|
|
43
|
+
<!-- send-email -->
|
|
44
|
+
<g filter="url(#nodeShadow)">
|
|
45
|
+
<rect x="250" y="20" width="180" height="46" rx="14" fill="url(#fluxNode)" stroke="#1f2937" />
|
|
46
|
+
<rect x="262" y="32" width="26" height="26" rx="8" fill="url(#glow-amber)" />
|
|
47
|
+
<path d="M268 38h14l-7 6z" fill="#0f172a" />
|
|
48
|
+
<rect x="268" y="40" width="14" height="10" rx="2" fill="none" stroke="#0f172a" stroke-width="1.6" />
|
|
49
|
+
<text x="350" y="48" fill="#e2e8f0" font-size="12" text-anchor="middle">send-email</text>
|
|
50
|
+
</g>
|
|
51
|
+
|
|
52
|
+
<!-- send-slack -->
|
|
53
|
+
<g filter="url(#nodeShadow)">
|
|
54
|
+
<rect x="250" y="96" width="180" height="46" rx="14" fill="url(#fluxNode)" stroke="#1f2937" />
|
|
55
|
+
<rect x="262" y="108" width="26" height="26" rx="8" fill="url(#glow-violet)" />
|
|
56
|
+
<path d="M269 115h10a4 4 0 0 1 4 4v6l-5-3h-9a4 4 0 0 1-4-4v-3a4 4 0 0 1 4-4z" fill="#0f172a" />
|
|
57
|
+
<text x="350" y="124" fill="#e2e8f0" font-size="12" text-anchor="middle">send-slack</text>
|
|
58
|
+
</g>
|
|
59
|
+
|
|
60
|
+
<!-- call-webhook -->
|
|
61
|
+
<g filter="url(#nodeShadow)">
|
|
62
|
+
<rect x="250" y="172" width="180" height="46" rx="14" fill="url(#fluxNode)" stroke="#1f2937" />
|
|
63
|
+
<rect x="262" y="184" width="26" height="26" rx="8" fill="url(#glow-emerald)" />
|
|
64
|
+
<path d="M268 198h14m-7-6v12" stroke="#0f172a" stroke-width="2" stroke-linecap="round" />
|
|
65
|
+
<text x="350" y="200" fill="#e2e8f0" font-size="12" text-anchor="middle">call-webhook</text>
|
|
66
|
+
</g>
|
|
67
|
+
|
|
68
|
+
<!-- audit -->
|
|
69
|
+
<g filter="url(#nodeShadow)">
|
|
70
|
+
<rect x="520" y="100" width="160" height="50" rx="14" fill="url(#fluxNode)" stroke="#1f2937" />
|
|
71
|
+
<rect x="532" y="112" width="26" height="26" rx="8" fill="url(#glow-rose)" />
|
|
72
|
+
<path d="M538 118h14v12h-14z" fill="none" stroke="#0f172a" stroke-width="1.6" />
|
|
73
|
+
<path d="M541 122h8M541 126h8M541 130h6" stroke="#0f172a" stroke-width="1.6" stroke-linecap="round" />
|
|
74
|
+
<text x="610" y="130" fill="#e2e8f0" font-size="12" text-anchor="middle">audit</text>
|
|
75
|
+
</g>
|
|
76
|
+
|
|
77
|
+
<line x1="190" y1="125" x2="250" y2="43" stroke="#60a5fa" stroke-width="2" marker-end="url(#arrow)" />
|
|
78
|
+
<line x1="190" y1="125" x2="250" y2="119" stroke="#60a5fa" stroke-width="2" marker-end="url(#arrow)" />
|
|
79
|
+
<line x1="190" y1="125" x2="250" y2="195" stroke="#60a5fa" stroke-width="2" marker-end="url(#arrow)" />
|
|
80
|
+
|
|
81
|
+
<line x1="430" y1="43" x2="520" y2="125" stroke="#38bdf8" stroke-width="2" marker-end="url(#arrow)" />
|
|
82
|
+
<line x1="430" y1="119" x2="520" y2="125" stroke="#38bdf8" stroke-width="2" marker-end="url(#arrow)" />
|
|
83
|
+
<line x1="430" y1="195" x2="520" y2="125" stroke="#38bdf8" stroke-width="2" marker-end="url(#arrow)" />
|
|
84
|
+
</svg>
|
package/dist/bun.cjs
ADDED
package/dist/bun.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/bun.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,8DAAC","file":"/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/bun.cjs"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { n as WorkflowStorage, l as WorkflowState, k as WorkflowFilter } from './types-DvVHBmP6.cjs';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @fileoverview Bun SQLite Storage Adapter
|
|
3
6
|
*
|
|
@@ -5,12 +8,11 @@
|
|
|
5
8
|
*
|
|
6
9
|
* @module @gravito/flux/storage
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
import type { WorkflowFilter, WorkflowState, WorkflowStorage } from '../types';
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* SQLite Storage Options
|
|
12
14
|
*/
|
|
13
|
-
|
|
15
|
+
interface BunSQLiteStorageOptions {
|
|
14
16
|
/** Database file path (default: ':memory:') */
|
|
15
17
|
path?: string;
|
|
16
18
|
/** Table name (default: 'flux_workflows') */
|
|
@@ -28,7 +30,7 @@ export interface BunSQLiteStorageOptions {
|
|
|
28
30
|
* })
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
|
-
|
|
33
|
+
declare class BunSQLiteStorage implements WorkflowStorage {
|
|
32
34
|
private db;
|
|
33
35
|
private tableName;
|
|
34
36
|
private initialized;
|
|
@@ -70,4 +72,5 @@ export declare class BunSQLiteStorage implements WorkflowStorage {
|
|
|
70
72
|
*/
|
|
71
73
|
vacuum(): void;
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
|
|
76
|
+
export { BunSQLiteStorage, type BunSQLiteStorageOptions };
|
package/dist/bun.d.ts
CHANGED
|
@@ -1,9 +1,76 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { n as WorkflowStorage, l as WorkflowState, k as WorkflowFilter } from './types-DvVHBmP6.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @fileoverview Bun
|
|
5
|
+
* @fileoverview Bun SQLite Storage Adapter
|
|
3
6
|
*
|
|
4
|
-
*
|
|
7
|
+
* High-performance storage using Bun's built-in SQLite.
|
|
5
8
|
*
|
|
6
|
-
* @module @gravito/flux/
|
|
9
|
+
* @module @gravito/flux/storage
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SQLite Storage Options
|
|
14
|
+
*/
|
|
15
|
+
interface BunSQLiteStorageOptions {
|
|
16
|
+
/** Database file path (default: ':memory:') */
|
|
17
|
+
path?: string;
|
|
18
|
+
/** Table name (default: 'flux_workflows') */
|
|
19
|
+
tableName?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Bun SQLite Storage
|
|
23
|
+
*
|
|
24
|
+
* High-performance storage adapter using Bun's built-in SQLite.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const engine = new FluxEngine({
|
|
29
|
+
* storage: new BunSQLiteStorage({ path: './data/flux.db' })
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare class BunSQLiteStorage implements WorkflowStorage {
|
|
34
|
+
private db;
|
|
35
|
+
private tableName;
|
|
36
|
+
private initialized;
|
|
37
|
+
constructor(options?: BunSQLiteStorageOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Initialize storage (create tables)
|
|
40
|
+
*/
|
|
41
|
+
init(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Save workflow state
|
|
44
|
+
*/
|
|
45
|
+
save(state: WorkflowState): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Load workflow state by ID
|
|
48
|
+
*/
|
|
49
|
+
load(id: string): Promise<WorkflowState | null>;
|
|
50
|
+
/**
|
|
51
|
+
* List workflow states with optional filter
|
|
52
|
+
*/
|
|
53
|
+
list(filter?: WorkflowFilter): Promise<WorkflowState[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete workflow state
|
|
56
|
+
*/
|
|
57
|
+
delete(id: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Close database connection
|
|
60
|
+
*/
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Convert SQLite row to WorkflowState
|
|
64
|
+
*/
|
|
65
|
+
private rowToState;
|
|
66
|
+
/**
|
|
67
|
+
* Get raw database (for advanced usage)
|
|
68
|
+
*/
|
|
69
|
+
getDatabase(): Database;
|
|
70
|
+
/**
|
|
71
|
+
* Run a vacuum to optimize database
|
|
72
|
+
*/
|
|
73
|
+
vacuum(): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { BunSQLiteStorage, type BunSQLiteStorageOptions };
|
package/dist/bun.js
CHANGED
package/dist/bun.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|