@prisma-next/cli 0.3.0-dev.16 → 0.3.0-dev.162

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 (242) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +381 -128
  3. package/dist/cli-errors-BDCYR5ap.mjs +4 -0
  4. package/dist/cli-errors-Dzs7Oxz7.d.mts +3 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.js +1 -2671
  7. package/dist/cli.mjs +245 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/client-yYtotiSX.mjs +1063 -0
  10. package/dist/client-yYtotiSX.mjs.map +1 -0
  11. package/dist/commands/contract-emit.d.mts +7 -0
  12. package/dist/commands/contract-emit.d.mts.map +1 -0
  13. package/dist/commands/contract-emit.mjs +8 -0
  14. package/dist/commands/contract-infer.d.mts +7 -0
  15. package/dist/commands/contract-infer.d.mts.map +1 -0
  16. package/dist/commands/contract-infer.mjs +9 -0
  17. package/dist/commands/db-init.d.mts +7 -0
  18. package/dist/commands/db-init.d.mts.map +1 -0
  19. package/dist/commands/db-init.mjs +125 -0
  20. package/dist/commands/db-init.mjs.map +1 -0
  21. package/dist/commands/db-schema.d.mts +7 -0
  22. package/dist/commands/db-schema.d.mts.map +1 -0
  23. package/dist/commands/db-schema.mjs +55 -0
  24. package/dist/commands/db-schema.mjs.map +1 -0
  25. package/dist/commands/db-sign.d.mts +7 -0
  26. package/dist/commands/db-sign.d.mts.map +1 -0
  27. package/dist/commands/db-sign.mjs +136 -0
  28. package/dist/commands/db-sign.mjs.map +1 -0
  29. package/dist/commands/db-update.d.mts +7 -0
  30. package/dist/commands/db-update.d.mts.map +1 -0
  31. package/dist/commands/db-update.mjs +122 -0
  32. package/dist/commands/db-update.mjs.map +1 -0
  33. package/dist/commands/db-verify.d.mts +7 -0
  34. package/dist/commands/db-verify.d.mts.map +1 -0
  35. package/dist/commands/db-verify.mjs +322 -0
  36. package/dist/commands/db-verify.mjs.map +1 -0
  37. package/dist/commands/migration-apply.d.mts +36 -0
  38. package/dist/commands/migration-apply.d.mts.map +1 -0
  39. package/dist/commands/migration-apply.mjs +244 -0
  40. package/dist/commands/migration-apply.mjs.map +1 -0
  41. package/dist/commands/migration-new.d.mts +8 -0
  42. package/dist/commands/migration-new.d.mts.map +1 -0
  43. package/dist/commands/migration-new.mjs +151 -0
  44. package/dist/commands/migration-new.mjs.map +1 -0
  45. package/dist/commands/migration-plan.d.mts +47 -0
  46. package/dist/commands/migration-plan.d.mts.map +1 -0
  47. package/dist/commands/migration-plan.mjs +312 -0
  48. package/dist/commands/migration-plan.mjs.map +1 -0
  49. package/dist/commands/migration-ref.d.mts +43 -0
  50. package/dist/commands/migration-ref.d.mts.map +1 -0
  51. package/dist/commands/migration-ref.mjs +194 -0
  52. package/dist/commands/migration-ref.mjs.map +1 -0
  53. package/dist/commands/migration-show.d.mts +28 -0
  54. package/dist/commands/migration-show.d.mts.map +1 -0
  55. package/dist/commands/migration-show.mjs +139 -0
  56. package/dist/commands/migration-show.mjs.map +1 -0
  57. package/dist/commands/migration-status.d.mts +86 -0
  58. package/dist/commands/migration-status.d.mts.map +1 -0
  59. package/dist/commands/migration-status.mjs +8 -0
  60. package/dist/commands/migration-verify.d.mts +16 -0
  61. package/dist/commands/migration-verify.d.mts.map +1 -0
  62. package/dist/commands/migration-verify.mjs +109 -0
  63. package/dist/commands/migration-verify.mjs.map +1 -0
  64. package/dist/config-loader-C4VXKl8f.mjs +43 -0
  65. package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
  66. package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
  67. package/dist/config-loader.d.mts.map +1 -0
  68. package/dist/config-loader.mjs +3 -0
  69. package/dist/contract-emit-Bk_eEDKu.mjs +187 -0
  70. package/dist/contract-emit-Bk_eEDKu.mjs.map +1 -0
  71. package/dist/contract-infer-suMDmFSG.mjs +89 -0
  72. package/dist/contract-infer-suMDmFSG.mjs.map +1 -0
  73. package/dist/exports/config-types.d.mts +2 -0
  74. package/dist/exports/config-types.mjs +3 -0
  75. package/dist/exports/control-api.d.mts +624 -0
  76. package/dist/exports/control-api.d.mts.map +1 -0
  77. package/dist/exports/control-api.mjs +109 -0
  78. package/dist/exports/control-api.mjs.map +1 -0
  79. package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
  80. package/dist/exports/index.d.mts.map +1 -0
  81. package/dist/exports/index.mjs +141 -0
  82. package/dist/exports/index.mjs.map +1 -0
  83. package/dist/extract-operation-statements-BVlb3jxp.mjs +13 -0
  84. package/dist/extract-operation-statements-BVlb3jxp.mjs.map +1 -0
  85. package/dist/extract-sql-ddl-6EVSOThm.mjs +26 -0
  86. package/dist/extract-sql-ddl-6EVSOThm.mjs.map +1 -0
  87. package/dist/framework-components-BAsliT4V.mjs +59 -0
  88. package/dist/framework-components-BAsliT4V.mjs.map +1 -0
  89. package/dist/inspect-live-schema-HMutsJYh.mjs +91 -0
  90. package/dist/inspect-live-schema-HMutsJYh.mjs.map +1 -0
  91. package/dist/migration-command-scaffold-Dg7CKKCg.mjs +105 -0
  92. package/dist/migration-command-scaffold-Dg7CKKCg.mjs.map +1 -0
  93. package/dist/migration-status-BqfVmC0w.mjs +1582 -0
  94. package/dist/migration-status-BqfVmC0w.mjs.map +1 -0
  95. package/dist/migrations-Bv8oeiY_.mjs +173 -0
  96. package/dist/migrations-Bv8oeiY_.mjs.map +1 -0
  97. package/dist/progress-adapter-D4x8SbJa.mjs +43 -0
  98. package/dist/progress-adapter-D4x8SbJa.mjs.map +1 -0
  99. package/dist/terminal-ui-N5tR-ob5.mjs +967 -0
  100. package/dist/terminal-ui-N5tR-ob5.mjs.map +1 -0
  101. package/dist/verify-WARh5TjK.mjs +385 -0
  102. package/dist/verify-WARh5TjK.mjs.map +1 -0
  103. package/package.json +88 -42
  104. package/src/cli.ts +113 -58
  105. package/src/commands/contract-emit.ts +237 -144
  106. package/src/commands/contract-infer-paths.ts +32 -0
  107. package/src/commands/contract-infer.ts +143 -0
  108. package/src/commands/db-init.ts +97 -219
  109. package/src/commands/db-schema.ts +77 -0
  110. package/src/commands/db-sign.ts +208 -229
  111. package/src/commands/db-update.ts +236 -0
  112. package/src/commands/db-verify.ts +504 -184
  113. package/src/commands/inspect-live-schema.ts +170 -0
  114. package/src/commands/migration-apply.ts +427 -0
  115. package/src/commands/migration-new.ts +260 -0
  116. package/src/commands/migration-plan.ts +519 -0
  117. package/src/commands/migration-ref.ts +305 -0
  118. package/src/commands/migration-show.ts +246 -0
  119. package/src/commands/migration-status.ts +864 -0
  120. package/src/commands/migration-verify.ts +180 -0
  121. package/src/config-loader.ts +13 -3
  122. package/src/control-api/client.ts +424 -72
  123. package/src/control-api/contract-enrichment.ts +119 -0
  124. package/src/control-api/errors.ts +9 -0
  125. package/src/control-api/operations/contract-emit.ts +174 -0
  126. package/src/control-api/operations/db-init.ts +53 -49
  127. package/src/control-api/operations/db-update.ts +220 -0
  128. package/src/control-api/operations/extract-operation-statements.ts +14 -0
  129. package/src/control-api/operations/extract-sql-ddl.ts +47 -0
  130. package/src/control-api/operations/migration-apply.ts +191 -0
  131. package/src/control-api/operations/migration-helpers.ts +49 -0
  132. package/src/control-api/types.ts +388 -18
  133. package/src/exports/config-types.ts +4 -3
  134. package/src/exports/control-api.ts +21 -2
  135. package/src/load-ts-contract.ts +30 -19
  136. package/src/utils/cli-errors.ts +14 -8
  137. package/src/utils/command-helpers.ts +302 -3
  138. package/src/utils/formatters/emit.ts +67 -0
  139. package/src/utils/formatters/errors.ts +82 -0
  140. package/src/utils/formatters/graph-migration-mapper.ts +240 -0
  141. package/src/utils/formatters/graph-render.ts +1323 -0
  142. package/src/utils/formatters/graph-types.ts +120 -0
  143. package/src/utils/formatters/help.ts +380 -0
  144. package/src/utils/formatters/helpers.ts +28 -0
  145. package/src/utils/formatters/migrations.ts +346 -0
  146. package/src/utils/formatters/styled.ts +212 -0
  147. package/src/utils/formatters/verify.ts +621 -0
  148. package/src/utils/framework-components.ts +13 -10
  149. package/src/utils/global-flags.ts +41 -23
  150. package/src/utils/migration-command-scaffold.ts +184 -0
  151. package/src/utils/migration-types.ts +12 -0
  152. package/src/utils/progress-adapter.ts +18 -29
  153. package/src/utils/result-handler.ts +12 -13
  154. package/src/utils/shutdown.ts +92 -0
  155. package/src/utils/suggest-command.ts +31 -0
  156. package/src/utils/terminal-ui.ts +276 -0
  157. package/dist/chunk-5MPKZYVI.js +0 -47
  158. package/dist/chunk-5MPKZYVI.js.map +0 -1
  159. package/dist/chunk-6EPKRATC.js +0 -91
  160. package/dist/chunk-6EPKRATC.js.map +0 -1
  161. package/dist/chunk-74IELXRA.js +0 -371
  162. package/dist/chunk-74IELXRA.js.map +0 -1
  163. package/dist/chunk-HWYQOCAJ.js +0 -47
  164. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  165. package/dist/chunk-U6QI3AZ3.js +0 -133
  166. package/dist/chunk-U6QI3AZ3.js.map +0 -1
  167. package/dist/chunk-VI2YETW7.js +0 -38
  168. package/dist/chunk-VI2YETW7.js.map +0 -1
  169. package/dist/chunk-ZG5T6OB5.js +0 -923
  170. package/dist/chunk-ZG5T6OB5.js.map +0 -1
  171. package/dist/cli.d.ts +0 -2
  172. package/dist/cli.d.ts.map +0 -1
  173. package/dist/cli.js.map +0 -1
  174. package/dist/commands/contract-emit.d.ts +0 -3
  175. package/dist/commands/contract-emit.d.ts.map +0 -1
  176. package/dist/commands/contract-emit.js +0 -11
  177. package/dist/commands/contract-emit.js.map +0 -1
  178. package/dist/commands/db-init.d.ts +0 -3
  179. package/dist/commands/db-init.d.ts.map +0 -1
  180. package/dist/commands/db-init.js +0 -302
  181. package/dist/commands/db-init.js.map +0 -1
  182. package/dist/commands/db-introspect.d.ts +0 -3
  183. package/dist/commands/db-introspect.d.ts.map +0 -1
  184. package/dist/commands/db-introspect.js +0 -185
  185. package/dist/commands/db-introspect.js.map +0 -1
  186. package/dist/commands/db-schema-verify.d.ts +0 -3
  187. package/dist/commands/db-schema-verify.d.ts.map +0 -1
  188. package/dist/commands/db-schema-verify.js +0 -163
  189. package/dist/commands/db-schema-verify.js.map +0 -1
  190. package/dist/commands/db-sign.d.ts +0 -3
  191. package/dist/commands/db-sign.d.ts.map +0 -1
  192. package/dist/commands/db-sign.js +0 -198
  193. package/dist/commands/db-sign.js.map +0 -1
  194. package/dist/commands/db-verify.d.ts +0 -3
  195. package/dist/commands/db-verify.d.ts.map +0 -1
  196. package/dist/commands/db-verify.js +0 -172
  197. package/dist/commands/db-verify.js.map +0 -1
  198. package/dist/config-loader.d.ts.map +0 -1
  199. package/dist/config-loader.js +0 -7
  200. package/dist/config-loader.js.map +0 -1
  201. package/dist/control-api/client.d.ts +0 -13
  202. package/dist/control-api/client.d.ts.map +0 -1
  203. package/dist/control-api/operations/db-init.d.ts +0 -29
  204. package/dist/control-api/operations/db-init.d.ts.map +0 -1
  205. package/dist/control-api/types.d.ts +0 -256
  206. package/dist/control-api/types.d.ts.map +0 -1
  207. package/dist/exports/config-types.d.ts +0 -3
  208. package/dist/exports/config-types.d.ts.map +0 -1
  209. package/dist/exports/config-types.js +0 -6
  210. package/dist/exports/config-types.js.map +0 -1
  211. package/dist/exports/control-api.d.ts +0 -13
  212. package/dist/exports/control-api.d.ts.map +0 -1
  213. package/dist/exports/control-api.js +0 -9
  214. package/dist/exports/control-api.js.map +0 -1
  215. package/dist/exports/index.d.ts +0 -4
  216. package/dist/exports/index.d.ts.map +0 -1
  217. package/dist/exports/index.js +0 -177
  218. package/dist/exports/index.js.map +0 -1
  219. package/dist/load-ts-contract.d.ts.map +0 -1
  220. package/dist/utils/action.d.ts +0 -16
  221. package/dist/utils/action.d.ts.map +0 -1
  222. package/dist/utils/cli-errors.d.ts +0 -7
  223. package/dist/utils/cli-errors.d.ts.map +0 -1
  224. package/dist/utils/command-helpers.d.ts +0 -12
  225. package/dist/utils/command-helpers.d.ts.map +0 -1
  226. package/dist/utils/framework-components.d.ts +0 -70
  227. package/dist/utils/framework-components.d.ts.map +0 -1
  228. package/dist/utils/global-flags.d.ts +0 -25
  229. package/dist/utils/global-flags.d.ts.map +0 -1
  230. package/dist/utils/output.d.ts +0 -142
  231. package/dist/utils/output.d.ts.map +0 -1
  232. package/dist/utils/progress-adapter.d.ts +0 -26
  233. package/dist/utils/progress-adapter.d.ts.map +0 -1
  234. package/dist/utils/result-handler.d.ts +0 -15
  235. package/dist/utils/result-handler.d.ts.map +0 -1
  236. package/dist/utils/spinner.d.ts +0 -29
  237. package/dist/utils/spinner.d.ts.map +0 -1
  238. package/src/commands/db-introspect.ts +0 -254
  239. package/src/commands/db-schema-verify.ts +0 -231
  240. package/src/utils/action.ts +0 -43
  241. package/src/utils/output.ts +0 -1471
  242. package/src/utils/spinner.ts +0 -67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/cli",
