@modernrelay/orbit-omnigraph 0.2.0 → 0.13.6

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.
@@ -271,25 +271,30 @@ function parseBody(body) {
271
271
  const constraints = [];
272
272
  for (const stmt of splitStatements(body)) {
273
273
  if (stmt.startsWith("@")) {
274
- const { anns: anns2 } = scanAnnotations(stmt, 0);
275
- for (const a of anns2) constraints.push(a.raw);
274
+ const { anns } = scanAnnotations(stmt, 0);
275
+ for (const a of anns) constraints.push(a.raw);
276
276
  continue;
277
277
  }
278
- const head = /^([A-Za-z_]\w*)\s*:\s*/.exec(stmt);
279
- if (!head || head[1] === void 0) continue;
280
- const name = head[1];
281
- const rest = stmt.slice(head[0].length);
282
- const { type, optional, end } = parseTypeRef(rest);
283
- const { anns } = scanAnnotations(rest, end);
284
- properties.push({
285
- name,
286
- type,
287
- optional,
288
- key: anns.some((a) => a.name === "key"),
289
- unique: anns.some((a) => a.name === "unique"),
290
- index: anns.some((a) => a.name === "index"),
291
- annotations: anns.map((a) => a.raw)
292
- });
278
+ let cursor = stmt;
279
+ for (; ; ) {
280
+ const head = /^([A-Za-z_]\w*)\s*:\s*/.exec(cursor);
281
+ if (!head || head[1] === void 0) break;
282
+ const name = head[1];
283
+ const rest = cursor.slice(head[0].length);
284
+ const { type, optional, end } = parseTypeRef(rest);
285
+ const { anns, end: annsEnd } = scanAnnotations(rest, end);
286
+ properties.push({
287
+ name,
288
+ type,
289
+ optional,
290
+ key: anns.some((a) => a.name === "key"),
291
+ unique: anns.some((a) => a.name === "unique"),
292
+ index: anns.some((a) => a.name === "index"),
293
+ annotations: anns.map((a) => a.raw)
294
+ });
295
+ cursor = rest.slice(annsEnd).trimStart();
296
+ if (cursor === "") break;
297
+ }
293
298
  }
294
299
  for (const raw of constraints) {
295
300
  const m = /^@(key|unique|index)\((.*)\)$/s.exec(raw);
@@ -343,12 +348,17 @@ function parsePgSchema(source) {
343
348
  continue;
344
349
  }
345
350
  let impls = [];
351
+ const skipAnnotations = () => {
352
+ pos = scanAnnotations(src, pos).end;
353
+ };
354
+ skipAnnotations();
346
355
  if (kw === "node") {
347
356
  const im = /^\s*implements\s+([A-Za-z_]\w*(?:\s*,\s*[A-Za-z_]\w*)*)/.exec(src.slice(pos));
348
357
  if (im && im[1] !== void 0) {
349
358
  impls = im[1].split(",").map((s) => s.trim());
350
359
  pos += im[0].length;
351
360
  }
361
+ skipAnnotations();
352
362
  }
353
363
  let braceIdx = pos;
354
364
  while (braceIdx < src.length && /\s/.test(src.charAt(braceIdx))) braceIdx++;
@@ -472,7 +482,14 @@ function propTypeMap(t) {
472
482
  }
473
483
  function normalizeData(data, types) {
474
484
  const out = {};
475
- for (const [k, v] of Object.entries(data)) out[k] = normalizeValue(types.get(k), v);
485
+ for (const [k, v] of Object.entries(data)) {
486
+ Object.defineProperty(out, k, {
487
+ value: normalizeValue(types.get(k), v),
488
+ enumerable: true,
489
+ writable: true,
490
+ configurable: true
491
+ });
492
+ }
476
493
  return out;
477
494
  }
478
495
  function requireStringId(data, what) {
@@ -513,5 +530,5 @@ function normalizeEdge(line, schema) {
513
530
  }
514
531
 
515
532
  export { InvalidExportLineError, ORBIT_TYPE_KEY, UnknownEdgeTypeError, bigIntKeyWarnings, classifyExportLine, decodeSourceId, edgeEndpointTypes, encodeSourceId, encodeSyntheticEdgeId, normalizeEdge, normalizeNode, parsePgSchema, schemaFingerprint };
516
- //# sourceMappingURL=chunk-32TESFMK.js.map
517
- //# sourceMappingURL=chunk-32TESFMK.js.map
533
+ //# sourceMappingURL=chunk-NT5KJVIT.js.map
534
+ //# sourceMappingURL=chunk-NT5KJVIT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/idCodec.ts","../src/pgSchema.ts","../src/normalize.ts"],"names":["body","braceIdx","blockEnd"],"mappings":";AA6BO,SAAS,cAAA,CAAe,MAAc,QAAA,EAA0B;AACrE,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,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,KAAK,IAAA,EAAM,WAAA,CAAY,QAAQ,CAAC,CAAA,EAAG,CAAC,cAAc,GAAG,KAAK,IAAA;AAAK,GAC3F;AACF","file":"chunk-NT5KJVIT.js","sourcesContent":["/**\n * Identity codec (spec Appendix B.3 / B.4).\n *\n * Omnigraph node ids are unique **per type only** (derived from the `@key`\n * tuple within each type's table), so unqualified ids are unsound as orbit\n * `NodeId`s. Every adapter path — nodes, edges, search results, view state,\n * services — MUST qualify ids through this one collision-proof tuple codec.\n * `JSON.stringify` of a fixed-arity string tuple is injective over its inputs\n * (quotes, brackets, commas, and unicode in either component are escaped), so\n * no `(kind, sourceId)` pair can collide with a different pair.\n *\n * Human-readable labels stay separate from identity; there is deliberately no\n * `namespaceIds:false` escape hatch (B.3).\n */\n\nexport interface DecodedSourceId {\n /** The namespace component: a node type name or an edge type name. */\n kind: string;\n /** The physical Omnigraph id within that type's table. */\n sourceId: string;\n}\n\n/**\n * Encode a `(kind, sourceId)` pair as a collision-proof orbit id.\n *\n * - Nodes: `encodeSourceId(NodeType, data.id)`\n * - Edges: `encodeSourceId(EdgeName, data.id)`; endpoints use\n * `encodeSourceId(endpointType, from|to)` (B.3).\n */\nexport function encodeSourceId(kind: string, sourceId: string): string {\n return JSON.stringify([kind, sourceId]);\n}\n\n/**\n * Decode an id produced by {@link encodeSourceId}.\n *\n * Returns `null` for anything that does not conform exactly (non-JSON input,\n * non-array JSON, wrong arity — including synthetic edge ids, which are\n * 4-tuples — or non-string elements). Never throws.\n */\nexport function decodeSourceId(id: string): DecodedSourceId | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(id);\n } catch {\n return null;\n }\n if (!Array.isArray(parsed) || parsed.length !== 2) return null;\n const [kind, sourceId] = parsed as unknown[];\n if (typeof kind !== 'string' || typeof sourceId !== 'string') return null;\n return { kind, sourceId };\n}\n\n/**\n * Synthetic edge id for **query-derived** subgraphs (spec §5 rule, B.4).\n *\n * The GQ grammar has no edge variable, so the query path can never surface\n * physical edge ids; query-derived edges are identified by\n * `['synthetic-edge', EdgeName, source, target]` where `source`/`target` are\n * the already-encoded endpoint node ids.\n *\n * Exported for the future query path (B.5 expansion recipe — post-v1).\n * Caveats (B.4): parallel edges collapse under this scheme, and a dataset\n * MUST NOT mix synthetic ids with physical `/export` ids for the same edges —\n * one scheme per dataset, never both. Because a synthetic id is a 4-tuple,\n * {@link decodeSourceId} rejects it (`null`), keeping the two schemes\n * mechanically un-confusable.\n */\nexport function encodeSyntheticEdgeId(edgeName: string, source: string, target: string): string {\n return JSON.stringify(['synthetic-edge', edgeName, source, target]);\n}\n","/**\n * `.pg` schema model + tolerant parser (spec Appendix B.3 / B.6).\n *\n * The adapter needs three things from the graph schema, all served here:\n * 1. edge endpoint-type resolution (B.3 — export edge lines carry bare\n * `from`/`to` ids without endpoint types),\n * 2. per-property wire-type knowledge for temporal/blob normalization (B.6),\n * 3. a stable schema fingerprint for the export revision stamp (B.2).\n *\n * The parser is deliberately tolerant: it extracts the declarations it\n * understands (interfaces, node blocks, edge declarations, properties,\n * constraints) and preserves anything else — unknown annotations survive as\n * raw strings, unknown type spellings become `{ kind: 'unknown' }` — so a\n * newer server grammar degrades gracefully instead of failing the load.\n *\n * Browser-safe: no `node:` imports. The fingerprint is a pure FNV-1a 64-bit\n * hash rather than `node:crypto` sha256 so this module can sit on the\n * browser entry's critical path.\n */\n\n// ---------------------------------------------------------------------------\n// Model\n// ---------------------------------------------------------------------------\n\n/** Closed scalar set per the `.pg` grammar (docs/user/schema). */\nexport type PgScalarName =\n | 'String'\n | 'Blob'\n | 'Bool'\n | 'I32'\n | 'I64'\n | 'U32'\n | 'U64'\n | 'F32'\n | 'F64'\n | 'Date'\n | 'DateTime';\n\nexport type PgType =\n | PgScalarName\n | { kind: 'vector'; dim: number }\n | { kind: 'enum'; values: readonly string[] }\n | { kind: 'list'; element: PgScalarName }\n | { kind: 'unknown'; raw: string };\n\nexport interface PgProperty {\n name: string;\n type: PgType;\n /** `T?` nullability. */\n optional: boolean;\n /** Set by inline `@key` or a body-level `@key(...)` naming this property. */\n key: boolean;\n /** Set by inline `@unique` or a body-level `@unique(...)` naming this property. */\n unique: boolean;\n /** Set by inline `@index` or a body-level `@index(...)` naming this property. */\n index: boolean;\n /** Every annotation as written (`'@key'`, `'@embed(\"body\")'`) — unknown ones preserved verbatim. */\n annotations: readonly string[];\n}\n\nexport interface PgInterfaceType {\n name: string;\n properties: readonly PgProperty[];\n /** Body-level constraint declarations preserved verbatim (e.g. `'@unique(a, b)'`). */\n constraints: readonly string[];\n}\n\nexport interface PgNodeType {\n name: string;\n /** Interface names from the `implements` clause (already expanded into `properties`). */\n implements: readonly string[];\n properties: readonly PgProperty[];\n constraints: readonly string[];\n}\n\nexport interface PgEdgeType {\n name: string;\n /** Source (from) node type name. */\n from: string;\n /** Destination (to) node type name. */\n to: string;\n /** Raw `@card` bounds, e.g. `'1..1'`, `'0..*'`. Absent means the default `0..*`. */\n card?: string;\n /** Header annotations as written (including the `@card(...)` one, if any). */\n annotations: readonly string[];\n properties: readonly PgProperty[];\n constraints: readonly string[];\n}\n\nexport interface PgSchema {\n interfaces: readonly PgInterfaceType[];\n nodes: readonly PgNodeType[];\n edges: readonly PgEdgeType[];\n}\n\nconst SCALARS: ReadonlySet<string> = new Set<PgScalarName>([\n 'String',\n 'Blob',\n 'Bool',\n 'I32',\n 'I64',\n 'U32',\n 'U64',\n 'F32',\n 'F64',\n 'Date',\n 'DateTime',\n]);\n\n// ---------------------------------------------------------------------------\n// Lexical helpers (string-aware; `.pg` strings are double-quoted with `\\` escapes)\n// ---------------------------------------------------------------------------\n\n/** Blank out line and block comments, preserving newlines and string literals. */\nfunction stripComments(src: string): string {\n let out = '';\n let i = 0;\n const n = src.length;\n while (i < n) {\n const ch = src.charAt(i);\n if (ch === '\"') {\n out += ch;\n i++;\n while (i < n) {\n const c = src.charAt(i);\n out += c;\n i++;\n if (c === '\\\\' && i < n) {\n out += src.charAt(i);\n i++;\n } else if (c === '\"') break;\n }\n } else if (ch === '/' && src.charAt(i + 1) === '/') {\n while (i < n && src.charAt(i) !== '\\n') i++;\n } else if (ch === '/' && src.charAt(i + 1) === '*') {\n i += 2;\n while (i < n && !(src.charAt(i) === '*' && src.charAt(i + 1) === '/')) {\n out += src.charAt(i) === '\\n' ? '\\n' : ' ';\n i++;\n }\n i += 2;\n } else {\n out += ch;\n i++;\n }\n }\n return out;\n}\n\n/** Index just past the `}` matching the `{` at `openIdx`, or `src.length` if unbalanced. */\nfunction findBlockEnd(src: string, openIdx: number): number {\n let depth = 0;\n let i = openIdx;\n const n = src.length;\n while (i < n) {\n const ch = src.charAt(i);\n if (ch === '\"') {\n i++;\n while (i < n) {\n const c = src.charAt(i);\n i++;\n if (c === '\\\\') i++;\n else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '{') depth++;\n else if (ch === '}') {\n depth--;\n if (depth === 0) return i + 1;\n }\n i++;\n }\n return n;\n}\n\n/** Split a block body into statements at newlines that sit outside parens/brackets/strings. */\nfunction splitStatements(body: string): string[] {\n const out: string[] = [];\n let depth = 0;\n let current = '';\n let i = 0;\n const n = body.length;\n while (i < n) {\n const ch = body.charAt(i);\n if (ch === '\"') {\n current += ch;\n i++;\n while (i < n) {\n const c = body.charAt(i);\n current += c;\n i++;\n if (c === '\\\\' && i < n) {\n current += body.charAt(i);\n i++;\n } else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '(' || ch === '[') depth++;\n else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);\n if (ch === '\\n' && depth === 0) {\n out.push(current);\n current = '';\n } else {\n current += ch;\n }\n i++;\n }\n out.push(current);\n return out.map((s) => s.trim()).filter((s) => s.length > 0);\n}\n\ninterface RawAnnotation {\n name: string;\n args?: string;\n raw: string;\n}\n\n/** Scan a run of `@ident` / `@ident(...)` annotations starting at `start`. */\nfunction scanAnnotations(src: string, start: number): { anns: RawAnnotation[]; end: number } {\n const anns: RawAnnotation[] = [];\n let i = start;\n const n = src.length;\n for (;;) {\n let j = i;\n while (j < n && /\\s/.test(src.charAt(j))) j++;\n if (src.charAt(j) !== '@') break;\n const m = /^@([A-Za-z_]\\w*)/.exec(src.slice(j));\n if (!m || m[1] === undefined) break;\n const name = m[1];\n let end = j + m[0].length;\n let args: string | undefined;\n if (src.charAt(end) === '(') {\n let depth = 0;\n let k = end;\n while (k < n) {\n const ch = src.charAt(k);\n if (ch === '\"') {\n k++;\n while (k < n) {\n const c = src.charAt(k);\n k++;\n if (c === '\\\\') k++;\n else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '(') depth++;\n else if (ch === ')') {\n depth--;\n if (depth === 0) {\n k++;\n break;\n }\n }\n k++;\n }\n args = src.slice(end + 1, k - 1);\n end = k;\n }\n const entry: RawAnnotation = { name, raw: src.slice(j, end) };\n if (args !== undefined) entry.args = args;\n anns.push(entry);\n i = end;\n }\n return { anns, end: i };\n}\n\n/** Split on top-level commas (outside parens/strings), trim, drop empties. */\nfunction splitArgs(args: string): string[] {\n const out: string[] = [];\n let depth = 0;\n let current = '';\n for (let i = 0; i < args.length; i++) {\n const ch = args.charAt(i);\n if (ch === '\"') {\n current += ch;\n i++;\n while (i < args.length) {\n const c = args.charAt(i);\n current += c;\n if (c === '\\\\') {\n i++;\n current += args.charAt(i);\n } else if (c === '\"') break;\n i++;\n }\n continue;\n }\n if (ch === '(' || ch === '[') depth++;\n else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);\n if (ch === ',' && depth === 0) {\n out.push(current);\n current = '';\n } else {\n current += ch;\n }\n }\n out.push(current);\n return out.map((s) => s.trim()).filter((s) => s.length > 0);\n}\n\n// ---------------------------------------------------------------------------\n// Statement parsing\n// ---------------------------------------------------------------------------\n\ninterface MutableTypeBody {\n properties: PgProperty[];\n constraints: string[];\n}\n\nfunction parseTypeRef(text: string): { type: PgType; optional: boolean; end: number } {\n let i = 0;\n const n = text.length;\n while (i < n && /\\s/.test(text.charAt(i))) i++;\n let type: PgType;\n if (text.charAt(i) === '[') {\n const m = /^\\[\\s*([A-Za-z_]\\w*)\\s*\\]/.exec(text.slice(i));\n if (m && m[1] !== undefined && SCALARS.has(m[1])) {\n type = { kind: 'list', element: m[1] as PgScalarName };\n i += m[0].length;\n } else {\n const close = text.indexOf(']', i);\n const end = close === -1 ? n : close + 1;\n type = { kind: 'unknown', raw: text.slice(i, end).trim() };\n i = end;\n }\n } else {\n const m = /^([A-Za-z_]\\w*)/.exec(text.slice(i));\n if (!m || m[1] === undefined) {\n return { type: { kind: 'unknown', raw: text.trim() }, optional: false, end: n };\n }\n const ident = m[1];\n i += m[0].length;\n if ((ident === 'enum' || ident === 'Vector') && text.charAt(i) === '(') {\n let depth = 0;\n let k = i;\n while (k < n) {\n const ch = text.charAt(k);\n if (ch === '(') depth++;\n else if (ch === ')') {\n depth--;\n if (depth === 0) {\n k++;\n break;\n }\n }\n k++;\n }\n const inner = text.slice(i + 1, k - 1);\n i = k;\n if (ident === 'enum') {\n const values = splitArgs(inner).map((v) => v.replace(/^\"(.*)\"$/s, '$1'));\n type = { kind: 'enum', values };\n } else {\n const dim = Number.parseInt(inner.trim(), 10);\n type = Number.isFinite(dim)\n ? { kind: 'vector', dim }\n : { kind: 'unknown', raw: `Vector(${inner})` };\n }\n } else if (SCALARS.has(ident)) {\n type = ident as PgScalarName;\n } else {\n type = { kind: 'unknown', raw: ident };\n }\n }\n let optional = false;\n if (text.charAt(i) === '?') {\n optional = true;\n i++;\n }\n return { type, optional, end: i };\n}\n\nfunction parseBody(body: string): MutableTypeBody {\n const properties: PgProperty[] = [];\n const constraints: string[] = [];\n for (const stmt of splitStatements(body)) {\n if (stmt.startsWith('@')) {\n const { anns } = scanAnnotations(stmt, 0);\n for (const a of anns) constraints.push(a.raw);\n continue;\n }\n // Review P2: a statement may carry SEVERAL whitespace-separated\n // properties (`id: String when: DateTime`) — the old single-parse kept\n // only the first and silently dropped the rest. Loop until the trailer\n // stops looking like another property head; junk trailers stay\n // tolerant-skipped as before.\n let cursor = stmt;\n for (;;) {\n const head = /^([A-Za-z_]\\w*)\\s*:\\s*/.exec(cursor);\n if (!head || head[1] === undefined) break; // tolerant: skip unrecognized statements\n const name = head[1];\n const rest = cursor.slice(head[0].length);\n const { type, optional, end } = parseTypeRef(rest);\n const { anns, end: annsEnd } = scanAnnotations(rest, end);\n properties.push({\n name,\n type,\n optional,\n key: anns.some((a) => a.name === 'key'),\n unique: anns.some((a) => a.name === 'unique'),\n index: anns.some((a) => a.name === 'index'),\n annotations: anns.map((a) => a.raw),\n });\n cursor = rest.slice(annsEnd).trimStart();\n if (cursor === '') break;\n }\n }\n // Body-level @key(a, b) / @unique(a) / @index(a) constraints flag the named properties.\n for (const raw of constraints) {\n const m = /^@(key|unique|index)\\((.*)\\)$/s.exec(raw);\n if (!m || m[1] === undefined || m[2] === undefined) continue;\n const flag = m[1] as 'key' | 'unique' | 'index';\n for (const propName of splitArgs(m[2])) {\n const prop = properties.find((p) => p.name === propName);\n if (prop) prop[flag] = true;\n }\n }\n return { properties, constraints };\n}\n\n// ---------------------------------------------------------------------------\n// Top-level parse\n// ---------------------------------------------------------------------------\n\n/**\n * Parse `.pg` source into a {@link PgSchema}. Tolerant by design: malformed\n * or unrecognized declarations are skipped, not fatal; `implements` clauses\n * are expanded into node properties (node-declared properties win on name\n * collisions, matching the server's table layout).\n */\nexport function parsePgSchema(source: string): PgSchema {\n const src = stripComments(source);\n const interfaces: PgInterfaceType[] = [];\n const nodes: (PgNodeType & { properties: PgProperty[] })[] = [];\n const edges: PgEdgeType[] = [];\n\n const headRe = /\\b(interface|node|edge)\\s+([A-Za-z_]\\w*)/g;\n let m: RegExpExecArray | null;\n while ((m = headRe.exec(src)) !== null) {\n const kw = m[1];\n const name = m[2];\n if (kw === undefined || name === undefined) continue;\n let pos = headRe.lastIndex;\n\n if (kw === 'edge') {\n const em = /^\\s*:\\s*([A-Za-z_]\\w*)\\s*->\\s*([A-Za-z_]\\w*)/.exec(src.slice(pos));\n if (!em || em[1] === undefined || em[2] === undefined) continue; // tolerant skip\n pos += em[0].length;\n const { anns, end } = scanAnnotations(src, pos);\n pos = end;\n let body: MutableTypeBody = { properties: [], constraints: [] };\n let braceIdx = pos;\n while (braceIdx < src.length && /\\s/.test(src.charAt(braceIdx))) braceIdx++;\n if (src.charAt(braceIdx) === '{') {\n const blockEnd = findBlockEnd(src, braceIdx);\n body = parseBody(src.slice(braceIdx + 1, blockEnd - 1));\n pos = blockEnd;\n }\n const card = anns.find((a) => a.name === 'card')?.args?.trim();\n const edge: PgEdgeType = {\n name,\n from: em[1],\n to: em[2],\n annotations: anns.map((a) => a.raw),\n properties: body.properties,\n constraints: body.constraints,\n ...(card !== undefined ? { card } : {}),\n };\n edges.push(edge);\n headRe.lastIndex = pos;\n continue;\n }\n\n // interface / node: optional `implements A, B` (node only), then a block.\n let impls: string[] = [];\n // Review P1: the grammar carries head annotations (`@card`/`@unique`\n // prove the family) — `node Account @rename_from(\"User\") { … }` used to\n // hit the tolerant skip and silently DROP the whole declaration.\n // Annotations are consumed (and ignored — migration metadata) on either\n // side of `implements`, through the SAME scanner the body lane uses —\n // it honors nested parens and escaped quotes, where a first-`)` regex\n // truncated `@rename_from(\"User (legacy)\")` and re-dropped the node\n // (Greptile P1 on the first fix).\n const skipAnnotations = (): void => {\n pos = scanAnnotations(src, pos).end;\n };\n skipAnnotations();\n if (kw === 'node') {\n const im = /^\\s*implements\\s+([A-Za-z_]\\w*(?:\\s*,\\s*[A-Za-z_]\\w*)*)/.exec(src.slice(pos));\n if (im && im[1] !== undefined) {\n impls = im[1].split(',').map((s) => s.trim());\n pos += im[0].length;\n }\n skipAnnotations();\n }\n let braceIdx = pos;\n while (braceIdx < src.length && /\\s/.test(src.charAt(braceIdx))) braceIdx++;\n if (src.charAt(braceIdx) !== '{') continue; // tolerant skip\n const blockEnd = findBlockEnd(src, braceIdx);\n const body = parseBody(src.slice(braceIdx + 1, blockEnd - 1));\n headRe.lastIndex = blockEnd;\n if (kw === 'interface') {\n interfaces.push({ name, properties: body.properties, constraints: body.constraints });\n } else {\n nodes.push({\n name,\n implements: impls,\n properties: body.properties,\n constraints: body.constraints,\n });\n }\n }\n\n // Expand implements clauses: interface properties precede the node's own,\n // except where the node re-declares a name (node declaration wins).\n for (const node of nodes) {\n if (node.implements.length === 0) continue;\n const own = new Set(node.properties.map((p) => p.name));\n const inherited: PgProperty[] = [];\n for (const ifaceName of node.implements) {\n const iface = interfaces.find((i) => i.name === ifaceName);\n if (!iface) continue; // tolerant: unknown interface\n for (const p of iface.properties) {\n if (!own.has(p.name) && !inherited.some((q) => q.name === p.name)) inherited.push(p);\n }\n }\n node.properties = [...inherited, ...node.properties];\n }\n\n return { interfaces, nodes, edges };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve an edge type's declared endpoint node types (B.3). Export edge\n * lines carry bare `from`/`to` ids, so endpoint types come from here. Edge\n * names match exactly first, then case-insensitively (the server matches edge\n * names case-insensitively). Returns `null` for an unknown edge name.\n */\nexport function edgeEndpointTypes(\n schema: PgSchema,\n edgeName: string,\n): { from: string; to: string } | null {\n const lower = edgeName.toLowerCase();\n const edge =\n schema.edges.find((e) => e.name === edgeName) ??\n schema.edges.find((e) => e.name.toLowerCase() === lower);\n return edge ? { from: edge.from, to: edge.to } : null;\n}\n\n/**\n * Stable fingerprint of `.pg` source for the B.2 revision stamp: FNV-1a\n * 64-bit over the UTF-8 bytes of the source, as 16 lowercase hex chars.\n *\n * Pure and browser-safe (no `node:crypto`). Hashes the source **verbatim**:\n * any textual change — including comments or whitespace — changes the\n * fingerprint, which is the conservative choice for drift detection.\n */\nexport function schemaFingerprint(source: string): string {\n const MASK64 = 0xffffffffffffffffn;\n let h = 0xcbf29ce484222325n;\n const bytes = new TextEncoder().encode(source);\n for (const b of bytes) {\n h ^= BigInt(b);\n h = (h * 0x100000001b3n) & MASK64;\n }\n return h.toString(16).padStart(16, '0');\n}\n\nexport interface BigIntKeyWarning {\n /** Node or edge type name. */\n type: string;\n /** The hazardous property. */\n property: string;\n}\n\n/**\n * B.6 hazard scan: `I64`/`U64` properties used as identity (`@key` or named\n * `id`). The HTTP path emits native JSON numbers even past ±2^53 — silently\n * rounded by `JSON.parse`, unrescued by the SDK — so two distinct big-int ids\n * can collapse after rounding, violating §5. Surface these before loading.\n */\nexport function bigIntKeyWarnings(schema: PgSchema): BigIntKeyWarning[] {\n const out: BigIntKeyWarning[] = [];\n for (const t of [...schema.nodes, ...schema.edges]) {\n for (const p of t.properties) {\n if ((p.type === 'I64' || p.type === 'U64') && (p.key || p.name === 'id')) {\n out.push({ type: t.name, property: p.name });\n }\n }\n }\n return out;\n}\n","/**\n * Export-line classification and normalization (spec Appendix B.2 / B.3 / B.6).\n *\n * `/export` streams NDJSON — one JSON object per line, `data` passed through\n * **verbatim** by the SDK. This module turns those lines into orbit\n * `GraphNode`/`GraphEdge` values:\n *\n * - ids are namespaced through the B.3 codec (`encodeSourceId`),\n * - the node/edge KIND is injected as {@link ORBIT_TYPE_KEY} — namespaced so\n * a schema's own `type` property passes through as ordinary data (B.6),\n * - edge endpoint types are resolved from the `.pg` schema (edge lines carry\n * bare `from`/`to` ids — B.3),\n * - attr values are normalized to the query-path string forms (B.6) so\n * generated types and §16.6 temporal dimensions see one encoding\n * regardless of read path:\n * * `Date` — export sends **days since Unix epoch** (number) →\n * `'YYYY-MM-DD'` (UTC)\n * * `DateTime` — export sends **epoch milliseconds** (number) →\n * ISO 8601 (`'YYYY-MM-DDTHH:MM:SS.mmmZ'`)\n * * `Blob` — inline internal blobs arrive as `'base64:<data>'` →\n * `'data:application/octet-stream;base64,<data>'`;\n * external-URI refs pass through verbatim (B.10)\n * * everything else — verbatim.\n *\n * Non-finite float sentinels (`'NaN'`/`'Infinity'`/`'-Infinity'`) are a\n * **query-path-only** encoding: a non-finite stored float aborts `/export`\n * server-side, so export-loaded data never contains the sentinels (B.6).\n * This module therefore does NOT special-case them.\n */\n\nimport type { GraphEdge, GraphNode } from '@modernrelay/orbit-core';\nimport { encodeSourceId } from './idCodec';\nimport {\n edgeEndpointTypes,\n type PgEdgeType,\n type PgNodeType,\n type PgProperty,\n type PgSchema,\n type PgType,\n} from './pgSchema';\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** An edge line names an edge type the `.pg` schema does not declare (B.3). */\nexport class UnknownEdgeTypeError extends Error {\n override readonly name = 'UnknownEdgeTypeError';\n readonly edgeName: string;\n constructor(edgeName: string) {\n super(\n `Unknown edge type '${edgeName}': not declared in the graph schema, so its ` +\n `endpoint node types cannot be resolved (spec B.3).`,\n );\n this.edgeName = edgeName;\n }\n}\n\n/** An export line is structurally unusable (e.g. missing/non-string `data.id`). */\nexport class InvalidExportLineError extends Error {\n override readonly name = 'InvalidExportLineError';\n constructor(message: string) {\n super(message);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Classification (B.2 line shapes)\n// ---------------------------------------------------------------------------\n\nexport interface NodeExportLine {\n kind: 'node';\n type: string;\n data: Record<string, unknown>;\n}\n\nexport interface EdgeExportLine {\n kind: 'edge';\n edge: string;\n from: string;\n to: string;\n data: Record<string, unknown>;\n}\n\nexport type ClassifiedExportLine = NodeExportLine | EdgeExportLine | { kind: 'unknown' };\n\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v);\n}\n\n/**\n * Classify one parsed export line per the B.2 shapes:\n * - node line: `{\"type\": \"<NodeType>\", \"data\": {\"id\", …props}}`\n * - edge line: `{\"edge\": \"<EdgeName>\", \"from\": <src id>, \"to\": <dst id>, \"data\": {\"id\", …props}}`\n * Anything else is `{ kind: 'unknown' }`.\n */\nexport function classifyExportLine(line: unknown): ClassifiedExportLine {\n if (!isRecord(line) || !isRecord(line['data'])) return { kind: 'unknown' };\n const data = line['data'];\n if (\n typeof line['edge'] === 'string' &&\n typeof line['from'] === 'string' &&\n typeof line['to'] === 'string'\n ) {\n return { kind: 'edge', edge: line['edge'], from: line['from'], to: line['to'], data };\n }\n if (typeof line['type'] === 'string') {\n return { kind: 'node', type: line['type'], data };\n }\n return { kind: 'unknown' };\n}\n\n// ---------------------------------------------------------------------------\n// Value normalization (B.6)\n// ---------------------------------------------------------------------------\n\nconst MS_PER_DAY = 86_400_000;\n\n/** Format an epoch-day count as `'YYYY-MM-DD'` (UTC). Handles negative days. */\nfunction formatEpochDay(days: number): string {\n const d = new Date(days * MS_PER_DAY);\n const t = d.getTime();\n if (!Number.isFinite(t)) return String(days); // out of Date range — leave a readable value\n const y = d.getUTCFullYear();\n const year =\n y < 0\n ? `-${String(-y).padStart(6, '0')}`\n : y > 9999\n ? `+${String(y).padStart(6, '0')}`\n : String(y).padStart(4, '0');\n const month = String(d.getUTCMonth() + 1).padStart(2, '0');\n const day = String(d.getUTCDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\nfunction normalizeValue(type: PgType | undefined, value: unknown): unknown {\n if (type === undefined || value === null || value === undefined) return value;\n if (type === 'Date' && typeof value === 'number' && Number.isInteger(value)) {\n return formatEpochDay(value);\n }\n if (type === 'DateTime' && typeof value === 'number' && Number.isFinite(value)) {\n const d = new Date(value);\n return Number.isFinite(d.getTime()) ? d.toISOString() : value;\n }\n if (type === 'Blob' && typeof value === 'string' && value.startsWith('base64:')) {\n return `data:application/octet-stream;base64,${value.slice('base64:'.length)}`;\n }\n return value;\n}\n\nfunction propTypeMap(t: PgNodeType | PgEdgeType | undefined): ReadonlyMap<string, PgType> {\n const map = new Map<string, PgType>();\n if (t) for (const p of t.properties as readonly PgProperty[]) map.set(p.name, p.type);\n return map;\n}\n\nfunction normalizeData(\n data: Record<string, unknown>,\n types: ReadonlyMap<string, PgType>,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n // Review P2: source data can carry '__proto__' as an own key (JSON.parse\n // creates it) — defineProperty writes the own property, never the setter.\n for (const [k, v] of Object.entries(data)) {\n Object.defineProperty(out, k, {\n value: normalizeValue(types.get(k), v),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return out;\n}\n\nfunction requireStringId(data: Record<string, unknown>, what: string): string {\n const id = data['id'];\n if (typeof id !== 'string') {\n throw new InvalidExportLineError(\n `${what} export line has ${id === undefined ? 'no' : 'a non-string'} 'data.id' — ` +\n `cannot build a stable orbit id (spec B.3).`,\n );\n }\n return id;\n}\n\n// ---------------------------------------------------------------------------\n// Node / edge normalization (B.3)\n// ---------------------------------------------------------------------------\n\n/**\n * The adapter's node/edge KIND discriminator key (B.3/B.6).\n *\n * Namespaced on purpose: the adapter injects this field into someone else's\n * data, so it takes the awkward key and leaves the generic word `type` to the\n * schema author, who means something real by it (`Company.type = investor`).\n * A colon is illegal in `.pg` identifiers, so no schema property can ever\n * claim this key — the collision class is closed by construction, and a\n * source-declared `type` now flows through untouched with no preservation\n * mechanism, no warning, and no schema migration. Same convention as\n * GraphQL's `__typename` / JSON-LD's `@type`.\n */\nexport const ORBIT_TYPE_KEY = 'orbit:type';\n\n/**\n * Normalize a node export line to a `GraphNode`:\n * `id = encodeSourceId(type, data.id)`, `attrs = { …data, 'orbit:type' }`\n * with B.6 value normalization driven by the schema's property types. A node\n * type absent from the schema is tolerated — its attrs pass through verbatim\n * (identity never needs the schema on the node path).\n */\nexport function normalizeNode(\n line: { type: string; data: Record<string, unknown> },\n schema: PgSchema,\n): GraphNode {\n const nodeType = schema.nodes.find((n) => n.name === line.type);\n const id = encodeSourceId(line.type, requireStringId(line.data, `Node '${line.type}'`));\n return {\n id,\n // The discriminator is adapter-owned identity metadata. It lands LAST so\n // a forward-compatible export field literally named `orbit:type` cannot\n // forge the value the generated attrs unions promise (B.3/B.6).\n attrs: { ...normalizeData(line.data, propTypeMap(nodeType)), [ORBIT_TYPE_KEY]: line.type },\n };\n}\n\n/**\n * Normalize an edge export line to a `GraphEdge`:\n * `id = encodeSourceId(edge, data.id)`; `source`/`target` namespace the bare\n * `from`/`to` ids with the endpoint node types resolved from the schema\n * (B.3). Throws {@link UnknownEdgeTypeError} when the schema does not declare\n * the edge — endpoint identity cannot be constructed without it.\n */\nexport function normalizeEdge(\n line: { edge: string; from: string; to: string; data: Record<string, unknown> },\n schema: PgSchema,\n): GraphEdge {\n const endpoints = edgeEndpointTypes(schema, line.edge);\n if (endpoints === null) throw new UnknownEdgeTypeError(line.edge);\n const lower = line.edge.toLowerCase();\n const edgeType =\n schema.edges.find((e) => e.name === line.edge) ??\n schema.edges.find((e) => e.name.toLowerCase() === lower);\n const id = encodeSourceId(line.edge, requireStringId(line.data, `Edge '${line.edge}'`));\n return {\n id,\n source: encodeSourceId(endpoints.from, line.from),\n target: encodeSourceId(endpoints.to, line.to),\n // As on nodes, the adapter's resolved edge name lands last and always\n // wins the discriminator key; a source `type` property is ordinary data.\n attrs: { ...normalizeData(line.data, propTypeMap(edgeType)), [ORBIT_TYPE_KEY]: line.edge },\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { parsePgSchema, schemaFingerprint, ORBIT_TYPE_KEY } from './chunk-32TESFMK.js';
2
+ import { parsePgSchema, schemaFingerprint, ORBIT_TYPE_KEY } from './chunk-NT5KJVIT.js';
3
3
  import { readFileSync, writeFileSync } from 'fs';
4
4
  import process from 'process';
5
5
  import { Omnigraph } from '@modernrelay/omnigraph';
package/dist/index.d.ts CHANGED
@@ -353,6 +353,12 @@ interface OmnigraphDataRef {
353
353
  headAfter: string;
354
354
  /** Fingerprint of the `.pg` schema source (see `schemaFingerprint`). */
355
355
  schemaFingerprint: string;
356
+ /**
357
+ * Sorted node-type subset of a PARTIAL export; absent = full export.
358
+ * Part of the identity coordinate (review P1: two partial exports at the
359
+ * same head differing only by types must never replay as one another).
360
+ */
361
+ typeNames?: readonly string[];
356
362
  }
357
363
  interface OmnigraphLoadCounts {
358
364
  lines: number;
@@ -401,7 +407,8 @@ interface IngestTarget {
401
407
  * never introduce nodes or edges.
402
408
  *
403
409
  * Revision stamp (B.2): the canonical `sourceRevision` hashes
404
- * `{ graphId, branch, headBefore, headAfter, schemaFingerprint }`, but
410
+ * `{ graphId, branch, headBefore, headAfter, schemaFingerprint }` (plus the
411
+ * sorted `typeNames` subset when the export is partial — review P1), but
405
412
  * `headAfter` is only knowable after the stream — while core's
406
413
  * `BeginIngestOptions` requires `sourceRevision` up front for a replace
407
414
  * session. Resolution: under the rejecting/retrying policies the session
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { encodeSourceId, parsePgSchema, schemaFingerprint, bigIntKeyWarnings, classifyExportLine, normalizeNode, normalizeEdge } from './chunk-32TESFMK.js';
2
- export { InvalidExportLineError, ORBIT_TYPE_KEY, UnknownEdgeTypeError, bigIntKeyWarnings, classifyExportLine, decodeSourceId, edgeEndpointTypes, encodeSourceId, encodeSyntheticEdgeId, normalizeEdge, normalizeNode, parsePgSchema, schemaFingerprint } from './chunk-32TESFMK.js';
1
+ import { encodeSourceId, parsePgSchema, schemaFingerprint, bigIntKeyWarnings, classifyExportLine, normalizeNode, normalizeEdge } from './chunk-NT5KJVIT.js';
2
+ export { InvalidExportLineError, ORBIT_TYPE_KEY, UnknownEdgeTypeError, bigIntKeyWarnings, classifyExportLine, decodeSourceId, edgeEndpointTypes, encodeSourceId, encodeSyntheticEdgeId, normalizeEdge, normalizeNode, parsePgSchema, schemaFingerprint } from './chunk-NT5KJVIT.js';
3
3
  import { SERVER_VERSION, OmnigraphError } from '@modernrelay/omnigraph';
4
4
  import { OrbitOperationError } from '@modernrelay/orbit-core';
5
5
 
@@ -32,9 +32,15 @@ function hash64(s) {
32
32
  return h.toString(16).padStart(16, "0");
33
33
  }
34
34
  function canonicalSourceRevision(ref) {
35
- return `og:${hash64(
36
- JSON.stringify([ref.graphId, ref.branch, ref.headBefore, ref.headAfter, ref.schemaFingerprint])
37
- )}`;
35
+ const tuple = [
36
+ ref.graphId,
37
+ ref.branch,
38
+ ref.headBefore,
39
+ ref.headAfter,
40
+ ref.schemaFingerprint
41
+ ];
42
+ if (ref.typeNames !== void 0) tuple.push(ref.typeNames);
43
+ return `og:${hash64(JSON.stringify(tuple))}`;
38
44
  }
39
45
  function majorMinor(version) {
40
46
  const m = /^(\d+)\.(\d+)/.exec(version);
@@ -72,9 +78,9 @@ function createOmnigraphSource(options) {
72
78
  }
73
79
  const driftPolicy = options.driftPolicy ?? "reject";
74
80
  const onProgress = options.onProgress;
75
- const typeNames = options.typeNames === void 0 ? void 0 : [...options.typeNames];
81
+ const typeNames = options.typeNames === void 0 ? void 0 : [...options.typeNames].sort();
76
82
  const client = options.client.graph(graphId);
77
- const datasetKey = `og:${graphId}:${branch}`;
83
+ const datasetKey = typeNames === void 0 ? `og:${graphId}:${branch}` : `og:${graphId}:${branch}:types=${typeNames.join(",")}`;
78
84
  async function newestHead(signal) {
79
85
  const commits = await client.commits.list({ branch }, callOpts(signal));
80
86
  const newest = commits[0];
@@ -104,7 +110,8 @@ function createOmnigraphSource(options) {
104
110
  headBefore,
105
111
  headAfter: headBefore,
106
112
  // provisional: assume quiescence, verify after the stream
107
- schemaFingerprint: fingerprint
113
+ schemaFingerprint: fingerprint,
114
+ ...typeNames !== void 0 ? { typeNames } : {}
108
115
  };
109
116
  const provisionalRevision = canonicalSourceRevision(provisionalRef);
110
117
  function beginSession(sourceRevision) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/loader.ts","../src/searchService.ts"],"names":["activeSession","throwIfAborted","isAbortError","mapError","OmnigraphError"],"mappings":";;;;;AAqDA,IAAM,kBAAA,GAAqB,GAAA;AAW3B,IAAM,yBAAA,GAA4B,MAAM,IAAA,GAAO,IAAA;AAG/C,IAAM,YAAA,GAAe,IAAI,WAAA,EAAY;AAO9B,IAAM,mBAAA,GAAN,cAAkC,KAAA,CAAM;AAAA,EAC3B,IAAA,GAAO,qBAAA;AAAA,EAChB,OAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAgB,UAAA,EAAoB,SAAA,EAAmB;AAClF,IAAA,KAAA;AAAA,MACE,sB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S,MAAA,KAAW,MAAA,GAAY,OAAO,GAAG,CAAA,GAAI,cAAc,GAAG,CAAA;AACrE,QAAA,IAAI,MAAA,KAAW,IAAA,EAAM,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAA;AAAA,MAC1C;AACA,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * v1 export loader (spec Appendix B.2 / B.8 / B.10).\n *\n * The organizing rule (B.10): graphs load via `og.export()` — one streamed\n * NDJSON pass, edge lines first (lexicographic table-key order), driven\n * straight into a `purpose:'replace'` ingest session on the target. Queries\n * never introduce nodes or edges.\n *\n * Revision stamp (B.2): the canonical `sourceRevision` hashes\n * `{ graphId, branch, headBefore, headAfter, schemaFingerprint }`, but\n * `headAfter` is only knowable after the stream — while core's\n * `BeginIngestOptions` requires `sourceRevision` up front for a replace\n * session. Resolution: under the rejecting/retrying policies the session\n * begins under the PROVISIONAL revision (the canonical hash with\n * `headAfter := headBefore`), the stream appends into it, and `headAfter` is\n * captured BEFORE `commit()`. `accept-warn` is the exception: normalized\n * batches are buffered until `headAfter` is known, then appended once into a\n * session opened with the canonical FINAL revision:\n *\n * - equal heads → provisional === final; commit cleanly. The session only\n * ever commits a revision whose hash is truthful.\n * - drifted heads → `driftPolicy` decides: `'reject'` aborts the session\n * (graph untouched) and throws {@link OmnigraphDriftError};\n * `'accept-warn'` commits the buffered export under the\n * final revision, records BOTH heads in `dataRef`, and\n * adds a warning;\n * `'retry-once'` aborts and restarts the whole load once\n * (a second drift rejects).\n *\n * This is sound because a replace session is atomic and invisible until\n * commit (§7.5): nothing is published under a revision the policy did not\n * explicitly accept.\n *\n * Error surface (B.9): SDK typed errors never cross this package's public\n * surface — they are mapped to plain `Error`s with a stable `omnigraph:`\n * message prefix.\n */\n\nimport { OmnigraphError, SERVER_VERSION } from '@modernrelay/omnigraph';\nimport type { CallOptions, ExportInput, Omnigraph } from '@modernrelay/omnigraph';\nimport { OrbitOperationError } from '@modernrelay/orbit-core';\nimport type { GraphEdge, GraphNode, IngestBatch, IngestSession } from '@modernrelay/orbit-core';\n\nimport { classifyExportLine, normalizeEdge, normalizeNode } from './normalize';\nimport { bigIntKeyWarnings, parsePgSchema, schemaFingerprint } from './pgSchema';\nimport type { PgSchema } from './pgSchema';\nimport type {\n IngestTarget,\n OmnigraphDataRef,\n OmnigraphLoadResult,\n OmnigraphSourceOptions,\n} from './types';\n\nconst DEFAULT_BATCH_SIZE = 2000;\n\n/**\n * Finite whole-export cap for the necessarily atomic replace session. A\n * whole-graph load stages EVERY row before commit, so this is a total-load\n * memory bound, not a backpressure window — real graphs routinely exceed\n * 100 MB of serialized rows (the intel fixture streams ~128 MB), so the\n * default is deliberately generous; callers with tighter memory budgets pass\n * `maxPendingBytes` explicitly. PR #8's 64 MiB default regressed >64 MiB\n * loads that v0.6 handled.\n */\nconst DEFAULT_MAX_PENDING_BYTES = 512 * 1024 * 1024;\n\n/** Stateless and safe to reuse; counts serialized UTF-8 rather than UTF-16 code units. */\nconst UTF8_ENCODER = new TextEncoder();\n\n/**\n * B.2 drift under `driftPolicy: 'reject'` (or a second drift under\n * `'retry-once'`): the branch head moved while the export streamed, the\n * session was aborted, and the target graph is untouched.\n */\nexport class OmnigraphDriftError extends Error {\n override readonly name = 'OmnigraphDriftError';\n readonly graphId: string;\n readonly branch: string;\n readonly headBefore: string;\n readonly headAfter: string;\n constructor(graphId: string, branch: string, headBefore: string, headAfter: string) {\n super(\n `omnigraph: branch '${branch}' of graph '${graphId}' changed during export ` +\n `(head ${headBefore} → ${headAfter}); session aborted per driftPolicy (spec B.2: ` +\n `service:omnigraph-source-changed-during-export)`,\n );\n this.graphId = graphId;\n this.branch = branch;\n this.headBefore = headBefore;\n this.headAfter = headAfter;\n }\n}\n\n/** The one load path a v1 source exposes (B.10). */\nexport interface OmnigraphSource {\n /**\n * Stream one export of the configured graph/branch into `target` via a\n * `purpose:'replace'` ingest session. Resolves with the revision-stamped\n * result; rejects with the session aborted and the target untouched.\n * `signal` aborts both the HTTP stream and the session.\n */\n load(target: IngestTarget, signal?: AbortSignal): Promise<OmnigraphLoadResult>;\n}\n\n// ---------------------------------------------------------------------------\n// Small pure helpers\n// ---------------------------------------------------------------------------\n\n/** FNV-1a 64-bit over the UTF-8 bytes of `s`, as 16 lowercase hex chars. */\nfunction hash64(s: string): string {\n const MASK64 = 0xffffffffffffffffn;\n let h = 0xcbf29ce484222325n;\n for (const b of new TextEncoder().encode(s)) {\n h ^= BigInt(b);\n h = (h * 0x100000001b3n) & MASK64;\n }\n return h.toString(16).padStart(16, '0');\n}\n\n/**\n * The canonical B.2 source revision: a hash of the readable `dataRef` object\n * `{ graphId, branch, headBefore, headAfter, schemaFingerprint }` (`dataRef`\n * itself retains the readable form).\n */\nfunction canonicalSourceRevision(ref: OmnigraphDataRef): string {\n return `og:${hash64(\n JSON.stringify([ref.graphId, ref.branch, ref.headBefore, ref.headAfter, ref.schemaFingerprint]),\n )}`;\n}\n\n/** `'0.8.1'` → `'0.8'`; null when unparseable. */\nfunction majorMinor(version: string): string | null {\n const m = /^(\\d+)\\.(\\d+)/.exec(version);\n return m ? `${m[1]}.${m[2]}` : null;\n}\n\n/** CallOptions without an explicit-undefined signal (exactOptionalPropertyTypes). */\nfunction callOpts(signal: AbortSignal | undefined): CallOptions {\n return signal ? { signal } : {};\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) {\n throw new DOMException('omnigraph: load aborted by caller signal', 'AbortError');\n }\n}\n\nfunction isAbortError(err: unknown): boolean {\n return err instanceof Error && err.name === 'AbortError';\n}\n\n/**\n * B.9: SDK typed errors (NetworkError, ConflictError, …) never leak across\n * the public surface — rethrow as plain `Error` with a stable prefix.\n * Abort rejections and this package's own errors pass through unchanged.\n */\nfunction mapError(err: unknown): unknown {\n if (err instanceof OmnigraphError && !isAbortError(err)) {\n return new Error(`omnigraph: ${err.name} (status ${err.status}): ${err.message}`);\n }\n return err;\n}\n\nfunction pushUnique(warnings: string[], warning: string): void {\n if (!warnings.includes(warning)) warnings.push(warning);\n}\n\n// ---------------------------------------------------------------------------\n// createOmnigraphSource\n// ---------------------------------------------------------------------------\n\ninterface AttemptSuccess {\n kind: 'done';\n sourceRevision: string;\n dataRef: OmnigraphDataRef;\n counts: { lines: number; nodes: number; edges: number; bytes: number };\n}\n\ninterface AttemptRetry {\n kind: 'retry';\n}\n\n/**\n * Create a v1 export-backed data source (B.2/B.10). The client must be\n * preconfigured (B.1): in the browser a safe same-origin or public client —\n * there is deliberately no `baseUrl`/`token` option here. Authenticated\n * construction lives only in `@modernrelay/orbit-omnigraph/server`.\n */\nexport function createOmnigraphSource(options: OmnigraphSourceOptions): OmnigraphSource {\n const graphId = options.graphId;\n const branch = options.branch ?? 'main';\n const batchSize = Math.max(1, Math.floor(options.batchSize ?? DEFAULT_BATCH_SIZE));\n const maxPendingBytes = options.maxPendingBytes ?? DEFAULT_MAX_PENDING_BYTES;\n if (!Number.isSafeInteger(maxPendingBytes) || maxPendingBytes <= 0) {\n throw new TypeError(\n 'createOmnigraphSource: maxPendingBytes must be a positive safe integer',\n );\n }\n const driftPolicy = options.driftPolicy ?? 'reject';\n const onProgress = options.onProgress;\n const typeNames = options.typeNames === undefined ? undefined : [...options.typeNames];\n /** Every call is scoped to the graph (SDK cluster routing). */\n const client: Omnigraph = options.client.graph(graphId);\n const datasetKey = `og:${graphId}:${branch}`;\n\n async function newestHead(signal: AbortSignal | undefined): Promise<string> {\n const commits = await client.commits.list({ branch }, callOpts(signal));\n const newest = commits[0]; // SDK: most recent first\n if (newest === undefined) {\n throw new Error(\n `omnigraph: branch '${branch}' of graph '${graphId}' has no commits — nothing to export`,\n );\n }\n return newest.graphCommitId;\n }\n\n async function runAttempt(\n target: IngestTarget,\n signal: AbortSignal | undefined,\n warnings: string[],\n attempt: number,\n ): Promise<AttemptSuccess | AttemptRetry> {\n throwIfAborted(signal);\n // Pin the target's SOURCE lineage before any remote work: a competing\n // replace/snapshot landing mid-stream must fail the load. Overlay-only\n // model advances are benign for a replace commit (it supersedes overlays\n // anyway), so the CAS base itself is read fresh at each beginIngest —\n // pinning it here made long accept-warn streams fail late (and livelock)\n // under unrelated concurrent overlay traffic (PR #8 follow-up).\n const baseSource = target.getRevisions().source;\n\n // The before/after head bracket must enclose BOTH the schema read and the\n // export. Otherwise a schema migration between schema.get() and the first\n // head sample could look quiescent while we normalize with stale types.\n const headBefore = await newestHead(signal);\n\n // Endpoint-type resolution + wire-type normalization + the fingerprint\n // half of the revision stamp (B.2/B.3/B.6).\n const schemaSource = (await client.schema.get(callOpts(signal))).schemaSource;\n const schema: PgSchema = parsePgSchema(schemaSource);\n const fingerprint = schemaFingerprint(schemaSource);\n for (const hazard of bigIntKeyWarnings(schema)) {\n pushUnique(\n warnings,\n `omnigraph: ${hazard.type}.${hazard.property} is a 64-bit integer used as identity — ` +\n `JSON parsing silently rounds values past ±2^53, which can collapse distinct ids (B.6)`,\n );\n }\n // NOTE (B.6): a schema-declared `type` property needs no warning — the\n // adapter's discriminator lives at the namespaced ORBIT_TYPE_KEY, so the\n // source's own `type` loads as ordinary data with nothing to report.\n\n const provisionalRef: OmnigraphDataRef = {\n graphId,\n branch,\n headBefore,\n headAfter: headBefore, // provisional: assume quiescence, verify after the stream\n schemaFingerprint: fingerprint,\n };\n const provisionalRevision = canonicalSourceRevision(provisionalRef);\n\n function beginSession(sourceRevision: string): IngestSession {\n const now = target.getRevisions();\n if (now.source !== baseSource) {\n throw new Error(\n `omnigraph: the target's source lineage changed while the load was streaming ` +\n `(a competing replace or snapshot landed); aborting instead of overwriting it`,\n );\n }\n return target.beginIngest({\n purpose: 'replace',\n datasetKey,\n sourceRevision,\n baseModelRevision: now.model,\n maxPendingBytes,\n });\n }\n\n // `accept-warn` cannot open a truthful session until headAfter is known.\n // Buffer only that opt-in policy; rejecting/retrying loads keep streaming\n // directly into the atomic target under the provisional revision.\n let session: IngestSession | undefined =\n driftPolicy === 'accept-warn' ? undefined : beginSession(provisionalRevision);\n const requestId = hash64(`${datasetKey}|${provisionalRevision}|${attempt}`);\n\n interface BufferedBatch {\n nodes: GraphNode[];\n edges: GraphEdge[];\n bytes: number;\n progress: { lines: number; nodes: number; edges: number; bytes: number };\n }\n const bufferedBatches: Array<BufferedBatch | undefined> | undefined =\n driftPolicy === 'accept-warn' ? [] : undefined;\n\n let lines = 0;\n let nodeCount = 0;\n let edgeCount = 0;\n let bytes = 0;\n let unknown = 0;\n let sequence = 0;\n let pendingNodes: GraphNode[] = [];\n let pendingEdges: GraphEdge[] = [];\n let pendingBytes = 0;\n let acceptedBytes = 0;\n\n /**\n * Replace ingestion is atomic, so neither core staging nor accept-warn's\n * adapter buffer can drain before commit. Enforce the same finite\n * whole-load budget before retaining the next normalized row.\n */\n function accountAcceptedBytes(lineBytes: number): void {\n const next = acceptedBytes + lineBytes;\n if (next > maxPendingBytes) {\n throw new OrbitOperationError(\n { code: 'queue-overflow', queuedBytes: next, limit: maxPendingBytes },\n `omnigraph: export rows require at least ${next} bytes, exceeding ` +\n `maxPendingBytes ${maxPendingBytes}; load aborted before commit`,\n );\n }\n acceptedBytes = next;\n pendingBytes += lineBytes;\n }\n\n /** Await every append; retain bounded adapter-side pending batches (B.2). */\n async function flush(): Promise<void> {\n if (pendingNodes.length === 0 && pendingEdges.length === 0) return;\n const nodes = pendingNodes;\n const edges = pendingEdges;\n const batchBytes = pendingBytes;\n const progress = { lines, nodes: nodeCount, edges: edgeCount, bytes };\n pendingNodes = [];\n pendingEdges = [];\n pendingBytes = 0;\n\n if (bufferedBatches !== undefined) {\n bufferedBatches.push({ nodes, edges, bytes: batchBytes, progress });\n return;\n }\n\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n const batch: IngestBatch = {\n sequence,\n batchId: `og:${requestId}:${sequence}`,\n bytes: batchBytes,\n };\n if (edges.length > 0) batch.edges = edges;\n if (nodes.length > 0) batch.nodes = nodes;\n sequence += 1;\n await activeSession.append(batch);\n onProgress?.(progress);\n }\n\n /** Commit buffered accept-warn rows once, under the now-known final revision. */\n async function commitBuffered(sourceRevision: string): Promise<void> {\n if (bufferedBatches === undefined) {\n throw new Error('omnigraph: internal missing accept-warn batch buffer');\n }\n const finalSession = beginSession(sourceRevision);\n session = finalSession;\n const finalRequestId = hash64(`${datasetKey}|${sourceRevision}|${attempt}`);\n for (let i = 0; i < bufferedBatches.length; i++) {\n throwIfAborted(signal);\n const buffered = bufferedBatches[i];\n if (buffered === undefined) continue;\n // Release the buffer's array slot as soon as ownership passes to the\n // target session; the local `buffered` reference dies this iteration.\n bufferedBatches[i] = undefined;\n const batch: IngestBatch = {\n sequence: i,\n batchId: `og:${finalRequestId}:${i}`,\n bytes: buffered.bytes,\n };\n if (buffered.edges.length > 0) batch.edges = buffered.edges;\n if (buffered.nodes.length > 0) batch.nodes = buffered.nodes;\n await finalSession.append(batch);\n onProgress?.(buffered.progress);\n }\n bufferedBatches.length = 0;\n await finalSession.commit();\n }\n\n // Bind the iterator ONCE (B.2: each iteration re-issues the request) and\n // make sure early exits cancel the underlying stream via `return()`.\n const exportInput: ExportInput = { branch, ...(typeNames !== undefined ? { typeNames } : {}) };\n const iterator = client\n .export<Record<string, unknown>>(exportInput, callOpts(signal))\n [Symbol.asyncIterator]();\n\n try {\n for (;;) {\n throwIfAborted(signal);\n const step = await iterator.next();\n if (step.done === true) break;\n const line = step.value;\n lines += 1;\n // The SDK exposes parsed rows rather than raw chunks. Re-serialize to\n // UTF-8 and include one NDJSON newline: a conservative, consistent\n // accounting unit for progress, batches, and the whole-load cap.\n const lineBytes = UTF8_ENCODER.encode(JSON.stringify(line)).byteLength + 1;\n bytes += lineBytes;\n const classified = classifyExportLine(line);\n if (classified.kind === 'node') {\n const node = normalizeNode(classified, schema);\n accountAcceptedBytes(lineBytes);\n pendingNodes.push(node);\n nodeCount += 1;\n } else if (classified.kind === 'edge') {\n const edge = normalizeEdge(classified, schema);\n accountAcceptedBytes(lineBytes);\n pendingEdges.push(edge);\n edgeCount += 1;\n } else {\n unknown += 1;\n }\n if (pendingNodes.length + pendingEdges.length >= batchSize) await flush();\n }\n await flush();\n\n if (unknown > 0) {\n pushUnique(warnings, `omnigraph: skipped ${unknown} unrecognized export line(s) (B.2)`);\n }\n\n // Revision stamp, second half: the head AFTER the stream, captured\n // BEFORE commit (B.2).\n throwIfAborted(signal);\n const headAfter = await newestHead(signal);\n const counts = { lines, nodes: nodeCount, edges: edgeCount, bytes };\n\n if (driftPolicy === 'accept-warn') {\n const finalRef: OmnigraphDataRef = { ...provisionalRef, headAfter };\n const finalRevision = canonicalSourceRevision(finalRef);\n if (headAfter !== headBefore) {\n pushUnique(\n warnings,\n `omnigraph: branch '${branch}' advanced during export (head ${headBefore} → ` +\n `${headAfter}); committed under the canonical final revision per ` +\n `driftPolicy:'accept-warn' — dataRef records both heads (B.2)`,\n );\n }\n await commitBuffered(finalRevision);\n return { kind: 'done', sourceRevision: finalRevision, dataRef: finalRef, counts };\n }\n\n if (headAfter === headBefore) {\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n await activeSession.commit();\n return { kind: 'done', sourceRevision: provisionalRevision, dataRef: provisionalRef, counts };\n }\n\n // Drift (B.2: service:omnigraph-source-changed-during-export).\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n await activeSession.abort('omnigraph: source changed during export (B.2)');\n if (driftPolicy === 'retry-once' && attempt === 1) {\n pushUnique(\n warnings,\n `omnigraph: branch '${branch}' advanced during export (head ${headBefore} → ` +\n `${headAfter}); load restarted once per driftPolicy:'retry-once' (B.2)`,\n );\n return { kind: 'retry' };\n }\n throw new OmnigraphDriftError(graphId, branch, headBefore, headAfter);\n } catch (err) {\n if (session?.state === 'open') {\n try {\n await session.abort(err);\n } catch {\n // the original failure wins\n }\n }\n throw mapError(err);\n } finally {\n // Cancel the underlying NDJSON stream on any non-exhausted exit.\n try {\n await iterator.return?.();\n } catch {\n // stream teardown must never mask the outcome\n }\n }\n }\n\n async function load(target: IngestTarget, signal?: AbortSignal): Promise<OmnigraphLoadResult> {\n const warnings: string[] = [];\n\n // B.1: surface an SDK/server major.minor mismatch — a warning, never a\n // hard failure.\n let serverVersion: string;\n try {\n serverVersion = (await client.health(callOpts(signal))).version;\n } catch (err) {\n throw mapError(err);\n }\n const server = majorMinor(serverVersion);\n const sdk = majorMinor(SERVER_VERSION);\n if (server === null || server !== sdk) {\n warnings.push(\n `omnigraph: server version ${serverVersion} does not match the SDK-pinned server ` +\n `version ${SERVER_VERSION} (major.minor differ) — SDK behavior is undefined ` +\n `against this server (B.1)`,\n );\n }\n\n for (let attempt = 1; ; attempt += 1) {\n let outcome: AttemptSuccess | AttemptRetry;\n try {\n outcome = await runAttempt(target, signal, warnings, attempt);\n } catch (err) {\n // Covers SDK errors thrown before the session/stream phase\n // (schema.get, commits.list); mapError is a no-op on already-mapped\n // or package-owned errors (B.9).\n throw mapError(err);\n }\n if (outcome.kind === 'retry') continue;\n return {\n sourceRevision: outcome.sourceRevision,\n dataRef: outcome.dataRef,\n counts: outcome.counts,\n serverVersion,\n warnings,\n };\n }\n }\n\n return { load };\n}\n","/**\n * B.7 stored-query `SearchService` (§16.5).\n *\n * A stored query using `bm25`/`fuzzy`/`nearest`/`rrf` with\n * `order { score desc } limit K` returns entity rows plus a score column; this\n * module wires it as a §16.5 `SearchService` via\n * `og.queries.invoke(name, { params, branch })`, passing\n * `RequestContext.signal` through SDK `CallOptions`. Core performs revision\n * admission — the service only declares `revisionDependencies: ['source']`\n * (results come from the server-side branch, so they are invalidated by a\n * source change, never by client-side model/scope drift).\n *\n * Identity (B.3): Omnigraph ids are unique per type only, and a query row\n * carries no type discriminator of its own — so the adapter REQUIRES a\n * caller-supplied column→node-type mapping (`typeOf`), either a\n * `{ column: NodeType }` record keyed by the projection columns that hold\n * bare-variable node structs, or a per-row function. Every returned id is\n * qualified through `encodeSourceId(nodeType, physicalId)` — the same codec\n * every other adapter path uses — so results round-trip `decodeSourceId` and\n * match export-loaded node ids exactly.\n *\n * v1 caveat (B.7): search runs server-side over the WHOLE branch, so against\n * a partial export load it can return ids outside the loaded set. §16.5\n * classifies those as `'not-loaded'` at activation; constrain the stored\n * query to the loaded types, or load the full graph, to avoid the mismatch.\n *\n * Error surface (B.9): SDK typed errors never cross this package's public\n * surface — they rethrow as plain `Error`s with the stable `omnigraph:`\n * prefix. Abort rejections pass through unchanged.\n */\n\nimport { OmnigraphError } from '@modernrelay/omnigraph';\nimport type { InvokeQueryInput, Omnigraph } from '@modernrelay/omnigraph';\nimport type { RequestContext, SearchResult, SearchService } from '@modernrelay/orbit-core';\n\nimport { encodeSourceId } from './idCodec';\n\n/** One stored-query result row: projection column → value. Bare-variable\n * projections (`return { $s }`) hold whole-node structs including `id`. */\nexport type OmnigraphSearchRow = Record<string, unknown>;\n\n/**\n * The required B.3 column→node-type mapping:\n *\n * - a record `{ '$s': 'Signal' }` — the FIRST listed column present in a row\n * with a node struct supplies the physical id, encoded under the mapped\n * type name;\n * - or a per-row function returning the node type name — the row's first\n * node-struct column (row key order) supplies the physical id.\n */\nexport type OmnigraphSearchTypeOf =\n | ((row: OmnigraphSearchRow) => string)\n | Readonly<Record<string, string>>;\n\nexport interface OmnigraphSearchServiceOptions<N = Record<string, unknown>> {\n /** A **preconfigured** SDK client (B.1) — no `baseUrl`/`token` here. */\n client: Omnigraph;\n /** Cluster graph id; the invoke is scoped via `client.graph(graphId)`. */\n graphId: string;\n /** Branch the stored query reads (B.7). Default `'main'`. */\n branch?: string;\n /** Registry name of the stored search query (`POST /queries/{name}`).\n * Invoking a known name works whether or not it is `mcp.expose`d. */\n queryName: string;\n /** Builds the stored query's `params` object from the §16.5 call.\n * Default: `(q, limit) => ({ q, limit })`. */\n params?: (q: string, limit: number) => Record<string, unknown>;\n /** REQUIRED B.3 mapping from row to node type — see\n * {@link OmnigraphSearchTypeOf}. */\n typeOf: OmnigraphSearchTypeOf;\n /** Column whose value becomes `label` (String()-coerced when present).\n * Default: the first string-valued column in row key order. */\n labelColumn?: string;\n /** Full custom row→result escape hatch: overrides the default mapping\n * (including `typeOf`/`labelColumn`); return `null` to skip a row. The\n * returned `id` MUST already be B.3-encoded via `encodeSourceId`. */\n mapRow?: (row: OmnigraphSearchRow) => SearchResult<N> | null;\n}\n\n// ---------------------------------------------------------------------------\n// Small pure helpers\n// ---------------------------------------------------------------------------\n\nfunction defaultParams(q: string, limit: number): Record<string, unknown> {\n return { q, limit };\n}\n\nfunction throwIfAborted(signal: AbortSignal, queryName: string): void {\n if (signal.aborted) {\n throw new DOMException(\n `omnigraph: search query '${queryName}' aborted by request signal`,\n 'AbortError',\n );\n }\n}\n\nfunction isAbortError(err: unknown): boolean {\n return err instanceof Error && err.name === 'AbortError';\n}\n\n/** B.9: SDK typed errors rethrow as plain prefixed `Error`s; abort rejections\n * and everything else pass through unchanged. */\nfunction mapError(err: unknown): unknown {\n if (err instanceof OmnigraphError && !isAbortError(err)) {\n return new Error(`omnigraph: ${err.name} (status ${err.status}): ${err.message}`);\n }\n return err;\n}\n\n/** A bare-variable projection value: a whole-node struct carrying its\n * physical id (B.5 note — `return { $s }` yields `{ id, ...props }`). */\nfunction isNodeStruct(value: unknown): value is { id: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n typeof (value as { id?: unknown }).id === 'string'\n );\n}\n\n/** The invoke response must be a READ envelope with tabular rows — a stored\n * mutation (Change envelope) or malformed body is a hard error. */\nfunction extractRows(response: unknown, queryName: string): readonly OmnigraphSearchRow[] {\n const rows = (response as { rows?: unknown }).rows;\n if (!Array.isArray(rows)) {\n throw new Error(\n `omnigraph: stored query '${queryName}' did not return a read envelope with rows — ` +\n `the B.7 search query must be a stored READ query (not a mutation)`,\n );\n }\n for (const row of rows) {\n if (typeof row !== 'object' || row === null || Array.isArray(row)) {\n throw new Error(\n `omnigraph: stored query '${queryName}' returned a non-object row — ` +\n `expected column→value row objects`,\n );\n }\n }\n return rows as OmnigraphSearchRow[];\n}\n\ninterface ResolvedIdentity {\n kind: string;\n sourceId: string;\n}\n\n/** Resolve the B.3 `(nodeType, physicalId)` pair for one row via `typeOf`. */\nfunction resolveIdentity(\n row: OmnigraphSearchRow,\n typeOf: OmnigraphSearchTypeOf,\n queryName: string,\n): ResolvedIdentity {\n if (typeof typeOf === 'function') {\n const kind = typeOf(row);\n if (typeof kind !== 'string' || kind.length === 0) {\n throw new Error(\n `omnigraph: typeOf returned ${JSON.stringify(kind)} for a '${queryName}' search row — ` +\n `it must return a non-empty node type name (B.3)`,\n );\n }\n for (const key of Object.keys(row)) {\n const value = row[key];\n if (isNodeStruct(value)) return { kind, sourceId: value.id };\n }\n throw new Error(\n `omnigraph: '${queryName}' search row has no node-struct column (an object with a ` +\n `string 'id') — project the matched entity bare (return { $s }) so its physical ` +\n `id is available (B.7)`,\n );\n }\n for (const [column, kind] of Object.entries(typeOf)) {\n const value = row[column];\n if (isNodeStruct(value)) return { kind, sourceId: value.id };\n }\n throw new Error(\n `omnigraph: '${queryName}' search row has no node struct under the mapped column(s) ` +\n `${JSON.stringify(Object.keys(typeOf))} — the typeOf record must key the ` +\n `bare-variable projection column(s) (B.3)`,\n );\n}\n\n// ---------------------------------------------------------------------------\n// createOmnigraphSearchService\n// ---------------------------------------------------------------------------\n\n/**\n * Create the B.7 stored-query search service. Plug it into core as\n * `services.search`; the instance owns `RequestContext` creation,\n * revision-keyed caching, supersede cancellation, and stale-result rejection\n * at admission (§16.5).\n */\nexport function createOmnigraphSearchService<N = Record<string, unknown>>(\n options: OmnigraphSearchServiceOptions<N>,\n): SearchService<N> {\n const { graphId, queryName, typeOf, labelColumn, mapRow } = options;\n const branch = options.branch ?? 'main';\n const buildParams = options.params ?? defaultParams;\n /** Every call is scoped to the graph (SDK cluster routing). */\n const client: Omnigraph = options.client.graph(graphId);\n\n function mapRowDefault(row: OmnigraphSearchRow): SearchResult<N> {\n const { kind, sourceId } = resolveIdentity(row, typeOf, queryName);\n const result: SearchResult<N> = { id: encodeSourceId(kind, sourceId) };\n\n const score = row['score'];\n if (typeof score === 'number' && Number.isFinite(score)) result.score = score;\n\n if (labelColumn !== undefined) {\n const value = row[labelColumn];\n if (typeof value === 'string' || typeof value === 'number') result.label = String(value);\n } else {\n for (const key of Object.keys(row)) {\n if (key === 'score') continue; // the score lane never doubles as a label\n const value = row[key];\n if (typeof value === 'string') {\n result.label = value;\n break;\n }\n }\n }\n return result;\n }\n\n return {\n revisionDependencies: ['source'],\n async search(\n q: string,\n searchOptions: { limit: number },\n ctx: RequestContext,\n ): Promise<readonly SearchResult<N>[]> {\n throwIfAborted(ctx.signal, queryName);\n const limit = Number.isFinite(searchOptions.limit) ? Math.floor(searchOptions.limit) : 0;\n if (q.length === 0 || limit <= 0) return [];\n\n const input: InvokeQueryInput = { branch, params: buildParams(q, limit) };\n let response: unknown;\n try {\n response = await client.queries.invoke(queryName, input, { signal: ctx.signal });\n } catch (err) {\n throw mapError(err);\n }\n throwIfAborted(ctx.signal, queryName);\n\n const rows = extractRows(response, queryName);\n const results: SearchResult<N>[] = [];\n for (const row of rows) {\n if (results.length >= limit) break; // defensive cap — the query owns K\n const mapped = mapRow !== undefined ? mapRow(row) : mapRowDefault(row);\n if (mapped !== null) results.push(mapped);\n }\n return results;\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/loader.ts","../src/searchService.ts"],"names":["activeSession","throwIfAborted","isAbortError","mapError","OmnigraphError"],"mappings":";;;;;AAsDA,IAAM,kBAAA,GAAqB,GAAA;AAW3B,IAAM,yBAAA,GAA4B,MAAM,IAAA,GAAO,IAAA;AAG/C,IAAM,YAAA,GAAe,IAAI,WAAA,EAAY;AAO9B,IAAM,mBAAA,GAAN,cAAkC,KAAA,CAAM;AAAA,EAC3B,IAAA,GAAO,qBAAA;AAAA,EAChB,OAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAgB,UAAA,EAAoB,SAAA,EAAmB;AAClF,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AAI,MAAA,EAAQ,CAAA;AAAA,MACjF,SAAS,GAAA,EAAK;AACZ,QAAA,MAAME,UAAS,GAAG,CAAA;AAAA,MACpB;AACA,MAAAF,eAAAA,CAAe,GAAA,CAAI,MAAA,EAAQ,SAAS,CAAA;AAEpC,MAAA,MAAM,IAAA,GAAO,WAAA,CAAY,QAAA,EAAU,SAAS,CAAA;AAC5C,MAAA,MAAM,UAA6B,EAAC;AACpC,MAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,QAAA,IAAI,OAAA,CAAQ,UAAU,KAAA,EAAO;AAC7B,QAAA,MAAM,SAAS,MAAA,KAAW,MAAA,GAAY,OAAO,GAAG,CAAA,GAAI,cAAc,GAAG,CAAA;AACrE,QAAA,IAAI,MAAA,KAAW,IAAA,EAAM,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAA;AAAA,MAC1C;AACA,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * v1 export loader (spec Appendix B.2 / B.8 / B.10).\n *\n * The organizing rule (B.10): graphs load via `og.export()` — one streamed\n * NDJSON pass, edge lines first (lexicographic table-key order), driven\n * straight into a `purpose:'replace'` ingest session on the target. Queries\n * never introduce nodes or edges.\n *\n * Revision stamp (B.2): the canonical `sourceRevision` hashes\n * `{ graphId, branch, headBefore, headAfter, schemaFingerprint }` (plus the\n * sorted `typeNames` subset when the export is partial — review P1), but\n * `headAfter` is only knowable after the stream — while core's\n * `BeginIngestOptions` requires `sourceRevision` up front for a replace\n * session. Resolution: under the rejecting/retrying policies the session\n * begins under the PROVISIONAL revision (the canonical hash with\n * `headAfter := headBefore`), the stream appends into it, and `headAfter` is\n * captured BEFORE `commit()`. `accept-warn` is the exception: normalized\n * batches are buffered until `headAfter` is known, then appended once into a\n * session opened with the canonical FINAL revision:\n *\n * - equal heads → provisional === final; commit cleanly. The session only\n * ever commits a revision whose hash is truthful.\n * - drifted heads → `driftPolicy` decides: `'reject'` aborts the session\n * (graph untouched) and throws {@link OmnigraphDriftError};\n * `'accept-warn'` commits the buffered export under the\n * final revision, records BOTH heads in `dataRef`, and\n * adds a warning;\n * `'retry-once'` aborts and restarts the whole load once\n * (a second drift rejects).\n *\n * This is sound because a replace session is atomic and invisible until\n * commit (§7.5): nothing is published under a revision the policy did not\n * explicitly accept.\n *\n * Error surface (B.9): SDK typed errors never cross this package's public\n * surface — they are mapped to plain `Error`s with a stable `omnigraph:`\n * message prefix.\n */\n\nimport { OmnigraphError, SERVER_VERSION } from '@modernrelay/omnigraph';\nimport type { CallOptions, ExportInput, Omnigraph } from '@modernrelay/omnigraph';\nimport { OrbitOperationError } from '@modernrelay/orbit-core';\nimport type { GraphEdge, GraphNode, IngestBatch, IngestSession } from '@modernrelay/orbit-core';\n\nimport { classifyExportLine, normalizeEdge, normalizeNode } from './normalize';\nimport { bigIntKeyWarnings, parsePgSchema, schemaFingerprint } from './pgSchema';\nimport type { PgSchema } from './pgSchema';\nimport type {\n IngestTarget,\n OmnigraphDataRef,\n OmnigraphLoadResult,\n OmnigraphSourceOptions,\n} from './types';\n\nconst DEFAULT_BATCH_SIZE = 2000;\n\n/**\n * Finite whole-export cap for the necessarily atomic replace session. A\n * whole-graph load stages EVERY row before commit, so this is a total-load\n * memory bound, not a backpressure window — real graphs routinely exceed\n * 100 MB of serialized rows (the intel fixture streams ~128 MB), so the\n * default is deliberately generous; callers with tighter memory budgets pass\n * `maxPendingBytes` explicitly. PR #8's 64 MiB default regressed >64 MiB\n * loads that v0.6 handled.\n */\nconst DEFAULT_MAX_PENDING_BYTES = 512 * 1024 * 1024;\n\n/** Stateless and safe to reuse; counts serialized UTF-8 rather than UTF-16 code units. */\nconst UTF8_ENCODER = new TextEncoder();\n\n/**\n * B.2 drift under `driftPolicy: 'reject'` (or a second drift under\n * `'retry-once'`): the branch head moved while the export streamed, the\n * session was aborted, and the target graph is untouched.\n */\nexport class OmnigraphDriftError extends Error {\n override readonly name = 'OmnigraphDriftError';\n readonly graphId: string;\n readonly branch: string;\n readonly headBefore: string;\n readonly headAfter: string;\n constructor(graphId: string, branch: string, headBefore: string, headAfter: string) {\n super(\n `omnigraph: branch '${branch}' of graph '${graphId}' changed during export ` +\n `(head ${headBefore} → ${headAfter}); session aborted per driftPolicy (spec B.2: ` +\n `service:omnigraph-source-changed-during-export)`,\n );\n this.graphId = graphId;\n this.branch = branch;\n this.headBefore = headBefore;\n this.headAfter = headAfter;\n }\n}\n\n/** The one load path a v1 source exposes (B.10). */\nexport interface OmnigraphSource {\n /**\n * Stream one export of the configured graph/branch into `target` via a\n * `purpose:'replace'` ingest session. Resolves with the revision-stamped\n * result; rejects with the session aborted and the target untouched.\n * `signal` aborts both the HTTP stream and the session.\n */\n load(target: IngestTarget, signal?: AbortSignal): Promise<OmnigraphLoadResult>;\n}\n\n// ---------------------------------------------------------------------------\n// Small pure helpers\n// ---------------------------------------------------------------------------\n\n/** FNV-1a 64-bit over the UTF-8 bytes of `s`, as 16 lowercase hex chars. */\nfunction hash64(s: string): string {\n const MASK64 = 0xffffffffffffffffn;\n let h = 0xcbf29ce484222325n;\n for (const b of new TextEncoder().encode(s)) {\n h ^= BigInt(b);\n h = (h * 0x100000001b3n) & MASK64;\n }\n return h.toString(16).padStart(16, '0');\n}\n\n/**\n * The canonical B.2 source revision: a hash of the readable `dataRef` object\n * `{ graphId, branch, headBefore, headAfter, schemaFingerprint, typeNames? }`\n * (`dataRef` itself retains the readable form).\n */\nfunction canonicalSourceRevision(ref: OmnigraphDataRef): string {\n // typeNames joins the tuple ONLY when present (review P1) — full-export\n // hashes stay byte-identical to every previously persisted revision.\n const tuple: unknown[] = [\n ref.graphId,\n ref.branch,\n ref.headBefore,\n ref.headAfter,\n ref.schemaFingerprint,\n ];\n if (ref.typeNames !== undefined) tuple.push(ref.typeNames);\n return `og:${hash64(JSON.stringify(tuple))}`;\n}\n\n/** `'0.8.1'` → `'0.8'`; null when unparseable. */\nfunction majorMinor(version: string): string | null {\n const m = /^(\\d+)\\.(\\d+)/.exec(version);\n return m ? `${m[1]}.${m[2]}` : null;\n}\n\n/** CallOptions without an explicit-undefined signal (exactOptionalPropertyTypes). */\nfunction callOpts(signal: AbortSignal | undefined): CallOptions {\n return signal ? { signal } : {};\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) {\n throw new DOMException('omnigraph: load aborted by caller signal', 'AbortError');\n }\n}\n\nfunction isAbortError(err: unknown): boolean {\n return err instanceof Error && err.name === 'AbortError';\n}\n\n/**\n * B.9: SDK typed errors (NetworkError, ConflictError, …) never leak across\n * the public surface — rethrow as plain `Error` with a stable prefix.\n * Abort rejections and this package's own errors pass through unchanged.\n */\nfunction mapError(err: unknown): unknown {\n if (err instanceof OmnigraphError && !isAbortError(err)) {\n return new Error(`omnigraph: ${err.name} (status ${err.status}): ${err.message}`);\n }\n return err;\n}\n\nfunction pushUnique(warnings: string[], warning: string): void {\n if (!warnings.includes(warning)) warnings.push(warning);\n}\n\n// ---------------------------------------------------------------------------\n// createOmnigraphSource\n// ---------------------------------------------------------------------------\n\ninterface AttemptSuccess {\n kind: 'done';\n sourceRevision: string;\n dataRef: OmnigraphDataRef;\n counts: { lines: number; nodes: number; edges: number; bytes: number };\n}\n\ninterface AttemptRetry {\n kind: 'retry';\n}\n\n/**\n * Create a v1 export-backed data source (B.2/B.10). The client must be\n * preconfigured (B.1): in the browser a safe same-origin or public client —\n * there is deliberately no `baseUrl`/`token` option here. Authenticated\n * construction lives only in `@modernrelay/orbit-omnigraph/server`.\n */\nexport function createOmnigraphSource(options: OmnigraphSourceOptions): OmnigraphSource {\n const graphId = options.graphId;\n const branch = options.branch ?? 'main';\n const batchSize = Math.max(1, Math.floor(options.batchSize ?? DEFAULT_BATCH_SIZE));\n const maxPendingBytes = options.maxPendingBytes ?? DEFAULT_MAX_PENDING_BYTES;\n if (!Number.isSafeInteger(maxPendingBytes) || maxPendingBytes <= 0) {\n throw new TypeError(\n 'createOmnigraphSource: maxPendingBytes must be a positive safe integer',\n );\n }\n const driftPolicy = options.driftPolicy ?? 'reject';\n const onProgress = options.onProgress;\n // Sorted canonical form: ['B','A'] and ['A','B'] are the SAME subset and\n // must produce the same identity coordinate (review P1).\n const typeNames =\n options.typeNames === undefined ? undefined : [...options.typeNames].sort();\n /** Every call is scoped to the graph (SDK cluster routing). */\n const client: Omnigraph = options.client.graph(graphId);\n // A partial export is a DIFFERENT dataset lifetime than the full graph —\n // positions/selection/history must not carry across subsets (review P1).\n const datasetKey =\n typeNames === undefined\n ? `og:${graphId}:${branch}`\n : `og:${graphId}:${branch}:types=${typeNames.join(',')}`;\n\n async function newestHead(signal: AbortSignal | undefined): Promise<string> {\n const commits = await client.commits.list({ branch }, callOpts(signal));\n const newest = commits[0]; // SDK: most recent first\n if (newest === undefined) {\n throw new Error(\n `omnigraph: branch '${branch}' of graph '${graphId}' has no commits — nothing to export`,\n );\n }\n return newest.graphCommitId;\n }\n\n async function runAttempt(\n target: IngestTarget,\n signal: AbortSignal | undefined,\n warnings: string[],\n attempt: number,\n ): Promise<AttemptSuccess | AttemptRetry> {\n throwIfAborted(signal);\n // Pin the target's SOURCE lineage before any remote work: a competing\n // replace/snapshot landing mid-stream must fail the load. Overlay-only\n // model advances are benign for a replace commit (it supersedes overlays\n // anyway), so the CAS base itself is read fresh at each beginIngest —\n // pinning it here made long accept-warn streams fail late (and livelock)\n // under unrelated concurrent overlay traffic (PR #8 follow-up).\n const baseSource = target.getRevisions().source;\n\n // The before/after head bracket must enclose BOTH the schema read and the\n // export. Otherwise a schema migration between schema.get() and the first\n // head sample could look quiescent while we normalize with stale types.\n const headBefore = await newestHead(signal);\n\n // Endpoint-type resolution + wire-type normalization + the fingerprint\n // half of the revision stamp (B.2/B.3/B.6).\n const schemaSource = (await client.schema.get(callOpts(signal))).schemaSource;\n const schema: PgSchema = parsePgSchema(schemaSource);\n const fingerprint = schemaFingerprint(schemaSource);\n for (const hazard of bigIntKeyWarnings(schema)) {\n pushUnique(\n warnings,\n `omnigraph: ${hazard.type}.${hazard.property} is a 64-bit integer used as identity — ` +\n `JSON parsing silently rounds values past ±2^53, which can collapse distinct ids (B.6)`,\n );\n }\n // NOTE (B.6): a schema-declared `type` property needs no warning — the\n // adapter's discriminator lives at the namespaced ORBIT_TYPE_KEY, so the\n // source's own `type` loads as ordinary data with nothing to report.\n\n const provisionalRef: OmnigraphDataRef = {\n graphId,\n branch,\n headBefore,\n headAfter: headBefore, // provisional: assume quiescence, verify after the stream\n schemaFingerprint: fingerprint,\n ...(typeNames !== undefined ? { typeNames } : {}),\n };\n const provisionalRevision = canonicalSourceRevision(provisionalRef);\n\n function beginSession(sourceRevision: string): IngestSession {\n const now = target.getRevisions();\n if (now.source !== baseSource) {\n throw new Error(\n `omnigraph: the target's source lineage changed while the load was streaming ` +\n `(a competing replace or snapshot landed); aborting instead of overwriting it`,\n );\n }\n return target.beginIngest({\n purpose: 'replace',\n datasetKey,\n sourceRevision,\n baseModelRevision: now.model,\n maxPendingBytes,\n });\n }\n\n // `accept-warn` cannot open a truthful session until headAfter is known.\n // Buffer only that opt-in policy; rejecting/retrying loads keep streaming\n // directly into the atomic target under the provisional revision.\n let session: IngestSession | undefined =\n driftPolicy === 'accept-warn' ? undefined : beginSession(provisionalRevision);\n const requestId = hash64(`${datasetKey}|${provisionalRevision}|${attempt}`);\n\n interface BufferedBatch {\n nodes: GraphNode[];\n edges: GraphEdge[];\n bytes: number;\n progress: { lines: number; nodes: number; edges: number; bytes: number };\n }\n const bufferedBatches: Array<BufferedBatch | undefined> | undefined =\n driftPolicy === 'accept-warn' ? [] : undefined;\n\n let lines = 0;\n let nodeCount = 0;\n let edgeCount = 0;\n let bytes = 0;\n let unknown = 0;\n let sequence = 0;\n let pendingNodes: GraphNode[] = [];\n let pendingEdges: GraphEdge[] = [];\n let pendingBytes = 0;\n let acceptedBytes = 0;\n\n /**\n * Replace ingestion is atomic, so neither core staging nor accept-warn's\n * adapter buffer can drain before commit. Enforce the same finite\n * whole-load budget before retaining the next normalized row.\n */\n function accountAcceptedBytes(lineBytes: number): void {\n const next = acceptedBytes + lineBytes;\n if (next > maxPendingBytes) {\n throw new OrbitOperationError(\n { code: 'queue-overflow', queuedBytes: next, limit: maxPendingBytes },\n `omnigraph: export rows require at least ${next} bytes, exceeding ` +\n `maxPendingBytes ${maxPendingBytes}; load aborted before commit`,\n );\n }\n acceptedBytes = next;\n pendingBytes += lineBytes;\n }\n\n /** Await every append; retain bounded adapter-side pending batches (B.2). */\n async function flush(): Promise<void> {\n if (pendingNodes.length === 0 && pendingEdges.length === 0) return;\n const nodes = pendingNodes;\n const edges = pendingEdges;\n const batchBytes = pendingBytes;\n const progress = { lines, nodes: nodeCount, edges: edgeCount, bytes };\n pendingNodes = [];\n pendingEdges = [];\n pendingBytes = 0;\n\n if (bufferedBatches !== undefined) {\n bufferedBatches.push({ nodes, edges, bytes: batchBytes, progress });\n return;\n }\n\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n const batch: IngestBatch = {\n sequence,\n batchId: `og:${requestId}:${sequence}`,\n bytes: batchBytes,\n };\n if (edges.length > 0) batch.edges = edges;\n if (nodes.length > 0) batch.nodes = nodes;\n sequence += 1;\n await activeSession.append(batch);\n onProgress?.(progress);\n }\n\n /** Commit buffered accept-warn rows once, under the now-known final revision. */\n async function commitBuffered(sourceRevision: string): Promise<void> {\n if (bufferedBatches === undefined) {\n throw new Error('omnigraph: internal missing accept-warn batch buffer');\n }\n const finalSession = beginSession(sourceRevision);\n session = finalSession;\n const finalRequestId = hash64(`${datasetKey}|${sourceRevision}|${attempt}`);\n for (let i = 0; i < bufferedBatches.length; i++) {\n throwIfAborted(signal);\n const buffered = bufferedBatches[i];\n if (buffered === undefined) continue;\n // Release the buffer's array slot as soon as ownership passes to the\n // target session; the local `buffered` reference dies this iteration.\n bufferedBatches[i] = undefined;\n const batch: IngestBatch = {\n sequence: i,\n batchId: `og:${finalRequestId}:${i}`,\n bytes: buffered.bytes,\n };\n if (buffered.edges.length > 0) batch.edges = buffered.edges;\n if (buffered.nodes.length > 0) batch.nodes = buffered.nodes;\n await finalSession.append(batch);\n onProgress?.(buffered.progress);\n }\n bufferedBatches.length = 0;\n await finalSession.commit();\n }\n\n // Bind the iterator ONCE (B.2: each iteration re-issues the request) and\n // make sure early exits cancel the underlying stream via `return()`.\n const exportInput: ExportInput = { branch, ...(typeNames !== undefined ? { typeNames } : {}) };\n const iterator = client\n .export<Record<string, unknown>>(exportInput, callOpts(signal))\n [Symbol.asyncIterator]();\n\n try {\n for (;;) {\n throwIfAborted(signal);\n const step = await iterator.next();\n if (step.done === true) break;\n const line = step.value;\n lines += 1;\n // The SDK exposes parsed rows rather than raw chunks. Re-serialize to\n // UTF-8 and include one NDJSON newline: a conservative, consistent\n // accounting unit for progress, batches, and the whole-load cap.\n const lineBytes = UTF8_ENCODER.encode(JSON.stringify(line)).byteLength + 1;\n bytes += lineBytes;\n const classified = classifyExportLine(line);\n if (classified.kind === 'node') {\n const node = normalizeNode(classified, schema);\n accountAcceptedBytes(lineBytes);\n pendingNodes.push(node);\n nodeCount += 1;\n } else if (classified.kind === 'edge') {\n const edge = normalizeEdge(classified, schema);\n accountAcceptedBytes(lineBytes);\n pendingEdges.push(edge);\n edgeCount += 1;\n } else {\n unknown += 1;\n }\n if (pendingNodes.length + pendingEdges.length >= batchSize) await flush();\n }\n await flush();\n\n if (unknown > 0) {\n pushUnique(warnings, `omnigraph: skipped ${unknown} unrecognized export line(s) (B.2)`);\n }\n\n // Revision stamp, second half: the head AFTER the stream, captured\n // BEFORE commit (B.2).\n throwIfAborted(signal);\n const headAfter = await newestHead(signal);\n const counts = { lines, nodes: nodeCount, edges: edgeCount, bytes };\n\n if (driftPolicy === 'accept-warn') {\n const finalRef: OmnigraphDataRef = { ...provisionalRef, headAfter };\n const finalRevision = canonicalSourceRevision(finalRef);\n if (headAfter !== headBefore) {\n pushUnique(\n warnings,\n `omnigraph: branch '${branch}' advanced during export (head ${headBefore} → ` +\n `${headAfter}); committed under the canonical final revision per ` +\n `driftPolicy:'accept-warn' — dataRef records both heads (B.2)`,\n );\n }\n await commitBuffered(finalRevision);\n return { kind: 'done', sourceRevision: finalRevision, dataRef: finalRef, counts };\n }\n\n if (headAfter === headBefore) {\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n await activeSession.commit();\n return { kind: 'done', sourceRevision: provisionalRevision, dataRef: provisionalRef, counts };\n }\n\n // Drift (B.2: service:omnigraph-source-changed-during-export).\n const activeSession = session;\n if (activeSession === undefined) throw new Error('omnigraph: internal missing ingest session');\n await activeSession.abort('omnigraph: source changed during export (B.2)');\n if (driftPolicy === 'retry-once' && attempt === 1) {\n pushUnique(\n warnings,\n `omnigraph: branch '${branch}' advanced during export (head ${headBefore} → ` +\n `${headAfter}); load restarted once per driftPolicy:'retry-once' (B.2)`,\n );\n return { kind: 'retry' };\n }\n throw new OmnigraphDriftError(graphId, branch, headBefore, headAfter);\n } catch (err) {\n if (session?.state === 'open') {\n try {\n await session.abort(err);\n } catch {\n // the original failure wins\n }\n }\n throw mapError(err);\n } finally {\n // Cancel the underlying NDJSON stream on any non-exhausted exit.\n try {\n await iterator.return?.();\n } catch {\n // stream teardown must never mask the outcome\n }\n }\n }\n\n async function load(target: IngestTarget, signal?: AbortSignal): Promise<OmnigraphLoadResult> {\n const warnings: string[] = [];\n\n // B.1: surface an SDK/server major.minor mismatch — a warning, never a\n // hard failure.\n let serverVersion: string;\n try {\n serverVersion = (await client.health(callOpts(signal))).version;\n } catch (err) {\n throw mapError(err);\n }\n const server = majorMinor(serverVersion);\n const sdk = majorMinor(SERVER_VERSION);\n if (server === null || server !== sdk) {\n warnings.push(\n `omnigraph: server version ${serverVersion} does not match the SDK-pinned server ` +\n `version ${SERVER_VERSION} (major.minor differ) — SDK behavior is undefined ` +\n `against this server (B.1)`,\n );\n }\n\n for (let attempt = 1; ; attempt += 1) {\n let outcome: AttemptSuccess | AttemptRetry;\n try {\n outcome = await runAttempt(target, signal, warnings, attempt);\n } catch (err) {\n // Covers SDK errors thrown before the session/stream phase\n // (schema.get, commits.list); mapError is a no-op on already-mapped\n // or package-owned errors (B.9).\n throw mapError(err);\n }\n if (outcome.kind === 'retry') continue;\n return {\n sourceRevision: outcome.sourceRevision,\n dataRef: outcome.dataRef,\n counts: outcome.counts,\n serverVersion,\n warnings,\n };\n }\n }\n\n return { load };\n}\n","/**\n * B.7 stored-query `SearchService` (§16.5).\n *\n * A stored query using `bm25`/`fuzzy`/`nearest`/`rrf` with\n * `order { score desc } limit K` returns entity rows plus a score column; this\n * module wires it as a §16.5 `SearchService` via\n * `og.queries.invoke(name, { params, branch })`, passing\n * `RequestContext.signal` through SDK `CallOptions`. Core performs revision\n * admission — the service only declares `revisionDependencies: ['source']`\n * (results come from the server-side branch, so they are invalidated by a\n * source change, never by client-side model/scope drift).\n *\n * Identity (B.3): Omnigraph ids are unique per type only, and a query row\n * carries no type discriminator of its own — so the adapter REQUIRES a\n * caller-supplied column→node-type mapping (`typeOf`), either a\n * `{ column: NodeType }` record keyed by the projection columns that hold\n * bare-variable node structs, or a per-row function. Every returned id is\n * qualified through `encodeSourceId(nodeType, physicalId)` — the same codec\n * every other adapter path uses — so results round-trip `decodeSourceId` and\n * match export-loaded node ids exactly.\n *\n * v1 caveat (B.7): search runs server-side over the WHOLE branch, so against\n * a partial export load it can return ids outside the loaded set. §16.5\n * classifies those as `'not-loaded'` at activation; constrain the stored\n * query to the loaded types, or load the full graph, to avoid the mismatch.\n *\n * Error surface (B.9): SDK typed errors never cross this package's public\n * surface — they rethrow as plain `Error`s with the stable `omnigraph:`\n * prefix. Abort rejections pass through unchanged.\n */\n\nimport { OmnigraphError } from '@modernrelay/omnigraph';\nimport type { InvokeQueryInput, Omnigraph } from '@modernrelay/omnigraph';\nimport type { RequestContext, SearchResult, SearchService } from '@modernrelay/orbit-core';\n\nimport { encodeSourceId } from './idCodec';\n\n/** One stored-query result row: projection column → value. Bare-variable\n * projections (`return { $s }`) hold whole-node structs including `id`. */\nexport type OmnigraphSearchRow = Record<string, unknown>;\n\n/**\n * The required B.3 column→node-type mapping:\n *\n * - a record `{ '$s': 'Signal' }` — the FIRST listed column present in a row\n * with a node struct supplies the physical id, encoded under the mapped\n * type name;\n * - or a per-row function returning the node type name — the row's first\n * node-struct column (row key order) supplies the physical id.\n */\nexport type OmnigraphSearchTypeOf =\n | ((row: OmnigraphSearchRow) => string)\n | Readonly<Record<string, string>>;\n\nexport interface OmnigraphSearchServiceOptions<N = Record<string, unknown>> {\n /** A **preconfigured** SDK client (B.1) — no `baseUrl`/`token` here. */\n client: Omnigraph;\n /** Cluster graph id; the invoke is scoped via `client.graph(graphId)`. */\n graphId: string;\n /** Branch the stored query reads (B.7). Default `'main'`. */\n branch?: string;\n /** Registry name of the stored search query (`POST /queries/{name}`).\n * Invoking a known name works whether or not it is `mcp.expose`d. */\n queryName: string;\n /** Builds the stored query's `params` object from the §16.5 call.\n * Default: `(q, limit) => ({ q, limit })`. */\n params?: (q: string, limit: number) => Record<string, unknown>;\n /** REQUIRED B.3 mapping from row to node type — see\n * {@link OmnigraphSearchTypeOf}. */\n typeOf: OmnigraphSearchTypeOf;\n /** Column whose value becomes `label` (String()-coerced when present).\n * Default: the first string-valued column in row key order. */\n labelColumn?: string;\n /** Full custom row→result escape hatch: overrides the default mapping\n * (including `typeOf`/`labelColumn`); return `null` to skip a row. The\n * returned `id` MUST already be B.3-encoded via `encodeSourceId`. */\n mapRow?: (row: OmnigraphSearchRow) => SearchResult<N> | null;\n}\n\n// ---------------------------------------------------------------------------\n// Small pure helpers\n// ---------------------------------------------------------------------------\n\nfunction defaultParams(q: string, limit: number): Record<string, unknown> {\n return { q, limit };\n}\n\nfunction throwIfAborted(signal: AbortSignal, queryName: string): void {\n if (signal.aborted) {\n throw new DOMException(\n `omnigraph: search query '${queryName}' aborted by request signal`,\n 'AbortError',\n );\n }\n}\n\nfunction isAbortError(err: unknown): boolean {\n return err instanceof Error && err.name === 'AbortError';\n}\n\n/** B.9: SDK typed errors rethrow as plain prefixed `Error`s; abort rejections\n * and everything else pass through unchanged. */\nfunction mapError(err: unknown): unknown {\n if (err instanceof OmnigraphError && !isAbortError(err)) {\n return new Error(`omnigraph: ${err.name} (status ${err.status}): ${err.message}`);\n }\n return err;\n}\n\n/** A bare-variable projection value: a whole-node struct carrying its\n * physical id (B.5 note — `return { $s }` yields `{ id, ...props }`). */\nfunction isNodeStruct(value: unknown): value is { id: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n typeof (value as { id?: unknown }).id === 'string'\n );\n}\n\n/** The invoke response must be a READ envelope with tabular rows — a stored\n * mutation (Change envelope) or malformed body is a hard error. */\nfunction extractRows(response: unknown, queryName: string): readonly OmnigraphSearchRow[] {\n const rows = (response as { rows?: unknown }).rows;\n if (!Array.isArray(rows)) {\n throw new Error(\n `omnigraph: stored query '${queryName}' did not return a read envelope with rows — ` +\n `the B.7 search query must be a stored READ query (not a mutation)`,\n );\n }\n for (const row of rows) {\n if (typeof row !== 'object' || row === null || Array.isArray(row)) {\n throw new Error(\n `omnigraph: stored query '${queryName}' returned a non-object row — ` +\n `expected column→value row objects`,\n );\n }\n }\n return rows as OmnigraphSearchRow[];\n}\n\ninterface ResolvedIdentity {\n kind: string;\n sourceId: string;\n}\n\n/** Resolve the B.3 `(nodeType, physicalId)` pair for one row via `typeOf`. */\nfunction resolveIdentity(\n row: OmnigraphSearchRow,\n typeOf: OmnigraphSearchTypeOf,\n queryName: string,\n): ResolvedIdentity {\n if (typeof typeOf === 'function') {\n const kind = typeOf(row);\n if (typeof kind !== 'string' || kind.length === 0) {\n throw new Error(\n `omnigraph: typeOf returned ${JSON.stringify(kind)} for a '${queryName}' search row — ` +\n `it must return a non-empty node type name (B.3)`,\n );\n }\n for (const key of Object.keys(row)) {\n const value = row[key];\n if (isNodeStruct(value)) return { kind, sourceId: value.id };\n }\n throw new Error(\n `omnigraph: '${queryName}' search row has no node-struct column (an object with a ` +\n `string 'id') — project the matched entity bare (return { $s }) so its physical ` +\n `id is available (B.7)`,\n );\n }\n for (const [column, kind] of Object.entries(typeOf)) {\n const value = row[column];\n if (isNodeStruct(value)) return { kind, sourceId: value.id };\n }\n throw new Error(\n `omnigraph: '${queryName}' search row has no node struct under the mapped column(s) ` +\n `${JSON.stringify(Object.keys(typeOf))} — the typeOf record must key the ` +\n `bare-variable projection column(s) (B.3)`,\n );\n}\n\n// ---------------------------------------------------------------------------\n// createOmnigraphSearchService\n// ---------------------------------------------------------------------------\n\n/**\n * Create the B.7 stored-query search service. Plug it into core as\n * `services.search`; the instance owns `RequestContext` creation,\n * revision-keyed caching, supersede cancellation, and stale-result rejection\n * at admission (§16.5).\n */\nexport function createOmnigraphSearchService<N = Record<string, unknown>>(\n options: OmnigraphSearchServiceOptions<N>,\n): SearchService<N> {\n const { graphId, queryName, typeOf, labelColumn, mapRow } = options;\n const branch = options.branch ?? 'main';\n const buildParams = options.params ?? defaultParams;\n /** Every call is scoped to the graph (SDK cluster routing). */\n const client: Omnigraph = options.client.graph(graphId);\n\n function mapRowDefault(row: OmnigraphSearchRow): SearchResult<N> {\n const { kind, sourceId } = resolveIdentity(row, typeOf, queryName);\n const result: SearchResult<N> = { id: encodeSourceId(kind, sourceId) };\n\n const score = row['score'];\n if (typeof score === 'number' && Number.isFinite(score)) result.score = score;\n\n if (labelColumn !== undefined) {\n const value = row[labelColumn];\n if (typeof value === 'string' || typeof value === 'number') result.label = String(value);\n } else {\n for (const key of Object.keys(row)) {\n if (key === 'score') continue; // the score lane never doubles as a label\n const value = row[key];\n if (typeof value === 'string') {\n result.label = value;\n break;\n }\n }\n }\n return result;\n }\n\n return {\n revisionDependencies: ['source'],\n async search(\n q: string,\n searchOptions: { limit: number },\n ctx: RequestContext,\n ): Promise<readonly SearchResult<N>[]> {\n throwIfAborted(ctx.signal, queryName);\n const limit = Number.isFinite(searchOptions.limit) ? Math.floor(searchOptions.limit) : 0;\n if (q.length === 0 || limit <= 0) return [];\n\n const input: InvokeQueryInput = { branch, params: buildParams(q, limit) };\n let response: unknown;\n try {\n response = await client.queries.invoke(queryName, input, { signal: ctx.signal });\n } catch (err) {\n throw mapError(err);\n }\n throwIfAborted(ctx.signal, queryName);\n\n const rows = extractRows(response, queryName);\n const results: SearchResult<N>[] = [];\n for (const row of rows) {\n if (results.length >= limit) break; // defensive cap — the query owns K\n const mapped = mapRow !== undefined ? mapRow(row) : mapRowDefault(row);\n if (mapped !== null) results.push(mapped);\n }\n return results;\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernrelay/orbit-omnigraph",
3
- "version": "0.2.0",
3
+ "version": "0.13.6",
4
4
  "description": "Omnigraph adapter for Orbit: og.export() loader with drift policies, .pg schema parser, and typed codegen.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  "orbit-omnigraph-codegen": "./dist/codegen-cli.js"
31
31
  },
32
32
  "dependencies": {
33
- "@modernrelay/omnigraph": "0.8.0",
34
- "@modernrelay/orbit-core": "0.2.0"
33
+ "@modernrelay/omnigraph": "0.9.0",
34
+ "@modernrelay/orbit-core": "0.13.6"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^5.6.0",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/idCodec.ts","../src/pgSchema.ts","../src/normalize.ts"],"names":["anns","body","braceIdx","blockEnd"],"mappings":";AA6BO,SAAS,cAAA,CAAe,MAAc,QAAA,EAA0B;AACrE,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,CAAC,IAAA,EAAM,QAAQ,CAAC,CAAA;AACxC;AASO,SAAS,eAAe,EAAA,EAAoC;AACjE,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAA,CAAK,MAAM,EAAE,CAAA;AAAA,EACxB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,MAAM,OA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A,CAAK,WAAA,OAAkB,KAAK,CAAA;AACzD,EAAA,MAAM,EAAA,GAAK,cAAA,CAAe,IAAA,CAAK,IAAA,EAAM,eAAA,CAAgB,IAAA,CAAK,IAAA,EAAM,CAAA,MAAA,EAAS,IAAA,CAAK,IAAI,CAAA,CAAA,CAAG,CAAC,CAAA;AACtF,EAAA,OAAO;AAAA,IACL,EAAA;AAAA,IACA,MAAA,EAAQ,cAAA,CAAe,SAAA,CAAU,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,IAChD,MAAA,EAAQ,cAAA,CAAe,SAAA,CAAU,EAAA,EAAI,KAAK,EAAE,CAAA;AAAA;AAAA;AAAA,IAG5C,KAAA,EAAO,EAAE,GAAG,aAAA,CAAc,KAAK,IAAA,EAAM,WAAA,CAAY,QAAQ,CAAC,CAAA,EAAG,CAAC,cAAc,GAAG,KAAK,IAAA;AAAK,GAC3F;AACF","file":"chunk-32TESFMK.js","sourcesContent":["/**\n * Identity codec (spec Appendix B.3 / B.4).\n *\n * Omnigraph node ids are unique **per type only** (derived from the `@key`\n * tuple within each type's table), so unqualified ids are unsound as orbit\n * `NodeId`s. Every adapter path — nodes, edges, search results, view state,\n * services — MUST qualify ids through this one collision-proof tuple codec.\n * `JSON.stringify` of a fixed-arity string tuple is injective over its inputs\n * (quotes, brackets, commas, and unicode in either component are escaped), so\n * no `(kind, sourceId)` pair can collide with a different pair.\n *\n * Human-readable labels stay separate from identity; there is deliberately no\n * `namespaceIds:false` escape hatch (B.3).\n */\n\nexport interface DecodedSourceId {\n /** The namespace component: a node type name or an edge type name. */\n kind: string;\n /** The physical Omnigraph id within that type's table. */\n sourceId: string;\n}\n\n/**\n * Encode a `(kind, sourceId)` pair as a collision-proof orbit id.\n *\n * - Nodes: `encodeSourceId(NodeType, data.id)`\n * - Edges: `encodeSourceId(EdgeName, data.id)`; endpoints use\n * `encodeSourceId(endpointType, from|to)` (B.3).\n */\nexport function encodeSourceId(kind: string, sourceId: string): string {\n return JSON.stringify([kind, sourceId]);\n}\n\n/**\n * Decode an id produced by {@link encodeSourceId}.\n *\n * Returns `null` for anything that does not conform exactly (non-JSON input,\n * non-array JSON, wrong arity — including synthetic edge ids, which are\n * 4-tuples — or non-string elements). Never throws.\n */\nexport function decodeSourceId(id: string): DecodedSourceId | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(id);\n } catch {\n return null;\n }\n if (!Array.isArray(parsed) || parsed.length !== 2) return null;\n const [kind, sourceId] = parsed as unknown[];\n if (typeof kind !== 'string' || typeof sourceId !== 'string') return null;\n return { kind, sourceId };\n}\n\n/**\n * Synthetic edge id for **query-derived** subgraphs (spec §5 rule, B.4).\n *\n * The GQ grammar has no edge variable, so the query path can never surface\n * physical edge ids; query-derived edges are identified by\n * `['synthetic-edge', EdgeName, source, target]` where `source`/`target` are\n * the already-encoded endpoint node ids.\n *\n * Exported for the future query path (B.5 expansion recipe — post-v1).\n * Caveats (B.4): parallel edges collapse under this scheme, and a dataset\n * MUST NOT mix synthetic ids with physical `/export` ids for the same edges —\n * one scheme per dataset, never both. Because a synthetic id is a 4-tuple,\n * {@link decodeSourceId} rejects it (`null`), keeping the two schemes\n * mechanically un-confusable.\n */\nexport function encodeSyntheticEdgeId(edgeName: string, source: string, target: string): string {\n return JSON.stringify(['synthetic-edge', edgeName, source, target]);\n}\n","/**\n * `.pg` schema model + tolerant parser (spec Appendix B.3 / B.6).\n *\n * The adapter needs three things from the graph schema, all served here:\n * 1. edge endpoint-type resolution (B.3 — export edge lines carry bare\n * `from`/`to` ids without endpoint types),\n * 2. per-property wire-type knowledge for temporal/blob normalization (B.6),\n * 3. a stable schema fingerprint for the export revision stamp (B.2).\n *\n * The parser is deliberately tolerant: it extracts the declarations it\n * understands (interfaces, node blocks, edge declarations, properties,\n * constraints) and preserves anything else — unknown annotations survive as\n * raw strings, unknown type spellings become `{ kind: 'unknown' }` — so a\n * newer server grammar degrades gracefully instead of failing the load.\n *\n * Browser-safe: no `node:` imports. The fingerprint is a pure FNV-1a 64-bit\n * hash rather than `node:crypto` sha256 so this module can sit on the\n * browser entry's critical path.\n */\n\n// ---------------------------------------------------------------------------\n// Model\n// ---------------------------------------------------------------------------\n\n/** Closed scalar set per the `.pg` grammar (docs/user/schema). */\nexport type PgScalarName =\n | 'String'\n | 'Blob'\n | 'Bool'\n | 'I32'\n | 'I64'\n | 'U32'\n | 'U64'\n | 'F32'\n | 'F64'\n | 'Date'\n | 'DateTime';\n\nexport type PgType =\n | PgScalarName\n | { kind: 'vector'; dim: number }\n | { kind: 'enum'; values: readonly string[] }\n | { kind: 'list'; element: PgScalarName }\n | { kind: 'unknown'; raw: string };\n\nexport interface PgProperty {\n name: string;\n type: PgType;\n /** `T?` nullability. */\n optional: boolean;\n /** Set by inline `@key` or a body-level `@key(...)` naming this property. */\n key: boolean;\n /** Set by inline `@unique` or a body-level `@unique(...)` naming this property. */\n unique: boolean;\n /** Set by inline `@index` or a body-level `@index(...)` naming this property. */\n index: boolean;\n /** Every annotation as written (`'@key'`, `'@embed(\"body\")'`) — unknown ones preserved verbatim. */\n annotations: readonly string[];\n}\n\nexport interface PgInterfaceType {\n name: string;\n properties: readonly PgProperty[];\n /** Body-level constraint declarations preserved verbatim (e.g. `'@unique(a, b)'`). */\n constraints: readonly string[];\n}\n\nexport interface PgNodeType {\n name: string;\n /** Interface names from the `implements` clause (already expanded into `properties`). */\n implements: readonly string[];\n properties: readonly PgProperty[];\n constraints: readonly string[];\n}\n\nexport interface PgEdgeType {\n name: string;\n /** Source (from) node type name. */\n from: string;\n /** Destination (to) node type name. */\n to: string;\n /** Raw `@card` bounds, e.g. `'1..1'`, `'0..*'`. Absent means the default `0..*`. */\n card?: string;\n /** Header annotations as written (including the `@card(...)` one, if any). */\n annotations: readonly string[];\n properties: readonly PgProperty[];\n constraints: readonly string[];\n}\n\nexport interface PgSchema {\n interfaces: readonly PgInterfaceType[];\n nodes: readonly PgNodeType[];\n edges: readonly PgEdgeType[];\n}\n\nconst SCALARS: ReadonlySet<string> = new Set<PgScalarName>([\n 'String',\n 'Blob',\n 'Bool',\n 'I32',\n 'I64',\n 'U32',\n 'U64',\n 'F32',\n 'F64',\n 'Date',\n 'DateTime',\n]);\n\n// ---------------------------------------------------------------------------\n// Lexical helpers (string-aware; `.pg` strings are double-quoted with `\\` escapes)\n// ---------------------------------------------------------------------------\n\n/** Blank out line and block comments, preserving newlines and string literals. */\nfunction stripComments(src: string): string {\n let out = '';\n let i = 0;\n const n = src.length;\n while (i < n) {\n const ch = src.charAt(i);\n if (ch === '\"') {\n out += ch;\n i++;\n while (i < n) {\n const c = src.charAt(i);\n out += c;\n i++;\n if (c === '\\\\' && i < n) {\n out += src.charAt(i);\n i++;\n } else if (c === '\"') break;\n }\n } else if (ch === '/' && src.charAt(i + 1) === '/') {\n while (i < n && src.charAt(i) !== '\\n') i++;\n } else if (ch === '/' && src.charAt(i + 1) === '*') {\n i += 2;\n while (i < n && !(src.charAt(i) === '*' && src.charAt(i + 1) === '/')) {\n out += src.charAt(i) === '\\n' ? '\\n' : ' ';\n i++;\n }\n i += 2;\n } else {\n out += ch;\n i++;\n }\n }\n return out;\n}\n\n/** Index just past the `}` matching the `{` at `openIdx`, or `src.length` if unbalanced. */\nfunction findBlockEnd(src: string, openIdx: number): number {\n let depth = 0;\n let i = openIdx;\n const n = src.length;\n while (i < n) {\n const ch = src.charAt(i);\n if (ch === '\"') {\n i++;\n while (i < n) {\n const c = src.charAt(i);\n i++;\n if (c === '\\\\') i++;\n else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '{') depth++;\n else if (ch === '}') {\n depth--;\n if (depth === 0) return i + 1;\n }\n i++;\n }\n return n;\n}\n\n/** Split a block body into statements at newlines that sit outside parens/brackets/strings. */\nfunction splitStatements(body: string): string[] {\n const out: string[] = [];\n let depth = 0;\n let current = '';\n let i = 0;\n const n = body.length;\n while (i < n) {\n const ch = body.charAt(i);\n if (ch === '\"') {\n current += ch;\n i++;\n while (i < n) {\n const c = body.charAt(i);\n current += c;\n i++;\n if (c === '\\\\' && i < n) {\n current += body.charAt(i);\n i++;\n } else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '(' || ch === '[') depth++;\n else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);\n if (ch === '\\n' && depth === 0) {\n out.push(current);\n current = '';\n } else {\n current += ch;\n }\n i++;\n }\n out.push(current);\n return out.map((s) => s.trim()).filter((s) => s.length > 0);\n}\n\ninterface RawAnnotation {\n name: string;\n args?: string;\n raw: string;\n}\n\n/** Scan a run of `@ident` / `@ident(...)` annotations starting at `start`. */\nfunction scanAnnotations(src: string, start: number): { anns: RawAnnotation[]; end: number } {\n const anns: RawAnnotation[] = [];\n let i = start;\n const n = src.length;\n for (;;) {\n let j = i;\n while (j < n && /\\s/.test(src.charAt(j))) j++;\n if (src.charAt(j) !== '@') break;\n const m = /^@([A-Za-z_]\\w*)/.exec(src.slice(j));\n if (!m || m[1] === undefined) break;\n const name = m[1];\n let end = j + m[0].length;\n let args: string | undefined;\n if (src.charAt(end) === '(') {\n let depth = 0;\n let k = end;\n while (k < n) {\n const ch = src.charAt(k);\n if (ch === '\"') {\n k++;\n while (k < n) {\n const c = src.charAt(k);\n k++;\n if (c === '\\\\') k++;\n else if (c === '\"') break;\n }\n continue;\n }\n if (ch === '(') depth++;\n else if (ch === ')') {\n depth--;\n if (depth === 0) {\n k++;\n break;\n }\n }\n k++;\n }\n args = src.slice(end + 1, k - 1);\n end = k;\n }\n const entry: RawAnnotation = { name, raw: src.slice(j, end) };\n if (args !== undefined) entry.args = args;\n anns.push(entry);\n i = end;\n }\n return { anns, end: i };\n}\n\n/** Split on top-level commas (outside parens/strings), trim, drop empties. */\nfunction splitArgs(args: string): string[] {\n const out: string[] = [];\n let depth = 0;\n let current = '';\n for (let i = 0; i < args.length; i++) {\n const ch = args.charAt(i);\n if (ch === '\"') {\n current += ch;\n i++;\n while (i < args.length) {\n const c = args.charAt(i);\n current += c;\n if (c === '\\\\') {\n i++;\n current += args.charAt(i);\n } else if (c === '\"') break;\n i++;\n }\n continue;\n }\n if (ch === '(' || ch === '[') depth++;\n else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);\n if (ch === ',' && depth === 0) {\n out.push(current);\n current = '';\n } else {\n current += ch;\n }\n }\n out.push(current);\n return out.map((s) => s.trim()).filter((s) => s.length > 0);\n}\n\n// ---------------------------------------------------------------------------\n// Statement parsing\n// ---------------------------------------------------------------------------\n\ninterface MutableTypeBody {\n properties: PgProperty[];\n constraints: string[];\n}\n\nfunction parseTypeRef(text: string): { type: PgType; optional: boolean; end: number } {\n let i = 0;\n const n = text.length;\n while (i < n && /\\s/.test(text.charAt(i))) i++;\n let type: PgType;\n if (text.charAt(i) === '[') {\n const m = /^\\[\\s*([A-Za-z_]\\w*)\\s*\\]/.exec(text.slice(i));\n if (m && m[1] !== undefined && SCALARS.has(m[1])) {\n type = { kind: 'list', element: m[1] as PgScalarName };\n i += m[0].length;\n } else {\n const close = text.indexOf(']', i);\n const end = close === -1 ? n : close + 1;\n type = { kind: 'unknown', raw: text.slice(i, end).trim() };\n i = end;\n }\n } else {\n const m = /^([A-Za-z_]\\w*)/.exec(text.slice(i));\n if (!m || m[1] === undefined) {\n return { type: { kind: 'unknown', raw: text.trim() }, optional: false, end: n };\n }\n const ident = m[1];\n i += m[0].length;\n if ((ident === 'enum' || ident === 'Vector') && text.charAt(i) === '(') {\n let depth = 0;\n let k = i;\n while (k < n) {\n const ch = text.charAt(k);\n if (ch === '(') depth++;\n else if (ch === ')') {\n depth--;\n if (depth === 0) {\n k++;\n break;\n }\n }\n k++;\n }\n const inner = text.slice(i + 1, k - 1);\n i = k;\n if (ident === 'enum') {\n const values = splitArgs(inner).map((v) => v.replace(/^\"(.*)\"$/s, '$1'));\n type = { kind: 'enum', values };\n } else {\n const dim = Number.parseInt(inner.trim(), 10);\n type = Number.isFinite(dim)\n ? { kind: 'vector', dim }\n : { kind: 'unknown', raw: `Vector(${inner})` };\n }\n } else if (SCALARS.has(ident)) {\n type = ident as PgScalarName;\n } else {\n type = { kind: 'unknown', raw: ident };\n }\n }\n let optional = false;\n if (text.charAt(i) === '?') {\n optional = true;\n i++;\n }\n return { type, optional, end: i };\n}\n\nfunction parseBody(body: string): MutableTypeBody {\n const properties: PgProperty[] = [];\n const constraints: string[] = [];\n for (const stmt of splitStatements(body)) {\n if (stmt.startsWith('@')) {\n const { anns } = scanAnnotations(stmt, 0);\n for (const a of anns) constraints.push(a.raw);\n continue;\n }\n const head = /^([A-Za-z_]\\w*)\\s*:\\s*/.exec(stmt);\n if (!head || head[1] === undefined) continue; // tolerant: skip unrecognized statements\n const name = head[1];\n const rest = stmt.slice(head[0].length);\n const { type, optional, end } = parseTypeRef(rest);\n const { anns } = scanAnnotations(rest, end);\n properties.push({\n name,\n type,\n optional,\n key: anns.some((a) => a.name === 'key'),\n unique: anns.some((a) => a.name === 'unique'),\n index: anns.some((a) => a.name === 'index'),\n annotations: anns.map((a) => a.raw),\n });\n }\n // Body-level @key(a, b) / @unique(a) / @index(a) constraints flag the named properties.\n for (const raw of constraints) {\n const m = /^@(key|unique|index)\\((.*)\\)$/s.exec(raw);\n if (!m || m[1] === undefined || m[2] === undefined) continue;\n const flag = m[1] as 'key' | 'unique' | 'index';\n for (const propName of splitArgs(m[2])) {\n const prop = properties.find((p) => p.name === propName);\n if (prop) prop[flag] = true;\n }\n }\n return { properties, constraints };\n}\n\n// ---------------------------------------------------------------------------\n// Top-level parse\n// ---------------------------------------------------------------------------\n\n/**\n * Parse `.pg` source into a {@link PgSchema}. Tolerant by design: malformed\n * or unrecognized declarations are skipped, not fatal; `implements` clauses\n * are expanded into node properties (node-declared properties win on name\n * collisions, matching the server's table layout).\n */\nexport function parsePgSchema(source: string): PgSchema {\n const src = stripComments(source);\n const interfaces: PgInterfaceType[] = [];\n const nodes: (PgNodeType & { properties: PgProperty[] })[] = [];\n const edges: PgEdgeType[] = [];\n\n const headRe = /\\b(interface|node|edge)\\s+([A-Za-z_]\\w*)/g;\n let m: RegExpExecArray | null;\n while ((m = headRe.exec(src)) !== null) {\n const kw = m[1];\n const name = m[2];\n if (kw === undefined || name === undefined) continue;\n let pos = headRe.lastIndex;\n\n if (kw === 'edge') {\n const em = /^\\s*:\\s*([A-Za-z_]\\w*)\\s*->\\s*([A-Za-z_]\\w*)/.exec(src.slice(pos));\n if (!em || em[1] === undefined || em[2] === undefined) continue; // tolerant skip\n pos += em[0].length;\n const { anns, end } = scanAnnotations(src, pos);\n pos = end;\n let body: MutableTypeBody = { properties: [], constraints: [] };\n let braceIdx = pos;\n while (braceIdx < src.length && /\\s/.test(src.charAt(braceIdx))) braceIdx++;\n if (src.charAt(braceIdx) === '{') {\n const blockEnd = findBlockEnd(src, braceIdx);\n body = parseBody(src.slice(braceIdx + 1, blockEnd - 1));\n pos = blockEnd;\n }\n const card = anns.find((a) => a.name === 'card')?.args?.trim();\n const edge: PgEdgeType = {\n name,\n from: em[1],\n to: em[2],\n annotations: anns.map((a) => a.raw),\n properties: body.properties,\n constraints: body.constraints,\n ...(card !== undefined ? { card } : {}),\n };\n edges.push(edge);\n headRe.lastIndex = pos;\n continue;\n }\n\n // interface / node: optional `implements A, B` (node only), then a block.\n let impls: string[] = [];\n if (kw === 'node') {\n const im = /^\\s*implements\\s+([A-Za-z_]\\w*(?:\\s*,\\s*[A-Za-z_]\\w*)*)/.exec(src.slice(pos));\n if (im && im[1] !== undefined) {\n impls = im[1].split(',').map((s) => s.trim());\n pos += im[0].length;\n }\n }\n let braceIdx = pos;\n while (braceIdx < src.length && /\\s/.test(src.charAt(braceIdx))) braceIdx++;\n if (src.charAt(braceIdx) !== '{') continue; // tolerant skip\n const blockEnd = findBlockEnd(src, braceIdx);\n const body = parseBody(src.slice(braceIdx + 1, blockEnd - 1));\n headRe.lastIndex = blockEnd;\n if (kw === 'interface') {\n interfaces.push({ name, properties: body.properties, constraints: body.constraints });\n } else {\n nodes.push({\n name,\n implements: impls,\n properties: body.properties,\n constraints: body.constraints,\n });\n }\n }\n\n // Expand implements clauses: interface properties precede the node's own,\n // except where the node re-declares a name (node declaration wins).\n for (const node of nodes) {\n if (node.implements.length === 0) continue;\n const own = new Set(node.properties.map((p) => p.name));\n const inherited: PgProperty[] = [];\n for (const ifaceName of node.implements) {\n const iface = interfaces.find((i) => i.name === ifaceName);\n if (!iface) continue; // tolerant: unknown interface\n for (const p of iface.properties) {\n if (!own.has(p.name) && !inherited.some((q) => q.name === p.name)) inherited.push(p);\n }\n }\n node.properties = [...inherited, ...node.properties];\n }\n\n return { interfaces, nodes, edges };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve an edge type's declared endpoint node types (B.3). Export edge\n * lines carry bare `from`/`to` ids, so endpoint types come from here. Edge\n * names match exactly first, then case-insensitively (the server matches edge\n * names case-insensitively). Returns `null` for an unknown edge name.\n */\nexport function edgeEndpointTypes(\n schema: PgSchema,\n edgeName: string,\n): { from: string; to: string } | null {\n const lower = edgeName.toLowerCase();\n const edge =\n schema.edges.find((e) => e.name === edgeName) ??\n schema.edges.find((e) => e.name.toLowerCase() === lower);\n return edge ? { from: edge.from, to: edge.to } : null;\n}\n\n/**\n * Stable fingerprint of `.pg` source for the B.2 revision stamp: FNV-1a\n * 64-bit over the UTF-8 bytes of the source, as 16 lowercase hex chars.\n *\n * Pure and browser-safe (no `node:crypto`). Hashes the source **verbatim**:\n * any textual change — including comments or whitespace — changes the\n * fingerprint, which is the conservative choice for drift detection.\n */\nexport function schemaFingerprint(source: string): string {\n const MASK64 = 0xffffffffffffffffn;\n let h = 0xcbf29ce484222325n;\n const bytes = new TextEncoder().encode(source);\n for (const b of bytes) {\n h ^= BigInt(b);\n h = (h * 0x100000001b3n) & MASK64;\n }\n return h.toString(16).padStart(16, '0');\n}\n\nexport interface BigIntKeyWarning {\n /** Node or edge type name. */\n type: string;\n /** The hazardous property. */\n property: string;\n}\n\n/**\n * B.6 hazard scan: `I64`/`U64` properties used as identity (`@key` or named\n * `id`). The HTTP path emits native JSON numbers even past ±2^53 — silently\n * rounded by `JSON.parse`, unrescued by the SDK — so two distinct big-int ids\n * can collapse after rounding, violating §5. Surface these before loading.\n */\nexport function bigIntKeyWarnings(schema: PgSchema): BigIntKeyWarning[] {\n const out: BigIntKeyWarning[] = [];\n for (const t of [...schema.nodes, ...schema.edges]) {\n for (const p of t.properties) {\n if ((p.type === 'I64' || p.type === 'U64') && (p.key || p.name === 'id')) {\n out.push({ type: t.name, property: p.name });\n }\n }\n }\n return out;\n}\n","/**\n * Export-line classification and normalization (spec Appendix B.2 / B.3 / B.6).\n *\n * `/export` streams NDJSON — one JSON object per line, `data` passed through\n * **verbatim** by the SDK. This module turns those lines into orbit\n * `GraphNode`/`GraphEdge` values:\n *\n * - ids are namespaced through the B.3 codec (`encodeSourceId`),\n * - the node/edge KIND is injected as {@link ORBIT_TYPE_KEY} — namespaced so\n * a schema's own `type` property passes through as ordinary data (B.6),\n * - edge endpoint types are resolved from the `.pg` schema (edge lines carry\n * bare `from`/`to` ids — B.3),\n * - attr values are normalized to the query-path string forms (B.6) so\n * generated types and §16.6 temporal dimensions see one encoding\n * regardless of read path:\n * * `Date` — export sends **days since Unix epoch** (number) →\n * `'YYYY-MM-DD'` (UTC)\n * * `DateTime` — export sends **epoch milliseconds** (number) →\n * ISO 8601 (`'YYYY-MM-DDTHH:MM:SS.mmmZ'`)\n * * `Blob` — inline internal blobs arrive as `'base64:<data>'` →\n * `'data:application/octet-stream;base64,<data>'`;\n * external-URI refs pass through verbatim (B.10)\n * * everything else — verbatim.\n *\n * Non-finite float sentinels (`'NaN'`/`'Infinity'`/`'-Infinity'`) are a\n * **query-path-only** encoding: a non-finite stored float aborts `/export`\n * server-side, so export-loaded data never contains the sentinels (B.6).\n * This module therefore does NOT special-case them.\n */\n\nimport type { GraphEdge, GraphNode } from '@modernrelay/orbit-core';\nimport { encodeSourceId } from './idCodec';\nimport {\n edgeEndpointTypes,\n type PgEdgeType,\n type PgNodeType,\n type PgProperty,\n type PgSchema,\n type PgType,\n} from './pgSchema';\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** An edge line names an edge type the `.pg` schema does not declare (B.3). */\nexport class UnknownEdgeTypeError extends Error {\n override readonly name = 'UnknownEdgeTypeError';\n readonly edgeName: string;\n constructor(edgeName: string) {\n super(\n `Unknown edge type '${edgeName}': not declared in the graph schema, so its ` +\n `endpoint node types cannot be resolved (spec B.3).`,\n );\n this.edgeName = edgeName;\n }\n}\n\n/** An export line is structurally unusable (e.g. missing/non-string `data.id`). */\nexport class InvalidExportLineError extends Error {\n override readonly name = 'InvalidExportLineError';\n constructor(message: string) {\n super(message);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Classification (B.2 line shapes)\n// ---------------------------------------------------------------------------\n\nexport interface NodeExportLine {\n kind: 'node';\n type: string;\n data: Record<string, unknown>;\n}\n\nexport interface EdgeExportLine {\n kind: 'edge';\n edge: string;\n from: string;\n to: string;\n data: Record<string, unknown>;\n}\n\nexport type ClassifiedExportLine = NodeExportLine | EdgeExportLine | { kind: 'unknown' };\n\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v);\n}\n\n/**\n * Classify one parsed export line per the B.2 shapes:\n * - node line: `{\"type\": \"<NodeType>\", \"data\": {\"id\", …props}}`\n * - edge line: `{\"edge\": \"<EdgeName>\", \"from\": <src id>, \"to\": <dst id>, \"data\": {\"id\", …props}}`\n * Anything else is `{ kind: 'unknown' }`.\n */\nexport function classifyExportLine(line: unknown): ClassifiedExportLine {\n if (!isRecord(line) || !isRecord(line['data'])) return { kind: 'unknown' };\n const data = line['data'];\n if (\n typeof line['edge'] === 'string' &&\n typeof line['from'] === 'string' &&\n typeof line['to'] === 'string'\n ) {\n return { kind: 'edge', edge: line['edge'], from: line['from'], to: line['to'], data };\n }\n if (typeof line['type'] === 'string') {\n return { kind: 'node', type: line['type'], data };\n }\n return { kind: 'unknown' };\n}\n\n// ---------------------------------------------------------------------------\n// Value normalization (B.6)\n// ---------------------------------------------------------------------------\n\nconst MS_PER_DAY = 86_400_000;\n\n/** Format an epoch-day count as `'YYYY-MM-DD'` (UTC). Handles negative days. */\nfunction formatEpochDay(days: number): string {\n const d = new Date(days * MS_PER_DAY);\n const t = d.getTime();\n if (!Number.isFinite(t)) return String(days); // out of Date range — leave a readable value\n const y = d.getUTCFullYear();\n const year =\n y < 0\n ? `-${String(-y).padStart(6, '0')}`\n : y > 9999\n ? `+${String(y).padStart(6, '0')}`\n : String(y).padStart(4, '0');\n const month = String(d.getUTCMonth() + 1).padStart(2, '0');\n const day = String(d.getUTCDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\nfunction normalizeValue(type: PgType | undefined, value: unknown): unknown {\n if (type === undefined || value === null || value === undefined) return value;\n if (type === 'Date' && typeof value === 'number' && Number.isInteger(value)) {\n return formatEpochDay(value);\n }\n if (type === 'DateTime' && typeof value === 'number' && Number.isFinite(value)) {\n const d = new Date(value);\n return Number.isFinite(d.getTime()) ? d.toISOString() : value;\n }\n if (type === 'Blob' && typeof value === 'string' && value.startsWith('base64:')) {\n return `data:application/octet-stream;base64,${value.slice('base64:'.length)}`;\n }\n return value;\n}\n\nfunction propTypeMap(t: PgNodeType | PgEdgeType | undefined): ReadonlyMap<string, PgType> {\n const map = new Map<string, PgType>();\n if (t) for (const p of t.properties as readonly PgProperty[]) map.set(p.name, p.type);\n return map;\n}\n\nfunction normalizeData(\n data: Record<string, unknown>,\n types: ReadonlyMap<string, PgType>,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(data)) out[k] = normalizeValue(types.get(k), v);\n return out;\n}\n\nfunction requireStringId(data: Record<string, unknown>, what: string): string {\n const id = data['id'];\n if (typeof id !== 'string') {\n throw new InvalidExportLineError(\n `${what} export line has ${id === undefined ? 'no' : 'a non-string'} 'data.id' — ` +\n `cannot build a stable orbit id (spec B.3).`,\n );\n }\n return id;\n}\n\n// ---------------------------------------------------------------------------\n// Node / edge normalization (B.3)\n// ---------------------------------------------------------------------------\n\n/**\n * The adapter's node/edge KIND discriminator key (B.3/B.6).\n *\n * Namespaced on purpose: the adapter injects this field into someone else's\n * data, so it takes the awkward key and leaves the generic word `type` to the\n * schema author, who means something real by it (`Company.type = investor`).\n * A colon is illegal in `.pg` identifiers, so no schema property can ever\n * claim this key — the collision class is closed by construction, and a\n * source-declared `type` now flows through untouched with no preservation\n * mechanism, no warning, and no schema migration. Same convention as\n * GraphQL's `__typename` / JSON-LD's `@type`.\n */\nexport const ORBIT_TYPE_KEY = 'orbit:type';\n\n/**\n * Normalize a node export line to a `GraphNode`:\n * `id = encodeSourceId(type, data.id)`, `attrs = { …data, 'orbit:type' }`\n * with B.6 value normalization driven by the schema's property types. A node\n * type absent from the schema is tolerated — its attrs pass through verbatim\n * (identity never needs the schema on the node path).\n */\nexport function normalizeNode(\n line: { type: string; data: Record<string, unknown> },\n schema: PgSchema,\n): GraphNode {\n const nodeType = schema.nodes.find((n) => n.name === line.type);\n const id = encodeSourceId(line.type, requireStringId(line.data, `Node '${line.type}'`));\n return {\n id,\n // The discriminator is adapter-owned identity metadata. It lands LAST so\n // a forward-compatible export field literally named `orbit:type` cannot\n // forge the value the generated attrs unions promise (B.3/B.6).\n attrs: { ...normalizeData(line.data, propTypeMap(nodeType)), [ORBIT_TYPE_KEY]: line.type },\n };\n}\n\n/**\n * Normalize an edge export line to a `GraphEdge`:\n * `id = encodeSourceId(edge, data.id)`; `source`/`target` namespace the bare\n * `from`/`to` ids with the endpoint node types resolved from the schema\n * (B.3). Throws {@link UnknownEdgeTypeError} when the schema does not declare\n * the edge — endpoint identity cannot be constructed without it.\n */\nexport function normalizeEdge(\n line: { edge: string; from: string; to: string; data: Record<string, unknown> },\n schema: PgSchema,\n): GraphEdge {\n const endpoints = edgeEndpointTypes(schema, line.edge);\n if (endpoints === null) throw new UnknownEdgeTypeError(line.edge);\n const lower = line.edge.toLowerCase();\n const edgeType =\n schema.edges.find((e) => e.name === line.edge) ??\n schema.edges.find((e) => e.name.toLowerCase() === lower);\n const id = encodeSourceId(line.edge, requireStringId(line.data, `Edge '${line.edge}'`));\n return {\n id,\n source: encodeSourceId(endpoints.from, line.from),\n target: encodeSourceId(endpoints.to, line.to),\n // As on nodes, the adapter's resolved edge name lands last and always\n // wins the discriminator key; a source `type` property is ordinary data.\n attrs: { ...normalizeData(line.data, propTypeMap(edgeType)), [ORBIT_TYPE_KEY]: line.edge },\n };\n}\n"]}