prisma-next 0.5.0-dev.74 → 0.5.0-dev.75

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 (92) hide show
  1. package/dist/cli.mjs +8 -8
  2. package/dist/{client-0ZX24FXF.mjs → client-qVH-rEgd.mjs} +433 -236
  3. package/dist/client-qVH-rEgd.mjs.map +1 -0
  4. package/dist/{result-handler-DWb1rFS-.mjs → command-helpers-BeZHkxV8.mjs} +22 -24
  5. package/dist/command-helpers-BeZHkxV8.mjs.map +1 -0
  6. package/dist/commands/contract-emit.mjs +1 -1
  7. package/dist/commands/contract-infer.mjs +1 -1
  8. package/dist/commands/db-init.d.mts.map +1 -1
  9. package/dist/commands/db-init.mjs +7 -5
  10. package/dist/commands/db-init.mjs.map +1 -1
  11. package/dist/commands/db-schema.mjs +5 -4
  12. package/dist/commands/db-schema.mjs.map +1 -1
  13. package/dist/commands/db-sign.mjs +6 -5
  14. package/dist/commands/db-sign.mjs.map +1 -1
  15. package/dist/commands/db-update.d.mts.map +1 -1
  16. package/dist/commands/db-update.mjs +7 -5
  17. package/dist/commands/db-update.mjs.map +1 -1
  18. package/dist/commands/db-verify.mjs +1 -1
  19. package/dist/commands/migration-apply.d.mts +29 -17
  20. package/dist/commands/migration-apply.d.mts.map +1 -1
  21. package/dist/commands/migration-apply.mjs +35 -129
  22. package/dist/commands/migration-apply.mjs.map +1 -1
  23. package/dist/commands/migration-new.mjs +4 -3
  24. package/dist/commands/migration-new.mjs.map +1 -1
  25. package/dist/commands/migration-plan.d.mts +19 -1
  26. package/dist/commands/migration-plan.d.mts.map +1 -1
  27. package/dist/commands/migration-plan.mjs +2 -2
  28. package/dist/commands/migration-ref.d.mts +1 -1
  29. package/dist/commands/migration-ref.mjs +3 -2
  30. package/dist/commands/migration-ref.mjs.map +1 -1
  31. package/dist/commands/migration-show.d.mts +1 -1
  32. package/dist/commands/migration-show.mjs +5 -4
  33. package/dist/commands/migration-show.mjs.map +1 -1
  34. package/dist/commands/migration-status.d.mts +104 -1
  35. package/dist/commands/migration-status.d.mts.map +1 -1
  36. package/dist/commands/migration-status.mjs +2 -2
  37. package/dist/{contract-emit-DkMqO7f2.mjs → contract-emit-9DBda5Ou.mjs} +7 -5
  38. package/dist/{contract-emit-DkMqO7f2.mjs.map → contract-emit-9DBda5Ou.mjs.map} +1 -1
  39. package/dist/{contract-emit-B3ChISB_.mjs → contract-emit-B77TsJqf.mjs} +4 -15
  40. package/dist/{contract-emit-B3ChISB_.mjs.map → contract-emit-B77TsJqf.mjs.map} +1 -1
  41. package/dist/{contract-enrichment-CF6ogEJ_.mjs → contract-enrichment-Dani0mMW.mjs} +1 -1
  42. package/dist/{contract-enrichment-CF6ogEJ_.mjs.map → contract-enrichment-Dani0mMW.mjs.map} +1 -1
  43. package/dist/{contract-infer-BDKAE0B0.mjs → contract-infer-BK9YFGEG.mjs} +5 -4
  44. package/dist/{contract-infer-BDKAE0B0.mjs.map → contract-infer-BK9YFGEG.mjs.map} +1 -1
  45. package/dist/{db-verify-B4TdDKOI.mjs → db-verify-C0y1PCO2.mjs} +7 -6
  46. package/dist/{db-verify-B4TdDKOI.mjs.map → db-verify-C0y1PCO2.mjs.map} +1 -1
  47. package/dist/exports/control-api.d.mts +3 -746
  48. package/dist/exports/control-api.d.mts.map +1 -1
  49. package/dist/exports/control-api.mjs +3 -3
  50. package/dist/exports/index.mjs +1 -1
  51. package/dist/exports/init-output.mjs +1 -1
  52. package/dist/extension-pack-inputs-C7xgE-vv.mjs +74 -0
  53. package/dist/extension-pack-inputs-C7xgE-vv.mjs.map +1 -0
  54. package/dist/{framework-components-gwAHl7ml.mjs → framework-components-ChqVUxR-.mjs} +1 -1
  55. package/dist/{framework-components-gwAHl7ml.mjs.map → framework-components-ChqVUxR-.mjs.map} +1 -1
  56. package/dist/global-flags-Icqpxk23.d.mts +12 -0
  57. package/dist/global-flags-Icqpxk23.d.mts.map +1 -0
  58. package/dist/helpers-eqdN8tH6.mjs +25 -0
  59. package/dist/helpers-eqdN8tH6.mjs.map +1 -0
  60. package/dist/{init-Deo7U8_U.mjs → init-CoDVPvQ4.mjs} +4 -4
  61. package/dist/{init-Deo7U8_U.mjs.map → init-CoDVPvQ4.mjs.map} +1 -1
  62. package/dist/{inspect-live-schema-BAgQMYpD.mjs → inspect-live-schema-CWYxGKlb.mjs} +4 -4
  63. package/dist/{inspect-live-schema-BAgQMYpD.mjs.map → inspect-live-schema-CWYxGKlb.mjs.map} +1 -1
  64. package/dist/{migration-command-scaffold-B8J702Uh.mjs → migration-command-scaffold-B5dORFEv.mjs} +4 -4
  65. package/dist/{migration-command-scaffold-B8J702Uh.mjs.map → migration-command-scaffold-B5dORFEv.mjs.map} +1 -1
  66. package/dist/{migration-plan-BcKNnTM7.mjs → migration-plan-C6lVaHsO.mjs} +47 -23
  67. package/dist/migration-plan-C6lVaHsO.mjs.map +1 -0
  68. package/dist/{migration-status-CjwB2of-.mjs → migration-status-CZ-D5k7k.mjs} +161 -7
  69. package/dist/migration-status-CZ-D5k7k.mjs.map +1 -0
  70. package/dist/{migrations-CIK94AJf.mjs → migrations-D_UJnpuW.mjs} +67 -24
  71. package/dist/migrations-D_UJnpuW.mjs.map +1 -0
  72. package/dist/{output-DnjfCC_u.mjs → output-B16Kefzx.mjs} +1 -1
  73. package/dist/{output-DnjfCC_u.mjs.map → output-B16Kefzx.mjs.map} +1 -1
  74. package/dist/{progress-adapter-xASh41wr.mjs → progress-adapter-DFfvZcYL.mjs} +1 -1
  75. package/dist/{progress-adapter-xASh41wr.mjs.map → progress-adapter-DFfvZcYL.mjs.map} +1 -1
  76. package/dist/result-handler-rmPVKIP2.mjs +25 -0
  77. package/dist/result-handler-rmPVKIP2.mjs.map +1 -0
  78. package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
  79. package/dist/{terminal-ui-zaRDhJnP.mjs → terminal-ui-C_hFNbAn.mjs} +3 -23
  80. package/dist/terminal-ui-C_hFNbAn.mjs.map +1 -0
  81. package/dist/types-D7x-IFLO.d.mts +858 -0
  82. package/dist/types-D7x-IFLO.d.mts.map +1 -0
  83. package/dist/{verify-BEIa9638.mjs → verify-CiwNWM9N.mjs} +2 -2
  84. package/dist/{verify-BEIa9638.mjs.map → verify-CiwNWM9N.mjs.map} +1 -1
  85. package/package.json +10 -10
  86. package/dist/client-0ZX24FXF.mjs.map +0 -1
  87. package/dist/migration-plan-BcKNnTM7.mjs.map +0 -1
  88. package/dist/migration-status-CjwB2of-.mjs.map +0 -1
  89. package/dist/migrations-CIK94AJf.mjs.map +0 -1
  90. package/dist/result-handler-DWb1rFS-.mjs.map +0 -1
  91. package/dist/terminal-ui-zaRDhJnP.mjs.map +0 -1
  92. /package/dist/{cli-errors-QH8kf-C2.d.mts → cli-errors-B9OBbled.d.mts} +0 -0
