@atolis-hq/corum 0.1.58 → 0.1.60

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.
@@ -11,8 +11,10 @@ export function mapDocument(document, specPath, existingSchemas = new Map()) {
11
11
  const allSchemas = (document.components?.schemas ?? {});
12
12
  // Maps #/components/schemas/X and #/components/schemas/X/properties/Y to materialized node IDs
13
13
  const refToNodeId = new Map();
14
- const documentNodeIds = new Set(Object.keys(document.nodes).map(normalizeNodeId));
15
- const rootNodeIds = getRootNodeIds(document.nodes);
14
+ const parents = resolveDocumentParents(document.nodes, specPath, diagnostics);
15
+ const rootNodeIds = [...parents.keys()]
16
+ .filter(nodeId => parents.get(nodeId) === undefined)
17
+ .sort((a, b) => b.length - a.length);
16
18
  // Pre-pass: determine canonical component for each schema (shared if referenced by 2+ components)
17
19
  const schemaComponents = computeSchemaComponents(document, allSchemas);
18
20
  const schemaUsage = computeSchemaUsage(document, allSchemas, rootNodeIds);
@@ -42,7 +44,7 @@ export function mapDocument(document, specPath, existingSchemas = new Map()) {
42
44
  if (entry['x-aka']?.length) {
43
45
  properties['x-aka'] = entry['x-aka'];
44
46
  }
45
- const node = makeNode(entry.type, component, specPath, normalizedNodeId, entry.provenance, properties, getDocumentParentId(normalizedNodeId, documentNodeIds));
47
+ const node = makeNode(entry.type, component, specPath, normalizedNodeId, entry.provenance, properties, parents.get(normalizedNodeId));
46
48
  nodes.push(node);
47
49
  if (schemaName) {
48
50
  const expanded = new Map();
@@ -124,17 +126,53 @@ function computeSchemaComponents(document, allSchemas) {
124
126
  }
125
127
  return result;
126
128
  }
127
- // Interchange documents encode explicit owned entries as {parent}.{section}.{name}.
128
- // Materialize that relationship at the adapter boundary, before graph queries or writes.
129
- function getDocumentParentId(nodeId, nodeIds) {
130
- const parentId = nodeId.split('.').slice(0, -2).join('.');
131
- return nodeIds.has(parentId) ? parentId : undefined;
132
- }
133
- function getRootNodeIds(nodes) {
129
+ // A compatibility heuristic only: packs may declare additional owned sections.
130
+ const CONVENTIONAL_SECTIONS = new Set(['schemas', 'enums', 'fields', 'values', 'mappings', 'operations']);
131
+ function resolveDocumentParents(nodes, specPath, diagnostics) {
134
132
  const nodeIds = new Set(Object.keys(nodes).map(normalizeNodeId));
135
- return [...nodeIds]
136
- .filter(nodeId => getDocumentParentId(nodeId, nodeIds) === undefined)
137
- .sort((a, b) => b.length - a.length);
133
+ const parents = new Map();
134
+ for (const [rawId, entry] of Object.entries(nodes)) {
135
+ const nodeId = normalizeNodeId(rawId);
136
+ if (entry.parentId !== undefined) {
137
+ const parentId = entry.parentId === null ? undefined : normalizeNodeId(entry.parentId);
138
+ if (parentId !== undefined && !nodeIds.has(parentId)) {
139
+ diagnostics.push({
140
+ severity: 'error', file: specPath,
141
+ message: `Node '${nodeId}' references unknown explicit parent '${parentId}'`,
142
+ });
143
+ }
144
+ else if (parentId !== undefined) {
145
+ const prefix = `${parentId}.`;
146
+ const childSegments = nodeId.startsWith(prefix) ? nodeId.slice(prefix.length).split('.') : [];
147
+ if (childSegments.length !== 2 || childSegments.some(segment => segment.length === 0)) {
148
+ diagnostics.push({
149
+ severity: 'error', file: specPath,
150
+ message: `Node '${nodeId}' explicit parent '${parentId}' must be its direct owner: expected {parentId}.{section}.{name}`,
151
+ });
152
+ }
153
+ }
154
+ // Keep invalid references visible; error diagnostics prevent importing this entry.
155
+ parents.set(nodeId, parentId);
156
+ continue;
157
+ }
158
+ const parts = nodeId.split('.');
159
+ const parentId = parts.slice(0, -2).join('.');
160
+ // Short namespace IDs must not capture ordinary component.Template.name roots.
161
+ if (parts.length >= 5 && nodeIds.has(parentId)) {
162
+ parents.set(nodeId, parentId);
163
+ const section = parts[parts.length - 2];
164
+ if (!CONVENTIONAL_SECTIONS.has(section)) {
165
+ diagnostics.push({
166
+ severity: 'warning', file: specPath,
167
+ message: `Node '${nodeId}' inferred parent '${parentId}' through implausible section '${section}'; set parentId explicitly to disambiguate ownership`,
168
+ });
169
+ }
170
+ }
171
+ else {
172
+ parents.set(nodeId, undefined);
173
+ }
174
+ }
175
+ return parents;
138
176
  }
139
177
  function computeSchemaUsage(document, allSchemas, rootNodeIds) {
140
178
  const usage = {
@@ -24,6 +24,18 @@ export function parseSpec(specPath) {
24
24
  return { document: null, diagnostics };
25
25
  }
26
26
  const doc = raw;
27
+ for (const [nodeId, entry] of Object.entries(doc.nodes)) {
28
+ if (entry && typeof entry === 'object' && 'parentId' in entry
29
+ && entry.parentId !== null && typeof entry.parentId !== 'string') {
30
+ diagnostics.push({
31
+ severity: 'error',
32
+ file: specPath,
33
+ message: `Node '${nodeId}' parentId must be a string or null`,
34
+ });
35
+ }
36
+ }
37
+ if (diagnostics.some(d => d.severity === 'error'))
38
+ return { document: null, diagnostics };
27
39
  if (doc.corum !== SUPPORTED_VERSION) {
28
40
  diagnostics.push({
29
41
  severity: 'warning',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",