@nicia-ai/typegraph 0.32.0 → 0.34.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 (264) hide show
  1. package/README.md +51 -0
  2. package/dist/backend/postgres/index.cjs +36 -19
  3. package/dist/backend/postgres/index.d.cts +6 -6
  4. package/dist/backend/postgres/index.d.ts +6 -6
  5. package/dist/backend/postgres/index.js +14 -9
  6. package/dist/backend/postgres/pglite.cjs +18 -13
  7. package/dist/backend/postgres/pglite.cjs.map +1 -1
  8. package/dist/backend/postgres/pglite.d.cts +3 -3
  9. package/dist/backend/postgres/pglite.d.ts +3 -3
  10. package/dist/backend/postgres/pglite.js +14 -9
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +34 -17
  13. package/dist/backend/sqlite/index.d.cts +7 -7
  14. package/dist/backend/sqlite/index.d.ts +7 -7
  15. package/dist/backend/sqlite/index.js +13 -8
  16. package/dist/backend/sqlite/libsql.cjs +19 -14
  17. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  18. package/dist/backend/sqlite/libsql.d.cts +12 -5
  19. package/dist/backend/sqlite/libsql.d.ts +12 -5
  20. package/dist/backend/sqlite/libsql.js +15 -10
  21. package/dist/backend/sqlite/libsql.js.map +1 -1
  22. package/dist/backend/sqlite/local.cjs +19 -14
  23. package/dist/backend/sqlite/local.cjs.map +1 -1
  24. package/dist/backend/sqlite/local.d.cts +3 -3
  25. package/dist/backend/sqlite/local.d.ts +3 -3
  26. package/dist/backend/sqlite/local.js +14 -9
  27. package/dist/backend/sqlite/local.js.map +1 -1
  28. package/dist/chunk-2EBMPJBO.js +16 -0
  29. package/dist/chunk-2EBMPJBO.js.map +1 -0
  30. package/dist/{chunk-CFNT3ITG.cjs → chunk-2JXB3NYJ.cjs} +15 -35
  31. package/dist/chunk-2JXB3NYJ.cjs.map +1 -0
  32. package/dist/chunk-2MRAX3UE.js +105 -0
  33. package/dist/chunk-2MRAX3UE.js.map +1 -0
  34. package/dist/{chunk-2LAT5BIK.cjs → chunk-3BRVBQQD.cjs} +2328 -3131
  35. package/dist/chunk-3BRVBQQD.cjs.map +1 -0
  36. package/dist/chunk-3E7SNSIA.cjs +55 -0
  37. package/dist/chunk-3E7SNSIA.cjs.map +1 -0
  38. package/dist/{chunk-FDN43KXV.cjs → chunk-3Z6TW3CT.cjs} +20 -19
  39. package/dist/chunk-3Z6TW3CT.cjs.map +1 -0
  40. package/dist/{chunk-IJORSAC3.js → chunk-4DIBPQNJ.js} +6 -4
  41. package/dist/chunk-4DIBPQNJ.js.map +1 -0
  42. package/dist/chunk-4S2FXGBJ.js +9 -0
  43. package/dist/chunk-4S2FXGBJ.js.map +1 -0
  44. package/dist/chunk-5IQIX7LU.cjs +2070 -0
  45. package/dist/chunk-5IQIX7LU.cjs.map +1 -0
  46. package/dist/{chunk-CWFPJ3RC.js → chunk-6GNSY7AV.js} +3 -3
  47. package/dist/{chunk-CWFPJ3RC.js.map → chunk-6GNSY7AV.js.map} +1 -1
  48. package/dist/{chunk-LAZGHOZW.cjs → chunk-6HVOHZHS.cjs} +184 -117
  49. package/dist/chunk-6HVOHZHS.cjs.map +1 -0
  50. package/dist/chunk-6SCVW4AS.js +20 -0
  51. package/dist/chunk-6SCVW4AS.js.map +1 -0
  52. package/dist/chunk-A7SZZFAG.js +2010 -0
  53. package/dist/chunk-A7SZZFAG.js.map +1 -0
  54. package/dist/chunk-ACSVZPK7.cjs +21 -0
  55. package/dist/chunk-ACSVZPK7.cjs.map +1 -0
  56. package/dist/{chunk-MXE2U3EX.js → chunk-BVTWD66D.js} +4 -115
  57. package/dist/chunk-BVTWD66D.js.map +1 -0
  58. package/dist/{chunk-W4ZX2GCP.js → chunk-CHXTTSC6.js} +5 -39
  59. package/dist/chunk-CHXTTSC6.js.map +1 -0
  60. package/dist/{chunk-XQFAJVYW.js → chunk-CYX2JTDG.js} +124 -5
  61. package/dist/chunk-CYX2JTDG.js.map +1 -0
  62. package/dist/{chunk-PRMKPFN5.js → chunk-DEQFL35G.js} +4 -3
  63. package/dist/chunk-DEQFL35G.js.map +1 -0
  64. package/dist/chunk-DI74SMXS.cjs +29 -0
  65. package/dist/chunk-DI74SMXS.cjs.map +1 -0
  66. package/dist/{chunk-WWVV44DY.cjs → chunk-G6SOJEDI.cjs} +11 -11
  67. package/dist/{chunk-WWVV44DY.cjs.map → chunk-G6SOJEDI.cjs.map} +1 -1
  68. package/dist/{chunk-LM2IC4ZJ.cjs → chunk-GQANNXXT.cjs} +15 -14
  69. package/dist/chunk-GQANNXXT.cjs.map +1 -0
  70. package/dist/chunk-GZCNZ7QW.js +24 -0
  71. package/dist/chunk-GZCNZ7QW.js.map +1 -0
  72. package/dist/{chunk-KTIEB7VH.cjs → chunk-HK5SATYM.cjs} +35 -58
  73. package/dist/chunk-HK5SATYM.cjs.map +1 -0
  74. package/dist/chunk-HMFK4BXR.cjs +12 -0
  75. package/dist/{chunk-6ZR4QC3O.cjs.map → chunk-HMFK4BXR.cjs.map} +1 -1
  76. package/dist/chunk-ITE4IXAK.js +25 -0
  77. package/dist/chunk-ITE4IXAK.js.map +1 -0
  78. package/dist/chunk-JJRCLAUN.cjs +155 -0
  79. package/dist/chunk-JJRCLAUN.cjs.map +1 -0
  80. package/dist/{chunk-ZFWNO3GE.cjs → chunk-JQGIPGVL.cjs} +66 -2
  81. package/dist/chunk-JQGIPGVL.cjs.map +1 -0
  82. package/dist/{chunk-2BVHPOIG.js → chunk-K2TGS3EN.js} +105 -38
  83. package/dist/chunk-K2TGS3EN.js.map +1 -0
  84. package/dist/chunk-K34OPSJK.js +29 -0
  85. package/dist/chunk-K34OPSJK.js.map +1 -0
  86. package/dist/{chunk-YW7GHMF4.cjs → chunk-KGC4LY5T.cjs} +18 -17
  87. package/dist/chunk-KGC4LY5T.cjs.map +1 -0
  88. package/dist/{chunk-SB65GJNY.cjs → chunk-KNHYNQQ3.cjs} +111 -72
  89. package/dist/chunk-KNHYNQQ3.cjs.map +1 -0
  90. package/dist/{chunk-C4C4Q7A6.js → chunk-KUTNI6SI.js} +6 -21
  91. package/dist/chunk-KUTNI6SI.js.map +1 -0
  92. package/dist/{chunk-NDM5PXEH.js → chunk-LANHCOXB.js} +44 -11
  93. package/dist/chunk-LANHCOXB.js.map +1 -0
  94. package/dist/chunk-N6WTUSBV.cjs +23 -0
  95. package/dist/chunk-N6WTUSBV.cjs.map +1 -0
  96. package/dist/{chunk-73KASJGO.cjs → chunk-NAUA4PW5.cjs} +4 -28
  97. package/dist/chunk-NAUA4PW5.cjs.map +1 -0
  98. package/dist/chunk-QV245VMN.js +145 -0
  99. package/dist/chunk-QV245VMN.js.map +1 -0
  100. package/dist/{chunk-CEF2QOTO.js → chunk-RBV7YCQD.js} +4 -3
  101. package/dist/chunk-RBV7YCQD.js.map +1 -0
  102. package/dist/chunk-RHZWOJVA.cjs +109 -0
  103. package/dist/chunk-RHZWOJVA.cjs.map +1 -0
  104. package/dist/{chunk-6RMLO5O4.cjs → chunk-RRKQAKD6.cjs} +13 -11
  105. package/dist/chunk-RRKQAKD6.cjs.map +1 -0
  106. package/dist/{chunk-TUA3MEJJ.js → chunk-RY2VIWAM.js} +612 -564
  107. package/dist/chunk-RY2VIWAM.js.map +1 -0
  108. package/dist/{chunk-PIHXFF73.js → chunk-SHLY4MCM.js} +3 -3
  109. package/dist/{chunk-PIHXFF73.js.map → chunk-SHLY4MCM.js.map} +1 -1
  110. package/dist/{chunk-HFBRAOF7.js → chunk-T2DWPQNE.js} +103 -64
  111. package/dist/chunk-T2DWPQNE.js.map +1 -0
  112. package/dist/{chunk-WYTUF3QO.js → chunk-T46GR2VY.js} +3 -3
  113. package/dist/{chunk-WYTUF3QO.js.map → chunk-T46GR2VY.js.map} +1 -1
  114. package/dist/{chunk-EEYV6UOE.cjs → chunk-T6SPUYLX.cjs} +5 -43
  115. package/dist/chunk-T6SPUYLX.cjs.map +1 -0
  116. package/dist/{chunk-3QRBXYT5.cjs → chunk-TGJE22RM.cjs} +6 -6
  117. package/dist/{chunk-3QRBXYT5.cjs.map → chunk-TGJE22RM.cjs.map} +1 -1
  118. package/dist/{chunk-YL4F3CMD.cjs → chunk-TOTPVGOG.cjs} +105 -72
  119. package/dist/chunk-TOTPVGOG.cjs.map +1 -0
  120. package/dist/{chunk-3HQDMOBK.cjs → chunk-UJLOZYKT.cjs} +680 -636
  121. package/dist/chunk-UJLOZYKT.cjs.map +1 -0
  122. package/dist/chunk-UNNPKQUG.cjs +1390 -0
  123. package/dist/chunk-UNNPKQUG.cjs.map +1 -0
  124. package/dist/chunk-UR7W5YQK.js +18 -0
  125. package/dist/chunk-UR7W5YQK.js.map +1 -0
  126. package/dist/chunk-V3QNTB7Z.js +1351 -0
  127. package/dist/chunk-V3QNTB7Z.js.map +1 -0
  128. package/dist/{chunk-XKNAK27R.js → chunk-VCGO4V26.js} +4 -3
  129. package/dist/chunk-VCGO4V26.js.map +1 -0
  130. package/dist/{chunk-YQGLVWB2.cjs → chunk-WL2SG7ZV.cjs} +6 -122
  131. package/dist/chunk-WL2SG7ZV.cjs.map +1 -0
  132. package/dist/{chunk-WNORITK6.js → chunk-WLRIWYHQ.js} +2041 -2834
  133. package/dist/chunk-WLRIWYHQ.js.map +1 -0
  134. package/dist/{chunk-JKRKIEVA.cjs → chunk-WVC2Q2FD.cjs} +128 -6
  135. package/dist/chunk-WVC2Q2FD.cjs.map +1 -0
  136. package/dist/chunk-XLUNB2TZ.js +53 -0
  137. package/dist/chunk-XLUNB2TZ.js.map +1 -0
  138. package/dist/chunk-XXVEULWX.js +39 -0
  139. package/dist/chunk-XXVEULWX.js.map +1 -0
  140. package/dist/chunk-YAZE7QZR.cjs +32 -0
  141. package/dist/chunk-YAZE7QZR.cjs.map +1 -0
  142. package/dist/chunk-YC6PWTHY.cjs +44 -0
  143. package/dist/chunk-YC6PWTHY.cjs.map +1 -0
  144. package/dist/chunk-Z5HBYM7U.cjs +11 -0
  145. package/dist/chunk-Z5HBYM7U.cjs.map +1 -0
  146. package/dist/{chunk-454I6GDF.js → chunk-Z5XBMDXU.js} +63 -3
  147. package/dist/chunk-Z5XBMDXU.js.map +1 -0
  148. package/dist/{chunk-CAMMC3E4.cjs → chunk-ZP5WHI4C.cjs} +109 -81
  149. package/dist/chunk-ZP5WHI4C.cjs.map +1 -0
  150. package/dist/{chunk-YCV72E6L.js → chunk-ZURTTSCM.js} +4 -25
  151. package/dist/chunk-ZURTTSCM.js.map +1 -0
  152. package/dist/{chunk-7WW3WL6E.js → chunk-ZV5N4DBG.js} +49 -21
  153. package/dist/chunk-ZV5N4DBG.js.map +1 -0
  154. package/dist/chunk-ZY4GXIVN.cjs +32 -0
  155. package/dist/chunk-ZY4GXIVN.cjs.map +1 -0
  156. package/dist/{ddl-C8e8zDAE.d.ts → ddl-BrmPg61z.d.ts} +3 -3
  157. package/dist/{ddl-CwyG4HoQ.d.cts → ddl-j1-sH6lE.d.cts} +3 -3
  158. package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
  159. package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
  160. package/dist/graph-extension/index.cjs +18 -17
  161. package/dist/graph-extension/index.d.cts +4 -4
  162. package/dist/graph-extension/index.d.ts +4 -4
  163. package/dist/graph-extension/index.js +3 -2
  164. package/dist/graph-merge/index.cjs +295 -146
  165. package/dist/graph-merge/index.cjs.map +1 -1
  166. package/dist/graph-merge/index.d.cts +6 -6
  167. package/dist/graph-merge/index.d.ts +6 -6
  168. package/dist/graph-merge/index.js +173 -24
  169. package/dist/graph-merge/index.js.map +1 -1
  170. package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
  171. package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
  172. package/dist/index.cjs +206 -172
  173. package/dist/index.cjs.map +1 -1
  174. package/dist/index.d.cts +25 -55
  175. package/dist/index.d.ts +25 -55
  176. package/dist/index.js +32 -22
  177. package/dist/index.js.map +1 -1
  178. package/dist/indexes/index.cjs +28 -25
  179. package/dist/indexes/index.d.cts +5 -5
  180. package/dist/indexes/index.d.ts +5 -5
  181. package/dist/indexes/index.js +10 -7
  182. package/dist/interchange/index.cjs +25 -16
  183. package/dist/interchange/index.d.cts +5 -5
  184. package/dist/interchange/index.d.ts +5 -5
  185. package/dist/interchange/index.js +12 -3
  186. package/dist/{manager-8htmuGr-.d.ts → manager-BZUeN_BU.d.ts} +2 -2
  187. package/dist/{manager-aVgxbGt-.d.cts → manager-ms9cKdc6.d.cts} +2 -2
  188. package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
  189. package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
  190. package/dist/{postgres-Dhom7iiX.d.ts → postgres-BhpxGMC5.d.cts} +2651 -596
  191. package/dist/{postgres-jgXmD45C.d.cts → postgres-CWHLwNl1.d.ts} +2651 -596
  192. package/dist/profiler/index.cjs +5 -4
  193. package/dist/profiler/index.cjs.map +1 -1
  194. package/dist/profiler/index.d.cts +7 -7
  195. package/dist/profiler/index.d.ts +7 -7
  196. package/dist/profiler/index.js +3 -2
  197. package/dist/profiler/index.js.map +1 -1
  198. package/dist/provenance/index.cjs +591 -0
  199. package/dist/provenance/index.cjs.map +1 -0
  200. package/dist/provenance/index.d.cts +73 -0
  201. package/dist/provenance/index.d.ts +73 -0
  202. package/dist/provenance/index.js +589 -0
  203. package/dist/provenance/index.js.map +1 -0
  204. package/dist/schema/index.cjs +37 -32
  205. package/dist/schema/index.cjs.map +1 -1
  206. package/dist/schema/index.d.cts +7 -7
  207. package/dist/schema/index.d.ts +7 -7
  208. package/dist/schema/index.js +14 -9
  209. package/dist/schema/index.js.map +1 -1
  210. package/dist/{sqlite-DcQ_BCUW.d.cts → sqlite-CGu5SLsw.d.ts} +2726 -455
  211. package/dist/{sqlite-BfLsCEqO.d.ts → sqlite-XrDxNaa7.d.cts} +2726 -455
  212. package/dist/{store-view-pBOUrQte.d.ts → store-view-BlgnhEYf.d.ts} +467 -131
  213. package/dist/{store-view-lTcb_cnp.d.cts → store-view-D09po4H6.d.cts} +467 -131
  214. package/dist/{types-DGDiXAYc.d.ts → types-B1TbZJYS.d.ts} +2 -2
  215. package/dist/{types-Dk8r09KY.d.ts → types-D1Sqeyxy.d.ts} +161 -26
  216. package/dist/{types-5RQwzWXx.d.cts → types-DiE1AO7p.d.cts} +2 -2
  217. package/dist/{types-Dvmn-eal.d.cts → types-DkNnF-7K.d.cts} +161 -26
  218. package/dist/{where-Cx_glEEB.d.cts → where-DKjuofPr.d.cts} +2 -2
  219. package/dist/{where-CHZFELX0.d.ts → where-DrUIIWHb.d.ts} +2 -2
  220. package/package.json +8 -2
  221. package/dist/chunk-2BVHPOIG.js.map +0 -1
  222. package/dist/chunk-2LAT5BIK.cjs.map +0 -1
  223. package/dist/chunk-2YMGNYXY.js +0 -40
  224. package/dist/chunk-2YMGNYXY.js.map +0 -1
  225. package/dist/chunk-3HQDMOBK.cjs.map +0 -1
  226. package/dist/chunk-454I6GDF.js.map +0 -1
  227. package/dist/chunk-6G35I3VW.cjs +0 -40
  228. package/dist/chunk-6G35I3VW.cjs.map +0 -1
  229. package/dist/chunk-6RMLO5O4.cjs.map +0 -1
  230. package/dist/chunk-6ZR4QC3O.cjs +0 -12
  231. package/dist/chunk-73KASJGO.cjs.map +0 -1
  232. package/dist/chunk-7WW3WL6E.js.map +0 -1
  233. package/dist/chunk-C4C4Q7A6.js.map +0 -1
  234. package/dist/chunk-CAMMC3E4.cjs.map +0 -1
  235. package/dist/chunk-CEF2QOTO.js.map +0 -1
  236. package/dist/chunk-CFNT3ITG.cjs.map +0 -1
  237. package/dist/chunk-EEYV6UOE.cjs.map +0 -1
  238. package/dist/chunk-FDN43KXV.cjs.map +0 -1
  239. package/dist/chunk-HFBRAOF7.js.map +0 -1
  240. package/dist/chunk-IJORSAC3.js.map +0 -1
  241. package/dist/chunk-JKRKIEVA.cjs.map +0 -1
  242. package/dist/chunk-KTIEB7VH.cjs.map +0 -1
  243. package/dist/chunk-LAZGHOZW.cjs.map +0 -1
  244. package/dist/chunk-LM2IC4ZJ.cjs.map +0 -1
  245. package/dist/chunk-M6OC455F.js +0 -65
  246. package/dist/chunk-M6OC455F.js.map +0 -1
  247. package/dist/chunk-MXE2U3EX.js.map +0 -1
  248. package/dist/chunk-NDM5PXEH.js.map +0 -1
  249. package/dist/chunk-PRMKPFN5.js.map +0 -1
  250. package/dist/chunk-RP7YITHX.cjs +0 -70
  251. package/dist/chunk-RP7YITHX.cjs.map +0 -1
  252. package/dist/chunk-SAJSMR2B.js +0 -35
  253. package/dist/chunk-SAJSMR2B.js.map +0 -1
  254. package/dist/chunk-SB65GJNY.cjs.map +0 -1
  255. package/dist/chunk-TUA3MEJJ.js.map +0 -1
  256. package/dist/chunk-W4ZX2GCP.js.map +0 -1
  257. package/dist/chunk-WNORITK6.js.map +0 -1
  258. package/dist/chunk-XKNAK27R.js.map +0 -1
  259. package/dist/chunk-XQFAJVYW.js.map +0 -1
  260. package/dist/chunk-YCV72E6L.js.map +0 -1
  261. package/dist/chunk-YL4F3CMD.cjs.map +0 -1
  262. package/dist/chunk-YQGLVWB2.cjs.map +0 -1
  263. package/dist/chunk-YW7GHMF4.cjs.map +0 -1
  264. package/dist/chunk-ZFWNO3GE.cjs.map +0 -1
