@prisma-next/cli 0.3.0-pr.94.3 → 0.3.0-pr.95.2

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 (115) hide show
  1. package/dist/chunk-AGOTG4L3.js +965 -0
  2. package/dist/chunk-AGOTG4L3.js.map +1 -0
  3. package/dist/chunk-HLLI4YL7.js +180 -0
  4. package/dist/chunk-HLLI4YL7.js.map +1 -0
  5. package/dist/chunk-HWYQOCAJ.js +47 -0
  6. package/dist/chunk-HWYQOCAJ.js.map +1 -0
  7. package/dist/chunk-VG2R7DGF.js +735 -0
  8. package/dist/chunk-VG2R7DGF.js.map +1 -0
  9. package/dist/cli.d.ts +2 -2
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +2764 -2522
  12. package/dist/cli.js.map +1 -1
  13. package/dist/commands/contract-emit.d.ts +3 -0
  14. package/dist/commands/contract-emit.d.ts.map +1 -0
  15. package/dist/commands/contract-emit.js +10 -0
  16. package/dist/commands/contract-emit.js.map +1 -0
  17. package/dist/commands/db-init.d.ts +3 -0
  18. package/dist/commands/db-init.d.ts.map +1 -0
  19. package/dist/commands/db-init.js +257 -0
  20. package/dist/commands/db-init.js.map +1 -0
  21. package/dist/commands/db-introspect.d.ts +3 -0
  22. package/dist/commands/db-introspect.d.ts.map +1 -0
  23. package/dist/commands/db-introspect.js +155 -0
  24. package/dist/commands/db-introspect.js.map +1 -0
  25. package/dist/commands/db-schema-verify.d.ts +3 -0
  26. package/dist/commands/db-schema-verify.d.ts.map +1 -0
  27. package/dist/commands/db-schema-verify.js +171 -0
  28. package/dist/commands/db-schema-verify.js.map +1 -0
  29. package/dist/commands/db-sign.d.ts +3 -0
  30. package/dist/commands/db-sign.d.ts.map +1 -0
  31. package/dist/commands/db-sign.js +195 -0
  32. package/dist/commands/db-sign.js.map +1 -0
  33. package/dist/commands/db-verify.d.ts +3 -0
  34. package/dist/commands/db-verify.d.ts.map +1 -0
  35. package/dist/commands/db-verify.js +193 -0
  36. package/dist/commands/db-verify.js.map +1 -0
  37. package/dist/{config-loader.d.mts → config-loader.d.ts} +3 -8
  38. package/dist/config-loader.d.ts.map +1 -0
  39. package/dist/config-loader.js +7 -0
  40. package/dist/config-loader.js.map +1 -0
  41. package/dist/control-api/client.d.ts +13 -0
  42. package/dist/control-api/client.d.ts.map +1 -0
  43. package/dist/control-api/operations/db-init.d.ts +29 -0
  44. package/dist/control-api/operations/db-init.d.ts.map +1 -0
  45. package/dist/control-api/types.d.ts +387 -0
  46. package/dist/control-api/types.d.ts.map +1 -0
  47. package/dist/exports/config-types.d.ts +3 -0
  48. package/dist/exports/config-types.d.ts.map +1 -0
  49. package/dist/exports/config-types.js +6 -0
  50. package/dist/exports/config-types.js.map +1 -0
  51. package/dist/exports/control-api.d.ts +13 -0
  52. package/dist/exports/control-api.d.ts.map +1 -0
  53. package/dist/exports/control-api.js +7 -0
  54. package/dist/exports/control-api.js.map +1 -0
  55. package/dist/exports/index.d.ts +4 -0
  56. package/dist/exports/index.d.ts.map +1 -0
  57. package/dist/exports/index.js +176 -0
  58. package/dist/exports/index.js.map +1 -0
  59. package/dist/{exports/index.d.mts → load-ts-contract.d.ts} +5 -10
  60. package/dist/load-ts-contract.d.ts.map +1 -0
  61. package/dist/utils/cli-errors.d.ts +7 -0
  62. package/dist/utils/cli-errors.d.ts.map +1 -0
  63. package/dist/utils/command-helpers.d.ts +12 -0
  64. package/dist/utils/command-helpers.d.ts.map +1 -0
  65. package/dist/utils/framework-components.d.ts +70 -0
  66. package/dist/utils/framework-components.d.ts.map +1 -0
  67. package/dist/utils/global-flags.d.ts +25 -0
  68. package/dist/utils/global-flags.d.ts.map +1 -0
  69. package/dist/utils/output.d.ts +142 -0
  70. package/dist/utils/output.d.ts.map +1 -0
  71. package/dist/utils/progress-adapter.d.ts +26 -0
  72. package/dist/utils/progress-adapter.d.ts.map +1 -0
  73. package/dist/utils/result-handler.d.ts +15 -0
  74. package/dist/utils/result-handler.d.ts.map +1 -0
  75. package/package.json +54 -29
  76. package/dist/client-CoxxGz_7.mjs +0 -692
  77. package/dist/client-CoxxGz_7.mjs.map +0 -1
  78. package/dist/commands/contract-emit.d.mts +0 -7
  79. package/dist/commands/contract-emit.d.mts.map +0 -1
  80. package/dist/commands/contract-emit.mjs +0 -139
  81. package/dist/commands/contract-emit.mjs.map +0 -1
  82. package/dist/commands/db-init.d.mts +0 -7
  83. package/dist/commands/db-init.d.mts.map +0 -1
  84. package/dist/commands/db-init.mjs +0 -178
  85. package/dist/commands/db-init.mjs.map +0 -1
  86. package/dist/commands/db-introspect.d.mts +0 -7
  87. package/dist/commands/db-introspect.d.mts.map +0 -1
  88. package/dist/commands/db-introspect.mjs +0 -120
  89. package/dist/commands/db-introspect.mjs.map +0 -1
  90. package/dist/commands/db-schema-verify.d.mts +0 -7
  91. package/dist/commands/db-schema-verify.d.mts.map +0 -1
  92. package/dist/commands/db-schema-verify.mjs +0 -116
  93. package/dist/commands/db-schema-verify.mjs.map +0 -1
  94. package/dist/commands/db-sign.d.mts +0 -7
  95. package/dist/commands/db-sign.d.mts.map +0 -1
  96. package/dist/commands/db-sign.mjs +0 -138
  97. package/dist/commands/db-sign.mjs.map +0 -1
  98. package/dist/commands/db-verify.d.mts +0 -7
  99. package/dist/commands/db-verify.d.mts.map +0 -1
  100. package/dist/commands/db-verify.mjs +0 -128
  101. package/dist/commands/db-verify.mjs.map +0 -1
  102. package/dist/config-loader-B-pobG0R.mjs +0 -42
  103. package/dist/config-loader-B-pobG0R.mjs.map +0 -1
  104. package/dist/config-loader.d.mts.map +0 -1
  105. package/dist/config-loader.mjs +0 -3
  106. package/dist/exports/config-types.d.mts +0 -2
  107. package/dist/exports/config-types.mjs +0 -3
  108. package/dist/exports/control-api.d.mts +0 -405
  109. package/dist/exports/control-api.d.mts.map +0 -1
  110. package/dist/exports/control-api.mjs +0 -3
  111. package/dist/exports/index.d.mts.map +0 -1
  112. package/dist/exports/index.mjs +0 -128
  113. package/dist/exports/index.mjs.map +0 -1
  114. package/dist/result-handler-Do_4Fi4U.mjs +0 -959
  115. package/dist/result-handler-Do_4Fi4U.mjs.map +0 -1
