@nicia-ai/typegraph 0.34.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 (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-ZV5N4DBG.js → chunk-3TWF3SH4.js} +300 -58
  24. package/dist/chunk-3TWF3SH4.js.map +1 -0
  25. package/dist/chunk-4JEZZJ6S.cjs +1271 -0
  26. package/dist/chunk-4JEZZJ6S.cjs.map +1 -0
  27. package/dist/{chunk-UNNPKQUG.cjs → chunk-4TOD4LBZ.cjs} +246 -155
  28. package/dist/chunk-4TOD4LBZ.cjs.map +1 -0
  29. package/dist/{chunk-QV245VMN.js → chunk-55MZDDZV.js} +100 -6
  30. package/dist/chunk-55MZDDZV.js.map +1 -0
  31. package/dist/{chunk-GQANNXXT.cjs → chunk-5A6FNS6N.cjs} +75 -20
  32. package/dist/chunk-5A6FNS6N.cjs.map +1 -0
  33. package/dist/{chunk-3Z6TW3CT.cjs → chunk-5AQIKK56.cjs} +65 -25
  34. package/dist/chunk-5AQIKK56.cjs.map +1 -0
  35. package/dist/{chunk-BVTWD66D.js → chunk-5SEGFTZX.js} +3 -3
  36. package/dist/{chunk-BVTWD66D.js.map → chunk-5SEGFTZX.js.map} +1 -1
  37. package/dist/{chunk-6GNSY7AV.js → chunk-6FR2MMS6.js} +7 -7
  38. package/dist/chunk-6FR2MMS6.js.map +1 -0
  39. package/dist/chunk-7YSP4V4R.cjs +69 -0
  40. package/dist/chunk-7YSP4V4R.cjs.map +1 -0
  41. package/dist/chunk-A42GCBGX.cjs +28 -0
  42. package/dist/chunk-A42GCBGX.cjs.map +1 -0
  43. package/dist/{chunk-RHZWOJVA.cjs → chunk-BLZDPRXT.cjs} +52 -4
  44. package/dist/chunk-BLZDPRXT.cjs.map +1 -0
  45. package/dist/chunk-BYPOGQWK.js +25 -0
  46. package/dist/chunk-BYPOGQWK.js.map +1 -0
  47. package/dist/{chunk-6HVOHZHS.cjs → chunk-CK5BVQOW.cjs} +213 -168
  48. package/dist/chunk-CK5BVQOW.cjs.map +1 -0
  49. package/dist/{chunk-JJRCLAUN.cjs → chunk-CTTSDJLY.cjs} +116 -10
  50. package/dist/chunk-CTTSDJLY.cjs.map +1 -0
  51. package/dist/chunk-CUHM5CWJ.cjs +12 -0
  52. package/dist/chunk-CUHM5CWJ.cjs.map +1 -0
  53. package/dist/{chunk-A7SZZFAG.js → chunk-CZQ3FO2Q.js} +409 -99
  54. package/dist/chunk-CZQ3FO2Q.js.map +1 -0
  55. package/dist/{chunk-2JXB3NYJ.cjs → chunk-D7ZEOS56.cjs} +25 -32
  56. package/dist/chunk-D7ZEOS56.cjs.map +1 -0
  57. package/dist/chunk-DFVLCOP6.js +10 -0
  58. package/dist/chunk-DFVLCOP6.js.map +1 -0
  59. package/dist/{chunk-UJLOZYKT.cjs → chunk-EM3CWPND.cjs} +441 -115
  60. package/dist/chunk-EM3CWPND.cjs.map +1 -0
  61. package/dist/chunk-EMF62TZG.cjs +1176 -0
  62. package/dist/chunk-EMF62TZG.cjs.map +1 -0
  63. package/dist/chunk-EOLERH7Y.cjs +40 -0
  64. package/dist/chunk-EOLERH7Y.cjs.map +1 -0
  65. package/dist/{chunk-TGJE22RM.cjs → chunk-FACJJWGF.cjs} +24 -6
  66. package/dist/chunk-FACJJWGF.cjs.map +1 -0
  67. package/dist/{chunk-HK5SATYM.cjs → chunk-FL472AMI.cjs} +16 -109
  68. package/dist/chunk-FL472AMI.cjs.map +1 -0
  69. package/dist/{chunk-WVC2Q2FD.cjs → chunk-FN35DLCN.cjs} +31 -9
  70. package/dist/chunk-FN35DLCN.cjs.map +1 -0
  71. package/dist/{chunk-KUTNI6SI.js → chunk-FPIZFYHE.js} +10 -18
  72. package/dist/chunk-FPIZFYHE.js.map +1 -0
  73. package/dist/{chunk-VCGO4V26.js → chunk-FRV5Q5IO.js} +64 -9
  74. package/dist/chunk-FRV5Q5IO.js.map +1 -0
  75. package/dist/{chunk-K5P5OZXS.js → chunk-G6Q5UM7U.js} +2 -2
  76. package/dist/{chunk-K5P5OZXS.js.map → chunk-G6Q5UM7U.js.map} +1 -1
  77. package/dist/chunk-GSQ6NPH6.cjs +100 -0
  78. package/dist/chunk-GSQ6NPH6.cjs.map +1 -0
  79. package/dist/chunk-GUR2FNB5.cjs +12 -0
  80. package/dist/{chunk-HMFK4BXR.cjs.map → chunk-GUR2FNB5.cjs.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-2MRAX3UE.js → chunk-I7ZUZKFD.js} +47 -4
  84. package/dist/chunk-I7ZUZKFD.js.map +1 -0
  85. package/dist/{chunk-3BRVBQQD.cjs → chunk-J7WFGBJR.cjs} +2445 -2367
  86. package/dist/chunk-J7WFGBJR.cjs.map +1 -0
  87. package/dist/{chunk-V3QNTB7Z.js → chunk-JBTOYDMN.js} +194 -114
  88. package/dist/chunk-JBTOYDMN.js.map +1 -0
  89. package/dist/{chunk-K2TGS3EN.js → chunk-K3PPLHY7.js} +138 -89
  90. package/dist/chunk-K3PPLHY7.js.map +1 -0
  91. package/dist/{chunk-Z5XBMDXU.js → chunk-KBGQIPRQ.js} +42 -3
  92. package/dist/chunk-KBGQIPRQ.js.map +1 -0
  93. package/dist/chunk-KMI7LYAF.js +1252 -0
  94. package/dist/chunk-KMI7LYAF.js.map +1 -0
  95. package/dist/{chunk-JIEJCTDS.cjs → chunk-LGEALRC6.cjs} +21 -4
  96. package/dist/chunk-LGEALRC6.cjs.map +1 -0
  97. package/dist/{chunk-TQOYM4LN.js → chunk-MP2JQKSG.js} +21 -5
  98. package/dist/chunk-MP2JQKSG.js.map +1 -0
  99. package/dist/{chunk-ZP5WHI4C.cjs → chunk-O7UN7OXA.cjs} +358 -116
  100. package/dist/chunk-O7UN7OXA.cjs.map +1 -0
  101. package/dist/chunk-OHMP6N2J.js +47 -0
  102. package/dist/chunk-OHMP6N2J.js.map +1 -0
  103. package/dist/{chunk-4DIBPQNJ.js → chunk-OR5ZA5WP.js} +135 -25
  104. package/dist/chunk-OR5ZA5WP.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-QNKSQTKQ.js +1312 -0
  108. package/dist/chunk-QNKSQTKQ.js.map +1 -0
  109. package/dist/{chunk-ZURTTSCM.js → chunk-QOTI55H7.js} +6 -94
  110. package/dist/chunk-QOTI55H7.js.map +1 -0
  111. package/dist/{chunk-CHXTTSC6.js → chunk-QWEUYILR.js} +104 -5
  112. package/dist/chunk-QWEUYILR.js.map +1 -0
  113. package/dist/{chunk-LANHCOXB.js → chunk-RGP33ZJ5.js} +485 -83
  114. package/dist/chunk-RGP33ZJ5.js.map +1 -0
  115. package/dist/chunk-RGPG7EOJ.js +94 -0
  116. package/dist/chunk-RGPG7EOJ.js.map +1 -0
  117. package/dist/{chunk-G6SOJEDI.cjs → chunk-S55OV6PW.cjs} +15 -15
  118. package/dist/chunk-S55OV6PW.cjs.map +1 -0
  119. package/dist/{chunk-3E7SNSIA.cjs → chunk-SJDMVITW.cjs} +4 -4
  120. package/dist/{chunk-3E7SNSIA.cjs.map → chunk-SJDMVITW.cjs.map} +1 -1
  121. package/dist/{chunk-XLUNB2TZ.js → chunk-SNXVDZAJ.js} +3 -3
  122. package/dist/{chunk-XLUNB2TZ.js.map → chunk-SNXVDZAJ.js.map} +1 -1
  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-WLRIWYHQ.js → chunk-UES55P7G.js} +1863 -1785
  132. package/dist/chunk-UES55P7G.js.map +1 -0
  133. package/dist/{chunk-WL2SG7ZV.cjs → chunk-UMDVATGY.cjs} +6 -6
  134. package/dist/{chunk-WL2SG7ZV.cjs.map → chunk-UMDVATGY.cjs.map} +1 -1
  135. package/dist/chunk-UT3S4SEN.js +31 -0
  136. package/dist/chunk-UT3S4SEN.js.map +1 -0
  137. package/dist/{chunk-RRKQAKD6.cjs → chunk-UUT7UN2N.cjs} +149 -39
  138. package/dist/chunk-UUT7UN2N.cjs.map +1 -0
  139. package/dist/{chunk-SHLY4MCM.js → chunk-UZV3AZKF.js} +21 -3
  140. package/dist/chunk-UZV3AZKF.js.map +1 -0
  141. package/dist/{chunk-CYX2JTDG.js → chunk-VHMPG6UL.js} +29 -7
  142. package/dist/chunk-VHMPG6UL.js.map +1 -0
  143. package/dist/{chunk-T6SPUYLX.cjs → chunk-VPYHY3LJ.cjs} +116 -10
  144. package/dist/chunk-VPYHY3LJ.cjs.map +1 -0
  145. package/dist/{chunk-T46GR2VY.js → chunk-VSPCZAXF.js} +3 -3
  146. package/dist/{chunk-T46GR2VY.js.map → chunk-VSPCZAXF.js.map} +1 -1
  147. package/dist/{chunk-K34OPSJK.js → chunk-W63OVYY4.js} +3 -3
  148. package/dist/{chunk-K34OPSJK.js.map → chunk-W63OVYY4.js.map} +1 -1
  149. package/dist/{chunk-RY2VIWAM.js → chunk-WDBCBWC4.js} +355 -32
  150. package/dist/chunk-WDBCBWC4.js.map +1 -0
  151. package/dist/chunk-WJT7OU7E.cjs +1334 -0
  152. package/dist/chunk-WJT7OU7E.cjs.map +1 -0
  153. package/dist/{chunk-5IQIX7LU.cjs → chunk-XOX22WHL.cjs} +476 -163
  154. package/dist/chunk-XOX22WHL.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-6CSUAq-x.d.ts} +234 -93
  172. package/dist/{index-SEvUHDA6.d.cts → index-Bks_3HHK.d.cts} +234 -93
  173. package/dist/index.cjs +208 -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 +47 -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 +14 -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-BSpqvAxK.d.cts} +415 -44
  210. package/dist/{store-view-BlgnhEYf.d.ts → store-view-CKbHFRnn.d.ts} +415 -44
  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,1252 @@
