@nicia-ai/typegraph 0.39.0 → 0.40.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 (247) hide show
  1. package/dist/backend/drizzle/indexes.cjs +8 -10
  2. package/dist/backend/drizzle/indexes.d.cts +2 -2
  3. package/dist/backend/drizzle/indexes.d.ts +2 -2
  4. package/dist/backend/drizzle/indexes.js +4 -6
  5. package/dist/backend/index.cjs +60 -39
  6. package/dist/backend/index.d.cts +60 -1
  7. package/dist/backend/index.d.ts +60 -1
  8. package/dist/backend/index.js +12 -3
  9. package/dist/backend/postgres/index.cjs +24 -26
  10. package/dist/backend/postgres/index.d.cts +6 -6
  11. package/dist/backend/postgres/index.d.ts +6 -6
  12. package/dist/backend/postgres/index.js +11 -13
  13. package/dist/backend/postgres/pglite-store.cjs +25 -26
  14. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  15. package/dist/backend/postgres/pglite-store.d.cts +6 -5
  16. package/dist/backend/postgres/pglite-store.d.ts +6 -5
  17. package/dist/backend/postgres/pglite-store.js +21 -22
  18. package/dist/backend/postgres/pglite-store.js.map +1 -1
  19. package/dist/backend/postgres/pglite.cjs +13 -15
  20. package/dist/backend/postgres/pglite.d.cts +3 -3
  21. package/dist/backend/postgres/pglite.d.ts +3 -3
  22. package/dist/backend/postgres/pglite.js +12 -14
  23. package/dist/backend/sqlite/index.cjs +25 -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 +9 -11
  27. package/dist/backend/sqlite/libsql.cjs +15 -17
  28. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  29. package/dist/backend/sqlite/libsql.d.cts +3 -3
  30. package/dist/backend/sqlite/libsql.d.ts +3 -3
  31. package/dist/backend/sqlite/libsql.js +14 -16
  32. package/dist/backend/sqlite/libsql.js.map +1 -1
  33. package/dist/backend/sqlite/local-store.cjs +26 -27
  34. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  35. package/dist/backend/sqlite/local-store.d.cts +6 -5
  36. package/dist/backend/sqlite/local-store.d.ts +6 -5
  37. package/dist/backend/sqlite/local-store.js +22 -23
  38. package/dist/backend/sqlite/local-store.js.map +1 -1
  39. package/dist/backend/sqlite/local.cjs +14 -16
  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 +12 -14
  43. package/dist/{chunk-U4JDJKPD.js → chunk-2I3DNNBU.js} +4 -4
  44. package/dist/{chunk-U4JDJKPD.js.map → chunk-2I3DNNBU.js.map} +1 -1
  45. package/dist/{chunk-NPWACFQJ.cjs → chunk-2J5NMMVR.cjs} +43 -43
  46. package/dist/{chunk-NPWACFQJ.cjs.map → chunk-2J5NMMVR.cjs.map} +1 -1
  47. package/dist/{chunk-3YFDFOYB.cjs → chunk-2X73QTIC.cjs} +12 -13
  48. package/dist/chunk-2X73QTIC.cjs.map +1 -0
  49. package/dist/{chunk-CBK2IVI2.js → chunk-3BL3JFHL.js} +40 -30
  50. package/dist/chunk-3BL3JFHL.js.map +1 -0
  51. package/dist/chunk-3SHAUJRB.js +79 -0
  52. package/dist/chunk-3SHAUJRB.js.map +1 -0
  53. package/dist/{chunk-3SK4SVTW.js → chunk-53BSOG3O.js} +8 -7
  54. package/dist/chunk-53BSOG3O.js.map +1 -0
  55. package/dist/chunk-5J4VNCUD.js +856 -0
  56. package/dist/chunk-5J4VNCUD.js.map +1 -0
  57. package/dist/chunk-5YBDB7UG.cjs +12 -0
  58. package/dist/{chunk-FMNUSGZ4.cjs.map → chunk-5YBDB7UG.cjs.map} +1 -1
  59. package/dist/{chunk-6XDBRDZE.js → chunk-6N7QBIWN.js} +7 -3
  60. package/dist/chunk-6N7QBIWN.js.map +1 -0
  61. package/dist/{chunk-EZH7FNUS.js → chunk-6QP4QXBR.js} +3 -3
  62. package/dist/{chunk-EZH7FNUS.js.map → chunk-6QP4QXBR.js.map} +1 -1
  63. package/dist/{chunk-E6TXEISH.cjs → chunk-7UTUKH4E.cjs} +4 -4
  64. package/dist/{chunk-E6TXEISH.cjs.map → chunk-7UTUKH4E.cjs.map} +1 -1
  65. package/dist/chunk-7WLEQIHA.cjs +605 -0
  66. package/dist/chunk-7WLEQIHA.cjs.map +1 -0
  67. package/dist/{chunk-BQITNFQJ.js → chunk-AQVDAKXH.js} +3 -3
  68. package/dist/{chunk-BQITNFQJ.js.map → chunk-AQVDAKXH.js.map} +1 -1
  69. package/dist/{chunk-X6CNEA32.js → chunk-BUZWMDNL.js} +5 -5
  70. package/dist/{chunk-X6CNEA32.js.map → chunk-BUZWMDNL.js.map} +1 -1
  71. package/dist/{chunk-7M3NACL3.cjs → chunk-CKFBZ4LV.cjs} +4 -4
  72. package/dist/{chunk-7M3NACL3.cjs.map → chunk-CKFBZ4LV.cjs.map} +1 -1
  73. package/dist/{chunk-SU7VQOJ3.js → chunk-CU3LPYNB.js} +4 -4
  74. package/dist/{chunk-SU7VQOJ3.js.map → chunk-CU3LPYNB.js.map} +1 -1
  75. package/dist/{chunk-IFRPHG7O.js → chunk-EFZ4S22A.js} +10 -9
  76. package/dist/chunk-EFZ4S22A.js.map +1 -0
  77. package/dist/chunk-ELA3V6UN.js +601 -0
  78. package/dist/chunk-ELA3V6UN.js.map +1 -0
  79. package/dist/{chunk-6SRLCSAV.cjs → chunk-H6I36MGT.cjs} +883 -873
  80. package/dist/chunk-H6I36MGT.cjs.map +1 -0
  81. package/dist/chunk-HAQVISUF.cjs +1098 -0
  82. package/dist/chunk-HAQVISUF.cjs.map +1 -0
  83. package/dist/{chunk-BKAKAVRW.cjs → chunk-HQRZEYYB.cjs} +44 -44
  84. package/dist/{chunk-BKAKAVRW.cjs.map → chunk-HQRZEYYB.cjs.map} +1 -1
  85. package/dist/{chunk-KAFXPB2L.js → chunk-I5CRUPKO.js} +9 -10
  86. package/dist/{chunk-KAFXPB2L.js.map → chunk-I5CRUPKO.js.map} +1 -1
  87. package/dist/{chunk-IFDXG2YJ.js → chunk-JHK6NPFV.js} +217 -305
  88. package/dist/chunk-JHK6NPFV.js.map +1 -0
  89. package/dist/chunk-JZYMOHHM.cjs +226 -0
  90. package/dist/chunk-JZYMOHHM.cjs.map +1 -0
  91. package/dist/{chunk-VXAFOF6Z.cjs → chunk-K4FB2RMO.cjs} +7 -7
  92. package/dist/{chunk-VXAFOF6Z.cjs.map → chunk-K4FB2RMO.cjs.map} +1 -1
  93. package/dist/{chunk-ERZ4QPQX.js → chunk-K6CD6W5J.js} +5 -5
  94. package/dist/{chunk-ERZ4QPQX.js.map → chunk-K6CD6W5J.js.map} +1 -1
  95. package/dist/{chunk-JD2YC62H.cjs → chunk-KHNKYSGP.cjs} +34 -34
  96. package/dist/{chunk-JD2YC62H.cjs.map → chunk-KHNKYSGP.cjs.map} +1 -1
  97. package/dist/{chunk-CWX77JB4.cjs → chunk-KLR77R5A.cjs} +13 -13
  98. package/dist/{chunk-CWX77JB4.cjs.map → chunk-KLR77R5A.cjs.map} +1 -1
  99. package/dist/{chunk-AOL64O4Z.js → chunk-L3DDZUZP.js} +3 -3
  100. package/dist/{chunk-AOL64O4Z.js.map → chunk-L3DDZUZP.js.map} +1 -1
  101. package/dist/{chunk-PZHC5GCD.js → chunk-L5ET7FYQ.js} +3 -3
  102. package/dist/{chunk-PZHC5GCD.js.map → chunk-L5ET7FYQ.js.map} +1 -1
  103. package/dist/{chunk-B63IFHXR.cjs → chunk-LFFVD5ZR.cjs} +41 -41
  104. package/dist/{chunk-B63IFHXR.cjs.map → chunk-LFFVD5ZR.cjs.map} +1 -1
  105. package/dist/chunk-LL5D5T5W.cjs +157 -0
  106. package/dist/chunk-LL5D5T5W.cjs.map +1 -0
  107. package/dist/{chunk-GUUWKPTK.cjs → chunk-LLE25NRD.cjs} +7 -7
  108. package/dist/{chunk-GUUWKPTK.cjs.map → chunk-LLE25NRD.cjs.map} +1 -1
  109. package/dist/chunk-LLHMAHG4.cjs +886 -0
  110. package/dist/chunk-LLHMAHG4.cjs.map +1 -0
  111. package/dist/{chunk-KIZSHRUI.cjs → chunk-M2RPZS7J.cjs} +10 -10
  112. package/dist/{chunk-KIZSHRUI.cjs.map → chunk-M2RPZS7J.cjs.map} +1 -1
  113. package/dist/chunk-MNURF4RF.cjs +85 -0
  114. package/dist/chunk-MNURF4RF.cjs.map +1 -0
  115. package/dist/chunk-QOHTVDHU.js +144 -0
  116. package/dist/chunk-QOHTVDHU.js.map +1 -0
  117. package/dist/{chunk-HTQOBY75.cjs → chunk-QXKVUJLI.cjs} +110 -109
  118. package/dist/chunk-QXKVUJLI.cjs.map +1 -0
  119. package/dist/{chunk-GNPGGLAE.cjs → chunk-QYDUCWD2.cjs} +4 -4
  120. package/dist/{chunk-GNPGGLAE.cjs.map → chunk-QYDUCWD2.cjs.map} +1 -1
  121. package/dist/{chunk-DOKUXLFH.js → chunk-QZYGZVUI.js} +34 -34
  122. package/dist/chunk-QZYGZVUI.js.map +1 -0
  123. package/dist/{chunk-GKQU44SQ.cjs → chunk-SAMJLDGG.cjs} +103 -103
  124. package/dist/{chunk-GKQU44SQ.cjs.map → chunk-SAMJLDGG.cjs.map} +1 -1
  125. package/dist/{chunk-DOVMTPKE.cjs → chunk-SE422RES.cjs} +27 -27
  126. package/dist/{chunk-DOVMTPKE.cjs.map → chunk-SE422RES.cjs.map} +1 -1
  127. package/dist/{chunk-5ELKD2FQ.cjs → chunk-UCHW2MGP.cjs} +330 -431
  128. package/dist/chunk-UCHW2MGP.cjs.map +1 -0
  129. package/dist/{chunk-Y6UA55YS.cjs → chunk-UDS5DZNY.cjs} +495 -1095
  130. package/dist/chunk-UDS5DZNY.cjs.map +1 -0
  131. package/dist/{chunk-VDYA2HMS.js → chunk-VWEFXG73.js} +3 -3
  132. package/dist/{chunk-VDYA2HMS.js.map → chunk-VWEFXG73.js.map} +1 -1
  133. package/dist/{chunk-KXFUQNF2.js → chunk-W66YCXWT.js} +463 -1047
  134. package/dist/chunk-W66YCXWT.js.map +1 -0
  135. package/dist/{chunk-NQBYTLPW.js → chunk-XMEYZYGE.js} +6 -6
  136. package/dist/{chunk-NQBYTLPW.js.map → chunk-XMEYZYGE.js.map} +1 -1
  137. package/dist/{chunk-G3CSQLLT.js → chunk-Y5UC3IXF.js} +461 -6
  138. package/dist/chunk-Y5UC3IXF.js.map +1 -0
  139. package/dist/{chunk-SDHV2MWU.js → chunk-YGX4PMG6.js} +5 -5
  140. package/dist/{chunk-SDHV2MWU.js.map → chunk-YGX4PMG6.js.map} +1 -1
  141. package/dist/{chunk-E2Q7SP2K.cjs → chunk-YIX3BEBR.cjs} +86 -85
  142. package/dist/chunk-YIX3BEBR.cjs.map +1 -0
  143. package/dist/{chunk-X6RDQ5NB.cjs → chunk-YX3H63VV.cjs} +8 -2
  144. package/dist/chunk-YX3H63VV.cjs.map +1 -0
  145. package/dist/chunk-YYLMXERH.js +211 -0
  146. package/dist/chunk-YYLMXERH.js.map +1 -0
  147. package/dist/{chunk-YPUNPG2T.js → chunk-ZE7E46IZ.js} +5 -5
  148. package/dist/{chunk-YPUNPG2T.js.map → chunk-ZE7E46IZ.js.map} +1 -1
  149. package/dist/{chunk-Z2PPIVOO.js → chunk-ZVME6OSV.js} +5 -5
  150. package/dist/{chunk-Z2PPIVOO.js.map → chunk-ZVME6OSV.js.map} +1 -1
  151. package/dist/core/index.cjs +15 -3
  152. package/dist/core/index.d.cts +4 -3
  153. package/dist/core/index.d.ts +4 -3
  154. package/dist/core/index.js +2 -2
  155. package/dist/{ddl-Dx3Z0_WC.d.ts → ddl-BLEzHw6j.d.ts} +3 -3
  156. package/dist/{ddl-J6sDyABg.d.cts → ddl-KnCdF_le.d.cts} +3 -3
  157. package/dist/{define-graph-CzEvA_8F.d.cts → define-graph-Cv3CFwKm.d.cts} +1 -1
  158. package/dist/{define-graph-DRo9xpYN.d.ts → define-graph-DQnj3fNH.d.ts} +1 -1
  159. package/dist/graph-merge/index.cjs +37 -38
  160. package/dist/graph-merge/index.cjs.map +1 -1
  161. package/dist/graph-merge/index.d.cts +6 -5
  162. package/dist/graph-merge/index.d.ts +6 -5
  163. package/dist/graph-merge/index.js +15 -16
  164. package/dist/graph-merge/index.js.map +1 -1
  165. package/dist/index.cjs +141 -117
  166. package/dist/index.d.cts +12 -10
  167. package/dist/index.d.ts +12 -10
  168. package/dist/index.js +22 -22
  169. package/dist/indexes/index.cjs +12 -14
  170. package/dist/indexes/index.d.cts +5 -5
  171. package/dist/indexes/index.d.ts +5 -5
  172. package/dist/indexes/index.js +5 -7
  173. package/dist/interchange/index.cjs +28 -29
  174. package/dist/interchange/index.cjs.map +1 -1
  175. package/dist/interchange/index.d.cts +6 -5
  176. package/dist/interchange/index.d.ts +6 -5
  177. package/dist/interchange/index.js +9 -10
  178. package/dist/interchange/index.js.map +1 -1
  179. package/dist/{manager-CASfhmzV.d.ts → manager-DjE6Mhag.d.ts} +2 -2
  180. package/dist/{manager-nCEJiYBb.d.cts → manager-mqee5MVB.d.cts} +2 -2
  181. package/dist/{postgres-DMgIKQU-.d.cts → postgres-Bm4DyFQU.d.cts} +100 -49
  182. package/dist/{postgres-Cl1ZAN1G.d.ts → postgres-DtaVALOZ.d.ts} +100 -49
  183. package/dist/profiler/index.d.cts +8 -7
  184. package/dist/profiler/index.d.ts +8 -7
  185. package/dist/provenance/index.cjs +19 -19
  186. package/dist/provenance/index.d.cts +6 -5
  187. package/dist/provenance/index.d.ts +6 -5
  188. package/dist/provenance/index.js +6 -6
  189. package/dist/schema/index.cjs +25 -27
  190. package/dist/schema/index.cjs.map +1 -1
  191. package/dist/schema/index.d.cts +5 -5
  192. package/dist/schema/index.d.ts +5 -5
  193. package/dist/schema/index.js +6 -8
  194. package/dist/schema/index.js.map +1 -1
  195. package/dist/{temporal-DqtOEo_B.d.ts → searchable-BxlJQVFw.d.cts} +3 -58
  196. package/dist/{temporal-BC_NQV5Y.d.cts → searchable-ChJ29MCd.d.ts} +3 -58
  197. package/dist/{sqlite-BDkW39aa.d.cts → sqlite-DT6tTHOG.d.cts} +124 -97
  198. package/dist/{sqlite-CYfhvESj.d.ts → sqlite-m9Izphk_.d.ts} +124 -97
  199. package/dist/{store-view-BJd6Vwpt.d.cts → store-view-C-buB8Q8.d.cts} +7 -14
  200. package/dist/{store-view-CLIhwMMX.d.ts → store-view-CagdeyNn.d.ts} +7 -14
  201. package/dist/temporal-CyFsSPe8.d.ts +73 -0
  202. package/dist/temporal-Dn_JADWY.d.cts +73 -0
  203. package/dist/{types-CUevi_D1.d.ts → types-CYdXzZef.d.ts} +1 -1
  204. package/dist/{types-COq3-vMC.d.cts → types-CqSfMRW3.d.cts} +1 -1
  205. package/dist/{where-C92TXCzT.d.cts → where-C3-HRgUq.d.cts} +1 -1
  206. package/dist/{where-BdE_cYtx.d.ts → where-sQL4u5h-.d.ts} +1 -1
  207. package/package.json +1 -1
  208. package/dist/chunk-3SK4SVTW.js.map +0 -1
  209. package/dist/chunk-3YFDFOYB.cjs.map +0 -1
  210. package/dist/chunk-5ELKD2FQ.cjs.map +0 -1
  211. package/dist/chunk-6SRLCSAV.cjs.map +0 -1
  212. package/dist/chunk-6XDBRDZE.js.map +0 -1
  213. package/dist/chunk-CBK2IVI2.js.map +0 -1
  214. package/dist/chunk-DDCIXXOO.js +0 -9
  215. package/dist/chunk-DDCIXXOO.js.map +0 -1
  216. package/dist/chunk-DDCYVIVV.cjs +0 -44
  217. package/dist/chunk-DDCYVIVV.cjs.map +0 -1
  218. package/dist/chunk-DOKUXLFH.js.map +0 -1
  219. package/dist/chunk-E2Q7SP2K.cjs.map +0 -1
  220. package/dist/chunk-EOJFGECD.cjs +0 -284
  221. package/dist/chunk-EOJFGECD.cjs.map +0 -1
  222. package/dist/chunk-FMNUSGZ4.cjs +0 -12
  223. package/dist/chunk-G3CSQLLT.js.map +0 -1
  224. package/dist/chunk-HTQOBY75.cjs.map +0 -1
  225. package/dist/chunk-I6FX7AAG.js +0 -39
  226. package/dist/chunk-I6FX7AAG.js.map +0 -1
  227. package/dist/chunk-IFDXG2YJ.js.map +0 -1
  228. package/dist/chunk-IFRPHG7O.js.map +0 -1
  229. package/dist/chunk-J6IJARLG.js +0 -94
  230. package/dist/chunk-J6IJARLG.js.map +0 -1
  231. package/dist/chunk-KXFUQNF2.js.map +0 -1
  232. package/dist/chunk-MTNEGGM2.js +0 -273
  233. package/dist/chunk-MTNEGGM2.js.map +0 -1
  234. package/dist/chunk-SVUKGWSN.cjs +0 -102
  235. package/dist/chunk-SVUKGWSN.cjs.map +0 -1
  236. package/dist/chunk-UH2USOMG.cjs +0 -627
  237. package/dist/chunk-UH2USOMG.cjs.map +0 -1
  238. package/dist/chunk-X6RDQ5NB.cjs.map +0 -1
  239. package/dist/chunk-Y6UA55YS.cjs.map +0 -1
  240. package/dist/chunk-Y7M44XEK.js +0 -462
  241. package/dist/chunk-Y7M44XEK.js.map +0 -1
  242. package/dist/chunk-Z5QHVL5U.cjs +0 -12
  243. package/dist/chunk-Z5QHVL5U.cjs.map +0 -1
  244. package/dist/chunk-ZKZAIX42.cjs +0 -479
  245. package/dist/chunk-ZKZAIX42.cjs.map +0 -1
  246. package/dist/{index-CrFL_ENI.d.cts → types-C5pZeKTl.d.cts} +1 -1
  247. package/dist/{index-Bq7vSPHy.d.ts → types-D8szWDUo.d.ts} +1 -1
