prisma-next 0.12.0-dev.4 → 0.12.0-dev.40

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 (122) hide show
  1. package/dist/cli.mjs +180 -163
  2. package/dist/cli.mjs.map +1 -1
  3. package/dist/{client-KgJorIvG.mjs → client-BNdG504y.mjs} +80 -56
  4. package/dist/client-BNdG504y.mjs.map +1 -0
  5. package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-xvg9oq4T.mjs} +301 -23
  6. package/dist/command-helpers-xvg9oq4T.mjs.map +1 -0
  7. package/dist/commands/contract-emit.mjs +1 -1
  8. package/dist/commands/contract-infer.mjs +1 -1
  9. package/dist/commands/db-init.mjs +4 -5
  10. package/dist/commands/db-init.mjs.map +1 -1
  11. package/dist/commands/db-schema.mjs +3 -3
  12. package/dist/commands/db-sign.mjs +4 -4
  13. package/dist/commands/db-update.d.mts.map +1 -1
  14. package/dist/commands/db-update.mjs +10 -7
  15. package/dist/commands/db-update.mjs.map +1 -1
  16. package/dist/commands/db-verify.mjs +1 -1
  17. package/dist/commands/migrate.d.mts +2 -2
  18. package/dist/commands/migrate.d.mts.map +1 -1
  19. package/dist/commands/migrate.mjs +6 -8
  20. package/dist/commands/migrate.mjs.map +1 -1
  21. package/dist/commands/migration-check.d.mts +55 -1
  22. package/dist/commands/migration-check.d.mts.map +1 -1
  23. package/dist/commands/migration-check.mjs +2 -2
  24. package/dist/commands/migration-graph.d.mts +25 -7
  25. package/dist/commands/migration-graph.d.mts.map +1 -1
  26. package/dist/commands/migration-graph.mjs +170 -2
  27. package/dist/commands/migration-graph.mjs.map +1 -0
  28. package/dist/commands/migration-list.d.mts +24 -26
  29. package/dist/commands/migration-list.d.mts.map +1 -1
  30. package/dist/commands/migration-list.mjs +2 -190
  31. package/dist/commands/migration-log.d.mts +20 -15
  32. package/dist/commands/migration-log.d.mts.map +1 -1
  33. package/dist/commands/migration-log.mjs +1 -137
  34. package/dist/commands/migration-new.mjs +3 -3
  35. package/dist/commands/migration-plan.d.mts +1 -1
  36. package/dist/commands/migration-plan.mjs +1 -1
  37. package/dist/commands/migration-show.d.mts +1 -4
  38. package/dist/commands/migration-show.d.mts.map +1 -1
  39. package/dist/commands/migration-show.mjs +13 -25
  40. package/dist/commands/migration-show.mjs.map +1 -1
  41. package/dist/commands/migration-status.d.mts +41 -141
  42. package/dist/commands/migration-status.d.mts.map +1 -1
  43. package/dist/commands/migration-status.mjs +2 -759
  44. package/dist/commands/ref.d.mts +1 -1
  45. package/dist/commands/ref.mjs +3 -3
  46. package/dist/commands/telemetry/index.d.mts +7 -0
  47. package/dist/commands/telemetry/index.d.mts.map +1 -0
  48. package/dist/commands/telemetry/index.mjs +2 -0
  49. package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-Wj3u4Xco.mjs} +2 -2
  50. package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-Wj3u4Xco.mjs.map} +1 -1
  51. package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-COg18szA.mjs} +3 -3
  52. package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-COg18szA.mjs.map} +1 -1
  53. package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-KyJNQK5-.mjs} +3 -3
  54. package/dist/{contract-emit-D-4jrNve.mjs.map → contract-emit-KyJNQK5-.mjs.map} +1 -1
  55. package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-IEp0227u.mjs} +3 -3
  56. package/dist/{contract-infer-D8uEbJuu.mjs.map → contract-infer-IEp0227u.mjs.map} +1 -1
  57. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-BdRPfM3Q.mjs} +63 -5
  58. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-BdRPfM3Q.mjs.map} +1 -1
  59. package/dist/{db-verify-v_vUKXTU.mjs → db-verify-C9k5KAyI.mjs} +4 -4
  60. package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-C9k5KAyI.mjs.map} +1 -1
  61. package/dist/exports/control-api.d.mts +2 -2
  62. package/dist/exports/control-api.d.mts.map +1 -1
  63. package/dist/exports/control-api.mjs +2 -2
  64. package/dist/exports/index.mjs +1 -1
  65. package/dist/exports/init-output.mjs +1 -1
  66. package/dist/{framework-components-fYXjz_in.mjs → framework-components-Be4inY3I.mjs} +2 -2
  67. package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-Be4inY3I.mjs.map} +1 -1
  68. package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-DG4uY5tV.d.mts} +1 -1
  69. package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-DG4uY5tV.d.mts.map} +1 -1
  70. package/dist/{init-Cv9UzWL5.mjs → init-BIxw3l7t.mjs} +5 -58
  71. package/dist/init-BIxw3l7t.mjs.map +1 -0
  72. package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-DXUFGQDe.mjs} +3 -3
  73. package/dist/{inspect-live-schema-C6ohV_oQ.mjs.map → inspect-live-schema-DXUFGQDe.mjs.map} +1 -1
  74. package/dist/{migration-check-BiBJoYYW.mjs → migration-check-CUavU7U9.mjs} +236 -88
  75. package/dist/migration-check-CUavU7U9.mjs.map +1 -0
  76. package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-omgKpt3K.mjs} +3 -3
  77. package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-omgKpt3K.mjs.map} +1 -1
  78. package/dist/migration-graph-space-render-ByJ83gxp.mjs +1966 -0
  79. package/dist/migration-graph-space-render-ByJ83gxp.mjs.map +1 -0
  80. package/dist/migration-list-jK6QeczE.mjs +228 -0
  81. package/dist/migration-list-jK6QeczE.mjs.map +1 -0
  82. package/dist/migration-list-types-DS63IdFd.d.mts +23 -0
  83. package/dist/migration-list-types-DS63IdFd.d.mts.map +1 -0
  84. package/dist/migration-log-CW0EjxSr.mjs +215 -0
  85. package/dist/migration-log-CW0EjxSr.mjs.map +1 -0
  86. package/dist/migration-path-target-DqcrbOis.mjs +24 -0
  87. package/dist/migration-path-target-DqcrbOis.mjs.map +1 -0
  88. package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-NHdlUwPG.mjs} +5 -6
  89. package/dist/{migration-plan-9DJ7q7_z.mjs.map → migration-plan-NHdlUwPG.mjs.map} +1 -1
  90. package/dist/migration-status-GZ6XfbWs.mjs +439 -0
  91. package/dist/migration-status-GZ6XfbWs.mjs.map +1 -0
  92. package/dist/{output-B60Gw5fu.mjs → output-CF_hqzI-.mjs} +1 -1
  93. package/dist/{output-B60Gw5fu.mjs.map → output-CF_hqzI-.mjs.map} +1 -1
  94. package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-CJY9zOv7.mjs} +1 -1
  95. package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-CJY9zOv7.mjs.map} +1 -1
  96. package/dist/telemetry-DQP0BvKv.mjs +122 -0
  97. package/dist/telemetry-DQP0BvKv.mjs.map +1 -0
  98. package/dist/{types-Dt_SfqFm.d.mts → types-Cculk5KV.d.mts} +44 -31
  99. package/dist/types-Cculk5KV.d.mts.map +1 -0
  100. package/dist/{verify-DCA9Sldu.mjs → verify-tvHRBBVP.mjs} +2 -2
  101. package/dist/{verify-DCA9Sldu.mjs.map → verify-tvHRBBVP.mjs.map} +1 -1
  102. package/package.json +11 -12
  103. package/dist/client-KgJorIvG.mjs.map +0 -1
  104. package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
  105. package/dist/commands/migration-list.mjs.map +0 -1
  106. package/dist/commands/migration-log.mjs.map +0 -1
  107. package/dist/commands/migration-status.mjs.map +0 -1
  108. package/dist/extension-pack-inputs-IDvjRCi3.mjs +0 -62
  109. package/dist/extension-pack-inputs-IDvjRCi3.mjs.map +0 -1
  110. package/dist/graph-render-rFAqZujX.mjs +0 -1081
  111. package/dist/graph-render-rFAqZujX.mjs.map +0 -1
  112. package/dist/init-Cv9UzWL5.mjs.map +0 -1
  113. package/dist/migration-check-BiBJoYYW.mjs.map +0 -1
  114. package/dist/migration-graph-D7DVUElV.mjs +0 -1232
  115. package/dist/migration-graph-D7DVUElV.mjs.map +0 -1
  116. package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
  117. package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
  118. package/dist/migration-types-D2FW63pr.d.mts +0 -15
  119. package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
  120. package/dist/migrations-Cv2jxNNK.mjs +0 -228
  121. package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
  122. package/dist/types-Dt_SfqFm.d.mts.map +0 -1
