@coral-viz/viz 0.2.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/LICENSE +4 -0
- package/README.md +11 -0
- package/dist/compatibility/CompatibilityEdge.d.ts +106 -0
- package/dist/compatibility/CompatibilityEdge.d.ts.map +1 -0
- package/dist/compatibility/CompatibilityEdge.js +233 -0
- package/dist/compatibility/CompatibilityEdge.js.map +1 -0
- package/dist/compatibility/IncompatibilityTooltip.d.ts +44 -0
- package/dist/compatibility/IncompatibilityTooltip.d.ts.map +1 -0
- package/dist/compatibility/IncompatibilityTooltip.js +145 -0
- package/dist/compatibility/IncompatibilityTooltip.js.map +1 -0
- package/dist/compatibility/index.d.ts +10 -0
- package/dist/compatibility/index.d.ts.map +1 -0
- package/dist/compatibility/index.js +10 -0
- package/dist/compatibility/index.js.map +1 -0
- package/dist/compatibility/useEdgeCompatibility.d.ts +82 -0
- package/dist/compatibility/useEdgeCompatibility.d.ts.map +1 -0
- package/dist/compatibility/useEdgeCompatibility.js +170 -0
- package/dist/compatibility/useEdgeCompatibility.js.map +1 -0
- package/dist/compatibility/validateConnection.d.ts +56 -0
- package/dist/compatibility/validateConnection.d.ts.map +1 -0
- package/dist/compatibility/validateConnection.js +382 -0
- package/dist/compatibility/validateConnection.js.map +1 -0
- package/dist/components/EditContext.d.ts +45 -0
- package/dist/components/EditContext.d.ts.map +1 -0
- package/dist/components/EditContext.js +41 -0
- package/dist/components/EditContext.js.map +1 -0
- package/dist/components/ShapeRenderer.d.ts +35 -0
- package/dist/components/ShapeRenderer.d.ts.map +1 -0
- package/dist/components/ShapeRenderer.js +77 -0
- package/dist/components/ShapeRenderer.js.map +1 -0
- package/dist/components/SymbolNode.d.ts +53 -0
- package/dist/components/SymbolNode.d.ts.map +1 -0
- package/dist/components/SymbolNode.js +333 -0
- package/dist/components/SymbolNode.js.map +1 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +10 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/nodes.d.ts +43 -0
- package/dist/components/nodes.d.ts.map +1 -0
- package/dist/components/nodes.js +111 -0
- package/dist/components/nodes.js.map +1 -0
- package/dist/editor/CoralEditor.d.ts +29 -0
- package/dist/editor/CoralEditor.d.ts.map +1 -0
- package/dist/editor/CoralEditor.js +112 -0
- package/dist/editor/CoralEditor.js.map +1 -0
- package/dist/editor/FileControls.d.ts +34 -0
- package/dist/editor/FileControls.d.ts.map +1 -0
- package/dist/editor/FileControls.js +139 -0
- package/dist/editor/FileControls.js.map +1 -0
- package/dist/editor/LayoutControls.d.ts +41 -0
- package/dist/editor/LayoutControls.d.ts.map +1 -0
- package/dist/editor/LayoutControls.js +124 -0
- package/dist/editor/LayoutControls.js.map +1 -0
- package/dist/editor/converter.d.ts +37 -0
- package/dist/editor/converter.d.ts.map +1 -0
- package/dist/editor/converter.js +256 -0
- package/dist/editor/converter.js.map +1 -0
- package/dist/editor/index.d.ts +8 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +8 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/file/deserialize.d.ts +15 -0
- package/dist/file/deserialize.d.ts.map +1 -0
- package/dist/file/deserialize.js +145 -0
- package/dist/file/deserialize.js.map +1 -0
- package/dist/file/index.d.ts +15 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +20 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/migrate.d.ts +29 -0
- package/dist/file/migrate.d.ts.map +1 -0
- package/dist/file/migrate.js +103 -0
- package/dist/file/migrate.js.map +1 -0
- package/dist/file/schema.d.ts +385 -0
- package/dist/file/schema.d.ts.map +1 -0
- package/dist/file/schema.js +180 -0
- package/dist/file/schema.js.map +1 -0
- package/dist/file/serialize.d.ts +30 -0
- package/dist/file/serialize.d.ts.map +1 -0
- package/dist/file/serialize.js +218 -0
- package/dist/file/serialize.js.map +1 -0
- package/dist/file/validate.d.ts +21 -0
- package/dist/file/validate.d.ts.map +1 -0
- package/dist/file/validate.js +165 -0
- package/dist/file/validate.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/elk.d.ts +77 -0
- package/dist/layout/elk.d.ts.map +1 -0
- package/dist/layout/elk.js +379 -0
- package/dist/layout/elk.js.map +1 -0
- package/dist/layout/index.d.ts +12 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +12 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/nodeSizing.d.ts +65 -0
- package/dist/layout/nodeSizing.d.ts.map +1 -0
- package/dist/layout/nodeSizing.js +319 -0
- package/dist/layout/nodeSizing.js.map +1 -0
- package/dist/layout/positionStability.d.ts +73 -0
- package/dist/layout/positionStability.d.ts.map +1 -0
- package/dist/layout/positionStability.js +199 -0
- package/dist/layout/positionStability.js.map +1 -0
- package/dist/layout/useAxisConstrain.d.ts +20 -0
- package/dist/layout/useAxisConstrain.d.ts.map +1 -0
- package/dist/layout/useAxisConstrain.js +106 -0
- package/dist/layout/useAxisConstrain.js.map +1 -0
- package/dist/layout/useDiagramState.d.ts +92 -0
- package/dist/layout/useDiagramState.d.ts.map +1 -0
- package/dist/layout/useDiagramState.js +256 -0
- package/dist/layout/useDiagramState.js.map +1 -0
- package/dist/layout/useLayoutHistory.d.ts +53 -0
- package/dist/layout/useLayoutHistory.d.ts.map +1 -0
- package/dist/layout/useLayoutHistory.js +124 -0
- package/dist/layout/useLayoutHistory.js.map +1 -0
- package/dist/properties/NodePropertiesPanel.d.ts +47 -0
- package/dist/properties/NodePropertiesPanel.d.ts.map +1 -0
- package/dist/properties/NodePropertiesPanel.js +199 -0
- package/dist/properties/NodePropertiesPanel.js.map +1 -0
- package/dist/properties/index.d.ts +10 -0
- package/dist/properties/index.d.ts.map +1 -0
- package/dist/properties/index.js +10 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/propertyUtils.d.ts +60 -0
- package/dist/properties/propertyUtils.d.ts.map +1 -0
- package/dist/properties/propertyUtils.js +89 -0
- package/dist/properties/propertyUtils.js.map +1 -0
- package/dist/settings/FontSettingsForm.d.ts +28 -0
- package/dist/settings/FontSettingsForm.d.ts.map +1 -0
- package/dist/settings/FontSettingsForm.js +129 -0
- package/dist/settings/FontSettingsForm.js.map +1 -0
- package/dist/settings/LayoutSettingsForm.d.ts +37 -0
- package/dist/settings/LayoutSettingsForm.d.ts.map +1 -0
- package/dist/settings/LayoutSettingsForm.js +165 -0
- package/dist/settings/LayoutSettingsForm.js.map +1 -0
- package/dist/settings/SettingsPanel.d.ts +55 -0
- package/dist/settings/SettingsPanel.d.ts.map +1 -0
- package/dist/settings/SettingsPanel.js +84 -0
- package/dist/settings/SettingsPanel.js.map +1 -0
- package/dist/settings/index.d.ts +13 -0
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +13 -0
- package/dist/settings/index.js.map +1 -0
- package/dist/settings/useSettings.d.ts +51 -0
- package/dist/settings/useSettings.d.ts.map +1 -0
- package/dist/settings/useSettings.js +154 -0
- package/dist/settings/useSettings.js.map +1 -0
- package/dist/text-editor/SplitEditor.d.ts +72 -0
- package/dist/text-editor/SplitEditor.d.ts.map +1 -0
- package/dist/text-editor/SplitEditor.js +172 -0
- package/dist/text-editor/SplitEditor.js.map +1 -0
- package/dist/text-editor/TextEditor.d.ts +53 -0
- package/dist/text-editor/TextEditor.d.ts.map +1 -0
- package/dist/text-editor/TextEditor.js +181 -0
- package/dist/text-editor/TextEditor.js.map +1 -0
- package/dist/text-editor/hooks/useBidirectionalSync.d.ts +106 -0
- package/dist/text-editor/hooks/useBidirectionalSync.d.ts.map +1 -0
- package/dist/text-editor/hooks/useBidirectionalSync.js +151 -0
- package/dist/text-editor/hooks/useBidirectionalSync.js.map +1 -0
- package/dist/text-editor/index.d.ts +9 -0
- package/dist/text-editor/index.d.ts.map +1 -0
- package/dist/text-editor/index.js +11 -0
- package/dist/text-editor/index.js.map +1 -0
- package/dist/types.d.ts +242 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/waypoints/index.d.ts +8 -0
- package/dist/waypoints/index.d.ts.map +1 -0
- package/dist/waypoints/index.js +7 -0
- package/dist/waypoints/index.js.map +1 -0
- package/dist/waypoints/operations.d.ts +29 -0
- package/dist/waypoints/operations.d.ts.map +1 -0
- package/dist/waypoints/operations.js +85 -0
- package/dist/waypoints/operations.js.map +1 -0
- package/dist/waypoints/router.d.ts +23 -0
- package/dist/waypoints/router.d.ts.map +1 -0
- package/dist/waypoints/router.js +109 -0
- package/dist/waypoints/router.js.map +1 -0
- package/dist/waypoints/types.d.ts +15 -0
- package/dist/waypoints/types.d.ts.map +1 -0
- package/dist/waypoints/types.js +5 -0
- package/dist/waypoints/types.js.map +1 -0
- package/dist/waypoints/useWaypointManager.d.ts +38 -0
- package/dist/waypoints/useWaypointManager.d.ts.map +1 -0
- package/dist/waypoints/useWaypointManager.js +106 -0
- package/dist/waypoints/useWaypointManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph-IR to React Flow Converter
|
|
3
|
+
*
|
|
4
|
+
* Transforms Graph-IR nodes and edges to React Flow format.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default node dimensions by type
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_DIMENSIONS = {
|
|
10
|
+
service: { width: 150, height: 50 },
|
|
11
|
+
database: { width: 120, height: 60 },
|
|
12
|
+
external_api: { width: 140, height: 50 },
|
|
13
|
+
actor: { width: 100, height: 100 },
|
|
14
|
+
module: { width: 120, height: 40 },
|
|
15
|
+
group: { width: 200, height: 150 },
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Map Graph-IR node type to React Flow node type
|
|
19
|
+
*/
|
|
20
|
+
function mapNodeType(graphType) {
|
|
21
|
+
switch (graphType) {
|
|
22
|
+
case 'service':
|
|
23
|
+
return 'coralService';
|
|
24
|
+
case 'database':
|
|
25
|
+
return 'coralDatabase';
|
|
26
|
+
case 'external_api':
|
|
27
|
+
return 'coralExternalApi';
|
|
28
|
+
case 'actor':
|
|
29
|
+
return 'coralActor';
|
|
30
|
+
case 'module':
|
|
31
|
+
return 'coralModule';
|
|
32
|
+
case 'group':
|
|
33
|
+
return 'coralGroup';
|
|
34
|
+
default:
|
|
35
|
+
return 'coralService';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert a Graph-IR node to React Flow node
|
|
40
|
+
*/
|
|
41
|
+
export function convertNode(node, index, parentId) {
|
|
42
|
+
const dimensions = node.dimensions || DEFAULT_DIMENSIONS[node.type] || DEFAULT_DIMENSIONS.service;
|
|
43
|
+
const hasChildren = node.children && node.children.length > 0;
|
|
44
|
+
const data = {
|
|
45
|
+
label: node.label || node.id,
|
|
46
|
+
nodeType: node.type,
|
|
47
|
+
description: node.description,
|
|
48
|
+
properties: node.properties,
|
|
49
|
+
pinned: node.pinned,
|
|
50
|
+
symbolId: node.symbol,
|
|
51
|
+
variant: node.variant,
|
|
52
|
+
isGroup: hasChildren || node.type === 'group',
|
|
53
|
+
childCount: node.children?.length,
|
|
54
|
+
canonical: {
|
|
55
|
+
...(node.symbol !== undefined ? { symbol: node.symbol } : {}),
|
|
56
|
+
...(node.variant !== undefined ? { variant: node.variant } : {}),
|
|
57
|
+
...(node.parent !== undefined ? { parent: node.parent } : {}),
|
|
58
|
+
...(node.ports !== undefined ? { ports: node.ports } : {}),
|
|
59
|
+
...(node.dimensions !== undefined ? { dimensions: node.dimensions } : {}),
|
|
60
|
+
...(node.layoutOptions !== undefined ? { layoutOptions: node.layoutOptions } : {}),
|
|
61
|
+
...(node.sourceInfo !== undefined ? { sourceInfo: node.sourceInfo } : {}),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const flowNode = {
|
|
65
|
+
id: node.id,
|
|
66
|
+
type: mapNodeType(node.type),
|
|
67
|
+
position: node.position || { x: index * 200, y: index * 100 },
|
|
68
|
+
draggable: !node.pinned,
|
|
69
|
+
data,
|
|
70
|
+
style: {
|
|
71
|
+
width: dimensions.width,
|
|
72
|
+
height: dimensions.height,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
// If this node has a parent, set it
|
|
76
|
+
if (parentId) {
|
|
77
|
+
flowNode.parentId = parentId;
|
|
78
|
+
flowNode.extent = 'parent';
|
|
79
|
+
}
|
|
80
|
+
// For group nodes, mark as expandable
|
|
81
|
+
if (hasChildren) {
|
|
82
|
+
flowNode.style = {
|
|
83
|
+
...flowNode.style,
|
|
84
|
+
width: Math.max(dimensions.width, 250),
|
|
85
|
+
height: Math.max(dimensions.height, 200),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return flowNode;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Flatten nested nodes for React Flow
|
|
92
|
+
* React Flow doesn't support deeply nested nodes well, so we flatten
|
|
93
|
+
* and use parentId for grouping
|
|
94
|
+
*/
|
|
95
|
+
export function flattenNodes(nodes) {
|
|
96
|
+
const result = [];
|
|
97
|
+
let index = 0;
|
|
98
|
+
function processNode(node, parentId) {
|
|
99
|
+
result.push(convertNode(node, index++, parentId));
|
|
100
|
+
if (node.children) {
|
|
101
|
+
for (const child of node.children) {
|
|
102
|
+
processNode(child, node.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const node of nodes) {
|
|
107
|
+
processNode(node);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convert a Graph-IR edge to React Flow edge
|
|
113
|
+
*/
|
|
114
|
+
export function convertEdge(edge) {
|
|
115
|
+
const data = {
|
|
116
|
+
label: edge.label,
|
|
117
|
+
edgeType: edge.type,
|
|
118
|
+
properties: edge.properties,
|
|
119
|
+
lineStyle: edge.style?.lineStyle,
|
|
120
|
+
routingPoints: edge.routingPoints,
|
|
121
|
+
canonical: {
|
|
122
|
+
...(edge.style !== undefined ? { style: edge.style } : {}),
|
|
123
|
+
...(edge.sourceInfo !== undefined ? { sourceInfo: edge.sourceInfo } : {}),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const flowEdge = {
|
|
127
|
+
id: edge.id,
|
|
128
|
+
source: edge.source,
|
|
129
|
+
target: edge.target,
|
|
130
|
+
data,
|
|
131
|
+
label: edge.label,
|
|
132
|
+
type: 'smoothstep', // Default edge type
|
|
133
|
+
};
|
|
134
|
+
// Apply edge style
|
|
135
|
+
if (edge.style) {
|
|
136
|
+
flowEdge.style = {};
|
|
137
|
+
if (edge.style.lineStyle === 'dashed') {
|
|
138
|
+
flowEdge.style.strokeDasharray = '5,5';
|
|
139
|
+
}
|
|
140
|
+
else if (edge.style.lineStyle === 'dotted') {
|
|
141
|
+
flowEdge.style.strokeDasharray = '2,2';
|
|
142
|
+
}
|
|
143
|
+
if (edge.style.targetArrow === 'none') {
|
|
144
|
+
flowEdge.markerEnd = undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Handle source/target ports
|
|
148
|
+
if (edge.sourcePort) {
|
|
149
|
+
flowEdge.sourceHandle = edge.sourcePort;
|
|
150
|
+
}
|
|
151
|
+
if (edge.targetPort) {
|
|
152
|
+
flowEdge.targetHandle = edge.targetPort;
|
|
153
|
+
}
|
|
154
|
+
return flowEdge;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Convert entire Graph-IR to React Flow format
|
|
158
|
+
*/
|
|
159
|
+
export function convertGraphToFlow(graph) {
|
|
160
|
+
const nodes = flattenNodes(graph.nodes);
|
|
161
|
+
const edges = graph.edges.map(convertEdge);
|
|
162
|
+
return { nodes, edges };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Convert React Flow nodes back to Graph-IR nodes
|
|
166
|
+
* Used for bidirectional sync
|
|
167
|
+
*/
|
|
168
|
+
export function convertFlowToGraphNodes(flowNodes, originalNodes) {
|
|
169
|
+
// Build a map of original nodes for reference
|
|
170
|
+
const originalMap = new Map();
|
|
171
|
+
function mapOriginal(nodes) {
|
|
172
|
+
for (const node of nodes) {
|
|
173
|
+
originalMap.set(node.id, node);
|
|
174
|
+
if (node.children) {
|
|
175
|
+
mapOriginal(node.children);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
mapOriginal(originalNodes);
|
|
180
|
+
// Build result maintaining hierarchy
|
|
181
|
+
const result = [];
|
|
182
|
+
const childMap = new Map();
|
|
183
|
+
// First pass: convert all nodes
|
|
184
|
+
for (const flowNode of flowNodes) {
|
|
185
|
+
const original = originalMap.get(flowNode.id);
|
|
186
|
+
const canonical = flowNode.data.canonical;
|
|
187
|
+
const graphNode = {
|
|
188
|
+
...canonical,
|
|
189
|
+
id: flowNode.id,
|
|
190
|
+
type: flowNode.data.nodeType,
|
|
191
|
+
label: flowNode.data.label,
|
|
192
|
+
description: flowNode.data.description,
|
|
193
|
+
properties: flowNode.data.properties,
|
|
194
|
+
position: flowNode.position,
|
|
195
|
+
pinned: flowNode.data.pinned ?? original?.pinned,
|
|
196
|
+
dimensions: (typeof flowNode.width === 'number' && typeof flowNode.height === 'number')
|
|
197
|
+
? { width: flowNode.width, height: flowNode.height }
|
|
198
|
+
: canonical?.dimensions,
|
|
199
|
+
};
|
|
200
|
+
if (flowNode.parentId) {
|
|
201
|
+
graphNode.parent = flowNode.parentId;
|
|
202
|
+
if (!childMap.has(flowNode.parentId)) {
|
|
203
|
+
childMap.set(flowNode.parentId, []);
|
|
204
|
+
}
|
|
205
|
+
childMap.get(flowNode.parentId).push(graphNode);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
result.push(graphNode);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Second pass: attach children
|
|
212
|
+
function attachChildren(nodes) {
|
|
213
|
+
for (const node of nodes) {
|
|
214
|
+
const children = childMap.get(node.id);
|
|
215
|
+
if (children) {
|
|
216
|
+
node.children = children;
|
|
217
|
+
attachChildren(children);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
attachChildren(result);
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Convert React Flow edges back to Graph-IR edges
|
|
226
|
+
*/
|
|
227
|
+
export function convertFlowToGraphEdges(flowEdges) {
|
|
228
|
+
return flowEdges.map(flowEdge => {
|
|
229
|
+
const canonical = flowEdge.data?.canonical;
|
|
230
|
+
const graphEdge = {
|
|
231
|
+
...canonical,
|
|
232
|
+
id: flowEdge.id,
|
|
233
|
+
source: flowEdge.source,
|
|
234
|
+
target: flowEdge.target,
|
|
235
|
+
label: flowEdge.data?.label,
|
|
236
|
+
type: flowEdge.data?.edgeType,
|
|
237
|
+
properties: flowEdge.data?.properties,
|
|
238
|
+
routingPoints: flowEdge.data?.routingPoints,
|
|
239
|
+
};
|
|
240
|
+
if (flowEdge.sourceHandle) {
|
|
241
|
+
graphEdge.sourcePort = flowEdge.sourceHandle;
|
|
242
|
+
}
|
|
243
|
+
if (flowEdge.targetHandle) {
|
|
244
|
+
graphEdge.targetPort = flowEdge.targetHandle;
|
|
245
|
+
}
|
|
246
|
+
const lineStyle = flowEdge.data?.lineStyle
|
|
247
|
+
?? (flowEdge.style?.strokeDasharray
|
|
248
|
+
? (String(flowEdge.style.strokeDasharray).includes('2') ? 'dotted' : 'dashed')
|
|
249
|
+
: undefined);
|
|
250
|
+
if (lineStyle || canonical?.style) {
|
|
251
|
+
graphEdge.style = { ...canonical?.style, ...(lineStyle ? { lineStyle } : {}) };
|
|
252
|
+
}
|
|
253
|
+
return graphEdge;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.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,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ;YAC7B,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU;YACrC,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE,aAAa;SAC5C,CAAC;QAEF,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/C,CAAC;QACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/C,CAAC;QAED,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS;eACrC,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe;gBACjC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC9E,CAAC,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,SAAS,IAAI,SAAS,EAAE,KAAK,EAAE,CAAC;YAClC,SAAS,CAAC,KAAK,GAAG,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QACjF,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Visual Editor
|
|
3
|
+
*/
|
|
4
|
+
export { CoralEditor, useGraphIR, type CoralEditorProps } from './CoralEditor.js';
|
|
5
|
+
export { convertGraphToFlow, convertNode, convertEdge, flattenNodes, convertFlowToGraphNodes, convertFlowToGraphEdges, } from './converter.js';
|
|
6
|
+
export { LayoutControls, type LayoutControlsProps } from './LayoutControls.js';
|
|
7
|
+
export { FileControls, type FileControlsProps } from './FileControls.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Visual Editor
|
|
3
|
+
*/
|
|
4
|
+
export { CoralEditor, useGraphIR } from './CoralEditor.js';
|
|
5
|
+
export { convertGraphToFlow, convertNode, convertEdge, flattenNodes, convertFlowToGraphNodes, convertFlowToGraphEdges, } from './converter.js';
|
|
6
|
+
export { LayoutControls } from './LayoutControls.js';
|
|
7
|
+
export { FileControls } from './FileControls.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAA0B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Document Deserialization (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Converts CoralDocument to React Flow nodes/edges.
|
|
5
|
+
*/
|
|
6
|
+
import type { CoralDocument, DeserializeResult } from './schema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Deserialize a CoralDocument to React Flow nodes and edges
|
|
9
|
+
*
|
|
10
|
+
* @param doc - CoralDocument to deserialize
|
|
11
|
+
* @returns Deserialized nodes, edges, settings, and metadata
|
|
12
|
+
* @throws Error if document is invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function deserialize(doc: CoralDocument): DeserializeResult;
|
|
15
|
+
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../src/file/deserialize.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAgB,MAAM,aAAa,CAAC;AAuGlF;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,iBAAiB,CAoDjE"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Document Deserialization (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Converts CoralDocument to React Flow nodes/edges.
|
|
5
|
+
*/
|
|
6
|
+
import { assertValidDocument } from './validate.js';
|
|
7
|
+
import { migrateDocument } from './migrate.js';
|
|
8
|
+
/**
|
|
9
|
+
* Default position for nodes without positions
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_POSITION = { x: 0, y: 0 };
|
|
12
|
+
/**
|
|
13
|
+
* Convert a GraphNode to a CoralNode
|
|
14
|
+
*/
|
|
15
|
+
function graphNodeToNode(graphNode, positions) {
|
|
16
|
+
const position = positions[graphNode.id] ?? graphNode.position ?? DEFAULT_POSITION;
|
|
17
|
+
return {
|
|
18
|
+
id: graphNode.id,
|
|
19
|
+
type: graphNode.type,
|
|
20
|
+
position: { x: position.x, y: position.y },
|
|
21
|
+
parentId: graphNode.parent,
|
|
22
|
+
draggable: !graphNode.pinned,
|
|
23
|
+
data: {
|
|
24
|
+
label: graphNode.label ?? graphNode.id,
|
|
25
|
+
nodeType: graphNode.type,
|
|
26
|
+
description: graphNode.description,
|
|
27
|
+
properties: graphNode.properties,
|
|
28
|
+
pinned: graphNode.pinned,
|
|
29
|
+
symbolId: graphNode.symbol,
|
|
30
|
+
variant: graphNode.variant,
|
|
31
|
+
isGroup: graphNode.children && graphNode.children.length > 0,
|
|
32
|
+
childCount: graphNode.children?.length,
|
|
33
|
+
canonical: {
|
|
34
|
+
...(graphNode.symbol !== undefined ? { symbol: graphNode.symbol } : {}),
|
|
35
|
+
...(graphNode.variant !== undefined ? { variant: graphNode.variant } : {}),
|
|
36
|
+
...(graphNode.parent !== undefined ? { parent: graphNode.parent } : {}),
|
|
37
|
+
...(graphNode.ports !== undefined ? { ports: graphNode.ports } : {}),
|
|
38
|
+
...(graphNode.dimensions !== undefined ? { dimensions: graphNode.dimensions } : {}),
|
|
39
|
+
...(graphNode.layoutOptions !== undefined ? { layoutOptions: graphNode.layoutOptions } : {}),
|
|
40
|
+
...(graphNode.sourceInfo !== undefined ? { sourceInfo: graphNode.sourceInfo } : {}),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
...(graphNode.dimensions && {
|
|
44
|
+
width: graphNode.dimensions.width,
|
|
45
|
+
height: graphNode.dimensions.height,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert a GraphEdge to a CoralEdge
|
|
51
|
+
*/
|
|
52
|
+
function graphEdgeToEdge(graphEdge) {
|
|
53
|
+
return {
|
|
54
|
+
id: graphEdge.id,
|
|
55
|
+
source: graphEdge.source,
|
|
56
|
+
target: graphEdge.target,
|
|
57
|
+
sourceHandle: graphEdge.sourcePort ?? null,
|
|
58
|
+
targetHandle: graphEdge.targetPort ?? null,
|
|
59
|
+
type: graphEdge.style?.lineStyle === 'dashed' ? 'dashed' : undefined,
|
|
60
|
+
label: graphEdge.label,
|
|
61
|
+
data: {
|
|
62
|
+
label: graphEdge.label,
|
|
63
|
+
edgeType: graphEdge.type,
|
|
64
|
+
properties: graphEdge.properties,
|
|
65
|
+
lineStyle: graphEdge.style?.lineStyle,
|
|
66
|
+
routingPoints: graphEdge.routingPoints,
|
|
67
|
+
canonical: {
|
|
68
|
+
...(graphEdge.style !== undefined ? { style: graphEdge.style } : {}),
|
|
69
|
+
...(graphEdge.sourceInfo !== undefined ? { sourceInfo: graphEdge.sourceInfo } : {}),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Flatten nested nodes (Graph-IR can have children, React Flow uses parentId)
|
|
76
|
+
*/
|
|
77
|
+
function flattenGraphNodes(nodes) {
|
|
78
|
+
const result = [];
|
|
79
|
+
function traverse(node, parentId) {
|
|
80
|
+
result.push({
|
|
81
|
+
...node,
|
|
82
|
+
parent: parentId ?? node.parent,
|
|
83
|
+
});
|
|
84
|
+
if (node.children) {
|
|
85
|
+
for (const child of node.children) {
|
|
86
|
+
traverse(child, node.id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const node of nodes) {
|
|
91
|
+
traverse(node);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Deserialize a CoralDocument to React Flow nodes and edges
|
|
97
|
+
*
|
|
98
|
+
* @param doc - CoralDocument to deserialize
|
|
99
|
+
* @returns Deserialized nodes, edges, settings, and metadata
|
|
100
|
+
* @throws Error if document is invalid
|
|
101
|
+
*/
|
|
102
|
+
export function deserialize(doc) {
|
|
103
|
+
// Migrate to current version if needed
|
|
104
|
+
const migratedDoc = migrateDocument(doc);
|
|
105
|
+
// Validate the document
|
|
106
|
+
assertValidDocument(migratedDoc);
|
|
107
|
+
// Extract positions map
|
|
108
|
+
const positions = migratedDoc.nodePositions ?? {};
|
|
109
|
+
// Get nodes and edges from Graph-IR content
|
|
110
|
+
let nodes = [];
|
|
111
|
+
let edges = [];
|
|
112
|
+
if (migratedDoc.content.format === 'graph-ir' && migratedDoc.content.graphIR) {
|
|
113
|
+
const graphIR = migratedDoc.content.graphIR;
|
|
114
|
+
// Flatten nested nodes
|
|
115
|
+
const flatNodes = flattenGraphNodes(graphIR.nodes);
|
|
116
|
+
// Convert to React Flow format
|
|
117
|
+
nodes = flatNodes.map((n) => graphNodeToNode(n, positions));
|
|
118
|
+
edges = graphIR.edges.map(graphEdgeToEdge);
|
|
119
|
+
}
|
|
120
|
+
// Restore waypoints from pinned edge routing (CORAL-REQ-015)
|
|
121
|
+
let edgeWaypoints;
|
|
122
|
+
if (migratedDoc.edgeRouting) {
|
|
123
|
+
for (const [edgeId, routing] of Object.entries(migratedDoc.edgeRouting)) {
|
|
124
|
+
if (routing.isPinned && routing.waypoints && routing.waypoints.length > 0) {
|
|
125
|
+
if (!edgeWaypoints)
|
|
126
|
+
edgeWaypoints = new Map();
|
|
127
|
+
edgeWaypoints.set(edgeId, routing.waypoints.map((wp) => ({
|
|
128
|
+
id: wp.id,
|
|
129
|
+
x: wp.x,
|
|
130
|
+
y: wp.y,
|
|
131
|
+
type: wp.type,
|
|
132
|
+
})));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
nodes,
|
|
138
|
+
edges,
|
|
139
|
+
settings: migratedDoc.settings,
|
|
140
|
+
viewState: migratedDoc.viewState,
|
|
141
|
+
metadata: migratedDoc.metadata,
|
|
142
|
+
edgeWaypoints,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=deserialize.js.map
|
|
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Q,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1E,IAAI,CAAC,aAAa;oBAAE,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;gBAC9C,aAAa,CAAC,GAAG,CACf,MAAM,EACN,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC7B,EAAE,EAAE,EAAE,CAAC,EAAE;oBACT,CAAC,EAAE,EAAE,CAAC,CAAC;oBACP,CAAC,EAAE,EAAE,CAAC,CAAC;oBACP,IAAI,EAAE,EAAE,CAAC,IAAI;iBACd,CAAC,CAAC,CACJ,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK;QACL,KAAK;QACL,QAAQ,EAAE,WAAW,CAAC,QAAQ;QAC9B,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,QAAQ,EAAE,WAAW,CAAC,QAAQ;QAC9B,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral File Format (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Exports for CoralDocument handling:
|
|
5
|
+
* - Schema types
|
|
6
|
+
* - Validation
|
|
7
|
+
* - Serialization/Deserialization
|
|
8
|
+
* - Migration
|
|
9
|
+
*/
|
|
10
|
+
export { CURRENT_SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSIONS, type CoralDocument, type DocumentMetadata, type DocumentContent, type DocumentSettings, type LayoutDirection, type LayoutSettings, type LayoutSpacing, type ViewState, type NodePosition, type DslType, type CreateDocumentOptions, type SerializeOptions, type DeserializeResult, type ValidationResult, type EdgeRouting, type LayoutAlgorithm, type LayoutPresetId, type LayoutPreset, type UserPreferences, type LLMProviderPreference, type SpeechRecognitionMode, type SettingsPanelState, DEFAULT_USER_PREFERENCES, DEFAULT_LAYOUT_SETTINGS, LAYOUT_PRESETS, getLayoutPreset, } from './schema.js';
|
|
11
|
+
export { validateDocument, assertValidDocument } from './validate.js';
|
|
12
|
+
export { createDocument, serialize } from './serialize.js';
|
|
13
|
+
export { deserialize } from './deserialize.js';
|
|
14
|
+
export { migrateDocument, needsMigration, getMigrationSteps } from './migrate.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral File Format (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Exports for CoralDocument handling:
|
|
5
|
+
* - Schema types
|
|
6
|
+
* - Validation
|
|
7
|
+
* - Serialization/Deserialization
|
|
8
|
+
* - Migration
|
|
9
|
+
*/
|
|
10
|
+
// Schema
|
|
11
|
+
export { CURRENT_SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSIONS, DEFAULT_USER_PREFERENCES, DEFAULT_LAYOUT_SETTINGS, LAYOUT_PRESETS, getLayoutPreset, } from './schema.js';
|
|
12
|
+
// Validation
|
|
13
|
+
export { validateDocument, assertValidDocument } from './validate.js';
|
|
14
|
+
// Serialization
|
|
15
|
+
export { createDocument, serialize } from './serialize.js';
|
|
16
|
+
// Deserialization
|
|
17
|
+
export { deserialize } from './deserialize.js';
|
|
18
|
+
// Migration
|
|
19
|
+
export { migrateDocument, needsMigration, getMigrationSteps } from './migrate.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,SAAS;AACT,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EAwBzB,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEtE,gBAAgB;AAChB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3D,kBAAkB;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,YAAY;AACZ,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Document Migration (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Handles schema version upgrades for backward compatibility.
|
|
5
|
+
*/
|
|
6
|
+
import type { CoralDocument } from './schema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Migrate a document to the current schema version
|
|
9
|
+
*
|
|
10
|
+
* @param doc - Document to migrate (may be older version)
|
|
11
|
+
* @returns Migrated document at current version
|
|
12
|
+
* @throws Error if document has unknown schema version
|
|
13
|
+
*/
|
|
14
|
+
export declare function migrateDocument(doc: CoralDocument): CoralDocument;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a document needs migration
|
|
17
|
+
*
|
|
18
|
+
* @param doc - Document to check
|
|
19
|
+
* @returns true if document needs migration
|
|
20
|
+
*/
|
|
21
|
+
export declare function needsMigration(doc: CoralDocument): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the migration path for a document
|
|
24
|
+
*
|
|
25
|
+
* @param doc - Document to check
|
|
26
|
+
* @returns Array of migration steps, empty if no migration needed
|
|
27
|
+
*/
|
|
28
|
+
export declare function getMigrationSteps(doc: CoralDocument): string[];
|
|
29
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/file/migrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA6DjD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,CAkCjE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,EAAE,CAE9D"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coral Document Migration (CORAL-REQ-008)
|
|
3
|
+
*
|
|
4
|
+
* Handles schema version upgrades for backward compatibility.
|
|
5
|
+
*/
|
|
6
|
+
import { CURRENT_SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSIONS } from './schema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Migration registry: maps "fromVersion→toVersion" to migration function
|
|
9
|
+
*/
|
|
10
|
+
const migrations = {
|
|
11
|
+
/**
|
|
12
|
+
* Migrate from 0.9.0 to 1.0.0
|
|
13
|
+
*
|
|
14
|
+
* Changes:
|
|
15
|
+
* - Added optional viewState.fitView field
|
|
16
|
+
* - Added optional settings.layout.elkOptions field
|
|
17
|
+
*/
|
|
18
|
+
'0.9.0→1.0.0': (doc) => {
|
|
19
|
+
const d = doc;
|
|
20
|
+
return {
|
|
21
|
+
...d,
|
|
22
|
+
schemaVersion: '1.0.0',
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get the migration path from one version to another
|
|
28
|
+
*/
|
|
29
|
+
function getMigrationPath(fromVersion, toVersion) {
|
|
30
|
+
const path = [];
|
|
31
|
+
const versionIndex = new Map(SUPPORTED_SCHEMA_VERSIONS.map((v, i) => [v, i]));
|
|
32
|
+
const fromIdx = versionIndex.get(fromVersion);
|
|
33
|
+
const toIdx = versionIndex.get(toVersion);
|
|
34
|
+
if (fromIdx === undefined || toIdx === undefined) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
// Build migration path
|
|
38
|
+
for (let i = fromIdx; i < toIdx; i++) {
|
|
39
|
+
const from = SUPPORTED_SCHEMA_VERSIONS[i];
|
|
40
|
+
const to = SUPPORTED_SCHEMA_VERSIONS[i + 1];
|
|
41
|
+
path.push(`${from}→${to}`);
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a schema version is known
|
|
47
|
+
*/
|
|
48
|
+
function isKnownVersion(version) {
|
|
49
|
+
return SUPPORTED_SCHEMA_VERSIONS.includes(version);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Migrate a document to the current schema version
|
|
53
|
+
*
|
|
54
|
+
* @param doc - Document to migrate (may be older version)
|
|
55
|
+
* @returns Migrated document at current version
|
|
56
|
+
* @throws Error if document has unknown schema version
|
|
57
|
+
*/
|
|
58
|
+
export function migrateDocument(doc) {
|
|
59
|
+
const currentVersion = doc.schemaVersion;
|
|
60
|
+
// Already at current version
|
|
61
|
+
if (currentVersion === CURRENT_SCHEMA_VERSION) {
|
|
62
|
+
return doc;
|
|
63
|
+
}
|
|
64
|
+
// 1.0 was emitted briefly before semantic-version normalization.
|
|
65
|
+
if (currentVersion === '1.0') {
|
|
66
|
+
return { ...doc, schemaVersion: CURRENT_SCHEMA_VERSION };
|
|
67
|
+
}
|
|
68
|
+
// Check if version is known
|
|
69
|
+
if (!isKnownVersion(currentVersion)) {
|
|
70
|
+
throw new Error(`Unknown schema version: ${currentVersion}. ` +
|
|
71
|
+
`Supported versions: ${SUPPORTED_SCHEMA_VERSIONS.join(', ')}`);
|
|
72
|
+
}
|
|
73
|
+
// Get migration path
|
|
74
|
+
const path = getMigrationPath(currentVersion, CURRENT_SCHEMA_VERSION);
|
|
75
|
+
// Apply migrations in sequence
|
|
76
|
+
let result = doc;
|
|
77
|
+
for (const step of path) {
|
|
78
|
+
const migrateFn = migrations[step];
|
|
79
|
+
if (migrateFn) {
|
|
80
|
+
result = migrateFn(result);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a document needs migration
|
|
87
|
+
*
|
|
88
|
+
* @param doc - Document to check
|
|
89
|
+
* @returns true if document needs migration
|
|
90
|
+
*/
|
|
91
|
+
export function needsMigration(doc) {
|
|
92
|
+
return doc.schemaVersion !== CURRENT_SCHEMA_VERSION;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the migration path for a document
|
|
96
|
+
*
|
|
97
|
+
* @param doc - Document to check
|
|
98
|
+
* @returns Array of migration steps, empty if no migration needed
|
|
99
|
+
*/
|
|
100
|
+
export function getMigrationSteps(doc) {
|
|
101
|
+
return getMigrationPath(doc.schemaVersion, CURRENT_SCHEMA_VERSION);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/file/migrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAOhF;;GAEG;AACH,MAAM,UAAU,GAAgC;IAC9C;;;;;;OAMG;IACH,aAAa,EAAE,CAAC,GAAY,EAAW,EAAE;QACvC,MAAM,CAAC,GAAG,GAA8B,CAAC;QACzC,OAAO;YACL,GAAG,CAAC;YACJ,aAAa,EAAE,OAAO;SACvB,CAAC;IACJ,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,SAAS,gBAAgB,CAAC,WAAmB,EAAE,SAAiB;IAC9D,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAChD,CAAC;IAEF,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAE1C,IAAI,OAAO,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACjD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,uBAAuB;IACvB,KAAK,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,yBAAyB,CAAC,CAA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