@nicia-ai/typegraph 0.49.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/README.md +12 -0
  2. package/dist/backend/drizzle/indexes.cjs +11 -9
  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 +7 -5
  6. package/dist/backend/index.cjs +190 -53
  7. package/dist/backend/index.d.cts +90 -4
  8. package/dist/backend/index.d.ts +90 -4
  9. package/dist/backend/index.js +9 -12
  10. package/dist/backend/postgres/index.cjs +36 -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 +19 -15
  14. package/dist/backend/postgres/pglite-store.cjs +7 -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 +7 -62
  19. package/dist/backend/postgres/pglite-store.js.map +1 -1
  20. package/dist/backend/postgres/pglite.cjs +21 -17
  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 +20 -16
  24. package/dist/backend/sqlite/index.cjs +33 -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 +17 -13
  28. package/dist/backend/sqlite/libsql.cjs +24 -20
  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 +19 -15
  33. package/dist/backend/sqlite/libsql.js.map +1 -1
  34. package/dist/backend/sqlite/local-store.cjs +9 -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 +8 -64
  39. package/dist/backend/sqlite/local-store.js.map +1 -1
  40. package/dist/backend/sqlite/local.cjs +25 -20
  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 +21 -16
  44. package/dist/chunk-2CVDZCXH.cjs +1278 -0
  45. package/dist/chunk-2CVDZCXH.cjs.map +1 -0
  46. package/dist/{chunk-MYKHJI2J.js → chunk-2DWTBNSH.js} +3 -3
  47. package/dist/{chunk-MYKHJI2J.js.map → chunk-2DWTBNSH.js.map} +1 -1
  48. package/dist/{chunk-JB6T4GLL.cjs → chunk-2KCTP3U2.cjs} +870 -528
  49. package/dist/chunk-2KCTP3U2.cjs.map +1 -0
  50. package/dist/{chunk-OORXGFL5.cjs → chunk-322TBTOQ.cjs} +48 -48
  51. package/dist/{chunk-OORXGFL5.cjs.map → chunk-322TBTOQ.cjs.map} +1 -1
  52. package/dist/{chunk-FA2AFWLP.cjs → chunk-36SX6QXP.cjs} +31 -12
  53. package/dist/chunk-36SX6QXP.cjs.map +1 -0
  54. package/dist/{chunk-SDBBMD4N.js → chunk-36VYWVQU.js} +3 -3
  55. package/dist/{chunk-SDBBMD4N.js.map → chunk-36VYWVQU.js.map} +1 -1
  56. package/dist/chunk-4DKY6RIU.js +1253 -0
  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-WIC7DRXW.js → chunk-57JM6NW3.js} +9 -19
  61. package/dist/chunk-57JM6NW3.js.map +1 -0
  62. package/dist/chunk-5WWEYV4H.cjs +5113 -0
  63. package/dist/chunk-5WWEYV4H.cjs.map +1 -0
  64. package/dist/chunk-6KQEICJ6.cjs +12 -0
  65. package/dist/{chunk-MKJ4KXL5.cjs.map → chunk-6KQEICJ6.cjs.map} +1 -1
  66. package/dist/{chunk-DZAICA5J.js → chunk-6NKSE5AU.js} +4 -4
  67. package/dist/{chunk-DZAICA5J.js.map → chunk-6NKSE5AU.js.map} +1 -1
  68. package/dist/{chunk-KKBDXCLQ.js → chunk-6NLYIMJO.js} +4 -4
  69. package/dist/{chunk-KKBDXCLQ.js.map → chunk-6NLYIMJO.js.map} +1 -1
  70. package/dist/{chunk-BFUOME67.cjs → chunk-7B7I7YAW.cjs} +20 -11
  71. package/dist/chunk-7B7I7YAW.cjs.map +1 -0
  72. package/dist/{chunk-ZDKTPBGV.js → chunk-7G5IYROL.js} +6 -548
  73. package/dist/chunk-7G5IYROL.js.map +1 -0
  74. package/dist/{chunk-3DMMGT6S.js → chunk-7QFRK6PU.js} +4 -8
  75. package/dist/chunk-7QFRK6PU.js.map +1 -0
  76. package/dist/chunk-A4C4NJ5U.cjs +12 -0
  77. package/dist/chunk-A4C4NJ5U.cjs.map +1 -0
  78. package/dist/{chunk-CHAOFCHV.js → chunk-AH2A74OZ.js} +3 -3
  79. package/dist/{chunk-CHAOFCHV.js.map → chunk-AH2A74OZ.js.map} +1 -1
  80. package/dist/{chunk-UGHQV7MP.cjs → chunk-B3MN7EJR.cjs} +228 -162
  81. package/dist/chunk-B3MN7EJR.cjs.map +1 -0
  82. package/dist/{chunk-TZEGUG6D.cjs → chunk-BZ5MVITP.cjs} +4 -4
  83. package/dist/{chunk-TZEGUG6D.cjs.map → chunk-BZ5MVITP.cjs.map} +1 -1
  84. package/dist/{chunk-YVF2EM7B.js → chunk-CAI6SMP6.js} +3 -3
  85. package/dist/{chunk-YVF2EM7B.js.map → chunk-CAI6SMP6.js.map} +1 -1
  86. package/dist/{chunk-JONXFAPO.js → chunk-CBOD7TXH.js} +5 -5
  87. package/dist/{chunk-JONXFAPO.js.map → chunk-CBOD7TXH.js.map} +1 -1
  88. package/dist/{chunk-FQPEMEWX.cjs → chunk-CRZ56SZU.cjs} +81 -32
  89. package/dist/chunk-CRZ56SZU.cjs.map +1 -0
  90. package/dist/{chunk-DO7SAMEK.cjs → chunk-D3GWARN7.cjs} +47 -47
  91. package/dist/{chunk-DO7SAMEK.cjs.map → chunk-D3GWARN7.cjs.map} +1 -1
  92. package/dist/{chunk-QTD6HX4O.js → chunk-D3OUDFU7.js} +5 -5
  93. package/dist/{chunk-QTD6HX4O.js.map → chunk-D3OUDFU7.js.map} +1 -1
  94. package/dist/{chunk-2QGYQBS2.cjs → chunk-DWUDZ66O.cjs} +10 -10
  95. package/dist/{chunk-2QGYQBS2.cjs.map → chunk-DWUDZ66O.cjs.map} +1 -1
  96. package/dist/chunk-EKG2UXNX.cjs +23 -0
  97. package/dist/chunk-EKG2UXNX.cjs.map +1 -0
  98. package/dist/chunk-FMMW3KX7.cjs +148 -0
  99. package/dist/chunk-FMMW3KX7.cjs.map +1 -0
  100. package/dist/{chunk-XVWOYKIK.js → chunk-FZHF5UWR.js} +3 -3
  101. package/dist/{chunk-XVWOYKIK.js.map → chunk-FZHF5UWR.js.map} +1 -1
  102. package/dist/chunk-H2VWDQWC.cjs +571 -0
  103. package/dist/chunk-H2VWDQWC.cjs.map +1 -0
  104. package/dist/chunk-H4FY6OZK.js +13 -0
  105. package/dist/chunk-H4FY6OZK.js.map +1 -0
  106. package/dist/{chunk-EDN4Y4ZG.cjs → chunk-H5IJSROF.cjs} +9 -15
  107. package/dist/chunk-H5IJSROF.cjs.map +1 -0
  108. package/dist/chunk-HZUB5CON.js +27 -0
  109. package/dist/chunk-HZUB5CON.js.map +1 -0
  110. package/dist/{chunk-NACVVDWB.js → chunk-I5IOSA27.js} +103 -105
  111. package/dist/chunk-I5IOSA27.js.map +1 -0
  112. package/dist/{chunk-OI2GQ25X.cjs → chunk-I7YAY2VQ.cjs} +7 -7
  113. package/dist/{chunk-OI2GQ25X.cjs.map → chunk-I7YAY2VQ.cjs.map} +1 -1
  114. package/dist/chunk-IRCWIA3R.js +20 -0
  115. package/dist/chunk-IRCWIA3R.js.map +1 -0
  116. package/dist/chunk-IVQBLXBK.cjs +55 -0
  117. package/dist/chunk-IVQBLXBK.cjs.map +1 -0
  118. package/dist/{chunk-7SQSZN2J.js → chunk-IZD4HTCP.js} +5 -5
  119. package/dist/{chunk-7SQSZN2J.js.map → chunk-IZD4HTCP.js.map} +1 -1
  120. package/dist/{chunk-3FPR224C.cjs → chunk-JHRUZ73O.cjs} +116 -107
  121. package/dist/chunk-JHRUZ73O.cjs.map +1 -0
  122. package/dist/{chunk-EZEEWCFJ.cjs → chunk-JQKMEKKW.cjs} +525 -298
  123. package/dist/chunk-JQKMEKKW.cjs.map +1 -0
  124. package/dist/chunk-JVA3KDEA.cjs +691 -0
  125. package/dist/chunk-JVA3KDEA.cjs.map +1 -0
  126. package/dist/{chunk-5K2BKEBD.js → chunk-K46SDNQD.js} +10 -4
  127. package/dist/chunk-K46SDNQD.js.map +1 -0
  128. package/dist/{chunk-7LZJNLA5.js → chunk-K67P5DLL.js} +108 -42
  129. package/dist/chunk-K67P5DLL.js.map +1 -0
  130. package/dist/{chunk-3G5W2U2L.cjs → chunk-KACEYDYV.cjs} +335 -258
  131. package/dist/chunk-KACEYDYV.cjs.map +1 -0
  132. package/dist/{chunk-JFRT7S3B.cjs → chunk-L6EVYIID.cjs} +318 -478
  133. package/dist/chunk-L6EVYIID.cjs.map +1 -0
  134. package/dist/{chunk-SHFBB23Q.js → chunk-LI4K2KEJ.js} +6 -4
  135. package/dist/chunk-LI4K2KEJ.js.map +1 -0
  136. package/dist/chunk-LKZDQ2B4.js +1581 -0
  137. package/dist/chunk-LKZDQ2B4.js.map +1 -0
  138. package/dist/{chunk-WODMN3Q2.cjs → chunk-LLFPQOBA.cjs} +27 -27
  139. package/dist/{chunk-WODMN3Q2.cjs.map → chunk-LLFPQOBA.cjs.map} +1 -1
  140. package/dist/{chunk-P6YLZTRE.js → chunk-LZMQ3SFK.js} +3 -3
  141. package/dist/{chunk-P6YLZTRE.js.map → chunk-LZMQ3SFK.js.map} +1 -1
  142. package/dist/{chunk-HEV35TGT.js → chunk-M3VTS3F6.js} +13 -4
  143. package/dist/chunk-M3VTS3F6.js.map +1 -0
  144. package/dist/{chunk-TQHGE7UC.cjs → chunk-M5MSP3BI.cjs} +18 -10
  145. package/dist/chunk-M5MSP3BI.cjs.map +1 -0
  146. package/dist/{chunk-D4QLTJSM.js → chunk-NBOS7BY3.js} +63 -23
  147. package/dist/chunk-NBOS7BY3.js.map +1 -0
  148. package/dist/chunk-NGQDGL5X.js +140 -0
  149. package/dist/chunk-NGQDGL5X.js.map +1 -0
  150. package/dist/{chunk-SIT26LAZ.cjs → chunk-NLX5OWK7.cjs} +33 -5
  151. package/dist/chunk-NLX5OWK7.cjs.map +1 -0
  152. package/dist/chunk-NUQ2YFFH.cjs +1637 -0
  153. package/dist/chunk-NUQ2YFFH.cjs.map +1 -0
  154. package/dist/{chunk-UMGZDVOA.cjs → chunk-OGL4X4PH.cjs} +206 -208
  155. package/dist/chunk-OGL4X4PH.cjs.map +1 -0
  156. package/dist/{chunk-LRQKXRXO.cjs → chunk-OTNTGEXR.cjs} +4 -4
  157. package/dist/{chunk-LRQKXRXO.cjs.map → chunk-OTNTGEXR.cjs.map} +1 -1
  158. package/dist/chunk-OTWE63BW.js +53 -0
  159. package/dist/chunk-OTWE63BW.js.map +1 -0
  160. package/dist/chunk-PC5NGH5A.js +549 -0
  161. package/dist/chunk-PC5NGH5A.js.map +1 -0
  162. package/dist/{chunk-26YKDNUD.cjs → chunk-PS3TUWJM.cjs} +12 -10
  163. package/dist/chunk-PS3TUWJM.cjs.map +1 -0
  164. package/dist/{chunk-OMZ37BM2.js → chunk-PVFFH7TL.js} +5 -5
  165. package/dist/{chunk-OMZ37BM2.js.map → chunk-PVFFH7TL.js.map} +1 -1
  166. package/dist/chunk-QCD5JKU4.cjs +15 -0
  167. package/dist/chunk-QCD5JKU4.cjs.map +1 -0
  168. package/dist/{chunk-UGHG7PGX.js → chunk-QG5VEOKX.js} +30 -4
  169. package/dist/chunk-QG5VEOKX.js.map +1 -0
  170. package/dist/{chunk-TUNPBZY3.cjs → chunk-QLLZM5I3.cjs} +4 -4
  171. package/dist/{chunk-TUNPBZY3.cjs.map → chunk-QLLZM5I3.cjs.map} +1 -1
  172. package/dist/{chunk-BRRP76WO.js → chunk-RCBG6YMT.js} +781 -375
  173. package/dist/chunk-RCBG6YMT.js.map +1 -0
  174. package/dist/{chunk-LTXQOEIC.js → chunk-RI7RJH4G.js} +281 -204
  175. package/dist/chunk-RI7RJH4G.js.map +1 -0
  176. package/dist/{chunk-GYEG3ZLZ.cjs → chunk-RJMHU2MG.cjs} +121 -18
  177. package/dist/chunk-RJMHU2MG.cjs.map +1 -0
  178. package/dist/{chunk-GLHXM7C4.js → chunk-RVUL2HXY.js} +61 -23
  179. package/dist/chunk-RVUL2HXY.js.map +1 -0
  180. package/dist/chunk-RWUWTJQY.cjs +30 -0
  181. package/dist/chunk-RWUWTJQY.cjs.map +1 -0
  182. package/dist/{chunk-2O4PCIZ6.cjs → chunk-S5GU4LUN.cjs} +13 -13
  183. package/dist/{chunk-2O4PCIZ6.cjs.map → chunk-S5GU4LUN.cjs.map} +1 -1
  184. package/dist/{chunk-JPD2CTC3.js → chunk-SDPWO2Z5.js} +7 -7
  185. package/dist/{chunk-JPD2CTC3.js.map → chunk-SDPWO2Z5.js.map} +1 -1
  186. package/dist/{chunk-OVI7IXYX.js → chunk-SLGGT2XD.js} +3 -3
  187. package/dist/{chunk-OVI7IXYX.js.map → chunk-SLGGT2XD.js.map} +1 -1
  188. package/dist/{chunk-ROR5ZR6A.cjs → chunk-TIJUA4I6.cjs} +45 -45
  189. package/dist/{chunk-ROR5ZR6A.cjs.map → chunk-TIJUA4I6.cjs.map} +1 -1
  190. package/dist/{chunk-AOSSQDVO.cjs → chunk-TM54OBHX.cjs} +13 -13
  191. package/dist/{chunk-AOSSQDVO.cjs.map → chunk-TM54OBHX.cjs.map} +1 -1
  192. package/dist/{chunk-KF6K7TGH.js → chunk-TYEYRCXL.js} +766 -433
  193. package/dist/chunk-TYEYRCXL.js.map +1 -0
  194. package/dist/{chunk-Z2JCLZFJ.js → chunk-UKOVGCRN.js} +2151 -570
  195. package/dist/chunk-UKOVGCRN.js.map +1 -0
  196. package/dist/chunk-UYKDYE5D.cjs +12 -0
  197. package/dist/{chunk-CICO5GXD.cjs.map → chunk-UYKDYE5D.cjs.map} +1 -1
  198. package/dist/{chunk-S5TERQVW.js → chunk-VAAC7L57.js} +284 -66
  199. package/dist/chunk-VAAC7L57.js.map +1 -0
  200. package/dist/{chunk-7UOLHNWC.cjs → chunk-VKHXYVN7.cjs} +22 -33
  201. package/dist/chunk-VKHXYVN7.cjs.map +1 -0
  202. package/dist/{chunk-6NGW27EO.cjs → chunk-VLBTRXA2.cjs} +10 -10
  203. package/dist/{chunk-6NGW27EO.cjs.map → chunk-VLBTRXA2.cjs.map} +1 -1
  204. package/dist/{chunk-YIURNGXI.js → chunk-VUQZNUHU.js} +22 -6
  205. package/dist/chunk-VUQZNUHU.js.map +1 -0
  206. package/dist/{chunk-YYUHLYM2.cjs → chunk-WDM5WQK4.cjs} +183 -143
  207. package/dist/chunk-WDM5WQK4.cjs.map +1 -0
  208. package/dist/{chunk-ZFMCDJGB.js → chunk-WFSYYU4W.js} +70 -220
  209. package/dist/chunk-WFSYYU4W.js.map +1 -0
  210. package/dist/{chunk-SR725PWF.cjs → chunk-WRBV2FNH.cjs} +2065 -1659
  211. package/dist/chunk-WRBV2FNH.cjs.map +1 -0
  212. package/dist/{chunk-MRDBBHIZ.cjs → chunk-X4GDXBOP.cjs} +2 -2
  213. package/dist/chunk-X4GDXBOP.cjs.map +1 -0
  214. package/dist/chunk-XORONCV3.js +202 -0
  215. package/dist/chunk-XORONCV3.js.map +1 -0
  216. package/dist/{chunk-D5R42W5D.js → chunk-XZW2CTNO.js} +115 -12
  217. package/dist/chunk-XZW2CTNO.js.map +1 -0
  218. package/dist/{chunk-ZLONH2UD.js → chunk-YDEJQWOL.js} +2 -2
  219. package/dist/chunk-YDEJQWOL.js.map +1 -0
  220. package/dist/{chunk-2TYSSBU5.js → chunk-YT2IVFAI.js} +30 -21
  221. package/dist/chunk-YT2IVFAI.js.map +1 -0
  222. package/dist/chunk-ZGVTNKTX.cjs +217 -0
  223. package/dist/chunk-ZGVTNKTX.cjs.map +1 -0
  224. package/dist/core/index.cjs +29 -28
  225. package/dist/core/index.d.cts +4 -4
  226. package/dist/core/index.d.ts +4 -4
  227. package/dist/core/index.js +9 -8
  228. package/dist/{ddl-D_oW-EVO.d.ts → ddl-BvcbgzHo.d.ts} +3 -3
  229. package/dist/{ddl-BL1NZLMY.d.cts → ddl-Ufebz5q5.d.cts} +3 -3
  230. package/dist/graph-extension/index.cjs +21 -20
  231. package/dist/graph-extension/index.d.cts +2 -4
  232. package/dist/graph-extension/index.d.ts +2 -4
  233. package/dist/graph-extension/index.js +5 -4
  234. package/dist/graph-merge/index.cjs +324 -307
  235. package/dist/graph-merge/index.cjs.map +1 -1
  236. package/dist/graph-merge/index.d.cts +8 -9
  237. package/dist/graph-merge/index.d.ts +8 -9
  238. package/dist/graph-merge/index.js +51 -34
  239. package/dist/graph-merge/index.js.map +1 -1
  240. package/dist/index.cjs +224 -222
  241. package/dist/index.cjs.map +1 -1
  242. package/dist/index.d.cts +11 -12
  243. package/dist/index.d.ts +11 -12
  244. package/dist/index.js +38 -36
  245. package/dist/index.js.map +1 -1
  246. package/dist/indexes/index.cjs +15 -13
  247. package/dist/indexes/index.d.cts +4 -4
  248. package/dist/indexes/index.d.ts +4 -4
  249. package/dist/indexes/index.js +8 -6
  250. package/dist/{ingestion-import-target-dNeL7iAv.d.ts → ingestion-import-target-CAs1OX-l.d.cts} +1 -1
  251. package/dist/{ingestion-import-target-XPxZYw89.d.cts → ingestion-import-target-DCQSPfNx.d.ts} +1 -1
  252. package/dist/interchange/index.cjs +57 -54
  253. package/dist/interchange/index.cjs.map +1 -1
  254. package/dist/interchange/index.d.cts +19 -8
  255. package/dist/interchange/index.d.ts +19 -8
  256. package/dist/interchange/index.js +21 -18
  257. package/dist/interchange/index.js.map +1 -1
  258. package/dist/local-store-impl-6DDTFM32.cjs +77 -0
  259. package/dist/local-store-impl-6DDTFM32.cjs.map +1 -0
  260. package/dist/local-store-impl-OXTOVU2J.js +75 -0
  261. package/dist/local-store-impl-OXTOVU2J.js.map +1 -0
  262. package/dist/{manager-CYaff3n3.d.cts → manager-B68OrPR2.d.ts} +29 -2
  263. package/dist/{manager-D9eRT_ns.d.ts → manager-D_t7oK69.d.cts} +29 -2
  264. package/dist/pglite-store-impl-6EMZGL7K.js +73 -0
  265. package/dist/pglite-store-impl-6EMZGL7K.js.map +1 -0
  266. package/dist/pglite-store-impl-GJG3Y7RP.cjs +75 -0
  267. package/dist/pglite-store-impl-GJG3Y7RP.cjs.map +1 -0
  268. package/dist/{postgres-CcL4bAHS.d.ts → postgres-BPLSVyHM.d.ts} +279 -2
  269. package/dist/{postgres-DMj39MEu.d.cts → postgres-CqvtFC2y.d.cts} +279 -2
  270. package/dist/profiler/index.d.cts +9 -9
  271. package/dist/profiler/index.d.ts +9 -9
  272. package/dist/provenance/index.cjs +59 -44
  273. package/dist/provenance/index.cjs.map +1 -1
  274. package/dist/provenance/index.d.cts +7 -7
  275. package/dist/provenance/index.d.ts +7 -7
  276. package/dist/provenance/index.js +28 -13
  277. package/dist/provenance/index.js.map +1 -1
  278. package/dist/{repair-validity-windows-BFNZvd_H.d.cts → repair-validity-windows-DEzCKAdy.d.cts} +7 -3
  279. package/dist/{repair-validity-windows-DlUSqwCg.d.ts → repair-validity-windows-GMdaS2AH.d.ts} +7 -3
  280. package/dist/resolve-D_H8MHtq.d.ts +1805 -0
  281. package/dist/resolve-WEW8gWws.d.cts +1805 -0
  282. package/dist/schema/index.cjs +48 -46
  283. package/dist/schema/index.d.cts +4 -6
  284. package/dist/schema/index.d.ts +4 -6
  285. package/dist/schema/index.js +21 -19
  286. package/dist/{searchable-bpE1bBfc.d.ts → searchable-C_UREI9K.d.ts} +1 -1
  287. package/dist/{searchable-DHJMh_nj.d.cts → searchable-ClgET_i7.d.cts} +1 -1
  288. package/dist/{sqlite-YppHrNFb.d.cts → sqlite-D1mXO9Kp.d.cts} +310 -2
  289. package/dist/{sqlite-D7Oz0SQh.d.ts → sqlite-MZA3oZNB.d.ts} +310 -2
  290. package/dist/{store-bphCSo7z.d.cts → store-CuFX7fCx.d.cts} +117 -31
  291. package/dist/{store-DRrFCx5x.d.ts → store-D-ZjXQpW.d.ts} +117 -31
  292. package/dist/{temporal-CbnLzTmM.d.ts → temporal-CpyEiRY8.d.cts} +1 -1
  293. package/dist/{temporal-5GqpYCk2.d.cts → temporal-y0Aep9Su.d.ts} +1 -1
  294. package/dist/{types-BqFZTQmV.d.cts → types-6yf0Vv-_.d.cts} +2016 -94
  295. package/dist/{types-BqFZTQmV.d.ts → types-6yf0Vv-_.d.ts} +2016 -94
  296. package/dist/{types-Bx74kaTt.d.ts → types-DzJ4dlzk.d.cts} +1 -1
  297. package/dist/{types-CXAhpW-c.d.cts → types-_vVSB9k-.d.ts} +1 -1
  298. package/dist/{where-O-k2wgYm.d.ts → where-DuG2LCLe.d.ts} +1 -1
  299. package/dist/{where-DI_Fqz-X.d.cts → where-Mhf_yyKX.d.cts} +1 -1
  300. package/package.json +7 -2
  301. package/dist/chunk-26YKDNUD.cjs.map +0 -1
  302. package/dist/chunk-2TYSSBU5.js.map +0 -1
  303. package/dist/chunk-3DMMGT6S.js.map +0 -1
  304. package/dist/chunk-3FPR224C.cjs.map +0 -1
  305. package/dist/chunk-3G5W2U2L.cjs.map +0 -1
  306. package/dist/chunk-3KOY4FH3.cjs +0 -934
  307. package/dist/chunk-3KOY4FH3.cjs.map +0 -1
  308. package/dist/chunk-3QNZ5SAJ.cjs +0 -3502
  309. package/dist/chunk-3QNZ5SAJ.cjs.map +0 -1
  310. package/dist/chunk-3U5ABFDW.cjs +0 -259
  311. package/dist/chunk-3U5ABFDW.cjs.map +0 -1
  312. package/dist/chunk-5K2BKEBD.js.map +0 -1
  313. package/dist/chunk-5PRKMB24.cjs +0 -124
  314. package/dist/chunk-5PRKMB24.cjs.map +0 -1
  315. package/dist/chunk-6LN7FIVU.js +0 -107
  316. package/dist/chunk-6LN7FIVU.js.map +0 -1
  317. package/dist/chunk-6SWPJEYN.js +0 -1126
  318. package/dist/chunk-6SWPJEYN.js.map +0 -1
  319. package/dist/chunk-7LZJNLA5.js.map +0 -1
  320. package/dist/chunk-7UOLHNWC.cjs.map +0 -1
  321. package/dist/chunk-BFUOME67.cjs.map +0 -1
  322. package/dist/chunk-BRRP76WO.js.map +0 -1
  323. package/dist/chunk-CICO5GXD.cjs +0 -12
  324. package/dist/chunk-D4QLTJSM.js.map +0 -1
  325. package/dist/chunk-D5R42W5D.js.map +0 -1
  326. package/dist/chunk-EDN4Y4ZG.cjs.map +0 -1
  327. package/dist/chunk-EZEEWCFJ.cjs.map +0 -1
  328. package/dist/chunk-FA2AFWLP.cjs.map +0 -1
  329. package/dist/chunk-FQPEMEWX.cjs.map +0 -1
  330. package/dist/chunk-GLHXM7C4.js.map +0 -1
  331. package/dist/chunk-GYEG3ZLZ.cjs.map +0 -1
  332. package/dist/chunk-HDL2ARHX.cjs +0 -1156
  333. package/dist/chunk-HDL2ARHX.cjs.map +0 -1
  334. package/dist/chunk-HEV35TGT.js.map +0 -1
  335. package/dist/chunk-I4GAZH5Z.js +0 -913
  336. package/dist/chunk-I4GAZH5Z.js.map +0 -1
  337. package/dist/chunk-JB6T4GLL.cjs.map +0 -1
  338. package/dist/chunk-JBQQ7THH.js +0 -20
  339. package/dist/chunk-JBQQ7THH.js.map +0 -1
  340. package/dist/chunk-JFRT7S3B.cjs.map +0 -1
  341. package/dist/chunk-KF6K7TGH.js.map +0 -1
  342. package/dist/chunk-L3LQNR34.cjs +0 -1254
  343. package/dist/chunk-L3LQNR34.cjs.map +0 -1
  344. package/dist/chunk-LTXQOEIC.js.map +0 -1
  345. package/dist/chunk-MKJ4KXL5.cjs +0 -12
  346. package/dist/chunk-MRDBBHIZ.cjs.map +0 -1
  347. package/dist/chunk-NACVVDWB.js.map +0 -1
  348. package/dist/chunk-NVY5CJFP.js +0 -244
  349. package/dist/chunk-NVY5CJFP.js.map +0 -1
  350. package/dist/chunk-PWLJ77UV.cjs +0 -23
  351. package/dist/chunk-PWLJ77UV.cjs.map +0 -1
  352. package/dist/chunk-S5TERQVW.js.map +0 -1
  353. package/dist/chunk-SHFBB23Q.js.map +0 -1
  354. package/dist/chunk-SIT26LAZ.cjs.map +0 -1
  355. package/dist/chunk-SR725PWF.cjs.map +0 -1
  356. package/dist/chunk-TQHGE7UC.cjs.map +0 -1
  357. package/dist/chunk-UGHG7PGX.js.map +0 -1
  358. package/dist/chunk-UGHQV7MP.cjs.map +0 -1
  359. package/dist/chunk-UMGZDVOA.cjs.map +0 -1
  360. package/dist/chunk-WIC7DRXW.js.map +0 -1
  361. package/dist/chunk-YIURNGXI.js.map +0 -1
  362. package/dist/chunk-YYUHLYM2.cjs.map +0 -1
  363. package/dist/chunk-Z2JCLZFJ.js.map +0 -1
  364. package/dist/chunk-ZDKTPBGV.js.map +0 -1
  365. package/dist/chunk-ZFMCDJGB.js.map +0 -1
  366. package/dist/chunk-ZLONH2UD.js.map +0 -1
  367. package/dist/index-COs_z6nV.d.cts +0 -1132
  368. package/dist/index-D7d1u2gr.d.ts +0 -1132
  369. package/dist/materialize-indexes-DJ3ykH59.d.ts +0 -266
  370. package/dist/materialize-indexes-DTtAnvfY.d.cts +0 -266
