node-env-resolver 0.0.0 → 1.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 (61) hide show
  1. package/README.md +221 -85
  2. package/dist/audit.d.ts +16 -0
  3. package/dist/audit.d.ts.map +1 -0
  4. package/dist/audit.js +1 -0
  5. package/dist/audit.test.d.ts +2 -0
  6. package/dist/audit.test.d.ts.map +1 -0
  7. package/dist/builder.d.ts +146 -0
  8. package/dist/builder.d.ts.map +1 -0
  9. package/dist/builder.js +1 -0
  10. package/dist/composition.test.d.ts +7 -0
  11. package/dist/composition.test.d.ts.map +1 -0
  12. package/dist/index.d.ts +99 -4
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +5 -20
  15. package/dist/index.test.d.ts +2 -0
  16. package/dist/index.test.d.ts.map +1 -0
  17. package/dist/providers.d.ts +11 -0
  18. package/dist/providers.d.ts.map +1 -0
  19. package/dist/resolver.d.ts +17 -0
  20. package/dist/resolver.d.ts.map +1 -0
  21. package/dist/resolver.js +5 -0
  22. package/dist/resolvers.d.ts +11 -0
  23. package/dist/resolvers.d.ts.map +1 -0
  24. package/dist/resolvers.js +3 -0
  25. package/dist/standard-schema.d.ts +32 -0
  26. package/dist/standard-schema.d.ts.map +1 -0
  27. package/dist/standard-schema.js +3 -0
  28. package/dist/type-override.test.d.ts +2 -0
  29. package/dist/type-override.test.d.ts.map +1 -0
  30. package/dist/types.d.ts +66 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +0 -0
  33. package/dist/utils.d.ts +41 -0
  34. package/dist/utils.d.ts.map +1 -0
  35. package/dist/utils.js +1 -0
  36. package/dist/utils.test.d.ts +2 -0
  37. package/dist/utils.test.d.ts.map +1 -0
  38. package/dist/validators.d.ts +68 -0
  39. package/dist/validators.d.ts.map +1 -0
  40. package/dist/validators.js +1 -0
  41. package/dist/web.d.ts +51 -0
  42. package/dist/web.d.ts.map +1 -0
  43. package/dist/web.js +6 -0
  44. package/dist/zod.d.ts +51 -0
  45. package/dist/zod.d.ts.map +1 -0
  46. package/dist/zod.js +1 -0
  47. package/package.json +88 -28
  48. package/dist/chunk-AST3HVOG.js +0 -148
  49. package/dist/chunk-UQYMDWOU.js +0 -13
  50. package/dist/chunk-XC5PWSNR.js +0 -37
  51. package/dist/esm/chunk-AST3HVOG.js +0 -144
  52. package/dist/esm/chunk-UQYMDWOU.js +0 -11
  53. package/dist/esm/chunk-XC5PWSNR.js +0 -35
  54. package/dist/esm/index.js +0 -3
  55. package/dist/esm/resolve.js +0 -2
  56. package/dist/esm/resolveZod.js +0 -2
  57. package/dist/index-6c4171f8.d.ts +0 -27
  58. package/dist/resolve.d.ts +0 -6
  59. package/dist/resolve.js +0 -15
  60. package/dist/resolveZod.d.ts +0 -7
  61. package/dist/resolveZod.js +0 -15
package/README.md CHANGED
@@ -1,148 +1,284 @@
1
1
  # node-env-resolver
2
2
 
3
- This package provides an easy way to resolve environment variables for Node.js applications.
3
+ Type-safe environment variable handling with zero dependencies.
4
4
 
