@nicia-ai/typegraph 0.50.0 → 0.51.1

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 (326) hide show
  1. package/README.md +12 -0
  2. package/dist/backend/drizzle/indexes.cjs +10 -8
  3. package/dist/backend/drizzle/indexes.d.cts +1 -1
  4. package/dist/backend/drizzle/indexes.d.ts +1 -1
  5. package/dist/backend/drizzle/indexes.js +6 -4
  6. package/dist/backend/index.cjs +183 -50
  7. package/dist/backend/index.d.cts +90 -4
  8. package/dist/backend/index.d.ts +90 -4
  9. package/dist/backend/index.js +6 -9
  10. package/dist/backend/postgres/index.cjs +30 -28
  11. package/dist/backend/postgres/index.d.cts +7 -7
  12. package/dist/backend/postgres/index.d.ts +7 -7
  13. package/dist/backend/postgres/index.js +16 -14
  14. package/dist/backend/postgres/pglite-store.cjs +6 -62
  15. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  16. package/dist/backend/postgres/pglite-store.d.cts +8 -8
  17. package/dist/backend/postgres/pglite-store.d.ts +8 -8
  18. package/dist/backend/postgres/pglite-store.js +6 -62
  19. package/dist/backend/postgres/pglite-store.js.map +1 -1
  20. package/dist/backend/postgres/pglite.cjs +18 -16
  21. package/dist/backend/postgres/pglite.d.cts +3 -3
  22. package/dist/backend/postgres/pglite.d.ts +3 -3
  23. package/dist/backend/postgres/pglite.js +17 -15
  24. package/dist/backend/sqlite/index.cjs +27 -25
  25. package/dist/backend/sqlite/index.d.cts +7 -7
  26. package/dist/backend/sqlite/index.d.ts +7 -7
  27. package/dist/backend/sqlite/index.js +14 -12
  28. package/dist/backend/sqlite/libsql.cjs +21 -19
  29. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  30. package/dist/backend/sqlite/libsql.d.cts +3 -3
  31. package/dist/backend/sqlite/libsql.d.ts +3 -3
  32. package/dist/backend/sqlite/libsql.js +16 -14
  33. package/dist/backend/sqlite/libsql.js.map +1 -1
  34. package/dist/backend/sqlite/local-store.cjs +8 -64
  35. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  36. package/dist/backend/sqlite/local-store.d.cts +8 -8
  37. package/dist/backend/sqlite/local-store.d.ts +8 -8
  38. package/dist/backend/sqlite/local-store.js +7 -64
  39. package/dist/backend/sqlite/local-store.js.map +1 -1
  40. package/dist/backend/sqlite/local.cjs +22 -19
  41. package/dist/backend/sqlite/local.d.cts +3 -3
  42. package/dist/backend/sqlite/local.d.ts +3 -3
  43. package/dist/backend/sqlite/local.js +18 -15
  44. package/dist/{chunk-TUVD4DFR.cjs → chunk-2CVDZCXH.cjs} +122 -51
  45. package/dist/chunk-2CVDZCXH.cjs.map +1 -0
  46. package/dist/{chunk-I5C6OTKR.js → chunk-2DWTBNSH.js} +3 -3
  47. package/dist/{chunk-I5C6OTKR.js.map → chunk-2DWTBNSH.js.map} +1 -1
  48. package/dist/{chunk-C76WFIVZ.cjs → chunk-2KCTP3U2.cjs} +180 -127
  49. package/dist/chunk-2KCTP3U2.cjs.map +1 -0
  50. package/dist/{chunk-BYBDM423.cjs → chunk-322TBTOQ.cjs} +48 -48
  51. package/dist/{chunk-BYBDM423.cjs.map → chunk-322TBTOQ.cjs.map} +1 -1
  52. package/dist/chunk-36SX6QXP.cjs +186 -0
  53. package/dist/chunk-36SX6QXP.cjs.map +1 -0
  54. package/dist/{chunk-H3XP6BAV.js → chunk-36VYWVQU.js} +3 -3
  55. package/dist/{chunk-H3XP6BAV.js.map → chunk-36VYWVQU.js.map} +1 -1
  56. package/dist/{chunk-VTJVMP4I.js → chunk-4DKY6RIU.js} +102 -31
  57. package/dist/chunk-4DKY6RIU.js.map +1 -0
  58. package/dist/chunk-4QKOZYMV.js +9 -0
  59. package/dist/chunk-4QKOZYMV.js.map +1 -0
  60. package/dist/{chunk-U3Z7XKAG.js → chunk-57JM6NW3.js} +8 -18
  61. package/dist/chunk-57JM6NW3.js.map +1 -0
  62. package/dist/{chunk-WCLMKNQE.cjs → chunk-5FVZSE3B.cjs} +1356 -1108
  63. package/dist/chunk-5FVZSE3B.cjs.map +1 -0
  64. package/dist/{chunk-XMY2SXOH.cjs → chunk-5WWEYV4H.cjs} +2208 -579
  65. package/dist/chunk-5WWEYV4H.cjs.map +1 -0
  66. package/dist/{chunk-WQBAQZHR.js → chunk-6NLYIMJO.js} +4 -4
  67. package/dist/{chunk-WQBAQZHR.js.map → chunk-6NLYIMJO.js.map} +1 -1
  68. package/dist/{chunk-G2TLHH6T.cjs → chunk-7B7I7YAW.cjs} +6 -6
  69. package/dist/{chunk-G2TLHH6T.cjs.map → chunk-7B7I7YAW.cjs.map} +1 -1
  70. package/dist/{chunk-EDLKIQRI.js → chunk-7G5IYROL.js} +6 -548
  71. package/dist/chunk-7G5IYROL.js.map +1 -0
  72. package/dist/{chunk-46UGOVRW.js → chunk-7QFRK6PU.js} +3 -7
  73. package/dist/chunk-7QFRK6PU.js.map +1 -0
  74. package/dist/chunk-A4C4NJ5U.cjs +12 -0
  75. package/dist/chunk-A4C4NJ5U.cjs.map +1 -0
  76. package/dist/{chunk-7CCMCMJO.cjs → chunk-AOGOC6JF.cjs} +77 -68
  77. package/dist/chunk-AOGOC6JF.cjs.map +1 -0
  78. package/dist/{chunk-TYGGUWMS.cjs → chunk-B3MN7EJR.cjs} +177 -137
  79. package/dist/chunk-B3MN7EJR.cjs.map +1 -0
  80. package/dist/{chunk-K6VKTBST.cjs → chunk-BZ5MVITP.cjs} +4 -4
  81. package/dist/{chunk-K6VKTBST.cjs.map → chunk-BZ5MVITP.cjs.map} +1 -1
  82. package/dist/{chunk-ZAQUKCUC.js → chunk-CBOD7TXH.js} +5 -5
  83. package/dist/{chunk-ZAQUKCUC.js.map → chunk-CBOD7TXH.js.map} +1 -1
  84. package/dist/{chunk-LLVOQOWE.cjs → chunk-CRZ56SZU.cjs} +6 -5
  85. package/dist/chunk-CRZ56SZU.cjs.map +1 -0
  86. package/dist/{chunk-ON47CBE4.cjs → chunk-D3GWARN7.cjs} +47 -47
  87. package/dist/{chunk-ON47CBE4.cjs.map → chunk-D3GWARN7.cjs.map} +1 -1
  88. package/dist/{chunk-W5SOCUBL.js → chunk-D3OUDFU7.js} +5 -5
  89. package/dist/{chunk-W5SOCUBL.js.map → chunk-D3OUDFU7.js.map} +1 -1
  90. package/dist/chunk-EKG2UXNX.cjs +23 -0
  91. package/dist/chunk-EKG2UXNX.cjs.map +1 -0
  92. package/dist/{chunk-2Q45FAIE.js → chunk-EVYW3532.js} +28 -19
  93. package/dist/chunk-EVYW3532.js.map +1 -0
  94. package/dist/{chunk-7PRMDZIA.cjs → chunk-FMMW3KX7.cjs} +21 -55
  95. package/dist/chunk-FMMW3KX7.cjs.map +1 -0
  96. package/dist/chunk-H2VWDQWC.cjs +571 -0
  97. package/dist/chunk-H2VWDQWC.cjs.map +1 -0
  98. package/dist/chunk-H4FY6OZK.js +13 -0
  99. package/dist/chunk-H4FY6OZK.js.map +1 -0
  100. package/dist/{chunk-OJHD3LXJ.cjs → chunk-H5IJSROF.cjs} +2 -8
  101. package/dist/chunk-H5IJSROF.cjs.map +1 -0
  102. package/dist/{chunk-U5EL6JUV.js → chunk-I5IOSA27.js} +101 -103
  103. package/dist/chunk-I5IOSA27.js.map +1 -0
  104. package/dist/{chunk-SHC7BCG5.cjs → chunk-I7YAY2VQ.cjs} +7 -7
  105. package/dist/{chunk-SHC7BCG5.cjs.map → chunk-I7YAY2VQ.cjs.map} +1 -1
  106. package/dist/chunk-IRCWIA3R.js +20 -0
  107. package/dist/chunk-IRCWIA3R.js.map +1 -0
  108. package/dist/chunk-IVQBLXBK.cjs +55 -0
  109. package/dist/chunk-IVQBLXBK.cjs.map +1 -0
  110. package/dist/{chunk-5PP4KRPV.js → chunk-IZD4HTCP.js} +5 -5
  111. package/dist/{chunk-5PP4KRPV.js.map → chunk-IZD4HTCP.js.map} +1 -1
  112. package/dist/{chunk-RDP6ZRSM.cjs → chunk-JQKMEKKW.cjs} +261 -204
  113. package/dist/chunk-JQKMEKKW.cjs.map +1 -0
  114. package/dist/chunk-JVA3KDEA.cjs +691 -0
  115. package/dist/chunk-JVA3KDEA.cjs.map +1 -0
  116. package/dist/{chunk-JG5XIJDY.js → chunk-K67P5DLL.js} +62 -22
  117. package/dist/chunk-K67P5DLL.js.map +1 -0
  118. package/dist/{chunk-MX7EKQPM.js → chunk-K6OZIHKI.js} +345 -97
  119. package/dist/chunk-K6OZIHKI.js.map +1 -0
  120. package/dist/{chunk-CS6JTQQ2.cjs → chunk-KACEYDYV.cjs} +94 -62
  121. package/dist/chunk-KACEYDYV.cjs.map +1 -0
  122. package/dist/{chunk-5OWHU7Z7.cjs → chunk-L6EVYIID.cjs} +248 -210
  123. package/dist/chunk-L6EVYIID.cjs.map +1 -0
  124. package/dist/{chunk-7OWE7WD6.js → chunk-LI4K2KEJ.js} +4 -4
  125. package/dist/{chunk-7OWE7WD6.js.map → chunk-LI4K2KEJ.js.map} +1 -1
  126. package/dist/chunk-LKZDQ2B4.js +1581 -0
  127. package/dist/chunk-LKZDQ2B4.js.map +1 -0
  128. package/dist/{chunk-45YZXI6X.cjs → chunk-LLFPQOBA.cjs} +27 -27
  129. package/dist/{chunk-45YZXI6X.cjs.map → chunk-LLFPQOBA.cjs.map} +1 -1
  130. package/dist/{chunk-ZRJTM7MT.js → chunk-LZMQ3SFK.js} +3 -3
  131. package/dist/{chunk-ZRJTM7MT.js.map → chunk-LZMQ3SFK.js.map} +1 -1
  132. package/dist/{chunk-DI6VC62F.js → chunk-M3VTS3F6.js} +3 -3
  133. package/dist/{chunk-DI6VC62F.js.map → chunk-M3VTS3F6.js.map} +1 -1
  134. package/dist/{chunk-MZ34E2GN.js → chunk-NBOS7BY3.js} +60 -21
  135. package/dist/chunk-NBOS7BY3.js.map +1 -0
  136. package/dist/{chunk-YA36ABIL.js → chunk-NGQDGL5X.js} +14 -48
  137. package/dist/chunk-NGQDGL5X.js.map +1 -0
  138. package/dist/{chunk-ZBFZGLZE.cjs → chunk-NLX5OWK7.cjs} +6 -2
  139. package/dist/chunk-NLX5OWK7.cjs.map +1 -0
  140. package/dist/chunk-NUQ2YFFH.cjs +1637 -0
  141. package/dist/chunk-NUQ2YFFH.cjs.map +1 -0
  142. package/dist/{chunk-TTCOPKUL.cjs → chunk-OGL4X4PH.cjs} +182 -184
  143. package/dist/chunk-OGL4X4PH.cjs.map +1 -0
  144. package/dist/{chunk-HY5BNOUN.cjs → chunk-OTNTGEXR.cjs} +4 -4
  145. package/dist/{chunk-HY5BNOUN.cjs.map → chunk-OTNTGEXR.cjs.map} +1 -1
  146. package/dist/chunk-OTWE63BW.js +53 -0
  147. package/dist/chunk-OTWE63BW.js.map +1 -0
  148. package/dist/chunk-PC5NGH5A.js +549 -0
  149. package/dist/chunk-PC5NGH5A.js.map +1 -0
  150. package/dist/{chunk-IPRP6TDL.cjs → chunk-PS3TUWJM.cjs} +7 -7
  151. package/dist/{chunk-IPRP6TDL.cjs.map → chunk-PS3TUWJM.cjs.map} +1 -1
  152. package/dist/{chunk-V76FGHY3.js → chunk-PVFFH7TL.js} +5 -5
  153. package/dist/{chunk-V76FGHY3.js.map → chunk-PVFFH7TL.js.map} +1 -1
  154. package/dist/chunk-QCD5JKU4.cjs +15 -0
  155. package/dist/chunk-QCD5JKU4.cjs.map +1 -0
  156. package/dist/{chunk-IRPYOHRC.js → chunk-QG5VEOKX.js} +6 -2
  157. package/dist/chunk-QG5VEOKX.js.map +1 -0
  158. package/dist/{chunk-2CYI5HRH.js → chunk-RI7RJH4G.js} +49 -17
  159. package/dist/chunk-RI7RJH4G.js.map +1 -0
  160. package/dist/{chunk-5LKOVCPP.js → chunk-RVUL2HXY.js} +6 -5
  161. package/dist/chunk-RVUL2HXY.js.map +1 -0
  162. package/dist/{chunk-WK23PGTP.cjs → chunk-S5GU4LUN.cjs} +11 -11
  163. package/dist/{chunk-WK23PGTP.cjs.map → chunk-S5GU4LUN.cjs.map} +1 -1
  164. package/dist/{chunk-S33YQEL7.js → chunk-SDPWO2Z5.js} +6 -6
  165. package/dist/{chunk-S33YQEL7.js.map → chunk-SDPWO2Z5.js.map} +1 -1
  166. package/dist/{chunk-6S3PTHL4.js → chunk-SLGGT2XD.js} +3 -3
  167. package/dist/{chunk-6S3PTHL4.js.map → chunk-SLGGT2XD.js.map} +1 -1
  168. package/dist/{chunk-HSEZ7X6Y.cjs → chunk-TIJUA4I6.cjs} +45 -45
  169. package/dist/{chunk-HSEZ7X6Y.cjs.map → chunk-TIJUA4I6.cjs.map} +1 -1
  170. package/dist/{chunk-CSNOYIB4.cjs → chunk-TM54OBHX.cjs} +13 -13
  171. package/dist/{chunk-CSNOYIB4.cjs.map → chunk-TM54OBHX.cjs.map} +1 -1
  172. package/dist/{chunk-MM3JHVKZ.cjs → chunk-TUWSVL6I.cjs} +4 -4
  173. package/dist/{chunk-MM3JHVKZ.cjs.map → chunk-TUWSVL6I.cjs.map} +1 -1
  174. package/dist/{chunk-2GIV5X4P.js → chunk-TYEYRCXL.js} +86 -33
  175. package/dist/chunk-TYEYRCXL.js.map +1 -0
  176. package/dist/{chunk-MJPZNEJZ.js → chunk-UKOVGCRN.js} +2095 -496
  177. package/dist/chunk-UKOVGCRN.js.map +1 -0
  178. package/dist/chunk-UYKDYE5D.cjs +12 -0
  179. package/dist/{chunk-KWNWG4RC.cjs.map → chunk-UYKDYE5D.cjs.map} +1 -1
  180. package/dist/{chunk-FX5ZW6PN.js → chunk-VAAC7L57.js} +95 -40
  181. package/dist/chunk-VAAC7L57.js.map +1 -0
  182. package/dist/{chunk-ISKCIQF2.cjs → chunk-VKHXYVN7.cjs} +14 -25
  183. package/dist/chunk-VKHXYVN7.cjs.map +1 -0
  184. package/dist/chunk-VUQZNUHU.js +171 -0
  185. package/dist/chunk-VUQZNUHU.js.map +1 -0
  186. package/dist/{chunk-K2XYLVVB.cjs → chunk-WDM5WQK4.cjs} +175 -136
  187. package/dist/chunk-WDM5WQK4.cjs.map +1 -0
  188. package/dist/{chunk-GVYVGGPJ.js → chunk-WFSYYU4W.js} +66 -28
  189. package/dist/chunk-WFSYYU4W.js.map +1 -0
  190. package/dist/{chunk-R7MRFE5P.js → chunk-WS5MT2UJ.js} +3 -3
  191. package/dist/{chunk-R7MRFE5P.js.map → chunk-WS5MT2UJ.js.map} +1 -1
  192. package/dist/chunk-XORONCV3.js +202 -0
  193. package/dist/chunk-XORONCV3.js.map +1 -0
  194. package/dist/chunk-ZGVTNKTX.cjs +217 -0
  195. package/dist/chunk-ZGVTNKTX.cjs.map +1 -0
  196. package/dist/core/index.cjs +20 -20
  197. package/dist/core/index.d.cts +4 -4
  198. package/dist/core/index.d.ts +4 -4
  199. package/dist/core/index.js +4 -4
  200. package/dist/{ddl-B49O7dB_.d.ts → ddl-BvcbgzHo.d.ts} +3 -3
  201. package/dist/{ddl-DcZG660s.d.cts → ddl-Ufebz5q5.d.cts} +3 -3
  202. package/dist/graph-extension/index.d.cts +2 -4
  203. package/dist/graph-extension/index.d.ts +2 -4
  204. package/dist/graph-merge/index.cjs +140 -125
  205. package/dist/graph-merge/index.cjs.map +1 -1
  206. package/dist/graph-merge/index.d.cts +8 -9
  207. package/dist/graph-merge/index.d.ts +8 -9
  208. package/dist/graph-merge/index.js +42 -27
  209. package/dist/graph-merge/index.js.map +1 -1
  210. package/dist/index.cjs +144 -143
  211. package/dist/index.cjs.map +1 -1
  212. package/dist/index.d.cts +11 -12
  213. package/dist/index.d.ts +11 -12
  214. package/dist/index.js +30 -29
  215. package/dist/index.js.map +1 -1
  216. package/dist/indexes/index.cjs +14 -12
  217. package/dist/indexes/index.d.cts +4 -4
  218. package/dist/indexes/index.d.ts +4 -4
  219. package/dist/indexes/index.js +7 -5
  220. package/dist/{ingestion-import-target-CI8OWIkM.d.ts → ingestion-import-target-CAs1OX-l.d.cts} +1 -1
  221. package/dist/{ingestion-import-target-DCpfM1PX.d.cts → ingestion-import-target-DCQSPfNx.d.ts} +1 -1
  222. package/dist/interchange/index.cjs +41 -39
  223. package/dist/interchange/index.cjs.map +1 -1
  224. package/dist/interchange/index.d.cts +8 -8
  225. package/dist/interchange/index.d.ts +8 -8
  226. package/dist/interchange/index.js +16 -14
  227. package/dist/interchange/index.js.map +1 -1
  228. package/dist/local-store-impl-JC7OBRAW.js +75 -0
  229. package/dist/local-store-impl-JC7OBRAW.js.map +1 -0
  230. package/dist/local-store-impl-UOS2LUIG.cjs +77 -0
  231. package/dist/local-store-impl-UOS2LUIG.cjs.map +1 -0
  232. package/dist/{manager-Cfg1ENj1.d.ts → manager-B68OrPR2.d.ts} +1 -2
  233. package/dist/{manager-D348fa6W.d.cts → manager-D_t7oK69.d.cts} +1 -2
  234. package/dist/pglite-store-impl-J5J5AA52.cjs +75 -0
  235. package/dist/pglite-store-impl-J5J5AA52.cjs.map +1 -0
  236. package/dist/pglite-store-impl-LDRH2DUH.js +73 -0
  237. package/dist/pglite-store-impl-LDRH2DUH.js.map +1 -0
  238. package/dist/{postgres-UStOycLI.d.ts → postgres-BPLSVyHM.d.ts} +1 -1
  239. package/dist/{postgres-CH1kkM5J.d.cts → postgres-CqvtFC2y.d.cts} +1 -1
  240. package/dist/profiler/index.d.cts +9 -9
  241. package/dist/profiler/index.d.ts +9 -9
  242. package/dist/provenance/index.cjs +33 -20
  243. package/dist/provenance/index.cjs.map +1 -1
  244. package/dist/provenance/index.d.cts +7 -7
  245. package/dist/provenance/index.d.ts +7 -7
  246. package/dist/provenance/index.js +24 -11
  247. package/dist/provenance/index.js.map +1 -1
  248. package/dist/{repair-validity-windows-aWX7VNvv.d.cts → repair-validity-windows-DEzCKAdy.d.cts} +7 -3
  249. package/dist/{repair-validity-windows-BtOEe2pS.d.ts → repair-validity-windows-GMdaS2AH.d.ts} +7 -3
  250. package/dist/resolve-D_H8MHtq.d.ts +1805 -0
  251. package/dist/resolve-WEW8gWws.d.cts +1805 -0
  252. package/dist/schema/index.cjs +42 -40
  253. package/dist/schema/index.d.cts +4 -6
  254. package/dist/schema/index.d.ts +4 -6
  255. package/dist/schema/index.js +15 -13
  256. package/dist/{searchable-z4BiFfHI.d.ts → searchable-C_UREI9K.d.ts} +1 -1
  257. package/dist/{searchable-C8-RrL3l.d.cts → searchable-ClgET_i7.d.cts} +1 -1
  258. package/dist/{sqlite-axLw5Lo5.d.ts → sqlite-D1mXO9Kp.d.cts} +2 -1
  259. package/dist/{sqlite-Cyx9j9o6.d.cts → sqlite-MZA3oZNB.d.ts} +2 -1
  260. package/dist/{store-CTfQ9taw.d.ts → store-CuFX7fCx.d.cts} +38 -41
  261. package/dist/{store-DR9J7JVB.d.cts → store-D-ZjXQpW.d.ts} +38 -41
  262. package/dist/{temporal-CBOrERz5.d.ts → temporal-CpyEiRY8.d.cts} +1 -1
  263. package/dist/{temporal-B4Ky4wzh.d.cts → temporal-y0Aep9Su.d.ts} +1 -1
  264. package/dist/{types-CWg4dTjj.d.ts → types-6yf0Vv-_.d.cts} +1672 -1
  265. package/dist/{types-CWg4dTjj.d.cts → types-6yf0Vv-_.d.ts} +1672 -1
  266. package/dist/{types-BScHXVM7.d.ts → types-DzJ4dlzk.d.cts} +1 -1
  267. package/dist/{types-BE921wRl.d.cts → types-_vVSB9k-.d.ts} +1 -1
  268. package/dist/{where-BWXUPV3C.d.ts → where-DuG2LCLe.d.ts} +1 -1
  269. package/dist/{where-CNtx1aLc.d.cts → where-Mhf_yyKX.d.cts} +1 -1
  270. package/package.json +5 -1
  271. package/dist/chunk-2CYI5HRH.js.map +0 -1
  272. package/dist/chunk-2GIV5X4P.js.map +0 -1
  273. package/dist/chunk-2Q45FAIE.js.map +0 -1
  274. package/dist/chunk-46UGOVRW.js.map +0 -1
  275. package/dist/chunk-5LKOVCPP.js.map +0 -1
  276. package/dist/chunk-5OWHU7Z7.cjs.map +0 -1
  277. package/dist/chunk-6LEOAIIB.js +0 -1160
  278. package/dist/chunk-6LEOAIIB.js.map +0 -1
  279. package/dist/chunk-7CCMCMJO.cjs.map +0 -1
  280. package/dist/chunk-7PRMDZIA.cjs.map +0 -1
  281. package/dist/chunk-C76WFIVZ.cjs.map +0 -1
  282. package/dist/chunk-CS6JTQQ2.cjs.map +0 -1
  283. package/dist/chunk-EDLKIQRI.js.map +0 -1
  284. package/dist/chunk-EH3JZJUM.cjs +0 -567
  285. package/dist/chunk-EH3JZJUM.cjs.map +0 -1
  286. package/dist/chunk-FX5ZW6PN.js.map +0 -1
  287. package/dist/chunk-GHZPZNFC.cjs +0 -132
  288. package/dist/chunk-GHZPZNFC.cjs.map +0 -1
  289. package/dist/chunk-GVYVGGPJ.js.map +0 -1
  290. package/dist/chunk-IHK5KA2Q.cjs +0 -262
  291. package/dist/chunk-IHK5KA2Q.cjs.map +0 -1
  292. package/dist/chunk-IRPYOHRC.js.map +0 -1
  293. package/dist/chunk-ISKCIQF2.cjs.map +0 -1
  294. package/dist/chunk-JG5XIJDY.js.map +0 -1
  295. package/dist/chunk-K2XYLVVB.cjs.map +0 -1
  296. package/dist/chunk-KWNWG4RC.cjs +0 -12
  297. package/dist/chunk-LLVOQOWE.cjs.map +0 -1
  298. package/dist/chunk-MJPZNEJZ.js.map +0 -1
  299. package/dist/chunk-MX7EKQPM.js.map +0 -1
  300. package/dist/chunk-MZ34E2GN.js.map +0 -1
  301. package/dist/chunk-OJHD3LXJ.cjs.map +0 -1
  302. package/dist/chunk-PALYTHGM.js +0 -114
  303. package/dist/chunk-PALYTHGM.js.map +0 -1
  304. package/dist/chunk-RDP6ZRSM.cjs.map +0 -1
  305. package/dist/chunk-S3SDEQMC.js +0 -532
  306. package/dist/chunk-S3SDEQMC.js.map +0 -1
  307. package/dist/chunk-TEC24ZDA.cjs +0 -1254
  308. package/dist/chunk-TEC24ZDA.cjs.map +0 -1
  309. package/dist/chunk-TP4NJTI3.cjs +0 -1192
  310. package/dist/chunk-TP4NJTI3.cjs.map +0 -1
  311. package/dist/chunk-TTCOPKUL.cjs.map +0 -1
  312. package/dist/chunk-TUVD4DFR.cjs.map +0 -1
  313. package/dist/chunk-TYGGUWMS.cjs.map +0 -1
  314. package/dist/chunk-U3Z7XKAG.js.map +0 -1
  315. package/dist/chunk-U5EL6JUV.js.map +0 -1
  316. package/dist/chunk-VTJVMP4I.js.map +0 -1
  317. package/dist/chunk-WCLMKNQE.cjs.map +0 -1
  318. package/dist/chunk-XMY2SXOH.cjs.map +0 -1
  319. package/dist/chunk-Y55DLLEG.js +0 -247
  320. package/dist/chunk-Y55DLLEG.js.map +0 -1
  321. package/dist/chunk-YA36ABIL.js.map +0 -1
  322. package/dist/chunk-ZBFZGLZE.cjs.map +0 -1
  323. package/dist/index-B0PrmE3K.d.cts +0 -1146
  324. package/dist/index-CwcXsL5R.d.ts +0 -1146
  325. package/dist/materialize-indexes-C9GG3O3C.d.ts +0 -266
  326. package/dist/materialize-indexes-CrSiW_lT.d.cts +0 -266
