@prisma-next/cli 0.12.0 → 0.13.0-dev.10

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 (213) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.mjs +180 -163
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/{client-KgJorIvG.mjs → client-CJzuo5wX.mjs} +222 -107
  5. package/dist/client-CJzuo5wX.mjs.map +1 -0
  6. package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-DGMvGBeX.mjs} +318 -25
  7. package/dist/command-helpers-DGMvGBeX.mjs.map +1 -0
  8. package/dist/commands/contract-emit.d.mts.map +1 -1
  9. package/dist/commands/contract-emit.mjs +1 -1
  10. package/dist/commands/contract-infer.d.mts.map +1 -1
  11. package/dist/commands/contract-infer.mjs +1 -1
  12. package/dist/commands/db-init.d.mts.map +1 -1
  13. package/dist/commands/db-init.mjs +4 -5
  14. package/dist/commands/db-init.mjs.map +1 -1
  15. package/dist/commands/db-schema.d.mts.map +1 -1
  16. package/dist/commands/db-schema.mjs +3 -3
  17. package/dist/commands/db-schema.mjs.map +1 -1
  18. package/dist/commands/db-sign.d.mts.map +1 -1
  19. package/dist/commands/db-sign.mjs +6 -6
  20. package/dist/commands/db-sign.mjs.map +1 -1
  21. package/dist/commands/db-update.d.mts.map +1 -1
  22. package/dist/commands/db-update.mjs +10 -7
  23. package/dist/commands/db-update.mjs.map +1 -1
  24. package/dist/commands/db-verify.d.mts.map +1 -1
  25. package/dist/commands/db-verify.mjs +1 -1
  26. package/dist/commands/migrate.d.mts +37 -3
  27. package/dist/commands/migrate.d.mts.map +1 -1
  28. package/dist/commands/migrate.mjs +298 -12
  29. package/dist/commands/migrate.mjs.map +1 -1
  30. package/dist/commands/migration-check.d.mts +55 -13
  31. package/dist/commands/migration-check.d.mts.map +1 -1
  32. package/dist/commands/migration-check.mjs +3 -2
  33. package/dist/commands/migration-graph.d.mts +17 -8
  34. package/dist/commands/migration-graph.d.mts.map +1 -1
  35. package/dist/commands/migration-graph.mjs +185 -2
  36. package/dist/commands/migration-graph.mjs.map +1 -0
  37. package/dist/commands/migration-list.d.mts +26 -27
  38. package/dist/commands/migration-list.d.mts.map +1 -1
  39. package/dist/commands/migration-list.mjs +2 -190
  40. package/dist/commands/migration-log.d.mts +9 -19
  41. package/dist/commands/migration-log.d.mts.map +1 -1
  42. package/dist/commands/migration-log.mjs +1 -137
  43. package/dist/commands/migration-new.d.mts.map +1 -1
  44. package/dist/commands/migration-new.mjs +6 -5
  45. package/dist/commands/migration-new.mjs.map +1 -1
  46. package/dist/commands/migration-plan.d.mts +1 -1
  47. package/dist/commands/migration-plan.d.mts.map +1 -1
  48. package/dist/commands/migration-plan.mjs +1 -1
  49. package/dist/commands/migration-show.d.mts +17 -21
  50. package/dist/commands/migration-show.d.mts.map +1 -1
  51. package/dist/commands/migration-show.mjs +24 -36
  52. package/dist/commands/migration-show.mjs.map +1 -1
  53. package/dist/commands/migration-status.d.mts +42 -144
  54. package/dist/commands/migration-status.d.mts.map +1 -1
  55. package/dist/commands/migration-status.mjs +3 -759
  56. package/dist/commands/ref.d.mts +1 -1
  57. package/dist/commands/ref.d.mts.map +1 -1
  58. package/dist/commands/ref.mjs +4 -4
  59. package/dist/commands/ref.mjs.map +1 -1
  60. package/dist/commands/telemetry/index.d.mts +7 -0
  61. package/dist/commands/telemetry/index.d.mts.map +1 -0
  62. package/dist/commands/telemetry/index.mjs +2 -0
  63. package/dist/{config-loader-B6sJjXTv.mjs → config-loader-p9JMrekQ.mjs} +1 -1
  64. package/dist/{config-loader-B6sJjXTv.mjs.map → config-loader-p9JMrekQ.mjs.map} +1 -1
  65. package/dist/config-loader.mjs +1 -1
  66. package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-CFXsstzm.mjs} +2 -2
  67. package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-CFXsstzm.mjs.map} +1 -1
  68. package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-B_qriF8B.mjs} +5 -5
  69. package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-B_qriF8B.mjs.map} +1 -1
  70. package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-C8HmtboH.mjs} +12 -7
  71. package/dist/contract-emit-C8HmtboH.mjs.map +1 -0
  72. package/dist/{contract-enrichment-a0V5Y_mL.mjs → contract-enrichment-gn9sWbPw.mjs} +1 -1
  73. package/dist/{contract-enrichment-a0V5Y_mL.mjs.map → contract-enrichment-gn9sWbPw.mjs.map} +1 -1
  74. package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-BYT_ra_U.mjs} +5 -5
  75. package/dist/contract-infer-BYT_ra_U.mjs.map +1 -0
  76. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-ClI1KN6d.mjs} +5 -5
  77. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-ClI1KN6d.mjs.map} +1 -1
  78. package/dist/{db-verify-v_vUKXTU.mjs → db-verify-C24FKhb7.mjs} +6 -6
  79. package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-C24FKhb7.mjs.map} +1 -1
  80. package/dist/exports/control-api.d.mts +5 -3
  81. package/dist/exports/control-api.d.mts.map +1 -1
  82. package/dist/exports/control-api.mjs +3 -3
  83. package/dist/exports/index.mjs +1 -1
  84. package/dist/exports/index.mjs.map +1 -1
  85. package/dist/exports/init-output.d.mts +1 -3
  86. package/dist/exports/init-output.d.mts.map +1 -1
  87. package/dist/exports/init-output.mjs +1 -1
  88. package/dist/{extension-pack-inputs-IDvjRCi3.mjs → extension-pack-inputs-1ySHqxKG.mjs} +1 -1
  89. package/dist/{extension-pack-inputs-IDvjRCi3.mjs.map → extension-pack-inputs-1ySHqxKG.mjs.map} +1 -1
  90. package/dist/{framework-components-fYXjz_in.mjs → framework-components-YVQHhPH7.mjs} +2 -2
  91. package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-YVQHhPH7.mjs.map} +1 -1
  92. package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-BpoOYtNZ.d.mts} +1 -1
  93. package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-BpoOYtNZ.d.mts.map} +1 -1
  94. package/dist/{init-Cv9UzWL5.mjs → init-0HwB-Vh8.mjs} +5 -58
  95. package/dist/init-0HwB-Vh8.mjs.map +1 -0
  96. package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-DF6IwcDl.mjs} +7 -5
  97. package/dist/inspect-live-schema-DF6IwcDl.mjs.map +1 -0
  98. package/dist/migration-check-soB5uZEQ.mjs +573 -0
  99. package/dist/migration-check-soB5uZEQ.mjs.map +1 -0
  100. package/dist/migration-cli.mjs +1 -1
  101. package/dist/migration-cli.mjs.map +1 -1
  102. package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-DA-Lhx6o.mjs} +5 -5
  103. package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-DA-Lhx6o.mjs.map} +1 -1
  104. package/dist/migration-graph-command-render-CEez7YUK.mjs +1960 -0
  105. package/dist/migration-graph-command-render-CEez7YUK.mjs.map +1 -0
  106. package/dist/migration-list-DlJJ_38Z.mjs +230 -0
  107. package/dist/migration-list-DlJJ_38Z.mjs.map +1 -0
  108. package/dist/migration-log-CG0qQAFm.mjs +222 -0
  109. package/dist/migration-log-CG0qQAFm.mjs.map +1 -0
  110. package/dist/migration-path-target-Ce6OZImp.mjs +38 -0
  111. package/dist/migration-path-target-Ce6OZImp.mjs.map +1 -0
  112. package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-z5Ing-TD.mjs} +9 -8
  113. package/dist/migration-plan-z5Ing-TD.mjs.map +1 -0
  114. package/dist/migration-status-CgWSoI_g.mjs +446 -0
  115. package/dist/migration-status-CgWSoI_g.mjs.map +1 -0
  116. package/dist/{output-B60Gw5fu.mjs → output-mEQ74_nd.mjs} +1 -1
  117. package/dist/{output-B60Gw5fu.mjs.map → output-mEQ74_nd.mjs.map} +1 -1
  118. package/dist/{progress-adapter-C644QK8l.mjs → progress-adapter-CjAeTxY_.mjs} +1 -1
  119. package/dist/{progress-adapter-C644QK8l.mjs.map → progress-adapter-CjAeTxY_.mjs.map} +1 -1
  120. package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-BkXlikCA.mjs} +1 -1
  121. package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-BkXlikCA.mjs.map} +1 -1
  122. package/dist/schemas-CeGMYFYX.d.mts +191 -0
  123. package/dist/schemas-CeGMYFYX.d.mts.map +1 -0
  124. package/dist/schemas-KhXMzNA_.mjs +112 -0
  125. package/dist/schemas-KhXMzNA_.mjs.map +1 -0
  126. package/dist/telemetry-BIM4beEO.mjs +122 -0
  127. package/dist/telemetry-BIM4beEO.mjs.map +1 -0
  128. package/dist/{terminal-ui-5Y6mrg93.d.mts → terminal-ui-DGRNFWna.d.mts} +1 -1
  129. package/dist/terminal-ui-DGRNFWna.d.mts.map +1 -0
  130. package/dist/{types-Dt_SfqFm.d.mts → types-C_tYiJYx.d.mts} +53 -31
  131. package/dist/types-C_tYiJYx.d.mts.map +1 -0
  132. package/dist/{verify-DCA9Sldu.mjs → verify-DcOYZ1tH.mjs} +2 -2
  133. package/dist/{verify-DCA9Sldu.mjs.map → verify-DcOYZ1tH.mjs.map} +1 -1
  134. package/package.json +26 -22
  135. package/src/cli.ts +5 -0
  136. package/src/commands/contract-infer.ts +2 -2
  137. package/src/commands/db-update.ts +7 -1
  138. package/src/commands/init/index.ts +6 -35
  139. package/src/commands/init/init.ts +1 -14
  140. package/src/commands/init/inputs.ts +0 -75
  141. package/src/commands/inspect-live-schema.ts +10 -0
  142. package/src/commands/json/schemas.ts +195 -0
  143. package/src/commands/migrate.ts +527 -8
  144. package/src/commands/migration-check.ts +469 -134
  145. package/src/commands/migration-graph.ts +164 -91
  146. package/src/commands/migration-list.ts +72 -39
  147. package/src/commands/migration-log.ts +52 -102
  148. package/src/commands/migration-new.ts +2 -1
  149. package/src/commands/migration-plan.ts +2 -1
  150. package/src/commands/migration-show.ts +31 -66
  151. package/src/commands/migration-status-overlay.ts +61 -0
  152. package/src/commands/migration-status.ts +458 -1066
  153. package/src/commands/telemetry/index.ts +107 -0
  154. package/src/commands/telemetry/status.ts +67 -0
  155. package/src/control-api/client.ts +70 -9
  156. package/src/control-api/operations/contract-emit.ts +22 -2
  157. package/src/control-api/operations/db-init.ts +6 -3
  158. package/src/control-api/operations/{db-apply.ts → db-run.ts} +55 -14
  159. package/src/control-api/operations/db-update.ts +7 -4
  160. package/src/control-api/operations/db-verify.ts +15 -5
  161. package/src/control-api/operations/{migration-apply.ts → migrate.ts} +181 -80
  162. package/src/control-api/operations/{apply.ts → run-migration.ts} +33 -27
  163. package/src/control-api/types.ts +56 -29
  164. package/src/utils/cli-errors.ts +70 -2
  165. package/src/utils/formatters/errors.ts +11 -0
  166. package/src/utils/formatters/migration-graph-command-render.ts +239 -0
  167. package/src/utils/formatters/migration-graph-grid-layout.ts +1134 -0
  168. package/src/utils/formatters/migration-graph-labels.ts +408 -0
  169. package/src/utils/formatters/migration-graph-model.ts +103 -0
  170. package/src/utils/formatters/migration-graph-occlusion-render.ts +258 -0
  171. package/src/utils/formatters/migration-graph-rows.ts +128 -15
  172. package/src/utils/formatters/migration-graph-space-render.ts +188 -0
  173. package/src/utils/formatters/migration-list-data-column.ts +4 -91
  174. package/src/utils/formatters/migration-list-graph-topology.ts +72 -94
  175. package/src/utils/formatters/migration-list-render.ts +135 -71
  176. package/src/utils/formatters/migration-list-styler.ts +46 -5
  177. package/src/utils/formatters/migration-list-types.ts +5 -21
  178. package/src/utils/formatters/migration-log-table.ts +205 -0
  179. package/src/utils/formatters/migrations.ts +33 -11
  180. package/src/utils/global-flags.ts +35 -0
  181. package/src/utils/integrity-violation-to-check-failure.ts +28 -19
  182. package/src/utils/legend.ts +38 -0
  183. package/src/utils/migration-path-target.ts +60 -0
  184. package/src/utils/telemetry.ts +68 -32
  185. package/dist/client-KgJorIvG.mjs.map +0 -1
  186. package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
  187. package/dist/commands/migration-list.mjs.map +0 -1
  188. package/dist/commands/migration-log.mjs.map +0 -1
  189. package/dist/commands/migration-status.mjs.map +0 -1
  190. package/dist/contract-emit-D-4jrNve.mjs.map +0 -1
  191. package/dist/contract-infer-D8uEbJuu.mjs.map +0 -1
  192. package/dist/graph-render-rFAqZujX.mjs +0 -1081
  193. package/dist/graph-render-rFAqZujX.mjs.map +0 -1
  194. package/dist/init-Cv9UzWL5.mjs.map +0 -1
  195. package/dist/inspect-live-schema-C6ohV_oQ.mjs.map +0 -1
  196. package/dist/migration-check-BiBJoYYW.mjs +0 -341
  197. package/dist/migration-check-BiBJoYYW.mjs.map +0 -1
  198. package/dist/migration-graph-D7DVUElV.mjs +0 -1232
  199. package/dist/migration-graph-D7DVUElV.mjs.map +0 -1
  200. package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
  201. package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
  202. package/dist/migration-plan-9DJ7q7_z.mjs.map +0 -1
  203. package/dist/migration-types-D2FW63pr.d.mts +0 -15
  204. package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
  205. package/dist/migrations-Cv2jxNNK.mjs +0 -228
  206. package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
  207. package/dist/terminal-ui-5Y6mrg93.d.mts.map +0 -1
  208. package/dist/types-Dt_SfqFm.d.mts.map +0 -1
  209. package/src/utils/formatters/graph-migration-mapper.ts +0 -235
  210. package/src/utils/formatters/graph-render.ts +0 -1323
  211. package/src/utils/formatters/graph-types.ts +0 -120
  212. package/src/utils/formatters/migration-graph-layout.ts +0 -1119
  213. package/src/utils/formatters/migration-graph-tree-render.ts +0 -459
