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

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 (45) hide show
  1. package/dist/{app-config-CErnR6NK-6QjHJ7q5.mjs → app-config-CErnR6NK-DnKH4Kqc.mjs} +2 -2
  2. package/dist/{app-config-CErnR6NK-6QjHJ7q5.mjs.map → app-config-CErnR6NK-DnKH4Kqc.mjs.map} +1 -1
  3. package/dist/app-configuration-file-CeJvBAti-Dk65W3Az.mjs +140 -0
  4. package/dist/app-configuration-file-CeJvBAti-Dk65W3Az.mjs.map +1 -0
  5. package/dist/{dev-current-BurA9uhA-BWYAftn9.mjs → dev-current-D0Kn6Mf4-DaV3DWR6.mjs} +5 -5
  6. package/dist/{dev-current-BurA9uhA-BWYAftn9.mjs.map → dev-current-D0Kn6Mf4-DaV3DWR6.mjs.map} +1 -1
  7. package/dist/{dev-environment-name-6eEr5PW8-YyPDRApO.mjs → dev-environment-name-6eEr5PW8-DpdGjmTb.mjs} +2 -2
  8. package/dist/dev-environment-name-6eEr5PW8-DpdGjmTb.mjs.map +1 -0
  9. package/dist/{dist-BsONwZNR.mjs → dist-DizJD76s.mjs} +2 -2
  10. package/dist/{dist-BsONwZNR.mjs.map → dist-DizJD76s.mjs.map} +1 -1
  11. package/dist/{execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs → execute-deploy-destroy-Dh1CQ9X6-XpXuMPxj.mjs} +58 -66
  12. package/dist/execute-deploy-destroy-Dh1CQ9X6-XpXuMPxj.mjs.map +1 -0
  13. package/dist/{execute-dev-4KYkqSMh-uh7gnPyS.mjs → execute-dev-Bl-5Q-Av-DK5AoRw1.mjs} +69 -41
  14. package/dist/{execute-dev-4KYkqSMh-uh7gnPyS.mjs.map → execute-dev-Bl-5Q-Av-DK5AoRw1.mjs.map} +1 -1
  15. package/dist/{execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs → execute-dev-current-D3USgHJ4-frlaz_BC.mjs} +6 -6
  16. package/dist/{execute-dev-current-Cd4YEUZk-b2L-LwbT.mjs.map → execute-dev-current-D3USgHJ4-frlaz_BC.mjs.map} +1 -1
  17. package/dist/family.d.mts +2 -2
  18. package/dist/family.mjs +8 -6
  19. package/dist/family.mjs.map +1 -1
  20. package/dist/{generate-dev-stack-DS6U_JHX-wDTViqdg.mjs → generate-dev-stack-Cag2Bd4s-CQLqIUWA.mjs} +11 -10
  21. package/dist/generate-dev-stack-Cag2Bd4s-CQLqIUWA.mjs.map +1 -0
  22. package/dist/{list-deployed-D5TBZvbj.mjs → list-deployed-DV6_IShe.mjs} +4 -4
  23. package/dist/{list-deployed-D5TBZvbj.mjs.map → list-deployed-DV6_IShe.mjs.map} +1 -1
  24. package/dist/{family-DACJfaA5-CBuEC2B3.d.mts → redaction-Bf8FvTFH-M5hYsi--.d.mts} +257 -175
  25. package/dist/redaction-Bf8FvTFH-M5hYsi--.d.mts.map +1 -0
  26. package/dist/redaction-HnbkSFrK-BjFRb2aC.mjs +534 -0
  27. package/dist/redaction-HnbkSFrK-BjFRb2aC.mjs.map +1 -0
  28. package/dist/{run-alchemy-B-Z6i3cD-f0MXFCG8.mjs → run-alchemy-OS_ix5g0-BzkuReFx.mjs} +29 -12
  29. package/dist/run-alchemy-OS_ix5g0-BzkuReFx.mjs.map +1 -0
  30. package/dist/testing.d.mts +31 -2
  31. package/dist/testing.d.mts.map +1 -1
  32. package/dist/testing.mjs +7 -4
  33. package/dist/testing.mjs.map +1 -1
  34. package/dist/{validate-environment-BNZC6W46-DY_7cPQJ.mjs → validate-environment-D_dECxgO-fg8lfCME.mjs} +902 -92
  35. package/dist/validate-environment-D_dECxgO-fg8lfCME.mjs.map +1 -0
  36. package/package.json +7 -7
  37. package/src/exports/testing.ts +3 -2
  38. package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs +0 -590
  39. package/dist/config-adapters-BA_IeiX0-CiRnz7z8.mjs.map +0 -1
  40. package/dist/dev-environment-name-6eEr5PW8-YyPDRApO.mjs.map +0 -1
  41. package/dist/execute-deploy-destroy-Cww6zOSC-CmOmzLiB.mjs.map +0 -1
  42. package/dist/family-DACJfaA5-CBuEC2B3.d.mts.map +0 -1
  43. package/dist/generate-dev-stack-DS6U_JHX-wDTViqdg.mjs.map +0 -1
  44. package/dist/run-alchemy-B-Z6i3cD-f0MXFCG8.mjs.map +0 -1
  45. package/dist/validate-environment-BNZC6W46-DY_7cPQJ.mjs.map +0 -1
@@ -1,11 +1,39 @@
1
- import { a as entryMissing, i as configFileMissing, n as environmentVariables, r as checkComposerConfig } from "./config-adapters-BA_IeiX0-CiRnz7z8.mjs";
1
+ import { d as configFileMissing, f as entryMissing, i as credentialLookingValues, l as valuesUnderSecretsKeys, n as SecretRedaction, u as checkComposerConfig } from "./redaction-HnbkSFrK-BjFRb2aC.mjs";
2
2
  import { a as InternalError, i as CliStructuredError, o as blindCast } from "./result-sR7PBi61.mjs";
3
3
  import * as mod from "node:module";
4
+ import { createRequire } from "node:module";
4
5
  import * as fs from "node:fs";
5
6
  import { existsSync } from "node:fs";
6
7
  import * as path from "node:path";
8
+ import "alchemy";
9
+ import "effect/Effect";
10
+ import "effect/Layer";
7
11
  import { fileURLToPath, pathToFileURL } from "node:url";
8
12
  import { spawnSync } from "node:child_process";
13
+ //#region \0rolldown/runtime.js
14
+ var __create = Object.create;
15
+ var __defProp = Object.defineProperty;
16
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
17
+ var __getOwnPropNames = Object.getOwnPropertyNames;
18
+ var __getProtoOf = Object.getPrototypeOf;
19
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
20
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
+ key = keys[i];
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
+ value: mod,
33
+ enumerable: true
34
+ }) : target, mod));
35
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
36
+ //#endregion
9
37
  //#region ../../0-framework/0-foundation/foundation/dist/describe-kind-Cpm_euxo.mjs
10
38
  /** How an error names the kind of a value it did not expect, without printing the value. */
