Chainable object validators for the Record type.

Type Parameters

Hierarchy (view full)

Constructors

Properties

__type: Invariant<T> = ...

Enforces T is in an invariant position. This prevents a validator with more strict rules is assigned to a less strict type, which can cause unexpected validation errors.

currentValidator: Validator<any, any>
operation?: ((validatorA: Validator<any, unknown>, validatorB: Validator<any, any>) => Validator<T, unknown>)
previousSchema?: SchemaBase<any>
base: RecordSchema<Record<string | number | symbol, unknown>> = ...

Accessors

  • get description(): string
  • A short description of the validator.

    Returns string

Methods

  • Returns a validator that asserts if this validator and the next passes.

    Type Parameters

    • U

    Parameters

    • nextValidator: Validator<U, any>

      The validator to run after the current.

    Returns ValueSchema<T & U>

    Returns a new ValueSchema intersecting this validator and the next.

    andValidators

  • Validates the given input, asserting that the input is type T. If the input is not valid, a ValidationError will be thrown.

    Parameters

    • input: unknown

      The input to validate.

    • Optionalorigin: string

      The error origin. ErrorOrigin.API by default.

    • Optionalpath: readonly string[]

      The current field path to this validator.

    Returns asserts input is T

    Returns the input, cast as the validated type T

  • Constructs a new schema with a validator chaining the current validator with the provided next in an AND operation.

    Parameters

    • nextValidator: Validator<any, any>

      The validator to run after the current.

    Returns any

    Returns a new Schema instance the same class with a new validator chaining the current validator with the given next in an AND operation.

  • Clones this schema, transforming all validators with the given mutator.

    Parameters

    • transform: ((validator: Validator<any, unknown>) => Validator<any, unknown>)

      A transformer which takes an existing validator in the chain and returns a new one. Validators should be considered to be immutable; transform should not change the input but instead return a new validator.

    Returns any

  • Returns true if the input is valid according to this validator.

    Parameters

    • input: unknown

    Returns input is T

  • Prepends this validator allowing for null or undefined.

    Returns ValueSchema<undefined | null | T>

  • Returns a validator that asserts if this validator or the next passes.

    Implementation note: subclasses should not change the schema instance returned unless all chainable validators accept input type 'unknown'.

    Type Parameters

    • U

    Parameters

    • nextValidator: Validator<U, any>

      The validator to run after the current.

    Returns ValueSchema<T | U>

    Returns a new ValueSchema providing the union of this validator and the next.

  • Returns a validator that asserts that the object's own enumerable properties has keys and values that match their respective validators.

    Prototype members are not included. Numeric keys are validated as strings. For example the object { [0]: 1 } will be passed to the key validator as '0'.

    Type Parameters

    • K extends string | symbol
    • V

    Parameters

    • keyValidator: Validator<K, unknown>

      Validates each key.

    • valueValidator: Validator<V, unknown>

      Validates each value.

    Returns RecordSchema<ReadonlyRecord<K, V>>

  • Returns a validator that asserts that the object's own enumerable properties has string keys and values that match the given validator.

    Prototype members are not included.

    Type Parameters

    • V

    Parameters

    • valueValidator: Validator<V, unknown>

      Validates each value.

    Returns RecordSchema<Record<string, V>>

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Validates the provided input, returning a list of error messages, or an empty array if the input passes this validator.

    Parameters

    • input: unknown

      The input to validate.

    • Optionaloptions: ValidationOptions

      Validation options.

    • Optionalpath: readonly string[]

      The current field path to this validator.

    Returns readonly ValidationErrorMessage[]

    Returns an array of validation failures. If options.all is not true, only the first error will be returned.