prisma-next 0.5.0-dev.8 → 0.5.0-dev.80

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 (142) hide show
  1. package/dist/cli-errors-B9OBbled.d.mts +3 -0
  2. package/dist/cli-errors-D3_sMh2K.mjs +33 -0
  3. package/dist/cli-errors-D3_sMh2K.mjs.map +1 -0
  4. package/dist/cli.mjs +16 -78
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/client-qVH-rEgd.mjs +1595 -0
  7. package/dist/client-qVH-rEgd.mjs.map +1 -0
  8. package/dist/{result-handler-Ba3zWQsI.mjs → command-helpers-BeZHkxV8.mjs} +70 -47
  9. package/dist/command-helpers-BeZHkxV8.mjs.map +1 -0
  10. package/dist/commands/contract-emit.d.mts.map +1 -1
  11. package/dist/commands/contract-emit.mjs +2 -4
  12. package/dist/commands/contract-infer.d.mts.map +1 -1
  13. package/dist/commands/contract-infer.mjs +2 -4
  14. package/dist/commands/db-init.d.mts.map +1 -1
  15. package/dist/commands/db-init.mjs +16 -13
  16. package/dist/commands/db-init.mjs.map +1 -1
  17. package/dist/commands/db-schema.d.mts.map +1 -1
  18. package/dist/commands/db-schema.mjs +6 -7
  19. package/dist/commands/db-schema.mjs.map +1 -1
  20. package/dist/commands/db-sign.d.mts.map +1 -1
  21. package/dist/commands/db-sign.mjs +9 -9
  22. package/dist/commands/db-sign.mjs.map +1 -1
  23. package/dist/commands/db-update.d.mts.map +1 -1
  24. package/dist/commands/db-update.mjs +15 -13
  25. package/dist/commands/db-update.mjs.map +1 -1
  26. package/dist/commands/db-verify.d.mts.map +1 -1
  27. package/dist/commands/db-verify.mjs +1 -321
  28. package/dist/commands/migration-apply.d.mts +28 -13
  29. package/dist/commands/migration-apply.d.mts.map +1 -1
  30. package/dist/commands/migration-apply.mjs +55 -151
  31. package/dist/commands/migration-apply.mjs.map +1 -1
  32. package/dist/commands/migration-new.d.mts +0 -1
  33. package/dist/commands/migration-new.d.mts.map +1 -1
  34. package/dist/commands/migration-new.mjs +34 -40
  35. package/dist/commands/migration-new.mjs.map +1 -1
  36. package/dist/commands/migration-plan.d.mts +33 -6
  37. package/dist/commands/migration-plan.d.mts.map +1 -1
  38. package/dist/commands/migration-plan.mjs +2 -348
  39. package/dist/commands/migration-ref.d.mts +1 -1
  40. package/dist/commands/migration-ref.d.mts.map +1 -1
  41. package/dist/commands/migration-ref.mjs +8 -12
  42. package/dist/commands/migration-ref.mjs.map +1 -1
  43. package/dist/commands/migration-show.d.mts +13 -7
  44. package/dist/commands/migration-show.d.mts.map +1 -1
  45. package/dist/commands/migration-show.mjs +35 -36
  46. package/dist/commands/migration-show.mjs.map +1 -1
  47. package/dist/commands/migration-status.d.mts +126 -5
  48. package/dist/commands/migration-status.d.mts.map +1 -1
  49. package/dist/commands/migration-status.mjs +2 -4
  50. package/dist/{config-loader-C25b63rJ.mjs → config-loader-B6sJjXTv.mjs} +3 -5
  51. package/dist/config-loader-B6sJjXTv.mjs.map +1 -0
  52. package/dist/config-loader.d.mts +0 -1
  53. package/dist/config-loader.d.mts.map +1 -1
  54. package/dist/config-loader.mjs +2 -3
  55. package/dist/contract-emit-9DBda5Ou.mjs +150 -0
  56. package/dist/contract-emit-9DBda5Ou.mjs.map +1 -0
  57. package/dist/contract-emit-B77TsJqf.mjs +327 -0
  58. package/dist/contract-emit-B77TsJqf.mjs.map +1 -0
  59. package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-Dani0mMW.mjs} +4 -6
  60. package/dist/contract-enrichment-Dani0mMW.mjs.map +1 -0
  61. package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-BK9YFGEG.mjs} +13 -22
  62. package/dist/contract-infer-BK9YFGEG.mjs.map +1 -0
  63. package/dist/db-verify-C0y1PCO2.mjs +404 -0
  64. package/dist/db-verify-C0y1PCO2.mjs.map +1 -0
  65. package/dist/exports/config-types.mjs +1 -2
  66. package/dist/exports/control-api.d.mts +101 -586
  67. package/dist/exports/control-api.d.mts.map +1 -1
  68. package/dist/exports/control-api.mjs +4 -6
  69. package/dist/exports/index.d.mts.map +1 -1
  70. package/dist/exports/index.mjs +28 -30
  71. package/dist/exports/index.mjs.map +1 -1
  72. package/dist/exports/init-output.d.mts +2 -4
  73. package/dist/exports/init-output.d.mts.map +1 -1
  74. package/dist/exports/init-output.mjs +2 -3
  75. package/dist/extension-pack-inputs-C7xgE-vv.mjs +74 -0
  76. package/dist/extension-pack-inputs-C7xgE-vv.mjs.map +1 -0
  77. package/dist/{framework-components-Cr--XBKy.mjs → framework-components-ChqVUxR-.mjs} +3 -4
  78. package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-ChqVUxR-.mjs.map} +1 -1
  79. package/dist/global-flags-Icqpxk23.d.mts +12 -0
  80. package/dist/global-flags-Icqpxk23.d.mts.map +1 -0
  81. package/dist/helpers-eqdN8tH6.mjs +25 -0
  82. package/dist/helpers-eqdN8tH6.mjs.map +1 -0
  83. package/dist/{init-C5220SY9.mjs → init-CoDVPvQ4.mjs} +26 -35
  84. package/dist/init-CoDVPvQ4.mjs.map +1 -0
  85. package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-CWYxGKlb.mjs} +10 -11
  86. package/dist/inspect-live-schema-CWYxGKlb.mjs.map +1 -0
  87. package/dist/migration-cli.d.mts +41 -12
  88. package/dist/migration-cli.d.mts.map +1 -1
  89. package/dist/migration-cli.mjs +309 -86
  90. package/dist/migration-cli.mjs.map +1 -1
  91. package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-B5dORFEv.mjs} +8 -9
  92. package/dist/migration-command-scaffold-B5dORFEv.mjs.map +1 -0
  93. package/dist/migration-plan-C6lVaHsO.mjs +554 -0
  94. package/dist/migration-plan-C6lVaHsO.mjs.map +1 -0
  95. package/dist/{migration-status-DUMiH8_G.mjs → migration-status-CZ-D5k7k.mjs} +272 -65
  96. package/dist/migration-status-CZ-D5k7k.mjs.map +1 -0
  97. package/dist/migrations-D_UJnpuW.mjs +216 -0
  98. package/dist/migrations-D_UJnpuW.mjs.map +1 -0
  99. package/dist/{output-BpcQrnnq.mjs → output-B16Kefzx.mjs} +9 -3
  100. package/dist/output-B16Kefzx.mjs.map +1 -0
  101. package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-DFfvZcYL.mjs} +2 -2
  102. package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-DFfvZcYL.mjs.map} +1 -1
  103. package/dist/result-handler-rmPVKIP2.mjs +25 -0
  104. package/dist/result-handler-rmPVKIP2.mjs.map +1 -0
  105. package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
  106. package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-C_hFNbAn.mjs} +4 -28
  107. package/dist/terminal-ui-C_hFNbAn.mjs.map +1 -0
  108. package/dist/types-D7x-IFLO.d.mts +858 -0
  109. package/dist/types-D7x-IFLO.d.mts.map +1 -0
  110. package/dist/{verify-Bkycc-Tf.mjs → verify-CiwNWM9N.mjs} +3 -4
  111. package/dist/verify-CiwNWM9N.mjs.map +1 -0
  112. package/package.json +19 -17
  113. package/dist/cli-errors-BFYgBH3L.d.mts +0 -4
  114. package/dist/cli-errors-Cd79vmTH.mjs +0 -5
  115. package/dist/client-CrsnY58k.mjs +0 -997
  116. package/dist/client-CrsnY58k.mjs.map +0 -1
  117. package/dist/commands/db-verify.mjs.map +0 -1
  118. package/dist/commands/migration-plan.mjs.map +0 -1
  119. package/dist/config-loader-C25b63rJ.mjs.map +0 -1
  120. package/dist/contract-emit--feXyNd7.mjs +0 -4
  121. package/dist/contract-emit-NJ01hiiv.mjs +0 -195
  122. package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
  123. package/dist/contract-emit-V5SSitUT.mjs +0 -122
  124. package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
  125. package/dist/contract-enrichment-CAOELa-H.mjs.map +0 -1
  126. package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
  127. package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
  128. package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
  129. package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
  130. package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
  131. package/dist/init-C5220SY9.mjs.map +0 -1
  132. package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
  133. package/dist/migration-command-scaffold-B3B09et6.mjs.map +0 -1
  134. package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
  135. package/dist/migrations-Bo5WtTla.mjs +0 -153
  136. package/dist/migrations-Bo5WtTla.mjs.map +0 -1
  137. package/dist/output-BpcQrnnq.mjs.map +0 -1
  138. package/dist/result-handler-Ba3zWQsI.mjs.map +0 -1
  139. package/dist/terminal-ui-C3ZLwQxK.mjs.map +0 -1
  140. package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
  141. package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
  142. package/dist/verify-Bkycc-Tf.mjs.map +0 -1
