Skip to main content

@react-querybuilder/rules-engine

Components

NameDescription
ActionElementRE-
ConditionBuilderDefault condition editor for RulesEngineBuilder. Analogous to an "if" or "else-if" block.
ConditionBuilderBodyDefault body component for ConditionBuilder.
ConditionCascadeRenders a sequential list of if/else-if/else blocks in a rules engine.
ConsequentBuilderDefault consequent editor for RulesEngineBuilder. Analogous to the body of an "if" or "else-if" block.
ConsequentBuilderBodyDefault body component for ConsequentBuilder.
ConsequentBuilderHeaderDefault header component for ConsequentBuilder.
RulesEngineBuilderHeaderDefault header component for RulesEngineBuilder.
ShiftActionsRE-
ValueSelectorRE-
RulesEngineBuilderThe rules engine builder component for React.

Props

NameDescription
ActionElementREProps-
ClassnamesREClassnames applied to each component.
ComponentsREAll subcomponents.
ConditionCascadePropsProps for ConditionCascade.
ConditionPropsProps for ConditionBuilder.
ConsequentPropsProps for ConsequentBuilder, ConsequentBuilderHeader, and ConsequentBuilderBody.
RulesEngineBuilderHeaderPropsProps for RulesEngineBuilderHeader.
RulesEnginePropsProps for RulesEngineBuilder.
SchemaREConfiguration options passed in the schema prop from RulesEngineBuilder to each subcomponent.
ShiftActionsREProps-
TranslationsREThe shape of the translations prop for RulesEngineBuilder.
ValueSelectorREProps-
TranslationsFullREThe full translations interface for RulesEngineBuilder, with all properties required.

Export

NameDescription
FormatRulesEngineOptionsOptions object shape for formatRulesEngine.
EvaluationModeDetermines how sibling conditions in a react-querybuilder!RulesEngine RulesEngine relate to one another when exported.
NativePredicateA compiled antecedent for the "native"/"node-rules" export targets: returns true when the supplied facts satisfy the rule group it was compiled from.
RulesEngineEvaluatorIn-process evaluator returned by formatRulesEngine(re, 'native'). Given a facts object, returns the react-querybuilder!Consequent consequents of every condition that fires, in order, honoring the react-querybuilder!RulesEngine.evaluationMode evaluationMode.
RulesEngineExportFormatAvailable export formats for formatRulesEngine.
RulesEngineProcessorFunction to produce a result that formatRulesEngine uses when processing a react-querybuilder!RulesEngine RulesEngine or react-querybuilder!RulesEngineIC RulesEngineIC object.
defaultRuleGroupProcessorNativeDefault rule group processor for the "native" export format. Compiles a rule group into a NativePredicate that ANDs ("and") or ORs ("or") its child predicates and negates the result when not is set. Invalid/placeholder rules are filtered out exactly as in the other export targets; an empty (or invalid outermost) group compiles to an always-true predicate.
defaultRuleGroupProcessorRulePilotDefault rule group processor for the "rulepilot" export format. Compiles a rule group into a rulepilot Condition: and{ all }, or{ any }, and a negated group (not) is wrapped in { none: [...] } (rulepilot has no not). Invalid/placeholder rules—and rules whose operator rulepilot cannot represent (the rule processor returns null for those)—are filtered out exactly as in the other export targets. An empty nested group is dropped; an empty outermost group compiles to an always-true { all: [] }.
defaultRuleProcessorNativeDefault rule processor for the "native" export format. Compiles a single rule into a NativePredicate that evaluates the rule's operator (via nativeOperators) against the fact identified by the rule's field. Unknown operators evaluate to false.
defaultRuleProcessorRulePilotDefault rule processor for the "rulepilot" export format. Compiles a single React Query Builder rule into a rulepilot Constraint (or a small Condition for range/null checks).
defaultRulesEngineProcessorJsonRulesEngineDefault processor for the json-rules-engine export format.
defaultRulesEngineProcessorNativeDefault processor for the "native" export format. Returns an in-process RulesEngineEvaluator: a function that, given a facts object, returns the consequents of every condition that fires—in order, honoring the evaluationMode. Antecedents are compiled to predicates with no runtime dependencies.
defaultRulesEngineProcessorNodeRulesDefault processor for the "node-rules" export format. Returns an array of live node-rules Rule objects with real condition/consequence functions—ready to pass to new RuleEngine(...) or register(...). Antecedents are compiled to predicates (shared with the "native" target) so evaluation needs no operator registration. Each fired condition's consequent is pushed onto fact.events (mirroring the json-rules-engine result shape).
defaultRulesEngineProcessorRulePilotDefault processor for the "rulepilot" export format. Returns a single rulepilot Rule whose ordered conditions reproduce the rules engine's cascade: each condition pairs a guard (its own antecedent AND-ed with its ancestor antecedents and the negated antecedents of prior siblings) with result: consequent.
jsonRulesEngineAdditionalOperatorsOperator evaluators for the React Query Builder operators that have no json-rules-engine built-in equivalent. Register these on an Engine so that rules exported by formatRulesEngine which use these operators can be evaluated—either manually via engine.addOperator(...), or automatically by passing the engine as context.engine to formatRulesEngine.
nativeOperatorsEvaluators for every React Query Builder default operator, comparing a fact value against the value stored on a rule. Used by the "native" and "node-rules" export targets to evaluate antecedents in process. Unknown operators evaluate to false.
rulePilotUnsupportedOperatorsReact Query Builder substring operators that the "rulepilot" export format cannot represent. rulepilot's only string-matching operator, matches, builds the regular expression from the runtime fact and tests it against the rule value (new RegExp(fact).test(value))—the inverse of what these operators require—so there is no faithful mapping. Rules using these operators are skipped (treated as invalid) during export; see defaultRuleGroupProcessorRulePilot.
formatRulesEngine-
walkRulesEngineFlattens a react-querybuilder!RulesEngine RulesEngine into an ordered list of guard/consequent pairs, reproducing the if/else-if/else ("cascade") or independent ("cumulative") semantics shared by the runnable export targets.

