@nicia-ai/typegraph 0.44.0 → 0.46.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 (392) hide show
  1. package/dist/backend/drizzle/indexes.cjs +11 -11
  2. package/dist/backend/drizzle/indexes.d.cts +1 -1
  3. package/dist/backend/drizzle/indexes.d.ts +1 -1
  4. package/dist/backend/drizzle/indexes.js +7 -7
  5. package/dist/backend/index.cjs +53 -54
  6. package/dist/backend/index.d.cts +3 -3
  7. package/dist/backend/index.d.ts +3 -3
  8. package/dist/backend/index.js +13 -14
  9. package/dist/backend/postgres/index.cjs +29 -30
  10. package/dist/backend/postgres/index.d.cts +7 -7
  11. package/dist/backend/postgres/index.d.ts +7 -7
  12. package/dist/backend/postgres/index.js +16 -17
  13. package/dist/backend/postgres/pglite-store.cjs +48 -43
  14. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  15. package/dist/backend/postgres/pglite-store.d.cts +15 -9
  16. package/dist/backend/postgres/pglite-store.d.ts +15 -9
  17. package/dist/backend/postgres/pglite-store.js +44 -39
  18. package/dist/backend/postgres/pglite-store.js.map +1 -1
  19. package/dist/backend/postgres/pglite.cjs +18 -19
  20. package/dist/backend/postgres/pglite.d.cts +4 -4
  21. package/dist/backend/postgres/pglite.d.ts +4 -4
  22. package/dist/backend/postgres/pglite.js +17 -18
  23. package/dist/backend/sqlite/index.cjs +26 -27
  24. package/dist/backend/sqlite/index.d.cts +6 -6
  25. package/dist/backend/sqlite/index.d.ts +6 -6
  26. package/dist/backend/sqlite/index.js +14 -15
  27. package/dist/backend/sqlite/libsql.cjs +21 -22
  28. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  29. package/dist/backend/sqlite/libsql.d.cts +15 -8
  30. package/dist/backend/sqlite/libsql.d.ts +15 -8
  31. package/dist/backend/sqlite/libsql.js +17 -18
  32. package/dist/backend/sqlite/libsql.js.map +1 -1
  33. package/dist/backend/sqlite/local-store.cjs +49 -44
  34. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  35. package/dist/backend/sqlite/local-store.d.cts +15 -10
  36. package/dist/backend/sqlite/local-store.d.ts +15 -10
  37. package/dist/backend/sqlite/local-store.js +45 -40
  38. package/dist/backend/sqlite/local-store.js.map +1 -1
  39. package/dist/backend/sqlite/local.cjs +19 -20
  40. package/dist/backend/sqlite/local.d.cts +3 -3
  41. package/dist/backend/sqlite/local.d.ts +3 -3
  42. package/dist/backend/sqlite/local.js +17 -18
  43. package/dist/{chunk-XMYJY7NI.js → chunk-2LG2XB2M.js} +3 -3
  44. package/dist/{chunk-XMYJY7NI.js.map → chunk-2LG2XB2M.js.map} +1 -1
  45. package/dist/{chunk-QGKILWGZ.cjs → chunk-2NA5DYLO.cjs} +4 -4
  46. package/dist/{chunk-QGKILWGZ.cjs.map → chunk-2NA5DYLO.cjs.map} +1 -1
  47. package/dist/{chunk-5MUSU4ZP.cjs → chunk-3DHZCOT7.cjs} +20 -20
  48. package/dist/chunk-3DHZCOT7.cjs.map +1 -0
  49. package/dist/{chunk-OVUUTCPJ.cjs → chunk-4UGOKMI5.cjs} +268 -150
  50. package/dist/chunk-4UGOKMI5.cjs.map +1 -0
  51. package/dist/{chunk-FRHHDHKH.js → chunk-5262ZMTR.js} +26 -5
  52. package/dist/chunk-5262ZMTR.js.map +1 -0
  53. package/dist/{chunk-HOIFFY4M.js → chunk-5763DULU.js} +248 -76
  54. package/dist/chunk-5763DULU.js.map +1 -0
  55. package/dist/{chunk-7G32LIQM.js → chunk-5UVRGXD3.js} +277 -7
  56. package/dist/chunk-5UVRGXD3.js.map +1 -0
  57. package/dist/{chunk-IIT5K7SK.cjs → chunk-62ZP23AW.cjs} +15 -15
  58. package/dist/{chunk-IIT5K7SK.cjs.map → chunk-62ZP23AW.cjs.map} +1 -1
  59. package/dist/{chunk-S4KQ5LV4.js → chunk-775A4ZMN.js} +40 -6
  60. package/dist/chunk-775A4ZMN.js.map +1 -0
  61. package/dist/{chunk-QYWINYEA.cjs → chunk-7BQXPCGN.cjs} +830 -170
  62. package/dist/chunk-7BQXPCGN.cjs.map +1 -0
  63. package/dist/{chunk-FJMPR3OH.cjs → chunk-7EO3TCQB.cjs} +33 -7
  64. package/dist/chunk-7EO3TCQB.cjs.map +1 -0
  65. package/dist/chunk-7GT72YHH.cjs +1979 -0
  66. package/dist/chunk-7GT72YHH.cjs.map +1 -0
  67. package/dist/{chunk-SQRD2CYF.js → chunk-7VQXLT5O.js} +717 -76
  68. package/dist/chunk-7VQXLT5O.js.map +1 -0
  69. package/dist/{chunk-BCP7LLOY.js → chunk-7Z5OR7KO.js} +2706 -625
  70. package/dist/chunk-7Z5OR7KO.js.map +1 -0
  71. package/dist/chunk-A4OC4DVN.cjs +12 -0
  72. package/dist/{chunk-4SZ6XPTG.cjs.map → chunk-A4OC4DVN.cjs.map} +1 -1
  73. package/dist/{chunk-TDXIBCGY.cjs → chunk-A7J2YDDI.cjs} +5 -3
  74. package/dist/chunk-A7J2YDDI.cjs.map +1 -0
  75. package/dist/{chunk-FMMIX6N4.js → chunk-AKLS3BYZ.js} +56 -5
  76. package/dist/chunk-AKLS3BYZ.js.map +1 -0
  77. package/dist/{chunk-D7PG5D5K.js → chunk-AMKPPFUO.js} +32 -6
  78. package/dist/chunk-AMKPPFUO.js.map +1 -0
  79. package/dist/{chunk-PAW2XUZN.js → chunk-ASTI57H3.js} +3 -3
  80. package/dist/{chunk-PAW2XUZN.js.map → chunk-ASTI57H3.js.map} +1 -1
  81. package/dist/{chunk-FMGEZBAQ.js → chunk-BKCUOV7A.js} +27 -5
  82. package/dist/chunk-BKCUOV7A.js.map +1 -0
  83. package/dist/chunk-BSFJMMV3.cjs +268 -0
  84. package/dist/chunk-BSFJMMV3.cjs.map +1 -0
  85. package/dist/{chunk-63KCKSSH.js → chunk-C23WSN5E.js} +209 -24
  86. package/dist/chunk-C23WSN5E.js.map +1 -0
  87. package/dist/{chunk-JRP3VGHS.js → chunk-CBTIUB76.js} +3 -3
  88. package/dist/{chunk-JRP3VGHS.js.map → chunk-CBTIUB76.js.map} +1 -1
  89. package/dist/chunk-CNV4TXJG.js +58 -0
  90. package/dist/chunk-CNV4TXJG.js.map +1 -0
  91. package/dist/{chunk-QB6VMOJ2.cjs → chunk-CXBHOOIQ.cjs} +45 -10
  92. package/dist/chunk-CXBHOOIQ.cjs.map +1 -0
  93. package/dist/{chunk-46GDII45.js → chunk-DCQVHAYQ.js} +5 -5
  94. package/dist/{chunk-46GDII45.js.map → chunk-DCQVHAYQ.js.map} +1 -1
  95. package/dist/chunk-DLNROMQ7.js +306 -0
  96. package/dist/chunk-DLNROMQ7.js.map +1 -0
  97. package/dist/chunk-DYATYRY4.js +47 -0
  98. package/dist/chunk-DYATYRY4.js.map +1 -0
  99. package/dist/chunk-E4WNQBEF.cjs +217 -0
  100. package/dist/chunk-E4WNQBEF.cjs.map +1 -0
  101. package/dist/{chunk-G6Q5UM7U.js → chunk-FWJKWH6U.js} +5 -3
  102. package/dist/chunk-FWJKWH6U.js.map +1 -0
  103. package/dist/{chunk-BNUFUFAU.js → chunk-HFHTMECK.js} +7 -7
  104. package/dist/chunk-HFHTMECK.js.map +1 -0
  105. package/dist/{chunk-TFMVL4QH.js → chunk-I5MOXA4H.js} +20 -14
  106. package/dist/chunk-I5MOXA4H.js.map +1 -0
  107. package/dist/{chunk-4MB3AQAQ.js → chunk-J3WZ3FA2.js} +77 -3
  108. package/dist/chunk-J3WZ3FA2.js.map +1 -0
  109. package/dist/{chunk-UR7W5YQK.js → chunk-JBQQ7THH.js} +5 -3
  110. package/dist/chunk-JBQQ7THH.js.map +1 -0
  111. package/dist/chunk-JIVMTW7W.js +3393 -0
  112. package/dist/chunk-JIVMTW7W.js.map +1 -0
  113. package/dist/{chunk-2Y4IFKW7.js → chunk-JXA2ZP2Q.js} +6 -17
  114. package/dist/chunk-JXA2ZP2Q.js.map +1 -0
  115. package/dist/{chunk-GYA4JRP5.js → chunk-JXXDZTMN.js} +2 -2
  116. package/dist/chunk-JXXDZTMN.js.map +1 -0
  117. package/dist/chunk-JZUR7ZWE.js +254 -0
  118. package/dist/chunk-JZUR7ZWE.js.map +1 -0
  119. package/dist/chunk-K5ELX2GT.js +248 -0
  120. package/dist/chunk-K5ELX2GT.js.map +1 -0
  121. package/dist/chunk-LBJKZXDE.cjs +257 -0
  122. package/dist/chunk-LBJKZXDE.cjs.map +1 -0
  123. package/dist/{chunk-FGO5JFVJ.cjs → chunk-M4BDU5RX.cjs} +12 -12
  124. package/dist/{chunk-FGO5JFVJ.cjs.map → chunk-M4BDU5RX.cjs.map} +1 -1
  125. package/dist/{chunk-MIJKEVV7.js → chunk-MSY7FSX4.js} +37 -4
  126. package/dist/chunk-MSY7FSX4.js.map +1 -0
  127. package/dist/{chunk-ST3LPB2V.cjs → chunk-MUK4BU7K.cjs} +788 -146
  128. package/dist/chunk-MUK4BU7K.cjs.map +1 -0
  129. package/dist/{chunk-MCHP7RHZ.cjs → chunk-MXJDTH5B.cjs} +64 -41
  130. package/dist/chunk-MXJDTH5B.cjs.map +1 -0
  131. package/dist/{chunk-2VLBGQBY.cjs → chunk-N3257XE6.cjs} +724 -577
  132. package/dist/chunk-N3257XE6.cjs.map +1 -0
  133. package/dist/chunk-N66HCGCY.cjs +57 -0
  134. package/dist/chunk-N66HCGCY.cjs.map +1 -0
  135. package/dist/{chunk-CPEL3YIR.cjs → chunk-NFCVHQ5P.cjs} +55 -22
  136. package/dist/chunk-NFCVHQ5P.cjs.map +1 -0
  137. package/dist/{chunk-C4F7VJ5D.cjs → chunk-NI72YOJB.cjs} +84 -2
  138. package/dist/chunk-NI72YOJB.cjs.map +1 -0
  139. package/dist/{chunk-EE7N5XXQ.cjs → chunk-NK5Q7UNE.cjs} +10 -21
  140. package/dist/chunk-NK5Q7UNE.cjs.map +1 -0
  141. package/dist/{chunk-PHXITZE4.js → chunk-NMWDXFPH.js} +4 -4
  142. package/dist/{chunk-PHXITZE4.js.map → chunk-NMWDXFPH.js.map} +1 -1
  143. package/dist/{chunk-FSXTPBRN.js → chunk-NQ6BRJBE.js} +416 -850
  144. package/dist/chunk-NQ6BRJBE.js.map +1 -0
  145. package/dist/chunk-OH5E5KIO.js +2057 -0
  146. package/dist/chunk-OH5E5KIO.js.map +1 -0
  147. package/dist/chunk-ONU3HIED.cjs +2082 -0
  148. package/dist/chunk-ONU3HIED.cjs.map +1 -0
  149. package/dist/{chunk-STQ3BSED.cjs → chunk-PNN7RHVR.cjs} +66 -44
  150. package/dist/chunk-PNN7RHVR.cjs.map +1 -0
  151. package/dist/{chunk-6DCB664D.js → chunk-PQBQG7IM.js} +3 -3
  152. package/dist/{chunk-6DCB664D.js.map → chunk-PQBQG7IM.js.map} +1 -1
  153. package/dist/{chunk-ACSVZPK7.cjs → chunk-PWLJ77UV.cjs} +5 -3
  154. package/dist/chunk-PWLJ77UV.cjs.map +1 -0
  155. package/dist/chunk-Q7Q4WSLJ.cjs +328 -0
  156. package/dist/chunk-Q7Q4WSLJ.cjs.map +1 -0
  157. package/dist/{chunk-BEFM74L2.js → chunk-QLRESYPU.js} +637 -493
  158. package/dist/chunk-QLRESYPU.js.map +1 -0
  159. package/dist/{chunk-SBPC5IP3.js → chunk-QWX5YA3K.js} +784 -202
  160. package/dist/chunk-QWX5YA3K.js.map +1 -0
  161. package/dist/{chunk-TCRIQMBU.js → chunk-RJS7DECT.js} +8 -9
  162. package/dist/chunk-RJS7DECT.js.map +1 -0
  163. package/dist/{chunk-6JZUSDY2.cjs → chunk-RMQLSPA2.cjs} +297 -27
  164. package/dist/chunk-RMQLSPA2.cjs.map +1 -0
  165. package/dist/{chunk-SJDMVITW.cjs → chunk-RT5ZY4XA.cjs} +6 -5
  166. package/dist/chunk-RT5ZY4XA.cjs.map +1 -0
  167. package/dist/{chunk-IJTLXNGJ.js → chunk-T4XNKYXB.js} +780 -127
  168. package/dist/chunk-T4XNKYXB.js.map +1 -0
  169. package/dist/{chunk-PDGEXGS6.cjs → chunk-TQR4KBY2.cjs} +354 -182
  170. package/dist/chunk-TQR4KBY2.cjs.map +1 -0
  171. package/dist/chunk-TTAITEPJ.cjs +755 -0
  172. package/dist/chunk-TTAITEPJ.cjs.map +1 -0
  173. package/dist/{chunk-NN3QSOVS.cjs → chunk-U5SON7R2.cjs} +27 -27
  174. package/dist/{chunk-NN3QSOVS.cjs.map → chunk-U5SON7R2.cjs.map} +1 -1
  175. package/dist/{chunk-A2I2XO52.cjs → chunk-U63GDNRC.cjs} +32 -26
  176. package/dist/chunk-U63GDNRC.cjs.map +1 -0
  177. package/dist/{chunk-YNULOIR5.cjs → chunk-UDISNXDL.cjs} +64 -43
  178. package/dist/chunk-UDISNXDL.cjs.map +1 -0
  179. package/dist/{chunk-GWEDD3DH.js → chunk-UV3SN74I.js} +5 -5
  180. package/dist/{chunk-GWEDD3DH.js.map → chunk-UV3SN74I.js.map} +1 -1
  181. package/dist/{chunk-U5W4LKZV.cjs → chunk-VCRRKBLN.cjs} +9 -9
  182. package/dist/{chunk-U5W4LKZV.cjs.map → chunk-VCRRKBLN.cjs.map} +1 -1
  183. package/dist/{chunk-EFELJVLA.js → chunk-VGTJPTIC.js} +28 -5
  184. package/dist/chunk-VGTJPTIC.js.map +1 -0
  185. package/dist/chunk-VQH4VAWD.cjs +12 -0
  186. package/dist/{chunk-EPTSMFH7.cjs.map → chunk-VQH4VAWD.cjs.map} +1 -1
  187. package/dist/{chunk-SNXVDZAJ.js → chunk-W6OG3HDG.js} +5 -4
  188. package/dist/chunk-W6OG3HDG.js.map +1 -0
  189. package/dist/chunk-WDGA7IYB.js +207 -0
  190. package/dist/chunk-WDGA7IYB.js.map +1 -0
  191. package/dist/chunk-WEVQJ5LH.js +736 -0
  192. package/dist/chunk-WEVQJ5LH.js.map +1 -0
  193. package/dist/{chunk-3PRKZW6D.cjs → chunk-XBYVV3MP.cjs} +60 -5
  194. package/dist/chunk-XBYVV3MP.cjs.map +1 -0
  195. package/dist/{chunk-GFRGG2US.cjs → chunk-XCAGZAKP.cjs} +7 -7
  196. package/dist/{chunk-GFRGG2US.cjs.map → chunk-XCAGZAKP.cjs.map} +1 -1
  197. package/dist/{chunk-XR4YZFKW.cjs → chunk-XDF2UPEQ.cjs} +3864 -1783
  198. package/dist/chunk-XDF2UPEQ.cjs.map +1 -0
  199. package/dist/{chunk-7V2FGGI2.cjs → chunk-XMQSEJCF.cjs} +632 -1080
  200. package/dist/chunk-XMQSEJCF.cjs.map +1 -0
  201. package/dist/chunk-XNLIZYRZ.cjs +3432 -0
  202. package/dist/chunk-XNLIZYRZ.cjs.map +1 -0
  203. package/dist/{chunk-66UVLHQA.cjs → chunk-XNSI2FJO.cjs} +99 -100
  204. package/dist/chunk-XNSI2FJO.cjs.map +1 -0
  205. package/dist/chunk-XQSCL77R.cjs +60 -0
  206. package/dist/chunk-XQSCL77R.cjs.map +1 -0
  207. package/dist/{chunk-SVJ5GEXW.cjs → chunk-XUO3KQFO.cjs} +2 -2
  208. package/dist/chunk-XUO3KQFO.cjs.map +1 -0
  209. package/dist/{chunk-HJH3RMXG.cjs → chunk-YAAM3M2S.cjs} +10 -10
  210. package/dist/{chunk-HJH3RMXG.cjs.map → chunk-YAAM3M2S.cjs.map} +1 -1
  211. package/dist/{chunk-ATLN63JA.js → chunk-YBFHZUXX.js} +6 -6
  212. package/dist/{chunk-ATLN63JA.js.map → chunk-YBFHZUXX.js.map} +1 -1
  213. package/dist/{chunk-K3BUWSFR.js → chunk-YDFDBE6D.js} +119 -6
  214. package/dist/chunk-YDFDBE6D.js.map +1 -0
  215. package/dist/{chunk-OSZPLZIV.cjs → chunk-YVWGEQJE.cjs} +318 -132
  216. package/dist/chunk-YVWGEQJE.cjs.map +1 -0
  217. package/dist/{chunk-QT6V3YRH.js → chunk-YWGVVALJ.js} +3 -3
  218. package/dist/{chunk-QT6V3YRH.js.map → chunk-YWGVVALJ.js.map} +1 -1
  219. package/dist/core/index.cjs +40 -41
  220. package/dist/core/index.d.cts +4 -5
  221. package/dist/core/index.d.ts +4 -5
  222. package/dist/core/index.js +8 -9
  223. package/dist/{ddl-eWg7hx6R.d.cts → ddl-BJcOp4WZ.d.cts} +3 -3
  224. package/dist/{ddl-D5369kOY.d.ts → ddl-BXfGHbPN.d.ts} +3 -3
  225. package/dist/graph-extension/index.cjs +26 -23
  226. package/dist/graph-extension/index.d.cts +16 -6
  227. package/dist/graph-extension/index.d.ts +16 -6
  228. package/dist/graph-extension/index.js +7 -8
  229. package/dist/graph-merge/index.cjs +2459 -655
  230. package/dist/graph-merge/index.cjs.map +1 -1
  231. package/dist/graph-merge/index.d.cts +170 -33
  232. package/dist/graph-merge/index.d.ts +170 -33
  233. package/dist/graph-merge/index.js +2269 -468
  234. package/dist/graph-merge/index.js.map +1 -1
  235. package/dist/{index-By89Sezh.d.ts → index-BSHvKfok.d.ts} +221 -10
  236. package/dist/{index-DcQ3Sxs-.d.cts → index-DxaYCv8Y.d.cts} +221 -10
  237. package/dist/index.cjs +330 -269
  238. package/dist/index.cjs.map +1 -1
  239. package/dist/index.d.cts +590 -576
  240. package/dist/index.d.ts +590 -576
  241. package/dist/index.js +73 -50
  242. package/dist/index.js.map +1 -1
  243. package/dist/indexes/index.cjs +17 -17
  244. package/dist/indexes/index.d.cts +4 -4
  245. package/dist/indexes/index.d.ts +4 -4
  246. package/dist/indexes/index.js +10 -10
  247. package/dist/interchange/index.cjs +165 -50
  248. package/dist/interchange/index.cjs.map +1 -1
  249. package/dist/interchange/index.d.cts +261 -16
  250. package/dist/interchange/index.d.ts +261 -16
  251. package/dist/interchange/index.js +128 -24
  252. package/dist/interchange/index.js.map +1 -1
  253. package/dist/{manager-B0KjKE93.d.ts → manager-CfZAimti.d.ts} +36 -5
  254. package/dist/{manager-Cn0NFIhN.d.cts → manager-HGk6E_HW.d.cts} +36 -5
  255. package/dist/{materialize-indexes-BD4V3svD.d.ts → materialize-indexes-6A7dWGtb.d.cts} +10 -2
  256. package/dist/{materialize-indexes-DVRhd5h4.d.cts → materialize-indexes-BMJP6Tms.d.ts} +10 -2
  257. package/dist/{postgres-DaEWvN4x.d.cts → postgres-DFYWENdR.d.cts} +1961 -439
  258. package/dist/{postgres-u0a0HN2D.d.ts → postgres-e7a9TdvR.d.ts} +1961 -439
  259. package/dist/profiler/index.cjs +15 -15
  260. package/dist/profiler/index.d.cts +9 -10
  261. package/dist/profiler/index.d.ts +9 -10
  262. package/dist/profiler/index.js +4 -4
  263. package/dist/provenance/index.cjs +46 -48
  264. package/dist/provenance/index.cjs.map +1 -1
  265. package/dist/provenance/index.d.cts +7 -7
  266. package/dist/provenance/index.d.ts +7 -7
  267. package/dist/provenance/index.js +12 -14
  268. package/dist/provenance/index.js.map +1 -1
  269. package/dist/schema/index.cjs +50 -49
  270. package/dist/schema/index.d.cts +9 -16
  271. package/dist/schema/index.d.ts +9 -16
  272. package/dist/schema/index.js +23 -22
  273. package/dist/{searchable-CnYEancP.d.ts → searchable-9OQoPuRs.d.ts} +1 -2
  274. package/dist/{searchable-BT7j9_IK.d.cts → searchable-CIje5XYD.d.cts} +1 -2
  275. package/dist/{sqlite-BrMoSsI7.d.cts → sqlite-DerU5tc7.d.ts} +2029 -347
  276. package/dist/{sqlite-CHhZUyO5.d.ts → sqlite-DitnISa9.d.cts} +2029 -347
  277. package/dist/{store-view-Bvdku0Ht.d.ts → store-DawaWWjJ.d.ts} +3145 -2556
  278. package/dist/{store-view-w-md0nQ4.d.cts → store-RwTJx8LX.d.cts} +3145 -2556
  279. package/dist/{temporal-BCORwUau.d.cts → temporal-Bn-Fi8FJ.d.cts} +1 -1
  280. package/dist/{temporal--x9T8K4S.d.ts → temporal-BtM4UALv.d.ts} +1 -1
  281. package/dist/{types-6-WJmSD4.d.cts → types-CoIx8HX5.d.cts} +1 -1
  282. package/dist/{types-Cjvkj0jA.d.ts → types-HkveCCx0.d.cts} +866 -21
  283. package/dist/{types-Cjvkj0jA.d.cts → types-HkveCCx0.d.ts} +866 -21
  284. package/dist/{types-COODtTJU.d.ts → types-KFfk-8Ah.d.ts} +1 -1
  285. package/dist/{where-CUQmCR6d.d.cts → where--fk7_0kv.d.cts} +1 -1
  286. package/dist/{where-5xVawAwL.d.ts → where-ws5hf-Ov.d.ts} +1 -1
  287. package/package.json +1 -1
  288. package/dist/chunk-2BIG7U6E.cjs +0 -83
  289. package/dist/chunk-2BIG7U6E.cjs.map +0 -1
  290. package/dist/chunk-2L54C2C2.js +0 -144
  291. package/dist/chunk-2L54C2C2.js.map +0 -1
  292. package/dist/chunk-2VLBGQBY.cjs.map +0 -1
  293. package/dist/chunk-2WDD2NO3.js +0 -59
  294. package/dist/chunk-2WDD2NO3.js.map +0 -1
  295. package/dist/chunk-2Y4IFKW7.js.map +0 -1
  296. package/dist/chunk-35S6P5ZU.js +0 -27
  297. package/dist/chunk-35S6P5ZU.js.map +0 -1
  298. package/dist/chunk-3PRKZW6D.cjs.map +0 -1
  299. package/dist/chunk-4MB3AQAQ.js.map +0 -1
  300. package/dist/chunk-4SZ6XPTG.cjs +0 -12
  301. package/dist/chunk-5MUSU4ZP.cjs.map +0 -1
  302. package/dist/chunk-63KCKSSH.js.map +0 -1
  303. package/dist/chunk-66UVLHQA.cjs.map +0 -1
  304. package/dist/chunk-6JZUSDY2.cjs.map +0 -1
  305. package/dist/chunk-764JHTLT.cjs +0 -15
  306. package/dist/chunk-764JHTLT.cjs.map +0 -1
  307. package/dist/chunk-7G32LIQM.js.map +0 -1
  308. package/dist/chunk-7V2FGGI2.cjs.map +0 -1
  309. package/dist/chunk-A2I2XO52.cjs.map +0 -1
  310. package/dist/chunk-A4PBRX4C.cjs +0 -100
  311. package/dist/chunk-A4PBRX4C.cjs.map +0 -1
  312. package/dist/chunk-ACSVZPK7.cjs.map +0 -1
  313. package/dist/chunk-ALFUGRYB.cjs +0 -1282
  314. package/dist/chunk-ALFUGRYB.cjs.map +0 -1
  315. package/dist/chunk-B75XRV3O.js +0 -125
  316. package/dist/chunk-B75XRV3O.js.map +0 -1
  317. package/dist/chunk-BCP7LLOY.js.map +0 -1
  318. package/dist/chunk-BEFM74L2.js.map +0 -1
  319. package/dist/chunk-BNUFUFAU.js.map +0 -1
  320. package/dist/chunk-C4F7VJ5D.cjs.map +0 -1
  321. package/dist/chunk-CPEL3YIR.cjs.map +0 -1
  322. package/dist/chunk-D7PG5D5K.js.map +0 -1
  323. package/dist/chunk-DI74SMXS.cjs +0 -29
  324. package/dist/chunk-DI74SMXS.cjs.map +0 -1
  325. package/dist/chunk-DK2S42XB.js +0 -77
  326. package/dist/chunk-DK2S42XB.js.map +0 -1
  327. package/dist/chunk-DRACN6XG.js +0 -27
  328. package/dist/chunk-DRACN6XG.js.map +0 -1
  329. package/dist/chunk-EE7N5XXQ.cjs.map +0 -1
  330. package/dist/chunk-EFELJVLA.js.map +0 -1
  331. package/dist/chunk-EPTSMFH7.cjs +0 -12
  332. package/dist/chunk-EQ7JKLZO.cjs +0 -157
  333. package/dist/chunk-EQ7JKLZO.cjs.map +0 -1
  334. package/dist/chunk-FJMPR3OH.cjs.map +0 -1
  335. package/dist/chunk-FMGEZBAQ.js.map +0 -1
  336. package/dist/chunk-FMMIX6N4.js.map +0 -1
  337. package/dist/chunk-FRHHDHKH.js.map +0 -1
  338. package/dist/chunk-FSXTPBRN.js.map +0 -1
  339. package/dist/chunk-G6Q5UM7U.js.map +0 -1
  340. package/dist/chunk-GYA4JRP5.js.map +0 -1
  341. package/dist/chunk-HOHAJ2NR.cjs +0 -61
  342. package/dist/chunk-HOHAJ2NR.cjs.map +0 -1
  343. package/dist/chunk-HOIFFY4M.js.map +0 -1
  344. package/dist/chunk-IIMQJYAM.js +0 -81
  345. package/dist/chunk-IIMQJYAM.js.map +0 -1
  346. package/dist/chunk-IJTLXNGJ.js.map +0 -1
  347. package/dist/chunk-ITE4IXAK.js +0 -25
  348. package/dist/chunk-ITE4IXAK.js.map +0 -1
  349. package/dist/chunk-K3BUWSFR.js.map +0 -1
  350. package/dist/chunk-KCO5EFJU.js +0 -79
  351. package/dist/chunk-KCO5EFJU.js.map +0 -1
  352. package/dist/chunk-KKYELPZ2.cjs +0 -83
  353. package/dist/chunk-KKYELPZ2.cjs.map +0 -1
  354. package/dist/chunk-MCHP7RHZ.cjs.map +0 -1
  355. package/dist/chunk-MIJKEVV7.js.map +0 -1
  356. package/dist/chunk-NCX65HBY.cjs +0 -1396
  357. package/dist/chunk-NCX65HBY.cjs.map +0 -1
  358. package/dist/chunk-OSZPLZIV.cjs.map +0 -1
  359. package/dist/chunk-OVUUTCPJ.cjs.map +0 -1
  360. package/dist/chunk-PDGEXGS6.cjs.map +0 -1
  361. package/dist/chunk-QB6VMOJ2.cjs.map +0 -1
  362. package/dist/chunk-QMQLUA66.js +0 -12
  363. package/dist/chunk-QMQLUA66.js.map +0 -1
  364. package/dist/chunk-QYWINYEA.cjs.map +0 -1
  365. package/dist/chunk-S4KQ5LV4.js.map +0 -1
  366. package/dist/chunk-SBPC5IP3.js.map +0 -1
  367. package/dist/chunk-SJDMVITW.cjs.map +0 -1
  368. package/dist/chunk-SNXVDZAJ.js.map +0 -1
  369. package/dist/chunk-SQRD2CYF.js.map +0 -1
  370. package/dist/chunk-ST3LPB2V.cjs.map +0 -1
  371. package/dist/chunk-STQ3BSED.cjs.map +0 -1
  372. package/dist/chunk-SVJ5GEXW.cjs.map +0 -1
  373. package/dist/chunk-TCRIQMBU.js.map +0 -1
  374. package/dist/chunk-TDXIBCGY.cjs.map +0 -1
  375. package/dist/chunk-TFMVL4QH.js.map +0 -1
  376. package/dist/chunk-TRF4EBJT.cjs +0 -30
  377. package/dist/chunk-TRF4EBJT.cjs.map +0 -1
  378. package/dist/chunk-TVLKA4AY.js +0 -94
  379. package/dist/chunk-TVLKA4AY.js.map +0 -1
  380. package/dist/chunk-UR7W5YQK.js.map +0 -1
  381. package/dist/chunk-VITTKBWF.js +0 -1263
  382. package/dist/chunk-VITTKBWF.js.map +0 -1
  383. package/dist/chunk-WBUFJ7BS.cjs +0 -131
  384. package/dist/chunk-WBUFJ7BS.cjs.map +0 -1
  385. package/dist/chunk-XR4YZFKW.cjs.map +0 -1
  386. package/dist/chunk-YNULOIR5.cjs.map +0 -1
  387. package/dist/chunk-ZDH3DX3C.cjs +0 -30
  388. package/dist/chunk-ZDH3DX3C.cjs.map +0 -1
  389. package/dist/chunk-ZTAJL4DT.cjs +0 -85
  390. package/dist/chunk-ZTAJL4DT.cjs.map +0 -1
  391. package/dist/define-graph-DVF-oN1i.d.cts +0 -173
  392. package/dist/define-graph-SvYXOl78.d.ts +0 -173
