@prisma/orm-toolchain 0.16.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 (321) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +28 -0
  3. package/dist/aggregate-B4mhR4Sk.mjs +1012 -0
  4. package/dist/aggregate-B4mhR4Sk.mjs.map +1 -0
  5. package/dist/aggregate-BflrjWPO.d.mts +803 -0
  6. package/dist/aggregate-BflrjWPO.d.mts.map +1 -0
  7. package/dist/bin__prisma-next.mjs +800 -0
  8. package/dist/bin__prisma-next.mjs.map +1 -0
  9. package/dist/cli-telemetry.d.mts +367 -0
  10. package/dist/cli-telemetry.d.mts.map +1 -0
  11. package/dist/cli-telemetry.mjs +48 -0
  12. package/dist/cli-telemetry.mjs.map +1 -0
  13. package/dist/cli-telemetry__sender.d.mts +1 -0
  14. package/dist/cli-telemetry__sender.mjs +1 -0
  15. package/dist/cli.d.mts +31 -0
  16. package/dist/cli.d.mts.map +1 -0
  17. package/dist/cli.mjs +180 -0
  18. package/dist/cli.mjs.map +1 -0
  19. package/dist/cli__commands__contract-emit.d.mts +2 -0
  20. package/dist/cli__commands__contract-emit.mjs +2 -0
  21. package/dist/cli__commands__contract-infer.d.mts +7 -0
  22. package/dist/cli__commands__contract-infer.d.mts.map +1 -0
  23. package/dist/cli__commands__contract-infer.mjs +2 -0
  24. package/dist/cli__commands__db-init.d.mts +7 -0
  25. package/dist/cli__commands__db-init.d.mts.map +1 -0
  26. package/dist/cli__commands__db-init.mjs +2 -0
  27. package/dist/cli__commands__db-schema.d.mts +7 -0
  28. package/dist/cli__commands__db-schema.d.mts.map +1 -0
  29. package/dist/cli__commands__db-schema.mjs +2 -0
  30. package/dist/cli__commands__db-sign.d.mts +7 -0
  31. package/dist/cli__commands__db-sign.d.mts.map +1 -0
  32. package/dist/cli__commands__db-sign.mjs +2 -0
  33. package/dist/cli__commands__db-update.d.mts +7 -0
  34. package/dist/cli__commands__db-update.d.mts.map +1 -0
  35. package/dist/cli__commands__db-update.mjs +2 -0
  36. package/dist/cli__commands__db-verify.d.mts +7 -0
  37. package/dist/cli__commands__db-verify.d.mts.map +1 -0
  38. package/dist/cli__commands__db-verify.mjs +2 -0
  39. package/dist/cli__commands__migrate.d.mts +66 -0
  40. package/dist/cli__commands__migrate.d.mts.map +1 -0
  41. package/dist/cli__commands__migrate.mjs +2 -0
  42. package/dist/cli__commands__migration-check.d.mts +64 -0
  43. package/dist/cli__commands__migration-check.d.mts.map +1 -0
  44. package/dist/cli__commands__migration-check.mjs +3 -0
  45. package/dist/cli__commands__migration-graph.d.mts +36 -0
  46. package/dist/cli__commands__migration-graph.d.mts.map +1 -0
  47. package/dist/cli__commands__migration-graph.mjs +2 -0
  48. package/dist/cli__commands__migration-list.d.mts +79 -0
  49. package/dist/cli__commands__migration-list.d.mts.map +1 -0
  50. package/dist/cli__commands__migration-list.mjs +2 -0
  51. package/dist/cli__commands__migration-log.d.mts +20 -0
  52. package/dist/cli__commands__migration-log.d.mts.map +1 -0
  53. package/dist/cli__commands__migration-log.mjs +2 -0
  54. package/dist/cli__commands__migration-new.d.mts +7 -0
  55. package/dist/cli__commands__migration-new.d.mts.map +1 -0
  56. package/dist/cli__commands__migration-new.mjs +2 -0
  57. package/dist/cli__commands__migration-plan.d.mts +79 -0
  58. package/dist/cli__commands__migration-plan.d.mts.map +1 -0
  59. package/dist/cli__commands__migration-plan.mjs +2 -0
  60. package/dist/cli__commands__migration-show.d.mts +27 -0
  61. package/dist/cli__commands__migration-show.d.mts.map +1 -0
  62. package/dist/cli__commands__migration-show.mjs +2 -0
  63. package/dist/cli__commands__migration-status.d.mts +55 -0
  64. package/dist/cli__commands__migration-status.d.mts.map +1 -0
  65. package/dist/cli__commands__migration-status.mjs +3 -0
  66. package/dist/cli__commands__ref.d.mts +34 -0
  67. package/dist/cli__commands__ref.d.mts.map +1 -0
  68. package/dist/cli__commands__ref.mjs +2 -0
  69. package/dist/cli__commands__telemetry.d.mts +7 -0
  70. package/dist/cli__commands__telemetry.d.mts.map +1 -0
  71. package/dist/cli__commands__telemetry.mjs +2 -0
  72. package/dist/cli__config-types.d.mts +2 -0
  73. package/dist/cli__config-types.mjs +2 -0
  74. package/dist/cli__control-api.d.mts +141 -0
  75. package/dist/cli__control-api.d.mts.map +1 -0
  76. package/dist/cli__control-api.mjs +4 -0
  77. package/dist/cli__init-output.d.mts +37 -0
  78. package/dist/cli__init-output.d.mts.map +1 -0
  79. package/dist/cli__init-output.mjs +2 -0
  80. package/dist/cli__migration-cli.d.mts +79 -0
  81. package/dist/cli__migration-cli.d.mts.map +1 -0
  82. package/dist/cli__migration-cli.mjs +407 -0
  83. package/dist/cli__migration-cli.mjs.map +1 -0
  84. package/dist/client-75qrAPqf-DZAVUxFa.mjs +1606 -0
  85. package/dist/client-75qrAPqf-DZAVUxFa.mjs.map +1 -0
  86. package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs +1671 -0
  87. package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs.map +1 -0
  88. package/dist/config-loader.d.mts +18 -0
  89. package/dist/config-loader.d.mts.map +1 -0
  90. package/dist/config-loader.mjs +2 -0
  91. package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs +10 -0
  92. package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs.map +1 -0
  93. package/dist/constants-Dkcn8Qu4.d.mts +10 -0
  94. package/dist/constants-Dkcn8Qu4.d.mts.map +1 -0
  95. package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs +36 -0
  96. package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs.map +1 -0
  97. package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs +148 -0
  98. package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs.map +1 -0
  99. package/dist/contract-emit-B65_UiFn.d.mts +7 -0
  100. package/dist/contract-emit-B65_UiFn.d.mts.map +1 -0
  101. package/dist/contract-emit-B6odMoem-CK3diBPk.mjs +359 -0
  102. package/dist/contract-emit-B6odMoem-CK3diBPk.mjs.map +1 -0
  103. package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs +56 -0
  104. package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs.map +1 -0
  105. package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs +73 -0
  106. package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs.map +1 -0
  107. package/dist/contract-snapshot-store-CbqynbtE.d.mts +28 -0
  108. package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +1 -0
  109. package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs +118 -0
  110. package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs.map +1 -0
  111. package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs +302 -0
  112. package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs.map +1 -0
  113. package/dist/db-init-Vbkb_TKZ.mjs +153 -0
  114. package/dist/db-init-Vbkb_TKZ.mjs.map +1 -0
  115. package/dist/db-schema-ClQCu3xY.mjs +47 -0
  116. package/dist/db-schema-ClQCu3xY.mjs.map +1 -0
  117. package/dist/db-sign-jjXDgQ1u.mjs +175 -0
  118. package/dist/db-sign-jjXDgQ1u.mjs.map +1 -0
  119. package/dist/db-update-BQlrqtDD.mjs +183 -0
  120. package/dist/db-update-BQlrqtDD.mjs.map +1 -0
  121. package/dist/db-verify-CKPsRFrj-3udprZQD.mjs +396 -0
  122. package/dist/db-verify-CKPsRFrj-3udprZQD.mjs.map +1 -0
  123. package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs +334 -0
  124. package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs.map +1 -0
  125. package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +63 -0
  126. package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +1 -0
  127. package/dist/emitter.d.mts +75 -0
  128. package/dist/emitter.d.mts.map +1 -0
  129. package/dist/emitter.mjs +3 -0
  130. package/dist/emitter__domain-type-generation.d.mts +2 -0
  131. package/dist/emitter__domain-type-generation.mjs +2 -0
  132. package/dist/emitter__type-expression-safety.d.mts +6 -0
  133. package/dist/emitter__type-expression-safety.d.mts.map +1 -0
  134. package/dist/emitter__type-expression-safety.mjs +2 -0
  135. package/dist/errors--qsXZUtL.d.mts +72 -0
  136. package/dist/errors--qsXZUtL.d.mts.map +1 -0
  137. package/dist/errors-IpZm1Skp-BH495dRd.mjs +378 -0
  138. package/dist/errors-IpZm1Skp-BH495dRd.mjs.map +1 -0
  139. package/dist/exports-BN0vFTxG.mjs +276 -0
  140. package/dist/exports-BN0vFTxG.mjs.map +1 -0
  141. package/dist/exports-B_xhKZmC.mjs +1436 -0
  142. package/dist/exports-B_xhKZmC.mjs.map +1 -0
  143. package/dist/exports-D3-NwrMA-CadaBGQ3.mjs +154 -0
  144. package/dist/exports-D3-NwrMA-CadaBGQ3.mjs.map +1 -0
  145. package/dist/exports-Dl2aGAk7.mjs +119 -0
  146. package/dist/exports-Dl2aGAk7.mjs.map +1 -0
  147. package/dist/format-ByDm2goZ-DKLyhNHo.mjs +101 -0
  148. package/dist/format-ByDm2goZ-DKLyhNHo.mjs.map +1 -0
  149. package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs +58 -0
  150. package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs.map +1 -0
  151. package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts +35 -0
  152. package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts.map +1 -0
  153. package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts +28 -0
  154. package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts.map +1 -0
  155. package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs +14 -0
  156. package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs.map +1 -0
  157. package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs +64 -0
  158. package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +1 -0
  159. package/dist/hash-XZYYKJ-i.d.mts +53 -0
  160. package/dist/hash-XZYYKJ-i.d.mts.map +1 -0
  161. package/dist/import-roots-B6CtsWXb.d.mts +119 -0
  162. package/dist/import-roots-B6CtsWXb.d.mts.map +1 -0
  163. package/dist/import-roots-NDOIEDVj.mjs +217 -0
  164. package/dist/import-roots-NDOIEDVj.mjs.map +1 -0
  165. package/dist/init-DHctXAI9-DSlaaYXN.mjs +2186 -0
  166. package/dist/init-DHctXAI9-DSlaaYXN.mjs.map +1 -0
  167. package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs +91 -0
  168. package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs.map +1 -0
  169. package/dist/invariants-B5wLrgQS.d.mts +39 -0
  170. package/dist/invariants-B5wLrgQS.d.mts.map +1 -0
  171. package/dist/invariants-lXzy6txi-DAoP4nTE.mjs +57 -0
  172. package/dist/invariants-lXzy6txi-DAoP4nTE.mjs.map +1 -0
  173. package/dist/io-C8TdyBKt-DloEBi70.mjs +313 -0
  174. package/dist/io-C8TdyBKt-DloEBi70.mjs.map +1 -0
  175. package/dist/io-DYfeLJxR.d.mts +1 -0
  176. package/dist/io-sr4CO9_t-C3eV_kn-.d.mts +125 -0
  177. package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +1 -0
  178. package/dist/ledger-origin-BGRN77Oy.d.mts +6 -0
  179. package/dist/ledger-origin-BGRN77Oy.d.mts.map +1 -0
  180. package/dist/ledger-origin-D7PN4Fon.mjs +9 -0
  181. package/dist/ledger-origin-D7PN4Fon.mjs.map +1 -0
  182. package/dist/metadata-2nbOAGsV-uYNeq2Cp.d.mts +2 -0
  183. package/dist/metadata-BtscDay2.d.mts +1 -0
  184. package/dist/migrate-Cb_iv264.mjs +500 -0
  185. package/dist/migrate-Cb_iv264.mjs.map +1 -0
  186. package/dist/migration-B2ljMJim.d.mts +155 -0
  187. package/dist/migration-B2ljMJim.d.mts.map +1 -0
  188. package/dist/migration-BuUmO7It.mjs +209 -0
  189. package/dist/migration-BuUmO7It.mjs.map +1 -0
  190. package/dist/migration-check-DcwUnadt-B6Qoh0ot.mjs +597 -0
  191. package/dist/migration-check-DcwUnadt-B6Qoh0ot.mjs.map +1 -0
  192. package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs +103 -0
  193. package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs.map +1 -0
  194. package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs +500 -0
  195. package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs.map +1 -0
  196. package/dist/migration-graph-DkoCC0Qy.mjs +185 -0
  197. package/dist/migration-graph-DkoCC0Qy.mjs.map +1 -0
  198. package/dist/migration-graph-Dqndu0i5.d.mts +9 -0
  199. package/dist/migration-graph-Dqndu0i5.d.mts.map +1 -0
  200. package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs +1945 -0
  201. package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs.map +1 -0
  202. package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts +124 -0
  203. package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +1 -0
  204. package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs +228 -0
  205. package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs.map +1 -0
  206. package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs +220 -0
  207. package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs.map +1 -0
  208. package/dist/migration-new-BurCjyaQ.mjs +168 -0
  209. package/dist/migration-new-BurCjyaQ.mjs.map +1 -0
  210. package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs +38 -0
  211. package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs.map +1 -0
  212. package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs +759 -0
  213. package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs.map +1 -0
  214. package/dist/migration-show-Bx5I5aW9.mjs +171 -0
  215. package/dist/migration-show-Bx5I5aW9.mjs.map +1 -0
  216. package/dist/migration-status-CE7cQLDq-B1jDVmqG.mjs +444 -0
  217. package/dist/migration-status-CE7cQLDq-B1jDVmqG.mjs.map +1 -0
  218. package/dist/migration-tools.d.mts +23 -0
  219. package/dist/migration-tools.mjs +17 -0
  220. package/dist/migration-tools__aggregate.d.mts +2 -0
  221. package/dist/migration-tools__aggregate.mjs +2 -0
  222. package/dist/migration-tools__constants.d.mts +2 -0
  223. package/dist/migration-tools__constants.mjs +2 -0
  224. package/dist/migration-tools__contract-snapshot-store.d.mts +2 -0
  225. package/dist/migration-tools__contract-snapshot-store.mjs +2 -0
  226. package/dist/migration-tools__errors.d.mts +2 -0
  227. package/dist/migration-tools__errors.mjs +2 -0
  228. package/dist/migration-tools__graph.d.mts +2 -0
  229. package/dist/migration-tools__graph.mjs +1 -0
  230. package/dist/migration-tools__hash.d.mts +2 -0
  231. package/dist/migration-tools__hash.mjs +2 -0
  232. package/dist/migration-tools__invariants.d.mts +2 -0
  233. package/dist/migration-tools__invariants.mjs +2 -0
  234. package/dist/migration-tools__io.d.mts +3 -0
  235. package/dist/migration-tools__io.mjs +2 -0
  236. package/dist/migration-tools__ledger-origin.d.mts +2 -0
  237. package/dist/migration-tools__ledger-origin.mjs +2 -0
  238. package/dist/migration-tools__metadata.d.mts +3 -0
  239. package/dist/migration-tools__metadata.mjs +1 -0
  240. package/dist/migration-tools__migration-graph.d.mts +3 -0
  241. package/dist/migration-tools__migration-graph.mjs +3 -0
  242. package/dist/migration-tools__migration-ts.d.mts +2 -0
  243. package/dist/migration-tools__migration-ts.mjs +2 -0
  244. package/dist/migration-tools__migration.d.mts +2 -0
  245. package/dist/migration-tools__migration.mjs +2 -0
  246. package/dist/migration-tools__package.d.mts +3 -0
  247. package/dist/migration-tools__package.mjs +1 -0
  248. package/dist/migration-tools__ref-resolution.d.mts +2 -0
  249. package/dist/migration-tools__ref-resolution.mjs +2 -0
  250. package/dist/migration-tools__refs.d.mts +2 -0
  251. package/dist/migration-tools__refs.mjs +2 -0
  252. package/dist/migration-tools__spaces.d.mts +3 -0
  253. package/dist/migration-tools__spaces.mjs +3 -0
  254. package/dist/migration-ts-CNaAtK8C.d.mts +38 -0
  255. package/dist/migration-ts-CNaAtK8C.d.mts.map +1 -0
  256. package/dist/migration-ts-FyF55c4M.mjs +67 -0
  257. package/dist/migration-ts-FyF55c4M.mjs.map +1 -0
  258. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +13 -0
  259. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +1 -0
  260. package/dist/output-DWNYqZGc-D2sRgLAm.mjs +109 -0
  261. package/dist/output-DWNYqZGc-D2sRgLAm.mjs.map +1 -0
  262. package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts +21 -0
  263. package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts.map +1 -0
  264. package/dist/package-N9PPdFV_.d.mts +3 -0
  265. package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs +43 -0
  266. package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs.map +1 -0
  267. package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs +99 -0
  268. package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs.map +1 -0
  269. package/dist/publish-surface.d.mts +3 -0
  270. package/dist/publish-surface.mjs +3 -0
  271. package/dist/publish-surface__import-roots.d.mts +2 -0
  272. package/dist/publish-surface__import-roots.mjs +2 -0
  273. package/dist/publish-surface__shells.d.mts +2 -0
  274. package/dist/publish-surface__shells.mjs +2 -0
  275. package/dist/quick-reference-mongo.md +114 -0
  276. package/dist/quick-reference-postgres.md +93 -0
  277. package/dist/readme-mongo.md +35 -0
  278. package/dist/readme-postgres.md +34 -0
  279. package/dist/ref-B6cTthTi.mjs +171 -0
  280. package/dist/ref-B6cTthTi.mjs.map +1 -0
  281. package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs +57 -0
  282. package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs.map +1 -0
  283. package/dist/ref-resolution-BjJBWPjX.mjs +250 -0
  284. package/dist/ref-resolution-BjJBWPjX.mjs.map +1 -0
  285. package/dist/ref-resolution-COGOSL57.d.mts +127 -0
  286. package/dist/ref-resolution-COGOSL57.d.mts.map +1 -0
  287. package/dist/refs-BDbB9BRB-D6Za3Q49.mjs +241 -0
  288. package/dist/refs-BDbB9BRB-D6Za3Q49.mjs.map +1 -0
  289. package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts +43 -0
  290. package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts.map +1 -0
  291. package/dist/schemas-CfGSxH5b-BSjB3nZS.d.mts +192 -0
  292. package/dist/schemas-CfGSxH5b-BSjB3nZS.d.mts.map +1 -0
  293. package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs +112 -0
  294. package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs.map +1 -0
  295. package/dist/shells-BenrJHp2.mjs +602 -0
  296. package/dist/shells-BenrJHp2.mjs.map +1 -0
  297. package/dist/shells-COHV_Ozf.d.mts +135 -0
  298. package/dist/shells-COHV_Ozf.d.mts.map +1 -0
  299. package/dist/spaces-C27bA-xc.mjs +267 -0
  300. package/dist/spaces-C27bA-xc.mjs.map +1 -0
  301. package/dist/spaces-DxFj5y8l.d.mts +415 -0
  302. package/dist/spaces-DxFj5y8l.d.mts.map +1 -0
  303. package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs +120 -0
  304. package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs.map +1 -0
  305. package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts +133 -0
  306. package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts.map +1 -0
  307. package/dist/type-expression-safety-CgHTWypx.mjs +8 -0
  308. package/dist/type-expression-safety-CgHTWypx.mjs.map +1 -0
  309. package/dist/types-DZWEs4si-D8UlyJI0.d.mts +893 -0
  310. package/dist/types-DZWEs4si-D8UlyJI0.d.mts.map +1 -0
  311. package/dist/verify-DnVNjc5C-BGdsblBK.mjs +283 -0
  312. package/dist/verify-DnVNjc5C-BGdsblBK.mjs.map +1 -0
  313. package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs +252 -0
  314. package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs.map +1 -0
  315. package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts +136 -0
  316. package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts.map +1 -0
  317. package/dist/vite-plugin-contract-emit.d.mts +54 -0
  318. package/dist/vite-plugin-contract-emit.d.mts.map +1 -0
  319. package/dist/vite-plugin-contract-emit.mjs +303 -0
  320. package/dist/vite-plugin-contract-emit.mjs.map +1 -0
  321. package/package.json +122 -0
