@prisma-next/cli 0.3.0-dev.11 → 0.3.0-dev.114

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 (215) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +470 -134
  3. package/dist/cli-errors-ByGuoqNj.mjs +3 -0
  4. package/dist/cli-errors-D6HxRn3A.d.mts +2 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.js +1 -2350
  7. package/dist/cli.mjs +235 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/client-612RJJD_.mjs +1069 -0
  10. package/dist/client-612RJJD_.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 +4 -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 +4 -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 +124 -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 +52 -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 +135 -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 +121 -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 +310 -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 +240 -0
  40. package/dist/commands/migration-apply.mjs.map +1 -0
  41. package/dist/commands/migration-plan.d.mts +47 -0
  42. package/dist/commands/migration-plan.d.mts.map +1 -0
  43. package/dist/commands/migration-plan.mjs +288 -0
  44. package/dist/commands/migration-plan.mjs.map +1 -0
  45. package/dist/commands/migration-ref.d.mts +43 -0
  46. package/dist/commands/migration-ref.d.mts.map +1 -0
  47. package/dist/commands/migration-ref.mjs +194 -0
  48. package/dist/commands/migration-ref.mjs.map +1 -0
  49. package/dist/commands/migration-show.d.mts +28 -0
  50. package/dist/commands/migration-show.d.mts.map +1 -0
  51. package/dist/commands/migration-show.mjs +139 -0
  52. package/dist/commands/migration-show.mjs.map +1 -0
  53. package/dist/commands/migration-status.d.mts +85 -0
  54. package/dist/commands/migration-status.d.mts.map +1 -0
  55. package/dist/commands/migration-status.mjs +4 -0
  56. package/dist/commands/migration-verify.d.mts +16 -0
  57. package/dist/commands/migration-verify.d.mts.map +1 -0
  58. package/dist/commands/migration-verify.mjs +87 -0
  59. package/dist/commands/migration-verify.mjs.map +1 -0
  60. package/dist/config-loader-d_KF19Tw.mjs +43 -0
  61. package/dist/config-loader-d_KF19Tw.mjs.map +1 -0
  62. package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
  63. package/dist/config-loader.d.mts.map +1 -0
  64. package/dist/config-loader.mjs +3 -0
  65. package/dist/contract-emit-CVv7dbQ9.mjs +187 -0
  66. package/dist/contract-emit-CVv7dbQ9.mjs.map +1 -0
  67. package/dist/contract-infer-Bvw8u8Eu.mjs +83 -0
  68. package/dist/contract-infer-Bvw8u8Eu.mjs.map +1 -0
  69. package/dist/exports/config-types.d.mts +2 -0
  70. package/dist/exports/config-types.mjs +3 -0
  71. package/dist/exports/control-api.d.mts +626 -0
  72. package/dist/exports/control-api.d.mts.map +1 -0
  73. package/dist/exports/control-api.mjs +107 -0
  74. package/dist/exports/control-api.mjs.map +1 -0
  75. package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +10 -5
  76. package/dist/exports/index.d.mts.map +1 -0
  77. package/dist/exports/index.mjs +130 -0
  78. package/dist/exports/index.mjs.map +1 -0
  79. package/dist/extract-sql-ddl-Jf5blEO0.mjs +26 -0
  80. package/dist/extract-sql-ddl-Jf5blEO0.mjs.map +1 -0
  81. package/dist/framework-components-M2j-qPfr.mjs +59 -0
  82. package/dist/framework-components-M2j-qPfr.mjs.map +1 -0
  83. package/dist/inspect-live-schema-BQe5i4YE.mjs +90 -0
  84. package/dist/inspect-live-schema-BQe5i4YE.mjs.map +1 -0
  85. package/dist/migration-command-scaffold-SLrjcKXS.mjs +104 -0
  86. package/dist/migration-command-scaffold-SLrjcKXS.mjs.map +1 -0
  87. package/dist/migration-status-B7OVZ-Ka.mjs +1576 -0
  88. package/dist/migration-status-B7OVZ-Ka.mjs.map +1 -0
  89. package/dist/migrations-Db_ea9eE.mjs +173 -0
  90. package/dist/migrations-Db_ea9eE.mjs.map +1 -0
  91. package/dist/progress-adapter-DRNe2idZ.mjs +43 -0
  92. package/dist/progress-adapter-DRNe2idZ.mjs.map +1 -0
  93. package/dist/terminal-ui-DAcMBRKf.mjs +980 -0
  94. package/dist/terminal-ui-DAcMBRKf.mjs.map +1 -0
  95. package/dist/verify-DXKxBFvU.mjs +385 -0
  96. package/dist/verify-DXKxBFvU.mjs.map +1 -0
  97. package/package.json +88 -43
  98. package/src/cli.ts +109 -58
  99. package/src/commands/contract-emit.ts +236 -143
  100. package/src/commands/contract-infer-paths.ts +32 -0
  101. package/src/commands/contract-infer.ts +131 -0
  102. package/src/commands/db-init.ts +211 -425
  103. package/src/commands/db-schema.ts +77 -0
  104. package/src/commands/db-sign.ts +207 -228
  105. package/src/commands/db-update.ts +236 -0
  106. package/src/commands/db-verify.ts +484 -186
  107. package/src/commands/inspect-live-schema.ts +171 -0
  108. package/src/commands/migration-apply.ts +416 -0
  109. package/src/commands/migration-plan.ts +451 -0
  110. package/src/commands/migration-ref.ts +305 -0
  111. package/src/commands/migration-show.ts +246 -0
  112. package/src/commands/migration-status.ts +838 -0
  113. package/src/commands/migration-verify.ts +134 -0
  114. package/src/config-loader.ts +13 -3
  115. package/src/control-api/client.ts +614 -0
  116. package/src/control-api/contract-enrichment.ts +135 -0
  117. package/src/control-api/errors.ts +9 -0
  118. package/src/control-api/operations/contract-emit.ts +173 -0
  119. package/src/control-api/operations/db-init.ts +286 -0
  120. package/src/control-api/operations/db-update.ts +221 -0
  121. package/src/control-api/operations/extract-sql-ddl.ts +47 -0
  122. package/src/control-api/operations/migration-apply.ts +194 -0
  123. package/src/control-api/operations/migration-helpers.ts +49 -0
  124. package/src/control-api/types.ts +683 -0
  125. package/src/exports/config-types.ts +4 -3
  126. package/src/exports/control-api.ts +56 -0
  127. package/src/load-ts-contract.ts +16 -11
  128. package/src/utils/cli-errors.ts +5 -2
  129. package/src/utils/command-helpers.ts +293 -3
  130. package/src/utils/formatters/emit.ts +67 -0
  131. package/src/utils/formatters/errors.ts +82 -0
  132. package/src/utils/formatters/graph-migration-mapper.ts +220 -0
  133. package/src/utils/formatters/graph-render.ts +1317 -0
  134. package/src/utils/formatters/graph-types.ts +114 -0
  135. package/src/utils/formatters/help.ts +380 -0
  136. package/src/utils/formatters/helpers.ts +28 -0
  137. package/src/utils/formatters/migrations.ts +346 -0
  138. package/src/utils/formatters/styled.ts +212 -0
  139. package/src/utils/formatters/verify.ts +620 -0
  140. package/src/utils/global-flags.ts +41 -23
  141. package/src/utils/migration-command-scaffold.ts +187 -0
  142. package/src/utils/migration-types.ts +12 -0
  143. package/src/utils/progress-adapter.ts +75 -0
  144. package/src/utils/result-handler.ts +12 -13
  145. package/src/utils/shutdown.ts +92 -0
  146. package/src/utils/suggest-command.ts +31 -0
  147. package/src/utils/terminal-ui.ts +276 -0
  148. package/dist/chunk-BZMBKEEQ.js +0 -997
  149. package/dist/chunk-BZMBKEEQ.js.map +0 -1
  150. package/dist/chunk-CVNWLFXO.js +0 -91
  151. package/dist/chunk-CVNWLFXO.js.map +0 -1
  152. package/dist/chunk-HWYQOCAJ.js +0 -47
  153. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  154. package/dist/chunk-QUPBU4KV.js +0 -131
  155. package/dist/chunk-QUPBU4KV.js.map +0 -1
  156. package/dist/cli.d.ts +0 -2
  157. package/dist/cli.d.ts.map +0 -1
  158. package/dist/cli.js.map +0 -1
  159. package/dist/commands/contract-emit.d.ts +0 -3
  160. package/dist/commands/contract-emit.d.ts.map +0 -1
  161. package/dist/commands/contract-emit.js +0 -9
  162. package/dist/commands/contract-emit.js.map +0 -1
  163. package/dist/commands/db-init.d.ts +0 -3
  164. package/dist/commands/db-init.d.ts.map +0 -1
  165. package/dist/commands/db-init.js +0 -337
  166. package/dist/commands/db-init.js.map +0 -1
  167. package/dist/commands/db-introspect.d.ts +0 -3
  168. package/dist/commands/db-introspect.d.ts.map +0 -1
  169. package/dist/commands/db-introspect.js +0 -186
  170. package/dist/commands/db-introspect.js.map +0 -1
  171. package/dist/commands/db-schema-verify.d.ts +0 -3
  172. package/dist/commands/db-schema-verify.d.ts.map +0 -1
  173. package/dist/commands/db-schema-verify.js +0 -160
  174. package/dist/commands/db-schema-verify.js.map +0 -1
  175. package/dist/commands/db-sign.d.ts +0 -3
  176. package/dist/commands/db-sign.d.ts.map +0 -1
  177. package/dist/commands/db-sign.js +0 -195
  178. package/dist/commands/db-sign.js.map +0 -1
  179. package/dist/commands/db-verify.d.ts +0 -3
  180. package/dist/commands/db-verify.d.ts.map +0 -1
  181. package/dist/commands/db-verify.js +0 -169
  182. package/dist/commands/db-verify.js.map +0 -1
  183. package/dist/config-loader.d.ts.map +0 -1
  184. package/dist/config-loader.js +0 -7
  185. package/dist/config-loader.js.map +0 -1
  186. package/dist/exports/config-types.d.ts +0 -3
  187. package/dist/exports/config-types.d.ts.map +0 -1
  188. package/dist/exports/config-types.js +0 -6
  189. package/dist/exports/config-types.js.map +0 -1
  190. package/dist/exports/index.d.ts +0 -4
  191. package/dist/exports/index.d.ts.map +0 -1
  192. package/dist/exports/index.js +0 -175
  193. package/dist/exports/index.js.map +0 -1
  194. package/dist/load-ts-contract.d.ts.map +0 -1
  195. package/dist/utils/action.d.ts +0 -16
  196. package/dist/utils/action.d.ts.map +0 -1
  197. package/dist/utils/cli-errors.d.ts +0 -7
  198. package/dist/utils/cli-errors.d.ts.map +0 -1
  199. package/dist/utils/command-helpers.d.ts +0 -12
  200. package/dist/utils/command-helpers.d.ts.map +0 -1
  201. package/dist/utils/framework-components.d.ts +0 -70
  202. package/dist/utils/framework-components.d.ts.map +0 -1
  203. package/dist/utils/global-flags.d.ts +0 -25
  204. package/dist/utils/global-flags.d.ts.map +0 -1
  205. package/dist/utils/output.d.ts +0 -142
  206. package/dist/utils/output.d.ts.map +0 -1
  207. package/dist/utils/result-handler.d.ts +0 -15
  208. package/dist/utils/result-handler.d.ts.map +0 -1
  209. package/dist/utils/spinner.d.ts +0 -29
  210. package/dist/utils/spinner.d.ts.map +0 -1
  211. package/src/commands/db-introspect.ts +0 -256
  212. package/src/commands/db-schema-verify.ts +0 -232
  213. package/src/utils/action.ts +0 -43
  214. package/src/utils/output.ts +0 -1471
  215. package/src/utils/spinner.ts +0 -67
