@prisma-next/cli 0.11.0-dev.5 → 0.11.0-dev.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/cli-errors-DFF1LlfU.mjs +215 -0
  2. package/dist/cli-errors-DFF1LlfU.mjs.map +1 -0
  3. package/dist/cli.mjs +9 -10
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/{client-oXO2WCPD.mjs → client-5uvDppD8.mjs} +23 -21
  6. package/dist/client-5uvDppD8.mjs.map +1 -0
  7. package/dist/{command-helpers-DtavI0wJ.mjs → command-helpers-4UNsRRc4.mjs} +427 -9
  8. package/dist/command-helpers-4UNsRRc4.mjs.map +1 -0
  9. package/dist/commands/contract-emit.d.mts.map +1 -1
  10. package/dist/commands/contract-emit.mjs +1 -1
  11. package/dist/commands/contract-infer.d.mts.map +1 -1
  12. package/dist/commands/contract-infer.mjs +1 -1
  13. package/dist/commands/db-init.d.mts.map +1 -1
  14. package/dist/commands/db-init.mjs +33 -7
  15. package/dist/commands/db-init.mjs.map +1 -1
  16. package/dist/commands/db-schema.d.mts.map +1 -1
  17. package/dist/commands/db-schema.mjs +3 -4
  18. package/dist/commands/db-schema.mjs.map +1 -1
  19. package/dist/commands/db-sign.d.mts.map +1 -1
  20. package/dist/commands/db-sign.mjs +6 -7
  21. package/dist/commands/db-sign.mjs.map +1 -1
  22. package/dist/commands/db-update.d.mts.map +1 -1
  23. package/dist/commands/db-update.mjs +36 -8
  24. package/dist/commands/db-update.mjs.map +1 -1
  25. package/dist/commands/db-verify.d.mts.map +1 -1
  26. package/dist/commands/db-verify.mjs +1 -1
  27. package/dist/commands/migrate.d.mts +5 -1
  28. package/dist/commands/migrate.d.mts.map +1 -1
  29. package/dist/commands/migrate.mjs +79 -39
  30. package/dist/commands/migrate.mjs.map +1 -1
  31. package/dist/commands/migration-check.d.mts +4 -3
  32. package/dist/commands/migration-check.d.mts.map +1 -1
  33. package/dist/commands/migration-check.mjs +1 -280
  34. package/dist/commands/migration-graph.d.mts +1 -1
  35. package/dist/commands/migration-graph.d.mts.map +1 -1
  36. package/dist/commands/migration-graph.mjs +3 -4
  37. package/dist/commands/migration-graph.mjs.map +1 -1
  38. package/dist/commands/migration-list.d.mts +63 -12
  39. package/dist/commands/migration-list.d.mts.map +1 -1
  40. package/dist/commands/migration-list.mjs +2 -103
  41. package/dist/commands/migration-log.d.mts.map +1 -1
  42. package/dist/commands/migration-log.mjs +3 -4
  43. package/dist/commands/migration-log.mjs.map +1 -1
  44. package/dist/commands/migration-new.d.mts.map +1 -1
  45. package/dist/commands/migration-new.mjs +33 -38
  46. package/dist/commands/migration-new.mjs.map +1 -1
  47. package/dist/commands/migration-plan.d.mts +2 -1
  48. package/dist/commands/migration-plan.d.mts.map +1 -1
  49. package/dist/commands/migration-plan.mjs +1 -1
  50. package/dist/commands/migration-show.d.mts +4 -55
  51. package/dist/commands/migration-show.d.mts.map +1 -1
  52. package/dist/commands/migration-show.mjs +62 -153
  53. package/dist/commands/migration-show.mjs.map +1 -1
  54. package/dist/commands/migration-status.d.mts +5 -40
  55. package/dist/commands/migration-status.d.mts.map +1 -1
  56. package/dist/commands/migration-status.mjs +93 -67
  57. package/dist/commands/migration-status.mjs.map +1 -1
  58. package/dist/commands/ref.d.mts +1 -1
  59. package/dist/commands/ref.d.mts.map +1 -1
  60. package/dist/commands/ref.mjs +34 -9
  61. package/dist/commands/ref.mjs.map +1 -1
  62. package/dist/config-loader-B6sJjXTv.mjs.map +1 -1
  63. package/dist/config-loader.d.mts.map +1 -1
  64. package/dist/{contract-emit-o-8VmdQX.mjs → contract-emit-C-CFGZsI.mjs} +9 -6
  65. package/dist/{contract-emit-o-8VmdQX.mjs.map → contract-emit-C-CFGZsI.mjs.map} +1 -1
  66. package/dist/{contract-emit-CmsklifJ.mjs → contract-emit-CuUzzM46.mjs} +5 -6
  67. package/dist/{contract-emit-CmsklifJ.mjs.map → contract-emit-CuUzzM46.mjs.map} +1 -1
  68. package/dist/{contract-enrichment-Dani0mMW.mjs → contract-enrichment-XmUPhmsS.mjs} +4 -25
  69. package/dist/contract-enrichment-XmUPhmsS.mjs.map +1 -0
  70. package/dist/{contract-infer-pKkiCt7C.mjs → contract-infer-C98ZaRhp.mjs} +3 -4
  71. package/dist/{contract-infer-pKkiCt7C.mjs.map → contract-infer-C98ZaRhp.mjs.map} +1 -1
  72. package/dist/contract-space-aggregate-loader-CVHGuA35.mjs +170 -0
  73. package/dist/contract-space-aggregate-loader-CVHGuA35.mjs.map +1 -0
  74. package/dist/{db-verify-AoIUriL4.mjs → db-verify-BWl1Yxi-.mjs} +6 -7
  75. package/dist/{db-verify-AoIUriL4.mjs.map → db-verify-BWl1Yxi-.mjs.map} +1 -1
  76. package/dist/exports/control-api.d.mts +1 -1
  77. package/dist/exports/control-api.d.mts.map +1 -1
  78. package/dist/exports/control-api.mjs +3 -3
  79. package/dist/exports/index.d.mts.map +1 -1
  80. package/dist/exports/index.mjs +1 -1
  81. package/dist/exports/index.mjs.map +1 -1
  82. package/dist/exports/init-output.d.mts.map +1 -1
  83. package/dist/exports/init-output.mjs +1 -1
  84. package/dist/extension-pack-inputs-BiY86HbQ.mjs +62 -0
  85. package/dist/extension-pack-inputs-BiY86HbQ.mjs.map +1 -0
  86. package/dist/{framework-components-65gOHkHB.mjs → framework-components-DTcjouhS.mjs} +2 -2
  87. package/dist/{framework-components-65gOHkHB.mjs.map → framework-components-DTcjouhS.mjs.map} +1 -1
  88. package/dist/{global-flags-CdE7M0d9.d.mts → global-flags-DWsQ6SSI.d.mts} +1 -1
  89. package/dist/global-flags-DWsQ6SSI.d.mts.map +1 -0
  90. package/dist/glyph-mode-CBB4emzO.d.mts +5 -0
  91. package/dist/glyph-mode-CBB4emzO.d.mts.map +1 -0
  92. package/dist/{graph-render-DJVv0_uf.mjs → graph-render-D2FnLpuK.mjs} +1 -1
  93. package/dist/{graph-render-DJVv0_uf.mjs.map → graph-render-D2FnLpuK.mjs.map} +1 -1
  94. package/dist/{init-Db5Itt5r.mjs → init-C7PvN163.mjs} +5 -5
  95. package/dist/{init-Db5Itt5r.mjs.map → init-C7PvN163.mjs.map} +1 -1
  96. package/dist/{inspect-live-schema-LeWvkZVz.mjs → inspect-live-schema-BRCWQ-Sr.mjs} +5 -5
  97. package/dist/{inspect-live-schema-LeWvkZVz.mjs.map → inspect-live-schema-BRCWQ-Sr.mjs.map} +1 -1
  98. package/dist/migration-check-DoskM1nB.mjs +341 -0
  99. package/dist/migration-check-DoskM1nB.mjs.map +1 -0
  100. package/dist/migration-cli.d.mts.map +1 -1
  101. package/dist/migration-cli.mjs +4 -4
  102. package/dist/migration-cli.mjs.map +1 -1
  103. package/dist/{migration-command-scaffold-BtkunvFQ.mjs → migration-command-scaffold-CXLkoIJx.mjs} +5 -5
  104. package/dist/{migration-command-scaffold-BtkunvFQ.mjs.map → migration-command-scaffold-CXLkoIJx.mjs.map} +1 -1
  105. package/dist/migration-list-B2-iQ5Jd.mjs +646 -0
  106. package/dist/migration-list-B2-iQ5Jd.mjs.map +1 -0
  107. package/dist/{migration-plan-C2jeH1J5.mjs → migration-plan-BqmIKQpZ.mjs} +341 -88
  108. package/dist/migration-plan-BqmIKQpZ.mjs.map +1 -0
  109. package/dist/{migration-types-BXWvz12q.d.mts → migration-types-q64xAI_J.d.mts} +1 -1
  110. package/dist/{migration-types-BXWvz12q.d.mts.map → migration-types-q64xAI_J.d.mts.map} +1 -1
  111. package/dist/{migrations-CwZMa1Ck.mjs → migrations-BcVTutso.mjs} +12 -13
  112. package/dist/migrations-BcVTutso.mjs.map +1 -0
  113. package/dist/{output-BlsrGMEF.mjs → output-B60Gw5fu.mjs} +1 -1
  114. package/dist/{output-BlsrGMEF.mjs.map → output-B60Gw5fu.mjs.map} +1 -1
  115. package/dist/{progress-adapter-DFfvZcYL.mjs → progress-adapter-xASh41wr.mjs} +1 -1
  116. package/dist/{progress-adapter-DFfvZcYL.mjs.map → progress-adapter-xASh41wr.mjs.map} +1 -1
  117. package/dist/ref-advancement-DRh5Nquq.mjs +50 -0
  118. package/dist/ref-advancement-DRh5Nquq.mjs.map +1 -0
  119. package/dist/{types-C9FfXb1l.d.mts → types-CEtm6v6a.d.mts} +5 -11
  120. package/dist/types-CEtm6v6a.d.mts.map +1 -0
  121. package/dist/{verify-Bom75OYI.mjs → verify-DOHbbrub.mjs} +2 -2
  122. package/dist/{verify-Bom75OYI.mjs.map → verify-DOHbbrub.mjs.map} +1 -1
  123. package/package.json +20 -20
  124. package/src/commands/db-init.ts +48 -2
  125. package/src/commands/db-update.ts +45 -0
  126. package/src/commands/migrate.ts +120 -40
  127. package/src/commands/migration-check.ts +43 -83
  128. package/src/commands/migration-list.ts +173 -74
  129. package/src/commands/migration-new.ts +44 -48
  130. package/src/commands/migration-plan.ts +359 -128
  131. package/src/commands/migration-show.ts +65 -284
  132. package/src/commands/migration-status.ts +131 -99
  133. package/src/commands/ref.ts +46 -6
  134. package/src/control-api/client.ts +0 -1
  135. package/src/control-api/contract-enrichment.ts +6 -42
  136. package/src/control-api/operations/contract-emit.ts +7 -2
  137. package/src/control-api/operations/db-verify.ts +9 -5
  138. package/src/control-api/operations/migration-apply.ts +11 -19
  139. package/src/control-api/types.ts +0 -7
  140. package/src/migration-cli.ts +4 -4
  141. package/src/utils/cli-errors.ts +224 -0
  142. package/src/utils/command-helpers.ts +9 -4
  143. package/src/utils/contract-space-aggregate-loader.ts +221 -117
  144. package/src/utils/formatters/migration-list-data-column.ts +115 -0
  145. package/src/utils/formatters/migration-list-graph-layout.ts +268 -0
  146. package/src/utils/formatters/migration-list-graph-render.ts +314 -0
  147. package/src/utils/formatters/migration-list-render.ts +194 -0
  148. package/src/utils/formatters/migration-list-styler.ts +61 -0
  149. package/src/utils/formatters/migrations.ts +29 -38
  150. package/src/utils/glyph-mode.ts +22 -0
  151. package/src/utils/integrity-violation-to-check-failure.ts +130 -0
  152. package/src/utils/plan-resolution.ts +257 -0
  153. package/src/utils/ref-advancement.ts +68 -0
  154. package/src/utils/terminal-ui.ts +42 -1
  155. package/dist/cli-errors-Czmx92Zy.d.mts +0 -3
  156. package/dist/cli-errors-Djtz98Vm.mjs +0 -71
  157. package/dist/cli-errors-Djtz98Vm.mjs.map +0 -1
  158. package/dist/client-oXO2WCPD.mjs.map +0 -1
  159. package/dist/command-helpers-DtavI0wJ.mjs.map +0 -1
  160. package/dist/commands/migration-check.mjs.map +0 -1
  161. package/dist/commands/migration-list.mjs.map +0 -1
  162. package/dist/contract-enrichment-Dani0mMW.mjs.map +0 -1
  163. package/dist/contract-space-aggregate-loader-BmNQwlws.mjs +0 -160
  164. package/dist/contract-space-aggregate-loader-BmNQwlws.mjs.map +0 -1
  165. package/dist/global-flags-CdE7M0d9.d.mts.map +0 -1
  166. package/dist/migration-plan-C2jeH1J5.mjs.map +0 -1
  167. package/dist/migrations-CwZMa1Ck.mjs.map +0 -1
  168. package/dist/terminal-ui-BiB_8KNo.mjs +0 -379
  169. package/dist/terminal-ui-BiB_8KNo.mjs.map +0 -1
  170. package/dist/types-C9FfXb1l.d.mts.map +0 -1
