@nicia-ai/typegraph 0.24.1 → 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-SUHW2UYL.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-GUTQTMOV.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-QOLTW7OZ.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-OVJ2BE5Q.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-nIhmttD-.d.ts → manager-BKaPQbns.d.ts} +189 -6
  104. package/dist/{manager-Vkz28eAC.d.cts → 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-U3i2tUch.d.ts → store-BAGuOHDh.d.cts} +659 -23
  122. package/dist/{store-CpvwTMxV.d.cts → 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 +33 -73
  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-3PPEHLGK.js +0 -1116
  134. package/dist/chunk-3PPEHLGK.js.map +0 -1
  135. package/dist/chunk-5HVDOPZU.cjs.map +0 -1
  136. package/dist/chunk-753F33CV.js.map +0 -1
  137. package/dist/chunk-EY4LBX3F.js.map +0 -1
  138. package/dist/chunk-EYELZHKY.js.map +0 -1
  139. package/dist/chunk-GFGVREHH.js +0 -1381
  140. package/dist/chunk-GFGVREHH.js.map +0 -1
  141. package/dist/chunk-GUTQTMOV.js.map +0 -1
  142. package/dist/chunk-LBORRUNJ.js +0 -135
  143. package/dist/chunk-LBORRUNJ.js.map +0 -1
  144. package/dist/chunk-O5PST6TB.cjs.map +0 -1
  145. package/dist/chunk-OLROXS2S.cjs +0 -147
  146. package/dist/chunk-OLROXS2S.cjs.map +0 -1
  147. package/dist/chunk-OVJ2BE5Q.cjs.map +0 -1
  148. package/dist/chunk-PAUN562Y.cjs +0 -1417
  149. package/dist/chunk-PAUN562Y.cjs.map +0 -1
  150. package/dist/chunk-PEE4EWXZ.cjs +0 -1131
  151. package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
  152. package/dist/chunk-QOLTW7OZ.js.map +0 -1
  153. package/dist/chunk-SUHW2UYL.cjs.map +0 -1
  154. package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
  155. package/dist/chunk-WFMTAEEN.js.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,1254 +0,0 @@
1
- import { SQL } from 'drizzle-orm';
2
- import { z } from 'zod';
3
-
4
- /** Brand key for NodeType */
5
- declare const NODE_TYPE_BRAND: "__nodeType";
6
- /** Brand key for EdgeType */
7
- declare const EDGE_TYPE_BRAND: "__edgeType";
8
- /** Brand symbol for NodeId */
9
- declare const __nodeId: unique symbol;
10
- /** Brand symbol for EdgeId */
11
- declare const __edgeId: unique symbol;
12
- /**
13
- * A node type definition.
14
- *
15
- * Created via `defineNode()`. Represents a type of node in the graph
16
- * with an associated Zod schema for properties.
17
- */
18
- type NodeType<K extends string = string, S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = Readonly<{
19
- [NODE_TYPE_BRAND]: true;
20
- kind: K;
21
- schema: S;
22
- description: string | undefined;
23
- }>;
24
- /**
25
- * Branded node ID type.
26
- *
27
- * Prevents mixing IDs from different node types at compile time.
28
- */
29
- type NodeId<N extends NodeType> = string & Readonly<{
30
- [__nodeId]: N;
31
- }>;
32
- /**
33
- * Infer the props type from a NodeType.
34
- */
35
- type NodeProps<N extends NodeType> = z.infer<N["schema"]>;
36
- /**
37
- * An edge type definition.
38
- *
39
- * Created via `defineEdge()`. Represents a type of edge in the graph
40
- * with an optional Zod schema for properties.
41
- *
42
- * Optionally includes `from` and `to` arrays that define the allowed
43
- * source and target node types (domain and range constraints).
44
- */
45
- type EdgeType<K extends string = string, S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, From extends readonly NodeType[] | undefined = undefined, To extends readonly NodeType[] | undefined = undefined> = Readonly<{
46
- [EDGE_TYPE_BRAND]: true;
47
- kind: K;
48
- schema: S;
49
- description: string | undefined;
50
- from: From;
51
- to: To;
52
- }>;
53
- /**
54
- * Base edge type for use in constraints - accepts any from/to configuration.
55
- */
56
- type AnyEdgeType = EdgeType<string, z.ZodObject<z.ZodRawShape>, readonly NodeType[] | undefined, readonly NodeType[] | undefined>;
57
- /**
58
- * An edge type that has both from and to constraints defined.
59
- * Can be used directly in defineGraph without an EdgeRegistration wrapper.
60
- */
61
- type EdgeTypeWithEndpoints = EdgeType<string, z.ZodObject<z.ZodRawShape>, readonly NodeType[], readonly NodeType[]>;
62
- /**
63
- * Branded edge ID type.
64
- *
65
- * Prevents mixing IDs from different edge types at compile time.
66
- */
67
- type EdgeId<E extends AnyEdgeType = AnyEdgeType> = string & Readonly<{
68
- [__edgeId]: E;
69
- }>;
70
- /**
71
- * Infer the props type from an EdgeType.
72
- */
73
- type EdgeProps<E extends AnyEdgeType> = z.infer<E["schema"]>;
74
- /**
75
- * Delete behaviors for nodes.
76
- */
77
- type DeleteBehavior = "restrict" | "cascade" | "disconnect";
78
- /**
79
- * Edge cardinality constraints.
80
- */
81
- type Cardinality = "many" | "one" | "unique" | "oneActive";
82
- /**
83
- * Endpoint existence modes for edge validation.
84
- */
85
- type EndpointExistence = "notDeleted" | "currentlyValid" | "ever";
86
- /**
87
- * Temporal query modes.
88
- */
89
- type TemporalMode = "current" | "asOf" | "includeEnded" | "includeTombstones";
90
- /**
91
- * Uniqueness constraint scope.
92
- */
93
- type UniquenessScope = "kind" | "kindWithSubClasses";
94
- /**
95
- * Collation for uniqueness constraints.
96
- */
97
- type Collation = "binary" | "caseInsensitive";
98
- /**
99
- * Uniqueness constraint definition.
100
- */
101
- type UniqueConstraint<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = Readonly<{
102
- name: string;
103
- fields: readonly (keyof z.infer<S> & string)[];
104
- where?: (props: UniqueConstraintPredicateBuilder<S>) => UniqueConstraintPredicate;
105
- scope: UniquenessScope;
106
- collation: Collation;
107
- }>;
108
- /**
109
- * Predicate builder for uniqueness constraint where clause.
110
- * Uses -? to make all fields required in the builder, even if optional in the schema.
111
- */
112
- type UniqueConstraintPredicateBuilder<S extends z.ZodObject<z.ZodRawShape>> = Readonly<{
113
- [K in keyof z.infer<S>]-?: UniqueConstraintField;
114
- }>;
115
- /**
116
- * Field operations for uniqueness constraint predicates.
117
- */
118
- type UniqueConstraintField = Readonly<{
119
- isNull: () => UniqueConstraintPredicate;
120
- isNotNull: () => UniqueConstraintPredicate;
121
- }>;
122
- /**
123
- * A uniqueness constraint predicate (internal representation).
124
- */
125
- type UniqueConstraintPredicate = Readonly<{
126
- __type: "unique_predicate";
127
- field: string;
128
- op: "isNull" | "isNotNull";
129
- }>;
130
- /**
131
- * Node registration in a graph definition.
132
- */
133
- type NodeRegistration<N extends NodeType = NodeType> = Readonly<{
134
- type: N;
135
- unique?: readonly UniqueConstraint<N["schema"]>[];
136
- onDelete?: DeleteBehavior;
137
- }>;
138
- /**
139
- * Edge registration in a graph definition.
140
- */
141
- type EdgeRegistration<E extends AnyEdgeType = AnyEdgeType, FromTypes extends NodeType = NodeType, ToTypes extends NodeType = NodeType> = Readonly<{
142
- type: E;
143
- from: readonly FromTypes[];
144
- to: readonly ToTypes[];
145
- cardinality?: Cardinality;
146
- endpointExistence?: EndpointExistence;
147
- }>;
148
- /**
149
- * Default settings for a graph.
150
- */
151
- type GraphDefaults = Readonly<{
152
- onNodeDelete?: DeleteBehavior;
153
- temporalMode?: TemporalMode;
154
- }>;
155
- /**
156
- * Checks if a value is a NodeType.
157
- */
158
- declare function isNodeType(value: unknown): value is NodeType;
159
- /**
160
- * Checks if a value is an EdgeType.
161
- */
162
- declare function isEdgeType(value: unknown): value is AnyEdgeType;
163
- /**
164
- * Checks if a value is an EdgeType with both from and to constraints defined.
165
- * Such edges can be used directly in defineGraph without an EdgeRegistration wrapper.
166
- */
167
- declare function isEdgeTypeWithEndpoints(value: unknown): value is EdgeTypeWithEndpoints;
168
-
169
- /** Brand key for MetaEdge */
170
- declare const META_EDGE_BRAND: "__metaEdge";
171
- /**
172
- * How a meta-edge affects queries and validation.
173
- */
174
- type InferenceType = "subsumption" | "hierarchy" | "substitution" | "constraint" | "composition" | "association" | "none";
175
- /**
176
- * Properties of a meta-edge.
177
- */
178
- type MetaEdgeProperties = Readonly<{
179
- transitive: boolean;
180
- symmetric: boolean;
181
- reflexive: boolean;
182
- inverse: string | undefined;
183
- inference: InferenceType;
184
- description: string | undefined;
185
- }>;
186
- /**
187
- * A meta-edge definition.
188
- *
189
- * Meta-edges represent type-level relationships (between kinds),
190
- * not instance-level relationships (between nodes).
191
- */
192
- type MetaEdge<K extends string = string> = Readonly<{
193
- [META_EDGE_BRAND]: true;
194
- name: K;
195
- properties: MetaEdgeProperties;
196
- }>;
197
- /**
198
- * A relation in the ontology (instance of meta-edge between types).
199
- *
200
- * @example
201
- * ```typescript
202
- * // Podcast subClassOf Media
203
- * subClassOf(Podcast, Media)
204
- *
205
- * // Person equivalentTo schema:Person
206
- * equivalentTo(Person, "https://schema.org/Person")
207
- * ```
208
- */
209
- type OntologyRelation = Readonly<{
210
- metaEdge: MetaEdge;
211
- from: NodeType | EdgeType | string;
212
- to: NodeType | EdgeType | string;
213
- }>;
214
- /**
215
- * Checks if a value is a MetaEdge.
216
- */
217
- declare function isMetaEdge(value: unknown): value is MetaEdge;
218
-
219
- /**
220
- * SQL Schema Configuration for Query Compilation
221
- *
222
- * Provides table and column identifiers that the query compiler uses.
223
- * This allows the compiler to work with custom table names instead of
224
- * hard-coded defaults.
225
- */
226
-
227
- /**
228
- * Table names for TypeGraph SQL schema.
229
- */
230
- type SqlTableNames = Readonly<{
231
- /** Nodes table name (default: "typegraph_nodes") */
232
- nodes: string;
233
- /** Edges table name (default: "typegraph_edges") */
234
- edges: string;
235
- /** Node embeddings table name (default: "typegraph_node_embeddings") */
236
- embeddings: string;
237
- /** Node fulltext table name (default: "typegraph_node_fulltext") */
238
- fulltext: string;
239
- }>;
240
- /**
241
- * SQL schema configuration for query compilation.
242
- * Contains table identifiers and utility methods for generating SQL references.
243
- */
244
- type SqlSchema = Readonly<{
245
- /** Table names */
246
- tables: SqlTableNames;
247
- /** Get a SQL reference to the nodes table */
248
- nodesTable: SQL;
249
- /** Get a SQL reference to the edges table */
250
- edgesTable: SQL;
251
- /** Get a SQL reference to the embeddings table */
252
- embeddingsTable: SQL;
253
- /** Get a SQL reference to the fulltext table */
254
- fulltextTable: SQL;
255
- }>;
256
- /**
257
- * Creates a SqlSchema configuration from table names.
258
- *
259
- * Table names are validated to ensure they are valid SQL identifiers.
260
- * This prevents SQL injection and ensures compatibility across databases.
261
- *
262
- * @param names - Optional custom table names (defaults to standard names)
263
- * @returns SqlSchema configuration for query compilation
264
- * @throws Error if any table name is invalid
265
- *
266
- * @example
267
- * ```typescript
268
- * // Use default table names
269
- * const schema = createSqlSchema();
270
- *
271
- * // Use custom table names
272
- * const schema = createSqlSchema({
273
- * nodes: "myapp_nodes",
274
- * edges: "myapp_edges",
275
- * embeddings: "myapp_embeddings",
276
- * });
277
- * ```
278
- */
279
- declare function createSqlSchema(names?: Partial<SqlTableNames>): SqlSchema;
280
- /**
281
- * Default SqlSchema using standard TypeGraph table names.
282
- */
283
- declare const DEFAULT_SQL_SCHEMA: SqlSchema;
284
-
285
- /**
286
- * Fulltext Strategy — pluggable DDL + SQL generation for a dialect's
287
- * fulltext stack. A strategy owns every SQL statement that touches its
288
- * backing table: DDL, upsert (single + batch), delete (single + batch),
289
- * MATCH condition, rank expression, and snippet expression.
290
- *
291
- * A dialect picks one as its default; `createPostgresBackend` /
292
- * `createSqliteBackend` accept an override for alternate Postgres stacks
293
- * (pg_trgm, ParadeDB/pg_search, pgroonga) to swap the entire fulltext
294
- * pipeline without forking TypeGraph.
295
- */
296
-
297
- /**
298
- * A pluggable fulltext implementation. Each strategy is expected to be
299
- * self-contained: given a table name, a query string, and a parse mode,
300
- * it emits every SQL statement the compiler and backend need — DDL,
301
- * reads, and writes. No out-of-band conventions across layers.
302
- */
303
- interface FulltextStrategy {
304
- /** Human-readable identifier used in error messages and telemetry. */
305
- readonly name: string;
306
- /**
307
- * Parse modes this strategy can translate. Callers validate against
308
- * this list before emitting SQL; a mode outside the set means the
309
- * strategy rejects the query at compile time.
310
- */
311
- readonly supportedModes: readonly FulltextQueryMode[];
312
- /**
313
- * Whether the strategy can emit a per-row highlighted snippet. When
314
- * false, `snippetExpression` returns a literal `NULL` so callers can
315
- * leave the `snippet` column in place without a branch.
316
- */
317
- readonly supportsSnippets: boolean;
318
- /**
319
- * Whether the strategy supports prefix queries (`foo*`). Used to
320
- * populate `BackendCapabilities.fulltext.prefixQueries`. A strategy
321
- * may support prefix queries via dedicated syntax without advertising
322
- * "raw" mode (and vice-versa).
323
- */
324
- readonly supportsPrefix: boolean;
325
- /**
326
- * Whether a per-query `language` override is honored. Postgres' tsvector
327
- * accepts any installed regconfig at query time; SQLite FTS5's tokenizer
328
- * is fixed at table-create time, so the override is silently ignored.
329
- * Callers may surface a warning when the user passes `language` to a
330
- * strategy that doesn't honor it.
331
- */
332
- readonly supportsLanguageOverride: boolean;
333
- /**
334
- * Languages / tokenizer names understood by the strategy. Advisory — a
335
- * runtime backend like Postgres may accept other installed regconfigs.
336
- * Used to populate `BackendCapabilities.fulltext.languages`.
337
- */
338
- readonly languages: readonly string[];
339
- /**
340
- * Emits the WHERE-side MATCH expression.
341
- *
342
- * @example
343
- * tsvector: `"typegraph_node_fulltext"."tsv" @@ websearch_to_tsquery('english', 'cats')`
344
- * fts5: `"typegraph_node_fulltext" MATCH '"cats"'`
345
- */
346
- matchCondition(tableName: string, query: string, mode: FulltextQueryMode, language?: string): SQL;
347
- /**
348
- * Emits the relevance expression. Higher values = more relevant. The
349
- * compiler orders by this expression DESC, and both builder and
350
- * backend-direct paths use the same form so their top-k results agree.
351
- */
352
- rankExpression(tableName: string, query: string, mode: FulltextQueryMode, language?: string): SQL;
353
- /**
354
- * Emits a per-row highlighted snippet expression, or `NULL` when
355
- * `supportsSnippets` is false. Snippet markup is `<mark>…</mark>` in
356
- * both shipped strategies so consumers can apply one stylesheet.
357
- */
358
- snippetExpression(tableName: string, query: string, mode: FulltextQueryMode, language?: string): SQL;
359
- /**
360
- * DDL statements to create the backing table and any supporting
361
- * indexes. Idempotent (`CREATE ... IF NOT EXISTS`). Called once from
362
- * `bootstrapTables()` on a fresh database.
363
- */
364
- generateDdl(tableName: string): readonly string[];
365
- /**
366
- * Emits the statements that upsert a single fulltext row. Returns one
367
- * or more statements — some backends (SQLite FTS5) cannot emulate
368
- * upsert in a single statement and need DELETE + INSERT.
369
- */
370
- buildUpsert(tableName: string, params: UpsertFulltextParams, timestamp: string): readonly SQL[];
371
- /**
372
- * Emits the statements that upsert many fulltext rows at once. Input
373
- * rows are expected to be de-duplicated last-write-wins by the
374
- * strategy if the underlying SQL statement cannot tolerate duplicate
375
- * conflict keys. Returns `[]` when `params.rows` is empty.
376
- */
377
- buildBatchUpsert(tableName: string, params: UpsertFulltextBatchParams, timestamp: string): readonly SQL[];
378
- /**
379
- * Emits the statements that delete a single fulltext row. Normally a
380
- * single PK-scoped DELETE, but strategies that maintain auxiliary
381
- * indexes (delete-triggered external stores, ParadeDB-style secondary
382
- * structures) may need more.
383
- */
384
- buildDelete(tableName: string, params: DeleteFulltextParams): readonly SQL[];
385
- /**
386
- * Emits the statements that delete many fulltext rows at once. Returns
387
- * `[]` when `params.nodeIds` is empty.
388
- */
389
- buildBatchDelete(tableName: string, params: DeleteFulltextBatchParams): readonly SQL[];
390
- }
391
- declare const tsvectorStrategy: FulltextStrategy;
392
- declare const fts5Strategy: FulltextStrategy;
393
-
394
- /**
395
- * Types for serialized schema storage.
396
- *
397
- * These types represent the JSON-serializable format used for
398
- * homoiconic schema storage in the database.
399
- *
400
- * The Zod schema (serializedSchemaZod) is the single source of truth.
401
- * The TypeScript type (SerializedSchema) is inferred from it.
402
- */
403
-
404
- /**
405
- * JSON Schema type (subset used by Zod toJSONSchema).
406
- *
407
- * This is a simplified version - the actual JSON Schema has many more properties.
408
- */
409
- type JsonSchema = Readonly<{
410
- $schema?: string;
411
- type?: string | readonly string[];
412
- properties?: Record<string, JsonSchema>;
413
- required?: readonly string[];
414
- items?: JsonSchema;
415
- additionalProperties?: boolean | JsonSchema;
416
- enum?: readonly unknown[];
417
- const?: unknown;
418
- anyOf?: readonly JsonSchema[];
419
- oneOf?: readonly JsonSchema[];
420
- allOf?: readonly JsonSchema[];
421
- not?: JsonSchema;
422
- description?: string;
423
- default?: unknown;
424
- minimum?: number;
425
- maximum?: number;
426
- minLength?: number;
427
- maxLength?: number;
428
- pattern?: string;
429
- format?: string;
430
- [key: string]: unknown;
431
- }>;
432
- /**
433
- * Serialized representation of a meta-edge.
434
- */
435
- type SerializedMetaEdge = Readonly<{
436
- name: string;
437
- transitive: boolean;
438
- symmetric: boolean;
439
- reflexive: boolean;
440
- inverse: string | undefined;
441
- inference: InferenceType;
442
- description: string | undefined;
443
- }>;
444
- /**
445
- * Serialized representation of an ontology relation.
446
- */
447
- type SerializedOntologyRelation = Readonly<{
448
- metaEdge: string;
449
- from: string;
450
- to: string;
451
- }>;
452
- /**
453
- * Precomputed closures stored in the schema for fast runtime lookup.
454
- */
455
- type SerializedClosures = Readonly<{
456
- subClassAncestors: Record<string, readonly string[]>;
457
- subClassDescendants: Record<string, readonly string[]>;
458
- broaderClosure: Record<string, readonly string[]>;
459
- narrowerClosure: Record<string, readonly string[]>;
460
- equivalenceSets: Record<string, readonly string[]>;
461
- disjointPairs: readonly string[];
462
- partOfClosure: Record<string, readonly string[]>;
463
- hasPartClosure: Record<string, readonly string[]>;
464
- iriToKind: Record<string, string>;
465
- edgeInverses: Record<string, string>;
466
- edgeImplicationsClosure: Record<string, readonly string[]>;
467
- edgeImplyingClosure: Record<string, readonly string[]>;
468
- }>;
469
- /**
470
- * Complete serialized ontology section.
471
- */
472
- type SerializedOntology = Readonly<{
473
- metaEdges: Record<string, SerializedMetaEdge>;
474
- relations: readonly SerializedOntologyRelation[];
475
- closures: SerializedClosures;
476
- }>;
477
- /**
478
- * Serialized representation of a uniqueness constraint.
479
- */
480
- type SerializedUniqueConstraint = Readonly<{
481
- name: string;
482
- fields: readonly string[];
483
- where: string | undefined;
484
- scope: UniquenessScope;
485
- collation: Collation;
486
- }>;
487
- /**
488
- * Serialized representation of a node kind.
489
- */
490
- type SerializedNodeDef = Readonly<{
491
- kind: string;
492
- properties: JsonSchema;
493
- uniqueConstraints: readonly SerializedUniqueConstraint[];
494
- onDelete: DeleteBehavior;
495
- description: string | undefined;
496
- }>;
497
- /**
498
- * Serialized representation of an edge kind.
499
- */
500
- type SerializedEdgeDef = Readonly<{
501
- kind: string;
502
- fromKinds: readonly string[];
503
- toKinds: readonly string[];
504
- properties: JsonSchema;
505
- cardinality: Cardinality;
506
- endpointExistence: EndpointExistence;
507
- description: string | undefined;
508
- }>;
509
- /**
510
- * Complete serialized schema document.
511
- *
512
- * This is the format stored in the schema_doc column of
513
- * typegraph_schema_versions. The type is kept explicit rather than
514
- * inferred from the Zod schema so that downstream code sees the
515
- * precise literal union types (DeleteBehavior, TemporalMode, etc.)
516
- * instead of the broader `string` type that Zod's passthrough schema uses.
517
- */
518
- type SerializedSchema = Readonly<{
519
- graphId: string;
520
- version: number;
521
- generatedAt: string;
522
- nodes: Record<string, SerializedNodeDef>;
523
- edges: Record<string, SerializedEdgeDef>;
524
- ontology: SerializedOntology;
525
- defaults: Readonly<{
526
- onNodeDelete: DeleteBehavior;
527
- temporalMode: TemporalMode;
528
- }>;
529
- }>;
530
- /**
531
- * A schema hash for detecting changes.
532
- *
533
- * We hash the schema content (excluding version and generatedAt)
534
- * to detect if the schema has actually changed.
535
- */
536
- type SchemaHash = string;
537
-
538
- /**
539
- * SQL Dialect Abstraction Layer
540
- *
541
- * Provides a unified interface for dialect-specific SQL generation.
542
- * Implementing a new dialect (MySQL, SQL Server, etc.) requires
543
- * implementing this interface.
544
- */
545
-
546
- /**
547
- * Supported SQL dialects.
548
- */
549
- type SqlDialect = "sqlite" | "postgres";
550
-
551
- /**
552
- * Backend interface types for TypeGraph storage.
553
- *
554
- * The backend abstracts database operations, allowing different
555
- * SQL implementations (SQLite, PostgreSQL) behind a common interface.
556
- */
557
-
558
- /**
559
- * Supported vector similarity metrics.
560
- */
561
- type VectorMetric = "cosine" | "l2" | "inner_product";
562
- /**
563
- * Supported vector index types.
564
- */
565
- type VectorIndexType = "hnsw" | "ivfflat" | "none";
566
- /**
567
- * Vector search capabilities.
568
- */
569
- type VectorCapabilities = Readonly<{
570
- /** Whether the backend supports vector operations */
571
- supported: boolean;
572
- /** Supported similarity metrics */
573
- metrics: readonly VectorMetric[];
574
- /** Supported index types */
575
- indexTypes: readonly VectorIndexType[];
576
- /** Maximum dimensions supported */
577
- maxDimensions: number;
578
- }>;
579
- /**
580
- * Query modes for fulltext search.
581
- *
582
- * - "websearch": Google-style syntax (quoted phrases, +required, -excluded).
583
- * Postgres: `websearch_to_tsquery`. SQLite: translated to FTS5 MATCH.
584
- * - "phrase": treats the whole query as a phrase.
585
- * Postgres: `phraseto_tsquery`. SQLite: FTS5 `"..."` phrase.
586
- * - "plain": splits on whitespace and ANDs terms.
587
- * Postgres: `plainto_tsquery`. SQLite: default FTS5 AND.
588
- * - "raw": dialect-native syntax passed through unchanged.
589
- */
590
- type FulltextQueryMode = "websearch" | "phrase" | "plain" | "raw";
591
- /**
592
- * Fulltext search capabilities declared by a backend.
593
- */
594
- type FulltextCapabilities = Readonly<{
595
- /** Whether the backend supports fulltext operations */
596
- supported: boolean;
597
- /**
598
- * Language / tokenizer names understood by this backend.
599
- * Postgres: installed regconfigs (english, simple, ...).
600
- * SQLite FTS5: tokenizer names (unicode61, porter, trigram).
601
- */
602
- languages: readonly string[];
603
- /** Whether phrase queries are supported. */
604
- phraseQueries: boolean;
605
- /** Whether prefix (`foo*`) queries are supported. */
606
- prefixQueries: boolean;
607
- /** Whether highlighting / snippets are supported. */
608
- highlighting: boolean;
609
- }>;
610
-
611
- /**
612
- * Backend capabilities that vary by dialect.
613
- */
614
- type BackendCapabilities = Readonly<{
615
- /** Whether the backend supports JSONB type (vs TEXT for JSON) */
616
- jsonb: boolean;
617
- /** Whether the backend supports partial indexes */
618
- partialIndexes: boolean;
619
- /** Whether the backend supports GIN indexes for JSON */
620
- ginIndexes: boolean;
621
- /** Whether the backend supports CTE (WITH) queries */
622
- cte: boolean;
623
- /** Whether the backend supports RETURNING clause */
624
- returning: boolean;
625
- /** Whether the backend supports atomic transactions (D1 does not) */
626
- transactions: boolean;
627
- /** Vector search capabilities (undefined if not configured) */
628
- vector?: VectorCapabilities | undefined;
629
- /** Fulltext search capabilities (undefined if not configured) */
630
- fulltext?: FulltextCapabilities | undefined;
631
- }>;
632
- /**
633
- * A row from the typegraph_nodes table.
634
- */
635
- type NodeRow = Readonly<{
636
- graph_id: string;
637
- kind: string;
638
- id: string;
639
- props: string;
640
- version: number;
641
- valid_from: string | undefined;
642
- valid_to: string | undefined;
643
- created_at: string;
644
- updated_at: string;
645
- deleted_at: string | undefined;
646
- }>;
647
- /**
648
- * A row from the typegraph_edges table.
649
- */
650
- type EdgeRow = Readonly<{
651
- graph_id: string;
652
- id: string;
653
- kind: string;
654
- from_kind: string;
655
- from_id: string;
656
- to_kind: string;
657
- to_id: string;
658
- props: string;
659
- valid_from: string | undefined;
660
- valid_to: string | undefined;
661
- created_at: string;
662
- updated_at: string;
663
- deleted_at: string | undefined;
664
- }>;
665
- /**
666
- * A row from the typegraph_node_uniques table.
667
- */
668
- type UniqueRow = Readonly<{
669
- graph_id: string;
670
- node_kind: string;
671
- constraint_name: string;
672
- key: string;
673
- node_id: string;
674
- concrete_kind: string;
675
- deleted_at: string | undefined;
676
- }>;
677
- /**
678
- * A row from the typegraph_schema_versions table.
679
- */
680
- type SchemaVersionRow = Readonly<{
681
- graph_id: string;
682
- version: number;
683
- schema_hash: string;
684
- schema_doc: string;
685
- created_at: string;
686
- is_active: boolean;
687
- }>;
688
- /**
689
- * A row from the typegraph_node_embeddings table.
690
- */
691
- type EmbeddingRow = Readonly<{
692
- graph_id: string;
693
- node_kind: string;
694
- node_id: string;
695
- field_path: string;
696
- embedding: readonly number[];
697
- dimensions: number;
698
- created_at: string;
699
- updated_at: string;
700
- }>;
701
- /**
702
- * Parameters for inserting a node.
703
- */
704
- type InsertNodeParams = Readonly<{
705
- graphId: string;
706
- kind: string;
707
- id: string;
708
- props: Readonly<Record<string, unknown>>;
709
- validFrom?: string;
710
- validTo?: string;
711
- }>;
712
- /**
713
- * Parameters for updating a node.
714
- */
715
- type UpdateNodeParams = Readonly<{
716
- graphId: string;
717
- kind: string;
718
- id: string;
719
- props: Readonly<Record<string, unknown>>;
720
- validTo?: string;
721
- incrementVersion?: boolean;
722
- /** If true, clears deleted_at (un-deletes the node). Used by upsert. */
723
- clearDeleted?: boolean;
724
- }>;
725
- /**
726
- * Parameters for deleting a node (soft delete).
727
- */
728
- type DeleteNodeParams = Readonly<{
729
- graphId: string;
730
- kind: string;
731
- id: string;
732
- }>;
733
- /**
734
- * Parameters for inserting an edge.
735
- */
736
- type InsertEdgeParams = Readonly<{
737
- graphId: string;
738
- id: string;
739
- kind: string;
740
- fromKind: string;
741
- fromId: string;
742
- toKind: string;
743
- toId: string;
744
- props: Readonly<Record<string, unknown>>;
745
- validFrom?: string;
746
- validTo?: string;
747
- }>;
748
- /**
749
- * Parameters for updating an edge.
750
- */
751
- type UpdateEdgeParams = Readonly<{
752
- graphId: string;
753
- id: string;
754
- props: Readonly<Record<string, unknown>>;
755
- validTo?: string;
756
- clearDeleted?: boolean;
757
- }>;
758
- /**
759
- * Parameters for deleting an edge (soft delete).
760
- */
761
- type DeleteEdgeParams = Readonly<{
762
- graphId: string;
763
- id: string;
764
- }>;
765
- /**
766
- * Parameters for hard deleting a node (permanent removal).
767
- */
768
- type HardDeleteNodeParams = Readonly<{
769
- graphId: string;
770
- kind: string;
771
- id: string;
772
- }>;
773
- /**
774
- * Parameters for hard deleting an edge (permanent removal).
775
- */
776
- type HardDeleteEdgeParams = Readonly<{
777
- graphId: string;
778
- id: string;
779
- }>;
780
- /**
781
- * Parameters for inserting or updating an embedding.
782
- */
783
- type UpsertEmbeddingParams = Readonly<{
784
- graphId: string;
785
- nodeKind: string;
786
- nodeId: string;
787
- fieldPath: string;
788
- embedding: readonly number[];
789
- dimensions: number;
790
- }>;
791
- /**
792
- * Parameters for deleting an embedding.
793
- */
794
- type DeleteEmbeddingParams = Readonly<{
795
- graphId: string;
796
- nodeKind: string;
797
- nodeId: string;
798
- fieldPath: string;
799
- }>;
800
- /**
801
- * Parameters for vector similarity search.
802
- */
803
- type VectorSearchParams = Readonly<{
804
- graphId: string;
805
- nodeKind: string;
806
- fieldPath: string;
807
- queryEmbedding: readonly number[];
808
- metric: VectorMetric;
809
- limit: number;
810
- minScore?: number;
811
- }>;
812
- /**
813
- * Result from a vector similarity search.
814
- */
815
- type VectorSearchResult = Readonly<{
816
- nodeId: string;
817
- /**
818
- * Cosine metric returns similarity score (higher is better).
819
- * L2 and inner_product return raw distance (lower is better).
820
- */
821
- score: number;
822
- }>;
823
- /**
824
- * Parameters for creating a vector index.
825
- */
826
- type CreateVectorIndexParams = Readonly<{
827
- graphId: string;
828
- nodeKind: string;
829
- fieldPath: string;
830
- dimensions: number;
831
- metric: VectorMetric;
832
- indexType: VectorIndexType;
833
- /** Index-specific parameters */
834
- indexParams?: Readonly<{
835
- /** HNSW: max connections per layer */
836
- m?: number;
837
- /** HNSW: construction search depth */
838
- efConstruction?: number;
839
- /** IVFFlat: number of lists */
840
- lists?: number;
841
- }>;
842
- }>;
843
- /**
844
- * Parameters for dropping a vector index.
845
- */
846
- type DropVectorIndexParams = Readonly<{
847
- graphId: string;
848
- nodeKind: string;
849
- fieldPath: string;
850
- }>;
851
- /**
852
- * Parameters for inserting or updating a fulltext entry.
853
- *
854
- * One row per node. Callers concatenate the searchable fields into
855
- * `content` so a single MATCH query can find terms spread across fields.
856
- */
857
- type UpsertFulltextParams = Readonly<{
858
- graphId: string;
859
- nodeKind: string;
860
- nodeId: string;
861
- content: string;
862
- language: string;
863
- }>;
864
- /**
865
- * Parameters for deleting a single fulltext entry.
866
- */
867
- type DeleteFulltextParams = Readonly<{
868
- graphId: string;
869
- nodeKind: string;
870
- nodeId: string;
871
- }>;
872
- /**
873
- * A single row in a fulltext batch upsert.
874
- */
875
- type FulltextBatchRow = Readonly<{
876
- nodeId: string;
877
- content: string;
878
- language: string;
879
- }>;
880
- /**
881
- * Parameters for a batched fulltext upsert.
882
- *
883
- * Homogeneous: one graph, one node kind, many nodes. Duplicate `nodeId`
884
- * values within a single batch are deduplicated last-write-wins by the
885
- * builders before SQL generation — Postgres `ON CONFLICT` errors on
886
- * repeated conflict keys in one statement, and SQLite `DELETE + INSERT`
887
- * would create duplicate virtual-table rows otherwise.
888
- */
889
- type UpsertFulltextBatchParams = Readonly<{
890
- graphId: string;
891
- nodeKind: string;
892
- rows: readonly FulltextBatchRow[];
893
- }>;
894
- /**
895
- * Parameters for a batched fulltext delete.
896
- */
897
- type DeleteFulltextBatchParams = Readonly<{
898
- graphId: string;
899
- nodeKind: string;
900
- nodeIds: readonly string[];
901
- }>;
902
- /**
903
- * Parameters for fulltext search.
904
- */
905
- type FulltextSearchParams = Readonly<{
906
- graphId: string;
907
- nodeKind: string;
908
- /** The user-supplied query string. */
909
- query: string;
910
- /** How to parse `query`. Default: "websearch". */
911
- mode?: FulltextQueryMode;
912
- /**
913
- * Language override. Default: per-row language (as stored at insert time).
914
- * Postgres: passed as the regconfig to `to_tsquery` / `websearch_to_tsquery`.
915
- * SQLite: informational only (FTS5 tokenizer is fixed at table-create time).
916
- */
917
- language?: string;
918
- /** Max rows to return. */
919
- limit: number;
920
- /** Minimum rank to include (backend-dependent units). */
921
- minScore?: number;
922
- /** Whether to return a highlighted snippet per match. */
923
- includeSnippets?: boolean;
924
- }>;
925
- /**
926
- * Result from a fulltext search.
927
- *
928
- * Score semantics differ by backend; prefer `rank` (1-based) when fusing
929
- * with another source via RRF.
930
- */
931
- type FulltextSearchResult = Readonly<{
932
- nodeId: string;
933
- /**
934
- * Backend-native relevance score.
935
- * Postgres: `ts_rank_cd` (higher is better).
936
- * SQLite FTS5: negated `bm25()` (higher is better; FTS5 returns lower-is-better).
937
- */
938
- score: number;
939
- /** 1-based rank within the result set, suitable for RRF. */
940
- rank: number;
941
- /** Highlighted snippet of the content (if `includeSnippets` was set). */
942
- snippet?: string;
943
- }>;
944
- /**
945
- * Parameters for creating a fulltext index.
946
- *
947
- * The canonical index (Postgres GIN on `tsv`, SQLite FTS5 virtual table)
948
- * is created when the fulltext table itself is created. This is reserved
949
- * for advanced per-kind specializations.
950
- */
951
- type CreateFulltextIndexParams = Readonly<{
952
- graphId: string;
953
- nodeKind: string;
954
- language: string;
955
- }>;
956
- /**
957
- * Parameters for dropping a fulltext index created via createFulltextIndex.
958
- */
959
- type DropFulltextIndexParams = Readonly<{
960
- graphId: string;
961
- nodeKind: string;
962
- }>;
963
- /**
964
- * Transaction options.
965
- */
966
- type TransactionOptions = Readonly<{
967
- /** Transaction isolation level (if supported) */
968
- isolationLevel?: "read_uncommitted" | "read_committed" | "repeatable_read" | "serializable";
969
- }>;
970
- /**
971
- * Transaction backend - a backend scoped to a transaction.
972
- */
973
- type TransactionBackend = Omit<GraphBackend, "transaction" | "close" | "refreshStatistics">;
974
- /**
975
- * The GraphBackend interface abstracts database operations.
976
- *
977
- * Implementations should provide:
978
- * - SQLite backend via better-sqlite3 or libsql
979
- * - PostgreSQL backend via pg or postgres
980
- */
981
- type GraphBackend = Readonly<{
982
- /** The SQL dialect */
983
- dialect: SqlDialect;
984
- /** Backend capabilities */
985
- capabilities: BackendCapabilities;
986
- /** Table names used by this backend (for query schema auto-derivation) */
987
- tableNames?: SqlTableNames | undefined;
988
- /**
989
- * Optional fulltext strategy override. When present, both the compiler
990
- * (for `$fulltext.matches()` in query builder) and backend-direct
991
- * search paths use this instead of the dialect's default strategy —
992
- * allowing a Postgres backend to ship pg_trgm, ParadeDB, pgroonga etc.
993
- * When absent, the dialect's default strategy is used.
994
- */
995
- fulltextStrategy?: FulltextStrategy | undefined;
996
- insertNode: (params: InsertNodeParams) => Promise<NodeRow>;
997
- insertNodeNoReturn?: (params: InsertNodeParams) => Promise<void>;
998
- insertNodesBatch?: (params: readonly InsertNodeParams[]) => Promise<void>;
999
- insertNodesBatchReturning?: (params: readonly InsertNodeParams[]) => Promise<readonly NodeRow[]>;
1000
- updateNode: (params: UpdateNodeParams) => Promise<NodeRow>;
1001
- deleteNode: (params: DeleteNodeParams) => Promise<void>;
1002
- hardDeleteNode: (params: HardDeleteNodeParams) => Promise<void>;
1003
- getNode: (graphId: string, kind: string, id: string) => Promise<NodeRow | undefined>;
1004
- getNodes?: (graphId: string, kind: string, ids: readonly string[]) => Promise<readonly NodeRow[]>;
1005
- insertEdge: (params: InsertEdgeParams) => Promise<EdgeRow>;
1006
- insertEdgeNoReturn?: (params: InsertEdgeParams) => Promise<void>;
1007
- insertEdgesBatch?: (params: readonly InsertEdgeParams[]) => Promise<void>;
1008
- insertEdgesBatchReturning?: (params: readonly InsertEdgeParams[]) => Promise<readonly EdgeRow[]>;
1009
- updateEdge: (params: UpdateEdgeParams) => Promise<EdgeRow>;
1010
- deleteEdge: (params: DeleteEdgeParams) => Promise<void>;
1011
- hardDeleteEdge: (params: HardDeleteEdgeParams) => Promise<void>;
1012
- getEdge: (graphId: string, id: string) => Promise<EdgeRow | undefined>;
1013
- getEdges?: (graphId: string, ids: readonly string[]) => Promise<readonly EdgeRow[]>;
1014
- countEdgesFrom: (params: CountEdgesFromParams) => Promise<number>;
1015
- edgeExistsBetween: (params: EdgeExistsBetweenParams) => Promise<boolean>;
1016
- findEdgesConnectedTo: (params: FindEdgesConnectedToParams) => Promise<readonly EdgeRow[]>;
1017
- findNodesByKind: (params: FindNodesByKindParams) => Promise<readonly NodeRow[]>;
1018
- countNodesByKind: (params: CountNodesByKindParams) => Promise<number>;
1019
- findEdgesByKind: (params: FindEdgesByKindParams) => Promise<readonly EdgeRow[]>;
1020
- countEdgesByKind: (params: CountEdgesByKindParams) => Promise<number>;
1021
- insertUnique: (params: InsertUniqueParams) => Promise<void>;
1022
- deleteUnique: (params: DeleteUniqueParams) => Promise<void>;
1023
- checkUnique: (params: CheckUniqueParams) => Promise<UniqueRow | undefined>;
1024
- checkUniqueBatch?: (params: CheckUniqueBatchParams) => Promise<readonly UniqueRow[]>;
1025
- getActiveSchema: (graphId: string) => Promise<SchemaVersionRow | undefined>;
1026
- getSchemaVersion: (graphId: string, version: number) => Promise<SchemaVersionRow | undefined>;
1027
- insertSchema: (params: InsertSchemaParams) => Promise<SchemaVersionRow>;
1028
- setActiveSchema: (graphId: string, version: number) => Promise<void>;
1029
- upsertEmbedding?: (params: UpsertEmbeddingParams) => Promise<void>;
1030
- deleteEmbedding?: (params: DeleteEmbeddingParams) => Promise<void>;
1031
- getEmbedding?: (graphId: string, nodeKind: string, nodeId: string, fieldPath: string) => Promise<EmbeddingRow | undefined>;
1032
- vectorSearch?: (params: VectorSearchParams) => Promise<readonly VectorSearchResult[]>;
1033
- createVectorIndex?: (params: CreateVectorIndexParams) => Promise<void>;
1034
- dropVectorIndex?: (params: DropVectorIndexParams) => Promise<void>;
1035
- upsertFulltext?: (params: UpsertFulltextParams) => Promise<void>;
1036
- deleteFulltext?: (params: DeleteFulltextParams) => Promise<void>;
1037
- /**
1038
- * Batched variant of `upsertFulltext`. Optional — callers fall back to
1039
- * per-row `upsertFulltext` when unset.
1040
- */
1041
- upsertFulltextBatch?: (params: UpsertFulltextBatchParams) => Promise<void>;
1042
- /**
1043
- * Batched variant of `deleteFulltext`. Optional — callers fall back to
1044
- * per-row `deleteFulltext` when unset.
1045
- */
1046
- deleteFulltextBatch?: (params: DeleteFulltextBatchParams) => Promise<void>;
1047
- fulltextSearch?: (params: FulltextSearchParams) => Promise<readonly FulltextSearchResult[]>;
1048
- createFulltextIndex?: (params: CreateFulltextIndexParams) => Promise<void>;
1049
- dropFulltextIndex?: (params: DropFulltextIndexParams) => Promise<void>;
1050
- /**
1051
- * Hard-deletes all data for a graph (nodes, edges, uniques, embeddings, schema versions).
1052
- * Intended for import-replacement workflows. No hooks, no per-row logic.
1053
- */
1054
- clearGraph: (graphId: string) => Promise<void>;
1055
- /**
1056
- * Creates the base TypeGraph tables if they don't already exist.
1057
- *
1058
- * Called automatically by `createStoreWithSchema()` when a fresh database
1059
- * is detected. Users who manage DDL themselves via `createStore()` never
1060
- * hit this path.
1061
- */
1062
- bootstrapTables?: () => Promise<void>;
1063
- /**
1064
- * Refreshes the backend's query-planner statistics.
1065
- *
1066
- * Call this once after a large initial import or bulk backfill. Without
1067
- * up-to-date statistics, the planner can pick suboptimal execution plans
1068
- * — on PostgreSQL this is the difference between a 0.5ms and a 5ms
1069
- * forward traversal; on SQLite it's the difference between 0.9ms and
1070
- * 23ms fulltext search. Autovacuum / background statistics collection
1071
- * will catch up eventually, but calling this explicitly after a bulk
1072
- * load gives you correct latencies immediately.
1073
- *
1074
- * Implementations:
1075
- * - SQLite runs `ANALYZE`, which populates `sqlite_stat1`
1076
- * - PostgreSQL runs `ANALYZE` on the TypeGraph-managed tables
1077
- *
1078
- * Safe to call at any time; costs a few tens of milliseconds on the
1079
- * sizes this library is designed for.
1080
- */
1081
- refreshStatistics: () => Promise<void>;
1082
- execute: <T>(query: SQL) => Promise<readonly T[]>;
1083
- /** Execute pre-compiled SQL text with bound parameters. Available on sync SQLite and pg backends. */
1084
- executeRaw?: <T>(sqlText: string, params: readonly unknown[]) => Promise<readonly T[]>;
1085
- /** Compile a Drizzle SQL object to { sql, params } without executing. */
1086
- compileSql?: (query: SQL) => Readonly<{
1087
- sql: string;
1088
- params: readonly unknown[];
1089
- }>;
1090
- transaction: <T>(fn: (tx: TransactionBackend) => Promise<T>, options?: TransactionOptions) => Promise<T>;
1091
- close: () => Promise<void>;
1092
- }>;
1093
- /**
1094
- * Parameters for inserting a unique constraint entry.
1095
- */
1096
- type InsertUniqueParams = Readonly<{
1097
- graphId: string;
1098
- nodeKind: string;
1099
- constraintName: string;
1100
- key: string;
1101
- nodeId: string;
1102
- concreteKind: string;
1103
- }>;
1104
- /**
1105
- * Parameters for deleting a unique constraint entry.
1106
- */
1107
- type DeleteUniqueParams = Readonly<{
1108
- graphId: string;
1109
- nodeKind: string;
1110
- constraintName: string;
1111
- key: string;
1112
- }>;
1113
- /**
1114
- * Parameters for checking a unique constraint.
1115
- */
1116
- type CheckUniqueParams = Readonly<{
1117
- graphId: string;
1118
- nodeKind: string;
1119
- constraintName: string;
1120
- key: string;
1121
- /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
1122
- includeDeleted?: boolean;
1123
- }>;
1124
- /**
1125
- * Parameters for batch-checking unique constraints.
1126
- */
1127
- type CheckUniqueBatchParams = Readonly<{
1128
- graphId: string;
1129
- nodeKind: string;
1130
- constraintName: string;
1131
- keys: readonly string[];
1132
- /** If true, also returns soft-deleted entries. Used by get-or-create operations. */
1133
- includeDeleted?: boolean;
1134
- }>;
1135
- /**
1136
- * Parameters for inserting a schema version.
1137
- */
1138
- type InsertSchemaParams = Readonly<{
1139
- graphId: string;
1140
- version: number;
1141
- schemaHash: string;
1142
- schemaDoc: SerializedSchema;
1143
- isActive: boolean;
1144
- }>;
1145
- /**
1146
- * Parameters for counting edges from a source node.
1147
- */
1148
- type CountEdgesFromParams = Readonly<{
1149
- graphId: string;
1150
- edgeKind: string;
1151
- fromKind: string;
1152
- fromId: string;
1153
- /** If true, only count edges where valid_to IS NULL */
1154
- activeOnly?: boolean;
1155
- }>;
1156
- /**
1157
- * Parameters for checking if an edge exists between two nodes.
1158
- */
1159
- type EdgeExistsBetweenParams = Readonly<{
1160
- graphId: string;
1161
- edgeKind: string;
1162
- fromKind: string;
1163
- fromId: string;
1164
- toKind: string;
1165
- toId: string;
1166
- }>;
1167
- /**
1168
- * Parameters for finding edges connected to a node.
1169
- */
1170
- type FindEdgesConnectedToParams = Readonly<{
1171
- graphId: string;
1172
- nodeKind: string;
1173
- nodeId: string;
1174
- }>;
1175
- /**
1176
- * Parameters for finding nodes by kind.
1177
- */
1178
- type FindNodesByKindParams = Readonly<{
1179
- graphId: string;
1180
- kind: string;
1181
- /** Max rows to return. */
1182
- limit?: number;
1183
- /** Offset. Present for backward compat; rebuild uses `after` instead. */
1184
- offset?: number;
1185
- /** If true, exclude deleted nodes. Default true. */
1186
- excludeDeleted?: boolean;
1187
- /** Temporal mode for filtering by validity period. */
1188
- temporalMode?: TemporalMode;
1189
- /** Timestamp for "current" and "asOf" temporal modes. */
1190
- asOf?: string;
1191
- /**
1192
- * Stable ordering for keyset pagination. Default: "created_at" (existing
1193
- * behavior). Rebuild should use "id" for iteration that is stable under
1194
- * concurrent writes and shared timestamps.
1195
- */
1196
- orderBy?: "id" | "created_at";
1197
- /**
1198
- * Keyset cursor. Returns rows strictly greater (by `orderBy`) than this
1199
- * value. When `orderBy: "id"`, compared lexicographically. Mutually
1200
- * exclusive with `offset` — callers pick one.
1201
- */
1202
- after?: string;
1203
- }>;
1204
- /**
1205
- * Parameters for counting nodes by kind.
1206
- */
1207
- type CountNodesByKindParams = Readonly<{
1208
- graphId: string;
1209
- kind: string;
1210
- /** If true, exclude deleted nodes. Default true. */
1211
- excludeDeleted?: boolean;
1212
- /** Temporal mode for filtering by validity period. */
1213
- temporalMode?: TemporalMode;
1214
- /** Timestamp for "current" and "asOf" temporal modes. */
1215
- asOf?: string;
1216
- }>;
1217
- /**
1218
- * Parameters for finding edges by kind.
1219
- */
1220
- type FindEdgesByKindParams = Readonly<{
1221
- graphId: string;
1222
- kind: string;
1223
- fromKind?: string;
1224
- fromId?: string;
1225
- toKind?: string;
1226
- toId?: string;
1227
- limit?: number;
1228
- offset?: number;
1229
- /** If true, exclude deleted edges. Default true. */
1230
- excludeDeleted?: boolean;
1231
- /** Temporal mode for filtering by validity period. */
1232
- temporalMode?: TemporalMode;
1233
- /** Timestamp for "current" and "asOf" temporal modes. */
1234
- asOf?: string;
1235
- }>;
1236
- /**
1237
- * Parameters for counting edges by kind.
1238
- */
1239
- type CountEdgesByKindParams = Readonly<{
1240
- graphId: string;
1241
- kind: string;
1242
- fromKind?: string;
1243
- fromId?: string;
1244
- toKind?: string;
1245
- toId?: string;
1246
- /** If true, exclude deleted edges. Default true. */
1247
- excludeDeleted?: boolean;
1248
- /** Temporal mode for filtering by validity period. */
1249
- temporalMode?: TemporalMode;
1250
- /** Timestamp for "current" and "asOf" temporal modes. */
1251
- asOf?: string;
1252
- }>;
1253
-
1254
- export { type SerializedSchema as $, type AnyEdgeType as A, type BackendCapabilities as B, type Cardinality as C, DEFAULT_SQL_SCHEMA as D, type EdgeType as E, type FulltextBatchRow as F, type GraphBackend as G, isEdgeTypeWithEndpoints as H, type InferenceType as I, isMetaEdge as J, isNodeType as K, tsvectorStrategy as L, type MetaEdge as M, type NodeType as N, type OntologyRelation as O, type EdgeRow as P, type NodeRow as Q, type VectorMetric as R, type SqlDialect as S, type TemporalMode as T, type UniqueConstraint as U, type VectorCapabilities as V, type SerializedNodeDef as W, type SerializedEdgeDef as X, type SerializedMetaEdge as Y, type SerializedOntologyRelation as Z, type SerializedClosures as _, type Collation as a, type SchemaHash as a0, type JsonSchema as a1, type SerializedOntology as a2, type SerializedUniqueConstraint as a3, type SchemaVersionRow as a4, type DeleteBehavior as b, type DeleteFulltextBatchParams as c, type EdgeId as d, type EdgeProps as e, type EdgeRegistration as f, type EdgeTypeWithEndpoints as g, type EndpointExistence as h, type FulltextCapabilities as i, type FulltextQueryMode as j, type FulltextSearchParams as k, type FulltextSearchResult as l, type FulltextStrategy as m, type GraphDefaults as n, type MetaEdgeProperties as o, type NodeId as p, type NodeProps as q, type NodeRegistration as r, type SqlSchema as s, type SqlTableNames as t, type TransactionBackend as u, type UniquenessScope as v, type UpsertFulltextBatchParams as w, createSqlSchema as x, fts5Strategy as y, isEdgeType as z };