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.
- package/README.md +403 -291
- package/dist/audit.d.cts +23 -0
- package/dist/audit.d.ts +23 -0
- package/dist/builder.cjs +1 -1
- package/dist/builder.js +1 -1
- package/dist/chunk-4QOKRJ3F.cjs +1 -0
- package/dist/chunk-6D5APQIG.cjs +1 -0
- package/dist/chunk-FH54ESWI.cjs +9 -0
- package/dist/chunk-HHOS5S5T.js +1 -0
- package/dist/chunk-LCW5BDAW.js +15 -0
- package/dist/chunk-PNUGGPRS.cjs +15 -0
- package/dist/chunk-WKIPEKF6.js +1 -0
- package/dist/chunk-XJLMVSPN.js +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -66
- package/dist/index.d.ts +72 -66
- package/dist/index.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +50 -267
- package/dist/resolvers.d.ts +50 -267
- package/dist/resolvers.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +33 -1
- package/dist/types.d.ts +33 -1
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +61 -1
- package/dist/utils.d.ts +61 -1
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.js +1 -1
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.cts +771 -17
- package/dist/validators.d.ts +771 -17
- package/dist/validators.js +2 -2
- package/dist/web.cjs +4 -4
- package/dist/web.js +4 -4
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-6FXCXA4R.cjs +0 -11
- package/dist/chunk-BFLXBLZ3.cjs +0 -1
- package/dist/chunk-BJ2QNYTS.js +0 -11
- package/dist/chunk-P3TTYVEW.js +0 -16
- package/dist/chunk-UCLEPPLS.cjs +0 -16
- package/dist/chunk-ZMRT37K3.js +0 -1
package/dist/resolvers.d.ts
CHANGED
|
@@ -1,15 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyncResolver, Resolver } from './types.js';
|
|
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,
|
|
190
|
+
export { type DotenvOptions, type TomlOptions, type YamlOptions, dotenv, http, json, packageJson, processEnv, secrets, toml, yaml };
|
package/dist/resolvers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{a as dotenv,c as http,d as json,b as packageJson,e as secrets,g as toml,f as yaml}from'./chunk-LCW5BDAW.js';export{a as processEnv}from'./chunk-WKIPEKF6.js';import'./chunk-5PELJRUQ.js';
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk6D5APQIG_cjs=require('./chunk-6D5APQIG.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.a}});
|
package/dist/types.d.cts
CHANGED
|
@@ -47,6 +47,38 @@ type SafeResolveResultType<T> = {
|
|
|
47
47
|
error: string;
|
|
48
48
|
details?: unknown;
|
|
49
49
|
};
|
|
50
|
+
type InferMergedSchema<T extends readonly [unknown, SimpleEnvSchema][]> = T extends readonly [
|
|
51
|
+
unknown,
|
|
52
|
+
infer S1,
|
|
53
|
+
...infer Rest
|
|
54
|
+
] ? Rest extends readonly [unknown, SimpleEnvSchema][] ? S1 & InferMergedSchema<Rest> : S1 : T extends readonly [unknown, infer S] ? S : Record<string, never>;
|
|
55
|
+
|
|
56
|
+
interface ResolveConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
|
|
57
|
+
schema?: T;
|
|
58
|
+
resolvers?: readonly [SyncResolver, SimpleEnvSchema][];
|
|
59
|
+
options?: Partial<ResolveOptions>;
|
|
60
|
+
}
|
|
61
|
+
interface ResolveAsyncConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
|
|
62
|
+
schema?: T;
|
|
63
|
+
resolvers?: readonly [Resolver, SimpleEnvSchema][];
|
|
64
|
+
options?: Partial<ResolveOptions>;
|
|
65
|
+
}
|
|
66
|
+
interface ResolveConfigWithSchema<T extends SimpleEnvSchema> {
|
|
67
|
+
schema: T;
|
|
68
|
+
options?: Partial<ResolveOptions>;
|
|
69
|
+
}
|
|
70
|
+
interface ResolveConfigWithResolvers<T extends readonly [SyncResolver, SimpleEnvSchema][]> {
|
|
71
|
+
resolvers: T;
|
|
72
|
+
options?: Partial<ResolveOptions>;
|
|
73
|
+
}
|
|
74
|
+
interface ResolveAsyncConfigWithSchema<T extends SimpleEnvSchema> {
|
|
75
|
+
schema: T;
|
|
76
|
+
options?: Partial<ResolveOptions>;
|
|
77
|
+
}
|
|
78
|
+
interface ResolveAsyncConfigWithResolvers<T extends readonly [Resolver, SimpleEnvSchema][]> {
|
|
79
|
+
resolvers: T;
|
|
80
|
+
options?: Partial<ResolveOptions>;
|
|
81
|
+
}
|
|
50
82
|
type Provenance = {
|
|
51
83
|
source: string;
|
|
52
84
|
timestamp: number;
|
|
@@ -71,4 +103,4 @@ interface EnvDefinition {
|
|
|
71
103
|
type InferType = unknown;
|
|
72
104
|
type InferSchema = unknown;
|
|
73
105
|
|
|
74
|
-
export { type AsyncResolver, type EnvDefinition, type EnvSchema, type InferNestedSchema, type InferResolveResult, type InferSchema, type InferSimpleSchema, type InferSimpleValue, type InferType, type PolicyOptions, type Provenance, type ResolveOptions, type Resolver, type SafeResolveResultType, type SimpleEnvSchema, type SimpleEnvValue, type SyncResolver, type Validator, isAsyncOnlyResolver, isSyncResolver };
|
|
106
|
+
export { type AsyncResolver, type EnvDefinition, type EnvSchema, type InferMergedSchema, type InferNestedSchema, type InferResolveResult, type InferSchema, type InferSimpleSchema, type InferSimpleValue, type InferType, type PolicyOptions, type Provenance, type ResolveAsyncConfig, type ResolveAsyncConfigWithResolvers, type ResolveAsyncConfigWithSchema, type ResolveConfig, type ResolveConfigWithResolvers, type ResolveConfigWithSchema, type ResolveOptions, type Resolver, type SafeResolveResultType, type SimpleEnvSchema, type SimpleEnvValue, type SyncResolver, type Validator, isAsyncOnlyResolver, isSyncResolver };
|
package/dist/types.d.ts
CHANGED
|
@@ -47,6 +47,38 @@ type SafeResolveResultType<T> = {
|
|
|
47
47
|
error: string;
|
|
48
48
|
details?: unknown;
|
|
49
49
|
};
|
|
50
|
+
type InferMergedSchema<T extends readonly [unknown, SimpleEnvSchema][]> = T extends readonly [
|
|
51
|
+
unknown,
|
|
52
|
+
infer S1,
|
|
53
|
+
...infer Rest
|
|
54
|
+
] ? Rest extends readonly [unknown, SimpleEnvSchema][] ? S1 & InferMergedSchema<Rest> : S1 : T extends readonly [unknown, infer S] ? S : Record<string, never>;
|
|
55
|
+
|
|
56
|
+
interface ResolveConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
|
|
57
|
+
schema?: T;
|
|
58
|
+
resolvers?: readonly [SyncResolver, SimpleEnvSchema][];
|
|
59
|
+
options?: Partial<ResolveOptions>;
|
|
60
|
+
}
|
|
61
|
+
interface ResolveAsyncConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
|
|
62
|
+
schema?: T;
|
|
63
|
+
resolvers?: readonly [Resolver, SimpleEnvSchema][];
|
|
64
|
+
options?: Partial<ResolveOptions>;
|
|
65
|
+
}
|
|
66
|
+
interface ResolveConfigWithSchema<T extends SimpleEnvSchema> {
|
|
67
|
+
schema: T;
|
|
68
|
+
options?: Partial<ResolveOptions>;
|
|
69
|
+
}
|
|
70
|
+
interface ResolveConfigWithResolvers<T extends readonly [SyncResolver, SimpleEnvSchema][]> {
|
|
71
|
+
resolvers: T;
|
|
72
|
+
options?: Partial<ResolveOptions>;
|
|
73
|
+
}
|
|
74
|
+
interface ResolveAsyncConfigWithSchema<T extends SimpleEnvSchema> {
|
|
75
|
+
schema: T;
|
|
76
|
+
options?: Partial<ResolveOptions>;
|
|
77
|
+
}
|
|
78
|
+
interface ResolveAsyncConfigWithResolvers<T extends readonly [Resolver, SimpleEnvSchema][]> {
|
|
79
|
+
resolvers: T;
|
|
80
|
+
options?: Partial<ResolveOptions>;
|
|
81
|
+
}
|
|
50
82
|
type Provenance = {
|
|
51
83
|
source: string;
|
|
52
84
|
timestamp: number;
|
|
@@ -71,4 +103,4 @@ interface EnvDefinition {
|
|
|
71
103
|
type InferType = unknown;
|
|
72
104
|
type InferSchema = unknown;
|
|
73
105
|
|
|
74
|
-
export { type AsyncResolver, type EnvDefinition, type EnvSchema, type InferNestedSchema, type InferResolveResult, type InferSchema, type InferSimpleSchema, type InferSimpleValue, type InferType, type PolicyOptions, type Provenance, type ResolveOptions, type Resolver, type SafeResolveResultType, type SimpleEnvSchema, type SimpleEnvValue, type SyncResolver, type Validator, isAsyncOnlyResolver, isSyncResolver };
|
|
106
|
+
export { type AsyncResolver, type EnvDefinition, type EnvSchema, type InferMergedSchema, type InferNestedSchema, type InferResolveResult, type InferSchema, type InferSimpleSchema, type InferSimpleValue, type InferType, type PolicyOptions, type Provenance, type ResolveAsyncConfig, type ResolveAsyncConfigWithResolvers, type ResolveAsyncConfigWithSchema, type ResolveConfig, type ResolveConfigWithResolvers, type ResolveConfigWithSchema, type ResolveOptions, type Resolver, type SafeResolveResultType, type SimpleEnvSchema, type SimpleEnvValue, type SyncResolver, type Validator, isAsyncOnlyResolver, isSyncResolver };
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-
|
|
1
|
+
export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-5PELJRUQ.js';
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkFH54ESWI_cjs=require('./chunk-FH54ESWI.cjs');require('./chunk-4YVXFL3I.cjs'),require('./chunk-4ZOF2PI4.cjs'),require('./chunk-4QOKRJ3F.cjs'),require('./chunk-6D5APQIG.cjs');var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs');function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a=null,i=[],d=async()=>{try{return await import('./index.cjs'),t=await chunkFH54ESWI_cjs.b(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a&&clearTimeout(a),a=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=chunkKIQXH265_cjs.a("fs"),{join:y}=chunkKIQXH265_cjs.a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a&&clearTimeout(a);for(let c of i)c.close();}}}exports.TTL=p;exports.awsCache=C;exports.cached=T;exports.retry=b;exports.watch=v;exports.withAliases=$;exports.withComputed=P;exports.withNamespace=k;exports.withPrefix=x;exports.withTransform=S;
|
package/dist/utils.d.cts
CHANGED
|
@@ -13,6 +13,33 @@ interface CacheOptions {
|
|
|
13
13
|
/** Custom cache key (useful for debugging or manual cache invalidation) */
|
|
14
14
|
key?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a resolver with caching functionality
|
|
18
|
+
* Provides TTL-based caching with stale-while-revalidate support
|
|
19
|
+
*
|
|
20
|
+
* @param resolver - Resolver to wrap with caching
|
|
21
|
+
* @param options - Cache configuration options
|
|
22
|
+
* @returns Cached resolver that implements the same interface
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { cached, TTL } from 'node-env-resolver/utils';
|
|
27
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
28
|
+
*
|
|
29
|
+
* // Cache AWS secrets for 5 minutes
|
|
30
|
+
* const cachedResolver = cached(
|
|
31
|
+
* awsSecrets({ secretId: 'prod/config' }),
|
|
32
|
+
* { ttl: TTL.minutes5 }
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* // With stale-while-revalidate
|
|
36
|
+
* const resilientResolver = cached(awsSecrets(), {
|
|
37
|
+
* ttl: TTL.minutes5,
|
|
38
|
+
* maxAge: TTL.hour,
|
|
39
|
+
* staleWhileRevalidate: true
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
16
43
|
declare function cached(resolver: Resolver, options?: CacheOptions): Resolver;
|
|
17
44
|
declare const TTL: {
|
|
18
45
|
/** 30 seconds */
|
|
@@ -30,6 +57,21 @@ declare const TTL: {
|
|
|
30
57
|
/** 24 hours */
|
|
31
58
|
readonly day: number;
|
|
32
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Helper function to create AWS-friendly cache configuration
|
|
62
|
+
* Provides sensible defaults for AWS services (5min TTL, 1hr maxAge, stale-while-revalidate enabled)
|
|
63
|
+
*
|
|
64
|
+
* @param options - Cache configuration options
|
|
65
|
+
* @returns Cache options optimized for AWS services
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { awsCache } from 'node-env-resolver/utils';
|
|
70
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
71
|
+
*
|
|
72
|
+
* const resolver = cached(awsSecrets(), awsCache({ ttl: 10 * 60 * 1000 }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
33
75
|
declare function awsCache(options?: {
|
|
34
76
|
/** Cache duration for AWS secrets/parameters (default: 5 minutes) */
|
|
35
77
|
ttl?: number;
|
|
@@ -38,6 +80,24 @@ declare function awsCache(options?: {
|
|
|
38
80
|
/** Enable stale-while-revalidate for better performance (default: true) */
|
|
39
81
|
staleWhileRevalidate?: boolean;
|
|
40
82
|
}): CacheOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Wrap a resolver with retry functionality
|
|
85
|
+
* Automatically retries failed requests with exponential backoff
|
|
86
|
+
*
|
|
87
|
+
* @param resolver - Resolver to wrap with retry logic
|
|
88
|
+
* @param maxRetries - Maximum number of retry attempts (default: 3)
|
|
89
|
+
* @param delayMs - Initial delay between retries in milliseconds (default: 1000)
|
|
90
|
+
* @returns Resolver with retry functionality
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { retry } from 'node-env-resolver/utils';
|
|
95
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
96
|
+
*
|
|
97
|
+
* // Retry up to 5 times with 2 second initial delay
|
|
98
|
+
* const resilientResolver = retry(awsSecrets(), 5, 2000);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
41
101
|
declare function retry(resolver: Resolver, maxRetries?: number, delayMs?: number): Resolver;
|
|
42
102
|
/**
|
|
43
103
|
* Wrap a resolver to strip a prefix from environment variable names
|
|
@@ -198,7 +258,7 @@ declare function withNamespace(resolver: Resolver, namespace: string): Resolver;
|
|
|
198
258
|
* process.on('SIGINT', () => stop());
|
|
199
259
|
* ```
|
|
200
260
|
*/
|
|
201
|
-
declare function watch<T>(
|
|
261
|
+
declare function watch<T>(config: Parameters<typeof resolveAsync>[0], options?: {
|
|
202
262
|
/** Callback when config changes */
|
|
203
263
|
onChange?: (config: T) => void;
|
|
204
264
|
/** Debounce delay in ms (default: 100) */
|
package/dist/utils.d.ts
CHANGED
|
@@ -13,6 +13,33 @@ interface CacheOptions {
|
|
|
13
13
|
/** Custom cache key (useful for debugging or manual cache invalidation) */
|
|
14
14
|
key?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a resolver with caching functionality
|
|
18
|
+
* Provides TTL-based caching with stale-while-revalidate support
|
|
19
|
+
*
|
|
20
|
+
* @param resolver - Resolver to wrap with caching
|
|
21
|
+
* @param options - Cache configuration options
|
|
22
|
+
* @returns Cached resolver that implements the same interface
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { cached, TTL } from 'node-env-resolver/utils';
|
|
27
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
28
|
+
*
|
|
29
|
+
* // Cache AWS secrets for 5 minutes
|
|
30
|
+
* const cachedResolver = cached(
|
|
31
|
+
* awsSecrets({ secretId: 'prod/config' }),
|
|
32
|
+
* { ttl: TTL.minutes5 }
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* // With stale-while-revalidate
|
|
36
|
+
* const resilientResolver = cached(awsSecrets(), {
|
|
37
|
+
* ttl: TTL.minutes5,
|
|
38
|
+
* maxAge: TTL.hour,
|
|
39
|
+
* staleWhileRevalidate: true
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
16
43
|
declare function cached(resolver: Resolver, options?: CacheOptions): Resolver;
|
|
17
44
|
declare const TTL: {
|
|
18
45
|
/** 30 seconds */
|
|
@@ -30,6 +57,21 @@ declare const TTL: {
|
|
|
30
57
|
/** 24 hours */
|
|
31
58
|
readonly day: number;
|
|
32
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Helper function to create AWS-friendly cache configuration
|
|
62
|
+
* Provides sensible defaults for AWS services (5min TTL, 1hr maxAge, stale-while-revalidate enabled)
|
|
63
|
+
*
|
|
64
|
+
* @param options - Cache configuration options
|
|
65
|
+
* @returns Cache options optimized for AWS services
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { awsCache } from 'node-env-resolver/utils';
|
|
70
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
71
|
+
*
|
|
72
|
+
* const resolver = cached(awsSecrets(), awsCache({ ttl: 10 * 60 * 1000 }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
33
75
|
declare function awsCache(options?: {
|
|
34
76
|
/** Cache duration for AWS secrets/parameters (default: 5 minutes) */
|
|
35
77
|
ttl?: number;
|
|
@@ -38,6 +80,24 @@ declare function awsCache(options?: {
|
|
|
38
80
|
/** Enable stale-while-revalidate for better performance (default: true) */
|
|
39
81
|
staleWhileRevalidate?: boolean;
|
|
40
82
|
}): CacheOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Wrap a resolver with retry functionality
|
|
85
|
+
* Automatically retries failed requests with exponential backoff
|
|
86
|
+
*
|
|
87
|
+
* @param resolver - Resolver to wrap with retry logic
|
|
88
|
+
* @param maxRetries - Maximum number of retry attempts (default: 3)
|
|
89
|
+
* @param delayMs - Initial delay between retries in milliseconds (default: 1000)
|
|
90
|
+
* @returns Resolver with retry functionality
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { retry } from 'node-env-resolver/utils';
|
|
95
|
+
* import { awsSecrets } from 'node-env-resolver-aws';
|
|
96
|
+
*
|
|
97
|
+
* // Retry up to 5 times with 2 second initial delay
|
|
98
|
+
* const resilientResolver = retry(awsSecrets(), 5, 2000);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
41
101
|
declare function retry(resolver: Resolver, maxRetries?: number, delayMs?: number): Resolver;
|
|
42
102
|
/**
|
|
43
103
|
* Wrap a resolver to strip a prefix from environment variable names
|
|
@@ -198,7 +258,7 @@ declare function withNamespace(resolver: Resolver, namespace: string): Resolver;
|
|
|
198
258
|
* process.on('SIGINT', () => stop());
|
|
199
259
|
* ```
|
|
200
260
|
*/
|
|
201
|
-
declare function watch<T>(
|
|
261
|
+
declare function watch<T>(config: Parameters<typeof resolveAsync>[0], options?: {
|
|
202
262
|
/** Callback when config changes */
|
|
203
263
|
onChange?: (config: T) => void;
|
|
204
264
|
/** Debounce delay in ms (default: 100) */
|