@prisma-next/cli 0.3.0-dev.4 → 0.3.0-dev.41

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 (106) hide show
  1. package/README.md +125 -40
  2. package/dist/cli.d.mts +1 -0
  3. package/dist/cli.js +1 -2376
  4. package/dist/cli.mjs +168 -0
  5. package/dist/cli.mjs.map +1 -0
  6. package/dist/client-Lm9Q6aQM.mjs +694 -0
  7. package/dist/client-Lm9Q6aQM.mjs.map +1 -0
  8. package/dist/commands/contract-emit.d.mts +7 -0
  9. package/dist/commands/contract-emit.d.mts.map +1 -0
  10. package/dist/commands/contract-emit.mjs +140 -0
  11. package/dist/commands/contract-emit.mjs.map +1 -0
  12. package/dist/commands/db-init.d.mts +7 -0
  13. package/dist/commands/db-init.d.mts.map +1 -0
  14. package/dist/commands/db-init.mjs +179 -0
  15. package/dist/commands/db-init.mjs.map +1 -0
  16. package/dist/commands/db-introspect.d.mts +7 -0
  17. package/dist/commands/db-introspect.d.mts.map +1 -0
  18. package/dist/commands/db-introspect.mjs +120 -0
  19. package/dist/commands/db-introspect.mjs.map +1 -0
  20. package/dist/commands/db-schema-verify.d.mts +7 -0
  21. package/dist/commands/db-schema-verify.d.mts.map +1 -0
  22. package/dist/commands/db-schema-verify.mjs +116 -0
  23. package/dist/commands/db-schema-verify.mjs.map +1 -0
  24. package/dist/commands/db-sign.d.mts +7 -0
  25. package/dist/commands/db-sign.d.mts.map +1 -0
  26. package/dist/commands/db-sign.mjs +138 -0
  27. package/dist/commands/db-sign.mjs.map +1 -0
  28. package/dist/commands/db-verify.d.mts +7 -0
  29. package/dist/commands/db-verify.d.mts.map +1 -0
  30. package/dist/commands/db-verify.mjs +129 -0
  31. package/dist/commands/db-verify.mjs.map +1 -0
  32. package/dist/config-loader-CnnWuluc.mjs +42 -0
  33. package/dist/config-loader-CnnWuluc.mjs.map +1 -0
  34. package/dist/{config-loader.d.ts → config-loader.d.mts} +5 -2
  35. package/dist/config-loader.d.mts.map +1 -0
  36. package/dist/config-loader.mjs +3 -0
  37. package/dist/exports/config-types.d.mts +2 -0
  38. package/dist/exports/config-types.mjs +3 -0
  39. package/dist/exports/control-api.d.mts +451 -0
  40. package/dist/exports/control-api.d.mts.map +1 -0
  41. package/dist/exports/control-api.mjs +59 -0
  42. package/dist/exports/control-api.mjs.map +1 -0
  43. package/dist/{index.d.ts → exports/index.d.mts} +7 -6
  44. package/dist/exports/index.d.mts.map +1 -0
  45. package/dist/exports/index.mjs +130 -0
  46. package/dist/exports/index.mjs.map +1 -0
  47. package/dist/result-handler-BZPY7HX4.mjs +1029 -0
  48. package/dist/result-handler-BZPY7HX4.mjs.map +1 -0
  49. package/package.json +50 -38
  50. package/src/cli.ts +260 -0
  51. package/src/commands/contract-emit.ts +267 -0
  52. package/src/commands/db-init.ts +355 -0
  53. package/src/commands/db-introspect.ts +227 -0
  54. package/src/commands/db-schema-verify.ts +238 -0
  55. package/src/commands/db-sign.ts +279 -0
  56. package/src/commands/db-verify.ts +259 -0
  57. package/src/config-loader.ts +76 -0
  58. package/src/control-api/client.ts +591 -0
  59. package/src/control-api/operations/contract-emit.ts +103 -0
  60. package/src/control-api/operations/db-init.ts +281 -0
  61. package/src/control-api/types.ts +493 -0
  62. package/src/exports/config-types.ts +6 -0
  63. package/src/exports/control-api.ts +51 -0
  64. package/src/exports/index.ts +4 -0
  65. package/src/load-ts-contract.ts +222 -0
  66. package/src/utils/cli-errors.ts +26 -0
  67. package/src/utils/command-helpers.ts +26 -0
  68. package/src/utils/framework-components.ts +177 -0
  69. package/src/utils/global-flags.ts +75 -0
  70. package/src/utils/output.ts +1477 -0
  71. package/src/utils/progress-adapter.ts +86 -0
  72. package/src/utils/result-handler.ts +44 -0
  73. package/dist/chunk-464LNZCE.js +0 -134
  74. package/dist/chunk-464LNZCE.js.map +0 -1
  75. package/dist/chunk-BZMBKEEQ.js +0 -997
  76. package/dist/chunk-BZMBKEEQ.js.map +0 -1
  77. package/dist/chunk-HWYQOCAJ.js +0 -47
  78. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  79. package/dist/chunk-ZKYEJROM.js +0 -94
  80. package/dist/chunk-ZKYEJROM.js.map +0 -1
  81. package/dist/cli.js.map +0 -1
  82. package/dist/commands/contract-emit.d.ts +0 -5
  83. package/dist/commands/contract-emit.js +0 -9
  84. package/dist/commands/contract-emit.js.map +0 -1
  85. package/dist/commands/db-init.d.ts +0 -5
  86. package/dist/commands/db-init.js +0 -341
  87. package/dist/commands/db-init.js.map +0 -1
  88. package/dist/commands/db-introspect.d.ts +0 -5
  89. package/dist/commands/db-introspect.js +0 -190
  90. package/dist/commands/db-introspect.js.map +0 -1
  91. package/dist/commands/db-schema-verify.d.ts +0 -5
  92. package/dist/commands/db-schema-verify.js +0 -164
  93. package/dist/commands/db-schema-verify.js.map +0 -1
  94. package/dist/commands/db-sign.d.ts +0 -5
  95. package/dist/commands/db-sign.js +0 -199
  96. package/dist/commands/db-sign.js.map +0 -1
  97. package/dist/commands/db-verify.d.ts +0 -5
  98. package/dist/commands/db-verify.js +0 -173
  99. package/dist/commands/db-verify.js.map +0 -1
  100. package/dist/config-loader.js +0 -7
  101. package/dist/config-loader.js.map +0 -1
  102. package/dist/config-types.d.ts +0 -1
  103. package/dist/config-types.js +0 -6
  104. package/dist/config-types.js.map +0 -1
  105. package/dist/index.js +0 -175
  106. package/dist/index.js.map +0 -1
