Class SchemaBuilder<TResult, TRequired>Abstract

Base class for all schema builders. Provides basic functionality for schema building.

Note: this class is not intended to be used directly, use one of the subclasses instead.

Typeparam

TResult Type of the object that will be returned by validate() method.

Typeparam

TRequired If true, object will be required. If false, object will be optional.

Type Parameters

  • TResult = any

  • TRequired extends boolean = true

Hierarchy

Constructors

Accessors

  • get preprocessors(): Preprocessor<TResult>[]
  • A list of preprocessors associated with the Builder

    Returns Preprocessor<TResult>[]

  • get validators(): Validator<TResult>[]
  • A list of validators associated with the Builder

    Returns Validator<TResult>[]

Methods

  • Clears type set by call to .hasType<T>(), default schema type inference will be used for schema retuned by this call.

    Returns any

  • Protected method used to create an new instance of the Builder defined by the props object. Should be used to instanticate new builders to keep builder's immutability.

    Parameters

    • props: any

      arbitrary props object

    Returns SchemaBuilder<TResult, TRequired>

  • Set type of schema explicitly. notUsed param is needed only for cas when JS is used. E.g. when you can't call method like schema.hasType<Date>(), so instead you can call schema.hasType(new Date()) with the same result.

    Type Parameters

    • T

    Parameters

    • Optional notUsed: T

    Returns any

  • Generates a serializable object describing the defined schema

    Returns {
        isRequired: boolean;
        preprocessors: readonly Preprocessor<TResult>[];
        type: string;
        validators: readonly Validator<TResult>[];
    }

    • isRequired: boolean

      If set to false, schema will be optional (null or undefined values will be considered as valid).

    • preprocessors: readonly Preprocessor<TResult>[]

      Array of preprocessor functions

    • type: string

      String id of schema type, e.g. string', numberorobject`.

    • validators: readonly Validator<TResult>[]

      Array of validator functions

  • Makes schema optional (consider null and undefined as valid objects for this schema)

    Returns any

  • Parameters

    • object: any

      Object to validate

    • Optional context: ValidationContext

    Returns Promise<PreValidationResult<any, {
        validatedObject: any;
    }>>

  • Makes schema required (consider null and undefined as invalid objects for this schema)

    Returns any

Generated using TypeDoc