node-env-resolver 3.0.1 → 5.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 (112) hide show
  1. package/README.md +396 -246
  2. package/dist/audit.cjs +1 -0
  3. package/dist/audit.d.cts +29 -0
  4. package/dist/audit.d.ts +19 -6
  5. package/dist/audit.js +1 -1
  6. package/dist/builder.cjs +1 -0
  7. package/dist/builder.d.cts +149 -0
  8. package/dist/builder.d.ts +17 -14
  9. package/dist/builder.js +1 -1
  10. package/dist/chunk-4YVXFL3I.cjs +9 -0
  11. package/dist/chunk-4ZOF2PI4.cjs +1 -0
  12. package/dist/chunk-5PELJRUQ.js +1 -0
  13. package/dist/chunk-6FXCXA4R.cjs +11 -0
  14. package/dist/chunk-BFLXBLZ3.cjs +1 -0
  15. package/dist/chunk-BJ2QNYTS.js +11 -0
  16. package/dist/chunk-DIXI6MUB.js +9 -0
  17. package/dist/chunk-KIQXH265.cjs +1 -0
  18. package/dist/chunk-P3TTYVEW.js +16 -0
  19. package/dist/chunk-UCLEPPLS.cjs +16 -0
  20. package/dist/chunk-YOHHFBZN.js +1 -0
  21. package/dist/chunk-ZMRT37K3.js +1 -0
  22. package/dist/cli.cjs +1 -0
  23. package/dist/cli.d.cts +52 -0
  24. package/dist/cli.d.ts +9 -6
  25. package/dist/cli.js +1 -1
  26. package/dist/index.cjs +1 -0
  27. package/dist/index.d.cts +150 -0
  28. package/dist/index.d.ts +122 -40
  29. package/dist/index.js +1 -1
  30. package/dist/resolver.cjs +1 -0
  31. package/dist/resolver.d.cts +20 -0
  32. package/dist/resolver.d.ts +8 -5
  33. package/dist/resolver.js +1 -1
  34. package/dist/resolvers.cjs +1 -0
  35. package/dist/resolvers.d.cts +407 -0
  36. package/dist/resolvers.d.ts +289 -22
  37. package/dist/resolvers.js +1 -1
  38. package/dist/types.cjs +1 -0
  39. package/dist/types.d.cts +74 -0
  40. package/dist/types.d.ts +58 -164
  41. package/dist/types.js +1 -0
  42. package/dist/utils.cjs +1 -0
  43. package/dist/utils.d.cts +213 -0
  44. package/dist/utils.d.ts +37 -33
  45. package/dist/utils.js +1 -1
  46. package/dist/valibot.cjs +1 -0
  47. package/dist/valibot.d.cts +156 -0
  48. package/dist/valibot.d.ts +11 -8
  49. package/dist/valibot.js +1 -1
  50. package/dist/validation-types.cjs +1 -0
  51. package/dist/validation-types.d.cts +29 -0
  52. package/dist/validation-types.d.ts +4 -3
  53. package/dist/validators.cjs +2 -0
  54. package/dist/validators.d.cts +116 -0
  55. package/dist/validators.d.ts +46 -18
  56. package/dist/validators.js +2 -1
  57. package/dist/web.cjs +6 -0
  58. package/dist/web.d.cts +69 -0
  59. package/dist/web.d.ts +28 -10
  60. package/dist/web.js +4 -4
  61. package/dist/zod.cjs +1 -0
  62. package/dist/zod.d.cts +135 -0
  63. package/dist/zod.d.ts +11 -8
  64. package/dist/zod.js +1 -1
  65. package/package.json +31 -19
  66. package/dist/advanced-features.test.d.ts +0 -2
  67. package/dist/advanced-features.test.d.ts.map +0 -1
  68. package/dist/audit.d.ts.map +0 -1
  69. package/dist/audit.test.d.ts +0 -2
  70. package/dist/audit.test.d.ts.map +0 -1
  71. package/dist/builder.d.ts.map +0 -1
  72. package/dist/chunk-476ZUILE.js +0 -1
  73. package/dist/chunk-DAGPFV3V.js +0 -1
  74. package/dist/chunk-MGTYH57K.js +0 -9
  75. package/dist/chunk-MWG7FWHN.js +0 -5
  76. package/dist/chunk-QWDK3BUB.js +0 -15
  77. package/dist/chunk-VJZZNSRI.js +0 -1
  78. package/dist/cli.d.ts.map +0 -1
  79. package/dist/cli.test.d.ts +0 -2
  80. package/dist/cli.test.d.ts.map +0 -1
  81. package/dist/composition.test.d.ts +0 -7
  82. package/dist/composition.test.d.ts.map +0 -1
  83. package/dist/computed.test.d.ts +0 -2
  84. package/dist/computed.test.d.ts.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/index.test.d.ts +0 -2
  87. package/dist/index.test.d.ts.map +0 -1
  88. package/dist/nested.test.d.ts +0 -2
  89. package/dist/nested.test.d.ts.map +0 -1
  90. package/dist/performance.test.d.ts +0 -7
  91. package/dist/performance.test.d.ts.map +0 -1
  92. package/dist/priority.test.d.ts +0 -6
  93. package/dist/priority.test.d.ts.map +0 -1
  94. package/dist/providers.d.ts +0 -11
  95. package/dist/providers.d.ts.map +0 -1
  96. package/dist/resolver.d.ts.map +0 -1
  97. package/dist/resolvers.d.ts.map +0 -1
  98. package/dist/resolvers.test.d.ts +0 -2
  99. package/dist/resolvers.test.d.ts.map +0 -1
  100. package/dist/type-inference.test.d.ts +0 -2
  101. package/dist/type-inference.test.d.ts.map +0 -1
  102. package/dist/type-override.test.d.ts +0 -2
  103. package/dist/type-override.test.d.ts.map +0 -1
  104. package/dist/types.d.ts.map +0 -1
  105. package/dist/utils.d.ts.map +0 -1
  106. package/dist/utils.test.d.ts +0 -2
  107. package/dist/utils.test.d.ts.map +0 -1
  108. package/dist/valibot.d.ts.map +0 -1
  109. package/dist/validation-types.d.ts.map +0 -1
  110. package/dist/validators.d.ts.map +0 -1
  111. package/dist/web.d.ts.map +0 -1
  112. package/dist/zod.d.ts.map +0 -1
