rulepilot
Version:
Rule parsing engine for JSON rules
37 lines (36 loc) • 1.42 kB
TypeScript
import { Validator } from "../services";
import { Rule, Operator, Condition, Constraint, ConditionType } from "../types";
export declare class Builder {
#private;
constructor(validator: Validator);
/**
* Adds a node (in the root) to the rule being constructed
* @param node The node to add to the rule
*/
add(node: Condition): Builder;
/**
* Creates a new condition node
* @param type The type of condition
* @param nodes Any child nodes of the condition
* @param result The result of the condition node (for granular rules)
*/
condition(type: ConditionType, nodes: Condition[ConditionType], result?: Condition["result"]): Condition;
/**
* Creates a new constraint node
* @param field The field to apply the constraint to
* @param operator The operator to apply to the field
* @param value The value to compare the field to
*/
constraint(field: string, operator: Operator, value: Constraint["value"]): Constraint;
/**
* Sets the default value of the rule being constructed
* @param value The default value of the rule
*/
default(value: Rule["default"]): Builder;
/**
* Builds the rule being and returns it
* @param validate Whether to validate the rule before returning it
* @throws Error if validation is enabled and the rule is invalid
*/
build(validate?: boolean): Rule;
}