@nicia-ai/typegraph 0.44.0 → 0.46.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 (392) hide show
  1. package/dist/backend/drizzle/indexes.cjs +11 -11
  2. package/dist/backend/drizzle/indexes.d.cts +1 -1
  3. package/dist/backend/drizzle/indexes.d.ts +1 -1
  4. package/dist/backend/drizzle/indexes.js +7 -7
  5. package/dist/backend/index.cjs +53 -54
  6. package/dist/backend/index.d.cts +3 -3
  7. package/dist/backend/index.d.ts +3 -3
  8. package/dist/backend/index.js +13 -14
  9. package/dist/backend/postgres/index.cjs +29 -30
  10. package/dist/backend/postgres/index.d.cts +7 -7
  11. package/dist/backend/postgres/index.d.ts +7 -7
  12. package/dist/backend/postgres/index.js +16 -17
  13. package/dist/backend/postgres/pglite-store.cjs +48 -43
  14. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  15. package/dist/backend/postgres/pglite-store.d.cts +15 -9
  16. package/dist/backend/postgres/pglite-store.d.ts +15 -9
  17. package/dist/backend/postgres/pglite-store.js +44 -39
  18. package/dist/backend/postgres/pglite-store.js.map +1 -1
  19. package/dist/backend/postgres/pglite.cjs +18 -19
  20. package/dist/backend/postgres/pglite.d.cts +4 -4
  21. package/dist/backend/postgres/pglite.d.ts +4 -4
  22. package/dist/backend/postgres/pglite.js +17 -18
  23. package/dist/backend/sqlite/index.cjs +26 -27
  24. package/dist/backend/sqlite/index.d.cts +6 -6
  25. package/dist/backend/sqlite/index.d.ts +6 -6
  26. package/dist/backend/sqlite/index.js +14 -15
  27. package/dist/backend/sqlite/libsql.cjs +21 -22
  28. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  29. package/dist/backend/sqlite/libsql.d.cts +15 -8
  30. package/dist/backend/sqlite/libsql.d.ts +15 -8
  31. package/dist/backend/sqlite/libsql.js +17 -18
  32. package/dist/backend/sqlite/libsql.js.map +1 -1
  33. package/dist/backend/sqlite/local-store.cjs +49 -44
  34. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  35. package/dist/backend/sqlite/local-store.d.cts +15 -10
  36. package/dist/backend/sqlite/local-store.d.ts +15 -10
  37. package/dist/backend/sqlite/local-store.js +45 -40
  38. package/dist/backend/sqlite/local-store.js.map +1 -1
  39. package/dist/backend/sqlite/local.cjs +19 -20
  40. package/dist/backend/sqlite/local.d.cts +3 -3
  41. package/dist/backend/sqlite/local.d.ts +3 -3
  42. package/dist/backend/sqlite/local.js +17 -18
  43. package/dist/{chunk-XMYJY7NI.js → chunk-2LG2XB2M.js} +3 -3
  44. package/dist/{chunk-XMYJY7NI.js.map → chunk-2LG2XB2M.js.map} +1 -1
  45. package/dist/{chunk-QGKILWGZ.cjs → chunk-2NA5DYLO.cjs} +4 -4
  46. package/dist/{chunk-QGKILWGZ.cjs.map → chunk-2NA5DYLO.cjs.map} +1 -1
  47. package/dist/{chunk-5MUSU4ZP.cjs → chunk-3DHZCOT7.cjs} +20 -20
  48. package/dist/chunk-3DHZCOT7.cjs.map +1 -0
  49. package/dist/{chunk-OVUUTCPJ.cjs → chunk-4UGOKMI5.cjs} +268 -150
  50. package/dist/chunk-4UGOKMI5.cjs.map +1 -0
  51. package/dist/{chunk-FRHHDHKH.js → chunk-5262ZMTR.js} +26 -5
  52. package/dist/chunk-5262ZMTR.js.map +1 -0
  53. package/dist/{chunk-HOIFFY4M.js → chunk-5763DULU.js} +248 -76
  54. package/dist/chunk-5763DULU.js.map +1 -0
  55. package/dist/{chunk-7G32LIQM.js → chunk-5UVRGXD3.js} +277 -7
  56. package/dist/chunk-5UVRGXD3.js.map +1 -0
  57. package/dist/{chunk-IIT5K7SK.cjs → chunk-62ZP23AW.cjs} +15 -15
  58. package/dist/{chunk-IIT5K7SK.cjs.map → chunk-62ZP23AW.cjs.map} +1 -1
  59. package/dist/{chunk-S4KQ5LV4.js → chunk-775A4ZMN.js} +40 -6
  60. package/dist/chunk-775A4ZMN.js.map +1 -0
  61. package/dist/{chunk-QYWINYEA.cjs → chunk-7BQXPCGN.cjs} +830 -170
  62. package/dist/chunk-7BQXPCGN.cjs.map +1 -0
  63. package/dist/{chunk-FJMPR3OH.cjs → chunk-7EO3TCQB.cjs} +33 -7
  64. package/dist/chunk-7EO3TCQB.cjs.map +1 -0
  65. package/dist/chunk-7GT72YHH.cjs +1979 -0
  66. package/dist/chunk-7GT72YHH.cjs.map +1 -0
  67. package/dist/{chunk-SQRD2CYF.js → chunk-7VQXLT5O.js} +717 -76
  68. package/dist/chunk-7VQXLT5O.js.map +1 -0
  69. package/dist/{chunk-BCP7LLOY.js → chunk-7Z5OR7KO.js} +2706 -625
  70. package/dist/chunk-7Z5OR7KO.js.map +1 -0
  71. package/dist/chunk-A4OC4DVN.cjs +12 -0
  72. package/dist/{chunk-4SZ6XPTG.cjs.map → chunk-A4OC4DVN.cjs.map} +1 -1
  73. package/dist/{chunk-TDXIBCGY.cjs → chunk-A7J2YDDI.cjs} +5 -3
  74. package/dist/chunk-A7J2YDDI.cjs.map +1 -0
  75. package/dist/{chunk-FMMIX6N4.js → chunk-AKLS3BYZ.js} +56 -5
  76. package/dist/chunk-AKLS3BYZ.js.map +1 -0
  77. package/dist/{chunk-D7PG5D5K.js → chunk-AMKPPFUO.js} +32 -6
  78. package/dist/chunk-AMKPPFUO.js.map +1 -0
  79. package/dist/{chunk-PAW2XUZN.js → chunk-ASTI57H3.js} +3 -3
  80. package/dist/{chunk-PAW2XUZN.js.map → chunk-ASTI57H3.js.map} +1 -1
  81. package/dist/{chunk-FMGEZBAQ.js → chunk-BKCUOV7A.js} +27 -5
  82. package/dist/chunk-BKCUOV7A.js.map +1 -0
  83. package/dist/chunk-BSFJMMV3.cjs +268 -0
  84. package/dist/chunk-BSFJMMV3.cjs.map +1 -0
  85. package/dist/{chunk-63KCKSSH.js → chunk-C23WSN5E.js} +209 -24
  86. package/dist/chunk-C23WSN5E.js.map +1 -0
  87. package/dist/{chunk-JRP3VGHS.js → chunk-CBTIUB76.js} +3 -3
  88. package/dist/{chunk-JRP3VGHS.js.map → chunk-CBTIUB76.js.map} +1 -1
  89. package/dist/chunk-CNV4TXJG.js +58 -0
  90. package/dist/chunk-CNV4TXJG.js.map +1 -0
  91. package/dist/{chunk-QB6VMOJ2.cjs → chunk-CXBHOOIQ.cjs} +45 -10
  92. package/dist/chunk-CXBHOOIQ.cjs.map +1 -0
  93. package/dist/{chunk-46GDII45.js → chunk-DCQVHAYQ.js} +5 -5
  94. package/dist/{chunk-46GDII45.js.map → chunk-DCQVHAYQ.js.map} +1 -1
  95. package/dist/chunk-DLNROMQ7.js +306 -0
  96. package/dist/chunk-DLNROMQ7.js.map +1 -0
  97. package/dist/chunk-DYATYRY4.js +47 -0
  98. package/dist/chunk-DYATYRY4.js.map +1 -0
  99. package/dist/chunk-E4WNQBEF.cjs +217 -0
  100. package/dist/chunk-E4WNQBEF.cjs.map +1 -0
  101. package/dist/{chunk-G6Q5UM7U.js → chunk-FWJKWH6U.js} +5 -3
  102. package/dist/chunk-FWJKWH6U.js.map +1 -0
  103. package/dist/{chunk-BNUFUFAU.js → chunk-HFHTMECK.js} +7 -7
  104. package/dist/chunk-HFHTMECK.js.map +1 -0
  105. package/dist/{chunk-TFMVL4QH.js → chunk-I5MOXA4H.js} +20 -14
  106. package/dist/chunk-I5MOXA4H.js.map +1 -0
  107. package/dist/{chunk-4MB3AQAQ.js → chunk-J3WZ3FA2.js} +77 -3
  108. package/dist/chunk-J3WZ3FA2.js.map +1 -0
  109. package/dist/{chunk-UR7W5YQK.js → chunk-JBQQ7THH.js} +5 -3
  110. package/dist/chunk-JBQQ7THH.js.map +1 -0
  111. package/dist/chunk-JIVMTW7W.js +3393 -0
  112. package/dist/chunk-JIVMTW7W.js.map +1 -0
  113. package/dist/{chunk-2Y4IFKW7.js → chunk-JXA2ZP2Q.js} +6 -17
  114. package/dist/chunk-JXA2ZP2Q.js.map +1 -0
  115. package/dist/{chunk-GYA4JRP5.js → chunk-JXXDZTMN.js} +2 -2
  116. package/dist/chunk-JXXDZTMN.js.map +1 -0
  117. package/dist/chunk-JZUR7ZWE.js +254 -0
  118. package/dist/chunk-JZUR7ZWE.js.map +1 -0
  119. package/dist/chunk-K5ELX2GT.js +248 -0
  120. package/dist/chunk-K5ELX2GT.js.map +1 -0
  121. package/dist/chunk-LBJKZXDE.cjs +257 -0
  122. package/dist/chunk-LBJKZXDE.cjs.map +1 -0
  123. package/dist/{chunk-FGO5JFVJ.cjs → chunk-M4BDU5RX.cjs} +12 -12
  124. package/dist/{chunk-FGO5JFVJ.cjs.map → chunk-M4BDU5RX.cjs.map} +1 -1
  125. package/dist/{chunk-MIJKEVV7.js → chunk-MSY7FSX4.js} +37 -4
  126. package/dist/chunk-MSY7FSX4.js.map +1 -0
  127. package/dist/{chunk-ST3LPB2V.cjs → chunk-MUK4BU7K.cjs} +788 -146
  128. package/dist/chunk-MUK4BU7K.cjs.map +1 -0
  129. package/dist/{chunk-MCHP7RHZ.cjs → chunk-MXJDTH5B.cjs} +64 -41
  130. package/dist/chunk-MXJDTH5B.cjs.map +1 -0
  131. package/dist/{chunk-2VLBGQBY.cjs → chunk-N3257XE6.cjs} +724 -577
  132. package/dist/chunk-N3257XE6.cjs.map +1 -0
  133. package/dist/chunk-N66HCGCY.cjs +57 -0
  134. package/dist/chunk-N66HCGCY.cjs.map +1 -0
  135. package/dist/{chunk-CPEL3YIR.cjs → chunk-NFCVHQ5P.cjs} +55 -22
  136. package/dist/chunk-NFCVHQ5P.cjs.map +1 -0
  137. package/dist/{chunk-C4F7VJ5D.cjs → chunk-NI72YOJB.cjs} +84 -2
  138. package/dist/chunk-NI72YOJB.cjs.map +1 -0
  139. package/dist/{chunk-EE7N5XXQ.cjs → chunk-NK5Q7UNE.cjs} +10 -21
  140. package/dist/chunk-NK5Q7UNE.cjs.map +1 -0
  141. package/dist/{chunk-PHXITZE4.js → chunk-NMWDXFPH.js} +4 -4
  142. package/dist/{chunk-PHXITZE4.js.map → chunk-NMWDXFPH.js.map} +1 -1
  143. package/dist/{chunk-FSXTPBRN.js → chunk-NQ6BRJBE.js} +416 -850
  144. package/dist/chunk-NQ6BRJBE.js.map +1 -0
  145. package/dist/chunk-OH5E5KIO.js +2057 -0
  146. package/dist/chunk-OH5E5KIO.js.map +1 -0
  147. package/dist/chunk-ONU3HIED.cjs +2082 -0
  148. package/dist/chunk-ONU3HIED.cjs.map +1 -0
  149. package/dist/{chunk-STQ3BSED.cjs → chunk-PNN7RHVR.cjs} +66 -44
  150. package/dist/chunk-PNN7RHVR.cjs.map +1 -0
  151. package/dist/{chunk-6DCB664D.js → chunk-PQBQG7IM.js} +3 -3
  152. package/dist/{chunk-6DCB664D.js.map → chunk-PQBQG7IM.js.map} +1 -1
  153. package/dist/{chunk-ACSVZPK7.cjs → chunk-PWLJ77UV.cjs} +5 -3
  154. package/dist/chunk-PWLJ77UV.cjs.map +1 -0
  155. package/dist/chunk-Q7Q4WSLJ.cjs +328 -0
  156. package/dist/chunk-Q7Q4WSLJ.cjs.map +1 -0
  157. package/dist/{chunk-BEFM74L2.js → chunk-QLRESYPU.js} +637 -493
  158. package/dist/chunk-QLRESYPU.js.map +1 -0
  159. package/dist/{chunk-SBPC5IP3.js → chunk-QWX5YA3K.js} +784 -202
  160. package/dist/chunk-QWX5YA3K.js.map +1 -0
  161. package/dist/{chunk-TCRIQMBU.js → chunk-RJS7DECT.js} +8 -9
  162. package/dist/chunk-RJS7DECT.js.map +1 -0
  163. package/dist/{chunk-6JZUSDY2.cjs → chunk-RMQLSPA2.cjs} +297 -27
  164. package/dist/chunk-RMQLSPA2.cjs.map +1 -0
  165. package/dist/{chunk-SJDMVITW.cjs → chunk-RT5ZY4XA.cjs} +6 -5
  166. package/dist/chunk-RT5ZY4XA.cjs.map +1 -0
  167. package/dist/{chunk-IJTLXNGJ.js → chunk-T4XNKYXB.js} +780 -127
  168. package/dist/chunk-T4XNKYXB.js.map +1 -0
  169. package/dist/{chunk-PDGEXGS6.cjs → chunk-TQR4KBY2.cjs} +354 -182
  170. package/dist/chunk-TQR4KBY2.cjs.map +1 -0
  171. package/dist/chunk-TTAITEPJ.cjs +755 -0
  172. package/dist/chunk-TTAITEPJ.cjs.map +1 -0
  173. package/dist/{chunk-NN3QSOVS.cjs → chunk-U5SON7R2.cjs} +27 -27
  174. package/dist/{chunk-NN3QSOVS.cjs.map → chunk-U5SON7R2.cjs.map} +1 -1
  175. package/dist/{chunk-A2I2XO52.cjs → chunk-U63GDNRC.cjs} +32 -26
  176. package/dist/chunk-U63GDNRC.cjs.map +1 -0
  177. package/dist/{chunk-YNULOIR5.cjs → chunk-UDISNXDL.cjs} +64 -43
  178. package/dist/chunk-UDISNXDL.cjs.map +1 -0
  179. package/dist/{chunk-GWEDD3DH.js → chunk-UV3SN74I.js} +5 -5
  180. package/dist/{chunk-GWEDD3DH.js.map → chunk-UV3SN74I.js.map} +1 -1
  181. package/dist/{chunk-U5W4LKZV.cjs → chunk-VCRRKBLN.cjs} +9 -9
  182. package/dist/{chunk-U5W4LKZV.cjs.map → chunk-VCRRKBLN.cjs.map} +1 -1
  183. package/dist/{chunk-EFELJVLA.js → chunk-VGTJPTIC.js} +28 -5
  184. package/dist/chunk-VGTJPTIC.js.map +1 -0
  185. package/dist/chunk-VQH4VAWD.cjs +12 -0
  186. package/dist/{chunk-EPTSMFH7.cjs.map → chunk-VQH4VAWD.cjs.map} +1 -1
  187. package/dist/{chunk-SNXVDZAJ.js → chunk-W6OG3HDG.js} +5 -4
  188. package/dist/chunk-W6OG3HDG.js.map +1 -0
  189. package/dist/chunk-WDGA7IYB.js +207 -0
  190. package/dist/chunk-WDGA7IYB.js.map +1 -0
  191. package/dist/chunk-WEVQJ5LH.js +736 -0
  192. package/dist/chunk-WEVQJ5LH.js.map +1 -0
  193. package/dist/{chunk-3PRKZW6D.cjs → chunk-XBYVV3MP.cjs} +60 -5
  194. package/dist/chunk-XBYVV3MP.cjs.map +1 -0
  195. package/dist/{chunk-GFRGG2US.cjs → chunk-XCAGZAKP.cjs} +7 -7
  196. package/dist/{chunk-GFRGG2US.cjs.map → chunk-XCAGZAKP.cjs.map} +1 -1
  197. package/dist/{chunk-XR4YZFKW.cjs → chunk-XDF2UPEQ.cjs} +3864 -1783
  198. package/dist/chunk-XDF2UPEQ.cjs.map +1 -0
  199. package/dist/{chunk-7V2FGGI2.cjs → chunk-XMQSEJCF.cjs} +632 -1080
  200. package/dist/chunk-XMQSEJCF.cjs.map +1 -0
  201. package/dist/chunk-XNLIZYRZ.cjs +3432 -0
  202. package/dist/chunk-XNLIZYRZ.cjs.map +1 -0
  203. package/dist/{chunk-66UVLHQA.cjs → chunk-XNSI2FJO.cjs} +99 -100
  204. package/dist/chunk-XNSI2FJO.cjs.map +1 -0
  205. package/dist/chunk-XQSCL77R.cjs +60 -0
  206. package/dist/chunk-XQSCL77R.cjs.map +1 -0
  207. package/dist/{chunk-SVJ5GEXW.cjs → chunk-XUO3KQFO.cjs} +2 -2
  208. package/dist/chunk-XUO3KQFO.cjs.map +1 -0
  209. package/dist/{chunk-HJH3RMXG.cjs → chunk-YAAM3M2S.cjs} +10 -10
  210. package/dist/{chunk-HJH3RMXG.cjs.map → chunk-YAAM3M2S.cjs.map} +1 -1
  211. package/dist/{chunk-ATLN63JA.js → chunk-YBFHZUXX.js} +6 -6
  212. package/dist/{chunk-ATLN63JA.js.map → chunk-YBFHZUXX.js.map} +1 -1
  213. package/dist/{chunk-K3BUWSFR.js → chunk-YDFDBE6D.js} +119 -6
  214. package/dist/chunk-YDFDBE6D.js.map +1 -0
  215. package/dist/{chunk-OSZPLZIV.cjs → chunk-YVWGEQJE.cjs} +318 -132
  216. package/dist/chunk-YVWGEQJE.cjs.map +1 -0
  217. package/dist/{chunk-QT6V3YRH.js → chunk-YWGVVALJ.js} +3 -3
  218. package/dist/{chunk-QT6V3YRH.js.map → chunk-YWGVVALJ.js.map} +1 -1
  219. package/dist/core/index.cjs +40 -41
  220. package/dist/core/index.d.cts +4 -5
  221. package/dist/core/index.d.ts +4 -5
  222. package/dist/core/index.js +8 -9
  223. package/dist/{ddl-eWg7hx6R.d.cts → ddl-BJcOp4WZ.d.cts} +3 -3
  224. package/dist/{ddl-D5369kOY.d.ts → ddl-BXfGHbPN.d.ts} +3 -3
  225. package/dist/graph-extension/index.cjs +26 -23
  226. package/dist/graph-extension/index.d.cts +16 -6
  227. package/dist/graph-extension/index.d.ts +16 -6
  228. package/dist/graph-extension/index.js +7 -8
  229. package/dist/graph-merge/index.cjs +2459 -655
  230. package/dist/graph-merge/index.cjs.map +1 -1
  231. package/dist/graph-merge/index.d.cts +170 -33
  232. package/dist/graph-merge/index.d.ts +170 -33
  233. package/dist/graph-merge/index.js +2269 -468
  234. package/dist/graph-merge/index.js.map +1 -1
  235. package/dist/{index-By89Sezh.d.ts → index-BSHvKfok.d.ts} +221 -10
  236. package/dist/{index-DcQ3Sxs-.d.cts → index-DxaYCv8Y.d.cts} +221 -10
  237. package/dist/index.cjs +330 -269
  238. package/dist/index.cjs.map +1 -1
  239. package/dist/index.d.cts +590 -576
  240. package/dist/index.d.ts +590 -576
  241. package/dist/index.js +73 -50
  242. package/dist/index.js.map +1 -1
  243. package/dist/indexes/index.cjs +17 -17
  244. package/dist/indexes/index.d.cts +4 -4
  245. package/dist/indexes/index.d.ts +4 -4
  246. package/dist/indexes/index.js +10 -10
  247. package/dist/interchange/index.cjs +165 -50
  248. package/dist/interchange/index.cjs.map +1 -1
  249. package/dist/interchange/index.d.cts +261 -16
  250. package/dist/interchange/index.d.ts +261 -16
  251. package/dist/interchange/index.js +128 -24
  252. package/dist/interchange/index.js.map +1 -1
  253. package/dist/{manager-B0KjKE93.d.ts → manager-CfZAimti.d.ts} +36 -5
  254. package/dist/{manager-Cn0NFIhN.d.cts → manager-HGk6E_HW.d.cts} +36 -5
  255. package/dist/{materialize-indexes-BD4V3svD.d.ts → materialize-indexes-6A7dWGtb.d.cts} +10 -2
  256. package/dist/{materialize-indexes-DVRhd5h4.d.cts → materialize-indexes-BMJP6Tms.d.ts} +10 -2
  257. package/dist/{postgres-DaEWvN4x.d.cts → postgres-DFYWENdR.d.cts} +1961 -439
  258. package/dist/{postgres-u0a0HN2D.d.ts → postgres-e7a9TdvR.d.ts} +1961 -439
  259. package/dist/profiler/index.cjs +15 -15
  260. package/dist/profiler/index.d.cts +9 -10
  261. package/dist/profiler/index.d.ts +9 -10
  262. package/dist/profiler/index.js +4 -4
  263. package/dist/provenance/index.cjs +46 -48
  264. package/dist/provenance/index.cjs.map +1 -1
  265. package/dist/provenance/index.d.cts +7 -7
  266. package/dist/provenance/index.d.ts +7 -7
  267. package/dist/provenance/index.js +12 -14
  268. package/dist/provenance/index.js.map +1 -1
  269. package/dist/schema/index.cjs +50 -49
  270. package/dist/schema/index.d.cts +9 -16
  271. package/dist/schema/index.d.ts +9 -16
  272. package/dist/schema/index.js +23 -22
  273. package/dist/{searchable-CnYEancP.d.ts → searchable-9OQoPuRs.d.ts} +1 -2
  274. package/dist/{searchable-BT7j9_IK.d.cts → searchable-CIje5XYD.d.cts} +1 -2
  275. package/dist/{sqlite-BrMoSsI7.d.cts → sqlite-DerU5tc7.d.ts} +2029 -347
  276. package/dist/{sqlite-CHhZUyO5.d.ts → sqlite-DitnISa9.d.cts} +2029 -347
  277. package/dist/{store-view-Bvdku0Ht.d.ts → store-DawaWWjJ.d.ts} +3145 -2556
  278. package/dist/{store-view-w-md0nQ4.d.cts → store-RwTJx8LX.d.cts} +3145 -2556
  279. package/dist/{temporal-BCORwUau.d.cts → temporal-Bn-Fi8FJ.d.cts} +1 -1
  280. package/dist/{temporal--x9T8K4S.d.ts → temporal-BtM4UALv.d.ts} +1 -1
  281. package/dist/{types-6-WJmSD4.d.cts → types-CoIx8HX5.d.cts} +1 -1
  282. package/dist/{types-Cjvkj0jA.d.ts → types-HkveCCx0.d.cts} +866 -21
  283. package/dist/{types-Cjvkj0jA.d.cts → types-HkveCCx0.d.ts} +866 -21
  284. package/dist/{types-COODtTJU.d.ts → types-KFfk-8Ah.d.ts} +1 -1
  285. package/dist/{where-CUQmCR6d.d.cts → where--fk7_0kv.d.cts} +1 -1
  286. package/dist/{where-5xVawAwL.d.ts → where-ws5hf-Ov.d.ts} +1 -1
  287. package/package.json +1 -1
  288. package/dist/chunk-2BIG7U6E.cjs +0 -83
  289. package/dist/chunk-2BIG7U6E.cjs.map +0 -1
  290. package/dist/chunk-2L54C2C2.js +0 -144
  291. package/dist/chunk-2L54C2C2.js.map +0 -1
  292. package/dist/chunk-2VLBGQBY.cjs.map +0 -1
  293. package/dist/chunk-2WDD2NO3.js +0 -59
  294. package/dist/chunk-2WDD2NO3.js.map +0 -1
  295. package/dist/chunk-2Y4IFKW7.js.map +0 -1
  296. package/dist/chunk-35S6P5ZU.js +0 -27
  297. package/dist/chunk-35S6P5ZU.js.map +0 -1
  298. package/dist/chunk-3PRKZW6D.cjs.map +0 -1
  299. package/dist/chunk-4MB3AQAQ.js.map +0 -1
  300. package/dist/chunk-4SZ6XPTG.cjs +0 -12
  301. package/dist/chunk-5MUSU4ZP.cjs.map +0 -1
  302. package/dist/chunk-63KCKSSH.js.map +0 -1
  303. package/dist/chunk-66UVLHQA.cjs.map +0 -1
  304. package/dist/chunk-6JZUSDY2.cjs.map +0 -1
  305. package/dist/chunk-764JHTLT.cjs +0 -15
  306. package/dist/chunk-764JHTLT.cjs.map +0 -1
  307. package/dist/chunk-7G32LIQM.js.map +0 -1
  308. package/dist/chunk-7V2FGGI2.cjs.map +0 -1
  309. package/dist/chunk-A2I2XO52.cjs.map +0 -1
  310. package/dist/chunk-A4PBRX4C.cjs +0 -100
  311. package/dist/chunk-A4PBRX4C.cjs.map +0 -1
  312. package/dist/chunk-ACSVZPK7.cjs.map +0 -1
  313. package/dist/chunk-ALFUGRYB.cjs +0 -1282
  314. package/dist/chunk-ALFUGRYB.cjs.map +0 -1
  315. package/dist/chunk-B75XRV3O.js +0 -125
  316. package/dist/chunk-B75XRV3O.js.map +0 -1
  317. package/dist/chunk-BCP7LLOY.js.map +0 -1
  318. package/dist/chunk-BEFM74L2.js.map +0 -1
  319. package/dist/chunk-BNUFUFAU.js.map +0 -1
  320. package/dist/chunk-C4F7VJ5D.cjs.map +0 -1
  321. package/dist/chunk-CPEL3YIR.cjs.map +0 -1
  322. package/dist/chunk-D7PG5D5K.js.map +0 -1
  323. package/dist/chunk-DI74SMXS.cjs +0 -29
  324. package/dist/chunk-DI74SMXS.cjs.map +0 -1
  325. package/dist/chunk-DK2S42XB.js +0 -77
  326. package/dist/chunk-DK2S42XB.js.map +0 -1
  327. package/dist/chunk-DRACN6XG.js +0 -27
  328. package/dist/chunk-DRACN6XG.js.map +0 -1
  329. package/dist/chunk-EE7N5XXQ.cjs.map +0 -1
  330. package/dist/chunk-EFELJVLA.js.map +0 -1
  331. package/dist/chunk-EPTSMFH7.cjs +0 -12
  332. package/dist/chunk-EQ7JKLZO.cjs +0 -157
  333. package/dist/chunk-EQ7JKLZO.cjs.map +0 -1
  334. package/dist/chunk-FJMPR3OH.cjs.map +0 -1
  335. package/dist/chunk-FMGEZBAQ.js.map +0 -1
  336. package/dist/chunk-FMMIX6N4.js.map +0 -1
  337. package/dist/chunk-FRHHDHKH.js.map +0 -1
  338. package/dist/chunk-FSXTPBRN.js.map +0 -1
  339. package/dist/chunk-G6Q5UM7U.js.map +0 -1
  340. package/dist/chunk-GYA4JRP5.js.map +0 -1
  341. package/dist/chunk-HOHAJ2NR.cjs +0 -61
  342. package/dist/chunk-HOHAJ2NR.cjs.map +0 -1
  343. package/dist/chunk-HOIFFY4M.js.map +0 -1
  344. package/dist/chunk-IIMQJYAM.js +0 -81
  345. package/dist/chunk-IIMQJYAM.js.map +0 -1
  346. package/dist/chunk-IJTLXNGJ.js.map +0 -1
  347. package/dist/chunk-ITE4IXAK.js +0 -25
  348. package/dist/chunk-ITE4IXAK.js.map +0 -1
  349. package/dist/chunk-K3BUWSFR.js.map +0 -1
  350. package/dist/chunk-KCO5EFJU.js +0 -79
  351. package/dist/chunk-KCO5EFJU.js.map +0 -1
  352. package/dist/chunk-KKYELPZ2.cjs +0 -83
  353. package/dist/chunk-KKYELPZ2.cjs.map +0 -1
  354. package/dist/chunk-MCHP7RHZ.cjs.map +0 -1
  355. package/dist/chunk-MIJKEVV7.js.map +0 -1
  356. package/dist/chunk-NCX65HBY.cjs +0 -1396
  357. package/dist/chunk-NCX65HBY.cjs.map +0 -1
  358. package/dist/chunk-OSZPLZIV.cjs.map +0 -1
  359. package/dist/chunk-OVUUTCPJ.cjs.map +0 -1
  360. package/dist/chunk-PDGEXGS6.cjs.map +0 -1
  361. package/dist/chunk-QB6VMOJ2.cjs.map +0 -1
  362. package/dist/chunk-QMQLUA66.js +0 -12
  363. package/dist/chunk-QMQLUA66.js.map +0 -1
  364. package/dist/chunk-QYWINYEA.cjs.map +0 -1
  365. package/dist/chunk-S4KQ5LV4.js.map +0 -1
  366. package/dist/chunk-SBPC5IP3.js.map +0 -1
  367. package/dist/chunk-SJDMVITW.cjs.map +0 -1
  368. package/dist/chunk-SNXVDZAJ.js.map +0 -1
  369. package/dist/chunk-SQRD2CYF.js.map +0 -1
  370. package/dist/chunk-ST3LPB2V.cjs.map +0 -1
  371. package/dist/chunk-STQ3BSED.cjs.map +0 -1
  372. package/dist/chunk-SVJ5GEXW.cjs.map +0 -1
  373. package/dist/chunk-TCRIQMBU.js.map +0 -1
  374. package/dist/chunk-TDXIBCGY.cjs.map +0 -1
  375. package/dist/chunk-TFMVL4QH.js.map +0 -1
  376. package/dist/chunk-TRF4EBJT.cjs +0 -30
  377. package/dist/chunk-TRF4EBJT.cjs.map +0 -1
  378. package/dist/chunk-TVLKA4AY.js +0 -94
  379. package/dist/chunk-TVLKA4AY.js.map +0 -1
  380. package/dist/chunk-UR7W5YQK.js.map +0 -1
  381. package/dist/chunk-VITTKBWF.js +0 -1263
  382. package/dist/chunk-VITTKBWF.js.map +0 -1
  383. package/dist/chunk-WBUFJ7BS.cjs +0 -131
  384. package/dist/chunk-WBUFJ7BS.cjs.map +0 -1
  385. package/dist/chunk-XR4YZFKW.cjs.map +0 -1
  386. package/dist/chunk-YNULOIR5.cjs.map +0 -1
  387. package/dist/chunk-ZDH3DX3C.cjs +0 -30
  388. package/dist/chunk-ZDH3DX3C.cjs.map +0 -1
  389. package/dist/chunk-ZTAJL4DT.cjs +0 -85
  390. package/dist/chunk-ZTAJL4DT.cjs.map +0 -1
  391. package/dist/define-graph-DVF-oN1i.d.cts +0 -173
  392. package/dist/define-graph-SvYXOl78.d.ts +0 -173