@@ -1,15 +1,1211 @@
1
- import { formatPostgresTimestamp, coerceNumericScore, nowIso } from './chunk-YIURNGXI.js';
2
- import { runtimeStrategyContributions } from './chunk-6SWPJEYN.js';
3
- import { toDrizzleSql } from './chunk-OMZ37BM2.js';
4
- import { sortedReplacer } from './chunk-JBQQ7THH.js';
5
- import { parseDimensionMismatch, deriveBackend, chunk, isMissingTableError, isDuplicatePrimaryKeyError, errorChain } from './chunk-UGHG7PGX.js';
6
- import { resolveStampedValidityLowerBound, resolveStatedValidityLowerBound } from './chunk-5K2BKEBD.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
+ import { resolveStampedValidityLowerBound, resolveStatedValidityLowerBound } from './chunk-K46SDNQD.js';
8
+ import { assertNoSystemIndexNameCollision } from './chunk-36VYWVQU.js';
7
9
  import { sha256Hex } from './chunk-K34OPSJK.js';
8
- import { buildFulltextGraphDelete, buildForeignFulltextGraphProbe, getDialect } from './chunk-ZDKTPBGV.js';
9
- import { sql as sql$1, asCompiledStatementSql, asCompiledRowsSql, isSqlFragment } from './chunk-3DMMGT6S.js';
10
- import { EmbeddingDimensionChangedError, ConfigurationError, StaleVersionError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, TrustedImportError, ContributionUnavailableError, ContributionRebuildUnsupportedError, StoreNotInitializedError } from './chunk-ZLONH2UD.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';
11
14
  import { isPresent } from './chunk-DYATYRY4.js';
12
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
+ }
13
1209
 
14
1210
  // src/backend/edge-endpoint-sets.ts
15
1211
  var FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT = 6;
