Libraries (v1.1.10)
    Preparing search index...

    Class DateSchemaBuilder<TResult, TRequired>

    Allows to create Date schema. It can be required or optional. It can be restricted to be: equal to a certain value, in future, in past, in a certain range. Supports parsing from JSON string and UNIX epoch (using preprocessors).

    NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use date() function instead.

    date

    Type Parameters

    • TResult = Date
    • TRequired extends boolean = true

    Hierarchy (View Summary)

    Index

    Accessors

    • get isRequired(): TRequired

      Whether the schema requires a non-null/non-undefined value.

      Returns TRequired

    • set isRequired(value: boolean): void

      Sets the requirement flag. Must be a boolean.

      Parameters

      • value: boolean

      Returns void

    • get preprocessors(): Preprocessor<TResult>[]

      A list of preprocessors associated with the Builder

      Returns Preprocessor<TResult>[]

    • get type(): string

      The string identifier of the schema type (e.g. 'string', 'number', 'object').

      Returns string

    • set type(value: string): void

      Sets the schema type identifier. Must be a non-empty string.

      Parameters

      • value: string

      Returns void

    • get validators(): Validator<TResult>[]

      A list of validators associated with the Builder

      Returns Validator<TResult>[]

    Methods

    • Ensures a ValidationErrorMessageProvider is valid. If provider is undefined, falls back to defaultValue. Function providers are bound to this for access to schema state.

      Parameters

      • provider: ValidationErrorMessageProvider<any> | undefined

        the provider to validate, or undefined

      • defaultValue: ValidationErrorMessageProvider<any>

        fallback provider when provider is not supplied

      Returns ValidationErrorMessageProvider<any>

      a valid ValidationErrorMessageProvider

    • Resolves a ValidationErrorMessageProvider to a string error message. Handles both string providers and function providers (sync or async).

      Parameters

      • provider: ValidationErrorMessageProvider<any>

        the error message provider (string or function)

      • seenValue: TResult

        the value that caused the validation error

      Returns Promise<string>

      the resolved error message string

    • Set type of schema explicitly. notUsed param is needed only for case 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 DateSchemaBuilder<T, true>

    • Generates a serializable object describing the defined schema

      Returns {
          ensureIsInFuture: boolean;
          ensureIsInFutureValidationErrorMessageProvider: ValidationErrorMessageProvider<
              DateSchemaBuilder<TResult, TRequired>,
          >;
          ensureIsInPast: boolean;
          ensureIsInPastValidationErrorMessageProvider: ValidationErrorMessageProvider<
              DateSchemaBuilder<TResult, TRequired>,
          >;
          equalsTo: Date | undefined;
          equalsToValidationErrorMessageProvider: ValidationErrorMessageProvider<
              DateSchemaBuilder<TResult, TRequired>,
          >;
          isRequired: boolean;
          max: Date | undefined;
          maxValidationErrorMessageProvider: ValidationErrorMessageProvider<
              DateSchemaBuilder<TResult, TRequired>,
          >;
          min: Date | undefined;
          minValidationErrorMessageProvider: ValidationErrorMessageProvider<
              DateSchemaBuilder<TResult, TRequired>,
          >;
          parseFromEpoch: boolean;
          parseFromJson: boolean;
          preprocessors: Preprocessor<TResult>[];
          requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<
              SchemaBuilder<any, any>,
          >;
          type: string;
          validators: Validator<TResult>[];
      }

      • ensureIsInFuture: boolean

        Make sure that date is in future. false by default.

      • ensureIsInFutureValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>

        Ensure in future validation error message provider. If not provided, default error message will be used.

      • ensureIsInPast: boolean

        Make sure that date is in past. false by default.

      • ensureIsInPastValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>

        Ensure in past validation error message provider. If not provided, default error message will be used.

      • equalsTo: Date | undefined

        If set, restrict date to be equal to a certain value.

      • equalsToValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>

        Equals to validation error message provider. If not provided, default error message will be used.

      • isRequired: boolean

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

      • max: Date | undefined

        Max valid value (if defined).

      • maxValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>

        Max value validation error message provider. If not provided, default error message will be used.

      • min: Date | undefined

        Min valid value (if defined).

      • minValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>

        Min value validation error message provider. If not provided, default error message will be used.

      • parseFromEpoch: boolean

        If set, schema will try to parse date from the UNIX epoch (number). false by default.

      • parseFromJson: boolean

        If set, schema will try to parse date from JSON string. false by default.

      • preprocessors: Preprocessor<TResult>[]

        Array of preprocessor functions

      • requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any>>

        Custom error message provider for the 'is required' validation error.

      • type: string

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

      • validators: Validator<TResult>[]

        Array of validator functions

    • Runs preprocessors, validators, and the required/optional check on object. Subclasses call this at the start of their validate() implementation to get a preprocessed value wrapped in a transaction, along with any early errors.

      Parameters

      • object: any

        the value to pre-validate

      • Optionalcontext: ValidationContext<SchemaBuilder<any, any>>

        optional validation context settings

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

      a PreValidationResult containing the preprocessed transaction, context, and any errors