@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,1143 @@
1
+ 'use strict';
2
+
3
+ var chunkYM5AL65Y_cjs = require('./chunk-YM5AL65Y.cjs');
4
+ var chunkP5CNM325_cjs = require('./chunk-P5CNM325.cjs');
5
+ var drizzleOrm = require('drizzle-orm');
6
+ var casing = require('drizzle-orm/casing');
7
+ var pgCore = require('drizzle-orm/pg-core');
8
+ var sqliteCore = require('drizzle-orm/sqlite-core');
9
+
10
+ function compileNodeIndexKeys(index, dialect, propsColumn, systemColumn) {
11
+ const adapter = chunkYM5AL65Y_cjs.getDialect(dialect);
12
+ const keys = [];
13
+ for (const column of getNodeScopeColumns(index.scope)) {
14
+ keys.push(systemColumn(column));
15
+ }
16
+ const allPointers = [...index.fields, ...index.coveringFields];
17
+ const allValueTypes = [
18
+ ...index.fieldValueTypes,
19
+ ...index.coveringFieldValueTypes
20
+ ];
21
+ for (const [pointerIndex, pointer] of allPointers.entries()) {
22
+ const valueType = allValueTypes[pointerIndex];
23
+ const extracted = compileIndexKeyValue(
24
+ adapter,
25
+ propsColumn,
26
+ pointer,
27
+ valueType
28
+ );
29
+ keys.push(drizzleOrm.sql`(${extracted})`);
30
+ }
31
+ return { keys };
32
+ }
33
+ function compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn) {
34
+ const adapter = chunkYM5AL65Y_cjs.getDialect(dialect);
35
+ const keys = [];
36
+ for (const column of getEdgeScopeColumns(index.scope, index.direction)) {
37
+ keys.push(systemColumn(column));
38
+ }
39
+ const allPointers = [...index.fields, ...index.coveringFields];
40
+ const allValueTypes = [
41
+ ...index.fieldValueTypes,
42
+ ...index.coveringFieldValueTypes
43
+ ];
44
+ for (const [pointerIndex, pointer] of allPointers.entries()) {
45
+ const valueType = allValueTypes[pointerIndex];
46
+ const extracted = compileIndexKeyValue(
47
+ adapter,
48
+ propsColumn,
49
+ pointer,
50
+ valueType
51
+ );
52
+ keys.push(drizzleOrm.sql`(${extracted})`);
53
+ }
54
+ return { keys };
55
+ }
56
+ function compileIndexKeyValue(dialect, propsColumn, pointer, valueType) {
57
+ switch (valueType) {
58
+ case "number": {
59
+ return dialect.jsonExtractNumber(propsColumn, pointer);
60
+ }
61
+ case "boolean": {
62
+ return dialect.jsonExtractBoolean(propsColumn, pointer);
63
+ }
64
+ case "date": {
65
+ return dialect.jsonExtractDate(propsColumn, pointer);
66
+ }
67
+ case "string":
68
+ case "unknown":
69
+ case void 0: {
70
+ return dialect.jsonExtractText(propsColumn, pointer);
71
+ }
72
+ case "array":
73
+ case "object":
74
+ case "embedding": {
75
+ return dialect.jsonExtract(propsColumn, pointer);
76
+ }
77
+ }
78
+ }
79
+ function getNodeScopeColumns(scope) {
80
+ switch (scope) {
81
+ case "graphAndKind": {
82
+ return ["graph_id", "kind"];
83
+ }
84
+ case "graph": {
85
+ return ["graph_id"];
86
+ }
87
+ case "none": {
88
+ return [];
89
+ }
90
+ }
91
+ }
92
+ function getEdgeScopeColumns(scope, direction) {
93
+ const base = scope === "graphAndKind" ? ["graph_id", "kind"] : scope === "graph" ? ["graph_id"] : [];
94
+ if (direction === "out") {
95
+ return [...base, "from_id"];
96
+ }
97
+ if (direction === "in") {
98
+ return [...base, "to_id"];
99
+ }
100
+ return [...base];
101
+ }
102
+ function isIndexWhereLiteralList(value) {
103
+ return Array.isArray(value);
104
+ }
105
+ function compileIndexWhere(ctx, expression) {
106
+ switch (expression.__type) {
107
+ case "index_where_and": {
108
+ return drizzleOrm.sql`(${drizzleOrm.sql.join(
109
+ expression.predicates.map((p) => compileIndexWhere(ctx, p)),
110
+ drizzleOrm.sql` AND `
111
+ )})`;
112
+ }
113
+ case "index_where_or": {
114
+ return drizzleOrm.sql`(${drizzleOrm.sql.join(
115
+ expression.predicates.map((p) => compileIndexWhere(ctx, p)),
116
+ drizzleOrm.sql` OR `
117
+ )})`;
118
+ }
119
+ case "index_where_not": {
120
+ return drizzleOrm.sql`(NOT ${compileIndexWhere(ctx, expression.predicate)})`;
121
+ }
122
+ case "index_where_null_check": {
123
+ const operand = compileIndexWhereOperand(ctx, expression.operand);
124
+ return expression.op === "isNull" ? drizzleOrm.sql`${operand} IS NULL` : drizzleOrm.sql`${operand} IS NOT NULL`;
125
+ }
126
+ case "index_where_comparison": {
127
+ const left = compileIndexWhereOperand(ctx, expression.left);
128
+ const right = expression.right;
129
+ if (isIndexWhereLiteralList(right)) {
130
+ if (expression.op !== "in" && expression.op !== "notIn") {
131
+ throw new Error(
132
+ `Operator "${expression.op}" does not support list comparison in index WHERE clause`
133
+ );
134
+ }
135
+ const values = right.map(
136
+ (literal) => compileIndexWhereLiteral(ctx.dialect, literal)
137
+ );
138
+ const operator = expression.op === "in" ? drizzleOrm.sql`IN` : drizzleOrm.sql`NOT IN`;
139
+ return drizzleOrm.sql`${left} ${operator} (${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)})`;
140
+ }
141
+ if (expression.op === "in" || expression.op === "notIn") {
142
+ throw new Error(
143
+ `Operator "${expression.op}" requires a list of values in index WHERE clause`
144
+ );
145
+ }
146
+ const rightLiteral = compileIndexWhereLiteral(ctx.dialect, right);
147
+ const opSql = compileComparisonOperator(expression.op);
148
+ return drizzleOrm.sql`${left} ${opSql} ${rightLiteral}`;
149
+ }
150
+ }
151
+ }
152
+ function compileIndexWhereOperand(ctx, operand) {
153
+ if (operand.__type === "index_operand_system") {
154
+ return ctx.systemColumn(operand.column);
155
+ }
156
+ const adapter = chunkYM5AL65Y_cjs.getDialect(ctx.dialect);
157
+ const pointer = chunkP5CNM325_cjs.jsonPointer([operand.field]);
158
+ switch (operand.valueType) {
159
+ case "number": {
160
+ return adapter.jsonExtractNumber(ctx.propsColumn, pointer);
161
+ }
162
+ case "boolean": {
163
+ return adapter.jsonExtractBoolean(ctx.propsColumn, pointer);
164
+ }
165
+ case "date": {
166
+ return adapter.jsonExtractDate(ctx.propsColumn, pointer);
167
+ }
168
+ case "array":
169
+ case "object":
170
+ case "embedding": {
171
+ return adapter.jsonExtract(ctx.propsColumn, pointer);
172
+ }
173
+ case "string":
174
+ case "unknown":
175
+ case void 0: {
176
+ return adapter.jsonExtractText(ctx.propsColumn, pointer);
177
+ }
178
+ }
179
+ }
180
+ function compileIndexWhereLiteral(dialect, literal) {
181
+ switch (literal.valueType) {
182
+ case "string":
183
+ case "date": {
184
+ return drizzleOrm.sql.raw(escapeStringLiteral(literal.value.toString()));
185
+ }
186
+ case "number": {
187
+ return drizzleOrm.sql.raw(literal.value.toString());
188
+ }
189
+ case "boolean": {
190
+ return chunkYM5AL65Y_cjs.getDialect(dialect).booleanLiteral(literal.value);
191
+ }
192
+ case "array":
193
+ case "object":
194
+ case "embedding":
195
+ case "unknown": {
196
+ return drizzleOrm.sql.raw(escapeStringLiteral(literal.value.toString()));
197
+ }
198
+ }
199
+ }
200
+ function compileComparisonOperator(op) {
201
+ switch (op) {
202
+ case "eq": {
203
+ return drizzleOrm.sql`=`;
204
+ }
205
+ case "neq": {
206
+ return drizzleOrm.sql`<>`;
207
+ }
208
+ case "gt": {
209
+ return drizzleOrm.sql`>`;
210
+ }
211
+ case "gte": {
212
+ return drizzleOrm.sql`>=`;
213
+ }
214
+ case "lt": {
215
+ return drizzleOrm.sql`<`;
216
+ }
217
+ case "lte": {
218
+ return drizzleOrm.sql`<=`;
219
+ }
220
+ }
221
+ }
222
+ function escapeStringLiteral(value) {
223
+ return `'${value.replaceAll("'", "''")}'`;
224
+ }
225
+
226
+ // src/indexes/ddl.ts
227
+ function generateIndexDDL(index, dialect, options = {}) {
228
+ if (index.__type === "typegraph_node_index") {
229
+ return generateNodeIndexDDL(index, dialect, options);
230
+ }
231
+ return generateEdgeIndexDDL(index, dialect, options);
232
+ }
233
+ function generateNodeIndexDDL(index, dialect, options = {}) {
234
+ const tableName = options.nodesTableName ?? "typegraph_nodes";
235
+ return generateTableIndexDDL(index, dialect, tableName, options);
236
+ }
237
+ function generateEdgeIndexDDL(index, dialect, options = {}) {
238
+ const tableName = options.edgesTableName ?? "typegraph_edges";
239
+ return generateTableIndexDDL(index, dialect, tableName, options);
240
+ }
241
+ function generateTableIndexDDL(index, dialect, tableName, options) {
242
+ const ifNotExists = options.ifNotExists ?? true;
243
+ const propsColumn = drizzleOrm.sql.raw('"props"');
244
+ const systemColumn = (column) => drizzleOrm.sql.raw(quoteIdentifier(column));
245
+ const keys = index.__type === "typegraph_node_index" ? compileNodeIndexKeys(index, dialect, propsColumn, systemColumn).keys : compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn).keys;
246
+ const whereSql = index.where ? sqlToInlineString(
247
+ compileIndexWhere(
248
+ {
249
+ dialect,
250
+ propsColumn,
251
+ systemColumn
252
+ },
253
+ index.where
254
+ ),
255
+ dialect
256
+ ) : void 0;
257
+ const keySql = keys.map((k) => sqlToInlineString(k, dialect)).join(", ");
258
+ const unique = index.unique ? "UNIQUE " : "";
259
+ const ifNotExistsSql = ifNotExists ? "IF NOT EXISTS " : "";
260
+ const whereClause = whereSql ? ` WHERE ${whereSql}` : "";
261
+ return `CREATE ${unique}INDEX ${ifNotExistsSql}${quoteIdentifier(index.name)} ON ${quoteIdentifier(tableName)} (${keySql})${whereClause};`;
262
+ }
263
+ function quoteIdentifier(identifier) {
264
+ return `"${identifier.replaceAll('"', '""')}"`;
265
+ }
266
+ function sqlToInlineString(object, dialect) {
267
+ const query = object.toQuery({
268
+ casing: new casing.CasingCache(),
269
+ escapeName: (name) => name,
270
+ escapeParam: (_number, value) => inlineParam(value, dialect),
271
+ escapeString: (value) => escapeStringLiteral2(value),
272
+ inlineParams: true,
273
+ invokeSource: "indexes"
274
+ });
275
+ if (query.params.length > 0) {
276
+ throw new Error(
277
+ "Index DDL generation produced parameters; expected fully inlined SQL"
278
+ );
279
+ }
280
+ return query.sql;
281
+ }
282
+ function inlineParam(value, dialect) {
283
+ if (value === null || value === void 0) {
284
+ return "NULL";
285
+ }
286
+ if (value instanceof Date) {
287
+ return escapeStringLiteral2(value.toISOString());
288
+ }
289
+ if (typeof value === "string") {
290
+ return escapeStringLiteral2(value);
291
+ }
292
+ if (typeof value === "number") {
293
+ return value.toString();
294
+ }
295
+ if (typeof value === "boolean") {
296
+ return chunkYM5AL65Y_cjs.getDialect(dialect).booleanLiteralString(value);
297
+ }
298
+ if (typeof value === "bigint") {
299
+ return value.toString();
300
+ }
301
+ throw new TypeError(
302
+ "Index DDL generation received an unsupported SQL parameter value"
303
+ );
304
+ }
305
+ function escapeStringLiteral2(value) {
306
+ return `'${value.replaceAll("'", "''")}'`;
307
+ }
308
+
309
+ // src/indexes/define-index.ts
310
+ function defineNodeIndex(node, config) {
311
+ const scope = config.scope ?? "graphAndKind";
312
+ const unique = config.unique ?? false;
313
+ const schemaIntrospector = chunkP5CNM325_cjs.createSchemaIntrospector(
314
+ /* @__PURE__ */ new Map([[node.name, { schema: node.schema }]])
315
+ );
316
+ const { pointers: fields, valueTypes: fieldValueTypes } = normalizeNodeIndexFieldsOrThrow(
317
+ node,
318
+ config.fields,
319
+ schemaIntrospector,
320
+ "fields",
321
+ { allowEmpty: false }
322
+ );
323
+ const { pointers: coveringFields, valueTypes: coveringFieldValueTypes } = normalizeNodeIndexFieldsOrThrow(
324
+ node,
325
+ config.coveringFields ?? [],
326
+ schemaIntrospector,
327
+ "coveringFields",
328
+ { allowEmpty: true }
329
+ );
330
+ assertNoOverlap(fields, coveringFields, "fields", "coveringFields");
331
+ const where = normalizeWhereInput(
332
+ config.where,
333
+ () => createNodeWhereBuilder(node, schemaIntrospector)
334
+ );
335
+ const name = config.name ?? generateDefaultIndexName({
336
+ kind: "node",
337
+ kindName: node.name,
338
+ unique,
339
+ scope,
340
+ direction: "none",
341
+ fields,
342
+ coveringFields
343
+ });
344
+ return {
345
+ __type: "typegraph_node_index",
346
+ node,
347
+ nodeKind: node.name,
348
+ fields,
349
+ fieldValueTypes,
350
+ coveringFields,
351
+ coveringFieldValueTypes,
352
+ unique,
353
+ scope,
354
+ where,
355
+ name
356
+ };
357
+ }
358
+ function defineEdgeIndex(edge, config) {
359
+ const scope = config.scope ?? "graphAndKind";
360
+ const unique = config.unique ?? false;
361
+ const direction = config.direction ?? "none";
362
+ const schemaIntrospector = chunkP5CNM325_cjs.createSchemaIntrospector(
363
+ /* @__PURE__ */ new Map(),
364
+ /* @__PURE__ */ new Map([[edge.name, { schema: edge.schema }]])
365
+ );
366
+ const { pointers: fields, valueTypes: fieldValueTypes } = normalizeEdgeIndexFieldsOrThrow(
367
+ edge,
368
+ config.fields,
369
+ schemaIntrospector,
370
+ "fields",
371
+ { allowEmpty: false }
372
+ );
373
+ const { pointers: coveringFields, valueTypes: coveringFieldValueTypes } = normalizeEdgeIndexFieldsOrThrow(
374
+ edge,
375
+ config.coveringFields ?? [],
376
+ schemaIntrospector,
377
+ "coveringFields",
378
+ { allowEmpty: true }
379
+ );
380
+ assertNoOverlap(fields, coveringFields, "fields", "coveringFields");
381
+ const where = normalizeWhereInput(
382
+ config.where,
383
+ () => createEdgeWhereBuilder(edge, schemaIntrospector)
384
+ );
385
+ const name = config.name ?? generateDefaultIndexName({
386
+ kind: "edge",
387
+ kindName: edge.name,
388
+ unique,
389
+ scope,
390
+ direction,
391
+ fields,
392
+ coveringFields
393
+ });
394
+ return {
395
+ __type: "typegraph_edge_index",
396
+ edge,
397
+ edgeKind: edge.name,
398
+ fields,
399
+ fieldValueTypes,
400
+ coveringFields,
401
+ coveringFieldValueTypes,
402
+ unique,
403
+ scope,
404
+ direction,
405
+ where,
406
+ name
407
+ };
408
+ }
409
+ function normalizeWhereInput(input, createBuilder) {
410
+ if (input === void 0) {
411
+ return void 0;
412
+ }
413
+ if (typeof input === "function") {
414
+ return input(createBuilder());
415
+ }
416
+ return input;
417
+ }
418
+ function createNodeWhereBuilder(node, schemaIntrospector) {
419
+ const shape = getSchemaShape(node.schema);
420
+ const system = createSystemColumnMapForNode();
421
+ function getOperand(key) {
422
+ const systemColumn = system.get(key);
423
+ if (systemColumn) {
424
+ return {
425
+ __type: "index_operand_system",
426
+ column: systemColumn.column,
427
+ valueType: systemColumn.valueType
428
+ };
429
+ }
430
+ if (!(key in shape)) {
431
+ throw new Error(
432
+ `Unknown field "${key}" in node index WHERE clause for "${node.name}"`
433
+ );
434
+ }
435
+ const info = schemaIntrospector.getFieldTypeInfo(node.name, key);
436
+ const valueType = info?.valueType;
437
+ return {
438
+ __type: "index_operand_prop",
439
+ field: key,
440
+ valueType
441
+ };
442
+ }
443
+ return createWhereProxy((key) => getOperand(key));
444
+ }
445
+ function createEdgeWhereBuilder(edge, schemaIntrospector) {
446
+ const shape = getSchemaShape(edge.schema);
447
+ const system = createSystemColumnMapForEdge();
448
+ function getOperand(key) {
449
+ const systemColumn = system.get(key);
450
+ if (systemColumn) {
451
+ return {
452
+ __type: "index_operand_system",
453
+ column: systemColumn.column,
454
+ valueType: systemColumn.valueType
455
+ };
456
+ }
457
+ if (!(key in shape)) {
458
+ throw new Error(
459
+ `Unknown field "${key}" in edge index WHERE clause for "${edge.name}"`
460
+ );
461
+ }
462
+ const info = schemaIntrospector.getEdgeFieldTypeInfo(edge.name, key);
463
+ const valueType = info?.valueType;
464
+ return {
465
+ __type: "index_operand_prop",
466
+ field: key,
467
+ valueType
468
+ };
469
+ }
470
+ return createWhereProxy((key) => getOperand(key));
471
+ }
472
+ function createWhereProxy(getOperand) {
473
+ return new Proxy(/* @__PURE__ */ Object.create(null), {
474
+ get: (_target, property) => {
475
+ if (typeof property !== "string") return;
476
+ if (property === "then") return;
477
+ if (property === "toJSON") return;
478
+ const operand = getOperand(property);
479
+ return createIndexWhereFieldBuilder(operand);
480
+ }
481
+ });
482
+ }
483
+ function createIndexWhereFieldBuilder(operand) {
484
+ function isNull() {
485
+ return { __type: "index_where_null_check", operand, op: "isNull" };
486
+ }
487
+ function isNotNull() {
488
+ return { __type: "index_where_null_check", operand, op: "isNotNull" };
489
+ }
490
+ function comparison(op, value) {
491
+ return {
492
+ __type: "index_where_comparison",
493
+ left: operand,
494
+ op,
495
+ right: toLiteralOrThrow(value, operand.valueType)
496
+ };
497
+ }
498
+ function listComparison(op, values) {
499
+ const literals = values.map(
500
+ (value) => toLiteralOrThrow(value, operand.valueType)
501
+ );
502
+ return {
503
+ __type: "index_where_comparison",
504
+ left: operand,
505
+ op,
506
+ right: literals
507
+ };
508
+ }
509
+ return {
510
+ eq: (value) => comparison("eq", value),
511
+ neq: (value) => comparison("neq", value),
512
+ gt: (value) => comparison("gt", value),
513
+ gte: (value) => comparison("gte", value),
514
+ lt: (value) => comparison("lt", value),
515
+ lte: (value) => comparison("lte", value),
516
+ in: (values) => listComparison("in", values),
517
+ notIn: (values) => listComparison("notIn", values),
518
+ isNull,
519
+ isNotNull
520
+ };
521
+ }
522
+ function toLiteralOrThrow(value, preferredType) {
523
+ if (value instanceof Date) {
524
+ return {
525
+ __type: "index_where_literal",
526
+ value: value.toISOString(),
527
+ valueType: "date"
528
+ };
529
+ }
530
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
531
+ const valueType = inferValueType(value, preferredType);
532
+ return { __type: "index_where_literal", value, valueType };
533
+ }
534
+ throw new Error(
535
+ `Unsupported literal value type in index WHERE clause: ${String(value)}`
536
+ );
537
+ }
538
+ function inferValueType(value, preferredType) {
539
+ if (preferredType === "date" && typeof value === "string") {
540
+ return "date";
541
+ }
542
+ if (preferredType === "number" && typeof value === "string") {
543
+ return "number";
544
+ }
545
+ if (preferredType === "boolean" && typeof value === "string") {
546
+ return "boolean";
547
+ }
548
+ if (typeof value === "string") return "string";
549
+ if (typeof value === "number") return "number";
550
+ return "boolean";
551
+ }
552
+ function toSystemColumnName(metaKey) {
553
+ const snake = metaKey.replaceAll(/([A-Z])/g, "_$1").toLowerCase();
554
+ switch (snake) {
555
+ case "deleted_at":
556
+ case "valid_from":
557
+ case "valid_to":
558
+ case "created_at":
559
+ case "updated_at": {
560
+ return snake;
561
+ }
562
+ default: {
563
+ throw new Error(`Unsupported system meta key: ${metaKey}`);
564
+ }
565
+ }
566
+ }
567
+ function createSystemColumnMapForNode() {
568
+ const entries = [
569
+ ["graphId", { column: "graph_id", valueType: "string" }],
570
+ ["kind", { column: "kind", valueType: "string" }],
571
+ ["id", { column: "id", valueType: "string" }]
572
+ ];
573
+ for (const key of chunkYM5AL65Y_cjs.NODE_META_KEYS) {
574
+ if (key === "version") {
575
+ entries.push([key, { column: "version", valueType: "number" }]);
576
+ continue;
577
+ }
578
+ entries.push([key, { column: toSystemColumnName(key), valueType: "date" }]);
579
+ }
580
+ return new Map(entries);
581
+ }
582
+ function createSystemColumnMapForEdge() {
583
+ const entries = [
584
+ ["graphId", { column: "graph_id", valueType: "string" }],
585
+ ["kind", { column: "kind", valueType: "string" }],
586
+ ["id", { column: "id", valueType: "string" }],
587
+ ["fromKind", { column: "from_kind", valueType: "string" }],
588
+ ["fromId", { column: "from_id", valueType: "string" }],
589
+ ["toKind", { column: "to_kind", valueType: "string" }],
590
+ ["toId", { column: "to_id", valueType: "string" }]
591
+ ];
592
+ for (const key of chunkYM5AL65Y_cjs.EDGE_META_KEYS) {
593
+ entries.push([key, { column: toSystemColumnName(key), valueType: "date" }]);
594
+ }
595
+ return new Map(entries);
596
+ }
597
+ function getSchemaShape(schema) {
598
+ if (schema.type !== "object") {
599
+ throw new Error("Index definitions require an object schema");
600
+ }
601
+ const def = schema.def;
602
+ const shape = def.shape;
603
+ if (!shape) {
604
+ throw new Error("Index definitions require a resolvable object shape");
605
+ }
606
+ return shape;
607
+ }
608
+ function assertNonEmpty(values, label) {
609
+ if (values.length === 0) {
610
+ throw new Error(`Index ${label} must not be empty`);
611
+ }
612
+ }
613
+ function assertUnique(values, label) {
614
+ const set = /* @__PURE__ */ new Set();
615
+ for (const value of values) {
616
+ if (set.has(value)) {
617
+ throw new Error(`Index ${label} contains duplicate value: ${value}`);
618
+ }
619
+ set.add(value);
620
+ }
621
+ }
622
+ function assertNoOverlap(a, b, aLabel, bLabel) {
623
+ const set = new Set(a);
624
+ for (const value of b) {
625
+ if (set.has(value)) {
626
+ throw new Error(`Index ${bLabel} must not overlap ${aLabel}: ${value}`);
627
+ }
628
+ }
629
+ }
630
+ function assertIndexableValueType(valueType, context) {
631
+ if (valueType === "embedding") {
632
+ throw new Error(
633
+ `Cannot create props index for embedding field (${context}); use vector indexes on the embeddings table instead`
634
+ );
635
+ }
636
+ if (valueType === "array" || valueType === "object") {
637
+ throw new Error(
638
+ `Cannot create btree props index for ${valueType} field (${context}); use a GIN/JSON index strategy instead`
639
+ );
640
+ }
641
+ }
642
+ function normalizeNodeIndexFieldsOrThrow(node, inputs, schemaIntrospector, label, options) {
643
+ if (inputs.length === 0 && options.allowEmpty) {
644
+ return { pointers: [], valueTypes: [] };
645
+ }
646
+ assertNonEmpty(inputs, label);
647
+ const pointers = [];
648
+ const valueTypes = [];
649
+ for (const input of inputs) {
650
+ const pointer = normalizeIndexFieldPointer(input);
651
+ const info = resolveNodeFieldTypeInfoOrThrow(
652
+ node.name,
653
+ pointer,
654
+ schemaIntrospector
655
+ );
656
+ assertIndexableValueType(info.valueType, `node "${node.name}" ${pointer}`);
657
+ pointers.push(pointer);
658
+ valueTypes.push(info.valueType);
659
+ }
660
+ assertUnique(pointers, label);
661
+ return { pointers, valueTypes };
662
+ }
663
+ function normalizeEdgeIndexFieldsOrThrow(edge, inputs, schemaIntrospector, label, options) {
664
+ if (inputs.length === 0 && options.allowEmpty) {
665
+ return { pointers: [], valueTypes: [] };
666
+ }
667
+ assertNonEmpty(inputs, label);
668
+ const pointers = [];
669
+ const valueTypes = [];
670
+ for (const input of inputs) {
671
+ const pointer = normalizeIndexFieldPointer(input);
672
+ const info = resolveEdgeFieldTypeInfoOrThrow(
673
+ edge.name,
674
+ pointer,
675
+ schemaIntrospector
676
+ );
677
+ assertIndexableValueType(info.valueType, `edge "${edge.name}" ${pointer}`);
678
+ pointers.push(pointer);
679
+ valueTypes.push(info.valueType);
680
+ }
681
+ assertUnique(pointers, label);
682
+ return { pointers, valueTypes };
683
+ }
684
+ function normalizeIndexFieldPointer(input) {
685
+ if (Array.isArray(input)) {
686
+ if (input.length === 0) {
687
+ throw new Error("Index field JSON pointer must not be empty");
688
+ }
689
+ return chunkP5CNM325_cjs.jsonPointer(input);
690
+ }
691
+ if (typeof input === "string") {
692
+ if (input.startsWith("/")) {
693
+ const pointer = chunkP5CNM325_cjs.normalizeJsonPointer(
694
+ input
695
+ );
696
+ if (pointer === "") {
697
+ throw new Error("Index field JSON pointer must not be empty");
698
+ }
699
+ return pointer;
700
+ }
701
+ return chunkP5CNM325_cjs.jsonPointer([input]);
702
+ }
703
+ throw new Error(`Unsupported index field input: ${String(input)}`);
704
+ }
705
+ function resolveNodeFieldTypeInfoOrThrow(nodeKind, pointer, schemaIntrospector) {
706
+ const segments = chunkP5CNM325_cjs.parseJsonPointer(pointer);
707
+ const [first, ...rest] = segments;
708
+ if (!first) {
709
+ throw new Error("Index field JSON pointer must not be empty");
710
+ }
711
+ const rootInfo = schemaIntrospector.getFieldTypeInfo(nodeKind, first);
712
+ if (!rootInfo) {
713
+ throw new Error(
714
+ `Unknown field "${first}" for node "${nodeKind}" in index definition`
715
+ );
716
+ }
717
+ if (rest.length === 0) {
718
+ return rootInfo;
719
+ }
720
+ const resolved = chunkP5CNM325_cjs.resolveFieldTypeInfoAtJsonPointer(
721
+ rootInfo,
722
+ chunkP5CNM325_cjs.jsonPointer(rest)
723
+ );
724
+ if (!resolved) {
725
+ throw new Error(
726
+ `Unknown JSON pointer "${pointer}" for node "${nodeKind}" in index definition`
727
+ );
728
+ }
729
+ return resolved;
730
+ }
731
+ function resolveEdgeFieldTypeInfoOrThrow(edgeKind, pointer, schemaIntrospector) {
732
+ const segments = chunkP5CNM325_cjs.parseJsonPointer(pointer);
733
+ const [first, ...rest] = segments;
734
+ if (!first) {
735
+ throw new Error("Index field JSON pointer must not be empty");
736
+ }
737
+ const rootInfo = schemaIntrospector.getEdgeFieldTypeInfo(edgeKind, first);
738
+ if (!rootInfo) {
739
+ throw new Error(
740
+ `Unknown field "${first}" for edge "${edgeKind}" in index definition`
741
+ );
742
+ }
743
+ if (rest.length === 0) {
744
+ return rootInfo;
745
+ }
746
+ const resolved = chunkP5CNM325_cjs.resolveFieldTypeInfoAtJsonPointer(
747
+ rootInfo,
748
+ chunkP5CNM325_cjs.jsonPointer(rest)
749
+ );
750
+ if (!resolved) {
751
+ throw new Error(
752
+ `Unknown JSON pointer "${pointer}" for edge "${edgeKind}" in index definition`
753
+ );
754
+ }
755
+ return resolved;
756
+ }
757
+ function generateDefaultIndexName(parts) {
758
+ const hash = fnv1aBase36Hash(
759
+ JSON.stringify({
760
+ kind: parts.kind,
761
+ kindName: parts.kindName,
762
+ unique: parts.unique,
763
+ scope: parts.scope,
764
+ direction: parts.direction,
765
+ fields: parts.fields,
766
+ covering: parts.coveringFields
767
+ })
768
+ );
769
+ const nameParts = [
770
+ "idx",
771
+ "tg",
772
+ parts.kind,
773
+ sanitizeIdentifierComponent(parts.kindName),
774
+ sanitizeIdentifierComponent(parts.fields.join("_")),
775
+ parts.coveringFields.length > 0 ? `cov_${sanitizeIdentifierComponent(parts.coveringFields.join("_"))}` : void 0,
776
+ parts.direction === "none" ? void 0 : parts.direction,
777
+ parts.unique ? "uniq" : void 0,
778
+ parts.scope === "graphAndKind" ? void 0 : sanitizeIdentifierComponent(parts.scope),
779
+ hash
780
+ ].filter((part) => part !== void 0);
781
+ const joined = nameParts.join("_");
782
+ return joined.length <= 63 ? joined : `${joined.slice(0, 54)}_${hash}`;
783
+ }
784
+ function sanitizeIdentifierComponent(value) {
785
+ return value.toLowerCase().replaceAll(/[^a-z0-9_]+/g, "_").replaceAll(/^_+|_+$/g, "").slice(0, 20);
786
+ }
787
+ function fnv1aBase36Hash(input) {
788
+ let hash = 2166136261;
789
+ for (const character of input) {
790
+ const codePoint = character.codePointAt(0);
791
+ if (codePoint === void 0) {
792
+ continue;
793
+ }
794
+ hash ^= codePoint;
795
+ hash = Math.imul(hash, 16777619);
796
+ }
797
+ return (hash >>> 0).toString(36);
798
+ }
799
+ function buildPostgresNodeIndexBuilders(table, indexes) {
800
+ const nodeIndexes = indexes.filter(
801
+ (index) => index.__type === "typegraph_node_index"
802
+ );
803
+ return nodeIndexes.map((index) => {
804
+ const propsColumn = drizzleOrm.sql`${table.props}`;
805
+ const systemColumn = (column) => drizzleOrm.sql`${getPostgresNodeSystemColumn(table, column)}`;
806
+ const { keys } = compileNodeIndexKeys(
807
+ index,
808
+ "postgres",
809
+ propsColumn,
810
+ systemColumn
811
+ );
812
+ assertNonEmpty2(keys, `node index "${index.name}"`);
813
+ const base = index.unique ? pgCore.uniqueIndex(index.name) : pgCore.index(index.name);
814
+ const builder = base.on(...keys);
815
+ if (index.where) {
816
+ const ctx = {
817
+ dialect: "postgres",
818
+ propsColumn,
819
+ systemColumn
820
+ };
821
+ builder.where(compileIndexWhere(ctx, index.where));
822
+ }
823
+ return builder;
824
+ });
825
+ }
826
+ function buildPostgresEdgeIndexBuilders(table, indexes) {
827
+ const edgeIndexes = indexes.filter(
828
+ (index) => index.__type === "typegraph_edge_index"
829
+ );
830
+ return edgeIndexes.map((index) => {
831
+ const propsColumn = drizzleOrm.sql`${table.props}`;
832
+ const systemColumn = (column) => drizzleOrm.sql`${getPostgresEdgeSystemColumn(table, column)}`;
833
+ const { keys } = compileEdgeIndexKeys(
834
+ index,
835
+ "postgres",
836
+ propsColumn,
837
+ systemColumn
838
+ );
839
+ assertNonEmpty2(keys, `edge index "${index.name}"`);
840
+ const base = index.unique ? pgCore.uniqueIndex(index.name) : pgCore.index(index.name);
841
+ const builder = base.on(...keys);
842
+ if (index.where) {
843
+ const ctx = {
844
+ dialect: "postgres",
845
+ propsColumn,
846
+ systemColumn
847
+ };
848
+ builder.where(compileIndexWhere(ctx, index.where));
849
+ }
850
+ return builder;
851
+ });
852
+ }
853
+ function getPostgresNodeSystemColumn(table, column) {
854
+ switch (column) {
855
+ case "graph_id": {
856
+ return table.graphId;
857
+ }
858
+ case "kind": {
859
+ return table.kind;
860
+ }
861
+ case "id": {
862
+ return table.id;
863
+ }
864
+ case "from_kind":
865
+ case "from_id":
866
+ case "to_kind":
867
+ case "to_id": {
868
+ throw new Error(`Unsupported node system column for indexes: ${column}`);
869
+ }
870
+ case "deleted_at": {
871
+ return table.deletedAt;
872
+ }
873
+ case "valid_from": {
874
+ return table.validFrom;
875
+ }
876
+ case "valid_to": {
877
+ return table.validTo;
878
+ }
879
+ case "created_at": {
880
+ return table.createdAt;
881
+ }
882
+ case "updated_at": {
883
+ return table.updatedAt;
884
+ }
885
+ case "version": {
886
+ return table.version;
887
+ }
888
+ }
889
+ }
890
+ function getPostgresEdgeSystemColumn(table, column) {
891
+ switch (column) {
892
+ case "graph_id": {
893
+ return table.graphId;
894
+ }
895
+ case "kind": {
896
+ return table.kind;
897
+ }
898
+ case "id": {
899
+ return table.id;
900
+ }
901
+ case "from_kind": {
902
+ return table.fromKind;
903
+ }
904
+ case "from_id": {
905
+ return table.fromId;
906
+ }
907
+ case "to_kind": {
908
+ return table.toKind;
909
+ }
910
+ case "to_id": {
911
+ return table.toId;
912
+ }
913
+ case "deleted_at": {
914
+ return table.deletedAt;
915
+ }
916
+ case "valid_from": {
917
+ return table.validFrom;
918
+ }
919
+ case "valid_to": {
920
+ return table.validTo;
921
+ }
922
+ case "created_at": {
923
+ return table.createdAt;
924
+ }
925
+ case "updated_at": {
926
+ return table.updatedAt;
927
+ }
928
+ case "version": {
929
+ throw new Error(`Unsupported edge system column for indexes: ${column}`);
930
+ }
931
+ }
932
+ }
933
+ function buildSqliteNodeIndexBuilders(table, indexes) {
934
+ const nodeIndexes = indexes.filter(
935
+ (index) => index.__type === "typegraph_node_index"
936
+ );
937
+ return nodeIndexes.map((index) => {
938
+ const propsColumn = drizzleOrm.sql`${table.props}`;
939
+ const systemColumn = (column) => drizzleOrm.sql`${getSqliteNodeSystemColumn(table, column)}`;
940
+ const { keys } = compileNodeIndexKeys(
941
+ index,
942
+ "sqlite",
943
+ propsColumn,
944
+ systemColumn
945
+ );
946
+ assertNonEmpty2(keys, `node index "${index.name}"`);
947
+ const base = index.unique ? sqliteCore.uniqueIndex(index.name) : sqliteCore.index(index.name);
948
+ const builder = base.on(...keys);
949
+ if (index.where) {
950
+ const ctx = {
951
+ dialect: "sqlite",
952
+ propsColumn,
953
+ systemColumn
954
+ };
955
+ builder.where(compileIndexWhere(ctx, index.where));
956
+ }
957
+ return builder;
958
+ });
959
+ }
960
+ function buildSqliteEdgeIndexBuilders(table, indexes) {
961
+ const edgeIndexes = indexes.filter(
962
+ (index) => index.__type === "typegraph_edge_index"
963
+ );
964
+ return edgeIndexes.map((index) => {
965
+ const propsColumn = drizzleOrm.sql`${table.props}`;
966
+ const systemColumn = (column) => drizzleOrm.sql`${getSqliteEdgeSystemColumn(table, column)}`;
967
+ const { keys } = compileEdgeIndexKeys(
968
+ index,
969
+ "sqlite",
970
+ propsColumn,
971
+ systemColumn
972
+ );
973
+ assertNonEmpty2(keys, `edge index "${index.name}"`);
974
+ const base = index.unique ? sqliteCore.uniqueIndex(index.name) : sqliteCore.index(index.name);
975
+ const builder = base.on(...keys);
976
+ if (index.where) {
977
+ const ctx = {
978
+ dialect: "sqlite",
979
+ propsColumn,
980
+ systemColumn
981
+ };
982
+ builder.where(compileIndexWhere(ctx, index.where));
983
+ }
984
+ return builder;
985
+ });
986
+ }
987
+ function getSqliteNodeSystemColumn(table, column) {
988
+ switch (column) {
989
+ case "graph_id": {
990
+ return table.graphId;
991
+ }
992
+ case "kind": {
993
+ return table.kind;
994
+ }
995
+ case "id": {
996
+ return table.id;
997
+ }
998
+ case "from_kind":
999
+ case "from_id":
1000
+ case "to_kind":
1001
+ case "to_id": {
1002
+ throw new Error(`Unsupported node system column for indexes: ${column}`);
1003
+ }
1004
+ case "deleted_at": {
1005
+ return table.deletedAt;
1006
+ }
1007
+ case "valid_from": {
1008
+ return table.validFrom;
1009
+ }
1010
+ case "valid_to": {
1011
+ return table.validTo;
1012
+ }
1013
+ case "created_at": {
1014
+ return table.createdAt;
1015
+ }
1016
+ case "updated_at": {
1017
+ return table.updatedAt;
1018
+ }
1019
+ case "version": {
1020
+ return table.version;
1021
+ }
1022
+ }
1023
+ }
1024
+ function getSqliteEdgeSystemColumn(table, column) {
1025
+ switch (column) {
1026
+ case "graph_id": {
1027
+ return table.graphId;
1028
+ }
1029
+ case "kind": {
1030
+ return table.kind;
1031
+ }
1032
+ case "id": {
1033
+ return table.id;
1034
+ }
1035
+ case "from_kind": {
1036
+ return table.fromKind;
1037
+ }
1038
+ case "from_id": {
1039
+ return table.fromId;
1040
+ }
1041
+ case "to_kind": {
1042
+ return table.toKind;
1043
+ }
1044
+ case "to_id": {
1045
+ return table.toId;
1046
+ }
1047
+ case "deleted_at": {
1048
+ return table.deletedAt;
1049
+ }
1050
+ case "valid_from": {
1051
+ return table.validFrom;
1052
+ }
1053
+ case "valid_to": {
1054
+ return table.validTo;
1055
+ }
1056
+ case "created_at": {
1057
+ return table.createdAt;
1058
+ }
1059
+ case "updated_at": {
1060
+ return table.updatedAt;
1061
+ }
1062
+ case "version": {
1063
+ throw new Error(`Unsupported edge system column for indexes: ${column}`);
1064
+ }
1065
+ }
1066
+ }
1067
+ function assertNonEmpty2(values, label) {
1068
+ if (values.length === 0) {
1069
+ throw new Error(`Index must have at least one key (${label})`);
1070
+ }
1071
+ }
1072
+
1073
+ // src/indexes/profiler.ts
1074
+ function toDeclaredIndex(index) {
1075
+ if (index.__type === "typegraph_node_index") {
1076
+ return toDeclaredNodeIndex(index);
1077
+ }
1078
+ return toDeclaredEdgeIndex(index);
1079
+ }
1080
+ function toDeclaredIndexes(indexes) {
1081
+ return indexes.map((index) => toDeclaredIndex(index));
1082
+ }
1083
+ function toDeclaredNodeIndex(index) {
1084
+ return {
1085
+ entityType: "node",
1086
+ kind: index.nodeKind,
1087
+ fields: [...index.fields],
1088
+ unique: index.unique,
1089
+ name: index.name
1090
+ };
1091
+ }
1092
+ function toDeclaredEdgeIndex(index) {
1093
+ return {
1094
+ entityType: "edge",
1095
+ kind: index.edgeKind,
1096
+ fields: [...index.fields],
1097
+ unique: index.unique,
1098
+ name: index.name
1099
+ };
1100
+ }
1101
+
1102
+ // src/indexes/where.ts
1103
+ function andWhere(...predicates) {
1104
+ if (predicates.length === 1) {
1105
+ return predicates[0];
1106
+ }
1107
+ return {
1108
+ __type: "index_where_and",
1109
+ predicates
1110
+ };
1111
+ }
1112
+ function orWhere(...predicates) {
1113
+ if (predicates.length === 1) {
1114
+ return predicates[0];
1115
+ }
1116
+ return {
1117
+ __type: "index_where_or",
1118
+ predicates
1119
+ };
1120
+ }
1121
+ function notWhere(predicate) {
1122
+ return {
1123
+ __type: "index_where_not",
1124
+ predicate
1125
+ };
1126
+ }
1127
+
1128
+ exports.andWhere = andWhere;
1129
+ exports.buildPostgresEdgeIndexBuilders = buildPostgresEdgeIndexBuilders;
1130
+ exports.buildPostgresNodeIndexBuilders = buildPostgresNodeIndexBuilders;
1131
+ exports.buildSqliteEdgeIndexBuilders = buildSqliteEdgeIndexBuilders;
1132
+ exports.buildSqliteNodeIndexBuilders = buildSqliteNodeIndexBuilders;
1133
+ exports.defineEdgeIndex = defineEdgeIndex;
1134
+ exports.defineNodeIndex = defineNodeIndex;
1135
+ exports.generateEdgeIndexDDL = generateEdgeIndexDDL;
1136
+ exports.generateIndexDDL = generateIndexDDL;
1137
+ exports.generateNodeIndexDDL = generateNodeIndexDDL;
1138
+ exports.notWhere = notWhere;
1139
+ exports.orWhere = orWhere;
1140
+ exports.toDeclaredIndex = toDeclaredIndex;
1141
+ exports.toDeclaredIndexes = toDeclaredIndexes;
1142
+ //# sourceMappingURL=chunk-DDM2FZRJ.cjs.map
1143
+ //# sourceMappingURL=chunk-DDM2FZRJ.cjs.map