UNPKG

rulepilot

Version:

Rule parsing engine for JSON rules

46 lines (45 loc) 2.33 kB
import { Rule, Constraint, IntrospectionResult } from "../types"; /** * Introspection deals with the process of examining the constraints and conditions of a rule to determine all the * possible range of input criteria which would satisfy the rule along with the result of the rule that would be * produced by the criteria. */ export declare class Introspector { #private; /** * Returns the number of outcomes that a rule has. * @param rule The rule to check. */ numOutcomes(rule: Rule): number; /** * Given a rule, checks the constraints and conditions to determine the possible range of input criteria which would be * satisfied by the rule. * @param rule The rule to introspect. * @param criteria The criteria to introspect against. * @param subjects The subjects to introspect for. */ introspect<R>(rule: Rule, criteria: Omit<Constraint, "operator">[], subjects: string[]): IntrospectionResult<R>[]; /** * Given a list of valid candidates and the input used in the introspection, this method * tests a new constraint (item) returning true if the item is self-consistent with the * candidates and the input. * * Testing happens by considering each item in the list as linked by an AND * @param candidates The result candidates to test against. * @param criteria The constraint which was input to the introspection. * @param item The constraint item to test against the candidates. * @param depth The current recursion depth. */ protected test(candidates: Constraint[], criteria: Omit<Constraint, "operator">[], item: Constraint, depth: number): boolean; /** * Takes a list of constraints which represent the possible values for a field which satisfy a rule * and sanitizes the list to remove any constraints which are redundant. This method will convert the * list of constraints to the smallest possible list of constraints which still represent the same * possible values for the field. * * Sanitization happens by considering each item in the list as linked by an OR * @param constraints The constraints to sanitize. * @param depth The current recursion depth. */ protected sanitize(constraints: Constraint[], depth: number): Constraint[]; }