node-env-resolver 5.0.0 → 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.
Files changed (46) hide show
  1. package/README.md +403 -291
  2. package/dist/audit.d.cts +23 -0
  3. package/dist/audit.d.ts +23 -0
  4. package/dist/builder.cjs +1 -1
  5. package/dist/builder.js +1 -1
  6. package/dist/chunk-4QOKRJ3F.cjs +1 -0
  7. package/dist/chunk-6D5APQIG.cjs +1 -0
  8. package/dist/chunk-FH54ESWI.cjs +9 -0
  9. package/dist/chunk-HHOS5S5T.js +1 -0
  10. package/dist/chunk-LCW5BDAW.js +15 -0
  11. package/dist/chunk-PNUGGPRS.cjs +15 -0
  12. package/dist/chunk-WKIPEKF6.js +1 -0
  13. package/dist/chunk-XJLMVSPN.js +9 -0
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.d.cts +72 -66
  16. package/dist/index.d.ts +72 -66
  17. package/dist/index.js +1 -1
  18. package/dist/resolvers.cjs +1 -1
  19. package/dist/resolvers.d.cts +50 -267
  20. package/dist/resolvers.d.ts +50 -267
  21. package/dist/resolvers.js +1 -1
  22. package/dist/types.cjs +1 -1
  23. package/dist/types.d.cts +33 -1
  24. package/dist/types.d.ts +33 -1
  25. package/dist/types.js +1 -1
  26. package/dist/utils.cjs +1 -1
  27. package/dist/utils.d.cts +61 -1
  28. package/dist/utils.d.ts +61 -1
  29. package/dist/utils.js +1 -1
  30. package/dist/valibot.cjs +1 -1
  31. package/dist/valibot.js +1 -1
  32. package/dist/validators.cjs +2 -2
  33. package/dist/validators.d.cts +771 -17
  34. package/dist/validators.d.ts +771 -17
  35. package/dist/validators.js +2 -2
  36. package/dist/web.cjs +4 -4
  37. package/dist/web.js +4 -4
  38. package/dist/zod.cjs +1 -1
  39. package/dist/zod.js +1 -1
  40. package/package.json +1 -1
  41. package/dist/chunk-6FXCXA4R.cjs +0 -11
  42. package/dist/chunk-BFLXBLZ3.cjs +0 -1
  43. package/dist/chunk-BJ2QNYTS.js +0 -11
  44. package/dist/chunk-P3TTYVEW.js +0 -16
  45. package/dist/chunk-UCLEPPLS.cjs +0 -16
  46. package/dist/chunk-ZMRT37K3.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SimpleEnvSchema, Resolver, ResolveOptions, InferSimpleValue, SyncResolver } from './types.js';
1
+ import { SimpleEnvSchema, ResolveAsyncConfig, InferSimpleValue, ResolveAsyncConfigWithSchema, Resolver, ResolveOptions, ResolveConfigWithSchema, SyncResolver, ResolveConfig } from './types.js';
2
2
  export { AsyncResolver, EnvDefinition, EnvSchema, InferResolveResult, InferSchema, InferSimpleSchema, InferType, PolicyOptions, Provenance, SimpleEnvValue, Validator, isAsyncOnlyResolver, isSyncResolver } from './types.js';
3
3
  export { SafeResolveResult as SafeResolveResultWithIssues, ValidationIssue } from './validation-types.js';
4
4
  export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.js';
