@prisma-next/cli 0.3.0-pr.99.5 → 0.3.0

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 (257) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +381 -128
  3. package/dist/agent-skill-mongo.md +106 -0
  4. package/dist/agent-skill-postgres.md +106 -0
  5. package/dist/cli-errors-BDCYR5ap.mjs +4 -0
  6. package/dist/cli-errors-DStABy9d.d.mts +3 -0
  7. package/dist/cli.d.mts +1 -0
  8. package/dist/cli.js +1 -2910
  9. package/dist/cli.mjs +261 -0
  10. package/dist/cli.mjs.map +1 -0
  11. package/dist/client-DiUkJAeN.mjs +987 -0
  12. package/dist/client-DiUkJAeN.mjs.map +1 -0
  13. package/dist/commands/contract-emit.d.mts +7 -0
  14. package/dist/commands/contract-emit.d.mts.map +1 -0
  15. package/dist/commands/contract-emit.mjs +9 -0
  16. package/dist/commands/contract-infer.d.mts +7 -0
  17. package/dist/commands/contract-infer.d.mts.map +1 -0
  18. package/dist/commands/contract-infer.mjs +10 -0
  19. package/dist/commands/db-init.d.mts +7 -0
  20. package/dist/commands/db-init.d.mts.map +1 -0
  21. package/dist/commands/db-init.mjs +126 -0
  22. package/dist/commands/db-init.mjs.map +1 -0
  23. package/dist/commands/db-schema.d.mts +7 -0
  24. package/dist/commands/db-schema.d.mts.map +1 -0
  25. package/dist/commands/db-schema.mjs +56 -0
  26. package/dist/commands/db-schema.mjs.map +1 -0
  27. package/dist/commands/db-sign.d.mts +7 -0
  28. package/dist/commands/db-sign.d.mts.map +1 -0
  29. package/dist/commands/db-sign.mjs +137 -0
  30. package/dist/commands/db-sign.mjs.map +1 -0
  31. package/dist/commands/db-update.d.mts +7 -0
  32. package/dist/commands/db-update.d.mts.map +1 -0
  33. package/dist/commands/db-update.mjs +123 -0
  34. package/dist/commands/db-update.mjs.map +1 -0
  35. package/dist/commands/db-verify.d.mts +7 -0
  36. package/dist/commands/db-verify.d.mts.map +1 -0
  37. package/dist/commands/db-verify.mjs +323 -0
  38. package/dist/commands/db-verify.mjs.map +1 -0
  39. package/dist/commands/migration-apply.d.mts +36 -0
  40. package/dist/commands/migration-apply.d.mts.map +1 -0
  41. package/dist/commands/migration-apply.mjs +245 -0
  42. package/dist/commands/migration-apply.mjs.map +1 -0
  43. package/dist/commands/migration-new.d.mts +8 -0
  44. package/dist/commands/migration-new.d.mts.map +1 -0
  45. package/dist/commands/migration-new.mjs +152 -0
  46. package/dist/commands/migration-new.mjs.map +1 -0
  47. package/dist/commands/migration-plan.d.mts +47 -0
  48. package/dist/commands/migration-plan.d.mts.map +1 -0
  49. package/dist/commands/migration-plan.mjs +313 -0
  50. package/dist/commands/migration-plan.mjs.map +1 -0
  51. package/dist/commands/migration-ref.d.mts +43 -0
  52. package/dist/commands/migration-ref.d.mts.map +1 -0
  53. package/dist/commands/migration-ref.mjs +195 -0
  54. package/dist/commands/migration-ref.mjs.map +1 -0
  55. package/dist/commands/migration-show.d.mts +28 -0
  56. package/dist/commands/migration-show.d.mts.map +1 -0
  57. package/dist/commands/migration-show.mjs +140 -0
  58. package/dist/commands/migration-show.mjs.map +1 -0
  59. package/dist/commands/migration-status.d.mts +86 -0
  60. package/dist/commands/migration-status.d.mts.map +1 -0
  61. package/dist/commands/migration-status.mjs +9 -0
  62. package/dist/commands/migration-verify.d.mts +16 -0
  63. package/dist/commands/migration-verify.d.mts.map +1 -0
  64. package/dist/commands/migration-verify.mjs +110 -0
  65. package/dist/commands/migration-verify.mjs.map +1 -0
  66. package/dist/config-loader-C4VXKl8f.mjs +43 -0
  67. package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
  68. package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
  69. package/dist/config-loader.d.mts.map +1 -0
  70. package/dist/config-loader.mjs +3 -0
  71. package/dist/contract-emit-D2wDXfyo.mjs +191 -0
  72. package/dist/contract-emit-D2wDXfyo.mjs.map +1 -0
  73. package/dist/contract-emit-Zm_sd1wQ.mjs +112 -0
  74. package/dist/contract-emit-Zm_sd1wQ.mjs.map +1 -0
  75. package/dist/contract-emit-kN-IkKTE.mjs +6 -0
  76. package/dist/contract-enrichment-CGW6mm-E.mjs +79 -0
  77. package/dist/contract-enrichment-CGW6mm-E.mjs.map +1 -0
  78. package/dist/contract-infer-DozZT511.mjs +90 -0
  79. package/dist/contract-infer-DozZT511.mjs.map +1 -0
  80. package/dist/exports/config-types.d.mts +2 -0
  81. package/dist/exports/config-types.mjs +3 -0
  82. package/dist/exports/control-api.d.mts +624 -0
  83. package/dist/exports/control-api.d.mts.map +1 -0
  84. package/dist/exports/control-api.mjs +8 -0
  85. package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
  86. package/dist/exports/index.d.mts.map +1 -0
  87. package/dist/exports/index.mjs +142 -0
  88. package/dist/exports/index.mjs.map +1 -0
  89. package/dist/extract-operation-statements-DZUJNmL3.mjs +13 -0
  90. package/dist/extract-operation-statements-DZUJNmL3.mjs.map +1 -0
  91. package/dist/extract-sql-ddl-DDMX-9mz.mjs +26 -0
  92. package/dist/extract-sql-ddl-DDMX-9mz.mjs.map +1 -0
  93. package/dist/framework-components-BAsliT4V.mjs +59 -0
  94. package/dist/framework-components-BAsliT4V.mjs.map +1 -0
  95. package/dist/init-6Pvm_esG.mjs +430 -0
  96. package/dist/init-6Pvm_esG.mjs.map +1 -0
  97. package/dist/inspect-live-schema-BYnhztxZ.mjs +91 -0
  98. package/dist/inspect-live-schema-BYnhztxZ.mjs.map +1 -0
  99. package/dist/migration-command-scaffold-CntCcntR.mjs +105 -0
  100. package/dist/migration-command-scaffold-CntCcntR.mjs.map +1 -0
  101. package/dist/migration-status-CJANY4yr.mjs +1583 -0
  102. package/dist/migration-status-CJANY4yr.mjs.map +1 -0
  103. package/dist/migrations-DTZBYXm1.mjs +173 -0
  104. package/dist/migrations-DTZBYXm1.mjs.map +1 -0
  105. package/dist/progress-adapter-B-YvmcDu.mjs +43 -0
  106. package/dist/progress-adapter-B-YvmcDu.mjs.map +1 -0
  107. package/dist/quick-reference-mongo.md +93 -0
  108. package/dist/quick-reference-postgres.md +91 -0
  109. package/dist/result-handler-oK_vA-Fn.mjs +697 -0
  110. package/dist/result-handler-oK_vA-Fn.mjs.map +1 -0
  111. package/dist/terminal-ui-C5k88MmW.mjs +274 -0
  112. package/dist/terminal-ui-C5k88MmW.mjs.map +1 -0
  113. package/dist/validate-contract-deps-esa-VQ0h.mjs +37 -0
  114. package/dist/validate-contract-deps-esa-VQ0h.mjs.map +1 -0
  115. package/dist/verify-DlFQ2FOw.mjs +385 -0
  116. package/dist/verify-DlFQ2FOw.mjs.map +1 -0
  117. package/package.json +87 -40
  118. package/src/cli.ts +118 -58
  119. package/src/commands/contract-emit.ts +101 -78
  120. package/src/commands/contract-infer-paths.ts +32 -0
  121. package/src/commands/contract-infer.ts +143 -0
  122. package/src/commands/db-init.ts +97 -219
  123. package/src/commands/db-schema.ts +77 -0
  124. package/src/commands/db-sign.ts +46 -73
  125. package/src/commands/db-update.ts +236 -0
  126. package/src/commands/db-verify.ts +409 -119
  127. package/src/commands/init/detect-package-manager.ts +47 -0
  128. package/src/commands/init/index.ts +21 -0
  129. package/src/commands/init/init.ts +203 -0
  130. package/src/commands/init/templates/agent-skill-mongo.md +106 -0
  131. package/src/commands/init/templates/agent-skill-postgres.md +106 -0
  132. package/src/commands/init/templates/agent-skill.ts +19 -0
  133. package/src/commands/init/templates/code-templates.ts +168 -0
  134. package/src/commands/init/templates/quick-reference-mongo.md +93 -0
  135. package/src/commands/init/templates/quick-reference-postgres.md +91 -0
  136. package/src/commands/init/templates/quick-reference.ts +19 -0
  137. package/src/commands/init/templates/render.ts +20 -0
  138. package/src/commands/init/templates/tsconfig.ts +35 -0
  139. package/src/commands/inspect-live-schema.ts +170 -0
  140. package/src/commands/migration-apply.ts +427 -0
  141. package/src/commands/migration-new.ts +260 -0
  142. package/src/commands/migration-plan.ts +519 -0
  143. package/src/commands/migration-ref.ts +305 -0
  144. package/src/commands/migration-show.ts +246 -0
  145. package/src/commands/migration-status.ts +864 -0
  146. package/src/commands/migration-verify.ts +180 -0
  147. package/src/config-loader.ts +13 -3
  148. package/src/control-api/client.ts +205 -183
  149. package/src/control-api/contract-enrichment.ts +119 -0
  150. package/src/control-api/errors.ts +9 -0
  151. package/src/control-api/operations/contract-emit.ts +181 -0
  152. package/src/control-api/operations/db-init.ts +53 -49
  153. package/src/control-api/operations/db-update.ts +220 -0
  154. package/src/control-api/operations/extract-operation-statements.ts +14 -0
  155. package/src/control-api/operations/extract-sql-ddl.ts +47 -0
  156. package/src/control-api/operations/migration-apply.ts +191 -0
  157. package/src/control-api/operations/migration-helpers.ts +49 -0
  158. package/src/control-api/types.ts +274 -52
  159. package/src/exports/config-types.ts +4 -3
  160. package/src/exports/control-api.ts +15 -5
  161. package/src/load-ts-contract.ts +30 -19
  162. package/src/utils/cli-errors.ts +14 -8
  163. package/src/utils/command-helpers.ts +302 -3
  164. package/src/utils/formatters/emit.ts +67 -0
  165. package/src/utils/formatters/errors.ts +82 -0
  166. package/src/utils/formatters/graph-migration-mapper.ts +240 -0
  167. package/src/utils/formatters/graph-render.ts +1323 -0
  168. package/src/utils/formatters/graph-types.ts +120 -0
  169. package/src/utils/formatters/help.ts +380 -0
  170. package/src/utils/formatters/helpers.ts +28 -0
  171. package/src/utils/formatters/migrations.ts +346 -0
  172. package/src/utils/formatters/styled.ts +212 -0
  173. package/src/utils/formatters/verify.ts +621 -0
  174. package/src/utils/framework-components.ts +13 -10
  175. package/src/utils/global-flags.ts +41 -23
  176. package/src/utils/migration-command-scaffold.ts +184 -0
  177. package/src/utils/migration-types.ts +12 -0
  178. package/src/utils/progress-adapter.ts +18 -29
  179. package/src/utils/result-handler.ts +12 -13
  180. package/src/utils/shutdown.ts +92 -0
  181. package/src/utils/suggest-command.ts +31 -0
  182. package/src/utils/terminal-ui.ts +276 -0
  183. package/src/utils/validate-contract-deps.ts +49 -0
  184. package/dist/chunk-AGOTG4L3.js +0 -965
  185. package/dist/chunk-AGOTG4L3.js.map +0 -1
  186. package/dist/chunk-HLLI4YL7.js +0 -180
  187. package/dist/chunk-HLLI4YL7.js.map +0 -1
  188. package/dist/chunk-HWYQOCAJ.js +0 -47
  189. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  190. package/dist/chunk-VG2R7DGF.js +0 -735
  191. package/dist/chunk-VG2R7DGF.js.map +0 -1
  192. package/dist/cli.d.ts +0 -2
  193. package/dist/cli.d.ts.map +0 -1
  194. package/dist/cli.js.map +0 -1
  195. package/dist/commands/contract-emit.d.ts +0 -3
  196. package/dist/commands/contract-emit.d.ts.map +0 -1
  197. package/dist/commands/contract-emit.js +0 -10
  198. package/dist/commands/contract-emit.js.map +0 -1
  199. package/dist/commands/db-init.d.ts +0 -3
  200. package/dist/commands/db-init.d.ts.map +0 -1
  201. package/dist/commands/db-init.js +0 -257
  202. package/dist/commands/db-init.js.map +0 -1
  203. package/dist/commands/db-introspect.d.ts +0 -3
  204. package/dist/commands/db-introspect.d.ts.map +0 -1
  205. package/dist/commands/db-introspect.js +0 -155
  206. package/dist/commands/db-introspect.js.map +0 -1
  207. package/dist/commands/db-schema-verify.d.ts +0 -3
  208. package/dist/commands/db-schema-verify.d.ts.map +0 -1
  209. package/dist/commands/db-schema-verify.js +0 -171
  210. package/dist/commands/db-schema-verify.js.map +0 -1
  211. package/dist/commands/db-sign.d.ts +0 -3
  212. package/dist/commands/db-sign.d.ts.map +0 -1
  213. package/dist/commands/db-sign.js +0 -195
  214. package/dist/commands/db-sign.js.map +0 -1
  215. package/dist/commands/db-verify.d.ts +0 -3
  216. package/dist/commands/db-verify.d.ts.map +0 -1
  217. package/dist/commands/db-verify.js +0 -193
  218. package/dist/commands/db-verify.js.map +0 -1
  219. package/dist/config-loader.d.ts.map +0 -1
  220. package/dist/config-loader.js +0 -7
  221. package/dist/config-loader.js.map +0 -1
  222. package/dist/control-api/client.d.ts +0 -13
  223. package/dist/control-api/client.d.ts.map +0 -1
  224. package/dist/control-api/operations/db-init.d.ts +0 -29
  225. package/dist/control-api/operations/db-init.d.ts.map +0 -1
  226. package/dist/control-api/types.d.ts +0 -387
  227. package/dist/control-api/types.d.ts.map +0 -1
  228. package/dist/exports/config-types.d.ts +0 -3
  229. package/dist/exports/config-types.d.ts.map +0 -1
  230. package/dist/exports/config-types.js +0 -6
  231. package/dist/exports/config-types.js.map +0 -1
  232. package/dist/exports/control-api.d.ts +0 -13
  233. package/dist/exports/control-api.d.ts.map +0 -1
  234. package/dist/exports/control-api.js +0 -7
  235. package/dist/exports/control-api.js.map +0 -1
  236. package/dist/exports/index.d.ts +0 -4
  237. package/dist/exports/index.d.ts.map +0 -1
  238. package/dist/exports/index.js +0 -176
  239. package/dist/exports/index.js.map +0 -1
  240. package/dist/load-ts-contract.d.ts.map +0 -1
  241. package/dist/utils/cli-errors.d.ts +0 -7
  242. package/dist/utils/cli-errors.d.ts.map +0 -1
  243. package/dist/utils/command-helpers.d.ts +0 -12
  244. package/dist/utils/command-helpers.d.ts.map +0 -1
  245. package/dist/utils/framework-components.d.ts +0 -70
  246. package/dist/utils/framework-components.d.ts.map +0 -1
  247. package/dist/utils/global-flags.d.ts +0 -25
  248. package/dist/utils/global-flags.d.ts.map +0 -1
  249. package/dist/utils/output.d.ts +0 -142
  250. package/dist/utils/output.d.ts.map +0 -1
  251. package/dist/utils/progress-adapter.d.ts +0 -26
  252. package/dist/utils/progress-adapter.d.ts.map +0 -1
  253. package/dist/utils/result-handler.d.ts +0 -15
  254. package/dist/utils/result-handler.d.ts.map +0 -1
  255. package/src/commands/db-introspect.ts +0 -227
  256. package/src/commands/db-schema-verify.ts +0 -238
  257. package/src/utils/output.ts +0 -1471
