@atolis-hq/corum 0.1.20 → 0.1.22
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/README.md +29 -0
- package/dist/src/adapters/corum/index.js +12 -0
- package/dist/src/adapters/corum/mapper.js +67 -0
- package/dist/src/adapters/corum/parser.js +41 -0
- package/dist/src/adapters/index.js +2 -0
- package/dist/src/bin/corum.js +18 -0
- package/dist/src/writer/graph-writer.js +4 -4
- package/package.json +1 -1
- package/web/app.jsx +59 -13
package/README.md
CHANGED
|
@@ -98,6 +98,7 @@ Examples:
|
|
|
98
98
|
```bash
|
|
99
99
|
corum pack install domain
|
|
100
100
|
corum pack install domain@v0.1.5
|
|
101
|
+
corum pack install extract # required for corum-extract import adapter
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
### `corum pack list`
|
|
@@ -183,6 +184,34 @@ Options:
|
|
|
183
184
|
--graph <path> Override the graph directory
|
|
184
185
|
```
|
|
185
186
|
|
|
187
|
+
#### `corum import corum <spec>`
|
|
188
|
+
|
|
189
|
+
Import a corum interchange file (`*.corum.yaml`) produced by `corum-extract` or compatible extraction tooling.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
corum import corum <spec> [options]
|
|
193
|
+
|
|
194
|
+
Options:
|
|
195
|
+
--graph <path> Override the graph directory
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The interchange format is self-describing — no component mapping strategy is needed. Node IDs, template names, and field references are already corum-native. Gaps reported by the extractor (unresolved types, name collisions) are surfaced as warnings.
|
|
199
|
+
|
|
200
|
+
Requires the `extract` pack to be active in your graph:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
corum pack install extract
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
You can also configure corum imports in a config file:
|
|
207
|
+
|
|
208
|
+
```yaml
|
|
209
|
+
# .corum/imports.yaml
|
|
210
|
+
imports:
|
|
211
|
+
- adapter: corum
|
|
212
|
+
spec: path/to/output.corum.yaml
|
|
213
|
+
```
|
|
214
|
+
|
|
186
215
|
## Configuration
|
|
187
216
|
|
|
188
217
|
Run `corum init` to generate a `.corum/config.yaml` with all available options. Corum walks up from the current directory to find it, so you can place it at your project root.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseSpec } from './parser.js';
|
|
2
|
+
import { mapDocument } from './mapper.js';
|
|
3
|
+
export class CorumAdapter {
|
|
4
|
+
adapterId = 'corum';
|
|
5
|
+
async import(entry, _context) {
|
|
6
|
+
const { document, diagnostics } = parseSpec(entry.spec);
|
|
7
|
+
if (!document)
|
|
8
|
+
return { nodes: [], edges: [], diagnostics };
|
|
9
|
+
const { nodes, edges, diagnostics: mapDiagnostics } = mapDocument(document, entry.spec);
|
|
10
|
+
return { nodes, edges, diagnostics: [...diagnostics, ...mapDiagnostics] };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const VALID_EDGE_TYPES = new Set([
|
|
2
|
+
'triggers', 'produces', 'reads', 'calls', 'implements',
|
|
3
|
+
'maps-to', 'derived-from', 'renamed-from', 'has-field', 'has-value',
|
|
4
|
+
]);
|
|
5
|
+
export function mapDocument(document, specPath) {
|
|
6
|
+
const nodes = [];
|
|
7
|
+
const edges = [];
|
|
8
|
+
const diagnostics = [];
|
|
9
|
+
for (const gap of document.gaps ?? []) {
|
|
10
|
+
const msg = gap.nodeId
|
|
11
|
+
? `[${gap.kind}] ${gap.nodeId}: ${gap.reason ?? ''}`
|
|
12
|
+
: `[${gap.kind}] ${gap.reason ?? ''}`;
|
|
13
|
+
diagnostics.push({ severity: 'warning', file: specPath, message: msg });
|
|
14
|
+
}
|
|
15
|
+
for (const raw of document.nodes) {
|
|
16
|
+
if (!raw.id || !raw.template) {
|
|
17
|
+
diagnostics.push({ severity: 'warning', file: specPath, message: `Node missing id or template — skipping` });
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
nodes.push(mapNode(raw, specPath));
|
|
21
|
+
}
|
|
22
|
+
for (const raw of document.edges ?? []) {
|
|
23
|
+
if (!VALID_EDGE_TYPES.has(raw.type)) {
|
|
24
|
+
diagnostics.push({
|
|
25
|
+
severity: 'warning',
|
|
26
|
+
file: specPath,
|
|
27
|
+
message: `Unknown edge type '${raw.type}' from '${raw.from}' to '${raw.to}' — skipping`,
|
|
28
|
+
});
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
edges.push(mapEdge(raw));
|
|
32
|
+
}
|
|
33
|
+
return { nodes, edges, diagnostics };
|
|
34
|
+
}
|
|
35
|
+
function mapNode(raw, specPath) {
|
|
36
|
+
return {
|
|
37
|
+
id: raw.id,
|
|
38
|
+
template: raw.template,
|
|
39
|
+
component: raw.id.split('.')[0],
|
|
40
|
+
state: 'implemented',
|
|
41
|
+
stability: 'unstable',
|
|
42
|
+
schemaVersion: '1',
|
|
43
|
+
lastModifiedAt: new Date().toISOString().split('T')[0],
|
|
44
|
+
extractedFrom: specPath,
|
|
45
|
+
derivation: derivationOf(raw.provenance),
|
|
46
|
+
derivedBy: derivedByOf(raw.provenance),
|
|
47
|
+
properties: raw.properties ?? {},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function mapEdge(raw) {
|
|
51
|
+
return {
|
|
52
|
+
id: `${raw.from}__${raw.type}__${raw.to}`,
|
|
53
|
+
from: raw.from,
|
|
54
|
+
to: raw.to,
|
|
55
|
+
type: raw.type,
|
|
56
|
+
state: 'implemented',
|
|
57
|
+
stability: 'unstable',
|
|
58
|
+
derivation: derivationOf(raw.provenance),
|
|
59
|
+
derivedBy: derivedByOf(raw.provenance),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { parse as parseYaml } from 'yaml';
|
|
3
|
+
const SUPPORTED_VERSION = '1.0';
|
|
4
|
+
export function parseSpec(specPath) {
|
|
5
|
+
const diagnostics = [];
|
|
6
|
+
let raw;
|
|
7
|
+
try {
|
|
8
|
+
raw = parseYaml(readFileSync(specPath, 'utf-8'));
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
diagnostics.push({
|
|
12
|
+
severity: 'error',
|
|
13
|
+
file: specPath,
|
|
14
|
+
message: `Failed to read or parse file: ${err instanceof Error ? err.message : String(err)}`,
|
|
15
|
+
});
|
|
16
|
+
return { document: null, diagnostics };
|
|
17
|
+
}
|
|
18
|
+
if (!isCorumInterchangeDocument(raw)) {
|
|
19
|
+
diagnostics.push({
|
|
20
|
+
severity: 'error',
|
|
21
|
+
file: specPath,
|
|
22
|
+
message: 'Invalid corum interchange file: missing required "corumInterchange" key or "nodes" array',
|
|
23
|
+
});
|
|
24
|
+
return { document: null, diagnostics };
|
|
25
|
+
}
|
|
26
|
+
const doc = raw;
|
|
27
|
+
if (doc.corumInterchange !== SUPPORTED_VERSION) {
|
|
28
|
+
diagnostics.push({
|
|
29
|
+
severity: 'warning',
|
|
30
|
+
file: specPath,
|
|
31
|
+
message: `Unknown corumInterchange version "${doc.corumInterchange}" — expected "${SUPPORTED_VERSION}", continuing`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return { document: doc, diagnostics };
|
|
35
|
+
}
|
|
36
|
+
function isCorumInterchangeDocument(value) {
|
|
37
|
+
if (typeof value !== 'object' || value === null)
|
|
38
|
+
return false;
|
|
39
|
+
const v = value;
|
|
40
|
+
return typeof v.corumInterchange === 'string' && Array.isArray(v.nodes);
|
|
41
|
+
}
|
|
@@ -12,3 +12,5 @@ import { OpenAPIAdapter } from './openapi/index.js';
|
|
|
12
12
|
registerAdapter(new OpenAPIAdapter());
|
|
13
13
|
import { AsyncAPIAdapter } from './asyncapi/index.js';
|
|
14
14
|
registerAdapter(new AsyncAPIAdapter());
|
|
15
|
+
import { CorumAdapter } from './corum/index.js';
|
|
16
|
+
registerAdapter(new CorumAdapter());
|
package/dist/src/bin/corum.js
CHANGED
|
@@ -223,6 +223,24 @@ importCmd
|
|
|
223
223
|
process.exit(2);
|
|
224
224
|
}
|
|
225
225
|
});
|
|
226
|
+
importCmd
|
|
227
|
+
.command('corum <spec>')
|
|
228
|
+
.description('Import a corum interchange file into the graph')
|
|
229
|
+
.option('--graph <path>', 'Override CORUM_GRAPH_PATH')
|
|
230
|
+
.action(async (spec, opts) => {
|
|
231
|
+
try {
|
|
232
|
+
const runtimeConfig = buildRuntimeConfig(opts.graph);
|
|
233
|
+
const entry = { adapter: 'corum', spec: path.resolve(spec) };
|
|
234
|
+
const result = await runImport({ imports: [entry] }, runtimeConfig);
|
|
235
|
+
reportDiagnostics(result.diagnostics);
|
|
236
|
+
if (result.diagnostics.some(d => d.severity === 'error'))
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
process.stderr.write(`[ERROR] ${err instanceof Error ? err.message : String(err)}\n`);
|
|
241
|
+
process.exit(2);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
226
244
|
const packCmd = program.command('pack').description('Manage template packs');
|
|
227
245
|
packCmd
|
|
228
246
|
.command('install <name>')
|
|
@@ -22,10 +22,10 @@ export function serializeGraph(graph, options = {}) {
|
|
|
22
22
|
}
|
|
23
23
|
function clusterPath(node) {
|
|
24
24
|
const parts = node.id.split('.');
|
|
25
|
-
if (parts.length
|
|
26
|
-
throw new Error(`clusterPath: expected 3-segment root node ID, got: ${node.id}`);
|
|
27
|
-
const [component, template,
|
|
28
|
-
return `components/${component}/${template}s/${
|
|
25
|
+
if (parts.length < 3)
|
|
26
|
+
throw new Error(`clusterPath: expected at least 3-segment root node ID, got: ${node.id}`);
|
|
27
|
+
const [component, template, ...rest] = parts;
|
|
28
|
+
return `components/${component}/${template}s/${rest.join('/')}.yaml`;
|
|
29
29
|
}
|
|
30
30
|
export async function saveGraph(graph, options) {
|
|
31
31
|
const { sourceGraphPath, outputGraphPath, replace = true } = options;
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -83,23 +83,63 @@ function NavRail({ activeSection, onSection, debugMode, onDebugMode }) {
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function entryKey(entry) {
|
|
87
|
+
return entry.kind === 'group' ? entry.groupTemplateName : entry.templateName;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds }) {
|
|
87
91
|
const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
|
|
88
92
|
const [openComponent, setOpenComponent] = useState();
|
|
93
|
+
const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
|
|
89
94
|
const templateMap = new Map(templates.map(template => [template.name, template]));
|
|
90
95
|
|
|
96
|
+
function openComponentWithEntries(component) {
|
|
97
|
+
setOpenComponent(component);
|
|
98
|
+
if (!component) { setOpenEntryKeys(new Set()); return; }
|
|
99
|
+
const entries = navTree.get(component) ?? [];
|
|
100
|
+
setOpenEntryKeys(entries.length === 1 ? new Set([entryKey(entries[0])]) : new Set());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Initialise / recover openComponent when the tree first loads or the open component disappears.
|
|
91
104
|
useEffect(() => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (openComponent !== null && !navTree.has(openComponent)) {
|
|
97
|
-
setOpenComponent(sortedComponents[0] ?? null);
|
|
98
|
-
}
|
|
105
|
+
const autoOpen = sortedComponents.length === 1 ? sortedComponents[0] : null;
|
|
106
|
+
if (openComponent === undefined) { openComponentWithEntries(autoOpen); return; }
|
|
107
|
+
if (openComponent !== null && !navTree.has(openComponent)) { openComponentWithEntries(autoOpen); }
|
|
99
108
|
}, [navTree, openComponent, sortedComponents]);
|
|
100
109
|
|
|
110
|
+
// When navigating directly to a node (e.g. via link), open its component and entry.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!activeNodeId || !navTree.size) return;
|
|
113
|
+
for (const [component, entries] of navTree.entries()) {
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const eKey = entryKey(entry);
|
|
116
|
+
let found = false;
|
|
117
|
+
if (entry.kind === 'group') {
|
|
118
|
+
found = entry.children.some(child => child.nodes.some(n => n.id === activeNodeId));
|
|
119
|
+
} else {
|
|
120
|
+
found = entry.nodes.some(n => n.id === activeNodeId) ||
|
|
121
|
+
entry.nodes.some(n => (n.navChildren ?? []).some(g => g.nodes.some(c => c.id === activeNodeId)));
|
|
122
|
+
}
|
|
123
|
+
if (found) {
|
|
124
|
+
setOpenComponent(component);
|
|
125
|
+
setOpenEntryKeys(new Set([eKey]));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [activeNodeId, navTree]);
|
|
131
|
+
|
|
101
132
|
function toggleComponent(component) {
|
|
102
|
-
|
|
133
|
+
if (openComponent === component) { openComponentWithEntries(null); }
|
|
134
|
+
else { openComponentWithEntries(component); }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function toggleEntry(key) {
|
|
138
|
+
setOpenEntryKeys(prev => {
|
|
139
|
+
const next = new Set(prev);
|
|
140
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
103
143
|
}
|
|
104
144
|
|
|
105
145
|
if (navTree.size === 0) {
|
|
@@ -118,9 +158,11 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
118
158
|
</div>
|
|
119
159
|
{openComponent === component && entries.map(entry => {
|
|
120
160
|
if (entry.kind === 'group') {
|
|
161
|
+
const gKey = entryKey(entry);
|
|
162
|
+
const gOpen = openEntryKeys.has(gKey);
|
|
121
163
|
return (
|
|
122
164
|
<div key={entry.groupTemplateName}>
|
|
123
|
-
<div className="nav-template-head">
|
|
165
|
+
<div className="nav-template-head" onClick={() => toggleEntry(gKey)} style={{ cursor: 'pointer' }}>
|
|
124
166
|
{entry.icon && (
|
|
125
167
|
<i
|
|
126
168
|
className={`fa-solid fa-${entry.icon}`}
|
|
@@ -128,8 +170,9 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
128
170
|
/>
|
|
129
171
|
)}
|
|
130
172
|
<span>{entry.label}</span>
|
|
173
|
+
<Icon name={gOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
131
174
|
</div>
|
|
132
|
-
{entry.children.map(child => (
|
|
175
|
+
{gOpen && entry.children.map(child => (
|
|
133
176
|
<div key={child.templateName}>
|
|
134
177
|
<div className="nav-subtype-head">
|
|
135
178
|
{child.icon && (
|
|
@@ -167,16 +210,19 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
167
210
|
|
|
168
211
|
const template = templateMap.get(entry.templateName);
|
|
169
212
|
const colour = template?.ui?.colour ?? 'var(--ink-4)';
|
|
213
|
+
const tKey = entryKey(entry);
|
|
214
|
+
const tOpen = openEntryKeys.has(tKey);
|
|
170
215
|
return (
|
|
171
216
|
<div key={entry.templateName}>
|
|
172
|
-
<div className="nav-template-head">
|
|
217
|
+
<div className="nav-template-head" onClick={() => toggleEntry(tKey)} style={{ cursor: 'pointer' }}>
|
|
173
218
|
<i
|
|
174
219
|
className={`fa-solid fa-${template?.ui?.icon ?? 'circle'}`}
|
|
175
220
|
style={{ fontSize: 12, width: 14, textAlign: 'center', flexShrink: 0 }}
|
|
176
221
|
/>
|
|
177
222
|
<span>{templateDisplayName(template)}</span>
|
|
223
|
+
<Icon name={tOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
178
224
|
</div>
|
|
179
|
-
{entry.nodes.map(node => {
|
|
225
|
+
{tOpen && entry.nodes.map(node => {
|
|
180
226
|
const isActive = node.id === activeNodeId;
|
|
181
227
|
return (
|
|
182
228
|
<div key={node.id}>
|
|
@@ -626,7 +672,7 @@ function App() {
|
|
|
626
672
|
|
|
627
673
|
const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
|
|
628
674
|
const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
|
|
629
|
-
const navTree = buildNavTree(nodes, templates);
|
|
675
|
+
const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
|
|
630
676
|
const showTree = activeSection === 'components' || activeNodeId;
|
|
631
677
|
const activeOverlayRefs = useMemo(() =>
|
|
632
678
|
overlayMode === 'single' ? [] :
|