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