@@ -1,17 +1,20 @@
1
- import { compareStrings } from './chunk-DRACN6XG.js';
2
- import { META_EDGE_BRAND, getTypeName, defineEdge, defineNode } from './chunk-2Y4IFKW7.js';
3
- import { canonicalEqual, sortedReplacer } from './chunk-UR7W5YQK.js';
4
- import { isMissingTableError } from './chunk-B75XRV3O.js';
5
- import { getNodeKinds, getEdgeKinds, autoDeriveVectorIndexes, mergeVectorIndexes } from './chunk-S4KQ5LV4.js';
6
- import { nowIso } from './chunk-KCO5EFJU.js';
7
- import { defineNodeIndex, defineEdgeIndex } from './chunk-TFMVL4QH.js';
1
+ import { META_EDGE_BRAND, getTypeName, defineEdge, defineNode } from './chunk-JXA2ZP2Q.js';
2
+ import { separationRebuildRequired, hasAssertionsTouchingKinds, lockIdentityGraph, lockIdentityEnablementNodes, purgeAssertionsWithUnregisteredKinds, deleteAssertionsTouchingKinds, rebuildIdentityClosureForContext } from './chunk-JIVMTW7W.js';
3
+ import { lockRecordedGraphWrite, withRecordedIdentityMutationTarget, compareStrings } from './chunk-NQ6BRJBE.js';
4
+ import { canonicalEqual, sortedReplacer } from './chunk-JBQQ7THH.js';
5
+ import { isMissingTableError, errorChain, isPostgresConcurrentDdlRaceError } from './chunk-JZUR7ZWE.js';
6
+ import { createSqlSchema, requireSqlSchema } from './chunk-MSY7FSX4.js';
7
+ import { getNodeKinds, getEdgeKinds, autoDeriveVectorIndexes, mergeVectorIndexes } from './chunk-775A4ZMN.js';
8
+ import { captureWherePredicate } from './chunk-WDGA7IYB.js';
9
+ import { nowIso } from './chunk-DLNROMQ7.js';
10
+ import { defineNodeIndex, defineEdgeIndex } from './chunk-I5MOXA4H.js';
8
11
  import { sha256Hex } from './chunk-K34OPSJK.js';
