@nicia-ai/typegraph 0.1.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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/ast-BVyihVbP.d.cts +564 -0
  4. package/dist/ast-BVyihVbP.d.ts +564 -0
  5. package/dist/backend/drizzle/index.cjs +41 -0
  6. package/dist/backend/drizzle/index.cjs.map +1 -0
  7. package/dist/backend/drizzle/index.d.cts +12 -0
  8. package/dist/backend/drizzle/index.d.ts +12 -0
  9. package/dist/backend/drizzle/index.js +12 -0
  10. package/dist/backend/drizzle/index.js.map +1 -0
  11. package/dist/backend/drizzle/postgres.cjs +27 -0
  12. package/dist/backend/drizzle/postgres.cjs.map +1 -0
  13. package/dist/backend/drizzle/postgres.d.cts +37 -0
  14. package/dist/backend/drizzle/postgres.d.ts +37 -0
  15. package/dist/backend/drizzle/postgres.js +10 -0
  16. package/dist/backend/drizzle/postgres.js.map +1 -0
  17. package/dist/backend/drizzle/schema/postgres.cjs +40 -0
  18. package/dist/backend/drizzle/schema/postgres.cjs.map +1 -0
  19. package/dist/backend/drizzle/schema/postgres.d.cts +2419 -0
  20. package/dist/backend/drizzle/schema/postgres.d.ts +2419 -0
  21. package/dist/backend/drizzle/schema/postgres.js +7 -0
  22. package/dist/backend/drizzle/schema/postgres.js.map +1 -0
  23. package/dist/backend/drizzle/schema/sqlite.cjs +40 -0
  24. package/dist/backend/drizzle/schema/sqlite.cjs.map +1 -0
  25. package/dist/backend/drizzle/schema/sqlite.d.cts +2647 -0
  26. package/dist/backend/drizzle/schema/sqlite.d.ts +2647 -0
  27. package/dist/backend/drizzle/schema/sqlite.js +7 -0
  28. package/dist/backend/drizzle/schema/sqlite.js.map +1 -0
  29. package/dist/backend/drizzle/sqlite.cjs +27 -0
  30. package/dist/backend/drizzle/sqlite.cjs.map +1 -0
  31. package/dist/backend/drizzle/sqlite.d.cts +36 -0
  32. package/dist/backend/drizzle/sqlite.d.ts +36 -0
  33. package/dist/backend/drizzle/sqlite.js +10 -0
  34. package/dist/backend/drizzle/sqlite.js.map +1 -0
  35. package/dist/backend/postgres/index.cjs +53 -0
  36. package/dist/backend/postgres/index.cjs.map +1 -0
  37. package/dist/backend/postgres/index.d.cts +12 -0
  38. package/dist/backend/postgres/index.d.ts +12 -0
  39. package/dist/backend/postgres/index.js +12 -0
  40. package/dist/backend/postgres/index.js.map +1 -0
  41. package/dist/backend/sqlite/index.cjs +117 -0
  42. package/dist/backend/sqlite/index.cjs.map +1 -0
  43. package/dist/backend/sqlite/index.d.cts +71 -0
  44. package/dist/backend/sqlite/index.d.ts +71 -0
  45. package/dist/backend/sqlite/index.js +78 -0
  46. package/dist/backend/sqlite/index.js.map +1 -0
  47. package/dist/chunk-2QHQ2C4P.js +146 -0
  48. package/dist/chunk-2QHQ2C4P.js.map +1 -0
  49. package/dist/chunk-3A5TKOEJ.js +306 -0
  50. package/dist/chunk-3A5TKOEJ.js.map +1 -0
  51. package/dist/chunk-4PIEL2VO.js +162 -0
  52. package/dist/chunk-4PIEL2VO.js.map +1 -0
  53. package/dist/chunk-536PH5FT.js +342 -0
  54. package/dist/chunk-536PH5FT.js.map +1 -0
  55. package/dist/chunk-DBFCKELK.cjs +156 -0
  56. package/dist/chunk-DBFCKELK.cjs.map +1 -0
  57. package/dist/chunk-DDM2FZRJ.cjs +1143 -0
  58. package/dist/chunk-DDM2FZRJ.cjs.map +1 -0
  59. package/dist/chunk-DGUM43GV.js +10 -0
  60. package/dist/chunk-DGUM43GV.js.map +1 -0
  61. package/dist/chunk-F32HCHYA.cjs +680 -0
  62. package/dist/chunk-F32HCHYA.cjs.map +1 -0
  63. package/dist/chunk-IIAT36MI.js +353 -0
  64. package/dist/chunk-IIAT36MI.js.map +1 -0
  65. package/dist/chunk-JDAET5LO.js +236 -0
  66. package/dist/chunk-JDAET5LO.js.map +1 -0
  67. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  68. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  69. package/dist/chunk-JKTO7TW3.js +299 -0
  70. package/dist/chunk-JKTO7TW3.js.map +1 -0
  71. package/dist/chunk-K7SQ3SWP.js +497 -0
  72. package/dist/chunk-K7SQ3SWP.js.map +1 -0
  73. package/dist/chunk-L642L24T.js +142 -0
  74. package/dist/chunk-L642L24T.js.map +1 -0
  75. package/dist/chunk-MFVCSNIY.cjs +308 -0
  76. package/dist/chunk-MFVCSNIY.cjs.map +1 -0
  77. package/dist/chunk-MNO33ASC.cjs +240 -0
  78. package/dist/chunk-MNO33ASC.cjs.map +1 -0
  79. package/dist/chunk-N4AOJ3VF.cjs +154 -0
  80. package/dist/chunk-N4AOJ3VF.cjs.map +1 -0
  81. package/dist/chunk-P5CNM325.cjs +508 -0
  82. package/dist/chunk-P5CNM325.cjs.map +1 -0
  83. package/dist/chunk-RYT4H46I.js +646 -0
  84. package/dist/chunk-RYT4H46I.js.map +1 -0
  85. package/dist/chunk-SV5H3XM5.cjs +321 -0
  86. package/dist/chunk-SV5H3XM5.cjs.map +1 -0
  87. package/dist/chunk-TXHKFLWX.cjs +344 -0
  88. package/dist/chunk-TXHKFLWX.cjs.map +1 -0
  89. package/dist/chunk-UJAGXJDG.cjs +170 -0
  90. package/dist/chunk-UJAGXJDG.cjs.map +1 -0
  91. package/dist/chunk-VXRVGFCI.js +1128 -0
  92. package/dist/chunk-VXRVGFCI.js.map +1 -0
  93. package/dist/chunk-YM5AL65Y.cjs +357 -0
  94. package/dist/chunk-YM5AL65Y.cjs.map +1 -0
  95. package/dist/index.cjs +8334 -0
  96. package/dist/index.cjs.map +1 -0
  97. package/dist/index.d.cts +1365 -0
  98. package/dist/index.d.ts +1365 -0
  99. package/dist/index.js +8105 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/indexes/index.cjs +67 -0
  102. package/dist/indexes/index.cjs.map +1 -0
  103. package/dist/indexes/index.d.cts +62 -0
  104. package/dist/indexes/index.d.ts +62 -0
  105. package/dist/indexes/index.js +6 -0
  106. package/dist/indexes/index.js.map +1 -0
  107. package/dist/interchange/index.cjs +612 -0
  108. package/dist/interchange/index.cjs.map +1 -0
  109. package/dist/interchange/index.d.cts +288 -0
  110. package/dist/interchange/index.d.ts +288 -0
  111. package/dist/interchange/index.js +598 -0
  112. package/dist/interchange/index.js.map +1 -0
  113. package/dist/profiler/index.cjs +793 -0
  114. package/dist/profiler/index.cjs.map +1 -0
  115. package/dist/profiler/index.d.cts +283 -0
  116. package/dist/profiler/index.d.ts +283 -0
  117. package/dist/profiler/index.js +785 -0
  118. package/dist/profiler/index.js.map +1 -0
  119. package/dist/store-60Lcfi0w.d.ts +2263 -0
  120. package/dist/store-Bifii8MZ.d.cts +2263 -0
  121. package/dist/test-helpers-BjyRYJZX.d.ts +22 -0
  122. package/dist/test-helpers-NoQXhleQ.d.cts +22 -0
  123. package/dist/types-BRzHlhKC.d.cts +14 -0
  124. package/dist/types-BRzHlhKC.d.ts +14 -0
  125. package/dist/types-BrSfFSpW.d.cts +158 -0
  126. package/dist/types-CX4cLd7M.d.ts +152 -0
  127. package/dist/types-CjZ7g_7v.d.ts +442 -0
  128. package/dist/types-DDOSfrih.d.cts +442 -0
  129. package/dist/types-D_3mEv2y.d.ts +158 -0
  130. package/dist/types-a5rAxC92.d.cts +152 -0
  131. package/package.json +201 -0