1
+ import { runInWriteTransaction, createNodeBatchValidationBackend, primeBatchValidationCaches } from './chunk-QNKSQTKQ.js';
2
+ import { getNodeKinds, getEdgeKinds } from './chunk-QWEUYILR.js';
3
+ import { applyNodeInsertSideEffectsBatch, applyNodeUpdate, checkUniquenessConstraints, applyNodeInsertSideEffects, validateEdgeEndpoints } from './chunk-CZQ3FO2Q.js';
4
+ import { rowPropsToObject, isLiveNodeRow } from './chunk-JBTOYDMN.js';
5
+ import { isCanonicalIsoDate, nowIso, validateOptionalCanonicalIsoDate } from './chunk-I7ZUZKFD.js';
6
+ import { UniquenessError } from './chunk-MP2JQKSG.js';
7
+ import { z } from 'zod';
8
+
9
+ var FORMAT_VERSION = "1.0";
10
+ var ValidityTimestampSchema = z.iso.datetime().refine((value) => isCanonicalIsoDate(value), {
11
+ message: "Expected canonical UTC ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ); convert with new Date(value).toISOString()."
12
+ });
13
+ var InterchangeNodeSchema = z.object({
14
+ kind: z.string().min(1),
15
+ id: z.string().min(1),
16
+ properties: z.record(z.string(), z.unknown()),
17
+ /**
18
+ * `undefined` (key absent): not requested (`includeTemporal: false`) —
19
+ * import defaults it to the import's own creation timestamp. `null`:
20
+ * requested and confirmed the row has no lower bound (e.g. a legacy row
21
+ * predating the "omitted validFrom defaults to creation time" fix) —
22
+ * import preserves that open-left validity instead of re-stamping it.
23
+ */
24
+ validFrom: ValidityTimestampSchema.nullable().optional(),
25
+ validTo: ValidityTimestampSchema.optional(),
26
+ meta: z.object({
27
+ version: z.number().int().positive().optional(),
28
+ createdAt: z.iso.datetime().optional(),
29
+ updatedAt: z.iso.datetime().optional()
30
+ }).optional()
31
+ });
32
+ var InterchangeEdgeSchema = z.object({
33
+ kind: z.string().min(1),
34
+ id: z.string().min(1),
35
+ from: z.object({
36
+ kind: z.string().min(1),
37
+ id: z.string().min(1)
38
+ }),
39
+ to: z.object({
40
+ kind: z.string().min(1),
41
+ id: z.string().min(1)
42
+ }),
43
+ properties: z.record(z.string(), z.unknown()).default({}),
44
+ /** See {@link InterchangeNodeSchema}'s `validFrom` for the null/undefined contract. */
45
+ validFrom: ValidityTimestampSchema.nullable().optional(),
46
+ validTo: ValidityTimestampSchema.optional(),
47
+ meta: z.object({
48
+ createdAt: z.iso.datetime().optional(),
49
+ updatedAt: z.iso.datetime().optional()
50
+ }).optional()
51
+ });
52
+ var ConflictStrategySchema = z.enum(["skip", "update", "error"]);
53
+ var UnknownPropertyStrategySchema = z.enum([
54
+ "error",
55
+ "strip",
56
+ "allow"
57
+ ]);
58
+ var ImportOptionsSchema = z.object({
59
+ /** How to handle existing nodes/edges with the same ID */
60
+ onConflict: ConflictStrategySchema,
61
+ /** How to handle properties not in the schema */
62
+ onUnknownProperty: UnknownPropertyStrategySchema.default("error"),
63
+ /** Whether to validate that edge endpoints exist */
64
+ validateReferences: z.boolean().default(true),
65
+ /**
66
+ * Number of items to process in each batch. Each batch pays fixed
67
+ * per-round-trip costs (existence probe, unique check, one multi-row
68
+ * insert), so undersized batches dominate import time on client/server
69
+ * engines: measured on PostgreSQL, 20k nodes + 5k edges import in
70
+ * 1,515ms at 100 vs 781ms at 1,000. Above ~1,000 the multi-row insert
71
+ * itself dominates and larger batches stop paying; SQLite is
72
+ * insensitive to the value (in-process, no round trips). The backend
73
+ * further splits inserts by its bind-parameter budget, so a large
74
+ * batch never overruns driver limits.
75
+ */
76
+ batchSize: z.number().int().positive().default(1e3),
77
+ /**
78
+ * Refresh planner statistics (ANALYZE) after an import that created or
79
+ * updated rows. Bulk loads otherwise run against stale statistics until
80
+ * the engine catches up on its own. Default: true.
81
+ */
82
+ refreshStatistics: z.boolean().optional(),
83
+ /**
84
+ * How a streamed import reacts when one chunk reports entity-level errors.
85
+ * `abort` is the safe default: earlier chunks are already committed, so
86
+ * callers must not mistake a partial stream for a successful retryable load.
87
+ * `continue` is reserved for explicit best-effort ingestion.
88
+ */
89
+ onStreamChunkError: z.enum(["abort", "continue"]).default("abort")
90
+ });
91
+ var GraphDataSourceSchema = z.discriminatedUnion("type", [
92
+ z.object({
93
+ type: z.literal("typegraph-export"),
94
+ graphId: z.string(),
95
+ schemaVersion: z.number().int().positive()
96
+ }),
97
+ z.object({
98
+ type: z.literal("external"),
99
+ description: z.string().optional()
100
+ })
101
+ ]);
102
+ var GraphDataSchema = z.object({
103
+ formatVersion: z.literal(FORMAT_VERSION),
104
+ exportedAt: z.iso.datetime(),
105
+ source: GraphDataSourceSchema,
106
+ nodes: z.array(InterchangeNodeSchema),
107
+ edges: z.array(InterchangeEdgeSchema)
108
+ });
109
+ var GraphDataHeaderSchema = GraphDataSchema.omit({
110
+ nodes: true,
111
+ edges: true
112
+ });
113
+ var GraphInterchangeChunkSchema = z.discriminatedUnion("type", [
114
+ z.object({ type: z.literal("header"), header: GraphDataHeaderSchema }),
115
+ z.object({ type: z.literal("nodes"), nodes: z.array(InterchangeNodeSchema) }),
116
+ z.object({ type: z.literal("edges"), edges: z.array(InterchangeEdgeSchema) })
117
+ ]);
118
+ var ImportErrorSchema = z.object({
119
+ entityType: z.enum(["node", "edge"]),
120
+ kind: z.string(),
121
+ id: z.string(),
122
+ error: z.string()
123
+ });
124
+ var ImportResultSchema = z.object({
125
+ success: z.boolean(),
126
+ nodes: z.object({
127
+ created: z.number().int().nonnegative(),
128
+ updated: z.number().int().nonnegative(),
129
+ skipped: z.number().int().nonnegative()
130
+ }),
131
+ edges: z.object({
132
+ created: z.number().int().nonnegative(),
133
+ updated: z.number().int().nonnegative(),
134
+ skipped: z.number().int().nonnegative()
135
+ }),
136
+ errors: z.array(ImportErrorSchema)
137
+ });
138
+ var ExportOptionsSchema = z.object({
139
+ /** Filter to specific node kinds (undefined = all) */
140
+ nodeKinds: z.array(z.string()).optional(),
141
+ /** Filter to specific edge kinds (undefined = all) */
142
+ edgeKinds: z.array(z.string()).optional(),
143
+ /** Include temporal fields (validFrom, validTo) */
144
+ includeTemporal: z.boolean().default(false),
145
+ /** Include metadata (version, timestamps) */
146
+ includeMeta: z.boolean().default(false),
147
+ /** Include soft-deleted records */
148
+ includeDeleted: z.boolean().default(false)
149
+ });
150
+ var ExportStreamOptionsSchema = ExportOptionsSchema.extend({
151
+ batchSize: z.number().int().positive().default(1e3)
152
+ });
153
+
154
+ // src/interchange/export.ts
155
+ async function exportGraph(store, options) {
156
+ const nodes = [];
157
+ const edges = [];
158
+ let header;
159
+ for await (const chunk of exportGraphStream(store, options)) {
160
+ switch (chunk.type) {
161
+ case "header": {
162
+ header = chunk.header;
163
+ break;
164
+ }
165
+ case "nodes": {
166
+ nodes.push(...chunk.nodes);
167
+ break;
168
+ }
169
+ case "edges": {
170
+ edges.push(...chunk.edges);
171
+ break;
172
+ }
173
+ }
174
+ }
175
+ if (header === void 0) {
176
+ throw new Error("Graph export stream ended before emitting its header.");
177
+ }
178
+ return { ...header, nodes, edges };
179
+ }
180
+ async function* exportGraphStream(store, options) {
181
+ const resolved = ExportStreamOptionsSchema.parse(options ?? {});
182
+ const graphId = store.graphId;
183
+ const backend = store.backend;
184
+ const nodeKinds = resolved.nodeKinds ?? getNodeKinds(store.graph);
185
+ const edgeKinds = resolved.edgeKinds ?? getEdgeKinds(store.graph);
186
+ const schemaVersion = await backend.getActiveSchema(graphId);
187
+ yield {
188
+ type: "header",
189
+ header: {
190
+ formatVersion: FORMAT_VERSION,
191
+ exportedAt: nowIso(),
192
+ source: {
193
+ type: "typegraph-export",
194
+ graphId,
195
+ schemaVersion: schemaVersion?.version ?? 1
196
+ }
197
+ }
198
+ };
199
+ for (const kind of nodeKinds) {
200
+ yield* exportNodeChunks(backend, graphId, kind, resolved);
201
+ }
202
+ for (const kind of edgeKinds) {
203
+ yield* exportEdgeChunks(backend, graphId, kind, resolved);
204
+ }
205
+ }
206
+ async function* exportNodeChunks(backend, graphId, kind, options) {
207
+ let after;
208
+ for (; ; ) {
209
+ const rows = await backend.findNodesByKind({
210
+ graphId,
211
+ kind,
212
+ excludeDeleted: !options.includeDeleted,
213
+ orderBy: "id",
214
+ limit: options.batchSize,
215
+ ...after === void 0 ? {} : { after }
216
+ });
217
+ if (rows.length === 0) return;
218
+ const nodes = rows.map((row) => {
219
+ const node = {
220
+ kind: row.kind,
221
+ id: row.id,
222
+ properties: rowPropsToObject(row.props)
223
+ };
224
+ if (options.includeTemporal) {
225
+ const validFrom = (
226
+ // eslint-disable-next-line unicorn/no-null
227
+ row.valid_from ?? null
228
+ );
229
+ node.validFrom = validFrom;
230
+ if (row.valid_to) {
231
+ node.validTo = row.valid_to;
232
+ }
233
+ }
234
+ if (options.includeMeta) {
235
+ node.meta = {
236
+ version: row.version,
237
+ createdAt: row.created_at,
238
+ updatedAt: row.updated_at
239
+ };
240
+ }
241
+ return node;
242
+ });
243
+ yield { type: "nodes", nodes };
244
+ if (rows.length < options.batchSize) return;
245
+ after = rows.at(-1).id;
246
+ }
247
+ }
248
+ async function* exportEdgeChunks(backend, graphId, kind, options) {
249
+ let after;
250
+ for (; ; ) {
251
+ const rows = await backend.findEdgesByKind({
252
+ graphId,
253
+ kind,
254
+ excludeDeleted: !options.includeDeleted,
255
+ orderBy: "id",
256
+ limit: options.batchSize,
257
+ ...after === void 0 ? {} : { after }
258
+ });
259
+ if (rows.length === 0) return;
260
+ const edges = rows.map((row) => {
261
+ const edge = {
262
+ kind: row.kind,
263
+ id: row.id,
264
+ from: {
265
+ kind: row.from_kind,
266
+ id: row.from_id
267
+ },
268
+ to: {
269
+ kind: row.to_kind,
270
+ id: row.to_id
271
+ },
272
+ properties: rowPropsToObject(row.props)
273
+ };
274
+ if (options.includeTemporal) {
275
+ const validFrom = (
276
+ // eslint-disable-next-line unicorn/no-null
277
+ row.valid_from ?? null
278
+ );
279
+ edge.validFrom = validFrom;
280
+ if (row.valid_to) {
281
+ edge.validTo = row.valid_to;
282
+ }
283
+ }
284
+ if (options.includeMeta) {
285
+ edge.meta = {
286
+ createdAt: row.created_at,
287
+ updatedAt: row.updated_at
288
+ };
289
+ }
290
+ return edge;
291
+ });
292
+ yield { type: "edges", edges };
293
+ if (rows.length < options.batchSize) return;
294
+ after = rows.at(-1).id;
295
+ }
296
+ }
297
+
298
+ // src/interchange/import.ts
299
+ async function importGraph(store, data, rawOptions) {
300
+ const options = ImportOptionsSchema.parse(rawOptions);
301
+ const result = emptyImportResult();
302
+ const errors = [];
303
+ const graph = store.graph;
304
+ const graphId = store.graphId;
305
+ const backend = store.backend;
306
+ const registry = store.registry;
307
+ const nodeSchemas = buildNodeSchemaMap(graph);
308
+ const edgeSchemas = buildEdgeSchemaMap(graph);
309
+ const importedNodeIds = /* @__PURE__ */ new Set();
310
+ await runInWriteTransaction(store, backend, async (target, lock) => {
311
+ await processNodes(
312
+ target,
313
+ graphId,
314
+ registry,
315
+ data.nodes,
316
+ nodeSchemas,
317
+ options,
318
+ result,
319
+ errors,
320
+ importedNodeIds,
321
+ lock
322
+ );
323
+ await processEdges(
324
+ target,
325
+ graphId,
326
+ registry,
327
+ data.edges,
328
+ edgeSchemas,
329
+ nodeSchemas,
330
+ options,
331
+ result,
332
+ errors,
333
+ importedNodeIds
334
+ );
335
+ });
336
+ await refreshStatisticsAfterImport(store, options, result, "importGraph");
337
+ return {
338
+ ...result,
339
+ success: errors.length === 0,
340
+ errors
341
+ };
342
+ }
343
+ async function importGraphStream(store, chunks, rawOptions) {
344
+ const options = ImportOptionsSchema.parse(rawOptions);
345
+ const result = emptyImportResult();
346
+ let header;
347
+ let receivedEdges = false;
348
+ for await (const chunk of chunks) {
349
+ switch (chunk.type) {
350
+ case "header": {
351
+ if (header !== void 0) {
352
+ throw new Error(
353
+ "Graph interchange stream emitted more than one header."
354
+ );
355
+ }
356
+ header = chunk.header;
357
+ break;
358
+ }
359
+ case "nodes": {
360
+ if (header === void 0) {
361
+ throw new Error("Graph interchange stream must start with a header.");
362
+ }
363
+ if (receivedEdges) {
364
+ throw new Error(
365
+ "Graph interchange stream cannot emit nodes after edges."
366
+ );
367
+ }
368
+ if (chunk.nodes.length === 0) break;
369
+ mergeImportResult(
370
+ result,
371
+ await importGraph(store, graphDataForChunk(header, chunk.nodes, []), {
372
+ ...options,
373
+ refreshStatistics: false
374
+ })
375
+ );
376
+ throwIfStreamChunkFailed(result, options);
377
+ break;
378
+ }
379
+ case "edges": {
380
+ if (header === void 0) {
381
+ throw new Error("Graph interchange stream must start with a header.");
382
+ }
383
+ receivedEdges = true;
384
+ if (chunk.edges.length === 0) break;
385
+ mergeImportResult(
386
+ result,
387
+ await importGraph(store, graphDataForChunk(header, [], chunk.edges), {
388
+ ...options,
389
+ refreshStatistics: false
390
+ })
391
+ );
392
+ throwIfStreamChunkFailed(result, options);
393
+ break;
394
+ }
395
+ }
396
+ }
397
+ if (header === void 0) {
398
+ throw new Error("Graph interchange stream ended before emitting a header.");
399
+ }
400
+ await refreshStatisticsAfterImport(
401
+ store,
402
+ options,
403
+ result,
404
+ "importGraphStream"
405
+ );
406
+ return { ...result, success: result.errors.length === 0 };
407
+ }
408
+ function throwIfStreamChunkFailed(result, options) {
409
+ if (options.onStreamChunkError === "continue" || result.errors.length === 0) {
410
+ return;
411
+ }
412
+ throw new Error(
413
+ 'Graph interchange stream aborted after a chunk reported import errors. Earlier chunks remain committed; use onStreamChunkError: "continue" for best-effort ingestion.'
414
+ );
415
+ }
416
+ function emptyImportResult() {
417
+ return {
418
+ success: true,
419
+ nodes: { created: 0, updated: 0, skipped: 0 },
420
+ edges: { created: 0, updated: 0, skipped: 0 },
421
+ errors: []
422
+ };
423
+ }
424
+ function graphDataForChunk(header, nodes, edges) {
425
+ return { ...header, nodes, edges };
426
+ }
427
+ function mergeImportResult(target, source) {
428
+ target.nodes.created += source.nodes.created;
429
+ target.nodes.updated += source.nodes.updated;
430
+ target.nodes.skipped += source.nodes.skipped;
431
+ target.edges.created += source.edges.created;
432
+ target.edges.updated += source.edges.updated;
433
+ target.edges.skipped += source.edges.skipped;
434
+ target.errors.push(...source.errors);
435
+ }
436
+ async function refreshStatisticsAfterImport(store, options, result, surface) {
437
+ const mutationCount = result.nodes.created + result.nodes.updated + result.edges.created + result.edges.updated;
438
+ if ((options.refreshStatistics ?? true) && mutationCount > 0) {
439
+ try {
440
+ await store.refreshStatistics();
441
+ } catch (error) {
442
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
443
+ console.warn(
444
+ `[typegraph] ${surface} committed its rows but the follow-up statistics refresh failed; run store.refreshStatistics() to give the planner fresh statistics.`,
445
+ error
446
+ );
447
+ }
448
+ }
449
+ }
450
+ }
451
+ function buildNodeSchemaMap(graph) {
452
+ const map = /* @__PURE__ */ new Map();
453
+ for (const kindName of getNodeKinds(graph)) {
454
+ const registration = graph.nodes[kindName];
455
+ map.set(kindName, {
456
+ registration,
457
+ schema: registration.type.schema
458
+ });
459
+ }
460
+ return map;
461
+ }
462
+ function buildEdgeSchemaMap(graph) {
463
+ const map = /* @__PURE__ */ new Map();
464
+ for (const kindName of getEdgeKinds(graph)) {
465
+ const registration = graph.edges[kindName];
466
+ map.set(kindName, {
467
+ registration,
468
+ schema: registration.type.schema
469
+ });
470
+ }
471
+ return map;
472
+ }
473
+ async function processNodes(backend, graphId, registry, nodes, schemas, options, result, errors, importedNodeIds, lock) {
474
+ const batchSize = options.batchSize;
475
+ for (let index = 0; index < nodes.length; index += batchSize) {
476
+ const batch = nodes.slice(index, index + batchSize);
477
+ await processNodeSlice(
478
+ backend,
479
+ graphId,
480
+ registry,
481
+ batch,
482
+ schemas,
483
+ options,
484
+ result,
485
+ errors,
486
+ importedNodeIds,
487
+ lock
488
+ );
489
+ }
490
+ }
491
+ function recordNodeOutcome(node, outcome, result, errors, importedNodeIds) {
492
+ switch (outcome.status) {
493
+ case "created": {
494
+ result.nodes.created++;
495
+ importedNodeIds.add(makeNodeKey(node.kind, node.id));
496
+ break;
497
+ }
498
+ case "updated": {
499
+ result.nodes.updated++;
500
+ importedNodeIds.add(makeNodeKey(node.kind, node.id));
501
+ break;
502
+ }
503
+ case "skipped": {
504
+ result.nodes.skipped++;
505
+ if (outcome.liveTarget) {
506
+ importedNodeIds.add(makeNodeKey(node.kind, node.id));
507
+ }
508
+ break;
509
+ }
510
+ case "error": {
511
+ errors.push({
512
+ entityType: "node",
513
+ kind: node.kind,
514
+ id: node.id,
515
+ error: outcome.error
516
+ });
517
+ break;
518
+ }
519
+ }
520
+ }
521
+ async function processNodeSlice(backend, graphId, registry, batch, schemas, options, result, errors, importedNodeIds, lock) {
522
+ const record = (node, outcome) => {
523
+ recordNodeOutcome(node, outcome, result, errors, importedNodeIds);
524
+ };
525
+ const candidates = [];
526
+ const deferred = [];
527
+ const seenKeys = /* @__PURE__ */ new Set();
528
+ for (const node of batch) {
529
+ const schemaEntry = schemas.get(node.kind);
530
+ if (!schemaEntry) {
531
+ record(node, {
532
+ status: "error",
533
+ error: `Unknown node kind: ${node.kind}`
534
+ });
535
+ continue;
536
+ }
537
+ const propsResult = validateProperties(
538
+ node.properties,
539
+ schemaEntry.schema,
540
+ options.onUnknownProperty
541
+ );
542
+ if (!propsResult.success) {
543
+ record(node, { status: "error", error: propsResult.error });
544
+ continue;
545
+ }
546
+ const validityError = validateValidityWindow(node);
547
+ if (validityError !== void 0) {
548
+ record(node, { status: "error", error: validityError });
549
+ continue;
550
+ }
551
+ const key = makeNodeKey(node.kind, node.id);
552
+ if (seenKeys.has(key)) {
553
+ deferred.push(node);
554
+ continue;
555
+ }
556
+ seenKeys.add(key);
557
+ candidates.push({
558
+ node,
559
+ schemaEntry,
560
+ props: propsResult.data,
561
+ draft: {
562
+ kind: node.kind,
563
+ id: node.id,
564
+ nodeKind: schemaEntry.registration.type,
565
+ uniqueConstraints: schemaEntry.registration.unique ?? [],
566
+ validatedProps: propsResult.data,
567
+ // NodeCreateDraft.validFrom is string | undefined (never null) — it
568
+ // only feeds batch validation-cache priming, which never inspects
569
+ // it, so normalizing the explicit-NULL sentinel away here is inert.
570
+ // The actual insert (buildImportInsertParams) reads node.validFrom
571
+ // directly and preserves the null.
572
+ validFrom: node.validFrom ?? void 0,
573
+ validTo: node.validTo
574
+ }
575
+ });
576
+ }
577
+ const {
578
+ backend: validationBackend,
579
+ registerPendingNode,
580
+ registerPendingUniqueEntries,
581
+ registerAppliedNodeUpdate,
582
+ seedNodeRow,
583
+ seedUniqueRow
584
+ } = createNodeBatchValidationBackend(graphId, registry, backend);
585
+ await primeBatchValidationCaches(
586
+ { graphId, registry },
587
+ candidates.map((candidate) => candidate.draft),
588
+ backend,
589
+ { seedNodeRow, seedUniqueRow }
590
+ );
591
+ const writeContext = { graphId, registry, lock };
592
+ const accepted = [];
593
+ for (const candidate of candidates) {
594
+ const { node, schemaEntry, props } = candidate;
595
+ const uniqueConstraints = schemaEntry.registration.unique ?? [];
596
+ const existing = await validationBackend.getNode(
597
+ graphId,
598
+ node.kind,
599
+ node.id
600
+ );
601
+ if (existing) {
602
+ switch (options.onConflict) {
603
+ case "skip": {
604
+ record(node, {
605
+ status: "skipped",
606
+ liveTarget: isLiveNodeRow(existing)
607
+ });
608
+ break;
609
+ }
610
+ case "error": {
611
+ record(node, {
612
+ status: "error",
613
+ error: `Node already exists: ${node.kind}:${node.id}`
614
+ });
615
+ break;
616
+ }
617
+ case "update": {
618
+ if (!isLiveNodeRow(existing)) {
619
+ record(node, { status: "skipped", liveTarget: false });
620
+ break;
621
+ }
622
+ const updateResult = await catchUniquenessError(
623
+ () => applyNodeUpdate(
624
+ writeContext,
625
+ {
626
+ existing,
627
+ schema: schemaEntry.registration.type.schema,
628
+ validatedProps: props,
629
+ uniqueConstraints,
630
+ ...node.validTo !== void 0 && { validTo: node.validTo }
631
+ },
632
+ // The pending-aware overlay, not the raw backend: the update's
633
+ // uniqueness pre-check must see a unique value already reserved by
634
+ // an unflushed create EARLIER in this slice, so it degrades to a
635
+ // per-row error exactly as the sequential path does — rather than
636
+ // claiming the key on the real backend and colliding with that
637
+ // create at flush (which would throw and roll back the whole
638
+ // import). Writes still delegate to the real backend.
639
+ validationBackend
640
+ )
641
+ );
642
+ if (updateResult.ok) {
643
+ registerAppliedNodeUpdate(
644
+ node.kind,
645
+ node.id,
646
+ rowPropsToObject(existing.props),
647
+ props,
648
+ uniqueConstraints
649
+ );
650
+ }
651
+ record(
652
+ node,
653
+ updateResult.ok ? { status: "updated" } : { status: "error", error: updateResult.error }
654
+ );
655
+ break;
656
+ }
657
+ }
658
+ continue;
659
+ }
660
+ const uniquenessResult = await catchUniquenessError(
661
+ () => checkUniquenessConstraints(
662
+ { graphId, registry, backend: validationBackend },
663
+ node.kind,
664
+ node.id,
665
+ props,
666
+ uniqueConstraints
667
+ )
668
+ );
669
+ if (!uniquenessResult.ok) {
670
+ record(node, { status: "error", error: uniquenessResult.error });
671
+ continue;
672
+ }
673
+ registerPendingNode(buildImportInsertParams(graphId, candidate));
674
+ registerPendingUniqueEntries(node.kind, node.id, props, uniqueConstraints);
675
+ accepted.push(candidate);
676
+ }
677
+ if (accepted.length > 0) {
678
+ const insertParamsList = accepted.map(
679
+ (candidate) => buildImportInsertParams(graphId, candidate)
680
+ );
681
+ if (backend.insertNodesBatch === void 0) {
682
+ for (const params of insertParamsList) {
683
+ await backend.insertNode(params);
684
+ }
685
+ } else {
686
+ await backend.insertNodesBatch(insertParamsList);
687
+ }
688
+ await applyNodeInsertSideEffectsBatch(
689
+ writeContext,
690
+ accepted.map((candidate) => ({
691
+ kind: candidate.node.kind,
692
+ id: candidate.node.id,
693
+ schema: candidate.schemaEntry.registration.type.schema,
694
+ props: candidate.props,
695
+ uniqueConstraints: candidate.schemaEntry.registration.unique ?? []
696
+ })),
697
+ backend
698
+ );
699
+ for (const candidate of accepted) {
700
+ record(candidate.node, { status: "created" });
701
+ }
702
+ }
703
+ for (const node of deferred) {
704
+ record(
705
+ node,
706
+ await processNode(
707
+ backend,
708
+ graphId,
709
+ registry,
710
+ node,
711
+ schemas,
712
+ options,
713
+ lock
714
+ )
715
+ );
716
+ }
717
+ }
718
+ function buildImportInsertParams(graphId, candidate) {
719
+ const { node, props } = candidate;
720
+ return {
721
+ graphId,
722
+ kind: node.kind,
723
+ id: node.id,
724
+ props,
725
+ ...node.validFrom !== void 0 && { validFrom: node.validFrom },
726
+ ...node.validTo !== void 0 && { validTo: node.validTo }
727
+ };
728
+ }
729
+ async function catchUniquenessError(fn) {
730
+ try {
731
+ return { ok: true, value: await fn() };
732
+ } catch (error) {
733
+ if (error instanceof UniquenessError) {
734
+ return { ok: false, error: error.message };
735
+ }
736
+ throw error;
737
+ }
738
+ }
739
+ function validateValidityWindow(entity) {
740
+ try {
741
+ validateOptionalCanonicalIsoDate(
742
+ entity.validFrom ?? void 0,
743
+ "validFrom"
744
+ );
745
+ validateOptionalCanonicalIsoDate(entity.validTo, "validTo");
746
+ return void 0;
747
+ } catch (error) {
748
+ return error instanceof Error ? error.message : String(error);
749
+ }
750
+ }
751
+ async function processNode(backend, graphId, registry, node, schemas, options, lock) {
752
+ const schemaEntry = schemas.get(node.kind);
753
+ if (!schemaEntry) {
754
+ return { status: "error", error: `Unknown node kind: ${node.kind}` };
755
+ }
756
+ const propsResult = validateProperties(
757
+ node.properties,
758
+ schemaEntry.schema,
759
+ options.onUnknownProperty
760
+ );
761
+ if (!propsResult.success) {
762
+ return { status: "error", error: propsResult.error };
763
+ }
764
+ const validityError = validateValidityWindow(node);
765
+ if (validityError !== void 0) {
766
+ return { status: "error", error: validityError };
767
+ }
768
+ const { registration } = schemaEntry;
769
+ const uniqueConstraints = registration.unique ?? [];
770
+ const writeContext = { graphId, registry, lock };
771
+ const existing = await backend.getNode(graphId, node.kind, node.id);
772
+ if (existing) {
773
+ switch (options.onConflict) {
774
+ case "skip": {
775
+ return { status: "skipped", liveTarget: isLiveNodeRow(existing) };
776
+ }
777
+ case "error": {
778
+ return {
779
+ status: "error",
780
+ error: `Node already exists: ${node.kind}:${node.id}`
781
+ };
782
+ }
783
+ case "update": {
784
+ if (!isLiveNodeRow(existing)) {
785
+ return { status: "skipped", liveTarget: false };
786
+ }
787
+ const updateResult = await catchUniquenessError(
788
+ () => applyNodeUpdate(
789
+ writeContext,
790
+ {
791
+ existing,
792
+ schema: registration.type.schema,
793
+ validatedProps: propsResult.data,
794
+ uniqueConstraints,
795
+ ...node.validTo !== void 0 && { validTo: node.validTo }
796
+ },
797
+ backend
798
+ )
799
+ );
800
+ if (!updateResult.ok) {
801
+ return { status: "error", error: updateResult.error };
802
+ }
803
+ return { status: "updated" };
804
+ }
805
+ }
806
+ }
807
+ const uniquenessResult = await catchUniquenessError(
808
+ () => checkUniquenessConstraints(
809
+ { graphId, registry, backend },
810
+ node.kind,
811
+ node.id,
812
+ propsResult.data,
813
+ uniqueConstraints
814
+ )
815
+ );
816
+ if (!uniquenessResult.ok) {
817
+ return { status: "error", error: uniquenessResult.error };
818
+ }
819
+ await backend.insertNode({
820
+ graphId,
821
+ kind: node.kind,
822
+ id: node.id,
823
+ props: propsResult.data,
824
+ ...node.validFrom !== void 0 && { validFrom: node.validFrom },
825
+ ...node.validTo !== void 0 && { validTo: node.validTo }
826
+ });
827
+ await applyNodeInsertSideEffects(
828
+ writeContext,
829
+ {
830
+ kind: node.kind,
831
+ id: node.id,
832
+ schema: registration.type.schema,
833
+ props: propsResult.data,
834
+ uniqueConstraints
835
+ },
836
+ backend
837
+ );
838
+ return { status: "created" };
839
+ }
840
+ async function processEdges(backend, graphId, registry, edges, edgeSchemas, nodeSchemas, options, result, errors, importedNodeIds) {
841
+ const batchSize = options.batchSize;
842
+ for (let index = 0; index < edges.length; index += batchSize) {
843
+ const batch = edges.slice(index, index + batchSize);
844
+ await processEdgeSlice(
845
+ backend,
846
+ graphId,
847
+ registry,
848
+ batch,
849
+ edgeSchemas,
850
+ nodeSchemas,
851
+ options,
852
+ result,
853
+ errors,
854
+ importedNodeIds
855
+ );
856
+ }
857
+ }
858
+ function recordEdgeOutcome(edge, outcome, result, errors) {
859
+ switch (outcome.status) {
860
+ case "created": {
861
+ result.edges.created++;
862
+ break;
863
+ }
864
+ case "updated": {
865
+ result.edges.updated++;
866
+ break;
867
+ }
868
+ case "skipped": {
869
+ result.edges.skipped++;
870
+ break;
871
+ }
872
+ case "error": {
873
+ errors.push({
874
+ entityType: "edge",
875
+ kind: edge.kind,
876
+ id: edge.id,
877
+ error: outcome.error
878
+ });
879
+ break;
880
+ }
881
+ }
882
+ }
883
+ async function processEdgeSlice(backend, graphId, registry, batch, edgeSchemas, nodeSchemas, options, result, errors, importedNodeIds) {
884
+ const record = (edge, outcome) => {
885
+ recordEdgeOutcome(edge, outcome, result, errors);
886
+ };
887
+ const candidates = [];
888
+ const deferred = [];
889
+ const seenIds = /* @__PURE__ */ new Set();
890
+ for (const edge of batch) {
891
+ const schemaEntry = edgeSchemas.get(edge.kind);
892
+ if (!schemaEntry) {
893
+ record(edge, {
894
+ status: "error",
895
+ error: `Unknown edge kind: ${edge.kind}`
896
+ });
897
+ continue;
898
+ }
899
+ if (!nodeSchemas.has(edge.from.kind)) {
900
+ record(edge, {
901
+ status: "error",
902
+ error: `Unknown from node kind: ${edge.from.kind}`
903
+ });
904
+ continue;
905
+ }
906
+ if (!nodeSchemas.has(edge.to.kind)) {
907
+ record(edge, {
908
+ status: "error",
909
+ error: `Unknown to node kind: ${edge.to.kind}`
910
+ });
911
+ continue;
912
+ }
913
+ const endpointError = validateEdgeEndpoints(
914
+ edge.kind,
915
+ edge.from.kind,
916
+ edge.to.kind,
917
+ schemaEntry.registration,
918
+ registry
919
+ );
920
+ if (endpointError !== void 0) {
921
+ record(edge, { status: "error", error: endpointError.message });
922
+ continue;
923
+ }
924
+ const propsResult = validateProperties(
925
+ edge.properties,
926
+ schemaEntry.schema,
927
+ options.onUnknownProperty
928
+ );
929
+ if (!propsResult.success) {
930
+ record(edge, { status: "error", error: propsResult.error });
931
+ continue;
932
+ }
933
+ const validityError = validateValidityWindow(edge);
934
+ if (validityError !== void 0) {
935
+ record(edge, { status: "error", error: validityError });
936
+ continue;
937
+ }
938
+ if (seenIds.has(edge.id)) {
939
+ deferred.push(edge);
940
+ continue;
941
+ }
942
+ seenIds.add(edge.id);
943
+ candidates.push({ edge, props: propsResult.data });
944
+ }
945
+ const liveEndpointKeys = /* @__PURE__ */ new Set();
946
+ const checkedEndpointKeys = /* @__PURE__ */ new Set();
947
+ if (options.validateReferences && backend.getNodes !== void 0) {
948
+ const idsByKind = /* @__PURE__ */ new Map();
949
+ for (const { edge } of candidates) {
950
+ for (const endpoint of [edge.from, edge.to]) {
951
+ const key = makeNodeKey(endpoint.kind, endpoint.id);
952
+ if (importedNodeIds.has(key) || checkedEndpointKeys.has(key)) continue;
953
+ checkedEndpointKeys.add(key);
954
+ const ids = idsByKind.get(endpoint.kind) ?? /* @__PURE__ */ new Set();
955
+ ids.add(endpoint.id);
956
+ idsByKind.set(endpoint.kind, ids);
957
+ }
958
+ }
959
+ for (const [kind, ids] of idsByKind) {
960
+ const rows = await backend.getNodes(graphId, kind, [...ids]);
961
+ for (const row of rows) {
962
+ if (isLiveNodeRow(row)) {
963
+ liveEndpointKeys.add(makeNodeKey(kind, row.id));
964
+ }
965
+ }
966
+ }
967
+ }
968
+ const endpointIsLive = async (endpoint) => {
969
+ const key = makeNodeKey(endpoint.kind, endpoint.id);
970
+ if (importedNodeIds.has(key)) return true;
971
+ if (checkedEndpointKeys.has(key)) return liveEndpointKeys.has(key);
972
+ const row = await backend.getNode(graphId, endpoint.kind, endpoint.id);
973
+ return row !== void 0 && isLiveNodeRow(row);
974
+ };
975
+ const existingById = /* @__PURE__ */ new Map();
976
+ if (candidates.length > 0 && backend.getEdges !== void 0) {
977
+ const rows = await backend.getEdges(
978
+ graphId,
979
+ candidates.map((candidate) => candidate.edge.id)
980
+ );
981
+ for (const row of rows) {
982
+ existingById.set(row.id, row);
983
+ }
984
+ for (const { edge } of candidates) {
985
+ if (!existingById.has(edge.id)) existingById.set(edge.id, void 0);
986
+ }
987
+ }
988
+ const accepted = [];
989
+ for (const candidate of candidates) {
990
+ const { edge, props } = candidate;
991
+ if (options.validateReferences) {
992
+ if (!await endpointIsLive(edge.from)) {
993
+ record(edge, {
994
+ status: "error",
995
+ error: `From node not found: ${edge.from.kind}:${edge.from.id}`
996
+ });
997
+ continue;
998
+ }
999
+ if (!await endpointIsLive(edge.to)) {
1000
+ record(edge, {
1001
+ status: "error",
1002
+ error: `To node not found: ${edge.to.kind}:${edge.to.id}`
1003
+ });
1004
+ continue;
1005
+ }
1006
+ }
1007
+ const existing = existingById.has(edge.id) ? existingById.get(edge.id) : await backend.getEdge(graphId, edge.id);
1008
+ if (existing) {
1009
+ switch (options.onConflict) {
1010
+ case "skip": {
1011
+ record(edge, {
1012
+ status: "skipped",
1013
+ liveTarget: existing.deleted_at === void 0
1014
+ });
1015
+ break;
1016
+ }
1017
+ case "error": {
1018
+ record(edge, {
1019
+ status: "error",
1020
+ error: `Edge already exists: ${edge.id}`
1021
+ });
1022
+ break;
1023
+ }
1024
+ case "update": {
1025
+ if (existing.deleted_at !== void 0) {
1026
+ record(edge, { status: "skipped"});
1027
+ break;
1028
+ }
1029
+ await backend.updateEdge({
1030
+ graphId,
1031
+ id: edge.id,
1032
+ props,
1033
+ ...edge.validTo !== void 0 && { validTo: edge.validTo }
1034
+ });
1035
+ record(edge, { status: "updated" });
1036
+ break;
1037
+ }
1038
+ }
1039
+ continue;
1040
+ }
1041
+ accepted.push(candidate);
1042
+ }
1043
+ if (accepted.length > 0) {
1044
+ const insertParamsList = accepted.map(({ edge, props }) => ({
1045
+ graphId,
1046
+ id: edge.id,
1047
+ kind: edge.kind,
1048
+ fromKind: edge.from.kind,
1049
+ fromId: edge.from.id,
1050
+ toKind: edge.to.kind,
1051
+ toId: edge.to.id,
1052
+ props,
1053
+ ...edge.validFrom !== void 0 && { validFrom: edge.validFrom },
1054
+ ...edge.validTo !== void 0 && { validTo: edge.validTo }
1055
+ }));
1056
+ if (backend.insertEdgesBatch === void 0) {
1057
+ for (const params of insertParamsList) {
1058
+ await backend.insertEdge(params);
1059
+ }
1060
+ } else {
1061
+ await backend.insertEdgesBatch(insertParamsList);
1062
+ }
1063
+ for (const candidate of accepted) {
1064
+ record(candidate.edge, { status: "created" });
1065
+ }
1066
+ }
1067
+ for (const edge of deferred) {
1068
+ record(
1069
+ edge,
1070
+ await processEdge(
1071
+ backend,
1072
+ graphId,
1073
+ registry,
1074
+ edge,
1075
+ edgeSchemas,
1076
+ nodeSchemas,
1077
+ options,
1078
+ importedNodeIds
1079
+ )
1080
+ );
1081
+ }
1082
+ }
1083
+ async function processEdge(backend, graphId, registry, edge, edgeSchemas, nodeSchemas, options, importedNodeIds) {
1084
+ const schemaEntry = edgeSchemas.get(edge.kind);
1085
+ if (!schemaEntry) {
1086
+ return { status: "error", error: `Unknown edge kind: ${edge.kind}` };
1087
+ }
1088
+ if (!nodeSchemas.has(edge.from.kind)) {
1089
+ return {
1090
+ status: "error",
1091
+ error: `Unknown from node kind: ${edge.from.kind}`
1092
+ };
1093
+ }
1094
+ if (!nodeSchemas.has(edge.to.kind)) {
1095
+ return { status: "error", error: `Unknown to node kind: ${edge.to.kind}` };
1096
+ }
1097
+ const endpointError = validateEdgeEndpoints(
1098
+ edge.kind,
1099
+ edge.from.kind,
1100
+ edge.to.kind,
1101
+ schemaEntry.registration,
1102
+ registry
1103
+ );
1104
+ if (endpointError !== void 0) {
1105
+ return { status: "error", error: endpointError.message };
1106
+ }
1107
+ if (options.validateReferences) {
1108
+ const fromKey = makeNodeKey(edge.from.kind, edge.from.id);
1109
+ const toKey = makeNodeKey(edge.to.kind, edge.to.id);
1110
+ if (!importedNodeIds.has(fromKey)) {
1111
+ const fromExists = await backend.getNode(
1112
+ graphId,
1113
+ edge.from.kind,
1114
+ edge.from.id
1115
+ );
1116
+ if (fromExists === void 0 || !isLiveNodeRow(fromExists)) {
1117
+ return {
1118
+ status: "error",
1119
+ error: `From node not found: ${edge.from.kind}:${edge.from.id}`
1120
+ };
1121
+ }
1122
+ }
1123
+ if (!importedNodeIds.has(toKey)) {
1124
+ const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);
1125
+ if (toExists === void 0 || !isLiveNodeRow(toExists)) {
1126
+ return {
1127
+ status: "error",
1128
+ error: `To node not found: ${edge.to.kind}:${edge.to.id}`
1129
+ };
1130
+ }
1131
+ }
1132
+ }
1133
+ const propsResult = validateProperties(
1134
+ edge.properties,
1135
+ schemaEntry.schema,
1136
+ options.onUnknownProperty
1137
+ );
1138
+ if (!propsResult.success) {
1139
+ return { status: "error", error: propsResult.error };
1140
+ }
1141
+ const validityError = validateValidityWindow(edge);
1142
+ if (validityError !== void 0) {
1143
+ return { status: "error", error: validityError };
1144
+ }
1145
+ const existing = await backend.getEdge(graphId, edge.id);
1146
+ if (existing) {
1147
+ switch (options.onConflict) {
1148
+ case "skip": {
1149
+ return {
1150
+ status: "skipped",
1151
+ liveTarget: existing.deleted_at === void 0
1152
+ };
1153
+ }
1154
+ case "error": {
1155
+ return { status: "error", error: `Edge already exists: ${edge.id}` };
1156
+ }
1157
+ case "update": {
1158
+ if (existing.deleted_at !== void 0) {
1159
+ return { status: "skipped", liveTarget: false };
1160
+ }
1161
+ await backend.updateEdge({
1162
+ graphId,
1163
+ id: edge.id,
1164
+ props: propsResult.data,
1165
+ ...edge.validTo !== void 0 && { validTo: edge.validTo }
1166
+ });
1167
+ return { status: "updated" };
1168
+ }
1169
+ }
1170
+ }
1171
+ await backend.insertEdge({
1172
+ graphId,
1173
+ id: edge.id,
1174
+ kind: edge.kind,
1175
+ fromKind: edge.from.kind,
1176
+ fromId: edge.from.id,
1177
+ toKind: edge.to.kind,
1178
+ toId: edge.to.id,
1179
+ props: propsResult.data,
1180
+ ...edge.validFrom !== void 0 && { validFrom: edge.validFrom },
1181
+ ...edge.validTo !== void 0 && { validTo: edge.validTo }
1182
+ });
1183
+ return { status: "created" };
1184
+ }
1185
+ function validateProperties(properties, schema, unknownStrategy) {
1186
+ try {
1187
+ const knownKeys = new Set(Object.keys(schema.shape));
1188
+ const unknownKeys = Object.keys(properties).filter(
1189
+ (key) => !knownKeys.has(key)
1190
+ );
1191
+ if (unknownKeys.length > 0) {
1192
+ switch (unknownStrategy) {
1193
+ case "error": {
1194
+ return {
1195
+ success: false,
1196
+ error: `Unknown properties: ${unknownKeys.join(", ")}`
1197
+ };
1198
+ }
1199
+ case "strip": {
1200
+ const stripped = {};
1201
+ for (const key of knownKeys) {
1202
+ if (key in properties) {
1203
+ stripped[key] = properties[key];
1204
+ }
1205
+ }
1206
+ const result2 = schema.safeParse(stripped);
1207
+ if (!result2.success) {
1208
+ return {
1209
+ success: false,
1210
+ error: formatZodError(result2.error)
1211
+ };
1212
+ }
1213
+ return {
1214
+ success: true,
1215
+ data: result2.data
1216
+ };
1217
+ }
1218
+ case "allow": {
1219
+ const result2 = schema.safeParse(properties);
1220
+ if (!result2.success) {
1221
+ return {
1222
+ success: false,
1223
+ error: formatZodError(result2.error)
1224
+ };
1225
+ }
1226
+ return { success: true, data: properties };
1227
+ }
1228
+ }
1229
+ }
1230
+ const result = schema.safeParse(properties);
1231
+ if (!result.success) {
1232
+ return { success: false, error: formatZodError(result.error) };
1233
+ }
1234
+ return { success: true, data: result.data };
1235
+ } catch (error) {
1236
+ const message = error instanceof Error ? error.message : String(error);
1237
+ return { success: false, error: `Validation error: ${message}` };
1238
+ }
1239
+ }
1240
+ function formatZodError(error) {
1241
+ return error.issues.map((issue) => {
1242
+ const path = issue.path.join(".");
1243
+ return path ? `${path}: ${issue.message}` : issue.message;
1244
+ }).join("; ");
1245
+ }
1246
+ function makeNodeKey(kind, id) {
1247
+ return `${kind}:${id}`;
1248
+ }
1249
+
1250
+ export { ConflictStrategySchema, ExportOptionsSchema, ExportStreamOptionsSchema, FORMAT_VERSION, GraphDataHeaderSchema, GraphDataSchema, GraphDataSourceSchema, GraphInterchangeChunkSchema, ImportErrorSchema, ImportOptionsSchema, ImportResultSchema, InterchangeEdgeSchema, InterchangeNodeSchema, UnknownPropertyStrategySchema, exportGraph, exportGraphStream, importGraph, importGraphStream };
1251
+ //# sourceMappingURL=chunk-KMI7LYAF.js.map
1252
+ //# sourceMappingURL=chunk-KMI7LYAF.js.map