package/dist/cli.d.cts ADDED
@@ -0,0 +1,52 @@
1
+ import { Resolver } from './types.cjs';
2
+
3
+ /**
4
+ * CLI argument parser resolver
5
+ * Converts --kebab-case flags to SCREAMING_SNAKE_CASE env vars
6
+ *
7
+ * @example
8
+ * ```bash
9
+ * node app.js --port 8080 --database-url postgres://localhost --verbose
10
+ * ```
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { resolve } from 'node-env-resolver';
15
+ * import { cliArgs } from 'node-env-resolver/cli';
16
+ *
17
+ * const config = await resolveAsync(
18
+ * [cliArgs(), {
19
+ * PORT: 3000,
20
+ * DATABASE_URL: postgres(),
21
+ * VERBOSE: false
22
+ * }]
23
+ * );
24
+ * // config.PORT === 8080
25
+ * // config.DATABASE_URL === 'postgres://localhost'
26
+ * // config.VERBOSE === true
27
+ * ```
28
+ */
29
+
30
+ interface CliArgsOptions {
31
+ /** Arguments to parse (default: process.argv.slice(2)) */
32
+ argv?: string[];
33
+ /** Prefix for flags (default: '--') */
34
+ prefix?: string;
35
+ /** Convert kebab-case to SCREAMING_SNAKE_CASE (default: true) */
36
+ normalizeKeys?: boolean;
37
+ }
38
+ /**
39
+ * Parse CLI arguments as environment variables
40
+ *
41
+ * Supports:
42
+ * - `--key value` → KEY=value
43
+ * - `--key=value` → KEY=value
44
+ * - `--flag` → FLAG=true (boolean flags)
45
+ * - `--kebab-case` → KEBAB_CASE (auto-normalization)
46
+ *
47
+ * @param options Configuration options
48
+ * @returns Resolver that parses CLI arguments
49
+ */
50
+ declare function cliArgs(options?: CliArgsOptions): Resolver;
51
+
52
+ export { type CliArgsOptions, cliArgs };
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Resolver } from './types.js';
2
+
1
3
  /**
2
4
  * CLI argument parser resolver
3
5
  * Converts --kebab-case flags to SCREAMING_SNAKE_CASE env vars
@@ -12,10 +14,10 @@
12
14
  * import { resolve } from 'node-env-resolver';
13
15
  * import { cliArgs } from 'node-env-resolver/cli';
14
16
  *
15
- * const config = await resolve.with(
17
+ * const config = await resolveAsync(
16
18
  * [cliArgs(), {
17
19
  * PORT: 3000,
18
- * DATABASE_URL: 'postgres',
20
+ * DATABASE_URL: postgres(),
19
21
  * VERBOSE: false
20
22
  * }]
21
23
  * );
@@ -24,8 +26,8 @@
24
26
  * // config.VERBOSE === true
25
27
  * ```
26
28
  */