3
- "version": "0.3.0-dev.16",
3
+ "version": "0.3.0-dev.162",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -11,83 +11,129 @@
11
11
  "prisma-next": "./dist/cli.js"
12
12
  },
13
13
  "dependencies": {
14
+ "@clack/prompts": "^1.1.0",
15
+ "@dagrejs/dagre": "^3.0.0",
14
16
  "arktype": "^2.0.0",
15
17
  "c12": "^3.3.2",
18
+ "closest-match": "^1.3.3",
16
19
  "colorette": "^2.0.20",
17
20
  "commander": "^12.0.0",
18
- "esbuild": "^0.19.0",
19
- "ora": "^8.1.1",
20
- "string-width": "^7.2.0",
21
+ "esbuild": "^0.25.11",
22
+ "pathe": "^2.0.3",
23
+ "string-width": "^8.2.0",
21
24
  "strip-ansi": "^7.1.2",
22
- "wrap-ansi": "^9.0.2",
23
- "@prisma-next/contract": "0.3.0-dev.16",
24
- "@prisma-next/core-control-plane": "0.3.0-dev.16",
25
- "@prisma-next/emitter": "0.3.0-dev.16",
26
- "@prisma-next/utils": "0.3.0-dev.16"
25
+ "wrap-ansi": "^10.0.0",
26
+ "@prisma-next/config": "0.3.0-dev.162",
27
+ "@prisma-next/contract": "0.3.0-dev.162",
28
+ "@prisma-next/emitter": "0.3.0-dev.162",
29
+ "@prisma-next/errors": "0.3.0-dev.162",
30
+ "@prisma-next/framework-components": "0.3.0-dev.162",
31
+ "@prisma-next/migration-tools": "0.3.0-dev.162",
32
+ "@prisma-next/psl-printer": "0.3.0-dev.162",
33
+ "@prisma-next/utils": "0.3.0-dev.162"
27
34
  },
