@nicia-ai/typegraph 0.24.0 → 0.25.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.
Files changed (159) hide show
  1. package/dist/backend/postgres/index.cjs +178 -55
  2. package/dist/backend/postgres/index.cjs.map +1 -1
  3. package/dist/backend/postgres/index.d.cts +6 -7
  4. package/dist/backend/postgres/index.d.ts +6 -7
  5. package/dist/backend/postgres/index.js +151 -28
  6. package/dist/backend/postgres/index.js.map +1 -1
  7. package/dist/backend/sqlite/index.cjs +19 -17
  8. package/dist/backend/sqlite/index.d.cts +6 -7
  9. package/dist/backend/sqlite/index.d.ts +6 -7
  10. package/dist/backend/sqlite/index.js +9 -7
  11. package/dist/backend/sqlite/libsql.cjs +12 -10
  12. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  13. package/dist/backend/sqlite/libsql.d.cts +4 -5
  14. package/dist/backend/sqlite/libsql.d.ts +4 -5
  15. package/dist/backend/sqlite/libsql.js +9 -7
  16. package/dist/backend/sqlite/libsql.js.map +1 -1
  17. package/dist/backend/sqlite/local.cjs +14 -12
  18. package/dist/backend/sqlite/local.cjs.map +1 -1
  19. package/dist/backend/sqlite/local.d.cts +4 -5
  20. package/dist/backend/sqlite/local.d.ts +4 -5
  21. package/dist/backend/sqlite/local.js +9 -7
  22. package/dist/backend/sqlite/local.js.map +1 -1
  23. package/dist/chunk-4BOWVUGQ.js +2029 -0
  24. package/dist/chunk-4BOWVUGQ.js.map +1 -0
  25. package/dist/{chunk-RNUNP5JD.cjs → chunk-7CDXX3QZ.cjs} +2 -2
  26. package/dist/chunk-7CDXX3QZ.cjs.map +1 -0
  27. package/dist/chunk-7V335GHG.cjs +112 -0
  28. package/dist/chunk-7V335GHG.cjs.map +1 -0
  29. package/dist/chunk-7W3KAMVQ.cjs +2678 -0
  30. package/dist/chunk-7W3KAMVQ.cjs.map +1 -0
  31. package/dist/chunk-CTHNVU6K.cjs +551 -0
  32. package/dist/chunk-CTHNVU6K.cjs.map +1 -0
  33. package/dist/chunk-D2GO3RBL.cjs +12 -0
  34. package/dist/chunk-D2GO3RBL.cjs.map +1 -0
  35. package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
  36. package/dist/chunk-DOTEN2FG.js.map +1 -0
  37. package/dist/chunk-E5JZSEGJ.cjs +301 -0
  38. package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
  39. package/dist/chunk-EG6TJ3I5.js +286 -0
  40. package/dist/chunk-EG6TJ3I5.js.map +1 -0
  41. package/dist/chunk-EJCDOA37.js +537 -0
  42. package/dist/chunk-EJCDOA37.js.map +1 -0
  43. package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
  44. package/dist/chunk-EK6RJ373.cjs.map +1 -0
  45. package/dist/{chunk-7TU5EWQ7.js → chunk-FPCOUJSL.js} +2 -2
  46. package/dist/chunk-FPCOUJSL.js.map +1 -0
  47. package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
  48. package/dist/chunk-JTI5WT4P.cjs.map +1 -0
  49. package/dist/chunk-LVCSL6A3.js +2626 -0
  50. package/dist/chunk-LVCSL6A3.js.map +1 -0
  51. package/dist/chunk-NHQWXSTS.js +10 -0
  52. package/dist/chunk-NHQWXSTS.js.map +1 -0
  53. package/dist/chunk-NZ5PMBTG.js +105 -0
  54. package/dist/chunk-NZ5PMBTG.js.map +1 -0
  55. package/dist/{chunk-5HVDOPZU.cjs → chunk-O2P3KAUT.cjs} +416 -93
  56. package/dist/chunk-O2P3KAUT.cjs.map +1 -0
  57. package/dist/{chunk-GTG5J4UP.js → chunk-OJ6IQVZG.js} +151 -13
  58. package/dist/chunk-OJ6IQVZG.js.map +1 -0
  59. package/dist/{chunk-EYELZHKY.js → chunk-OOS2RKRH.js} +5 -140
  60. package/dist/chunk-OOS2RKRH.js.map +1 -0
  61. package/dist/chunk-RCAJZG67.cjs +2069 -0
  62. package/dist/chunk-RCAJZG67.cjs.map +1 -0
  63. package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
  64. package/dist/chunk-W5MTHMTE.cjs.map +1 -0
  65. package/dist/{chunk-EY4LBX3F.js → chunk-WI5VRP3X.js} +337 -26
  66. package/dist/chunk-WI5VRP3X.js.map +1 -0
  67. package/dist/chunk-WVQXAFP3.js +79 -0
  68. package/dist/chunk-WVQXAFP3.js.map +1 -0
  69. package/dist/chunk-X3244EKP.cjs +84 -0
  70. package/dist/chunk-X3244EKP.cjs.map +1 -0
  71. package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
  72. package/dist/chunk-YZZBDCLV.js.map +1 -0
  73. package/dist/{chunk-3MDBMCFF.cjs → chunk-ZEMNF3QK.cjs} +171 -33
  74. package/dist/chunk-ZEMNF3QK.cjs.map +1 -0
  75. package/dist/{ddl-B_H8JM-E.d.cts → ddl-B2jjLjpR.d.cts} +762 -99
  76. package/dist/{ddl-1tFIvt9V.d.ts → ddl-DpaeAKPp.d.ts} +762 -99
  77. package/dist/extension-types-D07e_NTw.d.cts +543 -0
  78. package/dist/extension-types-D07e_NTw.d.ts +543 -0
  79. package/dist/graph-extension/index.cjs +71 -0
  80. package/dist/graph-extension/index.cjs.map +1 -0
  81. package/dist/graph-extension/index.d.cts +278 -0
  82. package/dist/graph-extension/index.d.ts +278 -0
  83. package/dist/graph-extension/index.js +6 -0
  84. package/dist/graph-extension/index.js.map +1 -0
  85. package/dist/{index-DXkEXpNz.d.ts → index-CT6nvtxL.d.cts} +114 -5
  86. package/dist/{index-DXkEXpNz.d.cts → index-DQheiVQV.d.ts} +114 -5
  87. package/dist/index.cjs +2672 -901
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.d.cts +29 -10
  90. package/dist/index.d.ts +29 -10
  91. package/dist/index.js +2248 -598
  92. package/dist/index.js.map +1 -1
  93. package/dist/indexes/index.cjs +25 -23
  94. package/dist/indexes/index.d.cts +40 -22
  95. package/dist/indexes/index.d.ts +40 -22
  96. package/dist/indexes/index.js +5 -3
  97. package/dist/interchange/index.cjs +8 -7
  98. package/dist/interchange/index.cjs.map +1 -1
  99. package/dist/interchange/index.d.cts +5 -4
  100. package/dist/interchange/index.d.ts +5 -4
  101. package/dist/interchange/index.js +3 -2
  102. package/dist/interchange/index.js.map +1 -1
  103. package/dist/{manager-Vkz28eAC.d.cts → manager-BKaPQbns.d.ts} +189 -6
  104. package/dist/{manager-nIhmttD-.d.ts → manager-BpjBW1JK.d.cts} +189 -6
  105. package/dist/materialize-indexes-BB9N5uQl.d.cts +68 -0
  106. package/dist/materialize-indexes-BYpU2RKh.d.ts +68 -0
  107. package/dist/profiler/index.cjs +10 -8
  108. package/dist/profiler/index.cjs.map +1 -1
  109. package/dist/profiler/index.d.cts +8 -7
  110. package/dist/profiler/index.d.ts +8 -7
  111. package/dist/profiler/index.js +3 -1
  112. package/dist/profiler/index.js.map +1 -1
  113. package/dist/schema/index.cjs +43 -22
  114. package/dist/schema/index.cjs.map +1 -1
  115. package/dist/schema/index.d.cts +17 -8
  116. package/dist/schema/index.d.ts +17 -8
  117. package/dist/schema/index.js +9 -4
  118. package/dist/schema/index.js.map +1 -1
  119. package/dist/{sqlite-D0aceIe0.d.cts → sqlite-CU3j6rc7.d.ts} +837 -120
  120. package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-Myo8e3Lr.d.cts} +837 -120
  121. package/dist/{store-CpvwTMxV.d.cts → store-BAGuOHDh.d.cts} +659 -23
  122. package/dist/{store-U3i2tUch.d.ts → store-De98Lod4.d.ts} +659 -23
  123. package/dist/types--0EslBx5.d.cts +2123 -0
  124. package/dist/{types-qYFZ9SqD.d.ts → types-BLmJq4wI.d.ts} +3 -2
  125. package/dist/types-BNWYZ-0-.d.ts +2123 -0
  126. package/dist/{types-yH4_p0XB.d.cts → types-CYga3lZp.d.cts} +3 -2
  127. package/dist/where-CluR73rs.d.ts +11 -0
  128. package/dist/where-m1uWsdua.d.cts +11 -0
  129. package/package.json +37 -77
  130. package/dist/ast-C8S37w1A.d.ts +0 -497
  131. package/dist/ast-dgLhLOg0.d.cts +0 -497
  132. package/dist/chunk-3JK66E3I.cjs.map +0 -1
  133. package/dist/chunk-3MDBMCFF.cjs.map +0 -1
  134. package/dist/chunk-3PPEHLGK.js +0 -1116
  135. package/dist/chunk-3PPEHLGK.js.map +0 -1
  136. package/dist/chunk-5HVDOPZU.cjs.map +0 -1
  137. package/dist/chunk-753F33CV.js.map +0 -1
  138. package/dist/chunk-7TU5EWQ7.js.map +0 -1
  139. package/dist/chunk-EY4LBX3F.js.map +0 -1
  140. package/dist/chunk-EYELZHKY.js.map +0 -1
  141. package/dist/chunk-GTG5J4UP.js.map +0 -1
  142. package/dist/chunk-HRNQ3DVJ.cjs +0 -1417
  143. package/dist/chunk-HRNQ3DVJ.cjs.map +0 -1
  144. package/dist/chunk-JYUQA77I.js +0 -1381
  145. package/dist/chunk-JYUQA77I.js.map +0 -1
  146. package/dist/chunk-O5PST6TB.cjs.map +0 -1
  147. package/dist/chunk-PEE4EWXZ.cjs +0 -1131
  148. package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
  149. package/dist/chunk-RNUNP5JD.cjs.map +0 -1
  150. package/dist/chunk-RS5OLGEW.js +0 -135
  151. package/dist/chunk-RS5OLGEW.js.map +0 -1
  152. package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
  153. package/dist/chunk-WFMTAEEN.js.map +0 -1
  154. package/dist/chunk-WRWVWKQL.cjs +0 -147
  155. package/dist/chunk-WRWVWKQL.cjs.map +0 -1
  156. package/dist/types-C-zfYDJB.d.ts +0 -159
  157. package/dist/types-CQx4iW5Y.d.cts +0 -159
  158. package/dist/types-Qk2l3IkQ.d.cts +0 -1254
  159. package/dist/types-Qk2l3IkQ.d.ts +0 -1254
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/interchange/types.ts","../../src/interchange/export.ts","../../src/interchange/import.ts"],"names":["result"],"mappings":";;;;AAmBO,IAAM,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AAS,KAAA,EAAO,OAAO,cAAA,CAAe,MAAA,CAAO,KAAK,CAAA,EAAE;AAAA,IAC/D;AAEA,IAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EAC5C,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,UAAU,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AACrE,IAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,CAAA,kBAAA,EAAqB,OAAO,CAAA,CAAA,EAAG;AAAA,EACjE;AACF;AAEA,SAAS,eAAe,KAAA,EAA2B;AACjD,EAAA,OAAO,KAAA,CAAM,MAAA,CACV,GAAA,CAAI,CAAC,KAAA,KAAU;AACd,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAChC,IAAA,OAAO,OAAO,CAAA,EAAG,IAAI,KAAK,KAAA,CAAM,OAAO,KAAK,KAAA,CAAM,OAAA;AAAA,EACpD,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACd;AAMA,SAAS,WAAA,CAAY,MAAc,EAAA,EAAoB;AACrD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA;AACtB","file":"index.js","sourcesContent":["/**\n * Graph interchange format types.\n *\n * Defines Zod schemas for importing and exporting graph data.\n * The format is designed to be:\n * - JSON-serializable for API transport\n * - Validated via Zod at runtime\n * - Exportable as JSON Schema for LLM/API documentation\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// Format Version\n// ============================================================\n\n/**\n * Current interchange format version.\n * Increment for breaking changes to the format.\n */\nexport const FORMAT_VERSION = \"1.0\" as const;\n\n// ============================================================\n// Node Interchange\n// ============================================================\n\n/**\n * Interchange format for a node.\n *\n * Properties are stored as a record to allow schema-agnostic transport.\n * Validation against the actual schema happens during import.\n */\nexport const InterchangeNodeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n properties: z.record(z.string(), z.unknown()),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n version: z.number().int().positive().optional(),\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeNode = z.infer<typeof InterchangeNodeSchema>;\n\n// ============================================================\n// Edge Interchange\n// ============================================================\n\n/**\n * Interchange format for an edge.\n *\n * Endpoint references are objects with kind and id, rather than\n * composite strings, for clarity and type safety.\n */\nexport const InterchangeEdgeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n from: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n to: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n properties: z.record(z.string(), z.unknown()).default({}),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeEdge = z.infer<typeof InterchangeEdgeSchema>;\n\n// ============================================================\n// Import Configuration\n// ============================================================\n\n/**\n * Strategy for handling conflicts when a node/edge ID already exists.\n *\n * - `skip`: Keep existing, ignore incoming\n * - `update`: Merge incoming properties into existing\n * - `error`: Throw an error on conflict\n */\nexport const ConflictStrategySchema = z.enum([\"skip\", \"update\", \"error\"]);\nexport type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;\n\n/**\n * Strategy for handling properties not defined in the schema.\n *\n * - `error`: Throw a validation error\n * - `strip`: Remove unknown properties silently\n * - `allow`: Pass through to storage (relies on backend behavior)\n */\nexport const UnknownPropertyStrategySchema = z.enum([\n \"error\",\n \"strip\",\n \"allow\",\n]);\nexport type UnknownPropertyStrategy = z.infer<\n typeof UnknownPropertyStrategySchema\n>;\n\n/**\n * Options for importing graph data.\n */\nexport const ImportOptionsSchema = z.object({\n /** How to handle existing nodes/edges with the same ID */\n onConflict: ConflictStrategySchema,\n /** How to handle properties not in the schema */\n onUnknownProperty: UnknownPropertyStrategySchema.default(\"error\"),\n /** Whether to validate that edge endpoints exist */\n validateReferences: z.boolean().default(true),\n /** Number of items to process in each batch */\n batchSize: z.number().int().positive().default(100),\n});\n\nexport type ImportOptions = z.infer<typeof ImportOptionsSchema>;\n\n// ============================================================\n// Graph Data Source\n// ============================================================\n\n/**\n * Source metadata for graph data.\n *\n * Uses discriminated union to capture different origin types:\n * - `typegraph-cloud`: Extracted by TypeGraph Cloud\n * - `typegraph-export`: Exported from a TypeGraph store\n * - `external`: From a third-party system\n */\nexport const GraphDataSourceSchema = z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"typegraph-cloud\"),\n extractionId: z.string(),\n schemaId: z.string(),\n schemaVersion: z.number().int().positive().optional(),\n }),\n z.object({\n type: z.literal(\"typegraph-export\"),\n graphId: z.string(),\n schemaVersion: z.number().int().positive(),\n }),\n z.object({\n type: z.literal(\"external\"),\n description: z.string().optional(),\n }),\n]);\n\nexport type GraphDataSource = z.infer<typeof GraphDataSourceSchema>;\n\n// ============================================================\n// Graph Data Envelope\n// ============================================================\n\n/**\n * Complete graph data interchange format.\n *\n * The envelope contains metadata about the data source and format version,\n * plus arrays of nodes and edges to import.\n */\nexport const GraphDataSchema = z.object({\n formatVersion: z.literal(FORMAT_VERSION),\n exportedAt: z.iso.datetime(),\n source: GraphDataSourceSchema,\n nodes: z.array(InterchangeNodeSchema),\n edges: z.array(InterchangeEdgeSchema),\n});\n\nexport type GraphData = z.infer<typeof GraphDataSchema>;\n\n// ============================================================\n// Import Result\n// ============================================================\n\n/**\n * An error that occurred during import.\n */\nexport const ImportErrorSchema = z.object({\n entityType: z.enum([\"node\", \"edge\"]),\n kind: z.string(),\n id: z.string(),\n error: z.string(),\n});\n\nexport type ImportError = z.infer<typeof ImportErrorSchema>;\n\n/**\n * Result of an import operation.\n *\n * Contains counts of created/updated/skipped entities and any errors.\n */\nexport const ImportResultSchema = z.object({\n success: z.boolean(),\n nodes: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n edges: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n errors: z.array(ImportErrorSchema),\n});\n\nexport type ImportResult = z.infer<typeof ImportResultSchema>;\n\n// ============================================================\n// Export Options\n// ============================================================\n\n/**\n * Options for exporting graph data.\n */\nexport const ExportOptionsSchema = z.object({\n /** Filter to specific node kinds (undefined = all) */\n nodeKinds: z.array(z.string()).optional(),\n /** Filter to specific edge kinds (undefined = all) */\n edgeKinds: z.array(z.string()).optional(),\n /** Include temporal fields (validFrom, validTo) */\n includeTemporal: z.boolean().default(false),\n /** Include metadata (version, timestamps) */\n includeMeta: z.boolean().default(false),\n /** Include soft-deleted records */\n includeDeleted: z.boolean().default(false),\n});\n\n/** Export options with defaults applied (output type) */\nexport type ExportOptions = z.infer<typeof ExportOptionsSchema>;\n\n/** Export options as accepted by exportGraph (input type with optional defaults) */\nexport type ExportOptionsInput = z.input<typeof ExportOptionsSchema>;\n","/**\n * Graph data export functionality.\n *\n * Exports nodes and edges from a store to the interchange format.\n */\nimport { type GraphBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type Store } from \"../store/store\";\nimport { nowIso } from \"../utils/date\";\nimport {\n type ExportOptionsInput,\n FORMAT_VERSION,\n type GraphData,\n type InterchangeEdge,\n type InterchangeNode,\n} from \"./types\";\n\n// ============================================================\n// Export Function\n// ============================================================\n\n/**\n * Export graph data from a store.\n *\n * @param store - The graph store to export from\n * @param options - Export configuration\n * @returns Graph data in interchange format\n *\n * @example\n * ```typescript\n * const data = await exportGraph(store, {\n * nodeKinds: [\"Person\", \"Organization\"],\n * includeMeta: true,\n * });\n *\n * // Write to file\n * await fs.writeFile(\"backup.json\", JSON.stringify(data, null, 2));\n * ```\n */\nexport async function exportGraph<G extends GraphDef>(\n store: Store<G>,\n options?: ExportOptionsInput,\n): Promise<GraphData> {\n const options_ = {\n nodeKinds: options?.nodeKinds,\n edgeKinds: options?.edgeKinds,\n includeTemporal: options?.includeTemporal ?? false,\n includeMeta: options?.includeMeta ?? false,\n includeDeleted: options?.includeDeleted ?? false,\n };\n\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Determine which kinds to export\n const nodeKindsToExport = options_.nodeKinds ?? getNodeKinds(graph);\n const edgeKindsToExport = options_.edgeKinds ?? getEdgeKinds(graph);\n\n // Export nodes\n const nodes: InterchangeNode[] = [];\n for (const kind of nodeKindsToExport) {\n const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);\n nodes.push(...kindNodes);\n }\n\n // Export edges\n const edges: InterchangeEdge[] = [];\n for (const kind of edgeKindsToExport) {\n const kindEdges = await exportEdgesOfKind(backend, graphId, kind, options_);\n edges.push(...kindEdges);\n }\n\n // Get current schema version\n const schemaVersion = await backend.getActiveSchema(graphId);\n\n return {\n formatVersion: FORMAT_VERSION,\n exportedAt: nowIso(),\n source: {\n type: \"typegraph-export\",\n graphId,\n schemaVersion: schemaVersion?.version ?? 1,\n },\n nodes,\n edges,\n };\n}\n\n// ============================================================\n// Node Export\n// ============================================================\n\ntype ExportOptions_ = Readonly<{\n includeTemporal: boolean;\n includeMeta: boolean;\n includeDeleted: boolean;\n}>;\n\nasync function exportNodesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeNode[]> {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const node: InterchangeNode = {\n kind: row.kind,\n id: row.id,\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (node as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (node as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (node as { meta?: InterchangeNode[\"meta\"] }).meta = {\n version: row.version,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return node;\n });\n}\n\n// ============================================================\n// Edge Export\n// ============================================================\n\nasync function exportEdgesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeEdge[]> {\n const rows = await backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const edge: InterchangeEdge = {\n kind: row.kind,\n id: row.id,\n from: {\n kind: row.from_kind,\n id: row.from_id,\n },\n to: {\n kind: row.to_kind,\n id: row.to_id,\n },\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (edge as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (edge as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (edge as { meta?: InterchangeEdge[\"meta\"] }).meta = {\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return edge;\n });\n}\n","/**\n * Graph data import functionality.\n *\n * Imports nodes and edges from the interchange format into a store,\n * with configurable conflict resolution and validation.\n */\nimport type { z } from \"zod\";\n\nimport { type GraphBackend, type TransactionBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type EdgeRegistration, type NodeRegistration } from \"../core/types\";\nimport { type Store } from \"../store/store\";\nimport {\n type GraphData,\n type ImportError,\n type ImportOptions,\n type ImportResult,\n type InterchangeEdge,\n type InterchangeNode,\n type UnknownPropertyStrategy,\n} from \"./types\";\n\n// ============================================================\n// Import Function\n// ============================================================\n\n/**\n * Import graph data into a store.\n *\n * Nodes are imported first to satisfy edge reference validation.\n * The import runs within a transaction for atomicity when supported.\n *\n * @param store - The graph store to import into\n * @param data - Graph data in interchange format\n * @param options - Import configuration\n * @returns Import statistics and any errors\n *\n * @example\n * ```typescript\n * const result = await importGraph(store, data, {\n * onConflict: \"update\",\n * onUnknownProperty: \"strip\",\n * });\n *\n * console.log(`Created ${result.nodes.created} nodes`);\n * ```\n */\nexport async function importGraph<G extends GraphDef>(\n store: Store<G>,\n data: GraphData,\n options: ImportOptions,\n): Promise<ImportResult> {\n const result: ImportResult = {\n success: true,\n nodes: { created: 0, updated: 0, skipped: 0 },\n edges: { created: 0, updated: 0, skipped: 0 },\n errors: [],\n };\n\n const errors: ImportError[] = [];\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Build lookup maps for schema validation\n const nodeSchemas = buildNodeSchemaMap(graph);\n const edgeSchemas = buildEdgeSchemaMap(graph);\n\n // Track imported node IDs for reference validation\n const importedNodeIds = new Set<string>();\n\n // Process in transaction if supported\n if (backend.capabilities.transactions) {\n await backend.transaction(async (tx) => {\n await processNodes(\n tx,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n tx,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n });\n } else {\n await processNodes(\n backend,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n backend,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n }\n\n return {\n ...result,\n success: errors.length === 0,\n errors,\n };\n}\n\n// ============================================================\n// Schema Maps\n// ============================================================\n\ntype NodeSchemaEntry = Readonly<{\n registration: NodeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n}>;\n\ntype EdgeSchemaEntry = Readonly<{\n registration: EdgeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n fromKinds: ReadonlySet<string>;\n toKinds: ReadonlySet<string>;\n}>;\n\nfunction buildNodeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, NodeSchemaEntry> {\n const map = new Map<string, NodeSchemaEntry>();\n\n for (const kindName of getNodeKinds(graph)) {\n const registration = graph.nodes[kindName] as NodeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n });\n }\n\n return map;\n}\n\nfunction buildEdgeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, EdgeSchemaEntry> {\n const map = new Map<string, EdgeSchemaEntry>();\n\n for (const kindName of getEdgeKinds(graph)) {\n const registration = graph.edges[kindName] as EdgeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n fromKinds: new Set(registration.from.map((node) => node.kind)),\n toKinds: new Set(registration.to.map((node) => node.kind)),\n });\n }\n\n return map;\n}\n\n// ============================================================\n// Node Processing\n// ============================================================\n\nasync function processNodes(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n nodes: readonly InterchangeNode[],\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < nodes.length; index += batchSize) {\n const batch = nodes.slice(index, index + batchSize);\n\n for (const node of batch) {\n const importResult = await processNode(\n backend,\n graphId,\n node,\n schemas,\n options,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.nodes.created++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"updated\": {\n result.nodes.updated++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"skipped\": {\n result.nodes.skipped++;\n // Still track as available for edge references\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"node\",\n kind: node.kind,\n id: node.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\ntype ProcessResult =\n | { status: \"created\" }\n | { status: \"updated\" }\n | { status: \"skipped\" }\n | { status: \"error\"; error: string };\n\nasync function processNode(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n node: InterchangeNode,\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n): Promise<ProcessResult> {\n // Validate kind exists\n const schemaEntry = schemas.get(node.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown node kind: ${node.kind}` };\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n node.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if node already exists\n const existing = await backend.getNode(graphId, node.kind, node.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return {\n status: \"error\",\n error: `Node already exists: ${node.kind}:${node.id}`,\n };\n }\n case \"update\": {\n await backend.updateNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n incrementVersion: true,\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new node\n await backend.insertNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n ...(node.validFrom !== undefined && { validFrom: node.validFrom }),\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Edge Processing\n// ============================================================\n\nasync function processEdges(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edges: readonly InterchangeEdge[],\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < edges.length; index += batchSize) {\n const batch = edges.slice(index, index + batchSize);\n\n for (const edge of batch) {\n const importResult = await processEdge(\n backend,\n graphId,\n edge,\n edgeSchemas,\n nodeSchemas,\n options,\n importedNodeIds,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.edges.created++;\n break;\n }\n case \"updated\": {\n result.edges.updated++;\n break;\n }\n case \"skipped\": {\n result.edges.skipped++;\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"edge\",\n kind: edge.kind,\n id: edge.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\nasync function processEdge(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edge: InterchangeEdge,\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n importedNodeIds: Set<string>,\n): Promise<ProcessResult> {\n // Validate edge kind exists\n const schemaEntry = edgeSchemas.get(edge.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown edge kind: ${edge.kind}` };\n }\n\n // Validate endpoint kinds\n if (!nodeSchemas.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Unknown from node kind: ${edge.from.kind}`,\n };\n }\n if (!nodeSchemas.has(edge.to.kind)) {\n return { status: \"error\", error: `Unknown to node kind: ${edge.to.kind}` };\n }\n\n // Validate endpoint kinds are allowed for this edge type\n if (!schemaEntry.fromKinds.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow from kind: ${edge.from.kind}`,\n };\n }\n if (!schemaEntry.toKinds.has(edge.to.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`,\n };\n }\n\n // Validate references exist (in DB or in import batch)\n if (options.validateReferences) {\n const fromKey = makeNodeKey(edge.from.kind, edge.from.id);\n const toKey = makeNodeKey(edge.to.kind, edge.to.id);\n\n // Check import batch first, then DB\n if (!importedNodeIds.has(fromKey)) {\n const fromExists = await backend.getNode(\n graphId,\n edge.from.kind,\n edge.from.id,\n );\n if (!fromExists) {\n return {\n status: \"error\",\n error: `From node not found: ${edge.from.kind}:${edge.from.id}`,\n };\n }\n }\n\n if (!importedNodeIds.has(toKey)) {\n const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);\n if (!toExists) {\n return {\n status: \"error\",\n error: `To node not found: ${edge.to.kind}:${edge.to.id}`,\n };\n }\n }\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n edge.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if edge already exists\n const existing = await backend.getEdge(graphId, edge.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return { status: \"error\", error: `Edge already exists: ${edge.id}` };\n }\n case \"update\": {\n await backend.updateEdge({\n graphId,\n id: edge.id,\n props: propsResult.data,\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new edge\n await backend.insertEdge({\n graphId,\n id: edge.id,\n kind: edge.kind,\n fromKind: edge.from.kind,\n fromId: edge.from.id,\n toKind: edge.to.kind,\n toId: edge.to.id,\n props: propsResult.data,\n ...(edge.validFrom !== undefined && { validFrom: edge.validFrom }),\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Property Validation\n// ============================================================\n\ntype ValidationResult =\n | { success: true; data: Record<string, unknown> }\n | { success: false; error: string };\n\nfunction validateProperties(\n properties: Record<string, unknown>,\n schema: z.ZodObject<z.ZodRawShape>,\n unknownStrategy: UnknownPropertyStrategy,\n): ValidationResult {\n try {\n // Get the schema's known keys\n const knownKeys = new Set(Object.keys(schema.shape));\n\n // Check for unknown properties\n const unknownKeys = Object.keys(properties).filter(\n (key) => !knownKeys.has(key),\n );\n\n if (unknownKeys.length > 0) {\n switch (unknownStrategy) {\n case \"error\": {\n return {\n success: false,\n error: `Unknown properties: ${unknownKeys.join(\", \")}`,\n };\n }\n case \"strip\": {\n // Remove unknown properties\n const stripped: Record<string, unknown> = {};\n for (const key of knownKeys) {\n if (key in properties) {\n stripped[key] = properties[key];\n }\n }\n // Validate stripped properties\n const result = schema.safeParse(stripped);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n return {\n success: true,\n data: result.data,\n };\n }\n case \"allow\": {\n // Validate but allow extra properties through\n const result = schema.safeParse(properties);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n // Return original properties (including unknown ones)\n return { success: true, data: properties };\n }\n }\n }\n\n // No unknown properties - standard validation\n const result = schema.safeParse(properties);\n if (!result.success) {\n return { success: false, error: formatZodError(result.error) };\n }\n\n return { success: true, data: result.data };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { success: false, error: `Validation error: ${message}` };\n }\n}\n\nfunction formatZodError(error: z.ZodError): string {\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n return path ? `${path}: ${issue.message}` : issue.message;\n })\n .join(\"; \");\n}\n\n// ============================================================\n// Helpers\n// ============================================================\n\nfunction makeNodeKey(kind: string, id: string): string {\n return `${kind}:${id}`;\n}\n"]}
1
+ {"version":3,"sources":["../../src/interchange/types.ts","../../src/interchange/export.ts","../../src/interchange/import.ts"],"names":["result"],"mappings":";;;;;AAmBO,IAAM,cAAA,GAAiB;AAYvB,IAAM,qBAAA,GAAwB,EAAE,MAAA,CAAO;AAAA,EAC5C,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACtB,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACpB,UAAA,EAAY,EAAE,MAAA,CAAO,CAAA,CAAE,QAAO,EAAG,CAAA,CAAE,SAAS,CAAA;AAAA,EAC5C,SAAA,EAAW,CAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,EACrC,OAAA,EAAS,CAAA,CAAE,GAAA,CAAI,QAAA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AA,EAA2B;AACjD,EAAA,OAAO,KAAA,CAAM,MAAA,CACV,GAAA,CAAI,CAAC,KAAA,KAAU;AACd,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAChC,IAAA,OAAO,OAAO,CAAA,EAAG,IAAI,KAAK,KAAA,CAAM,OAAO,KAAK,KAAA,CAAM,OAAA;AAAA,EACpD,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACd;AAMA,SAAS,WAAA,CAAY,MAAc,EAAA,EAAoB;AACrD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA;AACtB","file":"index.js","sourcesContent":["/**\n * Graph interchange format types.\n *\n * Defines Zod schemas for importing and exporting graph data.\n * The format is designed to be:\n * - JSON-serializable for API transport\n * - Validated via Zod at runtime\n * - Exportable as JSON Schema for LLM/API documentation\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// Format Version\n// ============================================================\n\n/**\n * Current interchange format version.\n * Increment for breaking changes to the format.\n */\nexport const FORMAT_VERSION = \"1.0\" as const;\n\n// ============================================================\n// Node Interchange\n// ============================================================\n\n/**\n * Interchange format for a node.\n *\n * Properties are stored as a record to allow schema-agnostic transport.\n * Validation against the actual schema happens during import.\n */\nexport const InterchangeNodeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n properties: z.record(z.string(), z.unknown()),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n version: z.number().int().positive().optional(),\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeNode = z.infer<typeof InterchangeNodeSchema>;\n\n// ============================================================\n// Edge Interchange\n// ============================================================\n\n/**\n * Interchange format for an edge.\n *\n * Endpoint references are objects with kind and id, rather than\n * composite strings, for clarity and type safety.\n */\nexport const InterchangeEdgeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n from: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n to: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n properties: z.record(z.string(), z.unknown()).default({}),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeEdge = z.infer<typeof InterchangeEdgeSchema>;\n\n// ============================================================\n// Import Configuration\n// ============================================================\n\n/**\n * Strategy for handling conflicts when a node/edge ID already exists.\n *\n * - `skip`: Keep existing, ignore incoming\n * - `update`: Merge incoming properties into existing\n * - `error`: Throw an error on conflict\n */\nexport const ConflictStrategySchema = z.enum([\"skip\", \"update\", \"error\"]);\nexport type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;\n\n/**\n * Strategy for handling properties not defined in the schema.\n *\n * - `error`: Throw a validation error\n * - `strip`: Remove unknown properties silently\n * - `allow`: Pass through to storage (relies on backend behavior)\n */\nexport const UnknownPropertyStrategySchema = z.enum([\n \"error\",\n \"strip\",\n \"allow\",\n]);\nexport type UnknownPropertyStrategy = z.infer<\n typeof UnknownPropertyStrategySchema\n>;\n\n/**\n * Options for importing graph data.\n */\nexport const ImportOptionsSchema = z.object({\n /** How to handle existing nodes/edges with the same ID */\n onConflict: ConflictStrategySchema,\n /** How to handle properties not in the schema */\n onUnknownProperty: UnknownPropertyStrategySchema.default(\"error\"),\n /** Whether to validate that edge endpoints exist */\n validateReferences: z.boolean().default(true),\n /** Number of items to process in each batch */\n batchSize: z.number().int().positive().default(100),\n});\n\nexport type ImportOptions = z.infer<typeof ImportOptionsSchema>;\n\n// ============================================================\n// Graph Data Source\n// ============================================================\n\n/**\n * Source metadata for graph data.\n *\n * Uses discriminated union to capture different origin types:\n * - `typegraph-cloud`: Extracted by TypeGraph Cloud\n * - `typegraph-export`: Exported from a TypeGraph store\n * - `external`: From a third-party system\n */\nexport const GraphDataSourceSchema = z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"typegraph-cloud\"),\n extractionId: z.string(),\n schemaId: z.string(),\n schemaVersion: z.number().int().positive().optional(),\n }),\n z.object({\n type: z.literal(\"typegraph-export\"),\n graphId: z.string(),\n schemaVersion: z.number().int().positive(),\n }),\n z.object({\n type: z.literal(\"external\"),\n description: z.string().optional(),\n }),\n]);\n\nexport type GraphDataSource = z.infer<typeof GraphDataSourceSchema>;\n\n// ============================================================\n// Graph Data Envelope\n// ============================================================\n\n/**\n * Complete graph data interchange format.\n *\n * The envelope contains metadata about the data source and format version,\n * plus arrays of nodes and edges to import.\n */\nexport const GraphDataSchema = z.object({\n formatVersion: z.literal(FORMAT_VERSION),\n exportedAt: z.iso.datetime(),\n source: GraphDataSourceSchema,\n nodes: z.array(InterchangeNodeSchema),\n edges: z.array(InterchangeEdgeSchema),\n});\n\nexport type GraphData = z.infer<typeof GraphDataSchema>;\n\n// ============================================================\n// Import Result\n// ============================================================\n\n/**\n * An error that occurred during import.\n */\nexport const ImportErrorSchema = z.object({\n entityType: z.enum([\"node\", \"edge\"]),\n kind: z.string(),\n id: z.string(),\n error: z.string(),\n});\n\nexport type ImportError = z.infer<typeof ImportErrorSchema>;\n\n/**\n * Result of an import operation.\n *\n * Contains counts of created/updated/skipped entities and any errors.\n */\nexport const ImportResultSchema = z.object({\n success: z.boolean(),\n nodes: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n edges: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n errors: z.array(ImportErrorSchema),\n});\n\nexport type ImportResult = z.infer<typeof ImportResultSchema>;\n\n// ============================================================\n// Export Options\n// ============================================================\n\n/**\n * Options for exporting graph data.\n */\nexport const ExportOptionsSchema = z.object({\n /** Filter to specific node kinds (undefined = all) */\n nodeKinds: z.array(z.string()).optional(),\n /** Filter to specific edge kinds (undefined = all) */\n edgeKinds: z.array(z.string()).optional(),\n /** Include temporal fields (validFrom, validTo) */\n includeTemporal: z.boolean().default(false),\n /** Include metadata (version, timestamps) */\n includeMeta: z.boolean().default(false),\n /** Include soft-deleted records */\n includeDeleted: z.boolean().default(false),\n});\n\n/** Export options with defaults applied (output type) */\nexport type ExportOptions = z.infer<typeof ExportOptionsSchema>;\n\n/** Export options as accepted by exportGraph (input type with optional defaults) */\nexport type ExportOptionsInput = z.input<typeof ExportOptionsSchema>;\n","/**\n * Graph data export functionality.\n *\n * Exports nodes and edges from a store to the interchange format.\n */\nimport { type GraphBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type Store } from \"../store/store\";\nimport { nowIso } from \"../utils/date\";\nimport {\n type ExportOptionsInput,\n FORMAT_VERSION,\n type GraphData,\n type InterchangeEdge,\n type InterchangeNode,\n} from \"./types\";\n\n// ============================================================\n// Export Function\n// ============================================================\n\n/**\n * Export graph data from a store.\n *\n * @param store - The graph store to export from\n * @param options - Export configuration\n * @returns Graph data in interchange format\n *\n * @example\n * ```typescript\n * const data = await exportGraph(store, {\n * nodeKinds: [\"Person\", \"Organization\"],\n * includeMeta: true,\n * });\n *\n * // Write to file\n * await fs.writeFile(\"backup.json\", JSON.stringify(data, null, 2));\n * ```\n */\nexport async function exportGraph<G extends GraphDef>(\n store: Store<G>,\n options?: ExportOptionsInput,\n): Promise<GraphData> {\n const options_ = {\n nodeKinds: options?.nodeKinds,\n edgeKinds: options?.edgeKinds,\n includeTemporal: options?.includeTemporal ?? false,\n includeMeta: options?.includeMeta ?? false,\n includeDeleted: options?.includeDeleted ?? false,\n };\n\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Determine which kinds to export\n const nodeKindsToExport = options_.nodeKinds ?? getNodeKinds(graph);\n const edgeKindsToExport = options_.edgeKinds ?? getEdgeKinds(graph);\n\n // Export nodes\n const nodes: InterchangeNode[] = [];\n for (const kind of nodeKindsToExport) {\n const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);\n nodes.push(...kindNodes);\n }\n\n // Export edges\n const edges: InterchangeEdge[] = [];\n for (const kind of edgeKindsToExport) {\n const kindEdges = await exportEdgesOfKind(backend, graphId, kind, options_);\n edges.push(...kindEdges);\n }\n\n // Get current schema version\n const schemaVersion = await backend.getActiveSchema(graphId);\n\n return {\n formatVersion: FORMAT_VERSION,\n exportedAt: nowIso(),\n source: {\n type: \"typegraph-export\",\n graphId,\n schemaVersion: schemaVersion?.version ?? 1,\n },\n nodes,\n edges,\n };\n}\n\n// ============================================================\n// Node Export\n// ============================================================\n\ntype ExportOptions_ = Readonly<{\n includeTemporal: boolean;\n includeMeta: boolean;\n includeDeleted: boolean;\n}>;\n\nasync function exportNodesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeNode[]> {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const node: InterchangeNode = {\n kind: row.kind,\n id: row.id,\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (node as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (node as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (node as { meta?: InterchangeNode[\"meta\"] }).meta = {\n version: row.version,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return node;\n });\n}\n\n// ============================================================\n// Edge Export\n// ============================================================\n\nasync function exportEdgesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeEdge[]> {\n const rows = await backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const edge: InterchangeEdge = {\n kind: row.kind,\n id: row.id,\n from: {\n kind: row.from_kind,\n id: row.from_id,\n },\n to: {\n kind: row.to_kind,\n id: row.to_id,\n },\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (edge as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (edge as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (edge as { meta?: InterchangeEdge[\"meta\"] }).meta = {\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return edge;\n });\n}\n","/**\n * Graph data import functionality.\n *\n * Imports nodes and edges from the interchange format into a store,\n * with configurable conflict resolution and validation.\n */\nimport type { z } from \"zod\";\n\nimport { type GraphBackend, type TransactionBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type EdgeRegistration, type NodeRegistration } from \"../core/types\";\nimport { type Store } from \"../store/store\";\nimport {\n type GraphData,\n type ImportError,\n type ImportOptions,\n type ImportResult,\n type InterchangeEdge,\n type InterchangeNode,\n type UnknownPropertyStrategy,\n} from \"./types\";\n\n// ============================================================\n// Import Function\n// ============================================================\n\n/**\n * Import graph data into a store.\n *\n * Nodes are imported first to satisfy edge reference validation.\n * The import runs within a transaction for atomicity when supported.\n *\n * @param store - The graph store to import into\n * @param data - Graph data in interchange format\n * @param options - Import configuration\n * @returns Import statistics and any errors\n *\n * @example\n * ```typescript\n * const result = await importGraph(store, data, {\n * onConflict: \"update\",\n * onUnknownProperty: \"strip\",\n * });\n *\n * console.log(`Created ${result.nodes.created} nodes`);\n * ```\n */\nexport async function importGraph<G extends GraphDef>(\n store: Store<G>,\n data: GraphData,\n options: ImportOptions,\n): Promise<ImportResult> {\n const result: ImportResult = {\n success: true,\n nodes: { created: 0, updated: 0, skipped: 0 },\n edges: { created: 0, updated: 0, skipped: 0 },\n errors: [],\n };\n\n const errors: ImportError[] = [];\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Build lookup maps for schema validation\n const nodeSchemas = buildNodeSchemaMap(graph);\n const edgeSchemas = buildEdgeSchemaMap(graph);\n\n // Track imported node IDs for reference validation\n const importedNodeIds = new Set<string>();\n\n // Process in transaction if supported\n if (backend.capabilities.transactions) {\n await backend.transaction(async (tx) => {\n await processNodes(\n tx,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n tx,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n });\n } else {\n await processNodes(\n backend,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n backend,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n }\n\n return {\n ...result,\n success: errors.length === 0,\n errors,\n };\n}\n\n// ============================================================\n// Schema Maps\n// ============================================================\n\ntype NodeSchemaEntry = Readonly<{\n registration: NodeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n}>;\n\ntype EdgeSchemaEntry = Readonly<{\n registration: EdgeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n fromKinds: ReadonlySet<string>;\n toKinds: ReadonlySet<string>;\n}>;\n\nfunction buildNodeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, NodeSchemaEntry> {\n const map = new Map<string, NodeSchemaEntry>();\n\n for (const kindName of getNodeKinds(graph)) {\n const registration = graph.nodes[kindName] as NodeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n });\n }\n\n return map;\n}\n\nfunction buildEdgeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, EdgeSchemaEntry> {\n const map = new Map<string, EdgeSchemaEntry>();\n\n for (const kindName of getEdgeKinds(graph)) {\n const registration = graph.edges[kindName] as EdgeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n fromKinds: new Set(registration.from.map((node) => node.kind)),\n toKinds: new Set(registration.to.map((node) => node.kind)),\n });\n }\n\n return map;\n}\n\n// ============================================================\n// Node Processing\n// ============================================================\n\nasync function processNodes(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n nodes: readonly InterchangeNode[],\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < nodes.length; index += batchSize) {\n const batch = nodes.slice(index, index + batchSize);\n\n for (const node of batch) {\n const importResult = await processNode(\n backend,\n graphId,\n node,\n schemas,\n options,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.nodes.created++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"updated\": {\n result.nodes.updated++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"skipped\": {\n result.nodes.skipped++;\n // Still track as available for edge references\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"node\",\n kind: node.kind,\n id: node.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\ntype ProcessResult =\n | { status: \"created\" }\n | { status: \"updated\" }\n | { status: \"skipped\" }\n | { status: \"error\"; error: string };\n\nasync function processNode(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n node: InterchangeNode,\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n): Promise<ProcessResult> {\n // Validate kind exists\n const schemaEntry = schemas.get(node.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown node kind: ${node.kind}` };\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n node.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if node already exists\n const existing = await backend.getNode(graphId, node.kind, node.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return {\n status: \"error\",\n error: `Node already exists: ${node.kind}:${node.id}`,\n };\n }\n case \"update\": {\n await backend.updateNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n incrementVersion: true,\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new node\n await backend.insertNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n ...(node.validFrom !== undefined && { validFrom: node.validFrom }),\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Edge Processing\n// ============================================================\n\nasync function processEdges(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edges: readonly InterchangeEdge[],\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < edges.length; index += batchSize) {\n const batch = edges.slice(index, index + batchSize);\n\n for (const edge of batch) {\n const importResult = await processEdge(\n backend,\n graphId,\n edge,\n edgeSchemas,\n nodeSchemas,\n options,\n importedNodeIds,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.edges.created++;\n break;\n }\n case \"updated\": {\n result.edges.updated++;\n break;\n }\n case \"skipped\": {\n result.edges.skipped++;\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"edge\",\n kind: edge.kind,\n id: edge.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\nasync function processEdge(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edge: InterchangeEdge,\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n importedNodeIds: Set<string>,\n): Promise<ProcessResult> {\n // Validate edge kind exists\n const schemaEntry = edgeSchemas.get(edge.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown edge kind: ${edge.kind}` };\n }\n\n // Validate endpoint kinds\n if (!nodeSchemas.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Unknown from node kind: ${edge.from.kind}`,\n };\n }\n if (!nodeSchemas.has(edge.to.kind)) {\n return { status: \"error\", error: `Unknown to node kind: ${edge.to.kind}` };\n }\n\n // Validate endpoint kinds are allowed for this edge type\n if (!schemaEntry.fromKinds.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow from kind: ${edge.from.kind}`,\n };\n }\n if (!schemaEntry.toKinds.has(edge.to.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`,\n };\n }\n\n // Validate references exist (in DB or in import batch)\n if (options.validateReferences) {\n const fromKey = makeNodeKey(edge.from.kind, edge.from.id);\n const toKey = makeNodeKey(edge.to.kind, edge.to.id);\n\n // Check import batch first, then DB\n if (!importedNodeIds.has(fromKey)) {\n const fromExists = await backend.getNode(\n graphId,\n edge.from.kind,\n edge.from.id,\n );\n if (!fromExists) {\n return {\n status: \"error\",\n error: `From node not found: ${edge.from.kind}:${edge.from.id}`,\n };\n }\n }\n\n if (!importedNodeIds.has(toKey)) {\n const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);\n if (!toExists) {\n return {\n status: \"error\",\n error: `To node not found: ${edge.to.kind}:${edge.to.id}`,\n };\n }\n }\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n edge.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if edge already exists\n const existing = await backend.getEdge(graphId, edge.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return { status: \"error\", error: `Edge already exists: ${edge.id}` };\n }\n case \"update\": {\n await backend.updateEdge({\n graphId,\n id: edge.id,\n props: propsResult.data,\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new edge\n await backend.insertEdge({\n graphId,\n id: edge.id,\n kind: edge.kind,\n fromKind: edge.from.kind,\n fromId: edge.from.id,\n toKind: edge.to.kind,\n toId: edge.to.id,\n props: propsResult.data,\n ...(edge.validFrom !== undefined && { validFrom: edge.validFrom }),\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Property Validation\n// ============================================================\n\ntype ValidationResult =\n | { success: true; data: Record<string, unknown> }\n | { success: false; error: string };\n\nfunction validateProperties(\n properties: Record<string, unknown>,\n schema: z.ZodObject<z.ZodRawShape>,\n unknownStrategy: UnknownPropertyStrategy,\n): ValidationResult {\n try {\n // Get the schema's known keys\n const knownKeys = new Set(Object.keys(schema.shape));\n\n // Check for unknown properties\n const unknownKeys = Object.keys(properties).filter(\n (key) => !knownKeys.has(key),\n );\n\n if (unknownKeys.length > 0) {\n switch (unknownStrategy) {\n case \"error\": {\n return {\n success: false,\n error: `Unknown properties: ${unknownKeys.join(\", \")}`,\n };\n }\n case \"strip\": {\n // Remove unknown properties\n const stripped: Record<string, unknown> = {};\n for (const key of knownKeys) {\n if (key in properties) {\n stripped[key] = properties[key];\n }\n }\n // Validate stripped properties\n const result = schema.safeParse(stripped);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n return {\n success: true,\n data: result.data,\n };\n }\n case \"allow\": {\n // Validate but allow extra properties through\n const result = schema.safeParse(properties);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n // Return original properties (including unknown ones)\n return { success: true, data: properties };\n }\n }\n }\n\n // No unknown properties - standard validation\n const result = schema.safeParse(properties);\n if (!result.success) {\n return { success: false, error: formatZodError(result.error) };\n }\n\n return { success: true, data: result.data };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { success: false, error: `Validation error: ${message}` };\n }\n}\n\nfunction formatZodError(error: z.ZodError): string {\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n return path ? `${path}: ${issue.message}` : issue.message;\n })\n .join(\"; \");\n}\n\n// ============================================================\n// Helpers\n// ============================================================\n\nfunction makeNodeKey(kind: string, id: string): string {\n return `${kind}:${id}`;\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { r as NodeRegistration, f as EdgeRegistration, O as OntologyRelation, b as DeleteBehavior, T as TemporalMode, N as NodeType, A as AnyEdgeType, n as GraphDefaults, W as SerializedNodeDef, X as SerializedEdgeDef, $ as SerializedSchema, G as GraphBackend, a4 as SchemaVersionRow } from './types-Qk2l3IkQ.cjs';
1
+ import { b as NodeRegistration, E as EdgeRegistration, D as DeleteBehavior, T as TemporalMode, G as GraphExtension, N as NodeType, A as AnyEdgeType, c as GraphDefaults, I as IndexEntity } from './extension-types-D07e_NTw.js';
2
+ import { O as OntologyRelation, I as IndexDeclaration, S as SerializedNodeDef, d as SerializedEdgeDef, h as SerializedSchema, y as SchemaVersionRow, G as GraphBackend } from './types-BNWYZ-0-.js';
2
3
 
3
4
  /** Brand key for GraphDef */
4
5
  declare const GRAPH_DEF_BRAND: "__graphDef";
@@ -31,6 +32,23 @@ type GraphDefConfig<TNodes extends Record<string, NodeRegistration>, TEdges exte
31
32
  ontology?: TOntology;
32
33
  /** Graph-wide defaults */
33
34
  defaults?: GraphDefaults;
35
+ /**
36
+ * Index declarations attached to this graph.
37
+ *
38
+ * Accepts the outputs of `defineNodeIndex` / `defineEdgeIndex` (which
39
+ * already return `IndexDeclaration` values) or pre-built declarations
40
+ * reconstructed from a stored schema or graph extension.
41
+ *
42
+ * Validated at definition time: every index must reference a `kind`
43
+ * that exists in `nodes` / `edges`, and index `name`s must be unique
44
+ * within the graph.
45
+ *
46
+ * Index DDL is **not** generated by `defineGraph`. Indexes flow into
47
+ * `SerializedSchema.indexes` so they can later be materialized via
48
+ * `store.materializeIndexes()` — lifting the storage concern out of
49
+ * the schema-version commit path.
50
+ */
51
+ indexes?: readonly IndexDeclaration[];
34
52
  }>;
35
53
  /**
36
54
  * A graph definition.
@@ -48,6 +66,35 @@ type GraphDef<TNodes extends Record<string, NodeRegistration> = Record<string, N
48
66
  onNodeDelete: DeleteBehavior;
49
67
  temporalMode: TemporalMode;
50
68
  }>;
69
+ /**
70
+ * Index declarations attached to this graph. Preserves whatever the
71
+ * caller passed to `defineGraph` (including an explicit empty array)
72
+ * for introspection purposes.
73
+ *
74
+ * The serialized canonical form is order-canonicalized (sorted by
75
+ * `name`) and treats `undefined` and `[]` as the same "no slice" form
76
+ * — an empty array does not bump the schema hash, since indexes are
77
+ * an unordered set keyed by name and `[]` carries no semantic meaning
78
+ * that an absent slice doesn't.
79
+ */
80
+ indexes: readonly IndexDeclaration[] | undefined;
81
+ /**
82
+ * Graph extension this graph was merged with, if any. Set by
83
+ * `mergeGraphExtension`; never set by `defineGraph` directly.
84
+ * Exists solely so re-serialization is stable — the rest of the
85
+ * system reads the merged kinds through `nodes` / `edges` /
86
+ * `ontology` and never inspects this field. Absent on graphs that
87
+ * have never been extended; legacy graphs hash byte-identically.
88
+ */
89
+ extension: GraphExtension | undefined;
90
+ /**
91
+ * Soft-deprecated kind names attached to this graph. Set by the
92
+ * loader from the persisted schema and by `store.deprecateKinds(...)`
93
+ * / `store.undeprecateKinds(...)`. A purely informational signal
94
+ * surfaced for introspection — does not gate reads, writes, or
95
+ * queries. Defaults to the empty set on freshly-defined graphs.
96
+ */
97
+ deprecatedKinds: ReadonlySet<string>;
51
98
  }>;
