@sigloch/graph-view-edit 0.22.1 → 0.23.0

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/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>graph-view-edit</title>
7
- <script type="module" crossorigin src="/assets/index-DzxcrONp.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-BQGzkC9X.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-B3cgYeCa.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigloch/graph-view-edit",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "description": "React/Vite viewer+editor over @sigloch/graphcode — 12 graph-views + 16 doc-views via a declarative View-Registry, plus an SE-Dashboard sibling route. Reads docs/graph/<member>.graph.json client-side (no 2nd Kuzu handle).",
5
5
  "type": "module",
6
6
  "bin": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@playwright/test": "^1.58.2",
36
- "@sigloch/graphcode": "^0.41.0",
36
+ "@sigloch/graphcode": "^0.42.0",
37
37
  "@tanstack/react-table": "^8.20.5",
38
38
  "@testing-library/react": "^16.0.1",
39
39
  "elkjs": "^0.11.1",
@@ -1,9 +1,11 @@
1
1
  /**
2
- * Code einer FUNC (CR-GVE-390) — Server-Seite. Der `realRef` kommt aus dem Graphen, nie aus der Anfrage: der Browser
3
- * nennt nur die FUNC, kann also keine beliebige Datei lesen oder öffnen.
2
+ * Code eines Knotens für die Detailspalte — Server-Seite. FUNC und SCHEMA zeigen ihren `realRef` (CR-GVE-390,
3
+ * CR-GVE-407), ein TEST eine Datei aus seinen `testRefs` (CR-GVE-407). Der Pfad kommt aus dem Graphen, nie aus der
4
+ * Anfrage: der Browser nennt nur id und Index, kann also keine beliebige Datei lesen oder öffnen.
4
5
  *
5
- * Eine FUNC ohne Code ist ein gültiger Stand, kein Fehler: ein Block hat seinen Code in den Teilen (`block`), eine
6
- * ungebaute Funktion noch keinen (`missing`). Ein Skill hat kein `symbol`: die Datei ist die Funktion, Zeile 1.
6
+ * Ein Knoten ohne Code ist ein gültiger Stand, kein Fehler: ein Block hat seinen Code in den Teilen (`block`), eine
7
+ * ungebaute Funktion, ein ungebundenes Schema oder ein ungebundener Test noch keinen (`missing`). Ein Skill hat kein
8
+ * `symbol`: die Datei ist die Funktion, Zeile 1. Eine Testdatei beginnt immer bei Zeile 1.
7
9
  *
8
10
  * @author andreas@siglochconsulting
9
11
  */