27
- import type { Resolver } from './types';
28
- export interface CliArgsOptions {
29
+
30
+ interface CliArgsOptions {
29
31
  /** Arguments to parse (default: process.argv.slice(2)) */
30
32
  argv?: string[];
31
33
  /** Prefix for flags (default: '--') */
@@ -45,5 +47,6 @@ export interface CliArgsOptions {
45
47
  * @param options Configuration options
46
48
  * @returns Resolver that parses CLI arguments
47
49
  */
48
- export declare function cliArgs(options?: CliArgsOptions): Resolver;
49
- //# sourceMappingURL=cli.d.ts.map
50
+ declare function cliArgs(options?: CliArgsOptions): Resolver;
51
+
52
+ export { type CliArgsOptions, cliArgs };
package/dist/cli.js CHANGED
@@ -1 +1 @@
1
- import'./chunk-476ZUILE.js';function f(g={}){let{argv:s=process.argv.slice(2),prefix:n="--",normalizeKeys:i=true}=g,l=()=>{let t={};for(let r=0;r<s.length;r++){let c=s[r];if(!c.startsWith(n))continue;let e=c.slice(n.length);if(e.includes("=")){let[p,u]=e.split("=",2);e=i?p.replace(/-/g,"_").toUpperCase():p,t[e]=u;continue}let a=i?e.replace(/-/g,"_").toUpperCase():e,o=s[r+1];!o||o.startsWith(n)?t[a]="true":(t[a]=o,r++);}return t};return {name:"cli-args",load(){return Promise.resolve(l())},loadSync(){return l()}}}export{f as cliArgs};
1
+ import'./chunk-5PELJRUQ.js';function f(g={}){let{argv:s=process.argv.slice(2),prefix:n="--",normalizeKeys:i=true}=g,l=()=>{let t={};for(let r=0;r<s.length;r++){let c=s[r];if(!c.startsWith(n))continue;let e=c.slice(n.length);if(e.includes("=")){let[p,u]=e.split("=",2);e=i?p.replace(/-/g,"_").toUpperCase():p,t[e]=u;continue}let a=i?e.replace(/-/g,"_").toUpperCase():e,o=s[r+1];!o||o.startsWith(n)?t[a]="true":(t[a]=o,r++);}return t};return {name:"cli-args",load(){return Promise.resolve(l())},loadSync(){return l()}}}export{f as cliArgs};
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var chunk6FXCXA4R_cjs=require('./chunk-6FXCXA4R.cjs');require('./chunk-4YVXFL3I.cjs');var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs'),chunkBFLXBLZ3_cjs=require('./chunk-BFLXBLZ3.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunk6FXCXA4R_cjs.a}});Object.defineProperty(exports,"resolve",{enumerable:true,get:function(){return chunk6FXCXA4R_cjs.b}});Object.defineProperty(exports,"resolveAsync",{enumerable:true,get:function(){return chunk6FXCXA4R_cjs.c}});Object.defineProperty(exports,"safeResolve",{enumerable:true,get:function(){return chunk6FXCXA4R_cjs.d}});Object.defineProperty(exports,"safeResolveAsync",{enumerable:true,get:function(){return chunk6FXCXA4R_cjs.e}});Object.defineProperty(exports,"clearAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.d}});Object.defineProperty(exports,"getAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.c}});Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunkBFLXBLZ3_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunkBFLXBLZ3_cjs.a}});
@@ -0,0 +1,150 @@
1
+ import { SimpleEnvSchema, Resolver, ResolveOptions, InferSimpleValue, SyncResolver } from './types.cjs';
2
+ export { AsyncResolver, EnvDefinition, EnvSchema, InferResolveResult, InferSchema, InferSimpleSchema, InferType, PolicyOptions, Provenance, SimpleEnvValue, Validator, isAsyncOnlyResolver, isSyncResolver } from './types.cjs';
3
+ export { SafeResolveResult as SafeResolveResultWithIssues, ValidationIssue } from './validation-types.cjs';
4
+ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.cjs';
5
+
6
+ /**
7
+ * Type-safe environment variable resolver
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { resolve } from 'node-env-resolver';
12
+ * import { postgres, string } from 'node-env-resolver/resolvers';
13
+ *
14
+ * const config = resolve({
15
+ * PORT: 3000, // number with default
16
+ * DATABASE_URL: postgres(), // required PostgreSQL URL
17
+ * NODE_ENV: ['development', 'production'], // enum
18
+ * DEBUG: false, // boolean with default
19
+ * API_KEY: string({optional: true}), // optional string
20
+ * });
21
+ * ```
22
+ */
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
+ interface SafeResolveResult<T> {
30
+ success: true;
31
+ data: T;
32
+ }
33
+ interface SafeResolveError {
34
+ success: false;
35
+ error: string;
36
+ errors?: string[];
37
+ }
38
+ type SafeResolveResultType<T> = SafeResolveResult<T> | SafeResolveError;
39
+ declare function resolve<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): {
40
+ [K in keyof T]: InferSimpleValue<T[K]>;
41
+ };
42
+ declare function resolve<T extends SimpleEnvSchema>(tuple: readonly [SyncResolver, T] | [SyncResolver, T], options?: Partial<ResolveOptions>): {
43
+ [K in keyof T]: InferSimpleValue<T[K]>;
44
+ };
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]>;
47
+ };
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]>;
50
+ };
51
+ /**
52
+ * Resolve environment variables asynchronously (supports all resolver types - both sync and async)
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { resolveAsync } from 'node-env-resolver';
57
+ * import { postgres, string } from 'node-env-resolver/resolvers';
58
+ * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
59
+ *
60
+ * // Works with async-only resolvers
61
+ * const config = await resolveAsync([
62
+ * awsSecrets(),
63
+ * { PORT: 3000, DATABASE_URL: postgres(), API_KEY: string() }
64
+ * ]);
65
+ *
66
+ * // 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 });
71
+ *
72
+ * // Multiple resolvers - supports unlimited tuples!
73
+ * const config = await resolveAsync(
74
+ * [dotenv(), { PORT: 3000 }],
75
+ * [awsSecrets(), { DATABASE_URL: postgres() }],
76
+ * { strict: true }
77
+ * );
78
+ * ```
79
+ */
80
+ declare function resolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<{
81
+ [K in keyof T]: InferSimpleValue<T[K]>;
82
+ }>;
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]>;
91
+ }>;
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]>;
94
+ }>;
95
+ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | [SyncResolver, T], ...rest: ([SyncResolver, T] | Partial<ResolveOptions>)[]): SafeResolveResultType<{
96
+ [K in keyof T]: InferSimpleValue<T[K]>;
97
+ }>;
98
+ /**
99
+ * Safe async resolve (doesn't throw, returns result object)
100
+ * Supports both sync and async resolvers
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * import { safeResolveAsync } from 'node-env-resolver';
105
+ * import { postgres } from 'node-env-resolver/resolvers';
106
+ * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
107
+ *
108
+ * // Works with async resolvers
109
+ * const result = await safeResolveAsync([
110
+ * awsSecrets({ region: 'us-east-1' }),
111
+ * { PORT: 3000, DATABASE_URL: postgres() }
112
+ * ]);
113
+ *
114
+ * // Also works with sync resolvers
115
+ * const result = await safeResolveAsync([
116
+ * processEnv(), // Sync resolver works fine
117
+ * { PORT: 3000 }
118
+ * ]);
119
+ *
120
+ * // Multiple resolvers - supports unlimited tuples!
121
+ * const result = await safeResolveAsync(
122
+ * [dotenv(), { PORT: 3000 }],
123
+ * [awsSecrets(), { DATABASE_URL: postgres() }],
124
+ * { strict: true }
125
+ * );
126
+ *
127
+ * if (result.success) {
128
+ * console.log(result.data.PORT); // Type-safe access
129
+ * } else {
130
+ * console.error(result.error); // Detailed error message
131
+ * }
132
+ * ```
133
+ */
134
+ declare function safeResolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
135
+ [K in keyof T]: InferSimpleValue<T[K]>;
136
+ }>>;
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
+
150
+ export { ResolveOptions, Resolver, type SafeResolveError, type SafeResolveResult, type SafeResolveResultType, SimpleEnvSchema, SyncResolver, processEnv, resolve, resolveAsync, safeResolve, safeResolveAsync };
package/dist/index.d.ts CHANGED
@@ -1,68 +1,150 @@
1
+ import { SimpleEnvSchema, Resolver, ResolveOptions, InferSimpleValue, SyncResolver } from './types.js';
2
+ export { AsyncResolver, EnvDefinition, EnvSchema, InferResolveResult, InferSchema, InferSimpleSchema, InferType, PolicyOptions, Provenance, SimpleEnvValue, Validator, isAsyncOnlyResolver, isSyncResolver } from './types.js';
3
+ export { SafeResolveResult as SafeResolveResultWithIssues, ValidationIssue } from './validation-types.js';
4
+ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.js';
5
+
1
6
  /**
2
7
  * Type-safe environment variable resolver
3
8
  *
4
9
  * @example
5
10
  * ```typescript
6
11
  * import { resolve } from 'node-env-resolver';
12
+ * import { postgres, string } from 'node-env-resolver/resolvers';
7
13
  *
8
- * const config = await resolve({
14
+ * const config = resolve({
9
15
  * PORT: 3000, // number with default
10
- * DATABASE_URL: 'url', // required secret url
16
+ * DATABASE_URL: postgres(), // required PostgreSQL URL
11
17
  * NODE_ENV: ['development', 'production'], // enum
12
18
  * DEBUG: false, // boolean with default
13
- * API_KEY: 'string?', // optional string
19
+ * API_KEY: string({optional: true}), // optional string
14
20
  * });
15
21
  * ```
16
22
  */
