@sigloch/graph-api-core 5.11.2 → 6.0.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.
@@ -22,6 +22,17 @@ const MERGE_RE = /^M\s+(.+)$/;
22
22
  const FORMAT_E_FENCE = /```format-e\s*\n([\s\S]*?)```/;
23
23
  /** Inline attribute block: [key:value,key:value] */
24
24
  const INLINE_ATTRS_RE = /\[([^\]]+)\]$/;
25
+ /**
26
+ * CR-SM-446 — ein Block am Ende einer KNOTENZEILE ist nur dann ein Attributblock, wenn JEDES
27
+ * Glied die Form `schluessel:wert` hat. Vorher zaehlte jede eckige Klammer am Zeilenende: aus der
28
+ * Beschreibung „… höchstens [limit ≤ 100]" wurde „… höchstens", ohne Fehler. Eine Beschreibung
29
+ * darf eckige Klammern tragen (Parameter in der Anforderung, CR-GC-979 in graphcode).
30
+ *
31
+ * Mehrdeutig bleibt ein Text, der selbst mit `[wort:wert]` endet; er wird weiter als
32
+ * Attributblock gelesen (benannter Preis der Variante A, CR-SM-445).
33
+ */
34
+ const ATTR_PAIR_RE = /^\s*[A-Za-z_]\w*\s*:/;
35
+ const isAttrBlock = (raw) => raw.split(',').every(pair => ATTR_PAIR_RE.test(pair));
25
36
  /**
26
37
  * CR-SM-332 (ITEM-2026-183) — Format E ist ZEILENBASIERT, also darf kein Feld eine Zeile
27
38
  * beenden koennen. `serialize` schrieb `|${description}` roh hinaus; eine Beschreibung mit
@@ -298,7 +309,7 @@ export class FormatECodec {
298
309
  let mainPart = rest;
299
310
  let inlineAttrs;
300
311
  const attrMatch = INLINE_ATTRS_RE.exec(rest);
301
- if (attrMatch) {
312
+ if (attrMatch && isAttrBlock(attrMatch[1])) {
302
313
  mainPart = rest.slice(0, attrMatch.index).trim();
303
314
  inlineAttrs = this.parseInlineAttrs(attrMatch[1], nodeType);
304
315
  }
@@ -6,15 +6,15 @@
6
6
  * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
7
  * ein Konsument den Vertrag eines anderen definiert.
8
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).
9
+ * Die Tuer hat zwei Teile (CR-SM-450/451): das Zod-Schema `FormatEInputSchema` ist reine Struktur und
10
+ * wird vom Konsumenten geparst, die Funktion `leseFormatE` liest die geparste Eingabe ueber den Codec. Ein Vertrag traegt keine frei programmierte Pruefung
11
+ * (FAQ vertrag-ohne-refine-custom); der Codec ist keine Schema-Pruefung, sondern ein Leser.
12
12
  *
13
13
  * @author andreas@siglochconsulting
14
14
  */
15
15
  import { z } from 'zod/v4';
16
16
  import { FormatECodec } from './format-e-codec.js';
17
- import type { Graph } from './types.js';
17
+ import type { FormatEDiff } from './types.js';
18
18
  /**
19
19
  * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
20
  * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
@@ -22,16 +22,44 @@ import type { Graph } from './types.js';
22
22
  */
23
23
  export declare const SE_FORMAT_E_CODEC: FormatECodec;
24
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.
25
+ * Eingabe der Tuer: `{ text, bestand }`. Der Parser typisiert uids, die der Text nicht deklariert,
26
+ * aus dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
27
+ * `### <TYPE>`-Sektion. Reine Struktur (CR-SM-450): der Vertrag traegt keine eigene Pruefung, der
28
+ * Bestand ist ein ganzer `GraphSchema` (Knoten UND Kanten).
30
29
  */
