@oxog/vld 2.1.0 → 2.2.7
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/CHANGELOG.md +113 -0
- package/README.md +413 -1235
- package/dist/chunks/errors-core-CerMg2rq.js +1 -0
- package/dist/chunks/index-CkbfQQ4n.js +1 -0
- package/dist/chunks/index-yjpbvFgw.js +1 -0
- package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
- package/dist/chunks/security-Dy24T8N7.js +1 -0
- package/dist/cjs/chunks/errors-core-DrydF46s.cjs +1 -0
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
- package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
- package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
- package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -505
- package/dist/cjs/cli/index.cjs +1 -209
- package/dist/cjs/codecs/index.cjs +1 -45
- package/dist/cjs/coercion/index.cjs +1 -588
- package/dist/cjs/compat/emitter.cjs +1 -184
- package/dist/cjs/compat/result.cjs +1 -189
- package/dist/cjs/errors.cjs +1 -180
- package/dist/cjs/index.cjs +1 -1894
- package/dist/cjs/kernel.cjs +1 -415
- package/dist/cjs/locales/af.cjs +1 -108
- package/dist/cjs/locales/ar.cjs +1 -108
- package/dist/cjs/locales/bn.cjs +1 -108
- package/dist/cjs/locales/da.cjs +1 -108
- package/dist/cjs/locales/de.cjs +1 -108
- package/dist/cjs/locales/en.cjs +1 -108
- package/dist/cjs/locales/es-MX.cjs +1 -107
- package/dist/cjs/locales/es.cjs +1 -96
- package/dist/cjs/locales/fi.cjs +1 -108
- package/dist/cjs/locales/fr.cjs +1 -96
- package/dist/cjs/locales/hi.cjs +1 -108
- package/dist/cjs/locales/id.cjs +1 -108
- package/dist/cjs/locales/index.cjs +1 -43
- package/dist/cjs/locales/it.cjs +1 -108
- package/dist/cjs/locales/ja.cjs +1 -108
- package/dist/cjs/locales/ko.cjs +1 -108
- package/dist/cjs/locales/lazy.cjs +1 -188
- package/dist/cjs/locales/nl.cjs +1 -108
- package/dist/cjs/locales/no.cjs +1 -108
- package/dist/cjs/locales/pl.cjs +1 -108
- package/dist/cjs/locales/pt-BR.cjs +1 -108
- package/dist/cjs/locales/pt.cjs +1 -108
- package/dist/cjs/locales/ru.cjs +1 -108
- package/dist/cjs/locales/runtime.cjs +1 -51
- package/dist/cjs/locales/sv.cjs +1 -108
- package/dist/cjs/locales/sw.cjs +1 -108
- package/dist/cjs/locales/th.cjs +1 -108
- package/dist/cjs/locales/tr.cjs +1 -108
- package/dist/cjs/locales/vi.cjs +1 -108
- package/dist/cjs/locales/zh.cjs +1 -108
- package/dist/cjs/mini.cjs +1 -242
- package/dist/cjs/pigment.cjs +1 -207
- package/dist/cjs/plugins/index.cjs +1 -12
- package/dist/cjs/registry.cjs +1 -37
- package/dist/cjs/v3/index.cjs +1 -425
- package/dist/cjs/v4/core/index.cjs +1 -894
- package/dist/cjs/v4/index.cjs +1 -425
- package/dist/cjs/v4/locales/index.cjs +1 -130
- package/dist/cjs/v4/mini/index.cjs +1 -509
- package/dist/cjs/v4-mini/index.cjs +1 -532
- package/dist/cjs/validators/any.cjs +1 -40
- package/dist/cjs/validators/array.cjs +1 -283
- package/dist/cjs/validators/base.cjs +1 -887
- package/dist/cjs/validators/base64.cjs +1 -73
- package/dist/cjs/validators/bigint.cjs +1 -232
- package/dist/cjs/validators/boolean.cjs +1 -146
- package/dist/cjs/validators/codec.cjs +1 -205
- package/dist/cjs/validators/custom.cjs +1 -71
- package/dist/cjs/validators/date.cjs +1 -278
- package/dist/cjs/validators/discriminated-union.cjs +1 -130
- package/dist/cjs/validators/enum.cjs +1 -154
- package/dist/cjs/validators/file.cjs +1 -130
- package/dist/cjs/validators/function.cjs +1 -63
- package/dist/cjs/validators/hex.cjs +1 -70
- package/dist/cjs/validators/index.cjs +1 -123
- package/dist/cjs/validators/intersection.cjs +1 -120
- package/dist/cjs/validators/json.cjs +1 -70
- package/dist/cjs/validators/lazy.cjs +1 -53
- package/dist/cjs/validators/literal.cjs +1 -64
- package/dist/cjs/validators/map.cjs +1 -218
- package/dist/cjs/validators/nan.cjs +1 -41
- package/dist/cjs/validators/never.cjs +1 -36
- package/dist/cjs/validators/null.cjs +1 -43
- package/dist/cjs/validators/number.cjs +1 -427
- package/dist/cjs/validators/object.cjs +1 -868
- package/dist/cjs/validators/promise.cjs +1 -115
- package/dist/cjs/validators/record.cjs +1 -262
- package/dist/cjs/validators/set.cjs +1 -203
- package/dist/cjs/validators/string-bool.cjs +1 -124
- package/dist/cjs/validators/string-formats.cjs +1 -168
- package/dist/cjs/validators/string.cjs +1 -12
- package/dist/cjs/validators/symbol.cjs +1 -62
- package/dist/cjs/validators/template-literal.cjs +1 -108
- package/dist/cjs/validators/tuple.cjs +1 -187
- package/dist/cjs/validators/uint8array.cjs +1 -106
- package/dist/cjs/validators/undefined.cjs +1 -43
- package/dist/cjs/validators/union.cjs +1 -191
- package/dist/cjs/validators/unknown.cjs +1 -40
- package/dist/cjs/validators/void.cjs +1 -48
- package/dist/cjs/validators/xor.cjs +1 -69
- package/dist/cli/bin.js +1 -406
- package/dist/cli/index.js +1 -205
- package/dist/codecs/index.js +1 -11
- package/dist/coercion/index.js +1 -579
- package/dist/compat/emitter.js +1 -180
- package/dist/compat/result.js +1 -170
- package/dist/errors-core.d.ts +32 -2
- package/dist/errors.js +1 -171
- package/dist/index.d.ts +315 -361
- package/dist/index.js +1 -1534
- package/dist/kernel.js +1 -409
- package/dist/locales/af.js +1 -106
- package/dist/locales/ar.js +1 -106
- package/dist/locales/bn.js +1 -106
- package/dist/locales/da.js +1 -106
- package/dist/locales/de.js +1 -106
- package/dist/locales/en.js +1 -106
- package/dist/locales/es-MX.js +1 -105
- package/dist/locales/es.js +1 -94
- package/dist/locales/fi.js +1 -106
- package/dist/locales/fr.js +1 -94
- package/dist/locales/hi.js +1 -106
- package/dist/locales/id.js +1 -106
- package/dist/locales/index.js +1 -29
- package/dist/locales/it.js +1 -106
- package/dist/locales/ja.js +1 -106
- package/dist/locales/ko.js +1 -106
- package/dist/locales/lazy.js +1 -177
- package/dist/locales/nl.js +1 -106
- package/dist/locales/no.js +1 -106
- package/dist/locales/pl.js +1 -106
- package/dist/locales/pt-BR.js +1 -106
- package/dist/locales/pt.js +1 -106
- package/dist/locales/ru.js +1 -106
- package/dist/locales/runtime.js +1 -41
- package/dist/locales/sv.js +1 -106
- package/dist/locales/sw.js +1 -106
- package/dist/locales/th.js +1 -106
- package/dist/locales/tr.js +1 -106
- package/dist/locales/vi.js +1 -106
- package/dist/locales/zh.js +1 -106
- package/dist/mini.d.ts +3 -3
- package/dist/mini.js +1 -156
- package/dist/pigment.js +1 -180
- package/dist/plugins/index.js +1 -1
- package/dist/registry.js +1 -34
- package/dist/utils/json-schema.d.ts +10 -1
- package/dist/v3/index.js +1 -46
- package/dist/v4/core/index.d.ts +28 -16
- package/dist/v4/core/index.js +1 -277
- package/dist/v4/index.js +1 -50
- package/dist/v4/locales/index.d.ts +4 -0
- package/dist/v4/locales/index.js +1 -77
- package/dist/v4/mini/index.js +1 -47
- package/dist/v4-mini/index.d.ts +1 -1
- package/dist/v4-mini/index.js +1 -75
- package/dist/validators/any.js +1 -37
- package/dist/validators/array.d.ts +7 -0
- package/dist/validators/array.js +1 -279
- package/dist/validators/base.d.ts +210 -17
- package/dist/validators/base.js +1 -868
- package/dist/validators/base64.js +1 -68
- package/dist/validators/bigint.d.ts +7 -0
- package/dist/validators/bigint.js +1 -228
- package/dist/validators/boolean.js +1 -142
- package/dist/validators/codec.js +1 -200
- package/dist/validators/custom.d.ts +20 -10
- package/dist/validators/custom.js +1 -67
- package/dist/validators/date.d.ts +2 -0
- package/dist/validators/date.js +1 -274
- package/dist/validators/discriminated-union.d.ts +4 -2
- package/dist/validators/discriminated-union.js +1 -123
- package/dist/validators/enum.d.ts +8 -2
- package/dist/validators/enum.js +1 -150
- package/dist/validators/file.js +1 -125
- package/dist/validators/function.js +1 -58
- package/dist/validators/hex.js +1 -65
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.js +1 -35
- package/dist/validators/intersection.js +1 -116
- package/dist/validators/json.js +1 -66
- package/dist/validators/lazy.js +1 -50
- package/dist/validators/literal.d.ts +8 -3
- package/dist/validators/literal.js +1 -60
- package/dist/validators/map.d.ts +7 -0
- package/dist/validators/map.js +1 -214
- package/dist/validators/nan.js +1 -38
- package/dist/validators/never.js +1 -32
- package/dist/validators/null.js +1 -40
- package/dist/validators/number.d.ts +25 -1
- package/dist/validators/number.js +1 -423
- package/dist/validators/object.d.ts +18 -2
- package/dist/validators/object.js +1 -864
- package/dist/validators/promise.d.ts +6 -7
- package/dist/validators/promise.js +1 -111
- package/dist/validators/record.d.ts +13 -8
- package/dist/validators/record.js +1 -258
- package/dist/validators/set.d.ts +5 -0
- package/dist/validators/set.js +1 -199
- package/dist/validators/string-bool.js +1 -120
- package/dist/validators/string-formats.d.ts +58 -62
- package/dist/validators/string-formats.js +1 -135
- package/dist/validators/string.d.ts +49 -10
- package/dist/validators/string.js +1 -4
- package/dist/validators/symbol.js +1 -58
- package/dist/validators/template-literal.js +1 -103
- package/dist/validators/tuple.d.ts +17 -13
- package/dist/validators/tuple.js +1 -183
- package/dist/validators/uint8array.js +1 -101
- package/dist/validators/undefined.js +1 -40
- package/dist/validators/union.d.ts +1 -0
- package/dist/validators/union.js +1 -187
- package/dist/validators/unknown.js +1 -37
- package/dist/validators/void.js +1 -44
- package/dist/validators/xor.d.ts +2 -2
- package/dist/validators/xor.js +1 -66
- package/package.json +240 -238
- package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
- package/dist/chunks/index-0R2ntSud.js +0 -508
- package/dist/chunks/index-BvH403Yy.js +0 -88
- package/dist/chunks/security-B0Pd_vSY.js +0 -35
- package/dist/chunks/string-BJRQod3t.js +0 -530
- package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
- package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
- package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
- package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
- package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import type { SchemaRegistry } from '../registry.js';
|
|
2
|
+
import { VldError } from '../errors-core.js';
|
|
2
3
|
/**
|
|
3
4
|
* Base result type for validation
|
|
4
5
|
*/
|
|
5
6
|
export type ParseResult<T> = {
|
|
6
7
|
readonly success: true;
|
|
7
8
|
readonly data: T;
|
|
9
|
+
readonly error?: undefined;
|
|
8
10
|
} | {
|
|
9
11
|
readonly success: false;
|
|
10
|
-
readonly error:
|
|
12
|
+
readonly error: VldError;
|
|
13
|
+
readonly data?: undefined;
|
|
11
14
|
};
|
|
15
|
+
export type SafeParseSuccess<T> = {
|
|
16
|
+
readonly success: true;
|
|
17
|
+
readonly data: T;
|
|
18
|
+
readonly error?: undefined;
|
|
19
|
+
};
|
|
20
|
+
export type SafeParseError<_T = unknown> = {
|
|
21
|
+
readonly success: false;
|
|
22
|
+
readonly error: VldError;
|
|
23
|
+
readonly data?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export type SafeParseReturnType<_Input, Output> = SafeParseSuccess<Output> | SafeParseError<_Input>;
|
|
26
|
+
export declare function ensureVldError(error: unknown): VldError;
|
|
12
27
|
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
13
28
|
readonly '~standard': StandardTypedV1Props<Input, Output>;
|
|
14
29
|
}
|
|
@@ -112,25 +127,59 @@ export declare const VLD_VALIDATOR_TYPES: {
|
|
|
112
127
|
};
|
|
113
128
|
export type ValidatorType = typeof VLD_VALIDATOR_TYPES[keyof typeof VLD_VALIDATOR_TYPES];
|
|
114
129
|
/**
|
|
115
|
-
* Context for superRefine - allows adding multiple issues
|
|
130
|
+
* Context for superRefine - allows adding multiple issues with path and code
|
|
116
131
|
*/
|
|
117
132
|
export interface SuperRefineContext {
|
|
118
133
|
addIssue(issue: {
|
|
119
134
|
message: string;
|
|
120
135
|
code?: string;
|
|
136
|
+
path?: (string | number)[];
|
|
137
|
+
fatal?: boolean;
|
|
138
|
+
[key: string]: any;
|
|
121
139
|
}): void;
|
|
122
140
|
path: (string | number)[];
|
|
123
141
|
}
|
|
142
|
+
export interface CheckPayload<T> {
|
|
143
|
+
value: T;
|
|
144
|
+
issues: Array<{
|
|
145
|
+
message?: string;
|
|
146
|
+
code?: string;
|
|
147
|
+
path?: (string | number)[];
|
|
148
|
+
}>;
|
|
149
|
+
aborted?: boolean;
|
|
150
|
+
}
|
|
151
|
+
export type VldCheck<T> = ((payload: CheckPayload<T>) => void | Promise<void>) | {
|
|
152
|
+
_zod?: {
|
|
153
|
+
check?: (payload: CheckPayload<T>) => void | Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export type CustomErrorParams = {
|
|
157
|
+
message?: string;
|
|
158
|
+
path?: (string | number)[];
|
|
159
|
+
params?: {
|
|
160
|
+
[k: string]: any;
|
|
161
|
+
};
|
|
162
|
+
fatal?: boolean;
|
|
163
|
+
};
|
|
124
164
|
export type ErrorMap = (issue: {
|
|
125
165
|
code?: string;
|
|
126
166
|
input?: unknown;
|
|
127
167
|
path?: (string | number)[];
|
|
128
168
|
}) => string | undefined;
|
|
129
|
-
export type ErrorParam = string | {
|
|
169
|
+
export type ErrorParam = string | CustomErrorParams | ((value: any) => CustomErrorParams | string) | {
|
|
130
170
|
error?: string | ErrorMap;
|
|
131
171
|
message?: string;
|
|
132
172
|
};
|
|
133
173
|
export declare function resolveErrorMessage(error: ErrorParam | undefined, fallback: string): string;
|
|
174
|
+
export declare function isPromiseLike<T = unknown>(value: unknown): value is PromiseLike<T>;
|
|
175
|
+
type ValueOrFactory<T> = T | (() => T);
|
|
176
|
+
interface SchemaCompositionFactories {
|
|
177
|
+
array<TInput, TOutput>(schema: VldBase<TInput, TOutput>): VldBase<unknown[], TOutput[]>;
|
|
178
|
+
union<TInput, TOutput, TNext>(left: VldBase<TInput, TOutput>, right: VldBase<any, TNext>): VldBase<unknown, TOutput | TNext>;
|
|
179
|
+
intersection<TInput, TOutput, TNext>(left: VldBase<TInput, TOutput>, right: VldBase<any, TNext>): VldBase<unknown, TOutput & TNext>;
|
|
180
|
+
toJSONSchema(schema: VldBase<any, any>, options?: unknown): unknown;
|
|
181
|
+
}
|
|
182
|
+
export declare function configureSchemaCompositionFactories(factories: SchemaCompositionFactories): void;
|
|
134
183
|
/**
|
|
135
184
|
* Abstract base class for all validators
|
|
136
185
|
* Implements immutable pattern to prevent memory leaks and race conditions
|
|
@@ -146,6 +195,10 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
146
195
|
* @param validatorType The runtime type identifier
|
|
147
196
|
*/
|
|
148
197
|
constructor(validatorType?: ValidatorType);
|
|
198
|
+
get type(): string;
|
|
199
|
+
get _def(): any;
|
|
200
|
+
get def(): any;
|
|
201
|
+
get _zod(): any;
|
|
149
202
|
get '~standard'(): StandardSchemaV1Props<unknown, TOutput>;
|
|
150
203
|
/**
|
|
151
204
|
* Parse and validate a value, throwing an error if invalid
|
|
@@ -162,6 +215,26 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
162
215
|
abstract safeParse(value: unknown): ParseResult<TOutput>;
|
|
163
216
|
parseAsync(value: unknown): Promise<TOutput>;
|
|
164
217
|
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
218
|
+
/** Strongly typed forward parse aliases from the Zod 4 codec API. */
|
|
219
|
+
decode(value: TInput): TOutput;
|
|
220
|
+
safeDecode(value: TInput): ParseResult<TOutput>;
|
|
221
|
+
decodeAsync(value: TInput): Promise<TOutput>;
|
|
222
|
+
safeDecodeAsync(value: TInput): Promise<ParseResult<TOutput>>;
|
|
223
|
+
/**
|
|
224
|
+
* Backward parse aliases. Primitive and validation-only schemas are
|
|
225
|
+
* bidirectional; codecs override these methods with their inverse transform.
|
|
226
|
+
*/
|
|
227
|
+
encode(value: TOutput): TInput;
|
|
228
|
+
safeEncode(value: TOutput): ParseResult<TInput>;
|
|
229
|
+
encodeAsync(value: TOutput): Promise<TInput>;
|
|
230
|
+
safeEncodeAsync(value: TOutput): Promise<ParseResult<TInput>>;
|
|
231
|
+
/** Zod's short alias for safeParseAsync. */
|
|
232
|
+
spa(value: unknown): Promise<ParseResult<TOutput>>;
|
|
233
|
+
/** Compatibility helpers retained by Zod 4. */
|
|
234
|
+
isOptional(): boolean;
|
|
235
|
+
isNullable(): boolean;
|
|
236
|
+
/** VLD validators are immutable, so cloning can safely share the instance. */
|
|
237
|
+
clone(): this;
|
|
165
238
|
/**
|
|
166
239
|
* Check if a value is valid according to this validator
|
|
167
240
|
* @param value The value to check
|
|
@@ -182,8 +255,8 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
182
255
|
* @param message Optional custom error message
|
|
183
256
|
* @returns A new refined validator
|
|
184
257
|
*/
|
|
185
|
-
refine<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: string): VldRefine<TInput, TOutput, TRefined>;
|
|
186
|
-
refine(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: string): VldRefine<TInput, TOutput, TOutput>;
|
|
258
|
+
refine<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: ErrorParam | CustomErrorParams | ((val: TOutput) => CustomErrorParams | string)): VldRefine<TInput, TOutput, TRefined>;
|
|
259
|
+
refine(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: ErrorParam | CustomErrorParams | ((val: TOutput) => CustomErrorParams | string)): VldRefine<TInput, TOutput, TOutput>;
|
|
187
260
|
/**
|
|
188
261
|
* Advanced refinement with context for adding multiple issues
|
|
189
262
|
* @param refinement The refinement function with context
|
|
@@ -201,7 +274,16 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
201
274
|
* @param defaultValue The default value
|
|
202
275
|
* @returns A new validator with default
|
|
203
276
|
*/
|
|
204
|
-
default(defaultValue: TOutput): VldDefault<TInput, TOutput>;
|
|
277
|
+
default(defaultValue: ValueOrFactory<TOutput>): VldDefault<TInput, TOutput>;
|
|
278
|
+
/** Provide an input value before parsing when the input is undefined. */
|
|
279
|
+
prefault(defaultValue: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
280
|
+
nonoptional(message?: ErrorParam): VldRefine<TInput, TOutput, TOutput>;
|
|
281
|
+
array(): VldBase<unknown[], TOutput[]>;
|
|
282
|
+
or<TNext>(option: VldBase<any, TNext>): VldBase<unknown, TOutput | TNext>;
|
|
283
|
+
and<TNext>(incoming: VldBase<any, TNext>): VldBase<unknown, TOutput & TNext>;
|
|
284
|
+
overwrite(transformer: (value: TOutput) => TOutput): VldTransform<TInput, TOutput, TOutput>;
|
|
285
|
+
with(...checks: VldCheck<TOutput>[]): VldSuperRefine<TInput, TOutput>;
|
|
286
|
+
toJSONSchema(options?: unknown): unknown;
|
|
205
287
|
/**
|
|
206
288
|
* Create a new validator that catches errors and returns a fallback
|
|
207
289
|
* @param fallbackValue The fallback value
|
|
@@ -236,7 +318,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
236
318
|
* @param next The next validator to pipe into
|
|
237
319
|
* @returns A new piped validator
|
|
238
320
|
*/
|
|
239
|
-
pipe<TNextOutput>(next: VldBase<
|
|
321
|
+
pipe<TNextOutput>(next: VldBase<any, TNextOutput>): VldPipe<TInput, TOutput, TNextOutput>;
|
|
240
322
|
/**
|
|
241
323
|
* Create a new validator that returns readonly output
|
|
242
324
|
* Zod 4 API parity - marks output as readonly for TypeScript
|
|
@@ -266,7 +348,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
266
348
|
* const withLength = (schema: VldBase<unknown, string>) => schema.transform(s => s.length);
|
|
267
349
|
* const lengthSchema = v.string().apply(withLength); // validates string, returns number
|
|
268
350
|
*/
|
|
269
|
-
apply<
|
|
351
|
+
apply<TResult>(fn: (schema: this) => TResult): TResult;
|
|
270
352
|
/**
|
|
271
353
|
* Create a new validator that refines this one with a custom predicate
|
|
272
354
|
* Alias for refine() - check() is the Zod 4 API name
|
|
@@ -274,8 +356,8 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
274
356
|
* @param message Optional custom error message
|
|
275
357
|
* @returns A new refined validator
|
|
276
358
|
*/
|
|
277
|
-
check<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: string): VldRefine<TInput, TOutput, TRefined>;
|
|
278
|
-
check(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: string): VldRefine<TInput, TOutput, TOutput>;
|
|
359
|
+
check<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: ErrorParam | CustomErrorParams | ((val: TOutput) => CustomErrorParams | string)): VldRefine<TInput, TOutput, TRefined>;
|
|
360
|
+
check(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: ErrorParam | CustomErrorParams | ((val: TOutput) => CustomErrorParams | string)): VldRefine<TInput, TOutput, TOutput>;
|
|
279
361
|
/**
|
|
280
362
|
* Get metadata for this schema
|
|
281
363
|
* Zod 4 API parity - allows attaching OpenAPI/JSON Schema metadata
|
|
@@ -289,6 +371,11 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
289
371
|
* @returns A new validator with the metadata
|
|
290
372
|
*/
|
|
291
373
|
meta(data: Partial<SchemaMetadata>): VldMeta<TInput, TOutput>;
|
|
374
|
+
/**
|
|
375
|
+
* Get or set metadata for this schema
|
|
376
|
+
*/
|
|
377
|
+
meta(): SchemaMetadata | undefined;
|
|
378
|
+
meta(data: Partial<SchemaMetadata>): VldMeta<TInput, TOutput>;
|
|
292
379
|
/**
|
|
293
380
|
* Register this schema in a metadata registry and return the same instance.
|
|
294
381
|
* This mirrors Zod 4's registry convenience API without changing validator
|
|
@@ -302,6 +389,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
302
389
|
* @returns A new validator with the description
|
|
303
390
|
*/
|
|
304
391
|
describe(description: string): VldMeta<TInput, TOutput>;
|
|
392
|
+
get description(): string | undefined;
|
|
305
393
|
}
|
|
306
394
|
/**
|
|
307
395
|
* Schema metadata interface for OpenAPI/JSON Schema compatibility
|
|
@@ -365,11 +453,63 @@ export declare class VldBrand<TInput, TOutput, TBrand extends string> extends Vl
|
|
|
365
453
|
export declare class VldRefine<TInput, TBase, TOutput extends TBase = TBase> extends VldBase<TInput, TOutput> {
|
|
366
454
|
private readonly baseValidator;
|
|
367
455
|
private readonly predicate;
|
|
368
|
-
private readonly customMessage
|
|
369
|
-
|
|
456
|
+
private readonly customMessage;
|
|
457
|
+
private readonly refinePath?;
|
|
458
|
+
constructor(baseValidator: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, customMessage?: ErrorParam | CustomErrorParams | ((val: TBase) => CustomErrorParams | string));
|
|
459
|
+
private _createIssue;
|
|
370
460
|
parse(value: unknown): TOutput;
|
|
371
461
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
372
462
|
parseAsync(value: unknown): Promise<TOutput>;
|
|
463
|
+
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
464
|
+
private _wrap;
|
|
465
|
+
min(length: number | Date | bigint | any, message?: ErrorParam): this;
|
|
466
|
+
max(length: number | Date | bigint | any, message?: ErrorParam): this;
|
|
467
|
+
length(length: number, message?: ErrorParam): this;
|
|
468
|
+
email(message?: ErrorParam): this;
|
|
469
|
+
url(message?: ErrorParam): this;
|
|
470
|
+
uuid(message?: ErrorParam): this;
|
|
471
|
+
regex(pattern: RegExp, message?: ErrorParam): this;
|
|
472
|
+
startsWith(str: string, message?: ErrorParam): this;
|
|
473
|
+
endsWith(str: string, message?: ErrorParam): this;
|
|
474
|
+
includes(str: string, message?: ErrorParam): this;
|
|
475
|
+
ip(message?: ErrorParam): this;
|
|
476
|
+
ipv4(message?: ErrorParam): this;
|
|
477
|
+
ipv6(message?: ErrorParam): this;
|
|
478
|
+
nonempty(message?: ErrorParam): this;
|
|
479
|
+
trim(): this;
|
|
480
|
+
toLowerCase(): this;
|
|
481
|
+
lowercase(): this;
|
|
482
|
+
toUpperCase(): this;
|
|
483
|
+
uppercase(): this;
|
|
484
|
+
positive(message?: ErrorParam): this;
|
|
485
|
+
negative(message?: ErrorParam): this;
|
|
486
|
+
nonnegative(message?: ErrorParam): this;
|
|
487
|
+
nonpositive(message?: ErrorParam): this;
|
|
488
|
+
int(message?: ErrorParam): this;
|
|
489
|
+
finite(message?: ErrorParam): this;
|
|
490
|
+
safe(message?: ErrorParam): this;
|
|
491
|
+
multipleOf(value: number, message?: ErrorParam): this;
|
|
492
|
+
step(value: number, message?: ErrorParam): this;
|
|
493
|
+
gt(value: any, message?: ErrorParam): this;
|
|
494
|
+
gte(value: any, message?: ErrorParam): this;
|
|
495
|
+
lt(value: any, message?: ErrorParam): this;
|
|
496
|
+
lte(value: any, message?: ErrorParam): this;
|
|
497
|
+
extend<U extends Record<string, any>>(extension: {
|
|
498
|
+
[K in keyof U]: VldBase<unknown, U[K]>;
|
|
499
|
+
}): any;
|
|
500
|
+
merge(other: any): any;
|
|
501
|
+
pick<K extends keyof TOutput>(...keys: K[]): any;
|
|
502
|
+
omit<K extends keyof TOutput>(...keys: K[]): any;
|
|
503
|
+
partial(): any;
|
|
504
|
+
required(): any;
|
|
505
|
+
strict(message?: ErrorParam): this;
|
|
506
|
+
passthrough(): this;
|
|
507
|
+
strip(): this;
|
|
508
|
+
catchall(validator: any): this;
|
|
509
|
+
get shape(): any;
|
|
510
|
+
get keyof(): any;
|
|
511
|
+
unwrap(): any;
|
|
512
|
+
get element(): any;
|
|
373
513
|
}
|
|
374
514
|
/**
|
|
375
515
|
* Transform validator - transforms data after validation
|
|
@@ -390,14 +530,16 @@ export declare class VldTransform<TInput, TBase, TOutput> extends VldBase<TInput
|
|
|
390
530
|
export declare class VldDefault<TInput, TOutput> extends VldBase<TInput | undefined, TOutput> {
|
|
391
531
|
private readonly baseValidator;
|
|
392
532
|
private readonly defaultValue;
|
|
393
|
-
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: TOutput);
|
|
533
|
+
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: ValueOrFactory<TOutput>);
|
|
394
534
|
parse(value: unknown): TOutput;
|
|
395
535
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
396
536
|
/**
|
|
397
537
|
* Pre-parse default - validates the default value instead of returning it directly
|
|
398
538
|
* This is useful when the default value needs to be validated against the schema
|
|
399
539
|
*/
|
|
400
|
-
prefault(): VldPrefault<TInput, TOutput>;
|
|
540
|
+
prefault(defaultValue?: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
541
|
+
unwrap(): VldBase<TInput, TOutput>;
|
|
542
|
+
removeDefault(): VldBase<TInput, TOutput>;
|
|
401
543
|
}
|
|
402
544
|
/**
|
|
403
545
|
* Prefault validator - validates the default value instead of returning it directly
|
|
@@ -405,13 +547,14 @@ export declare class VldDefault<TInput, TOutput> extends VldBase<TInput | undefi
|
|
|
405
547
|
export declare class VldPrefault<TInput, TOutput> extends VldBase<TInput | undefined, TOutput> {
|
|
406
548
|
private readonly baseValidator;
|
|
407
549
|
private readonly defaultValue;
|
|
408
|
-
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue:
|
|
550
|
+
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: ValueOrFactory<TInput>);
|
|
409
551
|
parse(value: unknown): TOutput;
|
|
410
552
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
411
553
|
/**
|
|
412
554
|
* Calling prefault multiple times should be safe - return self
|
|
413
555
|
*/
|
|
414
|
-
prefault(): VldPrefault<TInput, TOutput>;
|
|
556
|
+
prefault(defaultValue?: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
557
|
+
unwrap(): VldBase<TInput, TOutput>;
|
|
415
558
|
}
|
|
416
559
|
/**
|
|
417
560
|
* Catch validator - provides fallback value on validation error
|
|
@@ -483,7 +626,7 @@ export declare class VldNullish<TInput, TOutput> extends VldBase<TInput | null |
|
|
|
483
626
|
export declare class VldPipe<TInput, TIntermediate, TOutput> extends VldBase<TInput, TOutput> {
|
|
484
627
|
private readonly first;
|
|
485
628
|
private readonly second;
|
|
486
|
-
constructor(first: VldBase<TInput, TIntermediate>, second: VldBase<
|
|
629
|
+
constructor(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>);
|
|
487
630
|
parse(value: unknown): TOutput;
|
|
488
631
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
489
632
|
}
|
|
@@ -498,6 +641,55 @@ export declare class VldSuperRefine<TInput, TOutput> extends VldBase<TInput, TOu
|
|
|
498
641
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
499
642
|
parseAsync(value: unknown): Promise<TOutput>;
|
|
500
643
|
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
644
|
+
private _wrap;
|
|
645
|
+
min(length: number | Date | bigint | any, message?: ErrorParam): this;
|
|
646
|
+
max(length: number | Date | bigint | any, message?: ErrorParam): this;
|
|
647
|
+
length(length: number, message?: ErrorParam): this;
|
|
648
|
+
email(message?: ErrorParam): this;
|
|
649
|
+
url(message?: ErrorParam): this;
|
|
650
|
+
uuid(message?: ErrorParam): this;
|
|
651
|
+
regex(pattern: RegExp, message?: ErrorParam): this;
|
|
652
|
+
startsWith(str: string, message?: ErrorParam): this;
|
|
653
|
+
endsWith(str: string, message?: ErrorParam): this;
|
|
654
|
+
includes(str: string, message?: ErrorParam): this;
|
|
655
|
+
ip(message?: ErrorParam): this;
|
|
656
|
+
ipv4(message?: ErrorParam): this;
|
|
657
|
+
ipv6(message?: ErrorParam): this;
|
|
658
|
+
nonempty(message?: ErrorParam): this;
|
|
659
|
+
trim(): this;
|
|
660
|
+
toLowerCase(): this;
|
|
661
|
+
lowercase(): this;
|
|
662
|
+
toUpperCase(): this;
|
|
663
|
+
uppercase(): this;
|
|
664
|
+
positive(message?: ErrorParam): this;
|
|
665
|
+
negative(message?: ErrorParam): this;
|
|
666
|
+
nonnegative(message?: ErrorParam): this;
|
|
667
|
+
nonpositive(message?: ErrorParam): this;
|
|
668
|
+
int(message?: ErrorParam): this;
|
|
669
|
+
finite(message?: ErrorParam): this;
|
|
670
|
+
safe(message?: ErrorParam): this;
|
|
671
|
+
multipleOf(value: number, message?: ErrorParam): this;
|
|
672
|
+
step(value: number, message?: ErrorParam): this;
|
|
673
|
+
gt(value: any, message?: ErrorParam): this;
|
|
674
|
+
gte(value: any, message?: ErrorParam): this;
|
|
675
|
+
lt(value: any, message?: ErrorParam): this;
|
|
676
|
+
lte(value: any, message?: ErrorParam): this;
|
|
677
|
+
extend<U extends Record<string, any>>(extension: {
|
|
678
|
+
[K in keyof U]: VldBase<unknown, U[K]>;
|
|
679
|
+
}): any;
|
|
680
|
+
merge(other: any): any;
|
|
681
|
+
pick<K extends keyof TOutput>(...keys: K[]): any;
|
|
682
|
+
omit<K extends keyof TOutput>(...keys: K[]): any;
|
|
683
|
+
partial(): any;
|
|
684
|
+
required(): any;
|
|
685
|
+
strict(message?: ErrorParam): this;
|
|
686
|
+
passthrough(): this;
|
|
687
|
+
strip(): this;
|
|
688
|
+
catchall(validator: any): this;
|
|
689
|
+
get shape(): any;
|
|
690
|
+
get keyof(): any;
|
|
691
|
+
unwrap(): any;
|
|
692
|
+
get element(): any;
|
|
501
693
|
}
|
|
502
694
|
/**
|
|
503
695
|
* Preprocess validator - transforms input before validation
|
|
@@ -510,3 +702,4 @@ export declare class VldPreprocess<TInput, TOutput> extends VldBase<unknown, TOu
|
|
|
510
702
|
parse(value: unknown): TOutput;
|
|
511
703
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
512
704
|
}
|
|
705
|
+
export {};
|