17
- import type { Resolver, ResolveOptions, SimpleEnvSchema, InferSimpleSchema } from './types';
18
- export type { EnvDefinition, EnvSchema, Resolver, ResolveOptions, Provenance, PolicyOptions, SimpleEnvValue, SimpleEnvSchema, InferType, InferSchema, InferSimpleSchema, } from './types';
19
- export type { ValidationIssue, SafeResolveResult as SafeResolveResultWithIssues } from './validation-types';
20
- export { getAuditLog, clearAuditLog, type AuditEvent, type AuditEventType } from './audit';
21
- import { type MergeSchemas } from './builder';
22
- export declare function processEnv(): Resolver;
23
- type FilterOptions<T extends ReadonlyArray<unknown>> = T extends readonly [infer First, ...infer Rest] ? First extends readonly [Resolver, SimpleEnvSchema] ? readonly [First, ...FilterOptions<Rest>] : FilterOptions<Rest> : readonly [];
24
- type MergeTupleSchemas<T extends ReadonlyArray<unknown>> = T extends readonly [infer First, ...infer Rest] ? First extends readonly [Resolver, infer Schema extends SimpleEnvSchema] ? Rest extends ReadonlyArray<unknown> ? Rest['length'] extends 0 ? InferSimpleSchema<Schema> : MergeSchemas<InferSimpleSchema<Schema>, MergeTupleSchemas<Rest>> : InferSimpleSchema<Schema> : never : Record<string, never>;
25
- export interface SafeResolveResult<T> {
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
+ interface SafeResolveResult<T> {
26
30
  success: true;
27
31
  data: T;
28
32
  }
29
- export interface SafeResolveError {
33
+ interface SafeResolveError {
30
34
  success: false;
31
35
  error: string;
32
36
  errors?: string[];
33
37
  }
34
- export type SafeResolveResultType<T> = SafeResolveResult<T> | SafeResolveError;
38
+ type SafeResolveResultType<T> = SafeResolveResult<T> | SafeResolveError;
39
+ declare function resolve<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): {
40
+ [K in keyof T]: InferSimpleValue<T[K]>;
41
+ };
42
+ declare function resolve<T extends SimpleEnvSchema>(tuple: readonly [SyncResolver, T] | [SyncResolver, T], options?: Partial<ResolveOptions>): {
43
+ [K in keyof T]: InferSimpleValue<T[K]>;
44
+ };
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]>;
47
+ };
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]>;
50
+ };
35
51
  /**
36
- * Resolve environment variables with smart defaults
52
+ * Resolve environment variables asynchronously (supports all resolver types - both sync and async)
37
53
  *
38
54
  * @example
39
55
  * ```typescript
40
- * // Simple usage - local vars only
41
- * const config = await resolve({
42
- * PORT: 3000, // number with default
43
- * DATABASE_URL: 'url', // required secret url
44
- * NODE_ENV: ['dev', 'prod'], // enum
45
- * FEATURE_FLAG: 'string?', // optional string
46
- * });
56
+ * import { resolveAsync } from 'node-env-resolver';
57
+ * import { postgres, string } from 'node-env-resolver/resolvers';
58
+ * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
59
+ *
60
+ * // Works with async-only resolvers
61
+ * const config = await resolveAsync([
62
+ * awsSecrets(),
63
+ * { PORT: 3000, DATABASE_URL: postgres(), API_KEY: string() }
64
+ * ]);
65
+ *
66
+ * // 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 });
47
71
  *
48
- * // Multiple resolvers with resolve.with()
49
- * const config = await resolve.with(
50
- * [processEnv(), { PORT: 3000, NODE_ENV: ['dev', 'prod'] as const }],
51
- * [awsSecrets({ region: 'us-east-1' }), { DATABASE_URL: 'url' }],
52
- * [databaseResolver, { FEATURE_FLAGS: 'json' }]
72
+ * // Multiple resolvers - supports unlimited tuples!
73
+ * const config = await resolveAsync(
74
+ * [dotenv(), { PORT: 3000 }],
75
+ * [awsSecrets(), { DATABASE_URL: postgres() }],
76
+ * { strict: true }
53
77
  * );
54
78
  * ```
55
79
  */
