@atolis-hq/corum 0.1.25 → 0.1.27
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/dist/src/web/server.js +41 -0
- package/package.json +1 -1
- package/web/app.jsx +69 -4
- package/web/graph-utils.js +74 -0
- package/web/graph-utils.test.js +63 -0
- package/web/graph.jsx +441 -0
- package/web/index.html +6 -0
- package/web/package.json +1 -0
- package/web/router.js +1 -1
- package/web/search-utils.test.js +61 -0
- package/web/search.jsx +111 -0
- package/web/style.css +613 -0
package/dist/src/web/server.js
CHANGED
|
@@ -343,6 +343,47 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
343
343
|
});
|
|
344
344
|
res.json(nodes);
|
|
345
345
|
});
|
|
346
|
+
const GRAPH_EXCLUDED_TEMPLATES = new Set([
|
|
347
|
+
'Schema', 'EnumDefinition', 'Field', 'EnumValue', 'Mapping',
|
|
348
|
+
]);
|
|
349
|
+
const GRAPH_SEMANTIC_EDGE_TYPES = new Set([
|
|
350
|
+
'triggers', 'produces', 'reads', 'calls', 'implements', 'maps-to', 'derived-from',
|
|
351
|
+
]);
|
|
352
|
+
app.get('/api/graph', async (req, res) => {
|
|
353
|
+
try {
|
|
354
|
+
let targetGraph = graph;
|
|
355
|
+
if (typeof req.query.ref === 'string' && multiCache) {
|
|
356
|
+
targetGraph = await getGraphForRef(req.query.ref, multiCache, graph);
|
|
357
|
+
}
|
|
358
|
+
const nodes = [];
|
|
359
|
+
for (const node of targetGraph.nodesById.values()) {
|
|
360
|
+
if (GRAPH_EXCLUDED_TEMPLATES.has(node.template))
|
|
361
|
+
continue;
|
|
362
|
+
nodes.push({
|
|
363
|
+
id: node.id,
|
|
364
|
+
template: node.template,
|
|
365
|
+
component: node.component,
|
|
366
|
+
state: node.state,
|
|
367
|
+
stability: node.stability,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
const nodeIds = new Set(nodes.map(n => n.id));
|
|
371
|
+
const edges = [];
|
|
372
|
+
for (const edgeList of targetGraph.edgesByFrom.values()) {
|
|
373
|
+
for (const edge of edgeList) {
|
|
374
|
+
if (!GRAPH_SEMANTIC_EDGE_TYPES.has(edge.type))
|
|
375
|
+
continue;
|
|
376
|
+
if (!nodeIds.has(edge.from) || !nodeIds.has(edge.to))
|
|
377
|
+
continue;
|
|
378
|
+
edges.push({ id: edge.id, from: edge.from, to: edge.to, type: edge.type });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
res.json({ nodes, edges });
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
res.status(500).json({ error: String(err) });
|
|
385
|
+
}
|
|
386
|
+
});
|
|
346
387
|
app.get('/api/cluster', async (req, res) => {
|
|
347
388
|
const nodeId = typeof req.query.nodeId === 'string' ? req.query.nodeId : undefined;
|
|
348
389
|
if (!nodeId) {
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
} = window.CorumPrimitives;
|
|
14
14
|
const { buildNavTree, buildOverlayIndicatorIds } = window.CorumNav;
|
|
15
15
|
const { parseRoute, buildRoute } = window.CorumRouter;
|
|
16
|
+
const { SearchModal } = window.CorumSearch;
|
|
16
17
|
|
|
17
18
|
const PANEL_EDGE_TYPES = new Set(['triggers', 'produces', 'calls', 'implements']);
|
|
18
19
|
|
|
@@ -58,13 +59,31 @@ function summarizeBranchFailure(result) {
|
|
|
58
59
|
return result?.error ?? 'Branch failed to load';
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
function TopBar() {
|
|
62
|
+
function TopBar({ onSearchOpen }) {
|
|
63
|
+
const inputRef = React.useRef(null);
|
|
64
|
+
|
|
65
|
+
function handleFocus() {
|
|
66
|
+
inputRef.current?.blur();
|
|
67
|
+
onSearchOpen();
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
return (
|
|
63
71
|
<div className="topbar">
|
|
64
72
|
<div className="brand">
|
|
65
73
|
<BrandMark size={22} color="#fff" />
|
|
66
74
|
<span>corum</span>
|
|
67
75
|
</div>
|
|
76
|
+
<div className="topbar-search-wrap">
|
|
77
|
+
<i className="fa-solid fa-magnifying-glass topbar-search-icon" aria-hidden="true" />
|
|
78
|
+
<input
|
|
79
|
+
ref={inputRef}
|
|
80
|
+
className="topbar-search"
|
|
81
|
+
placeholder="Search graph..."
|
|
82
|
+
onFocus={handleFocus}
|
|
83
|
+
readOnly
|
|
84
|
+
/>
|
|
85
|
+
<span className="topbar-search-hint">⌘K</span>
|
|
86
|
+
</div>
|
|
68
87
|
</div>
|
|
69
88
|
);
|
|
70
89
|
}
|
|
@@ -73,6 +92,7 @@ function NavRail({ activeSection, onSection, debugMode, onDebugMode }) {
|
|
|
73
92
|
const items = [
|
|
74
93
|
{ id: 'dashboard', icon: 'grip', label: 'Dashboard' },
|
|
75
94
|
{ id: 'components', icon: 'circle-nodes', label: 'Models' },
|
|
95
|
+
{ id: 'graph', icon: 'diagram-project', label: 'Graph' },
|
|
76
96
|
];
|
|
77
97
|
|
|
78
98
|
return (
|
|
@@ -482,7 +502,7 @@ function ComponentsPage() {
|
|
|
482
502
|
return <div className="content"><h1>Components</h1></div>;
|
|
483
503
|
}
|
|
484
504
|
|
|
485
|
-
function EdgePanel({ inbound, outbound, allNodes, templates, onNavigate }) {
|
|
505
|
+
function EdgePanel({ inbound, outbound, allNodes, templates, onNavigate, viewingRef }) {
|
|
486
506
|
const { useState: useLocalState } = React;
|
|
487
507
|
const [open, setOpen] = useLocalState(() => {
|
|
488
508
|
try { return localStorage.getItem('corum:edgePanelOpen') === 'true'; } catch { return false; }
|
|
@@ -517,6 +537,14 @@ function EdgePanel({ inbound, outbound, allNodes, templates, onNavigate }) {
|
|
|
517
537
|
<span style={{ fontWeight: 500, fontSize: 13 }}>{name}</span>
|
|
518
538
|
{node && <StateTag state={node.state} />}
|
|
519
539
|
{node && <StabilityTag stability={node.stability} />}
|
|
540
|
+
<button
|
|
541
|
+
className="graph-nav-link"
|
|
542
|
+
title="View in graph"
|
|
543
|
+
onClick={e => { e.stopPropagation(); navigate(buildRoute({ pathname: '/graph', params: { focus: linkedNodeId }, branch: viewingRef })); }}
|
|
544
|
+
style={{ marginLeft: 'auto' }}
|
|
545
|
+
>
|
|
546
|
+
<Icon name="diagram-project" size={11} />
|
|
547
|
+
</button>
|
|
520
548
|
</div>
|
|
521
549
|
);
|
|
522
550
|
}
|
|
@@ -619,6 +647,14 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
619
647
|
<TemplateBadge name={templateDisplayName(template)} colour={colour} />
|
|
620
648
|
<StateTag state={root.state} />
|
|
621
649
|
<StabilityTag stability={root.stability} />
|
|
650
|
+
<button
|
|
651
|
+
className="graph-nav-link"
|
|
652
|
+
onClick={() => navigate(buildRoute({ pathname: '/graph', params: { focus: root.id }, branch: viewingRef }))}
|
|
653
|
+
title="View in graph"
|
|
654
|
+
>
|
|
655
|
+
<Icon name="diagram-project" size={11} />
|
|
656
|
+
<span>Graph</span>
|
|
657
|
+
</button>
|
|
622
658
|
</div>
|
|
623
659
|
<div className="label-sm mono">{root.id}</div>
|
|
624
660
|
</div>
|
|
@@ -629,6 +665,7 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
629
665
|
allNodes={[root, ...descendants, ...includedNodes]}
|
|
630
666
|
templates={templates}
|
|
631
667
|
onNavigate={onNavigate}
|
|
668
|
+
viewingRef={viewingRef}
|
|
632
669
|
/>
|
|
633
670
|
|
|
634
671
|
<div className="meta-strip">
|
|
@@ -730,6 +767,7 @@ function App() {
|
|
|
730
767
|
const [debugMode, setDebugMode] = useState(() => {
|
|
731
768
|
try { return localStorage.getItem('corum:debugMode') === 'true'; } catch { return false; }
|
|
732
769
|
});
|
|
770
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
733
771
|
|
|
734
772
|
function handleDebugMode() {
|
|
735
773
|
setDebugMode(prev => {
|
|
@@ -810,10 +848,21 @@ function App() {
|
|
|
810
848
|
return () => window.removeEventListener('hashchange', handler);
|
|
811
849
|
}, []);
|
|
812
850
|
|
|
851
|
+
useEffect(() => {
|
|
852
|
+
function handleKeyDown(e) {
|
|
853
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
854
|
+
e.preventDefault();
|
|
855
|
+
setSearchOpen(true);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
859
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
860
|
+
}, []);
|
|
861
|
+
|
|
813
862
|
const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
|
|
814
863
|
const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
|
|
815
864
|
const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
|
|
816
|
-
const showTree = activeSection === 'components' || activeNodeId;
|
|
865
|
+
const showTree = (activeSection === 'components' || activeNodeId) && activeSection !== 'graph';
|
|
817
866
|
const activeOverlayRefs = useMemo(() =>
|
|
818
867
|
overlayMode === 'single' ? [] :
|
|
819
868
|
overlayMode === 'consolidated' ? branches.filter(branch => branch.ref !== viewingRef).map(branch => branch.ref) :
|
|
@@ -866,13 +915,29 @@ function App() {
|
|
|
866
915
|
compact={!debugMode}
|
|
867
916
|
/>
|
|
868
917
|
);
|
|
918
|
+
} else if (route.pathname === '/graph') {
|
|
919
|
+
page = (
|
|
920
|
+
<window.CorumGraph.GraphView
|
|
921
|
+
route={route}
|
|
922
|
+
viewingRef={viewingRef}
|
|
923
|
+
templates={templates}
|
|
924
|
+
/>
|
|
925
|
+
);
|
|
869
926
|
} else {
|
|
870
927
|
page = <div className="content"><p className="label-sm">Page not found.</p></div>;
|
|
871
928
|
}
|
|
872
929
|
|
|
873
930
|
return (
|
|
874
931
|
<>
|
|
875
|
-
|
|
932
|
+
{searchOpen && (
|
|
933
|
+
<SearchModal
|
|
934
|
+
nodes={nodes}
|
|
935
|
+
templates={templates}
|
|
936
|
+
onNavigate={handleNode}
|
|
937
|
+
onClose={() => setSearchOpen(false)}
|
|
938
|
+
/>
|
|
939
|
+
)}
|
|
940
|
+
<TopBar onSearchOpen={() => setSearchOpen(true)} />
|
|
876
941
|
{gitMode && (
|
|
877
942
|
<BranchBar
|
|
878
943
|
branches={branches}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* Pure graph utility functions — browser globals + Node require() compatible. */
|
|
2
|
+
|
|
3
|
+
function getDisplayName(nodeId) {
|
|
4
|
+
return nodeId.split('.').pop();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function buildComponentMap(nodes, edges) {
|
|
8
|
+
const componentCounts = new Map();
|
|
9
|
+
for (const node of nodes) {
|
|
10
|
+
componentCounts.set(node.component, (componentCounts.get(node.component) ?? 0) + 1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const componentNodes = [...componentCounts.entries()].map(([component, count]) => ({
|
|
14
|
+
id: component,
|
|
15
|
+
component,
|
|
16
|
+
count,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const nodeById = new Map(nodes.map(n => [n.id, n]));
|
|
20
|
+
const compEdgeMap = new Map();
|
|
21
|
+
for (const edge of edges) {
|
|
22
|
+
const fromNode = nodeById.get(edge.from);
|
|
23
|
+
const toNode = nodeById.get(edge.to);
|
|
24
|
+
if (!fromNode || !toNode) continue;
|
|
25
|
+
if (fromNode.component === toNode.component) continue;
|
|
26
|
+
const key = `${fromNode.component}__${toNode.component}`;
|
|
27
|
+
if (!compEdgeMap.has(key)) compEdgeMap.set(key, { from: fromNode.component, to: toNode.component, types: new Set() });
|
|
28
|
+
compEdgeMap.get(key).types.add(edge.type);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const componentEdges = [...compEdgeMap.entries()].map(([key, entry]) => ({
|
|
32
|
+
id: key,
|
|
33
|
+
from: entry.from,
|
|
34
|
+
to: entry.to,
|
|
35
|
+
types: [...entry.types],
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
return { nodes: componentNodes, edges: componentEdges };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function buildFocusGraph(focalNodeId, nodes, edges, depth) {
|
|
42
|
+
const nodeById = new Map(nodes.map(n => [n.id, n]));
|
|
43
|
+
const visited = new Set([focalNodeId]);
|
|
44
|
+
const queue = [{ id: focalNodeId, d: 0 }];
|
|
45
|
+
|
|
46
|
+
while (queue.length > 0) {
|
|
47
|
+
const { id, d } = queue.shift();
|
|
48
|
+
if (d >= depth) continue;
|
|
49
|
+
for (const edge of edges) {
|
|
50
|
+
let neighborId = null;
|
|
51
|
+
if (edge.from === id) neighborId = edge.to;
|
|
52
|
+
else if (edge.to === id) neighborId = edge.from;
|
|
53
|
+
if (!neighborId || visited.has(neighborId) || !nodeById.has(neighborId)) continue;
|
|
54
|
+
visited.add(neighborId);
|
|
55
|
+
queue.push({ id: neighborId, d: d + 1 });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
nodes: [...visited].map(id => nodeById.get(id)).filter(Boolean),
|
|
61
|
+
edges: edges.filter(e => visited.has(e.from) && visited.has(e.to)),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function applyEdgeTypeFilter(edges, visibleTypes) {
|
|
66
|
+
return edges.filter(e => visibleTypes.has(e.type));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
70
|
+
module.exports = { buildComponentMap, buildFocusGraph, applyEdgeTypeFilter, getDisplayName };
|
|
71
|
+
}
|
|
72
|
+
if (typeof window !== 'undefined') {
|
|
73
|
+
window.CorumGraphUtils = { buildComponentMap, buildFocusGraph, applyEdgeTypeFilter, getDisplayName };
|
|
74
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// run with: node web/graph-utils.test.js
|
|
2
|
+
const { buildComponentMap, buildFocusGraph, applyEdgeTypeFilter, getDisplayName } = require('./graph-utils.js');
|
|
3
|
+
|
|
4
|
+
(async () => {
|
|
5
|
+
|
|
6
|
+
let passed = 0, failed = 0;
|
|
7
|
+
function assert(condition, name) {
|
|
8
|
+
if (condition) { console.log(` ✓ ${name}`); passed++; }
|
|
9
|
+
else { console.error(` ✗ ${name}`); failed++; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const nodes = [
|
|
13
|
+
{ id: 'orders.DomainModel.order', template: 'DomainModel', component: 'orders', state: 'agreed', stability: 'stable' },
|
|
14
|
+
{ id: 'orders.RestAPI.ordersApi', template: 'RestAPI', component: 'orders', state: 'agreed', stability: 'stable' },
|
|
15
|
+
{ id: 'payments.DomainModel.payment', template: 'DomainModel', component: 'payments', state: 'proposed', stability: 'unstable' },
|
|
16
|
+
{ id: 'payments.RestAPI.paymentsApi', template: 'RestAPI', component: 'payments', state: 'proposed', stability: 'unstable' },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const edges = [
|
|
20
|
+
{ id: 'e1', from: 'orders.RestAPI.ordersApi', to: 'orders.DomainModel.order', type: 'reads' },
|
|
21
|
+
{ id: 'e2', from: 'orders.RestAPI.ordersApi', to: 'payments.RestAPI.paymentsApi', type: 'calls' },
|
|
22
|
+
{ id: 'e3', from: 'payments.RestAPI.paymentsApi', to: 'payments.DomainModel.payment', type: 'reads' },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// getDisplayName
|
|
26
|
+
assert(getDisplayName('orders.DomainModel.order') === 'order', 'getDisplayName returns last segment');
|
|
27
|
+
assert(getDisplayName('payments.RestAPI.paymentsApi') === 'paymentsApi', 'getDisplayName handles nested id');
|
|
28
|
+
|
|
29
|
+
// buildComponentMap
|
|
30
|
+
const cm = buildComponentMap(nodes, edges);
|
|
31
|
+
assert(cm.nodes.length === 2, 'buildComponentMap: one node per component');
|
|
32
|
+
assert(cm.nodes.every(n => typeof n.count === 'number' && n.count > 0), 'buildComponentMap: nodes have count');
|
|
33
|
+
const cmOrders = cm.nodes.find(n => n.id === 'orders');
|
|
34
|
+
assert(cmOrders?.count === 2, 'buildComponentMap: orders has 2 nodes');
|
|
35
|
+
assert(cm.edges.length === 1, 'buildComponentMap: one cross-component edge');
|
|
36
|
+
assert(cm.edges[0].from === 'orders' && cm.edges[0].to === 'payments', 'buildComponentMap: edge direction correct');
|
|
37
|
+
assert(cm.edges[0].types.includes('calls'), 'buildComponentMap: edge types collected');
|
|
38
|
+
const sameCmEdges = buildComponentMap(nodes, [{ id: 'x', from: 'orders.DomainModel.order', to: 'orders.RestAPI.ordersApi', type: 'reads' }]);
|
|
39
|
+
assert(sameCmEdges.edges.length === 0, 'buildComponentMap: intra-component edges excluded');
|
|
40
|
+
|
|
41
|
+
// buildFocusGraph - depth 1
|
|
42
|
+
const focus1 = buildFocusGraph('orders.RestAPI.ordersApi', nodes, edges, 1);
|
|
43
|
+
assert(focus1.nodes.some(n => n.id === 'orders.RestAPI.ordersApi'), 'buildFocusGraph depth=1: includes focal node');
|
|
44
|
+
assert(focus1.nodes.some(n => n.id === 'orders.DomainModel.order'), 'buildFocusGraph depth=1: includes 1-hop neighbour (via reads)');
|
|
45
|
+
assert(focus1.nodes.some(n => n.id === 'payments.RestAPI.paymentsApi'), 'buildFocusGraph depth=1: includes 1-hop neighbour (via calls)');
|
|
46
|
+
assert(!focus1.nodes.some(n => n.id === 'payments.DomainModel.payment'), 'buildFocusGraph depth=1: excludes 2-hop neighbour');
|
|
47
|
+
assert(focus1.edges.length === 2, 'buildFocusGraph depth=1: includes only edges within visible nodes');
|
|
48
|
+
|
|
49
|
+
// buildFocusGraph - depth Infinity
|
|
50
|
+
const focusAll = buildFocusGraph('orders.RestAPI.ordersApi', nodes, edges, Infinity);
|
|
51
|
+
assert(focusAll.nodes.length === 4, 'buildFocusGraph depth=Infinity: includes all reachable nodes');
|
|
52
|
+
assert(focusAll.edges.length === 3, 'buildFocusGraph depth=Infinity: includes all reachable edges');
|
|
53
|
+
|
|
54
|
+
// applyEdgeTypeFilter
|
|
55
|
+
const filtered = applyEdgeTypeFilter(edges, new Set(['reads']));
|
|
56
|
+
assert(filtered.length === 2, 'applyEdgeTypeFilter: keeps only matching type');
|
|
57
|
+
assert(filtered.every(e => e.type === 'reads'), 'applyEdgeTypeFilter: all results have correct type');
|
|
58
|
+
const none = applyEdgeTypeFilter(edges, new Set([]));
|
|
59
|
+
assert(none.length === 0, 'applyEdgeTypeFilter: empty set returns nothing');
|
|
60
|
+
|
|
61
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
62
|
+
if (failed > 0) process.exit(1);
|
|
63
|
+
})();
|