@@ -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
@@ -21,11 +21,6 @@ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.
21
21
  * ```
22
22
  */
23
23
 
24
- /**
25
- * Resolver that reads from process.env
26
- * This is the default resolver used when no custom resolvers are provided
27
- */
28
- declare function processEnv(): SyncResolver;
29
24
  interface SafeResolveResult<T> {
30
25
  success: true;
31
26
  data: T;
@@ -39,14 +34,20 @@ type SafeResolveResultType<T> = SafeResolveResult<T> | SafeResolveError;
39
34
  declare function resolve<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): {
40
35
  [K in keyof T]: InferSimpleValue<T[K]>;
41
36
  };
42
- declare function resolve<T extends SimpleEnvSchema>(tuple: readonly [SyncResolver, T] | [SyncResolver, T], options?: Partial<ResolveOptions>): {
37
+ declare function resolve<T extends SimpleEnvSchema>(config: ResolveConfigWithSchema<T>): {
43
38
  [K in keyof T]: InferSimpleValue<T[K]>;
44
39
  };
45
- declare function resolve<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema>(tuple1: readonly [SyncResolver, T1] | [SyncResolver, T1], tuple2: readonly [SyncResolver, T2] | [SyncResolver, T2], options?: Partial<ResolveOptions>): {
46
- [K in keyof (T1 & T2)]: InferSimpleValue<(T1 & T2)[K]>;
40
+ declare function resolve<T extends SimpleEnvSchema>(config: {
41
+ resolvers: readonly [[SyncResolver, T]];
42
+ options?: Partial<ResolveOptions>;
43
+ }): {
44
+ [K in keyof T]: InferSimpleValue<T[K]>;
47
45
  };
48
- declare function resolve<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema>(tuple1: readonly [SyncResolver, T1] | [SyncResolver, T1], tuple2: readonly [SyncResolver, T2] | [SyncResolver, T2], tuple3: readonly [SyncResolver, T3] | [SyncResolver, T3], options?: Partial<ResolveOptions>): {
49
- [K in keyof (T1 & T2 & T3)]: InferSimpleValue<(T1 & T2 & T3)[K]>;
46
+ declare function resolve<T extends SimpleEnvSchema>(config: {
47
+ resolvers: readonly [SyncResolver, SimpleEnvSchema][];
48
+ options?: Partial<ResolveOptions>;
49
+ }): {
50
+ [K in keyof T]: InferSimpleValue<T[K]>;
50
51
  };
51
52
  /**
52
53
  * Resolve environment variables asynchronously (supports all resolver types - both sync and async)
@@ -54,45 +55,58 @@ declare function resolve<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema,
54
55
  * @example
55
56
  * ```typescript
56
57
  * import { resolveAsync } from 'node-env-resolver';
57
- * import { postgres, string } from 'node-env-resolver/resolvers';
58
+ * import { postgres, string } from 'node-env-resolver/validators';
58
59
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
59
60
  *
60
61
  * // Works with async-only resolvers
61
- * const config = await resolveAsync([
62
- * awsSecrets(),
63
- * { PORT: 3000, DATABASE_URL: postgres(), API_KEY: string() }
64
- * ]);
62
+ * const config = await resolveAsync({
63
+ * resolvers: [
64
+ * [awsSecrets(), { PORT: 3000, DATABASE_URL: postgres(), API_KEY: string() }]
65
+ * ]
66
+ * });
65
67
  *
66
68
  * // Also works with sync resolvers (automatically wrapped in Promise)
67
- * const config = await resolveAsync([
68
- * processEnv(), // Sync resolver works in async context
69
- * { DATABASE_URL: postgres() }
70
- * ], { strict: true });
69
+ * const config = await resolveAsync({
70
+ * resolvers: [
71
+ * [processEnv(), { DATABASE_URL: postgres() }]
72
+ * ],
73
+ * options: { strict: true }
74
+ * });
71
75
  *
72
76
  * // Multiple resolvers - supports unlimited tuples!