@@ -4,6 +4,7 @@ import { notOk } from "@prisma-next/utils/result";
4
4
  import { relative, resolve } from "pathe";
5
5
  import { readFile } from "node:fs/promises";
6
6
  import { hasMigrations } from "@prisma-next/framework-components/control";
7
+ import { blindCast } from "@prisma-next/utils/casts";
7
8
  import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
8
9
  import "@prisma-next/errors/migration";
9
10
  import { APP_SPACE_ID as APP_SPACE_ID$1, spaceMigrationDirectory } from "@prisma-next/migration-tools/spaces";
@@ -39,6 +40,20 @@ function errorRefSetEmptySentinel(hash) {
39
40
  });
40
41
  }
41
42
  /**
43
+ * `--legend` was combined with a machine-readable or silent output flag.
44
+ * The legend is human-only decoration on stderr.
45
+ */
46
+ function errorLegendHumanOnly(conflictingFlag) {
47
+ return errorRuntime("`--legend` is only available for human-readable output", {
48
+ why: `\`--legend\` prints a glyph key to stderr and cannot be combined with ${conflictingFlag}.`,
49
+ fix: `Omit ${conflictingFlag} to print the legend alongside the tree, or omit --legend when using ${conflictingFlag}.`,
50
+ meta: {
51
+ code: "MIGRATION.LEGEND_HUMAN_ONLY",
52
+ conflictingFlag
53
+ }
54
+ });
55
+ }
56
+ /**
42
57
  * `--space <id>` was given a value that doesn't satisfy the contract-space
43
58
  * naming rule (`[a-z][a-z0-9_-]{0,63}` per `isValidSpaceId`). Fires before
44
59
  * any fs work — the input is syntactically rejected the same way an on-disk
@@ -189,9 +204,43 @@ function mapMigrationToolsError(error) {
189
204
  });
190
205
  }
191
206
  /**
207
+ * Shared "needs a live database" precondition for read verbs that consult the
208
+ * marker/ledger (`migration log`, `migration status`). A command needs both a
209
+ * connection string and a control-plane driver; either missing yields the same
210
+ * `PN-CLI-4005` envelope with `meta.missingFlags` (canonical long-form flags
211
+ * per CLI Style Guide §Errors) so callers can react programmatically. Returns
212
+ * `null` when both are present.
213
+ */
214
+ function requireLiveDatabase(args) {
215
+ if (args.dbConnection && args.hasDriver) return null;
216
+ const missingFlags = args.dbConnection ? [] : ["--db"];
217
+ return errorDatabaseConnectionRequired({
218
+ why: args.why,
219
+ missingFlags,
220
+ ...ifDefined("commandName", args.commandName),
221
+ ...ifDefined("retryCommand", args.retryCommand)
222
+ });
223
+ }
224
+ /**
192
225
  * Maps a `RefResolutionError` from the contract/migration reference
193
226
  * resolver into a CLI structured error envelope.
194
227
  */
