@vite-hub/env 0.0.2 → 0.0.4

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.
@@ -0,0 +1,303 @@
1
+ import { SecretEnv } from "./secret.js";
2
+ import { i as invalidRuntimeEnvValue, n as envSourceFailed, o as missingRequiredEnv, t as asyncServerEnvRequired } from "./errors-C4Xcs6Fi.js";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ import { isViteHubError } from "@vite-hub/runtime";
5
+ const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
6
+ const runtimeGlobal = globalThis;
7
+ const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
8
+ function getActiveCloudflareEnv() {
9
+ const scoped = activeEnvStorage.getStore();
10
+ return scoped ? scoped.env : globalThis.__env__;
11
+ }
12
+ function getCloudflareEnv(event) {
13
+ const target = event;
14
+ return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || target?.node?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
15
+ }
16
+ //#endregion
17
+ //#region src/server.ts
18
+ function isRecord(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ function isRuntimeLiteralEntry(value) {
22
+ return isRecord(value) && value.kind === "literal";
23
+ }
24
+ function isRuntimeEnvEntry(value) {
25
+ return isRecord(value) && isRecord(value.source) && value.source.kind === "env" && typeof value.source.name === "string" && typeof value.required === "boolean" && typeof value.secret === "boolean";
26
+ }
27
+ function isRuntimeProviderEntry(value) {
28
+ return isRecord(value) && isRecord(value.source) && value.source.kind === "provider" && typeof value.source.key === "string" && typeof value.source.provider === "string" && typeof value.required === "boolean" && typeof value.secret === "boolean";
29
+ }
30
+ function processEnv() {
31
+ return typeof process === "object" && process && process.env ? process.env : {};
32
+ }
33
+ function runtimeEnv(event) {
34
+ return {
35
+ ...processEnv(),
36
+ ...getCloudflareEnv(event)
37
+ };
38
+ }
39
+ function readRuntimeSource(entry, env) {
40
+ for (const name of entry.source.names || [entry.source.name]) if (Object.hasOwn(env, name) && typeof env[name] !== "undefined") return {
41
+ found: true,
42
+ value: env[name]
43
+ };
44
+ return { found: false };
45
+ }
46
+ function resolvedRuntimeValue(entry, value, found) {
47
+ const resolved = found ? value : entry.default;
48
+ if (typeof resolved === "undefined") {
49
+ if (entry.required) throw missingRequiredEnv(entry.source.kind, `Missing Runtime Env from ${entry.source.kind}.`);
50
+ return;
51
+ }
52
+ if (typeof resolved !== "string") throw invalidRuntimeEnvValue(entry.source.kind, `Runtime Env from ${entry.source.kind} must resolve to a string.`);
53
+ return entry.secret ? new SecretEnv(resolved) : resolved;
54
+ }
55
+ function resolveRegistryValue(value, env, path) {
56
+ if (isRuntimeLiteralEntry(value)) return value.value;
57
+ if (isRuntimeEnvEntry(value)) {
58
+ const source = readRuntimeSource(value, env);
59
+ return resolvedRuntimeValue(value, source.value, source.found);
60
+ }
61
+ if (isRuntimeProviderEntry(value)) throw asyncServerEnvRequired(path);
62
+ if (!isRecord(value)) return void 0;
63
+ const output = Object.create(null);
64
+ for (const [key, child] of Object.entries(value)) {
65
+ const childPath = `${path}.${key}`;
66
+ if (isRuntimeProviderEntry(child)) Object.defineProperty(output, key, {
67
+ enumerable: true,
68
+ get() {
69
+ throw asyncServerEnvRequired(childPath);
70
+ }
71
+ });
72
+ else output[key] = resolveRegistryValue(child, env, childPath);
73
+ }
74
+ return output;
75
+ }
76
+ function providerFor(name, providers) {
77
+ let provider;
78
+ try {
79
+ const configured = providers && Object.hasOwn(providers, name) ? providers[name] : void 0;
80
+ if (configured && typeof configured === "object" && typeof configured.read === "function") {
81
+ const read = configured.read;
82
+ provider = { read: (input) => read.call(configured, input) };
83
+ }
84
+ } catch (cause) {
85
+ throw envSourceFailed("provider", cause);
86
+ }
87
+ if (!provider) throw new TypeError("The configured Server Env provider is unavailable or invalid.");
88
+ return provider;
89
+ }
90
+ function abortReason(signal) {
91
+ return signal.reason === void 0 ? Object.assign(/* @__PURE__ */ new Error("Server Env loading was aborted."), { name: "AbortError" }) : signal.reason;
92
+ }
93
+ async function withAbort(operation, signal) {
94
+ if (!signal) return await operation();
95
+ if (signal.aborted) throw abortReason(signal);
96
+ return await new Promise((resolve, reject) => {
97
+ const abort = () => reject(abortReason(signal));
98
+ signal.addEventListener("abort", abort, { once: true });
99
+ Promise.resolve().then(() => {
100
+ if (signal.aborted) throw abortReason(signal);
101
+ return operation();
102
+ }).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
103
+ });
104
+ }
105
+ function isCancellation(error, signal) {
106
+ return Boolean(signal?.aborted && error === abortReason(signal));
107
+ }
108
+ async function readProvider(provider, input, signal) {
109
+ try {
110
+ return await withAbort(() => provider.read(input), signal);
111
+ } catch (cause) {
112
+ if (isCancellation(cause, signal)) throw cause;
113
+ throw envSourceFailed("provider", cause);
114
+ }
115
+ }
116
+ function collectProviderKeys(value, requests = /* @__PURE__ */ new Map()) {
117
+ if (isRuntimeProviderEntry(value)) {
118
+ let keys = requests.get(value.source.provider);
119
+ if (!keys) {
120
+ keys = /* @__PURE__ */ new Set();
121
+ requests.set(value.source.provider, keys);
122
+ }
123
+ keys.add(value.source.key);
124
+ return requests;
125
+ }
126
+ if (isRuntimeEnvEntry(value) || isRuntimeLiteralEntry(value) || !isRecord(value)) return requests;
127
+ for (const child of Object.values(value)) collectProviderKeys(child, requests);
128
+ return requests;
129
+ }
130
+ function normalizeProviderValues(value, keys) {
131
+ let record;
132
+ try {
133
+ if (isRecord(value)) record = value;
134
+ } catch (cause) {
135
+ throw envSourceFailed("provider", cause);
136
+ }
137
+ if (!record) throw invalidRuntimeEnvValue("provider", "A Server Env provider must return a plain record.");
138
+ let prototype;
139
+ try {
140
+ prototype = Object.getPrototypeOf(record);
141
+ } catch (cause) {
142
+ throw envSourceFailed("provider", cause);
143
+ }
144
+ if (prototype !== null && prototype !== Object.prototype) throw invalidRuntimeEnvValue("provider", "A Server Env provider must return a plain record.");
145
+ const output = /* @__PURE__ */ new Map();
146
+ for (const key of keys) {
147
+ let descriptor;
148
+ try {
149
+ descriptor = Object.getOwnPropertyDescriptor(record, key);
150
+ } catch (cause) {
151
+ throw envSourceFailed("provider", cause);
152
+ }
153
+ if (!descriptor) {
154
+ output.set(key, void 0);
155
+ continue;
156
+ }
157
+ if (!("value" in descriptor)) throw invalidRuntimeEnvValue("provider", "A Server Env provider returned an accessor instead of a value.");
158
+ output.set(key, descriptor.value);
159
+ }
160
+ return output;
161
+ }
162
+ function createProviderLoads(registry, localEnv, options) {
163
+ if (options.signal?.aborted) throw abortReason(options.signal);
164
+ const loads = /* @__PURE__ */ new Map();
165
+ for (const [name, requested] of collectProviderKeys(registry)) {
166
+ const keys = Object.freeze([...requested]);
167
+ const load = Promise.resolve().then(() => providerFor(name, options.providers)).then((provider) => readProvider(provider, {
168
+ env: localEnv,
169
+ keys,
170
+ signal: options.signal
171
+ }, options.signal)).then((value) => normalizeProviderValues(value, keys)).catch((cause) => {
172
+ if (options.signal?.aborted) throw abortReason(options.signal);
173
+ if (isCancellation(cause, options.signal) || isViteHubError(cause)) throw cause;
174
+ throw envSourceFailed("provider", cause);
175
+ });
176
+ loads.set(name, load);
177
+ }
178
+ return loads;
179
+ }
180
+ async function providerValue(entry, loads) {
181
+ const load = loads.get(entry.source.provider);
182
+ if (!load) throw envSourceFailed("provider", /* @__PURE__ */ new TypeError("The Server Env provider was not loaded."));
183
+ return (await load).get(entry.source.key);
184
+ }
185
+ const skipProviderValue = Symbol("vitehub.env.skip-provider");
186
+ function localRegistryValue(value, env, tolerateInvalid) {
187
+ if (isRuntimeLiteralEntry(value)) return snapshotValue(value.value);
188
+ if (isRuntimeProviderEntry(value)) return skipProviderValue;
189
+ if (isRuntimeEnvEntry(value)) try {
190
+ const source = readRuntimeSource(value, env);
191
+ return resolvedRuntimeValue(value, source.value, source.found);
192
+ } catch (error) {
193
+ if (!tolerateInvalid) throw error;
194
+ return skipProviderValue;
195
+ }
196
+ if (!isRecord(value)) return skipProviderValue;
197
+ const output = Object.create(null);
198
+ for (const [key, child] of Object.entries(value)) {
199
+ const resolved = localRegistryValue(child, env, tolerateInvalid);
200
+ if (resolved !== skipProviderValue) output[key] = resolved;
201
+ }
202
+ return Object.freeze(output);
203
+ }
204
+ function createLocalEnv(registry, env, tolerateInvalid) {
205
+ return localRegistryValue(registry, env, tolerateInvalid);
206
+ }
207
+ async function loadRegistryValue(value, env, loads) {
208
+ if (isRuntimeLiteralEntry(value)) return snapshotValue(value.value);
209
+ if (isRuntimeEnvEntry(value)) {
210
+ const source = readRuntimeSource(value, env);
211
+ return resolvedRuntimeValue(value, source.value, source.found);
212
+ }
213
+ if (isRuntimeProviderEntry(value)) {
214
+ const resolved = await providerValue(value, loads);
215
+ return resolvedRuntimeValue(value, resolved, typeof resolved !== "undefined");
216
+ }
217
+ if (!isRecord(value)) return void 0;
218
+ const output = Object.create(null);
219
+ for (const [key, child] of Object.entries(value)) output[key] = await loadRegistryValue(child, env, loads);
220
+ return Object.freeze(output);
221
+ }
222
+ function snapshotValue(value) {
223
+ if (!Array.isArray(value)) return value;
224
+ return Object.freeze(value.map(snapshotValue));
225
+ }
226
+ function inspectionStatus(entry, value, found) {
227
+ if (!found && typeof entry.default !== "undefined") return "defaulted";
228
+ if (!found || typeof value === "undefined") return "missing";
229
+ return typeof value === "string" ? "available" : "invalid";
230
+ }
231
+ function inspectionPath(path) {
232
+ if (path.length > 256) return {};
233
+ return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? { path } : {};
234
+ }
235
+ async function inspectRegistryValue(value, env, options, loads, path, entries) {
236
+ if (isRuntimeLiteralEntry(value)) {
237
+ entries.push({
238
+ masked: false,
239
+ ...inspectionPath(path),
240
+ source: "literal",
241
+ status: "available"
242
+ });
243
+ return;
244
+ }
245
+ if (isRuntimeEnvEntry(value)) {
246
+ const source = readRuntimeSource(value, env);
247
+ entries.push({
248
+ masked: value.secret,
249
+ ...inspectionPath(path),
250
+ source: "env",
251
+ status: inspectionStatus(value, source.value, source.found)
252
+ });
253
+ return;
254
+ }
255
+ if (isRuntimeProviderEntry(value)) {
256
+ try {
257
+ const resolved = await providerValue(value, loads);
258
+ entries.push({
259
+ masked: value.secret,
260
+ ...inspectionPath(path),
261
+ source: "provider",
262
+ status: inspectionStatus(value, resolved, typeof resolved !== "undefined")
263
+ });
264
+ } catch (error) {
265
+ if (isCancellation(error, options.signal)) throw error;
266
+ entries.push({
267
+ masked: value.secret,
268
+ ...inspectionPath(path),
269
+ source: "provider",
270
+ status: "error"
271
+ });
272
+ }
273
+ return;
274
+ }
275
+ if (!isRecord(value)) return;
276
+ for (const [key, child] of Object.entries(value)) await inspectRegistryValue(child, env, options, loads, `${path}.${key}`, entries);
277
+ }
278
+ function resolveServerEnv(registry, event) {
279
+ return resolveRegistryValue(registry, runtimeEnv(event), "env.server");
280
+ }
281
+ async function loadServerEnv(registry, event, options = {}) {
282
+ if (options.signal?.aborted) throw abortReason(options.signal);
283
+ const env = runtimeEnv(event);
284
+ const loads = createProviderLoads(registry, createLocalEnv(registry, env, false), options);
285
+ await Promise.all(loads.values());
286
+ if (options.signal?.aborted) throw abortReason(options.signal);
287
+ const value = await loadRegistryValue(registry, env, loads);
288
+ if (options.signal?.aborted) throw abortReason(options.signal);
289
+ return value;
290
+ }
291
+ async function inspectServerEnv(registry, event, options = {}) {
292
+ if (options.signal?.aborted) throw abortReason(options.signal);
293
+ const env = runtimeEnv(event);
294
+ const loads = createProviderLoads(registry, createLocalEnv(registry, env, true), options);
295
+ await Promise.allSettled(loads.values());
296
+ if (options.signal?.aborted) throw abortReason(options.signal);
297
+ const entries = [];
298
+ await inspectRegistryValue(registry, env, options, loads, "env.server", entries);
299
+ if (options.signal?.aborted) throw abortReason(options.signal);
300
+ return Object.freeze({ entries: Object.freeze(entries.map((entry) => Object.freeze(entry))) });
301
+ }
302
+ //#endregion
303
+ export { loadServerEnv as n, resolveServerEnv as r, inspectServerEnv as t };
package/dist/server.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { s as EnvRuntimeRegistry } from "./types-FcnPKias.js";
1
+ import { C as ServerEnvInspection, T as ServerEnvInspectionStatus, b as LoadServerEnvOptions, f as EnvRuntimeRegistry, t as DeepReadonly, w as ServerEnvInspectionEntry } from "./types-CsB6DTGE.js";
2
2
 
3
3
  //#region src/server.d.ts
4
- declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry, event?: unknown): TServerEnv;
4
+ declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown): TServerEnv;
5
+ declare function loadServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown, options?: LoadServerEnvOptions): Promise<DeepReadonly<TServerEnv>>;
6
+ declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: unknown, options?: LoadServerEnvOptions): Promise<ServerEnvInspection>;
5
7
  //#endregion