9
- import { requireDefined } from './chunk-QMQLUA66.js';
12
+ import { asCompiledRowsSql, sql } from './chunk-PQBQG7IM.js';
10
13
  import { resolveGraphVectorSlots, embedding, searchable } from './chunk-PC2UBAUB.js';
11
- import { isReachable, LEGACY_GRAPH_EXTENSION_VERSION, unwrap, validateGraphExtension, KindCollisionError, GraphExtensionUnresolvedEndpointError, RemoveCompileTimeKindError, KindHasReferentsError, computeTransitiveClosure, invertClosure } from './chunk-IJTLXNGJ.js';
12
- import { ALL_META_EDGE_NAMES, META_EDGE_IMPLIES, META_EDGE_INVERSE_OF, META_EDGE_PART_OF, META_EDGE_HAS_PART, META_EDGE_DISJOINT_WITH, META_EDGE_DIFFERENT_FROM, META_EDGE_SAME_AS, META_EDGE_EQUIVALENT_TO, META_EDGE_RELATED_TO, META_EDGE_BROADER, META_EDGE_NARROWER, META_EDGE_SUB_CLASS_OF } from './chunk-GYA4JRP5.js';
13
- import { compactUndefined, freezeDeep } from './chunk-ITE4IXAK.js';
14
- import { ConfigurationError, KindNotFoundError, DatabaseOperationError, MigrationError, StaleVersionError } from './chunk-4MB3AQAQ.js';
14
+ import { LEGACY_GRAPH_EXTENSION_VERSION, computeClosuresFromOntology, unwrap, validateGraphExtension, KindCollisionError, GraphExtensionUnresolvedEndpointError, isExternalIri, GraphExtensionUnresolvedOntologyEndpointError, RemoveCompileTimeKindError, KindHasReferentsError, KindRegistry, createEmptyClosures, validateOntologyRelations, computeClosuresFromNamedOntology } from './chunk-T4XNKYXB.js';
15
+ import { ALL_META_EDGE_NAMES, META_EDGE_IMPLIES, META_EDGE_INVERSE_OF, META_EDGE_PART_OF, META_EDGE_HAS_PART, META_EDGE_DISJOINT_WITH, META_EDGE_DIFFERENT_FROM, META_EDGE_SAME_AS, META_EDGE_EQUIVALENT_TO, META_EDGE_RELATED_TO, META_EDGE_BROADER, META_EDGE_NARROWER, META_EDGE_SUB_CLASS_OF } from './chunk-JXXDZTMN.js';
16
+ import { ConfigurationError, KindNotFoundError, DatabaseOperationError, MigrationError, StaleVersionError } from './chunk-J3WZ3FA2.js';
17
+ import { requireDefined, hasOwnKey, createDataKeyedBag, compactUndefined, freezeDeep } from './chunk-DYATYRY4.js';
15
18
  import { z } from 'zod';
16
19
 
17
20
  // src/ontology/core-meta-edges.ts
@@ -96,7 +99,7 @@ var sameAsMetaEdge = createMetaEdge(META_EDGE_SAME_AS, {
96
99
  symmetric: true,
97
100
  transitive: true,
98
101
  inference: "substitution",
99
- description: "Same individual (for deduplication)"
102
+ description: "Deprecated type-level equivalence alias"
100
103
  });
