@railway-ts/pipelines 0.1.30 → 0.2.1
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/README.md +4 -4
- package/dist/composition/index.d.mts +367 -0
- package/dist/composition/index.mjs +37 -59
- package/dist/composition/index.mjs.map +1 -1
- package/dist/{result/index.d.cts → index-DDkNG41b.d.mts} +63 -139
- package/dist/option/index.d.mts +7 -0
- package/dist/option/index.mjs +1 -114
- package/dist/option-BQCaaEBP.mjs +909 -0
- package/dist/option-BQCaaEBP.mjs.map +1 -0
- package/dist/result/index.d.mts +7 -0
- package/dist/result/index.mjs +1 -185
- package/dist/schema/{index.d.cts → index.d.mts} +227 -259
- package/dist/schema/index.mjs +1646 -978
- package/dist/schema/index.mjs.map +1 -1
- package/docs/GETTING_STARTED.md +1 -1
- package/docs/RECIPES.md +3 -3
- package/package.json +26 -70
- package/dist/composition/index.cjs +0 -94
- package/dist/composition/index.cjs.map +0 -1
- package/dist/composition/index.d.cts +0 -373
- package/dist/composition/index.d.ts +0 -373
- package/dist/option/index.cjs +0 -137
- package/dist/option/index.cjs.map +0 -1
- package/dist/option/index.d.cts +0 -1
- package/dist/option/index.d.ts +0 -1
- package/dist/option/index.mjs.map +0 -1
- package/dist/result/index.cjs +0 -219
- package/dist/result/index.cjs.map +0 -1
- package/dist/result/index.d.ts +0 -1063
- package/dist/result/index.mjs.map +0 -1
- package/dist/schema/index.cjs +0 -1165
- package/dist/schema/index.cjs.map +0 -1
- package/dist/schema/index.d.ts +0 -1266
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Schema validation functions for functional programming
|
|
3
|
+
*
|
|
4
|
+
* @module schema
|
|
5
|
+
*/
|
|
6
|
+
import { T as Result$1 } from "../index-DDkNG41b.mjs";
|
|
3
7
|
/**
|
|
4
8
|
* Represents a validation error with path information and a message.
|
|
5
9
|
*/
|
|
6
|
-
type ValidationError = {
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
export type ValidationError = {
|
|
11
|
+
path: string[];
|
|
12
|
+
message: string;
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
15
|
* A synchronous validator function that checks if a value meets certain criteria.
|
|
@@ -14,7 +18,7 @@ type ValidationError = {
|
|
|
14
18
|
* @param path - The path to the current value (used for nested objects)
|
|
15
19
|
* @returns A Result containing either the validated value or validation errors
|
|
16
20
|
*/
|
|
17
|
-
type Validator<I, O = I> = (value: I, path?: string[]) => Result<O, ValidationError[]>;
|
|
21
|
+
export type Validator<I, O = I> = (value: I, path?: string[]) => Result$1<O, ValidationError[]>;
|
|
18
22
|
/**
|
|
19
23
|
* An asynchronous validator function that always returns a Promise.
|
|
20
24
|
*
|
|
@@ -22,7 +26,7 @@ type Validator<I, O = I> = (value: I, path?: string[]) => Result<O, ValidationEr
|
|
|
22
26
|
* @param path - The path to the current value (used for nested objects)
|
|
23
27
|
* @returns A Promise resolving to a Result
|
|
24
28
|
*/
|
|
25
|
-
type AsyncValidator<I, O = I> = (value: I, path?: string[]) => Promise<Result<O, ValidationError[]>>;
|
|
29
|
+
export type AsyncValidator<I, O = I> = (value: I, path?: string[]) => Promise<Result$1<O, ValidationError[]>>;
|
|
26
30
|
/**
|
|
27
31
|
* A validator function that may return either a synchronous Result or a Promise.
|
|
28
32
|
* Use this type when a validator accepts both sync and async validators
|
|
@@ -32,55 +36,39 @@ type AsyncValidator<I, O = I> = (value: I, path?: string[]) => Promise<Result<O,
|
|
|
32
36
|
* @param path - The path to the current value (used for nested objects)
|
|
33
37
|
* @returns A Result or Promise of Result
|
|
34
38
|
*/
|
|
35
|
-
type MaybeAsyncValidator<I, O = I> = (value: I, path?: string[]) => Result<O, ValidationError[]> | Promise<Result<O, ValidationError[]>>;
|
|
39
|
+
export type MaybeAsyncValidator<I, O = I> = (value: I, path?: string[]) => Result$1<O, ValidationError[]> | Promise<Result$1<O, ValidationError[]>>;
|
|
36
40
|
/**
|
|
37
41
|
* Extracts the union of output types from a validator map.
|
|
38
42
|
* Used by {@link discriminatedUnion} to infer the output type from the map's validators.
|
|
39
43
|
*/
|
|
40
|
-
type ValidatorMapOutput<M extends Record<string, MaybeAsyncValidator<unknown, unknown>>> = {
|
|
41
|
-
[K in keyof M]: M[K] extends MaybeAsyncValidator<unknown, infer O> ? O : never;
|
|
42
|
-
}[keyof M];
|
|
44
|
+
export type ValidatorMapOutput<M extends Record<string, MaybeAsyncValidator<unknown, unknown>>> = { [K in keyof M]: M[K] extends MaybeAsyncValidator<unknown, infer O> ? O : never; }[keyof M];
|
|
43
45
|
type AtomicType = string | number | boolean | Date | null | undefined | bigint;
|
|
44
46
|
type RemoveUndefined<T> = T extends undefined ? never : T;
|
|
45
|
-
type ProcessType<T> = T extends AtomicType ? T : T extends readonly [unknown, ...unknown[]] ? {
|
|
46
|
-
[K in keyof T]: ProcessType<T[K]>;
|
|
47
|
-
} : T extends [unknown, ...unknown[]] ? {
|
|
48
|
-
[K in keyof T]: ProcessType<T[K]>;
|
|
49
|
-
} : T extends Array<infer U> ? Array<ProcessType<U>> : T extends object ? {
|
|
50
|
-
[K in keyof T as undefined extends T[K] ? never : K]: ProcessType<T[K]>;
|
|
51
|
-
} & {
|
|
52
|
-
[K in keyof T as undefined extends T[K] ? K : never]?: ProcessType<RemoveUndefined<T[K]>>;
|
|
53
|
-
} extends infer O ? {
|
|
54
|
-
[K in keyof O]: O[K];
|
|
55
|
-
} : never : T;
|
|
47
|
+
type ProcessType<T> = T extends AtomicType ? T : T extends readonly [unknown, ...unknown[]] ? { [K in keyof T]: ProcessType<T[K]>; } : T extends [unknown, ...unknown[]] ? { [K in keyof T]: ProcessType<T[K]>; } : T extends Array<infer U> ? Array<ProcessType<U>> : T extends object ? { [K in keyof T as undefined extends T[K] ? never : K]: ProcessType<T[K]>; } & { [K in keyof T as undefined extends T[K] ? K : never]?: ProcessType<RemoveUndefined<T[K]>>; } extends (infer O) ? { [K in keyof O]: O[K]; } : never : T;
|
|
56
48
|
type InferType<V> = V extends Validator<unknown, infer O> ? O : V extends AsyncValidator<unknown, infer O> ? O : V extends MaybeAsyncValidator<unknown, infer O> ? O : never;
|
|
57
49
|
/**
|
|
58
50
|
* Infer the output type of a validator or schema after processing.
|
|
59
51
|
* Useful for getting the TypeScript type that a validator will produce.
|
|
60
52
|
*/
|
|
61
|
-
type InferSchemaType<V> = ProcessType<InferType<V>>;
|
|
53
|
+
export type InferSchemaType<V> = ProcessType<InferType<V>>;
|
|
62
54
|
/**
|
|
63
55
|
* A validation schema where each key maps to a synchronous validator for that field.
|
|
64
56
|
*/
|
|
65
|
-
type SyncSchema<T = Record<string, unknown>> = {
|
|
66
|
-
[K in keyof T]: Validator<unknown, T[K]>;
|
|
67
|
-
};
|
|
57
|
+
export type SyncSchema<T = Record<string, unknown>> = { [K in keyof T]: Validator<unknown, T[K]>; };
|
|
68
58
|
/**
|
|
69
59
|
* A validation schema that accepts both sync and async validators.
|
|
70
60
|
* Use {@link SyncSchema} when all validators are synchronous to preserve sync return types.
|
|
71
61
|
*/
|
|
72
|
-
type Schema<T = Record<string, unknown>> = {
|
|
73
|
-
[K in keyof T]: MaybeAsyncValidator<unknown, T[K]>;
|
|
74
|
-
};
|
|
62
|
+
export type Schema<T = Record<string, unknown>> = { [K in keyof T]: MaybeAsyncValidator<unknown, T[K]>; };
|
|
75
63
|
/**
|
|
76
64
|
* The result of a validation operation.
|
|
77
65
|
*/
|
|
78
|
-
type ValidationResult<T> = {
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
export type ValidationResult<T> = {
|
|
67
|
+
valid: true;
|
|
68
|
+
data: T;
|
|
81
69
|
} | {
|
|
82
|
-
|
|
83
|
-
|
|
70
|
+
valid: false;
|
|
71
|
+
errors: Record<string, string>;
|
|
84
72
|
};
|
|
85
73
|
/**
|
|
86
74
|
* Create a validator for objects based on a schema.
|
|
@@ -96,11 +84,11 @@ type ValidationResult<T> = {
|
|
|
96
84
|
* @param options - Options object. `strict` (default true) rejects extra properties
|
|
97
85
|
* @returns A validator that validates objects against the schema
|
|
98
86
|
*/
|
|
99
|
-
declare function object<T extends Record<string, unknown>>(schema: SyncSchema<T>, options?: {
|
|
100
|
-
|
|
87
|
+
export declare function object<T extends Record<string, unknown>>(schema: SyncSchema<T>, options?: {
|
|
88
|
+
strict?: boolean;
|
|
101
89
|
}): Validator<unknown, T>;
|
|
102
|
-
declare function object<T extends Record<string, unknown>>(schema: Schema<T>, options?: {
|
|
103
|
-
|
|
90
|
+
export declare function object<T extends Record<string, unknown>>(schema: Schema<T>, options?: {
|
|
91
|
+
strict?: boolean;
|
|
104
92
|
}): MaybeAsyncValidator<unknown, T>;
|
|
105
93
|
/**
|
|
106
94
|
* Create a validator that requires a value to be defined (not null or undefined).
|
|
@@ -114,8 +102,8 @@ declare function object<T extends Record<string, unknown>>(schema: Schema<T>, op
|
|
|
114
102
|
* @param message - Error message when value is null or undefined
|
|
115
103
|
* @returns A validator that checks the value is defined
|
|
116
104
|
*/
|
|
117
|
-
declare function required<I, O>(validator: Validator<I, O>, message?: string): Validator<I | undefined | null, O>;
|
|
118
|
-
declare function required<I, O>(validator: MaybeAsyncValidator<I, O>, message?: string): MaybeAsyncValidator<I | undefined | null, O>;
|
|
105
|
+
export declare function required<I, O>(validator: Validator<I, O>, message?: string): Validator<I | undefined | null, O>;
|
|
106
|
+
export declare function required<I, O>(validator: MaybeAsyncValidator<I, O>, message?: string): MaybeAsyncValidator<I | undefined | null, O>;
|
|
119
107
|
/**
|
|
120
108
|
* Create a validator that makes a field optional.
|
|
121
109
|
* Returns undefined for null/undefined values, otherwise applies the validator.
|
|
@@ -128,8 +116,8 @@ declare function required<I, O>(validator: MaybeAsyncValidator<I, O>, message?:
|
|
|
128
116
|
* @param validator - The validator to apply if the value is defined
|
|
129
117
|
* @returns A validator that allows undefined values
|
|
130
118
|
*/
|
|
131
|
-
declare function optional<I, O>(validator: Validator<I, O>): Validator<I | undefined | null, O | undefined>;
|
|
132
|
-
declare function optional<I, O>(validator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<I | undefined | null, O | undefined>;
|
|
119
|
+
export declare function optional<I, O>(validator: Validator<I, O>): Validator<I | undefined | null, O | undefined>;
|
|
120
|
+
export declare function optional<I, O>(validator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<I | undefined | null, O | undefined>;
|
|
133
121
|
/**
|
|
134
122
|
* Create a validator that only accepts null values.
|
|
135
123
|
*
|
|
@@ -141,7 +129,7 @@ declare function optional<I, O>(validator: MaybeAsyncValidator<I, O>): MaybeAsyn
|
|
|
141
129
|
* @param message - Custom error message
|
|
142
130
|
* @returns A validator that ensures the value is exactly null
|
|
143
131
|
*/
|
|
144
|
-
declare function nullable(message?: string): Validator<unknown, null>;
|
|
132
|
+
export declare function nullable(message?: string): Validator<unknown, null>;
|
|
145
133
|
/**
|
|
146
134
|
* Create a validator that treats empty strings, empty arrays, and empty objects as optional.
|
|
147
135
|
*
|
|
@@ -155,8 +143,8 @@ declare function nullable(message?: string): Validator<unknown, null>;
|
|
|
155
143
|
* @param validator - The validator to apply if the value is not empty
|
|
156
144
|
* @returns A validator that treats empty values as undefined
|
|
157
145
|
*/
|
|
158
|
-
declare function emptyAsOptional<I, O>(validator: Validator<I, O>): Validator<I | undefined | null, O | undefined>;
|
|
159
|
-
declare function emptyAsOptional<I, O>(validator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<I | undefined | null, O | undefined>;
|
|
146
|
+
export declare function emptyAsOptional<I, O>(validator: Validator<I, O>): Validator<I | undefined | null, O | undefined>;
|
|
147
|
+
export declare function emptyAsOptional<I, O>(validator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<I | undefined | null, O | undefined>;
|
|
160
148
|
/**
|
|
161
149
|
* Create a validator that checks if a value exactly matches the expected literal.
|
|
162
150
|
*
|
|
@@ -169,32 +157,31 @@ declare function emptyAsOptional<I, O>(validator: MaybeAsyncValidator<I, O>): Ma
|
|
|
169
157
|
* @param message - Custom error message
|
|
170
158
|
* @returns A validator that checks if the value matches the literal
|
|
171
159
|
*/
|
|
172
|
-
declare function literal<T>(expectedValue: T, message?: string): Validator<unknown, T>;
|
|
173
|
-
|
|
160
|
+
export declare function literal<T>(expectedValue: T, message?: string): Validator<unknown, T>;
|
|
174
161
|
/**
|
|
175
162
|
* Options for controlling validation behavior.
|
|
176
163
|
*/
|
|
177
|
-
type ValidateOptions = {
|
|
178
|
-
|
|
164
|
+
export type ValidateOptions = {
|
|
165
|
+
abortEarly?: boolean;
|
|
179
166
|
};
|
|
180
167
|
/**
|
|
181
168
|
* The key used in formatted error objects for root-level validation errors (i.e. errors with an empty path).
|
|
182
169
|
*/
|
|
183
|
-
declare const ROOT_ERROR_KEY = "_root";
|
|
170
|
+
export declare const ROOT_ERROR_KEY = "_root";
|
|
184
171
|
/**
|
|
185
172
|
* Combine multiple validators into a single validator, applying them in sequence.
|
|
186
173
|
* Each validator's output feeds into the next. Short-circuits on first error.
|
|
187
174
|
*/
|
|
188
|
-
declare function chain<A, B>(v1: Validator<A, B>): Validator<A, B>;
|
|
189
|
-
declare function chain<A, B, C>(v1: Validator<A, B>, v2: Validator<B, C>): Validator<A, C>;
|
|
190
|
-
declare function chain<A, B, C, D>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>): Validator<A, D>;
|
|
191
|
-
declare function chain<A, B, C, D, E>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>): Validator<A, E>;
|
|
192
|
-
declare function chain<A, B, C, D, E, F>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>): Validator<A, F>;
|
|
193
|
-
declare function chain<A, B, C, D, E, F, G>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>): Validator<A, G>;
|
|
194
|
-
declare function chain<A, B, C, D, E, F, G, H>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>): Validator<A, H>;
|
|
195
|
-
declare function chain<A, B, C, D, E, F, G, H, I>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>): Validator<A, I>;
|
|
196
|
-
declare function chain<A, B, C, D, E, F, G, H, I, J>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>, v9: Validator<I, J>): Validator<A, J>;
|
|
197
|
-
declare function chain<A, B, C, D, E, F, G, H, I, J, K>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>, v9: Validator<I, J>, v10: Validator<J, K>): Validator<A, K>;
|
|
175
|
+
export declare function chain<A, B>(v1: Validator<A, B>): Validator<A, B>;
|
|
176
|
+
export declare function chain<A, B, C>(v1: Validator<A, B>, v2: Validator<B, C>): Validator<A, C>;
|
|
177
|
+
export declare function chain<A, B, C, D>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>): Validator<A, D>;
|
|
178
|
+
export declare function chain<A, B, C, D, E>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>): Validator<A, E>;
|
|
179
|
+
export declare function chain<A, B, C, D, E, F>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>): Validator<A, F>;
|
|
180
|
+
export declare function chain<A, B, C, D, E, F, G>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>): Validator<A, G>;
|
|
181
|
+
export declare function chain<A, B, C, D, E, F, G, H>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>): Validator<A, H>;
|
|
182
|
+
export declare function chain<A, B, C, D, E, F, G, H, I>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>): Validator<A, I>;
|
|
183
|
+
export declare function chain<A, B, C, D, E, F, G, H, I, J>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>, v9: Validator<I, J>): Validator<A, J>;
|
|
184
|
+
export declare function chain<A, B, C, D, E, F, G, H, I, J, K>(v1: Validator<A, B>, v2: Validator<B, C>, v3: Validator<C, D>, v4: Validator<D, E>, v5: Validator<E, F>, v6: Validator<F, G>, v7: Validator<G, H>, v8: Validator<H, I>, v9: Validator<I, J>, v10: Validator<J, K>): Validator<A, K>;
|
|
198
185
|
/**
|
|
199
186
|
* Combine multiple validators (sync or async) into a single async validator.
|
|
200
187
|
* Each validator's output feeds into the next. Short-circuits on first error.
|
|
@@ -211,16 +198,16 @@ declare function chain<A, B, C, D, E, F, G, H, I, J, K>(v1: Validator<A, B>, v2:
|
|
|
211
198
|
* @param validators - A list of sync or async validators to compose
|
|
212
199
|
* @returns A combined async validator that applies all validators in sequence
|
|
213
200
|
*/
|
|
214
|
-
declare function chainAsync<A, B>(v1: MaybeAsyncValidator<A, B>): AsyncValidator<A, B>;
|
|
215
|
-
declare function chainAsync<A, B, C>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>): AsyncValidator<A, C>;
|
|
216
|
-
declare function chainAsync<A, B, C, D>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>): AsyncValidator<A, D>;
|
|
217
|
-
declare function chainAsync<A, B, C, D, E>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>): AsyncValidator<A, E>;
|
|
218
|
-
declare function chainAsync<A, B, C, D, E, F>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>): AsyncValidator<A, F>;
|
|
219
|
-
declare function chainAsync<A, B, C, D, E, F, G>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>): AsyncValidator<A, G>;
|
|
220
|
-
declare function chainAsync<A, B, C, D, E, F, G, H>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>): AsyncValidator<A, H>;
|
|
221
|
-
declare function chainAsync<A, B, C, D, E, F, G, H, I>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>): AsyncValidator<A, I>;
|
|
222
|
-
declare function chainAsync<A, B, C, D, E, F, G, H, I, J>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>, v9: MaybeAsyncValidator<I, J>): AsyncValidator<A, J>;
|
|
223
|
-
declare function chainAsync<A, B, C, D, E, F, G, H, I, J, K>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>, v9: MaybeAsyncValidator<I, J>, v10: MaybeAsyncValidator<J, K>): AsyncValidator<A, K>;
|
|
201
|
+
export declare function chainAsync<A, B>(v1: MaybeAsyncValidator<A, B>): AsyncValidator<A, B>;
|
|
202
|
+
export declare function chainAsync<A, B, C>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>): AsyncValidator<A, C>;
|
|
203
|
+
export declare function chainAsync<A, B, C, D>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>): AsyncValidator<A, D>;
|
|
204
|
+
export declare function chainAsync<A, B, C, D, E>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>): AsyncValidator<A, E>;
|
|
205
|
+
export declare function chainAsync<A, B, C, D, E, F>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>): AsyncValidator<A, F>;
|
|
206
|
+
export declare function chainAsync<A, B, C, D, E, F, G>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>): AsyncValidator<A, G>;
|
|
207
|
+
export declare function chainAsync<A, B, C, D, E, F, G, H>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>): AsyncValidator<A, H>;
|
|
208
|
+
export declare function chainAsync<A, B, C, D, E, F, G, H, I>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>): AsyncValidator<A, I>;
|
|
209
|
+
export declare function chainAsync<A, B, C, D, E, F, G, H, I, J>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>, v9: MaybeAsyncValidator<I, J>): AsyncValidator<A, J>;
|
|
210
|
+
export declare function chainAsync<A, B, C, D, E, F, G, H, I, J, K>(v1: MaybeAsyncValidator<A, B>, v2: MaybeAsyncValidator<B, C>, v3: MaybeAsyncValidator<C, D>, v4: MaybeAsyncValidator<D, E>, v5: MaybeAsyncValidator<E, F>, v6: MaybeAsyncValidator<F, G>, v7: MaybeAsyncValidator<G, H>, v8: MaybeAsyncValidator<H, I>, v9: MaybeAsyncValidator<I, J>, v10: MaybeAsyncValidator<J, K>): AsyncValidator<A, K>;
|
|
224
211
|
/**
|
|
225
212
|
* Validate a value against a validator.
|
|
226
213
|
*
|
|
@@ -238,14 +225,14 @@ declare function chainAsync<A, B, C, D, E, F, G, H, I, J, K>(v1: MaybeAsyncValid
|
|
|
238
225
|
* @param maybeOptions - Options object when path is also provided
|
|
239
226
|
* @returns A Result containing either the validated value or validation errors
|
|
240
227
|
*/
|
|
241
|
-
declare function validate<T>(value: unknown, validator: Validator<unknown, T>): Result<T, ValidationError[]>;
|
|
242
|
-
declare function validate<T>(value: unknown, validator: Validator<unknown, T>, path: string[]): Result<T, ValidationError[]>;
|
|
243
|
-
declare function validate<T>(value: unknown, validator: Validator<unknown, T>, options: ValidateOptions): Result<T, ValidationError[]>;
|
|
244
|
-
declare function validate<T>(value: unknown, validator: Validator<unknown, T>, path: string[], options: ValidateOptions): Result<T, ValidationError[]>;
|
|
245
|
-
declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
|
|
246
|
-
declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[]): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
|
|
247
|
-
declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
|
|
248
|
-
declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[], options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
|
|
228
|
+
export declare function validate<T>(value: unknown, validator: Validator<unknown, T>): Result$1<T, ValidationError[]>;
|
|
229
|
+
export declare function validate<T>(value: unknown, validator: Validator<unknown, T>, path: string[]): Result$1<T, ValidationError[]>;
|
|
230
|
+
export declare function validate<T>(value: unknown, validator: Validator<unknown, T>, options: ValidateOptions): Result$1<T, ValidationError[]>;
|
|
231
|
+
export declare function validate<T>(value: unknown, validator: Validator<unknown, T>, path: string[], options: ValidateOptions): Result$1<T, ValidationError[]>;
|
|
232
|
+
export declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>): Result$1<T, ValidationError[]> | Promise<Result$1<T, ValidationError[]>>;
|
|
233
|
+
export declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[]): Result$1<T, ValidationError[]> | Promise<Result$1<T, ValidationError[]>>;
|
|
234
|
+
export declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, options: ValidateOptions): Result$1<T, ValidationError[]> | Promise<Result$1<T, ValidationError[]>>;
|
|
235
|
+
export declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[], options: ValidateOptions): Result$1<T, ValidationError[]> | Promise<Result$1<T, ValidationError[]>>;
|
|
249
236
|
/**
|
|
250
237
|
* Check whether a value satisfies a validator, returning a boolean.
|
|
251
238
|
* Always short-circuits on first error for maximum performance.
|
|
@@ -259,8 +246,8 @@ declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unkn
|
|
|
259
246
|
* @param validator - The validator to apply
|
|
260
247
|
* @returns `true` if valid, `false` otherwise (or a Promise for async validators)
|
|
261
248
|
*/
|
|
262
|
-
declare function is(value: unknown, validator: Validator<unknown, unknown>): boolean;
|
|
263
|
-
declare function is(value: unknown, validator: MaybeAsyncValidator<unknown, unknown>): boolean | Promise<boolean>;
|
|
249
|
+
export declare function is(value: unknown, validator: Validator<unknown, unknown>): boolean;
|
|
250
|
+
export declare function is(value: unknown, validator: MaybeAsyncValidator<unknown, unknown>): boolean | Promise<boolean>;
|
|
264
251
|
/**
|
|
265
252
|
* Format validation errors into a user-friendly object.
|
|
266
253
|
* Converts array paths to dot/bracket notation strings.
|
|
@@ -275,7 +262,7 @@ declare function is(value: unknown, validator: MaybeAsyncValidator<unknown, unkn
|
|
|
275
262
|
* @param errors - The array of validation errors to format
|
|
276
263
|
* @returns An object mapping paths to error messages
|
|
277
264
|
*/
|
|
278
|
-
declare function formatErrors(errors: ValidationError[]): Record<string, string>;
|
|
265
|
+
export declare function formatErrors(errors: ValidationError[]): Record<string, string>;
|
|
279
266
|
/**
|
|
280
267
|
* Validate input and return a formatted ValidationResult in one call.
|
|
281
268
|
* Combines validate() + formatErrors() + match() into a single operation.
|
|
@@ -289,8 +276,8 @@ declare function formatErrors(errors: ValidationError[]): Record<string, string>
|
|
|
289
276
|
* @param schema - The validator/schema to validate against
|
|
290
277
|
* @returns An object with either `{ valid: true, data }` or `{ valid: false, errors }`
|
|
291
278
|
*/
|
|
292
|
-
declare function validateAndFormatResult<T>(input: unknown, schema: Validator<unknown, T>, options?: ValidateOptions): ValidationResult<T>;
|
|
293
|
-
declare function validateAndFormatResult<T>(input: unknown, schema: MaybeAsyncValidator<unknown, T>, options?: ValidateOptions): ValidationResult<T> | Promise<ValidationResult<T>>;
|
|
279
|
+
export declare function validateAndFormatResult<T>(input: unknown, schema: Validator<unknown, T>, options?: ValidateOptions): ValidationResult<T>;
|
|
280
|
+
export declare function validateAndFormatResult<T>(input: unknown, schema: MaybeAsyncValidator<unknown, T>, options?: ValidateOptions): ValidationResult<T> | Promise<ValidationResult<T>>;
|
|
294
281
|
/**
|
|
295
282
|
* Create a validator that transforms a value during validation.
|
|
296
283
|
* The transformer function must be pure and not throw exceptions.
|
|
@@ -302,7 +289,7 @@ declare function validateAndFormatResult<T>(input: unknown, schema: MaybeAsyncVa
|
|
|
302
289
|
* @param transformer - A pure function that transforms the input value
|
|
303
290
|
* @returns A validator that applies the transformation
|
|
304
291
|
*/
|
|
305
|
-
declare function transform<I, O>(transformer: (value: I) => O): Validator<I, O>;
|
|
292
|
+
export declare function transform<I, O>(transformer: (value: I) => O): Validator<I, O>;
|
|
306
293
|
/**
|
|
307
294
|
* Create a validator that refines a value with a custom predicate.
|
|
308
295
|
*
|
|
@@ -315,7 +302,7 @@ declare function transform<I, O>(transformer: (value: I) => O): Validator<I, O>;
|
|
|
315
302
|
* @param message - The error message if validation fails
|
|
316
303
|
* @returns A validator that checks the predicate
|
|
317
304
|
*/
|
|
318
|
-
declare function refine<T>(predicate: (value: T) => boolean, message?: string): Validator<T, T>;
|
|
305
|
+
export declare function refine<T>(predicate: (value: T) => boolean, message?: string): Validator<T, T>;
|
|
319
306
|
/**
|
|
320
307
|
* Create an async validator that refines a value with an asynchronous predicate.
|
|
321
308
|
* This is the async counterpart of {@link refine}.
|
|
@@ -330,7 +317,7 @@ declare function refine<T>(predicate: (value: T) => boolean, message?: string):
|
|
|
330
317
|
* @param message - The error message if validation fails
|
|
331
318
|
* @returns An async validator that checks the predicate
|
|
332
319
|
*/
|
|
333
|
-
declare function refineAsync<T>(predicate: (value: T) => Promise<boolean>, message?: string): AsyncValidator<T, T>;
|
|
320
|
+
export declare function refineAsync<T>(predicate: (value: T) => Promise<boolean>, message?: string): AsyncValidator<T, T>;
|
|
334
321
|
/**
|
|
335
322
|
* Create a validator that targets a specific field path with cross-field validation.
|
|
336
323
|
* Unlike `refine`, receives the entire parent object and attaches errors to a specific field.
|
|
@@ -348,7 +335,7 @@ declare function refineAsync<T>(predicate: (value: T) => Promise<boolean>, messa
|
|
|
348
335
|
*
|
|
349
336
|
* @see refine - For single-field validation without cross-field dependencies
|
|
350
337
|
*/
|
|
351
|
-
declare function refineAt<T>(targetPath: string | string[], predicate: (value: T) => boolean, message: string): Validator<T, T>;
|
|
338
|
+
export declare function refineAt<T>(targetPath: string | string[], predicate: (value: T) => boolean, message: string): Validator<T, T>;
|
|
352
339
|
/**
|
|
353
340
|
* Create an async validator that targets a specific field path with cross-field validation.
|
|
354
341
|
* This is the async counterpart of {@link refineAt}.
|
|
@@ -370,7 +357,7 @@ declare function refineAt<T>(targetPath: string | string[], predicate: (value: T
|
|
|
370
357
|
*
|
|
371
358
|
* @see refineAt - For synchronous cross-field validation
|
|
372
359
|
*/
|
|
373
|
-
declare function refineAtAsync<T>(targetPath: string | string[], predicate: (value: T) => Promise<boolean>, message: string): AsyncValidator<T, T>;
|
|
360
|
+
export declare function refineAtAsync<T>(targetPath: string | string[], predicate: (value: T) => Promise<boolean>, message: string): AsyncValidator<T, T>;
|
|
374
361
|
/**
|
|
375
362
|
* Create a conditional validator that applies different validators based on a predicate.
|
|
376
363
|
* When the predicate returns true, `thenValidator` is applied.
|
|
@@ -388,7 +375,7 @@ declare function refineAtAsync<T>(targetPath: string | string[], predicate: (val
|
|
|
388
375
|
* @param elseValidator - Optional validator applied when predicate returns false
|
|
389
376
|
* @returns A validator that conditionally applies validation
|
|
390
377
|
*/
|
|
391
|
-
declare function when<T>(predicate: (data: T) => boolean, thenValidator: Validator<T, T>, elseValidator?: Validator<T, T>): Validator<T, T>;
|
|
378
|
+
export declare function when<T>(predicate: (data: T) => boolean, thenValidator: Validator<T, T>, elseValidator?: Validator<T, T>): Validator<T, T>;
|
|
392
379
|
/**
|
|
393
380
|
* Create a conditional async validator that applies different validators based on a predicate.
|
|
394
381
|
* This is the async counterpart of {@link when}.
|
|
@@ -404,8 +391,7 @@ declare function when<T>(predicate: (data: T) => boolean, thenValidator: Validat
|
|
|
404
391
|
* @param elseValidator - Optional validator applied when predicate returns false
|
|
405
392
|
* @returns An async validator that conditionally applies validation
|
|
406
393
|
*/
|
|
407
|
-
declare function whenAsync<T>(predicate: (data: T) => boolean, thenValidator: MaybeAsyncValidator<T, T>, elseValidator?: MaybeAsyncValidator<T, T>): AsyncValidator<T, T>;
|
|
408
|
-
|
|
394
|
+
export declare function whenAsync<T>(predicate: (data: T) => boolean, thenValidator: MaybeAsyncValidator<T, T>, elseValidator?: MaybeAsyncValidator<T, T>): AsyncValidator<T, T>;
|
|
409
395
|
/**
|
|
410
396
|
* Create a validator for arrays where each item is validated by the provided validator.
|
|
411
397
|
*
|
|
@@ -417,8 +403,8 @@ declare function whenAsync<T>(predicate: (data: T) => boolean, thenValidator: Ma
|
|
|
417
403
|
* @param itemValidator - The validator to apply to each array item
|
|
418
404
|
* @returns A validator that validates arrays of items
|
|
419
405
|
*/
|
|
420
|
-
declare function array<I, O>(itemValidator: Validator<I, O>): Validator<unknown, O[]>;
|
|
421
|
-
declare function array<I, O>(itemValidator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<unknown, O[]>;
|
|
406
|
+
export declare function array<I, O>(itemValidator: Validator<I, O>): Validator<unknown, O[]>;
|
|
407
|
+
export declare function array<I, O>(itemValidator: MaybeAsyncValidator<I, O>): MaybeAsyncValidator<unknown, O[]>;
|
|
422
408
|
/**
|
|
423
409
|
* Validate that an array has at least a minimum number of items.
|
|
424
410
|
*
|
|
@@ -431,7 +417,7 @@ declare function array<I, O>(itemValidator: MaybeAsyncValidator<I, O>): MaybeAsy
|
|
|
431
417
|
* @param message - Custom error message
|
|
432
418
|
* @returns A validator that checks minimum array length
|
|
433
419
|
*/
|
|
434
|
-
declare function minItems<T>(min: number, message?: string): Validator<T[], T[]>;
|
|
420
|
+
export declare function minItems<T>(min: number, message?: string): Validator<T[], T[]>;
|
|
435
421
|
/**
|
|
436
422
|
* Validate that an array has at most a maximum number of items.
|
|
437
423
|
*
|
|
@@ -444,7 +430,7 @@ declare function minItems<T>(min: number, message?: string): Validator<T[], T[]>
|
|
|
444
430
|
* @param message - Custom error message
|
|
445
431
|
* @returns A validator that checks maximum array length
|
|
446
432
|
*/
|
|
447
|
-
declare function maxItems<T>(max: number, message?: string): Validator<T[], T[]>;
|
|
433
|
+
export declare function maxItems<T>(max: number, message?: string): Validator<T[], T[]>;
|
|
448
434
|
/**
|
|
449
435
|
* Validate that an array is not empty.
|
|
450
436
|
*
|
|
@@ -456,7 +442,7 @@ declare function maxItems<T>(max: number, message?: string): Validator<T[], T[]>
|
|
|
456
442
|
* @param message - Custom error message
|
|
457
443
|
* @returns A validator that checks the array is not empty
|
|
458
444
|
*/
|
|
459
|
-
declare function notEmpty<T>(message?: string): Validator<T[], T[]>;
|
|
445
|
+
export declare function notEmpty<T>(message?: string): Validator<T[], T[]>;
|
|
460
446
|
/**
|
|
461
447
|
* Validate that an array contains only unique values.
|
|
462
448
|
*
|
|
@@ -473,7 +459,7 @@ declare function notEmpty<T>(message?: string): Validator<T[], T[]>;
|
|
|
473
459
|
* @param keyExtractor - Optional function to extract a comparison key from each item
|
|
474
460
|
* @returns A validator that checks for unique array values
|
|
475
461
|
*/
|
|
476
|
-
declare function unique<T>(message?: string, keyExtractor?: (item: T) => unknown): Validator<T[], T[]>;
|
|
462
|
+
export declare function unique<T>(message?: string, keyExtractor?: (item: T) => unknown): Validator<T[], T[]>;
|
|
477
463
|
/**
|
|
478
464
|
* Create a validator that ensures a value is one of the allowed values.
|
|
479
465
|
*
|
|
@@ -486,7 +472,7 @@ declare function unique<T>(message?: string, keyExtractor?: (item: T) => unknown
|
|
|
486
472
|
* @param message - Custom error message
|
|
487
473
|
* @returns A validator that checks if a value is in the allowed list
|
|
488
474
|
*/
|
|
489
|
-
declare function oneOf<T>(allowedValues: T[], message?: string): Validator<T>;
|
|
475
|
+
export declare function oneOf<T>(allowedValues: T[], message?: string): Validator<T>;
|
|
490
476
|
/**
|
|
491
477
|
* Create a validator that ensures a value is a string and one of the allowed enum values.
|
|
492
478
|
*
|
|
@@ -500,8 +486,13 @@ declare function oneOf<T>(allowedValues: T[], message?: string): Validator<T>;
|
|
|
500
486
|
* @param message - Custom error message
|
|
501
487
|
* @returns A validator that checks if a value is a string and in the allowed list
|
|
502
488
|
*/
|
|
503
|
-
declare function stringEnum<T extends string>(allowedValues: T[], message?: string): Validator<unknown, T>;
|
|
504
|
-
|
|
489
|
+
export declare function stringEnum<T extends string>(allowedValues: T[], message?: string): Validator<unknown, T>;
|
|
490
|
+
/**
|
|
491
|
+
* Extracts output types from an array of validators into a tuple type.
|
|
492
|
+
* Not exported, but kept in the published declarations because `tuple()`'s
|
|
493
|
+
* signature uses it.
|
|
494
|
+
*/
|
|
495
|
+
type TupleType<V extends ReadonlyArray<MaybeAsyncValidator<unknown, unknown>>> = { [K in keyof V]: V[K] extends Validator<unknown, infer O> ? O : V[K] extends MaybeAsyncValidator<unknown, infer O> ? O : never; };
|
|
505
496
|
/**
|
|
506
497
|
* Validate a heterogeneous tuple where each position has its own validator.
|
|
507
498
|
*
|
|
@@ -513,8 +504,8 @@ declare function stringEnum<T extends string>(allowedValues: T[], message?: stri
|
|
|
513
504
|
* @param validators - Array of validators, one for each tuple position
|
|
514
505
|
* @returns A validator that ensures the input is a tuple matching the validator array
|
|
515
506
|
*/
|
|
516
|
-
declare function tuple<V extends ReadonlyArray<Validator<unknown, unknown>>>(validators: V): Validator<unknown, TupleType<V>>;
|
|
517
|
-
declare function tuple<V extends ReadonlyArray<MaybeAsyncValidator<unknown, unknown>>>(validators: V): MaybeAsyncValidator<unknown, TupleType<V>>;
|
|
507
|
+
export declare function tuple<V extends ReadonlyArray<Validator<unknown, unknown>>>(validators: V): Validator<unknown, TupleType<V>>;
|
|
508
|
+
export declare function tuple<V extends ReadonlyArray<MaybeAsyncValidator<unknown, unknown>>>(validators: V): MaybeAsyncValidator<unknown, TupleType<V>>;
|
|
518
509
|
/**
|
|
519
510
|
* Validate a homogeneous tuple where all elements share the same type and fixed length.
|
|
520
511
|
*
|
|
@@ -527,29 +518,28 @@ declare function tuple<V extends ReadonlyArray<MaybeAsyncValidator<unknown, unkn
|
|
|
527
518
|
* @param length - Fixed length of the tuple
|
|
528
519
|
* @returns A validator that ensures the input is a tuple of the specified length
|
|
529
520
|
*/
|
|
530
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 1): Validator<unknown, [T]>;
|
|
531
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 1): MaybeAsyncValidator<unknown, [T]>;
|
|
532
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 2): Validator<unknown, [T, T]>;
|
|
533
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 2): MaybeAsyncValidator<unknown, [T, T]>;
|
|
534
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 3): Validator<unknown, [T, T, T]>;
|
|
535
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 3): MaybeAsyncValidator<unknown, [T, T, T]>;
|
|
536
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 4): Validator<unknown, [T, T, T, T]>;
|
|
537
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 4): MaybeAsyncValidator<unknown, [T, T, T, T]>;
|
|
538
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 5): Validator<unknown, [T, T, T, T, T]>;
|
|
539
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 5): MaybeAsyncValidator<unknown, [T, T, T, T, T]>;
|
|
540
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 6): Validator<unknown, [T, T, T, T, T, T]>;
|
|
541
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 6): MaybeAsyncValidator<unknown, [T, T, T, T, T, T]>;
|
|
542
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 7): Validator<unknown, [T, T, T, T, T, T, T]>;
|
|
543
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 7): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T]>;
|
|
544
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 8): Validator<unknown, [T, T, T, T, T, T, T, T]>;
|
|
545
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 8): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T]>;
|
|
546
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 9): Validator<unknown, [T, T, T, T, T, T, T, T, T]>;
|
|
547
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 9): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T, T]>;
|
|
548
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 10): Validator<unknown, [T, T, T, T, T, T, T, T, T, T]>;
|
|
549
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 10): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T, T, T]>;
|
|
550
|
-
declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: number): Validator<unknown, T[]>;
|
|
551
|
-
declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: number): MaybeAsyncValidator<unknown, T[]>;
|
|
552
|
-
|
|
521
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 1): Validator<unknown, [T]>;
|
|
522
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 1): MaybeAsyncValidator<unknown, [T]>;
|
|
523
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 2): Validator<unknown, [T, T]>;
|
|
524
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 2): MaybeAsyncValidator<unknown, [T, T]>;
|
|
525
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 3): Validator<unknown, [T, T, T]>;
|
|
526
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 3): MaybeAsyncValidator<unknown, [T, T, T]>;
|
|
527
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 4): Validator<unknown, [T, T, T, T]>;
|
|
528
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 4): MaybeAsyncValidator<unknown, [T, T, T, T]>;
|
|
529
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 5): Validator<unknown, [T, T, T, T, T]>;
|
|
530
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 5): MaybeAsyncValidator<unknown, [T, T, T, T, T]>;
|
|
531
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 6): Validator<unknown, [T, T, T, T, T, T]>;
|
|
532
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 6): MaybeAsyncValidator<unknown, [T, T, T, T, T, T]>;
|
|
533
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 7): Validator<unknown, [T, T, T, T, T, T, T]>;
|
|
534
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 7): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T]>;
|
|
535
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 8): Validator<unknown, [T, T, T, T, T, T, T, T]>;
|
|
536
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 8): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T]>;
|
|
537
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 9): Validator<unknown, [T, T, T, T, T, T, T, T, T]>;
|
|
538
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 9): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T, T]>;
|
|
539
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: 10): Validator<unknown, [T, T, T, T, T, T, T, T, T, T]>;
|
|
540
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: 10): MaybeAsyncValidator<unknown, [T, T, T, T, T, T, T, T, T, T]>;
|
|
541
|
+
export declare function tupleOf<T>(elementValidator: Validator<unknown, T>, length: number): Validator<unknown, T[]>;
|
|
542
|
+
export declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, length: number): MaybeAsyncValidator<unknown, T[]>;
|
|
553
543
|
/**
|
|
554
544
|
* Create a validator that ensures a value is a number and not NaN.
|
|
555
545
|
*
|
|
@@ -561,7 +551,7 @@ declare function tupleOf<T>(elementValidator: MaybeAsyncValidator<unknown, T>, l
|
|
|
561
551
|
* @param message - Custom error message
|
|
562
552
|
* @returns A validator that checks if a value is a number
|
|
563
553
|
*/
|
|
564
|
-
declare function number(message?: string): Validator<unknown, number>;
|
|
554
|
+
export declare function number(message?: string): Validator<unknown, number>;
|
|
565
555
|
/**
|
|
566
556
|
* Create a validator that ensures a number is at least a minimum value.
|
|
567
557
|
*
|
|
@@ -574,7 +564,7 @@ declare function number(message?: string): Validator<unknown, number>;
|
|
|
574
564
|
* @param message - Custom error message
|
|
575
565
|
* @returns A validator that checks if a number is at least the minimum
|
|
576
566
|
*/
|
|
577
|
-
declare function min(value: number, message?: string): Validator<number>;
|
|
567
|
+
export declare function min(value: number, message?: string): Validator<number>;
|
|
578
568
|
/**
|
|
579
569
|
* Create a validator that ensures a number is at most a maximum value.
|
|
580
570
|
*
|
|
@@ -587,7 +577,7 @@ declare function min(value: number, message?: string): Validator<number>;
|
|
|
587
577
|
* @param message - Custom error message
|
|
588
578
|
* @returns A validator that checks if a number is at most the maximum
|
|
589
579
|
*/
|
|
590
|
-
declare function max(value: number, message?: string): Validator<number>;
|
|
580
|
+
export declare function max(value: number, message?: string): Validator<number>;
|
|
591
581
|
/**
|
|
592
582
|
* Create a validator that ensures a number is between a minimum and maximum (inclusive).
|
|
593
583
|
*
|
|
@@ -601,7 +591,7 @@ declare function max(value: number, message?: string): Validator<number>;
|
|
|
601
591
|
* @param message - Custom error message
|
|
602
592
|
* @returns A validator that checks if a number is between min and max
|
|
603
593
|
*/
|
|
604
|
-
declare function between(min: number, max: number, message?: string): Validator<number>;
|
|
594
|
+
export declare function between(min: number, max: number, message?: string): Validator<number>;
|
|
605
595
|
/**
|
|
606
596
|
* Create a validator that ensures a number is an integer.
|
|
607
597
|
*
|
|
@@ -613,7 +603,7 @@ declare function between(min: number, max: number, message?: string): Validator<
|
|
|
613
603
|
* @param message - Custom error message
|
|
614
604
|
* @returns A validator that checks if a number is an integer
|
|
615
605
|
*/
|
|
616
|
-
declare function integer(message?: string): Validator<number>;
|
|
606
|
+
export declare function integer(message?: string): Validator<number>;
|
|
617
607
|
/**
|
|
618
608
|
* Create a validator that ensures a number is positive (greater than zero).
|
|
619
609
|
*
|
|
@@ -625,7 +615,7 @@ declare function integer(message?: string): Validator<number>;
|
|
|
625
615
|
* @param message - Custom error message
|
|
626
616
|
* @returns A validator that checks if a number is positive
|
|
627
617
|
*/
|
|
628
|
-
declare function positive(message?: string): Validator<number>;
|
|
618
|
+
export declare function positive(message?: string): Validator<number>;
|
|
629
619
|
/**
|
|
630
620
|
* Create a validator that ensures a number is negative (less than zero).
|
|
631
621
|
*
|
|
@@ -637,7 +627,7 @@ declare function positive(message?: string): Validator<number>;
|
|
|
637
627
|
* @param message - Custom error message
|
|
638
628
|
* @returns A validator that checks if a number is negative
|
|
639
629
|
*/
|
|
640
|
-
declare function negative(message?: string): Validator<number>;
|
|
630
|
+
export declare function negative(message?: string): Validator<number>;
|
|
641
631
|
/**
|
|
642
632
|
* Create a validator that ensures a number is not zero.
|
|
643
633
|
*
|
|
@@ -649,7 +639,7 @@ declare function negative(message?: string): Validator<number>;
|
|
|
649
639
|
* @param message - Custom error message
|
|
650
640
|
* @returns A validator that checks if a number is not zero
|
|
651
641
|
*/
|
|
652
|
-
declare function nonZero(message?: string): Validator<number>;
|
|
642
|
+
export declare function nonZero(message?: string): Validator<number>;
|
|
653
643
|
/**
|
|
654
644
|
* Create a validator that ensures a number is divisible by a specific divisor.
|
|
655
645
|
*
|
|
@@ -662,7 +652,7 @@ declare function nonZero(message?: string): Validator<number>;
|
|
|
662
652
|
* @param message - Custom error message
|
|
663
653
|
* @returns A validator that checks if a number is divisible by the divisor
|
|
664
654
|
*/
|
|
665
|
-
declare function divisibleBy(divisor: number, message?: string): Validator<number>;
|
|
655
|
+
export declare function divisibleBy(divisor: number, message?: string): Validator<number>;
|
|
666
656
|
/**
|
|
667
657
|
* Create a validator that ensures a number has at most the specified decimal places.
|
|
668
658
|
*
|
|
@@ -675,7 +665,7 @@ declare function divisibleBy(divisor: number, message?: string): Validator<numbe
|
|
|
675
665
|
* @param message - Custom error message
|
|
676
666
|
* @returns A validator that checks the number's decimal precision
|
|
677
667
|
*/
|
|
678
|
-
declare function precision(maxDecimalPlaces: number, message?: string): Validator<number>;
|
|
668
|
+
export declare function precision(maxDecimalPlaces: number, message?: string): Validator<number>;
|
|
679
669
|
/**
|
|
680
670
|
* Create a validator that ensures a number is finite (not Infinity or -Infinity).
|
|
681
671
|
*
|
|
@@ -687,8 +677,7 @@ declare function precision(maxDecimalPlaces: number, message?: string): Validato
|
|
|
687
677
|
* @param message - Custom error message
|
|
688
678
|
* @returns A validator that checks if a number is finite
|
|
689
679
|
*/
|
|
690
|
-
declare function finite(message?: string): Validator<number>;
|
|
691
|
-
|
|
680
|
+
export declare function finite(message?: string): Validator<number>;
|
|
692
681
|
/**
|
|
693
682
|
* Create a validator that ensures a value is a string.
|
|
694
683
|
*
|
|
@@ -700,7 +689,7 @@ declare function finite(message?: string): Validator<number>;
|
|
|
700
689
|
* @param message - Custom error message
|
|
701
690
|
* @returns A validator that checks if a value is a string
|
|
702
691
|
*/
|
|
703
|
-
declare function string(message?: string): Validator<unknown, string>;
|
|
692
|
+
export declare function string(message?: string): Validator<unknown, string>;
|
|
704
693
|
/**
|
|
705
694
|
* Create a validator that ensures a string's length is at least a minimum value.
|
|
706
695
|
*
|
|
@@ -713,7 +702,7 @@ declare function string(message?: string): Validator<unknown, string>;
|
|
|
713
702
|
* @param message - Custom error message
|
|
714
703
|
* @returns A validator that checks if a string meets the minimum length
|
|
715
704
|
*/
|
|
716
|
-
declare function minLength(min: number, message?: string): Validator<string>;
|
|
705
|
+
export declare function minLength(min: number, message?: string): Validator<string>;
|
|
717
706
|
/**
|
|
718
707
|
* Create a validator that ensures a string's length is at most a maximum value.
|
|
719
708
|
*
|
|
@@ -726,7 +715,7 @@ declare function minLength(min: number, message?: string): Validator<string>;
|
|
|
726
715
|
* @param message - Custom error message
|
|
727
716
|
* @returns A validator that checks if a string meets the maximum length
|
|
728
717
|
*/
|
|
729
|
-
declare function maxLength(max: number, message?: string): Validator<string>;
|
|
718
|
+
export declare function maxLength(max: number, message?: string): Validator<string>;
|
|
730
719
|
/**
|
|
731
720
|
* Create a validator that ensures a string matches a regular expression pattern.
|
|
732
721
|
*
|
|
@@ -739,7 +728,7 @@ declare function maxLength(max: number, message?: string): Validator<string>;
|
|
|
739
728
|
* @param message - Custom error message
|
|
740
729
|
* @returns A validator that checks if a string matches the pattern
|
|
741
730
|
*/
|
|
742
|
-
declare function pattern(regex: RegExp, message?: string): Validator<string>;
|
|
731
|
+
export declare function pattern(regex: RegExp, message?: string): Validator<string>;
|
|
743
732
|
/**
|
|
744
733
|
* Create a validator that ensures a string is not empty after trimming whitespace.
|
|
745
734
|
*
|
|
@@ -752,7 +741,7 @@ declare function pattern(regex: RegExp, message?: string): Validator<string>;
|
|
|
752
741
|
* @param message - Custom error message
|
|
753
742
|
* @returns A validator that checks if a string is not empty
|
|
754
743
|
*/
|
|
755
|
-
declare function nonEmpty(message?: string): Validator<string>;
|
|
744
|
+
export declare function nonEmpty(message?: string): Validator<string>;
|
|
756
745
|
/**
|
|
757
746
|
* Create a validator that ensures a string is a valid email address.
|
|
758
747
|
*
|
|
@@ -764,7 +753,7 @@ declare function nonEmpty(message?: string): Validator<string>;
|
|
|
764
753
|
* @param message - Custom error message
|
|
765
754
|
* @returns A validator that checks if a string is a valid email
|
|
766
755
|
*/
|
|
767
|
-
declare function email(message?: string): Validator<string>;
|
|
756
|
+
export declare function email(message?: string): Validator<string>;
|
|
768
757
|
/**
|
|
769
758
|
* Create a validator that ensures a string is a valid URL.
|
|
770
759
|
*
|
|
@@ -776,7 +765,7 @@ declare function email(message?: string): Validator<string>;
|
|
|
776
765
|
* @param message - Custom error message
|
|
777
766
|
* @returns A validator that checks if a string is a valid URL
|
|
778
767
|
*/
|
|
779
|
-
declare function url(message?: string): Validator<string>;
|
|
768
|
+
export declare function url(message?: string): Validator<string>;
|
|
780
769
|
/**
|
|
781
770
|
* Create a validator that ensures a string is a valid phone number.
|
|
782
771
|
* Accepts common formats including international (+), spaces, dashes, and parentheses.
|
|
@@ -789,7 +778,7 @@ declare function url(message?: string): Validator<string>;
|
|
|
789
778
|
* @param message - Custom error message
|
|
790
779
|
* @returns A validator that checks if a string is a valid phone number
|
|
791
780
|
*/
|
|
792
|
-
declare function phoneNumber(message?: string): Validator<string>;
|
|
781
|
+
export declare function phoneNumber(message?: string): Validator<string>;
|
|
793
782
|
/**
|
|
794
783
|
* Create a validator that ensures a string is a valid UUID (RFC 4122).
|
|
795
784
|
* Accepts any UUID version including NIL UUIDs (all zeros).
|
|
@@ -802,7 +791,7 @@ declare function phoneNumber(message?: string): Validator<string>;
|
|
|
802
791
|
* @param message - Custom error message
|
|
803
792
|
* @returns A validator that checks if a string is a valid UUID
|
|
804
793
|
*/
|
|
805
|
-
declare function uuid(message?: string): Validator<string>;
|
|
794
|
+
export declare function uuid(message?: string): Validator<string>;
|
|
806
795
|
/**
|
|
807
796
|
* Create a validator that ensures a string is a valid ISO 8601 date (YYYY-MM-DD).
|
|
808
797
|
* Validates both format and calendar correctness (e.g., rejects Feb 30).
|
|
@@ -815,7 +804,7 @@ declare function uuid(message?: string): Validator<string>;
|
|
|
815
804
|
* @param message - Custom error message
|
|
816
805
|
* @returns A validator that checks if a string is a valid ISO date
|
|
817
806
|
*/
|
|
818
|
-
declare function isoDate(message?: string): Validator<string>;
|
|
807
|
+
export declare function isoDate(message?: string): Validator<string>;
|
|
819
808
|
/**
|
|
820
809
|
* Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 time.
|
|
821
810
|
* Format: `HH:mm:ss[.fractional][Z|±HH:mm]`. Timezone is optional.
|
|
@@ -830,7 +819,7 @@ declare function isoDate(message?: string): Validator<string>;
|
|
|
830
819
|
* @param message - Custom error message
|
|
831
820
|
* @returns A validator that checks if a string is a valid ISO time
|
|
832
821
|
*/
|
|
833
|
-
declare function isoTime(message?: string): Validator<string>;
|
|
822
|
+
export declare function isoTime(message?: string): Validator<string>;
|
|
834
823
|
/**
|
|
835
824
|
* Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 datetime.
|
|
836
825
|
* Format: `YYYY-MM-DDTHH:mm:ss[.fractional][Z|±HH:mm]`.
|
|
@@ -844,7 +833,7 @@ declare function isoTime(message?: string): Validator<string>;
|
|
|
844
833
|
* @param message - Custom error message
|
|
845
834
|
* @returns A validator that checks if a string is a valid ISO datetime
|
|
846
835
|
*/
|
|
847
|
-
declare function isoDateTime(message?: string): Validator<string>;
|
|
836
|
+
export declare function isoDateTime(message?: string): Validator<string>;
|
|
848
837
|
/**
|
|
849
838
|
* Create a validator that ensures a string is a valid ISO 8601 duration.
|
|
850
839
|
* Format: `PnYnMnDTnHnMnS` or `PnW`.
|
|
@@ -859,8 +848,7 @@ declare function isoDateTime(message?: string): Validator<string>;
|
|
|
859
848
|
* @param message - Custom error message
|
|
860
849
|
* @returns A validator that checks if a string is a valid ISO duration
|
|
861
850
|
*/
|
|
862
|
-
declare function isoDuration(message?: string): Validator<string>;
|
|
863
|
-
|
|
851
|
+
export declare function isoDuration(message?: string): Validator<string>;
|
|
864
852
|
/**
|
|
865
853
|
* Create a validator that parses input into a number.
|
|
866
854
|
* Accepts both numbers and string representations of numbers.
|
|
@@ -874,7 +862,7 @@ declare function isoDuration(message?: string): Validator<string>;
|
|
|
874
862
|
* @param message - Custom error message
|
|
875
863
|
* @returns A validator that parses and validates numbers
|
|
876
864
|
*/
|
|
877
|
-
declare function parseNumber(message?: string): Validator<unknown, number>;
|
|
865
|
+
export declare function parseNumber(message?: string): Validator<unknown, number>;
|
|
878
866
|
/**
|
|
879
867
|
* Create a validator that parses input into a BigInt.
|
|
880
868
|
* Accepts BigInt values, strings, and integer numbers.
|
|
@@ -888,7 +876,7 @@ declare function parseNumber(message?: string): Validator<unknown, number>;
|
|
|
888
876
|
* @param message - Custom error message
|
|
889
877
|
* @returns A validator that parses and validates BigInt values
|
|
890
878
|
*/
|
|
891
|
-
declare function parseBigInt(message?: string): Validator<unknown, bigint>;
|
|
879
|
+
export declare function parseBigInt(message?: string): Validator<unknown, bigint>;
|
|
892
880
|
/**
|
|
893
881
|
* Create a validator that parses input into enum values.
|
|
894
882
|
* Handles string/number to enum conversions with flexible matching.
|
|
@@ -903,7 +891,7 @@ declare function parseBigInt(message?: string): Validator<unknown, bigint>;
|
|
|
903
891
|
* @param message - Custom error message
|
|
904
892
|
* @returns A validator that parses to enum values
|
|
905
893
|
*/
|
|
906
|
-
declare function parseEnum<T extends Record<string, string | number>>(enumObject: T, message?: string): Validator<unknown, T[keyof T]>;
|
|
894
|
+
export declare function parseEnum<T extends Record<string, string | number>>(enumObject: T, message?: string): Validator<unknown, T[keyof T]>;
|
|
907
895
|
/**
|
|
908
896
|
* Create a validator that parses input into a Date object.
|
|
909
897
|
* Accepts Date objects, date strings, and numeric timestamps.
|
|
@@ -917,7 +905,7 @@ declare function parseEnum<T extends Record<string, string | number>>(enumObject
|
|
|
917
905
|
* @param message - Custom error message
|
|
918
906
|
* @returns A validator that parses and validates dates
|
|
919
907
|
*/
|
|
920
|
-
declare function parseDate(message?: string): Validator<unknown, Date>;
|
|
908
|
+
export declare function parseDate(message?: string): Validator<unknown, Date>;
|
|
921
909
|
/**
|
|
922
910
|
* Create a validator that parses input into a boolean.
|
|
923
911
|
* Accepts booleans, 0/1, and strings like 'true'/'false', 'yes'/'no'.
|
|
@@ -932,7 +920,7 @@ declare function parseDate(message?: string): Validator<unknown, Date>;
|
|
|
932
920
|
* @param message - Custom error message
|
|
933
921
|
* @returns A validator that parses and validates booleans
|
|
934
922
|
*/
|
|
935
|
-
declare function parseBool(message?: string): Validator<unknown, boolean>;
|
|
923
|
+
export declare function parseBool(message?: string): Validator<unknown, boolean>;
|
|
936
924
|
/**
|
|
937
925
|
* Create a validator that parses input into a string.
|
|
938
926
|
* Accepts strings and any value convertible to string, except null and undefined.
|
|
@@ -946,7 +934,7 @@ declare function parseBool(message?: string): Validator<unknown, boolean>;
|
|
|
946
934
|
* @param message - Custom error message
|
|
947
935
|
* @returns A validator that parses and validates strings
|
|
948
936
|
*/
|
|
949
|
-
declare function parseString(message?: string): Validator<unknown, string>;
|
|
937
|
+
export declare function parseString(message?: string): Validator<unknown, string>;
|
|
950
938
|
/**
|
|
951
939
|
* Create a validator that parses JSON strings into objects.
|
|
952
940
|
* Accepts JSON strings or already-parsed objects.
|
|
@@ -960,7 +948,7 @@ declare function parseString(message?: string): Validator<unknown, string>;
|
|
|
960
948
|
* @param message - Custom error message
|
|
961
949
|
* @returns A validator that parses and validates JSON
|
|
962
950
|
*/
|
|
963
|
-
declare function parseJSON(message?: string): Validator<unknown, unknown>;
|
|
951
|
+
export declare function parseJSON(message?: string): Validator<unknown, unknown>;
|
|
964
952
|
/**
|
|
965
953
|
* Create a validator that parses ISO date strings (YYYY-MM-DD) into Date objects.
|
|
966
954
|
* Performs strict validation of the date format and validity.
|
|
@@ -974,7 +962,7 @@ declare function parseJSON(message?: string): Validator<unknown, unknown>;
|
|
|
974
962
|
* @param message - Custom error message
|
|
975
963
|
* @returns A validator that parses and validates ISO date strings
|
|
976
964
|
*/
|
|
977
|
-
declare function parseISODate(message?: string): Validator<unknown, Date>;
|
|
965
|
+
export declare function parseISODate(message?: string): Validator<unknown, Date>;
|
|
978
966
|
/**
|
|
979
967
|
* Create a validator that parses string URLs into URL objects.
|
|
980
968
|
*
|
|
@@ -986,8 +974,7 @@ declare function parseISODate(message?: string): Validator<unknown, Date>;
|
|
|
986
974
|
* @param message - Custom error message
|
|
987
975
|
* @returns A validator that parses and validates URLs
|
|
988
976
|
*/
|
|
989
|
-
declare function parseURL(message?: string): Validator<unknown, URL>;
|
|
990
|
-
|
|
977
|
+
export declare function parseURL(message?: string): Validator<unknown, URL>;
|
|
991
978
|
/**
|
|
992
979
|
* Create a validator that ensures a value is a valid Date object.
|
|
993
980
|
*
|
|
@@ -999,7 +986,7 @@ declare function parseURL(message?: string): Validator<unknown, URL>;
|
|
|
999
986
|
* @param message - Custom error message
|
|
1000
987
|
* @returns A validator that checks if value is a valid Date
|
|
1001
988
|
*/
|
|
1002
|
-
declare function date(message?: string): Validator<unknown, Date>;
|
|
989
|
+
export declare function date(message?: string): Validator<unknown, Date>;
|
|
1003
990
|
/**
|
|
1004
991
|
* Create a validator that ensures a Date is within a specified range.
|
|
1005
992
|
*
|
|
@@ -1013,7 +1000,7 @@ declare function date(message?: string): Validator<unknown, Date>;
|
|
|
1013
1000
|
* @param message - Custom error message
|
|
1014
1001
|
* @returns A validator that checks if a date is between min and max
|
|
1015
1002
|
*/
|
|
1016
|
-
declare function dateRange(min: Date, max: Date, message?: string): Validator<Date>;
|
|
1003
|
+
export declare function dateRange(min: Date, max: Date, message?: string): Validator<Date>;
|
|
1017
1004
|
/**
|
|
1018
1005
|
* Create a validator that ensures a Date is in the past.
|
|
1019
1006
|
*
|
|
@@ -1024,7 +1011,7 @@ declare function dateRange(min: Date, max: Date, message?: string): Validator<Da
|
|
|
1024
1011
|
* @param message - Custom error message
|
|
1025
1012
|
* @returns A validator that checks if a date is in the past
|
|
1026
1013
|
*/
|
|
1027
|
-
declare function pastDate(message?: string): Validator<Date>;
|
|
1014
|
+
export declare function pastDate(message?: string): Validator<Date>;
|
|
1028
1015
|
/**
|
|
1029
1016
|
* Create a validator that ensures a Date is in the future.
|
|
1030
1017
|
*
|
|
@@ -1037,7 +1024,7 @@ declare function pastDate(message?: string): Validator<Date>;
|
|
|
1037
1024
|
* @param message - Custom error message
|
|
1038
1025
|
* @returns A validator that checks if a date is in the future
|
|
1039
1026
|
*/
|
|
1040
|
-
declare function futureDate(message?: string): Validator<Date>;
|
|
1027
|
+
export declare function futureDate(message?: string): Validator<Date>;
|
|
1041
1028
|
/**
|
|
1042
1029
|
* Create a validator that ensures a Date is today or in the future.
|
|
1043
1030
|
* Uses calendar date comparison (ignoring time portions).
|
|
@@ -1049,8 +1036,7 @@ declare function futureDate(message?: string): Validator<Date>;
|
|
|
1049
1036
|
* @param message - Custom error message
|
|
1050
1037
|
* @returns A validator that checks if a date is today or in the future
|
|
1051
1038
|
*/
|
|
1052
|
-
declare function todayOrFuture(message?: string): Validator<Date>;
|
|
1053
|
-
|
|
1039
|
+
export declare function todayOrFuture(message?: string): Validator<Date>;
|
|
1054
1040
|
/**
|
|
1055
1041
|
* Create a validator that ensures a value is a boolean.
|
|
1056
1042
|
*
|
|
@@ -1062,7 +1048,7 @@ declare function todayOrFuture(message?: string): Validator<Date>;
|
|
|
1062
1048
|
* @param message - Custom error message
|
|
1063
1049
|
* @returns A validator that checks if a value is a boolean
|
|
1064
1050
|
*/
|
|
1065
|
-
declare function boolean(message?: string): Validator<unknown, boolean>;
|
|
1051
|
+
export declare function boolean(message?: string): Validator<unknown, boolean>;
|
|
1066
1052
|
/**
|
|
1067
1053
|
* Create a validator that ensures a boolean matches the expected value.
|
|
1068
1054
|
*
|
|
@@ -1075,8 +1061,7 @@ declare function boolean(message?: string): Validator<unknown, boolean>;
|
|
|
1075
1061
|
* @param message - Custom error message
|
|
1076
1062
|
* @returns A validator that confirms the value matches the expected boolean
|
|
1077
1063
|
*/
|
|
1078
|
-
declare function matches(expected: boolean, message?: string): Validator<boolean>;
|
|
1079
|
-
|
|
1064
|
+
export declare function matches(expected: boolean, message?: string): Validator<boolean>;
|
|
1080
1065
|
/**
|
|
1081
1066
|
* Create a validator that checks if a value matches any of the provided validators.
|
|
1082
1067
|
* Returns the result of the first successful validator, or all errors if none match.
|
|
@@ -1091,68 +1076,57 @@ declare function matches(expected: boolean, message?: string): Validator<boolean
|
|
|
1091
1076
|
* @param options - Configuration options
|
|
1092
1077
|
* @returns A validator that succeeds if any of the provided validators succeed
|
|
1093
1078
|
*/
|
|
1094
|
-
declare function union<I>(validators: [], options?: {
|
|
1095
|
-
|
|
1096
|
-
|
|
1079
|
+
export declare function union<I>(validators: [], options?: {
|
|
1080
|
+
collectAllErrors?: boolean;
|
|
1081
|
+
errorPrefix?: string;
|
|
1097
1082
|
}): Validator<I, never>;
|
|
1098
|
-
declare function union<I, O1>(validators: [Validator<I, O1>], options?: {
|
|
1099
|
-
|
|
1100
|
-
|
|
1083
|
+
export declare function union<I, O1>(validators: [Validator<I, O1>], options?: {
|
|
1084
|
+
collectAllErrors?: boolean;
|
|
1085
|
+
errorPrefix?: string;
|
|
1101
1086
|
}): Validator<I, O1>;
|
|
1102
|
-
declare function union<I, O1>(validators: [MaybeAsyncValidator<I, O1>], options?: {
|
|
1103
|
-
|
|
1104
|
-
|
|
1087
|
+
export declare function union<I, O1>(validators: [MaybeAsyncValidator<I, O1>], options?: {
|
|
1088
|
+
collectAllErrors?: boolean;
|
|
1089
|
+
errorPrefix?: string;
|
|
1105
1090
|
}): MaybeAsyncValidator<I, O1>;
|
|
1106
|
-
declare function union<I, O1, O2>(validators: [Validator<I, O1>, Validator<I, O2>], options?: {
|
|
1107
|
-
|
|
1108
|
-
|
|
1091
|
+
export declare function union<I, O1, O2>(validators: [Validator<I, O1>, Validator<I, O2>], options?: {
|
|
1092
|
+
collectAllErrors?: boolean;
|
|
1093
|
+
errorPrefix?: string;
|
|
1109
1094
|
}): Validator<I, O1 | O2>;
|
|
1110
|
-
declare function union<I, O1, O2>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>], options?: {
|
|
1111
|
-
|
|
1112
|
-
|
|
1095
|
+
export declare function union<I, O1, O2>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>], options?: {
|
|
1096
|
+
collectAllErrors?: boolean;
|
|
1097
|
+
errorPrefix?: string;
|
|
1113
1098
|
}): MaybeAsyncValidator<I, O1 | O2>;
|
|
1114
|
-
declare function union<I, O1, O2, O3>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>], options?: {
|
|
1115
|
-
|
|
1116
|
-
|
|
1099
|
+
export declare function union<I, O1, O2, O3>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>], options?: {
|
|
1100
|
+
collectAllErrors?: boolean;
|
|
1101
|
+
errorPrefix?: string;
|
|
1117
1102
|
}): Validator<I, O1 | O2 | O3>;
|
|
1118
|
-
declare function union<I, O1, O2, O3>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>, MaybeAsyncValidator<I, O3>], options?: {
|
|
1119
|
-
|
|
1120
|
-
|
|
1103
|
+
export declare function union<I, O1, O2, O3>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>, MaybeAsyncValidator<I, O3>], options?: {
|
|
1104
|
+
collectAllErrors?: boolean;
|
|
1105
|
+
errorPrefix?: string;
|
|
1121
1106
|
}): MaybeAsyncValidator<I, O1 | O2 | O3>;
|
|
1122
|
-
declare function union<I, O1, O2, O3, O4>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>, Validator<I, O4>], options?: {
|
|
1123
|
-
|
|
1124
|
-
|
|
1107
|
+
export declare function union<I, O1, O2, O3, O4>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>, Validator<I, O4>], options?: {
|
|
1108
|
+
collectAllErrors?: boolean;
|
|
1109
|
+
errorPrefix?: string;
|
|
1125
1110
|
}): Validator<I, O1 | O2 | O3 | O4>;
|
|
1126
|
-
declare function union<I, O1, O2, O3, O4>(validators: [
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
MaybeAsyncValidator<I, O3>,
|
|
1130
|
-
MaybeAsyncValidator<I, O4>
|
|
1131
|
-
], options?: {
|
|
1132
|
-
collectAllErrors?: boolean;
|
|
1133
|
-
errorPrefix?: string;
|
|
1111
|
+
export declare function union<I, O1, O2, O3, O4>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>, MaybeAsyncValidator<I, O3>, MaybeAsyncValidator<I, O4>], options?: {
|
|
1112
|
+
collectAllErrors?: boolean;
|
|
1113
|
+
errorPrefix?: string;
|
|
1134
1114
|
}): MaybeAsyncValidator<I, O1 | O2 | O3 | O4>;
|
|
1135
|
-
declare function union<I, O1, O2, O3, O4, O5>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>, Validator<I, O4>, Validator<I, O5>], options?: {
|
|
1136
|
-
|
|
1137
|
-
|
|
1115
|
+
export declare function union<I, O1, O2, O3, O4, O5>(validators: [Validator<I, O1>, Validator<I, O2>, Validator<I, O3>, Validator<I, O4>, Validator<I, O5>], options?: {
|
|
1116
|
+
collectAllErrors?: boolean;
|
|
1117
|
+
errorPrefix?: string;
|
|
1138
1118
|
}): Validator<I, O1 | O2 | O3 | O4 | O5>;
|
|
1139
|
-
declare function union<I, O1, O2, O3, O4, O5>(validators: [
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
MaybeAsyncValidator<I, O3>,
|
|
1143
|
-
MaybeAsyncValidator<I, O4>,
|
|
1144
|
-
MaybeAsyncValidator<I, O5>
|
|
1145
|
-
], options?: {
|
|
1146
|
-
collectAllErrors?: boolean;
|
|
1147
|
-
errorPrefix?: string;
|
|
1119
|
+
export declare function union<I, O1, O2, O3, O4, O5>(validators: [MaybeAsyncValidator<I, O1>, MaybeAsyncValidator<I, O2>, MaybeAsyncValidator<I, O3>, MaybeAsyncValidator<I, O4>, MaybeAsyncValidator<I, O5>], options?: {
|
|
1120
|
+
collectAllErrors?: boolean;
|
|
1121
|
+
errorPrefix?: string;
|
|
1148
1122
|
}): MaybeAsyncValidator<I, O1 | O2 | O3 | O4 | O5>;
|
|
1149
|
-
declare function union<I, O>(validators: Array<Validator<I, O>>, options?: {
|
|
1150
|
-
|
|
1151
|
-
|
|
1123
|
+
export declare function union<I, O>(validators: Array<Validator<I, O>>, options?: {
|
|
1124
|
+
collectAllErrors?: boolean;
|
|
1125
|
+
errorPrefix?: string;
|
|
1152
1126
|
}): Validator<I, O>;
|
|
1153
|
-
declare function union<I, O>(validators: Array<MaybeAsyncValidator<I, O>>, options?: {
|
|
1154
|
-
|
|
1155
|
-
|
|
1127
|
+
export declare function union<I, O>(validators: Array<MaybeAsyncValidator<I, O>>, options?: {
|
|
1128
|
+
collectAllErrors?: boolean;
|
|
1129
|
+
errorPrefix?: string;
|
|
1156
1130
|
}): MaybeAsyncValidator<I, O>;
|
|
1157
1131
|
/**
|
|
1158
1132
|
* Create a discriminated union validator that selects the validator based on
|
|
@@ -1171,9 +1145,8 @@ declare function union<I, O>(validators: Array<MaybeAsyncValidator<I, O>>, optio
|
|
|
1171
1145
|
* @param fallbackMessage - Message when the discriminant value is not found
|
|
1172
1146
|
* @returns A validator that selects the appropriate schema based on the discriminant
|
|
1173
1147
|
*/
|
|
1174
|
-
declare function discriminatedUnion<const M extends Record<string, Validator<unknown, unknown>>>(discriminantField: string, validatorMap: M, fallbackMessage?: string): Validator<unknown, ValidatorMapOutput<M>>;
|
|
1175
|
-
declare function discriminatedUnion<const M extends Record<string, MaybeAsyncValidator<unknown, unknown>>>(discriminantField: string, validatorMap: M, fallbackMessage?: string): MaybeAsyncValidator<unknown, ValidatorMapOutput<M>>;
|
|
1176
|
-
|
|
1148
|
+
export declare function discriminatedUnion<const M extends Record<string, Validator<unknown, unknown>>>(discriminantField: string, validatorMap: M, fallbackMessage?: string): Validator<unknown, ValidatorMapOutput<M>>;
|
|
1149
|
+
export declare function discriminatedUnion<const M extends Record<string, MaybeAsyncValidator<unknown, unknown>>>(discriminantField: string, validatorMap: M, fallbackMessage?: string): MaybeAsyncValidator<unknown, ValidatorMapOutput<M>>;
|
|
1177
1150
|
/**
|
|
1178
1151
|
* Create a validator for TypeScript enum values.
|
|
1179
1152
|
* Works with both string and numeric enums.
|
|
@@ -1194,8 +1167,7 @@ declare function discriminatedUnion<const M extends Record<string, MaybeAsyncVal
|
|
|
1194
1167
|
* @param excludedValues - Values to exclude from the valid set
|
|
1195
1168
|
* @returns A validator that ensures the value is a valid enum value
|
|
1196
1169
|
*/
|
|
1197
|
-
declare function enumValue<T extends Record<string, string | number>>(enumObject: T, message?: string, excludedValues?: T[keyof T][]): Validator<unknown, T[keyof T]>;
|
|
1198
|
-
|
|
1170
|
+
export declare function enumValue<T extends Record<string, string | number>>(enumObject: T, message?: string, excludedValues?: T[keyof T][]): Validator<unknown, T[keyof T]>;
|
|
1199
1171
|
/**
|
|
1200
1172
|
* Create a validator that ensures a value is a bigint.
|
|
1201
1173
|
*
|
|
@@ -1207,39 +1179,37 @@ declare function enumValue<T extends Record<string, string | number>>(enumObject
|
|
|
1207
1179
|
* @param message - Custom error message
|
|
1208
1180
|
* @returns A validator that checks if the value is a bigint
|
|
1209
1181
|
*/
|
|
1210
|
-
declare function bigint(message?: string): Validator<unknown, bigint>;
|
|
1211
|
-
|
|
1182
|
+
export declare function bigint(message?: string): Validator<unknown, bigint>;
|
|
1212
1183
|
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
1213
|
-
|
|
1184
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
1214
1185
|
}
|
|
1215
1186
|
declare namespace StandardSchemaV1 {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1187
|
+
interface Props<Input = unknown, Output = Input> {
|
|
1188
|
+
readonly version: 1;
|
|
1189
|
+
readonly vendor: string;
|
|
1190
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
1191
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
1192
|
+
}
|
|
1193
|
+
type Result<Output> = {
|
|
1194
|
+
readonly value: Output;
|
|
1195
|
+
readonly issues?: undefined;
|
|
1196
|
+
} | {
|
|
1197
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
1198
|
+
};
|
|
1199
|
+
interface Issue {
|
|
1200
|
+
readonly message: string;
|
|
1201
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
1202
|
+
}
|
|
1203
|
+
interface PathSegment {
|
|
1204
|
+
readonly key: PropertyKey;
|
|
1205
|
+
}
|
|
1206
|
+
interface Types<Input = unknown, Output = Input> {
|
|
1207
|
+
readonly input: Input;
|
|
1208
|
+
readonly output: Output;
|
|
1209
|
+
}
|
|
1210
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
1211
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
1241
1212
|
}
|
|
1242
|
-
|
|
1243
1213
|
/**
|
|
1244
1214
|
* Wrap a validator as a Standard Schema v1 object.
|
|
1245
1215
|
*
|
|
@@ -1259,8 +1229,6 @@ declare namespace StandardSchemaV1 {
|
|
|
1259
1229
|
* @param validator - A sync or async validator to wrap
|
|
1260
1230
|
* @returns A Standard Schema v1 object
|
|
1261
1231
|
*/
|
|
1262
|
-
declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1263
|
-
declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1264
|
-
|
|
1265
|
-
export { ROOT_ERROR_KEY, StandardSchemaV1, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult, when, whenAsync };
|
|
1266
|
-
export type { AsyncValidator, InferSchemaType, MaybeAsyncValidator, Schema, SyncSchema, ValidateOptions, ValidationError, ValidationResult, Validator, ValidatorMapOutput };
|
|
1232
|
+
export declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1233
|
+
export declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1234
|
+
export type { StandardSchemaV1 };
|