@nicia-ai/typegraph 0.46.2 → 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 (310) hide show
  1. package/README.md +20 -1
  2. package/dist/backend/drizzle/indexes.cjs +9 -9
  3. package/dist/backend/drizzle/indexes.d.cts +1 -1
  4. package/dist/backend/drizzle/indexes.d.ts +1 -1
  5. package/dist/backend/drizzle/indexes.js +5 -5
  6. package/dist/backend/index.cjs +58 -49
  7. package/dist/backend/index.d.cts +37 -55
  8. package/dist/backend/index.d.ts +37 -55
  9. package/dist/backend/index.js +11 -10
  10. package/dist/backend/postgres/index.cjs +27 -26
  11. package/dist/backend/postgres/index.d.cts +21 -7
  12. package/dist/backend/postgres/index.d.ts +21 -7
  13. package/dist/backend/postgres/index.js +14 -13
  14. package/dist/backend/postgres/pglite-store.cjs +34 -33
  15. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  16. package/dist/backend/postgres/pglite-store.d.cts +8 -8
  17. package/dist/backend/postgres/pglite-store.d.ts +8 -8
  18. package/dist/backend/postgres/pglite-store.js +30 -29
  19. package/dist/backend/postgres/pglite-store.js.map +1 -1
  20. package/dist/backend/postgres/pglite.cjs +16 -15
  21. package/dist/backend/postgres/pglite.d.cts +3 -3
  22. package/dist/backend/postgres/pglite.d.ts +3 -3
  23. package/dist/backend/postgres/pglite.js +15 -14
  24. package/dist/backend/sqlite/index.cjs +24 -23
  25. package/dist/backend/sqlite/index.d.cts +20 -7
  26. package/dist/backend/sqlite/index.d.ts +20 -7
  27. package/dist/backend/sqlite/index.js +12 -11
  28. package/dist/backend/sqlite/libsql.cjs +19 -18
  29. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  30. package/dist/backend/sqlite/libsql.d.cts +3 -3
  31. package/dist/backend/sqlite/libsql.d.ts +3 -3
  32. package/dist/backend/sqlite/libsql.js +14 -13
  33. package/dist/backend/sqlite/libsql.js.map +1 -1
  34. package/dist/backend/sqlite/local-store.cjs +35 -34
  35. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  36. package/dist/backend/sqlite/local-store.d.cts +8 -8
  37. package/dist/backend/sqlite/local-store.d.ts +8 -8
  38. package/dist/backend/sqlite/local-store.js +31 -30
  39. package/dist/backend/sqlite/local-store.js.map +1 -1
  40. package/dist/backend/sqlite/local.cjs +17 -16
  41. package/dist/backend/sqlite/local.d.cts +3 -3
  42. package/dist/backend/sqlite/local.d.ts +3 -3
  43. package/dist/backend/sqlite/local.js +15 -14
  44. package/dist/{chunk-TCT66A7N.cjs → chunk-26YKDNUD.cjs} +10 -10
  45. package/dist/{chunk-TCT66A7N.cjs.map → chunk-26YKDNUD.cjs.map} +1 -1
  46. package/dist/{chunk-E4OSGBCM.cjs → chunk-2HIYYMWY.cjs} +139 -136
  47. package/dist/chunk-2HIYYMWY.cjs.map +1 -0
  48. package/dist/chunk-2QGYQBS2.cjs +161 -0
  49. package/dist/chunk-2QGYQBS2.cjs.map +1 -0
  50. package/dist/{chunk-GWXXHOLU.js → chunk-2SYZXD54.js} +21 -18
  51. package/dist/chunk-2SYZXD54.js.map +1 -0
  52. package/dist/{chunk-KA4L2NZ3.js → chunk-2TYSSBU5.js} +14 -14
  53. package/dist/{chunk-KA4L2NZ3.js.map → chunk-2TYSSBU5.js.map} +1 -1
  54. package/dist/{chunk-QOJ2L2AD.js → chunk-3DMMGT6S.js} +3 -3
  55. package/dist/{chunk-QOJ2L2AD.js.map → chunk-3DMMGT6S.js.map} +1 -1
  56. package/dist/{chunk-F36KZDFX.cjs → chunk-3FPR224C.cjs} +91 -91
  57. package/dist/{chunk-F36KZDFX.cjs.map → chunk-3FPR224C.cjs.map} +1 -1
  58. package/dist/{chunk-32UETY6S.cjs → chunk-3KOY4FH3.cjs} +207 -28
  59. package/dist/chunk-3KOY4FH3.cjs.map +1 -0
  60. package/dist/{chunk-QU7QLJA4.cjs → chunk-3U5ABFDW.cjs} +26 -26
  61. package/dist/{chunk-QU7QLJA4.cjs.map → chunk-3U5ABFDW.cjs.map} +1 -1
  62. package/dist/{chunk-RFDEYLIK.js → chunk-4WMMBDS5.js} +7 -7
  63. package/dist/chunk-4WMMBDS5.js.map +1 -0
  64. package/dist/{chunk-R7EWHKID.js → chunk-5K2BKEBD.js} +19 -145
  65. package/dist/chunk-5K2BKEBD.js.map +1 -0
  66. package/dist/chunk-5PRKMB24.cjs +124 -0
  67. package/dist/chunk-5PRKMB24.cjs.map +1 -0
  68. package/dist/chunk-6LN7FIVU.js +107 -0
  69. package/dist/chunk-6LN7FIVU.js.map +1 -0
  70. package/dist/{chunk-D6GCNNMK.cjs → chunk-6NGW27EO.cjs} +10 -10
  71. package/dist/{chunk-D6GCNNMK.cjs.map → chunk-6NGW27EO.cjs.map} +1 -1
  72. package/dist/{chunk-WHS2Y43J.js → chunk-6SWPJEYN.js} +5 -5
  73. package/dist/{chunk-WHS2Y43J.js.map → chunk-6SWPJEYN.js.map} +1 -1
  74. package/dist/{chunk-7TKNK32B.js → chunk-7SQSZN2J.js} +5 -5
  75. package/dist/{chunk-7TKNK32B.js.map → chunk-7SQSZN2J.js.map} +1 -1
  76. package/dist/{chunk-UTVQPZPN.cjs → chunk-7XUYFFR4.cjs} +20 -20
  77. package/dist/chunk-7XUYFFR4.cjs.map +1 -0
  78. package/dist/{chunk-KXSMF6PL.js → chunk-ACGSAMD3.js} +39 -34
  79. package/dist/chunk-ACGSAMD3.js.map +1 -0
  80. package/dist/{chunk-PYKF7UIL.cjs → chunk-AOSSQDVO.cjs} +13 -13
  81. package/dist/{chunk-PYKF7UIL.cjs.map → chunk-AOSSQDVO.cjs.map} +1 -1
  82. package/dist/{chunk-AT3MLMJV.js → chunk-AX6JGVTZ.js} +91 -20
  83. package/dist/chunk-AX6JGVTZ.js.map +1 -0
  84. package/dist/{chunk-WA64ZSCA.cjs → chunk-BFUOME67.cjs} +11 -11
  85. package/dist/{chunk-WA64ZSCA.cjs.map → chunk-BFUOME67.cjs.map} +1 -1
  86. package/dist/{chunk-YQ4JONWE.js → chunk-BRRP76WO.js} +401 -131
  87. package/dist/chunk-BRRP76WO.js.map +1 -0
  88. package/dist/{chunk-FCIZNUW5.js → chunk-CHAOFCHV.js} +3 -3
  89. package/dist/{chunk-FCIZNUW5.js.map → chunk-CHAOFCHV.js.map} +1 -1
  90. package/dist/chunk-CICO5GXD.cjs +12 -0
  91. package/dist/{chunk-73MWKDFK.cjs.map → chunk-CICO5GXD.cjs.map} +1 -1
  92. package/dist/{chunk-S3G5VLSW.js → chunk-CT3ZKTOF.js} +7 -6
  93. package/dist/chunk-CT3ZKTOF.js.map +1 -0
  94. package/dist/{chunk-SXWLLQ3D.js → chunk-D5R42W5D.js} +4 -4
  95. package/dist/{chunk-SXWLLQ3D.js.map → chunk-D5R42W5D.js.map} +1 -1
  96. package/dist/{chunk-BZZI7B43.cjs → chunk-DO7SAMEK.cjs} +47 -47
  97. package/dist/{chunk-BZZI7B43.cjs.map → chunk-DO7SAMEK.cjs.map} +1 -1
  98. package/dist/chunk-DZAICA5J.js +147 -0
  99. package/dist/chunk-DZAICA5J.js.map +1 -0
  100. package/dist/{chunk-2ZWM2RFH.cjs → chunk-EDN4Y4ZG.cjs} +9 -9
  101. package/dist/{chunk-2ZWM2RFH.cjs.map → chunk-EDN4Y4ZG.cjs.map} +1 -1
  102. package/dist/{chunk-A4R3H7RU.cjs → chunk-EZEEWCFJ.cjs} +264 -361
  103. package/dist/chunk-EZEEWCFJ.cjs.map +1 -0
  104. package/dist/{chunk-BEB4OFZF.cjs → chunk-FA2AFWLP.cjs} +51 -59
  105. package/dist/chunk-FA2AFWLP.cjs.map +1 -0
  106. package/dist/{chunk-ZBVZ7HXD.cjs → chunk-FQPEMEWX.cjs} +12 -12
  107. package/dist/{chunk-ZBVZ7HXD.cjs.map → chunk-FQPEMEWX.cjs.map} +1 -1
  108. package/dist/{chunk-LNIWCQR4.js → chunk-GLHXM7C4.js} +3 -3
  109. package/dist/{chunk-LNIWCQR4.js.map → chunk-GLHXM7C4.js.map} +1 -1
  110. package/dist/{chunk-6BD6ZBKT.cjs → chunk-GYEG3ZLZ.cjs} +10 -10
  111. package/dist/{chunk-6BD6ZBKT.cjs.map → chunk-GYEG3ZLZ.cjs.map} +1 -1
  112. package/dist/{chunk-A7NMUYEL.cjs → chunk-HDL2ARHX.cjs} +27 -27
  113. package/dist/{chunk-A7NMUYEL.cjs.map → chunk-HDL2ARHX.cjs.map} +1 -1
  114. package/dist/{chunk-5ZJOB5YS.js → chunk-HEV35TGT.js} +4 -4
  115. package/dist/{chunk-5ZJOB5YS.js.map → chunk-HEV35TGT.js.map} +1 -1
  116. package/dist/{chunk-LHYSY6SE.js → chunk-I4GAZH5Z.js} +186 -9
  117. package/dist/chunk-I4GAZH5Z.js.map +1 -0
  118. package/dist/{chunk-BQM5P2NO.cjs → chunk-JB6T4GLL.cjs} +260 -223
  119. package/dist/chunk-JB6T4GLL.cjs.map +1 -0
  120. package/dist/{chunk-QPOQX2DI.cjs → chunk-JFRT7S3B.cjs} +1026 -369
  121. package/dist/chunk-JFRT7S3B.cjs.map +1 -0
  122. package/dist/{chunk-JCNTKRAK.js → chunk-JONXFAPO.js} +5 -5
  123. package/dist/{chunk-JCNTKRAK.js.map → chunk-JONXFAPO.js.map} +1 -1
  124. package/dist/{chunk-WEJHA7AD.js → chunk-KF6K7TGH.js} +109 -75
  125. package/dist/chunk-KF6K7TGH.js.map +1 -0
  126. package/dist/{chunk-EDJDDY6H.js → chunk-KKBDXCLQ.js} +4 -4
  127. package/dist/{chunk-EDJDDY6H.js.map → chunk-KKBDXCLQ.js.map} +1 -1
  128. package/dist/{chunk-ZHOAZD7Q.cjs → chunk-L3LQNR34.cjs} +161 -161
  129. package/dist/{chunk-ZHOAZD7Q.cjs.map → chunk-L3LQNR34.cjs.map} +1 -1
  130. package/dist/{chunk-AF3TWL5C.cjs → chunk-LRQKXRXO.cjs} +4 -4
  131. package/dist/{chunk-AF3TWL5C.cjs.map → chunk-LRQKXRXO.cjs.map} +1 -1
  132. package/dist/chunk-MKJ4KXL5.cjs +12 -0
  133. package/dist/{chunk-6LAXM4J2.cjs.map → chunk-MKJ4KXL5.cjs.map} +1 -1
  134. package/dist/{chunk-KCH7WQA5.cjs → chunk-MRDBBHIZ.cjs} +48 -2
  135. package/dist/chunk-MRDBBHIZ.cjs.map +1 -0
  136. package/dist/{chunk-FXNHZFZV.js → chunk-MYKHJI2J.js} +3 -3
  137. package/dist/{chunk-FXNHZFZV.js.map → chunk-MYKHJI2J.js.map} +1 -1
  138. package/dist/{chunk-Z43KWLZF.js → chunk-NACVVDWB.js} +213 -12
  139. package/dist/chunk-NACVVDWB.js.map +1 -0
  140. package/dist/{chunk-72WUT4GG.js → chunk-NVY5CJFP.js} +4 -4
  141. package/dist/{chunk-72WUT4GG.js.map → chunk-NVY5CJFP.js.map} +1 -1
  142. package/dist/{chunk-WYFB7BN3.js → chunk-OD4SSY2U.js} +166 -48
  143. package/dist/chunk-OD4SSY2U.js.map +1 -0
  144. package/dist/{chunk-ZIH42CRX.cjs → chunk-OI2GQ25X.cjs} +7 -7
  145. package/dist/{chunk-ZIH42CRX.cjs.map → chunk-OI2GQ25X.cjs.map} +1 -1
  146. package/dist/{chunk-AU3IJNNP.js → chunk-OMZ37BM2.js} +5 -5
  147. package/dist/{chunk-AU3IJNNP.js.map → chunk-OMZ37BM2.js.map} +1 -1
  148. package/dist/{chunk-C4DYN2SD.cjs → chunk-OORXGFL5.cjs} +48 -48
  149. package/dist/{chunk-C4DYN2SD.cjs.map → chunk-OORXGFL5.cjs.map} +1 -1
  150. package/dist/{chunk-HNYLMPQQ.cjs → chunk-OTUPEF2W.cjs} +149 -78
  151. package/dist/chunk-OTUPEF2W.cjs.map +1 -0
  152. package/dist/{chunk-BRN3RGD2.js → chunk-OVI7IXYX.js} +3 -3
  153. package/dist/{chunk-BRN3RGD2.js.map → chunk-OVI7IXYX.js.map} +1 -1
  154. package/dist/{chunk-WMKEGJG4.js → chunk-P6YLZTRE.js} +3 -3
  155. package/dist/{chunk-WMKEGJG4.js.map → chunk-P6YLZTRE.js.map} +1 -1
  156. package/dist/{chunk-C2ZP5YS6.cjs → chunk-PFBRJBUL.cjs} +278 -160
  157. package/dist/chunk-PFBRJBUL.cjs.map +1 -0
  158. package/dist/{chunk-EJSYWAEV.js → chunk-QTD6HX4O.js} +5 -5
  159. package/dist/{chunk-EJSYWAEV.js.map → chunk-QTD6HX4O.js.map} +1 -1
  160. package/dist/{chunk-JL5UEBWT.cjs → chunk-ROR5ZR6A.cjs} +45 -45
  161. package/dist/{chunk-JL5UEBWT.cjs.map → chunk-ROR5ZR6A.cjs.map} +1 -1
  162. package/dist/{chunk-EDHV4CBU.js → chunk-S5TERQVW.js} +37 -134
  163. package/dist/chunk-S5TERQVW.js.map +1 -0
  164. package/dist/{chunk-FSLTU57P.js → chunk-SDBBMD4N.js} +3 -3
  165. package/dist/{chunk-FSLTU57P.js.map → chunk-SDBBMD4N.js.map} +1 -1
  166. package/dist/{chunk-36LIJXWC.js → chunk-SHFBB23Q.js} +4 -4
  167. package/dist/{chunk-36LIJXWC.js.map → chunk-SHFBB23Q.js.map} +1 -1
  168. package/dist/chunk-SIT26LAZ.cjs +614 -0
  169. package/dist/chunk-SIT26LAZ.cjs.map +1 -0
  170. package/dist/{chunk-C6KE2HSQ.cjs → chunk-SR725PWF.cjs} +1662 -1392
  171. package/dist/chunk-SR725PWF.cjs.map +1 -0
  172. package/dist/{chunk-S7WIRFNS.cjs → chunk-TKZXMWQF.cjs} +13 -12
  173. package/dist/chunk-TKZXMWQF.cjs.map +1 -0
  174. package/dist/{chunk-5PDSCELM.cjs → chunk-TQHGE7UC.cjs} +29 -164
  175. package/dist/chunk-TQHGE7UC.cjs.map +1 -0
  176. package/dist/{chunk-XBHRKLZU.cjs → chunk-TUNPBZY3.cjs} +4 -4
  177. package/dist/{chunk-XBHRKLZU.cjs.map → chunk-TUNPBZY3.cjs.map} +1 -1
  178. package/dist/{chunk-KOAI3KIV.cjs → chunk-TZEGUG6D.cjs} +4 -4
  179. package/dist/{chunk-KOAI3KIV.cjs.map → chunk-TZEGUG6D.cjs.map} +1 -1
  180. package/dist/chunk-UGHG7PGX.js +592 -0
  181. package/dist/chunk-UGHG7PGX.js.map +1 -0
  182. package/dist/{chunk-N3QTGPC7.cjs → chunk-UMGZDVOA.cjs} +303 -101
  183. package/dist/chunk-UMGZDVOA.cjs.map +1 -0
  184. package/dist/{chunk-RHDOAQCT.cjs → chunk-WCCATHMB.cjs} +140 -135
  185. package/dist/chunk-WCCATHMB.cjs.map +1 -0
  186. package/dist/{chunk-DYPRZ53S.cjs → chunk-WODMN3Q2.cjs} +27 -27
  187. package/dist/{chunk-DYPRZ53S.cjs.map → chunk-WODMN3Q2.cjs.map} +1 -1
  188. package/dist/{chunk-OZJCH7ZS.js → chunk-XVWOYKIK.js} +3 -3
  189. package/dist/{chunk-OZJCH7ZS.js.map → chunk-XVWOYKIK.js.map} +1 -1
  190. package/dist/{chunk-IHRDX7K6.js → chunk-YIURNGXI.js} +46 -56
  191. package/dist/chunk-YIURNGXI.js.map +1 -0
  192. package/dist/{chunk-GWUWRZXW.js → chunk-YVF2EM7B.js} +3 -3
  193. package/dist/{chunk-GWUWRZXW.js.map → chunk-YVF2EM7B.js.map} +1 -1
  194. package/dist/{chunk-EAMVXR5B.js → chunk-ZDKTPBGV.js} +4 -4
  195. package/dist/{chunk-EAMVXR5B.js.map → chunk-ZDKTPBGV.js.map} +1 -1
  196. package/dist/{chunk-A2LJG5GM.js → chunk-ZFMCDJGB.js} +803 -148
  197. package/dist/chunk-ZFMCDJGB.js.map +1 -0
  198. package/dist/{chunk-62ZXBMSD.js → chunk-ZLONH2UD.js} +46 -3
  199. package/dist/chunk-ZLONH2UD.js.map +1 -0
  200. package/dist/core/index.cjs +28 -27
  201. package/dist/core/index.d.cts +4 -4
  202. package/dist/core/index.d.ts +4 -4
  203. package/dist/core/index.js +8 -7
  204. package/dist/ddl-BL1NZLMY.d.cts +78 -0
  205. package/dist/ddl-D_oW-EVO.d.ts +78 -0
  206. package/dist/graph-extension/index.cjs +20 -20
  207. package/dist/graph-extension/index.d.cts +4 -4
  208. package/dist/graph-extension/index.d.ts +4 -4
  209. package/dist/graph-extension/index.js +4 -4
  210. package/dist/graph-merge/index.cjs +3418 -706
  211. package/dist/graph-merge/index.cjs.map +1 -1
  212. package/dist/graph-merge/index.d.cts +550 -58
  213. package/dist/graph-merge/index.d.ts +550 -58
  214. package/dist/graph-merge/index.js +3191 -497
  215. package/dist/graph-merge/index.js.map +1 -1
  216. package/dist/{index-Deyu8IXL.d.ts → index-COs_z6nV.d.cts} +47 -3
  217. package/dist/{index-DrRS51Ld.d.cts → index-D7d1u2gr.d.ts} +47 -3
  218. package/dist/index.cjs +233 -216
  219. package/dist/index.cjs.map +1 -1
  220. package/dist/index.d.cts +12 -12
  221. package/dist/index.d.ts +12 -12
  222. package/dist/index.js +35 -34
  223. package/dist/index.js.map +1 -1
  224. package/dist/indexes/index.cjs +13 -13
  225. package/dist/indexes/index.d.cts +4 -4
  226. package/dist/indexes/index.d.ts +4 -4
  227. package/dist/indexes/index.js +6 -6
  228. package/dist/interchange/index.cjs +53 -52
  229. package/dist/interchange/index.cjs.map +1 -1
  230. package/dist/interchange/index.d.cts +17 -13
  231. package/dist/interchange/index.d.ts +17 -13
  232. package/dist/interchange/index.js +17 -16
  233. package/dist/interchange/index.js.map +1 -1
  234. package/dist/{manager-ptr3JLRP.d.cts → manager-CYaff3n3.d.cts} +2 -2
  235. package/dist/{manager-DX983gJ0.d.ts → manager-D9eRT_ns.d.ts} +2 -2
  236. package/dist/{materialize-indexes-CpXoggWU.d.ts → materialize-indexes-DJ3ykH59.d.ts} +1 -1
  237. package/dist/{materialize-indexes-BXz77YqO.d.cts → materialize-indexes-DTtAnvfY.d.cts} +1 -1
  238. package/dist/{postgres-DwgEXSPI.d.cts → postgres-CcL4bAHS.d.ts} +1 -1
  239. package/dist/{postgres-QdOMHTBz.d.ts → postgres-DMj39MEu.d.cts} +1 -1
  240. package/dist/profiler/index.d.cts +9 -9
  241. package/dist/profiler/index.d.ts +9 -9
  242. package/dist/provenance/index.cjs +46 -46
  243. package/dist/provenance/index.cjs.map +1 -1
  244. package/dist/provenance/index.d.cts +7 -7
  245. package/dist/provenance/index.d.ts +7 -7
  246. package/dist/provenance/index.js +13 -13
  247. package/dist/provenance/index.js.map +1 -1
  248. package/dist/repair-validity-windows-BFNZvd_H.d.cts +166 -0
  249. package/dist/repair-validity-windows-DlUSqwCg.d.ts +166 -0
  250. package/dist/schema/index.cjs +45 -44
  251. package/dist/schema/index.d.cts +6 -6
  252. package/dist/schema/index.d.ts +6 -6
  253. package/dist/schema/index.js +18 -17
  254. package/dist/{searchable-BOUuA83f.d.ts → searchable-DHJMh_nj.d.cts} +1 -1
  255. package/dist/{searchable-BrUh0pdc.d.cts → searchable-bpE1bBfc.d.ts} +1 -1
  256. package/dist/{sqlite-BfYcV61E.d.cts → sqlite-D7Oz0SQh.d.ts} +1 -1
  257. package/dist/{sqlite-DK40XVR1.d.ts → sqlite-YppHrNFb.d.cts} +1 -1
  258. package/dist/{store-FTqBpuJD.d.cts → store-JUVvtmR4.d.cts} +228 -92
  259. package/dist/{store-Bo1psfVZ.d.ts → store-UzrGvZOo.d.ts} +228 -92
  260. package/dist/{temporal-DPtn0HOu.d.ts → temporal-5GqpYCk2.d.cts} +1 -1
  261. package/dist/{temporal-CXewwLTB.d.cts → temporal-CbnLzTmM.d.ts} +1 -1
  262. package/dist/{types-Du78EvpN.d.ts → types-BqFZTQmV.d.cts} +60 -9
  263. package/dist/{types-Du78EvpN.d.cts → types-BqFZTQmV.d.ts} +60 -9
  264. package/dist/{types-CeT7xM4M.d.ts → types-Bx74kaTt.d.ts} +1 -1
  265. package/dist/{types-XR1nHERK.d.cts → types-CXAhpW-c.d.cts} +1 -1
  266. package/dist/{where-CJsp-YUf.d.cts → where-DI_Fqz-X.d.cts} +1 -1
  267. package/dist/{where-CMbFiWwp.d.ts → where-O-k2wgYm.d.ts} +1 -1
  268. package/package.json +1 -1
  269. package/dist/chunk-32UETY6S.cjs.map +0 -1
  270. package/dist/chunk-5PDSCELM.cjs.map +0 -1
  271. package/dist/chunk-62ZXBMSD.js.map +0 -1
  272. package/dist/chunk-6LAXM4J2.cjs +0 -12
  273. package/dist/chunk-73MWKDFK.cjs +0 -12
  274. package/dist/chunk-A2LJG5GM.js.map +0 -1
  275. package/dist/chunk-A4R3H7RU.cjs.map +0 -1
  276. package/dist/chunk-ANKOXPCC.cjs +0 -267
  277. package/dist/chunk-ANKOXPCC.cjs.map +0 -1
  278. package/dist/chunk-AT3MLMJV.js.map +0 -1
  279. package/dist/chunk-BEB4OFZF.cjs.map +0 -1
  280. package/dist/chunk-BQM5P2NO.cjs.map +0 -1
  281. package/dist/chunk-C2ZP5YS6.cjs.map +0 -1
  282. package/dist/chunk-C6KE2HSQ.cjs.map +0 -1
  283. package/dist/chunk-DSAWGCMP.js +0 -254
  284. package/dist/chunk-DSAWGCMP.js.map +0 -1
  285. package/dist/chunk-E4OSGBCM.cjs.map +0 -1
  286. package/dist/chunk-EDHV4CBU.js.map +0 -1
  287. package/dist/chunk-FA6Z7B5L.js +0 -244
  288. package/dist/chunk-FA6Z7B5L.js.map +0 -1
  289. package/dist/chunk-GVAMRRZR.cjs +0 -268
  290. package/dist/chunk-GVAMRRZR.cjs.map +0 -1
  291. package/dist/chunk-GWXXHOLU.js.map +0 -1
  292. package/dist/chunk-HNYLMPQQ.cjs.map +0 -1
  293. package/dist/chunk-IHRDX7K6.js.map +0 -1
  294. package/dist/chunk-KCH7WQA5.cjs.map +0 -1
  295. package/dist/chunk-KXSMF6PL.js.map +0 -1
  296. package/dist/chunk-LHYSY6SE.js.map +0 -1
  297. package/dist/chunk-N3QTGPC7.cjs.map +0 -1
  298. package/dist/chunk-QPOQX2DI.cjs.map +0 -1
  299. package/dist/chunk-R7EWHKID.js.map +0 -1
  300. package/dist/chunk-RFDEYLIK.js.map +0 -1
  301. package/dist/chunk-RHDOAQCT.cjs.map +0 -1
  302. package/dist/chunk-S3G5VLSW.js.map +0 -1
  303. package/dist/chunk-S7WIRFNS.cjs.map +0 -1
  304. package/dist/chunk-UTVQPZPN.cjs.map +0 -1
  305. package/dist/chunk-WEJHA7AD.js.map +0 -1
  306. package/dist/chunk-WYFB7BN3.js.map +0 -1
  307. package/dist/chunk-YQ4JONWE.js.map +0 -1
  308. package/dist/chunk-Z43KWLZF.js.map +0 -1
  309. package/dist/ddl-mE07h_EM.d.cts +0 -38
  310. package/dist/ddl-opIn8DfX.d.ts +0 -38
