@samatawy/rules
    Preparing search index...

    Class ScopeTypeChecker

    An implementation of TypeChecker used within a scope context. It holds the data types of custom function arguments for internal type checking. You should not need to use this class directly.

    Implements

    Index

    Constructors

    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.

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

      Parameters

      • target: any

        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

      • input: any

      Returns any

      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