@prisma/composer-cli 0.36.0-dev.3 → 0.36.0-dev.5

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 (40) hide show
  1. package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs +590 -0
  2. package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs.map +1 -0
  3. package/dist/{dev-current-BNoPkDRU-DGd_7FDS.mjs → dev-current-BurA9uhA-BWYAftn9.mjs} +6 -6
  4. package/dist/{dev-current-BNoPkDRU-DGd_7FDS.mjs.map → dev-current-BurA9uhA-BWYAftn9.mjs.map} +1 -1
  5. package/dist/{dev-environment-name-6eEr5PW8-lIZmJjfr.mjs → dev-environment-name-6eEr5PW8-YyPDRApO.mjs} +2 -2
  6. package/dist/dev-environment-name-6eEr5PW8-YyPDRApO.mjs.map +1 -0
  7. package/dist/{dist-B9-nLeho.mjs → dist-BsONwZNR.mjs} +3 -6
  8. package/dist/{dist-B9-nLeho.mjs.map → dist-BsONwZNR.mjs.map} +1 -1
  9. package/dist/{execute-deploy-destroy-BIqwt1RF-D3F6yxLV.mjs → execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs} +50 -11
  10. package/dist/execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs.map +1 -0
  11. package/dist/{execute-dev-DIEyloWn-CjtRM3-x.mjs → execute-dev-4KYkqSMh-uh7gnPyS.mjs} +33 -17
  12. package/dist/{execute-dev-DIEyloWn-CjtRM3-x.mjs.map → execute-dev-4KYkqSMh-uh7gnPyS.mjs.map} +1 -1
  13. package/dist/{execute-dev-current-CeKI-tiC-fd62IW2Y.mjs → execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs} +6 -6
  14. package/dist/{execute-dev-current-CeKI-tiC-fd62IW2Y.mjs.map → execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs.map} +1 -1
  15. package/dist/{family-Dy3ZQOxG-CcELNRXg.d.mts → family-DACJfaA5-CBuEC2B3.d.mts} +103 -61
  16. package/dist/family-DACJfaA5-CBuEC2B3.d.mts.map +1 -0
  17. package/dist/family.d.mts +1 -1
  18. package/dist/family.mjs +12 -4
  19. package/dist/family.mjs.map +1 -1
  20. package/dist/{generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs → generate-dev-stack-DS6U_JHX-wDTViqdg.mjs} +9 -4
  21. package/dist/generate-dev-stack-DS6U_JHX-wDTViqdg.mjs.map +1 -0
  22. package/dist/{list-deployed-2Xs64YAh.mjs → list-deployed-D5TBZvbj.mjs} +4 -4
  23. package/dist/{list-deployed-2Xs64YAh.mjs.map → list-deployed-D5TBZvbj.mjs.map} +1 -1
  24. package/dist/result-sR7PBi61.mjs +229 -0
  25. package/dist/result-sR7PBi61.mjs.map +1 -0
  26. package/dist/run-alchemy-B-Z6i3cD-f0MXFCG8.mjs +219 -0
  27. package/dist/run-alchemy-B-Z6i3cD-f0MXFCG8.mjs.map +1 -0
  28. package/dist/testing.d.mts +1 -1
  29. package/dist/testing.mjs +3 -2
  30. package/dist/testing.mjs.map +1 -1
  31. package/dist/{validate-environment-CEhUSEg2-BohWFcgr.mjs → validate-environment-BNZC6W46-DY_7cPQJ.mjs} +449 -342
  32. package/dist/validate-environment-BNZC6W46-DY_7cPQJ.mjs.map +1 -0
  33. package/package.json +9 -9
  34. package/dist/dev-environment-name-6eEr5PW8-lIZmJjfr.mjs.map +0 -1
  35. package/dist/execute-deploy-destroy-BIqwt1RF-D3F6yxLV.mjs.map +0 -1
  36. package/dist/family-Dy3ZQOxG-CcELNRXg.d.mts.map +0 -1
  37. package/dist/generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs.map +0 -1
  38. package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs +0 -667
  39. package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map +0 -1
  40. package/dist/validate-environment-CEhUSEg2-BohWFcgr.mjs.map +0 -1
