Interface RecordSchema<KeyT, ValueT>

Requires a non-null, non-array object where all keys share a schema and all values share a schema

interface RecordSchema<KeyT extends string, ValueT> {
    allowNull: () => Schema<null | Partial<Record<KeyT, ValueT>>>;
    allowUnknownKeys: boolean;
    clone: () => RecordSchema<KeyT, ValueT>;
    cloneValueAsync: AsyncCloner<Partial<Record<KeyT, ValueT>>>;
    description?: string;
    deserializeAsync: AsyncDeserializer<Partial<Record<KeyT, ValueT>>>;
    estimatedValidationTimeComplexity: number;
    example?: string;
    isContainerType: boolean;
    isOrContainsObjectPotentiallyNeedingUnknownKeyRemoval: boolean;
    isYaSchema: true;
    keys: RegExp | Schema<KeyT>;
    not: <ExcludeT>(
        notSchema: Schema<ExcludeT>,
        options?: { expectedTypeName?: string },
    ) => Schema<Exclude<Partial<Record<KeyT, ValueT>>, ExcludeT>>;
    optional: () => Schema<undefined | Partial<Record<KeyT, ValueT>>>;
    preferredValidationMode: SchemaPreferredValidationMode;
    schemaType: "record";
    serializeAsync: AsyncSerializer<Partial<Record<KeyT, ValueT>>>;
    setAllowUnknownKeys: (allow: boolean) => this;
    setDescription: (description?: string) => this;
    setExample: (example?: string) => this;
    setPreferredValidationMode: (
        validationMode: SchemaPreferredValidationMode,
    ) => this;
    toString: () => string;
    usesCustomSerDes: boolean;
    validateAsync: AsyncValidator;
    valueSchema: Schema<ValueT>;
    valueType: Partial;
}

Type Parameters

  • KeyT extends string
  • ValueT

Hierarchy (View Summary)

Properties

allowNull: () => Schema<null | Partial<Record<KeyT, ValueT>>>

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

allowUnknownKeys: boolean

If true, extra keys won't be removed. This effects the directly described value but not sub-values.

clone: () => RecordSchema<KeyT, ValueT>
cloneValueAsync: AsyncCloner<Partial<Record<KeyT, ValueT>>>

Deeply clones a value

description?: string

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

deserializeAsync: AsyncDeserializer<Partial<Record<KeyT, ValueT>>>

Deserialize (and validate) a value

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

keys: RegExp | Schema<KeyT>
not: <ExcludeT>(
    notSchema: Schema<ExcludeT>,
    options?: { expectedTypeName?: string },
) => Schema<Exclude<Partial<Record<KeyT, ValueT>>, ExcludeT>>

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

optional: () => Schema<undefined | Partial<Record<KeyT, ValueT>>>

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: "record"

The type of schema

serializeAsync: AsyncSerializer<Partial<Record<KeyT, ValueT>>>

Serialize (and validate) a value

setAllowUnknownKeys: (allow: boolean) => this
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

valueSchema: Schema<ValueT>
valueType: Partial

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