@@ -0,0 +1,1029 @@
1
+ import { relative } from "node:path";
2
+ import { ifDefined } from "@prisma-next/utils/defined";
3
+ import { bgGreen, blue, bold, cyan, dim, green, magenta, red, yellow } from "colorette";
4
+ import stringWidth from "string-width";
5
+ import stripAnsi from "strip-ansi";
6
+ import wrapAnsi from "wrap-ansi";
7
+ import ora from "ora";
8
+
9
+ //#region src/utils/command-helpers.ts
10
+ /**
11
+ * Sets both short and long descriptions for a command.
12
+ * The short description is used in command trees and headers.
13
+ * The long description is shown at the bottom of help output.
14
+ */
15
+ function setCommandDescriptions(command, shortDescription, longDescription) {
16
+ command.description(shortDescription);
17
+ if (longDescription) command._longDescription = longDescription;
18
+ return command;
19
+ }
20
+ /**
21
+ * Gets the long description from a command if it was set via setCommandDescriptions.
22
+ */
23
+ function getLongDescription(command) {
24
+ return command._longDescription;
25
+ }
26
+
27
+ //#endregion
28
+ //#region src/utils/global-flags.ts
29
+ /**
30
+ * Parses global flags from CLI options.
31
+ * Handles verbosity flags (-v, -vv, --trace), JSON output, quiet mode, timestamps, and color.
32
+ */
33
+ function parseGlobalFlags(options) {
34
+ const flags = {};
35
+ if (options.json === true || options.json === "object") flags.json = "object";
36
+ else if (options.json === "ndjson") flags.json = "ndjson";
37
+ if (options.quiet || options.q) flags.quiet = true;
38
+ if (options.vv || options.trace) flags.verbose = 2;
39
+ else if (options.verbose || options.v) flags.verbose = 1;
40
+ else flags.verbose = 0;
41
+ if (options.timestamps) flags.timestamps = true;
42
+ if (process.env["NO_COLOR"] || flags.json) flags.color = false;
43
+ else if (options["no-color"]) flags.color = false;
44
+ else if (options.color !== void 0) flags.color = options.color;
45
+ else flags.color = process.stdout.isTTY && !process.env["CI"];
46
+ return flags;
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/utils/output.ts
51
+ /**
52
+ * Formats a timestamp for output.
53
+ */
54
+ function formatTimestamp() {
55
+ return (/* @__PURE__ */ new Date()).toISOString();
56
+ }
57
+ /**
58
+ * Creates a prefix string if timestamps are enabled.
59
+ */
60
+ function createPrefix(flags) {
61
+ return flags.timestamps ? `[${formatTimestamp()}] ` : "";
62
+ }
63
+ /**
64
+ * Checks if verbose output is enabled at the specified level.
65
+ */
66
+ function isVerbose(flags, level) {
67
+ return (flags.verbose ?? 0) >= level;
68
+ }
69
+ /**
70
+ * Creates a color-aware formatter function.
71
+ * Returns a function that applies the color only if colors are enabled.
72
+ */
73
+ function createColorFormatter(useColor, colorFn) {
74
+ return useColor ? colorFn : (text) => text;
75
+ }
76
+ /**
77
+ * Formats text with dim styling if colors are enabled.
78
+ */
79
+ function formatDim(useColor, text) {
80
+ return useColor ? dim(text) : text;
81
+ }
82
+ /**
83
+ * Formats human-readable output for contract emit.
84
+ */
85
+ function formatEmitOutput(result, flags) {
86
+ if (flags.quiet) return "";
87
+ const lines = [];
88
+ const prefix = createPrefix(flags);
89
+ const jsonPath = relative(process.cwd(), result.files.json);
90
+ const dtsPath = relative(process.cwd(), result.files.dts);
91
+ lines.push(`${prefix}✔ Emitted contract.json → ${jsonPath}`);
92
+ lines.push(`${prefix}✔ Emitted contract.d.ts → ${dtsPath}`);
93
+ lines.push(`${prefix} storageHash: ${result.storageHash}`);
94
+ if (result.executionHash) lines.push(`${prefix} executionHash: ${result.executionHash}`);
95
+ if (result.profileHash) lines.push(`${prefix} profileHash: ${result.profileHash}`);
96
+ if (isVerbose(flags, 1)) lines.push(`${prefix} Total time: ${result.timings.total}ms`);
97
+ return lines.join("\n");
98
+ }
99
+ /**
100
+ * Formats JSON output for contract emit.
101
+ */
102
+ function formatEmitJson(result) {
103
+ const output = {
104
+ ok: true,
105
+ storageHash: result.storageHash,
106
+ ...ifDefined("executionHash", result.executionHash),
107
+ ...result.profileHash ? { profileHash: result.profileHash } : {},
108
+ outDir: result.outDir,
109
+ files: result.files,
110
+ timings: result.timings
111
+ };
112
+ return JSON.stringify(output, null, 2);
113
+ }
114
+ /**
115
+ * Formats error output for human-readable display.
116
+ */
117
+ function formatErrorOutput(error, flags) {
118
+ const lines = [];
119
+ const prefix = createPrefix(flags);
120
+ const useColor = flags.color !== false;
121
+ const formatRed = createColorFormatter(useColor, red);
122
+ const formatDimText = (text) => formatDim(useColor, text);
123
+ lines.push(`${prefix}${formatRed("✖")} ${error.summary} (${error.code})`);
124
+ if (error.why) lines.push(`${prefix}${formatDimText(` Why: ${error.why}`)}`);
125
+ if (error.fix) lines.push(`${prefix}${formatDimText(` Fix: ${error.fix}`)}`);
126
+ if (error.where?.path) {
127
+ const whereLine = error.where.line ? `${error.where.path}:${error.where.line}` : error.where.path;
128
+ lines.push(`${prefix}${formatDimText(` Where: ${whereLine}`)}`);
129
+ }
130
+ if (error.meta?.["conflicts"]) {
131
+ const conflicts = error.meta["conflicts"];
132
+ if (conflicts.length > 0) {
133
+ const maxToShow = isVerbose(flags, 1) ? conflicts.length : Math.min(3, conflicts.length);
134
+ const header = isVerbose(flags, 1) ? " Conflicts:" : ` Conflicts (showing ${maxToShow} of ${conflicts.length}):`;
135
+ lines.push(`${prefix}${formatDimText(header)}`);
136
+ for (const conflict of conflicts.slice(0, maxToShow)) lines.push(`${prefix}${formatDimText(` - [${conflict.kind}] ${conflict.summary}`)}`);
137
+ if (!isVerbose(flags, 1) && conflicts.length > maxToShow) lines.push(`${prefix}${formatDimText(" Re-run with -v/--verbose to see all conflicts")}`);
138
+ }
139
+ }
140
+ if (error.meta?.["issues"]) {
141
+ const issues = error.meta["issues"];
142
+ if (issues.length > 0) {
143
+ const maxToShow = isVerbose(flags, 1) ? issues.length : Math.min(3, issues.length);
144
+ const header = isVerbose(flags, 1) ? " Issues:" : ` Issues (showing ${maxToShow} of ${issues.length}):`;
145
+ lines.push(`${prefix}${formatDimText(header)}`);
146
+ for (const issue of issues.slice(0, maxToShow)) {
147
+ const kind = issue.kind ?? "issue";
148
+ const message = issue.message ?? "";
149
+ lines.push(`${prefix}${formatDimText(` - [${kind}] ${message}`)}`);
150
+ }
151
+ if (!isVerbose(flags, 1) && issues.length > maxToShow) lines.push(`${prefix}${formatDimText(" Re-run with -v/--verbose to see all issues")}`);
152
+ }
153
+ }
154
+ if (error.docsUrl && isVerbose(flags, 1)) lines.push(formatDimText(error.docsUrl));
155
+ if (isVerbose(flags, 2) && error.meta) lines.push(`${prefix}${formatDimText(` Meta: ${JSON.stringify(error.meta, null, 2)}`)}`);
156
+ return lines.join("\n");
157
+ }
158
+ /**
159
+ * Formats error output as JSON.
160
+ */
161
+ function formatErrorJson(error) {
162
+ return JSON.stringify(error, null, 2);
163
+ }
164
+ /**
165
+ * Formats human-readable output for database verify.
166
+ */
167
+ function formatVerifyOutput(result, flags) {
168
+ if (flags.quiet) return "";
169
+ const lines = [];
170
+ const prefix = createPrefix(flags);
171
+ const useColor = flags.color !== false;
172
+ const formatGreen = createColorFormatter(useColor, green);
173
+ const formatRed = createColorFormatter(useColor, red);
174
+ const formatDimText = (text) => formatDim(useColor, text);
175
+ if (result.ok) {
176
+ lines.push(`${prefix}${formatGreen("✔")} ${result.summary}`);
177
+ lines.push(`${prefix}${formatDimText(` storageHash: ${result.contract.storageHash}`)}`);
178
+ if (result.contract.profileHash) lines.push(`${prefix}${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
179
+ } else lines.push(`${prefix}${formatRed("✖")} ${result.summary} (${result.code})`);
180
+ if (isVerbose(flags, 1)) {
181
+ if (result.codecCoverageSkipped) lines.push(`${prefix}${formatDimText(" Codec coverage check skipped (helper returned no supported types)")}`);
182
+ lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
183
+ }
184
+ return lines.join("\n");
185
+ }
186
+ /**
187
+ * Formats JSON output for database verify.
188
+ */
189
+ function formatVerifyJson(result) {
190
+ const output = {
191
+ ok: result.ok,
192
+ ...result.code ? { code: result.code } : {},
193
+ summary: result.summary,
194
+ contract: result.contract,
195
+ ...result.marker ? { marker: result.marker } : {},
196
+ target: result.target,
197
+ ...result.missingCodecs ? { missingCodecs: result.missingCodecs } : {},
198
+ ...result.meta ? { meta: result.meta } : {},
199
+ timings: result.timings
200
+ };
201
+ return JSON.stringify(output, null, 2);
202
+ }
203
+ /**
204
+ * Formats JSON output for database introspection.
205
+ */
206
+ function formatIntrospectJson(result) {
207
+ return JSON.stringify(result, null, 2);
208
+ }
209
+ /**
210
+ * Renders a schema tree structure from CoreSchemaView.
211
+ * Matches the style of renderSchemaVerificationTree for consistency.
212
+ */
213
+ function renderSchemaTree(node, flags, options) {
214
+ const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
215
+ const lines = [];
216
+ let formattedLabel = node.label;
217
+ if (useColor) switch (node.kind) {
218
+ case "root":
219
+ formattedLabel = bold(node.label);
220
+ break;
221
+ case "entity": {
222
+ const tableMatch = node.label.match(/^table\s+(.+)$/);
223
+ if (tableMatch?.[1]) {
224
+ const tableName = tableMatch[1];
225
+ formattedLabel = `${dim("table")} ${cyan(tableName)}`;
226
+ } else formattedLabel = cyan(node.label);
227
+ break;
228
+ }
229
+ case "collection":
230
+ formattedLabel = dim(node.label);
231
+ break;
232
+ case "field": {
233
+ const columnMatch = node.label.match(/^([^:]+):\s*(.+)$/);
234
+ if (columnMatch?.[1] && columnMatch[2]) {
235
+ const columnName = columnMatch[1];
236
+ const rest = columnMatch[2];
237
+ const typeMatch = rest.match(/^([^\s(]+)\s*(\([^)]+\))$/);
238
+ if (typeMatch?.[1] && typeMatch[2]) {
239
+ const typeDisplay = typeMatch[1];
240
+ const nullability = typeMatch[2];
241
+ formattedLabel = `${cyan(columnName)}: ${typeDisplay} ${dim(nullability)}`;
242
+ } else formattedLabel = `${cyan(columnName)}: ${rest}`;
243
+ } else formattedLabel = node.label;
244
+ break;
245
+ }
246
+ case "index": {
247
+ const pkMatch = node.label.match(/^primary key:\s*(.+)$/);
248
+ if (pkMatch?.[1]) {
249
+ const columnNames = pkMatch[1];
250
+ formattedLabel = `${dim("primary key")}: ${cyan(columnNames)}`;
251
+ } else {
252
+ const uniqueMatch = node.label.match(/^unique\s+(.+)$/);
253
+ if (uniqueMatch?.[1]) {
254
+ const name = uniqueMatch[1];
255
+ formattedLabel = `${dim("unique")} ${cyan(name)}`;
256
+ } else {
257
+ const indexMatch = node.label.match(/^(unique\s+)?index\s+(.+)$/);
258
+ if (indexMatch?.[2]) {
259
+ const prefix$1 = indexMatch[1] ? `${dim("unique")} ` : "";
260
+ const name = indexMatch[2];
261
+ formattedLabel = `${prefix$1}${dim("index")} ${cyan(name)}`;
262
+ } else formattedLabel = dim(node.label);
263
+ }
264
+ }
265
+ break;
266
+ }
267
+ case "extension": {
268
+ const extMatch = node.label.match(/^([^\s]+)\s+(extension is enabled)$/);
269
+ if (extMatch?.[1] && extMatch[2]) {
270
+ const extName = extMatch[1];
271
+ const rest = extMatch[2];
272
+ formattedLabel = `${cyan(extName)} ${dim(rest)}`;
273
+ } else formattedLabel = magenta(node.label);
274
+ break;
275
+ }
276
+ default:
277
+ formattedLabel = node.label;
278
+ break;
279
+ }
280
+ if (isRoot) lines.push(formattedLabel);
281
+ else {
282
+ const treePrefix = `${prefix}${formatDimText(isLast ? "└" : "├")}─ `;
283
+ const isRootChild = prefix === "";
284
+ const prefixHasVerticalBar = stripAnsi(prefix).includes("│");
285
+ if (isRootChild) lines.push(`${treePrefix}${formattedLabel}`);
286
+ else if (prefixHasVerticalBar) lines.push(`${treePrefix}${formattedLabel}`);
287
+ else lines.push(`${formatDimText("│")} ${treePrefix}${formattedLabel}`);
288
+ }
289
+ if (node.children && node.children.length > 0) {
290
+ const childPrefix = isRoot ? "" : isLast ? `${prefix} ` : `${prefix}${formatDimText("│")} `;
291
+ for (let i = 0; i < node.children.length; i++) {
292
+ const child = node.children[i];
293
+ if (!child) continue;
294
+ const childLines = renderSchemaTree(child, flags, {
295
+ isLast: i === node.children.length - 1,
296
+ prefix: childPrefix,
297
+ useColor,
298
+ formatDimText,
299
+ isRoot: false
300
+ });
301
+ lines.push(...childLines);
302
+ }
303
+ }
304
+ return lines;
305
+ }
306
+ /**
307
+ * Formats human-readable output for database introspection.
308
+ */
309
+ function formatIntrospectOutput(result, schemaView, flags) {
310
+ if (flags.quiet) return "";
311
+ const lines = [];
312
+ const prefix = createPrefix(flags);
313
+ const useColor = flags.color !== false;
314
+ const formatDimText = (text) => formatDim(useColor, text);
315
+ if (schemaView) {
316
+ const prefixedTreeLines = renderSchemaTree(schemaView.root, flags, {
317
+ isLast: true,
318
+ prefix: "",
319
+ useColor,
320
+ formatDimText,
321
+ isRoot: true
322
+ }).map((line) => `${prefix}${line}`);
323
+ lines.push(...prefixedTreeLines);
324
+ } else {
325
+ lines.push(`${prefix}✔ ${result.summary}`);
326
+ if (isVerbose(flags, 1)) {
327
+ lines.push(`${prefix} Target: ${result.target.familyId}/${result.target.id}`);
328
+ if (result.meta?.dbUrl) lines.push(`${prefix} Database: ${result.meta.dbUrl}`);
329
+ }
330
+ }
331
+ if (isVerbose(flags, 1)) lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
332
+ return lines.join("\n");
333
+ }
334
+ /**
335
+ * Renders a schema verification tree structure from SchemaVerificationNode.
336
+ * Similar to renderSchemaTree but for verification nodes with status-based colors and glyphs.
337
+ */
338
+ function renderSchemaVerificationTree(node, flags, options) {
339
+ const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
340
+ const lines = [];
341
+ let statusGlyph = "";
342
+ let statusColor = (text) => text;
343
+ if (useColor) switch (node.status) {
344
+ case "pass":
345
+ statusGlyph = "✔";
346
+ statusColor = green;
347
+ break;
348
+ case "warn":
349
+ statusGlyph = "⚠";
350
+ statusColor = (text) => useColor ? yellow(text) : text;
351
+ break;
352
+ case "fail":
353
+ statusGlyph = "✖";
354
+ statusColor = red;
355
+ break;
356
+ }
357
+ else switch (node.status) {
358
+ case "pass":
359
+ statusGlyph = "✔";
360
+ break;
361
+ case "warn":
362
+ statusGlyph = "⚠";
363
+ break;
364
+ case "fail":
365
+ statusGlyph = "✖";
366
+ break;
367
+ }
368
+ let labelColor = (text) => text;
369
+ let formattedLabel = node.name;
370
+ if (useColor) switch (node.kind) {
371
+ case "contract":
372
+ case "schema":
373
+ labelColor = bold;
374
+ formattedLabel = labelColor(node.name);
375
+ break;
376
+ case "table": {
377
+ const tableMatch = node.name.match(/^table\s+(.+)$/);
378
+ if (tableMatch?.[1]) {
379
+ const tableName = tableMatch[1];
380
+ formattedLabel = `${dim("table")} ${cyan(tableName)}`;
381
+ } else formattedLabel = dim(node.name);
382
+ break;
383
+ }
384
+ case "columns":
385
+ labelColor = dim;
386
+ formattedLabel = labelColor(node.name);
387
+ break;
388
+ case "column": {
389
+ const columnMatch = node.name.match(/^([^:]+):\s*(.+)$/);
390
+ if (columnMatch?.[1] && columnMatch[2]) {
391
+ const columnName = columnMatch[1];
392
+ const rest = columnMatch[2];
393
+ const typeMatch = rest.match(/^([^\s→]+)\s*→\s*([^\s(]+)\s*(\([^)]+\))$/);
394
+ if (typeMatch?.[1] && typeMatch[2] && typeMatch[3]) {
395
+ const contractType = typeMatch[1];
396
+ const nativeType = typeMatch[2];
397
+ const nullability = typeMatch[3];
398
+ formattedLabel = `${cyan(columnName)}: ${contractType} → ${dim(nativeType)} ${dim(nullability)}`;
399
+ } else formattedLabel = `${cyan(columnName)}: ${rest}`;
400
+ } else formattedLabel = node.name;
401
+ break;
402
+ }
403
+ case "type":
404
+ case "nullability":
405
+ labelColor = (text) => text;
406
+ formattedLabel = labelColor(node.name);
407
+ break;
408
+ case "primaryKey": {
409
+ const pkMatch = node.name.match(/^primary key:\s*(.+)$/);
410
+ if (pkMatch?.[1]) {
411
+ const columnNames = pkMatch[1];
412
+ formattedLabel = `${dim("primary key")}: ${cyan(columnNames)}`;
413
+ } else formattedLabel = dim(node.name);
414
+ break;
415
+ }
416
+ case "foreignKey":
417
+ case "unique":
418
+ case "index":
419
+ labelColor = dim;
420
+ formattedLabel = labelColor(node.name);
421
+ break;
422
+ case "extension": {
423
+ const dbMatch = node.name.match(/^database is\s+(.+)$/);
424
+ if (dbMatch?.[1]) {
425
+ const dbName = dbMatch[1];
426
+ formattedLabel = `${dim("database is")} ${cyan(dbName)}`;
427
+ } else {
428
+ const extMatch = node.name.match(/^([^\s]+)\s+(extension is enabled)$/);
429
+ if (extMatch?.[1] && extMatch[2]) {
430
+ const extName = extMatch[1];
431
+ const rest = extMatch[2];
432
+ formattedLabel = `${cyan(extName)} ${dim(rest)}`;
433
+ } else {
434
+ labelColor = magenta;
435
+ formattedLabel = labelColor(node.name);
436
+ }
437
+ }
438
+ break;
439
+ }
440
+ default:
441
+ formattedLabel = node.name;
442
+ break;
443
+ }
444
+ else formattedLabel = node.name;
445
+ const statusGlyphColored = statusColor(statusGlyph);
446
+ let nodeLabel = formattedLabel;
447
+ if ((node.status === "fail" || node.status === "warn") && node.message && node.message.length > 0) {
448
+ const messageText = formatDimText(`(${node.message})`);
449
+ nodeLabel = `${formattedLabel} ${messageText}`;
450
+ }
451
+ if (isRoot) lines.push(`${statusGlyphColored} ${nodeLabel}`);
452
+ else {
453
+ const treePrefix = `${prefix}${formatDimText(isLast ? "└" : "├")}─ `;
454
+ const isRootChild = prefix === "";
455
+ const prefixHasVerticalBar = stripAnsi(prefix).includes("│");
456
+ if (isRootChild) lines.push(`${treePrefix}${statusGlyphColored} ${nodeLabel}`);
457
+ else if (prefixHasVerticalBar) lines.push(`${treePrefix}${statusGlyphColored} ${nodeLabel}`);
458
+ else lines.push(`${formatDimText("│")} ${treePrefix}${statusGlyphColored} ${nodeLabel}`);
459
+ }
460
+ if (node.children && node.children.length > 0) {
461
+ const childPrefix = isRoot ? "" : isLast ? `${prefix} ` : `${prefix}${formatDimText("│")} `;
462
+ for (let i = 0; i < node.children.length; i++) {
463
+ const child = node.children[i];
464
+ if (!child) continue;
465
+ const childLines = renderSchemaVerificationTree(child, flags, {
466
+ isLast: i === node.children.length - 1,
467
+ prefix: childPrefix,
468
+ useColor,
469
+ formatDimText,
470
+ isRoot: false
471
+ });
472
+ lines.push(...childLines);
473
+ }
474
+ }
475
+ return lines;
476
+ }
477
+ /**
478
+ * Formats human-readable output for database schema verification.
479
+ */
480
+ function formatSchemaVerifyOutput(result, flags) {
481
+ if (flags.quiet) return "";
482
+ const lines = [];
483
+ const prefix = createPrefix(flags);
484
+ const useColor = flags.color !== false;
485
+ const formatGreen = createColorFormatter(useColor, green);
486
+ const formatRed = createColorFormatter(useColor, red);
487
+ const formatDimText = (text) => formatDim(useColor, text);
488
+ const prefixedTreeLines = renderSchemaVerificationTree(result.schema.root, flags, {
489
+ isLast: true,
490
+ prefix: "",
491
+ useColor,
492
+ formatDimText,
493
+ isRoot: true
494
+ }).map((line) => `${prefix}${line}`);
495
+ lines.push(...prefixedTreeLines);
496
+ if (isVerbose(flags, 1)) {
497
+ lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
498
+ lines.push(`${prefix}${formatDimText(` pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`);
499
+ }
500
+ lines.push("");
501
+ if (result.ok) lines.push(`${prefix}${formatGreen("✔")} ${result.summary}`);
502
+ else {
503
+ const codeText = result.code ? ` (${result.code})` : "";
504
+ lines.push(`${prefix}${formatRed("✖")} ${result.summary}${codeText}`);
505
+ }
506
+ return lines.join("\n");
507
+ }
508
+ /**
509
+ * Formats JSON output for database schema verification.
510
+ */
511
+ function formatSchemaVerifyJson(result) {
512
+ return JSON.stringify(result, null, 2);
513
+ }
514
+ /**
515
+ * Formats human-readable output for database sign.
516
+ */
517
+ function formatSignOutput(result, flags) {
518
+ if (flags.quiet) return "";
519
+ const lines = [];
520
+ const prefix = createPrefix(flags);
521
+ const useColor = flags.color !== false;
522
+ const formatGreen = createColorFormatter(useColor, green);
523
+ const formatDimText = (text) => formatDim(useColor, text);
524
+ if (result.ok) {
525
+ lines.push(`${prefix}${formatGreen("✔")} Database signed`);
526
+ const previousHash = result.marker.previous?.storageHash ?? "none";
527
+ const currentHash = result.contract.storageHash;
528
+ lines.push(`${prefix}${formatDimText(` from: ${previousHash}`)}`);
529
+ lines.push(`${prefix}${formatDimText(` to: ${currentHash}`)}`);
530
+ if (isVerbose(flags, 1)) {
531
+ if (result.contract.profileHash) lines.push(`${prefix}${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
532
+ if (result.marker.previous?.profileHash) lines.push(`${prefix}${formatDimText(` previous profileHash: ${result.marker.previous.profileHash}`)}`);
533
+ lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
534
+ }
535
+ }
536
+ return lines.join("\n");
537
+ }
538
+ /**
539
+ * Formats JSON output for database sign.
540
+ */
541
+ function formatSignJson(result) {
542
+ return JSON.stringify(result, null, 2);
543
+ }
544
+ /**
545
+ * Formats human-readable output for db init plan mode.
546
+ */
547
+ function formatDbInitPlanOutput(result, flags) {
548
+ if (flags.quiet) return "";
549
+ const lines = [];
550
+ const prefix = createPrefix(flags);
551
+ const useColor = flags.color !== false;
552
+ const formatGreen = createColorFormatter(useColor, green);
553
+ const formatDimText = (text) => formatDim(useColor, text);
554
+ const operationCount = result.plan?.operations.length ?? 0;
555
+ lines.push(`${prefix}${formatGreen("✔")} Planned ${operationCount} operation(s)`);
556
+ if (result.plan?.operations && result.plan.operations.length > 0) {
557
+ lines.push(`${prefix}${formatDimText("│")}`);
558
+ for (let i = 0; i < result.plan.operations.length; i++) {
559
+ const op = result.plan.operations[i];
560
+ if (!op) continue;
561
+ const treeChar = i === result.plan.operations.length - 1 ? "└" : "├";
562
+ const opClass = formatDimText(`[${op.operationClass}]`);
563
+ lines.push(`${prefix}${formatDimText(treeChar)}─ ${op.label} ${opClass}`);
564
+ }
565
+ }
566
+ if (result.plan?.destination) {
567
+ lines.push(`${prefix}`);
568
+ lines.push(`${prefix}${formatDimText(`Destination hash: ${result.plan.destination.storageHash}`)}`);
569
+ }
570
+ if (isVerbose(flags, 1)) lines.push(`${prefix}${formatDimText(`Total time: ${result.timings.total}ms`)}`);
571
+ lines.push(`${prefix}`);
572
+ lines.push(`${prefix}${formatDimText("This is a dry run. No changes were applied.")}`);
573
+ lines.push(`${prefix}${formatDimText("Run without --plan to apply changes.")}`);
574
+ return lines.join("\n");
575
+ }
576
+ /**
577
+ * Formats human-readable output for db init apply mode.
578
+ */
579
+ function formatDbInitApplyOutput(result, flags) {
580
+ if (flags.quiet) return "";
581
+ const lines = [];
582
+ const prefix = createPrefix(flags);
583
+ const useColor = flags.color !== false;
584
+ const formatGreen = createColorFormatter(useColor, green);
585
+ const formatDimText = (text) => formatDim(useColor, text);
586
+ if (result.ok) {
587
+ const executed = result.execution?.operationsExecuted ?? 0;
588
+ lines.push(`${prefix}${formatGreen("✔")} Applied ${executed} operation(s)`);
589
+ if (result.marker) {
590
+ lines.push(`${prefix}${formatDimText(` Marker written: ${result.marker.storageHash}`)}`);
591
+ if (result.marker.profileHash) lines.push(`${prefix}${formatDimText(` Profile hash: ${result.marker.profileHash}`)}`);
592
+ }
593
+ if (isVerbose(flags, 1)) lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
594
+ }
595
+ return lines.join("\n");
596
+ }
597
+ /**
598
+ * Formats JSON output for db init command.
599
+ */
600
+ function formatDbInitJson(result) {
601
+ return JSON.stringify(result, null, 2);
602
+ }
603
+ /**
604
+ * Fixed width for left column in help output.
605
+ */
606
+ const LEFT_COLUMN_WIDTH = 20;
607
+ /**
608
+ * Minimum width for right column wrapping in help output.
609
+ */
610
+ const RIGHT_COLUMN_MIN_WIDTH = 40;
611
+ /**
612
+ * Maximum width for right column wrapping in help output (when terminal is wide enough).
613
+ */
614
+ const RIGHT_COLUMN_MAX_WIDTH = 90;
615
+ /**
616
+ * Gets the terminal width, or returns a default if not available.
617
+ */
618
+ function getTerminalWidth() {
619
+ const terminalWidth = process.stdout.columns;
620
+ const defaultWidth = Number.parseInt(process.env["CLI_WIDTH"] || "80", 10);
621
+ return terminalWidth || defaultWidth;
622
+ }
623
+ /**
624
+ * Calculates the available width for the right column based on terminal width.
625
+ * Format: "│ " (2) + left column (20) + " " (2) + right column = total
626
+ * So: right column = terminal width - 2 - 20 - 2 = terminal width - 24
627
+ */
628
+ function calculateRightColumnWidth() {
629
+ const availableWidth = getTerminalWidth() - 2 - LEFT_COLUMN_WIDTH - 2;
630
+ return Math.max(RIGHT_COLUMN_MIN_WIDTH, Math.min(availableWidth, RIGHT_COLUMN_MAX_WIDTH));
631
+ }
632
+ /**
633
+ * Creates an arrow segment badge with green background and white text.
634
+ * Body: green background with white "prisma-next" text
635
+ * Tip: dark grey arrow pointing right (Powerline separator)
636
+ */
637
+ function createPrismaNextBadge(useColor) {
638
+ if (!useColor) return "prisma-next";
639
+ return `${bgGreen(bold(" prisma-next "))}${green("")}`;
640
+ }
641
+ /**
642
+ * Creates a padding function.
643
+ */
644
+ function createPadFunction() {
645
+ return (s, w) => s + " ".repeat(Math.max(0, w - s.length));
646
+ }
647
+ /**
648
+ * Formats a header line: brand + operation + intent
649
+ */
650
+ function formatHeaderLine(options) {
651
+ if (options.operation) return `${options.brand} ${options.operation} → ${options.intent}`;
652
+ return `${options.brand} ${options.intent}`;
653
+ }
654
+ /**
655
+ * Formats a "Read more" URL line.
656
+ * The "Read more" label is in default color (not cyan), and the URL is blue.
657
+ */
658
+ function formatReadMoreLine(options) {
659
+ const labelPadded = createPadFunction()("Read more", options.maxLabelWidth);
660
+ const valueColored = options.useColor ? blue(options.url) : options.url;
661
+ return `${options.formatDimText("│")} ${labelPadded} ${valueColored}`;
662
+ }
663
+ /**
664
+ * Pads text to a fixed width, accounting for ANSI escape codes.
665
+ * Uses string-width to measure the actual display width.
666
+ */
667
+ function padToFixedWidth(text, width) {
668
+ const actualWidth = stringWidth(text);
669
+ const padding = Math.max(0, width - actualWidth);
670
+ return text + " ".repeat(padding);
671
+ }
672
+ /**
673
+ * Wraps text to fit within a specified width using wrap-ansi.
674
+ * Preserves ANSI escape codes and breaks at word boundaries.
675
+ */
676
+ function wrapTextAnsi(text, width) {
677
+ return wrapAnsi(text, width, {
678
+ hard: false,
679
+ trim: true
680
+ }).split("\n");
681
+ }
682
+ /**
683
+ * Formats a default value as "default: <value>" with dimming.
684
+ */
685
+ function formatDefaultValue(value, useColor) {
686
+ const defaultText = `default: ${String(value)}`;
687
+ return useColor ? dim(defaultText) : defaultText;
688
+ }
689
+ /**
690
+ * Renders a command tree structure.
691
+ * Handles both single-level (subcommands of a command) and multi-level (top-level commands with subcommands) trees.
692
+ */
693
+ function renderCommandTree(options) {
694
+ const { commands, useColor, formatDimText, hasItemsAfter, continuationPrefix } = options;
695
+ const lines = [];
696
+ if (commands.length === 0) return lines;
697
+ for (let i = 0; i < commands.length; i++) {
698
+ const cmd = commands[i];
699
+ if (!cmd) continue;
700
+ const subcommands = cmd.commands.filter((subcmd) => !subcmd.name().startsWith("_"));
701
+ const isLastCommand = i === commands.length - 1;
702
+ if (subcommands.length > 0) {
703
+ const treePrefix = `${isLastCommand && !hasItemsAfter ? formatDimText("└") : formatDimText("├")}─ `;
704
+ const remainingWidth = LEFT_COLUMN_WIDTH - stringWidth(stripAnsi(treePrefix));
705
+ const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
706
+ const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
707
+ lines.push(`${formatDimText("│")} ${treePrefix}${commandNameColored}`);
708
+ for (let j = 0; j < subcommands.length; j++) {
709
+ const subcmd = subcommands[j];
710
+ if (!subcmd) continue;
711
+ const isLastSubcommand = j === subcommands.length - 1;
712
+ const shortDescription = subcmd.description() || "";
713
+ const treeChar = isLastSubcommand ? "└" : "├";
714
+ const continuation = continuationPrefix ?? (isLastCommand && isLastSubcommand && !hasItemsAfter ? " " : formatDimText("│"));
715
+ const subTreePrefix = `${continuation === " " ? " " : continuation} ${formatDimText(treeChar)}─ `;
716
+ const subRemainingWidth = LEFT_COLUMN_WIDTH - stringWidth(stripAnsi(subTreePrefix));
717
+ const subcommandNamePadded = padToFixedWidth(subcmd.name(), subRemainingWidth);
718
+ const subcommandNameColored = useColor ? cyan(subcommandNamePadded) : subcommandNamePadded;
719
+ lines.push(`${formatDimText("│")} ${subTreePrefix}${subcommandNameColored} ${shortDescription}`);
720
+ }
721
+ } else {
722
+ const treePrefix = `${isLastCommand && !hasItemsAfter ? formatDimText("└") : formatDimText("├")}─ `;
723
+ const remainingWidth = LEFT_COLUMN_WIDTH - stringWidth(stripAnsi(treePrefix));
724
+ const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
725
+ const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
726
+ const shortDescription = cmd.description() || "";
727
+ lines.push(`${formatDimText("│")} ${treePrefix}${commandNameColored} ${shortDescription}`);
728
+ }
729
+ }
730
+ return lines;
731
+ }
732
+ /**
733
+ * Formats multiline description with "Prisma Next" in green.
734
+ * Wraps at the same right-hand boundary as the right column.
735
+ * The right edge is defined by: left column (20) + gap (2) + right column (90) = 112 characters total.
736
+ * Since the description line starts with "│ " (2 chars), the text wraps at 112 - 2 = 110 characters.
737
+ */
738
+ function formatMultilineDescription(options) {
739
+ const lines = [];
740
+ const formatGreen = (text) => options.useColor ? green(text) : text;
741
+ const rightColumnWidth = calculateRightColumnWidth();
742
+ const wrapWidth = 2 + LEFT_COLUMN_WIDTH + 2 + rightColumnWidth - 2;
743
+ for (const descLine of options.descriptionLines) {
744
+ const wrappedLines = wrapTextAnsi(descLine.replace(/Prisma Next/g, (match) => formatGreen(match)), wrapWidth);
745
+ for (const wrappedLine of wrappedLines) lines.push(`${options.formatDimText("│")} ${wrappedLine}`);
746
+ }
747
+ return lines;
748
+ }
749
+ /**
750
+ * Formats the header in the new experimental visual style.
751
+ * This header appears at the start of command output, showing the operation,
752
+ * intent, documentation link, and parameters.
753
+ */
754
+ function formatStyledHeader(options) {
755
+ const lines = [];
756
+ const useColor = options.flags.color !== false;
757
+ const formatDimText = (text) => formatDim(useColor, text);
758
+ const brand = createPrismaNextBadge(useColor);
759
+ const operation = useColor ? bold(options.command) : options.command;
760
+ const intent = formatDimText(options.description);
761
+ lines.push(formatHeaderLine({
762
+ brand,
763
+ operation,
764
+ intent
765
+ }));
766
+ lines.push(formatDimText("│"));
767
+ for (const detail of options.details) {
768
+ const labelPadded = padToFixedWidth(`${detail.label}:`, LEFT_COLUMN_WIDTH);
769
+ const labelColored = useColor ? cyan(labelPadded) : labelPadded;
770
+ lines.push(`${formatDimText("│")} ${labelColored} ${detail.value}`);
771
+ }
772
+ if (options.url) {
773
+ lines.push(formatDimText("│"));
774
+ lines.push(formatReadMoreLine({
775
+ url: options.url,
776
+ maxLabelWidth: LEFT_COLUMN_WIDTH,
777
+ useColor,
778
+ formatDimText
779
+ }));
780
+ }
781
+ lines.push(formatDimText("└"));
782
+ return `${lines.join("\n")}\n`;
783
+ }
784
+ /**
785
+ * Formats a success message in the styled output format.
786
+ */
787
+ function formatSuccessMessage(flags) {
788
+ return `${createColorFormatter(flags.color !== false, green)("✔")} Success`;
789
+ }
790
+ /**
791
+ * Maps command paths to their documentation URLs.
792
+ */
793
+ function getCommandDocsUrl(commandPath) {
794
+ return {
795
+ "contract emit": "https://pris.ly/contract-emit",
796
+ "db verify": "https://pris.ly/db-verify"
797
+ }[commandPath];
798
+ }
799
+ /**
800
+ * Builds the full command path from a command and its parents.
801
+ */
802
+ function buildCommandPath(command) {
803
+ const parts = [];
804
+ let current = command;
805
+ while (current && current.name() !== "prisma-next") {
806
+ parts.unshift(current.name());
807
+ current = current.parent ?? void 0;
808
+ }
809
+ return parts.join(" ");
810
+ }
811
+ /**
812
+ * Formats help output for a command using the styled format.
813
+ */
814
+ function formatCommandHelp(options) {
815
+ const { command, flags } = options;
816
+ const lines = [];
817
+ const useColor = flags.color !== false;
818
+ const formatDimText = (text) => formatDim(useColor, text);
819
+ const commandPath = buildCommandPath(command);
820
+ const shortDescription = command.description() || "";
821
+ const longDescription = getLongDescription(command);
822
+ const brand = createPrismaNextBadge(useColor);
823
+ const operation = useColor ? bold(commandPath) : commandPath;
824
+ const intent = formatDimText(shortDescription);
825
+ lines.push(formatHeaderLine({
826
+ brand,
827
+ operation,
828
+ intent
829
+ }));
830
+ lines.push(formatDimText("│"));
831
+ const optionsList = command.options.map((opt) => {
832
+ return {
833
+ flags: opt.flags,
834
+ description: opt.description || "",
835
+ defaultValue: opt.defaultValue
836
+ };
837
+ });
838
+ const subcommands = command.commands.filter((cmd) => !cmd.name().startsWith("_"));
839
+ if (subcommands.length > 0) {
840
+ const treeLines = renderCommandTree({
841
+ commands: subcommands,
842
+ useColor,
843
+ formatDimText,
844
+ hasItemsAfter: optionsList.length > 0
845
+ });
846
+ lines.push(...treeLines);
847
+ }
848
+ if (subcommands.length > 0 && optionsList.length > 0) lines.push(formatDimText("│"));
849
+ if (optionsList.length > 0) for (const opt of optionsList) {
850
+ const flagsPadded = padToFixedWidth(opt.flags, LEFT_COLUMN_WIDTH);
851
+ let flagsColored = flagsPadded;
852
+ if (useColor) {
853
+ flagsColored = flagsPadded.replace(/(<[^>]+>)/g, (match) => magenta(match));
854
+ flagsColored = cyan(flagsColored);
855
+ }
856
+ const rightColumnWidth = calculateRightColumnWidth();
857
+ const wrappedDescription = wrapTextAnsi(opt.description, rightColumnWidth);
858
+ lines.push(`${formatDimText("│")} ${flagsColored} ${wrappedDescription[0] || ""}`);
859
+ for (let i = 1; i < wrappedDescription.length; i++) {
860
+ const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
861
+ lines.push(`${formatDimText("│")} ${emptyLabel} ${wrappedDescription[i] || ""}`);
862
+ }
863
+ if (opt.defaultValue !== void 0) {
864
+ const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
865
+ const defaultText = formatDefaultValue(opt.defaultValue, useColor);
866
+ lines.push(`${formatDimText("│")} ${emptyLabel} ${defaultText}`);
867
+ }
868
+ }
869
+ const docsUrl = getCommandDocsUrl(commandPath);
870
+ if (docsUrl) {
871
+ lines.push(formatDimText("│"));
872
+ lines.push(formatReadMoreLine({
873
+ url: docsUrl,
874
+ maxLabelWidth: LEFT_COLUMN_WIDTH,
875
+ useColor,
876
+ formatDimText
877
+ }));
878
+ }
879
+ if (longDescription) {
880
+ lines.push(formatDimText("│"));
881
+ const descriptionLines = longDescription.split("\n").filter((line) => line.trim().length > 0);
882
+ lines.push(...formatMultilineDescription({
883
+ descriptionLines,
884
+ useColor,
885
+ formatDimText
886
+ }));
887
+ }
888
+ lines.push(formatDimText("└"));
889
+ return `${lines.join("\n")}\n`;
890
+ }
891
+ /**
892
+ * Formats help output for the root program using the styled format.
893
+ */
894
+ function formatRootHelp(options) {
895
+ const { program, flags } = options;
896
+ const lines = [];
897
+ const useColor = flags.color !== false;
898
+ const formatDimText = (text) => formatDim(useColor, text);
899
+ const brand = createPrismaNextBadge(useColor);
900
+ const intent = formatDimText("Manage your data layer");
901
+ lines.push(formatHeaderLine({
902
+ brand,
903
+ operation: "",
904
+ intent
905
+ }));
906
+ lines.push(formatDimText("│"));
907
+ const topLevelCommands = program.commands.filter((cmd) => !cmd.name().startsWith("_") && cmd.name() !== "help");
908
+ const globalOptions = program.options.map((opt) => {
909
+ return {
910
+ flags: opt.flags,
911
+ description: opt.description || "",
912
+ defaultValue: opt.defaultValue
913
+ };
914
+ });
915
+ if (topLevelCommands.length > 0) {
916
+ const treeLines = renderCommandTree({
917
+ commands: topLevelCommands,
918
+ useColor,
919
+ formatDimText,
920
+ hasItemsAfter: globalOptions.length > 0
921
+ });
922
+ lines.push(...treeLines);
923
+ }
924
+ if (topLevelCommands.length > 0 && globalOptions.length > 0) lines.push(formatDimText("│"));
925
+ if (globalOptions.length > 0) for (const opt of globalOptions) {
926
+ const flagsPadded = padToFixedWidth(opt.flags, LEFT_COLUMN_WIDTH);
927
+ let flagsColored = flagsPadded;
928
+ if (useColor) {
929
+ flagsColored = flagsPadded.replace(/(<[^>]+>)/g, (match) => magenta(match));
930
+ flagsColored = cyan(flagsColored);
931
+ }
932
+ const rightColumnWidth = calculateRightColumnWidth();
933
+ const wrappedDescription = wrapTextAnsi(opt.description, rightColumnWidth);
934
+ lines.push(`${formatDimText("│")} ${flagsColored} ${wrappedDescription[0] || ""}`);
935
+ for (let i = 1; i < wrappedDescription.length; i++) {
936
+ const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
937
+ lines.push(`${formatDimText("│")} ${emptyLabel} ${wrappedDescription[i] || ""}`);
938
+ }
939
+ if (opt.defaultValue !== void 0) {
940
+ const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
941
+ const defaultText = formatDefaultValue(opt.defaultValue, useColor);
942
+ lines.push(`${formatDimText("│")} ${emptyLabel} ${defaultText}`);
943
+ }
944
+ }
945
+ const formatGreen = (text) => useColor ? green(text) : text;
946
+ const descriptionLines = [`Use ${formatGreen("Prisma Next")} to define your data layer as a contract. Sign your database and application with the same contract to guarantee compatibility. Plan and apply migrations to safely evolve your schema.`];
947
+ if (descriptionLines.length > 0) {
948
+ lines.push(formatDimText("│"));
949
+ lines.push(...formatMultilineDescription({
950
+ descriptionLines,
951
+ useColor,
952
+ formatDimText
953
+ }));
954
+ }
955
+ lines.push(formatDimText("└"));
956
+ return `${lines.join("\n")}\n`;
957
+ }
958
+
959
+ //#endregion
960
+ //#region src/utils/progress-adapter.ts
961
+ /**
962
+ * Creates a progress adapter that converts control-api progress events
963
+ * into CLI spinner/progress output.
964
+ *
965
+ * The adapter:
966
+ * - Starts/succeeds spinners for top-level span boundaries
967
+ * - Prints per-operation lines for nested spans (e.g., migration operations under 'apply')
968
+ * - Respects quiet/json/non-TTY flags (no-op in those cases)
969
+ *
970
+ * @param options - Progress adapter configuration
971
+ * @returns An onProgress callback compatible with control-api operations
972
+ */
973
+ function createProgressAdapter(options) {
974
+ const { flags } = options;
975
+ if (!(!flags.quiet && flags.json !== "object" && process.stdout.isTTY)) return () => {};
976
+ const activeSpans = /* @__PURE__ */ new Map();
977
+ return (event) => {
978
+ if (event.kind === "spanStart") {
979
+ if (event.parentSpanId) {
980
+ console.log(` → ${event.label}...`);
981
+ return;
982
+ }
983
+ const spinner = ora({
984
+ text: event.label,
985
+ color: flags.color !== false ? "cyan" : false
986
+ }).start();
987
+ activeSpans.set(event.spanId, {
988
+ spinner,
989
+ startTime: Date.now()
990
+ });
991
+ } else if (event.kind === "spanEnd") {
992
+ const spanState = activeSpans.get(event.spanId);
993
+ if (spanState) {
994
+ const elapsed = Date.now() - spanState.startTime;
995
+ if (event.outcome === "error") spanState.spinner.fail(`${spanState.spinner.text} (failed)`);
996
+ else if (event.outcome === "skipped") spanState.spinner.info(`${spanState.spinner.text} (skipped)`);
997
+ else spanState.spinner.succeed(`${spanState.spinner.text} (${elapsed}ms)`);
998
+ activeSpans.delete(event.spanId);
999
+ }
1000
+ }
1001
+ };
1002
+ }
1003
+
1004
+ //#endregion
1005
+ //#region src/utils/result-handler.ts
1006
+ /**
1007
+ * Processes a CLI command result, handling both success and error cases.
1008
+ * Formats output appropriately and returns the exit code.
1009
+ * Never throws - returns exit code for commands to use with process.exit().
1010
+ *
1011
+ * @param result - The result from a CLI command
1012
+ * @param flags - Global flags for output formatting
1013
+ * @param onSuccess - Optional callback for successful results (for custom success output)
1014
+ * @returns The exit code that should be used (0 for success, non-zero for errors)
1015
+ */
1016
+ function handleResult(result, flags, onSuccess) {
1017
+ if (result.ok) {
1018
+ if (onSuccess) onSuccess(result.value);
1019
+ return 0;
1020
+ }
1021
+ const envelope = result.failure.toEnvelope();
1022
+ if (flags.json) console.error(formatErrorJson(envelope));
1023
+ else console.error(formatErrorOutput(envelope, flags));
1024
+ return result.failure.domain === "CLI" ? 2 : 1;
1025
+ }
1026
+
1027
+ //#endregion
1028
+ export { formatSuccessMessage as _, formatDbInitJson as a, parseGlobalFlags as b, formatEmitOutput as c, formatRootHelp as d, formatSchemaVerifyJson as f, formatStyledHeader as g, formatSignOutput as h, formatDbInitApplyOutput as i, formatIntrospectJson as l, formatSignJson as m, createProgressAdapter as n, formatDbInitPlanOutput as o, formatSchemaVerifyOutput as p, formatCommandHelp as r, formatEmitJson as s, handleResult as t, formatIntrospectOutput as u, formatVerifyJson as v, setCommandDescriptions as x, formatVerifyOutput as y };
1029
+ //# sourceMappingURL=result-handler-BZPY7HX4.mjs.map