@nicia-ai/typegraph 0.30.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 (181) hide show
  1. package/README.md +39 -0
  2. package/dist/backend/postgres/index.cjs +19 -18
  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 +9 -8
  6. package/dist/backend/postgres/pglite.cjs +13 -12
  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 +9 -8
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +16 -16
  13. package/dist/backend/sqlite/index.d.cts +7 -7
  14. package/dist/backend/sqlite/index.d.ts +7 -7
  15. package/dist/backend/sqlite/index.js +7 -7
  16. package/dist/backend/sqlite/libsql.cjs +12 -12
  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 +8 -8
  20. package/dist/backend/sqlite/local.cjs +13 -13
  21. package/dist/backend/sqlite/local.d.cts +3 -3
  22. package/dist/backend/sqlite/local.d.ts +3 -3
  23. package/dist/backend/sqlite/local.js +8 -8
  24. package/dist/{chunk-AI3RNREM.js → chunk-2HZGWCB4.js} +94 -496
  25. package/dist/chunk-2HZGWCB4.js.map +1 -0
  26. package/dist/chunk-2YMGNYXY.js +40 -0
  27. package/dist/chunk-2YMGNYXY.js.map +1 -0
  28. package/dist/chunk-2ZY4K43M.js +90 -0
  29. package/dist/chunk-2ZY4K43M.js.map +1 -0
  30. package/dist/chunk-3EUKJEQ3.js +77 -0
  31. package/dist/chunk-3EUKJEQ3.js.map +1 -0
  32. package/dist/chunk-3JBJEYWE.cjs +604 -0
  33. package/dist/chunk-3JBJEYWE.cjs.map +1 -0
  34. package/dist/{chunk-IUIJJYPI.js → chunk-4A4GUZTQ.js} +6 -5
  35. package/dist/chunk-4A4GUZTQ.js.map +1 -0
  36. package/dist/{chunk-WEMZM7J7.cjs → chunk-54JVNOAQ.cjs} +5 -41
  37. package/dist/chunk-54JVNOAQ.cjs.map +1 -0
  38. package/dist/{chunk-IE6GN7L3.cjs → chunk-5CN7B4CZ.cjs} +17 -98
  39. package/dist/chunk-5CN7B4CZ.cjs.map +1 -0
  40. package/dist/{chunk-K4N35E7B.cjs → chunk-5DTPBFX5.cjs} +64 -63
  41. package/dist/chunk-5DTPBFX5.cjs.map +1 -0
  42. package/dist/chunk-6G35I3VW.cjs +40 -0
  43. package/dist/chunk-6G35I3VW.cjs.map +1 -0
  44. package/dist/{chunk-4BXHVEFB.cjs → chunk-6RMLO5O4.cjs} +6 -51
  45. package/dist/chunk-6RMLO5O4.cjs.map +1 -0
  46. package/dist/chunk-6SA7UIQJ.cjs +94 -0
  47. package/dist/chunk-6SA7UIQJ.cjs.map +1 -0
  48. package/dist/chunk-6ZR4QC3O.cjs +12 -0
  49. package/dist/{chunk-LUHU4T2F.cjs.map → chunk-6ZR4QC3O.cjs.map} +1 -1
  50. package/dist/chunk-73KASJGO.cjs +52 -0
  51. package/dist/chunk-73KASJGO.cjs.map +1 -0
  52. package/dist/chunk-A3W7QG7K.js +45 -0
  53. package/dist/chunk-A3W7QG7K.js.map +1 -0
  54. package/dist/{chunk-FWBVPATK.cjs → chunk-ASYQDPPU.cjs} +19 -19
  55. package/dist/{chunk-FWBVPATK.cjs.map → chunk-ASYQDPPU.cjs.map} +1 -1
  56. package/dist/{chunk-FVIGJTS7.js → chunk-ATTXBMAX.js} +4 -74
  57. package/dist/chunk-ATTXBMAX.js.map +1 -0
  58. package/dist/chunk-AW4A3P5A.cjs +51 -0
  59. package/dist/chunk-AW4A3P5A.cjs.map +1 -0
  60. package/dist/{chunk-WFCECD6Q.cjs → chunk-CIINW6PS.cjs} +73 -68
  61. package/dist/chunk-CIINW6PS.cjs.map +1 -0
  62. package/dist/{chunk-26HWIIVS.cjs → chunk-FLOI7QOT.cjs} +63 -62
  63. package/dist/chunk-FLOI7QOT.cjs.map +1 -0
  64. package/dist/{chunk-633N7DSE.js → chunk-GKFWM3DS.js} +4 -36
  65. package/dist/chunk-GKFWM3DS.js.map +1 -0
  66. package/dist/chunk-HTGDWIDE.cjs +89 -0
  67. package/dist/chunk-HTGDWIDE.cjs.map +1 -0
  68. package/dist/{chunk-R4JOBEJU.js → chunk-IJORSAC3.js} +4 -40
  69. package/dist/chunk-IJORSAC3.js.map +1 -0
  70. package/dist/{chunk-SGPXKJ4A.cjs → chunk-KTIEB7VH.cjs} +26 -16
  71. package/dist/chunk-KTIEB7VH.cjs.map +1 -0
  72. package/dist/chunk-LJLMDDCW.js +282 -0
  73. package/dist/chunk-LJLMDDCW.js.map +1 -0
  74. package/dist/{chunk-VFX3LC76.cjs → chunk-N2MBPTAF.cjs} +14 -14
  75. package/dist/{chunk-VFX3LC76.cjs.map → chunk-N2MBPTAF.cjs.map} +1 -1
  76. package/dist/{chunk-3IRMLJEK.js → chunk-O4VUR6SI.js} +3 -3
  77. package/dist/{chunk-3IRMLJEK.js.map → chunk-O4VUR6SI.js.map} +1 -1
  78. package/dist/chunk-RZ4DH4E7.cjs +15832 -0
  79. package/dist/chunk-RZ4DH4E7.cjs.map +1 -0
  80. package/dist/chunk-SAJSMR2B.js +35 -0
  81. package/dist/chunk-SAJSMR2B.js.map +1 -0
  82. package/dist/{chunk-4LBO6KIF.cjs → chunk-SFFJ2IKN.cjs} +60 -59
  83. package/dist/chunk-SFFJ2IKN.cjs.map +1 -0
  84. package/dist/{chunk-K5VREXMZ.js → chunk-STP7QVUB.js} +7 -6
  85. package/dist/chunk-STP7QVUB.js.map +1 -0
  86. package/dist/chunk-THX25XW6.js +590 -0
  87. package/dist/chunk-THX25XW6.js.map +1 -0
  88. package/dist/chunk-UIFEEPME.js +15787 -0
  89. package/dist/chunk-UIFEEPME.js.map +1 -0
  90. package/dist/{chunk-2QA5EHEN.js → chunk-UJ4V3YUQ.js} +3 -3
  91. package/dist/{chunk-2QA5EHEN.js.map → chunk-UJ4V3YUQ.js.map} +1 -1
  92. package/dist/{chunk-UESTHN47.cjs → chunk-V4IQYOQ4.cjs} +95 -507
  93. package/dist/chunk-V4IQYOQ4.cjs.map +1 -0
  94. package/dist/chunk-VMEWZU2N.cjs +287 -0
  95. package/dist/chunk-VMEWZU2N.cjs.map +1 -0
  96. package/dist/{chunk-N2OEOGBB.js → chunk-VZX2KSY3.js} +13 -8
  97. package/dist/chunk-VZX2KSY3.js.map +1 -0
  98. package/dist/{chunk-IX7RE7CG.js → chunk-WYTUF3QO.js} +3 -3
  99. package/dist/{chunk-IX7RE7CG.js.map → chunk-WYTUF3QO.js.map} +1 -1
  100. package/dist/{chunk-3JLRHQ67.js → chunk-XKJQQQVR.js} +6 -5
  101. package/dist/chunk-XKJQQQVR.js.map +1 -0
  102. package/dist/{chunk-ENDUY2CD.js → chunk-YCV72E6L.js} +23 -17
  103. package/dist/chunk-YCV72E6L.js.map +1 -0
  104. package/dist/{ddl-EdkIiFVU.d.ts → ddl-BJcPrB4L.d.ts} +3 -3
  105. package/dist/{ddl-BSFlbGQF.d.cts → ddl-CPZ7mB7X.d.cts} +3 -3
  106. package/dist/{extension-types-CwHV-Uk4.d.cts → extension-types-D1k0inWU.d.cts} +1 -1
  107. package/dist/{extension-types-CwHV-Uk4.d.ts → extension-types-D1k0inWU.d.ts} +1 -1
  108. package/dist/graph-extension/index.cjs +17 -17
  109. package/dist/graph-extension/index.d.cts +5 -16
  110. package/dist/graph-extension/index.d.ts +5 -16
  111. package/dist/graph-extension/index.js +2 -2
  112. package/dist/graph-merge/index.cjs +3822 -0
  113. package/dist/graph-merge/index.cjs.map +1 -0
  114. package/dist/graph-merge/index.d.cts +1191 -0
  115. package/dist/graph-merge/index.d.ts +1191 -0
  116. package/dist/graph-merge/index.js +3791 -0
  117. package/dist/graph-merge/index.js.map +1 -0
  118. package/dist/{index-DzeIiMO3.d.ts → index-BEK0VtNB.d.ts} +2 -2
  119. package/dist/{index-Ln_KHTGA.d.cts → index-C8sSTErx.d.cts} +2 -2
  120. package/dist/index.cjs +281 -15913
  121. package/dist/index.cjs.map +1 -1
  122. package/dist/index.d.cts +12 -11
  123. package/dist/index.d.ts +12 -11
  124. package/dist/index.js +23 -15790
  125. package/dist/index.js.map +1 -1
  126. package/dist/indexes/index.cjs +30 -26
  127. package/dist/indexes/index.d.cts +5 -5
  128. package/dist/indexes/index.d.ts +5 -5
  129. package/dist/indexes/index.js +6 -2
  130. package/dist/interchange/index.cjs +49 -592
  131. package/dist/interchange/index.cjs.map +1 -1
  132. package/dist/interchange/index.d.cts +5 -5
  133. package/dist/interchange/index.d.ts +5 -5
  134. package/dist/interchange/index.js +2 -588
  135. package/dist/interchange/index.js.map +1 -1
  136. package/dist/{manager-BbdyNhkv.d.ts → manager-By-WEd8M.d.ts} +3 -3
  137. package/dist/{manager-wTDgjoXG.d.cts → manager-Np7VVSlE.d.cts} +3 -3
  138. package/dist/{materialize-indexes-lkawaDor.d.ts → materialize-indexes-CAGhqPHQ.d.ts} +1 -1
  139. package/dist/{materialize-indexes-oanE3RU0.d.cts → materialize-indexes-DEYkU-wr.d.cts} +1 -1
  140. package/dist/{postgres-CK2ByP1q.d.cts → postgres-4J2tmauh.d.cts} +1 -1
  141. package/dist/{postgres-ymXYC6Rr.d.ts → postgres-BdIb7tS_.d.ts} +1 -1
  142. package/dist/profiler/index.d.cts +7 -7
  143. package/dist/profiler/index.d.ts +7 -7
  144. package/dist/result-DWo6mUVz.d.cts +37 -0
  145. package/dist/result-DWo6mUVz.d.ts +37 -0
  146. package/dist/schema/index.cjs +29 -28
  147. package/dist/schema/index.cjs.map +1 -1
  148. package/dist/schema/index.d.cts +7 -7
  149. package/dist/schema/index.d.ts +7 -7
  150. package/dist/schema/index.js +6 -5
  151. package/dist/schema/index.js.map +1 -1
  152. package/dist/{sqlite-DxH1lrwD.d.cts → sqlite-Gatk_iw_.d.cts} +1 -1
  153. package/dist/{sqlite-R8YGOqVQ.d.ts → sqlite-aM_PAz-O.d.ts} +1 -1
  154. package/dist/{store--z1Tmk7U.d.cts → store-DuCbdqsh.d.cts} +49 -49
  155. package/dist/{store-CNKM334w.d.ts → store-MloRPwb9.d.ts} +49 -49
  156. package/dist/{types-BBiDqJCU.d.ts → types-BKQljXom.d.ts} +16 -2
  157. package/dist/{types-dL-clxO3.d.cts → types-C1CYxWrL.d.cts} +16 -2
  158. package/dist/{types-D5B6Be5c.d.cts → types-DoByHGyU.d.cts} +2 -2
  159. package/dist/{types-CMvxx2kd.d.ts → types-K3vpaJAL.d.ts} +2 -2
  160. package/dist/{where-CAo6wsBZ.d.ts → where-Dt49bvo6.d.ts} +2 -2
  161. package/dist/{where-bJjuOCeV.d.cts → where-DydZjGOb.d.cts} +2 -2
  162. package/package.json +6 -1
  163. package/dist/chunk-26HWIIVS.cjs.map +0 -1
  164. package/dist/chunk-3JLRHQ67.js.map +0 -1
  165. package/dist/chunk-4BXHVEFB.cjs.map +0 -1
  166. package/dist/chunk-4LBO6KIF.cjs.map +0 -1
  167. package/dist/chunk-633N7DSE.js.map +0 -1
  168. package/dist/chunk-AI3RNREM.js.map +0 -1
  169. package/dist/chunk-ENDUY2CD.js.map +0 -1
  170. package/dist/chunk-FVIGJTS7.js.map +0 -1
  171. package/dist/chunk-IE6GN7L3.cjs.map +0 -1
  172. package/dist/chunk-IUIJJYPI.js.map +0 -1
  173. package/dist/chunk-K4N35E7B.cjs.map +0 -1
  174. package/dist/chunk-K5VREXMZ.js.map +0 -1
  175. package/dist/chunk-LUHU4T2F.cjs +0 -12
  176. package/dist/chunk-N2OEOGBB.js.map +0 -1
  177. package/dist/chunk-R4JOBEJU.js.map +0 -1
  178. package/dist/chunk-SGPXKJ4A.cjs.map +0 -1
  179. package/dist/chunk-UESTHN47.cjs.map +0 -1
  180. package/dist/chunk-WEMZM7J7.cjs.map +0 -1
  181. package/dist/chunk-WFCECD6Q.cjs.map +0 -1
