UNPKG

react-querybuilder

Version:

React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts

75 lines (74 loc) 3.12 kB
import type { ParserCommonOptions } from "../../types/import"; import type { DefaultRuleGroupType, DefaultRuleGroupTypeIC, Except, RuleGroupType, RuleType } from "../../types/index.noReact"; /** * Options object for {@link parseMongoDB}. */ export interface ParseMongoDbOptions extends ParserCommonOptions { /** * When `true`, MongoDB rules in the form of `{ fieldName: { $not: { <...rule> } } }` * will be parsed into a rule group with the `not` attribute set to `true`. By default * (i.e., when this attribute is `false`), such "`$not`" rules will be parsed into a * rule with a negated operator. * * For example, with `preventOperatorNegation` set to `true`, a MongoDB rule like this... * * ```ts * { fieldName: { $not: { $eq: 1 } } } * ``` * * ...would yield a rule group like this: * * ```ts * { * combinator: 'and', * not: true, * rules: [{ field: 'fieldName', operator: '=', value: 1 }] * } * ``` * * By default, the same MongoDB rule would yield a rule like this: * * ```ts * { field: 'fieldName', operator: '!=', value: 1 } * // negated operator ^ * ``` * * @default false */ preventOperatorNegation?: boolean; /** * Map of additional operators to their respective processing functions. Operators * must begin with `"$"`. Processing functions should return either a {@link index!RuleType RuleType} * or {@link index!RuleGroupType RuleGroupType}. * * (The functions should _not_ return {@link index!RuleGroupTypeIC RuleGroupTypeIC}, even if using independent * combinators. If the `independentCombinators` option is `true`, `parseMongoDB` * will convert the final query to {@link index!RuleGroupTypeIC RuleGroupTypeIC} before returning it.) * * @default {} */ additionalOperators?: Record<`$${string}`, (field: string, operator: string, value: any, options: ParserCommonOptions) => RuleType | RuleGroupType>; } /** * Converts a MongoDB query object or parseable string into a query suitable * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}). */ declare function parseMongoDB(mongoDbRules: string | Record<string, any>): DefaultRuleGroupType; /** * Converts a MongoDB query object or parseable string into a query suitable * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}). */ declare function parseMongoDB(mongoDbRules: string | Record<string, any>, options: Except<ParseMongoDbOptions, "independentCombinators"> & { independentCombinators?: false }): DefaultRuleGroupType; /** * Converts a MongoDB query object or parseable string into a query suitable * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}). */ declare function parseMongoDB(mongoDbRules: string | Record<string, any>, options: Except<ParseMongoDbOptions, "independentCombinators"> & { independentCombinators: true }): DefaultRuleGroupTypeIC; export { parseMongoDB };