@vite-hub/env 0.0.1 → 0.0.3

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/nuxt.js DELETED
@@ -1,38 +0,0 @@
1
- import { a as hasNitroModule, i as assertNoVitePlugin, r as assertNoNitroModule, t as envNitro } from "./module-C74wPcKe.js";
2
- import { addServerImports, defineNuxtModule } from "@nuxt/kit";
3
- //#region src/nuxt/module.ts
4
- const NITRO_MODULE_ID = "@vite-hub/env/nitro";
5
- const NITRO_MODULE_NAME = "@vite-hub/env";
6
- const NUXT_MODULE_ID = "@vite-hub/env/nuxt";
7
- const VITE_PLUGIN_NAME = "@vite-hub/env/vite";
8
- function hasEnvNitroModule(entry) {
9
- return hasNitroModule(entry, NITRO_MODULE_ID, NITRO_MODULE_NAME);
10
- }
11
- function createEnvNitroModuleEntry(options) {
12
- return Object.keys(options).length === 0 ? NITRO_MODULE_ID : envNitro(options);
13
- }
14
- function installEnvNitroModule(nitro, env, options) {
15
- nitro.modules ||= [];
16
- if (!nitro.modules.some(hasEnvNitroModule)) nitro.modules.push(createEnvNitroModuleEntry(options));
17
- if (env !== void 0) nitro.env = env;
18
- }
19
- const envNuxtModule = defineNuxtModule({
20
- meta: { name: NUXT_MODULE_ID },
21
- async setup(inlineOptions = {}, nuxt) {
22
- if (nuxt.options.env === false) return;
23
- const nitro = nuxt.options.nitro ||= {};
24
- await assertNoVitePlugin(nuxt.options.vite, VITE_PLUGIN_NAME, NUXT_MODULE_ID);
25
- assertNoNitroModule(nitro, NITRO_MODULE_ID, NITRO_MODULE_NAME, NUXT_MODULE_ID);
26
- installEnvNitroModule(nitro, nuxt.options.env, inlineOptions);
27
- nuxt.hook("nitro:config", (config) => {
28
- const env = nuxt.options.env;
29
- if (env !== false) installEnvNitroModule(config, env, inlineOptions);
30
- });
31
- addServerImports({
32
- from: "#vitehub/env/server",
33
- name: "useServerEnv"
34
- });
35
- }
36
- });
37
- //#endregion
38
- export { envNuxtModule as default };
@@ -1,400 +0,0 @@
1
- import { r as isDefaultStringEnvVariable, t as defaultStringSchema } from "./declarations-DgJVnQyx.js";
2
- import { parseSchema } from "./schema.js";
3
- import { resolve } from "node:path";
4
- import { realpathSync } from "node:fs";
5
- import "node:url";
6
- import { mkdir, readFile, writeFile } from "node:fs/promises";
7
- import { promisify } from "node:util";
8
- import { execFile } from "node:child_process";
9
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
10
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
11
- function normalizeWindowsPath(input = "") {
12
- if (!input) return input;
13
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
14
- }
15
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
16
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
17
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
18
- function cwd() {
19
- if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
20
- return "/";
21
- }
22
- const resolve$1 = function(...arguments_) {
23
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
24
- let resolvedPath = "";
25
- let resolvedAbsolute = false;
26
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
27
- const path = index >= 0 ? arguments_[index] : cwd();
28
- if (!path || path.length === 0) continue;
29
- resolvedPath = `${path}/${resolvedPath}`;
30
- resolvedAbsolute = isAbsolute$1(path);
31
- }
32
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
33
- if (resolvedAbsolute && !isAbsolute$1(resolvedPath)) return `/${resolvedPath}`;
34
- return resolvedPath.length > 0 ? resolvedPath : ".";
35
- };
36
- function normalizeString(path, allowAboveRoot) {
37
- let res = "";
38
- let lastSegmentLength = 0;
39
- let lastSlash = -1;
40
- let dots = 0;
41
- let char = null;
42
- for (let index = 0; index <= path.length; ++index) {
43
- if (index < path.length) char = path[index];
44
- else if (char === "/") break;
45
- else char = "/";
46
- if (char === "/") {
47
- if (lastSlash === index - 1 || dots === 1);
48
- else if (dots === 2) {
49
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
50
- if (res.length > 2) {
51
- const lastSlashIndex = res.lastIndexOf("/");
52
- if (lastSlashIndex === -1) {
53
- res = "";
54
- lastSegmentLength = 0;
55
- } else {
56
- res = res.slice(0, lastSlashIndex);
57
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
58
- }
59
- lastSlash = index;
60
- dots = 0;
61
- continue;
62
- } else if (res.length > 0) {
63
- res = "";
64
- lastSegmentLength = 0;
65
- lastSlash = index;
66
- dots = 0;
67
- continue;
68
- }
69
- }
70
- if (allowAboveRoot) {
71
- res += res.length > 0 ? "/.." : "..";
72
- lastSegmentLength = 2;
73
- }
74
- } else {
75
- if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
76
- else res = path.slice(lastSlash + 1, index);
77
- lastSegmentLength = index - lastSlash - 1;
78
- }
79
- lastSlash = index;
80
- dots = 0;
81
- } else if (char === "." && dots !== -1) ++dots;
82
- else dots = -1;
83
- }
84
- return res;
85
- }
86
- const isAbsolute$1 = function(p) {
87
- return _IS_ABSOLUTE_RE.test(p);
88
- };
89
- const relative = function(from, to) {
90
- const _from = resolve$1(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
91
- const _to = resolve$1(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
92
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
93
- const _fromCopy = [..._from];
94
- for (const segment of _fromCopy) {
95
- if (_to[0] !== segment) break;
96
- _from.shift();
97
- _to.shift();
98
- }
99
- return [..._from.map(() => ".."), ..._to].join("/");
100
- };
101
- const dirname = function(p) {
102
- const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
103
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
104
- return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
105
- };
106
- //#endregion
107
- //#region ../internal/src/build/paths.ts
108
- function createImportPath(fromFile, targetFile) {
109
- const importPath = relative(realpathIfExists(dirname(fromFile)), realpathIfExists(targetFile));
110
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
111
- }
112
- function realpathIfExists(path) {
113
- try {
114
- return realpathSync.native(path);
115
- } catch {
116
- return resolve$1(path);
117
- }
118
- }
119
- //#endregion
120
- //#region ../internal/src/definition-catalog.ts
121
- async function writeFileIfChanged(file, contents) {
122
- if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
123
- await mkdir(resolve$1(file, ".."), { recursive: true });
124
- await writeFile(file, contents, "utf8");
125
- }
126
- //#endregion
127
- //#region src/core/diagnostics.ts
128
- function shouldTraceDiagnostics(option) {
129
- return option === "trace" || process.env.VITEHUB_ENV_TRACE === "true";
130
- }
131
- function formatDiagnostics(entries, option = "summary") {
132
- if (option === "off" || entries.length === 0) return;
133
- if (!shouldTraceDiagnostics(option)) return `@vite-hub/env validated ${entries.length} declaration${entries.length === 1 ? "" : "s"}.`;
134
- return ["@vite-hub/env", ...entries.flatMap((entry) => [
135
- entry.key,
136
- ` source: ${entry.source}`,
137
- ` mode: ${entry.mode}`,
138
- ` timing: ${entry.timing}`,
139
- ` exposed: ${entry.exposed}`,
140
- ` status: ${entry.status}`,
141
- entry.type ? ` type: ${entry.type}` : void 0,
142
- entry.masked ? " value: ********" : void 0
143
- ].filter(Boolean))].join("\n");
144
- }
145
- //#endregion
146
- //#region src/core/errors.ts
147
- var EnvError = class extends Error {
148
- constructor(message) {
149
- super(`[vitehub] ${message}`);
150
- this.name = "EnvError";
151
- }
152
- };
153
- //#endregion
154
- //#region src/core/resolve.ts
155
- const execFileAsync = promisify(execFile);
156
- function validateEnvConfigShape(config, target) {
157
- if (!config) return;
158
- if (target === "nitro") {
159
- const nitroConfig = config;
160
- if ("server" in nitroConfig) throw new EnvError("`env.server` is not available in Nitro env config. Put private runtime declarations directly under `env`.");
161
- if ("define" in nitroConfig) throw new EnvError("`env.define` is build-only and only available in Vite config.");
162
- validateNitroDeclarations(nitroConfig, "env");
163
- return;
164
- }
165
- const viteConfig = config;
166
- for (const key of Object.keys(viteConfig)) if (key !== "define" && key !== "public") throw new EnvError(`Invalid declaration at env.${key}. Vite env config only supports env.public and env.define.`);
167
- for (const [key, declaration] of Object.entries(viteConfig.public || {})) {
168
- assertEnvVariableDeclaration(`env.public.${key}`, declaration);
169
- if (declaration.mode !== "build") throw new EnvError(`env.public.${key} must use mode: "build" in Vite config. Runtime public config requires Nitro transport.`);
170
- if (declaration.secret) throw new EnvError(`env.public.${key} cannot be marked secret.`);
171
- }
172
- for (const [key, declaration] of Object.entries(viteConfig.define || {})) {
173
- assertEnvVariableDeclaration(`env.define.${key}`, declaration);
174
- if (declaration.mode !== "build") throw new EnvError(`env.define.${key} must use mode: "build".`);
175
- if (declaration.secret) throw new EnvError(`env.define.${key} cannot be marked secret because Vite define values are bundled.`);
176
- }
177
- }
178
- function createSourceContext(input) {
179
- return {
180
- env: input.env,
181
- git: {
182
- branch: () => gitOutput(input.rootDir, [
183
- "rev-parse",
184
- "--abbrev-ref",
185
- "HEAD"
186
- ]),
187
- commit: (options) => gitOutput(input.rootDir, options?.short ? [
188
- "rev-parse",
189
- "--short",
190
- "HEAD"
191
- ] : ["rev-parse", "HEAD"])
192
- },
193
- mode: input.mode,
194
- packageJson: () => readPackageJson(input.rootDir),
195
- rootDir: input.rootDir
196
- };
197
- }
198
- async function resolveEnvEntries(declarations, input) {
199
- const entries = [];
200
- const diagnostics = [];
201
- for (const [key, declaration] of Object.entries(declarations || {})) {
202
- const source = resolveEnvSource(declaration, `${input.section}.${key}`, input.prefix);
203
- const resolvedSource = await resolveSourceValue(source, input.context);
204
- const defaulted = typeof resolvedSource.value === "undefined";
205
- const valueForSchema = defaulted ? declaration.default : resolvedSource.value;
206
- if (typeof valueForSchema === "undefined") {
207
- if (declaration.required) throw new EnvError(`Missing ${input.section}.${key} from ${source.label}.`);
208
- entries.push({
209
- key,
210
- masked: declaration.secret,
211
- source: resolvedSource.label,
212
- type: declaration.type ?? "undefined",
213
- value: void 0
214
- });
215
- diagnostics.push({
216
- exposed: declaration.secret ? `${input.exposure}, masked` : input.exposure,
217
- key: `${input.section}.${key}`,
218
- masked: declaration.secret,
219
- mode: declaration.mode,
220
- source: resolvedSource.label,
221
- status: "missing",
222
- timing: input.timing,
223
- type: declaration.type ?? "undefined"
224
- });
225
- continue;
226
- }
227
- const value = parseSchema(declaration.schema, valueForSchema, `${input.section}.${key}`);
228
- const type = declaration.type ?? inferTypeName(value);
229
- entries.push({
230
- key,
231
- masked: declaration.secret,
232
- source: resolvedSource.label,
233
- type,
234
- value
235
- });
236
- diagnostics.push({
237
- exposed: declaration.secret ? `${input.exposure}, masked` : input.exposure,
238
- key: `${input.section}.${key}`,
239
- masked: declaration.secret,
240
- mode: declaration.mode,
241
- source: defaulted ? "default" : resolvedSource.label,
242
- status: defaulted ? "defaulted" : "valid",
243
- timing: input.timing,
244
- type
245
- });
246
- }
247
- return {
248
- diagnostics,
249
- entries
250
- };
251
- }
252
- function createRuntimeRegistry(declarations, options = {}) {
253
- return buildRegistry(declarations, "env", options.prefix);
254
- }
255
- function buildRegistry(declarations, path, prefix) {
256
- if (!declarations) return {};
257
- return Object.fromEntries(Object.entries(declarations).map(([key, value]) => {
258
- const valuePath = `${path}.${key}`;
259
- if (!isEnvVariableDeclaration(value)) {
260
- if (isNitroStaticValue(value)) return [key, {
261
- kind: "literal",
262
- value
263
- }];
264
- return [key, buildRegistry(value, valuePath, prefix)];
265
- }
266
- const source = resolveEnvSource(value, valuePath, prefix);
267
- if (source.kind !== "env") throw new EnvError(`Runtime declaration ${valuePath} must use env.source() in v1.`);
268
- if (!isDefaultStringEnvVariable(value)) throw new EnvError(`Runtime declaration ${valuePath} uses a custom schema, but Nitro runtime schemas cannot be serialized in v1.`);
269
- if (value.type && value.type !== "string") throw new EnvError(`Runtime declaration ${valuePath} uses type ${JSON.stringify(value.type)}, but Nitro runtime values are strings in v1.`);
270
- return [key, {
271
- default: typeof value.default === "undefined" ? void 0 : parseSchema(defaultStringSchema, value.default, valuePath),
272
- required: value.required,
273
- schema: { kind: "string" },
274
- secret: value.secret,
275
- source,
276
- type: value.type
277
- }];
278
- }));
279
- }
280
- function resolveEnvSource(declaration, path, prefix = "") {
281
- return declaration.source ?? inferEnvSource(path, prefix);
282
- }
283
- function inferTypeName(value) {
284
- if (Array.isArray(value)) return "unknown[]";
285
- switch (typeof value) {
286
- case "boolean":
287
- case "number":
288
- case "string": return typeof value;
289
- case "object": return value === null ? "null" : "Record<string, unknown>";
290
- case "undefined": return "undefined";
291
- default: return "unknown";
292
- }
293
- }
294
- async function resolveSourceValue(source, context) {
295
- switch (source.kind) {
296
- case "custom": return {
297
- label: source.label,
298
- value: await source.resolver(context)
299
- };
300
- case "env":
301
- for (const name of source.names || [source.name]) {
302
- const value = context.env[name];
303
- if (typeof value !== "undefined") return {
304
- label: `env:${name}`,
305
- value
306
- };
307
- }
308
- return {
309
- label: source.label,
310
- value: void 0
311
- };
312
- case "git-branch": return {
313
- label: source.label,
314
- value: await context.git.branch()
315
- };
316
- case "git-commit": return {
317
- label: source.label,
318
- value: await context.git.commit({ short: source.short })
319
- };
320
- case "package-json": return {
321
- label: source.label,
322
- value: readPath(await context.packageJson(), source.path)
323
- };
324
- }
325
- }
326
- function validateNitroDeclarations(declarations, path) {
327
- for (const [key, value] of Object.entries(declarations)) {
328
- const valuePath = `${path}.${key}`;
329
- if (path === "env" && key === "public") {
330
- if (!isPlainRecord(value) || isEnvVariableDeclaration(value)) throw new EnvError("Invalid declaration at env.public. Use a nested object of public env() declarations.");
331
- validateNitroDeclarations(value, valuePath);
332
- continue;
333
- }
334
- if (isEnvVariableDeclaration(value)) {
335
- if (value.mode !== "runtime") throw new EnvError(`${valuePath} must use runtime mode.`);
336
- if (value.source && value.source.kind !== "env") throw new EnvError(`${valuePath} must use an env source in runtime mode for v1. Custom, package, and git sources are build-only.`);
337
- if (path === "env.public" || path.startsWith("env.public.")) {
338
- if (value.secret) throw new EnvError(`${valuePath} cannot be marked secret because public Runtime Env transport is exposed to the client.`);
339
- }
340
- continue;
341
- }
342
- if (isNitroStaticValue(value)) continue;
343
- if (!isPlainRecord(value)) throw new EnvError(`Invalid declaration at ${valuePath}. Use env(), a serializable literal, or a nested object.`);
344
- validateNitroDeclarations(value, valuePath);
345
- }
346
- }
347
- function assertEnvVariableDeclaration(path, declaration) {
348
- if (!isEnvVariableDeclaration(declaration)) throw new EnvError(`Invalid declaration at ${path}. Use env().`);
349
- }
350
- function inferEnvSource(path, prefix) {
351
- const name = `${prefix}${pathToEnvName(path)}`;
352
- return {
353
- kind: "env",
354
- label: `env:${name}`,
355
- name,
356
- serializable: true
357
- };
358
- }
359
- function pathToEnvName(path) {
360
- return path.split(".").slice(1).flatMap((segment) => segmentToEnvParts(segment)).filter(Boolean).join("_");
361
- }
362
- function segmentToEnvParts(segment) {
363
- return segment.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "").split("_").map((part) => part.toUpperCase()).filter(Boolean);
364
- }
365
- function isEnvVariableDeclaration(value) {
366
- return isPlainRecord(value) && value.kind === "env-variable";
367
- }
368
- function isPlainRecord(value) {
369
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
370
- const prototype = Object.getPrototypeOf(value);
371
- return prototype === null || prototype === Object.prototype;
372
- }
373
- function isNitroStaticValue(value) {
374
- if (value === null) return true;
375
- switch (typeof value) {
376
- case "boolean":
377
- case "string": return true;
378
- case "number": return Number.isFinite(value);
379
- case "object":
380
- if (!Array.isArray(value)) return false;
381
- for (let index = 0; index < value.length; index += 1) if (!(index in value) || !isNitroStaticValue(value[index])) return false;
382
- return true;
383
- default: return false;
384
- }
385
- }
386
- async function readPackageJson(rootDir) {
387
- return JSON.parse(await readFile(resolve(rootDir, "package.json"), "utf8"));
388
- }
389
- async function gitOutput(rootDir, args) {
390
- const { stdout } = await execFileAsync("git", args, { cwd: rootDir });
391
- return stdout.trim();
392
- }
393
- function readPath(value, path) {
394
- return path.split(".").reduce((current, segment) => {
395
- if (typeof current !== "object" || current === null) return;
396
- return current[segment];
397
- }, value);
398
- }
399
- //#endregion
400
- export { resolveEnvSource as a, writeFileIfChanged as c, resolveEnvEntries as i, createImportPath as l, createSourceContext as n, validateEnvConfigShape as o, isEnvVariableDeclaration as r, formatDiagnostics as s, createRuntimeRegistry as t };
@@ -1,10 +0,0 @@
1
- import { _ as ServerEnv$1, c as EnvRuntimeRegistry } from "../types-DnbiD9KN.js";
2
- import { SecretEnv } from "../secret.js";
3
-
4
- //#region src/runtime/server.d.ts
5
- interface ServerEnv extends ServerEnv$1 {}
6
- declare function setEnvRegistry(nextRegistry: EnvRuntimeRegistry): void;
7
- declare function useServerEnv(event?: unknown): ServerEnv;
8
- declare function applyRuntimeEnvToRuntimeConfig(runtimeConfig: Record<string, unknown>, event?: unknown): ServerEnv;
9
- //#endregion
10
- export { SecretEnv, ServerEnv, applyRuntimeEnvToRuntimeConfig, setEnvRegistry, useServerEnv };
@@ -1,98 +0,0 @@
1
- import { SecretEnv } from "../secret.js";
2
- import { AsyncLocalStorage } from "node:async_hooks";
3
- import { useRuntimeConfig } from "nitro/runtime-config";
4
- //#region ../internal/src/runtime/cloudflare-env.ts
5
- let activeEnv;
6
- const activeEnvStorage = new AsyncLocalStorage();
7
- function getActiveCloudflareEnv() {
8
- return activeEnvStorage.getStore() ?? activeEnv ?? globalThis.__env__;
9
- }
10
- function getCloudflareEnv(event) {
11
- const target = event;
12
- return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
13
- }
14
- //#endregion
15
- //#region src/runtime/server.ts
16
- let registry = {};
17
- function setEnvRegistry(nextRegistry) {
18
- registry = nextRegistry;
19
- }
20
- function useServerEnv(event) {
21
- return applyRuntimeEnvToRuntimeConfig(resolveNitroRuntimeConfig(event), event);
22
- }
23
- function applyRuntimeEnvToRuntimeConfig(runtimeConfig, event) {
24
- assignRuntimeValues(runtimeConfig, resolveRuntimeValues(registry, resolveRuntimeEnv(event)));
25
- return runtimeConfig;
26
- }
27
- function resolveNitroRuntimeConfig(event) {
28
- try {
29
- return useRuntimeConfig(event);
30
- } catch {
31
- return {};
32
- }
33
- }
34
- function resolveRuntimeEnv(event) {
35
- const cloudflareEnv = event ? getCloudflareEnv(event) : void 0;
36
- if (!cloudflareEnv) return process.env;
37
- return Object.fromEntries(Object.entries(cloudflareEnv).map(([key, value]) => [key, typeof value === "string" ? value : void 0]));
38
- }
39
- function resolveRuntimeValues(declarations, env, path = "env") {
40
- const values = {};
41
- for (const [key, entry] of Object.entries(declarations)) {
42
- if (isLiteralEntry(entry)) {
43
- values[key] = entry.value;
44
- continue;
45
- }
46
- if (!isRegistryEntry(entry)) {
47
- values[key] = resolveRuntimeValues(entry, env, `${path}.${key}`);
48
- continue;
49
- }
50
- const declaration = entry;
51
- const rawValue = resolveEnvValue(declaration.source, env) ?? declaration.default;
52
- if (typeof rawValue === "undefined") {
53
- if (declaration.required) throw new Error(`[vitehub] Missing runtime env value ${path}.${key} from ${declaration.source.label}.`);
54
- values[key] = void 0;
55
- continue;
56
- }
57
- const value = parseRuntimeValue(declaration.schema, rawValue, `${path}.${key}`);
58
- values[key] = declaration.secret ? new SecretEnv(value) : value;
59
- }
60
- return values;
61
- }
62
- function parseRuntimeValue(schema, value, label) {
63
- if (!schema) return value;
64
- if (schema.kind === "string" && typeof value === "string") return value;
65
- throw new Error(`[vitehub] Invalid ${label}: Expected string`);
66
- }
67
- function resolveEnvValue(source, env) {
68
- for (const name of source.names || [source.name]) {
69
- const value = env[name];
70
- if (typeof value !== "undefined") return value;
71
- }
72
- }
73
- function assignRuntimeValues(target, values) {
74
- for (const [key, value] of Object.entries(values)) {
75
- if (isPlainRuntimeObject(value)) {
76
- const existing = target[key];
77
- const next = isPlainRuntimeObject(existing) ? existing : {};
78
- assignRuntimeValues(next, value);
79
- target[key] = next;
80
- continue;
81
- }
82
- target[key] = value;
83
- }
84
- }
85
- function isRegistryEntry(value) {
86
- const source = value.source;
87
- return typeof source === "object" && source !== null && source.kind === "env" && typeof source.name === "string";
88
- }
89
- function isLiteralEntry(value) {
90
- return typeof value === "object" && value !== null && !Array.isArray(value) && value.kind === "literal";
91
- }
92
- function isPlainRuntimeObject(value) {
93
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
94
- const prototype = Object.getPrototypeOf(value);
95
- return prototype === null || prototype === Object.prototype;
96
- }
97
- //#endregion
98
- export { SecretEnv, applyRuntimeEnvToRuntimeConfig, setEnvRegistry, useServerEnv };