@atolis-hq/corum 0.1.61 → 0.1.62

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.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { NODE_ROOT_DIR } from '../source/graph-paths.js';
2
3
  import { Command } from 'commander';
3
4
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
4
5
  import { readFile as fsReadFile } from 'node:fs/promises';
@@ -146,7 +147,7 @@ program
146
147
  else {
147
148
  mkdirSync(path.dirname(graphPath), { recursive: true });
148
149
  writeFileSync(graphPath, GRAPH_TEMPLATE);
149
- mkdirSync(path.join(corumDir, 'graph', 'components'), { recursive: true });
150
+ mkdirSync(path.join(corumDir, 'graph', NODE_ROOT_DIR), { recursive: true });
150
151
  mkdirSync(path.join(corumDir, 'graph', 'edges'), { recursive: true });
151
152
  process.stdout.write('Created .corum/graph/graph.yaml\n');
152
153
  }
@@ -1,3 +1,4 @@
1
+ import { NODE_ROOT_DIR } from '../source/graph-paths.js';
1
2
  import { getEdgeTypeConstraints } from '../graph/roles.js';
2
3
  import { CORE_EDGE_TYPE_MAP } from '../loader/constants.js';
3
4
  import { validateNodeId } from '../loader/id-grammar.js';
@@ -335,7 +336,7 @@ function approxFilePath(graph, node) {
335
336
  if (parts.length < 2)
336
337
  return current.id;
337
338
  const [component, template, ...rest] = parts;
338
- return `components/${component}/${template}s/${rest.join('/') || template}.yaml`;
339
+ return `${NODE_ROOT_DIR}/${component}/${template}s/${rest.join('/') || template}.yaml`;
339
340
  }
340
341
  function valueMatchesType(value, type) {
341
342
  switch (type) {
@@ -1,3 +1,4 @@
1
+ import { NODE_ROOT_DIR } from '../source/graph-paths.js';
1
2
  import { parse as parseYaml } from 'yaml';
2
3
  import { getOwnedSections } from './pack-loader.js';
3
4
  import { listYamlKeys, readYaml } from '../source/content-utils.js';
@@ -12,7 +13,7 @@ const STRUCTURAL_EDGE_BY_ROLE = {
12
13
  };
13
14
  export function loadClusters(content, templates, diagnostics) {
14
15
  const result = { nodes: new Map(), edgesByFrom: new Map(), edgesByTo: new Map() };
15
- for (const key of listYamlKeys(content, 'components')) {
16
+ for (const key of listYamlKeys(content, NODE_ROOT_DIR)) {
16
17
  let raw;
17
18
  try {
18
19
  raw = parseYaml(readYaml(content, key));
@@ -1,3 +1,4 @@
1
+ import { NODE_ROOT_DIR } from '../source/graph-paths.js';
1
2
  import { stringify as stringifyYaml } from 'yaml';
2
3
  import { loadClusters, materialiseChildren } from '../loader/cluster-loader.js';
3
4
  import { getOwnedSections } from '../loader/pack-loader.js';
@@ -210,7 +211,7 @@ export function materialiseRootDocument(document, templates) {
210
211
  if (parts.length < 3) {
211
212
  throw new MutationError([mutationDiagnostic('error', `create node: '${id}' is not a valid cluster root id (component.Template.name)`, id)]);
212
213
  }
213
- const filePath = `components/${parts[0]}/${parts[1]}s/${parts.slice(2).join('/')}.yaml`;
214
+ const filePath = `${NODE_ROOT_DIR}/${parts[0]}/${parts[1]}s/${parts.slice(2).join('/')}.yaml`;
214
215
  const diagnostics = [];
215
216
  const result = loadClusters(new Map([[filePath, stringifyYaml(doc)]]), templates, diagnostics);
216
217
  if (diagnostics.some(d => d.severity === 'error'))
@@ -1,3 +1,4 @@
1
+ import { isManagedGraphYamlKey } from './graph-paths.js';
1
2
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
3
  import { createHash } from 'node:crypto';
3
4
  import fs from 'node:fs';
@@ -251,9 +252,6 @@ function walkManagedGraphYamlIntoMap(baseDir, currentDir, map, excludeDirs = new
251
252
  map.set(key, content);
252
253
  }
253
254
  }
254
- function isManagedGraphYamlKey(key) {
255
- return key === 'graph.yaml' || key.startsWith('components/') || key.startsWith('edges/');
256
- }
257
255
  function normalizeContentKey(key) {
258
256
  return key.split(path.sep).join('/');
259
257
  }
@@ -1,3 +1,4 @@
1
+ import { isManagedGraphYamlKey } from './graph-paths.js';
1
2
  import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import * as git from 'isomorphic-git';
@@ -161,7 +162,7 @@ export class GitGraphSource {
161
162
  const commitSha = await this.resolveBranchOid(ref);
162
163
  const prefix = this.graphDir.endsWith('/') ? this.graphDir : `${this.graphDir}/`;
163
164
  const allFiles = await git.listFiles({ fs, dir, ref: commitSha });
164
- for (const filePath of allFiles.filter(file => file.startsWith(prefix) && file.endsWith('.yaml'))) {
165
+ for (const filePath of allFiles.filter(file => file.startsWith(prefix) && file.endsWith('.yaml') && isManagedGraphYamlKey(file.slice(prefix.length)))) {
165
166
  try {
166
167
  const { blob } = await git.readBlob({ fs, dir, oid: commitSha, filepath: filePath });
167
168
  map.set(filePath.slice(prefix.length), Buffer.from(blob).toString('utf-8'));
@@ -0,0 +1,6 @@
1
+ /** Root directory for graph node cluster files. */
2
+ export const NODE_ROOT_DIR = 'nodes';
3
+ /** Graph YAML owned by loaders and graph replacement. */
4
+ export function isManagedGraphYamlKey(key) {
5
+ return key === 'graph.yaml' || key.startsWith(`${NODE_ROOT_DIR}/`) || key.startsWith('edges/');
6
+ }
@@ -1,3 +1,4 @@
1
+ import { NODE_ROOT_DIR } from '../source/graph-paths.js';
1
2
  import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
@@ -26,7 +27,7 @@ function clusterPath(node) {
26
27
  if (parts.length < 3)
27
28
  throw new Error(`clusterPath: expected at least 3-segment root node ID, got: ${node.id}`);
28
29
  const [component, template, ...rest] = parts;
29
- return `components/${component}/${template}s/${rest.join('/')}.yaml`;
30
+ return `${NODE_ROOT_DIR}/${component}/${template}s/${rest.join('/')}.yaml`;
30
31
  }
31
32
  export async function saveGraph(graph, options) {
32
33
  const { sourceGraphPath, outputGraphPath, replace = true } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",