@nicia-ai/typegraph 0.29.0 → 0.31.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 (205) hide show
  1. package/README.md +39 -0
  2. package/dist/backend/postgres/index.cjs +21 -20
  3. package/dist/backend/postgres/index.d.cts +6 -6
  4. package/dist/backend/postgres/index.d.ts +6 -6
  5. package/dist/backend/postgres/index.js +11 -10
  6. package/dist/backend/postgres/pglite.cjs +16 -15
  7. package/dist/backend/postgres/pglite.cjs.map +1 -1
  8. package/dist/backend/postgres/pglite.d.cts +3 -3
  9. package/dist/backend/postgres/pglite.d.ts +3 -3
  10. package/dist/backend/postgres/pglite.js +11 -10
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +18 -18
  13. package/dist/backend/sqlite/index.d.cts +12 -7
  14. package/dist/backend/sqlite/index.d.ts +12 -7
  15. package/dist/backend/sqlite/index.js +9 -9
  16. package/dist/backend/sqlite/libsql.cjs +14 -14
  17. package/dist/backend/sqlite/libsql.d.cts +3 -3
  18. package/dist/backend/sqlite/libsql.d.ts +3 -3
  19. package/dist/backend/sqlite/libsql.js +10 -10
  20. package/dist/backend/sqlite/local.cjs +17 -16
  21. package/dist/backend/sqlite/local.cjs.map +1 -1
  22. package/dist/backend/sqlite/local.d.cts +9 -3
  23. package/dist/backend/sqlite/local.d.ts +9 -3
  24. package/dist/backend/sqlite/local.js +12 -11
  25. package/dist/backend/sqlite/local.js.map +1 -1
  26. package/dist/{chunk-7KLVFWXR.js → chunk-2HZGWCB4.js} +121 -497
  27. package/dist/chunk-2HZGWCB4.js.map +1 -0
  28. package/dist/chunk-2YMGNYXY.js +40 -0
  29. package/dist/chunk-2YMGNYXY.js.map +1 -0
  30. package/dist/chunk-2ZY4K43M.js +90 -0
  31. package/dist/chunk-2ZY4K43M.js.map +1 -0
  32. package/dist/chunk-3EUKJEQ3.js +77 -0
  33. package/dist/chunk-3EUKJEQ3.js.map +1 -0
  34. package/dist/chunk-3JBJEYWE.cjs +604 -0
  35. package/dist/chunk-3JBJEYWE.cjs.map +1 -0
  36. package/dist/{chunk-A4H6QMV4.js → chunk-4A4GUZTQ.js} +15 -11
  37. package/dist/chunk-4A4GUZTQ.js.map +1 -0
  38. package/dist/{chunk-F2Q76CQ4.cjs → chunk-54JVNOAQ.cjs} +5 -37
  39. package/dist/chunk-54JVNOAQ.cjs.map +1 -0
  40. package/dist/{chunk-KGAJ5HFO.cjs → chunk-5CN7B4CZ.cjs} +17 -98
  41. package/dist/chunk-5CN7B4CZ.cjs.map +1 -0
  42. package/dist/{chunk-XTQHSOIC.cjs → chunk-5DTPBFX5.cjs} +88 -87
  43. package/dist/chunk-5DTPBFX5.cjs.map +1 -0
  44. package/dist/chunk-6G35I3VW.cjs +40 -0
  45. package/dist/chunk-6G35I3VW.cjs.map +1 -0
  46. package/dist/{chunk-UPBXUOW7.cjs → chunk-6RMLO5O4.cjs} +19 -64
  47. package/dist/chunk-6RMLO5O4.cjs.map +1 -0
  48. package/dist/chunk-6SA7UIQJ.cjs +94 -0
  49. package/dist/chunk-6SA7UIQJ.cjs.map +1 -0
  50. package/dist/chunk-6ZR4QC3O.cjs +12 -0
  51. package/dist/{chunk-Q3ZZLU3O.cjs.map → chunk-6ZR4QC3O.cjs.map} +1 -1
  52. package/dist/chunk-73KASJGO.cjs +52 -0
  53. package/dist/chunk-73KASJGO.cjs.map +1 -0
  54. package/dist/{chunk-R2LA6MKR.cjs → chunk-7JGLPAFV.cjs} +8 -8
  55. package/dist/{chunk-R2LA6MKR.cjs.map → chunk-7JGLPAFV.cjs.map} +1 -1
  56. package/dist/chunk-A3W7QG7K.js +45 -0
  57. package/dist/chunk-A3W7QG7K.js.map +1 -0
  58. package/dist/{chunk-Q5ASTPM4.cjs → chunk-ASYQDPPU.cjs} +19 -19
  59. package/dist/{chunk-Q5ASTPM4.cjs.map → chunk-ASYQDPPU.cjs.map} +1 -1
  60. package/dist/{chunk-IE2TPFBT.js → chunk-ATTXBMAX.js} +4 -74
  61. package/dist/chunk-ATTXBMAX.js.map +1 -0
  62. package/dist/chunk-AW4A3P5A.cjs +51 -0
  63. package/dist/chunk-AW4A3P5A.cjs.map +1 -0
  64. package/dist/{chunk-ZYQEXGYC.cjs → chunk-CIINW6PS.cjs} +92 -87
  65. package/dist/chunk-CIINW6PS.cjs.map +1 -0
  66. package/dist/{chunk-UP4QAJND.cjs → chunk-FLOI7QOT.cjs} +66 -65
  67. package/dist/chunk-FLOI7QOT.cjs.map +1 -0
  68. package/dist/{chunk-7V335GHG.cjs → chunk-FLRCVI2G.cjs} +12 -2
  69. package/dist/chunk-FLRCVI2G.cjs.map +1 -0
  70. package/dist/{chunk-HKN622O4.js → chunk-GKFWM3DS.js} +4 -32
  71. package/dist/chunk-GKFWM3DS.js.map +1 -0
  72. package/dist/chunk-HTGDWIDE.cjs +89 -0
  73. package/dist/chunk-HTGDWIDE.cjs.map +1 -0
  74. package/dist/{chunk-OGUH56BB.js → chunk-IJORSAC3.js} +6 -42
  75. package/dist/chunk-IJORSAC3.js.map +1 -0
  76. package/dist/{chunk-G6P3OVDY.cjs → chunk-JIEJCTDS.cjs} +18 -2
  77. package/dist/chunk-JIEJCTDS.cjs.map +1 -0
  78. package/dist/{chunk-NZ5PMBTG.js → chunk-K5P5OZXS.js} +12 -3
  79. package/dist/chunk-K5P5OZXS.js.map +1 -0
  80. package/dist/{chunk-HM6XMR3E.cjs → chunk-KTIEB7VH.cjs} +42 -32
  81. package/dist/chunk-KTIEB7VH.cjs.map +1 -0
  82. package/dist/chunk-LJLMDDCW.js +282 -0
  83. package/dist/chunk-LJLMDDCW.js.map +1 -0
  84. package/dist/{chunk-Z36W5WUM.js → chunk-MAQJYNJR.js} +3 -3
  85. package/dist/{chunk-Z36W5WUM.js.map → chunk-MAQJYNJR.js.map} +1 -1
  86. package/dist/{chunk-N3VVQDMA.js → chunk-MXE2U3EX.js} +3 -3
  87. package/dist/{chunk-N3VVQDMA.js.map → chunk-MXE2U3EX.js.map} +1 -1
  88. package/dist/{chunk-4K6IHUW6.cjs → chunk-N2MBPTAF.cjs} +14 -14
  89. package/dist/{chunk-4K6IHUW6.cjs.map → chunk-N2MBPTAF.cjs.map} +1 -1
  90. package/dist/{chunk-CUZGBWFT.js → chunk-O4VUR6SI.js} +3 -3
  91. package/dist/{chunk-CUZGBWFT.js.map → chunk-O4VUR6SI.js.map} +1 -1
  92. package/dist/chunk-RZ4DH4E7.cjs +15832 -0
  93. package/dist/chunk-RZ4DH4E7.cjs.map +1 -0
  94. package/dist/chunk-SAJSMR2B.js +35 -0
  95. package/dist/chunk-SAJSMR2B.js.map +1 -0
  96. package/dist/{chunk-RU5BBUU2.cjs → chunk-SFFJ2IKN.cjs} +71 -67
  97. package/dist/chunk-SFFJ2IKN.cjs.map +1 -0
  98. package/dist/{chunk-Y52UNT66.js → chunk-STP7QVUB.js} +8 -7
  99. package/dist/chunk-STP7QVUB.js.map +1 -0
  100. package/dist/chunk-THX25XW6.js +590 -0
  101. package/dist/chunk-THX25XW6.js.map +1 -0
  102. package/dist/{chunk-MB363HT5.js → chunk-TQOYM4LN.js} +18 -3
  103. package/dist/chunk-TQOYM4LN.js.map +1 -0
  104. package/dist/chunk-UIFEEPME.js +15787 -0
  105. package/dist/chunk-UIFEEPME.js.map +1 -0
  106. package/dist/{chunk-GPUNAJFH.js → chunk-UJ4V3YUQ.js} +3 -3
  107. package/dist/{chunk-GPUNAJFH.js.map → chunk-UJ4V3YUQ.js.map} +1 -1
  108. package/dist/{chunk-C2RWFIYP.cjs → chunk-V4IQYOQ4.cjs} +127 -511
  109. package/dist/chunk-V4IQYOQ4.cjs.map +1 -0
  110. package/dist/chunk-VMEWZU2N.cjs +287 -0
  111. package/dist/chunk-VMEWZU2N.cjs.map +1 -0
  112. package/dist/{chunk-3DTLDGIM.js → chunk-VZX2KSY3.js} +14 -9
  113. package/dist/chunk-VZX2KSY3.js.map +1 -0
  114. package/dist/{chunk-BMDF2S7S.js → chunk-WYTUF3QO.js} +3 -3
  115. package/dist/{chunk-BMDF2S7S.js.map → chunk-WYTUF3QO.js.map} +1 -1
  116. package/dist/{chunk-MRMD7S7E.js → chunk-XKJQQQVR.js} +9 -8
  117. package/dist/chunk-XKJQQQVR.js.map +1 -0
  118. package/dist/{chunk-SFNUHFON.js → chunk-YCV72E6L.js} +25 -19
  119. package/dist/chunk-YCV72E6L.js.map +1 -0
  120. package/dist/{chunk-VGU26WIU.cjs → chunk-YQGLVWB2.cjs} +4 -4
  121. package/dist/{chunk-VGU26WIU.cjs.map → chunk-YQGLVWB2.cjs.map} +1 -1
  122. package/dist/{ddl-BwH00BB6.d.ts → ddl-BJcPrB4L.d.ts} +3 -3
  123. package/dist/{ddl-D3o-RmsV.d.cts → ddl-CPZ7mB7X.d.cts} +3 -3
  124. package/dist/{extension-types-CwHV-Uk4.d.ts → extension-types-D1k0inWU.d.cts} +1 -1
  125. package/dist/{extension-types-CwHV-Uk4.d.cts → extension-types-D1k0inWU.d.ts} +1 -1
  126. package/dist/graph-extension/index.cjs +19 -19
  127. package/dist/graph-extension/index.d.cts +5 -16
  128. package/dist/graph-extension/index.d.ts +5 -16
  129. package/dist/graph-extension/index.js +4 -4
  130. package/dist/graph-merge/index.cjs +3822 -0
  131. package/dist/graph-merge/index.cjs.map +1 -0
  132. package/dist/graph-merge/index.d.cts +1191 -0
  133. package/dist/graph-merge/index.d.ts +1191 -0
  134. package/dist/graph-merge/index.js +3791 -0
  135. package/dist/graph-merge/index.js.map +1 -0
  136. package/dist/{index-CapHwi1a.d.ts → index-BEK0VtNB.d.ts} +11 -3
  137. package/dist/{index-jPPexxM5.d.cts → index-C8sSTErx.d.cts} +11 -3
  138. package/dist/index.cjs +365 -15732
  139. package/dist/index.cjs.map +1 -1
  140. package/dist/index.d.cts +12 -11
  141. package/dist/index.d.ts +12 -11
  142. package/dist/index.js +27 -15533
  143. package/dist/index.js.map +1 -1
  144. package/dist/indexes/index.cjs +32 -28
  145. package/dist/indexes/index.d.cts +5 -5
  146. package/dist/indexes/index.d.ts +5 -5
  147. package/dist/indexes/index.js +8 -4
  148. package/dist/interchange/index.cjs +50 -593
  149. package/dist/interchange/index.cjs.map +1 -1
  150. package/dist/interchange/index.d.cts +5 -5
  151. package/dist/interchange/index.d.ts +5 -5
  152. package/dist/interchange/index.js +3 -589
  153. package/dist/interchange/index.js.map +1 -1
  154. package/dist/{manager-BUugwCYz.d.ts → manager-By-WEd8M.d.ts} +3 -3
  155. package/dist/{manager-DpIpn1HQ.d.cts → manager-Np7VVSlE.d.cts} +3 -3
  156. package/dist/{materialize-indexes-lkawaDor.d.ts → materialize-indexes-CAGhqPHQ.d.ts} +1 -1
  157. package/dist/{materialize-indexes-oanE3RU0.d.cts → materialize-indexes-DEYkU-wr.d.cts} +1 -1
  158. package/dist/{postgres-CQL9UIn2.d.cts → postgres-4J2tmauh.d.cts} +1 -1
  159. package/dist/{postgres-CcRLaxz0.d.ts → postgres-BdIb7tS_.d.ts} +1 -1
  160. package/dist/profiler/index.cjs +9 -9
  161. package/dist/profiler/index.d.cts +7 -7
  162. package/dist/profiler/index.d.ts +7 -7
  163. package/dist/profiler/index.js +2 -2
  164. package/dist/result-DWo6mUVz.d.cts +37 -0
  165. package/dist/result-DWo6mUVz.d.ts +37 -0
  166. package/dist/schema/index.cjs +33 -32
  167. package/dist/schema/index.cjs.map +1 -1
  168. package/dist/schema/index.d.cts +7 -7
  169. package/dist/schema/index.d.ts +7 -7
  170. package/dist/schema/index.js +10 -9
  171. package/dist/schema/index.js.map +1 -1
  172. package/dist/{sqlite-Rj3xu4It.d.cts → sqlite-Gatk_iw_.d.cts} +1 -1
  173. package/dist/{sqlite-CZDFUfHS.d.ts → sqlite-aM_PAz-O.d.ts} +1 -1
  174. package/dist/{store-B43FpOVX.d.cts → store-DuCbdqsh.d.cts} +84 -44
  175. package/dist/{store-De0Y33wP.d.ts → store-MloRPwb9.d.ts} +84 -44
  176. package/dist/{types-DXCSyxac.d.cts → types-BKQljXom.d.ts} +18 -2
  177. package/dist/{types-CmAT-Z47.d.ts → types-C1CYxWrL.d.cts} +18 -2
  178. package/dist/{types-Bwlp_yvu.d.cts → types-DoByHGyU.d.cts} +2 -2
  179. package/dist/{types-B5GSeE3t.d.ts → types-K3vpaJAL.d.ts} +2 -2
  180. package/dist/{where-CP4qGIHd.d.ts → where-Dt49bvo6.d.ts} +2 -2
  181. package/dist/{where-2dsyYt3d.d.cts → where-DydZjGOb.d.cts} +2 -2
  182. package/package.json +6 -1
  183. package/dist/chunk-3DTLDGIM.js.map +0 -1
  184. package/dist/chunk-7KLVFWXR.js.map +0 -1
  185. package/dist/chunk-7V335GHG.cjs.map +0 -1
  186. package/dist/chunk-A4H6QMV4.js.map +0 -1
  187. package/dist/chunk-C2RWFIYP.cjs.map +0 -1
  188. package/dist/chunk-F2Q76CQ4.cjs.map +0 -1
  189. package/dist/chunk-G6P3OVDY.cjs.map +0 -1
  190. package/dist/chunk-HKN622O4.js.map +0 -1
  191. package/dist/chunk-HM6XMR3E.cjs.map +0 -1
  192. package/dist/chunk-IE2TPFBT.js.map +0 -1
  193. package/dist/chunk-KGAJ5HFO.cjs.map +0 -1
  194. package/dist/chunk-MB363HT5.js.map +0 -1
  195. package/dist/chunk-MRMD7S7E.js.map +0 -1
  196. package/dist/chunk-NZ5PMBTG.js.map +0 -1
  197. package/dist/chunk-OGUH56BB.js.map +0 -1
  198. package/dist/chunk-Q3ZZLU3O.cjs +0 -12
  199. package/dist/chunk-RU5BBUU2.cjs.map +0 -1
  200. package/dist/chunk-SFNUHFON.js.map +0 -1
  201. package/dist/chunk-UP4QAJND.cjs.map +0 -1
  202. package/dist/chunk-UPBXUOW7.cjs.map +0 -1
  203. package/dist/chunk-XTQHSOIC.cjs.map +0 -1
  204. package/dist/chunk-Y52UNT66.js.map +0 -1
  205. package/dist/chunk-ZYQEXGYC.cjs.map +0 -1
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk7V335GHG_cjs = require('./chunk-7V335GHG.cjs');
3
+ var chunkFLRCVI2G_cjs = require('./chunk-FLRCVI2G.cjs');
4
4
  var drizzleOrm = require('drizzle-orm');