Defaults

VariableDescription
defaultClassnamesREDefault classnames used by RulesEngineBuilder.
defaultComponentsREDefault components used by RulesEngineBuilder.
defaultTranslationsREDefault configuration of translatable strings for RulesEngineBuilder.
standardClassnamesREStandard classnames applied by RulesEngineBuilder.

Functions

FunctionDescription
findConditionIDReturns the RuleGroupType/RuleGroupTypeIC with the given id within a rules engine.
findConditionPathReturns the RuleGroupType/RuleGroupTypeIC at the given path within a rules engine.
getConditionPathOfIDReturns the Path of the RuleGroupType/RuleGroupTypeIC with the given id within a rules engine.
getFactValueLooks up path in a fact object. An exact key match wins (so flat keys that literally contain dots still work); otherwise the path is traversed segment-by-segment ("profile.age").
inRangeDetermines whether factVal falls within the inclusive range described by compareVal, mirroring the robustness of the "between" handling in formatQuery. The bounds may be supplied as an array ([lo, hi]) or a comma-separated string ("lo,hi"). Numeric bounds are parsed and reordered ascending; non-numeric bounds compare lexicographically in the order given. Returns null when fewer than two valid bounds are present.
isRulesEngineDetermines if an object is a RulesEngine.
isRulesEngineAnyDetermines if an object is a RulesEngine or RulesEngineIC.
isRulesEngineConditionDetermines if an object is a RulesEngineAntecedent.
isRulesEngineConditionAnyDetermines if an object is a RulesEngineAntecedent or REConditionIC.
isRulesEngineConditionICDetermines if an object is a REConditionIC.
isRulesEngineConsequentDetermines if an object is a RulesEngine or RulesEngineIC.
isRulesEngineICDetermines if an object is a RulesEngineIC.
mergeClassnamesREMerges a list of partial ClassnamesRE definitions into a single definition.
prepareRulesEngineEnsures that a rule group is valid by recursively adding an id property to the group itself and all its rules and subgroups where one does not already exist.
prepareRulesEngineCondition-
regenerateREIDsRecursively generates new id properties for a rule group or rules engine and all its rules/conditions and subgroups/subconditions.