@@ -0,0 +1,1979 @@
1
+ 'use strict';
2
+
3
+ var chunkTTAITEPJ_cjs = require('./chunk-TTAITEPJ.cjs');
4
+ var chunkXNLIZYRZ_cjs = require('./chunk-XNLIZYRZ.cjs');
5
+ var chunkXMQSEJCF_cjs = require('./chunk-XMQSEJCF.cjs');
6
+ var chunkPWLJ77UV_cjs = require('./chunk-PWLJ77UV.cjs');
7
+ var chunkNFCVHQ5P_cjs = require('./chunk-NFCVHQ5P.cjs');
8
+ var chunkXBYVV3MP_cjs = require('./chunk-XBYVV3MP.cjs');
9
+ var chunkE4WNQBEF_cjs = require('./chunk-E4WNQBEF.cjs');
10
+ var chunkQ7Q4WSLJ_cjs = require('./chunk-Q7Q4WSLJ.cjs');
11
+ var chunk4UGOKMI5_cjs = require('./chunk-4UGOKMI5.cjs');
12
+ var chunkVCRRKBLN_cjs = require('./chunk-VCRRKBLN.cjs');
13
+ var chunkHAHNRASW_cjs = require('./chunk-HAHNRASW.cjs');
14
+ var chunkLBJKZXDE_cjs = require('./chunk-LBJKZXDE.cjs');
15
+ var chunkNI72YOJB_cjs = require('./chunk-NI72YOJB.cjs');
16
+ var chunkA7J2YDDI_cjs = require('./chunk-A7J2YDDI.cjs');
17
+ var chunkN66HCGCY_cjs = require('./chunk-N66HCGCY.cjs');
18
+
19
+ // src/store/row-mappers.ts
20
+ function nullToUndefined(value) {
21
+ return value === null ? void 0 : value;
22
+ }
23
+ function rowToNode(row) {
24
+ const rawProps = chunkXBYVV3MP_cjs.rowPropsToObject(row.props);
25
+ const props = chunkLBJKZXDE_cjs.filterReservedKeys(rawProps, chunkLBJKZXDE_cjs.RESERVED_NODE_KEYS);
26
+ return {
27
+ kind: row.kind,
28
+ id: row.id,
29
+ meta: rowToNodeMeta(row),
30
+ ...props
31
+ };
32
+ }
33
+ function rowToNodeMeta(row) {
34
+ return {
35
+ version: row.version,
36
+ validFrom: nullToUndefined(row.valid_from),
37
+ validTo: nullToUndefined(row.valid_to),
38
+ createdAt: row.created_at,
39
+ updatedAt: row.updated_at,
40
+ deletedAt: nullToUndefined(row.deleted_at)
41
+ };
42
+ }
43
+ function rowToEdge(row) {
44
+ const rawProps = chunkXBYVV3MP_cjs.rowPropsToObject(row.props);
45
+ const props = chunkLBJKZXDE_cjs.filterReservedKeys(rawProps, chunkLBJKZXDE_cjs.RESERVED_EDGE_KEYS);
46
+ return {
47
+ id: row.id,
48
+ kind: row.kind,
49
+ fromKind: row.from_kind,
50
+ fromId: row.from_id,
51
+ toKind: row.to_kind,
52
+ toId: row.to_id,
53
+ meta: rowToEdgeMeta(row),
54
+ ...props
55
+ };
56
+ }
57
+ function rowToEdgeMeta(row) {
58
+ return {
59
+ validFrom: nullToUndefined(row.valid_from),
60
+ validTo: nullToUndefined(row.valid_to),
61
+ createdAt: row.created_at,
62
+ updatedAt: row.updated_at,
63
+ deletedAt: nullToUndefined(row.deleted_at)
64
+ };
65
+ }
66
+
67
+ // src/store/constraints.ts
68
+ function edgeWriteNeedsConstraintFence(cardinality) {
69
+ return cardinality === "many" ? void 0 : "edgeCardinality";
70
+ }
71
+ function nodeWriteNeedsConstraintFence(registry, kind, uniqueConstraints, operation) {
72
+ if (operation === "create" && registry.getDisjointKinds(kind).length > 0) {
73
+ return "nodeDisjointness";
74
+ }
75
+ const sharedScope = uniqueConstraints.some(
76
+ (constraint) => chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(kind, constraint.scope, registry).length > 1
77
+ );
78
+ return sharedScope ? "nodeUniquenessScope" : void 0;
79
+ }
80
+ async function checkDisjointnessConstraint(ctx, kind, id) {
81
+ const disjointKinds = ctx.registry.getDisjointKinds(kind);
82
+ for (const disjointKind of disjointKinds) {
83
+ const existing = await ctx.backend.getNode(ctx.graphId, disjointKind, id);
84
+ if (existing && !existing.deleted_at) {
85
+ const error = chunkE4WNQBEF_cjs.checkDisjointness(id, kind, [disjointKind], ctx.registry);
86
+ if (error) throw error;
87
+ }
88
+ }
89
+ }
90
+ async function checkCardinalityConstraint(ctx, edgeKind, cardinality, fromKind, fromId, toKind, toId, validTo) {
91
+ switch (cardinality) {
92
+ case "many": {
93
+ return;
94
+ }
95
+ case "one": {
96
+ const count = await ctx.backend.countEdgesFrom({
97
+ graphId: ctx.graphId,
98
+ edgeKind,
99
+ fromKind,
100
+ fromId
101
+ });
102
+ const error = chunkE4WNQBEF_cjs.checkCardinality(
103
+ edgeKind,
104
+ fromKind,
105
+ fromId,
106
+ "one",
107
+ count,
108
+ false
109
+ );
110
+ if (error) throw error;
111
+ return;
112
+ }
113
+ case "unique": {
114
+ const exists = await ctx.backend.edgeExistsBetween({
115
+ graphId: ctx.graphId,
116
+ edgeKind,
117
+ fromKind,
118
+ fromId,
119
+ toKind,
120
+ toId
121
+ });
122
+ const error = chunkE4WNQBEF_cjs.checkUniqueEdge(
123
+ edgeKind,
124
+ fromKind,
125
+ fromId,
126
+ toKind,
127
+ toId,
128
+ exists ? 1 : 0
129
+ );
130
+ if (error) throw error;
131
+ return;
132
+ }
133
+ case "oneActive": {
134
+ if (validTo !== void 0) {
135
+ return;
136
+ }
137
+ const count = await ctx.backend.countEdgesFrom({
138
+ graphId: ctx.graphId,
139
+ edgeKind,
140
+ fromKind,
141
+ fromId,
142
+ activeOnly: true
143
+ });
144
+ const error = chunkE4WNQBEF_cjs.checkCardinality(
145
+ edgeKind,
146
+ fromKind,
147
+ fromId,
148
+ "oneActive",
149
+ count,
150
+ count > 0
151
+ );
152
+ if (error) throw error;
153
+ return;
154
+ }
155
+ }
156
+ }
157
+
158
+ // src/store/operations/already-exists.ts
159
+ var ENTITY_LABELS = {
160
+ node: { title: "Node", article: "A node" },
161
+ edge: { title: "Edge", article: "An edge" }
162
+ };
163
+ function alreadyExistsError(entity, kind, id, detail, cause) {
164
+ const label = ENTITY_LABELS[entity];
165
+ return new chunkNI72YOJB_cjs.ValidationError(
166
+ `${label.title} already exists: ${detail}`,
167
+ {
168
+ entityType: entity,
169
+ kind,
170
+ operation: "create",
171
+ ...id === void 0 ? {} : { id },
172
+ issues: [
173
+ {
174
+ path: "id",
175
+ code: chunkNI72YOJB_cjs.ENTITY_ALREADY_EXISTS_CODE,
176
+ message: `${label.article} with this ID already exists`
177
+ }
178
+ ]
179
+ },
180
+ {
181
+ suggestion: `Use a different ID or update the existing ${entity}.`,
182
+ ...cause === void 0 ? {} : { cause }
183
+ }
184
+ );
185
+ }
186
+ function createAlreadyExistsError(entity, kind, id) {
187
+ return alreadyExistsError(entity, kind, id, `${kind}/${id}`, void 0);
188
+ }
189
+ function isDuplicateKeyInsertError(error, entity) {
190
+ return error instanceof chunkNI72YOJB_cjs.DatabaseOperationError && error.details.operation === "insert" && error.details.entity === entity && error.details.reason === "duplicate_key";
191
+ }
192
+ function rethrowAsAlreadyExists(error, entity) {
193
+ if (!isDuplicateKeyInsertError(error, entity)) throw error;
194
+ const attempted = error.details.attempted ?? [];
195
+ const first = attempted[0];
196
+ if (first === void 0) throw error;
197
+ if (attempted.length === 1) {
198
+ throw alreadyExistsError(
199
+ entity,
200
+ first.kind,
201
+ first.id,
202
+ `${first.kind}/${first.id}`,
203
+ error
204
+ );
205
+ }
206
+ throw alreadyExistsError(
207
+ entity,
208
+ first.kind,
209
+ void 0,
210
+ `one of the ${attempted.length} ${first.kind} ids in the refused insert`,
211
+ error
212
+ );
213
+ }
214
+ async function withAlreadyExistsTranslation(entity, run) {
215
+ try {
216
+ return await run();
217
+ } catch (error) {
218
+ rethrowAsAlreadyExists(error, entity);
219
+ }
220
+ }
221
+
222
+ // src/store/operations/node-operations.ts
223
+ function getNodeRegistration(graph, kind) {
224
+ if (!chunkN66HCGCY_cjs.hasOwnKey(graph.nodes, kind)) throw new chunkNI72YOJB_cjs.KindNotFoundError(kind, "node");
225
+ const registration = graph.nodes[kind];
226
+ if (registration === void 0) throw new chunkNI72YOJB_cjs.KindNotFoundError(kind, "node");
227
+ return registration;
228
+ }
229
+ function nodeFencesConstraintProbe(ctx, kind, operation) {
230
+ if (!chunkN66HCGCY_cjs.hasOwnKey(ctx.graph.nodes, kind)) return void 0;
231
+ return nodeWriteNeedsConstraintFence(
232
+ ctx.registry,
233
+ kind,
234
+ getNodeRegistration(ctx.graph, kind).unique ?? [],
235
+ operation
236
+ );
237
+ }
238
+ function nodeBatchFencesConstraintProbe(ctx, inputs, operation) {
239
+ for (const input of inputs) {
240
+ const reason = nodeFencesConstraintProbe(ctx, input.kind, operation);
241
+ if (reason !== void 0) return reason;
242
+ }
243
+ return void 0;
244
+ }
245
+ function buildNodeCacheKey(graphId, kind, id) {
246
+ return chunkXNLIZYRZ_cjs.encodeTupleKey([graphId, kind, id]);
247
+ }
248
+ function buildUniqueCacheKey(graphId, nodeKind, constraintName, key) {
249
+ return chunkXNLIZYRZ_cjs.encodeTupleKey([graphId, nodeKind, constraintName, key]);
250
+ }
251
+ function buildInsertNodeParams(graphId, kind, id, props, validFrom, validTo) {
252
+ const insertParams = {
253
+ graphId,
254
+ kind,
255
+ id,
256
+ props
257
+ };
258
+ if (validFrom !== void 0) insertParams.validFrom = validFrom;
259
+ if (validTo !== void 0) insertParams.validTo = validTo;
260
+ return insertParams;
261
+ }
262
+ function createPendingUniqueRow(graphId, nodeKind, constraintName, key, nodeId) {
263
+ return {
264
+ graph_id: graphId,
265
+ node_kind: nodeKind,
266
+ constraint_name: constraintName,
267
+ key,
268
+ node_id: nodeId,
269
+ concrete_kind: nodeKind,
270
+ deleted_at: void 0
271
+ };
272
+ }
273
+ function resolveConstraint(graph, kind, constraintName) {
274
+ const registration = getNodeRegistration(graph, kind);
275
+ const constraints = registration.unique ?? [];
276
+ const constraint = constraints.find(
277
+ (candidate) => candidate.name === constraintName
278
+ );
279
+ if (constraint === void 0) {
280
+ throw new chunkNI72YOJB_cjs.NodeConstraintNotFoundError(constraintName, kind);
281
+ }
282
+ return constraint;
283
+ }
284
+ function createNodeBatchValidationBackend(graphId, registry, backend) {
285
+ const nodeCache = /* @__PURE__ */ new Map();
286
+ const pendingNodes = /* @__PURE__ */ new Map();
287
+ const uniqueCache = /* @__PURE__ */ new Map();
288
+ const pendingUniqueOwners = /* @__PURE__ */ new Map();
289
+ async function getNodeCached(lookupGraphId, kind, id) {
290
+ const cacheKey = buildNodeCacheKey(lookupGraphId, kind, id);
291
+ const pendingNode = pendingNodes.get(cacheKey);
292
+ if (pendingNode !== void 0) return pendingNode;
293
+ if (nodeCache.has(cacheKey)) return nodeCache.get(cacheKey);
294
+ const existing = await backend.getNode(lookupGraphId, kind, id);
295
+ nodeCache.set(cacheKey, existing);
296
+ return existing;
297
+ }
298
+ async function checkUniqueCached(params) {
299
+ const cacheKey = buildUniqueCacheKey(
300
+ params.graphId,
301
+ params.nodeKind,
302
+ params.constraintName,
303
+ params.key
304
+ );
305
+ const pendingOwner = pendingUniqueOwners.get(cacheKey);
306
+ if (pendingOwner !== void 0) {
307
+ return createPendingUniqueRow(
308
+ params.graphId,
309
+ params.nodeKind,
310
+ params.constraintName,
311
+ params.key,
312
+ pendingOwner
313
+ );
314
+ }
315
+ if (uniqueCache.has(cacheKey)) return uniqueCache.get(cacheKey);
316
+ const existing = await backend.checkUnique(params);
317
+ uniqueCache.set(cacheKey, existing);
318
+ return existing;
319
+ }
320
+ function registerPendingNode(params) {
321
+ const cacheKey = buildNodeCacheKey(params.graphId, params.kind, params.id);
322
+ pendingNodes.set(cacheKey, {
323
+ graph_id: params.graphId,
324
+ kind: params.kind,
325
+ id: params.id,
326
+ props: JSON.stringify(params.props),
327
+ version: 1,
328
+ // The simulated cached row only needs a NodeRow-shaped valid_from
329
+ // (string | undefined, never null) for existence/uniqueness checks,
330
+ // which don't inspect its value — normalize import's explicit-NULL
331
+ // sentinel away rather than widen this cache's row shape.
332
+ valid_from: params.validFrom ?? void 0,
333
+ valid_to: params.validTo,
334
+ created_at: "",
335
+ updated_at: "",
336
+ deleted_at: void 0
337
+ });
338
+ }
339
+ function registerPendingUniqueEntries(kind, id, props, constraints) {
340
+ for (const constraint of constraints) {
341
+ if (!chunkE4WNQBEF_cjs.checkWherePredicate(constraint, props)) continue;
342
+ const key = chunkE4WNQBEF_cjs.computeUniqueKey(
343
+ props,
344
+ constraint.fields,
345
+ constraint.collation
346
+ );
347
+ const concreteEntryKey = buildUniqueCacheKey(
348
+ graphId,
349
+ kind,
350
+ constraint.name,
351
+ key
352
+ );
353
+ pendingUniqueOwners.set(concreteEntryKey, id);
354
+ if (constraint.scope !== "kind") {
355
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
356
+ kind,
357
+ constraint.scope,
358
+ registry
359
+ );
360
+ for (const kindToCheck of kindsToCheck) {
361
+ const inheritedEntryKey = buildUniqueCacheKey(
362
+ graphId,
363
+ kindToCheck,
364
+ constraint.name,
365
+ key
366
+ );
367
+ pendingUniqueOwners.set(inheritedEntryKey, id);
368
+ }
369
+ }
370
+ }
371
+ }
372
+ function registerAppliedNodeUpdate(kind, id, oldProps, newProps, constraints) {
373
+ for (const constraint of constraints) {
374
+ const oldApplies = chunkE4WNQBEF_cjs.checkWherePredicate(constraint, oldProps);
375
+ const newApplies = chunkE4WNQBEF_cjs.checkWherePredicate(constraint, newProps);
376
+ const oldKey = oldApplies ? chunkE4WNQBEF_cjs.computeUniqueKey(oldProps, constraint.fields, constraint.collation) : void 0;
377
+ const newKey = newApplies ? chunkE4WNQBEF_cjs.computeUniqueKey(newProps, constraint.fields, constraint.collation) : void 0;
378
+ if (oldKey === newKey) continue;
379
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
380
+ kind,
381
+ constraint.scope,
382
+ registry
383
+ );
384
+ if (oldKey !== void 0) {
385
+ for (const kindToCheck of kindsToCheck) {
386
+ const cacheKey = buildUniqueCacheKey(
387
+ graphId,
388
+ kindToCheck,
389
+ constraint.name,
390
+ oldKey
391
+ );
392
+ pendingUniqueOwners.delete(cacheKey);
393
+ uniqueCache.set(cacheKey, void 0);
394
+ }
395
+ }
396
+ if (newKey !== void 0) {
397
+ for (const kindToCheck of kindsToCheck) {
398
+ const cacheKey = buildUniqueCacheKey(
399
+ graphId,
400
+ kindToCheck,
401
+ constraint.name,
402
+ newKey
403
+ );
404
+ pendingUniqueOwners.set(cacheKey, id);
405
+ }
406
+ }
407
+ }
408
+ }
409
+ function seedNodeRow(kind, id, row) {
410
+ const cacheKey = buildNodeCacheKey(graphId, kind, id);
411
+ if (nodeCache.has(cacheKey)) return;
412
+ nodeCache.set(cacheKey, row);
413
+ }
414
+ function seedUniqueRow(kind, constraintName, key, row) {
415
+ const cacheKey = buildUniqueCacheKey(graphId, kind, constraintName, key);
416
+ if (uniqueCache.has(cacheKey)) return;
417
+ uniqueCache.set(cacheKey, row);
418
+ }
419
+ const validationBackend = chunkXBYVV3MP_cjs.createBackendOverlay(backend, {
420
+ getNode: getNodeCached,
421
+ checkUnique: checkUniqueCached
422
+ });
423
+ return {
424
+ backend: validationBackend,
425
+ registerPendingNode,
426
+ registerPendingUniqueEntries,
427
+ registerAppliedNodeUpdate,
428
+ seedNodeRow,
429
+ seedUniqueRow
430
+ };
431
+ }
432
+ function draftNodeCreate(ctx, input, id, options) {
433
+ const kind = input.kind;
434
+ const registration = getNodeRegistration(ctx.graph, kind);
435
+ const nodeKind = registration.type;
436
+ const validatedProps = options?.propsPreValidated === true ? input.props : chunkXNLIZYRZ_cjs.validateNodeProps(nodeKind.schema, input.props, {
437
+ kind,
438
+ operation: "create"
439
+ });
440
+ const validFrom = chunkQ7Q4WSLJ_cjs.validateOptionalCanonicalIsoDate(
441
+ input.validFrom,
442
+ "validFrom"
443
+ );
444
+ const validTo = chunkQ7Q4WSLJ_cjs.validateOptionalCanonicalIsoDate(input.validTo, "validTo");
445
+ chunkQ7Q4WSLJ_cjs.assertOrderedValidityWindow(`${kind} "${id}"`, validFrom, validTo);
446
+ return {
447
+ kind,
448
+ id,
449
+ idProvided: input.id !== void 0,
450
+ nodeKind,
451
+ uniqueConstraints: registration.unique ?? [],
452
+ validatedProps,
453
+ validFrom,
454
+ validTo
455
+ };
456
+ }
457
+ async function finishNodeCreatePreparation(ctx, draft, backend) {
458
+ const { kind, id, validatedProps, uniqueConstraints } = draft;
459
+ const existingNode = await backend.getNode(ctx.graphId, kind, id);
460
+ if (existingNode && !existingNode.deleted_at) {
461
+ throw createAlreadyExistsError("node", kind, id);
462
+ }
463
+ const constraintContext = {
464
+ graphId: ctx.graphId,
465
+ registry: ctx.registry,
466
+ backend
467
+ };
468
+ await checkDisjointnessConstraint(constraintContext, kind, id);
469
+ await chunkTTAITEPJ_cjs.checkUniquenessConstraints(
470
+ chunkTTAITEPJ_cjs.createUniquenessContext(ctx.graphId, ctx.registry, backend),
471
+ kind,
472
+ id,
473
+ validatedProps,
474
+ uniqueConstraints
475
+ );
476
+ return {
477
+ kind,
478
+ id,
479
+ idProvided: draft.idProvided,
480
+ tombstone: existingNode,
481
+ nodeKind: draft.nodeKind,
482
+ validatedProps,
483
+ uniqueConstraints,
484
+ insertParams: buildInsertNodeParams(
485
+ ctx.graphId,
486
+ kind,
487
+ id,
488
+ validatedProps,
489
+ draft.validFrom,
490
+ draft.validTo
491
+ )
492
+ };
493
+ }
494
+ async function validateAndPrepareNodeCreate(ctx, input, id, backend, options) {
495
+ return finishNodeCreatePreparation(
496
+ ctx,
497
+ draftNodeCreate(ctx, input, id, options),
498
+ backend
499
+ );
500
+ }
501
+ async function finalizeNodeCreateBatch(ctx, preparedCreates, backend, lock) {
502
+ await chunkTTAITEPJ_cjs.applyNodeInsertSideEffectsBatch(
503
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
504
+ preparedCreates.map((prepared) => ({
505
+ kind: prepared.kind,
506
+ id: prepared.id,
507
+ schema: prepared.nodeKind.schema,
508
+ props: prepared.validatedProps,
509
+ uniqueConstraints: prepared.uniqueConstraints
510
+ })),
511
+ backend
512
+ );
513
+ }
514
+ function foldReferences(preparedCreates) {
515
+ return preparedCreates.filter((prepared) => prepared.idProvided).map((prepared) => ({ kind: prepared.kind, id: prepared.id }));
516
+ }
517
+ async function finalizeNodeCreate(ctx, prepared, backend, lock) {
518
+ await chunkTTAITEPJ_cjs.applyNodeInsertSideEffects(
519
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
520
+ {
521
+ kind: prepared.kind,
522
+ id: prepared.id,
523
+ schema: prepared.nodeKind.schema,
524
+ props: prepared.validatedProps,
525
+ uniqueConstraints: prepared.uniqueConstraints
526
+ },
527
+ backend
528
+ );
529
+ }
530
+ function computeNodeUpdate(ctx, kind, id, existingProps, inputProps) {
531
+ const registration = getNodeRegistration(ctx.graph, kind);
532
+ const validatedProps = chunkXNLIZYRZ_cjs.validateNodeProps(
533
+ registration.type.schema,
534
+ { ...existingProps, ...inputProps },
535
+ { kind, operation: "update", id }
536
+ );
537
+ return { registration, validatedProps };
538
+ }
539
+ function resolveNodeUpdateProps(ctx, existing, inputProps) {
540
+ const existingProps = chunkXBYVV3MP_cjs.rowPropsToObject(existing.props);
541
+ const { registration, validatedProps } = computeNodeUpdate(
542
+ ctx,
543
+ existing.kind,
544
+ existing.id,
545
+ existingProps,
546
+ inputProps
547
+ );
548
+ return { registration, existingProps, validatedProps };
549
+ }
550
+ function nodeUpsertDirtyCheck(ctx, kind, id, existingProps, inputProps) {
551
+ const { validatedProps } = computeNodeUpdate(
552
+ ctx,
553
+ kind,
554
+ id,
555
+ existingProps,
556
+ inputProps
557
+ );
558
+ return {
559
+ validatedProps,
560
+ unchanged: chunkPWLJ77UV_cjs.canonicalEqual(validatedProps, existingProps)
561
+ };
562
+ }
563
+ async function performNodeUpdate(ctx, input, backend, lock, options) {
564
+ const { kind, id } = input;
565
+ const existing = await backend.getNode(ctx.graphId, kind, id);
566
+ if (!existing) throw new chunkNI72YOJB_cjs.NodeNotFoundError(kind, id);
567
+ const { registration, validatedProps } = resolveNodeUpdateProps(
568
+ ctx,
569
+ existing,
570
+ input.props
571
+ );
572
+ const nodeKind = registration.type;
573
+ const validFrom = chunkQ7Q4WSLJ_cjs.validateOptionalCanonicalIsoDate(
574
+ input.validFrom,
575
+ "validFrom"
576
+ );
577
+ const validTo = chunkQ7Q4WSLJ_cjs.validateOptionalCanonicalIsoDate(input.validTo, "validTo");
578
+ const resurrectionInstant = options?.clearDeleted === true && existing.deleted_at !== void 0 ? chunkQ7Q4WSLJ_cjs.nowIso() : void 0;
579
+ const windowVerdict = chunkQ7Q4WSLJ_cjs.assertWritableValidityWindow(
580
+ `${kind} "${id}"`,
581
+ validFrom,
582
+ resurrectionInstant === void 0 ? {
583
+ effectiveValidFrom: existing.valid_from,
584
+ appliesStatedValidFrom: false,
585
+ effectiveBoundIsStored: true
586
+ } : {
587
+ effectiveValidFrom: resurrectionInstant,
588
+ appliesStatedValidFrom: true,
589
+ // The instant this write is about to stamp, not a bound the row holds.
590
+ effectiveBoundIsStored: false
591
+ },
592
+ validTo
593
+ );
594
+ const writeContext = chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock);
595
+ const effectiveValidFrom = validFrom ?? resurrectionInstant;
596
+ const shared = {
597
+ schema: nodeKind.schema,
598
+ validatedProps,
599
+ uniqueConstraints: registration.unique ?? [],
600
+ ...effectiveValidFrom !== void 0 && { validFrom: effectiveValidFrom },
601
+ ...validTo !== void 0 && { validTo },
602
+ // The bound the verdict above READ, carried into the UPDATE's own `WHERE`
603
+ // so the row this writes is the row that was judged. The verdict hands over
604
+ // the predicate rather than a flag, so both conditions that decide it — did
605
+ // the verdict consult the effective bound, and WAS that bound the row's
606
+ // stored one — are answered where they are known. A plain
607
+ // `update({ props })` states no window, reads no bound, and stays unfenced:
608
+ // the same rule `UpdateEdgeParams`'s identity components follow, for the
609
+ // same reason. The resurrecting leg is judged against `resurrectionInstant`
610
+ // and so fences on `deleted_at IS NOT NULL` alone, converging through the
611
+ // recovery below.
612
+ ...windowVerdict.storedLowerBoundFence
613
+ };
614
+ if (options?.clearDeleted) {
615
+ const row2 = await chunkTTAITEPJ_cjs.applyNodeUpdate(
616
+ writeContext,
617
+ { ...shared, existing, clearDeleted: true },
618
+ backend
619
+ );
620
+ return rowToNode(row2);
621
+ }
622
+ if (!chunkXBYVV3MP_cjs.isLiveNodeRow(existing)) throw new chunkNI72YOJB_cjs.NodeNotFoundError(kind, id);
623
+ const row = await chunkTTAITEPJ_cjs.applyNodeUpdate(
624
+ writeContext,
625
+ { ...shared, existing },
626
+ backend
627
+ );
628
+ return rowToNode(row);
629
+ }
630
+ var NODE_UPDATE_ATTEMPTS = 2;
631
+ async function performNodeUpdateWithResurrectionRecovery(ctx, input, target, lock, options) {
632
+ for (let attempt = 1; attempt <= NODE_UPDATE_ATTEMPTS; attempt += 1) {
633
+ try {
634
+ return await performNodeUpdate(
635
+ ctx,
636
+ input,
637
+ target,
638
+ lock,
639
+ attempt === 1 ? options : void 0
640
+ );
641
+ } catch (error) {
642
+ if (!isNodeUpdateNoRowError(error) || attempt === NODE_UPDATE_ATTEMPTS) {
643
+ throw nodeUpdateRaceError(input, error);
644
+ }
645
+ const current = await target.getNode(ctx.graphId, input.kind, input.id);
646
+ if (current === void 0 || current.deleted_at !== void 0) {
647
+ throw new chunkNI72YOJB_cjs.NodeNotFoundError(input.kind, input.id);
648
+ }
649
+ }
650
+ }
651
+ throw new chunkNI72YOJB_cjs.NodeNotFoundError(input.kind, input.id);
652
+ }
653
+ function nodeUpdateRaceError(input, error) {
654
+ if (!isNodeUpdateNoRowError(error)) return error;
655
+ return new chunkNI72YOJB_cjs.DatabaseOperationError(
656
+ `Node update for ${input.kind} "${input.id}" could not be applied to a stable row after ${NODE_UPDATE_ATTEMPTS} attempts: the row was removed and recreated between each read and its write. A concurrent writer is replacing this node faster than it can be read; serialize the writers, or retry.`,
657
+ {
658
+ operation: "update",
659
+ entity: "node",
660
+ attempted: [{ kind: input.kind, id: input.id }]
661
+ },
662
+ { cause: error }
663
+ );
664
+ }
665
+ async function primeBatchValidationCaches(ctx, drafts, backend, seams) {
666
+ if (backend.getNodes !== void 0) {
667
+ const idsByKind = /* @__PURE__ */ new Map();
668
+ for (const draft of drafts) {
669
+ const ids = idsByKind.get(draft.kind) ?? /* @__PURE__ */ new Set();
670
+ ids.add(draft.id);
671
+ idsByKind.set(draft.kind, ids);
672
+ }
673
+ for (const [kind, ids] of idsByKind) {
674
+ const orderedIds = [...ids];
675
+ const rows = await backend.getNodes(ctx.graphId, kind, orderedIds);
676
+ const rowsById = new Map(rows.map((row) => [row.id, row]));
677
+ for (const id of orderedIds) {
678
+ seams.seedNodeRow(kind, id, rowsById.get(id));
679
+ }
680
+ }
681
+ }
682
+ if (backend.checkUniqueBatch !== void 0) {
683
+ const groups = /* @__PURE__ */ new Map();
684
+ for (const draft of drafts) {
685
+ for (const constraint of draft.uniqueConstraints) {
686
+ if (!chunkE4WNQBEF_cjs.checkWherePredicate(constraint, draft.validatedProps)) continue;
687
+ const key = chunkE4WNQBEF_cjs.computeUniqueKey(
688
+ draft.validatedProps,
689
+ constraint.fields,
690
+ constraint.collation
691
+ );
692
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
693
+ draft.kind,
694
+ constraint.scope,
695
+ ctx.registry
696
+ );
697
+ for (const kindToCheck of kindsToCheck) {
698
+ const groupKey = chunkXNLIZYRZ_cjs.encodeTupleKey([kindToCheck, constraint.name]);
699
+ const group = groups.get(groupKey) ?? {
700
+ nodeKind: kindToCheck,
701
+ constraintName: constraint.name,
702
+ keys: /* @__PURE__ */ new Set()
703
+ };
704
+ group.keys.add(key);
705
+ groups.set(groupKey, group);
706
+ }
707
+ }
708
+ }
709
+ for (const group of groups.values()) {
710
+ const orderedKeys = [...group.keys];
711
+ const rows = await backend.checkUniqueBatch({
712
+ graphId: ctx.graphId,
713
+ nodeKind: group.nodeKind,
714
+ constraintName: group.constraintName,
715
+ keys: orderedKeys
716
+ });
717
+ const rowsByKey = new Map(rows.map((row) => [row.key, row]));
718
+ for (const key of orderedKeys) {
719
+ seams.seedUniqueRow(
720
+ group.nodeKind,
721
+ group.constraintName,
722
+ key,
723
+ rowsByKey.get(key)
724
+ );
725
+ }
726
+ }
727
+ }
728
+ }
729
+ async function prepareBatchCreates(ctx, inputs, backend, options) {
730
+ const {
731
+ backend: validationBackend,
732
+ registerPendingNode,
733
+ registerPendingUniqueEntries,
734
+ seedNodeRow,
735
+ seedUniqueRow
736
+ } = createNodeBatchValidationBackend(ctx.graphId, ctx.registry, backend);
737
+ const drafts = inputs.map(
738
+ (input) => draftNodeCreate(ctx, input, input.id ?? chunkXMQSEJCF_cjs.generateId(), options)
739
+ );
740
+ await primeBatchValidationCaches(ctx, drafts, backend, {
741
+ seedNodeRow,
742
+ seedUniqueRow
743
+ });
744
+ const preparedCreates = [];
745
+ for (const draft of drafts) {
746
+ const prepared = await finishNodeCreatePreparation(
747
+ ctx,
748
+ draft,
749
+ validationBackend
750
+ );
751
+ preparedCreates.push(prepared);
752
+ registerPendingNode(prepared.insertParams);
753
+ registerPendingUniqueEntries(
754
+ prepared.kind,
755
+ prepared.id,
756
+ prepared.validatedProps,
757
+ prepared.uniqueConstraints
758
+ );
759
+ }
760
+ return preparedCreates;
761
+ }
762
+ function partitionCreates(preparedCreates) {
763
+ const inserts = [];
764
+ const resurrections = [];
765
+ for (const prepared of preparedCreates) {
766
+ if (prepared.tombstone === void 0) {
767
+ inserts.push(prepared);
768
+ } else {
769
+ resurrections.push(prepared);
770
+ }
771
+ }
772
+ return { inserts, resurrections };
773
+ }
774
+ function isNodeUpdateNoRowError(error) {
775
+ return error instanceof chunkNI72YOJB_cjs.DatabaseOperationError && error.details.operation === "update" && error.details.entity === "node" && error.details.reason === "no_row_returned";
776
+ }
777
+ async function resurrectPreparedNode(ctx, target, lock, prepared) {
778
+ const current = await target.getNode(ctx.graphId, prepared.kind, prepared.id);
779
+ if (current === void 0) {
780
+ throw new chunkNI72YOJB_cjs.DatabaseOperationError(
781
+ `Node tombstone disappeared before resurrection: ${prepared.kind} ${prepared.id}`,
782
+ { operation: "update", entity: "node" }
783
+ );
784
+ }
785
+ if (current.deleted_at === void 0) {
786
+ throw createAlreadyExistsError("node", prepared.kind, prepared.id);
787
+ }
788
+ try {
789
+ return await chunkTTAITEPJ_cjs.applyNodeUpdate(
790
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
791
+ {
792
+ existing: current,
793
+ clearDeleted: true,
794
+ schema: prepared.nodeKind.schema,
795
+ validatedProps: prepared.validatedProps,
796
+ uniqueConstraints: prepared.uniqueConstraints,
797
+ ...prepared.insertParams.validFrom === void 0 ? {} : { validFrom: prepared.insertParams.validFrom },
798
+ ...prepared.insertParams.validTo === void 0 ? {} : { validTo: prepared.insertParams.validTo }
799
+ },
800
+ target
801
+ );
802
+ } catch (error) {
803
+ if (!isNodeUpdateNoRowError(error)) throw error;
804
+ const afterFailure = await target.getNode(
805
+ ctx.graphId,
806
+ prepared.kind,
807
+ prepared.id
808
+ );
809
+ if (afterFailure !== void 0 && afterFailure.deleted_at === void 0) {
810
+ throw createAlreadyExistsError("node", prepared.kind, prepared.id);
811
+ }
812
+ throw error;
813
+ }
814
+ }
815
+ async function findUniqueRowAcrossKinds(backend, graphId, constraintName, key, kindsToCheck, includeDeleted) {
816
+ for (const kindToCheck of kindsToCheck) {
817
+ const row = await backend.checkUnique({
818
+ graphId,
819
+ nodeKind: kindToCheck,
820
+ constraintName,
821
+ key,
822
+ includeDeleted
823
+ });
824
+ if (row !== void 0) return row;
825
+ }
826
+ return void 0;
827
+ }
828
+ async function batchCheckUniqueAcrossKinds(backend, graphId, constraintName, uniqueKeys, kindsToCheck, includeDeleted) {
829
+ const existingByKey = /* @__PURE__ */ new Map();
830
+ for (const kindToCheck of kindsToCheck) {
831
+ if (backend.checkUniqueBatch === void 0) {
832
+ for (const key of uniqueKeys) {
833
+ if (existingByKey.has(key)) continue;
834
+ const row = await backend.checkUnique({
835
+ graphId,
836
+ nodeKind: kindToCheck,
837
+ constraintName,
838
+ key,
839
+ includeDeleted
840
+ });
841
+ if (row !== void 0) {
842
+ existingByKey.set(row.key, row);
843
+ }
844
+ }
845
+ } else {
846
+ const rows = await backend.checkUniqueBatch({
847
+ graphId,
848
+ nodeKind: kindToCheck,
849
+ constraintName,
850
+ keys: uniqueKeys,
851
+ includeDeleted
852
+ });
853
+ for (const row of rows) {
854
+ if (!existingByKey.has(row.key)) {
855
+ existingByKey.set(row.key, row);
856
+ }
857
+ }
858
+ }
859
+ }
860
+ return existingByKey;
861
+ }
862
+ async function executeNodeCreateInternal(ctx, input, backend, options) {
863
+ const kind = input.kind;
864
+ const id = input.id ?? chunkXMQSEJCF_cjs.generateId();
865
+ const opContext = ctx.createOperationContext("create", "node", kind, id);
866
+ const shouldReturnRow = options?.returnRow ?? true;
867
+ return chunkXNLIZYRZ_cjs.runHookedWriteOperation(
868
+ ctx,
869
+ opContext,
870
+ backend,
871
+ async (target, lock) => {
872
+ const identity = ctx.identity;
873
+ if (identity !== void 0) await identity.lock(target);
874
+ const prepared = await validateAndPrepareNodeCreate(
875
+ ctx,
876
+ input,
877
+ id,
878
+ target,
879
+ options
880
+ );
881
+ const existing = prepared.tombstone;
882
+ if (existing !== void 0) {
883
+ const resurrected = await resurrectPreparedNode(
884
+ ctx,
885
+ target,
886
+ lock,
887
+ prepared
888
+ );
889
+ if (identity !== void 0) {
890
+ await identity.foldCreated(target, foldReferences([prepared]));
891
+ }
892
+ return shouldReturnRow ? rowToNode(resurrected) : void 0;
893
+ }
894
+ const row = await withAlreadyExistsTranslation("node", async () => {
895
+ if (shouldReturnRow) return target.insertNode(prepared.insertParams);
896
+ await chunkXMQSEJCF_cjs.runInsertNoReturn(
897
+ chunkXMQSEJCF_cjs.nodeInsertDispatch(target),
898
+ prepared.insertParams
899
+ );
900
+ return;
901
+ });
902
+ await finalizeNodeCreate(ctx, prepared, target, lock);
903
+ if (identity !== void 0) {
904
+ await identity.foldCreated(target, foldReferences([prepared]));
905
+ }
906
+ if (row === void 0) return;
907
+ return rowToNode(row);
908
+ },
909
+ {
910
+ fencesConstraintProbe: nodeFencesConstraintProbe(ctx, kind, "create")
911
+ }
912
+ );
913
+ }
914
+ async function executeNodeCreate(ctx, input, backend, options) {
915
+ const result = await executeNodeCreateInternal(ctx, input, backend, {
916
+ returnRow: true,
917
+ ...options
918
+ });
919
+ if (!result) {
920
+ throw new chunkNI72YOJB_cjs.DatabaseOperationError(
921
+ "Node create failed: expected created node row",
922
+ { operation: "insert", entity: "node" }
923
+ );
924
+ }
925
+ return result;
926
+ }
927
+ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
928
+ if (inputs.length === 0) return;
929
+ await chunkXNLIZYRZ_cjs.runInWriteTransaction(
930
+ ctx,
931
+ backend,
932
+ async (target, lock) => {
933
+ const identity = ctx.identity;
934
+ if (identity !== void 0) await identity.lock(target);
935
+ const preparedCreates = await prepareBatchCreates(ctx, inputs, target);
936
+ const partition = partitionCreates(preparedCreates);
937
+ await withAlreadyExistsTranslation(
938
+ "node",
939
+ () => chunkXMQSEJCF_cjs.runInsertBatch(
940
+ chunkXMQSEJCF_cjs.nodeInsertDispatch(target),
941
+ partition.inserts.map((prepared) => prepared.insertParams)
942
+ )
943
+ );
944
+ for (const prepared of partition.resurrections) {
945
+ await resurrectPreparedNode(ctx, target, lock, prepared);
946
+ }
947
+ await finalizeNodeCreateBatch(ctx, partition.inserts, target, lock);
948
+ if (identity !== void 0) {
949
+ await identity.foldCreated(target, foldReferences(preparedCreates));
950
+ }
951
+ },
952
+ {
953
+ fencesConstraintProbe: nodeBatchFencesConstraintProbe(
954
+ ctx,
955
+ inputs,
956
+ "create"
957
+ )
958
+ }
959
+ );
960
+ }
961
+ async function executeNodeCreateBatch(ctx, inputs, backend, options) {
962
+ if (inputs.length === 0) return [];
963
+ return chunkXNLIZYRZ_cjs.runInWriteTransaction(
964
+ ctx,
965
+ backend,
966
+ async (target, lock) => {
967
+ const identity = ctx.identity;
968
+ if (identity !== void 0) await identity.lock(target);
969
+ const preparedCreates = await prepareBatchCreates(
970
+ ctx,
971
+ inputs,
972
+ target,
973
+ options
974
+ );
975
+ const partition = partitionCreates(preparedCreates);
976
+ const inserted = await withAlreadyExistsTranslation(
977
+ "node",
978
+ () => chunkXMQSEJCF_cjs.runInsertBatchReturning(
979
+ chunkXMQSEJCF_cjs.nodeInsertDispatch(target),
980
+ partition.inserts.map((prepared) => prepared.insertParams)
981
+ )
982
+ );
983
+ const resurrected = [];
984
+ for (const prepared of partition.resurrections) {
985
+ resurrected.push(
986
+ await resurrectPreparedNode(ctx, target, lock, prepared)
987
+ );
988
+ }
989
+ await finalizeNodeCreateBatch(ctx, partition.inserts, target, lock);
990
+ const byReference = new Map(
991
+ [...inserted, ...resurrected].map((row) => [
992
+ chunkXNLIZYRZ_cjs.refKey({ kind: row.kind, id: row.id }),
993
+ row
994
+ ])
995
+ );
996
+ const rows = preparedCreates.map(
997
+ (prepared) => chunkN66HCGCY_cjs.requireDefined(
998
+ byReference.get(chunkXNLIZYRZ_cjs.refKey({ kind: prepared.kind, id: prepared.id })),
999
+ `Missing written row for ${prepared.kind} ${prepared.id}`
1000
+ )
1001
+ );
1002
+ if (identity !== void 0) {
1003
+ await identity.foldCreated(target, foldReferences(preparedCreates));
1004
+ }
1005
+ return rows.map((row) => rowToNode(row));
1006
+ },
1007
+ {
1008
+ fencesConstraintProbe: nodeBatchFencesConstraintProbe(
1009
+ ctx,
1010
+ inputs,
1011
+ "create"
1012
+ )
1013
+ }
1014
+ );
1015
+ }
1016
+ async function executeNodeUpdate(ctx, input, backend, options) {
1017
+ const opContext = ctx.createOperationContext(
1018
+ "update",
1019
+ "node",
1020
+ input.kind,
1021
+ input.id
1022
+ );
1023
+ return chunkXNLIZYRZ_cjs.runHookedWriteOperation(
1024
+ ctx,
1025
+ opContext,
1026
+ backend,
1027
+ async (target, lock) => {
1028
+ const identity = ctx.identity;
1029
+ if (options?.clearDeleted && identity !== void 0) {
1030
+ await identity.lock(target);
1031
+ }
1032
+ const node = await performNodeUpdateWithResurrectionRecovery(
1033
+ ctx,
1034
+ input,
1035
+ target,
1036
+ lock,
1037
+ options
1038
+ );
1039
+ if (options?.clearDeleted && identity !== void 0) {
1040
+ await identity.foldCreated(target, [
1041
+ { kind: input.kind, id: input.id }
1042
+ ]);
1043
+ }
1044
+ return node;
1045
+ },
1046
+ {
1047
+ fencesConstraintProbe: nodeFencesConstraintProbe(
1048
+ ctx,
1049
+ input.kind,
1050
+ "update"
1051
+ )
1052
+ }
1053
+ );
1054
+ }
1055
+ async function executeNodeUpdateWhere(ctx, kind, inputPatch, candidateIds, candidateIdColumn, backend) {
1056
+ const registration = getNodeRegistration(ctx.graph, kind);
1057
+ const schema = registration.type.schema;
1058
+ const uniqueConstraints = registration.unique ?? [];
1059
+ if (!backend.capabilities.transactions) {
1060
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1061
+ "updateWhere() requires a transactional backend so validation and sidecars are atomic",
1062
+ { code: "SET_UPDATE_TRANSACTIONS_REQUIRED", kind }
1063
+ );
1064
+ }
1065
+ if (backend.updateNodeSet === void 0) {
1066
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1067
+ "This backend does not support set-based node updates",
1068
+ { code: "SET_UPDATE_UNSUPPORTED", kind }
1069
+ );
1070
+ }
1071
+ if (Object.keys(inputPatch).length === 0) {
1072
+ throw new chunkNI72YOJB_cjs.ValidationError("updateWhere() patch must not be empty", {
1073
+ entityType: "node",
1074
+ kind,
1075
+ operation: "update",
1076
+ issues: [{ path: "patch", message: "Provide at least one property" }]
1077
+ });
1078
+ }
1079
+ const unknownProperty = Object.keys(inputPatch).find(
1080
+ (property) => !Object.hasOwn(schema.shape, property)
1081
+ );
1082
+ if (unknownProperty !== void 0) {
1083
+ throw new chunkNI72YOJB_cjs.ValidationError(
1084
+ `Unknown ${kind} property in updateWhere() patch: ${unknownProperty}`,
1085
+ {
1086
+ entityType: "node",
1087
+ kind,
1088
+ operation: "update",
1089
+ issues: [
1090
+ {
1091
+ path: unknownProperty,
1092
+ message: "Property is not declared by the node schema"
1093
+ }
1094
+ ]
1095
+ }
1096
+ );
1097
+ }
1098
+ const parsedPatch = chunkXNLIZYRZ_cjs.validateNodeProps(schema.partial(), inputPatch, {
1099
+ kind,
1100
+ operation: "update"
1101
+ });
1102
+ const patch = chunkN66HCGCY_cjs.createDataKeyedBag();
1103
+ const unsetProperties = [];
1104
+ for (const [property, value] of Object.entries(parsedPatch)) {
1105
+ if (value === void 0) {
1106
+ unsetProperties.push(property);
1107
+ continue;
1108
+ }
1109
+ chunkLBJKZXDE_cjs.assertJsonValue(value, property, `Node "${kind}" updateWhere patch`);
1110
+ patch[property] = value;
1111
+ }
1112
+ if (Object.keys(patch).length === 0 && unsetProperties.length === 0) {
1113
+ throw new chunkNI72YOJB_cjs.ValidationError(
1114
+ "updateWhere() patch has no recognized properties",
1115
+ {
1116
+ entityType: "node",
1117
+ kind,
1118
+ operation: "update",
1119
+ issues: [
1120
+ { path: "patch", message: "Provide a declared node property" }
1121
+ ]
1122
+ }
1123
+ );
1124
+ }
1125
+ if (uniqueConstraints.length > 0 && (backend.hardDeleteUniquesByNodeIds === void 0 || backend.insertUniqueBatch === void 0 || backend.checkUniqueBatch === void 0)) {
1126
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1127
+ "updateWhere() requires batched uniqueness sidecar operations for constrained nodes",
1128
+ { code: "SET_UPDATE_UNIQUENESS_UNSUPPORTED", kind }
1129
+ );
1130
+ }
1131
+ if (chunkHAHNRASW_cjs.getSearchableFields(schema).length > 0 && (backend.upsertFulltext === void 0 || backend.deleteFulltext === void 0 || backend.upsertFulltextBatch === void 0 || backend.deleteFulltextBatch === void 0)) {
1132
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1133
+ "updateWhere() requires batched fulltext sidecar operations for searchable nodes",
1134
+ { code: "SET_UPDATE_FULLTEXT_UNSUPPORTED", kind }
1135
+ );
1136
+ }
1137
+ if (chunkTTAITEPJ_cjs.getEmbeddingFields(schema).length > 0 && (backend.upsertEmbedding === void 0 || backend.deleteEmbedding === void 0 || backend.upsertEmbeddingBatch === void 0 || backend.deleteEmbeddingBatch === void 0)) {
1138
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1139
+ "updateWhere() requires batched vector sidecar operations for embedded nodes",
1140
+ { code: "SET_UPDATE_VECTOR_UNSUPPORTED", kind }
1141
+ );
1142
+ }
1143
+ const hookContext = ctx.createBulkOperationContext("updateWhere", kind);
1144
+ return ctx.withBulkOperationHooks(
1145
+ hookContext,
1146
+ () => chunkXNLIZYRZ_cjs.runInWriteTransaction(
1147
+ ctx,
1148
+ backend,
1149
+ async (target, lock) => {
1150
+ const updateNodeSet = target.updateNodeSet;
1151
+ if (updateNodeSet === void 0) {
1152
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1153
+ "The transaction backend does not support set-based node updates",
1154
+ { code: "SET_UPDATE_UNSUPPORTED", kind }
1155
+ );
1156
+ }
1157
+ const hardDeleteUniquesByNodeIds = target.hardDeleteUniquesByNodeIds;
1158
+ if (uniqueConstraints.length > 0 && (hardDeleteUniquesByNodeIds === void 0 || target.insertUniqueBatch === void 0 || target.checkUniqueBatch === void 0)) {
1159
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1160
+ "The transaction backend lacks batched uniqueness operations",
1161
+ { code: "SET_UPDATE_UNIQUENESS_UNSUPPORTED", kind }
1162
+ );
1163
+ }
1164
+ if (chunkHAHNRASW_cjs.getSearchableFields(schema).length > 0 && (target.upsertFulltext === void 0 || target.deleteFulltext === void 0 || target.upsertFulltextBatch === void 0 || target.deleteFulltextBatch === void 0)) {
1165
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1166
+ "The transaction backend lacks batched fulltext operations",
1167
+ { code: "SET_UPDATE_FULLTEXT_UNSUPPORTED", kind }
1168
+ );
1169
+ }
1170
+ if (chunkTTAITEPJ_cjs.getEmbeddingFields(schema).length > 0 && (target.upsertEmbedding === void 0 || target.deleteEmbedding === void 0 || target.upsertEmbeddingBatch === void 0 || target.deleteEmbeddingBatch === void 0)) {
1171
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1172
+ "The transaction backend lacks batched vector operations",
1173
+ { code: "SET_UPDATE_VECTOR_UNSUPPORTED", kind }
1174
+ );
1175
+ }
1176
+ const result = await updateNodeSet({
1177
+ graphId: ctx.graphId,
1178
+ kind,
1179
+ patch,
1180
+ unsetProperties,
1181
+ candidateIds,
1182
+ candidateIdColumn
1183
+ });
1184
+ if (result.affectedCount === 0) return { affectedCount: 0 };
1185
+ const sidecarItems = result.rows.map((row) => {
1186
+ const props = chunkXBYVV3MP_cjs.rowPropsToObject(row.props);
1187
+ const validatedProps = chunkXNLIZYRZ_cjs.validateNodeProps(schema, props, {
1188
+ kind,
1189
+ operation: "update",
1190
+ id: row.id
1191
+ });
1192
+ if (!chunkPWLJ77UV_cjs.canonicalEqual(validatedProps, props)) {
1193
+ throw new chunkNI72YOJB_cjs.ValidationError(
1194
+ `Set update would persist a non-canonical ${kind} row`,
1195
+ {
1196
+ entityType: "node",
1197
+ kind,
1198
+ operation: "update",
1199
+ id: row.id,
1200
+ issues: [
1201
+ {
1202
+ path: "props",
1203
+ message: "The complete row requires schema normalization"
1204
+ }
1205
+ ]
1206
+ }
1207
+ );
1208
+ }
1209
+ return {
1210
+ kind,
1211
+ id: row.id,
1212
+ schema,
1213
+ props: validatedProps,
1214
+ uniqueConstraints
1215
+ };
1216
+ });
1217
+ if (uniqueConstraints.length > 0) {
1218
+ const affectedIds = new Set(result.rows.map((row) => row.id));
1219
+ for (const constraint of uniqueConstraints) {
1220
+ const keyToId = /* @__PURE__ */ new Map();
1221
+ for (const item of sidecarItems) {
1222
+ if (!chunkE4WNQBEF_cjs.checkWherePredicate(constraint, item.props)) continue;
1223
+ const key = chunkE4WNQBEF_cjs.computeUniqueKey(
1224
+ item.props,
1225
+ constraint.fields,
1226
+ constraint.collation
1227
+ );
1228
+ const priorId = keyToId.get(key);
1229
+ if (priorId !== void 0 && priorId !== item.id) {
1230
+ throw new chunkNI72YOJB_cjs.UniquenessError({
1231
+ constraintName: constraint.name,
1232
+ kind,
1233
+ existingId: priorId,
1234
+ newId: item.id,
1235
+ fields: constraint.fields
1236
+ });
1237
+ }
1238
+ keyToId.set(key, item.id);
1239
+ }
1240
+ const keys = [...keyToId.keys()];
1241
+ if (keys.length === 0) continue;
1242
+ for (const kindToCheck of chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
1243
+ kind,
1244
+ constraint.scope,
1245
+ ctx.registry
1246
+ )) {
1247
+ const existingRows = await chunkN66HCGCY_cjs.requireDefined(
1248
+ target.checkUniqueBatch
1249
+ )({
1250
+ graphId: ctx.graphId,
1251
+ nodeKind: kindToCheck,
1252
+ constraintName: constraint.name,
1253
+ keys
1254
+ });
1255
+ for (const existing of existingRows) {
1256
+ if (existing.concrete_kind === kind && affectedIds.has(existing.node_id)) {
1257
+ continue;
1258
+ }
1259
+ throw new chunkNI72YOJB_cjs.UniquenessError({
1260
+ constraintName: constraint.name,
1261
+ kind: kindToCheck,
1262
+ existingId: existing.node_id,
1263
+ newId: chunkN66HCGCY_cjs.requireDefined(keyToId.get(existing.key)),
1264
+ fields: constraint.fields
1265
+ });
1266
+ }
1267
+ }
1268
+ }
1269
+ await chunkN66HCGCY_cjs.requireDefined(hardDeleteUniquesByNodeIds)({
1270
+ graphId: ctx.graphId,
1271
+ concreteKind: kind,
1272
+ nodeIds: result.rows.map((row) => row.id)
1273
+ });
1274
+ }
1275
+ await chunkTTAITEPJ_cjs.applyNodeInsertSideEffectsBatch(
1276
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
1277
+ sidecarItems,
1278
+ target
1279
+ );
1280
+ return { affectedCount: result.affectedCount };
1281
+ },
1282
+ {
1283
+ didWrite: (result) => result.affectedCount > 0,
1284
+ // The set update re-checks every changed unique key across the
1285
+ // constraint's scope before rebuilding the sidecars, so a shared-scope
1286
+ // constraint makes it a constrained write like any other update.
1287
+ fencesConstraintProbe: nodeFencesConstraintProbe(ctx, kind, "update")
1288
+ }
1289
+ )
1290
+ );
1291
+ }
1292
+ async function executeNodeUpsertUpdate(ctx, input, backend, options) {
1293
+ return chunkXNLIZYRZ_cjs.runInWriteTransaction(
1294
+ ctx,
1295
+ backend,
1296
+ async (target, lock) => {
1297
+ const identity = ctx.identity;
1298
+ if (options?.clearDeleted && identity !== void 0) {
1299
+ await identity.lock(target);
1300
+ }
1301
+ const node = await performNodeUpdateWithResurrectionRecovery(
1302
+ ctx,
1303
+ input,
1304
+ target,
1305
+ lock,
1306
+ options
1307
+ );
1308
+ if (options?.clearDeleted && identity !== void 0) {
1309
+ await identity.foldCreated(target, [
1310
+ { kind: input.kind, id: input.id }
1311
+ ]);
1312
+ }
1313
+ return node;
1314
+ },
1315
+ {
1316
+ fencesConstraintProbe: nodeFencesConstraintProbe(
1317
+ ctx,
1318
+ input.kind,
1319
+ "update"
1320
+ )
1321
+ }
1322
+ );
1323
+ }
1324
+ async function executeNodeDelete(ctx, kind, id, backend) {
1325
+ const gate = await backend.getNode(ctx.graphId, kind, id);
1326
+ if (!gate || gate.deleted_at) return;
1327
+ const opContext = ctx.createOperationContext("delete", "node", kind, id);
1328
+ return chunkXNLIZYRZ_cjs.runHookedWriteOperation(
1329
+ ctx,
1330
+ opContext,
1331
+ backend,
1332
+ async (target, lock) => {
1333
+ const identity = ctx.identity;
1334
+ if (identity !== void 0) await identity.lock(target);
1335
+ const registration = getNodeRegistration(ctx.graph, kind);
1336
+ const preflight = await target.getNode(ctx.graphId, kind, id);
1337
+ if (!preflight || !chunkXBYVV3MP_cjs.isLiveNodeRow(preflight)) return;
1338
+ await chunkTTAITEPJ_cjs.applyNodeSoftDelete(
1339
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
1340
+ {
1341
+ existing: preflight,
1342
+ schema: registration.type.schema,
1343
+ uniqueConstraints: registration.unique ?? [],
1344
+ onDelete: registration.onDelete
1345
+ },
1346
+ target
1347
+ );
1348
+ if (identity !== void 0) {
1349
+ await identity.detachDeleted(target, { kind, id }, "soft");
1350
+ }
1351
+ }
1352
+ );
1353
+ }
1354
+ async function executeNodeDeleteBatch(ctx, kind, ids, backend) {
1355
+ await chunkXNLIZYRZ_cjs.runInWriteTransaction(
1356
+ ctx,
1357
+ backend,
1358
+ async (target, lock) => {
1359
+ const identity = ctx.identity;
1360
+ if (identity !== void 0) await identity.lock(target);
1361
+ const registration = getNodeRegistration(ctx.graph, kind);
1362
+ const writeContext = chunkTTAITEPJ_cjs.createNodeWriteContext(
1363
+ ctx.graphId,
1364
+ ctx.registry,
1365
+ lock
1366
+ );
1367
+ let affectedCount = 0;
1368
+ for (const id of ids) {
1369
+ const preflight = await target.getNode(ctx.graphId, kind, id);
1370
+ if (!preflight || !chunkXBYVV3MP_cjs.isLiveNodeRow(preflight)) continue;
1371
+ await chunkTTAITEPJ_cjs.applyNodeSoftDelete(
1372
+ writeContext,
1373
+ {
1374
+ existing: preflight,
1375
+ schema: registration.type.schema,
1376
+ uniqueConstraints: registration.unique ?? [],
1377
+ onDelete: registration.onDelete
1378
+ },
1379
+ target
1380
+ );
1381
+ if (identity !== void 0) {
1382
+ await identity.detachDeleted(target, { kind, id }, "soft");
1383
+ }
1384
+ affectedCount += 1;
1385
+ }
1386
+ return affectedCount;
1387
+ },
1388
+ { didWrite: (affectedCount) => affectedCount > 0 }
1389
+ );
1390
+ }
1391
+ async function executeNodeHardDelete(ctx, kind, id, backend) {
1392
+ const gate = await backend.getNode(ctx.graphId, kind, id);
1393
+ if (!gate) return;
1394
+ const opContext = ctx.createOperationContext("delete", "node", kind, id);
1395
+ return chunkXNLIZYRZ_cjs.runHookedWriteOperation(
1396
+ ctx,
1397
+ opContext,
1398
+ backend,
1399
+ async (target, lock) => {
1400
+ const identity = ctx.identity;
1401
+ if (identity !== void 0) await identity.lock(target);
1402
+ const registration = getNodeRegistration(ctx.graph, kind);
1403
+ await chunkTTAITEPJ_cjs.applyNodeHardDelete(
1404
+ chunkTTAITEPJ_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
1405
+ {
1406
+ kind,
1407
+ id,
1408
+ schema: registration.type.schema,
1409
+ onDelete: registration.onDelete
1410
+ },
1411
+ target
1412
+ );
1413
+ if (identity !== void 0) {
1414
+ await identity.detachDeleted(target, { kind, id }, "hard");
1415
+ }
1416
+ }
1417
+ );
1418
+ }
1419
+ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, props, backend, options) {
1420
+ const ifExists = options?.ifExists ?? "return";
1421
+ const registration = getNodeRegistration(ctx.graph, kind);
1422
+ const nodeKind = registration.type;
1423
+ const validatedProps = chunkXNLIZYRZ_cjs.validateNodeProps(nodeKind.schema, props, {
1424
+ kind,
1425
+ operation: "create"
1426
+ });
1427
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
1428
+ if (!chunkE4WNQBEF_cjs.checkWherePredicate(constraint, validatedProps)) {
1429
+ const node = await executeNodeCreate(
1430
+ ctx,
1431
+ { kind, props: validatedProps },
1432
+ backend,
1433
+ { propsPreValidated: true }
1434
+ );
1435
+ return { node, action: "created" };
1436
+ }
1437
+ const key = chunkE4WNQBEF_cjs.computeUniqueKey(
1438
+ validatedProps,
1439
+ constraint.fields,
1440
+ constraint.collation
1441
+ );
1442
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
1443
+ kind,
1444
+ constraint.scope,
1445
+ ctx.registry
1446
+ );
1447
+ async function attempt() {
1448
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
1449
+ backend,
1450
+ ctx.graphId,
1451
+ constraint.name,
1452
+ key,
1453
+ kindsToCheck,
1454
+ true
1455
+ );
1456
+ if (existingUniqueRow === void 0) {
1457
+ const node = await executeNodeCreate(
1458
+ ctx,
1459
+ { kind, props: validatedProps },
1460
+ backend,
1461
+ { propsPreValidated: true }
1462
+ );
1463
+ return { node, action: "created" };
1464
+ }
1465
+ const existingRow = await backend.getNode(
1466
+ ctx.graphId,
1467
+ existingUniqueRow.concrete_kind,
1468
+ existingUniqueRow.node_id
1469
+ );
1470
+ if (existingRow === void 0) {
1471
+ const node = await executeNodeCreate(
1472
+ ctx,
1473
+ { kind, props: validatedProps },
1474
+ backend,
1475
+ { propsPreValidated: true }
1476
+ );
1477
+ return { node, action: "created" };
1478
+ }
1479
+ const isSoftDeleted = existingRow.deleted_at !== void 0;
1480
+ if (isSoftDeleted || ifExists === "update") {
1481
+ const concreteKind = existingUniqueRow.concrete_kind;
1482
+ const node = await executeNodeUpsertUpdate(
1483
+ ctx,
1484
+ {
1485
+ kind: concreteKind,
1486
+ id: existingRow.id,
1487
+ props: validatedProps
1488
+ },
1489
+ backend,
1490
+ { clearDeleted: isSoftDeleted }
1491
+ );
1492
+ return { node, action: isSoftDeleted ? "resurrected" : "updated" };
1493
+ }
1494
+ return { node: rowToNode(existingRow), action: "found" };
1495
+ }
1496
+ try {
1497
+ return await attempt();
1498
+ } catch (error) {
1499
+ if (!(error instanceof chunkNI72YOJB_cjs.UniquenessError)) throw error;
1500
+ return attempt();
1501
+ }
1502
+ }
1503
+ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
1504
+ const registration = getNodeRegistration(ctx.graph, kind);
1505
+ const nodeKind = registration.type;
1506
+ const validatedProps = chunkXNLIZYRZ_cjs.validateNodeProps(nodeKind.schema, props, {
1507
+ kind,
1508
+ operation: "create"
1509
+ });
1510
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
1511
+ if (!chunkE4WNQBEF_cjs.checkWherePredicate(constraint, validatedProps)) return void 0;
1512
+ const key = chunkE4WNQBEF_cjs.computeUniqueKey(
1513
+ validatedProps,
1514
+ constraint.fields,
1515
+ constraint.collation
1516
+ );
1517
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
1518
+ kind,
1519
+ constraint.scope,
1520
+ ctx.registry
1521
+ );
1522
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
1523
+ backend,
1524
+ ctx.graphId,
1525
+ constraint.name,
1526
+ key,
1527
+ kindsToCheck,
1528
+ false
1529
+ );
1530
+ if (existingUniqueRow === void 0) return void 0;
1531
+ const existingRow = await backend.getNode(
1532
+ ctx.graphId,
1533
+ existingUniqueRow.concrete_kind,
1534
+ existingUniqueRow.node_id
1535
+ );
1536
+ if (existingRow === void 0 || existingRow.deleted_at !== void 0)
1537
+ return void 0;
1538
+ return rowToNode(existingRow);
1539
+ }
1540
+ function validateAndComputeKeys(nodeKind, kind, constraint, items) {
1541
+ const validated = [];
1542
+ for (const item of items) {
1543
+ const validatedProps = chunkXNLIZYRZ_cjs.validateNodeProps(nodeKind.schema, item.props, {
1544
+ kind,
1545
+ operation: "create"
1546
+ });
1547
+ const applies = chunkE4WNQBEF_cjs.checkWherePredicate(constraint, validatedProps);
1548
+ const key = applies ? chunkE4WNQBEF_cjs.computeUniqueKey(
1549
+ validatedProps,
1550
+ constraint.fields,
1551
+ constraint.collation
1552
+ ) : void 0;
1553
+ validated.push({ validatedProps, key });
1554
+ }
1555
+ return validated;
1556
+ }
1557
+ function collectUniqueKeys(validated) {
1558
+ return [
1559
+ ...new Set(
1560
+ validated.map((entry) => entry.key).filter((key) => key !== void 0)
1561
+ )
1562
+ ];
1563
+ }
1564
+ async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
1565
+ if (items.length === 0) return [];
1566
+ const registration = getNodeRegistration(ctx.graph, kind);
1567
+ const nodeKind = registration.type;
1568
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
1569
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
1570
+ const uniqueKeys = collectUniqueKeys(validated);
1571
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
1572
+ kind,
1573
+ constraint.scope,
1574
+ ctx.registry
1575
+ );
1576
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
1577
+ backend,
1578
+ ctx.graphId,
1579
+ constraint.name,
1580
+ uniqueKeys,
1581
+ kindsToCheck,
1582
+ false
1583
+ ) : /* @__PURE__ */ new Map();
1584
+ const results = Array.from({ length: items.length });
1585
+ const seenKeys = /* @__PURE__ */ new Map();
1586
+ for (const [index, { key }] of validated.entries()) {
1587
+ if (key === void 0) {
1588
+ results[index] = void 0;
1589
+ continue;
1590
+ }
1591
+ const previousIndex = seenKeys.get(key);
1592
+ if (previousIndex !== void 0) {
1593
+ results[index] = results[previousIndex];
1594
+ continue;
1595
+ }
1596
+ seenKeys.set(key, index);
1597
+ const existing = existingByKey.get(key);
1598
+ if (existing === void 0) {
1599
+ results[index] = void 0;
1600
+ continue;
1601
+ }
1602
+ const existingRow = await backend.getNode(
1603
+ ctx.graphId,
1604
+ existing.concrete_kind,
1605
+ existing.node_id
1606
+ );
1607
+ if (existingRow === void 0 || existingRow.deleted_at !== void 0) {
1608
+ results[index] = void 0;
1609
+ continue;
1610
+ }
1611
+ results[index] = rowToNode(existingRow);
1612
+ }
1613
+ return results;
1614
+ }
1615
+ function resolveNodeIndex(graph, kind, indexName) {
1616
+ getNodeRegistration(graph, kind);
1617
+ const declaration = graph.indexes?.find(
1618
+ (candidate) => candidate.entity === "node" && candidate.kind === kind && candidate.name === indexName
1619
+ );
1620
+ if (declaration?.entity !== "node") {
1621
+ throw new chunkNI72YOJB_cjs.NodeIndexNotFoundError(indexName, kind);
1622
+ }
1623
+ if (declaration.method !== void 0) {
1624
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1625
+ `bulkFindByIndex cannot probe index "${indexName}" (method "${declaration.method}"): only btree indexes serve equality probes.`,
1626
+ { indexName, kind, method: declaration.method }
1627
+ );
1628
+ }
1629
+ return declaration;
1630
+ }
1631
+ var INDEX_PROBE_EXPECTED_TYPEOF = {
1632
+ string: "string",
1633
+ number: "number",
1634
+ boolean: "boolean"
1635
+ };
1636
+ function validateIndexProbeValue(value, valueType, pointer, kind) {
1637
+ if (value === void 0 || value === null) return;
1638
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean" && !(value instanceof Date)) {
1639
+ throw indexProbeTypeError(
1640
+ pointer,
1641
+ kind,
1642
+ "a scalar (string, number, boolean, or Date)",
1643
+ value
1644
+ );
1645
+ }
1646
+ if (valueType === "date") {
1647
+ if (value instanceof Date || typeof value === "string") return;
1648
+ throw indexProbeTypeError(
1649
+ pointer,
1650
+ kind,
1651
+ "date (Date or ISO string)",
1652
+ value
1653
+ );
1654
+ }
1655
+ const expected = INDEX_PROBE_EXPECTED_TYPEOF[valueType ?? "unknown"];
1656
+ if (expected === void 0) return;
1657
+ if (typeof value !== expected) {
1658
+ throw indexProbeTypeError(pointer, kind, expected, value);
1659
+ }
1660
+ }
1661
+ function indexProbeTypeError(pointer, kind, expected, value) {
1662
+ return new chunkNI72YOJB_cjs.ValidationError(
1663
+ `Index probe value for "${pointer}" on node kind "${kind}" has an incompatible type`,
1664
+ {
1665
+ entityType: "node",
1666
+ kind,
1667
+ issues: [
1668
+ {
1669
+ path: pointer,
1670
+ message: `Expected ${expected}, received ${typeof value}`,
1671
+ code: "invalid_type"
1672
+ }
1673
+ ]
1674
+ }
1675
+ );
1676
+ }
1677
+ function coerceIndexProbeBind(value, adapter) {
1678
+ return adapter.bindValue(normalizeProbeScalar(value));
1679
+ }
1680
+ function normalizeProbeScalar(value) {
1681
+ return value instanceof Date ? value.toISOString() : value;
1682
+ }
1683
+ var PROBE_NULL_TAG = 0;
1684
+ var PROBE_VALUE_TAG = 1;
1685
+ function canonicalIndexProbeKey(probe) {
1686
+ return JSON.stringify(
1687
+ probe.map(
1688
+ (value) => value === void 0 || value === null ? [PROBE_NULL_TAG] : [PROBE_VALUE_TAG, normalizeProbeScalar(value)]
1689
+ )
1690
+ );
1691
+ }
1692
+ async function executeNodeBulkFindByIndex(ctx, kind, indexName, items, backend, options) {
1693
+ if (items.length === 0) return [];
1694
+ const index = resolveNodeIndex(ctx.graph, kind, indexName);
1695
+ if (index.fields.length === 0) {
1696
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1697
+ `bulkFindByIndex requires an index with at least one prop-based field on index "${indexName}" (node kind "${kind}")`,
1698
+ { indexName, kind },
1699
+ {
1700
+ suggestion: "bulkFindByIndex probes by prop values from each item; an index declared with only keySystemColumns/coveringFields (no fields) has nothing to probe by."
1701
+ }
1702
+ );
1703
+ }
1704
+ if (index.fieldValueTypes.includes("date")) {
1705
+ throw new chunkNI72YOJB_cjs.ConfigurationError(
1706
+ `bulkFindByIndex does not support date-typed key fields on index "${indexName}" (node kind "${kind}")`,
1707
+ { indexName, kind },
1708
+ {
1709
+ suggestion: "Date index keys compare differently across SQLite and PostgreSQL. Use a string-encoded key field, or query date predicates via store.query(...).where(...)."
1710
+ }
1711
+ );
1712
+ }
1713
+ const limitPerInput = options?.limitPerInput;
1714
+ if (limitPerInput !== void 0 && (!Number.isInteger(limitPerInput) || limitPerInput <= 0)) {
1715
+ throw new chunkNI72YOJB_cjs.ValidationError(
1716
+ "bulkFindByIndex limitPerInput must be a positive integer",
1717
+ {
1718
+ entityType: "node",
1719
+ kind,
1720
+ issues: [
1721
+ {
1722
+ path: "limitPerInput",
1723
+ message: `Expected a positive integer, received ${String(limitPerInput)}`,
1724
+ code: "invalid_value"
1725
+ }
1726
+ ]
1727
+ }
1728
+ );
1729
+ }
1730
+ const adapter = chunk4UGOKMI5_cjs.getDialect(backend.dialect);
1731
+ const probes = items.map(
1732
+ (item) => index.fields.map((pointer, position) => {
1733
+ const value = chunkA7J2YDDI_cjs.resolveJsonPointer(item.props, pointer);
1734
+ validateIndexProbeValue(
1735
+ value,
1736
+ index.fieldValueTypes[position],
1737
+ pointer,
1738
+ kind
1739
+ );
1740
+ return value;
1741
+ })
1742
+ );
1743
+ const groupByKey = /* @__PURE__ */ new Map();
1744
+ const groupProbes = [];
1745
+ const groupToInputs = [];
1746
+ for (const [inputIndex, probe] of probes.entries()) {
1747
+ const key = canonicalIndexProbeKey(probe);
1748
+ const existing = groupByKey.get(key);
1749
+ if (existing === void 0) {
1750
+ groupByKey.set(key, groupProbes.length);
1751
+ groupProbes.push(probe);
1752
+ groupToInputs.push([inputIndex]);
1753
+ continue;
1754
+ }
1755
+ groupToInputs[existing]?.push(inputIndex);
1756
+ }
1757
+ const schema = backend.tableNames ? chunkNFCVHQ5P_cjs.createSqlSchema(backend.tableNames) : chunkNFCVHQ5P_cjs.DEFAULT_SQL_SCHEMA;
1758
+ const compileContext = {
1759
+ dialect: backend.dialect,
1760
+ propsColumn: chunkVCRRKBLN_cjs.sql.raw(`"props"`),
1761
+ systemColumn: (column) => chunkVCRRKBLN_cjs.sql.raw(`"${column}"`)
1762
+ };
1763
+ const fieldKeys = chunk4UGOKMI5_cjs.compileNodeIndexFieldKeys(index, compileContext);
1764
+ const groupPredicates = groupProbes.map(
1765
+ (probe) => chunkVCRRKBLN_cjs.sql`(${chunkVCRRKBLN_cjs.sql.join(
1766
+ fieldKeys.map((fieldKey, position) => {
1767
+ const value = probe[position];
1768
+ if (value === void 0 || value === null) {
1769
+ return chunkVCRRKBLN_cjs.sql`${fieldKey} IS NULL`;
1770
+ }
1771
+ return adapter.nullSafeEquals(
1772
+ fieldKey,
1773
+ chunkVCRRKBLN_cjs.sql`${coerceIndexProbeBind(value, adapter)}`
1774
+ );
1775
+ }),
1776
+ chunkVCRRKBLN_cjs.sql` AND `
1777
+ )})`
1778
+ );
1779
+ const caseBranches = groupPredicates.map(
1780
+ (predicate, group) => chunkVCRRKBLN_cjs.sql`WHEN ${predicate} THEN ${chunkVCRRKBLN_cjs.sql.raw(String(group))}`
1781
+ );
1782
+ const probeIndexExpr = chunkVCRRKBLN_cjs.sql`CASE ${chunkVCRRKBLN_cjs.sql.join(caseBranches, chunkVCRRKBLN_cjs.sql` `)} ELSE NULL END`;
1783
+ const conditions = [
1784
+ chunkVCRRKBLN_cjs.sql`"graph_id" = ${ctx.graphId}`,
1785
+ chunkVCRRKBLN_cjs.sql`"kind" = ${kind}`,
1786
+ chunkVCRRKBLN_cjs.sql`"deleted_at" IS NULL`
1787
+ ];
1788
+ if (index.where !== void 0) {
1789
+ conditions.push(chunk4UGOKMI5_cjs.compileIndexWhere(compileContext, index.where));
1790
+ }
1791
+ conditions.push(chunkVCRRKBLN_cjs.sql`(${chunkVCRRKBLN_cjs.sql.join(groupPredicates, chunkVCRRKBLN_cjs.sql` OR `)})`);
1792
+ const whereClause = chunkVCRRKBLN_cjs.sql.join(conditions, chunkVCRRKBLN_cjs.sql` AND `);
1793
+ const probedSelect = chunkVCRRKBLN_cjs.sql`SELECT "id", ${probeIndexExpr} AS probe_idx FROM ${schema.nodesTable} WHERE ${whereClause}`;
1794
+ const capInSql = limitPerInput !== void 0 && backend.capabilities.windowFunctions;
1795
+ const query = capInSql ? chunkVCRRKBLN_cjs.sql`SELECT "id", probe_idx FROM (SELECT "id", probe_idx, ROW_NUMBER() OVER (PARTITION BY probe_idx ORDER BY "id") AS probe_rank FROM (${probedSelect}) AS probed) AS ranked WHERE probe_rank <= ${limitPerInput} ORDER BY probe_idx, "id"` : chunkVCRRKBLN_cjs.sql`${probedSelect} ORDER BY probe_idx, "id"`;
1796
+ const rawMatches = await backend.execute(
1797
+ chunkVCRRKBLN_cjs.asCompiledRowsSql(query)
1798
+ );
1799
+ const matches = limitPerInput !== void 0 && !capInSql ? capMatchesPerGroup(rawMatches, limitPerInput) : rawMatches;
1800
+ const nodesById = await hydrateNodesById(
1801
+ backend,
1802
+ ctx.graphId,
1803
+ kind,
1804
+ matches.map((match) => match.id)
1805
+ );
1806
+ const results = Array.from({ length: items.length }, () => []);
1807
+ for (const match of matches) {
1808
+ const node = nodesById.get(match.id);
1809
+ if (node === void 0) continue;
1810
+ const inputs = groupToInputs[match.probe_idx];
1811
+ if (inputs === void 0) continue;
1812
+ for (const inputIndex of inputs) {
1813
+ results[inputIndex]?.push(node);
1814
+ }
1815
+ }
1816
+ return results;
1817
+ }
1818
+ function capMatchesPerGroup(matches, limitPerInput) {
1819
+ const perGroupCount = /* @__PURE__ */ new Map();
1820
+ const capped = [];
1821
+ for (const match of matches) {
1822
+ const count = perGroupCount.get(match.probe_idx) ?? 0;
1823
+ if (count >= limitPerInput) continue;
1824
+ perGroupCount.set(match.probe_idx, count + 1);
1825
+ capped.push(match);
1826
+ }
1827
+ return capped;
1828
+ }
1829
+ async function hydrateNodesById(backend, graphId, kind, ids) {
1830
+ const rowsById = await chunkXMQSEJCF_cjs.getNodeRowsByIds(backend, graphId, kind, ids);
1831
+ const nodesById = /* @__PURE__ */ new Map();
1832
+ for (const [id, row] of rowsById) {
1833
+ if (row.deleted_at !== void 0) continue;
1834
+ nodesById.set(id, rowToNode(row));
1835
+ }
1836
+ return nodesById;
1837
+ }
1838
+ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName, items, backend, options) {
1839
+ if (items.length === 0) return [];
1840
+ const ifExists = options?.ifExists ?? "return";
1841
+ const registration = getNodeRegistration(ctx.graph, kind);
1842
+ const nodeKind = registration.type;
1843
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
1844
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
1845
+ const uniqueKeys = collectUniqueKeys(validated);
1846
+ const kindsToCheck = chunkE4WNQBEF_cjs.getKindsForUniquenessCheck(
1847
+ kind,
1848
+ constraint.scope,
1849
+ ctx.registry
1850
+ );
1851
+ async function attempt() {
1852
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
1853
+ backend,
1854
+ ctx.graphId,
1855
+ constraint.name,
1856
+ uniqueKeys,
1857
+ kindsToCheck,
1858
+ true
1859
+ ) : /* @__PURE__ */ new Map();
1860
+ const toCreate = [];
1861
+ const toFetch = [];
1862
+ const duplicateOf = [];
1863
+ const seenKeys = /* @__PURE__ */ new Map();
1864
+ for (const [index, { validatedProps, key }] of validated.entries()) {
1865
+ if (key === void 0) {
1866
+ toCreate.push({ index, input: { kind, props: validatedProps } });
1867
+ continue;
1868
+ }
1869
+ const previousIndex = seenKeys.get(key);
1870
+ if (previousIndex !== void 0) {
1871
+ duplicateOf.push({ index, sourceIndex: previousIndex });
1872
+ continue;
1873
+ }
1874
+ seenKeys.set(key, index);
1875
+ const existing = existingByKey.get(key);
1876
+ if (existing === void 0) {
1877
+ toCreate.push({ index, input: { kind, props: validatedProps } });
1878
+ } else {
1879
+ toFetch.push({
1880
+ index,
1881
+ nodeId: existing.node_id,
1882
+ concreteKind: existing.concrete_kind,
1883
+ validatedProps
1884
+ });
1885
+ }
1886
+ }
1887
+ const results = Array.from({ length: items.length });
1888
+ if (toCreate.length > 0) {
1889
+ const createInputs = toCreate.map((entry) => entry.input);
1890
+ const createdNodes = await executeNodeCreateBatch(
1891
+ ctx,
1892
+ createInputs,
1893
+ backend,
1894
+ { propsPreValidated: true }
1895
+ );
1896
+ for (const [batchIndex, entry] of toCreate.entries()) {
1897
+ results[entry.index] = {
1898
+ node: chunkN66HCGCY_cjs.requireDefined(createdNodes[batchIndex]),
1899
+ action: "created"
1900
+ };
1901
+ }
1902
+ }
1903
+ for (const entry of toFetch) {
1904
+ const { index, concreteKind, validatedProps, nodeId } = entry;
1905
+ const existingRow = await backend.getNode(
1906
+ ctx.graphId,
1907
+ concreteKind,
1908
+ nodeId
1909
+ );
1910
+ if (existingRow === void 0) {
1911
+ const node = await executeNodeCreate(
1912
+ ctx,
1913
+ { kind, props: validatedProps },
1914
+ backend,
1915
+ { propsPreValidated: true }
1916
+ );
1917
+ results[index] = { node, action: "created" };
1918
+ continue;
1919
+ }
1920
+ const isSoftDeleted = existingRow.deleted_at !== void 0;
1921
+ if (isSoftDeleted || ifExists === "update") {
1922
+ const node = await executeNodeUpsertUpdate(
1923
+ ctx,
1924
+ {
1925
+ kind: concreteKind,
1926
+ id: existingRow.id,
1927
+ props: validatedProps
1928
+ },
1929
+ backend,
1930
+ { clearDeleted: isSoftDeleted }
1931
+ );
1932
+ results[index] = {
1933
+ node,
1934
+ action: isSoftDeleted ? "resurrected" : "updated"
1935
+ };
1936
+ } else {
1937
+ results[index] = { node: rowToNode(existingRow), action: "found" };
1938
+ }
1939
+ }
1940
+ for (const { index, sourceIndex } of duplicateOf) {
1941
+ const sourceResult = chunkN66HCGCY_cjs.requireDefined(results[sourceIndex]);
1942
+ results[index] = { node: sourceResult.node, action: "found" };
1943
+ }
1944
+ return results;
1945
+ }
1946
+ try {
1947
+ return await attempt();
1948
+ } catch (error) {
1949
+ if (!(error instanceof chunkNI72YOJB_cjs.UniquenessError)) throw error;
1950
+ return attempt();
1951
+ }
1952
+ }
1953
+
1954
+ exports.checkCardinalityConstraint = checkCardinalityConstraint;
1955
+ exports.createNodeBatchValidationBackend = createNodeBatchValidationBackend;
1956
+ exports.edgeWriteNeedsConstraintFence = edgeWriteNeedsConstraintFence;
1957
+ exports.executeNodeBulkFindByConstraint = executeNodeBulkFindByConstraint;
1958
+ exports.executeNodeBulkFindByIndex = executeNodeBulkFindByIndex;
1959
+ exports.executeNodeBulkGetOrCreateByConstraint = executeNodeBulkGetOrCreateByConstraint;
1960
+ exports.executeNodeCreate = executeNodeCreate;
1961
+ exports.executeNodeCreateBatch = executeNodeCreateBatch;
1962
+ exports.executeNodeCreateNoReturnBatch = executeNodeCreateNoReturnBatch;
1963
+ exports.executeNodeDelete = executeNodeDelete;
1964
+ exports.executeNodeDeleteBatch = executeNodeDeleteBatch;
1965
+ exports.executeNodeFindByConstraint = executeNodeFindByConstraint;
1966
+ exports.executeNodeGetOrCreateByConstraint = executeNodeGetOrCreateByConstraint;
1967
+ exports.executeNodeHardDelete = executeNodeHardDelete;
1968
+ exports.executeNodeUpdate = executeNodeUpdate;
1969
+ exports.executeNodeUpdateWhere = executeNodeUpdateWhere;
1970
+ exports.executeNodeUpsertUpdate = executeNodeUpsertUpdate;
1971
+ exports.nodeUpsertDirtyCheck = nodeUpsertDirtyCheck;
1972
+ exports.primeBatchValidationCaches = primeBatchValidationCaches;
1973
+ exports.rowToEdge = rowToEdge;
1974
+ exports.rowToEdgeMeta = rowToEdgeMeta;
1975
+ exports.rowToNode = rowToNode;
1976
+ exports.rowToNodeMeta = rowToNodeMeta;
1977
+ exports.withAlreadyExistsTranslation = withAlreadyExistsTranslation;
1978
+ //# sourceMappingURL=chunk-7GT72YHH.cjs.map
1979
+ //# sourceMappingURL=chunk-7GT72YHH.cjs.map