@@ -1,16 +1,1211 @@
1
- import { formatPostgresTimestamp, coerceNumericScore, nowIso, buildPurgeEdgeClaims, buildTakeOverEdgeClaim, buildLockEdgeClaims, buildHardDeleteUniquesByConcreteKind, buildInsertUniqueBatch, buildInsertUnique, edgePrimaryKeyConstraint, nodePrimaryKeyConstraint, liveNodeIdsSubquery, buildCheckUniqueBatch, buildCheckUnique, buildHardDeleteUniquesByNodeIds, buildHardDeleteUniquesByNode, buildDeleteUnique, quotedColumn, quotedTableName, codePointOrderKey, sqlNull, expectedValidFromPredicate, edgeColumnList, nodeColumnList } from './chunk-S3SDEQMC.js';
2
- import { runtimeStrategyContributions } from './chunk-6LEOAIIB.js';
3
- import { toDrizzleSql } from './chunk-V76FGHY3.js';
4
- import { edgeCardinalityClaimTarget, EDGE_CARDINALITY_SPECS } from './chunk-YA36ABIL.js';
5
- import { parseDimensionMismatch, deriveBackend, chunk, isMissingTableError, isDuplicatePrimaryKeyError, errorChain, sortedReplacer } from './chunk-IRPYOHRC.js';
6
- import { isSameClaimOwner } from './chunk-5LKOVCPP.js';
1
+ import { buildPostgresSystemIndexBuilders, buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteSystemIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders, toDrizzleSql } from './chunk-PVFFH7TL.js';
2
+ import { formatPostgresTimestamp, coerceNumericScore, nowIso, buildHardDeleteUniquesByConcreteKind } from './chunk-VUQZNUHU.js';
3
+ import { edgeCardinalityClaimTarget, EDGE_CARDINALITY_SPECS } from './chunk-NGQDGL5X.js';
4
+ import { parseDimensionMismatch, deriveBackend, chunk, isMissingTableError, isDuplicatePrimaryKeyError, errorChain, sortedReplacer } from './chunk-QG5VEOKX.js';
5
+ import { resolveWriteFencePlan, requireWriteFence } from './chunk-LKZDQ2B4.js';
6
+ import { isSameClaimOwner, claimOwnerMatchesSql } from './chunk-RVUL2HXY.js';
7
7
  import { resolveStampedValidityLowerBound, resolveStatedValidityLowerBound } from './chunk-K46SDNQD.js';
8
+ import { assertNoSystemIndexNameCollision } from './chunk-36VYWVQU.js';
8
9
  import { sha256Hex } from './chunk-K34OPSJK.js';
9
- import { buildFulltextGraphDelete, buildForeignFulltextGraphProbe, getDialect } from './chunk-EDLKIQRI.js';
10
- import { sql as sql$1, asCompiledStatementSql, asCompiledRowsSql, isSqlFragment } from './chunk-46UGOVRW.js';
11
- import { EmbeddingDimensionChangedError, ConfigurationError, StaleVersionError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, TrustedImportError, ContributionUnavailableError, ContributionRebuildUnsupportedError, StoreNotInitializedError } from './chunk-YDEJQWOL.js';
10
+ import { getDialect } from './chunk-7G5IYROL.js';
11
+ import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER, buildFulltextGraphDelete, buildForeignFulltextGraphProbe } from './chunk-PC5NGH5A.js';
12
+ import { sql as sql$1, asCompiledStatementSql, asCompiledRowsSql, isSqlFragment } from './chunk-7QFRK6PU.js';
13
+ import { ConfigurationError, EmbeddingDimensionChangedError, StaleVersionError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, TrustedImportError, ContributionUnavailableError, ContributionRebuildUnsupportedError, StoreNotInitializedError } from './chunk-YDEJQWOL.js';
12
14
  import { isPresent } from './chunk-DYATYRY4.js';
13
15
  import { sql, is, getTableName } from 'drizzle-orm';