@@ -0,0 +1,442 @@
1
+ import { SQL } from 'drizzle-orm';
2
+ import { S as SqlDialect } from './types-BRzHlhKC.cjs';
3
+
4
+ /**
5
+ * Backend interface types for TypeGraph storage.
6
+ *
7
+ * The backend abstracts database operations, allowing different
8
+ * SQL implementations (SQLite, PostgreSQL) behind a common interface.
9
+ */
10
+
11
+ /**
12
+ * Supported vector similarity metrics.
13
+ */
14
+ type VectorMetric = "cosine" | "l2" | "inner_product";
15
+ /**
16
+ * Supported vector index types.
17
+ */
18
+ type VectorIndexType = "hnsw" | "ivfflat" | "none";
19
+ /**
20
+ * Vector search capabilities.
21
+ */
22
+ type VectorCapabilities = Readonly<{
23
+ /** Whether the backend supports vector operations */
24
+ supported: boolean;
25
+ /** Supported similarity metrics */
26
+ metrics: readonly VectorMetric[];
27
+ /** Supported index types */
28
+ indexTypes: readonly VectorIndexType[];
29
+ /** Maximum dimensions supported */
30
+ maxDimensions: number;
31
+ }>;
32
+
33
+ type Dialect = SqlDialect;
34
+ /**
35
+ * Backend capabilities that vary by dialect.
36
+ */
37
+ type BackendCapabilities = Readonly<{
38
+ /** Whether the backend supports JSONB type (vs TEXT for JSON) */
39
+ jsonb: boolean;
40
+ /** Whether the backend supports partial indexes */
41
+ partialIndexes: boolean;
42
+ /** Whether the backend supports GIN indexes for JSON */
43
+ ginIndexes: boolean;
44
+ /** Whether the backend supports CTE (WITH) queries */
45
+ cte: boolean;
46
+ /** Whether the backend supports RETURNING clause */
47
+ returning: boolean;
48
+ /** Whether the backend supports atomic transactions (D1 does not) */
49
+ transactions: boolean;
50
+ /** Vector search capabilities (undefined if not configured) */
51
+ vector?: VectorCapabilities | undefined;
52
+ }>;
53
+ /**
54
+ * A row from the typegraph_nodes table.
55
+ */
56
+ type NodeRow = Readonly<{
57
+ graph_id: string;
58
+ kind: string;
59
+ id: string;
60
+ props: string;
61
+ version: number;
62
+ valid_from: string | undefined;
63
+ valid_to: string | undefined;
64
+ created_at: string;
65
+ updated_at: string;
66
+ deleted_at: string | undefined;
67
+ }>;
68
+ /**
69
+ * A row from the typegraph_edges table.
70
+ */
71
+ type EdgeRow = Readonly<{
72
+ graph_id: string;
73
+ id: string;
74
+ kind: string;
75
+ from_kind: string;
76
+ from_id: string;
77
+ to_kind: string;
78
+ to_id: string;
79
+ props: string;
80
+ valid_from: string | undefined;
81
+ valid_to: string | undefined;
82
+ created_at: string;
83
+ updated_at: string;
84
+ deleted_at: string | undefined;
85
+ }>;
86
+ /**
87
+ * A row from the typegraph_node_uniques table.
88
+ */
89
+ type UniqueRow = Readonly<{
90
+ graph_id: string;
91
+ node_kind: string;
92
+ constraint_name: string;
93
+ key: string;
94
+ node_id: string;
95
+ concrete_kind: string;
96
+ deleted_at: string | undefined;
97
+ }>;
98
+ /**
99
+ * A row from the typegraph_schema_versions table.
100
+ */
101
+ type SchemaVersionRow = Readonly<{
102
+ graph_id: string;
103
+ version: number;
104
+ schema_hash: string;
105
+ schema_doc: string;
106
+ created_at: string;
107
+ is_active: boolean;
108
+ }>;
109
+ /**
110
+ * A row from the typegraph_node_embeddings table.
111
+ */
112
+ type EmbeddingRow = Readonly<{
113
+ graph_id: string;
114
+ node_kind: string;
115
+ node_id: string;
116
+ field_path: string;
117
+ embedding: readonly number[];
118
+ dimensions: number;
119
+ created_at: string;
120
+ updated_at: string;
121
+ }>;
122
+ /**
123
+ * Parameters for inserting a node.
124
+ */
125
+ type InsertNodeParams = Readonly<{
126
+ graphId: string;
127
+ kind: string;
128
+ id: string;
129
+ props: Record<string, unknown>;
130
+ validFrom?: string;
131
+ validTo?: string;
132
+ }>;
133
+ /**
134
+ * Parameters for updating a node.
135
+ */
136
+ type UpdateNodeParams = Readonly<{
137
+ graphId: string;
138
+ kind: string;
139
+ id: string;
140
+ props: Record<string, unknown>;
141
+ validTo?: string;
142
+ incrementVersion?: boolean;
143
+ /** If true, clears deleted_at (un-deletes the node). Used by upsert. */
144
+ clearDeleted?: boolean;
145
+ }>;
146
+ /**
147
+ * Parameters for deleting a node (soft delete).
148
+ */
149
+ type DeleteNodeParams = Readonly<{
150
+ graphId: string;
151
+ kind: string;
152
+ id: string;
153
+ }>;
154
+ /**
155
+ * Parameters for inserting an edge.
156
+ */
157
+ type InsertEdgeParams = Readonly<{
158
+ graphId: string;
159
+ id: string;
160
+ kind: string;
161
+ fromKind: string;
162
+ fromId: string;
163
+ toKind: string;
164
+ toId: string;
165
+ props: Record<string, unknown>;
166
+ validFrom?: string;
167
+ validTo?: string;
168
+ }>;
169
+ /**
170
+ * Parameters for updating an edge.
171
+ */
172
+ type UpdateEdgeParams = Readonly<{
173
+ graphId: string;
174
+ id: string;
175
+ props: Record<string, unknown>;
176
+ validTo?: string;
177
+ }>;
178
+ /**
179
+ * Parameters for deleting an edge (soft delete).
180
+ */
181
+ type DeleteEdgeParams = Readonly<{
182
+ graphId: string;
183
+ id: string;
184
+ }>;
185
+ /**
186
+ * Parameters for hard deleting a node (permanent removal).
187
+ */
188
+ type HardDeleteNodeParams = Readonly<{
189
+ graphId: string;
190
+ kind: string;
191
+ id: string;
192
+ }>;
193
+ /**
194
+ * Parameters for hard deleting an edge (permanent removal).
195
+ */
196
+ type HardDeleteEdgeParams = Readonly<{
197
+ graphId: string;
198
+ id: string;
199
+ }>;
200
+ /**
201
+ * Parameters for inserting or updating an embedding.
202
+ */
203
+ type UpsertEmbeddingParams = Readonly<{
204
+ graphId: string;
205
+ nodeKind: string;
206
+ nodeId: string;
207
+ fieldPath: string;
208
+ embedding: readonly number[];
209
+ dimensions: number;
210
+ }>;
211
+ /**
212
+ * Parameters for deleting an embedding.
213
+ */
214
+ type DeleteEmbeddingParams = Readonly<{
215
+ graphId: string;
216
+ nodeKind: string;
217
+ nodeId: string;
218
+ fieldPath: string;
219
+ }>;
220
+ /**
221
+ * Parameters for vector similarity search.
222
+ */
223
+ type VectorSearchParams = Readonly<{
224
+ graphId: string;
225
+ nodeKind: string;
226
+ fieldPath: string;
227
+ queryEmbedding: readonly number[];
228
+ metric: VectorMetric;
229
+ limit: number;
230
+ minScore?: number;
231
+ }>;
232
+ /**
233
+ * Result from a vector similarity search.
234
+ */
235
+ type VectorSearchResult = Readonly<{
236
+ nodeId: string;
237
+ score: number;
238
+ }>;
239
+ /**
240
+ * Parameters for creating a vector index.
241
+ */
242
+ type CreateVectorIndexParams = Readonly<{
243
+ graphId: string;
244
+ nodeKind: string;
245
+ fieldPath: string;
246
+ dimensions: number;
247
+ metric: VectorMetric;
248
+ indexType: VectorIndexType;
249
+ /** Index-specific parameters */
250
+ indexParams?: Readonly<{
251
+ /** HNSW: max connections per layer */
252
+ m?: number;
253
+ /** HNSW: construction search depth */
254
+ efConstruction?: number;
255
+ /** IVFFlat: number of lists */
256
+ lists?: number;
257
+ }>;
258
+ }>;
259
+ /**
260
+ * Parameters for dropping a vector index.
261
+ */
262
+ type DropVectorIndexParams = Readonly<{
263
+ graphId: string;
264
+ nodeKind: string;
265
+ fieldPath: string;
266
+ }>;
267
+ /**
268
+ * Transaction options.
269
+ */
270
+ type TransactionOptions = Readonly<{
271
+ /** Transaction isolation level (if supported) */
272
+ isolationLevel?: "read_uncommitted" | "read_committed" | "repeatable_read" | "serializable";
273
+ }>;
274
+ /**
275
+ * Transaction backend - a backend scoped to a transaction.
276
+ */
277
+ type TransactionBackend = Omit<GraphBackend, "transaction" | "close">;
278
+ /**
279
+ * The GraphBackend interface abstracts database operations.
280
+ *
281
+ * Implementations should provide:
282
+ * - SQLite backend via better-sqlite3 or libsql
283
+ * - PostgreSQL backend via pg or postgres
284
+ */
285
+ type GraphBackend = Readonly<{
286
+ /** The SQL dialect */
287
+ dialect: Dialect;
288
+ /** Backend capabilities */
289
+ capabilities: BackendCapabilities;
290
+ insertNode: (params: InsertNodeParams) => Promise<NodeRow>;
291
+ updateNode: (params: UpdateNodeParams) => Promise<NodeRow>;
292
+ deleteNode: (params: DeleteNodeParams) => Promise<void>;
293
+ hardDeleteNode: (params: HardDeleteNodeParams) => Promise<void>;
294
+ getNode: (graphId: string, kind: string, id: string) => Promise<NodeRow | undefined>;
295
+ insertEdge: (params: InsertEdgeParams) => Promise<EdgeRow>;
296
+ updateEdge: (params: UpdateEdgeParams) => Promise<EdgeRow>;
297
+ deleteEdge: (params: DeleteEdgeParams) => Promise<void>;
298
+ hardDeleteEdge: (params: HardDeleteEdgeParams) => Promise<void>;
299
+ getEdge: (graphId: string, id: string) => Promise<EdgeRow | undefined>;
300
+ countEdgesFrom: (params: CountEdgesFromParams) => Promise<number>;
301
+ edgeExistsBetween: (params: EdgeExistsBetweenParams) => Promise<boolean>;
302
+ findEdgesConnectedTo: (params: FindEdgesConnectedToParams) => Promise<readonly EdgeRow[]>;
303
+ findNodesByKind: (params: FindNodesByKindParams) => Promise<readonly NodeRow[]>;
304
+ countNodesByKind: (params: CountNodesByKindParams) => Promise<number>;
305
+ findEdgesByKind: (params: FindEdgesByKindParams) => Promise<readonly EdgeRow[]>;
306
+ countEdgesByKind: (params: CountEdgesByKindParams) => Promise<number>;
307
+ insertUnique: (params: InsertUniqueParams) => Promise<void>;
308
+ deleteUnique: (params: DeleteUniqueParams) => Promise<void>;
309
+ checkUnique: (params: CheckUniqueParams) => Promise<UniqueRow | undefined>;
310
+ getActiveSchema: (graphId: string) => Promise<SchemaVersionRow | undefined>;
311
+ getSchemaVersion: (graphId: string, version: number) => Promise<SchemaVersionRow | undefined>;
312
+ insertSchema: (params: InsertSchemaParams) => Promise<SchemaVersionRow>;
313
+ setActiveSchema: (graphId: string, version: number) => Promise<void>;
314
+ upsertEmbedding?: (params: UpsertEmbeddingParams) => Promise<void>;
315
+ deleteEmbedding?: (params: DeleteEmbeddingParams) => Promise<void>;
316
+ getEmbedding?: (graphId: string, nodeKind: string, nodeId: string, fieldPath: string) => Promise<EmbeddingRow | undefined>;
317
+ vectorSearch?: (params: VectorSearchParams) => Promise<readonly VectorSearchResult[]>;
318
+ createVectorIndex?: (params: CreateVectorIndexParams) => Promise<void>;
319
+ dropVectorIndex?: (params: DropVectorIndexParams) => Promise<void>;
320
+ execute: <T>(query: SQL) => Promise<readonly T[]>;
321
+ transaction: <T>(fn: (tx: TransactionBackend) => Promise<T>, options?: TransactionOptions) => Promise<T>;
322
+ close: () => Promise<void>;
323
+ }>;
324
+ /**
325
+ * Parameters for inserting a unique constraint entry.
326
+ */
327
+ type InsertUniqueParams = Readonly<{
328
+ graphId: string;
329
+ nodeKind: string;
330
+ constraintName: string;
331
+ key: string;
332
+ nodeId: string;
333
+ concreteKind: string;
334
+ }>;
335
+ /**
336
+ * Parameters for deleting a unique constraint entry.
337
+ */
338
+ type DeleteUniqueParams = Readonly<{
339
+ graphId: string;
340
+ nodeKind: string;
341
+ constraintName: string;
342
+ key: string;
343
+ }>;
344
+ /**
345
+ * Parameters for checking a unique constraint.
346
+ */
347
+ type CheckUniqueParams = Readonly<{
348
+ graphId: string;
349
+ nodeKind: string;
350
+ constraintName: string;
351
+ key: string;
352
+ }>;
353
+ /**
354
+ * Parameters for inserting a schema version.
355
+ */
356
+ type InsertSchemaParams = Readonly<{
357
+ graphId: string;
358
+ version: number;
359
+ schemaHash: string;
360
+ schemaDoc: Record<string, unknown>;
361
+ isActive: boolean;
362
+ }>;
363
+ /**
364
+ * Parameters for counting edges from a source node.
365
+ */
366
+ type CountEdgesFromParams = Readonly<{
367
+ graphId: string;
368
+ edgeKind: string;
369
+ fromKind: string;
370
+ fromId: string;
371
+ /** If true, only count edges where valid_to IS NULL */
372
+ activeOnly?: boolean;
373
+ }>;
374
+ /**
375
+ * Parameters for checking if an edge exists between two nodes.
376
+ */
377
+ type EdgeExistsBetweenParams = Readonly<{
378
+ graphId: string;
379
+ edgeKind: string;
380
+ fromKind: string;
381
+ fromId: string;
382
+ toKind: string;
383
+ toId: string;
384
+ }>;
385
+ /**
386
+ * Parameters for finding edges connected to a node.
387
+ */
388
+ type FindEdgesConnectedToParams = Readonly<{
389
+ graphId: string;
390
+ nodeKind: string;
391
+ nodeId: string;
392
+ }>;
393
+ /**
394
+ * Parameters for finding nodes by kind.
395
+ */
396
+ type FindNodesByKindParams = Readonly<{
397
+ graphId: string;
398
+ kind: string;
399
+ limit?: number;
400
+ offset?: number;
401
+ /** If true, exclude deleted nodes. Default true. */
402
+ excludeDeleted?: boolean;
403
+ }>;
404
+ /**
405
+ * Parameters for counting nodes by kind.
406
+ */
407
+ type CountNodesByKindParams = Readonly<{
408
+ graphId: string;
409
+ kind: string;
410
+ /** If true, exclude deleted nodes. Default true. */
411
+ excludeDeleted?: boolean;
412
+ }>;
413
+ /**
414
+ * Parameters for finding edges by kind.
415
+ */
416
+ type FindEdgesByKindParams = Readonly<{
417
+ graphId: string;
418
+ kind: string;
419
+ fromKind?: string;
420
+ fromId?: string;
421
+ toKind?: string;
422
+ toId?: string;
423
+ limit?: number;
424
+ offset?: number;
425
+ /** If true, exclude deleted edges. Default true. */
426
+ excludeDeleted?: boolean;
427
+ }>;
428
+ /**
429
+ * Parameters for counting edges by kind.
430
+ */
431
+ type CountEdgesByKindParams = Readonly<{
432
+ graphId: string;
433
+ kind: string;
434
+ fromKind?: string;
435
+ fromId?: string;
436
+ toKind?: string;
437
+ toId?: string;
438
+ /** If true, exclude deleted edges. Default true. */
439
+ excludeDeleted?: boolean;
440
+ }>;
441
+
442
+ export type { GraphBackend as G, SchemaVersionRow as S, TransactionBackend as T };
@@ -0,0 +1,158 @@
1
+ import { J as JsonPointer } from './ast-BVyihVbP.js';
2
+
3
+ /**
4
+ * QueryProfiler types.
5
+ *
6
+ * Type definitions for the query profiling system that captures
7
+ * property access patterns and generates index recommendations.
8
+ */
9
+
10
+ type ProfileEntityType = "node" | "edge";
11
+ type PropertyTarget = Readonly<{
12
+ __type: "prop";
13
+ pointer: JsonPointer;
14
+ }> | Readonly<{
15
+ __type: "system";
16
+ field: string;
17
+ }>;
18
+ /**
19
+ * Represents a property access path.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Simple property access
24
+ * { entityType: "node", kind: "Person", target: { __type: "prop", pointer: "/email" } }
25
+ *
26
+ * // Nested property access
27
+ * { entityType: "node", kind: "Order", target: { __type: "prop", pointer: "/metadata/priority" } }
28
+ * ```
29
+ */
30
+ type PropertyPath = Readonly<{
31
+ entityType: ProfileEntityType;
32
+ kind: string;
33
+ target: PropertyTarget;
34
+ }>;
35
+ /**
36
+ * Usage context for a property access.
37
+ */
38
+ type UsageContext = "filter" | "sort" | "select" | "groupBy";
39
+ /**
40
+ * Statistics for a property access pattern.
41
+ */
42
+ type PropertyAccessStats = Readonly<{
43
+ /** Number of times this property was accessed */
44
+ count: number;
45
+ /** Contexts in which this property was used */
46
+ contexts: ReadonlySet<UsageContext>;
47
+ /** Predicate types used with this property (eq, contains, gt, etc.) */
48
+ predicateTypes: ReadonlySet<string>;
49
+ /** When this pattern was first observed */
50
+ firstSeen: Date;
51
+ /** When this pattern was last observed */
52
+ lastSeen: Date;
53
+ }>;
54
+ /**
55
+ * A declared index for comparison against usage patterns.
56
+ *
57
+ * Pass these to QueryProfiler to exclude already-indexed
58
+ * properties from recommendations.
59
+ */
60
+ type DeclaredIndex = Readonly<{
61
+ /** Whether this index applies to nodes or edges */
62
+ entityType: ProfileEntityType;
63
+ /** The kind name this index applies to */
64
+ kind: string;
65
+ /** Props JSON pointers covered by this index (in key order for composite indexes) */
66
+ fields: readonly JsonPointer[];
67
+ /** Whether this is a unique index */
68
+ unique: boolean;
69
+ /** Index name (for reference in reports) */
70
+ name: string;
71
+ }>;
72
+ /**
73
+ * Priority level for index recommendations.
74
+ */
75
+ type RecommendationPriority = "high" | "medium" | "low";
76
+ /**
77
+ * An index recommendation based on observed query patterns.
78
+ */
79
+ type IndexRecommendation = Readonly<{
80
+ /** Whether this recommendation is for nodes or edges */
81
+ entityType: ProfileEntityType;
82
+ /** The kind name that would benefit from this index */
83
+ kind: string;
84
+ /** Props JSON pointers to index (in key order for composite indexes) */
85
+ fields: readonly JsonPointer[];
86
+ /** Human-readable reason for the recommendation */
87
+ reason: string;
88
+ /** How often this property was accessed */
89
+ frequency: number;
90
+ /** Priority based on frequency and usage context */
91
+ priority: RecommendationPriority;
92
+ }>;
93
+ /**
94
+ * Summary statistics for a profiling session.
95
+ */
96
+ type ProfileSummary = Readonly<{
97
+ /** Total number of queries executed */
98
+ totalQueries: number;
99
+ /** Number of unique property access patterns */
100
+ uniquePatterns: number;
101
+ /** When profiling started */
102
+ startedAt: Date;
103
+ /** Duration of profiling session in milliseconds */
104
+ durationMs: number;
105
+ }>;
106
+ /**
107
+ * Complete profiler report with patterns, recommendations, and summary.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const report = profiler.getReport();
112
+ *
113
+ * console.log(`Total queries: ${report.summary.totalQueries}`);
114
+ * console.log(`Unique patterns: ${report.summary.uniquePatterns}`);
115
+ *
116
+ * for (const rec of report.recommendations) {
117
+ * console.log(`[${rec.priority}] ${rec.entityType}:${rec.kind} ${rec.fields.join(", ")}: ${rec.reason}`);
118
+ * }
119
+ * ```
120
+ */
121
+ type ProfileReport = Readonly<{
122
+ /** All property access patterns aggregated by path */
123
+ patterns: ReadonlyMap<string, PropertyAccessStats>;
124
+ /** Index recommendations sorted by priority */
125
+ recommendations: readonly IndexRecommendation[];
126
+ /** Summary statistics */
127
+ summary: ProfileSummary;
128
+ /** Properties used in filters that lack indexes */
129
+ unindexedFilters: readonly PropertyPath[];
130
+ }>;
131
+ /**
132
+ * Options for configuring the QueryProfiler.
133
+ */
134
+ type ProfilerOptions = Readonly<{
135
+ /**
136
+ * Declared indexes to compare against usage patterns.
137
+ * Properties covered by these indexes will be excluded from recommendations.
138
+ */
139
+ declaredIndexes?: readonly DeclaredIndex[];
140
+ /**
141
+ * Minimum frequency for a property to be included in recommendations.
142
+ * Properties accessed fewer times than this will not generate recommendations.
143
+ * @default 3
144
+ */
145
+ minFrequencyForRecommendation?: number;
146
+ /**
147
+ * Minimum frequency for a `medium` priority recommendation.
148
+ * @default 5
149
+ */
150
+ mediumFrequencyThreshold?: number;
151
+ /**
152
+ * Minimum frequency for a `high` priority recommendation.
153
+ * @default 10
154
+ */
155
+ highFrequencyThreshold?: number;
156
+ }>;
157
+
158
+ export type { DeclaredIndex as D, IndexRecommendation as I, ProfilerOptions as P, RecommendationPriority as R, UsageContext as U, ProfileReport as a, ProfileEntityType as b, PropertyTarget as c, PropertyPath as d, PropertyAccessStats as e, ProfileSummary as f };