228
+ /**
229
+ * A migration ref (dirName or hash-prefix) resolves in more than one contract
230
+ * space. The user must qualify with `--space <id>` to disambiguate.
231
+ */
232
+ function errorAmbiguousMigrationRef(ref, spaceIds) {
233
+ const spaceList = spaceIds.join(", ");
234
+ return errorRuntime(`Ambiguous migration reference: "${ref}" resolves in multiple spaces — qualify with --space <id>`, {
235
+ why: `"${ref}" matches migrations in spaces: ${spaceList}.`,
236
+ fix: `Qualify with --space <id> to select one space. Available matching spaces: ${spaceList}.`,
237
+ meta: {
238
+ code: "MIGRATION.AMBIGUOUS_MIGRATION_REF",
239
+ ref,
240
+ spaceIds: [...spaceIds]
241
+ }
242
+ });
243
+ }
195
244
  function mapRefResolutionError(error) {
196
245
  switch (error.kind) {
197
246
  case "not-found": return errorRuntime(`Not a known ${error.grammar} reference: "${error.input}"`, {
@@ -450,8 +499,7 @@ function formatReadMoreLine(options) {
450
499
  function formatMultilineDescription(options) {
451
500
  const lines = [];
452
501
  const formatGreen = (text) => options.useColor ? green(text) : text;
453
- const rightColumnWidth = calculateRightColumnWidth();
454
- const wrapWidth = 2 + LEFT_COLUMN_WIDTH + 2 + rightColumnWidth - 2;
502
+ const wrapWidth = 24 + calculateRightColumnWidth() - 2;
455
503
  for (const descLine of options.descriptionLines) {
456
504
  const wrappedLines = wrapTextAnsi(descLine.replace(/Prisma Next/g, (match) => formatGreen(match)), wrapWidth);
457
505
  for (const wrappedLine of wrappedLines) lines.push(`${options.formatDimText("│")} ${wrappedLine}`);
@@ -670,6 +718,237 @@ function isCI$1() {
670
718
  return isCI;
671
719
  }
672
720
  //#endregion
721
+ //#region src/utils/formatters/migrations.ts
722
+ /**
723
+ * Render a single statement of an `OperationPreview` for the human-readable
724
+ * preview block. SQL statements get a trailing `;` if missing so the rendered
725
+ * preview is byte-identical to the legacy `string[]`-based renderer for SQL
726
+ * targets. Other languages (`'mongodb-shell'`) render verbatim.
727
+ */
728
+ function renderPreviewStatement(text, language) {
729
+ const trimmed = text.trim();
730
+ if (!trimmed) return void 0;
731
+ if (language === "sql") return trimmed.endsWith(";") ? trimmed : `${trimmed};`;
732
+ return trimmed;
733
+ }
734
+ /**
735
+ * Choose the header label for a preview block. SQL-only previews keep the
736
+ * legacy `DDL preview` label so the rendered output is byte-identical to the
737
+ * pre-aggregate SQL CLI; previews from any other family — or a mix that
738
+ * includes any non-SQL language — use the family-agnostic `Operation preview`
739
+ * label.
740
+ *
741
+ * An empty `statements` array deliberately renders as `Operation preview`
742
+ * rather than `DDL preview`: `Array.prototype.every` is vacuously true for
743
+ * empty arrays, but we have no evidence the preview is SQL-only when no
744
+ * statements are present, so the family-agnostic label is the safer default.
745
+ */
746
+ function previewBlockHeader(preview) {
747
+ return preview.statements.length > 0 && preview.statements.every((s) => s.language === "sql") ? "DDL preview" : "Operation preview";
748
+ }
749
+ function formatPlannerWarningsBlock(warnings, useColor) {
750
+ const formatDimText = (text) => formatDim(useColor, text);
751
+ const lines = ["", "Warnings:"];
752
+ for (const warning of warnings) lines.push(` ${formatDimText(`- ${warning.summary}`)}`);
753
+ return lines;
754
+ }
755
+ /**
756
+ * Render the shared per-space execution block consumed by the `db init`
757
+ * / `db update` / `migrate` summaries. Always shows: space
758
+ * label (`Extension space: <id>` or `App space`) → per-op lines under
759
+ * each space → per-space marker hash (when known).
760
+ *
761
+ * `mode` controls the marker label phrasing — `'apply'` shows
762
+ * `marker → <hash>` (post-apply), `'plan'` omits the marker line
763
+ * entirely (no marker has been written yet).
764
+ */
765
+ function formatPerSpaceBlock(perSpace, mode, useColor) {
766
+ const formatYellow = createColorFormatter(useColor, yellow);
767
+ const formatCyan = createColorFormatter(useColor, cyan);
768
+ const formatDimText = (text) => formatDim(useColor, text);
769
+ const lines = [];
770
+ for (let s = 0; s < perSpace.length; s++) {
771
+ const space = perSpace[s];
772
+ if (s > 0) lines.push("");
773
+ const header = space.kind === "app" ? formatCyan("App space") : formatCyan(`Extension space: ${space.spaceId}`);
774
+ lines.push(header);
775
+ if (space.operations.length === 0) lines.push(` ${formatDimText("(no operations)")}`);
776
+ else for (let i = 0; i < space.operations.length; i++) {
777
+ const op = space.operations[i];
778
+ const treeChar = i === space.operations.length - 1 ? "└" : "├";
779
+ const destructiveMarker = op.operationClass === "destructive" ? ` ${formatYellow("(destructive)")}` : "";
780
+ lines.push(` ${formatDimText(treeChar)}─ ${op.label}${destructiveMarker}`);
781
+ }
782
+ if (mode === "apply" && space.marker) lines.push(` ${formatDimText(`marker: ${space.marker.storageHash}`)}`);
783
+ }
784
+ return lines;
785
+ }
786
+ /**
787
+ * Formats human-readable output for migration commands (db init, db update) in plan mode.
788
+ */
789
+ function formatMigrationPlanOutput(result, flags) {
790
+ if (flags.quiet) return "";
791
+ const lines = [];
792
+ const useColor = flags.color !== false;
793
+ const formatGreen = createColorFormatter(useColor, green);
794
+ const formatDimText = (text) => formatDim(useColor, text);
795
+ const operationCount = result.plan?.operations.length ?? 0;
796
+ const spaceCount = result.perSpace?.length ?? 0;
797
+ if (spaceCount > 0) lines.push(`${formatGreen("✔")} Planned ${operationCount} operation(s) across ${spaceCount} contract space${spaceCount === 1 ? "" : "s"}`);
798
+ else lines.push(`${formatGreen("✔")} Planned ${operationCount} operation(s)`);
799
+ if (result.warnings && result.warnings.length > 0) lines.push(...formatPlannerWarningsBlock(result.warnings, useColor));
800
+ const formatYellow = createColorFormatter(useColor, yellow);
801
+ if (result.perSpace && result.perSpace.length > 0) {
802
+ lines.push("");
803
+ lines.push(...formatPerSpaceBlock(result.perSpace, "plan", useColor));
804
+ if (result.perSpace.some((s) => s.operations.some((op) => op.operationClass === "destructive"))) {
805
+ lines.push("");
806
+ lines.push(`${formatYellow("⚠")} This migration contains destructive operations that may cause data loss.`);
807
+ }
808
+ } else if (result.plan?.operations && result.plan.operations.length > 0) {
809
+ lines.push(`${formatDimText("│")}`);
810
+ for (let i = 0; i < result.plan.operations.length; i++) {
811
+ const op = result.plan.operations[i];
812
+ if (!op) continue;
813
+ const treeChar = i === result.plan.operations.length - 1 ? "└" : "├";
814
+ const destructiveMarker = op.operationClass === "destructive" ? ` ${formatYellow("(destructive)")}` : "";
815
+ lines.push(`${formatDimText(treeChar)}─ ${op.label}${destructiveMarker}`);
816
+ }
817
+ if (result.plan.operations.some((op) => op.operationClass === "destructive")) {
818
+ lines.push("");
819
+ lines.push(`${formatYellow("⚠")} This migration contains destructive operations that may cause data loss.`);
820
+ }
821
+ }
822
+ if (result.plan?.destination) {
823
+ lines.push("");
824
+ lines.push(`${formatDimText(`Destination hash: ${result.plan.destination.storageHash}`)}`);
825
+ }
826
+ if (result.plannedAdvanceRef) {
827
+ lines.push("");
828
+ lines.push(formatDimText(`Would advance ref "${result.plannedAdvanceRef.name}" → ${result.plannedAdvanceRef.hash}`));
829
+ }
830
+ const preview = result.plan?.preview;
831
+ if (preview) {
832
+ lines.push("");
833
+ lines.push(`${formatDimText(previewBlockHeader(preview))}`);
834
+ if (preview.statements.length === 0) lines.push(`${formatDimText("No operations.")}`);
835
+ else {
836
+ lines.push("");
837
+ for (const statement of preview.statements) {
838
+ const rendered = renderPreviewStatement(statement.text, statement.language);
839
+ if (rendered) lines.push(rendered);
840
+ }
841
+ }
842
+ }
843
+ if (isVerbose(flags, 1)) lines.push(`${formatDimText(`Total time: ${result.timings.total}ms`)}`);
844
+ lines.push("");
845
+ lines.push(`${formatDimText("This is a dry run. No changes were applied.")}`);
846
+ lines.push(`${formatDimText("Run without --dry-run to apply changes.")}`);
847
+ return lines.join("\n");
848
+ }
849
+ function formatMigrationApplyCommandOutput(result, flags) {
850
+ if (flags.quiet) return "";
851
+ const lines = [];
852
+ const useColor = flags.color !== false;
853
+ const formatGreen = createColorFormatter(useColor, green);
854
+ const formatDimText = (text) => formatDim(useColor, text);
855
+ lines.push(`${formatGreen("✔")} ${result.summary}`);
856
+ if (result.perSpace.length > 0) {
857
+ lines.push("");
858
+ for (const line of formatPerSpaceBlock(result.perSpace, "apply", useColor)) lines.push(line);
859
+ }
860
+ if (result.advancedRef) {
861
+ lines.push("");
862
+ lines.push(formatDimText(`Advanced ref "${result.advancedRef.name}" → ${result.advancedRef.hash}`));
863
+ }
864
+ lines.push("");
865
+ lines.push(formatDimText("Next: prisma-next migration status"));
866
+ if (isVerbose(flags, 1) && result.timings) {
867
+ lines.push("");
868
+ lines.push(formatDimText(`Total time: ${result.timings.total}ms`));
869
+ }
870
+ return lines.join("\n");
871
+ }
872
+ function formatSpaceShowBlock(space, useColor) {
873
+ const formatGreen = createColorFormatter(useColor, green);
874
+ const formatYellow = createColorFormatter(useColor, yellow);
875
+ const formatDimText = (text) => formatDim(useColor, text);
876
+ const lines = [];
877
+ lines.push(`${formatGreen("✔")} ${space.name}`);
878
+ lines.push(`${formatDimText(` from: ${space.fromContract ?? "(baseline)"}`)}`);
879
+ lines.push(`${formatDimText(` to: ${space.toContract}`)}`);
880
+ lines.push(`${formatDimText(` hash: ${space.hash}`)}`);
881
+ lines.push(`${formatDimText(` created: ${space.createdAt}`)}`);
882
+ lines.push("");
883
+ lines.push(`${space.operations.length} operation(s)`);
884
+ if (space.operations.length > 0) {
885
+ lines.push(`${formatDimText("│")}`);
886
+ for (let i = 0; i < space.operations.length; i++) {
887
+ const op = space.operations[i];
888
+ const treeChar = i === space.operations.length - 1 ? "└" : "├";
889
+ const destructiveMarker = op.operationClass === "destructive" ? ` ${formatYellow("(destructive)")}` : "";
890
+ lines.push(`${formatDimText(treeChar)}─ ${op.label}${destructiveMarker}`);
891
+ }
892
+ if (space.operations.some((op) => op.operationClass === "destructive")) {
893
+ lines.push("");
894
+ lines.push(`${formatYellow("⚠")} This migration contains destructive operations that may cause data loss.`);
895
+ }
896
+ }
897
+ if (space.preview.statements.length > 0) {
898
+ lines.push("");
899
+ lines.push(`${formatDimText(previewBlockHeader(space.preview))}`);
900
+ lines.push("");
901
+ for (const statement of space.preview.statements) {
902
+ const rendered = renderPreviewStatement(statement.text, statement.language);
903
+ if (rendered) lines.push(rendered);
904
+ }
905
+ }
906
+ return lines;
907
+ }
908
+ function formatMigrationShowOutput(result, flags) {
909
+ if (flags.quiet) return "";
910
+ const useColor = flags.color !== false;
911
+ return formatSpaceShowBlock(result.migration, useColor).join("\n");
912
+ }
913
+ /**
914
+ * Formats human-readable output for migration commands (db init, db update) in apply mode.
915
+ */
916
+ function formatMigrationApplyOutput(result, flags) {
917
+ if (flags.quiet) return "";
918
+ const lines = [];
919
+ const useColor = flags.color !== false;
920
+ const formatGreen = createColorFormatter(useColor, green);
921
+ const formatDimText = (text) => formatDim(useColor, text);
922
+ if (result.ok) {
923
+ const executed = result.execution?.operationsExecuted ?? 0;
924
+ const spaceCount = result.perSpace?.length ?? 0;
925
+ if (executed === 0) {
926
+ const acrossClause = spaceCount > 0 ? ` across ${spaceCount} contract space${spaceCount === 1 ? "" : "s"}` : "";
927
+ lines.push(`${formatGreen("✔")} Database already matches contract${acrossClause}`);
928
+ } else if (spaceCount > 0) lines.push(`${formatGreen("✔")} Applied ${executed} operation(s) across ${spaceCount} contract space${spaceCount === 1 ? "" : "s"}`);
929
+ else lines.push(`${formatGreen("✔")} Applied ${executed} operation(s)`);
930
+ if (result.warnings && result.warnings.length > 0) lines.push(...formatPlannerWarningsBlock(result.warnings, useColor));
931
+ if (result.perSpace && result.perSpace.length > 0) {
932
+ lines.push("");
933
+ lines.push(...formatPerSpaceBlock(result.perSpace, "apply", useColor));
934
+ lines.push("");
935
+ lines.push(formatDimText(`Run 'prisma-next migration status' to confirm ${spaceCount === 1 ? "the space is" : "all spaces are"} up to date.`));
936
+ } else if (result.marker) {
937
+ lines.push(`${formatDimText(` App-space marker: ${result.marker.storageHash}`)}`);
938
+ if (result.marker.profileHash) lines.push(`${formatDimText(` Profile hash: ${result.marker.profileHash}`)}`);
939
+ }
940
+ if (isVerbose(flags, 1)) lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
941
+ if (result.advancedRef) lines.push(formatDimText(`Advanced ref "${result.advancedRef.name}" → ${result.advancedRef.hash}`));
942
+ }
943
+ return lines.join("\n");
944
+ }
945
+ /**
946
+ * Formats JSON output for migration commands (db init, db update).
947
+ */
948
+ function formatMigrationJson(result) {
949
+ return JSON.stringify(result, null, 2);
950
+ }
951
+ //#endregion
673
952
  //#region src/utils/formatters/errors.ts
674
953
  /**
675
954
  * Formats error output for human-readable display.
@@ -711,6 +990,11 @@ function formatErrorOutput(error, flags) {
711
990
  }
712
991
  }
713
992
  if (error.docsUrl && isVerbose(flags, 1)) lines.push(formatDimText(error.docsUrl));
993
+ const plannerWarnings = error.meta?.["plannerWarnings"];
994
+ if (Array.isArray(plannerWarnings) && plannerWarnings.length > 0) {
995
+ const typedWarnings = blindCast(plannerWarnings);
996
+ lines.push(...formatPlannerWarningsBlock(typedWarnings, useColor));
997
+ }
714
998
  if (isVerbose(flags, 2) && error.meta) lines.push(`${formatDimText(` Meta: ${JSON.stringify(error.meta, null, 2)}`)}`);
715
999
  return lines.join("\n");
716
1000
  }
@@ -1163,6 +1447,36 @@ function parseGlobalFlags(options) {
1163
1447
  if (options.yes || options.y) flags.yes = true;
1164
1448
  return flags;
1165
1449
  }
1450
+ /**
1451
+ * Bridges the two TTY checks (stdout via `flags`, stdin via
1452
+ * `process.stdin.isTTY`) into the `canPrompt` boolean the interactive
1453
+ * `init` flow consumes.
1454
+ *
1455
+ * Per the [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity):
1456
+ *
1457
+ * - `flags.interactive` governs *decoration* (TerminalUI, intro/outro,
1458
+ * spinners) and is derived from stdout-TTY by `parseGlobalFlags`,
1459
+ * honouring `--interactive` / `--no-interactive`.
1460
+ * - Prompting additionally requires a stdin TTY — closing stdin is a
1461
+ * common signal in CI / agent environments even when stdout stays
1462
+ * attached.
1463
+ * - `--interactive` is the explicit override: when the user passes it,
1464
+ * we honour it (e.g. testing flows where stdin is stubbed).
1465
+ *
1466
+ * Single source of truth for the interactive-prompt decision: both the
1467
+ * `init` action handler and the preAction telemetry bridge derive
1468
+ * prompt-eligibility from this helper so they cannot drift. Lives in
1469
+ * `global-flags` (alongside `parseGlobalFlags`) to keep
1470
+ * `utils/telemetry` and `commands/init/index` free of an import cycle.
1471
+ *
1472
+ * Exported so callers and tests can derive the same value without
1473
+ * touching `process` globals.
1474
+ */
1475
+ function deriveCanPrompt(opts) {
1476
+ if (opts.optionInteractive === true) return true;
1477
+ if (opts.flagsInteractive === false) return false;
1478
+ return opts.stdinIsTTY;
1479
+ }
1166
1480
  //#endregion
1167
1481
  //#region src/utils/command-helpers.ts
1168
1482
  const longDescriptions = /* @__PURE__ */ new WeakMap();
@@ -1269,27 +1583,6 @@ function toStructuralEdge(edge) {
1269
1583
  invariants: edge.invariants
1270
1584
  };
1271
1585
  }
1272
- /**
1273
- * Maps a PathDecision to the slim CLI output representation.
1274
- */
1275
- function toPathDecisionResult(decision) {
1276
- return {
1277
- fromHash: decision.fromHash,
1278
- toHash: decision.toHash,
1279
- alternativeCount: decision.alternativeCount,
1280
- tieBreakReasons: decision.tieBreakReasons,
1281
- requiredInvariants: decision.requiredInvariants ?? [],
1282
- satisfiedInvariants: decision.satisfiedInvariants ?? [],
1283
- ...ifDefined("refName", decision.refName),
1284
- selectedPath: decision.selectedPath.map((entry) => ({
1285
- dirName: entry.dirName,
1286
- migrationHash: entry.migrationHash,
1287
- from: entry.from,
1288
- to: entry.to,
1289
- invariants: entry.invariants
1290
- }))
1291
- };
1292
- }
1293
1586
  function targetSupportsMigrations(target) {
1294
1587
  return hasMigrations(target);
1295
1588
  }
@@ -1370,6 +1663,6 @@ function addGlobalOptions(command) {
1370
1663
  } }).option("--format <pretty|json>", "Output format (default: pretty, or json when stdout is not a TTY)").option("--json", "Output as JSON (alias for --format json)").option("-q, --quiet", "Quiet mode: errors only").option("-v, --verbose", "Verbose output: debug info, timings").option("--trace", "Trace output: deep internals, stack traces").option("--color", "Force color output").option("--no-color", "Disable color output").option("--interactive", "Force interactive mode").option("--no-interactive", "Disable interactive prompts").option("-y, --yes", "Auto-accept prompts");
1371
1664
  }
1372
1665
  //#endregion
1373
- export { errorTargetMigrationNotSupported as $, CliStructuredError$1 as A, errorInvalidSpaceId as B, formatCommandHelp as C, createColorFormatter as D, formatSuccessMessage as E, errorDatabaseConnectionRequired as F, errorPlanForgotTheFlag as G, errorMarkerMissing as H, errorDestructiveChanges as I, errorRefSetHashNotInGraph as J, errorRefSetBundleNotFound as K, errorDriverRequired as L, errorConfigValidation$1 as M, errorContractConfigMissing$1 as N, formatDim as O, errorContractValidationFailed as P, errorSpaceNotFound as Q, errorFileNotFound as R, isCI$1 as S, formatStyledHeader as T, errorMigrationPlanningFailed as U, errorMarkerMismatch as V, errorPathUnreachable as W, errorRuntime$1 as X, errorRunnerFailed as Y, errorSnapshotMissing as Z, createTerminalUI as _, readContractEnvelope as a, formatErrorJson as b, sanitizeErrorMessage as c, setCommandSeeAlso as d, errorTargetMismatch as et, targetSupportsMigrations as f, parseGlobalFlagsOrExit as g, parseGlobalFlags as h, maskConnectionUrl as i, ERROR_CODE_DESTRUCTIVE_CHANGES as j, isVerbose as k, setCommandDescriptions as l, toStructuralEdge as m, collectDeclaredInvariants as n, mapMigrationToolsError as nt, resolveContractPath as o, toPathDecisionResult as p, errorRefSetEmptySentinel as q, getTargetMigrations as r, mapRefResolutionError as rt, resolveMigrationPaths as s, addGlobalOptions as t, errorUnexpected$1 as tt, setCommandExamples as u, installShutdownHandlers as v, formatRootHelp as w, formatErrorOutput as x, handleResult as y, errorHashMismatch as z };
1666
+ export { errorRefSetBundleNotFound as $, formatStyledHeader as A, errorContractValidationFailed as B, formatMigrationApplyOutput as C, isCI$1 as D, formatMigrationShowOutput as E, CliStructuredError$1 as F, errorHashMismatch as G, errorDestructiveChanges as H, ERROR_CODE_DESTRUCTIVE_CHANGES as I, errorMarkerMismatch as J, errorInvalidSpaceId as K, errorAmbiguousMigrationRef as L, createColorFormatter as M, formatDim as N, formatCommandHelp as O, isVerbose as P, errorPlanForgotTheFlag as Q, errorConfigValidation$1 as R, formatMigrationApplyCommandOutput as S, formatMigrationPlanOutput as T, errorDriverRequired as U, errorDatabaseConnectionRequired as V, errorFileNotFound as W, errorMigrationPlanningFailed as X, errorMarkerMissing as Y, errorPathUnreachable as Z, createTerminalUI as _, readContractEnvelope as a, errorSpaceNotFound as at, formatErrorJson as b, sanitizeErrorMessage as c, errorUnexpected$1 as ct, setCommandSeeAlso as d, requireLiveDatabase as dt, errorRefSetEmptySentinel as et, targetSupportsMigrations as f, parseGlobalFlagsOrExit as g, parseGlobalFlags as h, maskConnectionUrl as i, errorSnapshotMissing as it, formatSuccessMessage as j, formatRootHelp as k, setCommandDescriptions as l, mapMigrationToolsError as lt, deriveCanPrompt as m, collectDeclaredInvariants as n, errorRunnerFailed as nt, resolveContractPath as o, errorTargetMigrationNotSupported as ot, toStructuralEdge as p, errorLegendHumanOnly as q, getTargetMigrations as r, errorRuntime$1 as rt, resolveMigrationPaths as s, errorTargetMismatch as st, addGlobalOptions as t, errorRefSetHashNotInGraph as tt, setCommandExamples as u, mapRefResolutionError as ut, installShutdownHandlers as v, formatMigrationJson as w, formatErrorOutput as x, handleResult as y, errorContractConfigMissing$1 as z };
1374
1667
 
1375
- //# sourceMappingURL=command-helpers-Bbw1GbwL.mjs.map
1668
+ //# sourceMappingURL=command-helpers-DGMvGBeX.mjs.map