Skip to main content

QueryManager<RG extends RuleGroupTypeAny = RuleGroupType, F extends FullField = FullField, O extends FullOperator = FullOperator, C extends FullCombinator = FullCombinator>

Defined in: packages/core/src/utils/QueryManager.ts:528

Stateful wrapper around the add/remove/update/move/ insert/group query tools, plus rule/group factories, * validation, and formatting.

The query is held internally, so each method takes the same arguments as its queryTools counterpart minus the leading query parameter, and returns the manager itself for chaining. Mutations use the non-InPlace tools, so a query previously handed out by QueryManager.getQuery is never modified. Under freeze: false that remains true, but as a convention rather than a runtime-enforced guarantee.

const q = new QueryManager(undefined, { fields });
q.add(q.createRule()).add({ field: 'firstName', operator: '=', value: 'Steve' });
q.format('sql');

Like the underlying query tools, methods are a no-op when the target path or id can't be resolved (including attempts to remove the root group). By default nothing is thrown; pass strict: true to raise a QueryManagerError instead, or onInvalidTarget to observe aborted operations without changing control flow.

Type Parameters​

Type ParameterDefault type
RG extends RuleGroupTypeAnyRuleGroupType
F extends FullFieldFullField
O extends FullOperatorFullOperator
C extends FullCombinatorFullCombinator

Constructors​

Constructor​