6
- export { resolveServerEnv };
8
+ export { type ServerEnvInspection, type ServerEnvInspectionEntry, type ServerEnvInspectionStatus, inspectServerEnv, loadServerEnv, resolveServerEnv };
package/dist/server.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./secret.js";
2
- import { t as resolveServerEnv } from "./server-B2Dp8Nc0.js";
3
- export { resolveServerEnv };
2
+ import { n as loadServerEnv, r as resolveServerEnv, t as inspectServerEnv } from "./server-C16sFc1E.js";
3
+ export { inspectServerEnv, loadServerEnv, resolveServerEnv };
@@ -1,3 +1,5 @@
1
+ import { t as SecretEnv } from "./secret-C2191nAa.js";
2
+
1
3
  //#region src/types.d.ts
2
4
  type EnvDiagnostics = "off" | "summary" | "trace";
3
5
  type EnvMode = "build" | "runtime";
@@ -5,6 +7,7 @@ interface EnvIntegrationOptions {
5
7
  diagnostics?: EnvDiagnostics;
6
8
  prefix?: string;
7
9
  projectRoot?: string;
10
+ providers?: Record<string, string>;
8
11
  runtimeImports?: EnvRuntimeImportSpecifiers;
9
12
  }
10
13
  interface EnvRuntimeImportSpecifiers {
@@ -74,6 +77,12 @@ type EnvSource = {
74
77
  label: string;
75
78
  path: string;
76
79
  serializable: true;
80
+ } | {
81
+ key: string;
82
+ kind: "provider";
83
+ label: "provider";
84
+ provider: string;
85
+ serializable: true;
77
86
  };
78
87
  interface EnvVariableDeclaration {
79
88
  default?: unknown;
@@ -130,7 +139,7 @@ interface EnvRegistryEntry {
130
139
  schema?: EnvRuntimeSchema;
131
140
  secret: boolean;
132
141
  source: Extract<EnvSource, {
133
- kind: "env";
142
+ kind: "env" | "provider";
134
143
  }>;
135
144
  type?: string;
136
145
  }
@@ -142,12 +151,40 @@ interface EnvRuntimeLiteralEntry {
142
151
  value: EnvRuntimeStaticValue;
143
152
  }
144
153
  type EnvRuntimeRegistryValue = EnvRegistryEntry | EnvRuntimeLiteralEntry | EnvRuntimeRegistry;
145
- interface EnvRuntimeRegistry {
154
+ declare const serverEnvType: unique symbol;
155
+ interface EnvRuntimeRegistry<TServerEnv extends Record<string, unknown> = Record<string, unknown>> {
146
156
  [key: string]: EnvRuntimeRegistryValue;
157
+ readonly [serverEnvType]?: (value: TServerEnv) => void;
147
158
  }
148
159
  interface ServerEnv {
149
160
  [key: string]: unknown;
150
161
  }
151
162
  type PublicEnv = Record<string, unknown>;
163
+ interface EnvProviderContext<TEnv extends Record<string, unknown> = Record<string, unknown>> {
164
+ env: DeepReadonly<TEnv>;
165
+ signal?: AbortSignal;
166
+ }
167
+ type EnvProviderValues = Readonly<Record<string, string | undefined>>;
168
+ interface EnvProvider<TEnv extends Record<string, unknown> = Record<string, unknown>> {
169
+ read(input: EnvProviderContext<TEnv> & {
170
+ keys: readonly string[];
171
+ }): EnvProviderValues | Promise<EnvProviderValues>;
172
+ }
173
+ type EnvProviders = Record<string, EnvProvider>;
174
+ interface LoadServerEnvOptions {
175
+ providers?: EnvProviders;
176
+ signal?: AbortSignal;
177
+ }
178
+ type DeepReadonly<T> = T extends SecretEnv<unknown> ? T : T extends ((...args: infer TArguments) => infer TResult) ? (...args: TArguments) => TResult : T extends object ? { readonly [TKey in keyof T]: DeepReadonly<T[TKey]> } : T;
179
+ type ServerEnvInspectionStatus = "available" | "defaulted" | "error" | "invalid" | "missing";
180
+ interface ServerEnvInspectionEntry {
181
+ masked: boolean;
182
+ path?: string;
183
+ source: "env" | "literal" | "provider";
184
+ status: ServerEnvInspectionStatus;
185
+ }
186
+ interface ServerEnvInspection {
187
+ entries: readonly ServerEnvInspectionEntry[];
188
+ }
152
189
  //#endregion
153
- export { EnvMode as a, EnvSource as c, EnvVariableDeclaration as d, EnvVariableOptions as f, ServerEnv as g, PublicEnv as h, EnvIntegrationOptions as i, EnvSourceContext as l, EnvViteUserConfig as m, EnvDiagnosticEntry as n, EnvRuntimeConfigOptions as o, EnvViteConfigOptions as p, EnvDiagnostics as r, EnvRuntimeRegistry as s, EnvConfigOptions as t, EnvSourceResolver as u };
190
+ export { ServerEnvInspection as C, ServerEnv as S, ServerEnvInspectionStatus as T, EnvVariableOptions as _, EnvIntegrationOptions as a, LoadServerEnvOptions as b, EnvProviderContext as c, EnvRuntimeConfigOptions as d, EnvRuntimeRegistry as f, EnvVariableDeclaration as g, EnvSourceResolver as h, EnvDiagnostics as i, EnvProviderValues as l, EnvSourceContext as m, EnvConfigOptions as n, EnvMode as o, EnvSource as p, EnvDiagnosticEntry as r, EnvProvider as s, DeepReadonly as t, EnvProviders as u, EnvViteConfigOptions as v, ServerEnvInspectionEntry as w, PublicEnv as x, EnvViteUserConfig as y };
@@ -0,0 +1,30 @@
1
+ declare module "#vitehub/env/public" {
2
+ export interface PublicEnv extends Record<string, unknown> {}
3
+ export const publicEnv: PublicEnv
4
+ export function usePublicEnv(): PublicEnv
5
+ }
6
+
7
+ declare module "#vitehub/env/server" {
8
+ export interface ServerEnv extends Record<string, unknown> {}
9
+ export interface ServerEnvInspectionEntry {
10
+ masked: boolean
11
+ path?: string
12
+ source: "env" | "literal" | "provider"
13
+ status: "available" | "defaulted" | "error" | "invalid" | "missing"
14
+ }
15
+ export interface ServerEnvInspection {
16
+ entries: readonly ServerEnvInspectionEntry[]
17
+ }
18
+ export type ReadonlyServerEnv = DeepReadonly<ServerEnv>
19
+ type DeepReadonly<T> = T extends import("@vite-hub/env/secret").SecretEnv<unknown>
20
+ ? T
21
+ : T extends (...args: infer TArguments) => infer TResult
22
+ ? (...args: TArguments) => TResult
23
+ : T extends object
24
+ ? { readonly [TKey in keyof T]: DeepReadonly<T[TKey]> }
25
+ : T
26
+ export function inspectServerEnv(event?: unknown, options?: { signal?: AbortSignal }): Promise<ServerEnvInspection>
27
+ export function loadServerEnv(event?: unknown, options?: { signal?: AbortSignal }): Promise<ReadonlyServerEnv>
28
+ export function useServerEnv(event?: unknown): ServerEnv
29
+ export function runWithServerEnv<T>(event: unknown, callback: (env: ReadonlyServerEnv) => T | Promise<T>, options?: { signal?: AbortSignal }): Promise<T>
30
+ }
package/dist/virtual.d.ts CHANGED
@@ -1,15 +1,2 @@
1
- declare module "#vitehub/env/public" {
2
- export interface PublicEnv extends Record<string, unknown> {}
3
- export const publicEnv: PublicEnv
4
- export function usePublicEnv(): PublicEnv
5
- }
6
-
7
- declare module "#vitehub/env/server" {
8
- import type { SecretEnv } from "@vite-hub/env/secret"
9
-
10
- export interface ServerEnv extends Record<string, unknown> {}
11
- export function useServerEnv(event?: unknown): ServerEnv
12
- export function runWithServerEnv<T>(event: unknown, callback: (env: ServerEnv) => T | Promise<T>): Promise<T>
13
- }
14
-
15
- export {}
1
+ /// <reference path="./virtual-module.d.ts" />
2
+ export { };
package/dist/vite.d.ts CHANGED
@@ -1,18 +1,28 @@
1
- import { i as EnvIntegrationOptions, p as EnvViteConfigOptions, s as EnvRuntimeRegistry } from "./types-FcnPKias.js";
2
- import { t as env } from "./declarations-BIBfEwer.js";
3
- import { Plugin } from "vite";
1
+ import { a as EnvIntegrationOptions, d as EnvRuntimeConfigOptions, f as EnvRuntimeRegistry, v as EnvViteConfigOptions } from "./types-CsB6DTGE.js";
2
+ import { t as env } from "./declarations-U6P3rvxC.js";
3
+ import { Plugin, UserConfig } from "vite";
4
4
 
5
5
  //#region ../internal/src/build/vite.d.ts
6
6
  declare const VITEHUB_ENV_PUBLIC_ID: "#vitehub/env/public";
7
7
  declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
8
8
  //#endregion
9
+ //#region src/core/resolve.d.ts
10
+ declare function createRuntimeRegistry(declarations: EnvRuntimeConfigOptions | undefined, options?: {
11
+ path?: string;
12
+ prefix?: string;
13
+ }): EnvRuntimeRegistry;
14
+ //#endregion
9
15
  //#region src/vite.d.ts
10
16
  declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
11
17
  declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
12
18
  declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
13
19
  interface EnvVitePluginAPI {
20
+ createServerEnvRegistry: (declarations: EnvRuntimeConfigOptions | undefined) => EnvRuntimeRegistry;
14
21
  getPublicEnv: () => Record<string, unknown>;
15
22
  getServerEnvRegistry: () => EnvRuntimeRegistry;
23
+ onServerEnvRegistry: (handler: (registry: EnvRuntimeRegistry, config: UserConfig) => void) => void;
24
+ prepareTypes: (config: EnvViteConfigOptions | undefined, viteRoot: string) => Promise<void>;
25
+ resolveProjectRoot: (viteRoot: string) => string;
16
26
  }
17
27
  type EnvVitePlugin = Plugin & {
18
28
  api: EnvVitePluginAPI;
@@ -30,4 +40,4 @@ declare module "vite" {
30
40
  }
31
41
  }
32
42
  //#endregion
33
- export { ENV_PUBLIC_ID, ENV_SERVER_ID, ENV_VITE_PLUGIN_NAME, EnvGeneratedPathOptions, EnvVitePlugin, EnvVitePluginAPI, createEnvImportAliases, createEnvTypeScriptPaths, env, hubEnv };
43
+ export { ENV_PUBLIC_ID, ENV_SERVER_ID, ENV_VITE_PLUGIN_NAME, EnvGeneratedPathOptions, EnvVitePlugin, EnvVitePluginAPI, createEnvImportAliases, createEnvTypeScriptPaths, createRuntimeRegistry as createRuntimeEnvRegistry, env, hubEnv };