@prisma-next/cli 0.12.0-dev.9 → 0.13.0-dev.1
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-CEez7YUK.mjs +1960 -0
- package/dist/migration-graph-command-render-CEez7YUK.mjs.map +1 -0
- package/dist/migration-list-DlJJ_38Z.mjs +230 -0
- package/dist/migration-list-DlJJ_38Z.mjs.map +1 -0
- package/dist/migration-log-CG0qQAFm.mjs +222 -0
- package/dist/migration-log-CG0qQAFm.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-CgWSoI_g.mjs +446 -0
- package/dist/migration-status-CgWSoI_g.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 +1134 -0
- package/src/utils/formatters/migration-graph-labels.ts +408 -0
- package/src/utils/formatters/migration-graph-model.ts +103 -0
- package/src/utils/formatters/migration-graph-occlusion-render.ts +258 -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-C9WC-7eO.mjs +0 -1478
- package/dist/migration-graph-C9WC-7eO.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 -1141
- package/src/utils/formatters/migration-graph-tree-render.ts +0 -768
|
@@ -1,768 +0,0 @@
|
|
|
1
|
-
import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
|
|
2
|
-
import { bold, createColors } from 'colorette';
|
|
3
|
-
import stringWidth from 'string-width';
|
|
4
|
-
import type { GlyphMode } from '../glyph-mode';
|
|
5
|
-
import { laneColorForColumn } from './migration-graph-lane-colors';
|
|
6
|
-
import type {
|
|
7
|
-
MigrationGraphGridModel,
|
|
8
|
-
MigrationGraphGridRow,
|
|
9
|
-
StructuralCell,
|
|
10
|
-
} from './migration-graph-layout';
|
|
11
|
-
import type { ClassifiedEdge } from './migration-graph-rows';
|
|
12
|
-
import {
|
|
13
|
-
MIGRATION_LIST_HASH_WIDTH,
|
|
14
|
-
migrationListEmptySource,
|
|
15
|
-
migrationListForwardArrow,
|
|
16
|
-
} from './migration-list-data-column';
|
|
17
|
-
import type { MigrationEdgeKind } from './migration-list-graph-topology';
|
|
18
|
-
import type { MigrationListStyler } from './migration-list-render';
|
|
19
|
-
import { CONTRACT_MARKER_NAME, createAnsiMigrationListStyler } from './migration-list-styler';
|
|
20
|
-
|
|
21
|
-
const LABEL_GAP = 2;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The live-database overlay marker. Just another ref as far as styling goes —
|
|
25
|
-
* the only emphasized markers are the active ref and the `contract`
|
|
26
|
-
* desired-state marker (see {@link CONTRACT_MARKER_NAME}).
|
|
27
|
-
*/
|
|
28
|
-
const DB_MARKER_NAME = 'db';
|
|
29
|
-
|
|
30
|
-
export interface RenderMigrationGraphTreeOptions {
|
|
31
|
-
readonly refsByHash?: ReadonlyMap<string, readonly string[]>;
|
|
32
|
-
readonly dbHash?: string;
|
|
33
|
-
readonly contractHash?: string;
|
|
34
|
-
readonly activeRefName?: string;
|
|
35
|
-
readonly hashLength?: number;
|
|
36
|
-
readonly colorize: boolean;
|
|
37
|
-
readonly glyphMode?: GlyphMode;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface MigrationGraphTreeGlyphPalette {
|
|
41
|
-
readonly node: string;
|
|
42
|
-
readonly arcLand: string;
|
|
43
|
-
readonly arcTee: string;
|
|
44
|
-
readonly verticalPass: string;
|
|
45
|
-
readonly branchTee: string;
|
|
46
|
-
readonly mergeTee: string;
|
|
47
|
-
readonly branchCorner: string;
|
|
48
|
-
readonly mergeCorner: string;
|
|
49
|
-
readonly arcBranchCorner: string;
|
|
50
|
-
readonly arcBranchTee: string;
|
|
51
|
-
readonly arcLandCorner: string;
|
|
52
|
-
readonly arcCrossing: string;
|
|
53
|
-
readonly arcLandBridge: string;
|
|
54
|
-
readonly horizontalPass: string;
|
|
55
|
-
readonly connectorBranchTee: string;
|
|
56
|
-
readonly connectorBranchTeeCo: string;
|
|
57
|
-
readonly connectorMergeTeeCo: string;
|
|
58
|
-
readonly edgeArrow: Readonly<Record<MigrationEdgeKind, string>>;
|
|
59
|
-
readonly forwardArrow: string;
|
|
60
|
-
readonly emptySource: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const UNICODE_PALETTE: MigrationGraphTreeGlyphPalette = {
|
|
64
|
-
node: '○ ',
|
|
65
|
-
arcLand: '○◂',
|
|
66
|
-
arcTee: '○─',
|
|
67
|
-
verticalPass: '│ ',
|
|
68
|
-
branchTee: '├─',
|
|
69
|
-
mergeTee: '├─',
|
|
70
|
-
branchCorner: '╮ ',
|
|
71
|
-
mergeCorner: '╯ ',
|
|
72
|
-
arcBranchCorner: '╮ ',
|
|
73
|
-
arcBranchTee: '┬─',
|
|
74
|
-
arcLandCorner: '╯ ',
|
|
75
|
-
arcCrossing: '┼─',
|
|
76
|
-
arcLandBridge: '──',
|
|
77
|
-
horizontalPass: '──',
|
|
78
|
-
connectorBranchTee: '├─',
|
|
79
|
-
connectorBranchTeeCo: '┬─',
|
|
80
|
-
connectorMergeTeeCo: '┴─',
|
|
81
|
-
edgeArrow: { forward: '↑', rollback: '↓', self: '⟲' },
|
|
82
|
-
forwardArrow: migrationListForwardArrow('unicode'),
|
|
83
|
-
emptySource: migrationListEmptySource('unicode'),
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const ASCII_PALETTE: MigrationGraphTreeGlyphPalette = {
|
|
87
|
-
node: '* ',
|
|
88
|
-
arcLand: '*<',
|
|
89
|
-
arcTee: '*-',
|
|
90
|
-
verticalPass: '| ',
|
|
91
|
-
branchTee: '+-',
|
|
92
|
-
mergeTee: '+-',
|
|
93
|
-
branchCorner: '\\ ',
|
|
94
|
-
mergeCorner: '/ ',
|
|
95
|
-
arcBranchCorner: '\\ ',
|
|
96
|
-
arcBranchTee: '+-',
|
|
97
|
-
arcLandCorner: '/ ',
|
|
98
|
-
arcCrossing: '+-',
|
|
99
|
-
arcLandBridge: '--',
|
|
100
|
-
horizontalPass: '--',
|
|
101
|
-
connectorBranchTee: '+-',
|
|
102
|
-
connectorBranchTeeCo: '+-',
|
|
103
|
-
connectorMergeTeeCo: '+-',
|
|
104
|
-
edgeArrow: { forward: '^', rollback: 'v', self: '@' },
|
|
105
|
-
forwardArrow: migrationListForwardArrow('ascii'),
|
|
106
|
-
emptySource: migrationListEmptySource('ascii'),
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
function paletteFor(mode: GlyphMode): MigrationGraphTreeGlyphPalette {
|
|
110
|
-
return mode === 'ascii' ? ASCII_PALETTE : UNICODE_PALETTE;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function arrowForEdgeKind(
|
|
114
|
-
kind: MigrationEdgeKind,
|
|
115
|
-
palette: MigrationGraphTreeGlyphPalette,
|
|
116
|
-
): string {
|
|
117
|
-
return palette.edgeArrow[kind];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The leftmost lane (column 0) renders with the neutral dim lane style rather
|
|
122
|
-
* than a palette hue — in the common single-lane case it has nothing to be told
|
|
123
|
-
* apart from. Used as the "no owning arc" sentinel during colour resolution.
|
|
124
|
-
*/
|
|
125
|
-
const NEUTRAL_LANE = 0;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Forced bold for branch-coloured names. A branched name pairs its lane hue
|
|
129
|
-
* (also forced, via {@link laneColorForColumn}) with bold; both must emit even
|
|
130
|
-
* when colorette's ambient TTY detection is off, so the colorized branch name
|
|
131
|
-
* is deterministically bold + hue rather than hue-only.
|
|
132
|
-
*/
|
|
133
|
-
const { bold: forcedBold } = createColors({ useColor: true });
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The colour-source column for each cell of a row, resolved together because a
|
|
137
|
-
* routed back-arc spans columns and must read as **one hue** rather than a
|
|
138
|
-
* per-column "rainbow". An arc's horizontal bridges, corners, and node-pair
|
|
139
|
-
* connector all take the arc's owning back-lane column (the corner that closes
|
|
140
|
-
* the arc), not the column they pass through.
|
|
141
|
-
*/
|
|
142
|
-
interface RowLaneColors {
|
|
143
|
-
/** Colour column for a cell's structural glyph (lane / spine / arc body). */
|
|
144
|
-
readonly lane: readonly number[];
|
|
145
|
-
/** Colour column for a node arc-pair's connector half (`◂` / `─`). */
|
|
146
|
-
readonly connector: readonly number[];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Resolve per-cell colour columns for a row. Scanning right-to-left lets each
|
|
151
|
-
* arc bridge inherit the corner column that closes it (the arc's back-lane), so
|
|
152
|
-
* the whole arc — vertical run (already its own column), horizontal bridges,
|
|
153
|
-
* corners, crossings, and the `◂`/`─` connector — reads as a single continuous
|
|
154
|
-
* hue. A crossing can only be one colour, so rather than leave it dim (wrong for
|
|
155
|
-
* both crossing lines) it takes the arc owning the horizontal run at this row
|
|
156
|
-
* (the nearest corner to its right); the crossed vertical lane is simply
|
|
157
|
-
* occluded at that one cell and reappears on the next row.
|
|
158
|
-
*/
|
|
159
|
-
function resolveRowLaneColors(cells: readonly StructuralCell[]): RowLaneColors {
|
|
160
|
-
const lane = new Array<number>(cells.length);
|
|
161
|
-
const connector = new Array<number>(cells.length);
|
|
162
|
-
let arcCorner = NEUTRAL_LANE;
|
|
163
|
-
for (let column = cells.length - 1; column >= 0; column--) {
|
|
164
|
-
const cell = cells[column];
|
|
165
|
-
connector[column] = arcCorner;
|
|
166
|
-
switch (cell?.kind) {
|
|
167
|
-
case 'arc-branch-corner':
|
|
168
|
-
case 'arc-land-corner':
|
|
169
|
-
arcCorner = column;
|
|
170
|
-
lane[column] = column;
|
|
171
|
-
break;
|
|
172
|
-
case 'arc-branch-tee':
|
|
173
|
-
// An inner co-sourced arc's own back-lane junction: its vertical run
|
|
174
|
-
// continues below in this column, so it keeps its own column hue.
|
|
175
|
-
lane[column] = column;
|
|
176
|
-
break;
|
|
177
|
-
case 'arc-crossing':
|
|
178
|
-
case 'arc-land-bridge':
|
|
179
|
-
lane[column] = arcCorner;
|
|
180
|
-
break;
|
|
181
|
-
case 'horizontal-pass':
|
|
182
|
-
lane[column] = arcCorner === NEUTRAL_LANE ? column : arcCorner;
|
|
183
|
-
break;
|
|
184
|
-
case 'node':
|
|
185
|
-
lane[column] = column;
|
|
186
|
-
arcCorner = NEUTRAL_LANE;
|
|
187
|
-
break;
|
|
188
|
-
default:
|
|
189
|
-
lane[column] = column;
|
|
190
|
-
arcCorner = NEUTRAL_LANE;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return { lane, connector };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Per-cell colour for a forward branch/merge connector row, split into the
|
|
198
|
-
* cell's junction `glyph` and its trailing `dash`. A connector's horizontal run
|
|
199
|
-
* is one logical line (a fork into new lanes, or a merge into a surviving lane)
|
|
200
|
-
* and reads best as the colour of the lane each segment serves — not dim-gray
|
|
201
|
-
* or a per-pass-through-column "rainbow".
|
|
202
|
-
*/
|
|
203
|
-
interface ConnectorLaneColors {
|
|
204
|
-
/** Colour column for a cell's junction glyph (`├` / `┬` / `┴` / `╮` / `╯`). */
|
|
205
|
-
readonly glyph: readonly number[];
|
|
206
|
-
/** Colour column for a tee's trailing `─` — the branch it leads into. */
|
|
207
|
-
readonly dash: readonly number[];
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Resolve per-cell connector colours. Scanning right-to-left, a corner or an
|
|
212
|
-
* intermediate tee anchors its own lane (its junction glyph takes that column),
|
|
213
|
-
* but a tee's **trailing dash leads into the branch on its right** (the next
|
|
214
|
-
* branch point), so `┬─` reads as "this lane, then on toward the next" rather
|
|
215
|
-
* than tinting the dash with the left lane. The leading tee at `startLane` (the
|
|
216
|
-
* fork/merge origin) and pure horizontal segments inherit the nearest branch
|
|
217
|
-
* point to their right whole-cell, so the run into a branch — or collapsing
|
|
218
|
-
* into a merge corner — stays continuous. Pass-through verticals outside the
|
|
219
|
-
* run keep their own column (column 0 stays neutral).
|
|
220
|
-
*/
|
|
221
|
-
function resolveConnectorLaneColors(
|
|
222
|
-
cells: readonly StructuralCell[],
|
|
223
|
-
startLane: number,
|
|
224
|
-
): ConnectorLaneColors {
|
|
225
|
-
const glyph = new Array<number>(cells.length);
|
|
226
|
-
const dash = new Array<number>(cells.length);
|
|
227
|
-
let owner = NEUTRAL_LANE;
|
|
228
|
-
for (let column = cells.length - 1; column >= 0; column--) {
|
|
229
|
-
const cell = cells[column];
|
|
230
|
-
switch (cell?.kind) {
|
|
231
|
-
case 'branch-corner':
|
|
232
|
-
case 'merge-corner':
|
|
233
|
-
owner = column;
|
|
234
|
-
glyph[column] = column;
|
|
235
|
-
dash[column] = column;
|
|
236
|
-
break;
|
|
237
|
-
case 'branch-tee':
|
|
238
|
-
case 'merge-tee':
|
|
239
|
-
if (column === startLane) {
|
|
240
|
-
const served = owner === NEUTRAL_LANE ? column : owner;
|
|
241
|
-
glyph[column] = column;
|
|
242
|
-
dash[column] = served;
|
|
243
|
-
} else {
|
|
244
|
-
dash[column] = owner === NEUTRAL_LANE ? column : owner;
|
|
245
|
-
glyph[column] = column;
|
|
246
|
-
owner = column;
|
|
247
|
-
}
|
|
248
|
-
break;
|
|
249
|
-
case 'arc-crossing':
|
|
250
|
-
glyph[column] = column;
|
|
251
|
-
dash[column] = column;
|
|
252
|
-
break;
|
|
253
|
-
case 'horizontal-pass': {
|
|
254
|
-
const served = owner === NEUTRAL_LANE ? column : owner;
|
|
255
|
-
glyph[column] = served;
|
|
256
|
-
dash[column] = served;
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
default:
|
|
260
|
-
glyph[column] = column;
|
|
261
|
-
dash[column] = column;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return { glyph, dash };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Style a structural glyph by its resolved colour column. Column 0 and the
|
|
269
|
-
* neutral sentinel render dim (`style.lane`); columns ≥ 1 take a palette hue.
|
|
270
|
-
*/
|
|
271
|
-
function laneStylerForColumn(
|
|
272
|
-
colorColumn: number,
|
|
273
|
-
colorize: boolean,
|
|
274
|
-
style: MigrationListStyler,
|
|
275
|
-
): (text: string) => string {
|
|
276
|
-
if (!colorize || colorColumn <= NEUTRAL_LANE) {
|
|
277
|
-
return (text) => style.lane(text);
|
|
278
|
-
}
|
|
279
|
-
return laneColorForColumn(colorColumn);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Tint a branch-owned token (direction arrow, migration name) by its edge's
|
|
284
|
-
* lane so the whole branch row reads in one colour. Column 0 has nothing to be
|
|
285
|
-
* told apart from in the common linear chain, so it keeps the token's existing
|
|
286
|
-
* default styling (`fallback`) rather than a palette hue; only lanes ≥ 1 take a
|
|
287
|
-
* colour. With colour off, the fallback (also colourless) is used unchanged.
|
|
288
|
-
*/
|
|
289
|
-
function branchStylerOrDefault(
|
|
290
|
-
column: number,
|
|
291
|
-
colorize: boolean,
|
|
292
|
-
fallback: (text: string) => string,
|
|
293
|
-
): (text: string) => string {
|
|
294
|
-
if (!colorize || column <= NEUTRAL_LANE) {
|
|
295
|
-
return fallback;
|
|
296
|
-
}
|
|
297
|
-
return laneColorForColumn(column);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Render a connector tee (`├─` / `┬─` / `┴─`) with its junction glyph and its
|
|
302
|
-
* trailing dash coloured independently: the junction anchors its own lane while
|
|
303
|
-
* the dash leads into the branch on its right.
|
|
304
|
-
*/
|
|
305
|
-
function renderConnectorTee(
|
|
306
|
-
pair: string,
|
|
307
|
-
glyphColumn: number,
|
|
308
|
-
dashColumn: number,
|
|
309
|
-
colorize: boolean,
|
|
310
|
-
style: MigrationListStyler,
|
|
311
|
-
): string {
|
|
312
|
-
const glyph = laneStylerForColumn(glyphColumn, colorize, style);
|
|
313
|
-
if (glyphColumn === dashColumn) {
|
|
314
|
-
return glyph(pair);
|
|
315
|
-
}
|
|
316
|
-
return glyph(pair.slice(0, 1)) + laneStylerForColumn(dashColumn, colorize, style)(pair.slice(1));
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* A node-marker glyph pair (`○◂`, `○─`, `*<`, `*-`) is the contract node
|
|
321
|
-
* marker (`○` / `*`) followed by an arc connector (`◂` / `─` / `<` / `-`). The
|
|
322
|
-
* marker takes its own lane's hue (so each node visibly belongs to its branch);
|
|
323
|
-
* the connector follows the arc it belongs to (its owning back-lane hue).
|
|
324
|
-
* Direction arrows are handled elsewhere — they take their edge's lane hue too.
|
|
325
|
-
*/
|
|
326
|
-
function renderNodeMarkerPair(
|
|
327
|
-
pair: string,
|
|
328
|
-
nodeColumn: number,
|
|
329
|
-
arcColumn: number,
|
|
330
|
-
colorize: boolean,
|
|
331
|
-
style: MigrationListStyler,
|
|
332
|
-
): string {
|
|
333
|
-
const marker = laneStylerForColumn(nodeColumn, colorize, style);
|
|
334
|
-
const connector = laneStylerForColumn(arcColumn, colorize, style);
|
|
335
|
-
return marker(pair.slice(0, 1)) + connector(pair.slice(1));
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function renderCellPair(
|
|
339
|
-
cell: StructuralCell,
|
|
340
|
-
column: number,
|
|
341
|
-
colors: RowLaneColors,
|
|
342
|
-
colorize: boolean,
|
|
343
|
-
style: MigrationListStyler,
|
|
344
|
-
palette: MigrationGraphTreeGlyphPalette,
|
|
345
|
-
): string {
|
|
346
|
-
const laneColumn = colors.lane[column] ?? column;
|
|
347
|
-
const lane = laneStylerForColumn(laneColumn, colorize, style);
|
|
348
|
-
switch (cell.kind) {
|
|
349
|
-
case 'node': {
|
|
350
|
-
const arcColumn = colors.connector[column] ?? NEUTRAL_LANE;
|
|
351
|
-
if (cell.arcLand === true) {
|
|
352
|
-
return renderNodeMarkerPair(palette.arcLand, column, arcColumn, colorize, style);
|
|
353
|
-
}
|
|
354
|
-
if (cell.arcTee === true) {
|
|
355
|
-
return renderNodeMarkerPair(palette.arcTee, column, arcColumn, colorize, style);
|
|
356
|
-
}
|
|
357
|
-
return lane(palette.node);
|
|
358
|
-
}
|
|
359
|
-
case 'vertical-pass':
|
|
360
|
-
return lane(palette.verticalPass);
|
|
361
|
-
case 'edge-lane':
|
|
362
|
-
return cell.ownsLabel
|
|
363
|
-
? lane(palette.verticalPass.trimEnd()) +
|
|
364
|
-
branchStylerOrDefault(
|
|
365
|
-
column,
|
|
366
|
-
colorize,
|
|
367
|
-
style.kind,
|
|
368
|
-
)(arrowForEdgeKind(cell.edgeKind, palette))
|
|
369
|
-
: lane(palette.verticalPass);
|
|
370
|
-
case 'branch-tee':
|
|
371
|
-
return lane(palette.branchTee);
|
|
372
|
-
case 'merge-tee':
|
|
373
|
-
return lane(palette.mergeTee);
|
|
374
|
-
case 'branch-corner':
|
|
375
|
-
return lane(palette.branchCorner);
|
|
376
|
-
case 'merge-corner':
|
|
377
|
-
return lane(palette.mergeCorner);
|
|
378
|
-
case 'arc-branch-corner':
|
|
379
|
-
return lane(palette.arcBranchCorner);
|
|
380
|
-
case 'arc-branch-tee':
|
|
381
|
-
return lane(palette.arcBranchTee);
|
|
382
|
-
case 'arc-land-corner':
|
|
383
|
-
return lane(palette.arcLandCorner);
|
|
384
|
-
case 'arc-crossing':
|
|
385
|
-
return lane(palette.arcLandBridge);
|
|
386
|
-
case 'arc-land-bridge':
|
|
387
|
-
return lane(palette.arcLandBridge);
|
|
388
|
-
case 'horizontal-pass':
|
|
389
|
-
return lane(palette.horizontalPass);
|
|
390
|
-
case 'empty':
|
|
391
|
-
return ' ';
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function renderConnectorRow(
|
|
396
|
-
row: MigrationGraphGridRow,
|
|
397
|
-
gridWidth: number,
|
|
398
|
-
colorize: boolean,
|
|
399
|
-
style: MigrationListStyler,
|
|
400
|
-
palette: MigrationGraphTreeGlyphPalette,
|
|
401
|
-
): string {
|
|
402
|
-
const isMerge = row.kind === 'merge-connector';
|
|
403
|
-
if (row.cells.length > 0) {
|
|
404
|
-
const colors = resolveConnectorLaneColors(row.cells, row.startLane ?? 0);
|
|
405
|
-
let seenTee = false;
|
|
406
|
-
let out = '';
|
|
407
|
-
for (let column = 0; column < row.cells.length; column++) {
|
|
408
|
-
const cell = row.cells[column];
|
|
409
|
-
if (cell === undefined) continue;
|
|
410
|
-
const glyphColumn = colors.glyph[column] ?? column;
|
|
411
|
-
const dashColumn = colors.dash[column] ?? glyphColumn;
|
|
412
|
-
const lane = laneStylerForColumn(glyphColumn, colorize, style);
|
|
413
|
-
switch (cell.kind) {
|
|
414
|
-
case 'branch-tee':
|
|
415
|
-
out += renderConnectorTee(
|
|
416
|
-
seenTee ? palette.connectorBranchTeeCo : palette.connectorBranchTee,
|
|
417
|
-
glyphColumn,
|
|
418
|
-
dashColumn,
|
|
419
|
-
colorize,
|
|
420
|
-
style,
|
|
421
|
-
);
|
|
422
|
-
seenTee = true;
|
|
423
|
-
break;
|
|
424
|
-
case 'merge-tee':
|
|
425
|
-
out += renderConnectorTee(
|
|
426
|
-
seenTee ? palette.connectorMergeTeeCo : palette.connectorBranchTee,
|
|
427
|
-
glyphColumn,
|
|
428
|
-
dashColumn,
|
|
429
|
-
colorize,
|
|
430
|
-
style,
|
|
431
|
-
);
|
|
432
|
-
seenTee = true;
|
|
433
|
-
break;
|
|
434
|
-
case 'branch-corner':
|
|
435
|
-
out += lane(palette.branchCorner);
|
|
436
|
-
break;
|
|
437
|
-
case 'merge-corner':
|
|
438
|
-
out += lane(palette.mergeCorner);
|
|
439
|
-
break;
|
|
440
|
-
case 'vertical-pass':
|
|
441
|
-
out += lane(palette.verticalPass);
|
|
442
|
-
break;
|
|
443
|
-
case 'horizontal-pass':
|
|
444
|
-
out += lane(palette.horizontalPass);
|
|
445
|
-
break;
|
|
446
|
-
case 'arc-crossing':
|
|
447
|
-
out += renderConnectorTee(palette.arcCrossing, glyphColumn, dashColumn, colorize, style);
|
|
448
|
-
break;
|
|
449
|
-
default:
|
|
450
|
-
out += ' ';
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
// The cells array is sized to the grid width at emit time; a back-arc lane
|
|
454
|
-
// allocated by a later row can push the grid wider afterwards, so pad any
|
|
455
|
-
// trailing columns rather than dropping the lanes that pass through here.
|
|
456
|
-
for (let column = row.cells.length; column < gridWidth; column++) {
|
|
457
|
-
out += ' ';
|
|
458
|
-
}
|
|
459
|
-
return out;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
const start = row.startLane ?? 0;
|
|
463
|
-
const end = row.endLane ?? start;
|
|
464
|
-
// The whole fork/merge run reads as one line in the served lane's hue (the
|
|
465
|
-
// corner it reaches); pass-through columns outside the run keep their own.
|
|
466
|
-
const runLane = laneStylerForColumn(end, colorize, style);
|
|
467
|
-
let out = '';
|
|
468
|
-
for (let column = 0; column < gridWidth; column++) {
|
|
469
|
-
if (column < start || column > end) out += ' ';
|
|
470
|
-
else if (column === start) out += runLane(palette.connectorBranchTee);
|
|
471
|
-
else if (column === end) out += runLane(isMerge ? palette.mergeCorner : palette.branchCorner);
|
|
472
|
-
else out += runLane(isMerge ? palette.connectorMergeTeeCo : palette.connectorBranchTeeCo);
|
|
473
|
-
}
|
|
474
|
-
return out;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function abbreviateHash(hash: string, hashLength: number, emptySource: string): string {
|
|
478
|
-
if (hash === EMPTY_CONTRACT_HASH) {
|
|
479
|
-
return emptySource;
|
|
480
|
-
}
|
|
481
|
-
const stripped = hash.startsWith('sha256:') ? hash.slice(7) : hash;
|
|
482
|
-
return stripped.slice(0, hashLength);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const MIN_HASH_DATA_COLUMN = 25;
|
|
486
|
-
|
|
487
|
-
function overlayNamesForContract(
|
|
488
|
-
contractHash: string,
|
|
489
|
-
opts: RenderMigrationGraphTreeOptions,
|
|
490
|
-
): readonly string[] {
|
|
491
|
-
const names: string[] = [];
|
|
492
|
-
const userRefs = opts.refsByHash?.get(contractHash);
|
|
493
|
-
if (userRefs) {
|
|
494
|
-
names.push(...[...userRefs].sort((a, b) => a.localeCompare(b)));
|
|
495
|
-
}
|
|
496
|
-
if (opts.dbHash === contractHash) {
|
|
497
|
-
names.push(DB_MARKER_NAME);
|
|
498
|
-
}
|
|
499
|
-
if (opts.contractHash === contractHash && contractHash !== EMPTY_CONTRACT_HASH) {
|
|
500
|
-
names.push(CONTRACT_MARKER_NAME);
|
|
501
|
-
}
|
|
502
|
-
return names;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function createTreeStyler(opts: RenderMigrationGraphTreeOptions): MigrationListStyler {
|
|
506
|
-
const base = createAnsiMigrationListStyler({ useColor: opts.colorize });
|
|
507
|
-
const activeRefName = opts.activeRefName;
|
|
508
|
-
if (!opts.colorize || activeRefName === undefined) {
|
|
509
|
-
return base;
|
|
510
|
-
}
|
|
511
|
-
return {
|
|
512
|
-
...base,
|
|
513
|
-
refs: (names) => {
|
|
514
|
-
const styledNames = names.map((name) => (name === activeRefName ? bold(name) : name));
|
|
515
|
-
return base.refs(styledNames);
|
|
516
|
-
},
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
function formatEdgeHashColumn(
|
|
521
|
-
edge: ClassifiedEdge,
|
|
522
|
-
style: MigrationListStyler,
|
|
523
|
-
hashLength: number,
|
|
524
|
-
palette: MigrationGraphTreeGlyphPalette,
|
|
525
|
-
): string {
|
|
526
|
-
if (edge.kind === 'self') {
|
|
527
|
-
const hash = abbreviateHash(edge.from, hashLength, palette.emptySource);
|
|
528
|
-
return `${style.sourceHash(hash)} ${style.glyph(palette.forwardArrow)} ${style.destHash(hash)}`;
|
|
529
|
-
}
|
|
530
|
-
const source =
|
|
531
|
-
edge.from === EMPTY_CONTRACT_HASH
|
|
532
|
-
? style.glyph(palette.emptySource) +
|
|
533
|
-
' '.repeat(Math.max(0, hashLength - palette.emptySource.length))
|
|
534
|
-
: style.sourceHash(abbreviateHash(edge.from, hashLength, palette.emptySource));
|
|
535
|
-
const arrow = style.glyph(palette.forwardArrow);
|
|
536
|
-
const dest = style.destHash(abbreviateHash(edge.to, hashLength, palette.emptySource));
|
|
537
|
-
return `${source} ${arrow} ${dest}`;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
function padVisible(text: string, targetWidth: number): string {
|
|
541
|
-
const padding = Math.max(0, targetWidth - stringWidth(text));
|
|
542
|
-
return text + ' '.repeat(padding);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
const ANSI_ESCAPE = '\x1b';
|
|
546
|
-
|
|
547
|
-
function trimTrailingWhitespace(line: string): string {
|
|
548
|
-
const trailingSpaceBeforeReset = new RegExp(`[\\t ]+((?:${ANSI_ESCAPE}\\[[0-9;]*m)+)$`);
|
|
549
|
-
return line.replace(trailingSpaceBeforeReset, '$1').replace(/\s+$/, '');
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
function gridWidthForModel(rows: readonly MigrationGraphGridRow[]): number {
|
|
553
|
-
return rows.reduce(
|
|
554
|
-
(max, row) =>
|
|
555
|
-
row.kind === 'node' || row.kind === 'edge' ? Math.max(max, row.cells.length) : max,
|
|
556
|
-
1,
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function maxDirNameLength(edges: readonly ClassifiedEdge[]): number {
|
|
561
|
-
if (edges.length === 0) return 0;
|
|
562
|
-
return Math.max(...edges.map((edge) => edge.dirName.length));
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function rowDirNameWidth(labelColumn: number, maxDirNameLen: number, dirNameGap: number): number {
|
|
566
|
-
return Math.max(maxDirNameLen + dirNameGap, MIN_HASH_DATA_COLUMN - labelColumn);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function gridUsesSkipRollbackArcs(rows: readonly MigrationGraphGridRow[]): boolean {
|
|
570
|
-
return rows.some((row) =>
|
|
571
|
-
row.cells.some(
|
|
572
|
-
(cell) => cell.kind === 'edge-lane' && cell.adjacency === 'node-skipping-rollback',
|
|
573
|
-
),
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
function edgeLabelColumn(row: MigrationGraphGridRow, wideLabelColumn: number | undefined): number {
|
|
578
|
-
if (wideLabelColumn !== undefined) {
|
|
579
|
-
return wideLabelColumn;
|
|
580
|
-
}
|
|
581
|
-
const laneIndex = row.laneIndex ?? 0;
|
|
582
|
-
if (row.edge?.from === EMPTY_CONTRACT_HASH && laneIndex === 0) {
|
|
583
|
-
return (laneIndex + 1) * 2 + LABEL_GAP;
|
|
584
|
-
}
|
|
585
|
-
const usesFullRowGutter = row.cells.some(
|
|
586
|
-
(cell, index) => index > laneIndex && cell.kind === 'vertical-pass',
|
|
587
|
-
);
|
|
588
|
-
return usesFullRowGutter ? row.cells.length * 2 + LABEL_GAP : (laneIndex + 1) * 2 + LABEL_GAP;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
function nodeHasArcDecoration(row: MigrationGraphGridRow): boolean {
|
|
592
|
-
return row.cells.some(
|
|
593
|
-
(cell) => cell.kind === 'node' && (cell.arcTee === true || cell.arcLand === true),
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
export function renderMigrationGraphTree(
|
|
598
|
-
model: MigrationGraphGridModel,
|
|
599
|
-
opts: RenderMigrationGraphTreeOptions,
|
|
600
|
-
): string {
|
|
601
|
-
const glyphMode = opts.glyphMode ?? 'unicode';
|
|
602
|
-
const palette = paletteFor(glyphMode);
|
|
603
|
-
const style = createTreeStyler(opts);
|
|
604
|
-
const hashLength = opts.hashLength ?? MIGRATION_LIST_HASH_WIDTH;
|
|
605
|
-
const gridWidth = gridWidthForModel(model.rows);
|
|
606
|
-
const wideLabelColumn = gridUsesSkipRollbackArcs(model.rows) ? gridWidth * 2 + 4 : undefined;
|
|
607
|
-
const dirNameGap = wideLabelColumn !== undefined ? 3 : LABEL_GAP;
|
|
608
|
-
const allEdges = model.rows
|
|
609
|
-
.filter(
|
|
610
|
-
(row): row is MigrationGraphGridRow & { edge: ClassifiedEdge } =>
|
|
611
|
-
row.kind === 'edge' && row.edge !== undefined,
|
|
612
|
-
)
|
|
613
|
-
.map((row) => row.edge);
|
|
614
|
-
const maxDirNameLen = maxDirNameLength(allEdges);
|
|
615
|
-
|
|
616
|
-
const lines: string[] = [];
|
|
617
|
-
|
|
618
|
-
for (let rowIndex = 0; rowIndex < model.rows.length; rowIndex++) {
|
|
619
|
-
const row = model.rows[rowIndex];
|
|
620
|
-
if (row === undefined) continue;
|
|
621
|
-
|
|
622
|
-
if (row.kind === 'component-separator') {
|
|
623
|
-
lines.push('');
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (row.kind === 'branch-connector' || row.kind === 'merge-connector') {
|
|
628
|
-
lines.push(
|
|
629
|
-
trimTrailingWhitespace(renderConnectorRow(row, gridWidth, opts.colorize, style, palette)),
|
|
630
|
-
);
|
|
631
|
-
continue;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
const cellColors = resolveRowLaneColors(row.cells);
|
|
635
|
-
let gutter = row.cells
|
|
636
|
-
.map((cell, column) =>
|
|
637
|
-
renderCellPair(cell, column, cellColors, opts.colorize, style, palette),
|
|
638
|
-
)
|
|
639
|
-
.join('');
|
|
640
|
-
let laneSpan = row.cells.length;
|
|
641
|
-
if (row.kind === 'node') {
|
|
642
|
-
const contractHash = row.contractHash ?? EMPTY_CONTRACT_HASH;
|
|
643
|
-
if (contractHash === EMPTY_CONTRACT_HASH) {
|
|
644
|
-
laneSpan = 1;
|
|
645
|
-
} else {
|
|
646
|
-
let lastActiveColumn = -1;
|
|
647
|
-
for (let column = row.cells.length - 1; column >= 0; column--) {
|
|
648
|
-
if (row.cells[column]?.kind !== 'empty') {
|
|
649
|
-
lastActiveColumn = column;
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
laneSpan = lastActiveColumn >= 0 ? lastActiveColumn + 1 : 1;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
const labelColumn =
|
|
657
|
-
row.kind === 'edge'
|
|
658
|
-
? edgeLabelColumn(row, wideLabelColumn)
|
|
659
|
-
: wideLabelColumn !== undefined &&
|
|
660
|
-
(nodeHasArcDecoration(row) || row.contractHash !== undefined)
|
|
661
|
-
? wideLabelColumn
|
|
662
|
-
: laneSpan * 2 + LABEL_GAP;
|
|
663
|
-
if (
|
|
664
|
-
row.kind === 'edge' &&
|
|
665
|
-
row.edge?.from === EMPTY_CONTRACT_HASH &&
|
|
666
|
-
(row.laneIndex ?? 0) === 0
|
|
667
|
-
) {
|
|
668
|
-
gutter = row.cells
|
|
669
|
-
.slice(0, 1)
|
|
670
|
-
.map((cell, column) =>
|
|
671
|
-
renderCellPair(cell, column, cellColors, opts.colorize, style, palette),
|
|
672
|
-
)
|
|
673
|
-
.join('');
|
|
674
|
-
} else if (row.kind === 'node' && laneSpan < row.cells.length && !nodeHasArcDecoration(row)) {
|
|
675
|
-
gutter = row.cells
|
|
676
|
-
.slice(0, laneSpan)
|
|
677
|
-
.map((cell, column) =>
|
|
678
|
-
renderCellPair(cell, column, cellColors, opts.colorize, style, palette),
|
|
679
|
-
)
|
|
680
|
-
.join('');
|
|
681
|
-
} else if (gutter.length < laneSpan * 2) {
|
|
682
|
-
gutter = gutter.padEnd(laneSpan * 2, ' ');
|
|
683
|
-
}
|
|
684
|
-
const dirNameWidth = rowDirNameWidth(labelColumn, maxDirNameLen, dirNameGap);
|
|
685
|
-
const dataColumn = labelColumn + dirNameWidth;
|
|
686
|
-
const gutterPad = padVisible(gutter, labelColumn);
|
|
687
|
-
|
|
688
|
-
if (row.kind === 'node') {
|
|
689
|
-
const contractHash = row.contractHash ?? EMPTY_CONTRACT_HASH;
|
|
690
|
-
if (contractHash === EMPTY_CONTRACT_HASH) {
|
|
691
|
-
const trailingLanes = row.cells
|
|
692
|
-
.slice(1)
|
|
693
|
-
.map((cell, offset) =>
|
|
694
|
-
renderCellPair(cell, offset + 1, cellColors, opts.colorize, style, palette),
|
|
695
|
-
)
|
|
696
|
-
.join('');
|
|
697
|
-
const emptyGutter = palette.emptySource.padEnd(2, ' ') + trailingLanes;
|
|
698
|
-
const overlayNames = overlayNamesForContract(contractHash, opts);
|
|
699
|
-
if (overlayNames.length === 0) {
|
|
700
|
-
lines.push(trimTrailingWhitespace(emptyGutter));
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
const overlay = style.refs(overlayNames);
|
|
704
|
-
lines.push(trimTrailingWhitespace(`${padVisible(emptyGutter, dataColumn)}${overlay}`));
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
const hashText = style.sourceHash(
|
|
708
|
-
abbreviateHash(contractHash, hashLength, palette.emptySource),
|
|
709
|
-
);
|
|
710
|
-
const overlayNames = overlayNamesForContract(contractHash, opts);
|
|
711
|
-
const overlayPad =
|
|
712
|
-
overlayNames.length > 0
|
|
713
|
-
? ' '.repeat(Math.max(0, dataColumn - labelColumn - stringWidth(hashText)))
|
|
714
|
-
: '';
|
|
715
|
-
const overlay = overlayNames.length > 0 ? style.refs(overlayNames) : '';
|
|
716
|
-
lines.push(trimTrailingWhitespace(`${gutterPad}${hashText}${overlayPad}${overlay}`));
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
const edge = row.edge;
|
|
721
|
-
if (edge === undefined) continue;
|
|
722
|
-
|
|
723
|
-
const dirNamePadding = ' '.repeat(Math.max(0, dirNameWidth - edge.dirName.length));
|
|
724
|
-
const laneIndex = row.laneIndex ?? 0;
|
|
725
|
-
// A branched name keeps its bold (via `style.dirName`) and adds the lane
|
|
726
|
-
// hue, so it reads as one with its lane/arrow; column-0 names stay bold-only.
|
|
727
|
-
const dirNameStyler =
|
|
728
|
-
opts.colorize && laneIndex > NEUTRAL_LANE
|
|
729
|
-
? (text: string) => forcedBold(laneColorForColumn(laneIndex)(text))
|
|
730
|
-
: style.dirName;
|
|
731
|
-
const dirName = `${dirNameStyler(edge.dirName)}${dirNamePadding}`;
|
|
732
|
-
const hashColumn = formatEdgeHashColumn(edge, style, hashLength, palette);
|
|
733
|
-
lines.push(trimTrailingWhitespace(`${gutterPad}${dirName}${hashColumn}`));
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
return lines.join('\n');
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
export interface RenderMigrationGraphLegendOptions {
|
|
740
|
-
readonly colorize: boolean;
|
|
741
|
-
readonly glyphMode?: GlyphMode;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* A compact key for the `--tree` visual language: the contract marker, the
|
|
746
|
-
* in-lane direction arrows, the empty baseline, the `(refs)` overlay (including
|
|
747
|
-
* the reserved `db` live-database and `contract` working-schema markers), and a
|
|
748
|
-
* worked sample of the data-column `from → to` migration hash arrow.
|
|
749
|
-
*
|
|
750
|
-
* Honors the same glyph palette (unicode vs ASCII) and `colorize` gate as the
|
|
751
|
-
* tree renderer, so the key matches whatever the graph itself drew and stays
|
|
752
|
-
* pipe-safe (zero ANSI when color is off). The caller adds the trailing blank
|
|
753
|
-
* line that separates this stderr key from the graph on stdout.
|
|
754
|
-
*/
|
|
755
|
-
export function renderMigrationGraphLegend(opts: RenderMigrationGraphLegendOptions): string {
|
|
756
|
-
const palette = paletteFor(opts.glyphMode ?? 'unicode');
|
|
757
|
-
const style = createAnsiMigrationListStyler({ useColor: opts.colorize });
|
|
758
|
-
const node = palette.node.trimEnd();
|
|
759
|
-
const sampleArrow = `${style.sourceHash('aaaaaa')} ${style.glyph(palette.forwardArrow)} ${style.destHash('bbbbbb')}`;
|
|
760
|
-
return [
|
|
761
|
-
'Legend:',
|
|
762
|
-
` ${style.kind(node)} contract ${style.kind(palette.edgeArrow.forward)} forward ${style.kind(palette.edgeArrow.rollback)} rollback`,
|
|
763
|
-
` ${style.kind(palette.edgeArrow.self)} migration without schema change`,
|
|
764
|
-
` ${style.glyph(palette.emptySource)} empty database (baseline)`,
|
|
765
|
-
` ${style.refs(['refs'])} ${DB_MARKER_NAME} / ${CONTRACT_MARKER_NAME} markers`,
|
|
766
|
-
` ${sampleArrow} migration from contract aaaaaa to bbbbbb`,
|
|
767
|
-
].join('\n');
|
|
768
|
-
}
|