@prisma/composer-cli 0.36.0-dev.3 → 0.36.0-dev.4
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.
- package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs +590 -0
- package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs.map +1 -0
- package/dist/{dev-current-BNoPkDRU-DGd_7FDS.mjs → dev-current-BurA9uhA-BWYAftn9.mjs} +6 -6
- package/dist/{dev-current-BNoPkDRU-DGd_7FDS.mjs.map → dev-current-BurA9uhA-BWYAftn9.mjs.map} +1 -1
- package/dist/{dev-environment-name-6eEr5PW8-lIZmJjfr.mjs → dev-environment-name-6eEr5PW8-YyPDRApO.mjs} +2 -2
- package/dist/dev-environment-name-6eEr5PW8-YyPDRApO.mjs.map +1 -0
- package/dist/{dist-B9-nLeho.mjs → dist-BsONwZNR.mjs} +3 -6
- package/dist/{dist-B9-nLeho.mjs.map → dist-BsONwZNR.mjs.map} +1 -1
- package/dist/{execute-deploy-destroy-BIqwt1RF-D3F6yxLV.mjs → execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs} +50 -11
- package/dist/execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs.map +1 -0
- package/dist/{execute-dev-DIEyloWn-CjtRM3-x.mjs → execute-dev-4KYkqSMh-uh7gnPyS.mjs} +33 -17
- package/dist/{execute-dev-DIEyloWn-CjtRM3-x.mjs.map → execute-dev-4KYkqSMh-uh7gnPyS.mjs.map} +1 -1
- package/dist/{execute-dev-current-CeKI-tiC-fd62IW2Y.mjs → execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs} +6 -6
- package/dist/{execute-dev-current-CeKI-tiC-fd62IW2Y.mjs.map → execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs.map} +1 -1
- package/dist/{family-Dy3ZQOxG-CcELNRXg.d.mts → family-DACJfaA5-CBuEC2B3.d.mts} +103 -61
- package/dist/family-DACJfaA5-CBuEC2B3.d.mts.map +1 -0
- package/dist/family.d.mts +1 -1
- package/dist/family.mjs +12 -4
- package/dist/family.mjs.map +1 -1
- package/dist/{generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs → generate-dev-stack-DS6U_JHX-wDTViqdg.mjs} +9 -4
- package/dist/generate-dev-stack-DS6U_JHX-wDTViqdg.mjs.map +1 -0
- package/dist/{list-deployed-2Xs64YAh.mjs → list-deployed-CH3SMsQ4.mjs} +4 -4
- package/dist/{list-deployed-2Xs64YAh.mjs.map → list-deployed-CH3SMsQ4.mjs.map} +1 -1
- package/dist/result-sR7PBi61.mjs +229 -0
- package/dist/result-sR7PBi61.mjs.map +1 -0
- package/dist/run-alchemy-B-Z6i3cD-f0MXFCG8.mjs +219 -0
- package/dist/run-alchemy-B-Z6i3cD-f0MXFCG8.mjs.map +1 -0
- package/dist/testing.d.mts +1 -1
- package/dist/testing.mjs +3 -2
- package/dist/testing.mjs.map +1 -1
- package/dist/{validate-environment-CEhUSEg2-BohWFcgr.mjs → validate-environment-BNZC6W46-DY_7cPQJ.mjs} +449 -342
- package/dist/validate-environment-BNZC6W46-DY_7cPQJ.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/dev-environment-name-6eEr5PW8-lIZmJjfr.mjs.map +0 -1
- package/dist/execute-deploy-destroy-BIqwt1RF-D3F6yxLV.mjs.map +0 -1
- package/dist/family-Dy3ZQOxG-CcELNRXg.d.mts.map +0 -1
- package/dist/generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs.map +0 -1
- package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs +0 -667
- package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map +0 -1
- package/dist/validate-environment-CEhUSEg2-BohWFcgr.mjs.map +0 -1
|
@@ -1,667 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import spawn from "cross-spawn";
|
|
5
|
-
//#region ../../0-framework/3-tooling/cli/dist/composer-config-ehUUVHtU.mjs
|
|
6
|
-
/**
|
|
7
|
-
* What makes a `composer` section valid, shared by the CLI's section validator and the programmatic operations.
|
|
8
|
-
* It imports nothing from the CLI engine, because `@prisma/composer` must not depend on it.
|
|
9
|
-
*/
|
|
10
|
-
const SECTION_FIX = "Write `composer: composer({ entry: './module.ts', extensions: [...], state: ... })` in prisma.config.ts, with `import { defineConfig as composer } from '@prisma/composer/config'`.";
|
|
11
|
-
const MOVE_TO_SECTION_FIX = `${SECTION_FIX} If the project has a prisma-composer.config.ts, move its extensions and state into that section and delete the file.`;
|
|
12
|
-
const SECTION_IS_THE_ONLY_SOURCE = "Composer reads its configuration only from the `composer` section of prisma.config.ts.";
|
|
13
|
-
const DESCRIPTOR_FIX = "Use the descriptor the extension factory returns, unchanged, instead of building one by hand.";
|
|
14
|
-
const RETIRED_FILE_NAMES = [
|
|
15
|
-
"ts",
|
|
16
|
-
"mts",
|
|
17
|
-
"mjs",
|
|
18
|
-
"js"
|
|
19
|
-
].map((extension) => `prisma-composer.config.${extension}`);
|
|
20
|
-
const sectionMissing = {
|
|
21
|
-
code: "CONFIG.SECTION_MISSING",
|
|
22
|
-
summary: "No loaded prisma.config.ts declares a `composer` section.",
|
|
23
|
-
why: `${SECTION_IS_THE_ONLY_SOURCE} A prisma-composer.config.ts file is no longer read.`,
|
|
24
|
-
fix: MOVE_TO_SECTION_FIX
|
|
25
|
-
};
|
|
26
|
-
/** What the generated stack file throws when the file it imports has no `composer` export. */
|
|
27
|
-
function noComposerExportMessage(configFile) {
|
|
28
|
-
return `${configFile} declares no \`composer\` section. Pass the prisma.config.ts that declares it.`;
|
|
29
|
-
}
|
|
30
|
-
function configFileMissing(file) {
|
|
31
|
-
return {
|
|
32
|
-
code: "CONFIG.FILE_MISSING",
|
|
33
|
-
summary: `${file} does not exist.`,
|
|
34
|
-
fix: "Pass the path of the prisma.config.ts that declares the `composer` section.",
|
|
35
|
-
where: file
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/** A prisma-composer.config.* beside the declaring file would otherwise be silently ignored. */
|
|
39
|
-
/** The path with symlinks resolved; the path itself when it cannot be resolved, so the check never throws. */
|
|
40
|
-
function realPath(file) {
|
|
41
|
-
try {
|
|
42
|
-
return fs.realpathSync(file);
|
|
43
|
-
} catch {
|
|
44
|
-
return file;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function retiredFileFinding(configFile) {
|
|
48
|
-
const directory = path.dirname(realPath(configFile));
|
|
49
|
-
const found = RETIRED_FILE_NAMES.map((name) => path.join(directory, name)).find((file) => fs.existsSync(file));
|
|
50
|
-
if (found === void 0) return void 0;
|
|
51
|
-
return {
|
|
52
|
-
code: "CONFIG.FILE_RETIRED",
|
|
53
|
-
summary: `${found} is no longer read.`,
|
|
54
|
-
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
55
|
-
fix: MOVE_TO_SECTION_FIX,
|
|
56
|
-
where: found
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function isObject(value) {
|
|
60
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
|
-
}
|
|
62
|
-
function isExtensionDescriptor(value) {
|
|
63
|
-
return isObject(value) && typeof value["id"] === "string" && value["id"].length > 0 && isObject(value["nodes"]);
|
|
64
|
-
}
|
|
65
|
-
function isStateDescriptor(value) {
|
|
66
|
-
return isObject(value) && typeof value["extension"] === "string" && typeof value["create"] === "function";
|
|
67
|
-
}
|
|
68
|
-
const stateInvalid = {
|
|
69
|
-
code: "CONFIG.FIELD_INVALID",
|
|
70
|
-
summary: "`composer.state` must be a state descriptor with a string `extension` and a `create` function.",
|
|
71
|
-
fix: "Set `state` to the state descriptor an extension provides, e.g. `state: prismaState()`.",
|
|
72
|
-
field: "state"
|
|
73
|
-
};
|
|
74
|
-
const SECTION_FIELDS = /* @__PURE__ */ new Set([
|
|
75
|
-
"entry",
|
|
76
|
-
"extensions",
|
|
77
|
-
"state"
|
|
78
|
-
]);
|
|
79
|
-
const entryInvalid = {
|
|
80
|
-
code: "CONFIG.FIELD_INVALID",
|
|
81
|
-
summary: "`composer.entry` must be a non-empty string: the path to the module whose default export is the app.",
|
|
82
|
-
fix: "Set `entry` to that module's path, relative to prisma.config.ts, e.g. `entry: './module.ts'`.",
|
|
83
|
-
field: "entry"
|
|
84
|
-
};
|
|
85
|
-
/** Neither the section's `entry` nor an override names the module whose default export is the app. */
|
|
86
|
-
const entryMissing = {
|
|
87
|
-
code: "CONFIG.ENTRY_MISSING",
|
|
88
|
-
summary: "No entry module is set, so there is no app to load.",
|
|
89
|
-
why: "The entry is the module whose default export is the app root, built with module(...).",
|
|
90
|
-
fix: "Set `entry: './module.ts'` in the `composer` section of prisma.config.ts, or pass `--entry <path>` (the `entry` input when calling @prisma/composer/control).",
|
|
91
|
-
field: "entry"
|
|
92
|
-
};
|
|
93
|
-
function unknownField(key) {
|
|
94
|
-
return {
|
|
95
|
-
code: "CONFIG.FIELD_UNKNOWN",
|
|
96
|
-
summary: `The \`composer\` section has no field \`${key}\`.`,
|
|
97
|
-
fix: key === "composer" ? "Pass the `composer` property of the prisma.config.ts export, not the whole export. The section takes only `entry`, `extensions` and `state`." : `Remove \`${key}\`. The section takes only \`entry\`, \`extensions\` and \`state\`.`,
|
|
98
|
-
field: key
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function checkExtensions(value) {
|
|
102
|
-
if (!Array.isArray(value)) return {
|
|
103
|
-
extensions: [],
|
|
104
|
-
findings: [{
|
|
105
|
-
code: "CONFIG.FIELD_INVALID",
|
|
106
|
-
summary: "`composer.extensions` must be an array of extension descriptors.",
|
|
107
|
-
fix: "Set `extensions` to the descriptors your extensions provide, e.g. `extensions: [nodeBuild()]`.",
|
|
108
|
-
field: "extensions"
|
|
109
|
-
}]
|
|
110
|
-
};
|
|
111
|
-
const findings = [];
|
|
112
|
-
const extensions = [];
|
|
113
|
-
const seen = /* @__PURE__ */ new Set();
|
|
114
|
-
for (const [index, entry] of value.entries()) {
|
|
115
|
-
const field = `extensions[${index}]`;
|
|
116
|
-
if (!isObject(entry)) {
|
|
117
|
-
findings.push({
|
|
118
|
-
code: "CONFIG.FIELD_INVALID",
|
|
119
|
-
summary: `\`composer.${field}\` must be an extension descriptor object.`,
|
|
120
|
-
fix: "Put the descriptor an extension factory returns here, e.g. `nodeBuild()`, not the factory itself.",
|
|
121
|
-
field
|
|
122
|
-
});
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
const id = entry["id"];
|
|
126
|
-
if (typeof id !== "string" || id.length === 0) findings.push({
|
|
127
|
-
code: "CONFIG.FIELD_INVALID",
|
|
128
|
-
summary: `\`composer.${field}.id\` must be a non-empty string (the extension package name).`,
|
|
129
|
-
fix: DESCRIPTOR_FIX,
|
|
130
|
-
field: `${field}.id`
|
|
131
|
-
});
|
|
132
|
-
else if (seen.has(id)) findings.push({
|
|
133
|
-
code: "CONFIG.EXTENSION_DUPLICATE",
|
|
134
|
-
summary: `Extension "${id}" is listed more than once in \`composer.extensions\`.`,
|
|
135
|
-
fix: `Remove the repeated "${id}" entry from \`extensions\`.`,
|
|
136
|
-
field: `${field}.id`
|
|
137
|
-
});
|
|
138
|
-
else seen.add(id);
|
|
139
|
-
if (!isObject(entry["nodes"])) findings.push({
|
|
140
|
-
code: "CONFIG.FIELD_INVALID",
|
|
141
|
-
summary: `\`composer.${field}.nodes\` must be an object (the node-ID → control registry).`,
|
|
142
|
-
fix: DESCRIPTOR_FIX,
|
|
143
|
-
field: `${field}.nodes`
|
|
144
|
-
});
|
|
145
|
-
if (isExtensionDescriptor(entry)) extensions.push(entry);
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
findings,
|
|
149
|
-
extensions
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function checkFields(section) {
|
|
153
|
-
if (Object.hasOwn(section, "configPath")) return {
|
|
154
|
-
ok: false,
|
|
155
|
-
findings: [{
|
|
156
|
-
code: "CONFIG.FIELD_RETIRED",
|
|
157
|
-
summary: "`composer.configPath` is no longer supported: prisma-composer.config.ts is no longer read.",
|
|
158
|
-
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
159
|
-
fix: `Replace \`configPath\` with the section itself. ${MOVE_TO_SECTION_FIX}`,
|
|
160
|
-
field: "configPath"
|
|
161
|
-
}]
|
|
162
|
-
};
|
|
163
|
-
if (Object.hasOwn(section, "composer")) return {
|
|
164
|
-
ok: false,
|
|
165
|
-
findings: [unknownField("composer")]
|
|
166
|
-
};
|
|
167
|
-
const findings = Object.keys(section).filter((key) => !SECTION_FIELDS.has(key)).map(unknownField);
|
|
168
|
-
const checked = checkExtensions(section["extensions"]);
|
|
169
|
-
findings.push(...checked.findings);
|
|
170
|
-
const state = section["state"];
|
|
171
|
-
if (!isStateDescriptor(state)) findings.push(stateInvalid);
|
|
172
|
-
const entry = section["entry"];
|
|
173
|
-
const entryValid = entry === void 0 || typeof entry === "string" && entry.length > 0;
|
|
174
|
-
if (!entryValid) findings.push(entryInvalid);
|
|
175
|
-
const [first, ...rest] = findings;
|
|
176
|
-
if (first === void 0 && isStateDescriptor(state) && entryValid) return {
|
|
177
|
-
ok: true,
|
|
178
|
-
value: {
|
|
179
|
-
extensions: checked.extensions,
|
|
180
|
-
state,
|
|
181
|
-
...entry === void 0 ? {} : { entry }
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
return {
|
|
185
|
-
ok: false,
|
|
186
|
-
findings: [first ?? stateInvalid, ...rest]
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Checks the fields that identify each descriptor and returns the descriptors as the config file's own objects.
|
|
191
|
-
* Never throws: a section's values are user code, and a throwing getter or Proxy trap becomes a finding.
|
|
192
|
-
*/
|
|
193
|
-
function checkComposerSection(raw) {
|
|
194
|
-
if (!isObject(raw)) return {
|
|
195
|
-
ok: false,
|
|
196
|
-
findings: [{
|
|
197
|
-
code: "CONFIG.FIELD_INVALID",
|
|
198
|
-
summary: "The `composer` section of prisma.config.ts must be an object.",
|
|
199
|
-
fix: SECTION_FIX
|
|
200
|
-
}]
|
|
201
|
-
};
|
|
202
|
-
try {
|
|
203
|
-
return checkFields({ ...raw });
|
|
204
|
-
} catch (cause) {
|
|
205
|
-
return {
|
|
206
|
-
ok: false,
|
|
207
|
-
findings: [{
|
|
208
|
-
code: "CONFIG.FIELD_INVALID",
|
|
209
|
-
summary: "The `composer` section of prisma.config.ts could not be read.",
|
|
210
|
-
why: `Reading it threw: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
211
|
-
fix: SECTION_FIX
|
|
212
|
-
}]
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* The whole check, shared by the section validator and the programmatic operations so both report the same findings in the same order: the retired file beside the declaring `configFile` (resolved through symlinks), then every field finding.
|
|
218
|
-
*/
|
|
219
|
-
function checkComposerConfig(raw, configFile) {
|
|
220
|
-
const retired = retiredFileFinding(configFile);
|
|
221
|
-
const checked = checkComposerSection(raw);
|
|
222
|
-
if (retired === void 0) return checked;
|
|
223
|
-
return {
|
|
224
|
-
ok: false,
|
|
225
|
-
findings: checked.ok ? [retired] : [retired, ...checked.findings]
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region ../../0-framework/0-foundation/foundation/dist/casts-DpaahrlC.mjs
|
|
230
|
-
/**
|
|
231
|
-
* **Last-resort escape hatch for unsafe type assertions. Not a sanctioned tool to reach for.**
|
|
232
|
-
*
|
|
233
|
-
* Before reaching for `blindCast`, **rewrite the surrounding code so the cast becomes
|
|
234
|
-
* unnecessary**: tighten an input type, add a runtime check that narrows via a type
|
|
235
|
-
* predicate, restructure a generic so the compiler can see the relationship you're
|
|
236
|
-
* asserting, or use {@link castAs} when the value already satisfies the target type.
|
|
237
|
-
* Only when no rewrite is feasible does `blindCast` become the right answer — and at
|
|
238
|
-
* that point, the `Reason` literal you supply must articulate the compromise in
|
|
239
|
-
* language a reviewer can evaluate.
|
|
240
|
-
*
|
|
241
|
-
* The reviewer **will** validate the `Reason`. If it doesn't hold up under scrutiny,
|
|
242
|
-
* that is not a signal to soften the reason; it is a signal to go back and solve the
|
|
243
|
-
* underlying type-system problem properly. An unconvincing justification is rework,
|
|
244
|
-
* not a free pass.
|
|
245
|
-
*
|
|
246
|
-
* `blindCast` is the auditable form of `as Foo` / `as unknown as Foo`: it bypasses
|
|
247
|
-
* the compiler's checks (the input type is `unknown`, the output type is whatever the
|
|
248
|
-
* caller asks for), but it forces the unsafety to be named at the call site instead of
|
|
249
|
-
* smuggled in via a bare `as`. The `Reason` type parameter exists only at compile
|
|
250
|
-
* time — it is not present in the emitted JavaScript — but it is grep-able and
|
|
251
|
-
* visible to future readers.
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```typescript
|
|
255
|
-
* const stringValue = blindCast<
|
|
256
|
-
* string,
|
|
257
|
-
* "JSON.parse returns `unknown`; this field is documented to be a string in the API contract"
|
|
258
|
-
* >(parsed[key]);
|
|
259
|
-
* ```
|
|
260
|
-
*
|
|
261
|
-
* @typeParam TargetType - The type the caller is asserting the input has.
|
|
262
|
-
* @typeParam _Reason - A string literal describing why bypassing the type system is necessary here.
|
|
263
|
-
* Only meaningful at compile time. The reviewer evaluates whether it justifies the unsafety.
|
|
264
|
-
*/
|
|
265
|
-
function blindCast(input) {
|
|
266
|
-
return input;
|
|
267
|
-
}
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region ../../0-framework/0-foundation/foundation/dist/internal-error-Dfur7Zqt.mjs
|
|
270
|
-
/**
|
|
271
|
-
* A bug in Prisma ORM, not a user error. Never catch this except at the
|
|
272
|
-
* outermost boundary for crash reporting — an InternalError means an invariant
|
|
273
|
-
* broke and the process cannot reliably continue. User-facing failures use
|
|
274
|
-
* `structuredError` with a dotted code instead.
|
|
275
|
-
*/
|
|
276
|
-
var InternalError = class extends Error {
|
|
277
|
-
isPrismaInternalError = true;
|
|
278
|
-
constructor(message, options) {
|
|
279
|
-
super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
280
|
-
this.name = "InternalError";
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region ../../0-framework/0-foundation/foundation/dist/errors.mjs
|
|
285
|
-
/**
|
|
286
|
-
* Returns an object with the key/value if value is defined, otherwise an empty object.
|
|
287
|
-
*
|
|
288
|
-
* Use with spread to conditionally include optional properties while satisfying
|
|
289
|
-
* exactOptionalPropertyTypes. This is explicit about which properties are optional
|
|
290
|
-
* and won't inadvertently strip other undefined values.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* ```typescript
|
|
294
|
-
* // Instead of:
|
|
295
|
-
* const obj = {
|
|
296
|
-
* required: 'value',
|
|
297
|
-
* ...(optional ? { optional } : {}),
|
|
298
|
-
* };
|
|
299
|
-
*
|
|
300
|
-
* // Use:
|
|
301
|
-
* const obj = {
|
|
302
|
-
* required: 'value',
|
|
303
|
-
* ...ifDefined('optional', optional),
|
|
304
|
-
* };
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
function ifDefined(key, value) {
|
|
308
|
-
return value !== void 0 ? blindCast({ [key]: value }) : {};
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Structured CLI error that contains all information needed for error envelopes.
|
|
312
|
-
* Call sites throw these errors with full context.
|
|
313
|
-
*
|
|
314
|
-
* A `CliStructuredError` is a `StructuredError` (see
|
|
315
|
-
* `./structured-error.ts`): `code` is a dotted
|
|
316
|
-
* `NAMESPACE.SUBCODE` string, and the namespace prefix is the error's
|
|
317
|
-
* category — there is no separate `domain` field. See ADR 239 in
|
|
318
|
-
* prisma/prisma and composer's ADR-0044 for the namespace taxonomy.
|
|
319
|
-
*/
|
|
320
|
-
var CliStructuredError = class extends Error {
|
|
321
|
-
code;
|
|
322
|
-
severity;
|
|
323
|
-
constructor(code, summary, options) {
|
|
324
|
-
super(summary, options?.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
325
|
-
this.name = "CliStructuredError";
|
|
326
|
-
this.code = code;
|
|
327
|
-
this.severity = options?.severity ?? "error";
|
|
328
|
-
const fix = options?.fix === options?.why ? void 0 : options?.fix;
|
|
329
|
-
const where = options?.where ? {
|
|
330
|
-
...ifDefined("path", options.where.path),
|
|
331
|
-
...ifDefined("line", options.where.line)
|
|
332
|
-
} : void 0;
|
|
333
|
-
Object.assign(this, {
|
|
334
|
-
...ifDefined("why", options?.why),
|
|
335
|
-
...ifDefined("fix", fix),
|
|
336
|
-
...ifDefined("where", where),
|
|
337
|
-
...ifDefined("meta", options?.meta),
|
|
338
|
-
...ifDefined("docsUrl", options?.docsUrl)
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Converts this error to a CLI error envelope for output formatting.
|
|
343
|
-
*/
|
|
344
|
-
toEnvelope() {
|
|
345
|
-
return {
|
|
346
|
-
ok: false,
|
|
347
|
-
code: this.code,
|
|
348
|
-
severity: this.severity,
|
|
349
|
-
summary: this.message,
|
|
350
|
-
...ifDefined("why", this.why),
|
|
351
|
-
...ifDefined("fix", this.fix),
|
|
352
|
-
...ifDefined("where", this.where),
|
|
353
|
-
...ifDefined("meta", this.meta),
|
|
354
|
-
...ifDefined("docsUrl", this.docsUrl)
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Type guard to check if an error is a CliStructuredError.
|
|
359
|
-
* Uses duck-typing to work across module boundaries where instanceof may fail.
|
|
360
|
-
*/
|
|
361
|
-
static is(error) {
|
|
362
|
-
if (!(error instanceof Error)) return false;
|
|
363
|
-
const candidate = blindCast(error);
|
|
364
|
-
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && typeof candidate.toEnvelope === "function";
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region ../../0-framework/0-foundation/foundation/dist/result.mjs
|
|
369
|
-
/**
|
|
370
|
-
* Generic Result type for representing success or failure outcomes.
|
|
371
|
-
*
|
|
372
|
-
* This is the standard way to return "expected failures" as values rather than
|
|
373
|
-
* throwing exceptions. See docs/Error Handling.md for the full taxonomy.
|
|
374
|
-
*
|
|
375
|
-
* Naming rationale:
|
|
376
|
-
* - `Ok<T>` / `NotOk<F>` mirror the `ok: true/false` discriminator
|
|
377
|
-
* - `NotOk` avoids collision with domain types like "Failure" or "Error"
|
|
378
|
-
* - `failure` property distinguishes from JS Error semantics
|
|
379
|
-
*/
|
|
380
|
-
/**
|
|
381
|
-
* Result class that implements both Ok and NotOk variants.
|
|
382
|
-
*/
|
|
383
|
-
var ResultImpl = class ResultImpl {
|
|
384
|
-
ok;
|
|
385
|
-
_value;
|
|
386
|
-
_failure;
|
|
387
|
-
constructor(ok, valueOrFailure) {
|
|
388
|
-
this.ok = ok;
|
|
389
|
-
if (ok) this._value = blindCast(valueOrFailure);
|
|
390
|
-
else this._failure = blindCast(valueOrFailure);
|
|
391
|
-
Object.freeze(this);
|
|
392
|
-
}
|
|
393
|
-
get value() {
|
|
394
|
-
if (!this.ok) throw new InternalError("Cannot access value on NotOk result");
|
|
395
|
-
return this._value;
|
|
396
|
-
}
|
|
397
|
-
get failure() {
|
|
398
|
-
if (this.ok) throw new InternalError("Cannot access failure on Ok result");
|
|
399
|
-
return this._failure;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Creates a successful result.
|
|
403
|
-
*/
|
|
404
|
-
static ok(value) {
|
|
405
|
-
return blindCast(new ResultImpl(true, value));
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Creates an unsuccessful result.
|
|
409
|
-
*/
|
|
410
|
-
static notOk(failure) {
|
|
411
|
-
return blindCast(new ResultImpl(false, failure));
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Asserts that this result is Ok and returns the value.
|
|
415
|
-
* Throws if the result is NotOk.
|
|
416
|
-
*/
|
|
417
|
-
assertOk() {
|
|
418
|
-
if (!this.ok) throw new InternalError("Expected Ok result but got NotOk");
|
|
419
|
-
return this.value;
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Asserts that this result is NotOk and returns the failure.
|
|
423
|
-
* Throws if the result is Ok.
|
|
424
|
-
*/
|
|
425
|
-
assertNotOk() {
|
|
426
|
-
if (this.ok) throw new InternalError("Expected NotOk result but got Ok");
|
|
427
|
-
return this.failure;
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
/**
|
|
431
|
-
* Creates a successful result.
|
|
432
|
-
*/
|
|
433
|
-
function ok(value) {
|
|
434
|
-
return ResultImpl.ok(value);
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Creates an unsuccessful result.
|
|
438
|
-
*/
|
|
439
|
-
function notOk(failure) {
|
|
440
|
-
return ResultImpl.notOk(failure);
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Singleton for void success results.
|
|
444
|
-
* Use this for validation checks that don't produce a value.
|
|
445
|
-
*/
|
|
446
|
-
const OK_VOID = ResultImpl.ok(void 0);
|
|
447
|
-
/**
|
|
448
|
-
* Returns a successful void result.
|
|
449
|
-
* Use this for validation checks that don't produce a value.
|
|
450
|
-
*/
|
|
451
|
-
function okVoid() {
|
|
452
|
-
return OK_VOID;
|
|
453
|
-
}
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region ../../0-framework/3-tooling/cli/dist/run-alchemy-Dl_MWw4g.mjs
|
|
456
|
-
/**
|
|
457
|
-
* Which Alchemy CLI runs a generated stack file: the `alchemy` that
|
|
458
|
-
* `@prisma/composer` depends on, found from the app the way the stack file's
|
|
459
|
-
* own `@prisma/composer/...` imports are. The CLI and the stack code then
|
|
460
|
-
* come from one install, so the child loads one copy of `alchemy`.
|
|
461
|
-
*
|
|
462
|
-
* Node's resolver finds `@prisma/composer` from the app. It cannot find
|
|
463
|
-
* `alchemy` from there: alchemy exports neither its `package.json` nor its
|
|
464
|
-
* bin, and has no `require` condition. Bun has no `module.findPackageJSON`.
|
|
465
|
-
* So the last step is Node's own lookup written out: each `node_modules`
|
|
466
|
-
* above `@prisma/composer`'s real location, nearest first.
|
|
467
|
-
*/
|
|
468
|
-
const FIX = "Check that the app depends on @prisma/composer and that `alchemy`, which @prisma/composer depends on, is installed in a node_modules directory. Layouts without one, such as Yarn Plug'n'Play, are not supported.";
|
|
469
|
-
function binMissing(message) {
|
|
470
|
-
return new CliStructuredError("DEPLOY.ALCHEMY_BIN_MISSING", message, { fix: FIX });
|
|
471
|
-
}
|
|
472
|
-
function composerPackageDir(appDir) {
|
|
473
|
-
try {
|
|
474
|
-
const manifest = createRequire(path.join(appDir, "package.json")).resolve("@prisma/composer/package.json");
|
|
475
|
-
return path.dirname(fs.realpathSync(manifest));
|
|
476
|
-
} catch {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
function alchemyPackageDirAbove(dir) {
|
|
481
|
-
for (let current = dir;; current = path.dirname(current)) {
|
|
482
|
-
const candidate = path.join(current, "node_modules", "alchemy");
|
|
483
|
-
if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
|
|
484
|
-
if (path.dirname(current) === current) return void 0;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
function readPackageJson(packageDir) {
|
|
488
|
-
try {
|
|
489
|
-
return JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8"));
|
|
490
|
-
} catch {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function binOf(packageDir) {
|
|
495
|
-
const manifest = readPackageJson(packageDir);
|
|
496
|
-
if (typeof manifest !== "object" || manifest === null || !("bin" in manifest)) return void 0;
|
|
497
|
-
const bin = manifest.bin;
|
|
498
|
-
const relative = typeof bin === "string" ? bin : typeof bin === "object" && bin !== null && "alchemy" in bin ? bin.alchemy : void 0;
|
|
499
|
-
if (typeof relative !== "string") return void 0;
|
|
500
|
-
const entry = path.join(packageDir, relative);
|
|
501
|
-
return fs.existsSync(entry) ? entry : void 0;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* The JavaScript file `alchemy`'s `bin` names, for the app in `appDir`.
|
|
505
|
-
* Raises DEPLOY.ALCHEMY_BIN_MISSING when the app does not resolve
|
|
506
|
-
* `@prisma/composer` or no usable `alchemy` is installed beside it.
|
|
507
|
-
*/
|
|
508
|
-
function resolveAlchemyBin(appDir) {
|
|
509
|
-
const composerDir = composerPackageDir(appDir);
|
|
510
|
-
if (composerDir === void 0) throw binMissing(`Could not resolve @prisma/composer from "${appDir}".`);
|
|
511
|
-
const alchemyDir = alchemyPackageDirAbove(composerDir);
|
|
512
|
-
const entry = alchemyDir === void 0 ? void 0 : binOf(alchemyDir);
|
|
513
|
-
if (entry === void 0) throw binMissing(`Could not resolve the bin of the \`alchemy\` package @prisma/composer depends on, from "${composerDir}".`);
|
|
514
|
-
return entry;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Pipeline step 7 (deploy-cli.md § The pipeline; design-notes.md's "Driving
|
|
518
|
-
* Alchemy" call): hand the terminal to the generated stack file.
|
|
519
|
-
*
|
|
520
|
-
* Runs the bin of the `alchemy` the app's `@prisma/composer` depends on
|
|
521
|
-
* (`resolveAlchemyBin`), started with Node (`nodeExecutable`). Never a
|
|
522
|
-
* `node_modules/.bin` link, which pnpm creates only for an app's direct
|
|
523
|
-
* dependencies.
|
|
524
|
-
*
|
|
525
|
-
* This module composes the invocation; it does not decide how the child is
|
|
526
|
-
* started. Under the CLI the engine starts it (`ctx.spawn`), which is what
|
|
527
|
-
* makes Ctrl-C reach the child natively and keeps signal policy in one place.
|
|
528
|
-
* `spawnAlchemy` is the default for programmatic hosts driving
|
|
529
|
-
* `@prisma/composer/control`, which have no engine to borrow.
|
|
530
|
-
*/
|
|
531
|
-
function currentRuntime() {
|
|
532
|
-
return {
|
|
533
|
-
bun: process.versions.bun !== void 0,
|
|
534
|
-
execPath: process.execPath,
|
|
535
|
-
env: process.env,
|
|
536
|
-
platform: process.platform,
|
|
537
|
-
exists: fs.existsSync
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
function envValue(env, name) {
|
|
541
|
-
return Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
542
|
-
}
|
|
543
|
-
/** The file names `node` may have in a PATH directory: PATHEXT's extensions on Windows. */
|
|
544
|
-
function nodeFileNames(runtime) {
|
|
545
|
-
if (runtime.platform !== "win32") return ["node"];
|
|
546
|
-
return (envValue(runtime.env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((extension) => extension.length > 0).map((extension) => `node${extension}`);
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* The Node that starts Alchemy's launcher: this process's own runtime under
|
|
550
|
-
* Node, and the first `node` on PATH under Bun. Alchemy's launcher may still
|
|
551
|
-
* move itself to Bun when the package-manager environment says Bun invoked
|
|
552
|
-
* it (`bunx`, `bun run`), so the runtime Alchemy ends up on follows how
|
|
553
|
-
* `prisma` was invoked.
|
|
554
|
-
*/
|
|
555
|
-
function nodeExecutable(runtime = currentRuntime()) {
|
|
556
|
-
if (!runtime.bun) return runtime.execPath;
|
|
557
|
-
const paths = runtime.platform === "win32" ? path.win32 : path.posix;
|
|
558
|
-
const names = nodeFileNames(runtime);
|
|
559
|
-
for (const rawDir of (envValue(runtime.env, "PATH") ?? "").split(paths.delimiter)) {
|
|
560
|
-
const dir = rawDir.replace(/^"(.*)"$/, "$1");
|
|
561
|
-
if (dir.length === 0) continue;
|
|
562
|
-
for (const name of names) {
|
|
563
|
-
const candidate = paths.join(dir, name);
|
|
564
|
-
if (runtime.exists(candidate)) return candidate;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
throw new CliStructuredError("DEPLOY.NODE_MISSING", "Composer starts Alchemy with Node, and no `node` was found on PATH.", { fix: "Install Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer, and put it on PATH, or run `prisma` under Node." });
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Resolves the invocation against this machine — the step every adapter takes
|
|
571
|
-
* and no caller should. Runs alchemy's JavaScript entry with Node, so no shell
|
|
572
|
-
* shim is involved on any platform. Raises DEPLOY.ALCHEMY_BIN_MISSING when
|
|
573
|
-
* Composer's alchemy cannot be resolved, and DEPLOY.NODE_MISSING when no Node
|
|
574
|
-
* can run it.
|
|
575
|
-
*/
|
|
576
|
-
function alchemyCommandLine(invocation, alchemyBin = resolveAlchemyBin(invocation.cwd), node = nodeExecutable()) {
|
|
577
|
-
return {
|
|
578
|
-
command: node,
|
|
579
|
-
args: [
|
|
580
|
-
alchemyBin,
|
|
581
|
-
invocation.action,
|
|
582
|
-
invocation.stackFileRelativePath,
|
|
583
|
-
"--yes",
|
|
584
|
-
"--stage",
|
|
585
|
-
invocation.stage
|
|
586
|
-
],
|
|
587
|
-
cwd: invocation.cwd,
|
|
588
|
-
env: invocation.env
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
/** What becomes `alchemy deploy|destroy <stack file> --yes --stage <stage>`. */
|
|
592
|
-
function alchemyInvocation(input) {
|
|
593
|
-
return {
|
|
594
|
-
action: input.command,
|
|
595
|
-
stackFileRelativePath: input.stackFileRelativePath,
|
|
596
|
-
cwd: input.cwd,
|
|
597
|
-
stage: input.stage,
|
|
598
|
-
env: {
|
|
599
|
-
...input.containerEnv,
|
|
600
|
-
...input.preflightEnv,
|
|
601
|
-
...input.env
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* The default runner for hosts with no engine: inherited stdio, the caller's
|
|
607
|
-
* own process group, and the child's status returned verbatim. It does not
|
|
608
|
-
* collapse a signal into an exit code — that collapse is what made a
|
|
609
|
-
* Ctrl-C'd deploy report itself as a failure.
|
|
610
|
-
*/
|
|
611
|
-
const spawnAlchemy = async (invocation) => {
|
|
612
|
-
const commandLine = alchemyCommandLine(invocation);
|
|
613
|
-
return {
|
|
614
|
-
...await spawnCommandLine(commandLine),
|
|
615
|
-
commandLine
|
|
616
|
-
};
|
|
617
|
-
};
|
|
618
|
-
/**
|
|
619
|
-
* One argument as the platform's shell reads it literally: single quotes for
|
|
620
|
-
* POSIX shells, double quotes for cmd.exe. cmd.exe expands `%VAR%` inside
|
|
621
|
-
* double quotes, and strips or expands `!` when delayed expansion is on; no
|
|
622
|
-
* quoting prevents either, so an argument containing them is not fully
|
|
623
|
-
* literal there.
|
|
624
|
-
*/
|
|
625
|
-
function shellArg(arg, platform) {
|
|
626
|
-
if (platform === "win32") return /^[\w@+=:,./\\~-]+$/.test(arg) ? arg : `"${arg.replaceAll("\"", "\"\"")}"`;
|
|
627
|
-
return /^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* The command a user runs from the invocation's directory to repeat a
|
|
631
|
-
* converge: the command line the adapter started, or, from an adapter that
|
|
632
|
-
* does not report one, `alchemy` with the same arguments.
|
|
633
|
-
*/
|
|
634
|
-
function reproduceCommand(invocation, outcome, platform = process.platform) {
|
|
635
|
-
return (outcome?.commandLine === void 0 ? [
|
|
636
|
-
"alchemy",
|
|
637
|
-
invocation.action,
|
|
638
|
-
invocation.stackFileRelativePath,
|
|
639
|
-
"--yes",
|
|
640
|
-
"--stage",
|
|
641
|
-
invocation.stage
|
|
642
|
-
] : [outcome.commandLine.command, ...outcome.commandLine.args]).map((arg) => shellArg(arg, platform)).join(" ");
|
|
643
|
-
}
|
|
644
|
-
/** Starts a resolved command line with inherited stdio and returns how it ended. */
|
|
645
|
-
function spawnCommandLine(line) {
|
|
646
|
-
return new Promise((resolve, reject) => {
|
|
647
|
-
const child = spawn(line.command, [...line.args], {
|
|
648
|
-
cwd: line.cwd,
|
|
649
|
-
stdio: "inherit",
|
|
650
|
-
env: {
|
|
651
|
-
...process.env,
|
|
652
|
-
...line.env
|
|
653
|
-
}
|
|
654
|
-
});
|
|
655
|
-
child.on("error", reject);
|
|
656
|
-
child.on("close", (exitCode, signal) => {
|
|
657
|
-
resolve({
|
|
658
|
-
exitCode,
|
|
659
|
-
signal
|
|
660
|
-
});
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
//#endregion
|
|
665
|
-
export { notOk as a, CliStructuredError as c, checkComposerConfig as d, configFileMissing as f, sectionMissing as h, spawnAlchemy as i, InternalError as l, noComposerExportMessage as m, alchemyInvocation as n, ok as o, entryMissing as p, reproduceCommand as r, okVoid as s, alchemyCommandLine as t, blindCast as u };
|
|
666
|
-
|
|
667
|
-
//# sourceMappingURL=run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map
|