@@ -1,10 +1,10 @@
1
- import { advanceRevisionClock, lockRecordedGraphWrite, uncapturedGraphWriteLock, identityAssertionSnapshotSource, identitySqlCoordinate, IDENTITY_ASSERTION_COLUMNS, compareCodePoints, withRecordedIdentityMutationTarget, recordedBindParamBudget, identityNodeVisibilitySql, historicalIdentityReconstructionCtes, generateId, identityNodeSnapshotSource } from './chunk-EDHV4CBU.js';
2
- import { chunk, isSqliteStaleSnapshotError, isMissingTableError } from './chunk-DSAWGCMP.js';
3
- import { runOptionallyInTransaction } from './chunk-FA6Z7B5L.js';
4
- import { nowIso, canonicalizeDatabaseTimestamp } from './chunk-R7EWHKID.js';
5
- import { getDialect } from './chunk-EAMVXR5B.js';
6
- import { asCompiledRowsSql, sql, asCompiledStatementSql } from './chunk-QOJ2L2AD.js';
7
- import { ValidationError, ConfigurationError, NodeNotFoundError, KindNotFoundError, IdentityContradictionError, IdentitySeparationViolationError } from './chunk-62ZXBMSD.js';
1
+ import { encodeTupleKey, advanceRevisionClock, lockRecordedGraphWrite, uncapturedGraphWriteLock, identityAssertionSnapshotSource, identitySqlCoordinate, IDENTITY_ASSERTION_COLUMNS, compareCodePoints, withRecordedIdentityMutationTarget, recordedBindParamBudget, identityNodeVisibilitySql, historicalIdentityReconstructionCtes, generateId, identityNodeSnapshotSource } from './chunk-S5TERQVW.js';
2
+ import { chunk, isSqliteStaleSnapshotError, isMissingTableError } from './chunk-UGHG7PGX.js';
3
+ import { runOptionallyInTransaction } from './chunk-6LN7FIVU.js';
4
+ import { nowIso, canonicalizeDatabaseTimestamp, validateOptionalCanonicalIsoDate } from './chunk-5K2BKEBD.js';
5
+ import { getDialect } from './chunk-ZDKTPBGV.js';
6
+ import { asCompiledRowsSql, sql, asCompiledStatementSql } from './chunk-3DMMGT6S.js';
7
+ import { ValidationError, ConfigurationError, IdentityEndpointValidityError, NodeNotFoundError, KindNotFoundError, IdentityValidityWindowError, IdentityContradictionError, IdentitySeparationViolationError } from './chunk-ZLONH2UD.js';
8
8
  import { requireDefined } from './chunk-DYATYRY4.js';
