envapt 5.0.3 → 5.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/Debug.cjs +2 -0
  3. package/dist/Debug.cjs.map +1 -0
  4. package/dist/Debug.d.cts +13 -0
  5. package/dist/Debug.d.cts.map +1 -0
  6. package/dist/Debug.d.mts +13 -0
  7. package/dist/Debug.d.mts.map +1 -0
  8. package/dist/Debug.mjs +2 -0
  9. package/dist/Debug.mjs.map +1 -0
  10. package/dist/Dotenv.cjs +3 -0
  11. package/dist/Dotenv.cjs.map +1 -0
  12. package/dist/Dotenv.d.cts +17 -0
  13. package/dist/Dotenv.d.cts.map +1 -0
  14. package/dist/Dotenv.d.mts +17 -0
  15. package/dist/Dotenv.d.mts.map +1 -0
  16. package/dist/Dotenv.mjs +3 -0
  17. package/dist/Dotenv.mjs.map +1 -0
  18. package/dist/Envapter.cjs +2 -0
  19. package/dist/Envapter.cjs.map +1 -0
  20. package/dist/Envapter.d.cts +70 -0
  21. package/dist/Envapter.d.cts.map +1 -0
  22. package/dist/Envapter.d.mts +70 -0
  23. package/dist/Envapter.d.mts.map +1 -0
  24. package/dist/Envapter.mjs +2 -0
  25. package/dist/Envapter.mjs.map +1 -0
  26. package/dist/Error.cjs +2 -0
  27. package/dist/Error.cjs.map +1 -0
  28. package/dist/Error.d.cts +68 -0
  29. package/dist/Error.d.cts.map +1 -0
  30. package/dist/Error.d.mts +68 -0
  31. package/dist/Error.d.mts.map +1 -0
  32. package/dist/Error.mjs +2 -0
  33. package/dist/Error.mjs.map +1 -0
  34. package/dist/StandardSchema.d.cts +59 -0
  35. package/dist/StandardSchema.d.cts.map +1 -0
  36. package/dist/StandardSchema.d.mts +59 -0
  37. package/dist/StandardSchema.d.mts.map +1 -0
  38. package/dist/TemplateResolver.cjs +2 -0
  39. package/dist/TemplateResolver.cjs.map +1 -0
  40. package/dist/TemplateResolver.d.cts +17 -0
  41. package/dist/TemplateResolver.d.cts.map +1 -0
  42. package/dist/TemplateResolver.d.mts +17 -0
  43. package/dist/TemplateResolver.d.mts.map +1 -0
  44. package/dist/TemplateResolver.mjs +2 -0
  45. package/dist/TemplateResolver.mjs.map +1 -0
  46. package/dist/Validators.cjs +2 -0
  47. package/dist/Validators.cjs.map +1 -0
  48. package/dist/Validators.mjs +2 -0
  49. package/dist/Validators.mjs.map +1 -0
  50. package/dist/_virtual/_rolldown/runtime.cjs +1 -0
  51. package/dist/config.cjs +1 -1
  52. package/dist/config.cjs.map +1 -1
  53. package/dist/config.mjs +1 -1
  54. package/dist/config.mjs.map +1 -1
  55. package/dist/converters/BuiltInConverters.cjs +2 -0
  56. package/dist/converters/BuiltInConverters.cjs.map +1 -0
  57. package/dist/converters/BuiltInConverters.mjs +2 -0
  58. package/dist/converters/BuiltInConverters.mjs.map +1 -0
  59. package/dist/converters/Converters.cjs +2 -0
  60. package/dist/converters/Converters.cjs.map +1 -0
  61. package/dist/converters/Converters.d.cts +93 -0
  62. package/dist/converters/Converters.d.cts.map +1 -0
  63. package/dist/converters/Converters.d.mts +93 -0
  64. package/dist/converters/Converters.d.mts.map +1 -0
  65. package/dist/converters/Converters.mjs +2 -0
  66. package/dist/converters/Converters.mjs.map +1 -0
  67. package/dist/converters/ListOfBuiltInConverters.cjs +2 -0
  68. package/dist/converters/ListOfBuiltInConverters.cjs.map +1 -0
  69. package/dist/converters/ListOfBuiltInConverters.mjs +2 -0
  70. package/dist/converters/ListOfBuiltInConverters.mjs.map +1 -0
  71. package/dist/converters/ValueConverter.cjs +2 -0
  72. package/dist/converters/ValueConverter.cjs.map +1 -0
  73. package/dist/converters/ValueConverter.d.cts +25 -0
  74. package/dist/converters/ValueConverter.d.cts.map +1 -0
  75. package/dist/converters/ValueConverter.d.mts +25 -0
  76. package/dist/converters/ValueConverter.d.mts.map +1 -0
  77. package/dist/converters/ValueConverter.mjs +2 -0
  78. package/dist/converters/ValueConverter.mjs.map +1 -0
  79. package/dist/core/AdvancedMethods.cjs +2 -0
  80. package/dist/core/AdvancedMethods.cjs.map +1 -0
  81. package/dist/core/AdvancedMethods.d.cts +76 -0
  82. package/dist/core/AdvancedMethods.d.cts.map +1 -0
  83. package/dist/core/AdvancedMethods.d.mts +76 -0
  84. package/dist/core/AdvancedMethods.d.mts.map +1 -0
  85. package/dist/core/AdvancedMethods.mjs +2 -0
  86. package/dist/core/AdvancedMethods.mjs.map +1 -0
  87. package/dist/core/EnvapterBase.cjs +2 -0
  88. package/dist/core/EnvapterBase.cjs.map +1 -0
  89. package/dist/core/EnvapterBase.d.cts +105 -0
  90. package/dist/core/EnvapterBase.d.cts.map +1 -0
  91. package/dist/core/EnvapterBase.d.mts +105 -0
  92. package/dist/core/EnvapterBase.d.mts.map +1 -0
  93. package/dist/core/EnvapterBase.mjs +2 -0
  94. package/dist/core/EnvapterBase.mjs.map +1 -0
  95. package/dist/core/EnvironmentMethods.cjs +2 -0
  96. package/dist/core/EnvironmentMethods.cjs.map +1 -0
  97. package/dist/core/EnvironmentMethods.d.cts +132 -0
  98. package/dist/core/EnvironmentMethods.d.cts.map +1 -0
  99. package/dist/core/EnvironmentMethods.d.mts +132 -0
  100. package/dist/core/EnvironmentMethods.d.mts.map +1 -0
  101. package/dist/core/EnvironmentMethods.mjs +2 -0
  102. package/dist/core/EnvironmentMethods.mjs.map +1 -0
  103. package/dist/core/PrimitiveMethods.cjs +2 -0
  104. package/dist/core/PrimitiveMethods.cjs.map +1 -0
  105. package/dist/core/PrimitiveMethods.d.cts +70 -0
  106. package/dist/core/PrimitiveMethods.d.cts.map +1 -0
  107. package/dist/core/PrimitiveMethods.d.mts +70 -0
  108. package/dist/core/PrimitiveMethods.d.mts.map +1 -0
  109. package/dist/core/PrimitiveMethods.mjs +2 -0
  110. package/dist/core/PrimitiveMethods.mjs.map +1 -0
  111. package/dist/decorators/Envapt.cjs +2 -0
  112. package/dist/decorators/Envapt.cjs.map +1 -0
  113. package/dist/decorators/Envapt.d.cts +233 -0
  114. package/dist/decorators/Envapt.d.cts.map +1 -0
  115. package/dist/decorators/Envapt.d.mts +233 -0
  116. package/dist/decorators/Envapt.d.mts.map +1 -0
  117. package/dist/decorators/Envapt.mjs +2 -0
  118. package/dist/decorators/Envapt.mjs.map +1 -0
  119. package/dist/decorators/SugarDecorators.cjs +2 -0
  120. package/dist/decorators/SugarDecorators.cjs.map +1 -0
  121. package/dist/decorators/SugarDecorators.d.cts +34 -0
  122. package/dist/decorators/SugarDecorators.d.cts.map +1 -0
  123. package/dist/decorators/SugarDecorators.d.mts +34 -0
  124. package/dist/decorators/SugarDecorators.d.mts.map +1 -0
  125. package/dist/decorators/SugarDecorators.mjs +2 -0
  126. package/dist/decorators/SugarDecorators.mjs.map +1 -0
  127. package/dist/decorators/createPropertyDecorator.cjs +2 -0
  128. package/dist/decorators/createPropertyDecorator.cjs.map +1 -0
  129. package/dist/decorators/createPropertyDecorator.mjs +2 -0
  130. package/dist/decorators/createPropertyDecorator.mjs.map +1 -0
  131. package/dist/index.cjs +1 -2
  132. package/dist/index.d.cts +14 -1127
  133. package/dist/index.d.mts +14 -1127
  134. package/dist/index.mjs +1 -2
  135. package/dist/types/Conversion.d.cts +128 -0
  136. package/dist/types/Conversion.d.cts.map +1 -0
  137. package/dist/types/Conversion.d.mts +128 -0
  138. package/dist/types/Conversion.d.mts.map +1 -0
  139. package/dist/types/Env.d.cts +17 -0
  140. package/dist/types/Env.d.cts.map +1 -0
  141. package/dist/types/Env.d.mts +17 -0
  142. package/dist/types/Env.d.mts.map +1 -0
  143. package/dist/types/Options.d.cts +39 -0
  144. package/dist/types/Options.d.cts.map +1 -0
  145. package/dist/types/Options.d.mts +39 -0
  146. package/dist/types/Options.d.mts.map +1 -0
  147. package/dist/types/Schema.d.cts +12 -0
  148. package/dist/types/Schema.d.cts.map +1 -0
  149. package/dist/types/Schema.d.mts +12 -0
  150. package/dist/types/Schema.d.mts.map +1 -0
  151. package/package.json +1 -1
  152. package/dist/Envapter-CBSM3v-5.cjs +0 -3
  153. package/dist/Envapter-CBSM3v-5.cjs.map +0 -1
  154. package/dist/Envapter-D8FEdzBR.mjs +0 -3
  155. package/dist/Envapter-D8FEdzBR.mjs.map +0 -1
  156. package/dist/index.cjs.map +0 -1
  157. package/dist/index.d.cts.map +0 -1
  158. package/dist/index.d.mts.map +0 -1
  159. package/dist/index.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,1127 +1,14 @@