101
104
  function sameAs(kindA, kindBOrIri) {
102
105
  return {
@@ -108,7 +111,7 @@ function sameAs(kindA, kindBOrIri) {
108
111
  var differentFromMetaEdge = createMetaEdge(META_EDGE_DIFFERENT_FROM, {
109
112
  symmetric: true,
110
113
  inference: "constraint",
111
- description: "Explicitly different individuals"
114
+ description: "Deprecated decorative type-level non-identity relation"
112
115
  });
113
116
  function differentFrom(kindA, kindB) {
114
117
  return {
@@ -199,7 +202,9 @@ var core = {
199
202
  narrower,
200
203
  relatedTo,
201
204
  equivalentTo,
205
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- compatibility member until the next major
202
206
  sameAs,
207
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- compatibility member until the next major
203
208
  differentFrom,
204
209
  disjointWith,
205
210
  partOf,
@@ -213,6 +218,7 @@ function computeSchemaDiff(before, after) {
213
218
  const nodeChanges = diffNodes(before.nodes, after.nodes);
214
219
  const edgeChanges = diffEdges(before.edges, after.edges);
215
220
  const ontologyChanges = diffOntology(before.ontology, after.ontology);
221
+ const identityChange = diffIdentity(before.identity, after.identity);
216
222
  const indexChanges = diffIndexes(before.indexes, after.indexes);
217
223
  const extensionChange = diffExtension(before.extension, after.extension);
218
224
  const deprecatedKindsChange = diffDeprecatedKinds(
@@ -225,14 +231,13 @@ function computeSchemaDiff(before, after) {
225
231
  ...ontologyChanges,
226
232
  ...indexChanges
227
233
  ];
228
- const hasBreakingChanges = allChanges.some(
229
- (change) => change.severity === "breaking"
230
- );
231
- const hasChanges = allChanges.length > 0 || extensionChange !== void 0 || deprecatedKindsChange !== void 0;
234
+ const hasBreakingChanges = allChanges.some((change) => change.severity === "breaking") || identityChange?.severity === "breaking";
235
+ const hasChanges = allChanges.length > 0 || identityChange !== void 0 || extensionChange !== void 0 || deprecatedKindsChange !== void 0;
232
236
  const summary = generateSummary(
233
237
  nodeChanges,
234
238
  edgeChanges,
235
239
  ontologyChanges,
240
+ identityChange,
236
241
  indexChanges,
237
242
  extensionChange,
238
243
  deprecatedKindsChange
@@ -243,6 +248,7 @@ function computeSchemaDiff(before, after) {
243
248
  nodes: nodeChanges,
244
249
  edges: edgeChanges,
245
250
  ontology: ontologyChanges,
251
+ ...identityChange === void 0 ? {} : { identity: identityChange },
246
252
  indexes: indexChanges,
247
253
  ...extensionChange === void 0 ? {} : { extension: extensionChange },
248
254
  ...deprecatedKindsChange === void 0 ? {} : { deprecatedKinds: deprecatedKindsChange },
@@ -252,6 +258,29 @@ function computeSchemaDiff(before, after) {
252
258
  summary
253
259
  };
254
260
  }
261
+ function diffIdentity(before, after) {
262
+ if (before === void 0 && after === void 0) return;
263
+ if (before === void 0) {
264
+ return {
265
+ type: "added",
266
+ severity: "safe",
267
+ details: "Operational Identity enabled"
268
+ };
269
+ }
270
+ if (after === void 0) {
271
+ return {
272
+ type: "removed",
273
+ severity: "breaking",
274
+ details: "Operational Identity disabled"
275
+ };
276
+ }
277
+ if (before.sameIdAcrossKinds === after.sameIdAcrossKinds) return;
278
+ return {
279
+ type: "modified",
280
+ severity: "breaking",
281
+ details: `Operational Identity sameIdAcrossKinds changed from "${before.sameIdAcrossKinds}" to "${after.sameIdAcrossKinds}"`
282
+ };
283
+ }
255
284
  function diffNodes(before, after) {
256
285
  const changes = [];
257
286
  const beforeNames = new Set(Object.keys(before));
@@ -327,7 +356,7 @@ function orderNormalizedSchema(value) {
327
356
  return value.map((item) => orderNormalizedSchema(item));
328
357
  }
329
358
  if (value !== null && typeof value === "object") {
330
- const normalized = {};
359
+ const normalized = createDataKeyedBag();
331
360
  for (const [key, entry] of Object.entries(value)) {
332
361
  normalized[key] = normalizedKeywordValue(key, entry);
333
362
  }
@@ -350,7 +379,7 @@ function normalizedDependentRequired(value) {
350
379
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
351
380
  return value;
352
381
  }
353
- const normalized = {};
382
+ const normalized = createDataKeyedBag();
354
383
  for (const [name, required] of Object.entries(value)) {
355
384
  normalized[name] = Array.isArray(required) ? sortedByCanonicalForm(required) : required;
356
385
  }
@@ -360,7 +389,7 @@ function normalizedSubschemaMap(value) {
360
389
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
361
390
  return orderNormalizedSchema(value);
362
391
  }
363
- const normalized = {};
392
+ const normalized = createDataKeyedBag();
364
393
  for (const [name, subschema] of Object.entries(value)) {
365
394
  normalized[name] = orderNormalizedSchema(subschema);
366
395
  }
@@ -440,7 +469,7 @@ var NON_CONSTRAINING_KEYWORDS = /* @__PURE__ */ new Set([
440
469
  "$schema"
441
470
  ]);
442
471
  function stripSchemaMetadata(schema) {
443
- const stripped = {};
472
+ const stripped = createDataKeyedBag();
444
473
  for (const [key, value] of Object.entries(schema)) {
445
474
  if (!NON_CONSTRAINING_KEYWORDS.has(key)) stripped[key] = value;
446
475
  }
@@ -470,7 +499,7 @@ function isBreakingObjectSchemaChange(before, after) {
470
499
  const beforeRequired = new Set(before.required);
471
500
  const afterRequired = new Set(after.required);
472
501
  for (const key of Object.keys(beforeProps)) {
473
- if (!(key in afterProps)) return true;
502
+ if (!hasOwnKey(afterProps, key)) return true;
474
503
  }
475
504
  for (const key of afterRequired) {
476
505
  if (!beforeRequired.has(key)) return true;
@@ -487,9 +516,15 @@ function classifyPropertyChanges(kind, before, after) {
487
516
  const afterProps = after.properties ?? {};
488
517
  const beforeRequired = new Set(before.required);
489
518
  const afterRequired = new Set(after.required);
490
- const removed = Object.keys(beforeProps).filter((p) => !(p in afterProps));
491
- const added = Object.keys(afterProps).filter((p) => !(p in beforeProps));
492
- const newRequired = [...afterRequired].filter((p) => !beforeRequired.has(p));
519
+ const removed = Object.keys(beforeProps).filter(
520
+ (property) => !hasOwnKey(afterProps, property)
521
+ );
522
+ const added = Object.keys(afterProps).filter(
523
+ (property) => !hasOwnKey(beforeProps, property)
524
+ );
525
+ const newRequired = [...afterRequired].filter(
526
+ (property) => !beforeRequired.has(property)
527
+ );
493
528
  const breakingProps = [];
494
529
  for (const [property, beforeProperty] of Object.entries(beforeProps)) {
495
530
  const afterProperty = afterProps[property];
@@ -783,7 +818,7 @@ function diffDeprecatedKinds(before, after) {
783
818
  details: `Deprecated kinds: ${parts.join("; ")}`
784
819
  };
785
820
  }
786
- function generateSummary(nodeChanges, edgeChanges, ontologyChanges, indexChanges, extensionChange, deprecatedKindsChange) {
821
+ function generateSummary(nodeChanges, edgeChanges, ontologyChanges, identityChange, indexChanges, extensionChange, deprecatedKindsChange) {
787
822
  const parts = [];
788
823
  const nodeAdded = nodeChanges.filter((c) => c.type === "added").length;
789
824
  const nodeRemoved = nodeChanges.filter((c) => c.type === "removed").length;
@@ -810,6 +845,9 @@ function generateSummary(nodeChanges, edgeChanges, ontologyChanges, indexChanges
810
845
  if (ontologyAdded > 0 || ontologyRemoved > 0) {
811
846
  parts.push(`Ontology: ${ontologyAdded} added, ${ontologyRemoved} removed`);
812
847
  }
848
+ if (identityChange !== void 0) {
849
+ parts.push(`Identity: ${identityChange.type}`);
850
+ }
813
851
  const indexAdded = indexChanges.filter((c) => c.type === "added").length;
814
852
  const indexRemoved = indexChanges.filter((c) => c.type === "removed").length;
815
853
  const indexModified = indexChanges.filter(
@@ -858,419 +896,30 @@ function getMigrationActions(diff) {
858
896
  actions.push(`DELETE data for removed edge kind "${change.kind}"`);
859
897
  }
860
898
  }
861
- return actions;
862
- }
863
-
864
- // src/registry/kind-registry.ts
865
- var KindRegistry = class {
866
- // === Node & Edge Kinds ===
867
- nodeKinds;
868
- edgeKinds;
869
- // === Subsumption (subClassOf) ===
870
- // Transitive closure for inheritance
871
- subClassAncestors;
872
- subClassDescendants;
873
- // === Hierarchy (broader/narrower) ===
874
- // Transitive closure for concept hierarchy (separate from subClassOf!)
875
- broaderClosure;
876
- narrowerClosure;
877
- // === Equivalence ===
878
- equivalenceSets;
879
- iriToKind;
880
- // === Constraints ===
881
- disjointPairs;
882
- // Normalized pairs: "Organization|Person"
883
- // === Composition ===
884
- partOfClosure;
885
- hasPartClosure;
886
- // === Edge Relationships ===
887
- edgeInverses;
888
- edgeImplicationsClosure;
889
- edgeImplyingClosure;
890
- constructor(nodeKinds, edgeKinds, closures) {
891
- this.nodeKinds = nodeKinds;
892
- this.edgeKinds = edgeKinds;
893
- this.subClassAncestors = closures.subClassAncestors;
894
- this.subClassDescendants = closures.subClassDescendants;
895
- this.broaderClosure = closures.broaderClosure;
896
- this.narrowerClosure = closures.narrowerClosure;
897
- this.equivalenceSets = closures.equivalenceSets;
898
- this.iriToKind = closures.iriToKind;
899
- this.disjointPairs = closures.disjointPairs;
900
- this.partOfClosure = closures.partOfClosure;
901
- this.hasPartClosure = closures.hasPartClosure;
902
- this.edgeInverses = closures.edgeInverses;
903
- this.edgeImplicationsClosure = closures.edgeImplicationsClosure;
904
- this.edgeImplyingClosure = closures.edgeImplyingClosure;
905
- }
906
- // === Subsumption Methods ===
907
- /**
908
- * Checks if child is a subclass of parent (directly or transitively).
909
- */
910
- isSubClassOf(child, parent) {
911
- return isReachable(this.subClassAncestors, child, parent);
912
- }
913
- /**
914
- * Expands a kind to include all its subclasses.
915
- * Returns [kind, ...subclasses].
916
- */
917
- expandSubClasses(kind) {
918
- const descendants = this.subClassDescendants.get(kind) ?? /* @__PURE__ */ new Set();
919
- return [kind, ...descendants];
920
- }
921
- /**
922
- * Gets all ancestors of a kind (via subClassOf).
923
- */
924
- getAncestors(kind) {
925
- return this.subClassAncestors.get(kind) ?? /* @__PURE__ */ new Set();
926
- }
927
- /**
928
- * Gets all descendants of a kind (via subClassOf).
929
- */
930
- getDescendants(kind) {
931
- return this.subClassDescendants.get(kind) ?? /* @__PURE__ */ new Set();
932
- }
933
- // === Hierarchy Methods ===
934
- /**
935
- * Checks if narrowerConcept is narrower than broaderConcept.
936
- */
937
- isNarrowerThan(narrowerConcept, broaderConcept) {
938
- return isReachable(this.broaderClosure, narrowerConcept, broaderConcept);
939
- }
940
- /**
941
- * Checks if broaderConcept is broader than narrowerConcept.
942
- */
943
- isBroaderThan(broaderConcept, narrowerConcept) {
944
- return isReachable(this.narrowerClosure, broaderConcept, narrowerConcept);
945
- }
946
- /**
947
- * Expands to include all narrower concepts.
948
- */
949
- expandNarrower(kind) {
950
- const narrower2 = this.narrowerClosure.get(kind) ?? /* @__PURE__ */ new Set();
951
- return [kind, ...narrower2];
952
- }
953
- /**
954
- * Expands to include all broader concepts.
955
- */
956
- expandBroader(kind) {
957
- const broader2 = this.broaderClosure.get(kind) ?? /* @__PURE__ */ new Set();
958
- return [kind, ...broader2];
959
- }
960
- // === Equivalence Methods ===
961
- /**
962
- * Checks if two kinds are equivalent.
963
- */
964
- areEquivalent(a, b) {
965
- const equivalents = this.equivalenceSets.get(a);
966
- return equivalents?.has(b) ?? false;
967
- }
968
- /**
969
- * Gets all equivalents of a kind (including external IRIs).
970
- */
971
- getEquivalents(kind) {
972
- const equivalents = this.equivalenceSets.get(kind);
973
- return equivalents ? [...equivalents] : [];
974
- }
975
- /**
976
- * Resolves an external IRI to an internal kind name.
977
- */
978
- resolveIri(iri) {
979
- return this.iriToKind.get(iri);
980
- }
981
- // === Constraint Methods ===
982
- /**
983
- * Checks if two kinds are disjoint.
984
- */
985
- areDisjoint(a, b) {
986
- const normalizedPair = a < b ? `${a}|${b}` : `${b}|${a}`;
987
- return this.disjointPairs.has(normalizedPair);
988
- }
989
- /**
990
- * Gets all kinds that are disjoint with the given kind.
991
- */
992
- getDisjointKinds(kind) {
993
- const result = [];
994
- for (const pair of this.disjointPairs) {
995
- const parts = pair.split("|");
996
- const firstKind = requireDefined(parts[0]);
997
- const secondKind = requireDefined(parts[1]);
998
- if (firstKind === kind) result.push(secondKind);
999
- else if (secondKind === kind) result.push(firstKind);
1000
- }
1001
- return result;
1002
- }
1003
- // === Composition Methods ===
1004
- /**
1005
- * Checks if part is part of whole (directly or transitively).
1006
- */
1007
- isPartOf(part, whole) {
1008
- return isReachable(this.partOfClosure, part, whole);
1009
- }
1010
- /**
1011
- * Gets all wholes that contain this part.
1012
- */
1013
- getWholes(part) {
1014
- const wholes = this.partOfClosure.get(part);
1015
- return wholes ? [...wholes] : [];
1016
- }
1017
- /**
1018
- * Gets all parts of this whole.
1019
- */
1020
- getParts(whole) {
1021
- const parts = this.hasPartClosure.get(whole);
1022
- return parts ? [...parts] : [];
1023
- }
1024
- // === Edge Relationship Methods ===
1025
- /**
1026
- * Gets the inverse edge kind for a given edge kind.
1027
- * If edgeA inverseOf edgeB, then getInverseEdge("edgeA") returns "edgeB".
1028
- */
1029
- getInverseEdge(edgeKind) {
1030
- return this.edgeInverses.get(edgeKind);
1031
- }
1032
- /**
1033
- * Gets all edges implied by a given edge (transitively).
1034
- * If A implies B and B implies C, then getImpliedEdges("A") returns ["B", "C"].
1035
- */
1036
- getImpliedEdges(edgeKind) {
1037
- const implied = this.edgeImplicationsClosure.get(edgeKind);
1038
- return implied ? [...implied] : [];
1039
- }
1040
- /**
1041
- * Gets all edges that imply a given edge (transitively).
1042
- * If A implies B and B implies C, then getImplyingEdges("C") returns ["A", "B"].
1043
- * Used for query-time expansion: when querying for C, also include A and B edges.
1044
- */
1045
- getImplyingEdges(edgeKind) {
1046
- const implying = this.edgeImplyingClosure.get(edgeKind);
1047
- return implying ? [...implying] : [];
1048
- }
1049
- /**
1050
- * Expands an edge kind to include all edges that imply it.
1051
- * Returns [edgeKind, ...implyingEdges].
1052
- */
1053
- expandImplyingEdges(edgeKind) {
1054
- const implying = this.edgeImplyingClosure.get(edgeKind) ?? /* @__PURE__ */ new Set();
1055
- return [edgeKind, ...implying];
1056
- }
1057
- // === Edge Endpoint Validation ===
1058
- /**
1059
- * Checks if a concrete kind is assignable to a target kind.
1060
- * Uses subsumption: Company is assignable to Organization if Company subClassOf Organization.
1061
- */
1062
- isAssignableTo(concreteKind, targetKind) {
1063
- if (concreteKind === targetKind) return true;
1064
- return this.isSubClassOf(concreteKind, targetKind);
1065
- }
1066
- /**
1067
- * Checks if a concrete kind is assignable to at least one of the given
1068
- * target kinds. Shared by every "is this kind usable where one of these
1069
- * kinds is expected" check (edge endpoint validation, ontology relation
1070
- * endpoint compatibility) so they can't independently drift.
1071
- */
1072
- isAssignableToAny(concreteKind, targetKinds) {
1073
- return targetKinds.some(
1074
- (targetKind) => this.isAssignableTo(concreteKind, targetKind)
1075
- );
1076
- }
1077
- /**
1078
- * Validates that a kind exists in the registry.
1079
- */
1080
- hasNodeType(name) {
1081
- return this.nodeKinds.has(name);
1082
- }
1083
- /**
1084
- * Validates that an edge kind exists in the registry.
1085
- */
1086
- hasEdgeType(name) {
1087
- return this.edgeKinds.has(name);
1088
- }
1089
- /**
1090
- * Gets a node kind by name.
1091
- */
1092
- getNodeType(name) {
1093
- return this.nodeKinds.get(name);
1094
- }
1095
- /**
1096
- * Gets an edge kind by name.
1097
- */
1098
- getEdgeType(name) {
1099
- return this.edgeKinds.get(name);
1100
- }
1101
- };
1102
- function createEmptyClosures() {
1103
- return {
1104
- subClassAncestors: /* @__PURE__ */ new Map(),
1105
- subClassDescendants: /* @__PURE__ */ new Map(),
1106
- broaderClosure: /* @__PURE__ */ new Map(),
1107
- narrowerClosure: /* @__PURE__ */ new Map(),
1108
- equivalenceSets: /* @__PURE__ */ new Map(),
1109
- iriToKind: /* @__PURE__ */ new Map(),
1110
- disjointPairs: /* @__PURE__ */ new Set(),
1111
- partOfClosure: /* @__PURE__ */ new Map(),
1112
- hasPartClosure: /* @__PURE__ */ new Map(),
1113
- edgeInverses: /* @__PURE__ */ new Map(),
1114
- edgeImplicationsClosure: /* @__PURE__ */ new Map(),
1115
- edgeImplyingClosure: /* @__PURE__ */ new Map()
1116
- };
1117
- }
1118
- function computeClosuresFromOntology(ontology) {
1119
- const subClassRelations = [];
1120
- const broaderRelations = [];
1121
- const equivalentRelations = [];
1122
- const disjointRelations = [];
1123
- const partOfRelations = [];
1124
- const inverseOfRelations = [];
1125
- const impliesRelations = [];
1126
- for (const relation of ontology) {
1127
- const fromName = getKindName(relation.from);
1128
- const toName = getKindName(relation.to);
1129
- switch (relation.metaEdge.name) {
1130
- case META_EDGE_SUB_CLASS_OF: {
1131
- subClassRelations.push([fromName, toName]);
1132
- break;
1133
- }
1134
- case META_EDGE_BROADER: {
1135
- broaderRelations.push([fromName, toName]);
1136
- break;
1137
- }
1138
- case META_EDGE_NARROWER: {
1139
- broaderRelations.push([toName, fromName]);
1140
- break;
1141
- }
1142
- case META_EDGE_EQUIVALENT_TO:
1143
- case META_EDGE_SAME_AS: {
1144
- equivalentRelations.push([fromName, toName]);
1145
- break;
1146
- }
1147
- case META_EDGE_DISJOINT_WITH: {
1148
- disjointRelations.push([fromName, toName]);
899
+ if (diff.identity !== void 0) {
900
+ switch (diff.identity.type) {
901
+ case "added": {
902
+ actions.push(
903
+ `BUILD Operational Identity closure: ${diff.identity.details} (materializes the closure table, running a same-id fold scan when sameIdAcrossKinds is "fold")`
904
+ );
1149
905
  break;
1150
906
  }
1151
- case META_EDGE_PART_OF: {
1152
- partOfRelations.push([fromName, toName]);
907
+ case "modified": {
908
+ actions.push(
909
+ `REBUILD Operational Identity closure: ${diff.identity.details} (every areSame/membersOf/includeIdentityMembers answer is recomputed under the new profile)`
910
+ );
1153
911
  break;
1154
912
  }
1155
- case META_EDGE_HAS_PART: {
1156
- partOfRelations.push([toName, fromName]);
913
+ case "removed": {
914
+ actions.push(
915
+ `DISABLE Operational Identity: ${diff.identity.details} (the materialized closure is left in place, unread; the identity API becomes unavailable)`
916
+ );
1157
917
  break;
1158
918
  }
1159
- case META_EDGE_INVERSE_OF: {
1160
- inverseOfRelations.push([fromName, toName]);
1161
- break;
1162
- }
1163
- case META_EDGE_IMPLIES: {
1164
- impliesRelations.push([fromName, toName]);
1165
- break;
1166
- }
1167
- }
1168
- }
1169
- const subClassAncestors = computeTransitiveClosure(subClassRelations);
1170
- const subClassDescendants = invertClosure(subClassAncestors);
1171
- const broaderClosure = computeTransitiveClosure(broaderRelations);
1172
- const narrowerClosure = invertClosure(broaderClosure);
1173
- const equivalenceSets = computeEquivalenceSets(equivalentRelations);
1174
- const iriToKind = computeIriMapping(equivalentRelations);
1175
- const disjointPairs = computeDisjointPairs(disjointRelations);
1176
- const partOfClosure = computeTransitiveClosure(partOfRelations);
1177
- const hasPartClosure = invertClosure(partOfClosure);
1178
- const edgeInverses = computeEdgeInverses(inverseOfRelations);
1179
- const edgeImplicationsClosure = computeTransitiveClosure(impliesRelations);
1180
- const edgeImplyingClosure = invertClosure(edgeImplicationsClosure);
1181
- return {
1182
- subClassAncestors,
1183
- subClassDescendants,
1184
- broaderClosure,
1185
- narrowerClosure,
1186
- equivalenceSets,
1187
- iriToKind,
1188
- disjointPairs,
1189
- partOfClosure,
1190
- hasPartClosure,
1191
- edgeInverses,
1192
- edgeImplicationsClosure,
1193
- edgeImplyingClosure
1194
- };
1195
- }
1196
- function getKindName(kindOrIri) {
1197
- if (typeof kindOrIri === "string") {
1198
- return kindOrIri;
1199
- }
1200
- return kindOrIri.kind;
1201
- }
1202
- function isExternalIri(value) {
1203
- return value.startsWith("http://") || value.startsWith("https://");
1204
- }
1205
- function computeEquivalenceSets(relations) {
1206
- const parent = /* @__PURE__ */ new Map();
1207
- function find(x) {
1208
- if (!parent.has(x)) {
1209
- parent.set(x, x);
1210
- return x;
1211
- }
1212
- const parentNode = requireDefined(parent.get(x));
1213
- if (parentNode === x) return x;
1214
- const root = find(parentNode);
1215
- parent.set(x, root);
1216
- return root;
1217
- }
1218
- function union(a, b) {
1219
- const rootA = find(a);
1220
- const rootB = find(b);
1221
- if (rootA !== rootB) {
1222
- parent.set(rootA, rootB);
1223
- }
1224
- }
1225
- for (const [a, b] of relations) {
1226
- union(a, b);
1227
- }
1228
- const classes = /* @__PURE__ */ new Map();
1229
- for (const key of parent.keys()) {
1230
- const root = find(key);
1231
- const existing = classes.get(root) ?? /* @__PURE__ */ new Set();
1232
- existing.add(key);
1233
- classes.set(root, existing);
1234
- }
1235
- const result = /* @__PURE__ */ new Map();
1236
- for (const members of classes.values()) {
1237
- for (const member of members) {
1238
- const others = new Set(members);
1239
- others.delete(member);
1240
- result.set(member, others);
1241
919
  }
1242
920
  }
1243
- return result;
1244
- }
1245
- function computeIriMapping(relations) {
1246
- const result = /* @__PURE__ */ new Map();
1247
- for (const [a, b] of relations) {
1248
- if (isExternalIri(a) && !isExternalIri(b)) {
1249
- result.set(a, b);
1250
- } else if (isExternalIri(b) && !isExternalIri(a)) {
1251
- result.set(b, a);
1252
- }
1253
- }
1254
- return result;
1255
- }
1256
- function computeDisjointPairs(relations) {
1257
- const result = /* @__PURE__ */ new Set();
1258
- for (const [a, b] of relations) {
1259
- const normalized = a < b ? `${a}|${b}` : `${b}|${a}`;
1260
- result.add(normalized);
1261
- }
1262
- return result;
1263
- }
1264
- function computeEdgeInverses(relations) {
1265
- const result = /* @__PURE__ */ new Map();
1266
- for (const [a, b] of relations) {
1267
- result.set(a, b);
1268
- result.set(b, a);
1269
- }
1270
- return result;
921
+ return actions;
1271
922
  }
1272
-
1273
- // src/schema/serializer.ts
1274
923
  function serializeSchema(graph, version) {
1275
924
  const nodes = serializeNodes(graph);
1276
925
  const edges = serializeEdges(graph);
@@ -1289,6 +938,7 @@ function serializeSchema(graph, version) {
1289
938
  onNodeDelete: graph.defaults.onNodeDelete,
1290
939
  temporalMode: graph.defaults.temporalMode
1291
940
  },
941
+ ...graph.identity === void 0 ? {} : { identity: graph.identity },
1292
942
  // `serializeIndexes` collapses both absent and empty inputs to
1293
943
  // `undefined` (see the helper's docstring); omit the field entirely
1294
944
  // in that case so legacy graphs hash byte-identically to the
@@ -1397,13 +1047,13 @@ function serializeEdgeIndexDeclaration(declaration) {
1397
1047
  };
1398
1048
  }
1399
1049
  function serializeNodes(graph) {
1400
- const result = {};
1050
+ const result = createDataKeyedBag();
1401
1051
  for (const kindName of getNodeKinds(graph)) {
1402
1052
  const registration = graph.nodes[kindName];
1403
1053
  if (registration === void 0) continue;
1404
1054
  result[kindName] = serializeNodeDef(registration);
1405
1055
  }
1406
- return result;
1056
+ return { ...result };
1407
1057
  }
1408
1058
  function serializeNodeDef(registration) {
1409
1059
  const node = registration.type;
@@ -1427,26 +1077,16 @@ function serializeUniqueConstraints(constraints) {
1427
1077
  }));
1428
1078
  }
1429
1079
  function serializeWherePredicate(whereFunction) {
1430
- const builder = new Proxy(
1431
- {},
1432
- {
1433
- get(_target, field) {
1434
- return {
1435
- isNull: () => ({
1436
- __type: "unique_predicate",
1437
- field,
1438
- op: "isNull"
1439
- }),
1440
- isNotNull: () => ({
1441
- __type: "unique_predicate",
1442
- field,
1443
- op: "isNotNull"
1444
- })
1445
- };
1080
+ const predicate = captureWherePredicate(whereFunction);
1081
+ if (predicate === void 0) {
1082
+ throw new ConfigurationError(
1083
+ `A unique constraint's \`where\` callback did not return a predicate, so it cannot be persisted.`,
1084
+ {},
1085
+ {
1086
+ suggestion: `Return a field predicate, e.g. \`where: (fields) => fields.someField.isNotNull()\`.`
1446
1087
  }
1447
- }
1448
- );
1449
- const predicate = whereFunction(builder);
1088
+ );
1089
+ }
1450
1090
  return JSON.stringify({ field: predicate.field, op: predicate.op });
1451
1091
  }
1452
1092
  function deserializeWherePredicate(serialized) {
@@ -1465,13 +1105,13 @@ function deserializeWherePredicate(serialized) {
1465
1105
  };
1466
1106
  }
1467
1107
  function serializeEdges(graph) {
1468
- const result = {};
1108
+ const result = createDataKeyedBag();
1469
1109
  for (const kindName of getEdgeKinds(graph)) {
1470
1110
  const registration = graph.edges[kindName];
1471
1111
  if (registration === void 0) continue;
1472
1112
  result[kindName] = serializeEdgeDef(registration);
1473
1113
  }
1474
- return result;
1114
+ return { ...result };
1475
1115
  }
1476
1116
  function serializeEdgeDef(registration) {
1477
1117
  const edge = registration.type;
@@ -1495,7 +1135,7 @@ function serializeOntology(relations) {
1495
1135
  metaEdgeMap.set(metaEdge.name, metaEdge);
1496
1136
  }
1497
1137
  }
1498
- const metaEdges = {};
1138
+ const metaEdges = createDataKeyedBag();
1499
1139
  for (const [name, metaEdge] of metaEdgeMap) {
1500
1140
  metaEdges[name] = serializeMetaEdge(metaEdge);
1501
1141
  }
@@ -1504,7 +1144,7 @@ function serializeOntology(relations) {
1504
1144
  );
1505
1145
  const closures = serializeClosures(relations);
1506
1146
  return {
1507
- metaEdges,
1147
+ metaEdges: { ...metaEdges },
1508
1148
  relations: serializedRelations,
1509
1149
  closures
1510
1150
  };
@@ -1561,11 +1201,11 @@ function serializeClosures(relations) {
1561
1201
  };
1562
1202
  }
1563
1203
  function mapToRecord(map) {
1564
- const result = {};
1204
+ const result = createDataKeyedBag();
1565
1205
  for (const [key, values] of map) {
1566
1206
  result[key] = [...values];
1567
1207
  }
1568
- return result;
1208
+ return { ...result };
1569
1209
  }
1570
1210
  function mapToSimpleRecord(map) {
1571
1211
  return Object.fromEntries(map);
@@ -1606,6 +1246,7 @@ async function computeSchemaHash(schema) {
1606
1246
  edges: schema.edges,
1607
1247
  ontology: schema.ontology,
1608
1248
  defaults: schema.defaults,
1249
+ ...schema.identity === void 0 ? {} : { identity: schema.identity },
1609
1250
  ...schema.indexes === void 0 ? {} : { indexes: schema.indexes },
1610
1251
  ...schema.extension === void 0 ? {} : { extension: schema.extension },
1611
1252
  ...schema.deprecatedKinds === void 0 ? {} : { deprecatedKinds: schema.deprecatedKinds }
@@ -1694,7 +1335,7 @@ function compileEdge(kindName, document, nodeTypeByName) {
1694
1335
  );
1695
1336
  }
1696
1337
  function buildObjectSchema(properties) {
1697
- const shape = {};
1338
+ const shape = createDataKeyedBag();
1698
1339
  for (const [propertyName, propertyType] of Object.entries(properties)) {
1699
1340
  shape[propertyName] = applyOptional(
1700
1341
  compileProperty(propertyType),
@@ -1873,7 +1514,7 @@ function mergeGraphExtension(graph, document) {
1873
1514
  );
1874
1515
  nodeKinds.set(node.type.kind, node.type);
1875
1516
  }
1876
- const mergedNodes = {};
1517
+ const mergedNodes = createDataKeyedBag();
1877
1518
  for (const [name, registration] of Object.entries(graph.nodes)) {
1878
1519
  if (runtimeNodeNames.has(name)) continue;
1879
1520
  mergedNodes[name] = registration;
@@ -1884,7 +1525,7 @@ function mergeGraphExtension(graph, document) {
1884
1525
  ...node.unique.length === 0 ? {} : { unique: [...node.unique] }
1885
1526
  };
1886
1527
  }
1887
- const mergedEdges = {};
1528
+ const mergedEdges = createDataKeyedBag();
1888
1529
  for (const [name, registration] of Object.entries(graph.edges)) {
1889
1530
  if (runtimeEdgeNames.has(name)) continue;
1890
1531
  mergedEdges[name] = registration;
@@ -1893,7 +1534,7 @@ function mergeGraphExtension(graph, document) {
1893
1534
  assertNoCollision(
1894
1535
  edge.kindName,
1895
1536
  "edge",
1896
- mergedEdges[edge.kindName] !== void 0,
1537
+ hasOwnKey(mergedEdges, edge.kindName),
1897
1538
  graph.id
1898
1539
  );
1899
1540
  const from = resolveEndpoints(edge.from, nodeKinds, {
@@ -1925,7 +1566,7 @@ function mergeGraphExtension(graph, document) {
1925
1566
  const mergedOntology = [
1926
1567
  ...compileTimeOntology,
1927
1568
  ...compiled.ontology.map(
1928
- (relation) => resolveOntologyEndpoints(relation, nodeKinds)
1569
+ (relation) => resolveOntologyEndpoints(relation, nodeKinds, mergedEdges, graph.id)
1929
1570
  )
1930
1571
  ];
1931
1572
  const runtimeVectorIndexes = deriveGraphExtensionVectorIndexes(compiled.nodes);
@@ -1942,8 +1583,8 @@ function mergeGraphExtension(graph, document) {
1942
1583
  );
1943
1584
  return Object.freeze({
1944
1585
  ...graph,
1945
- nodes: mergedNodes,
1946
- edges: mergedEdges,
1586
+ nodes: { ...mergedNodes },
1587
+ edges: { ...mergedEdges },
1947
1588
  ontology: mergedOntology,
1948
1589
  indexes: mergedIndexes,
1949
1590
  extension: validatedUnion
@@ -1951,7 +1592,7 @@ function mergeGraphExtension(graph, document) {
1951
1592
  }
1952
1593
  function deriveGraphExtensionVectorIndexes(compiledNodes) {
1953
1594
  if (compiledNodes.length === 0) return [];
1954
- const registrations = {};
1595
+ const registrations = createDataKeyedBag();
1955
1596
  for (const compiled of compiledNodes) {
1956
1597
  registrations[compiled.type.kind] = {
1957
1598
  type: compiled.type,
@@ -2127,11 +1768,38 @@ function resolveEndpoints(entries, nodeKinds, context) {
2127
1768
  return resolved;
2128
1769
  });
2129
1770
  }
2130
- function resolveOntologyEndpoints(relation, nodeKinds) {
1771
+ function resolveOntologyEndpoints(relation, nodeKinds, edgeKinds, graphId) {
1772
+ if (relation.metaEdge.name === META_EDGE_INVERSE_OF || relation.metaEdge.name === META_EDGE_IMPLIES) {
1773
+ return {
1774
+ ...relation,
1775
+ from: resolveOntologyEdgeEndpoint(
1776
+ relation.metaEdge.name,
1777
+ relation.from,
1778
+ edgeKinds,
1779
+ graphId
1780
+ ),
1781
+ to: resolveOntologyEdgeEndpoint(
1782
+ relation.metaEdge.name,
1783
+ relation.to,
1784
+ edgeKinds,
1785
+ graphId
1786
+ )
1787
+ };
1788
+ }
2131
1789
  const from = typeof relation.from === "string" ? nodeKinds.get(relation.from) ?? relation.from : relation.from;
2132
1790
  const to = typeof relation.to === "string" ? nodeKinds.get(relation.to) ?? relation.to : relation.to;
2133
1791
  return { ...relation, from, to };
2134
1792
  }
1793
+ function resolveOntologyEdgeEndpoint(metaEdge, endpoint, edgeKinds, graphId) {
1794
+ if (typeof endpoint !== "string") return endpoint;
1795
+ if (Object.hasOwn(edgeKinds, endpoint)) return endpoint;
1796
+ if (isExternalIri(endpoint)) return endpoint;
1797
+ throw new GraphExtensionUnresolvedOntologyEndpointError(
1798
+ metaEdge,
1799
+ endpoint,
1800
+ graphId
1801
+ );
1802
+ }
2135
1803
 
2136
1804
  // src/graph-extension/remove.ts
2137
1805
  function planRemovals(graph, names) {
@@ -2181,7 +1849,7 @@ function planRemovals(graph, names) {
2181
1849
  const removedNodeKindsSet = new Set(removedNodeKinds);
2182
1850
  const explicitlyRemovedEdgeKindsSet = new Set(explicitlyRemovedEdgeKinds);
2183
1851
  const cascadeEdges = /* @__PURE__ */ new Set();
2184
- const updatedEdges = {};
1852
+ const updatedEdges = createDataKeyedBag();
2185
1853
  for (const [edgeName, edgeDocument] of Object.entries(document.edges ?? {})) {
2186
1854
  if (explicitlyRemovedEdgeKindsSet.has(edgeName)) {
2187
1855
  cascadeEdges.add(edgeName);
@@ -2203,7 +1871,7 @@ function planRemovals(graph, names) {
2203
1871
  to: newTo
2204
1872
  };
2205
1873
  }
2206
- const updatedNodes = {};
1874
+ const updatedNodes = createDataKeyedBag();
2207
1875
  for (const [nodeName, nodeDocument] of Object.entries(document.nodes ?? {})) {
2208
1876
  if (removedNodeKindsSet.has(nodeName)) continue;
2209
1877
  updatedNodes[nodeName] = nodeDocument;
@@ -2221,8 +1889,11 @@ function planRemovals(graph, names) {
2221
1889
  );
2222
1890
  const newDocument = Object.freeze({
2223
1891
  ...document.version === void 0 ? {} : { version: document.version },
2224
- ...Object.keys(updatedNodes).length === 0 ? {} : { nodes: updatedNodes },
2225
- ...Object.keys(updatedEdges).length === 0 ? {} : { edges: updatedEdges },
1892
+ // Spread at the boundary: these land on the returned extension document,
1893
+ // which is public as `graph.extension`. See `createDataKeyedBag` in
1894
+ // ../utils/object.ts.
1895
+ ...Object.keys(updatedNodes).length === 0 ? {} : { nodes: { ...updatedNodes } },
1896
+ ...Object.keys(updatedEdges).length === 0 ? {} : { edges: { ...updatedEdges } },
2226
1897
  ...survivingOntology.length === 0 ? {} : { ontology: survivingOntology },
2227
1898
  ...survivingIndexes.length === 0 ? {} : { indexes: survivingIndexes }
2228
1899
  });
@@ -2242,12 +1913,12 @@ function stripGraphExtension(graph) {
2242
1913
  if (document === void 0) return graph;
2243
1914
  const { nodes: runtimeNodeNames, edges: runtimeEdgeNames } = extensionKindNames(document);
2244
1915
  const runtimeOntologyKeys = buildGraphExtensionOntologyKeySet(document);
2245
- const compileNodes = {};
1916
+ const compileNodes = createDataKeyedBag();
2246
1917
  for (const [name, registration] of Object.entries(graph.nodes)) {
2247
1918
  if (runtimeNodeNames.has(name)) continue;
2248
1919
  compileNodes[name] = registration;
2249
1920
  }
2250
- const compileEdges = {};
1921
+ const compileEdges = createDataKeyedBag();
2251
1922
  for (const [name, registration] of Object.entries(graph.edges)) {
2252
1923
  if (runtimeEdgeNames.has(name)) continue;
2253
1924
  compileEdges[name] = registration;
@@ -2260,8 +1931,8 @@ function stripGraphExtension(graph) {
2260
1931
  );
2261
1932
  return Object.freeze({
2262
1933
  ...graph,
2263
- nodes: compileNodes,
2264
- edges: compileEdges,
1934
+ nodes: { ...compileNodes },
1935
+ edges: { ...compileEdges },
2265
1936
  ontology: compileOntology,
2266
1937
  indexes: compileIndexes.length === 0 ? void 0 : compileIndexes,
2267
1938
  extension: void 0
@@ -2310,6 +1981,244 @@ function buildCompileTimeReferentIndex(graph, runtimeEdgeNames) {
2310
1981
  return index;
2311
1982
  }
2312
1983
 
1984
+ // src/identity/schema-transition.ts
1985
+ function identityTableNames(schema) {
1986
+ return {
1987
+ identityAssertions: schema.tables.identityAssertions,
1988
+ recordedIdentityAssertions: schema.tables.recordedIdentityAssertions,
1989
+ identityClosure: schema.tables.identityClosure,
1990
+ identitySeparation: schema.tables.identitySeparation
1991
+ };
1992
+ }
1993
+ var IDENTITY_SEPARATION_RELATION = "identitySeparation";
1994
+ var UPGRADEABLE_DERIVED_RELATIONS = /* @__PURE__ */ new Set([
1995
+ IDENTITY_SEPARATION_RELATION
1996
+ ]);
1997
+ var NOTHING_OWED = { provisionInCommit: [] };
1998
+ async function ensureIdentitySchemaStorage(backend, schema, options) {
1999
+ const ensureIdentityTables = backend.ensureIdentityTables;
2000
+ if (ensureIdentityTables === void 0) return NOTHING_OWED;
2001
+ const tableNames = identityTableNames(schema);
2002
+ const missingTables = await ensureIdentityTables(tableNames, {
2003
+ provisionMissing: options.enablement
2004
+ });
2005
+ if (options.enablement) return NOTHING_OWED;
2006
+ assertIdentityStoragePresent(
2007
+ options.graphId,
2008
+ missingTables.filter((name) => !UPGRADEABLE_DERIVED_RELATIONS.has(name))
2009
+ );
2010
+ const separationMissing = missingTables.includes(
2011
+ IDENTITY_SEPARATION_RELATION
2012
+ );
2013
+ const rebuildRequired = await separationRebuildRequired(
2014
+ backend,
2015
+ schema,
2016
+ options.graphId,
2017
+ { relationExists: !separationMissing, registry: options.registry }
2018
+ );
2019
+ if (!separationMissing && !rebuildRequired) return NOTHING_OWED;
2020
+ const recompute = options.recomputeDerivedRelations;
2021
+ if (recompute === void 0) {
2022
+ return provisioningForCommit(backend, tableNames, options.graphId, {
2023
+ ensureIdentityTables,
2024
+ separationMissing,
2025
+ rebuildRequired
2026
+ });
2027
+ }
2028
+ await provisionDerivedRelations(backend, tableNames, options.graphId, {
2029
+ ensureIdentityTables,
2030
+ recompute,
2031
+ separationMissing,
2032
+ rebuildRequired
2033
+ });
2034
+ return NOTHING_OWED;
2035
+ }
2036
+ async function provisioningForCommit(backend, tableNames, graphId, input) {
2037
+ if (!input.separationMissing) return NOTHING_OWED;
2038
+ const identityTableDdl = backend.identityTableDdl;
2039
+ if (identityTableDdl !== void 0) {
2040
+ return { provisionInCommit: identityTableDdl(tableNames) };
2041
+ }
2042
+ if (input.rebuildRequired) {
2043
+ throw identityDerivedUpgradeUnsupportedError(graphId, ["identityTableDdl"]);
2044
+ }
2045
+ await input.ensureIdentityTables(tableNames, { provisionMissing: true });
2046
+ return NOTHING_OWED;
2047
+ }
2048
+ async function provisionDerivedRelations(backend, tableNames, graphId, ports) {
2049
+ if (!ports.separationMissing) {
2050
+ await ports.recompute(backend);
2051
+ return;
2052
+ }
2053
+ if (!ports.rebuildRequired) {
2054
+ await ports.ensureIdentityTables(tableNames, { provisionMissing: true });
2055
+ return;
2056
+ }
2057
+ const fence = backend.schemaWriteTransaction;
2058
+ const identityTableDdl = backend.identityTableDdl;
2059
+ if (fence === void 0 || identityTableDdl === void 0) {
2060
+ throw identityDerivedUpgradeUnsupportedError(graphId, [
2061
+ ...fence === void 0 ? ["schemaWriteTransaction"] : [],
2062
+ ...identityTableDdl === void 0 ? ["identityTableDdl"] : []
2063
+ ]);
2064
+ }
2065
+ await withIdentityDdlRaceRetry(
2066
+ async () => fence(graphId, async (target) => {
2067
+ await lockIdentityDdl(target);
2068
+ await executeIdentityDdl(
2069
+ (ddl) => target.executeSchemaDdl(ddl),
2070
+ identityTableDdl(tableNames)
2071
+ );
2072
+ await ports.recompute(target);
2073
+ })
2074
+ );
2075
+ }
2076
+ var IDENTITY_DDL_RACES = /* @__PURE__ */ new WeakSet();
2077
+ function markIdentityDdlRace(error) {
2078
+ if (typeof error === "object" && error !== null) {
2079
+ IDENTITY_DDL_RACES.add(error);
2080
+ }
2081
+ return error;
2082
+ }
2083
+ function isIdentityDdlRace(error) {
2084
+ for (const link of errorChain(error)) {
2085
+ if (typeof link === "object" && link !== null && IDENTITY_DDL_RACES.has(link)) {
2086
+ return true;
2087
+ }
2088
+ }
2089
+ return false;
2090
+ }
2091
+ async function executeIdentityDdl(execute, statements) {
2092
+ for (const statement of statements) {
2093
+ try {
2094
+ await execute(statement);
2095
+ } catch (error) {
2096
+ if (isPostgresConcurrentDdlRaceError(error)) {
2097
+ throw markIdentityDdlRace(error);
2098
+ }
2099
+ throw error;
2100
+ }
2101
+ }
2102
+ }
2103
+ async function withIdentityDdlRaceRetry(attempt) {
2104
+ try {
2105
+ return await attempt();
2106
+ } catch (error) {
2107
+ if (!isIdentityDdlRace(error)) throw error;
2108
+ return attempt();
2109
+ }
2110
+ }
2111
+ async function lockIdentityDdl(target) {
2112
+ if (target.dialect !== "postgres") return;
2113
+ await target.execute(
2114
+ asCompiledRowsSql(sql`
2115
+ SELECT pg_advisory_xact_lock(hashtext(${IDENTITY_DDL_LOCK_KEY}), 0)
2116
+ `)
2117
+ );
2118
+ }
2119
+ var IDENTITY_DDL_LOCK_KEY = "typegraph:identity-ddl";
2120
+ function identityDerivedUpgradeUnsupportedError(graphId, missingPorts) {
2121
+ return new ConfigurationError(
2122
+ "This backend cannot publish an Operational Identity derived-relation upgrade atomically.",
2123
+ {
2124
+ code: "IDENTITY_UPGRADE_REQUIRES_ATOMIC_DDL",
2125
+ graphId,
2126
+ missingPorts,
2127
+ tables: [IDENTITY_SEPARATION_RELATION]
2128
+ },
2129
+ {
2130
+ suggestion: "Use a backend that implements schemaWriteTransaction and identityTableDdl (both bundled Drizzle backends do when transactions are enabled). Creating the separation relation and filling it as two steps would leave it readable and empty in between, where every pair reads as not separated. To upgrade out of band, create the relation with the standard TypeGraph DDL and run rebuildIdentityClosure(store) before serving traffic."
2131
+ }
2132
+ );
2133
+ }
2134
+ async function identityKindCascadeNeeded(backend, schema, graphId, droppedNodeKinds) {
2135
+ if (droppedNodeKinds.length === 0) return false;
2136
+ const ensureIdentityTables = backend.ensureIdentityTables;
2137
+ if (ensureIdentityTables === void 0) return false;
2138
+ const missingTables = await ensureIdentityTables(identityTableNames(schema), {
2139
+ provisionMissing: false
2140
+ });
2141
+ if (missingTables.length > 0) return false;
2142
+ return hasAssertionsTouchingKinds(backend, schema, graphId, droppedNodeKinds);
2143
+ }
2144
+ function assertIdentityStoragePresent(graphId, missingTables) {
2145
+ if (missingTables.length === 0) return;
2146
+ throw new ConfigurationError(
2147
+ "Operational Identity storage was missing from an already enabled graph.",
2148
+ {
2149
+ code: "IDENTITY_STORAGE_MISSING",
2150
+ graphId,
2151
+ tables: missingTables
2152
+ },
2153
+ {
2154
+ suggestion: "Restore missing assertion-ledger tables from backup. If only the derived relations (closure, separation) are missing, recreate them with the standard TypeGraph DDL, open the Store, and run rebuildIdentityClosure() before serving traffic."
2155
+ }
2156
+ );
2157
+ }
2158
+ function identitySchemaCommitPreflight(ctx, options) {
2159
+ return async (target) => {
2160
+ await provisionDerivedRelationsInCommit(
2161
+ target,
2162
+ ctx.graphId,
2163
+ options.provisionDerivedRelations ?? []
2164
+ );
2165
+ await lockRecordedGraphWrite(target, ctx.graphId);
2166
+ await lockIdentityGraph(target, ctx.graphId);
2167
+ if (options.enablement) {
2168
+ await lockIdentityEnablementNodes(target, ctx.schema);
2169
+ await withRecordedIdentityMutationTarget(
2170
+ target,
2171
+ (rawTarget, touch) => purgeAssertionsWithUnregisteredKinds(
2172
+ rawTarget,
2173
+ ctx.schema,
2174
+ ctx.graphId,
2175
+ new Set(ctx.registry.nodeKinds.keys()),
2176
+ touch
2177
+ )
2178
+ );
2179
+ }
2180
+ const droppedNodeKinds = options.droppedNodeKinds ?? [];
2181
+ if (droppedNodeKinds.length > 0) {
2182
+ await withRecordedIdentityMutationTarget(
2183
+ target,
2184
+ (rawTarget, touch) => deleteAssertionsTouchingKinds(
2185
+ rawTarget,
2186
+ ctx.schema,
2187
+ ctx.graphId,
2188
+ droppedNodeKinds,
2189
+ touch
2190
+ )
2191
+ );
2192
+ }
2193
+ await rebuildIdentityClosureForContext({ ...ctx, backend: target });
2194
+ };
2195
+ }
2196
+ async function provisionDerivedRelationsInCommit(target, graphId, ddl) {
2197
+ if (ddl.length === 0) return;
2198
+ const executeSchemaDdl = target.executeSchemaDdl;
2199
+ if (executeSchemaDdl === void 0) {
2200
+ throw identityDerivedUpgradeUnsupportedError(graphId, ["executeSchemaDdl"]);
2201
+ }
2202
+ await lockIdentityDdl(target);
2203
+ await executeIdentityDdl((statement) => executeSchemaDdl(statement), ddl);
2204
+ }
2205
+ function identityKindCascadePreflight(ctx, droppedNodeKinds) {
2206
+ return async (target) => {
2207
+ await lockRecordedGraphWrite(target, ctx.graphId);
2208
+ await lockIdentityGraph(target, ctx.graphId);
2209
+ await withRecordedIdentityMutationTarget(
2210
+ target,
2211
+ (rawTarget, touch) => deleteAssertionsTouchingKinds(
2212
+ rawTarget,
2213
+ ctx.schema,
2214
+ ctx.graphId,
2215
+ droppedNodeKinds,
2216
+ touch
2217
+ )
2218
+ );
2219
+ };
2220
+ }
2221
+
2313
2222
  // src/registry/validate-implies.ts
2314
2223
  function validateImpliesEndpointCompatibility(edgeEndpoints, registry) {
2315
2224
  for (const [impliedEdgeKind, impliedEndpoints] of edgeEndpoints) {
@@ -2359,17 +2268,132 @@ function assertEndpointCompatible(side, implyingEdgeKind, implyingKinds, implied
2359
2268
  );
2360
2269
  }
2361
2270
 
2271
+ // src/registry/validate-inverse.ts
2272
+ function validateInverseEndpointCompatibility(ontology, edgeEndpoints, registry) {
2273
+ for (const relation of ontology) {
2274
+ if (relation.metaEdge !== META_EDGE_INVERSE_OF) continue;
2275
+ const left = edgeEndpoints.get(relation.from);
2276
+ const right = edgeEndpoints.get(relation.to);
2277
+ if (left === void 0 || right === void 0) continue;
2278
+ assertInverseSideCompatible(
2279
+ relation.from,
2280
+ "from",
2281
+ left.from,
2282
+ relation.to,
2283
+ "to",
2284
+ right.to,
2285
+ registry
2286
+ );
2287
+ assertInverseSideCompatible(
2288
+ relation.from,
2289
+ "to",
2290
+ left.to,
2291
+ relation.to,
2292
+ "from",
2293
+ right.from,
2294
+ registry
2295
+ );
2296
+ if (relation.from === relation.to) continue;
2297
+ assertInverseSideCompatible(
2298
+ relation.to,
2299
+ "from",
2300
+ right.from,
2301
+ relation.from,
2302
+ "to",
2303
+ left.to,
2304
+ registry
2305
+ );
2306
+ assertInverseSideCompatible(
2307
+ relation.to,
2308
+ "to",
2309
+ right.to,
2310
+ relation.from,
2311
+ "from",
2312
+ left.from,
2313
+ registry
2314
+ );
2315
+ }
2316
+ }
2317
+ function assertInverseSideCompatible(sourceEdge, sourceSide, sourceKinds, inverseEdge, inverseSide, inverseKinds, registry) {
2318
+ const incompatibleKinds = sourceKinds.filter(
2319
+ (kind) => !registry.isAssignableToAny(kind, inverseKinds)
2320
+ );
2321
+ if (incompatibleKinds.length === 0) return;
2322
+ throw new ConfigurationError(
2323
+ `inverseOf("${sourceEdge}", "${inverseEdge}") is endpoint-incompatible: ${sourceSide} kind(s) [${incompatibleKinds.join(", ")}] declared on "${sourceEdge}" cannot be assigned to any of "${inverseEdge}"'s ${inverseSide} kind(s) [${inverseKinds.join(", ")}].`,
2324
+ {
2325
+ metaEdge: META_EDGE_INVERSE_OF,
2326
+ sourceEdge,
2327
+ inverseEdge,
2328
+ sourceEndpoint: sourceSide,
2329
+ inverseEndpoint: inverseSide,
2330
+ incompatibleKinds,
2331
+ allowedKinds: inverseKinds
2332
+ },
2333
+ {
2334
+ suggestion: "Make the inverse edge declarations exact reversals (allowing subClassOf assignability), or remove the inverseOf relation."
2335
+ }
2336
+ );
2337
+ }
2338
+
2339
+ // src/registry/build-validated.ts
2340
+ function buildValidatedKindRegistry(input) {
2341
+ if (input.ontology.length === 0) {
2342
+ const registry2 = new KindRegistry(
2343
+ input.nodeKinds,
2344
+ input.edgeKinds,
2345
+ createEmptyClosures(),
2346
+ input.identity
2347
+ );
2348
+ validateImpliesEndpointCompatibility(input.edgeEndpoints, registry2);
2349
+ return registry2;
2350
+ }
2351
+ const issues = validateOntologyRelations(input.ontology);
2352
+ if (issues.length > 0) {
2353
+ const firstIssue = requireDefined(issues[0]);
2354
+ throw new ConfigurationError(
2355
+ `Ontology is incoherent: ${firstIssue.message}`,
2356
+ {
2357
+ code: firstIssue.code,
2358
+ issues
2359
+ },
2360
+ {
2361
+ suggestion: "Correct the ontology relations before constructing or loading the graph registry."
2362
+ }
2363
+ );
2364
+ }
2365
+ const closures = computeClosuresFromNamedOntology(input.ontology);
2366
+ const registry = new KindRegistry(
2367
+ input.nodeKinds,
2368
+ input.edgeKinds,
2369
+ closures,
2370
+ input.identity
2371
+ );
2372
+ validateImpliesEndpointCompatibility(input.edgeEndpoints, registry);
2373
+ validateInverseEndpointCompatibility(
2374
+ input.ontology,
2375
+ input.edgeEndpoints,
2376
+ registry
2377
+ );
2378
+ return registry;
2379
+ }
2380
+
2362
2381
  // src/registry/builders.ts
2382
+ var EMPTY_NAMED_ONTOLOGY = [];
2363
2383
  function buildKindRegistry(graph) {
2364
2384
  const nodeTypes = extractNodeTypes(graph);
2365
2385
  const edgeTypes = extractEdgeTypes(graph);
2366
- const closures = graph.ontology.length > 0 ? computeClosuresFromOntology(graph.ontology) : createEmptyClosures();
2367
- const registry = new KindRegistry(nodeTypes, edgeTypes, closures);
2368
- validateImpliesEndpointCompatibility(
2369
- buildEdgeEndpointKinds(graph.edges),
2370
- registry
2371
- );
2372
- return registry;
2386
+ return buildValidatedKindRegistry({
2387
+ nodeKinds: nodeTypes,
2388
+ edgeKinds: edgeTypes,
2389
+ ontology: graph.ontology.length === 0 ? EMPTY_NAMED_ONTOLOGY : graph.ontology.map((relation) => ({
2390
+ metaEdge: relation.metaEdge.name,
2391
+ from: typeof relation.from === "string" ? relation.from : relation.from.kind,
2392
+ to: typeof relation.to === "string" ? relation.to : relation.to.kind
2393
+ })),
2394
+ edgeEndpoints: buildEdgeEndpointKinds(graph.edges),
2395
+ ...graph.identity === void 0 ? {} : { identity: graph.identity }
2396
+ });
2373
2397
  }
2374
2398
  function buildEdgeEndpointKinds(edges) {
2375
2399
  const result = /* @__PURE__ */ new Map();
@@ -2695,6 +2719,7 @@ var serializedSchemaZod = z.object({
2695
2719
  onNodeDelete: deleteBehaviorZod,
2696
2720
  temporalMode: temporalModeZod
2697
2721
  }).loose(),
2722
+ identity: z.object({ sameIdAcrossKinds: z.enum(["fold", "ignore"]) }).readonly().optional(),
2698
2723
  /**
2699
2724
  * Index declarations attached to the graph.
2700
2725
  *
@@ -2810,7 +2835,9 @@ async function ensureSchema(backend, graph, options) {
2810
2835
  const preloaded = options?.preloaded;
2811
2836
  const activeSchema = preloaded === void 0 ? await loadActiveSchemaWithBootstrap(backend, graph.id) : preloaded.activeRow;
2812
2837
  if (activeSchema === void 0) {
2813
- const result = await initializeSchema(backend, graph);
2838
+ const result = await initializeSchema(backend, graph, {
2839
+ ...options?.schema === void 0 ? {} : { schema: options.schema }
2840
+ });
2814
2841
  return {
2815
2842
  status: "initialized",
2816
2843
  version: result.version,
@@ -2837,10 +2864,15 @@ async function ensureSchema(backend, graph, options) {
2837
2864
  diff
2838
2865
  };
2839
2866
  await options?.onBeforeMigrate?.(hookContext);
2840
- const committedRow = await commitNewSchemaVersion(
2867
+ const preflight = graph.identity === void 0 ? void 0 : await prepareIdentitySchemaCommit(backend, graph, {
2868
+ enablement: storedSchema.identity === void 0,
2869
+ ...options?.schema === void 0 ? {} : { schema: options.schema }
2870
+ });
2871
+ const committedRow = preflight === void 0 ? await commitNewSchemaVersion(backend, graph, activeSchema.version) : await commitNewSchemaVersionWithPreflight(
2841
2872
  backend,
2842
2873
  graph,
2843
- activeSchema.version
2874
+ activeSchema.version,
2875
+ preflight
2844
2876
  );
2845
2877
  await options?.onAfterMigrate?.(hookContext);
2846
2878
  return {
@@ -2955,17 +2987,39 @@ function schemaNotInitializedError(graphId, cause) {
2955
2987
  }
2956
2988
  );
2957
2989
  }
2958
- async function initializeSchema(backend, graph) {
2990
+ function requireCommitWithPreflight(backend, graph) {
2991
+ const commitWithPreflight = backend.commitSchemaVersionWithPreflight;
2992
+ if (commitWithPreflight === void 0) {
2993
+ throw new ConfigurationError(
2994
+ "This backend cannot atomically commit identity data with a schema transition.",
2995
+ {
2996
+ code: "IDENTITY_REQUIRES_ATOMIC_BACKEND",
2997
+ graphId: graph.id
2998
+ }
2999
+ );
3000
+ }
3001
+ return commitWithPreflight;
3002
+ }
3003
+ async function initializeSchema(backend, graph, options) {
2959
3004
  buildKindRegistry(graph);
2960
3005
  const schema = serializeSchema(graph, 1);
2961
3006
  const hash = await computeSchemaHash(schema);
2962
- return backend.commitSchemaVersion({
3007
+ const commit = {
2963
3008
  graphId: graph.id,
2964
3009
  expected: { kind: "initial" },
2965
3010
  version: 1,
2966
3011
  schemaHash: hash,
2967
3012
  schemaDoc: schema
3013
+ };
3014
+ if (graph.identity === void 0) {
3015
+ return backend.commitSchemaVersion(commit);
3016
+ }
3017
+ const preflight = await prepareIdentitySchemaCommit(backend, graph, {
3018
+ enablement: true,
3019
+ ...options?.schema === void 0 ? {} : { schema: options.schema }
2968
3020
  });
3021
+ const commitWithPreflight = requireCommitWithPreflight(backend, graph);
3022
+ return withIdentityDdlRaceRetry(() => commitWithPreflight(commit, preflight));
2969
3023
  }
2970
3024
  async function migrateSchema(backend, graph, currentVersion, options) {
2971
3025
  const {
@@ -2984,14 +3038,96 @@ async function migrateSchema(backend, graph, currentVersion, options) {
2984
3038
  ...droppedKinds(storedSchema.nodes, getNodeKinds(target), "node"),
2985
3039
  ...droppedKinds(storedSchema.edges, getEdgeKinds(target), "edge")
2986
3040
  ];
2987
- const committed = dropped.length > 0 && options?.discardDroppedKindRows !== true ? await commitDroppedKindsOnlyWhenEmpty(
3041
+ const guardedDrops = options?.discardDroppedKindRows === true ? [] : dropped;
3042
+ const droppedNodeKinds = dropped.filter((drop) => drop.entity === "node").map((drop) => drop.kind);
3043
+ const identityPreflight = activeRow === void 0 ? void 0 : target.identity === void 0 ? (
3044
+ // Identity being OFF in the target is not evidence the ledger is empty:
3045
+ // disabling retains the assertion rows. A drop committed here would
3046
+ // strand every assertion touching the kind — a later re-enablement
3047
+ // filters them out of the closure while raw ledger reads and merge
3048
+ // staging still see them.
3049
+ await prepareIdentityKindCascade(backend, target, {
3050
+ droppedNodeKinds,
3051
+ probeBeforeCascade: storedSchema?.identity === void 0,
3052
+ ...options?.schema === void 0 ? {} : { schema: options.schema }
3053
+ })
3054
+ ) : await prepareIdentitySchemaCommit(backend, target, {
3055
+ enablement: storedSchema?.identity === void 0,
3056
+ droppedNodeKinds,
3057
+ ...options?.schema === void 0 ? {} : { schema: options.schema }
3058
+ });
3059
+ const committed = identityPreflight === void 0 ? guardedDrops.length > 0 ? await commitDroppedKindsOnlyWhenEmpty(
2988
3060
  backend,
2989
3061
  target,
2990
3062
  currentVersion,
2991
- dropped
2992
- ) : await commitNewSchemaVersion(backend, target, currentVersion);
3063
+ guardedDrops
3064
+ ) : await commitNewSchemaVersion(backend, target, currentVersion) : await commitNewSchemaVersionWithPreflight(
3065
+ backend,
3066
+ target,
3067
+ currentVersion,
3068
+ async (transactionBackend) => {
3069
+ await assertDroppedKindsEmpty(
3070
+ transactionBackend,
3071
+ target.id,
3072
+ currentVersion,
3073
+ guardedDrops
3074
+ );
3075
+ await identityPreflight(transactionBackend);
3076
+ }
3077
+ );
2993
3078
  return committed.version;
2994
3079
  }
3080
+ async function prepareIdentityKindCascade(backend, target, options) {
3081
+ if (options.droppedNodeKinds.length === 0) return void 0;
3082
+ const schema = options.schema === void 0 ? createSqlSchema(backend.tableNames) : requireSqlSchema(options.schema, "The schema option");
3083
+ if (options.probeBeforeCascade) {
3084
+ const needed = await identityKindCascadeNeeded(
3085
+ backend,
3086
+ schema,
3087
+ target.id,
3088
+ options.droppedNodeKinds
3089
+ );
3090
+ if (!needed) return void 0;
3091
+ }
3092
+ return identityKindCascadePreflight(
3093
+ { graphId: target.id, schema },
3094
+ options.droppedNodeKinds
3095
+ );
3096
+ }
3097
+ async function prepareIdentitySchemaCommit(backend, target, options) {
3098
+ const schema = options.schema === void 0 ? createSqlSchema(backend.tableNames) : requireSqlSchema(options.schema, "The schema option");
3099
+ const registry = buildKindRegistry(target);
3100
+ const provisioning = await ensureIdentitySchemaStorage(backend, schema, {
3101
+ graphId: target.id,
3102
+ enablement: options.enablement,
3103
+ registry
3104
+ });
3105
+ return identitySchemaCommitPreflight(
3106
+ {
3107
+ graphId: target.id,
3108
+ registry,
3109
+ schema,
3110
+ sameIdAcrossKinds: target.identity?.sameIdAcrossKinds ?? "ignore"
3111
+ },
3112
+ {
3113
+ enablement: options.enablement,
3114
+ droppedNodeKinds: options.droppedNodeKinds ?? [],
3115
+ provisionDerivedRelations: provisioning.provisionInCommit
3116
+ }
3117
+ );
3118
+ }
3119
+ async function assertDroppedKindsEmpty(backend, graphId, currentVersion, dropped) {
3120
+ const counts = await Promise.all(
3121
+ dropped.map(async (entry) => ({
3122
+ entity: entry.entity,
3123
+ kind: entry.kind,
3124
+ count: entry.entity === "node" ? await backend.countNodesByKind({ graphId, kind: entry.kind }) : await backend.countEdgesByKind({ graphId, kind: entry.kind })
3125
+ }))
3126
+ );
3127
+ const populated = counts.filter((entry) => entry.count > 0);
3128
+ if (populated.length === 0) return;
3129
+ throwPopulatedKindRemovalError(graphId, currentVersion, populated);
3130
+ }
2995
3131
  async function commitDroppedKindsOnlyWhenEmpty(backend, graph, currentVersion, dropped) {
2996
3132
  const result = await commitNewSchemaVersionIfKindsEmpty(
2997
3133
  backend,
@@ -3053,6 +3189,14 @@ async function buildNewSchemaVersionCommit(graph, currentVersion) {
3053
3189
  schemaDoc: schema
3054
3190
  };
3055
3191
  }
3192
+ async function commitNewSchemaVersionWithPreflight(backend, graph, currentVersion, preflight) {
3193
+ if (backend.commitSchemaVersionWithPreflight === void 0) {
3194
+ buildKindRegistry(graph);
3195
+ }
3196
+ const commitWithPreflight = requireCommitWithPreflight(backend, graph);
3197
+ const commit = await buildNewSchemaVersionCommit(graph, currentVersion);
3198
+ return withIdentityDdlRaceRetry(() => commitWithPreflight(commit, preflight));
3199
+ }
3056
3200
  async function rollbackSchema(backend, graphId, targetVersion) {
3057
3201
  const activeRow = await backend.getActiveSchema(graphId);
3058
3202
  if (activeRow === void 0) {
@@ -3101,6 +3245,6 @@ async function getCommittedSchemaVersion(backend, graphId) {
3101
3245
  return row?.version;
3102
3246
  }
3103
3247
 
3104
- export { KindRegistry, applyDeprecatedKinds, assertSchemaCurrent, broader, buildGraphExtensionOntologyKeySet, buildKindRegistry, classifySchemaChanges, commitNewSchemaVersion, commitNewSchemaVersionIfKindsEmpty, compileTimeOntologyKey, computeSchemaDiff, computeSchemaHash, core, deserializeWherePredicate, differentFrom, disjointWith, ensureSchema, equivalentTo, extensionKindNames, getActiveSchema, getCommittedSchemaVersion, getMigrationActions, getSchemaChanges, hasPart, implies, initializeSchema, inverseOf, isBackwardsCompatible, isSchemaInitialized, loadActiveSchemaWithBootstrap, loadAndMergeGraphExtensionDocument, loadAndVerifyGraph, mergeGraphExtension, migrateSchema, narrower, parseSerializedSchema, partOf, planRemovals, relatedTo, requiresMigration, rollbackSchema, sameAs, serializeIndexDeclaration, serializeSchema, serializeSchemaProperties, stripGraphExtension, subClassOf, validateImpliesEndpointCompatibility };
3105
- //# sourceMappingURL=chunk-BEFM74L2.js.map
3106
- //# sourceMappingURL=chunk-BEFM74L2.js.map
3248
+ export { applyDeprecatedKinds, assertSchemaCurrent, broader, buildGraphExtensionOntologyKeySet, buildKindRegistry, buildValidatedKindRegistry, classifySchemaChanges, commitNewSchemaVersion, commitNewSchemaVersionIfKindsEmpty, commitNewSchemaVersionWithPreflight, compileTimeOntologyKey, computeSchemaDiff, computeSchemaHash, core, deserializeWherePredicate, differentFrom, disjointWith, ensureIdentitySchemaStorage, ensureSchema, equivalentTo, extensionKindNames, getActiveSchema, getCommittedSchemaVersion, getMigrationActions, getSchemaChanges, hasPart, identityKindCascadeNeeded, identitySchemaCommitPreflight, implies, initializeSchema, inverseOf, isBackwardsCompatible, isSchemaInitialized, loadActiveSchemaWithBootstrap, loadAndMergeGraphExtensionDocument, loadAndVerifyGraph, mergeGraphExtension, migrateSchema, narrower, parseSerializedSchema, partOf, planRemovals, relatedTo, requiresMigration, rollbackSchema, sameAs, serializeIndexDeclaration, serializeSchema, serializeSchemaProperties, stripGraphExtension, subClassOf };
3249
+ //# sourceMappingURL=chunk-QLRESYPU.js.map
3250
+ //# sourceMappingURL=chunk-QLRESYPU.js.map