Interface RestrictedNumberSchema

Requires a real, finite number, optionally matching one of the specified values or in one of the specified ranges and optionally being divisible by one of the specified divisors.

interface RestrictedNumberSchema {
    allowedSerializationForms?: ("string" | "number")[];
    allowedValuesAndRanges: (number | Range<number>)[];
    allowNull: () => Schema<null | number>;
    clone: () => RestrictedNumberSchema;
    cloneValueAsync: AsyncCloner<number>;
    description?: string;
    deserializeAsync: AsyncDeserializer<number>;
    divisibleBy: number[];
    estimatedValidationTimeComplexity: number;
    example?: string;
    isContainerType: boolean;
    isOrContainsObjectPotentiallyNeedingUnknownKeyRemoval: boolean;
    isYaSchema: true;
    not: <ExcludeT>(
        notSchema: Schema<ExcludeT>,
        options?: { expectedTypeName?: string },
    ) => Schema<Exclude<number, ExcludeT>>;
    optional: () => Schema<undefined | number>;
    preferredValidationMode: SchemaPreferredValidationMode;
    schemaType: "restrictedNumber";
    serializeAsync: AsyncSerializer<number>;
    setAllowedSerializationForms: (allowed?: ("string" | "number")[]) => this;
    setDescription: (description?: string) => this;
    setExample: (example?: string) => this;
    setPreferredValidationMode: (
        validationMode: SchemaPreferredValidationMode,
    ) => this;
    toString: () => string;
    usesCustomSerDes: boolean;
    validateAsync: AsyncValidator;
    valueType: number;
}

Hierarchy (View Summary)

  • Schema<number>
    • RestrictedNumberSchema

Properties

allowedSerializationForms?: ("string" | "number")[]

For serialization, the first type will be used. ['number'] is assumed if nothing is specified.

For deserialization, forms are tried in order.

allowedValuesAndRanges: (number | Range<number>)[]

If one or more values are specified, the value must be equal to one of the specified values or in one of the specified ranges

allowNull: () => Schema<null | number>

Returns a new schema that requires that either this schema is satisfied or that the value is null.

cloneValueAsync: AsyncCloner<number>

Deeply clones a value

description?: string

A description, which can be used by code generation tools to generate documentation

deserializeAsync: AsyncDeserializer<number>

Deserialize (and validate) a value

divisibleBy: number[]

If one or more values are specified, the value must be divisible by one of the specified options

estimatedValidationTimeComplexity: number

An estimate of the time complexity for validating this element, which should be on the same order of the number of items to be validated

example?: string

An example, which can be used by code generation tools to generate documentation

isContainerType: boolean

If true, "shallow" ancestor validation mode preferences won't be used when this schemas validation mode preference is "inherit", like other built-in container types

isOrContainsObjectPotentiallyNeedingUnknownKeyRemoval: boolean

If true, this schema or any sub-elements have the potential to represent an object value that might need unknown-key removal

isYaSchema: true

A marker that can be used for testing if this is a YaSchema schema

not: <ExcludeT>(
    notSchema: Schema<ExcludeT>,
    options?: { expectedTypeName?: string },
) => Schema<Exclude<number, ExcludeT>>

Returns a new schema that requires that this schema is satisfied but that the specified schema cannot be satisfied.

optional: () => Schema<undefined | number>

Returns a new schema that requires that either this schema is satisfied or that the value is undefined.

preferredValidationMode: SchemaPreferredValidationMode

The preferred validation mode for this schema.

The lesser level of the preferred validation mode, which will be applied recursively depending on the depth parameter / unless further re-specified, and the specified validation mode, will be used, where the order is none < soft < hard.

Special Values:

  • "initial" - use the initially specified validation mode for the current operation (ex. the validation field of the options parameter to deserialize).
  • "inherit" - use the closet applicable mode from an ancestor schema level.
schemaType: "restrictedNumber"

The type of schema

serializeAsync: AsyncSerializer<number>

Serialize (and validate) a value

setAllowedSerializationForms: (allowed?: ("string" | "number")[]) => this

Sets (replaces) the allowed serialization forms metadata for this schema and returns the same schema

setDescription: (description?: string) => this

Sets (replaces) the description metadata for this schema and returns the same schema

setExample: (example?: string) => this

Sets (replaces) the example metadata for this schema and returns the same schema

setPreferredValidationMode: (
    validationMode: SchemaPreferredValidationMode,
) => this

Sets (replaces) the preferred validation mode for this schema and returns the same schema.

The lesser level of the preferred validation mode, which will be applied recursively depending on the depth parameter / unless further re-specified, and the specified validation mode, will be used, where the order is none < soft < hard.

Type declaration

    • (validationMode: SchemaPreferredValidationMode): this
    • Parameters

      • validationMode: SchemaPreferredValidationMode

        The preferred validation mode for this schema Special Values:

        • "initial" - use the initially specified validation mode for the current operation (ex. the validation field of the options parameter to deserialize).
        • "inherit" - use the closet applicable mode from an ancestor schema level.

      Returns this

toString: () => string

Makes a string representation of this schema, mostly for debugging

usesCustomSerDes: boolean

If true, this schema or any sub-elements have a custom serializer-deserializer

validateAsync: AsyncValidator

Validate a value

valueType: number

The actual value of this field is always undefined, but this should be used for determining the value type represented by this schema, ex. typeof someSchema.valueType