@nicia-ai/typegraph 0.37.1 → 0.39.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 (372) hide show
  1. package/README.md +12 -10
  2. package/dist/backend/drizzle/indexes.cjs +32 -0
  3. package/dist/backend/drizzle/indexes.cjs.map +1 -0
  4. package/dist/backend/drizzle/indexes.d.cts +43 -0
  5. package/dist/backend/drizzle/indexes.d.ts +43 -0
  6. package/dist/backend/drizzle/indexes.js +11 -0
  7. package/dist/backend/drizzle/indexes.js.map +1 -0
  8. package/dist/backend/index.cjs +161 -0
  9. package/dist/backend/index.cjs.map +1 -0
  10. package/dist/backend/index.d.cts +3 -0
  11. package/dist/backend/index.d.ts +3 -0
  12. package/dist/backend/index.js +8 -0
  13. package/dist/backend/index.js.map +1 -0
  14. package/dist/backend/postgres/index.cjs +32 -28
  15. package/dist/backend/postgres/index.d.cts +13 -12
  16. package/dist/backend/postgres/index.d.ts +13 -12
  17. package/dist/backend/postgres/index.js +19 -15
  18. package/dist/backend/postgres/pglite-store.cjs +67 -0
  19. package/dist/backend/postgres/pglite-store.cjs.map +1 -0
  20. package/dist/backend/postgres/pglite-store.d.cts +38 -0
  21. package/dist/backend/postgres/pglite-store.d.ts +38 -0
  22. package/dist/backend/postgres/pglite-store.js +65 -0
  23. package/dist/backend/postgres/pglite-store.js.map +1 -0
  24. package/dist/backend/postgres/pglite.cjs +25 -50
  25. package/dist/backend/postgres/pglite.cjs.map +1 -1
  26. package/dist/backend/postgres/pglite.d.cts +10 -9
  27. package/dist/backend/postgres/pglite.d.ts +10 -9
  28. package/dist/backend/postgres/pglite.js +20 -52
  29. package/dist/backend/postgres/pglite.js.map +1 -1
  30. package/dist/backend/sqlite/index.cjs +29 -25
  31. package/dist/backend/sqlite/index.d.cts +11 -11
  32. package/dist/backend/sqlite/index.d.ts +11 -11
  33. package/dist/backend/sqlite/index.js +17 -13
  34. package/dist/backend/sqlite/libsql.cjs +23 -19
  35. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  36. package/dist/backend/sqlite/libsql.d.cts +9 -10
  37. package/dist/backend/sqlite/libsql.d.ts +9 -10
  38. package/dist/backend/sqlite/libsql.js +19 -15
  39. package/dist/backend/sqlite/libsql.js.map +1 -1
  40. package/dist/backend/sqlite/local-store.cjs +72 -0
  41. package/dist/backend/sqlite/local-store.cjs.map +1 -0
  42. package/dist/backend/sqlite/local-store.d.cts +42 -0
  43. package/dist/backend/sqlite/local-store.d.ts +42 -0
  44. package/dist/backend/sqlite/local-store.js +67 -0
  45. package/dist/backend/sqlite/local-store.js.map +1 -0
  46. package/dist/backend/sqlite/local.cjs +28 -183
  47. package/dist/backend/sqlite/local.cjs.map +1 -1
  48. package/dist/backend/sqlite/local.d.cts +8 -81
  49. package/dist/backend/sqlite/local.d.ts +8 -81
  50. package/dist/backend/sqlite/local.js +20 -180
  51. package/dist/backend/sqlite/local.js.map +1 -1
  52. package/dist/chunk-2EBMPJBO.js +16 -0
  53. package/dist/chunk-2EBMPJBO.js.map +1 -0
  54. package/dist/chunk-35S6P5ZU.js +27 -0
  55. package/dist/chunk-35S6P5ZU.js.map +1 -0
  56. package/dist/chunk-3LKL3S6X.js +50 -0
  57. package/dist/chunk-3LKL3S6X.js.map +1 -0
  58. package/dist/{chunk-RCVLFTCT.js → chunk-3SK4SVTW.js} +13 -12
  59. package/dist/chunk-3SK4SVTW.js.map +1 -0
  60. package/dist/chunk-3YFDFOYB.cjs +192 -0
  61. package/dist/chunk-3YFDFOYB.cjs.map +1 -0
  62. package/dist/{chunk-WOJMKB3N.cjs → chunk-5ELKD2FQ.cjs} +1677 -308
  63. package/dist/chunk-5ELKD2FQ.cjs.map +1 -0
  64. package/dist/{chunk-5AVRFNP4.cjs → chunk-6SRLCSAV.cjs} +3012 -1513
  65. package/dist/chunk-6SRLCSAV.cjs.map +1 -0
  66. package/dist/chunk-6XDBRDZE.js +312 -0
  67. package/dist/chunk-6XDBRDZE.js.map +1 -0
  68. package/dist/chunk-764JHTLT.cjs +15 -0
  69. package/dist/chunk-764JHTLT.cjs.map +1 -0
  70. package/dist/chunk-76HE7DJP.js +68 -0
  71. package/dist/chunk-76HE7DJP.js.map +1 -0
  72. package/dist/{chunk-VGDDG3XJ.cjs → chunk-7M3NACL3.cjs} +12 -12
  73. package/dist/{chunk-VGDDG3XJ.cjs.map → chunk-7M3NACL3.cjs.map} +1 -1
  74. package/dist/chunk-AOL64O4Z.js +165 -0
  75. package/dist/chunk-AOL64O4Z.js.map +1 -0
  76. package/dist/{chunk-27SSDCEP.cjs → chunk-B63IFHXR.cjs} +53 -74
  77. package/dist/chunk-B63IFHXR.cjs.map +1 -0
  78. package/dist/{chunk-3XXGYU62.cjs → chunk-BKAKAVRW.cjs} +56 -53
  79. package/dist/chunk-BKAKAVRW.cjs.map +1 -0
  80. package/dist/{chunk-YTSN73ND.js → chunk-BQITNFQJ.js} +3 -3
  81. package/dist/{chunk-YTSN73ND.js.map → chunk-BQITNFQJ.js.map} +1 -1
  82. package/dist/{chunk-GA4TT3DH.js → chunk-CBK2IVI2.js} +1999 -503
  83. package/dist/chunk-CBK2IVI2.js.map +1 -0
  84. package/dist/{chunk-6EEO3OVU.cjs → chunk-CWX77JB4.cjs} +22 -59
  85. package/dist/chunk-CWX77JB4.cjs.map +1 -0
  86. package/dist/{chunk-UGZUAYAR.js → chunk-D7PG5D5K.js} +4 -3
  87. package/dist/chunk-D7PG5D5K.js.map +1 -0
  88. package/dist/chunk-DDCIXXOO.js +9 -0
  89. package/dist/chunk-DDCIXXOO.js.map +1 -0
  90. package/dist/chunk-DDCYVIVV.cjs +44 -0
  91. package/dist/chunk-DDCYVIVV.cjs.map +1 -0
  92. package/dist/{chunk-UV3WP5WZ.js → chunk-DOKUXLFH.js} +61 -29
  93. package/dist/chunk-DOKUXLFH.js.map +1 -0
  94. package/dist/{chunk-XPCZADMT.cjs → chunk-DOVMTPKE.cjs} +89 -27
  95. package/dist/chunk-DOVMTPKE.cjs.map +1 -0
  96. package/dist/{chunk-5PNMDJ7J.js → chunk-DPNA466P.js} +14 -9
  97. package/dist/chunk-DPNA466P.js.map +1 -0
  98. package/dist/{chunk-BYPOGQWK.js → chunk-DRACN6XG.js} +6 -4
  99. package/dist/chunk-DRACN6XG.js.map +1 -0
  100. package/dist/{chunk-TGOMW4MB.cjs → chunk-E2Q7SP2K.cjs} +110 -109
  101. package/dist/chunk-E2Q7SP2K.cjs.map +1 -0
  102. package/dist/chunk-E6TXEISH.cjs +175 -0
  103. package/dist/chunk-E6TXEISH.cjs.map +1 -0
  104. package/dist/{chunk-3C2RYI6L.cjs → chunk-EOJFGECD.cjs} +11 -11
  105. package/dist/chunk-EOJFGECD.cjs.map +1 -0
  106. package/dist/{chunk-XWV4JT34.js → chunk-ERZ4QPQX.js} +27 -22
  107. package/dist/chunk-ERZ4QPQX.js.map +1 -0
  108. package/dist/{chunk-DFVLCOP6.js → chunk-EZH7FNUS.js} +3 -3
  109. package/dist/{chunk-DFVLCOP6.js.map → chunk-EZH7FNUS.js.map} +1 -1
  110. package/dist/{chunk-WWFHO375.cjs → chunk-FJMPR3OH.cjs} +4 -3
  111. package/dist/chunk-FJMPR3OH.cjs.map +1 -0
  112. package/dist/chunk-FMNUSGZ4.cjs +12 -0
  113. package/dist/chunk-FMNUSGZ4.cjs.map +1 -0
  114. package/dist/{chunk-EXU3RASM.js → chunk-G3CSQLLT.js} +20 -474
  115. package/dist/chunk-G3CSQLLT.js.map +1 -0
  116. package/dist/{chunk-EJYMTO3K.cjs → chunk-GKQU44SQ.cjs} +150 -118
  117. package/dist/chunk-GKQU44SQ.cjs.map +1 -0
  118. package/dist/chunk-GNPGGLAE.cjs +212 -0
  119. package/dist/chunk-GNPGGLAE.cjs.map +1 -0
  120. package/dist/{chunk-QARBLBXT.cjs → chunk-GUUWKPTK.cjs} +7 -7
  121. package/dist/{chunk-QARBLBXT.cjs.map → chunk-GUUWKPTK.cjs.map} +1 -1
  122. package/dist/chunk-GYA4JRP5.js +31 -0
  123. package/dist/chunk-GYA4JRP5.js.map +1 -0
  124. package/dist/{chunk-3GH67G4Z.cjs → chunk-HP6LWBLB.cjs} +16 -42
  125. package/dist/chunk-HP6LWBLB.cjs.map +1 -0
  126. package/dist/{chunk-NXQFATMF.cjs → chunk-HTQOBY75.cjs} +153 -123
  127. package/dist/chunk-HTQOBY75.cjs.map +1 -0
  128. package/dist/chunk-I6FX7AAG.js +39 -0
  129. package/dist/chunk-I6FX7AAG.js.map +1 -0
  130. package/dist/{chunk-VKGKDOKR.js → chunk-IFDXG2YJ.js} +1539 -206
  131. package/dist/chunk-IFDXG2YJ.js.map +1 -0
  132. package/dist/{chunk-IXGYRP2P.js → chunk-IFRPHG7O.js} +79 -49
  133. package/dist/chunk-IFRPHG7O.js.map +1 -0
  134. package/dist/chunk-IMQKXL4E.cjs +12 -0
  135. package/dist/{chunk-QSXTWU4U.cjs.map → chunk-IMQKXL4E.cjs.map} +1 -1
  136. package/dist/chunk-J6IJARLG.js +94 -0
  137. package/dist/chunk-J6IJARLG.js.map +1 -0
  138. package/dist/{chunk-3DS7Z4T4.cjs → chunk-JD2YC62H.cjs} +44 -43
  139. package/dist/chunk-JD2YC62H.cjs.map +1 -0
  140. package/dist/{chunk-W63OVYY4.js → chunk-K34OPSJK.js} +3 -3
  141. package/dist/{chunk-W63OVYY4.js.map → chunk-K34OPSJK.js.map} +1 -1
  142. package/dist/chunk-KAFXPB2L.js +184 -0
  143. package/dist/chunk-KAFXPB2L.js.map +1 -0
  144. package/dist/chunk-KIZSHRUI.cjs +49 -0
  145. package/dist/chunk-KIZSHRUI.cjs.map +1 -0
  146. package/dist/{chunk-K3Q3LJY3.js → chunk-KXFUQNF2.js} +201 -100
  147. package/dist/chunk-KXFUQNF2.js.map +1 -0
  148. package/dist/{chunk-UXLSNRYL.js → chunk-MTNEGGM2.js} +4 -4
  149. package/dist/chunk-MTNEGGM2.js.map +1 -0
  150. package/dist/{chunk-IP3CGGPA.cjs → chunk-N2V3HJFV.cjs} +92 -185
  151. package/dist/chunk-N2V3HJFV.cjs.map +1 -0
  152. package/dist/chunk-NAUA4PW5.cjs +28 -0
  153. package/dist/chunk-NAUA4PW5.cjs.map +1 -0
  154. package/dist/chunk-NMQ6C6TS.cjs +61 -0
  155. package/dist/chunk-NMQ6C6TS.cjs.map +1 -0
  156. package/dist/{chunk-2N6EOBTH.cjs → chunk-NPWACFQJ.cjs} +58 -53
  157. package/dist/chunk-NPWACFQJ.cjs.map +1 -0
  158. package/dist/{chunk-TKT2XHED.js → chunk-NQBYTLPW.js} +13 -12
  159. package/dist/chunk-NQBYTLPW.js.map +1 -0
  160. package/dist/{chunk-5KEQ74YU.cjs → chunk-NT6ILURI.cjs} +9 -86
  161. package/dist/chunk-NT6ILURI.cjs.map +1 -0
  162. package/dist/{chunk-3SLPDKHQ.js → chunk-PH4IJ3V5.js} +5 -77
  163. package/dist/chunk-PH4IJ3V5.js.map +1 -0
  164. package/dist/chunk-PWXGB77L.cjs +56 -0
  165. package/dist/chunk-PWXGB77L.cjs.map +1 -0
  166. package/dist/chunk-PZHC5GCD.js +193 -0
  167. package/dist/chunk-PZHC5GCD.js.map +1 -0
  168. package/dist/chunk-QMQLUA66.js +12 -0
  169. package/dist/chunk-QMQLUA66.js.map +1 -0
  170. package/dist/{chunk-5WWVZMVX.js → chunk-QZ7A6HBM.js} +2 -2
  171. package/dist/{chunk-5WWVZMVX.js.map → chunk-QZ7A6HBM.js.map} +1 -1
  172. package/dist/chunk-RW24SAHI.cjs +74 -0
  173. package/dist/chunk-RW24SAHI.cjs.map +1 -0
  174. package/dist/{chunk-BVRDGYXQ.cjs → chunk-SAFZ6JTI.cjs} +14 -9
  175. package/dist/chunk-SAFZ6JTI.cjs.map +1 -0
  176. package/dist/{chunk-L7HQ2OSI.js → chunk-SCTZRFW5.js} +87 -166
  177. package/dist/chunk-SCTZRFW5.js.map +1 -0
  178. package/dist/{chunk-5KPNWT6X.js → chunk-SDHV2MWU.js} +24 -45
  179. package/dist/chunk-SDHV2MWU.js.map +1 -0
  180. package/dist/{chunk-3RWZPJKV.js → chunk-SU7VQOJ3.js} +21 -78
  181. package/dist/chunk-SU7VQOJ3.js.map +1 -0
  182. package/dist/chunk-SVJ5GEXW.cjs +45 -0
  183. package/dist/chunk-SVJ5GEXW.cjs.map +1 -0
  184. package/dist/chunk-SVUKGWSN.cjs +102 -0
  185. package/dist/chunk-SVUKGWSN.cjs.map +1 -0
  186. package/dist/chunk-TAUGGLNQ.js +59 -0
  187. package/dist/chunk-TAUGGLNQ.js.map +1 -0
  188. package/dist/{chunk-A42GCBGX.cjs → chunk-TRF4EBJT.cjs} +6 -4
  189. package/dist/chunk-TRF4EBJT.cjs.map +1 -0
  190. package/dist/{chunk-KQJ54OG5.js → chunk-U4JDJKPD.js} +19 -56
  191. package/dist/chunk-U4JDJKPD.js.map +1 -0
  192. package/dist/chunk-UH2USOMG.cjs +627 -0
  193. package/dist/chunk-UH2USOMG.cjs.map +1 -0
  194. package/dist/{chunk-XGPUQ56G.js → chunk-UUIBACKJ.js} +15 -38
  195. package/dist/chunk-UUIBACKJ.js.map +1 -0
  196. package/dist/{chunk-5VQM6VWP.cjs → chunk-UWG5GX6E.cjs} +2 -2
  197. package/dist/{chunk-5VQM6VWP.cjs.map → chunk-UWG5GX6E.cjs.map} +1 -1
  198. package/dist/{chunk-K5UBVGJN.js → chunk-VDYA2HMS.js} +6 -6
  199. package/dist/{chunk-K5UBVGJN.js.map → chunk-VDYA2HMS.js.map} +1 -1
  200. package/dist/{chunk-NUIG3BCV.cjs → chunk-VXAFOF6Z.cjs} +93 -155
  201. package/dist/chunk-VXAFOF6Z.cjs.map +1 -0
  202. package/dist/chunk-X4PVHAZ6.cjs +83 -0
  203. package/dist/chunk-X4PVHAZ6.cjs.map +1 -0
  204. package/dist/{chunk-UYQMBBWJ.js → chunk-X6CNEA32.js} +23 -20
  205. package/dist/chunk-X6CNEA32.js.map +1 -0
  206. package/dist/chunk-X6RDQ5NB.cjs +335 -0
  207. package/dist/chunk-X6RDQ5NB.cjs.map +1 -0
  208. package/dist/{chunk-DEFQM7JU.cjs → chunk-XRU7V7FF.cjs} +7 -7
  209. package/dist/{chunk-DEFQM7JU.cjs.map → chunk-XRU7V7FF.cjs.map} +1 -1
  210. package/dist/{chunk-TPF25IG6.js → chunk-XZA3Y4YH.js} +3 -3
  211. package/dist/{chunk-TPF25IG6.js.map → chunk-XZA3Y4YH.js.map} +1 -1
  212. package/dist/{chunk-DIQ3AV5W.cjs → chunk-Y6UA55YS.cjs} +324 -224
  213. package/dist/chunk-Y6UA55YS.cjs.map +1 -0
  214. package/dist/chunk-Y7M44XEK.js +462 -0
  215. package/dist/chunk-Y7M44XEK.js.map +1 -0
  216. package/dist/{chunk-RRSNR3TP.js → chunk-YIRLBUNN.js} +3 -3
  217. package/dist/{chunk-RRSNR3TP.js.map → chunk-YIRLBUNN.js.map} +1 -1
  218. package/dist/chunk-YPUNPG2T.js +47 -0
  219. package/dist/chunk-YPUNPG2T.js.map +1 -0
  220. package/dist/{chunk-QERAIDRJ.js → chunk-Z2PPIVOO.js} +82 -22
  221. package/dist/chunk-Z2PPIVOO.js.map +1 -0
  222. package/dist/chunk-Z5QHVL5U.cjs +12 -0
  223. package/dist/chunk-Z5QHVL5U.cjs.map +1 -0
  224. package/dist/chunk-ZDH3DX3C.cjs +30 -0
  225. package/dist/chunk-ZDH3DX3C.cjs.map +1 -0
  226. package/dist/chunk-ZE6NVENI.js +77 -0
  227. package/dist/chunk-ZE6NVENI.js.map +1 -0
  228. package/dist/chunk-ZKZAIX42.cjs +479 -0
  229. package/dist/chunk-ZKZAIX42.cjs.map +1 -0
  230. package/dist/{chunk-TEDRJXOG.cjs → chunk-ZY4GXIVN.cjs} +5 -5
  231. package/dist/{chunk-TEDRJXOG.cjs.map → chunk-ZY4GXIVN.cjs.map} +1 -1
  232. package/dist/core/index.cjs +117 -0
  233. package/dist/core/index.cjs.map +1 -0
  234. package/dist/core/index.d.cts +225 -0
  235. package/dist/core/index.d.ts +225 -0
  236. package/dist/core/index.js +12 -0
  237. package/dist/core/index.js.map +1 -0
  238. package/dist/{ddl-CS0KUVwB.d.ts → ddl-Dx3Z0_WC.d.ts} +3 -3
  239. package/dist/{ddl-BD-ZfKeX.d.cts → ddl-J6sDyABg.d.cts} +3 -3
  240. package/dist/define-graph-CzEvA_8F.d.cts +174 -0
  241. package/dist/define-graph-DRo9xpYN.d.ts +174 -0
  242. package/dist/{extension-types-BM2ACfYO.d.cts → extension-types-BLEVH4SG.d.cts} +1 -1
  243. package/dist/{extension-types-BM2ACfYO.d.ts → extension-types-BLEVH4SG.d.ts} +1 -1
  244. package/dist/graph-extension/index.cjs +21 -19
  245. package/dist/graph-extension/index.d.cts +4 -4
  246. package/dist/graph-extension/index.d.ts +4 -4
  247. package/dist/graph-extension/index.js +6 -4
  248. package/dist/graph-merge/index.cjs +267 -218
  249. package/dist/graph-merge/index.cjs.map +1 -1
  250. package/dist/graph-merge/index.d.cts +17 -93
  251. package/dist/graph-merge/index.d.ts +17 -93
  252. package/dist/graph-merge/index.js +143 -94
  253. package/dist/graph-merge/index.js.map +1 -1
  254. package/dist/{index-BeacbPoe.d.ts → index-BD_3TCgh.d.ts} +6 -4
  255. package/dist/{index-BPM59vsg.d.cts → index-BihFPsPu.d.cts} +6 -4
  256. package/dist/{fulltext-strategy-C27vXaeB.d.cts → index-Bq7vSPHy.d.ts} +3195 -2646
  257. package/dist/{fulltext-strategy-DebsMrqg.d.ts → index-CrFL_ENI.d.cts} +3195 -2646
  258. package/dist/index.cjs +326 -315
  259. package/dist/index.cjs.map +1 -1
  260. package/dist/index.d.cts +59 -240
  261. package/dist/index.d.ts +59 -240
  262. package/dist/index.js +46 -79
  263. package/dist/index.js.map +1 -1
  264. package/dist/indexes/index.cjs +26 -38
  265. package/dist/indexes/index.d.cts +6 -41
  266. package/dist/indexes/index.d.ts +6 -41
  267. package/dist/indexes/index.js +14 -10
  268. package/dist/interchange/index.cjs +48 -39
  269. package/dist/interchange/index.cjs.map +1 -1
  270. package/dist/interchange/index.d.cts +7 -8
  271. package/dist/interchange/index.d.ts +7 -8
  272. package/dist/interchange/index.js +23 -14
  273. package/dist/interchange/index.js.map +1 -1
  274. package/dist/local-options-CZ1BnIoF.d.cts +29 -0
  275. package/dist/local-options-CZ1BnIoF.d.ts +29 -0
  276. package/dist/{manager-D00_NXvT.d.ts → manager-CASfhmzV.d.ts} +4 -173
  277. package/dist/{manager-nU1vTJLy.d.cts → manager-nCEJiYBb.d.cts} +4 -173
  278. package/dist/{materialize-indexes-zK2J_flP.d.ts → materialize-indexes-D4iei4Kp.d.ts} +1 -1
  279. package/dist/{materialize-indexes-CuR3gAZb.d.cts → materialize-indexes-ExQ6OrAh.d.cts} +1 -1
  280. package/dist/{postgres-IaBA4RgE.d.ts → postgres-Cl1ZAN1G.d.ts} +1 -1
  281. package/dist/{postgres-YrYmPlaU.d.cts → postgres-DMgIKQU-.d.cts} +1 -1
  282. package/dist/postgres-execution-fKW0qRiN.d.cts +14 -0
  283. package/dist/postgres-execution-fKW0qRiN.d.ts +14 -0
  284. package/dist/profiler/index.cjs +9 -8
  285. package/dist/profiler/index.cjs.map +1 -1
  286. package/dist/profiler/index.d.cts +9 -17
  287. package/dist/profiler/index.d.ts +9 -17
  288. package/dist/profiler/index.js +8 -7
  289. package/dist/profiler/index.js.map +1 -1
  290. package/dist/provenance/index.cjs +61 -55
  291. package/dist/provenance/index.cjs.map +1 -1
  292. package/dist/provenance/index.d.cts +7 -8
  293. package/dist/provenance/index.d.ts +7 -8
  294. package/dist/provenance/index.js +34 -28
  295. package/dist/provenance/index.js.map +1 -1
  296. package/dist/schema/index.cjs +46 -37
  297. package/dist/schema/index.cjs.map +1 -1
  298. package/dist/schema/index.d.cts +8 -10
  299. package/dist/schema/index.d.ts +8 -10
  300. package/dist/schema/index.js +22 -13
  301. package/dist/schema/index.js.map +1 -1
  302. package/dist/{sqlite-BUOHPx7p.d.ts → sqlite-BDkW39aa.d.cts} +1 -1
  303. package/dist/{sqlite-Pp8O19WE.d.cts → sqlite-CYfhvESj.d.ts} +1 -1
  304. package/dist/sqlite-execution-DwbE2a9y.d.cts +32 -0
  305. package/dist/sqlite-execution-DwbE2a9y.d.ts +32 -0
  306. package/dist/{store-view-X96Rd00T.d.cts → store-view-BJd6Vwpt.d.cts} +427 -1404
  307. package/dist/{store-view-ANL6mTph.d.ts → store-view-CLIhwMMX.d.ts} +427 -1404
  308. package/dist/temporal-BC_NQV5Y.d.cts +281 -0
  309. package/dist/temporal-DqtOEo_B.d.ts +281 -0
  310. package/dist/{types-r-Zyq2Hz.d.cts → types-COq3-vMC.d.cts} +2 -2
  311. package/dist/{types-wsvuBgPK.d.ts → types-CUevi_D1.d.ts} +2 -2
  312. package/dist/{where-CJOpJj3a.d.ts → where-BdE_cYtx.d.ts} +5 -5
  313. package/dist/{where-K3uBP33l.d.cts → where-C92TXCzT.d.cts} +5 -5
  314. package/package.json +37 -6
  315. package/dist/chunk-27SSDCEP.cjs.map +0 -1
  316. package/dist/chunk-2N6EOBTH.cjs.map +0 -1
  317. package/dist/chunk-3C2RYI6L.cjs.map +0 -1
  318. package/dist/chunk-3DS7Z4T4.cjs.map +0 -1
  319. package/dist/chunk-3GH67G4Z.cjs.map +0 -1
  320. package/dist/chunk-3RWZPJKV.js.map +0 -1
  321. package/dist/chunk-3SLPDKHQ.js.map +0 -1
  322. package/dist/chunk-3XXGYU62.cjs.map +0 -1
  323. package/dist/chunk-44TA22QT.js +0 -1478
  324. package/dist/chunk-44TA22QT.js.map +0 -1
  325. package/dist/chunk-5AVRFNP4.cjs.map +0 -1
  326. package/dist/chunk-5KEQ74YU.cjs.map +0 -1
  327. package/dist/chunk-5KPNWT6X.js.map +0 -1
  328. package/dist/chunk-5PNMDJ7J.js.map +0 -1
  329. package/dist/chunk-6EEO3OVU.cjs.map +0 -1
  330. package/dist/chunk-7YSP4V4R.cjs +0 -69
  331. package/dist/chunk-7YSP4V4R.cjs.map +0 -1
  332. package/dist/chunk-A42GCBGX.cjs.map +0 -1
  333. package/dist/chunk-BVRDGYXQ.cjs.map +0 -1
  334. package/dist/chunk-BYPOGQWK.js.map +0 -1
  335. package/dist/chunk-CUHM5CWJ.cjs +0 -12
  336. package/dist/chunk-CUHM5CWJ.cjs.map +0 -1
  337. package/dist/chunk-DIQ3AV5W.cjs.map +0 -1
  338. package/dist/chunk-EJYMTO3K.cjs.map +0 -1
  339. package/dist/chunk-EXU3RASM.js.map +0 -1
  340. package/dist/chunk-GA4TT3DH.js.map +0 -1
  341. package/dist/chunk-IP3CGGPA.cjs.map +0 -1
  342. package/dist/chunk-IPSVVTWT.cjs +0 -1540
  343. package/dist/chunk-IPSVVTWT.cjs.map +0 -1
  344. package/dist/chunk-IXGYRP2P.js.map +0 -1
  345. package/dist/chunk-K3Q3LJY3.js.map +0 -1
  346. package/dist/chunk-KQJ54OG5.js.map +0 -1
  347. package/dist/chunk-L7HQ2OSI.js.map +0 -1
  348. package/dist/chunk-M6VES7V6.js +0 -239
  349. package/dist/chunk-M6VES7V6.js.map +0 -1
  350. package/dist/chunk-NUIG3BCV.cjs.map +0 -1
  351. package/dist/chunk-NXQFATMF.cjs.map +0 -1
  352. package/dist/chunk-OHMP6N2J.js +0 -47
  353. package/dist/chunk-OHMP6N2J.js.map +0 -1
  354. package/dist/chunk-QERAIDRJ.js.map +0 -1
  355. package/dist/chunk-QSXTWU4U.cjs +0 -12
  356. package/dist/chunk-RCVLFTCT.js.map +0 -1
  357. package/dist/chunk-TGOMW4MB.cjs.map +0 -1
  358. package/dist/chunk-TKT2XHED.js.map +0 -1
  359. package/dist/chunk-UGZUAYAR.js.map +0 -1
  360. package/dist/chunk-UV3WP5WZ.js.map +0 -1
  361. package/dist/chunk-UXLSNRYL.js.map +0 -1
  362. package/dist/chunk-UYQMBBWJ.js.map +0 -1
  363. package/dist/chunk-VKGKDOKR.js.map +0 -1
  364. package/dist/chunk-VL2V6PEN.cjs +0 -261
  365. package/dist/chunk-VL2V6PEN.cjs.map +0 -1
  366. package/dist/chunk-WOJMKB3N.cjs.map +0 -1
  367. package/dist/chunk-WWFHO375.cjs.map +0 -1
  368. package/dist/chunk-XGPUQ56G.js.map +0 -1
  369. package/dist/chunk-XGU7DZDA.cjs +0 -1095
  370. package/dist/chunk-XGU7DZDA.cjs.map +0 -1
  371. package/dist/chunk-XPCZADMT.cjs.map +0 -1
  372. package/dist/chunk-XWV4JT34.js.map +0 -1
