@nicia-ai/typegraph 0.47.0 → 0.48.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 (207) hide show
  1. package/dist/backend/drizzle/indexes.d.cts +1 -1
  2. package/dist/backend/drizzle/indexes.d.ts +1 -1
  3. package/dist/backend/index.cjs +27 -19
  4. package/dist/backend/index.d.cts +37 -55
  5. package/dist/backend/index.d.ts +37 -55
  6. package/dist/backend/index.js +4 -4
  7. package/dist/backend/postgres/index.cjs +7 -7
  8. package/dist/backend/postgres/index.d.cts +21 -7
  9. package/dist/backend/postgres/index.d.ts +21 -7
  10. package/dist/backend/postgres/index.js +6 -6
  11. package/dist/backend/postgres/pglite-store.cjs +17 -17
  12. package/dist/backend/postgres/pglite-store.d.cts +8 -8
  13. package/dist/backend/postgres/pglite-store.d.ts +8 -8
  14. package/dist/backend/postgres/pglite-store.js +14 -14
  15. package/dist/backend/postgres/pglite.cjs +8 -8
  16. package/dist/backend/postgres/pglite.d.cts +3 -3
  17. package/dist/backend/postgres/pglite.d.ts +3 -3
  18. package/dist/backend/postgres/pglite.js +7 -7
  19. package/dist/backend/sqlite/index.cjs +7 -7
  20. package/dist/backend/sqlite/index.d.cts +20 -7
  21. package/dist/backend/sqlite/index.d.ts +20 -7
  22. package/dist/backend/sqlite/index.js +6 -6
  23. package/dist/backend/sqlite/libsql.cjs +8 -8
  24. package/dist/backend/sqlite/libsql.d.cts +3 -3
  25. package/dist/backend/sqlite/libsql.d.ts +3 -3
  26. package/dist/backend/sqlite/libsql.js +6 -6
  27. package/dist/backend/sqlite/local-store.cjs +18 -18
  28. package/dist/backend/sqlite/local-store.d.cts +8 -8
  29. package/dist/backend/sqlite/local-store.d.ts +8 -8
  30. package/dist/backend/sqlite/local-store.js +15 -15
  31. package/dist/backend/sqlite/local.cjs +9 -9
  32. package/dist/backend/sqlite/local.d.cts +3 -3
  33. package/dist/backend/sqlite/local.d.ts +3 -3
  34. package/dist/backend/sqlite/local.js +7 -7
  35. package/dist/{chunk-EMIB2RXD.cjs → chunk-2HIYYMWY.cjs} +99 -96
  36. package/dist/chunk-2HIYYMWY.cjs.map +1 -0
  37. package/dist/{chunk-6KFLYYOC.cjs → chunk-2QGYQBS2.cjs} +5 -5
  38. package/dist/{chunk-6KFLYYOC.cjs.map → chunk-2QGYQBS2.cjs.map} +1 -1
  39. package/dist/{chunk-5FT3TLPK.js → chunk-2SYZXD54.js} +16 -13
  40. package/dist/chunk-2SYZXD54.js.map +1 -0
  41. package/dist/{chunk-XYBQI6LE.js → chunk-2TYSSBU5.js} +6 -6
  42. package/dist/{chunk-XYBQI6LE.js.map → chunk-2TYSSBU5.js.map} +1 -1
  43. package/dist/{chunk-6JVZSOHQ.cjs → chunk-3FPR224C.cjs} +26 -26
  44. package/dist/{chunk-6JVZSOHQ.cjs.map → chunk-3FPR224C.cjs.map} +1 -1
  45. package/dist/{chunk-MFZR4QKM.cjs → chunk-3KOY4FH3.cjs} +181 -4
  46. package/dist/chunk-3KOY4FH3.cjs.map +1 -0
  47. package/dist/{chunk-6FWSNSRE.js → chunk-4WMMBDS5.js} +4 -4
  48. package/dist/chunk-4WMMBDS5.js.map +1 -0
  49. package/dist/{chunk-NG2RB5WL.js → chunk-5K2BKEBD.js} +18 -3
  50. package/dist/chunk-5K2BKEBD.js.map +1 -0
  51. package/dist/chunk-5PRKMB24.cjs +124 -0
  52. package/dist/chunk-5PRKMB24.cjs.map +1 -0
  53. package/dist/chunk-6LN7FIVU.js +107 -0
  54. package/dist/chunk-6LN7FIVU.js.map +1 -0
  55. package/dist/{chunk-I4G3SQPF.cjs → chunk-7XUYFFR4.cjs} +7 -7
  56. package/dist/chunk-7XUYFFR4.cjs.map +1 -0
  57. package/dist/{chunk-KH7XW7VV.js → chunk-ACGSAMD3.js} +24 -27
  58. package/dist/chunk-ACGSAMD3.js.map +1 -0
  59. package/dist/{chunk-QS3NQZVC.js → chunk-AX6JGVTZ.js} +16 -11
  60. package/dist/chunk-AX6JGVTZ.js.map +1 -0
  61. package/dist/{chunk-DJZTXBWY.js → chunk-BRRP76WO.js} +71 -30
  62. package/dist/chunk-BRRP76WO.js.map +1 -0
  63. package/dist/{chunk-5UMTUOM5.js → chunk-CT3ZKTOF.js} +5 -4
  64. package/dist/chunk-CT3ZKTOF.js.map +1 -0
  65. package/dist/{chunk-XY5OMOJD.js → chunk-DZAICA5J.js} +3 -3
  66. package/dist/{chunk-XY5OMOJD.js.map → chunk-DZAICA5J.js.map} +1 -1
  67. package/dist/{chunk-OIFSOPSR.cjs → chunk-EZEEWCFJ.cjs} +38 -156
  68. package/dist/chunk-EZEEWCFJ.cjs.map +1 -0
  69. package/dist/{chunk-AMMWA76F.cjs → chunk-FA2AFWLP.cjs} +6 -6
  70. package/dist/{chunk-AMMWA76F.cjs.map → chunk-FA2AFWLP.cjs.map} +1 -1
  71. package/dist/{chunk-FNOMT74T.js → chunk-I4GAZH5Z.js} +180 -5
  72. package/dist/chunk-I4GAZH5Z.js.map +1 -0
  73. package/dist/{chunk-WGX7JH7E.cjs → chunk-JB6T4GLL.cjs} +106 -134
  74. package/dist/chunk-JB6T4GLL.cjs.map +1 -0
  75. package/dist/{chunk-MX4DHSQP.cjs → chunk-JFRT7S3B.cjs} +92 -98
  76. package/dist/chunk-JFRT7S3B.cjs.map +1 -0
  77. package/dist/{chunk-SE6EGQSD.js → chunk-KF6K7TGH.js} +38 -66
  78. package/dist/chunk-KF6K7TGH.js.map +1 -0
  79. package/dist/{chunk-ZHNXLS3C.js → chunk-NACVVDWB.js} +208 -8
  80. package/dist/chunk-NACVVDWB.js.map +1 -0
  81. package/dist/{chunk-M35DF33T.js → chunk-OD4SSY2U.js} +29 -16
  82. package/dist/chunk-OD4SSY2U.js.map +1 -0
  83. package/dist/{chunk-U5EDAVOJ.cjs → chunk-OTUPEF2W.cjs} +54 -49
  84. package/dist/chunk-OTUPEF2W.cjs.map +1 -0
  85. package/dist/{chunk-BCQ76AXA.cjs → chunk-PFBRJBUL.cjs} +107 -94
  86. package/dist/chunk-PFBRJBUL.cjs.map +1 -0
  87. package/dist/{chunk-AVGUJWVX.js → chunk-S5TERQVW.js} +15 -132
  88. package/dist/chunk-S5TERQVW.js.map +1 -0
  89. package/dist/chunk-SIT26LAZ.cjs +614 -0
  90. package/dist/chunk-SIT26LAZ.cjs.map +1 -0
  91. package/dist/{chunk-BR7SHKGM.cjs → chunk-SR725PWF.cjs} +548 -507
  92. package/dist/chunk-SR725PWF.cjs.map +1 -0
  93. package/dist/{chunk-5FBRVORR.cjs → chunk-TKZXMWQF.cjs} +8 -7
  94. package/dist/chunk-TKZXMWQF.cjs.map +1 -0
  95. package/dist/{chunk-425IZOQ5.cjs → chunk-TQHGE7UC.cjs} +20 -2
  96. package/dist/chunk-TQHGE7UC.cjs.map +1 -0
  97. package/dist/{chunk-GYUJZARH.cjs → chunk-TUNPBZY3.cjs} +4 -4
  98. package/dist/{chunk-GYUJZARH.cjs.map → chunk-TUNPBZY3.cjs.map} +1 -1
  99. package/dist/chunk-UGHG7PGX.js +592 -0
  100. package/dist/chunk-UGHG7PGX.js.map +1 -0
  101. package/dist/{chunk-KABFHAL7.cjs → chunk-UMGZDVOA.cjs} +213 -12
  102. package/dist/chunk-UMGZDVOA.cjs.map +1 -0
  103. package/dist/{chunk-UPAJHMW3.cjs → chunk-WCCATHMB.cjs} +54 -57
  104. package/dist/chunk-WCCATHMB.cjs.map +1 -0
  105. package/dist/{chunk-LEWHMOUY.js → chunk-YIURNGXI.js} +4 -4
  106. package/dist/{chunk-LEWHMOUY.js.map → chunk-YIURNGXI.js.map} +1 -1
  107. package/dist/{chunk-EP4RUYD6.js → chunk-YVF2EM7B.js} +3 -3
  108. package/dist/{chunk-EP4RUYD6.js.map → chunk-YVF2EM7B.js.map} +1 -1
  109. package/dist/{chunk-NNQ6A3RM.js → chunk-ZFMCDJGB.js} +7 -12
  110. package/dist/chunk-ZFMCDJGB.js.map +1 -0
  111. package/dist/core/index.cjs +6 -6
  112. package/dist/core/index.d.cts +4 -4
  113. package/dist/core/index.d.ts +4 -4
  114. package/dist/core/index.js +2 -2
  115. package/dist/ddl-BL1NZLMY.d.cts +78 -0
  116. package/dist/ddl-D_oW-EVO.d.ts +78 -0
  117. package/dist/graph-extension/index.d.cts +4 -4
  118. package/dist/graph-extension/index.d.ts +4 -4
  119. package/dist/graph-merge/index.cjs +334 -191
  120. package/dist/graph-merge/index.cjs.map +1 -1
  121. package/dist/graph-merge/index.d.cts +65 -15
  122. package/dist/graph-merge/index.d.ts +65 -15
  123. package/dist/graph-merge/index.js +174 -32
  124. package/dist/graph-merge/index.js.map +1 -1
  125. package/dist/{index-CHTv4XMZ.d.cts → index-COs_z6nV.d.cts} +2 -2
  126. package/dist/{index-CzoJ3MUw.d.ts → index-D7d1u2gr.d.ts} +2 -2
  127. package/dist/index.cjs +90 -86
  128. package/dist/index.d.cts +12 -12
  129. package/dist/index.d.ts +12 -12
  130. package/dist/index.js +13 -13
  131. package/dist/indexes/index.d.cts +4 -4
  132. package/dist/indexes/index.d.ts +4 -4
  133. package/dist/interchange/index.cjs +38 -38
  134. package/dist/interchange/index.d.cts +7 -7
  135. package/dist/interchange/index.d.ts +7 -7
  136. package/dist/interchange/index.js +10 -10
  137. package/dist/{manager-DlY1vlla.d.cts → manager-CYaff3n3.d.cts} +2 -2
  138. package/dist/{manager-B6sOQzcQ.d.ts → manager-D9eRT_ns.d.ts} +2 -2
  139. package/dist/{materialize-indexes-DQL4xcpf.d.ts → materialize-indexes-DJ3ykH59.d.ts} +1 -1
  140. package/dist/{materialize-indexes-sskhp-c_.d.cts → materialize-indexes-DTtAnvfY.d.cts} +1 -1
  141. package/dist/{postgres-BXy_nyMs.d.cts → postgres-CcL4bAHS.d.ts} +1 -1
  142. package/dist/{postgres-B6YOUcaK.d.ts → postgres-DMj39MEu.d.cts} +1 -1
  143. package/dist/profiler/index.d.cts +9 -9
  144. package/dist/profiler/index.d.ts +9 -9
  145. package/dist/provenance/index.cjs +25 -26
  146. package/dist/provenance/index.cjs.map +1 -1
  147. package/dist/provenance/index.d.cts +7 -7
  148. package/dist/provenance/index.d.ts +7 -7
  149. package/dist/provenance/index.js +9 -10
  150. package/dist/provenance/index.js.map +1 -1
  151. package/dist/repair-validity-windows-BFNZvd_H.d.cts +166 -0
  152. package/dist/repair-validity-windows-DlUSqwCg.d.ts +166 -0
  153. package/dist/schema/index.cjs +35 -35
  154. package/dist/schema/index.d.cts +6 -6
  155. package/dist/schema/index.d.ts +6 -6
  156. package/dist/schema/index.js +8 -8
  157. package/dist/{searchable-D9gMiwcS.d.ts → searchable-DHJMh_nj.d.cts} +1 -1
  158. package/dist/{searchable-0Cn_lY8U.d.cts → searchable-bpE1bBfc.d.ts} +1 -1
  159. package/dist/{sqlite-DioSxaPe.d.cts → sqlite-D7Oz0SQh.d.ts} +1 -1
  160. package/dist/{sqlite-ClXuBYAj.d.ts → sqlite-YppHrNFb.d.cts} +1 -1
  161. package/dist/{store-5j-w5onJ.d.ts → store-JUVvtmR4.d.cts} +113 -26
  162. package/dist/{store-CFedKGU5.d.cts → store-UzrGvZOo.d.ts} +113 -26
  163. package/dist/{temporal-CjO9FH1l.d.ts → temporal-5GqpYCk2.d.cts} +1 -1
  164. package/dist/{temporal-Ce1pG0S1.d.cts → temporal-CbnLzTmM.d.ts} +1 -1
  165. package/dist/{types-DKkMJZjR.d.cts → types-BqFZTQmV.d.cts} +29 -4
  166. package/dist/{types-DKkMJZjR.d.ts → types-BqFZTQmV.d.ts} +29 -4
  167. package/dist/{types-BrdOFu48.d.ts → types-Bx74kaTt.d.ts} +1 -1
  168. package/dist/{types-oj_OGAaZ.d.cts → types-CXAhpW-c.d.cts} +1 -1
  169. package/dist/{where-D1wKCJ4Q.d.cts → where-DI_Fqz-X.d.cts} +1 -1
  170. package/dist/{where-C8w2627G.d.ts → where-O-k2wgYm.d.ts} +1 -1
  171. package/package.json +1 -1
  172. package/dist/chunk-3HGRTCDU.cjs +0 -269
  173. package/dist/chunk-3HGRTCDU.cjs.map +0 -1
  174. package/dist/chunk-425IZOQ5.cjs.map +0 -1
  175. package/dist/chunk-5FBRVORR.cjs.map +0 -1
  176. package/dist/chunk-5FT3TLPK.js.map +0 -1
  177. package/dist/chunk-5UMTUOM5.js.map +0 -1
  178. package/dist/chunk-6FWSNSRE.js.map +0 -1
  179. package/dist/chunk-AVGUJWVX.js.map +0 -1
  180. package/dist/chunk-BCQ76AXA.cjs.map +0 -1
  181. package/dist/chunk-BR7SHKGM.cjs.map +0 -1
  182. package/dist/chunk-DJZTXBWY.js.map +0 -1
  183. package/dist/chunk-EMIB2RXD.cjs.map +0 -1
  184. package/dist/chunk-FNOMT74T.js.map +0 -1
  185. package/dist/chunk-I4G3SQPF.cjs.map +0 -1
  186. package/dist/chunk-JR6SX5RH.cjs +0 -268
  187. package/dist/chunk-JR6SX5RH.cjs.map +0 -1
  188. package/dist/chunk-KABFHAL7.cjs.map +0 -1
  189. package/dist/chunk-KH7XW7VV.js.map +0 -1
  190. package/dist/chunk-M35DF33T.js.map +0 -1
  191. package/dist/chunk-MFZR4QKM.cjs.map +0 -1
  192. package/dist/chunk-MX4DHSQP.cjs.map +0 -1
  193. package/dist/chunk-NAZ2RA4L.js +0 -254
  194. package/dist/chunk-NAZ2RA4L.js.map +0 -1
  195. package/dist/chunk-NG2RB5WL.js.map +0 -1
  196. package/dist/chunk-NNQ6A3RM.js.map +0 -1
  197. package/dist/chunk-OIFSOPSR.cjs.map +0 -1
  198. package/dist/chunk-QS3NQZVC.js.map +0 -1
  199. package/dist/chunk-SE6EGQSD.js.map +0 -1
  200. package/dist/chunk-SHSSRCFR.js +0 -246
  201. package/dist/chunk-SHSSRCFR.js.map +0 -1
  202. package/dist/chunk-U5EDAVOJ.cjs.map +0 -1
  203. package/dist/chunk-UPAJHMW3.cjs.map +0 -1
  204. package/dist/chunk-WGX7JH7E.cjs.map +0 -1
  205. package/dist/chunk-ZHNXLS3C.js.map +0 -1
  206. package/dist/ddl-CprnMXJ-.d.ts +0 -38
  207. package/dist/ddl-DJA7Lci5.d.cts +0 -38
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkMFZR4QKM_cjs = require('../chunk-MFZR4QKM.cjs');
4
- var chunkOIFSOPSR_cjs = require('../chunk-OIFSOPSR.cjs');
5
- require('../chunk-JR6SX5RH.cjs');
3
+ var chunk3KOY4FH3_cjs = require('../chunk-3KOY4FH3.cjs');
4
+ var chunkEZEEWCFJ_cjs = require('../chunk-EZEEWCFJ.cjs');
5
+ require('../chunk-SIT26LAZ.cjs');
6
6
  require('../chunk-3U5ABFDW.cjs');
