@nicia-ai/typegraph 0.38.0 → 0.40.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 (254) hide show
  1. package/dist/backend/drizzle/indexes.cjs +8 -10
  2. package/dist/backend/drizzle/indexes.d.cts +2 -2
  3. package/dist/backend/drizzle/indexes.d.ts +2 -2
  4. package/dist/backend/drizzle/indexes.js +4 -6
  5. package/dist/backend/index.cjs +60 -39
  6. package/dist/backend/index.d.cts +60 -1
  7. package/dist/backend/index.d.ts +60 -1
  8. package/dist/backend/index.js +12 -3
  9. package/dist/backend/postgres/index.cjs +25 -27
  10. package/dist/backend/postgres/index.d.cts +6 -6
  11. package/dist/backend/postgres/index.d.ts +6 -6
  12. package/dist/backend/postgres/index.js +12 -14
  13. package/dist/backend/postgres/pglite-store.cjs +26 -27
  14. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  15. package/dist/backend/postgres/pglite-store.d.cts +6 -5
  16. package/dist/backend/postgres/pglite-store.d.ts +6 -5
  17. package/dist/backend/postgres/pglite-store.js +22 -23
  18. package/dist/backend/postgres/pglite-store.js.map +1 -1
  19. package/dist/backend/postgres/pglite.cjs +14 -16
  20. package/dist/backend/postgres/pglite.d.cts +3 -3
  21. package/dist/backend/postgres/pglite.d.ts +3 -3
  22. package/dist/backend/postgres/pglite.js +13 -15
  23. package/dist/backend/sqlite/index.cjs +26 -28
  24. package/dist/backend/sqlite/index.d.cts +6 -6
  25. package/dist/backend/sqlite/index.d.ts +6 -6
  26. package/dist/backend/sqlite/index.js +10 -12
  27. package/dist/backend/sqlite/libsql.cjs +16 -18
  28. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  29. package/dist/backend/sqlite/libsql.d.cts +3 -3
  30. package/dist/backend/sqlite/libsql.d.ts +3 -3
  31. package/dist/backend/sqlite/libsql.js +15 -17
  32. package/dist/backend/sqlite/libsql.js.map +1 -1
  33. package/dist/backend/sqlite/local-store.cjs +27 -28
  34. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  35. package/dist/backend/sqlite/local-store.d.cts +6 -5
  36. package/dist/backend/sqlite/local-store.d.ts +6 -5
  37. package/dist/backend/sqlite/local-store.js +23 -24
  38. package/dist/backend/sqlite/local-store.js.map +1 -1
  39. package/dist/backend/sqlite/local.cjs +15 -17
  40. package/dist/backend/sqlite/local.d.cts +3 -3
  41. package/dist/backend/sqlite/local.d.ts +3 -3
  42. package/dist/backend/sqlite/local.js +13 -15
  43. package/dist/{chunk-U4JDJKPD.js → chunk-2I3DNNBU.js} +4 -4
  44. package/dist/{chunk-U4JDJKPD.js.map → chunk-2I3DNNBU.js.map} +1 -1
  45. package/dist/{chunk-NPWACFQJ.cjs → chunk-2J5NMMVR.cjs} +43 -43
  46. package/dist/{chunk-NPWACFQJ.cjs.map → chunk-2J5NMMVR.cjs.map} +1 -1
  47. package/dist/{chunk-NU23DUSJ.cjs → chunk-2X73QTIC.cjs} +12 -13
  48. package/dist/chunk-2X73QTIC.cjs.map +1 -0
  49. package/dist/{chunk-A2FGSWMQ.js → chunk-3BL3JFHL.js} +202 -52
  50. package/dist/chunk-3BL3JFHL.js.map +1 -0
  51. package/dist/chunk-3SHAUJRB.js +79 -0
  52. package/dist/chunk-3SHAUJRB.js.map +1 -0
  53. package/dist/{chunk-UPXDVI3T.js → chunk-53BSOG3O.js} +8 -7
  54. package/dist/chunk-53BSOG3O.js.map +1 -0
  55. package/dist/chunk-5J4VNCUD.js +856 -0
  56. package/dist/chunk-5J4VNCUD.js.map +1 -0
  57. package/dist/chunk-5YBDB7UG.cjs +12 -0
  58. package/dist/{chunk-FMNUSGZ4.cjs.map → chunk-5YBDB7UG.cjs.map} +1 -1
  59. package/dist/{chunk-6XDBRDZE.js → chunk-6N7QBIWN.js} +7 -3
  60. package/dist/chunk-6N7QBIWN.js.map +1 -0
  61. package/dist/{chunk-EZH7FNUS.js → chunk-6QP4QXBR.js} +3 -3
  62. package/dist/{chunk-EZH7FNUS.js.map → chunk-6QP4QXBR.js.map} +1 -1
  63. package/dist/{chunk-E6TXEISH.cjs → chunk-7UTUKH4E.cjs} +4 -4
  64. package/dist/{chunk-E6TXEISH.cjs.map → chunk-7UTUKH4E.cjs.map} +1 -1
  65. package/dist/chunk-7WLEQIHA.cjs +605 -0
  66. package/dist/chunk-7WLEQIHA.cjs.map +1 -0
  67. package/dist/{chunk-BQITNFQJ.js → chunk-AQVDAKXH.js} +3 -3
  68. package/dist/{chunk-BQITNFQJ.js.map → chunk-AQVDAKXH.js.map} +1 -1
  69. package/dist/{chunk-X6CNEA32.js → chunk-BUZWMDNL.js} +5 -5
  70. package/dist/{chunk-X6CNEA32.js.map → chunk-BUZWMDNL.js.map} +1 -1
  71. package/dist/{chunk-7M3NACL3.cjs → chunk-CKFBZ4LV.cjs} +4 -4
  72. package/dist/{chunk-7M3NACL3.cjs.map → chunk-CKFBZ4LV.cjs.map} +1 -1
  73. package/dist/{chunk-VBH7ZXSZ.js → chunk-CU3LPYNB.js} +5 -5
  74. package/dist/{chunk-VBH7ZXSZ.js.map → chunk-CU3LPYNB.js.map} +1 -1
  75. package/dist/{chunk-YJDSPA5E.js → chunk-EFZ4S22A.js} +11 -10
  76. package/dist/chunk-EFZ4S22A.js.map +1 -0
  77. package/dist/chunk-ELA3V6UN.js +601 -0
  78. package/dist/chunk-ELA3V6UN.js.map +1 -0
  79. package/dist/{chunk-2SL7OGPR.cjs → chunk-H6I36MGT.cjs} +1037 -887
  80. package/dist/chunk-H6I36MGT.cjs.map +1 -0
  81. package/dist/chunk-HAQVISUF.cjs +1098 -0
  82. package/dist/chunk-HAQVISUF.cjs.map +1 -0
  83. package/dist/{chunk-O5H62ZWJ.cjs → chunk-HP6LWBLB.cjs} +14 -2
  84. package/dist/chunk-HP6LWBLB.cjs.map +1 -0
  85. package/dist/{chunk-BKAKAVRW.cjs → chunk-HQRZEYYB.cjs} +44 -44
  86. package/dist/{chunk-BKAKAVRW.cjs.map → chunk-HQRZEYYB.cjs.map} +1 -1
  87. package/dist/{chunk-XD6X7O5R.js → chunk-I5CRUPKO.js} +9 -10
  88. package/dist/{chunk-XD6X7O5R.js.map → chunk-I5CRUPKO.js.map} +1 -1
  89. package/dist/{chunk-RQPRCEIO.js → chunk-JHK6NPFV.js} +218 -306
  90. package/dist/chunk-JHK6NPFV.js.map +1 -0
  91. package/dist/chunk-JZYMOHHM.cjs +226 -0
  92. package/dist/chunk-JZYMOHHM.cjs.map +1 -0
  93. package/dist/{chunk-CQC6VBAF.cjs → chunk-K4FB2RMO.cjs} +10 -10
  94. package/dist/{chunk-CQC6VBAF.cjs.map → chunk-K4FB2RMO.cjs.map} +1 -1
  95. package/dist/{chunk-ERZ4QPQX.js → chunk-K6CD6W5J.js} +5 -5
  96. package/dist/{chunk-ERZ4QPQX.js.map → chunk-K6CD6W5J.js.map} +1 -1
  97. package/dist/{chunk-LZ3TVJY4.cjs → chunk-KHNKYSGP.cjs} +34 -34
  98. package/dist/{chunk-LZ3TVJY4.cjs.map → chunk-KHNKYSGP.cjs.map} +1 -1
  99. package/dist/{chunk-CWX77JB4.cjs → chunk-KLR77R5A.cjs} +13 -13
  100. package/dist/{chunk-CWX77JB4.cjs.map → chunk-KLR77R5A.cjs.map} +1 -1
  101. package/dist/{chunk-AOL64O4Z.js → chunk-L3DDZUZP.js} +3 -3
  102. package/dist/{chunk-AOL64O4Z.js.map → chunk-L3DDZUZP.js.map} +1 -1
  103. package/dist/{chunk-PZHC5GCD.js → chunk-L5ET7FYQ.js} +3 -3
  104. package/dist/{chunk-PZHC5GCD.js.map → chunk-L5ET7FYQ.js.map} +1 -1
  105. package/dist/{chunk-B63IFHXR.cjs → chunk-LFFVD5ZR.cjs} +41 -41
  106. package/dist/{chunk-B63IFHXR.cjs.map → chunk-LFFVD5ZR.cjs.map} +1 -1
  107. package/dist/chunk-LL5D5T5W.cjs +157 -0
  108. package/dist/chunk-LL5D5T5W.cjs.map +1 -0
  109. package/dist/{chunk-GUUWKPTK.cjs → chunk-LLE25NRD.cjs} +7 -7
  110. package/dist/{chunk-GUUWKPTK.cjs.map → chunk-LLE25NRD.cjs.map} +1 -1
  111. package/dist/chunk-LLHMAHG4.cjs +886 -0
  112. package/dist/chunk-LLHMAHG4.cjs.map +1 -0
  113. package/dist/{chunk-ZHX4KEM7.cjs → chunk-M2RPZS7J.cjs} +10 -10
  114. package/dist/{chunk-ZHX4KEM7.cjs.map → chunk-M2RPZS7J.cjs.map} +1 -1
  115. package/dist/chunk-MNURF4RF.cjs +85 -0
  116. package/dist/chunk-MNURF4RF.cjs.map +1 -0
  117. package/dist/chunk-QOHTVDHU.js +144 -0
  118. package/dist/chunk-QOHTVDHU.js.map +1 -0
  119. package/dist/{chunk-7VLCN3JB.cjs → chunk-QXKVUJLI.cjs} +113 -112
  120. package/dist/chunk-QXKVUJLI.cjs.map +1 -0
  121. package/dist/{chunk-GNPGGLAE.cjs → chunk-QYDUCWD2.cjs} +4 -4
  122. package/dist/{chunk-GNPGGLAE.cjs.map → chunk-QYDUCWD2.cjs.map} +1 -1
  123. package/dist/{chunk-TE5ZA4VX.js → chunk-QZYGZVUI.js} +45 -41
  124. package/dist/chunk-QZYGZVUI.js.map +1 -0
  125. package/dist/{chunk-YLINFV7Z.cjs → chunk-SAMJLDGG.cjs} +114 -110
  126. package/dist/chunk-SAMJLDGG.cjs.map +1 -0
  127. package/dist/{chunk-DOVMTPKE.cjs → chunk-SE422RES.cjs} +27 -27
  128. package/dist/{chunk-DOVMTPKE.cjs.map → chunk-SE422RES.cjs.map} +1 -1
  129. package/dist/{chunk-NWYCOFEZ.cjs → chunk-UCHW2MGP.cjs} +332 -433
  130. package/dist/chunk-UCHW2MGP.cjs.map +1 -0
  131. package/dist/{chunk-XFY73JWD.cjs → chunk-UDS5DZNY.cjs} +498 -1098
  132. package/dist/chunk-UDS5DZNY.cjs.map +1 -0
  133. package/dist/{chunk-KFLXWVUJ.js → chunk-UUIBACKJ.js} +14 -3
  134. package/dist/chunk-UUIBACKJ.js.map +1 -0
  135. package/dist/{chunk-VDYA2HMS.js → chunk-VWEFXG73.js} +3 -3
  136. package/dist/{chunk-VDYA2HMS.js.map → chunk-VWEFXG73.js.map} +1 -1
  137. package/dist/{chunk-G32AO634.js → chunk-W66YCXWT.js} +464 -1048
  138. package/dist/chunk-W66YCXWT.js.map +1 -0
  139. package/dist/{chunk-E6YZRKMM.js → chunk-XMEYZYGE.js} +6 -6
  140. package/dist/{chunk-E6YZRKMM.js.map → chunk-XMEYZYGE.js.map} +1 -1
  141. package/dist/{chunk-G3CSQLLT.js → chunk-Y5UC3IXF.js} +461 -6
  142. package/dist/chunk-Y5UC3IXF.js.map +1 -0
  143. package/dist/{chunk-SDHV2MWU.js → chunk-YGX4PMG6.js} +5 -5
  144. package/dist/{chunk-SDHV2MWU.js.map → chunk-YGX4PMG6.js.map} +1 -1
  145. package/dist/{chunk-KCLZHYPU.cjs → chunk-YIX3BEBR.cjs} +86 -85
  146. package/dist/chunk-YIX3BEBR.cjs.map +1 -0
  147. package/dist/{chunk-X6RDQ5NB.cjs → chunk-YX3H63VV.cjs} +8 -2
  148. package/dist/chunk-YX3H63VV.cjs.map +1 -0
  149. package/dist/chunk-YYLMXERH.js +211 -0
  150. package/dist/chunk-YYLMXERH.js.map +1 -0
  151. package/dist/{chunk-6G5CQ6JX.js → chunk-ZE7E46IZ.js} +5 -5
  152. package/dist/{chunk-6G5CQ6JX.js.map → chunk-ZE7E46IZ.js.map} +1 -1
  153. package/dist/{chunk-Z2PPIVOO.js → chunk-ZVME6OSV.js} +5 -5
  154. package/dist/{chunk-Z2PPIVOO.js.map → chunk-ZVME6OSV.js.map} +1 -1
  155. package/dist/core/index.cjs +15 -3
  156. package/dist/core/index.d.cts +4 -3
  157. package/dist/core/index.d.ts +4 -3
  158. package/dist/core/index.js +2 -2
  159. package/dist/{ddl-Dx3Z0_WC.d.ts → ddl-BLEzHw6j.d.ts} +3 -3
  160. package/dist/{ddl-J6sDyABg.d.cts → ddl-KnCdF_le.d.cts} +3 -3
  161. package/dist/{define-graph-CzEvA_8F.d.cts → define-graph-Cv3CFwKm.d.cts} +1 -1
  162. package/dist/{define-graph-DRo9xpYN.d.ts → define-graph-DQnj3fNH.d.ts} +1 -1
  163. package/dist/graph-merge/index.cjs +40 -43
  164. package/dist/graph-merge/index.cjs.map +1 -1
  165. package/dist/graph-merge/index.d.cts +15 -9
  166. package/dist/graph-merge/index.d.ts +15 -9
  167. package/dist/graph-merge/index.js +19 -22
  168. package/dist/graph-merge/index.js.map +1 -1
  169. package/dist/index.cjs +143 -119
  170. package/dist/index.d.cts +12 -10
  171. package/dist/index.d.ts +12 -10
  172. package/dist/index.js +23 -23
  173. package/dist/indexes/index.cjs +12 -14
  174. package/dist/indexes/index.d.cts +5 -5
  175. package/dist/indexes/index.d.ts +5 -5
  176. package/dist/indexes/index.js +5 -7
  177. package/dist/interchange/index.cjs +29 -30
  178. package/dist/interchange/index.cjs.map +1 -1
  179. package/dist/interchange/index.d.cts +6 -5
  180. package/dist/interchange/index.d.ts +6 -5
  181. package/dist/interchange/index.js +10 -11
  182. package/dist/interchange/index.js.map +1 -1
  183. package/dist/{manager-CASfhmzV.d.ts → manager-DjE6Mhag.d.ts} +2 -2
  184. package/dist/{manager-nCEJiYBb.d.cts → manager-mqee5MVB.d.cts} +2 -2
  185. package/dist/{postgres-DMgIKQU-.d.cts → postgres-Bm4DyFQU.d.cts} +100 -49
  186. package/dist/{postgres-Cl1ZAN1G.d.ts → postgres-DtaVALOZ.d.ts} +100 -49
  187. package/dist/profiler/index.d.cts +8 -7
  188. package/dist/profiler/index.d.ts +8 -7
  189. package/dist/provenance/index.cjs +20 -20
  190. package/dist/provenance/index.d.cts +6 -5
  191. package/dist/provenance/index.d.ts +6 -5
  192. package/dist/provenance/index.js +7 -7
  193. package/dist/schema/index.cjs +26 -28
  194. package/dist/schema/index.cjs.map +1 -1
  195. package/dist/schema/index.d.cts +5 -5
  196. package/dist/schema/index.d.ts +5 -5
  197. package/dist/schema/index.js +7 -9
  198. package/dist/schema/index.js.map +1 -1
  199. package/dist/{temporal-DqtOEo_B.d.ts → searchable-BxlJQVFw.d.cts} +3 -58
  200. package/dist/{temporal-BC_NQV5Y.d.cts → searchable-ChJ29MCd.d.ts} +3 -58
  201. package/dist/{sqlite-BDkW39aa.d.cts → sqlite-DT6tTHOG.d.cts} +124 -97
  202. package/dist/{sqlite-CYfhvESj.d.ts → sqlite-m9Izphk_.d.ts} +124 -97
  203. package/dist/{store-view-BoHqdHjB.d.cts → store-view-C-buB8Q8.d.cts} +46 -31
  204. package/dist/{store-view-Ctq-3OHy.d.ts → store-view-CagdeyNn.d.ts} +46 -31
  205. package/dist/temporal-CyFsSPe8.d.ts +73 -0
  206. package/dist/temporal-Dn_JADWY.d.cts +73 -0
  207. package/dist/{types-CUevi_D1.d.ts → types-CYdXzZef.d.ts} +1 -1
  208. package/dist/{types-COq3-vMC.d.cts → types-CqSfMRW3.d.cts} +1 -1
  209. package/dist/{where-C92TXCzT.d.cts → where-C3-HRgUq.d.cts} +1 -1
  210. package/dist/{where-BdE_cYtx.d.ts → where-sQL4u5h-.d.ts} +1 -1
  211. package/package.json +1 -1
  212. package/dist/chunk-2SL7OGPR.cjs.map +0 -1
  213. package/dist/chunk-6XDBRDZE.js.map +0 -1
  214. package/dist/chunk-7VLCN3JB.cjs.map +0 -1
  215. package/dist/chunk-A2FGSWMQ.js.map +0 -1
  216. package/dist/chunk-DDCIXXOO.js +0 -9
  217. package/dist/chunk-DDCIXXOO.js.map +0 -1
  218. package/dist/chunk-DDCYVIVV.cjs +0 -44
  219. package/dist/chunk-DDCYVIVV.cjs.map +0 -1
  220. package/dist/chunk-EOJFGECD.cjs +0 -284
  221. package/dist/chunk-EOJFGECD.cjs.map +0 -1
  222. package/dist/chunk-FMNUSGZ4.cjs +0 -12
  223. package/dist/chunk-G32AO634.js.map +0 -1
  224. package/dist/chunk-G3CSQLLT.js.map +0 -1
  225. package/dist/chunk-I6FX7AAG.js +0 -39
  226. package/dist/chunk-I6FX7AAG.js.map +0 -1
  227. package/dist/chunk-J6IJARLG.js +0 -94
  228. package/dist/chunk-J6IJARLG.js.map +0 -1
  229. package/dist/chunk-KCLZHYPU.cjs.map +0 -1
  230. package/dist/chunk-KFLXWVUJ.js.map +0 -1
  231. package/dist/chunk-MTNEGGM2.js +0 -273
  232. package/dist/chunk-MTNEGGM2.js.map +0 -1
  233. package/dist/chunk-NU23DUSJ.cjs.map +0 -1
  234. package/dist/chunk-NWYCOFEZ.cjs.map +0 -1
  235. package/dist/chunk-O5H62ZWJ.cjs.map +0 -1
  236. package/dist/chunk-RQPRCEIO.js.map +0 -1
  237. package/dist/chunk-SVUKGWSN.cjs +0 -102
  238. package/dist/chunk-SVUKGWSN.cjs.map +0 -1
  239. package/dist/chunk-TE5ZA4VX.js.map +0 -1
  240. package/dist/chunk-UH2USOMG.cjs +0 -627
  241. package/dist/chunk-UH2USOMG.cjs.map +0 -1
  242. package/dist/chunk-UPXDVI3T.js.map +0 -1
  243. package/dist/chunk-X6RDQ5NB.cjs.map +0 -1
  244. package/dist/chunk-XFY73JWD.cjs.map +0 -1
  245. package/dist/chunk-Y7M44XEK.js +0 -462
  246. package/dist/chunk-Y7M44XEK.js.map +0 -1
  247. package/dist/chunk-YJDSPA5E.js.map +0 -1
  248. package/dist/chunk-YLINFV7Z.cjs.map +0 -1
  249. package/dist/chunk-Z5QHVL5U.cjs +0 -12
  250. package/dist/chunk-Z5QHVL5U.cjs.map +0 -1
  251. package/dist/chunk-ZKZAIX42.cjs +0 -479
  252. package/dist/chunk-ZKZAIX42.cjs.map +0 -1
  253. package/dist/{index-CrFL_ENI.d.cts → types-C5pZeKTl.d.cts} +1 -1
  254. package/dist/{index-Bq7vSPHy.d.ts → types-D8szWDUo.d.ts} +1 -1