56
- declare function resolveImpl<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): InferSimpleSchema<T>;
57
- declare namespace resolveImpl {
58
- var _a: <const T extends ReadonlyArray<readonly [Resolver, SimpleEnvSchema] | Partial<ResolveOptions>>>(...args: T) => Promise<MergeTupleSchemas<FilterOptions<T>>>;
59
- export { _a as with };
60
- }
61
- declare function safeResolveImpl<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): SafeResolveResultType<InferSimpleSchema<T>>;
62
- declare namespace safeResolveImpl {
63
- var _a: <const T extends ReadonlyArray<readonly [Resolver, SimpleEnvSchema] | Partial<ResolveOptions>>>(...args: T) => Promise<SafeResolveResultType<MergeTupleSchemas<FilterOptions<T>>>>;
64
- export { _a as with };
65
- }
66
- export declare const resolve: typeof resolveImpl;
67
- export declare const safeResolve: typeof safeResolveImpl;
68
- //# sourceMappingURL=index.d.ts.map
80
+ declare function resolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<{
81
+ [K in keyof T]: InferSimpleValue<T[K]>;
82
+ }>;
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]>;
91
+ }>;
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]>;
94
+ }>;
95
+ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | [SyncResolver, T], ...rest: ([SyncResolver, T] | Partial<ResolveOptions>)[]): SafeResolveResultType<{
96
+ [K in keyof T]: InferSimpleValue<T[K]>;
97
+ }>;
98
+ /**
99
+ * Safe async resolve (doesn't throw, returns result object)
100
+ * Supports both sync and async resolvers
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * import { safeResolveAsync } from 'node-env-resolver';
105
+ * import { postgres } from 'node-env-resolver/resolvers';
106
+ * import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
107
+ *
108
+ * // Works with async resolvers
109
+ * const result = await safeResolveAsync([
110
+ * awsSecrets({ region: 'us-east-1' }),
111
+ * { PORT: 3000, DATABASE_URL: postgres() }
112
+ * ]);
113
+ *
114
+ * // Also works with sync resolvers
115
+ * const result = await safeResolveAsync([
116
+ * processEnv(), // Sync resolver works fine
117
+ * { PORT: 3000 }
118
+ * ]);
119
+ *
120
+ * // Multiple resolvers - supports unlimited tuples!
121
+ * const result = await safeResolveAsync(
122
+ * [dotenv(), { PORT: 3000 }],
123
+ * [awsSecrets(), { DATABASE_URL: postgres() }],
124
+ * { strict: true }
125
+ * );
126
+ *
127
+ * if (result.success) {
128
+ * console.log(result.data.PORT); // Type-safe access
129
+ * } else {
130
+ * console.error(result.error); // Detailed error message
131
+ * }
132
+ * ```
133
+ */
134
+ declare function safeResolveAsync<T extends SimpleEnvSchema>(tuple: readonly [Resolver, T] | [Resolver, T], options?: Partial<ResolveOptions>): Promise<SafeResolveResultType<{
135
+ [K in keyof T]: InferSimpleValue<T[K]>;
136
+ }>>;
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
+
150
+ export { ResolveOptions, Resolver, type SafeResolveError, type SafeResolveResult, type SafeResolveResultType, SimpleEnvSchema, SyncResolver, processEnv, resolve, resolveAsync, safeResolve, safeResolveAsync };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{a as processEnv,b as resolve,c as safeResolve}from'./chunk-MWG7FWHN.js';export{c as clearAuditLog,b as getAuditLog}from'./chunk-DAGPFV3V.js';import'./chunk-MGTYH57K.js';import'./chunk-VJZZNSRI.js';import'./chunk-476ZUILE.js';
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';
@@ -0,0 +1 @@
1
+ 'use strict';var chunk4YVXFL3I_cjs=require('./chunk-4YVXFL3I.cjs');require('./chunk-4ZOF2PI4.cjs'),require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"normalizeSchema",{enumerable:true,get:function(){return chunk4YVXFL3I_cjs.a}});Object.defineProperty(exports,"resolveEnvInternal",{enumerable:true,get:function(){return chunk4YVXFL3I_cjs.b}});Object.defineProperty(exports,"resolveEnvInternalSync",{enumerable:true,get:function(){return chunk4YVXFL3I_cjs.c}});
@@ -0,0 +1,20 @@
1
+ import { SimpleEnvSchema, EnvSchema, Resolver, ResolveOptions } from './types.cjs';
2
+
3
+ /**
4
+ * Internal resolver functions - extracted for use by both old and new APIs
5
+ */
6
+
7
+ /**
8
+ * Convert simplified schema to standard EnvSchema
9
+ */
10
+ declare function normalizeSchema(schema: SimpleEnvSchema): EnvSchema;
11
+ /**
12
+ * Internal resolver - used by both old resolve() and new env() APIs
13
+ */
14
+ declare function resolveEnvInternal<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Promise<Record<string, unknown>>;
15
+ /**
16
+ * Internal sync resolver
17
+ */
18
+ declare function resolveEnvInternalSync<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Record<string, unknown>;
19
+
20
+ export { normalizeSchema, resolveEnvInternal, resolveEnvInternalSync };
@@ -1,17 +1,20 @@
1
+ import { SimpleEnvSchema, EnvSchema, Resolver, ResolveOptions } from './types.js';
2
+
1
3
  /**
2
4
  * Internal resolver functions - extracted for use by both old and new APIs
3
5
  */