5
- var casing = require('drizzle-orm/casing');
6
- var pgCore = require('drizzle-orm/pg-core');
7
- var sqliteCore = require('drizzle-orm/sqlite-core');
8
5
 
9
6
  function sqlNull(value) {
10
7
  return value ?? drizzleOrm.sql.raw("NULL");
@@ -384,6 +381,97 @@ var fts5Strategy = {
384
381
  return stmt === void 0 ? [] : [stmt];
385
382
  }
386
383
  };
384
+ var VECTOR_CONTRIBUTION_PREFIX = "vector";
385
+ function buildVectorCapabilities(strategy) {
386
+ return strategy.capabilities;
387
+ }
388
+ function vectorScoreExpression(distanceExpression, metric) {
389
+ switch (metric) {
390
+ case "cosine": {
391
+ return drizzleOrm.sql`(1 - (${distanceExpression}))`;
392
+ }
393
+ case "l2":
394
+ case "inner_product": {
395
+ return distanceExpression;
396
+ }
397
+ default: {
398
+ const _exhaustive = metric;
399
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
400
+ }
401
+ }
402
+ }
403
+ function vectorMinScoreCondition(distanceExpression, metric, minScore) {
404
+ assertVectorMinScore(minScore, metric);
405
+ switch (metric) {
406
+ case "cosine": {
407
+ return drizzleOrm.sql`${distanceExpression} <= ${1 - minScore}`;
408
+ }
409
+ case "l2": {
410
+ return drizzleOrm.sql`${distanceExpression} <= ${minScore}`;
411
+ }
412
+ case "inner_product": {
413
+ return drizzleOrm.sql`${distanceExpression} <= ${-minScore}`;
414
+ }
415
+ default: {
416
+ const _exhaustive = metric;
417
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
418
+ }
419
+ }
420
+ }
421
+ function assertFiniteEmbedding(embedding, name) {
422
+ for (const [index, value] of embedding.entries()) {
423
+ if (typeof value !== "number" || !Number.isFinite(value)) {
424
+ throw new TypeError(
425
+ `${name}[${index}] must be a finite number, got: ${value}`
426
+ );
427
+ }
428
+ }
429
+ }
430
+ function assertVectorSearchLimit(limit) {
431
+ if (!Number.isInteger(limit) || limit <= 0) {
432
+ throw new RangeError(
433
+ `vectorSearch limit must be a positive integer, got: ${limit}`
434
+ );
435
+ }
436
+ }
437
+ function assertVectorMinScore(minScore, metric, label = "minScore") {
438
+ if (!Number.isFinite(minScore)) {
439
+ throw new RangeError(`${label} must be a finite number, got: ${minScore}`);
440
+ }
441
+ if (metric === "cosine" && (minScore < -1 || minScore > 1)) {
442
+ throw new RangeError(
443
+ `${label} for the cosine metric must be between -1 and 1, got: ${minScore}`
444
+ );
445
+ }
446
+ }
447
+ var MAX_VECTOR_IDENTIFIER_LENGTH = 63;
448
+ function sanitizeIdentifierPart(value) {
449
+ return value.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
450
+ }
451
+ function shortHash(input) {
452
+ let h1 = 3735928559;
453
+ let h2 = 1103547991;
454
+ for (let index = 0; index < input.length; index++) {
455
+ const ch = input.codePointAt(index);
456
+ h1 = Math.imul(h1 ^ ch, 2654435761);
457
+ h2 = Math.imul(h2 ^ ch, 1597334677);
458
+ }
459
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
460
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
461
+ const hi = (h2 >>> 0).toString(16).padStart(8, "0");
462
+ const lo = (h1 >>> 0).toString(16).padStart(8, "0");
463
+ return `${hi}${lo}`.slice(0, 8);
464
+ }
465
+ function vectorPhysicalName(prefix, graphId, nodeKind, fieldPath) {
466
+ const readable = `${prefix}_${sanitizeIdentifierPart(graphId)}_${sanitizeIdentifierPart(nodeKind)}_${sanitizeIdentifierPart(fieldPath)}`;
467
+ const hash = shortHash(JSON.stringify([graphId, nodeKind, fieldPath]));
468
+ const full = `${readable}_${hash}`;
469
+ if (full.length <= MAX_VECTOR_IDENTIFIER_LENGTH) return full;
470
+ return `${readable.slice(0, MAX_VECTOR_IDENTIFIER_LENGTH - 1 - hash.length)}_${hash}`;
471
+ }
472
+ function quoteIdentifier2(name) {
473
+ return `"${name.replaceAll('"', '""')}"`;
474
+ }
387
475
  function escapePostgresLiteral(value) {
388
476
  return `'${value.replaceAll("'", "''")}'`;
389
477
  }
