node-env-resolver 6.6.0 → 6.7.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 (114) hide show
  1. package/README.md +186 -11
  2. package/dist/audit.d.ts +7 -8
  3. package/dist/audit.d.ts.map +1 -0
  4. package/dist/builder.cjs +1 -1
  5. package/dist/builder.d.ts +9 -12
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +1 -1
  8. package/dist/chunk-3TXO5AOZ.cjs +3 -0
  9. package/dist/chunk-4CLWNKB5.js +1 -0
  10. package/dist/chunk-4DUWYBNJ.cjs +6 -0
  11. package/dist/chunk-6NSX37SO.js +6 -0
  12. package/dist/chunk-BITH5LSH.js +3 -0
  13. package/dist/{chunk-DIJNUFGZ.cjs → chunk-G5HNCCR6.cjs} +3 -3
  14. package/dist/chunk-IP6POQCY.cjs +1 -0
  15. package/dist/{chunk-ZSM2NDX5.js → chunk-JVRRDD3Y.js} +3 -3
  16. package/dist/chunk-KHEBSYFP.js +9 -0
  17. package/dist/chunk-NHXSZY2U.cjs +9 -0
  18. package/dist/chunk-NKISCWWB.js +1 -0
  19. package/dist/chunk-UZ7HKTYL.cjs +1 -0
  20. package/dist/cli/bin.cjs +67 -27
  21. package/dist/cli/bin.d.ts +11 -0
  22. package/dist/cli/bin.d.ts.map +1 -0
  23. package/dist/cli/bin.js +67 -27
  24. package/dist/cli/scan.d.ts +24 -0
  25. package/dist/cli/scan.d.ts.map +1 -0
  26. package/dist/cli.d.ts +4 -7
  27. package/dist/cli.d.ts.map +1 -0
  28. package/dist/debug.d.ts +142 -0
  29. package/dist/debug.d.ts.map +1 -0
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.ts +19 -61
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +1 -1
  34. package/dist/inspect.d.ts +63 -0
  35. package/dist/inspect.d.ts.map +1 -0
  36. package/dist/process-env.d.ts +32 -0
  37. package/dist/process-env.d.ts.map +1 -0
  38. package/dist/provider-kit.d.ts +7 -8
  39. package/dist/provider-kit.d.ts.map +1 -0
  40. package/dist/providers.d.ts +49 -0
  41. package/dist/providers.d.ts.map +1 -0
  42. package/dist/references.d.ts +5 -0
  43. package/dist/references.d.ts.map +1 -0
  44. package/dist/resolver.cjs +1 -1
  45. package/dist/resolver.d.ts +16 -8
  46. package/dist/resolver.d.ts.map +1 -0
  47. package/dist/resolver.js +1 -1
  48. package/dist/resolvers.cjs +1 -1
  49. package/dist/resolvers.d.ts +13 -31
  50. package/dist/resolvers.d.ts.map +1 -0
  51. package/dist/resolvers.js +1 -1
  52. package/dist/runtime/index.cjs +1 -1
  53. package/dist/runtime/index.d.ts +8 -108
  54. package/dist/runtime/index.d.ts.map +1 -0
  55. package/dist/runtime/index.js +1 -1
  56. package/dist/runtime/patch-console.d.ts +23 -0
  57. package/dist/runtime/patch-console.d.ts.map +1 -0
  58. package/dist/runtime/redactor.d.ts +22 -0
  59. package/dist/runtime/redactor.d.ts.map +1 -0
  60. package/dist/runtime/response.d.ts +59 -0
  61. package/dist/runtime/response.d.ts.map +1 -0
  62. package/dist/security.d.ts +49 -0
  63. package/dist/security.d.ts.map +1 -0
  64. package/dist/sensitivity.d.ts +34 -0
  65. package/dist/sensitivity.d.ts.map +1 -0
  66. package/dist/types.d.ts +150 -1
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/utils.cjs +1 -1
  69. package/dist/utils.d.ts +19 -21
  70. package/dist/utils.d.ts.map +1 -0
  71. package/dist/utils.js +1 -1
  72. package/dist/valibot.cjs +1 -1
  73. package/dist/valibot.d.ts +9 -11
  74. package/dist/valibot.d.ts.map +1 -0
  75. package/dist/valibot.js +1 -1
  76. package/dist/validation-types.d.ts +3 -4
  77. package/dist/validation-types.d.ts.map +1 -0
  78. package/dist/validators.cjs +2 -2
  79. package/dist/validators.d.ts +59 -44
  80. package/dist/validators.d.ts.map +1 -0
  81. package/dist/validators.js +2 -2
  82. package/dist/web.cjs +3 -3
  83. package/dist/web.d.ts +8 -10
  84. package/dist/web.d.ts.map +1 -0
  85. package/dist/web.js +3 -3
  86. package/dist/zod.cjs +1 -1
  87. package/dist/zod.d.ts +9 -11
  88. package/dist/zod.d.ts.map +1 -0
  89. package/dist/zod.js +1 -1
  90. package/package.json +15 -23
  91. package/dist/audit.d.cts +0 -52
  92. package/dist/builder.d.cts +0 -149
  93. package/dist/chunk-3EWCMDFP.js +0 -9
  94. package/dist/chunk-4QOKRJ3F.cjs +0 -1
  95. package/dist/chunk-DYFRO3NM.cjs +0 -9
  96. package/dist/chunk-K4NIC5T3.js +0 -9
  97. package/dist/chunk-WKIPEKF6.js +0 -1
  98. package/dist/chunk-WVMDTD6J.cjs +0 -9
  99. package/dist/cli/bin.d.cts +0 -1
  100. package/dist/cli.d.cts +0 -52
  101. package/dist/index.d.cts +0 -220
  102. package/dist/provider-kit.d.cts +0 -50
  103. package/dist/resolver.d.cts +0 -20
  104. package/dist/resolvers.d.cts +0 -190
  105. package/dist/runtime/index.d.cts +0 -161
  106. package/dist/types--RcOnfdl.d.cts +0 -284
  107. package/dist/types--RcOnfdl.d.ts +0 -284
  108. package/dist/types.d.cts +0 -1
  109. package/dist/utils.d.cts +0 -327
  110. package/dist/valibot.d.cts +0 -143
  111. package/dist/validation-types.d.cts +0 -29
  112. package/dist/validators.d.cts +0 -933
  113. package/dist/web.d.cts +0 -71
  114. package/dist/zod.d.cts +0 -122