9
9
 
10
10
  // src/errors/validation.ts
@@ -79,11 +79,6 @@ function createValidationError(message, issues, context) {
79
79
  });
80
80
  }
81
81
 
82
- // src/utils/tuple-key.ts
83
- function encodeTupleKey(values) {
84
- return JSON.stringify(values);
85
- }
86
-
87
82
  // src/identity/row-codec.ts
88
83
  function toCanonicalIdentityTimestamp(value) {
89
84
  const canonical = canonicalizeDatabaseTimestamp(value);
@@ -684,6 +679,12 @@ async function readIdentityAssertionsForInterchange(ctx, mode, options) {
684
679
 
685
680
  // src/store/operations/write-transaction.ts
686
681
  var writeTransactionSessions = /* @__PURE__ */ new WeakMap();
682
+ function forceWriteTransactionRevision(target) {
683
+ const session = writeTransactionSessions.get(target);
684
+ if (session === void 0) return false;
685
+ session.wrote = true;
686
+ return true;
687
+ }
687
688
  var heldGraphWriteLocks = /* @__PURE__ */ new WeakMap();
688
689
  async function withWriteTransactionSession(target, ctx, fn) {
689
690
  const session = {
@@ -1490,6 +1491,51 @@ function separationMismatchError(graphId, detail) {
1490
1491
  );
1491
1492
  }
1492
1493
 
1494
+ // src/identity/validity-window.ts
1495
+ function hasExplicitIdentityValidityWindow(window) {
1496
+ return window?.validFrom !== void 0 || window?.validTo !== void 0;
1497
+ }
1498
+ function resolveIdentityValidityWindow(window, operationInstant) {
1499
+ const validFrom = validateOptionalCanonicalIsoDate(window?.validFrom, "validFrom") ?? operationInstant;
1500
+ const validTo = validateOptionalCanonicalIsoDate(window?.validTo, "validTo");
1501
+ if (compareCodePoints(validFrom, operationInstant) > 0) {
1502
+ throw new IdentityValidityWindowError({
1503
+ reason: "future-valid-from",
1504
+ validFrom,
1505
+ ...validTo === void 0 ? {} : { validTo },
1506
+ operationInstant
1507
+ });
1508
+ }
1509
+ if (validTo !== void 0 && compareCodePoints(validTo, operationInstant) > 0) {
1510
+ throw new IdentityValidityWindowError({
1511
+ reason: "future-valid-to",
1512
+ validFrom,
1513
+ validTo,
1514
+ operationInstant
1515
+ });
1516
+ }
1517
+ if (validTo !== void 0 && compareCodePoints(validTo, validFrom) < 0) {
1518
+ throw new IdentityValidityWindowError({
1519
+ reason: "inverted",
1520
+ validFrom,
1521
+ validTo,
1522
+ operationInstant
1523
+ });
1524
+ }
1525
+ const effective = validTo === validFrom ? "empty" : validTo === void 0 ? "current" : "historical";
1526
+ return {
1527
+ validFrom,
1528
+ ...validTo === void 0 ? {} : { validTo },
1529
+ effective
1530
+ };
1531
+ }
1532
+ function identityValidityWindowsOverlap(left, right) {
1533
+ if (left.validFrom === left.validTo || right.validFrom === right.validTo) {
1534
+ return false;
1535
+ }
1536
+ return (right.validTo === void 0 || left.validFrom < right.validTo) && (left.validTo === void 0 || right.validFrom < left.validTo);
1537
+ }
1538
+
1493
1539
  // src/identity/service-mutation.ts
1494
1540
  async function validateCurrentRelation(ctx, target, relation, operation, a, b) {
1495
1541
  const classes = await loadCurrentStructuralClasses(
@@ -1557,23 +1603,50 @@ async function currentAssertionForPair(target, schema, graphId, relation, a, b)
1557
1603
  );
1558
1604
  return rows[0] === void 0 ? void 0 : normalizeIdentityAssertionRow(rows[0]);
1559
1605
  }
1560
- async function insertAssertion(target, schema, graphId, relation, a, b, timestamp, touch, preserved) {
1561
- const row = buildAssertionRow(graphId, relation, a, b, timestamp, preserved);
1606
+ async function assertionForExactWindow(target, schema, graphId, relation, a, b, window) {
1607
+ const validToMatch = window.validTo === void 0 ? sql`valid_to IS NULL` : sql`valid_to = ${window.validTo}`;
1608
+ const rows = await target.execute(
1609
+ asCompiledRowsSql(sql`
1610
+ SELECT ${IDENTITY_ASSERTION_COLUMNS}
1611
+ FROM ${schema.identityAssertionsTable}
1612
+ WHERE graph_id = ${graphId}
1613
+ AND rel = ${relation}
1614
+ AND a_kind = ${a.kind}
1615
+ AND a_id = ${a.id}
1616
+ AND b_kind = ${b.kind}
1617
+ AND b_id = ${b.id}
1618
+ AND valid_from = ${window.validFrom}
1619
+ AND ${validToMatch}
1620
+ AND deleted_at IS NULL
1621
+ LIMIT 1
1622
+ `)
1623
+ );
1624
+ return rows[0] === void 0 ? void 0 : normalizeIdentityAssertionRow(rows[0]);
1625
+ }
1626
+ async function insertAssertion(target, schema, graphId, relation, a, b, operationInstant, touch, options) {
1627
+ const row = buildAssertionRow(
1628
+ graphId,
1629
+ relation,
1630
+ a,
1631
+ b,
1632
+ operationInstant,
1633
+ options
1634
+ );
1562
1635
  await insertAssertionRows(target, schema, [row]);
1563
1636
  touch(graphId, row.id, row);
1564
1637
  return row;
1565
1638
  }
1566
- function buildAssertionRow(graphId, relation, a, b, timestamp, preserved) {
1639
+ function buildAssertionRow(graphId, relation, a, b, timestamp, options) {
1567
1640
  return {
1568
1641
  graph_id: graphId,
1569
- id: preserved?.id ?? generateId(),
1642
+ id: options?.id ?? generateId(),
1570
1643
  rel: relation,
1571
1644
  a_kind: a.kind,
1572
1645
  a_id: a.id,
1573
1646
  b_kind: b.kind,
1574
1647
  b_id: b.id,
1575
- valid_from: preserved?.validFrom ?? timestamp,
1576
- valid_to: void 0,
1648
+ valid_from: options?.validFrom ?? timestamp,
1649
+ valid_to: options?.validTo,
1577
1650
  created_at: timestamp,
1578
1651
  updated_at: timestamp,
1579
1652
  deleted_at: void 0,
@@ -1581,6 +1654,329 @@ function buildAssertionRow(graphId, relation, a, b, timestamp, preserved) {
1581
1654
  ended_by_id: void 0
1582
1655
  };
1583
1656
  }
1657
+ function canonicalEndpointTimestamp(value) {
1658
+ if (value === void 0 || value === null) return void 0;
1659
+ return canonicalizeDatabaseTimestamp(value);
1660
+ }
1661
+ async function requireEndpointsCoverIdentityWindow(target, graphId, references, window) {
1662
+ for (const ref of references) {
1663
+ const row = await target.getNode(graphId, ref.kind, ref.id);
1664
+ if (row === void 0) throw new NodeNotFoundError(ref.kind, ref.id);
1665
+ if (window.effective === "empty") continue;
1666
+ const validFrom = canonicalEndpointTimestamp(row.valid_from);
1667
+ const validTo = canonicalEndpointTimestamp(row.valid_to);
1668
+ const deletedAt = canonicalEndpointTimestamp(row.deleted_at);
1669
+ const endpointWindow = {
1670
+ ...validFrom === void 0 ? {} : { validFrom },
1671
+ ...validTo === void 0 ? {} : { validTo },
1672
+ ...deletedAt === void 0 ? {} : { deletedAt }
1673
+ };
1674
+ const startsTooLate = endpointWindow.validFrom !== void 0 && endpointWindow.validFrom > window.validFrom;
1675
+ const effectiveEnd = [endpointWindow.validTo, endpointWindow.deletedAt].filter((value) => value !== void 0).toSorted()[0];
1676
+ const endsTooEarly = window.validTo === void 0 ? effectiveEnd !== void 0 : effectiveEnd !== void 0 && effectiveEnd < window.validTo;
1677
+ if (!startsTooLate && !endsTooEarly) continue;
1678
+ throw new IdentityEndpointValidityError({
1679
+ endpoint: ref,
1680
+ assertionWindow: {
1681
+ validFrom: window.validFrom,
1682
+ ...window.validTo === void 0 ? {} : { validTo: window.validTo }
1683
+ },
1684
+ endpointWindow
1685
+ });
1686
+ }
1687
+ }
1688
+ function windowOverlapSql(alias, lowerBoundary, upperBoundary) {
1689
+ const column = (name) => sql`${sql.identifier(alias)}.${sql.identifier(name)}`;
1690
+ return sql`
1691
+ ${column("deleted_at")} IS NULL
1692
+ AND ${column("valid_from")} <= ${upperBoundary}
1693
+ AND (${column("valid_to")} IS NULL OR ${column("valid_to")} > ${lowerBoundary})
1694
+ `;
1695
+ }
1696
+ async function loadIdentityWindowLedger(target, schema, graphId, requests, operationInstant, sameIdAcrossKinds) {
1697
+ const activeRequests = requests.filter(
1698
+ (request) => request.window.effective !== "empty"
1699
+ );
1700
+ if (activeRequests.length === 0) return { nodes: [], assertions: [] };
1701
+ const referencesByKey = /* @__PURE__ */ new Map();
1702
+ for (const request of activeRequests) {
1703
+ for (const reference of request.references) {
1704
+ referencesByKey.set(refKey(reference), reference);
1705
+ }
1706
+ }
1707
+ const references = [...referencesByKey.values()];
1708
+ const lowerBoundary = requireDefined(
1709
+ activeRequests.map((request) => request.window.validFrom).toSorted()[0]
1710
+ );
1711
+ const upperBoundary = requireDefined(
1712
+ activeRequests.map((request) => request.window.validTo ?? operationInstant).toSorted().at(-1)
1713
+ );
1714
+ const seedChunkSize = identityChunkSize(target, {
1715
+ fixedParameters: 20,
1716
+ maxItems: MAX_REFERENCE_CHUNK_SIZE,
1717
+ parametersPerItem: 2
1718
+ });
1719
+ const rows = [];
1720
+ for (const referenceChunk of chunk(references, seedChunkSize)) {
1721
+ const seedRows = sql.join(
1722
+ referenceChunk.map(
1723
+ (reference) => sql`(${reference.kind}, ${reference.id})`
1724
+ ),
1725
+ sql`, `
1726
+ );
1727
+ const component = sameIdAcrossKinds === "fold" ? sql`
1728
+ neighbor_modes(mode) AS (
1729
+ VALUES ('assertion'), ('fold')
1730
+ ),
1731
+ component(kind, id) AS (
1732
+ SELECT seed_kind, seed_id FROM seeds
1733
+ UNION
1734
+ SELECT CASE
1735
+ WHEN neighbor_modes.mode = 'fold' THEN folded.kind
1736
+ WHEN assertion.a_kind = component.kind AND assertion.a_id = component.id
1737
+ THEN assertion.b_kind
1738
+ ELSE assertion.a_kind
1739
+ END,
1740
+ CASE
1741
+ WHEN neighbor_modes.mode = 'fold' THEN folded.id
1742
+ WHEN assertion.a_kind = component.kind AND assertion.a_id = component.id
1743
+ THEN assertion.b_id
1744
+ ELSE assertion.a_id
1745
+ END
1746
+ FROM component
1747
+ JOIN neighbor_modes ON 1 = 1
1748
+ LEFT JOIN ${schema.identityAssertionsTable} assertion
1749
+ ON neighbor_modes.mode = 'assertion'
1750
+ AND assertion.graph_id = ${graphId}
1751
+ AND assertion.rel = 'same'
1752
+ AND ${windowOverlapSql("assertion", lowerBoundary, upperBoundary)}
1753
+ AND ((assertion.a_kind = component.kind AND assertion.a_id = component.id)
1754
+ OR (assertion.b_kind = component.kind AND assertion.b_id = component.id))
1755
+ LEFT JOIN ${schema.nodesTable} folded
1756
+ ON neighbor_modes.mode = 'fold'
1757
+ AND folded.graph_id = ${graphId}
1758
+ AND folded.id = component.id
1759
+ WHERE assertion.id IS NOT NULL OR folded.id IS NOT NULL
1760
+ )
1761
+ ` : sql`
1762
+ component(kind, id) AS (
1763
+ SELECT seed_kind, seed_id FROM seeds
1764
+ UNION
1765
+ SELECT CASE
1766
+ WHEN assertion.a_kind = component.kind AND assertion.a_id = component.id
1767
+ THEN assertion.b_kind
1768
+ ELSE assertion.a_kind
1769
+ END,
1770
+ CASE
1771
+ WHEN assertion.a_kind = component.kind AND assertion.a_id = component.id
1772
+ THEN assertion.b_id
1773
+ ELSE assertion.a_id
1774
+ END
1775
+ FROM component
1776
+ JOIN ${schema.identityAssertionsTable} assertion
1777
+ ON assertion.graph_id = ${graphId}
1778
+ AND assertion.rel = 'same'
1779
+ AND ${windowOverlapSql("assertion", lowerBoundary, upperBoundary)}
1780
+ AND ((assertion.a_kind = component.kind AND assertion.a_id = component.id)
1781
+ OR (assertion.b_kind = component.kind AND assertion.b_id = component.id))
1782
+ )
1783
+ `;
1784
+ rows.push(
1785
+ ...await target.execute(
1786
+ asCompiledRowsSql(sql`
1787
+ WITH RECURSIVE
1788
+ seeds(seed_kind, seed_id) AS (VALUES ${seedRows}),
1789
+ ${component},
1790
+ selected_assertions AS (
1791
+ SELECT DISTINCT assertion.*
1792
+ FROM ${schema.identityAssertionsTable} assertion
1793
+ JOIN component
1794
+ ON (assertion.a_kind = component.kind AND assertion.a_id = component.id)
1795
+ OR (assertion.b_kind = component.kind AND assertion.b_id = component.id)
1796
+ WHERE assertion.graph_id = ${graphId}
1797
+ AND ${windowOverlapSql("assertion", lowerBoundary, upperBoundary)}
1798
+ )
1799
+ SELECT 'assertion' AS row_type, ${IDENTITY_ASSERTION_COLUMNS},
1800
+ NULL AS node_kind, NULL AS node_id,
1801
+ NULL AS node_created_at, NULL AS node_deleted_at
1802
+ FROM selected_assertions
1803
+ UNION ALL
1804
+ SELECT 'node', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1805
+ NULL, NULL, NULL, NULL, NULL,
1806
+ node.kind, node.id, node.created_at, node.deleted_at
1807
+ FROM ${schema.nodesTable} node
1808
+ JOIN component ON component.kind = node.kind AND component.id = node.id
1809
+ WHERE node.graph_id = ${graphId}
1810
+ `)
1811
+ )
1812
+ );
1813
+ }
1814
+ const nodesByKey = /* @__PURE__ */ new Map();
1815
+ const assertionsById = /* @__PURE__ */ new Map();
1816
+ for (const row of rows) {
1817
+ if (row.row_type === "assertion") {
1818
+ const assertion = normalizeIdentityAssertionRow(row);
1819
+ assertionsById.set(assertion.id, assertion);
1820
+ continue;
1821
+ }
1822
+ if (typeof row.node_kind !== "string" || typeof row.node_id !== "string")
1823
+ continue;
1824
+ const createdAt = canonicalEndpointTimestamp(row.node_created_at);
1825
+ if (createdAt === void 0) continue;
1826
+ const deletedAt = canonicalEndpointTimestamp(row.node_deleted_at);
1827
+ const node = {
1828
+ ref: { kind: row.node_kind, id: row.node_id },
1829
+ createdAt,
1830
+ ...deletedAt === void 0 ? {} : { deletedAt }
1831
+ };
1832
+ nodesByKey.set(refKey(node.ref), node);
1833
+ }
1834
+ return {
1835
+ nodes: [...nodesByKey.values()],
1836
+ assertions: [...assertionsById.values()]
1837
+ };
1838
+ }
1839
+ function identityWindowCheckpoints(window, operationInstant, nodes, assertions) {
1840
+ if (window.effective === "empty") return [];
1841
+ const checkpoints = /* @__PURE__ */ new Set([window.validFrom]);
1842
+ if (window.validTo === void 0) checkpoints.add(operationInstant);
1843
+ for (const row of [...assertions, ...nodes]) {
1844
+ for (const value of [
1845
+ "valid_from" in row ? row.valid_from : void 0,
1846
+ "valid_to" in row ? row.valid_to : void 0,
1847
+ "createdAt" in row ? row.createdAt : void 0,
1848
+ "deletedAt" in row ? row.deletedAt : void 0
1849
+ ]) {
1850
+ const boundary = canonicalEndpointTimestamp(value);
1851
+ if (boundary === void 0 || boundary < window.validFrom) continue;
1852
+ if (window.validTo !== void 0 && boundary >= window.validTo) continue;
1853
+ if (boundary > operationInstant) continue;
1854
+ checkpoints.add(boundary);
1855
+ }
1856
+ }
1857
+ return [...checkpoints].toSorted();
1858
+ }
1859
+ function validateRelationAgainstLedger(ctx, nodes, assertions, relation, operation, a, b, window, operationInstant) {
1860
+ const checkpoints = identityWindowCheckpoints(
1861
+ window,
1862
+ operationInstant,
1863
+ nodes,
1864
+ assertions
1865
+ );
1866
+ for (const instant of checkpoints) {
1867
+ const structuralNodes = nodes.map((node) => node.ref);
1868
+ const activeAssertions = assertions.filter(
1869
+ (assertion) => assertion.deleted_at === void 0 && assertion.valid_from <= instant && (assertion.valid_to === void 0 || assertion.valid_to > instant)
1870
+ );
1871
+ const activeFoldReferences = nodes.filter(
1872
+ (node) => node.createdAt <= instant && (node.deletedAt === void 0 || node.deletedAt > instant)
1873
+ ).map((node) => node.ref);
1874
+ const foldAssertions = [];
1875
+ if (ctx.sameIdAcrossKinds === "fold") {
1876
+ const byId = /* @__PURE__ */ new Map();
1877
+ for (const reference of activeFoldReferences) {
1878
+ const sameId = byId.get(reference.id) ?? [];
1879
+ sameId.push(reference);
1880
+ byId.set(reference.id, sameId);
1881
+ }
1882
+ for (const sameId of byId.values()) {
1883
+ const first = sameId[0];
1884
+ if (first === void 0) continue;
1885
+ for (const other of sameId.slice(1)) {
1886
+ foldAssertions.push({
1887
+ rel: "same",
1888
+ a_kind: first.kind,
1889
+ a_id: first.id,
1890
+ b_kind: other.kind,
1891
+ b_id: other.id
1892
+ });
1893
+ }
1894
+ }
1895
+ }
1896
+ const components = buildComponents(
1897
+ structuralNodes,
1898
+ [...activeAssertions, ...foldAssertions],
1899
+ "ignore"
1900
+ );
1901
+ const aClass = components.get(refKey(a)) ?? [];
1902
+ const bClass = components.get(refKey(b)) ?? [];
1903
+ if (relation === "different") {
1904
+ if (!containsRef(aClass, b)) continue;
1905
+ throw new IdentityContradictionError({
1906
+ operation,
1907
+ a,
1908
+ b,
1909
+ reason: "same-class"
1910
+ });
1911
+ }
1912
+ const different = spanningDifferentAssertion(
1913
+ activeAssertions,
1914
+ aClass,
1915
+ bClass
1916
+ );
1917
+ if (different !== void 0) {
1918
+ throw new IdentityContradictionError({
1919
+ operation,
1920
+ a,
1921
+ b,
1922
+ reason: "different-assertion",
1923
+ conflictingAssertionId: different.id
1924
+ });
1925
+ }
1926
+ const disjointKinds = classHasDisjointKinds(ctx.registry, aClass, bClass);
1927
+ if (disjointKinds === void 0) continue;
1928
+ throw new IdentityContradictionError({
1929
+ operation,
1930
+ a,
1931
+ b,
1932
+ reason: "disjoint-kinds",
1933
+ conflictingKinds: disjointKinds
1934
+ });
1935
+ }
1936
+ }
1937
+ async function createIdentityWindowValidator(ctx, target, requests, operationInstant, ignoredAssertionIds = /* @__PURE__ */ new Set()) {
1938
+ const ledger = await loadIdentityWindowLedger(
1939
+ target,
1940
+ ctx.schema,
1941
+ ctx.graphId,
1942
+ requests,
1943
+ operationInstant,
1944
+ ctx.sameIdAcrossKinds
1945
+ );
1946
+ if (ignoredAssertionIds.size > 0) {
1947
+ const retained = ledger.assertions.filter(
1948
+ (assertion) => !ignoredAssertionIds.has(assertion.id)
1949
+ );
1950
+ ledger.assertions.splice(0, ledger.assertions.length, ...retained);
1951
+ }
1952
+ return {
1953
+ validate(relation, operation, a, b, window) {
1954
+ validateRelationAgainstLedger(
1955
+ ctx,
1956
+ ledger.nodes,
1957
+ ledger.assertions,
1958
+ relation,
1959
+ operation,
1960
+ a,
1961
+ b,
1962
+ window,
1963
+ operationInstant
1964
+ );
1965
+ },
1966
+ record(assertion) {
1967
+ ledger.assertions.push(assertion);
1968
+ }
1969
+ };
1970
+ }
1971
+ async function validateRelationThroughoutIdentityWindow(ctx, target, relation, operation, a, b, window, operationInstant) {
1972
+ const validator = await createIdentityWindowValidator(
1973
+ ctx,
1974
+ target,
1975
+ [{ references: [a, b], window }],
1976
+ operationInstant
1977
+ );
1978
+ validator.validate(relation, operation, a, b, window);
1979
+ }
1584
1980
  function nullableAssertionValue(value) {
1585
1981
  return value === void 0 ? sql`NULL` : sql`${value}`;
1586
1982
  }
@@ -1903,34 +2299,107 @@ async function mergeCurrentClasses(target, schema, graphId, a, b) {
1903
2299
  }
1904
2300
  await replaceSeparationForMembers(target, schema, graphId, fusedMembers);
1905
2301
  }
1906
- async function assertPair(ctx, target, relation, firstInput, secondInput, touch) {
2302
+ async function assertPair(ctx, target, relation, firstInput, secondInput, touch, windowInput, operationInstant, windowValidator) {
1907
2303
  const first = registeredPlainRef(ctx, firstInput);
1908
2304
  const second = registeredPlainRef(ctx, secondInput);
1909
2305
  if (refKey(first) === refKey(second)) throw selfAssertionError(relation);
1910
2306
  const [a, b] = normalizePair(first, second);
1911
- await Promise.all([
1912
- requireLiveEndpoint(target, ctx.graphId, a),
1913
- requireLiveEndpoint(target, ctx.graphId, b)
1914
- ]);
1915
- const existing = await currentAssertionForPair(
2307
+ if (windowInput === void 0) {
2308
+ const current = await currentAssertionForPair(
2309
+ target,
2310
+ ctx.schema,
2311
+ ctx.graphId,
2312
+ relation,
2313
+ a,
2314
+ b
2315
+ );
2316
+ if (current !== void 0) {
2317
+ return assertionResult(publicAssertion(current), "existing");
2318
+ }
2319
+ await Promise.all([
2320
+ requireLiveEndpoint(target, ctx.graphId, a),
2321
+ requireLiveEndpoint(target, ctx.graphId, b)
2322
+ ]);
2323
+ await validateCurrentRelation(
2324
+ ctx,
2325
+ target,
2326
+ relation,
2327
+ relation === "same" ? "assertSame" : "assertDifferent",
2328
+ a,
2329
+ b
2330
+ );
2331
+ const row2 = await insertAssertion(
2332
+ target,
2333
+ ctx.schema,
2334
+ ctx.graphId,
2335
+ relation,
2336
+ a,
2337
+ b,
2338
+ operationInstant,
2339
+ touch
2340
+ );
2341
+ windowValidator?.record(row2);
2342
+ if (relation === "same") {
2343
+ await mergeCurrentClasses(target, ctx.schema, ctx.graphId, a, b);
2344
+ } else {
2345
+ await replaceSeparationForReferences(target, ctx.schema, ctx.graphId, [
2346
+ a,
2347
+ b
2348
+ ]);
2349
+ }
2350
+ return assertionResult(publicAssertion(row2), "created");
2351
+ }
2352
+ const window = resolveIdentityValidityWindow(windowInput, operationInstant);
2353
+ await requireEndpointsCoverIdentityWindow(
2354
+ target,
2355
+ ctx.graphId,
2356
+ [a, b],
2357
+ window
2358
+ );
2359
+ const existing = await assertionForExactWindow(
1916
2360
  target,
1917
2361
  ctx.schema,
1918
2362
  ctx.graphId,
1919
2363
  relation,
1920
2364
  a,
1921
- b
2365
+ b,
2366
+ window
1922
2367
  );
1923
2368
  if (existing !== void 0) {
1924
2369
  return assertionResult(publicAssertion(existing), "existing");
1925
2370
  }
1926
- await validateCurrentRelation(
1927
- ctx,
1928
- target,
1929
- relation,
1930
- relation === "same" ? "assertSame" : "assertDifferent",
1931
- a,
1932
- b
1933
- );
2371
+ if (window.effective === "current") {
2372
+ const current = await currentAssertionForPair(
2373
+ target,
2374
+ ctx.schema,
2375
+ ctx.graphId,
2376
+ relation,
2377
+ a,
2378
+ b
2379
+ );
2380
+ if (current !== void 0) {
2381
+ throw new IdentityValidityWindowError({
2382
+ reason: "overlapping-open-window",
2383
+ validFrom: window.validFrom,
2384
+ operationInstant
2385
+ });
2386
+ }
2387
+ }
2388
+ const operation = relation === "same" ? "assertSame" : "assertDifferent";
2389
+ if (windowValidator === void 0) {
2390
+ await validateRelationThroughoutIdentityWindow(
2391
+ ctx,
2392
+ target,
2393
+ relation,
2394
+ operation,
2395
+ a,
2396
+ b,
2397
+ window,
2398
+ operationInstant
2399
+ );
2400
+ } else {
2401
+ windowValidator.validate(relation, operation, a, b, window);
2402
+ }
1934
2403
  const row = await insertAssertion(
1935
2404
  target,
1936
2405
  ctx.schema,
@@ -1938,9 +2407,17 @@ async function assertPair(ctx, target, relation, firstInput, secondInput, touch)
1938
2407
  relation,
1939
2408
  a,
1940
2409
  b,
1941
- nowIso(),
1942
- touch
2410
+ operationInstant,
2411
+ touch,
2412
+ {
2413
+ validFrom: window.validFrom,
2414
+ ...window.validTo === void 0 ? {} : { validTo: window.validTo }
2415
+ }
1943
2416
  );
2417
+ windowValidator?.record(row);
2418
+ if (window.effective !== "current") {
2419
+ return assertionResult(publicAssertion(row), "created");
2420
+ }
1944
2421
  if (relation === "same") {
1945
2422
  await mergeCurrentClasses(target, ctx.schema, ctx.graphId, a, b);
1946
2423
  } else {
@@ -2145,6 +2622,40 @@ async function bulkAssertPairs(ctx, target, relation, pairs, touch) {
2145
2622
  }
2146
2623
  return results;
2147
2624
  }
2625
+ async function bulkAssertWindowedPairs(ctx, target, relation, pairs, touch, operationInstant) {
2626
+ const windowRequests = pairs.map((pair) => {
2627
+ const first = registeredPlainRef(ctx, pair.a);
2628
+ const second = registeredPlainRef(ctx, pair.b);
2629
+ return {
2630
+ references: normalizePair(first, second),
2631
+ window: resolveIdentityValidityWindow(pair, operationInstant)
2632
+ };
2633
+ });
2634
+ const windowValidator = await createIdentityWindowValidator(
2635
+ ctx,
2636
+ target,
2637
+ windowRequests,
2638
+ operationInstant
2639
+ );
2640
+ const results = [];
2641
+ for (const pair of pairs) {
2642
+ const window = hasExplicitIdentityValidityWindow(pair) ? pair : void 0;
2643
+ results.push(
2644
+ await assertPair(
2645
+ ctx,
2646
+ target,
2647
+ relation,
2648
+ pair.a,
2649
+ pair.b,
2650
+ touch,
2651
+ window,
2652
+ operationInstant,
2653
+ windowValidator
2654
+ )
2655
+ );
2656
+ }
2657
+ return results;
2658
+ }
2148
2659
  async function findCurrentAssertionById(target, schema, graphId, id) {
2149
2660
  const rows = await target.execute(
2150
2661
  asCompiledRowsSql(sql`
@@ -2183,7 +2694,7 @@ async function retractById(ctx, target, id, touch) {
2183
2694
  touch(ctx.graphId, id, ended);
2184
2695
  return ended;
2185
2696
  }
2186
- async function retractByIds(ctx, target, ids, touch) {
2697
+ async function retractCurrentAssertions(ctx, target, ids, touch, resolveValidTo) {
2187
2698
  const uniqueIds = [...new Set(ids)];
2188
2699
  if (uniqueIds.length === 0) return [];
2189
2700
  const current = [];
@@ -2210,11 +2721,11 @@ async function retractByIds(ctx, target, ids, touch) {
2210
2721
  current.push(...rows.map((row) => normalizeIdentityAssertionRow(row)));
2211
2722
  }
2212
2723
  if (current.length === 0) return [];
2213
- const now = nowIso();
2724
+ const operationInstant = nowIso();
2214
2725
  const byValidTo = /* @__PURE__ */ new Map();
2215
2726
  const endedById = /* @__PURE__ */ new Map();
2216
2727
  for (const row of current) {
2217
- const validTo = clampValidTo(now, row.valid_from);
2728
+ const validTo = resolveValidTo(row, operationInstant);
2218
2729
  endedById.set(row.id, validTo);
2219
2730
  const group = byValidTo.get(validTo) ?? [];
2220
2731
  group.push(row.id);
@@ -2235,7 +2746,7 @@ async function retractByIds(ctx, target, ids, touch) {
2235
2746
  target,
2236
2747
  sql`
2237
2748
  UPDATE ${ctx.schema.identityAssertionsTable}
2238
- SET valid_to = ${validTo}, updated_at = ${now}
2749
+ SET valid_to = ${validTo}, updated_at = ${operationInstant}
2239
2750
  WHERE graph_id = ${ctx.graphId}
2240
2751
  AND id IN (${placeholders})
2241
2752
  AND valid_to IS NULL
@@ -2251,7 +2762,7 @@ async function retractByIds(ctx, target, ids, touch) {
2251
2762
  {
2252
2763
  ...row,
2253
2764
  valid_to: requireDefined(endedById.get(row.id)),
2254
- updated_at: now
2765
+ updated_at: operationInstant
2255
2766
  }
2256
2767
  ];
2257
2768
  });
@@ -2260,6 +2771,44 @@ async function retractByIds(ctx, target, ids, touch) {
2260
2771
  }
2261
2772
  return ended;
2262
2773
  }
2774
+ async function retractByIds(ctx, target, ids, touch) {
2775
+ return retractCurrentAssertions(
2776
+ ctx,
2777
+ target,
2778
+ ids,
2779
+ touch,
2780
+ (row, operationInstant) => clampValidTo(operationInstant, row.valid_from)
2781
+ );
2782
+ }
2783
+ async function retractPlannedAssertions(ctx, target, retractions, touch) {
2784
+ const retractionById = new Map(
2785
+ retractions.map((retraction) => [retraction.id, retraction])
2786
+ );
2787
+ return retractCurrentAssertions(
2788
+ ctx,
2789
+ target,
2790
+ retractions.map((retraction) => retraction.id),
2791
+ touch,
2792
+ (row, operationInstant) => {
2793
+ const retraction = requireDefined(retractionById.get(row.id));
2794
+ if (retraction.validTo === void 0) {
2795
+ throw new ConfigurationError(
2796
+ `Identity merge retraction ${retraction.id} is missing validTo.`,
2797
+ {
2798
+ code: "IDENTITY_MERGE_RETRACTION_REQUIRES_END",
2799
+ assertionId: retraction.id
2800
+ }
2801
+ );
2802
+ }
2803
+ return requireDefined(
2804
+ resolveIdentityValidityWindow(
2805
+ { validFrom: row.valid_from, validTo: retraction.validTo },
2806
+ operationInstant
2807
+ ).validTo
2808
+ );
2809
+ }
2810
+ );
2811
+ }
2263
2812
  async function runIdentityMutation(ctx, fn) {
2264
2813
  let touched = false;
2265
2814
  return runInWriteTransaction(
@@ -2421,29 +2970,65 @@ function partitionRetractedEndpoints(retracted) {
2421
2970
  function createIdentityFacade(ctx) {
2422
2971
  return {
2423
2972
  ...createIdentityReadFacade(ctx),
2424
- assertSame(a, b) {
2425
- return runIdentityMutation(
2426
- ctx,
2427
- (target, touch) => assertPair(ctx, target, "same", a, b, touch)
2428
- );
2973
+ assertSame(a, b, window) {
2974
+ return runIdentityMutation(ctx, (target, touch) => {
2975
+ const operationInstant = nowIso();
2976
+ return assertPair(
2977
+ ctx,
2978
+ target,
2979
+ "same",
2980
+ a,
2981
+ b,
2982
+ touch,
2983
+ hasExplicitIdentityValidityWindow(window) ? window : void 0,
2984
+ operationInstant
2985
+ );
2986
+ });
2429
2987
  },
2430
- assertDifferent(a, b) {
2431
- return runIdentityMutation(
2432
- ctx,
2433
- (target, touch) => assertPair(ctx, target, "different", a, b, touch)
2434
- );
2988
+ assertDifferent(a, b, window) {
2989
+ return runIdentityMutation(ctx, (target, touch) => {
2990
+ const operationInstant = nowIso();
2991
+ return assertPair(
2992
+ ctx,
2993
+ target,
2994
+ "different",
2995
+ a,
2996
+ b,
2997
+ touch,
2998
+ hasExplicitIdentityValidityWindow(window) ? window : void 0,
2999
+ operationInstant
3000
+ );
3001
+ });
2435
3002
  },
2436
3003
  bulkAssertSame(pairs) {
2437
- return runIdentityMutation(
2438
- ctx,
2439
- (target, touch) => bulkAssertPairs(ctx, target, "same", pairs, touch)
2440
- );
3004
+ return runIdentityMutation(ctx, (target, touch) => {
3005
+ if (!pairs.some((pair) => hasExplicitIdentityValidityWindow(pair))) {
3006
+ return bulkAssertPairs(ctx, target, "same", pairs, touch);
3007
+ }
3008
+ return bulkAssertWindowedPairs(
3009
+ ctx,
3010
+ target,
3011
+ "same",
3012
+ pairs,
3013
+ touch,
3014
+ nowIso()
3015
+ );
3016
+ });
2441
3017
  },
2442
3018
  bulkAssertDifferent(pairs) {
2443
- return runIdentityMutation(
2444
- ctx,
2445
- (target, touch) => bulkAssertPairs(ctx, target, "different", pairs, touch)
2446
- );
3019
+ return runIdentityMutation(ctx, (target, touch) => {
3020
+ if (!pairs.some((pair) => hasExplicitIdentityValidityWindow(pair))) {
3021
+ return bulkAssertPairs(ctx, target, "different", pairs, touch);
3022
+ }
3023
+ return bulkAssertWindowedPairs(
3024
+ ctx,
3025
+ target,
3026
+ "different",
3027
+ pairs,
3028
+ touch,
3029
+ nowIso()
3030
+ );
3031
+ });
2447
3032
  },
2448
3033
  retractAssertion(id) {
2449
3034
  return runIdentityMutation(ctx, async (target, touch) => {
@@ -2560,7 +3145,7 @@ function transferShapeError(assertion, message, issue) {
2560
3145
  ]
2561
3146
  });
2562
3147
  }
2563
- function validateTransferShape(ctx, assertion, mode) {
3148
+ function validateTransferShape(ctx, assertion, mode, operationInstant) {
2564
3149
  if (!ctx.registry.nodeKinds.has(assertion.a.kind) || !ctx.registry.nodeKinds.has(assertion.b.kind)) {
2565
3150
  throw transferShapeError(
2566
3151
  assertion,
@@ -2602,25 +3187,31 @@ function validateTransferShape(ctx, assertion, mode) {
2602
3187
  }
2603
3188
  );
2604
3189
  }
2605
- const now = nowIso();
2606
- if (assertion.validTo === void 0 && compareCodePoints(assertion.validFrom, now) > 0) {
2607
- throw transferShapeError(
2608
- assertion,
2609
- "Identity import cannot contain future-dated open assertions.",
3190
+ let window;
3191
+ try {
3192
+ window = resolveIdentityValidityWindow(
2610
3193
  {
2611
- message: `Assertion ${assertion.id} validFrom is in the future`,
2612
- code: "IDENTITY_IMPORT_FUTURE_VALID_FROM"
2613
- }
3194
+ validFrom: assertion.validFrom,
3195
+ ...assertion.validTo === void 0 ? {} : { validTo: assertion.validTo }
3196
+ },
3197
+ operationInstant
2614
3198
  );
2615
- }
2616
- if (assertion.validTo !== void 0 && compareCodePoints(assertion.validTo, assertion.validFrom) < 0) {
3199
+ } catch (error) {
3200
+ if (!(error instanceof IdentityValidityWindowError)) throw error;
3201
+ const issue = error.details.reason === "future-valid-from" ? {
3202
+ code: "IDENTITY_IMPORT_FUTURE_VALID_FROM",
3203
+ message: `Assertion ${assertion.id} validFrom is in the future`
3204
+ } : error.details.reason === "future-valid-to" ? {
3205
+ code: "IDENTITY_IMPORT_FUTURE_VALID_TO",
3206
+ message: `Assertion ${assertion.id} validTo is in the future`
3207
+ } : {
3208
+ code: "IDENTITY_IMPORT_INVALID_WINDOW",
3209
+ message: `Assertion ${assertion.id} validTo must not precede validFrom`
3210
+ };
2617
3211
  throw transferShapeError(
2618
3212
  assertion,
2619
- "Identity assertion validity window is empty.",
2620
- {
2621
- message: `Assertion ${assertion.id} validTo must not precede validFrom`,
2622
- code: "IDENTITY_IMPORT_INVALID_WINDOW"
2623
- }
3213
+ "Identity import contains an unsupported validity window.",
3214
+ issue
2624
3215
  );
2625
3216
  }
2626
3217
  if (assertion.endedBy !== void 0) {
@@ -2646,17 +3237,7 @@ function validateTransferShape(ctx, assertion, mode) {
2646
3237
  );
2647
3238
  }
2648
3239
  }
2649
- if (assertion.validTo !== void 0 && compareCodePoints(assertion.validTo, now) > 0) {
2650
- throw transferShapeError(
2651
- assertion,
2652
- "Identity import cannot contain assertions that end in the future.",
2653
- {
2654
- message: `Assertion ${assertion.id} validTo is in the future`,
2655
- code: "IDENTITY_IMPORT_FUTURE_VALID_TO"
2656
- }
2657
- );
2658
- }
2659
- return normalized;
3240
+ return { endpoints: normalized, window };
2660
3241
  }
2661
3242
  var IDENTITY_IMPORT_FAILED_ASSERTION = /* @__PURE__ */ Symbol(
2662
3243
  "typegraph.identity.failedAssertionId"
@@ -2679,13 +3260,14 @@ function rethrowTaggedWithAssertion(error, assertionId, progress) {
2679
3260
  }
2680
3261
  throw error;
2681
3262
  }
2682
- async function importIdentityAssertionsIntoTarget(ctx, target, assertions, mode) {
3263
+ async function importIdentityAssertionsIntoTarget(ctx, target, assertions, mode, ignoredAssertionIds = /* @__PURE__ */ new Set()) {
2683
3264
  let created = 0;
2684
3265
  let skipped = 0;
2685
3266
  await withRecordedIdentityMutationTarget(target, async (rawTarget, touch) => {
3267
+ const operationInstant = nowIso();
2686
3268
  const normalized = assertions.map((assertion) => ({
2687
3269
  assertion,
2688
- endpoints: validateTransferShape(ctx, assertion, mode)
3270
+ ...validateTransferShape(ctx, assertion, mode, operationInstant)
2689
3271
  }));
2690
3272
  const existingById = await loadAssertionsByIds(
2691
3273
  rawTarget,
@@ -2740,7 +3322,17 @@ async function importIdentityAssertionsIntoTarget(ctx, target, assertions, mode)
2740
3322
  } catch (error) {
2741
3323
  attributeMissingEndpoint(error, true);
2742
3324
  }
2743
- for (const { assertion, endpoints } of normalized) {
3325
+ const windowValidator = await createIdentityWindowValidator(
3326
+ ctx,
3327
+ rawTarget,
3328
+ normalized.map(({ endpoints, window }) => ({
3329
+ references: endpoints,
3330
+ window
3331
+ })),
3332
+ operationInstant,
3333
+ ignoredAssertionIds
3334
+ );
3335
+ for (const { assertion, endpoints, window } of normalized) {
2744
3336
  const [a, b] = endpoints;
2745
3337
  try {
2746
3338
  const sameId = existingById.get(assertion.id);
@@ -2759,73 +3351,102 @@ async function importIdentityAssertionsIntoTarget(ctx, target, assertions, mode)
2759
3351
  }
2760
3352
  );
2761
3353
  }
2762
- if (assertion.validTo !== void 0) {
2763
- const timestamp = assertion.validFrom;
2764
- const row = {
2765
- graph_id: ctx.graphId,
2766
- id: assertion.id,
2767
- rel: assertion.relation,
2768
- a_kind: a.kind,
2769
- a_id: a.id,
2770
- b_kind: b.kind,
2771
- b_id: b.id,
2772
- valid_from: assertion.validFrom,
2773
- valid_to: assertion.validTo,
2774
- created_at: timestamp,
2775
- updated_at: assertion.validTo,
2776
- deleted_at: void 0,
2777
- ended_by_kind: assertion.endedBy?.kind,
2778
- ended_by_id: assertion.endedBy?.id
2779
- };
2780
- await insertAssertionRows(rawTarget, ctx.schema, [row]);
2781
- touch(ctx.graphId, row.id, row);
2782
- existingById.set(row.id, row);
2783
- created += 1;
2784
- continue;
2785
- }
2786
- const existing = await currentAssertionForPair(
3354
+ const exactWindow = await assertionForExactWindow(
2787
3355
  rawTarget,
2788
3356
  ctx.schema,
2789
3357
  ctx.graphId,
2790
3358
  assertion.relation,
2791
3359
  a,
2792
- b
3360
+ b,
3361
+ window
2793
3362
  );
2794
- if (existing !== void 0) {
3363
+ if (exactWindow !== void 0) {
2795
3364
  skipped += 1;
2796
3365
  continue;
2797
3366
  }
2798
- await validateCurrentRelation(
2799
- ctx,
2800
- rawTarget,
2801
- assertion.relation,
2802
- "import",
2803
- a,
2804
- b
2805
- );
2806
- const inserted = await insertAssertion(
2807
- rawTarget,
2808
- ctx.schema,
2809
- ctx.graphId,
2810
- assertion.relation,
2811
- a,
2812
- b,
2813
- nowIso(),
2814
- touch,
2815
- { id: assertion.id, validFrom: assertion.validFrom }
2816
- );
2817
- existingById.set(inserted.id, inserted);
2818
- created += 1;
2819
- if (assertion.relation === "same") {
2820
- await mergeCurrentClasses(rawTarget, ctx.schema, ctx.graphId, a, b);
2821
- } else {
2822
- await replaceSeparationForReferences(
3367
+ if (window.effective === "current") {
3368
+ const current = await currentAssertionForPair(
3369
+ rawTarget,
3370
+ ctx.schema,
3371
+ ctx.graphId,
3372
+ assertion.relation,
3373
+ a,
3374
+ b
3375
+ );
3376
+ if (current !== void 0) {
3377
+ skipped += 1;
3378
+ continue;
3379
+ }
3380
+ await requireEndpointsCoverIdentityWindow(
3381
+ rawTarget,
3382
+ ctx.graphId,
3383
+ [a, b],
3384
+ window
3385
+ );
3386
+ windowValidator.validate(assertion.relation, "import", a, b, window);
3387
+ await validateCurrentRelation(
3388
+ ctx,
3389
+ rawTarget,
3390
+ assertion.relation,
3391
+ "import",
3392
+ a,
3393
+ b
3394
+ );
3395
+ const inserted = await insertAssertion(
2823
3396
  rawTarget,
2824
3397
  ctx.schema,
2825
3398
  ctx.graphId,
2826
- [a, b]
3399
+ assertion.relation,
3400
+ a,
3401
+ b,
3402
+ operationInstant,
3403
+ touch,
3404
+ { id: assertion.id, validFrom: window.validFrom }
2827
3405
  );
3406
+ existingById.set(inserted.id, inserted);
3407
+ windowValidator.record(inserted);
3408
+ created += 1;
3409
+ if (assertion.relation === "same") {
3410
+ await mergeCurrentClasses(rawTarget, ctx.schema, ctx.graphId, a, b);
3411
+ } else {
3412
+ await replaceSeparationForReferences(
3413
+ rawTarget,
3414
+ ctx.schema,
3415
+ ctx.graphId,
3416
+ [a, b]
3417
+ );
3418
+ }
3419
+ continue;
2828
3420
  }
3421
+ await requireEndpointsCoverIdentityWindow(
3422
+ rawTarget,
3423
+ ctx.graphId,
3424
+ [a, b],
3425
+ window
3426
+ );
3427
+ windowValidator.validate(assertion.relation, "import", a, b, window);
3428
+ const timestamp = window.validFrom;
3429
+ const row = {
3430
+ graph_id: ctx.graphId,
3431
+ id: assertion.id,
3432
+ rel: assertion.relation,
3433
+ a_kind: a.kind,
3434
+ a_id: a.id,
3435
+ b_kind: b.kind,
3436
+ b_id: b.id,
3437
+ valid_from: window.validFrom,
3438
+ valid_to: window.validTo,
3439
+ created_at: timestamp,
3440
+ updated_at: window.validTo ?? window.validFrom,
3441
+ deleted_at: void 0,
3442
+ ended_by_kind: assertion.endedBy?.kind,
3443
+ ended_by_id: assertion.endedBy?.id
3444
+ };
3445
+ await insertAssertionRows(rawTarget, ctx.schema, [row]);
3446
+ touch(ctx.graphId, row.id, row);
3447
+ existingById.set(row.id, row);
3448
+ windowValidator.record(row);
3449
+ created += 1;
2829
3450
  } catch (error) {
2830
3451
  rethrowTaggedWithAssertion(error, assertion.id, { created, skipped });
2831
3452
  }
@@ -2833,12 +3454,17 @@ async function importIdentityAssertionsIntoTarget(ctx, target, assertions, mode)
2833
3454
  });
2834
3455
  return { created, skipped };
2835
3456
  }
2836
- async function applyIdentityChangesForContext(ctx, retractionIds, assertions) {
2837
- if (retractionIds.length === 0 && assertions.length === 0) {
3457
+ async function applyIdentityChangesForContext(ctx, retractions, assertions) {
3458
+ if (retractions.length === 0 && assertions.length === 0) {
2838
3459
  return { created: 0, retracted: 0 };
2839
3460
  }
2840
3461
  return runIdentityMutation(ctx, async (target, touch, markWritten) => {
2841
- const retracted = await retractByIds(ctx, target, retractionIds, touch);
3462
+ const retracted = await retractPlannedAssertions(
3463
+ ctx,
3464
+ target,
3465
+ retractions,
3466
+ touch
3467
+ );
2842
3468
  const { closureReferences, separationReferences } = partitionRetractedEndpoints(retracted);
2843
3469
  if (closureReferences.length > 0) {
2844
3470
  await replaceAffectedClosure(
@@ -2859,7 +3485,8 @@ async function applyIdentityChangesForContext(ctx, retractionIds, assertions) {
2859
3485
  ctx,
2860
3486
  target,
2861
3487
  assertions,
2862
- "state"
3488
+ "archival",
3489
+ new Set(retracted.map((assertion) => assertion.id))
2863
3490
  );
2864
3491
  if (summary.created > 0) markWritten();
2865
3492
  return { created: summary.created, retracted: retracted.length };
@@ -3310,6 +3937,34 @@ async function readNodeDeletionInstant(target, schema, graphId, ref) {
3310
3937
  const row = rows.at(0);
3311
3938
  return row === void 0 ? void 0 : optionalIdentityTimestamp(row.deleted_at);
3312
3939
  }
3940
+ async function requireNodeValidityEndCompatible(ctx, target, ref, validTo) {
3941
+ const rows = await target.execute(
3942
+ asCompiledRowsSql(sql`
3943
+ SELECT ${IDENTITY_ASSERTION_COLUMNS}
3944
+ FROM ${ctx.schema.identityAssertionsTable}
3945
+ WHERE graph_id = ${ctx.graphId}
3946
+ AND deleted_at IS NULL
3947
+ AND (valid_to IS NULL OR valid_to > ${validTo})
3948
+ AND (
3949
+ (a_kind = ${ref.kind} AND a_id = ${ref.id})
3950
+ OR (b_kind = ${ref.kind} AND b_id = ${ref.id})
3951
+ )
3952
+ ORDER BY id
3953
+ LIMIT 1
3954
+ `)
3955
+ );
3956
+ const row = rows.at(0);
3957
+ if (row === void 0) return;
3958
+ const assertion = normalizeIdentityAssertionRow(row);
3959
+ throw new IdentityEndpointValidityError({
3960
+ endpoint: ref,
3961
+ assertionWindow: {
3962
+ validFrom: assertion.valid_from,
3963
+ ...assertion.valid_to === void 0 ? {} : { validTo: assertion.valid_to }
3964
+ },
3965
+ endpointWindow: { validTo }
3966
+ });
3967
+ }
3313
3968
  async function detachIdentityForNode(ctx, target, ref, mode) {
3314
3969
  await lockIdentityGraph(target, ctx.graphId);
3315
3970
  await withRecordedIdentityMutationTarget(target, async (rawTarget, touch) => {
@@ -3388,6 +4043,6 @@ async function detachIdentityForNode(ctx, target, ref, mode) {
3388
4043
  });
3389
4044
  }
3390
4045
 
3391
- export { IDENTITY_IMPORT_FAILED_ASSERTION, IDENTITY_IMPORT_PROGRESS, applyIdentityChangesForContext, assertAffectedIdentityClassesConsistent, createIdentityFacade, createIdentityReadFacade, createValidationError, deleteAssertionsTouchingKinds, detachIdentityForNode, encodeTupleKey, foldIdentityForCreatedNodes, hasAssertionsTouchingKinds, identityAssertionSemanticKey, identityReferenceKey, importIdentityAssertionsIntoTarget, liveNodeKindsSharingIds, loadAssertionsByIds, loadCurrentStructuralClasses, lockIdentityEnablementNodes, lockIdentityGraph, lockSchemaVersionForStoreWrite, normalizeIdentityPair, purgeAssertionsWithUnregisteredKinds, readIdentityAssertionPageAtTarget, readIdentityAssertionsForInterchange, rebuildIdentityClosureForContext, refKey, removeIdentityKindsForContext, runHookedWriteOperation, runInWriteTransaction, separationRebuildRequired, toTransferAssertion, validateEdgeProps, validateIdentityForContext, validateNodeProps, validateProps, withWriteTransactionSession, wrapZodError };
3392
- //# sourceMappingURL=chunk-A2LJG5GM.js.map
3393
- //# sourceMappingURL=chunk-A2LJG5GM.js.map
4046
+ export { IDENTITY_IMPORT_FAILED_ASSERTION, IDENTITY_IMPORT_PROGRESS, applyIdentityChangesForContext, assertAffectedIdentityClassesConsistent, createIdentityFacade, createIdentityReadFacade, createValidationError, deleteAssertionsTouchingKinds, detachIdentityForNode, foldIdentityForCreatedNodes, forceWriteTransactionRevision, hasAssertionsTouchingKinds, identityAssertionSemanticKey, identityReferenceKey, identityValidityWindowsOverlap, importIdentityAssertionsIntoTarget, liveNodeKindsSharingIds, loadAssertionsByIds, loadCurrentStructuralClasses, lockIdentityEnablementNodes, lockIdentityGraph, lockSchemaVersionForStoreWrite, normalizeIdentityPair, purgeAssertionsWithUnregisteredKinds, readIdentityAssertionPageAtTarget, readIdentityAssertionsForInterchange, rebuildIdentityClosureForContext, refKey, removeIdentityKindsForContext, requireNodeValidityEndCompatible, runHookedWriteOperation, runInWriteTransaction, separationRebuildRequired, toTransferAssertion, validateEdgeProps, validateIdentityForContext, validateNodeProps, validateProps, withWriteTransactionSession, wrapZodError };
4047
+ //# sourceMappingURL=chunk-ZFMCDJGB.js.map
4048
+ //# sourceMappingURL=chunk-ZFMCDJGB.js.map