@@ -0,0 +1,591 @@
1
+ 'use strict';
2
+
3
+ var chunkZ5HBYM7U_cjs = require('../chunk-Z5HBYM7U.cjs');
4
+ var chunk5IQIX7LU_cjs = require('../chunk-5IQIX7LU.cjs');
5
+ var chunkUNNPKQUG_cjs = require('../chunk-UNNPKQUG.cjs');
6
+ var chunkYC6PWTHY_cjs = require('../chunk-YC6PWTHY.cjs');
7
+ require('../chunk-RHZWOJVA.cjs');
8
+ require('../chunk-YAZE7QZR.cjs');
9
+ require('../chunk-NAUA4PW5.cjs');
10
+ require('../chunk-JQGIPGVL.cjs');
11
+ require('../chunk-3E7SNSIA.cjs');
12
+ var chunkDI74SMXS_cjs = require('../chunk-DI74SMXS.cjs');
13
+ var chunkJIEJCTDS_cjs = require('../chunk-JIEJCTDS.cjs');
14
+ require('../chunk-FLRCVI2G.cjs');
15
+
16
+ // src/provenance/index.ts
17
+ var DEFAULT_RETRACTED_FIELD = "retracted";
18
+ var KEY_SEPARATOR = "\0";
19
+ function refKey(ref) {
20
+ return `${ref.kind}${KEY_SEPARATOR}${ref.id}`;
21
+ }
22
+ function rowKey(row) {
23
+ return refKey({ kind: row.kind, id: row.id });
24
+ }
25
+ function edgeFromKey(edge) {
26
+ return refKey({ kind: edge.from_kind, id: edge.from_id });
27
+ }
28
+ function edgeToKey(edge) {
29
+ return refKey({ kind: edge.to_kind, id: edge.to_id });
30
+ }
31
+ function keyToRef(key) {
32
+ const separatorIndex = key.indexOf(KEY_SEPARATOR);
33
+ if (separatorIndex === -1) {
34
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
35
+ "Invalid provenance identity key.",
36
+ { key },
37
+ {
38
+ suggestion: "Report this TypeGraph provenance bug with the graph roles that produced the key."
39
+ }
40
+ );
41
+ }
42
+ const kind = key.slice(0, separatorIndex);
43
+ const id = key.slice(separatorIndex + KEY_SEPARATOR.length);
44
+ return { kind, id };
45
+ }
46
+ function sortedReferences(keys) {
47
+ return [...keys].toSorted((left, right) => chunkZ5HBYM7U_cjs.compareStrings(left, right)).map((key) => keyToRef(key));
48
+ }
49
+ function parseNodeProps(row) {
50
+ const parsed = JSON.parse(row.props);
51
+ if (!chunkDI74SMXS_cjs.isPlainObject(parsed)) {
52
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
53
+ `Node ${row.kind}/${row.id} props are not an object.`,
54
+ { kind: row.kind, id: row.id }
55
+ );
56
+ }
57
+ return parsed;
58
+ }
59
+ function sourceRetractedState(row, retractedField) {
60
+ const props = parseNodeProps(row);
61
+ const value = props[retractedField];
62
+ if (value === void 0) return "available";
63
+ if (typeof value !== "boolean") {
64
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
65
+ `Provenance source field "${retractedField}" must contain a boolean value.`,
66
+ { kind: row.kind, id: row.id, field: retractedField },
67
+ {
68
+ suggestion: "Use a source node schema with a boolean retracted flag, for example z.boolean().default(false)."
69
+ }
70
+ );
71
+ }
72
+ return value ? "retracted" : "available";
73
+ }
74
+ function normalizeConfig(graph, config) {
75
+ const sourceKinds = sourceKindsFromConfig(config.source);
76
+ const justificationKind = config.justification.kind;
77
+ const factKinds = [...config.fact.kinds];
78
+ const premiseOfKind = config.premiseOf.kind;
79
+ const derivesKind = config.derives.kind;
80
+ const retractedField = config.source.retractedField ?? DEFAULT_RETRACTED_FIELD;
81
+ if (sourceKinds.length === 0) {
82
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
83
+ "Provenance retraction requires at least one source kind.",
84
+ { role: "source" }
85
+ );
86
+ }
87
+ if (factKinds.length === 0) {
88
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
89
+ "Provenance retraction requires at least one fact kind.",
90
+ { role: "fact" }
91
+ );
92
+ }
93
+ const duplicateSourceKinds = duplicateValues(sourceKinds);
94
+ if (duplicateSourceKinds.length > 0) {
95
+ throw new chunkJIEJCTDS_cjs.ConfigurationError("Provenance source kinds must be unique.", {
96
+ duplicateSourceKinds
97
+ });
98
+ }
99
+ const duplicateFactKinds = duplicateValues(factKinds);
100
+ if (duplicateFactKinds.length > 0) {
101
+ throw new chunkJIEJCTDS_cjs.ConfigurationError("Provenance fact kinds must be unique.", {
102
+ duplicateFactKinds
103
+ });
104
+ }
105
+ for (const kind of sourceKinds) {
106
+ assertKind(graph.nodes, kind, "source", "node", graph.id);
107
+ }
108
+ assertKind(graph.nodes, justificationKind, "justification", "node", graph.id);
109
+ for (const kind of factKinds) {
110
+ assertKind(graph.nodes, kind, "fact", "node", graph.id);
111
+ }
112
+ for (const kind of sourceKinds)
113
+ assertSourceField(graph, kind, retractedField);
114
+ assertKind(graph.edges, premiseOfKind, "premiseOf", "edge", graph.id);
115
+ assertKind(graph.edges, derivesKind, "derives", "edge", graph.id);
116
+ if (factKinds.some(
117
+ (kind) => sourceKinds.includes(kind) || kind === justificationKind
118
+ )) {
119
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
120
+ "Provenance fact kinds must be distinct from source and justification kinds.",
121
+ { sourceKinds, justificationKind, factKinds }
122
+ );
123
+ }
124
+ assertEdgeEndpoints(graph, premiseOfKind, {
125
+ role: "premiseOf",
126
+ fromKinds: sourceKinds,
127
+ toKinds: [justificationKind]
128
+ });
129
+ assertEdgeEndpoints(graph, derivesKind, {
130
+ role: "derives",
131
+ fromKinds: [justificationKind],
132
+ toKinds: factKinds
133
+ });
134
+ return {
135
+ sourceKinds,
136
+ retractedField,
137
+ justificationKind,
138
+ factKinds,
139
+ premiseOfKind,
140
+ derivesKind
141
+ };
142
+ }
143
+ function sourceKindsFromConfig(source) {
144
+ if ("kinds" in source) return [...source.kinds];
145
+ return [source.kind];
146
+ }
147
+ function duplicateValues(values) {
148
+ const seen = /* @__PURE__ */ new Set();
149
+ const duplicates = /* @__PURE__ */ new Set();
150
+ for (const value of values) {
151
+ if (seen.has(value)) {
152
+ duplicates.add(value);
153
+ continue;
154
+ }
155
+ seen.add(value);
156
+ }
157
+ return [...duplicates].toSorted((left, right) => chunkZ5HBYM7U_cjs.compareStrings(left, right));
158
+ }
159
+ function assertKind(records, kind, role, noun, graphId) {
160
+ if (Object.hasOwn(records, kind)) return;
161
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
162
+ `Provenance ${role} kind "${kind}" is not a ${noun} kind in this graph.`,
163
+ { role, kind, graphId }
164
+ );
165
+ }
166
+ function assertSourceField(graph, sourceKind, retractedField) {
167
+ const registration = graph.nodes[sourceKind];
168
+ if (registration === void 0) return;
169
+ if (Object.hasOwn(registration.type.schema.shape, retractedField)) return;
170
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
171
+ `Provenance source kind "${sourceKind}" must include field "${retractedField}".`,
172
+ { sourceKind, retractedField },
173
+ {
174
+ suggestion: "Add a boolean retracted flag to the source node schema or pass source.retractedField."
175
+ }
176
+ );
177
+ }
178
+ function assertEdgeEndpoints(graph, edgeKind, expected) {
179
+ const registration = graph.edges[edgeKind];
180
+ if (registration === void 0) return;
181
+ const fromKinds = new Set(registration.from.map((node) => node.kind));
182
+ const toKinds = new Set(registration.to.map((node) => node.kind));
183
+ for (const kind of expected.fromKinds) {
184
+ if (fromKinds.has(kind)) continue;
185
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
186
+ `Provenance ${expected.role} edge "${edgeKind}" cannot start at "${kind}".`,
187
+ { edgeKind, role: expected.role, expectedFrom: kind }
188
+ );
189
+ }
190
+ for (const kind of expected.toKinds) {
191
+ if (toKinds.has(kind)) continue;
192
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
193
+ `Provenance ${expected.role} edge "${edgeKind}" cannot end at "${kind}".`,
194
+ { edgeKind, role: expected.role, expectedTo: kind }
195
+ );
196
+ }
197
+ }
198
+ function isValidAt(row, asOf) {
199
+ return (row.valid_from === void 0 || row.valid_from <= asOf) && (row.valid_to === void 0 || row.valid_to > asOf);
200
+ }
201
+ async function findNodeRows(backend, graphId, kind, options) {
202
+ if (options.includeTombstones) {
203
+ const rows = await backend.findNodesByKind({
204
+ graphId,
205
+ kind,
206
+ excludeDeleted: false,
207
+ temporalMode: "includeTombstones",
208
+ orderBy: "id"
209
+ });
210
+ return rows.filter((row) => isValidAt(row, options.asOf));
211
+ }
212
+ return backend.findNodesByKind({
213
+ graphId,
214
+ kind,
215
+ excludeDeleted: true,
216
+ temporalMode: "current",
217
+ asOf: options.asOf,
218
+ orderBy: "id"
219
+ });
220
+ }
221
+ async function findEdgeRows(backend, graphId, kind, asOf) {
222
+ return backend.findEdgesByKind({
223
+ graphId,
224
+ kind,
225
+ excludeDeleted: true,
226
+ temporalMode: "current",
227
+ asOf,
228
+ orderBy: "id"
229
+ });
230
+ }
231
+ async function readRoles(backend, graphId, config, asOf) {
232
+ const [justificationRows, factRowsByKind, premiseEdges, deriveEdges] = await Promise.all([
233
+ findNodeRows(backend, graphId, config.justificationKind, {
234
+ includeTombstones: false,
235
+ asOf
236
+ }),
237
+ Promise.all(
238
+ config.factKinds.map(
239
+ (kind) => findNodeRows(backend, graphId, kind, {
240
+ includeTombstones: true,
241
+ asOf
242
+ })
243
+ )
244
+ ),
245
+ findEdgeRows(backend, graphId, config.premiseOfKind, asOf),
246
+ findEdgeRows(backend, graphId, config.derivesKind, asOf)
247
+ ]);
248
+ const factRows = factRowsByKind.flat();
249
+ return {
250
+ justifications: rowsByKey(justificationRows),
251
+ facts: rowsByKey(factRows),
252
+ premiseEdges,
253
+ deriveEdges
254
+ };
255
+ }
256
+ function rowsByKey(rows) {
257
+ const byKey = /* @__PURE__ */ new Map();
258
+ for (const row of rows) byKey.set(rowKey(row), row);
259
+ return byKey;
260
+ }
261
+ function appendGroupedValue(groups, key, value) {
262
+ const group = groups.get(key);
263
+ if (group === void 0) {
264
+ groups.set(key, [value]);
265
+ return;
266
+ }
267
+ if (group.includes(value)) return;
268
+ group.push(value);
269
+ }
270
+ function buildSupportEdges(config, rows) {
271
+ const premisesByJustification = /* @__PURE__ */ new Map();
272
+ const factsByJustification = /* @__PURE__ */ new Map();
273
+ const justificationsByPremise = /* @__PURE__ */ new Map();
274
+ for (const edge of rows.premiseEdges) {
275
+ if (edge.to_kind !== config.justificationKind) continue;
276
+ if (!isPremiseKind(config, edge.from_kind)) continue;
277
+ const premiseKey = edgeFromKey(edge);
278
+ const justificationKey = edgeToKey(edge);
279
+ appendGroupedValue(premisesByJustification, justificationKey, premiseKey);
280
+ appendGroupedValue(justificationsByPremise, premiseKey, justificationKey);
281
+ }
282
+ for (const edge of rows.deriveEdges) {
283
+ if (edge.from_kind !== config.justificationKind) continue;
284
+ if (!config.factKinds.includes(edge.to_kind)) continue;
285
+ appendGroupedValue(
286
+ factsByJustification,
287
+ edgeFromKey(edge),
288
+ edgeToKey(edge)
289
+ );
290
+ }
291
+ return {
292
+ premisesByJustification,
293
+ factsByJustification,
294
+ justificationsByPremise
295
+ };
296
+ }
297
+ async function loadSupportGraph(backend, graphId, config) {
298
+ const asOf = chunkYC6PWTHY_cjs.nowIso();
299
+ const roles = await readRoles(backend, graphId, config, asOf);
300
+ const supportEdges = buildSupportEdges(config, roles);
301
+ const sourceRowsByKind = await Promise.all(
302
+ config.sourceKinds.map(
303
+ (kind) => findNodeRows(backend, graphId, kind, { includeTombstones: false, asOf })
304
+ )
305
+ );
306
+ return { roles, supportEdges, sourceRows: sourceRowsByKind.flat() };
307
+ }
308
+ function availableSourceKeys(sourceRows, retractedField) {
309
+ const available = /* @__PURE__ */ new Set();
310
+ for (const row of sourceRows) {
311
+ if (sourceRetractedState(row, retractedField) === "available") {
312
+ available.add(rowKey(row));
313
+ }
314
+ }
315
+ return available;
316
+ }
317
+ function computeSupportSnapshot(graph, available) {
318
+ const { roles, supportEdges } = graph;
319
+ const supported = /* @__PURE__ */ new Set();
320
+ const inSet = new Set(available);
321
+ const firingJustifications = /* @__PURE__ */ new Set();
322
+ const firingJustificationKeysByFact = /* @__PURE__ */ new Map();
323
+ let changed = true;
324
+ while (changed) {
325
+ changed = false;
326
+ for (const [justificationKey] of roles.justifications) {
327
+ if (firingJustifications.has(justificationKey)) continue;
328
+ const premises = supportEdges.premisesByJustification.get(justificationKey) ?? [];
329
+ if (!allPremisesSupported(premises, inSet)) continue;
330
+ firingJustifications.add(justificationKey);
331
+ const derivedFacts = supportEdges.factsByJustification.get(justificationKey) ?? [];
332
+ for (const factKey of derivedFacts) {
333
+ if (!roles.facts.has(factKey)) continue;
334
+ appendGroupedValue(
335
+ firingJustificationKeysByFact,
336
+ factKey,
337
+ justificationKey
338
+ );
339
+ if (supported.has(factKey)) continue;
340
+ supported.add(factKey);
341
+ inSet.add(factKey);
342
+ changed = true;
343
+ }
344
+ }
345
+ }
346
+ const believed = /* @__PURE__ */ new Set();
347
+ for (const key of supported) {
348
+ const row = roles.facts.get(key);
349
+ if (row !== void 0 && row.deleted_at === void 0) believed.add(key);
350
+ }
351
+ return {
352
+ facts: roles.facts,
353
+ supportedFactKeys: supported,
354
+ believedFactKeys: believed,
355
+ firingJustificationKeysByFact,
356
+ affectedFactKeys(targets) {
357
+ return computeAffectedFactKeys(targets, roles, supportEdges);
358
+ }
359
+ };
360
+ }
361
+ async function computeSupport(backend, graphId, config) {
362
+ const graph = await loadSupportGraph(backend, graphId, config);
363
+ return computeSupportSnapshot(
364
+ graph,
365
+ availableSourceKeys(graph.sourceRows, config.retractedField)
366
+ );
367
+ }
368
+ function isPremiseKind(config, kind) {
369
+ return config.sourceKinds.includes(kind) || config.factKinds.includes(kind);
370
+ }
371
+ function allPremisesSupported(premises, supported) {
372
+ for (const premise of premises) {
373
+ if (!supported.has(premise)) return false;
374
+ }
375
+ return true;
376
+ }
377
+ function computeAffectedFactKeys(sources, roles, supportEdges) {
378
+ const affected = /* @__PURE__ */ new Set();
379
+ const frontier = sources.map((source) => refKey(source));
380
+ const seen = new Set(frontier);
381
+ while (frontier.length > 0) {
382
+ const current = frontier.shift();
383
+ if (current === void 0) continue;
384
+ const justifications = supportEdges.justificationsByPremise.get(current) ?? [];
385
+ for (const justificationKey of justifications) {
386
+ const derivedFacts = supportEdges.factsByJustification.get(justificationKey) ?? [];
387
+ for (const factKey of derivedFacts) {
388
+ if (!roles.facts.has(factKey)) continue;
389
+ affected.add(factKey);
390
+ if (seen.has(factKey)) continue;
391
+ seen.add(factKey);
392
+ frontier.push(factKey);
393
+ }
394
+ }
395
+ }
396
+ return affected;
397
+ }
398
+ function buildReport(before, after, affected) {
399
+ const believedBefore = [...before.believedFactKeys];
400
+ const died = sortedReferences(
401
+ believedBefore.filter((key) => !after.supportedFactKeys.has(key))
402
+ );
403
+ const unaffected = sortedReferences(
404
+ believedBefore.filter((key) => !affected.has(key))
405
+ );
406
+ const survivedVia = [...affected].filter((key) => after.supportedFactKeys.has(key)).toSorted((left, right) => chunkZ5HBYM7U_cjs.compareStrings(left, right)).map((key) => ({
407
+ fact: keyToRef(key),
408
+ via: sortedReferences(
409
+ after.firingJustificationKeysByFact.get(key) ?? []
410
+ )
411
+ }));
412
+ return { died, survivedVia, unaffected };
413
+ }
414
+ async function forEachAffectedFact(snapshot, affected, isTargetKey, isTargetRow, action) {
415
+ const rows = [];
416
+ for (const [key, row] of snapshot.facts) {
417
+ if (!affected.has(key)) continue;
418
+ if (!isTargetKey(key)) continue;
419
+ if (!isTargetRow(row)) continue;
420
+ rows.push(row);
421
+ }
422
+ await Promise.all(rows.map((row) => action(row)));
423
+ }
424
+ async function synchronizeFactCurrency(backend, store, runHooks, snapshot, affected, lock) {
425
+ await forEachAffectedFact(
426
+ snapshot,
427
+ affected,
428
+ (key) => !snapshot.supportedFactKeys.has(key),
429
+ chunkUNNPKQUG_cjs.isLiveNodeRow,
430
+ (row) => closeFactCurrency(backend, store, runHooks, row, lock)
431
+ );
432
+ await forEachAffectedFact(
433
+ snapshot,
434
+ affected,
435
+ (key) => snapshot.supportedFactKeys.has(key),
436
+ chunkUNNPKQUG_cjs.isTombstonedNodeRow,
437
+ (row) => reopenFactCurrency(backend, store, runHooks, row, lock)
438
+ );
439
+ }
440
+ function getFactRegistration(store, row) {
441
+ const registration = store.graph.nodes[row.kind];
442
+ if (registration !== void 0) return registration;
443
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
444
+ `Provenance fact kind "${row.kind}" is not a node kind in this graph.`,
445
+ { kind: row.kind, graphId: store.graphId }
446
+ );
447
+ }
448
+ async function closeFactCurrency(backend, store, runHooks, row, lock) {
449
+ await runHooks("delete", row.kind, row.id, async () => {
450
+ const registration = getFactRegistration(store, row);
451
+ await chunk5IQIX7LU_cjs.applyNodeSoftDelete(
452
+ chunk5IQIX7LU_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
453
+ {
454
+ existing: row,
455
+ schema: registration.type.schema,
456
+ uniqueConstraints: registration.unique ?? [],
457
+ onDelete: registration.onDelete
458
+ },
459
+ backend,
460
+ { enforceDeleteBehavior: false }
461
+ );
462
+ });
463
+ }
464
+ async function reopenFactCurrency(backend, store, runHooks, row, lock) {
465
+ await runHooks("update", row.kind, row.id, async () => {
466
+ const registration = getFactRegistration(store, row);
467
+ await chunk5IQIX7LU_cjs.applyNodeResurrect(
468
+ chunk5IQIX7LU_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
469
+ {
470
+ existing: row,
471
+ schema: registration.type.schema,
472
+ uniqueConstraints: registration.unique ?? []
473
+ },
474
+ backend
475
+ );
476
+ });
477
+ }
478
+ function getTransactionNodeCollection(tx, kind) {
479
+ const collection = tx.getNodeCollection(kind);
480
+ if (collection !== void 0) return collection;
481
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
482
+ `Provenance source kind "${kind}" is not available on this transaction.`,
483
+ { kind }
484
+ );
485
+ }
486
+ async function setSourceRetractionState(tx, config, source, retracted) {
487
+ const collection = getTransactionNodeCollection(tx, source.kind);
488
+ await collection.update(source.id, { [config.retractedField]: retracted });
489
+ }
490
+ async function runTransition(store, config, sources, retracted) {
491
+ const uniqueSources = uniqueNodeReferences(sources);
492
+ for (const source of uniqueSources) {
493
+ if (config.sourceKinds.includes(source.kind)) continue;
494
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
495
+ `Provenance retraction source must be one of: ${config.sourceKinds.join(", ")}.`,
496
+ { expectedKinds: config.sourceKinds, actualKind: source.kind }
497
+ );
498
+ }
499
+ return store.transaction(async (tx) => {
500
+ const lock = await chunk5IQIX7LU_cjs.lockRecordedGraphWrite(tx.backend, store.graphId);
501
+ const rows = await Promise.all(
502
+ uniqueSources.map(
503
+ (source) => tx.backend.getNode(store.graphId, source.kind, source.id)
504
+ )
505
+ );
506
+ const sourceRows = uniqueSources.map((source, index) => {
507
+ const sourceRow = rows[index];
508
+ if (sourceRow === void 0 || sourceRow.deleted_at !== void 0) {
509
+ throw new chunkJIEJCTDS_cjs.NodeNotFoundError(source.kind, source.id);
510
+ }
511
+ return { source, row: sourceRow };
512
+ });
513
+ const supportGraph = await loadSupportGraph(
514
+ tx.backend,
515
+ store.graphId,
516
+ config
517
+ );
518
+ const availableBefore = availableSourceKeys(
519
+ supportGraph.sourceRows,
520
+ config.retractedField
521
+ );
522
+ const before = computeSupportSnapshot(supportGraph, availableBefore);
523
+ const nextState = retracted ? "retracted" : "available";
524
+ const availableAfter = new Set(availableBefore);
525
+ for (const { source, row } of sourceRows) {
526
+ const currentState = sourceRetractedState(row, config.retractedField);
527
+ if (currentState === nextState) continue;
528
+ await setSourceRetractionState(tx, config, source, retracted);
529
+ if (nextState === "available") {
530
+ availableAfter.add(refKey(source));
531
+ } else {
532
+ availableAfter.delete(refKey(source));
533
+ }
534
+ }
535
+ const after = computeSupportSnapshot(supportGraph, availableAfter);
536
+ const affected = after.affectedFactKeys(uniqueSources);
537
+ await synchronizeFactCurrency(
538
+ tx.backend,
539
+ store,
540
+ tx.runNodeOperationHooks,
541
+ after,
542
+ affected,
543
+ lock
544
+ );
545
+ return buildReport(before, after, affected);
546
+ });
547
+ }
548
+ function uniqueNodeReferences(references) {
549
+ const byKey = /* @__PURE__ */ new Map();
550
+ for (const reference of references) {
551
+ byKey.set(refKey(reference), reference);
552
+ }
553
+ return [...byKey.values()];
554
+ }
555
+ function createRetractionCapability(store, config) {
556
+ const historyEnabled = store.historyEnabled;
557
+ if (!historyEnabled) {
558
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
559
+ "createRetractionCapability requires a store created with { history: true }.",
560
+ { graphId: store.graphId },
561
+ {
562
+ suggestion: "Use createStoreWithSchema(graph, backend, { history: true }) so retraction mutations are captured and queryable with asOfRecorded()."
563
+ }
564
+ );
565
+ }
566
+ const normalized = normalizeConfig(store.graph, config);
567
+ const transition = (sources, retracted) => runTransition(store, normalized, sources, retracted);
568
+ return {
569
+ retract: (source) => transition([source], true),
570
+ retractMany: (sources) => transition(sources, true),
571
+ unRetract: (source) => transition([source], false),
572
+ unRetractMany: (sources) => transition(sources, false),
573
+ async holding() {
574
+ return store.transaction(async (tx) => {
575
+ await chunk5IQIX7LU_cjs.lockRecordedGraphWrite(tx.backend, store.graphId);
576
+ const snapshot = await computeSupport(
577
+ tx.backend,
578
+ store.graphId,
579
+ normalized
580
+ );
581
+ return sortedReferences(
582
+ snapshot.believedFactKeys
583
+ );
584
+ });
585
+ }
586
+ };
587
+ }
588
+
589
+ exports.createRetractionCapability = createRetractionCapability;
590
+ //# sourceMappingURL=index.cjs.map
591
+ //# sourceMappingURL=index.cjs.map