@@ -29,28 +31,64 @@ export function symbolLine(text, symbol) {
29
31
 
30
32
  /**
31
33
  * @param {{elements?: object[], traces?: object[]}} graph
32
- * @param {string} funcId
34
+ * @param {string} id FUNC, SCHEMA oder TEST
33
35
  * @param {string} repoRoot
34
- * @returns {{status: 'ok', file: string, path: string, line: number, total: number, excerpt: string[]}
36
+ * @param {number} [ref] bei TEST: Index in `testRefs`
37
+ * @returns {{status: 'ok', file: string, path: string, line: number, total: number, excerpt: string[], result?: string}
35
38
  * | {status: 'block', parts: number} | {status: 'missing'} | {status: 'no-file', file: string} | {status: 'unknown'}}
36
39
  */
37
- export function codeOf(graph, funcId, repoRoot) {
40
+ export function codeOf(graph, id, repoRoot, ref = 0) {
38
41
  const elements = graph?.elements ?? [];
39
- const el = elements.find((e) => e.id === funcId);
40
- if (el?.type !== 'FUNC') return { status: 'unknown' };
41
- const ref = el.realRef;
42
- if (!ref?.file) {
42
+ const el = elements.find((e) => e.id === id);
43
+ if (el?.type === 'TEST') {
44
+ const refs = el.testRefs ?? [];
45
+ if (!refs.length) return { status: 'missing' };
46
+ const r = refs[ref];
47
+ if (!r) return { status: 'unknown' };
48
+ const code = excerptOf(r.file, null, repoRoot);
49
+ return code.status === 'ok' && r.result ? { ...code, result: r.result } : code;
50
+ }
51
+ if (el?.type !== 'FUNC' && el?.type !== 'SCHEMA') return { status: 'unknown' };
52
+ const realRef = el.realRef;
53
+ if (!realRef?.file) {
54
+ if (el.type === 'SCHEMA') return { status: 'missing' };
43
55
  const isFunc = new Set(elements.filter((e) => e.type === 'FUNC').map((e) => e.id));
44
- const parts = (graph.traces ?? []).filter((t) => t.type === 'compose' && t.source === funcId && isFunc.has(t.target)).length;
56
+ const parts = (graph.traces ?? []).filter((t) => t.type === 'compose' && t.source === id && isFunc.has(t.target)).length;
45
57
  return parts ? { status: 'block', parts } : { status: 'missing' };
46
58
  }
47
- const path = resolve(repoRoot, ref.file);
59
+ return excerptOf(realRef.file, realRef.symbol, repoRoot);
60
+ }
61
+
62
+ /** Auszug ab dem Symbol, sonst ab Zeile 1. Ein Pfad aus dem Repo heraus gilt als nicht gefunden. */
63
+ function excerptOf(file, symbol, repoRoot) {
64
+ if (!file) return { status: 'missing' };
65
+ const path = resolve(repoRoot, file);
48
66
  const inside = relative(repoRoot, path);
49
- if (inside.startsWith('..') || isAbsolute(inside) || !existsSync(path)) return { status: 'no-file', file: ref.file };
67
+ if (inside.startsWith('..') || isAbsolute(inside) || !existsSync(path)) return { status: 'no-file', file };
50
68
  const text = readFileSync(path, 'utf8');
51
69
  const lines = text.split('\n');
52
- const line = ref.symbol ? symbolLine(text, ref.symbol) : 1;
53
- return { status: 'ok', file: ref.file, path, line, total: lines.length, excerpt: lines.slice(line - 1, line - 1 + EXCERPT_LINES) };
70
+ const line = symbol ? symbolLine(text, symbol) : 1;
71
+ return { status: 'ok', file, path, line, total: lines.length, excerpt: lines.slice(line - 1, line - 1 + EXCERPT_LINES) };
72
+ }
73
+
74
+ /**
75
+ * Die Tests einer SCHEMA (`TEST -verify-> SCHEMA`), je `testRefs`-Eintrag eine Zeile; ein Test ohne `testRefs` steht
76
+ * mit `ref: 0` da und zeigt dann „missing". Der Vertragstest (R-32, Datei `*.vertrag.test.*`) steht zuerst.
77
+ * @returns {{id: string, name: string, ref: number, file?: string}[]}
78
+ */
79
+ export function testsOfSchema(graph, schemaId) {
80
+ const byId = new Map((graph?.elements ?? []).map((e) => [e.id, e]));
81
+ if (byId.get(schemaId)?.type !== 'SCHEMA') return [];
82
+ const rows = [];
83
+ for (const t of graph?.traces ?? []) {
84
+ const test = byId.get(t.source);
85
+ if (t.type !== 'verify' || t.target !== schemaId || test?.type !== 'TEST') continue;
86
+ const refs = test.testRefs ?? [];
87
+ if (!refs.length) rows.push({ id: test.id, name: test.name || test.id, ref: 0 });
88
+ refs.forEach((r, ref) => rows.push({ id: test.id, name: test.name || test.id, ref, file: r.file }));
89
+ }
90
+ const contract = (r) => (/\.vertrag\.test\./.test(r.file ?? '') ? 0 : 1);
91
+ return rows.sort((a, b) => contract(a) - contract(b) || a.id.localeCompare(b.id) || a.ref - b.ref);
54
92
  }
55
93
 
56
94
  /**
package/vite.config.js CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  HOST_SOCK_BASENAME,
39
39
  } from '@sigloch/graphcode-client';
40
40
  import { loadConfig } from './src/config.mjs';
41
- import { codeOf, openInEditor } from './src/code-lookup.mjs';
41
+ import { codeOf, openInEditor, testsOfSchema } from './src/code-lookup.mjs';
42
42
  import { fetchVerlauf, fetchAblehnung } from './src/host-verlauf.mjs';
43
43
 
44
44
  /**
@@ -1232,12 +1232,13 @@ function mutateApiPlugin() {
1232
1232
  }
1233
1233
 
1234
1234
  /**
1235
- * GET /api/code?func=<id> und POST /api/open-code { funcId } (CR-GVE-390) — der Code einer FUNC für die Detailspalte
1236
- * und der Start des Editors. Beide lesen den `realRef` aus dem Graphen auf der Platte; siehe src/code-lookup.mjs.
1235
+ * GET /api/code?id=<id>&ref=<n> und POST /api/open-code { id, ref } — der Code eines Knotens für die Detailspalte und
1236
+ * der Start des Editors: FUNC (CR-GVE-390), SCHEMA und TEST (CR-GVE-407). Eine SCHEMA bringt ihre Tests als `tests`
1237
+ * mit. Beide lesen `realRef`/`testRefs` aus dem Graphen auf der Platte; siehe src/code-lookup.mjs.
1237
1238
  */
1238
1239
  function codeApiPlugin() {
1239
1240
  const repoRoot = resolveRepoRoot();
1240
- const locate = (funcId) => codeOf(JSON.parse(readFileSync(join(repoRoot, servedGraphPath(repoRoot)), 'utf8')), funcId, repoRoot);
1241
+ const readGraph = () => JSON.parse(readFileSync(join(repoRoot, servedGraphPath(repoRoot)), 'utf8'));
1241
1242
  const send = (res, status, body) => {
1242
1243
  res.statusCode = status;
1243
1244
  res.setHeader('Content-Type', 'application/json');
@@ -1247,24 +1248,27 @@ function codeApiPlugin() {
1247
1248
  const middleware = (req, res, next) => {
1248
1249
  const url = new URL(req.url ?? '/', 'http://localhost');
1249
1250
  if (url.pathname === '/api/code') {
1250
- const code = locate(url.searchParams.get('func'));
1251
- send(res, code.status === 'unknown' ? 404 : 200, code);
1251
+ const graph = readGraph();
1252
+ const id = url.searchParams.get('id');
1253
+ const code = codeOf(graph, id, repoRoot, Number(url.searchParams.get('ref') ?? 0));
1254
+ const tests = testsOfSchema(graph, id);
1255
+ send(res, code.status === 'unknown' ? 404 : 200, tests.length ? { ...code, tests } : code);
1252
1256
  return;
1253
1257
  }
1254
1258
  if (url.pathname !== '/api/open-code' || req.method !== 'POST') return next();
1255
1259
  let raw = '';
1256
1260
  req.on('data', (chunk) => { raw += chunk; });
1257
1261
  req.on('end', async () => {
1258
- let funcId;
1262
+ let id, ref;
1259
1263
  try {
1260
- ({ funcId } = JSON.parse(raw));
1264
+ ({ id, ref = 0 } = JSON.parse(raw));
1261
1265
  } catch {
1262
1266
  send(res, 400, { success: false, error: 'invalid JSON body' });
1263
1267
  return;
1264
1268
  }
1265
- const code = locate(funcId);
1269
+ const code = codeOf(readGraph(), id, repoRoot, ref);
1266
1270
  if (code.status !== 'ok') {
1267
- send(res, 404, { success: false, error: `kein Code zu ${funcId}: ${code.status}` });
1271
+ send(res, 404, { success: false, error: `kein Code zu ${id}: ${code.status}` });
1268
1272
  return;
1269
1273
  }
1270
1274
  send(res, 200, await openInEditor(code, APP_CONFIG.editor.command));