@prisma/composer 0.6.0-dev.14 → 0.6.0-dev.15

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 (110) hide show
  1. package/dist/{app-config-CFsSXEVj-B242oUnm.d.mts → app-config-aIrriqVU-D6lJHzh2.d.mts} +42 -17
  2. package/dist/app-config-aIrriqVU-D6lJHzh2.d.mts.map +1 -0
  3. package/dist/bin.mjs +950 -12
  4. package/dist/bin.mjs.map +1 -1
  5. package/dist/config-CL7Jbve2.d.mts +1 -0
  6. package/dist/config.d.mts +3 -3
  7. package/dist/container-transport-DKmKg5JQ-CoY4XPma.mjs +30 -0
  8. package/dist/container-transport-DKmKg5JQ-CoY4XPma.mjs.map +1 -0
  9. package/dist/control.d.mts +3 -216
  10. package/dist/control.mjs +1 -69
  11. package/dist/deploy-CL7Jbve2.d.mts +1 -0
  12. package/dist/deploy.d.mts +2 -2
  13. package/dist/deploy.mjs +1 -1
  14. package/dist/{deployment-summary-r47O6kFr-CcMYVOn5.mjs → deployment-summary-DswOl_9E-C03NJ98H.mjs} +2 -2
  15. package/dist/{deployment-summary-r47O6kFr-CcMYVOn5.mjs.map → deployment-summary-DswOl_9E-C03NJ98H.mjs.map} +1 -1
  16. package/dist/{dist-C5rZnr4n.mjs → dist-C0dNEgS-.mjs} +2 -2
  17. package/dist/{dist-C5rZnr4n.mjs.map → dist-C0dNEgS-.mjs.map} +1 -1
  18. package/dist/{errors-0e8IVwzi.mjs → errors-DkXcnjPx.mjs} +3 -2
  19. package/dist/{errors-0e8IVwzi.mjs.map → errors-DkXcnjPx.mjs.map} +1 -1
  20. package/dist/{execute-deploy-destroy-IT4vGkMc-oO8yjHPH.mjs → execute-deploy-destroy-DfVJUICu-AMM8CwgV.mjs} +30 -19
  21. package/dist/execute-deploy-destroy-DfVJUICu-AMM8CwgV.mjs.map +1 -0
  22. package/dist/{execute-deploy-destroy-IT4vGkMc-YM1Cv6cu.mjs → execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs} +29 -19
  23. package/dist/execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs.map +1 -0
  24. package/dist/{execute-dev-DLYyduEM-88uyvrbj.mjs → execute-dev-BMTFWfFc-B1whS-Rr.mjs} +25 -23
  25. package/dist/{execute-dev-DLYyduEM-88uyvrbj.mjs.map → execute-dev-BMTFWfFc-B1whS-Rr.mjs.map} +1 -1
  26. package/dist/{execute-dev-DLYyduEM-BuUGTm0g.mjs → execute-dev-BMTFWfFc-BoKbcFVF.mjs} +29 -20
  27. package/dist/{execute-dev-DLYyduEM-BuUGTm0g.mjs.map → execute-dev-BMTFWfFc-BoKbcFVF.mjs.map} +1 -1
  28. package/dist/{execute-log-VIOL4DBz-DBPH8By4.mjs → execute-log-Cay9hlKW-B0tmRtrY.mjs} +11 -7
  29. package/dist/execute-log-Cay9hlKW-B0tmRtrY.mjs.map +1 -0
  30. package/dist/{execute-log-VIOL4DBz-DKodBrxS.mjs → execute-log-Cay9hlKW-DrMeVOXq.mjs} +9 -7
  31. package/dist/execute-log-Cay9hlKW-DrMeVOXq.mjs.map +1 -0
  32. package/dist/family-DkH0si4D-Uov_MuHV.d.mts +27 -0
  33. package/dist/family-DkH0si4D-Uov_MuHV.d.mts.map +1 -0
  34. package/dist/family.d.mts +53 -0
  35. package/dist/family.d.mts.map +1 -0
  36. package/dist/family.mjs +839 -0
  37. package/dist/family.mjs.map +1 -0
  38. package/dist/{graph-BJgUfGB0-kvgFzT4q.mjs → graph-BJgUfGB0-7fmubS_y.mjs} +2 -2
  39. package/dist/{graph-BJgUfGB0-kvgFzT4q.mjs.map → graph-BJgUfGB0-7fmubS_y.mjs.map} +1 -1
  40. package/dist/{graph-types-N6brq1zY-1VMNwtkJ.d.mts → graph-DqklX5Sf-CdNH3lA7.d.mts} +17 -2
  41. package/dist/graph-DqklX5Sf-CdNH3lA7.d.mts.map +1 -0
  42. package/dist/{index-DryPyF9U.d.mts → index-DuF5iI3i.d.mts} +2 -3
  43. package/dist/index-DuF5iI3i.d.mts.map +1 -0
  44. package/dist/index.d.mts +2 -3
  45. package/dist/index.mjs +2 -2
  46. package/dist/{local-target-DnA2E8IN.mjs → local-target-D3u_wuNF.mjs} +2 -2
  47. package/dist/{local-target-DnA2E8IN.mjs.map → local-target-D3u_wuNF.mjs.map} +1 -1
  48. package/dist/{local-target-DuSyWeYc.mjs → local-target-H0IWu_FM.mjs} +2 -2
  49. package/dist/{local-target-DuSyWeYc.mjs.map → local-target-H0IWu_FM.mjs.map} +1 -1
  50. package/dist/local-target.d.mts +1 -1
  51. package/dist/local-target.mjs +1 -1
  52. package/dist/log-DRnnWupy-9jbzL64M.d.mts +324 -0
  53. package/dist/log-DRnnWupy-9jbzL64M.d.mts.map +1 -0
  54. package/dist/{result-CzGChwbZ.mjs → log-DfT2hHqi-CDp9nfI5.mjs} +85 -90
  55. package/dist/log-DfT2hHqi-CDp9nfI5.mjs.map +1 -0
  56. package/dist/{nextjs-DLyeRR7M-DZODs9tk.d.mts → nextjs-DLyeRR7M-BfUbLXwr.d.mts} +3 -3
  57. package/dist/{nextjs-DLyeRR7M-DZODs9tk.d.mts.map → nextjs-DLyeRR7M-BfUbLXwr.d.mts.map} +1 -1
  58. package/dist/nextjs-control.d.mts +4 -4
  59. package/dist/nextjs.d.mts +1 -1
  60. package/dist/node-control.d.mts +3 -3
  61. package/dist/node.d.mts +2 -2
  62. package/dist/{pipeline-D3QoVzAB-D_ufjg3N.mjs → pipeline-AoW8zq4I-C6Qe0VaZ.mjs} +161 -42
  63. package/dist/{pipeline-D3QoVzAB-D_ufjg3N.mjs.map → pipeline-AoW8zq4I-C6Qe0VaZ.mjs.map} +1 -1
  64. package/dist/{pipeline-D3QoVzAB-Ci2aJ2mE.mjs → pipeline-AoW8zq4I-DM74ygtH.mjs} +164 -43
  65. package/dist/pipeline-AoW8zq4I-DM74ygtH.mjs.map +1 -0
  66. package/dist/report.d.mts +2 -2
  67. package/dist/report.mjs +1 -1
  68. package/dist/report.mjs.map +1 -1
  69. package/dist/{shared-CCaR42wo-BvegvmA_.mjs → result-B4XjxVK6.mjs} +127 -8
  70. package/dist/result-B4XjxVK6.mjs.map +1 -0
  71. package/dist/{result-CFqJKiqg.mjs → result-wonf1deB.mjs} +4 -18
  72. package/dist/result-wonf1deB.mjs.map +1 -0
  73. package/dist/run-alchemy-D44OZlyB-DA7s331N.mjs +93 -0
  74. package/dist/run-alchemy-D44OZlyB-DA7s331N.mjs.map +1 -0
  75. package/dist/run-alchemy-D44OZlyB-DeDTFsB6.mjs +93 -0
  76. package/dist/run-alchemy-D44OZlyB-DeDTFsB6.mjs.map +1 -0
  77. package/dist/service-rpc.d.mts +2 -2
  78. package/dist/service-rpc.mjs +2 -2
  79. package/dist/testing.d.mts +54 -2
  80. package/dist/testing.d.mts.map +1 -1
  81. package/dist/testing.mjs +150 -1
  82. package/dist/testing.mjs.map +1 -1
  83. package/package.json +12 -11
  84. package/src/exports/family.ts +14 -0
  85. package/src/exports/testing.ts +1 -0
  86. package/dist/app-config-CFsSXEVj-B242oUnm.d.mts.map +0 -1
  87. package/dist/cli-B3sWzFlb-CxEIzKsQ.mjs +0 -401
  88. package/dist/cli-B3sWzFlb-CxEIzKsQ.mjs.map +0 -1
  89. package/dist/config-ku5b_2YD.d.mts +0 -1
  90. package/dist/container-transport-DKmKg5JQ-BMRhx5w-.mjs +0 -75
  91. package/dist/container-transport-DKmKg5JQ-BMRhx5w-.mjs.map +0 -1
  92. package/dist/control.d.mts.map +0 -1
  93. package/dist/control.mjs.map +0 -1
  94. package/dist/deploy-ku5b_2YD.d.mts +0 -1
  95. package/dist/execute-deploy-destroy-IT4vGkMc-YM1Cv6cu.mjs.map +0 -1
  96. package/dist/execute-deploy-destroy-IT4vGkMc-oO8yjHPH.mjs.map +0 -1
  97. package/dist/execute-log-VIOL4DBz-DBPH8By4.mjs.map +0 -1
  98. package/dist/execute-log-VIOL4DBz-DKodBrxS.mjs.map +0 -1
  99. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts +0 -18
  100. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts.map +0 -1
  101. package/dist/graph-types-N6brq1zY-1VMNwtkJ.d.mts.map +0 -1
  102. package/dist/index-DryPyF9U.d.mts.map +0 -1
  103. package/dist/pipeline-D3QoVzAB-Ci2aJ2mE.mjs.map +0 -1
  104. package/dist/render-error-DsPN5qfr-CkVGj9uP.mjs +0 -30
  105. package/dist/render-error-DsPN5qfr-CkVGj9uP.mjs.map +0 -1
  106. package/dist/result-CFqJKiqg.mjs.map +0 -1
  107. package/dist/result-CzGChwbZ.mjs.map +0 -1
  108. package/dist/run-alchemy-hghRtddF-CQHOzlrW.mjs +0 -48
  109. package/dist/run-alchemy-hghRtddF-CQHOzlrW.mjs.map +0 -1
  110. package/dist/shared-CCaR42wo-BvegvmA_.mjs.map +0 -1