@@ -1,1232 +0,0 @@
1
- import { t as loadConfig } from "./config-loader-B6sJjXTv.mjs";
2
- import { T as formatStyledHeader, _ as createTerminalUI, d as setCommandSeeAlso, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, s as resolveMigrationPaths, t as addGlobalOptions, u as setCommandExamples, y as handleResult } from "./command-helpers-Bbw1GbwL.mjs";
3
- import { r as buildReadAggregate } from "./contract-space-aggregate-loader-DvZwdkrr.mjs";
4
- import { i as migrationGraphToRenderInput, n as graphRenderer } from "./graph-render-rFAqZujX.mjs";
5
- import { a as migrationListEmptySource, n as createAnsiMigrationListStyler, o as migrationListForwardArrow, s as classifyMigrationGraphTopology, t as CONTRACT_MARKER_NAME } from "./migration-list-styler-BRwF4-gy.mjs";
6
- import { Command } from "commander";
7
- import { ok } from "@prisma-next/utils/result";
8
- import { bold } from "colorette";
9
- import stringWidth from "string-width";
10
- import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
11
- //#region src/utils/formatters/migration-graph-layout.ts
12
- function forwardEdges(edges) {
13
- return edges.filter((e) => e.kind === "forward");
14
- }
15
- function buildForwardProducersByTo(edges) {
16
- const byTo = /* @__PURE__ */ new Map();
17
- for (const edge of edges) {
18
- if (edge.kind !== "forward") continue;
19
- const bucket = byTo.get(edge.to);
20
- if (bucket) bucket.push(edge);
21
- else byTo.set(edge.to, [edge]);
22
- }
23
- return byTo;
24
- }
25
- function buildForwardOutDegree(edges) {
26
- const out = /* @__PURE__ */ new Map();
27
- for (const edge of edges) {
28
- if (edge.kind !== "forward" || edge.from === edge.to) continue;
29
- out.set(edge.from, (out.get(edge.from) ?? 0) + 1);
30
- }
31
- return out;
32
- }
33
- function buildForwardInDegree(edges) {
34
- const indeg = /* @__PURE__ */ new Map();
35
- for (const edge of forwardEdges(edges)) {
36
- if (edge.from === edge.to) continue;
37
- indeg.set(edge.to, (indeg.get(edge.to) ?? 0) + 1);
38
- }
39
- return indeg;
40
- }
41
- /**
42
- * Distinct source contracts among a contract's forward producers. A contract is
43
- * a *convergence* when this count is >= 2. Multiple migrations sharing one
44
- * source (a multi-edge) count once — they stack in a single lane rather than
45
- * fanning into a convergence.
46
- */
47
- function buildDistinctSourceCountByTo(edges) {
48
- const sources = /* @__PURE__ */ new Map();
49
- for (const edge of edges) {
50
- if (edge.kind !== "forward" || edge.from === edge.to) continue;
51
- const set = sources.get(edge.to);
52
- if (set) set.add(edge.from);
53
- else sources.set(edge.to, new Set([edge.from]));
54
- }
55
- const counts = /* @__PURE__ */ new Map();
56
- for (const [to, set] of sources) counts.set(to, set.size);
57
- return counts;
58
- }
59
- function splitComponents(nodes) {
60
- const components = [];
61
- let current = [];
62
- for (const node of nodes) {
63
- if (node === null) {
64
- if (current.length > 0) {
65
- components.push(current);
66
- current = [];
67
- }
68
- continue;
69
- }
70
- current.push(node);
71
- }
72
- if (current.length > 0) components.push(current);
73
- return components;
74
- }
75
- function classifyForwardShortConvergenceAdjacency(rows, edgeRowIndex, edge, laneIndex) {
76
- for (let index = edgeRowIndex + 1; index < rows.length; index++) {
77
- const row = rows[index];
78
- if (row === void 0) break;
79
- if (row.kind === "component-separator" || row.kind === "branch-connector") continue;
80
- if (row.kind === "merge-connector") continue;
81
- if (row.kind === "edge") {
82
- if (row.laneIndex === laneIndex) return "node-skipping-forward";
83
- continue;
84
- }
85
- if (row.kind === "node" && row.contractHash === edge.from) return "adjacent";
86
- }
87
- return "node-skipping-forward";
88
- }
89
- function convergenceProducerUsesShortAdjacency(edge, laneIndex, forwardProducersByTo, producerLaneByHash) {
90
- const producers = (forwardProducersByTo.get(edge.to) ?? []).filter((candidate) => candidate.kind === "forward");
91
- if (producers.length < 2) return false;
92
- const fanStart = [...new Set(producers.map((producer) => producerLaneByHash.get(producer.migrationHash)).filter((candidate) => candidate !== void 0))].sort((a, b) => a - b)[0];
93
- if (fanStart === void 0) return false;
94
- return laneIndex === fanStart;
95
- }
96
- function classifyForwardLayoutAdjacency(rows, edgeRowIndex, edge, laneIndex, passThroughLanes, nodeColumn, convergenceProducer, divergenceBranchEdge) {
97
- let sawObstruction = false;
98
- const passThroughLaneSet = new Set(passThroughLanes);
99
- for (let index = edgeRowIndex + 1; index < rows.length; index++) {
100
- const row = rows[index];
101
- if (row === void 0) break;
102
- if (row.kind === "component-separator") continue;
103
- if (row.kind === "merge-connector") {
104
- if (convergenceProducer) {
105
- if (row.contractHash === edge.from) sawObstruction = true;
106
- } else if (!divergenceBranchEdge && row.contractHash !== edge.from) sawObstruction = true;
107
- continue;
108
- }
109
- if (row.kind === "branch-connector") continue;
110
- if (row.kind === "edge") {
111
- if (row.laneIndex === laneIndex) return "node-skipping-forward";
112
- if (!divergenceBranchEdge && row.edge !== void 0 && row.edge.to !== edge.to) sawObstruction = true;
113
- continue;
114
- }
115
- if (row.kind === "node" && row.contractHash !== void 0) {
116
- if (row.contractHash === edge.from) return sawObstruction ? "node-skipping-forward" : "adjacent";
117
- const nodeCol = nodeColumn.get(row.contractHash) ?? 0;
118
- if (!divergenceBranchEdge && !passThroughLaneSet.has(nodeCol)) sawObstruction = true;
119
- }
120
- }
121
- return "node-skipping-forward";
122
- }
123
- function classifyLayoutAdjacency(rows, edgeRowIndex, edge, laneIndex, passThroughLanes, nodeColumn, position, forwardInDegree, convergenceProducer, divergenceBranchEdge) {
124
- if (edge.kind === "self") return "adjacent";
125
- const fromPos = position.get(edge.from);
126
- const toPos = position.get(edge.to);
127
- if (edge.kind === "forward") {
128
- if ((forwardInDegree.get(edge.to) ?? 0) <= 1 && fromPos !== void 0 && toPos !== void 0 && fromPos === toPos + 1) return "adjacent";
129
- return classifyForwardLayoutAdjacency(rows, edgeRowIndex, edge, laneIndex, passThroughLanes, nodeColumn, convergenceProducer, divergenceBranchEdge);
130
- }
131
- if (fromPos !== void 0 && toPos !== void 0 && toPos === fromPos + 1) return "adjacent";
132
- for (let index = edgeRowIndex + 1; index < rows.length; index++) {
133
- const row = rows[index];
134
- if (row === void 0) break;
135
- if (row.kind === "component-separator" || row.kind === "branch-connector" || row.kind === "merge-connector") continue;
136
- if (row.kind === "edge") continue;
137
- if (row.kind === "node") return row.contractHash === edge.to ? "adjacent" : "node-skipping-rollback";
138
- }
139
- return "node-skipping-rollback";
140
- }
141
- function refineAdjacency(rows, nodeColumn, position, forwardInDegree, forwardOutDegree, edges, producerLaneByHash) {
142
- const forwardProducersByTo = buildForwardProducersByTo(edges);
143
- function branchLaneForEdge(producer) {
144
- const children = edges.filter((edge) => edge.from === producer.from && edge.kind === "forward" && edge.from !== edge.to);
145
- if (children.length < 2) return void 0;
146
- const index = children.findIndex((child) => child.migrationHash === producer.migrationHash);
147
- return index >= 0 ? index : void 0;
148
- }
149
- return rows.map((row, rowIndex) => {
150
- if (row.kind !== "edge" || row.edge === void 0 || row.laneIndex === void 0) return row;
151
- const divergenceBranchEdge = row.edge.kind === "forward" && !(row.convergenceProducer ?? false) && (forwardOutDegree.get(row.edge.from) ?? 0) >= 2 && branchLaneForEdge(row.edge) !== void 0;
152
- const adjacency = row.convergenceProducer === true && convergenceProducerUsesShortAdjacency(row.edge, row.laneIndex, forwardProducersByTo, producerLaneByHash) ? classifyForwardShortConvergenceAdjacency(rows, rowIndex, row.edge, row.laneIndex) : classifyLayoutAdjacency(rows, rowIndex, row.edge, row.laneIndex, row.passThroughLanes ?? [], nodeColumn, position, forwardInDegree, row.convergenceProducer ?? false, divergenceBranchEdge);
153
- return {
154
- ...row,
155
- cells: buildEdgeCells(row.edge, row.laneIndex, row.passThroughLanes ?? [], adjacency, row.cells.length)
156
- };
157
- });
158
- }
159
- function classifyEdgeAdjacency(edge, position) {
160
- if (edge.kind === "self") return "adjacent";
161
- const fromPos = position.get(edge.from);
162
- const toPos = position.get(edge.to);
163
- if (fromPos === void 0 || toPos === void 0) return "adjacent";
164
- if (edge.kind === "forward") {
165
- if (toPos >= fromPos) return "adjacent";
166
- return fromPos === toPos + 1 ? "adjacent" : "node-skipping-forward";
167
- }
168
- if (toPos <= fromPos) return "adjacent";
169
- return toPos === fromPos + 1 ? "adjacent" : "node-skipping-rollback";
170
- }
171
- function emptyCells(width) {
172
- return Array.from({ length: width }, () => ({ kind: "empty" }));
173
- }
174
- function buildBranchConnectorCells(startLane, endLane, activeLanes, gridWidth) {
175
- const cells = emptyCells(gridWidth);
176
- for (let lane = 0; lane < gridWidth; lane++) {
177
- if (activeLanes.has(lane) && (lane < startLane || lane > endLane)) {
178
- cells[lane] = { kind: "vertical-pass" };
179
- continue;
180
- }
181
- if (lane === startLane) cells[lane] = { kind: "branch-tee" };
182
- else if (lane === endLane) cells[lane] = { kind: "branch-corner" };
183
- else if (lane > startLane && lane < endLane) cells[lane] = { kind: "branch-tee" };
184
- }
185
- return cells;
186
- }
187
- function buildMergeConnectorCells(startLane, endLane, activeLanes, gridWidth) {
188
- const cells = emptyCells(gridWidth);
189
- for (let lane = 0; lane < gridWidth; lane++) {
190
- if (activeLanes.has(lane) && (lane < startLane || lane > endLane)) {
191
- cells[lane] = { kind: "vertical-pass" };
192
- continue;
193
- }
194
- if (lane === startLane) cells[lane] = { kind: "merge-tee" };
195
- else if (lane === endLane) cells[lane] = { kind: "merge-corner" };
196
- else if (lane > startLane && lane < endLane) cells[lane] = activeLanes.has(lane) ? { kind: "merge-tee" } : { kind: "horizontal-pass" };
197
- }
198
- return cells;
199
- }
200
- function buildNodeCells(contractHash, nodeColumn, activeLanes, gridWidth) {
201
- const cells = emptyCells(gridWidth);
202
- for (const lane of activeLanes) if (lane !== nodeColumn && lane < gridWidth) cells[lane] = { kind: "vertical-pass" };
203
- if (nodeColumn < gridWidth) cells[nodeColumn] = {
204
- kind: "node",
205
- contractHash
206
- };
207
- return cells;
208
- }
209
- function buildEdgeCells(edge, laneIndex, passThroughLanes, adjacency, gridWidth) {
210
- const cells = emptyCells(gridWidth);
211
- for (const lane of passThroughLanes) if (lane < gridWidth) cells[lane] = { kind: "vertical-pass" };
212
- if (laneIndex < gridWidth) cells[laneIndex] = {
213
- kind: "edge-lane",
214
- migrationHash: edge.migrationHash,
215
- edgeKind: edge.kind,
216
- ownsLabel: true,
217
- adjacency
218
- };
219
- return cells;
220
- }
221
- /**
222
- * Compute the vertical node order for a component: tips at the top (index 0),
223
- * roots at the bottom. This is a DFS post-order over forward edges starting
224
- * from forward roots, visiting children in their input (insertion) order. A
225
- * node is emitted only after all of its forward children, so convergence nodes
226
- * sit below every branch that feeds them and the longest contiguous chain reads
227
- * top-to-bottom without braiding.
228
- */
229
- function computeVerticalOrder(componentNodes, forwardChildren, forwardInDegree) {
230
- const WHITE = 0;
231
- const GRAY = 1;
232
- const BLACK = 2;
233
- const color = /* @__PURE__ */ new Map();
234
- for (const node of componentNodes) color.set(node, WHITE);
235
- const sortRoots = (roots) => [...roots].sort((a, b) => {
236
- if (a === EMPTY_CONTRACT_HASH) return -1;
237
- if (b === EMPTY_CONTRACT_HASH) return 1;
238
- return a.localeCompare(b);
239
- });
240
- let roots = sortRoots(componentNodes.filter((n) => (forwardInDegree.get(n) ?? 0) === 0));
241
- if (roots.length === 0) roots = sortRoots(componentNodes);
242
- const result = [];
243
- function runDfs(root) {
244
- if (color.get(root) !== WHITE) return;
245
- const stack = [{
246
- node: root,
247
- children: forwardChildren.get(root) ?? [],
248
- index: 0
249
- }];
250
- color.set(root, GRAY);
251
- while (stack.length > 0) {
252
- const frame = stack[stack.length - 1];
253
- if (frame === void 0) break;
254
- if (frame.index >= frame.children.length) {
255
- color.set(frame.node, BLACK);
256
- result.push(frame.node);
257
- stack.pop();
258
- continue;
259
- }
260
- const child = frame.children[frame.index];
261
- frame.index += 1;
262
- if (child === void 0) continue;
263
- if (color.get(child.to) === WHITE) {
264
- color.set(child.to, GRAY);
265
- stack.push({
266
- node: child.to,
267
- children: forwardChildren.get(child.to) ?? [],
268
- index: 0
269
- });
270
- }
271
- }
272
- }
273
- for (const root of roots) runDfs(root);
274
- for (const node of componentNodes) if (color.get(node) === WHITE) runDfs(node);
275
- return result;
276
- }
277
- function rollbackSpan(edge, position) {
278
- const top = position.get(edge.from) ?? 0;
279
- return {
280
- top,
281
- bottom: position.get(edge.to) ?? top
282
- };
283
- }
284
- function spansOverlap(a, b) {
285
- return a.top <= b.bottom && b.top <= a.bottom;
286
- }
287
- function forwardMaxLane(rows, skipMigrationHashes) {
288
- let max = 0;
289
- for (const row of rows) {
290
- if (row.kind === "edge" && row.edge !== void 0 && skipMigrationHashes.has(row.edge.migrationHash)) continue;
291
- max = Math.max(max, row.laneIndex ?? 0);
292
- for (const lane of row.passThroughLanes ?? []) max = Math.max(max, lane);
293
- if (row.startLane !== void 0) max = Math.max(max, row.startLane, row.endLane ?? row.startLane);
294
- }
295
- return max;
296
- }
297
- function allocateSkipRollbackBackLanes(skipRollbacks, position, forwardMax) {
298
- const sorted = [...skipRollbacks].sort((a, b) => {
299
- const aTop = position.get(a.from) ?? 0;
300
- const bTop = position.get(b.from) ?? 0;
301
- if (aTop !== bTop) return aTop - bTop;
302
- return b.dirName.localeCompare(a.dirName);
303
- });
304
- const occupied = [];
305
- const lanes = /* @__PURE__ */ new Map();
306
- let nextLane = forwardMax + 1;
307
- for (const edge of sorted) {
308
- const span = rollbackSpan(edge, position);
309
- let lane = nextLane;
310
- while (occupied.some((entry) => entry.lane === lane && spansOverlap(entry, span))) lane += 1;
311
- occupied.push({
312
- ...span,
313
- lane
314
- });
315
- lanes.set(edge.migrationHash, lane);
316
- nextLane = Math.max(nextLane, lane + 1);
317
- }
318
- return lanes;
319
- }
320
- function findNodeRowIndex(rows, contractHash) {
321
- return rows.findIndex((row) => row.kind === "node" && row.contractHash === contractHash);
322
- }
323
- function findEdgeRowIndex(rows, migrationHash) {
324
- return rows.findIndex((row) => row.kind === "edge" && row.edge?.migrationHash === migrationHash);
325
- }
326
- function ensureCellWidth(cells, width) {
327
- while (cells.length < width) cells.push({ kind: "empty" });
328
- }
329
- function cloneRow(row) {
330
- return {
331
- ...row,
332
- cells: [...row.cells]
333
- };
334
- }
335
- function routeCrossesRow(route, rowIndex, rows) {
336
- const sourceRow = findNodeRowIndex(rows, route.edge.from);
337
- const targetRow = findNodeRowIndex(rows, route.edge.to);
338
- if (sourceRow < 0 || targetRow < 0) return false;
339
- return rowIndex > sourceRow && rowIndex <= targetRow;
340
- }
341
- function applySkipRollbackRouting(rows, skipRollbacks, position, nodeColumn, edgeColumn) {
342
- if (skipRollbacks.length === 0) return [...rows];
343
- const forwardMax = forwardMaxLane(rows, new Set(skipRollbacks.map((edge) => edge.migrationHash)));
344
- const backLaneByHash = allocateSkipRollbackBackLanes(skipRollbacks, position, forwardMax);
345
- const routes = skipRollbacks.map((edge) => ({
346
- edge,
347
- backLane: backLaneByHash.get(edge.migrationHash) ?? forwardMax + 1
348
- }));
349
- const result = rows.map(cloneRow);
350
- for (const route of routes) {
351
- const { edge, backLane } = route;
352
- const nodeCol = nodeColumn.get(edge.from) ?? 0;
353
- const targetCol = nodeColumn.get(edge.to) ?? 0;
354
- const sourceRowIndex = findNodeRowIndex(result, edge.from);
355
- const targetRowIndex = findNodeRowIndex(result, edge.to);
356
- const edgeRowIndex = findEdgeRowIndex(result, edge.migrationHash);
357
- if (sourceRowIndex < 0 || targetRowIndex < 0 || edgeRowIndex < 0) continue;
358
- edgeColumn.set(edge.migrationHash, backLane);
359
- const coSourcedLanes = routes.filter((other) => other.edge.from === edge.from).map((other) => other.backLane);
360
- const maxCoSourcedLane = Math.max(...coSourcedLanes);
361
- const sourceRow = result[sourceRowIndex];
362
- if (sourceRow !== void 0) {
363
- const cells = sourceRow.cells;
364
- ensureCellWidth(cells, backLane + 1);
365
- cells[nodeCol] = {
366
- kind: "node",
367
- contractHash: sourceRow.contractHash ?? EMPTY_CONTRACT_HASH,
368
- arcTee: true
369
- };
370
- for (let lane = nodeCol + 1; lane < backLane; lane += 1) {
371
- if (coSourcedLanes.includes(lane)) {
372
- cells[lane] = { kind: "arc-branch-tee" };
373
- continue;
374
- }
375
- const existing = cells[lane];
376
- cells[lane] = existing !== void 0 && existing.kind !== "empty" && existing.kind !== "horizontal-pass" && existing.kind !== "arc-land-bridge" || routes.some((other) => other.edge.migrationHash !== edge.migrationHash && other.backLane === lane && routeCrossesRow(other, sourceRowIndex, result)) ? { kind: "arc-crossing" } : { kind: "horizontal-pass" };
377
- }
378
- cells[backLane] = backLane < maxCoSourcedLane ? { kind: "arc-branch-tee" } : { kind: "arc-branch-corner" };
379
- }
380
- const edgeRow = result[edgeRowIndex];
381
- if (edgeRow !== void 0) {
382
- const cells = edgeRow.cells;
383
- ensureCellWidth(cells, backLane + 1);
384
- cells[nodeCol] = { kind: "vertical-pass" };
385
- cells[backLane] = {
386
- kind: "edge-lane",
387
- migrationHash: edge.migrationHash,
388
- edgeKind: edge.kind,
389
- ownsLabel: true,
390
- adjacency: "node-skipping-rollback"
391
- };
392
- result[edgeRowIndex] = {
393
- ...edgeRow,
394
- laneIndex: backLane,
395
- passThroughLanes: [nodeCol]
396
- };
397
- }
398
- for (let index = sourceRowIndex + 1; index < targetRowIndex; index += 1) {
399
- if (index === edgeRowIndex) continue;
400
- const row = result[index];
401
- if (row === void 0) continue;
402
- const cells = row.cells;
403
- ensureCellWidth(cells, backLane + 1);
404
- const existing = cells[backLane];
405
- if (existing?.kind !== "arc-land-corner" && existing?.kind !== "arc-land-bridge" && existing?.kind !== "arc-branch-corner" && existing?.kind !== "arc-branch-tee" && existing?.kind !== "arc-crossing") cells[backLane] = { kind: "vertical-pass" };
406
- }
407
- const targetRow = result[targetRowIndex];
408
- if (targetRow !== void 0) {
409
- const cells = targetRow.cells;
410
- ensureCellWidth(cells, backLane + 1);
411
- cells[targetCol] = {
412
- kind: "node",
413
- contractHash: targetRow.contractHash ?? EMPTY_CONTRACT_HASH,
414
- arcLand: true
415
- };
416
- for (let lane = targetCol + 1; lane < backLane; lane += 1) {
417
- const existing = cells[lane];
418
- cells[lane] = existing !== void 0 && existing.kind !== "empty" && existing.kind !== "horizontal-pass" && existing.kind !== "arc-land-bridge" || routes.some((other) => other.edge.migrationHash !== edge.migrationHash && other.backLane === lane && routeCrossesRow(other, targetRowIndex, result)) ? { kind: "arc-crossing" } : { kind: "arc-land-bridge" };
419
- }
420
- cells[backLane] = { kind: "arc-land-corner" };
421
- for (const other of routes) {
422
- if (other.backLane <= backLane) continue;
423
- if (!routeCrossesRow(other, targetRowIndex, result)) continue;
424
- ensureCellWidth(cells, other.backLane + 1);
425
- const existing = cells[other.backLane];
426
- if (existing?.kind !== "arc-land-corner" && existing?.kind !== "arc-land-bridge" && existing?.kind !== "node") cells[other.backLane] = { kind: "vertical-pass" };
427
- }
428
- }
429
- }
430
- return result;
431
- }
432
- function collectNodeSkippingRollbacks(edges, position) {
433
- return edges.filter((edge) => edge.kind === "rollback" && classifyEdgeAdjacency(edge, position) === "node-skipping-rollback");
434
- }
435
- function layoutComponent(componentNodes, allEdges) {
436
- const componentSet = new Set(componentNodes);
437
- const edges = allEdges.filter((e) => componentSet.has(e.from) && componentSet.has(e.to));
438
- const forwardChildren = /* @__PURE__ */ new Map();
439
- const producersByTo = /* @__PURE__ */ new Map();
440
- const rollbacksByFrom = /* @__PURE__ */ new Map();
441
- const selfByFrom = /* @__PURE__ */ new Map();
442
- for (const edge of edges) {
443
- if (edge.kind === "self" || edge.from === edge.to) {
444
- const bucket = selfByFrom.get(edge.from);
445
- if (bucket) bucket.push(edge);
446
- else selfByFrom.set(edge.from, [edge]);
447
- continue;
448
- }
449
- if (edge.kind === "forward") {
450
- const children = forwardChildren.get(edge.from);
451
- if (children) children.push(edge);
452
- else forwardChildren.set(edge.from, [edge]);
453
- const producers = producersByTo.get(edge.to);
454
- if (producers) producers.push(edge);
455
- else producersByTo.set(edge.to, [edge]);
456
- continue;
457
- }
458
- const bucket = rollbacksByFrom.get(edge.from);
459
- if (bucket) bucket.push(edge);
460
- else rollbacksByFrom.set(edge.from, [edge]);
461
- }
462
- const forwardInDegree = buildForwardInDegree(edges);
463
- const forwardOutDegree = buildForwardOutDegree(edges);
464
- const distinctSourceCountByTo = buildDistinctSourceCountByTo(edges);
465
- const order = computeVerticalOrder(componentNodes, forwardChildren, forwardInDegree);
466
- const position = /* @__PURE__ */ new Map();
467
- for (let index = 0; index < order.length; index++) {
468
- const node = order[index];
469
- if (node !== void 0) position.set(node, index);
470
- }
471
- const lanes = [];
472
- const rows = [];
473
- const nodeColumn = /* @__PURE__ */ new Map();
474
- const edgeColumn = /* @__PURE__ */ new Map();
475
- const producerLaneByHash = /* @__PURE__ */ new Map();
476
- let gridWidth = 1;
477
- function ensureGridWidth(minWidth) {
478
- if (minWidth > gridWidth) gridWidth = minWidth;
479
- }
480
- function setLane(index, want) {
481
- while (lanes.length <= index) lanes.push(null);
482
- lanes[index] = want;
483
- if (want !== null) ensureGridWidth(index + 1);
484
- }
485
- function activeLaneIndices() {
486
- const indices = [];
487
- for (let index = 0; index < lanes.length; index++) if (lanes[index] !== null) indices.push(index);
488
- return indices;
489
- }
490
- function passThroughExcept(lane) {
491
- return activeLaneIndices().filter((index) => index !== lane);
492
- }
493
- function leftmostFreeLane() {
494
- for (let index = 0; index < lanes.length; index++) if (lanes[index] === null) return index;
495
- return lanes.length;
496
- }
497
- function lanesWanting(contract) {
498
- const indices = [];
499
- for (let index = 0; index < lanes.length; index++) if (lanes[index] === contract) indices.push(index);
500
- return indices;
501
- }
502
- function emitMergeConnector(contractHash, laneIndices) {
503
- const startLane = Math.min(...laneIndices);
504
- const endLane = Math.max(...laneIndices);
505
- ensureGridWidth(endLane + 1);
506
- const activeLanes = new Set(activeLaneIndices());
507
- rows.push({
508
- kind: "merge-connector",
509
- contractHash,
510
- startLane,
511
- endLane,
512
- branchCount: laneIndices.length,
513
- cells: buildMergeConnectorCells(startLane, endLane, activeLanes, gridWidth)
514
- });
515
- for (const index of laneIndices) if (index !== startLane) setLane(index, null);
516
- return startLane;
517
- }
518
- function emitBranchConnector(contractHash, startLane, endLane, branchCount) {
519
- ensureGridWidth(endLane + 1);
520
- const activeLanes = new Set(activeLaneIndices());
521
- rows.push({
522
- kind: "branch-connector",
523
- contractHash,
524
- startLane,
525
- endLane,
526
- branchCount,
527
- cells: buildBranchConnectorCells(startLane, endLane, activeLanes, gridWidth)
528
- });
529
- }
530
- function emitEdgeRow(edge, lane, convergenceProducer) {
531
- const passThrough = passThroughExcept(lane);
532
- const adjacency = classifyEdgeAdjacency(edge, position);
533
- ensureGridWidth(Math.max(lane, ...passThrough, 0) + 1);
534
- const row = {
535
- kind: "edge",
536
- edge,
537
- laneIndex: lane,
538
- passThroughLanes: passThrough,
539
- cells: buildEdgeCells(edge, lane, passThrough, adjacency, gridWidth)
540
- };
541
- rows.push(convergenceProducer ? {
542
- ...row,
543
- convergenceProducer: true
544
- } : row);
545
- edgeColumn.set(edge.migrationHash, lane);
546
- if (convergenceProducer) producerLaneByHash.set(edge.migrationHash, lane);
547
- }
548
- function emitNodeRow(contractHash, column) {
549
- ensureGridWidth(column + 1);
550
- const passThrough = activeLaneIndices().filter((index) => index !== column);
551
- rows.push({
552
- kind: "node",
553
- contractHash,
554
- cells: buildNodeCells(contractHash, column, passThrough, gridWidth)
555
- });
556
- nodeColumn.set(contractHash, column);
557
- }
558
- function producerGroups(node) {
559
- const byTarget = /* @__PURE__ */ new Map();
560
- for (const producer of producersByTo.get(node) ?? []) {
561
- const group = byTarget.get(producer.from);
562
- if (group) group.edges.push(producer);
563
- else byTarget.set(producer.from, {
564
- target: producer.from,
565
- edges: [producer]
566
- });
567
- }
568
- const groups = [...byTarget.values()];
569
- groups.sort((a, b) => (position.get(a.target) ?? 0) - (position.get(b.target) ?? 0));
570
- for (const group of groups) group.edges.sort((a, b) => b.dirName.localeCompare(a.dirName));
571
- return groups;
572
- }
573
- function processNode(node) {
574
- const wanting = lanesWanting(node);
575
- let column;
576
- if (wanting.length >= 2) column = emitMergeConnector(node, wanting);
577
- else if (wanting.length === 1) column = wanting[0] ?? 0;
578
- else column = leftmostFreeLane();
579
- const selfEdges = [...selfByFrom.get(node) ?? []].sort((a, b) => b.dirName.localeCompare(a.dirName));
580
- for (const selfEdge of selfEdges) emitEdgeRow(selfEdge, column, false);
581
- emitNodeRow(node, column);
582
- const rollbacks = [...rollbacksByFrom.get(node) ?? []].sort((a, b) => b.dirName.localeCompare(a.dirName));
583
- const skipRollbacks = [];
584
- const adjacentRollbacks = [];
585
- for (const rollback of rollbacks) if (classifyEdgeAdjacency(rollback, position) === "node-skipping-rollback") skipRollbacks.push(rollback);
586
- else adjacentRollbacks.push(rollback);
587
- for (const rollback of skipRollbacks) emitEdgeRow(rollback, column, false);
588
- const groups = producerGroups(node);
589
- const isConvergence = (distinctSourceCountByTo.get(node) ?? 0) >= 2;
590
- const laneForGroup = [];
591
- for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
592
- const group = groups[groupIndex];
593
- if (group === void 0) continue;
594
- const lane = groupIndex === 0 ? column : leftmostFreeLane();
595
- laneForGroup[groupIndex] = lane;
596
- setLane(lane, group.target);
597
- }
598
- if (groups.length >= 2) {
599
- const endLane = Math.max(...laneForGroup);
600
- emitBranchConnector(node, column, endLane, groups.length);
601
- }
602
- for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
603
- const group = groups[groupIndex];
604
- const lane = laneForGroup[groupIndex];
605
- if (group === void 0 || lane === void 0) continue;
606
- for (const edge of group.edges) emitEdgeRow(edge, lane, isConvergence);
607
- }
608
- for (const rollback of adjacentRollbacks) emitEdgeRow(rollback, column, false);
609
- if (groups.length === 0) setLane(column, null);
610
- }
611
- for (const node of order) processNode(node);
612
- return {
613
- rows: applySkipRollbackRouting(refineAdjacency(rows, nodeColumn, position, forwardInDegree, forwardOutDegree, edges, producerLaneByHash), collectNodeSkippingRollbacks(edges, position), position, nodeColumn, edgeColumn),
614
- nodeColumn,
615
- edgeColumn
616
- };
617
- }
618
- function buildMigrationGraphLayout(rowModel) {
619
- if (rowModel.nodes.length === 0) return {
620
- rows: [],
621
- nodeColumn: /* @__PURE__ */ new Map(),
622
- edgeColumn: /* @__PURE__ */ new Map()
623
- };
624
- const components = splitComponents(rowModel.nodes);
625
- const allRows = [];
626
- const nodeColumn = /* @__PURE__ */ new Map();
627
- const edgeColumn = /* @__PURE__ */ new Map();
628
- for (let componentIndex = 0; componentIndex < components.length; componentIndex++) {
629
- if (componentIndex > 0) allRows.push({
630
- kind: "component-separator",
631
- cells: []
632
- });
633
- const component = components[componentIndex];
634
- if (component === void 0 || component.length === 0) continue;
635
- const result = layoutComponent(component, rowModel.edges);
636
- allRows.push(...result.rows);
637
- for (const [hash, column] of result.nodeColumn) nodeColumn.set(hash, column);
638
- for (const [hash, column] of result.edgeColumn) edgeColumn.set(hash, column);
639
- }
640
- return {
641
- rows: allRows,
642
- nodeColumn,
643
- edgeColumn
644
- };
645
- }
646
- //#endregion
647
- //#region src/utils/formatters/migration-graph-rows.ts
648
- /**
649
- * Return the weakly-connected components of `graph` as an array of node sets,
650
- * ordered so the component containing EMPTY_CONTRACT_HASH comes first (if
651
- * present), with remaining components sorted by their lex-smallest node hash.
652
- */
653
- function weaklyConnectedComponents(graph) {
654
- const visited = /* @__PURE__ */ new Set();
655
- const adjacency = /* @__PURE__ */ new Map();
656
- function addAdjacent(a, b) {
657
- const aList = adjacency.get(a);
658
- if (aList) aList.push(b);
659
- else adjacency.set(a, [b]);
660
- const bList = adjacency.get(b);
661
- if (bList) bList.push(a);
662
- else adjacency.set(b, [a]);
663
- }
664
- for (const edges of graph.forwardChain.values()) for (const edge of edges) if (edge.from !== edge.to) addAdjacent(edge.from, edge.to);
665
- for (const node of graph.nodes) if (!adjacency.has(node)) adjacency.set(node, []);
666
- const components = [];
667
- function bfsComponent(start) {
668
- const component = /* @__PURE__ */ new Set();
669
- const queue = [start];
670
- while (queue.length > 0) {
671
- const node = queue.shift();
672
- if (node === void 0 || visited.has(node)) continue;
673
- visited.add(node);
674
- component.add(node);
675
- for (const neighbor of adjacency.get(node) ?? []) if (!visited.has(neighbor)) queue.push(neighbor);
676
- }
677
- return component;
678
- }
679
- const allNodes = [...graph.nodes].sort((a, b) => {
680
- if (a === EMPTY_CONTRACT_HASH) return -1;
681
- if (b === EMPTY_CONTRACT_HASH) return 1;
682
- return a.localeCompare(b);
683
- });
684
- for (const node of allNodes) if (!visited.has(node)) components.push(bfsComponent(node));
685
- components.sort((a, b) => {
686
- const aHasEmpty = a.has(EMPTY_CONTRACT_HASH);
687
- const bHasEmpty = b.has(EMPTY_CONTRACT_HASH);
688
- if (aHasEmpty && !bHasEmpty) return -1;
689
- if (!aHasEmpty && bHasEmpty) return 1;
690
- const aMin = [...a].sort((x, y) => x.localeCompare(y))[0] ?? "";
691
- const bMin = [...b].sort((x, y) => x.localeCompare(y))[0] ?? "";
692
- return aMin.localeCompare(bMin);
693
- });
694
- return components;
695
- }
696
- function forwardRootsInComponent(componentNodes, topology) {
697
- const roots = [];
698
- for (const node of componentNodes) if ((topology.forwardInDegree.get(node) ?? 0) === 0) roots.push(node);
699
- roots.sort((a, b) => {
700
- if (a === EMPTY_CONTRACT_HASH) return -1;
701
- if (b === EMPTY_CONTRACT_HASH) return 1;
702
- return a.localeCompare(b);
703
- });
704
- if (roots.length > 0) return roots;
705
- return [...componentNodes].sort((a, b) => {
706
- if (a === EMPTY_CONTRACT_HASH) return -1;
707
- if (b === EMPTY_CONTRACT_HASH) return 1;
708
- return a.localeCompare(b);
709
- });
710
- }
711
- function compareNodesTipsFirst(a, b, rank) {
712
- const rankA = rank.get(a) ?? 0;
713
- const rankB = rank.get(b) ?? 0;
714
- if (rankA !== rankB) return rankB - rankA;
715
- if (a === EMPTY_CONTRACT_HASH) return 1;
716
- if (b === EMPTY_CONTRACT_HASH) return -1;
717
- return a.localeCompare(b);
718
- }
719
- /**
720
- * Layer nodes by longest forward-path rank from forward roots within the
721
- * component. Rank 0 is the root (bottom row); the maximum rank is the tip
722
- * (top row). Emits rank-descending with lex-ascending tie-break among siblings
723
- * at the same rank — stable across edge-insertion order and correct under
724
- * diamonds, cross-links, and rollbacks.
725
- */
726
- function layerNodesByLongestForwardPath(componentNodes, topology, graph) {
727
- const forwardOut = /* @__PURE__ */ new Map();
728
- for (const node of componentNodes) forwardOut.set(node, []);
729
- for (const edges of graph.forwardChain.values()) for (const edge of edges) {
730
- if (!componentNodes.has(edge.from) || !componentNodes.has(edge.to)) continue;
731
- if (edge.from === edge.to) continue;
732
- if (topology.kindByMigrationHash.get(edge.migrationHash) !== "forward") continue;
733
- const bucket = forwardOut.get(edge.from);
734
- if (bucket) bucket.push(edge.to);
735
- }
736
- const roots = forwardRootsInComponent(componentNodes, topology);
737
- const rank = /* @__PURE__ */ new Map();
738
- for (const root of roots) rank.set(root, 0);
739
- const maxPasses = componentNodes.size;
740
- for (let pass = 0; pass < maxPasses; pass++) {
741
- let changed = false;
742
- for (const node of componentNodes) {
743
- const base = rank.get(node);
744
- if (base === void 0) continue;
745
- for (const to of forwardOut.get(node) ?? []) {
746
- const next = base + 1;
747
- if (next > (rank.get(to) ?? -1)) {
748
- rank.set(to, next);
749
- changed = true;
750
- }
751
- }
752
- }
753
- if (!changed) break;
754
- }
755
- for (const node of componentNodes) if (!rank.has(node)) rank.set(node, 0);
756
- return [...componentNodes].sort((a, b) => compareNodesTipsFirst(a, b, rank));
757
- }
758
- /**
759
- * Build the row model from a tolerant `MigrationGraph`.
760
- *
761
- * The row model is the first pure-data stage of the `migration graph` render
762
- * pipeline. It:
763
- * - classifies every edge as `forward`, `rollback`, or `self`;
764
- * - produces a deterministic vertical node ordering (tips at index 0, roots
765
- * at the end) within each weakly-connected component;
766
- * - separates disjoint components with `null` sentinels;
767
- * - optionally prepends a detached current contract as its own single-node
768
- * component when `contractHash` is not already in the graph.
769
- *
770
- * No columns, no lane allocation, no glyphs, no rendering.
771
- */
772
- /**
773
- * Resolve the detached current contract, if any: a real contract (not the
774
- * empty baseline) that no migration on disk produces, so it is absent from
775
- * the graph. Such a contract renders as a floating node rather than
776
- * decorating an existing one. Returns the hash when detached, else undefined.
777
- */
778
- function detachedContractHash(graph, contractHash) {
779
- return contractHash !== void 0 && contractHash !== EMPTY_CONTRACT_HASH && !graph.nodes.has(contractHash) ? contractHash : void 0;
780
- }
781
- function buildMigrationGraphRows(graph, options = {}) {
782
- const emptyModel = {
783
- nodes: [],
784
- edges: [],
785
- edgesByFrom: /* @__PURE__ */ new Map(),
786
- edgesByTo: /* @__PURE__ */ new Map()
787
- };
788
- if (graph.nodes.size === 0) {
789
- const detached = detachedContractHash(graph, options.contractHash);
790
- return detached !== void 0 ? {
791
- ...emptyModel,
792
- nodes: [detached]
793
- } : emptyModel;
794
- }
795
- const topology = classifyMigrationGraphTopology(graph);
796
- const edges = [];
797
- const edgesByFrom = /* @__PURE__ */ new Map();
798
- const edgesByTo = /* @__PURE__ */ new Map();
799
- for (const edgeList of graph.forwardChain.values()) for (const edge of edgeList) {
800
- const kind = topology.kindByMigrationHash.get(edge.migrationHash) ?? "forward";
801
- const classified = {
802
- migrationHash: edge.migrationHash,
803
- from: edge.from,
804
- to: edge.to,
805
- dirName: edge.dirName,
806
- kind
807
- };
808
- edges.push(classified);
809
- const fromBucket = edgesByFrom.get(edge.from);
810
- if (fromBucket) fromBucket.push(classified);
811
- else edgesByFrom.set(edge.from, [classified]);
812
- const toBucket = edgesByTo.get(edge.to);
813
- if (toBucket) toBucket.push(classified);
814
- else edgesByTo.set(edge.to, [classified]);
815
- }
816
- const components = weaklyConnectedComponents(graph);
817
- const nodes = [];
818
- for (let i = 0; i < components.length; i++) {
819
- if (i > 0) nodes.push(null);
820
- const component = components[i];
821
- if (component === void 0) continue;
822
- const ordered = layerNodesByLongestForwardPath(component, topology, graph);
823
- for (const node of ordered) nodes.push(node);
824
- }
825
- const detached = detachedContractHash(graph, options.contractHash);
826
- if (detached !== void 0) {
827
- if (nodes.length > 0) nodes.unshift(null);
828
- nodes.unshift(detached);
829
- }
830
- return {
831
- nodes,
832
- edges,
833
- edgesByFrom,
834
- edgesByTo
835
- };
836
- }
837
- //#endregion
838
- //#region src/utils/formatters/migration-graph-tree-render.ts
839
- const LABEL_GAP = 2;
840
- /**
841
- * The live-database overlay marker. Just another ref as far as styling goes —
842
- * the only emphasized markers are the active ref and the `contract`
843
- * desired-state marker (see {@link CONTRACT_MARKER_NAME}).
844
- */
845
- const DB_MARKER_NAME = "db";
846
- const UNICODE_PALETTE = {
847
- node: "○ ",
848
- arcLand: "○◂",
849
- arcTee: "○─",
850
- verticalPass: "│ ",
851
- branchTee: "├─",
852
- mergeTee: "├─",
853
- branchCorner: "╮ ",
854
- mergeCorner: "╯ ",
855
- arcBranchCorner: "╮ ",
856
- arcBranchTee: "┬─",
857
- arcLandCorner: "╯ ",
858
- arcCrossing: "┼─",
859
- arcLandBridge: "──",
860
- horizontalPass: "──",
861
- connectorBranchTee: "├─",
862
- connectorBranchTeeCo: "┬─",
863
- connectorMergeTeeCo: "┴─",
864
- edgeArrow: {
865
- forward: "↑",
866
- rollback: "↓",
867
- self: "⟲"
868
- },
869
- forwardArrow: migrationListForwardArrow("unicode"),
870
- emptySource: migrationListEmptySource("unicode")
871
- };
872
- const ASCII_PALETTE = {
873
- node: "* ",
874
- arcLand: "*<",
875
- arcTee: "*-",
876
- verticalPass: "| ",
877
- branchTee: "+-",
878
- mergeTee: "+-",
879
- branchCorner: "\\ ",
880
- mergeCorner: "/ ",
881
- arcBranchCorner: "\\ ",
882
- arcBranchTee: "+-",
883
- arcLandCorner: "/ ",
884
- arcCrossing: "+-",
885
- arcLandBridge: "--",
886
- horizontalPass: "--",
887
- connectorBranchTee: "+-",
888
- connectorBranchTeeCo: "+-",
889
- connectorMergeTeeCo: "+-",
890
- edgeArrow: {
891
- forward: "^",
892
- rollback: "v",
893
- self: "@"
894
- },
895
- forwardArrow: migrationListForwardArrow("ascii"),
896
- emptySource: migrationListEmptySource("ascii")
897
- };
898
- function paletteFor(mode) {
899
- return mode === "ascii" ? ASCII_PALETTE : UNICODE_PALETTE;
900
- }
901
- function arrowForEdgeKind(kind, palette) {
902
- return palette.edgeArrow[kind];
903
- }
904
- /**
905
- * A node-marker glyph pair (`○◂`, `○─`, `*<`, `*-`) is the contract node
906
- * marker (`○` / `*`) followed by an arc connector (`◂` / `─` / `<` / `-`).
907
- * The marker is the signal and stays bright (`style.kind`); the connector is
908
- * gutter and stays dim (`style.lane`) — consistent with the plain node marker,
909
- * which is never dimmed.
910
- */
911
- function renderNodeMarkerPair(pair, style) {
912
- return style.kind(pair.slice(0, 1)) + style.lane(pair.slice(1));
913
- }
914
- function renderCellPair(cell, style, palette) {
915
- switch (cell.kind) {
916
- case "node":
917
- if (cell.arcLand === true) return renderNodeMarkerPair(palette.arcLand, style);
918
- if (cell.arcTee === true) return renderNodeMarkerPair(palette.arcTee, style);
919
- return style.kind(palette.node);
920
- case "vertical-pass": return style.lane(palette.verticalPass);
921
- case "edge-lane": return cell.ownsLabel ? style.lane(palette.verticalPass.trimEnd()) + style.kind(arrowForEdgeKind(cell.edgeKind, palette)) : style.lane(palette.verticalPass);
922
- case "branch-tee": return style.lane(palette.branchTee);
923
- case "merge-tee": return style.lane(palette.mergeTee);
924
- case "branch-corner": return style.lane(palette.branchCorner);
925
- case "merge-corner": return style.lane(palette.mergeCorner);
926
- case "arc-branch-corner": return style.lane(palette.arcBranchCorner);
927
- case "arc-branch-tee": return style.lane(palette.arcBranchTee);
928
- case "arc-land-corner": return style.lane(palette.arcLandCorner);
929
- case "arc-crossing": return style.lane(palette.arcCrossing);
930
- case "arc-land-bridge": return style.lane(palette.arcLandBridge);
931
- case "horizontal-pass": return style.lane(palette.horizontalPass);
932
- case "empty": return " ";
933
- }
934
- }
935
- function renderConnectorRow(row, gridWidth, style, palette) {
936
- const isMerge = row.kind === "merge-connector";
937
- if (row.cells.length > 0) {
938
- let seenTee = false;
939
- let out = "";
940
- for (const cell of row.cells) switch (cell.kind) {
941
- case "branch-tee":
942
- out += style.lane(seenTee ? palette.connectorBranchTeeCo : palette.connectorBranchTee);
943
- seenTee = true;
944
- break;
945
- case "merge-tee":
946
- out += style.lane(seenTee ? palette.connectorMergeTeeCo : palette.connectorBranchTee);
947
- seenTee = true;
948
- break;
949
- case "branch-corner":
950
- out += style.lane(palette.branchCorner);
951
- break;
952
- case "merge-corner":
953
- out += style.lane(palette.mergeCorner);
954
- break;
955
- case "vertical-pass":
956
- out += style.lane(palette.verticalPass);
957
- break;
958
- case "horizontal-pass":
959
- out += style.lane(palette.horizontalPass);
960
- break;
961
- default: out += " ";
962
- }
963
- for (let column = row.cells.length; column < gridWidth; column++) out += " ";
964
- return out;
965
- }
966
- const start = row.startLane ?? 0;
967
- const end = row.endLane ?? start;
968
- let out = "";
969
- for (let column = 0; column < gridWidth; column++) if (column < start || column > end) out += " ";
970
- else if (column === start) out += style.lane(palette.connectorBranchTee);
971
- else if (column === end) out += style.lane(isMerge ? palette.mergeCorner : palette.branchCorner);
972
- else out += style.lane(isMerge ? palette.connectorMergeTeeCo : palette.connectorBranchTeeCo);
973
- return out;
974
- }
975
- function abbreviateHash(hash, hashLength, emptySource) {
976
- if (hash === EMPTY_CONTRACT_HASH) return emptySource;
977
- return (hash.startsWith("sha256:") ? hash.slice(7) : hash).slice(0, hashLength);
978
- }
979
- const MIN_HASH_DATA_COLUMN = 25;
980
- function overlayNamesForContract(contractHash, opts) {
981
- const names = [];
982
- const userRefs = opts.refsByHash?.get(contractHash);
983
- if (userRefs) names.push(...[...userRefs].sort((a, b) => a.localeCompare(b)));
984
- if (opts.dbHash === contractHash) names.push(DB_MARKER_NAME);
985
- if (opts.contractHash === contractHash && contractHash !== EMPTY_CONTRACT_HASH) names.push(CONTRACT_MARKER_NAME);
986
- return names;
987
- }
988
- function createTreeStyler(opts) {
989
- const base = createAnsiMigrationListStyler({ useColor: opts.colorize });
990
- const activeRefName = opts.activeRefName;
991
- if (!opts.colorize || activeRefName === void 0) return base;
992
- return {
993
- ...base,
994
- refs: (names) => {
995
- const styledNames = names.map((name) => name === activeRefName ? bold(name) : name);
996
- return base.refs(styledNames);
997
- }
998
- };
999
- }
1000
- function formatEdgeHashColumn(edge, style, hashLength, palette) {
1001
- if (edge.kind === "self") {
1002
- const hash = abbreviateHash(edge.from, hashLength, palette.emptySource);
1003
- return `${style.sourceHash(hash)} ${style.glyph(palette.forwardArrow)} ${style.destHash(hash)}`;
1004
- }
1005
- return `${edge.from === EMPTY_CONTRACT_HASH ? style.glyph(palette.emptySource) + " ".repeat(Math.max(0, hashLength - palette.emptySource.length)) : style.sourceHash(abbreviateHash(edge.from, hashLength, palette.emptySource))} ${style.glyph(palette.forwardArrow)} ${style.destHash(abbreviateHash(edge.to, hashLength, palette.emptySource))}`;
1006
- }
1007
- function padVisible(text, targetWidth) {
1008
- const padding = Math.max(0, targetWidth - stringWidth(text));
1009
- return text + " ".repeat(padding);
1010
- }
1011
- function gridWidthForModel(rows) {
1012
- return rows.reduce((max, row) => row.kind === "node" || row.kind === "edge" ? Math.max(max, row.cells.length) : max, 1);
1013
- }
1014
- function maxDirNameLength(edges) {
1015
- if (edges.length === 0) return 0;
1016
- return Math.max(...edges.map((edge) => edge.dirName.length));
1017
- }
1018
- function rowDirNameWidth(labelColumn, maxDirNameLen, dirNameGap) {
1019
- return Math.max(maxDirNameLen + dirNameGap, MIN_HASH_DATA_COLUMN - labelColumn);
1020
- }
1021
- function gridUsesSkipRollbackArcs(rows) {
1022
- return rows.some((row) => row.cells.some((cell) => cell.kind === "edge-lane" && cell.adjacency === "node-skipping-rollback"));
1023
- }
1024
- function edgeLabelColumn(row, wideLabelColumn) {
1025
- if (wideLabelColumn !== void 0) return wideLabelColumn;
1026
- const laneIndex = row.laneIndex ?? 0;
1027
- if (row.edge?.from === EMPTY_CONTRACT_HASH && laneIndex === 0) return (laneIndex + 1) * 2 + LABEL_GAP;
1028
- return row.cells.some((cell, index) => index > laneIndex && cell.kind === "vertical-pass") ? row.cells.length * 2 + LABEL_GAP : (laneIndex + 1) * 2 + LABEL_GAP;
1029
- }
1030
- function nodeHasArcDecoration(row) {
1031
- return row.cells.some((cell) => cell.kind === "node" && (cell.arcTee === true || cell.arcLand === true));
1032
- }
1033
- function renderMigrationGraphTree(model, opts) {
1034
- const palette = paletteFor(opts.glyphMode ?? "unicode");
1035
- const style = createTreeStyler(opts);
1036
- const hashLength = opts.hashLength ?? 7;
1037
- const gridWidth = gridWidthForModel(model.rows);
1038
- const wideLabelColumn = gridUsesSkipRollbackArcs(model.rows) ? gridWidth * 2 + 4 : void 0;
1039
- const dirNameGap = wideLabelColumn !== void 0 ? 3 : LABEL_GAP;
1040
- const maxDirNameLen = maxDirNameLength(model.rows.filter((row) => row.kind === "edge" && row.edge !== void 0).map((row) => row.edge));
1041
- const lines = [];
1042
- for (let rowIndex = 0; rowIndex < model.rows.length; rowIndex++) {
1043
- const row = model.rows[rowIndex];
1044
- if (row === void 0) continue;
1045
- if (row.kind === "component-separator") {
1046
- lines.push("");
1047
- continue;
1048
- }
1049
- if (row.kind === "branch-connector" || row.kind === "merge-connector") {
1050
- lines.push(renderConnectorRow(row, gridWidth, style, palette).replace(/\s+$/, ""));
1051
- continue;
1052
- }
1053
- let gutter = row.cells.map((cell) => renderCellPair(cell, style, palette)).join("");
1054
- const prevRow = model.rows[rowIndex - 1];
1055
- let laneSpan = row.cells.length;
1056
- if (row.kind === "node") {
1057
- const contractHash = row.contractHash ?? EMPTY_CONTRACT_HASH;
1058
- if (prevRow?.kind === "merge-connector" || contractHash === EMPTY_CONTRACT_HASH) laneSpan = 1;
1059
- else laneSpan = row.cells.length;
1060
- }
1061
- const labelColumn = row.kind === "edge" ? edgeLabelColumn(row, wideLabelColumn) : wideLabelColumn !== void 0 && (nodeHasArcDecoration(row) || row.contractHash !== void 0) ? wideLabelColumn : laneSpan * 2 + LABEL_GAP;
1062
- if (row.kind === "edge" && row.edge?.from === EMPTY_CONTRACT_HASH && (row.laneIndex ?? 0) === 0) gutter = row.cells.slice(0, 1).map((cell) => renderCellPair(cell, style, palette)).join("");
1063
- else if (row.kind === "node" && laneSpan < row.cells.length && !nodeHasArcDecoration(row)) gutter = row.cells.slice(0, laneSpan).map((cell) => renderCellPair(cell, style, palette)).join("");
1064
- else if (gutter.length < laneSpan * 2) gutter = gutter.padEnd(laneSpan * 2, " ");
1065
- const dirNameWidth = rowDirNameWidth(labelColumn, maxDirNameLen, dirNameGap);
1066
- const dataColumn = labelColumn + dirNameWidth;
1067
- const gutterPad = padVisible(gutter, labelColumn);
1068
- if (row.kind === "node") {
1069
- const contractHash = row.contractHash ?? EMPTY_CONTRACT_HASH;
1070
- if (contractHash === EMPTY_CONTRACT_HASH) {
1071
- const trailingLanes = row.cells.slice(1).map((cell) => renderCellPair(cell, style, palette)).join("");
1072
- const emptyGutter = palette.emptySource.padEnd(2, " ") + trailingLanes;
1073
- const overlayNames = overlayNamesForContract(contractHash, opts);
1074
- if (overlayNames.length === 0) {
1075
- lines.push(emptyGutter.replace(/\s+$/, ""));
1076
- continue;
1077
- }
1078
- const overlay = style.refs(overlayNames);
1079
- lines.push(`${padVisible(emptyGutter, dataColumn)}${overlay}`.replace(/\s+$/, ""));
1080
- continue;
1081
- }
1082
- const hashText = style.sourceHash(abbreviateHash(contractHash, hashLength, palette.emptySource));
1083
- const overlayNames = overlayNamesForContract(contractHash, opts);
1084
- const overlayPad = overlayNames.length > 0 ? " ".repeat(Math.max(0, dataColumn - labelColumn - stringWidth(hashText))) : "";
1085
- const overlay = overlayNames.length > 0 ? style.refs(overlayNames) : "";
1086
- lines.push(`${gutterPad}${hashText}${overlayPad}${overlay}`.replace(/\s+$/, ""));
1087
- continue;
1088
- }
1089
- const edge = row.edge;
1090
- if (edge === void 0) continue;
1091
- const dirNamePadding = " ".repeat(Math.max(0, dirNameWidth - edge.dirName.length));
1092
- const dirName = `${style.dirName(edge.dirName)}${dirNamePadding}`;
1093
- const hashColumn = formatEdgeHashColumn(edge, style, hashLength, palette);
1094
- lines.push(`${gutterPad}${dirName}${hashColumn}`.replace(/\s+$/, ""));
1095
- }
1096
- return lines.join("\n");
1097
- }
1098
- //#endregion
1099
- //#region src/commands/migration-graph.ts
1100
- async function executeMigrationGraphCommand(options, flags, ui) {
1101
- const config = await loadConfig(options.config);
1102
- const { configPath, appMigrationsRelative, migrationsDir } = resolveMigrationPaths(options.config, config);
1103
- if (!flags.json && !flags.quiet) {
1104
- const header = formatStyledHeader({
1105
- command: "migration graph",
1106
- description: "Show the migration graph topology",
1107
- details: [{
1108
- label: "config",
1109
- value: configPath
1110
- }, {
1111
- label: "migrations",
1112
- value: appMigrationsRelative
1113
- }],
1114
- flags
1115
- });
1116
- ui.stderr(header);
1117
- }
1118
- const loaded = await buildReadAggregate(config, { migrationsDir });
1119
- if (!loaded.ok) return loaded;
1120
- const { aggregate, contractHash } = loaded.value;
1121
- const graph = aggregate.app.graph();
1122
- return ok({
1123
- ok: true,
1124
- graph,
1125
- contractHash,
1126
- refs: Object.entries(aggregate.app.refs).map(([name, entry]) => ({
1127
- name,
1128
- hash: entry.hash,
1129
- active: false
1130
- })),
1131
- summary: `${graph.nodes.size} node(s), ${graph.migrationByHash.size} edge(s)`
1132
- });
1133
- }
1134
- function createMigrationGraphCommand() {
1135
- const command = new Command("graph");
1136
- setCommandDescriptions(command, "Show the migration graph topology", "Renders the migration graph topology. Offline — does not consult\nthe database. Use --tree for the condensed annotated tree\n(--ascii swaps box-drawing for pipe-friendly ASCII glyphs),\n--json for machine-readable output, or --dot for Graphviz DOT\nformat.");
1137
- setCommandExamples(command, [
1138
- "prisma-next migration graph",
1139
- "prisma-next migration graph --json",
1140
- "prisma-next migration graph --dot",
1141
- "prisma-next migration graph --tree",
1142
- "prisma-next migration graph --tree --ascii"
1143
- ]);
1144
- setCommandSeeAlso(command, [
1145
- {
1146
- verb: "migration status",
1147
- oneLiner: "Show migration path and pending status"
1148
- },
1149
- {
1150
- verb: "migration log",
1151
- oneLiner: "Show executed migration history"
1152
- },
1153
- {
1154
- verb: "migration list",
1155
- oneLiner: "List on-disk migrations"
1156
- },
1157
- {
1158
- verb: "migration show",
1159
- oneLiner: "Display migration package contents"
1160
- }
1161
- ]);
1162
- addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").option("--dot", "Output in Graphviz DOT format").option("--tree", "Experimental condensed annotated tree renderer").option("--ascii", "Use ASCII glyphs for --tree (pipe-friendly)").action(async (options) => {
1163
- const flags = parseGlobalFlagsOrExit(options);
1164
- const ui = createTerminalUI(flags);
1165
- const exitCode = handleResult(await executeMigrationGraphCommand(options, flags, ui), flags, ui, (graphResult) => {
1166
- if (options.dot) {
1167
- const lines = ["digraph migrations {"];
1168
- for (const edge of graphResult.graph.migrationByHash.values()) {
1169
- const from = edge.from.slice(0, 12);
1170
- const to = edge.to.slice(0, 12);
1171
- lines.push(` "${from}" -> "${to}" [label="${edge.dirName}"];`);
1172
- }
1173
- lines.push("}");
1174
- ui.output(lines.join("\n"));
1175
- } else if (flags.json) {
1176
- const nodes = [...graphResult.graph.nodes];
1177
- const edges = [...graphResult.graph.migrationByHash.values()].map((e) => ({
1178
- dirName: e.dirName,
1179
- from: e.from,
1180
- to: e.to,
1181
- migrationHash: e.migrationHash
1182
- }));
1183
- ui.output(JSON.stringify({
1184
- ok: true,
1185
- nodes,
1186
- edges,
1187
- summary: graphResult.summary
1188
- }, null, 2));
1189
- } else if (!flags.quiet) if (options.tree) {
1190
- const refsByHash = /* @__PURE__ */ new Map();
1191
- for (const ref of graphResult.refs) {
1192
- const existing = refsByHash.get(ref.hash);
1193
- refsByHash.set(ref.hash, existing ? [...existing, ref.name] : [ref.name]);
1194
- }
1195
- const layout = buildMigrationGraphLayout(buildMigrationGraphRows(graphResult.graph, { ...graphResult.contractHash !== null ? { contractHash: graphResult.contractHash } : {} }));
1196
- const activeRef = graphResult.refs.find((ref) => ref.active);
1197
- const treeOutput = renderMigrationGraphTree(layout, {
1198
- refsByHash,
1199
- ...graphResult.contractHash !== null ? { contractHash: graphResult.contractHash } : {},
1200
- ...activeRef !== void 0 ? { activeRefName: activeRef.name } : {},
1201
- colorize: flags.color !== false,
1202
- glyphMode: ui.resolveGlyphMode(options.ascii === true)
1203
- });
1204
- ui.output(treeOutput);
1205
- ui.output(`\n${graphResult.summary}`);
1206
- } else {
1207
- const renderInput = migrationGraphToRenderInput({
1208
- graph: graphResult.graph,
1209
- mode: "offline",
1210
- markerHash: void 0,
1211
- contractHash: graphResult.contractHash ?? EMPTY_CONTRACT_HASH,
1212
- refs: graphResult.refs,
1213
- activeRefHash: void 0,
1214
- activeRefName: void 0,
1215
- edgeStatuses: []
1216
- });
1217
- const graphOutput = graphRenderer.render(renderInput.graph, {
1218
- ...renderInput.options,
1219
- colorize: flags.color !== false
1220
- });
1221
- ui.log(graphOutput);
1222
- ui.log(`\n${graphResult.summary}`);
1223
- }
1224
- });
1225
- process.exit(exitCode);
1226
- });
1227
- return command;
1228
- }
1229
- //#endregion
1230
- export { executeMigrationGraphCommand as n, createMigrationGraphCommand as t };
1231
-
1232
- //# sourceMappingURL=migration-graph-D7DVUElV.mjs.map