@modernrelay/orbit-omnigraph 0.13.5 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -39
- package/dist/{chunk-32TESFMK.js → chunk-YDRPXYQ7.js} +40 -23
- package/dist/chunk-YDRPXYQ7.js.map +1 -0
- package/dist/codegen-cli.js +14 -14
- package/dist/codegen-cli.js.map +1 -1
- package/dist/index.d.ts +117 -110
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +9 -9
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-32TESFMK.js.map +0 -1
package/dist/codegen-cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/codegen.ts","../src/codegen-cli.ts"],"names":[],"mappings":";;;;;;;AAoEA,IAAM,SAAA,GAA0C;AAAA,EAC9C,MAAA,EAAQ,QAAA;AAAA,EACR,IAAA,EAAM,QAAA;AAAA,EACN,IAAA,EAAM,SAAA;AAAA,EACN,GAAA,EAAK,QAAA;AAAA,EACL,GAAA,EAAK,QAAA;AAAA,EACL,GAAA,EAAK,QAAA;AAAA,EACL,GAAA,EAAK,QAAA;AAAA,EACL,GAAA,EAAK,QAAA;AAAA,EACL,GAAA,EAAK,QAAA;AAAA,EACL,IAAA,EAAM,QAAA;AAAA,EACN,QAAA,EAAU;AACZ,CAAA;AAGA,SAAS,gBAAgB,KAAA,EAAuB;AAC9C,EAAA,OAAO,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,MAAM,EAAE,OAAA,CAAQ,IAAA,EAAM,KAAK,CAAA,CAAE,QAAQ,KAAA,EAAO,KAAK,EAAE,OAAA,CAAQ,KAAA,EAAO,KAAK,CAAC,CAAA,CAAA,CAAA;AAC1G;AAEA,SAAS,OAAO,IAAA,EAAsB;AACpC,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAO,UAAU,IA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CAAI,CAAA;AAAA,EACvE,CAAA,MAAO;AACL,IAAA,OAAA,CAAQ,MAAA,CAAO,MAAM,MAAM,CAAA;AAAA,EAC7B;AACA,EAAA,OAAO,CAAA;AACT;AAEA,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA,CAAE,IAAA;AAAA,EAC1B,CAAC,IAAA,KAAS;AACR,IAAA,OAAA,CAAQ,QAAA,GAAW,IAAA;AAAA,EACrB,CAAA;AAAA,EACA,CAAC,GAAA,KAAiB;AAChB,IAAA,MAAM,UAAU,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,OAAO,GAAG,CAAA;AAC/D,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,yBAAA,EAA4B,OAAO;AAAA,CAAI,CAAA;AAC5D,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AAAA,EACrB;AACF,CAAA","file":"codegen-cli.js","sourcesContent":["/**\n * `.pg` → TypeScript codegen (spec Appendix B.6).\n *\n * The `.pg` scalar set is closed, so typed attrs for the §5 `N`/`E` generics\n * generate mechanically: one interface per node/edge type, a `NodeAttrs` /\n * `EdgeAttrs` discriminated union on the adapter-injected `'orbit:type'`\n * field (B.3 — namespaced so a schema's own `type` property emits as an\n * ordinary member), and a `TypeMap` lookup interface.\n *\n * Generated shapes describe attrs **after** the adapter's B.6 normalization\n * (the v1 loader rewrites export-path wire values to the query-path string\n * forms before populating attrs — see `normalize.ts`), so one encoding holds\n * regardless of read path:\n *\n * `Date` → `string` (`'YYYY-MM-DD'`)\n * `DateTime` → `string` (ISO 8601, `'YYYY-MM-DDTHH:MM:SS.mmmZ'`)\n * `enum(...)` → string-literal union\n * `I64`/`U64` → `number` (beware silent rounding past ±2^53 — B.6)\n * `F32`/`F64` → `number`\n * `Vector(n)` → `number[]`\n * `Blob` → `string` (`data:` URI for inline blobs, stored URI refs verbatim)\n * `T?` → `T | null`\n *\n * Output is a self-contained module (no imports), safe under the strictest\n * tsconfig (`strict`, `exactOptionalPropertyTypes`, `verbatimModuleSyntax`,\n * `isolatedModules`). The file carries a DO-NOT-EDIT header with the B.2\n * schema fingerprint. Generation is deterministic — no timestamps — so the\n * output is committable and diff-stable.\n *\n * Browser-safe: no `node:` imports (the CLI wrapper in `codegen-cli.ts` owns\n * file I/O).\n */\n\nimport { ORBIT_TYPE_KEY } from './normalize';\nimport {\n parsePgSchema,\n schemaFingerprint,\n type PgProperty,\n type PgScalarName,\n type PgSchema,\n type PgType,\n} from './pgSchema';\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\nexport interface GenerateTypesOptions {\n /**\n * Extra provenance lines for the DO-NOT-EDIT banner (e.g. the schema file\n * path or server URL). May be multi-line; lines are comment-prefixed as\n * needed.\n */\n header?: string;\n /**\n * The B.2 schema fingerprint of the `.pg` **source** (from\n * {@link schemaFingerprint}). When omitted, a fingerprint of the canonical\n * parsed model is used instead and labelled as such — prefer\n * {@link generateTypesFromPgSource}, which always stamps the source\n * fingerprint.\n */\n fingerprint?: string;\n}\n\n// ---------------------------------------------------------------------------\n// B.6 wire → TS mapping (post-normalization)\n// ---------------------------------------------------------------------------\n\nconst SCALAR_TS: Record<PgScalarName, string> = {\n String: 'string',\n Blob: 'string',\n Bool: 'boolean',\n I32: 'number',\n I64: 'number',\n U32: 'number',\n U64: 'number',\n F32: 'number',\n F64: 'number',\n Date: 'string',\n DateTime: 'string',\n};\n\n/** Single-quoted TS string literal with escapes. */\nfunction tsStringLiteral(value: string): string {\n return `'${value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\").replace(/\\r/g, '\\\\r').replace(/\\n/g, '\\\\n')}'`;\n}\n\nfunction tsType(type: PgType): string {\n if (typeof type === 'string') return SCALAR_TS[type];\n switch (type.kind) {\n case 'vector':\n return 'number[]';\n case 'enum':\n return type.values.length === 0 ? 'string' : type.values.map(tsStringLiteral).join(' | ');\n case 'list':\n return `${SCALAR_TS[type.element]}[]`;\n case 'unknown':\n return 'unknown';\n }\n}\n\n/** One-line doc note for types whose TS shape hides a wire subtlety (B.6). */\nfunction wireNote(type: PgType): string | null {\n if (typeof type === 'string') {\n switch (type) {\n case 'Date':\n return \"`Date` — normalized to 'YYYY-MM-DD' (UTC) on load (B.6).\";\n case 'DateTime':\n return '`DateTime` — normalized to ISO 8601 UTC on load (B.6).';\n case 'Blob':\n return \"`Blob` — `data:` URI for inline blobs, stored URI refs verbatim (B.6/B.10).\";\n case 'I64':\n case 'U64':\n return `\\`${type}\\` — JSON numbers round silently past ±2^53 (B.6).`;\n default:\n return null;\n }\n }\n switch (type.kind) {\n case 'vector':\n return `\\`Vector(${type.dim})\\`.`;\n case 'unknown':\n return `Unrecognized \\`.pg\\` type \\`${type.raw}\\` — value passes through verbatim.`;\n default:\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Emission helpers\n// ---------------------------------------------------------------------------\n\nconst IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nfunction propertyKey(name: string): string {\n return IDENT_RE.test(name) ? name : tsStringLiteral(name);\n}\n\nfunction emitProperty(lines: string[], prop: PgProperty): void {\n const note = wireNote(prop.type);\n if (note !== null) lines.push(` /** ${note} */`);\n const base = tsType(prop.type);\n lines.push(` ${propertyKey(prop.name)}: ${prop.optional ? `${base} | null` : base};`);\n}\n\nfunction emitPropsInterface(\n lines: string[],\n interfaceName: string,\n kindLabel: 'node' | 'edge',\n typeName: string,\n properties: readonly PgProperty[],\n): void {\n lines.push(`/** Normalized attrs for ${kindLabel} type \\`${typeName}\\` (B.6). */`);\n lines.push(`export interface ${interfaceName} {`);\n if (!properties.some((p) => p.name === 'id')) {\n lines.push(\n ` /** Physical Omnigraph id — injected into every export line's \\`data\\` (B.2); unique per ${kindLabel} type only (B.3). */`,\n );\n lines.push(' id: string;');\n }\n for (const prop of properties) {\n // Every schema property emits normally — including one named `type`: the\n // adapter's discriminator lives at the namespaced ORBIT_TYPE_KEY, so\n // there is nothing to shadow (B.3/B.6).\n emitProperty(lines, prop);\n }\n lines.push('}');\n lines.push('');\n}\n\nfunction emitAttrsUnion(\n lines: string[],\n unionName: string,\n doc: string,\n members: ReadonlyArray<{ typeName: string; interfaceName: string }>,\n): void {\n lines.push(`/** ${doc} */`);\n if (members.length === 0) {\n lines.push(`export type ${unionName} = never;`);\n } else {\n lines.push(`export type ${unionName} =`);\n members.forEach(({ typeName, interfaceName }, i) => {\n const tail = i === members.length - 1 ? ';' : '';\n lines.push(\n ` | ({ ${tsStringLiteral(ORBIT_TYPE_KEY)}: ${tsStringLiteral(typeName)} } & ${interfaceName})${tail}`,\n );\n });\n }\n lines.push('');\n}\n\nfunction headerBanner(fingerprintLine: string, extra: string | undefined): string[] {\n const lines = [\n '// AUTO-GENERATED — DO NOT EDIT.',\n '//',\n '// .pg → TypeScript typed attrs (orbit spec Appendix B.6), generated by',\n '// @modernrelay/orbit-omnigraph (`orbit-omnigraph-codegen`).',\n `// ${fingerprintLine}`,\n ];\n if (extra !== undefined && extra.length > 0) {\n for (const raw of extra.split('\\n')) {\n lines.push(raw.startsWith('//') ? raw : `// ${raw}`.trimEnd());\n }\n }\n lines.push(\n '//',\n \"// Shapes describe attrs AFTER the adapter's B.6 normalization (both read\",\n '// paths converge on the query-path string encodings):',\n \"// Date → 'YYYY-MM-DD' · DateTime → ISO 8601 · enum(...) → literal union\",\n '// I64/U64/F32/F64 → number · Vector(n) → number[] · T? → T | null',\n \"// Blob → string ('data:' URI for inline blobs, stored URI for external)\",\n '',\n );\n return lines;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Generate a self-contained TypeScript module of typed attrs from a parsed\n * `.pg` schema (B.6): one `<Name>Props` interface per node type, one\n * `<Name>EdgeProps` per edge type (suffixed so a node and an edge sharing a\n * name cannot collide), `NodeAttrs`/`EdgeAttrs` discriminated unions on the\n * adapter-injected `'orbit:type'` field, and a `TypeMap` lookup interface with\n * `NodeTypeName`/`EdgeTypeName` key unions.\n *\n * Deterministic: identical input (schema + options) yields identical output.\n */\nexport function generateTypes(schema: PgSchema, opts?: GenerateTypesOptions): string {\n const fingerprintLine =\n opts?.fingerprint !== undefined\n ? `Schema fingerprint: ${opts.fingerprint} (B.2).`\n : `Schema fingerprint: ${schemaFingerprint(JSON.stringify(schema))} (parsed model — regenerate from .pg source for the B.2 source fingerprint).`;\n const lines = headerBanner(fingerprintLine, opts?.header);\n\n const nodeMembers = schema.nodes.map((n) => ({\n typeName: n.name,\n interfaceName: `${n.name}Props`,\n }));\n const edgeMembers = schema.edges.map((e) => ({\n typeName: e.name,\n interfaceName: `${e.name}EdgeProps`,\n }));\n\n schema.nodes.forEach((n, i) => {\n const member = nodeMembers[i];\n if (member) emitPropsInterface(lines, member.interfaceName, 'node', n.name, n.properties);\n });\n schema.edges.forEach((e, i) => {\n const member = edgeMembers[i];\n if (member) emitPropsInterface(lines, member.interfaceName, 'edge', e.name, e.properties);\n });\n\n emitAttrsUnion(\n lines,\n 'NodeAttrs',\n \"Discriminated union over every node type's normalized attrs — `'orbit:type'` is injected by the adapter (B.3).\",\n nodeMembers,\n );\n emitAttrsUnion(\n lines,\n 'EdgeAttrs',\n \"Discriminated union over every edge type's normalized attrs — `'orbit:type'` is the edge name (B.3).\",\n edgeMembers,\n );\n\n lines.push('/** Type-name → props lookup for both kinds (closed sets from the schema — B.3). */');\n lines.push('export interface TypeMap {');\n lines.push(' nodes: {');\n for (const m of nodeMembers) lines.push(` ${propertyKey(m.typeName)}: ${m.interfaceName};`);\n lines.push(' };');\n lines.push(' edges: {');\n for (const m of edgeMembers) lines.push(` ${propertyKey(m.typeName)}: ${m.interfaceName};`);\n lines.push(' };');\n lines.push('}');\n lines.push('');\n lines.push(\"export type NodeTypeName = keyof TypeMap['nodes'];\");\n lines.push(\"export type EdgeTypeName = keyof TypeMap['edges'];\");\n lines.push('');\n return lines.join('\\n');\n}\n\n/**\n * Parse `.pg` source and generate typed attrs (see {@link generateTypes}),\n * stamping the header with the B.2 source fingerprint\n * ({@link schemaFingerprint} over the verbatim source).\n */\nexport function generateTypesFromPgSource(\n source: string,\n opts?: Omit<GenerateTypesOptions, 'fingerprint'>,\n): string {\n const schema = parsePgSchema(source);\n const options: GenerateTypesOptions = { fingerprint: schemaFingerprint(source) };\n if (opts?.header !== undefined) options.header = opts.header;\n return generateTypes(schema, options);\n}\n","#!/usr/bin/env node\n/**\n * `orbit-omnigraph-codegen` — minimal `.pg` → TypeScript codegen CLI (spec B.6).\n *\n * orbit-omnigraph-codegen <schema.pg> [-o out.ts]\n * orbit-omnigraph-codegen --from-server <baseUrl> --graph <id> [-o out.ts]\n *\n * The first form reads a `.pg` file; the second fetches the active schema\n * from a running omnigraph-server via a plain **unauthenticated** SDK client\n * (`og.schema.get()` returns the raw `.pg` source — B.6). Authenticated\n * client construction stays exclusively in the `/server` entry (B.1); point\n * this tool at an `--unauthenticated` server or a same-origin proxy.\n *\n * Without `-o`, the generated module goes to stdout.\n */\n\nimport { readFileSync, writeFileSync } from 'node:fs';\nimport process from 'node:process';\nimport { Omnigraph } from '@modernrelay/omnigraph';\nimport { generateTypesFromPgSource } from './codegen';\n\nconst USAGE = `Usage:\n orbit-omnigraph-codegen <schema.pg> [-o <out.ts>]\n orbit-omnigraph-codegen --from-server <baseUrl> --graph <id> [-o <out.ts>]\n\nGenerates TypeScript typed attrs (spec B.6) from a .pg schema — read from a\nfile, or fetched from a running omnigraph-server (unauthenticated client).\nWrites to stdout unless -o is given.\n`;\n\ninterface CliArgs {\n schemaPath?: string;\n out?: string;\n fromServer?: string;\n graph?: string;\n}\n\nfunction parseArgs(argv: readonly string[]): CliArgs | string {\n const args: CliArgs = {};\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === undefined) continue;\n switch (arg) {\n case '-h':\n case '--help':\n return 'help';\n case '-o':\n case '--out': {\n const v = argv[++i];\n if (v === undefined) return `missing value for ${arg}`;\n args.out = v;\n break;\n }\n case '--from-server': {\n const v = argv[++i];\n if (v === undefined) return 'missing value for --from-server';\n args.fromServer = v;\n break;\n }\n case '--graph': {\n const v = argv[++i];\n if (v === undefined) return 'missing value for --graph';\n args.graph = v;\n break;\n }\n default:\n if (arg.startsWith('-')) return `unknown option '${arg}'`;\n if (args.schemaPath !== undefined) return `unexpected argument '${arg}'`;\n args.schemaPath = arg;\n }\n }\n if (args.fromServer !== undefined && args.schemaPath !== undefined) {\n return 'pass a schema file OR --from-server, not both';\n }\n if (args.fromServer !== undefined && args.graph === undefined) {\n return '--from-server requires --graph <id> (schema reads are graph-scoped)';\n }\n if (args.fromServer === undefined && args.schemaPath === undefined) {\n return 'no schema given';\n }\n return args;\n}\n\nasync function main(argv: readonly string[]): Promise<number> {\n const parsed = parseArgs(argv);\n if (parsed === 'help') {\n process.stdout.write(USAGE);\n return 0;\n }\n if (typeof parsed === 'string') {\n process.stderr.write(`orbit-omnigraph-codegen: ${parsed}\\n\\n${USAGE}`);\n return 2;\n }\n\n let source: string;\n let provenance: string;\n if (parsed.fromServer !== undefined && parsed.graph !== undefined) {\n const og = new Omnigraph({ baseUrl: parsed.fromServer, graphId: parsed.graph });\n const schema = await og.schema.get();\n source = schema.schemaSource;\n provenance = `Source: ${parsed.fromServer} (graph '${parsed.graph}', GET /schema)`;\n } else if (parsed.schemaPath !== undefined) {\n source = readFileSync(parsed.schemaPath, 'utf8');\n provenance = `Source: ${parsed.schemaPath}`;\n } else {\n // Unreachable: parseArgs guarantees one of the two.\n return 2;\n }\n\n const output = generateTypesFromPgSource(source, { header: provenance });\n if (parsed.out !== undefined) {\n writeFileSync(parsed.out, output);\n process.stderr.write(`orbit-omnigraph-codegen: wrote ${parsed.out}\\n`);\n } else {\n process.stdout.write(output);\n }\n return 0;\n}\n\nmain(process.argv.slice(2)).then(\n (code) => {\n process.exitCode = code;\n },\n (err: unknown) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`orbit-omnigraph-codegen: ${message}\\n`);\n process.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AAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,yBAAA,EAA4B,OAAO;AAAA,CAAI,CAAA;AAC5D,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AAAA,EACrB;AACF,CAAA","file":"codegen-cli.js","sourcesContent":["/**\n * `.pg` → TypeScript code generation.\n *\n * The `.pg` scalar set is closed, so typed attrs for the `N`/`E` generics\n * generate mechanically: one interface per node/edge type, a `NodeAttrs` /\n * `EdgeAttrs` discriminated union on the adapter-injected `'orbit:type'`\n * field (namespaced so a schema's own `type` property emits as an ordinary\n * member), and a `TypeMap` lookup interface.\n *\n * Generated shapes describe attrs **after** the adapter's wire normalization\n * (the v1 loader rewrites export-path wire values to the query-path string\n * forms before populating attrs — see `normalize.ts`), so one encoding holds\n * regardless of read path:\n *\n * `Date` → `string` (`'YYYY-MM-DD'`)\n * `DateTime` → `string` (ISO 8601, `'YYYY-MM-DDTHH:MM:SS.mmmZ'`)\n * `enum(...)` → string-literal union\n * `I64`/`U64` → `number` (beware silent rounding past ±2^53)\n * `F32`/`F64` → `number`\n * `Vector(n)` → `number[]`\n * `Blob` → `string` (`data:` URI for inline blobs, stored URI refs verbatim)\n * `T?` → `T | null`\n *\n * Output is a self-contained module (no imports), safe under the strictest\n * tsconfig (`strict`, `exactOptionalPropertyTypes`, `verbatimModuleSyntax`,\n * `isolatedModules`). The file carries a DO-NOT-EDIT header with the\n * schema fingerprint. Generation is deterministic — no timestamps — so the\n * output is committable and diff-stable.\n *\n * Browser-safe: no `node:` imports (the CLI wrapper in `codegen-cli.ts` owns\n * file I/O).\n */\n\nimport { ORBIT_TYPE_KEY } from './normalize';\nimport {\n parsePgSchema,\n schemaFingerprint,\n type PgProperty,\n type PgScalarName,\n type PgSchema,\n type PgType,\n} from './pgSchema';\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\nexport interface GenerateTypesOptions {\n /**\n * Extra provenance lines for the DO-NOT-EDIT banner (e.g. the schema file\n * path or server URL). May be multi-line; lines are comment-prefixed as\n * needed.\n */\n header?: string;\n /**\n * The schema fingerprint of the `.pg` **source** (from\n * {@link schemaFingerprint}). When omitted, a fingerprint of the canonical\n * parsed model is used instead and labelled as such — prefer\n * {@link generateTypesFromPgSource}, which always stamps the source\n * fingerprint.\n */\n fingerprint?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Wire value → TypeScript mapping (post-normalization)\n// ---------------------------------------------------------------------------\n\nconst SCALAR_TS: Record<PgScalarName, string> = {\n String: 'string',\n Blob: 'string',\n Bool: 'boolean',\n I32: 'number',\n I64: 'number',\n U32: 'number',\n U64: 'number',\n F32: 'number',\n F64: 'number',\n Date: 'string',\n DateTime: 'string',\n};\n\n/** Single-quoted TS string literal with escapes. */\nfunction tsStringLiteral(value: string): string {\n return `'${value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\").replace(/\\r/g, '\\\\r').replace(/\\n/g, '\\\\n')}'`;\n}\n\nfunction tsType(type: PgType): string {\n if (typeof type === 'string') return SCALAR_TS[type];\n switch (type.kind) {\n case 'vector':\n return 'number[]';\n case 'enum':\n return type.values.length === 0 ? 'string' : type.values.map(tsStringLiteral).join(' | ');\n case 'list':\n return `${SCALAR_TS[type.element]}[]`;\n case 'unknown':\n return 'unknown';\n }\n}\n\n/** One-line doc note for types whose TS shape hides a wire subtlety. */\nfunction wireNote(type: PgType): string | null {\n if (typeof type === 'string') {\n switch (type) {\n case 'Date':\n return \"`Date` — normalized to 'YYYY-MM-DD' (UTC) on load.\";\n case 'DateTime':\n return '`DateTime` — normalized to ISO 8601 UTC on load.';\n case 'Blob':\n return \"`Blob` — `data:` URI for inline blobs, stored URI refs verbatim.\";\n case 'I64':\n case 'U64':\n return `\\`${type}\\` — JSON numbers round silently past ±2^53.`;\n default:\n return null;\n }\n }\n switch (type.kind) {\n case 'vector':\n return `\\`Vector(${type.dim})\\`.`;\n case 'unknown':\n return `Unrecognized \\`.pg\\` type \\`${type.raw}\\` — value passes through verbatim.`;\n default:\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Emission helpers\n// ---------------------------------------------------------------------------\n\nconst IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nfunction propertyKey(name: string): string {\n return IDENT_RE.test(name) ? name : tsStringLiteral(name);\n}\n\nfunction emitProperty(lines: string[], prop: PgProperty): void {\n const note = wireNote(prop.type);\n if (note !== null) lines.push(` /** ${note} */`);\n const base = tsType(prop.type);\n lines.push(` ${propertyKey(prop.name)}: ${prop.optional ? `${base} | null` : base};`);\n}\n\nfunction emitPropsInterface(\n lines: string[],\n interfaceName: string,\n kindLabel: 'node' | 'edge',\n typeName: string,\n properties: readonly PgProperty[],\n): void {\n lines.push(`/** Normalized attrs for ${kindLabel} type \\`${typeName}\\`. */`);\n lines.push(`export interface ${interfaceName} {`);\n if (!properties.some((p) => p.name === 'id')) {\n lines.push(\n ` /** Physical Omnigraph id — injected into every export line's \\`data\\`; unique per ${kindLabel} type only. */`,\n );\n lines.push(' id: string;');\n }\n for (const prop of properties) {\n // Every schema property emits normally — including one named `type`: the\n // adapter's discriminator lives at the namespaced ORBIT_TYPE_KEY, so\n // there is nothing to shadow.\n emitProperty(lines, prop);\n }\n lines.push('}');\n lines.push('');\n}\n\nfunction emitAttrsUnion(\n lines: string[],\n unionName: string,\n doc: string,\n members: ReadonlyArray<{ typeName: string; interfaceName: string }>,\n): void {\n lines.push(`/** ${doc} */`);\n if (members.length === 0) {\n lines.push(`export type ${unionName} = never;`);\n } else {\n lines.push(`export type ${unionName} =`);\n members.forEach(({ typeName, interfaceName }, i) => {\n const tail = i === members.length - 1 ? ';' : '';\n lines.push(\n ` | ({ ${tsStringLiteral(ORBIT_TYPE_KEY)}: ${tsStringLiteral(typeName)} } & ${interfaceName})${tail}`,\n );\n });\n }\n lines.push('');\n}\n\nfunction headerBanner(fingerprintLine: string, extra: string | undefined): string[] {\n const lines = [\n '// AUTO-GENERATED — DO NOT EDIT.',\n '//',\n '// .pg → TypeScript typed attrs (wire-normalized), generated by',\n '// @modernrelay/orbit-omnigraph (`orbit-omnigraph-codegen`).',\n `// ${fingerprintLine}`,\n ];\n if (extra !== undefined && extra.length > 0) {\n for (const raw of extra.split('\\n')) {\n lines.push(raw.startsWith('//') ? raw : `// ${raw}`.trimEnd());\n }\n }\n lines.push(\n '//',\n \"// Shapes describe attrs AFTER the adapter's wire normalization (both read\",\n '// paths converge on the query-path string encodings):',\n \"// Date → 'YYYY-MM-DD' · DateTime → ISO 8601 · enum(...) → literal union\",\n '// I64/U64/F32/F64 → number · Vector(n) → number[] · T? → T | null',\n \"// Blob → string ('data:' URI for inline blobs, stored URI for external)\",\n '',\n );\n return lines;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Generate a self-contained TypeScript module of typed attrs from a parsed\n * `.pg` schema: one `<Name>Props` interface per node type, one\n * `<Name>EdgeProps` per edge type (suffixed so a node and an edge sharing a\n * name cannot collide), `NodeAttrs`/`EdgeAttrs` discriminated unions on the\n * adapter-injected `'orbit:type'` field, and a `TypeMap` lookup interface with\n * `NodeTypeName`/`EdgeTypeName` key unions.\n *\n * Deterministic: identical input (schema + options) yields identical output.\n */\nexport function generateTypes(schema: PgSchema, opts?: GenerateTypesOptions): string {\n const fingerprintLine =\n opts?.fingerprint !== undefined\n ? `Schema fingerprint: ${opts.fingerprint}.`\n : `Schema fingerprint: ${schemaFingerprint(JSON.stringify(schema))} (parsed model — regenerate from .pg source for the source fingerprint).`;\n const lines = headerBanner(fingerprintLine, opts?.header);\n\n const nodeMembers = schema.nodes.map((n) => ({\n typeName: n.name,\n interfaceName: `${n.name}Props`,\n }));\n const edgeMembers = schema.edges.map((e) => ({\n typeName: e.name,\n interfaceName: `${e.name}EdgeProps`,\n }));\n\n schema.nodes.forEach((n, i) => {\n const member = nodeMembers[i];\n if (member) emitPropsInterface(lines, member.interfaceName, 'node', n.name, n.properties);\n });\n schema.edges.forEach((e, i) => {\n const member = edgeMembers[i];\n if (member) emitPropsInterface(lines, member.interfaceName, 'edge', e.name, e.properties);\n });\n\n emitAttrsUnion(\n lines,\n 'NodeAttrs',\n \"Discriminated union over every node type's normalized attrs — `'orbit:type'` is injected by the adapter.\",\n nodeMembers,\n );\n emitAttrsUnion(\n lines,\n 'EdgeAttrs',\n \"Discriminated union over every edge type's normalized attrs — `'orbit:type'` is the edge name.\",\n edgeMembers,\n );\n\n lines.push('/** Type-name → props lookup for both kinds (closed sets from the schema — the wire contract). */');\n lines.push('export interface TypeMap {');\n lines.push(' nodes: {');\n for (const m of nodeMembers) lines.push(` ${propertyKey(m.typeName)}: ${m.interfaceName};`);\n lines.push(' };');\n lines.push(' edges: {');\n for (const m of edgeMembers) lines.push(` ${propertyKey(m.typeName)}: ${m.interfaceName};`);\n lines.push(' };');\n lines.push('}');\n lines.push('');\n lines.push(\"export type NodeTypeName = keyof TypeMap['nodes'];\");\n lines.push(\"export type EdgeTypeName = keyof TypeMap['edges'];\");\n lines.push('');\n return lines.join('\\n');\n}\n\n/**\n * Parse `.pg` source and generate typed attrs (see {@link generateTypes}),\n * stamping the header with the source fingerprint\n * ({@link schemaFingerprint} over the verbatim source).\n */\nexport function generateTypesFromPgSource(\n source: string,\n opts?: Omit<GenerateTypesOptions, 'fingerprint'>,\n): string {\n const schema = parsePgSchema(source);\n const options: GenerateTypesOptions = { fingerprint: schemaFingerprint(source) };\n if (opts?.header !== undefined) options.header = opts.header;\n return generateTypes(schema, options);\n}\n","#!/usr/bin/env node\n/**\n * `orbit-omnigraph-codegen` — minimal `.pg` → TypeScript codegen CLI.\n *\n * orbit-omnigraph-codegen <schema.pg> [-o out.ts]\n * orbit-omnigraph-codegen --from-server <baseUrl> --graph <id> [-o out.ts]\n *\n * The first form reads a `.pg` file; the second fetches the active schema\n * from a running omnigraph-server via a plain **unauthenticated** SDK client\n * (`og.schema.get()` returns the raw `.pg` source). Authenticated client\n * construction stays exclusively in the `/server` entry; point\n * this tool at an `--unauthenticated` server or a same-origin proxy.\n *\n * Without `-o`, the generated module goes to stdout.\n */\n\nimport { readFileSync, writeFileSync } from 'node:fs';\nimport process from 'node:process';\nimport { Omnigraph } from '@modernrelay/omnigraph';\nimport { generateTypesFromPgSource } from './codegen';\n\nconst USAGE = `Usage:\n orbit-omnigraph-codegen <schema.pg> [-o <out.ts>]\n orbit-omnigraph-codegen --from-server <baseUrl> --graph <id> [-o <out.ts>]\n\nGenerates TypeScript typed attrs from a .pg schema — read from a\nfile, or fetched from a running omnigraph-server (unauthenticated client).\nWrites to stdout unless -o is given.\n`;\n\ninterface CliArgs {\n schemaPath?: string;\n out?: string;\n fromServer?: string;\n graph?: string;\n}\n\nfunction parseArgs(argv: readonly string[]): CliArgs | string {\n const args: CliArgs = {};\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === undefined) continue;\n switch (arg) {\n case '-h':\n case '--help':\n return 'help';\n case '-o':\n case '--out': {\n const v = argv[++i];\n if (v === undefined) return `missing value for ${arg}`;\n args.out = v;\n break;\n }\n case '--from-server': {\n const v = argv[++i];\n if (v === undefined) return 'missing value for --from-server';\n args.fromServer = v;\n break;\n }\n case '--graph': {\n const v = argv[++i];\n if (v === undefined) return 'missing value for --graph';\n args.graph = v;\n break;\n }\n default:\n if (arg.startsWith('-')) return `unknown option '${arg}'`;\n if (args.schemaPath !== undefined) return `unexpected argument '${arg}'`;\n args.schemaPath = arg;\n }\n }\n if (args.fromServer !== undefined && args.schemaPath !== undefined) {\n return 'pass a schema file OR --from-server, not both';\n }\n if (args.fromServer !== undefined && args.graph === undefined) {\n return '--from-server requires --graph <id> (schema reads are graph-scoped)';\n }\n if (args.fromServer === undefined && args.schemaPath === undefined) {\n return 'no schema given';\n }\n return args;\n}\n\nasync function main(argv: readonly string[]): Promise<number> {\n const parsed = parseArgs(argv);\n if (parsed === 'help') {\n process.stdout.write(USAGE);\n return 0;\n }\n if (typeof parsed === 'string') {\n process.stderr.write(`orbit-omnigraph-codegen: ${parsed}\\n\\n${USAGE}`);\n return 2;\n }\n\n let source: string;\n let provenance: string;\n if (parsed.fromServer !== undefined && parsed.graph !== undefined) {\n const og = new Omnigraph({ baseUrl: parsed.fromServer, graphId: parsed.graph });\n const schema = await og.schema.get();\n source = schema.schemaSource;\n provenance = `Source: ${parsed.fromServer} (graph '${parsed.graph}', GET /schema)`;\n } else if (parsed.schemaPath !== undefined) {\n source = readFileSync(parsed.schemaPath, 'utf8');\n provenance = `Source: ${parsed.schemaPath}`;\n } else {\n // Unreachable: parseArgs guarantees one of the two.\n return 2;\n }\n\n const output = generateTypesFromPgSource(source, { header: provenance });\n if (parsed.out !== undefined) {\n writeFileSync(parsed.out, output);\n process.stderr.write(`orbit-omnigraph-codegen: wrote ${parsed.out}\\n`);\n } else {\n process.stdout.write(output);\n }\n return 0;\n}\n\nmain(process.argv.slice(2)).then(\n (code) => {\n process.exitCode = code;\n },\n (err: unknown) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`orbit-omnigraph-codegen: ${message}\\n`);\n process.exitCode = 1;\n },\n);\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { GraphEdge, GraphNode, BeginIngestOptions, IngestSession, Revisions, Gra
|
|
|
2
2
|
import { Omnigraph } from '@modernrelay/omnigraph';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Identity codec
|
|
5
|
+
* Identity codec.
|
|
6
6
|
*
|
|
7
7
|
* Omnigraph node ids are unique **per type only** (derived from the `@key`
|
|
8
8
|
* tuple within each type's table), so unqualified ids are unsound as orbit
|
|
@@ -13,7 +13,7 @@ import { Omnigraph } from '@modernrelay/omnigraph';
|
|
|
13
13
|
* no `(kind, sourceId)` pair can collide with a different pair.
|
|
14
14
|
*
|
|
15
15
|
* Human-readable labels stay separate from identity; there is deliberately no
|
|
16
|
-
* `namespaceIds:false` escape hatch
|
|
16
|
+
* `namespaceIds:false` escape hatch.
|
|
17
17
|
*/
|
|
18
18
|
interface DecodedSourceId {
|
|
19
19
|
/** The namespace component: a node type name or an edge type name. */
|
|
@@ -26,7 +26,7 @@ interface DecodedSourceId {
|
|
|
26
26
|
*
|
|
27
27
|
* - Nodes: `encodeSourceId(NodeType, data.id)`
|
|
28
28
|
* - Edges: `encodeSourceId(EdgeName, data.id)`; endpoints use
|
|
29
|
-
*
|
|
29
|
+
* `encodeSourceId(endpointType, from|to)`.
|
|
30
30
|
*/
|
|
31
31
|
declare function encodeSourceId(kind: string, sourceId: string): string;
|
|
32
32
|
/**
|
|
@@ -38,16 +38,16 @@ declare function encodeSourceId(kind: string, sourceId: string): string;
|
|
|
38
38
|
*/
|
|
39
39
|
declare function decodeSourceId(id: string): DecodedSourceId | null;
|
|
40
40
|
/**
|
|
41
|
-
* Synthetic edge id for **query-derived** subgraphs
|
|
41
|
+
* Synthetic edge id for **query-derived** subgraphs.
|
|
42
42
|
*
|
|
43
43
|
* The GQ grammar has no edge variable, so the query path can never surface
|
|
44
44
|
* physical edge ids; query-derived edges are identified by
|
|
45
45
|
* `['synthetic-edge', EdgeName, source, target]` where `source`/`target` are
|
|
46
46
|
* the already-encoded endpoint node ids.
|
|
47
47
|
*
|
|
48
|
-
* Exported for the future query path
|
|
49
|
-
* Caveats
|
|
50
|
-
* MUST NOT mix synthetic ids with physical `/export` ids for the same edges
|
|
48
|
+
* Exported for the future query path.
|
|
49
|
+
* Caveats: parallel edges collapse under this scheme, and a dataset
|
|
50
|
+
* MUST NOT mix synthetic ids with physical `/export` ids for the same edges
|
|
51
51
|
* one scheme per dataset, never both. Because a synthetic id is a 4-tuple,
|
|
52
52
|
* {@link decodeSourceId} rejects it (`null`), keeping the two schemes
|
|
53
53
|
* mechanically un-confusable.
|
|
@@ -55,13 +55,13 @@ declare function decodeSourceId(id: string): DecodedSourceId | null;
|
|
|
55
55
|
declare function encodeSyntheticEdgeId(edgeName: string, source: string, target: string): string;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* `.pg` schema model + tolerant parser
|
|
58
|
+
* `.pg` schema model + tolerant parser.
|
|
59
59
|
*
|
|
60
60
|
* The adapter needs three things from the graph schema, all served here:
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
61
|
+
* 1. edge endpoint-type resolution (export edge lines carry bare `from`/`to`
|
|
62
|
+
* ids without endpoint types),
|
|
63
|
+
* 2. per-property wire-type knowledge for temporal/blob normalization,
|
|
64
|
+
* 3. a stable schema fingerprint for the export revision stamp.
|
|
65
65
|
*
|
|
66
66
|
* The parser is deliberately tolerant: it extracts the declarations it
|
|
67
67
|
* understands (interfaces, node blocks, edge declarations, properties,
|
|
@@ -141,7 +141,7 @@ interface PgSchema {
|
|
|
141
141
|
*/
|
|
142
142
|
declare function parsePgSchema(source: string): PgSchema;
|
|
143
143
|
/**
|
|
144
|
-
* Resolve an edge type's declared endpoint node types
|
|
144
|
+
* Resolve an edge type's declared endpoint node types. Export edge
|
|
145
145
|
* lines carry bare `from`/`to` ids, so endpoint types come from here. Edge
|
|
146
146
|
* names match exactly first, then case-insensitively (the server matches edge
|
|
147
147
|
* names case-insensitively). Returns `null` for an unknown edge name.
|
|
@@ -151,7 +151,7 @@ declare function edgeEndpointTypes(schema: PgSchema, edgeName: string): {
|
|
|
151
151
|
to: string;
|
|
152
152
|
} | null;
|
|
153
153
|
/**
|
|
154
|
-
* Stable fingerprint of `.pg` source for the
|
|
154
|
+
* Stable fingerprint of `.pg` source for the adapter revision stamp: FNV-1a
|
|
155
155
|
* 64-bit over the UTF-8 bytes of the source, as 16 lowercase hex chars.
|
|
156
156
|
*
|
|
157
157
|
* Pure and browser-safe (no `node:crypto`). Hashes the source **verbatim**:
|
|
@@ -166,44 +166,44 @@ interface BigIntKeyWarning {
|
|
|
166
166
|
property: string;
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
169
|
+
* Find `I64`/`U64` properties used as identity (`@key` or named `id`). The
|
|
170
|
+
* HTTP path emits native JSON numbers even past ±2^53, where `JSON.parse`
|
|
171
|
+
* silently rounds them, so two distinct big-int ids can collapse. Surface
|
|
172
|
+
* these hazards before loading.
|
|
173
173
|
*/
|
|
174
174
|
declare function bigIntKeyWarnings(schema: PgSchema): BigIntKeyWarning[];
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
* Export-line classification and normalization
|
|
177
|
+
* Export-line classification and normalization.
|
|
178
178
|
*
|
|
179
179
|
* `/export` streams NDJSON — one JSON object per line, `data` passed through
|
|
180
180
|
* **verbatim** by the SDK. This module turns those lines into orbit
|
|
181
181
|
* `GraphNode`/`GraphEdge` values:
|
|
182
182
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
183
|
+
* - ids are namespaced through the adapter identity codec (`encodeSourceId`),
|
|
184
|
+
* - the node/edge KIND is injected as {@link ORBIT_TYPE_KEY} — namespaced so
|
|
185
|
+
* a schema's own `type` property passes through as ordinary data,
|
|
186
|
+
* - edge endpoint types are resolved from the `.pg` schema because edge lines
|
|
187
|
+
* carry bare `from`/`to` ids,
|
|
188
|
+
* - attr values are normalized to the query-path string forms so
|
|
189
|
+
* generated types and temporal dimensions see one encoding
|
|
190
|
+
* regardless of read path:
|
|
191
|
+
* * `Date` — export sends **days since Unix epoch** (number) →
|
|
192
|
+
* `'YYYY-MM-DD'` (UTC)
|
|
193
|
+
* * `DateTime` — export sends **epoch milliseconds** (number) →
|
|
194
|
+
* ISO 8601 (`'YYYY-MM-DDTHH:MM:SS.mmmZ'`)
|
|
195
|
+
* * `Blob` — inline internal blobs arrive as `'base64:<data>'` →
|
|
196
|
+
* `'data:application/octet-stream;base64,<data>'`;
|
|
197
|
+
* external-URI refs pass through verbatim
|
|
198
|
+
* * everything else — verbatim.
|
|
199
199
|
*
|
|
200
200
|
* Non-finite float sentinels (`'NaN'`/`'Infinity'`/`'-Infinity'`) are a
|
|
201
201
|
* **query-path-only** encoding: a non-finite stored float aborts `/export`
|
|
202
|
-
* server-side, so export-loaded data never contains the sentinels
|
|
202
|
+
* server-side, so export-loaded data never contains the sentinels.
|
|
203
203
|
* This module therefore does NOT special-case them.
|
|
204
204
|
*/
|
|
205
205
|
|
|
206
|
-
/** An edge line names an edge type the `.pg` schema does not declare
|
|
206
|
+
/** An edge line names an edge type the `.pg` schema does not declare. */
|
|
207
207
|
declare class UnknownEdgeTypeError extends Error {
|
|
208
208
|
readonly name = "UnknownEdgeTypeError";
|
|
209
209
|
readonly edgeName: string;
|
|
@@ -230,14 +230,14 @@ type ClassifiedExportLine = NodeExportLine | EdgeExportLine | {
|
|
|
230
230
|
kind: 'unknown';
|
|
231
231
|
};
|
|
232
232
|
/**
|
|
233
|
-
* Classify one parsed export line
|
|
234
|
-
*
|
|
235
|
-
*
|
|
233
|
+
* Classify one parsed export line using the adapter's wire shapes:
|
|
234
|
+
* - node line: `{"type": "<NodeType>", "data": {"id", …props}}`
|
|
235
|
+
* - edge line: `{"edge": "<EdgeName>", "from": <src id>, "to": <dst id>, "data": {"id", …props}}`
|
|
236
236
|
* Anything else is `{ kind: 'unknown' }`.
|
|
237
237
|
*/
|
|
238
238
|
declare function classifyExportLine(line: unknown): ClassifiedExportLine;
|
|
239
239
|
/**
|
|
240
|
-
* The adapter's node/edge KIND discriminator key
|
|
240
|
+
* The adapter's node/edge KIND discriminator key.
|
|
241
241
|
*
|
|
242
242
|
* Namespaced on purpose: the adapter injects this field into someone else's
|
|
243
243
|
* data, so it takes the awkward key and leaves the generic word `type` to the
|
|
@@ -252,8 +252,8 @@ declare const ORBIT_TYPE_KEY = "orbit:type";
|
|
|
252
252
|
/**
|
|
253
253
|
* Normalize a node export line to a `GraphNode`:
|
|
254
254
|
* `id = encodeSourceId(type, data.id)`, `attrs = { …data, 'orbit:type' }`
|
|
255
|
-
* with
|
|
256
|
-
*
|
|
255
|
+
* with value normalization driven by the schema's property types. A node type
|
|
256
|
+
* absent from the schema is tolerated — its attrs pass through verbatim
|
|
257
257
|
* (identity never needs the schema on the node path).
|
|
258
258
|
*/
|
|
259
259
|
declare function normalizeNode(line: {
|
|
@@ -263,8 +263,8 @@ declare function normalizeNode(line: {
|
|
|
263
263
|
/**
|
|
264
264
|
* Normalize an edge export line to a `GraphEdge`:
|
|
265
265
|
* `id = encodeSourceId(edge, data.id)`; `source`/`target` namespace the bare
|
|
266
|
-
* `from`/`to` ids with the endpoint node types resolved from the schema
|
|
267
|
-
*
|
|
266
|
+
* `from`/`to` ids with the endpoint node types resolved from the schema.
|
|
267
|
+
* Throws {@link UnknownEdgeTypeError} when the schema does not declare
|
|
268
268
|
* the edge — endpoint identity cannot be constructed without it.
|
|
269
269
|
*/
|
|
270
270
|
declare function normalizeEdge(line: {
|
|
@@ -275,14 +275,14 @@ declare function normalizeEdge(line: {
|
|
|
275
275
|
}, schema: PgSchema): GraphEdge;
|
|
276
276
|
|
|
277
277
|
/**
|
|
278
|
-
* Public types for the v1 export loader
|
|
278
|
+
* Public types for the v1 export loader.
|
|
279
279
|
*
|
|
280
|
-
* The organizing rule of the v1 adapter
|
|
281
|
-
* queries only ever resolve ids. These types describe that one load path
|
|
280
|
+
* The organizing rule of the v1 adapter: graphs load via `og.export()`;
|
|
281
|
+
* queries only ever resolve ids. These types describe that one load path
|
|
282
282
|
* its options, its ingestion target seam, and its revision-stamped result.
|
|
283
283
|
*/
|
|
284
284
|
|
|
285
|
-
/** Cumulative progress, reported after every appended batch
|
|
285
|
+
/** Cumulative progress, reported after every appended batch. */
|
|
286
286
|
interface OmnigraphLoadProgress {
|
|
287
287
|
/** Export lines consumed so far (nodes + edges + skipped unknowns). */
|
|
288
288
|
lines: number;
|
|
@@ -294,33 +294,33 @@ interface OmnigraphLoadProgress {
|
|
|
294
294
|
bytes: number;
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
297
|
+
* Revision-stamp drift policy: what to do when the branch head observed after
|
|
298
|
+
* the export stream differs from the head observed before it.
|
|
299
299
|
*
|
|
300
300
|
* - `'reject'` (default): abort the session and throw — the graph is left
|
|
301
|
-
*
|
|
301
|
+
* untouched. The right choice for durable/shareable sessions.
|
|
302
302
|
* - `'accept-warn'`: buffer the export, then commit under the canonical final
|
|
303
|
-
*
|
|
304
|
-
*
|
|
303
|
+
* revision once `headAfter` is known; both heads are recorded in `dataRef`
|
|
304
|
+
* and a warning is added when they differ.
|
|
305
305
|
* - `'retry-once'`: abort, restart the whole load once; a second drift
|
|
306
|
-
*
|
|
306
|
+
* rejects.
|
|
307
307
|
*/
|
|
308
308
|
type OmnigraphDriftPolicy = 'reject' | 'accept-warn' | 'retry-once';
|
|
309
309
|
interface OmnigraphSourceOptions {
|
|
310
310
|
/**
|
|
311
311
|
* A **preconfigured** SDK client. In the browser this must be a safe
|
|
312
312
|
* same-origin or public client — this option surface deliberately accepts
|
|
313
|
-
* no `baseUrl`/`token` pair
|
|
313
|
+
* no `baseUrl`/`token` pair: authenticated client construction lives
|
|
314
314
|
* ONLY in `@modernrelay/orbit-omnigraph/server`
|
|
315
315
|
* (`createOmnigraphServerClient`), which is excluded from client bundles.
|
|
316
316
|
*/
|
|
317
317
|
client: Omnigraph;
|
|
318
318
|
/** Cluster graph id; every call is scoped to it via `client.graph(graphId)`. */
|
|
319
319
|
graphId: string;
|
|
320
|
-
/** Branch to export
|
|
320
|
+
/** Branch to export. Default `'main'`. */
|
|
321
321
|
branch?: string;
|
|
322
322
|
/**
|
|
323
|
-
* Partial per-type load
|
|
323
|
+
* Partial per-type load: forwarded as the SDK `ExportInput.typeNames`
|
|
324
324
|
* field (wire form `type_names`). Omit to export every table.
|
|
325
325
|
*/
|
|
326
326
|
typeNames?: readonly string[];
|
|
@@ -330,17 +330,17 @@ interface OmnigraphSourceOptions {
|
|
|
330
330
|
* Whole-load byte budget for the atomic replace. Because atomic staging
|
|
331
331
|
* cannot drain before commit, exceeding this finite cap aborts the load
|
|
332
332
|
* without publishing a partial graph. Must be a positive safe integer.
|
|
333
|
-
* Default
|
|
333
|
+
* Default 512 MiB.
|
|
334
334
|
*/
|
|
335
335
|
maxPendingBytes?: number;
|
|
336
|
-
/**
|
|
336
|
+
/** Revision-stamp drift policy. Default `'reject'`. */
|
|
337
337
|
driftPolicy?: OmnigraphDriftPolicy;
|
|
338
338
|
/** Called after every appended batch with cumulative counts. */
|
|
339
339
|
onProgress?: (p: OmnigraphLoadProgress) => void;
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
342
|
-
*
|
|
343
|
-
* canonical `sourceRevision` hash
|
|
342
|
+
* Branch-based view-state `dataRef`. This is the readable object behind the
|
|
343
|
+
* canonical `sourceRevision` hash, retained so hosts can display or persist the
|
|
344
344
|
* exact coordinates a session was loaded from. `headBefore !== headAfter`
|
|
345
345
|
* only ever appears under `driftPolicy: 'accept-warn'`.
|
|
346
346
|
*/
|
|
@@ -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: two partial exports at the same head
|
|
359
|
+
* 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;
|
|
@@ -363,9 +369,9 @@ interface OmnigraphLoadCounts {
|
|
|
363
369
|
}
|
|
364
370
|
interface OmnigraphLoadResult {
|
|
365
371
|
/**
|
|
366
|
-
* The committed source coordinate: the canonical hash of `dataRef
|
|
372
|
+
* The committed source coordinate: the canonical hash of `dataRef`.
|
|
367
373
|
* Stable across identical replays — a second load of a quiescent branch
|
|
368
|
-
* commits idempotently (
|
|
374
|
+
* commits idempotently (the same `{datasetKey, sourceRevision}` publishes
|
|
369
375
|
* nothing).
|
|
370
376
|
*/
|
|
371
377
|
sourceRevision: string;
|
|
@@ -374,14 +380,14 @@ interface OmnigraphLoadResult {
|
|
|
374
380
|
/** `og.health().version` — the server build the load ran against. */
|
|
375
381
|
serverVersion: string;
|
|
376
382
|
/**
|
|
377
|
-
* Non-fatal observations: SDK/server major.minor mismatch
|
|
378
|
-
* drift
|
|
383
|
+
* Non-fatal observations: SDK/server major.minor mismatch, accepted
|
|
384
|
+
* drift, big-int identity hazards, and skipped unknown lines. Never
|
|
379
385
|
* hides a retry or accepted-drift decision.
|
|
380
386
|
*/
|
|
381
387
|
warnings: string[];
|
|
382
388
|
}
|
|
383
389
|
/**
|
|
384
|
-
* Minimal structural ingestion target
|
|
390
|
+
* Minimal structural ingestion target — deliberately decoupled from
|
|
385
391
|
* `GraphInstance`. The loader needs exactly the ingest seam and nothing else,
|
|
386
392
|
* so any object with these members works: a real `GraphInstance` (which
|
|
387
393
|
* satisfies this interface structurally), a recorder, or a headless pipeline.
|
|
@@ -393,47 +399,47 @@ interface IngestTarget {
|
|
|
393
399
|
}
|
|
394
400
|
|
|
395
401
|
/**
|
|
396
|
-
* v1 export loader
|
|
402
|
+
* v1 export loader.
|
|
397
403
|
*
|
|
398
|
-
* The organizing rule
|
|
404
|
+
* The organizing rule: graphs load via `og.export` — one streamed
|
|
399
405
|
* NDJSON pass, edge lines first (lexicographic table-key order), driven
|
|
400
406
|
* straight into a `purpose:'replace'` ingest session on the target. Queries
|
|
401
407
|
* never introduce nodes or edges.
|
|
402
408
|
*
|
|
403
|
-
* Revision stamp
|
|
404
|
-
* `{ graphId, branch, headBefore, headAfter, schemaFingerprint }
|
|
409
|
+
* Revision stamp: the canonical `sourceRevision` hashes
|
|
410
|
+
* `{ graphId, branch, headBefore, headAfter, schemaFingerprint }` (plus the
|
|
411
|
+
* sorted `typeNames` subset when the export is partial), 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
|
|
408
415
|
* begins under the PROVISIONAL revision (the canonical hash with
|
|
409
|
-
* `headAfter
|
|
410
|
-
* captured BEFORE `commit
|
|
416
|
+
* `headAfter:= headBefore`), the stream appends into it, and `headAfter` is
|
|
417
|
+
* captured BEFORE `commit`. `accept-warn` is the exception: normalized
|
|
411
418
|
* batches are buffered until `headAfter` is known, then appended once into a
|
|
412
419
|
* session opened with the canonical FINAL revision:
|
|
413
420
|
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
421
|
+
* - equal heads → provisional === final; commit cleanly. The session only
|
|
422
|
+
* ever commits a revision whose hash is truthful.
|
|
423
|
+
* - drifted heads → `driftPolicy` decides: `'reject'` aborts the session
|
|
424
|
+
* (graph untouched) and throws {@link OmnigraphDriftError};
|
|
425
|
+
* `'accept-warn'` commits the buffered export under the
|
|
426
|
+
* final revision, records BOTH heads in `dataRef`, and
|
|
427
|
+
* adds a warning;
|
|
428
|
+
* `'retry-once'` aborts and restarts the whole load once
|
|
429
|
+
* (a second drift rejects).
|
|
423
430
|
*
|
|
424
431
|
* This is sound because a replace session is atomic and invisible until
|
|
425
|
-
* commit
|
|
432
|
+
* commit: nothing is published under a revision the policy did not
|
|
426
433
|
* explicitly accept.
|
|
427
434
|
*
|
|
428
|
-
* Error surface
|
|
435
|
+
* Error surface: SDK typed errors never cross this package's public
|
|
429
436
|
* surface — they are mapped to plain `Error`s with a stable `omnigraph:`
|
|
430
437
|
* message prefix.
|
|
431
438
|
*/
|
|
432
439
|
|
|
433
440
|
/**
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* session was aborted, and the target graph is untouched.
|
|
441
|
+
* Raised when a branch moves during export and the configured drift policy
|
|
442
|
+
* rejects the load. The session is aborted and the target graph is untouched.
|
|
437
443
|
*/
|
|
438
444
|
declare class OmnigraphDriftError extends Error {
|
|
439
445
|
readonly name = "OmnigraphDriftError";
|
|
@@ -443,7 +449,7 @@ declare class OmnigraphDriftError extends Error {
|
|
|
443
449
|
readonly headAfter: string;
|
|
444
450
|
constructor(graphId: string, branch: string, headBefore: string, headAfter: string);
|
|
445
451
|
}
|
|
446
|
-
/** The one load path a v1 source exposes
|
|
452
|
+
/** The one load path a v1 source exposes. */
|
|
447
453
|
interface OmnigraphSource {
|
|
448
454
|
/**
|
|
449
455
|
* Stream one export of the configured graph/branch into `target` via a
|
|
@@ -454,26 +460,26 @@ interface OmnigraphSource {
|
|
|
454
460
|
load(target: IngestTarget, signal?: AbortSignal): Promise<OmnigraphLoadResult>;
|
|
455
461
|
}
|
|
456
462
|
/**
|
|
457
|
-
* Create a v1 export-backed data source
|
|
458
|
-
* preconfigured
|
|
463
|
+
* Create a v1 export-backed data source. The client must be
|
|
464
|
+
* preconfigured. In the browser, use a safe same-origin or public client;
|
|
459
465
|
* there is deliberately no `baseUrl`/`token` option here. Authenticated
|
|
460
466
|
* construction lives only in `@modernrelay/orbit-omnigraph/server`.
|
|
461
467
|
*/
|
|
462
468
|
declare function createOmnigraphSource(options: OmnigraphSourceOptions): OmnigraphSource;
|
|
463
469
|
|
|
464
470
|
/**
|
|
465
|
-
*
|
|
471
|
+
* Stored-query `SearchService` integration.
|
|
466
472
|
*
|
|
467
473
|
* A stored query using `bm25`/`fuzzy`/`nearest`/`rrf` with
|
|
468
474
|
* `order { score desc } limit K` returns entity rows plus a score column; this
|
|
469
|
-
* module wires it as a
|
|
475
|
+
* module wires it as a `SearchService` via
|
|
470
476
|
* `og.queries.invoke(name, { params, branch })`, passing
|
|
471
477
|
* `RequestContext.signal` through SDK `CallOptions`. Core performs revision
|
|
472
478
|
* admission — the service only declares `revisionDependencies: ['source']`
|
|
473
479
|
* (results come from the server-side branch, so they are invalidated by a
|
|
474
480
|
* source change, never by client-side model/scope drift).
|
|
475
481
|
*
|
|
476
|
-
* Identity
|
|
482
|
+
* Identity: Omnigraph ids are unique per type only, and a query row
|
|
477
483
|
* carries no type discriminator of its own — so the adapter REQUIRES a
|
|
478
484
|
* caller-supplied column→node-type mapping (`typeOf`), either a
|
|
479
485
|
* `{ column: NodeType }` record keyed by the projection columns that hold
|
|
@@ -482,12 +488,13 @@ declare function createOmnigraphSource(options: OmnigraphSourceOptions): Omnigra
|
|
|
482
488
|
* every other adapter path uses — so results round-trip `decodeSourceId` and
|
|
483
489
|
* match export-loaded node ids exactly.
|
|
484
490
|
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* classifies those as `'not-loaded'
|
|
488
|
-
* query to the loaded types, or load the full graph, to avoid the
|
|
491
|
+
* Partial-load caveat: search runs server-side over the whole branch, so a
|
|
492
|
+
* partial export load can return ids outside the loaded set.
|
|
493
|
+
* `activateSearchResult` classifies those as `'not-loaded'`; constrain the
|
|
494
|
+
* stored query to the loaded types, or load the full graph, to avoid the
|
|
495
|
+
* mismatch.
|
|
489
496
|
*
|
|
490
|
-
* Error surface
|
|
497
|
+
* Error surface: SDK typed errors never cross this package's public
|
|
491
498
|
* surface — they rethrow as plain `Error`s with the stable `omnigraph:`
|
|
492
499
|
* prefix. Abort rejections pass through unchanged.
|
|
493
500
|
*/
|
|
@@ -496,44 +503,44 @@ declare function createOmnigraphSource(options: OmnigraphSourceOptions): Omnigra
|
|
|
496
503
|
* projections (`return { $s }`) hold whole-node structs including `id`. */
|
|
497
504
|
type OmnigraphSearchRow = Record<string, unknown>;
|
|
498
505
|
/**
|
|
499
|
-
* The required
|
|
506
|
+
* The required column→node-type mapping:
|
|
500
507
|
*
|
|
501
508
|
* - a record `{ '$s': 'Signal' }` — the FIRST listed column present in a row
|
|
502
|
-
*
|
|
503
|
-
*
|
|
509
|
+
* with a node struct supplies the physical id, encoded under the mapped
|
|
510
|
+
* type name;
|
|
504
511
|
* - or a per-row function returning the node type name — the row's first
|
|
505
|
-
*
|
|
512
|
+
* node-struct column (row key order) supplies the physical id.
|
|
506
513
|
*/
|
|
507
514
|
type OmnigraphSearchTypeOf = ((row: OmnigraphSearchRow) => string) | Readonly<Record<string, string>>;
|
|
508
515
|
interface OmnigraphSearchServiceOptions<N = Record<string, unknown>> {
|
|
509
|
-
/** A **preconfigured** SDK client
|
|
516
|
+
/** A **preconfigured** SDK client — no `baseUrl`/`token` here. */
|
|
510
517
|
client: Omnigraph;
|
|
511
518
|
/** Cluster graph id; the invoke is scoped via `client.graph(graphId)`. */
|
|
512
519
|
graphId: string;
|
|
513
|
-
/** Branch the stored query reads
|
|
520
|
+
/** Branch the stored query reads. Default `'main'`. */
|
|
514
521
|
branch?: string;
|
|
515
522
|
/** Registry name of the stored search query (`POST /queries/{name}`).
|
|
516
523
|
* Invoking a known name works whether or not it is `mcp.expose`d. */
|
|
517
524
|
queryName: string;
|
|
518
|
-
/** Builds the stored query's `params` object from the
|
|
525
|
+
/** Builds the stored query's `params` object from the call.
|
|
519
526
|
* Default: `(q, limit) => ({ q, limit })`. */
|
|
520
527
|
params?: (q: string, limit: number) => Record<string, unknown>;
|
|
521
|
-
/** REQUIRED
|
|
528
|
+
/** REQUIRED mapping from row to node type — see
|
|
522
529
|
* {@link OmnigraphSearchTypeOf}. */
|
|
523
530
|
typeOf: OmnigraphSearchTypeOf;
|
|
524
|
-
/** Column whose value becomes `label` (String
|
|
531
|
+
/** Column whose value becomes `label` (String-coerced when present).
|
|
525
532
|
* Default: the first string-valued column in row key order. */
|
|
526
533
|
labelColumn?: string;
|
|
527
534
|
/** Full custom row→result escape hatch: overrides the default mapping
|
|
528
535
|
* (including `typeOf`/`labelColumn`); return `null` to skip a row. The
|
|
529
|
-
* returned `id` MUST already be
|
|
536
|
+
* returned `id` MUST already be type-qualified via `encodeSourceId`. */
|
|
530
537
|
mapRow?: (row: OmnigraphSearchRow) => SearchResult<N> | null;
|
|
531
538
|
}
|
|
532
539
|
/**
|
|
533
|
-
* Create the
|
|
540
|
+
* Create the stored-query search service. Plug it into core as
|
|
534
541
|
* `services.search`; the instance owns `RequestContext` creation,
|
|
535
542
|
* revision-keyed caching, supersede cancellation, and stale-result rejection
|
|
536
|
-
* at admission
|
|
543
|
+
* at admission.
|
|
537
544
|
*/
|
|
538
545
|
declare function createOmnigraphSearchService<N = Record<string, unknown>>(options: OmnigraphSearchServiceOptions<N>): SearchService<N>;
|
|
539
546
|
|