@@ -0,0 +1,683 @@
1
+ import type {
2
+ ContractSourceDiagnostics,
3
+ ContractSourceProvider,
4
+ } from '@prisma-next/config/config-types';
5
+ import type { ContractMarkerRecord } from '@prisma-next/contract/types';
6
+ import type { CoreSchemaView } from '@prisma-next/core-control-plane/schema-view';
7
+ import type {
8
+ ControlAdapterDescriptor,
9
+ ControlDriverDescriptor,
10
+ ControlExtensionDescriptor,
11
+ ControlFamilyDescriptor,
12
+ ControlTargetDescriptor,
13
+ MigrationPlannerConflict,
14
+ MigrationPlanOperation,
15
+ SignDatabaseResult,
16
+ VerifyDatabaseResult,
17
+ VerifyDatabaseSchemaResult,
18
+ } from '@prisma-next/core-control-plane/types';
19
+ import type { Result } from '@prisma-next/utils/result';
20
+
21
+ // ============================================================================
22
+ // Client Options
23
+ // ============================================================================
24
+
25
+ /**
26
+ * Options for creating a control client.
27
+ *
28
+ * Note: This is NOT the same as CLI config. There's no `contract` field,
29
+ * no file paths. The client is config-agnostic.
30
+ *
31
+ * The descriptor types use permissive `any` because family-specific descriptors
32
+ * (e.g., SqlFamilyDescriptor) have more specific `create` method signatures that
33
+ * are not compatible with the base ControlFamilyDescriptor type due to TypeScript
34
+ * variance rules. The client implementation casts these internally.
35
+ */
36
+ export interface ControlClientOptions {
37
+ // biome-ignore lint/suspicious/noExplicitAny: required for contravariance - SqlFamilyDescriptor.create has specific parameter types
38
+ readonly family: ControlFamilyDescriptor<any, any>;
39
+ // biome-ignore lint/suspicious/noExplicitAny: required for contravariance - SqlControlTargetDescriptor extends with additional methods
40
+ readonly target: ControlTargetDescriptor<any, any, any, any>;
41
+ // biome-ignore lint/suspicious/noExplicitAny: required for contravariance in adapter.create()
42
+ readonly adapter: ControlAdapterDescriptor<any, any, any>;
43
+ /** Optional - control client can be created without driver for offline operations */
44
+ // biome-ignore lint/suspicious/noExplicitAny: required for contravariance in driver.create()
45
+ readonly driver?: ControlDriverDescriptor<any, any, any, any>;
46
+ // biome-ignore lint/suspicious/noExplicitAny: required for contravariance in extension.create()
47
+ readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<any, any, any>>;
48
+ /**
49
+ * Optional default connection for auto-connect.
50
+ * When provided, operations will auto-connect if not already connected.
51
+ * The type is driver-specific (e.g., string URL for Postgres).
52
+ */
53
+ readonly connection?: unknown;
54
+ }
55
+
56
+ // ============================================================================
57
+ // Progress Events
58
+ // ============================================================================
59
+
60
+ /**
61
+ * Action names for control-api operations that can emit progress events.
62
+ */
63
+ export type ControlActionName =
64
+ | 'dbInit'
65
+ | 'dbUpdate'
66
+ | 'migrationApply'
67
+ | 'verify'
68
+ | 'schemaVerify'
69
+ | 'sign'
70
+ | 'introspect'
71
+ | 'emit';
72
+
73
+ /**
74
+ * Progress event emitted during control-api operation execution.
75
+ *
76
+ * Events model operation progress using a span-based model:
77
+ * - `spanStart`: Begin a timed segment (supports nesting via parentSpanId)
78
+ * - `spanEnd`: Complete a timed segment
79
+ *
80
+ * All operation-specific progress (e.g., per-migration-operation) is modeled
81
+ * as nested spans rather than special event types.
82
+ *
83
+ * Events are delivered via an optional `onProgress` callback to avoid polluting
84
+ * return types. If the callback is absent, operations emit no events (zero overhead).
85
+ */
86
+ export type ControlProgressEvent =
87
+ | {
88
+ readonly action: ControlActionName;
89
+ readonly kind: 'spanStart';
90
+ readonly spanId: string;
91
+ readonly parentSpanId?: string;
92
+ readonly label: string;
93
+ }
94
+ | {
95
+ readonly action: ControlActionName;
96
+ readonly kind: 'spanEnd';
97
+ readonly spanId: string;
98
+ readonly outcome: 'ok' | 'skipped' | 'error';
99
+ };
100
+
101
+ /**
102
+ * Callback function for receiving progress events during control-api operations.
103
+ *
104
+ * @param event - The progress event emitted by the operation
105
+ */
106
+ export type OnControlProgress = (event: ControlProgressEvent) => void;
107
+
108
+ // ============================================================================
109
+ // Operation Options
110
+ // ============================================================================
111
+
112
+ /**
113
+ * Options for the verify operation.
114
+ */
115
+ export interface VerifyOptions {
116
+ /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
117
+ readonly contractIR: unknown;
118
+ /**
119
+ * Database connection. If provided, verify will connect before executing.
120
+ * If omitted, the client must already be connected.
121
+ * The type is driver-specific (e.g., string URL for Postgres).
122
+ */
123
+ readonly connection?: unknown;
124
+ /** Optional progress callback for observing operation progress */
125
+ readonly onProgress?: OnControlProgress;
126
+ }
127
+
128
+ /**
129
+ * Options for the schemaVerify operation.
130
+ */
131
+ export interface SchemaVerifyOptions {
132
+ /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
133
+ readonly contractIR: unknown;
134
+ /**
135
+ * Whether to use strict mode for schema verification.
136
+ * In strict mode, extra tables/columns are reported as issues.
137
+ * Default: false (tolerant mode - allows superset)
138
+ */
139
+ readonly strict?: boolean;
140
+ /**
141
+ * Database connection. If provided, schemaVerify will connect before executing.
142
+ * If omitted, the client must already be connected.
143
+ * The type is driver-specific (e.g., string URL for Postgres).
144
+ */
145
+ readonly connection?: unknown;
146
+ /** Optional progress callback for observing operation progress */
147
+ readonly onProgress?: OnControlProgress;
148
+ }
149
+
150
+ /**
151
+ * Options for the sign operation.
152
+ */
153
+ export interface SignOptions {
154
+ /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
155
+ readonly contractIR: unknown;
156
+ /**
157
+ * Path to the contract file (for metadata in the result).
158
+ */
159
+ readonly contractPath?: string;
160
+ /**
161
+ * Path to the config file (for metadata in the result).
162
+ */
163
+ readonly configPath?: string;
164
+ /**
165
+ * Database connection. If provided, sign will connect before executing.
166
+ * If omitted, the client must already be connected.
167
+ * The type is driver-specific (e.g., string URL for Postgres).
168
+ */
169
+ readonly connection?: unknown;
170
+ /** Optional progress callback for observing operation progress */
171
+ readonly onProgress?: OnControlProgress;
172
+ }
173
+
174
+ /**
175
+ * Options for the dbInit operation.
176
+ */
177
+ export interface DbInitOptions {
178
+ /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
179
+ readonly contractIR: unknown;
180
+ /**
181
+ * Mode for the dbInit operation.
182
+ * - 'plan': Returns planned operations without applying
183
+ * - 'apply': Applies operations and writes marker
184
+ */
185
+ readonly mode: 'plan' | 'apply';
186
+ /**
187
+ * Database connection. If provided, dbInit will connect before executing.
188
+ * If omitted, the client must already be connected.
189
+ * The type is driver-specific (e.g., string URL for Postgres).
190
+ */
191
+ readonly connection?: unknown;
192
+ /** Optional progress callback for observing operation progress */
193
+ readonly onProgress?: OnControlProgress;
194
+ }
195
+
196
+ /**
197
+ * Options for the dbUpdate operation.
198
+ */
199
+ export interface DbUpdateOptions {
200
+ /** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
201
+ readonly contractIR: 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
+
226
+ /**
227
+ * Options for the introspect operation.
228
+ */
229
+ export interface IntrospectOptions {
230
+ /**
231
+ * Optional schema name to introspect.
232
+ */
233
+ readonly schema?: string;
234
+ /**
235
+ * Database connection. If provided, introspect will connect before executing.
236
+ * If omitted, the client must already be connected.
237
+ * The type is driver-specific (e.g., string URL for Postgres).
238
+ */
239
+ readonly connection?: unknown;
240
+ /** Optional progress callback for observing operation progress */
241
+ readonly onProgress?: OnControlProgress;
242
+ }
243
+
244
+ /**
245
+ * Contract configuration for emit operation.
246
+ */
247
+ export interface EmitContractConfig {
248
+ /**
249
+ * Contract source provider.
250
+ */
251
+ readonly sourceProvider: ContractSourceProvider;
252
+ /**
253
+ * Output path for contract.json.
254
+ * The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
255
+ */
256
+ readonly output: string;
257
+ }
258
+
259
+ /**
260
+ * Options for the emit operation.
261
+ */
262
+ export interface EmitOptions {
263
+ /**
264
+ * Contract configuration containing source, output, and types paths.
265
+ */
266
+ readonly contractConfig: EmitContractConfig;
267
+ /** Optional progress callback for observing operation progress */
268
+ readonly onProgress?: OnControlProgress;
269
+ }
270
+
271
+ // ============================================================================
272
+ // Result Types
273
+ // ============================================================================
274
+
275
+ /**
276
+ * Successful dbInit result.
277
+ */
278
+ export interface DbInitSuccess {
279
+ readonly mode: 'plan' | 'apply';
280
+ readonly plan: {
281
+ readonly operations: ReadonlyArray<{
282
+ readonly id: string;
283
+ readonly label: string;
284
+ readonly operationClass: string;
285
+ }>;
286
+ readonly sql?: ReadonlyArray<string>;
287
+ };
288
+ readonly destination: {
289
+ readonly storageHash: string;
290
+ readonly profileHash?: string;
291
+ };
292
+ readonly execution?: {
293
+ readonly operationsPlanned: number;
294
+ readonly operationsExecuted: number;
295
+ };
296
+ readonly marker?: {
297
+ readonly storageHash: string;
298
+ readonly profileHash?: string;
299
+ };
300
+ readonly summary: string;
301
+ }
302
+
303
+ /**
304
+ * Failure codes for dbInit operation.
305
+ */
306
+ export type DbInitFailureCode = 'PLANNING_FAILED' | 'MARKER_ORIGIN_MISMATCH' | 'RUNNER_FAILED';
307
+
308
+ /**
309
+ * Failure details for dbInit operation.
310
+ */
311
+ export interface DbInitFailure {
312
+ readonly code: DbInitFailureCode;
313
+ readonly summary: string;
314
+ readonly why: string | undefined;
315
+ readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
316
+ readonly meta: Record<string, unknown> | undefined;
317
+ readonly marker?: {
318
+ readonly storageHash?: string;
319
+ readonly profileHash?: string;
320
+ };
321
+ readonly destination?: {
322
+ readonly storageHash: string;
323
+ readonly profileHash?: string | undefined;
324
+ };
325
+ }
326
+
327
+ /**
328
+ * Result type for dbInit operation.
329
+ * Uses Result pattern: success returns DbInitSuccess, failure returns DbInitFailure.
330
+ */
331
+ export type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
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
+
383
+ /**
384
+ * Successful emit result.
385
+ * Contains the hashes and paths of emitted files.
386
+ */
387
+ export interface EmitSuccess {
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;
392
+ /** Profile hash of the emitted contract (target-specific) */
393
+ readonly profileHash: string;
394
+ /** The emitted contract as JSON string */
395
+ readonly contractJson: string;
396
+ /** The emitted contract TypeScript declarations */
397
+ readonly contractDts: string;
398
+ }
399
+
400
+ /**
401
+ * Failure codes for emit operation.
402
+ */
403
+ export type EmitFailureCode =
404
+ | 'CONTRACT_SOURCE_INVALID'
405
+ | 'CONTRACT_VALIDATION_FAILED'
406
+ | 'EMIT_FAILED';
407
+
408
+ /**
409
+ * Failure details for emit operation.
410
+ */
411
+ export interface EmitFailure {
412
+ readonly code: EmitFailureCode;
413
+ readonly summary: string;
414
+ readonly why: string | undefined;
415
+ readonly meta: Record<string, unknown> | undefined;
416
+ readonly diagnostics?: ContractSourceDiagnostics;
417
+ }
418
+
419
+ /**
420
+ * Result type for emit operation.
421
+ * Uses Result pattern: success returns EmitSuccess, failure returns EmitFailure.
422
+ */
423
+ export type EmitResult = Result<EmitSuccess, EmitFailure>;
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: unknown;
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
+
544
+ // ============================================================================
545
+ // Client Interface
546
+ // ============================================================================
547
+
548
+ /**
549
+ * Programmatic control client for Prisma Next operations.
550
+ *
551
+ * Lifecycle: `connect(connection)` before operations, `close()` when done.
552
+ * Both `init()` and `connect()` are auto-called by operations if needed,
553
+ * but `connect()` requires a connection so must be called explicitly first
554
+ * unless a default connection was provided in options.
555
+ *
556
+ * @see README.md "Programmatic Control API" section for usage examples
557
+ */
558
+ export interface ControlClient {
559
+ /**
560
+ * Initializes the client by creating the control plane stack,
561
+ * family instance, and validating framework components.
562
+ *
563
+ * Idempotent (safe to call multiple times).
564
+ * Called automatically by `connect()` if not already initialized.
565
+ */
566
+ init(): void;
567
+
568
+ /**
569
+ * Establishes a database connection.
570
+ * Auto-calls `init()` if not already initialized.
571
+ * Must be called before any database operations unless a default connection
572
+ * was provided in options.
573
+ *
574
+ * @param connection - Driver-specific connection input (e.g., URL string for Postgres).
575
+ * If omitted, uses the default connection from options (if provided).
576
+ * @throws If connection fails, already connected, driver is not configured,
577
+ * or no connection provided and no default connection in options.
578
+ */
579
+ connect(connection?: unknown): Promise<void>;
580
+
581
+ /**
582
+ * Closes the database connection.
583
+ * Idempotent (safe to call multiple times).
584
+ * After close(), can call `connect()` again with same or different URL.
585
+ */
586
+ close(): Promise<void>;
587
+
588
+ /**
589
+ * Verifies database marker matches the contract.
590
+ * Compares storageHash and profileHash.
591
+ *
592
+ * @returns Structured result (ok: false for mismatch, not throwing)
593
+ * @throws If not connected or infrastructure failure
594
+ */
595
+ verify(options: VerifyOptions): Promise<VerifyDatabaseResult>;
596
+
597
+ /**
598
+ * Verifies database schema satisfies the contract requirements.
599
+ *
600
+ * @param options.strict - If true, extra tables/columns are issues. Default: false
601
+ * @returns Structured result with schema issues
602
+ * @throws If not connected or infrastructure failure
603
+ */
604
+ schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult>;
605
+
606
+ /**
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).
610
+ *
611
+ * @returns Structured result
612
+ * @throws If not connected or infrastructure failure
613
+ */
614
+ sign(options: SignOptions): Promise<SignDatabaseResult>;
615
+
616
+ /**
617
+ * Initializes database schema from contract.
618
+ * Uses additive-only policy (no destructive changes).
619
+ *
620
+ * @param options.mode - 'plan' to preview, 'apply' to execute
621
+ * @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
622
+ * @throws If not connected, target doesn't support migrations, or infrastructure failure
623
+ */
624
+ dbInit(options: DbInitOptions): Promise<DbInitResult>;
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
+
658
+ /**
659
+ * Introspects the database schema.
660
+ *
661
+ * @returns Raw schema IR
662
+ * @throws If not connected or infrastructure failure
663
+ */
664
+ introspect(options?: IntrospectOptions): Promise<unknown>;
665
+
666
+ /**
667
+ * Converts a schema IR to a schema view for CLI tree rendering.
668
+ * Delegates to the family instance's toSchemaView method.
669
+ *
670
+ * @param schemaIR - The schema IR from introspect()
671
+ * @returns CoreSchemaView if the family supports it, undefined otherwise
672
+ */
673
+ toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
674
+
675
+ /**
676
+ * Emits the contract to JSON and TypeScript declarations.
677
+ * This is an offline operation that does NOT require a database connection.
678
+ * Uses `init()` to create the stack but does NOT call `connect()`.
679
+ *
680
+ * @returns Result pattern: Ok with emit details, NotOk with failure details
681
+ */
682
+ emit(options: EmitOptions): Promise<EmitResult>;
683
+ }
@@ -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';