@@ -0,0 +1,735 @@
1
+ // src/utils/cli-errors.ts
2
+ import {
3
+ CliStructuredError,
4
+ errorConfigFileNotFound,
5
+ errorConfigValidation,
6
+ errorContractConfigMissing,
7
+ errorContractMissingExtensionPacks,
8
+ errorContractValidationFailed,
9
+ errorDatabaseConnectionRequired,
10
+ errorDriverRequired,
11
+ errorFamilyReadMarkerSqlRequired,
12
+ errorFileNotFound,
13
+ errorHashMismatch,
14
+ errorJsonFormatNotSupported,
15
+ errorMarkerMissing,
16
+ errorMigrationPlanningFailed,
17
+ errorQueryRunnerFactoryRequired,
18
+ errorRuntime,
19
+ errorTargetMigrationNotSupported,
20
+ errorTargetMismatch,
21
+ errorUnexpected
22
+ } from "@prisma-next/core-control-plane/errors";
23
+
24
+ // src/control-api/client.ts
25
+ import { createControlPlaneStack } from "@prisma-next/core-control-plane/stack";
26
+ import { notOk as notOk2, ok as ok2 } from "@prisma-next/utils/result";
27
+
28
+ // src/utils/framework-components.ts
29
+ import {
30
+ checkContractComponentRequirements
31
+ } from "@prisma-next/contract/framework-components";
32
+ function assertFrameworkComponentsCompatible(expectedFamilyId, expectedTargetId, frameworkComponents) {
33
+ for (let i = 0; i < frameworkComponents.length; i++) {
34
+ const component = frameworkComponents[i];
35
+ if (typeof component !== "object" || component === null) {
36
+ throw errorConfigValidation("frameworkComponents[]", {
37
+ why: `Framework component at index ${i} must be an object`
38
+ });
39
+ }
40
+ const record = component;
41
+ if (!Object.hasOwn(record, "kind")) {
42
+ throw errorConfigValidation("frameworkComponents[].kind", {
43
+ why: `Framework component at index ${i} must have 'kind' property`
44
+ });
45
+ }
46
+ const kind = record["kind"];
47
+ if (kind !== "target" && kind !== "adapter" && kind !== "extension" && kind !== "driver") {
48
+ throw errorConfigValidation("frameworkComponents[].kind", {
49
+ why: `Framework component at index ${i} has invalid kind '${String(kind)}' (must be 'target', 'adapter', 'extension', or 'driver')`
50
+ });
51
+ }
52
+ if (!Object.hasOwn(record, "familyId")) {
53
+ throw errorConfigValidation("frameworkComponents[].familyId", {
54
+ why: `Framework component at index ${i} (kind: ${String(kind)}) must have 'familyId' property`
55
+ });
56
+ }
57
+ const familyId = record["familyId"];
58
+ if (familyId !== expectedFamilyId) {
59
+ throw errorConfigValidation("frameworkComponents[].familyId", {
60
+ why: `Framework component at index ${i} (kind: ${String(kind)}) has familyId '${String(familyId)}' but expected '${expectedFamilyId}'`
61
+ });
62
+ }
63
+ if (!Object.hasOwn(record, "targetId")) {
64
+ throw errorConfigValidation("frameworkComponents[].targetId", {
65
+ why: `Framework component at index ${i} (kind: ${String(kind)}) must have 'targetId' property`
66
+ });
67
+ }
68
+ const targetId = record["targetId"];
69
+ if (targetId !== expectedTargetId) {
70
+ throw errorConfigValidation("frameworkComponents[].targetId", {
71
+ why: `Framework component at index ${i} (kind: ${String(kind)}) has targetId '${String(targetId)}' but expected '${expectedTargetId}'`
72
+ });
73
+ }
74
+ }
75
+ return frameworkComponents;
76
+ }
77
+
78
+ // src/control-api/operations/db-init.ts
79
+ import { notOk, ok } from "@prisma-next/utils/result";
80
+ async function executeDbInit(options) {
81
+ const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents, onProgress } = options;
82
+ const planner = migrations.createPlanner(familyInstance);
83
+ const runner = migrations.createRunner(familyInstance);
84
+ const introspectSpanId = "introspect";
85
+ onProgress?.({
86
+ action: "dbInit",
87
+ kind: "spanStart",
88
+ spanId: introspectSpanId,
89
+ label: "Introspecting database schema"
90
+ });
91
+ const schemaIR = await familyInstance.introspect({ driver });
92
+ onProgress?.({
93
+ action: "dbInit",
94
+ kind: "spanEnd",
95
+ spanId: introspectSpanId,
96
+ outcome: "ok"
97
+ });
98
+ const policy = { allowedOperationClasses: ["additive"] };
99
+ const planSpanId = "plan";
100
+ onProgress?.({
101
+ action: "dbInit",
102
+ kind: "spanStart",
103
+ spanId: planSpanId,
104
+ label: "Planning migration"
105
+ });
106
+ const plannerResult = await planner.plan({
107
+ contract: contractIR,
108
+ schema: schemaIR,
109
+ policy,
110
+ frameworkComponents
111
+ });
112
+ if (plannerResult.kind === "failure") {
113
+ onProgress?.({
114
+ action: "dbInit",
115
+ kind: "spanEnd",
116
+ spanId: planSpanId,
117
+ outcome: "error"
118
+ });
119
+ return notOk({
120
+ code: "PLANNING_FAILED",
121
+ summary: "Migration planning failed due to conflicts",
122
+ conflicts: plannerResult.conflicts,
123
+ why: void 0,
124
+ meta: void 0
125
+ });
126
+ }
127
+ const migrationPlan = plannerResult.plan;
128
+ onProgress?.({
129
+ action: "dbInit",
130
+ kind: "spanEnd",
131
+ spanId: planSpanId,
132
+ outcome: "ok"
133
+ });
134
+ const checkMarkerSpanId = "checkMarker";
135
+ onProgress?.({
136
+ action: "dbInit",
137
+ kind: "spanStart",
138
+ spanId: checkMarkerSpanId,
139
+ label: "Checking contract marker"
140
+ });
141
+ const existingMarker = await familyInstance.readMarker({ driver });
142
+ if (existingMarker) {
143
+ const markerMatchesDestination = existingMarker.coreHash === migrationPlan.destination.coreHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash);
144
+ if (markerMatchesDestination) {
145
+ onProgress?.({
146
+ action: "dbInit",
147
+ kind: "spanEnd",
148
+ spanId: checkMarkerSpanId,
149
+ outcome: "skipped"
150
+ });
151
+ const result2 = {
152
+ mode,
153
+ plan: { operations: [] },
154
+ ...mode === "apply" ? {
155
+ execution: { operationsPlanned: 0, operationsExecuted: 0 },
156
+ marker: {
157
+ coreHash: existingMarker.coreHash,
158
+ profileHash: existingMarker.profileHash
159
+ }
160
+ } : {},
161
+ summary: "Database already at target contract state"
162
+ };
163
+ return ok(result2);
164
+ }
165
+ onProgress?.({
166
+ action: "dbInit",
167
+ kind: "spanEnd",
168
+ spanId: checkMarkerSpanId,
169
+ outcome: "error"
170
+ });
171
+ return notOk({
172
+ code: "MARKER_ORIGIN_MISMATCH",
173
+ summary: "Existing contract marker does not match plan destination",
174
+ marker: {
175
+ coreHash: existingMarker.coreHash,
176
+ profileHash: existingMarker.profileHash
177
+ },
178
+ destination: {
179
+ coreHash: migrationPlan.destination.coreHash,
180
+ profileHash: migrationPlan.destination.profileHash
181
+ },
182
+ why: void 0,
183
+ conflicts: void 0,
184
+ meta: void 0
185
+ });
186
+ }
187
+ onProgress?.({
188
+ action: "dbInit",
189
+ kind: "spanEnd",
190
+ spanId: checkMarkerSpanId,
191
+ outcome: "ok"
192
+ });
193
+ if (mode === "plan") {
194
+ const result2 = {
195
+ mode: "plan",
196
+ plan: { operations: migrationPlan.operations },
197
+ summary: `Planned ${migrationPlan.operations.length} operation(s)`
198
+ };
199
+ return ok(result2);
200
+ }
201
+ const applySpanId = "apply";
202
+ onProgress?.({
203
+ action: "dbInit",
204
+ kind: "spanStart",
205
+ spanId: applySpanId,
206
+ label: "Applying migration plan"
207
+ });
208
+ const callbacks = onProgress ? {
209
+ onOperationStart: (op) => {
210
+ onProgress({
211
+ action: "dbInit",
212
+ kind: "spanStart",
213
+ spanId: `operation:${op.id}`,
214
+ parentSpanId: applySpanId,
215
+ label: op.label
216
+ });
217
+ },
218
+ onOperationComplete: (op) => {
219
+ onProgress({
220
+ action: "dbInit",
221
+ kind: "spanEnd",
222
+ spanId: `operation:${op.id}`,
223
+ outcome: "ok"
224
+ });
225
+ }
226
+ } : void 0;
227
+ const runnerResult = await runner.execute({
228
+ plan: migrationPlan,
229
+ driver,
230
+ destinationContract: contractIR,
231
+ policy,
232
+ ...callbacks ? { callbacks } : {},
233
+ // db init plans and applies back-to-back from a fresh introspection, so per-operation
234
+ // pre/postchecks and the idempotency probe are usually redundant overhead. We still
235
+ // enforce marker/origin compatibility and a full schema verification after apply.
236
+ executionChecks: {
237
+ prechecks: false,
238
+ postchecks: false,
239
+ idempotencyChecks: false
240
+ },
241
+ frameworkComponents
242
+ });
243
+ if (!runnerResult.ok) {
244
+ onProgress?.({
245
+ action: "dbInit",
246
+ kind: "spanEnd",
247
+ spanId: applySpanId,
248
+ outcome: "error"
249
+ });
250
+ return notOk({
251
+ code: "RUNNER_FAILED",
252
+ summary: runnerResult.failure.summary,
253
+ why: runnerResult.failure.why,
254
+ meta: runnerResult.failure.meta,
255
+ conflicts: void 0
256
+ });
257
+ }
258
+ const execution = runnerResult.value;
259
+ onProgress?.({
260
+ action: "dbInit",
261
+ kind: "spanEnd",
262
+ spanId: applySpanId,
263
+ outcome: "ok"
264
+ });
265
+ const result = {
266
+ mode: "apply",
267
+ plan: { operations: migrationPlan.operations },
268
+ execution: {
269
+ operationsPlanned: execution.operationsPlanned,
270
+ operationsExecuted: execution.operationsExecuted
271
+ },
272
+ marker: migrationPlan.destination.profileHash ? {
273
+ coreHash: migrationPlan.destination.coreHash,
274
+ profileHash: migrationPlan.destination.profileHash
275
+ } : { coreHash: migrationPlan.destination.coreHash },
276
+ summary: `Applied ${execution.operationsExecuted} operation(s), marker written`
277
+ };
278
+ return ok(result);
279
+ }
280
+
281
+ // src/control-api/client.ts
282
+ function createControlClient(options) {
283
+ return new ControlClientImpl(options);
284
+ }
285
+ var ControlClientImpl = class {
286
+ options;
287
+ stack = null;
288
+ driver = null;
289
+ familyInstance = null;
290
+ frameworkComponents = null;
291
+ initialized = false;
292
+ defaultConnection;
293
+ constructor(options) {
294
+ this.options = options;
295
+ this.defaultConnection = options.connection;
296
+ }
297
+ init() {
298
+ if (this.initialized) {
299
+ return;
300
+ }
301
+ this.stack = createControlPlaneStack({
302
+ target: this.options.target,
303
+ adapter: this.options.adapter,
304
+ driver: this.options.driver,
305
+ extensionPacks: this.options.extensionPacks
306
+ });
307
+ this.familyInstance = this.options.family.create(this.stack);
308
+ const rawComponents = [
309
+ this.options.target,
310
+ this.options.adapter,
311
+ ...this.options.extensionPacks ?? []
312
+ ];
313
+ this.frameworkComponents = assertFrameworkComponentsCompatible(
314
+ this.options.family.familyId,
315
+ this.options.target.targetId,
316
+ rawComponents
317
+ );
318
+ this.initialized = true;
319
+ }
320
+ async connect(connection) {
321
+ this.init();
322
+ if (this.driver) {
323
+ throw new Error("Already connected. Call close() before reconnecting.");
324
+ }
325
+ const resolvedConnection = connection ?? this.defaultConnection;
326
+ if (resolvedConnection === void 0) {
327
+ throw new Error(
328
+ "No connection provided. Pass a connection to connect() or provide a default connection when creating the client."
329
+ );
330
+ }
331
+ if (!this.stack?.driver) {
332
+ throw new Error(
333
+ "Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations."
334
+ );
335
+ }
336
+ this.driver = await this.stack?.driver.create(resolvedConnection);
337
+ }
338
+ async close() {
339
+ if (this.driver) {
340
+ await this.driver.close();
341
+ this.driver = null;
342
+ }
343
+ }
344
+ async ensureConnected() {
345
+ this.init();
346
+ if (!this.driver && this.defaultConnection !== void 0) {
347
+ await this.connect(this.defaultConnection);
348
+ }
349
+ if (!this.driver || !this.familyInstance || !this.frameworkComponents) {
350
+ throw new Error("Not connected. Call connect(connection) first.");
351
+ }
352
+ return {
353
+ driver: this.driver,
354
+ familyInstance: this.familyInstance,
355
+ frameworkComponents: this.frameworkComponents
356
+ };
357
+ }
358
+ async verify(options) {
359
+ const { onProgress } = options;
360
+ if (options.connection !== void 0) {
361
+ onProgress?.({
362
+ action: "verify",
363
+ kind: "spanStart",
364
+ spanId: "connect",
365
+ label: "Connecting to database..."
366
+ });
367
+ try {
368
+ await this.connect(options.connection);
369
+ onProgress?.({
370
+ action: "verify",
371
+ kind: "spanEnd",
372
+ spanId: "connect",
373
+ outcome: "ok"
374
+ });
375
+ } catch (error) {
376
+ onProgress?.({
377
+ action: "verify",
378
+ kind: "spanEnd",
379
+ spanId: "connect",
380
+ outcome: "error"
381
+ });
382
+ throw error;
383
+ }
384
+ }
385
+ const { driver, familyInstance } = await this.ensureConnected();
386
+ const contractIR = familyInstance.validateContractIR(options.contractIR);
387
+ onProgress?.({
388
+ action: "verify",
389
+ kind: "spanStart",
390
+ spanId: "verify",
391
+ label: "Verifying contract marker..."
392
+ });
393
+ try {
394
+ const result = await familyInstance.verify({
395
+ driver,
396
+ contractIR,
397
+ expectedTargetId: this.options.target.targetId,
398
+ contractPath: ""
399
+ });
400
+ onProgress?.({
401
+ action: "verify",
402
+ kind: "spanEnd",
403
+ spanId: "verify",
404
+ outcome: result.ok ? "ok" : "error"
405
+ });
406
+ return result;
407
+ } catch (error) {
408
+ onProgress?.({
409
+ action: "verify",
410
+ kind: "spanEnd",
411
+ spanId: "verify",
412
+ outcome: "error"
413
+ });
414
+ throw error;
415
+ }
416
+ }
417
+ async schemaVerify(options) {
418
+ const { onProgress } = options;
419
+ if (options.connection !== void 0) {
420
+ onProgress?.({
421
+ action: "schemaVerify",
422
+ kind: "spanStart",
423
+ spanId: "connect",
424
+ label: "Connecting to database..."
425
+ });
426
+ try {
427
+ await this.connect(options.connection);
428
+ onProgress?.({
429
+ action: "schemaVerify",
430
+ kind: "spanEnd",
431
+ spanId: "connect",
432
+ outcome: "ok"
433
+ });
434
+ } catch (error) {
435
+ onProgress?.({
436
+ action: "schemaVerify",
437
+ kind: "spanEnd",
438
+ spanId: "connect",
439
+ outcome: "error"
440
+ });
441
+ throw error;
442
+ }
443
+ }
444
+ const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
445
+ const contractIR = familyInstance.validateContractIR(options.contractIR);
446
+ onProgress?.({
447
+ action: "schemaVerify",
448
+ kind: "spanStart",
449
+ spanId: "schemaVerify",
450
+ label: "Verifying database schema..."
451
+ });
452
+ try {
453
+ const result = await familyInstance.schemaVerify({
454
+ driver,
455
+ contractIR,
456
+ strict: options.strict ?? false,
457
+ contractPath: "",
458
+ frameworkComponents
459
+ });
460
+ onProgress?.({
461
+ action: "schemaVerify",
462
+ kind: "spanEnd",
463
+ spanId: "schemaVerify",
464
+ outcome: result.ok ? "ok" : "error"
465
+ });
466
+ return result;
467
+ } catch (error) {
468
+ onProgress?.({
469
+ action: "schemaVerify",
470
+ kind: "spanEnd",
471
+ spanId: "schemaVerify",
472
+ outcome: "error"
473
+ });
474
+ throw error;
475
+ }
476
+ }
477
+ async sign(options) {
478
+ const { onProgress } = options;
479
+ if (options.connection !== void 0) {
480
+ onProgress?.({
481
+ action: "sign",
482
+ kind: "spanStart",
483
+ spanId: "connect",
484
+ label: "Connecting to database..."
485
+ });
486
+ try {
487
+ await this.connect(options.connection);
488
+ onProgress?.({
489
+ action: "sign",
490
+ kind: "spanEnd",
491
+ spanId: "connect",
492
+ outcome: "ok"
493
+ });
494
+ } catch (error) {
495
+ onProgress?.({
496
+ action: "sign",
497
+ kind: "spanEnd",
498
+ spanId: "connect",
499
+ outcome: "error"
500
+ });
501
+ throw error;
502
+ }
503
+ }
504
+ const { driver, familyInstance } = await this.ensureConnected();
505
+ const contractIR = familyInstance.validateContractIR(options.contractIR);
506
+ onProgress?.({
507
+ action: "sign",
508
+ kind: "spanStart",
509
+ spanId: "sign",
510
+ label: "Signing database..."
511
+ });
512
+ try {
513
+ const result = await familyInstance.sign({
514
+ driver,
515
+ contractIR,
516
+ contractPath: options.contractPath ?? "",
517
+ ...options.configPath ? { configPath: options.configPath } : {}
518
+ });
519
+ onProgress?.({
520
+ action: "sign",
521
+ kind: "spanEnd",
522
+ spanId: "sign",
523
+ outcome: "ok"
524
+ });
525
+ return result;
526
+ } catch (error) {
527
+ onProgress?.({
528
+ action: "sign",
529
+ kind: "spanEnd",
530
+ spanId: "sign",
531
+ outcome: "error"
532
+ });
533
+ throw error;
534
+ }
535
+ }
536
+ async dbInit(options) {
537
+ const { onProgress } = options;
538
+ if (options.connection !== void 0) {
539
+ onProgress?.({
540
+ action: "dbInit",
541
+ kind: "spanStart",
542
+ spanId: "connect",
543
+ label: "Connecting to database..."
544
+ });
545
+ try {
546
+ await this.connect(options.connection);
547
+ onProgress?.({
548
+ action: "dbInit",
549
+ kind: "spanEnd",
550
+ spanId: "connect",
551
+ outcome: "ok"
552
+ });
553
+ } catch (error) {
554
+ onProgress?.({
555
+ action: "dbInit",
556
+ kind: "spanEnd",
557
+ spanId: "connect",
558
+ outcome: "error"
559
+ });
560
+ throw error;
561
+ }
562
+ }
563
+ const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
564
+ if (!this.options.target.migrations) {
565
+ throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
566
+ }
567
+ const contractIR = familyInstance.validateContractIR(options.contractIR);
568
+ return executeDbInit({
569
+ driver,
570
+ familyInstance,
571
+ contractIR,
572
+ mode: options.mode,
573
+ migrations: this.options.target.migrations,
574
+ frameworkComponents,
575
+ ...onProgress ? { onProgress } : {}
576
+ });
577
+ }
578
+ async introspect(options) {
579
+ const onProgress = options?.onProgress;
580
+ if (options?.connection !== void 0) {
581
+ onProgress?.({
582
+ action: "introspect",
583
+ kind: "spanStart",
584
+ spanId: "connect",
585
+ label: "Connecting to database..."
586
+ });
587
+ try {
588
+ await this.connect(options.connection);
589
+ onProgress?.({
590
+ action: "introspect",
591
+ kind: "spanEnd",
592
+ spanId: "connect",
593
+ outcome: "ok"
594
+ });
595
+ } catch (error) {
596
+ onProgress?.({
597
+ action: "introspect",
598
+ kind: "spanEnd",
599
+ spanId: "connect",
600
+ outcome: "error"
601
+ });
602
+ throw error;
603
+ }
604
+ }
605
+ const { driver, familyInstance } = await this.ensureConnected();
606
+ const _schema = options?.schema;
607
+ void _schema;
608
+ onProgress?.({
609
+ action: "introspect",
610
+ kind: "spanStart",
611
+ spanId: "introspect",
612
+ label: "Introspecting database schema..."
613
+ });
614
+ try {
615
+ const result = await familyInstance.introspect({ driver });
616
+ onProgress?.({
617
+ action: "introspect",
618
+ kind: "spanEnd",
619
+ spanId: "introspect",
620
+ outcome: "ok"
621
+ });
622
+ return result;
623
+ } catch (error) {
624
+ onProgress?.({
625
+ action: "introspect",
626
+ kind: "spanEnd",
627
+ spanId: "introspect",
628
+ outcome: "error"
629
+ });
630
+ throw error;
631
+ }
632
+ }
633
+ toSchemaView(schemaIR) {
634
+ this.init();
635
+ if (this.familyInstance?.toSchemaView) {
636
+ return this.familyInstance.toSchemaView(schemaIR);
637
+ }
638
+ return void 0;
639
+ }
640
+ async emit(options) {
641
+ const { onProgress, contractConfig } = options;
642
+ this.init();
643
+ if (!this.familyInstance) {
644
+ throw new Error("Family instance was not initialized. This is a bug.");
645
+ }
646
+ let contractRaw;
647
+ onProgress?.({
648
+ action: "emit",
649
+ kind: "spanStart",
650
+ spanId: "resolveSource",
651
+ label: "Resolving contract source..."
652
+ });
653
+ try {
654
+ switch (contractConfig.source.kind) {
655
+ case "loader":
656
+ contractRaw = await contractConfig.source.load();
657
+ break;
658
+ case "value":
659
+ contractRaw = contractConfig.source.value;
660
+ break;
661
+ }
662
+ onProgress?.({
663
+ action: "emit",
664
+ kind: "spanEnd",
665
+ spanId: "resolveSource",
666
+ outcome: "ok"
667
+ });
668
+ } catch (error) {
669
+ onProgress?.({
670
+ action: "emit",
671
+ kind: "spanEnd",
672
+ spanId: "resolveSource",
673
+ outcome: "error"
674
+ });
675
+ return notOk2({
676
+ code: "CONTRACT_SOURCE_INVALID",
677
+ summary: "Failed to resolve contract source",
678
+ why: error instanceof Error ? error.message : String(error),
679
+ meta: void 0
680
+ });
681
+ }
682
+ onProgress?.({
683
+ action: "emit",
684
+ kind: "spanStart",
685
+ spanId: "emit",
686
+ label: "Emitting contract..."
687
+ });
688
+ try {
689
+ const emitResult = await this.familyInstance.emitContract({ contractIR: contractRaw });
690
+ onProgress?.({
691
+ action: "emit",
692
+ kind: "spanEnd",
693
+ spanId: "emit",
694
+ outcome: "ok"
695
+ });
696
+ return ok2({
697
+ coreHash: emitResult.coreHash,
698
+ profileHash: emitResult.profileHash,
699
+ contractJson: emitResult.contractJson,
700
+ contractDts: emitResult.contractDts
701
+ });
702
+ } catch (error) {
703
+ onProgress?.({
704
+ action: "emit",
705
+ kind: "spanEnd",
706
+ spanId: "emit",
707
+ outcome: "error"
708
+ });
709
+ return notOk2({
710
+ code: "EMIT_FAILED",
711
+ summary: "Failed to emit contract",
712
+ why: error instanceof Error ? error.message : String(error),
713
+ meta: void 0
714
+ });
715
+ }
716
+ }
717
+ };
718
+
719
+ export {
720
+ CliStructuredError,
721
+ errorContractValidationFailed,
722
+ errorDatabaseConnectionRequired,
723
+ errorDriverRequired,
724
+ errorFileNotFound,
725
+ errorHashMismatch,
726
+ errorJsonFormatNotSupported,
727
+ errorMarkerMissing,
728
+ errorMigrationPlanningFailed,
729
+ errorRuntime,
730
+ errorTargetMigrationNotSupported,
731
+ errorTargetMismatch,
732
+ errorUnexpected,
733
+ createControlClient
734
+ };
735
+ //# sourceMappingURL=chunk-VG2R7DGF.js.map