@prisma-next/cli 0.3.0-pr.99.6 → 0.4.0-dev.1

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