11
39
  function describeKind(value) {
@@ -17,59 +45,646 @@ function describeKind(value) {
17
45
  return `a ${typeof value}`;
18
46
  }
19
47
  //#endregion
20
- //#region ../../0-framework/3-tooling/cli/dist/config-pools-DiYw7wMu.mjs
21
- function adapterInvalid(list, index, input, summary, fix) {
22
- return new CliStructuredError("CONFIG.ADAPTER_INVALID", summary, {
23
- fix,
24
- where: { path: input.configFile },
25
- meta: { field: `${list}[${index}]` }
26
- });
27
- }
28
- function isValues(value) {
29
- return typeof value === "object" && value !== null && !Array.isArray(value);
30
- }
31
- function isText(pool) {
32
- return Object.values(pool).every((value) => typeof value === "string");
33
- }
34
- async function readPool(list, adapters, input) {
35
- const adapterInput = Object.freeze({
36
- environment: input.environment,
37
- configDirectory: path.dirname(input.configFile)
38
- });
39
- const pool = Object.create(null);
40
- for (const [index, adapter] of adapters.entries()) {
41
- const field = `composer.${list}[${index}]`;
42
- let values;
48
+ //#region ../../../node_modules/dotenv-flow/node_modules/dotenv/package.json
49
+ var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
50
+ module.exports = {
51
+ "name": "dotenv",
52
+ "version": "16.6.1",
53
+ "description": "Loads environment variables from .env file",
54
+ "main": "lib/main.js",
55
+ "types": "lib/main.d.ts",
56
+ "exports": {
57
+ ".": {
58
+ "types": "./lib/main.d.ts",
59
+ "require": "./lib/main.js",
60
+ "default": "./lib/main.js"
61
+ },
62
+ "./config": "./config.js",
63
+ "./config.js": "./config.js",
64
+ "./lib/env-options": "./lib/env-options.js",
65
+ "./lib/env-options.js": "./lib/env-options.js",
66
+ "./lib/cli-options": "./lib/cli-options.js",
67
+ "./lib/cli-options.js": "./lib/cli-options.js",
68
+ "./package.json": "./package.json"
69
+ },
70
+ "scripts": {
71
+ "dts-check": "tsc --project tests/types/tsconfig.json",
72
+ "lint": "standard",
73
+ "pretest": "npm run lint && npm run dts-check",
74
+ "test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
75
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
76
+ "prerelease": "npm test",
77
+ "release": "standard-version"
78
+ },
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "git://github.com/motdotla/dotenv.git"
82
+ },
83
+ "homepage": "https://github.com/motdotla/dotenv#readme",
84
+ "funding": "https://dotenvx.com",
85
+ "keywords": [
86
+ "dotenv",
87
+ "env",
88
+ ".env",
89
+ "environment",
90
+ "variables",
91
+ "config",
92
+ "settings"
93
+ ],
94
+ "readmeFilename": "README.md",
95
+ "license": "BSD-2-Clause",
96
+ "devDependencies": {
97
+ "@types/node": "^18.11.3",
98
+ "decache": "^4.6.2",
99
+ "sinon": "^14.0.1",
100
+ "standard": "^17.0.0",
101
+ "standard-version": "^9.5.0",
102
+ "tap": "^19.2.0",
103
+ "typescript": "^4.8.4"
104
+ },
105
+ "engines": { "node": ">=12" },
106
+ "browser": { "fs": false }
107
+ };
108
+ }));
109
+ //#endregion
110
+ //#region ../../../node_modules/dotenv-flow/node_modules/dotenv/lib/main.js
111
+ var require_main = /* @__PURE__ */ __commonJSMin(((exports, module) => {
112
+ const fs$2 = __require("fs");
113
+ const path$1 = __require("path");
114
+ const os = __require("os");
115
+ const crypto = __require("crypto");
116
+ const version = require_package$1().version;
117
+ const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
118
+ function parse(src) {
119
+ const obj = {};
120
+ let lines = src.toString();
121
+ lines = lines.replace(/\r\n?/gm, "\n");
122
+ let match;
123
+ while ((match = LINE.exec(lines)) != null) {
124
+ const key = match[1];
125
+ let value = match[2] || "";
126
+ value = value.trim();
127
+ const maybeQuote = value[0];
128
+ value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
129
+ if (maybeQuote === "\"") {
130
+ value = value.replace(/\\n/g, "\n");
131
+ value = value.replace(/\\r/g, "\r");
132
+ }
133
+ obj[key] = value;
134
+ }
135
+ return obj;
136
+ }
137
+ function _parseVault(options) {
138
+ options = options || {};
139
+ const vaultPath = _vaultPath(options);
140
+ options.path = vaultPath;
141
+ const result = DotenvModule.configDotenv(options);
142
+ if (!result.parsed) {
143
+ const err = /* @__PURE__ */ new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
144
+ err.code = "MISSING_DATA";
145
+ throw err;
146
+ }
147
+ const keys = _dotenvKey(options).split(",");
148
+ const length = keys.length;
149
+ let decrypted;
150
+ for (let i = 0; i < length; i++) try {
151
+ const attrs = _instructions(result, keys[i].trim());
152
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
153
+ break;
154
+ } catch (error) {
155
+ if (i + 1 >= length) throw error;
156
+ }
157
+ return DotenvModule.parse(decrypted);
158
+ }
159
+ function _warn(message) {
160
+ console.log(`[dotenv@${version}][WARN] ${message}`);
161
+ }
162
+ function _debug(message) {
163
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
164
+ }
165
+ function _log(message) {
166
+ console.log(`[dotenv@${version}] ${message}`);
167
+ }
168
+ function _dotenvKey(options) {
169
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) return options.DOTENV_KEY;
170
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) return process.env.DOTENV_KEY;
171
+ return "";
172
+ }
173
+ function _instructions(result, dotenvKey) {
174
+ let uri;
43
175
  try {
44
- values = await adapter(adapterInput);
45
- } catch (thrown) {
46
- throw new CliStructuredError("CONFIG.ADAPTER_FAILED", `\`${field}\` failed to read the values for the environment "${input.environment}".`, {
47
- why: `It threw: ${thrown instanceof Error ? thrown.message : String(thrown)}`,
48
- fix: `Fix the adapter, or remove it from \`composer.${list}\` in prisma.config.ts.`,
49
- where: { path: input.configFile },
50
- meta: { field: `${list}[${index}]` },
51
- cause: thrown
176
+ uri = new URL(dotenvKey);
177
+ } catch (error) {
178
+ if (error.code === "ERR_INVALID_URL") {
179
+ 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");
180
+ err.code = "INVALID_DOTENV_KEY";
181
+ throw err;
182
+ }
183
+ throw error;
184
+ }
185
+ const key = uri.password;
186
+ if (!key) {
187
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing key part");
188
+ err.code = "INVALID_DOTENV_KEY";
189
+ throw err;
190
+ }
191
+ const environment = uri.searchParams.get("environment");
192
+ if (!environment) {
193
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing environment part");
194
+ err.code = "INVALID_DOTENV_KEY";
195
+ throw err;
196
+ }
197
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
198
+ const ciphertext = result.parsed[environmentKey];
199
+ if (!ciphertext) {
200
+ const err = /* @__PURE__ */ new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
201
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
202
+ throw err;
203
+ }
204
+ return {
205
+ ciphertext,
206
+ key
207
+ };
208
+ }
209
+ function _vaultPath(options) {
210
+ let possibleVaultPath = null;
211
+ if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
212
+ for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
213
+ } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
214
+ else possibleVaultPath = path$1.resolve(process.cwd(), ".env.vault");
215
+ if (fs$2.existsSync(possibleVaultPath)) return possibleVaultPath;
216
+ return null;
217
+ }
218
+ function _resolveHome(envPath) {
219
+ return envPath[0] === "~" ? path$1.join(os.homedir(), envPath.slice(1)) : envPath;
220
+ }
221
+ function _configVault(options) {
222
+ const debug = Boolean(options && options.debug);
223
+ const quiet = options && "quiet" in options ? options.quiet : true;
224
+ if (debug || !quiet) _log("Loading env from encrypted .env.vault");
225
+ const parsed = DotenvModule._parseVault(options);
226
+ let processEnv = process.env;
227
+ if (options && options.processEnv != null) processEnv = options.processEnv;
228
+ DotenvModule.populate(processEnv, parsed, options);
229
+ return { parsed };
230
+ }
231
+ function configDotenv(options) {
232
+ const dotenvPath = path$1.resolve(process.cwd(), ".env");
233
+ let encoding = "utf8";
234
+ const debug = Boolean(options && options.debug);
235
+ const quiet = options && "quiet" in options ? options.quiet : true;
236
+ if (options && options.encoding) encoding = options.encoding;
237
+ else if (debug) _debug("No encoding is specified. UTF-8 is used by default");
238
+ let optionPaths = [dotenvPath];
239
+ if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
240
+ else {
241
+ optionPaths = [];
242
+ for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
243
+ }
244
+ let lastError;
245
+ const parsedAll = {};
246
+ for (const path of optionPaths) try {
247
+ const parsed = DotenvModule.parse(fs$2.readFileSync(path, { encoding }));
248
+ DotenvModule.populate(parsedAll, parsed, options);
249
+ } catch (e) {
250
+ if (debug) _debug(`Failed to load ${path} ${e.message}`);
251
+ lastError = e;
252
+ }
253
+ let processEnv = process.env;
254
+ if (options && options.processEnv != null) processEnv = options.processEnv;
255
+ DotenvModule.populate(processEnv, parsedAll, options);
256
+ if (debug || !quiet) {
257
+ const keysCount = Object.keys(parsedAll).length;
258
+ const shortPaths = [];
259
+ for (const filePath of optionPaths) try {
260
+ const relative = path$1.relative(process.cwd(), filePath);
261
+ shortPaths.push(relative);
262
+ } catch (e) {
263
+ if (debug) _debug(`Failed to load ${filePath} ${e.message}`);
264
+ lastError = e;
265
+ }
266
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")}`);
267
+ }
268
+ if (lastError) return {
269
+ parsed: parsedAll,
270
+ error: lastError
271
+ };
272
+ else return { parsed: parsedAll };
273
+ }
274
+ function config(options) {
275
+ if (_dotenvKey(options).length === 0) return DotenvModule.configDotenv(options);
276
+ const vaultPath = _vaultPath(options);
277
+ if (!vaultPath) {
278
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
279
+ return DotenvModule.configDotenv(options);
280
+ }
281
+ return DotenvModule._configVault(options);
282
+ }
283
+ function decrypt(encrypted, keyStr) {
284
+ const key = Buffer.from(keyStr.slice(-64), "hex");
285
+ let ciphertext = Buffer.from(encrypted, "base64");
286
+ const nonce = ciphertext.subarray(0, 12);
287
+ const authTag = ciphertext.subarray(-16);
288
+ ciphertext = ciphertext.subarray(12, -16);
289
+ try {
290
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
291
+ aesgcm.setAuthTag(authTag);
292
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
293
+ } catch (error) {
294
+ const isRange = error instanceof RangeError;
295
+ const invalidKeyLength = error.message === "Invalid key length";
296
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
297
+ if (isRange || invalidKeyLength) {
298
+ const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
299
+ err.code = "INVALID_DOTENV_KEY";
300
+ throw err;
301
+ } else if (decryptionFailed) {
302
+ const err = /* @__PURE__ */ new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
303
+ err.code = "DECRYPTION_FAILED";
304
+ throw err;
305
+ } else throw error;
306
+ }
307
+ }
308
+ function populate(processEnv, parsed, options = {}) {
309
+ const debug = Boolean(options && options.debug);
310
+ const override = Boolean(options && options.override);
311
+ if (typeof parsed !== "object") {
312
+ const err = /* @__PURE__ */ new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
313
+ err.code = "OBJECT_REQUIRED";
314
+ throw err;
315
+ }
316
+ for (const key of Object.keys(parsed)) if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
317
+ if (override === true) processEnv[key] = parsed[key];
318
+ if (debug) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
319
+ else _debug(`"${key}" is already defined and was NOT overwritten`);
320
+ } else processEnv[key] = parsed[key];
321
+ }
322
+ const DotenvModule = {
323
+ configDotenv,
324
+ _configVault,
325
+ _parseVault,
326
+ config,
327
+ decrypt,
328
+ parse,
329
+ populate
330
+ };
331
+ module.exports.configDotenv = DotenvModule.configDotenv;
332
+ module.exports._configVault = DotenvModule._configVault;
333
+ module.exports._parseVault = DotenvModule._parseVault;
334
+ module.exports.config = DotenvModule.config;
335
+ module.exports.decrypt = DotenvModule.decrypt;
336
+ module.exports.parse = DotenvModule.parse;
337
+ module.exports.populate = DotenvModule.populate;
338
+ module.exports = DotenvModule;
339
+ }));
340
+ //#endregion
341
+ //#region ../../../node_modules/dotenv-flow/package.json
342
+ var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
343
+ module.exports = {
344
+ "name": "dotenv-flow",
345
+ "version": "4.1.0",
346
+ "description": "Loads environment variables from `.env.[development|test|production][.local]` files",
347
+ "keywords": [
348
+ "dotenv",
349
+ "node_env",
350
+ "development",
351
+ "test",
352
+ "production",
353
+ "local",
354
+ "env",
355
+ "environment",
356
+ "variables"
357
+ ],
358
+ "homepage": "https://github.com/kerimdzhanov/dotenv-flow#readme",
359
+ "repository": {
360
+ "type": "git",
361
+ "url": "git+https://github.com/kerimdzhanov/dotenv-flow.git"
362
+ },
363
+ "bugs": { "url": "https://github.com/kerimdzhanov/dotenv-flow/issues" },
364
+ "main": "lib/dotenv-flow.js",
365
+ "types": "lib/dotenv-flow.d.ts",
366
+ "exports": {
367
+ ".": "./lib/dotenv-flow.js",
368
+ "./config": {
369
+ "require": "./config.js",
370
+ "node": "./config.js"
371
+ },
372
+ "./package.json": "./package.json"
373
+ },
374
+ "files": [
375
+ "lib/cli-options.js",
376
+ "lib/dotenv-flow.d.ts",
377
+ "lib/env-options.js",
378
+ "config.d.ts",
379
+ "config.js"
380
+ ],
381
+ "dependencies": { "dotenv": "^16.0.0" },
382
+ "devDependencies": {
383
+ "@types/node": "^20.6.2",
384
+ "chai": "^4.3.7",
385
+ "conventional-changelog-cli": "^2.0.35",
386
+ "mocha": "^10.2.0",
387
+ "sinon": "^15.2.0",
388
+ "sinon-chai": "^3.7.0",
389
+ "tmp": "^0.2.1",
390
+ "typescript": "^5.2.2"
391
+ },
392
+ "engines": { "node": ">= 12.0.0" },
393
+ "scripts": {
394
+ "test": "yarn run test:unit && yarn run test:integration && yarn run test:types",
395
+ "test:unit": "mocha -r mocha.conf.js test/unit/*.spec.js",
396
+ "test:integration": "mocha -r mocha.conf.js test/integration/*.spec.{m,}js",
397
+ "test:types": "tsc",
398
+ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
399
+ },
400
+ "author": "Dan Kerimdzhanov",
401
+ "license": "MIT"
402
+ };
403
+ }));
404
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
405
+ const fs$1 = __require("fs");
406
+ const p = __require("path");
407
+ const dotenv = require_main();
408
+ const { version } = require_package();
409
+ const DEFAULT_PATTERN = ".env[.node_env][.local]";
410
+ const LOCAL_PLACEHOLDER_REGEX = /\[(\W*\blocal\b\W*)]/g;
411
+ const NODE_ENV_PLACEHOLDER_REGEX = /\[(\W*\b)node_env(\b\W*)]/g;
412
+ /**
413
+ * Compose a filename from a given `patten`.
414
+ *
415
+ * @param {string} pattern
416
+ * @param {object} [options]
417
+ * @param {boolean} [options.local]
418
+ * @param {string} [options.node_env]
419
+ * @return {string} filename
420
+ */
421
+ function composeFilename(pattern, options) {
422
+ let filename = pattern;
423
+ filename = filename.replace(LOCAL_PLACEHOLDER_REGEX, options && options.local ? "$1" : "");
424
+ filename = filename.replace(NODE_ENV_PLACEHOLDER_REGEX, options && options.node_env ? `$1${options.node_env}$2` : "");
425
+ return filename;
426
+ }
427
+ /**
428
+ * Returns a list of existing `.env*` filenames depending on the given `options`.
429
+ *
430
+ * The resulting list is ordered by the env files'
431
+ * variables overwriting priority from lowest to highest.
432
+ *
433
+ * This can also be referenced as "env files' environment cascade"
434
+ * or "order of ascending priority."
435
+ *
436
+ * ⚠️ Note that the `.env.local` file is not listed for "test" environment,
437
+ * since normally you expect tests to produce the same results for everyone.
438
+ *
439
+ * @param {object} [options] - `.env*` files listing options
440
+ * @param {string} [options.node_env] - node environment (development/test/production/etc.)
441
+ * @param {string} [options.path] - path to the working directory (default: `process.cwd()`)
442
+ * @param {string} [options.pattern] - `.env*` files' naming convention pattern
443
+ * (default: ".env[.node_env][.local]")
444
+ * @param {boolean} [options.debug] - turn on debug messages
445
+ * @return {string[]}
446
+ */
447
+ function listFiles(options = {}) {
448
+ options.debug && debug("listing effective `.env*` files…");
449
+ const { node_env, path = process.cwd(), pattern = DEFAULT_PATTERN } = options;
450
+ const hasLocalPlaceholder = LOCAL_PLACEHOLDER_REGEX.test(pattern);
451
+ const filenames = {};
452
+ if (pattern === DEFAULT_PATTERN) filenames[".env.defaults"] = ".env.defaults";
453
+ filenames[".env"] = composeFilename(pattern);
454
+ if (hasLocalPlaceholder) {
455
+ const envlocal = composeFilename(pattern, { local: true });
456
+ if (node_env !== "test") filenames[".env.local"] = envlocal;
457
+ else if (options.debug && fs$1.existsSync(p.resolve(path, envlocal))) debug("[!] note that `%s` is being skipped for \"test\" environment", envlocal);
458
+ }
459
+ if (node_env && NODE_ENV_PLACEHOLDER_REGEX.test(pattern)) {
460
+ filenames[".env.node_env"] = composeFilename(pattern, { node_env });
461
+ if (hasLocalPlaceholder) filenames[".env.node_env.local"] = composeFilename(pattern, {
462
+ node_env,
463
+ local: true
52
464
  });
53
465
  }
54
- if (typeof values === "function") throw adapterInvalid(list, index, input, `\`${field}\` returned a function, not an object of values.`, "An adapter factory was put in the list instead of the adapter it makes: write `dotenv()`, not `dotenv`.");
55
- if (!isValues(values)) throw adapterInvalid(list, index, input, `\`${field}\` returned ${describeKind(values)}, not an object of values.`, "Return an object whose keys are the names of the values, e.g. `{ EMAIL_FROM: 'shop@example.com' }`.");
56
- for (const [key, value] of Object.entries(values)) {
57
- if (value === void 0) continue;
58
- if (list === "secrets" && typeof value !== "string") throw adapterInvalid(list, index, input, `\`${field}\` returned ${describeKind(value)} for "${key}", but a secret is text.`, "Return the secret as a string. A platform variable holds text.");
59
- pool[key] = value;
466
+ return [
467
+ ".env.defaults",
468
+ ".env",
469
+ ".env.local",
470
+ ".env.node_env",
471
+ ".env.node_env.local"
472
+ ].reduce((list, basename) => {
473
+ if (!filenames[basename]) return list;
474
+ const filename = p.resolve(path, filenames[basename]);
475
+ if (fs$1.existsSync(filename)) {
476
+ options.debug && debug(">> %s", filename);
477
+ list.push(filename);
478
+ }
479
+ return list;
480
+ }, []);
481
+ }
482
+ /**
483
+ * Parses a given file or a list of files.
484
+ *
485
+ * When a list of filenames is given, the files will be parsed and merged in the same order as given.
486
+ *
487
+ * @param {string|string[]} filenames - filename or a list of filenames to parse and merge
488
+ * @param {{ encoding?: string, debug?: boolean }} [options] - parse options
489
+ * @return {Object<string, string>} the resulting map of `{ env_var: value }` as an object
490
+ */
491
+ function parse(filenames, options = {}) {
492
+ if (typeof filenames === "string") {
493
+ options.debug && debug("parsing \"%s\"…", filenames);
494
+ const parsed = dotenv.parse(fs$1.readFileSync(filenames, options.encoding && { encoding: options.encoding }));
495
+ if (options.debug) Object.keys(parsed).forEach((varname) => debug(">> %s", varname));
496
+ return parsed;
60
497
  }
498
+ return filenames.reduce((result, filename) => {
499
+ const parsed = parse(filename, options);
500
+ if (options.debug) Object.keys(parsed).filter((varname) => result.hasOwnProperty(varname)).forEach((varname) => debug("`%s` is being overwritten by merge from \"%s\"", varname, filename));
501
+ return Object.assign(result, parsed);
502
+ }, {});
61
503
  }
62
- return Object.freeze(pool);
63
- }
64
- /** Calls the section's `config` adapters (default `[environmentVariables()]`) and merges what they return: the config pool. */
65
- function readConfigPool(section, input) {
66
- return readPool("config", section.config ?? [environmentVariables()], input);
67
- }
68
- /** Calls the section's `secrets` adapters (default `[environmentVariables()]`) and merges what they return: the secrets pool. Every value must be text. */
69
- async function readSecretsPool(section, input) {
70
- const pool = await readPool("secrets", section.secrets ?? [environmentVariables()], input);
71
- if (!isText(pool)) throw new InternalError("readPool admitted a secret that is not text");
72
- return pool;
504
+ /**
505
+ * Parses variables defined in given file(s) and assigns them to `process.env`.
506
+ *
507
+ * Variables that are already defined in `process.env` will not be overwritten,
508
+ * thus giving a higher priority to environment variables predefined by the shell.
509
+ *
510
+ * If the loading is successful, an object with `parsed` property is returned.
511
+ * The `parsed` property contains parsed variables' `key => value` pairs merged in order using
512
+ * the "overwrite merge" strategy.
513
+ *
514
+ * If parsing fails for any of the given files, `process.env` is being left untouched,
515
+ * and an object with `error` property is returned.
516
+ * The `error` property, if present, references to the occurred error.
517
+ *
518
+ * @param {string|string[]} filenames - filename or a list of filenames to parse and merge
519
+ * @param {object} [options] - file loading options
520
+ * @param {string} [options.encoding="utf8"] - encoding of `.env*` files
521
+ * @param {boolean} [options.debug=false] - turn on debug messages
522
+ * @param {boolean} [options.silent=false] - suppress console errors and warnings
523
+ * @return {{ error: Error } | { parsed: Object<string, string> }}
524
+ */
525
+ function load(filenames, options = {}) {
526
+ try {
527
+ const parsed = parse(filenames, {
528
+ encoding: options.encoding,
529
+ debug: options.debug
530
+ });
531
+ options.debug && debug("safe-merging parsed environment variables into `process.env`…");
532
+ for (const varname of Object.keys(parsed)) if (!process.env.hasOwnProperty(varname)) {
533
+ options.debug && debug(">> process.env.%s", varname);
534
+ process.env[varname] = parsed[varname];
535
+ } else if (options.debug && process.env[varname] !== parsed[varname]) debug("environment variable `%s` is predefined and not being overwritten", varname);
536
+ return { parsed };
537
+ } catch (error) {
538
+ return failure(error, options);
539
+ }
540
+ }
541
+ /**
542
+ * Unload variables defined in a given file(s) from `process.env`.
543
+ *
544
+ * This function can gracefully resolve the following issue:
545
+ *
546
+ * In some cases, the original "dotenv" library can be used by one of the dependent npm modules.
547
+ * It causes calling the original `dotenv.config()` that loads the `.env` file from your project before you can call `dotenv-flow.config()`.
548
+ * Such cases break `.env*` files priority because the previously loaded environment variables are treated as shell-defined thus having a higher priority.
549
+ *
550
+ * Unloading the previously loaded `.env` file can be activated when using the `dotenv-flow.config()` with the `purge_dotenv` option set to `true`.
551
+ *
552
+ * @param {string|string[]} filenames - filename or a list of filenames to unload
553
+ * @param {object} [options] - `fs.readFileSync` options
554
+ */
555
+ function unload(filenames, options = {}) {
556
+ const parsed = parse(filenames, options);
557
+ Object.keys(parsed).forEach((key) => {
558
+ if (process.env[key] === parsed[key]) delete process.env[key];
559
+ });
560
+ }
561
+ /**
562
+ * Returns effective (computed) `node_env`.
563
+ *
564
+ * @param {object} [options]
565
+ * @param {string} [options.node_env]
566
+ * @param {string} [options.default_node_env]
567
+ * @param {boolean} [options.debug]
568
+ * @return {string|undefined} node_env
569
+ */
570
+ function getEffectiveNodeEnv(options = {}) {
571
+ if (options.node_env) {
572
+ options.debug && debug(`operating in "${options.node_env}" environment (set by \`options.node_env\`)`);
573
+ return options.node_env;
574
+ }
575
+ if (process.env.NODE_ENV) {
576
+ options.debug && debug(`operating in "${process.env.NODE_ENV}" environment (as per \`process.env.NODE_ENV\`)`);
577
+ return process.env.NODE_ENV;
578
+ }
579
+ if (options.default_node_env) {
580
+ options.debug && debug(`operating in "${options.default_node_env}" environment (taken from \`options.default_node_env\`)`);
581
+ return options.default_node_env;
582
+ }
583
+ options.debug && debug("operating in \"no environment\" mode (no environment-related options are set)");
584
+ }
585
+ const CONFIG_OPTION_KEYS = [
586
+ "node_env",
587
+ "default_node_env",
588
+ "path",
589
+ "pattern",
590
+ "files",
591
+ "encoding",
592
+ "purge_dotenv",
593
+ "silent"
594
+ ];
595
+ /**
596
+ * "dotenv-flow" initialization function (API entry point).
597
+ *
598
+ * Allows configuring dotenv-flow programmatically.
599
+ *
600
+ * @param {object} [options] - configuration options
601
+ * @param {string} [options.node_env=process.env.NODE_ENV] - node environment (development/test/production/etc.)
602
+ * @param {string} [options.default_node_env] - the default node environment
603
+ * @param {string} [options.path=process.cwd()] - path to `.env*` files directory
604
+ * @param {string} [options.pattern=".env[.node_env][.local]"] - `.env*` files' naming convention pattern
605
+ * @param {string[]} [options.files] - an explicit list of `.env*` files to load (note that `options.[default_]node_env` and `options.pattern` are ignored in this case)
606
+ * @param {string} [options.encoding="utf8"] - encoding of `.env*` files
607
+ * @param {boolean} [options.purge_dotenv=false] - perform the `.env` file {@link unload}
608
+ * @param {boolean} [options.debug=false] - turn on detailed logging to help debug why certain variables are not being set as you expect
609
+ * @param {boolean} [options.silent=false] - suppress all kinds of warnings including ".env*" files' loading errors
610
+ * @return {{ parsed?: object, error?: Error }} with a `parsed` key containing the loaded content or an `error` key with an error that is occurred
611
+ */
612
+ function config(options = {}) {
613
+ if (options.debug) {
614
+ debug("initializing…");
615
+ CONFIG_OPTION_KEYS.filter((key) => key in options).forEach((key) => debug(`| options.${key} =`, options[key]));
616
+ }
617
+ const { path = process.cwd(), pattern = DEFAULT_PATTERN } = options;
618
+ if (options.purge_dotenv) {
619
+ options.debug && debug("`options.purge_dotenv` is enabled, unloading potentially pre-loaded `.env`…");
620
+ const dotenvFile = p.resolve(path, ".env");
621
+ try {
622
+ fs$1.existsSync(dotenvFile) && unload(dotenvFile, { encoding: options.encoding });
623
+ } catch (error) {
624
+ !options.silent && warn("unloading failed: ", error);
625
+ }
626
+ }
627
+ try {
628
+ let filenames;
629
+ if (options.files) {
630
+ options.debug && debug("using explicit list of `.env*` files: %s…", options.files.join(", "));
631
+ filenames = options.files.reduce((list, basename) => {
632
+ const filename = p.resolve(path, basename);
633
+ if (fs$1.existsSync(filename)) list.push(filename);
634
+ else if (options.debug) debug(">> %s does not exist, skipping…", filename);
635
+ return list;
636
+ }, []);
637
+ } else {
638
+ const node_env = getEffectiveNodeEnv(options);
639
+ filenames = listFiles({
640
+ node_env,
641
+ path,
642
+ pattern,
643
+ debug: options.debug
644
+ });
645
+ if (filenames.length === 0) {
646
+ const _pattern = node_env ? pattern.replace(NODE_ENV_PLACEHOLDER_REGEX, `[$1${node_env}$2]`) : pattern;
647
+ return failure(/* @__PURE__ */ new Error(`no ".env*" files matching pattern "${_pattern}" in "${path}" dir`), options);
648
+ }
649
+ }
650
+ const result = load(filenames, {
651
+ encoding: options.encoding,
652
+ debug: options.debug,
653
+ silent: options.silent
654
+ });
655
+ options.debug && debug("initialization completed.");
656
+ return result;
657
+ } catch (error) {
658
+ return failure(error, options);
659
+ }
660
+ }
661
+ function failure(error, options) {
662
+ if (!options.silent) warn(`".env*" files loading failed: ${error.message || error}`);
663
+ return { error };
664
+ }
665
+ function warn(message, error) {
666
+ if (error) message += ": %s";
667
+ console.warn(`[dotenv-flow@${version}]: ${message}`, error);
668
+ }
669
+ function debug(message, ...values) {
670
+ console.debug(`[dotenv-flow@${version}]: ${message}`, ...values);
671
+ }
672
+ module.exports = {
673
+ DEFAULT_PATTERN,
674
+ listFiles,
675
+ parse,
676
+ load,
677
+ unload,
678
+ config
679
+ };
680
+ })))();
681
+ /** Reads the process environment when called: every variable whose value is a string. The default for both `config` and `secrets`. */
682
+ function environmentVariables() {
683
+ return () => {
684
+ const values = {};
685
+ for (const [name, value] of Object.entries(process.env)) if (typeof value === "string") values[name] = value;
686
+ return values;
687
+ };
73
688
  }
