@prisma/composer 0.6.0-dev.2 → 0.6.0-dev.20

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 (75) hide show
  1. package/dist/{app-config-Cbv_lA38-BHJsd1DF.d.mts → app-config-aIrriqVU-Dpj1RqnY.d.mts} +43 -17
  2. package/dist/app-config-aIrriqVU-Dpj1RqnY.d.mts.map +1 -0
  3. package/dist/config-BeBRB-6m.d.mts +1 -0
  4. package/dist/config.d.mts +3 -3
  5. package/dist/control.d.mts +219 -0
  6. package/dist/control.d.mts.map +1 -0
  7. package/dist/control.mjs +70 -0
  8. package/dist/control.mjs.map +1 -0
  9. package/dist/deploy-BeBRB-6m.d.mts +1 -0
  10. package/dist/deploy.d.mts +2 -2
  11. package/dist/deploy.mjs +312 -1
  12. package/dist/deploy.mjs.map +1 -0
  13. package/dist/deployment-summary-DswOl_9E-C03NJ98H.mjs +70 -0
  14. package/dist/deployment-summary-DswOl_9E-C03NJ98H.mjs.map +1 -0
  15. package/dist/{dist-BdvFDCLV.mjs → dist-C5rZnr4n.mjs} +2 -2
  16. package/dist/{dist-BdvFDCLV.mjs.map → dist-C5rZnr4n.mjs.map} +1 -1
  17. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs +24 -0
  18. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs.map +1 -0
  19. package/dist/errors-0e8IVwzi.mjs +88 -0
  20. package/dist/errors-0e8IVwzi.mjs.map +1 -0
  21. package/dist/execute-deploy-destroy-DfVJUICu-Dbgn1GR_.mjs +275 -0
  22. package/dist/execute-deploy-destroy-DfVJUICu-Dbgn1GR_.mjs.map +1 -0
  23. package/dist/execute-dev-BMTFWfFc-CGDFqR4w.mjs +2014 -0
  24. package/dist/execute-dev-BMTFWfFc-CGDFqR4w.mjs.map +1 -0
  25. package/dist/execute-log-Cay9hlKW-ChlIv192.mjs +160 -0
  26. package/dist/execute-log-Cay9hlKW-ChlIv192.mjs.map +1 -0
  27. package/dist/{graph-DgbALPDo-BEHF94BN.mjs → graph-BJgUfGB0-kvgFzT4q.mjs} +13 -7
  28. package/dist/graph-BJgUfGB0-kvgFzT4q.mjs.map +1 -0
  29. package/dist/{graph-DDpXh7S8-b-93BcHn.d.mts → graph-DqklX5Sf-BNS2aO1j.d.mts} +3 -3
  30. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts.map +1 -0
  31. package/dist/{graph-types-C3FOaaXm-C6_rGzfn.d.mts → graph-types-N6brq1zY-1VMNwtkJ.d.mts} +88 -5
  32. package/dist/graph-types-N6brq1zY-1VMNwtkJ.d.mts.map +1 -0
  33. package/dist/{index-BQVrMGfe.d.mts → index-DryPyF9U.d.mts} +3 -3
  34. package/dist/{index-BQVrMGfe.d.mts.map → index-DryPyF9U.d.mts.map} +1 -1
  35. package/dist/index.d.mts +3 -3
  36. package/dist/index.mjs +2 -2
  37. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs +18 -0
  38. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs.map +1 -0
  39. package/dist/local-target-DnA2E8IN.mjs +47 -0
  40. package/dist/local-target-DnA2E8IN.mjs.map +1 -0
  41. package/dist/local-target.d.mts +1 -1
  42. package/dist/local-target.mjs +2 -46
  43. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts → nextjs-DLyeRR7M-DZODs9tk.d.mts} +3 -3
  44. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts.map → nextjs-DLyeRR7M-DZODs9tk.d.mts.map} +1 -1
  45. package/dist/nextjs-control.d.mts +4 -4
  46. package/dist/nextjs.d.mts +1 -1
  47. package/dist/node-control.d.mts +3 -3
  48. package/dist/node.d.mts +2 -2
  49. package/dist/pipeline-AoW8zq4I-CUon5KZH.mjs +452 -0
  50. package/dist/pipeline-AoW8zq4I-CUon5KZH.mjs.map +1 -0
  51. package/dist/report.d.mts +4 -3
  52. package/dist/report.d.mts.map +1 -1
  53. package/dist/report.mjs +4 -1
  54. package/dist/report.mjs.map +1 -1
  55. package/dist/result-CY_TB7bn.mjs +247 -0
  56. package/dist/result-CY_TB7bn.mjs.map +1 -0
  57. package/dist/run-alchemy-D44OZlyB-gVq_0gf4.mjs +93 -0
  58. package/dist/run-alchemy-D44OZlyB-gVq_0gf4.mjs.map +1 -0
  59. package/dist/service-rpc.d.mts +2 -2
  60. package/dist/service-rpc.mjs +2 -2
  61. package/dist/testing.d.mts +1 -1
  62. package/package.json +17 -21
  63. package/src/exports/control.ts +1 -0
  64. package/src/exports/testing.ts +5 -0
  65. package/dist/app-config-Cbv_lA38-BHJsd1DF.d.mts.map +0 -1
  66. package/dist/bin.mjs +0 -3283
  67. package/dist/bin.mjs.map +0 -1
  68. package/dist/config-whuqZ5xT.d.mts +0 -1
  69. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs +0 -313
  70. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs.map +0 -1
  71. package/dist/deploy-whuqZ5xT.d.mts +0 -1
  72. package/dist/graph-DDpXh7S8-b-93BcHn.d.mts.map +0 -1
  73. package/dist/graph-DgbALPDo-BEHF94BN.mjs.map +0 -1
  74. package/dist/graph-types-C3FOaaXm-C6_rGzfn.d.mts.map +0 -1
  75. package/dist/local-target.mjs.map +0 -1
