@samatawy/rules
    Preparing search index...

    Class AbstractRuleAbstract

    Abstract base class for all rules in the system, providing common properties and methods for evaluating and executing rules. Each specific rule type (e.g. conditional rules, assignment rules) should extend this class and implement the abstract methods for evaluation and execution.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    name?: string

    Optional name for the rule, which can be used for identification and debugging purposes.

    hint?: string

    An optional hint or description for the rule, which can provide additional information about its purpose or usage. This is primarily for documentation and user guidance when working with the rule.

    changeTargets: Record<string, AtomicType | ArrayType | ObjectType>
    compiled_eval?: Function

    Methods

    • Get the original syntax string from which this rule was created. This can be useful for debugging and error reporting, as it allows you to see the exact rule definition that led to a particular rule instance.

      Returns string

      the original syntax string of the rule.

    • Get the salience (priority) of the rule, which determines the order in which rules are evaluated and executed when multiple rules are applicable. Higher salience means higher priority. If salience is not set, it defaults to 0.

      Returns number

      the salience (priority) of the rule where 0 is default and 10 is the highest.

    • Set the salience (priority) of the rule, which determines the order in which rules are evaluated and executed when multiple rules are applicable. Higher salience means higher priority. If salience is not set, it defaults to 0.

      Parameters

      • salience: number

        the salience (priority) of the rule where 0 is default and 10 is the highest.

      Returns void

    • Check whether the rule is currently disabled. A disabled rule will not be evaluated or executed by the engine.

      Returns boolean

      true if the rule is disabled, false otherwise.

    • Disable the rule, preventing it from being evaluated or executed by the engine. This can be useful for temporarily turning off rules without removing them from the system, such as during testing. Optionally, a reason can be provided for why the rule is being disabled, which will be included in the hint if no hint is already set for the rule.

      Parameters

      • Optionalreason: string

        a hint or reason for why the rule is being disabled.

      Returns void

    • Enable the rule, allowing it to be evaluated and executed by the engine if it is applicable. This can be used to re-enable a rule that was previously disabled.

      Returns void

    • What data keys are required for this rule to be applicable? This is determined by the specific implementation of the rule and should be set during the construction of the instance. The rule engine uses this information to determine which rules are applicable based on the current context.

      Returns Set<string>

      a set of data keys required for this rule to be applicable.

    • Whether this rule is applicable in the given context, based on whether all of its required data keys are present in the context.

      Parameters

      • context: WorkingContext

        the current working context containing data and constants.

      Returns boolean

      true if the rule is applicable, false otherwise.