@atolis-hq/corum 0.1.23 → 0.1.24
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 +17 -15
- package/package.json +1 -1
- package/web/app.jsx +105 -1
- package/web/primitives.jsx +28 -14
package/dist/src/web/server.js
CHANGED
|
@@ -41,24 +41,26 @@ async function getPluginFiles() {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
function getNavigationOwnership(graph, node) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
// Walk up the node's own ID hierarchy in 2-segment strides (section + name),
|
|
45
|
+
// returning the deepest valid parent. This is O(depth) per node instead of O(N).
|
|
46
|
+
const parts = node.id.split('.');
|
|
47
|
+
let endIdx = parts.length - 2;
|
|
48
|
+
while (endIdx >= 1) {
|
|
49
|
+
const candidateId = parts.slice(0, endIdx).join('.');
|
|
50
|
+
const section = parts[endIdx];
|
|
51
|
+
const candidate = graph.nodesById.get(candidateId);
|
|
52
|
+
if (candidate) {
|
|
53
|
+
const tmpl = graph.templates.get(candidate.template);
|
|
54
|
+
if (tmpl) {
|
|
55
|
+
const ownedSections = getOwnedSections(tmpl);
|
|
56
|
+
if (section in ownedSections && ownedSections[section] === node.template) {
|
|
57
|
+
return { parentId: candidateId, ownedSection: section };
|
|
58
|
+
}
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
endIdx -= 2;
|
|
60
62
|
}
|
|
61
|
-
return
|
|
63
|
+
return undefined;
|
|
62
64
|
}
|
|
63
65
|
function summarizeNodeForNavigation(graph, node) {
|
|
64
66
|
const ownership = getNavigationOwnership(graph, node);
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -14,6 +14,29 @@ const {
|
|
|
14
14
|
const { buildNavTree, buildOverlayIndicatorIds } = window.CorumNav;
|
|
15
15
|
const { parseRoute, buildRoute } = window.CorumRouter;
|
|
16
16
|
|
|
17
|
+
const PANEL_EDGE_TYPES = new Set(['triggers', 'produces', 'calls', 'implements']);
|
|
18
|
+
|
|
19
|
+
const EDGE_TYPE_STYLES = {
|
|
20
|
+
triggers: { background: '#fef3c7', color: '#b45309' },
|
|
21
|
+
produces: { background: '#ccfbf1', color: '#0f766e' },
|
|
22
|
+
calls: { background: '#ede9fe', color: '#6d28d9' },
|
|
23
|
+
implements: { background: '#f1f5f9', color: '#475569' },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function classifyEdges(edges, clusterIds) {
|
|
27
|
+
const inbound = [];
|
|
28
|
+
const outbound = [];
|
|
29
|
+
for (const edge of edges) {
|
|
30
|
+
if (!PANEL_EDGE_TYPES.has(edge.type)) continue;
|
|
31
|
+
if (clusterIds.has(edge.from) && !clusterIds.has(edge.to)) {
|
|
32
|
+
outbound.push(edge);
|
|
33
|
+
} else if (!clusterIds.has(edge.from) && clusterIds.has(edge.to)) {
|
|
34
|
+
inbound.push(edge);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { inbound, outbound };
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
function displayName(id) {
|
|
18
41
|
const parts = id.split('.');
|
|
19
42
|
return parts[parts.length - 1];
|
|
@@ -423,6 +446,77 @@ function ComponentsPage() {
|
|
|
423
446
|
return <div className="content"><h1>Components</h1></div>;
|
|
424
447
|
}
|
|
425
448
|
|
|
449
|
+
function EdgePanel({ inbound, outbound, allNodes, templates, onNavigate }) {
|
|
450
|
+
const { useState: useLocalState } = React;
|
|
451
|
+
const [open, setOpen] = useLocalState(() => {
|
|
452
|
+
try { return localStorage.getItem('corum:edgePanelOpen') === 'true'; } catch { return false; }
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
if (inbound.length === 0 && outbound.length === 0) return null;
|
|
456
|
+
|
|
457
|
+
function toggle() {
|
|
458
|
+
setOpen(prev => {
|
|
459
|
+
const next = !prev;
|
|
460
|
+
try { localStorage.setItem('corum:edgePanelOpen', String(next)); } catch {}
|
|
461
|
+
return next;
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const nodeMap = new Map(allNodes.map(n => [n.id, n]));
|
|
466
|
+
const templateMap = new Map(templates.map(t => [t.name, t]));
|
|
467
|
+
|
|
468
|
+
function EdgeRow({ edge, linkedNodeId }) {
|
|
469
|
+
const node = nodeMap.get(linkedNodeId);
|
|
470
|
+
const tmpl = node ? templateMap.get(node.template) : null;
|
|
471
|
+
const colour = tmpl?.ui?.colour ?? null;
|
|
472
|
+
const name = linkedNodeId.split('.').pop();
|
|
473
|
+
return (
|
|
474
|
+
<div
|
|
475
|
+
onClick={() => onNavigate(linkedNodeId)}
|
|
476
|
+
title={linkedNodeId}
|
|
477
|
+
style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '5px 0', cursor: 'pointer' }}
|
|
478
|
+
>
|
|
479
|
+
<span className="tag" style={EDGE_TYPE_STYLES[edge.type] ?? {}}>{edge.type}</span>
|
|
480
|
+
<TemplateBadge name={tmpl?.ui?.displayName ?? node?.template ?? '?'} colour={colour} />
|
|
481
|
+
<span style={{ fontWeight: 500, fontSize: 13 }}>{name}</span>
|
|
482
|
+
{node && <StateTag state={node.state} />}
|
|
483
|
+
{node && <StabilityTag stability={node.stability} />}
|
|
484
|
+
</div>
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return (
|
|
489
|
+
<div className="card" style={{ marginBottom: 16 }}>
|
|
490
|
+
<div
|
|
491
|
+
className="card-head"
|
|
492
|
+
onClick={toggle}
|
|
493
|
+
style={{ cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 12, userSelect: 'none' }}
|
|
494
|
+
>
|
|
495
|
+
<span>Connections</span>
|
|
496
|
+
{inbound.length > 0 && <span className="label-sm">← {inbound.length} inbound</span>}
|
|
497
|
+
{outbound.length > 0 && <span className="label-sm">→ {outbound.length} outbound</span>}
|
|
498
|
+
<span style={{ marginLeft: 'auto' }}><Icon name={open ? 'chevron-up' : 'chevron-down'} size={12} /></span>
|
|
499
|
+
</div>
|
|
500
|
+
{open && (
|
|
501
|
+
<div className="card-body" style={{ display: 'flex', flexDirection: 'column', gap: 16, padding: '12px 16px' }}>
|
|
502
|
+
{inbound.length > 0 && (
|
|
503
|
+
<div>
|
|
504
|
+
<div className="label-xs" style={{ marginBottom: 8 }}>Inbound</div>
|
|
505
|
+
{inbound.map(edge => <EdgeRow key={edge.id} edge={edge} linkedNodeId={edge.from} />)}
|
|
506
|
+
</div>
|
|
507
|
+
)}
|
|
508
|
+
{outbound.length > 0 && (
|
|
509
|
+
<div>
|
|
510
|
+
<div className="label-xs" style={{ marginBottom: 8 }}>Outbound</div>
|
|
511
|
+
{outbound.map(edge => <EdgeRow key={edge.id} edge={edge} linkedNodeId={edge.to} />)}
|
|
512
|
+
</div>
|
|
513
|
+
)}
|
|
514
|
+
</div>
|
|
515
|
+
)}
|
|
516
|
+
</div>
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
|
|
426
520
|
function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, overlayRefs, compact = true }) {
|
|
427
521
|
const [cluster, setCluster] = useState(null);
|
|
428
522
|
const [error, setError] = useState(null);
|
|
@@ -435,7 +529,7 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
435
529
|
const overlayParam = overlayRefs && overlayRefs.length > 0
|
|
436
530
|
? '&' + overlayRefs.map(ref => `overlayRefs=${encodeURIComponent(ref)}`).join('&')
|
|
437
531
|
: '';
|
|
438
|
-
fetch(`/api/cluster?nodeId=${encodeURIComponent(nodeId)}&includeEdges=maps-to,reads${refParam}${overlayParam}`)
|
|
532
|
+
fetch(`/api/cluster?nodeId=${encodeURIComponent(nodeId)}&includeEdges=maps-to,reads,triggers,produces,calls,implements${refParam}${overlayParam}`)
|
|
439
533
|
.then(response => response.ok ? response.json() : Promise.reject(response.status))
|
|
440
534
|
.then(setCluster)
|
|
441
535
|
.catch(err => setError(String(err)));
|
|
@@ -446,6 +540,8 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
446
540
|
if (!cluster) return <div className="content"><p className="label-sm">Loading...</p></div>;
|
|
447
541
|
|
|
448
542
|
const { root, descendants, includedNodes, edges } = cluster;
|
|
543
|
+
const clusterIds = new Set([root.id, ...descendants.map(d => d.id)]);
|
|
544
|
+
const { inbound: panelInbound, outbound: panelOutbound } = classifyEdges(edges, clusterIds);
|
|
449
545
|
const template = templates.find(item => item.name === root.template);
|
|
450
546
|
const colour = template?.ui?.colour ?? null;
|
|
451
547
|
const nestedSections = new Set((template?.ui?.nav?.nestOwned ?? []).map(item => item.section));
|
|
@@ -491,6 +587,14 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
491
587
|
<div className="label-sm mono">{root.id}</div>
|
|
492
588
|
</div>
|
|
493
589
|
|
|
590
|
+
<EdgePanel
|
|
591
|
+
inbound={panelInbound}
|
|
592
|
+
outbound={panelOutbound}
|
|
593
|
+
allNodes={[root, ...descendants, ...includedNodes]}
|
|
594
|
+
templates={templates}
|
|
595
|
+
onNavigate={onNavigate}
|
|
596
|
+
/>
|
|
597
|
+
|
|
494
598
|
<div className="meta-strip">
|
|
495
599
|
{[
|
|
496
600
|
['Component', root.component],
|
package/web/primitives.jsx
CHANGED
|
@@ -323,23 +323,33 @@ function enumValueDescription(node) {
|
|
|
323
323
|
return node.properties?.description ?? '-';
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
function parentSchemaId(fieldNodeId) {
|
|
327
|
+
const idx = fieldNodeId.lastIndexOf('.fields.');
|
|
328
|
+
return idx >= 0 ? fieldNodeId.slice(0, idx) : null;
|
|
329
|
+
}
|
|
330
|
+
|
|
326
331
|
function buildSchemaModel(schemaNodes, allNodes) {
|
|
327
|
-
// Include all Schema nodes from allNodes so canExpand works for included/referenced schemas
|
|
328
332
|
const allSchemaNodes = (allNodes ?? []).filter(n => n.template === 'Schema');
|
|
329
333
|
const allMappingNodes = (allNodes ?? []).filter(n => n.template === 'Mapping');
|
|
330
334
|
const schemasByName = new Map(allSchemaNodes.map(node => [localSchemaName(node.id), node]));
|
|
335
|
+
const schemasById = new Map(allSchemaNodes.map(node => [node.id, node]));
|
|
331
336
|
const mappingsByNodeId = new Map(allMappingNodes.map(node => [node.id, node]));
|
|
332
337
|
// Ensure the primary schemaNodes are always present (they may not be in allNodes)
|
|
333
|
-
for (const node of schemaNodes)
|
|
338
|
+
for (const node of schemaNodes) {
|
|
339
|
+
schemasByName.set(localSchemaName(node.id), node);
|
|
340
|
+
schemasById.set(node.id, node);
|
|
341
|
+
}
|
|
342
|
+
// fieldsBySchema keyed by full schema node ID — prevents same-named schemas from
|
|
343
|
+
// different clusters contaminating each other's field lists
|
|
334
344
|
const fieldsBySchema = new Map();
|
|
335
345
|
const referencedSchemas = new Set();
|
|
336
346
|
|
|
337
347
|
for (const node of allNodes ?? []) {
|
|
338
348
|
if (node.template !== 'Field') continue;
|
|
339
|
-
const
|
|
340
|
-
if (!
|
|
341
|
-
if (!fieldsBySchema.has(
|
|
342
|
-
fieldsBySchema.get(
|
|
349
|
+
const schemaId = parentSchemaId(node.id);
|
|
350
|
+
if (!schemaId) continue;
|
|
351
|
+
if (!fieldsBySchema.has(schemaId)) fieldsBySchema.set(schemaId, []);
|
|
352
|
+
fieldsBySchema.get(schemaId).push(node);
|
|
343
353
|
|
|
344
354
|
const ref = node.properties?.['$ref'];
|
|
345
355
|
const localName = refLocalSchemaName(ref);
|
|
@@ -351,6 +361,7 @@ function buildSchemaModel(schemaNodes, allNodes) {
|
|
|
351
361
|
const topSchemas = schemaNodes.filter(node => !referencedSchemas.has(localSchemaName(node.id)));
|
|
352
362
|
return {
|
|
353
363
|
schemasByName,
|
|
364
|
+
schemasById,
|
|
354
365
|
mappingsByNodeId,
|
|
355
366
|
fieldsBySchema,
|
|
356
367
|
topSchemas: topSchemas.length > 0 ? topSchemas : schemaNodes,
|
|
@@ -409,7 +420,7 @@ function MappingInlineRows({ mappingNode, depth, model, edges, compact, visited
|
|
|
409
420
|
{valueCanExpand && !valueCollapsed && (
|
|
410
421
|
valueCanExpandSchema ? (
|
|
411
422
|
<SchemaFieldRows
|
|
412
|
-
|
|
423
|
+
schemaNodeId={valueSchema.id}
|
|
413
424
|
model={model}
|
|
414
425
|
depth={depth + 1}
|
|
415
426
|
visited={nextVisited}
|
|
@@ -431,9 +442,9 @@ function MappingInlineRows({ mappingNode, depth, model, edges, compact, visited
|
|
|
431
442
|
);
|
|
432
443
|
}
|
|
433
444
|
|
|
434
|
-
function SchemaFieldRows({
|
|
445
|
+
function SchemaFieldRows({ schemaNodeId, model, prefix = '', depth = 0, visited = new Set(), edges = [], overlayFields, overlayRefs, compact = false }) {
|
|
435
446
|
const [collapsed, setCollapsed] = React.useState(new Set());
|
|
436
|
-
const fields = model.fieldsBySchema.get(
|
|
447
|
+
const fields = model.fieldsBySchema.get(schemaNodeId) ?? [];
|
|
437
448
|
if (fields.length === 0) {
|
|
438
449
|
return (
|
|
439
450
|
<div className="field-row">
|
|
@@ -457,14 +468,17 @@ function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited =
|
|
|
457
468
|
const refNodeId = ref && typeof ref === 'object' && 'nodeId' in ref ? ref.nodeId : null;
|
|
458
469
|
const mappingNode = refNodeId ? (model.mappingsByNodeId?.get(refNodeId) ?? null) : null;
|
|
459
470
|
const canExpandMapping = !!mappingNode;
|
|
460
|
-
|
|
461
|
-
const
|
|
471
|
+
// Prefer exact node ID lookup to avoid same-named schemas from different clusters
|
|
472
|
+
const childSchemaNode = !canExpandMapping
|
|
473
|
+
? (refNodeId ? (model.schemasById?.get(refNodeId) ?? null) : (localRef ? (model.schemasByName.get(localRef) ?? null) : null))
|
|
474
|
+
: null;
|
|
475
|
+
const canExpand = !!childSchemaNode && !visited.has(childSchemaNode.id);
|
|
462
476
|
const isExpandable = canExpand || canExpandMapping;
|
|
463
477
|
const childGhostFields = childSchemaNode ? overlayFieldsForSchema(overlayFields, childSchemaNode.id) : [];
|
|
464
478
|
const c = field.properties?.collection;
|
|
465
479
|
const childPrefix = `${prefix}${name}${c === 'array' ? '[].' : '.'}`;
|
|
466
480
|
const nextVisited = new Set(visited);
|
|
467
|
-
nextVisited.add(
|
|
481
|
+
nextVisited.add(schemaNodeId);
|
|
468
482
|
const links = edges.filter(e =>
|
|
469
483
|
(e.from === field.id || e.to === field.id)
|
|
470
484
|
&& e.type !== 'has-field'
|
|
@@ -525,7 +539,7 @@ function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited =
|
|
|
525
539
|
) : (
|
|
526
540
|
<>
|
|
527
541
|
<SchemaFieldRows
|
|
528
|
-
|
|
542
|
+
schemaNodeId={childSchemaNode.id}
|
|
529
543
|
model={model}
|
|
530
544
|
prefix={childPrefix}
|
|
531
545
|
depth={depth + 1}
|
|
@@ -708,7 +722,7 @@ function SchemaCard({ title, nodes, allNodes, edges, anchorIdForNode, overlayFie
|
|
|
708
722
|
<div className="label-xs">Links</div>
|
|
709
723
|
</div>
|
|
710
724
|
<SchemaFieldRows
|
|
711
|
-
|
|
725
|
+
schemaNodeId={schema.id}
|
|
712
726
|
model={model}
|
|
713
727
|
visited={new Set()}
|
|
714
728
|
edges={edges ?? []}
|