@nicia-ai/typegraph 0.2.0 → 0.3.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 (146) hide show
  1. package/README.md +23 -0
  2. package/dist/{ast-BVyihVbP.d.cts → ast-CXFx6bF6.d.ts} +45 -165
  3. package/dist/{ast-BVyihVbP.d.ts → ast-D-3bOanX.d.cts} +45 -165
  4. package/dist/backend/drizzle/index.cjs +20 -20
  5. package/dist/backend/drizzle/index.d.cts +6 -5
  6. package/dist/backend/drizzle/index.d.ts +6 -5
  7. package/dist/backend/drizzle/index.js +8 -8
  8. package/dist/backend/drizzle/postgres.cjs +9 -9
  9. package/dist/backend/drizzle/postgres.d.cts +9 -11
  10. package/dist/backend/drizzle/postgres.d.ts +9 -11
  11. package/dist/backend/drizzle/postgres.js +6 -6
  12. package/dist/backend/drizzle/schema/postgres.cjs +10 -10
  13. package/dist/backend/drizzle/schema/postgres.d.cts +6 -5
  14. package/dist/backend/drizzle/schema/postgres.d.ts +6 -5
  15. package/dist/backend/drizzle/schema/postgres.js +3 -3
  16. package/dist/backend/drizzle/schema/sqlite.cjs +10 -10
  17. package/dist/backend/drizzle/schema/sqlite.d.cts +6 -5
  18. package/dist/backend/drizzle/schema/sqlite.d.ts +6 -5
  19. package/dist/backend/drizzle/schema/sqlite.js +3 -3
  20. package/dist/backend/drizzle/sqlite.cjs +9 -9
  21. package/dist/backend/drizzle/sqlite.d.cts +17 -18
  22. package/dist/backend/drizzle/sqlite.d.ts +17 -18
  23. package/dist/backend/drizzle/sqlite.js +6 -6
  24. package/dist/backend/postgres/index.cjs +21 -17
  25. package/dist/backend/postgres/index.d.cts +8 -7
  26. package/dist/backend/postgres/index.d.ts +8 -7
  27. package/dist/backend/postgres/index.js +8 -8
  28. package/dist/backend/sqlite/index.cjs +27 -21
  29. package/dist/backend/sqlite/index.cjs.map +1 -1
  30. package/dist/backend/sqlite/index.d.cts +7 -6
  31. package/dist/backend/sqlite/index.d.ts +7 -6
  32. package/dist/backend/sqlite/index.js +18 -12
  33. package/dist/backend/sqlite/index.js.map +1 -1
  34. package/dist/{chunk-YM5AL65Y.cjs → chunk-2WVFEIHR.cjs} +29 -3
  35. package/dist/chunk-2WVFEIHR.cjs.map +1 -0
  36. package/dist/{chunk-4PIEL2VO.js → chunk-3PURVEA4.js} +36 -5
  37. package/dist/chunk-3PURVEA4.js.map +1 -0
  38. package/dist/chunk-4HARSV2G.js +1448 -0
  39. package/dist/chunk-4HARSV2G.js.map +1 -0
  40. package/dist/{chunk-IIAT36MI.js → chunk-54WJF3DW.js} +29 -3
  41. package/dist/chunk-54WJF3DW.js.map +1 -0
  42. package/dist/chunk-CMHFS34N.cjs +390 -0
  43. package/dist/chunk-CMHFS34N.cjs.map +1 -0
  44. package/dist/chunk-DD6ONEBN.cjs +1264 -0
  45. package/dist/chunk-DD6ONEBN.cjs.map +1 -0
  46. package/dist/chunk-F2BZSEFE.js +388 -0
  47. package/dist/chunk-F2BZSEFE.js.map +1 -0
  48. package/dist/{chunk-DDM2FZRJ.cjs → chunk-JQDWEX6V.cjs} +24 -24
  49. package/dist/{chunk-DDM2FZRJ.cjs.map → chunk-JQDWEX6V.cjs.map} +1 -1
  50. package/dist/chunk-NP4G4ZKM.js +1228 -0
  51. package/dist/chunk-NP4G4ZKM.js.map +1 -0
  52. package/dist/{chunk-UJAGXJDG.cjs → chunk-NU2XNMVI.cjs} +38 -7
  53. package/dist/chunk-NU2XNMVI.cjs.map +1 -0
  54. package/dist/{chunk-JKTO7TW3.js → chunk-O5XPCJLF.js} +25 -3
  55. package/dist/chunk-O5XPCJLF.js.map +1 -0
  56. package/dist/{chunk-2QHQ2C4P.js → chunk-OGGLFYFA.js} +36 -5
  57. package/dist/chunk-OGGLFYFA.js.map +1 -0
  58. package/dist/{chunk-SV5H3XM5.cjs → chunk-OYL2SGBD.cjs} +26 -2
  59. package/dist/chunk-OYL2SGBD.cjs.map +1 -0
  60. package/dist/chunk-SFY2PPOY.cjs +1469 -0
  61. package/dist/chunk-SFY2PPOY.cjs.map +1 -0
  62. package/dist/{chunk-JDAET5LO.js → chunk-SMLIWLS7.js} +9 -9
  63. package/dist/chunk-SMLIWLS7.js.map +1 -0
  64. package/dist/{chunk-VXRVGFCI.js → chunk-U3452TEU.js} +17 -17
  65. package/dist/{chunk-VXRVGFCI.js.map → chunk-U3452TEU.js.map} +1 -1
  66. package/dist/{chunk-MNO33ASC.cjs → chunk-UYMT4LO2.cjs} +9 -8
  67. package/dist/chunk-UYMT4LO2.cjs.map +1 -0
  68. package/dist/chunk-V7CS2MDB.cjs +289 -0
  69. package/dist/chunk-V7CS2MDB.cjs.map +1 -0
  70. package/dist/chunk-WE5BKYNB.js +287 -0
  71. package/dist/chunk-WE5BKYNB.js.map +1 -0
  72. package/dist/{chunk-L642L24T.js → chunk-XDTYTNYL.js} +14 -21
  73. package/dist/chunk-XDTYTNYL.js.map +1 -0
  74. package/dist/{chunk-N4AOJ3VF.cjs → chunk-XZL6MCZJ.cjs} +38 -7
  75. package/dist/chunk-XZL6MCZJ.cjs.map +1 -0
  76. package/dist/{chunk-DBFCKELK.cjs → chunk-ZJHQZZT2.cjs} +18 -27
  77. package/dist/chunk-ZJHQZZT2.cjs.map +1 -0
  78. package/dist/index-Dkicw49A.d.cts +373 -0
  79. package/dist/index-Dkicw49A.d.ts +373 -0
  80. package/dist/index.cjs +5915 -3377
  81. package/dist/index.cjs.map +1 -1
  82. package/dist/index.d.cts +24 -664
  83. package/dist/index.d.ts +24 -664
  84. package/dist/index.js +5781 -3223
  85. package/dist/index.js.map +1 -1
  86. package/dist/indexes/index.cjs +16 -16
  87. package/dist/indexes/index.d.cts +5 -4
  88. package/dist/indexes/index.d.ts +5 -4
  89. package/dist/indexes/index.js +2 -2
  90. package/dist/interchange/index.cjs +9 -9
  91. package/dist/interchange/index.cjs.map +1 -1
  92. package/dist/interchange/index.d.cts +5 -3
  93. package/dist/interchange/index.d.ts +5 -3
  94. package/dist/interchange/index.js +8 -8
  95. package/dist/interchange/index.js.map +1 -1
  96. package/dist/manager-Jc5Btay9.d.cts +493 -0
  97. package/dist/manager-e9LXthrx.d.ts +493 -0
  98. package/dist/profiler/index.cjs +2 -8
  99. package/dist/profiler/index.cjs.map +1 -1
  100. package/dist/profiler/index.d.cts +9 -161
  101. package/dist/profiler/index.d.ts +9 -161
  102. package/dist/profiler/index.js +4 -4
  103. package/dist/profiler/index.js.map +1 -1
  104. package/dist/schema/index.cjs +145 -0
  105. package/dist/schema/index.cjs.map +1 -0
  106. package/dist/schema/index.d.cts +237 -0
  107. package/dist/schema/index.d.ts +237 -0
  108. package/dist/schema/index.js +72 -0
  109. package/dist/schema/index.js.map +1 -0
  110. package/dist/{store-BPhjw5S8.d.ts → store-DM3Tk3Pw.d.ts} +874 -1283
  111. package/dist/{store-DNOOQEm8.d.cts → store-nbBybLWP.d.cts} +874 -1283
  112. package/dist/{test-helpers-BjyRYJZX.d.ts → test-helpers-CIq1Hhj1.d.ts} +5 -1
  113. package/dist/{test-helpers-NoQXhleQ.d.cts → test-helpers-DPRFVky4.d.cts} +5 -1
  114. package/dist/{types-D_3mEv2y.d.ts → types-BL1GyVku.d.cts} +2 -2
  115. package/dist/{types-DsRfx0yk.d.ts → types-Cdbi4hcx.d.ts} +228 -4
  116. package/dist/{types-BrSfFSpW.d.cts → types-DCGa53O2.d.ts} +2 -2
  117. package/dist/{types-aapj0GLz.d.cts → types-DDP0MGBF.d.cts} +228 -4
  118. package/dist/{types-CX4cLd7M.d.ts → types-DHRsi6j9.d.cts} +4 -3
  119. package/dist/types-DTJEu_-h.d.cts +158 -0
  120. package/dist/types-DTJEu_-h.d.ts +158 -0
  121. package/dist/{types-a5rAxC92.d.cts → types-ZT5mlism.d.ts} +4 -3
  122. package/package.json +17 -2
  123. package/dist/chunk-2FURVVAX.cjs +0 -350
  124. package/dist/chunk-2FURVVAX.cjs.map +0 -1
  125. package/dist/chunk-2QHQ2C4P.js.map +0 -1
  126. package/dist/chunk-4PIEL2VO.js.map +0 -1
  127. package/dist/chunk-DBFCKELK.cjs.map +0 -1
  128. package/dist/chunk-H7THXVH6.cjs +0 -314
  129. package/dist/chunk-H7THXVH6.cjs.map +0 -1
  130. package/dist/chunk-HXAPXPZH.cjs +0 -680
  131. package/dist/chunk-HXAPXPZH.cjs.map +0 -1
  132. package/dist/chunk-IIAT36MI.js.map +0 -1
  133. package/dist/chunk-JDAET5LO.js.map +0 -1
  134. package/dist/chunk-JKTO7TW3.js.map +0 -1
  135. package/dist/chunk-L642L24T.js.map +0 -1
  136. package/dist/chunk-MNO33ASC.cjs.map +0 -1
  137. package/dist/chunk-N4AOJ3VF.cjs.map +0 -1
  138. package/dist/chunk-QB3WBMDT.js +0 -646
  139. package/dist/chunk-QB3WBMDT.js.map +0 -1
  140. package/dist/chunk-SV5H3XM5.cjs.map +0 -1
  141. package/dist/chunk-UJAGXJDG.cjs.map +0 -1
  142. package/dist/chunk-X4EVMBON.js +0 -312
  143. package/dist/chunk-X4EVMBON.js.map +0 -1
  144. package/dist/chunk-XZL4NLV6.js +0 -348
  145. package/dist/chunk-XZL4NLV6.js.map +0 -1
  146. package/dist/chunk-YM5AL65Y.cjs.map +0 -1