@@ -1,8 +1,5 @@
1
1
  import { jsonPointer, parseJsonPointer } from './chunk-K5P5OZXS.js';
2
2
  import { sql } from 'drizzle-orm';
3
- import { CasingCache } from 'drizzle-orm/casing';
4
- import { uniqueIndex, index } from 'drizzle-orm/pg-core';
5
- import { uniqueIndex as uniqueIndex$1, index as index$1 } from 'drizzle-orm/sqlite-core';
6
3
 
7
4
  function sqlNull(value) {
8
5
  return value ?? sql.raw("NULL");
@@ -382,6 +379,97 @@ var fts5Strategy = {
382
379
  return stmt === void 0 ? [] : [stmt];
383
380
  }
384
381
  };
382
+ var VECTOR_CONTRIBUTION_PREFIX = "vector";
383
+ function buildVectorCapabilities(strategy) {
384
+ return strategy.capabilities;
385
+ }
386
+ function vectorScoreExpression(distanceExpression, metric) {
387
+ switch (metric) {
388
+ case "cosine": {
389
+ return sql`(1 - (${distanceExpression}))`;
390
+ }
391
+ case "l2":
392
+ case "inner_product": {
393
+ return distanceExpression;
394
+ }
395
+ default: {
396
+ const _exhaustive = metric;
397
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
398
+ }
399
+ }
400
+ }
401
+ function vectorMinScoreCondition(distanceExpression, metric, minScore) {
402
+ assertVectorMinScore(minScore, metric);
403
+ switch (metric) {
404
+ case "cosine": {
405
+ return sql`${distanceExpression} <= ${1 - minScore}`;
406
+ }
407
+ case "l2": {
408
+ return sql`${distanceExpression} <= ${minScore}`;
409
+ }
410
+ case "inner_product": {
411
+ return sql`${distanceExpression} <= ${-minScore}`;
412
+ }
413
+ default: {
414
+ const _exhaustive = metric;
415
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
416
+ }
417
+ }
418
+ }
419
+ function assertFiniteEmbedding(embedding, name) {
420
+ for (const [index, value] of embedding.entries()) {
421
+ if (typeof value !== "number" || !Number.isFinite(value)) {
422
+ throw new TypeError(
423
+ `${name}[${index}] must be a finite number, got: ${value}`
424
+ );
425
+ }
426
+ }
427
+ }
428
+ function assertVectorSearchLimit(limit) {
429
+ if (!Number.isInteger(limit) || limit <= 0) {
430
+ throw new RangeError(
431
+ `vectorSearch limit must be a positive integer, got: ${limit}`
432
+ );
433
+ }
434
+ }
435
+ function assertVectorMinScore(minScore, metric, label = "minScore") {
436
+ if (!Number.isFinite(minScore)) {
437
+ throw new RangeError(`${label} must be a finite number, got: ${minScore}`);
438
+ }
439
+ if (metric === "cosine" && (minScore < -1 || minScore > 1)) {
440
+ throw new RangeError(
441
+ `${label} for the cosine metric must be between -1 and 1, got: ${minScore}`
442
+ );
443
+ }
444
+ }
445
+ var MAX_VECTOR_IDENTIFIER_LENGTH = 63;
446
+ function sanitizeIdentifierPart(value) {
447
+ return value.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
448
+ }
449
+ function shortHash(input) {
450
+ let h1 = 3735928559;
451
+ let h2 = 1103547991;
452
+ for (let index = 0; index < input.length; index++) {
453
+ const ch = input.codePointAt(index);
454
+ h1 = Math.imul(h1 ^ ch, 2654435761);
455
+ h2 = Math.imul(h2 ^ ch, 1597334677);
456
+ }
457
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
458
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
459
+ const hi = (h2 >>> 0).toString(16).padStart(8, "0");
460
+ const lo = (h1 >>> 0).toString(16).padStart(8, "0");
461
+ return `${hi}${lo}`.slice(0, 8);
462
+ }
463
+ function vectorPhysicalName(prefix, graphId, nodeKind, fieldPath) {
464
+ const readable = `${prefix}_${sanitizeIdentifierPart(graphId)}_${sanitizeIdentifierPart(nodeKind)}_${sanitizeIdentifierPart(fieldPath)}`;
465
+ const hash = shortHash(JSON.stringify([graphId, nodeKind, fieldPath]));
466
+ const full = `${readable}_${hash}`;
467
+ if (full.length <= MAX_VECTOR_IDENTIFIER_LENGTH) return full;
468
+ return `${readable.slice(0, MAX_VECTOR_IDENTIFIER_LENGTH - 1 - hash.length)}_${hash}`;
469
+ }
470
+ function quoteIdentifier2(name) {
471
+ return `"${name.replaceAll('"', '""')}"`;
472
+ }
385
473
  function escapePostgresLiteral(value) {
386
474
  return `'${value.replaceAll("'", "''")}'`;
387
475
  }