5
- All you need to do is provide the names of the environment variables you want to resolve, an object with defaults and the package will do the rest.
5
+ [![npm version](https://img.shields.io/npm/v/node-env-resolver)](https://www.npmjs.com/package/node-env-resolver)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install node-env-resolver
11
+ ```
12
+
13
+ ## Quick start
6
14
 
7
15
  ```ts
8
16
  import { resolve } from 'node-env-resolver';
9
17
 
10
- // using array of environment variables
11
- const resolvedEnvs = await resolve([
12
- 'NODE_ENV',
13
- 'PORT',
14
- 'DATABASE_URL',
15
- 'REDIS_URL',
16
- ]);
17
-
18
- // using object with default values
19
- const resolvedEnvs = await resolve({
20
- NODE_ENV: 'local',
18
+ const config = await resolve({
21
19
  PORT: 3000,
22
- DATABASE_URL: 'postgres://localhost:5432/mydb',
23
- REDIS_URL: '',
20
+ DATABASE_URL: 'url',
21
+ DEBUG: false,
22
+ API_KEY: 'string?'
24
23
  });
24
+
25
+ // All typed correctly
26
+ config.PORT; // number
27
+ config.DATABASE_URL; // URL object
28
+ config.DEBUG; // boolean
29
+ config.API_KEY; // string | undefined
25
30
  ```
26
31
 
27
- will both return an object with the following structure:
32
+ ## Features
28
33
 
29
- ```json
30
- {
31
- "NODE_ENV": "local",
32
- "PORT": 3000,
33
- "DATABASE_URL": "postgres://localhost:5432/mydb",
34
- "REDIS_URL": "redis://localhost:6379"
35
- }
36
- ```
34
+ - Zero runtime dependencies
35
+ - Full TypeScript type inference
36
+ - Custom validation functions
37
+ - Standard Schema compliant
38
+ - Works with any Node.js application
39
+
40
+ ## Built-in validators
37
41
 
38
- The library also supports Zod Schemas. If you provide a Zod Schema, the package will validate the resolved environment variables against the schema and throw an error if any of the environment variables are invalid.
42
+ The library includes validators for common use cases:
43
+
44
+ - **Basic**: `string`, `number`, `boolean`, `json`, `port`
45
+ - **Network**: `url`, `http`, `https`, `email`
46
+ - **Database**: `postgres`, `mysql`, `mongodb`, `redis`
47
+
48
+ ## Usage
49
+
50
+ ### Simple schema
39
51
 
40
52
  ```ts
41
- const resolvedEnvs = await resolveZod(
42
- z.object({
43
- NODE_ENV: z.string().default('local'),
44
- PORT: z.coerce.number().default(3000),
45
- DATABASE_URL: z.string().url().default('postgres://localhost:5432/mydb'),
46
- REDIS_URL: z.string().url().default('redis://localhost:6379'),
47
- })
48
- );
53
+ import { resolve } from 'node-env-resolver';
54
+
55
+ const config = await resolve({
56
+ PORT: 3000,
57
+ NODE_ENV: ['development', 'production'] as const,
58
+ DATABASE_URL: 'postgres',
59
+ DEBUG: false
60
+ });
49
61
  ```
50
62
 
51
- ## Installation
63
+ ### Optional values
52
64
 
53
- ```sh
54
- npm install node-env-resolver
65
+ Add `?` to make a value optional:
66
+
67
+ ```ts
68
+ const config = await resolve({
69
+ API_KEY: 'string?',
70
+ REDIS_URL: 'url?'
71
+ });
55
72
  ```
56
73
 
57
- ## Usage
74
+ ### Custom validators
58
75
 
59
- By default the package will resolve the following environment variables from process.env.
76
+ Write your own validation functions:
60
77
 
61
- You can configure and add additional resolvers in the second argument of the resolve function.
78
+ ```ts
79
+ const portValidator = (value: string): number => {
80
+ const port = parseInt(value, 10);
81
+ if (isNaN(port) || port < 1 || port > 65535) {
82
+ throw new Error('Port must be between 1 and 65535');
83
+ }
84
+ return port;
85
+ };
86
+
87
+ const config = await resolve({
88
+ CUSTOM_PORT: portValidator,
89
+ DATABASE_URL: 'postgres'
90
+ });
91
+ ```
62
92
 
63
- The default value of this argument is `local` which uses an in-built resolver that resolves environment variables from process.env.
93
+ ### Multiple sources
94
+
95
+ Load from different sources with explicit mapping:
64
96
 
65
97
  ```ts
66
- const resolvedEnvs = await resolve(['PORT'], 'local');
98
+ import { resolve, processEnv, dotenv } from 'node-env-resolver';
99
+
100
+ const config = await resolve.with(
101
+ [processEnv(), {
102
+ PORT: 3000,
103
+ NODE_ENV: ['development', 'production'] as const,
104
+ }],
105
+ [dotenv(), {
106
+ DATABASE_URL: 'postgres',
107
+ API_KEY: 'string',
108
+ }]
109
+ );
67
110
  ```
68
111
 
69
- Environmental variables are resolved in the order of the resolvers provided in the second argument.
112
+ Later sources override earlier ones if there are conflicts.
70
113
 
71
- For example, if you provide `['local', 'aws-secrets']` as the second argument, the package will first resolve the environment variables from process.env and then from AWS Secrets Manager.
114
+ ### With caching
72
115
 
73
- Values resolved from AWS Secrets Manager will override the values resolved from process.env.
116
+ Add TTL caching for remote sources:
74
117
 
75
- ### Adding a custom resolver
118
+ ```ts
119
+ import { resolve, cached, TTL } from 'node-env-resolver';
76
120
 
77
- You can add a custom resolver by providing a function that returns a promise that resolves to an object with the resolved environment variables.
121
+ const config = await resolve.with(
122
+ [processEnv(), { PORT: 3000 }],
123
+ [cached(customProvider, { ttl: TTL.minutes5 }), {
124
+ API_KEY: 'string',
125
+ }]
126
+ );
127
+ ```
78
128
 
79
- ```ts
80
- async function customResolver(): EnvValues {
81
- return Promise.resolve({
82
- FOO: 'bar',
83
- QUZ: 'quux',
84
- });
85
- }
129
+ ## API
86
130
 
87
- const resolvedEnvs = await resolve(['FOO', 'QUZ'], customResolver);
131
+ ### Shorthand syntax
132
+
133
+ ```ts
134
+ 'string' // Required string
135
+ 'string?' // Optional string
136
+ 'url' // URL (returns URL object)
137
+ 'email' // Email address
138
+ 'port' // Port number (1-65535)
139
+ 'json' // JSON value
140
+ 'postgres' // PostgreSQL connection string
141
+ 'mysql' // MySQL connection string
142
+ 'mongodb' // MongoDB connection string
143
+ 'redis' // Redis connection string
144
+
145
+ // Defaults
146
+ 3000 // number with default
147
+ false // boolean with default
148
+ ['dev', 'prod'] as const // enum (requires 'as const')
88
149
  ```
89
150
 
90
- which will return an object with the following structure:
151
+ ### Object syntax
91
152
 
92
- ```json
153
+ For advanced validation:
154
+
155
+ ```ts
93
156
  {
94
- "FOO": "bar",
95
- "QUZ": "quux"
157
+ type: 'string',
158
+ pattern: '^sk_[a-zA-Z0-9]+$',
159
+ min: 32,
160
+ max: 64,
161
+ optional: true,
162
+ description: 'API key'
96
163
  }
97
164
  ```
98
165
 
99
- ### AWS Secrets Manager
100
-
101
- It also has in-built support for the resolving environment variables from aws-secrets-manager.
166
+ ### Options
102
167
 
103
168
  ```ts
104
- import { resolve } from 'node-env-resolver';
105
- const resolvedEnvs = await resolve(
106
- ['NODE_ENV', 'PORT', 'DATABASE_URL', 'REDIS_URL'],
107
- 'aws-secrets'
108
- );
169
+ await resolve(schema, {
170
+ resolvers: [customResolver], // Custom resolvers
171
+ extend: [awsSecrets()], // Extend default resolvers
172
+ strict: true, // Strict mode
173
+ enableAudit: true, // Audit logging
174
+ policies: { // Security policies
175
+ enforceAllowedSources: {
176
+ DATABASE_URL: ['aws-secrets']
177
+ }
178
+ }
179
+ });
109
180
  ```
110
181
 
111
- In this case the package expects to use aws credentials from the environment variables `AWS_DEFAULT_REGION`, `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
182
+ ### Built-in resolvers
112
183
 
113
- In addition you need to provide the id of the secret in AWS Secrets Manager that contains the environment variables you want to resolve using the environmental variable `AWS_SECRET_ID`.
184
+ ```ts
185
+ import { dotenv, processEnv } from 'node-env-resolver';
114
186
 
115
- ### Mixing and matching resolver types
187
+ // Load from .env files
188
+ dotenv({ path: '.env', expand: true })
189
+
190
+ // Load from process.env
191
+ processEnv()
192
+ ```
116
193
 
117
- You can mix and match the resolver types.
194
+ ### Utility resolvers
118
195
 
119
196
  ```ts
120
- async function customResolver(): EnvValues {
121
- return Promise.resolve({
122
- FOO: 'bar',
123
- QUZ: 'quux',
124
- });
125
- }
197
+ import { cached, retry, TTL } from 'node-env-resolver';
198
+
199
+ // Cache with TTL
200
+ cached(resolver, { ttl: 300 })
201
+
202
+ // Retry on failure
203
+ retry(resolver, { attempts: 3 })
126
204
 
127
- const resolvedEnvs = await resolve(['FOO', 'QUZ'], ['local', customResolver]);
205
+ // TTL constants
206
+ TTL.minute // 60
207
+ TTL.minutes5 // 300
208
+ TTL.hour // 3600
209
+ TTL.day // 86400
128
210
  ```
129
211
 
130
- This will first resolve the environment variables from process.env and then from the custom resolver.
212
+ ## Examples
131
213
 
132
- ### Options
214
+ ### Express app
133
215
 
134
- The third argument of the resolve function is an options object.
216
+ ```ts
217
+ import { resolve } from 'node-env-resolver';
218
+
219
+ const config = await resolve({
220
+ PORT: 3000,
221
+ NODE_ENV: ['development', 'production', 'test'] as const,
222
+ DATABASE_URL: 'postgres',
223
+ REDIS_URL: 'redis?',
224
+ JWT_SECRET: 'string',
225
+ JWT_EXPIRES_IN: '7d',
226
+ ENABLE_ANALYTICS: false
227
+ });
228
+
229
+ app.listen(config.PORT, () => {
230
+ console.log(`Server running on port ${config.PORT}`);
231
+ });
232
+ ```
233
+
234
+ ### AWS Lambda
135
235
 
136
236
  ```ts
137
- {
138
- strict?: boolean;
237
+ import { resolve } from 'node-env-resolver';
238
+ import { awsSecrets } from '@node-env-resolver/aws';
239
+
240
+ const config = await resolve({
241
+ API_ENDPOINT: 'url',
242
+ TIMEOUT: 30,
243
+ LOG_LEVEL: ['debug', 'info', 'warn', 'error'] as const
244
+ }, {
245
+ extend: [awsSecrets({ secretId: 'lambda/secrets' })]
246
+ });
247
+
248
+ export const handler = async (event) => {
249
+ // Use config values
139
250
  };
140
251
  ```
141
252
 
142
- By default the package will throw an error if any of the environment variables are not found.
253
+ ## Error messages
254
+
255
+ The library provides clear, actionable error messages:
256
+
257
+ ```
258
+ ❌ Environment validation failed:
259
+ - Missing required environment variable: DATABASE_URL
260
+ - PORT: Invalid port number (1-65535)
261
+ - NODE_ENV: must be one of: development, production (got: "staging")
262
+ ```
263
+
264
+ ## TypeScript support
143
265
 
144
- You can disable this behaviour by setting the `strict` option to `false`.
266
+ Full type inference works automatically:
145
267
 
146
268
  ```ts
147
- const resolvedEnvs = await resolve(['FOO', 'QUZ'], 'local', { strict: false });
269
+ const config = await resolve({
270
+ PORT: 3000,
271
+ DATABASE_URL: 'url',
272
+ NODE_ENV: ['dev', 'prod'] as const,
273
+ DEBUG: false
274
+ });
275
+
276
+ config.PORT.toFixed(2); // ✓ number
277
+ config.DATABASE_URL.protocol; // ✓ URL object
278
+ config.NODE_ENV === 'dev'; // ✓ 'dev' | 'prod'
279
+ config.DEBUG ? 'yes' : 'no'; // ✓ boolean
148
280
  ```
281
+
282
+ ## License
283
+
284
+ MIT © [Jagvinder Singh Reehal](https://jagreehal.com)
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Audit logging for environment variable resolution
3
+ */
4
+ export type AuditEventType = 'validation_success' | 'validation_failure' | 'policy_violation' | 'env_loaded' | 'provider_error' | 'resolver_error';
5
+ export interface AuditEvent {
6
+ type: AuditEventType;
7
+ timestamp: number;
8
+ key?: string;
9
+ source?: string;
10
+ error?: string;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ export declare function logAuditEvent(event: AuditEvent): void;
14
+ export declare function getAuditLog(): readonly AuditEvent[];
15
+ export declare function clearAuditLog(): void;
16
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GACtB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,YAAY,GACZ,gBAAgB,GAChB,gBAAgB,CAAC;AAErB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAMrD;AAED,wBAAgB,WAAW,IAAI,SAAS,UAAU,EAAE,CAEnD;AAED,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
package/dist/audit.js ADDED
@@ -0,0 +1 @@
1
+ const t=[];function n(e){t.push(e),t.length>1e3&&t.shift();}function o(){return [...t]}function r(){t.length=0;}export{r as clearAuditLog,o as getAuditLog,n as logAuditEvent};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=audit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.test.d.ts","sourceRoot":"","sources":["../src/audit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * EnvBuilder - Fluent API for composing environment variables from multiple resolvers
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const config = await env({
7
+ * FOO: 'string',
8
+ * BAR: 3000,
9
+ * })
10
+ * .from(customResolver, {
11
+ * QUZ: 'string',
12
+ * })
13
+ * .resolve();
14
+ * ```
15
+ */
16
+ import type { Resolver, SimpleEnvSchema, InferSimpleSchema, ResolveOptions } from './types.js';
17
+ export type MergeSchemas<T, U> = Omit<T, keyof U> & U;
18
+ /**
19
+ * EnvBuilder class - accumulates resolvers and schemas, then resolves
20
+ */
21
+ export declare class EnvBuilder<TAccumulated extends Record<string, unknown>> {
22
+ private localSchema;
23
+ private options;
24
+ private layers;
25
+ constructor(localSchema: SimpleEnvSchema, options?: Partial<ResolveOptions>);
26
+ /**
27
+ * Add a custom provider with its schema
28
+ * Later resolvers override earlier ones (last-wins)
29
+ */
30
+ from<TNew extends SimpleEnvSchema>(resolver: Resolver, schema: TNew): EnvBuilder<MergeSchemas<TAccumulated, InferSimpleSchema<TNew>>>;
31
+ /**
32
+ * Resolve all resolvers and validate environment variables
33
+ */
34
+ resolve(): Promise<TAccumulated>;
35
+ /**
36
+ * Build default resolvers (dotenv + process.env) for local schema
37
+ */
38
+ private buildDefaultResolvers;
39
+ }
40
+ /**
41
+ * Synchronous EnvBuilder - only works with sync-capable resolvers
42
+ */
43
+ export declare class EnvBuilderSync<TAccumulated extends Record<string, unknown>> {
44
+ private localSchema;
45
+ private options;
46
+ private layers;
47
+ constructor(localSchema: SimpleEnvSchema, options?: Partial<ResolveOptions>);
48
+ /**
49
+ * Add a custom provider with its schema (sync version)
50
+ */
51
+ from<TNew extends SimpleEnvSchema>(resolver: Resolver, schema: TNew): EnvBuilderSync<MergeSchemas<TAccumulated, InferSimpleSchema<TNew>>>;
52
+ /**
53
+ * Synchronously resolve all resolvers
54
+ */
55
+ resolveSync(): TAccumulated;
56
+ private buildDefaultResolvers;
57
+ }
58
+ /**
59
+ * Create an environment builder with local schema
60
+ * Use .from() to add custom resolvers, then .resolve() to execute
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const config = await env({
65
+ * FOO: 'string',
66
+ * BAR: 3000,
67
+ * })
68
+ * .from(customResolver, { QUZ: 'string' })
69
+ * .resolve();
70
+ * ```
71
+ */
72
+ export declare function env<T extends SimpleEnvSchema>(localSchema: T, options?: Partial<ResolveOptions>): EnvBuilder<InferSimpleSchema<T>>;
73
+ /**
74
+ * Synchronous version of env() - only works with sync-capable resolvers
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const config = envSync({
79
+ * FOO: 'string',
80
+ * BAR: 3000,
81
+ * }).resolveSync();
82
+ * ```
83
+ */
84
+ export declare function envSync<T extends SimpleEnvSchema>(localSchema: T, options?: Partial<ResolveOptions>): EnvBuilderSync<InferSimpleSchema<T>>;
85
+ /**
86
+ * ResolvableBuilder - A builder that is both awaitable AND chainable
87
+ * Simple usage: await resolve({...})
88
+ * Composition: await resolve({...}).from(...).compose()
89
+ */
90
+ export declare class ResolvableBuilder<TAccumulated extends Record<string, unknown>> implements PromiseLike<TAccumulated> {
91
+ private builder;
92
+ private simpleResolve;
93
+ constructor(localSchema: SimpleEnvSchema, options?: Partial<ResolveOptions>);
94
+ /**
95
+ * Add a custom provider with its schema
96
+ */
97
+ from<TNew extends SimpleEnvSchema>(resolver: Resolver, schema: TNew): ResolvableBuilder<MergeSchemas<TAccumulated, InferSimpleSchema<TNew>>>;
98
+ /**
99
+ * Terminal operation for composition - resolves all resolvers
100
+ * Only needed when using .from() - otherwise just await directly
101
+ */
102
+ compose(): Promise<TAccumulated>;
103
+ /**
104
+ * Make this object awaitable (PromiseLike)
105
+ * Allows: const config = await resolve({...})
106
+ */
107
+ then<TResult1 = TAccumulated, TResult2 = never>(onfulfilled?: ((value: TAccumulated) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
108
+ /**
109
+ * Catch errors (Promise-like interface)
110
+ */
111
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<TAccumulated | TResult>;
112
+ /**
113
+ * Finally handler (Promise-like interface)
114
+ */
115
+ finally(onfinally?: (() => void) | null): Promise<TAccumulated>;
116
+ }
117
+ /**
118
+ * ResolvableBuilderSync - Synchronous version
119
+ * Returns the resolved value directly, but also chainable
120
+ *
121
+ * The returned object has all properties from TAccumulated plus builder methods
122
+ */
123
+ export declare class ResolvableBuilderSync<TAccumulated extends Record<string, unknown>> {
124
+ private builder;
125
+ private _resolved;
126
+ private _hasComposition;
127
+ constructor(localSchema: SimpleEnvSchema, options?: Partial<ResolveOptions>);
128
+ /**
129
+ * Add a custom provider with its schema
130
+ */
131
+ from<TNew extends SimpleEnvSchema>(resolver: Resolver, schema: TNew): ResolvableBuilderSync<MergeSchemas<TAccumulated, InferSimpleSchema<TNew>>>;
132
+ /**
133
+ * Terminal operation for composition - resolves all resolvers synchronously
134
+ * Only needed when using .from() - otherwise properties are already available
135
+ */
136
+ compose(): TAccumulated;
137
+ /**
138
+ * Convert to plain object
139
+ */
140
+ valueOf(): TAccumulated;
141
+ /**
142
+ * For JSON serialization
143
+ */
144
+ toJSON(): TAccumulated;
145
+ }
146
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EAEf,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAIpB,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;AAUtD;;GAEG;AACH,qBAAa,UAAU,CAAC,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIhE,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,OAAO;IAJjB,OAAO,CAAC,MAAM,CAAwC;gBAG5C,WAAW,EAAE,eAAe,EAC5B,OAAO,GAAE,OAAO,CAAC,cAAc,CAAM;IAG/C;;;OAGG;IACH,IAAI,CAAC,IAAI,SAAS,eAAe,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,IAAI,GACX,UAAU,CAAC,YAAY,CAAC,YAAY,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;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I,SAAS,eAAe,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,IAAI,GACX,qBAAqB,CAAC,YAAY,CAAC,YAAY,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAW7E;;;OAGG;IACH,OAAO,IAAI,YAAY;IASvB;;OAEG;IACH,OAAO,IAAI,YAAY;IAIvB;;OAEG;IACH,MAAM,IAAI,YAAY;CAGvB"}
@@ -0,0 +1 @@
1
+ import {normalizeSchema,resolveEnvInternal,resolveEnvInternalSync}from'./resolver.js';import {dotenv,processEnv}from'./resolvers.js';class v{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}async resolve(){const e=normalizeSchema(this.localSchema);for(const l of this.layers){const c=normalizeSchema(l.schema);Object.assign(e,c);}const s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),i=this.options.extend||[],n=this.options.resolvers?this.options.resolvers:[...s,...r,...i],a=this.options.policies??{};return await resolveEnvInternal(e,{...this.options,resolvers:n,policies:a,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){const e=process.env.NODE_ENV==="production",s=[];return e||s.push(dotenv({expand:true})),s.push(processEnv()),s}}class p{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){const e=normalizeSchema(this.localSchema);for(const l of this.layers){const c=normalizeSchema(l.schema);Object.assign(e,c);}const s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),i=this.options.extend||[],n=this.options.resolvers?this.options.resolvers:[...s,...r,...i],a=this.options.policies??{};return resolveEnvInternalSync(e,{...this.options,resolvers:n,policies:a,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){const e=process.env.NODE_ENV==="production",s=[];return e||s.push(dotenv({expand:true})),s.push(processEnv()),s}}function f(t,e){return new v(t,e)}function y(t,e){return new p(t,e)}class b{builder;simpleResolve=null;constructor(e,s={}){this.builder=new v(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=this.builder.resolve()),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=this.builder.resolve()),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=this.builder.resolve()),this.simpleResolve.finally(e)}}class E{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new p(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});const r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}}export{v as EnvBuilder,p as EnvBuilderSync,b as ResolvableBuilder,E as ResolvableBuilderSync,f as env,y as envSync};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * TDD Tests for Resolver Composition API
3
+ *
4
+ * Tests the new env().from().resolve() API for explicit provider composition
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=composition.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.test.d.ts","sourceRoot":"","sources":["../src/composition.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}