@atolis-hq/corum 0.1.30 → 0.1.31
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.
|
@@ -29,6 +29,9 @@ export function mapDocument(document, specPath) {
|
|
|
29
29
|
if (entry.title && !schemaName) {
|
|
30
30
|
properties.description = entry.title;
|
|
31
31
|
}
|
|
32
|
+
if (entry['x-aka']?.length) {
|
|
33
|
+
properties['x-aka'] = entry['x-aka'];
|
|
34
|
+
}
|
|
32
35
|
const node = makeNode(entry.type, component, specPath, nodeId, entry.provenance, properties);
|
|
33
36
|
nodes.push(node);
|
|
34
37
|
if (schemaName) {
|
|
@@ -17,6 +17,11 @@ export function loadImportConfig(filePath) {
|
|
|
17
17
|
throw new Error(`Invalid import config: componentNameReplacements entries must have non-empty "from" and "to"`);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
for (const rule of cfg.deduplication ?? []) {
|
|
21
|
+
if (!rule.primary || !rule.secondary) {
|
|
22
|
+
throw new Error(`Invalid import config: deduplication entries must have non-empty "primary" and "secondary"`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
20
25
|
return cfg;
|
|
21
26
|
}
|
|
22
27
|
export function applyComponentNameReplacements(name, replacements) {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export function deduplicateResults(results, rules) {
|
|
2
|
+
const diagnostics = [];
|
|
3
|
+
for (const rule of rules) {
|
|
4
|
+
const primaryNodes = new Map();
|
|
5
|
+
for (const r of results) {
|
|
6
|
+
if (r.adapterId === rule.primary) {
|
|
7
|
+
for (const node of r.nodes)
|
|
8
|
+
primaryNodes.set(node.id, node);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const primaryNodeIds = new Set(primaryNodes.keys());
|
|
12
|
+
const redirects = new Map();
|
|
13
|
+
// Phase 1a: x-aka matching
|
|
14
|
+
for (const r of results) {
|
|
15
|
+
if (r.adapterId !== rule.secondary)
|
|
16
|
+
continue;
|
|
17
|
+
for (const node of r.nodes) {
|
|
18
|
+
if (redirects.has(node.id))
|
|
19
|
+
continue;
|
|
20
|
+
const aka = node.properties['x-aka'];
|
|
21
|
+
if (Array.isArray(aka)) {
|
|
22
|
+
const parts = node.id.split('.');
|
|
23
|
+
const component = parts[0];
|
|
24
|
+
const template = parts[1];
|
|
25
|
+
for (const alias of aka) {
|
|
26
|
+
const candidate = `${component}.${template}.${alias}`;
|
|
27
|
+
if (primaryNodes.has(candidate)) {
|
|
28
|
+
redirects.set(node.id, candidate);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Phase 1b: collect raw same-ID collisions
|
|
36
|
+
const rawSameIds = [];
|
|
37
|
+
for (const r of results) {
|
|
38
|
+
if (r.adapterId !== rule.secondary)
|
|
39
|
+
continue;
|
|
40
|
+
for (const node of r.nodes) {
|
|
41
|
+
if (!redirects.has(node.id) && primaryNodes.has(node.id)) {
|
|
42
|
+
rawSameIds.push(node.id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Phase 2: add only root collisions (those not covered by another collision)
|
|
47
|
+
for (const nodeId of rawSameIds) {
|
|
48
|
+
const coveredByRoot = rawSameIds.some(id => id !== nodeId && nodeId.startsWith(id + '.'));
|
|
49
|
+
if (!coveredByRoot) {
|
|
50
|
+
redirects.set(nodeId, nodeId);
|
|
51
|
+
diagnostics.push({
|
|
52
|
+
severity: 'warning',
|
|
53
|
+
file: '',
|
|
54
|
+
message: `Duplicate node ID from adapters ${rule.primary} and ${rule.secondary}: ${nodeId} — ${rule.secondary} node dropped`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (redirects.size === 0)
|
|
59
|
+
continue;
|
|
60
|
+
for (const r of results) {
|
|
61
|
+
r.edges = r.edges.flatMap(edge => {
|
|
62
|
+
const rewritten = rewriteEdge(edge, redirects, primaryNodeIds);
|
|
63
|
+
return rewritten === null ? [] : [rewritten];
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
for (const r of results) {
|
|
67
|
+
if (r.adapterId !== rule.secondary)
|
|
68
|
+
continue;
|
|
69
|
+
r.nodes = r.nodes.filter(node => {
|
|
70
|
+
if (redirects.has(node.id))
|
|
71
|
+
return false;
|
|
72
|
+
for (const secondaryId of redirects.keys()) {
|
|
73
|
+
if (node.id.startsWith(secondaryId + '.'))
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const r of results) {
|
|
81
|
+
for (const node of r.nodes) {
|
|
82
|
+
delete node.properties['x-aka'];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { results, diagnostics };
|
|
86
|
+
}
|
|
87
|
+
function rewriteEdge(edge, redirects, primaryNodeIds) {
|
|
88
|
+
const from = rewriteEndpoint(edge.from, redirects, primaryNodeIds);
|
|
89
|
+
const to = rewriteEndpoint(edge.to, redirects, primaryNodeIds);
|
|
90
|
+
if (from === null || to === null)
|
|
91
|
+
return null;
|
|
92
|
+
if (from === edge.from && to === edge.to)
|
|
93
|
+
return edge;
|
|
94
|
+
return { ...edge, from, to, id: `${from}__${edge.type}__${to}` };
|
|
95
|
+
}
|
|
96
|
+
function rewriteEndpoint(endpoint, redirects, primaryNodeIds) {
|
|
97
|
+
const exact = redirects.get(endpoint);
|
|
98
|
+
if (exact !== undefined && exact !== endpoint)
|
|
99
|
+
return exact;
|
|
100
|
+
for (const [secondaryId, primaryId] of redirects) {
|
|
101
|
+
if (secondaryId === primaryId)
|
|
102
|
+
continue;
|
|
103
|
+
const prefix = secondaryId + '.';
|
|
104
|
+
if (endpoint.startsWith(prefix)) {
|
|
105
|
+
const rewritten = primaryId + '.' + endpoint.slice(prefix.length);
|
|
106
|
+
if (!primaryNodeIds.has(rewritten))
|
|
107
|
+
return null;
|
|
108
|
+
return rewritten;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return endpoint;
|
|
112
|
+
}
|
|
@@ -4,9 +4,11 @@ import { loadGraph } from '../loader/index.js';
|
|
|
4
4
|
import { serializeGraph } from '../writer/graph-writer.js';
|
|
5
5
|
import { getAdapter } from '../adapters/index.js';
|
|
6
6
|
import { diffNodes } from '../reconcile/index.js';
|
|
7
|
+
import { deduplicateResults } from './dedup.js';
|
|
7
8
|
export async function runImport(config, runtimeConfig) {
|
|
8
9
|
const allDiagnostics = [];
|
|
9
10
|
const graph = await loadGraph({ source: runtimeConfig.source });
|
|
11
|
+
const entryResults = [];
|
|
10
12
|
for (const entry of config.imports) {
|
|
11
13
|
const packConfig = await loadPackAdapterConfig(runtimeConfig, entry.adapter);
|
|
12
14
|
if (!packConfig) {
|
|
@@ -28,18 +30,25 @@ export async function runImport(config, runtimeConfig) {
|
|
|
28
30
|
allDiagnostics.push(...result.diagnostics);
|
|
29
31
|
if (result.diagnostics.some(d => d.severity === 'error'))
|
|
30
32
|
continue;
|
|
31
|
-
|
|
33
|
+
entryResults.push({ adapterId: entry.adapter, specPath, nodes: result.nodes, edges: result.edges });
|
|
34
|
+
}
|
|
35
|
+
if (config.deduplication?.length) {
|
|
36
|
+
const { results: deduped, diagnostics } = deduplicateResults(entryResults, config.deduplication);
|
|
37
|
+
allDiagnostics.push(...diagnostics);
|
|
38
|
+
entryResults.splice(0, entryResults.length, ...deduped);
|
|
39
|
+
}
|
|
40
|
+
const STRUCTURAL_EDGE_TYPES = new Set(['has-field', 'has-value']);
|
|
41
|
+
for (const er of entryResults) {
|
|
42
|
+
const { toAdd, toUpdate, toRemove } = diffNodes(er.nodes, graph.nodesById, er.specPath);
|
|
32
43
|
for (const node of [...toAdd, ...toUpdate, ...toRemove]) {
|
|
33
44
|
graph.nodesById.set(node.id, node);
|
|
34
45
|
}
|
|
35
|
-
const
|
|
36
|
-
for (const edge of result.edges) {
|
|
46
|
+
for (const edge of er.edges) {
|
|
37
47
|
if (STRUCTURAL_EDGE_TYPES.has(edge.type))
|
|
38
48
|
continue;
|
|
39
49
|
const existing = graph.edgesByFrom.get(edge.from) ?? [];
|
|
40
50
|
if (!existing.some(e => e.id === edge.id)) {
|
|
41
|
-
|
|
42
|
-
graph.edgesByFrom.set(edge.from, updated);
|
|
51
|
+
graph.edgesByFrom.set(edge.from, [...existing, edge]);
|
|
43
52
|
const byTo = graph.edgesByTo.get(edge.to) ?? [];
|
|
44
53
|
graph.edgesByTo.set(edge.to, [...byTo, edge]);
|
|
45
54
|
}
|