Skip to main content

Class: ObjectValidator<T, I>

Extends

Type parameters

Type parameterValue
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>

Parameters

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

Returns

ObjectValidator<T, I>

Overrides

BaseValidator . constructor

Source

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

Properties

constraints

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

Inherited from

BaseValidator . constraints

Source

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


description?

optional description: string

Inherited from

BaseValidator . description

Source

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


handleStrategy()

private readonly handleStrategy: (value: object) => Result<I, CombinedPropertyError>

Parameters

ParameterType
valueobject

Returns

Result<I, CombinedPropertyError>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:19


isValidationEnabled

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

Inherited from

BaseValidator . isValidationEnabled

Source

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


keys

private readonly keys: readonly keyof I[] = []

Source

projects/shapeshift/src/validators/ObjectValidator.ts:18


parent?

protected optional parent: object

Inherited from

BaseValidator . parent

Source

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


possiblyUndefinedKeys

private readonly possiblyUndefinedKeys: Map<keyof I, BaseValidator<unknown>>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:22


possiblyUndefinedKeysWithDefaults

private readonly possiblyUndefinedKeysWithDefaults: Map<keyof I, DefaultValidator<unknown>>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:23


requiredKeys

private readonly requiredKeys: Map<keyof I, BaseValidator<unknown>>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:21


shape

readonly shape: MappedObjectValidator<T>

Source

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


strategy

readonly strategy: ObjectValidatorStrategy

Source

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


validatorOptions

protected validatorOptions: ValidatorOptions

Inherited from

BaseValidator . validatorOptions

Source

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

Accessors

shouldRunConstraints

get protected shouldRunConstraints(): boolean

Returns

boolean

Source

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

Methods

addConstraint()

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

Parameters

ParameterType
constraintIConstraint<I, I>
validatorOptionsValidatorOptions

Returns

this

Inherited from

BaseValidator . addConstraint

Source

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


array()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

ArrayValidator<I[], I>

Inherited from

BaseValidator . array

Source

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


clone()

protected clone(): this

Returns

this

Overrides

BaseValidator . clone

Source

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


default()

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

Parameters

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

Returns

DefaultValidator <Exclude<I, undefined>>

Inherited from

BaseValidator . default

Source

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


describe()

describe(description: string): this

Parameters

ParameterType
descriptionstring

Returns

this

Inherited from

BaseValidator . describe

Source

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


extend()

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

Type parameters

Type parameter
ET extends object

Parameters

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

Returns

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

Source

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


getValidationEnabled()

getValidationEnabled(): null | boolean

Returns

null | boolean

Inherited from

BaseValidator . getValidationEnabled

Source

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


handle()

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

Parameters

ParameterType
valueunknown

Returns

Result<I, ValidationError | CombinedPropertyError>

Overrides

BaseValidator . handle

Source

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


handleIgnoreStrategy()

private handleIgnoreStrategy(value: object): Result<I, CombinedPropertyError>

Parameters

ParameterType
valueobject

Returns

Result<I, CombinedPropertyError>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:176


handlePassthroughStrategy()

private handlePassthroughStrategy(value: object): Result<I, CombinedPropertyError>

Parameters

ParameterType
valueobject

Returns

Result<I, CombinedPropertyError>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:291


handleStrictStrategy()

private handleStrictStrategy(value: object): Result<I, CombinedPropertyError>

Parameters

ParameterType
valueobject

Returns

Result<I, CombinedPropertyError>

Source

projects/shapeshift/src/validators/ObjectValidator.ts:238


ignore()

ignore(options: ValidatorOptions): this

Parameters

ParameterType
optionsValidatorOptions

Returns

this

Source

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


is()

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

Type parameters

Type parameterValue
RI

Parameters

ParameterType
valueunknown

Returns

value is R

Inherited from

BaseValidator . is

Source

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


nullable()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<null | I>

Inherited from

BaseValidator . nullable

Source

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


nullish()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | null | I>

Inherited from

BaseValidator . nullish

Source

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


omit()

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

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] }>>

Source

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


optional()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | I>

Inherited from

BaseValidator . optional

Source

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


or()

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

Type parameters

Type parameter
O

Parameters

ParameterType
...predicatesreadonly BaseValidator<O>[]

Returns

UnionValidator<I | O>

Inherited from

BaseValidator . or

Source

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


parse()

parse<R>(value: unknown): R

Type parameters

Type parameterValue
RI

Parameters

ParameterType
valueunknown

Returns

R

Inherited from

BaseValidator . parse

Source

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


partial()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

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

Source

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


passthrough()

passthrough(options: ValidatorOptions): this

Parameters

ParameterType
optionsValidatorOptions

Returns

this

Source

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


pick()

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

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] }>>

Source

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


required()

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

Parameters

ParameterType
optionsValidatorOptions

Returns

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

Source

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


reshape()

reshape(cb, options)

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

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

this

Inherited from

BaseValidator . reshape

Source

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

reshape(cb, options)

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

Type parameters
Type parameterValue
R extends Result<unknown, Error>-
OInferResultType<R>
Parameters
ParameterType
cb(input: I) => R
options?ValidatorOptions
Returns

BaseValidator<O>

Inherited from

BaseValidator . reshape

Source

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


run()

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

Parameters

ParameterType
valueunknown

Returns

Result<I, BaseError>

Inherited from

BaseValidator . run

Source

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


set()

set(options: ValidatorOptions): SetValidator<I>

Parameters

ParameterType
optionsValidatorOptions

Returns

SetValidator<I>

Inherited from

BaseValidator . set

Source

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


setParent()

setParent(parent: object): this

Parameters

ParameterType
parentobject

Returns

this

Inherited from

BaseValidator . setParent

Source

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


setValidationEnabled()

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

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

Source

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


strict()

strict(options: ValidatorOptions): this

Parameters

ParameterType
optionsValidatorOptions

Returns

this

Source

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


transform()

transform(cb, options)

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

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

this

Inherited from

BaseValidator . transform

Source

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

transform(cb, options)

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

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

BaseValidator<O>

Inherited from

BaseValidator . transform

Source

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


when()

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

Type parameters

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

Parameters

ParameterType
keyKey
optionsWhenOptions<This, Key>
validatorOptions?ValidatorOptions

Returns

this

Inherited from

BaseValidator . when

Source

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