Fake Mirrors
    Preparing search index...

    Interface Validator

    Defines the public contract for a validator.

    Provides type-safe methods for guarding and asserting data structures against registered JSON Schemas.

    interface Validator {
        addSchema(name: string, schema: object): this;
        assertSchema<T>(name: string, data: unknown): asserts data is T;
        guardSchema<T>(name: string, data: unknown): data is T;
    }

    Implemented by

    • Registers a JSON Schema with a unique name.

      The schema will be compiled and cached for later validation.

      Parameters

      • name: string

        The unique identifier for the schema.

      • schema: object

        The JSON Schema object.

      Returns this

      This validator for method chaining.

      Error If a schema with the given name is already registered.

    • Validates data against a JSON Schema, acting as a type assertion.

      On failure, it throws a detailed validation error.

      Type Parameters

      • T

        The expected type after validation.

      Parameters

      • name: string

        The name of the schema to validate against.

      • data: unknown

        The data to be validated.

      Returns asserts data is T

      ValidatorError If validation fails, containing detailed error information.

    • Validates data against a JSON Schema, acting as a type guard.

      On success, it narrows the type of the data to the specified type T.

      Type Parameters

      • T

        The expected type after validation.

      Parameters

      • name: string

        The name of the schema to validate against.

      • data: unknown

        The data to be validated.

      Returns data is T

      true if the data is valid, false otherwise.