@@ -1,12 +1,18 @@
1
- import { compareStrings } from '../chunk-BYPOGQWK.js';
2
- import { lockRecordedGraphWrite, applyNodeSoftDelete, createNodeWriteContext, applyNodeResurrect } from '../chunk-VKGKDOKR.js';
3
- import { rowPropsToObject, isLiveNodeRow, isTombstonedNodeRow } from '../chunk-44TA22QT.js';
4
- import { nowIso } from '../chunk-XGPUQ56G.js';
5
- import '../chunk-OHMP6N2J.js';
6
- import '../chunk-PC2UBAUB.js';
1
+ import { compareStrings } from '../chunk-DRACN6XG.js';
2
+ import { transactionBackend, lockRecordedGraphWrite, transactionNodeOperationHookRunner, applyNodeSoftDelete, createNodeWriteContext, applyNodeResurrect } from '../chunk-IFDXG2YJ.js';
3
+ import '../chunk-35S6P5ZU.js';
4
+ import { rowPropsToObject, isLiveNodeRow, isTombstonedNodeRow } from '../chunk-PZHC5GCD.js';
5
+ import '../chunk-J6IJARLG.js';
6
+ import '../chunk-UUIBACKJ.js';
7
+ import { nowIso } from '../chunk-I6FX7AAG.js';
8
+ import '../chunk-2EBMPJBO.js';
9
+ import '../chunk-DDCIXXOO.js';
10
+ import '../chunk-6XDBRDZE.js';
7
11
  import '../chunk-SNXVDZAJ.js';
12
+ import '../chunk-QMQLUA66.js';
13
+ import '../chunk-PC2UBAUB.js';
8
14
  import { isPlainObject } from '../chunk-ITE4IXAK.js';
9
- import { ConfigurationError, NodeNotFoundError } from '../chunk-5PNMDJ7J.js';
15
+ import { ConfigurationError, NodeNotFoundError } from '../chunk-DPNA466P.js';
10
16
  import '../chunk-G6Q5UM7U.js';
11
17
 
12
18
  // src/provenance/index.ts
@@ -493,10 +499,11 @@ async function runTransition(store, config, sources, retracted) {
493
499
  );
494
500
  }