74
689
  //#endregion
75
690
  //#region ../../0-framework/3-tooling/assemble/dist/index.mjs
@@ -191,7 +806,7 @@ function isSecretString(value) {
191
806
  return typeof value === "object" && value !== null && blindCast(value)[SECRET_BOX] === true;
192
807
  }
193
808
  //#endregion
194
- //#region ../../0-framework/1-core/core/dist/graph-gE31_ToO.mjs
809
+ //#region ../../0-framework/1-core/core/dist/graph-Bqr7PSGl.mjs
195
810
  /** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
196
811
  const RESOURCE_OUT_PORT = "$out";
197
812
  /**
@@ -240,6 +855,7 @@ function inputFieldLabel(origin) {
240
855
  return origin.path.length === 0 ? "input" : `input.${origin.path.join(".")}`;
241
856
  }
242
857
  function misuse(origin, what) {
858
+ if (origin.path.length === 0) return new LoadError(`input of module "${origin.module}" is a dictionary of values, not data, and ${what}. A module body can only pass the fields of its input on, by name: into a provision() binding or, for a plain field, as a resolve() dependency.`);
243
859
  const field = inputFieldLabel(origin);
244
860
  return new LoadError(`${field} of module "${origin.module}" is a value, not its real value, and ${what}. A module body can only pass an input field on: into a provision() binding or as a resolve() dependency. To compute with it, it must be a plain field, not a wrapped or secret one; list it: resolve([${field}], ([v]) => …).`);
245
861
  }
@@ -255,7 +871,9 @@ function primitiveMisuse(hint) {
255
871
  * Builds the `input` a module body receives. Every property access returns a
256
872
  * value recording its key path, and the same path always returns the same
257
873
  * object, so Load's identity-keyed maps see one value per field. Any way of
258
- * reading the real value throws a LoadError naming the field.
874
+ * reading the real value throws a LoadError naming the field. At run time the
875
+ * whole input still answers the value brand, at path `[]`, so Load can find
876
+ * and refuse it wherever it is passed on.
259
877
  */