@@ -78,10 +1274,10 @@ function resolveHeterogeneousEdgeRead(params, maxBindParameters) {
78
1274
 
79
1275
  // src/backend/live-node-candidates.ts
80
1276
  function buildLiveNodeCandidates(nodesTableName, graphId, nodeKind, now) {
81
- const nodes = sql$1.identifier(nodesTableName);
1277
+ const nodes3 = sql$1.identifier(nodesTableName);
82
1278
  return sql$1`
83
1279
  SELECT "id" AS node_id
84
- FROM ${nodes}
1280
+ FROM ${nodes3}
85
1281
  WHERE "graph_id" = ${graphId}
86
1282
  AND "kind" = ${nodeKind}
87
1283
  AND "deleted_at" IS NULL
@@ -384,7 +1580,7 @@ function createContributionMaterializer(deps) {
384
1580
  const cachedCreateDdl = cached?.createDdl;
385
1581
  const cachedSignature = cached?.signature;
386
1582
  if (cachedCreateDdl?.length === contribution.createDdl.length && cachedSignature !== void 0 && contribution.createDdl.every(
387
- (statement, index) => cachedCreateDdl[index] === statement
1583
+ (statement, index3) => cachedCreateDdl[index3] === statement
388
1584
  )) {
389
1585
  return cachedSignature;
390
1586
  }
@@ -752,20 +1948,42 @@ function createContributionMaterializer(deps) {
752
1948
  };
753
1949
  }
754
1950
  async function lockContributionDdl(tx) {
755
- if (dialect !== "postgres") return;
756
- await tx.execute(
757
- asCompiledRowsSql(
758
- sql$1`SELECT pg_advisory_xact_lock(hashtext(${CONTRIBUTION_DDL_LOCK_KEY}), 0)`
759
- )
760
- );
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
+ }
761
1966
  }
762
1967
  async function lockSharedFulltextTable(tx, tableName) {
763
- if (dialect !== "postgres") return;
764
- await tx.executeStatement(
765
- asCompiledStatementSql(
766
- sql$1`LOCK TABLE ${sql$1.identifier(tableName)} IN ACCESS EXCLUSIVE MODE`
767
- )
1968
+ const plan = resolveWriteFencePlan(deps.fenceTarget);
1969
+ const fence = requireWriteFence(
1970
+ plan,
1971
+ "shared fulltext table lock",
1972
+ "table-lock"
768
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
+ }
769
1987
  }
770
1988
  async function readForeignGraphIds(tx, tableName, graphId) {
771
1989
  const rows = await tx.execute(
@@ -1043,24 +2261,24 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
1043
2261
  function primaryKeyConstraintNames(relation, keyColumns) {
1044
2262
  return [`${relation}_pkey`, `${relation}_${keyColumns.join("_")}_pk`];
1045
2263
  }
1046
- function nodePrimaryKeyConstraint(nodes) {
1047
- const relation = getTableName(nodes);
2264
+ function nodePrimaryKeyConstraint(nodes3) {
2265
+ const relation = getTableName(nodes3);
1048
2266
  return {
1049
2267
  table: relation,
1050
2268
  constraintNames: primaryKeyConstraintNames(relation, [
1051
- nodes.graphId.name,
1052
- nodes.kind.name,
1053
- nodes.id.name
2269
+ nodes3.graphId.name,
2270
+ nodes3.kind.name,
2271
+ nodes3.id.name
1054
2272
  ])
1055
2273
  };
1056
2274
  }
1057
- function edgePrimaryKeyConstraint(edges) {
1058
- const relation = getTableName(edges);
2275
+ function edgePrimaryKeyConstraint(edges3) {
2276
+ const relation = getTableName(edges3);
1059
2277
  return {
1060
2278
  table: relation,
1061
2279
  constraintNames: primaryKeyConstraintNames(relation, [
1062
- edges.graphId.name,
1063
- edges.id.name
2280
+ edges3.graphId.name,
2281
+ edges3.id.name
1064
2282
  ])
1065
2283
  };
1066
2284
  }
@@ -1085,17 +2303,17 @@ var CODE_POINT_ORDER_BUILDERS = {
1085
2303
  function codePointOrderKey(column, dialect) {
1086
2304
  return CODE_POINT_ORDER_BUILDERS[dialect](column);
1087
2305
  }
1088
- function liveNodeIdsSubquery(nodes, graphId, nodeKind, nowIso2) {
1089
- return sql`SELECT ${nodes.id} AS node_id FROM ${nodes} WHERE ${nodes.graphId} = ${graphId} AND ${nodes.kind} = ${nodeKind} AND ${nodes.deletedAt} IS NULL AND (${nodes.validFrom} IS NULL OR ${nodes.validFrom} <= ${nowIso2}) AND (${nodes.validTo} IS NULL OR ${nodes.validTo} > ${nowIso2})`;
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})`;
1090
2308
  }
1091
- function nodeColumnList(nodes) {
2309
+ function nodeColumnList(nodes3) {
1092
2310
  return sql.raw(
1093
- `"${nodes.graphId.name}", "${nodes.kind.name}", "${nodes.id.name}", "${nodes.props.name}", "${nodes.version.name}", "${nodes.validFrom.name}", "${nodes.validTo.name}", "${nodes.createdAt.name}", "${nodes.updatedAt.name}"`
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}"`
1094
2312
  );
1095
2313
  }
1096
- function edgeColumnList(edges) {
2314
+ function edgeColumnList(edges3) {
1097
2315
  return sql.raw(
1098
- `"${edges.graphId.name}", "${edges.id.name}", "${edges.kind.name}", "${edges.fromKind.name}", "${edges.fromId.name}", "${edges.toKind.name}", "${edges.toId.name}", "${edges.props.name}", "${edges.validFrom.name}", "${edges.validTo.name}", "${edges.createdAt.name}", "${edges.updatedAt.name}"`
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}"`
1099
2317
  );
1100
2318
  }
1101
2319
 
@@ -1107,20 +2325,20 @@ function hybridCandidatesRef() {
1107
2325
  return sql`SELECT node_id FROM tg_hybrid_cand`;
1108
2326
  }
1109
2327
  function buildHybridSearchStatement(input) {
1110
- const { nodes } = input;
2328
+ const { nodes: nodes3 } = input;
1111
2329
  const nodeIdOrder = nodeIdOrderKey(input.dialect);
1112
2330
  const vectorOrder = input.vectorScoreDescending ? sql`score DESC, ${nodeIdOrder} ASC` : sql`score ASC, ${nodeIdOrder} ASC`;
1113
2331
  const columnPairs = [
1114
- [nodes.graphId, "graph_id"],
1115
- [nodes.kind, "kind"],
1116
- [nodes.id, "id"],
1117
- [nodes.props, "props"],
1118
- [nodes.version, "version"],
1119
- [nodes.validFrom, "valid_from"],
1120
- [nodes.validTo, "valid_to"],
1121
- [nodes.createdAt, "created_at"],
1122
- [nodes.updatedAt, "updated_at"],
1123
- [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"]
1124
2342
  ];
1125
2343
  const nodeColumns = sql.raw(
1126
2344
  columnPairs.map(
@@ -1173,17 +2391,17 @@ function buildHybridSearchStatement(input) {
1173
2391
  tg_hybrid_fused.snippet AS snippet,
1174
2392
  ${nodeColumns}
1175
2393
  FROM tg_hybrid_fused
1176
- JOIN ${nodes} AS tg_hybrid_node
1177
- ON ${qualified(nodes, "graphId")} = ${input.graphId}
1178
- AND ${qualified(nodes, "kind")} = ${input.nodeKind}
1179
- AND ${qualified(nodes, "id")} = tg_hybrid_fused.node_id
1180
- 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
1181
2399
  ORDER BY fused_score DESC, ${nodeIdOrder} ASC
1182
2400
  LIMIT ${input.limit} OFFSET ${input.offset}
1183
2401
  `;
1184
2402
  }
1185
- function qualified(nodes, member) {
1186
- return sql`tg_hybrid_node.${quotedColumn(nodes[member])}`;
2403
+ function qualified(nodes3, member) {
2404
+ return sql`tg_hybrid_node.${quotedColumn(nodes3[member])}`;
1187
2405
  }
1188
2406
  function present(value) {
1189
2407
  return value !== null && value !== void 0;
@@ -1203,67 +2421,78 @@ function mapHybridSearchRow(row, toNodeRow) {
1203
2421
  ...present(row["snippet"]) ? { snippet: String(row["snippet"]) } : {}
1204
2422
  };
1205
2423
  }
1206
- function buildClearGraph(tables, graphId) {
2424
+ function buildClearGraph(tables3, graphId) {
1207
2425
  return [
1208
2426
  // The fulltext table is shared by every graph in the database, so its
1209
2427
  // graph-scoped delete is owned by one builder the destructive
1210
2428
  // contribution rebuild calls too — see `buildFulltextGraphDelete`.
1211
- { query: buildFulltextGraphDelete(tables.fulltextTableName, graphId) },
2429
+ { query: buildFulltextGraphDelete(tables3.fulltextTableName, graphId) },
1212
2430
  {
1213
- query: sql`DELETE FROM ${tables.recordedIdentityAssertions} WHERE ${tables.recordedIdentityAssertions.graphId} = ${graphId}`,
2431
+ query: sql`DELETE FROM ${tables3.recordedIdentityAssertions} WHERE ${tables3.recordedIdentityAssertions.graphId} = ${graphId}`,
1214
2432
  ignoreMissingTable: true,
1215
- requiredTableName: getTableName(tables.recordedIdentityAssertions)
2433
+ requiredTableName: getTableName(tables3.recordedIdentityAssertions)
1216
2434
  },
1217
2435
  {
1218
- query: sql`DELETE FROM ${tables.recordedEdges} WHERE ${tables.recordedEdges.graphId} = ${graphId}`,
2436
+ query: sql`DELETE FROM ${tables3.recordedEdges} WHERE ${tables3.recordedEdges.graphId} = ${graphId}`,
1219
2437
  ignoreMissingTable: true,
1220
- requiredTableName: getTableName(tables.recordedEdges)
2438
+ requiredTableName: getTableName(tables3.recordedEdges)
1221
2439
  },
1222
2440
  {
1223
- query: sql`DELETE FROM ${tables.recordedNodes} WHERE ${tables.recordedNodes.graphId} = ${graphId}`,
2441
+ query: sql`DELETE FROM ${tables3.recordedNodes} WHERE ${tables3.recordedNodes.graphId} = ${graphId}`,
1224
2442
  ignoreMissingTable: true,
1225
- requiredTableName: getTableName(tables.recordedNodes)
2443
+ requiredTableName: getTableName(tables3.recordedNodes)
1226
2444
  },
1227
2445
  {
1228
- query: sql`DELETE FROM ${tables.recordedClock} WHERE ${tables.recordedClock.graphId} = ${graphId}`,
2446
+ query: sql`DELETE FROM ${tables3.recordedClock} WHERE ${tables3.recordedClock.graphId} = ${graphId}`,
1229
2447
  ignoreMissingTable: true,
1230
- requiredTableName: getTableName(tables.recordedClock)
2448
+ requiredTableName: getTableName(tables3.recordedClock)
1231
2449
  },
1232
2450
  {
1233
- query: sql`DELETE FROM ${tables.identitySeparation} WHERE ${tables.identitySeparation.graphId} = ${graphId}`,
2451
+ query: sql`DELETE FROM ${tables3.identitySeparation} WHERE ${tables3.identitySeparation.graphId} = ${graphId}`,
1234
2452
  ignoreMissingTable: true,
1235
- requiredTableName: getTableName(tables.identitySeparation)
2453
+ requiredTableName: getTableName(tables3.identitySeparation)
1236
2454
  },
1237
2455
  {
1238
- query: sql`DELETE FROM ${tables.identityClosure} WHERE ${tables.identityClosure.graphId} = ${graphId}`,
2456
+ query: sql`DELETE FROM ${tables3.identityClosure} WHERE ${tables3.identityClosure.graphId} = ${graphId}`,
1239
2457
  ignoreMissingTable: true,
1240
- requiredTableName: getTableName(tables.identityClosure)
2458
+ requiredTableName: getTableName(tables3.identityClosure)
1241
2459
  },
1242
2460
  {
1243
- query: sql`DELETE FROM ${tables.identityAssertions} WHERE ${tables.identityAssertions.graphId} = ${graphId}`,
2461
+ query: sql`DELETE FROM ${tables3.identityAssertions} WHERE ${tables3.identityAssertions.graphId} = ${graphId}`,
1244
2462
  ignoreMissingTable: true,
1245
- requiredTableName: getTableName(tables.identityAssertions)
2463
+ requiredTableName: getTableName(tables3.identityAssertions)
1246
2464
  },
1247
2465
  {
1248
- query: sql`DELETE FROM ${tables.uniques} WHERE ${tables.uniques.graphId} = ${graphId}`
2466
+ query: sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`
2467
+ },
2468
+ // Edge claims name the edges they are held by, so they are cleared
2469
+ // BEFORE the edges — the same ordering `uniques` gets against `nodes`.
2470
+ // Tolerates absence for the reason the recorded relations do: bootstrap DDL
2471
+ // runs only on first boot, so a database initialized before this relation
2472
+ // existed has no such table, and clearing a graph must not become the
2473
+ // operation that fails on it.
2474
+ {
2475
+ query: sql`DELETE FROM ${tables3.edgeClaims} WHERE ${tables3.edgeClaims.graphId} = ${graphId}`,
2476
+ ignoreMissingTable: true,
2477
+ requiredTableName: getTableName(tables3.edgeClaims)
1249
2478
  },
1250
2479
  {
1251
- query: sql`DELETE FROM ${tables.edges} WHERE ${tables.edges.graphId} = ${graphId}`
2480
+ query: sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`
1252
2481
  },
1253
2482
  {
1254
- query: sql`DELETE FROM ${tables.nodes} WHERE ${tables.nodes.graphId} = ${graphId}`
2483
+ query: sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`
1255
2484
  },
1256
2485
  {
1257
- query: sql`DELETE FROM ${tables.indexMaterializations} WHERE ${tables.indexMaterializations.graphId} = ${graphId}`
2486
+ query: sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`
1258
2487
  },
1259
2488
  {
1260
- query: sql`DELETE FROM ${tables.kindRemovals} WHERE ${tables.kindRemovals.graphId} = ${graphId}`
2489
+ query: sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`
1261
2490
  },
1262
2491
  {
1263
- query: sql`DELETE FROM ${tables.reconciliationMarkers} WHERE ${tables.reconciliationMarkers.graphId} = ${graphId}`
2492
+ query: sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
1264
2493
  },
1265
2494
  {
1266
- query: sql`DELETE FROM ${tables.schemaVersions} WHERE ${tables.schemaVersions.graphId} = ${graphId}`
2495
+ query: sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
1267
2496
  }
1268
2497
  ];
1269
2498
  }
@@ -1285,21 +2514,21 @@ function buildTemporalConditions(table, params) {
1285
2514
  }
1286
2515
  return conditions;
1287
2516
  }
1288
- function buildFindNodesByKind(tables, params) {
1289
- const { nodes } = tables;
2517
+ function buildFindNodesByKind(tables3, params) {
2518
+ const { nodes: nodes3 } = tables3;
1290
2519
  const conditions = [
1291
- sql`${nodes.graphId} = ${params.graphId}`,
1292
- sql`${nodes.kind} = ${params.kind}`,
1293
- ...buildTemporalConditions(nodes, params)
2520
+ sql`${nodes3.graphId} = ${params.graphId}`,
2521
+ sql`${nodes3.kind} = ${params.kind}`,
2522
+ ...buildTemporalConditions(nodes3, params)
1294
2523
  ];
1295
2524
  if (params.orderBy === "id" && params.after !== void 0) {
1296
- conditions.push(sql`${nodes.id} > ${params.after}`);
2525
+ conditions.push(sql`${nodes3.id} > ${params.after}`);
1297
2526
  }
1298
2527
  const whereClause = sql.join(conditions, sql` AND `);
1299
- 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`;
1300
2529
  if (params.limit !== void 0 && params.offset !== void 0) {
1301
2530
  return sql`
1302
- SELECT * FROM ${nodes}
2531
+ SELECT * FROM ${nodes3}
1303
2532
  WHERE ${whereClause}
1304
2533
  ORDER BY ${orderByClause}
1305
2534
  LIMIT ${params.limit} OFFSET ${params.offset}
@@ -1307,28 +2536,28 @@ function buildFindNodesByKind(tables, params) {
1307
2536
  }
1308
2537
  if (params.limit !== void 0) {
1309
2538
  return sql`
1310
- SELECT * FROM ${nodes}
2539
+ SELECT * FROM ${nodes3}
1311
2540
  WHERE ${whereClause}
1312
2541
  ORDER BY ${orderByClause}
1313
2542
  LIMIT ${params.limit}
1314
2543
  `;
1315
2544
  }
1316
2545
  return sql`
1317
- SELECT * FROM ${nodes}
2546
+ SELECT * FROM ${nodes3}
1318
2547
  WHERE ${whereClause}
1319
2548
  ORDER BY ${orderByClause}
1320
2549
  `;
1321
2550
  }
1322
- function buildCountNodesByKind(tables, params) {
1323
- const { nodes } = tables;
2551
+ function buildCountNodesByKind(tables3, params) {
2552
+ const { nodes: nodes3 } = tables3;
1324
2553
  const conditions = [
1325
- sql`${nodes.graphId} = ${params.graphId}`,
1326
- sql`${nodes.kind} = ${params.kind}`,
1327
- ...buildTemporalConditions(nodes, params)
2554
+ sql`${nodes3.graphId} = ${params.graphId}`,
2555
+ sql`${nodes3.kind} = ${params.kind}`,
2556
+ ...buildTemporalConditions(nodes3, params)
1328
2557
  ];
1329
2558
  const whereClause = sql.join(conditions, sql` AND `);
1330
2559
  return sql`
1331
- SELECT COUNT(*) as count FROM ${nodes}
2560
+ SELECT COUNT(*) as count FROM ${nodes3}
1332
2561
  WHERE ${whereClause}
1333
2562
  `;
1334
2563
  }
@@ -1338,43 +2567,43 @@ function buildIdSetCondition(column, ids) {
1338
2567
  sql`, `
1339
2568
  )})`;
1340
2569
  }
1341
- function buildEdgeOrdering(tables, orderBy) {
1342
- const { edges } = tables;
1343
- return orderBy === "id" ? { qualified: sql`${edges.id} ASC`, bare: sql.raw(`"id" ASC`) } : {
1344
- 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`,
1345
2574
  bare: sql.raw(`"created_at" DESC, "id" DESC`)
1346
2575
  };
1347
2576
  }