new QueryManager<RG extends RuleGroupTypeAny = RuleGroupType<RuleType<string, string, any, string, Record<string, any>>, string>, F extends {[key: string]: unknown; className?: Classname; comparator?: string | ((f: {[key: string]: unknown; className?: Classname; comparator?: string | ((f: { [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string...; defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }> | FlexibleOption<string>[] | string | FlexibleOption<string>[]; placeholder?: string; subproperties?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string | FlexibleOpt...>; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType); values?: FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); }, operator: string) => boolean); defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }> | FlexibleOption<string>[] | string | FlexibleOption<string>[]; placeholder?: string; subproperties?: FlexibleOptionList<{[key: string]: unknown; className?: Classname | undefined; comparator?: string | ((f: { [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string | FlexibleOpt..., operator: string) => boolean); defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null | undefined; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<string>[] | (string | FlexibleOption<...>)[] | undefined; placeholder?: string; subproperties?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (s...; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType) | undefined; values?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | undefined; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); }>; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType); values?: FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); } = {[key: string]: unknown; className?: Classname; comparator?: string | ((f: {[key: string]: unknown; className?: Classname; comparator?: string | ((f: { [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string...; defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }> | FlexibleOption<string>[] | string | FlexibleOption<string>[]; placeholder?: string; subproperties?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string | FlexibleOpt...>; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType); values?: FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); }, operator: string) => boolean); defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }> | FlexibleOption<string>[] | string | FlexibleOption<string>[]; placeholder?: string; subproperties?: FlexibleOptionList<{[key: string]: unknown; className?: Classname | undefined; comparator?: string | ((f: { [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (string | FlexibleOpt..., operator: string) => boolean); defaultOperator?: string; defaultValue?: any; disabled?: boolean; id?: string; inputType?: InputType | null | undefined; label: string; matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[]; name: string; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<string>[] | (string | FlexibleOption<...>)[] | undefined; placeholder?: string; subproperties?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; id?: string | undefined; operators?: string[] | FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | FlexibleOption<...>[] | (s...; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType) | undefined; values?: FlexibleOptionList<{ [x: string]: unknown; label: string; disabled?: boolean | undefined; name: string; value: string; }> | undefined; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); }>; validator?: RuleValidator; value: string; valueEditorType?: ValueEditorType | ((operator: string) => ValueEditorType); values?: FlexibleOptionList<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>; valueSources?: ValueSources | [FlexibleOption, ...FlexibleOption[]] | ((operator: string) => ValueSources | [FlexibleOption, ...FlexibleOption[]]); }, O extends FullOperator<string> = FullOperator<string>, C extends FullCombinator = FullCombinator>(query?: RG, options?: QueryManagerOptions<F, O, C>): QueryManager<RG, F, O, C>

Defined in: packages/core/src/utils/QueryManager.ts:547

Parameters​

ParameterType
query?RG
options?QueryManagerOptions<F, O, C>

Returns​

QueryManager<RG, F, O, C>

Methods​

[iterator]()​

[iterator](): Generator<QueryNode<RG>>

Defined in: packages/core/src/utils/QueryManager.ts:1558

Equivalent to QueryManager.walk with no options, enabling for...of and spread.

Returns​

Generator<QueryNode<RG>>


add()​

add(ruleOrGroup: RuleType<string, string, any, string, Record<string, any>> | RG, parentPathOrID?: string | Path, options?: AddOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:953

Adds a rule or group to the end of the group at parentPathOrID, which defaults to the root group.

Parameters​

ParameterTypeDefault value
ruleOrGroupRuleType<string, string, any, string, Record<string, any>> | RGundefined
parentPathOrIDstring | Path[]
optionsAddOptions & StrictOptions{}

Returns​

this


batch()​

batch(fn: () => void): this

Defined in: packages/core/src/utils/QueryManager.ts:1279

Runs fn, deferring history recording and subscriber notification until it returns. The whole batch becomes a single undo step and triggers a single notification, or neither if the query ends up unchanged.

Batches may be nested; only the outermost one commits. If fn throws, the query and its history are restored to their pre-batch state and the error propagates, so a batch either applies completely or not at all.

QueryManager.undo, QueryManager.redo, and QueryManager.clearHistory may be called inside a batch; their notifications are deferred like everything else. Because they manage the history stacks themselves, a batch containing one of them records no entry of its own, leaving the stacks exactly as those methods left them.

Parameters​

ParameterType
fn() => void

Returns​

this


canRedo()​

canRedo(): boolean

Defined in: packages/core/src/utils/QueryManager.ts:1351

Whether there is an undone query to restore. Always false unless history is enabled.

Returns​

boolean


canUndo()​

canUndo(): boolean

Defined in: packages/core/src/utils/QueryManager.ts:1346

Whether there is a previous query to restore. Always false unless history is enabled.

Returns​

boolean


clearHistory()​

clearHistory(): this

Defined in: packages/core/src/utils/QueryManager.ts:1384

Discards all undo/redo history without changing the current query.

Returns​

this


clone()​

clone(options?: { regenerateIDs?: boolean; }): QueryManager<RG, F, O, C>

Defined in: packages/core/src/utils/QueryManager.ts:1224

Creates an independent manager with the same configuration and the current query.

Subscribers and history are not carried over: the clone starts with no listeners and an empty undo stack. Because every mutation produces a new query object, the two managers share the initial query safely and diverge from the first change.

Pass { regenerateIDs: true } to give every rule and group in the clone a new id, which is useful when both queries will be used together (e.g. inserted into the same tree).

Parameters​

ParameterType
options?{ regenerateIDs?: boolean; }
options.regenerateIDs?boolean

Returns​

QueryManager<RG, F, O, C>


createRule()​

createRule(): RuleType

Defined in: packages/core/src/utils/QueryManager.ts:917

Creates a rule using the configured fields, operators, and defaults. The rule is not added to the query—pass it to QueryManager.add or QueryManager.insert.

Returns​

RuleType


createRuleGroup()​

createRuleGroup(independentCombinators?: boolean): RG

Defined in: packages/core/src/utils/QueryManager.ts:933

Creates a group. Pass true for a group with independent combinators. The group is not added to the query—pass it to QueryManager.add or QueryManager.insert.

Parameters​

ParameterType
independentCombinators?boolean

Returns​

RG


diagnostics()​

diagnostics(): DiagnosticsResult

Defined in: packages/core/src/utils/QueryManager.ts:1794

Generates a DiagnosticsResult. Shorthand for format('diagnostics').

Returns​

DiagnosticsResult


filter()​

filter(predicate: (entry: QueryNode<RG>) => boolean, options?: WalkOptions): QueryNode<RG>[]

Defined in: packages/core/src/utils/QueryManager.ts:1549

Returns every node matching predicate.

Parameters​

ParameterType
predicate(entry: QueryNode<RG>) => boolean
optionsWalkOptions

Returns​

QueryNode<RG>[]


find()​

find(predicate: (entry: QueryNode<RG>) => boolean, options?: WalkOptions): QueryNode<RG> | null

Defined in: packages/core/src/utils/QueryManager.ts:1538

Returns the first node matching predicate, or null if there is none.

Parameters​

ParameterType
predicate(entry: QueryNode<RG>) => boolean
optionsWalkOptions

Returns​

QueryNode<RG> | null


findID()​

findID(id: string): FindPathReturnType

Defined in: packages/core/src/utils/QueryManager.ts:1580

Returns the rule or group with the given id, or null if there is none. Backed by an index built once per query, so repeated lookups are constant time.

Parameters​

ParameterType
idstring

Returns​

FindPathReturnType


findPath()​

findPath(path: Path): FindPathReturnType

Defined in: packages/core/src/utils/QueryManager.ts:1572

Returns the rule or group at the given path, or null if the path can't be resolved.

Unlike the standalone findPath, which can return undefined for an out-of-range index, unresolvable paths are always normalized to null here.

Parameters​

ParameterType
pathPath

Returns​

FindPathReturnType


format()​

Call Signature​

format(): string

Defined in: packages/core/src/utils/QueryManager.ts:1421

Generates a JSON string from the current query.

Returns​

string

Call Signature​

format<TResult = unknown>(options: FormatQueryOptions & { ruleGroupProcessor: RuleGroupProcessor<TResult>; }): TResult

Defined in: packages/core/src/utils/QueryManager.ts:1423

Generates a result based on the provided rule group processor.

Type Parameters​
Type ParameterDefault type
TResultunknown
Parameters​
ParameterType
optionsFormatQueryOptions & { ruleGroupProcessor: RuleGroupProcessor<TResult>; }
Returns​

TResult

Call Signature​

format(options: "parameterized" | FormatQueryOptions & { format: "parameterized"; }): ParameterizedSQL

Defined in: packages/core/src/utils/QueryManager.ts:1427

Generates a ParameterizedSQL object from the current query.

Parameters​
ParameterType
options"parameterized" | FormatQueryOptions & { format: "parameterized"; }
Returns​

ParameterizedSQL

Call Signature​

format(options: "parameterized_named" | FormatQueryOptions & { format: "parameterized_named"; }): ParameterizedNamedSQL

Defined in: packages/core/src/utils/QueryManager.ts:1431

Generates a ParameterizedNamedSQL object from the current query.

Parameters​
ParameterType
options"parameterized_named" | FormatQueryOptions & { format: "parameterized_named"; }
Returns​

ParameterizedNamedSQL

Call Signature​

format(options: "jsonlogic" | FormatQueryOptions & { format: "jsonlogic"; }): RQBJsonLogic

Defined in: packages/core/src/utils/QueryManager.ts:1435

Generates a JsonLogic object from the current query.

Parameters​
ParameterType
options"jsonlogic" | FormatQueryOptions & { format: "jsonlogic"; }
Returns​

RQBJsonLogic

Call Signature​

format(options: "elasticsearch" | FormatQueryOptions & { format: "elasticsearch"; }): Record<string, any>

Defined in: packages/core/src/utils/QueryManager.ts:1437

Generates an ElasticSearch query object from the current query.

Parameters​
ParameterType
options"elasticsearch" | FormatQueryOptions & { format: "elasticsearch"; }
Returns​

Record<string, any>

Call Signature​

format(options: "mongodb_query" | FormatQueryOptions & { format: "mongodb_query"; }): Record<string, any>

Defined in: packages/core/src/utils/QueryManager.ts:1442

Generates a MongoDB query object from the current query.

Parameters​
ParameterType
options"mongodb_query" | FormatQueryOptions & { format: "mongodb_query"; }
Returns​

Record<string, any>

Call Signature​

format(options: "prisma" | FormatQueryOptions & { format: "prisma"; }): Record<string, any>

Defined in: packages/core/src/utils/QueryManager.ts:1447

Generates a Prisma ORM query object from the current query.

Parameters​
ParameterType
options"prisma" | FormatQueryOptions & { format: "prisma"; }
Returns​

Record<string, any>

Call Signature​

format(options: "drizzle" | FormatQueryOptions & { format: "drizzle"; }): DrizzleWhereCallback

Defined in: packages/core/src/utils/QueryManager.ts:1452

Generates a Drizzle ORM query object from the current query.

Parameters​
ParameterType
options"drizzle" | FormatQueryOptions & { format: "drizzle"; }
Returns​

DrizzleWhereCallback

Call Signature​

format(options: "tanstack_db" | FormatQueryOptions & { format: "tanstack_db"; }): TanStackDbWhereCallback

Defined in: packages/core/src/utils/QueryManager.ts:1456

Generates a TanStack DB query object from the current query.

Parameters​
ParameterType
options"tanstack_db" | FormatQueryOptions & { format: "tanstack_db"; }
Returns​

TanStackDbWhereCallback

Call Signature​

format(options: "sequelize" | FormatQueryOptions & { format: "sequelize"; }): SequelizeWhereOptionsLike | undefined

Defined in: packages/core/src/utils/QueryManager.ts:1460

Generates a Sequelize ORM query object from the current query.

Parameters​
ParameterType
options"sequelize" | FormatQueryOptions & { format: "sequelize"; }
Returns​

SequelizeWhereOptionsLike | undefined

Call Signature​

format(options: "diagnostics" | FormatQueryOptions & { format: "diagnostics"; }): DiagnosticsResult

Defined in: packages/core/src/utils/QueryManager.ts:1464

Generates a diagnostics result from the current query.

Parameters​
ParameterType
options"diagnostics" | FormatQueryOptions & { format: "diagnostics"; }
Returns​

DiagnosticsResult

Call Signature​

format(options: "sequelize" | "json" | "sql" | "json_without_ids" | "mongodb" | "cel" | "spel" | "natural_language" | "ldap" | "drizzle" | "tanstack_db" | "prisma" | "cypher" | "gql" | "sparql" | "gremlin"): string

Defined in: packages/core/src/utils/QueryManager.ts:1468

Generates a query string in the requested format.

Parameters​
ParameterType
options"sequelize" | "json" | "sql" | "json_without_ids" | "mongodb" | "cel" | "spel" | "natural_language" | "ldap" | "drizzle" | "tanstack_db" | "prisma" | "cypher" | "gql" | "sparql" | "gremlin"
Returns​

string

Call Signature​

format(options: FormatQueryOptions & { format: "sequelize" | "json" | "sql" | "json_without_ids" | "mongodb" | "cel" | "spel" | "natural_language" | "ldap" | "drizzle" | "tanstack_db" | "prisma" | "cypher" | "gql" | "sparql" | "gremlin"; }): string

Defined in: packages/core/src/utils/QueryManager.ts:1470

Generates a query string in the requested format.

Parameters​
ParameterType
optionsFormatQueryOptions & { format: "sequelize" | "json" | "sql" | "json_without_ids" | "mongodb" | "cel" | "spel" | "natural_language" | "ldap" | "drizzle" | "tanstack_db" | "prisma" | "cypher" | "gql" | "sparql" | "gremlin"; }
Returns​

string

Call Signature​

format(options: FormatQueryOptions): string

Defined in: packages/core/src/utils/QueryManager.ts:1474

Generates a query string in the requested format.

Parameters​
ParameterType
optionsFormatQueryOptions
Returns​

string


fromIC()​

fromIC(): QueryManager<AsRuleGroup<ToRuleGroupType<RG>>, F, O, C>

Defined in: packages/core/src/utils/QueryManager.ts:1827

Returns a new manager with the same configuration and the current query converted to use a single combinator per group. Idempotent, and never modifies this manager. As with QueryManager.clone, subscribers and history are not carried over.

Returns​

QueryManager<AsRuleGroup<ToRuleGroupType<RG>>, F, O, C>


getCombinators()​

getCombinators(): FullOptionList<C>

Defined in: packages/core/src/utils/QueryManager.ts:1655

The normalized combinator list, as the QueryBuilder component would render it. Needed to populate a combinator selector.

Returns​

FullOptionList<C>


getConfigVersion()​

getConfigVersion(): number

Defined in: packages/core/src/utils/QueryManager.ts:1208

A counter incremented by every QueryManager.reconfigure call. Because reconfiguring leaves the query object untouched, subscribers that compare query identity alone cannot see it; this provides a snapshot that does change.

Bound to the instance, so it can be passed directly to useSyncExternalStore alongside QueryManager.subscribe. The useQueryManager hook from react-querybuilder already does this.

Returns​

number


getFieldData()​

getFieldData(field: string): F

Defined in: packages/core/src/utils/QueryManager.ts:1664

The field configuration for a field name. When the field isn't configured, returns the same minimal fallback ({ name, value, label }, all set to the field name) that QueryManager.getRuleContext reports as fieldData, so both access paths agree.

Parameters​

ParameterType
fieldstring

Returns​

F


getFieldMap()​

getFieldMap(): Partial<FullOptionRecord<F>>

Defined in: packages/core/src/utils/QueryManager.ts:1716

The flattened field record backing QueryManager.getFieldData, keyed by field name with option groups flattened away.

Treat the result as read-only. It may or may not be frozen depending on configuration, so do not rely on frozen-ness to prevent mutation.

Returns​

Partial<FullOptionRecord<F>>


getFields()​

getFields(): FullOptionList<F>

Defined in: packages/core/src/utils/QueryManager.ts:1647

The normalized field list, as the QueryBuilder component would render it. Needed to populate a field selector.

Returns​

FullOptionList<F>


getGroup()​

getGroup(pathOrID: string | Path): RG | null

Defined in: packages/core/src/utils/QueryManager.ts:1621

Returns the group at the given path or id, or null if it can't be resolved or resolves to a rule.

Parameters​

ParameterType
pathOrIDstring | Path

Returns​

RG | null


getHistory()​

getHistory(): { future: RG[]; past: RG[]; }

Defined in: packages/core/src/utils/QueryManager.ts:1396

The recorded history: past oldest first, future newest first. Both are copies, so mutating them does not affect the manager.

Returns​

{ future: RG[]; past: RG[]; }

future​

future: RG[]

past​

past: RG[]


getMatchModes()​

getMatchModes(field: string): MatchModeOptions

Defined in: packages/core/src/utils/QueryManager.ts:1679

The match modes available for a field.

Parameters​

ParameterType
fieldstring

Returns​

MatchModeOptions


getNode()​

getNode(pathOrID: string | Path): FindPathReturnType

Defined in: packages/core/src/utils/QueryManager.ts:1603

Returns the rule or group at the given path or id, or null if it can't be resolved.

Parameters​

ParameterType
pathOrIDstring | Path

Returns​

FindPathReturnType


getOperators()​

getOperators(field: string): FullOptionList<O>

Defined in: packages/core/src/utils/QueryManager.ts:1669

The operator list for a field, mirroring QueryBuilder's precedence.

Parameters​

ParameterType
fieldstring

Returns​

FullOptionList<O>


getOptions()​

getOptions(): Readonly<QueryManagerOptions<F, O, C>>

Defined in: packages/core/src/utils/QueryManager.ts:1102

The options currently in effect, as a frozen shallow copy. Reflects everything applied by the constructor and any subsequent QueryManager.reconfigure calls, but not the defaults filled in for options that were never provided.

Returns​

Readonly<QueryManagerOptions<F, O, C>>


getParent()​

getParent(pathOrID: string | Path): RG | null

Defined in: packages/core/src/utils/QueryManager.ts:1630

Returns the group containing the rule or group at the given path or id. Returns null for the root group, which has no parent, and when the target can't be resolved.

Parameters​

ParameterType
pathOrIDstring | Path

Returns​

RG | null


getPathOfID()​

getPathOfID(id: string): Path | null

Defined in: packages/core/src/utils/QueryManager.ts:1590

Returns the Path of the rule or group with the given id, or null if there is none. Backed by an index built once per query, so repeated lookups are constant time.

Parameters​

ParameterType
idstring

Returns​

Path | null


getQuery()​

getQuery(): RG

Defined in: packages/core/src/utils/QueryManager.ts:901

The current query. The returned object is structurally shared, so it is safe to retain and compare by reference to detect changes. It is also frozen unless the freeze option is false.

Like QueryManager.subscribe, this method is bound to the instance, so it can be passed as a bare reference (e.g. as the getSnapshot argument to useSyncExternalStore).

Returns​

RG


getRule()​

getRule(pathOrID: string | Path): RuleType<string, string, any, string, Record<string, any>> | null

Defined in: packages/core/src/utils/QueryManager.ts:1612

Returns the rule at the given path or id, or null if it can't be resolved or resolves to a group.

Parameters​

ParameterType
pathOrIDstring | Path

Returns​

RuleType<string, string, any, string, Record<string, any>> | null


getRuleContext()​

getRuleContext(pathOrID: string | Path): RuleContext<F> | null

Defined in: packages/core/src/utils/QueryManager.ts:1728

Resolves everything about a rule that depends on the field/operator configuration—field data, operators, value editor type, value list, value sources, match modes, and validation result. Returns null when the target can't be resolved or isn't a rule.

This is the same derivation the useRule hook performs, so a non-React implementation can render a rule without reimplementing the configuration precedence rules.

Parameters​

ParameterType
pathOrIDstring | Path

Returns​

RuleContext<F> | null


getRuleDefaultOperator()​

getRuleDefaultOperator(field: string): string

Defined in: packages/core/src/utils/QueryManager.ts:1697

The default operator for a field, identical to the operator QueryManager.createRule would assign to a new rule on that field.

Parameters​

ParameterType
fieldstring

Returns​

string


getRuleDefaultValue()​

getRuleDefaultValue(rule: RuleType): unknown

Defined in: packages/core/src/utils/QueryManager.ts:1705

The default value for a rule, identical to the value QueryManager.createRule and QueryManager.update would assign after a field or operator change.

Parameters​

ParameterType
ruleRuleType

Returns​

unknown


getRuleGroupContext()​

getRuleGroupContext(pathOrID?: string | Path): RuleGroupContext<C> | null

Defined in: packages/core/src/utils/QueryManager.ts:1764

Resolves everything about a rule group that depends on the combinator configuration, plus its validation result. Returns null when the target can't be resolved or isn't a group.

This is the same derivation the useRuleGroup hook performs.

Parameters​

ParameterTypeDefault value
pathOrIDstring | Path[]

Returns​

RuleGroupContext<C> | null


getValueEditorType()​

getValueEditorType(field: string, operator: string): ValueEditorType

Defined in: packages/core/src/utils/QueryManager.ts:1689

The value editor type for a field/operator pair.

Parameters​

ParameterType
fieldstring
operatorstring

Returns​

ValueEditorType


getValues()​

getValues(field: string, operator: string): WithUnknownIndex<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value?: string; } & {[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>[] | OptionGroup<WithUnknownIndex<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value?: string; } & {[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>>[]

Defined in: packages/core/src/utils/QueryManager.ts:1684

The value option list for a field/operator pair.

Parameters​

ParameterType
fieldstring
operatorstring

Returns​

WithUnknownIndex<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value?: string; } & {[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>[] | OptionGroup<WithUnknownIndex<{[key: string]: unknown; disabled?: boolean; label: string; name: string; value?: string; } & {[key: string]: unknown; disabled?: boolean; label: string; name: string; value: string; }>>[]


getValueSources()​

getValueSources(field: string, operator: string): [{ label: string; name: ValueSource; value: ValueSource; }, ...{ label: string; name: ValueSource; value: ValueSource }[]]

Defined in: packages/core/src/utils/QueryManager.ts:1674

The value sources available for a field/operator pair.

Parameters​

ParameterType
fieldstring
operatorstring

Returns​

[{ label: string; name: ValueSource; value: ValueSource; }, ...{ label: string; name: ValueSource; value: ValueSource }[]]


group()​

group(sourcePathOrID: string | Path, targetPathOrID: string | Path, options?: GroupOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:1060

Creates a new group at targetPathOrID containing the rules/groups currently at targetPathOrID and sourcePathOrID.

Parameters​

ParameterType
sourcePathOrIDstring | Path
targetPathOrIDstring | Path
optionsGroupOptions & StrictOptions

Returns​

this


groups()​

groups(options?: Omit<WalkOptions, "rulesOnly" | "groupsOnly">): Generator<QueryNode<RG>>

Defined in: packages/core/src/utils/QueryManager.ts:1533

Yields every group in the query, including the root group. Shorthand for walk({ ...options, groupsOnly: true }).

Parameters​

ParameterType
optionsOmit<WalkOptions, "rulesOnly" | "groupsOnly">

Returns​

Generator<QueryNode<RG>>


insert()​

insert(ruleOrGroup: RuleType<string, string, any, string, Record<string, any>> | RG, path: Path, options?: InsertOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:1040

Inserts a rule or group at the given path. Unlike the other methods, this accepts a path only—inserting at an id would be ambiguous.

Parameters​

ParameterType
ruleOrGroupRuleType<string, string, any, string, Record<string, any>> | RG
pathPath
optionsInsertOptions & StrictOptions

Returns​

this


isIC()​

isIC(): boolean

Defined in: packages/core/src/utils/QueryManager.ts:1781

Whether the current query uses independent combinators.

Returns​

boolean


move()​

move(oldPathOrID: string | Path, newPath: Path | "up" | "down", options?: MoveOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:1020

Moves the rule or group at oldPathOrID to newPath, or shifts it 'up'/'down'.

Parameters​

ParameterType
oldPathOrIDstring | Path
newPathPath | "up" | "down"
optionsMoveOptions & StrictOptions

Returns​

this


pathIsDisabled()​

pathIsDisabled(path: Path): boolean

Defined in: packages/core/src/utils/QueryManager.ts:1598

Determines whether the rule or group at the given path is disabled, either itself or by an ancestor group.

Parameters​

ParameterType
pathPath

Returns​

boolean


reconfigure()​

reconfigure(options: Partial<QueryManagerOptions<F, O, C>>, config?: { replace?: boolean; }): this

Defined in: packages/core/src/utils/QueryManager.ts:1141

Updates the manager's configuration in place, keeping the current query, the undo/redo history, and every subscriber. Use this to propagate new translations, fields, operators, and so on without discarding state:

q.reconfigure({ translations: { fields: { placeholderLabel: 'Choisir un champ' } } });

The incoming options are shallow-merged over the current ones, so keys left out are preserved. Passing a key explicitly as undefined resets it to its default. Object-valued options like translations are replaced wholesale rather than deep-merged — spread the current value in yourself to patch one key. Pass { replace: true } to discard the existing options entirely and start from the incoming set.

The query is never rewritten, even when the new options no longer describe it: a rule whose field is not in the new fields list is left as-is. Call validate to detect that, or setQuery(getQuery()) to re-normalize.

History options are honored immediately: lowering maxHistory trims the undo stack, and turning history off clears both stacks.

A call that resolves to the configuration already in effect is a no-op: nothing is re-derived, QueryManager.getConfigVersion does not change, and subscribers are not notified. Equality is structural for data and by identity for functions (optionsEqual), so a caller that rebuilds its options object on every render — which every framework adapter does — does not force a reconfigure as long as the data is the same. Rebuilding a callback per render does count as a change; memoize it to avoid that.

Otherwise subscribers are notified once and getConfigVersion is incremented. Inside a batch the options are still applied immediately — configuration is not part of a batch's rollback — but the notification is deferred and merged into the batch's single notification.

Parameters​

ParameterType
optionsPartial<QueryManagerOptions<F, O, C>>
config?{ replace?: boolean; }
config.replace?boolean

Returns​

this


redo()​

redo(): this

Defined in: packages/core/src/utils/QueryManager.ts:1371

Restores the most recently undone query. No-op when QueryManager.canRedo is false.

Returns​

this


remove()​

remove(pathOrID: string | Path, options?: RemoveOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:970

Removes the rule or group at the given path or id. The root group cannot be removed.

Parameters​

ParameterType
pathOrIDstring | Path
optionsRemoveOptions & StrictOptions

Returns​

this


rules()​

rules(options?: Omit<WalkOptions, "rulesOnly" | "groupsOnly">): Generator<QueryNode<RG>>

Defined in: packages/core/src/utils/QueryManager.ts:1525

Yields every rule in the query. Shorthand for walk({ ...options, rulesOnly: true }).

Parameters​

ParameterType
optionsOmit<WalkOptions, "rulesOnly" | "groupsOnly">

Returns​

Generator<QueryNode<RG>>


setQuery()​

setQuery(query: RG): this

Defined in: packages/core/src/utils/QueryManager.ts:904

Replaces the current query, ensuring every rule and group has an id.

Parameters​

ParameterType
queryRG

Returns​

this


signatureOf()​

signatureOf(other: RuleGroupTypeAny): string

Defined in: packages/core/src/utils/QueryManager.ts:1789

Returns the signature describing how the current query differs from other, as used by this manager's history coalescing.

Parameters​

ParameterType
otherRuleGroupTypeAny

Returns​

string


subscribe()​

subscribe(listener: (change: SubscriptionChange) => void): () => void

Defined in: packages/core/src/utils/QueryManager.ts:1254

Registers a listener called after every change to the query, and returns a function that unregisters it. Mutations that resolve to a no-op do not notify, and a batch notifies once no matter how many changes it contains.

Together with QueryManager.getQuery, this satisfies React's useSyncExternalStore contract. Both methods are bound to the instance, so they are stable references across renders and can be passed directly:

const query = useSyncExternalStore(q.subscribe, q.getQuery);

In React, prefer the useQueryManager hook from react-querybuilder, which wraps this.

The listener receives a SubscriptionChange describing what changed. It is optional: a zero-argument listener — including useSyncExternalStore's onStoreChange — is still a valid listener and behaves as it always has.

Parameters​

ParameterType
listener(change: SubscriptionChange) => void

Returns​

() => void


toIC()​

toIC(): QueryManager<AsRuleGroup<ToRuleGroupTypeIC<RG>>, F, O, C>

Defined in: packages/core/src/utils/QueryManager.ts:1815

Returns a new manager with the same configuration and the current query converted to use independent combinators. Idempotent, and never modifies this manager. As with QueryManager.clone, subscribers and history are not carried over.

Returns​

QueryManager<AsRuleGroup<ToRuleGroupTypeIC<RG>>, F, O, C>


toJSON()​

toJSON(): RG

Defined in: packages/core/src/utils/QueryManager.ts:1802

Returns the current query, so JSON.stringify(queryManager) produces the same output as JSON.stringify(queryManager.getQuery()).

Returns​

RG


transform()​

transform<T = any>(options?: TransformQueryOptions<RG>): T

Defined in: packages/core/src/utils/QueryManager.ts:1842

Runs transformQuery against the current query and returns its result.

Unlike QueryManager.toIC/QueryManager.fromIC, this returns the raw transformed value rather than a new manager, since transformQuery can produce arbitrary shapes that are no longer valid queries. This manager is never modified.

Type Parameters​

Type ParameterDefault type
Tany

Parameters​

ParameterType
options?TransformQueryOptions<RG>

Returns​

T


undo()​

undo(): this

Defined in: packages/core/src/utils/QueryManager.ts:1356

Restores the previous query. No-op when QueryManager.canUndo is false.

Returns​

this


ungroup()​

ungroup(pathOrID: string | Path, options?: UngroupOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:1081

Replaces the group at pathOrID with its own rules in the parent group. The group's combinator, not, id, muted, and disabled properties are discarded; an empty group is simply removed.

Parameters​

ParameterType
pathOrIDstring | Path
optionsUngroupOptions & StrictOptions

Returns​

this


update()​

Call Signature​

update(prop: UpdateableProperties, value: unknown, pathOrID: string | Path, options?: UpdateOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:983

Updates a single property of the rule or group at the given path or id.

Parameters​
ParameterType
propUpdateableProperties
valueunknown
pathOrIDstring | Path
options?UpdateOptions & StrictOptions
Returns​

this

Call Signature​

update(props: UpdateableProperties[], values: unknown[], pathOrID: string | Path, options?: UpdateOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:990

Updates multiple properties using parallel arrays of names and values.

Parameters​
ParameterType
propsUpdateableProperties[]
valuesunknown[]
pathOrIDstring | Path
options?UpdateOptions & StrictOptions
Returns​

this

Call Signature​

update(props: UpdateValueMap, pathOrID: string | Path, options?: UpdateOptions & StrictOptions): this

Defined in: packages/core/src/utils/QueryManager.ts:997

Updates multiple properties using a map of names to values.

Parameters​
ParameterType
propsUpdateValueMap
pathOrIDstring | Path
options?UpdateOptions & StrictOptions
Returns​

this


validate()​

validate(): boolean | ValidationMap

Defined in: packages/core/src/utils/QueryManager.ts:1410

Validates the current query with the configured validator.

The result is cached until the query changes, so a custom validator with side effects (or one that depends on anything other than the query) may run fewer times than expected.

Returns​

boolean | ValidationMap


walk()​

walk(options?: WalkOptions): Generator<QueryNode<RG>>

Defined in: packages/core/src/utils/QueryManager.ts:1499

Yields every rule and group in the query, depth-first in pre-order, starting with the root group itself. Combinator strings in independent-combinator groups are skipped.

for (const { node, path, parent } of qm.walk({ rulesOnly: true })) {
console.log(path, node.field);
}

Traversal operates on the query as it was when iteration began, so mutating the manager mid-iteration does not affect a walk already in progress. Because generators are lazy, that happens on the first iteration step rather than when walk is called.

Parameters​

ParameterType
optionsWalkOptions

Returns​

Generator<QueryNode<RG>>

Yields​

Every rule and group in the query, subject to options.


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.