73
- * const config = await resolveAsync(
74
- * [dotenv(), { PORT: 3000 }],
75
- * [awsSecrets(), { DATABASE_URL: postgres() }],
76
- * { strict: true }
77
- * );
77
+ * const config = await resolveAsync({
78
+ * resolvers: [
79
+ * [dotenv(), { PORT: 3000 }],
80
+ * [awsSecrets(), { DATABASE_URL: postgres() }]
81
+ * ],
82
+ * options: { strict: true }
83
+ * });
78
84
  * ```
79
85
  */
80
- declare function resolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<{
86
+ declare function resolveAsync<T extends SimpleEnvSchema>(config: ResolveAsyncConfigWithSchema<T>): Promise<{
81
87
  [K in keyof T]: InferSimpleValue<T[K]>;
82
88
  }>;
83
- declare function resolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], options?: Partial<ResolveOptions>): Promise<{
84
- [K in keyof (T1 & T2)]: InferSimpleValue<(T1 & T2)[K]>;
85
- }>;
86
- declare function resolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], options?: Partial<ResolveOptions>): Promise<{
87
- [K in keyof (T1 & T2 & T3)]: InferSimpleValue<(T1 & T2 & T3)[K]>;
88
- }>;
89
- declare function resolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema, T4 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], tuple4: readonly [Resolver, T4] | [Resolver, T4], options?: Partial<ResolveOptions>): Promise<{
90
- [K in keyof (T1 & T2 & T3 & T4)]: InferSimpleValue<(T1 & T2 & T3 & T4)[K]>;
89
+ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
90
+ resolvers: readonly [[Resolver, T]];
91
+ options?: Partial<ResolveOptions>;
92
+ }): Promise<{
93
+ [K in keyof T]: InferSimpleValue<T[K]>;
91
94
  }>;
92
- declare function resolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema, T4 extends SimpleEnvSchema, T5 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], tuple4: readonly [Resolver, T4] | [Resolver, T4], tuple5: readonly [Resolver, T5] | [Resolver, T5], options?: Partial<ResolveOptions>): Promise<{
93
- [K in keyof (T1 & T2 & T3 & T4 & T5)]: InferSimpleValue<(T1 & T2 & T3 & T4 & T5)[K]>;
95
+ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
96
+ resolvers: readonly [Resolver, SimpleEnvSchema][];
97
+ options?: Partial<ResolveOptions>;
98
+ }): Promise<{
99
+ [K in keyof T]: InferSimpleValue<T[K]>;
94
100
  }>;
95
- declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | [SyncResolver, T], ...rest: ([SyncResolver, T] | Partial<ResolveOptions>)[]): SafeResolveResultType<{
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
+ */
109
+ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
96
110
  [K in keyof T]: InferSimpleValue<T[K]>;
97
111
  }>;
98
112
  /**
@@ -102,27 +116,31 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | [SyncResolver,
102
116
  * @example
103
117
  * ```typescript
104
118
  * import { safeResolveAsync } from 'node-env-resolver';
105
- * import { postgres } from 'node-env-resolver/resolvers';
119
+ * import { postgres } from 'node-env-resolver/validators';
106
120
  * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
107
121
  *
108
122
  * // Works with async resolvers
109
- * const result = await safeResolveAsync([
110
- * awsSecrets({ region: 'us-east-1' }),
111
- * { PORT: 3000, DATABASE_URL: postgres() }
112
- * ]);
123
+ * const result = await safeResolveAsync({
124
+ * resolvers: [
125
+ * [awsSecrets({ region: 'us-east-1' }), { PORT: 3000, DATABASE_URL: postgres() }]
126
+ * ]
127
+ * });
113
128
  *
114
129
  * // Also works with sync resolvers
115
- * const result = await safeResolveAsync([
116
- * processEnv(), // Sync resolver works fine
117
- * { PORT: 3000 }
118
- * ]);
130
+ * const result = await safeResolveAsync({
131
+ * resolvers: [
132
+ * [processEnv(), { PORT: 3000 }]
133
+ * ]
134
+ * });
119
135
  *
120
136
  * // Multiple resolvers - supports unlimited tuples!
121
- * const result = await safeResolveAsync(
122
- * [dotenv(), { PORT: 3000 }],
123
- * [awsSecrets(), { DATABASE_URL: postgres() }],
124
- * { strict: true }
125
- * );
137
+ * const result = await safeResolveAsync({
138
+ * resolvers: [
139
+ * [dotenv(), { PORT: 3000 }],
140
+ * [awsSecrets(), { DATABASE_URL: postgres() }]
141
+ * ],
142
+ * options: { strict: true }
143
+ * });
126
144
  *