7
- var chunk3HGRTCDU_cjs = require('../chunk-3HGRTCDU.cjs');
7
+ var chunk5PRKMB24_cjs = require('../chunk-5PRKMB24.cjs');
8
8
  require('../chunk-FQPEMEWX.cjs');
9
- require('../chunk-6KFLYYOC.cjs');
10
- var chunk425IZOQ5_cjs = require('../chunk-425IZOQ5.cjs');
9
+ require('../chunk-2QGYQBS2.cjs');
10
+ var chunkTQHGE7UC_cjs = require('../chunk-TQHGE7UC.cjs');
11
11
  require('../chunk-NAUA4PW5.cjs');
12
12
  require('../chunk-EDN4Y4ZG.cjs');
13
13
  require('../chunk-RT5ZY4XA.cjs');
@@ -47,10 +47,10 @@ function keyToRef(key) {
47
47
  return { kind, id };
48
48
  }
49
49
  function sortedReferences(keys) {
50
- return [...keys].toSorted((left, right) => chunkOIFSOPSR_cjs.compareStrings(left, right)).map((key) => keyToRef(key));
50
+ return [...keys].toSorted((left, right) => chunkEZEEWCFJ_cjs.compareStrings(left, right)).map((key) => keyToRef(key));
51
51
  }