52
99
  /**
53
100
  * Extract node kind names from a GraphDef.
@@ -314,6 +361,56 @@ type OntologyChange = Readonly<{
314
361
  severity: ChangeSeverity;
315
362
  details: string;
316
363
  }>;
364
+ /**
365
+ * A change to an index declaration.
366
+ *
367
+ * Index changes are always `safe`-severity: index DDL is materialized
368
+ * separately and never blocks schema-version commits or migrations.
369
+ * Adding, removing, or modifying an index never invalidates existing
370
+ * data — it only changes which physical indexes the deployment will
371
+ * materialize on its next pass.
372
+ */
373
+ type IndexChange = Readonly<{
374
+ type: ChangeType;
375
+ /** Index name (the diffing identity key). */
376
+ name: string;
377
+ /**
378
+ * Whether this index is on a node, edge, or vector field. Vector
379
+ * index changes flow through the same diff classification as
380
+ * relational ones.
381
+ */
382
+ entity: IndexEntity;
383
+ severity: ChangeSeverity;
384
+ details: string;
385
+ before?: IndexDeclaration | undefined;
386
+ after?: IndexDeclaration | undefined;
387
+ }>;
388
+ /**
389
+ * A change to the persisted graph-extension document.
390
+ *
391
+ * Graph-extension document changes are committed only through the
392
+ * graph-extension lifecycle verbs (`evolve` and `removeKinds`), so the
393
+ * extension-slice change itself is `safe`-severity. The detailed
394
+ * per-kind effect is captured in the corresponding node/edge/ontology
395
+ * changes the merged document produced.
396
+ */
397
+ type ExtensionChange = Readonly<{
398
+ type: ChangeType;
399
+ severity: ChangeSeverity;
400
+ details: string;
401
+ }>;
402
+ /**
403
+ * Change to the soft-deprecated kind set. `safe`-severity by
404
+ * construction — deprecation is a metadata signal that doesn't gate
405
+ * reads, writes, or queries. The `added` and `removed` arrays carry
406
+ * the per-name deltas so consumers can render granular diffs.
407
+ */
408
+ type DeprecatedKindsChange = Readonly<{
409
+ added: readonly string[];
410
+ removed: readonly string[];
411
+ severity: ChangeSeverity;
412
+ details: string;
413
+ }>;
317
414
  /**
318
415
  * A complete diff between two schema versions.
319
416
  */