@@ -1,933 +0,0 @@
1
- import { V as Validator } from './types--RcOnfdl.cjs';
2
-
3
- /**
4
- * Shared validation functions for advanced environment variable types
5
- * Import these when you need advanced validation beyond basic string/number/boolean
6
- *
7
- * These validators are tree-shakeable - only included if you use advanced types like:
8
- * 'postgres', 'mysql', 'mongodb', 'redis', 'http', 'https', 'url', 'email', 'port', 'json', 'date', 'timestamp'
9
- */
10
-
11
- /**
12
- * Result of a validation operation
13
- */
14
- interface ValidationResult {
15
- /** Whether the validation passed */
16
- valid: boolean;
17
- /** Error message if validation failed */
18
- error?: string;
19
- /** Parsed/transformed value if validation succeeded */
20
- value?: unknown;
21
- }
22
- /**
23
- * Validate PostgreSQL connection string
24
- * Checks for postgres:// or postgresql:// URLs
25
- *
26
- * @param value - Connection string to validate
27
- * @returns Validation result with success/error information
28
- */
29
- declare function validatePostgres(value: string): ValidationResult;
30
- /**
31
- * Validate MySQL connection string
32
- * Checks for mysql:// URLs
33
- *
34
- * @param value - Connection string to validate
35
- * @returns Validation result with success/error information
36
- */
37
- declare function validateMysql(value: string): ValidationResult;
38
- /**
39
- * Validate MongoDB connection string
40
- * Supports mongodb:// and mongodb+srv:// with replica sets
41
- *
42
- * @param value - Connection string to validate
43
- * @returns Validation result with success/error information
44
- */
45
- declare function validateMongodb(value: string): ValidationResult;
46
- /**
47
- * Validate Redis connection string
48
- * Supports redis:// and rediss:// (TLS)
49
- *
50
- * @param value - Connection string to validate
51
- * @returns Validation result with success/error information
52
- */
53
- declare function validateRedis(value: string): ValidationResult;
54
- /**
55
- * Validate generic URL (with protocol whitelist for security)
56
- * Only allows safe protocols: http, https, ws, wss, ftp, ftps, file, postgres, mysql, mongodb, redis
57
- *
58
- * @param value - URL to validate
59
- * @returns Validation result with success/error information
60
- */
61
- declare function validateUrl(value: string): ValidationResult;
62
- /**
63
- * Validate email address using RFC-compliant regex
64
- * Also checks maximum length (254 characters)
65
- *
66
- * @param value - Email address to validate
67
- * @returns Validation result with success/error information
68
- */
69
- declare function validateEmail(value: string): ValidationResult;
70
- /**
71
- * Validate port number (1-65535)
72
- *
73
- * @param value - Port number to validate
74
- * @returns Validation result with success/error information
75
- */
76
- declare function validatePort(value: string): ValidationResult;
77
- /**
78
- * Validate number
79
- * Converts string to number and checks if it's a valid number
80
- *
81
- * @param value - Number string to validate
82
- * @returns Validation result with success/error information
83
- */
84
- declare function validateNumber(value: string): ValidationResult;
85
- /**
86
- * Validate boolean
87
- * Accepts: true/1/yes/on, false/0/no/off
88
- *
89
- * @param value - Boolean string to validate
90
- * @returns Validation result with success/error information
91
- */
92
- declare function validateBoolean(value: string): ValidationResult;
93
- /**
94
- * Validate and normalize date string to ISO 8601
95
- * Accepts various formats and coerces them to YYYY-MM-DD or ISO 8601 datetime
96
- *
97
- * @param value - Date string to validate
98
- * @returns Validation result with success/error information
99
- */
100
- declare function validateDate(value: string): ValidationResult;
101
- /**
102
- * Validate Unix timestamp (seconds since epoch)
103
- * Validates positive integers representing Unix timestamps
104
- *
105
- * @param value - Timestamp string to validate
106
- * @returns Validation result with success/error information
107
- */
108
- declare function validateTimestamp(value: string): ValidationResult;
109
- /**
110
- * Validate and parse time duration (Go-style: 5s, 2h, 30m, etc.)
111
- * Returns milliseconds
112
- * Supports formats like: 5s, 2h, 30m, 1.5h, 2h30m, etc.
113
- *
114
- * @param value - Duration string to validate
115
- * @returns Validation result with parsed value in milliseconds
116
- */
117
- declare function validateDuration(value: string): ValidationResult & {
118
- value?: number;
119
- };
120
- /**
121
- * Read and validate file content
122
- * Reads the file at the path specified in the value
123
- *
124
- * @param value - File path to read
125
- * @param key - Optional env var key name (for error messages)
126
- * @returns ValidationResult with file content or error
127
- */
128
- declare function validateFile(value: string, key?: string): ValidationResult;
129
- /**
130
- * HTTP/HTTPS URL validator function factory
131
- * Creates a validator that accepts both http:// and https:// URLs
132
- *
133
- * @param opts - Validation options
134
- * @returns HTTP URL validator
135
- */
136
- declare function http<Opts extends {
137
- default?: string;
138
- optional?: boolean;
139
- } = Record<string, never>>(opts?: Opts): Opts extends {
140
- optional: true;
141
- } ? Validator<string> & {
142
- optional: true;
143
- default?: Opts['default'];
144
- } : Validator<string> & {
145
- optional?: Opts['optional'];
146
- default?: Opts['default'];
147
- };
148
- /**
149
- * JSON validator function factory
150
- * Creates a validator that parses JSON strings
151
- *
152
- * @param opts - Validation options
153
- * @returns JSON validator
154
- */
155
- declare function json<Opts extends {
156
- default?: unknown;
157
- optional?: boolean;
158
- } = Record<string, never>>(opts?: Opts): Opts extends {
159
- optional: true;
160
- } ? Validator<unknown> & {
161
- optional: true;
162
- default?: Opts['default'];
163
- } : Validator<unknown> & {
164
- optional?: Opts['optional'];
165
- default?: Opts['default'];
166
- };
167
- /**
168
- * String validator with length and pattern validation
169
- *
170
- * @param opts Validation options
171
- * @returns String validator
172
- *
173
- * @example
174
- * ```ts
175
- * import { string } from 'node-env-resolver/validators';
176
- *
177
- * const config = resolve({
178
- * API_KEY: string({ min: 32, pattern: '^[a-zA-Z0-9]+$' }),
179
- * NAME: string({ optional: true, max: 100 }),
180
- * DESCRIPTION: string({ allowEmpty: true })
181
- * });
182
- * ```
183
- */
184
- declare function string<Opts extends {
185
- /** Default value if not provided */
186
- default?: string;
187
- /** Make the field optional */
188
- optional?: boolean;
189
- /** Minimum string length */
190
- min?: number;
191
- /** Maximum string length */
192
- max?: number;
193
- /** Allow empty strings */
194
- allowEmpty?: boolean;
195
- /** Regex pattern to validate against */
196
- pattern?: string;
197
- } = Record<string, never>>(opts?: Opts): Opts extends {
198
- optional: true;
199
- } ? Validator<string> & {
200
- optional: true;
201
- default?: Opts['default'];
202
- } : Validator<string> & {
203
- optional?: Opts['optional'];
204
- default?: Opts['default'];
205
- };
206
- /**
207
- * Number validator with range validation
208
- *
209
- * @param opts Validation options
210
- * @returns Number validator
211
- *
212
- * @example
213
- * ```ts
214
- * import { number } from 'node-env-resolver/validators';
215
- *
216
- * const config = resolve({
217
- * PORT: number({ min: 1, max: 65535 }),
218
- * TIMEOUT: number({ default: 5000, optional: true }),
219
- * MAX_RETRIES: number({ min: 0, max: 10 })
220
- * });
221
- * ```
222
- */
223
- declare function number<Opts extends {
224
- /** Default value if not provided */
225
- default?: number;
226
- /** Make the field optional */
227
- optional?: boolean;
228
- /** Minimum number value */
229
- min?: number;
230
- /** Maximum number value */
231
- max?: number;
232
- } = Record<string, never>>(opts?: Opts): Opts extends {
233
- optional: true;
234
- } ? Validator<number> & {
235
- optional: true;
236
- default?: Opts['default'];
237
- } : Validator<number> & {
238
- optional?: Opts['optional'];
239
- default?: Opts['default'];
240
- };
241
- /**
242
- * Boolean validator with string coercion
243
- * Accepts: true/1/yes/on, false/0/no/off
244
- *
245
- * @param opts Validation options
246
- * @returns Boolean validator
247
- *
248
- * @example
249
- * ```ts
250
- * import { boolean } from 'node-env-resolver/validators';
251
- *
252
- * const config = resolve({
253
- * DEBUG: boolean({ default: false }),
254
- * ENABLE_LOGGING: boolean(),
255
- * FEATURE_FLAG: boolean({ optional: true })
256
- * });
257
- * ```
258
- */
259
- declare function boolean<Opts extends {
260
- /** Default value if not provided */
261
- default?: boolean;
262
- /** Make the field optional */
263
- optional?: boolean;
264
- } = Record<string, never>>(opts?: Opts): Opts extends {
265
- optional: true;
266
- } ? Validator<boolean> & {
267
- optional: true;
268
- default?: Opts['default'];
269
- } : Validator<boolean> & {
270
- optional?: Opts['optional'];
271
- default?: Opts['default'];
272
- };
273
- /**
274
- * URL validator using the built-in URL constructor
275
- *
276
- * @param opts Validation options
277
- * @returns URL validator
278
- *
279
- * @example
280
- * ```ts
281
- * import { url } from 'node-env-resolver/validators';
282
- *
283
- * const config = resolve({
284
- * API_URL: url(),
285
- * WEBHOOK_URL: url({ optional: true }),
286
- * BASE_URL: url({ default: 'https://api.example.com' })
287
- * });
288
- * ```
289
- */
290
- declare function url<Opts extends {
291
- /** Default value if not provided */
292
- default?: string;
293
- /** Make the field optional */
294
- optional?: boolean;
295
- } = Record<string, never>>(opts?: Opts): Opts extends {
296
- optional: true;
297
- } ? Validator<string> & {
298
- optional: true;
299
- default?: Opts['default'];
300
- } : Validator<string> & {
301
- optional?: Opts['optional'];
302
- default?: Opts['default'];
303
- };
304
- /**
305
- * Email address validator using regex pattern
306
- *
307
- * @param opts Validation options
308
- * @returns Email validator
309
- *
310
- * @example
311
- * ```ts
312
- * import { email } from 'node-env-resolver/validators';
313
- *
314
- * const config = resolve({
315
- * ADMIN_EMAIL: email(),
316
- * CONTACT_EMAIL: email({ optional: true }),
317
- * SUPPORT_EMAIL: email({ default: 'support@example.com' })
318
- * });
319
- * ```
320
- */
321
- declare function email<Opts extends {
322
- /** Default value if not provided */
323
- default?: string;
324
- /** Make the field optional */
325
- optional?: boolean;
326
- } = Record<string, never>>(opts?: Opts): Opts extends {
327
- optional: true;
328
- } ? Validator<string> & {
329
- optional: true;
330
- default?: Opts['default'];
331
- } : Validator<string> & {
332
- optional?: Opts['optional'];
333
- default?: Opts['default'];
334
- };
335
- /**
336
- * Port number validator (1-65535)
337
- *
338
- * @param opts Validation options
339
- * @returns Port validator
340
- *
341
- * @example
342
- * ```ts
343
- * import { port } from 'node-env-resolver/validators';
344
- *
345
- * const config = resolve({
346
- * PORT: port({ default: 3000 }),
347
- * REDIS_PORT: port(),
348
- * MONITORING_PORT: port({ optional: true })
349
- * });
350
- * ```
351
- */
352
- declare function port<Opts extends {
353
- /** Default value if not provided */
354
- default?: number;
355
- /** Make the field optional */
356
- optional?: boolean;
357
- } = Record<string, never>>(opts?: Opts): Opts extends {
358
- optional: true;
359
- } ? Validator<number> & {
360
- optional: true;
361
- default?: Opts['default'];
362
- } : Validator<number> & {
363
- optional?: Opts['optional'];
364
- default?: Opts['default'];
365
- };
366
- /**
367
- * PostgreSQL connection string validator
368
- * Validates postgres:// and postgresql:// URLs
369
- *
370
- * @param opts Validation options
371
- * @returns PostgreSQL URL validator
372
- *
373
- * @example
374
- * ```ts
375
- * import { postgres } from 'node-env-resolver/validators';
376
- *
377
- * const config = resolve({
378
- * DATABASE_URL: postgres(),
379
- * BACKUP_DB_URL: postgres({ optional: true }),
380
- * TEST_DATABASE_URL: postgres({ default: 'postgres://localhost:5432/test' })
381
- * });
382
- * ```
383
- */
384
- declare function postgres<Opts extends {
385
- /** Default value if not provided */
386
- default?: string;
387
- /** Make the field optional */
388
- optional?: boolean;
389
- } = Record<string, never>>(opts?: Opts): Opts extends {
390
- optional: true;
391
- } ? Validator<string> & {
392
- optional: true;
393
- default?: Opts['default'];
394
- } : Validator<string> & {
395
- optional?: Opts['optional'];
396
- default?: Opts['default'];
397
- };
398
- /**
399
- * MySQL connection string validator
400
- * Validates mysql:// URLs
401
- *
402
- * @param opts Validation options
403
- * @returns MySQL URL validator
404
- *
405
- * @example
406
- * ```ts
407
- * import { mysql } from 'node-env-resolver/validators';
408
- *
409
- * const config = resolve({
410
- * MYSQL_URL: mysql(),
411
- * READ_REPLICA_URL: mysql({ optional: true }),
412
- * TEST_MYSQL_URL: mysql({ default: 'mysql://localhost:3306/test' })
413
- * });
414
- * ```
415
- */
416
- declare function mysql<Opts extends {
417
- /** Default value if not provided */
418
- default?: string;
419
- /** Make the field optional */
420
- optional?: boolean;
421
- } = Record<string, never>>(opts?: Opts): Opts extends {
422
- optional: true;
423
- } ? Validator<string> & {
424
- optional: true;
425
- default?: Opts['default'];
426
- } : Validator<string> & {
427
- optional?: Opts['optional'];
428
- default?: Opts['default'];
429
- };
430
- /**
431
- * MongoDB connection string validator
432
- * Validates mongodb:// and mongodb+srv:// URLs
433
- *
434
- * @param opts Validation options
435
- * @returns MongoDB URL validator
436
- *
437
- * @example
438
- * ```ts
439
- * import { mongodb } from 'node-env-resolver/validators';
440
- *
441
- * const config = resolve({
442
- * MONGODB_URL: mongodb(),
443
- * MONGODB_ATLAS_URL: mongodb({ optional: true }),
444
- * TEST_MONGODB_URL: mongodb({ default: 'mongodb://localhost:27017/test' })
445
- * });
446
- * ```
447
- */
448
- declare function mongodb<Opts extends {
449
- /** Default value if not provided */
450
- default?: string;
451
- /** Make the field optional */
452
- optional?: boolean;
453
- } = Record<string, never>>(opts?: Opts): Opts extends {
454
- optional: true;
455
- } ? Validator<string> & {
456
- optional: true;
457
- default?: Opts['default'];
458
- } : Validator<string> & {
459
- optional?: Opts['optional'];
460
- default?: Opts['default'];
461
- };
462
- /**
463
- * Redis connection string validator
464
- * Validates redis:// and rediss:// URLs
465
- *
466
- * @param opts Validation options
467
- * @returns Redis URL validator
468
- *
469
- * @example
470
- * ```ts
471
- * import { redis } from 'node-env-resolver/validators';
472
- *
473
- * const config = resolve({
474
- * REDIS_URL: redis(),
475
- * REDIS_CACHE_URL: redis({ optional: true }),
476
- * TEST_REDIS_URL: redis({ default: 'redis://localhost:6379/0' })
477
- * });
478
- * ```
479
- */
480
- declare function redis<Opts extends {
481
- /** Default value if not provided */
482
- default?: string;
483
- /** Make the field optional */
484
- optional?: boolean;
485
- } = Record<string, never>>(opts?: Opts): Opts extends {
486
- optional: true;
487
- } ? Validator<string> & {
488
- optional: true;
489
- default?: Opts['default'];
490
- } : Validator<string> & {
491
- optional?: Opts['optional'];
492
- default?: Opts['default'];
493
- };
494
- /**
495
- * HTTPS-only URL validator
496
- * Only accepts URLs starting with https://
497
- *
498
- * @param opts Validation options
499
- * @returns HTTPS URL validator
500
- *
501
- * @example
502
- * ```ts
503
- * import { https } from 'node-env-resolver/validators';
504
- *
505
- * const config = resolve({
506
- * API_URL: https(),
507
- * WEBHOOK_URL: https({ optional: true }),
508
- * SECURE_URL: https({ default: 'https://api.example.com' })
509
- * });
510
- * ```
511
- */
512
- declare function https<Opts extends {
513
- /** Default value if not provided */
514
- default?: string;
515
- /** Make the field optional */
516
- optional?: boolean;
517
- } = Record<string, never>>(opts?: Opts): Opts extends {
518
- optional: true;
519
- } ? Validator<string> & {
520
- optional: true;
521
- default?: Opts['default'];
522
- } : Validator<string> & {
523
- optional?: Opts['optional'];
524
- default?: Opts['default'];
525
- };
526
- /**
527
- * String array validator
528
- * Splits comma-separated values into an array
529
- *
530
- * @param opts Validation options
531
- * @returns String array validator
532
- *
533
- * @example
534
- * ```ts
535
- * import { stringArray } from 'node-env-resolver/validators';
536
- *
537
- * const config = resolve({
538
- * ALLOWED_ORIGINS: stringArray(), // "a.com,b.com,c.com"
539
- * FEATURES: stringArray({ separator: ':' }), // "feature1:feature2"
540
- * TAGS: stringArray({ optional: true })
541
- * });
542
- * ```
543
- */
544
- declare function stringArray<Opts extends {
545
- /** Default value if not provided */
546
- default?: string[];
547
- /** Make the field optional */
548
- optional?: boolean;
549
- /** Separator character (default: ',') */
550
- separator?: string;
551
- } = Record<string, never>>(opts?: Opts): Opts extends {
552
- optional: true;
553
- } ? Validator<string[]> & {
554
- optional: true;
555
- default?: Opts['default'];
556
- } : Validator<string[]> & {
557
- optional?: Opts['optional'];
558
- default?: Opts['default'];
559
- };
560
- /**
561
- * Number array validator
562
- * Splits comma-separated values into an array of numbers
563
- *
564
- * @param opts Validation options
565
- * @returns Number array validator
566
- *
567
- * @example
568
- * ```ts
569
- * import { numberArray } from 'node-env-resolver/validators';
570
- *
571
- * const config = resolve({
572
- * PORTS: numberArray(), // "3000,3001,3002"
573
- * TIMEOUTS: numberArray({ separator: ':' }), // "1000:2000:3000"
574
- * RETRY_COUNTS: numberArray({ optional: true })
575
- * });
576
- * ```
577
- */
578
- declare function numberArray<Opts extends {
579
- /** Default value if not provided */
580
- default?: number[];
581
- /** Make the field optional */
582
- optional?: boolean;
583
- /** Separator character (default: ',') */
584
- separator?: string;
585
- } = Record<string, never>>(opts?: Opts): Opts extends {
586
- optional: true;
587
- } ? Validator<number[]> & {
588
- optional: true;
589
- default?: Opts['default'];
590
- } : Validator<number[]> & {
591
- optional?: Opts['optional'];
592
- default?: Opts['default'];
593
- };
594
- /**
595
- * URL array validator
596
- * Splits comma-separated URLs into an array with URL validation
597
- *
598
- * @param opts Validation options
599
- * @returns URL array validator
600
- *
601
- * @example
602
- * ```ts
603
- * import { urlArray } from 'node-env-resolver/validators';
604
- *
605
- * const config = resolve({
606
- * API_ENDPOINTS: urlArray(), // "https://api1.com,https://api2.com"
607
- * WEBHOOK_URLS: urlArray({ separator: ':' }),
608
- * BACKUP_URLS: urlArray({ optional: true })
609
- * });
610
- * ```
611
- */
612
- declare function urlArray<Opts extends {
613
- /** Default value if not provided */
614
- default?: string[];
615
- /** Make the field optional */
616
- optional?: boolean;
617
- /** Separator character (default: ',') */
618
- separator?: string;
619
- } = Record<string, never>>(opts?: Opts): Opts extends {
620
- optional: true;
621
- } ? Validator<string[]> & {
622
- optional: true;
623
- default?: Opts['default'];
624
- } : Validator<string[]> & {
625
- optional?: Opts['optional'];
626
- default?: Opts['default'];
627
- };
628
- /**
629
- * One-of validator for enum-like values
630
- * Validates that the value is one of the provided options
631
- *
632
- * @param values Array of allowed values
633
- * @param opts Validation options
634
- * @returns One-of validator
635
- *
636
- * @example
637
- * ```ts
638
- * import { oneOf } from 'node-env-resolver/validators';
639
- *
640
- * const config = resolve({
641
- * NODE_ENV: oneOf(['development', 'production', 'test'] as const),
642
- * LOG_LEVEL: oneOf(['debug', 'info', 'warn', 'error'] as const),
643
- * MODE: oneOf(['dev', 'prod'] as const, { optional: true })
644
- * });
645
- * ```
646
- */
647
- declare function oneOf<T extends readonly (string | number)[], Opts extends {
648
- /** Default value if not provided */
649
- default?: T[number];
650
- /** Make the field optional */
651
- optional?: boolean;
652
- } = Record<string, never>>(values: T, opts?: Opts): Opts extends {
653
- optional: true;
654
- } ? Validator<T[number]> & {
655
- optional: true;
656
- default?: Opts['default'];
657
- } : Validator<T[number]> & {
658
- optional?: Opts['optional'];
659
- default?: Opts['default'];
660
- };
661
- /**
662
- * Enum validator - validates that a value is one of the allowed values
663
- * This is an alias for `oneOf()` with a more descriptive name for enum validation
664
- *
665
- * @param values Array of allowed values
666
- * @param opts Validation options (optional, default)
667
- * @returns Enum validator
668
- *
669
- * @example
670
- * ```ts
671
- * import { enumOf } from 'node-env-resolver/validators';
672
- *
673
- * const config = resolve({
674
- * NODE_ENV: enumOf(['development', 'production', 'test'] as const),
675
- * LOG_LEVEL: enumOf(['error', 'warn', 'info', 'debug'] as const, { optional: true }),
676
- * PROTOCOL: enumOf(['http', 'grpc'] as const, { default: 'http' }),
677
- * });
678
- * // config.NODE_ENV is typed as 'development' | 'production' | 'test'
679
- * // config.LOG_LEVEL is typed as 'error' | 'warn' | 'info' | 'debug' | undefined
680
- * // config.PROTOCOL is typed as 'http' | 'grpc'
681
- * ```
682
- */
683
- declare function enumOf<T extends readonly (string | number)[], Opts extends {
684
- /** Default value if not provided */
685
- default?: T[number];
686
- /** Make the field optional */
687
- optional?: boolean;
688
- } = Record<string, never>>(values: T, opts?: Opts): Opts extends {
689
- optional: true;
690
- } ? Validator<T[number]> & {
691
- optional: true;
692
- default?: Opts['default'];
693
- } : Validator<T[number]> & {
694
- optional?: Opts['optional'];
695
- default?: Opts['default'];
696
- };
697
- /**
698
- * Marks an array enum as optional
699
- * Allows the array literal syntax to support optional values
700
- *
701
- * @param values Array of enum values to mark as optional
702
- * @returns The same array with optional metadata attached
703
- *
704
- * @example
705
- * ```ts
706
- * import { optional } from 'node-env-resolver/validators';
707
- *
708
- * const config = resolve({
709
- * // Required enum (must be set to one of these values)
710
- * NODE_ENV: ['development', 'production', 'test'] as const,
711
- *
712
- * // Optional enum (can be undefined or one of these values)
713
- * PROTOCOL: optional(['http', 'grpc'] as const),
714
- * LOG_LEVEL: optional(['error', 'warn', 'info', 'debug'] as const),
715
- * });
716
- * // config.NODE_ENV is typed as 'development' | 'production' | 'test'
717
- * // config.PROTOCOL is typed as 'http' | 'grpc' | undefined
718
- * // config.LOG_LEVEL is typed as 'error' | 'warn' | 'info' | 'debug' | undefined
719
- * ```
720
- */
721
- declare function optional<T extends readonly (string | number)[]>(values: T): T & {
722
- __optional: true;
723
- };
724
- /**
725
- * Duration validator with time unit parsing
726
- * Converts duration strings to milliseconds
727
- * Supports: s (seconds), m (minutes), h (hours), d (days)
728
- *
729
- * @param opts Validation options
730
- * @returns Duration validator
731
- *
732
- * @example
733
- * ```ts
734
- * import { duration } from 'node-env-resolver/validators';
735
- *
736
- * const config = resolve({
737
- * CACHE_TTL: duration(), // "5m" → 300000ms
738
- * TIMEOUT: duration({ default: 30000 }), // "30s" → 30000ms
739
- * RETRY_DELAY: duration({ optional: true }) // "2h" → 7200000ms
740
- * });
741
- * ```
742
- */
743
- declare function duration<Opts extends {
744
- /** Default value if not provided */
745
- default?: number;
746
- /** Make the field optional */
747
- optional?: boolean;
748
- } = Record<string, never>>(opts?: Opts): Opts extends {
749
- optional: true;
750
- } ? Validator<number> & {
751
- optional: true;
752
- default?: Opts['default'];
753
- } : Validator<number> & {
754
- optional?: Opts['optional'];
755
- default?: Opts['default'];
756
- };
757
- /**
758
- * File content validator
759
- * Reads the content of a file from the filesystem
760
- *
761
- * @param opts Validation options
762
- * @returns File content validator
763
- *
764
- * @example
765
- * ```ts
766
- * import { file } from 'node-env-resolver/validators';
767
- *
768
- * const config = resolve({
769
- * SSL_KEY: file(), // Reads content of SSL_KEY file path
770
- * CONFIG_FILE: file({ optional: true }),
771
- * DEFAULT_CERT: file({ default: './certs/default.pem' })
772
- * });
773
- * ```
774
- */
775
- declare function file<Opts extends {
776
- /** Default value if not provided */
777
- default?: string;
778
- /** Make the field optional */
779
- optional?: boolean;
780
- /** Base directory for secrets (Docker/K8s) */
781
- secretsDir?: string;
782
- } = Record<string, never>>(opts?: Opts): Opts extends {
783
- optional: true;
784
- } ? Validator<string> & {
785
- optional: true;
786
- default?: Opts['default'];
787
- secretsDir?: Opts['secretsDir'];
788
- } : Validator<string> & {
789
- optional?: Opts['optional'];
790
- default?: Opts['default'];
791
- secretsDir?: Opts['secretsDir'];
792
- };
793
- /**
794
- * Secret value validator
795
- * A generic validator for secret values with no specific validation
796
- *
797
- * @param opts Validation options
798
- * @returns Secret validator
799
- *
800
- * @example
801
- * ```ts
802
- * import { secret } from 'node-env-resolver/validators';
803
- *
804
- * const config = resolve({
805
- * API_SECRET: secret(),
806
- * ENCRYPTION_KEY: secret({ optional: true }),
807
- * JWT_SECRET: secret({ default: 'fallback-secret' })
808
- * });
809
- * ```
810
- */
811
- declare function secret<Opts extends {
812
- /** Default value if not provided */
813
- default?: string;
814
- /** Make the field optional */
815
- optional?: boolean;
816
- } = Record<string, never>>(opts?: Opts): Opts extends {
817
- optional: true;
818
- } ? Validator<string> & {
819
- optional: true;
820
- default?: Opts['default'];
821
- } : Validator<string> & {
822
- optional?: Opts['optional'];
823
- default?: Opts['default'];
824
- };
825
- /**
826
- * Custom validator function
827
- * Allows you to define your own validation logic
828
- *
829
- * @param validator Custom validation function
830
- * @param opts Validation options
831
- * @returns Custom validator
832
- *
833
- * @example
834
- * ```ts
835
- * import { custom } from 'node-env-resolver/validators';
836
- *
837
- * const config = resolve({
838
- * CUSTOM_PORT: custom((value) => {
839
- * const port = parseInt(value, 10);
840
- * if (port < 1000 || port > 9999) {
841
- * throw new Error('Port must be between 1000-9999');
842
- * }
843
- * return port;
844
- * }),
845
- * API_VERSION: custom((value) => {
846
- * if (!value.match(/^v\d+\.\d+$/)) {
847
- * throw new Error('Invalid API version format');
848
- * }
849
- * return value;
850
- * }, { optional: true })
851
- * });
852
- * ```
853
- */
854
- declare function custom<T = unknown, Opts extends {
855
- /** Default value if not provided */
856
- default?: T;
857
- /** Make the field optional */
858
- optional?: boolean;
859
- } = Record<string, never>>(validator: (value: string) => T, opts?: Opts): Opts extends {
860
- optional: true;
861
- } ? Validator<T> & {
862
- optional: true;
863
- default?: Opts['default'];
864
- } : Validator<T> & {
865
- optional?: Opts['optional'];
866
- default?: Opts['default'];
867
- };
868
- /**
869
- * ISO 8601 date validator
870
- * Validates dates in YYYY-MM-DD or YYYY-MM-DDTHH:mm:ssZ format
871
- *
872
- * @param opts Validation options
873
- * @returns Date validator
874
- *
875
- * @example
876
- * ```ts
877
- * import { date } from 'node-env-resolver/validators';
878
- *
879
- * const config = resolve({
880
- * START_DATE: date(), // "2024-01-01" or "2024-01-01T12:00:00Z"
881
- * END_DATE: date({ optional: true }),
882
- * DEFAULT_DATE: date({ default: '2024-01-01' })
883
- * });
884
- * ```
885
- */
886
- declare function date<Opts extends {
887
- /** Default value if not provided */
888
- default?: string;
889
- /** Make the field optional */
890
- optional?: boolean;
891
- } = Record<string, never>>(opts?: Opts): Opts extends {
892
- optional: true;
893
- } ? Validator<string> & {
894
- optional: true;
895
- default?: Opts['default'];
896
- } : Validator<string> & {
897
- optional?: Opts['optional'];
898
- default?: Opts['default'];
899
- };
900
- /**
901
- * Unix timestamp validator
902
- * Validates positive integers representing Unix timestamps
903
- *
904
- * @param opts Validation options
905
- * @returns Timestamp validator
906
- *
907
- * @example
908
- * ```ts
909
- * import { timestamp } from 'node-env-resolver/validators';
910
- *
911
- * const config = resolve({
912
- * CREATED_AT: timestamp(), // "1640995200"
913
- * UPDATED_AT: timestamp({ optional: true }),
914
- * EXPIRES_AT: timestamp({ default: 1640995200 })
915
- * });
916
- * ```
917
- */
918
- declare function timestamp<Opts extends {
919
- /** Default value if not provided */
920
- default?: number;
921
- /** Make the field optional */
922
- optional?: boolean;
923
- } = Record<string, never>>(opts?: Opts): Opts extends {
924
- optional: true;
925
- } ? Validator<number> & {
926
- optional: true;
927
- default?: Opts['default'];
928
- } : Validator<number> & {
929
- optional?: Opts['optional'];
930
- default?: Opts['default'];
931
- };
932
-
933
- export { type ValidationResult, boolean, custom, date, duration, email, enumOf, file, http, https, json, mongodb, mysql, number, numberArray, oneOf, optional, port, postgres, redis, secret, string, stringArray, timestamp, url, urlArray, validateBoolean, validateDate, validateDuration, validateEmail, validateFile, validateMongodb, validateMysql, validateNumber, validatePort, validatePostgres, validateRedis, validateTimestamp, validateUrl };