@atolis-hq/corum 0.1.32 → 0.1.34
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 +99 -13
- package/dist/src/web/server.js +8 -2
- package/package.json +1 -1
- package/web/app.jsx +28 -8
- package/web/graph.jsx +1 -0
|
@@ -7,6 +7,8 @@ export function mapDocument(document, specPath) {
|
|
|
7
7
|
const edges = [];
|
|
8
8
|
const diagnostics = [];
|
|
9
9
|
const allSchemas = (document.components?.schemas ?? {});
|
|
10
|
+
// Maps #/components/schemas/X and #/components/schemas/X/properties/Y to materialized node IDs
|
|
11
|
+
const refToNodeId = new Map();
|
|
10
12
|
for (const gap of document.gaps ?? []) {
|
|
11
13
|
const msg = gap.nodeId
|
|
12
14
|
? `[${gap.kind}] ${gap.nodeId}: ${gap.reason ?? ''}`
|
|
@@ -36,9 +38,50 @@ export function mapDocument(document, specPath) {
|
|
|
36
38
|
nodes.push(node);
|
|
37
39
|
if (schemaName) {
|
|
38
40
|
const expanded = new Map();
|
|
39
|
-
expandSchema(schemaName, nodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
41
|
+
expandSchema(schemaName, nodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId);
|
|
40
42
|
}
|
|
41
43
|
}
|
|
44
|
+
// Expand schemas referenced in edges that weren't reachable via any node's schema ref.
|
|
45
|
+
// Uses schema name as its own synthetic root so IDs are self-contained and don't collide.
|
|
46
|
+
// Enum schemas register their enum values as field nodes so edge refs to them can resolve.
|
|
47
|
+
const orphanExpanded = new Set();
|
|
48
|
+
for (const raw of document.edges ?? []) {
|
|
49
|
+
for (const endpoint of [raw.from, raw.to]) {
|
|
50
|
+
const schemaName = extractSchemaName(endpoint);
|
|
51
|
+
if (!schemaName)
|
|
52
|
+
continue;
|
|
53
|
+
const schemaRef = `#/components/schemas/${schemaName}`;
|
|
54
|
+
if (refToNodeId.has(schemaRef) || orphanExpanded.has(schemaName))
|
|
55
|
+
continue;
|
|
56
|
+
orphanExpanded.add(schemaName);
|
|
57
|
+
const schemaLocalName = schemaName.includes('.')
|
|
58
|
+
? schemaName.slice(schemaName.lastIndexOf('.') + 1)
|
|
59
|
+
: schemaName;
|
|
60
|
+
const schemaId = `${schemaLocalName}.schemas.${schemaLocalName}`;
|
|
61
|
+
refToNodeId.set(schemaRef, schemaId);
|
|
62
|
+
nodes.push(makeNode('Schema', '_', specPath, schemaId, undefined, {}));
|
|
63
|
+
const schemaDef = allSchemas[schemaName];
|
|
64
|
+
for (const fieldName of Object.keys(schemaDef?.properties ?? {})) {
|
|
65
|
+
const fieldId = `${schemaId}.fields.${fieldName}`;
|
|
66
|
+
refToNodeId.set(`${schemaRef}/properties/${fieldName}`, fieldId);
|
|
67
|
+
nodes.push(makeNode('Field', '_', specPath, fieldId, undefined, {}));
|
|
68
|
+
edges.push(makeHasFieldEdge(schemaId, fieldId));
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(schemaDef?.enum)) {
|
|
71
|
+
for (const value of schemaDef.enum) {
|
|
72
|
+
if (typeof value !== 'string')
|
|
73
|
+
continue;
|
|
74
|
+
const fieldId = `${schemaId}.values.${value}`;
|
|
75
|
+
refToNodeId.set(`${schemaRef}/properties/${value}`, fieldId);
|
|
76
|
+
nodes.push(makeNode('EnumValue', '_', specPath, fieldId, undefined, { value }));
|
|
77
|
+
edges.push(makeHasFieldEdge(schemaId, fieldId));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Build case-insensitive fallback index to handle PascalCase/camelCase mismatches
|
|
83
|
+
// between edge field refs and actual schema property names
|
|
84
|
+
const refToNodeIdLower = new Map([...refToNodeId.entries()].map(([k, v]) => [k.toLowerCase(), v]));
|
|
42
85
|
for (const raw of document.edges ?? []) {
|
|
43
86
|
if (!VALID_EDGE_TYPES.has(raw.type)) {
|
|
44
87
|
diagnostics.push({
|
|
@@ -48,7 +91,17 @@ export function mapDocument(document, specPath) {
|
|
|
48
91
|
});
|
|
49
92
|
continue;
|
|
50
93
|
}
|
|
51
|
-
|
|
94
|
+
const from = refToNodeId.get(raw.from) ?? refToNodeIdLower.get(raw.from.toLowerCase()) ?? raw.from;
|
|
95
|
+
const to = refToNodeId.get(raw.to) ?? refToNodeIdLower.get(raw.to.toLowerCase()) ?? raw.to;
|
|
96
|
+
if (from.startsWith('#/') || to.startsWith('#/')) {
|
|
97
|
+
diagnostics.push({
|
|
98
|
+
severity: 'warning',
|
|
99
|
+
file: specPath,
|
|
100
|
+
message: `edge references unresolvable node — skipping: ${from} → ${to}`,
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
edges.push(mapEdge({ ...raw, from, to }));
|
|
52
105
|
}
|
|
53
106
|
return { nodes, edges, diagnostics };
|
|
54
107
|
}
|
|
@@ -58,12 +111,28 @@ function schemaRefName(ref) {
|
|
|
58
111
|
return undefined;
|
|
59
112
|
return ref.slice(prefix.length);
|
|
60
113
|
}
|
|
61
|
-
function
|
|
114
|
+
function extractSchemaName(endpoint) {
|
|
115
|
+
const prefix = '#/components/schemas/';
|
|
116
|
+
if (!endpoint.startsWith(prefix))
|
|
117
|
+
return undefined;
|
|
118
|
+
return endpoint.slice(prefix.length).split('/')[0];
|
|
119
|
+
}
|
|
120
|
+
function expandSchema(schemaName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId) {
|
|
62
121
|
const existing = expanded.get(schemaName);
|
|
63
122
|
if (existing)
|
|
64
123
|
return existing;
|
|
65
|
-
|
|
124
|
+
// Schema names from corum extractors are sometimes prefixed with the component name
|
|
125
|
+
// (e.g. "workers.ReactToPersonCreatedCommand"). Strip the prefix so the local segment
|
|
126
|
+
// in the node ID is a simple identifier — graph serialization rejects local names
|
|
127
|
+
// that contain dots because it uses dots as a hierarchy separator.
|
|
128
|
+
const schemaLocalName = schemaName.includes('.')
|
|
129
|
+
? schemaName.slice(schemaName.lastIndexOf('.') + 1)
|
|
130
|
+
: schemaName;
|
|
131
|
+
const schemaId = `${rootNodeId}.schemas.${schemaLocalName}`;
|
|
66
132
|
expanded.set(schemaName, schemaId);
|
|
133
|
+
const schemaRef = `#/components/schemas/${schemaName}`;
|
|
134
|
+
if (!refToNodeId.has(schemaRef))
|
|
135
|
+
refToNodeId.set(schemaRef, schemaId);
|
|
67
136
|
const schemaDef = allSchemas[schemaName];
|
|
68
137
|
const schemaNode = makeNode('Schema', component, specPath, schemaId, undefined, {});
|
|
69
138
|
nodes.push(schemaNode);
|
|
@@ -71,20 +140,37 @@ function expandSchema(schemaName, rootNodeId, allSchemas, nodes, edges, specPath
|
|
|
71
140
|
const localMappings = new Map();
|
|
72
141
|
for (const [fieldName, rawProp] of Object.entries(schemaDef?.properties ?? {})) {
|
|
73
142
|
const fieldId = `${schemaId}.fields.${fieldName}`;
|
|
143
|
+
const fieldRef = `${schemaRef}/properties/${fieldName}`;
|
|
144
|
+
if (!refToNodeId.has(fieldRef))
|
|
145
|
+
refToNodeId.set(fieldRef, fieldId);
|
|
74
146
|
const fieldNode = makeNode('Field', component, specPath, fieldId, undefined, {});
|
|
75
147
|
const required = Array.isArray(schemaDef?.required) && schemaDef.required.includes(fieldName);
|
|
76
|
-
fieldNode.properties = resolveFieldProperties(fieldName, rawProp, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
148
|
+
fieldNode.properties = resolveFieldProperties(fieldName, rawProp, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings, refToNodeId);
|
|
77
149
|
nodes.push(fieldNode);
|
|
78
150
|
edges.push(makeHasFieldEdge(schemaId, fieldId));
|
|
79
151
|
}
|
|
152
|
+
// Register enum values as field refs so edges referencing them (as /properties/{value}) can resolve
|
|
153
|
+
if (Array.isArray(schemaDef?.enum)) {
|
|
154
|
+
for (const value of schemaDef.enum) {
|
|
155
|
+
if (typeof value !== 'string')
|
|
156
|
+
continue;
|
|
157
|
+
const fieldRef = `${schemaRef}/properties/${value}`;
|
|
158
|
+
if (!refToNodeId.has(fieldRef)) {
|
|
159
|
+
const fieldId = `${schemaId}.values.${value}`;
|
|
160
|
+
refToNodeId.set(fieldRef, fieldId);
|
|
161
|
+
nodes.push(makeNode('EnumValue', component, specPath, fieldId, undefined, { value }));
|
|
162
|
+
edges.push(makeHasFieldEdge(schemaId, fieldId));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
80
166
|
return schemaId;
|
|
81
167
|
}
|
|
82
|
-
function resolveFieldProperties(fieldName, prop, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings) {
|
|
168
|
+
function resolveFieldProperties(fieldName, prop, required, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings, refToNodeId) {
|
|
83
169
|
const nullable = !required;
|
|
84
170
|
if (typeof prop.$ref === 'string') {
|
|
85
171
|
const refName = schemaRefName(prop.$ref);
|
|
86
172
|
if (refName) {
|
|
87
|
-
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
173
|
+
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId);
|
|
88
174
|
return { $ref: refId, nullable, collection: 'one' };
|
|
89
175
|
}
|
|
90
176
|
return { type: 'string', nullable, collection: 'one' };
|
|
@@ -95,7 +181,7 @@ function resolveFieldProperties(fieldName, prop, required, schemaId, rootNodeId,
|
|
|
95
181
|
if (items && typeof items.$ref === 'string') {
|
|
96
182
|
const refName = schemaRefName(items.$ref);
|
|
97
183
|
if (refName) {
|
|
98
|
-
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
184
|
+
const refId = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId);
|
|
99
185
|
return { $ref: refId, nullable, collection: 'array' };
|
|
100
186
|
}
|
|
101
187
|
}
|
|
@@ -103,13 +189,13 @@ function resolveFieldProperties(fieldName, prop, required, schemaId, rootNodeId,
|
|
|
103
189
|
return { type: itemType, nullable, collection: 'array' };
|
|
104
190
|
}
|
|
105
191
|
if (type === 'object' && prop.additionalProperties !== undefined) {
|
|
106
|
-
createMapping(fieldName, prop.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
192
|
+
createMapping(fieldName, prop.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings, refToNodeId);
|
|
107
193
|
return { $ref: `#/mappings/${fieldName}`, nullable, collection: 'one' };
|
|
108
194
|
}
|
|
109
195
|
const scalarType = mapScalar(type ?? 'string', prop.format);
|
|
110
196
|
return { type: scalarType, nullable, collection: 'one' };
|
|
111
197
|
}
|
|
112
|
-
function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings) {
|
|
198
|
+
function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings, refToNodeId) {
|
|
113
199
|
const existing = localMappings.get(mappingName);
|
|
114
200
|
if (existing)
|
|
115
201
|
return existing;
|
|
@@ -125,7 +211,7 @@ function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, n
|
|
|
125
211
|
if (typeof addl.$ref === 'string') {
|
|
126
212
|
const refName = schemaRefName(addl.$ref);
|
|
127
213
|
if (refName) {
|
|
128
|
-
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
214
|
+
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId);
|
|
129
215
|
}
|
|
130
216
|
else {
|
|
131
217
|
props.type = 'string';
|
|
@@ -137,7 +223,7 @@ function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, n
|
|
|
137
223
|
if (items && typeof items.$ref === 'string') {
|
|
138
224
|
const refName = schemaRefName(items.$ref);
|
|
139
225
|
if (refName) {
|
|
140
|
-
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded);
|
|
226
|
+
props.$ref = expandSchema(refName, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, refToNodeId);
|
|
141
227
|
}
|
|
142
228
|
else {
|
|
143
229
|
props.type = 'string';
|
|
@@ -149,7 +235,7 @@ function createMapping(mappingName, addlDef, schemaId, rootNodeId, allSchemas, n
|
|
|
149
235
|
}
|
|
150
236
|
else if (addl.type === 'object' && addl.additionalProperties !== undefined) {
|
|
151
237
|
const innerName = `${mappingName}-values`;
|
|
152
|
-
props.$ref = createMapping(innerName, addl.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings);
|
|
238
|
+
props.$ref = createMapping(innerName, addl.additionalProperties, schemaId, rootNodeId, allSchemas, nodes, edges, specPath, component, expanded, localMappings, refToNodeId);
|
|
153
239
|
}
|
|
154
240
|
else {
|
|
155
241
|
props.type = mapScalar(addl.type ?? 'string', addl.format);
|
package/dist/src/web/server.js
CHANGED
|
@@ -415,12 +415,18 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
415
415
|
nodesWithEdges.add(edge.to);
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
|
-
const
|
|
419
|
-
|
|
418
|
+
const orphansByTemplate = {};
|
|
419
|
+
for (const node of targetGraph.nodesById.values()) {
|
|
420
|
+
if (!nodesWithEdges.has(node.id) && getNavigationOwnership(targetGraph, node) === undefined) {
|
|
421
|
+
orphansByTemplate[node.template] = (orphansByTemplate[node.template] ?? 0) + 1;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const orphanNodeCount = Object.values(orphansByTemplate).reduce((a, b) => a + b, 0);
|
|
420
425
|
res.json({
|
|
421
426
|
nodeCount: targetGraph.nodesById.size,
|
|
422
427
|
componentCount: components.size,
|
|
423
428
|
orphanNodeCount,
|
|
429
|
+
orphansByTemplate,
|
|
424
430
|
edgesByType,
|
|
425
431
|
diagnosticCount: targetGraph.diagnostics.length,
|
|
426
432
|
});
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -555,6 +555,10 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
555
555
|
? Object.entries(stats.edgesByType).filter(([, count]) => count > 0).sort((a, b) => b[1] - a[1])
|
|
556
556
|
: [];
|
|
557
557
|
|
|
558
|
+
const orphanRows = stats
|
|
559
|
+
? Object.entries(stats.orphansByTemplate).sort((a, b) => b[1] - a[1])
|
|
560
|
+
: [];
|
|
561
|
+
|
|
558
562
|
return (
|
|
559
563
|
<div className="content">
|
|
560
564
|
<div className="dashboard-hero">
|
|
@@ -597,14 +601,23 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
597
601
|
</div>
|
|
598
602
|
|
|
599
603
|
<div className="dashboard-panel">
|
|
600
|
-
<div className="card-head">
|
|
604
|
+
<div className="card-head">Orphan Nodes by Type</div>
|
|
601
605
|
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
602
|
-
{
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
606
|
+
{stats === null && <div className="label-sm">Loading…</div>}
|
|
607
|
+
{stats !== null && orphanRows.length === 0 && <div className="label-sm">No orphan nodes.</div>}
|
|
608
|
+
{orphanRows.map(([name, count]) => {
|
|
609
|
+
const tmpl = templateMap.get(name);
|
|
610
|
+
const colour = tmpl?.ui?.colour ?? 'var(--ink-4)';
|
|
611
|
+
return (
|
|
612
|
+
<div key={name} className="stat-row">
|
|
613
|
+
<span className="stat-row-label">
|
|
614
|
+
<span className="stat-colour-dot" style={{ background: colour }} />
|
|
615
|
+
{tmpl?.ui?.displayName ?? name}
|
|
616
|
+
</span>
|
|
617
|
+
<span className="stat-row-value">{count}</span>
|
|
618
|
+
</div>
|
|
619
|
+
);
|
|
620
|
+
})}
|
|
608
621
|
</div>
|
|
609
622
|
</div>
|
|
610
623
|
|
|
@@ -625,8 +638,15 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
625
638
|
</div>
|
|
626
639
|
|
|
627
640
|
<div className="dashboard-panel">
|
|
628
|
-
<div className="card-head">Stability</div>
|
|
641
|
+
<div className="card-head">State & Stability</div>
|
|
629
642
|
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
643
|
+
{nodesByState.map(([state, count]) => (
|
|
644
|
+
<div key={state} className="stat-row">
|
|
645
|
+
<span className="stat-row-label"><StateTag state={state} /></span>
|
|
646
|
+
<span className="stat-row-value">{count}</span>
|
|
647
|
+
</div>
|
|
648
|
+
))}
|
|
649
|
+
<div style={{ borderTop: '1px solid var(--rule-2)', margin: '8px 0' }} />
|
|
630
650
|
{nodesByStability.map(([stability, count]) => (
|
|
631
651
|
<div key={stability} className="stat-row">
|
|
632
652
|
<span className="stat-row-label"><StabilityTag stability={stability} /></span>
|