Skip to main content

Class: ObjectValidator<T, I>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:15

Extends

Type Parameters

Type ParameterDefault type
T extends object-
IUndefinedToOptional<T>

Constructors

new ObjectValidator()

new ObjectValidator<T, I>(shape: MappedObjectValidator<T>, strategy: ObjectValidatorStrategy, validatorOptions: ValidatorOptions, constraints: readonly IConstraint<I, I>[]): ObjectValidator<T, I>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:25

Parameters

ParameterTypeDefault value
shapeMappedObjectValidator<T>undefined
strategyObjectValidatorStrategyObjectValidatorStrategy.Ignore
validatorOptionsValidatorOptions{}
constraintsreadonly IConstraint<I, I>[][]

Returns

ObjectValidator<T, I>

Overrides

BaseValidator.constructor

Properties

constraints

protected constraints: readonly IConstraint<I, I>[] = []

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:19

Inherited from

BaseValidator.constraints


description?

optional description: string

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:16

Inherited from

BaseValidator.description


isValidationEnabled

protected isValidationEnabled: null | boolean | () => boolean = null

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:20

Inherited from

BaseValidator.isValidationEnabled


parent?

protected optional parent: object

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:18

Inherited from

BaseValidator.parent


shape

readonly shape: MappedObjectValidator<T>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:16


strategy

readonly strategy: ObjectValidatorStrategy

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:17


validatorOptions

protected validatorOptions: ValidatorOptions

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:17

Inherited from

BaseValidator.validatorOptions

Accessors

shouldRunConstraints

Get Signature

get protected shouldRunConstraints(): boolean

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:143

Returns

boolean

Inherited from

BaseValidator.shouldRunConstraints

Methods

addConstraint()

protected addConstraint(constraint: IConstraint<I, I>, validatorOptions: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:155

Parameters

ParameterType
constraintIConstraint<I, I>
validatorOptionsValidatorOptions

Returns

this

Inherited from

BaseValidator.addConstraint


array()

array(options: ValidatorOptions): ArrayValidator<I[], I>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:44

Parameters

ParameterType
optionsValidatorOptions

Returns

ArrayValidator<I[], I>

Inherited from

BaseValidator.array


clone()

protected clone(): this

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:172

Returns

this

Overrides

BaseValidator.clone


default()

default(value: Exclude<I, undefined> | () => Exclude<I, undefined>, options: ValidatorOptions): DefaultValidator<Exclude<I, undefined>>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:81

Parameters

ParameterType
valueExclude<I, undefined> | () => Exclude<I, undefined>
optionsValidatorOptions

Returns

DefaultValidator<Exclude<I, undefined>>

Inherited from

BaseValidator.default


describe()

describe(description: string): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:96

Parameters

ParameterType
descriptionstring

Returns

this

Inherited from

BaseValidator.describe


extend()

extend<ET>(schema: ObjectValidator<ET, UndefinedToOptional<ET>> | MappedObjectValidator<ET>, options: ValidatorOptions): ObjectValidator<T & ET, UndefinedToOptional<T & ET>>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:113

Type Parameters

Type Parameter
ET extends object

Parameters

ParameterType
schemaObjectValidator<ET, UndefinedToOptional<ET>> | MappedObjectValidator<ET>
optionsValidatorOptions

Returns

ObjectValidator<T & ET, UndefinedToOptional<T & ET>>


getValidationEnabled()

getValidationEnabled(): null | boolean

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:139

Returns

null | boolean

Inherited from

BaseValidator.getValidationEnabled


handle()

protected handle(value: unknown): Result<I, ValidationError | CombinedPropertyError>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:141

Parameters

ParameterType
valueunknown

Returns

Result<I, ValidationError | CombinedPropertyError>

Overrides

BaseValidator.handle


ignore()

ignore(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:89

Parameters

ParameterType
optionsValidatorOptions

Returns

this


is()

is<R>(value: unknown): value is R

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:124

Type Parameters

Type ParameterDefault type
RI

Parameters

ParameterType
valueunknown

Returns

value is R

Inherited from

BaseValidator.is


nullable()

nullable(options: ValidatorOptions): UnionValidator<null | I>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:36

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<null | I>

Inherited from

BaseValidator.nullable


nullish()

nullish(options: ValidatorOptions): UnionValidator<undefined | null | I>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:40

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | null | I>

Inherited from

BaseValidator.nullish


omit()

omit<K>(keys: readonly K[], options: ValidatorOptions): ObjectValidator<{ [Key in string | number | symbol]: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]: I[Key] }>>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:131

Type Parameters

Type Parameter
K extends string | number | symbol

Parameters

ParameterType
keysreadonly K[]
optionsValidatorOptions

Returns

ObjectValidator<{ [Key in string | number | symbol]: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]: I[Key] }>>


