node-env-resolver 5.0.1 → 6.0.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/dist/index.d.cts CHANGED
@@ -9,7 +9,7 @@ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.
9
9
  * @example
10
10
  * ```typescript
11
11
  * import { resolve } from 'node-env-resolver';
12
- * import { postgres, string } from 'node-env-resolver/resolvers';
12
+ * import { postgres, string } from 'node-env-resolver/validators';
13
13
  *
14
14
  * const config = resolve({
15
15
  * PORT: 3000, // number with default
@@ -55,7 +55,7 @@ declare function resolve<T extends SimpleEnvSchema>(config: {
55
55
  * @example
56
56
  * ```typescript
57
57
  * import { resolveAsync } from 'node-env-resolver';
58
- * import { postgres, string } from 'node-env-resolver/resolvers';
58
+ * import { postgres, string } from 'node-env-resolver/validators';
59
59
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
60
60
  *
61
61
  * // Works with async-only resolvers
@@ -98,6 +98,14 @@ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
98
98
  }): Promise<{
99
99
  [K in keyof T]: InferSimpleValue<T[K]>;
100
100
  }>;
101
+ /**
102
+ * Safe resolve implementation (doesn't throw, returns result object)
103
+ *
104
+ * @param arg1 - Schema object or config object
105
+ * @param arg2 - Optional resolve options
106
+ * @returns Safe resolve result with success/error information
107
+ * @private
108
+ */
101
109
  declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
102
110
  [K in keyof T]: InferSimpleValue<T[K]>;
103
111
  }>;
@@ -108,7 +116,7 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<
108
116
  * @example
109
117
  * ```typescript
110
118
  * import { safeResolveAsync } from 'node-env-resolver';
111
- * import { postgres } from 'node-env-resolver/resolvers';
119
+ * import { postgres } from 'node-env-resolver/validators';
112
120
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
113
121
  *
114
122
  * // Works with async resolvers
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.
9
9
  * @example
10
10
  * ```typescript
11
11
  * import { resolve } from 'node-env-resolver';
12
- * import { postgres, string } from 'node-env-resolver/resolvers';
12
+ * import { postgres, string } from 'node-env-resolver/validators';
13
13
  *