@@ -706,97 +794,6 @@ var sqliteDialect = {
706
794
  // ============================================================
707
795
  fulltext: fts5Strategy
708
796
  };
709
- var VECTOR_CONTRIBUTION_PREFIX = "vector";
710
- function buildVectorCapabilities(strategy) {
711
- return strategy.capabilities;
712
- }
713
- function vectorScoreExpression(distanceExpression, metric) {
714
- switch (metric) {
715
- case "cosine": {
716
- return sql`(1 - (${distanceExpression}))`;
717
- }
718
- case "l2":
719
- case "inner_product": {
720
- return distanceExpression;
721
- }
722
- default: {
723
- const _exhaustive = metric;
724
- throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
725
- }
726
- }
727
- }
728
- function vectorMinScoreCondition(distanceExpression, metric, minScore) {
729
- assertVectorMinScore(minScore, metric);
730
- switch (metric) {
731
- case "cosine": {
732
- return sql`${distanceExpression} <= ${1 - minScore}`;
733
- }
734
- case "l2": {
735
- return sql`${distanceExpression} <= ${minScore}`;
736
- }
737
- case "inner_product": {
738
- return sql`${distanceExpression} <= ${-minScore}`;
739
- }
740
- default: {
741
- const _exhaustive = metric;
742
- throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
743
- }
744
- }
745
- }
746
- function assertFiniteEmbedding(embedding, name) {
747
- for (const [index, value] of embedding.entries()) {
748
- if (typeof value !== "number" || !Number.isFinite(value)) {
749
- throw new TypeError(
750
- `${name}[${index}] must be a finite number, got: ${value}`
751
- );
752
- }
753
- }
754
- }
755
- function assertVectorSearchLimit(limit) {
756
- if (!Number.isInteger(limit) || limit <= 0) {
757
- throw new RangeError(
758
- `vectorSearch limit must be a positive integer, got: ${limit}`
759
- );
760
- }
761
- }
762
- function assertVectorMinScore(minScore, metric, label = "minScore") {
763
- if (!Number.isFinite(minScore)) {
764
- throw new RangeError(`${label} must be a finite number, got: ${minScore}`);
765
- }
766
- if (metric === "cosine" && (minScore < -1 || minScore > 1)) {
767
- throw new RangeError(
768
- `${label} for the cosine metric must be between -1 and 1, got: ${minScore}`
769
- );
770
- }
771
- }
772
- var MAX_VECTOR_IDENTIFIER_LENGTH = 63;
773
- function sanitizeIdentifierPart(value) {
774
- return value.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
775
- }
776
- function shortHash(input) {
777
- let h1 = 3735928559;
778
- let h2 = 1103547991;
779
- for (let index = 0; index < input.length; index++) {
780
- const ch = input.codePointAt(index);
781
- h1 = Math.imul(h1 ^ ch, 2654435761);
782
- h2 = Math.imul(h2 ^ ch, 1597334677);
783
- }
784
- h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
785
- h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
786
- const hi = (h2 >>> 0).toString(16).padStart(8, "0");
787
- const lo = (h1 >>> 0).toString(16).padStart(8, "0");
788
- return `${hi}${lo}`.slice(0, 8);
789
- }
790
- function vectorPhysicalName(prefix, graphId, nodeKind, fieldPath) {
791
- const readable = `${prefix}_${sanitizeIdentifierPart(graphId)}_${sanitizeIdentifierPart(nodeKind)}_${sanitizeIdentifierPart(fieldPath)}`;
792
- const hash = shortHash(JSON.stringify([graphId, nodeKind, fieldPath]));
793
- const full = `${readable}_${hash}`;
794
- if (full.length <= MAX_VECTOR_IDENTIFIER_LENGTH) return full;
795
- return `${readable.slice(0, MAX_VECTOR_IDENTIFIER_LENGTH - 1 - hash.length)}_${hash}`;
796
- }
797
- function quoteIdentifier2(name) {
798
- return `"${name.replaceAll('"', '""')}"`;
799
- }
800
797
 