@@ -1,15 +1,21 @@
1
- import type { CoreSchemaView } from '@prisma-next/core-control-plane/schema-view';
1
+ import type {
2
+ ContractSourceDiagnostics,
3
+ ContractSourceProvider,
4
+ } from '@prisma-next/config/config-types';
5
+ import type { Contract, ContractMarkerRecord } from '@prisma-next/contract/types';
2
6
  import type {
3
7
  ControlAdapterDescriptor,
4
8
  ControlDriverDescriptor,
5
9
  ControlExtensionDescriptor,
6
10
  ControlFamilyDescriptor,
7
11
  ControlTargetDescriptor,
12
+ CoreSchemaView,
8
13
  MigrationPlannerConflict,
14
+ MigrationPlanOperation,
9
15
  SignDatabaseResult,
10
16
  VerifyDatabaseResult,
11
17
  VerifyDatabaseSchemaResult,
12
- } from '@prisma-next/core-control-plane/types';
18
+ } from '@prisma-next/framework-components/control';
13
19
  import type { Result } from '@prisma-next/utils/result';
14
20
 
15
21
  // ============================================================================
@@ -31,7 +37,7 @@ export interface ControlClientOptions {
31
37
  // biome-ignore lint/suspicious/noExplicitAny: required for contravariance - SqlFamilyDescriptor.create has specific parameter types
32
38
  readonly family: ControlFamilyDescriptor<any, any>;
33
39
  // biome-ignore lint/suspicious/noExplicitAny: required for contravariance - SqlControlTargetDescriptor extends with additional methods
34
- readonly target: ControlTargetDescriptor<any, any, any, any>;
40
+ readonly target: ControlTargetDescriptor<any, any, any>;
35
41
  // biome-ignore lint/suspicious/noExplicitAny: required for contravariance in adapter.create()
36
42
  readonly adapter: ControlAdapterDescriptor<any, any, any>;
37
43
  /** Optional - control client can be created without driver for offline operations */
@@ -56,6 +62,8 @@ export interface ControlClientOptions {
56
62
  */
57
63
  export type ControlActionName =
58
64
  | 'dbInit'
65
+ | 'dbUpdate'
66
+ | 'migrationApply'
59
67
  | 'verify'
60
68
  | 'schemaVerify'
61
69
  | 'sign'
@@ -105,8 +113,8 @@ export type OnControlProgress = (event: ControlProgressEvent) => void;
105
113
  * Options for the verify operation.
106
114
  */
107
115
  export interface VerifyOptions {
108
- /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
109
- readonly contractIR: unknown;
116
+ /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
117
+ readonly contract: unknown;
110
118
  /**
111
119
  * Database connection. If provided, verify will connect before executing.
112
120
  * If omitted, the client must already be connected.
@@ -121,8 +129,8 @@ export interface VerifyOptions {
121
129
  * Options for the schemaVerify operation.
122
130
  */
123
131
  export interface SchemaVerifyOptions {
124
- /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
125
- readonly contractIR: unknown;
132
+ /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
133
+ readonly contract: unknown;
126
134
  /**
127
135
  * Whether to use strict mode for schema verification.
128
136
  * In strict mode, extra tables/columns are reported as issues.
@@ -143,8 +151,8 @@ export interface SchemaVerifyOptions {
143
151
  * Options for the sign operation.
144
152
  */
145
153
  export interface SignOptions {
146
- /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
147
- readonly contractIR: unknown;
154
+ /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
155
+ readonly contract: unknown;
148
156
  /**
149
157
  * Path to the contract file (for metadata in the result).
150
158
  */
@@ -167,8 +175,8 @@ export interface SignOptions {
167
175
  * Options for the dbInit operation.
168
176
  */
169
177
  export interface DbInitOptions {
170
- /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
171
- readonly contractIR: unknown;
178
+ /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
179
+ readonly contract: unknown;
172
180
  /**
173
181
  * Mode for the dbInit operation.
174
182
  * - 'plan': Returns planned operations without applying
@@ -185,6 +193,36 @@ export interface DbInitOptions {
185
193
  readonly onProgress?: OnControlProgress;
186
194
  }
187
195
 
196
+ /**
197
+ * Options for the dbUpdate operation.
198
+ */
199
+ export interface DbUpdateOptions {
200
+ /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
201
+ readonly contract: unknown;
202
+ /**
203
+ * Mode for the dbUpdate operation.
204
+ * - 'plan': Returns planned operations without applying
205
+ * - 'apply': Applies operations and writes marker/ledger
206
+ */
207
+ readonly mode: 'plan' | 'apply';
208
+ /**
209
+ * Database connection. If provided, dbUpdate will connect before executing.
210
+ * If omitted, the client must already be connected.
211
+ * The type is driver-specific (e.g., string URL for Postgres).
212
+ */
213
+ readonly connection?: unknown;
214
+ /**
215
+ * When true, allows applying plans that contain destructive operations
216
+ * (e.g., DROP TABLE, DROP COLUMN, ALTER TYPE).
217
+ * When false (default), the operation returns a failure if the plan
218
+ * includes destructive operations, prompting the user to confirm interactively
219
+ * or re-run with -y/--yes.
220
+ */
221
+ readonly acceptDataLoss?: boolean;
222
+ /** Optional progress callback for observing operation progress */
223
+ readonly onProgress?: OnControlProgress;
224
+ }
225
+
188
226
  /**
189
227
  * Options for the introspect operation.
190
228
  */
@@ -203,47 +241,19 @@ export interface IntrospectOptions {
203
241
  readonly onProgress?: OnControlProgress;
204
242
  }
205
243
 
206
- /**
207
- * Contract source as a raw value (any JSON-serializable value).
208
- */
209
- export interface ContractSourceValue {
210
- readonly kind: 'value';
211
- readonly value: unknown;
212
- }
213
-
214
- /**
215
- * Contract source as a lazy loader function.
216
- */
217
- export interface ContractSourceLoader {
218
- readonly kind: 'loader';
219
- readonly load: () => unknown | Promise<unknown>;
220
- }
221
-
222
- /**
223
- * Discriminated union for contract source.
224
- * Use `kind` to determine how to resolve the contract.
225
- */
226
- export type EmitContractSource = ContractSourceValue | ContractSourceLoader;
227
-
228
244
  /**
229
245
  * Contract configuration for emit operation.
230
246
  */
231
247
  export interface EmitContractConfig {
232
248
  /**
233
- * Contract source - either a raw value or a loader function.
234
- * Switch on `source.kind` to determine how to resolve.
249
+ * Contract source provider.
235
250
  */
236
- readonly source: EmitContractSource;
251
+ readonly sourceProvider: ContractSourceProvider;
237
252
  /**
238
253
  * Output path for contract.json.
239
- * Should be an absolute or relative path.
254
+ * The .d.ts types file will be colocated (e.g., contract.json contract.d.ts).
240
255
  */
241
256
  readonly output: string;
242
- /**
243
- * Output path for contract.d.ts.
244
- * Should be an absolute or relative path.
245
- */
246
- readonly types: string;
247
257
  }
248
258
 
249
259
  /**
@@ -273,13 +283,18 @@ export interface DbInitSuccess {
273
283
  readonly label: string;
274
284
  readonly operationClass: string;
275
285
  }>;
286
+ readonly sql?: ReadonlyArray<string>;
287
+ };
288
+ readonly destination: {
289
+ readonly storageHash: string;
290
+ readonly profileHash?: string;
276
291
  };
277
292
  readonly execution?: {
278
293
  readonly operationsPlanned: number;
279
294
  readonly operationsExecuted: number;
280
295
  };
281
296
  readonly marker?: {
282
- readonly coreHash: string;
297
+ readonly storageHash: string;
283
298
  readonly profileHash?: string;
284
299
  };
285
300
  readonly summary: string;
@@ -300,11 +315,11 @@ export interface DbInitFailure {
300
315
  readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
301
316
  readonly meta: Record<string, unknown> | undefined;
302
317
  readonly marker?: {
303
- readonly coreHash?: string;
318
+ readonly storageHash?: string;
304
319
  readonly profileHash?: string;
305
320
  };
306
321
  readonly destination?: {
307
- readonly coreHash: string;
322
+ readonly storageHash: string;
308
323
  readonly profileHash?: string | undefined;
309
324
  };
310
325
  }
@@ -315,13 +330,65 @@ export interface DbInitFailure {
315
330
  */
316
331
  export type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
317
332
 
333
+ /**
334
+ * Successful dbUpdate result.
335
+ */
336
+ export interface DbUpdateSuccess {
337
+ readonly mode: 'plan' | 'apply';
338
+ readonly plan: {
339
+ readonly operations: ReadonlyArray<{
340
+ readonly id: string;
341
+ readonly label: string;
342
+ readonly operationClass: string;
343
+ }>;
344
+ readonly sql?: ReadonlyArray<string>;
345
+ };
346
+ readonly destination: {
347
+ readonly storageHash: string;
348
+ readonly profileHash?: string;
349
+ };
350
+ readonly execution?: {
351
+ readonly operationsPlanned: number;
352
+ readonly operationsExecuted: number;
353
+ };
354
+ readonly marker?: {
355
+ readonly storageHash: string;
356
+ readonly profileHash?: string;
357
+ };
358
+ readonly summary: string;
359
+ }
360
+
361
+ /**
362
+ * Failure codes for dbUpdate operation.
363
+ */
364
+ export type DbUpdateFailureCode = 'PLANNING_FAILED' | 'RUNNER_FAILED' | 'DESTRUCTIVE_CHANGES';
365
+
366
+ /**
367
+ * Failure details for dbUpdate operation.
368
+ */
369
+ export interface DbUpdateFailure {
370
+ readonly code: DbUpdateFailureCode;
371
+ readonly summary: string;
372
+ readonly why: string | undefined;
373
+ readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
374
+ readonly meta: Record<string, unknown> | undefined;
375
+ }
376
+
377
+ /**
378
+ * Result type for dbUpdate operation.
379
+ * Uses Result pattern: success returns DbUpdateSuccess, failure returns DbUpdateFailure.
380
+ */
381
+ export type DbUpdateResult = Result<DbUpdateSuccess, DbUpdateFailure>;
382
+
318
383
  /**
319
384
  * Successful emit result.
320
385
  * Contains the hashes and paths of emitted files.
321
386
  */
322
387
  export interface EmitSuccess {
323
- /** Core hash of the emitted contract */
324
- readonly coreHash: string;
388
+ /** Storage hash of the emitted contract */
389
+ readonly storageHash: string;
390
+ /** Execution hash of the emitted contract (if execution section exists) */
391
+ readonly executionHash?: string;
325
392
  /** Profile hash of the emitted contract (target-specific) */
326
393
  readonly profileHash: string;
327
394
  /** The emitted contract as JSON string */
@@ -333,7 +400,10 @@ export interface EmitSuccess {
333
400
  /**
334
401
  * Failure codes for emit operation.
335
402
  */
336
- export type EmitFailureCode = 'CONTRACT_SOURCE_INVALID' | 'EMIT_FAILED';
403
+ export type EmitFailureCode =
404
+ | 'CONTRACT_SOURCE_INVALID'
405
+ | 'CONTRACT_VALIDATION_FAILED'
406
+ | 'EMIT_FAILED';
337
407
 
338
408
  /**
339
409
  * Failure details for emit operation.
@@ -343,6 +413,7 @@ export interface EmitFailure {
343
413
  readonly summary: string;
344
414
  readonly why: string | undefined;
345
415
  readonly meta: Record<string, unknown> | undefined;
416
+ readonly diagnostics?: ContractSourceDiagnostics;
346
417
  }
347
418
 
348
419
  /**
@@ -351,6 +422,125 @@ export interface EmitFailure {
351
422
  */
352
423
  export type EmitResult = Result<EmitSuccess, EmitFailure>;
353
424
 
425
+ // ============================================================================
426
+ // Migration Apply Types
427
+ // ============================================================================
428
+
429
+ /**
430
+ * A pre-planned migration step ready for execution.
431
+ * Contains the manifest metadata and the serialized operations from ops.json.
432
+ */
433
+ export interface MigrationApplyStep {
434
+ readonly dirName: string;
435
+ readonly from: string;
436
+ readonly to: string;
437
+ readonly toContract: Contract;
438
+ readonly operations: readonly MigrationPlanOperation[];
439
+ }
440
+
441
+ /**
442
+ * Options for the migrationApply operation.
443
+ */
444
+ export interface MigrationApplyOptions {
445
+ /**
446
+ * Hash of the database state this apply path starts from.
447
+ * This is resolved by the caller (typically the CLI orchestration layer).
448
+ */
449
+ readonly originHash: string;
450
+ /**
451
+ * Hash of the target contract this apply path must reach.
452
+ * This is resolved by the caller (typically the CLI orchestration layer).
453
+ */
454
+ readonly destinationHash: string;
455
+ /**
456
+ * Ordered list of migrations to execute from originHash to destinationHash.
457
+ * The execution layer does not choose defaults; it only executes this explicit path.
458
+ */
459
+ readonly pendingMigrations: readonly MigrationApplyStep[];
460
+ /**
461
+ * Database connection. If provided, migrationApply will connect before executing.
462
+ * If omitted, the client must already be connected.
463
+ */
464
+ readonly connection?: unknown;
465
+ /** Optional progress callback for observing operation progress */
466
+ readonly onProgress?: OnControlProgress;
467
+ }
468
+
469
+ /**
470
+ * Record of a successfully applied migration.
471
+ */
472
+ export interface MigrationApplyAppliedEntry {
473
+ readonly dirName: string;
474
+ readonly from: string;
475
+ readonly to: string;
476
+ readonly operationsExecuted: number;
477
+ }
478
+
479
+ /**
480
+ * Successful migrationApply result.
481
+ */
482
+ export interface MigrationApplySuccess {
483
+ readonly migrationsApplied: number;
484
+ readonly markerHash: string;
485
+ readonly applied: readonly MigrationApplyAppliedEntry[];
486
+ readonly summary: string;
487
+ }
488
+
489
+ /**
490
+ * Failure codes for migrationApply operation.
491
+ */
492
+ export type MigrationApplyFailureCode = 'RUNNER_FAILED' | 'MIGRATION_PATH_NOT_FOUND';
493
+
494
+ /**
495
+ * Failure details for migrationApply operation.
496
+ */
497
+ export interface MigrationApplyFailure {
498
+ readonly code: MigrationApplyFailureCode;
499
+ readonly summary: string;
500
+ readonly why: string | undefined;
501
+ readonly meta: Record<string, unknown> | undefined;
502
+ }
503
+
504
+ /**
505
+ * Result type for migrationApply operation.
506
+ */
507
+ export type MigrationApplyResult = Result<MigrationApplySuccess, MigrationApplyFailure>;
508
+
509
+ // ============================================================================
510
+ // Standalone Contract Emit Types
511
+ // ============================================================================
512
+
513
+ /**
514
+ * Options for the standalone executeContractEmit function.
515
+ * Used by tooling (e.g., Vite plugin) that needs to emit contracts
516
+ * without the full ControlClient infrastructure.
517
+ */
518
+ export interface ContractEmitOptions {
519
+ /** Path to the prisma-next.config.ts file */
520
+ readonly configPath: string;
521
+ /** Optional AbortSignal for cancellation support */
522
+ readonly signal?: AbortSignal;
523
+ }
524
+
525
+ /**
526
+ * Result from the standalone executeContractEmit function.
527
+ */
528
+ export interface ContractEmitResult {
529
+ /** Hash of the storage contract (schema-level) */
530
+ readonly storageHash: string;
531
+ /** Hash of the execution contract (if execution section exists) */
532
+ readonly executionHash?: string;
533
+ /** Hash of the profile (target+extensions) */
534
+ readonly profileHash: string;
535
+ /** Paths to the emitted files */
536
+ readonly files: {
537
+ /** Path to the emitted contract.json file */
538
+ readonly json: string;
539
+ /** Path to the emitted contract.d.ts file */
540
+ readonly dts: string;
541
+ };
542
+ }
543
+
354
544
  // ============================================================================
355
545
  // Client Interface
356
546
  // ============================================================================
@@ -397,7 +587,7 @@ export interface ControlClient {
397
587
 
398
588
  /**
399
589
  * Verifies database marker matches the contract.
400
- * Compares coreHash and profileHash.
590
+ * Compares storageHash and profileHash.
401
591
  *
402
592
  * @returns Structured result (ok: false for mismatch, not throwing)
403
593
  * @throws If not connected or infrastructure failure
@@ -414,9 +604,9 @@ export interface ControlClient {
414
604
  schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult>;
415
605
 
416
606
  /**
417
- * Signs the database with a contract marker.
418
- * Writes or updates the contract marker if schema verification passes.
419
- * Idempotent (no-op if marker already matches).
607
+ * Signs the database with a contract signature.
608
+ * Writes or updates the signature if schema verification passes.
609
+ * Idempotent (no-op if signature already matches).
420
610
  *
421
611
  * @returns Structured result
422
612
  * @throws If not connected or infrastructure failure
@@ -433,6 +623,38 @@ export interface ControlClient {
433
623
  */
434
624
  dbInit(options: DbInitOptions): Promise<DbInitResult>;
435
625
 
626
+ /**
627
+ * Updates a database schema to match the current contract.
628
+ * Creates the signature table if it does not exist. No preconditions required.
629
+ * Allows additive, widening, and destructive operation classes.
630
+ *
631
+ * @param options.mode - 'plan' to preview, 'apply' to execute
632
+ * @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
633
+ * @throws If not connected, target doesn't support migrations, or infrastructure failure
634
+ */
635
+ dbUpdate(options: DbUpdateOptions): Promise<DbUpdateResult>;
636
+
637
+ /**
638
+ * Reads the contract marker from the database.
639
+ * Returns null if no marker exists (fresh database).
640
+ *
641
+ * @throws If not connected or infrastructure failure
642
+ */
643
+ readMarker(): Promise<ContractMarkerRecord | null>;
644
+
645
+ /**
646
+ * Applies pre-planned on-disk migrations to the database.
647
+ * Each migration runs in its own transaction with full execution checks.
648
+ * Resume-safe: re-running after failure picks up from the last applied migration.
649
+ *
650
+ * @param options.originHash - Explicit source hash for the apply path
651
+ * @param options.destinationHash - Explicit destination hash for the apply path
652
+ * @param options.pendingMigrations - Ordered migrations to execute
653
+ * @returns Result pattern: Ok with applied details, NotOk with failure details
654
+ * @throws If not connected, target doesn't support migrations, or infrastructure failure
655
+ */
656
+ migrationApply(options: MigrationApplyOptions): Promise<MigrationApplyResult>;
657
+
436
658
  /**
437
659
  * Introspects the database schema.
438
660
  *
@@ -1,6 +1,7 @@
1
- // Re-export core-control-plane config types for convenience
1
+ // Re-export config package types for convenience
2
2
  export type {
3
3
  ContractConfig,
4
+ ContractSourceContext,
4
5
  PrismaNextConfig,
5
- } from '@prisma-next/core-control-plane/config-types';
6
- export { defineConfig } from '@prisma-next/core-control-plane/config-types';
6
+ } from '@prisma-next/config/config-types';
7
+ export { defineConfig } from '@prisma-next/config/config-types';
@@ -10,18 +10,24 @@
10
10
 
11
11
  // Re-export core control plane types for consumer convenience
12
12
  export type {
13
- ControlPlaneStack,
13
+ ControlStack,
14
14
  SignDatabaseResult,
15
15
  VerifyDatabaseResult,
16
16
  VerifyDatabaseSchemaResult,
17
- } from '@prisma-next/core-control-plane/types';
17
+ } from '@prisma-next/framework-components/control';
18
18
  // Client factory
19
19
  export { createControlClient } from '../control-api/client';
20
20
 
21
+ // Contract enrichment (merges framework-derived capabilities and extension pack metadata)
22
+ export { enrichContract } from '../control-api/contract-enrichment';
23
+
24
+ // Standalone operations (for tooling that doesn't need full client)
25
+ export { executeContractEmit } from '../control-api/operations/contract-emit';
26
+
21
27
  // CLI-specific types
22
28
  export type {
23
- ContractSourceLoader,
24
- ContractSourceValue,
29
+ ContractEmitOptions,
30
+ ContractEmitResult,
25
31
  ControlActionName,
26
32
  ControlClient,
27
33
  ControlClientOptions,
@@ -31,8 +37,12 @@ export type {
31
37
  DbInitOptions,
32
38
  DbInitResult,
33
39
  DbInitSuccess,
40
+ DbUpdateFailure,
41
+ DbUpdateFailureCode,
42
+ DbUpdateOptions,
43
+ DbUpdateResult,
44
+ DbUpdateSuccess,
34
45
  EmitContractConfig,
35
- EmitContractSource,
36
46
  EmitFailure,
37
47
  EmitFailureCode,
38
48
  EmitOptions,
@@ -1,15 +1,16 @@
1
1
  import { existsSync, unlinkSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import type { ContractIR } from '@prisma-next/contract/ir';
3
+ import { pathToFileURL } from 'node:url';
4
+ import type { Contract } from '@prisma-next/contract/types';
5
5
  import type { Plugin } from 'esbuild';
6
6
  import { build } from 'esbuild';
7
+ import { join } from 'pathe';
7
8
 
8
9
  export interface LoadTsContractOptions {
9
10
  readonly allowlist?: ReadonlyArray<string>;
10
11
  }
11
12
 
12
- const DEFAULT_ALLOWLIST = ['@prisma-next/*'];
13
+ const DEFAULT_ALLOWLIST = ['@prisma-next/*', 'node:crypto'];
13
14
 
14
15
  function isAllowedImport(importPath: string, allowlist: ReadonlyArray<string>): boolean {
15
16
  for (const pattern of allowlist) {
@@ -18,6 +19,11 @@ function isAllowedImport(importPath: string, allowlist: ReadonlyArray<string>):
18
19
  if (importPath === prefix || importPath.startsWith(`${prefix}/`)) {
19
20
  return true;
20
21
  }
22
+ } else if (pattern.endsWith('*')) {
23
+ const prefix = pattern.slice(0, -1);
24
+ if (importPath.startsWith(prefix)) {
25
+ return true;
26
+ }
21
27
  } else if (importPath === pattern) {
22
28
  return true;
23
29
  }
@@ -30,26 +36,31 @@ function validatePurity(value: unknown): void {
30
36
  return;
31
37
  }
32
38
 
33
- const seen = new WeakSet();
39
+ const path = new WeakSet();
40
+
34
41
  function check(value: unknown): void {
35
42
  if (value === null || typeof value !== 'object') {
36
43
  return;
37
44
  }
38
45
 
39
- if (seen.has(value)) {
46
+ if (path.has(value)) {
40
47
  throw new Error('Contract export contains circular references');
41
48
  }
42
- seen.add(value);
49
+ path.add(value);
43
50
 
44
- for (const key in value) {
45
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
46
- if (descriptor && (descriptor.get || descriptor.set)) {
47
- throw new Error(`Contract export contains getter/setter at key "${key}"`);
48
- }
49
- if (descriptor && typeof descriptor.value === 'function') {
50
- throw new Error(`Contract export contains function at key "${key}"`);
51
+ try {
52
+ for (const key in value) {
53
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
54
+ if (descriptor && (descriptor.get || descriptor.set)) {
55
+ throw new Error(`Contract export contains getter/setter at key "${key}"`);
56
+ }
57
+ if (descriptor && typeof descriptor.value === 'function') {
58
+ throw new Error(`Contract export contains function at key "${key}"`);
59
+ }
60
+ check((value as Record<string, unknown>)[key]);
51
61
  }
52
- check((value as Record<string, unknown>)[key]);
62
+ } finally {
63
+ path.delete(value);
53
64
  }
54
65
  }
55
66
 
@@ -92,7 +103,7 @@ function createImportAllowlistPlugin(allowlist: ReadonlyArray<string>, entryPath
92
103
  }
93
104
 
94
105
  /**
95
- * Loads a contract from a TypeScript file and returns it as ContractIR.
106
+ * Loads a contract from a TypeScript file and returns it as Contract.
96
107
  *
97
108
  * **Responsibility: Parsing Only**
98
109
  * This function loads and parses a TypeScript contract file. It does NOT normalize the contract.
@@ -103,13 +114,13 @@ function createImportAllowlistPlugin(allowlist: ReadonlyArray<string>, entryPath
103
114
  *
104
115
  * @param entryPath - Path to the TypeScript contract file
105
116
  * @param options - Optional configuration (import allowlist)
106
- * @returns The contract as ContractIR (should already be normalized)
117
+ * @returns The contract as Contract (should already be normalized)
107
118
  * @throws Error if the contract cannot be loaded or is not JSON-serializable
108
119
  */
109
120
  export async function loadContractFromTs(
110
121
  entryPath: string,
111
122
  options?: LoadTsContractOptions,
112
- ): Promise<ContractIR> {
123
+ ): Promise<Contract> {
113
124
  const allowlist = options?.allowlist ?? DEFAULT_ALLOWLIST;
114
125
 
115
126
  if (!existsSync(entryPath)) {
@@ -175,7 +186,7 @@ export async function loadContractFromTs(
175
186
  }
176
187
  writeFileSync(tempFile, bundleContent, 'utf-8');
177
188
 
178
- const module = (await import(`file://${tempFile}`)) as {
189
+ const module = (await import(/* @vite-ignore */ pathToFileURL(tempFile).href)) as {
179
190
  default?: unknown;
180
191
  contract?: unknown;
181
192
  };
@@ -199,7 +210,7 @@ export async function loadContractFromTs(
199
210
 
200
211
  validatePurity(contract);
201
212
 
202
- return contract as ContractIR;
213
+ return contract as Contract;
203
214
  } catch (error) {
204
215
  try {
205
216
  if (tempFile) {
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Re-export all domain error factories from core-control-plane for convenience.
2
+ * Re-export all domain error factories from @prisma-next/errors for convenience.
3
3
  * CLI-specific errors (e.g., Commander.js argument validation) can be added here if needed.
4
4
  */
5
- export type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/core-control-plane/errors';
5
+ export type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/errors/control';
6
6
  export {
7
7
  CliStructuredError,
8
8
  errorConfigFileNotFound,
@@ -14,13 +14,19 @@ export {
14
14
  errorDriverRequired,
15
15
  errorFamilyReadMarkerSqlRequired,
16
16
  errorFileNotFound,
17
- errorHashMismatch,
18
- errorJsonFormatNotSupported,
19
- errorMarkerMissing,
20
17
  errorMigrationPlanningFailed,
21
18
  errorQueryRunnerFactoryRequired,
22
- errorRuntime,
23
19
  errorTargetMigrationNotSupported,
24
- errorTargetMismatch,
25
20
  errorUnexpected,
26
- } from '@prisma-next/core-control-plane/errors';
21
+ } from '@prisma-next/errors/control';
22
+ export {
23
+ ERROR_CODE_DESTRUCTIVE_CHANGES,
24
+ errorDestructiveChanges,
25
+ errorHashMismatch,
26
+ errorMarkerMissing,
27
+ errorMarkerRequired,
28
+ errorRunnerFailed,
29
+ errorRuntime,
30
+ errorSchemaVerificationFailed,
31
+ errorTargetMismatch,
32
+ } from '@prisma-next/errors/execution';