@sigloch/graph-api-core 5.7.0 → 5.8.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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * format-e-door.ts — die Tuer des Format-E-Vertrags (CR-SM-359).
3
+ *
4
+ * Format-E ist ein Familienvertrag: Codec und Deskriptor liegen in diesem Paket, jeder Konsument
5
+ * (graphcode, graph-view-edit, …) liest und schreibt denselben Dialekt. Die Tuer gehoert deshalb
6
+ * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
+ * ein Konsument den Vertrag eines anderen definiert.
8
+ *
9
+ * Die Tuer ist ein Zod-Schema, kein Typ: zur Laufzeit pruefbar, und als Konstante zaehlt die Regel
10
+ * RC-09 (contracts) jeden, der sie parst, gegen das Modell des Konsumenten. Ein zweiter Leser
11
+ * desselben Textes ist damit ein Befund, keine Stilfrage (Spike CR-GC-637).
12
+ *
13
+ * @author andreas@siglochconsulting
14
+ */
15
+ import { z } from 'zod/v4';
16
+ import { FormatECodec } from './format-e-codec.js';
17
+ import type { Graph } from './types.js';
18
+ /**
19
+ * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
+ * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
21
+ * Deskriptor unterschieben koennte. Konsumenten importieren diese, statt eine eigene zu bauen.
22
+ */
23
+ export declare const SE_FORMAT_E_CODEC: FormatECodec;
24
+ /**
25
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec.
26
+ *
27
+ * Eingabe ist `{ text, bestand }`: der Parser typisiert uids, die der Text nicht deklariert, aus
28
+ * dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
29
+ * `### <TYPE>`-Sektion. Jeder Codec-Fehler wird ein Zod-Issue, wortgleich.
30
+ */
31
+ export declare const FormatEInputSchema: z.ZodPipe<z.ZodObject<{
32
+ text: z.ZodString;
33
+ bestand: z.ZodCustom<Graph, Graph>;
34
+ }, z.core.$strip>, z.ZodTransform<import("./types.js").FormatEDiff, {
35
+ text: string;
36
+ bestand: Graph;
37
+ }>>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * format-e-door.ts — die Tuer des Format-E-Vertrags (CR-SM-359).
3
+ *
4
+ * Format-E ist ein Familienvertrag: Codec und Deskriptor liegen in diesem Paket, jeder Konsument
5
+ * (graphcode, graph-view-edit, …) liest und schreibt denselben Dialekt. Die Tuer gehoert deshalb
6
+ * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
+ * ein Konsument den Vertrag eines anderen definiert.
8
+ *
9
+ * Die Tuer ist ein Zod-Schema, kein Typ: zur Laufzeit pruefbar, und als Konstante zaehlt die Regel
10
+ * RC-09 (contracts) jeden, der sie parst, gegen das Modell des Konsumenten. Ein zweiter Leser
11
+ * desselben Textes ist damit ein Befund, keine Stilfrage (Spike CR-GC-637).
12
+ *
13
+ * @author andreas@siglochconsulting
14
+ */
15
+ import { z } from 'zod/v4';
16
+ import { FormatECodec } from './format-e-codec.js';
17
+ import { SE_DESCRIPTOR } from './se-descriptor.js';
18
+ /**
19
+ * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
+ * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
21
+ * Deskriptor unterschieben koennte. Konsumenten importieren diese, statt eine eigene zu bauen.
22
+ */
23
+ export const SE_FORMAT_E_CODEC = new FormatECodec(SE_DESCRIPTOR);
24
+ /**
25
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec.
26
+ *
27
+ * Eingabe ist `{ text, bestand }`: der Parser typisiert uids, die der Text nicht deklariert, aus
28
+ * dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
29
+ * `### <TYPE>`-Sektion. Jeder Codec-Fehler wird ein Zod-Issue, wortgleich.
30
+ */
31
+ export const FormatEInputSchema = z
32
+ .object({
33
+ text: z.string(),
34
+ bestand: z.custom((g) => typeof g === 'object' && g !== null && Array.isArray(g.nodes)),
35
+ })
36
+ .transform(({ text, bestand }, ctx) => {
37
+ const typeIndex = new Map(bestand.nodes.map((n) => [n.uid, n.type]));
38
+ const diff = SE_FORMAT_E_CODEC.parse(text, { resolveType: (uid) => typeIndex.get(uid) });
39
+ for (const message of diff.errors)
40
+ ctx.addIssue({ code: 'custom', message });
41
+ return diff;
42
+ });
@@ -33,23 +33,40 @@
33
33
  *
34
34
  * @author andreas@siglochconsulting
35
35
  */
36
- import type { Graph, GraphEdge, GraphNode } from './types.js';
36
+ import { z } from 'zod/v4';
37
+ import type { Graph, GraphNode } from './types.js';
37
38
  export type ImpactRole = 'seed' | 'whitebox' | 'blackbox';
