@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
package/README.md CHANGED
@@ -1420,7 +1420,7 @@ try {
1420
1420
  | `sign(options)` | Writes contract marker to database |
1421
1421
  | `dbInit(options)` | Initializes database schema from contract |
1422
1422
  | `dbUpdate(options)` | Updates database schema to match contract |
1423
- | `migrationApply(options)` | Applies pre-planned migration edges to database |
1423
+ | `migrate(options)` | Advances the database to the target contract via the migration graph |
1424
1424
  | `introspect(options)` | Introspects database schema |
1425
1425
 
1426
1426
  ### Result Types
@@ -1433,7 +1433,7 @@ Operations return structured result types:
1433
1433
  - `sign()` → `SignDatabaseResult`
1434
1434
  - `dbInit()` → `Result<DbInitSuccess, DbInitFailure>` (uses Result pattern)
1435
1435
  - `dbUpdate()` → `Result<DbUpdateSuccess, DbUpdateFailure>` (uses Result pattern)
1436
- - `migrationApply()` → `Result<MigrationApplySuccess, MigrationApplyFailure>` (uses Result pattern)
1436
+ - `migrate()` → `Result<MigrateSuccess, MigrateFailure>` (uses Result pattern)
1437
1437
  - `introspect()` → Schema IR (family-specific)
1438
1438
 
1439
1439
  ### Error Handling
package/dist/cli.mjs CHANGED
@@ -1,149 +1,30 @@
1
1
  #!/usr/bin/env node
2
- import { C as formatCommandHelp, S as isCI, g as parseGlobalFlagsOrExit, h as parseGlobalFlags, l as setCommandDescriptions, t as addGlobalOptions, u as setCommandExamples, v as installShutdownHandlers, w as formatRootHelp } from "./command-helpers-Bbw1GbwL.mjs";
3
- import { t as createContractEmitCommand } from "./contract-emit-DxcGl4Uq.mjs";
4
- import { t as createContractInferCommand } from "./contract-infer-D8uEbJuu.mjs";
2
+ import { D as isCI, O as formatCommandHelp, g as parseGlobalFlagsOrExit, h as parseGlobalFlags, k as formatRootHelp, l as setCommandDescriptions, m as deriveCanPrompt, t as addGlobalOptions, u as setCommandExamples, v as installShutdownHandlers } from "./command-helpers-DGMvGBeX.mjs";
3
+ import { t as createContractEmitCommand } from "./contract-emit-B_qriF8B.mjs";
4
+ import { t as createContractInferCommand } from "./contract-infer-BYT_ra_U.mjs";
5
5
  import { createDbInitCommand } from "./commands/db-init.mjs";
6
6
  import { createDbSchemaCommand } from "./commands/db-schema.mjs";
7
7
  import { createDbSignCommand } from "./commands/db-sign.mjs";
8
8
  import { createDbUpdateCommand } from "./commands/db-update.mjs";
9
- import { t as createDbVerifyCommand } from "./db-verify-v_vUKXTU.mjs";
9
+ import { t as createDbVerifyCommand } from "./db-verify-C24FKhb7.mjs";
10
+ import { t as createMigrationListCommand } from "./migration-list-DlJJ_38Z.mjs";
10
11
  import { createMigrateCommand } from "./commands/migrate.mjs";
11
- import { t as createMigrationCheckCommand } from "./migration-check-BiBJoYYW.mjs";
12
- import { t as createMigrationGraphCommand } from "./migration-graph-D7DVUElV.mjs";
13
- import { createMigrationListCommand } from "./commands/migration-list.mjs";
14
- import { createMigrationLogCommand } from "./commands/migration-log.mjs";
12
+ import { t as createMigrationCheckCommand } from "./migration-check-soB5uZEQ.mjs";
13
+ import { createMigrationGraphCommand } from "./commands/migration-graph.mjs";
14
+ import { t as createMigrationLogCommand } from "./migration-log-CG0qQAFm.mjs";
15
15
  import { createMigrationNewCommand } from "./commands/migration-new.mjs";
16
- import { t as createMigrationPlanCommand } from "./migration-plan-9DJ7q7_z.mjs";
16
+ import { t as createMigrationPlanCommand } from "./migration-plan-z5Ing-TD.mjs";
17
17
  import { createMigrationShowCommand } from "./commands/migration-show.mjs";
18
- import { createMigrationStatusCommand } from "./commands/migration-status.mjs";
18
+ import { r as createMigrationStatusCommand } from "./migration-status-CgWSoI_g.mjs";
19
19
  import { createRefCommand } from "./commands/ref.mjs";
20
+ import { t as createTelemetryCommand } from "./telemetry-BIM4beEO.mjs";
20
21
  import { Command } from "commander";
21
- import { ifDefined } from "@prisma-next/utils/defined";
22
22
  import { DEFAULT_CONTRACT_SOURCE_DIR } from "@prisma-next/config/config-types";
23
- import { fileURLToPath } from "node:url";
24
- import { readUserConfig, resolveGating, runTelemetry } from "@prisma-next/cli-telemetry";
23
+ import { ensureInstallationId, readUserConfig, resolveGating, runTelemetry, userConfigPath } from "@prisma-next/cli-telemetry";
25
24
  import { distance } from "closest-match";
25
+ import { fileURLToPath } from "node:url";
26
26
  //#region package.json
27
- var version = "0.12.0";
28
- //#endregion
29
- //#region src/utils/telemetry.ts
30
- /**
31
- * Resolve the commander command path from a leaf `Command`, walking up
32
- * the parent chain. Result is rooted at the program name and ends at
33
- * the leaf — `['prisma-next', 'migration', 'new']` for
34
- * `prisma-next migration new …`.
35
- */
36
- function commandPathFor(actionCommand) {
37
- const path = [];
38
- let cursor = actionCommand;
39
- while (cursor !== null) {
40
- path.unshift(cursor.name());
41
- cursor = cursor.parent;
42
- }
43
- return path;
44
- }
45
- function commanderOptionSnapshots(actionCommand) {
46
- return actionCommand.options.map((option) => {
47
- const attributeName = option.attributeName();
48
- return {
49
- attributeName,
50
- longName: option.long ?? null,
51
- source: actionCommand.getOptionValueSource(attributeName) ?? null
52
- };
53
- });
54
- }
55
- /**
56
- * Project commander's leaf `Command` into the wire-shape snapshot the
57
- * telemetry sanitiser consumes. Pure projection — no env, no I/O.
58
- */
59
- function commanderSnapshotForTelemetry(actionCommand) {
60
- return {
61
- commandPath: commandPathFor(actionCommand),
62
- positionalArgs: actionCommand.args,
63
- options: commanderOptionSnapshots(actionCommand)
64
- };
65
- }
66
- function resolveTelemetryGate() {
67
- if (isCI()) return {
68
- enabled: false,
69
- outcome: {
70
- spawned: false,
71
- reason: "ci"
72
- }
73
- };
74
- const userConfig = readUserConfig();
75
- if (!resolveGating({
76
- env: process.env,
77
- config: userConfig
78
- }).enabled) return {
79
- enabled: false,
80
- outcome: {
81
- spawned: false,
82
- reason: "gated-off"
83
- }
84
- };
85
- return {
86
- enabled: true,
87
- userConfig
88
- };
89
- }
90
- /**
91
- * Path to the compiled sender script inside `@prisma-next/cli-telemetry`'s
92
- * `dist/`. Resolved off this module's `import.meta.url` via the package
93
- * specifier `@prisma-next/cli-telemetry/sender`, so the consumer pays
94
- * no attention to internal package layout.
95
- */
96
- function senderPath() {
97
- return fileURLToPath(new URL(import.meta.resolve("@prisma-next/cli-telemetry/sender")));
98
- }
99
- function fireTelemetry(actionCommand, userConfig, overrides = {}) {
100
- return runTelemetry({
101
- command: commanderSnapshotForTelemetry(actionCommand),
102
- version,
103
- projectRoot: process.cwd(),
104
- senderPath: senderPath(),
105
- isCI: isCI(),
106
- env: process.env,
107
- userConfig,
108
- ...ifDefined("databaseTarget", overrides.databaseTarget)
109
- });
110
- }
111
- /**
112
- * preAction-stage entry point. Synchronous by construction: resolve
113
- * env/CI/user-consent gates (cheap, all in-memory and a single tiny
114
- * user-config read), then — only when enabled — `fork()` the detached
115
- * sender script. The forked child loads `prisma-next.config.*` via
116
- * c12 on its own (see `loadProjectConfig` in cli-telemetry); the
117
- * parent does no project-config I/O on the command's hot path.
118
- *
119
- * Privacy invariant: gate resolution always happens before any project
120
- * config touches disk. The child loading user TS code is acceptable
121
- * only because it's gated behind the same resolved-enabled signal.
122
- */
123
- function fireTelemetryFromPreAction(actionCommand) {
124
- const gate = resolveTelemetryGate();
125
- if (!gate.enabled) return gate.outcome;
126
- return fireTelemetry(actionCommand, gate.userConfig);
127
- }
128
- /**
129
- * Manual one-shot telemetry path for the first `init` run where the user
130
- * explicitly answers Yes to the consent prompt. The preAction hook for
131
- * that same run has already resolved before consent existed, so it is
132
- * default-off. After consent is persisted, `runInit` calls this helper
133
- * exactly for that first affirmative answer; subsequent init runs skip
134
- * it because the prompt is not shown again.
135
- *
136
- * The child's c12 load would return `databaseTarget: null` for this
137
- * specific invocation because `prisma-next.config.*` is not yet on
138
- * disk (init writes it later in the same run). To preserve the
139
- * prompt-chosen target in the first-init telemetry event, this
140
- * helper forwards the value as a parent-side IPC override on
141
- * `ParentToSenderPayload.databaseTarget` — the child consults the
142
- * override first and falls back to its c12 result when absent.
143
- */
144
- function fireTelemetryAfterInitConsent(actionCommand, inputs) {
145
- return fireTelemetry(actionCommand, readUserConfig(), { databaseTarget: inputs.databaseTarget });
146
- }
27
+ var version = "0.13.0-dev.10";
147
28
  //#endregion
148
29
  //#region src/commands/init/templates/code-templates.ts
149
30
  function targetPackageName(target) {
@@ -411,8 +292,8 @@ Exit codes (see CLI Style Guide § Exit Codes):
411
292
  "prisma-next init --no-install # skip pnpm/npm install + emit",
412
293
  "prisma-next init --no-skill # skip the skills install (air-gapped / restricted env)"
413
294
  ]);
