@gravito/flux 3.0.1 → 3.0.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.md +329 -8
- package/bin/flux.js +25 -1
- package/dev/viewer/app.js +4 -4
- package/dist/bun.cjs +2 -2
- package/dist/bun.d.cts +65 -26
- package/dist/bun.d.ts +65 -26
- package/dist/bun.js +1 -1
- package/dist/chunk-6AZNHVEO.cjs +316 -0
- package/dist/chunk-6AZNHVEO.cjs.map +1 -0
- package/dist/chunk-DN7SIQ34.cjs +3586 -0
- package/dist/chunk-DN7SIQ34.cjs.map +1 -0
- package/dist/{chunk-ZAMVC732.js → chunk-EZGSU6AW.js} +73 -16
- package/dist/chunk-EZGSU6AW.js.map +1 -0
- package/dist/chunk-M2ZRQRF4.js +3586 -0
- package/dist/chunk-M2ZRQRF4.js.map +1 -0
- package/dist/chunk-WGDTB6OC.js +316 -0
- package/dist/chunk-WGDTB6OC.js.map +1 -0
- package/dist/{chunk-SJSPR4ZU.cjs → chunk-ZE2RDS47.cjs} +75 -18
- package/dist/chunk-ZE2RDS47.cjs.map +1 -0
- package/dist/cli/flux-visualize.cjs +108 -0
- package/dist/cli/flux-visualize.cjs.map +1 -0
- package/dist/cli/flux-visualize.d.cts +1 -0
- package/dist/cli/flux-visualize.d.ts +1 -0
- package/dist/cli/flux-visualize.js +108 -0
- package/dist/cli/flux-visualize.js.map +1 -0
- package/dist/index.cjs +97 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +369 -13
- package/dist/index.d.ts +369 -13
- package/dist/index.js +96 -8
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +11 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +1141 -247
- package/dist/index.node.d.ts +1141 -247
- package/dist/index.node.js +10 -2
- package/dist/types-CGIEQPFv.d.cts +443 -0
- package/dist/types-CGIEQPFv.d.ts +443 -0
- package/package.json +19 -6
- package/dist/chunk-3JGQYHUN.js +0 -1006
- package/dist/chunk-3JGQYHUN.js.map +0 -1
- package/dist/chunk-5OXXH442.cjs +0 -1006
- package/dist/chunk-5OXXH442.cjs.map +0 -1
- package/dist/chunk-SJSPR4ZU.cjs.map +0 -1
- package/dist/chunk-ZAMVC732.js.map +0 -1
- package/dist/types-CZwYGpou.d.cts +0 -353
- package/dist/types-CZwYGpou.d.ts +0 -353
package/dist/bun.d.ts
CHANGED
|
@@ -1,74 +1,113 @@
|
|
|
1
1
|
import { Database } from 'bun:sqlite';
|
|
2
|
-
import {
|
|
2
|
+
import { p as WorkflowStorage, a as WorkflowState, n as WorkflowFilter } from './types-CGIEQPFv.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* High-performance storage using Bun's built-in SQLite.
|
|
8
|
-
*
|
|
9
|
-
* @module @gravito/flux/storage
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* SQLite Storage Options
|
|
5
|
+
* Configuration options for the Bun SQLite storage adapter.
|
|
14
6
|
*/
|
|
15
7
|
interface BunSQLiteStorageOptions {
|
|
16
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Path to the SQLite database file.
|
|
10
|
+
* Use ':memory:' for an ephemeral in-memory database.
|
|
11
|
+
*/
|
|
17
12
|
path?: string;
|
|
18
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Name of the table used to store workflow states.
|
|
15
|
+
*/
|
|
19
16
|
tableName?: string;
|
|
20
17
|
}
|
|
21
18
|
/**
|
|
22
|
-
* Bun SQLite
|
|
19
|
+
* BunSQLiteStorage provides a persistent storage backend for Flux workflows using Bun's native SQLite module.
|
|
23
20
|
*
|
|
24
|
-
*
|
|
21
|
+
* It handles automatic table creation, indexing for performance, and serialization of workflow state
|
|
22
|
+
* into a relational format.
|
|
25
23
|
*
|
|
26
24
|
* @example
|
|
27
25
|
* ```typescript
|
|
28
|
-
* const
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* const storage = new BunSQLiteStorage({
|
|
27
|
+
* path: './workflows.db',
|
|
28
|
+
* tableName: 'my_workflows'
|
|
29
|
+
* });
|
|
30
|
+
* await storage.init();
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare class BunSQLiteStorage implements WorkflowStorage {
|
|
34
34
|
private db;
|
|
35
35
|
private tableName;
|
|
36
36
|
private initialized;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new instance of BunSQLiteStorage.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration for the database connection and table naming.
|
|
41
|
+
*/
|
|
37
42
|
constructor(options?: BunSQLiteStorageOptions);
|
|
38
43
|
/**
|
|
39
|
-
*
|
|
44
|
+
* Initializes the database schema and required indexes.
|
|
45
|
+
*
|
|
46
|
+
* This method is idempotent and will be called automatically by other operations if not invoked manually.
|
|
47
|
+
*
|
|
48
|
+
* @throws {Error} If the database schema cannot be created or indexes fail to initialize.
|
|
40
49
|
*/
|
|
41
50
|
init(): Promise<void>;
|
|
42
51
|
/**
|
|
43
|
-
*
|
|
52
|
+
* Persists or updates a workflow state in the database.
|
|
53
|
+
*
|
|
54
|
+
* Uses an "INSERT OR REPLACE" strategy to ensure the latest state is always stored for a given ID.
|
|
55
|
+
*
|
|
56
|
+
* @param state - The current state of the workflow to be saved.
|
|
57
|
+
* @throws {Error} If the database write operation fails or serialization errors occur.
|
|
44
58
|
*/
|
|
45
59
|
save(state: WorkflowState): Promise<void>;
|
|
46
60
|
/**
|
|
47
|
-
*
|
|
61
|
+
* Retrieves a workflow state by its unique identifier.
|
|
62
|
+
*
|
|
63
|
+
* @param id - The unique ID of the workflow to load.
|
|
64
|
+
* @returns The reconstructed workflow state, or null if no record is found.
|
|
65
|
+
* @throws {Error} If the database query fails or deserialization of stored JSON fails.
|
|
48
66
|
*/
|
|
49
67
|
load(id: string): Promise<WorkflowState | null>;
|
|
50
68
|
/**
|
|
51
|
-
*
|
|
69
|
+
* Lists workflow states based on the provided filtering criteria.
|
|
70
|
+
*
|
|
71
|
+
* Results are returned in descending order of creation time.
|
|
72
|
+
*
|
|
73
|
+
* @param filter - Criteria for filtering and paginating the results.
|
|
74
|
+
* @returns An array of workflow states matching the filter.
|
|
75
|
+
* @throws {Error} If the database query fails.
|
|
52
76
|
*/
|
|
53
77
|
list(filter?: WorkflowFilter): Promise<WorkflowState[]>;
|
|
54
78
|
/**
|
|
55
|
-
*
|
|
79
|
+
* Deletes a workflow state from the database.
|
|
80
|
+
*
|
|
81
|
+
* @param id - The unique ID of the workflow to delete.
|
|
82
|
+
* @throws {Error} If the database deletion fails.
|
|
56
83
|
*/
|
|
57
84
|
delete(id: string): Promise<void>;
|
|
58
85
|
/**
|
|
59
|
-
*
|
|
86
|
+
* Closes the database connection and resets the initialization state.
|
|
87
|
+
*
|
|
88
|
+
* @throws {Error} If the database connection cannot be closed cleanly.
|
|
60
89
|
*/
|
|
61
90
|
close(): Promise<void>;
|
|
62
91
|
/**
|
|
63
|
-
*
|
|
92
|
+
* Converts a raw database row into a structured WorkflowState object.
|
|
93
|
+
*
|
|
94
|
+
* @param row - The raw SQLite row data.
|
|
95
|
+
* @returns The parsed workflow state.
|
|
96
|
+
* @private
|
|
64
97
|
*/
|
|
65
98
|
private rowToState;
|
|
66
99
|
/**
|
|
67
|
-
*
|
|
100
|
+
* Provides direct access to the underlying Bun SQLite Database instance.
|
|
101
|
+
*
|
|
102
|
+
* Useful for performing custom queries or maintenance tasks.
|
|
103
|
+
*
|
|
104
|
+
* @returns The raw Database instance.
|
|
68
105
|
*/
|
|
69
106
|
getDatabase(): Database;
|
|
70
107
|
/**
|
|
71
|
-
*
|
|
108
|
+
* Performs a VACUUM operation to reclaim unused space and defragment the database.
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error} If the VACUUM operation fails.
|
|
72
111
|
*/
|
|
73
112
|
vacuum(): void;
|
|
74
113
|
}
|
package/dist/bun.js
CHANGED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/visualization/MermaidGenerator.ts
|
|
2
|
+
var MermaidGenerator = class {
|
|
3
|
+
/**
|
|
4
|
+
* Generates a Mermaid flowchart from a workflow definition.
|
|
5
|
+
*
|
|
6
|
+
* @param definition - The workflow definition to visualize
|
|
7
|
+
* @param options - Customization options
|
|
8
|
+
* @returns Mermaid diagram syntax as a string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const generator = new MermaidGenerator()
|
|
13
|
+
* const diagram = generator.generateFromDefinition(workflow, {
|
|
14
|
+
* showDetails: true,
|
|
15
|
+
* showParallelGroups: true
|
|
16
|
+
* })
|
|
17
|
+
* console.log(diagram)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
generateFromDefinition(definition, options = {}) {
|
|
21
|
+
const { showDetails = false, showParallelGroups = true, theme = "default" } = options;
|
|
22
|
+
const lines = [];
|
|
23
|
+
lines.push(`%%{init: {'theme':'${theme}'}}%%`);
|
|
24
|
+
lines.push("flowchart TD");
|
|
25
|
+
lines.push(` Start([Start: ${definition.name}])`);
|
|
26
|
+
let prevNode = "Start";
|
|
27
|
+
const parallelGroups = /* @__PURE__ */ new Map();
|
|
28
|
+
if (showParallelGroups) {
|
|
29
|
+
for (const step of definition.steps) {
|
|
30
|
+
if (step.parallelGroup) {
|
|
31
|
+
const group = parallelGroups.get(step.parallelGroup) || [];
|
|
32
|
+
group.push(step.name);
|
|
33
|
+
parallelGroups.set(step.parallelGroup, group);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const processedGroups = /* @__PURE__ */ new Set();
|
|
38
|
+
for (let i = 0; i < definition.steps.length; i++) {
|
|
39
|
+
const step = definition.steps[i];
|
|
40
|
+
if (step.parallelGroup && showParallelGroups) {
|
|
41
|
+
if (processedGroups.has(step.parallelGroup)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
processedGroups.add(step.parallelGroup);
|
|
45
|
+
const groupSteps = parallelGroups.get(step.parallelGroup);
|
|
46
|
+
const groupName = `ParallelGroup_${step.parallelGroup}`;
|
|
47
|
+
lines.push(` subgraph ${groupName}[" "]`);
|
|
48
|
+
lines.push(` direction LR`);
|
|
49
|
+
for (const stepName of groupSteps) {
|
|
50
|
+
const s = definition.steps.find((st) => st.name === stepName);
|
|
51
|
+
const nodeId = this.sanitizeNodeId(stepName);
|
|
52
|
+
const label = this.buildStepLabel(s, showDetails);
|
|
53
|
+
const shape = s.commit ? `[${label}]` : `(${label})`;
|
|
54
|
+
lines.push(` ${nodeId}${shape}`);
|
|
55
|
+
if (s.compensate) {
|
|
56
|
+
lines.push(` ${nodeId}_comp[\u{1F504} Compensate]`);
|
|
57
|
+
lines.push(` ${nodeId} -.->|on failure| ${nodeId}_comp`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
lines.push(` end`);
|
|
61
|
+
lines.push(` ${prevNode} --> ${groupName}`);
|
|
62
|
+
prevNode = groupName;
|
|
63
|
+
} else if (!step.parallelGroup) {
|
|
64
|
+
const nodeId = this.sanitizeNodeId(step.name);
|
|
65
|
+
const label = this.buildStepLabel(step, showDetails);
|
|
66
|
+
const shape = step.commit ? `[${label}]` : `(${label})`;
|
|
67
|
+
lines.push(` ${nodeId}${shape}`);
|
|
68
|
+
if (step.when) {
|
|
69
|
+
const condId = `${nodeId}_cond`;
|
|
70
|
+
lines.push(` ${condId}{Condition?}`);
|
|
71
|
+
lines.push(` ${prevNode} --> ${condId}`);
|
|
72
|
+
lines.push(` ${condId} -->|yes| ${nodeId}`);
|
|
73
|
+
lines.push(` ${condId} -->|no| ${this.getNextNodeId(definition.steps, i)}`);
|
|
74
|
+
prevNode = nodeId;
|
|
75
|
+
} else {
|
|
76
|
+
lines.push(` ${prevNode} --> ${nodeId}`);
|
|
77
|
+
prevNode = nodeId;
|
|
78
|
+
}
|
|
79
|
+
if (step.compensate) {
|
|
80
|
+
lines.push(` ${nodeId}_comp[\u{1F504} Compensate]`);
|
|
81
|
+
lines.push(` ${nodeId} -.->|on failure| ${nodeId}_comp`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
lines.push(` ${prevNode} --> End([End])`);
|
|
86
|
+
lines.push("");
|
|
87
|
+
lines.push(" classDef commitStep fill:#e1f5e1,stroke:#4caf50,stroke-width:2px");
|
|
88
|
+
lines.push(" classDef normalStep fill:#e3f2fd,stroke:#2196f3,stroke-width:2px");
|
|
89
|
+
lines.push(
|
|
90
|
+
" classDef compensateStep fill:#fff3e0,stroke:#ff9800,stroke-width:1px,stroke-dasharray: 5 5"
|
|
91
|
+
);
|
|
92
|
+
return lines.join("\n");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generates a Mermaid flowchart from a workflow execution state.
|
|
96
|
+
* Overlays execution status (completed, failed, compensated) on top of the structure.
|
|
97
|
+
*
|
|
98
|
+
* @param definition - The workflow definition
|
|
99
|
+
* @param state - The current execution state
|
|
100
|
+
* @param options - Customization options
|
|
101
|
+
* @returns Mermaid diagram syntax with status overlay
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const diagram = generator.generateFromState(workflow, executionState, {
|
|
106
|
+
* showStatus: true,
|
|
107
|
+
* showDetails: true
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
generateFromState(definition, state, options = {}) {
|
|
112
|
+
const {
|
|
113
|
+
showDetails = true,
|
|
114
|
+
showStatus = true,
|
|
115
|
+
showParallelGroups = true,
|
|
116
|
+
theme = "default"
|
|
117
|
+
} = options;
|
|
118
|
+
const lines = [];
|
|
119
|
+
lines.push(`%%{init: {'theme':'${theme}'}}%%`);
|
|
120
|
+
lines.push("flowchart TD");
|
|
121
|
+
lines.push(` Start([Start: ${definition.name}])`);
|
|
122
|
+
lines.push(` Start:::started`);
|
|
123
|
+
let prevNode = "Start";
|
|
124
|
+
const parallelGroups = /* @__PURE__ */ new Map();
|
|
125
|
+
const executionMap = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const exec of state.history) {
|
|
127
|
+
executionMap.set(exec.name, exec);
|
|
128
|
+
}
|
|
129
|
+
if (showParallelGroups) {
|
|
130
|
+
for (const step of definition.steps) {
|
|
131
|
+
if (step.parallelGroup) {
|
|
132
|
+
const group = parallelGroups.get(step.parallelGroup) || [];
|
|
133
|
+
group.push(step.name);
|
|
134
|
+
parallelGroups.set(step.parallelGroup, group);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const processedGroups = /* @__PURE__ */ new Set();
|
|
139
|
+
for (let i = 0; i < definition.steps.length; i++) {
|
|
140
|
+
const step = definition.steps[i];
|
|
141
|
+
if (step.parallelGroup && showParallelGroups) {
|
|
142
|
+
if (processedGroups.has(step.parallelGroup)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
processedGroups.add(step.parallelGroup);
|
|
146
|
+
const groupSteps = parallelGroups.get(step.parallelGroup);
|
|
147
|
+
const groupName = `ParallelGroup_${step.parallelGroup}`;
|
|
148
|
+
lines.push(` subgraph ${groupName}[" "]`);
|
|
149
|
+
lines.push(` direction LR`);
|
|
150
|
+
for (const stepName of groupSteps) {
|
|
151
|
+
const s = definition.steps.find((st) => st.name === stepName);
|
|
152
|
+
const nodeId = this.sanitizeNodeId(stepName);
|
|
153
|
+
const exec = executionMap.get(stepName);
|
|
154
|
+
const label = this.buildStepLabelWithStatus(s, exec, showDetails, showStatus);
|
|
155
|
+
const shape = s.commit ? `[${label}]` : `(${label})`;
|
|
156
|
+
lines.push(` ${nodeId}${shape}`);
|
|
157
|
+
if (exec && showStatus) {
|
|
158
|
+
const statusClass = this.getStatusClass(exec.status);
|
|
159
|
+
lines.push(` ${nodeId}:::${statusClass}`);
|
|
160
|
+
}
|
|
161
|
+
if (s.compensate && _optionalChain([exec, 'optionalAccess', _ => _.status]) === "compensated") {
|
|
162
|
+
lines.push(` ${nodeId}_comp[\u{1F504} Compensated]`);
|
|
163
|
+
lines.push(` ${nodeId}_comp:::compensated`);
|
|
164
|
+
lines.push(` ${nodeId} -.->|rolled back| ${nodeId}_comp`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
lines.push(` end`);
|
|
168
|
+
lines.push(` ${prevNode} --> ${groupName}`);
|
|
169
|
+
prevNode = groupName;
|
|
170
|
+
} else if (!step.parallelGroup) {
|
|
171
|
+
const nodeId = this.sanitizeNodeId(step.name);
|
|
172
|
+
const exec = executionMap.get(step.name);
|
|
173
|
+
const label = this.buildStepLabelWithStatus(step, exec, showDetails, showStatus);
|
|
174
|
+
const shape = step.commit ? `[${label}]` : `(${label})`;
|
|
175
|
+
lines.push(` ${nodeId}${shape}`);
|
|
176
|
+
if (exec && showStatus) {
|
|
177
|
+
const statusClass = this.getStatusClass(exec.status);
|
|
178
|
+
lines.push(` ${nodeId}:::${statusClass}`);
|
|
179
|
+
}
|
|
180
|
+
if (step.when) {
|
|
181
|
+
const condId = `${nodeId}_cond`;
|
|
182
|
+
const skipped = _optionalChain([exec, 'optionalAccess', _2 => _2.status]) === "skipped";
|
|
183
|
+
lines.push(` ${condId}{Condition?}`);
|
|
184
|
+
lines.push(` ${prevNode} --> ${condId}`);
|
|
185
|
+
if (skipped) {
|
|
186
|
+
lines.push(` ${condId}:::skipped`);
|
|
187
|
+
lines.push(` ${condId} -->|no| ${nodeId}`);
|
|
188
|
+
} else {
|
|
189
|
+
lines.push(` ${condId} -->|yes| ${nodeId}`);
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
lines.push(` ${prevNode} --> ${nodeId}`);
|
|
193
|
+
}
|
|
194
|
+
if (step.compensate && _optionalChain([exec, 'optionalAccess', _3 => _3.status]) === "compensated") {
|
|
195
|
+
lines.push(` ${nodeId}_comp[\u{1F504} Compensated]`);
|
|
196
|
+
lines.push(` ${nodeId}_comp:::compensated`);
|
|
197
|
+
lines.push(` ${nodeId} -.->|rolled back| ${nodeId}_comp`);
|
|
198
|
+
}
|
|
199
|
+
prevNode = nodeId;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const finalStatus = this.getWorkflowFinalStatus(state.status);
|
|
203
|
+
lines.push(` ${prevNode} --> End([End: ${finalStatus}])`);
|
|
204
|
+
lines.push(` End:::${this.getStatusClass(state.status)}`);
|
|
205
|
+
lines.push("");
|
|
206
|
+
lines.push(" classDef started fill:#e3f2fd,stroke:#2196f3,stroke-width:2px");
|
|
207
|
+
lines.push(" classDef completed fill:#e8f5e9,stroke:#4caf50,stroke-width:2px");
|
|
208
|
+
lines.push(" classDef failed fill:#ffebee,stroke:#f44336,stroke-width:2px");
|
|
209
|
+
lines.push(" classDef compensated fill:#fff3e0,stroke:#ff9800,stroke-width:2px");
|
|
210
|
+
lines.push(
|
|
211
|
+
" classDef skipped fill:#f5f5f5,stroke:#9e9e9e,stroke-width:1px,stroke-dasharray: 5 5"
|
|
212
|
+
);
|
|
213
|
+
lines.push(" classDef pending fill:#fafafa,stroke:#bdbdbd,stroke-width:1px");
|
|
214
|
+
lines.push(
|
|
215
|
+
" classDef suspended fill:#e1f5fe,stroke:#03a9f4,stroke-width:2px,stroke-dasharray: 3 3"
|
|
216
|
+
);
|
|
217
|
+
return lines.join("\n");
|
|
218
|
+
}
|
|
219
|
+
sanitizeNodeId(name) {
|
|
220
|
+
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
221
|
+
}
|
|
222
|
+
buildStepLabel(step, showDetails) {
|
|
223
|
+
let label = step.name;
|
|
224
|
+
if (showDetails) {
|
|
225
|
+
const meta = [];
|
|
226
|
+
if (step.commit) {
|
|
227
|
+
meta.push("\u{1F4DD}");
|
|
228
|
+
}
|
|
229
|
+
if (step.retries && step.retries > 0) {
|
|
230
|
+
meta.push(`\u21BB${step.retries}`);
|
|
231
|
+
}
|
|
232
|
+
if (step.timeout) {
|
|
233
|
+
meta.push(`\u23F1${step.timeout}ms`);
|
|
234
|
+
}
|
|
235
|
+
if (step.when) {
|
|
236
|
+
meta.push("\u2753");
|
|
237
|
+
}
|
|
238
|
+
if (meta.length > 0) {
|
|
239
|
+
label += `<br/><small>${meta.join(" ")}</small>`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return label;
|
|
243
|
+
}
|
|
244
|
+
buildStepLabelWithStatus(step, exec, showDetails, showStatus) {
|
|
245
|
+
let label = step.name;
|
|
246
|
+
if (showStatus && exec) {
|
|
247
|
+
label += `<br/><small><b>${exec.status.toUpperCase()}</b></small>`;
|
|
248
|
+
if (exec.duration) {
|
|
249
|
+
label += `<br/><small>${exec.duration}ms</small>`;
|
|
250
|
+
}
|
|
251
|
+
if (exec.retries > 0) {
|
|
252
|
+
label += `<br/><small>Retries: ${exec.retries}</small>`;
|
|
253
|
+
}
|
|
254
|
+
} else if (showDetails) {
|
|
255
|
+
const meta = [];
|
|
256
|
+
if (step.commit) {
|
|
257
|
+
meta.push("\u{1F4DD}");
|
|
258
|
+
}
|
|
259
|
+
if (step.retries && step.retries > 0) {
|
|
260
|
+
meta.push(`\u21BB${step.retries}`);
|
|
261
|
+
}
|
|
262
|
+
if (step.timeout) {
|
|
263
|
+
meta.push(`\u23F1${step.timeout}ms`);
|
|
264
|
+
}
|
|
265
|
+
if (step.when) {
|
|
266
|
+
meta.push("\u2753");
|
|
267
|
+
}
|
|
268
|
+
if (meta.length > 0) {
|
|
269
|
+
label += `<br/><small>${meta.join(" ")}</small>`;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return label;
|
|
273
|
+
}
|
|
274
|
+
getStatusClass(status) {
|
|
275
|
+
switch (status) {
|
|
276
|
+
case "completed":
|
|
277
|
+
return "completed";
|
|
278
|
+
case "failed":
|
|
279
|
+
return "failed";
|
|
280
|
+
case "compensated":
|
|
281
|
+
case "compensating":
|
|
282
|
+
return "compensated";
|
|
283
|
+
case "skipped":
|
|
284
|
+
return "skipped";
|
|
285
|
+
case "suspended":
|
|
286
|
+
return "suspended";
|
|
287
|
+
case "running":
|
|
288
|
+
return "started";
|
|
289
|
+
default:
|
|
290
|
+
return "pending";
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
getWorkflowFinalStatus(status) {
|
|
294
|
+
switch (status) {
|
|
295
|
+
case "completed":
|
|
296
|
+
return "\u2705 Completed";
|
|
297
|
+
case "failed":
|
|
298
|
+
return "\u274C Failed";
|
|
299
|
+
case "rolled_back":
|
|
300
|
+
return "\u{1F504} Rolled Back";
|
|
301
|
+
case "suspended":
|
|
302
|
+
return "\u23F8 Suspended";
|
|
303
|
+
default:
|
|
304
|
+
return status;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
getNextNodeId(steps, currentIndex) {
|
|
308
|
+
const nextStep = steps[currentIndex + 1];
|
|
309
|
+
return nextStep ? this.sanitizeNodeId(nextStep.name) : "End";
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
exports.MermaidGenerator = MermaidGenerator;
|
|
316
|
+
//# sourceMappingURL=chunk-6AZNHVEO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/chunk-6AZNHVEO.cjs","../src/visualization/MermaidGenerator.ts"],"names":[],"mappings":"AAAA;AC6BO,IAAM,iBAAA,EAAN,MAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AA;AACR,QAAA;AAC9B,MAAA;AACkB,MAAA;AACc,QAAA;AAChC,MAAA;AACe,MAAA;AACA,QAAA;AACf,MAAA;AAEqB,MAAA;AACmB,QAAA;AACxC,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AAME,EAAA;AAEiB,IAAA;AAEO,IAAA;AAC8B,MAAA;AAEjC,MAAA;AACoB,QAAA;AACvC,MAAA;AAEsB,MAAA;AACyB,QAAA;AAC/C,MAAA;AACsB,IAAA;AACE,MAAA;AACP,MAAA;AACD,QAAA;AAChB,MAAA;AACsC,MAAA;AACR,QAAA;AAC9B,MAAA;AACkB,MAAA;AACc,QAAA;AAChC,MAAA;AACe,MAAA;AACA,QAAA;AACf,MAAA;AAEqB,MAAA;AACmB,QAAA;AACxC,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AAE+C,EAAA;AAC7B,IAAA;AACT,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACJ,MAAA;AACA,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACT,MAAA;AACS,QAAA;AACX,IAAA;AACF,EAAA;AAEuD,EAAA;AACrC,IAAA;AACT,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACJ,MAAA;AACI,QAAA;AACT,MAAA;AACS,QAAA;AACX,IAAA;AACF,EAAA;AAEkE,EAAA;AACzB,IAAA;AACgB,IAAA;AACzD,EAAA;AACF;ADzG8D;AACA;AACA;AACA","file":"/Users/carl/Dev/Carl/gravito-core/packages/flux/dist/chunk-6AZNHVEO.cjs","sourcesContent":[null,"import type { StepExecution, WorkflowDefinition, WorkflowState } from '../types'\n\n/**\n * Options for customizing Mermaid diagram generation.\n */\nexport interface MermaidOptions {\n /** Include detailed step information (retries, timeout, conditions). */\n showDetails?: boolean\n /** Include execution history with status colors. */\n showStatus?: boolean\n /** Render parallel groups visually. */\n showParallelGroups?: boolean\n /** Theme: 'default' | 'dark' | 'forest' | 'neutral'. */\n theme?: 'default' | 'dark' | 'forest' | 'neutral'\n}\n\n/**\n * Generates Mermaid flowchart diagrams from workflow definitions and execution states.\n *\n * **Features**:\n * - Workflow structure visualization (steps, parallel groups, conditions)\n * - Execution status overlay (completed, failed, compensated)\n * - Detailed metadata (retries, timeout, commit markers)\n *\n * **Use Cases**:\n * - Documentation generation\n * - Debugging workflow execution\n * - Visual workflow design validation\n */\nexport class MermaidGenerator {\n /**\n * Generates a Mermaid flowchart from a workflow definition.\n *\n * @param definition - The workflow definition to visualize\n * @param options - Customization options\n * @returns Mermaid diagram syntax as a string\n *\n * @example\n * ```typescript\n * const generator = new MermaidGenerator()\n * const diagram = generator.generateFromDefinition(workflow, {\n * showDetails: true,\n * showParallelGroups: true\n * })\n * console.log(diagram)\n * ```\n */\n generateFromDefinition<TInput, TData>(\n definition: WorkflowDefinition<TInput, TData>,\n options: MermaidOptions = {}\n ): string {\n const { showDetails = false, showParallelGroups = true, theme = 'default' } = options\n\n const lines: string[] = []\n lines.push(`%%{init: {'theme':'${theme}'}}%%`)\n lines.push('flowchart TD')\n lines.push(` Start([Start: ${definition.name}])`)\n\n let prevNode = 'Start'\n const parallelGroups = new Map<string, string[]>()\n\n // First pass: identify parallel groups\n if (showParallelGroups) {\n for (const step of definition.steps) {\n if (step.parallelGroup) {\n const group = parallelGroups.get(step.parallelGroup) || []\n group.push(step.name)\n parallelGroups.set(step.parallelGroup, group)\n }\n }\n }\n\n const processedGroups = new Set<string>()\n\n for (let i = 0; i < definition.steps.length; i++) {\n const step = definition.steps[i]!\n\n // Handle parallel groups\n if (step.parallelGroup && showParallelGroups) {\n if (processedGroups.has(step.parallelGroup)) {\n continue // Already processed this group\n }\n processedGroups.add(step.parallelGroup)\n\n const groupSteps = parallelGroups.get(step.parallelGroup)!\n const groupName = `ParallelGroup_${step.parallelGroup}`\n\n // Create subgraph for parallel execution\n lines.push(` subgraph ${groupName}[\" \"]`)\n lines.push(` direction LR`)\n\n for (const stepName of groupSteps) {\n const s = definition.steps.find((st) => st.name === stepName)!\n const nodeId = this.sanitizeNodeId(stepName)\n const label = this.buildStepLabel(s, showDetails)\n const shape = s.commit ? `[${label}]` : `(${label})`\n lines.push(` ${nodeId}${shape}`)\n\n if (s.compensate) {\n lines.push(` ${nodeId}_comp[🔄 Compensate]`)\n lines.push(` ${nodeId} -.->|on failure| ${nodeId}_comp`)\n }\n }\n\n lines.push(` end`)\n lines.push(` ${prevNode} --> ${groupName}`)\n prevNode = groupName\n } else if (!step.parallelGroup) {\n // Regular sequential step\n const nodeId = this.sanitizeNodeId(step.name)\n const label = this.buildStepLabel(step, showDetails)\n const shape = step.commit ? `[${label}]` : `(${label})`\n\n lines.push(` ${nodeId}${shape}`)\n\n // Handle conditional steps\n if (step.when) {\n const condId = `${nodeId}_cond`\n lines.push(` ${condId}{Condition?}`)\n lines.push(` ${prevNode} --> ${condId}`)\n lines.push(` ${condId} -->|yes| ${nodeId}`)\n lines.push(` ${condId} -->|no| ${this.getNextNodeId(definition.steps, i)}`)\n prevNode = nodeId\n } else {\n lines.push(` ${prevNode} --> ${nodeId}`)\n prevNode = nodeId\n }\n\n // Show compensation\n if (step.compensate) {\n lines.push(` ${nodeId}_comp[🔄 Compensate]`)\n lines.push(` ${nodeId} -.->|on failure| ${nodeId}_comp`)\n }\n }\n }\n\n lines.push(` ${prevNode} --> End([End])`)\n\n // Add styling\n lines.push('')\n lines.push(' classDef commitStep fill:#e1f5e1,stroke:#4caf50,stroke-width:2px')\n lines.push(' classDef normalStep fill:#e3f2fd,stroke:#2196f3,stroke-width:2px')\n lines.push(\n ' classDef compensateStep fill:#fff3e0,stroke:#ff9800,stroke-width:1px,stroke-dasharray: 5 5'\n )\n\n return lines.join('\\n')\n }\n\n /**\n * Generates a Mermaid flowchart from a workflow execution state.\n * Overlays execution status (completed, failed, compensated) on top of the structure.\n *\n * @param definition - The workflow definition\n * @param state - The current execution state\n * @param options - Customization options\n * @returns Mermaid diagram syntax with status overlay\n *\n * @example\n * ```typescript\n * const diagram = generator.generateFromState(workflow, executionState, {\n * showStatus: true,\n * showDetails: true\n * })\n * ```\n */\n generateFromState<TInput, TData>(\n definition: WorkflowDefinition<TInput, TData>,\n state: WorkflowState<TInput, TData>,\n options: MermaidOptions = {}\n ): string {\n const {\n showDetails = true,\n showStatus = true,\n showParallelGroups = true,\n theme = 'default',\n } = options\n\n const lines: string[] = []\n lines.push(`%%{init: {'theme':'${theme}'}}%%`)\n lines.push('flowchart TD')\n lines.push(` Start([Start: ${definition.name}])`)\n lines.push(` Start:::started`)\n\n let prevNode = 'Start'\n const parallelGroups = new Map<string, string[]>()\n const executionMap = new Map<string, StepExecution>()\n\n // Build execution map\n for (const exec of state.history) {\n executionMap.set(exec.name, exec)\n }\n\n // Identify parallel groups\n if (showParallelGroups) {\n for (const step of definition.steps) {\n if (step.parallelGroup) {\n const group = parallelGroups.get(step.parallelGroup) || []\n group.push(step.name)\n parallelGroups.set(step.parallelGroup, group)\n }\n }\n }\n\n const processedGroups = new Set<string>()\n\n for (let i = 0; i < definition.steps.length; i++) {\n const step = definition.steps[i]!\n\n // Handle parallel groups\n if (step.parallelGroup && showParallelGroups) {\n if (processedGroups.has(step.parallelGroup)) {\n continue\n }\n processedGroups.add(step.parallelGroup)\n\n const groupSteps = parallelGroups.get(step.parallelGroup)!\n const groupName = `ParallelGroup_${step.parallelGroup}`\n\n lines.push(` subgraph ${groupName}[\" \"]`)\n lines.push(` direction LR`)\n\n for (const stepName of groupSteps) {\n const s = definition.steps.find((st) => st.name === stepName)!\n const nodeId = this.sanitizeNodeId(stepName)\n const exec = executionMap.get(stepName)\n const label = this.buildStepLabelWithStatus(s, exec, showDetails, showStatus)\n const shape = s.commit ? `[${label}]` : `(${label})`\n\n lines.push(` ${nodeId}${shape}`)\n\n if (exec && showStatus) {\n const statusClass = this.getStatusClass(exec.status)\n lines.push(` ${nodeId}:::${statusClass}`)\n }\n\n if (s.compensate && exec?.status === 'compensated') {\n lines.push(` ${nodeId}_comp[🔄 Compensated]`)\n lines.push(` ${nodeId}_comp:::compensated`)\n lines.push(` ${nodeId} -.->|rolled back| ${nodeId}_comp`)\n }\n }\n\n lines.push(` end`)\n lines.push(` ${prevNode} --> ${groupName}`)\n prevNode = groupName\n } else if (!step.parallelGroup) {\n const nodeId = this.sanitizeNodeId(step.name)\n const exec = executionMap.get(step.name)\n const label = this.buildStepLabelWithStatus(step, exec, showDetails, showStatus)\n const shape = step.commit ? `[${label}]` : `(${label})`\n\n lines.push(` ${nodeId}${shape}`)\n\n if (exec && showStatus) {\n const statusClass = this.getStatusClass(exec.status)\n lines.push(` ${nodeId}:::${statusClass}`)\n }\n\n if (step.when) {\n const condId = `${nodeId}_cond`\n const skipped = exec?.status === 'skipped'\n lines.push(` ${condId}{Condition?}`)\n lines.push(` ${prevNode} --> ${condId}`)\n\n if (skipped) {\n lines.push(` ${condId}:::skipped`)\n lines.push(` ${condId} -->|no| ${nodeId}`)\n } else {\n lines.push(` ${condId} -->|yes| ${nodeId}`)\n }\n } else {\n lines.push(` ${prevNode} --> ${nodeId}`)\n }\n\n if (step.compensate && exec?.status === 'compensated') {\n lines.push(` ${nodeId}_comp[🔄 Compensated]`)\n lines.push(` ${nodeId}_comp:::compensated`)\n lines.push(` ${nodeId} -.->|rolled back| ${nodeId}_comp`)\n }\n\n prevNode = nodeId\n }\n }\n\n const finalStatus = this.getWorkflowFinalStatus(state.status)\n lines.push(` ${prevNode} --> End([End: ${finalStatus}])`)\n lines.push(` End:::${this.getStatusClass(state.status)}`)\n\n // Add status-based styling\n lines.push('')\n lines.push(' classDef started fill:#e3f2fd,stroke:#2196f3,stroke-width:2px')\n lines.push(' classDef completed fill:#e8f5e9,stroke:#4caf50,stroke-width:2px')\n lines.push(' classDef failed fill:#ffebee,stroke:#f44336,stroke-width:2px')\n lines.push(' classDef compensated fill:#fff3e0,stroke:#ff9800,stroke-width:2px')\n lines.push(\n ' classDef skipped fill:#f5f5f5,stroke:#9e9e9e,stroke-width:1px,stroke-dasharray: 5 5'\n )\n lines.push(' classDef pending fill:#fafafa,stroke:#bdbdbd,stroke-width:1px')\n lines.push(\n ' classDef suspended fill:#e1f5fe,stroke:#03a9f4,stroke-width:2px,stroke-dasharray: 3 3'\n )\n\n return lines.join('\\n')\n }\n\n private sanitizeNodeId(name: string): string {\n return name.replace(/[^a-zA-Z0-9_]/g, '_')\n }\n\n private buildStepLabel(step: any, showDetails: boolean): string {\n let label = step.name\n\n if (showDetails) {\n const meta: string[] = []\n if (step.commit) {\n meta.push('📝')\n }\n if (step.retries && step.retries > 0) {\n meta.push(`↻${step.retries}`)\n }\n if (step.timeout) {\n meta.push(`⏱${step.timeout}ms`)\n }\n if (step.when) {\n meta.push('❓')\n }\n\n if (meta.length > 0) {\n label += `<br/><small>${meta.join(' ')}</small>`\n }\n }\n\n return label\n }\n\n private buildStepLabelWithStatus(\n step: any,\n exec: StepExecution | undefined,\n showDetails: boolean,\n showStatus: boolean\n ): string {\n let label = step.name\n\n if (showStatus && exec) {\n label += `<br/><small><b>${exec.status.toUpperCase()}</b></small>`\n\n if (exec.duration) {\n label += `<br/><small>${exec.duration}ms</small>`\n }\n\n if (exec.retries > 0) {\n label += `<br/><small>Retries: ${exec.retries}</small>`\n }\n } else if (showDetails) {\n const meta: string[] = []\n if (step.commit) {\n meta.push('📝')\n }\n if (step.retries && step.retries > 0) {\n meta.push(`↻${step.retries}`)\n }\n if (step.timeout) {\n meta.push(`⏱${step.timeout}ms`)\n }\n if (step.when) {\n meta.push('❓')\n }\n\n if (meta.length > 0) {\n label += `<br/><small>${meta.join(' ')}</small>`\n }\n }\n\n return label\n }\n\n private getStatusClass(status: string): string {\n switch (status) {\n case 'completed':\n return 'completed'\n case 'failed':\n return 'failed'\n case 'compensated':\n case 'compensating':\n return 'compensated'\n case 'skipped':\n return 'skipped'\n case 'suspended':\n return 'suspended'\n case 'running':\n return 'started'\n default:\n return 'pending'\n }\n }\n\n private getWorkflowFinalStatus(status: string): string {\n switch (status) {\n case 'completed':\n return '✅ Completed'\n case 'failed':\n return '❌ Failed'\n case 'rolled_back':\n return '🔄 Rolled Back'\n case 'suspended':\n return '⏸ Suspended'\n default:\n return status\n }\n }\n\n private getNextNodeId(steps: any[], currentIndex: number): string {\n const nextStep = steps[currentIndex + 1]\n return nextStep ? this.sanitizeNodeId(nextStep.name) : 'End'\n }\n}\n"]}
|