1348
- function buildFindEdgesByKind(tables, params) {
1349
- const { edges } = tables;
2577
+ function buildFindEdgesByKind(tables3, params) {
2578
+ const { edges: edges3 } = tables3;
1350
2579
  const conditions = [
1351
- sql`${edges.graphId} = ${params.graphId}`,
1352
- sql`${edges.kind} = ${params.kind}`,
1353
- ...buildTemporalConditions(edges, params)
2580
+ sql`${edges3.graphId} = ${params.graphId}`,
2581
+ sql`${edges3.kind} = ${params.kind}`,
2582
+ ...buildTemporalConditions(edges3, params)
1354
2583
  ];
1355
2584
  if (params.fromKind !== void 0) {
1356
- conditions.push(sql`${edges.fromKind} = ${params.fromKind}`);
2585
+ conditions.push(sql`${edges3.fromKind} = ${params.fromKind}`);
1357
2586
  }
1358
2587
  if (params.fromId !== void 0) {
1359
- conditions.push(sql`${edges.fromId} = ${params.fromId}`);
2588
+ conditions.push(sql`${edges3.fromId} = ${params.fromId}`);
1360
2589
  }
1361
2590
  if (params.toKind !== void 0) {
1362
- conditions.push(sql`${edges.toKind} = ${params.toKind}`);
2591
+ conditions.push(sql`${edges3.toKind} = ${params.toKind}`);
1363
2592
  }
1364
2593
  if (params.toId !== void 0) {
1365
- conditions.push(sql`${edges.toId} = ${params.toId}`);
2594
+ conditions.push(sql`${edges3.toId} = ${params.toId}`);
1366
2595
  }
1367
2596
  if (params.orderBy === "id" && params.after !== void 0) {
1368
- conditions.push(sql`${edges.id} > ${params.after}`);
2597
+ conditions.push(sql`${edges3.id} > ${params.after}`);
1369
2598
  }
1370
2599
  const whereClause = sql.join(conditions, sql` AND `);
1371
2600
  const { qualified: orderByClause } = buildEdgeOrdering(
1372
- tables,
2601
+ tables3,
1373
2602
  params.orderBy
1374
2603
  );
1375
2604
  if (params.limit !== void 0 && params.offset !== void 0) {
1376
2605
  return sql`
1377
- SELECT * FROM ${edges}
2606
+ SELECT * FROM ${edges3}
1378
2607
  WHERE ${whereClause}
1379
2608
  ORDER BY ${orderByClause}
1380
2609
  LIMIT ${params.limit} OFFSET ${params.offset}
@@ -1382,37 +2611,37 @@ function buildFindEdgesByKind(tables, params) {
1382
2611
  }
1383
2612
  if (params.limit !== void 0) {
1384
2613
  return sql`
1385
- SELECT * FROM ${edges}
2614
+ SELECT * FROM ${edges3}
1386
2615
  WHERE ${whereClause}
1387
2616
  ORDER BY ${orderByClause}
1388
2617
  LIMIT ${params.limit}
1389
2618
  `;
1390
2619
  }
1391
2620
  return sql`
1392
- SELECT * FROM ${edges}
2621
+ SELECT * FROM ${edges3}
1393
2622
  WHERE ${whereClause}
1394
2623
  ORDER BY ${orderByClause}
1395
2624
  `;
1396
2625
  }
1397
- function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1398
- const { edges } = tables;
2626
+ function buildFindEdgesByEndpointSet(tables3, params, endpointIds) {
2627
+ const { edges: edges3 } = tables3;
1399
2628
  const fromSide = params.side === "from";
1400
- const kindColumn = fromSide ? edges.fromKind : edges.toKind;
1401
- const idColumn = fromSide ? edges.fromId : edges.toId;
2629
+ const kindColumn = fromSide ? edges3.fromKind : edges3.toKind;
2630
+ const idColumn = fromSide ? edges3.fromId : edges3.toId;
1402
2631
  const whereClause = sql.join(
1403
2632
  [
1404
- sql`${edges.graphId} = ${params.graphId}`,
1405
- sql`${edges.kind} = ${params.kind}`,
1406
- ...buildTemporalConditions(edges, params),
2633
+ sql`${edges3.graphId} = ${params.graphId}`,
2634
+ sql`${edges3.kind} = ${params.kind}`,
2635
+ ...buildTemporalConditions(edges3, params),
1407
2636
  sql`${kindColumn} = ${params.endpointKind}`,
1408
2637
  buildIdSetCondition(idColumn, endpointIds)
1409
2638
  ],
1410
2639
  sql` AND `
1411
2640
  );
1412
- const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
2641
+ const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables3, void 0);
1413
2642
  if (params.limitPerEndpoint === void 0) {
1414
2643
  return sql`
1415
- SELECT * FROM ${edges}
2644
+ SELECT * FROM ${edges3}
1416
2645
  WHERE ${whereClause}
1417
2646
  ORDER BY ${orderByClause}
1418
2647
  `;
@@ -1421,7 +2650,7 @@ function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1421
2650
  SELECT *, ROW_NUMBER() OVER (
1422
2651
  PARTITION BY ${idColumn} ORDER BY ${orderByClause}
1423
2652
  ) AS endpoint_rank
1424
- FROM ${edges}
2653
+ FROM ${edges3}
1425
2654
  WHERE ${whereClause}
1426
2655
  `;
1427
2656
  return sql`
@@ -1430,11 +2659,11 @@ function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
1430
2659
  ORDER BY ${derivedOrderByClause}
1431
2660
  `;
1432
2661
  }
1433
- function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edgeKinds) {
1434
- const { edges } = tables;
2662
+ function buildFindEdgesByHeterogeneousEndpointSet(tables3, params, endpoints, edgeKinds) {
2663
+ const { edges: edges3 } = tables3;
1435
2664
  const fromSide = params.side === "from";
1436
- const kindColumn = fromSide ? edges.fromKind : edges.toKind;
1437
- const idColumn = fromSide ? edges.fromId : edges.toId;
2665
+ const kindColumn = fromSide ? edges3.fromKind : edges3.toKind;
2666
+ const idColumn = fromSide ? edges3.fromId : edges3.toId;
1438
2667
  const requestedKind = sql.raw(`requested_endpoints."endpoint_kind"`);
1439
2668
  const requestedId = sql.raw(`requested_endpoints."endpoint_id"`);
1440
2669
  const requestedRows = sql.join(
@@ -1443,32 +2672,32 @@ function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edg
1443
2672
  );
1444
2673
  const whereClause = sql.join(
1445
2674
  [
1446
- sql`${edges.graphId} = ${params.graphId}`,
1447
- buildIdSetCondition(edges.kind, edgeKinds),
1448
- ...buildTemporalConditions(edges, params)
2675
+ sql`${edges3.graphId} = ${params.graphId}`,
2676
+ buildIdSetCondition(edges3.kind, edgeKinds),
2677
+ ...buildTemporalConditions(edges3, params)
1449
2678
  ],
1450
2679
  sql` AND `
1451
2680
  );
1452
2681
  const joinClause = sql`
1453
- FROM ${edges}
2682
+ FROM ${edges3}
1454
2683
  INNER JOIN requested_endpoints
1455
2684
  ON ${kindColumn} = ${requestedKind}
1456
2685
  AND ${idColumn} = ${requestedId}
1457
2686
  WHERE ${whereClause}
1458
2687
  `;
1459
- const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
2688
+ const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables3, void 0);
1460
2689
  if (params.limitPerEndpoint === void 0) {
1461
2690
  return sql`
1462
2691
  WITH requested_endpoints(endpoint_kind, endpoint_id) AS (
1463
2692
  VALUES ${requestedRows}
1464
2693
  )
1465
- SELECT ${edges}.*
2694
+ SELECT ${edges3}.*
1466
2695
  ${joinClause}
1467
2696
  ORDER BY ${orderByClause}
1468
2697
  `;
1469
2698
  }
1470
2699
  const ranked = sql`
1471
- SELECT ${edges}.*, ROW_NUMBER() OVER (
2700
+ SELECT ${edges3}.*, ROW_NUMBER() OVER (
1472
2701
  PARTITION BY ${kindColumn}, ${idColumn} ORDER BY ${orderByClause}
1473
2702
  ) AS endpoint_rank
1474
2703
  ${joinClause}
@@ -1482,269 +2711,417 @@ function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edg
1482
2711
  ORDER BY ${derivedOrderByClause}
1483
2712
  `;
1484
2713
  }
1485
- function buildCountEdgesByKind(tables, params) {
1486
- const { edges } = tables;
2714
+ function buildCountEdgesByKind(tables3, params) {
2715
+ const { edges: edges3 } = tables3;
1487
2716
  const conditions = [
1488
- sql`${edges.graphId} = ${params.graphId}`,
1489
- sql`${edges.kind} = ${params.kind}`,
1490
- ...buildTemporalConditions(edges, params)
2717
+ sql`${edges3.graphId} = ${params.graphId}`,
2718
+ sql`${edges3.kind} = ${params.kind}`,
2719
+ ...buildTemporalConditions(edges3, params)
1491
2720
  ];
1492
2721
  if (params.fromKind !== void 0) {
1493
- conditions.push(sql`${edges.fromKind} = ${params.fromKind}`);
2722
+ conditions.push(sql`${edges3.fromKind} = ${params.fromKind}`);
1494
2723
  }
1495
2724
  if (params.fromId !== void 0) {
1496
- conditions.push(sql`${edges.fromId} = ${params.fromId}`);
2725
+ conditions.push(sql`${edges3.fromId} = ${params.fromId}`);
1497
2726
  }
1498
2727
  if (params.toKind !== void 0) {
1499
- conditions.push(sql`${edges.toKind} = ${params.toKind}`);
2728
+ conditions.push(sql`${edges3.toKind} = ${params.toKind}`);
1500
2729
  }
1501
2730
  if (params.toId !== void 0) {
1502
- conditions.push(sql`${edges.toId} = ${params.toId}`);
2731
+ conditions.push(sql`${edges3.toId} = ${params.toId}`);
1503
2732
  }
1504
2733
  const whereClause = sql.join(conditions, sql` AND `);
1505
2734
  return sql`
1506
- SELECT COUNT(*) as count FROM ${edges}
2735
+ SELECT COUNT(*) as count FROM ${edges3}
1507
2736
  WHERE ${whereClause}
1508
2737
  `;
1509
2738
  }
1510
- function buildInsertEdge(tables, params, timestamp) {
1511
- const { edges } = tables;
2739
+ var PEER = "peer";
2740
+ function qualified2(relation, column) {
2741
+ return sql.raw(`"${relation}"."${column.name}"`);
2742
+ }
2743
+ function inList(values) {
2744
+ return sql.join(
2745
+ values.map((value) => sql`${value}`),
2746
+ sql`, `
2747
+ );
2748
+ }
2749
+ function buildContendedUniqueRowAudit(tables3, graphId, constraintNames) {
2750
+ const { uniques: uniques3 } = tables3;
2751
+ const relation = getTableName(uniques3);
2752
+ return sql`
2753
+ SELECT
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
2763
+ AND EXISTS (
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)}
2770
+ )
2771
+ `;
2772
+ }
2773
+ function buildContendedEdgeRowAudit(tables3, graphId, cardinality, edgeKinds) {
2774
+ const { edges: edges3 } = tables3;
2775
+ const relation = getTableName(edges3);
2776
+ const spec = EDGE_CARDINALITY_SPECS[cardinality];
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();
2779
+ const peerToEndpoints = spec.keyShape === "fromAndTo" ? sql`
2780
+ AND ${qualified2(PEER, edges3.toKind)} = ${qualified2(relation, edges3.toKind)}
2781
+ AND ${qualified2(PEER, edges3.toId)} = ${qualified2(relation, edges3.toId)}
2782
+ ` : sql.empty();
2783
+ return sql`
2784
+ SELECT
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}
2795
+ AND EXISTS (
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)}
2803
+ )
2804
+ `;
2805
+ }
2806
+ function buildDisjointOverlapAudit(tables3, graphId, kinds) {
2807
+ const { nodes: nodes3 } = tables3;
2808
+ const relation = getTableName(nodes3);
2809
+ const liveIdsOfKind = (kind) => sql`
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
2815
+ `;
2816
+ return sql`${liveIdsOfKind(kinds[0])} INTERSECT ${liveIdsOfKind(kinds[1])}`;
2817
+ }
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;
1512
2889
  const propsJson = JSON.stringify(params.props);
1513
- const columns = edgeColumnList(edges);
2890
+ const columns = edgeColumnList(edges3);
1514
2891
  return sql`
1515
- INSERT INTO ${edges} (${columns})
2892
+ INSERT INTO ${edges3} (${columns})
1516
2893
  VALUES (
1517
2894
  ${params.graphId}, ${params.id}, ${params.kind},
1518
2895
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1519
- ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1520
- ${timestamp}, ${timestamp}
2896
+ ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
2897
+ ${timestamp2}, ${timestamp2}
1521
2898
  )
1522
2899
  RETURNING *
1523
2900
  `;
1524
2901
  }
1525
- function buildInsertEdgeNoReturn(tables, params, timestamp) {
1526
- const { edges } = tables;
2902
+ function buildInsertEdgeNoReturn(tables3, params, timestamp2) {
2903
+ const { edges: edges3 } = tables3;
1527
2904
  const propsJson = JSON.stringify(params.props);
1528
- const columns = edgeColumnList(edges);
2905
+ const columns = edgeColumnList(edges3);
1529
2906
  return sql`
1530
- INSERT INTO ${edges} (${columns})
2907
+ INSERT INTO ${edges3} (${columns})
1531
2908
  VALUES (
1532
2909
  ${params.graphId}, ${params.id}, ${params.kind},
1533
2910
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1534
- ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1535
- ${timestamp}, ${timestamp}
2911
+ ${propsJson}, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
2912
+ ${timestamp2}, ${timestamp2}
1536
2913
  )
1537
2914
  `;
1538
2915
  }
1539
- function buildInsertEdgesBatch(tables, params, timestamp) {
1540
- const { edges } = tables;
1541
- const columns = edgeColumnList(edges);
2916
+ function buildInsertEdgesBatch(tables3, params, timestamp2) {
2917
+ const { edges: edges3 } = tables3;
2918
+ const columns = edgeColumnList(edges3);
1542
2919
  const values = params.map((edgeParams) => {
1543
2920
  const propsJson = JSON.stringify(edgeParams.props);
1544
- 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})`;
1545
2922
  });
1546
2923
  return sql`
1547
- INSERT INTO ${edges} (${columns})
2924
+ INSERT INTO ${edges3} (${columns})
1548
2925
  VALUES ${sql.join(values, sql`, `)}
1549
2926
  `;
1550
2927
  }
1551
- function buildInsertEdgesBatchReturning(tables, params, timestamp) {
1552
- const { edges } = tables;
1553
- const columns = edgeColumnList(edges);
2928
+ function buildInsertEdgesBatchReturning(tables3, params, timestamp2) {
2929
+ const { edges: edges3 } = tables3;
2930
+ const columns = edgeColumnList(edges3);
1554
2931
  const values = params.map((edgeParams) => {
1555
2932
  const propsJson = JSON.stringify(edgeParams.props);
1556
- 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})`;
1557
2934
  });
1558
2935
  return sql`
1559
- INSERT INTO ${edges} (${columns})
2936
+ INSERT INTO ${edges3} (${columns})
1560
2937
  VALUES ${sql.join(values, sql`, `)}
1561
2938
  RETURNING *
1562
2939
  `;
1563
2940
  }
1564
- function buildGetEdge(tables, graphId, id) {
1565
- const { edges } = tables;
2941
+ function buildGetEdge(tables3, graphId, id) {
2942
+ const { edges: edges3 } = tables3;
1566
2943
  return sql`
1567
- SELECT * FROM ${edges}
1568
- WHERE ${edges.graphId} = ${graphId}
1569
- AND ${edges.id} = ${id}
2944
+ SELECT * FROM ${edges3}
2945
+ WHERE ${edges3.graphId} = ${graphId}
2946
+ AND ${edges3.id} = ${id}
1570
2947
  `;
1571
2948
  }
1572
- function buildGetEdges(tables, graphId, ids) {
1573
- const { edges } = tables;
2949
+ function buildGetEdges(tables3, graphId, ids) {
2950
+ const { edges: edges3 } = tables3;
1574
2951
  return sql`
1575
- SELECT * FROM ${edges}
1576
- WHERE ${edges.graphId} = ${graphId}
1577
- AND ${edges.id} IN (${sql.join(
2952
+ SELECT * FROM ${edges3}
2953
+ WHERE ${edges3.graphId} = ${graphId}
2954
+ AND ${edges3.id} IN (${sql.join(
1578
2955
  ids.map((id) => sql`${id}`),
1579
2956
  sql`, `
1580
2957
  )})
1581
2958
  `;
1582
2959
  }
1583
- function expectedIdentityPredicate(tables, expected) {
1584
- const { edges } = tables;
2960
+ function expectedIdentityPredicate(tables3, expected) {
2961
+ const { edges: edges3 } = tables3;
1585
2962
  const parts = [
1586
- expected.kind === void 0 ? void 0 : sql` AND ${edges.kind} = ${expected.kind}`,
1587
- expected.fromKind === void 0 ? void 0 : sql` AND ${edges.fromKind} = ${expected.fromKind}`,
1588
- expected.fromId === void 0 ? void 0 : sql` AND ${edges.fromId} = ${expected.fromId}`,
1589
- expected.toKind === void 0 ? void 0 : sql` AND ${edges.toKind} = ${expected.toKind}`,
1590
- 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}`
1591
2968
  ].filter((part) => part !== void 0);
1592
2969
  return parts.length === 0 ? sql.empty() : sql.join(parts, sql``);
1593
2970
  }
1594
- function buildUpdateEdge(tables, params, timestamp) {
1595
- const { edges } = tables;
2971
+ function buildUpdateEdge(tables3, params, timestamp2) {
2972
+ const { edges: edges3 } = tables3;
1596
2973
  const propsJson = JSON.stringify(params.props);
1597
2974
  const setParts = [
1598
- sql`${quotedColumn(edges.props)} = ${propsJson}`,
1599
- sql`${quotedColumn(edges.updatedAt)} = ${timestamp}`
2975
+ sql`${quotedColumn(edges3.props)} = ${propsJson}`,
2976
+ sql`${quotedColumn(edges3.updatedAt)} = ${timestamp2}`
1600
2977
  ];
1601
2978
  if (params.clearDeleted && params.validFrom !== void 0) {
1602
2979
  setParts.push(
1603
- sql`${quotedColumn(edges.validFrom)} = ${sqlNull(resolveStatedValidityLowerBound(params.validFrom))}`,
1604
- sql`${quotedColumn(edges.validTo)} = ${sqlNull(params.validTo)}`
2980
+ sql`${quotedColumn(edges3.validFrom)} = ${sqlNull(resolveStatedValidityLowerBound(params.validFrom))}`,
2981
+ sql`${quotedColumn(edges3.validTo)} = ${sqlNull(params.validTo)}`
1605
2982
  );
1606
2983
  } else if (params.clearValidTo === true) {
1607
- setParts.push(sql`${quotedColumn(edges.validTo)} = NULL`);
2984
+ setParts.push(sql`${quotedColumn(edges3.validTo)} = NULL`);
1608
2985
  } else if (params.validTo !== void 0) {
1609
- setParts.push(sql`${quotedColumn(edges.validTo)} = ${params.validTo}`);
2986
+ setParts.push(sql`${quotedColumn(edges3.validTo)} = ${params.validTo}`);
1610
2987
  }
1611
2988
  if (params.clearDeleted) {
1612
- setParts.push(sql`${quotedColumn(edges.deletedAt)} = NULL`);
2989
+ setParts.push(sql`${quotedColumn(edges3.deletedAt)} = NULL`);
1613
2990
  }
1614
2991
  const setClause = sql.join(setParts, sql`, `);
1615
- const expectedIdentity = expectedIdentityPredicate(tables, params);
2992
+ const expectedIdentity = expectedIdentityPredicate(tables3, params);
1616
2993
  const expectedValidFrom = expectedValidFromPredicate(
1617
- edges.validFrom,
2994
+ edges3.validFrom,
1618
2995
  params.expectedValidFrom
1619
2996
  );
1620
2997
  const expectedValidTo = expectedValidFromPredicate(
1621
- edges.validTo,
2998
+ edges3.validTo,
1622
2999
  params.expectedValidTo
1623
3000
  );
1624
3001
  if (params.clearDeleted) {
1625
3002
  return sql`
1626
- UPDATE ${edges}
3003
+ UPDATE ${edges3}
1627
3004
  SET ${setClause}
1628
- WHERE ${edges.graphId} = ${params.graphId}
1629
- AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
3005
+ WHERE ${edges3.graphId} = ${params.graphId}
3006
+ AND ${edges3.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
1630
3007
  RETURNING *
1631
3008
  `;
1632
3009
  }
1633
3010
  return sql`
1634
- UPDATE ${edges}
3011
+ UPDATE ${edges3}
1635
3012
  SET ${setClause}
1636
- WHERE ${edges.graphId} = ${params.graphId}
1637
- AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
1638
- 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
1639
3016
  RETURNING *
1640
3017
  `;
1641
3018
  }
1642
- function buildDeleteEdge(tables, params, timestamp) {
1643
- const { edges } = tables;
3019
+ function buildDeleteEdge(tables3, params, timestamp2) {
3020
+ const { edges: edges3 } = tables3;
1644
3021
  return sql`
1645
- UPDATE ${edges}
1646
- SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
1647
- WHERE ${edges.graphId} = ${params.graphId}
1648
- AND ${edges.id} = ${params.id}${expectedIdentityPredicate(tables, params.kind === void 0 ? {} : { kind: params.kind })}
1649
- 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
1650
3027
  `;
1651
3028
  }
1652
- function buildDeleteEdgesBatch(tables, params, timestamp) {
1653
- const { edges } = tables;
3029
+ function buildDeleteEdgesBatch(tables3, params, timestamp2) {
3030
+ const { edges: edges3 } = tables3;
1654
3031
  return sql`
1655
- UPDATE ${edges}
1656
- SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
1657
- WHERE ${edges.graphId} = ${params.graphId}
1658
- 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(
1659
3036
  params.ids.map((id) => sql`${id}`),
1660
3037
  sql`, `
1661
3038
  )})
1662
- AND ${edges.deletedAt} IS NULL
3039
+ AND ${edges3.deletedAt} IS NULL
1663
3040
  `;
1664
3041
  }
1665
- function buildHardDeleteEdgesBatch(tables, params) {
1666
- const { edges } = tables;
3042
+ function buildHardDeleteEdgesBatch(tables3, params) {
3043
+ const { edges: edges3 } = tables3;
1667
3044
  return sql`
1668
- DELETE FROM ${edges}
1669
- WHERE ${edges.graphId} = ${params.graphId}
1670
- AND ${edges.id} IN (${sql.join(
3045
+ DELETE FROM ${edges3}
3046
+ WHERE ${edges3.graphId} = ${params.graphId}
3047
+ AND ${edges3.id} IN (${sql.join(
1671
3048
  params.ids.map((id) => sql`${id}`),
1672
3049
  sql`, `
1673
3050
  )})
1674
3051
  `;
1675
3052
  }
1676
- function buildHardDeleteEdge(tables, params) {
1677
- const { edges } = tables;
3053
+ function buildHardDeleteEdge(tables3, params) {
3054
+ const { edges: edges3 } = tables3;
1678
3055
  return sql`
1679
- DELETE FROM ${edges}
1680
- WHERE ${edges.graphId} = ${params.graphId}
1681
- 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 })}
1682
3059
  `;
1683
3060
  }
1684
- function buildHardDeleteEdgesByNode(tables, graphId, nodeKind, nodeId) {
1685
- const { edges } = tables;
3061
+ function buildHardDeleteEdgesByNode(tables3, graphId, nodeKind, nodeId) {
3062
+ const { edges: edges3 } = tables3;
1686
3063
  return sql`
1687
- DELETE FROM ${edges}
1688
- WHERE ${edges.graphId} = ${graphId}
3064
+ DELETE FROM ${edges3}
3065
+ WHERE ${edges3.graphId} = ${graphId}
1689
3066
  AND (
1690
- (${edges.fromKind} = ${nodeKind} AND ${edges.fromId} = ${nodeId})
1691
- 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})
1692
3069
  )
1693
3070
  `;
1694
3071
  }
1695
- function buildCountEdgesFrom(tables, params) {
1696
- const { edges } = tables;
3072
+ function buildCountEdgesFrom(tables3, params) {
3073
+ const { edges: edges3 } = tables3;
1697
3074
  if (params.activeOnly) {
1698
3075
  return sql`
1699
- SELECT COUNT(*) as count FROM ${edges}
1700
- WHERE ${edges.graphId} = ${params.graphId}
1701
- AND ${edges.kind} = ${params.edgeKind}
1702
- AND ${edges.fromKind} = ${params.fromKind}
1703
- AND ${edges.fromId} = ${params.fromId}
1704
- AND ${edges.deletedAt} IS NULL
1705
- 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
1706
3083
  `;
1707
3084
  }
1708
3085
  return sql`
1709
- SELECT COUNT(*) as count FROM ${edges}
1710
- WHERE ${edges.graphId} = ${params.graphId}
1711
- AND ${edges.kind} = ${params.edgeKind}
1712
- AND ${edges.fromKind} = ${params.fromKind}
1713
- AND ${edges.fromId} = ${params.fromId}
1714
- 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
1715
3092
  `;
1716
3093
  }
1717
- function buildEdgeExistsBetween(tables, params) {
1718
- const { edges } = tables;
3094
+ function buildEdgeExistsBetween(tables3, params) {
3095
+ const { edges: edges3 } = tables3;
1719
3096
  return sql`
1720
- SELECT 1 FROM ${edges}
1721
- WHERE ${edges.graphId} = ${params.graphId}
1722
- AND ${edges.kind} = ${params.edgeKind}
1723
- AND ${edges.fromKind} = ${params.fromKind}
1724
- AND ${edges.fromId} = ${params.fromId}
1725
- AND ${edges.toKind} = ${params.toKind}
1726
- AND ${edges.toId} = ${params.toId}
1727
- 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
1728
3105
  LIMIT 1
1729
3106
  `;
1730
3107
  }
1731
- function buildFindEdgesConnectedTo(tables, params) {
1732
- const { edges } = tables;
3108
+ function buildFindEdgesConnectedTo(tables3, params) {
3109
+ const { edges: edges3 } = tables3;
1733
3110
  return sql`
1734
- SELECT * FROM ${edges}
1735
- WHERE ${edges.graphId} = ${params.graphId}
1736
- AND ${edges.deletedAt} IS NULL
1737
- AND ${edges.fromKind} = ${params.nodeKind}
1738
- 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}
1739
3116
  UNION ALL
1740
- SELECT * FROM ${edges}
1741
- WHERE ${edges.graphId} = ${params.graphId}
1742
- AND ${edges.deletedAt} IS NULL
1743
- AND ${edges.toKind} = ${params.nodeKind}
1744
- 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}
1745
3122
  AND NOT (
1746
- ${edges.fromKind} = ${params.nodeKind}
1747
- AND ${edges.fromId} = ${params.nodeId}
3123
+ ${edges3.fromKind} = ${params.nodeKind}
3124
+ AND ${edges3.fromId} = ${params.nodeId}
1748
3125
  )
1749
3126
  `;
1750
3127
  }
@@ -1806,136 +3183,136 @@ function assertValidSearchParams(params) {
1806
3183
  );
1807
3184
  }
1808
3185
  }
1809
- function buildInsertNode(tables, params, timestamp) {
1810
- const { nodes } = tables;
3186
+ function buildInsertNode(tables3, params, timestamp2) {
3187
+ const { nodes: nodes3 } = tables3;
1811
3188
  const propsJson = JSON.stringify(params.props);
1812
- const columns = nodeColumnList(nodes);
3189
+ const columns = nodeColumnList(nodes3);
1813
3190
  return sql`
1814
- INSERT INTO ${nodes} (${columns})
3191
+ INSERT INTO ${nodes3} (${columns})
1815
3192
  VALUES (
1816
3193
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1817
- 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1818
- ${timestamp}, ${timestamp}
3194
+ 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
3195
+ ${timestamp2}, ${timestamp2}
1819
3196
  )
1820
3197
  RETURNING *
1821
3198
  `;
1822
3199
  }
1823
- function buildInsertNodeNoReturn(tables, params, timestamp) {
1824
- const { nodes } = tables;
3200
+ function buildInsertNodeNoReturn(tables3, params, timestamp2) {
3201
+ const { nodes: nodes3 } = tables3;
1825
3202
  const propsJson = JSON.stringify(params.props);
1826
- const columns = nodeColumnList(nodes);
3203
+ const columns = nodeColumnList(nodes3);
1827
3204
  return sql`
1828
- INSERT INTO ${nodes} (${columns})
3205
+ INSERT INTO ${nodes3} (${columns})
1829
3206
  VALUES (
1830
3207
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1831
- 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
1832
- ${timestamp}, ${timestamp}
3208
+ 1, ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp2))}, ${sqlNull(params.validTo)},
3209
+ ${timestamp2}, ${timestamp2}
1833
3210
  )