@@ -1,997 +0,0 @@
1
- import { t as assertFrameworkComponentsCompatible } from "./framework-components-Cr--XBKy.mjs";
2
- import { t as enrichContract } from "./contract-enrichment-CAOELa-H.mjs";
3
- import { t as extractOperationStatements } from "./extract-operation-statements-DsFfxXVZ.mjs";
4
- import { emit } from "@prisma-next/emitter";
5
- import { notOk, ok } from "@prisma-next/utils/result";
6
- import { ifDefined } from "@prisma-next/utils/defined";
7
- import { createControlStack, hasMigrations, hasSchemaView } from "@prisma-next/framework-components/control";
8
- import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
9
-
10
- //#region src/control-api/errors.ts
11
- var ContractValidationError = class extends Error {
12
- cause;
13
- constructor(message, cause) {
14
- super(message);
15
- this.name = "ContractValidationError";
16
- this.cause = cause;
17
- }
18
- };
19
-
20
- //#endregion
21
- //#region src/control-api/operations/migration-helpers.ts
22
- /**
23
- * Strips operation objects to their public shape (id, label, operationClass).
24
- * Used at the API boundary to avoid leaking internal fields (precheck, execute, postcheck, etc.).
25
- */
26
- function stripOperations(operations) {
27
- return operations.map((op) => ({
28
- id: op.id,
29
- label: op.label,
30
- operationClass: op.operationClass
31
- }));
32
- }
33
- /**
34
- * Creates per-operation progress callbacks for the runner.
35
- * Returns undefined when no onProgress callback is provided.
36
- */
37
- function createOperationCallbacks(onProgress, action, parentSpanId) {
38
- if (!onProgress) return;
39
- return {
40
- onOperationStart: (op) => {
41
- onProgress({
42
- action,
43
- kind: "spanStart",
44
- spanId: `operation:${op.id}`,
45
- parentSpanId,
46
- label: op.label
47
- });
48
- },
49
- onOperationComplete: (op) => {
50
- onProgress({
51
- action,
52
- kind: "spanEnd",
53
- spanId: `operation:${op.id}`,
54
- outcome: "ok"
55
- });
56
- }
57
- };
58
- }
59
-
60
- //#endregion
61
- //#region src/control-api/operations/db-init.ts
62
- /**
63
- * Executes the dbInit operation.
64
- *
65
- * This is the core logic extracted from the CLI command, without any file I/O,
66
- * process.exit(), or console output. It uses the Result pattern to return
67
- * success or failure details.
68
- *
69
- * @param options - The options for executing dbInit
70
- * @returns Result with DbInitSuccess on success, DbInitFailure on failure
71
- */
72
- async function executeDbInit(options) {
73
- const { driver, familyInstance, contract, mode, migrations, frameworkComponents, onProgress } = options;
74
- const planner = migrations.createPlanner(familyInstance);
75
- const runner = migrations.createRunner(familyInstance);
76
- const introspectSpanId = "introspect";
77
- onProgress?.({
78
- action: "dbInit",
79
- kind: "spanStart",
80
- spanId: introspectSpanId,
81
- label: "Introspecting database schema"
82
- });
83
- const schemaIR = await familyInstance.introspect({ driver });
84
- onProgress?.({
85
- action: "dbInit",
86
- kind: "spanEnd",
87
- spanId: introspectSpanId,
88
- outcome: "ok"
89
- });
90
- const policy = { allowedOperationClasses: ["additive"] };
91
- const planSpanId = "plan";
92
- onProgress?.({
93
- action: "dbInit",
94
- kind: "spanStart",
95
- spanId: planSpanId,
96
- label: "Planning migration"
97
- });
98
- const plannerResult = await planner.plan({
99
- contract,
100
- schema: schemaIR,
101
- policy,
102
- fromHash: "",
103
- frameworkComponents
104
- });
105
- if (plannerResult.kind === "failure") {
106
- onProgress?.({
107
- action: "dbInit",
108
- kind: "spanEnd",
109
- spanId: planSpanId,
110
- outcome: "error"
111
- });
112
- return notOk({
113
- code: "PLANNING_FAILED",
114
- summary: "Migration planning failed due to conflicts",
115
- conflicts: plannerResult.conflicts,
116
- why: void 0,
117
- meta: void 0
118
- });
119
- }
120
- const migrationPlan = plannerResult.plan;
121
- onProgress?.({
122
- action: "dbInit",
123
- kind: "spanEnd",
124
- spanId: planSpanId,
125
- outcome: "ok"
126
- });
127
- const checkMarkerSpanId = "checkMarker";
128
- onProgress?.({
129
- action: "dbInit",
130
- kind: "spanStart",
131
- spanId: checkMarkerSpanId,
132
- label: "Checking database signature"
133
- });
134
- const existingMarker = await familyInstance.readMarker({ driver });
135
- if (existingMarker) {
136
- if (existingMarker.storageHash === migrationPlan.destination.storageHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash)) {
137
- onProgress?.({
138
- action: "dbInit",
139
- kind: "spanEnd",
140
- spanId: checkMarkerSpanId,
141
- outcome: "skipped"
142
- });
143
- return ok({
144
- mode,
145
- plan: { operations: [] },
146
- destination: {
147
- storageHash: migrationPlan.destination.storageHash,
148
- ...ifDefined("profileHash", migrationPlan.destination.profileHash)
149
- },
150
- ...ifDefined("execution", mode === "apply" ? {
151
- operationsPlanned: 0,
152
- operationsExecuted: 0
153
- } : void 0),
154
- ...ifDefined("marker", mode === "apply" ? {
155
- storageHash: existingMarker.storageHash,
156
- profileHash: existingMarker.profileHash
157
- } : void 0),
158
- summary: "Database already at target contract state"
159
- });
160
- }
161
- onProgress?.({
162
- action: "dbInit",
163
- kind: "spanEnd",
164
- spanId: checkMarkerSpanId,
165
- outcome: "error"
166
- });
167
- return notOk({
168
- code: "MARKER_ORIGIN_MISMATCH",
169
- summary: "Existing contract marker does not match plan destination",
170
- marker: {
171
- storageHash: existingMarker.storageHash,
172
- profileHash: existingMarker.profileHash
173
- },
174
- destination: {
175
- storageHash: migrationPlan.destination.storageHash,
176
- profileHash: migrationPlan.destination.profileHash
177
- },
178
- why: void 0,
179
- conflicts: void 0,
180
- meta: void 0
181
- });
182
- }
183
- onProgress?.({
184
- action: "dbInit",
185
- kind: "spanEnd",
186
- spanId: checkMarkerSpanId,
187
- outcome: "ok"
188
- });
189
- if (mode === "plan") {
190
- const planSql = extractOperationStatements(familyInstance.familyId, migrationPlan.operations);
191
- return ok({
192
- mode: "plan",
193
- plan: {
194
- operations: stripOperations(migrationPlan.operations),
195
- ...ifDefined("sql", planSql)
196
- },
197
- destination: {
198
- storageHash: migrationPlan.destination.storageHash,
199
- ...ifDefined("profileHash", migrationPlan.destination.profileHash)
200
- },
201
- summary: `Planned ${migrationPlan.operations.length} operation(s)`
202
- });
203
- }
204
- const applySpanId = "apply";
205
- onProgress?.({
206
- action: "dbInit",
207
- kind: "spanStart",
208
- spanId: applySpanId,
209
- label: "Applying migration plan"
210
- });
211
- const callbacks = createOperationCallbacks(onProgress, "dbInit", applySpanId);
212
- const runnerResult = await runner.execute({
213
- plan: migrationPlan,
214
- driver,
215
- destinationContract: contract,
216
- policy,
217
- ...ifDefined("callbacks", callbacks),
218
- executionChecks: {
219
- prechecks: false,
220
- postchecks: false,
221
- idempotencyChecks: false
222
- },
223
- frameworkComponents
224
- });
225
- if (!runnerResult.ok) {
226
- onProgress?.({
227
- action: "dbInit",
228
- kind: "spanEnd",
229
- spanId: applySpanId,
230
- outcome: "error"
231
- });
232
- return notOk({
233
- code: "RUNNER_FAILED",
234
- summary: runnerResult.failure.summary,
235
- why: runnerResult.failure.why,
236
- meta: runnerResult.failure.meta,
237
- conflicts: void 0
238
- });
239
- }
240
- const execution = runnerResult.value;
241
- onProgress?.({
242
- action: "dbInit",
243
- kind: "spanEnd",
244
- spanId: applySpanId,
245
- outcome: "ok"
246
- });
247
- return ok({
248
- mode: "apply",
249
- plan: { operations: stripOperations(migrationPlan.operations) },
250
- destination: {
251
- storageHash: migrationPlan.destination.storageHash,
252
- ...ifDefined("profileHash", migrationPlan.destination.profileHash)
253
- },
254
- execution: {
255
- operationsPlanned: execution.operationsPlanned,
256
- operationsExecuted: execution.operationsExecuted
257
- },
258
- marker: migrationPlan.destination.profileHash ? {
259
- storageHash: migrationPlan.destination.storageHash,
260
- profileHash: migrationPlan.destination.profileHash
261
- } : { storageHash: migrationPlan.destination.storageHash },
262
- summary: `Applied ${execution.operationsExecuted} operation(s), database signed`
263
- });
264
- }
265
-
266
- //#endregion
267
- //#region src/control-api/operations/db-update.ts
268
- const DB_UPDATE_POLICY = { allowedOperationClasses: [
269
- "additive",
270
- "widening",
271
- "destructive"
272
- ] };
273
- /**
274
- * Executes the db update operation: introspect → plan → (optionally) apply → marker.
275
- *
276
- * db update is a pure reconciliation command: it introspects the live schema, plans the diff
277
- * to the destination contract, and applies operations. The marker is bookkeeping only — written
278
- * after apply so that `verify` and `db init` can reference it, but never read or validated
279
- * by db update itself. The runner creates the marker table if it does not exist.
280
- */
281
- async function executeDbUpdate(options) {
282
- const { driver, familyInstance, contract, mode, migrations, frameworkComponents, onProgress } = options;
283
- const planner = migrations.createPlanner(familyInstance);
284
- const runner = migrations.createRunner(familyInstance);
285
- const introspectSpanId = "introspect";
286
- onProgress?.({
287
- action: "dbUpdate",
288
- kind: "spanStart",
289
- spanId: introspectSpanId,
290
- label: "Introspecting database schema"
291
- });
292
- const schemaIR = await familyInstance.introspect({ driver });
293
- onProgress?.({
294
- action: "dbUpdate",
295
- kind: "spanEnd",
296
- spanId: introspectSpanId,
297
- outcome: "ok"
298
- });
299
- const policy = DB_UPDATE_POLICY;
300
- const planSpanId = "plan";
301
- onProgress?.({
302
- action: "dbUpdate",
303
- kind: "spanStart",
304
- spanId: planSpanId,
305
- label: "Planning migration"
306
- });
307
- const plannerResult = await planner.plan({
308
- contract,
309
- schema: schemaIR,
310
- policy,
311
- fromHash: "",
312
- frameworkComponents
313
- });
314
- if (plannerResult.kind === "failure") {
315
- onProgress?.({
316
- action: "dbUpdate",
317
- kind: "spanEnd",
318
- spanId: planSpanId,
319
- outcome: "error"
320
- });
321
- return notOk({
322
- code: "PLANNING_FAILED",
323
- summary: "Migration planning failed due to conflicts",
324
- conflicts: plannerResult.conflicts,
325
- why: void 0,
326
- meta: void 0
327
- });
328
- }
329
- onProgress?.({
330
- action: "dbUpdate",
331
- kind: "spanEnd",
332
- spanId: planSpanId,
333
- outcome: "ok"
334
- });
335
- const migrationPlan = plannerResult.plan;
336
- if (mode === "plan") {
337
- const planSql = extractOperationStatements(familyInstance.familyId, migrationPlan.operations);
338
- return ok({
339
- mode: "plan",
340
- plan: {
341
- operations: stripOperations(migrationPlan.operations),
342
- ...planSql !== void 0 ? { sql: planSql } : {}
343
- },
344
- destination: {
345
- storageHash: migrationPlan.destination.storageHash,
346
- ...ifDefined("profileHash", migrationPlan.destination.profileHash)
347
- },
348
- summary: `Planned ${migrationPlan.operations.length} operation(s)`
349
- });
350
- }
351
- if (!options.acceptDataLoss) {
352
- const destructiveOps = migrationPlan.operations.filter((op) => op.operationClass === "destructive").map((op) => ({
353
- id: op.id,
354
- label: op.label
355
- }));
356
- if (destructiveOps.length > 0) return notOk({
357
- code: "DESTRUCTIVE_CHANGES",
358
- summary: `Planned ${destructiveOps.length} destructive operation(s) that require confirmation`,
359
- why: "Destructive operations require confirmation — re-run with -y to accept",
360
- conflicts: void 0,
361
- meta: { destructiveOperations: destructiveOps }
362
- });
363
- }
364
- const applySpanId = "apply";
365
- onProgress?.({
366
- action: "dbUpdate",
367
- kind: "spanStart",
368
- spanId: applySpanId,
369
- label: "Applying migration plan"
370
- });
371
- const callbacks = createOperationCallbacks(onProgress, "dbUpdate", applySpanId);
372
- const runnerResult = await runner.execute({
373
- plan: migrationPlan,
374
- driver,
375
- destinationContract: contract,
376
- policy,
377
- ...callbacks ? { callbacks } : {},
378
- executionChecks: {
379
- prechecks: false,
380
- postchecks: false,
381
- idempotencyChecks: false
382
- },
383
- frameworkComponents
384
- });
385
- if (!runnerResult.ok) {
386
- onProgress?.({
387
- action: "dbUpdate",
388
- kind: "spanEnd",
389
- spanId: applySpanId,
390
- outcome: "error"
391
- });
392
- return notOk({
393
- code: "RUNNER_FAILED",
394
- summary: runnerResult.failure.summary,
395
- why: runnerResult.failure.why,
396
- meta: runnerResult.failure.meta,
397
- conflicts: void 0
398
- });
399
- }
400
- const execution = runnerResult.value;
401
- onProgress?.({
402
- action: "dbUpdate",
403
- kind: "spanEnd",
404
- spanId: applySpanId,
405
- outcome: "ok"
406
- });
407
- return ok({
408
- mode: "apply",
409
- plan: { operations: stripOperations(migrationPlan.operations) },
410
- destination: {
411
- storageHash: migrationPlan.destination.storageHash,
412
- ...ifDefined("profileHash", migrationPlan.destination.profileHash)
413
- },
414
- execution: {
415
- operationsPlanned: execution.operationsPlanned,
416
- operationsExecuted: execution.operationsExecuted
417
- },
418
- marker: migrationPlan.destination.profileHash ? {
419
- storageHash: migrationPlan.destination.storageHash,
420
- profileHash: migrationPlan.destination.profileHash
421
- } : { storageHash: migrationPlan.destination.storageHash },
422
- summary: execution.operationsExecuted === 0 ? "Database already matches contract, signature updated" : `Applied ${execution.operationsExecuted} operation(s), signature updated`
423
- });
424
- }
425
-
426
- //#endregion
427
- //#region src/control-api/operations/migration-apply.ts
428
- async function executeMigrationApply(options) {
429
- const { driver, familyInstance, originHash, destinationHash, pendingMigrations, migrations, frameworkComponents, targetId, onProgress } = options;
430
- if (pendingMigrations.length === 0) {
431
- if (originHash !== destinationHash) return notOk({
432
- code: "MIGRATION_PATH_NOT_FOUND",
433
- summary: "No migrations provided for requested origin and destination",
434
- why: `Requested ${originHash} -> ${destinationHash} but pendingMigrations is empty`,
435
- meta: {
436
- originHash,
437
- destinationHash
438
- }
439
- });
440
- return ok({
441
- migrationsApplied: 0,
442
- markerHash: originHash,
443
- applied: [],
444
- summary: "Already up to date"
445
- });
446
- }
447
- const firstMigration = pendingMigrations[0];
448
- const lastMigration = pendingMigrations[pendingMigrations.length - 1];
449
- if (firstMigration.from !== originHash || lastMigration.to !== destinationHash) return notOk({
450
- code: "MIGRATION_PATH_NOT_FOUND",
451
- summary: "Migration apply path does not match requested origin and destination",
452
- why: `Path resolved as ${firstMigration.from} -> ${lastMigration.to}, but requested ${originHash} -> ${destinationHash}`,
453
- meta: {
454
- originHash,
455
- destinationHash,
456
- pathOrigin: firstMigration.from,
457
- pathDestination: lastMigration.to
458
- }
459
- });
460
- for (let i = 1; i < pendingMigrations.length; i++) {
461
- const previous = pendingMigrations[i - 1];
462
- const current = pendingMigrations[i];
463
- if (previous.to !== current.from) return notOk({
464
- code: "MIGRATION_PATH_NOT_FOUND",
465
- summary: "Migration apply path contains a discontinuity between adjacent migrations",
466
- why: `Migration "${previous.dirName}" ends at ${previous.to}, but next migration "${current.dirName}" starts at ${current.from}`,
467
- meta: {
468
- originHash,
469
- destinationHash,
470
- previousDirName: previous.dirName,
471
- previousTo: previous.to,
472
- currentDirName: current.dirName,
473
- currentFrom: current.from,
474
- discontinuityIndex: i
475
- }
476
- });
477
- }
478
- const runner = migrations.createRunner(familyInstance);
479
- const applied = [];
480
- for (const migration of pendingMigrations) {
481
- const migrationSpanId = `migration:${migration.dirName}`;
482
- onProgress?.({
483
- action: "migrationApply",
484
- kind: "spanStart",
485
- spanId: migrationSpanId,
486
- label: `Applying ${migration.dirName}`
487
- });
488
- const { operations } = migration;
489
- const policy = { allowedOperationClasses: [
490
- "additive",
491
- "widening",
492
- "destructive",
493
- "data"
494
- ] };
495
- const plan = {
496
- targetId,
497
- origin: migration.from === EMPTY_CONTRACT_HASH ? null : { storageHash: migration.from },
498
- destination: { storageHash: migration.to },
499
- operations
500
- };
501
- const destinationContract = familyInstance.validateContract(migration.toContract);
502
- const runnerResult = await runner.execute({
503
- plan,
504
- driver,
505
- destinationContract,
506
- policy,
507
- executionChecks: {
508
- prechecks: true,
509
- postchecks: true,
510
- idempotencyChecks: true
511
- },
512
- frameworkComponents
513
- });
514
- if (!runnerResult.ok) {
515
- onProgress?.({
516
- action: "migrationApply",
517
- kind: "spanEnd",
518
- spanId: migrationSpanId,
519
- outcome: "error"
520
- });
521
- return notOk({
522
- code: "RUNNER_FAILED",
523
- summary: runnerResult.failure.summary,
524
- why: runnerResult.failure.why,
525
- meta: {
526
- migration: migration.dirName,
527
- from: migration.from,
528
- to: migration.to,
529
- ...runnerResult.failure.meta ?? {}
530
- }
531
- });
532
- }
533
- onProgress?.({
534
- action: "migrationApply",
535
- kind: "spanEnd",
536
- spanId: migrationSpanId,
537
- outcome: "ok"
538
- });
539
- applied.push({
540
- dirName: migration.dirName,
541
- from: migration.from,
542
- to: migration.to,
543
- operationsExecuted: runnerResult.value.operationsExecuted
544
- });
545
- }
546
- const finalHash = pendingMigrations[pendingMigrations.length - 1].to;
547
- const totalOps = applied.reduce((sum, a) => sum + a.operationsExecuted, 0);
548
- return ok({
549
- migrationsApplied: applied.length,
550
- markerHash: finalHash,
551
- applied,
552
- summary: `Applied ${applied.length} migration(s) (${totalOps} operation(s)), marker at ${finalHash}`
553
- });
554
- }
555
-
556
- //#endregion
557
- //#region src/control-api/client.ts
558
- /**
559
- * Creates a programmatic control client for Prisma Next operations.
560
- *
561
- * The client accepts framework component descriptors at creation time,
562
- * manages driver lifecycle via connect()/close(), and exposes domain
563
- * operations that delegate to the existing family instance methods.
564
- *
565
- * @see {@link ControlClient} for the client interface
566
- * @see README.md "Programmatic Control API" section for usage examples
567
- */
568
- function createControlClient(options) {
569
- return new ControlClientImpl(options);
570
- }
571
- /**
572
- * Implementation of ControlClient.
573
- * Manages initialization and connection state, delegates operations to family instance.
574
- */
575
- var ControlClientImpl = class {
576
- options;
577
- stack = null;
578
- driver = null;
579
- familyInstance = null;
580
- frameworkComponents = null;
581
- initialized = false;
582
- defaultConnection;
583
- constructor(options) {
584
- this.options = options;
585
- this.defaultConnection = options.connection;
586
- }
587
- init() {
588
- if (this.initialized) return;
589
- this.stack = createControlStack({
590
- family: this.options.family,
591
- target: this.options.target,
592
- adapter: this.options.adapter,
593
- driver: this.options.driver,
594
- extensionPacks: this.options.extensionPacks
595
- });
596
- this.familyInstance = this.options.family.create(this.stack);
597
- const rawComponents = [
598
- this.options.target,
599
- this.options.adapter,
600
- ...this.options.extensionPacks ?? []
601
- ];
602
- this.frameworkComponents = assertFrameworkComponentsCompatible(this.options.family.familyId, this.options.target.targetId, rawComponents);
603
- this.initialized = true;
604
- }
605
- async connect(connection) {
606
- this.init();
607
- if (this.driver) throw new Error("Already connected. Call close() before reconnecting.");
608
- const resolvedConnection = connection ?? this.defaultConnection;
609
- if (resolvedConnection === void 0) throw new Error("No connection provided. Pass a connection to connect() or provide a default connection when creating the client.");
610
- if (!this.stack?.driver) throw new Error("Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations.");
611
- this.driver = await this.stack.driver.create(resolvedConnection);
612
- }
613
- async close() {
614
- if (this.driver) {
615
- await this.driver.close();
616
- this.driver = null;
617
- }
618
- }
619
- async ensureConnected() {
620
- this.init();
621
- if (!this.driver && this.defaultConnection !== void 0) await this.connect(this.defaultConnection);
622
- if (!this.driver || !this.familyInstance || !this.frameworkComponents) throw new Error("Not connected. Call connect(connection) first.");
623
- return {
624
- driver: this.driver,
625
- familyInstance: this.familyInstance,
626
- frameworkComponents: this.frameworkComponents
627
- };
628
- }
629
- async connectWithProgress(connection, action, onProgress) {
630
- if (connection === void 0) return;
631
- onProgress?.({
632
- action,
633
- kind: "spanStart",
634
- spanId: "connect",
635
- label: "Connecting to database..."
636
- });
637
- try {
638
- await this.connect(connection);
639
- onProgress?.({
640
- action,
641
- kind: "spanEnd",
642
- spanId: "connect",
643
- outcome: "ok"
644
- });
645
- } catch (error) {
646
- onProgress?.({
647
- action,
648
- kind: "spanEnd",
649
- spanId: "connect",
650
- outcome: "error"
651
- });
652
- throw error;
653
- }
654
- }
655
- async verify(options) {
656
- const { onProgress } = options;
657
- await this.connectWithProgress(options.connection, "verify", onProgress);
658
- const { driver, familyInstance } = await this.ensureConnected();
659
- let contract;
660
- try {
661
- contract = familyInstance.validateContract(options.contract);
662
- } catch (error) {
663
- throw new ContractValidationError(error instanceof Error ? error.message : String(error), error);
664
- }
665
- onProgress?.({
666
- action: "verify",
667
- kind: "spanStart",
668
- spanId: "verify",
669
- label: "Verifying database marker..."
670
- });
671
- try {
672
- const result = await familyInstance.verify({
673
- driver,
674
- contract,
675
- expectedTargetId: this.options.target.targetId,
676
- contractPath: ""
677
- });
678
- onProgress?.({
679
- action: "verify",
680
- kind: "spanEnd",
681
- spanId: "verify",
682
- outcome: result.ok ? "ok" : "error"
683
- });
684
- return result;
685
- } catch (error) {
686
- onProgress?.({
687
- action: "verify",
688
- kind: "spanEnd",
689
- spanId: "verify",
690
- outcome: "error"
691
- });
692
- throw error;
693
- }
694
- }
695
- async schemaVerify(options) {
696
- const { onProgress } = options;
697
- await this.connectWithProgress(options.connection, "schemaVerify", onProgress);
698
- const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
699
- let contract;
700
- try {
701
- contract = familyInstance.validateContract(options.contract);
702
- } catch (error) {
703
- throw new ContractValidationError(error instanceof Error ? error.message : String(error), error);
704
- }
705
- onProgress?.({
706
- action: "schemaVerify",
707
- kind: "spanStart",
708
- spanId: "schemaVerify",
709
- label: "Verifying database schema..."
710
- });
711
- try {
712
- const result = await familyInstance.schemaVerify({
713
- driver,
714
- contract,
715
- strict: options.strict ?? false,
716
- contractPath: "",
717
- frameworkComponents
718
- });
719
- onProgress?.({
720
- action: "schemaVerify",
721
- kind: "spanEnd",
722
- spanId: "schemaVerify",
723
- outcome: result.ok ? "ok" : "error"
724
- });
725
- return result;
726
- } catch (error) {
727
- onProgress?.({
728
- action: "schemaVerify",
729
- kind: "spanEnd",
730
- spanId: "schemaVerify",
731
- outcome: "error"
732
- });
733
- throw error;
734
- }
735
- }
736
- async sign(options) {
737
- const { onProgress } = options;
738
- await this.connectWithProgress(options.connection, "sign", onProgress);
739
- const { driver, familyInstance } = await this.ensureConnected();
740
- let contract;
741
- try {
742
- contract = familyInstance.validateContract(options.contract);
743
- } catch (error) {
744
- throw new ContractValidationError(error instanceof Error ? error.message : String(error), error);
745
- }
746
- onProgress?.({
747
- action: "sign",
748
- kind: "spanStart",
749
- spanId: "sign",
750
- label: "Signing database..."
751
- });
752
- try {
753
- const result = await familyInstance.sign({
754
- driver,
755
- contract,
756
- contractPath: options.contractPath ?? "",
757
- ...ifDefined("configPath", options.configPath)
758
- });
759
- onProgress?.({
760
- action: "sign",
761
- kind: "spanEnd",
762
- spanId: "sign",
763
- outcome: "ok"
764
- });
765
- return result;
766
- } catch (error) {
767
- onProgress?.({
768
- action: "sign",
769
- kind: "spanEnd",
770
- spanId: "sign",
771
- outcome: "error"
772
- });
773
- throw error;
774
- }
775
- }
776
- async dbInit(options) {
777
- const { onProgress } = options;
778
- await this.connectWithProgress(options.connection, "dbInit", onProgress);
779
- const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
780
- if (!hasMigrations(this.options.target)) throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
781
- let contract;
782
- try {
783
- contract = familyInstance.validateContract(options.contract);
784
- } catch (error) {
785
- throw new ContractValidationError(error instanceof Error ? error.message : String(error), error);
786
- }
787
- return executeDbInit({
788
- driver,
789
- familyInstance,
790
- contract,
791
- mode: options.mode,
792
- migrations: this.options.target.migrations,
793
- frameworkComponents,
794
- ...ifDefined("onProgress", onProgress)
795
- });
796
- }
797
- async dbUpdate(options) {
798
- const { onProgress } = options;
799
- await this.connectWithProgress(options.connection, "dbUpdate", onProgress);
800
- const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
801
- if (!hasMigrations(this.options.target)) throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
802
- let contract;
803
- try {
804
- contract = familyInstance.validateContract(options.contract);
805
- } catch (error) {
806
- throw new ContractValidationError(error instanceof Error ? error.message : String(error), error);
807
- }
808
- return executeDbUpdate({
809
- driver,
810
- familyInstance,
811
- contract,
812
- mode: options.mode,
813
- migrations: this.options.target.migrations,
814
- frameworkComponents,
815
- ...ifDefined("acceptDataLoss", options.acceptDataLoss),
816
- ...ifDefined("onProgress", onProgress)
817
- });
818
- }
819
- async readMarker() {
820
- const { driver, familyInstance } = await this.ensureConnected();
821
- return familyInstance.readMarker({ driver });
822
- }
823
- async migrationApply(options) {
824
- const { onProgress } = options;
825
- await this.connectWithProgress(options.connection, "migrationApply", onProgress);
826
- const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
827
- if (!hasMigrations(this.options.target)) throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
828
- return executeMigrationApply({
829
- driver,
830
- familyInstance,
831
- originHash: options.originHash,
832
- destinationHash: options.destinationHash,
833
- pendingMigrations: options.pendingMigrations,
834
- migrations: this.options.target.migrations,
835
- frameworkComponents,
836
- targetId: this.options.target.targetId,
837
- ...onProgress ? { onProgress } : {}
838
- });
839
- }
840
- async introspect(options) {
841
- const onProgress = options?.onProgress;
842
- await this.connectWithProgress(options?.connection, "introspect", onProgress);
843
- const { driver, familyInstance } = await this.ensureConnected();
844
- options?.schema;
845
- onProgress?.({
846
- action: "introspect",
847
- kind: "spanStart",
848
- spanId: "introspect",
849
- label: "Introspecting database schema..."
850
- });
851
- try {
852
- const result = await familyInstance.introspect({ driver });
853
- onProgress?.({
854
- action: "introspect",
855
- kind: "spanEnd",
856
- spanId: "introspect",
857
- outcome: "ok"
858
- });
859
- return result;
860
- } catch (error) {
861
- onProgress?.({
862
- action: "introspect",
863
- kind: "spanEnd",
864
- spanId: "introspect",
865
- outcome: "error"
866
- });
867
- throw error;
868
- }
869
- }
870
- toSchemaView(schemaIR) {
871
- this.init();
872
- if (this.familyInstance && hasSchemaView(this.familyInstance)) return this.familyInstance.toSchemaView(schemaIR);
873
- }
874
- async emit(options) {
875
- const { onProgress, contractConfig } = options;
876
- this.init();
877
- if (!this.familyInstance) throw new Error("Family instance was not initialized. This is a bug.");
878
- let contractRaw;
879
- onProgress?.({
880
- action: "emit",
881
- kind: "spanStart",
882
- spanId: "resolveSource",
883
- label: "Resolving contract source..."
884
- });
885
- try {
886
- const stack = this.stack;
887
- const sourceContext = {
888
- composedExtensionPacks: stack.extensionPacks.map((p) => p.id),
889
- scalarTypeDescriptors: stack.scalarTypeDescriptors,
890
- authoringContributions: stack.authoringContributions,
891
- codecLookup: stack.codecLookup,
892
- controlMutationDefaults: stack.controlMutationDefaults,
893
- resolvedInputs: contractConfig.source.inputs ?? []
894
- };
895
- const providerResult = await contractConfig.source.load(sourceContext);
896
- if (!providerResult.ok) {
897
- onProgress?.({
898
- action: "emit",
899
- kind: "spanEnd",
900
- spanId: "resolveSource",
901
- outcome: "error"
902
- });
903
- return notOk({
904
- code: "CONTRACT_SOURCE_INVALID",
905
- summary: providerResult.failure.summary,
906
- why: providerResult.failure.summary,
907
- meta: providerResult.failure.meta,
908
- diagnostics: providerResult.failure
909
- });
910
- }
911
- contractRaw = providerResult.value;
912
- onProgress?.({
913
- action: "emit",
914
- kind: "spanEnd",
915
- spanId: "resolveSource",
916
- outcome: "ok"
917
- });
918
- } catch (error) {
919
- onProgress?.({
920
- action: "emit",
921
- kind: "spanEnd",
922
- spanId: "resolveSource",
923
- outcome: "error"
924
- });
925
- const message = error instanceof Error ? error.message : String(error);
926
- return notOk({
927
- code: "CONTRACT_SOURCE_INVALID",
928
- summary: "Failed to resolve contract source",
929
- why: message,
930
- diagnostics: {
931
- summary: "Contract source provider threw an exception",
932
- diagnostics: [{
933
- code: "PROVIDER_THROW",
934
- message
935
- }]
936
- },
937
- meta: void 0
938
- });
939
- }
940
- onProgress?.({
941
- action: "emit",
942
- kind: "spanStart",
943
- spanId: "emit",
944
- label: "Emitting contract..."
945
- });
946
- try {
947
- const enrichedIR = enrichContract(contractRaw, this.frameworkComponents ?? []);
948
- try {
949
- this.familyInstance.validateContract(enrichedIR);
950
- } catch (error) {
951
- onProgress?.({
952
- action: "emit",
953
- kind: "spanEnd",
954
- spanId: "emit",
955
- outcome: "error"
956
- });
957
- return notOk({
958
- code: "CONTRACT_VALIDATION_FAILED",
959
- summary: "Contract validation failed",
960
- why: error instanceof Error ? error.message : String(error),
961
- meta: void 0
962
- });
963
- }
964
- const result = await emit(enrichedIR, this.stack, this.options.family.emission);
965
- onProgress?.({
966
- action: "emit",
967
- kind: "spanEnd",
968
- spanId: "emit",
969
- outcome: "ok"
970
- });
971
- return ok({
972
- storageHash: result.storageHash,
973
- ...ifDefined("executionHash", result.executionHash),
974
- profileHash: result.profileHash,
975
- contractJson: result.contractJson,
976
- contractDts: result.contractDts
977
- });
978
- } catch (error) {
979
- onProgress?.({
980
- action: "emit",
981
- kind: "spanEnd",
982
- spanId: "emit",
983
- outcome: "error"
984
- });
985
- return notOk({
986
- code: "EMIT_FAILED",
987
- summary: "Failed to emit contract",
988
- why: error instanceof Error ? error.message : String(error),
989
- meta: void 0
990
- });
991
- }
992
- }
993
- };
994
-
995
- //#endregion
996
- export { ContractValidationError as n, createControlClient as t };
997
- //# sourceMappingURL=client-CrsnY58k.mjs.map