@@ -0,0 +1,257 @@
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import type { ControlFamilyInstance } from '@prisma-next/framework-components/control';
3
+ import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
4
+ import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
5
+ import {
6
+ assertHashIsGraphNode,
7
+ findLatestMigration,
8
+ isGraphNode,
9
+ } from '@prisma-next/migration-tools/migration-graph';
10
+ import type { OnDiskMigrationPackage } from '@prisma-next/migration-tools/package';
11
+ import { parseContractRef } from '@prisma-next/migration-tools/ref-resolution';
12
+ import type { Refs } from '@prisma-next/migration-tools/refs';
13
+ import { readRefSnapshot, readRefs } from '@prisma-next/migration-tools/refs';
14
+ import { notOk, ok, type Result } from '@prisma-next/utils/result';
15
+ import {
16
+ CliStructuredError,
17
+ errorContractValidationFailed,
18
+ errorPlanForgotTheFlag,
19
+ errorSnapshotMissing,
20
+ errorUnexpected,
21
+ mapMigrationToolsError,
22
+ mapRefResolutionError,
23
+ } from './cli-errors';
24
+
25
+ const FULL_HASH_PATTERN = /^sha256:([0-9a-f]{64}|empty)$/;
26
+
27
+ export function looksLikeFullHash(input: string): boolean {
28
+ return FULL_HASH_PATTERN.test(input);
29
+ }
30
+
31
+ export type FromResolution =
32
+ | { kind: 'greenfield'; fromHash: null; fromContract: null }
33
+ | { kind: 'graph-node'; fromHash: string; fromContract: Contract; sourceDir: string }
34
+ | {
35
+ kind: 'snapshot';
36
+ fromHash: string;
37
+ fromContract: Contract;
38
+ contractDts: string;
39
+ contractJson: unknown;
40
+ }
41
+ | {
42
+ kind: 'auto-baseline';
43
+ fromHash: string;
44
+ fromContract: Contract;
45
+ contractDts: string;
46
+ contractJson: unknown;
47
+ };
48
+
49
+ export interface ResolveFromForPlanInput {
50
+ readonly optionsFrom?: string | undefined;
51
+ readonly refsDir: string;
52
+ readonly bundles: readonly OnDiskMigrationPackage[];
53
+ readonly graph: MigrationGraph;
54
+ readonly familyInstance: ControlFamilyInstance<string, unknown>;
55
+ readonly readBundleEndContract: (migrationDir: string) => Promise<Contract>;
56
+ }
57
+
58
+ function graphIsEmpty(bundles: readonly OnDiskMigrationPackage[]): boolean {
59
+ return bundles.length === 0;
60
+ }
61
+
62
+ function getReachableRefs(
63
+ refs: Refs,
64
+ graph: MigrationGraph,
65
+ ): ReadonlyArray<{ name: string; hash: string }> {
66
+ return Object.entries(refs)
67
+ .flatMap(([name, entry]) =>
68
+ entry && isGraphNode(entry.hash, graph) ? [{ name, hash: entry.hash }] : [],
69
+ )
70
+ .sort((a, b) => a.name.localeCompare(b.name));
71
+ }
72
+
73
+ export function assertFromIsGraphNode(
74
+ fromHash: string,
75
+ graph: MigrationGraph,
76
+ refs: Refs,
77
+ graphTipHash: string | null,
78
+ ): void {
79
+ try {
80
+ assertHashIsGraphNode(fromHash, graph);
81
+ } catch (error) {
82
+ if (MigrationToolsError.is(error) && error.code === 'MIGRATION.HASH_NOT_IN_GRAPH') {
83
+ throw errorPlanForgotTheFlag(fromHash, getReachableRefs(refs, graph), graphTipHash);
84
+ }
85
+ throw error;
86
+ }
87
+ }
88
+
89
+ async function deserializeSnapshotContract(
90
+ familyInstance: ControlFamilyInstance<string, unknown>,
91
+ contract: unknown,
92
+ ): Promise<Result<Contract, CliStructuredError>> {
93
+ try {
94
+ return ok(familyInstance.deserializeContract(contract));
95
+ } catch (error) {
96
+ if (CliStructuredError.is(error)) {
97
+ return notOk(error);
98
+ }
99
+ return notOk(
100
+ errorContractValidationFailed(
101
+ `Ref snapshot contract failed to deserialize: ${error instanceof Error ? error.message : String(error)}`,
102
+ { where: { path: 'ref-snapshot' } },
103
+ ),
104
+ );
105
+ }
106
+ }
107
+
108
+ async function resolveGraphNodeFromBundle(
109
+ fromHash: string,
110
+ bundles: readonly OnDiskMigrationPackage[],
111
+ readBundleEndContract: (migrationDir: string) => Promise<Contract>,
112
+ explicitFromLabel?: string,
113
+ ): Promise<Result<Extract<FromResolution, { kind: 'graph-node' }>, CliStructuredError>> {
114
+ const matchingBundle = bundles.find((pkg) => pkg.metadata.to === fromHash);
115
+ if (!matchingBundle) {
116
+ return notOk(
117
+ errorUnexpected(
118
+ explicitFromLabel
119
+ ? `No migration bundle found for --from "${explicitFromLabel}" (resolved hash: ${fromHash})`
120
+ : `No migration bundle found for graph node ${fromHash}`,
121
+ {
122
+ why: `The hash ${fromHash} is a graph node but no on-disk migration package has an end-contract hash matching it.`,
123
+ fix: 'Provide a ref or hash that corresponds to an existing migration package, or run `migration list` to see available migrations.',
124
+ },
125
+ ),
126
+ );
127
+ }
128
+ try {
129
+ const fromContract = await readBundleEndContract(matchingBundle.dirPath);
130
+ return ok({
131
+ kind: 'graph-node',
132
+ fromHash,
133
+ fromContract,
134
+ sourceDir: matchingBundle.dirPath,
135
+ });
136
+ } catch (error) {
137
+ if (CliStructuredError.is(error)) {
138
+ return notOk(error);
139
+ }
140
+ throw error;
141
+ }
142
+ }
143
+
144
+ async function resolveFromRefName(
145
+ refName: string,
146
+ fromHash: string,
147
+ input: ResolveFromForPlanInput,
148
+ refs: Refs,
149
+ ): Promise<Result<FromResolution, CliStructuredError>> {
150
+ const { refsDir, bundles, graph, familyInstance, readBundleEndContract } = input;
151
+ const empty = graphIsEmpty(bundles);
152
+ const graphTip = findLatestMigration(graph)?.to ?? null;
153
+
154
+ let snapshot: Awaited<ReturnType<typeof readRefSnapshot>>;
155
+ try {
156
+ snapshot = await readRefSnapshot(refsDir, refName);
157
+ } catch (error) {
158
+ if (MigrationToolsError.is(error)) {
159
+ return notOk(mapMigrationToolsError(error));
160
+ }
161
+ throw error;
162
+ }
163
+
164
+ if (snapshot) {
165
+ const contractResult = await deserializeSnapshotContract(familyInstance, snapshot.contract);
166
+ if (!contractResult.ok) {
167
+ return contractResult;
168
+ }
169
+ const fromContract = contractResult.value;
170
+ const { contractDts, contract: contractJson } = snapshot;
171
+ if (empty) {
172
+ return ok({ kind: 'auto-baseline', fromHash, fromContract, contractDts, contractJson });
173
+ }
174
+ try {
175
+ assertFromIsGraphNode(fromHash, graph, refs, graphTip);
176
+ } catch (error) {
177
+ if (CliStructuredError.is(error)) {
178
+ return notOk(error);
179
+ }
180
+ throw error;
181
+ }
182
+ return ok({ kind: 'snapshot', fromHash, fromContract, contractDts, contractJson });
183
+ }
184
+
185
+ if (isGraphNode(fromHash, graph)) {
186
+ return resolveGraphNodeFromBundle(fromHash, bundles, readBundleEndContract);
187
+ }
188
+
189
+ return notOk(errorSnapshotMissing(refName));
190
+ }
191
+
192
+ async function resolveFromHashProvenance(
193
+ fromHash: string,
194
+ input: ResolveFromForPlanInput,
195
+ _refs: Refs,
196
+ explicitFromLabel?: string,
197
+ ): Promise<Result<FromResolution, CliStructuredError>> {
198
+ const { bundles, graph } = input;
199
+
200
+ if (isGraphNode(fromHash, graph)) {
201
+ return resolveGraphNodeFromBundle(
202
+ fromHash,
203
+ bundles,
204
+ input.readBundleEndContract,
205
+ explicitFromLabel,
206
+ );
207
+ }
208
+
209
+ throw new Error(
210
+ `resolveFromHashProvenance: non-graph-node hash ${fromHash} should be refused via looksLikeFullHash before this helper is called`,
211
+ );
212
+ }
213
+
214
+ export async function resolveFromForPlan(
215
+ input: ResolveFromForPlanInput,
216
+ ): Promise<Result<FromResolution, CliStructuredError>> {
217
+ const { optionsFrom, refsDir, graph } = input;
218
+
219
+ let refs: Refs;
220
+ try {
221
+ refs = await readRefs(refsDir);
222
+ } catch (error) {
223
+ if (MigrationToolsError.is(error)) {
224
+ return notOk(mapMigrationToolsError(error));
225
+ }
226
+ throw error;
227
+ }
228
+
229
+ if (optionsFrom === undefined) {
230
+ const dbRef = refs['db'];
231
+ if (!dbRef) {
232
+ return ok({ kind: 'greenfield', fromHash: null, fromContract: null });
233
+ }
234
+ return resolveFromRefName('db', dbRef.hash, input, refs);
235
+ }
236
+
237
+ const refResult = parseContractRef(optionsFrom, { graph, refs });
238
+ if (!refResult.ok) {
239
+ if (looksLikeFullHash(optionsFrom)) {
240
+ const empty = graphIsEmpty(input.bundles);
241
+ const graphTip = findLatestMigration(graph)?.to ?? null;
242
+ if (empty) {
243
+ return notOk(errorSnapshotMissing(optionsFrom, { viaRef: false }));
244
+ }
245
+ return notOk(errorPlanForgotTheFlag(optionsFrom, getReachableRefs(refs, graph), graphTip));
246
+ }
247
+ return notOk(mapRefResolutionError(refResult.failure));
248
+ }
249
+
250
+ const { hash: fromHash, provenance } = refResult.value;
251
+
252
+ if (provenance.kind === 'ref') {
253
+ return resolveFromRefName(provenance.refName, fromHash, input, refs);
254
+ }
255
+
256
+ return resolveFromHashProvenance(fromHash, input, refs, optionsFrom);
257
+ }
@@ -0,0 +1,68 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import type { ContractIR } from '@prisma-next/migration-tools/refs';
3
+ import { writeRefPaired } from '@prisma-next/migration-tools/refs';
4
+ import { ifDefined } from '@prisma-next/utils/defined';
5
+
6
+ export interface RefAdvancementFields {
7
+ readonly advancedRef: { readonly name: string; readonly hash: string } | null;
8
+ readonly plannedAdvanceRef: { readonly name: string; readonly hash: string } | null;
9
+ }
10
+
11
+ export function computeRefAdvancementName(options: {
12
+ readonly advanceRef?: string;
13
+ readonly db?: string;
14
+ }): string | null {
15
+ if (options.advanceRef !== undefined) {
16
+ return options.advanceRef;
17
+ }
18
+ if (options.db === undefined) {
19
+ return 'db';
20
+ }
21
+ return null;
22
+ }
23
+
24
+ export async function readContractIR(
25
+ contractJson: Record<string, unknown>,
26
+ contractJsonPath: string,
27
+ ): Promise<ContractIR> {
28
+ const contractDtsPath = contractJsonPath.replace(/\.json$/i, '.d.ts');
29
+ const contractDts = await readFile(contractDtsPath, 'utf-8');
30
+ return { contract: contractJson, contractDts };
31
+ }
32
+
33
+ export async function executeRefAdvancement(
34
+ refsDir: string,
35
+ name: string,
36
+ hash: string,
37
+ contractIR: ContractIR,
38
+ ): Promise<{ name: string; hash: string }> {
39
+ await writeRefPaired(refsDir, name, { hash, invariants: [] }, contractIR);
40
+ return { name, hash };
41
+ }
42
+
43
+ export async function buildRefAdvancementFields(options: {
44
+ readonly advanceRef?: string;
45
+ readonly db?: string;
46
+ readonly refsDir: string;
47
+ readonly contractIR: ContractIR;
48
+ readonly mode: 'plan' | 'apply';
49
+ readonly hash: string;
50
+ }): Promise<RefAdvancementFields> {
51
+ const name = computeRefAdvancementName({
52
+ ...ifDefined('advanceRef', options.advanceRef),
53
+ ...ifDefined('db', options.db),
54
+ });
55
+ if (name === null) {
56
+ return { advancedRef: null, plannedAdvanceRef: null };
57
+ }
58
+ if (options.mode === 'plan') {
59
+ return { advancedRef: null, plannedAdvanceRef: { name, hash: options.hash } };
60
+ }
61
+ const advancedRef = await executeRefAdvancement(
62
+ options.refsDir,
63
+ name,
64
+ options.hash,
65
+ options.contractIR,
66
+ );
67
+ return { advancedRef, plannedAdvanceRef: null };
68
+ }
@@ -1,8 +1,11 @@
1
1
  import * as clack from '@clack/prompts';
