justus 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dts-generator.js → dts-generator.cjs} +3 -3
- package/dist/{dts-generator.js.map → dts-generator.cjs.map} +1 -1
- package/{dts-generator.d.ts → dist/dts-generator.d.ts} +1 -1
- package/dist/dts-generator.mjs +1 -1
- package/dist/dts-generator.mjs.map +1 -1
- package/dist/errors.cjs +113 -0
- package/dist/errors.cjs.map +6 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.mjs +85 -0
- package/dist/errors.mjs.map +6 -0
- package/dist/index.cjs +133 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +23 -817
- package/dist/index.mjs.map +3 -3
- package/dist/schema.cjs +44 -0
- package/dist/schema.cjs.map +6 -0
- package/dist/schema.d.ts +16 -0
- package/dist/schema.mjs +18 -0
- package/dist/schema.mjs.map +6 -0
- package/dist/types.cjs +67 -0
- package/dist/types.cjs.map +6 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.mjs +36 -0
- package/dist/types.mjs.map +6 -0
- package/dist/utilities.cjs +54 -0
- package/dist/utilities.cjs.map +6 -0
- package/dist/utilities.d.ts +7 -0
- package/dist/utilities.mjs +29 -0
- package/dist/utilities.mjs.map +6 -0
- package/dist/validators/any.cjs +39 -0
- package/dist/validators/any.cjs.map +6 -0
- package/dist/validators/any.d.ts +7 -0
- package/dist/validators/any.mjs +13 -0
- package/dist/validators/any.mjs.map +6 -0
- package/dist/validators/array.cjs +104 -0
- package/dist/validators/array.cjs.map +6 -0
- package/dist/validators/array.d.ts +32 -0
- package/dist/validators/array.mjs +76 -0
- package/dist/validators/array.mjs.map +6 -0
- package/dist/validators/boolean.cjs +56 -0
- package/dist/validators/boolean.cjs.map +6 -0
- package/dist/validators/boolean.d.ts +21 -0
- package/dist/validators/boolean.mjs +30 -0
- package/dist/validators/boolean.mjs.map +6 -0
- package/dist/validators/constant.cjs +51 -0
- package/dist/validators/constant.cjs.map +6 -0
- package/dist/validators/constant.d.ts +12 -0
- package/dist/validators/constant.mjs +24 -0
- package/dist/validators/constant.mjs.map +6 -0
- package/dist/validators/date.cjs +80 -0
- package/dist/validators/date.cjs.map +6 -0
- package/dist/validators/date.d.ts +22 -0
- package/dist/validators/date.mjs +54 -0
- package/dist/validators/date.mjs.map +6 -0
- package/dist/validators/never.cjs +44 -0
- package/dist/validators/never.cjs.map +6 -0
- package/dist/validators/never.d.ts +9 -0
- package/dist/validators/never.mjs +18 -0
- package/dist/validators/never.mjs.map +6 -0
- package/dist/validators/number.cjs +153 -0
- package/dist/validators/number.cjs.map +6 -0
- package/dist/validators/number.d.ts +48 -0
- package/dist/validators/number.mjs +126 -0
- package/dist/validators/number.mjs.map +6 -0
- package/dist/validators/object.cjs +129 -0
- package/dist/validators/object.cjs.map +6 -0
- package/dist/validators/object.d.ts +22 -0
- package/dist/validators/object.mjs +108 -0
- package/dist/validators/object.mjs.map +6 -0
- package/dist/validators/optional.cjs +61 -0
- package/dist/validators/optional.cjs.map +6 -0
- package/dist/validators/optional.d.ts +21 -0
- package/dist/validators/optional.mjs +35 -0
- package/dist/validators/optional.mjs.map +6 -0
- package/dist/validators/string.cjs +84 -0
- package/dist/validators/string.cjs.map +6 -0
- package/dist/validators/string.d.ts +35 -0
- package/dist/validators/string.mjs +57 -0
- package/dist/validators/string.mjs.map +6 -0
- package/dist/validators/tuple.cjs +95 -0
- package/dist/validators/tuple.cjs.map +6 -0
- package/dist/validators/tuple.d.ts +15 -0
- package/dist/validators/tuple.mjs +69 -0
- package/dist/validators/tuple.mjs.map +6 -0
- package/dist/validators/union.cjs +78 -0
- package/dist/validators/union.cjs.map +6 -0
- package/dist/validators/union.d.ts +22 -0
- package/dist/validators/union.mjs +50 -0
- package/dist/validators/union.mjs.map +6 -0
- package/dist/validators/url.cjs +117 -0
- package/dist/validators/url.cjs.map +6 -0
- package/dist/validators/url.d.ts +57 -0
- package/dist/validators/url.mjs +91 -0
- package/dist/validators/url.mjs.map +6 -0
- package/package.json +33 -23
- package/src/dts-generator.ts +4 -0
- package/src/index.ts +23 -23
- package/src/schema.ts +7 -5
- package/src/types.ts +19 -9
- package/src/utilities.ts +6 -2
- package/src/validators/array.ts +6 -5
- package/src/validators/boolean.ts +2 -2
- package/src/validators/constant.ts +3 -1
- package/src/validators/date.ts +1 -1
- package/src/validators/never.ts +4 -2
- package/src/validators/number.ts +8 -7
- package/src/validators/object.ts +12 -12
- package/src/validators/optional.ts +5 -7
- package/src/validators/string.ts +8 -6
- package/src/validators/tuple.ts +5 -3
- package/src/validators/union.ts +7 -5
- package/src/validators/url.ts +8 -7
- package/dist/index.js +0 -948
- package/dist/index.js.map +0 -6
- package/index.d.ts +0 -618
package/src/types.ts
CHANGED
|
@@ -22,12 +22,21 @@ export const additionalValidator = Symbol.for('justus.additionalValidator')
|
|
|
22
22
|
* Options to be using while validating.
|
|
23
23
|
*/
|
|
24
24
|
export interface ValidationOptions {
|
|
25
|
-
/** Strip additional, undeclared properties from objects */
|
|
26
|
-
|
|
27
|
-
/** Strip `null`s from an object when associated with an optional key */
|
|
28
|
-
|
|
29
|
-
/** Ignore and strip forbidden (`never`) properties from objects */
|
|
30
|
-
|
|
25
|
+
/** Strip additional, undeclared properties from objects (default: `false`) */
|
|
26
|
+
stripAdditionalProperties?: boolean,
|
|
27
|
+
/** Strip `null`s from an object when associated with an optional key (default: `false`) */
|
|
28
|
+
stripOptionalNulls?: boolean,
|
|
29
|
+
/** Ignore and strip forbidden (`never`) properties from objects (default: `false`) */
|
|
30
|
+
stripForbiddenProperties?: boolean,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default validation options.
|
|
35
|
+
*/
|
|
36
|
+
export const defaultValidationOptions: Readonly<Required<ValidationOptions>> = {
|
|
37
|
+
stripAdditionalProperties: false,
|
|
38
|
+
stripForbiddenProperties: false,
|
|
39
|
+
stripOptionalNulls: false,
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
/**
|
|
@@ -40,7 +49,7 @@ export interface Validator<T = any> extends Iterable<TupleRestParameter<T>> {
|
|
|
40
49
|
optional?: boolean
|
|
41
50
|
|
|
42
51
|
/** Validate a _value_ and optionally convert it to the required `Type` */
|
|
43
|
-
validate(value: unknown, options
|
|
52
|
+
validate(value: unknown, options?: ValidationOptions | undefined): T
|
|
44
53
|
|
|
45
54
|
/** Allow any `Validator` to be used as a rest parameter in `Tuple`s */
|
|
46
55
|
[Symbol.iterator](): Generator<TupleRestParameter<T>>;
|
|
@@ -68,13 +77,14 @@ export function makeValidatorFactory<
|
|
|
68
77
|
* A `Validator` is an object capable of validating a given _value_ and
|
|
69
78
|
* (possibly) converting it the required type `T`.
|
|
70
79
|
*/
|
|
71
|
-
export abstract class AbstractValidator<T = any>
|
|
80
|
+
export abstract class AbstractValidator<T = any>
|
|
81
|
+
implements Validator<T>, Iterable<TupleRestParameter<T>> {
|
|
72
82
|
[isValidator]: true = true
|
|
73
83
|
|
|
74
84
|
optional?: boolean = undefined
|
|
75
85
|
|
|
76
86
|
/** Validate a _value_ and optionally convert it to the required `Type` */
|
|
77
|
-
abstract validate(value: unknown, options
|
|
87
|
+
abstract validate(value: unknown, options?: ValidationOptions | undefined): T
|
|
78
88
|
|
|
79
89
|
/** Allow any `Validator` to be used as a rest parameter in `Tuple`s */
|
|
80
90
|
* [Symbol.iterator](): Generator<TupleRestParameter<T>> {
|
package/src/utilities.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { isValidator, schemaValidator } from './types'
|
|
1
2
|
import { ConstantValidator, nullValidator } from './validators/constant'
|
|
2
|
-
|
|
3
|
-
import { TupleValidator } from './validators/tuple'
|
|
3
|
+
// eslint-disable-next-line import/no-cycle
|
|
4
4
|
import { ObjectValidator } from './validators/object'
|
|
5
|
+
// eslint-disable-next-line import/no-cycle
|
|
6
|
+
import { TupleValidator } from './validators/tuple'
|
|
7
|
+
|
|
8
|
+
import type { Schema, Validation, Validator } from './types'
|
|
5
9
|
|
|
6
10
|
/* ========================================================================== *
|
|
7
11
|
* UTILITY FUNCTIONS *
|
package/src/validators/array.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { assertSchema, assertValidation, ValidationErrorBuilder } from '../errors'
|
|
2
|
-
import {
|
|
2
|
+
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
3
3
|
import { getValidator } from '../utilities'
|
|
4
4
|
import { any } from './any'
|
|
5
5
|
|
|
6
|
+
import type { InferValidation, Validation, ValidationOptions, Validator } from '../types'
|
|
7
|
+
|
|
6
8
|
/* ========================================================================== *
|
|
7
9
|
* ARRAYS VALIDATION *
|
|
8
10
|
* ========================================================================== */
|
|
@@ -21,8 +23,7 @@ export interface ArrayConstraints<V extends Validation> {
|
|
|
21
23
|
|
|
22
24
|
/** Basic validator for `Array` instances. */
|
|
23
25
|
export class AnyArrayValidator<T = any> extends AbstractValidator<T[]> {
|
|
24
|
-
validate(value: unknown
|
|
25
|
-
void options
|
|
26
|
+
validate(value: unknown): T[] {
|
|
26
27
|
assertValidation(Array.isArray(value), 'Value is not an "array"')
|
|
27
28
|
return [ ...value ]
|
|
28
29
|
}
|
|
@@ -55,7 +56,7 @@ export class ArrayValidator<T> extends AbstractValidator<T[]> {
|
|
|
55
56
|
this.uniqueItems = uniqueItems
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
validate(value: unknown, options
|
|
59
|
+
validate(value: unknown, options?: ValidationOptions): T[] {
|
|
59
60
|
assertValidation(Array.isArray(value), 'Value is not an "array"')
|
|
60
61
|
|
|
61
62
|
assertValidation(value.length >= this.minItems,
|
|
@@ -88,7 +89,7 @@ export class ArrayValidator<T> extends AbstractValidator<T[]> {
|
|
|
88
89
|
|
|
89
90
|
/* -------------------------------------------------------------------------- */
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
function _array<V extends Validation>(constraints: ArrayConstraints<V>): ArrayValidator<InferValidation<V>> {
|
|
92
93
|
const items = constraints.items ? getValidator(constraints.items) : any
|
|
93
94
|
return new ArrayValidator({ ...constraints, items })
|
|
94
95
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
2
1
|
import { assertValidation } from '../errors'
|
|
2
|
+
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
3
3
|
|
|
4
4
|
/** Constraints to validate a `boolean` with. */
|
|
5
5
|
export interface BooleanConstraints {
|
|
@@ -37,7 +37,7 @@ export class BooleanValidator extends AbstractValidator<boolean> {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
function _boolean(constraints: BooleanConstraints): BooleanValidator {
|
|
41
41
|
return new BooleanValidator(constraints)
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { AbstractValidator, Validator } from '../types'
|
|
2
1
|
import { assertValidation } from '../errors'
|
|
2
|
+
import { AbstractValidator } from '../types'
|
|
3
|
+
|
|
4
|
+
import type { Validator } from '../types'
|
|
3
5
|
|
|
4
6
|
/** A `Validator` for _constants_. */
|
|
5
7
|
export class ConstantValidator<T extends string | number | boolean | null> extends AbstractValidator<T> {
|
package/src/validators/date.ts
CHANGED
package/src/validators/never.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ValidationError } from '../errors'
|
|
2
|
-
import {
|
|
2
|
+
import { AbstractValidator, defaultValidationOptions } from '../types'
|
|
3
|
+
|
|
4
|
+
import type { ValidationOptions } from '../types'
|
|
3
5
|
|
|
4
6
|
/** A `Validator` validating _nothing_. */
|
|
5
7
|
export class NeverValidator extends AbstractValidator<never> {
|
|
6
8
|
optional: true = true
|
|
7
9
|
|
|
8
|
-
validate(value: unknown, options: ValidationOptions): never {
|
|
10
|
+
validate(value: unknown, options: ValidationOptions = defaultValidationOptions): never {
|
|
9
11
|
const { stripForbiddenProperties } = options
|
|
10
12
|
|
|
11
13
|
// @ts-expect-error
|
package/src/validators/number.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { assertSchema, assertValidation, ValidationError } from '../errors'
|
|
2
|
+
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
3
|
+
|
|
4
|
+
import type { Branding, Validator } from '../types'
|
|
4
5
|
|
|
5
6
|
/* ========================================================================== */
|
|
6
7
|
|
|
@@ -160,10 +161,10 @@ export class NumberValidator<N extends number = number> extends AbstractValidato
|
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
function _number(constraints: NumberConstraints): NumberValidator<number>
|
|
165
|
+
function _number<N extends number>(constraints: NumberConstraints): NumberValidator<N>
|
|
166
|
+
function _number<B extends string>(constraints: BrandedNumberConstraints<B>): NumberValidator<number & Branding<B>>
|
|
167
|
+
function _number(constraints: NumberConstraints): Validator<number> {
|
|
167
168
|
return new NumberValidator(constraints)
|
|
168
169
|
}
|
|
169
170
|
|
package/src/validators/object.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
import { assertValidation, ValidationErrorBuilder } from '../errors'
|
|
2
|
+
// eslint-disable-next-line import/no-cycle
|
|
3
|
+
import { allowAdditionalProperties } from '../schema'
|
|
1
4
|
import {
|
|
2
|
-
InferSchema,
|
|
3
|
-
Schema,
|
|
4
|
-
TupleRestParameter,
|
|
5
|
-
ValidationOptions,
|
|
6
|
-
Validator,
|
|
7
5
|
AbstractValidator,
|
|
8
6
|
additionalValidator,
|
|
7
|
+
defaultValidationOptions,
|
|
8
|
+
makeValidatorFactory,
|
|
9
9
|
restValidator,
|
|
10
10
|
schemaValidator,
|
|
11
|
-
makeValidatorFactory,
|
|
12
|
-
Validation,
|
|
13
|
-
InferValidation,
|
|
14
11
|
} from '../types'
|
|
15
|
-
import { assertValidation, ValidationErrorBuilder } from '../errors'
|
|
16
12
|
import { getValidator } from '../utilities'
|
|
17
|
-
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
InferSchema, InferValidation, Schema, TupleRestParameter, Validation, ValidationOptions,
|
|
16
|
+
Validator,
|
|
17
|
+
} from '../types'
|
|
18
18
|
|
|
19
19
|
/* ========================================================================== *
|
|
20
20
|
* OBJECT VALIDATOR *
|
|
@@ -49,7 +49,7 @@ export class ObjectValidator<S extends Schema> extends AbstractValidator<InferSc
|
|
|
49
49
|
this.schema = schema
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
validate(value: unknown, options: ValidationOptions): InferSchema<S> {
|
|
52
|
+
validate(value: unknown, options: ValidationOptions = defaultValidationOptions): InferSchema<S> {
|
|
53
53
|
assertValidation(typeof value === 'object', 'Value is not an "object"')
|
|
54
54
|
assertValidation(value !== null, 'Value is "null"')
|
|
55
55
|
|
|
@@ -120,7 +120,7 @@ export class ObjectValidator<S extends Schema> extends AbstractValidator<InferSc
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
function _object<S extends Schema>(schema: S): S & {
|
|
124
124
|
[Symbol.iterator](): Generator<TupleRestParameter<InferSchema<S>>>
|
|
125
125
|
} {
|
|
126
126
|
const validator = new ObjectValidator(schema)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { AbstractValidator,
|
|
1
|
+
import { AbstractValidator, defaultValidationOptions } from '../types'
|
|
2
2
|
import { getValidator } from '../utilities'
|
|
3
3
|
|
|
4
|
+
import type { InferValidation, Validation, ValidationOptions, Validator } from '../types'
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* A `Validator` for _optional_ properties (that is `type | undefined`).
|
|
6
8
|
*/
|
|
@@ -24,17 +26,13 @@ export class OptionalValidator<
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
try {
|
|
27
|
-
this.defaultValue = validator.validate(defaultValue,
|
|
28
|
-
stripAdditionalProperties: false,
|
|
29
|
-
stripForbiddenProperties: false,
|
|
30
|
-
stripOptionalNulls: false,
|
|
31
|
-
})
|
|
29
|
+
this.defaultValue = validator.validate(defaultValue, defaultValidationOptions)
|
|
32
30
|
} catch (cause) {
|
|
33
31
|
throw new TypeError('Default value does not match validator', { cause })
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
validate(value: unknown, options
|
|
35
|
+
validate(value: unknown, options?: ValidationOptions): D extends undefined ? T | undefined : T {
|
|
38
36
|
if (value === undefined) return this.defaultValue as any // do not validate defaults!
|
|
39
37
|
return this.validator.validate(value, options)
|
|
40
38
|
}
|
package/src/validators/string.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { assertSchema, assertValidation } from '../errors'
|
|
2
|
+
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
3
|
+
|
|
4
|
+
import type { Branding, Validator } from '../types'
|
|
3
5
|
|
|
4
6
|
/** Constraints to validate a `string` with. */
|
|
5
7
|
export interface StringConstraints {
|
|
@@ -68,10 +70,10 @@ export class StringValidator<S extends string = string> extends AbstractValidato
|
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
function _string(constraints: StringConstraints): StringValidator<string>
|
|
74
|
+
function _string<S extends string>(constraints: StringConstraints): StringValidator<S>
|
|
75
|
+
function _string<B extends string>(constraints: BrandedStringConstraints<B>): StringValidator<string & Branding<B>>
|
|
76
|
+
function _string(constraints: StringConstraints): Validator<string> {
|
|
75
77
|
return new StringValidator(constraints)
|
|
76
78
|
}
|
|
77
79
|
|
package/src/validators/tuple.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Tuple, InferTuple, Validator, AbstractValidator, restValidator } from '../types'
|
|
2
|
-
import { ValidationOptions } from '../types'
|
|
3
1
|
import { assertValidation, ValidationError } from '../errors'
|
|
2
|
+
import { AbstractValidator, restValidator } from '../types'
|
|
3
|
+
// eslint-disable-next-line import/no-cycle
|
|
4
4
|
import { getValidator } from '../utilities'
|
|
5
5
|
import { nullValidator } from './constant'
|
|
6
6
|
|
|
7
|
+
import type { InferTuple, Tuple, ValidationOptions, Validator } from '../types'
|
|
8
|
+
|
|
7
9
|
export interface TupleMember { single: boolean, validator: Validator }
|
|
8
10
|
|
|
9
11
|
/** A `Validator` for _tuples_. */
|
|
@@ -29,7 +31,7 @@ export class TupleValidator<T extends Tuple> extends AbstractValidator<InferTupl
|
|
|
29
31
|
this.tuple = tuple
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
validate(value: unknown, options
|
|
34
|
+
validate(value: unknown, options?: ValidationOptions): InferTuple<T> {
|
|
33
35
|
assertValidation(Array.isArray(value), 'Value is not an "array"')
|
|
34
36
|
|
|
35
37
|
// Empty tuples
|
package/src/validators/union.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { assertSchema, ValidationErrorBuilder } from '../errors'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { AbstractValidator } from '../types'
|
|
3
|
+
import { getValidator } from '../utilities'
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
InferValidation,
|
|
4
7
|
Validation,
|
|
5
8
|
ValidationOptions,
|
|
6
9
|
Validator,
|
|
7
10
|
} from '../types'
|
|
8
|
-
import { getValidator } from '../utilities'
|
|
9
11
|
|
|
10
12
|
/* -------------------------------------------------------------------------- */
|
|
11
13
|
|
|
@@ -34,7 +36,7 @@ export class OneOfValidator<A extends OneOfArguments> extends AbstractValidator<
|
|
|
34
36
|
assertSchema(this.validators.length > 0, 'At least one validation required in "oneOf"')
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
validate(value: unknown, options
|
|
39
|
+
validate(value: unknown, options?: ValidationOptions): InferOneOfValidationType<A> {
|
|
38
40
|
const builder = new ValidationErrorBuilder()
|
|
39
41
|
for (const validator of this.validators) {
|
|
40
42
|
try {
|
|
@@ -75,7 +77,7 @@ export class AllOfValidator<A extends AllOfArguments> extends AbstractValidator<
|
|
|
75
77
|
assertSchema(this.validators.length > 0, 'At least one validation required in "allOf"')
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
validate(value: unknown, options
|
|
80
|
+
validate(value: unknown, options?: ValidationOptions): InferAllOfValidationType<A> {
|
|
79
81
|
for (const validator of this.validators) {
|
|
80
82
|
value = validator.validate(value, options)
|
|
81
83
|
}
|
package/src/validators/url.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ConstantValidator } from './constant'
|
|
2
1
|
import { ValidationError, ValidationErrorBuilder } from '../errors'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { AbstractValidator, makeValidatorFactory } from '../types'
|
|
3
|
+
import { ConstantValidator } from './constant'
|
|
4
|
+
import { ObjectValidator } from './object'
|
|
5
|
+
|
|
6
|
+
import type { ValidationOptions } from '..'
|
|
7
|
+
import type { Schema, Validator } from '../types'
|
|
5
8
|
|
|
6
9
|
const KEYS: Exclude<keyof URLConstraints, 'searchParams'>[] = [
|
|
7
10
|
'href',
|
|
@@ -127,11 +130,9 @@ export class URLValidator extends AbstractValidator<URL> {
|
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
export function _url(constraints: URLConstraints): URLValidator {
|
|
133
|
+
function _url(constraints: URLConstraints): URLValidator {
|
|
133
134
|
return new URLValidator(constraints)
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
/** Validate URLs and convert them to `URL` instances. */
|
|
137
|
-
export const url = makeValidatorFactory(
|
|
138
|
+
export const url = makeValidatorFactory(new URLValidator(), _url)
|