31
- export declare const FormatEInputSchema: z.ZodPipe<z.ZodObject<{
30
+ export declare const FormatEInputSchema: z.ZodObject<{
32
31
  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
- }>>;
32
+ bestand: z.ZodObject<{
33
+ nodes: z.ZodArray<z.ZodObject<{
34
+ uid: z.ZodString;
35
+ type: z.ZodString;
36
+ name: z.ZodString;
37
+ description: z.ZodOptional<z.ZodString>;
38
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
39
+ createdAt: z.ZodOptional<z.ZodString>;
40
+ updatedAt: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strip>>;
42
+ edges: z.ZodArray<z.ZodObject<{
43
+ sourceId: z.ZodString;
44
+ targetId: z.ZodString;
45
+ edgeType: z.ZodString;
46
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
47
+ }, z.core.$strip>>;
48
+ }, z.core.$strip>;
49
+ }, z.core.$strip>;
50
+ /** Die geparste Eingabe der Tuer. */
51
+ export type FormatEInput = z.infer<typeof FormatEInputSchema>;
52
+ /** Ergebnis von `leseFormatE`: der Diff, oder die Meldungen des Codecs (wortgleich). */
53
+ export type FormatELesung = {
54
+ ok: true;
55
+ diff: FormatEDiff;
56
+ } | {
57
+ ok: false;
58
+ messages: string[];
59
+ };
60
+ /**
61
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec. Nimmt die schon GEPARSTE Eingabe: wer liest,
62
+ * parst den Vertrag `FormatEInputSchema` an seiner Grenze selbst (Strukturfehler sind dort ein
63
+ * ZodError, CR-SM-451) und reicht das Ergebnis hierher. Wirft nicht.
64
+ */
65
+ export declare function leseFormatE(eingabe: FormatEInput): FormatELesung;
@@ -6,15 +6,16 @@
6
6
  * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
7
  * ein Konsument den Vertrag eines anderen definiert.
8
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).
9
+ * Die Tuer hat zwei Teile (CR-SM-450/451): das Zod-Schema `FormatEInputSchema` ist reine Struktur und
10
+ * wird vom Konsumenten geparst, die Funktion `leseFormatE` liest die geparste Eingabe ueber den Codec. Ein Vertrag traegt keine frei programmierte Pruefung
11
+ * (FAQ vertrag-ohne-refine-custom); der Codec ist keine Schema-Pruefung, sondern ein Leser.
12
12
  *
13
13
  * @author andreas@siglochconsulting
14
14
  */
15
15
  import { z } from 'zod/v4';
16
16
  import { FormatECodec } from './format-e-codec.js';
17
17
  import { SE_DESCRIPTOR } from './se-descriptor.js';
18
+ import { GraphSchema } from './schemas.js';
18
19
  /**
19
20
  * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
21
  * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
@@ -22,21 +23,25 @@ import { SE_DESCRIPTOR } from './se-descriptor.js';
22
23
  */
23
24
  export const SE_FORMAT_E_CODEC = new FormatECodec(SE_DESCRIPTOR);
24
25
  /**
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.
26
+ * Eingabe der Tuer: `{ text, bestand }`. Der Parser typisiert uids, die der Text nicht deklariert,
27
+ * aus dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
28
+ * `### <TYPE>`-Sektion. Reine Struktur (CR-SM-450): der Vertrag traegt keine eigene Pruefung, der
29
+ * Bestand ist ein ganzer `GraphSchema` (Knoten UND Kanten).
30
30
  */
31
- export const FormatEInputSchema = z
32
- .object({
31
+ export const FormatEInputSchema = z.object({
33
32
  text: z.string(),
34
- bestand: z.custom((g) => typeof g === 'object' && g !== null && Array.isArray(g.nodes)),
35
- })
36
- .transform(({ text, bestand }, ctx) => {
33
+ bestand: GraphSchema,
34
+ });
35
+ /**
36
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec. Nimmt die schon GEPARSTE Eingabe: wer liest,
37
+ * parst den Vertrag `FormatEInputSchema` an seiner Grenze selbst (Strukturfehler sind dort ein
38
+ * ZodError, CR-SM-451) und reicht das Ergebnis hierher. Wirft nicht.
39
+ */
40
+ export function leseFormatE(eingabe) {
41
+ const { text, bestand } = eingabe;
37
42
  const typeIndex = new Map(bestand.nodes.map((n) => [n.uid, n.type]));
38
43
  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
- });
44
+ if (diff.errors.length > 0)
45
+ return { ok: false, messages: diff.errors };
46
+ return { ok: true, diff };
47
+ }
package/dist/index.d.ts CHANGED
@@ -13,7 +13,8 @@ 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
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema, leseFormatE } from './format-e-door.js';
17
+ export type { FormatEInput, FormatELesung } from './format-e-door.js';
17
18
  export { commandsToFormatE } from './format-e-commands.js';
18
19
  export { applyDelta, deltaToFormatE, edgeToTrace, formatEToDelta, formatEToExportedGraph, graphToFormatE, nodeToElement, toExportedGraph } from './graph-delta.js';
19
20
  export type { ExportedElement, ExportedGraph, ExportedTrace, GraphDelta } from './graph-delta.js';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export { GraphService } from './graph-service.js';
14
14
  // Format E Codec
15
15
  export { FormatECodec } from './format-e-codec.js';
16
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';
17
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema, leseFormatE } from './format-e-door.js';
18
18
  export { commandsToFormatE } from './format-e-commands.js';
19
19
  export { applyDelta, deltaToFormatE, edgeToTrace, formatEToDelta, formatEToExportedGraph, graphToFormatE, nodeToElement, toExportedGraph } from './graph-delta.js';
20
20
  export { DefaultRuleEngine } from './rule-engine.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigloch/graph-api-core",
3
- "version": "5.11.2",
3
+ "version": "6.0.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",