16
+ import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, bigint, index, uniqueIndex, check, boolean, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
17
+ import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, uniqueIndex as uniqueIndex$1, check as check$1, getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
18
+
19
+ var regconfig = customType({
20
+ dataType: () => "regconfig"
21
+ });
22
+ var tsvector = customType({
23
+ dataType: () => "tsvector"
24
+ });
25
+
26
+ // src/backend/drizzle/schema/postgres.ts
27
+ var DEFAULT_TABLE_NAMES = {
28
+ nodes: "typegraph_nodes",
29
+ edges: "typegraph_edges",
30
+ recordedNodes: "typegraph_recorded_nodes",
31
+ recordedEdges: "typegraph_recorded_edges",
32
+ recordedClock: "typegraph_recorded_clock",
33
+ revisionOrigins: "typegraph_revision_origins",
34
+ identityAssertions: "typegraph_identity_assertions",
35
+ recordedIdentityAssertions: "typegraph_recorded_identity_assertions",
36
+ identityClosure: "typegraph_identity_closure",
37
+ identitySeparation: "typegraph_identity_separation",
38
+ uniques: "typegraph_node_uniques",
39
+ edgeClaims: "typegraph_edge_claims",
40
+ schemaVersions: "typegraph_schema_versions",
41
+ fulltext: "typegraph_node_fulltext",
42
+ indexMaterializations: "typegraph_index_materializations",
43
+ contributionMaterializations: "typegraph_contribution_materializations",
44
+ kindRemovals: "typegraph_kind_removals",
45
+ reconciliationMarkers: "typegraph_reconciliation_markers"
46
+ };
47
+ function createPostgresTables(names = {}, options = {}) {
48
+ const n = { ...DEFAULT_TABLE_NAMES, ...names };
49
+ const indexes = options.indexes ?? [];
50
+ assertNoSystemIndexNameCollision(indexes, n);
51
+ const nodes3 = pgTable(
52
+ n.nodes,
53
+ {
54
+ graphId: text("graph_id").notNull(),
55
+ kind: text("kind").notNull(),
56
+ id: text("id").notNull(),
57
+ props: jsonb("props").notNull(),
58
+ version: integer("version").notNull().default(1),
59
+ validFrom: timestamp("valid_from", { withTimezone: true }),
60
+ validTo: timestamp("valid_to", { withTimezone: true }),
61
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
62
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
63
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
64
+ },
65
+ (t) => [
66
+ primaryKey({ columns: [t.graphId, t.kind, t.id] }),
67
+ // System indexes come from SYSTEM_INDEX_DECLARATIONS (single source
68
+ // for both dialects + the runtime materializer).
69
+ ...buildPostgresSystemIndexBuilders("nodes", n.nodes, t),
70
+ ...buildPostgresNodeIndexBuilders(t, indexes)
71
+ ]
72
+ );
73
+ const edges3 = pgTable(
74
+ n.edges,
75
+ {
76
+ graphId: text("graph_id").notNull(),
77
+ id: text("id").notNull(),
78
+ kind: text("kind").notNull(),
79
+ fromKind: text("from_kind").notNull(),
80
+ fromId: text("from_id").notNull(),
81
+ toKind: text("to_kind").notNull(),
82
+ toId: text("to_id").notNull(),
83
+ props: jsonb("props").notNull(),
84
+ validFrom: timestamp("valid_from", { withTimezone: true }),
85
+ validTo: timestamp("valid_to", { withTimezone: true }),
86
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
87
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
88
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
89
+ },
90
+ (t) => [
91
+ primaryKey({ columns: [t.graphId, t.id] }),
92
+ ...buildPostgresSystemIndexBuilders("edges", n.edges, t),
93
+ ...buildPostgresEdgeIndexBuilders(t, indexes)
94
+ ]
95
+ );
96
+ const recordedNodes3 = pgTable(
97
+ n.recordedNodes,
98
+ {
99
+ historyId: text("history_id").notNull(),
100
+ graphId: text("graph_id").notNull(),
101
+ kind: text("kind").notNull(),
102
+ id: text("id").notNull(),
103
+ props: jsonb("props").notNull(),
104
+ version: integer("version").notNull(),
105
+ validFrom: timestamp("valid_from", { withTimezone: true }),
106
+ validTo: timestamp("valid_to", { withTimezone: true }),
107
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
108
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
109
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
110
+ recordedFrom: bigint("recorded_from", { mode: "number" }).notNull(),
111
+ recordedTo: bigint("recorded_to", { mode: "number" }).notNull(),
112
+ op: text("op").notNull(),
113
+ schemaVersion: integer("schema_version"),
114
+ txId: text("tx_id"),
115
+ meta: jsonb("meta")
116
+ },
117
+ (t) => [
118
+ primaryKey({ columns: [t.historyId] }),
119
+ ...buildPostgresSystemIndexBuilders("recordedNodes", n.recordedNodes, t)
120
+ ]
121
+ );
122
+ const recordedEdges3 = pgTable(
123
+ n.recordedEdges,
124
+ {
125
+ historyId: text("history_id").notNull(),
126
+ graphId: text("graph_id").notNull(),
127
+ id: text("id").notNull(),
128
+ kind: text("kind").notNull(),
129
+ fromKind: text("from_kind").notNull(),
130
+ fromId: text("from_id").notNull(),
131
+ toKind: text("to_kind").notNull(),
132
+ toId: text("to_id").notNull(),
133
+ props: jsonb("props").notNull(),
134
+ validFrom: timestamp("valid_from", { withTimezone: true }),
135
+ validTo: timestamp("valid_to", { withTimezone: true }),
136
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
137
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
138
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
139
+ recordedFrom: bigint("recorded_from", { mode: "number" }).notNull(),
140
+ recordedTo: bigint("recorded_to", { mode: "number" }).notNull(),
141
+ op: text("op").notNull(),
142
+ schemaVersion: integer("schema_version"),
143
+ txId: text("tx_id"),
144
+ meta: jsonb("meta")
145
+ },
146
+ (t) => [
147
+ primaryKey({ columns: [t.historyId] }),
148
+ ...buildPostgresSystemIndexBuilders("recordedEdges", n.recordedEdges, t)
149
+ ]
150
+ );
151
+ const recordedClock3 = pgTable(
152
+ n.recordedClock,
153
+ {
154
+ graphId: text("graph_id").notNull(),
155
+ revision: bigint("revision", { mode: "number" }).notNull(),
156
+ recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull()
157
+ },
158
+ (t) => [primaryKey({ columns: [t.graphId] })]
159
+ );
160
+ const revisionOrigins = pgTable(
161
+ n.revisionOrigins,
162
+ {
163
+ graphId: text("graph_id").notNull(),
164
+ origin: text("origin").notNull()
165
+ },
166
+ (t) => [primaryKey({ columns: [t.graphId] })]
167
+ );
168
+ const identityAssertions = pgTable(
169
+ n.identityAssertions,
170
+ {
171
+ graphId: text("graph_id").notNull(),
172
+ id: text("id").notNull(),
173
+ relation: text("rel").notNull(),
174
+ aKind: text("a_kind").notNull(),
175
+ aId: text("a_id").notNull(),
176
+ bKind: text("b_kind").notNull(),
177
+ bId: text("b_id").notNull(),
178
+ validFrom: timestamp("valid_from", { withTimezone: true }).notNull(),
179
+ validTo: timestamp("valid_to", { withTimezone: true }),
180
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
181
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
182
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
183
+ endedByKind: text("ended_by_kind"),
184
+ endedById: text("ended_by_id")
185
+ },
186
+ (t) => [
187
+ primaryKey({ columns: [t.graphId, t.id] }),
188
+ index(`${n.identityAssertions}_a_idx`).on(
189
+ t.graphId,
190
+ t.aKind,
191
+ t.aId,
192
+ t.validTo
193
+ ),
194
+ index(`${n.identityAssertions}_b_idx`).on(
195
+ t.graphId,
196
+ t.bKind,
197
+ t.bId,
198
+ t.validTo
199
+ ),
200
+ uniqueIndex(`${n.identityAssertions}_current_pair_idx`).on(t.graphId, t.relation, t.aKind, t.aId, t.bKind, t.bId).where(sql`${t.validTo} IS NULL`),
201
+ check(
202
+ `${n.identityAssertions}_ended_by_check`,
203
+ sql`(ended_by_kind IS NULL) = (ended_by_id IS NULL) AND (ended_by_kind IS NULL OR (valid_to IS NOT NULL AND ((ended_by_kind = a_kind AND ended_by_id = a_id) OR (ended_by_kind = b_kind AND ended_by_id = b_id))))`
204
+ )
205
+ ]
206
+ );
207
+ const recordedIdentityAssertions = pgTable(
208
+ n.recordedIdentityAssertions,
209
+ {
210
+ historyId: text("history_id").notNull(),
211
+ graphId: text("graph_id").notNull(),
212
+ id: text("id").notNull(),
213
+ relation: text("rel").notNull(),
214
+ aKind: text("a_kind").notNull(),
215
+ aId: text("a_id").notNull(),
216
+ bKind: text("b_kind").notNull(),
217
+ bId: text("b_id").notNull(),
218
+ validFrom: timestamp("valid_from", { withTimezone: true }).notNull(),
219
+ validTo: timestamp("valid_to", { withTimezone: true }),
220
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
221
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
222
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
223
+ endedByKind: text("ended_by_kind"),
224
+ endedById: text("ended_by_id"),
225
+ recordedFrom: bigint("recorded_from", { mode: "number" }).notNull(),
226
+ recordedTo: bigint("recorded_to", { mode: "number" }).notNull(),
227
+ op: text("op").notNull(),
228
+ schemaVersion: integer("schema_version"),
229
+ txId: text("tx_id"),
230
+ meta: jsonb("meta")
231
+ },
232
+ (t) => [
233
+ primaryKey({ columns: [t.historyId] }),
234
+ index(`${n.recordedIdentityAssertions}_entity_idx`).on(
235
+ t.graphId,
236
+ t.id,
237
+ t.recordedFrom,
238
+ t.recordedTo
239
+ ),
240
+ index(`${n.recordedIdentityAssertions}_a_idx`).on(
241
+ t.graphId,
242
+ t.aKind,
243
+ t.aId,
244
+ t.recordedFrom,
245
+ t.recordedTo
246
+ ),
247
+ index(`${n.recordedIdentityAssertions}_b_idx`).on(
248
+ t.graphId,
249
+ t.bKind,
250
+ t.bId,
251
+ t.recordedFrom,
252
+ t.recordedTo
253
+ )
254
+ ]
255
+ );
256
+ const identityClosure = pgTable(
257
+ n.identityClosure,
258
+ {
259
+ graphId: text("graph_id").notNull(),
260
+ memberKind: text("member_kind").notNull(),
261
+ memberId: text("member_id").notNull(),
262
+ classKind: text("class_kind").notNull(),
263
+ classId: text("class_id").notNull()
264
+ },
265
+ (t) => [
266
+ primaryKey({ columns: [t.graphId, t.memberKind, t.memberId] }),
267
+ index(`${n.identityClosure}_class_idx`).on(
268
+ t.graphId,
269
+ t.classKind,
270
+ t.classId
271
+ )
272
+ ]
273
+ );
274
+ const identitySeparation = pgTable(
275
+ n.identitySeparation,
276
+ {
277
+ graphId: text("graph_id").notNull(),
278
+ classKeyLow: text("class_key_low").notNull(),
279
+ classKeyHigh: text("class_key_high").notNull()
280
+ },
281
+ (t) => [
282
+ primaryKey({ columns: [t.graphId, t.classKeyLow, t.classKeyHigh] }),
283
+ index(`${n.identitySeparation}_high_idx`).on(t.graphId, t.classKeyHigh),
284
+ check(
285
+ `${n.identitySeparation}_ordered_pair_check`,
286
+ sql`class_key_low COLLATE "C" < class_key_high COLLATE "C"`
287
+ )
288
+ ]
289
+ );
290
+ const uniques3 = pgTable(
291
+ n.uniques,
292
+ {
293
+ graphId: text("graph_id").notNull(),
294
+ nodeKind: text("node_kind").notNull(),
295
+ constraintName: text("constraint_name").notNull(),
296
+ key: text("key").notNull(),
297
+ nodeId: text("node_id").notNull(),
298
+ concreteKind: text("concrete_kind").notNull(),
299
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
300
+ },
301
+ (t) => [
302
+ primaryKey({
303
+ columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
304
+ }),
305
+ index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
306
+ ]
307
+ );
308
+ const edgeClaims3 = pgTable(
309
+ n.edgeClaims,
310
+ {
311
+ graphId: text("graph_id").notNull(),
312
+ axis: text("axis").notNull(),
313
+ key: text("key").notNull(),
314
+ edgeId: text("edge_id").notNull(),
315
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
316
+ },
317
+ (t) => [
318
+ primaryKey({ columns: [t.graphId, t.axis, t.key] }),
319
+ index(`${n.edgeClaims}_edge_idx`).on(t.graphId, t.edgeId)
320
+ ]
321
+ );
322
+ const schemaVersions3 = pgTable(
323
+ n.schemaVersions,
324
+ {
325
+ graphId: text("graph_id").notNull(),
326
+ version: integer("version").notNull(),
327
+ schemaHash: text("schema_hash").notNull(),
328
+ schemaDoc: jsonb("schema_doc").notNull(),
329
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
330
+ isActive: boolean("is_active").notNull().default(false)
331
+ },
332
+ (t) => [
333
+ primaryKey({ columns: [t.graphId, t.version] }),
334
+ index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
335
+ // Partial unique index enforcing the "at most one active version
336
+ // per graph" invariant at the storage layer. Defense in depth
337
+ // against buggy backend implementations or out-of-band writes.
338
+ // Forces the deactivate-then-activate ordering used by
339
+ // `commitSchemaVersion` and `setActiveVersion`.
340
+ uniqueIndex(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = TRUE`)
341
+ ]
342
+ );
343
+ const indexMaterializations = pgTable(
344
+ n.indexMaterializations,
345
+ {
346
+ indexName: text("index_name").notNull(),
347
+ graphId: text("graph_id").notNull(),
348
+ entity: text("entity").notNull(),
349
+ kind: text("kind").notNull(),
350
+ signature: text("signature").notNull(),
351
+ schemaVersion: integer("schema_version").notNull(),
352
+ materializedAt: timestamp("materialized_at", { withTimezone: true }),
353
+ lastAttemptedAt: timestamp("last_attempted_at", {
354
+ withTimezone: true
355
+ }).notNull(),
356
+ lastError: text("last_error"),
357
+ // Cross-caller build claim: while `building_since` is fresh (within
358
+ // the lease), exactly one materializer owns this index's CREATE
359
+ // INDEX CONCURRENTLY. Serializes same-index CIC across processes —
360
+ // two concurrent expression-index CICs deadlock each other (no
361
+ // safe-snapshot exemption). NULL when no build is in flight.
362
+ buildingSince: timestamp("building_since", { withTimezone: true }),
363
+ claimToken: text("claim_token")
364
+ },
365
+ (t) => [primaryKey({ columns: [t.indexName] })]
366
+ );
367
+ const kindRemovals = pgTable(
368
+ n.kindRemovals,
369
+ {
370
+ graphId: text("graph_id").notNull(),
371
+ kindName: text("kind_name").notNull(),
372
+ entity: text("entity").notNull(),
373
+ schemaVersion: integer("schema_version").notNull(),
374
+ removedAt: timestamp("removed_at", { withTimezone: true }),
375
+ lastAttemptedAt: timestamp("last_attempted_at", {
376
+ withTimezone: true
377
+ }).notNull(),
378
+ lastError: text("last_error")
379
+ },
380
+ (t) => [
381
+ primaryKey({
382
+ columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
383
+ })
384
+ ]
385
+ );
386
+ const reconciliationMarkers = pgTable(
387
+ n.reconciliationMarkers,
388
+ {
389
+ graphId: text("graph_id").notNull(),
390
+ reconciledToVersion: integer("reconciled_to_version").notNull()
391
+ },
392
+ (t) => [primaryKey({ columns: [t.graphId] })]
393
+ );
394
+ const contributionMaterializations = pgTable(
395
+ n.contributionMaterializations,
396
+ {
397
+ graphId: text("graph_id").notNull(),
398
+ logicalName: text("logical_name").notNull(),
399
+ owner: text("owner").notNull(),
400
+ tableName: text("table_name").notNull(),
401
+ signature: text("signature").notNull(),
402
+ materializedAt: timestamp("materialized_at", { withTimezone: true }),
403
+ lastAttemptedAt: timestamp("last_attempted_at", {
404
+ withTimezone: true
405
+ }).notNull(),
406
+ lastError: text("last_error")
407
+ },
408
+ (t) => [
409
+ primaryKey({
410
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
411
+ })
412
+ ]
413
+ );
414
+ const fulltext2 = pgTable(
415
+ n.fulltext,
416
+ {
417
+ graphId: text("graph_id").notNull(),
418
+ nodeKind: text("node_kind").notNull(),
419
+ nodeId: text("node_id").notNull(),
420
+ content: text("content").notNull(),
421
+ language: regconfig("language").notNull(),
422
+ tsv: tsvector("tsv").generatedAlwaysAs(sql`to_tsvector("language", "content")`).notNull(),
423
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
424
+ },
425
+ (t) => [
426
+ primaryKey({ columns: [t.graphId, t.nodeKind, t.nodeId] }),
427
+ index(`${n.fulltext}_tsv_idx`).using("gin", t.tsv),
428
+ index(`${n.fulltext}_kind_idx`).on(t.graphId, t.nodeKind)
429
+ ]
430
+ );
431
+ return {
432
+ nodes: nodes3,
433
+ edges: edges3,
434
+ recordedNodes: recordedNodes3,
435
+ recordedEdges: recordedEdges3,
436
+ recordedClock: recordedClock3,
437
+ revisionOrigins,
438
+ identityAssertions,
439
+ recordedIdentityAssertions,
440
+ identityClosure,
441
+ identitySeparation,
442
+ uniques: uniques3,
443
+ edgeClaims: edgeClaims3,
444
+ schemaVersions: schemaVersions3,
445
+ indexMaterializations,
446
+ contributionMaterializations,
447
+ kindRemovals,
448
+ reconciliationMarkers,
449
+ fulltext: fulltext2,
450
+ fulltextTableName: n.fulltext
451
+ };
452
+ }
453
+ var tables = createPostgresTables();
454
+ var {
455
+ nodes,
456
+ edges,
457
+ recordedNodes,
458
+ recordedEdges,
459
+ recordedClock,
460
+ uniques,
461
+ edgeClaims,
462
+ schemaVersions,
463
+ fulltext
464
+ } = tables;
465
+ var DEFAULT_TABLE_NAMES2 = {
466
+ nodes: "typegraph_nodes",
467
+ edges: "typegraph_edges",
468
+ recordedNodes: "typegraph_recorded_nodes",
469
+ recordedEdges: "typegraph_recorded_edges",
470
+ recordedClock: "typegraph_recorded_clock",
471
+ revisionOrigins: "typegraph_revision_origins",
472
+ identityAssertions: "typegraph_identity_assertions",
473
+ recordedIdentityAssertions: "typegraph_recorded_identity_assertions",
474
+ identityClosure: "typegraph_identity_closure",
475
+ identitySeparation: "typegraph_identity_separation",
476
+ uniques: "typegraph_node_uniques",
477
+ edgeClaims: "typegraph_edge_claims",
478
+ schemaVersions: "typegraph_schema_versions",
479
+ fulltext: "typegraph_node_fulltext",
480
+ indexMaterializations: "typegraph_index_materializations",
481
+ contributionMaterializations: "typegraph_contribution_materializations",
482
+ kindRemovals: "typegraph_kind_removals",
483
+ reconciliationMarkers: "typegraph_reconciliation_markers"
484
+ };
485
+ function createSqliteTables(names = {}, options = {}) {
486
+ const n = { ...DEFAULT_TABLE_NAMES2, ...names };
487
+ const indexes = options.indexes ?? [];
488
+ assertNoSystemIndexNameCollision(indexes, n);
489
+ const nodes3 = sqliteTable(
490
+ n.nodes,
491
+ {
492
+ graphId: text$1("graph_id").notNull(),
493
+ kind: text$1("kind").notNull(),
494
+ id: text$1("id").notNull(),
495
+ props: text$1("props").notNull(),
496
+ version: integer$1("version").notNull().default(1),
497
+ validFrom: text$1("valid_from"),
498
+ validTo: text$1("valid_to"),
499
+ createdAt: text$1("created_at").notNull(),
500
+ updatedAt: text$1("updated_at").notNull(),
501
+ deletedAt: text$1("deleted_at")
502
+ },
503
+ (t) => [
504
+ primaryKey$1({ columns: [t.graphId, t.kind, t.id] }),
505
+ // System indexes come from SYSTEM_INDEX_DECLARATIONS (single source
506
+ // for both dialects + the runtime materializer).
507
+ ...buildSqliteSystemIndexBuilders("nodes", n.nodes, t),
508
+ ...buildSqliteNodeIndexBuilders(t, indexes)
509
+ ]
510
+ );
511
+ const edges3 = sqliteTable(
512
+ n.edges,
513
+ {
514
+ graphId: text$1("graph_id").notNull(),
515
+ id: text$1("id").notNull(),
516
+ kind: text$1("kind").notNull(),
517
+ fromKind: text$1("from_kind").notNull(),
518
+ fromId: text$1("from_id").notNull(),
519
+ toKind: text$1("to_kind").notNull(),
520
+ toId: text$1("to_id").notNull(),
521
+ props: text$1("props").notNull(),
522
+ validFrom: text$1("valid_from"),
523
+ validTo: text$1("valid_to"),
524
+ createdAt: text$1("created_at").notNull(),
525
+ updatedAt: text$1("updated_at").notNull(),
526
+ deletedAt: text$1("deleted_at")
527
+ },
528
+ (t) => [
529
+ primaryKey$1({ columns: [t.graphId, t.id] }),
530
+ ...buildSqliteSystemIndexBuilders("edges", n.edges, t),
531
+ ...buildSqliteEdgeIndexBuilders(t, indexes)
532
+ ]
533
+ );
534
+ const recordedNodes3 = sqliteTable(
535
+ n.recordedNodes,
536
+ {
537
+ historyId: text$1("history_id").notNull(),
538
+ graphId: text$1("graph_id").notNull(),
539
+ kind: text$1("kind").notNull(),
540
+ id: text$1("id").notNull(),
541
+ props: text$1("props").notNull(),
542
+ version: integer$1("version").notNull(),
543
+ validFrom: text$1("valid_from"),
544
+ validTo: text$1("valid_to"),
545
+ createdAt: text$1("created_at").notNull(),
546
+ updatedAt: text$1("updated_at").notNull(),
547
+ deletedAt: text$1("deleted_at"),
548
+ recordedFrom: integer$1("recorded_from").notNull(),
549
+ recordedTo: integer$1("recorded_to").notNull(),
550
+ op: text$1("op").notNull(),
551
+ schemaVersion: integer$1("schema_version"),
552
+ txId: text$1("tx_id"),
553
+ meta: text$1("meta")
554
+ },
555
+ (t) => [
556
+ primaryKey$1({ columns: [t.historyId] }),
557
+ ...buildSqliteSystemIndexBuilders("recordedNodes", n.recordedNodes, t)
558
+ ]
559
+ );
560
+ const recordedEdges3 = sqliteTable(
561
+ n.recordedEdges,
562
+ {
563
+ historyId: text$1("history_id").notNull(),
564
+ graphId: text$1("graph_id").notNull(),
565
+ id: text$1("id").notNull(),
566
+ kind: text$1("kind").notNull(),
567
+ fromKind: text$1("from_kind").notNull(),
568
+ fromId: text$1("from_id").notNull(),
569
+ toKind: text$1("to_kind").notNull(),
570
+ toId: text$1("to_id").notNull(),
571
+ props: text$1("props").notNull(),
572
+ validFrom: text$1("valid_from"),
573
+ validTo: text$1("valid_to"),
574
+ createdAt: text$1("created_at").notNull(),
575
+ updatedAt: text$1("updated_at").notNull(),
576
+ deletedAt: text$1("deleted_at"),
577
+ recordedFrom: integer$1("recorded_from").notNull(),
578
+ recordedTo: integer$1("recorded_to").notNull(),
579
+ op: text$1("op").notNull(),
580
+ schemaVersion: integer$1("schema_version"),
581
+ txId: text$1("tx_id"),
582
+ meta: text$1("meta")
583
+ },
584
+ (t) => [
585
+ primaryKey$1({ columns: [t.historyId] }),
586
+ ...buildSqliteSystemIndexBuilders("recordedEdges", n.recordedEdges, t)
587
+ ]
588
+ );
589
+ const recordedClock3 = sqliteTable(
590
+ n.recordedClock,
591
+ {
592
+ graphId: text$1("graph_id").notNull(),
593
+ revision: integer$1("revision").notNull(),
594
+ recordedAt: text$1("recorded_at").notNull()
595
+ },
596
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
597
+ );
598
+ const revisionOrigins = sqliteTable(
599
+ n.revisionOrigins,
600
+ {
601
+ graphId: text$1("graph_id").notNull(),
602
+ origin: text$1("origin").notNull()
603
+ },
604
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
605
+ );
606
+ const identityAssertions = sqliteTable(
607
+ n.identityAssertions,
608
+ {
609
+ graphId: text$1("graph_id").notNull(),
610
+ id: text$1("id").notNull(),
611
+ relation: text$1("rel").notNull(),
612
+ aKind: text$1("a_kind").notNull(),
613
+ aId: text$1("a_id").notNull(),
614
+ bKind: text$1("b_kind").notNull(),
615
+ bId: text$1("b_id").notNull(),
616
+ validFrom: text$1("valid_from").notNull(),
617
+ validTo: text$1("valid_to"),
618
+ createdAt: text$1("created_at").notNull(),
619
+ updatedAt: text$1("updated_at").notNull(),
620
+ deletedAt: text$1("deleted_at"),
621
+ endedByKind: text$1("ended_by_kind"),
622
+ endedById: text$1("ended_by_id")
623
+ },
624
+ (t) => [
625
+ primaryKey$1({ columns: [t.graphId, t.id] }),
626
+ index$1(`${n.identityAssertions}_a_idx`).on(
627
+ t.graphId,
628
+ t.aKind,
629
+ t.aId,
630
+ t.validTo
631
+ ),
632
+ index$1(`${n.identityAssertions}_b_idx`).on(
633
+ t.graphId,
634
+ t.bKind,
635
+ t.bId,
636
+ t.validTo
637
+ ),
638
+ uniqueIndex$1(`${n.identityAssertions}_current_pair_idx`).on(t.graphId, t.relation, t.aKind, t.aId, t.bKind, t.bId).where(sql`${t.validTo} IS NULL`),
639
+ check$1(
640
+ `${n.identityAssertions}_ended_by_check`,
641
+ sql`(ended_by_kind IS NULL) = (ended_by_id IS NULL) AND (ended_by_kind IS NULL OR (valid_to IS NOT NULL AND ((ended_by_kind = a_kind AND ended_by_id = a_id) OR (ended_by_kind = b_kind AND ended_by_id = b_id))))`
642
+ )
643
+ ]
644
+ );
645
+ const recordedIdentityAssertions = sqliteTable(
646
+ n.recordedIdentityAssertions,
647
+ {
648
+ historyId: text$1("history_id").notNull(),
649
+ graphId: text$1("graph_id").notNull(),
650
+ id: text$1("id").notNull(),
651
+ relation: text$1("rel").notNull(),
652
+ aKind: text$1("a_kind").notNull(),
653
+ aId: text$1("a_id").notNull(),
654
+ bKind: text$1("b_kind").notNull(),
655
+ bId: text$1("b_id").notNull(),
656
+ validFrom: text$1("valid_from").notNull(),
657
+ validTo: text$1("valid_to"),
658
+ createdAt: text$1("created_at").notNull(),
659
+ updatedAt: text$1("updated_at").notNull(),
660
+ deletedAt: text$1("deleted_at"),
661
+ endedByKind: text$1("ended_by_kind"),
662
+ endedById: text$1("ended_by_id"),
663
+ recordedFrom: integer$1("recorded_from").notNull(),
664
+ recordedTo: integer$1("recorded_to").notNull(),
665
+ op: text$1("op").notNull(),
666
+ schemaVersion: integer$1("schema_version"),
667
+ txId: text$1("tx_id"),
668
+ meta: text$1("meta")
669
+ },
670
+ (t) => [
671
+ primaryKey$1({ columns: [t.historyId] }),
672
+ index$1(`${n.recordedIdentityAssertions}_entity_idx`).on(
673
+ t.graphId,
674
+ t.id,
675
+ t.recordedFrom,
676
+ t.recordedTo
677
+ ),
678
+ index$1(`${n.recordedIdentityAssertions}_a_idx`).on(
679
+ t.graphId,
680
+ t.aKind,
681
+ t.aId,
682
+ t.recordedFrom,
683
+ t.recordedTo
684
+ ),
685
+ index$1(`${n.recordedIdentityAssertions}_b_idx`).on(
686
+ t.graphId,
687
+ t.bKind,
688
+ t.bId,
689
+ t.recordedFrom,
690
+ t.recordedTo
691
+ )
692
+ ]
693
+ );
694
+ const identityClosure = sqliteTable(
695
+ n.identityClosure,
696
+ {
697
+ graphId: text$1("graph_id").notNull(),
698
+ memberKind: text$1("member_kind").notNull(),
699
+ memberId: text$1("member_id").notNull(),
700
+ classKind: text$1("class_kind").notNull(),
701
+ classId: text$1("class_id").notNull()
702
+ },
703
+ (t) => [
704
+ primaryKey$1({ columns: [t.graphId, t.memberKind, t.memberId] }),
705
+ index$1(`${n.identityClosure}_class_idx`).on(
706
+ t.graphId,
707
+ t.classKind,
708
+ t.classId
709
+ )
710
+ ]
711
+ );
712
+ const identitySeparation = sqliteTable(
713
+ n.identitySeparation,
714
+ {
715
+ graphId: text$1("graph_id").notNull(),
716
+ classKeyLow: text$1("class_key_low").notNull(),
717
+ classKeyHigh: text$1("class_key_high").notNull()
718
+ },
719
+ (t) => [
720
+ primaryKey$1({ columns: [t.graphId, t.classKeyLow, t.classKeyHigh] }),
721
+ index$1(`${n.identitySeparation}_high_idx`).on(t.graphId, t.classKeyHigh),
722
+ check$1(
723
+ `${n.identitySeparation}_ordered_pair_check`,
724
+ sql`class_key_low < class_key_high`
725
+ )
726
+ ]
727
+ );
728
+ const uniques3 = sqliteTable(
729
+ n.uniques,
730
+ {
731
+ graphId: text$1("graph_id").notNull(),
732
+ nodeKind: text$1("node_kind").notNull(),
733
+ constraintName: text$1("constraint_name").notNull(),
734
+ key: text$1("key").notNull(),
735
+ nodeId: text$1("node_id").notNull(),
736
+ concreteKind: text$1("concrete_kind").notNull(),
737
+ deletedAt: text$1("deleted_at")
738
+ },
739
+ (t) => [
740
+ primaryKey$1({
741
+ columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
742
+ }),
743
+ index$1(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
744
+ ]
745
+ );
746
+ const edgeClaims3 = sqliteTable(
747
+ n.edgeClaims,
748
+ {
749
+ graphId: text$1("graph_id").notNull(),
750
+ axis: text$1("axis").notNull(),
751
+ key: text$1("key").notNull(),
752
+ edgeId: text$1("edge_id").notNull(),
753
+ updatedAt: text$1("updated_at").notNull()
754
+ },
755
+ (t) => [
756
+ primaryKey$1({ columns: [t.graphId, t.axis, t.key] }),
757
+ index$1(`${n.edgeClaims}_edge_idx`).on(t.graphId, t.edgeId)
758
+ ]
759
+ );
760
+ const schemaVersions3 = sqliteTable(
761
+ n.schemaVersions,
762
+ {
763
+ graphId: text$1("graph_id").notNull(),
764
+ version: integer$1("version").notNull(),
765
+ schemaHash: text$1("schema_hash").notNull(),
766
+ schemaDoc: text$1("schema_doc").notNull(),
767
+ createdAt: text$1("created_at").notNull(),
768
+ isActive: integer$1("is_active", { mode: "boolean" }).notNull().default(false)
769
+ },
770
+ (t) => [
771
+ primaryKey$1({ columns: [t.graphId, t.version] }),
772
+ index$1(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
773
+ // Partial unique index enforcing the "at most one active version
774
+ // per graph" invariant at the storage layer. Defense in depth
775
+ // against buggy backend implementations or out-of-band writes.
776
+ // Forces the deactivate-then-activate ordering used by
777
+ // `commitSchemaVersion` and `setActiveVersion`.
778
+ uniqueIndex$1(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = 1`)
779
+ ]
780
+ );
781
+ const indexMaterializations = sqliteTable(
782
+ n.indexMaterializations,
783
+ {
784
+ indexName: text$1("index_name").notNull(),
785
+ graphId: text$1("graph_id").notNull(),
786
+ entity: text$1("entity").notNull(),
787
+ kind: text$1("kind").notNull(),
788
+ signature: text$1("signature").notNull(),
789
+ schemaVersion: integer$1("schema_version").notNull(),
790
+ materializedAt: text$1("materialized_at"),
791
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
792
+ lastError: text$1("last_error")
793
+ },
794
+ (t) => [primaryKey$1({ columns: [t.indexName] })]
795
+ );
796
+ const kindRemovals = sqliteTable(
797
+ n.kindRemovals,
798
+ {
799
+ graphId: text$1("graph_id").notNull(),
800
+ kindName: text$1("kind_name").notNull(),
801
+ entity: text$1("entity").notNull(),
802
+ schemaVersion: integer$1("schema_version").notNull(),
803
+ removedAt: text$1("removed_at"),
804
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
805
+ lastError: text$1("last_error")
806
+ },
807
+ (t) => [
808
+ primaryKey$1({
809
+ columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
810
+ })
811
+ ]
812
+ );
813
+ const reconciliationMarkers = sqliteTable(
814
+ n.reconciliationMarkers,
815
+ {
816
+ graphId: text$1("graph_id").notNull(),
817
+ reconciledToVersion: integer$1("reconciled_to_version").notNull()
818
+ },
819
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
820
+ );
821
+ const contributionMaterializations = sqliteTable(
822
+ n.contributionMaterializations,
823
+ {
824
+ graphId: text$1("graph_id").notNull(),
825
+ logicalName: text$1("logical_name").notNull(),
826
+ owner: text$1("owner").notNull(),
827
+ tableName: text$1("table_name").notNull(),
828
+ signature: text$1("signature").notNull(),
829
+ materializedAt: text$1("materialized_at"),
830
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
831
+ lastError: text$1("last_error")
832
+ },
833
+ (t) => [
834
+ primaryKey$1({
835
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
836
+ })
837
+ ]
838
+ );
839
+ return {
840
+ nodes: nodes3,
841
+ edges: edges3,
842
+ recordedNodes: recordedNodes3,
843
+ recordedEdges: recordedEdges3,
844
+ recordedClock: recordedClock3,
845
+ revisionOrigins,
846
+ identityAssertions,
847
+ recordedIdentityAssertions,
848
+ identityClosure,
849
+ identitySeparation,
850
+ uniques: uniques3,
851
+ edgeClaims: edgeClaims3,
852
+ schemaVersions: schemaVersions3,
853
+ indexMaterializations,
854
+ contributionMaterializations,
855
+ kindRemovals,
856
+ reconciliationMarkers,
857
+ /**
858
+ * The fulltext storage is a FTS5 virtual table which Drizzle cannot
859
+ * represent. DDL is emitted as raw SQL and operations query it via
860
+ * `sql.raw()`.
861
+ */
862
+ fulltextTableName: n.fulltext
863
+ };
864
+ }
865
+ var tables2 = createSqliteTables();
866
+ var {
867
+ nodes: nodes2,
868
+ edges: edges2,
869
+ recordedNodes: recordedNodes2,
870
+ recordedEdges: recordedEdges2,
871
+ recordedClock: recordedClock2,
872
+ uniques: uniques2,
873
+ edgeClaims: edgeClaims2,
874
+ schemaVersions: schemaVersions2
875
+ } = tables2;
876
+ function getSqliteColumnType(column) {
877
+ switch (column.columnType) {
878
+ case "SQLiteText": {
879
+ return "TEXT";
880
+ }
881
+ case "SQLiteInteger": {
882
+ return "INTEGER";
883
+ }
884
+ case "SQLiteReal": {
885
+ return "REAL";
886
+ }
887
+ case "SQLiteBlob": {
888
+ return "BLOB";
889
+ }
890
+ default: {
891
+ return "TEXT";
892
+ }
893
+ }
894
+ }
895
+ function formatDefaultValue(value) {
896
+ if (value === null) return "NULL";
897
+ if (typeof value === "string") return `'${value}'`;
898
+ if (typeof value === "number") return String(value);
899
+ if (typeof value === "boolean") return value ? "1" : "0";
900
+ return JSON.stringify(value);
901
+ }
902
+ function generateSqliteCreateTableSQL(table) {
903
+ const config = getTableConfig(table);
904
+ const columnDefs = [];
905
+ for (const column of config.columns) {
906
+ const parts = [
907
+ `"${column.name}"`,
908
+ getSqliteColumnType(column)
909
+ ];
910
+ if (column.notNull) {
911
+ parts.push("NOT NULL");
912
+ }
913
+ if (column.hasDefault && column.default !== void 0) {
914
+ parts.push(`DEFAULT ${formatDefaultValue(column.default)}`);
915
+ }
916
+ columnDefs.push(parts.join(" "));
917
+ }
918
+ const pk = config.primaryKeys[0];
919
+ if (pk) {
920
+ const pkColumns = pk.columns.map((c) => `"${c.name}"`).join(", ");
921
+ columnDefs.push(`PRIMARY KEY (${pkColumns})`);
922
+ }
923
+ columnDefs.push(...renderTableChecks(config.checks, config.name));
924
+ return `CREATE TABLE IF NOT EXISTS "${config.name}" (
925
+ ${columnDefs.join(",\n ")}
926
+ );`;
927
+ }
928
+ function renderTableChecks(checks, tableName) {
929
+ return checks.map(
930
+ (check3) => `CONSTRAINT "${check3.name}" CHECK (${inlineSqlOrThrow(
931
+ check3.value,
932
+ `table "${tableName}" CHECK constraint "${check3.name}"`
933
+ )})`
934
+ );
935
+ }
936
+ function renderIndexColumn(col) {
937
+ if (col && typeof col === "object" && "name" in col) {
938
+ return `"${col.name}"`;
939
+ }
940
+ const sql19 = tryInlineSql(col);
941
+ if (sql19 !== void 0) {
942
+ return sql19;
943
+ }
944
+ return "unknown";
945
+ }
946
+ function tryInlineSql(value) {
947
+ if (value && typeof value === "object" && "getSQL" in value) {
948
+ const maybe = value;
949
+ if (typeof maybe.getSQL === "function") {
950
+ return inlineSql(maybe.getSQL());
951
+ }
952
+ }
953
+ return inlineSql(value);
954
+ }
955
+ function flattenSqlChunk(chunk2) {
956
+ if (typeof chunk2 === "string") {
957
+ return chunk2;
958
+ }
959
+ if (typeof chunk2 === "object" && chunk2 !== null) {
960
+ if ("name" in chunk2 && typeof chunk2.name === "string") {
961
+ return `"${chunk2.name}"`;
962
+ }
963
+ if ("value" in chunk2) {
964
+ const value = chunk2.value;
965
+ if (typeof value === "string") {
966
+ return value;
967
+ }
968
+ if (Array.isArray(value)) {
969
+ return value.map((part) => flattenSqlChunk(part)).join("");
970
+ }
971
+ }
972
+ if ("queryChunks" in chunk2 && Array.isArray(chunk2.queryChunks)) {
973
+ return chunk2.queryChunks.map((part) => flattenSqlChunk(part)).join("");
974
+ }
975
+ if ("getSQL" in chunk2) {
976
+ const maybe = chunk2;
977
+ if (typeof maybe.getSQL === "function") {
978
+ return flattenSqlChunk(maybe.getSQL());
979
+ }
980
+ }
981
+ }
982
+ throw new Error(`Unable to inline SQL chunk: ${String(chunk2)}`);
983
+ }
984
+ function inlineSql(value) {
985
+ try {
986
+ return flattenSqlChunk(value);
987
+ } catch {
988
+ return void 0;
989
+ }
990
+ }
991
+ function inlineSqlOrThrow(value, context) {
992
+ const inlined = inlineSql(value);
993
+ if (inlined === void 0) {
994
+ throw new Error(`Unable to inline SQL for ${context}`);
995
+ }
996
+ return inlined;
997
+ }
998
+ function generateSqliteCreateIndexSQL(table) {
999
+ const config = getTableConfig(table);
1000
+ const statements = [];
1001
+ for (const index3 of config.indexes) {
1002
+ const indexConfig = index3.config;
1003
+ const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
1004
+ const unique = indexConfig.unique ? "UNIQUE " : "";
1005
+ const where = indexConfig.where ? ` WHERE ${inlineSqlOrThrow(indexConfig.where, `SQLite index "${indexConfig.name}" WHERE clause`)}` : "";
1006
+ statements.push(
1007
+ `CREATE ${unique}INDEX IF NOT EXISTS "${indexConfig.name}" ON "${config.name}" (${columns})${where};`
1008
+ );
1009
+ }
1010
+ return statements;
1011
+ }
1012
+ function isSqliteTable(value) {
1013
+ return is(value, SQLiteTable);
1014
+ }
1015
+ function runtimeStrategyContributions(fulltextStrategy, fulltextTableName) {
1016
+ return fulltextStrategy.ownedTables(fulltextTableName).filter((contribution) => contribution.runtimeEnsure);
1017
+ }
1018
+ function sqliteContributions(tables3 = tables2, fulltextStrategy = fts5Strategy) {
1019
+ const contributions = [];
1020
+ for (const [key, table] of Object.entries(tables3)) {
1021
+ if (!isSqliteTable(table)) continue;
1022
+ contributions.push({
1023
+ logicalName: key,
1024
+ owner: BASE_CONTRIBUTION_OWNER,
1025
+ tableName: getTableConfig(table).name,
1026
+ createDdl: [
1027
+ generateSqliteCreateTableSQL(table),
1028
+ ...generateSqliteCreateIndexSQL(table)
1029
+ ],
1030
+ runtimeEnsure: false
1031
+ });
1032
+ }
1033
+ for (const declared of fulltextStrategy.ownedTables(
1034
+ tables3.fulltextTableName
1035
+ )) {
1036
+ contributions.push(declared);
1037
+ }
1038
+ return contributions;
1039
+ }
1040
+ function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
1041
+ return sqliteContributions(tables3, fulltextStrategy).flatMap(
1042
+ (contribution) => [...contribution.createDdl]
1043
+ );
1044
+ }
1045
+ function generateSqliteMigrationSQL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
1046
+ return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
1047
+ }
1048
+ function getPgColumnType(column) {
1049
+ switch (column.columnType) {
1050
+ case "PgText": {
1051
+ return "TEXT";
1052
+ }
1053
+ case "PgInteger": {
1054
+ return "INTEGER";
1055
+ }
1056
+ case "PgBigInt53":
1057
+ case "PgBigInt64": {
1058
+ return "BIGINT";
1059
+ }
1060
+ case "PgBoolean": {
1061
+ return "BOOLEAN";
1062
+ }
1063
+ case "PgJsonb": {
1064
+ return "JSONB";
1065
+ }
1066
+ case "PgTimestamp": {
1067
+ return column.config?.withTimezone ? "TIMESTAMPTZ" : "TIMESTAMP";
1068
+ }
1069
+ case "PgReal": {
1070
+ return "REAL";
1071
+ }
1072
+ case "PgDoublePrecision": {
1073
+ return "DOUBLE PRECISION";
1074
+ }
1075
+ case "PgCustomColumn": {
1076
+ const dataType = column.getSQLType?.();
1077
+ return dataType ?? "TEXT";
1078
+ }
1079
+ default: {
1080
+ return "TEXT";
1081
+ }
1082
+ }
1083
+ }
1084
+ function formatPgDefaultValue(value) {
1085
+ if (value === null) return "NULL";
1086
+ if (typeof value === "string") return `'${value}'`;
1087
+ if (typeof value === "number") return String(value);
1088
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
1089
+ return JSON.stringify(value);
1090
+ }
1091
+ function generatePgCreateTableSQL(table) {
1092
+ const config = getTableConfig$1(table);
1093
+ const columnDefs = [];
1094
+ for (const column of config.columns) {
1095
+ const parts = [`"${column.name}"`, getPgColumnType(column)];
1096
+ if (column.notNull) {
1097
+ parts.push("NOT NULL");
1098
+ }
1099
+ if (column.hasDefault && column.default !== void 0) {
1100
+ parts.push(`DEFAULT ${formatPgDefaultValue(column.default)}`);
1101
+ }
1102
+ columnDefs.push(parts.join(" "));
1103
+ }
1104
+ const pk = config.primaryKeys[0];
1105
+ if (pk) {
1106
+ const pkColumns = pk.columns.map((c) => `"${c.name}"`).join(", ");
1107
+ columnDefs.push(`PRIMARY KEY (${pkColumns})`);
1108
+ }
1109
+ columnDefs.push(...renderTableChecks(config.checks, config.name));
1110
+ return `CREATE TABLE IF NOT EXISTS "${config.name}" (
1111
+ ${columnDefs.join(",\n ")}
1112
+ );`;
1113
+ }
1114
+ function generatePgCreateIndexSQL(table) {
1115
+ const config = getTableConfig$1(table);
1116
+ const statements = [];
1117
+ for (const index3 of config.indexes) {
1118
+ const indexConfig = index3.config;
1119
+ const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
1120
+ const unique = indexConfig.unique ? "UNIQUE " : "";
1121
+ const method = indexConfig.method && indexConfig.method !== "btree" ? ` USING ${indexConfig.method}` : "";
1122
+ const where = indexConfig.where ? ` WHERE ${inlineSqlOrThrow(indexConfig.where, `PostgreSQL index "${indexConfig.name}" WHERE clause`)}` : "";
1123
+ statements.push(
1124
+ `CREATE ${unique}INDEX IF NOT EXISTS "${indexConfig.name}" ON "${config.name}"${method} (${columns})${where};`
1125
+ );
1126
+ }
1127
+ return statements;
1128
+ }
1129
+ function isPgTable(value) {
1130
+ return is(value, PgTable);
1131
+ }
1132
+ function postgresContributions(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
1133
+ const contributions = [];
1134
+ for (const [key, table] of Object.entries(tables3)) {
1135
+ if (!isPgTable(table)) continue;
1136
+ if (table === tables3.fulltext) continue;
1137
+ contributions.push({
1138
+ logicalName: key,
1139
+ owner: BASE_CONTRIBUTION_OWNER,
1140
+ tableName: getTableConfig$1(table).name,
1141
+ createDdl: [
1142
+ generatePgCreateTableSQL(table),
1143
+ ...generatePgCreateIndexSQL(table)
1144
+ ],
1145
+ runtimeEnsure: false
1146
+ });
1147
+ }
1148
+ for (const declared of fulltextStrategy.ownedTables(
1149
+ tables3.fulltextTableName
1150
+ )) {
1151
+ contributions.push(declared);
1152
+ }
1153
+ return contributions;
1154
+ }
1155
+ function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
1156
+ return postgresContributions(tables3, fulltextStrategy).flatMap(
1157
+ (contribution) => [...contribution.createDdl]
1158
+ );
1159
+ }
1160
+ function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
1161
+ const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
1162
+ const ddlSql = generatePostgresDDL(tables3, fulltextStrategy).join("\n\n");
1163
+ return `${extensionSql}
1164
+
1165
+ ${ddlSql}`;
1166
+ }
1167
+
1168
+ // src/backend/capabilities/declarations.ts
1169
+ function deepFreeze(value) {
1170
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) {
1171
+ return value;
1172
+ }
1173
+ Object.freeze(value);
1174
+ for (const propertyValue of Object.values(value)) {
1175
+ deepFreeze(propertyValue);
1176
+ }
1177
+ return value;
1178
+ }
1179
+ function assertBundledCapabilityDeclarations(capabilities) {
1180
+ const { recursiveTraversal } = capabilities;
1181
+ if (recursiveTraversal?.supported === false && recursiveTraversal.reason === void 0) {
1182
+ throw new ConfigurationError(
1183
+ "Backend capability declaration is contradictory: recursiveTraversal.supported is false but no reason is given.",
1184
+ {
1185
+ code: "CAPABILITY_DECLARATION_CONTRADICTION",
1186
+ member: "recursiveTraversal",
1187
+ missing: "reason"
1188
+ },
1189
+ {
1190
+ suggestion: "Supply a `reason` explaining why this backend cannot perform recursive traversal."
1191
+ }
1192
+ );
1193
+ }
1194
+ if (recursiveTraversal?.supported === true && recursiveTraversal.reason !== void 0) {
1195
+ throw new ConfigurationError(
1196
+ "Backend capability declaration is contradictory: recursiveTraversal.supported is true but a dangling reason is present.",
1197
+ {
1198
+ code: "CAPABILITY_DECLARATION_CONTRADICTION",
1199
+ member: "recursiveTraversal",
1200
+ danglingReason: recursiveTraversal.reason
1201
+ },
1202
+ {
1203
+ suggestion: "Remove `reason` when recursiveTraversal.supported is true \u2014 it is only meaningful alongside `supported: false`."
1204
+ }
1205
+ );
1206
+ }
1207
+ return deepFreeze(structuredClone(capabilities));
1208
+ }
14
1209
 
