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

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