@@ -1,751 +1,8 @@
1
- import { t as CliStructuredError } from "../cli-errors-QH8kf-C2.mjs";
2
- import { Result } from "@prisma-next/utils/result";
3
- import { ContractSourceDiagnostics, ContractSourceProvider } from "@prisma-next/config/config-types";
4
- import { ControlAdapterDescriptor, ControlDriverDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyDescriptor, ControlFamilyInstance, ControlStack, ControlTargetDescriptor, CoreSchemaView, MigrationPlanOperation, MigrationPlannerConflict, OperationPreview, SignDatabaseResult, SignDatabaseResult as SignDatabaseResult$1, TargetMigrationsCapability, VerifyDatabaseResult, VerifyDatabaseResult as VerifyDatabaseResult$1, VerifyDatabaseSchemaResult, VerifyDatabaseSchemaResult as VerifyDatabaseSchemaResult$1 } from "@prisma-next/framework-components/control";
1
+ import { A as ExecuteDbVerifyOptions, C as EmitSuccess, D as SchemaVerifyOptions, E as OnControlProgress, M as executeDbVerify, O as SignOptions, S as EmitResult, _ as DbUpdateSuccess, a as ControlClient, b as EmitFailureCode, c as DbInitFailure, d as DbInitResult, f as DbInitSuccess, g as DbUpdateResult, h as DbUpdateOptions, i as ControlActionName, j as ExecuteDbVerifyResult, k as VerifyOptions, l as DbInitFailureCode, m as DbUpdateFailureCode, n as ContractEmitOptions, o as ControlClientOptions, p as DbUpdateFailure, r as ContractEmitResult, s as ControlProgressEvent, u as DbInitOptions, v as EmitContractConfig, w as IntrospectOptions, x as EmitOptions, y as EmitFailure } from "../types-D7x-IFLO.mjs";
2
+ import { ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack, SignDatabaseResult, TargetMigrationsCapability, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
5
3
  import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
6
- import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
7
- import { PslDocumentAst } from "@prisma-next/framework-components/psl-ast";
4
+ import { Contract } from "@prisma-next/contract/types";
8
5
 
9
- //#region src/control-api/operations/db-verify.d.ts
10
- /**
11
- * Inputs for the aggregate `db verify` operation.
12
- *
13
- * Loader → verifier pipeline. The loader (sole descriptor-import
14
- * boundary) builds a {@link import('@prisma-next/migration-tools/aggregate').ContractSpaceAggregate};
15
- * the aggregate verifier bundles `markerCheck` + per-space pre-projected
16
- * `schemaCheck`. `mode: 'strict' | 'lenient'` maps directly to the user
17
- * facing `--strict` flag.
18
- */
19
- interface ExecuteDbVerifyOptions<TFamilyId extends string, TTargetId extends string> {
20
- readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
21
- readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;
22
- readonly contract: Contract;
23
- readonly migrationsDir: string;
24
- readonly targetId: TTargetId;
25
- readonly extensionPacks: ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>;
26
- readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
27
- readonly mode: 'strict' | 'lenient';
28
- readonly skipSchema: boolean;
29
- readonly skipMarker: boolean;
30
- readonly onProgress?: OnControlProgress;
31
- }
32
- /**
33
- * Result of the aggregate verify operation.
34
- *
35
- * Marker-check failures are surfaced as a {@link CliStructuredError}
36
- * (same envelope code `5002` the legacy `runContractSpaceVerifierMarkerCheck`
37
- * emitted, so downstream tooling and integration tests assert on the
38
- * same shape).
39
- *
40
- * On success, the per-space schema results are returned for the CLI to
41
- * render. When `skipSchema` is true (`--marker-only`), the schema map
42
- * is empty.
43
- */
44
- interface ExecuteDbVerifySuccess {
45
- readonly schemaResults: ReadonlyMap<string, VerifyDatabaseSchemaResult$1>;
46
- readonly memberOrder: readonly string[];
47
- readonly appSpaceId: string;
48
- }
49
- type ExecuteDbVerifyResult = Result<ExecuteDbVerifySuccess, CliStructuredError>;
50
- /**
51
- * Loader → verifier pipeline shared by `db verify` modes (`full`,
52
- * `marker-only`, `schema-only`).
53
- *
54
- * 1. **Load**: build a {@link import('@prisma-next/migration-tools/aggregate').ContractSpaceAggregate}
55
- * from descriptors + on-disk on-disk artefacts. Layout / drift /
56
- * integrity / disjointness violations short-circuit with a
57
- * structured CLI error.
58
- * 2. **Read DB state**: marker rows + (when `skipSchema` is `false`)
59
- * schema introspection.
60
- * 3. **Verify**: {@link verifyAggregate} returns per-space
61
- * `markerCheck` + per-space pre-projected `schemaCheck` (closes F23).
62
- * Marker mismatches map to `CliStructuredError` (code `5002`) so
63
- * callers (CLI command) can render and exit. Schema results are
64
- * returned to the caller verbatim.
65
- */
66
- declare function executeDbVerify<TFamilyId extends string, TTargetId extends string>(options: ExecuteDbVerifyOptions<TFamilyId, TTargetId>): Promise<ExecuteDbVerifyResult>;
67
- //#endregion
68
- //#region src/control-api/types.d.ts
69
- /**
70
- * Options for creating a control client.
71
- *
72
- * Note: This is NOT the same as CLI config. There's no `contract` field,
73
- * no file paths. The client is config-agnostic.
74
- *
75
- * The descriptor types use permissive `any` because family-specific descriptors
76
- * (e.g., SqlFamilyDescriptor) have more specific `create` method signatures that
77
- * are not compatible with the base ControlFamilyDescriptor type due to TypeScript
78
- * variance rules. The client implementation casts these internally.
79
- */
80
- interface ControlClientOptions {
81
- readonly family: ControlFamilyDescriptor<any, any>;
82
- readonly target: ControlTargetDescriptor<any, any, any>;
83
- readonly adapter: ControlAdapterDescriptor<any, any, any>;
84
- /** Optional - control client can be created without driver for offline operations */
85
- readonly driver?: ControlDriverDescriptor<any, any, any, any>;
86
- readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<any, any, any>>;
87
- /**
88
- * Optional default connection for auto-connect.
89
- * When provided, operations will auto-connect if not already connected.
90
- * The type is driver-specific (e.g., string URL for Postgres).
91
- */
92
- readonly connection?: unknown;
93
- }
94
- /**
95
- * Action names for control-api operations that can emit progress events.
96
- */
97
- type ControlActionName = 'dbInit' | 'dbUpdate' | 'dbVerify' | 'migrationApply' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
98
- /**
99
- * Progress event emitted during control-api operation execution.
100
- *
101
- * Events model operation progress using a span-based model:
102
- * - `spanStart`: Begin a timed segment (supports nesting via parentSpanId)
103
- * - `spanEnd`: Complete a timed segment
104
- *
105
- * All operation-specific progress (e.g., per-migration-operation) is modeled
106
- * as nested spans rather than special event types.
107
- *
108
- * Events are delivered via an optional `onProgress` callback to avoid polluting
109
- * return types. If the callback is absent, operations emit no events (zero overhead).
110
- */
111
- type ControlProgressEvent = {
112
- readonly action: ControlActionName;
113
- readonly kind: 'spanStart';
114
- readonly spanId: string;
115
- readonly parentSpanId?: string;
116
- readonly label: string;
117
- } | {
118
- readonly action: ControlActionName;
119
- readonly kind: 'spanEnd';
120
- readonly spanId: string;
121
- readonly outcome: 'ok' | 'skipped' | 'error';
122
- };
123
- /**
124
- * Callback function for receiving progress events during control-api operations.
125
- *
126
- * @param event - The progress event emitted by the operation
127
- */
128
- type OnControlProgress = (event: ControlProgressEvent) => void;
129
- /**
130
- * Options for the verify operation.
131
- */
132
- interface VerifyOptions {
133
- /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
134
- readonly contract: unknown;
135
- /**
136
- * Database connection. If provided, verify will connect before executing.
137
- * If omitted, the client must already be connected.
138
- * The type is driver-specific (e.g., string URL for Postgres).
139
- */
140
- readonly connection?: unknown;
141
- /** Optional progress callback for observing operation progress */
142
- readonly onProgress?: OnControlProgress;
143
- }
144
- /**
145
- * Options for the schemaVerify operation.
146
- */
147
- interface SchemaVerifyOptions {
148
- /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
149
- readonly contract: unknown;
150
- /**
151
- * Whether to use strict mode for schema verification.
152
- * In strict mode, extra tables/columns are reported as issues.
153
- * Default: false (tolerant mode - allows superset)
154
- */
155
- readonly strict?: boolean;
156
- /**
157
- * Database connection. If provided, schemaVerify will connect before executing.
158
- * If omitted, the client must already be connected.
159
- * The type is driver-specific (e.g., string URL for Postgres).
160
- */
161
- readonly connection?: unknown;
162
- /** Optional progress callback for observing operation progress */
163
- readonly onProgress?: OnControlProgress;
164
- }
165
- /**
166
- * Options for the sign operation.
167
- */
168
- interface SignOptions {
169
- /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
170
- readonly contract: unknown;
171
- /**
172
- * Path to the contract file (for metadata in the result).
173
- */
174
- readonly contractPath?: string;
175
- /**
176
- * Path to the config file (for metadata in the result).
177
- */
178
- readonly configPath?: string;
179
- /**
180
- * Database connection. If provided, sign will connect before executing.
181
- * If omitted, the client must already be connected.
182
- * The type is driver-specific (e.g., string URL for Postgres).
183
- */
184
- readonly connection?: unknown;
185
- /** Optional progress callback for observing operation progress */
186
- readonly onProgress?: OnControlProgress;
187
- }
188
- /**
189
- * Options for the dbInit operation.
190
- */
191
- interface DbInitOptions {
192
- /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
193
- readonly contract: unknown;
194
- /**
195
- * Mode for the dbInit operation.
196
- * - 'plan': Returns planned operations without applying
197
- * - 'apply': Applies operations and writes marker
198
- */
199
- readonly mode: 'plan' | 'apply';
200
- /**
201
- * Database connection. If provided, dbInit will connect before executing.
202
- * If omitted, the client must already be connected.
203
- * The type is driver-specific (e.g., string URL for Postgres).
204
- */
205
- readonly connection?: unknown;
206
- /**
207
- * On-disk migrations directory. Always required — every `db init`
208
- * routes through the per-space flow, which reads on-disk
209
- * `refs/head.json` and extension destination contracts from this
210
- * root.
211
- */
212
- readonly migrationsDir: string;
213
- /** Optional progress callback for observing operation progress */
214
- readonly onProgress?: OnControlProgress;
215
- }
216
- /**
217
- * Options for the dbUpdate operation.
218
- */
219
- interface DbUpdateOptions {
220
- /** Contract or unvalidated JSON - validated at runtime via familyInstance.validateContract() */
221
- readonly contract: unknown;
222
- /**
223
- * Mode for the dbUpdate operation.
224
- * - 'plan': Returns planned operations without applying
225
- * - 'apply': Applies operations and writes marker/ledger
226
- */
227
- readonly mode: 'plan' | 'apply';
228
- /**
229
- * Database connection. If provided, dbUpdate will connect before executing.
230
- * If omitted, the client must already be connected.
231
- * The type is driver-specific (e.g., string URL for Postgres).
232
- */
233
- readonly connection?: unknown;
234
- /**
235
- * When true, allows applying plans that contain destructive operations
236
- * (e.g., DROP TABLE, DROP COLUMN, ALTER TYPE).
237
- * When false (default), the operation returns a failure if the plan
238
- * includes destructive operations, prompting the user to confirm interactively
239
- * or re-run with -y/--yes.
240
- */
241
- readonly acceptDataLoss?: boolean;
242
- /**
243
- * On-disk migrations directory. Always required — every `db update`
244
- * routes through the per-space flow, which reads on-disk
245
- * `refs/head.json` and extension destination contracts from this
246
- * root.
247
- */
248
- readonly migrationsDir: string;
249
- /** Optional progress callback for observing operation progress */
250
- readonly onProgress?: OnControlProgress;
251
- }
252
- /**
253
- * Options for the dbVerify operation.
254
- *
255
- * Drives the loader → aggregate-verifier pipeline. `strict` maps to
256
- * `verifyAggregate({ mode: 'strict' | 'lenient' })`; `skipSchema`
257
- * mirrors the `--marker-only` CLI flag and short-circuits the schema
258
- * portion of the verifier.
259
- */
260
- interface DbVerifyOptions {
261
- readonly contract: unknown;
262
- readonly migrationsDir: string;
263
- readonly strict: boolean;
264
- readonly skipSchema: boolean;
265
- readonly skipMarker: boolean;
266
- readonly connection?: unknown;
267
- readonly onProgress?: OnControlProgress;
268
- }
269
- /**
270
- * Options for the introspect operation.
271
- */
272
- interface IntrospectOptions {
273
- /**
274
- * Optional schema name to introspect.
275
- */
276
- readonly schema?: string;
277
- /**
278
- * Database connection. If provided, introspect will connect before executing.
279
- * If omitted, the client must already be connected.
280
- * The type is driver-specific (e.g., string URL for Postgres).
281
- */
282
- readonly connection?: unknown;
283
- /** Optional progress callback for observing operation progress */
284
- readonly onProgress?: OnControlProgress;
285
- }
286
- /**
287
- * Contract configuration for emit operation.
288
- */
289
- interface EmitContractConfig {
290
- /**
291
- * Contract source provider.
292
- */
293
- readonly source: ContractSourceProvider;
294
- /**
295
- * Output path for contract.json.
296
- * The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
297
- */
298
- readonly output: string;
299
- }
300
- /**
301
- * Options for the emit operation.
302
- */
303
- interface EmitOptions {
304
- /**
305
- * Contract configuration containing source, output, and types paths.
306
- */
307
- readonly contractConfig: EmitContractConfig;
308
- /** Optional progress callback for observing operation progress */
309
- readonly onProgress?: OnControlProgress;
310
- }
311
- /**
312
- * Successful dbInit result.
313
- */
314
- interface DbInitSuccess {
315
- readonly mode: 'plan' | 'apply';
316
- readonly plan: {
317
- readonly operations: ReadonlyArray<{
318
- readonly id: string;
319
- readonly label: string;
320
- readonly operationClass: string;
321
- }>;
322
- /**
323
- * Family-agnostic textual preview of the planned operations, e.g.
324
- * `language: 'sql'` for SQL families and `language: 'mongodb-shell'`
325
- * for the Mongo family. Replaces the previous `sql?: readonly string[]`
326
- * field; consumers that previously read `plan.sql` should read
327
- * `plan.preview?.statements.map((s) => s.text)`.
328
- */
329
- readonly preview?: OperationPreview;
330
- };
331
- readonly destination: {
332
- readonly storageHash: string;
333
- readonly profileHash?: string;
334
- };
335
- readonly execution?: {
336
- readonly operationsPlanned: number;
337
- readonly operationsExecuted: number;
338
- };
339
- readonly marker?: {
340
- readonly storageHash: string;
341
- readonly profileHash?: string;
342
- };
343
- readonly summary: string;
344
- }
345
- /**
346
- * Failure codes for dbInit operation.
347
- */
348
- type DbInitFailureCode = 'PLANNING_FAILED' | 'MARKER_ORIGIN_MISMATCH' | 'RUNNER_FAILED';
349
- /**
350
- * Failure details for dbInit operation.
351
- */
352
- interface DbInitFailure {
353
- readonly code: DbInitFailureCode;
354
- readonly summary: string;
355
- readonly why: string | undefined;
356
- readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
357
- readonly meta: Record<string, unknown> | undefined;
358
- readonly marker?: {
359
- readonly storageHash?: string;
360
- readonly profileHash?: string;
361
- };
362
- readonly destination?: {
363
- readonly storageHash: string;
364
- readonly profileHash?: string | undefined;
365
- };
366
- }
367
- /**
368
- * Result type for dbInit operation.
369
- * Uses Result pattern: success returns DbInitSuccess, failure returns DbInitFailure.
370
- */
371
- type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
372
- /**
373
- * Successful dbUpdate result.
374
- */
375
- interface DbUpdateSuccess {
376
- readonly mode: 'plan' | 'apply';
377
- readonly plan: {
378
- readonly operations: ReadonlyArray<{
379
- readonly id: string;
380
- readonly label: string;
381
- readonly operationClass: string;
382
- }>;
383
- /**
384
- * Family-agnostic textual preview of the planned operations, e.g.
385
- * `language: 'sql'` for SQL families and `language: 'mongodb-shell'`
386
- * for the Mongo family. Replaces the previous `sql?: readonly string[]`
387
- * field; consumers that previously read `plan.sql` should read
388
- * `plan.preview?.statements.map((s) => s.text)`.
389
- */
390
- readonly preview?: OperationPreview;
391
- };
392
- readonly destination: {
393
- readonly storageHash: string;
394
- readonly profileHash?: string;
395
- };
396
- readonly execution?: {
397
- readonly operationsPlanned: number;
398
- readonly operationsExecuted: number;
399
- };
400
- readonly marker?: {
401
- readonly storageHash: string;
402
- readonly profileHash?: string;
403
- };
404
- readonly summary: string;
405
- }
406
- /**
407
- * Failure codes for dbUpdate operation.
408
- */
409
- type DbUpdateFailureCode = 'PLANNING_FAILED' | 'RUNNER_FAILED' | 'DESTRUCTIVE_CHANGES';
410
- /**
411
- * Failure details for dbUpdate operation.
412
- */
413
- interface DbUpdateFailure {
414
- readonly code: DbUpdateFailureCode;
415
- readonly summary: string;
416
- readonly why: string | undefined;
417
- readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
418
- readonly meta: Record<string, unknown> | undefined;
419
- }
420
- /**
421
- * Result type for dbUpdate operation.
422
- * Uses Result pattern: success returns DbUpdateSuccess, failure returns DbUpdateFailure.
423
- */
424
- type DbUpdateResult = Result<DbUpdateSuccess, DbUpdateFailure>;
425
- /**
426
- * Successful emit result.
427
- * Contains the hashes and paths of emitted files.
428
- */
429
- interface EmitSuccess {
430
- /** Storage hash of the emitted contract */
431
- readonly storageHash: string;
432
- /** Execution hash of the emitted contract (if execution section exists) */
433
- readonly executionHash?: string;
434
- /** Profile hash of the emitted contract (target-specific) */
435
- readonly profileHash: string;
436
- /** The emitted contract as JSON string */
437
- readonly contractJson: string;
438
- /** The emitted contract TypeScript declarations */
439
- readonly contractDts: string;
440
- }
441
- /**
442
- * Failure codes for emit operation.
443
- */
444
- type EmitFailureCode = 'CONTRACT_SOURCE_INVALID' | 'CONTRACT_VALIDATION_FAILED' | 'EMIT_FAILED';
445
- /**
446
- * Failure details for emit operation.
447
- */
448
- interface EmitFailure {
449
- readonly code: EmitFailureCode;
450
- readonly summary: string;
451
- readonly why: string | undefined;
452
- readonly meta: Record<string, unknown> | undefined;
453
- readonly diagnostics?: ContractSourceDiagnostics;
454
- }
455
- /**
456
- * Result type for emit operation.
457
- * Uses Result pattern: success returns EmitSuccess, failure returns EmitFailure.
458
- */
459
- type EmitResult = Result<EmitSuccess, EmitFailure>;
460
- /**
461
- * A pre-planned migration step ready for execution.
462
- * Contains the manifest metadata and the serialized operations from ops.json.
463
- */
464
- interface MigrationApplyStep {
465
- readonly dirName: string;
466
- readonly from: string | null;
467
- readonly to: string;
468
- readonly toContract: Contract;
469
- readonly operations: readonly MigrationPlanOperation[];
470
- /**
471
- * Sorted, deduplicated invariant ids from `migration.json.providedInvariants`.
472
- * Verified at load time by `readMigrationPackage` (manifest copy must equal
473
- * the value derived from `ops.json`). The control-api passes this through
474
- * to the runner via `MigrationPlan.providedInvariants` so target runners
475
- * read the canonical set instead of re-deriving from `operations`.
476
- */
477
- readonly providedInvariants: readonly string[];
478
- }
479
- /**
480
- * Options for the migrationApply operation.
481
- */
482
- interface MigrationApplyOptions {
483
- /**
484
- * Hash of the database state this apply path starts from.
485
- * This is resolved by the caller (typically the CLI orchestration layer).
486
- */
487
- readonly originHash: string;
488
- /**
489
- * Hash of the target contract this apply path must reach.
490
- * This is resolved by the caller (typically the CLI orchestration layer).
491
- */
492
- readonly destinationHash: string;
493
- /**
494
- * Ordered list of migrations to execute from originHash to destinationHash.
495
- * The execution layer does not choose defaults; it only executes this explicit path.
496
- */
497
- readonly pendingMigrations: readonly MigrationApplyStep[];
498
- /**
499
- * Database connection. If provided, migrationApply will connect before executing.
500
- * If omitted, the client must already be connected.
501
- */
502
- readonly connection?: unknown;
503
- /** Optional progress callback for observing operation progress */
504
- readonly onProgress?: OnControlProgress;
505
- }
506
- /**
507
- * Record of a successfully applied migration.
508
- */
509
- interface MigrationApplyAppliedEntry {
510
- readonly dirName: string;
511
- readonly from: string | null;
512
- readonly to: string;
513
- readonly operationsExecuted: number;
514
- }
515
- /**
516
- * Successful migrationApply result.
517
- */
518
- interface MigrationApplySuccess {
519
- readonly migrationsApplied: number;
520
- readonly markerHash: string;
521
- readonly applied: readonly MigrationApplyAppliedEntry[];
522
- readonly summary: string;
523
- }
524
- /**
525
- * Failure codes for migrationApply operation.
526
- */
527
- type MigrationApplyFailureCode = 'RUNNER_FAILED' | 'MIGRATION_PATH_NOT_FOUND';
528
- /**
529
- * Failure details for migrationApply operation.
530
- */
531
- interface MigrationApplyFailure {
532
- readonly code: MigrationApplyFailureCode;
533
- readonly summary: string;
534
- readonly why: string | undefined;
535
- readonly meta: Record<string, unknown> | undefined;
536
- }
537
- /**
538
- * Result type for migrationApply operation.
539
- */
540
- type MigrationApplyResult = Result<MigrationApplySuccess, MigrationApplyFailure>;
541
- /**
542
- * Options for the standalone executeContractEmit function.
543
- *
544
- * `executeContractEmit` is the canonical publication path for both the
545
- * `prisma-next contract emit` CLI command and the `@prisma-next/vite-plugin-contract-emit`
546
- * Vite plugin. Do not duplicate the load → emit → publish dance elsewhere; if a
547
- * caller needs additional behavior, extend this options shape and update the
548
- * single implementation rather than building a parallel publication path.
549
- *
550
- * Concurrent calls for the same output JSON path are serialized per-output via
551
- * a FIFO queue; concurrent calls for distinct outputs run in parallel.
552
- */
553
- interface ContractEmitOptions {
554
- /** Path to the prisma-next.config.ts file */
555
- readonly configPath: string;
556
- /** Optional AbortSignal for cancelling the in-flight emit */
557
- readonly signal?: AbortSignal;
558
- /** Optional progress callback for observing source-resolution and emit spans */
559
- readonly onProgress?: OnControlProgress;
560
- }
561
- /**
562
- * Result from the standalone executeContractEmit function.
563
- *
564
- * Always describes the bytes that were just published to disk. Failures throw
565
- * (config / source-resolution / emit / publish) — callers do not need to
566
- * branch on a result discriminator.
567
- */
568
- interface ContractEmitResult {
569
- /** Hash of the storage contract (schema-level) */
570
- readonly storageHash: string;
571
- /** Hash of the execution contract (if execution section exists) */
572
- readonly executionHash?: string;
573
- /** Hash of the profile (target+extensions) */
574
- readonly profileHash: string;
575
- /** Paths to the emitted files */
576
- readonly files: {
577
- /** Path to the emitted contract.json file */readonly json: string; /** Path to the emitted contract.d.ts file */
578
- readonly dts: string;
579
- };
580
- /**
581
- * Warning surfaced by `validateContractDeps` after a successful publication.
582
- * Callers (CLI, Vite plugin) decide how to render this; the operation does
583
- * not write to stderr itself. Undefined when no warning was raised.
584
- */
585
- readonly validationWarning?: string;
586
- }
587
- /**
588
- * Programmatic control client for Prisma Next operations.
589
- *
590
- * Lifecycle: `connect(connection)` before operations, `close()` when done.
591
- * Both `init()` and `connect()` are auto-called by operations if needed,
592
- * but `connect()` requires a connection so must be called explicitly first
593
- * unless a default connection was provided in options.
594
- *
595
- * @see README.md "Programmatic Control API" section for usage examples
596
- */
597
- interface ControlClient {
598
- /**
599
- * Initializes the client by creating the control plane stack,
600
- * family instance, and validating framework components.
601
- *
602
- * Idempotent (safe to call multiple times).
603
- * Called automatically by `connect()` if not already initialized.
604
- */
605
- init(): void;
606
- /**
607
- * Establishes a database connection.
608
- * Auto-calls `init()` if not already initialized.
609
- * Must be called before any database operations unless a default connection
610
- * was provided in options.
611
- *
612
- * @param connection - Driver-specific connection input (e.g., URL string for Postgres).
613
- * If omitted, uses the default connection from options (if provided).
614
- * @throws If connection fails, already connected, driver is not configured,
615
- * or no connection provided and no default connection in options.
616
- */
617
- connect(connection?: unknown): Promise<void>;
618
- /**
619
- * Closes the database connection.
620
- * Idempotent (safe to call multiple times).
621
- * After close(), can call `connect()` again with same or different URL.
622
- */
623
- close(): Promise<void>;
624
- /**
625
- * Verifies database marker matches the contract.
626
- * Compares storageHash and profileHash.
627
- *
628
- * @returns Structured result (ok: false for mismatch, not throwing)
629
- * @throws If not connected or infrastructure failure
630
- */
631
- verify(options: VerifyOptions): Promise<VerifyDatabaseResult$1>;
632
- /**
633
- * Verifies database schema satisfies the contract requirements.
634
- *
635
- * @param options.strict - If true, extra tables/columns are issues. Default: false
636
- * @returns Structured result with schema issues
637
- * @throws If not connected or infrastructure failure
638
- */
639
- schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult$1>;
640
- /**
641
- * Signs the database with a contract signature.
642
- * Writes or updates the signature if schema verification passes.
643
- * Idempotent (no-op if signature already matches).
644
- *
645
- * @returns Structured result
646
- * @throws If not connected or infrastructure failure
647
- */
648
- sign(options: SignOptions): Promise<SignDatabaseResult$1>;
649
- /**
650
- * Initializes database schema from contract.
651
- * Uses additive-only policy (no destructive changes).
652
- *
653
- * @param options.mode - 'plan' to preview, 'apply' to execute
654
- * @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
655
- * @throws If not connected, target doesn't support migrations, or infrastructure failure
656
- */
657
- dbInit(options: DbInitOptions): Promise<DbInitResult>;
658
- /**
659
- * Updates a database schema to match the current contract.
660
- * Creates the signature table if it does not exist. No preconditions required.
661
- * Allows additive, widening, and destructive operation classes.
662
- *
663
- * @param options.mode - 'plan' to preview, 'apply' to execute
664
- * @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
665
- * @throws If not connected, target doesn't support migrations, or infrastructure failure
666
- */
667
- dbUpdate(options: DbUpdateOptions): Promise<DbUpdateResult>;
668
- /**
669
- * Verifies the database against every contract space (app + extensions).
670
- *
671
- * Loader → aggregate-verifier pipeline:
672
- * - The loader catches layout / drift / disjointness violations.
673
- * - The aggregate verifier surfaces marker-vs-on-disk drift and orphan
674
- * markers, and (unless `skipSchema` is true) per-space schema
675
- * verification with pre-projection (closes F23).
676
- *
677
- * @returns Result pattern: per-space schema results on success;
678
- * structured CLI error on marker / loader failure.
679
- * @throws If not connected or infrastructure failure
680
- */
681
- dbVerify(options: DbVerifyOptions): Promise<ExecuteDbVerifyResult>;
682
- /**
683
- * Reads the contract marker from the database.
684
- * Returns null if no marker exists (fresh database).
685
- *
686
- * @throws If not connected or infrastructure failure
687
- */
688
- readMarker(): Promise<ContractMarkerRecord | null>;
689
- /**
690
- * Reads every marker row (one per contract space). Used by the
691
- * per-space verifier to detect orphan marker rows and marker-vs-on-disk
692
- * drift after a database connection has been established.
693
- */
694
- readAllMarkers(): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
695
- /**
696
- * Applies pre-planned on-disk migrations to the database.
697
- * Each migration runs in its own transaction with full execution checks.
698
- * Resume-safe: re-running after failure picks up from the last applied migration.
699
- *
700
- * @param options.originHash - Explicit source hash for the apply path
701
- * @param options.destinationHash - Explicit destination hash for the apply path
702
- * @param options.pendingMigrations - Ordered migrations to execute
703
- * @returns Result pattern: Ok with applied details, NotOk with failure details
704
- * @throws If not connected, target doesn't support migrations, or infrastructure failure
705
- */
706
- migrationApply(options: MigrationApplyOptions): Promise<MigrationApplyResult>;
707
- /**
708
- * Introspects the database schema.
709
- *
710
- * @returns Raw schema IR
711
- * @throws If not connected or infrastructure failure
712
- */
713
- introspect(options?: IntrospectOptions): Promise<unknown>;
714
- /**
715
- * Converts a schema IR to a schema view for CLI tree rendering.
716
- * Delegates to the family instance's toSchemaView method.
717
- *
718
- * @param schemaIR - The schema IR from introspect()
719
- * @returns CoreSchemaView if the family supports it, undefined otherwise
720
- */
721
- toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
722
- /**
723
- * Infers a PSL contract AST from an introspected schema IR.
724
- * Delegates to the family instance's inferPslContract method.
725
- *
726
- * @param schemaIR - The schema IR from introspect()
727
- * @returns PslDocumentAst if the family supports the capability, undefined otherwise
728
- */
729
- inferPslContract(schemaIR: unknown): PslDocumentAst | undefined;
730
- /**
731
- * Renders a textual preview of a migration plan's operations for the CLI's
732
- * "DDL preview" output. Delegates to the family instance's
733
- * `toOperationPreview` method.
734
- *
735
- * @param operations - The migration plan operations to render
736
- * @returns OperationPreview if the family supports the capability, undefined otherwise
737
- */
738
- toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview | undefined;
739
- /**
740
- * Emits the contract to JSON and TypeScript declarations.
741
- * This is an offline operation that does NOT require a database connection.
742
- * Uses `init()` to create the stack but does NOT call `connect()`.
743
- *
744
- * @returns Result pattern: Ok with emit details, NotOk with failure details
745
- */
746
- emit(options: EmitOptions): Promise<EmitResult>;
747
- }
748
- //#endregion
749
6
  //#region src/control-api/client.d.ts
750
7
  /**
751
8
  * Creates a programmatic control client for Prisma Next operations.