260
878
  function buildModuleInput(moduleAddress) {
261
879
  const byPath = /* @__PURE__ */ new Map();
@@ -499,7 +1117,11 @@ function loadService(root, rootId) {
499
1117
  authoredEdges: [],
500
1118
  inputBindings: [],
501
1119
  params: [],
502
- secretSources: []
1120
+ secretSources: [],
1121
+ appConfigurationRead: {
1122
+ rootInput: [],
1123
+ configurationKeyText: {}
1124
+ }
503
1125
  };
504
1126
  }
505
1127
  function joinPath(path, key) {
@@ -552,6 +1174,29 @@ function describeNotPlain(value) {
552
1174
  default: return;
553
1175
  }
554
1176
  }
1177
+ /** How `value` would not survive `JSON.stringify` and `JSON.parse` unchanged, or `undefined` when it would. A key whose value is `undefined` is dropped, which a body cannot tell from absent. */
1178
+ function jsonInexactKind(value) {
1179
+ if (value === null || typeof value === "string" || typeof value === "boolean") return void 0;
1180
+ if (typeof value === "number") return Number.isFinite(value) ? void 0 : "a non-finite number";
1181
+ if (Array.isArray(value)) {
1182
+ for (const member of value) {
1183
+ if (member === void 0) return "an array with a missing member";
1184
+ const kind = jsonInexactKind(member);
1185
+ if (kind !== void 0) return kind;
1186
+ }
1187
+ return;
1188
+ }
1189
+ if (isPlainObject(value)) {
1190
+ for (const member of Object.values(value)) {
1191
+ if (member === void 0) continue;
1192
+ const kind = jsonInexactKind(member);
1193
+ if (kind !== void 0) return kind;
1194
+ }
1195
+ return;
1196
+ }
1197
+ return describeNotPlain(value) ?? describeKind(value);
1198
+ }
1199
+ const SAME_GRAPH_ADVICE = "A module body must build the same graph every time; one that reads the process environment, a file or the clock can build a different one.";
555
1200
  function isThenable(value) {
556
1201
  if (isValue(value)) return false;
557
1202
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
@@ -674,8 +1319,12 @@ function readPath(data, origin) {
674
1319
  ...origin,
675
1320
  path: origin.path.slice(0, index)
676
1321
  });