@@ -0,0 +1,1945 @@
1
+ import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
2
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
3
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
4
+ import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
5
+ import stringWidth from "string-width";
6
+ //#region ../../../1-framework/3-tooling/cli/dist/migration-graph-command-render-BKrg6BPv.mjs
7
+ /**
8
+ * Occlusion renderer for the line/plane/occlusion migration-graph.
9
+ *
10
+ * Per cell: pick the topmost-plane line (lowest plane number = drawn on top),
11
+ * look up its glyph, apply colour from the line's lane or role. Lower-plane
12
+ * lines are occluded (not drawn).
13
+ *
14
+ * Colour is forced via createColors({ useColor: true }) regardless of NO_COLOR.
15
+ */
16
+ const palette = createColors({ useColor: true });
17
+ const LANE_COLORIZERS = [
18
+ palette.white,
19
+ palette.cyan,
20
+ palette.yellow,
21
+ palette.blueBright,
22
+ palette.magenta,
23
+ palette.green
24
+ ];
25
+ function laneColor(lane) {
26
+ return LANE_COLORIZERS[lane % LANE_COLORIZERS.length] ?? ((t) => t);
27
+ }
28
+ /**
29
+ * The colourizer for a lane's hue (lane0 = white, lane1 = cyan, …). Exported
30
+ * so the per-row LABEL renderer can tint a migration name in its lane's colour,
31
+ * matching the node `○`, the edges, and the arrows drawn in the gutter — one
32
+ * colour per lane across glyph and text.
33
+ */
34
+ function laneColorizer(lane) {
35
+ return laneColor(lane);
36
+ }
37
+ function roleColor(role) {
38
+ return role === "on-path" ? palette.greenBright : palette.dim;
39
+ }
40
+ const UNICODE_ALPHABET = {
41
+ vertical: "│",
42
+ horizontal: "─",
43
+ cornerUpRight: "╰",
44
+ cornerDownRight: "╭",
45
+ cornerUpLeft: "╯",
46
+ cornerDownLeft: "╮",
47
+ arrowUp: "↑",
48
+ arrowDown: "↓",
49
+ node: "○",
50
+ selfLoop: "⟲",
51
+ landingArrow: "◂",
52
+ fallback: "?"
53
+ };
54
+ const ASCII_ALPHABET = {
55
+ vertical: "|",
56
+ horizontal: "-",
57
+ cornerUpRight: "\\",
58
+ cornerDownRight: "/",
59
+ cornerUpLeft: "/",
60
+ cornerDownLeft: "\\",
61
+ arrowUp: "^",
62
+ arrowDown: "v",
63
+ node: "*",
64
+ selfLoop: "@",
65
+ landingArrow: "<",
66
+ fallback: "?"
67
+ };
68
+ function alphabetFor(mode) {
69
+ return mode === "ascii" ? ASCII_ALPHABET : UNICODE_ALPHABET;
70
+ }
71
+ function glyphFor(dirs, alphabet) {
72
+ const has = (d) => dirs.has(d);
73
+ if (has("up") && has("down") && !has("left") && !has("right")) return alphabet.vertical;
74
+ if (has("left") && has("right") && !has("up") && !has("down")) return alphabet.horizontal;
75
+ if (has("up") && has("right") && !has("down") && !has("left")) return alphabet.cornerUpRight;
76
+ if (has("down") && has("right") && !has("up") && !has("left")) return alphabet.cornerDownRight;
77
+ if (has("up") && has("left") && !has("down") && !has("right")) return alphabet.cornerUpLeft;
78
+ if (has("down") && has("left") && !has("up") && !has("right")) return alphabet.cornerDownLeft;
79
+ if (has("up") && !has("down") && !has("left") && !has("right")) return alphabet.arrowUp;
80
+ if (has("down") && !has("up") && !has("left") && !has("right")) return alphabet.arrowDown;
81
+ return alphabet.fallback;
82
+ }
83
+ const NO_COLOR = (t) => t;
84
+ function renderCell(cell, colorEnabled, alphabet) {
85
+ if (cell.node !== void 0) return (!colorEnabled ? NO_COLOR : cell.node.role !== void 0 ? roleColor(cell.node.role) : laneColor(cell.node.lane))(alphabet.node);
86
+ if (cell.lines.length === 0) return " ";
87
+ const topLine = cell.lines.reduce((best, current) => {
88
+ if (current.plane < best.plane) return current;
89
+ if (current.plane > best.plane) return best;
90
+ if (current.line.role === "on-path" && best.line.role !== "on-path") return current;
91
+ return best;
92
+ }, cell.lines[0]);
93
+ const glyph = topLine.selfLoop === true ? alphabet.selfLoop : topLine.landingArrow === true ? alphabet.landingArrow : glyphFor(topLine.directions, alphabet);
94
+ return (!colorEnabled ? NO_COLOR : topLine.line.role !== void 0 ? roleColor(topLine.line.role) : laneColor(topLine.line.lane))(glyph);
95
+ }
96
+ /**
97
+ * Render a single grid row to a coloured string. A completely empty row returns
98
+ * the empty string (the row is NOT dropped) so callers that pair grid rows with
99
+ * an external per-row label list keep a 1:1 index correspondence. `renderGrid`
100
+ * itself drops empty rows for its standalone output (but preserves separator rows).
101
+ */
102
+ function renderGridRow(row, opts = {}) {
103
+ if (row[0]?.separator === true) return "";
104
+ let lastNonEmpty = -1;
105
+ for (let i = row.length - 1; i >= 0; i--) {
106
+ const cell = row[i];
107
+ if (cell !== void 0 && (cell.lines.length > 0 || cell.node !== void 0)) {
108
+ lastNonEmpty = i;
109
+ break;
110
+ }
111
+ }
112
+ if (lastNonEmpty < 0) return "";
113
+ const colsPerLane = opts.colsPerLane ?? 2;
114
+ const colorEnabled = opts.colorize ?? true;
115
+ const alphabet = alphabetFor(opts.glyphMode ?? "unicode");
116
+ const lastConnectorCol = Math.floor(lastNonEmpty / colsPerLane) * colsPerLane + (colsPerLane - 1);
117
+ const renderThrough = Math.max(lastNonEmpty, lastConnectorCol);
118
+ let line = "";
119
+ for (let col = 0; col <= Math.min(renderThrough, row.length - 1); col++) {
120
+ const cell = row[col];
121
+ line += cell === void 0 ? " " : renderCell(cell, colorEnabled, alphabet);
122
+ }
123
+ return line;
124
+ }
125
+ function migrationListForwardArrow(glyphMode) {
126
+ return glyphMode === "ascii" ? "->" : "→";
127
+ }
128
+ function migrationListEmptySource(glyphMode) {
129
+ return glyphMode === "ascii" ? "-" : "∅";
130
+ }
131
+ function abbreviateContractHash(hash) {
132
+ return hash.slice(0, 7);
133
+ }
134
+ function padFromHashColumn(text, width) {
135
+ const padding = Math.max(0, width - stringWidth(text));
136
+ return `${" ".repeat(padding)}${text}`;
137
+ }
138
+ /**
139
+ * Grid layout for the line/plane/occlusion migration-graph renderer.
140
+ *
141
+ * Produces a Grid (rows × cells) from a MigrationGraphRowModel. Each node
142
+ * emits: fork connector, self-loop rows, node row, merge connector, and
143
+ * inbound migration rows — in display order (tips first, then roots).
144
+ */
145
+ function buildLaneAssignment(nodes, edges) {
146
+ const fwdEdges = edges.filter((e) => e.kind === "forward" && e.from !== e.to);
147
+ const outbound = /* @__PURE__ */ new Map();
148
+ const inbound = /* @__PURE__ */ new Map();
149
+ for (const edge of fwdEdges) {
150
+ const ob = outbound.get(edge.from);
151
+ if (ob) ob.push(edge);
152
+ else outbound.set(edge.from, [edge]);
153
+ const ib = inbound.get(edge.to);
154
+ if (ib) ib.push(edge);
155
+ else inbound.set(edge.to, [edge]);
156
+ }
157
+ for (const list of outbound.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
158
+ for (const list of inbound.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
159
+ const components = [];
160
+ let current = [];
161
+ for (const n of nodes) if (n === null) {
162
+ if (current.length > 0) components.push(current);
163
+ current = [];
164
+ } else current.push(n);
165
+ if (current.length > 0) components.push(current);
166
+ const allNodes = /* @__PURE__ */ new Set();
167
+ for (const n of nodes) if (n !== null) allNodes.add(n);
168
+ const nodeRank = /* @__PURE__ */ new Map();
169
+ for (const n of allNodes) nodeRank.set(n, 0);
170
+ for (let pass = 0; pass < allNodes.size; pass++) {
171
+ let changed = false;
172
+ for (const [from, es] of outbound) {
173
+ const base = nodeRank.get(from) ?? 0;
174
+ for (const e of es) {
175
+ const next = base + 1;
176
+ if (next > (nodeRank.get(e.to) ?? 0)) {
177
+ nodeRank.set(e.to, next);
178
+ changed = true;
179
+ }
180
+ }
181
+ }
182
+ if (!changed) break;
183
+ }
184
+ const nodeLane = /* @__PURE__ */ new Map();
185
+ const edgeLane = /* @__PURE__ */ new Map();
186
+ let totalLanes = 0;
187
+ for (const componentNodes of components) {
188
+ const componentSet = new Set(componentNodes);
189
+ let nextLane = 0;
190
+ const roots = [];
191
+ for (const n of componentNodes) if ((inbound.get(n) ?? []).length === 0) roots.push(n);
192
+ roots.sort((a, b) => {
193
+ if (a === "empty") return -1;
194
+ if (b === "empty") return 1;
195
+ return a.localeCompare(b);
196
+ });
197
+ const bfsQueue = [];
198
+ for (const root of roots) if (!nodeLane.has(root)) {
199
+ nodeLane.set(root, nextLane++);
200
+ bfsQueue.push({
201
+ node: root,
202
+ lane: nodeLane.get(root)
203
+ });
204
+ }
205
+ let head = 0;
206
+ while (head < bfsQueue.length) {
207
+ const { node, lane } = bfsQueue[head++];
208
+ const children = outbound.get(node) ?? [];
209
+ let first = true;
210
+ for (const childEdge of children) {
211
+ const child = childEdge.to;
212
+ if (!componentSet.has(child)) continue;
213
+ if (!nodeLane.has(child)) {
214
+ const childLane = first ? lane : nextLane++;
215
+ nodeLane.set(child, childLane);
216
+ bfsQueue.push({
217
+ node: child,
218
+ lane: childLane
219
+ });
220
+ edgeLane.set(childEdge.migrationHash, childLane);
221
+ } else edgeLane.set(childEdge.migrationHash, Math.max(lane, nodeLane.get(child)));
222
+ first = false;
223
+ }
224
+ }
225
+ for (const n of componentNodes) if (!nodeLane.has(n)) nodeLane.set(n, nextLane++);
226
+ for (const n of componentNodes) {
227
+ const parents = inbound.get(n);
228
+ if (!parents || parents.length <= 1) continue;
229
+ let trunkParent = parents[0].from;
230
+ let trunkRank = nodeRank.get(trunkParent) ?? 0;
231
+ let trunkLane = nodeLane.get(trunkParent) ?? 0;
232
+ for (let i = 1; i < parents.length; i++) {
233
+ const parent = parents[i].from;
234
+ const rank = nodeRank.get(parent) ?? 0;
235
+ const lane = nodeLane.get(parent) ?? 0;
236
+ if (rank > trunkRank || rank === trunkRank && lane < trunkLane) {
237
+ trunkParent = parent;
238
+ trunkRank = rank;
239
+ trunkLane = lane;
240
+ }
241
+ }
242
+ const trunkParentLane = nodeLane.get(trunkParent) ?? 0;
243
+ const currentNodeLane = nodeLane.get(n) ?? 0;
244
+ if (currentNodeLane === trunkParentLane) continue;
245
+ nodeLane.set(n, trunkParentLane);
246
+ for (const parentEdge of parents) if (parentEdge.from === trunkParent) edgeLane.set(parentEdge.migrationHash, trunkParentLane);
247
+ const bfsDescendants = [n];
248
+ let descHead = 0;
249
+ while (descHead < bfsDescendants.length) {
250
+ const current = bfsDescendants[descHead++];
251
+ const children = outbound.get(current) ?? [];
252
+ for (const childEdge of children) {
253
+ const child = childEdge.to;
254
+ if (!componentSet.has(child)) continue;
255
+ if ((nodeLane.get(child) ?? 0) !== currentNodeLane) continue;
256
+ nodeLane.set(child, trunkParentLane);
257
+ const existingEdgeLane = edgeLane.get(childEdge.migrationHash);
258
+ if (existingEdgeLane !== void 0 && existingEdgeLane === currentNodeLane) edgeLane.set(childEdge.migrationHash, trunkParentLane);
259
+ bfsDescendants.push(child);
260
+ }
261
+ }
262
+ }
263
+ if (nextLane > totalLanes) totalLanes = nextLane;
264
+ }
265
+ return {
266
+ nodeLane,
267
+ nodeRank,
268
+ edgeLane,
269
+ numLanes: totalLanes
270
+ };
271
+ }
272
+ function computeDisplayOrder(nodes, nodeLane, nodeRank) {
273
+ const seen = /* @__PURE__ */ new Set();
274
+ const result = [];
275
+ let componentBuffer = [];
276
+ function flushComponent() {
277
+ componentBuffer.sort((a, b) => b.rank - a.rank || a.lane - b.lane);
278
+ for (const d of componentBuffer) result.push(d);
279
+ componentBuffer = [];
280
+ }
281
+ for (const n of nodes) {
282
+ if (n === null) {
283
+ flushComponent();
284
+ result.push(null);
285
+ continue;
286
+ }
287
+ if (seen.has(n)) continue;
288
+ seen.add(n);
289
+ componentBuffer.push({
290
+ hash: n,
291
+ lane: nodeLane.get(n) ?? 0,
292
+ rank: nodeRank.get(n) ?? 0
293
+ });
294
+ }
295
+ flushComponent();
296
+ return result;
297
+ }
298
+ /** Create an empty cell. */
299
+ function emptyCell() {
300
+ return { lines: [] };
301
+ }
302
+ function buildGrid(rowModel, opts = {}, highlight = {
303
+ mode: "flat",
304
+ onPath: /* @__PURE__ */ new Set()
305
+ }) {
306
+ const colsPerLane = opts.colsPerLane ?? 2;
307
+ const isFocus = highlight.mode === "focus";
308
+ const { nodeLane, nodeRank, edgeLane, numLanes } = buildLaneAssignment(rowModel.nodes, rowModel.edges);
309
+ const displayOrder = computeDisplayOrder(rowModel.nodes, nodeLane, nodeRank);
310
+ const displayIndex = /* @__PURE__ */ new Map();
311
+ let nodeIdx = 0;
312
+ for (const d of displayOrder) if (d !== null) displayIndex.set(d.hash, nodeIdx++);
313
+ const rollbackEdges = rowModel.edges.filter((e) => e.kind === "rollback" && e.from !== e.to);
314
+ const adjacentRollbacks = [];
315
+ const skippingRollbacks = [];
316
+ for (const e of rollbackEdges) {
317
+ const si = displayIndex.get(e.from);
318
+ const ti = displayIndex.get(e.to);
319
+ if (si === void 0 || ti === void 0) continue;
320
+ if (ti === si + 1) adjacentRollbacks.push(e);
321
+ else skippingRollbacks.push(e);
322
+ }
323
+ const targetGroups = /* @__PURE__ */ new Map();
324
+ for (const e of skippingRollbacks) {
325
+ const group = targetGroups.get(e.to);
326
+ if (group) group.push(e);
327
+ else targetGroups.set(e.to, [e]);
328
+ }
329
+ const sortedTargetKeys = [...targetGroups.keys()].sort((a, b) => {
330
+ const ta = displayIndex.get(a) ?? 0;
331
+ return (displayIndex.get(b) ?? 0) - ta;
332
+ });
333
+ const numTargetGroups = sortedTargetKeys.length;
334
+ const geomLaneOf = /* @__PURE__ */ new Map();
335
+ const outermostGroup = numLanes + numTargetGroups - 1;
336
+ sortedTargetKeys.forEach((targetHash, i) => {
337
+ const groupGeomLane = outermostGroup - i;
338
+ for (const e of targetGroups.get(targetHash)) geomLaneOf.set(e.migrationHash, groupGeomLane);
339
+ });
340
+ const totalDisplayNodes = displayOrder.filter((d) => d !== null).length;
341
+ const planeLaneOf = /* @__PURE__ */ new Map();
342
+ for (const e of skippingRollbacks) {
343
+ const si = displayIndex.get(e.from) ?? 0;
344
+ planeLaneOf.set(e.migrationHash, totalDisplayNodes - si);
345
+ }
346
+ const PALETTE_SIZE = 6;
347
+ const GREEN_PALETTE_IDX = 5;
348
+ const arcSourceIndex = /* @__PURE__ */ new Map();
349
+ const arcTargetIndex = /* @__PURE__ */ new Map();
350
+ for (const e of skippingRollbacks) {
351
+ arcSourceIndex.set(e.migrationHash, displayIndex.get(e.from) ?? 0);
352
+ arcTargetIndex.set(e.migrationHash, displayIndex.get(e.to) ?? 0);
353
+ }
354
+ const arcsByTarget = /* @__PURE__ */ new Map();
355
+ const arcsBySource = /* @__PURE__ */ new Map();
356
+ for (const e of skippingRollbacks) {
357
+ const tb = arcsByTarget.get(e.to);
358
+ if (tb) tb.push(e);
359
+ else arcsByTarget.set(e.to, [e]);
360
+ const sb = arcsBySource.get(e.from);
361
+ if (sb) sb.push(e);
362
+ else arcsBySource.set(e.from, [e]);
363
+ }
364
+ const colourLaneOf = /* @__PURE__ */ new Map();
365
+ const activeArcColours = /* @__PURE__ */ new Map();
366
+ const activeFwdLaneColours = /* @__PURE__ */ new Set();
367
+ for (let i = displayOrder.length - 1; i >= 0; i--) {
368
+ const nd = displayOrder[i];
369
+ if (nd === null || nd === void 0) continue;
370
+ const { hash: nodeHash } = nd;
371
+ const nodeFwdLane = nodeLane.get(nodeHash) ?? 0;
372
+ activeFwdLaneColours.add(nodeFwdLane % PALETTE_SIZE);
373
+ const sortedIncoming = [...arcsByTarget.get(nodeHash) ?? []].sort((a, b) => a.dirName.localeCompare(b.dirName));
374
+ for (const arc of sortedIncoming) {
375
+ const originLaneColour = (nodeLane.get(arc.from) ?? 0) % PALETTE_SIZE;
376
+ const occupied = new Set(activeFwdLaneColours);
377
+ for (const c of activeArcColours.values()) occupied.add(c);
378
+ occupied.add(GREEN_PALETTE_IDX);
379
+ occupied.add(originLaneColour);
380
+ let chosen = -1;
381
+ for (let ci = 0; ci < PALETTE_SIZE; ci++) if (!occupied.has(ci)) {
382
+ chosen = ci;
383
+ break;
384
+ }
385
+ if (chosen === -1) {
386
+ for (let ci = 0; ci < PALETTE_SIZE; ci++) if (ci !== GREEN_PALETTE_IDX) {
387
+ chosen = ci;
388
+ break;
389
+ }
390
+ }
391
+ colourLaneOf.set(arc.migrationHash, chosen === -1 ? 0 : chosen);
392
+ activeArcColours.set(arc.migrationHash, chosen === -1 ? 0 : chosen);
393
+ }
394
+ for (const arc of arcsBySource.get(nodeHash) ?? []) activeArcColours.delete(arc.migrationHash);
395
+ }
396
+ const routedBackArcs = skippingRollbacks.map((e) => ({
397
+ edge: e,
398
+ sourceIndex: displayIndex.get(e.from) ?? 0,
399
+ targetIndex: displayIndex.get(e.to) ?? 0,
400
+ geomLane: geomLaneOf.get(e.migrationHash) ?? numLanes,
401
+ colourLane: colourLaneOf.get(e.migrationHash) ?? 0,
402
+ planeLane: planeLaneOf.get(e.migrationHash) ?? numLanes
403
+ }));
404
+ const backArcsBySource = /* @__PURE__ */ new Map();
405
+ const backArcsByTarget = /* @__PURE__ */ new Map();
406
+ for (const arc of routedBackArcs) {
407
+ const sb = backArcsBySource.get(arc.edge.from);
408
+ if (sb) sb.push(arc);
409
+ else backArcsBySource.set(arc.edge.from, [arc]);
410
+ const tb = backArcsByTarget.get(arc.edge.to);
411
+ if (tb) tb.push(arc);
412
+ else backArcsByTarget.set(arc.edge.to, [arc]);
413
+ }
414
+ const adjacentBySource = /* @__PURE__ */ new Map();
415
+ const adjacentByTarget = /* @__PURE__ */ new Map();
416
+ for (const e of adjacentRollbacks) {
417
+ const b = adjacentBySource.get(e.from);
418
+ if (b) b.push(e);
419
+ else adjacentBySource.set(e.from, [e]);
420
+ const t = adjacentByTarget.get(e.to);
421
+ if (t) t.push(e);
422
+ else adjacentByTarget.set(e.to, [e]);
423
+ }
424
+ for (const list of adjacentBySource.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
425
+ const totalCols = (numLanes + numTargetGroups) * colsPerLane;
426
+ const fwdEdges = rowModel.edges.filter((e) => e.kind === "forward" && e.from !== e.to);
427
+ const selfEdges = rowModel.edges.filter((e) => e.kind === "self");
428
+ const outboundFwd = /* @__PURE__ */ new Map();
429
+ const inboundFwd = /* @__PURE__ */ new Map();
430
+ for (const e of fwdEdges) {
431
+ const ob = outboundFwd.get(e.from);
432
+ if (ob) ob.push(e);
433
+ else outboundFwd.set(e.from, [e]);
434
+ const ib = inboundFwd.get(e.to);
435
+ if (ib) ib.push(e);
436
+ else inboundFwd.set(e.to, [e]);
437
+ }
438
+ for (const list of outboundFwd.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
439
+ for (const list of inboundFwd.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
440
+ const selfEdgesByNode = /* @__PURE__ */ new Map();
441
+ for (const e of selfEdges) {
442
+ const bucket = selfEdgesByNode.get(e.from);
443
+ if (bucket) bucket.push(e);
444
+ else selfEdgesByNode.set(e.from, [e]);
445
+ }
446
+ for (const list of selfEdgesByNode.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));
447
+ function roleOf(migrationHash) {
448
+ if (!isFocus) return void 0;
449
+ return highlight.onPath.has(migrationHash) ? "on-path" : "off-path";
450
+ }
451
+ const onPathNodes = /* @__PURE__ */ new Set();
452
+ if (isFocus) {
453
+ for (const e of [
454
+ ...fwdEdges,
455
+ ...selfEdges,
456
+ ...rollbackEdges
457
+ ]) if (highlight.onPath.has(e.migrationHash)) {
458
+ onPathNodes.add(e.from);
459
+ onPathNodes.add(e.to);
460
+ }
461
+ }
462
+ function nodeRoleOf(hash) {
463
+ if (!isFocus) return void 0;
464
+ return onPathNodes.has(hash) ? "on-path" : "off-path";
465
+ }
466
+ function planeOf(lane, role) {
467
+ if (!isFocus) return lane;
468
+ return role === "on-path" ? 0 : lane + 1;
469
+ }
470
+ function lineRefFor(edge, lane) {
471
+ return {
472
+ migrationHash: edge.migrationHash,
473
+ dirName: edge.dirName,
474
+ lane,
475
+ role: roleOf(edge.migrationHash)
476
+ };
477
+ }
478
+ /** Synthetic LineRef for a lane carrying a representative edge's role (pass-through). */
479
+ function passLineRef(lane, dirName, migHash) {
480
+ return {
481
+ migrationHash: migHash,
482
+ dirName,
483
+ lane,
484
+ role: roleOf(migHash)
485
+ };
486
+ }
487
+ function vertCell(line) {
488
+ return { lines: [{
489
+ line,
490
+ directions: /* @__PURE__ */ new Set(["up", "down"]),
491
+ plane: planeOf(line.lane, line.role)
492
+ }] };
493
+ }
494
+ function dirCell(line, dirs) {
495
+ return { lines: [{
496
+ line,
497
+ directions: dirs,
498
+ plane: planeOf(line.lane, line.role)
499
+ }] };
500
+ }
501
+ function nodeCell(nodeRef) {
502
+ return {
503
+ node: nodeRef,
504
+ lines: []
505
+ };
506
+ }
507
+ const laneCurrentEdge = /* @__PURE__ */ new Map();
508
+ function getRepLine(lane) {
509
+ const e = laneCurrentEdge.get(lane);
510
+ if (e) return lineRefFor(e, lane);
511
+ return passLineRef(lane, `lane${lane}`, `lane${lane}`);
512
+ }
513
+ const activeLanes = /* @__PURE__ */ new Set();
514
+ const grid = [];
515
+ function makeRow() {
516
+ return Array.from({ length: totalCols }, () => emptyCell());
517
+ }
518
+ function placeVerticals(row, skip) {
519
+ for (const lane of activeLanes) {
520
+ if (skip.has(lane)) continue;
521
+ const railCol = lane * colsPerLane;
522
+ const cell = row[railCol];
523
+ if (cell !== void 0 && cell.lines.length === 0 && !cell.node) row[railCol] = vertCell(getRepLine(lane));
524
+ }
525
+ }
526
+ const activeBackArcs = /* @__PURE__ */ new Set();
527
+ function backArcLine(arc) {
528
+ return {
529
+ migrationHash: arc.edge.migrationHash,
530
+ dirName: arc.edge.dirName,
531
+ lane: arc.colourLane,
532
+ role: roleOf(arc.edge.migrationHash)
533
+ };
534
+ }
535
+ function backArcPlane(arc) {
536
+ const role = roleOf(arc.edge.migrationHash);
537
+ if (!isFocus) return arc.planeLane;
538
+ return role === "on-path" ? 0 : arc.planeLane + 1;
539
+ }
540
+ function composeLine(row, col, line, dirs, plane, extra) {
541
+ const existing = row[col];
542
+ const cellLine = {
543
+ line,
544
+ directions: dirs,
545
+ plane,
546
+ ...extra?.landingArrow ? { landingArrow: true } : {}
547
+ };
548
+ if (existing && (existing.lines.length > 0 || existing.node)) row[col] = {
549
+ ...existing,
550
+ lines: [...existing.lines, cellLine]
551
+ };
552
+ else row[col] = { lines: [cellLine] };
553
+ }
554
+ function placeBackVerticals(row) {
555
+ for (const arc of activeBackArcs) composeLine(row, arc.geomLane * colsPerLane, backArcLine(arc), /* @__PURE__ */ new Set(["up", "down"]), backArcPlane(arc));
556
+ placeAdjacentOverlays(row);
557
+ }
558
+ const activeAdjacent = /* @__PURE__ */ new Set();
559
+ function placeAdjacentOverlays(row) {
560
+ for (const adj of activeAdjacent) {
561
+ const railCol = adj.lane * colsPerLane;
562
+ if (row[railCol]?.node) continue;
563
+ const line = lineRefFor(adj.edge, adj.lane);
564
+ composeLine(row, railCol, line, /* @__PURE__ */ new Set(["up", "down"]), planeOf(adj.lane, line.role));
565
+ }
566
+ }
567
+ function emitBackArcTee(row, nodeLaneNum, arc) {
568
+ const nodeRail = nodeLaneNum * colsPerLane;
569
+ const geomRail = arc.geomLane * colsPerLane;
570
+ const line = backArcLine(arc);
571
+ const plane = backArcPlane(arc);
572
+ for (let col = nodeRail + 1; col < geomRail; col++) composeLine(row, col, line, /* @__PURE__ */ new Set(["left", "right"]), plane);
573
+ composeLine(row, geomRail, line, /* @__PURE__ */ new Set(["down", "left"]), plane);
574
+ }
575
+ function emitBackArcLanding(row, nodeLaneNum, arc) {
576
+ const nodeRail = nodeLaneNum * colsPerLane;
577
+ const geomRail = arc.geomLane * colsPerLane;
578
+ const line = backArcLine(arc);
579
+ const plane = backArcPlane(arc);
580
+ composeLine(row, nodeRail + 1, line, /* @__PURE__ */ new Set(["left", "right"]), plane, { landingArrow: true });
581
+ for (let col = nodeRail + 2; col < geomRail; col++) composeLine(row, col, line, /* @__PURE__ */ new Set(["left", "right"]), plane);
582
+ composeLine(row, geomRail, line, /* @__PURE__ */ new Set(["up", "left"]), plane);
583
+ }
584
+ function emitConnectorRow(trunkLane, branchEntries, connectorType, trunkEdge) {
585
+ const row = makeRow();
586
+ const sorted = [...branchEntries].sort((a, b) => a.lane - b.lane);
587
+ if (sorted.length === 0) return row;
588
+ const branchByLane = /* @__PURE__ */ new Map();
589
+ for (const b of sorted) branchByLane.set(b.lane, b.edge);
590
+ let continuousLane = trunkLane;
591
+ if (isFocus) if (trunkEdge && highlight.onPath.has(trunkEdge.migrationHash)) continuousLane = trunkLane;
592
+ else {
593
+ const onPathBranch = sorted.find((b) => highlight.onPath.has(b.edge.migrationHash));
594
+ if (onPathBranch) continuousLane = onPathBranch.lane;
595
+ }
596
+ const trunkRailCol = trunkLane * colsPerLane;
597
+ const continuousRailCol = continuousLane * colsPerLane;
598
+ function addLine(col, line, dirs) {
599
+ const existing = row[col];
600
+ const cellLine = {
601
+ line,
602
+ directions: dirs,
603
+ plane: planeOf(line.lane, line.role)
604
+ };
605
+ row[col] = existing && existing.lines.length > 0 ? {
606
+ ...existing,
607
+ lines: [...existing.lines, cellLine]
608
+ } : { lines: [cellLine] };
609
+ }
610
+ const cornerLeftDown = connectorType === "merge" ? /* @__PURE__ */ new Set(["left", "down"]) : /* @__PURE__ */ new Set(["left", "up"]);
611
+ for (let i = 0; i < sorted.length; i++) {
612
+ const b = sorted[i];
613
+ if (b.lane === continuousLane) continue;
614
+ const branchLine = lineRefFor(b.edge, b.lane);
615
+ const railCol = b.lane * colsPerLane;
616
+ addLine(railCol, branchLine, cornerLeftDown);
617
+ const leftBound = i === 0 ? trunkRailCol + 1 : sorted[i - 1].lane * colsPerLane + 1;
618
+ for (let col = leftBound; col < railCol; col++) addLine(col, branchLine, /* @__PURE__ */ new Set(["left", "right"]));
619
+ }
620
+ const continuousLine = continuousLane === trunkLane ? trunkEdge ? lineRefFor(trunkEdge, trunkLane) : getRepLine(trunkLane) : lineRefFor(branchByLane.get(continuousLane), continuousLane);
621
+ if (continuousLane === trunkLane) addLine(trunkRailCol, continuousLine, /* @__PURE__ */ new Set(["up", "down"]));
622
+ else {
623
+ addLine(trunkRailCol, continuousLine, connectorType === "merge" ? /* @__PURE__ */ new Set(["up", "right"]) : /* @__PURE__ */ new Set(["down", "right"]));
624
+ for (let col = trunkRailCol + 1; col < continuousRailCol; col++) addLine(col, continuousLine, /* @__PURE__ */ new Set(["left", "right"]));
625
+ addLine(continuousRailCol, continuousLine, cornerLeftDown);
626
+ }
627
+ placeVerticals(row, /* @__PURE__ */ new Set([trunkLane, ...sorted.map((b) => b.lane)]));
628
+ placeBackVerticals(row);
629
+ return row;
630
+ }
631
+ for (const nodeDisplay of displayOrder) {
632
+ if (nodeDisplay === null) {
633
+ const sepRow = makeRow();
634
+ sepRow[0] = {
635
+ lines: [],
636
+ separator: true
637
+ };
638
+ grid.push(sepRow);
639
+ continue;
640
+ }
641
+ const { hash: nodeHash } = nodeDisplay;
642
+ const nodeLaneNum = nodeLane.get(nodeHash) ?? 0;
643
+ activeLanes.add(nodeLaneNum);
644
+ const outEdges = outboundFwd.get(nodeHash) ?? [];
645
+ if (outEdges.length > 1) {
646
+ const trunkEdgeForFork = outEdges[0];
647
+ const trunkChildLane = edgeLane.get(trunkEdgeForFork.migrationHash) ?? nodeLane.get(trunkEdgeForFork.to) ?? nodeLaneNum;
648
+ const branchEntries = outEdges.slice(1).map((e) => ({
649
+ lane: edgeLane.get(e.migrationHash) ?? nodeLane.get(e.to) ?? 0,
650
+ edge: e
651
+ })).filter((b) => b.lane !== trunkChildLane && activeLanes.has(b.lane));
652
+ if (branchEntries.length > 0) {
653
+ const trunkEdge = outEdges[0];
654
+ const connRow = emitConnectorRow(nodeLaneNum, branchEntries, "fork", trunkEdge);
655
+ grid.push(connRow);
656
+ assertSingleOwner(connRow, isFocus);
657
+ for (const b of branchEntries) activeLanes.delete(b.lane);
658
+ }
659
+ }
660
+ const selfMigrations = selfEdgesByNode.get(nodeHash) ?? [];
661
+ for (const selfEdge of selfMigrations) {
662
+ const row = makeRow();
663
+ const railCol = nodeLaneNum * colsPerLane;
664
+ const connCol = nodeLaneNum * colsPerLane + 1;
665
+ const line = lineRefFor(selfEdge, nodeLaneNum);
666
+ row[railCol] = vertCell(line);
667
+ row[connCol] = { lines: [{
668
+ line,
669
+ directions: /* @__PURE__ */ new Set(),
670
+ plane: planeOf(nodeLaneNum, line.role),
671
+ selfLoop: true
672
+ }] };
673
+ placeVerticals(row, /* @__PURE__ */ new Set([nodeLaneNum]));
674
+ placeBackVerticals(row);
675
+ grid.push(row);
676
+ }
677
+ {
678
+ const row = makeRow();
679
+ const railCol = nodeLaneNum * colsPerLane;
680
+ row[railCol] = nodeCell({
681
+ contractHash: nodeHash,
682
+ isEmpty: nodeHash === EMPTY_CONTRACT_HASH,
683
+ lane: nodeLaneNum,
684
+ role: nodeRoleOf(nodeHash)
685
+ });
686
+ placeVerticals(row, /* @__PURE__ */ new Set([nodeLaneNum]));
687
+ const landingArcs = backArcsByTarget.get(nodeHash) ?? [];
688
+ for (const arc of landingArcs) activeBackArcs.delete(arc);
689
+ for (const adj of [...activeAdjacent]) if (adj.edge.to === nodeHash) activeAdjacent.delete(adj);
690
+ placeBackVerticals(row);
691
+ for (const arc of landingArcs) emitBackArcLanding(row, nodeLaneNum, arc);
692
+ const teeArcs = backArcsBySource.get(nodeHash) ?? [];
693
+ for (const arc of teeArcs) emitBackArcTee(row, nodeLaneNum, arc);
694
+ grid.push(row);
695
+ for (const arc of teeArcs) activeBackArcs.add(arc);
696
+ for (const adj of adjacentBySource.get(nodeHash) ?? []) activeAdjacent.add({
697
+ lane: nodeLaneNum,
698
+ edge: adj
699
+ });
700
+ }
701
+ function edgeLaneFor(edge) {
702
+ const override = edgeLane.get(edge.migrationHash);
703
+ if (override !== void 0) return override;
704
+ return Math.max(nodeLane.get(edge.from) ?? 0, nodeLane.get(edge.to) ?? 0);
705
+ }
706
+ const inEdges = inboundFwd.get(nodeHash) ?? [];
707
+ inEdges.sort((a, b) => {
708
+ const aLane = edgeLaneFor(a);
709
+ const bLane = edgeLaneFor(b);
710
+ if (aLane !== bLane) return aLane - bLane;
711
+ return a.dirName.localeCompare(b.dirName);
712
+ });
713
+ for (const edge of inEdges) laneCurrentEdge.set(edgeLaneFor(edge), edge);
714
+ {
715
+ const teeArcs = backArcsBySource.get(nodeHash) ?? [];
716
+ for (const arc of teeArcs) {
717
+ const row = makeRow();
718
+ const railCol = arc.geomLane * colsPerLane;
719
+ const connCol = railCol + 1;
720
+ const line = backArcLine(arc);
721
+ const plane = backArcPlane(arc);
722
+ composeLine(row, railCol, line, /* @__PURE__ */ new Set(["up", "down"]), plane);
723
+ composeLine(row, connCol, line, /* @__PURE__ */ new Set(["down"]), plane);
724
+ placeVerticals(row, /* @__PURE__ */ new Set());
725
+ placeBackVerticals(row);
726
+ grid.push(row);
727
+ }
728
+ }
729
+ if (inEdges.length > 1) {
730
+ const branchEntries = inEdges.slice(1).map((e) => ({
731
+ lane: edgeLaneFor(e),
732
+ edge: e
733
+ }));
734
+ const trunkEdge = inEdges[0];
735
+ const connRow = emitConnectorRow(nodeLaneNum, branchEntries, "merge", trunkEdge);
736
+ grid.push(connRow);
737
+ assertSingleOwner(connRow, isFocus);
738
+ for (const b of branchEntries) activeLanes.add(b.lane);
739
+ }
740
+ for (const edge of inEdges) {
741
+ const eLane = edgeLaneFor(edge);
742
+ const row = makeRow();
743
+ const railCol = eLane * colsPerLane;
744
+ const connCol = eLane * colsPerLane + 1;
745
+ const line = lineRefFor(edge, eLane);
746
+ row[railCol] = vertCell(line);
747
+ row[connCol] = dirCell(line, /* @__PURE__ */ new Set(["up"]));
748
+ placeVerticals(row, /* @__PURE__ */ new Set([eLane]));
749
+ placeBackVerticals(row);
750
+ grid.push(row);
751
+ }
752
+ {
753
+ const adjacents = adjacentBySource.get(nodeHash) ?? [];
754
+ for (const adj of adjacents) {
755
+ const row = makeRow();
756
+ const connCol = nodeLaneNum * colsPerLane + 1;
757
+ const line = lineRefFor(adj, nodeLaneNum);
758
+ const plane = planeOf(nodeLaneNum, line.role);
759
+ composeLine(row, connCol, line, /* @__PURE__ */ new Set(["down"]), plane);
760
+ placeVerticals(row, /* @__PURE__ */ new Set());
761
+ placeBackVerticals(row);
762
+ grid.push(row);
763
+ }
764
+ }
765
+ if (inEdges.length === 0) activeLanes.delete(nodeLaneNum);
766
+ }
767
+ return grid;
768
+ }
769
+ function assertSingleOwner(row, isFocus) {
770
+ for (const cell of row) {
771
+ if (cell.lines.length <= 1) continue;
772
+ let topPlane = Number.POSITIVE_INFINITY;
773
+ for (const cl of cell.lines) if (cl.plane < topPlane) topPlane = cl.plane;
774
+ const top = cell.lines.filter((cl) => cl.plane === topPlane);
775
+ if (top.length > 1) {
776
+ if (isFocus) {
777
+ if (new Set(top.map((cl) => cl.line.role)).size > 1) throw new InternalError("migration-graph layout: single-owner invariant violated — two differently-roled lines share the top plane in one cell");
778
+ }
779
+ }
780
+ }
781
+ }
782
+ function compareDirNameDesc(a, b) {
783
+ return b.dirName.localeCompare(a.dirName);
784
+ }
785
+ function bumpDegree(map, key) {
786
+ map.set(key, (map.get(key) ?? 0) + 1);
787
+ }
788
+ function compareNodesRootFirst(a, b) {
789
+ if (a === "empty") return -1;
790
+ if (b === "empty") return 1;
791
+ return a.localeCompare(b);
792
+ }
793
+ /**
794
+ * Shortest-path distance of each node from the forward roots, over the given
795
+ * candidate edges. Roots are the in-degree-0 nodes (baseline first, then lex);
796
+ * a rooted component therefore distances every node by how many forward steps
797
+ * it sits from a root. A component with no root (a pure cycle) is seeded from
798
+ * its single lexically-smallest node so the cycle still gets a stable layering.
799
+ *
800
+ * Crucially this is *shortest* path, not longest: a backward (rollback) edge
801
+ * `deep → shallow` never offers a shorter route to the already-shallower
802
+ * target, so it is inert here. Distances are thus stable whether or not the
803
+ * rollbacks are still in the candidate set — which is what lets the peel below
804
+ * tell a genuine back-edge (target strictly shallower than source) apart from a
805
+ * forward edge that merely happens to share the back-edge's cycle.
806
+ */
807
+ function forwardDistances(nodes, candidates) {
808
+ const inDegree = /* @__PURE__ */ new Map();
809
+ for (const node of nodes) inDegree.set(node, 0);
810
+ for (const edge of candidates) bumpDegree(inDegree, edge.to);
811
+ const roots = [...nodes].filter((node) => (inDegree.get(node) ?? 0) === 0);
812
+ roots.sort(compareNodesRootFirst);
813
+ const seeds = roots.length > 0 ? roots : [...nodes].sort(compareNodesRootFirst).slice(0, 1);
814
+ const dist = /* @__PURE__ */ new Map();
815
+ for (const seed of seeds) dist.set(seed, 0);
816
+ const maxPasses = nodes.size;
817
+ for (let pass = 0; pass < maxPasses; pass++) {
818
+ let changed = false;
819
+ for (const edge of candidates) {
820
+ const base = dist.get(edge.from);
821
+ if (base === void 0) continue;
822
+ const next = base + 1;
823
+ if (next < (dist.get(edge.to) ?? Number.POSITIVE_INFINITY)) {
824
+ dist.set(edge.to, next);
825
+ changed = true;
826
+ }
827
+ }
828
+ if (!changed) break;
829
+ }
830
+ for (const node of nodes) if (!dist.has(node)) dist.set(node, 0);
831
+ return dist;
832
+ }
833
+ function canReachForward(start, goal, candidates) {
834
+ if (start === goal) return true;
835
+ const outgoing = /* @__PURE__ */ new Map();
836
+ for (const edge of candidates) {
837
+ const bucket = outgoing.get(edge.from);
838
+ if (bucket) bucket.push(edge.to);
839
+ else outgoing.set(edge.from, [edge.to]);
840
+ }
841
+ const visited = /* @__PURE__ */ new Set([start]);
842
+ const queue = [start];
843
+ while (queue.length > 0) {
844
+ const node = queue.shift();
845
+ if (node === void 0) continue;
846
+ for (const next of outgoing.get(node) ?? []) {
847
+ if (next === goal) return true;
848
+ if (!visited.has(next)) {
849
+ visited.add(next);
850
+ queue.push(next);
851
+ }
852
+ }
853
+ }
854
+ return false;
855
+ }
856
+ /**
857
+ * Demote node-skipping rollbacks left forward by the DFS. An edge `from → to`
858
+ * is a rollback exactly when both hold:
859
+ * 1. `to` is a forward-ancestor of `from` — `to` can still reach `from` over
860
+ * the other forward edges, so the edge closes a cycle; and
861
+ * 2. `to` is strictly shallower than `from` (smaller forward distance) — the
862
+ * edge points back toward the root rather than advancing history.
863
+ *
864
+ * Condition 2 is the discriminator: in a cycle created by a rollback every edge
865
+ * satisfies condition 1, but only the rollback itself runs deep → shallow. The
866
+ * forward chain edges run shallow → deep and are never peeled, however many
867
+ * rollbacks converge on the same target. Tight back-edges whose source and
868
+ * target sit at the same distance (mutual two-node cycles) are already resolved
869
+ * by the DFS immediate-parent rule, so they never reach this pass. One edge is
870
+ * peeled per iteration (dirName-descending tie-break) and distances/reachability
871
+ * are recomputed, making the outcome independent of edge input order.
872
+ */
873
+ function peelNodeSkippingRollbacks(nodes, kindByMigrationHash, nonSelf) {
874
+ let candidates = nonSelf.filter((edge) => kindByMigrationHash.get(edge.hash) === "forward");
875
+ while (candidates.length > 0) {
876
+ const dist = forwardDistances(nodes, candidates);
877
+ const backEdges = candidates.filter((edge) => {
878
+ if ((dist.get(edge.to) ?? 0) >= (dist.get(edge.from) ?? 0)) return false;
879
+ const without = candidates.filter((candidate) => candidate !== edge);
880
+ return canReachForward(edge.to, edge.from, without);
881
+ });
882
+ if (backEdges.length === 0) break;
883
+ backEdges.sort(compareDirNameDesc);
884
+ const rollback = backEdges[0];
885
+ if (rollback === void 0) break;
886
+ kindByMigrationHash.set(rollback.hash, "rollback");
887
+ candidates = candidates.filter((edge) => edge !== rollback);
888
+ }
889
+ }
890
+ /**
891
+ * DFS with dirName-descending traversal. A GRAY target is a rollback only when it
892
+ * is the immediate DFS parent of the source — cross-links to other GRAY nodes
893
+ * stay forward. A follow-up peel pass demotes node-skipping rollbacks (target is
894
+ * a forward-ancestor of the source and sits strictly shallower than it).
895
+ */
896
+ function classifyNormalizedEdges(edges) {
897
+ const nodes = /* @__PURE__ */ new Set();
898
+ const kindByMigrationHash = /* @__PURE__ */ new Map();
899
+ const outgoingByFrom = /* @__PURE__ */ new Map();
900
+ const nonSelf = [];
901
+ for (const edge of edges) {
902
+ nodes.add(edge.from);
903
+ nodes.add(edge.to);
904
+ if (edge.from === edge.to) {
905
+ kindByMigrationHash.set(edge.hash, "self");
906
+ continue;
907
+ }
908
+ nonSelf.push(edge);
909
+ const bucket = outgoingByFrom.get(edge.from);
910
+ if (bucket) bucket.push(edge);
911
+ else outgoingByFrom.set(edge.from, [edge]);
912
+ }
913
+ for (const bucket of outgoingByFrom.values()) bucket.sort(compareDirNameDesc);
914
+ const nonSelfInDegree = /* @__PURE__ */ new Map();
915
+ for (const node of nodes) nonSelfInDegree.set(node, 0);
916
+ for (const bucket of outgoingByFrom.values()) for (const edge of bucket) bumpDegree(nonSelfInDegree, edge.to);
917
+ const dfsRoots = [];
918
+ for (const node of nodes) if ((nonSelfInDegree.get(node) ?? 0) === 0) dfsRoots.push(node);
919
+ dfsRoots.sort((a, b) => {
920
+ if (a === "empty") return -1;
921
+ if (b === "empty") return 1;
922
+ return a.localeCompare(b);
923
+ });
924
+ if (dfsRoots.length === 0) dfsRoots.push(...[...nodes].sort((a, b) => a.localeCompare(b)));
925
+ const WHITE = 0;
926
+ const GRAY = 1;
927
+ const BLACK = 2;
928
+ const color = /* @__PURE__ */ new Map();
929
+ const dfsParent = /* @__PURE__ */ new Map();
930
+ for (const node of nodes) color.set(node, WHITE);
931
+ const stack = [];
932
+ function isImmediateDfsParent(ancestor, node) {
933
+ return dfsParent.get(node) === ancestor;
934
+ }
935
+ function pushFrame(node, parent) {
936
+ color.set(node, GRAY);
937
+ dfsParent.set(node, parent);
938
+ stack.push({
939
+ node,
940
+ outgoing: outgoingByFrom.get(node) ?? [],
941
+ index: 0
942
+ });
943
+ }
944
+ function runDfsFrom(root) {
945
+ if (color.get(root) !== WHITE) return;
946
+ pushFrame(root, void 0);
947
+ while (stack.length > 0) {
948
+ const frame = stack[stack.length - 1];
949
+ if (frame === void 0) break;
950
+ if (frame.index >= frame.outgoing.length) {
951
+ color.set(frame.node, BLACK);
952
+ stack.pop();
953
+ continue;
954
+ }
955
+ const edge = frame.outgoing[frame.index];
956
+ frame.index += 1;
957
+ if (edge === void 0) continue;
958
+ const v = edge.to;
959
+ const vColor = color.get(v);
960
+ if (vColor === GRAY && isImmediateDfsParent(v, frame.node)) kindByMigrationHash.set(edge.hash, "rollback");
961
+ else {
962
+ kindByMigrationHash.set(edge.hash, "forward");
963
+ if (vColor === WHITE) pushFrame(v, frame.node);
964
+ }
965
+ }
966
+ }
967
+ for (const root of dfsRoots) runDfsFrom(root);
968
+ const remainingWhite = [...nodes].filter((node) => color.get(node) === WHITE);
969
+ remainingWhite.sort((a, b) => a.localeCompare(b));
970
+ for (const root of remainingWhite) runDfsFrom(root);
971
+ peelNodeSkippingRollbacks(nodes, kindByMigrationHash, nonSelf);
972
+ const forwardInDegree = /* @__PURE__ */ new Map();
973
+ const forwardOutDegree = /* @__PURE__ */ new Map();
974
+ for (const edge of edges) {
975
+ if (kindByMigrationHash.get(edge.hash) !== "forward") continue;
976
+ bumpDegree(forwardOutDegree, edge.from);
977
+ bumpDegree(forwardInDegree, edge.to);
978
+ }
979
+ return {
980
+ kindByMigrationHash,
981
+ forwardInDegree,
982
+ forwardOutDegree
983
+ };
984
+ }
985
+ /**
986
+ * Classify forward/rollback/self for a `MigrationGraph` edge set (Tier-3).
987
+ */
988
+ function classifyMigrationGraphTopology(graph) {
989
+ const normalized = [];
990
+ for (const edges of graph.forwardChain.values()) for (const edge of edges) normalized.push({
991
+ hash: edge.migrationHash,
992
+ from: edge.from,
993
+ to: edge.to,
994
+ dirName: edge.dirName
995
+ });
996
+ return classifyNormalizedEdges(normalized);
997
+ }
998
+ /**
999
+ * Return the weakly-connected components of `graph` as an array of node sets,
1000
+ * ordered so the component containing EMPTY_CONTRACT_HASH comes first (if
1001
+ * present), with remaining components sorted by their lex-smallest node hash.
1002
+ */
1003
+ function weaklyConnectedComponents(graph) {
1004
+ const visited = /* @__PURE__ */ new Set();
1005
+ const adjacency = /* @__PURE__ */ new Map();
1006
+ function addAdjacent(a, b) {
1007
+ const aList = adjacency.get(a);
1008
+ if (aList) aList.push(b);
1009
+ else adjacency.set(a, [b]);
1010
+ const bList = adjacency.get(b);
1011
+ if (bList) bList.push(a);
1012
+ else adjacency.set(b, [a]);
1013
+ }
1014
+ for (const edges of graph.forwardChain.values()) for (const edge of edges) if (edge.from !== edge.to) addAdjacent(edge.from, edge.to);
1015
+ for (const node of graph.nodes) if (!adjacency.has(node)) adjacency.set(node, []);
1016
+ const components = [];
1017
+ function bfsComponent(start) {
1018
+ const component = /* @__PURE__ */ new Set();
1019
+ const queue = [start];
1020
+ while (queue.length > 0) {
1021
+ const node = queue.shift();
1022
+ if (node === void 0 || visited.has(node)) continue;
1023
+ visited.add(node);
1024
+ component.add(node);
1025
+ for (const neighbor of adjacency.get(node) ?? []) if (!visited.has(neighbor)) queue.push(neighbor);
1026
+ }
1027
+ return component;
1028
+ }
1029
+ const allNodes = [...graph.nodes].sort((a, b) => {
1030
+ if (a === "empty") return -1;
1031
+ if (b === "empty") return 1;
1032
+ return a.localeCompare(b);
1033
+ });
1034
+ for (const node of allNodes) if (!visited.has(node)) components.push(bfsComponent(node));
1035
+ components.sort((a, b) => {
1036
+ const aHasEmpty = a.has(EMPTY_CONTRACT_HASH);
1037
+ const bHasEmpty = b.has(EMPTY_CONTRACT_HASH);
1038
+ if (aHasEmpty && !bHasEmpty) return -1;
1039
+ if (!aHasEmpty && bHasEmpty) return 1;
1040
+ const aMin = [...a].sort((x, y) => x.localeCompare(y))[0] ?? "";
1041
+ const bMin = [...b].sort((x, y) => x.localeCompare(y))[0] ?? "";
1042
+ return aMin.localeCompare(bMin);
1043
+ });
1044
+ return components;
1045
+ }
1046
+ function forwardRootsInComponent(componentNodes, topology) {
1047
+ const roots = [];
1048
+ for (const node of componentNodes) if ((topology.forwardInDegree.get(node) ?? 0) === 0) roots.push(node);
1049
+ roots.sort((a, b) => {
1050
+ if (a === "empty") return -1;
1051
+ if (b === "empty") return 1;
1052
+ return a.localeCompare(b);
1053
+ });
1054
+ if (roots.length > 0) return roots;
1055
+ return [...componentNodes].sort((a, b) => {
1056
+ if (a === "empty") return -1;
1057
+ if (b === "empty") return 1;
1058
+ return a.localeCompare(b);
1059
+ });
1060
+ }
1061
+ function compareNodesTipsFirst(a, b, rank) {
1062
+ const rankA = rank.get(a) ?? 0;
1063
+ const rankB = rank.get(b) ?? 0;
1064
+ if (rankA !== rankB) return rankB - rankA;
1065
+ if (a === "empty") return 1;
1066
+ if (b === "empty") return -1;
1067
+ return a.localeCompare(b);
1068
+ }
1069
+ /**
1070
+ * Layer nodes by longest forward-path rank from forward roots within the
1071
+ * component. Rank 0 is the root (bottom row); the maximum rank is the tip
1072
+ * (top row). Emits rank-descending with lex-ascending tie-break among siblings
1073
+ * at the same rank — stable across edge-insertion order and correct under
1074
+ * diamonds, cross-links, and rollbacks.
1075
+ */
1076
+ function maxRank(rank) {
1077
+ let max = 0;
1078
+ for (const value of rank.values()) if (value > max) max = value;
1079
+ return max;
1080
+ }
1081
+ function layerNodesByLongestForwardPath(componentNodes, topology, graph, contractHash) {
1082
+ const forwardOut = /* @__PURE__ */ new Map();
1083
+ for (const node of componentNodes) forwardOut.set(node, []);
1084
+ for (const edges of graph.forwardChain.values()) for (const edge of edges) {
1085
+ if (!componentNodes.has(edge.from) || !componentNodes.has(edge.to)) continue;
1086
+ if (edge.from === edge.to) continue;
1087
+ if (topology.kindByMigrationHash.get(edge.migrationHash) !== "forward") continue;
1088
+ const bucket = forwardOut.get(edge.from);
1089
+ if (bucket) bucket.push(edge.to);
1090
+ }
1091
+ const roots = forwardRootsInComponent(componentNodes, topology);
1092
+ const rank = /* @__PURE__ */ new Map();
1093
+ for (const root of roots) rank.set(root, 0);
1094
+ const maxPasses = componentNodes.size;
1095
+ for (let pass = 0; pass < maxPasses; pass++) {
1096
+ let changed = false;
1097
+ for (const node of componentNodes) {
1098
+ const base = rank.get(node);
1099
+ if (base === void 0) continue;
1100
+ for (const to of forwardOut.get(node) ?? []) {
1101
+ const next = base + 1;
1102
+ if (next > (rank.get(to) ?? -1)) {
1103
+ rank.set(to, next);
1104
+ changed = true;
1105
+ }
1106
+ }
1107
+ }
1108
+ if (!changed) break;
1109
+ }
1110
+ for (const node of componentNodes) if (!rank.has(node)) rank.set(node, 0);
1111
+ if (contractHash !== void 0 && contractHash !== "empty" && componentNodes.has(contractHash) && (forwardOut.get(contractHash) ?? []).length === 0) rank.set(contractHash, maxRank(rank) + 1);
1112
+ return [...componentNodes].sort((a, b) => compareNodesTipsFirst(a, b, rank));
1113
+ }
1114
+ /**
1115
+ * Build the row model from a tolerant `MigrationGraph`.
1116
+ *
1117
+ * The row model is the first pure-data stage of the `migration graph` render
1118
+ * pipeline. It:
1119
+ * - classifies every edge as `forward`, `rollback`, or `self`;
1120
+ * - produces a deterministic vertical node ordering (tips at index 0, roots
1121
+ * at the end) within each weakly-connected component;
1122
+ * - separates disjoint components with `null` sentinels;
1123
+ * - optionally prepends a detached current contract as its own single-node
1124
+ * component when `contractHash` is not already in the graph.
1125
+ *
1126
+ * No columns, no lane allocation, no glyphs, no rendering.
1127
+ */
1128
+ /**
1129
+ * Resolve the detached current contract, if any: a real contract (not the
1130
+ * empty baseline) that no migration on disk produces, so it is absent from
1131
+ * the graph. Such a contract renders as a floating node rather than
1132
+ * decorating an existing one. Returns the hash when detached, else undefined.
1133
+ */
1134
+ function detachedContractHash(graph, contractHash) {
1135
+ return contractHash !== void 0 && contractHash !== "empty" && !graph.nodes.has(contractHash) ? contractHash : void 0;
1136
+ }
1137
+ function isForwardLeaf(node, edges) {
1138
+ return !edges.some((e) => e.kind === "forward" && e.from === node && e.from !== e.to);
1139
+ }
1140
+ function forwardReachableFrom(start, forwardTo) {
1141
+ const reachable = /* @__PURE__ */ new Set([start]);
1142
+ const queue = [start];
1143
+ while (queue.length > 0) {
1144
+ const node = queue.shift();
1145
+ if (node === void 0) continue;
1146
+ for (const next of forwardTo.get(node) ?? []) if (!reachable.has(next)) {
1147
+ reachable.add(next);
1148
+ queue.push(next);
1149
+ }
1150
+ }
1151
+ return reachable;
1152
+ }
1153
+ function buildForwardToMap(edges) {
1154
+ const forwardTo = /* @__PURE__ */ new Map();
1155
+ for (const edge of edges) {
1156
+ if (edge.kind !== "forward" || edge.from === edge.to) continue;
1157
+ const bucket = forwardTo.get(edge.from);
1158
+ if (bucket) bucket.push(edge.to);
1159
+ else forwardTo.set(edge.from, [edge.to]);
1160
+ }
1161
+ return forwardTo;
1162
+ }
1163
+ function sortEdgesForContractHashTrunk(edges, contractHash) {
1164
+ if (contractHash === void 0 || contractHash === "empty" || !isForwardLeaf(contractHash, edges)) return edges;
1165
+ const preferredLeaf = contractHash;
1166
+ const forwardTo = buildForwardToMap(edges);
1167
+ const reachability = /* @__PURE__ */ new Map();
1168
+ function canReachContractHash(from) {
1169
+ let cached = reachability.get(from);
1170
+ if (cached === void 0) {
1171
+ cached = forwardReachableFrom(from, forwardTo);
1172
+ reachability.set(from, cached);
1173
+ }
1174
+ return cached.has(preferredLeaf);
1175
+ }
1176
+ function trunkBias(edge) {
1177
+ if (edge.kind !== "forward" || edge.from === edge.to) return 0;
1178
+ if (edge.to === preferredLeaf) return 2;
1179
+ if (canReachContractHash(edge.to)) return 1;
1180
+ return 0;
1181
+ }
1182
+ return edges.map((edge, index) => ({
1183
+ edge,
1184
+ index,
1185
+ bias: trunkBias(edge)
1186
+ })).sort((a, b) => {
1187
+ if (a.edge.from !== b.edge.from) return a.index - b.index;
1188
+ if (a.bias !== b.bias) return b.bias - a.bias;
1189
+ return a.index - b.index;
1190
+ }).map(({ edge }) => edge);
1191
+ }
1192
+ function rebuildEdgeLookupMaps(edges) {
1193
+ const edgesByFrom = /* @__PURE__ */ new Map();
1194
+ const edgesByTo = /* @__PURE__ */ new Map();
1195
+ for (const classified of edges) {
1196
+ const fromBucket = edgesByFrom.get(classified.from);
1197
+ if (fromBucket) fromBucket.push(classified);
1198
+ else edgesByFrom.set(classified.from, [classified]);
1199
+ const toBucket = edgesByTo.get(classified.to);
1200
+ if (toBucket) toBucket.push(classified);
1201
+ else edgesByTo.set(classified.to, [classified]);
1202
+ }
1203
+ return {
1204
+ edgesByFrom,
1205
+ edgesByTo
1206
+ };
1207
+ }
1208
+ function buildMigrationGraphRows(graph, options = {}) {
1209
+ const emptyModel = {
1210
+ nodes: [],
1211
+ edges: [],
1212
+ edgesByFrom: /* @__PURE__ */ new Map(),
1213
+ edgesByTo: /* @__PURE__ */ new Map()
1214
+ };
1215
+ if (graph.nodes.size === 0) {
1216
+ const detached = detachedContractHash(graph, options.contractHash);
1217
+ return detached !== void 0 ? {
1218
+ ...emptyModel,
1219
+ nodes: [detached]
1220
+ } : emptyModel;
1221
+ }
1222
+ const topology = classifyMigrationGraphTopology(graph);
1223
+ const edges = [];
1224
+ for (const edgeList of graph.forwardChain.values()) for (const edge of edgeList) {
1225
+ const kind = topology.kindByMigrationHash.get(edge.migrationHash) ?? "forward";
1226
+ edges.push({
1227
+ migrationHash: edge.migrationHash,
1228
+ from: edge.from,
1229
+ to: edge.to,
1230
+ dirName: edge.dirName,
1231
+ kind
1232
+ });
1233
+ }
1234
+ const sortedEdges = sortEdgesForContractHashTrunk(edges, options.contractHash);
1235
+ const { edgesByFrom, edgesByTo } = rebuildEdgeLookupMaps(sortedEdges);
1236
+ const components = weaklyConnectedComponents(graph);
1237
+ const nodes = [];
1238
+ for (let i = 0; i < components.length; i++) {
1239
+ if (i > 0) nodes.push(null);
1240
+ const component = components[i];
1241
+ if (component === void 0) continue;
1242
+ const ordered = layerNodesByLongestForwardPath(component, topology, graph, options.contractHash);
1243
+ for (const node of ordered) nodes.push(node);
1244
+ }
1245
+ const detached = detachedContractHash(graph, options.contractHash);
1246
+ if (detached !== void 0) {
1247
+ if (nodes.length > 0) nodes.unshift(null);
1248
+ nodes.unshift(detached);
1249
+ }
1250
+ return {
1251
+ nodes,
1252
+ edges: sortedEdges,
1253
+ edgesByFrom,
1254
+ edgesByTo
1255
+ };
1256
+ }
1257
+ function mergeMigrationEdgeAnnotations(listOverlay, statusOverlay) {
1258
+ const merged = /* @__PURE__ */ new Map();
1259
+ for (const [migrationHash, listAnnotation] of listOverlay) {
1260
+ const statusAnnotation = statusOverlay.get(migrationHash);
1261
+ merged.set(migrationHash, {
1262
+ ...listAnnotation,
1263
+ ...statusAnnotation?.status !== void 0 ? { status: statusAnnotation.status } : {}
1264
+ });
1265
+ }
1266
+ return merged;
1267
+ }
1268
+ /**
1269
+ * Translate `migrate --show` per-edge path-highlight annotations into a
1270
+ * {@link Highlight}. With any `pathHighlight` present the result is focus mode
1271
+ * (on-path lifted green, off-path dim); otherwise flat (lane-rotation colour).
1272
+ */
1273
+ function highlightFromEdgeAnnotations(edgeAnnotationsByHash) {
1274
+ const onPath = /* @__PURE__ */ new Set();
1275
+ let anyPathHighlight = false;
1276
+ for (const [migrationHash, annotation] of edgeAnnotationsByHash) {
1277
+ if (annotation.pathHighlight === void 0) continue;
1278
+ anyPathHighlight = true;
1279
+ if (annotation.pathHighlight === "on-path") onPath.add(migrationHash);
1280
+ }
1281
+ return anyPathHighlight ? {
1282
+ mode: "focus",
1283
+ onPath
1284
+ } : {
1285
+ mode: "flat",
1286
+ onPath: /* @__PURE__ */ new Set()
1287
+ };
1288
+ }
1289
+ function buildGridForInput(input) {
1290
+ const rowModel = buildMigrationGraphRows(input.graph, { contractHash: input.liveContractHash });
1291
+ return {
1292
+ grid: buildGrid(rowModel, {}, {
1293
+ mode: "flat",
1294
+ onPath: /* @__PURE__ */ new Set()
1295
+ }),
1296
+ rowModel
1297
+ };
1298
+ }
1299
+ /**
1300
+ * The widest gutter→label column across the given space layouts. Cross-space
1301
+ * callers pass this back in so every section's labels share one column.
1302
+ */
1303
+ function computeGlobalMaxEdgeTreePrefixWidth(inputs, glyphMode = "unicode") {
1304
+ let globalMax = 0;
1305
+ for (const input of inputs) {
1306
+ const { grid } = buildGridForInput(input);
1307
+ globalMax = Math.max(globalMax, computeLabelColumn(grid, glyphMode));
1308
+ }
1309
+ return globalMax;
1310
+ }
1311
+ function computeGlobalMaxDirNameWidth(inputs) {
1312
+ let globalMax = 0;
1313
+ for (const input of inputs) {
1314
+ const { rowModel } = buildGridForInput(input);
1315
+ globalMax = Math.max(globalMax, computeMaxDirNameWidth(rowModel));
1316
+ }
1317
+ return globalMax;
1318
+ }
1319
+ function renderMigrationGraphSpaceTreeInternal(input) {
1320
+ const appSpace = input.isAppSpace !== false;
1321
+ const rowModel = buildMigrationGraphRows(input.graph, { ...appSpace ? { contractHash: input.liveContractHash } : {} });
1322
+ const listOverlay = buildEdgeAnnotationsByHashFromListEntries(input.migrations);
1323
+ const edgeAnnotationsByHash = input.statusOverlayByHash === void 0 ? listOverlay : mergeMigrationEdgeAnnotations(listOverlay, input.statusOverlayByHash);
1324
+ return renderMigrationGraphCommand({
1325
+ grid: buildGrid(rowModel, {}, highlightFromEdgeAnnotations(edgeAnnotationsByHash)),
1326
+ rowModel,
1327
+ colorize: input.colorize,
1328
+ glyphMode: input.glyphMode,
1329
+ contractHash: input.liveContractHash,
1330
+ isAppSpace: appSpace,
1331
+ edgeAnnotationsByHash,
1332
+ refsByHash: input.refsByHash ?? buildRefsByHashFromListEntries(input.migrations),
1333
+ ...input.dbHash !== void 0 ? { dbHash: input.dbHash } : {},
1334
+ ...input.styler !== void 0 ? { styler: input.styler } : {},
1335
+ ...input.globalMaxEdgeTreePrefixWidth !== void 0 ? { globalLabelColumn: input.globalMaxEdgeTreePrefixWidth } : {},
1336
+ ...input.globalMaxDirNameWidth !== void 0 ? { globalMaxDirNameWidth: input.globalMaxDirNameWidth } : {}
1337
+ });
1338
+ }
1339
+ function renderMigrationGraphSpaceTree(input) {
1340
+ return renderMigrationGraphSpaceTreeInternal(input);
1341
+ }
1342
+ function indentMigrationGraphTreeBlock(treeOutput, indent) {
1343
+ if (treeOutput.length === 0) return treeOutput;
1344
+ return treeOutput.split("\n").map((line) => line.length === 0 ? line : `${indent}${line}`).join("\n");
1345
+ }
1346
+ const IDENTITY_MIGRATION_LIST_STYLER = {
1347
+ kind: (text) => text,
1348
+ dirName: (text) => text,
1349
+ sourceHash: (text) => text,
1350
+ destHash: (text) => text,
1351
+ glyph: (text) => text,
1352
+ lane: (text) => text,
1353
+ invariants: (ids) => `{${ids.join(", ")}}`,
1354
+ refs: (names) => `(${names.join(", ")})`,
1355
+ spaceHeading: (text) => text,
1356
+ summary: (text) => text,
1357
+ emptyState: (text) => text
1358
+ };
1359
+ function canonicalFrom(from) {
1360
+ return from ?? "empty";
1361
+ }
1362
+ function migrationGraphFromListEntries(entries) {
1363
+ const nodes = /* @__PURE__ */ new Set();
1364
+ const forwardChain = /* @__PURE__ */ new Map();
1365
+ const reverseChain = /* @__PURE__ */ new Map();
1366
+ const migrationByHash = /* @__PURE__ */ new Map();
1367
+ for (const entry of entries) {
1368
+ const from = canonicalFrom(entry.fromContract);
1369
+ const edge = {
1370
+ from,
1371
+ to: entry.toContract,
1372
+ migrationHash: entry.hash,
1373
+ dirName: entry.name,
1374
+ createdAt: entry.createdAt,
1375
+ invariants: entry.providedInvariants
1376
+ };
1377
+ nodes.add(from);
1378
+ nodes.add(entry.toContract);
1379
+ const forward = forwardChain.get(from);
1380
+ if (forward) forward.push(edge);
1381
+ else forwardChain.set(from, [edge]);
1382
+ const reverse = reverseChain.get(entry.toContract);
1383
+ if (reverse) reverse.push(edge);
1384
+ else reverseChain.set(entry.toContract, [edge]);
1385
+ migrationByHash.set(entry.hash, edge);
1386
+ }
1387
+ return {
1388
+ nodes,
1389
+ forwardChain,
1390
+ reverseChain,
1391
+ migrationByHash
1392
+ };
1393
+ }
1394
+ function buildEdgeAnnotationsByHashFromListEntries(entries) {
1395
+ const annotations = /* @__PURE__ */ new Map();
1396
+ for (const entry of entries) annotations.set(entry.hash, {
1397
+ operationCount: entry.operationCount,
1398
+ invariants: entry.providedInvariants
1399
+ });
1400
+ return annotations;
1401
+ }
1402
+ function buildRefsByHashFromListEntries(entries) {
1403
+ const refsByHash = /* @__PURE__ */ new Map();
1404
+ for (const entry of entries) if (entry.refs.length > 0) refsByHash.set(entry.toContract, entry.refs);
1405
+ return refsByHash;
1406
+ }
1407
+ function formatEmptyStateLine(spaceId, style) {
1408
+ return style.emptyState(`There are no migrations in migrations/${spaceId}/ yet`);
1409
+ }
1410
+ function renderSpaceTreeBlock(spaceId, migrations, multiSpace, glyphMode, style, colorize, liveContractHash, graphForSpace, appSpaceId, globalMaxEdgeTreePrefixWidth, globalMaxDirNameWidth) {
1411
+ if (migrations.length === 0) {
1412
+ const emptyLine = formatEmptyStateLine(spaceId, style);
1413
+ if (!multiSpace) return [emptyLine];
1414
+ return [style.spaceHeading(`${spaceId}:`), ` ${emptyLine}`];
1415
+ }
1416
+ const graph = graphForSpace(spaceId) ?? migrationGraphFromListEntries(migrations);
1417
+ const isAppSpace = appSpaceId === void 0 ? void 0 : spaceId === appSpaceId;
1418
+ const treeOutput = renderMigrationGraphSpaceTree({
1419
+ graph,
1420
+ migrations,
1421
+ liveContractHash,
1422
+ glyphMode,
1423
+ colorize,
1424
+ refsByHash: buildRefsByHashFromListEntries(migrations),
1425
+ styler: style,
1426
+ ...isAppSpace !== void 0 ? { isAppSpace } : {},
1427
+ ...globalMaxEdgeTreePrefixWidth !== void 0 ? { globalMaxEdgeTreePrefixWidth } : {},
1428
+ ...globalMaxDirNameWidth !== void 0 ? { globalMaxDirNameWidth } : {}
1429
+ });
1430
+ if (!multiSpace) return treeOutput.length === 0 ? [] : [treeOutput];
1431
+ const indented = indentMigrationGraphTreeBlock(treeOutput, " ");
1432
+ return [style.spaceHeading(`${spaceId}:`), indented];
1433
+ }
1434
+ /**
1435
+ * Compose the styled `migration list` human output via the shared tree
1436
+ * renderer. Each on-disk migration is one edge row with package-fact
1437
+ * annotations; refs decorate destination contract nodes.
1438
+ *
1439
+ * `options.colorize` must match whether `style` emits ANSI (e.g. both true for
1440
+ * `createAnsiMigrationListStyler({ useColor: true })`).
1441
+ */
1442
+ function renderMigrationListWithStyle(result, style, glyphMode = "unicode", options = {}) {
1443
+ const multiSpace = result.spaces.length > 1;
1444
+ const colorize = options.colorize ?? false;
1445
+ const liveContractHash = options.liveContractHash ?? "empty";
1446
+ const graphForSpace = options.graphForSpace ?? (() => void 0);
1447
+ const appSpaceId = options.appSpaceId;
1448
+ const globalLayoutInputs = multiSpace ? result.spaces.filter((space) => space.migrations.length > 0).map((space) => ({
1449
+ graph: graphForSpace(space.space) ?? migrationGraphFromListEntries(space.migrations),
1450
+ liveContractHash
1451
+ })) : [];
1452
+ const globalMaxEdgeTreePrefixWidth = globalLayoutInputs.length > 0 ? computeGlobalMaxEdgeTreePrefixWidth(globalLayoutInputs) : void 0;
1453
+ const globalMaxDirNameWidth = globalLayoutInputs.length > 0 ? computeGlobalMaxDirNameWidth(globalLayoutInputs) : void 0;
1454
+ const lines = [];
1455
+ for (let index = 0; index < result.spaces.length; index++) {
1456
+ const space = result.spaces[index];
1457
+ if (index > 0) lines.push("");
1458
+ lines.push(...renderSpaceTreeBlock(space.space, space.migrations, multiSpace, glyphMode, style, colorize, liveContractHash, graphForSpace, appSpaceId, globalMaxEdgeTreePrefixWidth, globalMaxDirNameWidth));
1459
+ }
1460
+ if (result.spaces.reduce((count, space) => count + space.migrations.length, 0) > 0) {
1461
+ lines.push("");
1462
+ lines.push(style.summary(result.summary));
1463
+ }
1464
+ return lines.join("\n");
1465
+ }
1466
+ function hasMarkersFormatter(styler) {
1467
+ return "markers" in styler && typeof styler.markers === "function";
1468
+ }
1469
+ function styleMarkerName(name) {
1470
+ return name === "contract" ? bold(green(name)) : green(name);
1471
+ }
1472
+ function plainMarkers(names) {
1473
+ return names.map((name) => `@${name}`).join(" ");
1474
+ }
1475
+ function formatContractNodeOverlays(styler, markers, refs) {
1476
+ const parts = [];
1477
+ if (markers.length > 0) parts.push(hasMarkersFormatter(styler) ? styler.markers(markers) : plainMarkers(markers));
1478
+ if (refs.length > 0) parts.push(styler.refs(refs));
1479
+ return parts.join(" ");
1480
+ }
1481
+ /**
1482
+ * The current contract overlay marker. Unlike user refs, this names the user's
1483
+ * declared desired state — the implicit base/target for `plan` / `migrate` —
1484
+ * not a stored label. It is emphasized (bold) so it stands out from plain refs
1485
+ * (including the live-database `db` marker, which is just another ref).
1486
+ */
1487
+ const CONTRACT_MARKER_NAME = "contract";
1488
+ function styleRefName(name) {
1489
+ return green(name);
1490
+ }
1491
+ /**
1492
+ * Build a {@link MigrationListStyler} that decorates `migration list`
1493
+ * tokens with ANSI SGR codes. When `useColor` is `false` (non-TTY,
1494
+ * `--no-color`, `NO_COLOR=1`, piped output) the function returns the
1495
+ * shared identity styler so callers get plain text with zero ANSI
1496
+ * bytes — pipe-friendly by construction.
1497
+ *
1498
+ * Palette:
1499
+ *
1500
+ * - `dirName`: bold
1501
+ * - `sourceHash`: dim cyan
1502
+ * - `destHash`: bright cyan
1503
+ * - `kind` (`*` / `↩` / `⟲`): bright — the signal; lanes and arrows dim
1504
+ * - `glyph` (`→` / `⟲` / `∅`): dim
1505
+ * - `lane` (graph gutter lines `│` and fan/join connectors `├─┐` / `├─┘`): dim
1506
+ * - `invariants` (`{...}`): yellow
1507
+ * - `markers` (`@contract @db`): green; the `contract` desired-state marker is
1508
+ * green-bold (`db` is plain green); the `@` sigil is applied to each name
1509
+ * - `refs` (`(...)`): green (the active ref is bolded separately by the tree styler)
1510
+ * - `spaceHeading` (`<spaceId>:`): bold
1511
+ * - `summary`: dim
1512
+ * - `emptyState`: dim
1513
+ */
1514
+ function createAnsiMigrationListStyler(opts) {
1515
+ if (!opts.useColor) return {
1516
+ ...IDENTITY_MIGRATION_LIST_STYLER,
1517
+ markers: plainMarkers
1518
+ };
1519
+ return {
1520
+ kind: (text) => text,
1521
+ dirName: (text) => bold(text),
1522
+ sourceHash: (text) => dim(cyan(text)),
1523
+ destHash: (text) => cyanBright(text),
1524
+ glyph: (text) => dim(text),
1525
+ lane: (text) => dim(text),
1526
+ invariants: (ids) => yellow(`{${ids.join(", ")}}`),
1527
+ markers: (names) => {
1528
+ const sigil = green("@");
1529
+ return names.map((name) => sigil + styleMarkerName(name)).join(" ");
1530
+ },
1531
+ refs: (names) => {
1532
+ const open = green("(");
1533
+ const close = green(")");
1534
+ const separator = green(", ");
1535
+ return open + names.map(styleRefName).join(separator) + close;
1536
+ },
1537
+ spaceHeading: (text) => bold(text),
1538
+ summary: (text) => dim(text),
1539
+ emptyState: (text) => dim(text)
1540
+ };
1541
+ }
1542
+ /**
1543
+ * Per-row label formatting for the command graph renderer.
1544
+ *
1545
+ * The command graph renderer ({@link renderMigrationGraphCommand}) derives the
1546
+ * graph structure — rows, gutter, lane colours — from the grid pipeline. The
1547
+ * per-row LABEL (contract hash + markers + refs for node rows;
1548
+ * migration name + `from → to` + ops/status/will-run for migration rows) is
1549
+ * formatted here. This module owns ONLY label text + styling; it knows nothing
1550
+ * about lanes, gutters, or grid geometry.
1551
+ *
1552
+ * The label format (hash abbreviation, `from → to` arrow column, `@contract`/
1553
+ * `@db` markers, `(refs)`, ops/status/will-run suffix, the legend) is the same
1554
+ * as the previous renderer — that part was never the bug.
1555
+ */
1556
+ /**
1557
+ * The live-database overlay marker. Just another ref as far as styling goes —
1558
+ * the only emphasized markers are the active ref and the `contract`
1559
+ * desired-state marker (see {@link CONTRACT_MARKER_NAME}).
1560
+ */
1561
+ const DB_MARKER_NAME = "db";
1562
+ /**
1563
+ * Forced-color functions that always emit ANSI regardless of the ambient TTY
1564
+ * environment (NO_COLOR, piped output). Used so on-path green / off-path dim are
1565
+ * deterministically emitted in tests that request colour while NO_COLOR is set.
1566
+ */
1567
+ const { dim: forcedDim } = createColors({ useColor: true });
1568
+ const { greenBright: forcedGreen } = createColors({ useColor: true });
1569
+ /**
1570
+ * The two label styles used in `migrate --show` path-highlight mode.
1571
+ *
1572
+ * - `onPath`: bold name, neutral hashes (the on-path lane glyphs are coloured
1573
+ * green by the grid renderer, not here).
1574
+ * - `offPath`: uniform dim grey on the name and the whole hash column.
1575
+ *
1576
+ * To change the on-path / off-path label colour in future, edit this object.
1577
+ */
1578
+ const PATH_HIGHLIGHT_STYLES = {
1579
+ onPath: (_style, colorize) => ({
1580
+ lane: colorize ? forcedGreen : (text) => text,
1581
+ arrow: (text) => text,
1582
+ dirName: (text) => bold(text),
1583
+ hashOverride: void 0
1584
+ }),
1585
+ offPath: (colorize) => ({
1586
+ lane: colorize ? forcedDim : (text) => text,
1587
+ arrow: colorize ? forcedDim : (text) => text,
1588
+ dirName: colorize ? forcedDim : (text) => text,
1589
+ hashOverride: colorize ? forcedDim : void 0
1590
+ })
1591
+ };
1592
+ function abbreviateHash(hash, hashLength, emptySource) {
1593
+ if (hash === "empty") return emptySource;
1594
+ return hash.slice(0, hashLength);
1595
+ }
1596
+ function overlayNamesForContract(contractHash, opts) {
1597
+ const markers = [];
1598
+ const refs = [];
1599
+ const userRefs = opts.refsByHash?.get(contractHash);
1600
+ if (userRefs) refs.push(...[...userRefs].sort((a, b) => a.localeCompare(b)));
1601
+ if (opts.isAppSpace !== false && opts.contractHash === contractHash && contractHash !== "empty") markers.push(CONTRACT_MARKER_NAME);
1602
+ if (opts.dbHash === contractHash) markers.push(DB_MARKER_NAME);
1603
+ markers.sort((a, b) => {
1604
+ if (a === "contract") return -1;
1605
+ if (b === "contract") return 1;
1606
+ return a.localeCompare(b);
1607
+ });
1608
+ return {
1609
+ markers,
1610
+ refs
1611
+ };
1612
+ }
1613
+ function createLabelStyler(opts) {
1614
+ const base = opts.styler ?? createAnsiMigrationListStyler({ useColor: opts.colorize });
1615
+ const activeRefName = opts.activeRefName;
1616
+ if (!opts.colorize || activeRefName === void 0) return base;
1617
+ return {
1618
+ ...base,
1619
+ refs: (names) => {
1620
+ const styledNames = names.map((name) => name === activeRefName ? bold(name) : name);
1621
+ return base.refs(styledNames);
1622
+ }
1623
+ };
1624
+ }
1625
+ function overlayStatusGlyphs(mode) {
1626
+ return mode === "ascii" ? {
1627
+ applied: "+",
1628
+ pending: ">"
1629
+ } : {
1630
+ applied: "✓",
1631
+ pending: "⧗"
1632
+ };
1633
+ }
1634
+ function formatEdgeAnnotationSuffix(migrationHash, opts, style) {
1635
+ const annotation = opts.edgeAnnotationsByHash?.get(migrationHash);
1636
+ if (annotation === void 0) return "";
1637
+ const isOffPath = annotation.pathHighlight === "off-path";
1638
+ const segments = [];
1639
+ if (annotation.operationCount !== void 0) segments.push(`${annotation.operationCount} ops`);
1640
+ if (annotation.invariants !== void 0 && annotation.invariants.length > 0) segments.push(style.invariants(annotation.invariants));
1641
+ const status = annotation.status;
1642
+ if (status !== void 0) {
1643
+ const glyphs = overlayStatusGlyphs(opts.glyphMode ?? "unicode");
1644
+ const glyph = status === "applied" ? glyphs.applied : glyphs.pending;
1645
+ const label = status === "applied" ? "applied" : "pending";
1646
+ if (!opts.colorize) segments.push(`${glyph} ${label}`);
1647
+ else {
1648
+ const styler = status === "applied" ? green : yellow;
1649
+ segments.push(styler(`${glyph} ${label}`));
1650
+ }
1651
+ }
1652
+ if (annotation.pathHighlight === "on-path") {
1653
+ const glyph = opts.glyphMode === "ascii" ? ">" : "↑";
1654
+ segments.push(`${glyph} will run`);
1655
+ }
1656
+ if (segments.length === 0) return "";
1657
+ const suffix = ` ${segments.join(" ")}`;
1658
+ return opts.colorize && isOffPath ? forcedDim(suffix) : suffix;
1659
+ }
1660
+ /**
1661
+ * Format the `from → to` hash data column for an edge row.
1662
+ *
1663
+ * When `hashOverride` is provided (off-path → `dim`), it replaces ALL sub-stylers
1664
+ * so dim reaches every character without inner ANSI codes overriding it.
1665
+ */
1666
+ function formatEdgeHashColumn(edge, style, hashLength, glyphMode, hashOverride) {
1667
+ const emptySource = migrationListEmptySource(glyphMode);
1668
+ const forwardArrow = migrationListForwardArrow(glyphMode);
1669
+ const src = hashOverride ?? style.sourceHash;
1670
+ const dst = hashOverride ?? style.destHash;
1671
+ const glyph = hashOverride ?? style.glyph;
1672
+ if (edge.kind === "self") {
1673
+ const hash = abbreviateHash(edge.from, hashLength, emptySource);
1674
+ return `${padFromHashColumn(src(hash), hashLength)} ${glyph(forwardArrow)} ${dst(hash)}`;
1675
+ }
1676
+ return `${edge.from === "empty" ? padFromHashColumn(glyph(emptySource), hashLength) : padFromHashColumn(src(abbreviateHash(edge.from, hashLength, emptySource)), hashLength)} ${glyph(forwardArrow)} ${dst(abbreviateHash(edge.to, hashLength, emptySource))}`;
1677
+ }
1678
+ /**
1679
+ * The label text for a contract node row: the abbreviated hash (or the `∅`
1680
+ * empty-source token for the baseline) followed by its `@contract`/`@db` markers
1681
+ * and `(refs)`, with two spaces between the hash and the overlay block.
1682
+ */
1683
+ function formatNodeLabel(contractHash, opts, nodeHighlight) {
1684
+ const style = createLabelStyler(opts);
1685
+ const hashLength = opts.hashLength ?? 7;
1686
+ const emptySource = migrationListEmptySource(opts.glyphMode ?? "unicode");
1687
+ const overlays = overlayNamesForContract(contractHash, opts);
1688
+ const hasOverlays = overlays.markers.length > 0 || overlays.refs.length > 0;
1689
+ const offPath = nodeHighlight === "off-path" && opts.colorize;
1690
+ const hashText = contractHash === "empty" ? (offPath ? forcedDim : style.glyph)(emptySource) : (offPath ? forcedDim : style.sourceHash)(abbreviateHash(contractHash, hashLength, emptySource));
1691
+ if (!hasOverlays) return hashText;
1692
+ return `${hashText} ${formatContractNodeOverlays(style, overlays.markers, overlays.refs)}`;
1693
+ }
1694
+ /**
1695
+ * The label text for a migration row: the migration name (padded to
1696
+ * `dirNameWidth`) followed by the `from → to` hash column and the annotation
1697
+ * suffix (ops / status / will-run).
1698
+ *
1699
+ * In flat mode the name is tinted with its lane's hue (`lane` ≥ 0), so the node
1700
+ * `○`, the edges/arrows in the gutter, and the name all read in one colour. In
1701
+ * focus mode the on-path/off-path role overrides the lane hue (bold / dim).
1702
+ */
1703
+ function formatMigrationLabel(edge, dirNameWidth, opts, lane) {
1704
+ const style = createLabelStyler(opts);
1705
+ const hashLength = opts.hashLength ?? 7;
1706
+ const glyphMode = opts.glyphMode ?? "unicode";
1707
+ const highlight = opts.edgeAnnotationsByHash?.get(edge.migrationHash)?.pathHighlight;
1708
+ let dirNameStyler;
1709
+ let hashOverride;
1710
+ if (highlight === "on-path") {
1711
+ dirNameStyler = opts.colorize ? forcedGreen : (text) => text;
1712
+ hashOverride = void 0;
1713
+ } else if (highlight === "off-path") {
1714
+ dirNameStyler = opts.colorize ? forcedDim : style.dirName;
1715
+ hashOverride = opts.colorize ? forcedDim : void 0;
1716
+ } else if (opts.colorize && lane !== void 0) {
1717
+ dirNameStyler = (text) => laneColorizer(lane)(text);
1718
+ hashOverride = void 0;
1719
+ } else {
1720
+ dirNameStyler = style.dirName;
1721
+ hashOverride = void 0;
1722
+ }
1723
+ const dirNamePadding = " ".repeat(Math.max(0, dirNameWidth - edge.dirName.length));
1724
+ return `${`${dirNameStyler(edge.dirName)}${dirNamePadding}`}${formatEdgeHashColumn(edge, style, hashLength, glyphMode, hashOverride)}${formatEdgeAnnotationSuffix(edge.migrationHash, opts, style)}`;
1725
+ }
1726
+ /**
1727
+ * Format a single on-path migration row for the `migrate --show` run-list.
1728
+ * Shares PATH_HIGHLIGHT_STYLES.onPath with the graph tree so the run-list and
1729
+ * the graph are byte-for-byte identical in their name/hash columns.
1730
+ */
1731
+ function formatOnPathMigrationRow(dirName, from, to, dirNameWidth, colorize, glyphMode) {
1732
+ const style = createAnsiMigrationListStyler({ useColor: colorize });
1733
+ const styledDirName = `${PATH_HIGHLIGHT_STYLES.onPath(style, colorize).dirName(dirName)}${" ".repeat(Math.max(0, dirNameWidth - dirName.length))}`;
1734
+ const hashLength = 7;
1735
+ const emptySource = migrationListEmptySource(glyphMode);
1736
+ const forwardArrow = migrationListForwardArrow(glyphMode);
1737
+ const fromAbbr = from === "empty" ? padFromHashColumn(style.glyph(emptySource), hashLength) : padFromHashColumn(style.sourceHash(abbreviateHash(from, hashLength, emptySource)), hashLength);
1738
+ const toAbbr = to === "empty" ? style.glyph(emptySource) : style.destHash(abbreviateHash(to, hashLength, emptySource));
1739
+ return `${styledDirName} ${fromAbbr} ${style.glyph(forwardArrow)} ${toAbbr}`;
1740
+ }
1741
+ function legendGlyphs(mode) {
1742
+ return mode === "ascii" ? {
1743
+ node: "*",
1744
+ forward: "^",
1745
+ rollback: "v",
1746
+ self: "@"
1747
+ } : {
1748
+ node: "○",
1749
+ forward: "↑",
1750
+ rollback: "↓",
1751
+ self: "⟲"
1752
+ };
1753
+ }
1754
+ function formatLegendExampleMarkers(colorize) {
1755
+ if (!colorize) return "@contract @db";
1756
+ const sigil = green("@");
1757
+ return `${sigil + bold(green("contract"))} ${sigil}${green("db")}`;
1758
+ }
1759
+ /**
1760
+ * A compact key for the tree visual language: the contract node glyph, the
1761
+ * in-lane direction arrows, the empty baseline, the system-marker `@…` and
1762
+ * user-ref `(…)` conventions, and a worked sample of the data-column hash arrow.
1763
+ */
1764
+ function renderMigrationGraphLegend(opts) {
1765
+ const glyphMode = opts.glyphMode ?? "unicode";
1766
+ const style = createAnsiMigrationListStyler({ useColor: opts.colorize });
1767
+ const glyphs = legendGlyphs(glyphMode);
1768
+ const emptySource = migrationListEmptySource(glyphMode);
1769
+ const forwardArrow = migrationListForwardArrow(glyphMode);
1770
+ const sampleArrow = `${style.sourceHash("aaaaaa")} ${style.glyph(forwardArrow)} ${style.destHash("bbbbbb")}`;
1771
+ const statusGlyphs = overlayStatusGlyphs(glyphMode);
1772
+ const appliedPending = opts.colorize ? ` ${green(statusGlyphs.applied)} ${style.summary("applied")} ${yellow(statusGlyphs.pending)} ${style.summary("pending")}` : ` ${statusGlyphs.applied} ${style.summary("applied")} ${statusGlyphs.pending} ${style.summary("pending")}`;
1773
+ const exampleMarkers = formatLegendExampleMarkers(opts.colorize);
1774
+ const exampleRefs = opts.colorize ? style.refs(["prod", "staging"]) : "(prod, staging)";
1775
+ return [
1776
+ "Legend:",
1777
+ ` ${style.kind(glyphs.node)} ${style.summary("contract")} ${style.kind(glyphs.forward)} ${style.summary("forward")} ${style.kind(glyphs.rollback)} ${style.summary("rollback")}`,
1778
+ ` ${style.kind(glyphs.self)} ${style.summary("migration without schema change")}`,
1779
+ appliedPending,
1780
+ ` ${style.kind(emptySource)} ${style.summary("empty database (baseline)")}`,
1781
+ ` ${exampleMarkers} ${style.summary("reserved markers — also typeable as --from/--to tokens")}`,
1782
+ ` ${exampleRefs} ${style.summary("user-defined refs")}`,
1783
+ ` ${sampleArrow} ${style.summary("migration from contract aaaaaa to bbbbbb")}`
1784
+ ].join("\n");
1785
+ }
1786
+ /**
1787
+ * Command graph renderer: composes the gutter (from the grid) with per-row labels.
1788
+ *
1789
+ * Pipeline: buildMigrationGraphRows → buildGrid → renderMigrationGraphCommand
1790
+ *
1791
+ * Each grid row is classified by its cells: a node row gets a contract label;
1792
+ * a migration arrow row gets a migration label; connector rows get no label.
1793
+ * Label format and styling live in `./migration-graph-labels`.
1794
+ */
1795
+ const LABEL_GAP = 2;
1796
+ const MIN_HASH_DATA_COLUMN = 25;
1797
+ /**
1798
+ * Classify a grid row by its own cells:
1799
+ * - a cell carrying a NodeRef → node row (contract label);
1800
+ * - a cell whose top line is an arrow ({up}/{down}/self-loop) → migration row;
1801
+ * - otherwise → no label.
1802
+ *
1803
+ * A migration's arrow appears in exactly one grid row (the forward `↑` row, the
1804
+ * adjacent-rollback `↓` row, or the self-loop `⟲` row), so each migration gets
1805
+ * exactly one label, on the row that draws its arrow.
1806
+ *
1807
+ * Two distinct migrations with identical content (same from/to/ops) hash to the
1808
+ * SAME migration hash, so the arrow line is matched on BOTH its hash and its
1809
+ * `dirName` (which the LineRef carries per-row) — otherwise both rows would
1810
+ * resolve to one edge and the other migration's name would be lost.
1811
+ */
1812
+ function classifyRow(row, edgesByHash) {
1813
+ for (const cell of row) if (cell.node !== void 0) return {
1814
+ kind: "node",
1815
+ contractHash: cell.node.contractHash
1816
+ };
1817
+ for (const cell of row) {
1818
+ const arrow = arrowLine(cell);
1819
+ if (arrow === void 0) continue;
1820
+ const candidates = edgesByHash.get(arrow.line.migrationHash) ?? [];
1821
+ const edge = candidates.find((e) => e.dirName === arrow.line.dirName) ?? candidates[0];
1822
+ if (edge !== void 0) return {
1823
+ kind: "migration",
1824
+ edge,
1825
+ lane: arrow.line.lane
1826
+ };
1827
+ }
1828
+ return { kind: "none" };
1829
+ }
1830
+ /**
1831
+ * Return the cell's arrow line if it carries one — a self-loop, or a line whose
1832
+ * directions are exactly `{up}` or `{down}` (the migration-direction arrows).
1833
+ * Connector/corner/vertical lines are not arrows and yield `undefined`.
1834
+ */
1835
+ function arrowLine(cell) {
1836
+ for (const line of cell.lines) {
1837
+ if (line.selfLoop === true) return line;
1838
+ if (line.landingArrow === true) continue;
1839
+ const dirs = line.directions;
1840
+ if (dirs.size !== 1) continue;
1841
+ if (dirs.has("up") || dirs.has("down")) return line;
1842
+ }
1843
+ }
1844
+ /**
1845
+ * Resolve each contract's path-highlight role from the edges incident on it.
1846
+ * On-path wins: a contract touched by any on-path edge is on-path. Empty unless
1847
+ * focus-mode annotations are present.
1848
+ */
1849
+ function resolveNodeHighlights(rowModel, edgeAnnotationsByHash) {
1850
+ const result = /* @__PURE__ */ new Map();
1851
+ if (edgeAnnotationsByHash === void 0) return result;
1852
+ for (const edge of rowModel.edges) {
1853
+ const highlight = edgeAnnotationsByHash.get(edge.migrationHash)?.pathHighlight;
1854
+ if (highlight === void 0) continue;
1855
+ for (const hash of [edge.from, edge.to]) {
1856
+ if (hash === "empty") continue;
1857
+ if (result.get(hash) !== "on-path") result.set(hash, highlight);
1858
+ }
1859
+ }
1860
+ return result;
1861
+ }
1862
+ function maxDirNameLength(edges) {
1863
+ let max = 0;
1864
+ for (const edge of edges) max = Math.max(max, edge.dirName.length);
1865
+ return max;
1866
+ }
1867
+ /**
1868
+ * The label column for a render: the widest gutter (visible width) across every
1869
+ * row, plus the label gap. Labels begin here so they line up regardless of how
1870
+ * deep the lane structure runs on any one row. A cross-space override widens it
1871
+ * so sibling space sections share one column.
1872
+ */
1873
+ function computeLabelColumn(grid, glyphMode) {
1874
+ let maxGutter = 0;
1875
+ for (const row of grid) {
1876
+ const gutter = renderGridRow(row, {
1877
+ colorize: false,
1878
+ glyphMode
1879
+ });
1880
+ maxGutter = Math.max(maxGutter, stringWidth(gutter));
1881
+ }
1882
+ return maxGutter + LABEL_GAP;
1883
+ }
1884
+ function computeMaxDirNameWidth(rowModel) {
1885
+ return maxDirNameLength(rowModel.edges);
1886
+ }
1887
+ function padVisible(text, targetWidth) {
1888
+ const padding = Math.max(0, targetWidth - stringWidth(text));
1889
+ return text + " ".repeat(padding);
1890
+ }
1891
+ const ANSI_ESCAPE = "\x1B";
1892
+ function trimTrailingWhitespace(line) {
1893
+ const trailingSpaceBeforeReset = new RegExp(`[\\t ]+((?:${ANSI_ESCAPE}\\[[0-9;]*m)+)$`);
1894
+ return line.replace(trailingSpaceBeforeReset, "$1").replace(/\s+$/, "");
1895
+ }
1896
+ function renderMigrationGraphCommand(input) {
1897
+ const { grid, rowModel } = input;
1898
+ const glyphMode = input.glyphMode;
1899
+ const edgesByHash = /* @__PURE__ */ new Map();
1900
+ for (const edge of rowModel.edges) {
1901
+ const bucket = edgesByHash.get(edge.migrationHash);
1902
+ if (bucket) bucket.push(edge);
1903
+ else edgesByHash.set(edge.migrationHash, [edge]);
1904
+ }
1905
+ const labelOpts = {
1906
+ colorize: input.colorize,
1907
+ glyphMode,
1908
+ ...ifDefined("refsByHash", input.refsByHash),
1909
+ ...ifDefined("edgeAnnotationsByHash", input.edgeAnnotationsByHash),
1910
+ ...ifDefined("dbHash", input.dbHash),
1911
+ ...ifDefined("contractHash", input.contractHash),
1912
+ ...ifDefined("isAppSpace", input.isAppSpace),
1913
+ ...ifDefined("activeRefName", input.activeRefName),
1914
+ ...ifDefined("styler", input.styler)
1915
+ };
1916
+ const nodeHighlights = resolveNodeHighlights(rowModel, input.edgeAnnotationsByHash);
1917
+ const labelColumn = input.globalLabelColumn ?? computeLabelColumn(grid, glyphMode);
1918
+ const maxDirNameLen = input.globalMaxDirNameWidth ?? maxDirNameLength(rowModel.edges);
1919
+ const dirNameWidth = Math.max(maxDirNameLen + LABEL_GAP, MIN_HASH_DATA_COLUMN - labelColumn);
1920
+ const lines = [];
1921
+ for (const row of grid) {
1922
+ const gutter = renderGridRow(row, {
1923
+ colorize: input.colorize,
1924
+ glyphMode
1925
+ });
1926
+ const identity = classifyRow(row, edgesByHash);
1927
+ if (identity.kind === "none") {
1928
+ lines.push(trimTrailingWhitespace(gutter));
1929
+ continue;
1930
+ }
1931
+ const gutterPad = padVisible(gutter, labelColumn);
1932
+ if (identity.kind === "node") {
1933
+ const label = formatNodeLabel(identity.contractHash, labelOpts, nodeHighlights.get(identity.contractHash));
1934
+ lines.push(trimTrailingWhitespace(label.length === 0 ? gutter : `${gutterPad}${label}`));
1935
+ continue;
1936
+ }
1937
+ const label = formatMigrationLabel(identity.edge, dirNameWidth, labelOpts, identity.lane);
1938
+ lines.push(trimTrailingWhitespace(`${gutterPad}${label}`));
1939
+ }
1940
+ return lines.join("\n");
1941
+ }
1942
+ //#endregion
1943
+ export { renderMigrationGraphSpaceTree as _, computeGlobalMaxDirNameWidth as a, computeMaxDirNameWidth as c, highlightFromEdgeAnnotations as d, indentMigrationGraphTreeBlock as f, renderMigrationGraphLegend as g, renderMigrationGraphCommand as h, buildMigrationGraphRows as i, createAnsiMigrationListStyler as l, migrationListForwardArrow as m, abbreviateContractHash as n, computeGlobalMaxEdgeTreePrefixWidth as o, migrationListEmptySource as p, buildGrid as r, computeLabelColumn as s, IDENTITY_MIGRATION_LIST_STYLER as t, formatOnPathMigrationRow as u, renderMigrationListWithStyle as v };
1944
+
1945
+ //# sourceMappingURL=migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs.map