@@ -0,0 +1,590 @@
1
+ import { createRequire } from "node:module";
2
+ import * as fs$1 from "node:fs";
3
+ import * as path$1 from "node:path";
4
+ //#region \0rolldown/runtime.js
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
27
+ //#endregion
28
+ //#region ../../0-framework/3-tooling/cli/dist/composer-config-DO_iG0iR.mjs
29
+ /**
30
+ * What makes a `composer` section valid, shared by the CLI's section validator and the programmatic operations.
31
+ * It imports nothing from the CLI engine, because `@prisma/composer` must not depend on it.
32
+ */
33
+ const SECTION_FIX = "Write `composer: composer({ entry: './module.ts', extensions: [...], state: ... })` in prisma.config.ts, with `import { defineConfig as composer } from '@prisma/composer/config'`.";
34
+ 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.`;
35
+ const SECTION_IS_THE_ONLY_SOURCE = "Composer reads its configuration only from the `composer` section of prisma.config.ts.";
36
+ const DESCRIPTOR_FIX = "Use the descriptor the extension factory returns, unchanged, instead of building one by hand.";
37
+ const RETIRED_FILE_NAMES = [
38
+ "ts",
39
+ "mts",
40
+ "mjs",
41
+ "js"
42
+ ].map((extension) => `prisma-composer.config.${extension}`);
43
+ const sectionMissing = {
44
+ code: "CONFIG.SECTION_MISSING",
45
+ summary: "No loaded prisma.config.ts declares a `composer` section.",
46
+ why: `${SECTION_IS_THE_ONLY_SOURCE} A prisma-composer.config.ts file is no longer read.`,
47
+ fix: MOVE_TO_SECTION_FIX
48
+ };
49
+ /** What the generated stack file throws when the file it imports has no `composer` export. */
50
+ function noComposerExportMessage(configFile) {
51
+ return `${configFile} declares no \`composer\` section. Pass the prisma.config.ts that declares it.`;
52
+ }
53
+ function configFileMissing(file) {
54
+ return {
55
+ code: "CONFIG.FILE_MISSING",
56
+ summary: `${file} does not exist.`,
57
+ fix: "Pass the path of the prisma.config.ts that declares the `composer` section.",
58
+ where: file
59
+ };
60
+ }
61
+ /** A prisma-composer.config.* beside the declaring file would otherwise be silently ignored. */
62
+ /** The path with symlinks resolved; the path itself when it cannot be resolved, so the check never throws. */
63
+ function realPath(file) {
64
+ try {
65
+ return fs$1.realpathSync(file);
66
+ } catch {
67
+ return file;
68
+ }
69
+ }
70
+ function retiredFileFinding(configFile) {
71
+ const directory = path$1.dirname(realPath(configFile));
72
+ const found = RETIRED_FILE_NAMES.map((name) => path$1.join(directory, name)).find((file) => fs$1.existsSync(file));
73
+ if (found === void 0) return void 0;
74
+ return {
75
+ code: "CONFIG.FILE_RETIRED",
76
+ summary: `${found} is no longer read.`,
77
+ why: SECTION_IS_THE_ONLY_SOURCE,
78
+ fix: MOVE_TO_SECTION_FIX,
79
+ where: found
80
+ };
81
+ }
82
+ function isObject(value) {
83
+ return typeof value === "object" && value !== null && !Array.isArray(value);
84
+ }
85
+ function isExtensionDescriptor(value) {
86
+ return isObject(value) && typeof value["id"] === "string" && value["id"].length > 0 && isObject(value["nodes"]);
87
+ }
88
+ function isStateDescriptor(value) {
89
+ return isObject(value) && typeof value["extension"] === "string" && typeof value["create"] === "function";
90
+ }
91
+ const stateInvalid = {
92
+ code: "CONFIG.FIELD_INVALID",
93
+ summary: "`composer.state` must be a state descriptor with a string `extension` and a `create` function.",
94
+ fix: "Set `state` to the state descriptor an extension provides, e.g. `state: prismaState()`.",
95
+ field: "state"
96
+ };
97
+ const SECTION_FIELDS = /* @__PURE__ */ new Set([
98
+ "entry",
99
+ "extensions",
100
+ "state",
101
+ "config",
102
+ "secrets"
103
+ ]);
104
+ const entryInvalid = {
105
+ code: "CONFIG.FIELD_INVALID",
106
+ summary: "`composer.entry` must be a non-empty string: the path to the module whose default export is the app.",
107
+ fix: "Set `entry` to that module's path, relative to prisma.config.ts, e.g. `entry: './module.ts'`.",
108
+ field: "entry"
109
+ };
110
+ /** Neither the section's `entry` nor an override names the module whose default export is the app. */
111
+ const entryMissing = {
112
+ code: "CONFIG.ENTRY_MISSING",
113
+ summary: "No entry module is set, so there is no app to load.",
114
+ why: "The entry is the module whose default export is the app root, built with module(...).",
115
+ 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).",
116
+ field: "entry"
117
+ };
118
+ function unknownField(key) {
119
+ return {
120
+ code: "CONFIG.FIELD_UNKNOWN",
121
+ summary: `The \`composer\` section has no field \`${key}\`.`,
122
+ fix: key === "composer" ? "Pass the `composer` property of the prisma.config.ts export, not the whole export. The section takes only `entry`, `extensions`, `state`, `config` and `secrets`." : `Remove \`${key}\`. The section takes only \`entry\`, \`extensions\`, \`state\`, \`config\` and \`secrets\`.`,
123
+ field: key
124
+ };
125
+ }
126
+ function checkExtensions(value) {
127
+ if (!Array.isArray(value)) return {
128
+ extensions: [],
129
+ findings: [{
130
+ code: "CONFIG.FIELD_INVALID",
131
+ summary: "`composer.extensions` must be an array of extension descriptors.",
132
+ fix: "Set `extensions` to the descriptors your extensions provide, e.g. `extensions: [nodeBuild()]`.",
133
+ field: "extensions"
134
+ }]
135
+ };
136
+ const findings = [];
137
+ const extensions = [];
138
+ const seen = /* @__PURE__ */ new Set();
139
+ for (const [index, entry] of value.entries()) {
140
+ const field = `extensions[${index}]`;
141
+ if (!isObject(entry)) {
142
+ findings.push({
143
+ code: "CONFIG.FIELD_INVALID",
144
+ summary: `\`composer.${field}\` must be an extension descriptor object.`,
145
+ fix: "Put the descriptor an extension factory returns here, e.g. `nodeBuild()`, not the factory itself.",
146
+ field
147
+ });
148
+ continue;
149
+ }
150
+ const id = entry["id"];
151
+ if (typeof id !== "string" || id.length === 0) findings.push({
152
+ code: "CONFIG.FIELD_INVALID",
153
+ summary: `\`composer.${field}.id\` must be a non-empty string (the extension package name).`,
154
+ fix: DESCRIPTOR_FIX,
155
+ field: `${field}.id`
156
+ });
157
+ else if (seen.has(id)) findings.push({
158
+ code: "CONFIG.EXTENSION_DUPLICATE",
159
+ summary: `Extension "${id}" is listed more than once in \`composer.extensions\`.`,
160
+ fix: `Remove the repeated "${id}" entry from \`extensions\`.`,
161
+ field: `${field}.id`
162
+ });
163
+ else seen.add(id);
164
+ if (!isObject(entry["nodes"])) findings.push({
165
+ code: "CONFIG.FIELD_INVALID",
166
+ summary: `\`composer.${field}.nodes\` must be an object (the node-ID → control registry).`,
167
+ fix: DESCRIPTOR_FIX,
168
+ field: `${field}.nodes`
169
+ });
170
+ if (isExtensionDescriptor(entry)) extensions.push(entry);
171
+ }
172
+ return {
173
+ findings,
174
+ extensions
175
+ };
176
+ }
177
+ function isAdapterList(value) {
178
+ return Array.isArray(value) && value.every((entry) => typeof entry === "function");
179
+ }
180
+ function checkAdapters(list, value) {
181
+ if (value === void 0) return [];
182
+ if (!Array.isArray(value)) return [{
183
+ code: "CONFIG.FIELD_INVALID",
184
+ summary: `\`composer.${list}\` must be an array of adapters.`,
185
+ fix: `Set \`${list}\` to a list of adapters, e.g. \`${list}: [dotenv(), environmentVariables()]\`, imported from '@prisma/composer/config'.`,
186
+ field: list
187
+ }];
188
+ return value.flatMap((entry, index) => typeof entry === "function" ? [] : [{
189
+ code: "CONFIG.FIELD_INVALID",
190
+ summary: `\`composer.${list}[${index}]\` must be an adapter: a function that receives the environment and returns its values.`,
191
+ fix: "Put an adapter here, e.g. `dotenv()`.",
192
+ field: `${list}[${index}]`
193
+ }]);
194
+ }
195
+ function checkFields(section) {
196
+ if (Object.hasOwn(section, "configPath")) return {
197
+ ok: false,
198
+ findings: [{
199
+ code: "CONFIG.FIELD_RETIRED",
200
+ summary: "`composer.configPath` is no longer supported: prisma-composer.config.ts is no longer read.",
201
+ why: SECTION_IS_THE_ONLY_SOURCE,
202
+ fix: `Replace \`configPath\` with the section itself. ${MOVE_TO_SECTION_FIX}`,
203
+ field: "configPath"
204
+ }]
205
+ };
206
+ if (Object.hasOwn(section, "composer")) return {
207
+ ok: false,
208
+ findings: [unknownField("composer")]
209
+ };
210
+ const findings = Object.keys(section).filter((key) => !SECTION_FIELDS.has(key)).map(unknownField);
211
+ const checked = checkExtensions(section["extensions"]);
212
+ findings.push(...checked.findings);
213
+ const state = section["state"];
214
+ if (!isStateDescriptor(state)) findings.push(stateInvalid);
215
+ const entry = section["entry"];
216
+ const entryValid = entry === void 0 || typeof entry === "string" && entry.length > 0;
217
+ if (!entryValid) findings.push(entryInvalid);
218
+ const config = section["config"];
219
+ const secrets = section["secrets"];
220
+ findings.push(...checkAdapters("config", config), ...checkAdapters("secrets", secrets));
221
+ const [first, ...rest] = findings;
222
+ if (first === void 0 && isStateDescriptor(state) && entryValid && (config === void 0 || isAdapterList(config)) && (secrets === void 0 || isAdapterList(secrets))) return {
223
+ ok: true,
224
+ value: {
225
+ extensions: checked.extensions,
226
+ state,
227
+ ...entry === void 0 ? {} : { entry },
228
+ ...config === void 0 ? {} : { config },
229
+ ...secrets === void 0 ? {} : { secrets }
230
+ }
231
+ };
232
+ return {
233
+ ok: false,
234
+ findings: [first ?? stateInvalid, ...rest]
235
+ };
236
+ }
237
+ /**
238
+ * Checks the fields that identify each descriptor and returns the descriptors as the config file's own objects.
239
+ * Never throws: a section's values are user code, and a throwing getter or Proxy trap becomes a finding.
240
+ */
241
+ function checkComposerSection(raw) {
242
+ if (!isObject(raw)) return {
243
+ ok: false,
244
+ findings: [{
245
+ code: "CONFIG.FIELD_INVALID",
246
+ summary: "The `composer` section of prisma.config.ts must be an object.",
247
+ fix: SECTION_FIX
248
+ }]
249
+ };
250
+ try {
251
+ return checkFields({ ...raw });
252
+ } catch (cause) {
253
+ return {
254
+ ok: false,
255
+ findings: [{
256
+ code: "CONFIG.FIELD_INVALID",
257
+ summary: "The `composer` section of prisma.config.ts could not be read.",
258
+ why: `Reading it threw: ${cause instanceof Error ? cause.message : String(cause)}`,
259
+ fix: SECTION_FIX
260
+ }]
261
+ };
262
+ }
263
+ }
264
+ /**
265
+ * 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.
266
+ */
267
+ function checkComposerConfig(raw, configFile) {
268
+ const retired = retiredFileFinding(configFile);
269
+ const checked = checkComposerSection(raw);
270
+ if (retired === void 0) return checked;
271
+ return {
272
+ ok: false,
273
+ findings: checked.ok ? [retired] : [retired, ...checked.findings]
274
+ };
275
+ }
276
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
277
+ const fs = __require("fs");
278
+ const path = __require("path");
279
+ const os = __require("os");
280
+ const crypto = __require("crypto");
281
+ const TIPS = [
282
+ "◈ encrypted .env [www.dotenvx.com]",
283
+ "◈ secrets for agents [www.dotenvx.com]",
284
+ "⌁ auth for agents [www.vestauth.com]",
285
+ "⌘ custom filepath { path: '/custom/path/.env' }",
286
+ "⌘ enable debugging { debug: true }",
287
+ "⌘ override existing { override: true }",
288
+ "⌘ suppress logs { quiet: true }",
289
+ "⌘ multiple files { path: ['.env.local', '.env'] }"
290
+ ];
291
+ function _getRandomTip() {
292
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
293
+ }
294
+ function parseBoolean(value) {
295
+ if (typeof value === "string") return ![
296
+ "false",
297
+ "0",
298
+ "no",
299
+ "off",
300
+ ""
301
+ ].includes(value.toLowerCase());
302
+ return Boolean(value);
303
+ }
304
+ function supportsAnsi() {
305
+ return process.stdout.isTTY;
306
+ }
307
+ function dim(text) {
308
+ return supportsAnsi() ? `\x1b[2m${text}\x1b[0m` : text;
309
+ }
310
+ const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
311
+ function parse(src) {
312
+ const obj = {};
313
+ let lines = src.toString();
314
+ lines = lines.replace(/\r\n?/gm, "\n");
315
+ let match;
316
+ while ((match = LINE.exec(lines)) != null) {
317
+ const key = match[1];
318
+ let value = match[2] || "";
319
+ value = value.trim();
320
+ const maybeQuote = value[0];
321
+ value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
322
+ if (maybeQuote === "\"") {
323
+ value = value.replace(/\\n/g, "\n");
324
+ value = value.replace(/\\r/g, "\r");
325
+ }
326
+ obj[key] = value;
327
+ }
328
+ return obj;
329
+ }
330
+ function _parseVault(options) {
331
+ options = options || {};
332
+ const vaultPath = _vaultPath(options);
333
+ options.path = vaultPath;
334
+ const result = DotenvModule.configDotenv(options);
335
+ if (!result.parsed) {
336
+ const err = /* @__PURE__ */ new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
337
+ err.code = "MISSING_DATA";
338
+ throw err;
339
+ }
340
+ const keys = _dotenvKey(options).split(",");
341
+ const length = keys.length;
342
+ let decrypted;
343
+ for (let i = 0; i < length; i++) try {
344
+ const attrs = _instructions(result, keys[i].trim());
345
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
346
+ break;
347
+ } catch (error) {
348
+ if (i + 1 >= length) throw error;
349
+ }
350
+ return DotenvModule.parse(decrypted);
351
+ }
352
+ function _warn(message) {
353
+ console.error(`⚠ ${message}`);
354
+ }
355
+ function _debug(message) {
356
+ console.log(`┆ ${message}`);
357
+ }
358
+ function _log(message) {
359
+ console.log(`◇ ${message}`);
360
+ }
361
+ function _dotenvKey(options) {
362
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) return options.DOTENV_KEY;
363
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) return process.env.DOTENV_KEY;
364
+ return "";
365
+ }
366
+ function _instructions(result, dotenvKey) {
367
+ let uri;
368
+ try {
369
+ uri = new URL(dotenvKey);
370
+ } catch (error) {
371
+ if (error.code === "ERR_INVALID_URL") {
372
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
373
+ err.code = "INVALID_DOTENV_KEY";
374
+ throw err;
375
+ }
376
+ throw error;
377
+ }
378
+ const key = uri.password;
379
+ if (!key) {
380
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing key part");
381
+ err.code = "INVALID_DOTENV_KEY";
382
+ throw err;
383
+ }
384
+ const environment = uri.searchParams.get("environment");
385
+ if (!environment) {
386
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing environment part");
387
+ err.code = "INVALID_DOTENV_KEY";
388
+ throw err;
389
+ }
390
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
391
+ const ciphertext = result.parsed[environmentKey];
392
+ if (!ciphertext) {
393
+ const err = /* @__PURE__ */ new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
394
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
395
+ throw err;
396
+ }
397
+ return {
398
+ ciphertext,
399
+ key
400
+ };
401
+ }
402
+ function _vaultPath(options) {
403
+ let possibleVaultPath = null;
404
+ if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
405
+ for (const filepath of options.path) if (fs.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
406
+ } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
407
+ else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
408
+ if (fs.existsSync(possibleVaultPath)) return possibleVaultPath;
409
+ return null;
410
+ }
411
+ function _resolveHome(envPath) {
412
+ return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
413
+ }
414
+ function _configVault(options) {
415
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
416
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
417
+ if (debug || !quiet) _log("loading env from encrypted .env.vault");
418
+ const parsed = DotenvModule._parseVault(options);
419
+ let processEnv = process.env;
420
+ if (options && options.processEnv != null) processEnv = options.processEnv;
421
+ DotenvModule.populate(processEnv, parsed, options);
422
+ return { parsed };
423
+ }
424
+ function configDotenv(options) {
425
+ const dotenvPath = path.resolve(process.cwd(), ".env");
426
+ let encoding = "utf8";
427
+ let processEnv = process.env;
428
+ if (options && options.processEnv != null) processEnv = options.processEnv;
429
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
430
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
431
+ if (options && options.encoding) encoding = options.encoding;
432
+ else if (debug) _debug("no encoding is specified (UTF-8 is used by default)");
433
+ let optionPaths = [dotenvPath];
434
+ if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
435
+ else {
436
+ optionPaths = [];
437
+ for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
438
+ }
439
+ let lastError;
440
+ const parsedAll = {};
441
+ for (const path of optionPaths) try {
442
+ const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
443
+ DotenvModule.populate(parsedAll, parsed, options);
444
+ } catch (e) {
445
+ if (debug) _debug(`failed to load ${path} ${e.message}`);
446
+ lastError = e;
447
+ }
448
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
449
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
450
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
451
+ if (debug || !quiet) {
452
+ const keysCount = Object.keys(populated).length;
453
+ const shortPaths = [];
454
+ for (const filePath of optionPaths) try {
455
+ const relative = path.relative(process.cwd(), filePath);
456
+ shortPaths.push(relative);
457
+ } catch (e) {
458
+ if (debug) _debug(`failed to load ${filePath} ${e.message}`);
459
+ lastError = e;
460
+ }
461
+ _log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
462
+ }
463
+ if (lastError) return {
464
+ parsed: parsedAll,
465
+ error: lastError
466
+ };
467
+ else return { parsed: parsedAll };
468
+ }
469
+ function config(options) {
470
+ if (_dotenvKey(options).length === 0) return DotenvModule.configDotenv(options);
471
+ const vaultPath = _vaultPath(options);
472
+ if (!vaultPath) {
473
+ _warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
474
+ return DotenvModule.configDotenv(options);
475
+ }
476
+ return DotenvModule._configVault(options);
477
+ }
478
+ function decrypt(encrypted, keyStr) {
479
+ const key = Buffer.from(keyStr.slice(-64), "hex");
480
+ let ciphertext = Buffer.from(encrypted, "base64");
481
+ const nonce = ciphertext.subarray(0, 12);
482
+ const authTag = ciphertext.subarray(-16);
483
+ ciphertext = ciphertext.subarray(12, -16);
484
+ try {
485
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
486
+ aesgcm.setAuthTag(authTag);
487
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
488
+ } catch (error) {
489
+ const isRange = error instanceof RangeError;
490
+ const invalidKeyLength = error.message === "Invalid key length";
491
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
492
+ if (isRange || invalidKeyLength) {
493
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
494
+ err.code = "INVALID_DOTENV_KEY";
495
+ throw err;
496
+ } else if (decryptionFailed) {
497
+ const err = /* @__PURE__ */ new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
498
+ err.code = "DECRYPTION_FAILED";
499
+ throw err;
500
+ } else throw error;
501
+ }
502
+ }
503
+ function populate(processEnv, parsed, options = {}) {
504
+ const debug = Boolean(options && options.debug);
505
+ const override = Boolean(options && options.override);
506
+ const populated = {};
507
+ if (typeof parsed !== "object") {
508
+ const err = /* @__PURE__ */ new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
509
+ err.code = "OBJECT_REQUIRED";
510
+ throw err;
511
+ }
512
+ for (const key of Object.keys(parsed)) if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
513
+ if (override === true) {
514
+ processEnv[key] = parsed[key];
515
+ populated[key] = parsed[key];
516
+ }
517
+ if (debug) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
518
+ else _debug(`"${key}" is already defined and was NOT overwritten`);
519
+ } else {
520
+ processEnv[key] = parsed[key];
521
+ populated[key] = parsed[key];
522
+ }
523
+ return populated;
524
+ }
525
+ const DotenvModule = {
526
+ configDotenv,
527
+ _configVault,
528
+ _parseVault,
529
+ config,
530
+ decrypt,
531
+ parse,
532
+ populate
533
+ };
534
+ module.exports.configDotenv = DotenvModule.configDotenv;
535
+ module.exports._configVault = DotenvModule._configVault;
536
+ module.exports._parseVault = DotenvModule._parseVault;
537
+ module.exports.config = DotenvModule.config;
538
+ module.exports.decrypt = DotenvModule.decrypt;
539
+ module.exports.parse = DotenvModule.parse;
540
+ module.exports.populate = DotenvModule.populate;
541
+ module.exports = DotenvModule;
542
+ })))();
543
+ /** The prefix of the variables Composer sets for itself, such as the ones it passes its own child processes. */
544
+ const COMPOSER_PREFIX = "PRISMA_COMPOSER_";
545
+ /**
546
+ * Set on a child Composer starts. It maps each variable without Composer's prefix
547
+ * that Composer set or changed for the child to the parent's own value, or to null
548
+ * where the parent had none, so the child's environmentVariables() returns what the
549
+ * parent's did.
550
+ */
551
+ const PARENT_VALUES_ENV = `${COMPOSER_PREFIX}PARENT_VALUES`;
552
+ /**
553
+ * Reads the process environment when called: every variable whose value is a string,
554
+ * except Composer's own `PRISMA_COMPOSER_` variables. The default for both `config` and `secrets`.
555
+ */
556
+ function environmentVariables() {
557
+ return () => {
558
+ const values = {};
559
+ for (const [name, value] of Object.entries(process.env)) if (typeof value === "string" && !name.startsWith(COMPOSER_PREFIX)) values[name] = value;
560
+ for (const [name, parentValue] of parentValues()) if (parentValue === null) delete values[name];
561
+ else values[name] = parentValue;
562
+ return values;
563
+ };
564
+ }
565
+ function parentValues() {
566
+ const text = process.env[PARENT_VALUES_ENV];
567
+ if (text === void 0) return [];
568
+ const parsed = JSON.parse(text);
569
+ if (typeof parsed !== "object" || parsed === null) return [];
570
+ return Object.entries(parsed).filter((entry) => entry[1] === null || typeof entry[1] === "string");
571
+ }
572
+ /**
573
+ * The variables Composer adds to a child's environment, plus the record of the parent's
574
+ * own value for each one it sets or changes outside its prefix.
575
+ */
576
+ function childEnvironment(additions, parent = process.env) {
577
+ const changed = {};
578
+ for (const [name, value] of Object.entries(additions)) {
579
+ if (name.startsWith(COMPOSER_PREFIX) || value === void 0 || parent[name] === value) continue;
580
+ changed[name] = parent[name] ?? null;
581
+ }
582
+ return Object.keys(changed).length === 0 ? { ...additions } : {
583
+ ...additions,
584
+ [PARENT_VALUES_ENV]: JSON.stringify(changed)
585
+ };
586
+ }
587
+ //#endregion
588
+ export { entryMissing as a, __commonJSMin as c, configFileMissing as i, __require as l, environmentVariables as n, noComposerExportMessage as o, checkComposerConfig as r, sectionMissing as s, childEnvironment as t, __toESM as u };
589
+
590
+ //# sourceMappingURL=config-adapters-BA_IeiX0-CiRnz7z8.mjs.map