52
52
  function parseNodeProps(row) {
53
- const parsed = chunk3HGRTCDU_cjs.rowPropsToObject(row.props);
53
+ const parsed = chunk5PRKMB24_cjs.rowPropsToObject(row.props);
54
54
  if (!chunkN66HCGCY_cjs.isPlainObject(parsed)) {
55
55
  throw new chunkMRDBBHIZ_cjs.ConfigurationError(
56
56
  `Node ${row.kind}/${row.id} props are not an object.`,
@@ -157,7 +157,7 @@ function duplicateValues(values) {
157
157
  }
158
158
  seen.add(value);
159
159
  }
160
- return [...duplicates].toSorted((left, right) => chunkOIFSOPSR_cjs.compareStrings(left, right));
160
+ return [...duplicates].toSorted((left, right) => chunkEZEEWCFJ_cjs.compareStrings(left, right));
161
161
  }
162
162
  function assertKind(records, kind, role, noun, graphId) {
163
163
  if (Object.hasOwn(records, kind)) return;
@@ -198,9 +198,6 @@ function assertEdgeEndpoints(graph, edgeKind, expected) {
198
198
  );
199
199
  }
200
200
  }
201
- function isValidAt(row, asOf) {
202
- return (row.valid_from === void 0 || row.valid_from <= asOf) && (row.valid_to === void 0 || row.valid_to > asOf);
203
- }
204
201
  async function findNodeRows(backend, graphId, kind, options) {
205
202
  if (options.includeTombstones) {
206
203
  const rows = await backend.findNodesByKind({
@@ -210,7 +207,9 @@ async function findNodeRows(backend, graphId, kind, options) {
210
207
  temporalMode: "includeTombstones",
211
208
  orderBy: "id"
212
209
  });
213
- return rows.filter((row) => isValidAt(row, options.asOf));
210
+ return rows.filter(
211
+ (row) => chunkTQHGE7UC_cjs.validityWindowContainsInstant(row.valid_from, row.valid_to, options.asOf)
212
+ );
214
213
  }
215
214
  return backend.findNodesByKind({
216
215
  graphId,
@@ -298,7 +297,7 @@ function buildSupportEdges(config, rows) {
298
297
  };
299
298
  }
300
299
  async function loadSupportGraph(backend, graphId, config) {
301
- const asOf = chunk425IZOQ5_cjs.nowIso();
300
+ const asOf = chunkTQHGE7UC_cjs.nowIso();
302
301
  const roles = await readRoles(backend, graphId, config, asOf);
303
302
  const supportEdges = buildSupportEdges(config, roles);
304
303
  const sourceRowsByKind = await Promise.all(
@@ -406,7 +405,7 @@ function buildReport(before, after, affected) {
406
405
  const unaffected = sortedReferences(
407
406
  believedBefore.filter((key) => !affected.has(key))
408
407
  );
409
- const survivedVia = [...affected].filter((key) => after.supportedFactKeys.has(key)).toSorted((left, right) => chunkOIFSOPSR_cjs.compareStrings(left, right)).map((key) => ({
408
+ const survivedVia = [...affected].filter((key) => after.supportedFactKeys.has(key)).toSorted((left, right) => chunkEZEEWCFJ_cjs.compareStrings(left, right)).map((key) => ({
410
409
  fact: keyToRef(key),
411
410
  via: sortedReferences(
412
411
  after.firingJustificationKeysByFact.get(key) ?? []
@@ -429,14 +428,14 @@ async function synchronizeFactCurrency(backend, store, runHooks, snapshot, affec
429
428
  snapshot,
430
429
  affected,
431
430
  (key) => !snapshot.supportedFactKeys.has(key),
432
- chunk3HGRTCDU_cjs.isLiveNodeRow,
431
+ chunk5PRKMB24_cjs.isLiveNodeRow,
433
432
  (row) => closeFactCurrency(backend, store, runHooks, row, lock)
434
433
  );
435
434
  await forEachAffectedFact(
436
435
  snapshot,
437
436
  affected,
438
437
  (key) => snapshot.supportedFactKeys.has(key),
439
- chunk3HGRTCDU_cjs.isTombstonedNodeRow,
438
+ chunk5PRKMB24_cjs.isTombstonedNodeRow,
440
439
  (row) => reopenFactCurrency(backend, store, runHooks, row, lock)
441
440
  );
442
441
  }
@@ -451,8 +450,8 @@ function getFactRegistration(store, row) {
451
450
  async function closeFactCurrency(backend, store, runHooks, row, lock) {
452
451
  await runHooks("delete", row.kind, row.id, async () => {
453
452
  const registration = getFactRegistration(store, row);
454
- await chunkMFZR4QKM_cjs.applyNodeSoftDelete(
455
- chunkMFZR4QKM_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
453
+ await chunk3KOY4FH3_cjs.applyNodeSoftDelete(
454
+ chunk3KOY4FH3_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
456
455
  {
457
456
  existing: row,
458
457
  schema: registration.type.schema,
@@ -467,8 +466,8 @@ async function closeFactCurrency(backend, store, runHooks, row, lock) {
467
466
  async function reopenFactCurrency(backend, store, runHooks, row, lock) {
468
467
  await runHooks("update", row.kind, row.id, async () => {
469
468
  const registration = getFactRegistration(store, row);
470
- await chunkMFZR4QKM_cjs.applyNodeResurrect(
471
- chunkMFZR4QKM_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
469
+ await chunk3KOY4FH3_cjs.applyNodeResurrect(
470
+ chunk3KOY4FH3_cjs.createNodeWriteContext(store.graphId, store.registry, lock),
472
471
  {
473
472
  existing: row,
474
473
  schema: registration.type.schema,
@@ -500,8 +499,8 @@ async function runTransition(store, config, sources, retracted) {
500
499
  );
501
500
  }
502
501
  return store.transaction(async (tx) => {
503
- const backend = chunkMFZR4QKM_cjs.transactionBackend(tx);
504
- const lock = await chunkOIFSOPSR_cjs.lockRecordedGraphWrite(backend, store.graphId);
502
+ const backend = chunk3KOY4FH3_cjs.transactionBackend(tx);
503
+ const lock = await chunkEZEEWCFJ_cjs.lockRecordedGraphWrite(backend, store.graphId);
505
504
  const rows = await Promise.all(
506
505
  uniqueSources.map(
507
506
  (source) => backend.getNode(store.graphId, source.kind, source.id)
@@ -537,7 +536,7 @@ async function runTransition(store, config, sources, retracted) {
537
536
  await synchronizeFactCurrency(
538
537
  backend,
539
538
  store,
540
- chunkMFZR4QKM_cjs.transactionNodeOperationHookRunner(tx),
539
+ chunk3KOY4FH3_cjs.transactionNodeOperationHookRunner(tx),
541
540
  after,
542
541
  affected,
543
542
  lock
@@ -563,8 +562,8 @@ function createRetractionCapability(store, config) {
563
562
  unRetractMany: (sources) => transition(sources, false),
564
563
  async holding() {
565
564
  return store.transaction(async (tx) => {
566
- const backend = chunkMFZR4QKM_cjs.transactionBackend(tx);
567
- await chunkOIFSOPSR_cjs.lockRecordedGraphWrite(backend, store.graphId);
565
+ const backend = chunk3KOY4FH3_cjs.transactionBackend(tx);
566
+ await chunkEZEEWCFJ_cjs.lockRecordedGraphWrite(backend, store.graphId);
568
567
  const snapshot = await computeSupport(
569
568
  backend,
570
569
  store.graphId,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/provenance/index.ts"],"names":["ConfigurationError","compareStrings","rowPropsToObject","isPlainObject","nowIso","isLiveNodeRow","isTombstonedNodeRow","applyNodeSoftDelete","createNodeWriteContext","applyNodeResurrect","transactionBackend","lockRecordedGraphWrite","NodeNotF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geRow,\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\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../backend/types\";\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
+ {"version":3,"sources":["../../src/provenance/index.ts"],"names":["ConfigurationError","compareStrings","rowPropsToObject","isPlainObject","validityWindowContainsInstant","nowIso","isLiveNodeRow","isTombstonedNodeRow","applyNodeSoftDelete","createNodeWriteContext","applyNodeResurrect","transactionBackend","lockRecordedGraphWrite","NodeNotFoundError","transactionNodeOperationHookRunner"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,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,SAAS,UAAU,IAAA,EAAuB;AACxC,EAAA,OAAO,MAAA,CAAO,EAAE,IAAA,EAAM,IAAA,CAAK,SAAS,EAAA,EAAI,IAAA,CAAK,OAAO,CAAA;AACtD;AAEA,SAAS,SAGP,GAAA,EAAsC;AACtC,EAAA,M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A,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,IAAIZ,oCAAA;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.cjs","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, validityWindowContainsInstant } from \"../utils/date\";\nimport { isPlainObject } from \"../utils/object\";\n\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../backend/types\";\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 * 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) =>\n validityWindowContainsInstant(row.valid_from, row.valid_to, options.asOf),\n );\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,11 +1,11 @@
1
- import { d as GraphDef } from '../types-DKkMJZjR.cjs';
2
- export { C as ContributionDiagnostic, a as ContributionDiagnosticState, b as ContributionRepairEntry, c as ContributionRepairResult } from '../types-DKkMJZjR.cjs';
3
- import { b as HistoryStore } from '../store-CFedKGU5.cjs';
1
+ import { d8 as GraphDef } from '../types-BqFZTQmV.cjs';
2
+ export { u as ContributionDiagnostic, v as ContributionDiagnosticState, J as ContributionRepairEntry, K as ContributionRepairResult } from '../types-BqFZTQmV.cjs';
3
+ import { b as HistoryStore } from '../store-JUVvtmR4.cjs';
4
4
  import 'zod';
5
- import '../temporal-Ce1pG0S1.cjs';
6
- import '../searchable-0Cn_lY8U.cjs';
7
- import '../manager-DlY1vlla.cjs';
8
- import '../materialize-indexes-sskhp-c_.cjs';
5
+ import '../temporal-5GqpYCk2.cjs';
6
+ import '../searchable-DHJMh_nj.cjs';
7
+ import '../manager-CYaff3n3.cjs';
8
+ import '../materialize-indexes-DTtAnvfY.cjs';
9
9
 
10
10
  type NodeKind<G extends GraphDef> = Extract<keyof G["nodes"], string>;
11
11
  type EdgeKind<G extends GraphDef> = Extract<keyof G["edges"], string>;
@@ -1,11 +1,11 @@
1
- import { d as GraphDef } from '../types-DKkMJZjR.js';
2
- export { C as ContributionDiagnostic, a as ContributionDiagnosticState, b as ContributionRepairEntry, c as ContributionRepairResult } from '../types-DKkMJZjR.js';
3
- import { b as HistoryStore } from '../store-5j-w5onJ.js';
1
+ import { d8 as GraphDef } from '../types-BqFZTQmV.js';
2
+ export { u as ContributionDiagnostic, v as ContributionDiagnosticState, J as ContributionRepairEntry, K as ContributionRepairResult } from '../types-BqFZTQmV.js';
3
+ import { b as HistoryStore } from '../store-UzrGvZOo.js';
4
4
  import 'zod';
5
- import '../temporal-CjO9FH1l.js';
6
- import '../searchable-D9gMiwcS.js';
7
- import '../manager-B6sOQzcQ.js';
8
- import '../materialize-indexes-DQL4xcpf.js';
5
+ import '../temporal-CbnLzTmM.js';
6
+ import '../searchable-bpE1bBfc.js';
7
+ import '../manager-D9eRT_ns.js';
8
+ import '../materialize-indexes-DJ3ykH59.js';
9
9
 
10
10
  type NodeKind<G extends GraphDef> = Extract<keyof G["nodes"], string>;
11
11
  type EdgeKind<G extends GraphDef> = Extract<keyof G["edges"], string>;
@@ -1,11 +1,11 @@
1
- import { transactionBackend, transactionNodeOperationHookRunner, applyNodeSoftDelete, createNodeWriteContext, applyNodeResurrect } from '../chunk-FNOMT74T.js';
2
- import { lockRecordedGraphWrite, compareStrings } from '../chunk-AVGUJWVX.js';
3
- import '../chunk-NAZ2RA4L.js';
1
+ import { transactionBackend, transactionNodeOperationHookRunner, applyNodeSoftDelete, createNodeWriteContext, applyNodeResurrect } from '../chunk-I4GAZH5Z.js';
2
+ import { lockRecordedGraphWrite, compareStrings } from '../chunk-S5TERQVW.js';
3
+ import '../chunk-UGHG7PGX.js';
4
4
  import '../chunk-NVY5CJFP.js';
5
- import { rowPropsToObject, isLiveNodeRow, isTombstonedNodeRow } from '../chunk-SHSSRCFR.js';
5
+ import { rowPropsToObject, isLiveNodeRow, isTombstonedNodeRow } from '../chunk-6LN7FIVU.js';
6
6
  import '../chunk-GLHXM7C4.js';
7
- import '../chunk-XY5OMOJD.js';
8
- import { nowIso } from '../chunk-NG2RB5WL.js';
7
+ import '../chunk-DZAICA5J.js';
8
+ import { nowIso, validityWindowContainsInstant } from '../chunk-5K2BKEBD.js';
9
9
  import '../chunk-2EBMPJBO.js';
10
10
  import '../chunk-3DMMGT6S.js';
11
11
  import '../chunk-W6OG3HDG.js';
@@ -196,9 +196,6 @@ function assertEdgeEndpoints(graph, edgeKind, expected) {
196
196
  );
197
197
  }
198
198
  }
199
- function isValidAt(row, asOf) {
200
- return (row.valid_from === void 0 || row.valid_from <= asOf) && (row.valid_to === void 0 || row.valid_to > asOf);
201
- }
202
199
  async function findNodeRows(backend, graphId, kind, options) {
203
200
  if (options.includeTombstones) {
204
201
  const rows = await backend.findNodesByKind({
@@ -208,7 +205,9 @@ async function findNodeRows(backend, graphId, kind, options) {
208
205
  temporalMode: "includeTombstones",
209
206
  orderBy: "id"
210
207
  });
211
- return rows.filter((row) => isValidAt(row, options.asOf));
208
+ return rows.filter(
209
+ (row) => validityWindowContainsInstant(row.valid_from, row.valid_to, options.asOf)
210
+ );
212
211
  }
213
212
  return backend.findNodesByKind({
214
213
  graphId,