677
- if (isSecretSource(current) || isParamSource(current)) throw new LoadError(`${missing}: ${parent} stands for a value only the platform has at boot, so it has no fields and can only be passed on unchanged.`);
678
- if (!isPlainObject(current)) throw new LoadError(`${missing}: ${parent} is ${describeData(current)}, not a plain object, so it has no fields. To compute with it, it must be a plain field, not a wrapped or secret one; list it: resolve([${parent}], ([v]) => …).`);
1322
+ const schemaAdvice = `The module's input schema must output a plain object for its body to read fields.`;
1323
+ if (isSecretSource(current) || isParamSource(current)) throw new LoadError(`${missing}: ${parent} stands for a value only the platform has at boot, so it has no fields` + (index === 0 ? `. ${schemaAdvice}` : " and can only be passed on unchanged."));
1324
+ if (!isPlainObject(current)) {
1325
+ const advice = index === 0 ? schemaAdvice : `To compute with it, it must be a plain field, not a wrapped or secret one; list it: resolve([${parent}], ([v]) => …).`;
1326
+ throw new LoadError(`${missing}: ${parent} is ${describeData(current)}, not a plain object, so it has no fields. ${advice}`);
1327
+ }
679
1328
  if (!Object.hasOwn(current, key)) return void 0;
