@nicia-ai/typegraph 0.66.1 → 0.67.1

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 (65) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +15 -0
  3. package/dist/backend/drizzle/engine/index.cjs +6 -6
  4. package/dist/backend/drizzle/engine/index.js +1 -1
  5. package/dist/backend/postgres/index.cjs +15 -15
  6. package/dist/backend/postgres/index.js +1 -1
  7. package/dist/backend/postgres/pglite-store.cjs +1 -1
  8. package/dist/backend/postgres/pglite-store.js +1 -1
  9. package/dist/backend/postgres/pglite.cjs +3 -3
  10. package/dist/backend/postgres/pglite.js +2 -2
  11. package/dist/backend/sqlite/index.cjs +14 -14
  12. package/dist/backend/sqlite/index.js +1 -1
  13. package/dist/backend/sqlite/libsql.cjs +6 -6
  14. package/dist/backend/sqlite/libsql.js +1 -1
  15. package/dist/backend/sqlite/local-store.cjs +1 -1
  16. package/dist/backend/sqlite/local-store.js +1 -1
  17. package/dist/backend/sqlite/local.cjs +3 -3
  18. package/dist/backend/sqlite/local.js +2 -2
  19. package/dist/{chunk-TR7QTODF.js → chunk-55DGFZYC.js} +3 -3
  20. package/dist/{chunk-TR7QTODF.js.map → chunk-55DGFZYC.js.map} +1 -1
  21. package/dist/{chunk-WB55URNM.js → chunk-6CKSTY2D.js} +7 -3
  22. package/dist/chunk-6CKSTY2D.js.map +1 -0
  23. package/dist/{chunk-ZONDBN6H.js → chunk-6DY26DPE.js} +3 -3
  24. package/dist/{chunk-ZONDBN6H.js.map → chunk-6DY26DPE.js.map} +1 -1
  25. package/dist/{chunk-YHMXF7OZ.js → chunk-6J3VUPI6.js} +3 -3
  26. package/dist/{chunk-YHMXF7OZ.js.map → chunk-6J3VUPI6.js.map} +1 -1
  27. package/dist/{chunk-MN325MG4.cjs → chunk-7MQL7FEN.cjs} +11 -2
  28. package/dist/chunk-7MQL7FEN.cjs.map +1 -0
  29. package/dist/{chunk-WWSYGZED.cjs → chunk-E6XL3KMZ.cjs} +6 -6
  30. package/dist/{chunk-WWSYGZED.cjs.map → chunk-E6XL3KMZ.cjs.map} +1 -1
  31. package/dist/{chunk-SSDHR2C2.js → chunk-EFSXK3DW.js} +3 -3
  32. package/dist/{chunk-SSDHR2C2.js.map → chunk-EFSXK3DW.js.map} +1 -1
  33. package/dist/{chunk-2DJKHZQ4.js → chunk-EORFWD6O.js} +11 -2
  34. package/dist/chunk-EORFWD6O.js.map +1 -0
  35. package/dist/{chunk-Y4X6ODVY.cjs → chunk-FS2GVO2T.cjs} +56 -56
  36. package/dist/{chunk-Y4X6ODVY.cjs.map → chunk-FS2GVO2T.cjs.map} +1 -1
  37. package/dist/{chunk-K7YACILO.cjs → chunk-GXHEGNI6.cjs} +9 -9
  38. package/dist/{chunk-K7YACILO.cjs.map → chunk-GXHEGNI6.cjs.map} +1 -1
  39. package/dist/{chunk-BX42F7IJ.cjs → chunk-SSDLQPMY.cjs} +7 -2
  40. package/dist/chunk-SSDLQPMY.cjs.map +1 -0
  41. package/dist/{chunk-ANMCKLZQ.cjs → chunk-ZRIXU33S.cjs} +12 -12
  42. package/dist/{chunk-ANMCKLZQ.cjs.map → chunk-ZRIXU33S.cjs.map} +1 -1
  43. package/dist/graph-merge/index.cjs +500 -26
  44. package/dist/graph-merge/index.cjs.map +1 -1
  45. package/dist/graph-merge/index.d.cts +384 -2
  46. package/dist/graph-merge/index.d.ts +384 -2
  47. package/dist/graph-merge/index.js +485 -15
  48. package/dist/graph-merge/index.js.map +1 -1
  49. package/dist/index.cjs +63 -63
  50. package/dist/index.js +3 -3
  51. package/dist/{local-store-impl-ERPNYOCL.js → local-store-impl-CCMWTLGY.js} +6 -6
  52. package/dist/{local-store-impl-ERPNYOCL.js.map → local-store-impl-CCMWTLGY.js.map} +1 -1
  53. package/dist/{local-store-impl-OUINMCYI.cjs → local-store-impl-GI6S4J6B.cjs} +9 -9
  54. package/dist/{local-store-impl-OUINMCYI.cjs.map → local-store-impl-GI6S4J6B.cjs.map} +1 -1
  55. package/dist/{pglite-store-impl-Z3SOOP75.cjs → pglite-store-impl-HAPAJUIO.cjs} +9 -9
  56. package/dist/{pglite-store-impl-Z3SOOP75.cjs.map → pglite-store-impl-HAPAJUIO.cjs.map} +1 -1
  57. package/dist/{pglite-store-impl-DUJBQZS5.js → pglite-store-impl-HDLFOZWS.js} +6 -6
  58. package/dist/{pglite-store-impl-DUJBQZS5.js.map → pglite-store-impl-HDLFOZWS.js.map} +1 -1
  59. package/dist/schema/index.cjs +27 -27
  60. package/dist/schema/index.js +2 -2
  61. package/package.json +1 -1
  62. package/dist/chunk-2DJKHZQ4.js.map +0 -1
  63. package/dist/chunk-BX42F7IJ.cjs.map +0 -1
  64. package/dist/chunk-MN325MG4.cjs.map +0 -1
  65. package/dist/chunk-WB55URNM.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkBX42F7IJ_cjs = require('./chunk-BX42F7IJ.cjs');