@@ -1,8 +1,463 @@
1
- import { likeEscapeClause } from './chunk-DDCIXXOO.js';
2
- import { tsvectorStrategy, fts5Strategy } from './chunk-Y7M44XEK.js';
3
- import { sql, getSqlDialectProfile, inlineSqlStringLiteral } from './chunk-6XDBRDZE.js';
1
+ import { sql, getSqlDialectProfile, likeEscapeClause, inlineSqlStringLiteral } from './chunk-6N7QBIWN.js';
2
+ import { requireDefined } from './chunk-QMQLUA66.js';
4
3
  import { jsonPointer, parseJsonPointer } from './chunk-G6Q5UM7U.js';
5
4
 
5
+ // src/backend/table-contribution.ts
6
+ var FULLTEXT_CONTRIBUTION_NAME = "fulltext";
7
+ var BASE_CONTRIBUTION_OWNER = "base";
8
+
9
+ // src/query/dialect/fulltext-strategy.ts
10
+ var ALL_FULLTEXT_MODES = [
11
+ "websearch",
12
+ "phrase",
13
+ "plain",
14
+ "raw"
15
+ ];
16
+ function buildFulltextCapabilities(strategy) {
17
+ return {
18
+ supported: true,
19
+ languages: strategy.languages,
20
+ phraseQueries: strategy.supportedModes.includes("phrase"),
21
+ prefixQueries: strategy.supportsPrefix,
22
+ highlighting: strategy.supportsSnippets
23
+ };
24
+ }
25
+ function quoteIdentifier(name) {
26
+ return `"${name.replaceAll('"', '""')}"`;
27
+ }
28
+ function tsvectorColumn(tableName) {
29
+ return sql`${sql.identifier(tableName)}."tsv"`;
30
+ }
31
+ function dedupeFulltextBatchRows(rows) {
32
+ const seen = /* @__PURE__ */ new Map();
33
+ for (const row of rows) seen.set(row.nodeId, row);
34
+ return [...seen.values()];
35
+ }
36
+ function buildPkScopedDelete(tableName, params) {
37
+ const table = sql.identifier(tableName);
38
+ return sql`
39
+ DELETE FROM ${table}
40
+ WHERE "graph_id" = ${params.graphId}
41
+ AND "node_kind" = ${params.nodeKind}
42
+ AND "node_id" = ${params.nodeId}
43
+ `;
44
+ }
45
+ function buildPkScopedBatchDelete(tableName, params) {
46
+ if (params.nodeIds.length === 0) return void 0;
47
+ const unique = [...new Set(params.nodeIds)];
48
+ const table = sql.identifier(tableName);
49
+ return sql`
50
+ DELETE FROM ${table}
51
+ WHERE "graph_id" = ${params.graphId}
52
+ AND "node_kind" = ${params.nodeKind}
53
+ AND "node_id" IN (${sql.join(
54
+ unique.map((id) => sql`${id}`),
55
+ sql`, `
56
+ )})
57
+ `;
58
+ }
59
+ function postgresTsquery(mode, query, language) {
60
+ const langExpr = language === void 0 ? sql`"language"` : sql`${language}::regconfig`;
61
+ switch (mode) {
62
+ case "websearch": {
63
+ return sql`websearch_to_tsquery(${langExpr}, ${query})`;
64
+ }
65
+ case "phrase": {
66
+ return sql`phraseto_tsquery(${langExpr}, ${query})`;
67
+ }
68
+ case "plain": {
69
+ return sql`plainto_tsquery(${langExpr}, ${query})`;
70
+ }
71
+ case "raw": {
72
+ return sql`to_tsquery(${langExpr}, ${query})`;
73
+ }
74
+ default: {
75
+ const _exhaustive = mode;
76
+ throw new Error(`Unsupported fulltext mode: ${String(_exhaustive)}`);
77
+ }
78
+ }
79
+ }
80
+ var tsvectorStrategy = {
81
+ name: "tsvector",
82
+ supportedModes: ALL_FULLTEXT_MODES,
83
+ supportsSnippets: true,
84
+ // `raw` mode exposes `foo:*` prefix-match syntax to callers.
85
+ supportsPrefix: true,
86
+ supportsLanguageOverride: true,
87
+ // Canonical Postgres stemmers; every stock install ships these plus a
88
+ // few others. Runtime `to_tsvector` accepts any installed regconfig
89
+ // name — this list is advisory for capability discovery.
90
+ languages: [
91
+ "simple",
92
+ "english",
93
+ "french",
94
+ "german",
95
+ "italian",
96
+ "portuguese",
97
+ "russian",
98
+ "spanish",
99
+ "swedish"
100
+ ],
101
+ matchCondition(tableName, query, mode, language) {
102
+ const q = postgresTsquery(mode, query, language);
103
+ return sql`${tsvectorColumn(tableName)} @@ ${q}`;
104
+ },
105
+ rankExpression(tableName, query, mode, language) {
106
+ const q = postgresTsquery(mode, query, language);
107
+ return sql`ts_rank_cd(${tsvectorColumn(tableName)}, ${q})`;
108
+ },
109
+ snippetExpression(_tableName, query, mode, language) {
110
+ const langExpr = language === void 0 ? sql`"language"` : sql`${language}::regconfig`;
111
+ const q = postgresTsquery(mode, query, language);
112
+ return sql`ts_headline(${langExpr}, "content", ${q}, 'StartSel=<mark>,StopSel=</mark>,MaxFragments=1,MinWords=5,MaxWords=30,ShortWord=3')`;
113
+ },
114
+ ownedTables(primaryTableName) {
115
+ const name = quoteIdentifier(primaryTableName);
116
+ const gin = quoteIdentifier(`${primaryTableName}_tsv_idx`);
117
+ const kind = quoteIdentifier(`${primaryTableName}_kind_idx`);
118
+ const createDdl = [
119
+ `CREATE TABLE IF NOT EXISTS ${name} (
120
+ "graph_id" TEXT NOT NULL,
121
+ "node_kind" TEXT NOT NULL,
122
+ "node_id" TEXT NOT NULL,
123
+ "content" TEXT NOT NULL,
124
+ "language" regconfig NOT NULL,
125
+ "tsv" tsvector NOT NULL
126
+ GENERATED ALWAYS AS (to_tsvector("language", "content")) STORED,
127
+ "updated_at" TIMESTAMPTZ NOT NULL,
128
+ PRIMARY KEY ("graph_id", "node_kind", "node_id")
129
+ );`,
130
+ `CREATE INDEX IF NOT EXISTS ${gin} ON ${name} USING GIN ("tsv");`,
131
+ `CREATE INDEX IF NOT EXISTS ${kind} ON ${name} ("graph_id", "node_kind");`
132
+ ];
133
+ return [
134
+ {
135
+ logicalName: FULLTEXT_CONTRIBUTION_NAME,
136
+ owner: "tsvector",
137
+ tableName: primaryTableName,
138
+ createDdl,
139
+ runtimeEnsure: true
140
+ }
141
+ ];
142
+ },
143
+ buildUpsert(tableName, params, timestamp) {
144
+ const table = sql.identifier(tableName);
145
+ return [
146
+ sql`
147
+ INSERT INTO ${table} ("graph_id", "node_kind", "node_id", "content", "language", "updated_at")
148
+ VALUES (
149
+ ${params.graphId}, ${params.nodeKind}, ${params.nodeId},
150
+ ${params.content}, ${params.language}::regconfig,
151
+ ${timestamp}
152
+ )
153
+ ON CONFLICT ("graph_id", "node_kind", "node_id")
154
+ DO UPDATE SET
155
+ "content" = EXCLUDED."content",
156
+ "language" = EXCLUDED."language",
157
+ "updated_at" = EXCLUDED."updated_at"
158
+ `
159
+ ];
160
+ },
161
+ buildBatchUpsert(tableName, params, timestamp) {
162
+ const rows = dedupeFulltextBatchRows(params.rows);
163
+ if (rows.length === 0) return [];
164
+ const table = sql.identifier(tableName);
165
+ const valueTuples = rows.map(
166
+ (row) => sql`
167
+ (
168
+ ${params.graphId}, ${params.nodeKind}, ${row.nodeId},
169
+ ${row.content}, ${row.language}::regconfig,
170
+ ${timestamp}
171
+ )
172
+ `
173
+ );
174
+ return [
175
+ sql`
176
+ INSERT INTO ${table} ("graph_id", "node_kind", "node_id", "content", "language", "updated_at")
177
+ VALUES ${sql.join(valueTuples, sql`, `)}
178
+ ON CONFLICT ("graph_id", "node_kind", "node_id")
179
+ DO UPDATE SET
180
+ "content" = EXCLUDED."content",
181
+ "language" = EXCLUDED."language",
182
+ "updated_at" = EXCLUDED."updated_at"
183
+ `
184
+ ];
185
+ },
186
+ buildDelete(tableName, params) {
187
+ return [buildPkScopedDelete(tableName, params)];
188
+ },
189
+ buildBatchDelete(tableName, params) {
190
+ const stmt = buildPkScopedBatchDelete(tableName, params);
191
+ return stmt === void 0 ? [] : [stmt];
192
+ }
193
+ };
194
+ function translateToFts5Query(query, mode) {
195
+ switch (mode) {
196
+ case "phrase": {
197
+ return `"${query.replaceAll('"', '""')}"`;
198
+ }
199
+ case "plain": {
200
+ return query.trim().split(/\s+/u).filter((token) => token.length > 0).map((token) => `"${token.replaceAll('"', '""')}"`).join(" ");
201
+ }
202
+ case "websearch": {
203
+ return translateWebsearchToFts5(query);
204
+ }
205
+ case "raw": {
206
+ return query;
207
+ }
208
+ default: {
209
+ const _exhaustive = mode;
210
+ throw new Error(`Unsupported fulltext mode: ${String(_exhaustive)}`);
211
+ }
212
+ }
213
+ }
214
+ function translateWebsearchToFts5(query) {
215
+ const tokens = [];
216
+ let index = 0;
217
+ function skipWhitespace() {
218
+ while (index < query.length && /\s/u.test(query[index] ?? "")) {
219
+ index += 1;
220
+ }
221
+ }
222
+ function readPhrase() {
223
+ index += 1;
224
+ let content = "";
225
+ while (index < query.length && query[index] !== '"') {
226
+ content += query[index] ?? "";
227
+ index += 1;
228
+ }
229
+ if (query[index] === '"') index += 1;
230
+ return `"${content.replaceAll('"', '""')}"`;
231
+ }
232
+ function readBareTerm() {
233
+ let term = "";
234
+ while (index < query.length && !/\s/u.test(query[index] ?? "")) {
235
+ term += query[index] ?? "";
236
+ index += 1;
237
+ }
238
+ return term;
239
+ }
240
+ while (index < query.length) {
241
+ skipWhitespace();
242
+ if (index >= query.length) break;
243
+ const ch = query[index];
244
+ if (ch === '"') {
245
+ tokens.push(readPhrase());
246
+ continue;
247
+ }
248
+ if (ch === "-") {
249
+ index += 1;
250
+ const term = query[index] === '"' ? readPhrase() : `"${readBareTerm().replaceAll('"', '""')}"`;
251
+ tokens.push(`NOT ${term}`);
252
+ continue;
253
+ }
254
+ if (ch === "+") {
255
+ index += 1;
256
+ continue;
257
+ }
258
+ const bare = readBareTerm();
259
+ if (bare.length === 0) continue;
260
+ if (bare.toUpperCase() === "OR") {
261
+ tokens.push("OR");
262
+ continue;
263
+ }
264
+ tokens.push(`"${bare.replaceAll('"', '""')}"`);
265
+ }
266
+ if (tokens.length > 0 && tokens[0]?.startsWith("NOT ")) {
267
+ tokens.shift();
268
+ }
269
+ return tokens.join(" ");
270
+ }
271
+ var fts5Strategy = {
272
+ name: "fts5",
273
+ supportedModes: ALL_FULLTEXT_MODES,
274
+ supportsSnippets: true,
275
+ // FTS5 supports `foo*` prefix matching natively.
276
+ supportsPrefix: true,
277
+ // FTS5 tokenizer is fixed at table-create time; per-row / per-query
278
+ // language metadata is stored but not consulted.
279
+ supportsLanguageOverride: false,
280
+ // The built-in tokenizer is `porter unicode61 remove_diacritics 2`; the
281
+ // `language` field on searchable() is recorded for future use but not
282
+ // applied at query time.
283
+ languages: ["porter", "unicode61", "trigram"],
284
+ matchCondition(tableName, query, mode, _language) {
285
+ const matchExpression = translateToFts5Query(query, mode);
286
+ return sql`${sql.identifier(tableName)} MATCH ${matchExpression}`;
287
+ },
288
+ rankExpression(tableName, _query, _mode, _language) {
289
+ return sql`-bm25(${sql.identifier(tableName)})`;
290
+ },
291
+ snippetExpression(tableName, _query, _mode, _language) {
292
+ return sql`snippet(${sql.identifier(tableName)}, -1, '<mark>', '</mark>', '…', 20)`;
293
+ },
294
+ ownedTables(primaryTableName) {
295
+ const name = quoteIdentifier(primaryTableName);
296
+ return [
297
+ {
298
+ logicalName: FULLTEXT_CONTRIBUTION_NAME,
299
+ owner: "fts5",
300
+ tableName: primaryTableName,
301
+ createDdl: [
302
+ `CREATE VIRTUAL TABLE IF NOT EXISTS ${name} USING fts5(
303
+ graph_id UNINDEXED,
304
+ node_kind UNINDEXED,
305
+ node_id UNINDEXED,
306
+ language UNINDEXED,
307
+ updated_at UNINDEXED,
308
+ content,
309
+ tokenize='porter unicode61 remove_diacritics 2'
310
+ );`
311
+ ],
312
+ runtimeEnsure: true
313
+ }
314
+ ];
315
+ },
316
+ buildUpsert(tableName, params, timestamp) {
317
+ const table = sql.identifier(tableName);
318
+ return [
319
+ sql`
320
+ DELETE FROM ${table}
321
+ WHERE "graph_id" = ${params.graphId}
322
+ AND "node_kind" = ${params.nodeKind}
323
+ AND "node_id" = ${params.nodeId}
324
+ `,
325
+ sql`
326
+ INSERT INTO ${table} (graph_id, node_kind, node_id, content, language, updated_at)
327
+ VALUES (${params.graphId}, ${params.nodeKind}, ${params.nodeId}, ${params.content}, ${params.language}, ${timestamp})
328
+ `
329
+ ];
330
+ },
331
+ buildBatchUpsert(tableName, params, timestamp) {
332
+ const rows = dedupeFulltextBatchRows(params.rows);
333
+ if (rows.length === 0) return [];
334
+ const table = sql.identifier(tableName);
335
+ const nodeIds = rows.map((row) => row.nodeId);
336
+ const deleteStmt = sql`
337
+ DELETE FROM ${table}
338
+ WHERE "graph_id" = ${params.graphId}
339
+ AND "node_kind" = ${params.nodeKind}
340
+ AND "node_id" IN (${sql.join(
341
+ nodeIds.map((id) => sql`${id}`),
342
+ sql`, `
343
+ )})
344
+ `;
345
+ const valueTuples = rows.map(
346
+ (row) => sql`
347
+ (
348
+ ${params.graphId}, ${params.nodeKind}, ${row.nodeId},
349
+ ${row.content}, ${row.language}, ${timestamp}
350
+ )
351
+ `
352
+ );
353
+ const insertStmt = sql`
354
+ INSERT INTO ${table} (graph_id, node_kind, node_id, content, language, updated_at)
355
+ VALUES ${sql.join(valueTuples, sql`, `)}
356
+ `;
357
+ return [deleteStmt, insertStmt];
358
+ },
359
+ buildDelete(tableName, params) {
360
+ return [buildPkScopedDelete(tableName, params)];
361
+ },
362
+ buildBatchDelete(tableName, params) {
363
+ const stmt = buildPkScopedBatchDelete(tableName, params);
364
+ return stmt === void 0 ? [] : [stmt];
365
+ }
366
+ };
367
+
368
+ // src/query/dialect/vector-strategy.ts
369
+ var VECTOR_CONTRIBUTION_PREFIX = "vector";
370
+ function buildVectorCapabilities(strategy) {
371
+ return strategy.capabilities;
372
+ }
373
+ function vectorScoreExpression(distanceExpression, metric) {
374
+ switch (metric) {
375
+ case "cosine": {
376
+ return sql`(1 - (${distanceExpression}))`;
377
+ }
378
+ case "l2":
379
+ case "inner_product": {
380
+ return distanceExpression;
381
+ }
382
+ default: {
383
+ const _exhaustive = metric;
384
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
385
+ }
386
+ }
387
+ }
388
+ function vectorMinScoreCondition(distanceExpression, metric, minScore) {
389
+ assertVectorMinScore(minScore, metric);
390
+ switch (metric) {
391
+ case "cosine": {
392
+ return sql`${distanceExpression} <= ${1 - minScore}`;
393
+ }
394
+ case "l2": {
395
+ return sql`${distanceExpression} <= ${minScore}`;
396
+ }
397
+ case "inner_product": {
398
+ return sql`${distanceExpression} <= ${-minScore}`;
399
+ }
400
+ default: {
401
+ const _exhaustive = metric;
402
+ throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
403
+ }
404
+ }
405
+ }
406
+ function assertFiniteEmbedding(embedding, name) {
407
+ for (const [index, value] of embedding.entries()) {
408
+ if (typeof value !== "number" || !Number.isFinite(value)) {
409
+ throw new TypeError(
410
+ `${name}[${index}] must be a finite number, got: ${value}`
411
+ );
412
+ }
413
+ }
414
+ }
415
+ function assertVectorSearchLimit(limit) {
416
+ if (!Number.isInteger(limit) || limit <= 0) {
417
+ throw new RangeError(
418
+ `vectorSearch limit must be a positive integer, got: ${limit}`
419
+ );
420
+ }
421
+ }
422
+ function assertVectorMinScore(minScore, metric, label = "minScore") {
423
+ if (!Number.isFinite(minScore)) {
424
+ throw new RangeError(`${label} must be a finite number, got: ${minScore}`);
425
+ }
426
+ if (metric === "cosine" && Math.abs(minScore) > 1) {
427
+ throw new RangeError(
428
+ `${label} for the cosine metric must be between -1 and 1, got: ${minScore}`
429
+ );
430
+ }
431
+ }
432
+ var MAX_VECTOR_IDENTIFIER_LENGTH = 63;
433
+ function sanitizeIdentifierPart(value) {
434
+ return value.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
435
+ }
436
+ function shortHash(input) {
437
+ let h1 = 3735928559;
438
+ let h2 = 1103547991;
439
+ for (let index = 0; index < input.length; index++) {
440
+ const ch = requireDefined(input.codePointAt(index));
441
+ h1 = Math.imul(h1 ^ ch, 2654435761);
442
+ h2 = Math.imul(h2 ^ ch, 1597334677);
443
+ }
444
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
445
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
446
+ const hi = (h2 >>> 0).toString(16).padStart(8, "0");
447
+ const lo = (h1 >>> 0).toString(16).padStart(8, "0");
448
+ return `${hi}${lo}`.slice(0, 8);
449
+ }
450
+ function vectorPhysicalName(prefix, graphId, nodeKind, fieldPath) {
451
+ const readable = `${prefix}_${sanitizeIdentifierPart(graphId)}_${sanitizeIdentifierPart(nodeKind)}_${sanitizeIdentifierPart(fieldPath)}`;
452
+ const hash = shortHash(JSON.stringify([graphId, nodeKind, fieldPath]));
453
+ const full = `${readable}_${hash}`;
454
+ if (full.length <= MAX_VECTOR_IDENTIFIER_LENGTH) return full;
455
+ return `${readable.slice(0, MAX_VECTOR_IDENTIFIER_LENGTH - 1 - hash.length)}_${hash}`;
456
+ }
457
+ function quoteIdentifier2(name) {
458
+ return `"${name.replaceAll('"', '""')}"`;
459
+ }
460
+
6
461
  // src/query/dialect/postgres.ts