@@ -0,0 +1,493 @@
1
+ import { a as NodeRegistration, b as EdgeRegistration, D as DeleteBehavior, T as TemporalMode, N as NodeType, c as EdgeTypeWithEndpoints, G as GraphDefaults, A as AnyEdgeType } from './types-DTJEu_-h.cjs';
2
+ import { O as OntologyRelation, S as SerializedNodeDef, a as SerializedEdgeDef, e as SerializedSchema, G as GraphBackend, i as SchemaVersionRow } from './types-DDP0MGBF.cjs';
3
+
4
+ /** Brand key for GraphDef */
5
+ declare const GRAPH_DEF_BRAND: "__graphDef";
6
+ /**
7
+ * An edge entry in the graph definition.
8
+ * Can be:
9
+ * - EdgeType directly (if it has from/to defined)
10
+ * - EdgeRegistration object (always works, can override/narrow defaults)
11
+ */
12
+ type EdgeEntry = EdgeRegistration | EdgeTypeWithEndpoints;
13
+ /**
14
+ * Normalized edge map type - all entries become EdgeRegistration.
15
+ */
16
+ type NormalizedEdges<TEdges extends Record<string, EdgeEntry>> = {
17
+ [K in keyof TEdges]: TEdges[K] extends EdgeRegistration ? TEdges[K] : TEdges[K] extends EdgeTypeWithEndpoints ? EdgeRegistration<TEdges[K], TEdges[K]["from"][number], TEdges[K]["to"][number]> : never;
18
+ };
19
+ /**
20
+ * Configuration for defineGraph.
21
+ */
22
+ type GraphDefConfig<TNodes extends Record<string, NodeRegistration>, TEdges extends Record<string, EdgeEntry>, TOntology extends readonly OntologyRelation[]> = Readonly<{
23
+ /** Unique identifier for this graph */
24
+ id: string;
25
+ /** Node registrations */
26
+ nodes: TNodes;
27
+ /** Edge registrations or EdgeTypes with built-in domain/range */
28
+ edges: TEdges;
29
+ /** Ontology relations */
30
+ ontology?: TOntology;
31
+ /** Graph-wide defaults */
32
+ defaults?: GraphDefaults;
33
+ }>;
34
+ /**
35
+ * A graph definition.
36
+ *
37
+ * This is a compile-time artifact that describes the structure of a graph.
38
+ * Use `createStore()` to create a runtime store from this definition.
39
+ */
40
+ type GraphDef<TNodes extends Record<string, NodeRegistration> = Record<string, NodeRegistration>, TEdges extends Record<string, EdgeRegistration> = Record<string, EdgeRegistration>, TOntology extends readonly OntologyRelation[] = readonly OntologyRelation[]> = Readonly<{
41
+ [GRAPH_DEF_BRAND]: true;
42
+ id: string;
43
+ nodes: TNodes;
44
+ edges: TEdges;
45
+ ontology: TOntology;
46
+ defaults: Readonly<{
47
+ onNodeDelete: DeleteBehavior;
48
+ temporalMode: TemporalMode;
49
+ }>;
50
+ }>;
51
+ /**
52
+ * Extract node kind names from a GraphDef.
53
+ */
54
+ type NodeKinds<G extends GraphDef> = keyof G["nodes"] & string;
55
+ /**
56
+ * Extract edge kind names from a GraphDef.
57
+ */
58
+ type EdgeKinds<G extends GraphDef> = keyof G["edges"] & string;
59
+ /**
60
+ * Get a NodeType from a GraphDef by kind name.
61
+ */
62
+ type GetNodeType<G extends GraphDef, K extends NodeKinds<G>> = G["nodes"][K]["type"];
63
+ /**
64
+ * Get an EdgeType from a GraphDef by kind name.
65
+ */
66
+ type GetEdgeType<G extends GraphDef, K extends EdgeKinds<G>> = G["edges"][K]["type"];
67
+ /**
68
+ * Get all NodeTypes from a GraphDef.
69
+ */
70
+ type AllNodeTypes<G extends GraphDef> = {
71
+ [K in NodeKinds<G>]: G["nodes"][K]["type"];
72
+ }[NodeKinds<G>];
73
+ /**
74
+ * Get all EdgeTypes from a GraphDef.
75
+ */
76
+ type AllEdgeTypes<G extends GraphDef> = {
77
+ [K in EdgeKinds<G>]: G["edges"][K]["type"];
78
+ }[EdgeKinds<G>];
79
+ /**
80
+ * Creates a graph definition.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const graph = defineGraph({
85
+ * id: "my_graph",
86
+ * nodes: {
87
+ * Person: { type: Person },
88
+ * Company: { type: Company },
89
+ * },
90
+ * edges: {
91
+ * // Traditional EdgeRegistration syntax
92
+ * worksAt: {
93
+ * type: worksAt,
94
+ * from: [Person],
95
+ * to: [Company],
96
+ * cardinality: "many",
97
+ * },
98
+ * // Or use EdgeType directly if it has from/to defined
99
+ * knows, // EdgeType with built-in domain/range
100
+ * },
101
+ * ontology: [
102
+ * subClassOf(Company, Organization),
103
+ * disjointWith(Person, Organization),
104
+ * ],
105
+ * defaults: {
106
+ * onNodeDelete: "restrict",
107
+ * temporalMode: "current",
108
+ * },
109
+ * });
110
+ * ```
111
+ */
112
+ declare function defineGraph<TNodes extends Record<string, NodeRegistration<NodeType>>, TEdges extends Record<string, EdgeEntry>, TOntology extends readonly OntologyRelation[]>(config: GraphDefConfig<TNodes, TEdges, TOntology>): GraphDef<TNodes, NormalizedEdges<TEdges>, TOntology>;
113
+ /**
114
+ * Checks if a value is a GraphDef.
115
+ */
116
+ declare function isGraphDef(value: unknown): value is GraphDef;
117
+ /**
118
+ * Gets all node kind names from a GraphDef.
119
+ */
120
+ declare function getNodeKinds<G extends GraphDef>(graph: G): readonly string[];
121
+ /**
122
+ * Gets all edge kind names from a GraphDef.
123
+ */
124
+ declare function getEdgeKinds<G extends GraphDef>(graph: G): readonly string[];
125
+
126
+ /**
127
+ * KindRegistry holds precomputed closures for ontological reasoning.
128
+ *
129
+ * Computed at store initialization and cached for fast query-time lookups.
130
+ */
131
+ declare class KindRegistry {
132
+ readonly nodeKinds: ReadonlyMap<string, NodeType>;
133
+ readonly edgeKinds: ReadonlyMap<string, AnyEdgeType>;
134
+ readonly subClassAncestors: ReadonlyMap<string, ReadonlySet<string>>;
135
+ readonly subClassDescendants: ReadonlyMap<string, ReadonlySet<string>>;
136
+ readonly broaderClosure: ReadonlyMap<string, ReadonlySet<string>>;
137
+ readonly narrowerClosure: ReadonlyMap<string, ReadonlySet<string>>;
138
+ readonly equivalenceSets: ReadonlyMap<string, ReadonlySet<string>>;
139
+ readonly iriToKind: ReadonlyMap<string, string>;
140
+ readonly disjointPairs: ReadonlySet<string>;
141
+ readonly partOfClosure: ReadonlyMap<string, ReadonlySet<string>>;
142
+ readonly hasPartClosure: ReadonlyMap<string, ReadonlySet<string>>;
143
+ readonly edgeInverses: ReadonlyMap<string, string>;
144
+ readonly edgeImplicationsClosure: ReadonlyMap<string, ReadonlySet<string>>;
145
+ readonly edgeImplyingClosure: ReadonlyMap<string, ReadonlySet<string>>;
146
+ constructor(nodeKinds: ReadonlyMap<string, NodeType>, edgeKinds: ReadonlyMap<string, AnyEdgeType>, closures: {
147
+ subClassAncestors: ReadonlyMap<string, ReadonlySet<string>>;
148
+ subClassDescendants: ReadonlyMap<string, ReadonlySet<string>>;
149
+ broaderClosure: ReadonlyMap<string, ReadonlySet<string>>;
150
+ narrowerClosure: ReadonlyMap<string, ReadonlySet<string>>;
151
+ equivalenceSets: ReadonlyMap<string, ReadonlySet<string>>;
152
+ iriToKind: ReadonlyMap<string, string>;
153
+ disjointPairs: ReadonlySet<string>;
154
+ partOfClosure: ReadonlyMap<string, ReadonlySet<string>>;
155
+ hasPartClosure: ReadonlyMap<string, ReadonlySet<string>>;
156
+ edgeInverses: ReadonlyMap<string, string>;
157
+ edgeImplicationsClosure: ReadonlyMap<string, ReadonlySet<string>>;
158
+ edgeImplyingClosure: ReadonlyMap<string, ReadonlySet<string>>;
159
+ });
160
+ /**
161
+ * Checks if child is a subclass of parent (directly or transitively).
162
+ */
163
+ isSubClassOf(child: string, parent: string): boolean;
164
+ /**
165
+ * Expands a kind to include all its subclasses.
166
+ * Returns [kind, ...subclasses].
167
+ */
168
+ expandSubClasses(kind: string): readonly string[];
169
+ /**
170
+ * Gets all ancestors of a kind (via subClassOf).
171
+ */
172
+ getAncestors(kind: string): ReadonlySet<string>;
173
+ /**
174
+ * Gets all descendants of a kind (via subClassOf).
175
+ */
176
+ getDescendants(kind: string): ReadonlySet<string>;
177
+ /**
178
+ * Checks if narrowerConcept is narrower than broaderConcept.
179
+ */
180
+ isNarrowerThan(narrowerConcept: string, broaderConcept: string): boolean;
181
+ /**
182
+ * Checks if broaderConcept is broader than narrowerConcept.
183
+ */
184
+ isBroaderThan(broaderConcept: string, narrowerConcept: string): boolean;
185
+ /**
186
+ * Expands to include all narrower concepts.
187
+ */
188
+ expandNarrower(kind: string): readonly string[];
189
+ /**
190
+ * Expands to include all broader concepts.
191
+ */
192
+ expandBroader(kind: string): readonly string[];
193
+ /**
194
+ * Checks if two kinds are equivalent.
195
+ */
196
+ areEquivalent(a: string, b: string): boolean;
197
+ /**
198
+ * Gets all equivalents of a kind (including external IRIs).
199
+ */
200
+ getEquivalents(kind: string): readonly string[];
201
+ /**
202
+ * Resolves an external IRI to an internal kind name.
203
+ */
204
+ resolveIri(iri: string): string | undefined;
205
+ /**
206
+ * Checks if two kinds are disjoint.
207
+ */
208
+ areDisjoint(a: string, b: string): boolean;
209
+ /**
210
+ * Gets all kinds that are disjoint with the given kind.
211
+ */
212
+ getDisjointKinds(kind: string): readonly string[];
213
+ /**
214
+ * Checks if part is part of whole (directly or transitively).
215
+ */
216
+ isPartOf(part: string, whole: string): boolean;
217
+ /**
218
+ * Gets all wholes that contain this part.
219
+ */
220
+ getWholes(part: string): readonly string[];
221
+ /**
222
+ * Gets all parts of this whole.
223
+ */
224
+ getParts(whole: string): readonly string[];
225
+ /**
226
+ * Gets the inverse edge kind for a given edge kind.
227
+ * If edgeA inverseOf edgeB, then getInverseEdge("edgeA") returns "edgeB".
228
+ */
229
+ getInverseEdge(edgeKind: string): string | undefined;
230
+ /**
231
+ * Gets all edges implied by a given edge (transitively).
232
+ * If A implies B and B implies C, then getImpliedEdges("A") returns ["B", "C"].
233
+ */
234
+ getImpliedEdges(edgeKind: string): readonly string[];
235
+ /**
236
+ * Gets all edges that imply a given edge (transitively).
237
+ * If A implies B and B implies C, then getImplyingEdges("C") returns ["A", "B"].
238
+ * Used for query-time expansion: when querying for C, also include A and B edges.
239
+ */
240
+ getImplyingEdges(edgeKind: string): readonly string[];
241
+ /**
242
+ * Expands an edge kind to include all edges that imply it.
243
+ * Returns [edgeKind, ...implyingEdges].
244
+ */
245
+ expandImplyingEdges(edgeKind: string): readonly string[];
246
+ /**
247
+ * Checks if a concrete kind is assignable to a target kind.
248
+ * Uses subsumption: Company is assignable to Organization if Company subClassOf Organization.
249
+ */
250
+ isAssignableTo(concreteKind: string, targetKind: string): boolean;
251
+ /**
252
+ * Validates that a kind exists in the registry.
253
+ */
254
+ hasNodeType(name: string): boolean;
255
+ /**
256
+ * Validates that an edge kind exists in the registry.
257
+ */
258
+ hasEdgeType(name: string): boolean;
259
+ /**
260
+ * Gets a node kind by name.
261
+ */
262
+ getNodeType(name: string): NodeType | undefined;
263
+ /**
264
+ * Gets an edge kind by name.
265
+ */
266
+ getEdgeType(name: string): AnyEdgeType | undefined;
267
+ }
268
+
269
+ /**
270
+ * Schema migration utilities.
271
+ *
272
+ * Provides diff detection between schema versions to identify
273
+ * what has changed and what migrations might be needed.
274
+ */
275
+
276
+ /**
277
+ * Types of changes that can occur in a schema.
278
+ */
279
+ type ChangeType = "added" | "removed" | "modified" | "renamed";
280
+ /**
281
+ * Severity of a change for migration purposes.
282
+ */
283
+ type ChangeSeverity = "safe" | "warning" | "breaking";
284
+ /**
285
+ * A change to a node definition.
286
+ */
287
+ type NodeChange = Readonly<{
288
+ type: ChangeType;
289
+ kind: string;
290
+ severity: ChangeSeverity;
291
+ details: string;
292
+ before?: SerializedNodeDef | undefined;
293
+ after?: SerializedNodeDef | undefined;
294
+ }>;
295
+ /**
296
+ * A change to an edge definition.
297
+ */
298
+ type EdgeChange = Readonly<{
299
+ type: ChangeType;
300
+ kind: string;
301
+ severity: ChangeSeverity;
302
+ details: string;
303
+ before?: SerializedEdgeDef | undefined;
304
+ after?: SerializedEdgeDef | undefined;
305
+ }>;
306
+ /**
307
+ * A change to the ontology.
308
+ */
309
+ type OntologyChange = Readonly<{
310
+ type: ChangeType;
311
+ entity: "metaEdge" | "relation";
312
+ name: string;
313
+ severity: ChangeSeverity;
314
+ details: string;
315
+ }>;
316
+ /**
317
+ * A complete diff between two schema versions.
318
+ */
319
+ type SchemaDiff = Readonly<{
320
+ fromVersion: number;
321
+ toVersion: number;
322
+ /** Changes to node definitions */
323
+ nodes: readonly NodeChange[];
324
+ /** Changes to edge definitions */
325
+ edges: readonly EdgeChange[];
326
+ /** Changes to ontology */
327
+ ontology: readonly OntologyChange[];
328
+ /** Whether any breaking changes exist */
329
+ hasBreakingChanges: boolean;
330
+ /** Whether the change is backwards compatible (no breaking changes) */
331
+ isBackwardsCompatible: boolean;
332
+ /** Whether any changes exist at all */
333
+ hasChanges: boolean;
334
+ /** Summary of changes */
335
+ summary: string;
336
+ }>;
337
+ /**
338
+ * Computes the diff between two schema versions.
339
+ *
340
+ * @param before - The previous schema version
341
+ * @param after - The new schema version
342
+ * @returns A diff describing all changes
343
+ */
344
+ declare function computeSchemaDiff(before: SerializedSchema, after: SerializedSchema): SchemaDiff;
345
+ /**
346
+ * Checks if a schema change is backwards compatible.
347
+ *
348
+ * A change is backwards compatible if:
349
+ * - No nodes or edges were removed
350
+ * - No required properties were added
351
+ * - No existing properties were removed
352
+ */
353
+ declare function isBackwardsCompatible(diff: SchemaDiff): boolean;
354
+ /**
355
+ * Gets a list of actions needed for migration.
356
+ */
357
+ declare function getMigrationActions(diff: SchemaDiff): readonly string[];
358
+
359
+ /**
360
+ * Schema manager for TypeGraph.
361
+ *
362
+ * Provides schema lifecycle management:
363
+ * - Initialization on first store creation
364
+ * - Validation on store open
365
+ * - Auto-migration for safe changes
366
+ * - Error reporting for breaking changes
367
+ */
368
+
369
+ /**
370
+ * Result of schema validation.
371
+ */
372
+ type SchemaValidationResult = {
373
+ status: "initialized";
374
+ version: number;
375
+ } | {
376
+ status: "unchanged";
377
+ version: number;
378
+ } | {
379
+ status: "migrated";
380
+ fromVersion: number;
381
+ toVersion: number;
382
+ diff: SchemaDiff;
383
+ } | {
384
+ status: "pending";
385
+ version: number;
386
+ diff: SchemaDiff;
387
+ } | {
388
+ status: "breaking";
389
+ diff: SchemaDiff;
390
+ actions: readonly string[];
391
+ };
392
+ /**
393
+ * Context passed to migration lifecycle hooks.
394
+ *
395
+ * Hooks are intended for observability (logging, metrics, alerts),
396
+ * not for data transformations. Use an explicit migration runner
397
+ * for backfill scripts — see the schema evolution guide.
398
+ */
399
+ type MigrationHookContext = Readonly<{
400
+ graphId: string;
401
+ fromVersion: number;
402
+ toVersion: number;
403
+ diff: SchemaDiff;
404
+ }>;
405
+ /**
406
+ * Options for schema management.
407
+ */
408
+ type SchemaManagerOptions = Readonly<{
409
+ /** If true, auto-migrate safe changes. Default: true */
410
+ autoMigrate?: boolean;
411
+ /** If true, throw on breaking changes. Default: true */
412
+ throwOnBreaking?: boolean;
413
+ /** Called before a safe auto-migration is applied. For observability only. */
414
+ onBeforeMigrate?: (context: MigrationHookContext) => void | Promise<void>;
415
+ /** Called after a safe auto-migration is applied. For observability only. */
416
+ onAfterMigrate?: (context: MigrationHookContext) => void | Promise<void>;
417
+ }>;
418
+ /**
419
+ * Ensures the schema is initialized and up-to-date.
420
+ *
421
+ * This is the main entry point for schema management. It:
422
+ * 1. Initializes the schema if this is the first run (version 1)
423
+ * 2. Returns "unchanged" if the schema matches the current graph
424
+ * 3. Auto-migrates safe changes if autoMigrate is true
425
+ * 4. Throws MigrationError for breaking changes if throwOnBreaking is true
426
+ *
427
+ * @param backend - The database backend
428
+ * @param graph - The current graph definition
429
+ * @param options - Schema management options
430
+ * @returns The result of schema validation
431
+ * @throws MigrationError if breaking changes detected and throwOnBreaking is true
432
+ */
433
+ declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions): Promise<SchemaValidationResult>;
434
+ /**
435
+ * Initializes the schema for a new graph.
436
+ *
437
+ * Creates version 1 of the schema and marks it as active.
438
+ *
439
+ * @param backend - The database backend
440
+ * @param graph - The graph definition
441
+ * @returns The created schema version row
442
+ */
443
+ declare function initializeSchema<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<SchemaVersionRow>;
444
+ /**
445
+ * Migrates the schema to match the current graph definition.
446
+ *
447
+ * This creates a new schema version and marks it as active.
448
+ * The old version is preserved for history/rollback.
449
+ *
450
+ * @param backend - The database backend
451
+ * @param graph - The current graph definition
452
+ * @param currentVersion - The current active schema version
453
+ * @returns The new version number
454
+ */
455
+ declare function migrateSchema<G extends GraphDef>(backend: GraphBackend, graph: G, currentVersion: number): Promise<number>;
456
+ /**
457
+ * Rolls back the active schema to a previous version.
458
+ *
459
+ * The target version must already exist in the version history.
460
+ * This does not delete newer versions — it simply switches the active pointer.
461
+ *
462
+ * @param backend - The database backend
463
+ * @param graphId - The graph ID
464
+ * @param targetVersion - The version to roll back to
465
+ * @throws MigrationError if the target version does not exist
466
+ */
467
+ declare function rollbackSchema(backend: GraphBackend, graphId: string, targetVersion: number): Promise<void>;
468
+ /**
469
+ * Gets the current active schema for a graph.
470
+ *
471
+ * @param backend - The database backend
472
+ * @param graphId - The graph ID
473
+ * @returns The active schema or undefined if not initialized
474
+ */
475
+ declare function getActiveSchema(backend: GraphBackend, graphId: string): Promise<SerializedSchema | undefined>;
476
+ /**
477
+ * Checks if a graph's schema has been initialized.
478
+ *
479
+ * @param backend - The database backend
480
+ * @param graphId - The graph ID
481
+ * @returns True if the schema has been initialized
482
+ */
483
+ declare function isSchemaInitialized(backend: GraphBackend, graphId: string): Promise<boolean>;
484
+ /**
485
+ * Gets the schema diff between the stored schema and current graph.
486
+ *
487
+ * @param backend - The database backend
488
+ * @param graph - The current graph definition
489
+ * @returns The diff, or undefined if schema not initialized
490
+ */
491
+ declare function getSchemaChanges<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<SchemaDiff | undefined>;
492
+
493
+ export { type AllEdgeTypes as A, type ChangeSeverity as C, type EdgeChange as E, type GraphDef as G, KindRegistry as K, type MigrationHookContext as M, type NodeChange as N, type OntologyChange as O, type SchemaDiff as S, type ChangeType as a, type SchemaManagerOptions as b, type SchemaValidationResult as c, computeSchemaDiff as d, ensureSchema as e, getMigrationActions as f, getActiveSchema as g, getSchemaChanges as h, initializeSchema as i, isBackwardsCompatible as j, isSchemaInitialized as k, type AllNodeTypes as l, migrateSchema as m, type EdgeKinds as n, type GetEdgeType as o, type GetNodeType as p, type NodeKinds as q, rollbackSchema as r, defineGraph as s, getEdgeKinds as t, getNodeKinds as u, isGraphDef as v };