@prisma-next/cli 0.12.0-dev.7 → 0.12.0-dev.70
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.
- package/README.md +2 -2
- package/dist/cli.mjs +180 -163
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-KgJorIvG.mjs → client-CJzuo5wX.mjs} +222 -107
- package/dist/client-CJzuo5wX.mjs.map +1 -0
- package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-DGMvGBeX.mjs} +318 -25
- package/dist/command-helpers-DGMvGBeX.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +4 -5
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.d.mts.map +1 -1
- package/dist/commands/db-schema.mjs +3 -3
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +6 -6
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +10 -7
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.d.mts.map +1 -1
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +37 -3
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +298 -12
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +55 -13
- package/dist/commands/migration-check.d.mts.map +1 -1
- package/dist/commands/migration-check.mjs +3 -2
- package/dist/commands/migration-graph.d.mts +16 -25
- package/dist/commands/migration-graph.d.mts.map +1 -1
- package/dist/commands/migration-graph.mjs +185 -2
- package/dist/commands/migration-graph.mjs.map +1 -0
- package/dist/commands/migration-list.d.mts +26 -27
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +2 -190
- package/dist/commands/migration-log.d.mts +9 -19
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +1 -137
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +6 -5
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +1 -1
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.d.mts +17 -21
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +24 -36
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +42 -144
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +3 -759
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +4 -4
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/commands/telemetry/index.d.mts +7 -0
- package/dist/commands/telemetry/index.d.mts.map +1 -0
- package/dist/commands/telemetry/index.mjs +2 -0
- package/dist/{config-loader-B6sJjXTv.mjs → config-loader-p9JMrekQ.mjs} +1 -1
- package/dist/{config-loader-B6sJjXTv.mjs.map → config-loader-p9JMrekQ.mjs.map} +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-CFXsstzm.mjs} +2 -2
- package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-CFXsstzm.mjs.map} +1 -1
- package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-B_qriF8B.mjs} +5 -5
- package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-B_qriF8B.mjs.map} +1 -1
- package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-C8HmtboH.mjs} +12 -7
- package/dist/contract-emit-C8HmtboH.mjs.map +1 -0
- package/dist/{contract-enrichment-a0V5Y_mL.mjs → contract-enrichment-gn9sWbPw.mjs} +1 -1
- package/dist/{contract-enrichment-a0V5Y_mL.mjs.map → contract-enrichment-gn9sWbPw.mjs.map} +1 -1
- package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-BYT_ra_U.mjs} +5 -5
- package/dist/contract-infer-BYT_ra_U.mjs.map +1 -0
- package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-ClI1KN6d.mjs} +5 -5
- package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-ClI1KN6d.mjs.map} +1 -1
- package/dist/{db-verify-v_vUKXTU.mjs → db-verify-C24FKhb7.mjs} +6 -6
- package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-C24FKhb7.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +5 -3
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +3 -3
- package/dist/exports/index.mjs +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts +1 -3
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +1 -1
- package/dist/{extension-pack-inputs-IDvjRCi3.mjs → extension-pack-inputs-1ySHqxKG.mjs} +1 -1
- package/dist/{extension-pack-inputs-IDvjRCi3.mjs.map → extension-pack-inputs-1ySHqxKG.mjs.map} +1 -1
- package/dist/{framework-components-fYXjz_in.mjs → framework-components-YVQHhPH7.mjs} +2 -2
- package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-YVQHhPH7.mjs.map} +1 -1
- package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-BpoOYtNZ.d.mts} +1 -1
- package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-BpoOYtNZ.d.mts.map} +1 -1
- package/dist/{init-Cv9UzWL5.mjs → init-0HwB-Vh8.mjs} +5 -58
- package/dist/init-0HwB-Vh8.mjs.map +1 -0
- package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-DF6IwcDl.mjs} +7 -5
- package/dist/inspect-live-schema-DF6IwcDl.mjs.map +1 -0
- package/dist/migration-check-soB5uZEQ.mjs +573 -0
- package/dist/migration-check-soB5uZEQ.mjs.map +1 -0
- package/dist/migration-cli.mjs +1 -1
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-DA-Lhx6o.mjs} +5 -5
- package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-DA-Lhx6o.mjs.map} +1 -1
- package/dist/migration-graph-command-render-BAOzyYF6.mjs +1822 -0
- package/dist/migration-graph-command-render-BAOzyYF6.mjs.map +1 -0
- package/dist/migration-list-CihF6w5z.mjs +230 -0
- package/dist/migration-list-CihF6w5z.mjs.map +1 -0
- package/dist/migration-log-B75IArji.mjs +222 -0
- package/dist/migration-log-B75IArji.mjs.map +1 -0
- package/dist/migration-path-target-Ce6OZImp.mjs +38 -0
- package/dist/migration-path-target-Ce6OZImp.mjs.map +1 -0
- package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-z5Ing-TD.mjs} +9 -8
- package/dist/migration-plan-z5Ing-TD.mjs.map +1 -0
- package/dist/migration-status-Di82DGvo.mjs +446 -0
- package/dist/migration-status-Di82DGvo.mjs.map +1 -0
- package/dist/{output-B60Gw5fu.mjs → output-mEQ74_nd.mjs} +1 -1
- package/dist/{output-B60Gw5fu.mjs.map → output-mEQ74_nd.mjs.map} +1 -1
- package/dist/{progress-adapter-C644QK8l.mjs → progress-adapter-CjAeTxY_.mjs} +1 -1
- package/dist/{progress-adapter-C644QK8l.mjs.map → progress-adapter-CjAeTxY_.mjs.map} +1 -1
- package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-BkXlikCA.mjs} +1 -1
- package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-BkXlikCA.mjs.map} +1 -1
- package/dist/schemas-CeGMYFYX.d.mts +191 -0
- package/dist/schemas-CeGMYFYX.d.mts.map +1 -0
- package/dist/schemas-KhXMzNA_.mjs +112 -0
- package/dist/schemas-KhXMzNA_.mjs.map +1 -0
- package/dist/telemetry-BIM4beEO.mjs +122 -0
- package/dist/telemetry-BIM4beEO.mjs.map +1 -0
- package/dist/{terminal-ui-5Y6mrg93.d.mts → terminal-ui-DGRNFWna.d.mts} +1 -1
- package/dist/terminal-ui-DGRNFWna.d.mts.map +1 -0
- package/dist/{types-Dt_SfqFm.d.mts → types-C_tYiJYx.d.mts} +53 -31
- package/dist/types-C_tYiJYx.d.mts.map +1 -0
- package/dist/{verify-DCA9Sldu.mjs → verify-DcOYZ1tH.mjs} +2 -2
- package/dist/{verify-DCA9Sldu.mjs.map → verify-DcOYZ1tH.mjs.map} +1 -1
- package/package.json +26 -22
- package/src/cli.ts +5 -0
- package/src/commands/contract-infer.ts +2 -2
- package/src/commands/db-update.ts +7 -1
- package/src/commands/init/index.ts +6 -35
- package/src/commands/init/init.ts +1 -14
- package/src/commands/init/inputs.ts +0 -75
- package/src/commands/inspect-live-schema.ts +10 -0
- package/src/commands/json/schemas.ts +195 -0
- package/src/commands/migrate.ts +527 -8
- package/src/commands/migration-check.ts +469 -134
- package/src/commands/migration-graph.ts +151 -119
- package/src/commands/migration-list.ts +72 -39
- package/src/commands/migration-log.ts +52 -102
- package/src/commands/migration-new.ts +2 -1
- package/src/commands/migration-plan.ts +2 -1
- package/src/commands/migration-show.ts +31 -66
- package/src/commands/migration-status-overlay.ts +61 -0
- package/src/commands/migration-status.ts +458 -1066
- package/src/commands/telemetry/index.ts +107 -0
- package/src/commands/telemetry/status.ts +67 -0
- package/src/control-api/client.ts +70 -9
- package/src/control-api/operations/contract-emit.ts +22 -2
- package/src/control-api/operations/db-init.ts +6 -3
- package/src/control-api/operations/{db-apply.ts → db-run.ts} +55 -14
- package/src/control-api/operations/db-update.ts +7 -4
- package/src/control-api/operations/db-verify.ts +15 -5
- package/src/control-api/operations/{migration-apply.ts → migrate.ts} +181 -80
- package/src/control-api/operations/{apply.ts → run-migration.ts} +33 -27
- package/src/control-api/types.ts +56 -29
- package/src/utils/cli-errors.ts +70 -2
- package/src/utils/formatters/errors.ts +11 -0
- package/src/utils/formatters/migration-graph-command-render.ts +239 -0
- package/src/utils/formatters/migration-graph-grid-layout.ts +857 -0
- package/src/utils/formatters/migration-graph-labels.ts +406 -0
- package/src/utils/formatters/migration-graph-model.ts +94 -0
- package/src/utils/formatters/migration-graph-occlusion-render.ts +245 -0
- package/src/utils/formatters/migration-graph-rows.ts +128 -15
- package/src/utils/formatters/migration-graph-space-render.ts +188 -0
- package/src/utils/formatters/migration-list-data-column.ts +4 -91
- package/src/utils/formatters/migration-list-graph-topology.ts +72 -94
- package/src/utils/formatters/migration-list-render.ts +135 -71
- package/src/utils/formatters/migration-list-styler.ts +46 -5
- package/src/utils/formatters/migration-list-types.ts +5 -21
- package/src/utils/formatters/migration-log-table.ts +205 -0
- package/src/utils/formatters/migrations.ts +33 -11
- package/src/utils/global-flags.ts +35 -0
- package/src/utils/integrity-violation-to-check-failure.ts +28 -19
- package/src/utils/legend.ts +38 -0
- package/src/utils/migration-path-target.ts +60 -0
- package/src/utils/telemetry.ts +68 -32
- package/dist/client-KgJorIvG.mjs.map +0 -1
- package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
- package/dist/commands/migration-list.mjs.map +0 -1
- package/dist/commands/migration-log.mjs.map +0 -1
- package/dist/commands/migration-status.mjs.map +0 -1
- package/dist/contract-emit-D-4jrNve.mjs.map +0 -1
- package/dist/contract-infer-D8uEbJuu.mjs.map +0 -1
- package/dist/graph-render-rFAqZujX.mjs +0 -1081
- package/dist/graph-render-rFAqZujX.mjs.map +0 -1
- package/dist/init-Cv9UzWL5.mjs.map +0 -1
- package/dist/inspect-live-schema-C6ohV_oQ.mjs.map +0 -1
- package/dist/migration-check-BiBJoYYW.mjs +0 -341
- package/dist/migration-check-BiBJoYYW.mjs.map +0 -1
- package/dist/migration-graph-BzxEsMZg.mjs +0 -1463
- package/dist/migration-graph-BzxEsMZg.mjs.map +0 -1
- package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
- package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
- package/dist/migration-plan-9DJ7q7_z.mjs.map +0 -1
- package/dist/migration-types-D2FW63pr.d.mts +0 -15
- package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
- package/dist/migrations-Cv2jxNNK.mjs +0 -228
- package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
- package/dist/terminal-ui-5Y6mrg93.d.mts.map +0 -1
- package/dist/types-Dt_SfqFm.d.mts.map +0 -1
- package/src/utils/formatters/graph-migration-mapper.ts +0 -235
- package/src/utils/formatters/graph-render.ts +0 -1323
- package/src/utils/formatters/graph-types.ts +0 -120
- package/src/utils/formatters/migration-graph-lane-colors.ts +0 -31
- package/src/utils/formatters/migration-graph-layout.ts +0 -1119
- package/src/utils/formatters/migration-graph-tree-render.ts +0 -755
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-graph-command-render-BAOzyYF6.mjs","names":[],"sources":["../src/utils/formatters/migration-graph-occlusion-render.ts","../src/utils/formatters/migration-list-data-column.ts","../src/utils/formatters/migration-graph-grid-layout.ts","../src/utils/formatters/migration-list-graph-topology.ts","../src/utils/formatters/migration-graph-rows.ts","../src/utils/formatters/migration-graph-space-render.ts","../src/utils/formatters/migration-list-render.ts","../src/utils/formatters/migration-list-styler.ts","../src/utils/formatters/migration-graph-labels.ts","../src/utils/formatters/migration-graph-command-render.ts"],"sourcesContent":["/**\n * Occlusion renderer for the line/plane/occlusion migration-graph.\n *\n * Per cell: pick the topmost-plane line (lowest plane number = drawn on top),\n * look up its glyph, apply colour from the line's lane or role. Lower-plane\n * lines are occluded (not drawn).\n *\n * Colour is forced via createColors({ useColor: true }) regardless of NO_COLOR.\n */\n\nimport { createColors } from 'colorette';\nimport type { Cell, CellLine, Direction, Grid, PathRole } from './migration-graph-model';\n\n// ---------------------------------------------------------------------------\n// Force-colour seam — always emits ANSI regardless of NO_COLOR.\n// Same technique as gallery-cells.ts.\n// ---------------------------------------------------------------------------\nconst palette = createColors({ useColor: true });\n\n// Lane colour palette: lane N → colour N+1 (lane0=white, lane1=cyan, …).\n// No red (reads as an error). The on-path highlight uses greenBright (SGR 92),\n// distinct from flat-lane green (SGR 32).\ntype Colorizer = (text: string) => string;\n\nconst LANE_COLORIZERS: Colorizer[] = [\n palette.white,\n palette.cyan,\n palette.yellow,\n palette.blueBright,\n palette.magenta,\n palette.green,\n];\n\nfunction laneColor(lane: number): Colorizer {\n return LANE_COLORIZERS[lane % LANE_COLORIZERS.length] ?? ((t) => t);\n}\n\n/**\n * The colourizer for a lane's hue (lane0 = white, lane1 = cyan, …). Exported\n * so the per-row LABEL renderer can tint a migration name in its lane's colour,\n * matching the node `○`, the edges, and the arrows drawn in the gutter — one\n * colour per lane across glyph and text.\n */\nexport function laneColorizer(lane: number): (text: string) => string {\n return laneColor(lane);\n}\n\n// ---------------------------------------------------------------------------\n// Focus colour: on-path → green, off-path → dim. Read straight off the line's\n// role; a defined role always overrides the lane rotation.\n// ---------------------------------------------------------------------------\nfunction roleColor(role: PathRole): Colorizer {\n return role === 'on-path' ? palette.greenBright : palette.dim;\n}\n\n// ---------------------------------------------------------------------------\n// Glyph alphabet — unicode and ASCII variants.\n// ---------------------------------------------------------------------------\nexport type GraphGlyphMode = 'unicode' | 'ascii';\n\ninterface GraphGlyphAlphabet {\n readonly vertical: string;\n readonly horizontal: string;\n readonly cornerUpRight: string;\n readonly cornerDownRight: string;\n readonly cornerUpLeft: string;\n readonly cornerDownLeft: string;\n readonly arrowUp: string;\n readonly arrowDown: string;\n readonly node: string;\n readonly selfLoop: string;\n readonly landingArrow: string;\n readonly fallback: string;\n}\n\nconst UNICODE_ALPHABET: GraphGlyphAlphabet = {\n vertical: '│',\n horizontal: '─',\n cornerUpRight: '╰',\n cornerDownRight: '╭',\n cornerUpLeft: '╯',\n cornerDownLeft: '╮',\n arrowUp: '↑',\n arrowDown: '↓',\n node: '○',\n selfLoop: '⟲',\n landingArrow: '◂',\n fallback: '?',\n};\n\nconst ASCII_ALPHABET: GraphGlyphAlphabet = {\n vertical: '|',\n horizontal: '-',\n cornerUpRight: '\\\\',\n cornerDownRight: '/',\n cornerUpLeft: '/',\n cornerDownLeft: '\\\\',\n arrowUp: '^',\n arrowDown: 'v',\n node: '*',\n selfLoop: '@',\n landingArrow: '<',\n fallback: '?',\n};\n\nfunction alphabetFor(mode: GraphGlyphMode): GraphGlyphAlphabet {\n return mode === 'ascii' ? ASCII_ALPHABET : UNICODE_ALPHABET;\n}\n\nfunction glyphFor(dirs: ReadonlySet<Direction>, alphabet: GraphGlyphAlphabet): string {\n const has = (d: Direction) => dirs.has(d);\n\n if (has('up') && has('down') && !has('left') && !has('right')) return alphabet.vertical;\n if (has('left') && has('right') && !has('up') && !has('down')) return alphabet.horizontal;\n if (has('up') && has('right') && !has('down') && !has('left')) return alphabet.cornerUpRight;\n if (has('down') && has('right') && !has('up') && !has('left')) return alphabet.cornerDownRight;\n if (has('up') && has('left') && !has('down') && !has('right')) return alphabet.cornerUpLeft;\n if (has('down') && has('left') && !has('up') && !has('right')) return alphabet.cornerDownLeft;\n if (has('up') && !has('down') && !has('left') && !has('right')) return alphabet.arrowUp;\n if (has('down') && !has('up') && !has('left') && !has('right')) return alphabet.arrowDown;\n\n // Fallback: shouldn't happen in well-formed grids\n return alphabet.fallback;\n}\n\n// ---------------------------------------------------------------------------\n// renderCell — project one cell to a coloured string fragment.\n// ---------------------------------------------------------------------------\n\nconst NO_COLOR: Colorizer = (t) => t;\n\nfunction renderCell(cell: Cell, colorEnabled: boolean, alphabet: GraphGlyphAlphabet): string {\n // Node marker overrides everything\n if (cell.node !== undefined) {\n // Every node uses ○ — the ∅ identifier is only used as the label, not as a\n // glyph, per the golden colour model. Colour by role (focus) or lane (flat).\n const colorize = !colorEnabled\n ? NO_COLOR\n : cell.node.role !== undefined\n ? roleColor(cell.node.role)\n : laneColor(cell.node.lane);\n return colorize(alphabet.node);\n }\n\n if (cell.lines.length === 0) {\n return ' ';\n }\n\n // Pick the drawn line by occlusion: lowest plane number wins (drawn on top).\n // At an equal plane, on-path beats off-path explicitly — never rely on array\n // order to break the tie (the single-owner invariant should already prevent\n // a same-plane on/off-path collision, but the priority is made explicit here).\n const topLine = cell.lines.reduce<CellLine>((best, current) => {\n if (current.plane < best.plane) return current;\n if (current.plane > best.plane) return best;\n if (current.line.role === 'on-path' && best.line.role !== 'on-path') return current;\n return best;\n }, cell.lines[0]!);\n\n const glyph =\n topLine.selfLoop === true\n ? alphabet.selfLoop\n : topLine.landingArrow === true\n ? alphabet.landingArrow\n : glyphFor(topLine.directions, alphabet);\n const colorize = !colorEnabled\n ? NO_COLOR\n : topLine.line.role !== undefined\n ? roleColor(topLine.line.role)\n : laneColor(topLine.line.lane);\n return colorize(glyph);\n}\n\n// ---------------------------------------------------------------------------\n// RenderGridOptions\n// ---------------------------------------------------------------------------\n\nexport interface RenderGridOptions {\n readonly colorize?: boolean;\n readonly colsPerLane?: number;\n readonly glyphMode?: GraphGlyphMode;\n}\n\n// ---------------------------------------------------------------------------\n// renderGrid — the main render function.\n//\n// Produces the final string: one line per grid row, each cell rendered to\n// a coloured character. Trailing empty cells are trimmed, but we always\n// include up to the last non-empty cell's connector column\n// (the full 2-col-per-lane width for the active lane count).\n// ---------------------------------------------------------------------------\n\n/**\n * Render a single grid row to a coloured string. A completely empty row returns\n * the empty string (the row is NOT dropped) so callers that pair grid rows with\n * an external per-row label list keep a 1:1 index correspondence. `renderGrid`\n * itself drops empty rows for its standalone output.\n */\nexport function renderGridRow(\n row: readonly (Cell | undefined)[],\n opts: RenderGridOptions = {},\n): string {\n // Find the last non-empty cell index\n let lastNonEmpty = -1;\n for (let i = row.length - 1; i >= 0; i--) {\n const cell = row[i];\n if (cell !== undefined && (cell.lines.length > 0 || cell.node !== undefined)) {\n lastNonEmpty = i;\n break;\n }\n }\n\n if (lastNonEmpty < 0) {\n return '';\n }\n\n // Extend to the next even column boundary (connector col of the current lane)\n // so that connector columns are always present for active lane ranges.\n const colsPerLane = opts.colsPerLane ?? 2;\n const colorEnabled = opts.colorize ?? true;\n const alphabet = alphabetFor(opts.glyphMode ?? 'unicode');\n const lastLane = Math.floor(lastNonEmpty / colsPerLane);\n const lastConnectorCol = lastLane * colsPerLane + (colsPerLane - 1);\n const renderThrough = Math.max(lastNonEmpty, lastConnectorCol);\n\n let line = '';\n for (let col = 0; col <= Math.min(renderThrough, row.length - 1); col++) {\n const cell = row[col];\n line += cell === undefined ? ' ' : renderCell(cell, colorEnabled, alphabet);\n }\n return line;\n}\n\nexport function renderGrid(grid: Grid, opts: RenderGridOptions = {}): string {\n const lines: string[] = [];\n for (const row of grid) {\n const rendered = renderGridRow(row, opts);\n if (rendered === '') {\n // Completely empty row — skip in standalone output.\n continue;\n }\n lines.push(rendered);\n }\n return lines.join('\\n');\n}\n","import stringWidth from 'string-width';\nimport type { GlyphMode } from '../glyph-mode';\n\nexport const MIGRATION_LIST_HASH_WIDTH = 7;\nexport const MIGRATION_LIST_EMPTY_SOURCE = '∅';\nexport const MIGRATION_LIST_ASCII_EMPTY_SOURCE = '-';\nexport const MIGRATION_LIST_FORWARD_EDGE_GLYPH = '→';\nexport const MIGRATION_LIST_ASCII_FORWARD_EDGE_GLYPH = '->';\n\nexport function migrationListForwardArrow(glyphMode: GlyphMode): string {\n return glyphMode === 'ascii'\n ? MIGRATION_LIST_ASCII_FORWARD_EDGE_GLYPH\n : MIGRATION_LIST_FORWARD_EDGE_GLYPH;\n}\n\nexport function migrationListEmptySource(glyphMode: GlyphMode): string {\n return glyphMode === 'ascii' ? MIGRATION_LIST_ASCII_EMPTY_SOURCE : MIGRATION_LIST_EMPTY_SOURCE;\n}\n\nexport function abbreviateContractHash(hash: string): string {\n const stripped = hash.startsWith('sha256:') ? hash.slice(7) : hash;\n return stripped.slice(0, MIGRATION_LIST_HASH_WIDTH);\n}\n\nexport function padFromHashColumn(text: string, width: number): string {\n const padding = Math.max(0, width - stringWidth(text));\n return `${' '.repeat(padding)}${text}`;\n}\n","/**\n * Grid layout for the line/plane/occlusion migration-graph renderer.\n *\n * Produces a Grid (rows × cells) from a MigrationGraphRowModel. Each node\n * emits: fork connector, self-loop rows, node row, merge connector, and\n * inbound migration rows — in display order (tips first, then roots).\n */\n\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport type {\n Cell,\n CellLine,\n Direction,\n Grid,\n GridOptions,\n Highlight,\n LineRef,\n NodeRef,\n PathRole,\n} from './migration-graph-model';\nimport type { ClassifiedEdge, MigrationGraphRowModel } from './migration-graph-rows';\n\n// ---------------------------------------------------------------------------\n// Internal: lane + rank assignment\n// ---------------------------------------------------------------------------\n\ninterface LaneAssignment {\n nodeLane: Map<string, number>;\n nodeRank: Map<string, number>;\n /** Total number of lanes allocated. */\n numLanes: number;\n}\n\nfunction buildLaneAssignment(\n nodes: readonly (string | null)[],\n edges: readonly ClassifiedEdge[],\n): LaneAssignment {\n const allNodes = new Set<string>();\n for (const n of nodes) {\n if (n !== null) allNodes.add(n);\n }\n\n // Separate forward (non-self) edges\n const fwdEdges = edges.filter((e) => e.kind === 'forward' && e.from !== e.to);\n\n // Build adjacency: outbound forward edges per node, sorted lex by migrationHash\n const outbound = new Map<string, ClassifiedEdge[]>();\n const inbound = new Map<string, ClassifiedEdge[]>();\n for (const edge of fwdEdges) {\n const ob = outbound.get(edge.from);\n if (ob) ob.push(edge);\n else outbound.set(edge.from, [edge]);\n\n const ib = inbound.get(edge.to);\n if (ib) ib.push(edge);\n else inbound.set(edge.to, [edge]);\n }\n for (const list of outbound.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n for (const list of inbound.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n\n // Compute longest-forward-path rank from roots (tips get highest rank)\n const nodeRank = new Map<string, number>();\n for (const n of allNodes) nodeRank.set(n, 0);\n for (let pass = 0; pass < allNodes.size; pass++) {\n let changed = false;\n for (const [from, edges] of outbound) {\n const base = nodeRank.get(from) ?? 0;\n for (const e of edges) {\n const next = base + 1;\n if (next > (nodeRank.get(e.to) ?? 0)) {\n nodeRank.set(e.to, next);\n changed = true;\n }\n }\n }\n if (!changed) break;\n }\n\n // Lane assignment: BFS from roots, trunk keeps parent's lane\n const nodeLane = new Map<string, number>();\n let nextLane = 0;\n\n // Roots: nodes with no inbound forward edges\n const roots: string[] = [];\n for (const n of allNodes) {\n if ((inbound.get(n) ?? []).length === 0) roots.push(n);\n }\n roots.sort((a, b) => {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n });\n\n const bfsQueue: Array<{ node: string; lane: number }> = [];\n for (const root of roots) {\n if (!nodeLane.has(root)) {\n nodeLane.set(root, nextLane++);\n bfsQueue.push({ node: root, lane: nodeLane.get(root)! });\n }\n }\n\n // BFS expansion\n let head = 0;\n while (head < bfsQueue.length) {\n const item = bfsQueue[head++]!;\n const { node, lane } = item;\n const children = outbound.get(node) ?? [];\n let first = true;\n for (const childEdge of children) {\n const child = childEdge.to;\n if (!nodeLane.has(child)) {\n const childLane = first ? lane : nextLane++;\n nodeLane.set(child, childLane);\n bfsQueue.push({ node: child, lane: childLane });\n }\n first = false;\n }\n }\n\n // Isolated nodes (no edges) get their own lane\n for (const n of allNodes) {\n if (!nodeLane.has(n)) nodeLane.set(n, nextLane++);\n }\n\n return { nodeLane, nodeRank, numLanes: nextLane };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: display order\n// ---------------------------------------------------------------------------\n\ninterface NodeDisplay {\n hash: string;\n lane: number;\n rank: number;\n}\n\nfunction computeDisplayOrder(\n nodes: readonly (string | null)[],\n nodeLane: Map<string, number>,\n nodeRank: Map<string, number>,\n): NodeDisplay[] {\n const seen = new Set<string>();\n const result: NodeDisplay[] = [];\n for (const n of nodes) {\n if (n === null || seen.has(n)) continue;\n seen.add(n);\n result.push({ hash: n, lane: nodeLane.get(n) ?? 0, rank: nodeRank.get(n) ?? 0 });\n }\n // Tips first (rank desc), within same rank lane asc\n result.sort((a, b) => b.rank - a.rank || a.lane - b.lane);\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Internal: grid row builder\n// ---------------------------------------------------------------------------\n\ntype CellsRow = Cell[];\n\n/** Create an empty cell. */\nfunction emptyCell(): Cell {\n return { lines: [] };\n}\n\n// ---------------------------------------------------------------------------\n// buildGrid — main entry point\n// ---------------------------------------------------------------------------\n\nexport function buildGrid(\n rowModel: MigrationGraphRowModel,\n opts: GridOptions = {},\n highlight: Highlight = { mode: 'flat', onPath: new Set() },\n): Grid {\n const colsPerLane = opts.colsPerLane ?? 2;\n const isFocus = highlight.mode === 'focus';\n\n const { nodeLane, nodeRank, numLanes } = buildLaneAssignment(rowModel.nodes, rowModel.edges);\n\n const displayOrder = computeDisplayOrder(rowModel.nodes, nodeLane, nodeRank);\n\n // Display index per node (0 = topmost row).\n const displayIndex = new Map<string, number>();\n displayOrder.forEach((d, i) => {\n displayIndex.set(d.hash, i);\n });\n\n // ── Back-arc planning ────────────────────────────────────────────────────\n // Each rollback edge runs against the forward grain. An *adjacent* rollback\n // (target is the display-neighbour directly below the source) is a plain ↓ in\n // the source's own lane. A *node-skipping* rollback is routed on its own\n // back-lane to the right: it tees off the source node row (○─╮), runs a\n // vertical │ down its back-lane, and lands into the target node (◂╯).\n //\n // Two independent numbers per routed back-arc:\n // geomLane — the column its rail occupies. Outermost (largest) goes to the\n // arc reaching the lowest target (ties: higher source first), so\n // interleaving spans cross and nested spans nest cleanly.\n // colourLane — the lane index used purely for colour. Assigned by\n // migrationHash order, continuing after the forward lanes, so the\n // first rollback is lane numLanes, the next numLanes+1, etc.\n // These differ whenever two arcs interleave (rollback-cross): the inner column\n // may carry the higher colour. Colour is read off LineRef.lane; the column is\n // where the cell is placed.\n interface RoutedBackArc {\n readonly edge: ClassifiedEdge;\n readonly sourceIndex: number;\n readonly targetIndex: number;\n readonly geomLane: number;\n readonly colourLane: number;\n }\n\n const rollbackEdges = rowModel.edges.filter((e) => e.kind === 'rollback' && e.from !== e.to);\n\n const adjacentRollbacks: ClassifiedEdge[] = [];\n const skippingRollbacks: ClassifiedEdge[] = [];\n for (const e of rollbackEdges) {\n const si = displayIndex.get(e.from);\n const ti = displayIndex.get(e.to);\n if (si === undefined || ti === undefined) continue;\n // Adjacent: target sits directly below the source in display order.\n if (ti === si + 1) adjacentRollbacks.push(e);\n else skippingRollbacks.push(e);\n }\n\n // colourLane by migration NAME (dirName) order — chronological, not hash.\n const colourLaneOf = new Map<string, number>();\n [...skippingRollbacks]\n .sort((a, b) => a.dirName.localeCompare(b.dirName))\n .forEach((e, i) => {\n colourLaneOf.set(e.migrationHash, numLanes + i);\n });\n\n // geomLane: outermost rail to the arc with the lowest target (largest target\n // index); ties broken by the highest source (smallest source index). The first\n // in this order gets the outermost (largest) geometric lane.\n const geomOrder = [...skippingRollbacks].sort((a, b) => {\n const ta = displayIndex.get(a.to) ?? 0;\n const tb = displayIndex.get(b.to) ?? 0;\n if (ta !== tb) return tb - ta; // lower target (larger index) first\n const sa = displayIndex.get(a.from) ?? 0;\n const sb = displayIndex.get(b.from) ?? 0;\n return sa - sb; // higher source (smaller index) first\n });\n const geomLaneOf = new Map<string, number>();\n const outermost = numLanes + skippingRollbacks.length - 1;\n geomOrder.forEach((e, i) => {\n geomLaneOf.set(e.migrationHash, outermost - i);\n });\n\n const routedBackArcs: RoutedBackArc[] = skippingRollbacks.map((e) => ({\n edge: e,\n sourceIndex: displayIndex.get(e.from) ?? 0,\n targetIndex: displayIndex.get(e.to) ?? 0,\n geomLane: geomLaneOf.get(e.migrationHash) ?? numLanes,\n colourLane: colourLaneOf.get(e.migrationHash) ?? numLanes,\n }));\n\n const backArcsBySource = new Map<string, RoutedBackArc[]>();\n const backArcsByTarget = new Map<string, RoutedBackArc[]>();\n for (const arc of routedBackArcs) {\n const sb = backArcsBySource.get(arc.edge.from);\n if (sb) sb.push(arc);\n else backArcsBySource.set(arc.edge.from, [arc]);\n const tb = backArcsByTarget.get(arc.edge.to);\n if (tb) tb.push(arc);\n else backArcsByTarget.set(arc.edge.to, [arc]);\n }\n\n const adjacentBySource = new Map<string, ClassifiedEdge[]>();\n const adjacentByTarget = new Map<string, ClassifiedEdge[]>();\n for (const e of adjacentRollbacks) {\n const b = adjacentBySource.get(e.from);\n if (b) b.push(e);\n else adjacentBySource.set(e.from, [e]);\n const t = adjacentByTarget.get(e.to);\n if (t) t.push(e);\n else adjacentByTarget.set(e.to, [e]);\n }\n for (const list of adjacentBySource.values())\n list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n\n const numBackLanes = skippingRollbacks.length;\n const totalCols = (numLanes + numBackLanes) * colsPerLane;\n\n // Build edge lookup maps (classified)\n const fwdEdges = rowModel.edges.filter((e) => e.kind === 'forward' && e.from !== e.to);\n const selfEdges = rowModel.edges.filter((e) => e.kind === 'self');\n\n // outbound sorted by migrationHash\n const outboundFwd = new Map<string, ClassifiedEdge[]>();\n const inboundFwd = new Map<string, ClassifiedEdge[]>();\n for (const e of fwdEdges) {\n const ob = outboundFwd.get(e.from);\n if (ob) ob.push(e);\n else outboundFwd.set(e.from, [e]);\n const ib = inboundFwd.get(e.to);\n if (ib) ib.push(e);\n else inboundFwd.set(e.to, [e]);\n }\n for (const list of outboundFwd.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n for (const list of inboundFwd.values()) list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n\n const selfEdgesByNode = new Map<string, ClassifiedEdge[]>();\n for (const e of selfEdges) {\n const bucket = selfEdgesByNode.get(e.from);\n if (bucket) bucket.push(e);\n else selfEdgesByNode.set(e.from, [e]);\n }\n for (const list of selfEdgesByNode.values())\n list.sort((a, b) => a.dirName.localeCompare(b.dirName));\n\n // ── Role + plane: mode/z-order seam ──────────────────────────────────────\n // role(migrationHash): focus → on-path/off-path from highlight.onPath; flat → undefined.\n function roleOf(migrationHash: string): PathRole | undefined {\n if (!isFocus) return undefined;\n return highlight.onPath.has(migrationHash) ? 'on-path' : 'off-path';\n }\n\n // On-path node set: a node is on-path iff an on-path edge touches it (from or\n // to) — forward, self, OR rollback (a back-arc's endpoints are on its route).\n const onPathNodes = new Set<string>();\n if (isFocus) {\n for (const e of [...fwdEdges, ...selfEdges, ...rollbackEdges]) {\n if (highlight.onPath.has(e.migrationHash)) {\n onPathNodes.add(e.from);\n onPathNodes.add(e.to);\n }\n }\n }\n function nodeRoleOf(hash: string): PathRole | undefined {\n if (!isFocus) return undefined;\n return onPathNodes.has(hash) ? 'on-path' : 'off-path';\n }\n\n // planeOf — z-order. Lower number = drawn on top.\n // flat: trunk on top → plane = lane (lane 0 topmost).\n // focus: on-path on top → on-path = plane 0; off-path sits beneath it,\n // ordered by lane so a deterministic owner survives among off-path lines.\n function planeOf(lane: number, role: PathRole | undefined): number {\n if (!isFocus) return lane;\n return role === 'on-path' ? 0 : lane + 1;\n }\n\n // ── LineRef + cell builders (role-aware) ─────────────────────────────────\n function lineRefFor(edge: ClassifiedEdge, lane: number): LineRef {\n return {\n migrationHash: edge.migrationHash,\n dirName: edge.dirName,\n lane,\n role: roleOf(edge.migrationHash),\n };\n }\n\n /** Synthetic LineRef for a lane carrying a representative edge's role (pass-through). */\n function passLineRef(lane: number, dirName: string, migHash: string): LineRef {\n return { migrationHash: migHash, dirName, lane, role: roleOf(migHash) };\n }\n\n function vertCell(line: LineRef): Cell {\n return {\n lines: [\n {\n line,\n directions: new Set<Direction>(['up', 'down']),\n plane: planeOf(line.lane, line.role),\n },\n ],\n };\n }\n\n function dirCell(line: LineRef, dirs: ReadonlySet<Direction>): Cell {\n return { lines: [{ line, directions: dirs, plane: planeOf(line.lane, line.role) }] };\n }\n\n function nodeCell(nodeRef: NodeRef): Cell {\n return { node: nodeRef, lines: [] };\n }\n\n // Pass-through colour follows the edge CURRENTLY occupying a lane at this row,\n // not a lane-wide average. A single lane carries different edges (with different\n // roles) over its vertical extent — e.g. lane 0 below a fork carries the trunk\n // branch (off-path) above the fork node and the trunk's parent edge (on-path)\n // below it. We track the active edge per lane as we descend top-to-bottom and\n // colour pass-through verticals from it. `laneCurrentEdge[L]` = the edge whose\n // vertical body currently runs through lane L at the row being emitted.\n const laneCurrentEdge = new Map<number, ClassifiedEdge>();\n\n function getRepLine(lane: number): LineRef {\n const e = laneCurrentEdge.get(lane);\n if (e) return lineRefFor(e, lane);\n return passLineRef(lane, `lane${lane}`, `lane${lane}`);\n }\n\n // Active lanes: set of lane indices currently visible (vertical passes through them)\n const activeLanes = new Set<number>();\n\n const grid: Cell[][] = [];\n\n function makeRow(): CellsRow {\n return Array.from({ length: totalCols }, () => emptyCell());\n }\n\n // Place vertical pass-throughs for all active lanes in a row, skipping specified lanes.\n function placeVerticals(row: CellsRow, skip: Set<number>): void {\n for (const lane of activeLanes) {\n if (skip.has(lane)) continue;\n const railCol = lane * colsPerLane;\n const cell = row[railCol];\n if (cell !== undefined && cell.lines.length === 0 && !cell.node) {\n row[railCol] = vertCell(getRepLine(lane));\n }\n }\n }\n\n // ── Back-arc helpers ──────────────────────────────────────────────────────\n // Active routed back-arcs whose vertical currently runs through their geomLane.\n const activeBackArcs = new Set<RoutedBackArc>();\n\n // A back-arc's LineRef carries its colourLane (not its geomLane) so colour is\n // read off the lane that drives the rotation, independent of column placement.\n function backArcLine(arc: RoutedBackArc): LineRef {\n return {\n migrationHash: arc.edge.migrationHash,\n dirName: arc.edge.dirName,\n lane: arc.colourLane,\n role: roleOf(arc.edge.migrationHash),\n };\n }\n\n function backArcPlane(arc: RoutedBackArc): number {\n const role = roleOf(arc.edge.migrationHash);\n if (!isFocus) return arc.colourLane;\n return role === 'on-path' ? 0 : arc.colourLane + 1;\n }\n\n // Compose a CellLine into a row cell (never overwrite — occlusion arbitrates).\n function composeLine(\n row: CellsRow,\n col: number,\n line: LineRef,\n dirs: ReadonlySet<Direction>,\n plane: number,\n extra?: { landingArrow?: boolean },\n ): void {\n const existing = row[col];\n const cellLine: CellLine = {\n line,\n directions: dirs,\n plane,\n ...(extra?.landingArrow ? { landingArrow: true } : {}),\n };\n if (existing && (existing.lines.length > 0 || existing.node)) {\n row[col] = { ...existing, lines: [...existing.lines, cellLine] };\n } else {\n row[col] = { lines: [cellLine] };\n }\n }\n\n // Place verticals for every active back-arc on this row (in its geomLane rail).\n function placeBackVerticals(row: CellsRow): void {\n for (const arc of activeBackArcs) {\n const railCol = arc.geomLane * colsPerLane;\n composeLine(\n row,\n railCol,\n backArcLine(arc),\n new Set<Direction>(['up', 'down']),\n backArcPlane(arc),\n );\n }\n placeAdjacentOverlays(row);\n }\n\n // Adjacent rollbacks share the source's own lane: their vertical body overlays\n // the forward trunk between source and target. In focus, an on-path adjacent\n // rollback lifts that segment of the trunk to the top plane (drawn green); in\n // flat it sits at the same plane/colour as the trunk, so it is a no-op there.\n interface ActiveAdjacent {\n readonly lane: number;\n readonly edge: ClassifiedEdge;\n }\n const activeAdjacent = new Set<ActiveAdjacent>();\n\n function placeAdjacentOverlays(row: CellsRow): void {\n for (const adj of activeAdjacent) {\n const railCol = adj.lane * colsPerLane;\n const cell = row[railCol];\n if (cell?.node) continue; // never overlay a node marker\n const line = lineRefFor(adj.edge, adj.lane);\n composeLine(\n row,\n railCol,\n line,\n new Set<Direction>(['up', 'down']),\n planeOf(adj.lane, line.role),\n );\n }\n }\n\n // Tee a routed back-arc off its source node row: a horizontal bridge from the\n // node's connector column across to the back-lane rail, ending in a ╮ corner\n // (down+left). Composed (not overwritten) so it occludes / is occluded by any\n // back-arc vertical it crosses.\n function emitBackArcTee(row: CellsRow, nodeLaneNum: number, arc: RoutedBackArc): void {\n const nodeRail = nodeLaneNum * colsPerLane;\n const geomRail = arc.geomLane * colsPerLane;\n const line = backArcLine(arc);\n const plane = backArcPlane(arc);\n for (let col = nodeRail + 1; col < geomRail; col++) {\n composeLine(row, col, line, new Set<Direction>(['left', 'right']), plane);\n }\n composeLine(row, geomRail, line, new Set<Direction>(['down', 'left']), plane);\n }\n\n // Land a routed back-arc into its target node row: a ◂ arrowhead in the node's\n // connector column, a horizontal bridge across to the back-lane rail, ending in\n // a ╯ corner (up+left). Composed so the on-top arc draws the anchor and the\n // others yield their corners beneath it (occlusion arbitrates).\n function emitBackArcLanding(row: CellsRow, nodeLaneNum: number, arc: RoutedBackArc): void {\n const nodeRail = nodeLaneNum * colsPerLane;\n const geomRail = arc.geomLane * colsPerLane;\n const line = backArcLine(arc);\n const plane = backArcPlane(arc);\n composeLine(row, nodeRail + 1, line, new Set<Direction>(['left', 'right']), plane, {\n landingArrow: true,\n });\n for (let col = nodeRail + 2; col < geomRail; col++) {\n composeLine(row, col, line, new Set<Direction>(['left', 'right']), plane);\n }\n composeLine(row, geomRail, line, new Set<Direction>(['up', 'left']), plane);\n }\n\n // Emit a connector row (fork or merge).\n //\n // The CONTINUOUS lane gets the unbroken vertical/sweep; every other\n // participating lane yields into its own corner. In flat mode the continuous\n // lane is the trunk (lane of the node); in focus mode it is the on-path lane\n // (the inbound/outbound edge whose migration is on-path), so the chosen route\n // is drawn as one continuous green line sweeping the merge/fork.\n //\n // Geometry is identical regardless of which lane is continuous; only the\n // NODE-ANCHOR glyph at the trunk rail changes:\n // continuous == trunk → │ (vertical, the trunk passes straight through)\n // continuous == a branch → corner toward that branch\n // merge: ╰ (up+right) fork: ╭ (down+right)\n // The branch's own rail always carries its yield corner (merge ╮ / fork ╯), and\n // the cells between carry horizontals. The continuous (on-path) sweep is placed\n // on the top plane so it occludes the trunk's vertical at the node anchor.\n function emitConnectorRow(\n trunkLane: number,\n branchEntries: readonly { lane: number; edge: ClassifiedEdge }[],\n connectorType: 'fork' | 'merge',\n trunkEdge: ClassifiedEdge | undefined,\n ): CellsRow {\n const row = makeRow();\n const sorted = [...branchEntries].sort((a, b) => a.lane - b.lane);\n if (sorted.length === 0) return row;\n\n const branchByLane = new Map<number, ClassifiedEdge>();\n for (const b of sorted) branchByLane.set(b.lane, b.edge);\n\n // Continuous lane: the on-path participant in focus, else the trunk.\n let continuousLane = trunkLane;\n if (isFocus) {\n if (trunkEdge && highlight.onPath.has(trunkEdge.migrationHash)) {\n continuousLane = trunkLane;\n } else {\n const onPathBranch = sorted.find((b) => highlight.onPath.has(b.edge.migrationHash));\n if (onPathBranch) continuousLane = onPathBranch.lane;\n }\n }\n\n const trunkRailCol = trunkLane * colsPerLane;\n const continuousRailCol = continuousLane * colsPerLane;\n\n // Add a CellLine to a cell (compose, don't overwrite) so occlusion arbitrates.\n function addLine(col: number, line: LineRef, dirs: ReadonlySet<Direction>): void {\n const existing = row[col];\n const cellLine: CellLine = { line, directions: dirs, plane: planeOf(line.lane, line.role) };\n row[col] =\n existing && existing.lines.length > 0\n ? { ...existing, lines: [...existing.lines, cellLine] }\n : { lines: [cellLine] };\n }\n\n const cornerLeftDown: ReadonlySet<Direction> =\n connectorType === 'merge'\n ? new Set<Direction>(['left', 'down'])\n : new Set<Direction>(['left', 'up']);\n\n // ── Base plane: every yielding branch lays its own corner + the horizontal\n // segment to its left (up to the previous branch's rail). These sit on the\n // branch's lane plane; where the continuous sweep crosses them it occludes.\n for (let i = 0; i < sorted.length; i++) {\n const b = sorted[i]!;\n if (b.lane === continuousLane) continue; // continuous drawn separately, on top\n const branchLine = lineRefFor(b.edge, b.lane);\n const railCol = b.lane * colsPerLane;\n addLine(railCol, branchLine, cornerLeftDown);\n const leftBound = i === 0 ? trunkRailCol + 1 : sorted[i - 1]!.lane * colsPerLane + 1;\n for (let col = leftBound; col < railCol; col++) {\n addLine(col, branchLine, new Set<Direction>(['left', 'right']));\n }\n }\n\n // ── The continuous line ──────────────────────────────────────────────────\n const continuousLine: LineRef =\n continuousLane === trunkLane\n ? trunkEdge\n ? lineRefFor(trunkEdge, trunkLane)\n : getRepLine(trunkLane)\n : lineRefFor(branchByLane.get(continuousLane)!, continuousLane);\n\n if (continuousLane === trunkLane) {\n // Trunk passes straight through the node anchor (│), branches yield to it.\n addLine(trunkRailCol, continuousLine, new Set<Direction>(['up', 'down']));\n } else {\n // A branch is continuous: it sweeps from the node anchor across to its own\n // rail, on the TOP plane, occluding the trunk vertical and any intermediate\n // yielding branch corners it passes over.\n const anchorDirs: ReadonlySet<Direction> =\n connectorType === 'merge'\n ? new Set<Direction>(['up', 'right'])\n : new Set<Direction>(['down', 'right']);\n addLine(trunkRailCol, continuousLine, anchorDirs);\n for (let col = trunkRailCol + 1; col < continuousRailCol; col++) {\n addLine(col, continuousLine, new Set<Direction>(['left', 'right']));\n }\n addLine(continuousRailCol, continuousLine, cornerLeftDown);\n }\n\n // Other active lanes (not trunk, not branch): vertical pass-through.\n const skipSet = new Set<number>([trunkLane, ...sorted.map((b) => b.lane)]);\n placeVerticals(row, skipSet);\n placeBackVerticals(row);\n\n return row;\n }\n\n // Process each node in display order\n for (const nodeDisplay of displayOrder) {\n const { hash: nodeHash } = nodeDisplay;\n const nodeLaneNum = nodeLane.get(nodeHash) ?? 0;\n\n activeLanes.add(nodeLaneNum);\n\n // ── 1. Fork connector (BEFORE the node row) ──────────────────────────\n const outEdges = outboundFwd.get(nodeHash) ?? [];\n if (outEdges.length > 1) {\n const trunkChildLane = nodeLane.get(outEdges[0]!.to) ?? nodeLaneNum;\n const branchEntries = outEdges\n .slice(1)\n .map((e) => ({ lane: nodeLane.get(e.to) ?? 0, edge: e }))\n .filter((b) => b.lane !== trunkChildLane && activeLanes.has(b.lane));\n\n if (branchEntries.length > 0) {\n const trunkEdge = outEdges[0];\n const connRow = emitConnectorRow(nodeLaneNum, branchEntries, 'fork', trunkEdge);\n grid.push(connRow);\n assertSingleOwner(connRow, isFocus);\n\n for (const b of branchEntries) activeLanes.delete(b.lane);\n }\n }\n\n // ── 2. Self-loop rows (BEFORE the node row) ───────────────────────────\n const selfMigrations = selfEdgesByNode.get(nodeHash) ?? [];\n for (const selfEdge of selfMigrations) {\n const row = makeRow();\n const railCol = nodeLaneNum * colsPerLane;\n const connCol = nodeLaneNum * colsPerLane + 1;\n const line = lineRefFor(selfEdge, nodeLaneNum);\n row[railCol] = vertCell(line);\n row[connCol] = {\n lines: [\n {\n line,\n directions: new Set<Direction>(),\n plane: planeOf(nodeLaneNum, line.role),\n selfLoop: true,\n },\n ],\n };\n placeVerticals(row, new Set([nodeLaneNum]));\n placeBackVerticals(row);\n grid.push(row);\n }\n\n // ── 3. Node row ────────────────────────────────────────────────────────\n {\n const row = makeRow();\n const railCol = nodeLaneNum * colsPerLane;\n const nodeRef: NodeRef = {\n contractHash: nodeHash,\n isEmpty: nodeHash === EMPTY_CONTRACT_HASH,\n lane: nodeLaneNum,\n role: nodeRoleOf(nodeHash),\n };\n row[railCol] = nodeCell(nodeRef);\n placeVerticals(row, new Set([nodeLaneNum]));\n\n // A back-arc landing ends its vertical at this row, replacing it with a ╯\n // corner — so deactivate landing arcs BEFORE placing back verticals. An\n // adjacent rollback's overlay likewise ends at its target node.\n const landingArcs = backArcsByTarget.get(nodeHash) ?? [];\n for (const arc of landingArcs) activeBackArcs.delete(arc);\n for (const adj of [...activeAdjacent]) {\n if (adj.edge.to === nodeHash) activeAdjacent.delete(adj);\n }\n\n placeBackVerticals(row);\n\n // Back-arc landing: arcs targeting this node sweep from the node anchor\n // (◂ arrowhead) across to their own rail corner (╯). The on-top arc draws\n // the anchor; others yield their corners beneath (occlusion arbitrates).\n for (const arc of landingArcs) {\n emitBackArcLanding(row, nodeLaneNum, arc);\n }\n\n // Back-arc tee: arcs sourced at this node tee off the node row into their\n // back-lane (─ bridge + ╮ corner). The vertical begins on the next row.\n const teeArcs = backArcsBySource.get(nodeHash) ?? [];\n for (const arc of teeArcs) {\n emitBackArcTee(row, nodeLaneNum, arc);\n }\n\n grid.push(row);\n\n // Activate the back-arc verticals AFTER the node row so the rail runs from\n // the next row down to (but not including) the target landing row.\n for (const arc of teeArcs) activeBackArcs.add(arc);\n\n // Activate adjacent-rollback overlays sourced here (their trunk overlay\n // runs from the next row down to the target node).\n for (const adj of adjacentBySource.get(nodeHash) ?? []) {\n activeAdjacent.add({ lane: nodeLaneNum, edge: adj });\n }\n }\n\n // Inbound forward edges run down their lanes below this node. Record each as\n // its lane's current edge NOW (before emitting the back-arc arrow rows, merge\n // connector, and migration rows) so pass-through verticals colour from the\n // forward edge actually occupying the trunk below this node.\n const inEdges = inboundFwd.get(nodeHash) ?? [];\n inEdges.sort((a, b) => a.dirName.localeCompare(b.dirName));\n for (const edge of inEdges) {\n const edgeLane = Math.max(nodeLane.get(edge.from) ?? 0, nodeLane.get(edge.to) ?? 0);\n laneCurrentEdge.set(edgeLane, edge);\n }\n\n // ── 3b. Back-arc arrow rows ──────────────────────────────────────────────\n // For each routed arc sourced here, a │↓ arrow row in its back-lane sits\n // directly below the source node (before the source node's forward inbound\n // migration rows).\n {\n const teeArcs = backArcsBySource.get(nodeHash) ?? [];\n for (const arc of teeArcs) {\n const row = makeRow();\n const railCol = arc.geomLane * colsPerLane;\n const connCol = railCol + 1;\n const line = backArcLine(arc);\n const plane = backArcPlane(arc);\n composeLine(row, railCol, line, new Set<Direction>(['up', 'down']), plane);\n composeLine(row, connCol, line, new Set<Direction>(['down']), plane);\n placeVerticals(row, new Set<number>());\n placeBackVerticals(row);\n grid.push(row);\n }\n }\n\n // ── 4. Merge connector (AFTER the node row) ────────────────────────────\n if (inEdges.length > 1) {\n const branchEntries = inEdges\n .slice(1)\n .map((e) => ({ lane: nodeLane.get(e.from) ?? 0, edge: e }));\n\n const trunkEdge = inEdges[0];\n const connRow = emitConnectorRow(nodeLaneNum, branchEntries, 'merge', trunkEdge);\n grid.push(connRow);\n assertSingleOwner(connRow, isFocus);\n\n for (const b of branchEntries) activeLanes.add(b.lane);\n }\n\n // ── 5. Migration rows (one per inbound edge, ordered by migration hash) ─\n for (const edge of inEdges) {\n const fromLane = nodeLane.get(edge.from) ?? 0;\n const toLane = nodeLane.get(edge.to) ?? 0;\n const edgeLane = Math.max(fromLane, toLane);\n const row = makeRow();\n const railCol = edgeLane * colsPerLane;\n const connCol = edgeLane * colsPerLane + 1;\n const line = lineRefFor(edge, edgeLane);\n\n row[railCol] = vertCell(line);\n row[connCol] = dirCell(line, new Set<Direction>(['up']));\n\n placeVerticals(row, new Set([edgeLane]));\n placeBackVerticals(row);\n grid.push(row);\n }\n\n // ── 5b. Adjacent rollback ↓ rows ─────────────────────────────────────────\n // An adjacent rollback (target is the display-neighbour directly below) is a\n // plain ↓ in the source's own lane — mirror of the forward ↑ — emitted after\n // the source node's forward inbound rows, directly above the target node.\n {\n const adjacents = adjacentBySource.get(nodeHash) ?? [];\n for (const adj of adjacents) {\n const row = makeRow();\n const connCol = nodeLaneNum * colsPerLane + 1;\n const line = lineRefFor(adj, nodeLaneNum);\n const plane = planeOf(nodeLaneNum, line.role);\n // The rail │ belongs to the trunk passing through (drawn by placeVerticals\n // from the lane's current forward edge); only the ↓ arrow is the rollback.\n composeLine(row, connCol, line, new Set<Direction>(['down']), plane);\n placeVerticals(row, new Set<number>());\n placeBackVerticals(row);\n grid.push(row);\n }\n }\n\n // ── 6. Root lane deactivation ─────────────────────────────────────────\n if (inEdges.length === 0) {\n activeLanes.delete(nodeLaneNum);\n }\n }\n\n return grid;\n}\n\n// ---------------------------------------------------------------------------\n// Single-owner invariant — after building a connector row, assert that every\n// cell has at most one DRAWABLE owner once occlusion (topmost plane) is applied.\n// In focus mode a tie at the same plane between an on-path and an off-path line\n// would be a colour ambiguity, so we additionally assert that at the top plane\n// of each cell exactly one role survives.\n// ---------------------------------------------------------------------------\nfunction assertSingleOwner(row: CellsRow, isFocus: boolean): void {\n for (const cell of row) {\n if (cell.lines.length <= 1) continue;\n let topPlane = Number.POSITIVE_INFINITY;\n for (const cl of cell.lines) if (cl.plane < topPlane) topPlane = cl.plane;\n const top = cell.lines.filter((cl: CellLine) => cl.plane === topPlane);\n if (top.length > 1) {\n if (isFocus) {\n const roles = new Set(top.map((cl) => cl.line.role));\n if (roles.size > 1) {\n throw new Error(\n 'migration-graph layout: single-owner invariant violated — two differently-roled lines share the top plane in one cell',\n );\n }\n }\n }\n }\n}\n","import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport type { MigrationListEntry } from './migration-list-types';\n\nexport type MigrationEdgeKind = 'forward' | 'rollback' | 'self';\n\nexport interface MigrationListGraphTopology {\n readonly kindByMigrationHash: ReadonlyMap<string, MigrationEdgeKind>;\n readonly forwardInDegree: ReadonlyMap<string, number>;\n readonly forwardOutDegree: ReadonlyMap<string, number>;\n}\n\n// ---------------------------------------------------------------------------\n// Shared classifier — operates on a normalized edge shape for MigrationGraph.\n// ---------------------------------------------------------------------------\n\ninterface NormalizedEdge {\n readonly hash: string;\n readonly from: string;\n readonly to: string;\n readonly dirName: string;\n}\n\nfunction compareDirNameDesc(a: NormalizedEdge, b: NormalizedEdge): number {\n return b.dirName.localeCompare(a.dirName);\n}\n\nfunction bumpDegree(map: Map<string, number>, key: string): void {\n map.set(key, (map.get(key) ?? 0) + 1);\n}\n\nfunction compareNodesRootFirst(a: string, b: string): number {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n}\n\n/**\n * Shortest-path distance of each node from the forward roots, over the given\n * candidate edges. Roots are the in-degree-0 nodes (baseline first, then lex);\n * a rooted component therefore distances every node by how many forward steps\n * it sits from a root. A component with no root (a pure cycle) is seeded from\n * its single lexically-smallest node so the cycle still gets a stable layering.\n *\n * Crucially this is *shortest* path, not longest: a backward (rollback) edge\n * `deep → shallow` never offers a shorter route to the already-shallower\n * target, so it is inert here. Distances are thus stable whether or not the\n * rollbacks are still in the candidate set — which is what lets the peel below\n * tell a genuine back-edge (target strictly shallower than source) apart from a\n * forward edge that merely happens to share the back-edge's cycle.\n */\nfunction forwardDistances(\n nodes: ReadonlySet<string>,\n candidates: readonly NormalizedEdge[],\n): Map<string, number> {\n const inDegree = new Map<string, number>();\n for (const node of nodes) {\n inDegree.set(node, 0);\n }\n for (const edge of candidates) {\n bumpDegree(inDegree, edge.to);\n }\n\n const roots = [...nodes].filter((node) => (inDegree.get(node) ?? 0) === 0);\n roots.sort(compareNodesRootFirst);\n const seeds = roots.length > 0 ? roots : [...nodes].sort(compareNodesRootFirst).slice(0, 1);\n\n const dist = new Map<string, number>();\n for (const seed of seeds) {\n dist.set(seed, 0);\n }\n\n const maxPasses = nodes.size;\n for (let pass = 0; pass < maxPasses; pass++) {\n let changed = false;\n for (const edge of candidates) {\n const base = dist.get(edge.from);\n if (base === undefined) continue;\n const next = base + 1;\n if (next < (dist.get(edge.to) ?? Number.POSITIVE_INFINITY)) {\n dist.set(edge.to, next);\n changed = true;\n }\n }\n if (!changed) break;\n }\n\n for (const node of nodes) {\n if (!dist.has(node)) {\n dist.set(node, 0);\n }\n }\n\n return dist;\n}\n\nfunction canReachForward(\n start: string,\n goal: string,\n candidates: readonly NormalizedEdge[],\n): boolean {\n if (start === goal) return true;\n\n const outgoing = new Map<string, string[]>();\n for (const edge of candidates) {\n const bucket = outgoing.get(edge.from);\n if (bucket) bucket.push(edge.to);\n else outgoing.set(edge.from, [edge.to]);\n }\n\n const visited = new Set<string>([start]);\n const queue = [start];\n while (queue.length > 0) {\n const node = queue.shift();\n if (node === undefined) continue;\n for (const next of outgoing.get(node) ?? []) {\n if (next === goal) return true;\n if (!visited.has(next)) {\n visited.add(next);\n queue.push(next);\n }\n }\n }\n\n return false;\n}\n\n/**\n * Demote node-skipping rollbacks left forward by the DFS. An edge `from → to`\n * is a rollback exactly when both hold:\n * 1. `to` is a forward-ancestor of `from` — `to` can still reach `from` over\n * the other forward edges, so the edge closes a cycle; and\n * 2. `to` is strictly shallower than `from` (smaller forward distance) — the\n * edge points back toward the root rather than advancing history.\n *\n * Condition 2 is the discriminator: in a cycle created by a rollback every edge\n * satisfies condition 1, but only the rollback itself runs deep → shallow. The\n * forward chain edges run shallow → deep and are never peeled, however many\n * rollbacks converge on the same target. Tight back-edges whose source and\n * target sit at the same distance (mutual two-node cycles) are already resolved\n * by the DFS immediate-parent rule, so they never reach this pass. One edge is\n * peeled per iteration (dirName-descending tie-break) and distances/reachability\n * are recomputed, making the outcome independent of edge input order.\n */\nfunction peelNodeSkippingRollbacks(\n nodes: ReadonlySet<string>,\n kindByMigrationHash: Map<string, MigrationEdgeKind>,\n nonSelf: readonly NormalizedEdge[],\n): void {\n let candidates = nonSelf.filter((edge) => kindByMigrationHash.get(edge.hash) === 'forward');\n\n while (candidates.length > 0) {\n const dist = forwardDistances(nodes, candidates);\n const backEdges = candidates.filter((edge) => {\n const toDist = dist.get(edge.to) ?? 0;\n const fromDist = dist.get(edge.from) ?? 0;\n if (toDist >= fromDist) return false;\n const without = candidates.filter((candidate) => candidate !== edge);\n return canReachForward(edge.to, edge.from, without);\n });\n if (backEdges.length === 0) break;\n\n backEdges.sort(compareDirNameDesc);\n const rollback = backEdges[0];\n if (rollback === undefined) break;\n\n kindByMigrationHash.set(rollback.hash, 'rollback');\n candidates = candidates.filter((edge) => edge !== rollback);\n }\n}\n\n/**\n * DFS with dirName-descending traversal. A GRAY target is a rollback only when it\n * is the immediate DFS parent of the source — cross-links to other GRAY nodes\n * stay forward. A follow-up peel pass demotes node-skipping rollbacks (target is\n * a forward-ancestor of the source and sits strictly shallower than it).\n */\nfunction classifyNormalizedEdges(edges: readonly NormalizedEdge[]): MigrationListGraphTopology {\n const nodes = new Set<string>();\n const kindByMigrationHash = new Map<string, MigrationEdgeKind>();\n const outgoingByFrom = new Map<string, NormalizedEdge[]>();\n const nonSelf: NormalizedEdge[] = [];\n\n for (const edge of edges) {\n nodes.add(edge.from);\n nodes.add(edge.to);\n\n if (edge.from === edge.to) {\n kindByMigrationHash.set(edge.hash, 'self');\n continue;\n }\n\n nonSelf.push(edge);\n const bucket = outgoingByFrom.get(edge.from);\n if (bucket) bucket.push(edge);\n else outgoingByFrom.set(edge.from, [edge]);\n }\n\n for (const bucket of outgoingByFrom.values()) {\n bucket.sort(compareDirNameDesc);\n }\n\n const nonSelfInDegree = new Map<string, number>();\n for (const node of nodes) {\n nonSelfInDegree.set(node, 0);\n }\n for (const bucket of outgoingByFrom.values()) {\n for (const edge of bucket) {\n bumpDegree(nonSelfInDegree, edge.to);\n }\n }\n\n const dfsRoots: string[] = [];\n for (const node of nodes) {\n if ((nonSelfInDegree.get(node) ?? 0) === 0) {\n dfsRoots.push(node);\n }\n }\n dfsRoots.sort((a, b) => {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n });\n if (dfsRoots.length === 0) {\n dfsRoots.push(...[...nodes].sort((a, b) => a.localeCompare(b)));\n }\n\n const WHITE = 0;\n const GRAY = 1;\n const BLACK = 2;\n const color = new Map<string, number>();\n const dfsParent = new Map<string, string | undefined>();\n for (const node of nodes) {\n color.set(node, WHITE);\n }\n\n interface Frame {\n node: string;\n outgoing: readonly NormalizedEdge[];\n index: number;\n }\n const stack: Frame[] = [];\n\n function isImmediateDfsParent(ancestor: string, node: string): boolean {\n return dfsParent.get(node) === ancestor;\n }\n\n function pushFrame(node: string, parent: string | undefined): void {\n color.set(node, GRAY);\n dfsParent.set(node, parent);\n stack.push({ node, outgoing: outgoingByFrom.get(node) ?? [], index: 0 });\n }\n\n function runDfsFrom(root: string): void {\n if (color.get(root) !== WHITE) return;\n pushFrame(root, undefined);\n\n while (stack.length > 0) {\n const frame = stack[stack.length - 1];\n if (frame === undefined) break;\n if (frame.index >= frame.outgoing.length) {\n color.set(frame.node, BLACK);\n stack.pop();\n continue;\n }\n\n const edge = frame.outgoing[frame.index];\n frame.index += 1;\n if (edge === undefined) continue;\n\n const v = edge.to;\n const vColor = color.get(v);\n if (vColor === GRAY && isImmediateDfsParent(v, frame.node)) {\n kindByMigrationHash.set(edge.hash, 'rollback');\n } else {\n kindByMigrationHash.set(edge.hash, 'forward');\n if (vColor === WHITE) {\n pushFrame(v, frame.node);\n }\n }\n }\n }\n\n for (const root of dfsRoots) {\n runDfsFrom(root);\n }\n const remainingWhite = [...nodes].filter((node) => color.get(node) === WHITE);\n remainingWhite.sort((a, b) => a.localeCompare(b));\n for (const root of remainingWhite) {\n runDfsFrom(root);\n }\n\n peelNodeSkippingRollbacks(nodes, kindByMigrationHash, nonSelf);\n\n const forwardInDegree = new Map<string, number>();\n const forwardOutDegree = new Map<string, number>();\n\n for (const edge of edges) {\n if (kindByMigrationHash.get(edge.hash) !== 'forward') continue;\n bumpDegree(forwardOutDegree, edge.from);\n bumpDegree(forwardInDegree, edge.to);\n }\n\n return {\n kindByMigrationHash,\n forwardInDegree,\n forwardOutDegree,\n };\n}\n\nfunction canonicalFrom(from: string | null): string {\n return from ?? EMPTY_CONTRACT_HASH;\n}\n\n/**\n * Classify forward/rollback/self for a Tier-2 `MigrationListEntry[]` edge set.\n */\nexport function classifyMigrationListGraphTopology(\n entries: readonly MigrationListEntry[],\n): MigrationListGraphTopology {\n const normalized: NormalizedEdge[] = entries.map((entry) => ({\n hash: entry.hash,\n from: canonicalFrom(entry.fromContract),\n to: entry.toContract,\n dirName: entry.name,\n }));\n return classifyNormalizedEdges(normalized);\n}\n\n/**\n * Classify forward/rollback/self for a `MigrationGraph` edge set (Tier-3).\n */\nexport function classifyMigrationGraphTopology(graph: MigrationGraph): MigrationListGraphTopology {\n const normalized: NormalizedEdge[] = [];\n for (const edges of graph.forwardChain.values()) {\n for (const edge of edges) {\n normalized.push({\n hash: edge.migrationHash,\n from: edge.from,\n to: edge.to,\n dirName: edge.dirName,\n });\n }\n }\n return classifyNormalizedEdges(normalized);\n}\n","import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport {\n classifyMigrationGraphTopology,\n type MigrationEdgeKind,\n type MigrationListGraphTopology,\n} from './migration-list-graph-topology';\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * A migration edge with its forward/rollback/self classification resolved.\n * `from` and `to` are contract hashes (EMPTY_CONTRACT_HASH for the baseline).\n */\nexport interface ClassifiedEdge {\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly dirName: string;\n readonly kind: MigrationEdgeKind;\n}\n\n/**\n * The pure-data output of the row-model stage.\n *\n * `nodes` is the vertical ordering of contract nodes: index 0 is the topmost\n * row (the tip), the last non-null entry is the bottommost root. `null`\n * sentinels separate disjoint components (the blank row in the rendered\n * output). Ordering within each component is deterministic: longest forward-\n * path rank from forward roots (tips at rank max, roots at 0), with lex-\n * ascending tie-break among same-rank siblings.\n *\n * `edges` carries every classified migration. `edgesByFrom` and `edgesByTo`\n * are pre-built lookup maps for the column allocator.\n */\nexport interface MigrationGraphRowModel {\n readonly nodes: readonly (string | null)[];\n readonly edges: readonly ClassifiedEdge[];\n readonly edgesByFrom: ReadonlyMap<string, readonly ClassifiedEdge[]>;\n readonly edgesByTo: ReadonlyMap<string, readonly ClassifiedEdge[]>;\n}\n\nexport interface BuildMigrationGraphRowsOptions {\n readonly contractHash?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Weak connectivity — identify disjoint components\n// ---------------------------------------------------------------------------\n\n/**\n * Return the weakly-connected components of `graph` as an array of node sets,\n * ordered so the component containing EMPTY_CONTRACT_HASH comes first (if\n * present), with remaining components sorted by their lex-smallest node hash.\n */\nfunction weaklyConnectedComponents(graph: MigrationGraph): readonly ReadonlySet<string>[] {\n const visited = new Set<string>();\n const adjacency = new Map<string, string[]>();\n\n function addAdjacent(a: string, b: string): void {\n const aList = adjacency.get(a);\n if (aList) aList.push(b);\n else adjacency.set(a, [b]);\n const bList = adjacency.get(b);\n if (bList) bList.push(a);\n else adjacency.set(b, [a]);\n }\n\n for (const edges of graph.forwardChain.values()) {\n for (const edge of edges) {\n if (edge.from !== edge.to) {\n addAdjacent(edge.from, edge.to);\n }\n }\n }\n\n // Ensure all nodes (including isolated self-loops) are reachable\n for (const node of graph.nodes) {\n if (!adjacency.has(node)) {\n adjacency.set(node, []);\n }\n }\n\n const components: Set<string>[] = [];\n\n function bfsComponent(start: string): Set<string> {\n const component = new Set<string>();\n const queue = [start];\n while (queue.length > 0) {\n const node = queue.shift();\n if (node === undefined || visited.has(node)) continue;\n visited.add(node);\n component.add(node);\n for (const neighbor of adjacency.get(node) ?? []) {\n if (!visited.has(neighbor)) {\n queue.push(neighbor);\n }\n }\n }\n return component;\n }\n\n // Deterministic: visit nodes in a fixed order (EMPTY first, then lex)\n const allNodes = [...graph.nodes].sort((a, b) => {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n });\n\n for (const node of allNodes) {\n if (!visited.has(node)) {\n components.push(bfsComponent(node));\n }\n }\n\n // Order: EMPTY component first, others by lex-smallest node hash\n components.sort((a, b) => {\n const aHasEmpty = a.has(EMPTY_CONTRACT_HASH);\n const bHasEmpty = b.has(EMPTY_CONTRACT_HASH);\n if (aHasEmpty && !bHasEmpty) return -1;\n if (!aHasEmpty && bHasEmpty) return 1;\n const aMin = [...a].sort((x, y) => x.localeCompare(y))[0] ?? '';\n const bMin = [...b].sort((x, y) => x.localeCompare(y))[0] ?? '';\n return aMin.localeCompare(bMin);\n });\n\n return components;\n}\n\n// ---------------------------------------------------------------------------\n// Longest forward-path node ordering within a component\n// ---------------------------------------------------------------------------\n\nfunction forwardRootsInComponent(\n componentNodes: ReadonlySet<string>,\n topology: MigrationListGraphTopology,\n): readonly string[] {\n const roots: string[] = [];\n for (const node of componentNodes) {\n if ((topology.forwardInDegree.get(node) ?? 0) === 0) {\n roots.push(node);\n }\n }\n roots.sort((a, b) => {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n });\n if (roots.length > 0) return roots;\n\n return [...componentNodes].sort((a, b) => {\n if (a === EMPTY_CONTRACT_HASH) return -1;\n if (b === EMPTY_CONTRACT_HASH) return 1;\n return a.localeCompare(b);\n });\n}\n\nfunction compareNodesTipsFirst(a: string, b: string, rank: ReadonlyMap<string, number>): number {\n const rankA = rank.get(a) ?? 0;\n const rankB = rank.get(b) ?? 0;\n if (rankA !== rankB) return rankB - rankA;\n if (a === EMPTY_CONTRACT_HASH) return 1;\n if (b === EMPTY_CONTRACT_HASH) return -1;\n return a.localeCompare(b);\n}\n\n/**\n * Layer nodes by longest forward-path rank from forward roots within the\n * component. Rank 0 is the root (bottom row); the maximum rank is the tip\n * (top row). Emits rank-descending with lex-ascending tie-break among siblings\n * at the same rank — stable across edge-insertion order and correct under\n * diamonds, cross-links, and rollbacks.\n */\nfunction maxRank(rank: ReadonlyMap<string, number>): number {\n let max = 0;\n for (const value of rank.values()) {\n if (value > max) max = value;\n }\n return max;\n}\n\nfunction layerNodesByLongestForwardPath(\n componentNodes: ReadonlySet<string>,\n topology: MigrationListGraphTopology,\n graph: MigrationGraph,\n contractHash: string | undefined,\n): readonly string[] {\n const forwardOut = new Map<string, string[]>();\n\n for (const node of componentNodes) {\n forwardOut.set(node, []);\n }\n\n for (const edges of graph.forwardChain.values()) {\n for (const edge of edges) {\n if (!componentNodes.has(edge.from) || !componentNodes.has(edge.to)) continue;\n if (edge.from === edge.to) continue;\n if (topology.kindByMigrationHash.get(edge.migrationHash) !== 'forward') continue;\n const bucket = forwardOut.get(edge.from);\n if (bucket) bucket.push(edge.to);\n }\n }\n\n const roots = forwardRootsInComponent(componentNodes, topology);\n const rank = new Map<string, number>();\n for (const root of roots) {\n rank.set(root, 0);\n }\n\n const maxPasses = componentNodes.size;\n for (let pass = 0; pass < maxPasses; pass++) {\n let changed = false;\n for (const node of componentNodes) {\n const base = rank.get(node);\n if (base === undefined) continue;\n for (const to of forwardOut.get(node) ?? []) {\n const next = base + 1;\n const prev = rank.get(to) ?? -1;\n if (next > prev) {\n rank.set(to, next);\n changed = true;\n }\n }\n }\n if (!changed) break;\n }\n\n for (const node of componentNodes) {\n if (!rank.has(node)) {\n rank.set(node, 0);\n }\n }\n\n if (\n contractHash !== undefined &&\n contractHash !== EMPTY_CONTRACT_HASH &&\n componentNodes.has(contractHash) &&\n (forwardOut.get(contractHash) ?? []).length === 0\n ) {\n rank.set(contractHash, maxRank(rank) + 1);\n }\n\n return [...componentNodes].sort((a, b) => compareNodesTipsFirst(a, b, rank));\n}\n\n// ---------------------------------------------------------------------------\n// Public builder\n// ---------------------------------------------------------------------------\n\n/**\n * Build the row model from a tolerant `MigrationGraph`.\n *\n * The row model is the first pure-data stage of the `migration graph` render\n * pipeline. It:\n * - classifies every edge as `forward`, `rollback`, or `self`;\n * - produces a deterministic vertical node ordering (tips at index 0, roots\n * at the end) within each weakly-connected component;\n * - separates disjoint components with `null` sentinels;\n * - optionally prepends a detached current contract as its own single-node\n * component when `contractHash` is not already in the graph.\n *\n * No columns, no lane allocation, no glyphs, no rendering.\n */\n/**\n * Resolve the detached current contract, if any: a real contract (not the\n * empty baseline) that no migration on disk produces, so it is absent from\n * the graph. Such a contract renders as a floating node rather than\n * decorating an existing one. Returns the hash when detached, else undefined.\n */\nfunction detachedContractHash(\n graph: MigrationGraph,\n contractHash: string | undefined,\n): string | undefined {\n return contractHash !== undefined &&\n contractHash !== EMPTY_CONTRACT_HASH &&\n !graph.nodes.has(contractHash)\n ? contractHash\n : undefined;\n}\n\nfunction isForwardLeaf(node: string, edges: readonly ClassifiedEdge[]): boolean {\n return !edges.some((e) => e.kind === 'forward' && e.from === node && e.from !== e.to);\n}\n\nfunction forwardReachableFrom(\n start: string,\n forwardTo: ReadonlyMap<string, readonly string[]>,\n): ReadonlySet<string> {\n const reachable = new Set<string>([start]);\n const queue = [start];\n while (queue.length > 0) {\n const node = queue.shift();\n if (node === undefined) continue;\n for (const next of forwardTo.get(node) ?? []) {\n if (!reachable.has(next)) {\n reachable.add(next);\n queue.push(next);\n }\n }\n }\n return reachable;\n}\n\nfunction buildForwardToMap(edges: readonly ClassifiedEdge[]): Map<string, string[]> {\n const forwardTo = new Map<string, string[]>();\n for (const edge of edges) {\n if (edge.kind !== 'forward' || edge.from === edge.to) continue;\n const bucket = forwardTo.get(edge.from);\n if (bucket) bucket.push(edge.to);\n else forwardTo.set(edge.from, [edge.to]);\n }\n return forwardTo;\n}\n\nfunction sortEdgesForContractHashTrunk(\n edges: ClassifiedEdge[],\n contractHash: string | undefined,\n): ClassifiedEdge[] {\n if (\n contractHash === undefined ||\n contractHash === EMPTY_CONTRACT_HASH ||\n !isForwardLeaf(contractHash, edges)\n ) {\n return edges;\n }\n\n const preferredLeaf = contractHash;\n const forwardTo = buildForwardToMap(edges);\n const reachability = new Map<string, ReadonlySet<string>>();\n function canReachContractHash(from: string): boolean {\n let cached = reachability.get(from);\n if (cached === undefined) {\n cached = forwardReachableFrom(from, forwardTo);\n reachability.set(from, cached);\n }\n return cached.has(preferredLeaf);\n }\n\n function trunkBias(edge: ClassifiedEdge): number {\n if (edge.kind !== 'forward' || edge.from === edge.to) return 0;\n if (edge.to === preferredLeaf) return 2;\n if (canReachContractHash(edge.to)) return 1;\n return 0;\n }\n\n return edges\n .map((edge, index) => ({ edge, index, bias: trunkBias(edge) }))\n .sort((a, b) => {\n if (a.edge.from !== b.edge.from) return a.index - b.index;\n if (a.bias !== b.bias) return b.bias - a.bias;\n return a.index - b.index;\n })\n .map(({ edge }) => edge);\n}\n\nfunction rebuildEdgeLookupMaps(edges: readonly ClassifiedEdge[]): {\n edgesByFrom: Map<string, ClassifiedEdge[]>;\n edgesByTo: Map<string, ClassifiedEdge[]>;\n} {\n const edgesByFrom = new Map<string, ClassifiedEdge[]>();\n const edgesByTo = new Map<string, ClassifiedEdge[]>();\n for (const classified of edges) {\n const fromBucket = edgesByFrom.get(classified.from);\n if (fromBucket) fromBucket.push(classified);\n else edgesByFrom.set(classified.from, [classified]);\n\n const toBucket = edgesByTo.get(classified.to);\n if (toBucket) toBucket.push(classified);\n else edgesByTo.set(classified.to, [classified]);\n }\n return { edgesByFrom, edgesByTo };\n}\n\nexport function buildMigrationGraphRows(\n graph: MigrationGraph,\n options: BuildMigrationGraphRowsOptions = {},\n): MigrationGraphRowModel {\n const emptyModel: MigrationGraphRowModel = {\n nodes: [],\n edges: [],\n edgesByFrom: new Map(),\n edgesByTo: new Map(),\n };\n\n if (graph.nodes.size === 0) {\n const detached = detachedContractHash(graph, options.contractHash);\n return detached !== undefined ? { ...emptyModel, nodes: [detached] } : emptyModel;\n }\n\n // 1. Classify all edges (shared classifier: DFS plus a peel pass that demotes\n // node-skipping rollbacks, so the forward subgraph is acyclic)\n const topology = classifyMigrationGraphTopology(graph);\n\n // 2. Build classified edge list\n const edges: ClassifiedEdge[] = [];\n\n for (const edgeList of graph.forwardChain.values()) {\n for (const edge of edgeList) {\n const kind = topology.kindByMigrationHash.get(edge.migrationHash) ?? 'forward';\n edges.push({\n migrationHash: edge.migrationHash,\n from: edge.from,\n to: edge.to,\n dirName: edge.dirName,\n kind,\n });\n }\n }\n\n const sortedEdges = sortEdgesForContractHashTrunk(edges, options.contractHash);\n const { edgesByFrom, edgesByTo } = rebuildEdgeLookupMaps(sortedEdges);\n\n // 3. Find weakly-connected components (ordered: EMPTY first, then lex)\n const components = weaklyConnectedComponents(graph);\n\n // 4. Layer nodes by longest forward path per component, separate with null\n const nodes: (string | null)[] = [];\n for (let i = 0; i < components.length; i++) {\n if (i > 0) nodes.push(null);\n const component = components[i];\n if (component === undefined) continue;\n const ordered = layerNodesByLongestForwardPath(\n component,\n topology,\n graph,\n options.contractHash,\n );\n for (const node of ordered) {\n nodes.push(node);\n }\n }\n\n const detached = detachedContractHash(graph, options.contractHash);\n if (detached !== undefined) {\n if (nodes.length > 0) {\n nodes.unshift(null);\n }\n nodes.unshift(detached);\n }\n\n return {\n nodes,\n edges: sortedEdges,\n edgesByFrom,\n edgesByTo,\n };\n}\n","import type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport type { GlyphMode } from '../glyph-mode';\nimport {\n computeLabelColumn,\n computeMaxDirNameWidth,\n renderMigrationGraphCommand,\n} from './migration-graph-command-render';\nimport { buildGrid } from './migration-graph-grid-layout';\nimport type { MigrationEdgeAnnotation } from './migration-graph-labels';\nimport type { Highlight } from './migration-graph-model';\nimport { buildMigrationGraphRows } from './migration-graph-rows';\nimport {\n buildEdgeAnnotationsByHashFromListEntries,\n buildRefsByHashFromListEntries,\n type MigrationListStyler,\n} from './migration-list-render';\nimport type { MigrationListEntry } from './migration-list-types';\n\nexport { buildEdgeAnnotationsByHashFromListEntries } from './migration-list-render';\n\nexport function mergeMigrationEdgeAnnotations(\n listOverlay: ReadonlyMap<string, MigrationEdgeAnnotation>,\n statusOverlay: ReadonlyMap<string, MigrationEdgeAnnotation>,\n): ReadonlyMap<string, MigrationEdgeAnnotation> {\n const merged = new Map<string, MigrationEdgeAnnotation>();\n for (const [migrationHash, listAnnotation] of listOverlay) {\n const statusAnnotation = statusOverlay.get(migrationHash);\n merged.set(migrationHash, {\n ...listAnnotation,\n ...(statusAnnotation?.status !== undefined ? { status: statusAnnotation.status } : {}),\n });\n }\n return merged;\n}\n\n/**\n * Translate `migrate --show` per-edge path-highlight annotations into a\n * {@link Highlight}. With any `pathHighlight` present the result is focus mode\n * (on-path lifted green, off-path dim); otherwise flat (lane-rotation colour).\n */\nexport function highlightFromEdgeAnnotations(\n edgeAnnotationsByHash: ReadonlyMap<string, MigrationEdgeAnnotation>,\n): Highlight {\n const onPath = new Set<string>();\n let anyPathHighlight = false;\n for (const [migrationHash, annotation] of edgeAnnotationsByHash) {\n if (annotation.pathHighlight === undefined) continue;\n anyPathHighlight = true;\n if (annotation.pathHighlight === 'on-path') onPath.add(migrationHash);\n }\n return anyPathHighlight ? { mode: 'focus', onPath } : { mode: 'flat', onPath: new Set() };\n}\n\nexport interface RenderMigrationGraphSpaceTreeInput {\n readonly graph: MigrationGraph;\n readonly migrations: readonly MigrationListEntry[];\n readonly liveContractHash: string;\n readonly glyphMode: GlyphMode;\n readonly colorize: boolean;\n readonly refsByHash?: ReadonlyMap<string, readonly string[]>;\n readonly statusOverlayByHash?: ReadonlyMap<string, MigrationEdgeAnnotation>;\n readonly dbHash?: string;\n readonly styler?: MigrationListStyler;\n /**\n * Cross-space override for the gutter→label column (the widest gutter across\n * sibling space sections, plus the label gap). Named for historical\n * continuity with the previous renderer's prefix-width input.\n */\n readonly globalMaxEdgeTreePrefixWidth?: number;\n readonly globalMaxDirNameWidth?: number;\n /**\n * Whether this render is for the app space. When false, `contractHash` is not\n * forwarded to `buildMigrationGraphRows` (suppressing the floating working-\n * contract node) and the `@contract` marker is suppressed. Defaults to `true`.\n */\n readonly isAppSpace?: boolean;\n}\n\nexport interface ComputeGlobalMaxEdgeTreePrefixWidthInput {\n readonly graph: MigrationGraph;\n readonly liveContractHash: string;\n}\n\nfunction buildGridForInput(input: ComputeGlobalMaxEdgeTreePrefixWidthInput): {\n readonly grid: ReturnType<typeof buildGrid>;\n readonly rowModel: ReturnType<typeof buildMigrationGraphRows>;\n} {\n const rowModel = buildMigrationGraphRows(input.graph, { contractHash: input.liveContractHash });\n const grid = buildGrid(rowModel, {}, { mode: 'flat', onPath: new Set() });\n return { grid, rowModel };\n}\n\n/**\n * The widest gutter→label column across the given space layouts. Cross-space\n * callers pass this back in so every section's labels share one column.\n */\nexport function computeGlobalMaxEdgeTreePrefixWidth(\n inputs: readonly ComputeGlobalMaxEdgeTreePrefixWidthInput[],\n glyphMode: GlyphMode = 'unicode',\n): number {\n let globalMax = 0;\n for (const input of inputs) {\n const { grid } = buildGridForInput(input);\n globalMax = Math.max(globalMax, computeLabelColumn(grid, glyphMode));\n }\n return globalMax;\n}\n\nexport function computeGlobalMaxDirNameWidth(\n inputs: readonly ComputeGlobalMaxEdgeTreePrefixWidthInput[],\n): number {\n let globalMax = 0;\n for (const input of inputs) {\n const { rowModel } = buildGridForInput(input);\n globalMax = Math.max(globalMax, computeMaxDirNameWidth(rowModel));\n }\n return globalMax;\n}\n\nfunction renderMigrationGraphSpaceTreeInternal(input: RenderMigrationGraphSpaceTreeInput): string {\n const appSpace = input.isAppSpace !== false;\n const rowModel = buildMigrationGraphRows(input.graph, {\n ...(appSpace ? { contractHash: input.liveContractHash } : {}),\n });\n const listOverlay = buildEdgeAnnotationsByHashFromListEntries(input.migrations);\n const edgeAnnotationsByHash =\n input.statusOverlayByHash === undefined\n ? listOverlay\n : mergeMigrationEdgeAnnotations(listOverlay, input.statusOverlayByHash);\n const highlight = highlightFromEdgeAnnotations(edgeAnnotationsByHash);\n const grid = buildGrid(rowModel, {}, highlight);\n\n return renderMigrationGraphCommand({\n grid,\n rowModel,\n colorize: input.colorize,\n glyphMode: input.glyphMode,\n contractHash: input.liveContractHash,\n isAppSpace: appSpace,\n edgeAnnotationsByHash,\n refsByHash: input.refsByHash ?? buildRefsByHashFromListEntries(input.migrations),\n ...(input.dbHash !== undefined ? { dbHash: input.dbHash } : {}),\n ...(input.styler !== undefined ? { styler: input.styler } : {}),\n ...(input.globalMaxEdgeTreePrefixWidth !== undefined\n ? { globalLabelColumn: input.globalMaxEdgeTreePrefixWidth }\n : {}),\n ...(input.globalMaxDirNameWidth !== undefined\n ? { globalMaxDirNameWidth: input.globalMaxDirNameWidth }\n : {}),\n });\n}\n\nexport function renderMigrationGraphSpaceTree(input: RenderMigrationGraphSpaceTreeInput): string {\n return renderMigrationGraphSpaceTreeInternal(input);\n}\n\nexport function renderMigrationGraphSpaceTrees(\n inputs: readonly RenderMigrationGraphSpaceTreeInput[],\n): readonly string[] {\n const globalInputs: ComputeGlobalMaxEdgeTreePrefixWidthInput[] = inputs.map((input) => ({\n graph: input.graph,\n liveContractHash: input.liveContractHash,\n }));\n const glyphMode = inputs[0]?.glyphMode ?? 'unicode';\n const globalLabelColumn =\n inputs.length > 1 ? computeGlobalMaxEdgeTreePrefixWidth(globalInputs, glyphMode) : undefined;\n const globalMaxDirName =\n inputs.length > 1 ? computeGlobalMaxDirNameWidth(globalInputs) : undefined;\n return inputs.map((input) =>\n renderMigrationGraphSpaceTreeInternal({\n ...input,\n ...(globalLabelColumn !== undefined\n ? { globalMaxEdgeTreePrefixWidth: globalLabelColumn }\n : {}),\n ...(globalMaxDirName !== undefined ? { globalMaxDirNameWidth: globalMaxDirName } : {}),\n }),\n );\n}\n\nexport function indentMigrationGraphTreeBlock(treeOutput: string, indent: string): string {\n if (treeOutput.length === 0) {\n return treeOutput;\n }\n return treeOutput\n .split('\\n')\n .map((line) => (line.length === 0 ? line : `${indent}${line}`))\n .join('\\n');\n}\n","import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport type { MigrationEdge, MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport type { GlyphMode } from '../glyph-mode';\nimport type { MigrationEdgeAnnotation } from './migration-graph-labels';\nimport {\n computeGlobalMaxDirNameWidth,\n computeGlobalMaxEdgeTreePrefixWidth,\n indentMigrationGraphTreeBlock,\n renderMigrationGraphSpaceTree,\n} from './migration-graph-space-render';\nimport type { MigrationListEntry, MigrationListResult } from './migration-list-types';\n\nexport type { GlyphMode } from '../glyph-mode';\nexport type { MigrationEdgeKind } from './migration-list-graph-topology';\nexport type {\n MigrationListEntry,\n MigrationListResult,\n MigrationSpaceListEntry,\n} from './migration-list-types';\n\n/**\n * Semantic styler for `migration list` output tokens. Token-typed so\n * the renderer composes presentation-neutral fragments and the styler\n * decides how each token kind is decorated (ANSI codes, plain text,\n * etc.). The renderer pads with raw spaces *outside* styled tokens so\n * visible column widths stay stable regardless of what the styler\n * emits — adding ANSI escape sequences never disturbs alignment.\n *\n * `invariants` and `refs` receive the underlying string arrays rather\n * than a pre-joined string so per-element styling (e.g. distinguishing\n * the live-DB `db` marker from user-named refs) is possible without\n * having to re-parse a joined block.\n */\nexport interface MigrationListStyler {\n kind(text: string): string;\n dirName(text: string): string;\n sourceHash(text: string): string;\n destHash(text: string): string;\n glyph(text: string): string;\n lane(text: string): string;\n invariants(ids: readonly string[]): string;\n refs(names: readonly string[]): string;\n spaceHeading(text: string): string;\n summary(text: string): string;\n emptyState(text: string): string;\n}\n\nexport const IDENTITY_MIGRATION_LIST_STYLER: MigrationListStyler = {\n kind: (text) => text,\n dirName: (text) => text,\n sourceHash: (text) => text,\n destHash: (text) => text,\n glyph: (text) => text,\n lane: (text) => text,\n invariants: (ids) => `{${ids.join(', ')}}`,\n refs: (names) => `(${names.join(', ')})`,\n spaceHeading: (text) => text,\n summary: (text) => text,\n emptyState: (text) => text,\n};\n\nfunction canonicalFrom(from: string | null): string {\n return from ?? EMPTY_CONTRACT_HASH;\n}\n\nexport function migrationGraphFromListEntries(\n entries: readonly MigrationListEntry[],\n): MigrationGraph {\n const nodes = new Set<string>();\n const forwardChain = new Map<string, MigrationEdge[]>();\n const reverseChain = new Map<string, MigrationEdge[]>();\n const migrationByHash = new Map<string, MigrationEdge>();\n\n for (const entry of entries) {\n const from = canonicalFrom(entry.fromContract);\n const edge: MigrationEdge = {\n from,\n to: entry.toContract,\n migrationHash: entry.hash,\n dirName: entry.name,\n createdAt: entry.createdAt,\n invariants: entry.providedInvariants,\n };\n nodes.add(from);\n nodes.add(entry.toContract);\n const forward = forwardChain.get(from);\n if (forward) forward.push(edge);\n else forwardChain.set(from, [edge]);\n const reverse = reverseChain.get(entry.toContract);\n if (reverse) reverse.push(edge);\n else reverseChain.set(entry.toContract, [edge]);\n migrationByHash.set(entry.hash, edge);\n }\n\n return { nodes, forwardChain, reverseChain, migrationByHash };\n}\n\nexport function buildEdgeAnnotationsByHashFromListEntries(\n entries: readonly MigrationListEntry[],\n): ReadonlyMap<string, MigrationEdgeAnnotation> {\n const annotations = new Map<string, MigrationEdgeAnnotation>();\n for (const entry of entries) {\n annotations.set(entry.hash, {\n operationCount: entry.operationCount,\n invariants: entry.providedInvariants,\n });\n }\n return annotations;\n}\n\nexport function buildRefsByHashFromListEntries(\n entries: readonly MigrationListEntry[],\n): ReadonlyMap<string, readonly string[]> {\n const refsByHash = new Map<string, readonly string[]>();\n for (const entry of entries) {\n if (entry.refs.length > 0) {\n refsByHash.set(entry.toContract, entry.refs);\n }\n }\n return refsByHash;\n}\n\nfunction formatEmptyStateLine(spaceId: string, style: MigrationListStyler): string {\n return style.emptyState(`There are no migrations in migrations/${spaceId}/ yet`);\n}\n\nfunction renderSpaceTreeBlock(\n spaceId: string,\n migrations: readonly MigrationListEntry[],\n multiSpace: boolean,\n glyphMode: GlyphMode,\n style: MigrationListStyler,\n colorize: boolean,\n liveContractHash: string,\n graphForSpace: (spaceId: string) => MigrationGraph | undefined,\n appSpaceId: string | undefined,\n globalMaxEdgeTreePrefixWidth?: number,\n globalMaxDirNameWidth?: number,\n): readonly string[] {\n if (migrations.length === 0) {\n const emptyLine = formatEmptyStateLine(spaceId, style);\n if (!multiSpace) {\n return [emptyLine];\n }\n return [style.spaceHeading(`${spaceId}:`), ` ${emptyLine}`];\n }\n\n const graph = graphForSpace(spaceId) ?? migrationGraphFromListEntries(migrations);\n const isAppSpace = appSpaceId === undefined ? undefined : spaceId === appSpaceId;\n const treeOutput = renderMigrationGraphSpaceTree({\n graph,\n migrations,\n liveContractHash,\n glyphMode,\n colorize,\n refsByHash: buildRefsByHashFromListEntries(migrations),\n styler: style,\n ...(isAppSpace !== undefined ? { isAppSpace } : {}),\n ...(globalMaxEdgeTreePrefixWidth !== undefined ? { globalMaxEdgeTreePrefixWidth } : {}),\n ...(globalMaxDirNameWidth !== undefined ? { globalMaxDirNameWidth } : {}),\n });\n\n if (!multiSpace) {\n return treeOutput.length === 0 ? [] : [treeOutput];\n }\n\n const indented = indentMigrationGraphTreeBlock(treeOutput, ' ');\n return [style.spaceHeading(`${spaceId}:`), indented];\n}\n\nexport interface RenderMigrationListWithStyleOptions {\n readonly colorize?: boolean;\n readonly liveContractHash?: string;\n readonly graphForSpace?: (spaceId: string) => MigrationGraph | undefined;\n /**\n * The space ID that is the app contract space. When provided, `@contract`\n * and the floating working-contract node are shown only for this space.\n * When absent, the renderer falls back to the default (`isAppSpace: true`\n * for every space), which is safe for single-space callers.\n */\n readonly appSpaceId?: string;\n}\n\n/**\n * Compose the styled `migration list` human output via the shared tree\n * renderer. Each on-disk migration is one edge row with package-fact\n * annotations; refs decorate destination contract nodes.\n *\n * `options.colorize` must match whether `style` emits ANSI (e.g. both true for\n * `createAnsiMigrationListStyler({ useColor: true })`).\n */\nexport function renderMigrationListWithStyle(\n result: MigrationListResult,\n style: MigrationListStyler,\n glyphMode: GlyphMode = 'unicode',\n options: RenderMigrationListWithStyleOptions = {},\n): string {\n const multiSpace = result.spaces.length > 1;\n const colorize = options.colorize ?? false;\n const liveContractHash = options.liveContractHash ?? EMPTY_CONTRACT_HASH;\n const graphForSpace = options.graphForSpace ?? (() => undefined);\n const appSpaceId = options.appSpaceId;\n const globalLayoutInputs = multiSpace\n ? result.spaces\n .filter((space) => space.migrations.length > 0)\n .map((space) => ({\n graph: graphForSpace(space.space) ?? migrationGraphFromListEntries(space.migrations),\n liveContractHash,\n }))\n : [];\n const globalMaxEdgeTreePrefixWidth =\n globalLayoutInputs.length > 0\n ? computeGlobalMaxEdgeTreePrefixWidth(globalLayoutInputs)\n : undefined;\n const globalMaxDirNameWidth =\n globalLayoutInputs.length > 0 ? computeGlobalMaxDirNameWidth(globalLayoutInputs) : undefined;\n const lines: string[] = [];\n\n for (let index = 0; index < result.spaces.length; index++) {\n const space = result.spaces[index]!;\n if (index > 0) {\n lines.push('');\n }\n lines.push(\n ...renderSpaceTreeBlock(\n space.space,\n space.migrations,\n multiSpace,\n glyphMode,\n style,\n colorize,\n liveContractHash,\n graphForSpace,\n appSpaceId,\n globalMaxEdgeTreePrefixWidth,\n globalMaxDirNameWidth,\n ),\n );\n }\n\n const totalMigrations = result.spaces.reduce(\n (count, space) => count + space.migrations.length,\n 0,\n );\n if (totalMigrations > 0) {\n lines.push('');\n lines.push(style.summary(result.summary));\n }\n\n return lines.join('\\n');\n}\n\nexport function renderMigrationList(result: MigrationListResult): string {\n return renderMigrationListWithStyle(result, IDENTITY_MIGRATION_LIST_STYLER);\n}\n","import { bold, cyan, cyanBright, dim, green, yellow } from 'colorette';\nimport { IDENTITY_MIGRATION_LIST_STYLER, type MigrationListStyler } from './migration-list-render';\n\nexport type MigrationListStylerWithMarkers = MigrationListStyler & {\n markers(names: readonly string[]): string;\n};\n\nfunction hasMarkersFormatter(\n styler: MigrationListStyler,\n): styler is MigrationListStylerWithMarkers {\n return 'markers' in styler && typeof styler.markers === 'function';\n}\n\nfunction styleMarkerName(name: string): string {\n return name === CONTRACT_MARKER_NAME ? bold(green(name)) : green(name);\n}\n\nfunction plainMarkers(names: readonly string[]): string {\n return names.map((name) => `@${name}`).join(' ');\n}\n\nexport function formatContractNodeOverlays(\n styler: MigrationListStyler,\n markers: readonly string[],\n refs: readonly string[],\n): string {\n const parts: string[] = [];\n if (markers.length > 0) {\n parts.push(hasMarkersFormatter(styler) ? styler.markers(markers) : plainMarkers(markers));\n }\n if (refs.length > 0) {\n parts.push(styler.refs(refs));\n }\n return parts.join(' ');\n}\n\n/**\n * The current contract overlay marker. Unlike user refs, this names the user's\n * declared desired state — the implicit base/target for `plan` / `migrate` —\n * not a stored label. It is emphasized (bold) so it stands out from plain refs\n * (including the live-database `db` marker, which is just another ref).\n */\nexport const CONTRACT_MARKER_NAME = 'contract';\n\nfunction styleRefName(name: string): string {\n return green(name);\n}\n\n/**\n * Build a {@link MigrationListStyler} that decorates `migration list`\n * tokens with ANSI SGR codes. When `useColor` is `false` (non-TTY,\n * `--no-color`, `NO_COLOR=1`, piped output) the function returns the\n * shared identity styler so callers get plain text with zero ANSI\n * bytes — pipe-friendly by construction.\n *\n * Palette:\n *\n * - `dirName`: bold\n * - `sourceHash`: dim cyan\n * - `destHash`: bright cyan\n * - `kind` (`*` / `↩` / `⟲`): bright — the signal; lanes and arrows dim\n * - `glyph` (`→` / `⟲` / `∅`): dim\n * - `lane` (graph gutter lines `│` and fan/join connectors `├─┐` / `├─┘`): dim\n * - `invariants` (`{...}`): yellow\n * - `markers` (`@contract @db`): green; the `contract` desired-state marker is\n * green-bold (`db` is plain green); the `@` sigil is applied to each name\n * - `refs` (`(...)`): green (the active ref is bolded separately by the tree styler)\n * - `spaceHeading` (`<spaceId>:`): bold\n * - `summary`: dim\n * - `emptyState`: dim\n */\nexport function createAnsiMigrationListStyler(opts: {\n readonly useColor: boolean;\n}): MigrationListStylerWithMarkers {\n if (!opts.useColor) {\n return {\n ...IDENTITY_MIGRATION_LIST_STYLER,\n markers: plainMarkers,\n };\n }\n return {\n // Kind glyphs stay bright in both flat and graph views; lanes carry the dim gutter.\n kind: (text) => text,\n dirName: (text) => bold(text),\n sourceHash: (text) => dim(cyan(text)),\n destHash: (text) => cyanBright(text),\n glyph: (text) => dim(text),\n lane: (text) => dim(text),\n invariants: (ids) => yellow(`{${ids.join(', ')}}`),\n markers: (names) => {\n const sigil = green('@');\n return names.map((name) => sigil + styleMarkerName(name)).join(' ');\n },\n refs: (names) => {\n const open = green('(');\n const close = green(')');\n const separator = green(', ');\n return open + names.map(styleRefName).join(separator) + close;\n },\n spaceHeading: (text) => bold(text),\n summary: (text) => dim(text),\n emptyState: (text) => dim(text),\n };\n}\n","/**\n * Per-row label formatting for the command graph renderer.\n *\n * The command graph renderer ({@link renderMigrationGraphCommand}) derives the\n * graph structure — rows, gutter, lane colours — from the grid pipeline. The\n * per-row LABEL (contract hash + markers + refs for node rows;\n * migration name + `from → to` + ops/status/will-run for migration rows) is\n * formatted here. This module owns ONLY label text + styling; it knows nothing\n * about lanes, gutters, or grid geometry.\n *\n * The label format (hash abbreviation, `from → to` arrow column, `@contract`/\n * `@db` markers, `(refs)`, ops/status/will-run suffix, the legend) is the same\n * as the previous renderer — that part was never the bug.\n */\n\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { bold, createColors, green, yellow } from 'colorette';\nimport type { GlyphMode } from '../glyph-mode';\nimport { laneColorizer } from './migration-graph-occlusion-render';\nimport type { ClassifiedEdge } from './migration-graph-rows';\nimport {\n MIGRATION_LIST_HASH_WIDTH,\n migrationListEmptySource,\n migrationListForwardArrow,\n padFromHashColumn,\n} from './migration-list-data-column';\nimport type { MigrationEdgeKind } from './migration-list-graph-topology';\nimport type { MigrationListStyler } from './migration-list-render';\nimport {\n CONTRACT_MARKER_NAME,\n createAnsiMigrationListStyler,\n formatContractNodeOverlays,\n} from './migration-list-styler';\n\n/**\n * The live-database overlay marker. Just another ref as far as styling goes —\n * the only emphasized markers are the active ref and the `contract`\n * desired-state marker (see {@link CONTRACT_MARKER_NAME}).\n */\nconst DB_MARKER_NAME = 'db';\n\nexport interface MigrationEdgeAnnotation {\n readonly status?: 'applied' | 'pending';\n readonly operationCount?: number;\n readonly invariants?: readonly string[];\n /**\n * Path-highlight annotation for `migrate --show` preview.\n * - `'on-path'`: migration is on the chosen path; rendered in bright green.\n * - `'off-path'`: migration is off the chosen path; fully drawn but dim grey.\n */\n readonly pathHighlight?: 'on-path' | 'off-path';\n}\n\n/**\n * Inputs that drive label formatting. A subset of the command renderer's\n * options — everything the label functions read.\n */\nexport interface MigrationGraphLabelOptions {\n readonly refsByHash?: ReadonlyMap<string, readonly string[]>;\n readonly edgeAnnotationsByHash?: ReadonlyMap<string, MigrationEdgeAnnotation>;\n readonly dbHash?: string;\n readonly contractHash?: string;\n readonly isAppSpace?: boolean;\n readonly activeRefName?: string;\n readonly hashLength?: number;\n readonly colorize: boolean;\n readonly glyphMode?: GlyphMode;\n readonly styler?: MigrationListStyler;\n}\n\n/**\n * Forced-color functions that always emit ANSI regardless of the ambient TTY\n * environment (NO_COLOR, piped output). Used so on-path green / off-path dim are\n * deterministically emitted in tests that request colour while NO_COLOR is set.\n */\nconst { dim: forcedDim, bold: forcedBold } = createColors({ useColor: true });\nconst { greenBright: forcedGreen } = createColors({ useColor: true });\n\n/**\n * The two label styles used in `migrate --show` path-highlight mode.\n *\n * - `onPath`: bold name, neutral hashes (the on-path lane glyphs are coloured\n * green by the grid renderer, not here).\n * - `offPath`: uniform dim grey on the name and the whole hash column.\n *\n * To change the on-path / off-path label colour in future, edit this object.\n */\nexport const PATH_HIGHLIGHT_STYLES = {\n onPath: (_style: MigrationListStyler, colorize: boolean) => ({\n lane: colorize ? forcedGreen : (text: string) => text,\n arrow: (text: string) => text,\n dirName: (text: string) => bold(text),\n hashOverride: undefined,\n }),\n offPath: (colorize: boolean) => ({\n lane: colorize ? forcedDim : (text: string) => text,\n arrow: colorize ? forcedDim : (text: string) => text,\n dirName: colorize ? forcedDim : (text: string) => text,\n hashOverride: colorize ? forcedDim : undefined,\n }),\n} as const;\n\nfunction abbreviateHash(hash: string, hashLength: number, emptySource: string): string {\n if (hash === EMPTY_CONTRACT_HASH) {\n return emptySource;\n }\n const stripped = hash.startsWith('sha256:') ? hash.slice(7) : hash;\n return stripped.slice(0, hashLength);\n}\n\ninterface ContractOverlayNames {\n readonly markers: readonly string[];\n readonly refs: readonly string[];\n}\n\nfunction overlayNamesForContract(\n contractHash: string,\n opts: MigrationGraphLabelOptions,\n): ContractOverlayNames {\n const markers: string[] = [];\n const refs: string[] = [];\n const userRefs = opts.refsByHash?.get(contractHash);\n if (userRefs) {\n refs.push(...[...userRefs].sort((a, b) => a.localeCompare(b)));\n }\n if (\n opts.isAppSpace !== false &&\n opts.contractHash === contractHash &&\n contractHash !== EMPTY_CONTRACT_HASH\n ) {\n markers.push(CONTRACT_MARKER_NAME);\n }\n if (opts.dbHash === contractHash) {\n markers.push(DB_MARKER_NAME);\n }\n markers.sort((a, b) => {\n if (a === CONTRACT_MARKER_NAME) return -1;\n if (b === CONTRACT_MARKER_NAME) return 1;\n return a.localeCompare(b);\n });\n return { markers, refs };\n}\n\nexport function createLabelStyler(opts: MigrationGraphLabelOptions): MigrationListStyler {\n const base = opts.styler ?? createAnsiMigrationListStyler({ useColor: opts.colorize });\n const activeRefName = opts.activeRefName;\n if (!opts.colorize || activeRefName === undefined) {\n return base;\n }\n return {\n ...base,\n refs: (names) => {\n const styledNames = names.map((name) => (name === activeRefName ? bold(name) : name));\n return base.refs(styledNames);\n },\n };\n}\n\nfunction overlayStatusGlyphs(mode: GlyphMode): {\n readonly applied: string;\n readonly pending: string;\n} {\n return mode === 'ascii' ? { applied: '+', pending: '>' } : { applied: '✓', pending: '⧗' };\n}\n\nfunction formatEdgeAnnotationSuffix(\n migrationHash: string,\n opts: MigrationGraphLabelOptions,\n style: MigrationListStyler,\n): string {\n const annotation = opts.edgeAnnotationsByHash?.get(migrationHash);\n if (annotation === undefined) {\n return '';\n }\n const isOffPath = annotation.pathHighlight === 'off-path';\n const segments: string[] = [];\n if (annotation.operationCount !== undefined) {\n segments.push(`${annotation.operationCount} ops`);\n }\n if (annotation.invariants !== undefined && annotation.invariants.length > 0) {\n segments.push(style.invariants(annotation.invariants));\n }\n const status = annotation.status;\n if (status !== undefined) {\n const glyphs = overlayStatusGlyphs(opts.glyphMode ?? 'unicode');\n const glyph = status === 'applied' ? glyphs.applied : glyphs.pending;\n const label = status === 'applied' ? 'applied' : 'pending';\n if (!opts.colorize) {\n segments.push(`${glyph} ${label}`);\n } else {\n const styler = status === 'applied' ? green : yellow;\n segments.push(styler(`${glyph} ${label}`));\n }\n }\n if (annotation.pathHighlight === 'on-path') {\n const glyph = opts.glyphMode === 'ascii' ? '>' : '↑';\n segments.push(`${glyph} will run`);\n }\n if (segments.length === 0) {\n return '';\n }\n const suffix = ` ${segments.join(' ')}`;\n return opts.colorize && isOffPath ? forcedDim(suffix) : suffix;\n}\n\n/**\n * Format the `from → to` hash data column for an edge row.\n *\n * When `hashOverride` is provided (off-path → `dim`), it replaces ALL sub-stylers\n * so dim reaches every character without inner ANSI codes overriding it.\n */\nfunction formatEdgeHashColumn(\n edge: ClassifiedEdge,\n style: MigrationListStyler,\n hashLength: number,\n glyphMode: GlyphMode,\n hashOverride?: (text: string) => string,\n): string {\n const emptySource = migrationListEmptySource(glyphMode);\n const forwardArrow = migrationListForwardArrow(glyphMode);\n const src = hashOverride ?? style.sourceHash;\n const dst = hashOverride ?? style.destHash;\n const glyph = hashOverride ?? style.glyph;\n if (edge.kind === 'self') {\n const hash = abbreviateHash(edge.from, hashLength, emptySource);\n const source = padFromHashColumn(src(hash), hashLength);\n return `${source} ${glyph(forwardArrow)} ${dst(hash)}`;\n }\n const source =\n edge.from === EMPTY_CONTRACT_HASH\n ? padFromHashColumn(glyph(emptySource), hashLength)\n : padFromHashColumn(src(abbreviateHash(edge.from, hashLength, emptySource)), hashLength);\n const arrow = glyph(forwardArrow);\n const dest = dst(abbreviateHash(edge.to, hashLength, emptySource));\n return `${source} ${arrow} ${dest}`;\n}\n\n// ---------------------------------------------------------------------------\n// Public label builders used by the command renderer.\n// ---------------------------------------------------------------------------\n\n/**\n * The label text for a contract node row: the abbreviated hash (or the `∅`\n * empty-source token for the baseline) followed by its `@contract`/`@db` markers\n * and `(refs)`, with two spaces between the hash and the overlay block.\n */\nexport function formatNodeLabel(\n contractHash: string,\n opts: MigrationGraphLabelOptions,\n nodeHighlight?: 'on-path' | 'off-path' | undefined,\n): string {\n const style = createLabelStyler(opts);\n const hashLength = opts.hashLength ?? MIGRATION_LIST_HASH_WIDTH;\n const emptySource = migrationListEmptySource(opts.glyphMode ?? 'unicode');\n const overlays = overlayNamesForContract(contractHash, opts);\n const hasOverlays = overlays.markers.length > 0 || overlays.refs.length > 0;\n const offPath = nodeHighlight === 'off-path' && opts.colorize;\n // The baseline's label is the ∅ empty-source token (the gutter draws ○ for\n // every node, including the baseline); a real contract's label is its hash.\n const hashText =\n contractHash === EMPTY_CONTRACT_HASH\n ? (offPath ? forcedDim : style.glyph)(emptySource)\n : (offPath ? forcedDim : style.sourceHash)(\n abbreviateHash(contractHash, hashLength, emptySource),\n );\n if (!hasOverlays) return hashText;\n const overlay = formatContractNodeOverlays(style, overlays.markers, overlays.refs);\n return `${hashText} ${overlay}`;\n}\n\n/**\n * The label text for a migration row: the migration name (padded to\n * `dirNameWidth`) followed by the `from → to` hash column and the annotation\n * suffix (ops / status / will-run).\n *\n * In flat mode the name is tinted with its lane's hue (`lane` ≥ 0), so the node\n * `○`, the edges/arrows in the gutter, and the name all read in one colour. In\n * focus mode the on-path/off-path role overrides the lane hue (bold / dim).\n */\nexport function formatMigrationLabel(\n edge: ClassifiedEdge,\n dirNameWidth: number,\n opts: MigrationGraphLabelOptions,\n lane?: number,\n): string {\n const style = createLabelStyler(opts);\n const hashLength = opts.hashLength ?? MIGRATION_LIST_HASH_WIDTH;\n const glyphMode = opts.glyphMode ?? 'unicode';\n const highlight = opts.edgeAnnotationsByHash?.get(edge.migrationHash)?.pathHighlight;\n\n let dirNameStyler: (text: string) => string;\n let hashOverride: ((text: string) => string) | undefined;\n if (highlight === 'on-path') {\n dirNameStyler = (text) => bold(text);\n hashOverride = undefined;\n } else if (highlight === 'off-path') {\n dirNameStyler = opts.colorize ? forcedDim : style.dirName;\n hashOverride = opts.colorize ? forcedDim : undefined;\n } else if (opts.colorize && lane !== undefined) {\n // Flat mode: tint the name with the lane hue, bolded, so it matches the\n // lane's node/edge/arrow colour in the gutter.\n dirNameStyler = (text) => forcedBold(laneColorizer(lane)(text));\n hashOverride = undefined;\n } else {\n dirNameStyler = style.dirName;\n hashOverride = undefined;\n }\n\n const dirNamePadding = ' '.repeat(Math.max(0, dirNameWidth - edge.dirName.length));\n const dirName = `${dirNameStyler(edge.dirName)}${dirNamePadding}`;\n const hashColumn = formatEdgeHashColumn(edge, style, hashLength, glyphMode, hashOverride);\n const annotationSuffix = formatEdgeAnnotationSuffix(edge.migrationHash, opts, style);\n return `${dirName}${hashColumn}${annotationSuffix}`;\n}\n\n/**\n * Format a single on-path migration row for the `migrate --show` run-list.\n * Shares PATH_HIGHLIGHT_STYLES.onPath with the graph tree so the run-list and\n * the graph are byte-for-byte identical in their name/hash columns.\n */\nexport function formatOnPathMigrationRow(\n dirName: string,\n from: string,\n to: string,\n dirNameWidth: number,\n colorize: boolean,\n glyphMode: GlyphMode,\n): string {\n const style = createAnsiMigrationListStyler({ useColor: colorize });\n const s = PATH_HIGHLIGHT_STYLES.onPath(style, colorize);\n const styledDirName = `${s.dirName(dirName)}${' '.repeat(Math.max(0, dirNameWidth - dirName.length))}`;\n const hashLength = MIGRATION_LIST_HASH_WIDTH;\n const emptySource = migrationListEmptySource(glyphMode);\n const forwardArrow = migrationListForwardArrow(glyphMode);\n const fromAbbr =\n from === EMPTY_CONTRACT_HASH\n ? padFromHashColumn(style.glyph(emptySource), hashLength)\n : padFromHashColumn(\n style.sourceHash(abbreviateHash(from, hashLength, emptySource)),\n hashLength,\n );\n const toAbbr =\n to === EMPTY_CONTRACT_HASH\n ? style.glyph(emptySource)\n : style.destHash(abbreviateHash(to, hashLength, emptySource));\n const arrow = style.glyph(forwardArrow);\n return `${styledDirName} ${fromAbbr} ${arrow} ${toAbbr}`;\n}\n\nexport interface RenderMigrationGraphLegendOptions {\n readonly colorize: boolean;\n readonly glyphMode?: GlyphMode;\n}\n\nfunction legendGlyphs(mode: GlyphMode): {\n readonly node: string;\n readonly forward: string;\n readonly rollback: string;\n readonly self: string;\n} {\n return mode === 'ascii'\n ? { node: '*', forward: '^', rollback: 'v', self: '@' }\n : { node: '○', forward: '↑', rollback: '↓', self: '⟲' };\n}\n\nfunction formatLegendExampleMarkers(colorize: boolean): string {\n if (!colorize) {\n return '@contract @db';\n }\n const sigil = green('@');\n return `${sigil + bold(green('contract'))} ${sigil}${green('db')}`;\n}\n\n/**\n * A compact key for the tree visual language: the contract node glyph, the\n * in-lane direction arrows, the empty baseline, the system-marker `@…` and\n * user-ref `(…)` conventions, and a worked sample of the data-column hash arrow.\n */\nexport function renderMigrationGraphLegend(opts: RenderMigrationGraphLegendOptions): string {\n const glyphMode = opts.glyphMode ?? 'unicode';\n const style = createAnsiMigrationListStyler({ useColor: opts.colorize });\n const glyphs = legendGlyphs(glyphMode);\n const emptySource = migrationListEmptySource(glyphMode);\n const forwardArrow = migrationListForwardArrow(glyphMode);\n const sampleArrow = `${style.sourceHash('aaaaaa')} ${style.glyph(forwardArrow)} ${style.destHash('bbbbbb')}`;\n const statusGlyphs = overlayStatusGlyphs(glyphMode);\n const appliedPending = opts.colorize\n ? ` ${green(statusGlyphs.applied)} ${style.summary('applied')} ${yellow(statusGlyphs.pending)} ${style.summary('pending')}`\n : ` ${statusGlyphs.applied} ${style.summary('applied')} ${statusGlyphs.pending} ${style.summary('pending')}`;\n const exampleMarkers = formatLegendExampleMarkers(opts.colorize);\n const exampleRefs = opts.colorize ? style.refs(['prod', 'staging']) : '(prod, staging)';\n const lines = [\n 'Legend:',\n ` ${style.kind(glyphs.node)} ${style.summary('contract')} ${style.kind(glyphs.forward)} ${style.summary('forward')} ${style.kind(glyphs.rollback)} ${style.summary('rollback')}`,\n ` ${style.kind(glyphs.self)} ${style.summary('migration without schema change')}`,\n appliedPending,\n ` ${style.kind(emptySource)} ${style.summary('empty database (baseline)')}`,\n ` ${exampleMarkers} ${style.summary('reserved markers — also typeable as --from/--to tokens')}`,\n ` ${exampleRefs} ${style.summary('user-defined refs')}`,\n ` ${sampleArrow} ${style.summary('migration from contract aaaaaa to bbbbbb')}`,\n ];\n return lines.join('\\n');\n}\n\n// Re-export the edge kind type alias for downstream label callers.\nexport type { MigrationEdgeKind };\n","/**\n * Command graph renderer: composes the gutter (from the grid) with per-row labels.\n *\n * Pipeline: buildMigrationGraphRows → buildGrid → renderMigrationGraphCommand\n *\n * Each grid row is classified by its cells: a node row gets a contract label;\n * a migration arrow row gets a migration label; connector rows get no label.\n * Label format and styling live in `./migration-graph-labels`.\n */\n\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport stringWidth from 'string-width';\nimport type { GlyphMode } from '../glyph-mode';\nimport {\n formatMigrationLabel,\n formatNodeLabel,\n type MigrationEdgeAnnotation,\n type MigrationGraphLabelOptions,\n} from './migration-graph-labels';\nimport type { Cell, CellLine, Grid } from './migration-graph-model';\nimport { renderGridRow } from './migration-graph-occlusion-render';\nimport type { ClassifiedEdge, MigrationGraphRowModel } from './migration-graph-rows';\nimport type { MigrationListStyler } from './migration-list-render';\n\nconst LABEL_GAP = 2;\nconst MIN_HASH_DATA_COLUMN = 25;\n\nexport interface RenderMigrationGraphCommandInput {\n readonly grid: Grid;\n readonly rowModel: MigrationGraphRowModel;\n readonly colorize: boolean;\n readonly glyphMode: GlyphMode;\n readonly refsByHash?: ReadonlyMap<string, readonly string[]>;\n readonly edgeAnnotationsByHash?: ReadonlyMap<string, MigrationEdgeAnnotation>;\n readonly dbHash?: string;\n readonly contractHash?: string;\n readonly isAppSpace?: boolean;\n readonly activeRefName?: string;\n readonly styler?: MigrationListStyler;\n /** Cross-space override for the gutter→label column (max gutter width). */\n readonly globalLabelColumn?: number;\n /** Cross-space override for the migration-name column width. */\n readonly globalMaxDirNameWidth?: number;\n}\n\n// ---------------------------------------------------------------------------\n// Row classification — derive each grid row's identity from its own cells.\n// ---------------------------------------------------------------------------\n\ntype RowIdentity =\n | { readonly kind: 'node'; readonly contractHash: string }\n | { readonly kind: 'migration'; readonly edge: ClassifiedEdge; readonly lane: number }\n | { readonly kind: 'none' };\n\n/**\n * Classify a grid row by its own cells:\n * - a cell carrying a NodeRef → node row (contract label);\n * - a cell whose top line is an arrow ({up}/{down}/self-loop) → migration row;\n * - otherwise → no label.\n *\n * A migration's arrow appears in exactly one grid row (the forward `↑` row, the\n * adjacent-rollback `↓` row, or the self-loop `⟲` row), so each migration gets\n * exactly one label, on the row that draws its arrow.\n *\n * Two distinct migrations with identical content (same from/to/ops) hash to the\n * SAME migration hash, so the arrow line is matched on BOTH its hash and its\n * `dirName` (which the LineRef carries per-row) — otherwise both rows would\n * resolve to one edge and the other migration's name would be lost.\n */\nfunction classifyRow(\n row: readonly Cell[],\n edgesByHash: ReadonlyMap<string, readonly ClassifiedEdge[]>,\n): RowIdentity {\n for (const cell of row) {\n if (cell.node !== undefined) {\n return { kind: 'node', contractHash: cell.node.contractHash };\n }\n }\n for (const cell of row) {\n const arrow = arrowLine(cell);\n if (arrow === undefined) continue;\n const candidates = edgesByHash.get(arrow.line.migrationHash) ?? [];\n const edge = candidates.find((e) => e.dirName === arrow.line.dirName) ?? candidates[0];\n if (edge !== undefined) return { kind: 'migration', edge, lane: arrow.line.lane };\n }\n return { kind: 'none' };\n}\n\n/**\n * Return the cell's arrow line if it carries one — a self-loop, or a line whose\n * directions are exactly `{up}` or `{down}` (the migration-direction arrows).\n * Connector/corner/vertical lines are not arrows and yield `undefined`.\n */\nfunction arrowLine(cell: Cell): CellLine | undefined {\n for (const line of cell.lines) {\n if (line.selfLoop === true) return line;\n if (line.landingArrow === true) continue;\n const dirs = line.directions;\n if (dirs.size !== 1) continue;\n if (dirs.has('up') || dirs.has('down')) return line;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Node path-highlight resolution (focus mode).\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve each contract's path-highlight role from the edges incident on it.\n * On-path wins: a contract touched by any on-path edge is on-path. Empty unless\n * focus-mode annotations are present.\n */\nfunction resolveNodeHighlights(\n rowModel: MigrationGraphRowModel,\n edgeAnnotationsByHash: ReadonlyMap<string, MigrationEdgeAnnotation> | undefined,\n): Map<string, 'on-path' | 'off-path'> {\n const result = new Map<string, 'on-path' | 'off-path'>();\n if (edgeAnnotationsByHash === undefined) return result;\n for (const edge of rowModel.edges) {\n const highlight = edgeAnnotationsByHash.get(edge.migrationHash)?.pathHighlight;\n if (highlight === undefined) continue;\n for (const hash of [edge.from, edge.to]) {\n if (hash === EMPTY_CONTRACT_HASH) continue;\n if (result.get(hash) !== 'on-path') result.set(hash, highlight);\n }\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Width helpers\n// ---------------------------------------------------------------------------\n\nfunction maxDirNameLength(edges: readonly ClassifiedEdge[]): number {\n let max = 0;\n for (const edge of edges) max = Math.max(max, edge.dirName.length);\n return max;\n}\n\n/**\n * The label column for a render: the widest gutter (visible width) across every\n * row, plus the label gap. Labels begin here so they line up regardless of how\n * deep the lane structure runs on any one row. A cross-space override widens it\n * so sibling space sections share one column.\n */\nexport function computeLabelColumn(grid: Grid, glyphMode: GlyphMode): number {\n let maxGutter = 0;\n for (const row of grid) {\n const gutter = renderGridRow(row, { colorize: false, glyphMode });\n maxGutter = Math.max(maxGutter, stringWidth(gutter));\n }\n return maxGutter + LABEL_GAP;\n}\n\nexport function computeMaxDirNameWidth(rowModel: MigrationGraphRowModel): number {\n return maxDirNameLength(rowModel.edges);\n}\n\nfunction padVisible(text: string, targetWidth: number): string {\n const padding = Math.max(0, targetWidth - stringWidth(text));\n return text + ' '.repeat(padding);\n}\n\nconst ANSI_ESCAPE = '\\x1b';\n\nfunction trimTrailingWhitespace(line: string): string {\n const trailingSpaceBeforeReset = new RegExp(`[\\\\t ]+((?:${ANSI_ESCAPE}\\\\[[0-9;]*m)+)$`);\n return line.replace(trailingSpaceBeforeReset, '$1').replace(/\\s+$/, '');\n}\n\n// ---------------------------------------------------------------------------\n// Render\n// ---------------------------------------------------------------------------\n\nexport function renderMigrationGraphCommand(input: RenderMigrationGraphCommandInput): string {\n const { grid, rowModel } = input;\n const glyphMode = input.glyphMode;\n\n // Edges grouped by hash — a list, not a single entry, because two distinct\n // migrations with identical content collide on one hash. classifyRow then\n // disambiguates by the row's own dirName.\n const edgesByHash = new Map<string, ClassifiedEdge[]>();\n for (const edge of rowModel.edges) {\n const bucket = edgesByHash.get(edge.migrationHash);\n if (bucket) bucket.push(edge);\n else edgesByHash.set(edge.migrationHash, [edge]);\n }\n\n const labelOpts: MigrationGraphLabelOptions = {\n colorize: input.colorize,\n glyphMode,\n ...ifDefined('refsByHash', input.refsByHash),\n ...ifDefined('edgeAnnotationsByHash', input.edgeAnnotationsByHash),\n ...ifDefined('dbHash', input.dbHash),\n ...ifDefined('contractHash', input.contractHash),\n ...ifDefined('isAppSpace', input.isAppSpace),\n ...ifDefined('activeRefName', input.activeRefName),\n ...ifDefined('styler', input.styler),\n };\n\n const nodeHighlights = resolveNodeHighlights(rowModel, input.edgeAnnotationsByHash);\n\n const labelColumn = input.globalLabelColumn ?? computeLabelColumn(grid, glyphMode);\n const maxDirNameLen = input.globalMaxDirNameWidth ?? maxDirNameLength(rowModel.edges);\n // The migration-name column is at least wide enough to push the `from → to`\n // hash column to MIN_HASH_DATA_COLUMN, matching the historical layout.\n const dirNameWidth = Math.max(maxDirNameLen + LABEL_GAP, MIN_HASH_DATA_COLUMN - labelColumn);\n\n const lines: string[] = [];\n for (const row of grid) {\n const gutter = renderGridRow(row, { colorize: input.colorize, glyphMode });\n const identity = classifyRow(row, edgesByHash);\n\n if (identity.kind === 'none') {\n // Connector / pass-through / back-arc rows carry no label. A wholly empty\n // grid row (the blank line between disjoint components) renders as a blank.\n lines.push(trimTrailingWhitespace(gutter));\n continue;\n }\n\n const gutterPad = padVisible(gutter, labelColumn);\n if (identity.kind === 'node') {\n const label = formatNodeLabel(\n identity.contractHash,\n labelOpts,\n nodeHighlights.get(identity.contractHash),\n );\n lines.push(trimTrailingWhitespace(label.length === 0 ? gutter : `${gutterPad}${label}`));\n continue;\n }\n\n const label = formatMigrationLabel(identity.edge, dirNameWidth, labelOpts, identity.lane);\n lines.push(trimTrailingWhitespace(`${gutterPad}${label}`));\n }\n\n return lines.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,UAAU,aAAa,EAAE,UAAU,KAAK,CAAC;AAO/C,MAAM,kBAA+B;CACnC,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,UAAU,MAAyB;CAC1C,OAAO,gBAAgB,OAAO,gBAAgB,aAAa,MAAM;AACnE;;;;;;;AAQA,SAAgB,cAAc,MAAwC;CACpE,OAAO,UAAU,IAAI;AACvB;AAMA,SAAS,UAAU,MAA2B;CAC5C,OAAO,SAAS,YAAY,QAAQ,cAAc,QAAQ;AAC5D;AAsBA,MAAM,mBAAuC;CAC3C,UAAU;CACV,YAAY;CACZ,eAAe;CACf,iBAAiB;CACjB,cAAc;CACd,gBAAgB;CAChB,SAAS;CACT,WAAW;CACX,MAAM;CACN,UAAU;CACV,cAAc;CACd,UAAU;AACZ;AAEA,MAAM,iBAAqC;CACzC,UAAU;CACV,YAAY;CACZ,eAAe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,KAAK,uBAAuB,GAAG,YAAY,OAAO,CAAC;CAC3D;CAEA,OAAO,MAAM,KAAK,IAAI;AACxB"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { t as loadConfig } from "./config-loader-p9JMrekQ.mjs";
|
|
2
|
+
import { A as formatStyledHeader, K as errorInvalidSpaceId, _ as createTerminalUI, at as errorSpaceNotFound, d as setCommandSeeAlso, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, q as errorLegendHumanOnly, s as resolveMigrationPaths, t as addGlobalOptions, u as setCommandExamples, y as handleResult } from "./command-helpers-DGMvGBeX.mjs";
|
|
3
|
+
import { n as buildReadAggregate } from "./contract-space-aggregate-loader-ClI1KN6d.mjs";
|
|
4
|
+
import { a as renderMigrationGraphLegend, c as renderMigrationListWithStyle, o as createAnsiMigrationListStyler } from "./migration-graph-command-render-BAOzyYF6.mjs";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
7
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
8
|
+
import { APP_SPACE_ID, RESERVED_SPACE_SUBDIR_NAMES, isValidSpaceId, listContractSpaceDirectories } from "@prisma-next/migration-tools/spaces";
|
|
9
|
+
import { HEAD_REF_NAME, refsByContractHash } from "@prisma-next/migration-tools/refs";
|
|
10
|
+
//#region src/utils/legend.ts
|
|
11
|
+
/**
|
|
12
|
+
* The legend is decoration printed alongside the command header on stderr, so
|
|
13
|
+
* it is suppressed for the machine-readable / silent paths (`--json`, `--dot`,
|
|
14
|
+
* `--quiet`) exactly as the header is.
|
|
15
|
+
*/
|
|
16
|
+
function shouldShowLegend(options, flags) {
|
|
17
|
+
return options.legend === true && options.dot !== true && flags.json !== true && flags.quiet !== true;
|
|
18
|
+
}
|
|
19
|
+
function validateLegendOptions(options, flags) {
|
|
20
|
+
if (options.legend !== true) return ok(void 0);
|
|
21
|
+
if (flags.json === true) return notOk(errorLegendHumanOnly("--json"));
|
|
22
|
+
if (flags.quiet === true) return notOk(errorLegendHumanOnly("--quiet"));
|
|
23
|
+
if (options.dot === true) return notOk(errorLegendHumanOnly("--dot"));
|
|
24
|
+
return ok(void 0);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/commands/migration-list.ts
|
|
28
|
+
function compareSpaceIds(a, b) {
|
|
29
|
+
if (a === APP_SPACE_ID) return b === APP_SPACE_ID ? 0 : -1;
|
|
30
|
+
if (b === APP_SPACE_ID) return 1;
|
|
31
|
+
if (a < b) return -1;
|
|
32
|
+
if (a > b) return 1;
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
function compareDirNamesDescending(a, b) {
|
|
36
|
+
if (a.name < b.name) return 1;
|
|
37
|
+
if (a.name > b.name) return -1;
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Ref names decorating a space's destination contract hashes. The
|
|
42
|
+
* tolerant `member.refs` deliberately omits the structural `head.json`;
|
|
43
|
+
* for extension spaces the old enumerator surfaced it as a `head`
|
|
44
|
+
* decoration on the tip migration, so fold `member.headRef` back in to
|
|
45
|
+
* keep that output. The app space synthesises its head, so it carries
|
|
46
|
+
* no on-disk `head` ref to restore.
|
|
47
|
+
*/
|
|
48
|
+
function listRefsByContractHash(member) {
|
|
49
|
+
const byHash = new Map(refsByContractHash(member.refs));
|
|
50
|
+
if (member.spaceId !== APP_SPACE_ID && member.headRef !== null) {
|
|
51
|
+
const hash = member.headRef.hash;
|
|
52
|
+
const bucket = byHash.get(hash) ?? [];
|
|
53
|
+
if (!bucket.includes(HEAD_REF_NAME)) byHash.set(hash, [...bucket, HEAD_REF_NAME].sort());
|
|
54
|
+
}
|
|
55
|
+
return byHash;
|
|
56
|
+
}
|
|
57
|
+
async function orderedOnDiskSpaceIds(projectMigrationsDir) {
|
|
58
|
+
return (await listContractSpaceDirectories(projectMigrationsDir)).filter((name) => !RESERVED_SPACE_SUBDIR_NAMES.has(name)).filter(isValidSpaceId).sort(compareSpaceIds);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Project the loaded {@link ContractSpaceAggregate} into the render-ready
|
|
62
|
+
* {@link MigrationSpaceListEntry} rows `migration list` displays.
|
|
63
|
+
*
|
|
64
|
+
* Space membership matches the on-disk contract-space directories (not the
|
|
65
|
+
* aggregate's always-present synthesized app member when `migrations/app/`
|
|
66
|
+
* is absent); package and ref data come from `aggregate.space(id)`.
|
|
67
|
+
*/
|
|
68
|
+
async function migrationSpaceListEntriesFromAggregate(aggregate, projectMigrationsDir) {
|
|
69
|
+
const spaceIds = await orderedOnDiskSpaceIds(projectMigrationsDir);
|
|
70
|
+
const spaces = [];
|
|
71
|
+
for (const spaceId of spaceIds) {
|
|
72
|
+
const member = aggregate.space(spaceId);
|
|
73
|
+
if (member === void 0) continue;
|
|
74
|
+
const refsByHash = listRefsByContractHash(member);
|
|
75
|
+
const migrations = member.packages.map((pkg) => ({
|
|
76
|
+
name: pkg.dirName,
|
|
77
|
+
hash: pkg.metadata.migrationHash,
|
|
78
|
+
fromContract: pkg.metadata.from,
|
|
79
|
+
toContract: pkg.metadata.to,
|
|
80
|
+
operationCount: pkg.ops.length,
|
|
81
|
+
createdAt: pkg.metadata.createdAt,
|
|
82
|
+
refs: [...refsByHash.get(pkg.metadata.to) ?? []],
|
|
83
|
+
providedInvariants: [...pkg.metadata.providedInvariants]
|
|
84
|
+
})).sort(compareDirNamesDescending);
|
|
85
|
+
spaces.push({
|
|
86
|
+
space: spaceId,
|
|
87
|
+
migrations
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return spaces;
|
|
91
|
+
}
|
|
92
|
+
function renderMigrationListHumanOutput(result, options) {
|
|
93
|
+
return renderMigrationListWithStyle(result, createAnsiMigrationListStyler({ useColor: options.useColor }), options.glyphMode, {
|
|
94
|
+
colorize: options.useColor,
|
|
95
|
+
liveContractHash: options.liveContractHash,
|
|
96
|
+
graphForSpace: options.graphForSpace,
|
|
97
|
+
...options.appSpaceId !== void 0 ? { appSpaceId: options.appSpaceId } : {}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function computeSummary(spaces) {
|
|
101
|
+
const totalMigrations = spaces.reduce((count, space) => count + space.migrations.length, 0);
|
|
102
|
+
if (spaces.length <= 1) return `${totalMigrations} migration(s) on disk`;
|
|
103
|
+
return `${totalMigrations} migration(s) across ${spaces.length} contract space(s)`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Policy core of `migration list`: validates `--space`, narrows the
|
|
107
|
+
* pre-enumerated spaces, and assembles a {@link MigrationListResult}.
|
|
108
|
+
*
|
|
109
|
+
* - `migrations/` missing or contains no valid space directories →
|
|
110
|
+
* caller passes `spaces: []`; this synthesizes `[{ spaceId: APP_SPACE_ID, migrations: [] }]`.
|
|
111
|
+
* - `--space <id>` on an existing-but-empty space → `{ spaceId, migrations: [] }` in the input.
|
|
112
|
+
* - `--space <id>` on a non-existent (or reserved) space → `SPACE_NOT_FOUND`.
|
|
113
|
+
*/
|
|
114
|
+
function runMigrationList(inputs) {
|
|
115
|
+
const { spaces, spaceFilter } = inputs;
|
|
116
|
+
if (spaceFilter !== void 0 && !isValidSpaceId(spaceFilter)) return notOk(errorInvalidSpaceId(spaceFilter));
|
|
117
|
+
if (spaceFilter !== void 0 && !spaces.some((s) => s.space === spaceFilter)) return notOk(errorSpaceNotFound(spaceFilter, spaces.map((s) => s.space).sort()));
|
|
118
|
+
const scopedSpaces = spaceFilter !== void 0 ? spaces.filter((s) => s.space === spaceFilter) : spaces;
|
|
119
|
+
const resultSpaces = scopedSpaces.length === 0 ? [{
|
|
120
|
+
space: APP_SPACE_ID,
|
|
121
|
+
migrations: []
|
|
122
|
+
}] : scopedSpaces;
|
|
123
|
+
return ok({
|
|
124
|
+
ok: true,
|
|
125
|
+
spaces: [...resultSpaces],
|
|
126
|
+
summary: computeSummary(resultSpaces)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* CLI shell: loads config, resolves paths, prints the styled header on
|
|
131
|
+
* stderr (interactive mode only), and delegates to {@link runMigrationList}.
|
|
132
|
+
* Kept intentionally thin so the unit-testable surface lives in the core.
|
|
133
|
+
*/
|
|
134
|
+
async function executeMigrationListCommand(options, flags, ui) {
|
|
135
|
+
const config = await loadConfig(options.config);
|
|
136
|
+
const { configPath, migrationsDir, migrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
137
|
+
if (!flags.json && !flags.quiet) {
|
|
138
|
+
const header = formatStyledHeader({
|
|
139
|
+
command: "migration list",
|
|
140
|
+
description: "List on-disk migrations per contract space",
|
|
141
|
+
details: [
|
|
142
|
+
{
|
|
143
|
+
label: "config",
|
|
144
|
+
value: configPath
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
label: "migrations",
|
|
148
|
+
value: migrationsRelative
|
|
149
|
+
},
|
|
150
|
+
...options.space !== void 0 ? [{
|
|
151
|
+
label: "space",
|
|
152
|
+
value: options.space
|
|
153
|
+
}] : []
|
|
154
|
+
],
|
|
155
|
+
flags
|
|
156
|
+
});
|
|
157
|
+
ui.stderr(header);
|
|
158
|
+
if (shouldShowLegend(options, flags)) {
|
|
159
|
+
ui.stderr(renderMigrationGraphLegend({
|
|
160
|
+
colorize: flags.color !== false,
|
|
161
|
+
glyphMode: ui.resolveGlyphMode(options.ascii === true)
|
|
162
|
+
}));
|
|
163
|
+
ui.stderr("");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const loaded = await buildReadAggregate(config, { migrationsDir });
|
|
167
|
+
if (!loaded.ok) return notOk(loaded.failure);
|
|
168
|
+
const { aggregate, contractHash: liveContractHash } = loaded.value;
|
|
169
|
+
const listResult = runMigrationList({
|
|
170
|
+
spaces: await migrationSpaceListEntriesFromAggregate(aggregate, migrationsDir),
|
|
171
|
+
...ifDefined("spaceFilter", options.space)
|
|
172
|
+
});
|
|
173
|
+
if (!listResult.ok) return listResult;
|
|
174
|
+
return ok({
|
|
175
|
+
list: listResult.value,
|
|
176
|
+
liveContractHash,
|
|
177
|
+
aggregate
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function createMigrationListCommand() {
|
|
181
|
+
const command = new Command("list");
|
|
182
|
+
setCommandDescriptions(command, "List on-disk migrations per contract space", "Enumerates every on-disk migration under migrations/<space>/ for every\ncontract space found on disk. Offline — does not consult the database.\nHuman output draws the shared migration graph tree with operation counts,\ninvariants on each migration row, and refs on destination contract nodes.\nPass --space <id> to narrow to one contract space. --ascii forces ASCII\ntree glyphs (orthogonal to --no-color).");
|
|
183
|
+
setCommandExamples(command, [
|
|
184
|
+
"prisma-next migration list",
|
|
185
|
+
"prisma-next migration list --space app",
|
|
186
|
+
"prisma-next migration list --ascii",
|
|
187
|
+
"prisma-next migration list --legend",
|
|
188
|
+
"prisma-next migration list --json"
|
|
189
|
+
]);
|
|
190
|
+
setCommandSeeAlso(command, [
|
|
191
|
+
{
|
|
192
|
+
verb: "migration status",
|
|
193
|
+
oneLiner: "Show migration path and pending status"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
verb: "migration log",
|
|
197
|
+
oneLiner: "Show executed migration history"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
verb: "migration graph",
|
|
201
|
+
oneLiner: "Show the migration graph topology"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
verb: "migration show",
|
|
205
|
+
oneLiner: "Display migration package contents"
|
|
206
|
+
}
|
|
207
|
+
]);
|
|
208
|
+
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").option("--space <id>", "Narrow output to a single contract space").option("--ascii", "Use ASCII kind glyphs (pipe-friendly)").option("--legend", "Print a key for the tree glyphs and lane colors").action(async (options) => {
|
|
209
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
210
|
+
const ui = createTerminalUI(flags);
|
|
211
|
+
const legendValidation = validateLegendOptions(options, flags);
|
|
212
|
+
if (!legendValidation.ok) process.exit(handleResult(legendValidation, flags, ui));
|
|
213
|
+
const exitCode = handleResult(await executeMigrationListCommand(options, flags, ui), flags, ui, ({ list, liveContractHash, aggregate }) => {
|
|
214
|
+
if (flags.json) ui.output(JSON.stringify(list, null, 2));
|
|
215
|
+
else if (!flags.quiet) ui.output(renderMigrationListHumanOutput(list, {
|
|
216
|
+
glyphMode: ui.resolveGlyphMode(options.ascii === true),
|
|
217
|
+
useColor: ui.useColor,
|
|
218
|
+
liveContractHash,
|
|
219
|
+
graphForSpace: (spaceId) => aggregate.space(spaceId)?.graph(),
|
|
220
|
+
appSpaceId: aggregate.app.spaceId
|
|
221
|
+
}));
|
|
222
|
+
});
|
|
223
|
+
process.exit(exitCode);
|
|
224
|
+
});
|
|
225
|
+
return command;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { renderMigrationListHumanOutput as a, validateLegendOptions as c, migrationSpaceListEntriesFromAggregate as i, executeMigrationListCommand as n, runMigrationList as o, listRefsByContractHash as r, shouldShowLegend as s, createMigrationListCommand as t };
|
|
229
|
+
|
|
230
|
+
//# sourceMappingURL=migration-list-CihF6w5z.mjs.map
|