2
2
  import { bold, cyan, dim, green, red, yellow } from 'colorette';
3
3
  import type { GlobalFlags } from './global-flags';
4
+ import { detectGlyphMode, type GlyphMode, type GlyphModeInput } from './glyph-mode';
4
5
  import { shutdownSignal } from './shutdown';
5
6
 
7
+ export interface TerminalUIRuntime extends GlyphModeInput {}
8
+
6
9
  /**
7
10
  * Composable CLI output abstraction.
8
11
  *
@@ -36,17 +39,50 @@ export class TerminalUI {
36
39
  */
37
40
  readonly forcePretty: boolean;
38
41
 
42
+ /**
43
+ * Whether stdout is a TTY — used for migration-list graph glyph detection.
44
+ */
45
+ readonly stdoutIsTTY: boolean;
46
+
47
+ /**
48
+ * Process environment snapshot for locale-aware glyph detection.
49
+ */
50
+ readonly env: Readonly<Record<string, string | undefined>>;
51
+
39
52
  private static readonly stderrOpts = { output: process.stderr } as const;
40
53
 
41
54
  constructor(options?: {
42
55
  readonly color?: boolean | undefined;
43
56
  readonly interactive?: boolean | undefined;
44
57
  readonly forcePretty?: boolean | undefined;
58
+ readonly stdoutIsTTY?: boolean | undefined;
59
+ readonly env?: Readonly<Record<string, string | undefined>> | undefined;
45
60
  }) {
46
61
  // --interactive/--no-interactive override TTY detection
47
62
  this.isInteractive = options?.interactive ?? !!process.stdout.isTTY;
48
63
  this.forcePretty = options?.forcePretty ?? false;
49
64
  this.useColor = options?.color ?? (this.isInteractive || this.forcePretty);
65
+ this.stdoutIsTTY = options?.stdoutIsTTY ?? !!process.stdout.isTTY;
66
+ this.env = options?.env ?? process.env;
67
+ }
68
+
69
+ get isTTY(): boolean {
70
+ return this.stdoutIsTTY;
71
+ }
72
+
73
+ /**
74
+ * Resolve graph glyph mode for `migration list --graph`. `--ascii` forces
75
+ * ASCII; otherwise delegates to the pure {@link detectGlyphMode} helper.
76
+ */
77
+ resolveGlyphMode(forceAscii: boolean): GlyphMode {
78
+ if (forceAscii) {
79
+ return 'ascii';
80
+ }
81
+ return detectGlyphMode(this.glyphModeInput());
82
+ }
83
+
84
+ glyphModeInput(): GlyphModeInput {
85
+ return { isTTY: this.stdoutIsTTY, env: this.env };
50
86
  }