1834
3211
  `;
1835
3212
  }
1836
- function buildInsertNodesBatch(tables, params, timestamp) {
1837
- const { nodes } = tables;
1838
- const columns = nodeColumnList(nodes);
3213
+ function buildInsertNodesBatch(tables3, params, timestamp2) {
3214
+ const { nodes: nodes3 } = tables3;
3215
+ const columns = nodeColumnList(nodes3);
1839
3216
  const values = params.map((nodeParams) => {
1840
3217
  const propsJson = JSON.stringify(nodeParams.props);
1841
- 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})`;
1842
3219
  });
1843
3220
  return sql`
1844
- INSERT INTO ${nodes} (${columns})
3221
+ INSERT INTO ${nodes3} (${columns})
1845
3222
  VALUES ${sql.join(values, sql`, `)}
1846
3223
  `;
1847
3224
  }
1848
- function buildInsertNodesBatchReturning(tables, params, timestamp) {
1849
- const { nodes } = tables;
1850
- const columns = nodeColumnList(nodes);
3225
+ function buildInsertNodesBatchReturning(tables3, params, timestamp2) {
3226
+ const { nodes: nodes3 } = tables3;
3227
+ const columns = nodeColumnList(nodes3);
1851
3228
  const values = params.map((nodeParams) => {
1852
3229
  const propsJson = JSON.stringify(nodeParams.props);
1853
- 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})`;
1854
3231
  });
1855
3232
  return sql`
1856
- INSERT INTO ${nodes} (${columns})
3233
+ INSERT INTO ${nodes3} (${columns})
1857
3234
  VALUES ${sql.join(values, sql`, `)}
1858
3235
  RETURNING *
1859
3236
  `;
1860
3237
  }
1861
- function buildGetNode(tables, graphId, kind, id) {
1862
- const { nodes } = tables;
3238
+ function buildGetNode(tables3, graphId, kind, id) {
3239
+ const { nodes: nodes3 } = tables3;
1863
3240
  return sql`
1864
- SELECT * FROM ${nodes}
1865
- WHERE ${nodes.graphId} = ${graphId}
1866
- AND ${nodes.kind} = ${kind}
1867
- AND ${nodes.id} = ${id}
3241
+ SELECT * FROM ${nodes3}
3242
+ WHERE ${nodes3.graphId} = ${graphId}
3243
+ AND ${nodes3.kind} = ${kind}
3244
+ AND ${nodes3.id} = ${id}
1868
3245
  `;
1869
3246
  }
1870
- function buildGetNodes(tables, graphId, kind, ids) {
1871
- const { nodes } = tables;
3247
+ function buildGetNodes(tables3, graphId, kind, ids) {
3248
+ const { nodes: nodes3 } = tables3;
1872
3249
  return sql`
1873
- SELECT * FROM ${nodes}
1874
- WHERE ${nodes.graphId} = ${graphId}
1875
- AND ${nodes.kind} = ${kind}
1876
- 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(
1877
3254
  ids.map((id) => sql`${id}`),
1878
3255
  sql`, `
1879
3256
  )})
1880
3257
  `;
1881
3258
  }
1882
- function buildUpdateNode(tables, params, timestamp) {
1883
- const { nodes } = tables;
3259
+ function buildUpdateNode(tables3, params, timestamp2) {
3260
+ const { nodes: nodes3 } = tables3;
1884
3261
  const propsJson = JSON.stringify(params.props);
1885
3262
  const setParts = [
1886
- sql`${quotedColumn(nodes.props)} = ${propsJson}`,
1887
- sql`${quotedColumn(nodes.updatedAt)} = ${timestamp}`
3263
+ sql`${quotedColumn(nodes3.props)} = ${propsJson}`,
3264
+ sql`${quotedColumn(nodes3.updatedAt)} = ${timestamp2}`
1888
3265
  ];
1889
3266
  if (params.incrementVersion) {
1890
3267
  setParts.push(
1891
- sql`${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1`
3268
+ sql`${quotedColumn(nodes3.version)} = ${quotedColumn(nodes3.version)} + 1`
1892
3269
  );
1893
3270
  }
1894
3271
  if (params.clearDeleted) {
1895
3272
  setParts.push(
1896
- sql`${quotedColumn(nodes.validFrom)} = ${sqlNull(resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}`,
1897
- 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)}`
1898
3275
  );
1899
3276
  } else if (params.clearValidTo === true) {
1900
- setParts.push(sql`${quotedColumn(nodes.validTo)} = NULL`);
3277
+ setParts.push(sql`${quotedColumn(nodes3.validTo)} = NULL`);
1901
3278
  } else if (params.validTo !== void 0) {
1902
- setParts.push(sql`${quotedColumn(nodes.validTo)} = ${params.validTo}`);
3279
+ setParts.push(sql`${quotedColumn(nodes3.validTo)} = ${params.validTo}`);
1903
3280
  }
1904
3281
  if (params.clearDeleted) {
1905
- setParts.push(sql`${quotedColumn(nodes.deletedAt)} = NULL`);
3282
+ setParts.push(sql`${quotedColumn(nodes3.deletedAt)} = NULL`);
1906
3283
  }
1907
3284
  const setClause = sql.join(setParts, sql`, `);
