@prisma/composer-cli 0.36.0 → 0.37.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-config-CErnR6NK-6QjHJ7q5.mjs → app-config-CErnR6NK-DnKH4Kqc.mjs} +2 -2
- package/dist/{app-config-CErnR6NK-6QjHJ7q5.mjs.map → app-config-CErnR6NK-DnKH4Kqc.mjs.map} +1 -1
- package/dist/app-configuration-file-CeJvBAti-Dk65W3Az.mjs +140 -0
- package/dist/app-configuration-file-CeJvBAti-Dk65W3Az.mjs.map +1 -0
- package/dist/{dev-current-Brb4qugP-BOI9FJdz.mjs → dev-current-D-Qb6Yem-CvaY4xsk.mjs} +6 -6
- package/dist/{dev-current-Brb4qugP-BOI9FJdz.mjs.map → dev-current-D-Qb6Yem-CvaY4xsk.mjs.map} +1 -1
- package/dist/{dev-environment-name-6eEr5PW8-lIZmJjfr.mjs → dev-environment-name-6eEr5PW8-DpdGjmTb.mjs} +3 -3
- package/dist/dev-environment-name-6eEr5PW8-DpdGjmTb.mjs.map +1 -0
- package/dist/{dist-B9-nLeho.mjs → dist-BH6HQ6zZ.mjs} +3 -6
- package/dist/{dist-B9-nLeho.mjs.map → dist-BH6HQ6zZ.mjs.map} +1 -1
- package/dist/{execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs → execute-deploy-destroy-C6EsdmLz-DqdToZ_i.mjs} +62 -31
- package/dist/execute-deploy-destroy-C6EsdmLz-DqdToZ_i.mjs.map +1 -0
- package/dist/{execute-dev-current-BdEqeKAB-xCBBITAB.mjs → execute-dev-current-tBKmDAjV-DOOMGrl5.mjs} +7 -7
- package/dist/{execute-dev-current-BdEqeKAB-xCBBITAB.mjs.map → execute-dev-current-tBKmDAjV-DOOMGrl5.mjs.map} +1 -1
- package/dist/{execute-dev-BUk-XWBJ-DaB9ma8z.mjs → execute-dev-gjIKYybU-hRndPEgC.mjs} +93 -45
- package/dist/{execute-dev-BUk-XWBJ-DaB9ma8z.mjs.map → execute-dev-gjIKYybU-hRndPEgC.mjs.map} +1 -1
- package/dist/family.d.mts +2 -2
- package/dist/family.mjs +26 -9
- package/dist/family.mjs.map +1 -1
- package/dist/{generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs → generate-dev-stack-BV_n-X9n-BDBjgphH.mjs} +11 -5
- package/dist/generate-dev-stack-BV_n-X9n-BDBjgphH.mjs.map +1 -0
- package/dist/{list-deployed-B-N3imFH.mjs → list-deployed-D3tlbgmG.mjs} +5 -5
- package/dist/list-deployed-D3tlbgmG.mjs.map +1 -0
- package/dist/{family-B2JZ8O7U-P_rOUr4w.d.mts → redaction-Bf8FvTFH-D0dXGsO8.d.mts} +394 -185
- package/dist/redaction-Bf8FvTFH-D0dXGsO8.d.mts.map +1 -0
- package/dist/redaction-HnbkSFrK-CCKJNRwi.mjs +534 -0
- package/dist/redaction-HnbkSFrK-CCKJNRwi.mjs.map +1 -0
- package/dist/result-sR7PBi61.mjs +229 -0
- package/dist/result-sR7PBi61.mjs.map +1 -0
- package/dist/run-alchemy-OS_ix5g0-DSlHsv2p.mjs +236 -0
- package/dist/run-alchemy-OS_ix5g0-DSlHsv2p.mjs.map +1 -0
- package/dist/testing.d.mts +31 -2
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +8 -4
- package/dist/testing.mjs.map +1 -1
- package/dist/validate-environment-CpQLC3CA-Ct-PXoKN.mjs +2517 -0
- package/dist/validate-environment-CpQLC3CA-Ct-PXoKN.mjs.map +1 -0
- package/package.json +9 -9
- package/src/exports/testing.ts +3 -2
- package/src/family/deploy-list.ts +2 -2
- package/dist/dev-environment-name-6eEr5PW8-lIZmJjfr.mjs.map +0 -1
- package/dist/execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs.map +0 -1
- package/dist/family-B2JZ8O7U-P_rOUr4w.d.mts.map +0 -1
- package/dist/generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs.map +0 -1
- package/dist/list-deployed-B-N3imFH.mjs.map +0 -1
- package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs +0 -667
- package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map +0 -1
- package/dist/validate-environment-CEhUSEg2-ExABehBM.mjs +0 -1343
- package/dist/validate-environment-CEhUSEg2-ExABehBM.mjs.map +0 -1
|
@@ -0,0 +1,2517 @@
|
|
|
1
|
+
import { d as configFileMissing, f as entryMissing, i as credentialLookingValues, l as valuesUnderSecretsKeys, n as SecretRedaction, u as checkComposerConfig } from "./redaction-HnbkSFrK-CCKJNRwi.mjs";
|
|
2
|
+
import { a as InternalError, i as CliStructuredError, o as blindCast } from "./result-sR7PBi61.mjs";
|
|
3
|
+
import * as mod from "node:module";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import "alchemy";
|
|
9
|
+
import "effect/Effect";
|
|
10
|
+
import "effect/Layer";
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
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
|
|
37
|
+
//#region ../../0-framework/0-foundation/foundation/dist/describe-kind-Cpm_euxo.mjs
|
|
38
|
+
/** How an error names the kind of a value it did not expect, without printing the value. */
|
|
39
|
+
function describeKind(value) {
|
|
40
|
+
if (value === void 0) return "nothing";
|
|
41
|
+
if (value === null) return "null";
|
|
42
|
+
if (Array.isArray(value)) return "an array";
|
|
43
|
+
if (typeof value === "function") return "a function";
|
|
44
|
+
if (typeof value === "object") return "an object";
|
|
45
|
+
return `a ${typeof value}`;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
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;
|
|
175
|
+
try {
|
|
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
|
|
464
|
+
});
|
|
465
|
+
}
|
|
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;
|
|
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
|
+
}, {});
|
|
503
|
+
}
|
|
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
|
+
};
|
|
688
|
+
}
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region ../../0-framework/3-tooling/assemble/dist/index.mjs
|
|
691
|
+
/**
|
|
692
|
+
* A user-facing assembly failure, structured at origin (base-type rule 6):
|
|
693
|
+
* a `CliStructuredError` whose code names which way assembly went wrong.
|
|
694
|
+
* This package's second consumer is the programmatic deploy API, not just
|
|
695
|
+
* the CLI — hosts branch on `error.code`, the CLI renders the envelope.
|
|
696
|
+
*/
|
|
697
|
+
var AssembleError = class extends CliStructuredError {
|
|
698
|
+
constructor(code, summary, options) {
|
|
699
|
+
super(code, summary, options);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* The registry route for one service's build: extension by
|
|
704
|
+
* `build.extension`, node descriptor by `build.type`, kind must be "build".
|
|
705
|
+
* The CLI's coverage validation reports the same misses earlier with the
|
|
706
|
+
* config fix; these errors are the backstop for programmatic callers.
|
|
707
|
+
*/
|
|
708
|
+
function buildDescriptorAssemble(config, node, address, cwd, report) {
|
|
709
|
+
const { extension, type } = node.build;
|
|
710
|
+
const extensionDescriptor = config.extensions.find((candidate) => candidate.id === extension);
|
|
711
|
+
if (extensionDescriptor === void 0) throw new AssembleError("ASSEMBLE.EXTENSION_MISSING", `No extension "${extension}" is configured (needed by service "${node.name}"'s build).`, { fix: "Add it to `extensions` in the `composer` section of prisma.config.ts." });
|
|
712
|
+
const nodeDescriptor = extensionDescriptor.nodes[type];
|
|
713
|
+
if (nodeDescriptor === void 0) throw new AssembleError("ASSEMBLE.DESCRIPTOR_MISSING", `Extension "${extension}" has no descriptor for build type "${type}".`, { why: `Known types: ${Object.keys(extensionDescriptor.nodes).join(", ")}.` });
|
|
714
|
+
if (nodeDescriptor.kind !== "build") throw new AssembleError("ASSEMBLE.DESCRIPTOR_KIND_MISMATCH", `Extension "${extension}"'s descriptor for type "${type}" is a "${nodeDescriptor.kind}" descriptor.`, { why: "Assembling a service build needs a \"build\" descriptor." });
|
|
715
|
+
return nodeDescriptor.assemble({
|
|
716
|
+
build: node.build,
|
|
717
|
+
address,
|
|
718
|
+
cwd,
|
|
719
|
+
report
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* The dev server a service's build descriptor declares, or `undefined` when it
|
|
724
|
+
* declares none — including when the registry route misses, which the
|
|
725
|
+
* assemble that follows reports with its own pinned error.
|
|
726
|
+
*/
|
|
727
|
+
async function buildDescriptorServe(config, node, address) {
|
|
728
|
+
const { extension, type } = node.build;
|
|
729
|
+
const nodeDescriptor = config.extensions.find((candidate) => candidate.id === extension)?.nodes[type];
|
|
730
|
+
if (nodeDescriptor?.kind !== "build" || nodeDescriptor.serve === void 0) return void 0;
|
|
731
|
+
try {
|
|
732
|
+
return await nodeDescriptor.serve({
|
|
733
|
+
build: node.build,
|
|
734
|
+
address
|
|
735
|
+
});
|
|
736
|
+
} catch (error) {
|
|
737
|
+
if (CliStructuredError.is(error)) throw error;
|
|
738
|
+
throw new CliStructuredError("DEV.DEV_SERVER_UNAVAILABLE", `service "${address}" cannot run its dev server: ${error instanceof Error ? error.message : String(error)}`, {
|
|
739
|
+
meta: { address },
|
|
740
|
+
cause: error
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
async function assembleServices(graph, config, cwd, run, onEvent, options = {}) {
|
|
745
|
+
const runAssembler = run ?? ((node, address, nodeCwd, report) => buildDescriptorAssemble(config, node, address, nodeCwd, report));
|
|
746
|
+
const serviceNodes = graph.nodes.filter((n) => n.node.kind === "service");
|
|
747
|
+
if (serviceNodes.length === 0) throw new AssembleError("ASSEMBLE.SERVICE_MISSING", "The loaded graph has no service to assemble.");
|
|
748
|
+
const bundles = {};
|
|
749
|
+
const devServers = {};
|
|
750
|
+
for (const { id, node } of serviceNodes) {
|
|
751
|
+
if (options.devServers === true) {
|
|
752
|
+
const server = await buildDescriptorServe(config, node, id);
|
|
753
|
+
if (server !== void 0) {
|
|
754
|
+
devServers[id] = server;
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
onEvent?.({
|
|
759
|
+
kind: "service-started",
|
|
760
|
+
address: id
|
|
761
|
+
});
|
|
762
|
+
const data = {};
|
|
763
|
+
let artifact;
|
|
764
|
+
try {
|
|
765
|
+
artifact = await runAssembler(node, id, cwd, (reported) => Object.assign(data, reported));
|
|
766
|
+
} catch (error) {
|
|
767
|
+
if (CliStructuredError.is(error)) throw error;
|
|
768
|
+
throw new AssembleError("ASSEMBLE.BUILD_FAILED", error instanceof Error ? error.message : String(error), {
|
|
769
|
+
meta: { address: id },
|
|
770
|
+
cause: error
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
bundles[id] = artifact;
|
|
774
|
+
onEvent?.({
|
|
775
|
+
kind: "service-assembled",
|
|
776
|
+
address: id,
|
|
777
|
+
data
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
return {
|
|
781
|
+
bundles,
|
|
782
|
+
devServers
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
//#endregion
|
|
786
|
+
//#region ../../0-framework/0-foundation/foundation/dist/pointer-Cw3E-nrh.mjs
|
|
787
|
+
/** A pointer: what a value known only at boot holds at deploy. It names the platform variable the service reads at boot, and records whether that variable holds a secret. */
|
|
788
|
+
const POINTER = blindCast(Symbol.for("prisma:pointer"));
|
|
789
|
+
function kindOf(value) {
|
|
790
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
791
|
+
return Reflect.get(value, POINTER);
|
|
792
|
+
}
|
|
793
|
+
/** True for a secret pointer: a value known only at boot whose variable holds a secret. */
|
|
794
|
+
function isSecretPointer(value) {
|
|
795
|
+
return kindOf(value) === "secret";
|
|
796
|
+
}
|
|
797
|
+
//#endregion
|
|
798
|
+
//#region ../../0-framework/0-foundation/foundation/dist/secret-DoWGmN7m.mjs
|
|
799
|
+
const SECRET_BOX = blindCast(Symbol.for("prisma:secret-box"));
|
|
800
|
+
/**
|
|
801
|
+
* True for a redacting secret box — what a schema's secret leaf checks
|
|
802
|
+
* (ADR-0042). Reads the brand rather than `instanceof`, so a box from a
|
|
803
|
+
* duplicated module copy in a bundle counts and a look-alike does not.
|
|
804
|
+
*/
|
|
805
|
+
function isSecretString(value) {
|
|
806
|
+
return typeof value === "object" && value !== null && blindCast(value)[SECRET_BOX] === true;
|
|
807
|
+
}
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region ../../0-framework/1-core/core/dist/graph-CBt9CRBT.mjs
|
|
810
|
+
/** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
|
|
811
|
+
const RESOURCE_OUT_PORT = "$out";
|
|
812
|
+
/**
|
|
813
|
+
* Thrown by Load when the graph is malformed. Structured at origin
|
|
814
|
+
* (base-type rule 6): one type-level code covers every raise site until a
|
|
815
|
+
* finer per-site taxonomy is carved out. The `name` stays
|
|
816
|
+
* `CliStructuredError` — structural recognition depends on it.
|
|
817
|
+
*/
|
|
818
|
+
var LoadError = class extends CliStructuredError {
|
|
819
|
+
constructor(message, options) {
|
|
820
|
+
super("COMPOSE.GRAPH_INVALID", message, options);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
/** The declared style of an untrusted contract value, or `undefined` when it declares none. */
|
|
824
|
+
function contractStyleOf(contract) {
|
|
825
|
+
if (typeof contract !== "object" || contract === null || !("style" in contract)) return void 0;
|
|
826
|
+
return contract.style === "request-response" || contract.style === "stream" ? contract.style : void 0;
|
|
827
|
+
}
|
|
828
|
+
const VALUE = blindCast(Symbol.for("prisma:value"));
|
|
829
|
+
const VALUE_ORIGIN = blindCast(Symbol.for("prisma:value-origin"));
|
|
830
|
+
/** True if `value` is a `Value`, a source included (checks the brand only, never a prototype). */
|
|
831
|
+
function isValue(value) {
|
|
832
|
+
return typeof value === "object" && value !== null && blindCast(value)[VALUE] === true;
|
|
833
|
+
}
|
|
834
|
+
/** True for an object whose prototype is `Object.prototype` or `null`: the only objects Load walks into. */
|
|
835
|
+
function isPlainObject(value) {
|
|
836
|
+
if (typeof value !== "object" || value === null) return false;
|
|
837
|
+
const prototype = Object.getPrototypeOf(value);
|
|
838
|
+
return prototype === Object.prototype || prototype === null;
|
|
839
|
+
}
|
|
840
|
+
/** Where Load gets `value`'s real value. Internal to core. */
|
|
841
|
+
function originOf(value) {
|
|
842
|
+
return value[VALUE_ORIGIN];
|
|
843
|
+
}
|
|
844
|
+
/** The one `environment` object every module body receives. */
|
|
845
|
+
const environmentFacts = Object.freeze({ name: Object.freeze({
|
|
846
|
+
[VALUE]: true,
|
|
847
|
+
[VALUE_ORIGIN]: Object.freeze({
|
|
848
|
+
kind: "environment",
|
|
849
|
+
fact: "name"
|
|
850
|
+
})
|
|
851
|
+
}) });
|
|
852
|
+
const INSPECT = Symbol.for("nodejs.util.inspect.custom");
|
|
853
|
+
/** `input` or `input.a.b`: how an error names an input field. */
|
|
854
|
+
function inputFieldLabel(origin) {
|
|
855
|
+
return origin.path.length === 0 ? "input" : `input.${origin.path.join(".")}`;
|
|
856
|
+
}
|
|
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.`);
|
|
859
|
+
const field = inputFieldLabel(origin);
|
|
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]) => …).`);
|
|
861
|
+
}
|
|
862
|
+
/** What a coercion with `hint` did to a value, worded for a misuse error. */
|
|
863
|
+
function primitiveMisuse(hint) {
|
|
864
|
+
switch (hint) {
|
|
865
|
+
case "string": return "it was turned into text (a template literal or String())";
|
|
866
|
+
case "number": return "it was turned into a number (arithmetic, or a comparison such as <)";
|
|
867
|
+
default: return "it was combined with + or compared with ==";
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Builds the `input` a module body receives. Every property access returns a
|
|
872
|
+
* value recording its key path, and the same path always returns the same
|
|
873
|
+
* object, so Load's identity-keyed maps see one value per field. Any way of
|
|
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.
|
|
877
|
+
*/
|
|
878
|
+
function buildModuleInput(moduleAddress) {
|
|
879
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
880
|
+
const valueAt = (path) => {
|
|
881
|
+
const key = JSON.stringify(path);
|
|
882
|
+
const existing = byPath.get(key);
|
|
883
|
+
if (existing !== void 0) return existing;
|
|
884
|
+
const origin = Object.freeze({
|
|
885
|
+
kind: "input",
|
|
886
|
+
module: moduleAddress,
|
|
887
|
+
path: Object.freeze([...path])
|
|
888
|
+
});
|
|
889
|
+
const thrower = (what) => () => {
|
|
890
|
+
throw misuse(origin, what);
|
|
891
|
+
};
|
|
892
|
+
const handler = {
|
|
893
|
+
get(_target, property) {
|
|
894
|
+
if (property === VALUE) return true;
|
|
895
|
+
if (property === VALUE_ORIGIN) return origin;
|
|
896
|
+
if (property === Symbol.toPrimitive) return (hint) => {
|
|
897
|
+
throw misuse(origin, primitiveMisuse(hint));
|
|
898
|
+
};
|
|
899
|
+
if (property === "toString") return thrower("its toString() was called");
|
|
900
|
+
if (property === "valueOf") return thrower("its valueOf() was called");
|
|
901
|
+
if (property === "toJSON") return thrower("it was serialized with JSON.stringify");
|
|
902
|
+
if (property === Symbol.iterator || property === Symbol.asyncIterator) return thrower("it was iterated (array spread, for…of or array destructuring)");
|
|
903
|
+
if (typeof property === "symbol") return void 0;
|
|
904
|
+
return valueAt([...path, property]);
|
|
905
|
+
},
|
|
906
|
+
has(_target, property) {
|
|
907
|
+
if (property === VALUE || property === VALUE_ORIGIN) return true;
|
|
908
|
+
if (typeof property === "symbol") return false;
|
|
909
|
+
throw misuse(origin, `it was checked with the in operator ("${property}" in …)`);
|
|
910
|
+
},
|
|
911
|
+
ownKeys() {
|
|
912
|
+
throw misuse(origin, "its keys were listed (Object.keys, object spread, for…in or Object.entries)");
|
|
913
|
+
},
|
|
914
|
+
getOwnPropertyDescriptor() {
|
|
915
|
+
throw misuse(origin, "its properties were inspected");
|
|
916
|
+
},
|
|
917
|
+
set(_target, property) {
|
|
918
|
+
throw misuse(origin, `its field "${String(property)}" was assigned to`);
|
|
919
|
+
},
|
|
920
|
+
defineProperty(_target, property) {
|
|
921
|
+
throw misuse(origin, `its field "${String(property)}" was assigned to`);
|
|
922
|
+
},
|
|
923
|
+
deleteProperty() {
|
|
924
|
+
throw misuse(origin, "a property was deleted from it");
|
|
925
|
+
},
|
|
926
|
+
setPrototypeOf() {
|
|
927
|
+
throw misuse(origin, "its prototype was changed");
|
|
928
|
+
},
|
|
929
|
+
preventExtensions() {
|
|
930
|
+
throw misuse(origin, "it was frozen or sealed");
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const target = Object.create(null);
|
|
934
|
+
Object.defineProperty(target, INSPECT, {
|
|
935
|
+
value: () => `[${inputFieldLabel(origin)} of module "${origin.module}"]`,
|
|
936
|
+
configurable: true
|
|
937
|
+
});
|
|
938
|
+
const proxy = new Proxy(target, handler);
|
|
939
|
+
byPath.set(key, proxy);
|
|
940
|
+
return proxy;
|
|
941
|
+
};
|
|
942
|
+
return blindCast(valueAt([]));
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Core model: node types and the factories that construct them, plain frozen
|
|
946
|
+
* data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
|
|
947
|
+
*/
|
|
948
|
+
const NODE = Symbol.for("prisma:node");
|
|
949
|
+
const SECRET_SOURCE = blindCast(Symbol.for("prisma:secret-source"));
|
|
950
|
+
/** True if `value` is a secret source, such as an `envSecret()` result. */
|
|
951
|
+
function isSecretSource(value) {
|
|
952
|
+
return typeof value === "object" && value !== null && blindCast(value)[SECRET_SOURCE] === true;
|
|
953
|
+
}
|
|
954
|
+
blindCast(Symbol.for("prisma:provision-need"));
|
|
955
|
+
const PARAM_SOURCE = blindCast(Symbol.for("prisma:param-source"));
|
|
956
|
+
const sourceMisuses = /* @__PURE__ */ new WeakSet();
|
|
957
|
+
/** True for the error a source throws when code turns it into text or a number. Internal to core. */
|
|
958
|
+
function isSourceMisuse(error) {
|
|
959
|
+
return error instanceof LoadError && sourceMisuses.has(error);
|
|
960
|
+
}
|
|
961
|
+
/** A source's origin; `undefined` for a source another installed copy of core built without one. Internal to core. */
|
|
962
|
+
function sourceOriginOf(source) {
|
|
963
|
+
if (!isValue(source)) return void 0;
|
|
964
|
+
const origin = originOf(source);
|
|
965
|
+
return origin.kind === "source" ? origin : void 0;
|
|
966
|
+
}
|
|
967
|
+
/** True if `value` is a param source, such as an `envParam()` result. */
|
|
968
|
+
function isParamSource(value) {
|
|
969
|
+
return typeof value === "object" && value !== null && blindCast(value)[PARAM_SOURCE] === true;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Core's grammar for every name that becomes a config-key segment —
|
|
973
|
+
* addresses, input/param/secret names: ASCII letters and digits only.
|
|
974
|
+
* Conservative by design so any target medium — POSIX env-var keys
|
|
975
|
+
* included — can uppercase and "_"-join segments without escaping.
|
|
976
|
+
*/
|
|
977
|
+
function isConfigKeySegment(name) {
|
|
978
|
+
return /^[A-Za-z0-9]+$/.test(name);
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* True if `value` was constructed by this module's factories. Checks the
|
|
982
|
+
* brand only, never a prototype — a graph may mix nodes from a different
|
|
983
|
+
* installed copy of core (dual-package hazard).
|
|
984
|
+
*/
|
|
985
|
+
function isNode(value) {
|
|
986
|
+
return typeof value === "object" && value !== null && blindCast(value)[NODE] === true;
|
|
987
|
+
}
|
|
988
|
+
/** A node's dependency slots. A resource node built by another installed copy of core may have no `inputs`; that means none. */
|
|
989
|
+
function slotsOf(node) {
|
|
990
|
+
return node.kind === "resource" ? node.inputs ?? {} : node.inputs;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Stable topological sort: every edge's `from` precedes its `to` in the
|
|
994
|
+
* result. Ties (nodes with no ordering constraint between them) keep their
|
|
995
|
+
* relative order from `nodes` — so a graph already authored producer-first
|
|
996
|
+
* comes out byte-identical to its pre-sort layout; only a graph that
|
|
997
|
+
* genuinely needs reordering (e.g. a module wired via a forged ref pointing at a
|
|
998
|
+
* not-yet-provisioned producer) actually moves. A Kahn's-algorithm variant
|
|
999
|
+
* that always picks the ready node with the smallest original index. Edges
|
|
1000
|
+
* whose endpoint falls outside `nodes` (e.g. a service-root's input edges
|
|
1001
|
+
* targeting the root, which is appended separately) are ignored. Cycles
|
|
1002
|
+
* cannot reach here: `assertDependencyDag` already rejects them for
|
|
1003
|
+
* dependency edges, and input edges never cycle.
|
|
1004
|
+
*/
|
|
1005
|
+
function topoSort(nodes, edges) {
|
|
1006
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
1007
|
+
const indexOf = new Map(nodes.map((n, i) => [n.id, i]));
|
|
1008
|
+
const indegree = new Map(nodes.map((n) => [n.id, 0]));
|
|
1009
|
+
const successors = /* @__PURE__ */ new Map();
|
|
1010
|
+
for (const edge of edges) {
|
|
1011
|
+
if (!byId.has(edge.from) || !byId.has(edge.to)) continue;
|
|
1012
|
+
const targets = successors.get(edge.from) ?? [];
|
|
1013
|
+
targets.push(edge.to);
|
|
1014
|
+
successors.set(edge.from, targets);
|
|
1015
|
+
indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
|
|
1016
|
+
}
|
|
1017
|
+
const ready = new Set(nodes.filter((n) => indegree.get(n.id) === 0).map((n) => n.id));
|
|
1018
|
+
const order = [];
|
|
1019
|
+
while (ready.size > 0) {
|
|
1020
|
+
let next;
|
|
1021
|
+
let bestIndex = Number.POSITIVE_INFINITY;
|
|
1022
|
+
for (const id of ready) {
|
|
1023
|
+
const index = indexOf.get(id) ?? Number.POSITIVE_INFINITY;
|
|
1024
|
+
if (index < bestIndex) {
|
|
1025
|
+
bestIndex = index;
|
|
1026
|
+
next = id;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (next === void 0) break;
|
|
1030
|
+
ready.delete(next);
|
|
1031
|
+
order.push(next);
|
|
1032
|
+
for (const target of successors.get(next) ?? []) {
|
|
1033
|
+
const remaining = (indegree.get(target) ?? 0) - 1;
|
|
1034
|
+
indegree.set(target, remaining);
|
|
1035
|
+
if (remaining === 0) ready.add(target);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (order.length !== nodes.length) throw new InternalError(`topological sort processed ${order.length} of ${nodes.length} nodes — the graph contains a cycle that slipped past the DAG validation.`);
|
|
1039
|
+
return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* The declared boundary ports of a module, service or resource node at `id`:
|
|
1043
|
+
* dep slots as `in` ports (contractKind = the slot's `type`), exposed
|
|
1044
|
+
* contracts as `out` ports (contractKind = the contract's `kind`, style = its
|
|
1045
|
+
* declared style). A resource's one `$out` port is recorded at its provision
|
|
1046
|
+
* site instead (load-module.ts).
|
|
1047
|
+
*/
|
|
1048
|
+
function boundaryPortsOf(id, node) {
|
|
1049
|
+
const ports = [];
|
|
1050
|
+
const slots = node.kind === "module" ? node.deps : slotsOf(node);
|
|
1051
|
+
for (const [name, slot] of Object.entries(slots)) {
|
|
1052
|
+
const type = typeof slot === "object" && slot !== null && "type" in slot && typeof slot.type === "string" ? slot.type : void 0;
|
|
1053
|
+
ports.push({
|
|
1054
|
+
node: id,
|
|
1055
|
+
direction: "in",
|
|
1056
|
+
name,
|
|
1057
|
+
contractKind: type,
|
|
1058
|
+
style: void 0
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
const expose = node.kind === "resource" ? {} : node.expose ?? {};
|
|
1062
|
+
for (const [name, contract] of Object.entries(expose)) {
|
|
1063
|
+
const kind = typeof contract === "object" && contract !== null && "kind" in contract && typeof contract.kind === "string" ? contract.kind : void 0;
|
|
1064
|
+
ports.push({
|
|
1065
|
+
node: id,
|
|
1066
|
+
direction: "out",
|
|
1067
|
+
name,
|
|
1068
|
+
contractKind: kind,
|
|
1069
|
+
style: contractStyleOf(contract)
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
return ports;
|
|
1073
|
+
}
|
|
1074
|
+
/** A resource node built by another installed copy of core may have no `inputs`; it has no slots. */
|
|
1075
|
+
function slotNodesAndEdges(node, nodeId) {
|
|
1076
|
+
const inputs = slotsOf(node);
|
|
1077
|
+
if (typeof inputs !== "object" || inputs === null) throw new LoadError(`Node "${nodeId}" has no inputs map.`);
|
|
1078
|
+
const nodes = [];
|
|
1079
|
+
const edges = [];
|
|
1080
|
+
for (const [input, value] of Object.entries(inputs)) {
|
|
1081
|
+
const kind = isNode(value) ? value.kind : void 0;
|
|
1082
|
+
if (kind === "resource") throw new LoadError(`Dependency "${input}" of "${nodeId}" is a resource node — a resource is provisioned by the composing module, never created for a service that mentions it. Declare the input as a dependency (the pack's dependency factory) and wire the module-provisioned resource's ref into it.`);
|
|
1083
|
+
if (kind !== "dependency") throw new LoadError(`Dependency "${input}" of "${nodeId}" is not a branded dependency end (construct it with the dependency() factory).`);
|
|
1084
|
+
if (value.type.length === 0) throw new LoadError(`Dependency "${input}" of "${nodeId}" has an empty node type.`);
|
|
1085
|
+
const id = `${nodeId}.${input}`;
|
|
1086
|
+
nodes.push({
|
|
1087
|
+
id,
|
|
1088
|
+
parent: nodeId,
|
|
1089
|
+
node: value
|
|
1090
|
+
});
|
|
1091
|
+
edges.push({
|
|
1092
|
+
from: id,
|
|
1093
|
+
to: nodeId,
|
|
1094
|
+
input,
|
|
1095
|
+
kind: "input"
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
return {
|
|
1099
|
+
nodes,
|
|
1100
|
+
edges
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function loadService(root, rootId) {
|
|
1104
|
+
for (const [input, value] of Object.entries(root.inputs)) if (isNode(value) && value.kind === "dependency") throw new LoadError(`Service "${rootId}" has an unwired dependency "${input}" — this service is composed by a module; deploy the module instead of loading "${rootId}" directly.`);
|
|
1105
|
+
if (root.inputSchema !== void 0) throw new LoadError(`Service "${rootId}" declares an input schema but is being loaded directly — a lone service has no enclosing scope to bind its input. Compose it inside a module whose provision() call binds \`input: { … }\` (ADR-0042).`);
|
|
1106
|
+
const rootGraphNode = {
|
|
1107
|
+
id: rootId,
|
|
1108
|
+
parent: void 0,
|
|
1109
|
+
node: root
|
|
1110
|
+
};
|
|
1111
|
+
const { nodes, edges } = slotNodesAndEdges(root, rootId);
|
|
1112
|
+
return {
|
|
1113
|
+
root: rootGraphNode,
|
|
1114
|
+
nodes: [...topoSort(nodes, edges), rootGraphNode],
|
|
1115
|
+
edges,
|
|
1116
|
+
ports: boundaryPortsOf(rootId, root),
|
|
1117
|
+
authoredEdges: [],
|
|
1118
|
+
inputBindings: [],
|
|
1119
|
+
params: [],
|
|
1120
|
+
secretSources: [],
|
|
1121
|
+
appConfigurationRead: {
|
|
1122
|
+
rootInput: [],
|
|
1123
|
+
configurationKeyText: {}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
function joinPath(path, key) {
|
|
1128
|
+
return path === "" ? String(key) : `${path}.${key}`;
|
|
1129
|
+
}
|
|
1130
|
+
function describeSite(site) {
|
|
1131
|
+
switch (site.kind) {
|
|
1132
|
+
case "serviceInput": return site.path === "" ? `the input binding of service "${site.address}"` : `input key "${site.path}" of service "${site.address}"`;
|
|
1133
|
+
case "moduleInput": return site.path === "" ? `the input binding of module "${site.address}"` : `input key "${site.path}" of module "${site.address}"`;
|
|
1134
|
+
case "param": return `param "${site.path}" of service "${site.address}"`;
|
|
1135
|
+
case "props": return site.path === "" ? `the props of resource "${site.address}"` : `prop "${site.path}" of resource "${site.address}"`;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function collect(value, site, found, seen, recordSecret) {
|
|
1139
|
+
if (isSecretSource(value) || isParamSource(value)) {
|
|
1140
|
+
if (isSecretSource(value) && site.kind !== "props") recordSecret(value, site);
|
|
1141
|
+
if (site.kind === "serviceInput" || site.kind === "param" || !isValue(value)) return;
|
|
1142
|
+
found.push({
|
|
1143
|
+
value,
|
|
1144
|
+
site
|
|
1145
|
+
});
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
if (isValue(value)) {
|
|
1149
|
+
found.push({
|
|
1150
|
+
value,
|
|
1151
|
+
site
|
|
1152
|
+
});
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return;
|
|
1156
|
+
if (seen.has(value)) return;
|
|
1157
|
+
seen.add(value);
|
|
1158
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
1159
|
+
for (const [key, member] of entries) {
|
|
1160
|
+
const path = site.kind === "param" ? site.path : joinPath(site.path, key);
|
|
1161
|
+
collect(member, {
|
|
1162
|
+
...site,
|
|
1163
|
+
path
|
|
1164
|
+
}, found, seen, recordSecret);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function describeNotPlain(value) {
|
|
1168
|
+
switch (typeof value) {
|
|
1169
|
+
case "function": return "a function";
|
|
1170
|
+
case "symbol": return "a symbol";
|
|
1171
|
+
case "bigint": return "a bigint";
|
|
1172
|
+
case "number": return Number.isFinite(value) ? void 0 : "a non-finite number";
|
|
1173
|
+
case "object": return value === null || Array.isArray(value) || isPlainObject(value) ? void 0 : "an object that is not plain data";
|
|
1174
|
+
default: return;
|
|
1175
|
+
}
|
|
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.";
|
|
1200
|
+
function isThenable(value) {
|
|
1201
|
+
if (isValue(value)) return false;
|
|
1202
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
1203
|
+
}
|
|
1204
|
+
function canonicalSecret(source) {
|
|
1205
|
+
const original = sourceOriginOf(source)?.source;
|
|
1206
|
+
return isSecretSource(original) ? original : source;
|
|
1207
|
+
}
|
|
1208
|
+
function nodeKindOf(site) {
|
|
1209
|
+
switch (site.kind) {
|
|
1210
|
+
case "serviceInput":
|
|
1211
|
+
case "param": return "service";
|
|
1212
|
+
case "moduleInput": return "module";
|
|
1213
|
+
case "props": return "resource";
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
function pointersIn(values) {
|
|
1217
|
+
const pointers = /* @__PURE__ */ new Set();
|
|
1218
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1219
|
+
const walk = (value) => {
|
|
1220
|
+
if (isSecretSource(value) || isParamSource(value)) {
|
|
1221
|
+
pointers.add(value);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return;
|
|
1225
|
+
if (seen.has(value)) return;
|
|
1226
|
+
seen.add(value);
|
|
1227
|
+
for (const member of Array.isArray(value) ? value : Object.values(value)) walk(member);
|
|
1228
|
+
};
|
|
1229
|
+
walk(values);
|
|
1230
|
+
return pointers;
|
|
1231
|
+
}
|
|
1232
|
+
function checkResult(result, fnLabel) {
|
|
1233
|
+
if (isThenable(result)) throw new LoadError(`${fnLabel} returned a Promise. resolve() runs synchronously at Load.`);
|
|
1234
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1235
|
+
const walk = (value, path) => {
|
|
1236
|
+
const atPath = path === "" ? "" : ` at "${path}"`;
|
|
1237
|
+
if (value === void 0) throw new LoadError(`${fnLabel} returned undefined${atPath}. Return a result for every environment; Composer never picks a default.`);
|
|
1238
|
+
if (isSecretSource(value) || isParamSource(value)) throw new LoadError(`${fnLabel} returned a source${atPath}, such as envSecret() or envParam() called inside the function. resolve() returns plain data; bind a source directly.`);
|
|
1239
|
+
if (isValue(value)) throw new LoadError(`${fnLabel} returned a value${atPath}, not a real value. List that value as a dependency; fn receives its real value.`);
|
|
1240
|
+
const notPlain = describeNotPlain(value);
|
|
1241
|
+
if (notPlain !== void 0) throw new LoadError(`${fnLabel} returned ${notPlain}${atPath}. resolve() returns plain data: strings, finite numbers, booleans, null, arrays and plain objects.`);
|
|
1242
|
+
if (typeof value !== "object" || value === null || seen.has(value)) return;
|
|
1243
|
+
seen.add(value);
|
|
1244
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
1245
|
+
for (const [key, member] of entries) walk(member, joinPath(path, key));
|
|
1246
|
+
};
|
|
1247
|
+
walk(result, "");
|
|
1248
|
+
}
|
|
1249
|
+
/** The first pointer in `value`, at any depth through arrays and plain objects, with its key path; `undefined` when there is none. */
|
|
1250
|
+
function firstPointer(value, path = [], seen = /* @__PURE__ */ new WeakSet()) {
|
|
1251
|
+
if (isSecretSource(value) || isParamSource(value)) return {
|
|
1252
|
+
pointer: value,
|
|
1253
|
+
path
|
|
1254
|
+
};
|
|
1255
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return void 0;
|
|
1256
|
+
if (seen.has(value)) return void 0;
|
|
1257
|
+
seen.add(value);
|
|
1258
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [String(index), member]) : Object.entries(value);
|
|
1259
|
+
for (const [key, member] of entries) {
|
|
1260
|
+
const found = firstPointer(member, [...path, key], seen);
|
|
1261
|
+
if (found !== void 0) return found;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/** Refuses a resolve() dependency whose real value is a pointer or holds one at any depth: `fn` computes with deploy-time data only. */
|
|
1265
|
+
function refusePointerDependency(fnLabel, dependency, real) {
|
|
1266
|
+
const found = firstPointer(real);
|
|
1267
|
+
if (found === void 0) return;
|
|
1268
|
+
const label = sourceOriginOf(found.pointer)?.label ?? "a value known only at boot";
|
|
1269
|
+
const origin = originOf(dependency);
|
|
1270
|
+
if (origin.kind !== "input") throw new LoadError(`${fnLabel} lists ${label}, which is known only at boot. A resolve() dependency must be a deploy-time value. Bind ${label} directly into the input of the service that reads it.`);
|
|
1271
|
+
const listed = `${inputFieldLabel(origin)} of module "${origin.module}"`;
|
|
1272
|
+
const field = inputFieldLabel({
|
|
1273
|
+
...origin,
|
|
1274
|
+
path: [...origin.path, ...found.path]
|
|
1275
|
+
});
|
|
1276
|
+
throw new LoadError(`${fnLabel} lists ${listed}, ${found.path.length === 0 ? `whose real value is ${label}` : `which holds ${label} at ${field}`}, a value known only at boot. A resolve() dependency must be a deploy-time value. ${isSecretPointer(found.pointer) ? `A secret has no deploy-time value: pass ${field} on into a binding, and read it in the service.` : `To compute with ${field}, declare it plain, without field(), and bind it to deploy-time data.`}`);
|
|
1277
|
+
}
|
|
1278
|
+
function substitute(value, results, inProgress, sources) {
|
|
1279
|
+
if (isSecretSource(value) || isParamSource(value)) return sources === "keep" || !isValue(value) ? value : results.get(value);
|
|
1280
|
+
if (isValue(value)) return results.get(value);
|
|
1281
|
+
if (Array.isArray(value)) {
|
|
1282
|
+
if (inProgress.has(value)) return value;
|
|
1283
|
+
inProgress.add(value);
|
|
1284
|
+
const rebuilt = value.map((member) => substitute(member, results, inProgress, sources));
|
|
1285
|
+
inProgress.delete(value);
|
|
1286
|
+
return rebuilt.every((member, index) => member === value[index]) ? value : rebuilt;
|
|
1287
|
+
}
|
|
1288
|
+
if (isPlainObject(value)) {
|
|
1289
|
+
if (inProgress.has(value)) return value;
|
|
1290
|
+
inProgress.add(value);
|
|
1291
|
+
const rebuilt = {};
|
|
1292
|
+
let changed = false;
|
|
1293
|
+
for (const [key, member] of Object.entries(value)) {
|
|
1294
|
+
const real = substitute(member, results, inProgress, sources);
|
|
1295
|
+
if (real === void 0 && isValue(member)) {
|
|
1296
|
+
changed = true;
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
rebuilt[key] = real;
|
|
1300
|
+
if (real !== member) changed = true;
|
|
1301
|
+
}
|
|
1302
|
+
inProgress.delete(value);
|
|
1303
|
+
return changed ? rebuilt : value;
|
|
1304
|
+
}
|
|
1305
|
+
return value;
|
|
1306
|
+
}
|
|
1307
|
+
function describeData(value) {
|
|
1308
|
+
if (Array.isArray(value)) return "an array";
|
|
1309
|
+
if (typeof value === "object") return "an object that is not plain data";
|
|
1310
|
+
return `a ${typeof value}`;
|
|
1311
|
+
}
|
|
1312
|
+
/** The data at `origin`'s path inside a validated input; `undefined` where a key or a parent is absent. */
|
|
1313
|
+
function readPath(data, origin) {
|
|
1314
|
+
let current = data;
|
|
1315
|
+
for (const [index, key] of origin.path.entries()) {
|
|
1316
|
+
if (current === void 0 || current === null) return void 0;
|
|
1317
|
+
const missing = `${inputFieldLabel(origin)} of module "${origin.module}" does not exist`;
|
|
1318
|
+
const parent = inputFieldLabel({
|
|
1319
|
+
...origin,
|
|
1320
|
+
path: origin.path.slice(0, index)
|
|
1321
|
+
});
|
|
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
|
+
}
|
|
1328
|
+
if (!Object.hasOwn(current, key)) return void 0;
|
|
1329
|
+
current = current[key];
|
|
1330
|
+
}
|
|
1331
|
+
return current;
|
|
1332
|
+
}
|
|
1333
|
+
function refuseSecretBoxes(address, value, path) {
|
|
1334
|
+
if (isSecretSource(value) || isParamSource(value)) return;
|
|
1335
|
+
if (isSecretString(value)) throw new LoadError(`${describeSite({
|
|
1336
|
+
address,
|
|
1337
|
+
kind: "moduleInput",
|
|
1338
|
+
path
|
|
1339
|
+
})} is bound to a SecretString. A secret's value never appears in the code; bind envSecret('NAME'), or pass on an input field typed secretString().`);
|
|
1340
|
+
if (Array.isArray(value)) {
|
|
1341
|
+
for (const [index, member] of value.entries()) refuseSecretBoxes(address, member, joinPath(path, index));
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
if (isPlainObject(value)) for (const [key, member] of Object.entries(value)) refuseSecretBoxes(address, member, joinPath(path, key));
|
|
1345
|
+
}
|
|
1346
|
+
/** The original source each runtime value in `value` names, by its path. */
|
|
1347
|
+
function sourcesByPath(value, path = "", found = /* @__PURE__ */ new Map()) {
|
|
1348
|
+
if (isSecretSource(value) || isParamSource(value)) found.set(path, sourceOriginOf(value)?.source ?? value);
|
|
1349
|
+
else if (Array.isArray(value)) for (const [index, member] of value.entries()) sourcesByPath(member, joinPath(path, index), found);
|
|
1350
|
+
else if (isPlainObject(value)) for (const [key, member] of Object.entries(value)) sourcesByPath(member, joinPath(path, key), found);
|
|
1351
|
+
return found;
|
|
1352
|
+
}
|
|
1353
|
+
function validateModuleInput(entry, resolved, environment) {
|
|
1354
|
+
const address = entry.moduleAddress;
|
|
1355
|
+
refuseSecretBoxes(address, resolved, "");
|
|
1356
|
+
const result = entry.schema["~standard"].validate(resolved);
|
|
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.`);
|
|
1358
|
+
if (result.issues !== void 0) {
|
|
1359
|
+
const messages = result.issues.map((issue) => issue.message).join("; ");
|
|
1360
|
+
if (entry.isLoadRoot) 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}"`}.`);
|
|
1361
|
+
throw new LoadError(`The input binding of module "${address}" does not match the module's input schema: ${messages}`);
|
|
1362
|
+
}
|
|
1363
|
+
const bound = sourcesByPath(resolved);
|
|
1364
|
+
const onlyChecked = "Its value is known only at boot, so a module's schema may check the field but never replace or move it.";
|
|
1365
|
+
const restore = (value, path) => {
|
|
1366
|
+
const expected = bound.get(path);
|
|
1367
|
+
if (isSecretSource(value) || isParamSource(value)) {
|
|
1368
|
+
const source = sourceOriginOf(value)?.source ?? value;
|
|
1369
|
+
if (source !== expected) throw new LoadError(`The input schema of module "${address}" moved ${sourceOriginOf(source)?.label} to input key "${path}". ${onlyChecked}`);
|
|
1370
|
+
return source;
|
|
1371
|
+
}
|
|
1372
|
+
if (expected !== void 0 && value !== void 0) throw new LoadError(`The input schema of module "${address}" replaced input key "${path}", which is bound to ${sourceOriginOf(expected)?.label}. ${onlyChecked}`);
|
|
1373
|
+
if (isSecretString(value)) {
|
|
1374
|
+
const atPath = path === "" ? "" : ` at "${path}"`;
|
|
1375
|
+
throw new LoadError(`The input schema of module "${address}" produced a SecretString${atPath} that its binding did not supply. A module's schema may check a secret field, never create one.`);
|
|
1376
|
+
}
|
|
1377
|
+
if (Array.isArray(value)) return value.map((member, index) => restore(member, joinPath(path, index)));
|
|
1378
|
+
if (isPlainObject(value)) return Object.fromEntries(Object.entries(value).map(([key, member]) => [key, restore(member, joinPath(path, key))]));
|
|
1379
|
+
return value;
|
|
1380
|
+
};
|
|
1381
|
+
return restore(result.value, "");
|
|
1382
|
+
}
|
|
1383
|
+
function refusePointersInProps(address, props) {
|
|
1384
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1385
|
+
const walk = (value, path) => {
|
|
1386
|
+
if (isSecretSource(value) || isParamSource(value)) {
|
|
1387
|
+
const label = sourceOriginOf(value)?.label ?? (isSecretSource(value) ? "a secret source" : "a param source");
|
|
1388
|
+
throw new LoadError(`${describeSite({
|
|
1389
|
+
address,
|
|
1390
|
+
kind: "props",
|
|
1391
|
+
path
|
|
1392
|
+
})} is bound to ${label}, which is known only at boot. A resource's props are read at deploy; bind a value known at deploy.`);
|
|
1393
|
+
}
|
|
1394
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return;
|
|
1395
|
+
if (seen.has(value)) return;
|
|
1396
|
+
seen.add(value);
|
|
1397
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
1398
|
+
for (const [key, member] of entries) walk(member, joinPath(path, key));
|
|
1399
|
+
};
|
|
1400
|
+
walk(props, "");
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Resolves every value the graph binds, dependency-first, once each, and
|
|
1404
|
+
* returns each binding with its values replaced by their real values.
|
|
1405
|
+
*/
|
|
1406
|
+
function resolveValues(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
|
+
};
|
|
1424
|
+
const secretUses = /* @__PURE__ */ new Map();
|
|
1425
|
+
const recordSecret = (source, site) => {
|
|
1426
|
+
const canonical = canonicalSecret(source);
|
|
1427
|
+
if (secretUses.has(canonical)) return;
|
|
1428
|
+
secretUses.set(canonical, {
|
|
1429
|
+
source: canonical,
|
|
1430
|
+
address: site.address,
|
|
1431
|
+
nodeKind: nodeKindOf(site)
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
const secretSourcesReceivedBy = (inputBindings, params) => {
|
|
1435
|
+
for (const { serviceAddress, binding } of [...inputBindings, ...params]) for (const pointer of pointersIn(binding)) {
|
|
1436
|
+
if (!isSecretSource(pointer)) continue;
|
|
1437
|
+
const canonical = canonicalSecret(pointer);
|
|
1438
|
+
if (secretUses.get(canonical)?.nodeKind === "service") continue;
|
|
1439
|
+
secretUses.set(canonical, {
|
|
1440
|
+
source: canonical,
|
|
1441
|
+
address: serviceAddress,
|
|
1442
|
+
nodeKind: "service"
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
return [...secretUses.values()];
|
|
1446
|
+
};
|
|
1447
|
+
const found = [];
|
|
1448
|
+
for (const { serviceAddress, binding } of input.inputBindings) collect(binding, {
|
|
1449
|
+
address: serviceAddress,
|
|
1450
|
+
kind: "serviceInput",
|
|
1451
|
+
path: ""
|
|
1452
|
+
}, found, /* @__PURE__ */ new WeakSet(), recordSecret);
|
|
1453
|
+
for (const { serviceAddress, slot, binding } of input.params) collect(binding, {
|
|
1454
|
+
address: serviceAddress,
|
|
1455
|
+
kind: "param",
|
|
1456
|
+
path: slot
|
|
1457
|
+
}, found, /* @__PURE__ */ new WeakSet(), recordSecret);
|
|
1458
|
+
for (const [address, resource] of input.resources) {
|
|
1459
|
+
const site = {
|
|
1460
|
+
address,
|
|
1461
|
+
kind: "props",
|
|
1462
|
+
path: ""
|
|
1463
|
+
};
|
|
1464
|
+
collect(resource.props, site, found, /* @__PURE__ */ new WeakSet(), recordSecret);
|
|
1465
|
+
}
|
|
1466
|
+
const moduleInputByAddress = new Map(input.moduleInputs.map((entry) => [entry.moduleAddress, entry]));
|
|
1467
|
+
const validatedInputs = /* @__PURE__ */ new Map();
|
|
1468
|
+
const validating = /* @__PURE__ */ new Set();
|
|
1469
|
+
const results = /* @__PURE__ */ new Map();
|
|
1470
|
+
const visiting = [];
|
|
1471
|
+
const fnLabelFor = (site) => visiting.length === 1 ? `The resolve() function for ${describeSite(site)}` : `A resolve() function that ${describeSite(site)} depends on`;
|
|
1472
|
+
const resolveOne = (value, site) => {
|
|
1473
|
+
if (results.has(value)) return results.get(value);
|
|
1474
|
+
if (visiting.includes(value)) throw new LoadError(`${describeSite(site)} depends on itself: a computed value's dependencies lead back to it. Remove the cycle.`);
|
|
1475
|
+
visiting.push(value);
|
|
1476
|
+
const origin = originOf(value);
|
|
1477
|
+
let result;
|
|
1478
|
+
switch (origin.kind) {
|
|
1479
|
+
case "environment":
|
|
1480
|
+
if (environment === void 0) throw new LoadError(`${describeSite(site)} depends on environment.name, but Load was given no environment. Pass { environment: { name } } to Load; the deploy and dev commands do.`);
|
|
1481
|
+
result = environment[origin.fact];
|
|
1482
|
+
break;
|
|
1483
|
+
case "source":
|
|
1484
|
+
if (isSecretSource(origin.source)) recordSecret(origin.source, site);
|
|
1485
|
+
if (origin.sourceKind === "secret" || origin.configurationKey === void 0) result = origin.source;
|
|
1486
|
+
else result = configurationText(origin.configurationKey, origin.label, site);
|
|
1487
|
+
break;
|
|
1488
|
+
case "computed": {
|
|
1489
|
+
const args = origin.dependencies.map((dependency) => {
|
|
1490
|
+
const real = resolveOne(dependency, site);
|
|
1491
|
+
const source = originOf(dependency);
|
|
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.`);
|
|
1493
|
+
refusePointerDependency(fnLabelFor(site), dependency, real);
|
|
1494
|
+
return real;
|
|
1495
|
+
});
|
|
1496
|
+
try {
|
|
1497
|
+
result = origin.compute(args);
|
|
1498
|
+
} catch (thrown) {
|
|
1499
|
+
if (thrown instanceof LoadError && !isSourceMisuse(thrown)) throw thrown;
|
|
1500
|
+
const message = thrown instanceof Error ? thrown.message : String(thrown);
|
|
1501
|
+
throw new LoadError(`${fnLabelFor(site)} threw: ${message}`, { cause: thrown });
|
|
1502
|
+
}
|
|
1503
|
+
checkResult(result, fnLabelFor(site));
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
case "input": {
|
|
1507
|
+
const entry = moduleInputByAddress.get(origin.module);
|
|
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.`);
|
|
1509
|
+
if (origin.path.length === 0) {
|
|
1510
|
+
const everyVariable = entry.isLoadRoot ? " 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.isLoadRoot) rootFields.set(origin.path.join("\0"), result === void 0 ? { path: origin.path } : {
|
|
1520
|
+
path: origin.path,
|
|
1521
|
+
value: result
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
break;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
visiting.pop();
|
|
1528
|
+
results.set(value, result);
|
|
1529
|
+
return result;
|
|
1530
|
+
};
|
|
1531
|
+
const validatedInputOf = (entry) => {
|
|
1532
|
+
if (entry.checked !== void 0) return void 0;
|
|
1533
|
+
if (validatedInputs.has(entry.moduleAddress)) return validatedInputs.get(entry.moduleAddress);
|
|
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.`);
|
|
1535
|
+
validating.add(entry.moduleAddress);
|
|
1536
|
+
const site = {
|
|
1537
|
+
address: entry.moduleAddress,
|
|
1538
|
+
kind: "moduleInput",
|
|
1539
|
+
path: ""
|
|
1540
|
+
};
|
|
1541
|
+
const values = [];
|
|
1542
|
+
collect(entry.binding, site, values, /* @__PURE__ */ new WeakSet(), recordSecret);
|
|
1543
|
+
for (const { value, site: valueSite } of values) resolveOne(value, valueSite);
|
|
1544
|
+
const validated = validateModuleInput(entry, substitute(entry.binding, results, /* @__PURE__ */ new WeakSet(), "resolve"), environment);
|
|
1545
|
+
validating.delete(entry.moduleAddress);
|
|
1546
|
+
validatedInputs.set(entry.moduleAddress, validated);
|
|
1547
|
+
return validated;
|
|
1548
|
+
};
|
|
1549
|
+
const rootModuleAddress = () => input.moduleInputs.find((entry) => entry.isLoadRoot)?.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
|
+
};
|
|
1601
|
+
for (const entry of input.moduleInputs) validatedInputOf(entry);
|
|
1602
|
+
for (const { value, site } of found) resolveOne(value, site);
|
|
1603
|
+
const authoredProps = new Map([...input.resources].map(([address, resource]) => [address, resource.props]));
|
|
1604
|
+
if (found.length === 0) {
|
|
1605
|
+
for (const [address, props] of authoredProps) refusePointersInProps(address, props);
|
|
1606
|
+
const secretSources = secretSourcesReceivedBy(input.inputBindings, input.params);
|
|
1607
|
+
return {
|
|
1608
|
+
inputBindings: input.inputBindings,
|
|
1609
|
+
params: input.params,
|
|
1610
|
+
resourceProps: authoredProps,
|
|
1611
|
+
secretSources,
|
|
1612
|
+
appConfigurationRead: appConfigurationReadOf(input.inputBindings, input.params, secretSources)
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
1616
|
+
const resourceProps = /* @__PURE__ */ new Map();
|
|
1617
|
+
for (const [address, props] of authoredProps) {
|
|
1618
|
+
const substituted = substitute(props, results, inProgress, "resolve");
|
|
1619
|
+
refusePointersInProps(address, substituted);
|
|
1620
|
+
const resolvedProps = substituted === props ? props : blindCast(substituted);
|
|
1621
|
+
resourceProps.set(address, resolvedProps);
|
|
1622
|
+
}
|
|
1623
|
+
const inputBindings = input.inputBindings.map((entry) => {
|
|
1624
|
+
const binding = substitute(entry.binding, results, inProgress, "keep");
|
|
1625
|
+
return binding === entry.binding ? entry : {
|
|
1626
|
+
serviceAddress: entry.serviceAddress,
|
|
1627
|
+
binding: blindCast(binding)
|
|
1628
|
+
};
|
|
1629
|
+
});
|
|
1630
|
+
const params = input.params.flatMap((entry) => {
|
|
1631
|
+
const binding = substitute(entry.binding, results, inProgress, "keep");
|
|
1632
|
+
if (binding === void 0 && isValue(entry.binding)) return [];
|
|
1633
|
+
return [binding === entry.binding ? entry : {
|
|
1634
|
+
...entry,
|
|
1635
|
+
binding
|
|
1636
|
+
}];
|
|
1637
|
+
});
|
|
1638
|
+
const secretSources = secretSourcesReceivedBy(inputBindings, params);
|
|
1639
|
+
return {
|
|
1640
|
+
resourceProps,
|
|
1641
|
+
inputBindings,
|
|
1642
|
+
params,
|
|
1643
|
+
secretSources,
|
|
1644
|
+
appConfigurationRead: appConfigurationReadOf(inputBindings, params, secretSources)
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Brands a ref-port with the AUTHORED endpoint it stands for — which port of
|
|
1649
|
+
* which node the author wired, before any forwarding chain resolves. Read
|
|
1650
|
+
* only by `authoredSourceOf`; `__providerId` keeps carrying the resolved
|
|
1651
|
+
* producer for the flat (post-dereference) edges.
|
|
1652
|
+
*/
|
|
1653
|
+
const AUTHORED_PORT = Symbol("prisma:authored-port");
|
|
1654
|
+
/** The authored out-port brand carried by `ref`, if any. */
|
|
1655
|
+
function authoredPortOf(ref) {
|
|
1656
|
+
if (typeof ref !== "object" || ref === null) return void 0;
|
|
1657
|
+
const brand = blindCast(ref)[AUTHORED_PORT];
|
|
1658
|
+
if (typeof brand !== "object" || brand === null) return void 0;
|
|
1659
|
+
const { node, name } = blindCast(brand);
|
|
1660
|
+
return typeof node === "string" && typeof name === "string" ? {
|
|
1661
|
+
node,
|
|
1662
|
+
name
|
|
1663
|
+
} : void 0;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Builds the ref a provision() call hands back: the id (so a producer with no
|
|
1667
|
+
* exposed ports — or an untyped slot — can still be wired wholesale) plus one
|
|
1668
|
+
* ref-port per exposed contract, each the contract's own runtime value (so
|
|
1669
|
+
* its `satisfies()` still works) tagged with the provider's id.
|
|
1670
|
+
*/
|
|
1671
|
+
function refFor(id, service) {
|
|
1672
|
+
const ports = {};
|
|
1673
|
+
for (const [port, contract] of Object.entries(service.expose ?? {})) ports[port] = {
|
|
1674
|
+
...contract,
|
|
1675
|
+
__providerId: id,
|
|
1676
|
+
[AUTHORED_PORT]: {
|
|
1677
|
+
node: id,
|
|
1678
|
+
name: port
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
return blindCast({
|
|
1682
|
+
id,
|
|
1683
|
+
...ports
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* The resource variant of refFor: a resource has at most one port — the
|
|
1688
|
+
* contract it provides — flattened onto the ref itself, tagged with the
|
|
1689
|
+
* provider id. `id` and the authored brand are written last so a hostile
|
|
1690
|
+
* contract value cannot clobber them. A resource that exposes nothing gets
|
|
1691
|
+
* only its id.
|
|
1692
|
+
*/
|
|
1693
|
+
function refForResource(id, resource) {
|
|
1694
|
+
const provides = resource.provides;
|
|
1695
|
+
if (provides === void 0) return { id };
|
|
1696
|
+
return blindCast({
|
|
1697
|
+
...provides,
|
|
1698
|
+
__providerId: id,
|
|
1699
|
+
id,
|
|
1700
|
+
[AUTHORED_PORT]: {
|
|
1701
|
+
node: id,
|
|
1702
|
+
name: RESOURCE_OUT_PORT
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
/** A wired value's producer id: a ref-port's `__providerId`, or a bare ref's `id`. */
|
|
1707
|
+
function producerIdOf(ref) {
|
|
1708
|
+
if (typeof ref !== "object" || ref === null) return void 0;
|
|
1709
|
+
if ("__providerId" in ref && typeof ref.__providerId === "string") return ref.__providerId;
|
|
1710
|
+
if ("id" in ref && typeof ref.id === "string") return ref.id;
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Brands each `ctx.deps` entry with the input key it stands for (see
|
|
1714
|
+
* flatten): diagnostic only — usage attribution relies on the per-key object
|
|
1715
|
+
* identity the branding copy creates, never on reading this back.
|
|
1716
|
+
*/
|
|
1717
|
+
const MODULE_INPUT_KEY = Symbol("prisma:module-input-key");
|
|
1718
|
+
/** Whether `ref` carries a callable `satisfies` that accepts `required` truthily. */
|
|
1719
|
+
function satisfiesRequired(ref, required) {
|
|
1720
|
+
return typeof ref === "object" && ref !== null && "satisfies" in ref && typeof ref.satisfies === "function" && ref.satisfies(required);
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Checks one recorded `wiring` object against the Deps it was wired against:
|
|
1724
|
+
* every named input exists and is a dependency slot, every referenced
|
|
1725
|
+
* producer is a real (by-now-provisioned) address, and a wired ref whose
|
|
1726
|
+
* slot declares a required contract must satisfy() it — no producer-kind
|
|
1727
|
+
* branching, the contract alone determines validity, whether the producer is
|
|
1728
|
+
* a service port or a resource. Shared by both provisioned kinds so a
|
|
1729
|
+
* module-as-child gets exactly the checks a service gets, and run once per
|
|
1730
|
+
* entry against the one `byId` shared by the whole recursive flatten, so a
|
|
1731
|
+
* forwarded ref resolves through to its real producer address regardless of
|
|
1732
|
+
* which ancestor scope provisioned it.
|
|
1733
|
+
*/
|
|
1734
|
+
function validateWiring(pending, byId) {
|
|
1735
|
+
const { deps, wiring, targetId, targetKind, enclosingModuleName } = pending;
|
|
1736
|
+
for (const [input, ref] of Object.entries(wiring)) {
|
|
1737
|
+
const declared = blindCast(deps[input]);
|
|
1738
|
+
if (declared === void 0 || !isNode(declared) || declared.kind !== "dependency") throw new LoadError(`The deps for "${targetId}" name "${input}", which is not a dependency slot of that ${targetKind}.`);
|
|
1739
|
+
const producerId = producerIdOf(ref);
|
|
1740
|
+
const producer = producerId !== void 0 ? byId.get(producerId) : void 0;
|
|
1741
|
+
if (producerId === void 0 || producer === void 0) throw new LoadError(`The deps for "${targetId}.${input}" reference "${String(producerId)}", which is not provisioned in module "${enclosingModuleName}".`);
|
|
1742
|
+
const required = declared.required;
|
|
1743
|
+
if (required !== void 0 && !satisfiesRequired(ref, required)) throw new LoadError(`The deps for "${targetId}.${input}" do not satisfy the slot's required contract.`);
|
|
1744
|
+
}
|
|
1745
|
+
for (const [input, rawValue] of Object.entries(deps)) {
|
|
1746
|
+
const value = blindCast(rawValue);
|
|
1747
|
+
if (!isNode(value) || wiring[input] !== void 0) continue;
|
|
1748
|
+
if (value.kind === "dependency") throw new LoadError(`Dependency "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
/** The (unvalidated) edges a `wiring` object implies — one dependency edge per entry; `validateWiring` does the real checking. */
|
|
1752
|
+
function wiringEdges(wiring, targetId) {
|
|
1753
|
+
return Object.entries(wiring).map(([input, ref]) => ({
|
|
1754
|
+
from: producerIdOf(ref) ?? "",
|
|
1755
|
+
to: targetId,
|
|
1756
|
+
input,
|
|
1757
|
+
kind: "dependency"
|
|
1758
|
+
}));
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Checks the params wired into a provisioned SERVICE: a declared param is never
|
|
1762
|
+
* required to be bound here — it may fall back to its own `default` (checked
|
|
1763
|
+
* later, at `buildConfig`) — so this only rejects a wired key that names
|
|
1764
|
+
* something other than a real declared param.
|
|
1765
|
+
*/
|
|
1766
|
+
function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName) {
|
|
1767
|
+
for (const slot of Object.keys(paramWiring)) if (!Object.hasOwn(child.params, slot)) throw new LoadError(`The params for "${id}" name "${slot}", which is not a param of that service (module "${enclosingModuleName}").`);
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Recursively flattens one module's body into the shared graph state and
|
|
1771
|
+
* returns its resolved ModuleOutputs (one ref-port per expose key) for the
|
|
1772
|
+
* caller (the enclosing provision() call, or Load itself for the root) to
|
|
1773
|
+
* use. `wiring` supplies a
|
|
1774
|
+
* resolved producer ref-port for each of this module's OWN declared deps (empty
|
|
1775
|
+
* for the root, which may not declare any — see the root non-empty-deps
|
|
1776
|
+
* check in loadModule). `nodes`, `edges`, `pending`, and `byId` are shared
|
|
1777
|
+
* across the ENTIRE recursive flatten, not per scope — a nested module may
|
|
1778
|
+
* forward in a producer provisioned by an ancestor scope, and it is the
|
|
1779
|
+
* shared `byId` (keyed by full address) that lets that resolve.
|
|
1780
|
+
*
|
|
1781
|
+
* `selfId` is this module's own full address — for the root, the deployed app
|
|
1782
|
+
* name (ADR-0057). Every child's address is `selfId` plus its provision id, so
|
|
1783
|
+
* every address starts with the app name. It also anchors the authored view:
|
|
1784
|
+
* children carry it as their `parent`, and this module's own boundary ports
|
|
1785
|
+
* (and the authored edges touching them) are recorded against it.
|
|
1786
|
+
*/
|
|
1787
|
+
function flatten(moduleNode, selfId, wiring, nodes, edges, pending, inputBindings, paramBindings, moduleInputs, byId, ports, authoredEdges, loading) {
|
|
1788
|
+
ports.push(...boundaryPortsOf(selfId, moduleNode));
|
|
1789
|
+
const localIds = /* @__PURE__ */ new Set();
|
|
1790
|
+
const used = /* @__PURE__ */ new Set();
|
|
1791
|
+
const ctxInputs = {};
|
|
1792
|
+
for (const key of Object.keys(moduleNode.deps)) {
|
|
1793
|
+
const wired = wiring[key];
|
|
1794
|
+
ctxInputs[key] = typeof wired === "object" && wired !== null ? {
|
|
1795
|
+
...wired,
|
|
1796
|
+
[MODULE_INPUT_KEY]: key
|
|
1797
|
+
} : wired;
|
|
1798
|
+
}
|
|
1799
|
+
const markUsed = (values) => {
|
|
1800
|
+
for (const value of values) for (const key of Object.keys(ctxInputs)) if (value === ctxInputs[key]) used.add(key);
|
|
1801
|
+
};
|
|
1802
|
+
const authoredSourceOf = (value) => {
|
|
1803
|
+
for (const key of Object.keys(ctxInputs)) if (value === ctxInputs[key]) return {
|
|
1804
|
+
node: selfId,
|
|
1805
|
+
direction: "in",
|
|
1806
|
+
name: key
|
|
1807
|
+
};
|
|
1808
|
+
const brand = authoredPortOf(value);
|
|
1809
|
+
return brand === void 0 ? void 0 : {
|
|
1810
|
+
node: brand.node,
|
|
1811
|
+
direction: "out",
|
|
1812
|
+
name: brand.name
|
|
1813
|
+
};
|
|
1814
|
+
};
|
|
1815
|
+
/** Records the authored edge each wiring entry declares: source port → the target's own `in` port. */
|
|
1816
|
+
const recordAuthoredWiring = (targetId, targetWiring) => {
|
|
1817
|
+
for (const [input, ref] of Object.entries(targetWiring)) {
|
|
1818
|
+
const from = authoredSourceOf(ref);
|
|
1819
|
+
if (from !== void 0) authoredEdges.push({
|
|
1820
|
+
from,
|
|
1821
|
+
to: {
|
|
1822
|
+
node: targetId,
|
|
1823
|
+
direction: "in",
|
|
1824
|
+
name: input
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
const provision = (child, opts) => {
|
|
1830
|
+
if (loading.sealed) throw new LoadError(`provision() was called after module "${moduleNode.name}" was loaded, from inside a resolve() function. resolve() computes values, never structure: the graph is the same whatever inputs Composer is given (ADR-0062). Provision the node in the module body and pass the value into it.`);
|
|
1831
|
+
const id = opts?.id ?? child.name;
|
|
1832
|
+
const provisionWiring = opts?.deps;
|
|
1833
|
+
const provisionSecrets = opts?.secrets;
|
|
1834
|
+
const provisionInput = opts?.input;
|
|
1835
|
+
const provisionParams = opts?.params;
|
|
1836
|
+
if (isValue(id)) throw new LoadError(`provision() received a value as its id (module "${moduleNode.name}"). A value can configure a node, never decide its address: the graph is the same whatever inputs Composer is given (ADR-0062).`);
|
|
1837
|
+
if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
|
|
1838
|
+
if (!isConfigKeySegment(id)) throw new LoadError(`provision() id "${id}" (module "${moduleNode.name}") must contain only ASCII letters and digits ([A-Za-z0-9]) — the id becomes an address segment, and addresses derive deterministic config keys (segments uppercased and joined with "_"). "${id}" would put "${id.toUpperCase()}" inside the derived key. ("_" collides with the key separator and "." with the address separator.)`);
|
|
1839
|
+
if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
|
|
1840
|
+
const untrusted = child;
|
|
1841
|
+
if (!isNode(untrusted) || untrusted.kind !== "service" && untrusted.kind !== "resource" && untrusted.kind !== "module") throw new LoadError(`provision("${id}") expects a branded service, resource, or module node (construct it with the service()/resource()/module() factories or a pack's own).`);
|
|
1842
|
+
if (untrusted.kind === "module" && typeof untrusted.isRoot === "function" && untrusted.isRoot()) throw new LoadError(`Module "${selfId}" provisions the app root "${untrusted.name}". An app root is the deploy's entry and cannot be provisioned. Build the module with module() instead.`);
|
|
1843
|
+
localIds.add(id);
|
|
1844
|
+
const fullAddress = `${selfId}.${id}`;
|
|
1845
|
+
if (child.kind === "resource") {
|
|
1846
|
+
if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource's slots are wired when it is constructed, not at provision().`);
|
|
1847
|
+
if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
|
|
1848
|
+
if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
|
|
1849
|
+
if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
|
|
1850
|
+
if (child.type.length === 0) throw new LoadError(`provision("${id}") received a resource with an empty node type.`);
|
|
1851
|
+
const localWiring = { ...child.deps };
|
|
1852
|
+
markUsed(Object.values(localWiring));
|
|
1853
|
+
byId.set(fullAddress, child);
|
|
1854
|
+
const slots = slotNodesAndEdges(child, fullAddress);
|
|
1855
|
+
nodes.push(...slots.nodes, {
|
|
1856
|
+
id: fullAddress,
|
|
1857
|
+
parent: selfId,
|
|
1858
|
+
node: child
|
|
1859
|
+
});
|
|
1860
|
+
edges.push(...slots.edges, ...wiringEdges(localWiring, fullAddress));
|
|
1861
|
+
ports.push(...boundaryPortsOf(fullAddress, child));
|
|
1862
|
+
const provides = child.provides;
|
|
1863
|
+
if (provides !== void 0) ports.push({
|
|
1864
|
+
node: fullAddress,
|
|
1865
|
+
direction: "out",
|
|
1866
|
+
name: RESOURCE_OUT_PORT,
|
|
1867
|
+
contractKind: provides.kind,
|
|
1868
|
+
style: contractStyleOf(provides)
|
|
1869
|
+
});
|
|
1870
|
+
recordAuthoredWiring(fullAddress, localWiring);
|
|
1871
|
+
pending.push({
|
|
1872
|
+
deps: child.inputs ?? {},
|
|
1873
|
+
wiring: localWiring,
|
|
1874
|
+
targetId: fullAddress,
|
|
1875
|
+
targetKind: "resource",
|
|
1876
|
+
enclosingModuleName: moduleNode.name
|
|
1877
|
+
});
|
|
1878
|
+
return refForResource(fullAddress, child);
|
|
1879
|
+
}
|
|
1880
|
+
for (const [input, ref] of Object.entries(provisionWiring ?? {})) if (isValue(ref)) throw new LoadError(`The deps for "${fullAddress}.${input}" are bound to a value. A value can configure a node, never decide its edges: the graph is the same whatever inputs Composer is given (ADR-0062).`);
|
|
1881
|
+
const localWiring = { ...provisionWiring ?? {} };
|
|
1882
|
+
markUsed(Object.values(localWiring));
|
|
1883
|
+
const localParams = { ...provisionParams ?? {} };
|
|
1884
|
+
if (child.kind === "service") {
|
|
1885
|
+
if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a service — a service takes its secrets as envSecret(...) leaves of its \`input\` binding (ADR-0042), not a secrets map.`);
|
|
1886
|
+
if (child.inputSchema !== void 0 && provisionInput === void 0) throw new LoadError(`Input of provisioned service "${id}" is not bound (module "${moduleNode.name}") — the service declares an input schema; bind it with \`input: { … }\` on its provision() call.`);
|
|
1887
|
+
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}").`);
|
|
1888
|
+
if (provisionInput !== void 0) inputBindings.push({
|
|
1889
|
+
serviceAddress: fullAddress,
|
|
1890
|
+
binding: provisionInput
|
|
1891
|
+
});
|
|
1892
|
+
validateServiceParamBinding(child, id, localParams, moduleNode.name);
|
|
1893
|
+
for (const [slot, binding] of Object.entries(localParams)) paramBindings.push({
|
|
1894
|
+
serviceAddress: fullAddress,
|
|
1895
|
+
slot,
|
|
1896
|
+
binding
|
|
1897
|
+
});
|
|
1898
|
+
const inputs = slotNodesAndEdges(child, fullAddress);
|
|
1899
|
+
nodes.push(...inputs.nodes, {
|
|
1900
|
+
id: fullAddress,
|
|
1901
|
+
parent: selfId,
|
|
1902
|
+
node: child
|
|
1903
|
+
});
|
|
1904
|
+
edges.push(...inputs.edges, ...wiringEdges(localWiring, fullAddress));
|
|
1905
|
+
ports.push(...boundaryPortsOf(fullAddress, child));
|
|
1906
|
+
recordAuthoredWiring(fullAddress, localWiring);
|
|
1907
|
+
pending.push({
|
|
1908
|
+
deps: child.inputs,
|
|
1909
|
+
wiring: localWiring,
|
|
1910
|
+
targetId: fullAddress,
|
|
1911
|
+
targetKind: "service",
|
|
1912
|
+
enclosingModuleName: moduleNode.name
|
|
1913
|
+
});
|
|
1914
|
+
byId.set(fullAddress, child);
|
|
1915
|
+
return refFor(fullAddress, child);
|
|
1916
|
+
}
|
|
1917
|
+
if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a module, which a module no longer takes. A module takes a secret as a secretString() field of its \`input\` binding (ADR-0061), not a secrets map.`);
|
|
1918
|
+
if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a module, which a module no longer takes. A module takes its values as fields of its \`input\` binding (ADR-0061), not a params map.`);
|
|
1919
|
+
const childInputSchema = child.inputSchema;
|
|
1920
|
+
if (childInputSchema === void 0 && provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding, but the module declares no input schema (module "${moduleNode.name}").`);
|
|
1921
|
+
if (childInputSchema !== void 0 && provisionInput === void 0) throw new LoadError(`Input of provisioned module "${id}" is not bound (module "${moduleNode.name}") — the module declares an input schema; bind it with \`input: { … }\` on its provision() call.`);
|
|
1922
|
+
if (childInputSchema !== void 0) moduleInputs.push({
|
|
1923
|
+
moduleAddress: fullAddress,
|
|
1924
|
+
schema: childInputSchema,
|
|
1925
|
+
binding: provisionInput,
|
|
1926
|
+
isLoadRoot: false
|
|
1927
|
+
});
|
|
1928
|
+
edges.push(...wiringEdges(localWiring, fullAddress));
|
|
1929
|
+
recordAuthoredWiring(fullAddress, localWiring);
|
|
1930
|
+
pending.push({
|
|
1931
|
+
deps: child.deps,
|
|
1932
|
+
wiring: localWiring,
|
|
1933
|
+
targetId: fullAddress,
|
|
1934
|
+
targetKind: "module",
|
|
1935
|
+
enclosingModuleName: moduleNode.name
|
|
1936
|
+
});
|
|
1937
|
+
const childOutputs = flatten(child, fullAddress, localWiring, nodes, edges, pending, inputBindings, paramBindings, moduleInputs, byId, ports, authoredEdges, loading);
|
|
1938
|
+
nodes.push({
|
|
1939
|
+
id: fullAddress,
|
|
1940
|
+
parent: selfId,
|
|
1941
|
+
node: child
|
|
1942
|
+
});
|
|
1943
|
+
byId.set(fullAddress, child);
|
|
1944
|
+
const brandedOutputs = {};
|
|
1945
|
+
for (const [key, value] of Object.entries(childOutputs)) brandedOutputs[key] = typeof value === "object" && value !== null ? {
|
|
1946
|
+
...value,
|
|
1947
|
+
[AUTHORED_PORT]: {
|
|
1948
|
+
node: fullAddress,
|
|
1949
|
+
name: key
|
|
1950
|
+
}
|
|
1951
|
+
} : value;
|
|
1952
|
+
return blindCast({
|
|
1953
|
+
id: fullAddress,
|
|
1954
|
+
...brandedOutputs
|
|
1955
|
+
});
|
|
1956
|
+
};
|
|
1957
|
+
const ctx = blindCast({
|
|
1958
|
+
deps: ctxInputs,
|
|
1959
|
+
input: moduleNode.inputSchema === void 0 ? void 0 : buildModuleInput(selfId),
|
|
1960
|
+
environment: environmentFacts,
|
|
1961
|
+
provision: blindCast(provision)
|
|
1962
|
+
});
|
|
1963
|
+
const outputs = blindCast(moduleNode.body(ctx) ?? {});
|
|
1964
|
+
markUsed(Object.values(outputs));
|
|
1965
|
+
for (const key of Object.keys(moduleNode.deps)) if (!used.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares dependency "${key}" but never forwards it into a provision nor returns it as an exposed interface.`);
|
|
1966
|
+
for (const [key, contract] of Object.entries(moduleNode.expose)) {
|
|
1967
|
+
const port = outputs[key];
|
|
1968
|
+
if (port === void 0) throw new LoadError(`Module "${moduleNode.name}" declares expose "${key}" but its body did not return a port for it.`);
|
|
1969
|
+
if (isValue(port)) throw new LoadError(`Module "${moduleNode.name}" returned a value for expose "${key}". A value can configure a node, never decide its edges: return a port of a node the body provisions.`);
|
|
1970
|
+
if (!satisfiesRequired(port, contract)) throw new LoadError(`Module "${moduleNode.name}"'s returned port for expose "${key}" does not satisfy its declared contract.`);
|
|
1971
|
+
const from = authoredSourceOf(port);
|
|
1972
|
+
if (from !== void 0) authoredEdges.push({
|
|
1973
|
+
from,
|
|
1974
|
+
to: {
|
|
1975
|
+
node: selfId,
|
|
1976
|
+
direction: "out",
|
|
1977
|
+
name: key
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
return outputs;
|
|
1982
|
+
}
|
|
1983
|
+
function loadModule(root, opts) {
|
|
1984
|
+
const rootId = opts?.id ?? root.name;
|
|
1985
|
+
const rootDepKeys = Object.keys(root.deps);
|
|
1986
|
+
if (rootDepKeys.length > 0) {
|
|
1987
|
+
const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
|
|
1988
|
+
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.`);
|
|
1989
|
+
}
|
|
1990
|
+
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.");
|
|
1991
|
+
const moduleInputs = [];
|
|
1992
|
+
if (root.inputSchema !== void 0) if (opts?.appConfigurationRead !== void 0) moduleInputs.push({
|
|
1993
|
+
moduleAddress: rootId,
|
|
1994
|
+
schema: root.inputSchema,
|
|
1995
|
+
binding: void 0,
|
|
1996
|
+
isLoadRoot: true,
|
|
1997
|
+
checked: opts.appConfigurationRead.rootInput
|
|
1998
|
+
});
|
|
1999
|
+
else if (opts?.configuration !== void 0) moduleInputs.push({
|
|
2000
|
+
moduleAddress: rootId,
|
|
2001
|
+
schema: root.inputSchema,
|
|
2002
|
+
binding: opts.configuration,
|
|
2003
|
+
isLoadRoot: true
|
|
2004
|
+
});
|
|
2005
|
+
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.`);
|
|
2006
|
+
const nodes = [];
|
|
2007
|
+
const edges = [];
|
|
2008
|
+
const pending = [];
|
|
2009
|
+
const inputBindings = [];
|
|
2010
|
+
const paramBindings = [];
|
|
2011
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2012
|
+
const ports = [];
|
|
2013
|
+
const authoredEdges = [];
|
|
2014
|
+
const loading = { sealed: false };
|
|
2015
|
+
try {
|
|
2016
|
+
flatten(root, rootId, {}, nodes, edges, pending, inputBindings, paramBindings, moduleInputs, byId, ports, authoredEdges, loading);
|
|
2017
|
+
for (const entry of pending) validateWiring(entry, byId);
|
|
2018
|
+
assertDependencyDag(edges);
|
|
2019
|
+
} finally {
|
|
2020
|
+
loading.sealed = true;
|
|
2021
|
+
}
|
|
2022
|
+
const resources = /* @__PURE__ */ new Map();
|
|
2023
|
+
for (const [address, node] of byId) if (node.kind === "resource") resources.set(address, node);
|
|
2024
|
+
const resolved = resolveValues({
|
|
2025
|
+
environment: opts?.environment,
|
|
2026
|
+
configuration: opts?.configuration,
|
|
2027
|
+
appConfigurationRead: opts?.appConfigurationRead,
|
|
2028
|
+
inputBindings,
|
|
2029
|
+
params: paramBindings,
|
|
2030
|
+
moduleInputs,
|
|
2031
|
+
resources
|
|
2032
|
+
});
|
|
2033
|
+
const resolvedNodes = nodes.map((entry) => {
|
|
2034
|
+
const props = resolved.resourceProps.get(entry.id);
|
|
2035
|
+
if (entry.node.kind !== "resource" || props === void 0 || props === entry.node.props) return entry;
|
|
2036
|
+
return {
|
|
2037
|
+
...entry,
|
|
2038
|
+
node: withResolvedProps(entry.node, props)
|
|
2039
|
+
};
|
|
2040
|
+
});
|
|
2041
|
+
const rootGraphNode = {
|
|
2042
|
+
id: rootId,
|
|
2043
|
+
parent: void 0,
|
|
2044
|
+
node: root
|
|
2045
|
+
};
|
|
2046
|
+
return {
|
|
2047
|
+
root: rootGraphNode,
|
|
2048
|
+
nodes: [...topoSort(resolvedNodes, edges), rootGraphNode],
|
|
2049
|
+
edges,
|
|
2050
|
+
ports,
|
|
2051
|
+
authoredEdges,
|
|
2052
|
+
inputBindings: resolved.inputBindings,
|
|
2053
|
+
params: resolved.params,
|
|
2054
|
+
secretSources: resolved.secretSources,
|
|
2055
|
+
appConfigurationRead: resolved.appConfigurationRead
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* A frozen copy of `node` holding `props`, keeping its prototype (a class built
|
|
2060
|
+
* on `ResourceNodeBase` keeps its methods) and its own properties, the brand included.
|
|
2061
|
+
*/
|
|
2062
|
+
function withResolvedProps(node, props) {
|
|
2063
|
+
return Object.freeze(Object.create(Object.getPrototypeOf(node), {
|
|
2064
|
+
...Object.getOwnPropertyDescriptors(node),
|
|
2065
|
+
props: {
|
|
2066
|
+
value: Object.freeze(props),
|
|
2067
|
+
enumerable: true,
|
|
2068
|
+
writable: false,
|
|
2069
|
+
configurable: false
|
|
2070
|
+
}
|
|
2071
|
+
}));
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* The dependency edges must form a DAG — a cycle means neither producer can
|
|
2075
|
+
* deploy first. A resource with dependency slots can take part in a cycle too.
|
|
2076
|
+
*/
|
|
2077
|
+
function assertDependencyDag(edges) {
|
|
2078
|
+
const adjacency = /* @__PURE__ */ new Map();
|
|
2079
|
+
for (const edge of edges) {
|
|
2080
|
+
if (edge.kind !== "dependency") continue;
|
|
2081
|
+
const targets = adjacency.get(edge.from) ?? [];
|
|
2082
|
+
targets.push(edge.to);
|
|
2083
|
+
adjacency.set(edge.from, targets);
|
|
2084
|
+
}
|
|
2085
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2086
|
+
const done = /* @__PURE__ */ new Set();
|
|
2087
|
+
const stack = [];
|
|
2088
|
+
const visit = (id) => {
|
|
2089
|
+
if (done.has(id)) return;
|
|
2090
|
+
if (visiting.has(id)) throw new LoadError(`Dependency cycle: ${[...stack.slice(stack.indexOf(id)), id].join(" → ")} — no deploy order exists.`);
|
|
2091
|
+
visiting.add(id);
|
|
2092
|
+
stack.push(id);
|
|
2093
|
+
for (const next of adjacency.get(id) ?? []) visit(next);
|
|
2094
|
+
stack.pop();
|
|
2095
|
+
visiting.delete(id);
|
|
2096
|
+
done.add(id);
|
|
2097
|
+
};
|
|
2098
|
+
for (const id of adjacency.keys()) visit(id);
|
|
2099
|
+
}
|
|
2100
|
+
const APP_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2101
|
+
/**
|
|
2102
|
+
* Throws unless `name` can be an app name: the root's address and the first segment of every
|
|
2103
|
+
* other address (ADR-0057). A `.` would split it, and it becomes part of every `COMPOSER_` key.
|
|
2104
|
+
*/
|
|
2105
|
+
function assertAppName(name) {
|
|
2106
|
+
if (!APP_NAME.test(name)) throw new LoadError(`The app name "${name}" is not valid. An app name (the root module's name, or --name) must start with a letter or digit and contain only letters, digits, "-" and "_".`);
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Builds the in-memory graph from a root node. A service root walks its own
|
|
2110
|
+
* `inputs`; a module root executes its body (wiring, not user code — the
|
|
2111
|
+
* designed exception to imports-run-nothing) and recursively flattens every
|
|
2112
|
+
* module it provisions into one graph of hierarchical addresses. A malformed
|
|
2113
|
+
* graph is a `LoadError` that names its fix; the individual validation rules
|
|
2114
|
+
* live with `loadService` / `loadModule` and are covered by name in the Load
|
|
2115
|
+
* tests. Executes nothing of the user's own code beyond module bodies and `resolve()`
|
|
2116
|
+
* functions.
|
|
2117
|
+
*/
|
|
2118
|
+
function Load(root, opts) {
|
|
2119
|
+
if (!isNode(root)) throw new LoadError("Load expects a branded service, module or app root node (construct it with the service(), module() or appRoot() factories).");
|
|
2120
|
+
if (root.kind === "module") {
|
|
2121
|
+
assertAppName(opts?.id ?? root.name);
|
|
2122
|
+
return loadModule(root, opts);
|
|
2123
|
+
}
|
|
2124
|
+
if (root.kind === "service") return loadService(root, opts?.id ?? "root");
|
|
2125
|
+
throw new LoadError("Load expects a service, module or app root (received another node kind).");
|
|
2126
|
+
}
|
|
2127
|
+
/** 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. */
|
|
2128
|
+
function secretsKeys(graph) {
|
|
2129
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2130
|
+
for (const { source } of graph.secretSources) {
|
|
2131
|
+
const origin = sourceOriginOf(source);
|
|
2132
|
+
const key = origin?.sourceKind === "secret" ? origin.secretsKey : void 0;
|
|
2133
|
+
if (key !== void 0) keys.add(key);
|
|
2134
|
+
}
|
|
2135
|
+
return [...keys];
|
|
2136
|
+
}
|
|
2137
|
+
/** The address of every node in the graph, sorted. Two Loads of the same graph give the same list. */
|
|
2138
|
+
function nodeAddresses(graph) {
|
|
2139
|
+
return graph.nodes.map(({ id }) => id).sort();
|
|
2140
|
+
}
|
|
2141
|
+
//#endregion
|
|
2142
|
+
//#region ../../0-framework/3-tooling/cli/dist/validate-environment-CpQLC3CA.mjs
|
|
2143
|
+
function adapterInvalid(list, index, input, summary, fix) {
|
|
2144
|
+
return new CliStructuredError("CONFIG.ADAPTER_INVALID", summary, {
|
|
2145
|
+
fix,
|
|
2146
|
+
where: { path: input.configFile },
|
|
2147
|
+
meta: { field: `${list}[${index}]` }
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
function isValues(value) {
|
|
2151
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2152
|
+
}
|
|
2153
|
+
function isText(values) {
|
|
2154
|
+
return Object.values(values).every((value) => typeof value === "string");
|
|
2155
|
+
}
|
|
2156
|
+
async function readAdapters(list, adapters, input) {
|
|
2157
|
+
const adapterInput = Object.freeze({
|
|
2158
|
+
environment: input.environment,
|
|
2159
|
+
configDirectory: path.dirname(input.configFile)
|
|
2160
|
+
});
|
|
2161
|
+
const merged = Object.create(null);
|
|
2162
|
+
for (const [index, adapter] of adapters.entries()) {
|
|
2163
|
+
const field = `composer.${list}[${index}]`;
|
|
2164
|
+
let values;
|
|
2165
|
+
try {
|
|
2166
|
+
values = await adapter(adapterInput);
|
|
2167
|
+
} catch (thrown) {
|
|
2168
|
+
throw new CliStructuredError("CONFIG.ADAPTER_FAILED", `\`${field}\` failed to read the values for the environment "${input.environment}".`, {
|
|
2169
|
+
why: `It threw: ${thrown instanceof Error ? thrown.message : String(thrown)}`,
|
|
2170
|
+
fix: `Fix the adapter, or remove it from \`composer.${list}\` in prisma.config.ts.`,
|
|
2171
|
+
where: { path: input.configFile },
|
|
2172
|
+
meta: { field: `${list}[${index}]` },
|
|
2173
|
+
cause: thrown
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
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`.");
|
|
2177
|
+
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' }`.");
|
|
2178
|
+
for (const [key, value] of Object.entries(values)) {
|
|
2179
|
+
if (value === void 0) continue;
|
|
2180
|
+
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.");
|
|
2181
|
+
merged[key] = value;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
return Object.freeze(merged);
|
|
2185
|
+
}
|
|
2186
|
+
/** Calls the section's `config` adapters (default `[environmentVariables()]`) and merges what they return: the app configuration. */
|
|
2187
|
+
function readAppConfiguration(section, input) {
|
|
2188
|
+
return readAdapters("config", section.config ?? [environmentVariables()], input);
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* Calls the section's `secrets` adapters (default `[environmentVariables()]`) and merges what they
|
|
2192
|
+
* return: the app secrets. Every value must be text. A value is a known secret only once the graph
|
|
2193
|
+
* names it, so this adds none.
|
|
2194
|
+
*/
|
|
2195
|
+
async function readAppSecrets(section, input) {
|
|
2196
|
+
const merged = await readAdapters("secrets", section.secrets ?? [environmentVariables()], input);
|
|
2197
|
+
if (!isText(merged)) throw new InternalError("readAdapters admitted a secret that is not text");
|
|
2198
|
+
return merged;
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Synchronous Node resolve hook so that entry modules may import relative
|
|
2202
|
+
* files using the specifier forms TypeScript accepts by default —
|
|
2203
|
+
* extensionless `./service` and `./service.js` for a `.ts` source file —
|
|
2204
|
+
* without requiring `allowImportingTsExtensions` in every consumer's tsconfig.
|
|
2205
|
+
*
|
|
2206
|
+
* Resolution only; uses TypeScript's own documented mapping: for a specifier
|
|
2207
|
+
* Node could not resolve, strip any JS-family extension and probe the
|
|
2208
|
+
* corresponding TypeScript source; first candidate that exists on disk wins.
|
|
2209
|
+
* Format-specific rules: `.mjs` → `.mts`; `.cjs` → `.cts`; `.js` and
|
|
2210
|
+
* extensionless → `.ts`, `.mts`, `.tsx`, then `./index.ts`. Bare and package
|
|
2211
|
+
* specifiers are never touched. Existing `./x.ts` imports keep working —
|
|
2212
|
+
* Node resolves them before the hook fires (ADR-0005: no transform, no
|
|
2213
|
+
* guessing, deterministic TypeScript rule).
|
|
2214
|
+
*
|
|
2215
|
+
* Bun resolves `./x.js` and `./x` to `x.ts` natively, so the hook is a
|
|
2216
|
+
* no-op under Bun. Nothing is registered there.
|
|
2217
|
+
*/
|
|
2218
|
+
let registered = false;
|
|
2219
|
+
/**
|
|
2220
|
+
* Registers the resolve hook once (idempotent). Call at the start of
|
|
2221
|
+
* `loadEntry` so every module in the entry graph benefits, including those
|
|
2222
|
+
* imported lazily after the entry itself loads.
|
|
2223
|
+
*/
|
|
2224
|
+
function registerEntryResolution() {
|
|
2225
|
+
if (registered || typeof process.versions.bun === "string") return;
|
|
2226
|
+
if (typeof mod.registerHooks !== "function") return;
|
|
2227
|
+
registered = true;
|
|
2228
|
+
mod.registerHooks({ resolve(specifier, context, nextResolve) {
|
|
2229
|
+
try {
|
|
2230
|
+
return nextResolve(specifier, context);
|
|
2231
|
+
} catch (error) {
|
|
2232
|
+
if (!isRelativeSpecifier(specifier) || context.parentURL === void 0 || !isModuleNotFoundError(error)) throw error;
|
|
2233
|
+
for (const candidate of sourceCandidates(new URL(specifier, context.parentURL))) if (existsSync(fileURLToPath(candidate))) return nextResolve(candidate.href, context);
|
|
2234
|
+
throw error;
|
|
2235
|
+
}
|
|
2236
|
+
} });
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* TypeScript's extension mapping: for a JS-family or extensionless URL,
|
|
2240
|
+
* produce the source candidates to probe. Format-specific: `.mjs` maps only
|
|
2241
|
+
* to `.mts`; `.cjs` maps only to `.cts`; `.js` and extensionless probe
|
|
2242
|
+
* `.ts`, `.mts`, `.tsx` (keeping `.tsx` so the JSX diagnostic fires), then
|
|
2243
|
+
* `./index.ts`.
|
|
2244
|
+
*/
|
|
2245
|
+
function sourceCandidates(resolved) {
|
|
2246
|
+
const href = resolved.href;
|
|
2247
|
+
if (href.endsWith(".mjs")) {
|
|
2248
|
+
const base = href.slice(0, -4);
|
|
2249
|
+
return [new URL(`${base}.mts`)];
|
|
2250
|
+
}
|
|
2251
|
+
if (href.endsWith(".cjs")) {
|
|
2252
|
+
const base = href.slice(0, -4);
|
|
2253
|
+
return [new URL(`${base}.cts`)];
|
|
2254
|
+
}
|
|
2255
|
+
const base = href.endsWith(".js") ? href.slice(0, -3) : href;
|
|
2256
|
+
return [
|
|
2257
|
+
new URL(`${base}.ts`),
|
|
2258
|
+
new URL(`${base}.mts`),
|
|
2259
|
+
new URL(`${base}.tsx`),
|
|
2260
|
+
new URL(`${base}/index.ts`)
|
|
2261
|
+
];
|
|
2262
|
+
}
|
|
2263
|
+
function isRelativeSpecifier(specifier) {
|
|
2264
|
+
return specifier.startsWith("./") || specifier.startsWith("../");
|
|
2265
|
+
}
|
|
2266
|
+
function isModuleNotFoundError(error) {
|
|
2267
|
+
if (!(error instanceof Error)) return false;
|
|
2268
|
+
if (!("code" in error)) return false;
|
|
2269
|
+
return error.code === "ERR_MODULE_NOT_FOUND";
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* `loadEntry` imports a user's topology with the host runtime's own module
|
|
2273
|
+
* loader — under node (the CLI's shebang runtime), that loader strips
|
|
2274
|
+
* TypeScript types but has no JSX transform (ADR-0005: the framework
|
|
2275
|
+
* doesn't bundle or transform the app's code; deploy loading is no
|
|
2276
|
+
* exception). A `.tsx`/`.jsx` file anywhere in the topology's import graph
|
|
2277
|
+
* dies with node's raw `ERR_UNKNOWN_FILE_EXTENSION`, which names the file
|
|
2278
|
+
* but not the cause or the fix. This turns that one case into structured
|
|
2279
|
+
* error parts (summary/why/fix) that do — every other load failure (syntax
|
|
2280
|
+
* errors, missing files, non-JSX unknown extensions) is untouched.
|
|
2281
|
+
*/
|
|
2282
|
+
const UNKNOWN_EXTENSION_CODE = "ERR_UNKNOWN_FILE_EXTENSION";
|
|
2283
|
+
const JSX_EXTENSIONS = [".tsx", ".jsx"];
|
|
2284
|
+
function errorCode(error) {
|
|
2285
|
+
return "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
2286
|
+
}
|
|
2287
|
+
function unknownExtensionPath(error) {
|
|
2288
|
+
if (!(error instanceof Error)) return void 0;
|
|
2289
|
+
if (errorCode(error) !== UNKNOWN_EXTENSION_CODE) return void 0;
|
|
2290
|
+
return /Unknown file extension "\.\w+" for (.+)$/.exec(error.message)?.[1];
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Returns structured error parts when `error` is node's
|
|
2294
|
+
* `ERR_UNKNOWN_FILE_EXTENSION` for a `.tsx`/`.jsx` file — `undefined` for
|
|
2295
|
+
* every other error (including unknown-extension failures for some other
|
|
2296
|
+
* extension), so the caller can fall through to its normal rethrow.
|
|
2297
|
+
*/
|
|
2298
|
+
function explainJsxLoadError(error, entryPath) {
|
|
2299
|
+
const offendingPath = unknownExtensionPath(error);
|
|
2300
|
+
if (offendingPath === void 0) return void 0;
|
|
2301
|
+
if (!JSX_EXTENSIONS.some((ext) => offendingPath.endsWith(ext))) return void 0;
|
|
2302
|
+
return {
|
|
2303
|
+
summary: `"${offendingPath}" can't be loaded.`,
|
|
2304
|
+
why: `deploy loads "${entryPath}"'s topology with node's own module loader, which strips TypeScript types but has no JSX transform — so a .tsx/.jsx file can't sit anywhere in that import graph.`,
|
|
2305
|
+
fix: "Precompile that file in your own build (transform the JSX away, keep the real npm packages external) and import the compiled output instead of the raw .tsx/.jsx — see examples/email/scripts/build.ts in the prisma/composer repo for a worked example."
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Pipeline step 2 (deploy-cli.md § The pipeline): import the entry module
|
|
2310
|
+
* (resolved against cwd) and require its default export to be the app's root:
|
|
2311
|
+
* an app root built with `appRoot()`, or a module built with `module()`
|
|
2312
|
+
* (ADR-0003).
|
|
2313
|
+
*/
|
|
2314
|
+
/** `unloadableFix`, when given, says where the path came from, so a wrong path names its source. */
|
|
2315
|
+
async function loadEntry(entryArg, cwd, unloadableFix) {
|
|
2316
|
+
registerEntryResolution();
|
|
2317
|
+
const resolvedPath = path.resolve(cwd, entryArg);
|
|
2318
|
+
let mod;
|
|
2319
|
+
try {
|
|
2320
|
+
mod = await import(pathToFileURL(resolvedPath).href);
|
|
2321
|
+
} catch (error) {
|
|
2322
|
+
const explained = explainJsxLoadError(error, resolvedPath);
|
|
2323
|
+
if (explained !== void 0) throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", explained.summary, {
|
|
2324
|
+
why: explained.why,
|
|
2325
|
+
fix: explained.fix,
|
|
2326
|
+
where: { path: resolvedPath },
|
|
2327
|
+
cause: error
|
|
2328
|
+
});
|
|
2329
|
+
throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", `Failed to import entry module "${resolvedPath}": ${error instanceof Error ? error.message : String(error)}`, {
|
|
2330
|
+
...unloadableFix === void 0 ? {} : { fix: unloadableFix },
|
|
2331
|
+
where: { path: resolvedPath },
|
|
2332
|
+
cause: error
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
const root = blindCast(mod).default;
|
|
2336
|
+
if (isNode(root) && root.kind === "service") throw new CliStructuredError("COMPOSE.ROOT_NOT_MODULE", `The entry "${resolvedPath}" default-exports a service. The app's root must be a module, built with appRoot().`, {
|
|
2337
|
+
fix: "Provision the service inside a root, e.g. export default appRoot('name', ({ provision }) => { provision(service); }).",
|
|
2338
|
+
where: { path: resolvedPath }
|
|
2339
|
+
});
|
|
2340
|
+
if (!isNode(root) || root.kind !== "module") throw new CliStructuredError("COMPOSE.ENTRY_EXPORT_INVALID", `Entry module "${resolvedPath}" must default-export the app's root.`, {
|
|
2341
|
+
fix: "Build it with appRoot() from @prisma/composer.",
|
|
2342
|
+
where: { path: resolvedPath }
|
|
2343
|
+
});
|
|
2344
|
+
return {
|
|
2345
|
+
path: resolvedPath,
|
|
2346
|
+
root
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
function lookup(extensions, extension, type, expectedKind, what) {
|
|
2350
|
+
const ext = extensions.get(extension);
|
|
2351
|
+
if (ext === void 0) throw new CliStructuredError("CONFIG.EXTENSION_MISSING", `No extension "${extension}" is configured (needed by ${what}).`, {
|
|
2352
|
+
fix: "Add it to `extensions` in the `composer` section of prisma.config.ts (import its /control entry and list its descriptor).",
|
|
2353
|
+
meta: {
|
|
2354
|
+
extension,
|
|
2355
|
+
type
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
const descriptor = ext.nodes[type];
|
|
2359
|
+
if (descriptor === void 0) throw new CliStructuredError("CONFIG.DESCRIPTOR_MISSING", `Extension "${extension}" has no descriptor for node type "${type}" (needed by ${what}).`, {
|
|
2360
|
+
why: `Known types: ${Object.keys(ext.nodes).join(", ")}.`,
|
|
2361
|
+
meta: {
|
|
2362
|
+
extension,
|
|
2363
|
+
type
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
if (descriptor.kind !== expectedKind) throw new CliStructuredError("CONFIG.DESCRIPTOR_KIND_MISMATCH", `Extension "${extension}"'s descriptor for node type "${type}" is a "${descriptor.kind}" descriptor — ${what} needs a "${expectedKind}" descriptor.`, { meta: {
|
|
2367
|
+
extension,
|
|
2368
|
+
type,
|
|
2369
|
+
kind: descriptor.kind
|
|
2370
|
+
} });
|
|
2371
|
+
}
|
|
2372
|
+
/** Throws a structured CONFIG.* error on the first uncovered `(extension, type)`; silent when the config covers the whole graph. */
|
|
2373
|
+
function validateRegistryCoverage(graph, config) {
|
|
2374
|
+
const extensions = new Map(config.extensions.map((descriptor) => [descriptor.id, descriptor]));
|
|
2375
|
+
for (const { id, node } of graph.nodes) {
|
|
2376
|
+
if (node.kind === "resource") {
|
|
2377
|
+
lookup(extensions, node.extension, node.type, "resource", `resource node "${id}"`);
|
|
2378
|
+
continue;
|
|
2379
|
+
}
|
|
2380
|
+
if (node.kind !== "service") continue;
|
|
2381
|
+
lookup(extensions, node.extension, node.type, "service", `service node "${id}"`);
|
|
2382
|
+
lookup(extensions, node.build.extension, node.build.type, "build", `service node "${id}"'s build descriptor`);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2386
|
+
* The shared prefix of `deploy`/`destroy`/`dev` (deploy-cli.md § The
|
|
2387
|
+
* pipeline; local-dev spec § 6): entry load, Load,
|
|
2388
|
+
* registry coverage validation, name resolution, assemble. Deploy and dev
|
|
2389
|
+
* diverge after this — deploy resolves containers/preflight/stack file
|
|
2390
|
+
* against the hosted providers, dev against the local ones — so everything
|
|
2391
|
+
* up to and including assemble lives here once, consumed verbatim by both
|
|
2392
|
+
* `run()` (main.ts) and `runDev()` (dev/run-dev.ts), so the two pipelines
|
|
2393
|
+
* cannot drift.
|
|
2394
|
+
*/
|
|
2395
|
+
const NO_SECRETS = Object.freeze({});
|
|
2396
|
+
function configError(findings, file) {
|
|
2397
|
+
const [first] = findings;
|
|
2398
|
+
return new CliStructuredError(first.code, first.summary, {
|
|
2399
|
+
...first.why === void 0 ? {} : { why: first.why },
|
|
2400
|
+
fix: first.fix,
|
|
2401
|
+
where: { path: first.where ?? file },
|
|
2402
|
+
meta: {
|
|
2403
|
+
...first.field === void 0 ? {} : { field: first.field },
|
|
2404
|
+
findings
|
|
2405
|
+
}
|
|
2406
|
+
});
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Refuses a caller's config with the same findings, in the same order, as the CLI's section validator.
|
|
2410
|
+
* The error is the first finding and carries all of them in `meta.findings`. Returns the config with `file` resolved against `cwd`.
|
|
2411
|
+
*/
|
|
2412
|
+
function checkConfigSource(source, cwd) {
|
|
2413
|
+
const file = path.resolve(cwd, source.file);
|
|
2414
|
+
if (!fs.existsSync(file)) throw configError([configFileMissing(file)], file);
|
|
2415
|
+
const checked = checkComposerConfig(source.value, file);
|
|
2416
|
+
if (!checked.ok) throw configError(checked.findings, file);
|
|
2417
|
+
return {
|
|
2418
|
+
value: checked.value,
|
|
2419
|
+
file
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Resolves the entry module. An override (`--entry`, or an operation's `entry` input) resolves
|
|
2424
|
+
* against `cwd`; the section's `entry` resolves against the directory of the file that declares it,
|
|
2425
|
+
* as the CLI engine resolves path fields in prisma.config.ts.
|
|
2426
|
+
*/
|
|
2427
|
+
function resolveEntryPath(override, source, cwd) {
|
|
2428
|
+
if (override !== void 0) return {
|
|
2429
|
+
path: path.resolve(cwd, override),
|
|
2430
|
+
fix: `Check the \`--entry\` path (the \`entry\` input when calling @prisma/composer/control) "${override}". It is relative to the current directory, ${cwd}.`
|
|
2431
|
+
};
|
|
2432
|
+
const configured = source.value.entry;
|
|
2433
|
+
if (configured === void 0) throw configError([entryMissing], source.file);
|
|
2434
|
+
return {
|
|
2435
|
+
path: path.resolve(path.dirname(source.file), configured),
|
|
2436
|
+
fix: `Check \`entry: "${configured}"\` in ${source.file}. It is relative to that file's directory.`
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* The pipeline's front — entry load and name resolution —
|
|
2441
|
+
* WITHOUT Load, coverage, or assemble. `log` needs only who the app is (its
|
|
2442
|
+
* config and resolved name) to reach the already-running local instance; it
|
|
2443
|
+
* neither builds nor provisions, so it must not require the user's built
|
|
2444
|
+
* output the way the full pipeline does.
|
|
2445
|
+
*/
|
|
2446
|
+
async function resolveAppIdentity(entry, overrideName, cwd, config) {
|
|
2447
|
+
const checked = checkConfigSource(config, cwd);
|
|
2448
|
+
const { value } = checked;
|
|
2449
|
+
const resolved = resolveEntryPath(entry, checked, cwd);
|
|
2450
|
+
const entryModule = await loadEntry(resolved.path, cwd, resolved.fix);
|
|
2451
|
+
const name = overrideName ?? entryModule.root.name;
|
|
2452
|
+
if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
|
|
2453
|
+
assertAppName(name);
|
|
2454
|
+
return {
|
|
2455
|
+
config: value,
|
|
2456
|
+
name
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2459
|
+
/**
|
|
2460
|
+
* Runs entry load, name resolution, Load, registry coverage, and assemble — steps 1–5 of `run()`. `onAssembleError`, when
|
|
2461
|
+
* given, lets a caller decorate an assemble failure with command-specific
|
|
2462
|
+
* guidance (destroy's "build first" hint) without this shared step knowing
|
|
2463
|
+
* about any one command.
|
|
2464
|
+
*/
|
|
2465
|
+
async function runPipeline(entry, overrideName, environment, cwd, source, deps = {}, onAssembleError) {
|
|
2466
|
+
const configSource = checkConfigSource(source, cwd);
|
|
2467
|
+
const config = configSource.value;
|
|
2468
|
+
const resolved = resolveEntryPath(entry, configSource, cwd);
|
|
2469
|
+
const entryModule = await loadEntry(resolved.path, cwd, resolved.fix);
|
|
2470
|
+
const name = overrideName ?? entryModule.root.name;
|
|
2471
|
+
if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
|
|
2472
|
+
const redaction = deps.redaction ?? new SecretRedaction(process.env);
|
|
2473
|
+
const adapterInput = {
|
|
2474
|
+
environment,
|
|
2475
|
+
configFile: configSource.file
|
|
2476
|
+
};
|
|
2477
|
+
const secrets = deps.readSecrets === true ? await readAppSecrets(config, adapterInput) : NO_SECRETS;
|
|
2478
|
+
const configuration = await readAppConfiguration(config, adapterInput);
|
|
2479
|
+
redaction.addCredentialLookingValues(credentialLookingValues(configuration));
|
|
2480
|
+
const graph = Load(entryModule.root, {
|
|
2481
|
+
id: name,
|
|
2482
|
+
environment: { name: environment },
|
|
2483
|
+
configuration
|
|
2484
|
+
});
|
|
2485
|
+
redaction.addKnownSecrets(valuesUnderSecretsKeys(configuration, secrets, secretsKeys(graph)));
|
|
2486
|
+
validateRegistryCoverage(graph, config);
|
|
2487
|
+
deps.onEvent?.({ kind: "loaded" });
|
|
2488
|
+
let assembled;
|
|
2489
|
+
try {
|
|
2490
|
+
assembled = await assembleServices(graph, config, cwd, deps.runAssembler, deps.onEvent, { devServers: deps.devServers === true });
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
if (onAssembleError !== void 0 && error instanceof Error) throw onAssembleError(error);
|
|
2493
|
+
throw error;
|
|
2494
|
+
}
|
|
2495
|
+
return {
|
|
2496
|
+
configSource,
|
|
2497
|
+
entryModule,
|
|
2498
|
+
graph,
|
|
2499
|
+
name,
|
|
2500
|
+
assembled,
|
|
2501
|
+
configuration,
|
|
2502
|
+
secrets
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
/** Letters, digits, `-` and `_`, starting with a letter or digit: always a valid git ref, so no `git` is needed to check it. */
|
|
2506
|
+
const PLAIN_ENVIRONMENT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2507
|
+
/** An environment name must be a valid git ref (deploy-cli.md) — checked via `git check-ref-format`, never silently normalized. Runs before anything platform-specific. */
|
|
2508
|
+
function validateEnvironmentName(environment, spawn = spawnSync) {
|
|
2509
|
+
if (PLAIN_ENVIRONMENT_NAME.test(environment)) return;
|
|
2510
|
+
const result = spawn("git", ["check-ref-format", `refs/heads/${environment}`], { stdio: "ignore" });
|
|
2511
|
+
if (result.error) throw new CliStructuredError("DEPLOY.ENVIRONMENT_UNVALIDATABLE", `git is required to validate --environment "${environment}" (git check-ref-format): ${result.error.message}.`, { cause: result.error });
|
|
2512
|
+
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}").`);
|
|
2513
|
+
}
|
|
2514
|
+
//#endregion
|
|
2515
|
+
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 };
|
|
2516
|
+
|
|
2517
|
+
//# sourceMappingURL=validate-environment-CpQLC3CA-Ct-PXoKN.mjs.map
|