38
39
  /** A slice node: the graph node plus its role and BFS distance from the changeset. */
39
40
  export type ImpactSliceNode = GraphNode & {
40
41
  role: ImpactRole;
41
42
  distance: number;
42
43
  };
43
- export interface ImpactSlice {
44
- /** The seeds actually present in the graph (order of first mention, deduped). */
45
- seeds: string[];
46
- /** The requested traversal depth (whitebox horizon; blackbox ring sits at depth+1). */
47
- depth: number;
48
- /** Slice nodes in the graph's node order — blackbox nodes carry identity only. */
49
- nodes: ImpactSliceNode[];
50
- /** Induced edges: kept iff both endpoints are in the slice. */
51
- edges: GraphEdge[];
52
- }
44
+ export declare const ImpactSliceSchema: z.ZodObject<{
45
+ seeds: z.ZodArray<z.ZodString>;
46
+ depth: z.ZodNumber;
47
+ nodes: z.ZodArray<z.ZodObject<{
48
+ uid: z.ZodString;
49
+ type: z.ZodString;
50
+ name: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ createdAt: z.ZodOptional<z.ZodString>;
54
+ updatedAt: z.ZodOptional<z.ZodString>;
55
+ role: z.ZodEnum<{
56
+ seed: "seed";
57
+ whitebox: "whitebox";
58
+ blackbox: "blackbox";
59
+ }>;
60
+ distance: z.ZodNumber;
61
+ }, z.core.$strip>>;
62
+ edges: z.ZodArray<z.ZodObject<{
63
+ sourceId: z.ZodString;
64
+ targetId: z.ZodString;
65
+ edgeType: z.ZodString;
66
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
+ }, z.core.$strip>>;
68
+ }, z.core.$strip>;
69
+ export type ImpactSlice = z.infer<typeof ImpactSliceSchema>;
53
70
  /**
54
71
  * Compute the impact slice of `seedIds` over a loaded graph: directed incoming
55
72
  * BFS to `depth` (whitebox) plus the materialized blackbox ring at depth+1.
@@ -1,3 +1,51 @@
1
+ /**
2
+ * impactSlice — THE directed impact traversal (CR-GC-365, Weg b).
3
+ *
4
+ * One definition of "blast radius", two readers: graphcode's `graph_impact`
5
+ * (MCP surface, agent) and graph-view-edit's ImpactMap (viewer). Before this,
6
+ * the MCP side ran a directed incoming Kuzu query while the viewer ran its own
7
+ * undirected frontier-BFS in the browser — what the human saw was a superset
8
+ * in direction and a subset in depth of what the agent got, computed from a
9
+ * different source.
10
+ *
11
+ * Semantics (node-equal to the former Kuzu query `(m)-[*1..depth]->(root)`,
12
+ * direction 'in' — conformance-tested against KuzuAdapter.getSubgraph):
13
+ *
14
+ * - Traversal is DIRECTED INCOMING: dependents, i.e. nodes with a directed
15
+ * path INTO a seed of length <= depth (who breaks if the seed changes).
16
+ * `distance` is the shortest such path length (0 = seed).
17
+ *
18
+ * - Roles per SPIKE-GC-minimal-whitebox §8 (`seed | whitebox | blackbox`):
19
+ * seed distance 0 — the changeset,
20
+ * whitebox distance 1..depth — full node (description, attributes),
21
+ * blackbox distance depth+1 — the frontier ONE step beyond the request:
22
+ * identity only (uid/type/name), description and attributes
23
+ * stripped. The cut is materialized in the artifact, not merely
24
+ * meant in a renderer; the ring is also the honest
25
+ * "+"-affordance: a bigger slice (same function, depth+1) opens
26
+ * exactly these nodes.
27
+ *
28
+ * - Edges only when BOTH ends lie in the slice (§8 — no edges into nothing).
29
+ *
30
+ * Pure function over a loaded Graph — no store handle, browser-safe (exported
31
+ * from `./browser.js` too). Seeds not present in the graph are dropped; no
32
+ * present seed yields an empty slice, never a full dump.
33
+ *
34
+ * @author andreas@siglochconsulting
35
+ */
36
+ import { z } from 'zod/v4';
37
+ import { GraphNodeSchema, GraphEdgeSchema } from './schemas.js';
38
+ // CR-SM-361: der Slice ist ein Zod-Vertrag, kein Typ — `impactSlice` prueft seine Ausgabe.
39
+ export const ImpactSliceSchema = z.object({
40
+ /** The seeds actually present in the graph (order of first mention, deduped). */
41
+ seeds: z.array(z.string()),
42
+ /** The requested traversal depth (whitebox horizon; blackbox ring sits at depth+1). */
43
+ depth: z.number(),
44
+ /** Slice nodes in the graph's node order — blackbox nodes carry identity only. */
45
+ nodes: z.array(GraphNodeSchema.extend({ role: z.enum(['seed', 'whitebox', 'blackbox']), distance: z.number() })),
46
+ /** Induced edges: kept iff both endpoints are in the slice. */
47
+ edges: z.array(GraphEdgeSchema),
48
+ });
1
49
  /**
2
50
  * Compute the impact slice of `seedIds` over a loaded graph: directed incoming
3
51
  * BFS to `depth` (whitebox) plus the materialized blackbox ring at depth+1.
@@ -45,5 +93,7 @@ export function impactSlice(graph, seedIds, depth) {
45
93
  }
46
94
  const inSlice = new Set(nodes.map((n) => n.uid));
47
95
  const edges = graph.edges.filter((e) => inSlice.has(e.sourceId) && inSlice.has(e.targetId));
48
- return { seeds, depth, nodes, edges };
96
+ const slice = { seeds, depth, nodes, edges };
97
+ ImpactSliceSchema.parse(slice); // CR-SM-361: der Erzeuger prueft seinen Vertrag
98
+ return slice;
49
99
  }
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export type { FormatEOperation, FormatEDiff } from './types.js';
13
13
  export { GraphNodeSchema, GraphEdgeSchema, GraphSchema, GraphScopeSchema, GraphQuerySchema, MutationResultSchema, HealthStatusSchema, } from './schemas.js';
14
14
  export { GraphService } from './graph-service.js';
15
15
  export { FormatECodec } from './format-e-codec.js';
16
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema } from './format-e-door.js';
16
17
  export type { Rule, RuleViolation, RuleEngine } from './rule-engine.js';
17
18
  export { DefaultRuleEngine } from './rule-engine.js';
18
19
  export type { AuditEntry, AuditLog, OperationsLog } from './audit.js';
@@ -25,7 +26,7 @@ export type { GraphApiConfig } from './factory.js';
25
26
  export { SE_DESCRIPTOR, createSeDescriptor, projectToOntologyGraph, fromOntologyGraph } from './se-descriptor.js';
26
27
  export { findRoot } from './find-root.js';
27
28
  export type { RootQueryGraph } from './find-root.js';
28
- export { impactSlice } from './impact-slice.js';
29
+ export { impactSlice, ImpactSliceSchema } from './impact-slice.js';
29
30
  export type { ImpactSlice, ImpactSliceNode, ImpactRole } from './impact-slice.js';
30
31
  export { applyEdgeOps, updateEdge, mergeNodes } from './edge-ops.js';
31
32
  export type { EdgeIdentity, UpdateEdgeSet, UpdateEdgeResult, MergeNodesResult, EdgeOp, } from './edge-ops.js';
package/dist/index.js CHANGED
@@ -13,6 +13,8 @@ export { GraphNodeSchema, GraphEdgeSchema, GraphSchema, GraphScopeSchema, GraphQ
13
13
  export { GraphService } from './graph-service.js';
14
14
  // Format E Codec
15
15
  export { FormatECodec } from './format-e-codec.js';
16
+ // CR-SM-359: die Tuer des Format-E-Vertrags und die eine SE-Codec-Instanz — Konsumenten bauen keine eigene.
17
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema } from './format-e-door.js';
16
18
  export { DefaultRuleEngine } from './rule-engine.js';
17
19
  export { InMemoryAuditLog, FileOperationsLog, AUDIT_FILE, AUDIT_BASENAME, DEFAULT_COMPACT_BYTES } from './audit.js';
18
20
  export { MemoryAdapter } from './memory-adapter.js';
@@ -24,7 +26,7 @@ export { SE_DESCRIPTOR, createSeDescriptor, projectToOntologyGraph, fromOntology
24
26
  export { findRoot } from './find-root.js';
25
27
  // The shared directed impact traversal (CR-GC-365 b) — one definition for
26
28
  // graphcode's graph_impact and graph-view-edit's ImpactMap.
27
- export { impactSlice } from './impact-slice.js';
29
+ export { impactSlice, ImpactSliceSchema } from './impact-slice.js';
28
30
  // Edge ops — update-edge (flip/retype) + merge-nodes, shared by GraphService.mutate()
29
31
  // and the graphcode Apply-Gate (CR-198)
30
32
  export { applyEdgeOps, updateEdge, mergeNodes } from './edge-ops.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigloch/graph-api-core",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "peerDependencies": {
46
- "@sigloch/contracts": ">=10.10 <11",
46
+ "@sigloch/contracts": ">=10.11 <11",
47
47
  "kuzu-wasm": "^0.11.3"
48
48
  },
49
49
  "peerDependenciesMeta": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@sigloch/contracts": ">=10 <11",
55
+ "@sigloch/contracts": ">=10.11 <11",
56
56
  "kuzu-wasm": "^0.11.3"
57
57
  }
58
58
  }