@vite-hub/env 0.0.4 → 0.1.0
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/README.md +125 -5
- package/dist/access-B3qzBHye.js +54 -0
- package/dist/auth.d.ts +32 -0
- package/dist/auth.js +44 -0
- package/dist/bridge-CdNdTN1V.d.ts +374 -0
- package/dist/bridge-error-CFuU5zIz.js +65 -0
- package/dist/bridge.d.ts +2 -0
- package/dist/bridge.js +192 -0
- package/dist/cli-CMQPQbii.js +487 -0
- package/dist/cli-DEwcUIe0.d.ts +81 -0
- package/dist/cli.d.ts +41 -0
- package/dist/cli.js +2 -0
- package/dist/database.d.ts +21 -0
- package/dist/database.js +183 -0
- package/dist/declarations-CiRdb1qP.d.ts +32 -0
- package/dist/declarations-DAVgctKD.js +236 -0
- package/dist/error-diagnostics-CrxjYNYr.js +43 -0
- package/dist/http.d.ts +2 -0
- package/dist/http.js +122 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -4
- package/dist/internal/agent.d.ts +5 -0
- package/dist/internal/agent.js +22 -0
- package/dist/internal/connections.d.ts +18 -0
- package/dist/internal/connections.js +31 -0
- package/dist/presets.d.ts +15 -6
- package/dist/presets.js +21 -2
- package/dist/provider.d.ts +3 -4
- package/dist/provider.js +2 -1
- package/dist/schema.d.ts +5 -6
- package/dist/schema.js +26 -8
- package/dist/seal.d.ts +14 -0
- package/dist/seal.js +49 -0
- package/dist/server-DufVswRJ.js +670 -0
- package/dist/server.d.ts +23 -6
- package/dist/server.js +2 -3
- package/dist/values-D_r6V774.js +148 -0
- package/dist/virtual-module.d.ts +7 -3
- package/dist/virtual.d.ts +1 -1
- package/dist/vite.d.ts +27 -14
- package/dist/vite.js +840 -273
- package/package.json +81 -17
- package/dist/declarations-CoMmvRqH.js +0 -159
- package/dist/declarations-U6P3rvxC.d.ts +0 -24
- package/dist/errors-C4Xcs6Fi.js +0 -121
- package/dist/server-C16sFc1E.js +0 -303
- package/dist/types-CsB6DTGE.d.ts +0 -190
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/env",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Safe build and runtime environment variables for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
7
7
|
"environment-variables",
|
|
8
8
|
"runtime-config",
|
|
9
|
+
"secrets",
|
|
10
|
+
"typescript",
|
|
9
11
|
"vite",
|
|
10
12
|
"vitehub"
|
|
11
13
|
],
|
|
12
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://vitehub.dev",
|
|
13
15
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
16
|
"license": "Apache-2.0",
|
|
15
17
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -28,55 +30,117 @@
|
|
|
28
30
|
"exports": {
|
|
29
31
|
".": {
|
|
30
32
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"import": "./dist/index.js"
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./auth": {
|
|
37
|
+
"types": "./dist/auth.d.ts",
|
|
38
|
+
"import": "./dist/auth.js",
|
|
39
|
+
"default": "./dist/auth.js"
|
|
40
|
+
},
|
|
41
|
+
"./bridge": {
|
|
42
|
+
"types": "./dist/bridge.d.ts",
|
|
43
|
+
"import": "./dist/bridge.js",
|
|
44
|
+
"default": "./dist/bridge.js"
|
|
45
|
+
},
|
|
46
|
+
"./cli": {
|
|
47
|
+
"types": "./dist/cli.d.ts",
|
|
48
|
+
"import": "./dist/cli.js",
|
|
49
|
+
"default": "./dist/cli.js"
|
|
50
|
+
},
|
|
51
|
+
"./database": {
|
|
52
|
+
"types": "./dist/database.d.ts",
|
|
53
|
+
"import": "./dist/database.js",
|
|
54
|
+
"default": "./dist/database.js"
|
|
55
|
+
},
|
|
56
|
+
"./http": {
|
|
57
|
+
"types": "./dist/http.d.ts",
|
|
58
|
+
"import": "./dist/http.js",
|
|
59
|
+
"default": "./dist/http.js"
|
|
60
|
+
},
|
|
61
|
+
"./internal/agent": {
|
|
62
|
+
"types": "./dist/internal/agent.d.ts",
|
|
63
|
+
"import": "./dist/internal/agent.js",
|
|
64
|
+
"default": "./dist/internal/agent.js"
|
|
65
|
+
},
|
|
66
|
+
"./internal/connections": {
|
|
67
|
+
"types": "./dist/internal/connections.d.ts",
|
|
68
|
+
"import": "./dist/internal/connections.js",
|
|
69
|
+
"default": "./dist/internal/connections.js"
|
|
32
70
|
},
|
|
33
71
|
"./presets": {
|
|
34
72
|
"types": "./dist/presets.d.ts",
|
|
35
|
-
"import": "./dist/presets.js"
|
|
73
|
+
"import": "./dist/presets.js",
|
|
74
|
+
"default": "./dist/presets.js"
|
|
36
75
|
},
|
|
37
76
|
"./provider": {
|
|
38
77
|
"types": "./dist/provider.d.ts",
|
|
39
|
-
"import": "./dist/provider.js"
|
|
78
|
+
"import": "./dist/provider.js",
|
|
79
|
+
"default": "./dist/provider.js"
|
|
40
80
|
},
|
|
41
81
|
"./schema": {
|
|
42
82
|
"types": "./dist/schema.d.ts",
|
|
43
|
-
"import": "./dist/schema.js"
|
|
83
|
+
"import": "./dist/schema.js",
|
|
84
|
+
"default": "./dist/schema.js"
|
|
85
|
+
},
|
|
86
|
+
"./seal": {
|
|
87
|
+
"types": "./dist/seal.d.ts",
|
|
88
|
+
"import": "./dist/seal.js",
|
|
89
|
+
"default": "./dist/seal.js"
|
|
44
90
|
},
|
|
45
91
|
"./secret": {
|
|
46
92
|
"types": "./dist/secret.d.ts",
|
|
47
|
-
"import": "./dist/secret.js"
|
|
93
|
+
"import": "./dist/secret.js",
|
|
94
|
+
"default": "./dist/secret.js"
|
|
48
95
|
},
|
|
49
96
|
"./server": {
|
|
50
97
|
"types": "./dist/server.d.ts",
|
|
51
|
-
"import": "./dist/server.js"
|
|
98
|
+
"import": "./dist/server.js",
|
|
99
|
+
"default": "./dist/server.js"
|
|
52
100
|
},
|
|
53
101
|
"./virtual": {
|
|
54
102
|
"types": "./dist/virtual.d.ts",
|
|
55
|
-
"import": "./dist/virtual.js"
|
|
103
|
+
"import": "./dist/virtual.js",
|
|
104
|
+
"default": "./dist/virtual.js"
|
|
56
105
|
},
|
|
57
106
|
"./vite": {
|
|
58
107
|
"types": "./dist/vite.d.ts",
|
|
59
|
-
"import": "./dist/vite.js"
|
|
108
|
+
"import": "./dist/vite.js",
|
|
109
|
+
"default": "./dist/vite.js"
|
|
60
110
|
},
|
|
61
111
|
"./package.json": "./package.json"
|
|
62
112
|
},
|
|
63
113
|
"dependencies": {
|
|
64
|
-
"@
|
|
114
|
+
"@env-spec/parser": "0.6.2",
|
|
115
|
+
"@vite-hub/runtime": "0.1.0",
|
|
116
|
+
"nostics": "1.3.0",
|
|
117
|
+
"valibot": "^1.5.0"
|
|
65
118
|
},
|
|
66
119
|
"devDependencies": {
|
|
67
|
-
"
|
|
120
|
+
"zod": "^4.6.7",
|
|
121
|
+
"publint": "^0.3.25",
|
|
68
122
|
"typescript": "^6.0.3",
|
|
69
|
-
"vite": "^8.
|
|
70
|
-
"vite-plus": "^0.
|
|
71
|
-
"vitest": "^4.1.
|
|
123
|
+
"vite": "^8.2.2",
|
|
124
|
+
"vite-plus": "^0.3.3",
|
|
125
|
+
"vitest": "^4.1.11",
|
|
126
|
+
"drizzle-orm": "^0.45.3",
|
|
127
|
+
"@libsql/client": "^0.18.0",
|
|
72
128
|
"@vite-hub/internal": "0.0.1"
|
|
73
129
|
},
|
|
74
130
|
"peerDependencies": {
|
|
75
|
-
"vite": ">=8.0.0"
|
|
131
|
+
"vite": ">=8.0.0",
|
|
132
|
+
"drizzle-orm": "^0.45.3",
|
|
133
|
+
"@vite-hub/agent": "0.1.0"
|
|
76
134
|
},
|
|
77
135
|
"peerDependenciesMeta": {
|
|
78
136
|
"vite": {
|
|
79
137
|
"optional": true
|
|
138
|
+
},
|
|
139
|
+
"drizzle-orm": {
|
|
140
|
+
"optional": true
|
|
141
|
+
},
|
|
142
|
+
"@vite-hub/agent": {
|
|
143
|
+
"optional": true
|
|
80
144
|
}
|
|
81
145
|
},
|
|
82
146
|
"engines": {
|
|
@@ -85,7 +149,7 @@
|
|
|
85
149
|
"scripts": {
|
|
86
150
|
"build": "vp pack",
|
|
87
151
|
"dev": "vp pack --watch",
|
|
88
|
-
"typecheck": "
|
|
152
|
+
"typecheck": "vp run --cache -t @vite-hub/env#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
89
153
|
"test": "vp run -t @vite-hub/env#build && vp test"
|
|
90
154
|
}
|
|
91
155
|
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
//#region src/core/declarations.ts
|
|
2
|
-
const defaultStringSchema = {
|
|
3
|
-
__vitehubDefaultRuntimeSchema: getDefaultStringSchemaToken(),
|
|
4
|
-
safeParse(input) {
|
|
5
|
-
return typeof input === "string" ? {
|
|
6
|
-
data: input,
|
|
7
|
-
success: true
|
|
8
|
-
} : {
|
|
9
|
-
error: /* @__PURE__ */ new Error("Expected string"),
|
|
10
|
-
success: false
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const defaultStringSchemaProperty = "__vitehubDefaultRuntimeSchema";
|
|
15
|
-
const defaultStringSchemaToken = defaultStringSchema.__vitehubDefaultRuntimeSchema;
|
|
16
|
-
const defaultStringSchemas = /* @__PURE__ */ new WeakMap();
|
|
17
|
-
const defaultStringSchemaParsers = /* @__PURE__ */ new WeakSet();
|
|
18
|
-
defaultStringSchemaParsers.add(defaultStringSchema.safeParse);
|
|
19
|
-
function source(name) {
|
|
20
|
-
const names = Array.isArray(name) ? name : [name];
|
|
21
|
-
if (!names.length || names.some((value) => typeof value !== "string" || !value.trim())) throw new TypeError("env.source() requires one or more non-empty env variable names.");
|
|
22
|
-
const normalized = names.map((value) => value.trim());
|
|
23
|
-
return {
|
|
24
|
-
kind: "env",
|
|
25
|
-
label: `env:${normalized.join("|")}`,
|
|
26
|
-
name: normalized[0],
|
|
27
|
-
...normalized.length > 1 ? { names: normalized } : {},
|
|
28
|
-
serializable: true
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function custom(label, resolver) {
|
|
32
|
-
return {
|
|
33
|
-
kind: "custom",
|
|
34
|
-
label,
|
|
35
|
-
resolver,
|
|
36
|
-
serializable: false
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function gitBranch() {
|
|
40
|
-
return {
|
|
41
|
-
kind: "git-branch",
|
|
42
|
-
label: "git:branch",
|
|
43
|
-
serializable: true
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function gitCommit(options = {}) {
|
|
47
|
-
return {
|
|
48
|
-
kind: "git-commit",
|
|
49
|
-
label: "git:commit",
|
|
50
|
-
serializable: true,
|
|
51
|
-
short: options.short
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function gitRef() {
|
|
55
|
-
return {
|
|
56
|
-
kind: "git-ref",
|
|
57
|
-
label: "git:ref",
|
|
58
|
-
serializable: true
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function gitSha(options = {}) {
|
|
62
|
-
return {
|
|
63
|
-
kind: "git-sha",
|
|
64
|
-
label: "git:sha",
|
|
65
|
-
serializable: true,
|
|
66
|
-
short: options.short
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function gitTag() {
|
|
70
|
-
return {
|
|
71
|
-
kind: "git-tag",
|
|
72
|
-
label: "git:tag",
|
|
73
|
-
serializable: true
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function buildTimestamp() {
|
|
77
|
-
return {
|
|
78
|
-
kind: "build-timestamp",
|
|
79
|
-
label: "build:timestamp",
|
|
80
|
-
serializable: true
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function packageJson(path) {
|
|
84
|
-
return {
|
|
85
|
-
kind: "package-json",
|
|
86
|
-
label: `package.json:${path}`,
|
|
87
|
-
path,
|
|
88
|
-
serializable: true
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function provider(provider, key) {
|
|
92
|
-
if (typeof provider !== "string" || !/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(provider.trim())) throw new TypeError("env.provider() requires a provider name that starts with a letter and contains only letters, numbers, underscores, or hyphens.");
|
|
93
|
-
if (typeof key !== "string" || !key.trim() || key.length > 512) throw new TypeError("env.provider() requires a non-empty provider key.");
|
|
94
|
-
return {
|
|
95
|
-
key: key.trim(),
|
|
96
|
-
kind: "provider",
|
|
97
|
-
label: "provider",
|
|
98
|
-
provider: provider.trim(),
|
|
99
|
-
serializable: true
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function variable(options = {}) {
|
|
103
|
-
if (typeof options !== "object" || options === null || Array.isArray(options)) throw new TypeError("env() only accepts a single options object.");
|
|
104
|
-
if (options.optional && typeof options.required !== "undefined") throw new TypeError("env() cannot use both optional and required.");
|
|
105
|
-
const required = options.optional ? false : options.required ?? true;
|
|
106
|
-
const source = typeof options.source === "function" ? custom("custom", options.source) : options.source;
|
|
107
|
-
const schema = options.schema ?? defaultStringSchema;
|
|
108
|
-
const declaration = {
|
|
109
|
-
default: options.default,
|
|
110
|
-
kind: "env-variable",
|
|
111
|
-
mode: options.mode ?? "runtime",
|
|
112
|
-
required,
|
|
113
|
-
schema,
|
|
114
|
-
secret: options.secret ?? false,
|
|
115
|
-
source,
|
|
116
|
-
type: options.type
|
|
117
|
-
};
|
|
118
|
-
if (typeof options.schema === "undefined") {
|
|
119
|
-
defaultStringSchemas.set(declaration, defaultStringSchema);
|
|
120
|
-
Object.defineProperty(declaration, defaultStringSchemaProperty, {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
value: defaultStringSchemaToken
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return declaration;
|
|
126
|
-
}
|
|
127
|
-
const env = Object.assign(variable, {
|
|
128
|
-
buildTimestamp,
|
|
129
|
-
custom,
|
|
130
|
-
gitBranch,
|
|
131
|
-
gitCommit,
|
|
132
|
-
gitRef,
|
|
133
|
-
gitSha,
|
|
134
|
-
gitTag,
|
|
135
|
-
packageJson,
|
|
136
|
-
provider,
|
|
137
|
-
source,
|
|
138
|
-
variable
|
|
139
|
-
});
|
|
140
|
-
function isDefaultStringEnvVariable(declaration) {
|
|
141
|
-
const declarationToken = Object.getOwnPropertyDescriptor(declaration, defaultStringSchemaProperty)?.value;
|
|
142
|
-
const schemaObject = typeof declaration.schema === "object" && declaration.schema !== null ? declaration.schema : void 0;
|
|
143
|
-
const schemaToken = schemaObject ? Object.getOwnPropertyDescriptor(schemaObject, defaultStringSchemaProperty)?.value : void 0;
|
|
144
|
-
return defaultStringSchemas.get(declaration) === declaration.schema || declarationToken === defaultStringSchemaToken && schemaToken === defaultStringSchemaToken && schemaObject !== void 0 && hasOnlyDefaultStringSchemaKeys(schemaObject);
|
|
145
|
-
}
|
|
146
|
-
function getDefaultStringSchemaToken() {
|
|
147
|
-
const tokenKey = Symbol.for("vitehub.env.defaultRuntimeSchemaToken");
|
|
148
|
-
const globalScope = globalThis;
|
|
149
|
-
globalScope[tokenKey] ??= `string:${Math.random().toString(36).slice(2)}`;
|
|
150
|
-
return globalScope[tokenKey];
|
|
151
|
-
}
|
|
152
|
-
function hasOnlyDefaultStringSchemaKeys(schema) {
|
|
153
|
-
if ("~standard" in schema || "parse" in schema) return false;
|
|
154
|
-
const keys = Reflect.ownKeys(schema);
|
|
155
|
-
const safeParse = Object.getOwnPropertyDescriptor(schema, "safeParse");
|
|
156
|
-
return keys.length === 2 && keys.includes(defaultStringSchemaProperty) && keys.includes("safeParse") && typeof safeParse?.value === "function" && defaultStringSchemaParsers.has(safeParse.value);
|
|
157
|
-
}
|
|
158
|
-
//#endregion
|
|
159
|
-
export { env as n, isDefaultStringEnvVariable as r, defaultStringSchema as t };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { _ as EnvVariableOptions, g as EnvVariableDeclaration, h as EnvSourceResolver, p as EnvSource } from "./types-CsB6DTGE.js";
|
|
2
|
-
|
|
3
|
-
//#region src/core/declarations.d.ts
|
|
4
|
-
interface EnvNamespace {
|
|
5
|
-
(options?: EnvVariableOptions): EnvVariableDeclaration;
|
|
6
|
-
buildTimestamp: () => EnvSource;
|
|
7
|
-
custom: (label: string, resolver: EnvSourceResolver) => EnvSource;
|
|
8
|
-
gitBranch: () => EnvSource;
|
|
9
|
-
gitCommit: (options?: {
|
|
10
|
-
short?: boolean;
|
|
11
|
-
}) => EnvSource;
|
|
12
|
-
gitRef: () => EnvSource;
|
|
13
|
-
gitSha: (options?: {
|
|
14
|
-
short?: boolean;
|
|
15
|
-
}) => EnvSource;
|
|
16
|
-
gitTag: () => EnvSource;
|
|
17
|
-
packageJson: (path: string) => EnvSource;
|
|
18
|
-
provider: (provider: string, key: string) => EnvSource;
|
|
19
|
-
source: (name: string | string[]) => EnvSource;
|
|
20
|
-
variable: (options?: EnvVariableOptions) => EnvVariableDeclaration;
|
|
21
|
-
}
|
|
22
|
-
declare const env: EnvNamespace;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { env as t };
|
package/dist/errors-C4Xcs6Fi.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/core/errors.ts
|
|
3
|
-
const envErrorMessages = {
|
|
4
|
-
ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.",
|
|
5
|
-
ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.",
|
|
6
|
-
ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.",
|
|
7
|
-
ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.",
|
|
8
|
-
ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed."
|
|
9
|
-
};
|
|
10
|
-
const envSourceIdentifierSet = new Set([
|
|
11
|
-
"custom",
|
|
12
|
-
"env",
|
|
13
|
-
"git:branch",
|
|
14
|
-
"git:commit",
|
|
15
|
-
"git:ref",
|
|
16
|
-
"git:sha",
|
|
17
|
-
"git:tag",
|
|
18
|
-
"package.json",
|
|
19
|
-
"provider"
|
|
20
|
-
]);
|
|
21
|
-
function invalidOptions() {
|
|
22
|
-
throw new TypeError("[vitehub] Invalid Env error options.");
|
|
23
|
-
}
|
|
24
|
-
function own(value, key) {
|
|
25
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) invalidOptions();
|
|
26
|
-
try {
|
|
27
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
28
|
-
if (descriptor === void 0) return void 0;
|
|
29
|
-
if (!("value" in descriptor)) invalidOptions();
|
|
30
|
-
return descriptor.value;
|
|
31
|
-
} catch {
|
|
32
|
-
invalidOptions();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function createEnvError(options) {
|
|
36
|
-
const code = own(options, "code");
|
|
37
|
-
if (typeof code !== "string" || !Object.hasOwn(envErrorMessages, code)) invalidOptions();
|
|
38
|
-
const cause = own(options, "cause");
|
|
39
|
-
const details = normalizeDetails(code, own(options, "details"));
|
|
40
|
-
return new ViteHubError(code, envErrorMessages[code], {
|
|
41
|
-
...cause === void 0 ? {} : { cause },
|
|
42
|
-
...details === void 0 ? {} : { details }
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function invalidEnvDeclaration(path, diagnostic) {
|
|
46
|
-
return createEnvError({
|
|
47
|
-
cause: new TypeError(diagnostic),
|
|
48
|
-
code: "ENV_DECLARATION_INVALID",
|
|
49
|
-
details: optionalPath(path)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function asyncServerEnvRequired(path) {
|
|
53
|
-
return createEnvError({
|
|
54
|
-
cause: /* @__PURE__ */ new TypeError(`Server Env at ${path} uses env.provider(). Use loadServerEnv() or runWithServerEnv().`),
|
|
55
|
-
code: "ENV_ASYNC_REQUIRED",
|
|
56
|
-
details: optionalPath(path)
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function missingRequiredEnv(source, diagnostic, path) {
|
|
60
|
-
const pathDetails = optionalPath(path);
|
|
61
|
-
return createEnvError({
|
|
62
|
-
cause: new Error(diagnostic),
|
|
63
|
-
code: "ENV_REQUIRED_MISSING",
|
|
64
|
-
details: {
|
|
65
|
-
...pathDetails,
|
|
66
|
-
source: publicSourceIdentifier(source)
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function invalidRuntimeEnvValue(source, diagnostic) {
|
|
71
|
-
return createEnvError({
|
|
72
|
-
cause: new TypeError(diagnostic),
|
|
73
|
-
code: "ENV_RUNTIME_VALUE_INVALID",
|
|
74
|
-
details: { source: publicSourceIdentifier(source) }
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function envSourceFailed(source, cause) {
|
|
78
|
-
return createEnvError({
|
|
79
|
-
cause,
|
|
80
|
-
code: "ENV_SOURCE_FAILED",
|
|
81
|
-
details: { source: publicSourceIdentifier(source) }
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function isAbortError(value) {
|
|
85
|
-
if ((typeof value !== "object" || value === null) && typeof value !== "function") return false;
|
|
86
|
-
try {
|
|
87
|
-
return value.name === "AbortError";
|
|
88
|
-
} catch {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function publicSourceIdentifier(source) {
|
|
93
|
-
if (envSourceIdentifierSet.has(source)) return source;
|
|
94
|
-
if (source.startsWith("env:")) return "env";
|
|
95
|
-
if (source.startsWith("package.json:")) return "package.json";
|
|
96
|
-
return "custom";
|
|
97
|
-
}
|
|
98
|
-
function normalizeDetails(code, details) {
|
|
99
|
-
if (details === void 0) return void 0;
|
|
100
|
-
if (typeof details !== "object" || details === null || Array.isArray(details)) invalidOptions();
|
|
101
|
-
const normalized = {};
|
|
102
|
-
if (code === "ENV_ASYNC_REQUIRED" || code === "ENV_DECLARATION_INVALID" || code === "ENV_REQUIRED_MISSING") {
|
|
103
|
-
const path = safePath(own(details, "path"));
|
|
104
|
-
if (path) normalized.path = path;
|
|
105
|
-
}
|
|
106
|
-
if (code !== "ENV_ASYNC_REQUIRED" && code !== "ENV_DECLARATION_INVALID") {
|
|
107
|
-
const source = own(details, "source");
|
|
108
|
-
if (envSourceIdentifierSet.has(source)) normalized.source = source;
|
|
109
|
-
}
|
|
110
|
-
return Object.keys(normalized).length ? normalized : void 0;
|
|
111
|
-
}
|
|
112
|
-
function optionalPath(path) {
|
|
113
|
-
const normalized = safePath(path);
|
|
114
|
-
return normalized ? { path: normalized } : {};
|
|
115
|
-
}
|
|
116
|
-
function safePath(path) {
|
|
117
|
-
if (typeof path !== "string" || path.length > 256) return void 0;
|
|
118
|
-
return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? path : void 0;
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { isAbortError as a, invalidRuntimeEnvValue as i, envSourceFailed as n, missingRequiredEnv as o, invalidEnvDeclaration as r, asyncServerEnvRequired as t };
|