@atolis-hq/corum 0.1.21 → 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/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;
|