28
35
  "devDependencies": {
29
36
  "@types/node": "24.10.4",
30
- "@vitest/coverage-v8": "4.0.16",
31
- "tsup": "8.5.1",
37
+ "tsdown": "0.18.4",
32
38
  "typescript": "5.9.3",
33
- "vitest": "4.0.16",
34
- "@prisma-next/sql-contract": "0.3.0-dev.16",
35
- "@prisma-next/sql-contract-emitter": "0.3.0-dev.16",
36
- "@prisma-next/sql-contract-ts": "0.3.0-dev.16",
37
- "@prisma-next/sql-operations": "0.3.0-dev.16",
38
- "@prisma-next/sql-runtime": "0.3.0-dev.16",
39
- "@prisma-next/test-utils": "0.0.1"
39
+ "vitest": "4.0.17",
40
+ "@prisma-next/sql-contract": "0.3.0-dev.162",
41
+ "@prisma-next/sql-contract-emitter": "0.3.0-dev.162",
42
+ "@prisma-next/sql-operations": "0.3.0-dev.162",
43
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.162",
44
+ "@prisma-next/sql-runtime": "0.3.0-dev.162",
45
+ "@prisma-next/test-utils": "0.0.1",
46
+ "@prisma-next/tsdown": "0.0.0",
47
+ "@prisma-next/tsconfig": "0.0.0"
40
48
  },
