ultraenv 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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2058 -0
  3. package/bin/ultraenv.mjs +3 -0
  4. package/dist/chunk-2USZPWLZ.js +288 -0
  5. package/dist/chunk-3UV2QNJL.js +270 -0
  6. package/dist/chunk-3VYXPTYV.js +179 -0
  7. package/dist/chunk-4XUYMRK5.js +366 -0
  8. package/dist/chunk-5G2DU52U.js +189 -0
  9. package/dist/chunk-6KS56D6E.js +172 -0
  10. package/dist/chunk-AWN6ADV7.js +328 -0
  11. package/dist/chunk-CHVO6NWI.js +203 -0
  12. package/dist/chunk-CIFMBJ4H.js +3975 -0
  13. package/dist/chunk-GC7RXHLA.js +253 -0
  14. package/dist/chunk-HFXQGJY3.js +445 -0
  15. package/dist/chunk-IGFVP24Q.js +91 -0
  16. package/dist/chunk-IKPTKALB.js +78 -0
  17. package/dist/chunk-JB7RKV3C.js +66 -0
  18. package/dist/chunk-MNVFG7H4.js +611 -0
  19. package/dist/chunk-MSXMESFP.js +1910 -0
  20. package/dist/chunk-N5PAV4NM.js +127 -0
  21. package/dist/chunk-NBOABPHM.js +158 -0
  22. package/dist/chunk-OMAOROL4.js +49 -0
  23. package/dist/chunk-R7PZRSZ7.js +105 -0
  24. package/dist/chunk-TE7HPLA6.js +73 -0
  25. package/dist/chunk-TMT5KCO3.js +101 -0
  26. package/dist/chunk-UEWYFN6A.js +189 -0
  27. package/dist/chunk-WMHN5RW2.js +128 -0
  28. package/dist/chunk-XC65ORJ5.js +70 -0
  29. package/dist/chunk-YMMP4VQL.js +118 -0
  30. package/dist/chunk-YN2KGTCB.js +33 -0
  31. package/dist/chunk-YTICOB5M.js +65 -0
  32. package/dist/chunk-YVWLXFUT.js +107 -0
  33. package/dist/ci-check-sync-VBMSVWIV.js +48 -0
  34. package/dist/ci-scan-24MT5XGS.js +41 -0
  35. package/dist/ci-setup-C2NKEFRD.js +135 -0
  36. package/dist/ci-validate-7AW24LSQ.js +57 -0
  37. package/dist/cli/index.cjs +9217 -0
  38. package/dist/cli/index.d.cts +9 -0
  39. package/dist/cli/index.d.ts +9 -0
  40. package/dist/cli/index.js +339 -0
  41. package/dist/comparator-RDKX3OI7.js +13 -0
  42. package/dist/completion-MW35C2XO.js +168 -0
  43. package/dist/config-O5YRQP5Z.js +13 -0
  44. package/dist/debug-PTPXAF3K.js +131 -0
  45. package/dist/declaration-LEME4AFZ.js +10 -0
  46. package/dist/doctor-FZAUPKHS.js +129 -0
  47. package/dist/envs-compare-5K3HESX5.js +49 -0
  48. package/dist/envs-create-2XXHXMGA.js +58 -0
  49. package/dist/envs-list-NQM5252B.js +59 -0
  50. package/dist/envs-switch-6L2AQYID.js +50 -0
  51. package/dist/envs-validate-FL73Q76T.js +89 -0
  52. package/dist/fs-VH7ATUS3.js +31 -0
  53. package/dist/generator-LFZBMZZS.js +14 -0
  54. package/dist/git-BZS4DPAI.js +30 -0
  55. package/dist/help-3XJBXEHE.js +121 -0
  56. package/dist/index.cjs +12907 -0
  57. package/dist/index.d.cts +2562 -0
  58. package/dist/index.d.ts +2562 -0
  59. package/dist/index.js +3212 -0
  60. package/dist/init-Y7JQ2KYJ.js +146 -0
  61. package/dist/install-hook-SKXIV6NV.js +111 -0
  62. package/dist/json-schema-I26YNQBH.js +10 -0
  63. package/dist/key-manager-O3G55WPU.js +25 -0
  64. package/dist/middleware/express.cjs +103 -0
  65. package/dist/middleware/express.d.cts +115 -0
  66. package/dist/middleware/express.d.ts +115 -0
  67. package/dist/middleware/express.js +8 -0
  68. package/dist/middleware/fastify.cjs +91 -0
  69. package/dist/middleware/fastify.d.cts +111 -0
  70. package/dist/middleware/fastify.d.ts +111 -0
  71. package/dist/middleware/fastify.js +8 -0
  72. package/dist/module-IDIZPP4M.js +10 -0
  73. package/dist/protect-NCWPM6VC.js +161 -0
  74. package/dist/scan-TRLY36TT.js +58 -0
  75. package/dist/schema/index.cjs +4074 -0
  76. package/dist/schema/index.d.cts +1244 -0
  77. package/dist/schema/index.d.ts +1244 -0
  78. package/dist/schema/index.js +152 -0
  79. package/dist/sync-TMHMTLH2.js +186 -0
  80. package/dist/typegen-SQOSXBWM.js +80 -0
  81. package/dist/validate-IOAM5HWS.js +100 -0
  82. package/dist/vault-decrypt-U6HJZNBV.js +111 -0
  83. package/dist/vault-diff-B3ZOQTWI.js +132 -0
  84. package/dist/vault-encrypt-GUSLCSKS.js +112 -0
  85. package/dist/vault-init-GUBOTOUL.js +106 -0
  86. package/dist/vault-rekey-DAHT7JCN.js +132 -0
  87. package/dist/vault-status-GDLRU2OK.js +90 -0
  88. package/dist/vault-verify-CD76FJSF.js +102 -0
  89. package/package.json +106 -0