1908
3285
  const expectedValidFrom = expectedValidFromPredicate(
1909
- nodes.validFrom,
3286
+ nodes3.validFrom,
1910
3287
  params.expectedValidFrom
1911
3288
  );
1912
3289
  if (params.clearDeleted) {
1913
3290
  return sql`
1914
- UPDATE ${nodes}
3291
+ UPDATE ${nodes3}
1915
3292
  SET ${setClause}
1916
- WHERE ${nodes.graphId} = ${params.graphId}
1917
- AND ${nodes.kind} = ${params.kind}
1918
- AND ${nodes.id} = ${params.id}${expectedValidFrom}
1919
- 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
1920
3297
  RETURNING *
1921
3298
  `;
1922
3299
  }
1923
3300
  return sql`
1924
- UPDATE ${nodes}
3301
+ UPDATE ${nodes3}
1925
3302
  SET ${setClause}
1926
- WHERE ${nodes.graphId} = ${params.graphId}
1927
- AND ${nodes.kind} = ${params.kind}
1928
- AND ${nodes.id} = ${params.id}${expectedValidFrom}
1929
- 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
1930
3307
  RETURNING *
1931
3308
  `;
1932
3309
  }
1933
- function buildUpdateNodeSet(tables, dialect, params, timestamp) {
1934
- const { nodes } = tables;
3310
+ function buildUpdateNodeSet(tables3, dialect, params, timestamp2) {
3311
+ const { nodes: nodes3 } = tables3;
1935
3312
  const adapter = getDialect(dialect);
1936
3313
  const patchedProps = toDrizzleSql(
1937
3314
  adapter.jsonSetProperties(
1938
- sql$1.identifier(nodes.props.name),
3315
+ sql$1.identifier(nodes3.props.name),
1939
3316
  params.patch,
1940
3317
  params.unsetProperties ?? []
1941
3318
  ),
@@ -1947,38 +3324,38 @@ function buildUpdateNodeSet(tables, dialect, params, timestamp) {
1947
3324
  dialect
1948
3325
  );
1949
3326
  return sql`
1950
- UPDATE ${nodes}
1951
- SET ${quotedColumn(nodes.props)} = ${patchedProps},
1952
- ${quotedColumn(nodes.updatedAt)} = ${timestamp},
1953
- ${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1
1954
- WHERE ${nodes.graphId} = ${params.graphId}
1955
- AND ${nodes.kind} = ${params.kind}
1956
- AND ${nodes.deletedAt} IS NULL
1957
- 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 (
1958
3335
  SELECT ${candidateIdColumn}
1959
3336
  FROM (${candidateIds}) AS tg_set_candidates
1960
3337
  )
1961
3338
  RETURNING *
1962
3339
  `;
1963
3340
  }
1964
- function buildDeleteNode(tables, params, timestamp) {
1965
- const { nodes } = tables;
3341
+ function buildDeleteNode(tables3, params, timestamp2) {
3342
+ const { nodes: nodes3 } = tables3;
1966
3343
  return sql`
1967
- UPDATE ${nodes}
1968
- SET ${quotedColumn(nodes.deletedAt)} = ${timestamp}
1969
- WHERE ${nodes.graphId} = ${params.graphId}
1970
- AND ${nodes.kind} = ${params.kind}
1971
- AND ${nodes.id} = ${params.id}
1972
- 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
1973
3350
  `;
1974
3351
  }
1975
- function buildHardDeleteNode(tables, params) {
1976
- const { nodes } = tables;
3352
+ function buildHardDeleteNode(tables3, params) {
3353
+ const { nodes: nodes3 } = tables3;
1977
3354
  return sql`
1978
- DELETE FROM ${nodes}
1979
- WHERE ${nodes.graphId} = ${params.graphId}
1980
- AND ${nodes.kind} = ${params.kind}
1981
- 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}
1982
3359
  `;
1983
3360
  }
1984
3361
  function createSchemaDialectStrategy(dialect) {
@@ -1999,158 +3376,199 @@ var SCHEMA_DIALECT_STRATEGIES = {
1999
3376
  postgres: createSchemaDialectStrategy("postgres"),
2000
3377
  sqlite: createSchemaDialectStrategy("sqlite")
2001
3378
  };
2002
- function buildInsertSchema(tables, params, timestamp, dialect = "sqlite") {
2003
- const { schemaVersions } = tables;
3379
+ function buildInsertSchema(tables3, params, timestamp2, dialect = "sqlite") {
3380
+ const { schemaVersions: schemaVersions3 } = tables3;
2004
3381
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2005
3382
  const schemaDocumentJson = JSON.stringify(params.schemaDoc);
2006
3383
  const isActiveValue = strategy.booleanLiteral(params.isActive);
2007
3384
  const columns = sql.raw(
2008
- `"${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}"`
2009
3386
  );
2010
3387
  return sql`
2011
- INSERT INTO ${schemaVersions} (${columns})
3388
+ INSERT INTO ${schemaVersions3} (${columns})
2012
3389
  VALUES (
2013
3390
  ${params.graphId}, ${params.version},
2014
3391
  ${params.schemaHash}, ${schemaDocumentJson},
2015
- ${timestamp}, ${isActiveValue}
3392
+ ${timestamp2}, ${isActiveValue}
2016
3393
  )
2017
3394
  RETURNING *
2018
3395
  `;
2019
3396
  }
2020
- function buildGetActiveSchema(tables, graphId, dialect = "sqlite") {
2021
- const { schemaVersions } = tables;
3397
+ function buildGetActiveSchema(tables3, graphId, dialect = "sqlite") {
3398
+ const { schemaVersions: schemaVersions3 } = tables3;
2022
3399
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2023
3400
  return sql`
2024
- SELECT * FROM ${schemaVersions}
2025
- WHERE ${schemaVersions.graphId} = ${graphId}
2026
- AND ${schemaVersions.isActive} = ${strategy.booleanLiteral(true)}
3401
+ SELECT * FROM ${schemaVersions3}
3402
+ WHERE ${schemaVersions3.graphId} = ${graphId}
3403
+ AND ${schemaVersions3.isActive} = ${strategy.booleanLiteral(true)}
2027
3404
  `;
2028
3405
  }
2029
- function buildGetSchemaVersion(tables, graphId, version) {
2030
- const { schemaVersions } = tables;
3406
+ function buildGetSchemaVersion(tables3, graphId, version) {
3407
+ const { schemaVersions: schemaVersions3 } = tables3;
2031
3408
  return sql`
2032
- SELECT * FROM ${schemaVersions}
2033
- WHERE ${schemaVersions.graphId} = ${graphId}
2034
- AND ${schemaVersions.version} = ${version}
3409
+ SELECT * FROM ${schemaVersions3}
3410
+ WHERE ${schemaVersions3.graphId} = ${graphId}
3411
+ AND ${schemaVersions3.version} = ${version}
2035
3412
  `;
2036
3413
  }
2037
- function buildSetActiveSchema(tables, graphId, version, dialect = "sqlite") {
2038
- const { schemaVersions } = tables;
3414
+ function buildSetActiveSchema(tables3, graphId, version, dialect = "sqlite") {
3415
+ const { schemaVersions: schemaVersions3 } = tables3;
2039
3416
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2040
3417
  const deactivateAll = sql`
2041
- UPDATE ${schemaVersions}
2042
- SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(false)}
2043
- WHERE ${schemaVersions.graphId} = ${graphId}
3418
+ UPDATE ${schemaVersions3}
3419
+ SET ${quotedColumn(schemaVersions3.isActive)} = ${strategy.booleanLiteral(false)}
3420
+ WHERE ${schemaVersions3.graphId} = ${graphId}
2044
3421
  `;
2045
3422
  const activateVersion = sql`
2046
- UPDATE ${schemaVersions}
2047
- SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(true)}
2048
- WHERE ${schemaVersions.graphId} = ${graphId}
2049
- 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}
2050
3427
  `;
2051
3428
  return { deactivateAll, activateVersion };
2052
3429
  }
2053
- function buildInsertUniqueSqlite(tables, params) {
2054
- const { uniques } = tables;
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;
2055
3450
  const columns = sql.raw(
2056
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
3451
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
2057
3452
  );
2058
3453
  const conflictColumns = sql.raw(
2059
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
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)
2060
3461
  );
2061
3462
  return sql`
2062
- INSERT INTO ${uniques} (${columns})
3463
+ INSERT INTO ${uniques3} (${columns})
2063
3464
  VALUES (
2064
3465
  ${params.graphId}, ${params.nodeKind}, ${params.constraintName},
2065
3466
  ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")}
2066
3467
  )
2067
3468
  ON CONFLICT (${conflictColumns})
2068
3469
  DO UPDATE SET
2069
- ${quotedColumn(uniques.nodeId)} = CASE
2070
- WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
2071
- WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.nodeId}
2072
- ELSE ${quotedColumn(uniques.nodeId)}
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)}
2073
3474
  END,
2074
- ${quotedColumn(uniques.concreteKind)} = CASE
2075
- WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
2076
- WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
2077
- ELSE ${quotedColumn(uniques.concreteKind)}
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)}
2078
3479
  END,
2079
- ${quotedColumn(uniques.deletedAt)} = CASE
2080
- WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN NULL
2081
- WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
2082
- ELSE ${quotedColumn(uniques.deletedAt)}
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)}
2083
3484
  END
2084
- RETURNING ${quotedColumn(uniques.nodeId)} as node_id
3485
+ RETURNING
3486
+ ${quotedColumn(uniques3.nodeId)} as node_id,
3487
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind
2085
3488
  `;
2086
3489
  }
2087
- function buildInsertUniquePostgres(tables, params) {
2088
- const { uniques } = tables;
3490
+ function buildInsertUniquePostgres(tables3, params) {
3491
+ const { uniques: uniques3 } = tables3;
2089
3492
  const columns = sql.raw(
2090
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
3493
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
2091
3494
  );
2092
3495
  const conflictColumns = sql.raw(
2093
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
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)
2094
3506
  );
2095
- const tableName = getTableName(uniques);
2096
- const existingColumn = (column) => sql.raw(`"${tableName}"."${column.name}"`);
2097
3507
  return sql`
2098
- INSERT INTO ${uniques} (${columns})
3508
+ INSERT INTO ${uniques3} (${columns})
2099
3509
  VALUES (
2100
3510
  ${params.graphId}, ${params.nodeKind}, ${params.constraintName},
2101
3511
  ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")}
2102
3512
  )
2103
3513
  ON CONFLICT (${conflictColumns})
2104
3514
  DO UPDATE SET
2105
- ${quotedColumn(uniques.nodeId)} = CASE
2106
- WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
2107
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.nodeId}
2108
- ELSE ${existingColumn(uniques.nodeId)}
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)}
2109
3519
  END,
2110
- ${quotedColumn(uniques.concreteKind)} = CASE
2111
- WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
2112
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
2113
- ELSE ${existingColumn(uniques.concreteKind)}
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)}
2114
3524
  END,
2115
- ${quotedColumn(uniques.deletedAt)} = CASE
2116
- WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN NULL
2117
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
2118
- ELSE ${existingColumn(uniques.deletedAt)}
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)}
2119
3529
  END
2120
- RETURNING ${quotedColumn(uniques.nodeId)} as node_id
3530
+ RETURNING
3531
+ ${quotedColumn(uniques3.nodeId)} as node_id,
3532
+ ${quotedColumn(uniques3.concreteKind)} as concrete_kind
2121
3533
  `;
2122
3534
  }
2123
3535
  var UNIQUE_INSERT_BUILDERS = {
2124
3536
  postgres: buildInsertUniquePostgres,
2125
3537
  sqlite: buildInsertUniqueSqlite
2126
3538
  };
2127
- function buildInsertUnique(tables, dialect, params) {
3539
+ function buildInsertUnique(tables3, dialect, params) {
2128
3540
  const builder = UNIQUE_INSERT_BUILDERS[dialect];
2129
- return builder(tables, params);
3541
+ return builder(tables3, params);
2130
3542
  }
2131
- function buildInsertUniqueBatch(tables, dialect, entries) {
2132
- const { uniques } = tables;
3543
+ function buildInsertUniqueBatch(tables3, dialect, entries) {
3544
+ const { uniques: uniques3 } = tables3;
2133
3545
  const columns = sql.raw(
2134
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
3546
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}", "${uniques3.nodeId.name}", "${uniques3.concreteKind.name}", "${uniques3.deletedAt.name}"`
2135
3547
  );
2136
3548
  const conflictColumns = sql.raw(
2137
- `"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
3549
+ `"${uniques3.graphId.name}", "${uniques3.nodeKind.name}", "${uniques3.constraintName.name}", "${uniques3.key.name}"`
2138
3550
  );
2139
- const tableName = getTableName(uniques);
2140
- const existingColumn = (column) => {
3551
+ const tableName = getTableName(uniques3);
3552
+ const existingColumnByName = (columnName) => {
2141
3553
  switch (dialect) {
2142
3554
  case "postgres": {
2143
- return sql.raw(`"${tableName}"."${column.name}"`);
3555
+ return sql`${quotedTableName(tableName)}.${quotedColumn({ name: columnName })}`;
2144
3556
  }
2145
3557
  case "sqlite": {
2146
- return sql.raw(`"${column.name}"`);
3558
+ return quotedColumn({ name: columnName });
2147
3559
  }
2148
3560
  default: {
2149
3561
  return dialect;
2150
3562
  }
2151
3563
  }
2152
3564
  };
2153
- const excludedColumn = (column) => sql.raw(`excluded."${column.name}"`);
3565
+ const existingColumn = (column) => existingColumnByName(column.name);
3566
+ const ownerMatches = claimOwnerMatchesSql(
3567
+ drizzleSqlTag,
3568
+ (columnName) => existingColumnByName(columnName),
3569
+ excludedColumnByName,
3570
+ ownerColumnNames(uniques3)
3571
+ );
2154
3572
  const valueRows = sql.join(
2155
3573
  entries.map(
2156
3574
  (params) => sql`(${params.graphId}, ${params.nodeKind}, ${params.constraintName}, ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${sql.raw("NULL")})`
@@ -2158,105 +3576,108 @@ function buildInsertUniqueBatch(tables, dialect, entries) {
2158
3576
  sql`, `
2159
3577
  );
2160
3578
  return sql`
2161
- INSERT INTO ${uniques} (${columns})
3579
+ INSERT INTO ${uniques3} (${columns})
2162
3580
  VALUES ${valueRows}
2163
3581
  ON CONFLICT (${conflictColumns})
2164
3582
  DO UPDATE SET
2165
- ${quotedColumn(uniques.nodeId)} = CASE
2166
- WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN ${excludedColumn(uniques.nodeId)}
2167
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques.nodeId)}
2168
- ELSE ${existingColumn(uniques.nodeId)}
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)}
2169
3587
  END,
2170
- ${quotedColumn(uniques.concreteKind)} = CASE
2171
- WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN ${excludedColumn(uniques.concreteKind)}
2172
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques.concreteKind)}
2173
- ELSE ${existingColumn(uniques.concreteKind)}
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)}
2174
3592
  END,
2175
- ${quotedColumn(uniques.deletedAt)} = CASE
2176
- WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN NULL
2177
- WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
2178
- ELSE ${existingColumn(uniques.deletedAt)}
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)}
2179
3597
  END
2180
3598
  RETURNING
2181
- ${quotedColumn(uniques.nodeKind)} as node_kind,
2182
- ${quotedColumn(uniques.constraintName)} as constraint_name,
2183
- ${quotedColumn(uniques.key)} as key,
2184
- ${quotedColumn(uniques.nodeId)} as node_id
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
2185
3604
  `;
2186
3605
  }
2187
- function buildDeleteUnique(tables, params, timestamp) {
2188
- const { uniques } = tables;
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}`;
2189
3609
  return sql`
2190
- UPDATE ${uniques}
2191
- SET ${quotedColumn(uniques.deletedAt)} = ${timestamp}
2192
- WHERE ${uniques.graphId} = ${params.graphId}
2193
- AND ${uniques.nodeKind} = ${params.nodeKind}
2194
- AND ${uniques.constraintName} = ${params.constraintName}
2195
- AND ${uniques.key} = ${params.key}
2196
- AND ${uniques.deletedAt} IS NULL
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
2197
3618
  `;
2198
3619
  }
