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