@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,283 @@
1
+ import { G as GraphDef, S as Store } from '../store-60Lcfi0w.js';
2
+ import { Q as QueryAst } from '../ast-BVyihVbP.js';
3
+ import { P as ProfilerOptions, a as ProfileReport, b as ProfileEntityType, c as PropertyTarget, U as UsageContext, d as PropertyPath, e as PropertyAccessStats, f as ProfileSummary, D as DeclaredIndex, I as IndexRecommendation } from '../types-D_3mEv2y.js';
4
+ export { R as RecommendationPriority } from '../types-D_3mEv2y.js';
5
+ import '../types-CjZ7g_7v.js';
6
+ import 'drizzle-orm';
7
+ import '../types-BRzHlhKC.js';
8
+ import 'zod';
9
+
10
+ /**
11
+ * QueryProfiler - Main profiler class.
12
+ *
13
+ * Captures query patterns from the AST and generates index recommendations.
14
+ * Uses Proxy to wrap Store and QueryBuilder for transparent interception.
15
+ */
16
+
17
+ /**
18
+ * A Store with profiling capabilities.
19
+ *
20
+ * Behaves exactly like a regular Store but tracks all query executions.
21
+ * Access the profiler via the `profiler` property.
22
+ */
23
+ type ProfiledStore<G extends GraphDef> = Store<G> & {
24
+ /** The profiler instance attached to this store */
25
+ readonly profiler: QueryProfiler;
26
+ };
27
+ /**
28
+ * QueryProfiler captures and analyzes query patterns.
29
+ *
30
+ * Attach to a store to automatically track all query executions,
31
+ * then generate reports with index recommendations.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { QueryProfiler } from "@nicia-ai/typegraph/profiler";
36
+ *
37
+ * const profiler = new QueryProfiler({
38
+ * declaredIndexes: [
39
+ * { nodeKind: "Person", fields: ["email"], unique: true, name: "idx_email" },
40
+ * ],
41
+ * });
42
+ *
43
+ * const profiledStore = profiler.attachToStore(store);
44
+ *
45
+ * // Run queries...
46
+ * await profiledStore.query()
47
+ * .from("Person", "p")
48
+ * .whereNode("p", (p) => p.email.eq("alice@example.com"))
49
+ * .select((ctx) => ctx.p)
50
+ * .execute();
51
+ *
52
+ * // Get report
53
+ * const report = profiler.getReport();
54
+ * console.log(report.recommendations);
55
+ * ```
56
+ */
57
+ declare class QueryProfiler {
58
+ #private;
59
+ constructor(options?: ProfilerOptions);
60
+ /**
61
+ * Records a query execution from its AST.
62
+ *
63
+ * This is called automatically when attached to a store.
64
+ * Can also be called manually for custom integrations.
65
+ *
66
+ * @param ast - The query AST to analyze
67
+ */
68
+ recordQuery(ast: QueryAst): void;
69
+ /**
70
+ * Attaches the profiler to a store.
71
+ *
72
+ * Returns a wrapped store that tracks all query executions.
73
+ * The wrapped store behaves identically to the original.
74
+ *
75
+ * @param store - The store to attach to
76
+ * @returns A profiled store with the `profiler` property
77
+ * @throws Error if the profiler is already attached to another store
78
+ */
79
+ attachToStore<G extends GraphDef>(store: Store<G>): ProfiledStore<G>;
80
+ /**
81
+ * Generates a complete profile report.
82
+ *
83
+ * The report includes:
84
+ * - All property access patterns with frequency and context
85
+ * - Index recommendations sorted by priority
86
+ * - List of unindexed filter properties
87
+ * - Summary statistics
88
+ *
89
+ * @returns The profile report
90
+ */
91
+ getReport(): ProfileReport;
92
+ /**
93
+ * Checks if all filtered properties are covered by indexes.
94
+ *
95
+ * Throws an error if any filtered properties lack indexes.
96
+ * Useful for test assertions to ensure query performance.
97
+ *
98
+ * @throws Error if unindexed filter properties are found
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // In your test file
103
+ * it("all filtered properties should be indexed", () => {
104
+ * profiler.assertIndexCoverage();
105
+ * });
106
+ * ```
107
+ */
108
+ assertIndexCoverage(): void;
109
+ /**
110
+ * Resets all collected data.
111
+ *
112
+ * Clears patterns and query count. Useful for starting a fresh
113
+ * profiling session without creating a new profiler instance.
114
+ */
115
+ reset(): void;
116
+ /**
117
+ * Marks the profiler as detached.
118
+ *
119
+ * Call this when you're done profiling to allow reattachment
120
+ * to the same or a different store.
121
+ */
122
+ detach(): void;
123
+ /**
124
+ * Whether the profiler is currently attached to a store.
125
+ */
126
+ get isAttached(): boolean;
127
+ }
128
+
129
+ /**
130
+ * AST Extractor - Extracts property access patterns from QueryAst.
131
+ *
132
+ * Walks the query AST to identify all property accesses and their
133
+ * usage contexts (filter, sort, select, groupBy).
134
+ */
135
+
136
+ /**
137
+ * A property access extracted from the AST.
138
+ */
139
+ type ExtractedAccess = Readonly<{
140
+ /** Whether the access targets nodes or edges */
141
+ entityType: ProfileEntityType;
142
+ /** Expanded kind names for the alias */
143
+ kindNames: readonly string[];
144
+ /** The accessed target (props pointer or system field) */
145
+ target: PropertyTarget;
146
+ /** How the property was used */
147
+ context: UsageContext;
148
+ /** Predicate type if used in a filter (eq, contains, gt, etc.) */
149
+ predicateType?: string;
150
+ }>;
151
+ /**
152
+ * Extracts all property accesses from a QueryAst.
153
+ *
154
+ * Walks the AST to find all property references and categorizes
155
+ * them by usage context (filter, sort, select, groupBy).
156
+ *
157
+ * @param ast - The query AST to analyze
158
+ * @returns Array of extracted property accesses
159
+ */
160
+ declare function extractPropertyAccesses(ast: QueryAst): readonly ExtractedAccess[];
161
+
162
+ /**
163
+ * ProfileCollector - Aggregates property access patterns.
164
+ *
165
+ * Mutable collector that tracks property access patterns across queries
166
+ * and provides immutable snapshots for reporting.
167
+ */
168
+
169
+ /**
170
+ * Converts a PropertyPath to a string key for Map storage.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * pathToKey({
175
+ * entityType: "node",
176
+ * kind: "Person",
177
+ * target: { __type: "prop", pointer: "/email" },
178
+ * })
179
+ * // => "node:Person:/email"
180
+ * ```
181
+ */
182
+ declare function pathToKey(path: PropertyPath): string;
183
+ /**
184
+ * Parses a key back to a PropertyPath.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * keyToPath("node:Person:/email")
189
+ * // => { entityType: "node", kind: "Person", target: { __type: "prop", pointer: "/email" } }
190
+ * ```
191
+ */
192
+ declare function keyToPath(key: string): PropertyPath;
193
+ /**
194
+ * Collects and aggregates property access patterns.
195
+ *
196
+ * This class is mutable internally but provides immutable snapshots
197
+ * via `getPatterns()` and `getSummary()`.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * const collector = new ProfileCollector();
202
+ *
203
+ * collector.record(
204
+ * { nodeKind: "Person", fieldPath: ["email"] },
205
+ * "filter",
206
+ * "eq"
207
+ * );
208
+ * collector.recordQuery();
209
+ *
210
+ * const patterns = collector.getPatterns();
211
+ * const summary = collector.getSummary();
212
+ * ```
213
+ */
214
+ declare class ProfileCollector {
215
+ #private;
216
+ /**
217
+ * Records a property access.
218
+ *
219
+ * @param path - The property path that was accessed
220
+ * @param context - How the property was used (filter, sort, select, groupBy)
221
+ * @param predicateType - Optional predicate type (eq, contains, gt, etc.)
222
+ */
223
+ record(path: PropertyPath, context: UsageContext, predicateType?: string): void;
224
+ /**
225
+ * Increments the query count.
226
+ * Call this once per query execution.
227
+ */
228
+ recordQuery(): void;
229
+ /**
230
+ * Gets all patterns as an immutable map.
231
+ *
232
+ * Returns a new Map with immutable stats objects.
233
+ */
234
+ getPatterns(): ReadonlyMap<string, PropertyAccessStats>;
235
+ /**
236
+ * Gets summary statistics.
237
+ */
238
+ getSummary(): ProfileSummary;
239
+ /**
240
+ * Resets all collected data.
241
+ *
242
+ * Note: This does not reset the startedAt timestamp.
243
+ * Create a new ProfileCollector for a fresh session.
244
+ */
245
+ reset(): void;
246
+ }
247
+
248
+ /**
249
+ * Index Recommendations - Generates index suggestions from usage patterns.
250
+ *
251
+ * Analyzes collected property access patterns and generates prioritized
252
+ * recommendations for missing indexes.
253
+ */
254
+
255
+ type GenerateRecommendationsOptions = Readonly<{
256
+ minFrequencyForRecommendation?: number;
257
+ mediumFrequencyThreshold?: number;
258
+ highFrequencyThreshold?: number;
259
+ }>;
260
+ /**
261
+ * Generates index recommendations based on usage patterns.
262
+ *
263
+ * Analyzes property access patterns and returns prioritized recommendations
264
+ * for properties that would benefit from indexing.
265
+ *
266
+ * @param patterns - Collected property access patterns
267
+ * @param declaredIndexes - Indexes that already exist
268
+ * @param options - Threshold configuration (or legacy `minFrequency` number)
269
+ * @returns Sorted array of index recommendations
270
+ */
271
+ declare function generateRecommendations(patterns: ReadonlyMap<string, PropertyAccessStats>, declaredIndexes: readonly DeclaredIndex[], options?: number | GenerateRecommendationsOptions): readonly IndexRecommendation[];
272
+ /**
273
+ * Gets properties used in filters that lack indexes.
274
+ *
275
+ * Useful for test assertions to ensure all filtered properties are indexed.
276
+ *
277
+ * @param patterns - Collected property access patterns
278
+ * @param declaredIndexes - Indexes that already exist
279
+ * @returns Array of unindexed property paths
280
+ */
281
+ declare function getUnindexedFilters(patterns: ReadonlyMap<string, PropertyAccessStats>, declaredIndexes: readonly DeclaredIndex[]): readonly PropertyPath[];
282
+
283
+ export { DeclaredIndex, type ExtractedAccess, IndexRecommendation, ProfileCollector, ProfileReport, ProfileSummary, type ProfiledStore, ProfilerOptions, PropertyAccessStats, PropertyPath, QueryProfiler, UsageContext, extractPropertyAccesses, generateRecommendations, getUnindexedFilters, keyToPath, pathToKey };