680
1329
  current = current[key];
681
1330
  }
@@ -708,7 +1357,7 @@ function validateModuleInput(entry, resolved, environment) {
708
1357
  if (result instanceof Promise) throw new LoadError(`The input schema of module "${address}" returned a Promise from validate(). A module's input is validated synchronously at Load; use a schema with no asynchronous checks.`);
709
1358
  if (result.issues !== void 0) {
710
1359
  const messages = result.issues.map((issue) => issue.message).join("; ");
711
- if (entry.fromConfigPool) throw new LoadError(`The input of root module "${address}" does not match its input schema: ${messages}. A root's input is the values the \`config\` adapters in prisma.config.ts return${environment === void 0 ? "" : ` for the environment "${environment.name}"`}.`);
1360
+ if (entry.isRoot) throw new LoadError(`The input of root module "${address}" does not match its input schema: ${messages}. A root's input is the values the \`config\` adapters in prisma.config.ts return${environment === void 0 ? "" : ` for the environment "${environment.name}"`}.`);
712
1361
  throw new LoadError(`The input binding of module "${address}" does not match the module's input schema: ${messages}`);
713
1362
  }
714
1363
  const bound = sourcesByPath(resolved);
@@ -755,7 +1404,23 @@ function refusePointersInProps(address, props) {
755
1404
  * returns each binding with its values replaced by their real values.
756
1405
  */
757
1406
  function resolveValues(input) {
758
- const { environment, configPool } = input;
1407
+ const { environment } = input;
1408
+ const rootFields = /* @__PURE__ */ new Map();
1409
+ const keysRead = /* @__PURE__ */ new Map();
1410
+ /** The text the app configuration holds for `key`, recorded; `undefined` when it holds none or `''`. */
1411
+ const configurationText = (key, label, site) => {
1412
+ let raw;
1413
+ if (input.appConfigurationRead !== void 0) raw = input.appConfigurationRead.configurationKeyText[key];
1414
+ else if (input.configuration !== void 0) raw = input.configuration[key];
1415
+ else throw new LoadError(`${describeSite(site)} depends on ${label}, but Load was given no app configuration to read "${key}" from. Pass { configuration } to Load; the deploy and dev commands pass the values the \`config\` adapters return.`);
1416
+ if (raw !== void 0 && raw !== "" && typeof raw !== "string") throw new LoadError(`${describeSite(site)} depends on ${label}, which reads "${key}" from the values the \`config\` adapters return, but they return ${describeKind(raw)} for it, not text. ${label} reads text; to pass other data, declare it in the root module's input.`);
1417
+ const text = raw === void 0 || raw === "" ? void 0 : raw;
1418
+ keysRead.set(key, {
1419
+ label,
1420
+ text
1421
+ });
1422
+ return text;
1423
+ };
759
1424
  const secretUses = /* @__PURE__ */ new Map();
760
1425
  const recordSecret = (source, site) => {
761
1426
  const canonical = canonicalSecret(source);
@@ -817,20 +1482,14 @@ function resolveValues(input) {
817
1482
  break;
818
1483
  case "source":
819
1484
  if (isSecretSource(origin.source)) recordSecret(origin.source, site);
820
- if (origin.poolKey === void 0) result = origin.source;
821
- else if (configPool === void 0) throw new LoadError(`${describeSite(site)} depends on ${origin.label}, but Load was given no values from the \`config\` adapters to read "${origin.poolKey}" from. Pass { configPool } to Load; the deploy and dev commands pass the values the \`config\` adapters return.`);
822
- else {
823
- const raw = configPool[origin.poolKey];
824
- if (raw === void 0 || raw === "") result = void 0;
825
- else if (typeof raw === "string") result = raw;
826
- else throw new LoadError(`${describeSite(site)} depends on ${origin.label}, which reads "${origin.poolKey}" from the values the \`config\` adapters return, but they return ${describeKind(raw)} for it, not text. ${origin.label} reads text; to pass other data, declare it in the root module's input.`);
827
- }
1485
+ if (origin.sourceKind === "secret" || origin.configurationKey === void 0) result = origin.source;
1486
+ else result = configurationText(origin.configurationKey, origin.label, site);
828
1487
  break;
829
1488
  case "computed": {
830
1489
  const args = origin.dependencies.map((dependency) => {
831
1490
  const real = resolveOne(dependency, site);
832
1491
  const source = originOf(dependency);
833
- if (real === void 0 && source.kind === "source") throw new LoadError(`${fnLabelFor(site)} lists ${source.label}, but "${source.poolKey}" is unset or empty, so it has no real value. Set "${source.poolKey}", or bind ${source.label} directly into an input binding, where an absent value leaves the key out and the schema decides.`);
1492
+ if (real === void 0 && source.kind === "source" && source.sourceKind === "param") throw new LoadError(`${fnLabelFor(site)} lists ${source.label}, but "${source.configurationKey}" is unset or empty, so it has no real value. Set "${source.configurationKey}", or bind ${source.label} directly into an input binding, where an absent value leaves the key out and the schema decides.`);
834
1493
  refusePointerDependency(fnLabelFor(site), dependency, real);
835
1494
  return real;
836
1495
  });
@@ -847,8 +1506,21 @@ function resolveValues(input) {
847
1506
  case "input": {
848
1507
  const entry = moduleInputByAddress.get(origin.module);
849
1508
  if (entry === void 0) throw new LoadError(`${describeSite(site)} depends on ${inputFieldLabel(origin)} of module "${origin.module}", which this Load does not provision. An input field can be passed on only inside the body of the module that received it.`);
850
- if (entry.fromConfigPool && origin.path.length === 0) throw new LoadError(`${describeSite(site)} depends on the whole input of root module "${origin.module}". The root's input is every value the \`config\` adapters return, which by default is every variable of the process environment, secrets included. Pass on the fields the root declares one by one, such as input.EMAIL_FROM.`);
851
- result = readPath(validatedInputOf(entry), origin);
1509
+ if (origin.path.length === 0) {
1510
+ const everyVariable = entry.isRoot ? " The root's input is every value the `config` adapters return, which by default is every variable of the process environment, secrets included." : "";
1511
+ throw new LoadError(`${describeSite(site)} depends on the whole input of module "${origin.module}". A module body's input is a dictionary of values, not a value, so it cannot be passed on whole.${everyVariable} Pass its fields on by name, such as input.from.`);
1512
+ }
1513
+ if (entry.checked !== void 0) {
1514
+ const field = entry.checked.find((candidate) => candidate.path.join("\0") === origin.path.join("\0"));
1515
+ if (field === void 0) throw new LoadError(`${inputFieldLabel(origin)} of root module "${origin.module}" is not in the app configuration file. The first process's root body did not pass it on, so the deploy's two processes built different graphs. ${SAME_GRAPH_ADVICE}`);
1516
+ result = field.value;
1517
+ } else {
1518
+ result = readPath(validatedInputOf(entry), origin);
1519
+ if (entry.isRoot) rootFields.set(origin.path.join("\0"), result === void 0 ? { path: origin.path } : {
1520
+ path: origin.path,
1521
+ value: result
1522
+ });
1523
+ }
852
1524
  break;
853
1525
  }
854
1526
  }
@@ -857,6 +1529,7 @@ function resolveValues(input) {
857
1529
  return result;
858
1530
  };
859
1531
  const validatedInputOf = (entry) => {
1532
+ if (entry.checked !== void 0) return void 0;
860
1533
  if (validatedInputs.has(entry.moduleAddress)) return validatedInputs.get(entry.moduleAddress);
861
1534
  if (validating.has(entry.moduleAddress)) throw new LoadError(`The input binding of module "${entry.moduleAddress}" depends on that module's own input. Remove the cycle.`);
862
1535
  validating.add(entry.moduleAddress);
@@ -873,16 +1546,70 @@ function resolveValues(input) {
873
1546
  validatedInputs.set(entry.moduleAddress, validated);
874
1547
  return validated;
875
1548
  };
1549
+ const rootModuleAddress = () => input.moduleInputs.find((entry) => entry.isRoot)?.moduleAddress ?? "";
1550
+ const appConfigurationReadOf = (inputBindings, params, secretSources) => {
1551
+ if (input.configuration !== void 0 || input.appConfigurationRead !== void 0) {
1552
+ const kept = [...inputBindings.map(({ serviceAddress, binding }) => ({
1553
+ binding,
1554
+ site: {
1555
+ address: serviceAddress,
1556
+ kind: "serviceInput",
1557
+ path: ""
1558
+ }
1559
+ })), ...params.map(({ serviceAddress, slot, binding }) => ({
1560
+ binding,
1561
+ site: {
1562
+ address: serviceAddress,
1563
+ kind: "param",
1564
+ path: slot
1565
+ }
1566
+ }))];
1567
+ for (const { binding, site } of kept) for (const pointer of pointersIn(binding)) {
1568
+ if (!isParamSource(pointer)) continue;
1569
+ const origin = sourceOriginOf(pointer);
1570
+ if (origin?.sourceKind === "param" && origin.configurationKey !== void 0) configurationText(origin.configurationKey, origin.label, site);
1571
+ }
1572
+ }
1573
+ for (const use of secretSources) {
1574
+ const origin = sourceOriginOf(use.source);
1575
+ if (origin?.sourceKind !== "secret") continue;
1576
+ const key = origin.secretsKey;
1577
+ const read = key === void 0 ? void 0 : keysRead.get(key);
1578
+ if (key !== void 0 && read !== void 0) throw new LoadError(`${read.label} reads "${key}" from the app configuration, and ${origin.label} names "${key}" as a secret. A name is a plain value or a secret, not both: Composer hands the deploy's second process every plain value it reads, in a file, and never writes a secret to a file. Give the plain value and the secret different names.`);
1579
+ const field = [...rootFields.values()].find((candidate) => candidate.path[0] === key);
1580
+ if (key !== void 0 && field !== void 0) throw new LoadError(`${inputFieldLabel({
1581
+ kind: "input",
1582
+ module: rootModuleAddress(),
1583
+ path: field.path
1584
+ })} of root module "${rootModuleAddress()}" reads "${key}" from the app configuration, and ${origin.label} names "${key}" as a secret. A name is a plain value or a secret, not both: Composer hands the deploy's second process every root input field the root's body passes on, in a file, and never writes a secret to a file. Read the secret with ${origin.label} only, or give the plain value a different name.`);
1585
+ }
1586
+ for (const field of rootFields.values()) {
1587
+ const kind = "value" in field ? jsonInexactKind(field.value) : void 0;
1588
+ if (kind !== void 0) throw new LoadError(`${inputFieldLabel({
1589
+ kind: "input",
1590
+ module: rootModuleAddress(),
1591
+ path: field.path
1592
+ })} of root module "${rootModuleAddress()}" holds ${kind}, which JSON cannot hold exactly. The deploy hands the root's input to its second process in a JSON file, so a field the root's body passes on must hold text, a finite number, a boolean, null, or arrays and plain objects of these.`);
1593
+ }
1594
+ const configurationKeyText = {};
1595
+ for (const [key, { text }] of keysRead) if (text !== void 0) configurationKeyText[key] = text;
1596
+ return {
1597
+ rootInput: [...rootFields.values()],
1598
+ configurationKeyText
1599
+ };
1600
+ };
876
1601
  for (const entry of input.moduleInputs) validatedInputOf(entry);
877
1602
  for (const { value, site } of found) resolveOne(value, site);
878
1603
  const authoredProps = new Map([...input.resources].map(([address, resource]) => [address, resource.props]));
879
1604
  if (found.length === 0) {
880
1605
  for (const [address, props] of authoredProps) refusePointersInProps(address, props);
1606
+ const secretSources = secretSourcesReceivedBy(input.inputBindings, input.params);
881
1607
  return {
882
1608
  inputBindings: input.inputBindings,
883
1609
  params: input.params,
884
1610
  resourceProps: authoredProps,
885
- secretSources: secretSourcesReceivedBy(input.inputBindings, input.params)
1611
+ secretSources,
1612
+ appConfigurationRead: appConfigurationReadOf(input.inputBindings, input.params, secretSources)
886
1613
  };
887
1614
  }
888
1615
  const inProgress = /* @__PURE__ */ new WeakSet();
@@ -908,11 +1635,13 @@ function resolveValues(input) {
908
1635
  binding
909
1636
  }];
910
1637
  });
1638
+ const secretSources = secretSourcesReceivedBy(inputBindings, params);
911
1639
  return {
912
1640
  resourceProps,
913
1641
  inputBindings,
914
1642
  params,
915
- secretSources: secretSourcesReceivedBy(inputBindings, params)
1643
+ secretSources,
1644
+ appConfigurationRead: appConfigurationReadOf(inputBindings, params, secretSources)
916
1645
  };
917
1646
  }
918
1647
  /**
@@ -1157,7 +1886,7 @@ function flatten(moduleNode, selfId, wiring, nodes, edges, pending, inputBinding
1157
1886
  if (child.inputSchema === void 0 && provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding, but the service declares no input schema (module "${moduleNode.name}").`);
1158
1887
  if (provisionInput !== void 0) inputBindings.push({
1159
1888
  serviceAddress: fullAddress,
1160
- binding: blindCast(provisionInput)
1889
+ binding: provisionInput
1161
1890
  });
1162
1891
  validateServiceParamBinding(child, id, localParams, moduleNode.name);
1163
1892
  for (const [slot, binding] of Object.entries(localParams)) paramBindings.push({
@@ -1193,7 +1922,7 @@ function flatten(moduleNode, selfId, wiring, nodes, edges, pending, inputBinding
1193
1922
  moduleAddress: fullAddress,
1194
1923
  schema: childInputSchema,
1195
1924
  binding: provisionInput,
1196
- fromConfigPool: false
1925
+ isRoot: false
1197
1926
  });
1198
1927
  edges.push(...wiringEdges(localWiring, fullAddress));
1199
1928
  recordAuthoredWiring(fullAddress, localWiring);
@@ -1257,16 +1986,22 @@ function loadModule(root, opts) {
1257
1986
  const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
1258
1987
  throw new LoadError(`Module "${root.name}" declares ${rootDepKeys.length > 1 ? "dependencies" : "dependency"} ${names} but is being deployed as the root — a root has no enclosing scope to wire them; compose "${root.name}" from another module that provisions and wires it instead.`);
1259
1988
  }
1989
+ if (opts?.configuration !== void 0 && opts.appConfigurationRead !== void 0) throw new LoadError("Load takes configuration, in the first process, or appConfigurationRead, in the second, not both.");
1260
1990
  const moduleInputs = [];
1261
- if (root.inputSchema !== void 0) {
1262
- if (opts?.configPool === void 0) throw new LoadError(`Module "${root.name}" declares input and is being deployed as the root, but Load was given no values from the \`config\` adapters to fill it from. Pass { configPool } to Load; prisma deploy and prisma dev pass the values the \`config\` adapters return.`);
1263
- moduleInputs.push({
1264
- moduleAddress: rootId,
1265
- schema: root.inputSchema,
1266
- binding: opts.configPool,
1267
- fromConfigPool: true
1268
- });
1269
- }
1991
+ if (root.inputSchema !== void 0) if (opts?.appConfigurationRead !== void 0) moduleInputs.push({
1992
+ moduleAddress: rootId,
1993
+ schema: root.inputSchema,
1994
+ binding: void 0,
1995
+ isRoot: true,
1996
+ checked: opts.appConfigurationRead.rootInput
1997
+ });
1998
+ else if (opts?.configuration !== void 0) moduleInputs.push({
1999
+ moduleAddress: rootId,
2000
+ schema: root.inputSchema,
2001
+ binding: opts.configuration,
2002
+ isRoot: true
2003
+ });
2004
+ else throw new LoadError(`Module "${root.name}" declares input and is being deployed as the root, but Load was given no app configuration to fill it from. Pass { configuration } to Load; prisma deploy and prisma dev pass the values the \`config\` adapters return.`);
1270
2005
  const nodes = [];
1271
2006
  const edges = [];
1272
2007
  const pending = [];
@@ -1287,7 +2022,8 @@ function loadModule(root, opts) {
1287
2022
  for (const [address, node] of byId) if (node.kind === "resource") resources.set(address, node);
1288
2023
  const resolved = resolveValues({
1289
2024
  environment: opts?.environment,
1290
- configPool: opts?.configPool,
2025
+ configuration: opts?.configuration,
2026
+ appConfigurationRead: opts?.appConfigurationRead,
1291
2027
  inputBindings,
1292
2028
  params: paramBindings,
1293
2029
  moduleInputs,
@@ -1314,7 +2050,8 @@ function loadModule(root, opts) {
1314
2050
  authoredEdges,
1315
2051
  inputBindings: resolved.inputBindings,
1316
2052
  params: resolved.params,
1317
- secretSources: resolved.secretSources
2053
+ secretSources: resolved.secretSources,
2054
+ appConfigurationRead: resolved.appConfigurationRead
1318
2055
  };
1319
2056
  }
1320
2057
  /**
@@ -1386,8 +2123,79 @@ function Load(root, opts) {
1386
2123
  if (root.kind === "service") return loadService(root, opts?.id ?? "root");
1387
2124
  throw new LoadError("Load expects a service or module root (received another node kind).");
1388
2125
  }
2126
+ /** The app secrets key of every secret source the graph names, once each, in the order Load met them. A source built without a `secretsKey` is left out. */
2127
+ function secretsKeys(graph) {
2128
+ const keys = /* @__PURE__ */ new Set();
2129
+ for (const { source } of graph.secretSources) {
2130
+ const origin = sourceOriginOf(source);
2131
+ const key = origin?.sourceKind === "secret" ? origin.secretsKey : void 0;
2132
+ if (key !== void 0) keys.add(key);
2133
+ }
2134
+ return [...keys];
2135
+ }
2136
+ /** The address of every node in the graph, sorted. Two Loads of the same graph give the same list. */
2137
+ function nodeAddresses(graph) {
2138
+ return graph.nodes.map(({ id }) => id).sort();
2139
+ }
1389
2140
  //#endregion
1390
- //#region ../../0-framework/3-tooling/cli/dist/validate-environment-BNZC6W46.mjs
2141
+ //#region ../../0-framework/3-tooling/cli/dist/validate-environment-D_dECxgO.mjs
2142
+ function adapterInvalid(list, index, input, summary, fix) {
2143
+ return new CliStructuredError("CONFIG.ADAPTER_INVALID", summary, {
2144
+ fix,
2145
+ where: { path: input.configFile },
2146
+ meta: { field: `${list}[${index}]` }
2147
+ });
2148
+ }
2149
+ function isValues(value) {
2150
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2151
+ }
2152
+ function isText(values) {
2153
+ return Object.values(values).every((value) => typeof value === "string");
2154
+ }
2155
+ async function readAdapters(list, adapters, input) {
2156
+ const adapterInput = Object.freeze({
2157
+ environment: input.environment,
2158
+ configDirectory: path.dirname(input.configFile)
2159
+ });
2160
+ const merged = Object.create(null);
2161
+ for (const [index, adapter] of adapters.entries()) {
2162
+ const field = `composer.${list}[${index}]`;
2163
+ let values;
2164
+ try {
2165
+ values = await adapter(adapterInput);
2166
+ } catch (thrown) {
2167
+ throw new CliStructuredError("CONFIG.ADAPTER_FAILED", `\`${field}\` failed to read the values for the environment "${input.environment}".`, {
2168
+ why: `It threw: ${thrown instanceof Error ? thrown.message : String(thrown)}`,
2169
+ fix: `Fix the adapter, or remove it from \`composer.${list}\` in prisma.config.ts.`,
2170
+ where: { path: input.configFile },
2171
+ meta: { field: `${list}[${index}]` },
2172
+ cause: thrown
2173
+ });
2174
+ }
2175
+ if (typeof values === "function") throw adapterInvalid(list, index, input, `\`${field}\` returned a function, not an object of values.`, "An adapter factory was put in the list instead of the adapter it makes: write `dotenv()`, not `dotenv`.");
2176
+ if (!isValues(values)) throw adapterInvalid(list, index, input, `\`${field}\` returned ${describeKind(values)}, not an object of values.`, "Return an object whose keys are the names of the values, e.g. `{ EMAIL_FROM: 'shop@example.com' }`.");
2177
+ for (const [key, value] of Object.entries(values)) {
2178
+ if (value === void 0) continue;
2179
+ if (list === "secrets" && typeof value !== "string") throw adapterInvalid(list, index, input, `\`${field}\` returned ${describeKind(value)} for "${key}", but a secret is text.`, "Return the secret as a string. A platform variable holds text.");
2180
+ merged[key] = value;
2181
+ }
2182
+ }
2183
+ return Object.freeze(merged);
2184
+ }
2185
+ /** Calls the section's `config` adapters (default `[environmentVariables()]`) and merges what they return: the app configuration. */
2186
+ function readAppConfiguration(section, input) {
2187
+ return readAdapters("config", section.config ?? [environmentVariables()], input);
2188
+ }
2189
+ /**
2190
+ * Calls the section's `secrets` adapters (default `[environmentVariables()]`) and merges what they
2191
+ * return: the app secrets. Every value must be text. A value is a known secret only once the graph
2192
+ * names it, so this adds none.
2193
+ */
2194
+ async function readAppSecrets(section, input) {
2195
+ const merged = await readAdapters("secrets", section.secrets ?? [environmentVariables()], input);
2196
+ if (!isText(merged)) throw new InternalError("readAdapters admitted a secret that is not text");
2197
+ return merged;
2198
+ }
1391
2199
  /**
1392
2200
  * Synchronous Node resolve hook so that entry modules may import relative
1393
2201
  * files using the specifier forms TypeScript accepts by default —
@@ -1656,20 +2464,21 @@ async function runPipeline(entry, overrideName, environment, cwd, source, deps =
1656
2464
  const entryModule = await loadEntry(resolved.path, cwd, resolved.fix);
1657
2465
  const name = overrideName ?? entryModule.root.name;
1658
2466
  if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
1659
- const poolInput = {
2467
+ const redaction = deps.redaction ?? new SecretRedaction(process.env);
2468
+ const adapterInput = {
1660
2469
  environment,
1661
2470
  configFile: configSource.file
1662
2471
  };
1663
- const pools = {
1664
- config: await readConfigPool(config, poolInput),
1665
- secrets: deps.readSecrets === true ? await readSecretsPool(config, poolInput) : NO_SECRETS
1666
- };
2472
+ const secrets = deps.readSecrets === true ? await readAppSecrets(config, adapterInput) : NO_SECRETS;
2473
+ const configuration = await readAppConfiguration(config, adapterInput);
2474
+ redaction.addCredentialLookingValues(credentialLookingValues(configuration));
1667
2475
  const graph = Load(entryModule.root, {
1668
2476
  id: name,
1669
2477
  environment: { name: environment },
1670
- configPool: pools.config
2478
+ configuration
1671
2479
  });
1672
2480
  if (graph.root.node.kind !== "module") throw new CliStructuredError("COMPOSE.ROOT_NOT_MODULE", "The deploy root must be a module.", { fix: "Wrap your service, e.g. export default module('name', ({ provision }) => { provision(service); })." });
2481
+ redaction.addKnownSecrets(valuesUnderSecretsKeys(configuration, secrets, secretsKeys(graph)));
1673
2482
  validateRegistryCoverage(graph, config);
1674
2483
  deps.onEvent?.({ kind: "loaded" });
1675
2484
  let assembled;
@@ -1685,7 +2494,8 @@ async function runPipeline(entry, overrideName, environment, cwd, source, deps =
1685
2494
  graph,
1686
2495
  name,
1687
2496
  assembled,
1688
- pools
2497
+ configuration,
2498
+ secrets
1689
2499
  };
1690
2500
  }
1691
2501
  /** Letters, digits, `-` and `_`, starting with a letter or digit: always a valid git ref, so no `git` is needed to check it. */
@@ -1698,6 +2508,6 @@ function validateEnvironmentName(environment, spawn = spawnSync) {
1698
2508
  if (result.status !== 0) throw new CliStructuredError("DEPLOY.ENVIRONMENT_INVALID", `Invalid --environment "${environment}": must be a valid git ref name (git check-ref-format rejected "refs/heads/${environment}").`);
1699
2509
  }
1700
2510
  //#endregion
1701
- export { validateEnvironmentName as i, resolveAppIdentity as n, runPipeline as r, checkConfigSource as t };
2511
+ export { nodeAddresses as a, __require as c, validateEnvironmentName as i, __toESM as l, resolveAppIdentity as n, secretsKeys as o, runPipeline as r, __commonJSMin as s, checkConfigSource as t };
1702
2512
 
1703
- //# sourceMappingURL=validate-environment-BNZC6W46-DY_7cPQJ.mjs.map
2513
+ //# sourceMappingURL=validate-environment-D_dECxgO-fg8lfCME.mjs.map