@@ -391,7 +479,7 @@ function toPostgresPath(pointer) {
391
479
  if (!pointer || pointer === "" || pointer === "/") {
392
480
  return drizzleOrm.sql.raw("ARRAY[]::text[]");
393
481
  }
394
- const segments = chunk7V335GHG_cjs.parseJsonPointer(pointer);
482
+ const segments = chunkFLRCVI2G_cjs.parseJsonPointer(pointer);
395
483
  if (segments.length === 0) {
396
484
  return drizzleOrm.sql.raw("ARRAY[]::text[]");
397
485
  }
@@ -479,6 +567,12 @@ var postgresDialect = {
479
567
  return drizzleOrm.sql`(${column} #> ${path} IS NOT NULL AND ${column} #>> ${path} != 'null')`;
480
568
  },
481
569
  // ============================================================
570
+ // Comparison Operations
571
+ // ============================================================
572
+ nullSafeEquals(left, right) {
573
+ return drizzleOrm.sql`${left} IS NOT DISTINCT FROM ${right}`;
574
+ },
575
+ // ============================================================
482
576
  // String Operations
483
577
  // ============================================================
484
578
  ilike(column, pattern) {
@@ -541,7 +635,7 @@ function toSqlitePath(pointer) {
541
635
  if (!pointer || pointer === "" || pointer === "/") {
542
636
  return "$";
543
637
  }
544
- const segments = chunk7V335GHG_cjs.parseJsonPointer(pointer);
638
+ const segments = chunkFLRCVI2G_cjs.parseJsonPointer(pointer);
545
639
  const parts = ["$"];
546
640
  for (const segment of segments) {
547
641
  if (isArrayIndex(segment)) {
@@ -638,6 +732,12 @@ var sqliteDialect = {
638
732
  return drizzleOrm.sql`(json_extract(${column}, ${pathSql}) IS NOT NULL AND json_type(${column}, ${pathSql}) != 'null')`;
639
733
  },
640
734
  // ============================================================
735
+ // Comparison Operations
736
+ // ============================================================
737
+ nullSafeEquals(left, right) {
738
+ return drizzleOrm.sql`${left} IS ${right}`;
739
+ },
740
+ // ============================================================
641
741
  // String Operations
642
742
  // ============================================================
643
743
  ilike(column, pattern) {
@@ -696,97 +796,6 @@ var sqliteDialect = {
696
796
  // ============================================================
697
797
  fulltext: fts5Strategy
698
798
  };
699
- var VECTOR_CONTRIBUTION_PREFIX = "vector";
700
- function buildVectorCapabilities(strategy) {
701
- return strategy.capabilities;
702
- }
703
- function vectorScoreExpression(distanceExpression, metric) {
704
- switch (metric) {
705
- case "cosine": {
706
- return drizzleOrm.sql`(1 - (${distanceExpression}))`;
707
- }
708
- case "l2":
709
- case "inner_product": {
710
- return distanceExpression;
711
- }
712
- default: {
713
- const _exhaustive = metric;
714
- throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
715
- }
716
- }
717
- }
718
- function vectorMinScoreCondition(distanceExpression, metric, minScore) {
719
- assertVectorMinScore(minScore, metric);
720
- switch (metric) {
721
- case "cosine": {
722
- return drizzleOrm.sql`${distanceExpression} <= ${1 - minScore}`;
723
- }
724
- case "l2": {
725
- return drizzleOrm.sql`${distanceExpression} <= ${minScore}`;
726
- }
727
- case "inner_product": {
728
- return drizzleOrm.sql`${distanceExpression} <= ${-minScore}`;
729
- }
730
- default: {
731
- const _exhaustive = metric;
732
- throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
733
- }
734
- }
735
- }
736
- function assertFiniteEmbedding(embedding, name) {
737
- for (const [index, value] of embedding.entries()) {
738
- if (typeof value !== "number" || !Number.isFinite(value)) {
739
- throw new TypeError(
740
- `${name}[${index}] must be a finite number, got: ${value}`
741
- );
742
- }
743
- }
744
- }
745
- function assertVectorSearchLimit(limit) {
746
- if (!Number.isInteger(limit) || limit <= 0) {
747
- throw new RangeError(
748
- `vectorSearch limit must be a positive integer, got: ${limit}`
749
- );
750
- }
751
- }
752
- function assertVectorMinScore(minScore, metric, label = "minScore") {
753
- if (!Number.isFinite(minScore)) {
754
- throw new RangeError(`${label} must be a finite number, got: ${minScore}`);
755
- }
756
- if (metric === "cosine" && (minScore < -1 || minScore > 1)) {
757
- throw new RangeError(
758
- `${label} for the cosine metric must be between -1 and 1, got: ${minScore}`
759
- );
760
- }
761
- }
762
- var MAX_VECTOR_IDENTIFIER_LENGTH = 63;
763
- function sanitizeIdentifierPart(value) {
764
- return value.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
765
- }
766
- function shortHash(input) {
767
- let h1 = 3735928559;
768
- let h2 = 1103547991;
769
- for (let index = 0; index < input.length; index++) {
770
- const ch = input.codePointAt(index);
771
- h1 = Math.imul(h1 ^ ch, 2654435761);
772
- h2 = Math.imul(h2 ^ ch, 1597334677);
773
- }
774
- h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
775
- h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
776
- const hi = (h2 >>> 0).toString(16).padStart(8, "0");
777
- const lo = (h1 >>> 0).toString(16).padStart(8, "0");
778
- return `${hi}${lo}`.slice(0, 8);
779
- }
780
- function vectorPhysicalName(prefix, graphId, nodeKind, fieldPath) {
781
- const readable = `${prefix}_${sanitizeIdentifierPart(graphId)}_${sanitizeIdentifierPart(nodeKind)}_${sanitizeIdentifierPart(fieldPath)}`;
782
- const hash = shortHash(JSON.stringify([graphId, nodeKind, fieldPath]));
783
- const full = `${readable}_${hash}`;
784
- if (full.length <= MAX_VECTOR_IDENTIFIER_LENGTH) return full;
785
- return `${readable.slice(0, MAX_VECTOR_IDENTIFIER_LENGTH - 1 - hash.length)}_${hash}`;
786
- }
787
- function quoteIdentifier2(name) {
788
- return `"${name.replaceAll('"', '""')}"`;
789
- }
790
799
 
791
800
  // src/query/dialect/index.ts
792
801
  var DIALECT_ADAPTERS = {
@@ -842,6 +851,20 @@ function compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn) {
842
851
  }
843
852
  return { keys };
844
853
  }
854
+ function compileNodeIndexFieldKeys(index, ctx) {
855
+ const adapter = getDialect(ctx.dialect);
856
+ const keys = [];
857
+ for (const [position, pointer] of index.fields.entries()) {
858
+ const extracted = compileIndexKeyValue(
859
+ adapter,
860
+ ctx.propsColumn,
861
+ pointer,
862
+ index.fieldValueTypes[position]
863
+ );
864
+ keys.push(drizzleOrm.sql`(${extracted})`);
865
+ }
866
+ return keys;
867
+ }
845
868
  function compileIndexKeyValue(dialect, propsColumn, pointer, valueType) {
846
869
  switch (valueType) {
847
870
  case "number": {
@@ -943,7 +966,7 @@ function compileIndexWhereOperand(ctx, operand) {
943
966
  return ctx.systemColumn(operand.column);
944
967
  }
945
968
  const adapter = getDialect(ctx.dialect);
946
- const pointer = chunk7V335GHG_cjs.jsonPointer([operand.field]);
969
+ const pointer = chunkFLRCVI2G_cjs.jsonPointer([operand.field]);
947
970
  switch (operand.valueType) {
948
971
  case "number": {
949
972
  return adapter.jsonExtractNumber(ctx.propsColumn, pointer);
@@ -1012,435 +1035,28 @@ function escapeStringLiteral(value) {
1012
1035
  return `'${value.replaceAll("'", "''")}'`;
1013
1036
  }
1014
1037
 
1015
- // src/indexes/ddl.ts
1016
- function generateIndexDDL(index, dialect, options = {}) {
1017
- if (index.entity === "node") {
1018
- return generateNodeIndexDDL(index, dialect, options);
1019
- }
1020
- return generateEdgeIndexDDL(index, dialect, options);
1021
- }
1022
- function generateNodeIndexDDL(index, dialect, options = {}) {
1023
- const tableName = options.nodesTableName ?? "typegraph_nodes";
1024
- return generateTableIndexDDL(index, dialect, tableName, options);
1025
- }
1026
- function generateEdgeIndexDDL(index, dialect, options = {}) {
1027
- const tableName = options.edgesTableName ?? "typegraph_edges";
1028
- return generateTableIndexDDL(index, dialect, tableName, options);
1029
- }
1030
- function generateTableIndexDDL(index, dialect, tableName, options) {
1031
- const ifNotExists = options.ifNotExists ?? true;
1032
- const propsColumn = drizzleOrm.sql.raw('"props"');
1033
- const systemColumn = (column) => drizzleOrm.sql.raw(quoteIdentifier3(column));
1034
- const keys = index.entity === "node" ? compileNodeIndexKeys(index, dialect, propsColumn, systemColumn).keys : compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn).keys;
1035
- const whereSql = index.where ? sqlToInlineString(
1036
- compileIndexWhere(
1037
- {
1038
- dialect,
1039
- propsColumn,
1040
- systemColumn
1041
- },
1042
- index.where
1043
- ),
1044
- dialect
1045
- ) : void 0;
1046
- const keySql = keys.map((k) => sqlToInlineString(k, dialect)).join(", ");
1047
- const unique = index.unique ? "UNIQUE " : "";
1048
- const concurrent = options.concurrent === true && dialect === "postgres" ? "CONCURRENTLY " : "";
1049
- const ifNotExistsSql = ifNotExists ? "IF NOT EXISTS " : "";
1050
- const whereClause = whereSql ? ` WHERE ${whereSql}` : "";
1051
- return `CREATE ${unique}INDEX ${concurrent}${ifNotExistsSql}${quoteIdentifier3(index.name)} ON ${quoteIdentifier3(tableName)} (${keySql})${whereClause};`;
1052
- }
1053
- function quoteIdentifier3(identifier) {
1054
- return `"${identifier.replaceAll('"', '""')}"`;
1055
- }
1056
- function sqlToInlineString(object, dialect) {
1057
- const query = object.toQuery({
1058
- casing: new casing.CasingCache(),
1059
- escapeName: (name) => name,
1060
- escapeParam: (_number, value) => inlineParam(value, dialect),
1061
- escapeString: (value) => escapeStringLiteral2(value),
1062
- inlineParams: true,
1063
- invokeSource: "indexes"
1064
- });
1065
- if (query.params.length > 0) {
1066
- throw new Error(
1067
- "Index DDL generation produced parameters; expected fully inlined SQL"
1068
- );
1069
- }
1070
- return query.sql;
1071
- }
1072
- function inlineParam(value, dialect) {
1073
- if (value === null || value === void 0) {
1074
- return "NULL";
1075
- }
1076
- if (value instanceof Date) {
1077
- return escapeStringLiteral2(value.toISOString());
1078
- }
1079
- if (typeof value === "string") {
1080
- return escapeStringLiteral2(value);
1081
- }
1082
- if (typeof value === "number") {
1083
- return value.toString();
1084
- }
1085
- if (typeof value === "boolean") {
1086
- return getDialect(dialect).booleanLiteralString(value);
1087
- }
1088
- if (typeof value === "bigint") {
1089
- return value.toString();
1090
- }
1091
- throw new TypeError(
1092
- "Index DDL generation received an unsupported SQL parameter value"
1093
- );
1094
- }
1095
- function escapeStringLiteral2(value) {
1096
- return `'${value.replaceAll("'", "''")}'`;
1097
- }
1098
- function buildPostgresNodeIndexBuilders(table, indexes) {
1099
- const nodeIndexes = indexes.filter(
1100
- (index) => index.entity === "node"
1101
- );
1102
- return nodeIndexes.map((index) => {
1103
- const propsColumn = drizzleOrm.sql`${table.props}`;
1104
- const systemColumn = (column) => drizzleOrm.sql`${getPostgresNodeSystemColumn(table, column)}`;
1105
- const { keys } = compileNodeIndexKeys(
1106
- index,
1107
- "postgres",
1108
- propsColumn,
1109
- systemColumn
1110
- );
1111
- assertNonEmpty(keys, `node index "${index.name}"`);
1112
- const base = index.unique ? pgCore.uniqueIndex(index.name) : pgCore.index(index.name);
1113
- const builder = base.on(...keys);
1114
- if (index.where) {
1115
- const ctx = {
1116
- dialect: "postgres",
1117
- propsColumn,
1118
- systemColumn
1119
- };
1120
- builder.where(compileIndexWhere(ctx, index.where));
1121
- }
1122
- return builder;
1123
- });
1124
- }
1125
- function buildPostgresEdgeIndexBuilders(table, indexes) {
1126
- const edgeIndexes = indexes.filter(
1127
- (index) => index.entity === "edge"
1128
- );
1129
- return edgeIndexes.map((index) => {
1130
- const propsColumn = drizzleOrm.sql`${table.props}`;
1131
- const systemColumn = (column) => drizzleOrm.sql`${getPostgresEdgeSystemColumn(table, column)}`;
1132
- const { keys } = compileEdgeIndexKeys(
1133
- index,
1134
- "postgres",
1135
- propsColumn,
1136
- systemColumn
1137
- );
1138
- assertNonEmpty(keys, `edge index "${index.name}"`);
1139
- const base = index.unique ? pgCore.uniqueIndex(index.name) : pgCore.index(index.name);
1140
- const builder = base.on(...keys);
1141
- if (index.where) {
1142
- const ctx = {
1143
- dialect: "postgres",
1144
- propsColumn,
1145
- systemColumn
1146
- };
1147
- builder.where(compileIndexWhere(ctx, index.where));
1148
- }
1149
- return builder;
1150
- });
1151
- }
1152
- function getPostgresNodeSystemColumn(table, column) {
1153
- switch (column) {
1154
- case "graph_id": {
1155
- return table.graphId;
1156
- }
1157
- case "kind": {
1158
- return table.kind;
1159
- }
1160
- case "id": {
1161
- return table.id;
1162
- }
1163
- case "from_kind":
1164
- case "from_id":
1165
- case "to_kind":
1166
- case "to_id": {
1167
- throw new Error(`Unsupported node system column for indexes: ${column}`);
1168
- }
1169
- case "deleted_at": {
1170
- return table.deletedAt;
1171
- }
1172
- case "valid_from": {
1173
- return table.validFrom;
1174
- }
1175
- case "valid_to": {
1176
- return table.validTo;
1177
- }
1178
- case "created_at": {
1179
- return table.createdAt;
1180
- }
1181
- case "updated_at": {
1182
- return table.updatedAt;
1183
- }
1184
- case "version": {
1185
- return table.version;
1186
- }
1187
- }
1188
- }
1189
- function getPostgresEdgeSystemColumn(table, column) {
1190
- switch (column) {
1191
- case "graph_id": {
1192
- return table.graphId;
1193
- }
1194
- case "kind": {
1195
- return table.kind;
1196
- }
1197
- case "id": {
1198
- return table.id;
1199
- }
1200
- case "from_kind": {
1201
- return table.fromKind;
1202
- }
1203
- case "from_id": {
1204
- return table.fromId;
1205
- }
1206
- case "to_kind": {
1207
- return table.toKind;
1208
- }
1209
- case "to_id": {
1210
- return table.toId;
1211
- }
1212
- case "deleted_at": {
1213
- return table.deletedAt;
1214
- }
1215
- case "valid_from": {
1216
- return table.validFrom;
1217
- }
1218
- case "valid_to": {
1219
- return table.validTo;
1220
- }
1221
- case "created_at": {
1222
- return table.createdAt;
1223
- }
1224
- case "updated_at": {
1225
- return table.updatedAt;
1226
- }
1227
- case "version": {
1228
- throw new Error(`Unsupported edge system column for indexes: ${column}`);
1229
- }
1230
- }
1231
- }
1232
- function buildSqliteNodeIndexBuilders(table, indexes) {
1233
- const nodeIndexes = indexes.filter(
1234
- (index) => index.entity === "node"
1235
- );
1236
- return nodeIndexes.map((index) => {
1237
- const propsColumn = drizzleOrm.sql`${table.props}`;
1238
- const systemColumn = (column) => drizzleOrm.sql`${getSqliteNodeSystemColumn(table, column)}`;
1239
- const { keys } = compileNodeIndexKeys(
1240
- index,
1241
- "sqlite",
1242
- propsColumn,
1243
- systemColumn
1244
- );
1245
- assertNonEmpty(keys, `node index "${index.name}"`);
1246
- const base = index.unique ? sqliteCore.uniqueIndex(index.name) : sqliteCore.index(index.name);
1247
- const builder = base.on(...keys);
1248
- if (index.where) {
1249
- const ctx = {
1250
- dialect: "sqlite",
1251
- propsColumn,
1252
- systemColumn
1253
- };
1254
- builder.where(compileIndexWhere(ctx, index.where));
1255
- }
1256
- return builder;
1257
- });
1258
- }
1259
- function buildSqliteEdgeIndexBuilders(table, indexes) {
1260
- const edgeIndexes = indexes.filter(
1261
- (index) => index.entity === "edge"
1262
- );
1263
- return edgeIndexes.map((index) => {
1264
- const propsColumn = drizzleOrm.sql`${table.props}`;
1265
- const systemColumn = (column) => drizzleOrm.sql`${getSqliteEdgeSystemColumn(table, column)}`;
1266
- const { keys } = compileEdgeIndexKeys(
1267
- index,
1268
- "sqlite",
1269
- propsColumn,
1270
- systemColumn
1271
- );
1272
- assertNonEmpty(keys, `edge index "${index.name}"`);
1273
- const base = index.unique ? sqliteCore.uniqueIndex(index.name) : sqliteCore.index(index.name);
1274
- const builder = base.on(...keys);
1275
- if (index.where) {
1276
- const ctx = {
1277
- dialect: "sqlite",
1278
- propsColumn,
1279
- systemColumn
1280
- };
1281
- builder.where(compileIndexWhere(ctx, index.where));
1282
- }
1283
- return builder;
1284
- });
1285
- }
1286
- function getSqliteNodeSystemColumn(table, column) {
1287
- switch (column) {
1288
- case "graph_id": {
1289
- return table.graphId;
1290
- }
1291
- case "kind": {
1292
- return table.kind;
1293
- }
1294
- case "id": {
1295
- return table.id;
1296
- }
1297
- case "from_kind":
1298
- case "from_id":
1299
- case "to_kind":
1300
- case "to_id": {
1301
- throw new Error(`Unsupported node system column for indexes: ${column}`);
1302
- }
1303
- case "deleted_at": {
1304
- return table.deletedAt;
1305
- }
1306
- case "valid_from": {
1307
- return table.validFrom;
1308
- }
1309
- case "valid_to": {
1310
- return table.validTo;
1311
- }
1312
- case "created_at": {
1313
- return table.createdAt;
1314
- }
1315
- case "updated_at": {
1316
- return table.updatedAt;
1317
- }
1318
- case "version": {
1319
- return table.version;
1320
- }
1321
- }
1322
- }
1323
- function getSqliteEdgeSystemColumn(table, column) {
1324
- switch (column) {
1325
- case "graph_id": {
1326
- return table.graphId;
1327
- }
1328
- case "kind": {
1329
- return table.kind;
1330
- }
1331
- case "id": {
1332
- return table.id;
1333
- }
1334
- case "from_kind": {
1335
- return table.fromKind;
1336
- }
1337
- case "from_id": {
1338
- return table.fromId;
1339
- }
1340
- case "to_kind": {
1341
- return table.toKind;
1342
- }
1343
- case "to_id": {
1344
- return table.toId;
1345
- }
1346
- case "deleted_at": {
1347
- return table.deletedAt;
1348
- }
1349
- case "valid_from": {
1350
- return table.validFrom;
1351
- }
1352
- case "valid_to": {
1353
- return table.validTo;
1354
- }
1355
- case "created_at": {
1356
- return table.createdAt;
1357
- }
1358
- case "updated_at": {
1359
- return table.updatedAt;
1360
- }
1361
- case "version": {
1362
- throw new Error(`Unsupported edge system column for indexes: ${column}`);
1363
- }
1364
- }
1365
- }
1366
- function assertNonEmpty(values, label) {
1367
- if (values.length === 0) {
1368
- throw new Error(`Index must have at least one key (${label})`);
1369
- }
1370
- }
1371
-
1372
- // src/indexes/profiler.ts
1373
- function toDeclaredIndex(index) {
1374
- return {
1375
- entityType: index.entity,
1376
- kind: index.kind,
1377
- fields: [...index.fields],
1378
- unique: index.unique,
1379
- name: index.name
1380
- };
1381
- }
1382
- function toDeclaredIndexes(indexes) {
1383
- return indexes.filter(
1384
- (index) => index.entity === "node" || index.entity === "edge"
1385
- ).map((index) => toDeclaredIndex(index));
1386
- }
1387
-
1388
- // src/indexes/where.ts
1389
- function andWhere(...predicates) {
1390
- if (predicates.length === 1) {
1391
- return predicates[0];
1392
- }
1393
- return {
1394
- __type: "index_where_and",
1395
- predicates
1396
- };
1397
- }
1398
- function orWhere(...predicates) {
1399
- if (predicates.length === 1) {
1400
- return predicates[0];
1401
- }
1402
- return {
1403
- __type: "index_where_or",
1404
- predicates
1405
- };
1406
- }
1407
- function notWhere(predicate) {
1408
- return {
1409
- __type: "index_where_not",
1410
- predicate
1411
- };
1412
- }
1413
-
1414
1038
  exports.BASE_CONTRIBUTION_OWNER = BASE_CONTRIBUTION_OWNER;
1415
1039
  exports.VECTOR_CONTRIBUTION_PREFIX = VECTOR_CONTRIBUTION_PREFIX;
1416
- exports.andWhere = andWhere;
1417
1040
  exports.assertFiniteEmbedding = assertFiniteEmbedding;
1418
1041
  exports.assertVectorMinScore = assertVectorMinScore;
1419
1042
  exports.assertVectorSearchLimit = assertVectorSearchLimit;
1420
1043
  exports.buildFulltextCapabilities = buildFulltextCapabilities;
1421
- exports.buildPostgresEdgeIndexBuilders = buildPostgresEdgeIndexBuilders;
1422
- exports.buildPostgresNodeIndexBuilders = buildPostgresNodeIndexBuilders;
1423
- exports.buildSqliteEdgeIndexBuilders = buildSqliteEdgeIndexBuilders;
1424
- exports.buildSqliteNodeIndexBuilders = buildSqliteNodeIndexBuilders;
1425
1044
  exports.buildVectorCapabilities = buildVectorCapabilities;
1045
+ exports.compileEdgeIndexKeys = compileEdgeIndexKeys;
1046
+ exports.compileIndexWhere = compileIndexWhere;
1047
+ exports.compileNodeIndexFieldKeys = compileNodeIndexFieldKeys;
1048
+ exports.compileNodeIndexKeys = compileNodeIndexKeys;
1426
1049
  exports.edgeColumnList = edgeColumnList;
1427
1050
  exports.fts5Strategy = fts5Strategy;
1428
- exports.generateEdgeIndexDDL = generateEdgeIndexDDL;
1429
- exports.generateIndexDDL = generateIndexDDL;
1430
- exports.generateNodeIndexDDL = generateNodeIndexDDL;
1431
1051
  exports.getDialect = getDialect;
1432
1052
  exports.nodeColumnList = nodeColumnList;
1433
- exports.notWhere = notWhere;
1434
- exports.orWhere = orWhere;
1435
1053
  exports.quoteIdentifier = quoteIdentifier2;
1436
1054
  exports.quotedColumn = quotedColumn;
1437
1055
  exports.quotedTableName = quotedTableName;
1438
1056
  exports.sqlNull = sqlNull;
1439
- exports.toDeclaredIndex = toDeclaredIndex;
1440
- exports.toDeclaredIndexes = toDeclaredIndexes;
1441
1057
  exports.tsvectorStrategy = tsvectorStrategy;
1442
1058
  exports.vectorMinScoreCondition = vectorMinScoreCondition;
1443
1059
  exports.vectorPhysicalName = vectorPhysicalName;
1444
1060
  exports.vectorScoreExpression = vectorScoreExpression;
1445
- //# sourceMappingURL=chunk-C2RWFIYP.cjs.map
1446
- //# sourceMappingURL=chunk-C2RWFIYP.cjs.map
1061
+ //# sourceMappingURL=chunk-V4IQYOQ4.cjs.map
1062
+ //# sourceMappingURL=chunk-V4IQYOQ4.cjs.map