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