@ayepi/env 0.2.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/LICENSE +21 -0
- package/README.md +178 -0
- package/ayepi-env.md +303 -0
- package/dist/dotenv.cjs +45 -0
- package/dist/dotenv.d.cts +36 -0
- package/dist/dotenv.d.ts +36 -0
- package/dist/dotenv.js +40 -0
- package/dist/index.cjs +739 -0
- package/dist/index.d.cts +166 -0
- package/dist/index.d.ts +166 -0
- package/dist/index.js +722 -0
- package/dist/load.cjs +40 -0
- package/dist/load.d.cts +21 -0
- package/dist/load.d.ts +21 -0
- package/dist/load.js +37 -0
- package/package.json +76 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { a as mergeSources, i as defaultSource, n as EnvError, o as resolveRaw, r as EnvSource, t as parseDotenv } from "./dotenv.cjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/coerce.d.ts
|
|
5
|
+
|
|
6
|
+
/** The effective (unwrapped) zod type name of a field — e.g. `optional(number)` → `'number'`. */
|
|
7
|
+
declare function effectiveType(schema: z.ZodType): string;
|
|
8
|
+
/** The default strings parsed as `true` / `false` (matched case-insensitively, trimmed). */
|
|
9
|
+
declare const DEFAULT_TRUE: ReadonlySet<string>;
|
|
10
|
+
declare const DEFAULT_FALSE: ReadonlySet<string>;
|
|
11
|
+
/** Override the strings recognized as booleans. Each side omitted falls back to its default set. */
|
|
12
|
+
interface BooleanWords {
|
|
13
|
+
/** Strings that mean `true` (replaces {@link DEFAULT_TRUE} when given). */
|
|
14
|
+
readonly true?: ReadonlySet<string>;
|
|
15
|
+
/** Strings that mean `false` (replaces {@link DEFAULT_FALSE} when given). */
|
|
16
|
+
readonly false?: ReadonlySet<string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Coerce `value` toward what `schema` expects. Non-string values pass through; strings are
|
|
20
|
+
* converted per the field's effective type — so a plain `z.number()` / `z.boolean()` / `z.date()`
|
|
21
|
+
* / `z.object()` works straight from env strings, **no `z.coerce` needed**. Returns the original
|
|
22
|
+
* string when a conversion is ambiguous or fails, so zod produces the final, authoritative error.
|
|
23
|
+
* Pass `words` to customize which strings count as boolean `true`/`false`.
|
|
24
|
+
*/
|
|
25
|
+
declare function coerce(schema: z.ZodType, value: unknown, words?: BooleanWords): unknown;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/env.d.ts
|
|
28
|
+
|
|
29
|
+
/** A field definition: a zod schema, or a factory taking the inherited (earlier-group) values. */
|
|
30
|
+
type EnvFieldDef<Inherited> = z.ZodType | ((inherited: Inherited) => z.ZodType | any);
|
|
31
|
+
/** The fields passed to {@link env} / {@link Env.add}. `Inherited` is the type resolved so far. */
|
|
32
|
+
type EnvInput<Inherited> = Record<string, EnvFieldDef<Inherited>>;
|
|
33
|
+
/** The resolved output type of an {@link EnvInput} (zod outputs, computed schema outputs, or plain values). */
|
|
34
|
+
type EnvOutput<Inherited, Input extends EnvInput<Inherited>> = { [K in keyof Input]: Input[K] extends z.ZodType ? z.output<Input[K]> : Input[K] extends ((inherited: Inherited) => infer R) ? R extends z.ZodType ? z.output<R> : R : never };
|
|
35
|
+
/** Values accepted by {@link Env.set}: known fields (typed or raw string) plus any extra source keys. */
|
|
36
|
+
type EnvSet<T extends object> = { [K in keyof T]?: T[K] | string } & {
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
/** Build-time options for {@link env} / {@link asyncEnv}. */
|
|
40
|
+
interface EnvOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Customize which strings coerce to booleans (case-insensitive). Each side you provide
|
|
43
|
+
* **replaces** its default set; an omitted side keeps the default. E.g.
|
|
44
|
+
* `{ booleans: { true: ['enabled'], false: ['disabled'] } }`.
|
|
45
|
+
*/
|
|
46
|
+
readonly booleans?: {
|
|
47
|
+
readonly true?: readonly string[];
|
|
48
|
+
readonly false?: readonly string[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Normalize {@link EnvOptions} into the lowercased {@link BooleanWords} the coercer consumes. */
|
|
52
|
+
|
|
53
|
+
/** Options for {@link Env.on}. */
|
|
54
|
+
interface EnvOnOptions {
|
|
55
|
+
/** Fire at most once, then auto-unsubscribe. */
|
|
56
|
+
once?: boolean;
|
|
57
|
+
/** Compare values structurally (deep-equal) for change detection, instead of by identity. */
|
|
58
|
+
deep?: boolean;
|
|
59
|
+
/** Fire immediately on subscribe with the current value(s). */
|
|
60
|
+
immediate?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** A typed, lazy, reactive config object built by {@link env}. */
|
|
63
|
+
interface Env<T extends object> {
|
|
64
|
+
/** Add more fields; their factories receive the fields resolved so far. Returns a wider {@link Env}. */
|
|
65
|
+
add<A extends EnvInput<T>>(input: A): Env<T & EnvOutput<T, A>>;
|
|
66
|
+
/** Resolve a single field (lazily). Throws an {@link EnvError} if that field is missing/invalid. */
|
|
67
|
+
get<K extends keyof T>(key: K): T[K];
|
|
68
|
+
/** Override a single field/source key (typed value or raw string). */
|
|
69
|
+
set<K extends keyof T>(key: K, value: T[K] | string): void;
|
|
70
|
+
/** Override several fields/source keys at once (e.g. pass `process.env` or a loaded `.env`). */
|
|
71
|
+
set(updates: EnvSet<T>): void;
|
|
72
|
+
/** Resolve every field. Throws an aggregated {@link EnvError} listing all missing/invalid fields. */
|
|
73
|
+
parse(): T;
|
|
74
|
+
/** Subscribe to *all* field changes; the listener gets `(key, value)`. Returns an unsubscribe fn. */
|
|
75
|
+
on(listener: (key: keyof T, value: T[keyof T]) => void, options?: EnvOnOptions): () => void;
|
|
76
|
+
/** Subscribe to one field's changes. */
|
|
77
|
+
on<K extends keyof T>(key: K, listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
78
|
+
/** Subscribe to several fields' changes with one listener. */
|
|
79
|
+
on<K extends keyof T>(keys: readonly K[], listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
80
|
+
/** Run `fn` with this env (for grouped setup); returns nothing. */
|
|
81
|
+
with(fn: (env: Env<T>) => void): void;
|
|
82
|
+
/** Run `fn` with this env and return its result. */
|
|
83
|
+
map<R>(fn: (env: Env<T>) => R): R;
|
|
84
|
+
}
|
|
85
|
+
/** Build a typed, lazy, reactive config from a record of fields. Reads `process.env` by default. */
|
|
86
|
+
declare function env<const T extends EnvInput<{}>>(input: T, options?: EnvOptions): Env<EnvOutput<{}, T>>;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/provider.d.ts
|
|
89
|
+
/** A value, or a promise of one. */
|
|
90
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
91
|
+
/**
|
|
92
|
+
* An external source of a single field's **raw** value. `load` provides the initial value; the
|
|
93
|
+
* optional `watch` pushes live updates and returns an unsubscribe function.
|
|
94
|
+
*/
|
|
95
|
+
interface EnvProvider {
|
|
96
|
+
/** Fetch the current raw value (e.g. query a DB / call a service). `undefined` means "absent". */
|
|
97
|
+
load(): MaybePromise<string | undefined>;
|
|
98
|
+
/** Subscribe to live updates; call `emit` with each new raw value. Return an unsubscribe fn. */
|
|
99
|
+
watch?(emit: (raw: string | undefined) => void): () => void;
|
|
100
|
+
}
|
|
101
|
+
/** A field bound to a live {@link EnvProvider}, validated by `schema`. Created by {@link dynamic}. */
|
|
102
|
+
interface DynamicBinding<V> {
|
|
103
|
+
readonly kind: 'dynamic';
|
|
104
|
+
readonly provider: EnvProvider;
|
|
105
|
+
readonly schema: z.ZodType<V>;
|
|
106
|
+
}
|
|
107
|
+
/** Bind a field to a live {@link EnvProvider}; values are validated against `schema`. */
|
|
108
|
+
declare function dynamic<V>(provider: EnvProvider, schema: z.ZodType<V>): DynamicBinding<V>;
|
|
109
|
+
/** True if `x` is a {@link DynamicBinding}. */
|
|
110
|
+
declare function isDynamic(x: unknown): x is DynamicBinding<unknown>;
|
|
111
|
+
/** A provider that re-fetches on an interval — the simplest way to make any source "dynamic". */
|
|
112
|
+
declare function pollProvider(fetch: () => MaybePromise<string | undefined>, intervalMs: number): EnvProvider;
|
|
113
|
+
/** A fixed-value provider (no updates) — handy for tests and constants behind the provider interface. */
|
|
114
|
+
declare function staticProvider(value: string | undefined): EnvProvider;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/async.d.ts
|
|
117
|
+
/** A field for {@link asyncEnv}: zod schema, dynamic binding, or a (possibly async) factory. */
|
|
118
|
+
type AsyncEnvFieldDef<Inherited> = z.ZodType | DynamicBinding<any> | ((inherited: Inherited) => MaybePromise<z.ZodType | any>);
|
|
119
|
+
/** The fields passed to {@link asyncEnv} / {@link AsyncEnv.add}. */
|
|
120
|
+
type AsyncEnvInput<Inherited> = Record<string, AsyncEnvFieldDef<Inherited>>;
|
|
121
|
+
/** The resolved output type of an {@link AsyncEnvInput}. */
|
|
122
|
+
type AsyncEnvOutput<Inherited, Input extends AsyncEnvInput<Inherited>> = { [K in keyof Input]: Input[K] extends DynamicBinding<infer V> ? V : Input[K] extends z.ZodType ? z.output<Input[K]> : Input[K] extends ((inherited: Inherited) => infer R) ? Awaited<R> extends z.ZodType ? z.output<Awaited<R>> : Awaited<R> : never };
|
|
123
|
+
/** A typed, lazy, reactive **async** config object built by {@link asyncEnv}. */
|
|
124
|
+
interface AsyncEnv<T extends object> {
|
|
125
|
+
/** Add more fields; their factories receive the fields resolved so far. Returns a wider {@link AsyncEnv}. */
|
|
126
|
+
add<A extends AsyncEnvInput<T>>(input: A): AsyncEnv<T & AsyncEnvOutput<T, A>>;
|
|
127
|
+
/** Resolve a single field (lazily, async). Rejects with an {@link EnvError} if missing/invalid. */
|
|
128
|
+
get<K extends keyof T>(key: K): Promise<T[K]>;
|
|
129
|
+
/** Override a single field/source key (typed value or raw string). */
|
|
130
|
+
set<K extends keyof T>(key: K, value: T[K] | string): void;
|
|
131
|
+
/** Override several fields/source keys at once. */
|
|
132
|
+
set(updates: EnvSet<T>): void;
|
|
133
|
+
/** Resolve every field. Rejects with an aggregated {@link EnvError} listing all failures. */
|
|
134
|
+
parse(): Promise<T>;
|
|
135
|
+
/** Subscribe to *all* field changes; the listener gets `(key, value)`. Returns an unsubscribe fn. */
|
|
136
|
+
on(listener: (key: keyof T, value: T[keyof T]) => void, options?: EnvOnOptions): () => void;
|
|
137
|
+
/** Subscribe to one field's changes. */
|
|
138
|
+
on<K extends keyof T>(key: K, listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
139
|
+
/** Subscribe to several fields' changes with one listener. */
|
|
140
|
+
on<K extends keyof T>(keys: readonly K[], listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
141
|
+
/** Re-pull dynamic providers (all, or one field) and notify on any change. */
|
|
142
|
+
refresh(key?: keyof T): Promise<void>;
|
|
143
|
+
/** Stop all provider watchers. */
|
|
144
|
+
close(): void;
|
|
145
|
+
/** Run `fn` with this env (for grouped setup); returns nothing. */
|
|
146
|
+
with(fn: (env: AsyncEnv<T>) => void): void;
|
|
147
|
+
/** Run `fn` with this env and return its result. */
|
|
148
|
+
map<R>(fn: (env: AsyncEnv<T>) => R): R;
|
|
149
|
+
}
|
|
150
|
+
/** Build a typed, lazy, reactive **async** config — supports async factories and live providers. */
|
|
151
|
+
declare function asyncEnv<const T extends AsyncEnvInput<{}>>(input: T, options?: EnvOptions): AsyncEnv<AsyncEnvOutput<{}, T>>;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/meta.d.ts
|
|
154
|
+
/** The aliasing metadata a field may carry. */
|
|
155
|
+
interface EnvMeta {
|
|
156
|
+
/** A single source key to read this field from. */
|
|
157
|
+
readonly var?: string;
|
|
158
|
+
/** Several source keys to read this field from — first present wins. */
|
|
159
|
+
readonly vars?: readonly string[];
|
|
160
|
+
}
|
|
161
|
+
/** The source keys a field reads, in precedence order — its `vars`/`var` meta, else `[key]`. */
|
|
162
|
+
declare function varsOf(schema: z.ZodType, key: string): readonly string[];
|
|
163
|
+
/** Attach aliasing metadata: read `schema` from the first present of `keys`. */
|
|
164
|
+
declare function alias<S extends z.ZodType>(schema: S, ...keys: string[]): S;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { type AsyncEnv, type AsyncEnvFieldDef, type AsyncEnvInput, type AsyncEnvOutput, type BooleanWords, DEFAULT_FALSE, DEFAULT_TRUE, type DynamicBinding, type Env, EnvError, type EnvFieldDef, type EnvInput, type EnvMeta, type EnvOnOptions, type EnvOptions, type EnvOutput, type EnvProvider, type EnvSet, type EnvSource, type MaybePromise, alias, asyncEnv, coerce, defaultSource, dynamic, effectiveType, env, isDynamic, mergeSources, parseDotenv, pollProvider, resolveRaw, staticProvider, varsOf };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { a as mergeSources, i as defaultSource, n as EnvError, o as resolveRaw, r as EnvSource, t as parseDotenv } from "./dotenv.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/coerce.d.ts
|
|
5
|
+
|
|
6
|
+
/** The effective (unwrapped) zod type name of a field — e.g. `optional(number)` → `'number'`. */
|
|
7
|
+
declare function effectiveType(schema: z.ZodType): string;
|
|
8
|
+
/** The default strings parsed as `true` / `false` (matched case-insensitively, trimmed). */
|
|
9
|
+
declare const DEFAULT_TRUE: ReadonlySet<string>;
|
|
10
|
+
declare const DEFAULT_FALSE: ReadonlySet<string>;
|
|
11
|
+
/** Override the strings recognized as booleans. Each side omitted falls back to its default set. */
|
|
12
|
+
interface BooleanWords {
|
|
13
|
+
/** Strings that mean `true` (replaces {@link DEFAULT_TRUE} when given). */
|
|
14
|
+
readonly true?: ReadonlySet<string>;
|
|
15
|
+
/** Strings that mean `false` (replaces {@link DEFAULT_FALSE} when given). */
|
|
16
|
+
readonly false?: ReadonlySet<string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Coerce `value` toward what `schema` expects. Non-string values pass through; strings are
|
|
20
|
+
* converted per the field's effective type — so a plain `z.number()` / `z.boolean()` / `z.date()`
|
|
21
|
+
* / `z.object()` works straight from env strings, **no `z.coerce` needed**. Returns the original
|
|
22
|
+
* string when a conversion is ambiguous or fails, so zod produces the final, authoritative error.
|
|
23
|
+
* Pass `words` to customize which strings count as boolean `true`/`false`.
|
|
24
|
+
*/
|
|
25
|
+
declare function coerce(schema: z.ZodType, value: unknown, words?: BooleanWords): unknown;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/env.d.ts
|
|
28
|
+
|
|
29
|
+
/** A field definition: a zod schema, or a factory taking the inherited (earlier-group) values. */
|
|
30
|
+
type EnvFieldDef<Inherited> = z.ZodType | ((inherited: Inherited) => z.ZodType | any);
|
|
31
|
+
/** The fields passed to {@link env} / {@link Env.add}. `Inherited` is the type resolved so far. */
|
|
32
|
+
type EnvInput<Inherited> = Record<string, EnvFieldDef<Inherited>>;
|
|
33
|
+
/** The resolved output type of an {@link EnvInput} (zod outputs, computed schema outputs, or plain values). */
|
|
34
|
+
type EnvOutput<Inherited, Input extends EnvInput<Inherited>> = { [K in keyof Input]: Input[K] extends z.ZodType ? z.output<Input[K]> : Input[K] extends ((inherited: Inherited) => infer R) ? R extends z.ZodType ? z.output<R> : R : never };
|
|
35
|
+
/** Values accepted by {@link Env.set}: known fields (typed or raw string) plus any extra source keys. */
|
|
36
|
+
type EnvSet<T extends object> = { [K in keyof T]?: T[K] | string } & {
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
/** Build-time options for {@link env} / {@link asyncEnv}. */
|
|
40
|
+
interface EnvOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Customize which strings coerce to booleans (case-insensitive). Each side you provide
|
|
43
|
+
* **replaces** its default set; an omitted side keeps the default. E.g.
|
|
44
|
+
* `{ booleans: { true: ['enabled'], false: ['disabled'] } }`.
|
|
45
|
+
*/
|
|
46
|
+
readonly booleans?: {
|
|
47
|
+
readonly true?: readonly string[];
|
|
48
|
+
readonly false?: readonly string[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Normalize {@link EnvOptions} into the lowercased {@link BooleanWords} the coercer consumes. */
|
|
52
|
+
|
|
53
|
+
/** Options for {@link Env.on}. */
|
|
54
|
+
interface EnvOnOptions {
|
|
55
|
+
/** Fire at most once, then auto-unsubscribe. */
|
|
56
|
+
once?: boolean;
|
|
57
|
+
/** Compare values structurally (deep-equal) for change detection, instead of by identity. */
|
|
58
|
+
deep?: boolean;
|
|
59
|
+
/** Fire immediately on subscribe with the current value(s). */
|
|
60
|
+
immediate?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** A typed, lazy, reactive config object built by {@link env}. */
|
|
63
|
+
interface Env<T extends object> {
|
|
64
|
+
/** Add more fields; their factories receive the fields resolved so far. Returns a wider {@link Env}. */
|
|
65
|
+
add<A extends EnvInput<T>>(input: A): Env<T & EnvOutput<T, A>>;
|
|
66
|
+
/** Resolve a single field (lazily). Throws an {@link EnvError} if that field is missing/invalid. */
|
|
67
|
+
get<K extends keyof T>(key: K): T[K];
|
|
68
|
+
/** Override a single field/source key (typed value or raw string). */
|
|
69
|
+
set<K extends keyof T>(key: K, value: T[K] | string): void;
|
|
70
|
+
/** Override several fields/source keys at once (e.g. pass `process.env` or a loaded `.env`). */
|
|
71
|
+
set(updates: EnvSet<T>): void;
|
|
72
|
+
/** Resolve every field. Throws an aggregated {@link EnvError} listing all missing/invalid fields. */
|
|
73
|
+
parse(): T;
|
|
74
|
+
/** Subscribe to *all* field changes; the listener gets `(key, value)`. Returns an unsubscribe fn. */
|
|
75
|
+
on(listener: (key: keyof T, value: T[keyof T]) => void, options?: EnvOnOptions): () => void;
|
|
76
|
+
/** Subscribe to one field's changes. */
|
|
77
|
+
on<K extends keyof T>(key: K, listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
78
|
+
/** Subscribe to several fields' changes with one listener. */
|
|
79
|
+
on<K extends keyof T>(keys: readonly K[], listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
80
|
+
/** Run `fn` with this env (for grouped setup); returns nothing. */
|
|
81
|
+
with(fn: (env: Env<T>) => void): void;
|
|
82
|
+
/** Run `fn` with this env and return its result. */
|
|
83
|
+
map<R>(fn: (env: Env<T>) => R): R;
|
|
84
|
+
}
|
|
85
|
+
/** Build a typed, lazy, reactive config from a record of fields. Reads `process.env` by default. */
|
|
86
|
+
declare function env<const T extends EnvInput<{}>>(input: T, options?: EnvOptions): Env<EnvOutput<{}, T>>;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/provider.d.ts
|
|
89
|
+
/** A value, or a promise of one. */
|
|
90
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
91
|
+
/**
|
|
92
|
+
* An external source of a single field's **raw** value. `load` provides the initial value; the
|
|
93
|
+
* optional `watch` pushes live updates and returns an unsubscribe function.
|
|
94
|
+
*/
|
|
95
|
+
interface EnvProvider {
|
|
96
|
+
/** Fetch the current raw value (e.g. query a DB / call a service). `undefined` means "absent". */
|
|
97
|
+
load(): MaybePromise<string | undefined>;
|
|
98
|
+
/** Subscribe to live updates; call `emit` with each new raw value. Return an unsubscribe fn. */
|
|
99
|
+
watch?(emit: (raw: string | undefined) => void): () => void;
|
|
100
|
+
}
|
|
101
|
+
/** A field bound to a live {@link EnvProvider}, validated by `schema`. Created by {@link dynamic}. */
|
|
102
|
+
interface DynamicBinding<V> {
|
|
103
|
+
readonly kind: 'dynamic';
|
|
104
|
+
readonly provider: EnvProvider;
|
|
105
|
+
readonly schema: z.ZodType<V>;
|
|
106
|
+
}
|
|
107
|
+
/** Bind a field to a live {@link EnvProvider}; values are validated against `schema`. */
|
|
108
|
+
declare function dynamic<V>(provider: EnvProvider, schema: z.ZodType<V>): DynamicBinding<V>;
|
|
109
|
+
/** True if `x` is a {@link DynamicBinding}. */
|
|
110
|
+
declare function isDynamic(x: unknown): x is DynamicBinding<unknown>;
|
|
111
|
+
/** A provider that re-fetches on an interval — the simplest way to make any source "dynamic". */
|
|
112
|
+
declare function pollProvider(fetch: () => MaybePromise<string | undefined>, intervalMs: number): EnvProvider;
|
|
113
|
+
/** A fixed-value provider (no updates) — handy for tests and constants behind the provider interface. */
|
|
114
|
+
declare function staticProvider(value: string | undefined): EnvProvider;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/async.d.ts
|
|
117
|
+
/** A field for {@link asyncEnv}: zod schema, dynamic binding, or a (possibly async) factory. */
|
|
118
|
+
type AsyncEnvFieldDef<Inherited> = z.ZodType | DynamicBinding<any> | ((inherited: Inherited) => MaybePromise<z.ZodType | any>);
|
|
119
|
+
/** The fields passed to {@link asyncEnv} / {@link AsyncEnv.add}. */
|
|
120
|
+
type AsyncEnvInput<Inherited> = Record<string, AsyncEnvFieldDef<Inherited>>;
|
|
121
|
+
/** The resolved output type of an {@link AsyncEnvInput}. */
|
|
122
|
+
type AsyncEnvOutput<Inherited, Input extends AsyncEnvInput<Inherited>> = { [K in keyof Input]: Input[K] extends DynamicBinding<infer V> ? V : Input[K] extends z.ZodType ? z.output<Input[K]> : Input[K] extends ((inherited: Inherited) => infer R) ? Awaited<R> extends z.ZodType ? z.output<Awaited<R>> : Awaited<R> : never };
|
|
123
|
+
/** A typed, lazy, reactive **async** config object built by {@link asyncEnv}. */
|
|
124
|
+
interface AsyncEnv<T extends object> {
|
|
125
|
+
/** Add more fields; their factories receive the fields resolved so far. Returns a wider {@link AsyncEnv}. */
|
|
126
|
+
add<A extends AsyncEnvInput<T>>(input: A): AsyncEnv<T & AsyncEnvOutput<T, A>>;
|
|
127
|
+
/** Resolve a single field (lazily, async). Rejects with an {@link EnvError} if missing/invalid. */
|
|
128
|
+
get<K extends keyof T>(key: K): Promise<T[K]>;
|
|
129
|
+
/** Override a single field/source key (typed value or raw string). */
|
|
130
|
+
set<K extends keyof T>(key: K, value: T[K] | string): void;
|
|
131
|
+
/** Override several fields/source keys at once. */
|
|
132
|
+
set(updates: EnvSet<T>): void;
|
|
133
|
+
/** Resolve every field. Rejects with an aggregated {@link EnvError} listing all failures. */
|
|
134
|
+
parse(): Promise<T>;
|
|
135
|
+
/** Subscribe to *all* field changes; the listener gets `(key, value)`. Returns an unsubscribe fn. */
|
|
136
|
+
on(listener: (key: keyof T, value: T[keyof T]) => void, options?: EnvOnOptions): () => void;
|
|
137
|
+
/** Subscribe to one field's changes. */
|
|
138
|
+
on<K extends keyof T>(key: K, listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
139
|
+
/** Subscribe to several fields' changes with one listener. */
|
|
140
|
+
on<K extends keyof T>(keys: readonly K[], listener: (value: T[K]) => void, options?: EnvOnOptions): () => void;
|
|
141
|
+
/** Re-pull dynamic providers (all, or one field) and notify on any change. */
|
|
142
|
+
refresh(key?: keyof T): Promise<void>;
|
|
143
|
+
/** Stop all provider watchers. */
|
|
144
|
+
close(): void;
|
|
145
|
+
/** Run `fn` with this env (for grouped setup); returns nothing. */
|
|
146
|
+
with(fn: (env: AsyncEnv<T>) => void): void;
|
|
147
|
+
/** Run `fn` with this env and return its result. */
|
|
148
|
+
map<R>(fn: (env: AsyncEnv<T>) => R): R;
|
|
149
|
+
}
|
|
150
|
+
/** Build a typed, lazy, reactive **async** config — supports async factories and live providers. */
|
|
151
|
+
declare function asyncEnv<const T extends AsyncEnvInput<{}>>(input: T, options?: EnvOptions): AsyncEnv<AsyncEnvOutput<{}, T>>;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/meta.d.ts
|
|
154
|
+
/** The aliasing metadata a field may carry. */
|
|
155
|
+
interface EnvMeta {
|
|
156
|
+
/** A single source key to read this field from. */
|
|
157
|
+
readonly var?: string;
|
|
158
|
+
/** Several source keys to read this field from — first present wins. */
|
|
159
|
+
readonly vars?: readonly string[];
|
|
160
|
+
}
|
|
161
|
+
/** The source keys a field reads, in precedence order — its `vars`/`var` meta, else `[key]`. */
|
|
162
|
+
declare function varsOf(schema: z.ZodType, key: string): readonly string[];
|
|
163
|
+
/** Attach aliasing metadata: read `schema` from the first present of `keys`. */
|
|
164
|
+
declare function alias<S extends z.ZodType>(schema: S, ...keys: string[]): S;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { type AsyncEnv, type AsyncEnvFieldDef, type AsyncEnvInput, type AsyncEnvOutput, type BooleanWords, DEFAULT_FALSE, DEFAULT_TRUE, type DynamicBinding, type Env, EnvError, type EnvFieldDef, type EnvInput, type EnvMeta, type EnvOnOptions, type EnvOptions, type EnvOutput, type EnvProvider, type EnvSet, type EnvSource, type MaybePromise, alias, asyncEnv, coerce, defaultSource, dynamic, effectiveType, env, isDynamic, mergeSources, parseDotenv, pollProvider, resolveRaw, staticProvider, varsOf };
|