package/dist/bin.mjs CHANGED
@@ -1,18 +1,956 @@
1
1
  #!/usr/bin/env node
2
- import { a as CliStructuredError, t as checkEffectResolution } from "./shared-CCaR42wo-BvegvmA_.mjs";
3
- import { n as renderErrorEnvelope } from "./render-error-DsPN5qfr-CkVGj9uP.mjs";
4
- //#region ../../0-framework/3-tooling/cli/dist/bin.mjs
5
- try {
6
- checkEffectResolution(process.cwd());
7
- } catch (error) {
8
- if (CliStructuredError.is(error)) {
9
- console.error(renderErrorEnvelope(error.toEnvelope()));
10
- process.exit(2);
2
+ import { a as executionDiagnostics, l as DOCS_BASE, o as executorLoadFailure, t as notOk$1 } from "./result-B4XjxVK6.mjs";
3
+ import { t as alchemyCommandLine } from "./run-alchemy-D44OZlyB-DA7s331N.mjs";
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import { spawn } from "node:child_process";
7
+ import { EnvironmentCredentialManager, createCli, defineCommand, defineCommandFamily, defineConfigSection, defineSessionCommand, exitWithChildStatus, flag, loadConfig, positional } from "@prisma/cli-engine";
8
+ import { CliStructuredError, notOk, ok } from "@prisma/cli-engine/protocol";
9
+ import { fileURLToPath } from "node:url";
10
+ //#region ../../0-framework/3-tooling/cli/dist/log-DfT2hHqi.mjs
11
+ /** In-package variant threading the injection seam (the CLI's RunDeps, unit
12
+ * tests). Deliberately NOT re-exported through `./control` — the seam mirrors
13
+ * internal types and is not part of the published surface. */
14
+ async function deployWithDeps(input, deps) {
15
+ const cwd = input.cwd ?? process.cwd();
16
+ let executor;
17
+ try {
18
+ executor = await import("./execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs");
19
+ } catch (error) {
20
+ return notOk$1(executorLoadFailure("deploy", error, cwd));
21
+ }
22
+ return executor.executeDeploy(input, deps, cwd);
23
+ }
24
+ /** In-package variant threading the injection seam (the CLI's RunDeps, unit
25
+ * tests). Deliberately NOT re-exported through `./control` — the seam mirrors
26
+ * internal types and is not part of the published surface. */
27
+ async function destroyWithDeps(input, deps) {
28
+ const cwd = input.cwd ?? process.cwd();
29
+ let executor;
30
+ try {
31
+ executor = await import("./execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs");
32
+ } catch (error) {
33
+ return notOk$1(executorLoadFailure("destroy", error, cwd));
34
+ }
35
+ return executor.executeDestroy(input, deps, cwd);
36
+ }
37
+ /** In-package variant threading the injection seam (the CLI's RunDeps, unit
38
+ * tests). Deliberately NOT re-exported through `./control` — the seam mirrors
39
+ * internal types and is not part of the published surface. */
40
+ async function devWithDeps(input, deps) {
41
+ const cwd = input.cwd ?? process.cwd();
42
+ let executor;
43
+ try {
44
+ executor = await import("./execute-dev-BMTFWfFc-B1whS-Rr.mjs");
45
+ } catch (error) {
46
+ return notOk$1(executorLoadFailure("dev", error, cwd));
47
+ }
48
+ return executor.executeDev(input, deps, cwd);
49
+ }
50
+ /** In-package variant threading the injection seam (the CLI's LogRunDeps,
51
+ * unit tests). Deliberately NOT re-exported through `./control` — the seam
52
+ * mirrors internal types and is not part of the published surface. */
53
+ async function logWithDeps(input, deps) {
54
+ const cwd = input.cwd ?? process.cwd();
55
+ let executor;
56
+ try {
57
+ executor = await import("./execute-log-Cay9hlKW-DrMeVOXq.mjs");
58
+ } catch (error) {
59
+ return notOk$1(executorLoadFailure("log", error, cwd));
60
+ }
61
+ return executor.executeLog(input, deps, cwd);
62
+ }
63
+ //#endregion
64
+ //#region ../../0-framework/3-tooling/cli/dist/engine-cli-CrYVbsvO.mjs
65
+ /**
66
+ * The family boundary's error translation.
67
+ *
68
+ * Composer and the engine each carry a class called `CliStructuredError`, both
69
+ * descended from the same prisma/prisma foundation, and both recognize errors
70
+ * by duck-typing on `name === 'CliStructuredError'`. That means a composer
71
+ * error handed to the engine untranslated is ACCEPTED — it does not fail
72
+ * loudly, it renders. What it loses is its `fix`: composer's foundation
73
+ * carries remediation as one prose string on that field, the engine carries it
74
+ * as a `nextActions` list and has no `fix` at all, so the fix text is dropped
75
+ * silently and the user is told what broke with no word on what to do about
76
+ * it. Nothing about that failure is visible without a test that looks for the
77
+ * fix on the other side, which is why there is one.
78
+ *
79
+ * Everything else on the envelope survives as-is; only remediation changes
80
+ * representation.
81
+ */
82
+ /**
83
+ * Composer's `fix` is free prose — "add this overrides block and reinstall",
84
+ * "run the build, then retry" — with no machine-readable command inside it.
85
+ * `user-choice` is the engine's own kind for exactly that (it is what the
86
+ * engine uses for its own config and prompt failures), so the text carries
87
+ * over verbatim as one action rather than being parsed into a command the
88
+ * author never wrote.
89
+ */
90
+ function fixAsNextActions(fix) {
91
+ return fix === void 0 ? [] : [{
92
+ kind: "user-choice",
93
+ label: fix
94
+ }];
95
+ }
96
+ /** Translates a composer failure into the engine's error type. Composer-side detail — `meta`, `where`, `docsUrl` — rides along untouched. */
97
+ function toEngineError(error) {
98
+ return new CliStructuredError(error.code, error.message, {
99
+ severity: error.severity,
100
+ nextActions: fixAsNextActions(error.fix),
101
+ ...error.why === void 0 ? {} : { why: error.why },
102
+ ...error.where === void 0 ? {} : { where: error.where },
103
+ ...error.meta === void 0 ? {} : { meta: error.meta },
104
+ ...error.docsUrl === void 0 ? {} : { docsUrl: error.docsUrl },
105
+ cause: error
106
+ });
107
+ }
108
+ /** The adapter the operations call, backed by the engine's `ctx.spawn` so the
109
+ * terminal reaches alchemy natively and the engine owns signal policy. */
110
+ function convergeSpawn(ctx) {
111
+ return async (invocation) => {
112
+ const line = alchemyCommandLine(invocation);
113
+ return await ctx.spawn({
114
+ command: line.command,
115
+ args: line.args,
116
+ cwd: line.cwd,
117
+ env: line.env
118
+ });
119
+ };
120
+ }
121
+ /** The in-process leg's deps: composer's existing seam, carrying the engine's
122
+ * own client and workspace id rather than anything read from the env. */
123
+ function operationDeps(spec) {
124
+ return {
125
+ alchemy: spec.alchemy,
126
+ configPath: spec.configPath,
127
+ credentials: {
128
+ workspaceId: spec.workspaceId,
129
+ client: spec.client
130
+ }
131
+ };
132
+ }
133
+ /**
134
+ * The reproduce hint a failed converge carries. Deliberately absent for an
135
+ * aborted one: the user stopped it, so there is nothing to reproduce.
136
+ */
137
+ function reproduceHint(failure) {
138
+ const diagnostics = executionDiagnostics(failure);
139
+ if (diagnostics === void 0) return [];
140
+ return [{
141
+ kind: "run-command",
142
+ label: `Run the converge directly from ${diagnostics.cwd} to reproduce this`,
143
+ command: diagnostics.reproduceCommand,
144
+ reason: `Generated stack file: ${diagnostics.stackFilePath}`
145
+ }];
146
+ }
147
+ /**
148
+ * How a FAILED converge settles. `deploy`, `destroy` and `dev` all end this
149
+ * way and must not drift apart, so the decision lives here once rather than
150
+ * inline in each handler.
151
+ *
152
+ * A failure that reached the child exits with the child's status verbatim and
153
+ * carries the reproduce hint; a failure that never reached the child is an
154
+ * ordinary structured error and gets the normal envelope. Nothing here reads
155
+ * `signal` — see settleConverge.
156
+ */
157
+ function settleConvergeFailure(failure, ctx) {
158
+ const child = ctx.lastChild();
159
+ if (child !== void 0 && child.exitCode !== 0) return ok(exitWithChildStatus({ nextActions: reproduceHint(failure) }));
160
+ return notOk(toEngineError(failure));
161
+ }
162
+ /**
163
+ * How a converge settles, now that the engine owns the child's status.
164
+ *
165
+ * Nothing here reads `signal`. `exitWithChildStatus` settles from the engine's
166
+ * own record of the child, and a signal-killed one overrules whatever this
167
+ * function asked for: 128 + the signal, no failure envelope, and the reproduce
168
+ * hint dropped, because the user stopped the run and there is nothing to
169
+ * reproduce.
170
+ *
171
+ * What is left is the operation's own verdict. A failure that reached the
172
+ * child exits with the child's status verbatim and carries the reproduce hint;
173
+ * a failure that never reached the child is an ordinary structured error and
174
+ * gets the normal envelope.
175
+ *
176
+ * A SUCCESS presents its result even when the child was signal-killed. No
177
+ * composer operation produces that pair today — each one reports a
178
+ * signal-killed converge as a failure — and an operation that ever did would
179
+ * have a real result worth showing. The run still exits 130, because the
180
+ * engine settles a signal-terminated run from its own record of the signal
181
+ * whatever the handler returns.
182
+ */
183
+ function settleConverge(result, ctx, present) {
184
+ if (!result.ok) return settleConvergeFailure(result.failure, ctx);
185
+ return ok(present(result.value));
186
+ }
187
+ /**
188
+ * Composer's projection into `prisma.config.ts` — the `composer` section.
189
+ *
190
+ * The section is deliberately tiny. Composer's real configuration lives in
191
+ * `prisma-composer.config.ts`, which holds executable values (Effect layers,
192
+ * provider factories, container lifecycles) and can only be understood by
193
+ * evaluating it inside a running command. A config-section validator loads
194
+ * with the command tree at start-up and must be dependency-light and total,
195
+ * so it is the wrong place to evaluate any of that. What the section carries
196
+ * is therefore only the one fact the engine can usefully know before a
197
+ * command runs: WHERE that file is, when the user wants to say so.
198
+ *
199
+ * Its fields grow only by amending the slice contract.
200
+ */
201
+ const KNOWN_FIELDS = ["configPath"];
202
+ function diagnostic(spec) {
203
+ return {
204
+ code: spec.code,
205
+ severity: spec.severity,
206
+ summary: spec.summary,
207
+ ...spec.why === void 0 ? {} : { why: spec.why },
208
+ nextActions: spec.fix === void 0 ? [] : [{
209
+ kind: "edit-file",
210
+ label: spec.fix
211
+ }]
212
+ };
213
+ }
214
+ function validate(raw) {
215
+ if (raw === void 0) return {
216
+ ok: true,
217
+ value: {},
218
+ diagnostics: []
219
+ };
220
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {
221
+ ok: false,
222
+ diagnostics: [diagnostic({
223
+ code: "CONFIG.FIELD_INVALID",
224
+ severity: "error",
225
+ summary: "The `composer` section of prisma.config.ts must be an object.",
226
+ fix: "Write `composer: { configPath: \"./prisma-composer.config.ts\" }`, or remove the section entirely."
227
+ })]
228
+ };
229
+ let record;
230
+ try {
231
+ record = { ...raw };
232
+ } catch {
233
+ return {
234
+ ok: false,
235
+ diagnostics: [diagnostic({
236
+ code: "CONFIG.FIELD_INVALID",
237
+ severity: "error",
238
+ summary: "The `composer` section of prisma.config.ts could not be read.",
239
+ why: "Reading its fields threw, so nothing in it can be trusted.",
240
+ fix: "Write it as a plain object literal, e.g. `composer: { configPath: \"./prisma-composer.config.ts\" }`."
241
+ })]
242
+ };
11
243
  }
12
- throw error;
244
+ const configPath = record["configPath"];
245
+ if (configPath !== void 0 && (typeof configPath !== "string" || configPath.length === 0)) return {
246
+ ok: false,
247
+ diagnostics: [diagnostic({
248
+ code: "CONFIG.FIELD_INVALID",
249
+ severity: "error",
250
+ summary: "`composer.configPath` must be a non-empty string.",
251
+ why: "It names the prisma-composer.config.ts file to load.",
252
+ fix: "Set it to a path, or remove it to search upward from the entry."
253
+ })]
254
+ };
255
+ const unknown = Object.keys(record).filter((key) => !KNOWN_FIELDS.includes(key));
256
+ return {
257
+ ok: true,
258
+ value: configPath === void 0 ? {} : { configPath },
259
+ diagnostics: unknown.map((key) => diagnostic({
260
+ code: "CONFIG.FIELD_UNKNOWN",
261
+ severity: "warn",
262
+ summary: `The \`composer\` section has no field \`${key}\`; it is ignored.`,
263
+ fix: `Remove \`${key}\`, or check it against the version of @prisma/composer you have installed.`
264
+ }))
265
+ };
266
+ }
267
+ const composerSection = defineConfigSection({
268
+ name: "composer",
269
+ validate
270
+ });
271
+ /**
272
+ * The workspace the in-process leg acts in, from the engine's credential
273
+ * read. Handlers never decode a token and never read PRISMA_WORKSPACE_ID:
274
+ * whether the credential came from a stored session or the environment, the
275
+ * engine has already resolved it, and branching on where it came from is a
276
+ * defect by the credential-manager design.
277
+ *
278
+ * Undefined when the active credential names no workspace — an environment
279
+ * token whose claims carry none. The container descriptors raise their own
280
+ * "workspace required" error in that case, which is the error the user needs.
281
+ */
282
+ async function workspaceIdOf(ctx) {
283
+ return (await ctx.activeCredential())?.workspaceId;
13
284
  }
14
- const { cli } = await import("./cli-B3sWzFlb-CxEIzKsQ.mjs");
15
- cli();
285
+ /**
286
+ * `deploy <entry>` — a result command that hands the terminal to alchemy.
287
+ *
288
+ * `--production` is gone. It was accepted and then always errored ("only
289
+ * valid with destroy"), so no invocation using it could ever have succeeded;
290
+ * deploy targets production by default when no `--stage` is given.
291
+ */
292
+ const createDeployCommand = (operations) => defineCommand({
293
+ help: {
294
+ summary: "Deploy the application whose root node is <entry>'s default export.",
295
+ examples: ["{bin} deploy src/service.ts", "{bin} deploy src/service.ts --stage feat-auth"]
296
+ },
297
+ args: {
298
+ positionals: { entry: positional.string({
299
+ brief: "The module whose default export is the application root.",
300
+ placeholder: "entry"
301
+ }) },
302
+ flags: {
303
+ name: flag.string({
304
+ brief: "Override the root node's name — the deploy's application name.",
305
+ placeholder: "name"
306
+ }),
307
+ stage: flag.string({
308
+ brief: "Deploy scope to target; omit for production.",
309
+ placeholder: "stage"
310
+ })
311
+ }
312
+ },
313
+ needs: {
314
+ config: composerSection,
315
+ credentials: "child"
316
+ },
317
+ maySpawn: true,
318
+ handler: async (args, ctx) => {
319
+ const alchemy = convergeSpawn(ctx);
320
+ return settleConverge(await operations.deploy({
321
+ entry: args.positionals.entry,
322
+ name: args.flags.name,
323
+ stage: args.flags.stage,
324
+ cwd: ctx.cwd
325
+ }, operationDeps({
326
+ alchemy,
327
+ configPath: ctx.config.configPath,
328
+ workspaceId: await workspaceIdOf(ctx),
329
+ client: ctx.api
330
+ })), ctx, ({ summary }) => ctx.present({ data: { summary: summary ?? null } }, {
331
+ human: (ui) => summary === void 0 ? [{
332
+ kind: "summary",
333
+ tone: "ok",
334
+ text: "Deployed."
335
+ }] : [{
336
+ kind: "summary",
337
+ tone: "ok",
338
+ text: `Deployed ${ui.emphasize(summary.app)}.`
339
+ }, {
340
+ kind: "table",
341
+ columns: ["Address", "Deployed"],
342
+ rows: summary.nodes.map((node) => [node.address, node.entities.map((entity) => `${entity.kind} ${entity.id}`).join(", ")])
343
+ }],
344
+ json: () => ({ summary: summary ?? null })
345
+ }));
346
+ }
347
+ });
348
+ /**
349
+ * `destroy`'s target, from its two mutually exclusive flags. Kept out of the
350
+ * grammar because the engine's flag layer has no "exactly one of these"
351
+ * construct — and because both wrong shapes need their own remedy, which a
352
+ * generic arity error could not give.
353
+ */
354
+ function targetOf(stage, production) {
355
+ if (stage !== void 0 && production) return notOk(new CliStructuredError("DEPLOY.TARGET_CONFLICT", "Pass either --stage <name> or --production to `destroy`, not both."));
356
+ if (stage === void 0 && !production) return notOk(new CliStructuredError("DEPLOY.TARGET_MISSING", "`destroy` requires an explicit target.", { nextActions: [{
357
+ kind: "user-choice",
358
+ label: "Pass --stage <name> to tear down a branch environment, or --production to tear down the production environment."
359
+ }] }));
360
+ return ok(stage !== void 0 ? {
361
+ kind: "stage",
362
+ stage
363
+ } : { kind: "production" });
364
+ }
365
+ /**
366
+ * `destroy <entry>` — deploy's mirror: same derivation, alchemy destroy.
367
+ *
368
+ * No confirmation prompt, matching the CLI this replaces. The front door
369
+ * cannot know what the child will tear down, so a consent step here would be
370
+ * asking the user to approve a list nobody has computed yet; if destroy
371
+ * deserves one it belongs in composer's own operation, not in the grammar.
372
+ */
373
+ const createDestroyCommand = (operations) => defineCommand({
374
+ help: {
375
+ summary: "Tear down the application whose root node is <entry>'s default export.",
376
+ description: "Same derivation as deploy. Requires an explicit target: --stage <name> for a branch environment, or --production for the production environment.",
377
+ examples: ["{bin} destroy src/service.ts --stage feat-auth", "{bin} destroy src/service.ts --production"]
378
+ },
379
+ args: {
380
+ positionals: { entry: positional.string({
381
+ brief: "The module whose default export is the application root.",
382
+ placeholder: "entry"
383
+ }) },
384
+ flags: {
385
+ name: flag.string({
386
+ brief: "Override the root node's name — the application name to tear down.",
387
+ placeholder: "name"
388
+ }),
389
+ stage: flag.string({
390
+ brief: "Tear down this branch environment.",
391
+ placeholder: "stage"
392
+ }),
393
+ production: flag.boolean({ brief: "Tear down the project-level production environment." })
394
+ }
395
+ },
396
+ needs: {
397
+ config: composerSection,
398
+ credentials: "child"
399
+ },
400
+ maySpawn: true,
401
+ handler: async (args, ctx) => {
402
+ const target = targetOf(args.flags.stage, args.flags.production);
403
+ if (!target.ok) return target;
404
+ const alchemy = convergeSpawn(ctx);
405
+ return settleConverge(await operations.destroy({
406
+ entry: args.positionals.entry,
407
+ name: args.flags.name,
408
+ target: target.value,
409
+ cwd: ctx.cwd,
410
+ onEvent: (event) => {
411
+ if (event.kind !== "no-local-deploy-state") return;
412
+ ctx.report({
413
+ kind: "message",
414
+ severity: "warn",
415
+ text: `No prior deploy state under ${event.cwd} — if you deployed from a different directory, run destroy from there; otherwise this is a no-op.`
416
+ });
417
+ }
418
+ }, operationDeps({
419
+ alchemy,
420
+ configPath: ctx.config.configPath,
421
+ workspaceId: await workspaceIdOf(ctx),
422
+ client: ctx.api
423
+ })), ctx, () => ctx.present({ data: void 0 }, { human: () => [{
424
+ kind: "summary",
425
+ tone: "ok",
426
+ text: "Destroyed."
427
+ }] }));
428
+ }
429
+ });
430
+ const STOP_STEP = "Stopping the app's services — emulators and data stay up";
431
+ /** Resolves when the run is asked to stop. */
432
+ function stopRequested(signal) {
433
+ if (signal.aborted) return Promise.resolve();
434
+ return new Promise((resolve) => {
435
+ signal.addEventListener("abort", () => resolve(), { once: true });
436
+ });
437
+ }
438
+ /**
439
+ * One converge at a time. `ctx.spawn` refuses a second live child, and the
440
+ * watch loop can well fire a rebuild while the previous converge is still
441
+ * running — so a request that arrives during a live converge joins the single
442
+ * queued follow-up instead of starting its own. That extends the coalescing
443
+ * the watcher already does across a burst of edits to cover the converge
444
+ * itself, and it is sound because every dev converge is the SAME invocation:
445
+ * one stack file at one fixed path, rewritten in place before each request.
446
+ */
447
+ function coalescedConverge(run) {
448
+ let live;
449
+ let queued;
450
+ const start = (invocation) => {
451
+ const outcome = run(invocation);
452
+ const settled = outcome.then(() => void 0, () => void 0);
453
+ live = settled;
454
+ settled.then(() => {
455
+ if (live === settled) live = void 0;
456
+ });
457
+ return outcome;
458
+ };
459
+ return (invocation) => {
460
+ const running = live;
461
+ if (running === void 0) return start(invocation);
462
+ queued ??= running.then(() => {
463
+ queued = void 0;
464
+ return start(invocation);
465
+ });
466
+ return queued;
467
+ };
468
+ }
469
+ /** The front door, ordered by address depth (fewest dots first) then lexicographically. */
470
+ function frontDoorOrder(endpoints) {
471
+ return [...endpoints].sort((a, b) => {
472
+ const depth = a.address.split(".").length - b.address.split(".").length;
473
+ if (depth !== 0) return depth;
474
+ return a.address < b.address ? -1 : a.address > b.address ? 1 : 0;
475
+ });
476
+ }
477
+ /**
478
+ * The operation's events as engine events. The legacy `[dev]` console prefix
479
+ * is gone: these are commentary the engine renders and frames.
480
+ */
481
+ function reportDevEvent(report, lastChild) {
482
+ let stopFailed = false;
483
+ return (event) => {
484
+ switch (event.kind) {
485
+ case "ready":
486
+ report({
487
+ kind: "status",
488
+ subject: "dev",
489
+ status: "ready"
490
+ });
491
+ for (const endpoint of frontDoorOrder(event.endpoints)) report({
492
+ kind: "endpoint",
493
+ name: endpoint.address,
494
+ url: endpoint.url
495
+ });
496
+ return;
497
+ case "unwatchable":
498
+ report({
499
+ kind: "message",
500
+ severity: "warn",
501
+ text: `${event.address} has no watchable inputs.`
502
+ });
503
+ return;
504
+ case "rebuild-failed":
505
+ report({
506
+ kind: "message",
507
+ severity: "warn",
508
+ text: `Rebuild failed: ${event.message}`
509
+ });
510
+ return;
511
+ case "watch-error":
512
+ report({
513
+ kind: "message",
514
+ severity: "warn",
515
+ text: `Watch error: ${event.message}`
516
+ });
517
+ return;
518
+ case "converge-failed": {
519
+ const child = lastChild();
520
+ if (child !== void 0 && child.signal !== null) return;
521
+ report({
522
+ kind: "message",
523
+ severity: "warn",
524
+ text: `Converge failed — the running app is untouched; still watching.
525
+ Generated stack file: ${event.stackFilePath}\nRun \`${event.reproduceCommand}\` from ${event.cwd} to reproduce this directly.`
526
+ });
527
+ report({
528
+ kind: "remediation",
529
+ action: {
530
+ kind: "run-command",
531
+ label: `Run the converge directly from ${event.cwd} to reproduce this`,
532
+ command: event.reproduceCommand,
533
+ reason: `Generated stack file: ${event.stackFilePath}`
534
+ }
535
+ });
536
+ return;
537
+ }
538
+ case "stopping":
539
+ report({
540
+ kind: "step-started",
541
+ step: STOP_STEP,
542
+ id: "dev-stop"
543
+ });
544
+ return;
545
+ case "stop-error":
546
+ stopFailed = true;
547
+ report({
548
+ kind: "message",
549
+ severity: "warn",
550
+ text: `A service refused to stop: ${event.message}`
551
+ });
552
+ return;
553
+ case "stopped":
554
+ report({
555
+ kind: "step-finished",
556
+ step: STOP_STEP,
557
+ id: "dev-stop",
558
+ outcome: stopFailed ? "warning" : "ok"
559
+ });
560
+ return;
561
+ }
562
+ };
563
+ }
564
+ const createDevCommand = (operations) => defineSessionCommand({
565
+ help: {
566
+ summary: "Bring up the application whose root node is <entry>'s default export, entirely on this machine.",
567
+ description: "Runs credential-free and watches the app for changes, reconverging on every edit. Logs are a separate command; run `log <entry>` to tail them.",
568
+ examples: ["{bin} dev src/service.ts", "{bin} dev src/service.ts --fresh"]
569
+ },
570
+ args: {
571
+ positionals: { entry: positional.string({
572
+ brief: "The module whose default export is the application root.",
573
+ placeholder: "entry"
574
+ }) },
575
+ flags: {
576
+ name: flag.string({
577
+ brief: "Override the root node's name — the dev instance's application name.",
578
+ placeholder: "name"
579
+ }),
580
+ fresh: flag.boolean({ brief: "Destroy the dev stack and wipe the dev state directory before starting." })
581
+ }
582
+ },
583
+ needs: { config: composerSection },
584
+ maySpawn: true,
585
+ handler: async (args, ctx) => {
586
+ const alchemy = convergeSpawn(ctx);
587
+ const result = await operations.dev({
588
+ entry: args.positionals.entry,
589
+ name: args.flags.name,
590
+ fresh: args.flags.fresh,
591
+ cwd: ctx.cwd,
592
+ onEvent: reportDevEvent(ctx.report, ctx.lastChild)
593
+ }, {
594
+ alchemy: coalescedConverge(alchemy),
595
+ configPath: ctx.config.configPath
596
+ });
597
+ if (!result.ok) return settleConvergeFailure(result.failure, ctx);
598
+ await stopRequested(ctx.signal);
599
+ await result.value.stop();
600
+ return ok(void 0);
601
+ }
602
+ });
603
+ /**
604
+ * `log <entry> [address]` — a session command that tails the merged logs of
605
+ * the app running locally on this machine.
606
+ *
607
+ * It reads the LOCAL dev-emulator daemon, not the platform's logs surface, so
608
+ * it is credential-free. It hands the terminal to nothing, which is why it
609
+ * does not declare `maySpawn` and keeps json support: the log lines ARE its
610
+ * json surface.
611
+ *
612
+ * Windows is refused inside the operation itself (LOG.PLATFORM_UNSUPPORTED),
613
+ * which is why nothing here reads the platform.
614
+ */
615
+ /** An empty screen reads as broken, so show a little recent history before going live. */
616
+ const DEFAULT_TAIL = 20;
617
+ const createLogCommand = (operations) => defineSessionCommand({
618
+ help: {
619
+ summary: "Tail the merged logs of the locally-running application whose root node is <entry>'s default export.",
620
+ examples: ["{bin} log src/service.ts", "{bin} log src/service.ts catalog.service"]
621
+ },
622
+ args: {
623
+ positionals: {
624
+ entry: positional.string({
625
+ brief: "The module whose default export is the application root.",
626
+ placeholder: "entry"
627
+ }),
628
+ address: positional.optionalString({
629
+ brief: "Only this service's lines, by its dotted address (catalog.service); every service when absent.",
630
+ placeholder: "address"
631
+ })
632
+ },
633
+ flags: {
634
+ name: flag.string({
635
+ brief: "Override the root node's name — the dev instance's application name.",
636
+ placeholder: "name"
637
+ }),
638
+ tail: flag.number({
639
+ brief: `How many trailing history lines to show before live output (default ${String(DEFAULT_TAIL)}).`,
640
+ placeholder: "lines",
641
+ default: DEFAULT_TAIL
642
+ })
643
+ }
644
+ },
645
+ needs: { config: composerSection },
646
+ handler: async (args, ctx) => {
647
+ const reportLogEvent = (event) => {
648
+ ctx.report({
649
+ kind: "message",
650
+ severity: "warn",
651
+ text: event.kind === "stream-failed" ? `Stream failed: ${event.message}` : `Falling behind — dropped the ${String(event.count)} oldest lines.`
652
+ });
653
+ };
654
+ const result = await operations.log({
655
+ entry: args.positionals.entry,
656
+ name: args.flags.name,
657
+ address: args.positionals.address,
658
+ tail: args.flags.tail ?? DEFAULT_TAIL,
659
+ cwd: ctx.cwd,
660
+ signal: ctx.signal,
661
+ onEvent: reportLogEvent
662
+ }, { configPath: ctx.config.configPath });
663
+ if (!result.ok) return notOk(toEngineError(result.failure));
664
+ const attached = result.value;
665
+ if (attached.services.length === 0) {
666
+ ctx.report({
667
+ kind: "message",
668
+ severity: "warn",
669
+ text: `No running services for "${attached.appName}" — start it first with \`dev ${args.positionals.entry}\`.`
670
+ });
671
+ return ok(void 0);
672
+ }
673
+ for await (const { service, line } of attached.lines) ctx.report({
674
+ kind: "output",
675
+ source: service,
676
+ channel: "data",
677
+ line: `[${service}] ${line}`
678
+ });
679
+ return ok(void 0);
680
+ }
681
+ });
682
+ /**
683
+ * Composer's `CommandFamily` — the unit the engine mounts, whether the process
684
+ * is composer's own CLI or the `prisma` bin.
685
+ *
686
+ * This module and everything it reaches statically must stay free of alchemy
687
+ * and of effect VALUE imports: the `prisma` bin imports the family directly,
688
+ * so anything in this static graph loads on `prisma --version`. The mechanism
689
+ * that holds it is the existing lazy boundary inside the operation modules —
690
+ * `operations/deploy.ts`, `destroy.ts`, `dev.ts` and `log.ts` each `await
691
+ * import()` their executor, and it is the executors that reach the provider
692
+ * tree. Importing the operations here is therefore free; importing an
693
+ * executor, or flattening one of those dynamic imports, is not.
694
+ * scripts/check-family-static-graph.mjs enforces this against BUILT output,
695
+ * where type-only imports have already been erased.
696
+ *
697
+ * The four commands close over the operations they are given, so a host can
698
+ * mount this family against the test double and exercise real grammar, real
699
+ * arg validation and real handlers with no alchemy behind them.
700
+ */
701
+ const realOperations = {
702
+ deploy: deployWithDeps,
703
+ destroy: destroyWithDeps,
704
+ dev: devWithDeps,
705
+ log: logWithDeps
706
+ };
707
+ function createComposerFamily(options = {}) {
708
+ const operations = options.operations ?? realOperations;
709
+ return defineCommandFamily({
710
+ configSection: composerSection,
711
+ commands: {
712
+ deploy: createDeployCommand(operations),
713
+ destroy: createDestroyCommand(operations),
714
+ dev: createDevCommand(operations),
715
+ log: createLogCommand(operations)
716
+ },
717
+ docsBaseUrl: DOCS_BASE
718
+ });
719
+ }
720
+ /**
721
+ * Everything environmental the engine needs, assembled from a host process.
722
+ *
723
+ * The engine takes no globals: streams, cwd, env, TTY-ness, exit and signal
724
+ * subscription all arrive through `Runtime`, which is what lets a test drive a
725
+ * whole run without touching `process`. Composing one is the substantive part
726
+ * of hosting the engine — `createCli` and `Cli.run` are two calls.
727
+ *
728
+ * Credentials come from the engine's own environment-only manager, which
729
+ * composes a session from PRISMA_SERVICE_TOKEN / PRISMA_WORKSPACE_ID and
730
+ * refuses every mutation. That is the whole of composer's standalone auth
731
+ * story: this CLI has no login flow and mounts no auth commands, so there is
732
+ * nothing to store — the two variables ARE the credential.
733
+ */
734
+ /** Where the management API lives. Matches the lowering client's default origin; the env var is the escape hatch for staging. */
735
+ const DEFAULT_MANAGEMENT_API_BASE_URL = "https://api.prisma.io";
736
+ const DEFAULT_AUTH_BASE_URL = "https://auth.prisma.io";
737
+ /**
738
+ * Starts the converge child: inherited stdio, this process's own group, no
739
+ * `detached` and no new console — which is what lets the terminal deliver
740
+ * Ctrl-C to the child natively instead of the CLI forwarding it. The engine
741
+ * never imports node:child_process; this adapter is the whole of the host's
742
+ * side of that seam.
743
+ */
744
+ const spawnChild = (request) => {
745
+ const child = spawn(request.command, [...request.args], {
746
+ cwd: request.cwd,
747
+ stdio: "inherit",
748
+ env: request.env
749
+ });
750
+ return {
751
+ ended: new Promise((resolve, reject) => {
752
+ child.on("error", reject);
753
+ child.on("close", (exitCode, signal) => {
754
+ resolve({
755
+ exitCode,
756
+ signal
757
+ });
758
+ });
759
+ }),
760
+ kill: (signal) => {
761
+ child.kill(signal);
762
+ }
763
+ };
764
+ };
765
+ /**
766
+ * The SDK's client construction config. The engine requires all four fields
767
+ * whenever a credential manager is wired, but this host reaches none of the
768
+ * login paths: an environment credential carries no refresh token, so nothing
769
+ * ever refreshes and `clientId`/`redirectUri` are never read. They are
770
+ * env-overridable rather than hard-coded so a staging run can point the whole
771
+ * client somewhere else in one place.
772
+ */
773
+ function clientConfig(env, apiBaseUrl) {
774
+ return {
775
+ clientId: env["PRISMA_CLIENT_ID"] ?? "prisma-composer-cli",
776
+ redirectUri: env["PRISMA_REDIRECT_URI"] ?? "http://127.0.0.1/callback",
777
+ apiBaseUrl,
778
+ authBaseUrl: env["PRISMA_AUTH_URL"] ?? DEFAULT_AUTH_BASE_URL
779
+ };
780
+ }
781
+ /**
782
+ * Which package manager invoked us, read from the `npm_config_user_agent`
783
+ * every major manager sets (`pnpm/10.27.0 npm/? node/v24.16.0 darwin arm64`).
784
+ * `unknown` when the CLI was run directly rather than through a manager — a
785
+ * normal case, not a failure, so nothing is inferred from the filesystem.
786
+ */
787
+ function detectPackageManager(env) {
788
+ const agent = env["npm_config_user_agent"];
789
+ if (agent === void 0) return "unknown";
790
+ const name = agent.split("/")[0];
791
+ switch (name) {
792
+ case "npm":
793
+ case "pnpm":
794
+ case "yarn":
795
+ case "bun": return name;
796
+ default: return "unknown";
797
+ }
798
+ }
799
+ /**
800
+ * The config loader arrives as a function rather than an already-loaded config
801
+ * because the engine reads `prisma.config.ts` on demand — only when the command
802
+ * it is about to run declares a config section, and with whatever file
803
+ * `--config` named. A host that loaded the file up front would read it for runs
804
+ * that never needed it, and would have nowhere to put `--config`.
805
+ */
806
+ function createRuntime(host, loadConfig) {
807
+ const env = host.env;
808
+ const apiBaseUrl = env["PRISMA_MANAGEMENT_API_URL"] ?? DEFAULT_MANAGEMENT_API_BASE_URL;
809
+ return {
810
+ stdout: host.stdout,
811
+ stderr: host.stderr,
812
+ stdin: host.stdin,
813
+ cwd: host.cwd(),
814
+ env,
815
+ isTty: {
816
+ stdin: host.stdin.isTTY === true,
817
+ stdout: host.stdout.isTTY === true,
818
+ stderr: host.stderr.isTTY === true
819
+ },
820
+ exit: (code) => host.exit(code),
821
+ onSignal: (cb) => {
822
+ const onSigint = () => {
823
+ cb("SIGINT");
824
+ };
825
+ const onSigterm = () => {
826
+ cb("SIGTERM");
827
+ };
828
+ host.on("SIGINT", onSigint);
829
+ host.on("SIGTERM", onSigterm);
830
+ return () => {
831
+ host.off("SIGINT", onSigint);
832
+ host.off("SIGTERM", onSigterm);
833
+ };
834
+ },
835
+ loadConfig,
836
+ credentialManager: new EnvironmentCredentialManager({ env }),
837
+ managementApiClientConfig: clientConfig(env, apiBaseUrl),
838
+ spawn: spawnChild,
839
+ managementApi: { baseUrl: apiBaseUrl },
840
+ packageManager: detectPackageManager(env)
841
+ };
842
+ }
843
+ /**
844
+ * Composer's own CLI, rebuilt as a thin composition of the family it
845
+ * publishes: `createCli` over `createComposerFamily()`, `Cli.run` with a
846
+ * Runtime. Grammar, help, arg validation, output framing, exit codes and
847
+ * signal ownership all belong to the engine now — this module contributes the
848
+ * family and the environment, and nothing else.
849
+ *
850
+ * Running composer's commands through the same path an external host uses is
851
+ * the point: it is what proves the family works standalone before the `prisma`
852
+ * bin mounts it.
853
+ *
854
+ * This IS composer's CLI. The clipanion shell it replaced, and the bespoke
855
+ * runner that shelled out to alchemy, are gone; `bin.ts` is a call into here.
856
+ */
857
+ const BINARY_NAME = "prisma-composer";
858
+ /**
859
+ * Composer's commands mount at the top level of its own CLI (`prisma-composer
860
+ * deploy`); under the `prisma` bin the same family mounts one level down
861
+ * (`prisma composer deploy`). The family is identical either way — only the
862
+ * mount paths differ, which is exactly the split `createCli` draws between
863
+ * `commandFamilies` and `commands`.
864
+ */
865
+ function mountedTree(family) {
866
+ return { ...family.commands };
867
+ }
868
+ function createComposerCli(spec) {
869
+ const family = createComposerFamily({ operations: spec.operations });
870
+ return createCli({
871
+ name: BINARY_NAME,
872
+ version: spec.version,
873
+ commandFamilies: [family],
874
+ groups: {},
875
+ commands: mountedTree(family)
876
+ });
877
+ }
878
+ /**
879
+ * Composes the Runtime and runs one invocation. Returns the exit code rather
880
+ * than exiting, so the caller owns the process — a bin assigns it to
881
+ * `process.exitCode` and lets the streams drain, as composer's CLI has always
882
+ * done.
883
+ *
884
+ * `prisma.config.ts` is not read here. The loader goes in as a function, and the
885
+ * engine calls it only when the command it is about to run declares a config
886
+ * section, passing it the file `--config` named; the loader resolves that
887
+ * against the host's cwd.
888
+ */
889
+ function runComposerCli(argv, host, spec, hooks) {
890
+ const runtime = createRuntime(host, (configPath) => loadConfig(host.cwd(), configPath));
891
+ return createComposerCli(spec).run(argv, runtime, hooks);
892
+ }
893
+ //#endregion
894
+ //#region ../../0-framework/3-tooling/cli/dist/cli-DKVwu4w4.mjs
895
+ /**
896
+ * The `prisma-composer` entrypoint: adapt this process into the engine's
897
+ * `HostProcess`, run one invocation of composer's own CLI, and hand back an
898
+ * exit code. Grammar, help, argument validation, output framing, exit codes
899
+ * and signal policy all belong to the engine — this module contributes the
900
+ * process and the version, and nothing else.
901
+ *
902
+ * Node's `process` already satisfies `HostProcess` structurally, so there is
903
+ * no adapter object here; that is the whole point of the engine taking a host
904
+ * surface rather than reading globals.
905
+ */
906
+ /** Printed for a throw that escapes the engine entirely — by the shared base-type rules that is a bug, not a user failure. */
907
+ const REPORT_HINT = "This is a bug in prisma-composer, not in your app — please report it: https://github.com/prisma/composer/issues";
908
+ const UNKNOWN_VERSION = "unknown";
909
+ /**
910
+ * The version the CLI reports, read from the manifest of the package this
911
+ * module was BUNDLED INTO — `@prisma/composer` for the published bin, since
912
+ * that is the package whose executable the user installed. Walking up from the
913
+ * module's own location is what makes that true in both layouts: the published
914
+ * `dist/bin.mjs` finds `@prisma/composer`'s manifest, and a direct run of
915
+ * `src/bin.ts` finds this package's.
916
+ */
917
+ function shippedVersion(fromDir = path.dirname(fileURLToPath(import.meta.url))) {
918
+ let dir = fromDir;
919
+ while (true) {
920
+ const manifest = path.join(dir, "package.json");
921
+ if (fs.existsSync(manifest)) try {
922
+ const version = JSON.parse(fs.readFileSync(manifest, "utf-8")).version;
923
+ return typeof version === "string" ? version : UNKNOWN_VERSION;
924
+ } catch {
925
+ return UNKNOWN_VERSION;
926
+ }
927
+ const parent = path.dirname(dir);
928
+ if (parent === dir) return UNKNOWN_VERSION;
929
+ dir = parent;
930
+ }
931
+ }
932
+ /**
933
+ * Runs `prisma-composer` end to end and returns the process exit code. The
934
+ * caller assigns it to `process.exitCode` rather than exiting, so the streams
935
+ * drain — the engine returns a code for exactly this reason.
936
+ *
937
+ * The catch is not error handling for commands: the engine renders every
938
+ * command failure itself. It catches a throw that escaped the engine — a
939
+ * construction fault, a broken config load — which by ADR-0044 is a bug in
940
+ * this CLI and exits 1 with a report hint.
941
+ */
942
+ async function cli(argv = process.argv.slice(2)) {
943
+ try {
944
+ return await runComposerCli(argv, process, { version: shippedVersion() });
945
+ } catch (error) {
946
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
947
+ console.error(REPORT_HINT);
948
+ return 1;
949
+ }
950
+ }
951
+ //#endregion
952
+ //#region ../../0-framework/3-tooling/cli/dist/bin.mjs
953
+ process.exitCode = await cli();
16
954
  //#endregion
17
955
  export {};
18
956