1
- //#region src/converters/Converters.d.ts
2
- declare const SCALAR: {
3
- readonly String: "string";
4
- readonly Number: "number";
5
- readonly Boolean: "boolean";
6
- readonly Bigint: "bigint";
7
- readonly Symbol: "symbol";
8
- readonly Integer: "integer";
9
- readonly Float: "float";
10
- readonly Json: "json";
11
- readonly Url: "url";
12
- readonly Regexp: "regexp";
13
- readonly Date: "date";
14
- readonly Time: "time";
15
- };
16
- /**
17
- * String tokens for every built-in scalar converter.
18
- * @public
19
- */
20
- type ConverterToken = (typeof SCALAR)[keyof typeof SCALAR];
21
- /**
22
- * Custom element converter for use inside {@link Converters.array}. Receives the trimmed,
23
- * non-empty raw string for one array slot and returns the parsed value.
24
- * @public
25
- */
26
- type CustomElementConverter<TReturn = unknown> = (raw: string) => TReturn;
27
- /**
28
- * Valid element converters for {@link Converters.array}: any scalar token except
29
- * `json` and `regexp` (those don't compose as array elements), or a custom function.
30
- * @public
31
- */
32
- type ArrayElement = Exclude<ConverterToken, 'json' | 'regexp'> | CustomElementConverter;
33
- /**
34
- * Phantom-branded token produced by {@link Converters.array}. The `T` type parameter carries
35
- * the element converter through any variable indirection so inference survives. The
36
- * `__envaptKind` discriminant is present at runtime for dispatch.
37
- * @public
38
- */
39
- interface ArrayOf<TElement extends ArrayElement = ArrayElement> {
40
- readonly __envaptKind: 'array';
41
- readonly of: TElement;
42
- readonly delimiter: string;
43
- }
44
- /**
45
- * Runtime type guard for tokens produced by {@link Converters.array}.
46
- * @internal
47
- */
48
- declare function isArrayOf(value: unknown): value is ArrayOf;
49
- type ArrayScalarElement = Exclude<ConverterToken, 'json' | 'regexp'>;
50
- declare function buildArrayConverter<TReturn>(opts: {
51
- of: CustomElementConverter<TReturn>;
52
- delimiter?: string;
53
- }): ArrayOf<CustomElementConverter<TReturn>>;
54
- declare function buildArrayConverter<TToken extends ArrayScalarElement>(opts: {
55
- of: TToken;
56
- delimiter?: string;
57
- }): ArrayOf<TToken>;
58
- declare function buildArrayConverter(opts?: {
59
- delimiter?: string;
60
- }): ArrayOf<'string'>;
61
- /**
62
- * Built-in converters for environment variables. Use the scalar tokens (e.g. `Converters.Number`)
63
- * for primitive types and the {@link Converters.array} builder for delimited lists.
64
- *
65
- * @example
66
- * ```ts
67
- * \@Envapt('PORT', { converter: Converters.Number, fallback: 3000 })
68
- * static readonly port: number;
69
- *
70
- * \@Envapt('TAGS', { converter: Converters.array({ of: Converters.String, delimiter: ' ' }) })
71
- * static readonly tags: string[];
72
- * ```
73
- *
74
- * @public
75
- */
76
- declare const Converters: {
77
- readonly array: typeof buildArrayConverter;
78
- readonly String: "string";
79
- readonly Number: "number";
80
- readonly Boolean: "boolean";
81
- readonly Bigint: "bigint";
82
- readonly Symbol: "symbol";
83
- readonly Integer: "integer";
84
- readonly Float: "float";
85
- readonly Json: "json";
86
- readonly Url: "url";
87
- readonly Regexp: "regexp";
88
- readonly Date: "date";
89
- readonly Time: "time";
90
- };
91
- //#endregion
92
- //#region src/types/Conversion.d.ts
93
- /**
94
- * Scalar built-in converter tokens (e.g. `'number'`, `'time'`).
95
- * Excludes the array builder (see {@link ArrayOf}).
96
- * @public
97
- */
98
- type BuiltInConverter = ConverterToken;
99
- /**
100
- * Primitive types supported by Envapter
101
- * @public
102
- */
103
- type PrimitiveConstructor = typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol;
104
- /**
105
- * String value from a .env file or environment variable
106
- * @public
107
- */
108
- type BaseInput = string | undefined;
109
- /**
110
- * Custom parser function type for environment variables
111
- * @param raw - Raw string value from environment
112
- * @param fallback - Fallback value if parsing fails
113
- * @returns Parsed value of type T
114
- * @public
115
- */
116
- type ConverterFunction<TFallback = unknown> = (raw: BaseInput, fallback?: TFallback) => TFallback;
117
- /**
118
- * Environment variable converter: a primitive constructor, a built-in scalar token, an `ArrayOf<...>`
119
- * produced by {@link Converters.array}, or a custom parser function.
120
- * @public
121
- */
122
- type EnvaptConverter<TFallback> = PrimitiveConstructor | BuiltInConverter | ArrayOf | ConverterFunction<TFallback>;
123
- type JsonPrimitive = string | number | boolean | null;
124
- type JsonArray = JsonValue[];
125
- interface JsonObject {
126
- [key: string]: JsonValue;
127
- }
128
- /**
129
- * JSON value types for custom converters
130
- * @public
131
- */
132
- type JsonValue = JsonPrimitive | JsonArray | JsonObject;
133
- interface ConverterMap {
134
- string: string;
135
- number: number;
136
- boolean: boolean;
137
- bigint: bigint;
138
- symbol: symbol;
139
- integer: number;
140
- float: number;
141
- json: JsonValue;
142
- url: URL;
143
- regexp: RegExp;
144
- date: Date;
145
- time: number;
146
- }
147
- /**
148
- * Type mapping for built-in scalar converters to their return types
149
- * @internal
150
- */
151
- type BuiltInConverterReturnType<ConverterKey extends BuiltInConverter> = ConverterMap[ConverterKey];
152
- /**
153
- * Return type for built-in converter functions
154
- * @internal
155
- */
156
- type ReturnValuesOfConverterFunctions = ConverterMap[BuiltInConverter];
157
- /**
158
- * Function type for built-in converter functions
159
- * @internal
160
- */
161
- type BuiltInConverterFunction = (...args: Parameters<(...args: any[]) => ReturnValuesOfConverterFunctions>) => ReturnValuesOfConverterFunctions | undefined;
162
- /**
163
- * Map of built-in converter functions
164
- * @internal
165
- */
166
- type MapOfConverterFunctions = Record<BuiltInConverter, BuiltInConverterFunction>;
167
- /**
168
- * Time unit types for duration conversions
169
- * @internal
170
- */
171
- type TimeUnit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w';
172
- /**
173
- * Fallback type for time duration conversions
174
- * @public
175
- */
176
- type TimeFallback = number | `${number}${TimeUnit}`;
177
- /**
178
- * Helper type for getter methods that conditionally return undefined based on whether a fallback is provided
179
- * If fallback is provided, return ReturnType. If no fallback (undefined), return ReturnType | undefined.
180
- * @internal
181
- */
182
- type ConditionalReturn<ReturnType, TFallback> = TFallback extends undefined ? ReturnType | undefined : ReturnType;
183
- /**
184
- * Inferred return type for a converter.
185
- *
186
- * - `ArrayOf<E>` resolves to the element type's return as an array. When `E` is a custom
187
- * function, the function's return type drives the array element. When `E` is a scalar
188
- * token, `ConverterMap` provides the element type.
189
- * - Bare scalar tokens resolve through `ConverterMap`.
190
- * @internal
191
- */
192
- type InferConverterReturnType<TConverter> = TConverter extends ArrayOf<infer Element> ? Element extends BuiltInConverter ? ConverterMap[Element][] : Element extends CustomElementConverter<infer Returned> ? Returned[] : never : TConverter extends BuiltInConverter ? BuiltInConverterReturnType<TConverter> : never;
193
- /**
194
- * Type inference for the *fallback* slot of a converter. `Converters.Time` (scalar or array
195
- * element) accepts {@link TimeFallback} / `TimeFallback[]`; everything else mirrors the
196
- * return type. Add future asymmetric fallback/return converters to this conditional.
197
- * @internal
198
- */
199
- type InferConverterFallbackType<TConverter> = TConverter extends 'time' ? TimeFallback : TConverter extends ArrayOf<infer Element> ? Element extends 'time' ? TimeFallback[] : InferConverterReturnType<TConverter> : InferConverterReturnType<TConverter>;
200
- /**
201
- * Complete type inference for advanced converter methods
202
- * @internal
203
- */
204
- type AdvancedConverterReturn<TConverter, TFallback = undefined> = ConditionalReturn<InferConverterReturnType<TConverter>, TFallback>;
205
- /**
206
- * Type inference for primitive constructor return types
207
- * @internal
208
- */
209
- type InferPrimitiveReturnType<TConstructor extends PrimitiveConstructor> = TConstructor extends typeof String ? string : TConstructor extends typeof Number ? number : TConstructor extends typeof Boolean ? boolean : TConstructor extends typeof BigInt ? bigint : TConstructor extends typeof Symbol ? symbol : never;
210
- /**
211
- * Type inference for primitive fallback values
212
- * @internal
213
- */
214
- type InferPrimitiveFallbackType<TFallback extends string | number | boolean | bigint | symbol | undefined> = TFallback extends string ? string : TFallback extends number ? number : TFallback extends boolean ? boolean : TFallback extends bigint ? bigint : TFallback extends symbol ? symbol : undefined;
215
- //#endregion
216
- //#region src/StandardSchema.d.ts
217
- /**
218
- * Standard Schema V1 interface. Inlined verbatim from the spec at https://standardschema.dev
219
- * so envapt has zero runtime peer dependencies on any specific schema library
220
- * (zod / valibot / arktype / etc).
221
- *
222
- * envapt narrows usage to SYNCHRONOUS schemas only: env loading is boot-time,
223
- * `validate` returning `Promise<Result>` is rejected at the type level (see
224
- * `SchemaMustBeSync` brand in `Types.ts`) and at runtime by the Parser dispatch.
225
- *
226
- * @public
227
- */
228
- interface StandardSchemaV1<Input = unknown, Output = Input> {
229
- readonly '~standard': StandardSchemaV1.Props<Input, Output>;
230
- }
231
- declare namespace StandardSchemaV1 {
232
- interface Props<Input = unknown, Output = Input> {
233
- readonly version: 1;
234
- readonly vendor: string;
235
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
236
- readonly types?: Types<Input, Output> | undefined;
237
- }
238
- type Result<Output> = SuccessResult<Output> | FailureResult;
239
- interface SuccessResult<Output> {
240
- readonly value: Output;
241
- readonly issues?: undefined;
242
- }
243
- interface FailureResult {
244
- readonly issues: readonly Issue[];
245
- }
246
- interface Issue {
247
- readonly message: string;
248
- readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
249
- }
250
- interface PathSegment {
251
- readonly key: PropertyKey;
252
- }
253
- interface Types<Input = unknown, Output = Input> {
254
- readonly input: Input;
255
- readonly output: Output;
256
- }
257
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
258
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
259
- }
260
- /**
261
- * Envapt-side alias for {@link StandardSchemaV1.InferOutput}. Re-exported under a friendlier
262
- * name so consumers writing `declare static readonly x: InferSchemaOutput<typeof mySchema>`
263
- * don't need the namespace path.
264
- * @public
265
- */
266
- type InferSchemaOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>;
267
- /**
268
- * Envapt-side alias for {@link StandardSchemaV1.InferInput}.
269
- * @public
270
- */
271
- type InferSchemaInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>;
272
- //#endregion
273
- //#region src/types/Schema.d.ts
274
- declare const _envaptErrBrand: unique symbol;
275
- type Err<Msg extends string> = Msg & {
276
- readonly [_envaptErrBrand]: never;
277
- };
278
- type SchemaMustBeSync = Err<'Schema must be synchronous. envapt is boot-time config loading; async refinements (validate returning `Promise<Result>`) belong outside the env layer.'>;
279
- type SchemaConstraint<Schema extends StandardSchemaV1> = ReturnType<Schema['~standard']['validate']> extends Promise<unknown> ? SchemaMustBeSync : Schema;
280
- //#endregion
281
- //#region src/Debug.d.ts
282
- /**
283
- * Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.
284
- * `warn` covers signals that might indicate misconfiguration: failed file reads,
285
- * unresolved templates (when not strict), fallback values used in place of missing
286
- * env. `verbose` adds every loaded file, per-file key count, per-key load lines, and
287
- * effective-paths / cache-rebuild notices.
288
- * @public
289
- */
290
- type DebugLevel = 'silent' | 'warn' | 'verbose';
291
- //#endregion
292
- //#region src/Dotenv.d.ts
293
- /**
294
- * Public options for the internal `.env` loader. Mirrors the subset of dotenv's
295
- * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).
296
- * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).
297
- *
298
- * @public
299
- */
300
- interface EnvFileOptions {
301
- /** Encoding for reading .env files. Defaults to 'utf8'. */
302
- encoding?: BufferEncoding;
303
- /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */
304
- override?: boolean;
305
- }
306
- //#endregion
307
- //#region src/core/EnvapterBase.d.ts
308
- /**
309
- * Base class for environment variable management
310
- * Handles configuration, caching, and basic environment loading
311
- * @internal
312
- */
313
- declare abstract class EnvapterBase {
314
- protected static _envPaths: string[];
315
- protected static _envPathsExplicitlySet: boolean;
316
- protected static _baseDir: string | undefined;
317
- protected static _userDefinedEnvFileOptions: EnvFileOptions;
318
- protected static _strict: boolean;
319
- protected static _syncProcessEnv: boolean;
320
- protected static _dotenvAddedKeys: Set<string>;
321
- /**
322
- * Enable or disable strict mode. Default `false`. Setting refreshes the cache so
323
- * previously-cached converted values get re-evaluated under the new rule.
324
- */
325
- static set strict(value: boolean);
326
- static get strict(): boolean;
327
- /**
328
- * Set the debug log level. Defaults to `silent`. When unset, reads `ENVAPT_DEBUG` from
329
- * `process.env` on first access; the setter overrides any env-var value. Output goes
330
- * to stderr prefixed with `[envapt]`.
331
- */
332
- static set debug(level: DebugLevel);
333
- static get debug(): DebugLevel;
334
- /**
335
- * Opt-in mirror of dotenv-loaded keys back to `process.env`. Default `false`.
336
- *
337
- * Only keys the loader actually wrote are mirrored, so collision behavior follows
338
- * `envFileOptions.override`: with the default `false`, pre-existing `process.env` values
339
- * are preserved; with `true`, the file value wins in both the cache and the mirror.
340
- *
341
- * Flipping `false → true` mirrors the existing tracked delta immediately (no cache
342
- * refresh). Flipping `true → false` is one-way: previously mirrored keys remain in
343
- * `process.env` until the process exits.
344
- */
345
- static set syncProcessEnv(value: boolean);
346
- static get syncProcessEnv(): boolean;
347
- protected static treatAsMissing(value: string | undefined): boolean;
348
- /**
349
- * Set custom .env file paths. Accepts either a single path or array of paths.
350
- * Setting new paths clears the cache and reloads environment variables.
351
- *
352
- * When set, this takes absolute precedence. The dotenv-flow auto-cascade and any
353
- * {@link configureProfiles} configuration are ignored.
354
- */
355
- static set envPaths(paths: string[] | string);
356
- /**
357
- * Get currently configured .env file paths
358
- */
359
- static get envPaths(): string[];
360
- /**
361
- * Set a base directory that relative `.env` paths resolve against instead of
362
- * `process.cwd()`: the auto-cascade, {@link configureProfiles} paths, and relative
363
- * `envPaths`. Absolute paths always bypass it. Pass a directory, or a module URL
364
- * (`import.meta.url`, ESM) / `import.meta.dirname` / `__dirname` (CJS) to anchor
365
- * resolution next to the calling file regardless of launch directory.
366
- *
367
- * Set this before `envPaths` so relative `envPaths` validate against the right directory.
368
- * Unset (`undefined`) restores `process.cwd()` resolution.
369
- */
370
- static set baseDir(value: string | URL | undefined);
371
- static get baseDir(): string | undefined;
372
- private static normalizeBaseDir;
373
- protected static resolveAgainstBase(candidate: string): string;
374
- static set envFileOptions(config: EnvFileOptions);
375
- /**
376
- * Get current dotenv configuration options
377
- */
378
- static get envFileOptions(): EnvFileOptions;
379
- protected static refreshCache(): void;
380
- protected static mirrorToProcessEnv(): void;
381
- /**
382
- * Resolve the effective `.env` paths to load. Default implementation just returns the
383
- * explicit `_envPaths` array; subclasses (`EnvironmentMethods`) override to layer in the
384
- * dotenv-flow cascade and any {@link configureProfiles} overrides when `envPaths` was
385
- * never explicitly set.
386
- * @internal
387
- */
388
- protected static resolveEffectivePaths(): string[];
389
- protected static resolveKeyInput(keyInput: EnvKeyInput): {
390
- key: string;
391
- value: string | undefined;
392
- };
393
- protected static get config(): Map<string, unknown>;
394
- /**
395
- * Eagerly load the `.env` cascade now instead of lazily on the first read. Idempotent: a no-op
396
- * once the cache is built. Useful before mirroring to `process.env` (see {@link syncProcessEnv}),
397
- * which is what the `envapt/config` side-effect entry does.
398
- */
399
- static load(): void;
400
- /**
401
- * Read an environment variable as its raw string, skipping parsing and conversion.
402
- */
403
- getRaw(key: EnvKeyInput): string | undefined;
404
- }
405
- //#endregion
406
- //#region src/core/EnvironmentMethods.d.ts
407
- /**
408
- * Environment types supported by Envapter
409
- * @public
410
- */
411
- declare enum Environment {
412
- Development = 0,
413
- Staging = 1,
414
- Production = 2
415
- }
416
- /**
417
- * Mixin for environment detection and checking methods
418
- * @internal
419
- */
420
- declare class EnvironmentMethods extends EnvapterBase {
421
- protected static _environment: Environment | undefined;
422
- protected static _environmentExplicitlySet: boolean;
423
- protected static _profiles: ProfilesConfig | undefined;
424
- protected static determineEnvironment(env?: string | Environment): void;
425
- private static getRawValue;
426
- /**
427
- * Get the current application environment
428
- */
429
- static get environment(): Environment;
430
- /**
431
- * Set the application environment. Accepts either Environment enum or string value.
432
- */
433
- static set environment(env: string | Environment);
434
- /**
435
- * @see {@link EnvironmentMethods.environment}
436
- */
437
- get environment(): Environment;
438
- /**
439
- * @see {@link EnvironmentMethods.environment}
440
- */
441
- set environment(env: string | Environment);
442
- /**
443
- * Check if the current environment is production
444
- */
445
- static get isProduction(): boolean;
446
- /**
447
- * @see {@link EnvironmentMethods.isProduction}
448
- */
449
- get isProduction(): boolean;
450
- /**
451
- * Check if the current environment is staging
452
- */
453
- static get isStaging(): boolean;
454
- /**
455
- * @see {@link EnvironmentMethods.isStaging}
456
- */
457
- get isStaging(): boolean;
458
- /**
459
- * Check if the current environment is development
460
- */
461
- static get isDevelopment(): boolean;
462
- /**
463
- * @see {@link EnvironmentMethods.isDevelopment}
464
- */
465
- get isDevelopment(): boolean;
466
- protected static refreshCache(): void;
467
- /**
468
- * Configure per-environment `.env` path overrides on top of the dotenv-flow auto-cascade.
469
- *
470
- * When set, each `Environment` key's `paths` are loaded at higher precedence than the
471
- * cascade for that environment. Unspecified environments still use the cascade as-is.
472
- * Set `useDefaults: false` to disable the cascade entirely (load only the configured paths).
473
- *
474
- * Setting an explicit `Envapter.envPaths` value at any point overrides this configuration.
475
- *
476
- * @example
477
- * ```ts
478
- * Envapter.configureProfiles({
479
- * [Environment.Staging]: { paths: 'config/staging.env' },
480
- * [Environment.Production]: { paths: ['config/prod.env', 'secrets/prod.env'] }
481
- * });
482
- * ```
483
- */
484
- static configureProfiles(config: ProfilesConfig): void;
485
- /**
486
- * Reset all path-resolution configuration to defaults: clears any prior
487
- * {@link configureProfiles} call AND any explicit `Envapter.envPaths` assignment.
488
- * Returns the resolver to the pure dotenv-flow cascade.
489
- */
490
- static resetProfiles(): void;
491
- /**
492
- * Determine the current environment for cascade-file selection by reading `process.env`
493
- * directly. Bypassing `this.config` to avoid a circular dependency (cascade selection
494
- * happens before `.env` files are loaded). The post-load `Envapter.environment` value
495
- * may differ if a loaded `.env` file declares its own `ENVIRONMENT`/`ENV`/`NODE_ENV`.
496
- * @internal
497
- */
498
- protected static getCascadeEnvironment(): Environment;
499
- /**
500
- * Build the dotenv-flow cascade for a given environment, in dotenv first-wins precedence
501
- * order (highest precedence first). Missing files are silently filtered.
502
- *
503
- * Precedence is **most-specific-wins** (matches Vite / Astro / Vocs):
504
- * `.env.${env}.local` \> `.env.${env}` \> `.env.local` \> `.env`
505
- *
506
- * This differs from dotenv-flow / Next.js convention which puts `.env.local` above
507
- * `.env.${env}`. We chose the most-specific-wins order so committed env-specific files
508
- * (`.env.production`) are authoritative for that environment regardless of whether a
509
- * stray `.env.local` is present.
510
- * @internal
511
- */
512
- protected static buildCascadePaths(env: Environment): string[];
513
- private static normalizeProfilePaths;
514
- /**
515
- * Override the base implementation to layer the dotenv-flow cascade + any
516
- * {@link configureProfiles} overrides on top of `_envPaths` when the user has NOT
517
- * explicitly set `envPaths`.
518
- *
519
- * Precedence (passed to dotenv with first-wins semantics):
520
- * 1. profile-configured paths for the current env (if any)
521
- * 2. `.env.${env}.local`
522
- * 3. `.env.${env}`
523
- * 4. `.env.local`
524
- * 5. `.env`
525
- *
526
- * If `useDefaults: false` is set on the profiles config, only (1) is loaded — no cascade.
527
- * If `envPaths` was explicitly set, only `envPaths` is loaded (everything else ignored).
528
- * @internal
529
- */
530
- protected static resolveEffectivePaths(): string[];
531
- }
532
- //#endregion
533
- //#region src/types/Options.d.ts
534
- /**
535
- * Options for the \@Envapt decorator (modern API). `required: true` is mutually exclusive
536
- * with `fallback`; see the per-converter overloads in `Envapt.ts` for the type-level mutex.
537
- * @public
538
- */
539
- interface EnvaptOptions<TFallback = string> {
540
- fallback?: TFallback;
541
- converter?: EnvaptConverter<TFallback>;
542
- required?: boolean;
543
- }
544
- /**
545
- * Per-environment profile entry passed to {@link configureProfiles}.
546
- * @public
547
- */
548
- interface EnvProfile {
549
- /** One or more `.env` paths to load for this environment. Order matters: earlier paths take precedence. */
550
- paths: string | string[];
551
- }
552
- /**
553
- * Configuration object for {@link configureProfiles}. Maps each `Environment` to an optional
554
- * profile override. Unspecified environments fall through to the default cascade behavior
555
- * (`.env.${env}.local`, `.env.local`, `.env.${env}`, `.env`).
556
- * @public
557
- */
558
- type ProfilesConfig = Partial<Record<Environment, EnvProfile>> & {
559
- /**
560
- * When `false`, disables the default dotenv-flow cascade entirely. Only the explicitly
561
- * configured paths are loaded. Defaults to `true` (cascade still runs, configured paths
562
- * are layered on top with higher precedence).
563
- */
564
- useDefaults?: boolean;
565
- };
566
- //#endregion
567
- //#region src/types/Env.d.ts
568
- /**
569
- * Accepted shape for environment variable lookups. Either a single key or an ordered list of keys.
570
- * @public
571
- */
572
- type EnvKeyInput = string | readonly [string, ...string[]];
573
- /**
574
- * @internal
575
- */
576
- interface EnvapterService {
577
- getRaw(key: EnvKeyInput): string | undefined;
578
- get(key: EnvKeyInput, def?: string): string | undefined;
579
- isStrict(): boolean;
580
- }
581
- //#endregion
582
- //#region src/converters/ValueConverter.d.ts
583
- /**
584
- * Convert a resolved environment value to its declared type via built-in, primitive, array,
585
- * custom, or Standard Schema converters.
586
- * @internal
587
- */
588
- declare class ValueConverter {
589
- private readonly envService;
590
- constructor(envService: EnvapterService);
591
- convertValue<TFallback>(key: EnvKeyInput, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
592
- private processFallbackForConverter;
593
- private convertPrimitiveToString;
594
- private processBuiltInConverter;
595
- private processArrayConverter;
596
- private processCustomConverter;
597
- private resolveConverter;
598
- convertWithSchema(key: EnvKeyInput, schema: StandardSchemaV1, fallback: unknown, hasFallback: boolean): unknown;
599
- }
600
- //#endregion
601
- //#region src/decorators/Envapt.d.ts
602
- /**
603
- * Usage 1: Either a custom converter function + fallback (both required), OR a fallback
604
- * only (no converter).
605
- *
606
- * @param key - Environment variable name(s) to load
607
- * @param options - Configuration options
608
- * @public
609
- * @example
610
- * ```ts
611
- * class Config extends Envapter {
612
- * // Custom converter that validates a non-empty API key
613
- * \@Envapt('API_KEY', {
614
- * fallback: 'default-key',
615
- * converter(raw, _fallback) {
616
- * if (!raw || raw.trim() === '') throw new Error('API_KEY required');
617
- * return raw.trim();
618
- * }
619
- * })
620
- * static readonly apiKey: string;
621
- *
622
- * // Fallback-only (no converter): string fallback
623
- * \@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })
624
- * static readonly logFile: string;
625
- *
626
- * // Fallback-only: arbitrary object fallback
627
- * \@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })
628
- * static readonly retryPolicy: unknown;
629
- * }
630
- * ```
631
- */
632
- declare function Envapt<TFallback>(key: EnvKeyInput, options: {
633
- converter: (raw: string | undefined, fallback: TFallback) => TFallback;
634
- fallback: TFallback;
635
- } | {
636
- fallback: TFallback;
637
- converter?: undefined;
638
- }): PropertyDecorator;
639
- /**
640
- * Usage 2: Custom converter function without fallback. Either omit `required` (returns the
641
- * converter's output, possibly `undefined`) or pass `required: true` to throw `MissingEnvValue`
642
- * on missing/empty values.
643
- *
644
- * @param key - Environment variable name(s) to load
645
- * @param options - Configuration options with custom converter only, with optional `required: true`
646
- * @public
647
- * @example
648
- * ```ts
649
- * class Config extends Envapter {
650
- * \@Envapt('FEATURE_FLAGS', { converter(raw) {
651
- * return raw ? raw.split('|').map(s => s.trim()) : [];
652
- * } })
653
- * static readonly featureFlags: string[];
654
- *
655
- * \@Envapt('JWT_SECRET', {
656
- * converter: (raw) => Buffer.from(raw ?? '', 'base64'),
657
- * required: true
658
- * })
659
- * declare static readonly jwtSecret: Buffer;
660
- * }
661
- * ```
662
- */
663
- declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
664
- converter: ConverterFunction<TReturnType>;
665
- required?: false;
666
- } | {
667
- converter: ConverterFunction<TReturnType>;
668
- required: true;
669
- }): PropertyDecorator;
670
- /**
671
- * Usage 3: Built-in or array converter with optional fallback OR `required: true`.
672
- *
673
- * `InferConverterFallbackType` handles asymmetric cases: scalar `Converters.Time` accepts
674
- * `TimeFallback`, and `ArrayOf<'time'>` accepts `TimeFallback[]`. Every other converter
675
- * reduces to `InferConverterReturnType`. The two object-shape branches are mutually
676
- * exclusive: either provide a `fallback`, or pass `required: true` to throw
677
- * `MissingEnvValue` on missing/empty values.
678
- *
679
- * @param key - Environment variable name(s) to load
680
- * @param options - Configuration options
681
- * @public
682
- * @example
683
- * ```ts
684
- * import { Converters } from 'envapt';
685
- *
686
- * class Config extends Envapter {
687
- * // Use built-in Number converter with a numeric fallback
688
- * \@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })
689
- * static readonly port: number;
690
- *
691
- * // Url converter: the fallback is a URL instance, not a string
692
- * \@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })
693
- * static readonly url: URL;
694
- *
695
- * // Prefer CANARY_URL when present, otherwise fall back to APP_URL
696
- * \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
697
- * static readonly canaryUrl: URL | null;
698
- *
699
- * // `Converters.Time` accepts either a number (milliseconds) or a time-string fallback (`<integer><unit>`).
700
- * \@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })
701
- * static readonly requestTimeout: number;
702
- *
703
- * // Array converter: comma-separated list of origins -> string[]
704
- * \@Envapt('ALLOWED_ORIGINS', {
705
- * converter: Converters.array({ of: Converters.String }),
706
- * fallback: ['https://example.com']
707
- * })
708
- * static readonly allowedOrigins: string[];
709
- *
710
- * \@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })
711
- * declare static readonly databaseUrl: URL;
712
- * }
713
- * ```
714
- */
715
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
716
- converter: TConverter;
717
- fallback?: InferConverterFallbackType<TConverter> | undefined;
718
- required?: false;
719
- } | {
720
- converter: TConverter;
721
- required: true;
722
- }): PropertyDecorator;
723
- /**
724
- * Usage 4: Primitive constructor with optional fallback
725
- *
726
- * @param key - Environment variable name(s) to load
727
- * @param options - Configuration options with primitive constructor
728
- * @public
729
- * @example
730
- * ```ts
731
- * // Use primitive constructors to coerce values
732
- * class Config extends Envapter {
733
- * \@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })
734
- * static readonly maxConnections: number;
735
- *
736
- * \@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })
737
- * static readonly featureEnabled: boolean;
738
- * }
739
- * ```
740
- */
741
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
742
- converter: TConstructor;
743
- fallback?: InferPrimitiveReturnType<TConstructor>;
744
- required?: false;
745
- } | {
746
- converter: TConstructor;
747
- required: true;
748
- }): PropertyDecorator;
749
- /**
750
- * Usage 5: Required, no converter (raw string). Throws `MissingEnvValue` on first access if
751
- * the env value is missing or empty (post-trim). Independent of global `Envapter.strict`.
752
- * Combining `required: true` with `fallback` fails to match any overload at compile time;
753
- * the runtime Validator catches dynamic objects that bypass the types.
754
- *
755
- * @param key - Environment variable name(s) to load
756
- * @param options - `{ required: true }`
757
- * @public
758
- * @example
759
- * ```ts
760
- * class Config extends Envapter {
761
- * \@Envapt('API_KEY', { required: true })
762
- * declare static readonly apiKey: string;
763
- * }
764
- * ```
765
- */
766
- declare function Envapt(key: EnvKeyInput, options: {
767
- required: true;
768
- }): PropertyDecorator;
769
- /**
770
- * Classic API: No fallback
771
- *
772
- * @param key - Environment variable name(s) to load
773
- * @public
774
- * @example
775
- * ```ts
776
- * // Classic API: no fallback — property will resolve from env or be null
777
- * class Config extends Envapter {
778
- * \@Envapt('SIMPLE_VALUE')
779
- * static readonly simple?: string | null;
780
- * }
781
- * ```
782
- */
783
- declare function Envapt<_TReturnType = string | null>(key: EnvKeyInput): PropertyDecorator;
784
- /**
785
- * Classic API: Primitive fallback only
786
- *
787
- * @param key - Environment variable name(s) to load
788
- * @param fallback - Default primitive value
789
- * @param converter - Optional primitive constructor (String, Number, etc.)
790
- * @public
791
- * @deprecated - Use the options object: `@Envapt('KEY', { converter, fallback })`. The positional
792
- * form only accepts primitive constructors and cannot express built-in tokens, array/custom
793
- * converters, `schema`, or `required`. Deprecated in v5, removed in v6.
794
- * @example
795
- * ```ts
796
- * // Classic API with primitive fallback and optional primitive converter
797
- * class Config extends Envapter {
798
- * // Provide fallback only
799
- * \@Envapt('HOST', 'localhost')
800
- * static readonly host: string;
801
- *
802
- * // Provide fallback and converter
803
- * \@Envapt('PORT', 8080, Number)
804
- * static readonly port: number;
805
- * }
806
- * ```
807
- */
808
- declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: EnvKeyInput, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
809
- /**
810
- * Usage 6: Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous
811
- * schemas only; a Promise-returning `validate` triggers a runtime
812
- * `InvalidUserDefinedConfig` throw. Combining `schema` with `converter` fails to match any
813
- * overload at compile time; the runtime Validator catches dynamic objects that bypass the
814
- * types.
815
- * @public
816
- */
817
- declare function Envapt<Schema extends StandardSchemaV1>(key: EnvKeyInput, options: {
818
- schema: SchemaConstraint<Schema>;
819
- fallback?: InferSchemaOutput<Schema>;
820
- required?: false;
821
- } | {
822
- schema: SchemaConstraint<Schema>;
823
- required: true;
824
- }): PropertyDecorator;
825
- //#endregion
826
- //#region src/decorators/SugarDecorators.d.ts
827
- /**
828
- * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.
829
- * @public
830
- */
831
- declare function EnvBool(key: EnvKeyInput, fallback?: boolean): PropertyDecorator;
832
- /**
833
- * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.
834
- * @public
835
- */
836
- declare function EnvNum(key: EnvKeyInput, fallback?: number): PropertyDecorator;
837
- /**
838
- * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.
839
- * @public
840
- */
841
- declare function EnvStr(key: EnvKeyInput, fallback?: string): PropertyDecorator;
842
- /**
843
- * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a
844
- * millisecond number or a time string (`'15m'`); the resolved value is always milliseconds.
845
- * @public
846
- */
847
- declare function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): PropertyDecorator;
848
- /**
849
- * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`
850
- * instance, not a URL string.
851
- * @public
852
- */
853
- declare function EnvUrl(key: EnvKeyInput, fallback?: URL): PropertyDecorator;
854
- //#endregion
855
- //#region src/TemplateResolver.d.ts
856
- /**
857
- * Resolve `${VAR}` template references in environment values, guarding against circular
858
- * references and missing variables.
859
- * @internal
860
- */
861
- declare class TemplateResolver {
862
- private readonly envService;
863
- private readonly TEMPLATE_REGEX;
864
- constructor(envService: EnvapterService);
865
- resolveTemplate(key: string, value: string, stack?: Set<string>): string;
866
- }
867
- //#endregion
868
- //#region src/core/PrimitiveMethods.d.ts
869
- /**
870
- * @internal
871
- */
872
- declare class PrimitiveMethods extends EnvironmentMethods implements EnvapterService {
873
- private static readonly service;
874
- protected static readonly templateResolver: TemplateResolver;
875
- protected static readonly valueConverter: ValueConverter;
876
- isStrict(): boolean;
877
- private static _get;
878
- /**
879
- * Get a string environment variable with optional fallback.
880
- * Supports template variable resolution using `${VAR}` syntax.
881
- * Accepts a single key or an ordered array of keys (first match wins).
882
- */
883
- static get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
884
- /**
885
- * @see {@link PrimitiveMethods.get}
886
- */
887
- get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
888
- /**
889
- * Get a number environment variable with optional fallback.
890
- * Automatically converts string values to numbers.
891
- * Accepts a single key or an ordered array of keys (first match wins).
892
- */
893
- static getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
894
- /**
895
- * @see {@link PrimitiveMethods.getNumber}
896
- */
897
- getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
898
- /**
899
- * Get a boolean environment variable with optional fallback.
900
- * Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).
901
- * Accepts a single key or an ordered array of keys (first match wins).
902
- */
903
- static getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
904
- /**
905
- * @see {@link PrimitiveMethods.getBoolean}
906
- */
907
- getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
908
- /**
909
- * Get a bigint environment variable with optional fallback.
910
- * Automatically converts string values to bigint.
911
- * Accepts a single key or an ordered array of keys (first match wins).
912
- */
913
- static getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
914
- /**
915
- * @see {@link PrimitiveMethods.getBigInt}
916
- */
917
- getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
918
- /**
919
- * Get a symbol environment variable with optional fallback.
920
- * Creates a symbol from the string value.
921
- * Accepts a single key or an ordered array of keys (first match wins).
922
- */
923
- static getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
924
- /**
925
- * @see {@link PrimitiveMethods.getSymbol}
926
- */
927
- getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
928
- }
929
- //#endregion
930
- //#region src/core/AdvancedMethods.d.ts
931
- interface GetUsingRequiredOptions<TConverter> {
932
- converter: TConverter;
933
- required: true;
934
- }
935
- interface GetWithRequiredOptions<TReturnType> {
936
- converter: ConverterFunction<TReturnType>;
937
- required: true;
938
- }
939
- /**
940
- * Mixin for advanced methods for environment variable conversion using built-in and custom converters
941
- * @internal
942
- */
943
- declare class AdvancedMethods extends PrimitiveMethods {
944
- /**
945
- * Get an environment variable using a built-in converter.
946
- *
947
- * Supports both scalar tokens (e.g. `Converters.Number`) and `ArrayOf<...>` tokens
948
- * produced by `Converters.array(...)`. The key can be a single name or an ordered list;
949
- * the first defined value wins.
950
- */
951
- static getUsing<TFallback extends TimeFallback | undefined = undefined>(key: EnvKeyInput, converter: 'time', fallback?: TFallback): ConditionalReturn<number, TFallback>;
952
- static getUsing<TConverter extends BuiltInConverter | ArrayOf, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
953
- static getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayOf, fallback?: TReturn): TReturn;
954
- static getUsing(key: EnvKeyInput, options: GetUsingRequiredOptions<'time'>): number;
955
- static getUsing<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: GetUsingRequiredOptions<TConverter>): InferConverterReturnType<TConverter>;
956
- /**
957
- * @see {@link AdvancedMethods.getUsing}
958
- */
959
- getUsing<TFallback extends TimeFallback | undefined = undefined>(key: EnvKeyInput, converter: 'time', fallback?: TFallback): ConditionalReturn<number, TFallback>;
960
- getUsing<TConverter extends BuiltInConverter | ArrayOf, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
961
- getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayOf, fallback?: TReturn): TReturn;
962
- getUsing(key: EnvKeyInput, options: GetUsingRequiredOptions<'time'>): number;
963
- getUsing<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: GetUsingRequiredOptions<TConverter>): InferConverterReturnType<TConverter>;
964
- /**
965
- * Get an environment variable using a custom converter function.
966
- * Accepts a single key or an ordered list for automatic fallback.
967
- */
968
- static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
969
- static getWith<TReturnType>(key: EnvKeyInput, options: GetWithRequiredOptions<TReturnType>): TReturnType;
970
- /**
971
- * @see {@link AdvancedMethods.getWith}
972
- */
973
- getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
974
- getWith<TReturnType>(key: EnvKeyInput, options: GetWithRequiredOptions<TReturnType>): TReturnType;
975
- /**
976
- * Validate an environment variable through a {@link StandardSchemaV1}-conformant schema
977
- * (zod, valibot, arktype, etc). Throws `MissingEnvValue` if the env value is absent and
978
- * no fallback is provided. The fallback, when provided, is returned as-is on missing;
979
- * it does NOT pass through the schema (mirrors custom-converter behavior).
980
- *
981
- * Synchronous schemas only. A Promise-returning `validate` triggers an
982
- * `InvalidUserDefinedConfig` throw at the call site.
983
- *
984
- * @example
985
- * ```ts
986
- * import { z } from 'zod';
987
- * const port = Envapter.parse('PORT', z.coerce.number().min(1024).max(65535), 3000);
988
- * ```
989
- */
990
- static parse<Schema extends StandardSchemaV1>(key: EnvKeyInput, schema: SchemaConstraint<Schema>, fallback?: InferSchemaOutput<Schema>): InferSchemaOutput<Schema>;
991
- /**
992
- * @see {@link AdvancedMethods.parse}
993
- */
994
- parse<Schema extends StandardSchemaV1>(key: EnvKeyInput, schema: SchemaConstraint<Schema>, fallback?: InferSchemaOutput<Schema>): InferSchemaOutput<Schema>;
995
- }
996
- //#endregion
997
- //#region src/Envapter.d.ts
998
- /**
999
- * Main configuration class for environment variable management.
1000
- *
1001
- * Provides both static and instance methods for retrieving typed environment variables
1002
- * with support for template resolution, multiple .env files, and environment detection.
1003
- *
1004
- * Extend your own classes from this to define properties with \@Envapt decorators and get access to environment-variable methods.
1005
- *
1006
- * @example
1007
- * ```ts
1008
- * // Static usage
1009
- * const port = Envapter.getNumber('PORT', 3000);
1010
- * const url = Envapter.get('API_URL', 'http://localhost');
1011
- * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
1012
- *
1013
- * // Instance usage
1014
- * const env = new Envapter();
1015
- * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
1016
- * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
1017
- * ```
1018
- *
1019
- * @public
1020
- */
1021
- declare class Envapter extends AdvancedMethods {
1022
- /**
1023
- * Tagged template literal for resolving environment variables in template strings.
1024
- *
1025
- * @example
1026
- * ```ts
1027
- * // Given API_HOST=api.example.com and API_PORT=8080 in environment
1028
- * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;
1029
- * // Returns: "Connecting to api.example.com:8080"
1030
- *
1031
- * // Works with template variables in .env too:
1032
- * // API_URL=https://${API_HOST}:${API_PORT}
1033
- * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;
1034
- * // Returns: "Service endpoint: https://api.example.com:8080"
1035
- * ```
1036
- */
1037
- static resolve(strings: TemplateStringsArray, ...keys: string[]): string;
1038
- /**
1039
- * @see {@link Envapter.resolve}
1040
- */
1041
- resolve(strings: TemplateStringsArray, ...keys: string[]): string;
1042
- /**
1043
- * Assert that one or more environment variables are present and non-empty (post-trim,
1044
- * after template resolution). Throws `MissingEnvValue` listing every missing key.
1045
- *
1046
- * For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.
1047
- *
1048
- * @example
1049
- * ```ts
1050
- * Envapter.require('DATABASE_URL');
1051
- * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');
1052
- * ```
1053
- */
1054
- static require(...keys: [string, ...string[]]): void;
1055
- private static resolveAndValidate;
1056
- /**
1057
- * @see {@link Envapter.require}
1058
- */
1059
- require(...keys: [string, ...string[]]): void;
1060
- }
1061
- //#endregion
1062
- //#region src/Error.d.ts
1063
- declare enum EnvaptErrorCodes {
1064
- /** Thrown when an invalid fallback value is provided */
1065
- InvalidFallback = 101,
1066
- /** Thrown when fallback value type doesn't match expected converter type */
1067
- InvalidFallbackType = 102,
1068
- /** Thrown when array fallback contains elements of wrong type */
1069
- ArrayFallbackElementTypeMismatch = 103,
1070
- /** Thrown when fallback type doesn't match the specified converter */
1071
- FallbackConverterTypeMismatch = 104,
1072
- /** Thrown when a time-string fallback is malformed (does not match the required `<integer><unit>` format) */
1073
- MalformedTimeFallback = 105,
1074
- /** Thrown when invalid array converter configuration is provided */
1075
- InvalidArrayConverterType = 201,
1076
- /** Thrown when an invalid built-in converter is specified */
1077
- InvalidBuiltInConverter = 202,
1078
- /** Thrown when a custom converter is not a function */
1079
- InvalidCustomConverter = 203,
1080
- /** Thrown when converter type is not recognized */
1081
- InvalidConverterType = 204,
1082
- /** Thrown when primitive type coercion on fallback value fails */
1083
- PrimitiveCoercionFailed = 205,
1084
- /** Thrown when an array element fails to convert to the configured element type */
1085
- ArrayElementConversionFailed = 206,
1086
- /** Thrown under strict mode when an array element is empty or whitespace only */
1087
- EmptyArrayElement = 207,
1088
- /** Thrown when a Standard Schema returns issues for a non-empty env value */
1089
- SchemaValidationFailed = 208,
1090
- /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */
1091
- SchemaThrew = 209,
1092
- /** Thrown when delimiter is missing in array converter configuration */
1093
- MissingDelimiter = 301,
1094
- /** Thrown when invalid user-defined configuration is provided */
1095
- InvalidUserDefinedConfig = 302,
1096
- /** Thrown when specified environment files don't exist */
1097
- EnvFilesNotFound = 303,
1098
- /** Thrown when no valid environment key is provided */
1099
- InvalidKeyInput = 304,
1100
- /** Thrown when a required environment value is missing or empty (post-trim) */
1101
- MissingEnvValue = 305
1102
- }
1103
- interface EnvaptErrorOptions {
1104
- issues?: readonly StandardSchemaV1.Issue[];
1105
- cause?: unknown;
1106
- }
1107
- /**
1108
- * Custom error for better DX and debugging when using Envapt.
1109
- *
1110
- * @example
1111
- * ```ts
1112
- * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, "Invalid fallback value provided for environment variable.");
1113
- * ```
1114
- */
1115
- declare class EnvaptError extends Error {
1116
- readonly code: EnvaptErrorCodes;
1117
- /**
1118
- * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other
1119
- * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`
1120
- * without a type cast.
1121
- */
1122
- readonly issues: readonly StandardSchemaV1.Issue[] | undefined;
1123
- constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions);
1124
- }
1125
- //#endregion
1126
- export { type AdvancedConverterReturn, type ArrayElement, type ArrayOf, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, type ConverterToken, Converters, type CustomElementConverter, type DebugLevel, EnvBool, type EnvFileOptions, type EnvKeyInput, EnvNum, type EnvProfile, EnvStr, EnvTime, EnvUrl, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type Err, type InferConverterFallbackType, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type InferSchemaInput, type InferSchemaOutput, type JsonValue, type MapOfConverterFunctions, type PrimitiveConstructor, type ProfilesConfig, type SchemaConstraint, type SchemaMustBeSync, type StandardSchemaV1, type TimeFallback, type TimeUnit, isArrayOf };
1127
- //# sourceMappingURL=index.d.mts.map
1
+ import { ArrayElement, ArrayOf, ConverterToken, Converters, CustomElementConverter, isArrayOf } from "./converters/Converters.mjs";
2
+ import { AdvancedConverterReturn, BuiltInConverter, BuiltInConverterFunction, ConditionalReturn, ConverterFunction, EnvaptConverter, InferConverterFallbackType, InferConverterReturnType, InferPrimitiveFallbackType, InferPrimitiveReturnType, JsonValue, MapOfConverterFunctions, PrimitiveConstructor, TimeFallback, TimeUnit } from "./types/Conversion.mjs";
3
+ import { InferSchemaInput, InferSchemaOutput, StandardSchemaV1 } from "./StandardSchema.mjs";
4
+ import { Err, SchemaConstraint, SchemaMustBeSync } from "./types/Schema.mjs";
5
+ import { DebugLevel } from "./Debug.mjs";
6
+ import { EnvFileOptions } from "./Dotenv.mjs";
7
+ import { Environment } from "./core/EnvironmentMethods.mjs";
8
+ import { EnvProfile, EnvaptOptions, ProfilesConfig } from "./types/Options.mjs";
9
+ import { EnvKeyInput } from "./types/Env.mjs";
10
+ import { Envapt } from "./decorators/Envapt.mjs";
11
+ import { EnvBool, EnvNum, EnvStr, EnvTime, EnvUrl } from "./decorators/SugarDecorators.mjs";
12
+ import { Envapter } from "./Envapter.mjs";
13
+ import { EnvaptError, EnvaptErrorCodes } from "./Error.mjs";
14
+ export { type AdvancedConverterReturn, type ArrayElement, type ArrayOf, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, type ConverterToken, Converters, type CustomElementConverter, type DebugLevel, EnvBool, type EnvFileOptions, type EnvKeyInput, EnvNum, type EnvProfile, EnvStr, EnvTime, EnvUrl, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type Err, type InferConverterFallbackType, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type InferSchemaInput, type InferSchemaOutput, type JsonValue, type MapOfConverterFunctions, type PrimitiveConstructor, type ProfilesConfig, type SchemaConstraint, type SchemaMustBeSync, type StandardSchemaV1, type TimeFallback, type TimeUnit, isArrayOf };