@samatawy/rules
    Preparing search index...

    Interface TypeChecker

    interface TypeChecker {
        hasType(key: string): boolean;
        getType(key: string): PropertyType | undefined;
        checkTypes(target: HasValidity): ValidationResult;
        checkData(target: any): ValidationResult;
        coerceData(input: any): any;
        strictSyntax(): boolean;
        strictInputs(): boolean;
        strictOutputs(): boolean;
    }

    Implemented by

    Index

    Methods

    • Check if the type checker knows the type of the given key. Nested keys can be checked using dot notation (e.g., "user.name").

      Parameters

      • key: string

        the key to check.

      Returns boolean

      true if the type is known, false otherwise.

    • Get the type of the given key from the type checker. Nested keys can be accessed using dot notation (e.g., "user.name").

      Parameters

      • key: string

        the key to look up in the type checker.

      Returns PropertyType | undefined

      the type associated with the key, or undefined if the type is not known.

    • Perform type checking on the given target, which can be a rule, expression, or any other component that requires type validation.

      Parameters

      • target: HasValidity

        the target to check types for, which must implement the HasValidity interface.

      Returns ValidationResult

      the result of the type check, indicating whether the target is valid and any errors if it is not.

    • Perform type checking on the given data, which can be any json object or array. Can be used to validate input to a context (e.g. from an HTTP request body).

      Parameters

      • target: any

        the target to check types for.

      Returns ValidationResult

      the result of the type check, indicating whether the target is valid and any errors if it is not.

    • Coerce input data into types acceptable to the known types (as far as possible). Input data can only be a json object but can contain arrays. Can be used to coerce input to a context (e.g. from an HTTP request body). N.B. Unknown keys (i.e. wihout registyered type definitions) will be passed on without coercion. N.B. Recommended to use ONLY after validating input.

      Parameters

      • input: any

        the input data to coerce.

      Returns any

      a deep clone of the input data, with values mutated as necessary to suite declared types.

    • Indicates whether the type checker should enforce strict syntax validation. When true, the type checker will validate that all rules and expressions conform to expected syntax, potentially throwing errors if syntax is invalid. This can be used to catch issues early in development.

      Returns boolean

    • Indicates whether the type checker should enforce strict input validation. When true, the type checker will validate that all required input data for rules and expressions are defined and conform to expected types, potentially throwing errors if inputs are missing or incorrectly typed.

      Returns boolean

    • Indicates whether the type checker should enforce strict output validation. When true, the type checker will validate that all output data for rules and expressions are defined and conform to expected types, potentially throwing errors if outputs are missing or incorrectly typed.

      Returns boolean