3
+ var chunkSSDLQPMY_cjs = require('./chunk-SSDLQPMY.cjs');
4
4
  var chunkHAHNRASW_cjs = require('./chunk-HAHNRASW.cjs');
5
5
  var chunkBXHAPCQG_cjs = require('./chunk-BXHAPCQG.cjs');
6
6
  var chunk7XYPLAPL_cjs = require('./chunk-7XYPLAPL.cjs');
@@ -35,7 +35,7 @@ function deserializeSchema(schema) {
35
35
  function buildRegistryFromRelations(schema) {
36
36
  const nodeKinds = /* @__PURE__ */ new Map();
37
37
  const edgeKinds = /* @__PURE__ */ new Map();
38
- return chunkBX42F7IJ_cjs.buildValidatedKindRegistry({
38
+ return chunkSSDLQPMY_cjs.buildValidatedKindRegistry({
39
39
  nodeKinds,
40
40
  edgeKinds,
41
41
  ontology: schema.ontology.relations.map(
@@ -101,8 +101,8 @@ async function registerGraphTemplate(backend, params) {
101
101
  }
102
102
  );
103
103
  }
104
- const schemaDocument = chunkBX42F7IJ_cjs.serializeSchema(reconciled.graph, reconciled.version);
105
- const schemaHash = await chunkBX42F7IJ_cjs.computeSchemaHash(schemaDocument);
104
+ const schemaDocument = chunkSSDLQPMY_cjs.serializeSchema(reconciled.graph, reconciled.version);
105
+ const schemaHash = await chunkSSDLQPMY_cjs.computeSchemaHash(schemaDocument);
106
106
  if (schemaHash !== reconciled.hash) {
107
107
  throw new chunk7XYPLAPL_cjs.ConfigurationError(
108
108
  "Reconciled schema hash does not match its graph snapshot.",
@@ -129,8 +129,8 @@ async function instantiateGraphTemplate(backend, params) {
129
129
  if (sourceVersion === void 0 || reconciledHash === void 0) {
130
130
  throw graphTemplateHandleMismatchError(params.template.id);
131
131
  }
132
- const sourceHash = await chunkBX42F7IJ_cjs.computeSchemaHash(
133
- chunkBX42F7IJ_cjs.serializeSchema(params.template.reconciled.graph, sourceVersion)
132
+ const sourceHash = await chunkSSDLQPMY_cjs.computeSchemaHash(
133
+ chunkSSDLQPMY_cjs.serializeSchema(params.template.reconciled.graph, sourceVersion)
134
134
  );
135
135
  if (sourceHash !== params.template.schemaHash || reconciledHash !== params.template.schemaHash) {
136
136
  throw graphTemplateHandleMismatchError(params.template.id);
@@ -139,7 +139,7 @@ async function instantiateGraphTemplate(backend, params) {
139
139
  ...params.template.reconciled.graph,
140
140
  id: params.graphId
141
141
  });
142
- const targetHash = await chunkBX42F7IJ_cjs.computeSchemaHash(chunkBX42F7IJ_cjs.serializeSchema(targetGraph, 1));
142
+ const targetHash = await chunkSSDLQPMY_cjs.computeSchemaHash(chunkSSDLQPMY_cjs.serializeSchema(targetGraph, 1));
143
143
  const result = await instantiate({
144
144
  templateId: params.template.id,
145
145
  templateSchemaHash: params.template.schemaHash,
@@ -192,5 +192,5 @@ exports.deserializeSchema = deserializeSchema;
192
192
  exports.instantiateGraph = instantiateGraph;
193
193
  exports.instantiateGraphTemplate = instantiateGraphTemplate;
194
194
  exports.registerGraphTemplate = registerGraphTemplate;
195
- //# sourceMappingURL=chunk-K7YACILO.cjs.map
196
- //# sourceMappingURL=chunk-K7YACILO.cjs.map
195
+ //# sourceMappingURL=chunk-GXHEGNI6.cjs.map
196
+ //# sourceMappingURL=chunk-GXHEGNI6.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/schema/deserializer.ts","../src/schema/graph-templates.ts"],"names":["hasOwnKey","buildValidatedKindRegistry","ConfigurationError","resolveGraphVectorSlots","serializeSchema","computeSchemaHash"],"mappings":";;;;;;;;AAqFO,SAAS,kBACd,MAAA,EACoB;AACpB,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,SAAS,SAAS,CAAA;AAE3D,EAAA,OAAO;AAAA,IACL,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,aAAa,MAAA,CAAO,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAAM,SAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAAM,SAAA;AAAA,IAEpB,WAAA,EAAa,CAAC,IAAA,KACZA,2BAAA,CAAU,MAAA,CAAO,QAAA,CAAS,SAAA,EAAW,IAAI,CAAA,GACvC,MAAA,CAAO,QAAA,CAAS,SAAA,CAAU,IAAI,CAAA,GAC9B,MAAA;AAAA,IACJ,kBAAkB,MAAM,aAAA;AAAA,IAExB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AAA,EAC3B;AACA,IAAA,MAAM,IAAIA,oCAAA;AAAA,MACR,wFAAA;AAAA,MACA,EAAE,IAAA,EAAM,+BAAA,EAAiC,OAAA,EAAS,OAAO,OAAA;AAAQ,KACnE;AAAA,EACF;AACA,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAA,EAAQ,OAAA;AAAA,IACR,UAAA,EAAY,OAAO,MAAA,CAAO;AAAA,MACxB,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS,OAAO,GAAA,CAAI,OAAA;AAAA,MACpB,IAAA,EAAM,OAAO,GAAA,CAAI;AAAA,KAClB,CAAA;AAAA,IACD,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAEA,SAAS,iCACP,UAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,0BAA0B,UAAU,CAAA,gDAAA,CAAA;AAAA,IACpC,EAAE,IAAA,EAAM,gCAAA,EAAkC,UAAA;AAAW,GACvD;AACF;AAGO,SAAS,gBAAA,CACd,SACA,MAAA,EAC4C;AAC5C,EAAA,OAAO,wBAAA,CAAyB,SAAS,MAAM,CAAA;AACjD;AAEA,SAAS,+BACP,OAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,CAAA,IAAA,EAAO,QAAQ,OAAO,CAAA,kDAAA,CAAA;AAAA,IACtB,EAAE,IAAA,EAAM,6BAAA,EAA+B,OAAA,EAAS,QAAQ,OAAA;AAAQ,GAClE;AACF","file":"chunk-K7YACILO.cjs","sourcesContent":["/**\n * Schema deserializer for loading stored schemas.\n *\n * Reconstructs runtime objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { type AnyEdgeType, type NodeType } from \"../core/types\";\nimport { type NamedOntologyRelation } from \"../ontology/validation\";\nimport { buildValidatedKindRegistry } from \"../registry/build-validated\";\nimport type { KindRegistry } from \"../registry/kind-registry\";\nimport { type EdgeEndpointKinds } from \"../registry/validate-implies\";\nimport { hasOwnKey } from \"../utils/object\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the durable TypeGraph Identity Profile configuration. */\n getIdentity: () => SerializedSchema[\"identity\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a validated KindRegistry by recomputing closures from relations */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n // Own-key reads, for the same reason {@link buildEdgeEndpointKinds} below\n // uses a `Map`: `schema` is parsed out of a stored JSON document and the\n // caller supplies the name, so a raw read hands back an `Object.prototype`\n // member typed as a definition for any name no kind is registered under.\n getNode: (name) =>\n hasOwnKey(schema.nodes, name) ? schema.nodes[name] : undefined,\n getNodeNames: () => nodeNames,\n\n getEdge: (name) =>\n hasOwnKey(schema.edges, name) ? schema.edges[name] : undefined,\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) =>\n hasOwnKey(schema.ontology.metaEdges, name) ?\n schema.ontology.metaEdges[name]\n : undefined,\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getIdentity: () => schema.identity,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromRelations(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized relations.\n *\n * Persisted closures are a legacy inspection artifact. Relations are validated\n * and closures are recomputed so old schemas gain current hardening rules.\n */\nfunction buildRegistryFromRelations(schema: SerializedSchema): KindRegistry {\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map<string, NodeType>();\n const edgeKinds = new Map<string, AnyEdgeType>();\n return buildValidatedKindRegistry({\n nodeKinds,\n edgeKinds,\n ontology: schema.ontology.relations.map(\n (relation): NamedOntologyRelation => ({\n metaEdge: relation.metaEdge,\n from: relation.from,\n to: relation.to,\n }),\n ),\n edgeEndpoints: buildEdgeEndpointKinds(schema.edges),\n ...(schema.identity === undefined ? {} : { identity: schema.identity }),\n });\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n const pairs: { from: string; to: string }[] = [];\n if (def.targetKindsBySource === undefined) {\n for (const fromKind of def.fromKinds) {\n for (const toKind of def.toKinds) {\n pairs.push({ from: fromKind, to: toKind });\n }\n }\n } else {\n for (const [sourceKind, targetKinds] of Object.entries(\n def.targetKindsBySource,\n )) {\n for (const targetKind of targetKinds) {\n pairs.push({ from: sourceKind, to: targetKind });\n }\n }\n }\n result.set(kind, {\n from: def.fromKinds,\n to: def.toKinds,\n pairs,\n });\n }\n return result;\n}\n","import type { GraphBackend, SchemaVersionRow } from \"../backend/types\";\nimport { type GraphDef } from \"../core/define-graph\";\nimport { resolveGraphVectorSlots } from \"../core/embedding\";\nimport { ConfigurationError } from \"../errors\";\nimport { type ReconciledSchema } from \"../store/store\";\nimport { computeSchemaHash, serializeSchema } from \"./serializer\";\n\n/** A locally held handle for a durable server-side graph template. */\nexport type GraphTemplate<G extends GraphDef> = Readonly<{\n id: string;\n reconciled: ReconciledSchema<G>;\n schemaHash: string;\n}>;\n\nexport type InstantiateGraphTemplateResult<G extends GraphDef> = Readonly<{\n status: \"ready\";\n reconciled: ReconciledSchema<G>;\n schema: SchemaVersionRow;\n}>;\n\n/**\n * Registers the fully materialized shape of a verified store as a durable\n * template. The original schema version is retained only as snapshot\n * provenance: every instantiated graph starts at v1 with that final shape.\n */\nexport async function registerGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ templateId: string; reconciled: ReconciledSchema<G> }>,\n): Promise<GraphTemplate<G>> {\n const register = backend.registerGraphTemplate;\n if (register === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const { reconciled } = params;\n if (reconciled.version === undefined || reconciled.hash === undefined) {\n throw new ConfigurationError(\n \"A graph template requires a reconciled schema from a managed or verified Store.\",\n { code: \"GRAPH_TEMPLATE_REQUIRES_RECONCILED_SCHEMA\" },\n );\n }\n if (\n resolveGraphVectorSlots(reconciled.graph).length > 0 &&\n backend.capabilities.vector?.supported === true\n ) {\n throw new ConfigurationError(\n \"Graph templates do not support embedding fields because vector storage is graph-scoped and cannot be instantiated schema-only.\",\n {\n code: \"GRAPH_TEMPLATE_VECTOR_UNSUPPORTED\",\n graphId: reconciled.graph.id,\n },\n {\n suggestion:\n \"Provision the graph through createStoreWithSchema until template instantiation can atomically materialize vector contributions.\",\n },\n );\n }\n const schemaDocument = serializeSchema(reconciled.graph, reconciled.version);\n const schemaHash = await computeSchemaHash(schemaDocument);\n if (schemaHash !== reconciled.hash) {\n throw new ConfigurationError(\n \"Reconciled schema hash does not match its graph snapshot.\",\n { code: \"GRAPH_TEMPLATE_RECONCILED_HASH_MISMATCH\" },\n );\n }\n await register({\n templateId: params.templateId,\n schemaHash,\n schemaDoc: schemaDocument,\n });\n return Object.freeze({\n id: params.templateId,\n reconciled,\n schemaHash,\n });\n}\n\n/**\n * Instantiates the template's final graph shape as target schema v1. Only the\n * target hash crosses the wire; the durable source document stays in the\n * backend template registry and is rebound to `graphId` by one SQL statement.\n */\nexport async function instantiateGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n const instantiate = backend.instantiateGraphTemplate;\n if (instantiate === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const sourceVersion = params.template.reconciled.version;\n const reconciledHash = params.template.reconciled.hash;\n if (sourceVersion === undefined || reconciledHash === undefined) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const sourceHash = await computeSchemaHash(\n serializeSchema(params.template.reconciled.graph, sourceVersion),\n );\n if (\n sourceHash !== params.template.schemaHash ||\n reconciledHash !== params.template.schemaHash\n ) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const targetGraph: G = Object.freeze({\n ...params.template.reconciled.graph,\n id: params.graphId,\n });\n const targetHash = await computeSchemaHash(serializeSchema(targetGraph, 1));\n const result = await instantiate({\n templateId: params.template.id,\n templateSchemaHash: params.template.schemaHash,\n graphId: params.graphId,\n schemaHash: targetHash,\n });\n if (result.status === \"refused\") {\n throw new ConfigurationError(\n `Graph template instantiation was refused for graph \"${params.graphId}\". The template may be absent, or the graph already has a different schema.`,\n {\n code: \"GRAPH_TEMPLATE_INSTANTIATION_REFUSED\",\n graphId: params.graphId,\n templateId: params.template.id,\n },\n );\n }\n if (\n result.row.graph_id !== params.graphId ||\n result.row.version !== 1 ||\n result.row.schema_hash !== targetHash\n ) {\n throw new ConfigurationError(\n \"Graph template backend returned a schema row that does not match the requested target.\",\n { code: \"GRAPH_TEMPLATE_INVALID_RESULT\", graphId: params.graphId },\n );\n }\n return Object.freeze({\n status: \"ready\",\n reconciled: Object.freeze({\n graph: targetGraph,\n version: result.row.version,\n hash: result.row.schema_hash,\n }),\n schema: result.row,\n });\n}\n\nfunction graphTemplateHandleMismatchError(\n templateId: string,\n): ConfigurationError {\n return new ConfigurationError(\n `Graph template handle \"${templateId}\" does not match its reconciled schema snapshot.`,\n { code: \"GRAPH_TEMPLATE_HANDLE_MISMATCH\", templateId },\n );\n}\n\n/** Short public name for {@link instantiateGraphTemplate}. */\nexport function instantiateGraph<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n return instantiateGraphTemplate(backend, params);\n}\n\nfunction graphTemplatesUnsupportedError(\n backend: GraphBackend,\n): ConfigurationError {\n return new ConfigurationError(\n `The ${backend.dialect} backend does not support durable graph templates.`,\n { code: \"GRAPH_TEMPLATES_UNSUPPORTED\", dialect: backend.dialect },\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/schema/deserializer.ts","../src/schema/graph-templates.ts"],"names":["hasOwnKey","build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,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAA,EAAQ,OAAA;AAAA,IACR,UAAA,EAAY,OAAO,MAAA,CAAO;AAAA,MACxB,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS,OAAO,GAAA,CAAI,OAAA;AAAA,MACpB,IAAA,EAAM,OAAO,GAAA,CAAI;AAAA,KAClB,CAAA;AAAA,IACD,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAEA,SAAS,iCACP,UAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,0BAA0B,UAAU,CAAA,gDAAA,CAAA;AAAA,IACpC,EAAE,IAAA,EAAM,gCAAA,EAAkC,UAAA;AAAW,GACvD;AACF;AAGO,SAAS,gBAAA,CACd,SACA,MAAA,EAC4C;AAC5C,EAAA,OAAO,wBAAA,CAAyB,SAAS,MAAM,CAAA;AACjD;AAEA,SAAS,+BACP,OAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,CAAA,IAAA,EAAO,QAAQ,OAAO,CAAA,kDAAA,CAAA;AAAA,IACtB,EAAE,IAAA,EAAM,6BAAA,EAA+B,OAAA,EAAS,QAAQ,OAAA;AAAQ,GAClE;AACF","file":"chunk-GXHEGNI6.cjs","sourcesContent":["/**\n * Schema deserializer for loading stored schemas.\n *\n * Reconstructs runtime objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { type AnyEdgeType, type NodeType } from \"../core/types\";\nimport { type NamedOntologyRelation } from \"../ontology/validation\";\nimport { buildValidatedKindRegistry } from \"../registry/build-validated\";\nimport type { KindRegistry } from \"../registry/kind-registry\";\nimport { type EdgeEndpointKinds } from \"../registry/validate-implies\";\nimport { hasOwnKey } from \"../utils/object\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the durable TypeGraph Identity Profile configuration. */\n getIdentity: () => SerializedSchema[\"identity\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a validated KindRegistry by recomputing closures from relations */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n // Own-key reads, for the same reason {@link buildEdgeEndpointKinds} below\n // uses a `Map`: `schema` is parsed out of a stored JSON document and the\n // caller supplies the name, so a raw read hands back an `Object.prototype`\n // member typed as a definition for any name no kind is registered under.\n getNode: (name) =>\n hasOwnKey(schema.nodes, name) ? schema.nodes[name] : undefined,\n getNodeNames: () => nodeNames,\n\n getEdge: (name) =>\n hasOwnKey(schema.edges, name) ? schema.edges[name] : undefined,\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) =>\n hasOwnKey(schema.ontology.metaEdges, name) ?\n schema.ontology.metaEdges[name]\n : undefined,\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getIdentity: () => schema.identity,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromRelations(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized relations.\n *\n * Persisted closures are a legacy inspection artifact. Relations are validated\n * and closures are recomputed so old schemas gain current hardening rules.\n */\nfunction buildRegistryFromRelations(schema: SerializedSchema): KindRegistry {\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map<string, NodeType>();\n const edgeKinds = new Map<string, AnyEdgeType>();\n return buildValidatedKindRegistry({\n nodeKinds,\n edgeKinds,\n ontology: schema.ontology.relations.map(\n (relation): NamedOntologyRelation => ({\n metaEdge: relation.metaEdge,\n from: relation.from,\n to: relation.to,\n }),\n ),\n edgeEndpoints: buildEdgeEndpointKinds(schema.edges),\n ...(schema.identity === undefined ? {} : { identity: schema.identity }),\n });\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n const pairs: { from: string; to: string }[] = [];\n if (def.targetKindsBySource === undefined) {\n for (const fromKind of def.fromKinds) {\n for (const toKind of def.toKinds) {\n pairs.push({ from: fromKind, to: toKind });\n }\n }\n } else {\n for (const [sourceKind, targetKinds] of Object.entries(\n def.targetKindsBySource,\n )) {\n for (const targetKind of targetKinds) {\n pairs.push({ from: sourceKind, to: targetKind });\n }\n }\n }\n result.set(kind, {\n from: def.fromKinds,\n to: def.toKinds,\n pairs,\n });\n }\n return result;\n}\n","import type { GraphBackend, SchemaVersionRow } from \"../backend/types\";\nimport { type GraphDef } from \"../core/define-graph\";\nimport { resolveGraphVectorSlots } from \"../core/embedding\";\nimport { ConfigurationError } from \"../errors\";\nimport { type ReconciledSchema } from \"../store/store\";\nimport { computeSchemaHash, serializeSchema } from \"./serializer\";\n\n/** A locally held handle for a durable server-side graph template. */\nexport type GraphTemplate<G extends GraphDef> = Readonly<{\n id: string;\n reconciled: ReconciledSchema<G>;\n schemaHash: string;\n}>;\n\nexport type InstantiateGraphTemplateResult<G extends GraphDef> = Readonly<{\n status: \"ready\";\n reconciled: ReconciledSchema<G>;\n schema: SchemaVersionRow;\n}>;\n\n/**\n * Registers the fully materialized shape of a verified store as a durable\n * template. The original schema version is retained only as snapshot\n * provenance: every instantiated graph starts at v1 with that final shape.\n */\nexport async function registerGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ templateId: string; reconciled: ReconciledSchema<G> }>,\n): Promise<GraphTemplate<G>> {\n const register = backend.registerGraphTemplate;\n if (register === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const { reconciled } = params;\n if (reconciled.version === undefined || reconciled.hash === undefined) {\n throw new ConfigurationError(\n \"A graph template requires a reconciled schema from a managed or verified Store.\",\n { code: \"GRAPH_TEMPLATE_REQUIRES_RECONCILED_SCHEMA\" },\n );\n }\n if (\n resolveGraphVectorSlots(reconciled.graph).length > 0 &&\n backend.capabilities.vector?.supported === true\n ) {\n throw new ConfigurationError(\n \"Graph templates do not support embedding fields because vector storage is graph-scoped and cannot be instantiated schema-only.\",\n {\n code: \"GRAPH_TEMPLATE_VECTOR_UNSUPPORTED\",\n graphId: reconciled.graph.id,\n },\n {\n suggestion:\n \"Provision the graph through createStoreWithSchema until template instantiation can atomically materialize vector contributions.\",\n },\n );\n }\n const schemaDocument = serializeSchema(reconciled.graph, reconciled.version);\n const schemaHash = await computeSchemaHash(schemaDocument);\n if (schemaHash !== reconciled.hash) {\n throw new ConfigurationError(\n \"Reconciled schema hash does not match its graph snapshot.\",\n { code: \"GRAPH_TEMPLATE_RECONCILED_HASH_MISMATCH\" },\n );\n }\n await register({\n templateId: params.templateId,\n schemaHash,\n schemaDoc: schemaDocument,\n });\n return Object.freeze({\n id: params.templateId,\n reconciled,\n schemaHash,\n });\n}\n\n/**\n * Instantiates the template's final graph shape as target schema v1. Only the\n * target hash crosses the wire; the durable source document stays in the\n * backend template registry and is rebound to `graphId` by one SQL statement.\n */\nexport async function instantiateGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n const instantiate = backend.instantiateGraphTemplate;\n if (instantiate === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const sourceVersion = params.template.reconciled.version;\n const reconciledHash = params.template.reconciled.hash;\n if (sourceVersion === undefined || reconciledHash === undefined) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const sourceHash = await computeSchemaHash(\n serializeSchema(params.template.reconciled.graph, sourceVersion),\n );\n if (\n sourceHash !== params.template.schemaHash ||\n reconciledHash !== params.template.schemaHash\n ) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const targetGraph: G = Object.freeze({\n ...params.template.reconciled.graph,\n id: params.graphId,\n });\n const targetHash = await computeSchemaHash(serializeSchema(targetGraph, 1));\n const result = await instantiate({\n templateId: params.template.id,\n templateSchemaHash: params.template.schemaHash,\n graphId: params.graphId,\n schemaHash: targetHash,\n });\n if (result.status === \"refused\") {\n throw new ConfigurationError(\n `Graph template instantiation was refused for graph \"${params.graphId}\". The template may be absent, or the graph already has a different schema.`,\n {\n code: \"GRAPH_TEMPLATE_INSTANTIATION_REFUSED\",\n graphId: params.graphId,\n templateId: params.template.id,\n },\n );\n }\n if (\n result.row.graph_id !== params.graphId ||\n result.row.version !== 1 ||\n result.row.schema_hash !== targetHash\n ) {\n throw new ConfigurationError(\n \"Graph template backend returned a schema row that does not match the requested target.\",\n { code: \"GRAPH_TEMPLATE_INVALID_RESULT\", graphId: params.graphId },\n );\n }\n return Object.freeze({\n status: \"ready\",\n reconciled: Object.freeze({\n graph: targetGraph,\n version: result.row.version,\n hash: result.row.schema_hash,\n }),\n schema: result.row,\n });\n}\n\nfunction graphTemplateHandleMismatchError(\n templateId: string,\n): ConfigurationError {\n return new ConfigurationError(\n `Graph template handle \"${templateId}\" does not match its reconciled schema snapshot.`,\n { code: \"GRAPH_TEMPLATE_HANDLE_MISMATCH\", templateId },\n );\n}\n\n/** Short public name for {@link instantiateGraphTemplate}. */\nexport function instantiateGraph<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n return instantiateGraphTemplate(backend, params);\n}\n\nfunction graphTemplatesUnsupportedError(\n backend: GraphBackend,\n): ConfigurationError {\n return new ConfigurationError(\n `The ${backend.dialect} backend does not support durable graph templates.`,\n { code: \"GRAPH_TEMPLATES_UNSUPPORTED\", dialect: backend.dialect },\n );\n}\n"]}
@@ -573,6 +573,10 @@ async function getSchemaHash(graph, version) {
573
573
  }
574
574
  return hash;
575
575
  }
576
+ var DEFINITION_HASH_VERSION = 1;
577
+ async function getGraphDefinitionHash(graph) {
578
+ return getSchemaHash(graph, DEFINITION_HASH_VERSION);
579
+ }
576
580
  async function computeSchemaHash(schema) {
577
581
  const hashable = {
578
582
  graphId: schema.graphId,
@@ -3809,6 +3813,7 @@ exports.equivalentTo = equivalentTo;
3809
3813
  exports.extensionKindNames = extensionKindNames;
3810
3814
  exports.getActiveSchema = getActiveSchema;
3811
3815
  exports.getCommittedSchemaVersion = getCommittedSchemaVersion;
3816
+ exports.getGraphDefinitionHash = getGraphDefinitionHash;
3812
3817
  exports.getMigrationActions = getMigrationActions;
3813
3818
  exports.getSchemaChanges = getSchemaChanges;
3814
3819
  exports.hasPart = hasPart;
@@ -3839,5 +3844,5 @@ exports.serializeSchema = serializeSchema;
3839
3844
  exports.serializeSchemaProperties = serializeSchemaProperties;
3840
3845
  exports.stripGraphExtension = stripGraphExtension;
3841
3846
  exports.subClassOf = subClassOf;
3842
- //# sourceMappingURL=chunk-BX42F7IJ.cjs.map
3843
- //# sourceMappingURL=chunk-BX42F7IJ.cjs.map
3847
+ //# sourceMappingURL=chunk-SSDLQPMY.cjs.map
3848
+ //# sourceMappingURL=chunk-SSDLQPMY.cjs.map