@nicia-ai/typegraph 0.34.0 → 0.36.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 (287) hide show
  1. package/dist/backend/postgres/index.cjs +29 -29
  2. package/dist/backend/postgres/index.d.cts +39 -7
  3. package/dist/backend/postgres/index.d.ts +39 -7
  4. package/dist/backend/postgres/index.js +16 -16
  5. package/dist/backend/postgres/pglite.cjs +21 -21
  6. package/dist/backend/postgres/pglite.d.cts +4 -4
  7. package/dist/backend/postgres/pglite.d.ts +4 -4
  8. package/dist/backend/postgres/pglite.js +16 -16
  9. package/dist/backend/sqlite/index.cjs +25 -26
  10. package/dist/backend/sqlite/index.d.cts +8 -8
  11. package/dist/backend/sqlite/index.d.ts +8 -8
  12. package/dist/backend/sqlite/index.js +13 -14
  13. package/dist/backend/sqlite/libsql.cjs +19 -19
  14. package/dist/backend/sqlite/libsql.d.cts +4 -4
  15. package/dist/backend/sqlite/libsql.d.ts +4 -4
  16. package/dist/backend/sqlite/libsql.js +15 -15
  17. package/dist/backend/sqlite/local.cjs +101 -21
  18. package/dist/backend/sqlite/local.cjs.map +1 -1
  19. package/dist/backend/sqlite/local.d.cts +95 -5
  20. package/dist/backend/sqlite/local.d.ts +95 -5
  21. package/dist/backend/sqlite/local.js +95 -16
  22. package/dist/backend/sqlite/local.js.map +1 -1
  23. package/dist/{chunk-T6SPUYLX.cjs → chunk-2THZ3TQI.cjs} +116 -10
  24. package/dist/chunk-2THZ3TQI.cjs.map +1 -0
  25. package/dist/{chunk-UJLOZYKT.cjs → chunk-456Z2U7Y.cjs} +441 -115
  26. package/dist/chunk-456Z2U7Y.cjs.map +1 -0
  27. package/dist/chunk-4BCU6VFZ.cjs +100 -0
  28. package/dist/chunk-4BCU6VFZ.cjs.map +1 -0
  29. package/dist/chunk-4BMPGT35.cjs +12 -0
  30. package/dist/{chunk-HMFK4BXR.cjs.map → chunk-4BMPGT35.cjs.map} +1 -1
  31. package/dist/chunk-4CAXEB2F.cjs +1366 -0
  32. package/dist/chunk-4CAXEB2F.cjs.map +1 -0
  33. package/dist/{chunk-RY2VIWAM.js → chunk-4GX2JJXS.js} +355 -32
  34. package/dist/chunk-4GX2JJXS.js.map +1 -0
  35. package/dist/{chunk-GQANNXXT.cjs → chunk-5A6FNS6N.cjs} +75 -20
  36. package/dist/chunk-5A6FNS6N.cjs.map +1 -0
  37. package/dist/{chunk-3Z6TW3CT.cjs → chunk-5AQIKK56.cjs} +65 -25
  38. package/dist/chunk-5AQIKK56.cjs.map +1 -0
  39. package/dist/{chunk-WLRIWYHQ.js → chunk-5DIPR3L3.js} +2145 -1937
  40. package/dist/chunk-5DIPR3L3.js.map +1 -0
  41. package/dist/{chunk-BVTWD66D.js → chunk-5SEGFTZX.js} +3 -3
  42. package/dist/{chunk-BVTWD66D.js.map → chunk-5SEGFTZX.js.map} +1 -1
  43. package/dist/{chunk-A7SZZFAG.js → chunk-5VTR2F2K.js} +452 -109
  44. package/dist/chunk-5VTR2F2K.js.map +1 -0
  45. package/dist/{chunk-JJRCLAUN.cjs → chunk-5W4L6DLF.cjs} +116 -10
  46. package/dist/chunk-5W4L6DLF.cjs.map +1 -0
  47. package/dist/{chunk-6GNSY7AV.js → chunk-6FR2MMS6.js} +7 -7
  48. package/dist/chunk-6FR2MMS6.js.map +1 -0
  49. package/dist/{chunk-3BRVBQQD.cjs → chunk-7BQLPXK6.cjs} +2648 -2440
  50. package/dist/chunk-7BQLPXK6.cjs.map +1 -0
  51. package/dist/chunk-7YSP4V4R.cjs +69 -0
  52. package/dist/chunk-7YSP4V4R.cjs.map +1 -0
  53. package/dist/chunk-A42GCBGX.cjs +28 -0
  54. package/dist/chunk-A42GCBGX.cjs.map +1 -0
  55. package/dist/{chunk-ZV5N4DBG.js → chunk-BJVEU3ZL.js} +300 -58
  56. package/dist/chunk-BJVEU3ZL.js.map +1 -0
  57. package/dist/chunk-BYPOGQWK.js +25 -0
  58. package/dist/chunk-BYPOGQWK.js.map +1 -0
  59. package/dist/chunk-CUHM5CWJ.cjs +12 -0
  60. package/dist/chunk-CUHM5CWJ.cjs.map +1 -0
  61. package/dist/{chunk-2JXB3NYJ.cjs → chunk-D7ZEOS56.cjs} +25 -32
  62. package/dist/chunk-D7ZEOS56.cjs.map +1 -0
  63. package/dist/chunk-DFVLCOP6.js +10 -0
  64. package/dist/chunk-DFVLCOP6.js.map +1 -0
  65. package/dist/{chunk-JIEJCTDS.cjs → chunk-DIK74MXX.cjs} +37 -4
  66. package/dist/chunk-DIK74MXX.cjs.map +1 -0
  67. package/dist/chunk-DN5VP4JC.js +1343 -0
  68. package/dist/chunk-DN5VP4JC.js.map +1 -0
  69. package/dist/chunk-EOLERH7Y.cjs +40 -0
  70. package/dist/chunk-EOLERH7Y.cjs.map +1 -0
  71. package/dist/{chunk-TGJE22RM.cjs → chunk-FACJJWGF.cjs} +24 -6
  72. package/dist/chunk-FACJJWGF.cjs.map +1 -0
  73. package/dist/{chunk-WVC2Q2FD.cjs → chunk-FN35DLCN.cjs} +31 -9
  74. package/dist/chunk-FN35DLCN.cjs.map +1 -0
  75. package/dist/{chunk-KUTNI6SI.js → chunk-FPIZFYHE.js} +10 -18
  76. package/dist/chunk-FPIZFYHE.js.map +1 -0
  77. package/dist/{chunk-VCGO4V26.js → chunk-FRV5Q5IO.js} +64 -9
  78. package/dist/chunk-FRV5Q5IO.js.map +1 -0
  79. package/dist/{chunk-K5P5OZXS.js → chunk-G6Q5UM7U.js} +2 -2
  80. package/dist/{chunk-K5P5OZXS.js.map → chunk-G6Q5UM7U.js.map} +1 -1
  81. package/dist/{chunk-JQGIPGVL.cjs → chunk-H7YNSMA7.cjs} +43 -2
  82. package/dist/chunk-H7YNSMA7.cjs.map +1 -0
  83. package/dist/chunk-HW3LW7DH.cjs +1271 -0
  84. package/dist/chunk-HW3LW7DH.cjs.map +1 -0
  85. package/dist/{chunk-V3QNTB7Z.js → chunk-IU46OHVW.js} +194 -114
  86. package/dist/chunk-IU46OHVW.js.map +1 -0
  87. package/dist/{chunk-HK5SATYM.cjs → chunk-J3LEGNQB.cjs} +16 -109
  88. package/dist/chunk-J3LEGNQB.cjs.map +1 -0
  89. package/dist/{chunk-ZP5WHI4C.cjs → chunk-JFMEONLG.cjs} +358 -116
  90. package/dist/chunk-JFMEONLG.cjs.map +1 -0
  91. package/dist/{chunk-2MRAX3UE.js → chunk-JFUPDJXD.js} +47 -4
  92. package/dist/chunk-JFUPDJXD.js.map +1 -0
  93. package/dist/{chunk-Z5XBMDXU.js → chunk-KBGQIPRQ.js} +42 -3
  94. package/dist/chunk-KBGQIPRQ.js.map +1 -0
  95. package/dist/{chunk-K2TGS3EN.js → chunk-M75SUBFG.js} +138 -89
  96. package/dist/chunk-M75SUBFG.js.map +1 -0
  97. package/dist/chunk-OHMP6N2J.js +47 -0
  98. package/dist/chunk-OHMP6N2J.js.map +1 -0
  99. package/dist/{chunk-4DIBPQNJ.js → chunk-OR5ZA5WP.js} +135 -25
  100. package/dist/chunk-OR5ZA5WP.js.map +1 -0
  101. package/dist/{chunk-6HVOHZHS.cjs → chunk-PWGX5DF5.cjs} +213 -168
  102. package/dist/chunk-PWGX5DF5.cjs.map +1 -0
  103. package/dist/chunk-PZKNKG5M.js +1252 -0
  104. package/dist/chunk-PZKNKG5M.js.map +1 -0
  105. package/dist/{chunk-DEQFL35G.js → chunk-Q5TEXCTB.js} +61 -7
  106. package/dist/chunk-Q5TEXCTB.js.map +1 -0
  107. package/dist/{chunk-QV245VMN.js → chunk-RAXU3RMB.js} +100 -6
  108. package/dist/chunk-RAXU3RMB.js.map +1 -0
  109. package/dist/{chunk-RHZWOJVA.cjs → chunk-RSSQKPSZ.cjs} +52 -4
  110. package/dist/chunk-RSSQKPSZ.cjs.map +1 -0
  111. package/dist/{chunk-G6SOJEDI.cjs → chunk-S55OV6PW.cjs} +15 -15
  112. package/dist/chunk-S55OV6PW.cjs.map +1 -0
  113. package/dist/chunk-S5F7ZLP2.js +94 -0
  114. package/dist/chunk-S5F7ZLP2.js.map +1 -0
  115. package/dist/{chunk-3E7SNSIA.cjs → chunk-SJDMVITW.cjs} +4 -4
  116. package/dist/{chunk-3E7SNSIA.cjs.map → chunk-SJDMVITW.cjs.map} +1 -1
  117. package/dist/{chunk-CHXTTSC6.js → chunk-SKCOUWAX.js} +104 -5
  118. package/dist/chunk-SKCOUWAX.js.map +1 -0
  119. package/dist/{chunk-XLUNB2TZ.js → chunk-SNXVDZAJ.js} +3 -3
  120. package/dist/{chunk-XLUNB2TZ.js.map → chunk-SNXVDZAJ.js.map} +1 -1
  121. package/dist/{chunk-ZURTTSCM.js → chunk-SXGE7ITL.js} +6 -94
  122. package/dist/chunk-SXGE7ITL.js.map +1 -0
  123. package/dist/{chunk-RBV7YCQD.js → chunk-T2WUSPDA.js} +49 -9
  124. package/dist/chunk-T2WUSPDA.js.map +1 -0
  125. package/dist/{chunk-KGC4LY5T.cjs → chunk-TCOCYN2P.cjs} +75 -21
  126. package/dist/chunk-TCOCYN2P.cjs.map +1 -0
  127. package/dist/{chunk-FLRCVI2G.cjs → chunk-TDXIBCGY.cjs} +2 -2
  128. package/dist/{chunk-FLRCVI2G.cjs.map → chunk-TDXIBCGY.cjs.map} +1 -1
  129. package/dist/{chunk-ZY4GXIVN.cjs → chunk-TEDRJXOG.cjs} +5 -5
  130. package/dist/{chunk-ZY4GXIVN.cjs.map → chunk-TEDRJXOG.cjs.map} +1 -1
  131. package/dist/{chunk-WL2SG7ZV.cjs → chunk-UMDVATGY.cjs} +6 -6
  132. package/dist/{chunk-WL2SG7ZV.cjs.map → chunk-UMDVATGY.cjs.map} +1 -1
  133. package/dist/chunk-UT3S4SEN.js +31 -0
  134. package/dist/chunk-UT3S4SEN.js.map +1 -0
  135. package/dist/{chunk-RRKQAKD6.cjs → chunk-UUT7UN2N.cjs} +149 -39
  136. package/dist/chunk-UUT7UN2N.cjs.map +1 -0
  137. package/dist/{chunk-SHLY4MCM.js → chunk-UZV3AZKF.js} +21 -3
  138. package/dist/chunk-UZV3AZKF.js.map +1 -0
  139. package/dist/{chunk-CYX2JTDG.js → chunk-VHMPG6UL.js} +29 -7
  140. package/dist/chunk-VHMPG6UL.js.map +1 -0
  141. package/dist/{chunk-LANHCOXB.js → chunk-VQEXF5D4.js} +485 -83
  142. package/dist/chunk-VQEXF5D4.js.map +1 -0
  143. package/dist/{chunk-K34OPSJK.js → chunk-W63OVYY4.js} +3 -3
  144. package/dist/{chunk-K34OPSJK.js.map → chunk-W63OVYY4.js.map} +1 -1
  145. package/dist/{chunk-TQOYM4LN.js → chunk-WI7ISNQF.js} +35 -5
  146. package/dist/chunk-WI7ISNQF.js.map +1 -0
  147. package/dist/{chunk-UNNPKQUG.cjs → chunk-X4JBT642.cjs} +246 -155
  148. package/dist/chunk-X4JBT642.cjs.map +1 -0
  149. package/dist/chunk-ZAMFOJ5P.cjs +1176 -0
  150. package/dist/chunk-ZAMFOJ5P.cjs.map +1 -0
  151. package/dist/{chunk-T46GR2VY.js → chunk-ZIGXMKQQ.js} +3 -3
  152. package/dist/{chunk-T46GR2VY.js.map → chunk-ZIGXMKQQ.js.map} +1 -1
  153. package/dist/{chunk-5IQIX7LU.cjs → chunk-ZUNQ5BEP.cjs} +518 -172
  154. package/dist/chunk-ZUNQ5BEP.cjs.map +1 -0
  155. package/dist/{ddl-BrmPg61z.d.ts → ddl-C2rZ-Aen.d.ts} +4 -4
  156. package/dist/{ddl-j1-sH6lE.d.cts → ddl-CZz7a0E8.d.cts} +4 -4
  157. package/dist/{extension-types-YGFJPrzK.d.cts → extension-types-ixRpJVUp.d.cts} +24 -1
  158. package/dist/{extension-types-YGFJPrzK.d.ts → extension-types-ixRpJVUp.d.ts} +24 -1
  159. package/dist/{types-DkNnF-7K.d.cts → fulltext-strategy-B57yvC5Q.d.ts} +2562 -2133
  160. package/dist/{types-D1Sqeyxy.d.ts → fulltext-strategy-CDkSSYhq.d.cts} +2562 -2133
  161. package/dist/graph-extension/index.cjs +20 -19
  162. package/dist/graph-extension/index.d.cts +4 -4
  163. package/dist/graph-extension/index.d.ts +4 -4
  164. package/dist/graph-extension/index.js +5 -4
  165. package/dist/graph-merge/index.cjs +255 -164
  166. package/dist/graph-merge/index.cjs.map +1 -1
  167. package/dist/graph-merge/index.d.cts +63 -33
  168. package/dist/graph-merge/index.d.ts +63 -33
  169. package/dist/graph-merge/index.js +135 -44
  170. package/dist/graph-merge/index.js.map +1 -1
  171. package/dist/{index-DGX6D9j1.d.ts → index-BFvdmBPV.d.ts} +301 -93
  172. package/dist/{index-SEvUHDA6.d.cts → index-BLtQWKRj.d.cts} +301 -93
  173. package/dist/index.cjs +216 -188
  174. package/dist/index.d.cts +11 -11
  175. package/dist/index.d.ts +11 -11
  176. package/dist/index.js +33 -33
  177. package/dist/indexes/index.cjs +19 -20
  178. package/dist/indexes/index.d.cts +5 -5
  179. package/dist/indexes/index.d.ts +5 -5
  180. package/dist/indexes/index.js +10 -11
  181. package/dist/interchange/index.cjs +48 -26
  182. package/dist/interchange/index.d.cts +126 -12
  183. package/dist/interchange/index.d.ts +126 -12
  184. package/dist/interchange/index.js +15 -13
  185. package/dist/{manager-ms9cKdc6.d.cts → manager-DwQi8eV0.d.cts} +9 -2
  186. package/dist/{manager-BZUeN_BU.d.ts → manager-ejUCB52T.d.ts} +9 -2
  187. package/dist/{materialize-indexes-D20xNluI.d.cts → materialize-indexes-B4e9360H.d.cts} +20 -4
  188. package/dist/{materialize-indexes-CAkIYFV-.d.ts → materialize-indexes-te9TPMMJ.d.ts} +20 -4
  189. package/dist/{postgres-BhpxGMC5.d.cts → postgres-CfEqsRMp.d.cts} +152 -1
  190. package/dist/{postgres-CWHLwNl1.d.ts → postgres-DQ5R6rzV.d.ts} +152 -1
  191. package/dist/profiler/index.cjs +11 -11
  192. package/dist/profiler/index.d.cts +7 -7
  193. package/dist/profiler/index.d.ts +7 -7
  194. package/dist/profiler/index.js +4 -4
  195. package/dist/provenance/index.cjs +40 -41
  196. package/dist/provenance/index.cjs.map +1 -1
  197. package/dist/provenance/index.d.cts +5 -5
  198. package/dist/provenance/index.d.ts +5 -5
  199. package/dist/provenance/index.js +11 -12
  200. package/dist/provenance/index.js.map +1 -1
  201. package/dist/schema/index.cjs +53 -40
  202. package/dist/schema/index.cjs.map +1 -1
  203. package/dist/schema/index.d.cts +57 -57
  204. package/dist/schema/index.d.ts +57 -57
  205. package/dist/schema/index.js +28 -15
  206. package/dist/schema/index.js.map +1 -1
  207. package/dist/{sqlite-XrDxNaa7.d.cts → sqlite-D7zBinNR.d.cts} +92 -1
  208. package/dist/{sqlite-CGu5SLsw.d.ts → sqlite-DvQndLky.d.ts} +92 -1
  209. package/dist/{store-view-D09po4H6.d.cts → store-view-9KDOpZzF.d.cts} +643 -58
  210. package/dist/{store-view-BlgnhEYf.d.ts → store-view-DplHC3Nt.d.ts} +643 -58
  211. package/dist/{types-DiE1AO7p.d.cts → types-Bv9DcS_E.d.cts} +2 -2
  212. package/dist/{types-B1TbZJYS.d.ts → types-CoxuV7EJ.d.ts} +2 -2
  213. package/dist/{where-DKjuofPr.d.cts → where-7RKFOsXt.d.ts} +2 -2
  214. package/dist/{where-DrUIIWHb.d.ts → where-DdMIXOtH.d.cts} +2 -2
  215. package/package.json +14 -13
  216. package/dist/chunk-2EBMPJBO.js +0 -16
  217. package/dist/chunk-2EBMPJBO.js.map +0 -1
  218. package/dist/chunk-2JXB3NYJ.cjs.map +0 -1
  219. package/dist/chunk-2MRAX3UE.js.map +0 -1
  220. package/dist/chunk-3BRVBQQD.cjs.map +0 -1
  221. package/dist/chunk-3EUKJEQ3.js +0 -77
  222. package/dist/chunk-3EUKJEQ3.js.map +0 -1
  223. package/dist/chunk-3Z6TW3CT.cjs.map +0 -1
  224. package/dist/chunk-4DIBPQNJ.js.map +0 -1
  225. package/dist/chunk-4S2FXGBJ.js +0 -9
  226. package/dist/chunk-4S2FXGBJ.js.map +0 -1
  227. package/dist/chunk-5IQIX7LU.cjs.map +0 -1
  228. package/dist/chunk-6GNSY7AV.js.map +0 -1
  229. package/dist/chunk-6HVOHZHS.cjs.map +0 -1
  230. package/dist/chunk-6SCVW4AS.js +0 -20
  231. package/dist/chunk-6SCVW4AS.js.map +0 -1
  232. package/dist/chunk-A7SZZFAG.js.map +0 -1
  233. package/dist/chunk-CHXTTSC6.js.map +0 -1
  234. package/dist/chunk-CYX2JTDG.js.map +0 -1
  235. package/dist/chunk-DEQFL35G.js.map +0 -1
  236. package/dist/chunk-G6SOJEDI.cjs.map +0 -1
  237. package/dist/chunk-GQANNXXT.cjs.map +0 -1
  238. package/dist/chunk-GZCNZ7QW.js +0 -24
  239. package/dist/chunk-GZCNZ7QW.js.map +0 -1
  240. package/dist/chunk-HK5SATYM.cjs.map +0 -1
  241. package/dist/chunk-HMFK4BXR.cjs +0 -12
  242. package/dist/chunk-HTGDWIDE.cjs +0 -89
  243. package/dist/chunk-HTGDWIDE.cjs.map +0 -1
  244. package/dist/chunk-JIEJCTDS.cjs.map +0 -1
  245. package/dist/chunk-JJRCLAUN.cjs.map +0 -1
  246. package/dist/chunk-JQGIPGVL.cjs.map +0 -1
  247. package/dist/chunk-K2TGS3EN.js.map +0 -1
  248. package/dist/chunk-KGC4LY5T.cjs.map +0 -1
  249. package/dist/chunk-KNHYNQQ3.cjs +0 -663
  250. package/dist/chunk-KNHYNQQ3.cjs.map +0 -1
  251. package/dist/chunk-KUTNI6SI.js.map +0 -1
  252. package/dist/chunk-LANHCOXB.js.map +0 -1
  253. package/dist/chunk-N6WTUSBV.cjs +0 -23
  254. package/dist/chunk-N6WTUSBV.cjs.map +0 -1
  255. package/dist/chunk-NAUA4PW5.cjs +0 -28
  256. package/dist/chunk-NAUA4PW5.cjs.map +0 -1
  257. package/dist/chunk-QV245VMN.js.map +0 -1
  258. package/dist/chunk-RBV7YCQD.js.map +0 -1
  259. package/dist/chunk-RHZWOJVA.cjs.map +0 -1
  260. package/dist/chunk-RRKQAKD6.cjs.map +0 -1
  261. package/dist/chunk-RY2VIWAM.js.map +0 -1
  262. package/dist/chunk-SHLY4MCM.js.map +0 -1
  263. package/dist/chunk-T2DWPQNE.js +0 -649
  264. package/dist/chunk-T2DWPQNE.js.map +0 -1
  265. package/dist/chunk-T6SPUYLX.cjs.map +0 -1
  266. package/dist/chunk-TGJE22RM.cjs.map +0 -1
  267. package/dist/chunk-TOTPVGOG.cjs +0 -774
  268. package/dist/chunk-TOTPVGOG.cjs.map +0 -1
  269. package/dist/chunk-TQOYM4LN.js.map +0 -1
  270. package/dist/chunk-UJLOZYKT.cjs.map +0 -1
  271. package/dist/chunk-UNNPKQUG.cjs.map +0 -1
  272. package/dist/chunk-V3QNTB7Z.js.map +0 -1
  273. package/dist/chunk-VCGO4V26.js.map +0 -1
  274. package/dist/chunk-WLRIWYHQ.js.map +0 -1
  275. package/dist/chunk-WVC2Q2FD.cjs.map +0 -1
  276. package/dist/chunk-XXVEULWX.js +0 -39
  277. package/dist/chunk-XXVEULWX.js.map +0 -1
  278. package/dist/chunk-YAZE7QZR.cjs +0 -32
  279. package/dist/chunk-YAZE7QZR.cjs.map +0 -1
  280. package/dist/chunk-YC6PWTHY.cjs +0 -44
  281. package/dist/chunk-YC6PWTHY.cjs.map +0 -1
  282. package/dist/chunk-Z5HBYM7U.cjs +0 -11
  283. package/dist/chunk-Z5HBYM7U.cjs.map +0 -1
  284. package/dist/chunk-Z5XBMDXU.js.map +0 -1
  285. package/dist/chunk-ZP5WHI4C.cjs.map +0 -1
  286. package/dist/chunk-ZURTTSCM.js.map +0 -1
  287. package/dist/chunk-ZV5N4DBG.js.map +0 -1
