@prisma/orm-toolchain 8.0.0-rc.1-dev.44 → 8.0.0-rc.1-dev.46

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