@@ -0,0 +1,1244 @@
1
+ /** Discriminated union parse result — success or failure */
2
+ type ParseResult<T> = {
3
+ readonly success: true;
4
+ readonly value: T;
5
+ } | {
6
+ readonly success: false;
7
+ readonly error: string;
8
+ };
9
+ /** Configuration for conditional schema application */
10
+ interface ConditionalConfig {
11
+ /** Function that checks whether this schema should apply */
12
+ check: (env: Record<string, unknown>) => boolean;
13
+ }
14
+ /** Metadata attached to every schema builder */
15
+ interface SchemaMetadata {
16
+ /** Human-readable description for documentation */
17
+ description?: string;
18
+ /** Example value for documentation */
19
+ example?: string;
20
+ /** Whether this value is a secret (should be masked in logs) */
21
+ isSecret: boolean;
22
+ /** Whether this value is deprecated */
23
+ isDeprecated: boolean;
24
+ /** Deprecation message */
25
+ deprecationMessage?: string;
26
+ /** Alternative variable names that should map to this schema */
27
+ aliases: readonly string[];
28
+ /** Whether the field is required */
29
+ required: boolean;
30
+ /** Whether a default value has been set */
31
+ hasDefault: boolean;
32
+ /** The raw default value (before parsing) */
33
+ rawDefaultValue?: string;
34
+ /** Runtime type name for error messages */
35
+ typeName: string;
36
+ /** Conditional configuration */
37
+ conditional?: ConditionalConfig;
38
+ }
39
+ /** Prevent TypeScript from inferring a more specific type */
40
+ type NoInfer<T> = T extends infer U ? U : never;
41
+ /** Extract the output type from a SchemaBuilder */
42
+ type ExtractType$1<S> = S extends SchemaBuilder<infer T> ? T : never;
43
+ /** Check if a schema is optional */
44
+ type IsOptional<S> = S extends {
45
+ __optional: true;
46
+ } ? true : false;
47
+ /** Extract the default value type from a schema */
48
+ type ExtractDefault<S> = S extends {
49
+ __default: infer D;
50
+ } ? D : never;
51
+ /** Resolve the final output type of a schema */
52
+ type ResolveOutput$1<S> = S extends {
53
+ __optional: true;
54
+ } ? ExtractType$1<S> | undefined : S extends {
55
+ __default: infer D;
56
+ } ? D : ExtractType$1<S>;
57
+ /**
58
+ * Core chainable schema builder with full TypeScript type inference.
59
+ *
60
+ * @typeParam TOutput - The output type after parsing and validation
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const portSchema = t.number().port().default(3000);
65
+ * // portSchema._parse("8080") → { success: true, value: 8080 }
66
+ * // portSchema._parse("abc") → { success: false, error: "..." }
67
+ * ```
68
+ */
69
+ declare class SchemaBuilder<TOutput> {
70
+ /** Internal parser function: string → ParseResult<TOutput> */
71
+ protected _parser: (raw: string) => ParseResult<TOutput>;
72
+ /** Ordered list of validator functions: value → error message or null */
73
+ protected _validators: ReadonlyArray<(value: TOutput) => string | null>;
74
+ /** Ordered list of transform functions applied after validation */
75
+ protected _transforms: ReadonlyArray<(value: TOutput) => TOutput>;
76
+ /** Schema metadata */
77
+ protected _meta: SchemaMetadata;
78
+ constructor(parser: (raw: string) => ParseResult<TOutput>, typeName: string);
79
+ /**
80
+ * Parse a raw string value into the output type.
81
+ * Runs the parser, then all validators and transforms.
82
+ */
83
+ _parse(raw: string): ParseResult<TOutput>;
84
+ /**
85
+ * Validate an already-parsed value against all registered validators.
86
+ * Returns an error message string, or null if validation passes.
87
+ */
88
+ _validate(value: TOutput): string | null;
89
+ /** Get a readonly view of the schema metadata */
90
+ get meta(): Readonly<SchemaMetadata>;
91
+ /** Whether this schema is effectively optional (marked optional or has default) */
92
+ get isOptional(): boolean;
93
+ /** The runtime type name string */
94
+ get typeName(): string;
95
+ /** Get the default value, parsing it if a raw default exists */
96
+ getDefaultValue(): TOutput | undefined;
97
+ /** Return a composed reference to this builder for chaining */
98
+ get chain(): SchemaBuilder<TOutput>;
99
+ /** Add a human-readable description */
100
+ description(desc: string): this;
101
+ /** Set an example value for documentation */
102
+ example(ex: NoInfer<TOutput>): this;
103
+ /**
104
+ * Mark this field as optional. The output type becomes `TOutput | undefined`.
105
+ */
106
+ optional(): this & {
107
+ __optional: true;
108
+ };
109
+ /**
110
+ * Mark this field as required.
111
+ */
112
+ required(): this;
113
+ /**
114
+ * Set a default value. The field becomes effectively optional.
115
+ * The output type remains `TOutput` (guaranteed by the default).
116
+ */
117
+ default(value: NoInfer<TOutput>): this & {
118
+ __default: NoInfer<TOutput>;
119
+ };
120
+ /** Mark this field as a secret (masks in logs) */
121
+ secret(): this;
122
+ /** Mark this field as deprecated with a message */
123
+ deprecated(message: string): this;
124
+ /** Add alternative variable names */
125
+ alias(...names: string[]): this;
126
+ /** Add a transform function applied after validation */
127
+ transform(fn: (value: TOutput) => TOutput): this;
128
+ /** Add a custom validation function */
129
+ custom(fn: (value: TOutput) => string | null): this;
130
+ /**
131
+ * Apply this schema only when a condition is met.
132
+ * The condition receives the current env values.
133
+ */
134
+ when(check: (env: Record<string, unknown>) => boolean): this;
135
+ /** Add a validator function (used by type-specific subclasses) */
136
+ protected _addValidator(validator: (value: TOutput) => string | null): void;
137
+ /** Add a transform function (used by type-specific subclasses) */
138
+ protected _addTransform(fn: (value: TOutput) => TOutput): void;
139
+ /** Replace the parser function (used for type narrowing) */
140
+ protected _setParser(parser: (raw: string) => ParseResult<TOutput>): void;
141
+ /** Apply all transforms to a value */
142
+ protected _applyTransforms(value: TOutput): TOutput;
143
+ /** Clone this builder (for composition) */
144
+ clone(): SchemaBuilder<TOutput>;
145
+ }
146
+
147
+ /** A schema definition mapping variable names to schema builders */
148
+ type SchemaDefinition = Record<string, SchemaBuilder<unknown>>;
149
+ /** Error entry from validation */
150
+ interface ValidationErrorEntry {
151
+ /** The variable name */
152
+ field: string;
153
+ /** The raw string value (or empty string if missing) */
154
+ rawValue: string;
155
+ /** Human-readable error message */
156
+ message: string;
157
+ /** The expected type */
158
+ expected: string;
159
+ /** Schema metadata for context */
160
+ meta: Readonly<SchemaMetadata>;
161
+ }
162
+ /** Warning entry from validation (non-blocking) */
163
+ interface ValidationWarningEntry {
164
+ /** The variable name */
165
+ field: string;
166
+ /** The raw string value */
167
+ rawValue: string;
168
+ /** Warning message */
169
+ message: string;
170
+ /** Warning code */
171
+ code: string;
172
+ }
173
+ /** Final result of validation */
174
+ interface EngineValidationResult {
175
+ /** Whether all validations passed (no errors) */
176
+ valid: boolean;
177
+ /** All validation errors (blocking) */
178
+ errors: readonly ValidationErrorEntry[];
179
+ /** All warnings (non-blocking) */
180
+ warnings: readonly ValidationWarningEntry[];
181
+ /** Successfully validated values */
182
+ values: Record<string, unknown>;
183
+ /** Unknown variables not in schema (only when strict mode) */
184
+ unknown: readonly string[];
185
+ }
186
+ /** Options for the validation engine */
187
+ interface EngineOptions {
188
+ /** Whether to fail on unknown variables not in the schema — default: false */
189
+ strict?: boolean;
190
+ /** Whether to stop on first error — default: false */
191
+ abortEarly?: boolean;
192
+ /** Whether to include deprecation warnings — default: true */
193
+ deprecationWarnings?: boolean;
194
+ }
195
+ /**
196
+ * Validate environment variables against a schema definition.
197
+ *
198
+ * @param vars - The raw environment variable key-value pairs
199
+ * @param schema - The schema definition mapping names to builders
200
+ * @param options - Validation options
201
+ * @returns The complete validation result
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const schema = {
206
+ * PORT: t.number().port().default(3000),
207
+ * HOST: t.string().hostname().default('localhost'),
208
+ * DEBUG: t.boolean().optional(),
209
+ * };
210
+ *
211
+ * const result = validate(process.env, schema);
212
+ * if (result.valid) {
213
+ * console.log(result.values.PORT); // 3000 (number)
214
+ * }
215
+ * ```
216
+ */
217
+ declare function validate(vars: Record<string, string>, schema: SchemaDefinition, options?: EngineOptions): EngineValidationResult;
218
+ /**
219
+ * Validate a single value against a schema builder.
220
+ * Useful for testing individual validators.
221
+ */
222
+ declare function validateValue<T>(rawValue: string | undefined, builder: SchemaBuilder<T>): ParseResult<T>;
223
+ /**
224
+ * Create a validation summary string for human-readable output.
225
+ */
226
+ declare function formatValidationResult(result: EngineValidationResult): string;
227
+
228
+ /**
229
+ * Extract the output type from a SchemaBuilder instance.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * type T = ExtractType<typeof t.number().port()>;
234
+ * // T = number
235
+ *
236
+ * type T2 = ExtractType<typeof t.enum(['a', 'b'] as const)>;
237
+ * // T2 = 'a' | 'b'
238
+ * ```
239
+ */
240
+ type ExtractType<S> = S extends SchemaBuilder<infer T> ? T : never;
241
+ /**
242
+ * Resolve the final output type of a schema, considering optional and default.
243
+ *
244
+ * - If optional: T | undefined
245
+ * - If has default: D (the default type)
246
+ * - Otherwise: T
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * type V1 = ResolveOutput<typeof t.string()>;
251
+ * // V1 = string
252
+ *
253
+ * type V2 = ResolveOutput<typeof t.string().optional()>;
254
+ * // V2 = string | undefined
255
+ *
256
+ * type V3 = ResolveOutput<typeof t.number().default(3000)>;
257
+ * // V3 = number
258
+ * ```
259
+ */
260
+ type ResolveOutput<S> = S extends {
261
+ __optional: true;
262
+ } ? ExtractType<S> | undefined : S extends {
263
+ __default: infer D;
264
+ } ? D : ExtractType<S>;
265
+ /**
266
+ * Infer a complete typed object from a schema definition.
267
+ * This is the main type used by `defineEnv` for its return type.
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const schema = {
272
+ * PORT: t.number().port().default(3000),
273
+ * HOST: t.string().hostname(),
274
+ * NODE_ENV: t.enum(['dev', 'prod'] as const),
275
+ * DEBUG: t.boolean().optional(),
276
+ * };
277
+ *
278
+ * type Env = InferSchema<typeof schema>;
279
+ * // Env = {
280
+ * // PORT: number; // has default, so number (not undefined)
281
+ * // HOST: string; // required
282
+ * // NODE_ENV: 'dev' | 'prod'; // enum narrows the type
283
+ * // DEBUG: boolean | undefined; // optional
284
+ * // }
285
+ * ```
286
+ */
287
+ type InferSchema<T extends Record<string, SchemaBuilder<unknown>>> = {
288
+ readonly [K in keyof T]: ResolveOutput<T[K]>;
289
+ };
290
+ /**
291
+ * Make all fields of an inferred schema required (remove undefined).
292
+ * Useful when you know all defaults are applied.
293
+ */
294
+ type RequiredSchema<T> = {
295
+ readonly [K in keyof T]: Exclude<T[K], undefined>;
296
+ };
297
+ /**
298
+ * Make all fields of an inferred schema optional (add undefined).
299
+ * Useful for partial configs.
300
+ */
301
+ type PartialSchema<T> = {
302
+ readonly [K in keyof T]: T[K] | undefined;
303
+ };
304
+ /**
305
+ * Extract only the required fields from a schema.
306
+ */
307
+ type RequiredFields<T extends Record<string, unknown>> = {
308
+ readonly [K in keyof T as undefined extends T[K] ? never : K]: T[K];
309
+ };
310
+ /**
311
+ * Extract only the optional fields from a schema.
312
+ */
313
+ type OptionalFields<T extends Record<string, unknown>> = {
314
+ readonly [K in keyof T as undefined extends T[K] ? K : never]: T[K];
315
+ };
316
+ /**
317
+ * Omit fields from a schema definition (preserves types).
318
+ */
319
+ type SchemaOmit<T extends Record<string, SchemaBuilder<unknown>>, K extends keyof T> = Omit<T, K>;
320
+ /**
321
+ * Pick fields from a schema definition (preserves types).
322
+ */
323
+ type SchemaPick<T extends Record<string, SchemaBuilder<unknown>>, K extends keyof T> = Pick<T, K>;
324
+ /**
325
+ * Merge two schema definitions.
326
+ * Values from B override values from A for overlapping keys.
327
+ */
328
+ type SchemaMerge<A extends Record<string, SchemaBuilder<unknown>>, B extends Record<string, SchemaBuilder<unknown>>> = Omit<A, keyof B> & B;
329
+ /**
330
+ * Get the union of all output types in a schema.
331
+ */
332
+ type SchemaValueUnion<T extends Record<string, SchemaBuilder<unknown>>> = ExtractType<T[keyof T]>;
333
+ /**
334
+ * Create a mapped type that wraps each value in a Promise.
335
+ */
336
+ type AsyncSchema<T extends Record<string, SchemaBuilder<unknown>>> = {
337
+ readonly [K in keyof T]: Promise<ResolveOutput<T[K]>>;
338
+ };
339
+
340
+ interface UrlOptions {
341
+ /** Allowed protocols (default: ['http', 'https']) */
342
+ protocols?: readonly string[];
343
+ }
344
+ interface UuidOptions {
345
+ /** Specific UUID version to validate (1-7). If omitted, accepts any version. */
346
+ version?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
347
+ }
348
+ /**
349
+ * Chainable string schema builder with all string-specific validators.
350
+ *
351
+ * @typeParam T - The string literal union type (defaults to string)
352
+ *
353
+ * @example
354
+ * ```typescript
355
+ * const email = t.string().email();
356
+ * const role = t.string().oneOf(['admin', 'user'] as const); // type: 'admin' | 'user'
357
+ * const host = t.string().url({ protocols: ['https'] });
358
+ * ```
359
+ */
360
+ declare class StringSchemaBuilder<T extends string = string> extends SchemaBuilder<T> {
361
+ constructor();
362
+ /** Validate as an email address */
363
+ email(): StringSchemaBuilder<T>;
364
+ /** Validate as a URL with optional protocol restriction */
365
+ url(opts?: UrlOptions): StringSchemaBuilder<T>;
366
+ /** Validate as a UUID (optionally restrict to a specific version 1-7) */
367
+ uuid(version?: 1 | 2 | 3 | 4 | 5 | 6 | 7): StringSchemaBuilder<T>;
368
+ /** Validate as a hex string (with optional 0x prefix) */
369
+ hex(): StringSchemaBuilder<T>;
370
+ /** Validate as a base64-encoded string */
371
+ base64(): StringSchemaBuilder<T>;
372
+ /** Validate that the string contains only letters and numbers */
373
+ alphanumeric(): StringSchemaBuilder<T>;
374
+ /** Convert to lowercase */
375
+ lowercase(): StringSchemaBuilder<T>;
376
+ /** Convert to uppercase */
377
+ uppercase(): StringSchemaBuilder<T>;
378
+ /** Trim whitespace from both ends */
379
+ trim(): StringSchemaBuilder<T>;
380
+ /** Minimum string length */
381
+ minLength(n: number): StringSchemaBuilder<T>;
382
+ /** Maximum string length */
383
+ maxLength(n: number): StringSchemaBuilder<T>;
384
+ /** Exact string length */
385
+ length(n: number): StringSchemaBuilder<T>;
386
+ /** Match a regular expression pattern */
387
+ pattern(regex: RegExp): StringSchemaBuilder<T>;
388
+ /** Must start with a specific prefix */
389
+ startsWith(prefix: string): StringSchemaBuilder<T>;
390
+ /** Must end with a specific suffix */
391
+ endsWith(suffix: string): StringSchemaBuilder<T>;
392
+ /** Must contain a specific substring */
393
+ includes(substring: string): StringSchemaBuilder<T>;
394
+ /** Restrict to one of the specified values (alias for enum) */
395
+ oneOf<L extends string>(values: readonly L[]): StringSchemaBuilder<L>;
396
+ /** Restrict to an enum of literal values — narrows the output type */
397
+ enum<L extends string>(values: readonly L[]): StringSchemaBuilder<L>;
398
+ /** Non-empty string */
399
+ nonempty(): StringSchemaBuilder<T>;
400
+ /** Must match a valid JSON string (checks parseability) */
401
+ json(): StringSchemaBuilder<T>;
402
+ }
403
+ /** Create a new string schema builder */
404
+ declare function createStringSchema<T extends string = string>(): StringSchemaBuilder<T>;
405
+
406
+ /**
407
+ * Chainable number schema builder with all number-specific validators.
408
+ *
409
+ * @typeParam T - The number literal type (defaults to number)
410
+ *
411
+ * @example
412
+ * ```typescript
413
+ * const port = t.number().port().default(3000);
414
+ * const pct = t.number().percentage().min(0).max(100);
415
+ * ```
416
+ */
417
+ declare class NumberSchemaBuilder<T extends number = number> extends SchemaBuilder<T> {
418
+ constructor();
419
+ /** Must be an integer (no decimals) */
420
+ integer(): NumberSchemaBuilder<T>;
421
+ /** Must be a float (semantic marker — all JS numbers are doubles) */
422
+ float(): NumberSchemaBuilder<T>;
423
+ /** Minimum value (inclusive) */
424
+ min(n: number): NumberSchemaBuilder<T>;
425
+ /** Maximum value (inclusive) */
426
+ max(n: number): NumberSchemaBuilder<T>;
427
+ /** Must be positive (> 0) */
428
+ positive(): NumberSchemaBuilder<T>;
429
+ /** Must be negative (< 0) */
430
+ negative(): NumberSchemaBuilder<T>;
431
+ /** Must be non-negative (>= 0) */
432
+ nonNegative(): NumberSchemaBuilder<T>;
433
+ /** Must be a valid network port (1-65535) */
434
+ port(): NumberSchemaBuilder<T>;
435
+ /** Must be a percentage (0-100) */
436
+ percentage(): NumberSchemaBuilder<T>;
437
+ /** Must be finite (no Infinity or NaN) */
438
+ finite(): NumberSchemaBuilder<T>;
439
+ /** Must be one of the specified values — narrows the output type */
440
+ oneOf<const L extends number>(values: readonly L[]): NumberSchemaBuilder<L>;
441
+ /** Must be a multiple of the given number */
442
+ step(n: number): NumberSchemaBuilder<T>;
443
+ /** Must be a safe integer (-(2^53 - 1) to 2^53 - 1) */
444
+ safeInt(): NumberSchemaBuilder<T>;
445
+ }
446
+ /** Create a new number schema builder */
447
+ declare function createNumberSchema<T extends number = number>(): NumberSchemaBuilder<T>;
448
+
449
+ /**
450
+ * Chainable boolean schema builder.
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * const debug = t.boolean().default(false);
455
+ * // debug._parse("true") → { success: true, value: true }
456
+ * // debug._parse("1") → { success: true, value: true }
457
+ * // debug._parse("no") → { success: true, value: false }
458
+ * // debug._parse("abc") → { success: false, error: "..." }
459
+ * ```
460
+ */
461
+ declare class BooleanSchemaBuilder extends SchemaBuilder<boolean> {
462
+ private _truthyValues;
463
+ private _falsyValues;
464
+ constructor();
465
+ /**
466
+ * Override the set of truthy values (case-insensitive).
467
+ * Common defaults: true, 1, yes, on
468
+ */
469
+ truthy(values: readonly string[]): BooleanSchemaBuilder;
470
+ /**
471
+ * Override the set of falsy values (case-insensitive).
472
+ * Common defaults: false, 0, no, off, ''
473
+ */
474
+ falsy(values: readonly string[]): BooleanSchemaBuilder;
475
+ /** Rebuild the parser function with current truthy/falsy sets */
476
+ private _rebuildParser;
477
+ }
478
+ /** Create a new boolean schema builder */
479
+ declare function createBooleanSchema(): BooleanSchemaBuilder;
480
+
481
+ /**
482
+ * Chainable enum schema builder for literal string unions.
483
+ *
484
+ * @typeParam L - The literal string union type
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * const env = t.enum(['development', 'production', 'test'] as const);
489
+ * // env._parse("production") → { success: true, value: "production" }
490
+ * // env._parse("staging") → { success: false, error: "..." }
491
+ *
492
+ * // Type is inferred as: SchemaBuilder<"development" | "production" | "test">
493
+ * ```
494
+ */
495
+ declare class EnumSchemaBuilder<L extends string> extends SchemaBuilder<L> {
496
+ private readonly _values;
497
+ private readonly _valuesArray;
498
+ private _caseInsensitive;
499
+ constructor(values: readonly L[]);
500
+ /** Enable or disable case-insensitive matching */
501
+ caseInsensitive(enabled?: boolean): EnumSchemaBuilder<L>;
502
+ /** Get the list of allowed values */
503
+ get values(): readonly string[];
504
+ private _rebuildParser;
505
+ }
506
+ /** Create a new enum schema builder */
507
+ declare function createEnumSchema<L extends string>(values: readonly L[]): EnumSchemaBuilder<L>;
508
+
509
+ /**
510
+ * Chainable array schema builder.
511
+ * Splits a string by a configurable separator and validates each element.
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * const hosts = t.array().separator(',').minItems(1);
516
+ * // hosts._parse("a,b,c") → { success: true, value: ["a", "b", "c"] }
517
+ *
518
+ * const tags = t.array().separator('|').unique();
519
+ * // tags._parse("foo|bar|foo") → { success: false, error: "..." }
520
+ * ```
521
+ */
522
+ declare class ArraySchemaBuilder extends SchemaBuilder<string[]> {
523
+ private _separator;
524
+ private _trimItems;
525
+ private _filterEmpty;
526
+ constructor();
527
+ /** Set the separator character (default: ',') */
528
+ separator(char: string): ArraySchemaBuilder;
529
+ /** Trim whitespace from each item after splitting */
530
+ trimItems(enabled?: boolean): ArraySchemaBuilder;
531
+ /** Remove empty strings from the result */
532
+ filterEmpty(enabled?: boolean): ArraySchemaBuilder;
533
+ /** Require unique items (no duplicates) */
534
+ unique(): ArraySchemaBuilder;
535
+ /** Minimum number of items */
536
+ minItems(n: number): ArraySchemaBuilder;
537
+ /** Maximum number of items */
538
+ maxItems(n: number): ArraySchemaBuilder;
539
+ /** Exact number of items */
540
+ items(n: number): ArraySchemaBuilder;
541
+ /** Non-empty array */
542
+ nonempty(): ArraySchemaBuilder;
543
+ /** Validate each item against a custom function */
544
+ itemValidate(fn: (item: string, index: number) => string | null): ArraySchemaBuilder;
545
+ private _rebuildParser;
546
+ }
547
+ /** Create a new array schema builder */
548
+ declare function createArraySchema(): ArraySchemaBuilder;
549
+
550
+ /**
551
+ * Chainable JSON schema builder.
552
+ * Parses a JSON string into a typed object.
553
+ *
554
+ * @typeParam T - The expected JSON output type
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const config = t.json<{ host: string; port: number }>();
559
+ * // config._parse('{"host":"localhost","port":3000}') → { success: true, value: {...} }
560
+ *
561
+ * const configWithSchema = t.json<{ host: string }>().schema((obj) => {
562
+ * if (!obj.host) return 'host is required';
563
+ * return null;
564
+ * });
565
+ * ```
566
+ */
567
+ declare class JsonSchemaBuilder<T = unknown> extends SchemaBuilder<T> {
568
+ constructor();
569
+ /**
570
+ * Add a custom schema validation function for the parsed object.
571
+ * Return an error message string, or null if valid.
572
+ */
573
+ schema(fn: (value: T) => string | null): JsonSchemaBuilder<T>;
574
+ /** Require the parsed JSON to be an object (not null, array, or primitive) */
575
+ object(): JsonSchemaBuilder<T>;
576
+ /** Require the parsed JSON to be an array */
577
+ array(): JsonSchemaBuilder<T>;
578
+ /** Require the parsed JSON to be a string primitive */
579
+ string(): JsonSchemaBuilder<T>;
580
+ /** Require the parsed JSON to be a number primitive */
581
+ number(): JsonSchemaBuilder<T>;
582
+ /** Require the parsed JSON to be a boolean primitive */
583
+ boolean(): JsonSchemaBuilder<T>;
584
+ /** Require a specific top-level key to exist */
585
+ hasKey(key: string): JsonSchemaBuilder<T>;
586
+ /** Use a custom JSON reviver during parsing */
587
+ reviver(reviver: (key: string, value: unknown) => unknown): JsonSchemaBuilder<T>;
588
+ }
589
+ /** Create a new JSON schema builder */
590
+ declare function createJsonSchema<T = unknown>(): JsonSchemaBuilder<T>;
591
+
592
+ /**
593
+ * Chainable date schema builder.
594
+ * Parses various date formats and validates date constraints.
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * const deadline = t.date().future();
599
+ * const birthday = t.date().past();
600
+ * const launch = t.date().after(new Date('2025-01-01'));
601
+ * ```
602
+ */
603
+ declare class DateSchemaBuilder extends SchemaBuilder<Date> {
604
+ constructor();
605
+ /** Date must be in the past */
606
+ past(): DateSchemaBuilder;
607
+ /** Date must be in the future */
608
+ future(): DateSchemaBuilder;
609
+ /** Date must be after the given reference date */
610
+ after(ref: Date): DateSchemaBuilder;
611
+ /** Date must be before the given reference date */
612
+ before(ref: Date): DateSchemaBuilder;
613
+ /** Date must be a valid date (re-checks, useful after transforms) */
614
+ valid(): DateSchemaBuilder;
615
+ /** Use a custom date parser */
616
+ parse(fn: (raw: string) => Date): DateSchemaBuilder;
617
+ }
618
+ /** Create a new date schema builder */
619
+ declare function createDateSchema(): DateSchemaBuilder;
620
+
621
+ /**
622
+ * Chainable regex schema builder.
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * const pattern = t.regex();
627
+ * // pattern._parse("\\d+") → { success: true, value: /\d+/ }
628
+ * // pattern._parse("/^\\w+$/gi") → { success: true, value: /^\w+$/gi }
629
+ * // pattern._parse("[invalid") → { success: false, error: "Invalid regex: ..." }
630
+ * ```
631
+ */
632
+ declare class RegexSchemaBuilder extends SchemaBuilder<RegExp> {
633
+ constructor();
634
+ /** Require the regex to have a specific flag */
635
+ hasFlag(flag: string): RegexSchemaBuilder;
636
+ /** Require the regex to NOT have a specific flag */
637
+ noFlag(flag: string): RegexSchemaBuilder;
638
+ /** Require the regex to be case-insensitive */
639
+ caseInsensitive(): RegexSchemaBuilder;
640
+ /** Require the regex to be global */
641
+ global(): RegexSchemaBuilder;
642
+ /** Require the regex to be multiline */
643
+ multiline(): RegexSchemaBuilder;
644
+ /** Test the regex against a string (validation-only, doesn't change the value) */
645
+ test(testString: string, expectMatch: boolean): RegexSchemaBuilder;
646
+ }
647
+ /** Create a new regex schema builder */
648
+ declare function createRegexSchema(): RegexSchemaBuilder;
649
+
650
+ /**
651
+ * Chainable BigInt schema builder.
652
+ *
653
+ * @example
654
+ * ```typescript
655
+ * const big = t.bigint().positive().max(999999999999n);
656
+ * // big._parse("123456789012") → { success: true, value: 123456789012n }
657
+ * ```
658
+ */
659
+ declare class BigIntSchemaBuilder extends SchemaBuilder<bigint> {
660
+ private _radix;
661
+ constructor();
662
+ /** Set the radix for parsing (default: 10). Use 16 for hex. */
663
+ radix(r: number): BigIntSchemaBuilder;
664
+ /** Minimum value (inclusive) */
665
+ min(n: bigint): BigIntSchemaBuilder;
666
+ /** Maximum value (inclusive) */
667
+ max(n: bigint): BigIntSchemaBuilder;
668
+ /** Must be positive (> 0) */
669
+ positive(): BigIntSchemaBuilder;
670
+ /** Must be negative (< 0) */
671
+ negative(): BigIntSchemaBuilder;
672
+ /** Must be non-negative (>= 0) */
673
+ nonNegative(): BigIntSchemaBuilder;
674
+ /** Must be one of the specified values */
675
+ oneOf<const L extends bigint>(values: readonly L[]): BigIntSchemaBuilder;
676
+ /** Use a custom parse function */
677
+ parse(fn: (raw: string) => bigint): BigIntSchemaBuilder;
678
+ private _rebuildParser;
679
+ }
680
+ /** Create a new BigInt schema builder */
681
+ declare function createBigIntSchema(): BigIntSchemaBuilder;
682
+
683
+ interface UrlValidatorOptions {
684
+ /** Allowed protocols (default: ['http', 'https']) */
685
+ protocols?: readonly string[];
686
+ /** Require a specific hostname */
687
+ hostname?: string;
688
+ /** Allowed port numbers */
689
+ allowedPorts?: readonly number[];
690
+ /** Whether to allow query strings (default: true) */
691
+ allowQuery?: boolean;
692
+ /** Whether to allow fragments (default: true) */
693
+ allowFragment?: boolean;
694
+ /** Maximum URL length (default: 2048) */
695
+ maxLength?: number;
696
+ }
697
+ /** Create a URL schema builder with advanced validation */
698
+ declare function createUrlSchema(opts?: UrlValidatorOptions): SchemaBuilder<URL>;
699
+
700
+ interface EmailValidatorOptions {
701
+ /** Maximum email length (default: 254 per RFC 5321) */
702
+ maxLength?: number;
703
+ /** Maximum local part length (default: 64 per RFC 5321) */
704
+ maxLocalLength?: number;
705
+ /** Allowed TLDs (if specified, restricts to these) */
706
+ allowedTlds?: readonly string[];
707
+ /** Blocked domains */
708
+ blockedDomains?: readonly string[];
709
+ /** Whether to allow plus addressing (e.g., user+tag@domain.com) */
710
+ allowPlusAddressing?: boolean;
711
+ }
712
+ /** Create an email schema builder with advanced validation */
713
+ declare function createEmailSchema(opts?: EmailValidatorOptions): SchemaBuilder<string>;
714
+
715
+ interface IpValidatorOptions {
716
+ /** IP version to accept: '4', '6', or 'both' (default: 'both') */
717
+ version?: '4' | '6' | 'both';
718
+ /** Whether to accept CIDR notation (default: false) */
719
+ allowCidr?: boolean;
720
+ /** Whether to accept IPv4-mapped IPv6 addresses (default: true) */
721
+ allowMappedV4?: boolean;
722
+ }
723
+ /** Create an IP address schema builder */
724
+ declare function createIpSchema(opts?: IpValidatorOptions): SchemaBuilder<string>;
725
+ /** Create an IPv4-only schema builder */
726
+ declare function createIpv4Schema(opts?: Omit<IpValidatorOptions, 'version'>): SchemaBuilder<string>;
727
+ /** Create an IPv6-only schema builder */
728
+ declare function createIpv6Schema(opts?: Omit<IpValidatorOptions, 'version'>): SchemaBuilder<string>;
729
+
730
+ interface HostnameValidatorOptions {
731
+ /** Maximum total length (default: 253 per RFC 1035) */
732
+ maxLength?: number;
733
+ /** Maximum label length (default: 63 per RFC 1035) */
734
+ maxLabelLength?: number;
735
+ /** Whether to allow trailing dot (FQDN, default: false) */
736
+ allowTrailingDot?: boolean;
737
+ /** Whether to allow internationalized domain names (default: true) */
738
+ allowIdn?: boolean;
739
+ /** Whether to allow underscores in labels (default: false, but common in DNS) */
740
+ allowUnderscore?: boolean;
741
+ }
742
+ /** Create a hostname schema builder */
743
+ declare function createHostnameSchema(opts?: HostnameValidatorOptions): SchemaBuilder<string>;
744
+
745
+ interface PortValidatorOptions {
746
+ /** Whether to include well-known ports (0-1023) — default: true */
747
+ allowWellKnown?: boolean;
748
+ /** Whether to include registered ports (1024-49151) — default: true */
749
+ allowRegistered?: boolean;
750
+ /** Whether to include dynamic/ephemeral ports (49152-65535) — default: true */
751
+ allowDynamic?: boolean;
752
+ /** Whether to allow port 0 (default: false) */
753
+ allowZero?: boolean;
754
+ /** Specific allowed ports (overrides range checks if provided) */
755
+ allowedPorts?: readonly number[];
756
+ }
757
+ /** Create a port schema builder */
758
+ declare function createPortSchema(opts?: PortValidatorOptions): SchemaBuilder<number>;
759
+
760
+ interface PathValidatorOptions {
761
+ /** Whether the path must be absolute (start with /) — default: false */
762
+ absolute?: boolean;
763
+ /** Whether the path must be relative — default: false */
764
+ relative?: boolean;
765
+ /** Whether to allow .. segments — default: false */
766
+ allowParentTraversal?: boolean;
767
+ /** Whether to allow home directory (~) — default: false */
768
+ allowHomeDir?: boolean;
769
+ /** Maximum path depth (number of segments) — default: unlimited */
770
+ maxDepth?: number;
771
+ /** File extension restriction (e.g., ['.json', '.yaml']) */
772
+ extensions?: readonly string[];
773
+ }
774
+ /** Create a file path schema builder */
775
+ declare function createPathSchema(opts?: PathValidatorOptions): SchemaBuilder<string>;
776
+
777
+ interface UuidValidatorOptions {
778
+ /** Require a specific UUID version (1-7) */
779
+ version?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
780
+ /** Whether to allow nil UUID (00000000-0000-0000-0000-000000000000) — default: false */
781
+ allowNil?: boolean;
782
+ /** Whether to be strict about variant bits — default: true */
783
+ strictVariant?: boolean;
784
+ }
785
+ /** Create a UUID schema builder */
786
+ declare function createUuidSchema(opts?: UuidValidatorOptions): SchemaBuilder<string>;
787
+
788
+ interface HexValidatorOptions {
789
+ /** Whether to allow "0x" prefix — default: false */
790
+ allowPrefix?: boolean;
791
+ /** Require "0x" prefix — default: false */
792
+ requirePrefix?: boolean;
793
+ /** Exact byte length (number of hex pairs) — e.g., 32 for SHA-256 */
794
+ byteLength?: number;
795
+ /** Case requirement: 'lower', 'upper', or 'mixed' (default: 'mixed') */
796
+ caseSensitive?: 'lower' | 'upper' | 'mixed';
797
+ }
798
+ /** Create a hex string schema builder */
799
+ declare function createHexSchema(opts?: HexValidatorOptions): SchemaBuilder<string>;
800
+
801
+ interface Base64ValidatorOptions {
802
+ /** Whether to allow URL-safe characters (- and _ instead of + and /) — default: false */
803
+ urlSafe?: boolean;
804
+ /** Whether to require padding (= or ==) — default: false */
805
+ requirePadding?: boolean;
806
+ /** Whether to disallow whitespace — default: true */
807
+ noWhitespace?: boolean;
808
+ /** Whether to allow empty strings — default: false */
809
+ allowEmpty?: boolean;
810
+ /** Minimum decoded byte length — default: none */
811
+ minBytes?: number;
812
+ /** Maximum decoded byte length — default: none */
813
+ maxBytes?: number;
814
+ }
815
+ /** Create a base64 schema builder */
816
+ declare function createBase64Schema(opts?: Base64ValidatorOptions): SchemaBuilder<string>;
817
+
818
+ interface SemverValidatorOptions {
819
+ /** Whether to allow prerelease versions (e.g., 1.0.0-alpha.1) — default: true */
820
+ allowPrerelease?: boolean;
821
+ /** Whether to allow build metadata (e.g., 1.0.0+build.123) — default: true */
822
+ allowBuildMetadata?: boolean;
823
+ /** Whether to allow leading 'v' prefix (e.g., v1.0.0) — default: true */
824
+ allowVPrefix?: boolean;
825
+ /** Loose mode — allows non-compliant versions like "1.0" — default: false */
826
+ loose?: boolean;
827
+ }
828
+ /** Create a semver schema builder */
829
+ declare function createSemverSchema(opts?: SemverValidatorOptions): SchemaBuilder<string>;
830
+
831
+ interface CronValidatorOptions {
832
+ /** Whether to allow 6-field expressions (with year) — default: false */
833
+ allowYear?: boolean;
834
+ /** Whether to allow 6-field expressions (with seconds) — default: false */
835
+ allowSeconds?: boolean;
836
+ /** Whether to allow predefined expressions (e.g., @yearly, @daily) — default: true */
837
+ allowAliases?: boolean;
838
+ }
839
+ /** Create a cron expression schema builder */
840
+ declare function createCronSchema(opts?: CronValidatorOptions): SchemaBuilder<string>;
841
+
842
+ interface DurationValidatorOptions {
843
+ /** Output unit — default: 'ms' */
844
+ unit?: 'ms' | 's' | 'm' | 'h';
845
+ /** Maximum duration in milliseconds — default: unlimited */
846
+ max?: number;
847
+ /** Minimum duration in milliseconds — default: 0 */
848
+ min?: number;
849
+ /** Whether to allow negative durations (e.g., "-5m") — default: false */
850
+ allowNegative?: boolean;
851
+ }
852
+ /** Create a duration schema builder */
853
+ declare function createDurationSchema(opts?: DurationValidatorOptions): SchemaBuilder<number>;
854
+
855
+ interface BytesValidatorOptions {
856
+ /** Whether to use binary units (1024) or decimal units (1000) — default: binary */
857
+ binary?: boolean;
858
+ /** Output unit — default: 'bytes' */
859
+ unit?: 'bytes' | 'kb' | 'mb' | 'gb' | 'tb';
860
+ /** Maximum byte count — default: unlimited */
861
+ max?: number;
862
+ /** Minimum byte count — default: 0 */
863
+ min?: number;
864
+ }
865
+ /** Create a bytes schema builder */
866
+ declare function createBytesSchema(opts?: BytesValidatorOptions): SchemaBuilder<number>;
867
+
868
+ interface ColorValidatorOptions {
869
+ /** Which formats to accept (default: all) */
870
+ formats?: readonly ('hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'named')[];
871
+ /** Whether to accept 3-digit hex (#RGB) — default: true */
872
+ allowShortHex?: boolean;
873
+ /** Whether to accept 8-digit hex with alpha (#RRGGBBAA) — default: true */
874
+ allowAlpha?: boolean;
875
+ }
876
+ /** Create a color schema builder */
877
+ declare function createColorSchema(opts?: ColorValidatorOptions): SchemaBuilder<string>;
878
+
879
+ interface LocaleValidatorOptions {
880
+ /** Whether to require a region subtag (e.g., "en-US" not just "en") — default: false */
881
+ requireRegion?: boolean;
882
+ /** Allowed language subtags (ISO 639-1 codes) — default: any */
883
+ allowedLanguages?: readonly string[];
884
+ /** Whether to accept Unicode extensions (e.g., "en-US-u-ca-buddhist") — default: false */
885
+ allowExtensions?: boolean;
886
+ }
887
+ /** Create a locale schema builder */
888
+ declare function createLocaleSchema(opts?: LocaleValidatorOptions): SchemaBuilder<string>;
889
+
890
+ interface TimezoneValidatorOptions {
891
+ /** Whether to allow UTC offset format (e.g., "UTC+5:30") — default: true */
892
+ allowOffset?: boolean;
893
+ /** Whether to allow short timezone names (e.g., "EST", "PST") — default: false */
894
+ allowShort?: boolean;
895
+ /** Whether to allow the special "Z" identifier — default: true */
896
+ allowZ?: boolean;
897
+ }
898
+ /** Create a timezone schema builder */
899
+ declare function createTimezoneSchema(opts?: TimezoneValidatorOptions): SchemaBuilder<string>;
900
+
901
+ interface CountryValidatorOptions {
902
+ /** Which format to accept: 'alpha2', 'alpha3', or 'both' — default: 'both' */
903
+ format?: 'alpha2' | 'alpha3' | 'both';
904
+ /** Whether to accept numeric codes — default: false */
905
+ allowNumeric?: boolean;
906
+ }
907
+ /** Create a country code schema builder */
908
+ declare function createCountrySchema(opts?: CountryValidatorOptions): SchemaBuilder<string>;
909
+
910
+ interface CurrencyValidatorOptions {
911
+ /** Whether to accept only active currencies — default: true */
912
+ activeOnly?: boolean;
913
+ /** Whether to accept cryptocurrency codes (e.g., BTC, ETH) — default: false */
914
+ allowCrypto?: boolean;
915
+ }
916
+ /** Create a currency code schema builder */
917
+ declare function createCurrencySchema(opts?: CurrencyValidatorOptions): SchemaBuilder<string>;
918
+
919
+ /**
920
+ * Apply the required modifier to a schema builder.
921
+ * This makes the field mandatory — it must be present in the env.
922
+ *
923
+ * @param builder - The schema builder to modify
924
+ * @returns The same builder (for chaining)
925
+ *
926
+ * @example
927
+ * ```typescript
928
+ * const schema = applyRequired(t.string());
929
+ * ```
930
+ */
931
+ declare function applyRequired<T>(builder: SchemaBuilder<T>): SchemaBuilder<T>;
932
+ /**
933
+ * Check if a schema is marked as required.
934
+ */
935
+ declare function isRequired<T>(builder: SchemaBuilder<T>): boolean;
936
+
937
+ /**
938
+ * Apply the optional modifier to a schema builder.
939
+ * This makes the field optional — it can be omitted or have an undefined value.
940
+ *
941
+ * @param builder - The schema builder to modify
942
+ * @returns The same builder (for chaining)
943
+ *
944
+ * @example
945
+ * ```typescript
946
+ * const schema = applyOptional(t.string());
947
+ * ```
948
+ */
949
+ declare function applyOptional<T>(builder: SchemaBuilder<T>): SchemaBuilder<T>;
950
+ /**
951
+ * Check if a schema is marked as optional.
952
+ */
953
+ declare function isOptional<T>(builder: SchemaBuilder<T>): boolean;
954
+
955
+ /**
956
+ * Apply a default value modifier to a schema builder.
957
+ * When the env variable is not set, the default value will be used.
958
+ *
959
+ * @param builder - The schema builder to modify
960
+ * @param defaultValue - The default value (will be stored as a string for parsing)
961
+ * @returns The same builder (for chaining)
962
+ *
963
+ * @example
964
+ * ```typescript
965
+ * const port = applyDefault(t.number(), 3000);
966
+ * ```
967
+ */
968
+ declare function applyDefault<T>(builder: SchemaBuilder<T>, defaultValue: T): SchemaBuilder<T>;
969
+ /**
970
+ * Check if a schema has a default value.
971
+ */
972
+ declare function hasDefault<T>(builder: SchemaBuilder<T>): boolean;
973
+ /**
974
+ * Get the default value from a schema, parsed through the schema's parser.
975
+ */
976
+ declare function getDefaultValue<T>(builder: SchemaBuilder<T>): T | undefined;
977
+
978
+ /**
979
+ * Apply the secret modifier to a schema builder.
980
+ * Secret values will be masked in logs and diagnostic output.
981
+ *
982
+ * @param builder - The schema builder to modify
983
+ * @returns The same builder (for chaining)
984
+ *
985
+ * @example
986
+ * ```typescript
987
+ * const apiKey = applySecret(t.string());
988
+ * ```
989
+ */
990
+ declare function applySecret<T>(builder: SchemaBuilder<T>): SchemaBuilder<T>;
991
+ /**
992
+ * Check if a schema is marked as secret.
993
+ */
994
+ declare function isSecret<T>(builder: SchemaBuilder<T>): boolean;
995
+ /**
996
+ * Mask a value if the schema is marked as secret.
997
+ * Shows first 4 characters and replaces the rest with asterisks.
998
+ */
999
+ declare function maskValue<T>(value: T, builder: SchemaBuilder<T>): string;
1000
+
1001
+ /**
1002
+ * Apply the deprecated modifier to a schema builder.
1003
+ * Deprecated fields generate warnings during validation.
1004
+ *
1005
+ * @param builder - The schema builder to modify
1006
+ * @param message - The deprecation message (e.g., "Use NEW_VAR instead")
1007
+ * @returns The same builder (for chaining)
1008
+ *
1009
+ * @example
1010
+ * ```typescript
1011
+ * const oldVar = applyDeprecated(t.string(), 'Use NEW_VAR instead');
1012
+ * ```
1013
+ */
1014
+ declare function applyDeprecated<T>(builder: SchemaBuilder<T>, message: string): SchemaBuilder<T>;
1015
+ /**
1016
+ * Check if a schema is marked as deprecated.
1017
+ */
1018
+ declare function isDeprecated<T>(builder: SchemaBuilder<T>): boolean;
1019
+ /**
1020
+ * Get the deprecation message from a schema.
1021
+ */
1022
+ declare function getDeprecationMessage<T>(builder: SchemaBuilder<T>): string | undefined;
1023
+
1024
+ /**
1025
+ * Apply alias names to a schema builder.
1026
+ * Aliases are alternative env variable names that resolve to this schema.
1027
+ *
1028
+ * @param builder - The schema builder to modify
1029
+ * @param names - Alternative variable names
1030
+ * @returns The same builder (for chaining)
1031
+ *
1032
+ * @example
1033
+ * ```typescript
1034
+ * const host = applyAlias(t.string(), 'SERVER_HOST', 'HOSTNAME');
1035
+ * // Both HOST and SERVER_HOST and HOSTNAME will resolve to this schema
1036
+ * ```
1037
+ */
1038
+ declare function applyAlias<T>(builder: SchemaBuilder<T>, ...names: string[]): SchemaBuilder<T>;
1039
+ /**
1040
+ * Get all aliases for a schema.
1041
+ */
1042
+ declare function getAliases<T>(builder: SchemaBuilder<T>): readonly string[];
1043
+ /**
1044
+ * Check if a given variable name is an alias for this schema.
1045
+ */
1046
+ declare function isAlias<T>(builder: SchemaBuilder<T>, name: string): boolean;
1047
+
1048
+ /**
1049
+ * Apply a transform function to a schema builder.
1050
+ * The transform is applied AFTER validation passes.
1051
+ *
1052
+ * @param builder - The schema builder to modify
1053
+ * @param fn - The transform function
1054
+ * @returns The same builder (for chaining)
1055
+ *
1056
+ * @example
1057
+ * ```typescript
1058
+ * const port = applyTransform(t.number(), (v) => v * 1); // identity
1059
+ * const upper = applyTransform(t.string(), (v) => v.toUpperCase());
1060
+ * ```
1061
+ */
1062
+ declare function applyTransform<T>(builder: SchemaBuilder<T>, fn: (value: T) => T): SchemaBuilder<T>;
1063
+ /**
1064
+ * Compose multiple transform functions into a single function.
1065
+ * Functions are applied from left to right.
1066
+ */
1067
+ declare function composeTransforms<T>(...fns: ReadonlyArray<(value: T) => T>): (value: T) => T;
1068
+
1069
+ /**
1070
+ * Apply a custom validation function to a schema builder.
1071
+ * The function receives the parsed value and must return:
1072
+ * - `null` or `undefined` if validation passes
1073
+ * - An error message string if validation fails
1074
+ *
1075
+ * @param builder - The schema builder to modify
1076
+ * @param fn - The custom validation function
1077
+ * @returns The same builder (for chaining)
1078
+ *
1079
+ * @example
1080
+ * ```typescript
1081
+ * const password = applyCustom(t.string(), (v) => {
1082
+ * if (v.length < 12) return 'Password must be at least 12 characters';
1083
+ * return null;
1084
+ * });
1085
+ * ```
1086
+ */
1087
+ declare function applyCustom<T>(builder: SchemaBuilder<T>, fn: (value: T) => string | null): SchemaBuilder<T>;
1088
+ /**
1089
+ * Create a validator that checks for a minimum length.
1090
+ */
1091
+ declare function minLength<T extends string>(n: number): (value: T) => string | null;
1092
+ /**
1093
+ * Create a validator that checks for a maximum length.
1094
+ */
1095
+ declare function maxLength<T extends string>(n: number): (value: T) => string | null;
1096
+ /**
1097
+ * Create a validator that checks a condition with a custom error message.
1098
+ */
1099
+ declare function check<T>(condition: (value: T) => boolean, message: string): (value: T) => string | null;
1100
+ /**
1101
+ * Combine multiple validators with short-circuit evaluation.
1102
+ */
1103
+ declare function allOf<T>(...validators: ReadonlyArray<(value: T) => string | null>): (value: T) => string | null;
1104
+
1105
+ /**
1106
+ * Apply a conditional check to a schema builder.
1107
+ * The schema will only be validated if the condition function returns true.
1108
+ * If the condition returns false, the schema is skipped entirely.
1109
+ *
1110
+ * @param builder - The schema builder to modify
1111
+ * @param check - A function that receives the current env values and returns boolean
1112
+ * @returns The same builder (for chaining)
1113
+ *
1114
+ * @example
1115
+ * ```typescript
1116
+ * const workerThreads = applyConditional(
1117
+ * t.number().min(1).max(32),
1118
+ * (env) => env.USE_WORKERS === 'true'
1119
+ * );
1120
+ * ```
1121
+ */
1122
+ declare function applyConditional<T>(builder: SchemaBuilder<T>, check: (env: Record<string, unknown>) => boolean): SchemaBuilder<T>;
1123
+ /**
1124
+ * Check if a schema has a conditional applied.
1125
+ */
1126
+ declare function hasConditional<T>(builder: SchemaBuilder<T>): boolean;
1127
+ /**
1128
+ * Evaluate whether a schema's conditional passes given the current env values.
1129
+ * Returns true if the schema should be applied (no conditional or condition passes).
1130
+ */
1131
+ declare function shouldApply<T>(builder: SchemaBuilder<T>, env: Record<string, unknown>): boolean;
1132
+
1133
+ /**
1134
+ * Apply a description to a schema builder.
1135
+ * Descriptions are used for documentation and error messages.
1136
+ *
1137
+ * @param builder - The schema builder to modify
1138
+ * @param desc - The description text
1139
+ * @returns The same builder (for chaining)
1140
+ *
1141
+ * @example
1142
+ * ```typescript
1143
+ * const host = applyDescription(t.string(), 'The server hostname or IP address');
1144
+ * ```
1145
+ */
1146
+ declare function applyDescription<T>(builder: SchemaBuilder<T>, desc: string): SchemaBuilder<T>;
1147
+ /**
1148
+ * Get the description from a schema.
1149
+ */
1150
+ declare function getDescription<T>(builder: SchemaBuilder<T>): string | undefined;
1151
+ /**
1152
+ * Format a schema's description with its type information for documentation.
1153
+ */
1154
+ declare function formatSchemaDescription<T>(builder: SchemaBuilder<T>, fieldName: string): string;
1155
+
1156
+ /**
1157
+ * The schema builder factory. Use this to create type-safe schemas.
1158
+ *
1159
+ * @example
1160
+ * ```typescript
1161
+ * import { t, defineEnv } from 'ultraenv/schema';
1162
+ *
1163
+ * const env = defineEnv({
1164
+ * PORT: t.number().port().default(3000),
1165
+ * HOST: t.string().hostname().default('localhost'),
1166
+ * NODE_ENV: t.enum(['development', 'production', 'test'] as const),
1167
+ * DEBUG: t.boolean().optional(),
1168
+ * ALLOWED_ORIGINS: t.array().separator(','),
1169
+ * TIMEOUT: t.duration(),
1170
+ * MAX_SIZE: t.bytes(),
1171
+ * LOCALE: t.locale(),
1172
+ * TIMEZONE: t.timezone(),
1173
+ * });
1174
+ * ```
1175
+ */
1176
+ declare const t: {
1177
+ readonly string: <T extends string = string>() => StringSchemaBuilder<T>;
1178
+ readonly number: <T extends number = number>() => NumberSchemaBuilder<T>;
1179
+ readonly boolean: () => BooleanSchemaBuilder;
1180
+ readonly enum: <L extends string>(values: readonly L[]) => EnumSchemaBuilder<L>;
1181
+ readonly array: () => ArraySchemaBuilder;
1182
+ readonly json: <T = unknown>() => JsonSchemaBuilder<T>;
1183
+ readonly date: () => DateSchemaBuilder;
1184
+ readonly regex: () => RegexSchemaBuilder;
1185
+ readonly bigint: () => BigIntSchemaBuilder;
1186
+ readonly url: (opts?: UrlValidatorOptions) => SchemaBuilder<URL>;
1187
+ readonly email: (opts?: EmailValidatorOptions) => SchemaBuilder<string>;
1188
+ readonly ip: (opts?: IpValidatorOptions) => SchemaBuilder<string>;
1189
+ readonly ipv4: (opts?: Omit<IpValidatorOptions, "version">) => SchemaBuilder<string>;
1190
+ readonly ipv6: (opts?: Omit<IpValidatorOptions, "version">) => SchemaBuilder<string>;
1191
+ readonly hostname: (opts?: HostnameValidatorOptions) => SchemaBuilder<string>;
1192
+ readonly port: (opts?: PortValidatorOptions) => SchemaBuilder<number>;
1193
+ readonly path: (opts?: PathValidatorOptions) => SchemaBuilder<string>;
1194
+ readonly uuid: (opts?: UuidValidatorOptions) => SchemaBuilder<string>;
1195
+ readonly hex: (opts?: HexValidatorOptions) => SchemaBuilder<string>;
1196
+ readonly base64: (opts?: Base64ValidatorOptions) => SchemaBuilder<string>;
1197
+ readonly semver: (opts?: SemverValidatorOptions) => SchemaBuilder<string>;
1198
+ readonly cron: (opts?: CronValidatorOptions) => SchemaBuilder<string>;
1199
+ readonly duration: (opts?: DurationValidatorOptions) => SchemaBuilder<number>;
1200
+ readonly bytes: (opts?: BytesValidatorOptions) => SchemaBuilder<number>;
1201
+ readonly color: (opts?: ColorValidatorOptions) => SchemaBuilder<string>;
1202
+ readonly locale: (opts?: LocaleValidatorOptions) => SchemaBuilder<string>;
1203
+ readonly timezone: (opts?: TimezoneValidatorOptions) => SchemaBuilder<string>;
1204
+ readonly country: (opts?: CountryValidatorOptions) => SchemaBuilder<string>;
1205
+ readonly currency: (opts?: CurrencyValidatorOptions) => SchemaBuilder<string>;
1206
+ };
1207
+ /**
1208
+ * Define and validate environment variables from a schema.
1209
+ * Returns a fully typed object where TypeScript infers ALL types from the schema.
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * const env = defineEnv({
1214
+ * PORT: t.number().port().default(3000),
1215
+ * HOST: t.string().default('localhost'),
1216
+ * NODE_ENV: t.enum(['development', 'production', 'test'] as const),
1217
+ * DEBUG: t.boolean().optional(),
1218
+ * });
1219
+ *
1220
+ * // TypeScript knows:
1221
+ * // env.PORT → number
1222
+ * // env.HOST → string
1223
+ * // env.NODE_ENV → 'development' | 'production' | 'test'
1224
+ * // env.DEBUG → boolean | undefined
1225
+ * ```
1226
+ */
1227
+ declare function defineEnv<S extends Record<string, SchemaBuilder<unknown>>>(schema: S, vars?: Record<string, string>, options?: EngineOptions): InferSchema<S>;
1228
+ /**
1229
+ * Define environment variables without throwing on validation failure.
1230
+ * Returns the result object with valid/warning/error information.
1231
+ */
1232
+ declare function tryDefineEnv<S extends Record<string, SchemaBuilder<unknown>>>(schema: S, vars?: Record<string, string>, options?: EngineOptions): {
1233
+ valid: true;
1234
+ values: InferSchema<S>;
1235
+ warnings: readonly ValidationWarningEntry[];
1236
+ } | {
1237
+ valid: false;
1238
+ values: Record<string, unknown>;
1239
+ warnings: readonly ValidationWarningEntry[];
1240
+ errors: readonly ValidationErrorEntry[];
1241
+ unknown: readonly string[];
1242
+ };
1243
+
1244
+ export { ArraySchemaBuilder, type AsyncSchema, type Base64ValidatorOptions, BigIntSchemaBuilder, BooleanSchemaBuilder, type BytesValidatorOptions, type ColorValidatorOptions, type ConditionalConfig, type CountryValidatorOptions, type CronValidatorOptions, type CurrencyValidatorOptions, DateSchemaBuilder, type DurationValidatorOptions, type EmailValidatorOptions, type EngineOptions, type EngineValidationResult, EnumSchemaBuilder, type ExtractDefault, type ExtractType$1 as ExtractType, type HexValidatorOptions, type HostnameValidatorOptions, type InferSchema, type IpValidatorOptions, type IsOptional, JsonSchemaBuilder, type LocaleValidatorOptions, type NoInfer, NumberSchemaBuilder, type OptionalFields, type ParseResult, type PartialSchema, type PathValidatorOptions, type PortValidatorOptions, RegexSchemaBuilder, type RequiredFields, type RequiredSchema, type ResolveOutput$1 as ResolveOutput, SchemaBuilder, type SchemaDefinition, type SchemaMerge, type SchemaMetadata, type SchemaOmit, type SchemaPick, type SchemaValueUnion, type SemverValidatorOptions, StringSchemaBuilder, type TimezoneValidatorOptions, type UrlOptions, type UrlValidatorOptions, type UuidOptions, type UuidValidatorOptions, type ValidationErrorEntry, type ValidationWarningEntry, allOf, applyAlias, applyConditional, applyCustom, applyDefault, applyDeprecated, applyDescription, applyOptional, applyRequired, applySecret, applyTransform, check, composeTransforms, createArraySchema, createBase64Schema, createBigIntSchema, createBooleanSchema, createBytesSchema, createColorSchema, createCountrySchema, createCronSchema, createCurrencySchema, createDateSchema, createDurationSchema, createEmailSchema, createEnumSchema, createHexSchema, createHostnameSchema, createIpSchema, createIpv4Schema, createIpv6Schema, createJsonSchema, createLocaleSchema, createNumberSchema, createPathSchema, createPortSchema, createRegexSchema, createSemverSchema, createStringSchema, createTimezoneSchema, createUrlSchema, createUuidSchema, maxLength as customMaxLength, minLength as customMinLength, defineEnv, formatSchemaDescription, formatValidationResult, getAliases, getDeprecationMessage, getDescription, getDefaultValue as getModDefault, hasConditional, hasDefault, isAlias, isDeprecated, isOptional, isRequired, isSecret, maskValue, shouldApply, t, tryDefineEnv, validate, validateValue };