2199
- function buildHardDeleteUniquesByNode(tables, graphId, concreteKind, nodeId) {
2200
- return buildHardDeleteUniquesByNodeIds(tables, {
3620
+ function buildHardDeleteUniquesByNode(tables3, graphId, concreteKind, nodeId) {
3621
+ return buildHardDeleteUniquesByNodeIds(tables3, {
2201
3622
  graphId,
2202
3623
  concreteKind,
2203
3624
  nodeIds: [nodeId]
2204
3625
  });
2205
3626
  }
2206
- function buildHardDeleteUniquesByNodeIds(tables, params) {
2207
- const { uniques } = tables;
3627
+ function buildHardDeleteUniquesByNodeIds(tables3, params) {
3628
+ const { uniques: uniques3 } = tables3;
2208
3629
  return sql`
2209
- DELETE FROM ${uniques}
2210
- WHERE ${uniques.graphId} = ${params.graphId}
2211
- AND ${uniques.concreteKind} = ${params.concreteKind}
2212
- AND ${uniques.nodeId} IN (${sql.join(
3630
+ DELETE FROM ${uniques3}
3631
+ WHERE ${uniques3.graphId} = ${params.graphId}
3632
+ AND ${uniques3.concreteKind} = ${params.concreteKind}
3633
+ AND ${uniques3.nodeId} IN (${sql.join(
2213
3634
  params.nodeIds.map((nodeId) => sql`${nodeId}`),
2214
3635
  sql`, `
2215
3636
  )})
2216
3637
  `;
2217
3638
  }
2218
- function buildCheckUnique(tables, params) {
2219
- const { uniques } = tables;
3639
+ function buildCheckUnique(tables3, params) {
3640
+ const { uniques: uniques3 } = tables3;
2220
3641
  if (params.includeDeleted) {
2221
3642
  return sql`
2222
- SELECT * FROM ${uniques}
2223
- WHERE ${uniques.graphId} = ${params.graphId}
2224
- AND ${uniques.nodeKind} = ${params.nodeKind}
2225
- AND ${uniques.constraintName} = ${params.constraintName}
2226
- AND ${uniques.key} = ${params.key}
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}
2227
3648
  `;
2228
3649
  }
2229
3650
  return sql`
2230
- SELECT * FROM ${uniques}
2231
- WHERE ${uniques.graphId} = ${params.graphId}
2232
- AND ${uniques.nodeKind} = ${params.nodeKind}
2233
- AND ${uniques.constraintName} = ${params.constraintName}
2234
- AND ${uniques.key} = ${params.key}
2235
- AND ${uniques.deletedAt} IS NULL
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
2236
3657
  `;
2237
3658
  }
2238
- function buildCheckUniqueBatch(tables, params) {
2239
- const { uniques } = tables;
3659
+ function buildCheckUniqueBatch(tables3, params) {
3660
+ const { uniques: uniques3 } = tables3;
2240
3661
  const keyPlaceholders = sql.join(
2241
3662
  params.keys.map((key) => sql`${key}`),
2242
3663
  sql`, `
2243
3664
  );
2244
3665
  if (params.includeDeleted) {
2245
3666
  return sql`
2246
- SELECT * FROM ${uniques}
2247
- WHERE ${uniques.graphId} = ${params.graphId}
2248
- AND ${uniques.nodeKind} = ${params.nodeKind}
2249
- AND ${uniques.constraintName} = ${params.constraintName}
2250
- AND ${uniques.key} IN (${keyPlaceholders})
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})
2251
3672
  `;
2252
3673
  }
2253
3674
  return sql`
2254
- SELECT * FROM ${uniques}
2255
- WHERE ${uniques.graphId} = ${params.graphId}
2256
- AND ${uniques.nodeKind} = ${params.nodeKind}
2257
- AND ${uniques.constraintName} = ${params.constraintName}
2258
- AND ${uniques.key} IN (${keyPlaceholders})
2259
- AND ${uniques.deletedAt} IS NULL
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
2260
3681
  `;
2261
3682
  }
2262
3683
 
@@ -2264,10 +3685,10 @@ function buildCheckUniqueBatch(tables, params) {
2264
3685
  function nullableText(value) {
2265
3686
  return value === void 0 ? sql`NULL` : sql`${value}`;
2266
3687
  }
2267
- function bindTableOperationBuilders(tables, builders) {
3688
+ function bindTableOperationBuilders(tables3, builders) {
2268
3689
  const boundEntries = Object.entries(builders).map(([name, builder]) => {
2269
3690
  function boundBuilder(...args) {
2270
- return builder(tables, ...args);
3691
+ return builder(tables3, ...args);
2271
3692
  }
2272
3693
  return [name, boundBuilder];
2273
3694
  });
@@ -2313,22 +3734,22 @@ var COMMON_TABLE_OPERATION_BUILDERS = {
2313
3734
  buildCheckUniqueBatch,
2314
3735
  buildGetSchemaVersion
2315
3736
  };
2316
- function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
3737
+ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
2317
3738
  const tableOperations = bindTableOperationBuilders(
2318
- tables,
3739
+ tables3,
2319
3740
  COMMON_TABLE_OPERATION_BUILDERS
2320
3741
  );
2321
- const fulltextTable = tables.fulltextTableName;
2322
- const contributionMaterializations = tables.contributionMaterializations;
3742
+ const fulltextTable = tables3.fulltextTableName;
3743
+ const contributionMaterializations = tables3.contributionMaterializations;
2323
3744
  const fulltextBuilders = {
2324
- 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)),
2325
3746
  buildDeleteFulltext: (params) => fulltextStrategy.buildDelete(fulltextTable, params).map((statement) => toDrizzleSql(statement, dialect)),
2326
3747
  buildDeleteFulltextByNode: (graphId, nodeKind, nodeId) => fulltextStrategy.buildDelete(fulltextTable, {
2327
3748
  graphId,
2328
3749
  nodeKind,
2329
3750
  nodeId
2330
3751
  }).map((statement) => toDrizzleSql(statement, dialect)),
2331
- 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)),
2332
3753
  buildDeleteFulltextBatch: (params) => fulltextStrategy.buildBatchDelete(fulltextTable, params).map((statement) => toDrizzleSql(statement, dialect)),
2333
3754
  buildFulltextSearch: (params) => buildFulltextSearch(
2334
3755
  fulltextTable,
@@ -2338,7 +3759,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2338
3759
  // Store-compiled candidates (predicates + subclass + currency)
2339
3760
  // take precedence; the live-node default covers direct backend use.
2340
3761
  params.candidates ?? liveNodeIdsSubquery(
2341
- tables.nodes,
3762
+ tables3.nodes,
2342
3763
  params.graphId,
2343
3764
  params.nodeKind,
2344
3765
  nowIso()
@@ -2346,7 +3767,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2346
3767
  ),
2347
3768
  buildHybridSearch: (params, vectorSql, vectorScoreDescending) => {
2348
3769
  const candidates = params.candidates ?? liveNodeIdsSubquery(
2349
- tables.nodes,
3770
+ tables3.nodes,
2350
3771
  params.graphId,
2351
3772
  params.nodeKind,
2352
3773
  nowIso()
@@ -2374,7 +3795,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2374
3795
  vectorSql,
2375
3796
  vectorScoreDescending,
2376
3797
  fulltextSql,
2377
- nodes: tables.nodes,
3798
+ nodes: tables3.nodes,
2378
3799
  dialect,
2379
3800
  graphId: params.graphId,
2380
3801
  nodeKind: params.nodeKind,
@@ -2417,28 +3838,57 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2417
3838
  ...tableOperations,
2418
3839
  ...fulltextBuilders,
2419
3840
  primaryKeyConstraints: {
2420
- nodes: nodePrimaryKeyConstraint(tables.nodes),
2421
- edges: edgePrimaryKeyConstraint(tables.edges)
3841
+ nodes: nodePrimaryKeyConstraint(tables3.nodes),
3842
+ edges: edgePrimaryKeyConstraint(tables3.edges)
2422
3843
  },
2423
- buildUpdateNodeSet(params, timestamp) {
2424
- return buildUpdateNodeSet(tables, dialect, params, timestamp);
3844
+ buildUpdateNodeSet(params, timestamp2) {
3845
+ return buildUpdateNodeSet(tables3, dialect, params, timestamp2);
2425
3846
  },
2426
3847
  buildDeleteContributionMaterialization,
2427
3848
  buildInsertContributionMaterialization,
2428
3849
  buildInsertUnique(params) {
2429
- return buildInsertUnique(tables, dialect, params);
3850
+ return buildInsertUnique(tables3, dialect, params);
2430
3851
  },
2431
3852
  buildInsertUniqueBatch(entries) {
2432
- return buildInsertUniqueBatch(tables, dialect, entries);
3853
+ return buildInsertUniqueBatch(tables3, dialect, entries);
3854
+ },
3855
+ buildHardDeleteUniquesByConcreteKind(params) {
3856
+ return buildHardDeleteUniquesByConcreteKind(
3857
+ getTableName(tables3.uniques),
3858
+ params
3859
+ );
3860
+ },
3861
+ buildLockEdgeClaims(entries, timestamp2) {
3862
+ return buildLockEdgeClaims(tables3, entries, timestamp2);
3863
+ },
3864
+ buildTakeOverEdgeClaim(params, timestamp2) {
3865
+ return buildTakeOverEdgeClaim(tables3, params, timestamp2);
3866
+ },
3867
+ buildPurgeEdgeClaims(params) {
3868
+ return buildPurgeEdgeClaims(tables3, params);
3869
+ },
3870
+ buildContendedUniqueRowAudit(graphId, constraintNames) {
3871
+ return buildContendedUniqueRowAudit(tables3, graphId, constraintNames);
3872
+ },
3873
+ buildContendedEdgeRowAudit(graphId, cardinality, edgeKinds) {
3874
+ return buildContendedEdgeRowAudit(
3875
+ tables3,
3876
+ graphId,
3877
+ cardinality,
3878
+ edgeKinds
3879
+ );
3880
+ },
3881
+ buildDisjointOverlapAudit(graphId, kinds) {
3882
+ return buildDisjointOverlapAudit(tables3, graphId, kinds);
2433
3883
  },
2434
3884
  buildGetActiveSchema(graphId) {
2435
- return buildGetActiveSchema(tables, graphId, dialect);
3885
+ return buildGetActiveSchema(tables3, graphId, dialect);
2436
3886
  },
2437
- buildInsertSchema(params, timestamp) {
2438
- return buildInsertSchema(tables, params, timestamp, dialect);
3887
+ buildInsertSchema(params, timestamp2) {
3888
+ return buildInsertSchema(tables3, params, timestamp2, dialect);
2439
3889
  },
2440
3890
  buildSetActiveSchema(graphId, version) {
2441
- return buildSetActiveSchema(tables, graphId, version, dialect);
3891
+ return buildSetActiveSchema(tables3, graphId, version, dialect);
2442
3892
  },
2443
3893
  buildTableExists(tableName) {
2444
3894
  switch (dialect) {
@@ -2461,7 +3911,7 @@ function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
2461
3911
  }
2462
3912
  },
2463
3913
  buildClearGraph(graphId) {
2464
- return buildClearGraph(tables, graphId);
3914
+ return buildClearGraph(tables3, graphId);
2465
3915
  }
2466
3916
  };
2467
3917
  }
@@ -2487,11 +3937,14 @@ function createCachedTableExistence(probe, options) {
2487
3937
  return exists;
2488
3938
  };
2489
3939
  }
2490
- function createSqliteOperationStrategy(tables, fulltextStrategy) {
2491
- return createCommonOperationStrategy(tables, "sqlite", fulltextStrategy);
3940
+ function createSqliteOperationStrategy(tables3, fulltextStrategy) {
3941
+ return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
3942
+ }
3943
+ function createPostgresOperationStrategy(tables3, fulltextStrategy) {
3944
+ return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
2492
3945
  }
2493
- function createPostgresOperationStrategy(tables, fulltextStrategy) {
2494
- return createCommonOperationStrategy(tables, "postgres", fulltextStrategy);
3946
+ function claimOwnerOf(params) {
3947
+ return { concreteKind: params.concreteKind, nodeId: params.nodeId };
2495
3948
  }
2496
3949
  var DRIZZLE_DIALECT_LABELS = {
2497
3950
  postgres: "Postgres",
@@ -2594,6 +4047,50 @@ function createCommonOperationBackend(options) {
2594
4047
  }
2595
4048
  await execution.execRun(statement.query);
2596
4049
  }
4050
+ async function claimEdgeCardinalityEntries(entries) {
4051
+ if (entries.length === 0) return [];
4052
+ const targetKey = (entry) => {
4053
+ const target = edgeCardinalityClaimTarget(entry);
4054
+ return `${target.axis}\0${target.key}`;
4055
+ };
4056
+ const seen = /* @__PURE__ */ new Set();
4057
+ for (const entry of entries) {
4058
+ const key = targetKey(entry);
4059
+ if (seen.has(key)) {
4060
+ throw new DatabaseOperationError(
4061
+ "Two edge claims in one batch name the same cardinality axis and key; a multi-row upsert cannot affect one row twice.",
4062
+ { operation: "insert", entity: "edge" }
4063
+ );
4064
+ }
4065
+ seen.add(key);
4066
+ }
4067
+ const outcomes = /* @__PURE__ */ new Map();
4068
+ for (const chunk2 of chunk(entries, batchConfig.edgeInsertBatchSize)) {
4069
+ const lockQuery = operationStrategy.buildLockEdgeClaims(chunk2, nowIso2());
4070
+ const rows = await execution.execAll(lockQuery);
4071
+ const holderByTarget = new Map(
4072
+ rows.map((row) => [`${row.axis}\0${row.key}`, row.holder_edge_id])
4073
+ );
4074
+ for (const entry of chunk2) {
4075
+ const key = targetKey(entry);
4076
+ const holder = holderByTarget.get(key);
4077
+ if (holder === void 0 || holder === entry.edgeId) {
4078
+ outcomes.set(key, { status: "claimed" });
4079
+ continue;
4080
+ }
4081
+ const takeOver = await execution.execAll(
4082
+ operationStrategy.buildTakeOverEdgeClaim(entry, nowIso2())
4083
+ );
4084
+ outcomes.set(
4085
+ key,
4086
+ takeOver.length > 0 ? { status: "claimed" } : { status: "refused", holderEdgeId: holder }
4087
+ );
4088
+ }
4089
+ }
4090
+ return entries.map(
4091
+ (entry) => outcomes.get(targetKey(entry)) ?? { status: "claimed" }
4092
+ );
4093
+ }
2597
4094
  async function readActiveVersion(graphId) {
2598
4095
  const row = await execution.execGet(
2599
4096
  operationStrategy.buildGetActiveSchema(graphId)
@@ -2612,8 +4109,8 @@ function createCommonOperationBackend(options) {
2612
4109
  await execution.execRun(query);
2613
4110
  },
2614
4111
  async insertNode(params) {
2615
- const timestamp = nowIso2();
2616
- const query = operationStrategy.buildInsertNode(params, timestamp);
4112
+ const timestamp2 = nowIso2();
4113
+ const query = operationStrategy.buildInsertNode(params, timestamp2);
2617
4114
  const row = await withDuplicateKeyClassification(
2618
4115
  () => execution.execGet(query),
2619
4116
  {
@@ -2634,10 +4131,10 @@ function createCommonOperationBackend(options) {
2634
4131
  return rowMappers.toNodeRow(row);
2635
4132
  },
2636
4133
  async insertNodeNoReturn(params) {
2637
- const timestamp = nowIso2();
4134
+ const timestamp2 = nowIso2();
2638
4135
  const query = operationStrategy.buildInsertNodeNoReturn(
2639
4136
  params,
2640
- timestamp
4137
+ timestamp2
2641
4138
  );
2642
4139
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2643
4140
  entity: "node",
@@ -2649,9 +4146,9 @@ function createCommonOperationBackend(options) {
2649
4146
  if (params.length === 0) {
2650
4147
  return;
2651
4148
  }
2652
- const timestamp = nowIso2();
4149
+ const timestamp2 = nowIso2();
2653
4150
  for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
2654
- const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp);
4151
+ const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp2);
2655
4152
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2656
4153
  entity: "node",
2657
4154
  relation: operationStrategy.primaryKeyConstraints.nodes,
@@ -2663,12 +4160,12 @@ function createCommonOperationBackend(options) {
2663
4160
  if (params.length === 0) {
2664
4161
  return [];
2665
4162
  }
2666
- const timestamp = nowIso2();
4163
+ const timestamp2 = nowIso2();
2667
4164
  const allRows = [];
2668
4165
  for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
2669
4166
  const query = operationStrategy.buildInsertNodesBatchReturning(
2670
4167
  chunk2,
2671
- timestamp
4168
+ timestamp2
2672
4169
  );
2673
4170
  const rows = await withDuplicateKeyClassification(
2674
4171
  () => execution.execAll(query),
@@ -2698,8 +4195,8 @@ function createCommonOperationBackend(options) {
2698
4195
  return allRows;
2699
4196
  },
2700
4197
  async updateNode(params) {
2701
- const timestamp = nowIso2();
2702
- const query = operationStrategy.buildUpdateNode(params, timestamp);
4198
+ const timestamp2 = nowIso2();
4199
+ const query = operationStrategy.buildUpdateNode(params, timestamp2);
2703
4200
  const row = await execution.execGet(query);
2704
4201
  if (!row)
2705
4202
  throw new DatabaseOperationError(
@@ -2725,15 +4222,15 @@ function createCommonOperationBackend(options) {
2725
4222
  { operation: "updateNodeSet", kind: params.kind }
2726
4223
  );
2727
4224
  }
2728
- const timestamp = nowIso2();
2729
- const query = operationStrategy.buildUpdateNodeSet(params, timestamp);
4225
+ const timestamp2 = nowIso2();
4226
+ const query = operationStrategy.buildUpdateNodeSet(params, timestamp2);
2730
4227
  const rows = await execution.execAll(query);
2731
4228
  const updatedRows = rows.map((row) => rowMappers.toNodeRow(row));
2732
4229
  return { affectedCount: updatedRows.length, rows: updatedRows };
2733
4230
  },
2734
4231
  async deleteNode(params) {
2735
- const timestamp = nowIso2();
2736
- const query = operationStrategy.buildDeleteNode(params, timestamp);
4232
+ const timestamp2 = nowIso2();
4233
+ const query = operationStrategy.buildDeleteNode(params, timestamp2);
2737
4234
  await execution.execRun(query);
2738
4235
  },
2739
4236
  // IMPORTANT: This cascade is not atomic. Callers must ensure this runs
@@ -2770,8 +4267,8 @@ function createCommonOperationBackend(options) {
2770
4267
  await execution.execRun(query);
2771
4268
  },
2772
4269
  async insertEdge(params) {
2773
- const timestamp = nowIso2();
2774
- const query = operationStrategy.buildInsertEdge(params, timestamp);
4270
+ const timestamp2 = nowIso2();
4271
+ const query = operationStrategy.buildInsertEdge(params, timestamp2);
2775
4272
  const row = await withDuplicateKeyClassification(
2776
4273
  () => execution.execGet(query),
2777
4274
  {
@@ -2792,10 +4289,10 @@ function createCommonOperationBackend(options) {
2792
4289
  return rowMappers.toEdgeRow(row);
2793
4290
  },
2794
4291
  async insertEdgeNoReturn(params) {
2795
- const timestamp = nowIso2();
4292
+ const timestamp2 = nowIso2();
2796
4293
  const query = operationStrategy.buildInsertEdgeNoReturn(
2797
4294
  params,
2798
- timestamp
4295
+ timestamp2
2799
4296
  );
2800
4297
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2801
4298
  entity: "edge",
@@ -2807,9 +4304,9 @@ function createCommonOperationBackend(options) {
2807
4304
  if (params.length === 0) {
2808
4305
  return;
2809
4306
  }
2810
- const timestamp = nowIso2();
4307
+ const timestamp2 = nowIso2();
2811
4308
  for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
2812
- const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp);
4309
+ const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp2);
2813
4310
  await withDuplicateKeyClassification(() => execution.execRun(query), {
2814
4311
  entity: "edge",
2815
4312
  relation: operationStrategy.primaryKeyConstraints.edges,
@@ -2821,12 +4318,12 @@ function createCommonOperationBackend(options) {
2821
4318
  if (params.length === 0) {
2822
4319
  return [];
2823
4320
  }
2824
- const timestamp = nowIso2();
4321
+ const timestamp2 = nowIso2();
2825
4322
  const allRows = [];
2826
4323
  for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
2827
4324
  const query = operationStrategy.buildInsertEdgesBatchReturning(
2828
4325
  chunk2,
2829
- timestamp
4326
+ timestamp2
2830
4327
  );
2831
4328
  const rows = await withDuplicateKeyClassification(
2832
4329
  () => execution.execAll(query),
@@ -2856,8 +4353,8 @@ function createCommonOperationBackend(options) {
2856
4353
  return allRows;
2857
4354
  },
2858
4355
  async updateEdge(params) {
2859
- const timestamp = nowIso2();
2860
- const query = operationStrategy.buildUpdateEdge(params, timestamp);
4356
+ const timestamp2 = nowIso2();
4357
+ const query = operationStrategy.buildUpdateEdge(params, timestamp2);
2861
4358
  const row = await execution.execGet(query);
2862
4359
  if (!row)
2863
4360
  throw new DatabaseOperationError(
@@ -2871,8 +4368,8 @@ function createCommonOperationBackend(options) {
2871
4368
  return rowMappers.toEdgeRow(row);
2872
4369
  },
2873
4370
  async deleteEdge(params) {
2874
- const timestamp = nowIso2();
2875
- const query = operationStrategy.buildDeleteEdge(params, timestamp);
4371
+ const timestamp2 = nowIso2();
4372
+ const query = operationStrategy.buildDeleteEdge(params, timestamp2);
2876
4373
  await execution.execRun(query);
2877
4374
  },
2878
4375
  async hardDeleteEdge(params) {
@@ -2881,7 +4378,7 @@ function createCommonOperationBackend(options) {
2881
4378
  },
2882
4379
  async deleteEdgesBatch(params) {
2883
4380
  if (params.ids.length === 0) return;
2884
- const timestamp = nowIso2();
4381
+ const timestamp2 = nowIso2();
2885
4382
  const softDeleteChunkSize = Math.max(
2886
4383
  1,
2887
4384
  batchConfig.getEdgesChunkSize - 1
@@ -2889,7 +4386,7 @@ function createCommonOperationBackend(options) {
2889
4386
  for (const chunk2 of chunk(params.ids, softDeleteChunkSize)) {
2890
4387
  const query = operationStrategy.buildDeleteEdgesBatch(
2891
4388
  { graphId: params.graphId, ids: chunk2 },
2892
- timestamp
4389
+ timestamp2
2893
4390
  );
2894
4391
  await execution.execRun(query);
2895
4392
  }
@@ -2976,13 +4473,23 @@ function createCommonOperationBackend(options) {
2976
4473
  async insertUnique(params) {
2977
4474
  const query = operationStrategy.buildInsertUnique(params);
2978
4475
  const result = await execution.execGet(query);
2979
- if (result && result.node_id !== params.nodeId) {
4476
+ if (result && !isSameClaimOwner(
4477
+ { concreteKind: result.concrete_kind, nodeId: result.node_id },
4478
+ claimOwnerOf(params)
4479
+ )) {
2980
4480
  throw new UniquenessError({
2981
4481
  constraintName: params.constraintName,
2982
- kind: params.nodeKind,
4482
+ // The holder's own kind, never `nodeKind`: that column carries the
4483
+ // claim AXIS, which a shared scope folds across kinds, so it need not
4484
+ // be the holder's kind and usually is not.
4485
+ kind: result.concrete_kind,
2983
4486
  existingId: result.node_id,
2984
4487
  newId: params.nodeId,
2985
- fields: []
4488
+ fields: [],
4489
+ // The axis THIS statement attempted — `mapClaimRefusal`'s only way to
4490
+ // tell two disjoint pairs (or two scoped constraints) sharing a key
4491
+ // apart, since `constraintName` alone does not.
4492
+ axis: params.nodeKind
2986
4493
  });
2987
4494
  }
2988
4495
  },
@@ -2996,13 +4503,14 @@ function createCommonOperationBackend(options) {
2996
4503
  byTarget.set(targetKey(entry), entry);
2997
4504
  continue;
2998
4505
  }
2999
- if (existing.nodeId !== entry.nodeId) {
4506
+ if (!isSameClaimOwner(claimOwnerOf(existing), claimOwnerOf(entry))) {
3000
4507
  throw new UniquenessError({
3001
4508
  constraintName: entry.constraintName,
3002
- kind: entry.nodeKind,
4509
+ kind: existing.concreteKind,
3003
4510
  existingId: existing.nodeId,
3004
4511
  newId: entry.nodeId,
3005
- fields: []
4512
+ fields: [],
4513
+ axis: entry.nodeKind
3006
4514
  });
3007
4515
  }
3008
4516
  }
@@ -3016,26 +4524,27 @@ function createCommonOperationBackend(options) {
3016
4524
  const ownerByTarget = new Map(
3017
4525
  rows.map((row) => [
3018
4526
  `${row.node_kind}\0${row.constraint_name}\0${row.key}`,
3019
- row.node_id
4527
+ { concreteKind: row.concrete_kind, nodeId: row.node_id }
3020
4528
  ])
3021
4529
  );
3022
4530
  for (const entry of chunk2) {
3023
4531
  const owner = ownerByTarget.get(targetKey(entry));
3024
- if (owner !== void 0 && owner !== entry.nodeId) {
4532
+ if (owner !== void 0 && !isSameClaimOwner(owner, claimOwnerOf(entry))) {
3025
4533
  throw new UniquenessError({
3026
4534
  constraintName: entry.constraintName,
3027
- kind: entry.nodeKind,
3028
- existingId: owner,
4535
+ kind: owner.concreteKind,
4536
+ existingId: owner.nodeId,
3029
4537
  newId: entry.nodeId,
3030
- fields: []
4538
+ fields: [],
4539
+ axis: entry.nodeKind
3031
4540
  });
3032
4541
  }
3033
4542
  }
3034
4543
  }
3035
4544
  },
3036
4545
  async deleteUnique(params) {
3037
- const timestamp = nowIso2();
3038
- const query = operationStrategy.buildDeleteUnique(params, timestamp);
4546
+ const timestamp2 = nowIso2();
4547
+ const query = operationStrategy.buildDeleteUnique(params, timestamp2);
3039
4548
  await execution.execRun(query);
3040
4549
  },
3041
4550
  async hardDeleteUniquesByNodeIds(params) {
@@ -3051,6 +4560,78 @@ function createCommonOperationBackend(options) {
3051
4560
  await execution.execRun(query);
3052
4561
  }
3053
4562
  },
4563
+ async hardDeleteUniquesByConcreteKind(params) {
4564
+ const query = operationStrategy.buildHardDeleteUniquesByConcreteKind(params);
4565
+ await execution.execRun(query);
4566
+ },
4567
+ async claimEdgeCardinality(params) {
4568
+ const [outcome] = await claimEdgeCardinalityEntries([params]);
4569
+ return outcome ?? { status: "claimed" };
4570
+ },
4571
+ claimEdgeCardinalityBatch(entries) {
4572
+ return claimEdgeCardinalityEntries(entries);
4573
+ },
4574
+ async purgeEdgeClaims(params) {
4575
+ const edgeIds = [...new Set(params.edgeIds)];
4576
+ for (const chunk2 of chunk(edgeIds, batchConfig.getEdgesChunkSize)) {
4577
+ const query = operationStrategy.buildPurgeEdgeClaims({
4578
+ ...params,
4579
+ edgeIds: chunk2
4580
+ });
4581
+ await execution.execRun(query);
4582
+ }
4583
+ },
4584
+ async readConstraintFenceViolations(params) {
4585
+ const uniqueRows = params.uniqueConstraintNames.length === 0 ? [] : await execution.execAll(
4586
+ operationStrategy.buildContendedUniqueRowAudit(
4587
+ params.graphId,
4588
+ params.uniqueConstraintNames
4589
+ )
4590
+ );
4591
+ const contendedUniqueRows = uniqueRows.map((row) => ({
4592
+ nodeKind: row.node_kind,
4593
+ constraintName: row.constraint_name,
4594
+ key: row.key,
4595
+ concreteKind: row.concrete_kind,
4596
+ nodeId: row.node_id
4597
+ }));
4598
+ const edgeKindsByCardinality = /* @__PURE__ */ new Map();
4599
+ for (const declaration of params.edgeCardinalities) {
4600
+ const kinds = edgeKindsByCardinality.get(declaration.cardinality) ?? [];
4601
+ kinds.push(declaration.edgeKind);
4602
+ edgeKindsByCardinality.set(declaration.cardinality, kinds);
4603
+ }
4604
+ const contendedEdgeRows = [];
4605
+ for (const [cardinality, edgeKinds] of edgeKindsByCardinality) {
4606
+ const rows = await execution.execAll(
4607
+ operationStrategy.buildContendedEdgeRowAudit(
4608
+ params.graphId,
4609
+ cardinality,
4610
+ edgeKinds
4611
+ )
4612
+ );
4613
+ for (const row of rows) {
4614
+ contendedEdgeRows.push({
4615
+ edgeKind: row.edge_kind,
4616
+ cardinality,
4617
+ edgeId: row.edge_id,
4618
+ fromKind: row.from_kind,
4619
+ fromId: row.from_id,
4620
+ toKind: row.to_kind,
4621
+ toId: row.to_id
4622
+ });
4623
+ }
4624
+ }
4625
+ const disjointOverlaps = [];
4626
+ for (const kinds of params.disjointKindPairs) {
4627
+ const rows = await execution.execAll(
4628
+ operationStrategy.buildDisjointOverlapAudit(params.graphId, kinds)
4629
+ );
4630
+ for (const row of rows)
4631
+ disjointOverlaps.push({ kinds, nodeId: row.node_id });
4632
+ }
4633
+ return { contendedUniqueRows, contendedEdgeRows, disjointOverlaps };
4634
+ },
3054
4635
  async checkUnique(params) {
3055
4636
  const query = operationStrategy.buildCheckUnique(params);
3056
4637
  const row = await execution.execGet(query);
@@ -3125,7 +4706,7 @@ function createCommonOperationBackend(options) {
3125
4706
  );
3126
4707
  await execution.execRun(flip.deactivateAll);
3127
4708
  }
3128
- const timestamp = nowIso2();
4709
+ const timestamp2 = nowIso2();
3129
4710
  const insertQuery = operationStrategy.buildInsertSchema(
3130
4711
  {
3131
4712
  graphId: params.graphId,
@@ -3134,7 +4715,7 @@ function createCommonOperationBackend(options) {
3134
4715
  schemaDoc: params.schemaDoc,
3135
4716
  isActive: true
3136
4717
  },
3137
- timestamp
4718
+ timestamp2
3138
4719
  );
3139
4720
  const insertedRaw = await execution.execGet(insertQuery);
3140
4721
  if (!insertedRaw) {
@@ -3334,7 +4915,7 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3334
4915
  return {
3335
4916
  async insertNodes(params) {
3336
4917
  if (params.length === 0) return;
3337
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4918
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3338
4919
  await executePreparedRunBatch(
3339
4920
  nodeSql,
3340
4921
  params.map((item) => [
@@ -3342,16 +4923,16 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3342
4923
  item.kind,
3343
4924
  item.id,
3344
4925
  JSON.stringify(item.props),
3345
- resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
4926
+ resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL,
3346
4927
  item.validTo ?? DATABASE_NULL,
3347
- timestamp,
3348
- timestamp
4928
+ timestamp2,
4929
+ timestamp2
3349
4930
  ])
3350
4931
  );
3351
4932
  },
3352
4933
  async insertEdges(params) {
3353
4934
  if (params.length === 0) return;
3354
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4935
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3355
4936
  await executePreparedRunBatch(
3356
4937
  edgeSql,
3357
4938
  params.map((item) => [
@@ -3363,10 +4944,10 @@ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
3363
4944
  item.toKind,
3364
4945
  item.toId,
3365
4946
  JSON.stringify(item.props),
3366
- resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
4947
+ resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL,
3367
4948
  item.validTo ?? DATABASE_NULL,
3368
- timestamp,
3369
- timestamp
4949
+ timestamp2,
4950
+ timestamp2
3370
4951
  ])
3371
4952
  );
3372
4953
  }
@@ -3396,7 +4977,7 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3396
4977
  return {
3397
4978
  async insertNodes(params) {
3398
4979
  if (params.length === 0) return;
3399
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4980
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3400
4981
  await executeRaw(nodeSql, [
3401
4982
  postgresArray(params.map((item) => item.graphId)),
3402
4983
  postgresArray(params.map((item) => item.kind)),
@@ -3404,16 +4985,16 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3404
4985
  postgresArray(params.map((item) => JSON.stringify(item.props))),
3405
4986
  postgresArray(
3406
4987
  params.map(
3407
- (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
4988
+ (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL
3408
4989
  )
3409
4990
  ),
3410
4991
  postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
3411
- postgresArray(params.map(() => timestamp))
4992
+ postgresArray(params.map(() => timestamp2))
3412
4993
  ]);
3413
4994
  },
3414
4995
  async insertEdges(params) {
3415
4996
  if (params.length === 0) return;
3416
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
4997
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
3417
4998
  await executeRaw(edgeSql, [
3418
4999
  postgresArray(params.map((item) => item.graphId)),
3419
5000
  postgresArray(params.map((item) => item.id)),
@@ -3425,11 +5006,11 @@ function createPostgresTrustedImportSession(backend, tableNames) {
3425
5006
  postgresArray(params.map((item) => JSON.stringify(item.props))),
3426
5007
  postgresArray(
3427
5008
  params.map(
3428
- (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
5009
+ (item) => resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp2) ?? DATABASE_NULL
3429
5010
  )
3430
5011
  ),
3431
5012
  postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
3432
- postgresArray(params.map(() => timestamp))
5013
+ postgresArray(params.map(() => timestamp2))
3433
5014
  ]);
3434
5015
  }
3435
5016
  };
@@ -3452,6 +5033,6 @@ function getOrCreateLru(cache, key, cacheMax, create) {
3452
5033
  return value;
3453
5034
  }
3454
5035
 
3455
- 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 };
3456
- //# sourceMappingURL=chunk-Z2JCLZFJ.js.map
3457
- //# sourceMappingURL=chunk-Z2JCLZFJ.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