@@ -0,0 +1,605 @@
1
+ 'use strict';
2
+
3
+ var chunkLLHMAHG4_cjs = require('./chunk-LLHMAHG4.cjs');
4
+ var chunkJZYMOHHM_cjs = require('./chunk-JZYMOHHM.cjs');
5
+ var chunkLL5D5T5W_cjs = require('./chunk-LL5D5T5W.cjs');
6
+ var chunkMNURF4RF_cjs = require('./chunk-MNURF4RF.cjs');
7
+ var chunkHAQVISUF_cjs = require('./chunk-HAQVISUF.cjs');
8
+ var chunkYX3H63VV_cjs = require('./chunk-YX3H63VV.cjs');
9
+ var chunkSAFZ6JTI_cjs = require('./chunk-SAFZ6JTI.cjs');
10
+
11
+ // src/backend/migrate-recorded-time.ts
12
+ var LEGACY_RECORDED_MAX = "9999-12-31T23:59:59.999Z";
13
+ var MIGRATION_SUFFIX = "legacy_recorded_anchors";
14
+ var RECORDED_NODE_COLUMNS = [
15
+ "history_id",
16
+ "graph_id",
17
+ "kind",
18
+ "id",
19
+ "props",
20
+ "version",
21
+ "valid_from",
22
+ "valid_to",
23
+ "created_at",
24
+ "updated_at",
25
+ "deleted_at",
26
+ "recorded_from",
27
+ "recorded_to",
28
+ "op",
29
+ "schema_version",
30
+ "tx_id",
31
+ "meta"
32
+ ];
33
+ var RECORDED_EDGE_COLUMNS = [
34
+ "history_id",
35
+ "graph_id",
36
+ "id",
37
+ "kind",
38
+ "from_kind",
39
+ "from_id",
40
+ "to_kind",
41
+ "to_id",
42
+ "props",
43
+ "valid_from",
44
+ "valid_to",
45
+ "created_at",
46
+ "updated_at",
47
+ "deleted_at",
48
+ "recorded_from",
49
+ "recorded_to",
50
+ "op",
51
+ "schema_version",
52
+ "tx_id",
53
+ "meta"
54
+ ];
55
+ function resolvedTableNames(backend, override) {
56
+ return chunkJZYMOHHM_cjs.createSqlSchema(override ?? backend.tableNames ?? {}).tables;
57
+ }
58
+ function shortenedIdentifier(value) {
59
+ if (value.length <= 63) return value;
60
+ return `${value.slice(0, 50)}_${chunkHAQVISUF_cjs.shortHash(value)}`;
61
+ }
62
+ function mappingTableName(tables, override) {
63
+ const candidate = override ?? `${tables.recordedClock}_${MIGRATION_SUFFIX}`;
64
+ return chunkJZYMOHHM_cjs.createSqlSchema({
65
+ recordedClock: shortenedIdentifier(candidate)
66
+ }).tables.recordedClock;
67
+ }
68
+ function temporaryTableName(tableName, role) {
69
+ return shortenedIdentifier(`__tg_${role}_${chunkHAQVISUF_cjs.shortHash(tableName)}`);
70
+ }
71
+ function requireStatements(target) {
72
+ if (target.executeStatement === void 0) {
73
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
74
+ "Recorded-time migration requires executeStatement support.",
75
+ { dialect: target.dialect },
76
+ { suggestion: "Use a built-in SQLite or PostgreSQL backend." }
77
+ );
78
+ }
79
+ return target.executeStatement;
80
+ }
81
+ async function executeStatement(target, statement) {
82
+ await requireStatements(target)(chunkYX3H63VV_cjs.asCompiledStatementSql(statement));
83
+ }
84
+ async function executeDdl(target, ddl) {
85
+ await executeStatement(target, chunkYX3H63VV_cjs.sql.raw(ddl));
86
+ }
87
+ function canonicalLegacyInstant(value) {
88
+ const canonical = chunkMNURF4RF_cjs.canonicalizeDatabaseTimestamp(value);
89
+ if (canonical === void 0) {
90
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
91
+ "Legacy recorded-time relation contained an invalid timestamp.",
92
+ { value }
93
+ );
94
+ }
95
+ return canonical;
96
+ }
97
+ function safeRevision(value) {
98
+ const revision = typeof value === "bigint" ? Number(value) : typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
99
+ if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 1 || revision >= chunkLL5D5T5W_cjs.RECORDED_MAX_REVISION) {
100
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
101
+ "Recorded anchor mapping contained an invalid revision.",
102
+ { value }
103
+ );
104
+ }
105
+ return revision;
106
+ }
107
+ async function columnNames(target, tableName) {
108
+ const rows = target.dialect === "sqlite" ? await target.execute(
109
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`PRAGMA table_info(${chunkYX3H63VV_cjs.sql.identifier(tableName)})`)
110
+ ) : await target.execute(
111
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
112
+ SELECT column_name AS name
113
+ FROM information_schema.columns
114
+ WHERE table_schema = current_schema()
115
+ AND table_name = ${tableName}
116
+ `)
117
+ );
118
+ return new Set(
119
+ rows.flatMap((row) => typeof row.name === "string" ? [row.name] : [])
120
+ );
121
+ }
122
+ async function readLegacyInstants(target, tables) {
123
+ const rows = await target.execute(
124
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
125
+ SELECT graph_id, recorded_from AS recorded_at
126
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedNodes)}
127
+ UNION
128
+ SELECT graph_id, recorded_to AS recorded_at
129
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedNodes)}
130
+ WHERE recorded_to <> ${LEGACY_RECORDED_MAX}
131
+ UNION
132
+ SELECT graph_id, recorded_from AS recorded_at
133
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedEdges)}
134
+ UNION
135
+ SELECT graph_id, recorded_to AS recorded_at
136
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedEdges)}
137
+ WHERE recorded_to <> ${LEGACY_RECORDED_MAX}
138
+ UNION
139
+ SELECT graph_id, recorded_at
140
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedClock)}
141
+ `)
142
+ );
143
+ const instants = rows.map((row) => {
144
+ if (typeof row.graph_id !== "string") {
145
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
146
+ "Legacy recorded-time relation contained an invalid graph id.",
147
+ { graphId: row.graph_id }
148
+ );
149
+ }
150
+ return {
151
+ graphId: row.graph_id,
152
+ recordedAt: canonicalLegacyInstant(row.recorded_at)
153
+ };
154
+ });
155
+ instants.sort((left, right) => {
156
+ if (left.graphId < right.graphId) return -1;
157
+ if (left.graphId > right.graphId) return 1;
158
+ if (left.recordedAt < right.recordedAt) return -1;
159
+ if (left.recordedAt > right.recordedAt) return 1;
160
+ return 0;
161
+ });
162
+ const mapping = [];
163
+ let graphId;
164
+ let revision = 0;
165
+ let previousInstant;
166
+ for (const instant of instants) {
167
+ if (instant.graphId !== graphId) {
168
+ graphId = instant.graphId;
169
+ revision = 0;
170
+ previousInstant = void 0;
171
+ }
172
+ if (instant.recordedAt === previousInstant) continue;
173
+ revision += 1;
174
+ mapping.push({
175
+ graphId: instant.graphId,
176
+ legacyRecordedAt: instant.recordedAt,
177
+ recordedAt: instant.recordedAt,
178
+ revision
179
+ });
180
+ previousInstant = instant.recordedAt;
181
+ }
182
+ return mapping;
183
+ }
184
+ function migrationMapDdl(dialect, table) {
185
+ const revisionType = dialect === "postgres" ? "BIGINT" : "INTEGER";
186
+ const recordedAtType = dialect === "postgres" ? "TIMESTAMPTZ" : "TEXT";
187
+ return `CREATE TABLE IF NOT EXISTS "${table}" (
188
+ graph_id TEXT NOT NULL,
189
+ legacy_recorded_at TEXT NOT NULL,
190
+ revision ${revisionType} NOT NULL,
191
+ recorded_at ${recordedAtType} NOT NULL,
192
+ PRIMARY KEY (graph_id, legacy_recorded_at)
193
+ );`;
194
+ }
195
+ async function writeMappingRows(target, tableName, rows) {
196
+ await executeStatement(target, chunkYX3H63VV_cjs.sql`DELETE FROM ${chunkYX3H63VV_cjs.sql.identifier(tableName)}`);
197
+ const rowsPerStatement = Math.max(
198
+ 1,
199
+ Math.floor((target.capabilities.maxBindParameters ?? 900) / 4)
200
+ );
201
+ for (let start = 0; start < rows.length; start += rowsPerStatement) {
202
+ const values = rows.slice(start, start + rowsPerStatement).map(
203
+ (row) => chunkYX3H63VV_cjs.sql`(${row.graphId}, ${row.legacyRecordedAt}, ${row.revision}, ${row.recordedAt})`
204
+ );
205
+ await executeStatement(
206
+ target,
207
+ chunkYX3H63VV_cjs.sql`
208
+ INSERT INTO ${chunkYX3H63VV_cjs.sql.identifier(tableName)}
209
+ (graph_id, legacy_recorded_at, revision, recorded_at)
210
+ VALUES ${chunkYX3H63VV_cjs.sql.join(values, chunkYX3H63VV_cjs.sql`, `)}
211
+ `
212
+ );
213
+ }
214
+ }
215
+ function tableDdl(dialect, tables, temporary) {
216
+ if (dialect === "sqlite") {
217
+ const temporaryTables2 = chunkLLHMAHG4_cjs.createSqliteTables(temporary);
218
+ const finalTables2 = chunkLLHMAHG4_cjs.createSqliteTables(tables);
219
+ const temporaryContributions = chunkLLHMAHG4_cjs.sqliteContributions(temporaryTables2);
220
+ const finalContributions = chunkLLHMAHG4_cjs.sqliteContributions(finalTables2);
221
+ return ddlForRecordedTables(temporaryContributions, finalContributions);
222
+ }
223
+ const temporaryTables = chunkLLHMAHG4_cjs.createPostgresTables(temporary);
224
+ const finalTables = chunkLLHMAHG4_cjs.createPostgresTables(tables);
225
+ return ddlForRecordedTables(
226
+ chunkLLHMAHG4_cjs.postgresContributions(temporaryTables),
227
+ chunkLLHMAHG4_cjs.postgresContributions(finalTables)
228
+ );
229
+ }
230
+ function ddlForRecordedTables(temporary, final) {
231
+ function statements(logicalName) {
232
+ const temporaryDdl = temporary.find(
233
+ (entry) => entry.logicalName === logicalName
234
+ )?.createDdl;
235
+ const finalDdl = final.find(
236
+ (entry) => entry.logicalName === logicalName
237
+ )?.createDdl;
238
+ if (temporaryDdl === void 0 || finalDdl === void 0) {
239
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
240
+ `Could not generate migration DDL for ${logicalName}.`
241
+ );
242
+ }
243
+ const createTable = temporaryDdl[0];
244
+ if (createTable === void 0) {
245
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
246
+ `Could not generate migration table DDL for ${logicalName}.`
247
+ );
248
+ }
249
+ return [createTable, ...finalDdl.slice(1)];
250
+ }
251
+ return {
252
+ clock: statements("recordedClock"),
253
+ edges: statements("recordedEdges"),
254
+ nodes: statements("recordedNodes")
255
+ };
256
+ }
257
+ function migratedColumn(column, legacyAlias) {
258
+ if (column === "recorded_from") return chunkYX3H63VV_cjs.sql`from_map.revision`;
259
+ if (column === "recorded_to") {
260
+ return chunkYX3H63VV_cjs.sql`
261
+ CASE
262
+ WHEN ${chunkYX3H63VV_cjs.sql.raw(legacyAlias)}.recorded_to = ${LEGACY_RECORDED_MAX}
263
+ THEN ${chunkLL5D5T5W_cjs.RECORDED_MAX_REVISION}
264
+ ELSE to_map.revision
265
+ END
266
+ `;
267
+ }
268
+ return chunkYX3H63VV_cjs.sql`${chunkYX3H63VV_cjs.sql.raw(legacyAlias)}.${chunkYX3H63VV_cjs.sql.identifier(column)}`;
269
+ }
270
+ function mappingMatch(dialect, mappingAlias, legacyColumn) {
271
+ const mapping = chunkYX3H63VV_cjs.sql.raw(mappingAlias);
272
+ const legacy = chunkYX3H63VV_cjs.sql.raw(`legacy.${legacyColumn}`);
273
+ return dialect === "postgres" ? chunkYX3H63VV_cjs.sql`${mapping}.recorded_at = ${legacy}` : chunkYX3H63VV_cjs.sql`${mapping}.legacy_recorded_at = ${legacy}`;
274
+ }
275
+ function missingMappingCount(value, legacyTable) {
276
+ const count = Number(value);
277
+ if (!Number.isSafeInteger(count) || count < 0) {
278
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
279
+ "Recorded-time migration returned an invalid integrity-check count.",
280
+ { legacyTable, value }
281
+ );
282
+ }
283
+ return count;
284
+ }
285
+ async function assertRecordedRelationMappings(target, options) {
286
+ const fromMatch = mappingMatch(target.dialect, "from_map", "recorded_from");
287
+ const toMatch = mappingMatch(target.dialect, "to_map", "recorded_to");
288
+ const rows = await target.execute(
289
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
290
+ SELECT COUNT(*) AS missing
291
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(options.legacyTable)} AS legacy
292
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS from_map
293
+ ON from_map.graph_id = legacy.graph_id AND ${fromMatch}
294
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS to_map
295
+ ON to_map.graph_id = legacy.graph_id AND ${toMatch}
296
+ WHERE from_map.revision IS NULL
297
+ OR (
298
+ legacy.recorded_to <> ${LEGACY_RECORDED_MAX}
299
+ AND to_map.revision IS NULL
300
+ )
301
+ `)
302
+ );
303
+ const missing = missingMappingCount(rows[0]?.missing, options.legacyTable);
304
+ if (missing === 0) return;
305
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
306
+ "Legacy recorded-time boundaries could not be mapped exactly.",
307
+ { legacyTable: options.legacyTable, missingRows: missing },
308
+ {
309
+ suggestion: "Ensure every legacy boundary is a valid millisecond-precision timestamp produced by the preview recorded clock before retrying the offline migration."
310
+ }
311
+ );
312
+ }
313
+ async function assertRecordedClockMappings(target, options) {
314
+ const match = mappingMatch(target.dialect, "anchor_map", "recorded_at");
315
+ const rows = await target.execute(
316
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
317
+ SELECT COUNT(*) AS missing
318
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(options.legacyTable)} AS legacy
319
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS anchor_map
320
+ ON anchor_map.graph_id = legacy.graph_id AND ${match}
321
+ WHERE anchor_map.revision IS NULL
322
+ `)
323
+ );
324
+ const missing = missingMappingCount(rows[0]?.missing, options.legacyTable);
325
+ if (missing === 0) return;
326
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
327
+ "Legacy recorded clock values could not be mapped exactly.",
328
+ { legacyTable: options.legacyTable, missingRows: missing },
329
+ {
330
+ suggestion: "Ensure every legacy clock value is a valid millisecond-precision timestamp produced by the preview recorded clock before retrying the offline migration."
331
+ }
332
+ );
333
+ }
334
+ async function copyRecordedRelation(target, options) {
335
+ const columnList = options.columns.map((column) => chunkYX3H63VV_cjs.sql.identifier(column));
336
+ const values = options.columns.map(
337
+ (column) => migratedColumn(column, "legacy")
338
+ );
339
+ await assertRecordedRelationMappings(target, options);
340
+ const fromMatch = mappingMatch(target.dialect, "from_map", "recorded_from");
341
+ const toMatch = mappingMatch(target.dialect, "to_map", "recorded_to");
342
+ await executeStatement(
343
+ target,
344
+ chunkYX3H63VV_cjs.sql`
345
+ INSERT INTO ${chunkYX3H63VV_cjs.sql.identifier(options.temporaryTable)}
346
+ (${chunkYX3H63VV_cjs.sql.join(columnList, chunkYX3H63VV_cjs.sql`, `)})
347
+ SELECT ${chunkYX3H63VV_cjs.sql.join(values, chunkYX3H63VV_cjs.sql`, `)}
348
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(options.legacyTable)} AS legacy
349
+ -- LEFT JOIN is deliberate: a missing mapping reaches the NOT NULL
350
+ -- revision columns and fails loud instead of silently dropping history.
351
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS from_map
352
+ ON from_map.graph_id = legacy.graph_id AND ${fromMatch}
353
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS to_map
354
+ ON to_map.graph_id = legacy.graph_id AND ${toMatch}
355
+ `
356
+ );
357
+ }
358
+ async function copyRecordedClock(target, options) {
359
+ await assertRecordedClockMappings(target, options);
360
+ const match = mappingMatch(target.dialect, "anchor_map", "recorded_at");
361
+ await executeStatement(
362
+ target,
363
+ chunkYX3H63VV_cjs.sql`
364
+ INSERT INTO ${chunkYX3H63VV_cjs.sql.identifier(options.temporaryTable)}
365
+ (graph_id, revision, recorded_at)
366
+ SELECT legacy.graph_id, anchor_map.revision, legacy.recorded_at
367
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(options.legacyTable)} AS legacy
368
+ -- Preserve fail-loud behavior if the preflight invariant changes later.
369
+ LEFT JOIN ${chunkYX3H63VV_cjs.sql.identifier(options.mappingTable)} AS anchor_map
370
+ ON anchor_map.graph_id = legacy.graph_id AND ${match}
371
+ `
372
+ );
373
+ }
374
+ async function replaceLegacyTables(target, tables, mappingTable) {
375
+ const temporary = {
376
+ recordedNodes: temporaryTableName(tables.recordedNodes, "rn"),
377
+ recordedEdges: temporaryTableName(tables.recordedEdges, "re"),
378
+ recordedClock: temporaryTableName(tables.recordedClock, "rc")
379
+ };
380
+ const ddl = tableDdl(target.dialect, tables, temporary);
381
+ for (const table of Object.values(temporary)) {
382
+ await executeStatement(
383
+ target,
384
+ chunkYX3H63VV_cjs.sql`DROP TABLE IF EXISTS ${chunkYX3H63VV_cjs.sql.identifier(table)}`
385
+ );
386
+ }
387
+ await executeDdl(target, requireCreateTable(ddl.nodes));
388
+ await executeDdl(target, requireCreateTable(ddl.edges));
389
+ await executeDdl(target, requireCreateTable(ddl.clock));
390
+ await copyRecordedRelation(target, {
391
+ columns: RECORDED_NODE_COLUMNS,
392
+ legacyTable: tables.recordedNodes,
393
+ mappingTable,
394
+ temporaryTable: temporary.recordedNodes
395
+ });
396
+ await copyRecordedRelation(target, {
397
+ columns: RECORDED_EDGE_COLUMNS,
398
+ legacyTable: tables.recordedEdges,
399
+ mappingTable,
400
+ temporaryTable: temporary.recordedEdges
401
+ });
402
+ await copyRecordedClock(target, {
403
+ legacyTable: tables.recordedClock,
404
+ mappingTable,
405
+ temporaryTable: temporary.recordedClock
406
+ });
407
+ await executeStatement(
408
+ target,
409
+ chunkYX3H63VV_cjs.sql`DROP TABLE ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedNodes)}`
410
+ );
411
+ await executeStatement(
412
+ target,
413
+ chunkYX3H63VV_cjs.sql`DROP TABLE ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedEdges)}`
414
+ );
415
+ await executeStatement(
416
+ target,
417
+ chunkYX3H63VV_cjs.sql`DROP TABLE ${chunkYX3H63VV_cjs.sql.identifier(tables.recordedClock)}`
418
+ );
419
+ await renameTable(target, temporary.recordedNodes, tables.recordedNodes);
420
+ await renameTable(target, temporary.recordedEdges, tables.recordedEdges);
421
+ await renameTable(target, temporary.recordedClock, tables.recordedClock);
422
+ await renamePrimaryKeyConstraint(
423
+ target,
424
+ temporary.recordedNodes,
425
+ tables.recordedNodes
426
+ );
427
+ await renamePrimaryKeyConstraint(
428
+ target,
429
+ temporary.recordedEdges,
430
+ tables.recordedEdges
431
+ );
432
+ await renamePrimaryKeyConstraint(
433
+ target,
434
+ temporary.recordedClock,
435
+ tables.recordedClock
436
+ );
437
+ for (const statement of [
438
+ ...ddl.nodes.slice(1),
439
+ ...ddl.edges.slice(1),
440
+ ...ddl.clock.slice(1)
441
+ ]) {
442
+ await executeDdl(target, statement);
443
+ }
444
+ }
445
+ async function renamePrimaryKeyConstraint(target, temporaryTable, finalTable) {
446
+ if (target.dialect !== "postgres") return;
447
+ await executeStatement(
448
+ target,
449
+ chunkYX3H63VV_cjs.sql`
450
+ ALTER TABLE ${chunkYX3H63VV_cjs.sql.identifier(finalTable)}
451
+ RENAME CONSTRAINT ${chunkYX3H63VV_cjs.sql.identifier(`${temporaryTable}_pkey`)}
452
+ TO ${chunkYX3H63VV_cjs.sql.identifier(shortenedIdentifier(`${finalTable}_pkey`))}
453
+ `
454
+ );
455
+ }
456
+ function requireCreateTable(statements) {
457
+ const statement = statements[0];
458
+ if (statement === void 0) {
459
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError("Recorded migration table DDL was empty.");
460
+ }
461
+ return statement;
462
+ }
463
+ async function renameTable(target, from, to) {
464
+ try {
465
+ await executeStatement(
466
+ target,
467
+ chunkYX3H63VV_cjs.sql`ALTER TABLE ${chunkYX3H63VV_cjs.sql.identifier(from)} RENAME TO ${chunkYX3H63VV_cjs.sql.identifier(to)}`
468
+ );
469
+ } catch (error) {
470
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
471
+ "Could not rename a migrated recorded-time table.",
472
+ { from, to },
473
+ { cause: error }
474
+ );
475
+ }
476
+ }
477
+ async function migrateLegacyRecordedTime(options) {
478
+ const tables = resolvedTableNames(options.backend, options.tableNames);
479
+ const mapTable = mappingTableName(tables, options.mappingTableName);
480
+ return options.backend.transaction(async (target) => {
481
+ const clockColumns = await columnNames(target, tables.recordedClock);
482
+ if (clockColumns.size === 0) {
483
+ return {
484
+ migrated: false,
485
+ graphs: 0,
486
+ anchors: 0,
487
+ mappingTableName: mapTable
488
+ };
489
+ }
490
+ if (clockColumns.has("revision")) {
491
+ const mapColumns = await columnNames(target, mapTable);
492
+ if (mapColumns.size === 0) {
493
+ return {
494
+ migrated: false,
495
+ graphs: 0,
496
+ anchors: 0,
497
+ mappingTableName: mapTable
498
+ };
499
+ }
500
+ const rows = await target.execute(
501
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
502
+ SELECT COUNT(*) AS anchors, COUNT(DISTINCT graph_id) AS graphs
503
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(mapTable)}
504
+ `)
505
+ );
506
+ const anchors = Number(rows[0]?.anchors ?? 0);
507
+ const graphs = Number(rows[0]?.graphs ?? 0);
508
+ return {
509
+ migrated: false,
510
+ graphs: Number.isSafeInteger(graphs) ? graphs : 0,
511
+ anchors: Number.isSafeInteger(anchors) ? anchors : 0,
512
+ mappingTableName: mapTable
513
+ };
514
+ }
515
+ const nodeColumns = await columnNames(target, tables.recordedNodes);
516
+ const edgeColumns = await columnNames(target, tables.recordedEdges);
517
+ if (!nodeColumns.has("recorded_from") || !edgeColumns.has("recorded_from")) {
518
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
519
+ "Legacy recorded-time schema is incomplete.",
520
+ { tables }
521
+ );
522
+ }
523
+ await executeDdl(target, migrationMapDdl(target.dialect, mapTable));
524
+ const mapping = await readLegacyInstants(target, tables);
525
+ await writeMappingRows(target, mapTable, mapping);
526
+ await replaceLegacyTables(target, tables, mapTable);
527
+ return {
528
+ migrated: true,
529
+ graphs: new Set(mapping.map((row) => row.graphId)).size,
530
+ anchors: mapping.length,
531
+ mappingTableName: mapTable
532
+ };
533
+ });
534
+ }
535
+ async function migrateRecordedAnchor(options) {
536
+ try {
537
+ return chunkLL5D5T5W_cjs.asRecordedInstant(options.anchor);
538
+ } catch (error) {
539
+ if (!(error instanceof chunkSAFZ6JTI_cjs.ValidationError)) throw error;
540
+ }
541
+ const legacyRecordedAt = canonicalLegacyInstant(options.anchor);
542
+ const tables = resolvedTableNames(options.backend, options.tableNames);
543
+ const mapTable = mappingTableName(tables, options.mappingTableName);
544
+ const rows = await options.backend.execute(
545
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
546
+ SELECT revision, recorded_at
547
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(mapTable)}
548
+ WHERE graph_id = ${options.graphId}
549
+ AND legacy_recorded_at = ${legacyRecordedAt}
550
+ `)
551
+ );
552
+ const row = rows[0];
553
+ if (row === void 0) {
554
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
555
+ "No migrated recorded anchor matches this graph and legacy timestamp.",
556
+ { anchor: options.anchor, graphId: options.graphId },
557
+ {
558
+ suggestion: "Run migrateLegacyRecordedTime() before deleting its mapping rows, and pass the graph that produced the checkpoint."
559
+ }
560
+ );
561
+ }
562
+ return chunkLL5D5T5W_cjs.createRecordedInstant(
563
+ safeRevision(row.revision),
564
+ canonicalLegacyInstant(row.recorded_at)
565
+ );
566
+ }
567
+ async function deleteLegacyRecordedAnchorMap(options) {
568
+ if (options.backend.executeStatement === void 0) {
569
+ throw new chunkSAFZ6JTI_cjs.ConfigurationError(
570
+ "Deleting a recorded anchor migration map requires executeStatement support.",
571
+ { dialect: options.backend.dialect }
572
+ );
573
+ }
574
+ const tables = resolvedTableNames(options.backend, options.tableNames);
575
+ const mapTable = mappingTableName(tables, options.mappingTableName);
576
+ await options.backend.transaction(async (target) => {
577
+ await executeStatement(
578
+ target,
579
+ chunkYX3H63VV_cjs.sql`
580
+ DELETE FROM ${chunkYX3H63VV_cjs.sql.identifier(mapTable)}
581
+ WHERE graph_id = ${options.graphId}
582
+ `
583
+ );
584
+ if (options.dropWhenEmpty !== true) return;
585
+ const rows = await target.execute(
586
+ chunkYX3H63VV_cjs.asCompiledRowsSql(chunkYX3H63VV_cjs.sql`
587
+ SELECT COUNT(*) AS anchors, COUNT(DISTINCT graph_id) AS graphs
588
+ FROM ${chunkYX3H63VV_cjs.sql.identifier(mapTable)}
589
+ `)
590
+ );
591
+ const remaining = missingMappingCount(rows[0]?.anchors, mapTable);
592
+ if (remaining === 0) {
593
+ await executeStatement(
594
+ target,
595
+ chunkYX3H63VV_cjs.sql`DROP TABLE ${chunkYX3H63VV_cjs.sql.identifier(mapTable)}`
596
+ );
597
+ }
598
+ });
599
+ }
600
+
601
+ exports.deleteLegacyRecordedAnchorMap = deleteLegacyRecordedAnchorMap;
602
+ exports.migrateLegacyRecordedTime = migrateLegacyRecordedTime;
603
+ exports.migrateRecordedAnchor = migrateRecordedAnchor;
604
+ //# sourceMappingURL=chunk-7WLEQIHA.cjs.map
605
+ //# sourceMappingURL=chunk-7WLEQIHA.cjs.map