41
49
  "exports": {
42
50
  ".": {
43
- "types": "./dist/exports/index.d.ts",
44
- "import": "./dist/exports/index.js"
51
+ "types": "./dist/exports/index.d.mts",
52
+ "import": "./dist/exports/index.mjs"
45
53
  },
46
54
  "./config-types": {
47
- "types": "./dist/exports/config-types.d.ts",
48
- "import": "./dist/exports/config-types.js"
55
+ "types": "./dist/exports/config-types.d.mts",
56
+ "import": "./dist/exports/config-types.mjs"
49
57
  },
50
58
  "./commands/db-init": {
51
- "types": "./dist/commands/db-init.d.ts",
52
- "import": "./dist/commands/db-init.js"
59
+ "types": "./dist/commands/db-init.d.mts",
60
+ "import": "./dist/commands/db-init.mjs"
53
61
  },
54
- "./commands/db-introspect": {
55
- "types": "./dist/commands/db-introspect.d.ts",
56
- "import": "./dist/commands/db-introspect.js"
62
+ "./commands/db-update": {
63
+ "types": "./dist/commands/db-update.d.mts",
64
+ "import": "./dist/commands/db-update.mjs"
57
65
  },
58
- "./commands/db-schema-verify": {
59
- "types": "./dist/commands/db-schema-verify.d.ts",
60
- "import": "./dist/commands/db-schema-verify.js"
66
+ "./commands/db-schema": {
67
+ "types": "./dist/commands/db-schema.d.mts",
68
+ "import": "./dist/commands/db-schema.mjs"
61
69
  },
62
70
  "./commands/db-sign": {
63
- "types": "./dist/commands/db-sign.d.ts",
64
- "import": "./dist/commands/db-sign.js"
71
+ "types": "./dist/commands/db-sign.d.mts",
72
+ "import": "./dist/commands/db-sign.mjs"
65
73
  },
66
74
  "./commands/db-verify": {
67
- "types": "./dist/commands/db-verify.d.ts",
68
- "import": "./dist/commands/db-verify.js"
75
+ "types": "./dist/commands/db-verify.d.mts",
76
+ "import": "./dist/commands/db-verify.mjs"
69
77
  },
70
78
  "./commands/contract-emit": {
71
- "types": "./dist/commands/contract-emit.d.ts",
72
- "import": "./dist/commands/contract-emit.js"
79
+ "types": "./dist/commands/contract-emit.d.mts",
80
+ "import": "./dist/commands/contract-emit.mjs"
81
+ },
82
+ "./commands/contract-infer": {
83
+ "types": "./dist/commands/contract-infer.d.mts",
84
+ "import": "./dist/commands/contract-infer.mjs"
85
+ },
86
+ "./commands/migration-new": {
87
+ "types": "./dist/commands/migration-new.d.mts",
88
+ "import": "./dist/commands/migration-new.mjs"
89
+ },
90
+ "./commands/migration-plan": {
91
+ "types": "./dist/commands/migration-plan.d.mts",
92
+ "import": "./dist/commands/migration-plan.mjs"
93
+ },
94
+ "./commands/migration-show": {
95
+ "types": "./dist/commands/migration-show.d.mts",
96
+ "import": "./dist/commands/migration-show.mjs"
97
+ },
98
+ "./commands/migration-status": {
99
+ "types": "./dist/commands/migration-status.d.mts",
100
+ "import": "./dist/commands/migration-status.mjs"
101
+ },
102
+ "./commands/migration-verify": {
103
+ "types": "./dist/commands/migration-verify.d.mts",
104
+ "import": "./dist/commands/migration-verify.mjs"
105
+ },
106
+ "./commands/migration-apply": {
107
+ "types": "./dist/commands/migration-apply.d.mts",
108
+ "import": "./dist/commands/migration-apply.mjs"
109
+ },
110
+ "./commands/migration-ref": {
111
+ "types": "./dist/commands/migration-ref.d.mts",
112
+ "import": "./dist/commands/migration-ref.mjs"
73
113
  },
74
114
  "./config-loader": {
75
- "types": "./dist/config-loader.d.ts",
76
- "import": "./dist/config-loader.js"
115
+ "types": "./dist/config-loader.d.mts",
116
+ "import": "./dist/config-loader.mjs"
77
117
  },
78
118
  "./control-api": {
79
- "types": "./dist/exports/control-api.d.ts",
80
- "import": "./dist/exports/control-api.js"
119
+ "types": "./dist/exports/control-api.d.mts",
120
+ "import": "./dist/exports/control-api.mjs"
81
121
  }
82
122
  },
123
+ "repository": {
124
+ "type": "git",
125
+ "url": "https://github.com/prisma/prisma-next.git",
126
+ "directory": "packages/1-framework/3-tooling/cli"
127
+ },
83
128
  "scripts": {
84
- "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
129
+ "build": "tsdown && node ./scripts/write-cli-js-compat.mjs",
85
130
  "test": "vitest run",
86
131
  "test:coverage": "vitest run --coverage",
87
132
  "typecheck": "tsc --project tsconfig.json --noEmit",
88
133
  "lint": "biome check . --error-on-warnings",
89
134
  "lint:fix": "biome check --write .",
90
135
  "lint:fix:unsafe": "biome check --write --unsafe .",
91
- "clean": "node ../../../../scripts/clean.mjs"
136
+ "record": "tsx scripts/record.ts",
137
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
92
138
  }
93
139
  }
package/src/cli.ts CHANGED
@@ -1,13 +1,40 @@
1
1
  import { Command } from 'commander';
2
2
  import { createContractEmitCommand } from './commands/contract-emit';
3
+ import { createContractInferCommand } from './commands/contract-infer';
4
+ import { installShutdownHandlers } from './utils/shutdown';
5
+
6
+ // Install SIGINT/SIGTERM handlers before anything else
7
+ installShutdownHandlers();
8
+
3
9
  import { createDbInitCommand } from './commands/db-init';
4
- import { createDbIntrospectCommand } from './commands/db-introspect';
5
- import { createDbSchemaVerifyCommand } from './commands/db-schema-verify';
10
+ import { createDbSchemaCommand } from './commands/db-schema';
6
11
  import { createDbSignCommand } from './commands/db-sign';
12
+ import { createDbUpdateCommand } from './commands/db-update';
7
13
  import { createDbVerifyCommand } from './commands/db-verify';
14
+ import { createMigrationApplyCommand } from './commands/migration-apply';
15
+ import { createMigrationNewCommand } from './commands/migration-new';
16
+ import { createMigrationPlanCommand } from './commands/migration-plan';
17
+ import { createMigrationRefCommand } from './commands/migration-ref';
18
+ import { createMigrationShowCommand } from './commands/migration-show';
19
+ import { createMigrationStatusCommand } from './commands/migration-status';
20
+ import { createMigrationVerifyCommand } from './commands/migration-verify';
8
21
  import { setCommandDescriptions } from './utils/command-helpers';
22
+ import { formatCommandHelp, formatRootHelp } from './utils/formatters/help';
9
23
  import { parseGlobalFlags } from './utils/global-flags';
10
- import { formatCommandHelp, formatRootHelp } from './utils/output';
24
+ import { suggestCommands } from './utils/suggest-command';
25
+
26
+ /**
27
+ * Formats the "Did you mean ...?" hint for an unknown command.
28
+ */
29
+ function formatSuggestion(input: string, candidates: readonly string[]): string {
30
+ const suggestions = suggestCommands(
31
+ input,
32
+ candidates.map((c) => c),
33
+ );
34
+ if (suggestions.length === 0) return '';
35
+ if (suggestions.length === 1) return `\nDid you mean ${suggestions[0]}?\n`;
36
+ return `\nDid you mean one of these?\n${suggestions.map((s) => ` ${s}`).join('\n')}\n`;
37
+ }
11
38
 
12
39
  const program = new Command();
13
40
 
@@ -43,14 +70,11 @@ program.configureHelp({
43
70
  // Commands handle structured errors themselves via process.exit()
44
71
  program.exitOverride((err) => {
45
72
  if (err) {
46
- // Help requests are not errors - allow Commander to output help and exit normally
47
- // Commander throws errors with codes like 'commander.help', 'commander.helpDisplayed', or 'outputHelp'
48
73
  const errorCode = (err as { code?: string }).code;
49
74
  const errorMessage = String(err.message ?? '');
50
75
  const errorName = err.name ?? '';
51
76
 
52
- // Check for unknown command errors first (before other checks)
53
- // Commander.js uses code 'commander.unknownCommand' or error message contains 'unknown command'
77
+ // Unknown command/argument exit 2 (CLI usage error)
54
78
  const isUnknownCommandError =
55
79
  errorCode === 'commander.unknownCommand' ||
56
80
  errorCode === 'commander.unknownArgument' ||
@@ -58,40 +82,34 @@ program.exitOverride((err) => {
58
82
  (errorMessage.includes('unknown command') || errorMessage.includes('unknown argument')));
59
83
  if (isUnknownCommandError) {
60
84
  const flags = parseGlobalFlags({});
61
- // Extract the command/subcommand name from the error message
62
- // Error message format: "unknown command 'command-name'"
63
85
  const match = errorMessage.match(/unknown command ['"]([^'"]+)['"]/);
64
86
  const commandName = match ? match[1] : process.argv[3] || process.argv[2] || 'unknown';
65
87
 
66
- // Determine which command context we're in
67
- // Check if the first argument is a recognized parent command
68
88
  const firstArg = process.argv[2];
69
89
  const parentCommand = firstArg
70
90
  ? program.commands.find((cmd) => cmd.name() === firstArg)
71
91
  : undefined;
72
92
 
73
93
  if (parentCommand && commandName !== firstArg) {
74
- // Unrecognized subcommand - show parent command help
75
- // eslint-disable-next-line no-console
76
- console.error(`Unknown command: ${commandName}`);
77
- // eslint-disable-next-line no-console
78
- console.error('');
94
+ const subNames = parentCommand.commands.map((c) => c.name());
95
+ process.stderr.write(
96
+ `Unknown command: ${commandName}${formatSuggestion(commandName!, subNames)}\n`,
97
+ );
79
98
  const helpText = formatCommandHelp({ command: parentCommand, flags });
80
- // eslint-disable-next-line no-console
81
- console.log(helpText);
99
+ process.stderr.write(`${helpText}\n`);
82
100
  } else {
83
- // Unrecognized top-level command - show root help
84
- // eslint-disable-next-line no-console
85
- console.error(`Unknown command: ${commandName}`);
86
- // eslint-disable-next-line no-console
87
- console.error('');
101
+ const topNames = program.commands.map((c) => c.name());
102
+ process.stderr.write(
103
+ `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\n`,
104
+ );
88
105
  const helpText = formatRootHelp({ program, flags });
89
- // eslint-disable-next-line no-console
90
- console.log(helpText);
106
+ process.stderr.write(`${helpText}\n`);
91
107
  }
92
- process.exit(1);
108
+ process.exit(2);
93
109
  return;
94
110
  }
111
+
112
+ // Help requests → exit 0
95
113
  const isHelpError =
96
114
  errorCode === 'commander.help' ||
97
115
  errorCode === 'commander.helpDisplayed' ||
@@ -103,25 +121,22 @@ program.exitOverride((err) => {
103
121
  process.exit(0);
104
122
  return;
105
123
  }
106
- // Missing required arguments/subcommands - show help and exit with 0
107
- // Commander throws errors with code 'commander.missingArgument' or 'commander.missingMandatoryOptionValue'
108
- // or when a command with subcommands is called without a subcommand
124
+
125
+ // Missing required arguments exit 2 (CLI usage error)
109
126
  const isMissingArgumentError =
110
127
  errorCode === 'commander.missingArgument' ||
111
128
  errorCode === 'commander.missingMandatoryOptionValue' ||
112
129
  (errorName === 'CommanderError' &&
113
130
  (errorMessage.includes('missing') || errorMessage.includes('required')));
114
131
  if (isMissingArgumentError) {
115
- // Help was already displayed by Commander.js, just exit with 0
116
- process.exit(0);
132
+ process.exit(2);
117
133
  return;
118
134
  }
119
- // Unhandled error - fail fast with exit code 1
120
- // eslint-disable-next-line no-console
121
- console.error(`Unhandled error: ${err.message}`);
135
+
136
+ // Unhandled error → exit 1
137
+ process.stderr.write(`Unhandled error: ${err.message}\n`);
122
138
  if (err.stack) {
123
- // eslint-disable-next-line no-console
124
- console.error(err.stack);
139
+ process.stderr.write(`${err.stack}\n`);
125
140
  }
126
141
  process.exit(1);
127
142
  }
@@ -148,6 +163,10 @@ contractCommand.configureHelp({
148
163
  const contractEmitCommand = createContractEmitCommand();
149
164
  contractCommand.addCommand(contractEmitCommand);
150
165
 
166
+ // Add infer subcommand to contract
167
+ const contractInferCommand = createContractInferCommand();
168
+ contractCommand.addCommand(contractInferCommand);
169
+
151
170
  // Register contract command
152
171
  program.addCommand(contractCommand);
153
172
 
@@ -175,13 +194,13 @@ dbCommand.addCommand(dbVerifyCommand);
175
194
  const dbInitCommand = createDbInitCommand();
176
195
  dbCommand.addCommand(dbInitCommand);
177
196
 
178
- // Add introspect subcommand to db
179
- const dbIntrospectCommand = createDbIntrospectCommand();
180
- dbCommand.addCommand(dbIntrospectCommand);
197
+ // Add update subcommand to db
198
+ const dbUpdateCommand = createDbUpdateCommand();
199
+ dbCommand.addCommand(dbUpdateCommand);
181
200
 
182
- // Add schema-verify subcommand to db
183
- const dbSchemaVerifyCommand = createDbSchemaVerifyCommand();
184
- dbCommand.addCommand(dbSchemaVerifyCommand);
201
+ // Add schema subcommand to db
202
+ const dbSchemaCommand = createDbSchemaCommand();
203
+ dbCommand.addCommand(dbSchemaCommand);
185
204
 
186
205
  // Add sign subcommand to db
187
206
  const dbSignCommand = createDbSignCommand();
@@ -190,6 +209,45 @@ dbCommand.addCommand(dbSignCommand);
190
209
  // Register db command
191
210
  program.addCommand(dbCommand);
192
211
 
212
+ // Register migration subcommand
213
+ const migrationCommand = new Command('migration');
214
+ setCommandDescriptions(
215
+ migrationCommand,
216
+ 'On-disk migration management commands',
217
+ 'Plan, apply, verify, and scaffold on-disk migration packages. Migrations are\n' +
218
+ 'contract-to-contract edges stored as versioned directories under migrations/.',
219
+ );
220
+ migrationCommand.configureHelp({
221
+ formatHelp: (cmd) => {
222
+ const flags = parseGlobalFlags({});
223
+ return formatCommandHelp({ command: cmd, flags });
224
+ },
225
+ subcommandDescription: () => '',
226
+ });
227
+
228
+ const migrationPlanCommand = createMigrationPlanCommand();
229
+ migrationCommand.addCommand(migrationPlanCommand);
230
+
231
+ const migrationNewCommand = createMigrationNewCommand();
232
+ migrationCommand.addCommand(migrationNewCommand);
233
+
234
+ const migrationShowCommand = createMigrationShowCommand();
235
+ migrationCommand.addCommand(migrationShowCommand);
236
+
237
+ const migrationStatusCommand = createMigrationStatusCommand();
238
+ migrationCommand.addCommand(migrationStatusCommand);
239
+
240
+ const migrationVerifyCommand = createMigrationVerifyCommand();
241
+ migrationCommand.addCommand(migrationVerifyCommand);
242
+
243
+ const migrationApplyCommand = createMigrationApplyCommand();
244
+ migrationCommand.addCommand(migrationApplyCommand);
245
+
246
+ const migrationRefCommand = createMigrationRefCommand();
247
+ migrationCommand.addCommand(migrationRefCommand);
248
+
249
+ program.addCommand(migrationCommand);
250
+
193
251
  // Create help command
194
252
  const helpCommand = new Command('help')
195
253
  .description('Show usage instructions')
@@ -202,8 +260,8 @@ const helpCommand = new Command('help')
202
260
  .action(() => {
203
261
  const flags = parseGlobalFlags({});
204
262
  const helpText = formatRootHelp({ program, flags });
205
- // eslint-disable-next-line no-console
206
- console.log(helpText);
263
+ // Help is decoration → stderr
264
+ process.stderr.write(`${helpText}\n`);
207
265
  process.exit(0);
208
266
  });
209
267
 
@@ -213,8 +271,7 @@ program.addCommand(helpCommand);
213
271
  program.action(() => {
214
272
  const flags = parseGlobalFlags({});
215
273
  const helpText = formatRootHelp({ program, flags });
216
- // eslint-disable-next-line no-console
217
- console.log(helpText);
274
+ process.stderr.write(`${helpText}\n`);
218
275
  process.exit(0);
219
276
  });
220
277
 
@@ -225,8 +282,8 @@ if (args.length > 0) {
225
282
  const commandName = args[0];
226
283
  // Handle version option explicitly since we suppress default output
227
284
  if (commandName === '--version' || commandName === '-V') {
228
- // eslint-disable-next-line no-console
229
- console.log(program.version());
285
+ // Version is data → stdout
286
+ process.stdout.write(`${program.version()}\n`);
230
287
  process.exit(0);
231
288
  }
232
289
  // Skip command check for global options like --help, -h
@@ -236,22 +293,20 @@ if (args.length > 0) {
236
293
  const command = program.commands.find((cmd) => cmd.name() === commandName);
237
294
 
238
295
  if (!command) {
239
- // Unrecognized command - show error message and usage
296
+ // Unrecognized command exit 2 (CLI usage error)
240
297
  const flags = parseGlobalFlags({});
241
- // eslint-disable-next-line no-console
242
- console.error(`Unknown command: ${commandName}`);
243
- // eslint-disable-next-line no-console
244
- console.error('');
298
+ const topNames = program.commands.map((c) => c.name());
299
+ process.stderr.write(
300
+ `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\n`,
301
+ );
245
302
  const helpText = formatRootHelp({ program, flags });
246
- // eslint-disable-next-line no-console
247
- console.log(helpText);
248
- process.exit(1);
303
+ process.stderr.write(`${helpText}\n`);
304
+ process.exit(2);
249
305
  } else if (command.commands.length > 0 && args.length === 1) {
250
306
  // Parent command called with no subcommand - show help and exit with 0
251
307
  const flags = parseGlobalFlags({});
252
308
  const helpText = formatCommandHelp({ command, flags });
253
- // eslint-disable-next-line no-console
254
- console.log(helpText);
309
+ process.stderr.write(`${helpText}\n`);
255
310
  process.exit(0);
256
311
  }
257
312
  }