optional()

optional(options: ValidatorOptions): UnionValidator<undefined | I>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:32

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | I>

Inherited from

BaseValidator.optional


or()

or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<I | O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:52

Type Parameters

Type Parameter
O

Parameters

ParameterType
...predicatesreadonly BaseValidator<O>[]

Returns

UnionValidator<I | O>

Inherited from

BaseValidator.or


parse()

parse<R>(value: unknown): R

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:114

Type Parameters

Type ParameterDefault type
RI

Parameters

ParameterType
valueunknown

Returns

R

Inherited from

BaseValidator.parse


partial()

partial(options: ValidatorOptions): ObjectValidator<{ [Key in string | number | symbol]?: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]?: I[Key] }>>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:97

Parameters

ParameterType
optionsValidatorOptions

Returns

ObjectValidator<{ [Key in string | number | symbol]?: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]?: I[Key] }>>


passthrough()

passthrough(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:93

Parameters

ParameterType
optionsValidatorOptions

Returns

this


pick()

pick<K>(keys: readonly K[], options: ValidatorOptions): ObjectValidator<{ [Key in string | number | symbol]: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]: I[Key] }>>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:121

Type Parameters

Type Parameter
K extends string | number | symbol

Parameters

ParameterType
keysreadonly K[]
optionsValidatorOptions

Returns

ObjectValidator<{ [Key in string | number | symbol]: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]: I[Key] }>>


required()

required(options: ValidatorOptions): ObjectValidator<{ [Key in string | number | symbol]-?: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]-?: I[Key] }>>

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:102

Parameters

ParameterType
optionsValidatorOptions

Returns

ObjectValidator<{ [Key in string | number | symbol]-?: I[Key] }, UndefinedToOptional<{ [Key in string | number | symbol]-?: I[Key] }>>


reshape()

Call Signature

reshape(cb: (input: I) => Result<I>, options?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:67

Parameters
ParameterType
cb(input: I) => Result<I>
options?ValidatorOptions
Returns

this

Inherited from

BaseValidator.reshape

Call Signature

reshape<R, O>(cb: (input: I) => R, options?: ValidatorOptions): BaseValidator<O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:68

Type Parameters
Type ParameterDefault type
R extends Result<unknown>-
OInferResultType<R>
Parameters
ParameterType
cb(input: I) => R
options?ValidatorOptions
Returns

BaseValidator<O>

Inherited from

BaseValidator.reshape


run()

run(value: unknown): Result<I, BaseError>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:102

Parameters

ParameterType
valueunknown

Returns

Result<I, BaseError>

Inherited from

BaseValidator.run


set()

set(options: ValidatorOptions): SetValidator<I>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:48

Parameters

ParameterType
optionsValidatorOptions

Returns

SetValidator<I>

Inherited from

BaseValidator.set


setParent()

setParent(parent: object): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:27

Parameters

ParameterType
parentobject

Returns

this

Inherited from

BaseValidator.setParent


setValidationEnabled()

setValidationEnabled(isValidationEnabled: null | boolean | () => boolean): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:133

Sets if the validator should also run constraints or just do basic checks.

Parameters

ParameterTypeDescription
isValidationEnablednull | boolean | () => booleanWhether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing. Set to null to go off of the global configuration.

Returns

this

Inherited from

BaseValidator.setValidationEnabled


strict()

strict(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/ObjectValidator.ts:85

Parameters

ParameterType
optionsValidatorOptions

Returns

this


transform()

Call Signature

transform(cb: (value: I) => I, options?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:56

Parameters
ParameterType
cb(value: I) => I
options?ValidatorOptions
Returns

this

Inherited from

BaseValidator.transform

Call Signature

transform<O>(cb: (value: I) => O, options?: ValidatorOptions): BaseValidator<O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:57

Type Parameters
Type Parameter
O
Parameters
ParameterType
cb(value: I) => O
options?ValidatorOptions
Returns

BaseValidator<O>

Inherited from

BaseValidator.transform


when()

when<Key, This>(key: Key, options: WhenOptions<This, Key>, validatorOptions?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:88

Type Parameters

Type ParameterDefault type
Key extends WhenKey-
This extends BaseValidator<any>ObjectValidator<T, I>

Parameters

ParameterType
keyKey
optionsWhenOptions<This, Key>
validatorOptions?ValidatorOptions

Returns

this

Inherited from

BaseValidator.when