14
14
  * const config = resolve({
15
15
  * PORT: 3000, // number with default
@@ -55,7 +55,7 @@ declare function resolve<T extends SimpleEnvSchema>(config: {
55
55
  * @example
56
56
  * ```typescript
57
57
  * import { resolveAsync } from 'node-env-resolver';
58
- * import { postgres, string } from 'node-env-resolver/resolvers';
58
+ * import { postgres, string } from 'node-env-resolver/validators';
59
59
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
60
60
  *
61
61
  * // Works with async-only resolvers
@@ -98,6 +98,14 @@ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
98
98
  }): Promise<{
99
99
  [K in keyof T]: InferSimpleValue<T[K]>;
100
100
  }>;
101
+ /**
102
+ * Safe resolve implementation (doesn't throw, returns result object)
103
+ *
104
+ * @param arg1 - Schema object or config object
105
+ * @param arg2 - Optional resolve options
106
+ * @returns Safe resolve result with success/error information
107
+ * @private
108
+ */
101
109
  declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
102
110
  [K in keyof T]: InferSimpleValue<T[K]>;
103
111
  }>;
@@ -108,7 +116,7 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<
108
116
  * @example
109
117
  * ```typescript
110
118
  * import { safeResolveAsync } from 'node-env-resolver';
111
- * import { postgres } from 'node-env-resolver/resolvers';
119
+ * import { postgres } from 'node-env-resolver/validators';
112
120
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
113
121
  *
114
122
  * // Works with async resolvers
@@ -1 +1 @@
1
- 'use strict';var chunkXPL5XLTA_cjs=require('./chunk-XPL5XLTA.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"boolean",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.j}});Object.defineProperty(exports,"custom",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.z}});Object.defineProperty(exports,"date",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.A}});Object.defineProperty(exports,"dotenv",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.a}});Object.defineProperty(exports,"duration",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.w}});Object.defineProperty(exports,"email",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.l}});Object.defineProperty(exports,"enums",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.v}});Object.defineProperty(exports,"file",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.x}});Object.defineProperty(exports,"http",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.c}});Object.defineProperty(exports,"https",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.r}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.d}});Object.defineProperty(exports,"mongodb",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.p}});Object.defineProperty(exports,"mysql",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.o}});Object.defineProperty(exports,"number",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.i}});Object.defineProperty(exports,"numberArray",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.t}});Object.defineProperty(exports,"packageJson",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.b}});Object.defineProperty(exports,"port",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.m}});Object.defineProperty(exports,"postgres",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.n}});Object.defineProperty(exports,"redis",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.q}});Object.defineProperty(exports,"secret",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.y}});Object.defineProperty(exports,"secrets",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.e}});Object.defineProperty(exports,"string",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.h}});Object.defineProperty(exports,"stringArray",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.s}});Object.defineProperty(exports,"timestamp",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.B}});Object.defineProperty(exports,"toml",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.g}});Object.defineProperty(exports,"url",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.k}});Object.defineProperty(exports,"urlArray",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.u}});Object.defineProperty(exports,"yaml",{enumerable:true,get:function(){return chunkXPL5XLTA_cjs.f}});Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunk4QOKRJ3F_cjs.a}});
1
+ 'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"dotenv",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.a}});Object.defineProperty(exports,"http",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.c}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.d}});Object.defineProperty(exports,"packageJson",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.b}});Object.defineProperty(exports,"secrets",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.e}});Object.defineProperty(exports,"toml",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.g}});Object.defineProperty(exports,"yaml",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.f}});Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunk4QOKRJ3F_cjs.a}});
@@ -1,8 +1,18 @@
1
- import { SyncResolver, Resolver, Validator } from './types.cjs';
1
+ import { SyncResolver, Resolver } from './types.cjs';
2
2
 
3
3
  /**
4
4
  * Resolver that reads from process.env
5
5
  * This is the default resolver used when no custom resolvers are provided
6
+ *
7
+ * @returns SyncResolver that loads environment variables from process.env
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { processEnv } from 'node-env-resolver';
12
+ *
13
+ * const resolver = processEnv();
14
+ * const env = resolver.loadSync(); // { PORT: '3000', NODE_ENV: 'development', ... }
15
+ * ```
6
16
  */
7
17
  declare function processEnv(): SyncResolver;
8
18
 
@@ -10,10 +20,40 @@ declare function processEnv(): SyncResolver;
10
20
  * Built-in resolvers for environment variable resolution
11
21
  */
12
22
 
23
+ /**
24
+ * Options for the dotenv resolver
25
+ */
13
26
  interface DotenvOptions {
27
+ /** Path to the .env file (default: '.env') */
14
28
  path?: string;
29
+ /** Enable environment-specific file loading (default: false) */
15
30
  expand?: boolean;
16
31
  }
32
+ /**
33
+ * Load configuration from .env files
34
+ * Supports environment-specific files when expand=true
35
+ *
36
+ * @param options Path string or options object
37
+ * @returns Resolver that loads from .env file(s)
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { dotenv } from 'node-env-resolver/resolvers';
42
+ *
43
+ * // Simple .env file
44
+ * const config = await resolveAsync([
45
+ * dotenv('.env'),
46
+ * { PORT: 3000, API_KEY: string() }
47
+ * ]);
48
+ *
49
+ * // Environment-specific files
50
+ * const config = await resolveAsync([
51
+ * dotenv({ path: '.env', expand: true }),
52
+ * { PORT: 3000 }
53
+ * ]);
54
+ * // Loads: .env.defaults, .env, .env.local, .env.development, .env.development.local
55
+ * ```
56
+ */
17
57
  declare function dotenv(options?: string | DotenvOptions): Resolver;
18
58
  /**
19
59
  * Load configuration from package.json
@@ -99,6 +139,7 @@ declare function secrets(path?: string): Resolver;
99
139
  * Requires 'js-yaml' as a peer dependency (install separately for tree-shaking)
100
140
  */
101
141
  interface YamlOptions {
142
+ /** Path to the YAML file (default: 'config.yaml') */
102
143
  path?: string;
103
144
  }
104
145
  /**
@@ -124,6 +165,7 @@ declare function yaml(options?: string | YamlOptions): Resolver;
124
165
  * Requires 'smol-toml' as a peer dependency (install separately for tree-shaking)
125
166
  */
126
167
  interface TomlOptions {
168
+ /** Path to the TOML file (default: 'config.toml') */
127
169
  path?: string;
128
170
  }
129
171
  /**
@@ -144,269 +186,5 @@ interface TomlOptions {
144
186
  * ```
145
187
  */
146
188
  declare function toml(options?: string | TomlOptions): Resolver;
147
- declare function string<Opts extends {
148
- default?: string;
149
- optional?: boolean;
150
- min?: number;
151
- max?: number;
152
- allowEmpty?: boolean;
153
- pattern?: string;
154
- } = Record<string, never>>(opts?: Opts): Opts extends {
155
- optional: true;
156
- } ? Validator<string> & {
157
- optional: true;
158
- default?: Opts['default'];
159
- } : Validator<string> & {
160
- optional?: Opts['optional'];
161
- default?: Opts['default'];
162
- };
163
- declare function number<Opts extends {
164
- default?: number;
165
- optional?: boolean;
166
- min?: number;
167
- max?: number;
168
- } = Record<string, never>>(opts?: Opts): Opts extends {
169
- optional: true;
170
- } ? Validator<number> & {
171
- optional: true;
172
- default?: Opts['default'];
173
- } : Validator<number> & {
174
- optional?: Opts['optional'];
175
- default?: Opts['default'];
176
- };
177
- declare function boolean<Opts extends {
178
- default?: boolean;
179
- optional?: boolean;
180
- } = Record<string, never>>(opts?: Opts): Opts extends {
181
- optional: true;
182
- } ? Validator<boolean> & {
183
- optional: true;
184
- default?: Opts['default'];
185
- } : Validator<boolean> & {
186
- optional?: Opts['optional'];
187
- default?: Opts['default'];
188
- };
189
- declare function url<Opts extends {
190
- default?: string;
191
- optional?: boolean;
192
- } = Record<string, never>>(opts?: Opts): Opts extends {
193
- optional: true;
194
- } ? Validator<string> & {
195
- optional: true;
196
- default?: Opts['default'];
197
- } : Validator<string> & {
198
- optional?: Opts['optional'];
199
- default?: Opts['default'];
200
- };
201
- declare function email<Opts extends {
202
- default?: string;
203
- optional?: boolean;
204
- } = Record<string, never>>(opts?: Opts): Opts extends {
205
- optional: true;
206
- } ? Validator<string> & {
207
- optional: true;
208
- default?: Opts['default'];
209
- } : Validator<string> & {
210
- optional?: Opts['optional'];
211
- default?: Opts['default'];
212
- };
213
- declare function port<Opts extends {
214
- default?: number;
215
- optional?: boolean;
216
- } = Record<string, never>>(opts?: Opts): Opts extends {
217
- optional: true;
218
- } ? Validator<number> & {
219
- optional: true;
220
- default?: Opts['default'];
221
- } : Validator<number> & {
222
- optional?: Opts['optional'];
223
- default?: Opts['default'];
224
- };
225
- declare function postgres<Opts extends {
226
- default?: string;
227
- optional?: boolean;
228
- } = Record<string, never>>(opts?: Opts): Opts extends {
229
- optional: true;
230
- } ? Validator<string> & {
231
- optional: true;
232
- default?: Opts['default'];
233
- } : Validator<string> & {
234
- optional?: Opts['optional'];
235
- default?: Opts['default'];
236
- };
237
- declare function mysql<Opts extends {
238
- default?: string;
239
- optional?: boolean;
240
- } = Record<string, never>>(opts?: Opts): Opts extends {
241
- optional: true;
242
- } ? Validator<string> & {
243
- optional: true;
244
- default?: Opts['default'];
245
- } : Validator<string> & {
246
- optional?: Opts['optional'];
247
- default?: Opts['default'];
248
- };
249
- declare function mongodb<Opts extends {
250
- default?: string;
251
- optional?: boolean;
252
- } = Record<string, never>>(opts?: Opts): Opts extends {
253
- optional: true;
254
- } ? Validator<string> & {
255
- optional: true;
256
- default?: Opts['default'];
257
- } : Validator<string> & {
258
- optional?: Opts['optional'];
259
- default?: Opts['default'];
260
- };
261
- declare function redis<Opts extends {
262
- default?: string;
263
- optional?: boolean;
264
- } = Record<string, never>>(opts?: Opts): Opts extends {
265
- optional: true;
266
- } ? Validator<string> & {
267
- optional: true;
268
- default?: Opts['default'];
269
- } : Validator<string> & {
270
- optional?: Opts['optional'];
271
- default?: Opts['default'];
272
- };
273
- declare function https<Opts extends {
274
- default?: string;
275
- optional?: boolean;
276
- } = Record<string, never>>(opts?: Opts): Opts extends {
277
- optional: true;
278
- } ? Validator<string> & {
279
- optional: true;
280
- default?: Opts['default'];
281
- } : Validator<string> & {
282
- optional?: Opts['optional'];
283
- default?: Opts['default'];
284
- };
285
- declare function stringArray<Opts extends {
286
- default?: string[];
287
- optional?: boolean;
288
- separator?: string;
289
- } = Record<string, never>>(opts?: Opts): Opts extends {
290
- optional: true;
291
- } ? Validator<string[]> & {
292
- optional: true;
293
- default?: Opts['default'];
294
- } : Validator<string[]> & {
295
- optional?: Opts['optional'];
296
- default?: Opts['default'];
297
- };
298
- declare function numberArray<Opts extends {
299
- default?: number[];
300
- optional?: boolean;
301
- separator?: string;
302
- } = Record<string, never>>(opts?: Opts): Opts extends {
303
- optional: true;
304
- } ? Validator<number[]> & {
305
- optional: true;
306
- default?: Opts['default'];
307
- } : Validator<number[]> & {
308
- optional?: Opts['optional'];
309
- default?: Opts['default'];
310
- };
311
- declare function urlArray<Opts extends {
312
- default?: string[];
313
- optional?: boolean;
314
- separator?: string;
315
- } = Record<string, never>>(opts?: Opts): Opts extends {
316
- optional: true;
317
- } ? Validator<string[]> & {
318
- optional: true;
319
- default?: Opts['default'];
320
- } : Validator<string[]> & {
321
- optional?: Opts['optional'];
322
- default?: Opts['default'];
323
- };
324
- declare function enums<T extends readonly (string | number)[], Opts extends {
325
- default?: T[number];
326
- optional?: boolean;
327
- } = Record<string, never>>(values: T, opts?: Opts): Opts extends {
328
- optional: true;
329
- } ? Validator<T[number]> & {
330
- optional: true;
331
- default?: Opts['default'];
332
- } : Validator<T[number]> & {
333
- optional?: Opts['optional'];
334
- default?: Opts['default'];
335
- };
336
- declare function duration<Opts extends {
337
- default?: number;
338
- optional?: boolean;
339
- } = Record<string, never>>(opts?: Opts): Opts extends {
340
- optional: true;
341
- } ? Validator<number> & {
342
- optional: true;
343
- default?: Opts['default'];
344
- } : Validator<number> & {
345
- optional?: Opts['optional'];
346
- default?: Opts['default'];
347
- };
348
- declare function file<Opts extends {
349
- default?: string;
350
- optional?: boolean;
351
- secretsDir?: string;
352
- } = Record<string, never>>(opts?: Opts): Opts extends {
353
- optional: true;
354
- } ? Validator<string> & {
355
- optional: true;
356
- default?: Opts['default'];
357
- secretsDir?: Opts['secretsDir'];
358
- } : Validator<string> & {
359
- optional?: Opts['optional'];
360
- default?: Opts['default'];
361
- secretsDir?: Opts['secretsDir'];
362
- };
363
- declare function secret<Opts extends {
364
- default?: string;
365
- optional?: boolean;
366
- } = Record<string, never>>(opts?: Opts): Opts extends {
367
- optional: true;
368
- } ? Validator<string> & {
369
- optional: true;
370
- default?: Opts['default'];
371
- } : Validator<string> & {
372
- optional?: Opts['optional'];
373
- default?: Opts['default'];
374
- };
375
- declare function custom<T = unknown, Opts extends {
376
- default?: T;
377
- optional?: boolean;
378
- } = Record<string, never>>(validator: (value: string) => T, opts?: Opts): Opts extends {
379
- optional: true;
380
- } ? Validator<T> & {
381
- optional: true;
382
- default?: Opts['default'];
383
- } : Validator<T> & {
384
- optional?: Opts['optional'];
385
- default?: Opts['default'];
386
- };
387
- declare function date<Opts extends {
388
- default?: string;
389
- optional?: boolean;
390
- } = Record<string, never>>(opts?: Opts): Opts extends {
391
- optional: true;
392
- } ? Validator<string> & {
393
- optional: true;
394
- default?: Opts['default'];
395
- } : Validator<string> & {
396
- optional?: Opts['optional'];
397
- default?: Opts['default'];
398
- };
399
- declare function timestamp<Opts extends {
400
- default?: number;
401
- optional?: boolean;
402
- } = Record<string, never>>(opts?: Opts): Opts extends {
403
- optional: true;
404
- } ? Validator<number> & {
405
- optional: true;
406
- default?: Opts['default'];
407
- } : Validator<number> & {
408
- optional?: Opts['optional'];
409
- default?: Opts['default'];
410
- };
411
189
 
412
- export { type DotenvOptions, type TomlOptions, type YamlOptions, boolean, custom, date, dotenv, duration, email, enums, file, http, https, json, mongodb, mysql, number, numberArray, packageJson, port, postgres, processEnv, redis, secret, secrets, string, stringArray, timestamp, toml, url, urlArray, yaml };
190
+ export { type DotenvOptions, type TomlOptions, type YamlOptions, dotenv, http, json, packageJson, processEnv, secrets, toml, yaml };