127
145
  * if (result.success) {
128
146
  * console.log(result.data.PORT); // Type-safe access
@@ -131,20 +149,8 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | [SyncResolver,
131
149
  * }
132
150
  * ```
133
151
  */
134
- declare function safeResolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
152
+ declare function safeResolveAsync<T extends SimpleEnvSchema>(config: ResolveAsyncConfig<T>): Promise<SafeResolveResultType<{
135
153
  [K in keyof T]: InferSimpleValue<T[K]>;
136
154
  }>>;
137
- declare function safeResolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
138
- [K in keyof (T1 & T2)]: InferSimpleValue<(T1 & T2)[K]>;
139
- }>>;
140
- declare function safeResolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
141
- [K in keyof (T1 & T2 & T3)]: InferSimpleValue<(T1 & T2 & T3)[K]>;
142
- }>>;
143
- declare function safeResolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema, T4 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], tuple4: readonly [Resolver, T4] | [Resolver, T4], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
144
- [K in keyof (T1 & T2 & T3 & T4)]: InferSimpleValue<(T1 & T2 & T3 & T4)[K]>;
145
- }>>;
146
- declare function safeResolveAsync<T1 extends SimpleEnvSchema, T2 extends SimpleEnvSchema, T3 extends SimpleEnvSchema, T4 extends SimpleEnvSchema, T5 extends SimpleEnvSchema>(tuple1: readonly [Resolver, T1] | [Resolver, T1], tuple2: readonly [Resolver, T2] | [Resolver, T2], tuple3: readonly [Resolver, T3] | [Resolver, T3], tuple4: readonly [Resolver, T4] | [Resolver, T4], tuple5: readonly [Resolver, T5] | [Resolver, T5], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
147
- [K in keyof (T1 & T2 & T3 & T4 & T5)]: InferSimpleValue<(T1 & T2 & T3 & T4 & T5)[K]>;
148
- }>>;
149
155
 
150
- export { ResolveOptions, Resolver, type SafeResolveError, type SafeResolveResult, type SafeResolveResultType, SimpleEnvSchema, SyncResolver, processEnv, resolve, resolveAsync, safeResolve, safeResolveAsync };
156
+ export { ResolveAsyncConfig, ResolveConfig, ResolveOptions, Resolver, type SafeResolveError, type SafeResolveResult, type SafeResolveResultType, SimpleEnvSchema, SyncResolver, resolve, resolveAsync, safeResolve, safeResolveAsync };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{a as processEnv,b as resolve,c as resolveAsync,d as safeResolve,e as safeResolveAsync}from'./chunk-BJ2QNYTS.js';import'./chunk-DIXI6MUB.js';export{d as clearAuditLog,c as getAuditLog}from'./chunk-YOHHFBZN.js';export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-ZMRT37K3.js';import'./chunk-5PELJRUQ.js';
1
+ export{a as resolve,b as resolveAsync,c as safeResolve,d as safeResolveAsync}from'./chunk-XJLMVSPN.js';import'./chunk-DIXI6MUB.js';export{d as clearAuditLog,c as getAuditLog}from'./chunk-YOHHFBZN.js';import'./chunk-WKIPEKF6.js';export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-5PELJRUQ.js';
@@ -1 +1 @@
1
- 'use strict';var chunkUCLEPPLS_cjs=require('./chunk-UCLEPPLS.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"boolean",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.k}});Object.defineProperty(exports,"custom",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.A}});Object.defineProperty(exports,"date",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.B}});Object.defineProperty(exports,"dotenv",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.a}});Object.defineProperty(exports,"duration",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.x}});Object.defineProperty(exports,"email",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.m}});Object.defineProperty(exports,"enums",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.w}});Object.defineProperty(exports,"file",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.y}});Object.defineProperty(exports,"http",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.d}});Object.defineProperty(exports,"https",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.s}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.e}});Object.defineProperty(exports,"mongodb",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.q}});Object.defineProperty(exports,"mysql",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.p}});Object.defineProperty(exports,"number",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.j}});Object.defineProperty(exports,"numberArray",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.u}});Object.defineProperty(exports,"packageJson",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.c}});Object.defineProperty(exports,"port",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.n}});Object.defineProperty(exports,"postgres",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.o}});Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.b}});Object.defineProperty(exports,"redis",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.r}});Object.defineProperty(exports,"secret",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.z}});Object.defineProperty(exports,"secrets",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.f}});Object.defineProperty(exports,"string",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.i}});Object.defineProperty(exports,"stringArray",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.t}});Object.defineProperty(exports,"timestamp",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.C}});Object.defineProperty(exports,"toml",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.h}});Object.defineProperty(exports,"url",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.l}});Object.defineProperty(exports,"urlArray",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.v}});Object.defineProperty(exports,"yaml",{enumerable:true,get:function(){return chunkUCLEPPLS_cjs.g}});
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,15 +1,60 @@
1
- import { Resolver, SyncResolver, Validator } from './types.cjs';
1
+ import { SyncResolver, Resolver } from './types.cjs';
2
+
3
+ /**
4
+ * Resolver that reads from process.env
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
+ * ```
16
+ */
17
+ declare function processEnv(): SyncResolver;
2
18
 
3
19
  /**
4
20
  * Built-in resolvers for environment variable resolution
5
21
  */
6
22
 
23
+ /**
24
+ * Options for the dotenv resolver
25
+ */
7
26
  interface DotenvOptions {
27
+ /** Path to the .env file (default: '.env') */
8
28
  path?: string;
29
+ /** Enable environment-specific file loading (default: false) */
9
30
  expand?: boolean;
10
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
+ */
11
57
  declare function dotenv(options?: string | DotenvOptions): Resolver;
12
- declare function processEnv(): SyncResolver;
13
58
  /**
14
59
  * Load configuration from package.json
15
60
  * Reads version, name, and config fields by default
@@ -94,6 +139,7 @@ declare function secrets(path?: string): Resolver;
94
139
  * Requires 'js-yaml' as a peer dependency (install separately for tree-shaking)
95
140
  */
96
141
  interface YamlOptions {
142
+ /** Path to the YAML file (default: 'config.yaml') */
97
143
  path?: string;
98
144
  }
99
145
  /**
@@ -119,6 +165,7 @@ declare function yaml(options?: string | YamlOptions): Resolver;
119
165
  * Requires 'smol-toml' as a peer dependency (install separately for tree-shaking)
120
166
  */
121
167
  interface TomlOptions {
168
+ /** Path to the TOML file (default: 'config.toml') */
122
169
  path?: string;
123
170
  }
124
171
  /**
@@ -139,269 +186,5 @@ interface TomlOptions {
139
186
  * ```
140
187
  */
141
188
  declare function toml(options?: string | TomlOptions): Resolver;
142
- declare function string<Opts extends {
143
- default?: string;
144
- optional?: boolean;
145
- min?: number;
146
- max?: number;
147
- allowEmpty?: boolean;
148
- pattern?: string;
149
- } = Record<string, never>>(opts?: Opts): Opts extends {
150
- optional: true;
151
- } ? Validator<string> & {
152
- optional: true;
153
- default?: Opts['default'];
154
- } : Validator<string> & {
155
- optional?: Opts['optional'];
156
- default?: Opts['default'];
157
- };
158
- declare function number<Opts extends {
159
- default?: number;
160
- optional?: boolean;
161
- min?: number;
162
- max?: number;
163
- } = Record<string, never>>(opts?: Opts): Opts extends {
164
- optional: true;
165
- } ? Validator<number> & {
166
- optional: true;
167
- default?: Opts['default'];
168
- } : Validator<number> & {
169
- optional?: Opts['optional'];
170
- default?: Opts['default'];
171
- };
172
- declare function boolean<Opts extends {
173
- default?: boolean;
174
- optional?: boolean;
175
- } = Record<string, never>>(opts?: Opts): Opts extends {
176
- optional: true;
177
- } ? Validator<boolean> & {
178
- optional: true;
179
- default?: Opts['default'];
180
- } : Validator<boolean> & {
181
- optional?: Opts['optional'];
182
- default?: Opts['default'];
183
- };
184
- declare function url<Opts extends {
185
- default?: string;
186
- optional?: boolean;
187
- } = Record<string, never>>(opts?: Opts): Opts extends {
188
- optional: true;
189
- } ? Validator<string> & {
190
- optional: true;
191
- default?: Opts['default'];
192
- } : Validator<string> & {
193
- optional?: Opts['optional'];
194
- default?: Opts['default'];
195
- };
196
- declare function email<Opts extends {
197
- default?: string;
198
- optional?: boolean;
199
- } = Record<string, never>>(opts?: Opts): Opts extends {
200
- optional: true;
201
- } ? Validator<string> & {
202
- optional: true;
203
- default?: Opts['default'];
204
- } : Validator<string> & {
205
- optional?: Opts['optional'];
206
- default?: Opts['default'];
207
- };
208
- declare function port<Opts extends {
209
- default?: number;
210
- optional?: boolean;
211
- } = Record<string, never>>(opts?: Opts): Opts extends {
212
- optional: true;
213
- } ? Validator<number> & {
214
- optional: true;
215
- default?: Opts['default'];
216
- } : Validator<number> & {
217
- optional?: Opts['optional'];
218
- default?: Opts['default'];
219
- };
220
- declare function postgres<Opts extends {
221
- default?: string;
222
- optional?: boolean;
223
- } = Record<string, never>>(opts?: Opts): Opts extends {
224
- optional: true;
225
- } ? Validator<string> & {
226
- optional: true;
227
- default?: Opts['default'];
228
- } : Validator<string> & {
229
- optional?: Opts['optional'];
230
- default?: Opts['default'];
231
- };
232
- declare function mysql<Opts extends {
233
- default?: string;
234
- optional?: boolean;
235
- } = Record<string, never>>(opts?: Opts): Opts extends {
236
- optional: true;
237
- } ? Validator<string> & {
238
- optional: true;
239
- default?: Opts['default'];
240
- } : Validator<string> & {
241
- optional?: Opts['optional'];
242
- default?: Opts['default'];
243
- };
244
- declare function mongodb<Opts extends {
245
- default?: string;
246
- optional?: boolean;
247
- } = Record<string, never>>(opts?: Opts): Opts extends {
248
- optional: true;
249
- } ? Validator<string> & {
250
- optional: true;
251
- default?: Opts['default'];
252
- } : Validator<string> & {
253
- optional?: Opts['optional'];
254
- default?: Opts['default'];
255
- };
256
- declare function redis<Opts extends {
257
- default?: string;
258
- optional?: boolean;
259
- } = Record<string, never>>(opts?: Opts): Opts extends {
260
- optional: true;
261
- } ? Validator<string> & {
262
- optional: true;
263
- default?: Opts['default'];
264
- } : Validator<string> & {
265
- optional?: Opts['optional'];
266
- default?: Opts['default'];
267
- };
268
- declare function https<Opts extends {
269
- default?: string;
270
- optional?: boolean;
271
- } = Record<string, never>>(opts?: Opts): Opts extends {
272
- optional: true;
273
- } ? Validator<string> & {
274
- optional: true;
275
- default?: Opts['default'];
276
- } : Validator<string> & {
277
- optional?: Opts['optional'];
278
- default?: Opts['default'];
279
- };
280
- declare function stringArray<Opts extends {
281
- default?: string[];
282
- optional?: boolean;
283
- separator?: string;
284
- } = Record<string, never>>(opts?: Opts): Opts extends {
285
- optional: true;
286
- } ? Validator<string[]> & {
287
- optional: true;
288
- default?: Opts['default'];
289
- } : Validator<string[]> & {
290
- optional?: Opts['optional'];
291
- default?: Opts['default'];
292
- };
293
- declare function numberArray<Opts extends {
294
- default?: number[];
295
- optional?: boolean;
296
- separator?: string;
297
- } = Record<string, never>>(opts?: Opts): Opts extends {
298
- optional: true;
299
- } ? Validator<number[]> & {
300
- optional: true;
301
- default?: Opts['default'];
302
- } : Validator<number[]> & {
303
- optional?: Opts['optional'];
304
- default?: Opts['default'];
305
- };
306
- declare function urlArray<Opts extends {
307
- default?: string[];
308
- optional?: boolean;
309
- separator?: string;
310
- } = Record<string, never>>(opts?: Opts): Opts extends {
311
- optional: true;
312
- } ? Validator<string[]> & {
313
- optional: true;
314
- default?: Opts['default'];
315
- } : Validator<string[]> & {
316
- optional?: Opts['optional'];
317
- default?: Opts['default'];
318
- };
319
- declare function enums<T extends readonly (string | number)[], Opts extends {
320
- default?: T[number];
321
- optional?: boolean;
322
- } = Record<string, never>>(values: T, opts?: Opts): Opts extends {
323
- optional: true;
324
- } ? Validator<T[number]> & {
325
- optional: true;
326
- default?: Opts['default'];
327
- } : Validator<T[number]> & {
328
- optional?: Opts['optional'];
329
- default?: Opts['default'];
330
- };
331
- declare function duration<Opts extends {
332
- default?: number;
333
- optional?: boolean;
334
- } = Record<string, never>>(opts?: Opts): Opts extends {
335
- optional: true;
336
- } ? Validator<number> & {
337
- optional: true;
338
- default?: Opts['default'];
339
- } : Validator<number> & {
340
- optional?: Opts['optional'];
341
- default?: Opts['default'];
342
- };
343
- declare function file<Opts extends {
344
- default?: string;
345
- optional?: boolean;
346
- secretsDir?: string;
347
- } = Record<string, never>>(opts?: Opts): Opts extends {
348
- optional: true;
349
- } ? Validator<string> & {
350
- optional: true;
351
- default?: Opts['default'];
352
- secretsDir?: Opts['secretsDir'];
353
- } : Validator<string> & {
354
- optional?: Opts['optional'];
355
- default?: Opts['default'];
356
- secretsDir?: Opts['secretsDir'];
357
- };
358
- declare function secret<Opts extends {
359
- default?: string;
360
- optional?: boolean;
361
- } = Record<string, never>>(opts?: Opts): Opts extends {
362
- optional: true;
363
- } ? Validator<string> & {
364
- optional: true;
365
- default?: Opts['default'];
366
- } : Validator<string> & {
367
- optional?: Opts['optional'];
368
- default?: Opts['default'];
369
- };
370
- declare function custom<T = unknown, Opts extends {
371
- default?: T;
372
- optional?: boolean;
373
- } = Record<string, never>>(validator: (value: string) => T, opts?: Opts): Opts extends {
374
- optional: true;
375
- } ? Validator<T> & {
376
- optional: true;
377
- default?: Opts['default'];
378
- } : Validator<T> & {
379
- optional?: Opts['optional'];
380
- default?: Opts['default'];
381
- };
382
- declare function date<Opts extends {
383
- default?: string;
384
- optional?: boolean;
385
- } = Record<string, never>>(opts?: Opts): Opts extends {
386
- optional: true;
387
- } ? Validator<string> & {
388
- optional: true;
389
- default?: Opts['default'];
390
- } : Validator<string> & {
391
- optional?: Opts['optional'];
392
- default?: Opts['default'];
393
- };
394
- declare function timestamp<Opts extends {
395
- default?: number;
396
- optional?: boolean;
397
- } = Record<string, never>>(opts?: Opts): Opts extends {
398
- optional: true;
399
- } ? Validator<number> & {
400
- optional: true;
401
- default?: Opts['default'];
402
- } : Validator<number> & {
403
- optional?: Opts['optional'];
404
- default?: Opts['default'];
405
- };
406
189
 
407
- 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 };