@atolis-hq/corum 0.1.22 → 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/adapters/corum/mapper.js +167 -19
- package/dist/src/adapters/corum/parser.js +7 -4
- package/dist/src/bin/corum.js +10 -0
- package/dist/src/loader/edge-loader.js +2 -2
- 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
|
@@ -6,18 +6,35 @@ export function mapDocument(document, specPath) {
|
|
|
6
6
|
const nodes = [];
|
|
7
7
|
const edges = [];
|
|
8
8
|
const diagnostics = [];
|
|
9
|
+
const allSchemas = (document.components?.schemas ?? {});
|
|
9
10
|
for (const gap of document.gaps ?? []) {
|
|
10
11
|
const msg = gap.nodeId
|
|
11
12
|
? `[${gap.kind}] ${gap.nodeId}: ${gap.reason ?? ''}`
|
|
12
13
|
: `[${gap.kind}] ${gap.reason ?? ''}`;
|
|
13
14
|
diagnostics.push({ severity: 'warning', file: specPath, message: msg });
|
|
14
15
|
}
|
|
15
|
-
for (const
|
|
16
|
-
if (!
|
|
17
|
-
diagnostics.push({ severity: 'warning', file: specPath, message:
|
|
16
|
+
for (const [nodeId, entry] of Object.entries(document.nodes)) {
|
|
17
|
+
if (!nodeId || !entry.type) {
|
|
18
|
+
diagnostics.push({ severity: 'warning', file: specPath, message: 'Node missing id or type — skipping' });
|
|
18
19
|
continue;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
const component = nodeId.split('.')[0];
|
|
22
|
+
const properties = {};
|
|
23
|
+
let schemaName;
|
|
24
|
+
if (entry.schema?.$ref) {
|
|
25
|
+
schemaName = schemaRefName(entry.schema.$ref);
|
|
26
|
+
if (schemaName)
|
|
27
|
+
properties.schema = schemaName;
|
|
28
|
+
}
|
|
29
|
+
if (entry.title && !schemaName) {
|
|
30
|
+
properties.description = entry.title;
|
|
31
|
+
}
|
|
32
|
+
const node = makeNode(entry.type, component, specPath, nodeId, entry.provenance, properties);
|
|
33
|
+
nodes.push(node);
|
|
34
|
+
if (schemaName) {
|
|
35
|
+
const expanded = new Map();
|
|
36
|
+
expandSchema(schemaName, nodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
for (const raw of document.edges ?? []) {
|
|
23
40
|
if (!VALID_EDGE_TYPES.has(raw.type)) {
|
|
@@ -32,19 +49,156 @@ export function mapDocument(document, specPath) {
|
|
|
32
49
|
}
|
|
33
50
|
return { nodes, edges, diagnostics };
|
|
34
51
|
}
|
|
35
|
-
function
|
|
52
|
+
function schemaRefName(ref) {
|
|
53
|
+
const prefix = '#/components/schemas/';
|
|
54
|
+
if (!ref.startsWith(prefix))
|
|
55
|
+
return undefined;
|
|
56
|
+
return ref.slice(prefix.length);
|
|
57
|
+
}
|
|
58
|
+
function expandSchema(schemaName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded) {
|
|
59
|
+
const existing = expanded.get(schemaName);
|
|
60
|
+
if (existing)
|
|
61
|
+
return existing;
|
|
62
|
+
const schemaId = `${rootNodeId}.schemas.${schemaName}`;
|
|
63
|
+
expanded.set(schemaName, schemaId);
|
|
64
|
+
const schemaDef = allSchemas[schemaName];
|
|
65
|
+
const schemaNode = makeNode('Schema', component, specPath, schemaId, undefined, {});
|
|
66
|
+
nodes.push(schemaNode);
|
|
67
|
+
edges.push(makeHasFieldEdge(rootNodeId, schemaId));
|
|
68
|
+
const localMappings = new Map();
|
|
69
|
+
for (const [fieldName, rawProp] of Object.entries(schemaDef?.properties ?? {})) {
|
|
70
|
+
const fieldId = `${schemaId}.fields.${fieldName}`;
|
|
71
|
+
const fieldNode = makeNode('Field', component, specPath, fieldId, undefined, {});
|
|
72
|
+
const required = Array.isArray(schemaDef?.required) && schemaDef.required.includes(fieldName);
|
|
73
|
+
fieldNode.properties = resolveFieldProperties(fieldName, rawProp, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
74
|
+
nodes.push(fieldNode);
|
|
75
|
+
edges.push(makeHasFieldEdge(schemaId, fieldId));
|
|
76
|
+
}
|
|
77
|
+
return schemaId;
|
|
78
|
+
}
|
|
79
|
+
function resolveFieldProperties(fieldName, prop, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings) {
|
|
80
|
+
const nullable = !required;
|
|
81
|
+
if (typeof prop.$ref === 'string') {
|
|
82
|
+
const refName = schemaRefName(prop.$ref);
|
|
83
|
+
if (refName) {
|
|
84
|
+
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
85
|
+
return { $ref: refId, nullable, collection: 'one' };
|
|
86
|
+
}
|
|
87
|
+
return { type: 'string', nullable, collection: 'one' };
|
|
88
|
+
}
|
|
89
|
+
const type = prop.type;
|
|
90
|
+
if (type === 'array') {
|
|
91
|
+
const items = prop.items;
|
|
92
|
+
if (items && typeof items.$ref === 'string') {
|
|
93
|
+
const refName = schemaRefName(items.$ref);
|
|
94
|
+
if (refName) {
|
|
95
|
+
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
96
|
+
return { $ref: refId, nullable, collection: 'array' };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const itemType = mapScalar(items?.type ?? 'string', items?.format);
|
|
100
|
+
return { type: itemType, nullable, collection: 'array' };
|
|
101
|
+
}
|
|
102
|
+
if (type === 'object' && prop.additionalProperties !== undefined) {
|
|
103
|
+
createMapping(fieldName, prop.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
104
|
+
return { $ref: `#/mappings/${fieldName}`, nullable, collection: 'one' };
|
|
105
|
+
}
|
|
106
|
+
const scalarType = mapScalar(type ?? 'string', prop.format);
|
|
107
|
+
return { type: scalarType, nullable, collection: 'one' };
|
|
108
|
+
}
|
|
109
|
+
function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings) {
|
|
110
|
+
const existing = localMappings.get(mappingName);
|
|
111
|
+
if (existing)
|
|
112
|
+
return existing;
|
|
113
|
+
const mappingId = `${schemaId}.mappings.${mappingName}`;
|
|
114
|
+
localMappings.set(mappingName, mappingId);
|
|
115
|
+
const mappingNode = makeNode('Mapping', component, specPath, mappingId, undefined, {});
|
|
116
|
+
const props = {};
|
|
117
|
+
if (!addlDef || typeof addlDef === 'boolean') {
|
|
118
|
+
props.type = 'string';
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const addl = addlDef;
|
|
122
|
+
if (typeof addl.$ref === 'string') {
|
|
123
|
+
const refName = schemaRefName(addl.$ref);
|
|
124
|
+
if (refName) {
|
|
125
|
+
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
props.type = 'string';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (addl.type === 'array') {
|
|
132
|
+
props['value-collection'] = 'array';
|
|
133
|
+
const items = addl.items;
|
|
134
|
+
if (items && typeof items.$ref === 'string') {
|
|
135
|
+
const refName = schemaRefName(items.$ref);
|
|
136
|
+
if (refName) {
|
|
137
|
+
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
props.type = 'string';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
props.type = mapScalar(items?.type ?? 'string', items?.format);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (addl.type === 'object' && addl.additionalProperties !== undefined) {
|
|
148
|
+
const innerName = `${mappingName}-values`;
|
|
149
|
+
props.$ref = createMapping(innerName, addl.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
props.type = mapScalar(addl.type ?? 'string', addl.format);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
mappingNode.properties = props;
|
|
156
|
+
nodes.push(mappingNode);
|
|
157
|
+
return mappingId;
|
|
158
|
+
}
|
|
159
|
+
function mapScalar(type, format) {
|
|
160
|
+
if (type === 'string') {
|
|
161
|
+
if (format === 'uuid')
|
|
162
|
+
return 'uuid';
|
|
163
|
+
if (format === 'date-time')
|
|
164
|
+
return 'datetime';
|
|
165
|
+
if (format === 'date')
|
|
166
|
+
return 'date';
|
|
167
|
+
return 'string';
|
|
168
|
+
}
|
|
169
|
+
if (type === 'integer')
|
|
170
|
+
return 'integer';
|
|
171
|
+
if (type === 'number')
|
|
172
|
+
return 'decimal';
|
|
173
|
+
if (type === 'boolean')
|
|
174
|
+
return 'boolean';
|
|
175
|
+
return 'string';
|
|
176
|
+
}
|
|
177
|
+
function makeNode(template, component, specPath, id, provenance, properties) {
|
|
36
178
|
return {
|
|
37
|
-
id
|
|
38
|
-
template
|
|
39
|
-
component
|
|
179
|
+
id,
|
|
180
|
+
template,
|
|
181
|
+
component,
|
|
40
182
|
state: 'implemented',
|
|
41
183
|
stability: 'unstable',
|
|
42
184
|
schemaVersion: '1',
|
|
43
185
|
lastModifiedAt: new Date().toISOString().split('T')[0],
|
|
44
186
|
extractedFrom: specPath,
|
|
45
|
-
derivation:
|
|
46
|
-
derivedBy:
|
|
47
|
-
properties
|
|
187
|
+
derivation: provenance?.derivation === 'inferred' ? 'inferred' : 'determined',
|
|
188
|
+
derivedBy: provenance?.derivedBy ?? 'adapter:corum',
|
|
189
|
+
properties,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function makeHasFieldEdge(from, to) {
|
|
193
|
+
return {
|
|
194
|
+
id: `${from}__has-field__${to}`,
|
|
195
|
+
from,
|
|
196
|
+
to,
|
|
197
|
+
type: 'has-field',
|
|
198
|
+
state: 'implemented',
|
|
199
|
+
stability: 'unstable',
|
|
200
|
+
derivation: 'determined',
|
|
201
|
+
derivedBy: 'adapter:corum',
|
|
48
202
|
};
|
|
49
203
|
}
|
|
50
204
|
function mapEdge(raw) {
|
|
@@ -55,13 +209,7 @@ function mapEdge(raw) {
|
|
|
55
209
|
type: raw.type,
|
|
56
210
|
state: 'implemented',
|
|
57
211
|
stability: 'unstable',
|
|
58
|
-
derivation:
|
|
59
|
-
derivedBy:
|
|
212
|
+
derivation: raw.provenance?.derivation === 'inferred' ? 'inferred' : 'determined',
|
|
213
|
+
derivedBy: raw.provenance?.derivedBy ?? 'adapter:corum',
|
|
60
214
|
};
|
|
61
215
|
}
|
|
62
|
-
function derivationOf(p) {
|
|
63
|
-
return p?.derivation === 'inferred' ? 'inferred' : 'determined';
|
|
64
|
-
}
|
|
65
|
-
function derivedByOf(p) {
|
|
66
|
-
return p?.by ? `adapter:corum/${p.by}` : 'adapter:corum';
|
|
67
|
-
}
|
|
@@ -19,16 +19,16 @@ export function parseSpec(specPath) {
|
|
|
19
19
|
diagnostics.push({
|
|
20
20
|
severity: 'error',
|
|
21
21
|
file: specPath,
|
|
22
|
-
message: 'Invalid corum interchange file: missing required "
|
|
22
|
+
message: 'Invalid corum interchange file: missing required "corum" key or "nodes" object',
|
|
23
23
|
});
|
|
24
24
|
return { document: null, diagnostics };
|
|
25
25
|
}
|
|
26
26
|
const doc = raw;
|
|
27
|
-
if (doc.
|
|
27
|
+
if (doc.corum !== SUPPORTED_VERSION) {
|
|
28
28
|
diagnostics.push({
|
|
29
29
|
severity: 'warning',
|
|
30
30
|
file: specPath,
|
|
31
|
-
message: `Unknown
|
|
31
|
+
message: `Unknown corum version "${doc.corum}" — expected "${SUPPORTED_VERSION}", continuing`,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
return { document: doc, diagnostics };
|
|
@@ -37,5 +37,8 @@ function isCorumInterchangeDocument(value) {
|
|
|
37
37
|
if (typeof value !== 'object' || value === null)
|
|
38
38
|
return false;
|
|
39
39
|
const v = value;
|
|
40
|
-
return typeof v.
|
|
40
|
+
return (typeof v.corum === 'string' &&
|
|
41
|
+
typeof v.nodes === 'object' &&
|
|
42
|
+
v.nodes !== null &&
|
|
43
|
+
!Array.isArray(v.nodes));
|
|
41
44
|
}
|
package/dist/src/bin/corum.js
CHANGED
|
@@ -47,6 +47,7 @@ program
|
|
|
47
47
|
let graph;
|
|
48
48
|
try {
|
|
49
49
|
graph = await loadGraph({ source: config.source, strict: true });
|
|
50
|
+
reportGraphDiagnostics(graph.diagnostics);
|
|
50
51
|
}
|
|
51
52
|
catch (err) {
|
|
52
53
|
process.stderr.write(`[ERROR] ${err instanceof Error ? err.message : String(err)}\n`);
|
|
@@ -287,6 +288,15 @@ function reportDiagnostics(diagnostics) {
|
|
|
287
288
|
const warnings = diagnostics.filter(d => d.severity === 'warning').length;
|
|
288
289
|
process.stdout.write(`Import complete. ${errors} error(s), ${warnings} warning(s).\n`);
|
|
289
290
|
}
|
|
291
|
+
function reportGraphDiagnostics(diagnostics) {
|
|
292
|
+
const warnings = diagnostics.filter(d => d.severity === 'warning');
|
|
293
|
+
for (const d of warnings) {
|
|
294
|
+
process.stderr.write(`[WARN] ${d.file ?? 'graph'}: ${d.message}\n`);
|
|
295
|
+
}
|
|
296
|
+
if (warnings.length > 0) {
|
|
297
|
+
process.stderr.write(`Graph loaded with ${warnings.length} warning(s).\n`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
290
300
|
async function readPackRegistryUrl(cwd) {
|
|
291
301
|
const configPath = path.join(cwd, '.corum', 'config.yaml');
|
|
292
302
|
const text = await fsReadFile(configPath, 'utf8');
|
|
@@ -27,11 +27,11 @@ export function loadEdges(content, nodes, diagnostics) {
|
|
|
27
27
|
}
|
|
28
28
|
let unresolvedEndpoint = false;
|
|
29
29
|
if (!nodes.has(edgeRecord.from)) {
|
|
30
|
-
diagnostics.push({ severity: '
|
|
30
|
+
diagnostics.push({ severity: 'warning', file: key, message: `edge from unresolved node: ${edgeRecord.from}` });
|
|
31
31
|
unresolvedEndpoint = true;
|
|
32
32
|
}
|
|
33
33
|
if (!nodes.has(edgeRecord.to)) {
|
|
34
|
-
diagnostics.push({ severity: '
|
|
34
|
+
diagnostics.push({ severity: 'warning', file: key, message: `edge to unresolved node: ${edgeRecord.to}` });
|
|
35
35
|
unresolvedEndpoint = true;
|
|
36
36
|
}
|
|
37
37
|
if (unresolvedEndpoint)
|
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 ?? []}
|