@atolis-hq/corum 0.1.24 → 0.1.25
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/asyncapi/mapper.js +3 -12
- package/dist/src/adapters/openapi/mapper.js +3 -14
- package/dist/src/loader/cluster-loader.js +74 -3
- package/dist/src/writer/graph-writer.js +1 -1
- package/package.json +1 -1
- package/web/app.jsx +62 -26
- package/web/nav.js +6 -4
- package/web/style.css +3 -0
|
@@ -328,7 +328,6 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
328
328
|
if (payloadSchemaName) {
|
|
329
329
|
const globalId = sharedSchemas.get(payloadSchemaName);
|
|
330
330
|
if (globalId) {
|
|
331
|
-
emitReadsEdge(eventId, globalId, edges);
|
|
332
331
|
properties.payload = globalId;
|
|
333
332
|
}
|
|
334
333
|
else {
|
|
@@ -387,12 +386,6 @@ function makeNode(template, component, specPath, id) {
|
|
|
387
386
|
properties: {},
|
|
388
387
|
};
|
|
389
388
|
}
|
|
390
|
-
function emitReadsEdge(from, to, edges) {
|
|
391
|
-
const id = `${from}__reads__${to}`;
|
|
392
|
-
if (!edges.some(e => e.id === id)) {
|
|
393
|
-
edges.push({ id, from, to, type: 'reads', state: 'implemented', stability: 'unstable' });
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
389
|
function refName(ref) {
|
|
397
390
|
return ref.split('/').pop() ?? ref;
|
|
398
391
|
}
|
|
@@ -407,13 +400,12 @@ function resolveAllOfRef(schema) {
|
|
|
407
400
|
return s.allOf[0];
|
|
408
401
|
return schema;
|
|
409
402
|
}
|
|
410
|
-
function resolveSchemaRef(schemaName, nullable, collection,
|
|
403
|
+
function resolveSchemaRef(schemaName, nullable, collection, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
411
404
|
const extra = { nullable };
|
|
412
405
|
if (collection)
|
|
413
406
|
extra.collection = collection;
|
|
414
407
|
const globalId = sharedSchemas.get(schemaName);
|
|
415
408
|
if (globalId) {
|
|
416
|
-
emitReadsEdge(readsSource, globalId, edges);
|
|
417
409
|
return { $ref: globalId, ...extra };
|
|
418
410
|
}
|
|
419
411
|
if (localSchemas.has(schemaName))
|
|
@@ -482,7 +474,6 @@ function createMapping(mappingName, addlRaw, parentId, rootId, component, packCo
|
|
|
482
474
|
return mappingId;
|
|
483
475
|
}
|
|
484
476
|
function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
485
|
-
const readsSource = rootId ?? parentId;
|
|
486
477
|
const [component] = parentId.split('.');
|
|
487
478
|
for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
|
|
488
479
|
const resolvedSchemaId = componentSchemaIdOf(rawFieldSchema);
|
|
@@ -495,7 +486,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
495
486
|
? resolvedSchemaId
|
|
496
487
|
: (isRefSchema(fieldSchema) ? refName(fieldSchema.$ref) : undefined);
|
|
497
488
|
if (schemaName !== undefined) {
|
|
498
|
-
fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined,
|
|
489
|
+
fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
499
490
|
}
|
|
500
491
|
else {
|
|
501
492
|
const fs = fieldSchema;
|
|
@@ -514,7 +505,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
514
505
|
fieldNode.properties = { type: 'string', nullable, collection: 'array' };
|
|
515
506
|
}
|
|
516
507
|
else if (isRefSchema(items)) {
|
|
517
|
-
fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array',
|
|
508
|
+
fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array', rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
518
509
|
if (!fieldNode.properties.$ref)
|
|
519
510
|
fieldNode.properties = { type: 'string', nullable, collection: 'array' };
|
|
520
511
|
}
|
|
@@ -37,12 +37,6 @@ export function deriveNodeId(kind, component, name, parentId, section) {
|
|
|
37
37
|
export function refName(ref) {
|
|
38
38
|
return ref.split('/').pop() ?? ref;
|
|
39
39
|
}
|
|
40
|
-
function emitReadsEdge(from, to, edges) {
|
|
41
|
-
const id = `${from}__reads__${to}`;
|
|
42
|
-
if (!edges.some(e => e.id === id)) {
|
|
43
|
-
edges.push({ id, from, to, type: 'reads', state: 'implemented', stability: 'unstable' });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
40
|
export function mapDocument(document, entry, packConfig, componentNameReplacements = []) {
|
|
47
41
|
const nodes = [];
|
|
48
42
|
const edges = [];
|
|
@@ -283,8 +277,6 @@ function emitSchemaNode(schema, name, parentId, section, rootId, packConfig, spe
|
|
|
283
277
|
const schemaName = refName(schema.$ref);
|
|
284
278
|
const globalId = sharedSchemas.get(schemaName);
|
|
285
279
|
if (globalId) {
|
|
286
|
-
if (rootId)
|
|
287
|
-
emitReadsEdge(rootId, globalId, edges);
|
|
288
280
|
return globalId;
|
|
289
281
|
}
|
|
290
282
|
if (localSchemas.has(schemaName))
|
|
@@ -311,13 +303,12 @@ function createInlineSchema(schema, name, parentId, section, rootId, packConfig,
|
|
|
311
303
|
emitFields(schema, schemaId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
312
304
|
return localRef;
|
|
313
305
|
}
|
|
314
|
-
function resolveFieldRef(schemaName, collection, required, rootId,
|
|
306
|
+
function resolveFieldRef(schemaName, collection, required, rootId, refSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
315
307
|
const extra = { nullable: !required };
|
|
316
308
|
if (collection !== 'one')
|
|
317
309
|
extra.collection = collection;
|
|
318
310
|
const globalId = sharedSchemas.get(schemaName);
|
|
319
311
|
if (globalId) {
|
|
320
|
-
emitReadsEdge(readsSource, globalId, edges);
|
|
321
312
|
return { $ref: globalId, ...extra };
|
|
322
313
|
}
|
|
323
314
|
if (localSchemas.has(schemaName))
|
|
@@ -411,8 +402,6 @@ function createMapping(mappingName, addlRaw, parentId, rootId, packConfig, specP
|
|
|
411
402
|
return mappingId;
|
|
412
403
|
}
|
|
413
404
|
function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
414
|
-
// readsSource: when in endpoint context use rootId, otherwise use the schema itself
|
|
415
|
-
const readsSource = rootId ?? parentId;
|
|
416
405
|
for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
|
|
417
406
|
const fieldSchema = resolveAllOfRef(rawFieldSchema);
|
|
418
407
|
const fieldId = deriveNodeId('field', undefined, fieldName, parentId, section);
|
|
@@ -420,7 +409,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
420
409
|
const fieldNode = makeNode(packConfig.constructs.schemaProperty?.template ?? 'Field', component, specPath, fieldId);
|
|
421
410
|
const required = Array.isArray(schema.required) && schema.required.includes(fieldName);
|
|
422
411
|
if (isRefSchema(fieldSchema)) {
|
|
423
|
-
fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId,
|
|
412
|
+
fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId, fieldSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
424
413
|
}
|
|
425
414
|
else {
|
|
426
415
|
const fs = fieldSchema;
|
|
@@ -435,7 +424,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
435
424
|
fieldNode.properties = { type: 'string', nullable: !required, collection: 'array' };
|
|
436
425
|
}
|
|
437
426
|
else if (isRefSchema(items)) {
|
|
438
|
-
fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId,
|
|
427
|
+
fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
439
428
|
}
|
|
440
429
|
else {
|
|
441
430
|
const itemType = deriveScalarType(items.type ?? 'string', items.format, packConfig.scalarTypes);
|
|
@@ -38,11 +38,64 @@ export function loadClusters(content, templates, diagnostics) {
|
|
|
38
38
|
properties: isRecord(record.properties) ? record.properties : {},
|
|
39
39
|
};
|
|
40
40
|
addNode(result, root, key, diagnostics);
|
|
41
|
-
|
|
41
|
+
const rootTemplate = templates.get(root.template);
|
|
42
|
+
if (rootTemplate) {
|
|
43
|
+
for (const target of getNodeRefTargets(root, rootTemplate)) {
|
|
44
|
+
const readsId = `${root.id}__reads__${target}`;
|
|
45
|
+
const existingFrom = result.edgesByFrom.get(root.id) ?? [];
|
|
46
|
+
if (!existingFrom.some(e => e.id === readsId)) {
|
|
47
|
+
addEdge(result, {
|
|
48
|
+
id: readsId, from: root.id, to: target, type: 'reads',
|
|
49
|
+
state: root.state, stability: root.stability, generated: true,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
materialiseChildren(result, root, root, record, templates, key, diagnostics);
|
|
42
55
|
}
|
|
43
56
|
return result;
|
|
44
57
|
}
|
|
45
|
-
function
|
|
58
|
+
function getPropertySchemasFromTemplate(props) {
|
|
59
|
+
if (Array.isArray(props.allOf)) {
|
|
60
|
+
const merged = {};
|
|
61
|
+
for (const schema of props.allOf) {
|
|
62
|
+
Object.assign(merged, getPropertySchemasFromTemplate(schema));
|
|
63
|
+
}
|
|
64
|
+
return merged;
|
|
65
|
+
}
|
|
66
|
+
if (typeof props.properties === 'object' && props.properties !== null) {
|
|
67
|
+
return props.properties;
|
|
68
|
+
}
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
function getNodeRefTargets(node, template) {
|
|
72
|
+
if (!template.properties)
|
|
73
|
+
return [];
|
|
74
|
+
const propSchemas = getPropertySchemasFromTemplate(template.properties);
|
|
75
|
+
const targets = [];
|
|
76
|
+
for (const [key, schema] of Object.entries(propSchemas)) {
|
|
77
|
+
const s = schema;
|
|
78
|
+
if (s.format === 'node-ref') {
|
|
79
|
+
const value = node.properties[key];
|
|
80
|
+
if (typeof value === 'string' && !value.startsWith('#/'))
|
|
81
|
+
targets.push(value);
|
|
82
|
+
}
|
|
83
|
+
else if (s.type === 'object' &&
|
|
84
|
+
typeof s.additionalProperties === 'object' &&
|
|
85
|
+
s.additionalProperties !== null &&
|
|
86
|
+
s.additionalProperties.format === 'node-ref') {
|
|
87
|
+
const map = node.properties[key];
|
|
88
|
+
if (typeof map === 'object' && map !== null && !Array.isArray(map)) {
|
|
89
|
+
for (const value of Object.values(map)) {
|
|
90
|
+
if (typeof value === 'string' && !value.startsWith('#/'))
|
|
91
|
+
targets.push(value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return targets;
|
|
97
|
+
}
|
|
98
|
+
function materialiseChildren(result, parent, clusterRoot, source, templates, filePath, diagnostics) {
|
|
46
99
|
const template = templates.get(parent.template);
|
|
47
100
|
if (!template) {
|
|
48
101
|
diagnostics.push({ severity: 'error', file: filePath, nodeId: parent.id, message: `unknown template: ${parent.template}` });
|
|
@@ -85,7 +138,25 @@ function materialiseChildren(result, parent, source, templates, filePath, diagno
|
|
|
85
138
|
stability: child.stability,
|
|
86
139
|
});
|
|
87
140
|
}
|
|
88
|
-
|
|
141
|
+
const childTemplate = templates.get(child.template);
|
|
142
|
+
if (childTemplate) {
|
|
143
|
+
for (const target of getNodeRefTargets(child, childTemplate)) {
|
|
144
|
+
const readsId = `${clusterRoot.id}__reads__${target}`;
|
|
145
|
+
const existingFrom = result.edgesByFrom.get(clusterRoot.id) ?? [];
|
|
146
|
+
if (!existingFrom.some(e => e.id === readsId)) {
|
|
147
|
+
addEdge(result, {
|
|
148
|
+
id: readsId,
|
|
149
|
+
from: clusterRoot.id,
|
|
150
|
+
to: target,
|
|
151
|
+
type: 'reads',
|
|
152
|
+
state: clusterRoot.state,
|
|
153
|
+
stability: clusterRoot.stability,
|
|
154
|
+
generated: true,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
materialiseChildren(result, child, clusterRoot, value, templates, filePath, diagnostics);
|
|
89
160
|
}
|
|
90
161
|
}
|
|
91
162
|
}
|
|
@@ -13,7 +13,7 @@ export function serializeGraph(graph, options = {}) {
|
|
|
13
13
|
map.set(clusterPath(root), stringifyGraphYaml(toClusterDocument(graph, root)));
|
|
14
14
|
}
|
|
15
15
|
const explicitEdges = getAllEdges(graph)
|
|
16
|
-
.filter(edge => !STRUCTURAL_EDGE_TYPES.has(edge.type))
|
|
16
|
+
.filter(edge => !STRUCTURAL_EDGE_TYPES.has(edge.type) && edge.generated !== true)
|
|
17
17
|
.sort((a, b) => a.id.localeCompare(b.id));
|
|
18
18
|
if (explicitEdges.length > 0) {
|
|
19
19
|
map.set('edges/corum.edges.yaml', stringifyGraphYaml({ edges: explicitEdges.map(toEdgeDocument) }));
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -114,6 +114,7 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
114
114
|
const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
|
|
115
115
|
const [openComponent, setOpenComponent] = useState();
|
|
116
116
|
const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
|
|
117
|
+
const [openGroupKeys, setOpenGroupKeys] = useState(new Set());
|
|
117
118
|
const templateMap = new Map(templates.map(template => [template.name, template]));
|
|
118
119
|
|
|
119
120
|
function openComponentWithEntries(component) {
|
|
@@ -152,6 +153,26 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
152
153
|
}
|
|
153
154
|
}, [activeNodeId, navTree]);
|
|
154
155
|
|
|
156
|
+
// Auto-expand groups for the active node; collapse all others.
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!activeNodeId || !navTree.size) return;
|
|
159
|
+
for (const entries of navTree.values()) {
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
if (entry.kind === 'group') continue;
|
|
162
|
+
for (const node of entry.nodes) {
|
|
163
|
+
const isOwner =
|
|
164
|
+
node.id === activeNodeId ||
|
|
165
|
+
(node.navChildren ?? []).some(g => g.nodes.some(c => c.id === activeNodeId));
|
|
166
|
+
if (isOwner) {
|
|
167
|
+
setOpenGroupKeys(new Set((node.navChildren ?? []).map(g => `${node.id}:${g.label}`)));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
setOpenGroupKeys(new Set());
|
|
174
|
+
}, [activeNodeId, navTree]);
|
|
175
|
+
|
|
155
176
|
function toggleComponent(component) {
|
|
156
177
|
if (openComponent === component) { openComponentWithEntries(null); }
|
|
157
178
|
else { openComponentWithEntries(component); }
|
|
@@ -257,32 +278,47 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
257
278
|
>
|
|
258
279
|
{displayName(node.id)}
|
|
259
280
|
</div>
|
|
260
|
-
{(node.navChildren ?? []).map(group =>
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
281
|
+
{(node.navChildren ?? []).map(group => {
|
|
282
|
+
const groupKey = `${node.id}:${group.label}`;
|
|
283
|
+
const groupOpen = openGroupKeys.has(groupKey);
|
|
284
|
+
return (
|
|
285
|
+
<div className="nav-child-group" key={group.label}>
|
|
286
|
+
<div
|
|
287
|
+
className="nav-child-head"
|
|
288
|
+
style={{ cursor: 'pointer' }}
|
|
289
|
+
onClick={() => setOpenGroupKeys(prev => {
|
|
290
|
+
const next = new Set(prev);
|
|
291
|
+
next.has(groupKey) ? next.delete(groupKey) : next.add(groupKey);
|
|
292
|
+
return next;
|
|
293
|
+
})}
|
|
294
|
+
>
|
|
295
|
+
{group.label}
|
|
296
|
+
<Icon name={groupOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
297
|
+
</div>
|
|
298
|
+
{groupOpen && group.nodes.map(child => {
|
|
299
|
+
const childTemplate = templateMap.get(child.template);
|
|
300
|
+
const childColour = childTemplate?.ui?.colour ?? colour;
|
|
301
|
+
const childIsActive = child.id === activeNodeId;
|
|
302
|
+
return (
|
|
303
|
+
<div
|
|
304
|
+
key={child.id}
|
|
305
|
+
className={`nav-node-item nav-node-child${childIsActive ? ' active' : ''}`}
|
|
306
|
+
onClick={() => onNode(child.id)}
|
|
307
|
+
title={child.id}
|
|
308
|
+
style={childIsActive ? { '--nav-node-active-bg': childColour } : undefined}
|
|
309
|
+
>
|
|
310
|
+
{displayName(child.id)}
|
|
311
|
+
{overlayIndicatorIds && overlayIndicatorIds.has(child.id) && (
|
|
312
|
+
<span className="signal-dots">
|
|
313
|
+
<span className="signal-dot signal-dot-0" />
|
|
314
|
+
</span>
|
|
315
|
+
)}
|
|
316
|
+
</div>
|
|
317
|
+
);
|
|
318
|
+
})}
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
})}
|
|
286
322
|
</div>
|
|
287
323
|
);
|
|
288
324
|
})}
|
package/web/nav.js
CHANGED
|
@@ -46,10 +46,12 @@ function buildNavTree(nodes, templates) {
|
|
|
46
46
|
if (nestedNodeIds.has(node.id)) continue;
|
|
47
47
|
const template = templateMap.get(node.template);
|
|
48
48
|
const navGroup = template?.ui?.nav?.navGroup;
|
|
49
|
-
const navChildren = [...(nestedByParent.get(node.id)?.values() ?? [])]
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const navChildren = [...(nestedByParent.get(node.id)?.values() ?? [])]
|
|
50
|
+
.sort((a, b) => a.label.localeCompare(b.label))
|
|
51
|
+
.map(group => ({
|
|
52
|
+
label: group.label,
|
|
53
|
+
nodes: group.nodes.sort((a, b) => a.id.localeCompare(b.id)),
|
|
54
|
+
}));
|
|
53
55
|
const nodeWithChildren = { ...node, navChildren };
|
|
54
56
|
|
|
55
57
|
if (navGroup) {
|