7
462
  function toPostgresPath(pointer) {
8
463
  if (!pointer || pointer === "" || pointer === "/") {
@@ -615,6 +1070,6 @@ function escapeStringLiteral(value) {
615
1070
  return `'${value.replaceAll("'", "''")}'`;
616
1071
  }
617
1072
 
618
- export { compileEdgeIndexKeys, compileIndexWhere, compileNodeIndexFieldKeys, compileNodeIndexKeys, getDialect, getNodeScopeColumns };
619
- //# sourceMappingURL=chunk-G3CSQLLT.js.map
620
- //# sourceMappingURL=chunk-G3CSQLLT.js.map
1073
+ export { ALL_FULLTEXT_MODES, BASE_CONTRIBUTION_OWNER, FULLTEXT_CONTRIBUTION_NAME, VECTOR_CONTRIBUTION_PREFIX, assertFiniteEmbedding, assertVectorMinScore, assertVectorSearchLimit, buildFulltextCapabilities, buildVectorCapabilities, compileEdgeIndexKeys, compileIndexWhere, compileNodeIndexFieldKeys, compileNodeIndexKeys, fts5Strategy, getDialect, getNodeScopeColumns, quoteIdentifier2 as quoteIdentifier, shortHash, tsvectorStrategy, vectorMinScoreCondition, vectorPhysicalName, vectorScoreExpression };
1074
+ //# sourceMappingURL=chunk-Y5UC3IXF.js.map
1075
+ //# sourceMappingURL=chunk-Y5UC3IXF.js.map