@@ -0,0 +1,1366 @@
1
+ 'use strict';
2
+
3
+ var chunk2THZ3TQI_cjs = require('./chunk-2THZ3TQI.cjs');
4
+ var chunkACSVZPK7_cjs = require('./chunk-ACSVZPK7.cjs');
5
+ var chunkD7ZEOS56_cjs = require('./chunk-D7ZEOS56.cjs');
6
+ var chunk4BCU6VFZ_cjs = require('./chunk-4BCU6VFZ.cjs');
7
+ var chunkZUNQ5BEP_cjs = require('./chunk-ZUNQ5BEP.cjs');
8
+ var chunkEOLERH7Y_cjs = require('./chunk-EOLERH7Y.cjs');
9
+ var chunkX4JBT642_cjs = require('./chunk-X4JBT642.cjs');
10
+ var chunkRSSQKPSZ_cjs = require('./chunk-RSSQKPSZ.cjs');
11
+ var chunkDIK74MXX_cjs = require('./chunk-DIK74MXX.cjs');
12
+ var chunkTDXIBCGY_cjs = require('./chunk-TDXIBCGY.cjs');
13
+ var drizzleOrm = require('drizzle-orm');
14
+
15
+ // src/store/row-mappers.ts
16
+ function nullToUndefined(value) {
17
+ return value === null ? void 0 : value;
18
+ }
19
+ function rowToNode(row) {
20
+ const rawProps = chunkX4JBT642_cjs.rowPropsToObject(row.props);
21
+ const props = chunk4BCU6VFZ_cjs.filterReservedKeys(rawProps, chunk4BCU6VFZ_cjs.RESERVED_NODE_KEYS);
22
+ return {
23
+ kind: row.kind,
24
+ id: row.id,
25
+ meta: rowToNodeMeta(row),
26
+ ...props
27
+ };
28
+ }
29
+ function rowToNodeMeta(row) {
30
+ return {
31
+ version: row.version,
32
+ validFrom: nullToUndefined(row.valid_from),
33
+ validTo: nullToUndefined(row.valid_to),
34
+ createdAt: row.created_at,
35
+ updatedAt: row.updated_at,
36
+ deletedAt: nullToUndefined(row.deleted_at)
37
+ };
38
+ }
39
+ function rowToEdge(row) {
40
+ const rawProps = chunkX4JBT642_cjs.rowPropsToObject(row.props);
41
+ const props = chunk4BCU6VFZ_cjs.filterReservedKeys(rawProps, chunk4BCU6VFZ_cjs.RESERVED_EDGE_KEYS);
42
+ return {
43
+ id: row.id,
44
+ kind: row.kind,
45
+ fromKind: row.from_kind,
46
+ fromId: row.from_id,
47
+ toKind: row.to_kind,
48
+ toId: row.to_id,
49
+ meta: rowToEdgeMeta(row),
50
+ ...props
51
+ };
52
+ }
53
+ function rowToEdgeMeta(row) {
54
+ return {
55
+ validFrom: nullToUndefined(row.valid_from),
56
+ validTo: nullToUndefined(row.valid_to),
57
+ createdAt: row.created_at,
58
+ updatedAt: row.updated_at,
59
+ deletedAt: nullToUndefined(row.deleted_at)
60
+ };
61
+ }
62
+
63
+ // src/store/operations/write-transaction.ts
64
+ function runInWriteTransaction(ctx, backend, fn) {
65
+ const ownsWriteLock = "transaction" in backend && backend.capabilities.transactions;
66
+ return chunkX4JBT642_cjs.runOptionallyInTransaction(backend, async (target) => {
67
+ const lock = ctx.historyEnabled || ctx.revisionTrackingEnabled ? await chunkZUNQ5BEP_cjs.lockRecordedGraphWrite(target, ctx.graphId) : chunkZUNQ5BEP_cjs.uncapturedGraphWriteLock();
68
+ const result = await fn(target, lock);
69
+ if (ctx.revisionTrackingEnabled && !ctx.historyEnabled) {
70
+ await chunkZUNQ5BEP_cjs.advanceRevisionClock(
71
+ target,
72
+ ctx.revisionSchema,
73
+ ctx.graphId,
74
+ ownsWriteLock
75
+ );
76
+ }
77
+ return result;
78
+ });
79
+ }
80
+ function runHookedWriteOperation(ctx, opContext, backend, body) {
81
+ return ctx.withOperationHooks(
82
+ opContext,
83
+ () => runInWriteTransaction(ctx, backend, body)
84
+ );
85
+ }
86
+
87
+ // src/store/constraints.ts
88
+ async function checkDisjointnessConstraint(ctx, kind, id) {
89
+ const disjointKinds = ctx.registry.getDisjointKinds(kind);
90
+ for (const disjointKind of disjointKinds) {
91
+ const existing = await ctx.backend.getNode(ctx.graphId, disjointKind, id);
92
+ if (existing && !existing.deleted_at) {
93
+ const error = chunkZUNQ5BEP_cjs.checkDisjointness(id, kind, [disjointKind], ctx.registry);
94
+ if (error) throw error;
95
+ }
96
+ }
97
+ }
98
+ async function checkCardinalityConstraint(ctx, edgeKind, cardinality, fromKind, fromId, toKind, toId, validTo) {
99
+ switch (cardinality) {
100
+ case "many": {
101
+ return;
102
+ }
103
+ case "one": {
104
+ const count = await ctx.backend.countEdgesFrom({
105
+ graphId: ctx.graphId,
106
+ edgeKind,
107
+ fromKind,
108
+ fromId
109
+ });
110
+ const error = chunkZUNQ5BEP_cjs.checkCardinality(
111
+ edgeKind,
112
+ fromKind,
113
+ fromId,
114
+ "one",
115
+ count,
116
+ false
117
+ );
118
+ if (error) throw error;
119
+ return;
120
+ }
121
+ case "unique": {
122
+ const exists = await ctx.backend.edgeExistsBetween({
123
+ graphId: ctx.graphId,
124
+ edgeKind,
125
+ fromKind,
126
+ fromId,
127
+ toKind,
128
+ toId
129
+ });
130
+ const error = chunkZUNQ5BEP_cjs.checkUniqueEdge(
131
+ edgeKind,
132
+ fromKind,
133
+ fromId,
134
+ toKind,
135
+ toId,
136
+ exists ? 1 : 0
137
+ );
138
+ if (error) throw error;
139
+ return;
140
+ }
141
+ case "oneActive": {
142
+ if (validTo !== void 0) {
143
+ return;
144
+ }
145
+ const count = await ctx.backend.countEdgesFrom({
146
+ graphId: ctx.graphId,
147
+ edgeKind,
148
+ fromKind,
149
+ fromId,
150
+ activeOnly: true
151
+ });
152
+ const error = chunkZUNQ5BEP_cjs.checkCardinality(
153
+ edgeKind,
154
+ fromKind,
155
+ fromId,
156
+ "oneActive",
157
+ count,
158
+ count > 0
159
+ );
160
+ if (error) throw error;
161
+ return;
162
+ }
163
+ }
164
+ }
165
+
166
+ // src/store/operations/node-operations.ts
167
+ function getNodeRegistration(graph, kind) {
168
+ const registration = graph.nodes[kind];
169
+ if (registration === void 0) throw new chunkDIK74MXX_cjs.KindNotFoundError(kind, "node");
170
+ return registration;
171
+ }
172
+ var CACHE_KEY_SEPARATOR = "\0";
173
+ function buildNodeCacheKey(graphId, kind, id) {
174
+ return `${graphId}${CACHE_KEY_SEPARATOR}${kind}${CACHE_KEY_SEPARATOR}${id}`;
175
+ }
176
+ function buildUniqueCacheKey(graphId, nodeKind, constraintName, key) {
177
+ return `${graphId}${CACHE_KEY_SEPARATOR}${nodeKind}${CACHE_KEY_SEPARATOR}${constraintName}${CACHE_KEY_SEPARATOR}${key}`;
178
+ }
179
+ function createNodeAlreadyExistsError(kind, id) {
180
+ return new chunkDIK74MXX_cjs.ValidationError(
181
+ `Node already exists: ${kind}/${id}`,
182
+ {
183
+ entityType: "node",
184
+ kind,
185
+ operation: "create",
186
+ id,
187
+ issues: [{ path: "id", message: "A node with this ID already exists" }]
188
+ },
189
+ { suggestion: `Use a different ID or update the existing node.` }
190
+ );
191
+ }
192
+ function buildInsertNodeParams(graphId, kind, id, props, validFrom, validTo) {
193
+ const insertParams = {
194
+ graphId,
195
+ kind,
196
+ id,
197
+ props
198
+ };
199
+ if (validFrom !== void 0) insertParams.validFrom = validFrom;
200
+ if (validTo !== void 0) insertParams.validTo = validTo;
201
+ return insertParams;
202
+ }
203
+ function createPendingUniqueRow(graphId, nodeKind, constraintName, key, nodeId) {
204
+ return {
205
+ graph_id: graphId,
206
+ node_kind: nodeKind,
207
+ constraint_name: constraintName,
208
+ key,
209
+ node_id: nodeId,
210
+ concrete_kind: nodeKind,
211
+ deleted_at: void 0
212
+ };
213
+ }
214
+ function resolveConstraint(graph, kind, constraintName) {
215
+ const registration = getNodeRegistration(graph, kind);
216
+ const constraints = registration.unique ?? [];
217
+ const constraint = constraints.find(
218
+ (candidate) => candidate.name === constraintName
219
+ );
220
+ if (constraint === void 0) {
221
+ throw new chunkDIK74MXX_cjs.NodeConstraintNotFoundError(constraintName, kind);
222
+ }
223
+ return constraint;
224
+ }
225
+ function createNodeBatchValidationBackend(graphId, registry, backend) {
226
+ const nodeCache = /* @__PURE__ */ new Map();
227
+ const pendingNodes = /* @__PURE__ */ new Map();
228
+ const uniqueCache = /* @__PURE__ */ new Map();
229
+ const pendingUniqueOwners = /* @__PURE__ */ new Map();
230
+ async function getNodeCached(lookupGraphId, kind, id) {
231
+ const cacheKey = buildNodeCacheKey(lookupGraphId, kind, id);
232
+ const pendingNode = pendingNodes.get(cacheKey);
233
+ if (pendingNode !== void 0) return pendingNode;
234
+ if (nodeCache.has(cacheKey)) return nodeCache.get(cacheKey);
235
+ const existing = await backend.getNode(lookupGraphId, kind, id);
236
+ nodeCache.set(cacheKey, existing);
237
+ return existing;
238
+ }
239
+ async function checkUniqueCached(params) {
240
+ const cacheKey = buildUniqueCacheKey(
241
+ params.graphId,
242
+ params.nodeKind,
243
+ params.constraintName,
244
+ params.key
245
+ );
246
+ const pendingOwner = pendingUniqueOwners.get(cacheKey);
247
+ if (pendingOwner !== void 0) {
248
+ return createPendingUniqueRow(
249
+ params.graphId,
250
+ params.nodeKind,
251
+ params.constraintName,
252
+ params.key,
253
+ pendingOwner
254
+ );
255
+ }
256
+ if (uniqueCache.has(cacheKey)) return uniqueCache.get(cacheKey);
257
+ const existing = await backend.checkUnique(params);
258
+ uniqueCache.set(cacheKey, existing);
259
+ return existing;
260
+ }
261
+ function registerPendingNode(params) {
262
+ const cacheKey = buildNodeCacheKey(params.graphId, params.kind, params.id);
263
+ pendingNodes.set(cacheKey, {
264
+ graph_id: params.graphId,
265
+ kind: params.kind,
266
+ id: params.id,
267
+ props: JSON.stringify(params.props),
268
+ version: 1,
269
+ // The simulated cached row only needs a NodeRow-shaped valid_from
270
+ // (string | undefined, never null) for existence/uniqueness checks,
271
+ // which don't inspect its value — normalize import's explicit-NULL
272
+ // sentinel away rather than widen this cache's row shape.
273
+ valid_from: params.validFrom ?? void 0,
274
+ valid_to: params.validTo,
275
+ created_at: "",
276
+ updated_at: "",
277
+ deleted_at: void 0
278
+ });
279
+ }
280
+ function registerPendingUniqueEntries(kind, id, props, constraints) {
281
+ for (const constraint of constraints) {
282
+ if (!chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, props)) continue;
283
+ const key = chunkZUNQ5BEP_cjs.computeUniqueKey(
284
+ props,
285
+ constraint.fields,
286
+ constraint.collation
287
+ );
288
+ const concreteEntryKey = buildUniqueCacheKey(
289
+ graphId,
290
+ kind,
291
+ constraint.name,
292
+ key
293
+ );
294
+ pendingUniqueOwners.set(concreteEntryKey, id);
295
+ if (constraint.scope !== "kind") {
296
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
297
+ kind,
298
+ constraint.scope,
299
+ registry
300
+ );
301
+ for (const kindToCheck of kindsToCheck) {
302
+ const inheritedEntryKey = buildUniqueCacheKey(
303
+ graphId,
304
+ kindToCheck,
305
+ constraint.name,
306
+ key
307
+ );
308
+ pendingUniqueOwners.set(inheritedEntryKey, id);
309
+ }
310
+ }
311
+ }
312
+ }
313
+ function registerAppliedNodeUpdate(kind, id, oldProps, newProps, constraints) {
314
+ for (const constraint of constraints) {
315
+ const oldApplies = chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, oldProps);
316
+ const newApplies = chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, newProps);
317
+ const oldKey = oldApplies ? chunkZUNQ5BEP_cjs.computeUniqueKey(oldProps, constraint.fields, constraint.collation) : void 0;
318
+ const newKey = newApplies ? chunkZUNQ5BEP_cjs.computeUniqueKey(newProps, constraint.fields, constraint.collation) : void 0;
319
+ if (oldKey === newKey) continue;
320
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
321
+ kind,
322
+ constraint.scope,
323
+ registry
324
+ );
325
+ if (oldKey !== void 0) {
326
+ for (const kindToCheck of kindsToCheck) {
327
+ const cacheKey = buildUniqueCacheKey(
328
+ graphId,
329
+ kindToCheck,
330
+ constraint.name,
331
+ oldKey
332
+ );
333
+ pendingUniqueOwners.delete(cacheKey);
334
+ uniqueCache.set(cacheKey, void 0);
335
+ }
336
+ }
337
+ if (newKey !== void 0) {
338
+ for (const kindToCheck of kindsToCheck) {
339
+ const cacheKey = buildUniqueCacheKey(
340
+ graphId,
341
+ kindToCheck,
342
+ constraint.name,
343
+ newKey
344
+ );
345
+ pendingUniqueOwners.set(cacheKey, id);
346
+ }
347
+ }
348
+ }
349
+ }
350
+ function seedNodeRow(kind, id, row) {
351
+ const cacheKey = buildNodeCacheKey(graphId, kind, id);
352
+ if (nodeCache.has(cacheKey)) return;
353
+ nodeCache.set(cacheKey, row);
354
+ }
355
+ function seedUniqueRow(kind, constraintName, key, row) {
356
+ const cacheKey = buildUniqueCacheKey(graphId, kind, constraintName, key);
357
+ if (uniqueCache.has(cacheKey)) return;
358
+ uniqueCache.set(cacheKey, row);
359
+ }
360
+ const validationBackend = chunkX4JBT642_cjs.createBackendOverlay(backend, {
361
+ getNode: getNodeCached,
362
+ checkUnique: checkUniqueCached
363
+ });
364
+ return {
365
+ backend: validationBackend,
366
+ registerPendingNode,
367
+ registerPendingUniqueEntries,
368
+ registerAppliedNodeUpdate,
369
+ seedNodeRow,
370
+ seedUniqueRow
371
+ };
372
+ }
373
+ function draftNodeCreate(ctx, input, id, options) {
374
+ const kind = input.kind;
375
+ const registration = getNodeRegistration(ctx.graph, kind);
376
+ const nodeKind = registration.type;
377
+ const validatedProps = options?.propsPreValidated === true ? input.props : chunk2THZ3TQI_cjs.validateNodeProps(nodeKind.schema, input.props, {
378
+ kind,
379
+ operation: "create"
380
+ });
381
+ return {
382
+ kind,
383
+ id,
384
+ nodeKind,
385
+ uniqueConstraints: registration.unique ?? [],
386
+ validatedProps,
387
+ validFrom: chunkRSSQKPSZ_cjs.validateOptionalCanonicalIsoDate(input.validFrom, "validFrom"),
388
+ validTo: chunkRSSQKPSZ_cjs.validateOptionalCanonicalIsoDate(input.validTo, "validTo")
389
+ };
390
+ }
391
+ async function finishNodeCreatePreparation(ctx, draft, backend) {
392
+ const { kind, id, validatedProps, uniqueConstraints } = draft;
393
+ const existingNode = await backend.getNode(ctx.graphId, kind, id);
394
+ if (existingNode && !existingNode.deleted_at) {
395
+ throw createNodeAlreadyExistsError(kind, id);
396
+ }
397
+ const constraintContext = {
398
+ graphId: ctx.graphId,
399
+ registry: ctx.registry,
400
+ backend
401
+ };
402
+ await checkDisjointnessConstraint(constraintContext, kind, id);
403
+ await chunkZUNQ5BEP_cjs.checkUniquenessConstraints(
404
+ chunkZUNQ5BEP_cjs.createUniquenessContext(ctx.graphId, ctx.registry, backend),
405
+ kind,
406
+ id,
407
+ validatedProps,
408
+ uniqueConstraints
409
+ );
410
+ return {
411
+ kind,
412
+ id,
413
+ nodeKind: draft.nodeKind,
414
+ validatedProps,
415
+ uniqueConstraints,
416
+ insertParams: buildInsertNodeParams(
417
+ ctx.graphId,
418
+ kind,
419
+ id,
420
+ validatedProps,
421
+ draft.validFrom,
422
+ draft.validTo
423
+ )
424
+ };
425
+ }
426
+ async function validateAndPrepareNodeCreate(ctx, input, id, backend, options) {
427
+ return finishNodeCreatePreparation(
428
+ ctx,
429
+ draftNodeCreate(ctx, input, id, options),
430
+ backend
431
+ );
432
+ }
433
+ async function finalizeNodeCreateBatch(ctx, preparedCreates, backend, lock) {
434
+ await chunkZUNQ5BEP_cjs.applyNodeInsertSideEffectsBatch(
435
+ chunkZUNQ5BEP_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
436
+ preparedCreates.map((prepared) => ({
437
+ kind: prepared.kind,
438
+ id: prepared.id,
439
+ schema: prepared.nodeKind.schema,
440
+ props: prepared.validatedProps,
441
+ uniqueConstraints: prepared.uniqueConstraints
442
+ })),
443
+ backend
444
+ );
445
+ }
446
+ async function finalizeNodeCreate(ctx, prepared, backend, lock) {
447
+ await chunkZUNQ5BEP_cjs.applyNodeInsertSideEffects(
448
+ chunkZUNQ5BEP_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
449
+ {
450
+ kind: prepared.kind,
451
+ id: prepared.id,
452
+ schema: prepared.nodeKind.schema,
453
+ props: prepared.validatedProps,
454
+ uniqueConstraints: prepared.uniqueConstraints
455
+ },
456
+ backend
457
+ );
458
+ }
459
+ function computeNodeUpdate(ctx, kind, id, existingProps, inputProps) {
460
+ const registration = getNodeRegistration(ctx.graph, kind);
461
+ const validatedProps = chunk2THZ3TQI_cjs.validateNodeProps(
462
+ registration.type.schema,
463
+ { ...existingProps, ...inputProps },
464
+ { kind, operation: "update", id }
465
+ );
466
+ return { registration, validatedProps };
467
+ }
468
+ function resolveNodeUpdateProps(ctx, existing, inputProps) {
469
+ const existingProps = chunkX4JBT642_cjs.rowPropsToObject(existing.props);
470
+ const { registration, validatedProps } = computeNodeUpdate(
471
+ ctx,
472
+ existing.kind,
473
+ existing.id,
474
+ existingProps,
475
+ inputProps
476
+ );
477
+ return { registration, existingProps, validatedProps };
478
+ }
479
+ function nodeUpsertDirtyCheck(ctx, kind, id, existingProps, inputProps) {
480
+ const { validatedProps } = computeNodeUpdate(
481
+ ctx,
482
+ kind,
483
+ id,
484
+ existingProps,
485
+ inputProps
486
+ );
487
+ return {
488
+ validatedProps,
489
+ unchanged: chunkACSVZPK7_cjs.canonicalEqual(validatedProps, existingProps)
490
+ };
491
+ }
492
+ async function performNodeUpdate(ctx, input, backend, lock, options) {
493
+ const { kind, id } = input;
494
+ const existing = await backend.getNode(ctx.graphId, kind, id);
495
+ if (!existing) throw new chunkDIK74MXX_cjs.NodeNotFoundError(kind, id);
496
+ const { registration, validatedProps } = resolveNodeUpdateProps(
497
+ ctx,
498
+ existing,
499
+ input.props
500
+ );
501
+ const nodeKind = registration.type;
502
+ const validTo = chunkRSSQKPSZ_cjs.validateOptionalCanonicalIsoDate(input.validTo, "validTo");
503
+ const writeContext = chunkZUNQ5BEP_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock);
504
+ const shared = {
505
+ schema: nodeKind.schema,
506
+ validatedProps,
507
+ uniqueConstraints: registration.unique ?? [],
508
+ ...validTo !== void 0 && { validTo }
509
+ };
510
+ if (options?.clearDeleted) {
511
+ const row2 = await chunkZUNQ5BEP_cjs.applyNodeUpdate(
512
+ writeContext,
513
+ { ...shared, existing, clearDeleted: true },
514
+ backend
515
+ );
516
+ return rowToNode(row2);
517
+ }
518
+ if (!chunkX4JBT642_cjs.isLiveNodeRow(existing)) throw new chunkDIK74MXX_cjs.NodeNotFoundError(kind, id);
519
+ const row = await chunkZUNQ5BEP_cjs.applyNodeUpdate(
520
+ writeContext,
521
+ { ...shared, existing },
522
+ backend
523
+ );
524
+ return rowToNode(row);
525
+ }
526
+ async function primeBatchValidationCaches(ctx, drafts, backend, seams) {
527
+ if (backend.getNodes !== void 0) {
528
+ const idsByKind = /* @__PURE__ */ new Map();
529
+ for (const draft of drafts) {
530
+ const ids = idsByKind.get(draft.kind) ?? /* @__PURE__ */ new Set();
531
+ ids.add(draft.id);
532
+ idsByKind.set(draft.kind, ids);
533
+ }
534
+ for (const [kind, ids] of idsByKind) {
535
+ const orderedIds = [...ids];
536
+ const rows = await backend.getNodes(ctx.graphId, kind, orderedIds);
537
+ const rowsById = new Map(rows.map((row) => [row.id, row]));
538
+ for (const id of orderedIds) {
539
+ seams.seedNodeRow(kind, id, rowsById.get(id));
540
+ }
541
+ }
542
+ }
543
+ if (backend.checkUniqueBatch !== void 0) {
544
+ const groups = /* @__PURE__ */ new Map();
545
+ for (const draft of drafts) {
546
+ for (const constraint of draft.uniqueConstraints) {
547
+ if (!chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, draft.validatedProps)) continue;
548
+ const key = chunkZUNQ5BEP_cjs.computeUniqueKey(
549
+ draft.validatedProps,
550
+ constraint.fields,
551
+ constraint.collation
552
+ );
553
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
554
+ draft.kind,
555
+ constraint.scope,
556
+ ctx.registry
557
+ );
558
+ for (const kindToCheck of kindsToCheck) {
559
+ const groupKey = kindToCheck + CACHE_KEY_SEPARATOR + constraint.name;
560
+ const group = groups.get(groupKey) ?? {
561
+ nodeKind: kindToCheck,
562
+ constraintName: constraint.name,
563
+ keys: /* @__PURE__ */ new Set()
564
+ };
565
+ group.keys.add(key);
566
+ groups.set(groupKey, group);
567
+ }
568
+ }
569
+ }
570
+ for (const group of groups.values()) {
571
+ const orderedKeys = [...group.keys];
572
+ const rows = await backend.checkUniqueBatch({
573
+ graphId: ctx.graphId,
574
+ nodeKind: group.nodeKind,
575
+ constraintName: group.constraintName,
576
+ keys: orderedKeys
577
+ });
578
+ const rowsByKey = new Map(rows.map((row) => [row.key, row]));
579
+ for (const key of orderedKeys) {
580
+ seams.seedUniqueRow(
581
+ group.nodeKind,
582
+ group.constraintName,
583
+ key,
584
+ rowsByKey.get(key)
585
+ );
586
+ }
587
+ }
588
+ }
589
+ }
590
+ async function prepareBatchCreates(ctx, inputs, backend, options) {
591
+ const {
592
+ backend: validationBackend,
593
+ registerPendingNode,
594
+ registerPendingUniqueEntries,
595
+ seedNodeRow,
596
+ seedUniqueRow
597
+ } = createNodeBatchValidationBackend(ctx.graphId, ctx.registry, backend);
598
+ const drafts = inputs.map(
599
+ (input) => draftNodeCreate(ctx, input, input.id ?? chunkZUNQ5BEP_cjs.generateId(), options)
600
+ );
601
+ await primeBatchValidationCaches(ctx, drafts, backend, {
602
+ seedNodeRow,
603
+ seedUniqueRow
604
+ });
605
+ const preparedCreates = [];
606
+ for (const draft of drafts) {
607
+ const prepared = await finishNodeCreatePreparation(
608
+ ctx,
609
+ draft,
610
+ validationBackend
611
+ );
612
+ preparedCreates.push(prepared);
613
+ registerPendingNode(prepared.insertParams);
614
+ registerPendingUniqueEntries(
615
+ prepared.kind,
616
+ prepared.id,
617
+ prepared.validatedProps,
618
+ prepared.uniqueConstraints
619
+ );
620
+ }
621
+ const batchInsertParams = preparedCreates.map(
622
+ (prepared) => prepared.insertParams
623
+ );
624
+ return { preparedCreates, batchInsertParams };
625
+ }
626
+ async function findUniqueRowAcrossKinds(backend, graphId, constraintName, key, kindsToCheck, includeDeleted) {
627
+ for (const kindToCheck of kindsToCheck) {
628
+ const row = await backend.checkUnique({
629
+ graphId,
630
+ nodeKind: kindToCheck,
631
+ constraintName,
632
+ key,
633
+ includeDeleted
634
+ });
635
+ if (row !== void 0) return row;
636
+ }
637
+ return void 0;
638
+ }
639
+ async function batchCheckUniqueAcrossKinds(backend, graphId, constraintName, uniqueKeys, kindsToCheck, includeDeleted) {
640
+ const existingByKey = /* @__PURE__ */ new Map();
641
+ for (const kindToCheck of kindsToCheck) {
642
+ if (backend.checkUniqueBatch === void 0) {
643
+ for (const key of uniqueKeys) {
644
+ if (existingByKey.has(key)) continue;
645
+ const row = await backend.checkUnique({
646
+ graphId,
647
+ nodeKind: kindToCheck,
648
+ constraintName,
649
+ key,
650
+ includeDeleted
651
+ });
652
+ if (row !== void 0) {
653
+ existingByKey.set(row.key, row);
654
+ }
655
+ }
656
+ } else {
657
+ const rows = await backend.checkUniqueBatch({
658
+ graphId,
659
+ nodeKind: kindToCheck,
660
+ constraintName,
661
+ keys: uniqueKeys,
662
+ includeDeleted
663
+ });
664
+ for (const row of rows) {
665
+ if (!existingByKey.has(row.key)) {
666
+ existingByKey.set(row.key, row);
667
+ }
668
+ }
669
+ }
670
+ }
671
+ return existingByKey;
672
+ }
673
+ async function executeNodeCreateInternal(ctx, input, backend, options) {
674
+ const kind = input.kind;
675
+ const id = input.id ?? chunkZUNQ5BEP_cjs.generateId();
676
+ const opContext = ctx.createOperationContext("create", "node", kind, id);
677
+ const shouldReturnRow = options?.returnRow ?? true;
678
+ return runHookedWriteOperation(
679
+ ctx,
680
+ opContext,
681
+ backend,
682
+ async (target, lock) => {
683
+ const prepared = await validateAndPrepareNodeCreate(
684
+ ctx,
685
+ input,
686
+ id,
687
+ target,
688
+ options
689
+ );
690
+ let row;
691
+ if (shouldReturnRow) {
692
+ row = await target.insertNode(prepared.insertParams);
693
+ } else {
694
+ await chunkZUNQ5BEP_cjs.runInsertNoReturn(
695
+ chunkZUNQ5BEP_cjs.nodeInsertDispatch(target),
696
+ prepared.insertParams
697
+ );
698
+ }
699
+ await finalizeNodeCreate(ctx, prepared, target, lock);
700
+ if (row === void 0) return;
701
+ return rowToNode(row);
702
+ }
703
+ );
704
+ }
705
+ async function executeNodeCreate(ctx, input, backend, options) {
706
+ const result = await executeNodeCreateInternal(ctx, input, backend, {
707
+ returnRow: true,
708
+ ...options
709
+ });
710
+ if (!result) {
711
+ throw new chunkDIK74MXX_cjs.DatabaseOperationError(
712
+ "Node create failed: expected created node row",
713
+ { operation: "insert", entity: "node" }
714
+ );
715
+ }
716
+ return result;
717
+ }
718
+ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
719
+ if (inputs.length === 0) return;
720
+ await runInWriteTransaction(ctx, backend, async (target, lock) => {
721
+ const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
722
+ ctx,
723
+ inputs,
724
+ target
725
+ );
726
+ await chunkZUNQ5BEP_cjs.runInsertBatch(chunkZUNQ5BEP_cjs.nodeInsertDispatch(target), batchInsertParams);
727
+ await finalizeNodeCreateBatch(ctx, preparedCreates, target, lock);
728
+ });
729
+ }
730
+ async function executeNodeCreateBatch(ctx, inputs, backend, options) {
731
+ if (inputs.length === 0) return [];
732
+ return runInWriteTransaction(ctx, backend, async (target, lock) => {
733
+ const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
734
+ ctx,
735
+ inputs,
736
+ target,
737
+ options
738
+ );
739
+ const rows = await chunkZUNQ5BEP_cjs.runInsertBatchReturning(
740
+ chunkZUNQ5BEP_cjs.nodeInsertDispatch(target),
741
+ batchInsertParams
742
+ );
743
+ await finalizeNodeCreateBatch(ctx, preparedCreates, target, lock);
744
+ return rows.map((row) => rowToNode(row));
745
+ });
746
+ }
747
+ async function executeNodeUpdate(ctx, input, backend, options) {
748
+ const opContext = ctx.createOperationContext(
749
+ "update",
750
+ "node",
751
+ input.kind,
752
+ input.id
753
+ );
754
+ return runHookedWriteOperation(
755
+ ctx,
756
+ opContext,
757
+ backend,
758
+ (target, lock) => performNodeUpdate(ctx, input, target, lock, options)
759
+ );
760
+ }
761
+ async function executeNodeUpsertUpdate(ctx, input, backend, options) {
762
+ return runInWriteTransaction(
763
+ ctx,
764
+ backend,
765
+ (target, lock) => performNodeUpdate(ctx, input, target, lock, options)
766
+ );
767
+ }
768
+ async function executeNodeDelete(ctx, kind, id, backend) {
769
+ const gate = await backend.getNode(ctx.graphId, kind, id);
770
+ if (!gate || gate.deleted_at) return;
771
+ const opContext = ctx.createOperationContext("delete", "node", kind, id);
772
+ return runHookedWriteOperation(
773
+ ctx,
774
+ opContext,
775
+ backend,
776
+ async (target, lock) => {
777
+ const registration = getNodeRegistration(ctx.graph, kind);
778
+ const preflight = await target.getNode(ctx.graphId, kind, id);
779
+ if (!preflight || !chunkX4JBT642_cjs.isLiveNodeRow(preflight)) return;
780
+ await chunkZUNQ5BEP_cjs.applyNodeSoftDelete(
781
+ chunkZUNQ5BEP_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
782
+ {
783
+ existing: preflight,
784
+ schema: registration.type.schema,
785
+ uniqueConstraints: registration.unique ?? [],
786
+ onDelete: registration.onDelete
787
+ },
788
+ target
789
+ );
790
+ }
791
+ );
792
+ }
793
+ async function executeNodeHardDelete(ctx, kind, id, backend) {
794
+ const gate = await backend.getNode(ctx.graphId, kind, id);
795
+ if (!gate) return;
796
+ const opContext = ctx.createOperationContext("delete", "node", kind, id);
797
+ return runHookedWriteOperation(
798
+ ctx,
799
+ opContext,
800
+ backend,
801
+ async (target, lock) => {
802
+ const registration = getNodeRegistration(ctx.graph, kind);
803
+ await chunkZUNQ5BEP_cjs.applyNodeHardDelete(
804
+ chunkZUNQ5BEP_cjs.createNodeWriteContext(ctx.graphId, ctx.registry, lock),
805
+ {
806
+ kind,
807
+ id,
808
+ schema: registration.type.schema,
809
+ onDelete: registration.onDelete
810
+ },
811
+ target
812
+ );
813
+ }
814
+ );
815
+ }
816
+ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, props, backend, options) {
817
+ const ifExists = options?.ifExists ?? "return";
818
+ const registration = getNodeRegistration(ctx.graph, kind);
819
+ const nodeKind = registration.type;
820
+ const validatedProps = chunk2THZ3TQI_cjs.validateNodeProps(nodeKind.schema, props, {
821
+ kind,
822
+ operation: "create"
823
+ });
824
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
825
+ if (!chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, validatedProps)) {
826
+ const node = await executeNodeCreate(
827
+ ctx,
828
+ { kind, props: validatedProps },
829
+ backend,
830
+ { propsPreValidated: true }
831
+ );
832
+ return { node, action: "created" };
833
+ }
834
+ const key = chunkZUNQ5BEP_cjs.computeUniqueKey(
835
+ validatedProps,
836
+ constraint.fields,
837
+ constraint.collation
838
+ );
839
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
840
+ kind,
841
+ constraint.scope,
842
+ ctx.registry
843
+ );
844
+ async function attempt() {
845
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
846
+ backend,
847
+ ctx.graphId,
848
+ constraint.name,
849
+ key,
850
+ kindsToCheck,
851
+ true
852
+ );
853
+ if (existingUniqueRow === void 0) {
854
+ const node = await executeNodeCreate(
855
+ ctx,
856
+ { kind, props: validatedProps },
857
+ backend,
858
+ { propsPreValidated: true }
859
+ );
860
+ return { node, action: "created" };
861
+ }
862
+ const existingRow = await backend.getNode(
863
+ ctx.graphId,
864
+ existingUniqueRow.concrete_kind,
865
+ existingUniqueRow.node_id
866
+ );
867
+ if (existingRow === void 0) {
868
+ const node = await executeNodeCreate(
869
+ ctx,
870
+ { kind, props: validatedProps },
871
+ backend,
872
+ { propsPreValidated: true }
873
+ );
874
+ return { node, action: "created" };
875
+ }
876
+ const isSoftDeleted = existingRow.deleted_at !== void 0;
877
+ if (isSoftDeleted || ifExists === "update") {
878
+ const concreteKind = existingUniqueRow.concrete_kind;
879
+ const node = await executeNodeUpsertUpdate(
880
+ ctx,
881
+ {
882
+ kind: concreteKind,
883
+ id: existingRow.id,
884
+ props: validatedProps
885
+ },
886
+ backend,
887
+ { clearDeleted: isSoftDeleted }
888
+ );
889
+ return { node, action: isSoftDeleted ? "resurrected" : "updated" };
890
+ }
891
+ return { node: rowToNode(existingRow), action: "found" };
892
+ }
893
+ try {
894
+ return await attempt();
895
+ } catch (error) {
896
+ if (!(error instanceof chunkDIK74MXX_cjs.UniquenessError)) throw error;
897
+ return attempt();
898
+ }
899
+ }
900
+ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
901
+ const registration = getNodeRegistration(ctx.graph, kind);
902
+ const nodeKind = registration.type;
903
+ const validatedProps = chunk2THZ3TQI_cjs.validateNodeProps(nodeKind.schema, props, {
904
+ kind,
905
+ operation: "create"
906
+ });
907
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
908
+ if (!chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, validatedProps)) return void 0;
909
+ const key = chunkZUNQ5BEP_cjs.computeUniqueKey(
910
+ validatedProps,
911
+ constraint.fields,
912
+ constraint.collation
913
+ );
914
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
915
+ kind,
916
+ constraint.scope,
917
+ ctx.registry
918
+ );
919
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
920
+ backend,
921
+ ctx.graphId,
922
+ constraint.name,
923
+ key,
924
+ kindsToCheck,
925
+ false
926
+ );
927
+ if (existingUniqueRow === void 0) return void 0;
928
+ const existingRow = await backend.getNode(
929
+ ctx.graphId,
930
+ existingUniqueRow.concrete_kind,
931
+ existingUniqueRow.node_id
932
+ );
933
+ if (existingRow === void 0 || existingRow.deleted_at !== void 0)
934
+ return void 0;
935
+ return rowToNode(existingRow);
936
+ }
937
+ function validateAndComputeKeys(nodeKind, kind, constraint, items) {
938
+ const validated = [];
939
+ for (const item of items) {
940
+ const validatedProps = chunk2THZ3TQI_cjs.validateNodeProps(nodeKind.schema, item.props, {
941
+ kind,
942
+ operation: "create"
943
+ });
944
+ const applies = chunkZUNQ5BEP_cjs.checkWherePredicate(constraint, validatedProps);
945
+ const key = applies ? chunkZUNQ5BEP_cjs.computeUniqueKey(
946
+ validatedProps,
947
+ constraint.fields,
948
+ constraint.collation
949
+ ) : void 0;
950
+ validated.push({ validatedProps, key });
951
+ }
952
+ return validated;
953
+ }
954
+ function collectUniqueKeys(validated) {
955
+ return [
956
+ ...new Set(
957
+ validated.map((entry) => entry.key).filter((key) => key !== void 0)
958
+ )
959
+ ];
960
+ }
961
+ async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
962
+ if (items.length === 0) return [];
963
+ const registration = getNodeRegistration(ctx.graph, kind);
964
+ const nodeKind = registration.type;
965
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
966
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
967
+ const uniqueKeys = collectUniqueKeys(validated);
968
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
969
+ kind,
970
+ constraint.scope,
971
+ ctx.registry
972
+ );
973
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
974
+ backend,
975
+ ctx.graphId,
976
+ constraint.name,
977
+ uniqueKeys,
978
+ kindsToCheck,
979
+ false
980
+ ) : /* @__PURE__ */ new Map();
981
+ const results = Array.from({ length: items.length });
982
+ const seenKeys = /* @__PURE__ */ new Map();
983
+ for (const [index, { key }] of validated.entries()) {
984
+ if (key === void 0) {
985
+ results[index] = void 0;
986
+ continue;
987
+ }
988
+ const previousIndex = seenKeys.get(key);
989
+ if (previousIndex !== void 0) {
990
+ results[index] = results[previousIndex];
991
+ continue;
992
+ }
993
+ seenKeys.set(key, index);
994
+ const existing = existingByKey.get(key);
995
+ if (existing === void 0) {
996
+ results[index] = void 0;
997
+ continue;
998
+ }
999
+ const existingRow = await backend.getNode(
1000
+ ctx.graphId,
1001
+ existing.concrete_kind,
1002
+ existing.node_id
1003
+ );
1004
+ if (existingRow === void 0 || existingRow.deleted_at !== void 0) {
1005
+ results[index] = void 0;
1006
+ continue;
1007
+ }
1008
+ results[index] = rowToNode(existingRow);
1009
+ }
1010
+ return results;
1011
+ }
1012
+ function resolveNodeIndex(graph, kind, indexName) {
1013
+ getNodeRegistration(graph, kind);
1014
+ const declaration = graph.indexes?.find(
1015
+ (candidate) => candidate.entity === "node" && candidate.kind === kind && candidate.name === indexName
1016
+ );
1017
+ if (declaration?.entity !== "node") {
1018
+ throw new chunkDIK74MXX_cjs.NodeIndexNotFoundError(indexName, kind);
1019
+ }
1020
+ if (declaration.method !== void 0) {
1021
+ throw new chunkDIK74MXX_cjs.ConfigurationError(
1022
+ `bulkFindByIndex cannot probe index "${indexName}" (method "${declaration.method}"): only btree indexes serve equality probes.`,
1023
+ { indexName, kind, method: declaration.method }
1024
+ );
1025
+ }
1026
+ return declaration;
1027
+ }
1028
+ var INDEX_PROBE_EXPECTED_TYPEOF = {
1029
+ string: "string",
1030
+ number: "number",
1031
+ boolean: "boolean"
1032
+ };
1033
+ function validateIndexProbeValue(value, valueType, pointer, kind) {
1034
+ if (value === void 0 || value === null) return;
1035
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean" && !(value instanceof Date)) {
1036
+ throw indexProbeTypeError(
1037
+ pointer,
1038
+ kind,
1039
+ "a scalar (string, number, boolean, or Date)",
1040
+ value
1041
+ );
1042
+ }
1043
+ if (valueType === "date") {
1044
+ if (value instanceof Date || typeof value === "string") return;
1045
+ throw indexProbeTypeError(
1046
+ pointer,
1047
+ kind,
1048
+ "date (Date or ISO string)",
1049
+ value
1050
+ );
1051
+ }
1052
+ const expected = INDEX_PROBE_EXPECTED_TYPEOF[valueType ?? "unknown"];
1053
+ if (expected === void 0) return;
1054
+ if (typeof value !== expected) {
1055
+ throw indexProbeTypeError(pointer, kind, expected, value);
1056
+ }
1057
+ }
1058
+ function indexProbeTypeError(pointer, kind, expected, value) {
1059
+ return new chunkDIK74MXX_cjs.ValidationError(
1060
+ `Index probe value for "${pointer}" on node kind "${kind}" has an incompatible type`,
1061
+ {
1062
+ entityType: "node",
1063
+ kind,
1064
+ issues: [
1065
+ {
1066
+ path: pointer,
1067
+ message: `Expected ${expected}, received ${typeof value}`,
1068
+ code: "invalid_type"
1069
+ }
1070
+ ]
1071
+ }
1072
+ );
1073
+ }
1074
+ function coerceIndexProbeBind(value, adapter) {
1075
+ return adapter.bindValue(normalizeProbeScalar(value));
1076
+ }
1077
+ function normalizeProbeScalar(value) {
1078
+ return value instanceof Date ? value.toISOString() : value;
1079
+ }
1080
+ var PROBE_NULL_TAG = 0;
1081
+ var PROBE_VALUE_TAG = 1;
1082
+ function canonicalIndexProbeKey(probe) {
1083
+ return JSON.stringify(
1084
+ probe.map(
1085
+ (value) => value === void 0 || value === null ? [PROBE_NULL_TAG] : [PROBE_VALUE_TAG, normalizeProbeScalar(value)]
1086
+ )
1087
+ );
1088
+ }
1089
+ async function executeNodeBulkFindByIndex(ctx, kind, indexName, items, backend, options) {
1090
+ if (items.length === 0) return [];
1091
+ const index = resolveNodeIndex(ctx.graph, kind, indexName);
1092
+ if (index.fields.length === 0) {
1093
+ throw new chunkDIK74MXX_cjs.ConfigurationError(
1094
+ `bulkFindByIndex requires an index with at least one prop-based field on index "${indexName}" (node kind "${kind}")`,
1095
+ { indexName, kind },
1096
+ {
1097
+ suggestion: "bulkFindByIndex probes by prop values from each item; an index declared with only keySystemColumns/coveringFields (no fields) has nothing to probe by."
1098
+ }
1099
+ );
1100
+ }
1101
+ if (index.fieldValueTypes.includes("date")) {
1102
+ throw new chunkDIK74MXX_cjs.ConfigurationError(
1103
+ `bulkFindByIndex does not support date-typed key fields on index "${indexName}" (node kind "${kind}")`,
1104
+ { indexName, kind },
1105
+ {
1106
+ suggestion: "Date index keys compare differently across SQLite and PostgreSQL. Use a string-encoded key field, or query date predicates via store.query(...).where(...)."
1107
+ }
1108
+ );
1109
+ }
1110
+ const limitPerInput = options?.limitPerInput;
1111
+ if (limitPerInput !== void 0 && (!Number.isInteger(limitPerInput) || limitPerInput <= 0)) {
1112
+ throw new chunkDIK74MXX_cjs.ValidationError(
1113
+ "bulkFindByIndex limitPerInput must be a positive integer",
1114
+ {
1115
+ entityType: "node",
1116
+ kind,
1117
+ issues: [
1118
+ {
1119
+ path: "limitPerInput",
1120
+ message: `Expected a positive integer, received ${String(limitPerInput)}`,
1121
+ code: "invalid_value"
1122
+ }
1123
+ ]
1124
+ }
1125
+ );
1126
+ }
1127
+ const adapter = chunkD7ZEOS56_cjs.getDialect(backend.dialect);
1128
+ const probes = items.map(
1129
+ (item) => index.fields.map((pointer, position) => {
1130
+ const value = chunkTDXIBCGY_cjs.resolveJsonPointer(item.props, pointer);
1131
+ validateIndexProbeValue(
1132
+ value,
1133
+ index.fieldValueTypes[position],
1134
+ pointer,
1135
+ kind
1136
+ );
1137
+ return value;
1138
+ })
1139
+ );
1140
+ const groupByKey = /* @__PURE__ */ new Map();
1141
+ const groupProbes = [];
1142
+ const groupToInputs = [];
1143
+ for (const [inputIndex, probe] of probes.entries()) {
1144
+ const key = canonicalIndexProbeKey(probe);
1145
+ const existing = groupByKey.get(key);
1146
+ if (existing === void 0) {
1147
+ groupByKey.set(key, groupProbes.length);
1148
+ groupProbes.push(probe);
1149
+ groupToInputs.push([inputIndex]);
1150
+ continue;
1151
+ }
1152
+ groupToInputs[existing]?.push(inputIndex);
1153
+ }
1154
+ const schema = backend.tableNames ? chunkZUNQ5BEP_cjs.createSqlSchema(backend.tableNames) : chunkZUNQ5BEP_cjs.DEFAULT_SQL_SCHEMA;
1155
+ const compileContext = {
1156
+ dialect: backend.dialect,
1157
+ propsColumn: drizzleOrm.sql.raw(`"props"`),
1158
+ systemColumn: (column) => drizzleOrm.sql.raw(`"${column}"`)
1159
+ };
1160
+ const fieldKeys = chunkD7ZEOS56_cjs.compileNodeIndexFieldKeys(index, compileContext);
1161
+ const groupPredicates = groupProbes.map(
1162
+ (probe) => drizzleOrm.sql`(${drizzleOrm.sql.join(
1163
+ fieldKeys.map((fieldKey, position) => {
1164
+ const value = probe[position];
1165
+ if (value === void 0 || value === null) {
1166
+ return drizzleOrm.sql`${fieldKey} IS NULL`;
1167
+ }
1168
+ return adapter.nullSafeEquals(
1169
+ fieldKey,
1170
+ drizzleOrm.sql`${coerceIndexProbeBind(value, adapter)}`
1171
+ );
1172
+ }),
1173
+ drizzleOrm.sql` AND `
1174
+ )})`
1175
+ );
1176
+ const caseBranches = groupPredicates.map(
1177
+ (predicate, group) => drizzleOrm.sql`WHEN ${predicate} THEN ${drizzleOrm.sql.raw(String(group))}`
1178
+ );
1179
+ const probeIndexExpr = drizzleOrm.sql`CASE ${drizzleOrm.sql.join(caseBranches, drizzleOrm.sql` `)} ELSE NULL END`;
1180
+ const conditions = [
1181
+ drizzleOrm.sql`"graph_id" = ${ctx.graphId}`,
1182
+ drizzleOrm.sql`"kind" = ${kind}`,
1183
+ drizzleOrm.sql`"deleted_at" IS NULL`
1184
+ ];
1185
+ if (index.where !== void 0) {
1186
+ conditions.push(chunkD7ZEOS56_cjs.compileIndexWhere(compileContext, index.where));
1187
+ }
1188
+ conditions.push(drizzleOrm.sql`(${drizzleOrm.sql.join(groupPredicates, drizzleOrm.sql` OR `)})`);
1189
+ const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
1190
+ const probedSelect = drizzleOrm.sql`SELECT "id", ${probeIndexExpr} AS probe_idx FROM ${schema.nodesTable} WHERE ${whereClause}`;
1191
+ const capInSql = limitPerInput !== void 0 && backend.capabilities.windowFunctions;
1192
+ const query = capInSql ? drizzleOrm.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"` : drizzleOrm.sql`${probedSelect} ORDER BY probe_idx, "id"`;
1193
+ const rawMatches = await backend.execute(
1194
+ chunkEOLERH7Y_cjs.asCompiledRowsSql(query)
1195
+ );
1196
+ const matches = limitPerInput !== void 0 && !capInSql ? capMatchesPerGroup(rawMatches, limitPerInput) : rawMatches;
1197
+ const nodesById = await hydrateNodesById(
1198
+ backend,
1199
+ ctx.graphId,
1200
+ kind,
1201
+ matches.map((match) => match.id)
1202
+ );
1203
+ const results = Array.from({ length: items.length }, () => []);
1204
+ for (const match of matches) {
1205
+ const node = nodesById.get(match.id);
1206
+ if (node === void 0) continue;
1207
+ const inputs = groupToInputs[match.probe_idx];
1208
+ if (inputs === void 0) continue;
1209
+ for (const inputIndex of inputs) {
1210
+ results[inputIndex]?.push(node);
1211
+ }
1212
+ }
1213
+ return results;
1214
+ }
1215
+ function capMatchesPerGroup(matches, limitPerInput) {
1216
+ const perGroupCount = /* @__PURE__ */ new Map();
1217
+ const capped = [];
1218
+ for (const match of matches) {
1219
+ const count = perGroupCount.get(match.probe_idx) ?? 0;
1220
+ if (count >= limitPerInput) continue;
1221
+ perGroupCount.set(match.probe_idx, count + 1);
1222
+ capped.push(match);
1223
+ }
1224
+ return capped;
1225
+ }
1226
+ async function hydrateNodesById(backend, graphId, kind, ids) {
1227
+ const rowsById = await chunkZUNQ5BEP_cjs.getNodeRowsByIds(backend, graphId, kind, ids);
1228
+ const nodesById = /* @__PURE__ */ new Map();
1229
+ for (const [id, row] of rowsById) {
1230
+ if (row.deleted_at !== void 0) continue;
1231
+ nodesById.set(id, rowToNode(row));
1232
+ }
1233
+ return nodesById;
1234
+ }
1235
+ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName, items, backend, options) {
1236
+ if (items.length === 0) return [];
1237
+ const ifExists = options?.ifExists ?? "return";
1238
+ const registration = getNodeRegistration(ctx.graph, kind);
1239
+ const nodeKind = registration.type;
1240
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
1241
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
1242
+ const uniqueKeys = collectUniqueKeys(validated);
1243
+ const kindsToCheck = chunkZUNQ5BEP_cjs.getKindsForUniquenessCheck(
1244
+ kind,
1245
+ constraint.scope,
1246
+ ctx.registry
1247
+ );
1248
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
1249
+ backend,
1250
+ ctx.graphId,
1251
+ constraint.name,
1252
+ uniqueKeys,
1253
+ kindsToCheck,
1254
+ true
1255
+ ) : /* @__PURE__ */ new Map();
1256
+ const toCreate = [];
1257
+ const toFetch = [];
1258
+ const duplicateOf = [];
1259
+ const seenKeys = /* @__PURE__ */ new Map();
1260
+ for (const [index, { validatedProps, key }] of validated.entries()) {
1261
+ if (key === void 0) {
1262
+ toCreate.push({ index, input: { kind, props: validatedProps } });
1263
+ continue;
1264
+ }
1265
+ const previousIndex = seenKeys.get(key);
1266
+ if (previousIndex !== void 0) {
1267
+ duplicateOf.push({ index, sourceIndex: previousIndex });
1268
+ continue;
1269
+ }
1270
+ seenKeys.set(key, index);
1271
+ const existing = existingByKey.get(key);
1272
+ if (existing === void 0) {
1273
+ toCreate.push({ index, input: { kind, props: validatedProps } });
1274
+ } else {
1275
+ toFetch.push({
1276
+ index,
1277
+ nodeId: existing.node_id,
1278
+ concreteKind: existing.concrete_kind,
1279
+ validatedProps,
1280
+ isSoftDeleted: existing.deleted_at !== void 0
1281
+ });
1282
+ }
1283
+ }
1284
+ const results = Array.from({ length: items.length });
1285
+ if (toCreate.length > 0) {
1286
+ const createInputs = toCreate.map((entry) => entry.input);
1287
+ const createdNodes = await executeNodeCreateBatch(
1288
+ ctx,
1289
+ createInputs,
1290
+ backend,
1291
+ { propsPreValidated: true }
1292
+ );
1293
+ for (const [batchIndex, entry] of toCreate.entries()) {
1294
+ results[entry.index] = {
1295
+ node: createdNodes[batchIndex],
1296
+ action: "created"
1297
+ };
1298
+ }
1299
+ }
1300
+ for (const entry of toFetch) {
1301
+ const { index, concreteKind, validatedProps, isSoftDeleted, nodeId } = entry;
1302
+ const existingRow = await backend.getNode(
1303
+ ctx.graphId,
1304
+ concreteKind,
1305
+ nodeId
1306
+ );
1307
+ if (existingRow === void 0) {
1308
+ const node = await executeNodeCreate(
1309
+ ctx,
1310
+ { kind, props: validatedProps },
1311
+ backend,
1312
+ { propsPreValidated: true }
1313
+ );
1314
+ results[index] = { node, action: "created" };
1315
+ continue;
1316
+ }
1317
+ if (isSoftDeleted || ifExists === "update") {
1318
+ const node = await executeNodeUpsertUpdate(
1319
+ ctx,
1320
+ {
1321
+ kind: concreteKind,
1322
+ id: existingRow.id,
1323
+ props: validatedProps
1324
+ },
1325
+ backend,
1326
+ { clearDeleted: isSoftDeleted }
1327
+ );
1328
+ results[index] = {
1329
+ node,
1330
+ action: isSoftDeleted ? "resurrected" : "updated"
1331
+ };
1332
+ } else {
1333
+ results[index] = { node: rowToNode(existingRow), action: "found" };
1334
+ }
1335
+ }
1336
+ for (const { index, sourceIndex } of duplicateOf) {
1337
+ const sourceResult = results[sourceIndex];
1338
+ results[index] = { node: sourceResult.node, action: "found" };
1339
+ }
1340
+ return results;
1341
+ }
1342
+
1343
+ exports.checkCardinalityConstraint = checkCardinalityConstraint;
1344
+ exports.createNodeBatchValidationBackend = createNodeBatchValidationBackend;
1345
+ exports.executeNodeBulkFindByConstraint = executeNodeBulkFindByConstraint;
1346
+ exports.executeNodeBulkFindByIndex = executeNodeBulkFindByIndex;
1347
+ exports.executeNodeBulkGetOrCreateByConstraint = executeNodeBulkGetOrCreateByConstraint;
1348
+ exports.executeNodeCreate = executeNodeCreate;
1349
+ exports.executeNodeCreateBatch = executeNodeCreateBatch;
1350
+ exports.executeNodeCreateNoReturnBatch = executeNodeCreateNoReturnBatch;
1351
+ exports.executeNodeDelete = executeNodeDelete;
1352
+ exports.executeNodeFindByConstraint = executeNodeFindByConstraint;
1353
+ exports.executeNodeGetOrCreateByConstraint = executeNodeGetOrCreateByConstraint;
1354
+ exports.executeNodeHardDelete = executeNodeHardDelete;
1355
+ exports.executeNodeUpdate = executeNodeUpdate;
1356
+ exports.executeNodeUpsertUpdate = executeNodeUpsertUpdate;
1357
+ exports.nodeUpsertDirtyCheck = nodeUpsertDirtyCheck;
1358
+ exports.primeBatchValidationCaches = primeBatchValidationCaches;
1359
+ exports.rowToEdge = rowToEdge;
1360
+ exports.rowToEdgeMeta = rowToEdgeMeta;
1361
+ exports.rowToNode = rowToNode;
1362
+ exports.rowToNodeMeta = rowToNodeMeta;
1363
+ exports.runHookedWriteOperation = runHookedWriteOperation;
1364
+ exports.runInWriteTransaction = runInWriteTransaction;
1365
+ //# sourceMappingURL=chunk-4CAXEB2F.cjs.map
1366
+ //# sourceMappingURL=chunk-4CAXEB2F.cjs.map