env-validated 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.
- package/LICENSE +21 -0
- package/README.md +833 -0
- package/dist/adapters/arktype.cjs +38 -0
- package/dist/adapters/arktype.d.cts +1 -0
- package/dist/adapters/arktype.d.ts +1 -0
- package/dist/adapters/arktype.js +11 -0
- package/dist/adapters/effect.cjs +38 -0
- package/dist/adapters/effect.d.cts +1 -0
- package/dist/adapters/effect.d.ts +1 -0
- package/dist/adapters/effect.js +11 -0
- package/dist/adapters/joi.cjs +57 -0
- package/dist/adapters/joi.d.cts +55 -0
- package/dist/adapters/joi.d.ts +55 -0
- package/dist/adapters/joi.js +35 -0
- package/dist/adapters/runtypes.cjs +38 -0
- package/dist/adapters/runtypes.d.cts +1 -0
- package/dist/adapters/runtypes.d.ts +1 -0
- package/dist/adapters/runtypes.js +11 -0
- package/dist/adapters/superstruct.cjs +38 -0
- package/dist/adapters/superstruct.d.cts +1 -0
- package/dist/adapters/superstruct.d.ts +1 -0
- package/dist/adapters/superstruct.js +11 -0
- package/dist/adapters/typebox.cjs +38 -0
- package/dist/adapters/typebox.d.cts +1 -0
- package/dist/adapters/typebox.d.ts +1 -0
- package/dist/adapters/typebox.js +11 -0
- package/dist/adapters/valibot.cjs +38 -0
- package/dist/adapters/valibot.d.cts +1 -0
- package/dist/adapters/valibot.d.ts +1 -0
- package/dist/adapters/valibot.js +11 -0
- package/dist/adapters/yup.cjs +38 -0
- package/dist/adapters/yup.d.cts +1 -0
- package/dist/adapters/yup.d.ts +1 -0
- package/dist/adapters/yup.js +11 -0
- package/dist/adapters/zod.cjs +38 -0
- package/dist/adapters/zod.d.cts +1 -0
- package/dist/adapters/zod.d.ts +1 -0
- package/dist/adapters/zod.js +11 -0
- package/dist/effect-DIhhk_ck.d.cts +222 -0
- package/dist/effect-DIhhk_ck.d.ts +222 -0
- package/dist/index.cjs +737 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +714 -0
- package/package.json +215 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
interface BuiltInBase {
|
|
2
|
+
required?: boolean;
|
|
3
|
+
default?: unknown;
|
|
4
|
+
}
|
|
5
|
+
interface StringField extends BuiltInBase {
|
|
6
|
+
type: 'string';
|
|
7
|
+
default?: string;
|
|
8
|
+
minLength?: number;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
pattern?: RegExp;
|
|
11
|
+
}
|
|
12
|
+
interface NumberField extends BuiltInBase {
|
|
13
|
+
type: 'number';
|
|
14
|
+
default?: number;
|
|
15
|
+
min?: number;
|
|
16
|
+
max?: number;
|
|
17
|
+
}
|
|
18
|
+
interface BooleanField extends BuiltInBase {
|
|
19
|
+
type: 'boolean';
|
|
20
|
+
default?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface UrlField extends BuiltInBase {
|
|
23
|
+
type: 'url';
|
|
24
|
+
default?: string;
|
|
25
|
+
}
|
|
26
|
+
interface PortField extends BuiltInBase {
|
|
27
|
+
type: 'port';
|
|
28
|
+
default?: number;
|
|
29
|
+
}
|
|
30
|
+
interface EnumField<T extends readonly string[] = readonly string[]> extends BuiltInBase {
|
|
31
|
+
type: 'enum';
|
|
32
|
+
values: T;
|
|
33
|
+
default?: T[number];
|
|
34
|
+
}
|
|
35
|
+
interface JsonField extends BuiltInBase {
|
|
36
|
+
type: 'json';
|
|
37
|
+
default?: unknown;
|
|
38
|
+
}
|
|
39
|
+
type BuiltInFieldDef = StringField | NumberField | BooleanField | UrlField | PortField | EnumField<readonly string[]> | JsonField;
|
|
40
|
+
|
|
41
|
+
type ValidationResult<T = unknown> = {
|
|
42
|
+
success: true;
|
|
43
|
+
value: T;
|
|
44
|
+
} | {
|
|
45
|
+
success: false;
|
|
46
|
+
error: string;
|
|
47
|
+
};
|
|
48
|
+
interface EnvSafeValidator {
|
|
49
|
+
validate(value: string | undefined): ValidationResult;
|
|
50
|
+
}
|
|
51
|
+
interface CustomValidateField<T = unknown> {
|
|
52
|
+
validate: (value: string | undefined) => ValidationResult<T>;
|
|
53
|
+
}
|
|
54
|
+
interface CreateEnvOptions {
|
|
55
|
+
source?: Record<string, string | undefined>;
|
|
56
|
+
onError?: 'throw' | 'warn' | ((error: EnvSafeError) => void);
|
|
57
|
+
dotenv?: boolean | string;
|
|
58
|
+
prefix?: string;
|
|
59
|
+
}
|
|
60
|
+
declare class EnvSafeError extends Error {
|
|
61
|
+
readonly errors: ReadonlyArray<{
|
|
62
|
+
key: string;
|
|
63
|
+
message: string;
|
|
64
|
+
}>;
|
|
65
|
+
constructor(errors: Array<{
|
|
66
|
+
key: string;
|
|
67
|
+
message: string;
|
|
68
|
+
}>);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Maps a built-in field definition to its output TypeScript type.
|
|
72
|
+
*/
|
|
73
|
+
type BuiltInOutputType<F> = F extends EnumField<infer V> ? V[number] : F extends {
|
|
74
|
+
type: 'number' | 'port';
|
|
75
|
+
} ? number : F extends {
|
|
76
|
+
type: 'boolean';
|
|
77
|
+
} ? boolean : F extends {
|
|
78
|
+
type: 'string' | 'url';
|
|
79
|
+
} ? string : F extends {
|
|
80
|
+
type: 'json';
|
|
81
|
+
} ? unknown : string;
|
|
82
|
+
/**
|
|
83
|
+
* Infers the output type of a single schema field.
|
|
84
|
+
*
|
|
85
|
+
* Uses structural conditional types to match phantom properties
|
|
86
|
+
* on each validator library's schema objects. This means no imports
|
|
87
|
+
* of external libraries are needed at the type level.
|
|
88
|
+
*/
|
|
89
|
+
type InferFieldOutput<F> = F extends BuiltInFieldDef ? BuiltInOutputType<F> : F extends {
|
|
90
|
+
validate: (value: string | undefined) => {
|
|
91
|
+
success: true;
|
|
92
|
+
value: infer T;
|
|
93
|
+
} | {
|
|
94
|
+
success: false;
|
|
95
|
+
error: string;
|
|
96
|
+
};
|
|
97
|
+
} ? T : F extends {
|
|
98
|
+
_zod: {
|
|
99
|
+
output: infer O;
|
|
100
|
+
};
|
|
101
|
+
} ? O : F extends {
|
|
102
|
+
_output: infer O;
|
|
103
|
+
} ? O : F extends {
|
|
104
|
+
__outputType: infer O;
|
|
105
|
+
} ? O : F extends {
|
|
106
|
+
'~standard': {
|
|
107
|
+
types: {
|
|
108
|
+
output: infer O;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
} ? O : F extends {
|
|
112
|
+
inferOut: infer O;
|
|
113
|
+
} ? O : F extends {
|
|
114
|
+
static: infer O;
|
|
115
|
+
} ? O : F extends {
|
|
116
|
+
TYPE: infer O;
|
|
117
|
+
} ? O : F extends {
|
|
118
|
+
guard(x: unknown): x is infer O;
|
|
119
|
+
} ? O : F extends {
|
|
120
|
+
Type: infer O;
|
|
121
|
+
} ? O : F extends {
|
|
122
|
+
_flags: Record<string, unknown>;
|
|
123
|
+
alphanum(): unknown;
|
|
124
|
+
email(): unknown;
|
|
125
|
+
} ? string : F extends {
|
|
126
|
+
_flags: Record<string, unknown>;
|
|
127
|
+
greater(limit: number): unknown;
|
|
128
|
+
integer(): unknown;
|
|
129
|
+
} ? number : F extends {
|
|
130
|
+
_flags: Record<string, unknown>;
|
|
131
|
+
truthy(...values: unknown[]): unknown;
|
|
132
|
+
falsy(...values: unknown[]): unknown;
|
|
133
|
+
} ? boolean : F extends {
|
|
134
|
+
_flags: Record<string, unknown>;
|
|
135
|
+
iso(): unknown;
|
|
136
|
+
timestamp(): unknown;
|
|
137
|
+
} ? Date : unknown;
|
|
138
|
+
/**
|
|
139
|
+
* Maps an entire field-by-field schema object to its output type.
|
|
140
|
+
*/
|
|
141
|
+
type InferEnvOutput<S extends Record<string, unknown>> = {
|
|
142
|
+
readonly [K in keyof S]: InferFieldOutput<S[K]>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Maps a Joi schema type to its output TypeScript type using structural matching.
|
|
146
|
+
* Reuses the same logic as the Joi branch in InferFieldOutput.
|
|
147
|
+
*/
|
|
148
|
+
type InferJoiFieldOutput<F> = F extends {
|
|
149
|
+
alphanum(): unknown;
|
|
150
|
+
email(): unknown;
|
|
151
|
+
} ? string : F extends {
|
|
152
|
+
greater(limit: number): unknown;
|
|
153
|
+
integer(): unknown;
|
|
154
|
+
} ? number : F extends {
|
|
155
|
+
truthy(...values: unknown[]): unknown;
|
|
156
|
+
falsy(...values: unknown[]): unknown;
|
|
157
|
+
} ? boolean : F extends {
|
|
158
|
+
iso(): unknown;
|
|
159
|
+
timestamp(): unknown;
|
|
160
|
+
} ? Date : unknown;
|
|
161
|
+
/**
|
|
162
|
+
* Maps a Joi schema shape (from joiObject) to its output type.
|
|
163
|
+
*/
|
|
164
|
+
type InferJoiObjectOutput<T> = {
|
|
165
|
+
[K in keyof T]: InferJoiFieldOutput<T[K]>;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Extracts the output type from an object-level validator schema.
|
|
169
|
+
*
|
|
170
|
+
* Uses structural conditional types matching phantom properties
|
|
171
|
+
* on each validator library's object/struct schema types.
|
|
172
|
+
*/
|
|
173
|
+
type InferObjectSchemaOutput<S> = S extends {
|
|
174
|
+
__joiShape: infer Shape extends Record<string, unknown>;
|
|
175
|
+
} ? InferJoiObjectOutput<Shape> : S extends {
|
|
176
|
+
_zod: {
|
|
177
|
+
output: infer O;
|
|
178
|
+
};
|
|
179
|
+
} ? O : S extends {
|
|
180
|
+
_output: infer O;
|
|
181
|
+
} ? O : S extends {
|
|
182
|
+
__outputType: infer O;
|
|
183
|
+
} ? O : S extends {
|
|
184
|
+
inferOut: infer O;
|
|
185
|
+
} ? O : S extends {
|
|
186
|
+
static: infer O;
|
|
187
|
+
} ? O : S extends {
|
|
188
|
+
TYPE: infer O;
|
|
189
|
+
} ? O : S extends {
|
|
190
|
+
guard(x: unknown): x is infer O;
|
|
191
|
+
} ? O : S extends {
|
|
192
|
+
Type: infer O;
|
|
193
|
+
} ? O : S extends {
|
|
194
|
+
'~standard': {
|
|
195
|
+
types?: infer T;
|
|
196
|
+
};
|
|
197
|
+
} ? NonNullable<T> extends {
|
|
198
|
+
output: infer O;
|
|
199
|
+
} ? O : unknown : unknown;
|
|
200
|
+
/**
|
|
201
|
+
* Detects whether S is an object-level validator schema (e.g. z.object(), yup.object())
|
|
202
|
+
* or a field-by-field record of individual validators.
|
|
203
|
+
*
|
|
204
|
+
* When an object-level schema is passed, the output type is extracted directly
|
|
205
|
+
* from the validator's phantom types. Otherwise, falls back to per-field inference.
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* Helper: true when T is `any`.
|
|
209
|
+
* Uses the fact that `0 extends (1 & T)` is true only for `any`.
|
|
210
|
+
*/
|
|
211
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
212
|
+
type InferSchemaOutput<S> = InferObjectSchemaOutput<S> extends infer O ? IsAny<O> extends true ? Readonly<Record<string, unknown>> : [O] extends [Record<string, unknown>] ? Readonly<O> : S extends Record<string, unknown> ? InferEnvOutput<S> : Readonly<Record<string, unknown>> : never;
|
|
213
|
+
type SchemaInput = Record<string, unknown>;
|
|
214
|
+
|
|
215
|
+
interface RuntimeAdapter {
|
|
216
|
+
name: string;
|
|
217
|
+
detect(field: unknown): boolean;
|
|
218
|
+
validate(field: unknown, raw: string | undefined, key: string): ValidationResult;
|
|
219
|
+
}
|
|
220
|
+
declare function registerAdapter(adapter: RuntimeAdapter): void;
|
|
221
|
+
|
|
222
|
+
export { type BooleanField as B, type CreateEnvOptions as C, type EnumField as E, type InferSchemaOutput as I, type JsonField as J, type NumberField as N, type PortField as P, type SchemaInput as S, type UrlField as U, type ValidationResult as V, type BuiltInFieldDef as a, type CustomValidateField as b, EnvSafeError as c, type EnvSafeValidator as d, type InferEnvOutput as e, type InferFieldOutput as f, type StringField as g, registerAdapter as r };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
interface BuiltInBase {
|
|
2
|
+
required?: boolean;
|
|
3
|
+
default?: unknown;
|
|
4
|
+
}
|
|
5
|
+
interface StringField extends BuiltInBase {
|
|
6
|
+
type: 'string';
|
|
7
|
+
default?: string;
|
|
8
|
+
minLength?: number;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
pattern?: RegExp;
|
|
11
|
+
}
|
|
12
|
+
interface NumberField extends BuiltInBase {
|
|
13
|
+
type: 'number';
|
|
14
|
+
default?: number;
|
|
15
|
+
min?: number;
|
|
16
|
+
max?: number;
|
|
17
|
+
}
|
|
18
|
+
interface BooleanField extends BuiltInBase {
|
|
19
|
+
type: 'boolean';
|
|
20
|
+
default?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface UrlField extends BuiltInBase {
|
|
23
|
+
type: 'url';
|
|
24
|
+
default?: string;
|
|
25
|
+
}
|
|
26
|
+
interface PortField extends BuiltInBase {
|
|
27
|
+
type: 'port';
|
|
28
|
+
default?: number;
|
|
29
|
+
}
|
|
30
|
+
interface EnumField<T extends readonly string[] = readonly string[]> extends BuiltInBase {
|
|
31
|
+
type: 'enum';
|
|
32
|
+
values: T;
|
|
33
|
+
default?: T[number];
|
|
34
|
+
}
|
|
35
|
+
interface JsonField extends BuiltInBase {
|
|
36
|
+
type: 'json';
|
|
37
|
+
default?: unknown;
|
|
38
|
+
}
|
|
39
|
+
type BuiltInFieldDef = StringField | NumberField | BooleanField | UrlField | PortField | EnumField<readonly string[]> | JsonField;
|
|
40
|
+
|
|
41
|
+
type ValidationResult<T = unknown> = {
|
|
42
|
+
success: true;
|
|
43
|
+
value: T;
|
|
44
|
+
} | {
|
|
45
|
+
success: false;
|
|
46
|
+
error: string;
|
|
47
|
+
};
|
|
48
|
+
interface EnvSafeValidator {
|
|
49
|
+
validate(value: string | undefined): ValidationResult;
|
|
50
|
+
}
|
|
51
|
+
interface CustomValidateField<T = unknown> {
|
|
52
|
+
validate: (value: string | undefined) => ValidationResult<T>;
|
|
53
|
+
}
|
|
54
|
+
interface CreateEnvOptions {
|
|
55
|
+
source?: Record<string, string | undefined>;
|
|
56
|
+
onError?: 'throw' | 'warn' | ((error: EnvSafeError) => void);
|
|
57
|
+
dotenv?: boolean | string;
|
|
58
|
+
prefix?: string;
|
|
59
|
+
}
|
|
60
|
+
declare class EnvSafeError extends Error {
|
|
61
|
+
readonly errors: ReadonlyArray<{
|
|
62
|
+
key: string;
|
|
63
|
+
message: string;
|
|
64
|
+
}>;
|
|
65
|
+
constructor(errors: Array<{
|
|
66
|
+
key: string;
|
|
67
|
+
message: string;
|
|
68
|
+
}>);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Maps a built-in field definition to its output TypeScript type.
|
|
72
|
+
*/
|
|
73
|
+
type BuiltInOutputType<F> = F extends EnumField<infer V> ? V[number] : F extends {
|
|
74
|
+
type: 'number' | 'port';
|
|
75
|
+
} ? number : F extends {
|
|
76
|
+
type: 'boolean';
|
|
77
|
+
} ? boolean : F extends {
|
|
78
|
+
type: 'string' | 'url';
|
|
79
|
+
} ? string : F extends {
|
|
80
|
+
type: 'json';
|
|
81
|
+
} ? unknown : string;
|
|
82
|
+
/**
|
|
83
|
+
* Infers the output type of a single schema field.
|
|
84
|
+
*
|
|
85
|
+
* Uses structural conditional types to match phantom properties
|
|
86
|
+
* on each validator library's schema objects. This means no imports
|
|
87
|
+
* of external libraries are needed at the type level.
|
|
88
|
+
*/
|
|
89
|
+
type InferFieldOutput<F> = F extends BuiltInFieldDef ? BuiltInOutputType<F> : F extends {
|
|
90
|
+
validate: (value: string | undefined) => {
|
|
91
|
+
success: true;
|
|
92
|
+
value: infer T;
|
|
93
|
+
} | {
|
|
94
|
+
success: false;
|
|
95
|
+
error: string;
|
|
96
|
+
};
|
|
97
|
+
} ? T : F extends {
|
|
98
|
+
_zod: {
|
|
99
|
+
output: infer O;
|
|
100
|
+
};
|
|
101
|
+
} ? O : F extends {
|
|
102
|
+
_output: infer O;
|
|
103
|
+
} ? O : F extends {
|
|
104
|
+
__outputType: infer O;
|
|
105
|
+
} ? O : F extends {
|
|
106
|
+
'~standard': {
|
|
107
|
+
types: {
|
|
108
|
+
output: infer O;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
} ? O : F extends {
|
|
112
|
+
inferOut: infer O;
|
|
113
|
+
} ? O : F extends {
|
|
114
|
+
static: infer O;
|
|
115
|
+
} ? O : F extends {
|
|
116
|
+
TYPE: infer O;
|
|
117
|
+
} ? O : F extends {
|
|
118
|
+
guard(x: unknown): x is infer O;
|
|
119
|
+
} ? O : F extends {
|
|
120
|
+
Type: infer O;
|
|
121
|
+
} ? O : F extends {
|
|
122
|
+
_flags: Record<string, unknown>;
|
|
123
|
+
alphanum(): unknown;
|
|
124
|
+
email(): unknown;
|
|
125
|
+
} ? string : F extends {
|
|
126
|
+
_flags: Record<string, unknown>;
|
|
127
|
+
greater(limit: number): unknown;
|
|
128
|
+
integer(): unknown;
|
|
129
|
+
} ? number : F extends {
|
|
130
|
+
_flags: Record<string, unknown>;
|
|
131
|
+
truthy(...values: unknown[]): unknown;
|
|
132
|
+
falsy(...values: unknown[]): unknown;
|
|
133
|
+
} ? boolean : F extends {
|
|
134
|
+
_flags: Record<string, unknown>;
|
|
135
|
+
iso(): unknown;
|
|
136
|
+
timestamp(): unknown;
|
|
137
|
+
} ? Date : unknown;
|
|
138
|
+
/**
|
|
139
|
+
* Maps an entire field-by-field schema object to its output type.
|
|
140
|
+
*/
|
|
141
|
+
type InferEnvOutput<S extends Record<string, unknown>> = {
|
|
142
|
+
readonly [K in keyof S]: InferFieldOutput<S[K]>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Maps a Joi schema type to its output TypeScript type using structural matching.
|
|
146
|
+
* Reuses the same logic as the Joi branch in InferFieldOutput.
|
|
147
|
+
*/
|
|
148
|
+
type InferJoiFieldOutput<F> = F extends {
|
|
149
|
+
alphanum(): unknown;
|
|
150
|
+
email(): unknown;
|
|
151
|
+
} ? string : F extends {
|
|
152
|
+
greater(limit: number): unknown;
|
|
153
|
+
integer(): unknown;
|
|
154
|
+
} ? number : F extends {
|
|
155
|
+
truthy(...values: unknown[]): unknown;
|
|
156
|
+
falsy(...values: unknown[]): unknown;
|
|
157
|
+
} ? boolean : F extends {
|
|
158
|
+
iso(): unknown;
|
|
159
|
+
timestamp(): unknown;
|
|
160
|
+
} ? Date : unknown;
|
|
161
|
+
/**
|
|
162
|
+
* Maps a Joi schema shape (from joiObject) to its output type.
|
|
163
|
+
*/
|
|
164
|
+
type InferJoiObjectOutput<T> = {
|
|
165
|
+
[K in keyof T]: InferJoiFieldOutput<T[K]>;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Extracts the output type from an object-level validator schema.
|
|
169
|
+
*
|
|
170
|
+
* Uses structural conditional types matching phantom properties
|
|
171
|
+
* on each validator library's object/struct schema types.
|
|
172
|
+
*/
|
|
173
|
+
type InferObjectSchemaOutput<S> = S extends {
|
|
174
|
+
__joiShape: infer Shape extends Record<string, unknown>;
|
|
175
|
+
} ? InferJoiObjectOutput<Shape> : S extends {
|
|
176
|
+
_zod: {
|
|
177
|
+
output: infer O;
|
|
178
|
+
};
|
|
179
|
+
} ? O : S extends {
|
|
180
|
+
_output: infer O;
|
|
181
|
+
} ? O : S extends {
|
|
182
|
+
__outputType: infer O;
|
|
183
|
+
} ? O : S extends {
|
|
184
|
+
inferOut: infer O;
|
|
185
|
+
} ? O : S extends {
|
|
186
|
+
static: infer O;
|
|
187
|
+
} ? O : S extends {
|
|
188
|
+
TYPE: infer O;
|
|
189
|
+
} ? O : S extends {
|
|
190
|
+
guard(x: unknown): x is infer O;
|
|
191
|
+
} ? O : S extends {
|
|
192
|
+
Type: infer O;
|
|
193
|
+
} ? O : S extends {
|
|
194
|
+
'~standard': {
|
|
195
|
+
types?: infer T;
|
|
196
|
+
};
|
|
197
|
+
} ? NonNullable<T> extends {
|
|
198
|
+
output: infer O;
|
|
199
|
+
} ? O : unknown : unknown;
|
|
200
|
+
/**
|
|
201
|
+
* Detects whether S is an object-level validator schema (e.g. z.object(), yup.object())
|
|
202
|
+
* or a field-by-field record of individual validators.
|
|
203
|
+
*
|
|
204
|
+
* When an object-level schema is passed, the output type is extracted directly
|
|
205
|
+
* from the validator's phantom types. Otherwise, falls back to per-field inference.
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* Helper: true when T is `any`.
|
|
209
|
+
* Uses the fact that `0 extends (1 & T)` is true only for `any`.
|
|
210
|
+
*/
|
|
211
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
212
|
+
type InferSchemaOutput<S> = InferObjectSchemaOutput<S> extends infer O ? IsAny<O> extends true ? Readonly<Record<string, unknown>> : [O] extends [Record<string, unknown>] ? Readonly<O> : S extends Record<string, unknown> ? InferEnvOutput<S> : Readonly<Record<string, unknown>> : never;
|
|
213
|
+
type SchemaInput = Record<string, unknown>;
|
|
214
|
+
|
|
215
|
+
interface RuntimeAdapter {
|
|
216
|
+
name: string;
|
|
217
|
+
detect(field: unknown): boolean;
|
|
218
|
+
validate(field: unknown, raw: string | undefined, key: string): ValidationResult;
|
|
219
|
+
}
|
|
220
|
+
declare function registerAdapter(adapter: RuntimeAdapter): void;
|
|
221
|
+
|
|
222
|
+
export { type BooleanField as B, type CreateEnvOptions as C, type EnumField as E, type InferSchemaOutput as I, type JsonField as J, type NumberField as N, type PortField as P, type SchemaInput as S, type UrlField as U, type ValidationResult as V, type BuiltInFieldDef as a, type CustomValidateField as b, EnvSafeError as c, type EnvSafeValidator as d, type InferEnvOutput as e, type InferFieldOutput as f, type StringField as g, registerAdapter as r };
|