495
501
  return store.transaction(async (tx) => {
496
- const lock = await lockRecordedGraphWrite(tx.backend, store.graphId);
502
+ const backend = transactionBackend(tx);
503
+ const lock = await lockRecordedGraphWrite(backend, store.graphId);
497
504
  const rows = await Promise.all(
498
505
  uniqueSources.map(
499
- (source) => tx.backend.getNode(store.graphId, source.kind, source.id)
506
+ (source) => backend.getNode(store.graphId, source.kind, source.id)
500
507
  )
501
508
  );
502
509
  const sourceRows = uniqueSources.map((source, index) => {
@@ -506,11 +513,7 @@ async function runTransition(store, config, sources, retracted) {
506
513
  }
507
514
  return { source, row: sourceRow };
508
515
  });
509
- const supportGraph = await loadSupportGraph(
510
- tx.backend,
511
- store.graphId,
512
- config
513
- );
516
+ const supportGraph = await loadSupportGraph(backend, store.graphId, config);
514
517
  const availableBefore = availableSourceKeys(
515
518
  supportGraph.sourceRows,
516
519
  config.retractedField
@@ -531,9 +534,9 @@ async function runTransition(store, config, sources, retracted) {
531
534
  const after = computeSupportSnapshot(supportGraph, availableAfter);
532
535
  const affected = after.affectedFactKeys(uniqueSources);
533
536
  await synchronizeFactCurrency(
534
- tx.backend,
537
+ backend,
535
538
  store,
536
- tx.runNodeOperationHooks,
539
+ transactionNodeOperationHookRunner(tx),
537
540
  after,
538
541
  affected,
539
542
  lock
@@ -549,16 +552,7 @@ function uniqueNodeReferences(references) {
549
552
  return [...byKey.values()];
550
553
  }
551
554
  function createRetractionCapability(store, config) {
552
- const historyEnabled = store.historyEnabled;
553
- if (!historyEnabled) {
554
- throw new ConfigurationError(
555
- "createRetractionCapability requires a store created with { history: true }.",
556
- { graphId: store.graphId },
557
- {
558
- suggestion: "Use createStoreWithSchema(graph, backend, { history: true }) so retraction mutations are captured and queryable with asOfRecorded()."
559
- }
560
- );
561
- }
555
+ assertRetractionHistoryEnabled(store);
562
556
  const normalized = normalizeConfig(store.graph, config);
563
557
  const transition = (sources, retracted) => runTransition(store, normalized, sources, retracted);
564
558
  return {
@@ -568,9 +562,10 @@ function createRetractionCapability(store, config) {
568
562
  unRetractMany: (sources) => transition(sources, false),
569
563
  async holding() {
570
564
  return store.transaction(async (tx) => {
571
- await lockRecordedGraphWrite(tx.backend, store.graphId);
565
+ const backend = transactionBackend(tx);
566
+ await lockRecordedGraphWrite(backend, store.graphId);
572
567
  const snapshot = await computeSupport(
573
- tx.backend,
568
+ backend,
574
569
  store.graphId,
575
570
  normalized
576
571
  );
@@ -581,6 +576,17 @@ function createRetractionCapability(store, config) {
581
576
  }
582
577
  };
583
578
  }
579
+ function assertRetractionHistoryEnabled(store) {
580
+ if (!store.historyEnabled) {
581
+ throw new ConfigurationError(
582
+ "createRetractionCapability requires a store created with { history: true }.",
583
+ { graphId: store.graphId },
584
+ {
585
+ suggestion: "Use createStoreWithSchema(graph, backend, { history: true }) so retraction mutations are captured and queryable with asOfRecorded()."
586
+ }
587
+ );
588
+ }
589
+ }
584
590
 
585
591
  export { createRetractionCapability };
586
592
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/provenance/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AA8BA,IAAM,uBAAA,GAA0B,WAAA;AAChC,IAAM,aAAA,GAAgB,IAAA;AAmJtB,SAAS,OAAO,GAAA,EAAgC;AAC9C,EAAA,OAAO,GAAG,GAAA,CAAI,IAAI,GAAG,aAAa,CAAA,EAAG,IAAI,EAAE,CAAA,CAAA;AAC7C;AAEA,SAAS,OAAO,GAAA,EAA2C;AACzD,EAAA,OAAO,MAAA,CAAO,EAAE,IAAA,EAAM,GAAA,CAAI,MAAM,EAAA,EAAI,GAAA,CAAI,IAAI,CAAA;AAC9C;AAEA,SAAS,YAAY,IAAA,EAAuB;AAC1C,EAAA,OAAO,MAAA,CAAO,EAAE,IAAA,EAAM,IAAA,CAAK,WAAW,EAAA,EAAI,IAAA,CAAK,SAAS,CAAA;AAC1D;AAEA,SAA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,UAAA,CAAW,SAAS,IAAI,CAAA;AAAA,IAClD,WAAW,CAAC,MAAA,KAAW,WAAW,CAAC,MAAM,GAAG,KAAK,CAAA;AAAA,IACjD,aAAA,EAAe,CAAC,OAAA,KAAY,UAAA,CAAW,SAAS,KAAK,CAAA;AAAA,IAErD,MAAM,OAAA,GAAU;AACd,MAAA,OAAO,KAAA,CAAM,WAAA,CAAY,OAAO,EAAA,KAAO;AAKrC,QAAA,MAAM,sBAAA,CAAuB,EAAA,CAAG,OAAA,EAAS,KAAA,CAAM,OAAO,CAAA;AACtD,QAAA,MAAM,WAAW,MAAM,cAAA;AAAA,UACrB,EAAA,CAAG,OAAA;AAAA,UACH,KAAA,CAAM,OAAA;AAAA,UACN;AAAA,SACF;AACA,QAAA,OAAO,gBAAA;AAAA,UACL,QAAA,CAAS;AAAA,SACX;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import {\n type EdgeRow,\n type GraphReadBackend,\n isLiveNodeRow,\n isTombstonedNodeRow,\n type LiveNodeRow,\n type NodeRow,\n rowPropsToObject,\n type TombstonedNodeRow,\n} from \"../backend/types\";\nimport type { GraphDef } from \"../core/define-graph\";\nimport type { NodeRegistration } from \"../core/types\";\nimport { ConfigurationError, NodeNotFoundError } from \"../errors\";\nimport type {\n DynamicNodeCollection,\n HistorySafeTransactionBackend,\n HistoryStore,\n HistoryTransactionContext,\n} from \"../store\";\nimport {\n applyNodeResurrect,\n applyNodeSoftDelete,\n createNodeWriteContext,\n} from \"../store/operations/node-write-pipeline\";\nimport { lockRecordedGraphWrite } from \"../store/recorded-capture\";\nimport { type GraphWriteLock } from \"../store/recorded-capture/clock\";\nimport { compareStrings } from \"../utils/compare\";\nimport { nowIso } from \"../utils/date\";\nimport { isPlainObject } from \"../utils/object\";\n\nconst DEFAULT_RETRACTED_FIELD = \"retracted\";\nconst KEY_SEPARATOR = \"\\u0000\";\n\ntype NodeKind<G extends GraphDef> = Extract<keyof G[\"nodes\"], string>;\ntype EdgeKind<G extends GraphDef> = Extract<keyof G[\"edges\"], string>;\n\nexport type ProvenanceNodeRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n kind: K;\n id: string;\n}>;\n\nexport type ProvenanceJustificationRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = ProvenanceNodeRef<G, K>;\nexport type ProvenanceFactRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = ProvenanceNodeRef<G, K>;\n\ntype ProvenanceSourceConfig<G extends GraphDef = GraphDef> =\n | Readonly<{\n kind: NodeKind<G>;\n retractedField?: string;\n }>\n | Readonly<{\n kinds: readonly NodeKind<G>[];\n retractedField?: string;\n }>;\n\nexport type ProvenanceRetractionConfig<G extends GraphDef = GraphDef> =\n Readonly<{\n source: ProvenanceSourceConfig<G>;\n justification: Readonly<{ kind: NodeKind<G> }>;\n fact: Readonly<{ kinds: readonly NodeKind<G>[] }>;\n premiseOf: Readonly<{ kind: EdgeKind<G> }>;\n derives: Readonly<{ kind: EdgeKind<G> }>;\n }>;\n\n/**\n * Extracts the node kind(s) referenced by a provenance role config, whether\n * declared as a single `{ kind }` or a `{ kinds }` array. Falls back to the\n * full `NodeKind<G>` union when neither shape is present (e.g. a role config\n * that also carries unrelated fields, matched structurally).\n */\ntype KindsFromRef<G extends GraphDef, Ref> =\n Ref extends Readonly<{ kind: infer K }> ? Extract<K, NodeKind<G>>\n : Ref extends Readonly<{ kinds: readonly (infer K)[] }> ?\n Extract<K, NodeKind<G>>\n : NodeKind<G>;\n\ntype SourceKindsFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"source\"]>;\n\ntype FactKindsFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"fact\"]>;\n\ntype JustificationKindFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"justification\"]>;\n\nexport type SurvivedVia<\n G extends GraphDef = GraphDef,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n fact: ProvenanceFactRef<G, FactKind>;\n via: readonly ProvenanceJustificationRef<G, JustificationKind>[];\n}>;\n\nexport type RetractionReport<\n G extends GraphDef = GraphDef,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n died: readonly ProvenanceFactRef<G, FactKind>[];\n survivedVia: readonly SurvivedVia<G, FactKind, JustificationKind>[];\n unaffected: readonly ProvenanceFactRef<G, FactKind>[];\n}>;\n\nexport type RetractionCapability<\n G extends GraphDef = GraphDef,\n SourceKind extends NodeKind<G> = NodeKind<G>,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n retract: (\n source: ProvenanceNodeRef<G, SourceKind>,\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n retractMany: (\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n unRetract: (\n source: ProvenanceNodeRef<G, SourceKind>,\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n unRetractMany: (\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n holding: () => Promise<readonly ProvenanceFactRef<G, FactKind>[]>;\n}>;\n\ntype NormalizedConfig = Readonly<{\n sourceKinds: readonly string[];\n retractedField: string;\n justificationKind: string;\n factKinds: readonly string[];\n premiseOfKind: string;\n derivesKind: string;\n}>;\n\ntype ProvenanceRows = Readonly<{\n justifications: ReadonlyMap<string, NodeRow>;\n facts: ReadonlyMap<string, NodeRow>;\n premiseEdges: readonly EdgeRow[];\n deriveEdges: readonly EdgeRow[];\n}>;\n\ntype SupportEdges = Readonly<{\n premisesByJustification: ReadonlyMap<string, readonly string[]>;\n factsByJustification: ReadonlyMap<string, readonly string[]>;\n justificationsByPremise: ReadonlyMap<string, readonly string[]>;\n}>;\n\ntype SupportSnapshot = Readonly<{\n facts: ReadonlyMap<string, NodeRow>;\n supportedFactKeys: ReadonlySet<string>;\n believedFactKeys: ReadonlySet<string>;\n firingJustificationKeysByFact: ReadonlyMap<string, readonly string[]>;\n affectedFactKeys: (\n sources: readonly ProvenanceNodeRef[],\n ) => ReadonlySet<string>;\n}>;\n\ntype SourceRetractedState = \"retracted\" | \"available\";\n\ntype SourceRow<G extends GraphDef> = Readonly<{\n source: ProvenanceNodeRef<G>;\n row: NodeRow;\n}>;\n\nfunction refKey(ref: ProvenanceNodeRef): string {\n return `${ref.kind}${KEY_SEPARATOR}${ref.id}`;\n}\n\nfunction rowKey(row: Pick<NodeRow, \"kind\" | \"id\">): string {\n return refKey({ kind: row.kind, id: row.id });\n}\n\nfunction edgeFromKey(edge: EdgeRow): string {\n return refKey({ kind: edge.from_kind, id: edge.from_id });\n}\n\nfunction edgeToKey(edge: EdgeRow): string {\n return refKey({ kind: edge.to_kind, id: edge.to_id });\n}\n\nfunction keyToRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(key: string): ProvenanceNodeRef<G, K> {\n const separatorIndex = key.indexOf(KEY_SEPARATOR);\n if (separatorIndex === -1) {\n throw new ConfigurationError(\n \"Invalid provenance identity key.\",\n { key },\n {\n suggestion:\n \"Report this TypeGraph provenance bug with the graph roles that produced the key.\",\n },\n );\n }\n const kind = key.slice(0, separatorIndex);\n const id = key.slice(separatorIndex + KEY_SEPARATOR.length);\n return { kind, id } as ProvenanceNodeRef<G, K>;\n}\n\nfunction sortedReferences<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(keys: Iterable<string>): ProvenanceNodeRef<G, K>[] {\n return [...keys]\n .toSorted((left, right) => compareStrings(left, right))\n .map((key) => keyToRef<G, K>(key));\n}\n\nfunction parseNodeProps(row: NodeRow): Record<string, unknown> {\n const parsed = rowPropsToObject(row.props) as unknown;\n if (!isPlainObject(parsed)) {\n throw new ConfigurationError(\n `Node ${row.kind}/${row.id} props are not an object.`,\n { kind: row.kind, id: row.id },\n );\n }\n return parsed;\n}\n\nfunction sourceRetractedState(\n row: NodeRow,\n retractedField: string,\n): SourceRetractedState {\n const props = parseNodeProps(row);\n const value = props[retractedField];\n if (value === undefined) return \"available\";\n if (typeof value !== \"boolean\") {\n throw new ConfigurationError(\n `Provenance source field \"${retractedField}\" must contain a boolean value.`,\n { kind: row.kind, id: row.id, field: retractedField },\n {\n suggestion:\n \"Use a source node schema with a boolean retracted flag, for example z.boolean().default(false).\",\n },\n );\n }\n return value ? \"retracted\" : \"available\";\n}\n\nfunction normalizeConfig<G extends GraphDef>(\n graph: G,\n config: ProvenanceRetractionConfig<G>,\n): NormalizedConfig {\n const sourceKinds = sourceKindsFromConfig(config.source);\n const justificationKind = config.justification.kind;\n const factKinds = [...config.fact.kinds];\n const premiseOfKind = config.premiseOf.kind;\n const derivesKind = config.derives.kind;\n const retractedField =\n config.source.retractedField ?? DEFAULT_RETRACTED_FIELD;\n\n if (sourceKinds.length === 0) {\n throw new ConfigurationError(\n \"Provenance retraction requires at least one source kind.\",\n { role: \"source\" },\n );\n }\n\n if (factKinds.length === 0) {\n throw new ConfigurationError(\n \"Provenance retraction requires at least one fact kind.\",\n { role: \"fact\" },\n );\n }\n\n const duplicateSourceKinds = duplicateValues(sourceKinds);\n if (duplicateSourceKinds.length > 0) {\n throw new ConfigurationError(\"Provenance source kinds must be unique.\", {\n duplicateSourceKinds,\n });\n }\n\n const duplicateFactKinds = duplicateValues(factKinds);\n if (duplicateFactKinds.length > 0) {\n throw new ConfigurationError(\"Provenance fact kinds must be unique.\", {\n duplicateFactKinds,\n });\n }\n\n for (const kind of sourceKinds) {\n assertKind(graph.nodes, kind, \"source\", \"node\", graph.id);\n }\n assertKind(graph.nodes, justificationKind, \"justification\", \"node\", graph.id);\n for (const kind of factKinds) {\n assertKind(graph.nodes, kind, \"fact\", \"node\", graph.id);\n }\n for (const kind of sourceKinds)\n assertSourceField(graph, kind, retractedField);\n assertKind(graph.edges, premiseOfKind, \"premiseOf\", \"edge\", graph.id);\n assertKind(graph.edges, derivesKind, \"derives\", \"edge\", graph.id);\n\n if (\n factKinds.some(\n (kind) => sourceKinds.includes(kind) || kind === justificationKind,\n )\n ) {\n throw new ConfigurationError(\n \"Provenance fact kinds must be distinct from source and justification kinds.\",\n { sourceKinds, justificationKind, factKinds },\n );\n }\n\n assertEdgeEndpoints(graph, premiseOfKind, {\n role: \"premiseOf\",\n fromKinds: sourceKinds,\n toKinds: [justificationKind],\n });\n assertEdgeEndpoints(graph, derivesKind, {\n role: \"derives\",\n fromKinds: [justificationKind],\n toKinds: factKinds,\n });\n\n return {\n sourceKinds,\n retractedField,\n justificationKind,\n factKinds,\n premiseOfKind,\n derivesKind,\n };\n}\n\nfunction sourceKindsFromConfig<G extends GraphDef>(\n source: ProvenanceSourceConfig<G>,\n): string[] {\n if (\"kinds\" in source) return [...source.kinds];\n return [source.kind];\n}\n\nfunction duplicateValues(values: readonly string[]): string[] {\n const seen = new Set<string>();\n const duplicates = new Set<string>();\n for (const value of values) {\n if (seen.has(value)) {\n duplicates.add(value);\n continue;\n }\n seen.add(value);\n }\n return [...duplicates].toSorted((left, right) => compareStrings(left, right));\n}\n\nfunction assertKind(\n records: Readonly<Record<string, unknown>>,\n kind: string,\n role: string,\n noun: \"node\" | \"edge\",\n graphId: string,\n): void {\n if (Object.hasOwn(records, kind)) return;\n throw new ConfigurationError(\n `Provenance ${role} kind \"${kind}\" is not a ${noun} kind in this graph.`,\n { role, kind, graphId },\n );\n}\n\nfunction assertSourceField<G extends GraphDef>(\n graph: G,\n sourceKind: string,\n retractedField: string,\n): void {\n const registration = graph.nodes[sourceKind];\n if (registration === undefined) return;\n if (Object.hasOwn(registration.type.schema.shape, retractedField)) return;\n throw new ConfigurationError(\n `Provenance source kind \"${sourceKind}\" must include field \"${retractedField}\".`,\n { sourceKind, retractedField },\n {\n suggestion:\n \"Add a boolean retracted flag to the source node schema or pass source.retractedField.\",\n },\n );\n}\n\nfunction assertEdgeEndpoints<G extends GraphDef>(\n graph: G,\n edgeKind: string,\n expected: Readonly<{\n role: string;\n fromKinds: readonly string[];\n toKinds: readonly string[];\n }>,\n): void {\n const registration = graph.edges[edgeKind];\n if (registration === undefined) return;\n const fromKinds = new Set(registration.from.map((node) => node.kind));\n const toKinds = new Set(registration.to.map((node) => node.kind));\n for (const kind of expected.fromKinds) {\n if (fromKinds.has(kind)) continue;\n throw new ConfigurationError(\n `Provenance ${expected.role} edge \"${edgeKind}\" cannot start at \"${kind}\".`,\n { edgeKind, role: expected.role, expectedFrom: kind },\n );\n }\n for (const kind of expected.toKinds) {\n if (toKinds.has(kind)) continue;\n throw new ConfigurationError(\n `Provenance ${expected.role} edge \"${edgeKind}\" cannot end at \"${kind}\".`,\n { edgeKind, role: expected.role, expectedTo: kind },\n );\n }\n}\n\n/**\n * Whether a row's validity window contains `asOf`. The JS mirror of the SQL\n * `\"current\"`-mode predicate, for role reads that must include tombstoned\n * rows (which `\"current\"` cannot express) yet still respect validity.\n * Canonical fixed-width UTC ISO strings compare correctly as text.\n */\nfunction isValidAt(\n row: Pick<NodeRow, \"valid_from\" | \"valid_to\">,\n asOf: string,\n): boolean {\n return (\n (row.valid_from === undefined || row.valid_from <= asOf) &&\n (row.valid_to === undefined || row.valid_to > asOf)\n );\n}\n\n/**\n * Provenance reads follow the store's currency semantics: a source,\n * justification, or support edge counts only while currently valid (the\n * default `\"current\"` read mode), so a validity-expired source no longer\n * supports anything and `holding()` agrees with the collection API about\n * which facts are currently believed. Fact rows additionally need their\n * tombstones — a reopen candidate is by definition soft-deleted — so they\n * are loaded with tombstones and filtered to the same validity instant.\n */\nasync function findNodeRows(\n backend: GraphReadBackend,\n graphId: string,\n kind: string,\n options: Readonly<{ includeTombstones: boolean; asOf: string }>,\n): Promise<readonly NodeRow[]> {\n if (options.includeTombstones) {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: false,\n temporalMode: \"includeTombstones\",\n orderBy: \"id\",\n });\n return rows.filter((row) => isValidAt(row, options.asOf));\n }\n return backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: true,\n temporalMode: \"current\",\n asOf: options.asOf,\n orderBy: \"id\",\n });\n}\n\nasync function findEdgeRows(\n backend: GraphReadBackend,\n graphId: string,\n kind: string,\n asOf: string,\n): Promise<readonly EdgeRow[]> {\n return backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: true,\n temporalMode: \"current\",\n asOf,\n orderBy: \"id\",\n });\n}\n\nasync function readRoles(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n asOf: string,\n): Promise<ProvenanceRows> {\n const [justificationRows, factRowsByKind, premiseEdges, deriveEdges] =\n await Promise.all([\n findNodeRows(backend, graphId, config.justificationKind, {\n includeTombstones: false,\n asOf,\n }),\n Promise.all(\n config.factKinds.map((kind) =>\n findNodeRows(backend, graphId, kind, {\n includeTombstones: true,\n asOf,\n }),\n ),\n ),\n findEdgeRows(backend, graphId, config.premiseOfKind, asOf),\n findEdgeRows(backend, graphId, config.derivesKind, asOf),\n ]);\n const factRows = factRowsByKind.flat();\n\n return {\n justifications: rowsByKey(justificationRows),\n facts: rowsByKey(factRows),\n premiseEdges,\n deriveEdges,\n };\n}\n\nfunction rowsByKey(rows: readonly NodeRow[]): ReadonlyMap<string, NodeRow> {\n const byKey = new Map<string, NodeRow>();\n for (const row of rows) byKey.set(rowKey(row), row);\n return byKey;\n}\n\nfunction appendGroupedValue(\n groups: Map<string, string[]>,\n key: string,\n value: string,\n): void {\n const group = groups.get(key);\n if (group === undefined) {\n groups.set(key, [value]);\n return;\n }\n if (group.includes(value)) return;\n group.push(value);\n}\n\nfunction buildSupportEdges(\n config: NormalizedConfig,\n rows: ProvenanceRows,\n): SupportEdges {\n const premisesByJustification = new Map<string, string[]>();\n const factsByJustification = new Map<string, string[]>();\n const justificationsByPremise = new Map<string, string[]>();\n\n for (const edge of rows.premiseEdges) {\n if (edge.to_kind !== config.justificationKind) continue;\n if (!isPremiseKind(config, edge.from_kind)) continue;\n\n const premiseKey = edgeFromKey(edge);\n const justificationKey = edgeToKey(edge);\n appendGroupedValue(premisesByJustification, justificationKey, premiseKey);\n appendGroupedValue(justificationsByPremise, premiseKey, justificationKey);\n }\n\n for (const edge of rows.deriveEdges) {\n if (edge.from_kind !== config.justificationKind) continue;\n if (!config.factKinds.includes(edge.to_kind)) continue;\n appendGroupedValue(\n factsByJustification,\n edgeFromKey(edge),\n edgeToKey(edge),\n );\n }\n\n return {\n premisesByJustification,\n factsByJustification,\n justificationsByPremise,\n };\n}\n\n/**\n * The whole-graph read a support computation needs: the role rows, the support\n * edges derived from them, and the (non-retracted-visible) source rows. Loaded\n * once per transition so `before` and `after` snapshots share one read instead\n * of scanning the entire provenance graph twice — the graph structure is\n * identical across a transition, only source availability changes.\n */\ntype SupportGraph = Readonly<{\n roles: ProvenanceRows;\n supportEdges: SupportEdges;\n sourceRows: readonly NodeRow[];\n}>;\n\nasync function loadSupportGraph(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n): Promise<SupportGraph> {\n // One read instant for every role read, so the whole snapshot shares a\n // single \"currently valid\" coordinate.\n const asOf = nowIso();\n const roles = await readRoles(backend, graphId, config, asOf);\n const supportEdges = buildSupportEdges(config, roles);\n const sourceRowsByKind = await Promise.all(\n config.sourceKinds.map((kind) =>\n findNodeRows(backend, graphId, kind, { includeTombstones: false, asOf }),\n ),\n );\n return { roles, supportEdges, sourceRows: sourceRowsByKind.flat() };\n}\n\nfunction availableSourceKeys(\n sourceRows: readonly NodeRow[],\n retractedField: string,\n): Set<string> {\n const available = new Set<string>();\n for (const row of sourceRows) {\n if (sourceRetractedState(row, retractedField) === \"available\") {\n available.add(rowKey(row));\n }\n }\n return available;\n}\n\n/**\n * The pure TMS fixpoint: given the loaded graph and the set of available\n * (non-retracted) source keys, derive which facts are supported and believed.\n * No I/O — the same {@link SupportGraph} feeds both the pre- and post-transition\n * snapshots with different availability sets.\n */\nfunction computeSupportSnapshot(\n graph: Pick<SupportGraph, \"roles\" | \"supportEdges\">,\n available: ReadonlySet<string>,\n): SupportSnapshot {\n const { roles, supportEdges } = graph;\n const supported = new Set<string>();\n const inSet = new Set<string>(available);\n const firingJustifications = new Set<string>();\n const firingJustificationKeysByFact = new Map<string, string[]>();\n\n let changed = true;\n while (changed) {\n changed = false;\n for (const [justificationKey] of roles.justifications) {\n if (firingJustifications.has(justificationKey)) continue;\n const premises =\n supportEdges.premisesByJustification.get(justificationKey) ?? [];\n if (!allPremisesSupported(premises, inSet)) continue;\n\n firingJustifications.add(justificationKey);\n const derivedFacts =\n supportEdges.factsByJustification.get(justificationKey) ?? [];\n for (const factKey of derivedFacts) {\n if (!roles.facts.has(factKey)) continue;\n appendGroupedValue(\n firingJustificationKeysByFact,\n factKey,\n justificationKey,\n );\n if (supported.has(factKey)) continue;\n supported.add(factKey);\n inSet.add(factKey);\n changed = true;\n }\n }\n }\n\n const believed = new Set<string>();\n for (const key of supported) {\n const row = roles.facts.get(key);\n if (row !== undefined && row.deleted_at === undefined) believed.add(key);\n }\n\n return {\n facts: roles.facts,\n supportedFactKeys: supported,\n believedFactKeys: believed,\n firingJustificationKeysByFact,\n affectedFactKeys(\n targets: readonly ProvenanceNodeRef[],\n ): ReadonlySet<string> {\n return computeAffectedFactKeys(targets, roles, supportEdges);\n },\n };\n}\n\nasync function computeSupport(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n): Promise<SupportSnapshot> {\n const graph = await loadSupportGraph(backend, graphId, config);\n return computeSupportSnapshot(\n graph,\n availableSourceKeys(graph.sourceRows, config.retractedField),\n );\n}\n\nfunction isPremiseKind(config: NormalizedConfig, kind: string): boolean {\n return config.sourceKinds.includes(kind) || config.factKinds.includes(kind);\n}\n\nfunction allPremisesSupported(\n premises: readonly string[],\n supported: ReadonlySet<string>,\n): boolean {\n for (const premise of premises) {\n if (!supported.has(premise)) return false;\n }\n return true;\n}\n\nfunction computeAffectedFactKeys(\n sources: readonly ProvenanceNodeRef[],\n roles: ProvenanceRows,\n supportEdges: SupportEdges,\n): ReadonlySet<string> {\n const affected = new Set<string>();\n // Seed the BFS with every source at once: the union of facts reachable from\n // any source falls out of one traversal, instead of one BFS per source.\n const frontier = sources.map((source) => refKey(source));\n const seen = new Set<string>(frontier);\n\n while (frontier.length > 0) {\n const current = frontier.shift();\n if (current === undefined) continue;\n\n const justifications =\n supportEdges.justificationsByPremise.get(current) ?? [];\n for (const justificationKey of justifications) {\n const derivedFacts =\n supportEdges.factsByJustification.get(justificationKey) ?? [];\n for (const factKey of derivedFacts) {\n if (!roles.facts.has(factKey)) continue;\n affected.add(factKey);\n if (seen.has(factKey)) continue;\n seen.add(factKey);\n frontier.push(factKey);\n }\n }\n }\n\n return affected;\n}\n\nfunction buildReport<\n G extends GraphDef,\n FactKind extends NodeKind<G>,\n JustificationKind extends NodeKind<G>,\n>(\n before: SupportSnapshot,\n after: SupportSnapshot,\n affected: ReadonlySet<string>,\n): RetractionReport<G, FactKind, JustificationKind> {\n const believedBefore = [...before.believedFactKeys];\n const died = sortedReferences<G, FactKind>(\n believedBefore.filter((key) => !after.supportedFactKeys.has(key)),\n );\n const unaffected = sortedReferences<G, FactKind>(\n believedBefore.filter((key) => !affected.has(key)),\n );\n const survivedVia = [...affected]\n .filter((key) => after.supportedFactKeys.has(key))\n .toSorted((left, right) => compareStrings(left, right))\n .map((key) => ({\n fact: keyToRef<G, FactKind>(key),\n via: sortedReferences<G, JustificationKind>(\n after.firingJustificationKeysByFact.get(key) ?? [],\n ),\n }));\n return { died, survivedVia, unaffected };\n}\n\n/**\n * Brings fact currency in line with the post-transition support snapshot —\n * but only for the facts the transition could have affected (those reachable\n * from the flipped sources through justification edges). Facts outside that\n * set are never touched: an unsupported live fact elsewhere in the graph\n * (e.g. one whose justification edges have not been linked yet) is not this\n * transition's business, and silently tombstoning it would be invisible data\n * loss the report cannot even mention.\n *\n * Closes run before reopens: a reopen re-checks uniqueness, and the unique\n * key it needs may still be held by a fact this same transition is about to\n * close — closing first makes a legal transition order-independent.\n */\n/**\n * Runs `action` over every fact row in `snapshot` that is both affected by the\n * transition and matches `isTargetKey`/`isTargetRow`, concurrently — the\n * matched rows are independent facts, so there is no ordering dependency\n * within a single pass (only between the close pass and the reopen pass,\n * which the caller sequences).\n */\nasync function forEachAffectedFact<T extends NodeRow>(\n snapshot: SupportSnapshot,\n affected: ReadonlySet<string>,\n isTargetKey: (key: string) => boolean,\n isTargetRow: (row: NodeRow) => row is T,\n action: (row: T) => Promise<void>,\n): Promise<void> {\n const rows: T[] = [];\n for (const [key, row] of snapshot.facts) {\n if (!affected.has(key)) continue;\n if (!isTargetKey(key)) continue;\n if (!isTargetRow(row)) continue;\n rows.push(row);\n }\n await Promise.all(rows.map((row) => action(row)));\n}\n\n/**\n * The transaction-scoped hook lifecycle fact close/reopen runs through —\n * `HistoryTransactionContext[\"runNodeOperationHooks\"]`. Using the\n * transaction's runner (not the store's) defers each fact's success hook\n * until the transition's COMMIT, so hooks never report a closed or reopened\n * fact that a failed commit then rolls back.\n */\ntype RunNodeOperationHooks = <T>(\n operation: \"create\" | \"update\" | \"delete\",\n kind: string,\n id: string,\n fn: () => Promise<T>,\n) => Promise<T>;\n\nasync function synchronizeFactCurrency<G extends GraphDef>(\n backend: HistorySafeTransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n snapshot: SupportSnapshot,\n affected: ReadonlySet<string>,\n lock: GraphWriteLock,\n): Promise<void> {\n await forEachAffectedFact(\n snapshot,\n affected,\n (key) => !snapshot.supportedFactKeys.has(key),\n isLiveNodeRow,\n (row) => closeFactCurrency(backend, store, runHooks, row, lock),\n );\n await forEachAffectedFact(\n snapshot,\n affected,\n (key) => snapshot.supportedFactKeys.has(key),\n isTombstonedNodeRow,\n (row) => reopenFactCurrency(backend, store, runHooks, row, lock),\n );\n}\n\nfunction getFactRegistration<G extends GraphDef>(\n store: HistoryStore<G>,\n row: NodeRow,\n): NodeRegistration {\n const registration = store.graph.nodes[row.kind];\n if (registration !== undefined) return registration;\n throw new ConfigurationError(\n `Provenance fact kind \"${row.kind}\" is not a node kind in this graph.`,\n { kind: row.kind, graphId: store.graphId },\n );\n}\n\nasync function closeFactCurrency<G extends GraphDef>(\n backend: HistorySafeTransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n row: LiveNodeRow,\n lock: GraphWriteLock,\n): Promise<void> {\n await runHooks(\"delete\", row.kind, row.id, async () => {\n const registration = getFactRegistration(store, row);\n // The canonical soft-delete steps (tombstone, uniqueness/embedding/\n // fulltext cleanup) WITHOUT delete-behavior enforcement: closing a\n // fact's currency is a belief-status change, not a domain delete, so\n // its connected edges neither block the close (`restrict`) nor get\n // removed (`cascade` / `disconnect`). Every edge survives untouched,\n // making a later reopen an exact inverse of this close.\n await applyNodeSoftDelete(\n createNodeWriteContext(store.graphId, store.registry, lock),\n {\n existing: row,\n schema: registration.type.schema,\n uniqueConstraints: registration.unique ?? [],\n onDelete: registration.onDelete,\n },\n backend,\n { enforceDeleteBehavior: false },\n );\n });\n}\n\nasync function reopenFactCurrency<G extends GraphDef>(\n backend: HistorySafeTransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n row: TombstonedNodeRow,\n lock: GraphWriteLock,\n): Promise<void> {\n await runHooks(\"update\", row.kind, row.id, async () => {\n const registration = getFactRegistration(store, row);\n // The delete removed this fact's uniqueness entries, so reopen re-checks and\n // re-inserts them (rather than the diff-based update path) before clearing\n // the tombstone and re-syncing embeddings/fulltext.\n await applyNodeResurrect(\n createNodeWriteContext(store.graphId, store.registry, lock),\n {\n existing: row,\n schema: registration.type.schema,\n uniqueConstraints: registration.unique ?? [],\n },\n backend,\n );\n });\n}\n\nfunction getTransactionNodeCollection<G extends GraphDef>(\n tx: HistoryTransactionContext<G>,\n kind: string,\n): DynamicNodeCollection {\n const collection = tx.getNodeCollection(kind);\n if (collection !== undefined) return collection;\n throw new ConfigurationError(\n `Provenance source kind \"${kind}\" is not available on this transaction.`,\n { kind },\n );\n}\n\nasync function setSourceRetractionState<G extends GraphDef>(\n tx: HistoryTransactionContext<G>,\n config: NormalizedConfig,\n source: ProvenanceNodeRef,\n retracted: boolean,\n): Promise<void> {\n const collection = getTransactionNodeCollection(tx, source.kind);\n await collection.update(source.id, { [config.retractedField]: retracted });\n}\n\nasync function runTransition<\n G extends GraphDef,\n SourceKind extends NodeKind<G>,\n FactKind extends NodeKind<G>,\n JustificationKind extends NodeKind<G>,\n>(\n store: HistoryStore<G>,\n config: NormalizedConfig,\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n retracted: boolean,\n): Promise<RetractionReport<G, FactKind, JustificationKind>> {\n const uniqueSources = uniqueNodeReferences(sources);\n for (const source of uniqueSources) {\n if (config.sourceKinds.includes(source.kind)) continue;\n throw new ConfigurationError(\n `Provenance retraction source must be one of: ${config.sourceKinds.join(\", \")}.`,\n { expectedKinds: config.sourceKinds, actualKind: source.kind },\n );\n }\n\n return store.transaction(async (tx) => {\n // Serialize the whole read-compute-write transition per graph BEFORE the\n // first read. `store.transaction` itself takes no lock (write operations\n // acquire it at their own boundaries), but a transition's support\n // snapshot must not race a concurrent transition or history write, so\n // the per-graph write lock is acquired explicitly up front. The token is\n // the evidence the currency-sync pipeline steps require.\n const lock = await lockRecordedGraphWrite(tx.backend, store.graphId);\n const rows = await Promise.all(\n uniqueSources.map((source) =>\n tx.backend.getNode(store.graphId, source.kind, source.id),\n ),\n );\n const sourceRows = uniqueSources.map((source, index): SourceRow<G> => {\n const sourceRow = rows[index];\n if (sourceRow === undefined || sourceRow.deleted_at !== undefined) {\n throw new NodeNotFoundError(source.kind, source.id);\n }\n return { source, row: sourceRow };\n });\n\n // Load the provenance graph once. Its structure (justifications, facts,\n // premise/derive edges) is identical before and after the transition — only\n // source availability changes — so the pre- and post-flip snapshots share\n // this read instead of scanning the whole graph twice per retraction.\n const supportGraph = await loadSupportGraph(\n tx.backend,\n store.graphId,\n config,\n );\n const availableBefore = availableSourceKeys(\n supportGraph.sourceRows,\n config.retractedField,\n );\n const before = computeSupportSnapshot(supportGraph, availableBefore);\n\n const nextState: SourceRetractedState =\n retracted ? \"retracted\" : \"available\";\n const availableAfter = new Set(availableBefore);\n for (const { source, row } of sourceRows) {\n const currentState = sourceRetractedState(row, config.retractedField);\n if (currentState === nextState) continue;\n await setSourceRetractionState(tx, config, source, retracted);\n // Mirror the flip in the in-memory availability so `after` matches the\n // source rows now persisted, without re-reading the whole graph.\n if (nextState === \"available\") {\n availableAfter.add(refKey(source));\n } else {\n availableAfter.delete(refKey(source));\n }\n }\n const after = computeSupportSnapshot(supportGraph, availableAfter);\n const affected = after.affectedFactKeys(uniqueSources);\n await synchronizeFactCurrency(\n tx.backend,\n store,\n tx.runNodeOperationHooks,\n after,\n affected,\n lock,\n );\n return buildReport<G, FactKind, JustificationKind>(before, after, affected);\n });\n}\n\nfunction uniqueNodeReferences<\n G extends GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(references: readonly ProvenanceNodeRef<G, K>[]): ProvenanceNodeRef<G, K>[] {\n const byKey = new Map<string, ProvenanceNodeRef<G, K>>();\n for (const reference of references) {\n byKey.set(refKey(reference), reference);\n }\n return [...byKey.values()];\n}\n\nexport function createRetractionCapability<\n G extends GraphDef,\n const C extends ProvenanceRetractionConfig<G>,\n>(\n store: HistoryStore<G>,\n config: C,\n): RetractionCapability<\n G,\n SourceKindsFromConfig<G, C>,\n FactKindsFromConfig<G, C>,\n JustificationKindFromConfig<G, C>\n> {\n const historyEnabled = (store as Readonly<{ historyEnabled: boolean }>)\n .historyEnabled;\n if (!historyEnabled) {\n throw new ConfigurationError(\n \"createRetractionCapability requires a store created with { history: true }.\",\n { graphId: store.graphId },\n {\n suggestion:\n \"Use createStoreWithSchema(graph, backend, { history: true }) so retraction mutations are captured and queryable with asOfRecorded().\",\n },\n );\n }\n const normalized = normalizeConfig(store.graph, config);\n\n // The four retract verbs differ only in one/many source shape and the target\n // retracted flag; the generics are fixed by the config, so hoist one call.\n const transition = (\n sources: readonly ProvenanceNodeRef<G, SourceKindsFromConfig<G, C>>[],\n retracted: boolean,\n ) =>\n runTransition<\n G,\n SourceKindsFromConfig<G, C>,\n FactKindsFromConfig<G, C>,\n JustificationKindFromConfig<G, C>\n >(store, normalized, sources, retracted);\n\n return {\n retract: (source) => transition([source], true),\n retractMany: (sources) => transition(sources, true),\n unRetract: (source) => transition([source], false),\n unRetractMany: (sources) => transition(sources, false),\n\n async holding() {\n return store.transaction(async (tx) => {\n // Same explicit lock as runTransition: the support computation reads\n // several relations, and PostgreSQL's READ COMMITTED gives each\n // statement its own snapshot — without the lock a concurrent\n // transition could commit between those reads and tear the view.\n await lockRecordedGraphWrite(tx.backend, store.graphId);\n const snapshot = await computeSupport(\n tx.backend,\n store.graphId,\n normalized,\n );\n return sortedReferences<G, FactKindsFromConfig<G, C>>(\n snapshot.believedFactKeys,\n );\n });\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/provenance/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAkCA,IAAM,uBAAA,GAA0B,WAAA;AAChC,IAAM,aAAA,GAAgB,IAAA;AAmJtB,SAAS,OAAO,GAAA,EAAgC;AAC9C,EAAA,OAAO,GAAG,GAAA,CAAI,IAAI,GAAG,aAAa,CAAA,EAAG,IAAI,EAAE,CAAA,CAAA;AAC7C;AAEA,SAAS,OAAO,GAAA,EAA2C;AACzD,EAAA,OAAO,MAAA,CAAO,EAAE,IAAA,EAAM,GAAA,CAAI,MAAM,EAAA,EAAI,GAAA,CAAI,IAAI,CAAA;AAC9C;AAEA,SAAS,YAAY,IAAA,EAAuB;AAC1C,EAAA,OAAO,MAAA,CAAO,EAAE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AAA,KAAY,UAAA,CAAW,SAAS,KAAK,CAAA;AAAA,IAErD,MAAM,OAAA,GAAU;AACd,MAAA,OAAO,KAAA,CAAM,WAAA,CAAY,OAAO,EAAA,KAAO;AACrC,QAAA,MAAM,OAAA,GAAU,mBAAmB,EAAE,CAAA;AAKrC,QAAA,MAAM,sBAAA,CAAuB,OAAA,EAAS,KAAA,CAAM,OAAO,CAAA;AACnD,QAAA,MAAM,WAAW,MAAM,cAAA;AAAA,UACrB,OAAA;AAAA,UACA,KAAA,CAAM,OAAA;AAAA,UACN;AAAA,SACF;AACA,QAAA,OAAO,gBAAA;AAAA,UACL,QAAA,CAAS;AAAA,SACX;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF;AAEA,SAAS,+BACP,KAAA,EACM;AACN,EAAA,IAAI,CAAC,MAAM,cAAA,EAAgB;AACzB,IAAA,MAAM,IAAI,kBAAA;AAAA,MACR,6EAAA;AAAA,MACA,EAAE,OAAA,EAAS,KAAA,CAAM,OAAA,EAAQ;AAAA,MACzB;AAAA,QACE,UAAA,EACE;AAAA;AACJ,KACF;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import {\n type EdgeRow,\n type GraphReadBackend,\n isLiveNodeRow,\n isTombstonedNodeRow,\n type LiveNodeRow,\n type NodeRow,\n rowPropsToObject,\n type TombstonedNodeRow,\n type TransactionBackend,\n} from \"../backend/types\";\nimport type { GraphDef } from \"../core/define-graph\";\nimport type { NodeRegistration } from \"../core/types\";\nimport { ConfigurationError, NodeNotFoundError } from \"../errors\";\nimport {\n applyNodeResurrect,\n applyNodeSoftDelete,\n createNodeWriteContext,\n} from \"../store/operations/node-write-pipeline\";\nimport { lockRecordedGraphWrite } from \"../store/recorded-capture\";\nimport { type GraphWriteLock } from \"../store/recorded-capture/clock\";\nimport {\n transactionBackend,\n transactionNodeOperationHookRunner,\n} from \"../store/runtime-port\";\nimport type { HistoryStore } from \"../store/store\";\nimport {\n type DynamicNodeCollection,\n type TransactionContext,\n} from \"../store/types\";\nimport { compareStrings } from \"../utils/compare\";\nimport { nowIso } from \"../utils/date\";\nimport { isPlainObject } from \"../utils/object\";\n\nconst DEFAULT_RETRACTED_FIELD = \"retracted\";\nconst KEY_SEPARATOR = \"\\u0000\";\n\ntype NodeKind<G extends GraphDef> = Extract<keyof G[\"nodes\"], string>;\ntype EdgeKind<G extends GraphDef> = Extract<keyof G[\"edges\"], string>;\n\nexport type ProvenanceNodeRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n kind: K;\n id: string;\n}>;\n\nexport type ProvenanceJustificationRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = ProvenanceNodeRef<G, K>;\nexport type ProvenanceFactRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n> = ProvenanceNodeRef<G, K>;\n\ntype ProvenanceSourceConfig<G extends GraphDef = GraphDef> =\n | Readonly<{\n kind: NodeKind<G>;\n retractedField?: string;\n }>\n | Readonly<{\n kinds: readonly NodeKind<G>[];\n retractedField?: string;\n }>;\n\nexport type ProvenanceRetractionConfig<G extends GraphDef = GraphDef> =\n Readonly<{\n source: ProvenanceSourceConfig<G>;\n justification: Readonly<{ kind: NodeKind<G> }>;\n fact: Readonly<{ kinds: readonly NodeKind<G>[] }>;\n premiseOf: Readonly<{ kind: EdgeKind<G> }>;\n derives: Readonly<{ kind: EdgeKind<G> }>;\n }>;\n\n/**\n * Extracts the node kind(s) referenced by a provenance role config, whether\n * declared as a single `{ kind }` or a `{ kinds }` array. Falls back to the\n * full `NodeKind<G>` union when neither shape is present (e.g. a role config\n * that also carries unrelated fields, matched structurally).\n */\ntype KindsFromRef<G extends GraphDef, Ref> =\n Ref extends Readonly<{ kind: infer K }> ? Extract<K, NodeKind<G>>\n : Ref extends Readonly<{ kinds: readonly (infer K)[] }> ?\n Extract<K, NodeKind<G>>\n : NodeKind<G>;\n\ntype SourceKindsFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"source\"]>;\n\ntype FactKindsFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"fact\"]>;\n\ntype JustificationKindFromConfig<\n G extends GraphDef,\n C extends ProvenanceRetractionConfig<G>,\n> = KindsFromRef<G, C[\"justification\"]>;\n\nexport type SurvivedVia<\n G extends GraphDef = GraphDef,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n fact: ProvenanceFactRef<G, FactKind>;\n via: readonly ProvenanceJustificationRef<G, JustificationKind>[];\n}>;\n\nexport type RetractionReport<\n G extends GraphDef = GraphDef,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n died: readonly ProvenanceFactRef<G, FactKind>[];\n survivedVia: readonly SurvivedVia<G, FactKind, JustificationKind>[];\n unaffected: readonly ProvenanceFactRef<G, FactKind>[];\n}>;\n\nexport type RetractionCapability<\n G extends GraphDef = GraphDef,\n SourceKind extends NodeKind<G> = NodeKind<G>,\n FactKind extends NodeKind<G> = NodeKind<G>,\n JustificationKind extends NodeKind<G> = NodeKind<G>,\n> = Readonly<{\n retract: (\n source: ProvenanceNodeRef<G, SourceKind>,\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n retractMany: (\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n unRetract: (\n source: ProvenanceNodeRef<G, SourceKind>,\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n unRetractMany: (\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n ) => Promise<RetractionReport<G, FactKind, JustificationKind>>;\n holding: () => Promise<readonly ProvenanceFactRef<G, FactKind>[]>;\n}>;\n\ntype NormalizedConfig = Readonly<{\n sourceKinds: readonly string[];\n retractedField: string;\n justificationKind: string;\n factKinds: readonly string[];\n premiseOfKind: string;\n derivesKind: string;\n}>;\n\ntype ProvenanceRows = Readonly<{\n justifications: ReadonlyMap<string, NodeRow>;\n facts: ReadonlyMap<string, NodeRow>;\n premiseEdges: readonly EdgeRow[];\n deriveEdges: readonly EdgeRow[];\n}>;\n\ntype SupportEdges = Readonly<{\n premisesByJustification: ReadonlyMap<string, readonly string[]>;\n factsByJustification: ReadonlyMap<string, readonly string[]>;\n justificationsByPremise: ReadonlyMap<string, readonly string[]>;\n}>;\n\ntype SupportSnapshot = Readonly<{\n facts: ReadonlyMap<string, NodeRow>;\n supportedFactKeys: ReadonlySet<string>;\n believedFactKeys: ReadonlySet<string>;\n firingJustificationKeysByFact: ReadonlyMap<string, readonly string[]>;\n affectedFactKeys: (\n sources: readonly ProvenanceNodeRef[],\n ) => ReadonlySet<string>;\n}>;\n\ntype SourceRetractedState = \"retracted\" | \"available\";\n\ntype SourceRow<G extends GraphDef> = Readonly<{\n source: ProvenanceNodeRef<G>;\n row: NodeRow;\n}>;\n\nfunction refKey(ref: ProvenanceNodeRef): string {\n return `${ref.kind}${KEY_SEPARATOR}${ref.id}`;\n}\n\nfunction rowKey(row: Pick<NodeRow, \"kind\" | \"id\">): string {\n return refKey({ kind: row.kind, id: row.id });\n}\n\nfunction edgeFromKey(edge: EdgeRow): string {\n return refKey({ kind: edge.from_kind, id: edge.from_id });\n}\n\nfunction edgeToKey(edge: EdgeRow): string {\n return refKey({ kind: edge.to_kind, id: edge.to_id });\n}\n\nfunction keyToRef<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(key: string): ProvenanceNodeRef<G, K> {\n const separatorIndex = key.indexOf(KEY_SEPARATOR);\n if (separatorIndex === -1) {\n throw new ConfigurationError(\n \"Invalid provenance identity key.\",\n { key },\n {\n suggestion:\n \"Report this TypeGraph provenance bug with the graph roles that produced the key.\",\n },\n );\n }\n const kind = key.slice(0, separatorIndex);\n const id = key.slice(separatorIndex + KEY_SEPARATOR.length);\n return { kind, id } as ProvenanceNodeRef<G, K>;\n}\n\nfunction sortedReferences<\n G extends GraphDef = GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(keys: Iterable<string>): ProvenanceNodeRef<G, K>[] {\n return [...keys]\n .toSorted((left, right) => compareStrings(left, right))\n .map((key) => keyToRef<G, K>(key));\n}\n\nfunction parseNodeProps(row: NodeRow): Record<string, unknown> {\n const parsed = rowPropsToObject(row.props) as unknown;\n if (!isPlainObject(parsed)) {\n throw new ConfigurationError(\n `Node ${row.kind}/${row.id} props are not an object.`,\n { kind: row.kind, id: row.id },\n );\n }\n return parsed;\n}\n\nfunction sourceRetractedState(\n row: NodeRow,\n retractedField: string,\n): SourceRetractedState {\n const props = parseNodeProps(row);\n const value = props[retractedField];\n if (value === undefined) return \"available\";\n if (typeof value !== \"boolean\") {\n throw new ConfigurationError(\n `Provenance source field \"${retractedField}\" must contain a boolean value.`,\n { kind: row.kind, id: row.id, field: retractedField },\n {\n suggestion:\n \"Use a source node schema with a boolean retracted flag, for example z.boolean().default(false).\",\n },\n );\n }\n return value ? \"retracted\" : \"available\";\n}\n\nfunction normalizeConfig<G extends GraphDef>(\n graph: G,\n config: ProvenanceRetractionConfig<G>,\n): NormalizedConfig {\n const sourceKinds = sourceKindsFromConfig(config.source);\n const justificationKind = config.justification.kind;\n const factKinds = [...config.fact.kinds];\n const premiseOfKind = config.premiseOf.kind;\n const derivesKind = config.derives.kind;\n const retractedField =\n config.source.retractedField ?? DEFAULT_RETRACTED_FIELD;\n\n if (sourceKinds.length === 0) {\n throw new ConfigurationError(\n \"Provenance retraction requires at least one source kind.\",\n { role: \"source\" },\n );\n }\n\n if (factKinds.length === 0) {\n throw new ConfigurationError(\n \"Provenance retraction requires at least one fact kind.\",\n { role: \"fact\" },\n );\n }\n\n const duplicateSourceKinds = duplicateValues(sourceKinds);\n if (duplicateSourceKinds.length > 0) {\n throw new ConfigurationError(\"Provenance source kinds must be unique.\", {\n duplicateSourceKinds,\n });\n }\n\n const duplicateFactKinds = duplicateValues(factKinds);\n if (duplicateFactKinds.length > 0) {\n throw new ConfigurationError(\"Provenance fact kinds must be unique.\", {\n duplicateFactKinds,\n });\n }\n\n for (const kind of sourceKinds) {\n assertKind(graph.nodes, kind, \"source\", \"node\", graph.id);\n }\n assertKind(graph.nodes, justificationKind, \"justification\", \"node\", graph.id);\n for (const kind of factKinds) {\n assertKind(graph.nodes, kind, \"fact\", \"node\", graph.id);\n }\n for (const kind of sourceKinds)\n assertSourceField(graph, kind, retractedField);\n assertKind(graph.edges, premiseOfKind, \"premiseOf\", \"edge\", graph.id);\n assertKind(graph.edges, derivesKind, \"derives\", \"edge\", graph.id);\n\n if (\n factKinds.some(\n (kind) => sourceKinds.includes(kind) || kind === justificationKind,\n )\n ) {\n throw new ConfigurationError(\n \"Provenance fact kinds must be distinct from source and justification kinds.\",\n { sourceKinds, justificationKind, factKinds },\n );\n }\n\n assertEdgeEndpoints(graph, premiseOfKind, {\n role: \"premiseOf\",\n fromKinds: sourceKinds,\n toKinds: [justificationKind],\n });\n assertEdgeEndpoints(graph, derivesKind, {\n role: \"derives\",\n fromKinds: [justificationKind],\n toKinds: factKinds,\n });\n\n return {\n sourceKinds,\n retractedField,\n justificationKind,\n factKinds,\n premiseOfKind,\n derivesKind,\n };\n}\n\nfunction sourceKindsFromConfig<G extends GraphDef>(\n source: ProvenanceSourceConfig<G>,\n): string[] {\n if (\"kinds\" in source) return [...source.kinds];\n return [source.kind];\n}\n\nfunction duplicateValues(values: readonly string[]): string[] {\n const seen = new Set<string>();\n const duplicates = new Set<string>();\n for (const value of values) {\n if (seen.has(value)) {\n duplicates.add(value);\n continue;\n }\n seen.add(value);\n }\n return [...duplicates].toSorted((left, right) => compareStrings(left, right));\n}\n\nfunction assertKind(\n records: Readonly<Record<string, unknown>>,\n kind: string,\n role: string,\n noun: \"node\" | \"edge\",\n graphId: string,\n): void {\n if (Object.hasOwn(records, kind)) return;\n throw new ConfigurationError(\n `Provenance ${role} kind \"${kind}\" is not a ${noun} kind in this graph.`,\n { role, kind, graphId },\n );\n}\n\nfunction assertSourceField<G extends GraphDef>(\n graph: G,\n sourceKind: string,\n retractedField: string,\n): void {\n const registration = graph.nodes[sourceKind];\n if (registration === undefined) return;\n if (Object.hasOwn(registration.type.schema.shape, retractedField)) return;\n throw new ConfigurationError(\n `Provenance source kind \"${sourceKind}\" must include field \"${retractedField}\".`,\n { sourceKind, retractedField },\n {\n suggestion:\n \"Add a boolean retracted flag to the source node schema or pass source.retractedField.\",\n },\n );\n}\n\nfunction assertEdgeEndpoints<G extends GraphDef>(\n graph: G,\n edgeKind: string,\n expected: Readonly<{\n role: string;\n fromKinds: readonly string[];\n toKinds: readonly string[];\n }>,\n): void {\n const registration = graph.edges[edgeKind];\n if (registration === undefined) return;\n const fromKinds = new Set(registration.from.map((node) => node.kind));\n const toKinds = new Set(registration.to.map((node) => node.kind));\n for (const kind of expected.fromKinds) {\n if (fromKinds.has(kind)) continue;\n throw new ConfigurationError(\n `Provenance ${expected.role} edge \"${edgeKind}\" cannot start at \"${kind}\".`,\n { edgeKind, role: expected.role, expectedFrom: kind },\n );\n }\n for (const kind of expected.toKinds) {\n if (toKinds.has(kind)) continue;\n throw new ConfigurationError(\n `Provenance ${expected.role} edge \"${edgeKind}\" cannot end at \"${kind}\".`,\n { edgeKind, role: expected.role, expectedTo: kind },\n );\n }\n}\n\n/**\n * Whether a row's validity window contains `asOf`. The JS mirror of the SQL\n * `\"current\"`-mode predicate, for role reads that must include tombstoned\n * rows (which `\"current\"` cannot express) yet still respect validity.\n * Canonical fixed-width UTC ISO strings compare correctly as text.\n */\nfunction isValidAt(\n row: Pick<NodeRow, \"valid_from\" | \"valid_to\">,\n asOf: string,\n): boolean {\n return (\n (row.valid_from === undefined || row.valid_from <= asOf) &&\n (row.valid_to === undefined || row.valid_to > asOf)\n );\n}\n\n/**\n * Provenance reads follow the store's currency semantics: a source,\n * justification, or support edge counts only while currently valid (the\n * default `\"current\"` read mode), so a validity-expired source no longer\n * supports anything and `holding()` agrees with the collection API about\n * which facts are currently believed. Fact rows additionally need their\n * tombstones — a reopen candidate is by definition soft-deleted — so they\n * are loaded with tombstones and filtered to the same validity instant.\n */\nasync function findNodeRows(\n backend: GraphReadBackend,\n graphId: string,\n kind: string,\n options: Readonly<{ includeTombstones: boolean; asOf: string }>,\n): Promise<readonly NodeRow[]> {\n if (options.includeTombstones) {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: false,\n temporalMode: \"includeTombstones\",\n orderBy: \"id\",\n });\n return rows.filter((row) => isValidAt(row, options.asOf));\n }\n return backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: true,\n temporalMode: \"current\",\n asOf: options.asOf,\n orderBy: \"id\",\n });\n}\n\nasync function findEdgeRows(\n backend: GraphReadBackend,\n graphId: string,\n kind: string,\n asOf: string,\n): Promise<readonly EdgeRow[]> {\n return backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: true,\n temporalMode: \"current\",\n asOf,\n orderBy: \"id\",\n });\n}\n\nasync function readRoles(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n asOf: string,\n): Promise<ProvenanceRows> {\n const [justificationRows, factRowsByKind, premiseEdges, deriveEdges] =\n await Promise.all([\n findNodeRows(backend, graphId, config.justificationKind, {\n includeTombstones: false,\n asOf,\n }),\n Promise.all(\n config.factKinds.map((kind) =>\n findNodeRows(backend, graphId, kind, {\n includeTombstones: true,\n asOf,\n }),\n ),\n ),\n findEdgeRows(backend, graphId, config.premiseOfKind, asOf),\n findEdgeRows(backend, graphId, config.derivesKind, asOf),\n ]);\n const factRows = factRowsByKind.flat();\n\n return {\n justifications: rowsByKey(justificationRows),\n facts: rowsByKey(factRows),\n premiseEdges,\n deriveEdges,\n };\n}\n\nfunction rowsByKey(rows: readonly NodeRow[]): ReadonlyMap<string, NodeRow> {\n const byKey = new Map<string, NodeRow>();\n for (const row of rows) byKey.set(rowKey(row), row);\n return byKey;\n}\n\nfunction appendGroupedValue(\n groups: Map<string, string[]>,\n key: string,\n value: string,\n): void {\n const group = groups.get(key);\n if (group === undefined) {\n groups.set(key, [value]);\n return;\n }\n if (group.includes(value)) return;\n group.push(value);\n}\n\nfunction buildSupportEdges(\n config: NormalizedConfig,\n rows: ProvenanceRows,\n): SupportEdges {\n const premisesByJustification = new Map<string, string[]>();\n const factsByJustification = new Map<string, string[]>();\n const justificationsByPremise = new Map<string, string[]>();\n\n for (const edge of rows.premiseEdges) {\n if (edge.to_kind !== config.justificationKind) continue;\n if (!isPremiseKind(config, edge.from_kind)) continue;\n\n const premiseKey = edgeFromKey(edge);\n const justificationKey = edgeToKey(edge);\n appendGroupedValue(premisesByJustification, justificationKey, premiseKey);\n appendGroupedValue(justificationsByPremise, premiseKey, justificationKey);\n }\n\n for (const edge of rows.deriveEdges) {\n if (edge.from_kind !== config.justificationKind) continue;\n if (!config.factKinds.includes(edge.to_kind)) continue;\n appendGroupedValue(\n factsByJustification,\n edgeFromKey(edge),\n edgeToKey(edge),\n );\n }\n\n return {\n premisesByJustification,\n factsByJustification,\n justificationsByPremise,\n };\n}\n\n/**\n * The whole-graph read a support computation needs: the role rows, the support\n * edges derived from them, and the (non-retracted-visible) source rows. Loaded\n * once per transition so `before` and `after` snapshots share one read instead\n * of scanning the entire provenance graph twice — the graph structure is\n * identical across a transition, only source availability changes.\n */\ntype SupportGraph = Readonly<{\n roles: ProvenanceRows;\n supportEdges: SupportEdges;\n sourceRows: readonly NodeRow[];\n}>;\n\nasync function loadSupportGraph(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n): Promise<SupportGraph> {\n // One read instant for every role read, so the whole snapshot shares a\n // single \"currently valid\" coordinate.\n const asOf = nowIso();\n const roles = await readRoles(backend, graphId, config, asOf);\n const supportEdges = buildSupportEdges(config, roles);\n const sourceRowsByKind = await Promise.all(\n config.sourceKinds.map((kind) =>\n findNodeRows(backend, graphId, kind, { includeTombstones: false, asOf }),\n ),\n );\n return { roles, supportEdges, sourceRows: sourceRowsByKind.flat() };\n}\n\nfunction availableSourceKeys(\n sourceRows: readonly NodeRow[],\n retractedField: string,\n): Set<string> {\n const available = new Set<string>();\n for (const row of sourceRows) {\n if (sourceRetractedState(row, retractedField) === \"available\") {\n available.add(rowKey(row));\n }\n }\n return available;\n}\n\n/**\n * The pure TMS fixpoint: given the loaded graph and the set of available\n * (non-retracted) source keys, derive which facts are supported and believed.\n * No I/O — the same {@link SupportGraph} feeds both the pre- and post-transition\n * snapshots with different availability sets.\n */\nfunction computeSupportSnapshot(\n graph: Pick<SupportGraph, \"roles\" | \"supportEdges\">,\n available: ReadonlySet<string>,\n): SupportSnapshot {\n const { roles, supportEdges } = graph;\n const supported = new Set<string>();\n const inSet = new Set<string>(available);\n const firingJustifications = new Set<string>();\n const firingJustificationKeysByFact = new Map<string, string[]>();\n\n let changed = true;\n while (changed) {\n changed = false;\n for (const [justificationKey] of roles.justifications) {\n if (firingJustifications.has(justificationKey)) continue;\n const premises =\n supportEdges.premisesByJustification.get(justificationKey) ?? [];\n if (!allPremisesSupported(premises, inSet)) continue;\n\n firingJustifications.add(justificationKey);\n const derivedFacts =\n supportEdges.factsByJustification.get(justificationKey) ?? [];\n for (const factKey of derivedFacts) {\n if (!roles.facts.has(factKey)) continue;\n appendGroupedValue(\n firingJustificationKeysByFact,\n factKey,\n justificationKey,\n );\n if (supported.has(factKey)) continue;\n supported.add(factKey);\n inSet.add(factKey);\n changed = true;\n }\n }\n }\n\n const believed = new Set<string>();\n for (const key of supported) {\n const row = roles.facts.get(key);\n if (row !== undefined && row.deleted_at === undefined) believed.add(key);\n }\n\n return {\n facts: roles.facts,\n supportedFactKeys: supported,\n believedFactKeys: believed,\n firingJustificationKeysByFact,\n affectedFactKeys(\n targets: readonly ProvenanceNodeRef[],\n ): ReadonlySet<string> {\n return computeAffectedFactKeys(targets, roles, supportEdges);\n },\n };\n}\n\nasync function computeSupport(\n backend: GraphReadBackend,\n graphId: string,\n config: NormalizedConfig,\n): Promise<SupportSnapshot> {\n const graph = await loadSupportGraph(backend, graphId, config);\n return computeSupportSnapshot(\n graph,\n availableSourceKeys(graph.sourceRows, config.retractedField),\n );\n}\n\nfunction isPremiseKind(config: NormalizedConfig, kind: string): boolean {\n return config.sourceKinds.includes(kind) || config.factKinds.includes(kind);\n}\n\nfunction allPremisesSupported(\n premises: readonly string[],\n supported: ReadonlySet<string>,\n): boolean {\n for (const premise of premises) {\n if (!supported.has(premise)) return false;\n }\n return true;\n}\n\nfunction computeAffectedFactKeys(\n sources: readonly ProvenanceNodeRef[],\n roles: ProvenanceRows,\n supportEdges: SupportEdges,\n): ReadonlySet<string> {\n const affected = new Set<string>();\n // Seed the BFS with every source at once: the union of facts reachable from\n // any source falls out of one traversal, instead of one BFS per source.\n const frontier = sources.map((source) => refKey(source));\n const seen = new Set<string>(frontier);\n\n while (frontier.length > 0) {\n const current = frontier.shift();\n if (current === undefined) continue;\n\n const justifications =\n supportEdges.justificationsByPremise.get(current) ?? [];\n for (const justificationKey of justifications) {\n const derivedFacts =\n supportEdges.factsByJustification.get(justificationKey) ?? [];\n for (const factKey of derivedFacts) {\n if (!roles.facts.has(factKey)) continue;\n affected.add(factKey);\n if (seen.has(factKey)) continue;\n seen.add(factKey);\n frontier.push(factKey);\n }\n }\n }\n\n return affected;\n}\n\nfunction buildReport<\n G extends GraphDef,\n FactKind extends NodeKind<G>,\n JustificationKind extends NodeKind<G>,\n>(\n before: SupportSnapshot,\n after: SupportSnapshot,\n affected: ReadonlySet<string>,\n): RetractionReport<G, FactKind, JustificationKind> {\n const believedBefore = [...before.believedFactKeys];\n const died = sortedReferences<G, FactKind>(\n believedBefore.filter((key) => !after.supportedFactKeys.has(key)),\n );\n const unaffected = sortedReferences<G, FactKind>(\n believedBefore.filter((key) => !affected.has(key)),\n );\n const survivedVia = [...affected]\n .filter((key) => after.supportedFactKeys.has(key))\n .toSorted((left, right) => compareStrings(left, right))\n .map((key) => ({\n fact: keyToRef<G, FactKind>(key),\n via: sortedReferences<G, JustificationKind>(\n after.firingJustificationKeysByFact.get(key) ?? [],\n ),\n }));\n return { died, survivedVia, unaffected };\n}\n\n/**\n * Brings fact currency in line with the post-transition support snapshot —\n * but only for the facts the transition could have affected (those reachable\n * from the flipped sources through justification edges). Facts outside that\n * set are never touched: an unsupported live fact elsewhere in the graph\n * (e.g. one whose justification edges have not been linked yet) is not this\n * transition's business, and silently tombstoning it would be invisible data\n * loss the report cannot even mention.\n *\n * Closes run before reopens: a reopen re-checks uniqueness, and the unique\n * key it needs may still be held by a fact this same transition is about to\n * close — closing first makes a legal transition order-independent.\n */\n/**\n * Runs `action` over every fact row in `snapshot` that is both affected by the\n * transition and matches `isTargetKey`/`isTargetRow`, concurrently — the\n * matched rows are independent facts, so there is no ordering dependency\n * within a single pass (only between the close pass and the reopen pass,\n * which the caller sequences).\n */\nasync function forEachAffectedFact<T extends NodeRow>(\n snapshot: SupportSnapshot,\n affected: ReadonlySet<string>,\n isTargetKey: (key: string) => boolean,\n isTargetRow: (row: NodeRow) => row is T,\n action: (row: T) => Promise<void>,\n): Promise<void> {\n const rows: T[] = [];\n for (const [key, row] of snapshot.facts) {\n if (!affected.has(key)) continue;\n if (!isTargetKey(key)) continue;\n if (!isTargetRow(row)) continue;\n rows.push(row);\n }\n await Promise.all(rows.map((row) => action(row)));\n}\n\n/**\n * The transaction-scoped hook lifecycle fact close/reopen runs through —\n * transaction runtime's operation-hook runner. Using the\n * transaction's runner (not the store's) defers each fact's success hook\n * until the transition's COMMIT, so hooks never report a closed or reopened\n * fact that a failed commit then rolls back.\n */\ntype RunNodeOperationHooks = <T>(\n operation: \"create\" | \"update\" | \"delete\",\n kind: string,\n id: string,\n fn: () => Promise<T>,\n) => Promise<T>;\n\nasync function synchronizeFactCurrency<G extends GraphDef>(\n backend: TransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n snapshot: SupportSnapshot,\n affected: ReadonlySet<string>,\n lock: GraphWriteLock,\n): Promise<void> {\n await forEachAffectedFact(\n snapshot,\n affected,\n (key) => !snapshot.supportedFactKeys.has(key),\n isLiveNodeRow,\n (row) => closeFactCurrency(backend, store, runHooks, row, lock),\n );\n await forEachAffectedFact(\n snapshot,\n affected,\n (key) => snapshot.supportedFactKeys.has(key),\n isTombstonedNodeRow,\n (row) => reopenFactCurrency(backend, store, runHooks, row, lock),\n );\n}\n\nfunction getFactRegistration<G extends GraphDef>(\n store: HistoryStore<G>,\n row: NodeRow,\n): NodeRegistration {\n const registration = store.graph.nodes[row.kind];\n if (registration !== undefined) return registration;\n throw new ConfigurationError(\n `Provenance fact kind \"${row.kind}\" is not a node kind in this graph.`,\n { kind: row.kind, graphId: store.graphId },\n );\n}\n\nasync function closeFactCurrency<G extends GraphDef>(\n backend: TransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n row: LiveNodeRow,\n lock: GraphWriteLock,\n): Promise<void> {\n await runHooks(\"delete\", row.kind, row.id, async () => {\n const registration = getFactRegistration(store, row);\n // The canonical soft-delete steps (tombstone, uniqueness/embedding/\n // fulltext cleanup) WITHOUT delete-behavior enforcement: closing a\n // fact's currency is a belief-status change, not a domain delete, so\n // its connected edges neither block the close (`restrict`) nor get\n // removed (`cascade` / `disconnect`). Every edge survives untouched,\n // making a later reopen an exact inverse of this close.\n await applyNodeSoftDelete(\n createNodeWriteContext(store.graphId, store.registry, lock),\n {\n existing: row,\n schema: registration.type.schema,\n uniqueConstraints: registration.unique ?? [],\n onDelete: registration.onDelete,\n },\n backend,\n { enforceDeleteBehavior: false },\n );\n });\n}\n\nasync function reopenFactCurrency<G extends GraphDef>(\n backend: TransactionBackend,\n store: HistoryStore<G>,\n runHooks: RunNodeOperationHooks,\n row: TombstonedNodeRow,\n lock: GraphWriteLock,\n): Promise<void> {\n await runHooks(\"update\", row.kind, row.id, async () => {\n const registration = getFactRegistration(store, row);\n // The delete removed this fact's uniqueness entries, so reopen re-checks and\n // re-inserts them (rather than the diff-based update path) before clearing\n // the tombstone and re-syncing embeddings/fulltext.\n await applyNodeResurrect(\n createNodeWriteContext(store.graphId, store.registry, lock),\n {\n existing: row,\n schema: registration.type.schema,\n uniqueConstraints: registration.unique ?? [],\n },\n backend,\n );\n });\n}\n\nfunction getTransactionNodeCollection<G extends GraphDef>(\n tx: TransactionContext<G>,\n kind: string,\n): DynamicNodeCollection {\n const collection = tx.getNodeCollection(kind);\n if (collection !== undefined) return collection;\n throw new ConfigurationError(\n `Provenance source kind \"${kind}\" is not available on this transaction.`,\n { kind },\n );\n}\n\nasync function setSourceRetractionState<G extends GraphDef>(\n tx: TransactionContext<G>,\n config: NormalizedConfig,\n source: ProvenanceNodeRef,\n retracted: boolean,\n): Promise<void> {\n const collection = getTransactionNodeCollection(tx, source.kind);\n await collection.update(source.id, { [config.retractedField]: retracted });\n}\n\nasync function runTransition<\n G extends GraphDef,\n SourceKind extends NodeKind<G>,\n FactKind extends NodeKind<G>,\n JustificationKind extends NodeKind<G>,\n>(\n store: HistoryStore<G>,\n config: NormalizedConfig,\n sources: readonly ProvenanceNodeRef<G, SourceKind>[],\n retracted: boolean,\n): Promise<RetractionReport<G, FactKind, JustificationKind>> {\n const uniqueSources = uniqueNodeReferences(sources);\n for (const source of uniqueSources) {\n if (config.sourceKinds.includes(source.kind)) continue;\n throw new ConfigurationError(\n `Provenance retraction source must be one of: ${config.sourceKinds.join(\", \")}.`,\n { expectedKinds: config.sourceKinds, actualKind: source.kind },\n );\n }\n\n return store.transaction(async (tx) => {\n const backend = transactionBackend(tx);\n // Serialize the whole read-compute-write transition per graph BEFORE the\n // first read. `store.transaction` itself takes no lock (write operations\n // acquire it at their own boundaries), but a transition's support\n // snapshot must not race a concurrent transition or history write, so\n // the per-graph write lock is acquired explicitly up front. The token is\n // the evidence the currency-sync pipeline steps require.\n const lock = await lockRecordedGraphWrite(backend, store.graphId);\n const rows = await Promise.all(\n uniqueSources.map((source) =>\n backend.getNode(store.graphId, source.kind, source.id),\n ),\n );\n const sourceRows = uniqueSources.map((source, index): SourceRow<G> => {\n const sourceRow = rows[index];\n if (sourceRow === undefined || sourceRow.deleted_at !== undefined) {\n throw new NodeNotFoundError(source.kind, source.id);\n }\n return { source, row: sourceRow };\n });\n\n // Load the provenance graph once. Its structure (justifications, facts,\n // premise/derive edges) is identical before and after the transition — only\n // source availability changes — so the pre- and post-flip snapshots share\n // this read instead of scanning the whole graph twice per retraction.\n const supportGraph = await loadSupportGraph(backend, store.graphId, config);\n const availableBefore = availableSourceKeys(\n supportGraph.sourceRows,\n config.retractedField,\n );\n const before = computeSupportSnapshot(supportGraph, availableBefore);\n\n const nextState: SourceRetractedState =\n retracted ? \"retracted\" : \"available\";\n const availableAfter = new Set(availableBefore);\n for (const { source, row } of sourceRows) {\n const currentState = sourceRetractedState(row, config.retractedField);\n if (currentState === nextState) continue;\n await setSourceRetractionState(tx, config, source, retracted);\n // Mirror the flip in the in-memory availability so `after` matches the\n // source rows now persisted, without re-reading the whole graph.\n if (nextState === \"available\") {\n availableAfter.add(refKey(source));\n } else {\n availableAfter.delete(refKey(source));\n }\n }\n const after = computeSupportSnapshot(supportGraph, availableAfter);\n const affected = after.affectedFactKeys(uniqueSources);\n await synchronizeFactCurrency(\n backend,\n store,\n transactionNodeOperationHookRunner(tx),\n after,\n affected,\n lock,\n );\n return buildReport<G, FactKind, JustificationKind>(before, after, affected);\n });\n}\n\nfunction uniqueNodeReferences<\n G extends GraphDef,\n K extends NodeKind<G> = NodeKind<G>,\n>(references: readonly ProvenanceNodeRef<G, K>[]): ProvenanceNodeRef<G, K>[] {\n const byKey = new Map<string, ProvenanceNodeRef<G, K>>();\n for (const reference of references) {\n byKey.set(refKey(reference), reference);\n }\n return [...byKey.values()];\n}\n\nexport function createRetractionCapability<\n G extends GraphDef,\n const C extends ProvenanceRetractionConfig<G>,\n>(\n store: HistoryStore<G>,\n config: C,\n): RetractionCapability<\n G,\n SourceKindsFromConfig<G, C>,\n FactKindsFromConfig<G, C>,\n JustificationKindFromConfig<G, C>\n> {\n assertRetractionHistoryEnabled(store);\n const normalized = normalizeConfig(store.graph, config);\n\n // The four retract verbs differ only in one/many source shape and the target\n // retracted flag; the generics are fixed by the config, so hoist one call.\n const transition = (\n sources: readonly ProvenanceNodeRef<G, SourceKindsFromConfig<G, C>>[],\n retracted: boolean,\n ) =>\n runTransition<\n G,\n SourceKindsFromConfig<G, C>,\n FactKindsFromConfig<G, C>,\n JustificationKindFromConfig<G, C>\n >(store, normalized, sources, retracted);\n\n return {\n retract: (source) => transition([source], true),\n retractMany: (sources) => transition(sources, true),\n unRetract: (source) => transition([source], false),\n unRetractMany: (sources) => transition(sources, false),\n\n async holding() {\n return store.transaction(async (tx) => {\n const backend = transactionBackend(tx);\n // Same explicit lock as runTransition: the support computation reads\n // several relations, and PostgreSQL's READ COMMITTED gives each\n // statement its own snapshot — without the lock a concurrent\n // transition could commit between those reads and tear the view.\n await lockRecordedGraphWrite(backend, store.graphId);\n const snapshot = await computeSupport(\n backend,\n store.graphId,\n normalized,\n );\n return sortedReferences<G, FactKindsFromConfig<G, C>>(\n snapshot.believedFactKeys,\n );\n });\n },\n };\n}\n\nfunction assertRetractionHistoryEnabled(\n store: Readonly<{ historyEnabled: boolean; graphId: string }>,\n): void {\n if (!store.historyEnabled) {\n throw new ConfigurationError(\n \"createRetractionCapability requires a store created with { history: true }.\",\n { graphId: store.graphId },\n {\n suggestion:\n \"Use createStoreWithSchema(graph, backend, { history: true }) so retraction mutations are captured and queryable with asOfRecorded().\",\n },\n );\n }\n}\n"]}
@@ -1,20 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var chunkNUIG3BCV_cjs = require('../chunk-NUIG3BCV.cjs');
4
- var chunk5KEQ74YU_cjs = require('../chunk-5KEQ74YU.cjs');
3
+ var chunkVXAFOF6Z_cjs = require('../chunk-VXAFOF6Z.cjs');
4
+ require('../chunk-RW24SAHI.cjs');
5
+ var chunkX4PVHAZ6_cjs = require('../chunk-X4PVHAZ6.cjs');
5
6
  require('../chunk-ACSVZPK7.cjs');
6
- require('../chunk-VGDDG3XJ.cjs');
7
- require('../chunk-TEDRJXOG.cjs');
8
- require('../chunk-XGU7DZDA.cjs');
9
- require('../chunk-WWFHO375.cjs');
10
- require('../chunk-IP3CGGPA.cjs');
11
- require('../chunk-DEFQM7JU.cjs');
12
- require('../chunk-3GH67G4Z.cjs');
13
- require('../chunk-7YSP4V4R.cjs');
14
- require('../chunk-HAHNRASW.cjs');
7
+ require('../chunk-HP6LWBLB.cjs');
8
+ require('../chunk-NT6ILURI.cjs');
9
+ require('../chunk-DDCYVIVV.cjs');
10
+ require('../chunk-7M3NACL3.cjs');
11
+ require('../chunk-ZY4GXIVN.cjs');
12
+ require('../chunk-NAUA4PW5.cjs');
13
+ require('../chunk-UH2USOMG.cjs');
14
+ require('../chunk-Z5QHVL5U.cjs');
15
+ require('../chunk-ZKZAIX42.cjs');
16
+ require('../chunk-X6RDQ5NB.cjs');
17
+ require('../chunk-FJMPR3OH.cjs');
15
18
  require('../chunk-SJDMVITW.cjs');
19
+ require('../chunk-764JHTLT.cjs');
20
+ require('../chunk-HAHNRASW.cjs');
21
+ require('../chunk-N2V3HJFV.cjs');
22
+ require('../chunk-SVJ5GEXW.cjs');
23
+ require('../chunk-NMQ6C6TS.cjs');
16
24
  require('../chunk-DI74SMXS.cjs');
17
- require('../chunk-BVRDGYXQ.cjs');
25
+ require('../chunk-XRU7V7FF.cjs');
26
+ require('../chunk-SAFZ6JTI.cjs');
18
27
  require('../chunk-TDXIBCGY.cjs');
19
28
 
20
29
  // src/schema/deserializer.ts
@@ -55,7 +64,7 @@ function buildRegistryFromClosures(schema) {
55
64
  const edgeImplyingClosure = recordToMap(closures.edgeImplyingClosure);
56
65
  const nodeKinds = /* @__PURE__ */ new Map();
57
66
  const edgeKinds = /* @__PURE__ */ new Map();
58
- const registry = new chunkNUIG3BCV_cjs.KindRegistry(nodeKinds, edgeKinds, {
67
+ const registry = new chunkVXAFOF6Z_cjs.KindRegistry(nodeKinds, edgeKinds, {
59
68
  subClassAncestors,
60
69
  subClassDescendants,
61
70
  broaderClosure,
@@ -69,7 +78,7 @@ function buildRegistryFromClosures(schema) {
69
78
  edgeImplicationsClosure,
70
79
  edgeImplyingClosure
71
80
  });
72
- chunkNUIG3BCV_cjs.validateImpliesEndpointCompatibility(
81
+ chunkVXAFOF6Z_cjs.validateImpliesEndpointCompatibility(
73
82
  buildEdgeEndpointKinds(schema.edges),
74
83
  registry
75
84
  );
@@ -95,95 +104,95 @@ function simpleRecordToMap(record) {
95
104
 
96
105
  Object.defineProperty(exports, "applyDeprecatedKinds", {
97
106
  enumerable: true,
98
- get: function () { return chunkNUIG3BCV_cjs.applyDeprecatedKinds; }
107
+ get: function () { return chunkVXAFOF6Z_cjs.applyDeprecatedKinds; }
99
108
  });
100
109
  Object.defineProperty(exports, "assertSchemaCurrent", {
101
110
  enumerable: true,
102
- get: function () { return chunkNUIG3BCV_cjs.assertSchemaCurrent; }
111
+ get: function () { return chunkVXAFOF6Z_cjs.assertSchemaCurrent; }
103
112
  });
104
113
  Object.defineProperty(exports, "computeSchemaDiff", {
105
114
  enumerable: true,
106
- get: function () { return chunkNUIG3BCV_cjs.computeSchemaDiff; }
115
+ get: function () { return chunkVXAFOF6Z_cjs.computeSchemaDiff; }
107
116
  });
108
117
  Object.defineProperty(exports, "computeSchemaHash", {
109
118
  enumerable: true,
110
- get: function () { return chunkNUIG3BCV_cjs.computeSchemaHash; }
119
+ get: function () { return chunkVXAFOF6Z_cjs.computeSchemaHash; }
111
120
  });
112
121
  Object.defineProperty(exports, "deserializeWherePredicate", {
113
122
  enumerable: true,
114
- get: function () { return chunkNUIG3BCV_cjs.deserializeWherePredicate; }
123
+ get: function () { return chunkVXAFOF6Z_cjs.deserializeWherePredicate; }
115
124
  });
116
125
  Object.defineProperty(exports, "ensureSchema", {
117
126
  enumerable: true,
118
- get: function () { return chunkNUIG3BCV_cjs.ensureSchema; }
127
+ get: function () { return chunkVXAFOF6Z_cjs.ensureSchema; }
119
128
  });
120
129
  Object.defineProperty(exports, "getActiveSchema", {
121
130
  enumerable: true,
122
- get: function () { return chunkNUIG3BCV_cjs.getActiveSchema; }
131
+ get: function () { return chunkVXAFOF6Z_cjs.getActiveSchema; }
123
132
  });
124
133
  Object.defineProperty(exports, "getMigrationActions", {
125
134
  enumerable: true,
126
- get: function () { return chunkNUIG3BCV_cjs.getMigrationActions; }
135
+ get: function () { return chunkVXAFOF6Z_cjs.getMigrationActions; }
127
136
  });
128
137
  Object.defineProperty(exports, "getSchemaChanges", {
129
138
  enumerable: true,
130
- get: function () { return chunkNUIG3BCV_cjs.getSchemaChanges; }
139
+ get: function () { return chunkVXAFOF6Z_cjs.getSchemaChanges; }
131
140
  });
132
141
  Object.defineProperty(exports, "initializeSchema", {
133
142
  enumerable: true,
134
- get: function () { return chunkNUIG3BCV_cjs.initializeSchema; }
143
+ get: function () { return chunkVXAFOF6Z_cjs.initializeSchema; }
135
144
  });
136
145
  Object.defineProperty(exports, "isBackwardsCompatible", {
137
146
  enumerable: true,
138
- get: function () { return chunkNUIG3BCV_cjs.isBackwardsCompatible; }
147
+ get: function () { return chunkVXAFOF6Z_cjs.isBackwardsCompatible; }
139
148
  });
140
149
  Object.defineProperty(exports, "isSchemaInitialized", {
141
150
  enumerable: true,
142
- get: function () { return chunkNUIG3BCV_cjs.isSchemaInitialized; }
151
+ get: function () { return chunkVXAFOF6Z_cjs.isSchemaInitialized; }
143
152
  });
144
153
  Object.defineProperty(exports, "loadActiveSchemaWithBootstrap", {
145
154
  enumerable: true,
146
- get: function () { return chunkNUIG3BCV_cjs.loadActiveSchemaWithBootstrap; }
155
+ get: function () { return chunkVXAFOF6Z_cjs.loadActiveSchemaWithBootstrap; }
147
156
  });
148
157
  Object.defineProperty(exports, "loadAndMergeGraphExtensionDocument", {
149
158
  enumerable: true,
150
- get: function () { return chunkNUIG3BCV_cjs.loadAndMergeGraphExtensionDocument; }
159
+ get: function () { return chunkVXAFOF6Z_cjs.loadAndMergeGraphExtensionDocument; }
151
160
  });
152
161
  Object.defineProperty(exports, "migrateSchema", {
153
162
  enumerable: true,
154
- get: function () { return chunkNUIG3BCV_cjs.migrateSchema; }
163
+ get: function () { return chunkVXAFOF6Z_cjs.migrateSchema; }
155
164
  });
156
165
  Object.defineProperty(exports, "parseSerializedSchema", {
157
166
  enumerable: true,
158
- get: function () { return chunkNUIG3BCV_cjs.parseSerializedSchema; }
167
+ get: function () { return chunkVXAFOF6Z_cjs.parseSerializedSchema; }
159
168
  });
160
169
  Object.defineProperty(exports, "rollbackSchema", {
161
170
  enumerable: true,
162
- get: function () { return chunkNUIG3BCV_cjs.rollbackSchema; }
171
+ get: function () { return chunkVXAFOF6Z_cjs.rollbackSchema; }
163
172
  });
164
173
  Object.defineProperty(exports, "serializeSchema", {
165
174
  enumerable: true,
166
- get: function () { return chunkNUIG3BCV_cjs.serializeSchema; }
175
+ get: function () { return chunkVXAFOF6Z_cjs.serializeSchema; }
167
176
  });
168
177
  Object.defineProperty(exports, "createValidationError", {
169
178
  enumerable: true,
170
- get: function () { return chunk5KEQ74YU_cjs.createValidationError; }
179
+ get: function () { return chunkX4PVHAZ6_cjs.createValidationError; }
171
180
  });
172
181
  Object.defineProperty(exports, "validateEdgeProps", {
173
182
  enumerable: true,
174
- get: function () { return chunk5KEQ74YU_cjs.validateEdgeProps; }
183
+ get: function () { return chunkX4PVHAZ6_cjs.validateEdgeProps; }
175
184
  });
176
185
  Object.defineProperty(exports, "validateNodeProps", {
177
186
  enumerable: true,
178
- get: function () { return chunk5KEQ74YU_cjs.validateNodeProps; }
187
+ get: function () { return chunkX4PVHAZ6_cjs.validateNodeProps; }
179
188
  });
180
189
  Object.defineProperty(exports, "validateProps", {
181
190
  enumerable: true,
182
- get: function () { return chunk5KEQ74YU_cjs.validateProps; }
191
+ get: function () { return chunkX4PVHAZ6_cjs.validateProps; }
183
192
  });
184
193
  Object.defineProperty(exports, "wrapZodError", {
185
194
  enumerable: true,
186
- get: function () { return chunk5KEQ74YU_cjs.wrapZodError; }
195
+ get: function () { return chunkX4PVHAZ6_cjs.wrapZodError; }
187
196
  });
188
197
  exports.deserializeSchema = deserializeSchema;
189
198
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/deserializer.ts"],"names":["KindRegistry","validateImpliesEndpointCompatibility"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiFO,SAAS,kBACd,MAAA,EACoB;AACpB,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,SAAS,SAAS,CAAA;AAE3D,EAAA,OAAO;AAAA,IACL,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,aAAa,MAAA,CAAO,WAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KAAS,MAAA,CAAO,MAAM,IAAI,CAAA;AAAA,IACpC,cAAc,MAAM,SAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KAAS,MAAA,CAAO,MAAM,IAAI,CAAA;AAAA,IACpC,cAAc,MAAM,SAAA;AAAA,IAEpB,aAAa,CAAC,IAAA,KAAS,MAAA,CAAO,QAAA,CAAS,UAAU,IAAI,CAAA;AAAA,IACrD,kBAAkB,MAAM,aAAA;AAAA,IAExB,YAAA,EAAc,MAAM,MAAA,CAAO,QAAA,CAAS,SAAA;AAAA,IACpC,WAAA,EAAa,MAAM,MAAA,CAAO,QAAA,CAAS,QAAA;AAAA,IAEnC,WAAA,EAAa,MAAM,MAAA,CAAO,QAAA;AAAA,IAC1B,QAAQ,MAAM,MAAA;AAAA,IAEd,aAAA,EAAe,MAAM,yBAAA,CAA0B,MAAM;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,aAAA;AAAA,IACA,aAAA;AAAA,IACA,cAAA;AAAA,IACA,YAAA;AAAA,IACA,uBAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAAC,sDAAA;AAAA,IACE,sBAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACnC;AAAA,GACF;AAEA,EAAA,OAAO,QAAA;AACT;AASA,SAAS,uBACP,KAAA,EACwC;AACxC,EAAA,MAAM,MAAA,uBAAa,GAAA,EAA+B;AAClD,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,GAAG,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC/C,IAAA,MAAA,CAAO,GAAA,CAAI,MAAM,EAAE,IAAA,EAAM,IAAI,SAAA,EAAW,EAAA,EAAI,GAAA,CAAI,OAAA,EAAS,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,MAAA;AACT;AAKA,SAAS,YACP,MAAA,EAC0C;AAC1C,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAyB;AAC5C,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,MAAM,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AAClD,IAAA,MAAA,CAAO,GAAA,CAAI,GAAA,EAAK,IAAI,GAAA,CAAI,MAAM,CAAC,CAAA;AAAA,EACjC;AACA,EAAA,OAAO,MAAA;AACT;AAKA,SAAS,kBACP,MAAA,EAC6B;AAC7B,EAAA,OAAO,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAC,CAAA;AACvC","file":"index.cjs","sourcesContent":["/**\n * Schema deserializer for loading stored schemas.\n *\n * Reconstructs runtime objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { KindRegistry } from \"../registry/kind-registry\";\nimport {\n type EdgeEndpointKinds,\n validateImpliesEndpointCompatibility,\n} from \"../registry/validate-implies\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a KindRegistry from the closures */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n getNode: (name) => schema.nodes[name],\n getNodeNames: () => nodeNames,\n\n getEdge: (name) => schema.edges[name],\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) => schema.ontology.metaEdges[name],\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromClosures(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized closures.\n *\n * This allows query execution without recomputing closures.\n */\nfunction buildRegistryFromClosures(schema: SerializedSchema): KindRegistry {\n const { closures } = schema.ontology;\n\n // Convert Record<string, string[]> back to Map<string, Set<string>>\n const subClassAncestors = recordToMap(closures.subClassAncestors);\n const subClassDescendants = recordToMap(closures.subClassDescendants);\n const broaderClosure = recordToMap(closures.broaderClosure);\n const narrowerClosure = recordToMap(closures.narrowerClosure);\n const equivalenceSets = recordToMap(closures.equivalenceSets);\n const partOfClosure = recordToMap(closures.partOfClosure);\n const hasPartClosure = recordToMap(closures.hasPartClosure);\n const iriToKind = simpleRecordToMap(closures.iriToKind);\n const disjointPairs = new Set(closures.disjointPairs);\n const edgeInverses = simpleRecordToMap(closures.edgeInverses);\n const edgeImplicationsClosure = recordToMap(closures.edgeImplicationsClosure);\n const edgeImplyingClosure = recordToMap(closures.edgeImplyingClosure);\n\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map();\n const edgeKinds = new Map();\n\n const registry = new KindRegistry(nodeKinds, edgeKinds, {\n subClassAncestors,\n subClassDescendants,\n broaderClosure,\n narrowerClosure,\n equivalenceSets,\n iriToKind,\n disjointPairs,\n partOfClosure,\n hasPartClosure,\n edgeInverses,\n edgeImplicationsClosure,\n edgeImplyingClosure,\n });\n\n validateImpliesEndpointCompatibility(\n buildEdgeEndpointKinds(schema.edges),\n registry,\n );\n\n return registry;\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n result.set(kind, { from: def.fromKinds, to: def.toKinds });\n }\n return result;\n}\n\n/**\n * Converts Record<string, string[]> to Map<string, Set<string>>.\n */\nfunction recordToMap(\n record: Record<string, readonly string[]>,\n): ReadonlyMap<string, ReadonlySet<string>> {\n const result = new Map<string, Set<string>>();\n for (const [key, values] of Object.entries(record)) {\n result.set(key, new Set(values));\n }\n return result;\n}\n\n/**\n * Converts Record<string, string> to Map<string, string>.\n */\nfunction simpleRecordToMap(\n record: Record<string, string>,\n): ReadonlyMap<string, string> {\n return new Map(Object.entries(record));\n}\n"]}
1
+ {"version":3,"sources":["../../src/schema/deserializer.ts"],"names":["KindRegistry","validateImpliesEndpointCompatibility"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFO,SAAS,kBACd,MAAA,EACoB;AACpB,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,SAAS,SAAS,CAAA;AAE3D,EAAA,OAAO;AAAA,IACL,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,aAAa,MAAA,CAAO,WAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KAAS,MAAA,CAAO,MAAM,IAAI,CAAA;AAAA,IACpC,cAAc,MAAM,SAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KAAS,MAAA,CAAO,MAAM,IAAI,CAAA;AAAA,IACpC,cAAc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,SAAS,kBACP,MAAA,EAC6B;AAC7B,EAAA,OAAO,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAC,CAAA;AACvC","file":"index.cjs","sourcesContent":["/**\n * Schema deserializer for loading stored schemas.\n *\n * Reconstructs runtime objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { KindRegistry } from \"../registry/kind-registry\";\nimport {\n type EdgeEndpointKinds,\n validateImpliesEndpointCompatibility,\n} from \"../registry/validate-implies\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a KindRegistry from the closures */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n getNode: (name) => schema.nodes[name],\n getNodeNames: () => nodeNames,\n\n getEdge: (name) => schema.edges[name],\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) => schema.ontology.metaEdges[name],\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromClosures(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized closures.\n *\n * This allows query execution without recomputing closures.\n */\nfunction buildRegistryFromClosures(schema: SerializedSchema): KindRegistry {\n const { closures } = schema.ontology;\n\n // Convert Record<string, string[]> back to Map<string, Set<string>>\n const subClassAncestors = recordToMap(closures.subClassAncestors);\n const subClassDescendants = recordToMap(closures.subClassDescendants);\n const broaderClosure = recordToMap(closures.broaderClosure);\n const narrowerClosure = recordToMap(closures.narrowerClosure);\n const equivalenceSets = recordToMap(closures.equivalenceSets);\n const partOfClosure = recordToMap(closures.partOfClosure);\n const hasPartClosure = recordToMap(closures.hasPartClosure);\n const iriToKind = simpleRecordToMap(closures.iriToKind);\n const disjointPairs = new Set(closures.disjointPairs);\n const edgeInverses = simpleRecordToMap(closures.edgeInverses);\n const edgeImplicationsClosure = recordToMap(closures.edgeImplicationsClosure);\n const edgeImplyingClosure = recordToMap(closures.edgeImplyingClosure);\n\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map();\n const edgeKinds = new Map();\n\n const registry = new KindRegistry(nodeKinds, edgeKinds, {\n subClassAncestors,\n subClassDescendants,\n broaderClosure,\n narrowerClosure,\n equivalenceSets,\n iriToKind,\n disjointPairs,\n partOfClosure,\n hasPartClosure,\n edgeInverses,\n edgeImplicationsClosure,\n edgeImplyingClosure,\n });\n\n validateImpliesEndpointCompatibility(\n buildEdgeEndpointKinds(schema.edges),\n registry,\n );\n\n return registry;\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n result.set(kind, { from: def.fromKinds, to: def.toKinds });\n }\n return result;\n}\n\n/**\n * Converts Record<string, string[]> to Map<string, Set<string>>.\n */\nfunction recordToMap(\n record: Record<string, readonly string[]>,\n): ReadonlyMap<string, ReadonlySet<string>> {\n const result = new Map<string, Set<string>>();\n for (const [key, values] of Object.entries(record)) {\n result.set(key, new Set(values));\n }\n return result;\n}\n\n/**\n * Converts Record<string, string> to Map<string, string>.\n */\nfunction simpleRecordToMap(\n record: Record<string, string>,\n): ReadonlyMap<string, string> {\n return new Map(Object.entries(record));\n}\n"]}