@vite-hub/env 0.1.0 → 0.3.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 +178 -33
- package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
- package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
- package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +168 -6
- package/dist/cli-BPp7rdcA.d.ts +159 -0
- package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +1 -1
- package/dist/database.d.ts +29 -3
- package/dist/database.js +106 -15
- package/dist/declarations-C5XR3aKw.d.ts +58 -0
- package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
- package/dist/index.d.ts +145 -10
- package/dist/index.js +240 -7
- package/dist/internal/agent.d.ts +1 -1
- package/dist/internal/agent.js +2 -2
- package/dist/internal/connections.d.ts +1 -1
- package/dist/internal/connections.js +2 -2
- package/dist/internal/server.d.ts +3 -0
- package/dist/internal/server.js +2 -0
- package/dist/object-_dlsZ4lP.js +276 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-X1w--wds.js +30 -0
- package/dist/operations.d.ts +37 -0
- package/dist/operations.js +833 -0
- package/dist/runtime/public-env.d.ts +5 -0
- package/dist/runtime/public-env.js +8 -0
- package/dist/runtime/server-env.d.ts +22 -0
- package/dist/runtime/server-env.js +35 -0
- package/dist/schema-DMZ1_yhY.js +360 -0
- package/dist/seal.d.ts +8 -5
- package/dist/seal.js +9 -6
- package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
- package/dist/server-ChNL_Xc3.js +1279 -0
- package/dist/server-Dd8bjIKd.d.ts +145 -0
- package/dist/server.d.ts +3 -25
- package/dist/server.js +2 -2
- package/dist/virtual-module.d.ts +6 -6
- package/dist/vite.d.ts +59 -14
- package/dist/vite.js +304 -115
- package/package.json +27 -38
- package/dist/auth.d.ts +0 -32
- package/dist/auth.js +0 -44
- package/dist/cli-DEwcUIe0.d.ts +0 -81
- package/dist/declarations-CiRdb1qP.d.ts +0 -32
- package/dist/declarations-DAVgctKD.js +0 -236
- package/dist/error-diagnostics-CrxjYNYr.js +0 -43
- package/dist/http.d.ts +0 -2
- package/dist/http.js +0 -122
- package/dist/presets.d.ts +0 -20
- package/dist/presets.js +0 -44
- package/dist/provider.d.ts +0 -5
- package/dist/provider.js +0 -8
- package/dist/schema.d.ts +0 -15
- package/dist/schema.js +0 -55
- package/dist/secret-C2191nAa.d.ts +0 -11
- package/dist/secret.d.ts +0 -2
- package/dist/server-DufVswRJ.js +0 -670
- package/dist/values-D_r6V774.js +0 -148
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Safe build and runtime environment variables for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
@@ -27,17 +27,22 @@
|
|
|
27
27
|
"type": "module",
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
|
+
"imports": {
|
|
31
|
+
"#vitehub/env/public": {
|
|
32
|
+
"types": "./dist/runtime/public-env.d.ts",
|
|
33
|
+
"default": "./dist/runtime/public-env.js"
|
|
34
|
+
},
|
|
35
|
+
"#vitehub/env/server": {
|
|
36
|
+
"types": "./dist/runtime/server-env.d.ts",
|
|
37
|
+
"default": "./dist/runtime/server-env.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
30
40
|
"exports": {
|
|
31
41
|
".": {
|
|
32
42
|
"types": "./dist/index.d.ts",
|
|
33
43
|
"import": "./dist/index.js",
|
|
34
44
|
"default": "./dist/index.js"
|
|
35
45
|
},
|
|
36
|
-
"./auth": {
|
|
37
|
-
"types": "./dist/auth.d.ts",
|
|
38
|
-
"import": "./dist/auth.js",
|
|
39
|
-
"default": "./dist/auth.js"
|
|
40
|
-
},
|
|
41
46
|
"./bridge": {
|
|
42
47
|
"types": "./dist/bridge.d.ts",
|
|
43
48
|
"import": "./dist/bridge.js",
|
|
@@ -53,11 +58,6 @@
|
|
|
53
58
|
"import": "./dist/database.js",
|
|
54
59
|
"default": "./dist/database.js"
|
|
55
60
|
},
|
|
56
|
-
"./http": {
|
|
57
|
-
"types": "./dist/http.d.ts",
|
|
58
|
-
"import": "./dist/http.js",
|
|
59
|
-
"default": "./dist/http.js"
|
|
60
|
-
},
|
|
61
61
|
"./internal/agent": {
|
|
62
62
|
"types": "./dist/internal/agent.d.ts",
|
|
63
63
|
"import": "./dist/internal/agent.js",
|
|
@@ -68,31 +68,16 @@
|
|
|
68
68
|
"import": "./dist/internal/connections.js",
|
|
69
69
|
"default": "./dist/internal/connections.js"
|
|
70
70
|
},
|
|
71
|
-
"./
|
|
72
|
-
"types": "./dist/
|
|
73
|
-
"import": "./dist/
|
|
74
|
-
"default": "./dist/
|
|
75
|
-
},
|
|
76
|
-
"./provider": {
|
|
77
|
-
"types": "./dist/provider.d.ts",
|
|
78
|
-
"import": "./dist/provider.js",
|
|
79
|
-
"default": "./dist/provider.js"
|
|
80
|
-
},
|
|
81
|
-
"./schema": {
|
|
82
|
-
"types": "./dist/schema.d.ts",
|
|
83
|
-
"import": "./dist/schema.js",
|
|
84
|
-
"default": "./dist/schema.js"
|
|
71
|
+
"./internal/server": {
|
|
72
|
+
"types": "./dist/internal/server.d.ts",
|
|
73
|
+
"import": "./dist/internal/server.js",
|
|
74
|
+
"default": "./dist/internal/server.js"
|
|
85
75
|
},
|
|
86
76
|
"./seal": {
|
|
87
77
|
"types": "./dist/seal.d.ts",
|
|
88
78
|
"import": "./dist/seal.js",
|
|
89
79
|
"default": "./dist/seal.js"
|
|
90
80
|
},
|
|
91
|
-
"./secret": {
|
|
92
|
-
"types": "./dist/secret.d.ts",
|
|
93
|
-
"import": "./dist/secret.js",
|
|
94
|
-
"default": "./dist/secret.js"
|
|
95
|
-
},
|
|
96
81
|
"./server": {
|
|
97
82
|
"types": "./dist/server.d.ts",
|
|
98
83
|
"import": "./dist/server.js",
|
|
@@ -112,25 +97,29 @@
|
|
|
112
97
|
},
|
|
113
98
|
"dependencies": {
|
|
114
99
|
"@env-spec/parser": "0.6.2",
|
|
115
|
-
"@vite-hub/runtime": "0.
|
|
116
|
-
"nostics": "1.
|
|
100
|
+
"@vite-hub/runtime": "0.3.0",
|
|
101
|
+
"nostics": "1.4.0",
|
|
117
102
|
"valibot": "^1.5.0"
|
|
118
103
|
},
|
|
119
104
|
"devDependencies": {
|
|
105
|
+
"@types/node": "^24.19.1",
|
|
120
106
|
"zod": "^4.6.7",
|
|
107
|
+
"@vite-hub/internal": "0.0.1",
|
|
121
108
|
"publint": "^0.3.25",
|
|
122
109
|
"typescript": "^6.0.3",
|
|
123
110
|
"vite": "^8.2.2",
|
|
124
111
|
"vite-plus": "^0.3.3",
|
|
125
112
|
"vitest": "^4.1.11",
|
|
126
|
-
"drizzle-orm": "
|
|
113
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
127
114
|
"@libsql/client": "^0.18.0",
|
|
128
|
-
"
|
|
115
|
+
"miniflare": "4.20260730.0",
|
|
116
|
+
"nitro": "^3.0.261103-rc"
|
|
129
117
|
},
|
|
130
118
|
"peerDependencies": {
|
|
131
119
|
"vite": ">=8.0.0",
|
|
132
|
-
"drizzle-orm": "^0.
|
|
133
|
-
"@vite-hub/agent": "0.
|
|
120
|
+
"drizzle-orm": "1.0.0-rc.5 || ^1.0.0",
|
|
121
|
+
"@vite-hub/agent": "0.3.0",
|
|
122
|
+
"nitro": "3.0.261102-rc || ^3.0.261103-rc"
|
|
134
123
|
},
|
|
135
124
|
"peerDependenciesMeta": {
|
|
136
125
|
"vite": {
|
|
@@ -144,12 +133,12 @@
|
|
|
144
133
|
}
|
|
145
134
|
},
|
|
146
135
|
"engines": {
|
|
147
|
-
"node": ">=
|
|
136
|
+
"node": ">=22.18.0"
|
|
148
137
|
},
|
|
149
138
|
"scripts": {
|
|
150
139
|
"build": "vp pack",
|
|
151
140
|
"dev": "vp pack --watch",
|
|
152
141
|
"typecheck": "vp run --cache -t @vite-hub/env#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
153
|
-
"test": "vp run -t @vite-hub/env#build && vp test"
|
|
142
|
+
"test": "vp run --cache -t @vite-hub/env#build && vp test"
|
|
154
143
|
}
|
|
155
144
|
}
|
package/dist/auth.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { n as EnvAccessScope, t as EnvAccessContext } from "./bridge-CdNdTN1V.js";
|
|
2
|
-
//#region src/auth.d.ts
|
|
3
|
-
export interface EnvHumanSession {
|
|
4
|
-
user: {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export interface EnvAgentSession {
|
|
9
|
-
agent: {
|
|
10
|
-
id: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export type EnvAgentScope = EnvAccessScope;
|
|
14
|
-
export interface EnvAuthenticatorOptions<Human extends EnvHumanSession, Agent extends EnvAgentSession> {
|
|
15
|
-
/** Pass Better Auth's auth.api.getSession, preserving the incoming headers. */
|
|
16
|
-
getSession(input: {
|
|
17
|
-
headers: Headers;
|
|
18
|
-
}): Promise<Human | null>;
|
|
19
|
-
/** Application policy; authentication alone never grants administrator access. */
|
|
20
|
-
isAdmin(session: Human): boolean | Promise<boolean>;
|
|
21
|
-
agents?: {
|
|
22
|
-
/** Must verify the credential, e.g. auth.api.getAgentSession from Agent Auth. */
|
|
23
|
-
getSession(input: {
|
|
24
|
-
headers: Headers;
|
|
25
|
-
}): Promise<Agent | null>;
|
|
26
|
-
/** Map verified capability grants AND their constraints to exact store keys. */
|
|
27
|
-
scope(session: Agent): EnvAgentScope | null | Promise<EnvAgentScope | null>;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/** Authenticate management requests without coupling Env to a particular Better Auth plugin version. */
|
|
31
|
-
export declare function createEnvAuthenticator<Human extends EnvHumanSession, Agent extends EnvAgentSession = EnvAgentSession>(options: EnvAuthenticatorOptions<Human, Agent>): (request: Request) => Promise<EnvAccessContext | null>;
|
|
32
|
-
//#endregion
|
package/dist/auth.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { r as grantEnvAccess } from "./access-B3qzBHye.js";
|
|
2
|
-
//#region src/auth.ts
|
|
3
|
-
const permissions = [
|
|
4
|
-
"inspect",
|
|
5
|
-
"preview",
|
|
6
|
-
"replace",
|
|
7
|
-
"use"
|
|
8
|
-
];
|
|
9
|
-
function identifier(value) {
|
|
10
|
-
return typeof value === "string" && value.length > 0 && value.length <= 512 && !/[\u0000-\u001f]/.test(value);
|
|
11
|
-
}
|
|
12
|
-
/** Authenticate management requests without coupling Env to a particular Better Auth plugin version. */
|
|
13
|
-
function createEnvAuthenticator(options) {
|
|
14
|
-
return async (request) => {
|
|
15
|
-
try {
|
|
16
|
-
const authorization = request.headers.get("authorization");
|
|
17
|
-
if (authorization !== null) {
|
|
18
|
-
if (!/^Bearer\s+\S+$/i.test(authorization) || !options.agents) return null;
|
|
19
|
-
const session = await options.agents.getSession({ headers: request.headers });
|
|
20
|
-
if (!session || !identifier(session.agent.id)) return null;
|
|
21
|
-
const scope = await options.agents.scope(session);
|
|
22
|
-
if (!Array.isArray(scope) || scope.some((grant) => !identifier(grant.key) || !Array.isArray(grant.permissions) || grant.permissions.some((permission) => !permissions.includes(permission)))) return null;
|
|
23
|
-
return grantEnvAccess({ actor: {
|
|
24
|
-
kind: "agent",
|
|
25
|
-
id: session.agent.id
|
|
26
|
-
} }, {
|
|
27
|
-
kind: "actor",
|
|
28
|
-
scope
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
const session = await options.getSession({ headers: request.headers });
|
|
32
|
-
if (!session || !identifier(session.user.id)) return null;
|
|
33
|
-
const actor = {
|
|
34
|
-
kind: "user",
|
|
35
|
-
id: session.user.id
|
|
36
|
-
};
|
|
37
|
-
return grantEnvAccess({ actor }, await options.isAdmin(session) === true ? { kind: "admin" } : { kind: "actor" });
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { createEnvAuthenticator };
|
package/dist/cli-DEwcUIe0.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Diagnostic } from "nostics";
|
|
2
|
-
//#region ../internal/src/provision.d.ts
|
|
3
|
-
type ProvisionProvider = "cloudflare" | "vercel";
|
|
4
|
-
interface ProvisionLogger {
|
|
5
|
-
log: (message: string) => void;
|
|
6
|
-
warn: (message: string) => void;
|
|
7
|
-
}
|
|
8
|
-
interface ProvisionContext {
|
|
9
|
-
env: Record<string, string | undefined>;
|
|
10
|
-
fetch: typeof globalThis.fetch;
|
|
11
|
-
logger: ProvisionLogger;
|
|
12
|
-
markPlanUnchecked?: () => void;
|
|
13
|
-
}
|
|
14
|
-
interface ProvisionState {
|
|
15
|
-
cloudflare?: Record<string, Record<string, string>>;
|
|
16
|
-
vercel?: Record<string, Record<string, string>>;
|
|
17
|
-
}
|
|
18
|
-
interface ProvisionResult {
|
|
19
|
-
ids?: ProvisionState;
|
|
20
|
-
}
|
|
21
|
-
interface ProvisionAction {
|
|
22
|
-
kind: string;
|
|
23
|
-
name: string;
|
|
24
|
-
exists: boolean;
|
|
25
|
-
pending?: boolean;
|
|
26
|
-
apply: () => Promise<ProvisionResult>;
|
|
27
|
-
}
|
|
28
|
-
interface ProvisionStep {
|
|
29
|
-
id: string;
|
|
30
|
-
provider: ProvisionProvider;
|
|
31
|
-
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region ../internal/src/cli.d.ts
|
|
35
|
-
interface ViteHubCliStreams {
|
|
36
|
-
stderr: {
|
|
37
|
-
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
38
|
-
};
|
|
39
|
-
stdout: {
|
|
40
|
-
write: (chunk: string | Uint8Array) => unknown;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface ViteHubCliSpawnResult {
|
|
44
|
-
exitCode: number | null;
|
|
45
|
-
signal?: NodeJS.Signals | null;
|
|
46
|
-
}
|
|
47
|
-
interface ViteHubCliSpawnOptions {
|
|
48
|
-
cwd?: string;
|
|
49
|
-
env?: NodeJS.ProcessEnv;
|
|
50
|
-
stderr?: "inherit" | "pipe";
|
|
51
|
-
stdout?: "inherit" | "pipe";
|
|
52
|
-
}
|
|
53
|
-
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
54
|
-
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
55
|
-
cwd: string;
|
|
56
|
-
env: NodeJS.ProcessEnv;
|
|
57
|
-
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
58
|
-
fetch?: typeof fetch;
|
|
59
|
-
rootDir: string;
|
|
60
|
-
spawn: ViteHubCliSpawn;
|
|
61
|
-
}
|
|
62
|
-
interface ViteHubCliFeature {
|
|
63
|
-
description?: string;
|
|
64
|
-
name: string;
|
|
65
|
-
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
66
|
-
usage?: string;
|
|
67
|
-
}
|
|
68
|
-
interface ViteHubCliCommandNamespace {
|
|
69
|
-
/** The feature that `vitehub <name>` runs when no feature is named. */
|
|
70
|
-
defaultFeature?: string;
|
|
71
|
-
description?: string;
|
|
72
|
-
features: ViteHubCliFeature[];
|
|
73
|
-
name: string;
|
|
74
|
-
}
|
|
75
|
-
interface ViteHubCliContributor {
|
|
76
|
-
namespaces: ViteHubCliCommandNamespace[];
|
|
77
|
-
provision?: ProvisionStep[];
|
|
78
|
-
}
|
|
79
|
-
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
80
|
-
//#endregion
|
|
81
|
-
export { ViteHubCliContributor as n, ViteHubCliContext as t };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { E as EnvSource, M as EnvVariableOptions, O as EnvSourceResolver, j as EnvVariableDeclaration, k as EnvTypedVariableOptions } from "./bridge-CdNdTN1V.js";
|
|
2
|
-
//#region src/core/declarations.d.ts
|
|
3
|
-
interface EnvNamespace {
|
|
4
|
-
(options?: EnvVariableOptions): EnvVariableDeclaration;
|
|
5
|
-
/** Parse `true`, `false`, `1`, or `0` into a boolean. */
|
|
6
|
-
boolean: (options?: EnvTypedVariableOptions<boolean>) => EnvVariableDeclaration;
|
|
7
|
-
buildTimestamp: () => EnvSource;
|
|
8
|
-
custom: (label: string, resolver: EnvSourceResolver) => EnvSource;
|
|
9
|
-
/** Accept only the listed strings. The values are public metadata, so an enum cannot be secret. */
|
|
10
|
-
enum: <const TValues extends readonly [string, ...string[]]>(values: TValues, options?: Omit<EnvTypedVariableOptions<TValues[number]>, "secret">) => EnvVariableDeclaration;
|
|
11
|
-
gitBranch: () => EnvSource;
|
|
12
|
-
gitCommit: (options?: {
|
|
13
|
-
short?: boolean;
|
|
14
|
-
}) => EnvSource;
|
|
15
|
-
gitRef: () => EnvSource;
|
|
16
|
-
gitSha: (options?: {
|
|
17
|
-
short?: boolean;
|
|
18
|
-
}) => EnvSource;
|
|
19
|
-
gitTag: () => EnvSource;
|
|
20
|
-
/** Parse a finite number. */
|
|
21
|
-
number: (options?: EnvTypedVariableOptions<number>) => EnvVariableDeclaration;
|
|
22
|
-
packageJson: (path: string) => EnvSource;
|
|
23
|
-
provider: (provider: string, key: string) => EnvSource;
|
|
24
|
-
source: (name: string | string[], options?: {
|
|
25
|
-
canonical?: boolean;
|
|
26
|
-
skipEmpty?: boolean;
|
|
27
|
-
}) => EnvSource;
|
|
28
|
-
variable: (options?: EnvVariableOptions) => EnvVariableDeclaration;
|
|
29
|
-
}
|
|
30
|
-
declare const env: EnvNamespace;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { env as t };
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "./error-diagnostics-CrxjYNYr.js";
|
|
2
|
-
import { i as stringValueSchema, n as parseEnvValue, o as hasRuntimeType, s as isRuntimeRecord, t as envValueTypeName } from "./values-D_r6V774.js";
|
|
3
|
-
//#region src/core/declarations.ts
|
|
4
|
-
const runtimeSchemaProperty = "__vitehubRuntimeSchema";
|
|
5
|
-
const runtimeSchemaToken = getRuntimeSchemaToken();
|
|
6
|
-
const runtimeSchemaParsers = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
const runtimeSchemas = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
function createRuntimeValueSchema(valueSchema) {
|
|
9
|
-
const safeParse = (input) => {
|
|
10
|
-
const result = parseEnvValue(valueSchema, input);
|
|
11
|
-
return result.success ? result : {
|
|
12
|
-
error: envErrorDiagnostics.ENV_R0001({ message: result.message }),
|
|
13
|
-
success: false
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
runtimeSchemaParsers.set(safeParse, valueSchema);
|
|
17
|
-
return {
|
|
18
|
-
[runtimeSchemaProperty]: runtimeSchemaToken,
|
|
19
|
-
safeParse
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const defaultStringSchema = createRuntimeValueSchema(stringValueSchema);
|
|
23
|
-
const booleanSchema = createRuntimeValueSchema(Object.freeze({ kind: "boolean" }));
|
|
24
|
-
const numberSchema = createRuntimeValueSchema(Object.freeze({ kind: "number" }));
|
|
25
|
-
function source(name, options = {}) {
|
|
26
|
-
const names = Array.isArray(name) ? name : [name];
|
|
27
|
-
if (!names.length || names.some((value) => typeof value !== "string" || !value.trim())) throw envErrorDiagnostics.ENV_R0002({ message: "env.source() requires one or more non-empty env variable names." });
|
|
28
|
-
const normalized = names.map((value) => value.trim());
|
|
29
|
-
return {
|
|
30
|
-
kind: "env",
|
|
31
|
-
label: `env:${normalized.join("|")}`,
|
|
32
|
-
name: normalized[0],
|
|
33
|
-
...options.canonical === false ? { canonical: false } : {},
|
|
34
|
-
...normalized.length > 1 ? { names: normalized } : {},
|
|
35
|
-
...options.skipEmpty ? { skipEmpty: true } : {},
|
|
36
|
-
serializable: true
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function custom(label, resolver) {
|
|
40
|
-
return {
|
|
41
|
-
kind: "custom",
|
|
42
|
-
label,
|
|
43
|
-
resolver,
|
|
44
|
-
serializable: false
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function gitBranch() {
|
|
48
|
-
return {
|
|
49
|
-
kind: "git-branch",
|
|
50
|
-
label: "git:branch",
|
|
51
|
-
serializable: true
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function gitCommit(options = {}) {
|
|
55
|
-
return {
|
|
56
|
-
kind: "git-commit",
|
|
57
|
-
label: "git:commit",
|
|
58
|
-
serializable: true,
|
|
59
|
-
short: options.short
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function gitRef() {
|
|
63
|
-
return {
|
|
64
|
-
kind: "git-ref",
|
|
65
|
-
label: "git:ref",
|
|
66
|
-
serializable: true
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function gitSha(options = {}) {
|
|
70
|
-
return {
|
|
71
|
-
kind: "git-sha",
|
|
72
|
-
label: "git:sha",
|
|
73
|
-
serializable: true,
|
|
74
|
-
short: options.short
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function gitTag() {
|
|
78
|
-
return {
|
|
79
|
-
kind: "git-tag",
|
|
80
|
-
label: "git:tag",
|
|
81
|
-
serializable: true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function buildTimestamp() {
|
|
85
|
-
return {
|
|
86
|
-
kind: "build-timestamp",
|
|
87
|
-
label: "build:timestamp",
|
|
88
|
-
serializable: true
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function packageJson(path) {
|
|
92
|
-
return {
|
|
93
|
-
kind: "package-json",
|
|
94
|
-
label: `package.json:${path}`,
|
|
95
|
-
path,
|
|
96
|
-
serializable: true
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function provider(provider, key) {
|
|
100
|
-
if (typeof provider !== "string" || !/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(provider.trim())) throw envErrorDiagnostics.ENV_R0003({ message: "env.provider() requires a provider name that starts with a letter and contains only letters, numbers, underscores, or hyphens." });
|
|
101
|
-
if (typeof key !== "string" || !key.trim() || key.length > 512) throw envErrorDiagnostics.ENV_R0004({ message: "env.provider() requires a non-empty provider key." });
|
|
102
|
-
return {
|
|
103
|
-
key: key.trim(),
|
|
104
|
-
kind: "provider",
|
|
105
|
-
label: "provider",
|
|
106
|
-
provider: provider.trim(),
|
|
107
|
-
serializable: true
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function variable(options = {}) {
|
|
111
|
-
options = readDeclarationOptions(options);
|
|
112
|
-
return createDeclaration(options, options.schema ?? defaultStringSchema, options.type);
|
|
113
|
-
}
|
|
114
|
-
function typedVariable(schema, options) {
|
|
115
|
-
options = readDeclarationOptions(options);
|
|
116
|
-
const valueSchema = runtimeSchemaParsers.get(schema.safeParse);
|
|
117
|
-
return createDeclaration(options, schema, valueSchema && envValueTypeName(valueSchema));
|
|
118
|
-
}
|
|
119
|
-
/** Create an internal built-in declaration whose parser survives runtime serialization. */
|
|
120
|
-
function descriptorVariable(valueSchema, options) {
|
|
121
|
-
return typedVariable(createRuntimeValueSchema(valueSchema), options);
|
|
122
|
-
}
|
|
123
|
-
function booleanVariable(options = {}) {
|
|
124
|
-
return typedVariable(booleanSchema, options);
|
|
125
|
-
}
|
|
126
|
-
function numberVariable(options = {}) {
|
|
127
|
-
return typedVariable(numberSchema, options);
|
|
128
|
-
}
|
|
129
|
-
function enumVariable(values, options = {}) {
|
|
130
|
-
if (!Array.isArray(values) || !values.length || values.some((value) => !hasRuntimeType(value, "string") || !value) || new Set(values).size !== values.length) throw envErrorDiagnostics.ENV_R0022({ message: "env.enum() requires one or more unique non-empty strings." });
|
|
131
|
-
return typedVariable(createRuntimeValueSchema(Object.freeze({
|
|
132
|
-
kind: "enum",
|
|
133
|
-
values: Object.freeze([...values])
|
|
134
|
-
})), options);
|
|
135
|
-
}
|
|
136
|
-
function isInspectableRecord(value) {
|
|
137
|
-
try {
|
|
138
|
-
if (!isRuntimeRecord(value)) return false;
|
|
139
|
-
Reflect.ownKeys(value);
|
|
140
|
-
return true;
|
|
141
|
-
} catch {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function readDeclarationOptions(options) {
|
|
146
|
-
if (!isInspectableRecord(options)) throw envErrorDiagnostics.ENV_R0005({ message: "env() only accepts a single options object." });
|
|
147
|
-
let snapshot;
|
|
148
|
-
try {
|
|
149
|
-
snapshot = {
|
|
150
|
-
default: options.default,
|
|
151
|
-
mode: options.mode,
|
|
152
|
-
optional: options.optional,
|
|
153
|
-
required: options.required,
|
|
154
|
-
schema: options.schema,
|
|
155
|
-
secret: options.secret,
|
|
156
|
-
source: options.source,
|
|
157
|
-
type: options.type
|
|
158
|
-
};
|
|
159
|
-
} catch {
|
|
160
|
-
throw envErrorDiagnostics.ENV_R0005({ message: "env() only accepts a single options object." });
|
|
161
|
-
}
|
|
162
|
-
if (snapshot.optional && snapshot.required !== void 0) throw envErrorDiagnostics.ENV_R0006({ message: "env() cannot use both optional and required." });
|
|
163
|
-
return snapshot;
|
|
164
|
-
}
|
|
165
|
-
function createDeclaration(options, schema, type) {
|
|
166
|
-
const required = options.optional ? false : options.required ?? true;
|
|
167
|
-
const source = typeof options.source === "function" ? custom("custom", options.source) : options.source;
|
|
168
|
-
const declaration = {
|
|
169
|
-
default: options.default,
|
|
170
|
-
kind: "env-variable",
|
|
171
|
-
mode: options.mode ?? "runtime",
|
|
172
|
-
required,
|
|
173
|
-
schema,
|
|
174
|
-
secret: options.secret ?? false,
|
|
175
|
-
source,
|
|
176
|
-
type
|
|
177
|
-
};
|
|
178
|
-
if (isRuntimeValueSchema(schema)) {
|
|
179
|
-
runtimeSchemas.set(declaration, schema);
|
|
180
|
-
Object.defineProperty(declaration, runtimeSchemaProperty, {
|
|
181
|
-
enumerable: true,
|
|
182
|
-
value: runtimeSchemaToken
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
return declaration;
|
|
186
|
-
}
|
|
187
|
-
const env = Object.assign(variable, {
|
|
188
|
-
boolean: booleanVariable,
|
|
189
|
-
buildTimestamp,
|
|
190
|
-
custom,
|
|
191
|
-
enum: enumVariable,
|
|
192
|
-
gitBranch,
|
|
193
|
-
gitCommit,
|
|
194
|
-
gitRef,
|
|
195
|
-
gitSha,
|
|
196
|
-
gitTag,
|
|
197
|
-
number: numberVariable,
|
|
198
|
-
packageJson,
|
|
199
|
-
provider,
|
|
200
|
-
source,
|
|
201
|
-
variable
|
|
202
|
-
});
|
|
203
|
-
/** Return the serializable value schema of a declaration created by `env()`, `env.boolean()`, `env.number()`, or `env.enum()`. */
|
|
204
|
-
function runtimeValueSchema(declaration) {
|
|
205
|
-
const schema = declaration.schema;
|
|
206
|
-
if (runtimeSchemas.get(declaration) === schema && isRuntimeValueSchema(schema)) return runtimeSchemaParsers.get(schema.safeParse);
|
|
207
|
-
try {
|
|
208
|
-
if (Object.getOwnPropertyDescriptor(declaration, runtimeSchemaProperty)?.value !== runtimeSchemaToken || !isRuntimeRecord(schema)) return void 0;
|
|
209
|
-
if (Object.getOwnPropertyDescriptor(schema, runtimeSchemaProperty)?.value !== runtimeSchemaToken || !hasOnlyRuntimeSchemaKeys(schema)) return void 0;
|
|
210
|
-
const safeParse = Object.getOwnPropertyDescriptor(schema, "safeParse")?.value;
|
|
211
|
-
return hasRuntimeType(safeParse, "function") ? runtimeSchemaParsers.get(safeParse) : void 0;
|
|
212
|
-
} catch {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function isRuntimeValueSchema(schema) {
|
|
217
|
-
try {
|
|
218
|
-
return isRuntimeRecord(schema) && hasRuntimeType(schema.safeParse, "function") && runtimeSchemaParsers.has(schema.safeParse);
|
|
219
|
-
} catch {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function getRuntimeSchemaToken() {
|
|
224
|
-
const tokenKey = Symbol.for("vitehub.env.runtimeSchemaToken");
|
|
225
|
-
const globalScope = globalThis;
|
|
226
|
-
globalScope[tokenKey] ??= `schema:${Math.random().toString(36).slice(2)}`;
|
|
227
|
-
return globalScope[tokenKey];
|
|
228
|
-
}
|
|
229
|
-
function hasOnlyRuntimeSchemaKeys(schema) {
|
|
230
|
-
if ("~standard" in schema || "parse" in schema) return false;
|
|
231
|
-
const keys = Reflect.ownKeys(schema);
|
|
232
|
-
const safeParse = Object.getOwnPropertyDescriptor(schema, "safeParse");
|
|
233
|
-
return keys.length === 2 && keys.includes(runtimeSchemaProperty) && keys.includes("safeParse") && hasRuntimeType(safeParse?.value, "function");
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
|
-
export { env as n, runtimeValueSchema as r, descriptorVariable as t };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { defineDiagnostics } from "nostics";
|
|
2
|
-
//#region src/error-diagnostics.ts
|
|
3
|
-
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
-
const envErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
-
docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
|
|
6
|
-
codes: {
|
|
7
|
-
ENV_R0001: dynamicError,
|
|
8
|
-
ENV_R0002: dynamicError,
|
|
9
|
-
ENV_R0003: dynamicError,
|
|
10
|
-
ENV_R0004: dynamicError,
|
|
11
|
-
ENV_R0005: dynamicError,
|
|
12
|
-
ENV_R0006: dynamicError,
|
|
13
|
-
ENV_R0007: dynamicError,
|
|
14
|
-
ENV_R0008: dynamicError,
|
|
15
|
-
ENV_R0009: dynamicError,
|
|
16
|
-
ENV_R0010: dynamicError,
|
|
17
|
-
ENV_R0011: dynamicError,
|
|
18
|
-
ENV_R0012: dynamicError,
|
|
19
|
-
ENV_R0013: dynamicError,
|
|
20
|
-
ENV_R0014: dynamicError,
|
|
21
|
-
ENV_R0015: dynamicError,
|
|
22
|
-
ENV_R0016: dynamicError,
|
|
23
|
-
ENV_R0017: dynamicError,
|
|
24
|
-
ENV_R0018: dynamicError,
|
|
25
|
-
ENV_R0019: dynamicError,
|
|
26
|
-
ENV_R0020: dynamicError,
|
|
27
|
-
ENV_R0021: dynamicError,
|
|
28
|
-
ENV_R0022: dynamicError,
|
|
29
|
-
ENV_R0023: dynamicError,
|
|
30
|
-
ENV_R0024: dynamicError,
|
|
31
|
-
ENV_R0025: dynamicError,
|
|
32
|
-
ENV_R0026: dynamicError,
|
|
33
|
-
ENV_R0027: dynamicError,
|
|
34
|
-
ENV_R0028: dynamicError,
|
|
35
|
-
ENV_B0001: dynamicError,
|
|
36
|
-
ENV_B0002: dynamicError,
|
|
37
|
-
ENV_B0003: dynamicError,
|
|
38
|
-
ENV_B0004: dynamicError,
|
|
39
|
-
ENV_B0005: dynamicError
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
//#endregion
|
|
43
|
-
export { envErrorDiagnostics as t };
|
package/dist/http.d.ts
DELETED