15
1210
  // src/backend/edge-endpoint-sets.ts
16
1211
  var FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT = 6;
@@ -79,10 +1274,10 @@ function resolveHeterogeneousEdgeRead(params, maxBindParameters) {
79
1274
 
80
1275
  // src/backend/live-node-candidates.ts
81
1276
  function buildLiveNodeCandidates(nodesTableName, graphId, nodeKind, now) {
82
- const nodes = sql$1.identifier(nodesTableName);
1277
+ const nodes3 = sql$1.identifier(nodesTableName);
83
1278
  return sql$1`
84
1279
  SELECT "id" AS node_id
85
- FROM ${nodes}
1280
+ FROM ${nodes3}
86
1281
  WHERE "graph_id" = ${graphId}
87
1282
  AND "kind" = ${nodeKind}
88
1283
  AND "deleted_at" IS NULL
@@ -385,7 +1580,7 @@ function createContributionMaterializer(deps) {
385
1580
  const cachedCreateDdl = cached?.createDdl;
386
1581
  const cachedSignature = cached?.signature;
387
1582
  if (cachedCreateDdl?.length === contribution.createDdl.length && cachedSignature !== void 0 && contribution.createDdl.every(
388
- (statement, index) => cachedCreateDdl[index] === statement
1583
+ (statement, index3) => cachedCreateDdl[index3] === statement
389
1584
  )) {
390
1585
  return cachedSignature;
391
1586
  }
@@ -753,20 +1948,42 @@ function createContributionMaterializer(deps) {
753
1948
  };
754
1949
  }
755
1950
  async function lockContributionDdl(tx) {
756
- if (dialect !== "postgres") return;
757
- await tx.execute(
758
- asCompiledRowsSql(
759
- sql$1`SELECT pg_advisory_xact_lock(hashtext(${CONTRIBUTION_DDL_LOCK_KEY}), 0)`
760
- )
761
- );
1951
+ const plan = resolveWriteFencePlan(deps.fenceTarget);
1952
+ const fence = requireWriteFence(plan, "contribution DDL", "advisory-lock");
1953
+ switch (fence.kind) {
1954
+ case "lock": {
1955
+ await tx.execute(
1956
+ asCompiledRowsSql(
1957
+ sql$1`SELECT pg_advisory_xact_lock(hashtext(${CONTRIBUTION_DDL_LOCK_KEY}), 0)`
1958
+ )
1959
+ );
1960
+ return;
1961
+ }
1962
+ case "engine-serialized": {
1963
+ return;
1964
+ }
1965
+ }
762
1966
  }
763
1967
  async function lockSharedFulltextTable(tx, tableName) {
764
- if (dialect !== "postgres") return;
765
- await tx.executeStatement(
766
- asCompiledStatementSql(
767
- sql$1`LOCK TABLE ${sql$1.identifier(tableName)} IN ACCESS EXCLUSIVE MODE`
768
- )
1968
+ const plan = resolveWriteFencePlan(deps.fenceTarget);
1969
+ const fence = requireWriteFence(
1970
+ plan,
1971
+ "shared fulltext table lock",
1972
+ "table-lock"
769
1973
  );
1974
+ switch (fence.kind) {
1975
+ case "lock": {
1976
+ await tx.executeStatement(
1977
+ asCompiledStatementSql(
1978
+ sql$1`LOCK TABLE ${sql$1.identifier(tableName)} IN ACCESS EXCLUSIVE MODE`
1979
+ )
1980
+ );
1981
+ return;
1982
+ }
1983
+ case "engine-serialized": {
1984
+ return;
1985
+ }
1986
+ }
770
1987
  }
771
1988
  async function readForeignGraphIds(tx, tableName, graphId) {
772
1989
  const rows = await tx.execute(
@@ -1041,6 +2258,66 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
1041
2258
  lastError: sql`excluded.${sql.identifier("last_error")}`
1042
2259
  };
1043
2260
  }
2261
+ function primaryKeyConstraintNames(relation, keyColumns) {
2262
+ return [`${relation}_pkey`, `${relation}_${keyColumns.join("_")}_pk`];
2263
+ }
2264
+ function nodePrimaryKeyConstraint(nodes3) {
2265
+ const relation = getTableName(nodes3);
2266
+ return {
2267
+ table: relation,
2268
+ constraintNames: primaryKeyConstraintNames(relation, [
2269
+ nodes3.graphId.name,
2270
+ nodes3.kind.name,
2271
+ nodes3.id.name
2272
+ ])
2273
+ };
2274
+ }
2275
+ function edgePrimaryKeyConstraint(edges3) {
2276
+ const relation = getTableName(edges3);
2277
+ return {
2278
+ table: relation,
2279
+ constraintNames: primaryKeyConstraintNames(relation, [
2280
+ edges3.graphId.name,
2281
+ edges3.id.name
2282
+ ])
2283
+ };
2284
+ }
2285
+ function sqlNull(value) {
2286
+ return value ?? sql.raw("NULL");
2287
+ }
2288
+ function expectedValidFromPredicate(column, expected) {
2289
+ if (expected === void 0) return sql.empty();
2290
+ if (expected === null) return sql` AND ${column} IS NULL`;
2291
+ return sql` AND ${column} = ${expected}`;
2292
+ }
2293
+ function quotedColumn(column) {
2294
+ return sql.raw(`"${column.name.replaceAll('"', '""')}"`);
2295
+ }
2296
+ function quotedTableName(tableName) {
2297
+ return sql.raw(`"${tableName.replaceAll('"', '""')}"`);
2298
+ }
2299
+ var CODE_POINT_ORDER_BUILDERS = {
2300
+ postgres: (value) => sql`${value} COLLATE "C"`,
2301
+ sqlite: (value) => value
2302
+ };
2303
+ function codePointOrderKey(column, dialect) {
2304
+ return CODE_POINT_ORDER_BUILDERS[dialect](column);
2305
+ }
2306
+ function liveNodeIdsSubquery(nodes3, graphId, nodeKind, nowIso2) {
2307
+ return sql`SELECT ${nodes3.id} AS node_id FROM ${nodes3} WHERE ${nodes3.graphId} = ${graphId} AND ${nodes3.kind} = ${nodeKind} AND ${nodes3.deletedAt} IS NULL AND (${nodes3.validFrom} IS NULL OR ${nodes3.validFrom} <= ${nowIso2}) AND (${nodes3.validTo} IS NULL OR ${nodes3.validTo} > ${nowIso2})`;
2308
+ }
2309
+ function nodeColumnList(nodes3) {
2310
+ return sql.raw(
2311
+ `"${nodes3.graphId.name}", "${nodes3.kind.name}", "${nodes3.id.name}", "${nodes3.props.name}", "${nodes3.version.name}", "${nodes3.validFrom.name}", "${nodes3.validTo.name}", "${nodes3.createdAt.name}", "${nodes3.updatedAt.name}"`
2312
+ );
2313
+ }
2314
+ function edgeColumnList(edges3) {
2315
+ return sql.raw(
2316
+ `"${edges3.graphId.name}", "${edges3.id.name}", "${edges3.kind.name}", "${edges3.fromKind.name}", "${edges3.fromId.name}", "${edges3.toKind.name}", "${edges3.toId.name}", "${edges3.props.name}", "${edges3.validFrom.name}", "${edges3.validTo.name}", "${edges3.createdAt.name}", "${edges3.updatedAt.name}"`
2317
+ );
2318
+ }
2319
+
2320
+ // src/backend/drizzle/operations/hybrid.ts
1044
2321
  function nodeIdOrderKey(dialect) {
1045
2322
  return codePointOrderKey(sql.raw("node_id"), dialect);
1046
2323
  }
@@ -1048,20 +2325,20 @@ function hybridCandidatesRef() {
1048
2325
  return sql`SELECT node_id FROM tg_hybrid_cand`;
1049
2326
  }
1050
2327
  function buildHybridSearchStatement(input) {
1051
- const { nodes } = input;
2328
+ const { nodes: nodes3 } = input;
1052
2329
  const nodeIdOrder = nodeIdOrderKey(input.dialect);
1053
2330
  const vectorOrder = input.vectorScoreDescending ? sql`score DESC, ${nodeIdOrder} ASC` : sql`score ASC, ${nodeIdOrder} ASC`;
1054
2331
  const columnPairs = [
1055
- [nodes.graphId, "graph_id"],
1056
- [nodes.kind, "kind"],
1057
- [nodes.id, "id"],
1058
- [nodes.props, "props"],
1059
- [nodes.version, "version"],
1060
- [nodes.validFrom, "valid_from"],
1061
- [nodes.validTo, "valid_to"],
1062
- [nodes.createdAt, "created_at"],
1063
- [nodes.updatedAt, "updated_at"],
1064
- [nodes.deletedAt, "deleted_at"]
2332
+ [nodes3.graphId, "graph_id"],
2333
+ [nodes3.kind, "kind"],
2334
+ [nodes3.id, "id"],
2335
+ [nodes3.props, "props"],
2336
+ [nodes3.version, "version"],
2337
+ [nodes3.validFrom, "valid_from"],
2338
+ [nodes3.validTo, "valid_to"],
2339
+ [nodes3.createdAt, "created_at"],
2340
+ [nodes3.updatedAt, "updated_at"],
2341
+ [nodes3.deletedAt, "deleted_at"]
1065
2342
  ];
1066
2343
  const nodeColumns = sql.raw(
1067
2344
  columnPairs.map(
@@ -1114,17 +2391,17 @@ function buildHybridSearchStatement(input) {
1114
2391
  tg_hybrid_fused.snippet AS snippet,
1115
2392
  ${nodeColumns}
1116
2393
  FROM tg_hybrid_fused
1117
- JOIN ${nodes} AS tg_hybrid_node
1118
- ON ${qualified(nodes, "graphId")} = ${input.graphId}
1119
- AND ${qualified(nodes, "kind")} = ${input.nodeKind}
1120
- AND ${qualified(nodes, "id")} = tg_hybrid_fused.node_id
1121
- AND ${qualified(nodes, "deletedAt")} IS NULL
2394
+ JOIN ${nodes3} AS tg_hybrid_node
2395
+ ON ${qualified(nodes3, "graphId")} = ${input.graphId}
2396
+ AND ${qualified(nodes3, "kind")} = ${input.nodeKind}
2397
+ AND ${qualified(nodes3, "id")} = tg_hybrid_fused.node_id
2398
+ AND ${qualified(nodes3, "deletedAt")} IS NULL
1122
2399
  ORDER BY fused_score DESC, ${nodeIdOrder} ASC
1123
2400
  LIMIT ${input.limit} OFFSET ${input.offset}
1124
2401
  `;
1125
2402
  }
1126
- function qualified(nodes, member) {
1127
- return sql`tg_hybrid_node.${quotedColumn(nodes[member])}`;
2403
+ function qualified(nodes3, member) {
2404
+ return sql`tg_hybrid_node.${quotedColumn(nodes3[member])}`;
1128
2405
  }
1129
2406
  function present(value) {
1130
2407
  return value !== null && value !== void 0;
@@ -1144,49 +2421,49 @@ function mapHybridSearchRow(row, toNodeRow) {
1144
2421
  ...present(row["snippet"]) ? { snippet: String(row["snippet"]) } : {}
1145
2422
  };
1146
2423
  }
1147
- function buildClearGraph(tables, graphId) {
2424
+ function buildClearGraph(tables3, graphId) {
1148
2425
  return [
1149
2426
  // The fulltext table is shared by every graph in the database, so its
1150
2427
  // graph-scoped delete is owned by one builder the destructive
1151
2428
  // contribution rebuild calls too — see `buildFulltextGraphDelete`.
1152
- { query: buildFulltextGraphDelete(tables.fulltextTableName, graphId) },
2429
+ { query: buildFulltextGraphDelete(tables3.fulltextTableName, graphId) },
1153
2430
  {
1154
- query: sql`DELETE FROM ${tables.recordedIdentityAssertions} WHERE ${tables.recordedIdentityAssertions.graphId} = ${graphId}`,
2431
+ query: sql`DELETE FROM ${tables3.recordedIdentityAssertions} WHERE ${tables3.recordedIdentityAssertions.graphId} = ${graphId}`,
1155
2432
  ignoreMissingTable: true,
1156
- requiredTableName: getTableName(tables.recordedIdentityAssertions)
2433
+ requiredTableName: getTableName(tables3.recordedIdentityAssertions)
1157
2434
  },
1158
2435
  {
1159
- query: sql`DELETE FROM ${tables.recordedEdges} WHERE ${tables.recordedEdges.graphId} = ${graphId}`,
2436
+ query: sql`DELETE FROM ${tables3.recordedEdges} WHERE ${tables3.recordedEdges.graphId} = ${graphId}`,
1160
2437
  ignoreMissingTable: true,
1161
- requiredTableName: getTableName(tables.recordedEdges)
2438
+ requiredTableName: getTableName(tables3.recordedEdges)
1162
2439
  },
1163
2440
  {
1164
- query: sql`DELETE FROM ${tables.recordedNodes} WHERE ${tables.recordedNodes.graphId} = ${graphId}`,
2441
+ query: sql`DELETE FROM ${tables3.recordedNodes} WHERE ${tables3.recordedNodes.graphId} = ${graphId}`,
1165
2442
  ignoreMissingTable: true,
1166
- requiredTableName: getTableName(tables.recordedNodes)
2443
+ requiredTableName: getTableName(tables3.recordedNodes)
1167
2444
  },
1168
2445
  {
1169
- query: sql`DELETE FROM ${tables.recordedClock} WHERE ${tables.recordedClock.graphId} = ${graphId}`,
2446
+ query: sql`DELETE FROM ${tables3.recordedClock} WHERE ${tables3.recordedClock.graphId} = ${graphId}`,
1170
2447
  ignoreMissingTable: true,
1171
- requiredTableName: getTableName(tables.recordedClock)
2448
+ requiredTableName: getTableName(tables3.recordedClock)
1172
2449
  },
1173
2450
  {
1174
- query: sql`DELETE FROM ${tables.identitySeparation} WHERE ${tables.identitySeparation.graphId} = ${graphId}`,
2451
+ query: sql`DELETE FROM ${tables3.identitySeparation} WHERE ${tables3.identitySeparation.graphId} = ${graphId}`,
1175
2452
  ignoreMissingTable: true,
1176
- requiredTableName: getTableName(tables.identitySeparation)
2453
+ requiredTableName: getTableName(tables3.identitySeparation)
1177
2454
  },
1178
2455
  {
1179
- query: sql`DELETE FROM ${tables.identityClosure} WHERE ${tables.identityClosure.graphId} = ${graphId}`,
2456
+ query: sql`DELETE FROM ${tables3.identityClosure} WHERE ${tables3.identityClosure.graphId} = ${graphId}`,
1180
2457
  ignoreMissingTable: true,
1181
- requiredTableName: getTableName(tables.identityClosure)
2458
+ requiredTableName: getTableName(tables3.identityClosure)
1182
2459
  },
1183
2460
  {
1184
- query: sql`DELETE FROM ${tables.identityAssertions} WHERE ${tables.identityAssertions.graphId} = ${graphId}`,
2461
+ query: sql`DELETE FROM ${tables3.identityAssertions} WHERE ${tables3.identityAssertions.graphId} = ${graphId}`,
1185
2462
  ignoreMissingTable: true,
1186
- requiredTableName: getTableName(tables.identityAssertions)
2463
+ requiredTableName: getTableName(tables3.identityAssertions)
1187
2464
  },
1188
2465
  {
1189
- query: sql`DELETE FROM ${tables.uniques} WHERE ${tables.uniques.graphId} = ${graphId}`
2466
+ query: sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`
1190
2467
  },
1191
2468
  // Edge claims name the edges they are held by, so they are cleared
1192
2469
  // BEFORE the edges — the same ordering `uniques` gets against `nodes`.
@@ -1195,27 +2472,27 @@ function buildClearGraph(tables, graphId) {
1195
2472
  // existed has no such table, and clearing a graph must not become the
1196
2473
  // operation that fails on it.
1197
2474
  {
1198
- query: sql`DELETE FROM ${tables.edgeClaims} WHERE ${tables.edgeClaims.graphId} = ${graphId}`,
2475
+ query: sql`DELETE FROM ${tables3.edgeClaims} WHERE ${tables3.edgeClaims.graphId} = ${graphId}`,
1199
2476
  ignoreMissingTable: true,
1200
- requiredTableName: getTableName(tables.edgeClaims)
2477
+ requiredTableName: getTableName(tables3.edgeClaims)
1201
2478
  },
1202
2479
  {
1203
- query: sql`DELETE FROM ${tables.edges} WHERE ${tables.edges.graphId} = ${graphId}`
2480
+ query: sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`
1204
2481
  },
1205
2482
  {
1206
- query: sql`DELETE FROM ${tables.nodes} WHERE ${tables.nodes.graphId} = ${graphId}`
2483
+ query: sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`
1207
2484
  },
1208
2485
  {
1209
- query: sql`DELETE FROM ${tables.indexMaterializations} WHERE ${tables.indexMaterializations.graphId} = ${graphId}`
2486
+ query: sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`
1210
2487
  },
1211
2488
  {
1212
- query: sql`DELETE FROM ${tables.kindRemovals} WHERE ${tables.kindRemovals.graphId} = ${graphId}`
2489
+ query: sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`
1213
2490
  },
1214
2491
  {
1215
- query: sql`DELETE FROM ${tables.reconciliationMarkers} WHERE ${tables.reconciliationMarkers.graphId} = ${graphId}`
2492
+ query: sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
1216
2493
  },
1217
2494
  {
1218
- query: sql`DELETE FROM ${tables.schemaVersions} WHERE ${tables.schemaVersions.graphId} = ${graphId}`
2495
+ query: sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
1219
2496
  }
1220
2497
  ];
1221
2498
  }
@@ -1237,21 +2514,21 @@ function buildTemporalConditions(table, params) {
1237
2514
  }
1238
2515
  return conditions;
1239
2516
  }
1240
- function buildFindNodesByKind(tables, params) {
1241
- const { nodes } = tables;
2517
+ function buildFindNodesByKind(tables3, params) {
2518
+ const { nodes: nodes3 } = tables3;
1242
2519
  const conditions = [
1243
- sql`${nodes.graphId} = ${params.graphId}`,
1244
- sql`${nodes.kind} = ${params.kind}`,
1245
- ...buildTemporalConditions(nodes, params)
2520
+ sql`${nodes3.graphId} = ${params.graphId}`,
2521
+ sql`${nodes3.kind} = ${params.kind}`,
2522
+ ...buildTemporalConditions(nodes3, params)
1246
2523
  ];
1247
2524
  if (params.orderBy === "id" && params.after !== void 0) {
1248
- conditions.push(sql`${nodes.id} > ${params.after}`);
2525
+ conditions.push(sql`${nodes3.id} > ${params.after}`);
1249
2526
  }
1250
2527
  const whereClause = sql.join(conditions, sql` AND `);
1251
- const orderByClause = params.orderBy === "id" ? sql`${nodes.id} ASC` : sql`${nodes.createdAt} DESC, ${nodes.id} DESC`;
2528
+ const orderByClause = params.orderBy === "id" ? sql`${nodes3.id} ASC` : sql`${nodes3.createdAt} DESC, ${nodes3.id} DESC`;
1252
2529
  if (params.limit !== void 0 && params.offset !== void 0) {
1253
2530
  return sql`
1254
- SELECT * FROM ${nodes}
2531
+ SELECT * FROM ${nodes3}
1255
2532
  WHERE ${whereClause}
1256
2533
  ORDER BY ${orderByClause}
1257
2534
  LIMIT ${params.limit} OFFSET ${params.offset}
@@ -1259,28 +2536,28 @@ function buildFindNodesByKind(tables, params) {
1259
2536
  }
1260
2537
  if (params.limit !== void 0) {
1261
2538
  return sql`
1262
- SELECT * FROM ${nodes}
2539
+ SELECT * FROM ${nodes3}
1263
2540
  WHERE ${whereClause}
1264
2541
  ORDER BY ${orderByClause}
1265
2542
  LIMIT ${params.limit}
1266
2543
  `;
1267
2544
  }
1268
2545
  return sql`
1269
- SELECT * FROM ${nodes}
2546
+ SELECT * FROM ${nodes3}
1270
2547
  WHERE ${whereClause}
1271
2548
  ORDER BY ${orderByClause}
1272
2549
  `;
1273
2550
  }
1274
- function buildCountNodesByKind(tables, params) {
1275
- const { nodes } = tables;
2551
+ function buildCountNodesByKind(tables3, params) {
2552
+ const { nodes: nodes3 } = tables3;
1276
2553
  const conditions = [
1277
- sql`${nodes.graphId} = ${params.graphId}`,
1278
- sql`${nodes.kind} = ${params.kind}`,
1279
- ...buildTemporalConditions(nodes, params)
2554
+ sql`${nodes3.graphId} = ${params.graphId}`,
2555
+ sql`${nodes3.kind} = ${params.kind}`,
2556
+ ...buildTemporalConditions(nodes3, params)
1280
2557
  ];
1281
2558
  const whereClause = sql.join(conditions, sql` AND `);
1282
2559
  return sql`
1283
- SELECT COUNT(*) as count FROM ${nodes}
2560
+ SELECT COUNT(*) as count FROM ${nodes3}
1284
2561
  WHERE ${whereClause}
1285
2562
  `;
1286
2563
  }
@@ -1290,43 +2567,43 @@ function buildIdSetCondition(column, ids) {
1290
2567
  sql`, `
1291
2568
  )})`;
1292
2569
  }
1293
- function buildEdgeOrdering(tables, orderBy) {
1294
- const { edges } = tables;
1295
- return orderBy === "id" ? { qualified: sql`${edges.id} ASC`, bare: sql.raw(`"id" ASC`) } : {
1296
- qualified: sql`${edges.createdAt} DESC, ${edges.id} DESC`,
2570
+ function buildEdgeOrdering(tables3, orderBy) {
2571
+ const { edges: edges3 } = tables3;
2572
+ return orderBy === "id" ? { qualified: sql`${edges3.id} ASC`, bare: sql.raw(`"id" ASC`) } : {
2573
+ qualified: sql`${edges3.createdAt} DESC, ${edges3.id} DESC`,
1297
2574
  bare: sql.raw(`"created_at" DESC, "id" DESC`)
1298
2575
  };
1299
2576
  }
1300
- function buildFindEdgesByKind(tables, params) {
1301
- const { edges } = tables;
2577
+ function buildFindEdgesByKind(tables3, params) {
2578
+ const { edges: edges3 } = tables3;
1302
2579
  const conditions = [
1303
- sql`${edges.graphId} = ${params.graphId}`,
1304
- sql`${edges.kind} = ${params.kind}`,
1305
- ...buildTemporalConditions(edges, params)
2580
+ sql`${edges3.graphId} = ${params.graphId}`,
2581
+ sql`${edges3.kind} = ${params.kind}`,
2582
+ ...buildTemporalConditions(edges3, params)
1306
2583
  ];
1307
2584
  if (params.fromKind !== void 0) {
1308
- conditions.push(sql`${edges.fromKind} = ${params.fromKind}`);
2585
+ conditions.push(sql`${edges3.fromKind} = ${params.fromKind}`);
1309
2586
  }
1310
2587
  if (params.fromId !== void 0) {
1311
- conditions.push(sql`${edges.fromId} = ${params.fromId}`);
2588
+ conditions.push(sql`${edges3.fromId} = ${params.fromId}`);
1312
2589
  }
1313
2590
  if (params.toKind !== void 0) {
1314
- conditions.push(sql`${edges.toKind} = ${params.toKind}`);
2591
+ conditions.push(sql`${edges3.toKind} = ${params.toKind}`);
1315
2592
  }
1316
2593
  if (params.toId !== void 0) {
1317
- conditions.push(sql`${edges.toId} = ${params.toId}`);
2594
+ conditions.push(sql`${edges3.toId} = ${params.toId}`);
1318
2595
  }
1319
2596
  if (params.orderBy === "id" && params.after !== void 0) {
1320
- conditions.push(sql`${edges.id} > ${params.after}`);
2597
+ conditions.push(sql`${edges3.id} > ${params.after}`);
1321
2598
  }
1322
2599
  const whereClause = sql.join(conditions, sql` AND `);
1323
2600
  const { qualified: orderByClause } = buildEdgeOrdering(
1324
- tables,
2601
+ tables3,
1325
2602
  params.orderBy
1326
2603
  );
1327
2604
  if (params.limit !== void 0 && params.offset !== void 0) {
1328
2605
  return sql`
1329
- SELECT * FROM ${edges}
2606
+ SELECT * FROM ${edges3}
1330
2607
  WHERE ${whereClause}
1331
2608
  ORDER BY ${orderByClause}
1332
2609
  LIMIT ${params.limit} OFFSET ${params.offset}
@@ -1334,37 +2611,37 @@ function buildFindEdgesByKind(tables, params) {
1334
2611
  }
1335
2612
  if (params.limit !== void 0) {
1336
2613
  return sql`
1337
- SELECT * FROM ${edges}
2614
+ SELECT * FROM ${edges3}
1338
2615
  WHERE ${whereClause}
1339
2616
  ORDER BY ${orderByClause}
1340
2617
  LIMIT ${params.limit}
1341
2618
  `;
1342
2619
  }
1343
2620
  return sql`
1344
- SELECT * FROM ${edges}
2621
+ SELECT * FROM ${edges3}
1345
2622
  WHERE ${whereClause}
1346
2623
  ORDER BY ${orderByClause}
1347
2624
  `;
1348
2625
  }
1349
- function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1350
- const { edges } = tables;
2626
+ function buildFindEdgesByEndpointSet(tables3, params, endpointIds) {
2627
+ const { edges: edges3 } = tables3;
1351
2628
  const fromSide = params.side === "from";
1352
- const kindColumn = fromSide ? edges.fromKind : edges.toKind;
1353
- const idColumn = fromSide ? edges.fromId : edges.toId;
2629
+ const kindColumn = fromSide ? edges3.fromKind : edges3.toKind;
2630
+ const idColumn = fromSide ? edges3.fromId : edges3.toId;
1354
2631
  const whereClause = sql.join(
1355
2632
  [
1356
- sql`${edges.graphId} = ${params.graphId}`,
1357
- sql`${edges.kind} = ${params.kind}`,
1358
- ...buildTemporalConditions(edges, params),
2633
+ sql`${edges3.graphId} = ${params.graphId}`,
2634
+ sql`${edges3.kind} = ${params.kind}`,
2635
+ ...buildTemporalConditions(edges3, params),
1359
2636
  sql`${kindColumn} = ${params.endpointKind}`,
1360
2637
  buildIdSetCondition(idColumn, endpointIds)
1361
2638
  ],
1362
2639
  sql` AND `
1363
2640
  );
1364
- const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
2641
+ const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables3, void 0);
1365
2642
  if (params.limitPerEndpoint === void 0) {
1366
2643
  return sql`
1367
- SELECT * FROM ${edges}
2644
+ SELECT * FROM ${edges3}
1368
2645
  WHERE ${whereClause}
1369
2646
  ORDER BY ${orderByClause}
1370
2647
  `;
@@ -1373,7 +2650,7 @@ function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1373
2650
  SELECT *, ROW_NUMBER() OVER (
1374
2651
  PARTITION BY ${idColumn} ORDER BY ${orderByClause}
1375
2652
  ) AS endpoint_rank
1376
- FROM ${edges}
2653
+ FROM ${edges3}
1377
2654
  WHERE ${whereClause}
1378
2655
  `;
1379
2656
  return sql`
@@ -1382,11 +2659,11 @@ function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1382
2659
  ORDER BY ${derivedOrderByClause}
1383
2660
  `;
1384
2661
  }
1385
- function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edgeKinds) {
1386
- const { edges } = tables;
2662
+ function buildFindEdgesByHeterogeneousEndpointSet(tables3, params, endpoints, edgeKinds) {
2663
+ const { edges: edges3 } = tables3;
1387
2664
  const fromSide = params.side === "from";
1388
- const kindColumn = fromSide ? edges.fromKind : edges.toKind;
1389
- const idColumn = fromSide ? edges.fromId : edges.toId;
2665
+ const kindColumn = fromSide ? edges3.fromKind : edges3.toKind;
2666
+ const idColumn = fromSide ? edges3.fromId : edges3.toId;
1390
2667
  const requestedKind = sql.raw(`requested_endpoints."endpoint_kind"`);
1391
2668
  const requestedId = sql.raw(`requested_endpoints."endpoint_id"`);
1392
2669
  const requestedRows = sql.join(
@@ -1395,32 +2672,32 @@ function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edg
1395
2672
  );
1396
2673
  const whereClause = sql.join(
1397
2674
  [
1398
- sql`${edges.graphId} = ${params.graphId}`,
1399
- buildIdSetCondition(edges.kind, edgeKinds),
1400
- ...buildTemporalConditions(edges, params)
2675
+ sql`${edges3.graphId} = ${params.graphId}`,
2676
+ buildIdSetCondition(edges3.kind, edgeKinds),
2677
+ ...buildTemporalConditions(edges3, params)
1401
2678
  ],
1402
2679
  sql` AND `
1403
2680
  );
1404
2681
  const joinClause = sql`
1405
- FROM ${edges}
2682
+ FROM ${edges3}
1406
2683
  INNER JOIN requested_endpoints
1407
2684
  ON ${kindColumn} = ${requestedKind}
1408
2685
  AND ${idColumn} = ${requestedId}
1409
2686
  WHERE ${whereClause}
1410
2687
  `;
1411
- const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
2688
+ const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables3, void 0);
1412
2689
  if (params.limitPerEndpoint === void 0) {
1413
2690
  return sql`
1414
2691
  WITH requested_endpoints(endpoint_kind, endpoint_id) AS (
1415
2692
  VALUES ${requestedRows}
1416
2693
  )
1417
- SELECT ${edges}.*
2694
+ SELECT ${edges3}.*
1418
2695
  ${joinClause}
1419
2696
  ORDER BY ${orderByClause}
1420
2697
  `;
1421
2698
  }
1422
2699
  const ranked = sql`
1423
- SELECT ${edges}.*, ROW_NUMBER() OVER (
2700
+ SELECT ${edges3}.*, ROW_NUMBER() OVER (
1424
2701
  PARTITION BY ${kindColumn}, ${idColumn} ORDER BY ${orderByClause}
1425
2702
  ) AS endpoint_rank
1426
2703
  ${joinClause}
@@ -1434,28 +2711,28 @@ function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edg
1434
2711
  ORDER BY ${derivedOrderByClause}
1435
2712
  `;
1436
2713
  }
1437
- function buildCountEdgesByKind(tables, params) {
1438
- const { edges } = tables;
2714
+ function buildCountEdgesByKind(tables3, params) {
2715
+ const { edges: edges3 } = tables3;
1439
2716
  const conditions = [
1440
- sql`${edges.graphId} = ${params.graphId}`,
1441
- sql`${edges.kind} = ${params.kind}`,
1442
- ...buildTemporalConditions(edges, params)
2717
+ sql`${edges3.graphId} = ${params.graphId}`,
2718
+ sql`${edges3.kind} = ${params.kind}`,
2719
+ ...buildTemporalConditions(edges3, params)
1443
2720
  ];
1444
2721
  if (params.fromKind !== void 0) {
1445
- conditions.push(sql`${edges.fromKind} = ${params.fromKind}`);
2722
+ conditions.push(sql`${edges3.fromKind} = ${params.fromKind}`);
1446
2723
  }
1447
2724
  if (params.fromId !== void 0) {
1448
- conditions.push(sql`${edges.fromId} = ${params.fromId}`);
2725
+ conditions.push(sql`${edges3.fromId} = ${params.fromId}`);
1449
2726
  }
1450
2727
  if (params.toKind !== void 0) {
1451
- conditions.push(sql`${edges.toKind} = ${params.toKind}`);
2728
+ conditions.push(sql`${edges3.toKind} = ${params.toKind}`);
1452
2729
  }
1453
2730
  if (params.toId !== void 0) {
1454
- conditions.push(sql`${edges.toId} = ${params.toId}`);
2731
+ conditions.push(sql`${edges3.toId} = ${params.toId}`);
1455
2732
  }
1456
2733
  const whereClause = sql.join(conditions, sql` AND `);
1457
2734
  return sql`
1458
- SELECT COUNT(*) as count FROM ${edges}
2735
+ SELECT COUNT(*) as count FROM ${edges3}
1459
2736
  WHERE ${whereClause}
1460
2737
  `;
1461
2738
  }
@@ -1469,313 +2746,382 @@ function inList(values) {
1469
2746
  sql`, `
1470
2747
  );
1471
2748
  }
1472
- function buildContendedUniqueRowAudit(tables, graphId, constraintNames) {
1473
- const { uniques } = tables;
1474
- const relation = getTableName(uniques);
2749
+ function buildContendedUniqueRowAudit(tables3, graphId, constraintNames) {
2750
+ const { uniques: uniques3 } = tables3;
2751
+ const relation = getTableName(uniques3);
1475
2752
  return sql`
1476
2753
  SELECT
1477
- ${quotedColumn(uniques.nodeKind)} as node_kind,
1478
- ${quotedColumn(uniques.constraintName)} as constraint_name,
1479
- ${quotedColumn(uniques.key)} as key,
1480
- ${quotedColumn(uniques.concreteKind)} as concrete_kind,
1481
- ${quotedColumn(uniques.nodeId)} as node_id
1482
- FROM ${uniques}
1483
- WHERE ${qualified2(relation, uniques.graphId)} = ${graphId}
1484
- AND ${qualified2(relation, uniques.constraintName)} IN (${inList(constraintNames)})
1485
- AND ${qualified2(relation, uniques.deletedAt)} IS NULL
2754
+ ${quotedColumn(uniques3.nodeKind)} as node_kind,
2755
+ ${quotedColumn(uniques3.constraintName)} as constraint_name,
2756
+ ${quotedColumn(uniques3.key)} as key,
2757
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind,
2758
+ ${quotedColumn(uniques3.nodeId)} as node_id
2759
+ FROM ${uniques3}
2760
+ WHERE ${qualified2(relation, uniques3.graphId)} = ${graphId}
2761
+ AND ${qualified2(relation, uniques3.constraintName)} IN (${inList(constraintNames)})
2762
+ AND ${qualified2(relation, uniques3.deletedAt)} IS NULL
1486
2763
  AND EXISTS (
1487
- SELECT 1 FROM ${uniques} AS ${sql.raw(`"${PEER}"`)}
1488
- WHERE ${qualified2(PEER, uniques.graphId)} = ${qualified2(relation, uniques.graphId)}
1489
- AND ${qualified2(PEER, uniques.constraintName)} = ${qualified2(relation, uniques.constraintName)}
1490
- AND ${qualified2(PEER, uniques.key)} = ${qualified2(relation, uniques.key)}
1491
- AND ${qualified2(PEER, uniques.deletedAt)} IS NULL
1492
- AND ${qualified2(PEER, uniques.nodeKind)} <> ${qualified2(relation, uniques.nodeKind)}
2764
+ SELECT 1 FROM ${uniques3} AS ${sql.raw(`"${PEER}"`)}
2765
+ WHERE ${qualified2(PEER, uniques3.graphId)} = ${qualified2(relation, uniques3.graphId)}
2766
+ AND ${qualified2(PEER, uniques3.constraintName)} = ${qualified2(relation, uniques3.constraintName)}
2767
+ AND ${qualified2(PEER, uniques3.key)} = ${qualified2(relation, uniques3.key)}
2768
+ AND ${qualified2(PEER, uniques3.deletedAt)} IS NULL
2769
+ AND ${qualified2(PEER, uniques3.nodeKind)} <> ${qualified2(relation, uniques3.nodeKind)}
1493
2770
  )
1494
2771
  `;
1495
2772
  }
1496
- function buildContendedEdgeRowAudit(tables, graphId, cardinality, edgeKinds) {
1497
- const { edges } = tables;
1498
- const relation = getTableName(edges);
2773
+ function buildContendedEdgeRowAudit(tables3, graphId, cardinality, edgeKinds) {
2774
+ const { edges: edges3 } = tables3;
2775
+ const relation = getTableName(edges3);
1499
2776
  const spec = EDGE_CARDINALITY_SPECS[cardinality];
1500
- const activeOnly = spec.holderLiveness === "liveAndActive" ? sql` AND ${qualified2(relation, edges.validTo)} IS NULL` : sql.empty();
1501
- const peerActiveOnly = spec.holderLiveness === "liveAndActive" ? sql` AND ${qualified2(PEER, edges.validTo)} IS NULL` : sql.empty();
2777
+ const activeOnly = spec.holderLiveness === "liveAndActive" ? sql` AND ${qualified2(relation, edges3.validTo)} IS NULL` : sql.empty();
2778
+ const peerActiveOnly = spec.holderLiveness === "liveAndActive" ? sql` AND ${qualified2(PEER, edges3.validTo)} IS NULL` : sql.empty();
1502
2779
  const peerToEndpoints = spec.keyShape === "fromAndTo" ? sql`
1503
- AND ${qualified2(PEER, edges.toKind)} = ${qualified2(relation, edges.toKind)}
1504
- AND ${qualified2(PEER, edges.toId)} = ${qualified2(relation, edges.toId)}
2780
+ AND ${qualified2(PEER, edges3.toKind)} = ${qualified2(relation, edges3.toKind)}
2781
+ AND ${qualified2(PEER, edges3.toId)} = ${qualified2(relation, edges3.toId)}
1505
2782
  ` : sql.empty();
1506
2783
  return sql`
1507
2784
  SELECT
1508
- ${quotedColumn(edges.id)} as edge_id,
1509
- ${quotedColumn(edges.kind)} as edge_kind,
1510
- ${quotedColumn(edges.fromKind)} as from_kind,
1511
- ${quotedColumn(edges.fromId)} as from_id,
1512
- ${quotedColumn(edges.toKind)} as to_kind,
1513
- ${quotedColumn(edges.toId)} as to_id
1514
- FROM ${edges}
1515
- WHERE ${qualified2(relation, edges.graphId)} = ${graphId}
1516
- AND ${qualified2(relation, edges.kind)} IN (${inList(edgeKinds)})
1517
- AND ${qualified2(relation, edges.deletedAt)} IS NULL${activeOnly}
2785
+ ${quotedColumn(edges3.id)} as edge_id,
2786
+ ${quotedColumn(edges3.kind)} as edge_kind,
2787
+ ${quotedColumn(edges3.fromKind)} as from_kind,
2788
+ ${quotedColumn(edges3.fromId)} as from_id,
2789
+ ${quotedColumn(edges3.toKind)} as to_kind,
2790
+ ${quotedColumn(edges3.toId)} as to_id
2791
+ FROM ${edges3}
2792
+ WHERE ${qualified2(relation, edges3.graphId)} = ${graphId}
2793
+ AND ${qualified2(relation, edges3.kind)} IN (${inList(edgeKinds)})
2794
+ AND ${qualified2(relation, edges3.deletedAt)} IS NULL${activeOnly}
1518
2795
  AND EXISTS (
1519
- SELECT 1 FROM ${edges} AS ${sql.raw(`"${PEER}"`)}
1520
- WHERE ${qualified2(PEER, edges.graphId)} = ${qualified2(relation, edges.graphId)}
1521
- AND ${qualified2(PEER, edges.kind)} = ${qualified2(relation, edges.kind)}
1522
- AND ${qualified2(PEER, edges.fromKind)} = ${qualified2(relation, edges.fromKind)}
1523
- AND ${qualified2(PEER, edges.fromId)} = ${qualified2(relation, edges.fromId)}${peerToEndpoints}
1524
- AND ${qualified2(PEER, edges.deletedAt)} IS NULL${peerActiveOnly}
1525
- AND ${qualified2(PEER, edges.id)} <> ${qualified2(relation, edges.id)}
2796
+ SELECT 1 FROM ${edges3} AS ${sql.raw(`"${PEER}"`)}
2797
+ WHERE ${qualified2(PEER, edges3.graphId)} = ${qualified2(relation, edges3.graphId)}
2798
+ AND ${qualified2(PEER, edges3.kind)} = ${qualified2(relation, edges3.kind)}
2799
+ AND ${qualified2(PEER, edges3.fromKind)} = ${qualified2(relation, edges3.fromKind)}
2800
+ AND ${qualified2(PEER, edges3.fromId)} = ${qualified2(relation, edges3.fromId)}${peerToEndpoints}
2801
+ AND ${qualified2(PEER, edges3.deletedAt)} IS NULL${peerActiveOnly}
2802
+ AND ${qualified2(PEER, edges3.id)} <> ${qualified2(relation, edges3.id)}
1526
2803
  )
1527
2804
  `;
1528
2805
  }
1529
- function buildDisjointOverlapAudit(tables, graphId, kinds) {
1530
- const { nodes } = tables;
1531
- const relation = getTableName(nodes);
2806
+ function buildDisjointOverlapAudit(tables3, graphId, kinds) {
2807
+ const { nodes: nodes3 } = tables3;
2808
+ const relation = getTableName(nodes3);
1532
2809
  const liveIdsOfKind = (kind) => sql`
1533
- SELECT ${quotedColumn(nodes.id)} as node_id
1534
- FROM ${nodes}
1535
- WHERE ${qualified2(relation, nodes.graphId)} = ${graphId}
1536
- AND ${qualified2(relation, nodes.kind)} = ${kind}
1537
- AND ${qualified2(relation, nodes.deletedAt)} IS NULL
2810
+ SELECT ${quotedColumn(nodes3.id)} as node_id
2811
+ FROM ${nodes3}
2812
+ WHERE ${qualified2(relation, nodes3.graphId)} = ${graphId}
2813
+ AND ${qualified2(relation, nodes3.kind)} = ${kind}
2814
+ AND ${qualified2(relation, nodes3.deletedAt)} IS NULL
1538
2815
  `;
1539
2816
  return sql`${liveIdsOfKind(kinds[0])} INTERSECT ${liveIdsOfKind(kinds[1])}`;
1540
2817
  }
1541
- function buildInsertEdge(tables, params, timestamp) {
1542
- const { edges } = tables;
2818
+ function qualified3(tableName, column) {
2819
+ return sql.raw(`"${tableName}"."${column.name}"`);
2820
+ }
2821
+ function buildLockEdgeClaims(tables3, entries, timestamp2) {
2822
+ const { edgeClaims: edgeClaims3 } = tables3;
2823
+ const claimsName = getTableName(edgeClaims3);
2824
+ const columns = sql.raw(
2825
+ `"${edgeClaims3.graphId.name}", "${edgeClaims3.axis.name}", "${edgeClaims3.key.name}", "${edgeClaims3.edgeId.name}", "${edgeClaims3.updatedAt.name}"`
2826
+ );
2827
+ const conflictColumns = sql.raw(
2828
+ `"${edgeClaims3.graphId.name}", "${edgeClaims3.axis.name}", "${edgeClaims3.key.name}"`
2829
+ );
2830
+ const valueRows = sql.join(
2831
+ entries.map((entry) => {
2832
+ const target = edgeCardinalityClaimTarget(entry);
2833
+ return sql`(${entry.graphId}, ${target.axis}, ${target.key}, ${entry.edgeId}, ${timestamp2})`;
2834
+ }),
2835
+ sql`, `
2836
+ );
2837
+ return sql`
2838
+ INSERT INTO ${edgeClaims3} (${columns})
2839
+ VALUES ${valueRows}
2840
+ ON CONFLICT (${conflictColumns})
2841
+ DO UPDATE SET ${quotedColumn(edgeClaims3.updatedAt)} = ${qualified3(claimsName, edgeClaims3.updatedAt)}
2842
+ RETURNING
2843
+ ${quotedColumn(edgeClaims3.axis)} as axis,
2844
+ ${quotedColumn(edgeClaims3.key)} as key,
2845
+ ${quotedColumn(edgeClaims3.edgeId)} as holder_edge_id
2846
+ `;
2847
+ }
2848
+ function buildTakeOverEdgeClaim(tables3, params, timestamp2) {
2849
+ const { edgeClaims: edgeClaims3, edges: edges3 } = tables3;
2850
+ const claimsName = getTableName(edgeClaims3);
2851
+ const edgesName = getTableName(edges3);
2852
+ const spec = EDGE_CARDINALITY_SPECS[params.cardinality];
2853
+ const target = edgeCardinalityClaimTarget(params);
2854
+ const toEndpointTerms = spec.keyShape === "fromAndTo" ? sql` AND ${qualified3(edgesName, edges3.toKind)} = ${params.toKind} AND ${qualified3(edgesName, edges3.toId)} = ${params.toId}` : sql``;
2855
+ const activeTerm = spec.holderLiveness === "liveAndActive" ? sql` AND ${qualified3(edgesName, edges3.validTo)} IS NULL` : sql``;
2856
+ return sql`
2857
+ UPDATE ${edgeClaims3}
2858
+ SET ${quotedColumn(edgeClaims3.edgeId)} = ${params.edgeId},
2859
+ ${quotedColumn(edgeClaims3.updatedAt)} = ${timestamp2}
2860
+ WHERE ${qualified3(claimsName, edgeClaims3.graphId)} = ${params.graphId}
2861
+ AND ${qualified3(claimsName, edgeClaims3.axis)} = ${target.axis}
2862
+ AND ${qualified3(claimsName, edgeClaims3.key)} = ${target.key}
2863
+ AND ${qualified3(claimsName, edgeClaims3.edgeId)} <> ${params.edgeId}
2864
+ AND NOT EXISTS (
2865
+ SELECT 1 FROM ${edges3}
2866
+ WHERE ${qualified3(edgesName, edges3.graphId)} = ${qualified3(claimsName, edgeClaims3.graphId)}
2867
+ AND ${qualified3(edgesName, edges3.id)} = ${qualified3(claimsName, edgeClaims3.edgeId)}
2868
+ AND ${qualified3(edgesName, edges3.deletedAt)} IS NULL
2869
+ AND ${qualified3(edgesName, edges3.kind)} = ${params.edgeKind}
2870
+ AND ${qualified3(edgesName, edges3.fromKind)} = ${params.fromKind}
2871
+ AND ${qualified3(edgesName, edges3.fromId)} = ${params.fromId}${toEndpointTerms}${activeTerm}
2872
+ )
2873
+ RETURNING ${quotedColumn(edgeClaims3.edgeId)} as holder_edge_id
2874
+ `;
2875
+ }
2876
+ function buildPurgeEdgeClaims(tables3, params) {
2877
+ const { edgeClaims: edgeClaims3 } = tables3;
2878
+ return sql`
2879
+ DELETE FROM ${edgeClaims3}
2880
+ WHERE ${edgeClaims3.graphId} = ${params.graphId}
2881
+ AND ${edgeClaims3.edgeId} IN (${sql.join(
2882
+ params.edgeIds.map((edgeId) => sql`${edgeId}`),
2883
+ sql`, `
2884
+ )})
2885
+ `;
2886
+ }
2887
+ function buildInsertEdge(tables3, params, timestamp2) {
2888
+ const { edges: edges3 } = tables3;
1543
2889
  const propsJson = JSON.stringify(params.props);
1544
- const columns = edgeColumnList(edges);
2890
+ const columns = edgeColumnList(edges3);
1545
2891
  return sql`
1546
- INSERT INTO ${edges} (${columns})
2892
+ INSERT INTO ${edges3} (${columns})
1547
2893
  VALUES (
1548
2894
  ${params.graphId}, ${params.id}, ${params.kind},
1549
2895
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1550
- ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1551
- ${timestamp}, ${timestamp}
2896
+ ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
2897
+ ${timestamp2}, ${timestamp2}
1552
2898
  )
1553
2899
  RETURNING *
1554
2900
  `;
1555
2901
  }
1556
- function buildInsertEdgeNoReturn(tables, params, timestamp) {
1557
- const { edges } = tables;
2902
+ function buildInsertEdgeNoReturn(tables3, params, timestamp2) {
2903
+ const { edges: edges3 } = tables3;
1558
2904
  const propsJson = JSON.stringify(params.props);
1559
- const columns = edgeColumnList(edges);
2905
+ const columns = edgeColumnList(edges3);
1560
2906
  return sql`
1561
- INSERT INTO ${edges} (${columns})
2907
+ INSERT INTO ${edges3} (${columns})
1562
2908
  VALUES (
1563
2909
  ${params.graphId}, ${params.id}, ${params.kind},
1564
2910
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1565
- ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1566
- ${timestamp}, ${timestamp}
2911
+ ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
2912
+ ${timestamp2}, ${timestamp2}
1567
2913
  )
1568
2914
  `;
1569
2915
  }
1570
- function buildInsertEdgesBatch(tables, params, timestamp) {
1571
- const { edges } = tables;
1572
- const columns = edgeColumnList(edges);
2916
+ function buildInsertEdgesBatch(tables3, params, timestamp2) {
2917
+ const { edges: edges3 } = tables3;
2918
+ const columns = edgeColumnList(edges3);
1573
2919
  const values = params.map((edgeParams) => {
1574
2920
  const propsJson = JSON.stringify(edgeParams.props);
1575
- return sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp))}, ${sqlNull(edgeParams.validTo)}, ${timestamp}, ${timestamp})`;
2921
+ return sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp2))}, ${sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1576
2922
  });
1577
2923
  return sql`
1578
- INSERT INTO ${edges} (${columns})
2924
+ INSERT INTO ${edges3} (${columns})
1579
2925
  VALUES ${sql.join(values, sql`, `)}
1580
2926
  `;
1581
2927
  }
1582
- function buildInsertEdgesBatchReturning(tables, params, timestamp) {
1583
- const { edges } = tables;
1584
- const columns = edgeColumnList(edges);
2928
+ function buildInsertEdgesBatchReturning(tables3, params, timestamp2) {
2929
+ const { edges: edges3 } = tables3;
2930
+ const columns = edgeColumnList(edges3);
1585
2931
  const values = params.map((edgeParams) => {
1586
2932
  const propsJson = JSON.stringify(edgeParams.props);
1587
- return sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp))}, ${sqlNull(edgeParams.validTo)}, ${timestamp}, ${timestamp})`;
2933
+ return sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp2))}, ${sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1588
2934
  });
1589
2935
  return sql`
1590
- INSERT INTO ${edges} (${columns})
2936
+ INSERT INTO ${edges3} (${columns})
1591
2937
  VALUES ${sql.join(values, sql`, `)}
1592
2938
  RETURNING *
1593
2939
  `;
1594
2940
  }
1595
- function buildGetEdge(tables, graphId, id) {
1596
- const { edges } = tables;
2941
+ function buildGetEdge(tables3, graphId, id) {
2942
+ const { edges: edges3 } = tables3;
1597
2943
  return sql`
1598
- SELECT * FROM ${edges}
1599
- WHERE ${edges.graphId} = ${graphId}
1600
- AND ${edges.id} = ${id}
2944
+ SELECT * FROM ${edges3}
2945
+ WHERE ${edges3.graphId} = ${graphId}
2946
+ AND ${edges3.id} = ${id}
1601
2947
  `;
1602
2948
  }
1603
- function buildGetEdges(tables, graphId, ids) {
1604
- const { edges } = tables;
2949
+ function buildGetEdges(tables3, graphId, ids) {
2950
+ const { edges: edges3 } = tables3;
1605
2951
  return sql`
1606
- SELECT * FROM ${edges}
1607
- WHERE ${edges.graphId} = ${graphId}
1608
- AND ${edges.id} IN (${sql.join(
2952
+ SELECT * FROM ${edges3}
2953
+ WHERE ${edges3.graphId} = ${graphId}
2954
+ AND ${edges3.id} IN (${sql.join(
1609
2955
  ids.map((id) => sql`${id}`),
1610
2956
  sql`, `
1611
2957
  )})
1612
2958
  `;
1613
2959
  }
1614
- function expectedIdentityPredicate(tables, expected) {
1615
- const { edges } = tables;
2960
+ function expectedIdentityPredicate(tables3, expected) {
2961
+ const { edges: edges3 } = tables3;
1616
2962
  const parts = [
1617
- expected.kind === void 0 ? void 0 : sql` AND ${edges.kind} = ${expected.kind}`,
1618
- expected.fromKind === void 0 ? void 0 : sql` AND ${edges.fromKind} = ${expected.fromKind}`,
1619
- expected.fromId === void 0 ? void 0 : sql` AND ${edges.fromId} = ${expected.fromId}`,
1620
- expected.toKind === void 0 ? void 0 : sql` AND ${edges.toKind} = ${expected.toKind}`,
1621
- expected.toId === void 0 ? void 0 : sql` AND ${edges.toId} = ${expected.toId}`
2963
+ expected.kind === void 0 ? void 0 : sql` AND ${edges3.kind} = ${expected.kind}`,
2964
+ expected.fromKind === void 0 ? void 0 : sql` AND ${edges3.fromKind} = ${expected.fromKind}`,
2965
+ expected.fromId === void 0 ? void 0 : sql` AND ${edges3.fromId} = ${expected.fromId}`,
2966
+ expected.toKind === void 0 ? void 0 : sql` AND ${edges3.toKind} = ${expected.toKind}`,
2967
+ expected.toId === void 0 ? void 0 : sql` AND ${edges3.toId} = ${expected.toId}`
1622
2968
  ].filter((part) => part !== void 0);
1623
2969
  return parts.length === 0 ? sql.empty() : sql.join(parts, sql``);
1624
2970
  }
1625
- function buildUpdateEdge(tables, params, timestamp) {
1626
- const { edges } = tables;
2971
+ function buildUpdateEdge(tables3, params, timestamp2) {
2972
+ const { edges: edges3 } = tables3;
1627
2973
  const propsJson = JSON.stringify(params.props);
1628
2974
  const setParts = [
1629
- sql`${quotedColumn(edges.props)} = ${propsJson}`,
1630
- sql`${quotedColumn(edges.updatedAt)} = ${timestamp}`
2975
+ sql`${quotedColumn(edges3.props)} = ${propsJson}`,
2976
+ sql`${quotedColumn(edges3.updatedAt)} = ${timestamp2}`
1631
2977
  ];
1632
2978
  if (params.clearDeleted && params.validFrom !== void 0) {
1633
2979
  setParts.push(
1634
- sql`${quotedColumn(edges.validFrom)} = ${sqlNull(resolveStatedValidityLowerBound(params.validFrom))}`,
1635
- sql`${quotedColumn(edges.validTo)} = ${sqlNull(params.validTo)}`
2980
+ sql`${quotedColumn(edges3.validFrom)} = ${sqlNull(resolveStatedValidityLowerBound(params.validFrom))}`,
2981
+ sql`${quotedColumn(edges3.validTo)} = ${sqlNull(params.validTo)}`
1636
2982
  );
1637
2983
  } else if (params.clearValidTo === true) {
1638
- setParts.push(sql`${quotedColumn(edges.validTo)} = NULL`);
2984
+ setParts.push(sql`${quotedColumn(edges3.validTo)} = NULL`);
1639
2985
  } else if (params.validTo !== void 0) {
1640
- setParts.push(sql`${quotedColumn(edges.validTo)} = ${params.validTo}`);
2986
+ setParts.push(sql`${quotedColumn(edges3.validTo)} = ${params.validTo}`);
1641
2987
  }
1642
2988
  if (params.clearDeleted) {
1643
- setParts.push(sql`${quotedColumn(edges.deletedAt)} = NULL`);
2989
+ setParts.push(sql`${quotedColumn(edges3.deletedAt)} = NULL`);
1644
2990
  }
1645
2991
  const setClause = sql.join(setParts, sql`, `);
1646
- const expectedIdentity = expectedIdentityPredicate(tables, params);
2992
+ const expectedIdentity = expectedIdentityPredicate(tables3, params);
1647
2993
  const expectedValidFrom = expectedValidFromPredicate(
1648
- edges.validFrom,
2994
+ edges3.validFrom,
1649
2995
  params.expectedValidFrom
1650
2996
  );
1651
2997
  const expectedValidTo = expectedValidFromPredicate(
1652
- edges.validTo,
2998
+ edges3.validTo,
1653
2999
  params.expectedValidTo
1654
3000
  );
1655
3001
  if (params.clearDeleted) {
1656
3002
  return sql`
1657
- UPDATE ${edges}
3003
+ UPDATE ${edges3}
1658
3004
  SET ${setClause}
1659
- WHERE ${edges.graphId} = ${params.graphId}
1660
- AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
3005
+ WHERE ${edges3.graphId} = ${params.graphId}
3006
+ AND ${edges3.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
1661
3007
  RETURNING *
1662
3008
  `;
1663
3009
  }
1664
3010
  return sql`
1665
- UPDATE ${edges}
3011
+ UPDATE ${edges3}
1666
3012
  SET ${setClause}
1667
- WHERE ${edges.graphId} = ${params.graphId}
1668
- AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
1669
- AND ${edges.deletedAt} IS NULL
3013
+ WHERE ${edges3.graphId} = ${params.graphId}
3014
+ AND ${edges3.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
3015
+ AND ${edges3.deletedAt} IS NULL
1670
3016
  RETURNING *
1671
3017
  `;
1672
3018
  }
1673
- function buildDeleteEdge(tables, params, timestamp) {
1674
- const { edges } = tables;
3019
+ function buildDeleteEdge(tables3, params, timestamp2) {
3020
+ const { edges: edges3 } = tables3;
1675
3021
  return sql`
1676
- UPDATE ${edges}
1677
- SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
1678
- WHERE ${edges.graphId} = ${params.graphId}
1679
- AND ${edges.id} = ${params.id}${expectedIdentityPredicate(tables, params.kind === void 0 ? {} : { kind: params.kind })}
1680
- AND ${edges.deletedAt} IS NULL
3022
+ UPDATE ${edges3}
3023
+ SET ${quotedColumn(edges3.deletedAt)} = ${timestamp2}
3024
+ WHERE ${edges3.graphId} = ${params.graphId}
3025
+ AND ${edges3.id} = ${params.id}${expectedIdentityPredicate(tables3, params.kind === void 0 ? {} : { kind: params.kind })}
3026
+ AND ${edges3.deletedAt} IS NULL
1681
3027
  `;
1682
3028
  }
1683
- function buildDeleteEdgesBatch(tables, params, timestamp) {
1684
- const { edges } = tables;
3029
+ function buildDeleteEdgesBatch(tables3, params, timestamp2) {
3030
+ const { edges: edges3 } = tables3;
1685
3031
  return sql`
1686
- UPDATE ${edges}
1687
- SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
1688
- WHERE ${edges.graphId} = ${params.graphId}
1689
- AND ${edges.id} IN (${sql.join(
3032
+ UPDATE ${edges3}
3033
+ SET ${quotedColumn(edges3.deletedAt)} = ${timestamp2}
3034
+ WHERE ${edges3.graphId} = ${params.graphId}
3035
+ AND ${edges3.id} IN (${sql.join(
1690
3036
  params.ids.map((id) => sql`${id}`),
1691
3037
  sql`, `
1692
3038
  )})
1693
- AND ${edges.deletedAt} IS NULL
3039
+ AND ${edges3.deletedAt} IS NULL
1694
3040
  `;
1695
3041
  }
1696
- function buildHardDeleteEdgesBatch(tables, params) {
1697
- const { edges } = tables;
3042
+ function buildHardDeleteEdgesBatch(tables3, params) {
3043
+ const { edges: edges3 } = tables3;
1698
3044
  return sql`
1699
- DELETE FROM ${edges}
1700
- WHERE ${edges.graphId} = ${params.graphId}
1701
- AND ${edges.id} IN (${sql.join(
3045
+ DELETE FROM ${edges3}
3046
+ WHERE ${edges3.graphId} = ${params.graphId}
3047
+ AND ${edges3.id} IN (${sql.join(
1702
3048
  params.ids.map((id) => sql`${id}`),
1703
3049
  sql`, `
1704
3050
  )})
1705
3051
  `;
1706
3052
  }
1707
- function buildHardDeleteEdge(tables, params) {
1708
- const { edges } = tables;
3053
+ function buildHardDeleteEdge(tables3, params) {
3054
+ const { edges: edges3 } = tables3;
1709
3055
  return sql`
1710
- DELETE FROM ${edges}
1711
- WHERE ${edges.graphId} = ${params.graphId}
1712
- AND ${edges.id} = ${params.id}${expectedIdentityPredicate(tables, params.kind === void 0 ? {} : { kind: params.kind })}
3056
+ DELETE FROM ${edges3}
3057
+ WHERE ${edges3.graphId} = ${params.graphId}
3058
+ AND ${edges3.id} = ${params.id}${expectedIdentityPredicate(tables3, params.kind === void 0 ? {} : { kind: params.kind })}
1713
3059
  `;
1714
3060
  }
1715
- function buildHardDeleteEdgesByNode(tables, graphId, nodeKind, nodeId) {
1716
- const { edges } = tables;
3061
+ function buildHardDeleteEdgesByNode(tables3, graphId, nodeKind, nodeId) {
3062
+ const { edges: edges3 } = tables3;
1717
3063
  return sql`
1718
- DELETE FROM ${edges}
1719
- WHERE ${edges.graphId} = ${graphId}
3064
+ DELETE FROM ${edges3}
3065
+ WHERE ${edges3.graphId} = ${graphId}
1720
3066
  AND (
1721
- (${edges.fromKind} = ${nodeKind} AND ${edges.fromId} = ${nodeId})
1722
- OR (${edges.toKind} = ${nodeKind} AND ${edges.toId} = ${nodeId})
3067
+ (${edges3.fromKind} = ${nodeKind} AND ${edges3.fromId} = ${nodeId})
3068
+ OR (${edges3.toKind} = ${nodeKind} AND ${edges3.toId} = ${nodeId})
1723
3069
  )
1724
3070
  `;
1725
3071
  }
1726
- function buildCountEdgesFrom(tables, params) {
1727
- const { edges } = tables;
3072
+ function buildCountEdgesFrom(tables3, params) {
3073
+ const { edges: edges3 } = tables3;
1728
3074
  if (params.activeOnly) {
1729
3075
  return sql`
1730
- SELECT COUNT(*) as count FROM ${edges}
1731
- WHERE ${edges.graphId} = ${params.graphId}
1732
- AND ${edges.kind} = ${params.edgeKind}
1733
- AND ${edges.fromKind} = ${params.fromKind}
1734
- AND ${edges.fromId} = ${params.fromId}
1735
- AND ${edges.deletedAt} IS NULL
1736
- AND ${edges.validTo} IS NULL
3076
+ SELECT COUNT(*) as count FROM ${edges3}
3077
+ WHERE ${edges3.graphId} = ${params.graphId}
3078
+ AND ${edges3.kind} = ${params.edgeKind}
3079
+ AND ${edges3.fromKind} = ${params.fromKind}
3080
+ AND ${edges3.fromId} = ${params.fromId}
3081
+ AND ${edges3.deletedAt} IS NULL
3082
+ AND ${edges3.validTo} IS NULL
1737
3083
  `;
1738
3084
  }
1739
3085
  return sql`
1740
- SELECT COUNT(*) as count FROM ${edges}
1741
- WHERE ${edges.graphId} = ${params.graphId}
1742
- AND ${edges.kind} = ${params.edgeKind}
1743
- AND ${edges.fromKind} = ${params.fromKind}
1744
- AND ${edges.fromId} = ${params.fromId}
1745
- AND ${edges.deletedAt} IS NULL
3086
+ SELECT COUNT(*) as count FROM ${edges3}
3087
+ WHERE ${edges3.graphId} = ${params.graphId}
3088
+ AND ${edges3.kind} = ${params.edgeKind}
3089
+ AND ${edges3.fromKind} = ${params.fromKind}
3090
+ AND ${edges3.fromId} = ${params.fromId}
3091
+ AND ${edges3.deletedAt} IS NULL
1746
3092
  `;
1747
3093
  }
1748
- function buildEdgeExistsBetween(tables, params) {
1749
- const { edges } = tables;
3094
+ function buildEdgeExistsBetween(tables3, params) {
3095
+ const { edges: edges3 } = tables3;
1750
3096
  return sql`
1751
- SELECT 1 FROM ${edges}
1752
- WHERE ${edges.graphId} = ${params.graphId}
1753
- AND ${edges.kind} = ${params.edgeKind}
1754
- AND ${edges.fromKind} = ${params.fromKind}
1755
- AND ${edges.fromId} = ${params.fromId}
1756
- AND ${edges.toKind} = ${params.toKind}
1757
- AND ${edges.toId} = ${params.toId}
1758
- AND ${edges.deletedAt} IS NULL
3097
+ SELECT 1 FROM ${edges3}
3098
+ WHERE ${edges3.graphId} = ${params.graphId}
3099
+ AND ${edges3.kind} = ${params.edgeKind}
3100
+ AND ${edges3.fromKind} = ${params.fromKind}
3101
+ AND ${edges3.fromId} = ${params.fromId}
3102
+ AND ${edges3.toKind} = ${params.toKind}
3103
+ AND ${edges3.toId} = ${params.toId}
3104
+ AND ${edges3.deletedAt} IS NULL
1759
3105
  LIMIT 1
1760
3106
  `;
1761
3107
  }
1762
- function buildFindEdgesConnectedTo(tables, params) {
1763
- const { edges } = tables;
3108
+ function buildFindEdgesConnectedTo(tables3, params) {
3109
+ const { edges: edges3 } = tables3;
1764
3110
  return sql`
1765
- SELECT * FROM ${edges}
1766
- WHERE ${edges.graphId} = ${params.graphId}
1767
- AND ${edges.deletedAt} IS NULL
1768
- AND ${edges.fromKind} = ${params.nodeKind}
1769
- AND ${edges.fromId} = ${params.nodeId}
3111
+ SELECT * FROM ${edges3}
3112
+ WHERE ${edges3.graphId} = ${params.graphId}
3113
+ AND ${edges3.deletedAt} IS NULL
3114
+ AND ${edges3.fromKind} = ${params.nodeKind}
3115
+ AND ${edges3.fromId} = ${params.nodeId}
1770
3116
  UNION ALL
1771
- SELECT * FROM ${edges}
1772
- WHERE ${edges.graphId} = ${params.graphId}
1773
- AND ${edges.deletedAt} IS NULL
1774
- AND ${edges.toKind} = ${params.nodeKind}
1775
- AND ${edges.toId} = ${params.nodeId}
3117
+ SELECT * FROM ${edges3}
3118
+ WHERE ${edges3.graphId} = ${params.graphId}
3119
+ AND ${edges3.deletedAt} IS NULL
3120
+ AND ${edges3.toKind} = ${params.nodeKind}
3121
+ AND ${edges3.toId} = ${params.nodeId}
1776
3122
  AND NOT (
1777
- ${edges.fromKind} = ${params.nodeKind}
1778
- AND ${edges.fromId} = ${params.nodeId}
3123
+ ${edges3.fromKind} = ${params.nodeKind}
3124
+ AND ${edges3.fromId} = ${params.nodeId}
1779
3125
  )
1780
3126
  `;
1781
3127
  }
@@ -1837,136 +3183,136 @@ function assertValidSearchParams(params) {
1837
3183
  );
1838
3184
  }
1839
3185
  }
1840
- function buildInsertNode(tables, params, timestamp) {
1841
- const { nodes } = tables;
3186
+ function buildInsertNode(tables3, params, timestamp2) {
3187
+ const { nodes: nodes3 } = tables3;
1842
3188
  const propsJson = JSON.stringify(params.props);
1843
- const columns = nodeColumnList(nodes);
3189
+ const columns = nodeColumnList(nodes3);
1844
3190
  return sql`
1845
- INSERT INTO ${nodes} (${columns})
3191
+ INSERT INTO ${nodes3} (${columns})
1846
3192
  VALUES (
1847
3193
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1848
- 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1849
- ${timestamp}, ${timestamp}
3194
+ 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
3195
+ ${timestamp2}, ${timestamp2}
1850
3196
  )
1851
3197
  RETURNING *
1852
3198
  `;
1853
3199
  }
1854
- function buildInsertNodeNoReturn(tables, params, timestamp) {
1855
- const { nodes } = tables;
3200
+ function buildInsertNodeNoReturn(tables3, params, timestamp2) {
3201
+ const { nodes: nodes3 } = tables3;
1856
3202
  const propsJson = JSON.stringify(params.props);
1857
- const columns = nodeColumnList(nodes);
3203
+ const columns = nodeColumnList(nodes3);
1858
3204
  return sql`
1859
- INSERT INTO ${nodes} (${columns})
3205
+ INSERT INTO ${nodes3} (${columns})
1860
3206
  VALUES (
1861
3207
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1862
- 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1863
- ${timestamp}, ${timestamp}
3208
+ 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
3209
+ ${timestamp2}, ${timestamp2}
1864
3210
  )
1865
3211
  `;
1866
3212
  }
1867
- function buildInsertNodesBatch(tables, params, timestamp) {
1868
- const { nodes } = tables;
1869
- const columns = nodeColumnList(nodes);
3213
+ function buildInsertNodesBatch(tables3, params, timestamp2) {
3214
+ const { nodes: nodes3 } = tables3;
3215
+ const columns = nodeColumnList(nodes3);
1870
3216
  const values = params.map((nodeParams) => {
1871
3217
  const propsJson = JSON.stringify(nodeParams.props);
1872
- return sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp))}, ${sqlNull(nodeParams.validTo)}, ${timestamp}, ${timestamp})`;
3218
+ return sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp2))}, ${sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1873
3219
  });
1874
3220
  return sql`
1875
- INSERT INTO ${nodes} (${columns})
3221
+ INSERT INTO ${nodes3} (${columns})
1876
3222
  VALUES ${sql.join(values, sql`, `)}
1877
3223
  `;
1878
3224
  }
1879
- function buildInsertNodesBatchReturning(tables, params, timestamp) {
1880
- const { nodes } = tables;
1881
- const columns = nodeColumnList(nodes);
3225
+ function buildInsertNodesBatchReturning(tables3, params, timestamp2) {
3226
+ const { nodes: nodes3 } = tables3;
3227
+ const columns = nodeColumnList(nodes3);
1882
3228
  const values = params.map((nodeParams) => {
1883
3229
  const propsJson = JSON.stringify(nodeParams.props);
1884
- return sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp))}, ${sqlNull(nodeParams.validTo)}, ${timestamp}, ${timestamp})`;
3230
+ return sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp2))}, ${sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1885
3231
  });
1886
3232
  return sql`
1887
- INSERT INTO ${nodes} (${columns})
3233
+ INSERT INTO ${nodes3} (${columns})
1888
3234
  VALUES ${sql.join(values, sql`, `)}
1889
3235
  RETURNING *
1890
3236
  `;
1891
3237
  }
1892
- function buildGetNode(tables, graphId, kind, id) {
1893
- const { nodes } = tables;
3238
+ function buildGetNode(tables3, graphId, kind, id) {
3239
+ const { nodes: nodes3 } = tables3;
1894
3240
  return sql`
1895
- SELECT * FROM ${nodes}
1896
- WHERE ${nodes.graphId} = ${graphId}
1897
- AND ${nodes.kind} = ${kind}
1898
- AND ${nodes.id} = ${id}
3241
+ SELECT * FROM ${nodes3}
3242
+ WHERE ${nodes3.graphId} = ${graphId}
3243
+ AND ${nodes3.kind} = ${kind}
3244
+ AND ${nodes3.id} = ${id}
1899
3245
  `;
1900
3246
  }
1901
- function buildGetNodes(tables, graphId, kind, ids) {
1902
- const { nodes } = tables;
3247
+ function buildGetNodes(tables3, graphId, kind, ids) {
3248
+ const { nodes: nodes3 } = tables3;
1903
3249
  return sql`
1904
- SELECT * FROM ${nodes}
1905
- WHERE ${nodes.graphId} = ${graphId}
1906
- AND ${nodes.kind} = ${kind}
1907
- AND ${nodes.id} IN (${sql.join(
3250
+ SELECT * FROM ${nodes3}
3251
+ WHERE ${nodes3.graphId} = ${graphId}
3252
+ AND ${nodes3.kind} = ${kind}
3253
+ AND ${nodes3.id} IN (${sql.join(
1908
3254
  ids.map((id) => sql`${id}`),
1909
3255
  sql`, `
1910
3256
  )})
1911
3257
  `;
1912
3258
  }
1913
- function buildUpdateNode(tables, params, timestamp) {
1914
- const { nodes } = tables;
3259
+ function buildUpdateNode(tables3, params, timestamp2) {
3260
+ const { nodes: nodes3 } = tables3;
1915
3261
  const propsJson = JSON.stringify(params.props);
1916
3262
  const setParts = [
1917
- sql`${quotedColumn(nodes.props)} = ${propsJson}`,
1918
- sql`${quotedColumn(nodes.updatedAt)} = ${timestamp}`
3263
+ sql`${quotedColumn(nodes3.props)} = ${propsJson}`,
3264
+ sql`${quotedColumn(nodes3.updatedAt)} = ${timestamp2}`
1919
3265
  ];
1920
3266
  if (params.incrementVersion) {
1921
3267
  setParts.push(
1922
- sql`${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1`
3268
+ sql`${quotedColumn(nodes3.version)} = ${quotedColumn(nodes3.version)} + 1`
1923
3269
  );
1924
3270
  }
1925
3271
  if (params.clearDeleted) {
1926
3272
  setParts.push(
1927
- sql`${quotedColumn(nodes.validFrom)} = ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}`,
1928
- sql`${quotedColumn(nodes.validTo)} = ${sqlNull(params.validTo)}`
3273
+ sql`${quotedColumn(nodes3.validFrom)} = ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}`,
3274
+ sql`${quotedColumn(nodes3.validTo)} = ${sqlNull(params.validTo)}`
1929
3275
  );
1930
3276
  } else if (params.clearValidTo === true) {
1931
- setParts.push(sql`${quotedColumn(nodes.validTo)} = NULL`);
3277
+ setParts.push(sql`${quotedColumn(nodes3.validTo)} = NULL`);
1932
3278
  } else if (params.validTo !== void 0) {
1933
- setParts.push(sql`${quotedColumn(nodes.validTo)} = ${params.validTo}`);
3279
+ setParts.push(sql`${quotedColumn(nodes3.validTo)} = ${params.validTo}`);
1934
3280
  }
1935
3281
  if (params.clearDeleted) {
1936
- setParts.push(sql`${quotedColumn(nodes.deletedAt)} = NULL`);
3282
+ setParts.push(sql`${quotedColumn(nodes3.deletedAt)} = NULL`);
1937
3283
  }
1938
3284
  const setClause = sql.join(setParts, sql`, `);
1939
3285
  const expectedValidFrom = expectedValidFromPredicate(
1940
- nodes.validFrom,
3286
+ nodes3.validFrom,
1941
3287
  params.expectedValidFrom
1942
3288
  );
1943
3289
  if (params.clearDeleted) {
1944
3290
  return sql`
1945
- UPDATE ${nodes}
3291
+ UPDATE ${nodes3}
1946
3292
  SET ${setClause}
1947
- WHERE ${nodes.graphId} = ${params.graphId}
1948
- AND ${nodes.kind} = ${params.kind}
1949
- AND ${nodes.id} = ${params.id}${expectedValidFrom}
1950
- AND ${nodes.deletedAt} IS NOT NULL
3293
+ WHERE ${nodes3.graphId} = ${params.graphId}
3294
+ AND ${nodes3.kind} = ${params.kind}
3295
+ AND ${nodes3.id} = ${params.id}${expectedValidFrom}
3296
+ AND ${nodes3.deletedAt} IS NOT NULL
1951
3297
  RETURNING *
1952
3298
  `;
1953
3299
  }
1954
3300
  return sql`
1955
- UPDATE ${nodes}
3301
+ UPDATE ${nodes3}
1956
3302
  SET ${setClause}
1957
- WHERE ${nodes.graphId} = ${params.graphId}
1958
- AND ${nodes.kind} = ${params.kind}
1959
- AND ${nodes.id} = ${params.id}${expectedValidFrom}
1960
- AND ${nodes.deletedAt} IS NULL
3303
+ WHERE ${nodes3.graphId} = ${params.graphId}
3304
+ AND ${nodes3.kind} = ${params.kind}
3305
+ AND ${nodes3.id} = ${params.id}${expectedValidFrom}
3306
+ AND ${nodes3.deletedAt} IS NULL
1961
3307
  RETURNING *
1962
3308
  `;
1963
3309
  }
1964
- function buildUpdateNodeSet(tables, dialect, params, timestamp) {
1965
- const { nodes } = tables;
3310
+ function buildUpdateNodeSet(tables3, dialect, params, timestamp2) {
3311
+ const { nodes: nodes3 } = tables3;
1966
3312
  const adapter = getDialect(dialect);
1967
3313
  const patchedProps = toDrizzleSql(
1968
3314
  adapter.jsonSetProperties(
1969
- sql$1.identifier(nodes.props.name),
3315
+ sql$1.identifier(nodes3.props.name),
1970
3316
  params.patch,
1971
3317
  params.unsetProperties ?? []
1972
3318
  ),
@@ -1978,38 +3324,38 @@ function buildUpdateNodeSet(tables, dialect, params, timestamp) {
1978
3324
  dialect
1979
3325
  );
1980
3326
  return sql`
1981
- UPDATE ${nodes}
1982
- SET ${quotedColumn(nodes.props)} = ${patchedProps},
1983
- ${quotedColumn(nodes.updatedAt)} = ${timestamp},
1984
- ${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1
1985
- WHERE ${nodes.graphId} = ${params.graphId}
1986
- AND ${nodes.kind} = ${params.kind}
1987
- AND ${nodes.deletedAt} IS NULL
1988
- AND ${nodes.id} IN (
3327
+ UPDATE ${nodes3}
3328
+ SET ${quotedColumn(nodes3.props)} = ${patchedProps},
3329
+ ${quotedColumn(nodes3.updatedAt)} = ${timestamp2},
3330
+ ${quotedColumn(nodes3.version)} = ${quotedColumn(nodes3.version)} + 1
3331
+ WHERE ${nodes3.graphId} = ${params.graphId}
3332
+ AND ${nodes3.kind} = ${params.kind}
3333
+ AND ${nodes3.deletedAt} IS NULL
3334
+ AND ${nodes3.id} IN (
1989
3335
  SELECT ${candidateIdColumn}
1990
3336
  FROM (${candidateIds}) AS tg_set_candidates
1991
3337
  )
1992
3338
  RETURNING *
1993
3339
  `;
1994
3340
  }
1995
- function buildDeleteNode(tables, params, timestamp) {
1996
- const { nodes } = tables;
3341
+ function buildDeleteNode(tables3, params, timestamp2) {
3342
+ const { nodes: nodes3 } = tables3;
1997
3343
  return sql`
1998
- UPDATE ${nodes}
1999
- SET ${quotedColumn(nodes.deletedAt)} = ${timestamp}
2000
- WHERE ${nodes.graphId} = ${params.graphId}
2001
- AND ${nodes.kind} = ${params.kind}
2002
- AND ${nodes.id} = ${params.id}
2003
- AND ${nodes.deletedAt} IS NULL
3344
+ UPDATE ${nodes3}
3345
+ SET ${quotedColumn(nodes3.deletedAt)} = ${timestamp2}
3346
+ WHERE ${nodes3.graphId} = ${params.graphId}
3347
+ AND ${nodes3.kind} = ${params.kind}
3348
+ AND ${nodes3.id} = ${params.id}
3349
+ AND ${nodes3.deletedAt} IS NULL
2004
3350
  `;
2005
3351
  }
2006
- function buildHardDeleteNode(tables, params) {
2007
- const { nodes } = tables;
3352
+ function buildHardDeleteNode(tables3, params) {
3353
+ const { nodes: nodes3 } = tables3;
2008
3354
  return sql`
2009
- DELETE FROM ${nodes}
2010
- WHERE ${nodes.graphId} = ${params.graphId}
2011
- AND ${nodes.kind} = ${params.kind}
2012
- AND ${nodes.id} = ${params.id}
3355
+ DELETE FROM ${nodes3}
3356
+ WHERE ${nodes3.graphId} = ${params.graphId}
3357
+ AND ${nodes3.kind} = ${params.kind}
3358
+ AND ${nodes3.id} = ${params.id}
2013
3359
  `;
2014
3360
  }
2015
3361
  function createSchemaDialectStrategy(dialect) {
@@ -2030,66 +3376,319 @@ var SCHEMA_DIALECT_STRATEGIES = {
2030
3376
  postgres: createSchemaDialectStrategy("postgres"),
2031
3377
  sqlite: createSchemaDialectStrategy("sqlite")
2032
3378
  };
2033
- function buildInsertSchema(tables, params, timestamp, dialect = "sqlite") {
2034
- const { schemaVersions } = tables;
3379
+ function buildInsertSchema(tables3, params, timestamp2, dialect = "sqlite") {
3380
+ const { schemaVersions: schemaVersions3 } = tables3;
2035
3381
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2036
3382
  const schemaDocumentJson = JSON.stringify(params.schemaDoc);
2037
3383
  const isActiveValue = strategy.booleanLiteral(params.isActive);
2038
3384
  const columns = sql.raw(
2039
- `"${schemaVersions.graphId.name}", "${schemaVersions.version.name}", "${schemaVersions.schemaHash.name}", "${schemaVersions.schemaDoc.name}", "${schemaVersions.createdAt.name}", "${schemaVersions.isActive.name}"`
3385
+ `"${schemaVersions3.graphId.name}", "${schemaVersions3.version.name}", "${schemaVersions3.schemaHash.name}", "${schemaVersions3.schemaDoc.name}", "${schemaVersions3.createdAt.name}", "${schemaVersions3.isActive.name}"`
2040
3386
  );
2041
3387
  return sql`
2042
- INSERT INTO ${schemaVersions} (${columns})
3388
+ INSERT INTO ${schemaVersions3} (${columns})
2043
3389
  VALUES (
2044
3390
  ${params.graphId}, ${params.version},
2045
3391
  ${params.schemaHash}, ${schemaDocumentJson},
2046
- ${timestamp}, ${isActiveValue}
3392
+ ${timestamp2}, ${isActiveValue}
2047
3393
  )
2048
3394
  RETURNING *
2049
3395
  `;
2050
3396
  }
2051
- function buildGetActiveSchema(tables, graphId, dialect = "sqlite") {
2052
- const { schemaVersions } = tables;
3397
+ function buildGetActiveSchema(tables3, graphId, dialect = "sqlite") {
3398
+ const { schemaVersions: schemaVersions3 } = tables3;
2053
3399
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2054
3400
  return sql`
2055
- SELECT * FROM ${schemaVersions}
2056
- WHERE ${schemaVersions.graphId} = ${graphId}
2057
- AND ${schemaVersions.isActive} = ${strategy.booleanLiteral(true)}
3401
+ SELECT * FROM ${schemaVersions3}
3402
+ WHERE ${schemaVersions3.graphId} = ${graphId}
3403
+ AND ${schemaVersions3.isActive} = ${strategy.booleanLiteral(true)}
2058
3404
  `;
2059
3405
  }
2060
- function buildGetSchemaVersion(tables, graphId, version) {
2061
- const { schemaVersions } = tables;
3406
+ function buildGetSchemaVersion(tables3, graphId, version) {
3407
+ const { schemaVersions: schemaVersions3 } = tables3;
2062
3408
  return sql`
2063
- SELECT * FROM ${schemaVersions}
2064
- WHERE ${schemaVersions.graphId} = ${graphId}
2065
- AND ${schemaVersions.version} = ${version}
3409
+ SELECT * FROM ${schemaVersions3}
3410
+ WHERE ${schemaVersions3.graphId} = ${graphId}
3411
+ AND ${schemaVersions3.version} = ${version}
2066
3412
  `;
2067
3413
  }
2068
- function buildSetActiveSchema(tables, graphId, version, dialect = "sqlite") {
2069
- const { schemaVersions } = tables;
3414
+ function buildSetActiveSchema(tables3, graphId, version, dialect = "sqlite") {
3415
+ const { schemaVersions: schemaVersions3 } = tables3;
2070
3416
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2071
3417
  const deactivateAll = sql`
2072
- UPDATE ${schemaVersions}
2073
- SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(false)}
2074
- WHERE ${schemaVersions.graphId} = ${graphId}
3418
+ UPDATE ${schemaVersions3}
3419
+ SET ${quotedColumn(schemaVersions3.isActive)} = ${strategy.booleanLiteral(false)}
3420
+ WHERE ${schemaVersions3.graphId} = ${graphId}
2075
3421
  `;
2076
3422
  const activateVersion = sql`
2077
- UPDATE ${schemaVersions}
2078
- SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(true)}
2079
- WHERE ${schemaVersions.graphId} = ${graphId}
2080
- AND ${schemaVersions.version} = ${version}
3423
+ UPDATE ${schemaVersions3}
3424
+ SET ${quotedColumn(schemaVersions3.isActive)} = ${strategy.booleanLiteral(true)}
3425
+ WHERE ${schemaVersions3.graphId} = ${graphId}
3426
+ AND ${schemaVersions3.version} = ${version}
2081
3427
  `;
2082
3428
  return { deactivateAll, activateVersion };
2083
3429
  }
3430
+ function drizzleSqlTag(strings, ...expressions) {
3431
+ return sql(strings, ...expressions);
3432
+ }
3433
+ function ownerColumnNames(uniques3) {
3434
+ return {
3435
+ nodeId: uniques3.nodeId.name,
3436
+ concreteKind: uniques3.concreteKind.name
3437
+ };
3438
+ }
3439
+ function boundOwnerColumn(uniques3, params) {
3440
+ return (columnName) => columnName === uniques3.nodeId.name ? sql`${params.nodeId}` : sql`${params.concreteKind}`;
3441
+ }
3442
+ function excludedColumnByName(columnName) {
3443
+ return sql`excluded.${quotedColumn({ name: columnName })}`;
3444
+ }
3445
+ function excludedColumn(column) {
3446
+ return excludedColumnByName(column.name);
3447
+ }
3448
+ function buildInsertUniqueSqlite(tables3, params) {
3449
+ const { uniques: uniques3 } = tables3;
3450
+ const columns = sql.raw(
3451
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
3452
+ );
3453
+ const conflictColumns = sql.raw(
3454
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}"`
3455
+ );
3456
+ const ownerMatches = claimOwnerMatchesSql(
3457
+ drizzleSqlTag,
3458
+ (columnName) => quotedColumn({ name: columnName }),
3459
+ boundOwnerColumn(uniques3, params),
3460
+ ownerColumnNames(uniques3)
3461
+ );
3462
+ return sql`
3463
+ INSERT INTO ${uniques3} (${columns})
3464
+ VALUES (
3465
+ ${params.graphId}, ${params.nodeKind}, ${params.constraintName},
3466
+ ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")}
3467
+ )
3468
+ ON CONFLICT (${conflictColumns})
3469
+ DO UPDATE SET
3470
+ ${quotedColumn(uniques3.nodeId)} = CASE
3471
+ WHEN ${ownerMatches} THEN ${params.nodeId}
3472
+ WHEN ${quotedColumn(uniques3.deletedAt)} IS NOT NULL THEN ${params.nodeId}
3473
+ ELSE ${quotedColumn(uniques3.nodeId)}
3474
+ END,
3475
+ ${quotedColumn(uniques3.concreteKind)} = CASE
3476
+ WHEN ${ownerMatches} THEN ${params.concreteKind}
3477
+ WHEN ${quotedColumn(uniques3.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
3478
+ ELSE ${quotedColumn(uniques3.concreteKind)}
3479
+ END,
3480
+ ${quotedColumn(uniques3.deletedAt)} = CASE
3481
+ WHEN ${ownerMatches} THEN NULL
3482
+ WHEN ${quotedColumn(uniques3.deletedAt)} IS NOT NULL THEN NULL
3483
+ ELSE ${quotedColumn(uniques3.deletedAt)}
3484
+ END
3485
+ RETURNING
3486
+ ${quotedColumn(uniques3.nodeId)} as node_id,
3487
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind
3488
+ `;
3489
+ }
3490
+ function buildInsertUniquePostgres(tables3, params) {
3491
+ const { uniques: uniques3 } = tables3;
3492
+ const columns = sql.raw(
3493
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
3494
+ );
3495
+ const conflictColumns = sql.raw(
3496
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}"`
3497
+ );
3498
+ const tableName = getTableName(uniques3);
3499
+ const existingColumnByName = (columnName) => sql`${quotedTableName(tableName)}.${quotedColumn({ name: columnName })}`;
3500
+ const existingColumn = (column) => existingColumnByName(column.name);
3501
+ const ownerMatches = claimOwnerMatchesSql(
3502
+ drizzleSqlTag,
3503
+ (columnName) => existingColumnByName(columnName),
3504
+ boundOwnerColumn(uniques3, params),
3505
+ ownerColumnNames(uniques3)
3506
+ );
3507
+ return sql`
3508
+ INSERT INTO ${uniques3} (${columns})
3509
+ VALUES (
3510
+ ${params.graphId}, ${params.nodeKind}, ${params.constraintName},
3511
+ ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")}
3512
+ )
3513
+ ON CONFLICT (${conflictColumns})
3514
+ DO UPDATE SET
3515
+ ${quotedColumn(uniques3.nodeId)} = CASE
3516
+ WHEN ${ownerMatches} THEN ${params.nodeId}
3517
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN ${params.nodeId}
3518
+ ELSE ${existingColumn(uniques3.nodeId)}
3519
+ END,
3520
+ ${quotedColumn(uniques3.concreteKind)} = CASE
3521
+ WHEN ${ownerMatches} THEN ${params.concreteKind}
3522
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
3523
+ ELSE ${existingColumn(uniques3.concreteKind)}
3524
+ END,
3525
+ ${quotedColumn(uniques3.deletedAt)} = CASE
3526
+ WHEN ${ownerMatches} THEN NULL
3527
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN NULL
3528
+ ELSE ${existingColumn(uniques3.deletedAt)}
3529
+ END
3530
+ RETURNING
3531
+ ${quotedColumn(uniques3.nodeId)} as node_id,
3532
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind
3533
+ `;
3534
+ }
3535
+ var UNIQUE_INSERT_BUILDERS = {
3536
+ postgres: buildInsertUniquePostgres,
3537
+ sqlite: buildInsertUniqueSqlite
3538
+ };
3539
+ function buildInsertUnique(tables3, dialect, params) {
3540
+ const builder = UNIQUE_INSERT_BUILDERS[dialect];
3541
+ return builder(tables3, params);
3542
+ }
3543
+ function buildInsertUniqueBatch(tables3, dialect, entries) {
3544
+ const { uniques: uniques3 } = tables3;
3545
+ const columns = sql.raw(
3546
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
3547
+ );
3548
+ const conflictColumns = sql.raw(
3549
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}"`
3550
+ );
3551
+ const tableName = getTableName(uniques3);
3552
+ const existingColumnByName = (columnName) => {
3553
+ switch (dialect) {
3554
+ case "postgres": {
3555
+ return sql`${quotedTableName(tableName)}.${quotedColumn({ name: columnName })}`;
3556
+ }
3557
+ case "sqlite": {
3558
+ return quotedColumn({ name: columnName });
3559
+ }
3560
+ default: {
3561
+ return dialect;
3562
+ }
3563
+ }
3564
+ };
3565
+ const existingColumn = (column) => existingColumnByName(column.name);
3566
+ const ownerMatches = claimOwnerMatchesSql(
3567
+ drizzleSqlTag,
3568
+ (columnName) => existingColumnByName(columnName),
3569
+ excludedColumnByName,
3570
+ ownerColumnNames(uniques3)
3571
+ );
3572
+ const valueRows = sql.join(
3573
+ entries.map(
3574
+ (params) => sql`(${params.graphId}, ${params.nodeKind}, ${params.constraintName}, ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")})`
3575
+ ),
3576
+ sql`, `
3577
+ );
3578
+ return sql`
3579
+ INSERT INTO ${uniques3} (${columns})
3580
+ VALUES ${valueRows}
3581
+ ON CONFLICT (${conflictColumns})
3582
+ DO UPDATE SET
3583
+ ${quotedColumn(uniques3.nodeId)} = CASE
3584
+ WHEN ${ownerMatches} THEN ${excludedColumn(uniques3.nodeId)}
3585
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques3.nodeId)}
3586
+ ELSE ${existingColumn(uniques3.nodeId)}
3587
+ END,
3588
+ ${quotedColumn(uniques3.concreteKind)} = CASE
3589
+ WHEN ${ownerMatches} THEN ${excludedColumn(uniques3.concreteKind)}
3590
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques3.concreteKind)}
3591
+ ELSE ${existingColumn(uniques3.concreteKind)}
3592
+ END,
3593
+ ${quotedColumn(uniques3.deletedAt)} = CASE
3594
+ WHEN ${ownerMatches} THEN NULL
3595
+ WHEN ${existingColumn(uniques3.deletedAt)} IS NOT NULL THEN NULL
3596
+ ELSE ${existingColumn(uniques3.deletedAt)}
3597
+ END
3598
+ RETURNING
3599
+ ${quotedColumn(uniques3.nodeKind)} as node_kind,
3600
+ ${quotedColumn(uniques3.constraintName)} as constraint_name,
3601
+ ${quotedColumn(uniques3.key)} as key,
3602
+ ${quotedColumn(uniques3.nodeId)} as node_id,
3603
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind
3604
+ `;
3605
+ }
3606
+ function buildDeleteUnique(tables3, params, timestamp2) {
3607
+ const { uniques: uniques3 } = tables3;
3608
+ const axisTerm = params.nodeKind === void 0 ? sql`` : sql` AND ${uniques3.nodeKind} = ${params.nodeKind}`;
3609
+ return sql`
3610
+ UPDATE ${uniques3}
3611
+ SET ${quotedColumn(uniques3.deletedAt)} = ${timestamp2}
3612
+ WHERE ${uniques3.graphId} = ${params.graphId}
3613
+ AND ${uniques3.concreteKind} = ${params.concreteKind}
3614
+ AND ${uniques3.nodeId} = ${params.nodeId}
3615
+ AND ${uniques3.constraintName} = ${params.constraintName}
3616
+ AND ${uniques3.key} = ${params.key}${axisTerm}
3617
+ AND ${uniques3.deletedAt} IS NULL
3618
+ `;
3619
+ }
3620
+ function buildHardDeleteUniquesByNode(tables3, graphId, concreteKind, nodeId) {
3621
+ return buildHardDeleteUniquesByNodeIds(tables3, {
3622
+ graphId,
3623
+ concreteKind,
3624
+ nodeIds: [nodeId]
3625
+ });
3626
+ }
3627
+ function buildHardDeleteUniquesByNodeIds(tables3, params) {
3628
+ const { uniques: uniques3 } = tables3;
3629
+ return sql`
3630
+ DELETE FROM ${uniques3}
3631
+ WHERE ${uniques3.graphId} = ${params.graphId}
3632
+ AND ${uniques3.concreteKind} = ${params.concreteKind}
3633
+ AND ${uniques3.nodeId} IN (${sql.join(
3634
+ params.nodeIds.map((nodeId) => sql`${nodeId}`),
3635
+ sql`, `
3636
+ )})
3637
+ `;
3638
+ }
3639
+ function buildCheckUnique(tables3, params) {
3640
+ const { uniques: uniques3 } = tables3;
3641
+ if (params.includeDeleted) {
3642
+ return sql`
3643
+ SELECT * FROM ${uniques3}
3644
+ WHERE ${uniques3.graphId} = ${params.graphId}
3645
+ AND ${uniques3.nodeKind} = ${params.nodeKind}
3646
+ AND ${uniques3.constraintName} = ${params.constraintName}
3647
+ AND ${uniques3.key} = ${params.key}
3648
+ `;
3649
+ }
3650
+ return sql`
3651
+ SELECT * FROM ${uniques3}
3652
+ WHERE ${uniques3.graphId} = ${params.graphId}
3653
+ AND ${uniques3.nodeKind} = ${params.nodeKind}
3654
+ AND ${uniques3.constraintName} = ${params.constraintName}
3655
+ AND ${uniques3.key} = ${params.key}
3656
+ AND ${uniques3.deletedAt} IS NULL
3657
+ `;
3658
+ }
3659
+ function buildCheckUniqueBatch(tables3, params) {
3660
+ const { uniques: uniques3 } = tables3;
3661
+ const keyPlaceholders = sql.join(
3662
+ params.keys.map((key) => sql`${key}`),
3663
+ sql`, `
3664
+ );
3665
+ if (params.includeDeleted) {
3666
+ return sql`
3667
+ SELECT * FROM ${uniques3}
3668
+ WHERE ${uniques3.graphId} = ${params.graphId}
3669
+ AND ${uniques3.nodeKind} = ${params.nodeKind}
3670
+ AND ${uniques3.constraintName} = ${params.constraintName}
3671
+ AND ${uniques3.key} IN (${keyPlaceholders})
3672
+ `;
3673
+ }
3674
+ return sql`
3675
+ SELECT * FROM ${uniques3}
3676
+ WHERE ${uniques3.graphId} = ${params.graphId}
3677
+ AND ${uniques3.nodeKind} = ${params.nodeKind}
3678
+ AND ${uniques3.constraintName} = ${params.constraintName}
3679
+ AND ${uniques3.key} IN (${keyPlaceholders})
3680
+ AND ${uniques3.deletedAt} IS NULL
3681
+ `;
3682
+ }
2084
3683
 
2085
3684
  // src/backend/drizzle/operations/strategy.ts
2086
3685
  function nullableText(value) {
2087
3686
  return value === void 0 ? sql`NULL` : sql`${value}`;
2088
3687
  }
2089
- function bindTableOperationBuilders(tables, builders) {
3688
+ function bindTableOperationBuilders(tables3, builders) {
2090
3689
  const boundEntries = Object.entries(builders).map(([name, builder]) => {
2091
3690
  function boundBuilder(...args) {
2092
- return builder(tables, ...args);
3691
+ return builder(tables3, ...args);
2093
3692
  }
2094
3693
  return [name, boundBuilder];
2095
3694
  });
@@ -2135,22 +3734,22 @@ var COMMON_TABLE_OPERATION_BUILDERS = {
2135
3734
  buildCheckUniqueBatch,
2136
3735
  buildGetSchemaVersion
2137
3736
  };
2138
- function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
3737
+ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
2139
3738
  const tableOperations = bindTableOperationBuilders(
2140
- tables,
3739
+ tables3,
2141
3740
  COMMON_TABLE_OPERATION_BUILDERS
2142
3741
  );
2143
- const fulltextTable = tables.fulltextTableName;
2144
- const contributionMaterializations = tables.contributionMaterializations;
3742
+ const fulltextTable = tables3.fulltextTableName;
3743
+ const contributionMaterializations = tables3.contributionMaterializations;
2145
3744
  const fulltextBuilders = {
2146
- buildUpsertFulltext: (params, timestamp) => fulltextStrategy.buildUpsert(fulltextTable, params, timestamp).map((statement) => toDrizzleSql(statement, dialect)),
3745
+ buildUpsertFulltext: (params, timestamp2) => fulltextStrategy.buildUpsert(fulltextTable, params, timestamp2).map((statement) => toDrizzleSql(statement, dialect)),
2147
3746
  buildDeleteFulltext: (params) => fulltextStrategy.buildDelete(fulltextTable, params).map((statement) => toDrizzleSql(statement, dialect)),
2148
3747
  buildDeleteFulltextByNode: (graphId, nodeKind, nodeId) => fulltextStrategy.buildDelete(fulltextTable, {
2149
3748
  graphId,
2150
3749
  nodeKind,
2151
3750
  nodeId
2152
3751
  }).map((statement) => toDrizzleSql(statement, dialect)),
2153
- buildUpsertFulltextBatch: (params, timestamp) => fulltextStrategy.buildBatchUpsert(fulltextTable, params, timestamp).map((statement) => toDrizzleSql(statement, dialect)),
3752
+ buildUpsertFulltextBatch: (params, timestamp2) => fulltextStrategy.buildBatchUpsert(fulltextTable, params, timestamp2).map((statement) => toDrizzleSql(statement, dialect)),
2154
3753
  buildDeleteFulltextBatch: (params) => fulltextStrategy.buildBatchDelete(fulltextTable, params).map((statement) => toDrizzleSql(statement, dialect)),
2155
3754
  buildFulltextSearch: (params) => buildFulltextSearch(
2156
3755
  fulltextTable,
@@ -2160,7 +3759,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2160
3759
  // Store-compiled candidates (predicates + subclass + currency)
2161
3760
  // take precedence; the live-node default covers direct backend use.
2162
3761
  params.candidates ?? liveNodeIdsSubquery(
2163
- tables.nodes,
3762
+ tables3.nodes,
2164
3763
  params.graphId,
2165
3764
  params.nodeKind,
2166
3765
  nowIso()
@@ -2168,7 +3767,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2168
3767
  ),
2169
3768
  buildHybridSearch: (params, vectorSql, vectorScoreDescending) => {
2170
3769
  const candidates = params.candidates ?? liveNodeIdsSubquery(
2171
- tables.nodes,
3770
+ tables3.nodes,
2172
3771
  params.graphId,
2173
3772
  params.nodeKind,
2174
3773
  nowIso()
@@ -2196,7 +3795,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2196
3795
  vectorSql,
2197
3796
  vectorScoreDescending,
2198
3797
  fulltextSql,
2199
- nodes: tables.nodes,
3798
+ nodes: tables3.nodes,
2200
3799
  dialect,
2201
3800
  graphId: params.graphId,
2202
3801
  nodeKind: params.nodeKind,
@@ -2239,57 +3838,57 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2239
3838
  ...tableOperations,
2240
3839
  ...fulltextBuilders,
2241
3840
  primaryKeyConstraints: {
2242
- nodes: nodePrimaryKeyConstraint(tables.nodes),
2243
- edges: edgePrimaryKeyConstraint(tables.edges)
3841
+ nodes: nodePrimaryKeyConstraint(tables3.nodes),
3842
+ edges: edgePrimaryKeyConstraint(tables3.edges)
2244
3843
  },
2245
- buildUpdateNodeSet(params, timestamp) {
2246
- return buildUpdateNodeSet(tables, dialect, params, timestamp);
3844
+ buildUpdateNodeSet(params, timestamp2) {
3845
+ return buildUpdateNodeSet(tables3, dialect, params, timestamp2);
2247
3846
  },
2248
3847
  buildDeleteContributionMaterialization,
2249
3848
  buildInsertContributionMaterialization,
2250
3849
  buildInsertUnique(params) {
2251
- return buildInsertUnique(tables, dialect, params);
3850
+ return buildInsertUnique(tables3, dialect, params);
2252
3851
  },
2253
3852
  buildInsertUniqueBatch(entries) {
2254
- return buildInsertUniqueBatch(tables, dialect, entries);
3853
+ return buildInsertUniqueBatch(tables3, dialect, entries);
2255
3854
  },
2256
3855
  buildHardDeleteUniquesByConcreteKind(params) {
2257
3856
  return buildHardDeleteUniquesByConcreteKind(
2258
- getTableName(tables.uniques),
3857
+ getTableName(tables3.uniques),
2259
3858
  params
2260
3859
  );
2261
3860
  },
2262
- buildLockEdgeClaims(entries, timestamp) {
2263
- return buildLockEdgeClaims(tables, entries, timestamp);
3861
+ buildLockEdgeClaims(entries, timestamp2) {
3862
+ return buildLockEdgeClaims(tables3, entries, timestamp2);
2264
3863
  },
2265
- buildTakeOverEdgeClaim(params, timestamp) {
2266
- return buildTakeOverEdgeClaim(tables, params, timestamp);
3864
+ buildTakeOverEdgeClaim(params, timestamp2) {
3865
+ return buildTakeOverEdgeClaim(tables3, params, timestamp2);
2267
3866
  },
2268
3867
  buildPurgeEdgeClaims(params) {
2269
- return buildPurgeEdgeClaims(tables, params);
3868
+ return buildPurgeEdgeClaims(tables3, params);
2270
3869
  },
2271
3870
  buildContendedUniqueRowAudit(graphId, constraintNames) {
2272
- return buildContendedUniqueRowAudit(tables, graphId, constraintNames);
3871
+ return buildContendedUniqueRowAudit(tables3, graphId, constraintNames);
2273
3872
  },
2274
3873
  buildContendedEdgeRowAudit(graphId, cardinality, edgeKinds) {
2275
3874
  return buildContendedEdgeRowAudit(
2276
- tables,
3875
+ tables3,
2277
3876
  graphId,
2278
3877
  cardinality,
2279
3878
  edgeKinds
2280
3879
  );
2281
3880
  },
2282
3881
  buildDisjointOverlapAudit(graphId, kinds) {
2283
- return buildDisjointOverlapAudit(tables, graphId, kinds);
3882
+ return buildDisjointOverlapAudit(tables3, graphId, kinds);
2284
3883
  },
2285
3884
  buildGetActiveSchema(graphId) {
2286
- return buildGetActiveSchema(tables, graphId, dialect);
3885
+ return buildGetActiveSchema(tables3, graphId, dialect);
2287
3886
  },
2288
- buildInsertSchema(params, timestamp) {
2289
- return buildInsertSchema(tables, params, timestamp, dialect);
3887
+ buildInsertSchema(params, timestamp2) {
3888
+ return buildInsertSchema(tables3, params, timestamp2, dialect);
2290
3889
  },
2291
3890
  buildSetActiveSchema(graphId, version) {
2292
- return buildSetActiveSchema(tables, graphId, version, dialect);
3891
+ return buildSetActiveSchema(tables3, graphId, version, dialect);
2293
3892
  },
2294
3893
  buildTableExists(tableName) {
2295
3894
  switch (dialect) {
@@ -2312,7 +3911,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2312
3911
  }
2313
3912
  },
2314
3913
  buildClearGraph(graphId) {
2315
- return buildClearGraph(tables, graphId);
3914
+ return buildClearGraph(tables3, graphId);
2316
3915
  }
2317
3916
  };
2318
3917
  }
@@ -2338,11 +3937,11 @@ function createCachedTableExistence(probe, options) {
2338
3937
  return exists;
2339
3938
  };
2340
3939
  }
2341
- function createSqliteOperationStrategy(tables, fulltextStrategy) {
2342
- return createCommonOperationStrategy(tables, "sqlite", fulltextStrategy);
3940
+ function createSqliteOperationStrategy(tables3, fulltextStrategy) {
3941
+ return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
2343
3942
  }
2344
- function createPostgresOperationStrategy(tables, fulltextStrategy) {
2345
- return createCommonOperationStrategy(tables, "postgres", fulltextStrategy);
3943
+ function createPostgresOperationStrategy(tables3, fulltextStrategy) {
3944
+ return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
2346
3945
  }
2347
3946
  function claimOwnerOf(params) {
2348
3947
  return { concreteKind: params.concreteKind, nodeId: params.nodeId };
@@ -2510,8 +4109,8 @@ function createCommonOperationBackend(options) {
2510
4109
  await execution.execRun(query);
2511
4110
  },
2512
4111
  async insertNode(params) {
2513
- const timestamp = nowIso2();
2514
- const query = operationStrategy.buildInsertNode(params, timestamp);
4112
+ const timestamp2 = nowIso2();
4113
+ const query = operationStrategy.buildInsertNode(params, timestamp2);
2515
4114
  const row = await withDuplicateKeyClassification(
2516
4115
  () => execution.execGet(query),
2517
4116
  {
@@ -2532,10 +4131,10 @@ function createCommonOperationBackend(options) {
2532
4131
  return rowMappers.toNodeRow(row);
2533
4132
  },
2534
4133
  async insertNodeNoReturn(params) {
2535
- const timestamp = nowIso2();
4134
+ const timestamp2 = nowIso2();
2536
4135
  const query = operationStrategy.buildInsertNodeNoReturn(
2537
4136
  params,
2538
- timestamp
4137
+ timestamp2
2539
4138
  );
2540
4139
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2541
4140
  entity: "node",
@@ -2547,9 +4146,9 @@ function createCommonOperationBackend(options) {
2547
4146
  if (params.length === 0) {
2548
4147
  return;
2549
4148
  }
2550
- const timestamp = nowIso2();
4149
+ const timestamp2 = nowIso2();
2551
4150
  for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
2552
- const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp);
4151
+ const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp2);
2553
4152
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2554
4153
  entity: "node",
2555
4154
  relation: operationStrategy.primaryKeyConstraints.nodes,
@@ -2561,12 +4160,12 @@ function createCommonOperationBackend(options) {
2561
4160
  if (params.length === 0) {
2562
4161
  return [];
2563
4162
  }
2564
- const timestamp = nowIso2();
4163
+ const timestamp2 = nowIso2();
2565
4164
  const allRows = [];
2566
4165
  for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
2567
4166
  const query = operationStrategy.buildInsertNodesBatchReturning(
2568
4167
  chunk2,
2569
- timestamp
4168
+ timestamp2
2570
4169
  );
2571
4170
  const rows = await withDuplicateKeyClassification(
2572
4171
  () => execution.execAll(query),
@@ -2596,8 +4195,8 @@ function createCommonOperationBackend(options) {
2596
4195
  return allRows;
2597
4196
  },
2598
4197
  async updateNode(params) {
2599
- const timestamp = nowIso2();
2600
- const query = operationStrategy.buildUpdateNode(params, timestamp);
4198
+ const timestamp2 = nowIso2();
4199
+ const query = operationStrategy.buildUpdateNode(params, timestamp2);
2601
4200
  const row = await execution.execGet(query);
2602
4201
  if (!row)
2603
4202
  throw new DatabaseOperationError(
@@ -2623,15 +4222,15 @@ function createCommonOperationBackend(options) {
2623
4222
  { operation: "updateNodeSet", kind: params.kind }
2624
4223
  );
2625
4224
  }
2626
- const timestamp = nowIso2();
2627
- const query = operationStrategy.buildUpdateNodeSet(params, timestamp);
4225
+ const timestamp2 = nowIso2();
4226
+ const query = operationStrategy.buildUpdateNodeSet(params, timestamp2);
2628
4227
  const rows = await execution.execAll(query);
2629
4228
  const updatedRows = rows.map((row) => rowMappers.toNodeRow(row));
2630
4229
  return { affectedCount: updatedRows.length, rows: updatedRows };
2631
4230
  },
2632
4231
  async deleteNode(params) {
2633
- const timestamp = nowIso2();
2634
- const query = operationStrategy.buildDeleteNode(params, timestamp);
4232
+ const timestamp2 = nowIso2();
4233
+ const query = operationStrategy.buildDeleteNode(params, timestamp2);
2635
4234
  await execution.execRun(query);
2636
4235
  },
2637
4236
  // IMPORTANT: This cascade is not atomic. Callers must ensure this runs
@@ -2668,8 +4267,8 @@ function createCommonOperationBackend(options) {
2668
4267
  await execution.execRun(query);
2669
4268
  },
2670
4269
  async insertEdge(params) {
2671
- const timestamp = nowIso2();
2672
- const query = operationStrategy.buildInsertEdge(params, timestamp);
4270
+ const timestamp2 = nowIso2();
4271
+ const query = operationStrategy.buildInsertEdge(params, timestamp2);
2673
4272
  const row = await withDuplicateKeyClassification(
2674
4273
  () => execution.execGet(query),
2675
4274
  {
@@ -2690,10 +4289,10 @@ function createCommonOperationBackend(options) {
2690
4289
  return rowMappers.toEdgeRow(row);
2691
4290
  },
2692
4291
  async insertEdgeNoReturn(params) {
2693
- const timestamp = nowIso2();
4292
+ const timestamp2 = nowIso2();
2694
4293
  const query = operationStrategy.buildInsertEdgeNoReturn(
2695
4294
  params,
2696
- timestamp
4295
+ timestamp2
2697
4296
  );
2698
4297
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2699
4298
  entity: "edge",
@@ -2705,9 +4304,9 @@ function createCommonOperationBackend(options) {
2705
4304
  if (params.length === 0) {
2706
4305
  return;
2707
4306
  }
2708
- const timestamp = nowIso2();
4307
+ const timestamp2 = nowIso2();
2709
4308
  for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
2710
- const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp);
4309
+ const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp2);
2711
4310
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2712
4311
  entity: "edge",
2713
4312
  relation: operationStrategy.primaryKeyConstraints.edges,
@@ -2719,12 +4318,12 @@ function createCommonOperationBackend(options) {
2719
4318
  if (params.length === 0) {
2720
4319
  return [];
2721
4320
  }
2722
- const timestamp = nowIso2();
4321
+ const timestamp2 = nowIso2();
2723
4322
  const allRows = [];
2724
4323
  for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
2725
4324
  const query = operationStrategy.buildInsertEdgesBatchReturning(
2726
4325
  chunk2,
2727
- timestamp
4326
+ timestamp2
2728
4327
  );
2729
4328
  const rows = await withDuplicateKeyClassification(
2730
4329
  () => execution.execAll(query),
@@ -2754,8 +4353,8 @@ function createCommonOperationBackend(options) {
2754
4353
  return allRows;
2755
4354
  },
2756
4355
  async updateEdge(params) {
2757
- const timestamp = nowIso2();
2758
- const query = operationStrategy.buildUpdateEdge(params, timestamp);
4356
+ const timestamp2 = nowIso2();
4357
+ const query = operationStrategy.buildUpdateEdge(params, timestamp2);
2759
4358
  const row = await execution.execGet(query);
2760
4359
  if (!row)
2761
4360
  throw new DatabaseOperationError(
@@ -2769,8 +4368,8 @@ function createCommonOperationBackend(options) {
2769
4368
  return rowMappers.toEdgeRow(row);
2770
4369
  },
2771
4370
  async deleteEdge(params) {
2772
- const timestamp = nowIso2();
2773
- const query = operationStrategy.buildDeleteEdge(params, timestamp);
4371
+ const timestamp2 = nowIso2();
4372
+ const query = operationStrategy.buildDeleteEdge(params, timestamp2);
2774
4373
  await execution.execRun(query);
2775
4374
  },
2776
4375
  async hardDeleteEdge(params) {
@@ -2779,7 +4378,7 @@ function createCommonOperationBackend(options) {
2779
4378
  },
2780
4379
  async deleteEdgesBatch(params) {
2781
4380
  if (params.ids.length === 0) return;
2782
- const timestamp = nowIso2();
4381
+ const timestamp2 = nowIso2();
2783
4382
  const softDeleteChunkSize = Math.max(
2784
4383
  1,
2785
4384
  batchConfig.getEdgesChunkSize - 1
@@ -2787,7 +4386,7 @@ function createCommonOperationBackend(options) {
2787
4386
  for (const chunk2 of chunk(params.ids, softDeleteChunkSize)) {
2788
4387
  const query = operationStrategy.buildDeleteEdgesBatch(
2789
4388
  { graphId: params.graphId, ids: chunk2 },
2790
- timestamp
4389
+ timestamp2
2791
4390
  );
2792
4391
  await execution.execRun(query);
2793
4392
  }
@@ -2944,8 +4543,8 @@ function createCommonOperationBackend(options) {
2944
4543
  }
2945
4544
  },
2946
4545
  async deleteUnique(params) {
2947
- const timestamp = nowIso2();
2948
- const query = operationStrategy.buildDeleteUnique(params, timestamp);
4546
+ const timestamp2 = nowIso2();
4547
+ const query = operationStrategy.buildDeleteUnique(params, timestamp2);
2949
4548
  await execution.execRun(query);
2950
4549
  },
2951
4550
  async hardDeleteUniquesByNodeIds(params) {
@@ -3107,7 +4706,7 @@ function createCommonOperationBackend(options) {
3107
4706
  );
3108
4707
  await execution.execRun(flip.deactivateAll);
3109
4708
  }
3110
- const timestamp = nowIso2();
4709
+ const timestamp2 = nowIso2();
3111
4710
  const insertQuery = operationStrategy.buildInsertSchema(
3112
4711
  {
3113
4712
  graphId: params.graphId,
@@ -3116,7 +4715,7 @@ function createCommonOperationBackend(options) {
3116
4715
  schemaDoc: params.schemaDoc,
3117
4716
  isActive: true
3118
4717
  },
3119
- timestamp
4718
+ timestamp2
3120
4719
  );
3121
4720
  const insertedRaw = await execution.execGet(insertQuery);
3122
4721
  if (!insertedRaw) {
@@ -3316,7 +4915,7 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3316
4915
  return {
3317
4916
  async insertNodes(params) {
3318
4917
  if (params.length === 0) return;
3319
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4918
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3320
4919
  await executePreparedRunBatch(
3321
4920
  nodeSql,
3322
4921
  params.map((item) => [
@@ -3324,16 +4923,16 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3324
4923
  item.kind,
3325
4924
  item.id,
3326
4925
  JSON.stringify(item.props),
3327
- resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
4926
+ resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL,
3328
4927
  item.validTo ?? DATABASE_NULL,
3329
- timestamp,
3330
- timestamp
4928
+ timestamp2,
4929
+ timestamp2
3331
4930
  ])
3332
4931
  );
3333
4932
  },
3334
4933
  async insertEdges(params) {
3335
4934
  if (params.length === 0) return;
3336
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4935
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3337
4936
  await executePreparedRunBatch(
3338
4937
  edgeSql,
3339
4938
  params.map((item) => [
@@ -3345,10 +4944,10 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3345
4944
  item.toKind,
3346
4945
  item.toId,
3347
4946
  JSON.stringify(item.props),
3348
- resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
4947
+ resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL,
3349
4948
  item.validTo ?? DATABASE_NULL,
3350
- timestamp,
3351
- timestamp
4949
+ timestamp2,
4950
+ timestamp2
3352
4951
  ])
3353
4952
  );
3354
4953
  }
@@ -3378,7 +4977,7 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3378
4977
  return {
3379
4978
  async insertNodes(params) {
3380
4979
  if (params.length === 0) return;
3381
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4980
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3382
4981
  await executeRaw(nodeSql, [
3383
4982
  postgresArray(params.map((item) => item.graphId)),
3384
4983
  postgresArray(params.map((item) => item.kind)),
@@ -3386,16 +4985,16 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3386
4985
  postgresArray(params.map((item) => JSON.stringify(item.props))),
3387
4986
  postgresArray(
3388
4987
  params.map(
3389
- (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
4988
+ (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL
3390
4989
  )
3391
4990
  ),
3392
4991
  postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
3393
- postgresArray(params.map(() => timestamp))
4992
+ postgresArray(params.map(() => timestamp2))
3394
4993
  ]);
3395
4994
  },
3396
4995
  async insertEdges(params) {
3397
4996
  if (params.length === 0) return;
3398
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4997
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3399
4998
  await executeRaw(edgeSql, [
3400
4999
  postgresArray(params.map((item) => item.graphId)),
3401
5000
  postgresArray(params.map((item) => item.id)),
@@ -3407,11 +5006,11 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3407
5006
  postgresArray(params.map((item) => JSON.stringify(item.props))),
3408
5007
  postgresArray(
3409
5008
  params.map(
3410
- (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
5009
+ (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL
3411
5010
  )
3412
5011
  ),
3413
5012
  postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
3414
- postgresArray(params.map(() => timestamp))
5013
+ postgresArray(params.map(() => timestamp2))
3415
5014
  ]);
3416
5015
  }
3417
5016
  };
@@ -3434,6 +5033,6 @@ function getOrCreateLru(cache, key, cacheMax, create) {
3434
5033
  return value;
3435
5034
  }
3436
5035
 
3437
- export { EMBEDDING_UPSERT_PARAM_COUNT, FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, analyzeImportedTables, assertActiveSchemaVersion, assertAdoptedDialect, assertTrustedImportDatabaseEmpty, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildLiveNodeCandidates, buildMaterializationInsertValues, buildMaterializationOnConflictSet, commitSchemaVersionIfKindsEmpty, contributionRebuildSupported, createCachedTableExistence, createCommonOperationBackend, createContributionMaterializer, createPostgresOperationStrategy, createPostgresTrustedImportSession, createSqliteOperationStrategy, createSqliteTrustedImportSession, gateFulltext, gateFulltextMethods, getOrCreateLru, lockPostgresTrustedImportTables, mapContributionMaterializationRow, mapHybridSearchRow, mapKindRemovalRow, mapMaterializationRow, mapVectorWriteError, restoreSecondaryIndexes, suspendPostgresSecondaryIndexes, suspendSqliteSecondaryIndexes, tableExistsFromRow, vectorSlotFromCreateIndexParams, vectorSlotFromDropIndexParams, vectorSlotFromParams };
3438
- //# sourceMappingURL=chunk-MJPZNEJZ.js.map
3439
- //# sourceMappingURL=chunk-MJPZNEJZ.js.map
5036
+ export { EMBEDDING_UPSERT_PARAM_COUNT, FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, analyzeImportedTables, assertActiveSchemaVersion, assertAdoptedDialect, assertBundledCapabilityDeclarations, assertTrustedImportDatabaseEmpty, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildLiveNodeCandidates, buildMaterializationInsertValues, buildMaterializationOnConflictSet, commitSchemaVersionIfKindsEmpty, contributionRebuildSupported, createCachedTableExistence, createCommonOperationBackend, createContributionMaterializer, createPostgresOperationStrategy, createPostgresTables, createPostgresTrustedImportSession, createSqliteOperationStrategy, createSqliteTables, createSqliteTrustedImportSession, edgeClaims, edgeClaims2, edges, edges2, fulltext, gateFulltext, gateFulltextMethods, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, getOrCreateLru, lockPostgresTrustedImportTables, mapContributionMaterializationRow, mapHybridSearchRow, mapKindRemovalRow, mapMaterializationRow, mapVectorWriteError, nodes, nodes2, postgresContributions, recordedClock, recordedClock2, recordedEdges, recordedEdges2, recordedNodes, recordedNodes2, restoreSecondaryIndexes, schemaVersions, schemaVersions2, sqliteContributions, suspendPostgresSecondaryIndexes, suspendSqliteSecondaryIndexes, tableExistsFromRow, tables, tables2, uniques, uniques2, vectorSlotFromCreateIndexParams, vectorSlotFromDropIndexParams, vectorSlotFromParams };
5037
+ //# sourceMappingURL=chunk-UKOVGCRN.js.map
5038
+ //# sourceMappingURL=chunk-UKOVGCRN.js.map