414
- return addGlobalOptions(command).option("--target <db>", "Database target: postgres or mongodb").option("--authoring <style>", "Schema authoring style: psl or typescript").option("--schema-path <path>", `Where to write the starter schema (default: ${defaultSchemaPath("psl")})`).option("--force", "Overwrite an existing scaffold without prompting").option("--write-env", "Write a .env file from .env.example (gitignored; default: only .env.example)").option("--probe-db", "Connect to DATABASE_URL once and check the server version against the target minimum (opt-in; off by default)").option("--strict-probe", "Treat a failed --probe-db as fatal (no-op without --probe-db; init is offline-by-default)").option("--no-install", "Skip dependency installation and contract emission").option("--no-skill", "Skip Prisma Next skills install (air-gapped CI, restricted registries, etc.)").action(async (options, actionCommand) => {
415
- const { runInit } = await import("./init-Cv9UzWL5.mjs");
295
+ return addGlobalOptions(command).option("--target <db>", "Database target: postgres or mongodb").option("--authoring <style>", "Schema authoring style: psl or typescript").option("--schema-path <path>", `Where to write the starter schema (default: ${defaultSchemaPath("psl")})`).option("--force", "Overwrite an existing scaffold without prompting").option("--write-env", "Write a .env file from .env.example (gitignored; default: only .env.example)").option("--probe-db", "Connect to DATABASE_URL once and check the server version against the target minimum (opt-in; off by default)").option("--strict-probe", "Treat a failed --probe-db as fatal (no-op without --probe-db; init is offline-by-default)").option("--no-install", "Skip dependency installation and contract emission").option("--no-skill", "Skip Prisma Next skills install (air-gapped CI, restricted registries, etc.)").action(async (options) => {
296
+ const { runInit } = await import("./init-0HwB-Vh8.mjs");
416
297
  const flags = parseGlobalFlagsOrExit(options);
417
298
  const canPrompt = deriveCanPrompt({
418
299
  flagsInteractive: flags.interactive,
@@ -422,38 +303,11 @@ Exit codes (see CLI Style Guide § Exit Codes):
422
303
  const exitCode = await runInit(process.cwd(), {
423
304
  options,
424
305
  flags,
425
- canPrompt,
426
- afterFirstTelemetryConsent: (inputs) => {
427
- fireTelemetryAfterInitConsent(actionCommand, { databaseTarget: inputs.target });
428
- }
306
+ canPrompt
429
307
  });
430
308
  process.exit(exitCode);
431
309
  });
432
310
  }
433
- /**
434
- * Bridges the action handler's two TTY checks (stdout via `flags`, stdin
435
- * via `process.stdin.isTTY`) into the `canPrompt` boolean `runInit`
436
- * consumes.
437
- *
438
- * Per the [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity):
439
- *
440
- * - `flags.interactive` governs *decoration* (TerminalUI, intro/outro,
441
- * spinners) and is derived from stdout-TTY by `parseGlobalFlags`,
442
- * honouring `--interactive` / `--no-interactive`.
443
- * - Prompting additionally requires a stdin TTY — closing stdin is a
444
- * common signal in CI / agent environments even when stdout stays
445
- * attached.
446
- * - `--interactive` is the explicit override: when the user passes it,
447
- * we honour it (e.g. testing flows where stdin is stubbed).
448
- *
449
- * Exported so callers and tests can derive the same value without
450
- * touching `process` globals.
451
- */
452
- function deriveCanPrompt(opts) {
453
- if (opts.optionInteractive === true) return true;
454
- if (opts.flagsInteractive === false) return false;
455
- return opts.stdinIsTTY;
456
- }
457
311
  //#endregion
458
312
  //#region src/utils/suggest-command.ts
459
313
  /**
@@ -477,6 +331,167 @@ function suggestCommands(input, candidates) {
477
331
  return scored.filter((entry) => entry.dist === bestDist).slice(0, 3).map((entry) => entry.name);
478
332
  }
479
333
  //#endregion
334
+ //#region src/utils/telemetry.ts
335
+ /**
336
+ * Resolve the commander command path from a leaf `Command`, walking up
337
+ * the parent chain. Result is rooted at the program name and ends at
338
+ * the leaf — `['prisma-next', 'migration', 'new']` for
339
+ * `prisma-next migration new …`.
340
+ */
341
+ function commandPathFor(actionCommand) {
342
+ const path = [];
343
+ let cursor = actionCommand;
344
+ while (cursor !== null) {
345
+ path.unshift(cursor.name());
346
+ cursor = cursor.parent;
347
+ }
348
+ return path;
349
+ }
350
+ function commanderOptionSnapshots(actionCommand) {
351
+ return actionCommand.options.map((option) => {
352
+ const attributeName = option.attributeName();
353
+ return {
354
+ attributeName,
355
+ longName: option.long ?? null,
356
+ source: actionCommand.getOptionValueSource(attributeName) ?? null
357
+ };
358
+ });
359
+ }
360
+ /**
361
+ * Project commander's leaf `Command` into the wire-shape snapshot the
362
+ * telemetry sanitiser consumes. Pure projection — no env, no I/O.
363
+ */
364
+ function commanderSnapshotForTelemetry(actionCommand) {
365
+ return {
366
+ commandPath: commandPathFor(actionCommand),
367
+ positionalArgs: actionCommand.args,
368
+ options: commanderOptionSnapshots(actionCommand)
369
+ };
370
+ }
371
+ function resolveTelemetryGate() {
372
+ if (isCI()) return {
373
+ enabled: false,
374
+ outcome: {
375
+ spawned: false,
376
+ reason: "ci"
377
+ }
378
+ };
379
+ const userConfig = readUserConfig();
380
+ if (!resolveGating({
381
+ env: process.env,
382
+ config: userConfig
383
+ }).enabled) return {
384
+ enabled: false,
385
+ outcome: {
386
+ spawned: false,
387
+ reason: "gated-off"
388
+ }
389
+ };
390
+ return {
391
+ enabled: true,
392
+ userConfig
393
+ };
394
+ }
395
+ /**
396
+ * Path to the compiled sender script inside `@prisma-next/cli-telemetry`'s
397
+ * `dist/`. Resolved off this module's `import.meta.url` via the package
398
+ * specifier `@prisma-next/cli-telemetry/sender`, so the consumer pays
399
+ * no attention to internal package layout.
400
+ */
401
+ function senderPath() {
402
+ return fileURLToPath(new URL(import.meta.resolve("@prisma-next/cli-telemetry/sender")));
403
+ }
404
+ function fireTelemetry(actionCommand, userConfig) {
405
+ return runTelemetry({
406
+ command: commanderSnapshotForTelemetry(actionCommand),
407
+ version,
408
+ projectRoot: process.cwd(),
409
+ senderPath: senderPath(),
410
+ isCI: isCI(),
411
+ env: process.env,
412
+ userConfig
413
+ });
414
+ }
415
+ /**
416
+ * preAction-stage entry point. Synchronous by construction: resolve
417
+ * env/CI/user-consent gates (cheap, all in-memory and a single tiny
418
+ * user-config read), then — only when enabled — `fork()` the detached
419
+ * sender script. The forked child loads `prisma-next.config.*` via
420
+ * c12 on its own (see `loadProjectConfig` in cli-telemetry); the
421
+ * parent does no project-config I/O on the command's hot path.
422
+ *
423
+ * Privacy invariant: gate resolution always happens before any project
424
+ * config touches disk. The child loading user TS code is acceptable
425
+ * only because it's gated behind the same resolved-enabled signal.
426
+ */
427
+ /**
428
+ * Builds the one-time first-run disclosure. The resolved absolute path to
429
+ * the user-level config file is substituted in so the user can see exactly
430
+ * which file to edit (it must not be confused with `prisma-next.config.ts`).
431
+ * `prisma-next telemetry disable` is named as the primary, friendliest
432
+ * opt-out, alongside the env vars and the config edit.
433
+ */
434
+ function firstRunNotice(configPath) {
435
+ return [
436
+ "Prisma Next collects anonymous CLI usage data, enabled by default.",
437
+ "What's collected and why: https://prisma-next.dev/docs/cli/telemetry.",
438
+ "Opt out: run \"prisma-next telemetry disable\", set DO_NOT_TRACK=1 or",
439
+ `PRISMA_NEXT_DISABLE_TELEMETRY=1, or set "enableTelemetry": false in ${configPath}.`
440
+ ].join(" ");
441
+ }
442
+ /**
443
+ * Best-effort first-run disclosure + installationId mint. Runs only on the
444
+ * gating-enabled path. Prints the notice to stderr (never stdout) and mints
445
+ * a persistent id without touching `enableTelemetry`, so the opt-out default
446
+ * stays intact and no unasked-for consent is recorded.
447
+ *
448
+ * Every step is wrapped so an un-writable config dir (or any other failure)
449
+ * never throws and never blocks the command. Returns the minted (or
450
+ * pre-existing) id so the caller can forward it to `runTelemetry` without a
451
+ * redundant disk read. On mint failure it returns `undefined`: the notice may
452
+ * reprint next run, and `runTelemetry` no-ops on the missing id.
453
+ */
454
+ function discloseAndMintOnFirstRun() {
455
+ try {
456
+ process.stderr.write(`${firstRunNotice(userConfigPath())}\n`);
457
+ } catch {}
458
+ try {
459
+ return ensureInstallationId();
460
+ } catch {}
461
+ }
462
+ /**
463
+ * True when the run is the `telemetry` command (or one of its
464
+ * subcommands). The usage-telemetry preAction fire is exempted for it:
465
+ * it would be absurd for `telemetry disable` to send a usage event before
466
+ * disabling, or for `telemetry status` to mint an id + send while merely
467
+ * reporting state. This is the only command-specific exemption.
468
+ *
469
+ * The check is rooted at the program: the path must be
470
+ * `['prisma-next', 'telemetry', …]`, so it matches the top-level
471
+ * `telemetry` command and its subcommands without matching a hypothetical
472
+ * nested `… telemetry` elsewhere.
473
+ */
474
+ function isTelemetryCommand(actionCommand) {
475
+ return commandPathFor(actionCommand)[1] === "telemetry";
476
+ }
477
+ function fireTelemetryFromPreAction(actionCommand) {
478
+ if (isTelemetryCommand(actionCommand)) return {
479
+ spawned: false,
480
+ reason: "gated-off"
481
+ };
482
+ const gate = resolveTelemetryGate();
483
+ if (!gate.enabled) return gate.outcome;
484
+ const storedId = gate.userConfig.installationId;
485
+ if (typeof storedId !== "string" || storedId.length === 0) {
486
+ const installationId = discloseAndMintOnFirstRun();
487
+ return fireTelemetry(actionCommand, installationId === void 0 ? gate.userConfig : {
488
+ ...gate.userConfig,
489
+ installationId
490
+ });
491
+ }
492
+ return fireTelemetry(actionCommand, gate.userConfig);
493
+ }
494
+ //#endregion
480
495
  //#region src/cli.ts
481
496
  installShutdownHandlers();
482
497
  /**
@@ -642,6 +657,7 @@ const migrationCheckCommand = createMigrationCheckCommand();
642
657
  migrationCommand.addCommand(migrationCheckCommand);
643
658
  const migrateCommand = createMigrateCommand();
644
659
  const refCommand = createRefCommand();
660
+ const telemetryCommand = createTelemetryCommand();
645
661
  const initCommand = createInitCommand();
646
662
  program.addCommand(initCommand);
647
663
  program.addCommand(migrateCommand);
@@ -649,6 +665,7 @@ program.addCommand(contractCommand);
649
665
  program.addCommand(dbCommand);
650
666
  program.addCommand(migrationCommand);
651
667
  program.addCommand(refCommand);
668
+ program.addCommand(telemetryCommand);
652
669
  const TELEMETRY_CRASH_TEST_SLEEP_MS = 200;
653
670
  if (process.env["PRISMA_NEXT_ENABLE_TEST_COMMANDS"] === "1") {
654
671
  const telemetryCrashTestCommand = new Command("__telemetry-crash-test").description("Internal: deliberately throw for the telemetry e2e suite.").action(async () => {