@@ -326,6 +423,18 @@ type SchemaDiff = Readonly<{
326
423
  edges: readonly EdgeChange[];
327
424
  /** Changes to ontology */
328
425
  ontology: readonly OntologyChange[];
426
+ /** Changes to index declarations */
427
+ indexes: readonly IndexChange[];
428
+ /**
429
+ * Change to the graph-extension document, if any. `undefined` when
430
+ * the slice is unchanged on both sides (the common case).
431
+ */
432
+ extension?: ExtensionChange;
433
+ /**
434
+ * Change to the soft-deprecated kind set, if any. `undefined` when
435
+ * the set is unchanged on both sides.
436
+ */
437
+ deprecatedKinds?: DeprecatedKindsChange;
329
438
  /** Whether any breaking changes exist */
330
439
  hasBreakingChanges: boolean;
331
440
  /** Whether the change is backwards compatible (no breaking changes) */
@@ -367,12 +476,59 @@ declare function getMigrationActions(diff: SchemaDiff): readonly string[];
367
476
  * - Error reporting for breaking changes
368
477
  */
369
478
 
479
+ /**
480
+ * Parses and validates a serialized schema document from the database.
481
+ *
482
+ * Uses the Zod schema to validate the full nested structure, catching
483
+ * corruption, incompatible schema versions, or truncated JSON at the
484
+ * parse boundary rather than letting invalid data propagate silently.
485
+ */
486
+ declare function parseSerializedSchema(json: string): SerializedSchema;
487
+ /**
488
+ * Reads the active schema row, bootstrapping the base tables on the
489
+ * first call against an empty database.
490
+ */
491
+ declare function loadActiveSchemaWithBootstrap(backend: GraphBackend, graphId: string): Promise<SchemaVersionRow | undefined>;
492
+ /**
493
+ * Reads the active schema, parses it, and folds any persisted graph-extension
494
+ * document into the supplied compile-time graph. Returns the
495
+ * merged graph alongside the prefetched row + parsed schema so the
496
+ * caller can pass them through to `ensureSchema` without paying for a
497
+ * second `getActiveSchema` round trip or a second
498
+ * `serializedSchemaZod` walk.
499
+ *
500
+ * Throws `ConfigurationError` if the persisted graph-extension document
501
+ * references a compile-time kind that no longer exists (the
502
+ * startup-conflict case).
503
+ */
504
+ declare function loadAndMergeGraphExtensionDocument<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<Readonly<{
505
+ graph: G;
506
+ activeRow: SchemaVersionRow | undefined;
507
+ storedSchema: SerializedSchema | undefined;
508
+ }>>;
509
+ /**
510
+ * Returns a graph carrying the supplied deprecated-kind names. Used by
511
+ * the loader to propagate `SerializedSchema.deprecatedKinds` onto the
512
+ * `GraphDef` that the Store sees, and by `Store.deprecateKinds` /
513
+ * `Store.undeprecateKinds` to construct the next graph.
514
+ *
515
+ * Returns the original graph reference when the desired set already
516
+ * matches `graph.deprecatedKinds` — covers both the no-deprecations
517
+ * load path (empty equals empty) and the loader's restart-with-same-
518
+ * persisted-set hot path. Skips a Set allocation + spread + freeze.
519
+ */
520
+ declare function applyDeprecatedKinds<G extends GraphDef>(graph: G, names: Iterable<string> | undefined): G;
370
521
  /**
371
522
  * Result of schema validation.
523
+ *
524
+ * The `initialized` and `migrated` statuses carry the committed
525
+ * `SchemaVersionRow` directly so callers building post-commit metadata
526
+ * (e.g. `Store.deprecateKinds`) can skip a `getActiveSchema` round-trip.
372
527
  */
373
528
  type SchemaValidationResult = {
374
529
  status: "initialized";
375
530
  version: number;
531
+ committedRow: SchemaVersionRow;
376
532
  } | {
377
533
  status: "unchanged";
378
534
  version: number;
@@ -381,6 +537,7 @@ type SchemaValidationResult = {
381
537
  fromVersion: number;
382
538
  toVersion: number;
383
539
  diff: SchemaDiff;
540
+ committedRow: SchemaVersionRow;
384
541
  } | {
385
542
  status: "pending";
386
543
  version: number;
@@ -431,11 +588,27 @@ type SchemaManagerOptions = Readonly<{
431
588
  * @returns The result of schema validation
432
589
  * @throws MigrationError if breaking changes detected and throwOnBreaking is true
433
590
  */
434
- declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions): Promise<SchemaValidationResult>;
591
+ declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions & {
592
+ /**
593
+ * Pre-fetched active row + parsed stored schema. When the loader
594
+ * (`createStoreWithSchema`) has already paid for `getActiveSchema`
595
+ * and `parseSerializedSchema` to peek at `extension`, it
596
+ * passes the results through here so `ensureSchema` doesn't repeat
597
+ * the round trip + Zod walk on every Store boot.
598
+ */
599
+ preloaded?: Readonly<{
600
+ activeRow: SchemaVersionRow | undefined;
601
+ storedSchema: SerializedSchema | undefined;
602
+ }>;
603
+ }): Promise<SchemaValidationResult>;
435
604
  /**
436
605
  * Initializes the schema for a new graph.
437
606
  *
438
- * Creates version 1 of the schema and marks it as active.
607
+ * Creates version 1 of the schema and marks it as active. Goes through
608
+ * the same `commitSchemaVersion` primitive as `migrateSchema` so the
609
+ * initial-commit race (two processes booting against an empty database
610
+ * simultaneously) resolves with `StaleVersionError` or idempotent
611
+ * success rather than a raw PK violation.
439
612
  *
440
613
  * @param backend - The database backend
441
614
  * @param graph - The graph definition
@@ -445,8 +618,12 @@ declare function initializeSchema<G extends GraphDef>(backend: GraphBackend, gra
445
618
  /**
446
619
  * Migrates the schema to match the current graph definition.
447
620
  *
448
- * This creates a new schema version and marks it as active.
449
- * The old version is preserved for history/rollback.
621
+ * Creates a new schema version and atomically activates it via the
622
+ * `commitSchemaVersion` backend primitive — insert and activate happen
623
+ * in a single transactional unit with optimistic compare-and-swap on
624
+ * the currently-active version. If another writer has advanced the
625
+ * active version since `currentVersion` was read, this throws
626
+ * `StaleVersionError`; the caller should refetch and retry.
450
627
  *
451
628
  * @param backend - The database backend
452
629
  * @param graph - The current graph definition
@@ -460,10 +637,16 @@ declare function migrateSchema<G extends GraphDef>(backend: GraphBackend, graph:
460
637
  * The target version must already exist in the version history.
461
638
  * This does not delete newer versions — it simply switches the active pointer.
462
639
  *
640
+ * Uses the `setActiveVersion` backend primitive, which performs the flip
641
+ * atomically with optimistic compare-and-swap on the currently-active
642
+ * version. Concurrent rollbacks or commits surface as
643
+ * `StaleVersionError`.
644
+ *
463
645
  * @param backend - The database backend
464
646
  * @param graphId - The graph ID
465
647
  * @param targetVersion - The version to roll back to
466
648
  * @throws MigrationError if the target version does not exist
649
+ * @throws StaleVersionError if another writer changed the active version concurrently
467
650
  */
468
651
  declare function rollbackSchema(backend: GraphBackend, graphId: string, targetVersion: number): Promise<void>;
469
652
  /**
@@ -491,4 +674,4 @@ declare function isSchemaInitialized(backend: GraphBackend, graphId: string): Pr
491
674
  */
492
675
  declare function getSchemaChanges<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<SchemaDiff | undefined>;
493
676
 
494
- export { type AllEdgeTypes as A, type ChangeSeverity as C, type EdgeKinds as E, type GraphDef as G, KindRegistry as K, type MigrationHookContext as M, type NodeKinds as N, type OntologyChange as O, type SchemaManagerOptions as S, type AllNodeTypes as a, type GetEdgeType as b, type GetNodeType as c, type SchemaValidationResult as d, defineGraph as e, getNodeKinds as f, getEdgeKinds as g, type ChangeType as h, isGraphDef as i, type EdgeChange as j, type NodeChange as k, type SchemaDiff as l, computeSchemaDiff as m, ensureSchema as n, getActiveSchema as o, getMigrationActions as p, getSchemaChanges as q, initializeSchema as r, isBackwardsCompatible as s, isSchemaInitialized as t, migrateSchema as u, rollbackSchema as v };
677
+ export { type AllEdgeTypes as A, isGraphDef as B, type ChangeSeverity as C, type DeprecatedKindsChange as D, type EdgeChange as E, type GraphDef as G, type IndexChange as I, KindRegistry as K, type MigrationHookContext as M, type NodeChange as N, type OntologyChange as O, type SchemaDiff as S, type ChangeType as a, type ExtensionChange as b, type SchemaManagerOptions as c, type SchemaValidationResult as d, applyDeprecatedKinds as e, computeSchemaDiff as f, ensureSchema as g, getActiveSchema as h, getMigrationActions as i, getSchemaChanges as j, initializeSchema as k, isBackwardsCompatible as l, isSchemaInitialized as m, loadActiveSchemaWithBootstrap as n, loadAndMergeGraphExtensionDocument as o, migrateSchema as p, parseSerializedSchema as q, rollbackSchema as r, type AllNodeTypes as s, type EdgeKinds as t, type GetEdgeType as u, type GetNodeType as v, type NodeKinds as w, defineGraph as x, getEdgeKinds as y, getNodeKinds as z };