Interfaces

InterfaceDescription
AddMethodRE-
FlatRuleA flattened rules-engine condition: a single combined guard paired with its consequent.
InsertMethodRE-
MoveMethodRE-
PreparerOptionsREOptions for prepareRulesEngine.
REConditionA condition within a RulesEngine. Each condition has an antecedent (rule group) and an optional consequent. A condition may also itself contain nested conditions.
REConditionICA condition within a RulesEngine. Each condition has an antecedent (rule group) and an optional consequent. A condition may also itself contain nested conditions.
RemoveMethodRE-
RulesEngineRules engine with standard query objects (RuleGroupType). Contains an array of conditions, each with an antecedent (rule group) and an optional consequent. An optional defaultConsequent can be specified that will be used if none of the conditions are met.
RulesEngineICRules engine with "independent combinator" query objects RuleGroupTypeIC). Contains an array of conditions, each with an antecedent (rule group) and an optional consequent. An optional defaultConsequent can be specified that will be used if none of the conditions are met.
UpdateMethodRE-
WalkPrimitivesPrimitives that adapt walkRulesEngine to a particular guard representation G (e.g. a json-rules-engine TopLevelCondition, or a NativePredicate function).

Type Aliases

Type AliasDescription
FindConditionPathReturn type for findConditionPath.
REConditionAnyEither RECondition or REConditionIC.
REConditionCascadeArray of conditions within a RulesEngine or RulesEngineIC.
RulesEngineAnyEither RulesEngine or RulesEngineIC.

Variables

VariableDescription
ConditionBuilderHeaderDefault header component for ConditionBuilder.
defaultRuleGroupProcessorJsonRulesEngine-
defaultRuleProcessorJsonRulesEngine-
defaultRulesEngine-
defaultRulesEngineIC-

Rules Engine

NameDescription
Consequent-
ConsequentPropertyDefDefinition of a single editable property of a consequent type. Used by the built-in ConsequentBuilderBody to render an appropriate input for each property. Property values are stored on the consequent under params[name].
ConsequentBase-
ConsequentPropertyInputTypeSupported input types for a built-in consequent property editor.
ConsequentTypeOptionA consequent type option that may carry editable property definitions. Pass an array of these as the consequentTypes prop (or from getConsequentTypes) to enable the built-in property editor. Only name (the identifier stored as the consequent's type) and label are required; see FullConsequentTypeOption for the resolved form used internally.
FullConsequentTypeOptionA ConsequentTypeOption resolved to a FullOption (both name and value guaranteed). This is the form passed to subcomponents via the schema.

Rules Engine Tools

NameDescription
AddOptionsREOptions for addRE.
InsertOptionsREOptions for insertRE.
MoveOptionsREOptions for moveRE.
UpdateOptionsREOptions for updateRE.
addREAdds a rule or group to a query without mutating the original rules engine.
addREInPlaceAdds a rule or group to a query by mutating the rules engine.
insertREInserts a rule engine condition into a rules engine without mutating the original rules engine.
insertREInPlaceInserts a rule engine condition into a rules engine by mutating the rules engine.
moveREMoves a rule engine condition from one path to another without mutating the original rules engine. In the options parameter, pass { clone: true } to copy instead of move.
moveREInPlaceMoves a rule engine condition from one path to another by mutating the rules engine. In the options parameter, pass { clone: true } to copy instead of move.
removeRERemoves a rule engine condition from a rules engine without mutating the original rules engine.
removeREInPlaceRemoves a rule engine condition from a rules engine by mutating the rules engine.
updateREUpdates a property of a rule or group within a query without mutating the original rules engine.
updateREInPlaceUpdates a property of a rule or group within a query by mutating the rules engine.

caution

API documentation is generated from the latest commit on the main branch. It may be somewhat inconsistent with official releases of React Query Builder.