@@ -0,0 +1,275 @@
1
+ import { t as CliStructuredError } from "./errors-0e8IVwzi.mjs";
2
+ import { t as containerEnv } from "./container-transport-DKmKg5JQ-DKWs0ubK.mjs";
3
+ import { n as ok, r as okVoid, s as toStructured, t as notOk } from "./result-CY_TB7bn.mjs";
4
+ import { n as readDeploymentSummary, t as DEPLOYMENT_RESULT_FILE_ENV } from "./deployment-summary-DswOl_9E-C03NJ98H.mjs";
5
+ import { n as spawnAlchemy, t as alchemyInvocation } from "./run-alchemy-D44OZlyB-gVq_0gf4.mjs";
6
+ import { n as runPipeline } from "./pipeline-AoW8zq4I-CUon5KZH.mjs";
7
+ import * as fs from "node:fs";
8
+ import * as path from "node:path";
9
+ import { spawnSync } from "node:child_process";
10
+ import { randomUUID } from "node:crypto";
11
+ //#region ../../0-framework/3-tooling/cli/dist/generate-stack-BL6htaQb.mjs
12
+ /** Pipeline step 6: writes a regenerated-every-run, independently runnable stack module at `.prisma-composer/alchemy.run.ts`. */
13
+ const GENERATED_DIR = ".prisma-composer";
14
+ const GENERATED_FILE = "alchemy.run.ts";
15
+ /** A relative import specifier from `.prisma-composer/alchemy.run.ts` to `target` (posix separators). */
16
+ function relativeImportSpecifier(generatedDir, target) {
17
+ const rel = path.relative(generatedDir, target).split(path.sep).join("/");
18
+ return rel.startsWith(".") ? rel : `./${rel}`;
19
+ }
20
+ function quote(value) {
21
+ return JSON.stringify(value);
22
+ }
23
+ function renderBundle(bundle) {
24
+ return `{ dir: ${quote(bundle.dir)}, entry: ${quote(bundle.entry)} }`;
25
+ }
26
+ function renderOptions(input) {
27
+ const lines = [];
28
+ lines.push(` name: ${quote(input.name)},`);
29
+ lines.push(" bundles: {");
30
+ for (const [id, bundle] of Object.entries(input.assembled.bundles)) lines.push(` ${quote(id)}: ${renderBundle(bundle)},`);
31
+ lines.push(" },");
32
+ lines.push(" report: deploymentReport,");
33
+ return lines.join("\n");
34
+ }
35
+ /** Renders the stack module's source (tests assert on it without touching disk) — uses `//` headers, not a block comment, since a cwd path with a star-slash could close one early. */
36
+ function renderStackFile(input) {
37
+ const generatedDir = path.join(input.cwd, GENERATED_DIR);
38
+ const appImport = relativeImportSpecifier(generatedDir, input.entryPath);
39
+ const configImport = relativeImportSpecifier(generatedDir, input.configPath);
40
+ return `// Generated by \`prisma-composer deploy\`/\`prisma-composer destroy\` — overwritten on every
41
+ // run; do not edit by hand. Independently runnable from ${quote(input.cwd)}:
42
+ //
43
+ // alchemy deploy ${GENERATED_DIR}/${GENERATED_FILE}
44
+ //
45
+ // bisects a CLI bug from an Alchemy bug (deploy-cli.md § Implementation decisions).
46
+ import { lower } from '@prisma/composer/deploy';
47
+ import { deploymentReport } from '@prisma/composer/report';
48
+ import config from ${quote(configImport)};
49
+ import app from ${quote(appImport)};
50
+
51
+ export default lower(app, config, {
52
+ ${renderOptions(input)}
53
+ });
54
+ `;
55
+ }
56
+ /** Writes the stack file, returning its absolute path. */
57
+ function writeStackFile(input) {
58
+ const generatedDir = path.join(input.cwd, GENERATED_DIR);
59
+ fs.mkdirSync(generatedDir, { recursive: true });
60
+ const filePath = path.join(generatedDir, GENERATED_FILE);
61
+ fs.writeFileSync(filePath, renderStackFile(input));
62
+ return filePath;
63
+ }
64
+ const GENERATED_STACK_RELATIVE_PATH = path.join(GENERATED_DIR, GENERATED_FILE);
65
+ //#endregion
66
+ //#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-DfVJUICu.mjs
67
+ /** A stage name must be a valid git ref (deploy-cli.md) — checked via `git check-ref-format`, never silently normalized. Runs before anything platform-specific. */
68
+ function validateStageName(stage) {
69
+ const result = spawnSync("git", ["check-ref-format", `refs/heads/${stage}`], { stdio: "ignore" });
70
+ if (result.error) throw new CliStructuredError("DEPLOY.STAGE_UNVALIDATABLE", `git is required to validate --stage "${stage}" (git check-ref-format): ${result.error.message}.`, { cause: result.error });
71
+ if (result.status !== 0) throw new CliStructuredError("DEPLOY.STAGE_INVALID", `Invalid --stage "${stage}": must be a valid git ref name (git check-ref-format rejected "refs/heads/${stage}").`);
72
+ }
73
+ /**
74
+ * The deploy/destroy executor — main.ts's pipeline orchestration with argv,
75
+ * console, and exit codes removed: typed inputs in, structured results out.
76
+ * Reached only by lazy import from deploy.ts/destroy.ts — this module's
77
+ * static graph transitively loads alchemy's provider tree, so the control
78
+ * entry must never import it statically.
79
+ */
80
+ const ALCHEMY_STATE_DIR = ".alchemy";
81
+ /** Destroy guardrail (moved from main.ts): true when `<cwd>/.alchemy` is missing or empty — likely wrong directory or nothing deployed yet. */
82
+ function hasNoLocalDeployState(cwd) {
83
+ const stateDir = path.join(cwd, ALCHEMY_STATE_DIR);
84
+ return !(fs.existsSync(stateDir) && fs.readdirSync(stateDir).length > 0);
85
+ }
86
+ async function executeDeploy(input, deps, cwd) {
87
+ const outcome = await runStackPipeline("deploy", {
88
+ entry: input.entry,
89
+ name: input.name,
90
+ stage: input.stage,
91
+ cwd,
92
+ onEvent: void 0,
93
+ deps
94
+ });
95
+ if (!outcome.ok) return outcome;
96
+ return ok({ summary: outcome.value });
97
+ }
98
+ async function executeDestroy(input, deps, cwd) {
99
+ const outcome = await runStackPipeline("destroy", {
100
+ entry: input.entry,
101
+ name: input.name,
102
+ stage: input.target.kind === "stage" ? input.target.stage : void 0,
103
+ cwd,
104
+ onEvent: input.onEvent,
105
+ deps
106
+ });
107
+ if (!outcome.ok) return outcome;
108
+ return okVoid();
109
+ }
110
+ /** The pipeline both actions share: validate, resolve containers, preflight,
111
+ * write the stack file, run alchemy against it, then the destroy-only
112
+ * teardown/removal suffix. The value is only ever a summary for deploy. */
113
+ async function runStackPipeline(action, opts) {
114
+ const { entry, name, stage, cwd, onEvent, deps } = opts;
115
+ if (stage !== void 0) try {
116
+ validateStageName(stage);
117
+ } catch (error) {
118
+ if (CliStructuredError.is(error)) return notOk(error);
119
+ throw error;
120
+ }
121
+ if (action === "destroy" && hasNoLocalDeployState(cwd)) onEvent?.({
122
+ kind: "no-local-deploy-state",
123
+ cwd
124
+ });
125
+ let pipeline;
126
+ let containers;
127
+ let alchemyStage;
128
+ try {
129
+ pipeline = await runPipeline(entry, name, cwd, {
130
+ runAssembler: deps.runAssembler,
131
+ config: deps.config,
132
+ configPath: deps.configPath
133
+ }, action === "destroy" ? (error) => new CliStructuredError("DEPLOY.BUILD_REQUIRED", error.message, {
134
+ why: "destroy evaluates the same stack program as deploy, which packages the built artifacts — so the app must be built first.",
135
+ fix: "Run the build, then retry the destroy.",
136
+ cause: error
137
+ }) : void 0);
138
+ const { config, graph, name: resolvedName } = pipeline;
139
+ containers = /* @__PURE__ */ new Map();
140
+ for (const extension of config.extensions) {
141
+ if (extension.container === void 0) continue;
142
+ try {
143
+ if (action === "deploy") containers.set(extension.id, await extension.container.ensure({
144
+ appName: resolvedName,
145
+ stage
146
+ }, deps.credentials));
147
+ else {
148
+ const instance = await extension.container.locate({
149
+ appName: resolvedName,
150
+ stage
151
+ }, deps.credentials);
152
+ if (instance === void 0) throw new CliStructuredError("DEPLOY.TARGET_NOT_FOUND", `Nothing deployed for ${resolvedName}${stage !== void 0 ? `/${stage}` : ""}.`, { fix: "Deploy it first." });
153
+ containers.set(extension.id, instance);
154
+ }
155
+ } catch (error) {
156
+ throw toStructured("DEPLOY.CONTAINER_FAILED", error);
157
+ }
158
+ }
159
+ const pinnedStage = containers.get(config.state.extension)?.alchemyStage ?? stage;
160
+ if (pinnedStage === void 0) throw new CliStructuredError("DEPLOY.SCOPE_MISSING", "The configured deploy target supplied no deploy scope (its container defines no alchemyStage), so Alchemy has no stage to run under.", { fix: action === "deploy" ? "Pass --stage <name> to choose the deploy scope explicitly." : "destroy --production needs a target whose container supplies the production deploy scope." });
161
+ alchemyStage = pinnedStage;
162
+ if (action === "deploy") for (const extension of config.extensions) {
163
+ if (extension.preflight === void 0) continue;
164
+ try {
165
+ await extension.preflight({
166
+ graph,
167
+ container: containers.get(extension.id),
168
+ stage,
169
+ credentials: deps.credentials
170
+ });
171
+ } catch (error) {
172
+ throw toStructured("DEPLOY.PREFLIGHT_FAILED", error);
173
+ }
174
+ }
175
+ } catch (error) {
176
+ if (CliStructuredError.is(error)) return notOk(error);
177
+ throw error;
178
+ }
179
+ let stackPath;
180
+ const resultFilePath = path.join(cwd, ".prisma-composer", `deployment-result-${String(process.pid)}-${randomUUID()}.json`);
181
+ try {
182
+ try {
183
+ stackPath = writeStackFile({
184
+ entryPath: pipeline.entryModule.path,
185
+ cwd,
186
+ configPath: pipeline.configPath,
187
+ name: pipeline.name,
188
+ assembled: pipeline.assembled
189
+ });
190
+ } catch (error) {
191
+ return notOk(toStructured("DEPLOY.STACK_WRITE_FAILED", error));
192
+ }
193
+ const reproduceCommand = `alchemy ${action} ${GENERATED_STACK_RELATIVE_PATH} --yes --stage ${alchemyStage}`;
194
+ let outcome;
195
+ try {
196
+ outcome = await (deps.alchemy ?? spawnAlchemy)(alchemyInvocation({
197
+ command: action,
198
+ stackFileRelativePath: GENERATED_STACK_RELATIVE_PATH,
199
+ cwd,
200
+ stage: alchemyStage,
201
+ containerEnv: containerEnv(containers),
202
+ env: { [DEPLOYMENT_RESULT_FILE_ENV]: resultFilePath }
203
+ }));
204
+ } catch (error) {
205
+ if (CliStructuredError.is(error)) return notOk(error);
206
+ return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", error instanceof Error ? error.message : String(error), {
207
+ cause: error,
208
+ meta: { diagnostics: {
209
+ exitCode: void 0,
210
+ stackFilePath: stackPath,
211
+ reproduceCommand,
212
+ cwd
213
+ } }
214
+ }));
215
+ }
216
+ if (outcome.signal !== null) return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", `alchemy ${action} was interrupted by ${outcome.signal}.`, { meta: {
217
+ signal: outcome.signal,
218
+ diagnostics: {
219
+ exitCode: void 0,
220
+ signal: outcome.signal,
221
+ stackFilePath: stackPath,
222
+ reproduceCommand,
223
+ cwd
224
+ }
225
+ } }));
226
+ const status = outcome.exitCode ?? 1;
227
+ if (status !== 0) return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", `alchemy ${action} exited with status ${status}.`, { meta: {
228
+ exitCode: status,
229
+ diagnostics: {
230
+ exitCode: status,
231
+ stackFilePath: stackPath,
232
+ reproduceCommand,
233
+ cwd
234
+ }
235
+ } }));
236
+ try {
237
+ if (action === "destroy") {
238
+ for (const extension of pipeline.config.extensions) {
239
+ if (extension.teardown === void 0) continue;
240
+ try {
241
+ await extension.teardown({
242
+ container: containers.get(extension.id),
243
+ stage
244
+ });
245
+ } catch (error) {
246
+ throw toStructured("DEPLOY.TEARDOWN_FAILED", error);
247
+ }
248
+ }
249
+ for (const extension of pipeline.config.extensions) {
250
+ if (extension.container === void 0) continue;
251
+ const instance = containers.get(extension.id);
252
+ if (instance === void 0) continue;
253
+ try {
254
+ await extension.container.remove(instance, deps.credentials);
255
+ } catch (error) {
256
+ throw toStructured("DEPLOY.CONTAINER_REMOVE_FAILED", error);
257
+ }
258
+ }
259
+ }
260
+ } catch (error) {
261
+ if (CliStructuredError.is(error)) return notOk(error);
262
+ throw error;
263
+ }
264
+ if (action === "deploy") return ok(readDeploymentSummary(resultFilePath));
265
+ return ok(void 0);
266
+ } finally {
267
+ try {
268
+ fs.rmSync(resultFilePath, { force: true });
269
+ } catch {}
270
+ }
271
+ }
272
+ //#endregion
273
+ export { executeDeploy, executeDestroy };
274
+
275
+ //# sourceMappingURL=execute-deploy-destroy-DfVJUICu-Dbgn1GR_.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-deploy-destroy-DfVJUICu-Dbgn1GR_.mjs","names":[],"sources":["../../../0-framework/3-tooling/cli/dist/generate-stack-BL6htaQb.mjs","../../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-DfVJUICu.mjs"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n//#region src/generate-stack.ts\n/** Pipeline step 6: writes a regenerated-every-run, independently runnable stack module at `.prisma-composer/alchemy.run.ts`. */\nconst GENERATED_DIR = \".prisma-composer\";\nconst GENERATED_FILE = \"alchemy.run.ts\";\n/** A relative import specifier from `.prisma-composer/alchemy.run.ts` to `target` (posix separators). */\nfunction relativeImportSpecifier(generatedDir, target) {\n\tconst rel = path.relative(generatedDir, target).split(path.sep).join(\"/\");\n\treturn rel.startsWith(\".\") ? rel : `./${rel}`;\n}\nfunction quote(value) {\n\treturn JSON.stringify(value);\n}\nfunction renderBundle(bundle) {\n\treturn `{ dir: ${quote(bundle.dir)}, entry: ${quote(bundle.entry)} }`;\n}\nfunction renderOptions(input) {\n\tconst lines = [];\n\tlines.push(` name: ${quote(input.name)},`);\n\tlines.push(\" bundles: {\");\n\tfor (const [id, bundle] of Object.entries(input.assembled.bundles)) lines.push(` ${quote(id)}: ${renderBundle(bundle)},`);\n\tlines.push(\" },\");\n\tlines.push(\" report: deploymentReport,\");\n\treturn lines.join(\"\\n\");\n}\n/** Renders the stack module's source (tests assert on it without touching disk) — uses `//` headers, not a block comment, since a cwd path with a star-slash could close one early. */\nfunction renderStackFile(input) {\n\tconst generatedDir = path.join(input.cwd, GENERATED_DIR);\n\tconst appImport = relativeImportSpecifier(generatedDir, input.entryPath);\n\tconst configImport = relativeImportSpecifier(generatedDir, input.configPath);\n\treturn `// Generated by \\`prisma-composer deploy\\`/\\`prisma-composer destroy\\` — overwritten on every\n// run; do not edit by hand. Independently runnable from ${quote(input.cwd)}:\n//\n// alchemy deploy ${GENERATED_DIR}/${GENERATED_FILE}\n//\n// bisects a CLI bug from an Alchemy bug (deploy-cli.md § Implementation decisions).\nimport { lower } from '@prisma/composer/deploy';\nimport { deploymentReport } from '@prisma/composer/report';\nimport config from ${quote(configImport)};\nimport app from ${quote(appImport)};\n\nexport default lower(app, config, {\n${renderOptions(input)}\n});\n`;\n}\n/** Writes the stack file, returning its absolute path. */\nfunction writeStackFile(input) {\n\tconst generatedDir = path.join(input.cwd, GENERATED_DIR);\n\tfs.mkdirSync(generatedDir, { recursive: true });\n\tconst filePath = path.join(generatedDir, GENERATED_FILE);\n\tfs.writeFileSync(filePath, renderStackFile(input));\n\treturn filePath;\n}\nconst GENERATED_STACK_RELATIVE_PATH = path.join(GENERATED_DIR, GENERATED_FILE);\n//#endregion\nexport { renderStackFile as n, writeStackFile as r, GENERATED_STACK_RELATIVE_PATH as t };\n\n//# sourceMappingURL=generate-stack-BL6htaQb.mjs.map","import { r as toStructured } from \"./shared-BTnATsqm.mjs\";\nimport { i as spawnAlchemy, n as alchemyInvocation } from \"./run-alchemy-D44OZlyB.mjs\";\nimport { r as writeStackFile, t as GENERATED_STACK_RELATIVE_PATH } from \"./generate-stack-BL6htaQb.mjs\";\nimport { n as readDeploymentSummary, t as DEPLOYMENT_RESULT_FILE_ENV } from \"./deployment-summary-DswOl_9E.mjs\";\nimport { n as runPipeline } from \"./pipeline-AoW8zq4I.mjs\";\nimport { CliStructuredError } from \"@internal/foundation/errors\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { notOk, ok, okVoid } from \"@internal/foundation/result\";\nimport { spawnSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { containerEnv } from \"@internal/core/config\";\n//#region src/validate-stage.ts\n/** A stage name must be a valid git ref (deploy-cli.md) — checked via `git check-ref-format`, never silently normalized. Runs before anything platform-specific. */\nfunction validateStageName(stage) {\n\tconst result = spawnSync(\"git\", [\"check-ref-format\", `refs/heads/${stage}`], { stdio: \"ignore\" });\n\tif (result.error) throw new CliStructuredError(\"DEPLOY.STAGE_UNVALIDATABLE\", `git is required to validate --stage \"${stage}\" (git check-ref-format): ${result.error.message}.`, { cause: result.error });\n\tif (result.status !== 0) throw new CliStructuredError(\"DEPLOY.STAGE_INVALID\", `Invalid --stage \"${stage}\": must be a valid git ref name (git check-ref-format rejected \"refs/heads/${stage}\").`);\n}\n//#endregion\n//#region src/operations/execute-deploy-destroy.ts\n/**\n* The deploy/destroy executor — main.ts's pipeline orchestration with argv,\n* console, and exit codes removed: typed inputs in, structured results out.\n* Reached only by lazy import from deploy.ts/destroy.ts — this module's\n* static graph transitively loads alchemy's provider tree, so the control\n* entry must never import it statically.\n*/\nconst ALCHEMY_STATE_DIR = \".alchemy\";\n/** Destroy guardrail (moved from main.ts): true when `<cwd>/.alchemy` is missing or empty — likely wrong directory or nothing deployed yet. */\nfunction hasNoLocalDeployState(cwd) {\n\tconst stateDir = path.join(cwd, ALCHEMY_STATE_DIR);\n\treturn !(fs.existsSync(stateDir) && fs.readdirSync(stateDir).length > 0);\n}\nasync function executeDeploy(input, deps, cwd) {\n\tconst outcome = await runStackPipeline(\"deploy\", {\n\t\tentry: input.entry,\n\t\tname: input.name,\n\t\tstage: input.stage,\n\t\tcwd,\n\t\tonEvent: void 0,\n\t\tdeps\n\t});\n\tif (!outcome.ok) return outcome;\n\treturn ok({ summary: outcome.value });\n}\nasync function executeDestroy(input, deps, cwd) {\n\tconst outcome = await runStackPipeline(\"destroy\", {\n\t\tentry: input.entry,\n\t\tname: input.name,\n\t\tstage: input.target.kind === \"stage\" ? input.target.stage : void 0,\n\t\tcwd,\n\t\tonEvent: input.onEvent,\n\t\tdeps\n\t});\n\tif (!outcome.ok) return outcome;\n\treturn okVoid();\n}\n/** The pipeline both actions share: validate, resolve containers, preflight,\n* write the stack file, run alchemy against it, then the destroy-only\n* teardown/removal suffix. The value is only ever a summary for deploy. */\nasync function runStackPipeline(action, opts) {\n\tconst { entry, name, stage, cwd, onEvent, deps } = opts;\n\tif (stage !== void 0) try {\n\t\tvalidateStageName(stage);\n\t} catch (error) {\n\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\tthrow error;\n\t}\n\tif (action === \"destroy\" && hasNoLocalDeployState(cwd)) onEvent?.({\n\t\tkind: \"no-local-deploy-state\",\n\t\tcwd\n\t});\n\tlet pipeline;\n\tlet containers;\n\tlet alchemyStage;\n\ttry {\n\t\tpipeline = await runPipeline(entry, name, cwd, {\n\t\t\trunAssembler: deps.runAssembler,\n\t\t\tconfig: deps.config,\n\t\t\tconfigPath: deps.configPath\n\t\t}, action === \"destroy\" ? (error) => new CliStructuredError(\"DEPLOY.BUILD_REQUIRED\", error.message, {\n\t\t\twhy: \"destroy evaluates the same stack program as deploy, which packages the built artifacts — so the app must be built first.\",\n\t\t\tfix: \"Run the build, then retry the destroy.\",\n\t\t\tcause: error\n\t\t}) : void 0);\n\t\tconst { config, graph, name: resolvedName } = pipeline;\n\t\tcontainers = /* @__PURE__ */ new Map();\n\t\tfor (const extension of config.extensions) {\n\t\t\tif (extension.container === void 0) continue;\n\t\t\ttry {\n\t\t\t\tif (action === \"deploy\") containers.set(extension.id, await extension.container.ensure({\n\t\t\t\t\tappName: resolvedName,\n\t\t\t\t\tstage\n\t\t\t\t}, deps.credentials));\n\t\t\t\telse {\n\t\t\t\t\tconst instance = await extension.container.locate({\n\t\t\t\t\t\tappName: resolvedName,\n\t\t\t\t\t\tstage\n\t\t\t\t\t}, deps.credentials);\n\t\t\t\t\tif (instance === void 0) throw new CliStructuredError(\"DEPLOY.TARGET_NOT_FOUND\", `Nothing deployed for ${resolvedName}${stage !== void 0 ? `/${stage}` : \"\"}.`, { fix: \"Deploy it first.\" });\n\t\t\t\t\tcontainers.set(extension.id, instance);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow toStructured(\"DEPLOY.CONTAINER_FAILED\", error);\n\t\t\t}\n\t\t}\n\t\tconst pinnedStage = containers.get(config.state.extension)?.alchemyStage ?? stage;\n\t\tif (pinnedStage === void 0) throw new CliStructuredError(\"DEPLOY.SCOPE_MISSING\", \"The configured deploy target supplied no deploy scope (its container defines no alchemyStage), so Alchemy has no stage to run under.\", { fix: action === \"deploy\" ? \"Pass --stage <name> to choose the deploy scope explicitly.\" : \"destroy --production needs a target whose container supplies the production deploy scope.\" });\n\t\talchemyStage = pinnedStage;\n\t\tif (action === \"deploy\") for (const extension of config.extensions) {\n\t\t\tif (extension.preflight === void 0) continue;\n\t\t\ttry {\n\t\t\t\tawait extension.preflight({\n\t\t\t\t\tgraph,\n\t\t\t\t\tcontainer: containers.get(extension.id),\n\t\t\t\t\tstage,\n\t\t\t\t\tcredentials: deps.credentials\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow toStructured(\"DEPLOY.PREFLIGHT_FAILED\", error);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\tthrow error;\n\t}\n\tlet stackPath;\n\tconst resultFilePath = path.join(cwd, \".prisma-composer\", `deployment-result-${String(process.pid)}-${randomUUID()}.json`);\n\ttry {\n\t\ttry {\n\t\t\tstackPath = writeStackFile({\n\t\t\t\tentryPath: pipeline.entryModule.path,\n\t\t\t\tcwd,\n\t\t\t\tconfigPath: pipeline.configPath,\n\t\t\t\tname: pipeline.name,\n\t\t\t\tassembled: pipeline.assembled\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn notOk(toStructured(\"DEPLOY.STACK_WRITE_FAILED\", error));\n\t\t}\n\t\tconst reproduceCommand = `alchemy ${action} ${GENERATED_STACK_RELATIVE_PATH} --yes --stage ${alchemyStage}`;\n\t\tlet outcome;\n\t\ttry {\n\t\t\toutcome = await (deps.alchemy ?? spawnAlchemy)(alchemyInvocation({\n\t\t\t\tcommand: action,\n\t\t\t\tstackFileRelativePath: GENERATED_STACK_RELATIVE_PATH,\n\t\t\t\tcwd,\n\t\t\t\tstage: alchemyStage,\n\t\t\t\tcontainerEnv: containerEnv(containers),\n\t\t\t\tenv: { [DEPLOYMENT_RESULT_FILE_ENV]: resultFilePath }\n\t\t\t}));\n\t\t} catch (error) {\n\t\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\t\treturn notOk(new CliStructuredError(\"DEPLOY.ENGINE_FAILED\", error instanceof Error ? error.message : String(error), {\n\t\t\t\tcause: error,\n\t\t\t\tmeta: { diagnostics: {\n\t\t\t\t\texitCode: void 0,\n\t\t\t\t\tstackFilePath: stackPath,\n\t\t\t\t\treproduceCommand,\n\t\t\t\t\tcwd\n\t\t\t\t} }\n\t\t\t}));\n\t\t}\n\t\tif (outcome.signal !== null) return notOk(new CliStructuredError(\"DEPLOY.ENGINE_FAILED\", `alchemy ${action} was interrupted by ${outcome.signal}.`, { meta: {\n\t\t\tsignal: outcome.signal,\n\t\t\tdiagnostics: {\n\t\t\t\texitCode: void 0,\n\t\t\t\tsignal: outcome.signal,\n\t\t\t\tstackFilePath: stackPath,\n\t\t\t\treproduceCommand,\n\t\t\t\tcwd\n\t\t\t}\n\t\t} }));\n\t\tconst status = outcome.exitCode ?? 1;\n\t\tif (status !== 0) return notOk(new CliStructuredError(\"DEPLOY.ENGINE_FAILED\", `alchemy ${action} exited with status ${status}.`, { meta: {\n\t\t\texitCode: status,\n\t\t\tdiagnostics: {\n\t\t\t\texitCode: status,\n\t\t\t\tstackFilePath: stackPath,\n\t\t\t\treproduceCommand,\n\t\t\t\tcwd\n\t\t\t}\n\t\t} }));\n\t\ttry {\n\t\t\tif (action === \"destroy\") {\n\t\t\t\tfor (const extension of pipeline.config.extensions) {\n\t\t\t\t\tif (extension.teardown === void 0) continue;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait extension.teardown({\n\t\t\t\t\t\t\tcontainer: containers.get(extension.id),\n\t\t\t\t\t\t\tstage\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow toStructured(\"DEPLOY.TEARDOWN_FAILED\", error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const extension of pipeline.config.extensions) {\n\t\t\t\t\tif (extension.container === void 0) continue;\n\t\t\t\t\tconst instance = containers.get(extension.id);\n\t\t\t\t\tif (instance === void 0) continue;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait extension.container.remove(instance, deps.credentials);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow toStructured(\"DEPLOY.CONTAINER_REMOVE_FAILED\", error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\t\tthrow error;\n\t\t}\n\t\tif (action === \"deploy\") return ok(readDeploymentSummary(resultFilePath));\n\t\treturn ok(void 0);\n\t} finally {\n\t\ttry {\n\t\t\tfs.rmSync(resultFilePath, { force: true });\n\t\t} catch {}\n\t}\n}\n//#endregion\nexport { executeDeploy, executeDestroy };\n\n//# sourceMappingURL=execute-deploy-destroy-DfVJUICu.mjs.map"],"mappings":";;;;;;;;;;;;AAIA,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;;AAEvB,SAAS,wBAAwB,cAAc,QAAQ;CACtD,MAAM,MAAM,KAAK,SAAS,cAAc,MAAM,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;CACxE,OAAO,IAAI,WAAW,GAAG,IAAI,M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