51
87
 
52
88
  private get shouldDecorate(): boolean {
@@ -288,10 +324,15 @@ export class TerminalUI {
288
324
  }
289
325
  }
290
326
 
291
- export function createTerminalUI(flags: GlobalFlags): TerminalUI {
327
+ export function createTerminalUI(
328
+ flags: GlobalFlags,
329
+ runtime?: Partial<TerminalUIRuntime>,
330
+ ): TerminalUI {
292
331
  return new TerminalUI({
293
332
  color: flags.color,
294
333
  interactive: flags.interactive,
295
334
  forcePretty: flags.format === 'pretty' && flags.explicitFormat,
335
+ stdoutIsTTY: runtime?.isTTY,
336
+ env: runtime?.env,
296
337
  });
297
338
  }
@@ -1,3 +0,0 @@
1
- import { CliStructuredError as CliStructuredError$1 } from "@prisma-next/errors/control";
2
- import { MigrationToolsError } from "@prisma-next/migration-tools/errors";
3
- export { CliStructuredError$1 as t };
@@ -1,71 +0,0 @@
1
- import { CliStructuredError as CliStructuredError$1, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing as errorContractConfigMissing$1, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorInvalidOutputFormat, errorMigrationPlanningFailed, errorOutputFormatMutex, errorTargetMigrationNotSupported, errorUnexpected as errorUnexpected$1 } from "@prisma-next/errors/control";
2
- import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
3
- import "@prisma-next/errors/migration";
4
- //#region src/utils/cli-errors.ts
5
- /**
6
- * Maps a `MigrationToolsError` raised by the migration-tools loader/graph
7
- * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,
8
- * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.
9
- *
10
- * The full `error.details` payload is forwarded into `meta` so machine
11
- * consumers (`--json`) see structural fields like `dir`, `storedHash`,
12
- * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable
13
- * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.
14
- *
15
- * Callers are expected to gate on `MigrationToolsError.is(error)` first
16
- * (mirroring the original inline pattern); non-`MigrationToolsError`
17
- * values are caller-classified (rethrow, wrap with command-specific
18
- * `errorUnexpected`, etc.).
19
- */
20
- function mapMigrationToolsError(error) {
21
- return errorRuntime(error.message, {
22
- why: error.why,
23
- fix: error.fix,
24
- meta: {
25
- code: error.code,
26
- ...error.details ?? {}
27
- }
28
- });
29
- }
30
- /**
31
- * Maps a `RefResolutionError` from the contract/migration reference
32
- * resolver into a CLI structured error envelope.
33
- */
34
- function mapRefResolutionError(error) {
35
- switch (error.kind) {
36
- case "not-found": return errorRuntime(`Not a known ${error.grammar} reference: "${error.input}"`, {
37
- why: `No ${error.grammar} matching "${error.input}" exists in the migration graph or refs index.`,
38
- fix: error.grammar === "contract" ? "Provide a valid contract hash, ref name, or migration directory name." : "Provide a valid migration directory name or migration hash.",
39
- meta: {
40
- input: error.input,
41
- grammar: error.grammar
42
- }
43
- });
44
- case "ambiguous": return errorRuntime(`Ambiguous ${error.grammar} reference: "${error.input}"`, {
45
- why: `"${error.input}" matches multiple ${error.grammar}s: ${error.candidates.join(", ")}`,
46
- fix: "Provide a longer prefix or use the full hash to disambiguate.",
47
- meta: {
48
- input: error.input,
49
- candidates: error.candidates,
50
- grammar: error.grammar
51
- }
52
- });
53
- case "wrong-grammar": return errorRuntime(error.message, {
54
- why: error.message,
55
- fix: error.fix,
56
- meta: {
57
- input: error.input,
58
- expectedGrammar: error.expectedGrammar
59
- }
60
- });
61
- case "invalid-format": return errorRuntime(`Invalid reference format: "${error.input}"`, {
62
- why: error.reason,
63
- fix: "Provide a valid contract hash, ref name, or migration directory name.",
64
- meta: { input: error.input }
65
- });
66
- }
67
- }
68
- //#endregion
69
- export { errorTargetMigrationNotSupported as _, errorContractValidationFailed as a, mapMigrationToolsError as b, errorDriverRequired as c, errorInvalidOutputFormat as d, errorMarkerMissing as f, errorRuntime$1 as g, errorRunnerFailed as h, errorContractConfigMissing$1 as i, errorFileNotFound as l, errorOutputFormatMutex as m, ERROR_CODE_DESTRUCTIVE_CHANGES as n, errorDatabaseConnectionRequired as o, errorMigrationPlanningFailed as p, errorConfigValidation$1 as r, errorDestructiveChanges as s, CliStructuredError$1 as t, errorHashMismatch as u, errorTargetMismatch as v, mapRefResolutionError as x, errorUnexpected$1 as y };
70
-
71
- //# sourceMappingURL=cli-errors-Djtz98Vm.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-errors-Djtz98Vm.mjs","names":[],"sources":["../src/utils/cli-errors.ts"],"sourcesContent":["/**\n * Re-export all domain error factories from @prisma-next/errors for convenience.\n * CLI-specific errors (e.g., Commander argument validation in the main CLI, or\n * clipanion parse errors in the migration-file CLI) can be added here if needed.\n */\nexport type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/errors/control';\n\nimport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorInvalidOutputFormat,\n errorMigrationCliInvalidConfigArg,\n errorMigrationCliUnknownFlag,\n errorMigrationPlanningFailed,\n errorOutputFormatMutex,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { errorRuntime } from '@prisma-next/errors/execution';\nimport type { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport type { RefResolutionError } from '@prisma-next/migration-tools/ref-resolution';\n\nexport {\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorDestructiveChanges,\n errorHashMismatch,\n errorMarkerMissing,\n errorMarkerRequired,\n errorRunnerFailed,\n errorRuntime,\n errorSchemaVerificationFailed,\n errorTargetMismatch,\n} from '@prisma-next/errors/execution';\nexport {\n errorMigrationFileMissing,\n errorMigrationInvalidDefaultExport,\n errorMigrationPlanNotArray,\n errorUnfilledPlaceholder,\n placeholder,\n} from '@prisma-next/errors/migration';\nexport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorInvalidOutputFormat,\n errorMigrationCliInvalidConfigArg,\n errorMigrationCliUnknownFlag,\n errorMigrationPlanningFailed,\n errorOutputFormatMutex,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n};\n\n/**\n * Maps a `MigrationToolsError` raised by the migration-tools loader/graph\n * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,\n * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.\n *\n * The full `error.details` payload is forwarded into `meta` so machine\n * consumers (`--json`) see structural fields like `dir`, `storedHash`,\n * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable\n * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.\n *\n * Callers are expected to gate on `MigrationToolsError.is(error)` first\n * (mirroring the original inline pattern); non-`MigrationToolsError`\n * values are caller-classified (rethrow, wrap with command-specific\n * `errorUnexpected`, etc.).\n */\nexport function mapMigrationToolsError(error: MigrationToolsError): CliStructuredError {\n return errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code, ...(error.details ?? {}) },\n });\n}\n\n/**\n * Maps a `RefResolutionError` from the contract/migration reference\n * resolver into a CLI structured error envelope.\n */\nexport function mapRefResolutionError(error: RefResolutionError): CliStructuredError {\n switch (error.kind) {\n case 'not-found':\n return errorRuntime(`Not a known ${error.grammar} reference: \"${error.input}\"`, {\n why: `No ${error.grammar} matching \"${error.input}\" exists in the migration graph or refs index.`,\n fix:\n error.grammar === 'contract'\n ? 'Provide a valid contract hash, ref name, or migration directory name.'\n : 'Provide a valid migration directory name or migration hash.',\n meta: { input: error.input, grammar: error.grammar },\n });\n case 'ambiguous':\n return errorRuntime(`Ambiguous ${error.grammar} reference: \"${error.input}\"`, {\n why: `\"${error.input}\" matches multiple ${error.grammar}s: ${error.candidates.join(', ')}`,\n fix: 'Provide a longer prefix or use the full hash to disambiguate.',\n meta: { input: error.input, candidates: error.candidates, grammar: error.grammar },\n });\n case 'wrong-grammar':\n return errorRuntime(error.message, {\n why: error.message,\n fix: error.fix,\n meta: { input: error.input, expectedGrammar: error.expectedGrammar },\n });\n case 'invalid-format':\n return errorRuntime(`Invalid reference format: \"${error.input}\"`, {\n why: error.reason,\n fix: 'Provide a valid contract hash, ref name, or migration directory name.',\n meta: { input: error.input },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqFA,SAAgB,uBAAuB,OAAgD;CACrF,OAAO,aAAa,MAAM,SAAS;EACjC,KAAK,MAAM;EACX,KAAK,MAAM;EACX,MAAM;GAAE,MAAM,MAAM;GAAM,GAAI,MAAM,WAAW,EAAE;GAAG;EACrD,CAAC;;;;;;AAOJ,SAAgB,sBAAsB,OAA+C;CACnF,QAAQ,MAAM,MAAd;EACE,KAAK,aACH,OAAO,aAAa,eAAe,MAAM,QAAQ,eAAe,MAAM,MAAM,IAAI;GAC9E,KAAK,MAAM,MAAM,QAAQ,aAAa,MAAM,MAAM;GAClD,KACE,MAAM,YAAY,aACd,0EACA;GACN,MAAM;IAAE,OAAO,MAAM;IAAO,SAAS,MAAM;IAAS;GACrD,CAAC;EACJ,KAAK,aACH,OAAO,aAAa,aAAa,MAAM,QAAQ,eAAe,MAAM,MAAM,IAAI;GAC5E,KAAK,IAAI,MAAM,MAAM,qBAAqB,MAAM,QAAQ,KAAK,MAAM,WAAW,KAAK,KAAK;GACxF,KAAK;GACL,MAAM;IAAE,OAAO,MAAM;IAAO,YAAY,MAAM;IAAY,SAAS,MAAM;IAAS;GACnF,CAAC;EACJ,KAAK,iBACH,OAAO,aAAa,MAAM,SAAS;GACjC,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAM;IAAE,OAAO,MAAM;IAAO,iBAAiB,MAAM;IAAiB;GACrE,CAAC;EACJ,KAAK,kBACH,OAAO,aAAa,8BAA8B,MAAM,MAAM,IAAI;GAChE,KAAK,MAAM;GACX,KAAK;GACL,MAAM,EAAE,OAAO,MAAM,OAAO;GAC7B,CAAC"}