4
- import type { Resolver, EnvSchema, SimpleEnvSchema, ResolveOptions } from './types';
6
+
5
7
  /**
6
8
  * Convert simplified schema to standard EnvSchema
7
9
  */
8
- export declare function normalizeSchema(schema: SimpleEnvSchema): EnvSchema;
10
+ declare function normalizeSchema(schema: SimpleEnvSchema): EnvSchema;
9
11
  /**
10
12
  * Internal resolver - used by both old resolve() and new env() APIs
11
13
  */
12
- export declare function resolveEnvInternal<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Promise<Record<string, unknown>>;
14
+ declare function resolveEnvInternal<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Promise<Record<string, unknown>>;
13
15
  /**
14
16
  * Internal sync resolver
15
17
  */
16
- export declare function resolveEnvInternalSync<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Record<string, unknown>;
17
- //# sourceMappingURL=resolver.d.ts.map
18
+ declare function resolveEnvInternalSync<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Record<string, unknown>;
19
+
20
+ export { normalizeSchema, resolveEnvInternal, resolveEnvInternalSync };
package/dist/resolver.js CHANGED
@@ -1 +1 @@
1
- export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-MGTYH57K.js';import'./chunk-VJZZNSRI.js';import'./chunk-476ZUILE.js';
1
+ export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-DIXI6MUB.js';import'./chunk-YOHHFBZN.js';import'./chunk-5PELJRUQ.js';
@@ -0,0 +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}});