801
798
  // src/query/dialect/index.ts
802
799
  var DIALECT_ADAPTERS = {
@@ -1036,405 +1033,6 @@ function escapeStringLiteral(value) {
1036
1033
  return `'${value.replaceAll("'", "''")}'`;
1037
1034
  }
1038
1035
 
1039
- // src/indexes/ddl.ts
1040
- function generateIndexDDL(index, dialect, options = {}) {
1041
- if (index.entity === "node") {
1042
- return generateNodeIndexDDL(index, dialect, options);
1043
- }
1044
- return generateEdgeIndexDDL(index, dialect, options);
1045
- }
1046
- function generateNodeIndexDDL(index, dialect, options = {}) {
1047
- const tableName = options.nodesTableName ?? "typegraph_nodes";
1048
- return generateTableIndexDDL(index, dialect, tableName, options);
1049
- }
1050
- function generateEdgeIndexDDL(index, dialect, options = {}) {
1051
- const tableName = options.edgesTableName ?? "typegraph_edges";
1052
- return generateTableIndexDDL(index, dialect, tableName, options);
1053
- }
1054
- function generateTableIndexDDL(index, dialect, tableName, options) {
1055
- const ifNotExists = options.ifNotExists ?? true;
1056
- const propsColumn = sql.raw('"props"');
1057
- const systemColumn = (column) => sql.raw(quoteIdentifier3(column));
1058
- const keys = index.entity === "node" ? compileNodeIndexKeys(index, dialect, propsColumn, systemColumn).keys : compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn).keys;
1059
- const whereSql = index.where ? sqlToInlineString(
1060
- compileIndexWhere(
1061
- {
1062
- dialect,
1063
- propsColumn,
1064
- systemColumn
1065
- },
1066
- index.where
1067
- ),
1068
- dialect
1069
- ) : void 0;
1070
- const keySql = keys.map((k) => sqlToInlineString(k, dialect)).join(", ");
1071
- const unique = index.unique ? "UNIQUE " : "";
1072
- const concurrent = options.concurrent === true && dialect === "postgres" ? "CONCURRENTLY " : "";
1073
- const ifNotExistsSql = ifNotExists ? "IF NOT EXISTS " : "";
1074
- const whereClause = whereSql ? ` WHERE ${whereSql}` : "";
1075
- return `CREATE ${unique}INDEX ${concurrent}${ifNotExistsSql}${quoteIdentifier3(index.name)} ON ${quoteIdentifier3(tableName)} (${keySql})${whereClause};`;
1076
- }
1077
- function quoteIdentifier3(identifier) {
1078
- return `"${identifier.replaceAll('"', '""')}"`;
1079
- }
1080
- function sqlToInlineString(object, dialect) {
1081
- const query = object.toQuery({
1082
- casing: new CasingCache(),
1083
- escapeName: (name) => name,
1084
- escapeParam: (_number, value) => inlineParam(value, dialect),
1085
- escapeString: (value) => escapeStringLiteral2(value),
1086
- inlineParams: true,
1087
- invokeSource: "indexes"
1088
- });
1089
- if (query.params.length > 0) {
1090
- throw new Error(
1091
- "Index DDL generation produced parameters; expected fully inlined SQL"
1092
- );
1093
- }
1094
- return query.sql;
1095
- }
1096
- function inlineParam(value, dialect) {
1097
- if (value === null || value === void 0) {
1098
- return "NULL";
1099
- }
1100
- if (value instanceof Date) {
1101
- return escapeStringLiteral2(value.toISOString());
1102
- }
1103
- if (typeof value === "string") {
1104
- return escapeStringLiteral2(value);
1105
- }
1106
- if (typeof value === "number") {
1107
- return value.toString();
1108
- }
1109
- if (typeof value === "boolean") {
1110
- return getDialect(dialect).booleanLiteralString(value);
1111
- }
1112
- if (typeof value === "bigint") {
1113
- return value.toString();
1114
- }
1115
- throw new TypeError(
1116
- "Index DDL generation received an unsupported SQL parameter value"
1117
- );
1118
- }
1119
- function escapeStringLiteral2(value) {
1120
- return `'${value.replaceAll("'", "''")}'`;
1121
- }
1122
- function buildPostgresNodeIndexBuilders(table, indexes) {
1123
- const nodeIndexes = indexes.filter(
1124
- (index) => index.entity === "node"
1125
- );
1126
- return nodeIndexes.map((index$1) => {
1127
- const propsColumn = sql`${table.props}`;
1128
- const systemColumn = (column) => sql`${getPostgresNodeSystemColumn(table, column)}`;
1129
- const { keys } = compileNodeIndexKeys(
1130
- index$1,
1131
- "postgres",
1132
- propsColumn,
1133
- systemColumn
1134
- );
1135
- assertNonEmpty(keys, `node index "${index$1.name}"`);
1136
- const base = index$1.unique ? uniqueIndex(index$1.name) : index(index$1.name);
1137
- const builder = base.on(...keys);
1138
- if (index$1.where) {
1139
- const ctx = {
1140
- dialect: "postgres",
1141
- propsColumn,
1142
- systemColumn
1143
- };
1144
- builder.where(compileIndexWhere(ctx, index$1.where));
1145
- }
1146
- return builder;
1147
- });
1148
- }
1149
- function buildPostgresEdgeIndexBuilders(table, indexes) {
1150
- const edgeIndexes = indexes.filter(
1151
- (index) => index.entity === "edge"
1152
- );
1153
- return edgeIndexes.map((index$1) => {
1154
- const propsColumn = sql`${table.props}`;
1155
- const systemColumn = (column) => sql`${getPostgresEdgeSystemColumn(table, column)}`;
1156
- const { keys } = compileEdgeIndexKeys(
1157
- index$1,
1158
- "postgres",
1159
- propsColumn,
1160
- systemColumn
1161
- );
1162
- assertNonEmpty(keys, `edge index "${index$1.name}"`);
1163
- const base = index$1.unique ? uniqueIndex(index$1.name) : index(index$1.name);
1164
- const builder = base.on(...keys);
1165
- if (index$1.where) {
1166
- const ctx = {
1167
- dialect: "postgres",
1168
- propsColumn,
1169
- systemColumn
1170
- };
1171
- builder.where(compileIndexWhere(ctx, index$1.where));
1172
- }
1173
- return builder;
1174
- });
1175
- }
1176
- function getPostgresNodeSystemColumn(table, column) {
1177
- switch (column) {
1178
- case "graph_id": {
1179
- return table.graphId;
1180
- }
1181
- case "kind": {
1182
- return table.kind;
1183
- }
1184
- case "id": {
1185
- return table.id;
1186
- }
1187
- case "from_kind":
1188
- case "from_id":
1189
- case "to_kind":
1190
- case "to_id": {
1191
- throw new Error(`Unsupported node system column for indexes: ${column}`);
1192
- }
1193
- case "deleted_at": {
1194
- return table.deletedAt;
1195
- }
1196
- case "valid_from": {
1197
- return table.validFrom;
1198
- }
1199
- case "valid_to": {
1200
- return table.validTo;
1201
- }
1202
- case "created_at": {
1203
- return table.createdAt;
1204
- }
1205
- case "updated_at": {
1206
- return table.updatedAt;
1207
- }
1208
- case "version": {
1209
- return table.version;
1210
- }
1211
- }
1212
- }
1213
- function getPostgresEdgeSystemColumn(table, column) {
1214
- switch (column) {
1215
- case "graph_id": {
1216
- return table.graphId;
1217
- }
1218
- case "kind": {
1219
- return table.kind;
1220
- }
1221
- case "id": {
1222
- return table.id;
1223
- }
1224
- case "from_kind": {
1225
- return table.fromKind;
1226
- }
1227
- case "from_id": {
1228
- return table.fromId;
1229
- }
1230
- case "to_kind": {
1231
- return table.toKind;
1232
- }
1233
- case "to_id": {
1234
- return table.toId;
1235
- }
1236
- case "deleted_at": {
1237
- return table.deletedAt;
1238
- }
1239
- case "valid_from": {
1240
- return table.validFrom;
1241
- }
1242
- case "valid_to": {
1243
- return table.validTo;
1244
- }
1245
- case "created_at": {
1246
- return table.createdAt;
1247
- }
1248
- case "updated_at": {
1249
- return table.updatedAt;
1250
- }
1251
- case "version": {
1252
- throw new Error(`Unsupported edge system column for indexes: ${column}`);
1253
- }
1254
- }
1255
- }
1256
- function buildSqliteNodeIndexBuilders(table, indexes) {
1257
- const nodeIndexes = indexes.filter(
1258
- (index) => index.entity === "node"
1259
- );
1260
- return nodeIndexes.map((index) => {
1261
- const propsColumn = sql`${table.props}`;
1262
- const systemColumn = (column) => sql`${getSqliteNodeSystemColumn(table, column)}`;
1263
- const { keys } = compileNodeIndexKeys(
1264
- index,
1265
- "sqlite",
1266
- propsColumn,
1267
- systemColumn
1268
- );
1269
- assertNonEmpty(keys, `node index "${index.name}"`);
1270
- const base = index.unique ? uniqueIndex$1(index.name) : index$1(index.name);
1271
- const builder = base.on(...keys);
1272
- if (index.where) {
1273
- const ctx = {
1274
- dialect: "sqlite",
1275
- propsColumn,
1276
- systemColumn
1277
- };
1278
- builder.where(compileIndexWhere(ctx, index.where));
1279
- }
1280
- return builder;
1281
- });
1282
- }
1283
- function buildSqliteEdgeIndexBuilders(table, indexes) {
1284
- const edgeIndexes = indexes.filter(
1285
- (index) => index.entity === "edge"
1286
- );
1287
- return edgeIndexes.map((index) => {
1288
- const propsColumn = sql`${table.props}`;
1289
- const systemColumn = (column) => sql`${getSqliteEdgeSystemColumn(table, column)}`;
1290
- const { keys } = compileEdgeIndexKeys(
1291
- index,
1292
- "sqlite",
1293
- propsColumn,
1294
- systemColumn
1295
- );
1296
- assertNonEmpty(keys, `edge index "${index.name}"`);
1297
- const base = index.unique ? uniqueIndex$1(index.name) : index$1(index.name);
1298
- const builder = base.on(...keys);
1299
- if (index.where) {
1300
- const ctx = {
1301
- dialect: "sqlite",
1302
- propsColumn,
1303
- systemColumn
1304
- };
1305
- builder.where(compileIndexWhere(ctx, index.where));
1306
- }
1307
- return builder;
1308
- });
1309
- }
1310
- function getSqliteNodeSystemColumn(table, column) {
1311
- switch (column) {
1312
- case "graph_id": {
1313
- return table.graphId;
1314
- }
1315
- case "kind": {
1316
- return table.kind;
1317
- }
1318
- case "id": {
1319
- return table.id;
1320
- }
1321
- case "from_kind":
1322
- case "from_id":
1323
- case "to_kind":
1324
- case "to_id": {
1325
- throw new Error(`Unsupported node system column for indexes: ${column}`);
1326
- }
1327
- case "deleted_at": {
1328
- return table.deletedAt;
1329
- }
1330
- case "valid_from": {
1331
- return table.validFrom;
1332
- }
1333
- case "valid_to": {
1334
- return table.validTo;
1335
- }
1336
- case "created_at": {
1337
- return table.createdAt;
1338
- }
1339
- case "updated_at": {
1340
- return table.updatedAt;
1341
- }
1342
- case "version": {
1343
- return table.version;
1344
- }
1345
- }
1346
- }
1347
- function getSqliteEdgeSystemColumn(table, column) {
1348
- switch (column) {
1349
- case "graph_id": {
1350
- return table.graphId;
1351
- }
1352
- case "kind": {
1353
- return table.kind;
1354
- }
1355
- case "id": {
1356
- return table.id;
1357
- }
1358
- case "from_kind": {
1359
- return table.fromKind;
1360
- }
1361
- case "from_id": {
1362
- return table.fromId;
1363
- }
1364
- case "to_kind": {
1365
- return table.toKind;
1366
- }
1367
- case "to_id": {
1368
- return table.toId;
1369
- }
1370
- case "deleted_at": {
1371
- return table.deletedAt;
1372
- }
1373
- case "valid_from": {
1374
- return table.validFrom;
1375
- }
1376
- case "valid_to": {
1377
- return table.validTo;
1378
- }
1379
- case "created_at": {
1380
- return table.createdAt;
1381
- }
1382
- case "updated_at": {
1383
- return table.updatedAt;
1384
- }
1385
- case "version": {
1386
- throw new Error(`Unsupported edge system column for indexes: ${column}`);
1387
- }
1388
- }
1389
- }
1390
- function assertNonEmpty(values, label) {
1391
- if (values.length === 0) {
1392
- throw new Error(`Index must have at least one key (${label})`);
1393
- }
1394
- }
1395
-
1396
- // src/indexes/profiler.ts
1397
- function toDeclaredIndex(index) {
1398
- return {
1399
- entityType: index.entity,
1400
- kind: index.kind,
1401
- fields: [...index.fields],
1402
- unique: index.unique,
1403
- name: index.name
1404
- };
1405
- }
1406
- function toDeclaredIndexes(indexes) {
1407
- return indexes.filter(
1408
- (index) => index.entity === "node" || index.entity === "edge"
1409
- ).map((index) => toDeclaredIndex(index));
1410
- }
1411
-
1412
- // src/indexes/where.ts
1413
- function andWhere(...predicates) {
1414
- if (predicates.length === 1) {
1415
- return predicates[0];
1416
- }
1417
- return {
1418
- __type: "index_where_and",
1419
- predicates
1420
- };
1421
- }
1422
- function orWhere(...predicates) {
1423
- if (predicates.length === 1) {
1424
- return predicates[0];
1425
- }
1426
- return {
1427
- __type: "index_where_or",
1428
- predicates
1429
- };
1430
- }
1431
- function notWhere(predicate) {
1432
- return {
1433
- __type: "index_where_not",
1434
- predicate
1435
- };
1436
- }
1437
-
1438
- export { BASE_CONTRIBUTION_OWNER, VECTOR_CONTRIBUTION_PREFIX, andWhere, assertFiniteEmbedding, assertVectorMinScore, assertVectorSearchLimit, buildFulltextCapabilities, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders, buildVectorCapabilities, compileIndexWhere, compileNodeIndexFieldKeys, edgeColumnList, fts5Strategy, generateEdgeIndexDDL, generateIndexDDL, generateNodeIndexDDL, getDialect, nodeColumnList, notWhere, orWhere, quoteIdentifier2 as quoteIdentifier, quotedColumn, quotedTableName, sqlNull, toDeclaredIndex, toDeclaredIndexes, tsvectorStrategy, vectorMinScoreCondition, vectorPhysicalName, vectorScoreExpression };
1439
- //# sourceMappingURL=chunk-AI3RNREM.js.map
1440
- //# sourceMappingURL=chunk-AI3RNREM.js.map
1036
+ export { BASE_CONTRIBUTION_OWNER, VECTOR_CONTRIBUTION_PREFIX, assertFiniteEmbedding, assertVectorMinScore, assertVectorSearchLimit, buildFulltextCapabilities, buildVectorCapabilities, compileEdgeIndexKeys, compileIndexWhere, compileNodeIndexFieldKeys, compileNodeIndexKeys, edgeColumnList, fts5Strategy, getDialect, nodeColumnList, quoteIdentifier2 as quoteIdentifier, quotedColumn, quotedTableName, sqlNull, tsvectorStrategy, vectorMinScoreCondition, vectorPhysicalName, vectorScoreExpression };
1037
+ //# sourceMappingURL=chunk-2HZGWCB4.js.map
1038
+ //# sourceMappingURL=chunk-2HZGWCB4.js.map