@hazeljs/flow 0.2.0-beta.75
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/LICENSE +192 -0
- package/README.md +111 -0
- package/dist/decorators/flow.decorators.d.ts +32 -0
- package/dist/decorators/flow.decorators.d.ts.map +1 -0
- package/dist/decorators/flow.decorators.js +100 -0
- package/dist/dsl/flow.d.ts +19 -0
- package/dist/dsl/flow.d.ts.map +1 -0
- package/dist/dsl/flow.js +46 -0
- package/dist/dsl/types.d.ts +5 -0
- package/dist/dsl/types.d.ts.map +1 -0
- package/dist/dsl/types.js +2 -0
- package/dist/engine/Executor.d.ts +11 -0
- package/dist/engine/Executor.d.ts.map +1 -0
- package/dist/engine/Executor.js +113 -0
- package/dist/engine/FlowEngine.d.ts +46 -0
- package/dist/engine/FlowEngine.d.ts.map +1 -0
- package/dist/engine/FlowEngine.js +237 -0
- package/dist/engine/Idempotency.d.ts +10 -0
- package/dist/engine/Idempotency.d.ts.map +1 -0
- package/dist/engine/Idempotency.js +16 -0
- package/dist/engine/Locks.d.ts +11 -0
- package/dist/engine/Locks.d.ts.map +1 -0
- package/dist/engine/Locks.js +68 -0
- package/dist/engine/Retry.d.ts +7 -0
- package/dist/engine/Retry.d.ts.map +1 -0
- package/dist/engine/Retry.js +22 -0
- package/dist/engine/Timeout.d.ts +10 -0
- package/dist/engine/Timeout.d.ts.map +1 -0
- package/dist/engine/Timeout.js +25 -0
- package/dist/engine/Transition.d.ts +6 -0
- package/dist/engine/Transition.d.ts.map +1 -0
- package/dist/engine/Transition.js +19 -0
- package/dist/engine/utils.d.ts +5 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/engine/utils.js +25 -0
- package/dist/examples/branching.d.ts +2 -0
- package/dist/examples/branching.d.ts.map +1 -0
- package/dist/examples/branching.js +72 -0
- package/dist/examples/simple.d.ts +2 -0
- package/dist/examples/simple.d.ts.map +1 -0
- package/dist/examples/simple.js +65 -0
- package/dist/examples/wait_resume.d.ts +2 -0
- package/dist/examples/wait_resume.d.ts.map +1 -0
- package/dist/examples/wait_resume.js +75 -0
- package/dist/generated/prisma/client.d.ts +1 -0
- package/dist/generated/prisma/client.js +5 -0
- package/dist/generated/prisma/default.d.ts +1 -0
- package/dist/generated/prisma/default.js +5 -0
- package/dist/generated/prisma/edge.d.ts +1 -0
- package/dist/generated/prisma/edge.js +250 -0
- package/dist/generated/prisma/index-browser.js +236 -0
- package/dist/generated/prisma/index.d.ts +6577 -0
- package/dist/generated/prisma/index.js +271 -0
- package/dist/generated/prisma/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/dist/generated/prisma/package.json +183 -0
- package/dist/generated/prisma/query_engine_bg.js +2 -0
- package/dist/generated/prisma/query_engine_bg.wasm +0 -0
- package/dist/generated/prisma/runtime/edge-esm.js +35 -0
- package/dist/generated/prisma/runtime/edge.js +35 -0
- package/dist/generated/prisma/runtime/index-browser.d.ts +370 -0
- package/dist/generated/prisma/runtime/index-browser.js +17 -0
- package/dist/generated/prisma/runtime/library.d.ts +3982 -0
- package/dist/generated/prisma/runtime/library.js +147 -0
- package/dist/generated/prisma/runtime/react-native.js +84 -0
- package/dist/generated/prisma/runtime/wasm-compiler-edge.js +85 -0
- package/dist/generated/prisma/runtime/wasm-engine-edge.js +38 -0
- package/dist/generated/prisma/schema.prisma +70 -0
- package/dist/generated/prisma/wasm-edge-light-loader.mjs +5 -0
- package/dist/generated/prisma/wasm-worker-loader.mjs +5 -0
- package/dist/generated/prisma/wasm.d.ts +1 -0
- package/dist/generated/prisma/wasm.js +257 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/persistence/FlowDefinitionRepo.d.ts +14 -0
- package/dist/persistence/FlowDefinitionRepo.d.ts.map +1 -0
- package/dist/persistence/FlowDefinitionRepo.js +44 -0
- package/dist/persistence/FlowEventRepo.d.ts +15 -0
- package/dist/persistence/FlowEventRepo.d.ts.map +1 -0
- package/dist/persistence/FlowEventRepo.js +33 -0
- package/dist/persistence/FlowRunRepo.d.ts +12 -0
- package/dist/persistence/FlowRunRepo.d.ts.map +1 -0
- package/dist/persistence/FlowRunRepo.js +50 -0
- package/dist/persistence/IdempotencyRepo.d.ts +15 -0
- package/dist/persistence/IdempotencyRepo.d.ts.map +1 -0
- package/dist/persistence/IdempotencyRepo.js +39 -0
- package/dist/persistence/memory.d.ts +9 -0
- package/dist/persistence/memory.d.ts.map +1 -0
- package/dist/persistence/memory.js +154 -0
- package/dist/persistence/prisma.d.ts +5 -0
- package/dist/persistence/prisma.d.ts.map +1 -0
- package/dist/persistence/prisma.js +9 -0
- package/dist/persistence/prismaClient.d.ts +21 -0
- package/dist/persistence/prismaClient.d.ts.map +1 -0
- package/dist/persistence/prismaClient.js +47 -0
- package/dist/persistence/prismaStorage.d.ts +11 -0
- package/dist/persistence/prismaStorage.d.ts.map +1 -0
- package/dist/persistence/prismaStorage.js +24 -0
- package/dist/persistence/serialize.d.ts +6 -0
- package/dist/persistence/serialize.d.ts.map +1 -0
- package/dist/persistence/serialize.js +28 -0
- package/dist/persistence/storage.d.ts +75 -0
- package/dist/persistence/storage.d.ts.map +1 -0
- package/dist/persistence/storage.js +6 -0
- package/dist/prisma.d.ts +14 -0
- package/dist/prisma.d.ts.map +1 -0
- package/dist/prisma.js +25 -0
- package/dist/types/Errors.d.ts +21 -0
- package/dist/types/Errors.d.ts.map +1 -0
- package/dist/types/Errors.js +44 -0
- package/dist/types/Events.d.ts +17 -0
- package/dist/types/Events.d.ts.map +1 -0
- package/dist/types/Events.js +5 -0
- package/dist/types/FlowTypes.d.ts +66 -0
- package/dist/types/FlowTypes.d.ts.map +1 -0
- package/dist/types/FlowTypes.js +5 -0
- package/package.json +72 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory storage for flow engine (default, no DB required).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMemoryStorage = createMemoryStorage;
|
|
7
|
+
const serialize_js_1 = require("./serialize.js");
|
|
8
|
+
const RUNNING = 'RUNNING';
|
|
9
|
+
function now() {
|
|
10
|
+
return new Date();
|
|
11
|
+
}
|
|
12
|
+
class MemoryFlowDefinitionRepo {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.store = new Map();
|
|
15
|
+
}
|
|
16
|
+
key(flowId, version) {
|
|
17
|
+
return `${flowId}@${version}`;
|
|
18
|
+
}
|
|
19
|
+
async save(def) {
|
|
20
|
+
this.store.set(this.key(def.flowId, def.version), { ...def });
|
|
21
|
+
}
|
|
22
|
+
async get(flowId, version) {
|
|
23
|
+
return this.store.get(this.key(flowId, version)) ?? null;
|
|
24
|
+
}
|
|
25
|
+
async list() {
|
|
26
|
+
const entries = Array.from(this.store.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
27
|
+
return entries.map(([k, def]) => {
|
|
28
|
+
const [flowId, version] = k.split('@');
|
|
29
|
+
return {
|
|
30
|
+
flowId,
|
|
31
|
+
version,
|
|
32
|
+
definitionJson: (0, serialize_js_1.toSerializable)(def),
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class MemoryFlowRunRepo {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.runs = new Map();
|
|
40
|
+
}
|
|
41
|
+
async create(input) {
|
|
42
|
+
const now_ = now();
|
|
43
|
+
const row = {
|
|
44
|
+
runId: input.runId,
|
|
45
|
+
flowId: input.flowId,
|
|
46
|
+
flowVersion: input.flowVersion,
|
|
47
|
+
tenantId: input.tenantId ?? null,
|
|
48
|
+
status: RUNNING,
|
|
49
|
+
currentNodeId: null,
|
|
50
|
+
inputJson: input.input,
|
|
51
|
+
stateJson: input.initialState ?? {},
|
|
52
|
+
outputsJson: {},
|
|
53
|
+
createdAt: now_,
|
|
54
|
+
updatedAt: now_,
|
|
55
|
+
};
|
|
56
|
+
this.runs.set(input.runId, row);
|
|
57
|
+
return row;
|
|
58
|
+
}
|
|
59
|
+
async get(runId) {
|
|
60
|
+
return this.runs.get(runId) ?? null;
|
|
61
|
+
}
|
|
62
|
+
async update(runId, data) {
|
|
63
|
+
const existing = this.runs.get(runId);
|
|
64
|
+
if (!existing)
|
|
65
|
+
throw new Error(`Run not found: ${runId}`);
|
|
66
|
+
const updated = {
|
|
67
|
+
...existing,
|
|
68
|
+
...data,
|
|
69
|
+
updatedAt: now(),
|
|
70
|
+
};
|
|
71
|
+
this.runs.set(runId, updated);
|
|
72
|
+
return updated;
|
|
73
|
+
}
|
|
74
|
+
async findRunning() {
|
|
75
|
+
return Array.from(this.runs.values()).filter((r) => r.status === 'RUNNING');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class MemoryFlowEventRepo {
|
|
79
|
+
constructor() {
|
|
80
|
+
this.events = [];
|
|
81
|
+
this.id = 0;
|
|
82
|
+
}
|
|
83
|
+
async append(runId, type, payload = {}) {
|
|
84
|
+
this.events.push({
|
|
85
|
+
id: `evt-${++this.id}`,
|
|
86
|
+
runId,
|
|
87
|
+
at: now(),
|
|
88
|
+
type,
|
|
89
|
+
nodeId: payload.nodeId ?? null,
|
|
90
|
+
attempt: payload.attempt ?? null,
|
|
91
|
+
payloadJson: payload,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async getTimeline(runId) {
|
|
95
|
+
return this.events
|
|
96
|
+
.filter((e) => e.runId === runId)
|
|
97
|
+
.sort((a, b) => a.at.getTime() - b.at.getTime())
|
|
98
|
+
.map((e) => ({
|
|
99
|
+
at: e.at,
|
|
100
|
+
type: e.type,
|
|
101
|
+
nodeId: e.nodeId,
|
|
102
|
+
attempt: e.attempt,
|
|
103
|
+
payloadJson: e.payloadJson,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
class MemoryIdempotencyRepo {
|
|
108
|
+
constructor() {
|
|
109
|
+
this.store = new Map();
|
|
110
|
+
}
|
|
111
|
+
async get(key) {
|
|
112
|
+
return this.store.get(key) ?? null;
|
|
113
|
+
}
|
|
114
|
+
async set(key, runId, nodeId, outputJson, patchJson) {
|
|
115
|
+
this.store.set(key, {
|
|
116
|
+
key,
|
|
117
|
+
runId,
|
|
118
|
+
nodeId,
|
|
119
|
+
outputJson: outputJson ?? null,
|
|
120
|
+
patchJson: patchJson ?? null,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const memoryLockQueues = new Map();
|
|
125
|
+
/** In-memory mutex per runId */
|
|
126
|
+
function memoryWithLock(runId, fn) {
|
|
127
|
+
const prev = memoryLockQueues.get(runId) ?? Promise.resolve();
|
|
128
|
+
let resolveNext;
|
|
129
|
+
const _next = new Promise((r) => {
|
|
130
|
+
resolveNext = r;
|
|
131
|
+
});
|
|
132
|
+
const chain = prev.then(() => (async () => {
|
|
133
|
+
try {
|
|
134
|
+
return await fn();
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
resolveNext();
|
|
138
|
+
}
|
|
139
|
+
})());
|
|
140
|
+
memoryLockQueues.set(runId, chain);
|
|
141
|
+
return chain;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create in-memory storage (default, no database).
|
|
145
|
+
*/
|
|
146
|
+
function createMemoryStorage() {
|
|
147
|
+
return {
|
|
148
|
+
definitionRepo: new MemoryFlowDefinitionRepo(),
|
|
149
|
+
runRepo: new MemoryFlowRunRepo(),
|
|
150
|
+
eventRepo: new MemoryFlowEventRepo(),
|
|
151
|
+
idempotencyRepo: new MemoryIdempotencyRepo(),
|
|
152
|
+
withLock: memoryWithLock,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/persistence/prisma.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FlowRunStatus = exports.PrismaClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Re-export flow Prisma client (generated to src/generated/prisma)
|
|
6
|
+
*/
|
|
7
|
+
var prisma_1 = require("../generated/prisma");
|
|
8
|
+
Object.defineProperty(exports, "PrismaClient", { enumerable: true, get: function () { return prisma_1.PrismaClient; } });
|
|
9
|
+
Object.defineProperty(exports, "FlowRunStatus", { enumerable: true, get: function () { return prisma_1.FlowRunStatus; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma client factory and singleton for @hazeljs/flow
|
|
3
|
+
* Uses its own schema - independent of Hazel core
|
|
4
|
+
*/
|
|
5
|
+
import { PrismaClient } from './prisma.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create a Prisma client for the flow schema.
|
|
8
|
+
* Use this when you need a fresh client or want to pass a custom database URL.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFlowPrismaClient(databaseUrl?: string): PrismaClient;
|
|
11
|
+
/**
|
|
12
|
+
* Get the singleton Prisma client for flow.
|
|
13
|
+
* Uses DATABASE_URL from environment.
|
|
14
|
+
* Call createFlowPrismaClient(url) first if you need to set a custom URL.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFlowPrismaClient(databaseUrl?: string): PrismaClient;
|
|
17
|
+
/**
|
|
18
|
+
* Reset the singleton (useful for testing)
|
|
19
|
+
*/
|
|
20
|
+
export declare function resetFlowPrismaClient(): void;
|
|
21
|
+
//# sourceMappingURL=prismaClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prismaClient.d.ts","sourceRoot":"","sources":["../../src/persistence/prismaClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAYzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAMtE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAK5C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prisma client factory and singleton for @hazeljs/flow
|
|
4
|
+
* Uses its own schema - independent of Hazel core
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createFlowPrismaClient = createFlowPrismaClient;
|
|
8
|
+
exports.getFlowPrismaClient = getFlowPrismaClient;
|
|
9
|
+
exports.resetFlowPrismaClient = resetFlowPrismaClient;
|
|
10
|
+
const prisma_js_1 = require("./prisma.js");
|
|
11
|
+
let flowPrismaInstance = null;
|
|
12
|
+
/**
|
|
13
|
+
* Create a Prisma client for the flow schema.
|
|
14
|
+
* Use this when you need a fresh client or want to pass a custom database URL.
|
|
15
|
+
*/
|
|
16
|
+
function createFlowPrismaClient(databaseUrl) {
|
|
17
|
+
const url = databaseUrl ?? process.env.DATABASE_URL;
|
|
18
|
+
if (!url) {
|
|
19
|
+
throw new Error('DATABASE_URL is required. Set it in environment or pass to createFlowPrismaClient().');
|
|
20
|
+
}
|
|
21
|
+
return new prisma_js_1.PrismaClient({
|
|
22
|
+
datasources: {
|
|
23
|
+
db: { url },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the singleton Prisma client for flow.
|
|
29
|
+
* Uses DATABASE_URL from environment.
|
|
30
|
+
* Call createFlowPrismaClient(url) first if you need to set a custom URL.
|
|
31
|
+
*/
|
|
32
|
+
function getFlowPrismaClient(databaseUrl) {
|
|
33
|
+
if (flowPrismaInstance) {
|
|
34
|
+
return flowPrismaInstance;
|
|
35
|
+
}
|
|
36
|
+
flowPrismaInstance = createFlowPrismaClient(databaseUrl);
|
|
37
|
+
return flowPrismaInstance;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reset the singleton (useful for testing)
|
|
41
|
+
*/
|
|
42
|
+
function resetFlowPrismaClient() {
|
|
43
|
+
if (flowPrismaInstance) {
|
|
44
|
+
flowPrismaInstance.$disconnect();
|
|
45
|
+
flowPrismaInstance = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma-backed storage. Use when you want to persist flows in a database.
|
|
3
|
+
* Import from '@hazeljs/flow/prisma' so Prisma is optional for the default package.
|
|
4
|
+
*/
|
|
5
|
+
import type { PrismaClient } from './prisma.js';
|
|
6
|
+
import type { FlowStorage } from './storage.js';
|
|
7
|
+
/**
|
|
8
|
+
* Create storage backed by Prisma (Postgres). Requires @prisma/client and the flow schema.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPrismaStorage(prisma: PrismaClient): FlowStorage;
|
|
11
|
+
//# sourceMappingURL=prismaStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prismaStorage.d.ts","sourceRoot":"","sources":["../../src/persistence/prismaStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAOhD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAQrE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prisma-backed storage. Use when you want to persist flows in a database.
|
|
4
|
+
* Import from '@hazeljs/flow/prisma' so Prisma is optional for the default package.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createPrismaStorage = createPrismaStorage;
|
|
8
|
+
const FlowDefinitionRepo_js_1 = require("./FlowDefinitionRepo.js");
|
|
9
|
+
const FlowRunRepo_js_1 = require("./FlowRunRepo.js");
|
|
10
|
+
const FlowEventRepo_js_1 = require("./FlowEventRepo.js");
|
|
11
|
+
const IdempotencyRepo_js_1 = require("./IdempotencyRepo.js");
|
|
12
|
+
const Locks_js_1 = require("../engine/Locks.js");
|
|
13
|
+
/**
|
|
14
|
+
* Create storage backed by Prisma (Postgres). Requires @prisma/client and the flow schema.
|
|
15
|
+
*/
|
|
16
|
+
function createPrismaStorage(prisma) {
|
|
17
|
+
return {
|
|
18
|
+
definitionRepo: new FlowDefinitionRepo_js_1.FlowDefinitionRepo(prisma),
|
|
19
|
+
runRepo: new FlowRunRepo_js_1.FlowRunRepo(prisma),
|
|
20
|
+
eventRepo: new FlowEventRepo_js_1.FlowEventRepo(prisma),
|
|
21
|
+
idempotencyRepo: new IdempotencyRepo_js_1.IdempotencyRepo(prisma),
|
|
22
|
+
withLock: (runId, fn) => (0, Locks_js_1.withAdvisoryLock)(prisma, runId, fn),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/persistence/serialize.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwB3E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSerializable = toSerializable;
|
|
4
|
+
function toSerializable(def) {
|
|
5
|
+
const nodes = {};
|
|
6
|
+
for (const [id, node] of Object.entries(def.nodes)) {
|
|
7
|
+
nodes[id] = {
|
|
8
|
+
id: node.id,
|
|
9
|
+
name: node.name,
|
|
10
|
+
retry: node.retry,
|
|
11
|
+
timeoutMs: node.timeoutMs,
|
|
12
|
+
// handler, idempotencyKey are not serializable - omitted
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const edges = def.edges.map((e) => ({
|
|
16
|
+
from: e.from,
|
|
17
|
+
to: e.to,
|
|
18
|
+
priority: e.priority,
|
|
19
|
+
// when is a function - omitted
|
|
20
|
+
}));
|
|
21
|
+
return {
|
|
22
|
+
flowId: def.flowId,
|
|
23
|
+
version: def.version,
|
|
24
|
+
entry: def.entry,
|
|
25
|
+
nodes,
|
|
26
|
+
edges,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage interfaces for flow engine.
|
|
3
|
+
* Default implementation is in-memory; Prisma can be injected via createPrismaStorage (see @hazeljs/flow/prisma).
|
|
4
|
+
*/
|
|
5
|
+
import type { FlowDefinition } from '../types/FlowTypes.js';
|
|
6
|
+
import type { FlowRunStatus } from '../types/FlowTypes.js';
|
|
7
|
+
import type { FlowEventType, FlowRunEventPayload } from '../types/Events.js';
|
|
8
|
+
export type { FlowRunStatus };
|
|
9
|
+
export interface FlowRunRow {
|
|
10
|
+
runId: string;
|
|
11
|
+
flowId: string;
|
|
12
|
+
flowVersion: string;
|
|
13
|
+
tenantId: string | null;
|
|
14
|
+
status: FlowRunStatus;
|
|
15
|
+
currentNodeId: string | null;
|
|
16
|
+
inputJson: unknown;
|
|
17
|
+
stateJson: unknown;
|
|
18
|
+
outputsJson: unknown;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
}
|
|
22
|
+
export interface CreateRunInput {
|
|
23
|
+
runId: string;
|
|
24
|
+
flowId: string;
|
|
25
|
+
flowVersion: string;
|
|
26
|
+
tenantId?: string | null;
|
|
27
|
+
input: unknown;
|
|
28
|
+
initialState?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface IFlowDefinitionRepo {
|
|
31
|
+
save(def: FlowDefinition): Promise<void>;
|
|
32
|
+
get(flowId: string, version: string): Promise<FlowDefinition | null>;
|
|
33
|
+
list(): Promise<Array<{
|
|
34
|
+
flowId: string;
|
|
35
|
+
version: string;
|
|
36
|
+
definitionJson: unknown;
|
|
37
|
+
}>>;
|
|
38
|
+
}
|
|
39
|
+
export interface IFlowRunRepo {
|
|
40
|
+
create(input: CreateRunInput): Promise<FlowRunRow>;
|
|
41
|
+
get(runId: string): Promise<FlowRunRow | null>;
|
|
42
|
+
update(runId: string, data: Partial<FlowRunRow>): Promise<FlowRunRow>;
|
|
43
|
+
findRunning(): Promise<FlowRunRow[]>;
|
|
44
|
+
}
|
|
45
|
+
export interface IFlowEventRepo {
|
|
46
|
+
append(runId: string, type: FlowEventType, payload?: FlowRunEventPayload): Promise<void>;
|
|
47
|
+
getTimeline(runId: string): Promise<Array<{
|
|
48
|
+
at: Date;
|
|
49
|
+
type: string;
|
|
50
|
+
nodeId: string | null;
|
|
51
|
+
attempt: number | null;
|
|
52
|
+
payloadJson: unknown;
|
|
53
|
+
}>>;
|
|
54
|
+
}
|
|
55
|
+
export interface IdempotencyRecord {
|
|
56
|
+
key: string;
|
|
57
|
+
runId: string;
|
|
58
|
+
nodeId: string;
|
|
59
|
+
outputJson: unknown;
|
|
60
|
+
patchJson: unknown;
|
|
61
|
+
}
|
|
62
|
+
export interface IIdempotencyRepo {
|
|
63
|
+
get(key: string): Promise<IdempotencyRecord | null>;
|
|
64
|
+
set(key: string, runId: string, nodeId: string, outputJson?: unknown, patchJson?: unknown): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
/** Run-scoped lock: only one tick/resume per runId at a time */
|
|
67
|
+
export type WithLockFn = <T>(runId: string, fn: () => Promise<T>) => Promise<T>;
|
|
68
|
+
export interface FlowStorage {
|
|
69
|
+
definitionRepo: IFlowDefinitionRepo;
|
|
70
|
+
runRepo: IFlowRunRepo;
|
|
71
|
+
eventRepo: IFlowEventRepo;
|
|
72
|
+
idempotencyRepo: IIdempotencyRepo;
|
|
73
|
+
withLock: WithLockFn;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/persistence/storage.ts"],"names":[],"mappings":"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"}
|
package/dist/prisma.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma-backed storage for @hazeljs/flow.
|
|
3
|
+
* Import from '@hazeljs/flow/prisma' when you want DB persistence.
|
|
4
|
+
* Requires @prisma/client to be installed and the flow schema applied (migrations).
|
|
5
|
+
*/
|
|
6
|
+
export { createPrismaStorage } from './persistence/prismaStorage.js';
|
|
7
|
+
export { createFlowPrismaClient, getFlowPrismaClient, resetFlowPrismaClient, } from './persistence/prismaClient.js';
|
|
8
|
+
export { FlowDefinitionRepo } from './persistence/FlowDefinitionRepo.js';
|
|
9
|
+
export { FlowRunRepo } from './persistence/FlowRunRepo.js';
|
|
10
|
+
export type { FlowRunRow } from './persistence/FlowRunRepo.js';
|
|
11
|
+
export { FlowEventRepo } from './persistence/FlowEventRepo.js';
|
|
12
|
+
export { IdempotencyRepo } from './persistence/IdempotencyRepo.js';
|
|
13
|
+
export { runIdToLockKey, withAdvisoryLock } from './engine/Locks.js';
|
|
14
|
+
//# sourceMappingURL=prisma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../src/prisma.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/prisma.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prisma-backed storage for @hazeljs/flow.
|
|
4
|
+
* Import from '@hazeljs/flow/prisma' when you want DB persistence.
|
|
5
|
+
* Requires @prisma/client to be installed and the flow schema applied (migrations).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.withAdvisoryLock = exports.runIdToLockKey = exports.IdempotencyRepo = exports.FlowEventRepo = exports.FlowRunRepo = exports.FlowDefinitionRepo = exports.resetFlowPrismaClient = exports.getFlowPrismaClient = exports.createFlowPrismaClient = exports.createPrismaStorage = void 0;
|
|
9
|
+
var prismaStorage_js_1 = require("./persistence/prismaStorage.js");
|
|
10
|
+
Object.defineProperty(exports, "createPrismaStorage", { enumerable: true, get: function () { return prismaStorage_js_1.createPrismaStorage; } });
|
|
11
|
+
var prismaClient_js_1 = require("./persistence/prismaClient.js");
|
|
12
|
+
Object.defineProperty(exports, "createFlowPrismaClient", { enumerable: true, get: function () { return prismaClient_js_1.createFlowPrismaClient; } });
|
|
13
|
+
Object.defineProperty(exports, "getFlowPrismaClient", { enumerable: true, get: function () { return prismaClient_js_1.getFlowPrismaClient; } });
|
|
14
|
+
Object.defineProperty(exports, "resetFlowPrismaClient", { enumerable: true, get: function () { return prismaClient_js_1.resetFlowPrismaClient; } });
|
|
15
|
+
var FlowDefinitionRepo_js_1 = require("./persistence/FlowDefinitionRepo.js");
|
|
16
|
+
Object.defineProperty(exports, "FlowDefinitionRepo", { enumerable: true, get: function () { return FlowDefinitionRepo_js_1.FlowDefinitionRepo; } });
|
|
17
|
+
var FlowRunRepo_js_1 = require("./persistence/FlowRunRepo.js");
|
|
18
|
+
Object.defineProperty(exports, "FlowRunRepo", { enumerable: true, get: function () { return FlowRunRepo_js_1.FlowRunRepo; } });
|
|
19
|
+
var FlowEventRepo_js_1 = require("./persistence/FlowEventRepo.js");
|
|
20
|
+
Object.defineProperty(exports, "FlowEventRepo", { enumerable: true, get: function () { return FlowEventRepo_js_1.FlowEventRepo; } });
|
|
21
|
+
var IdempotencyRepo_js_1 = require("./persistence/IdempotencyRepo.js");
|
|
22
|
+
Object.defineProperty(exports, "IdempotencyRepo", { enumerable: true, get: function () { return IdempotencyRepo_js_1.IdempotencyRepo; } });
|
|
23
|
+
var Locks_js_1 = require("./engine/Locks.js");
|
|
24
|
+
Object.defineProperty(exports, "runIdToLockKey", { enumerable: true, get: function () { return Locks_js_1.runIdToLockKey; } });
|
|
25
|
+
Object.defineProperty(exports, "withAdvisoryLock", { enumerable: true, get: function () { return Locks_js_1.withAdvisoryLock; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flow engine error types
|
|
3
|
+
*/
|
|
4
|
+
export declare class FlowError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
constructor(message: string, code: string, retryable?: boolean);
|
|
8
|
+
}
|
|
9
|
+
export declare class LockBusyError extends FlowError {
|
|
10
|
+
constructor(runId: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class AmbiguousEdgeError extends FlowError {
|
|
13
|
+
constructor(nodeId: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class FlowNotFoundError extends FlowError {
|
|
16
|
+
constructor(flowId: string, version: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class RunNotFoundError extends FlowError {
|
|
19
|
+
constructor(runId: string);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../src/types/Errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,SAAU,SAAQ,KAAK;aAGhB,IAAI,EAAE,MAAM;aACZ,SAAS;gBAFzB,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,SAAS,UAAQ;CAMpC;AAED,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,KAAK,EAAE,MAAM;CAI1B;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,MAAM,EAAE,MAAM;CAI3B;AAED,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI5C;AAED,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,KAAK,EAAE,MAAM;CAI1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Flow engine error types
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RunNotFoundError = exports.FlowNotFoundError = exports.AmbiguousEdgeError = exports.LockBusyError = exports.FlowError = void 0;
|
|
7
|
+
class FlowError extends Error {
|
|
8
|
+
constructor(message, code, retryable = false) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.retryable = retryable;
|
|
12
|
+
this.name = 'FlowError';
|
|
13
|
+
Object.setPrototypeOf(this, FlowError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.FlowError = FlowError;
|
|
17
|
+
class LockBusyError extends FlowError {
|
|
18
|
+
constructor(runId) {
|
|
19
|
+
super(`Lock busy for run ${runId}`, 'LOCK_BUSY', true);
|
|
20
|
+
this.name = 'LockBusyError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.LockBusyError = LockBusyError;
|
|
24
|
+
class AmbiguousEdgeError extends FlowError {
|
|
25
|
+
constructor(nodeId) {
|
|
26
|
+
super(`Ambiguous edge from node ${nodeId}`, 'AMBIGUOUS_EDGE', false);
|
|
27
|
+
this.name = 'AmbiguousEdgeError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AmbiguousEdgeError = AmbiguousEdgeError;
|
|
31
|
+
class FlowNotFoundError extends FlowError {
|
|
32
|
+
constructor(flowId, version) {
|
|
33
|
+
super(`Flow not found: ${flowId}@${version}`, 'FLOW_NOT_FOUND', false);
|
|
34
|
+
this.name = 'FlowNotFoundError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.FlowNotFoundError = FlowNotFoundError;
|
|
38
|
+
class RunNotFoundError extends FlowError {
|
|
39
|
+
constructor(runId) {
|
|
40
|
+
super(`Run not found: ${runId}`, 'RUN_NOT_FOUND', false);
|
|
41
|
+
this.name = 'RunNotFoundError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.RunNotFoundError = RunNotFoundError;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flow run event types for audit timeline
|
|
3
|
+
*/
|
|
4
|
+
export type FlowEventType = 'RUN_STARTED' | 'NODE_STARTED' | 'NODE_FINISHED' | 'NODE_FAILED' | 'RUN_WAITING' | 'RUN_COMPLETED' | 'RUN_ABORTED';
|
|
5
|
+
export interface FlowRunEventPayload {
|
|
6
|
+
nodeId?: string;
|
|
7
|
+
attempt?: number;
|
|
8
|
+
cached?: boolean;
|
|
9
|
+
error?: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
reason?: string;
|
|
14
|
+
until?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=Events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Events.d.ts","sourceRoot":"","sources":["../../src/types/Events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,cAAc,GACd,eAAe,GACf,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,CAAC;AAElB,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core flow definition types
|
|
3
|
+
*/
|
|
4
|
+
export type NodeId = string;
|
|
5
|
+
/** Run status (used by storage; DB enum matches these values) */
|
|
6
|
+
export type FlowRunStatus = 'RUNNING' | 'WAITING' | 'COMPLETED' | 'FAILED';
|
|
7
|
+
export interface FlowContext {
|
|
8
|
+
runId: string;
|
|
9
|
+
flowId: string;
|
|
10
|
+
flowVersion: string;
|
|
11
|
+
tenantId?: string;
|
|
12
|
+
input: unknown;
|
|
13
|
+
state: Record<string, unknown>;
|
|
14
|
+
outputs: Record<string, unknown>;
|
|
15
|
+
meta: {
|
|
16
|
+
attempts: Record<string, number>;
|
|
17
|
+
startedAt: string;
|
|
18
|
+
};
|
|
19
|
+
services?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface RetryPolicy {
|
|
22
|
+
maxAttempts: number;
|
|
23
|
+
backoff: 'fixed' | 'exponential';
|
|
24
|
+
baseDelayMs: number;
|
|
25
|
+
maxDelayMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface NodeDefinition {
|
|
28
|
+
id: NodeId;
|
|
29
|
+
name?: string;
|
|
30
|
+
handler: (ctx: FlowContext) => Promise<NodeResult>;
|
|
31
|
+
retry?: RetryPolicy;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
idempotencyKey?: (ctx: FlowContext) => string;
|
|
34
|
+
}
|
|
35
|
+
export interface EdgeDefinition {
|
|
36
|
+
from: NodeId;
|
|
37
|
+
to: NodeId;
|
|
38
|
+
when?: (ctx: FlowContext) => boolean;
|
|
39
|
+
priority?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface FlowDefinition {
|
|
42
|
+
flowId: string;
|
|
43
|
+
version: string;
|
|
44
|
+
entry: NodeId;
|
|
45
|
+
nodes: Record<NodeId, NodeDefinition>;
|
|
46
|
+
edges: EdgeDefinition[];
|
|
47
|
+
}
|
|
48
|
+
export type NodeResult = {
|
|
49
|
+
status: 'ok';
|
|
50
|
+
patch?: Record<string, unknown>;
|
|
51
|
+
output?: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
status: 'error';
|
|
54
|
+
error: {
|
|
55
|
+
code: string;
|
|
56
|
+
message: string;
|
|
57
|
+
retryable?: boolean;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
status: 'wait';
|
|
61
|
+
reason?: string;
|
|
62
|
+
until?: string;
|
|
63
|
+
patch?: Record<string, unknown>;
|
|
64
|
+
output?: unknown;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=FlowTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowTypes.d.ts","sourceRoot":"","sources":["../../src/types/FlowTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,iEAAiE;AACjE,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE3E,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,GAAG,aAAa,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACnD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,MAAM,CAAC;CAC/C;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACtC,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GACnE;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC/D,GACD;IACE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC"}
|