import { Q as QueryValidator, F as Field, R as RuleType, V as ValueSource, a as RuleGroupTypeAny, O as OptionList, c as ValueSources } from './basic-6e8613a6.js';

type RenameToIn<T> = {
    [K in keyof T as K extends `in${Uppercase<string>}${Lowercase<string>}` ? `in` : K]: T[K];
};
/**
 * This is a utility type used below for the "if" operation.
 * Original: https://stackoverflow.com/a/68373774/765987
 */
type MAXIMUM_ALLOWED_BOUNDARY = 80;
type Mapped<Tuple extends unknown[], Result extends unknown[] = [], Count extends ReadonlyArray<number> = []> = Count['length'] extends MAXIMUM_ALLOWED_BOUNDARY ? Result : Tuple extends [] ? [] : Result extends [] ? Mapped<Tuple, Tuple, [...Count, 1]> : Mapped<Tuple, Result | [...Result, ...Tuple], [...Count, 1]>;
/**
 * Used for the "if" operation, which takes an array of odd length
 * and a minimum of three (3) elements.
 */
type AnyArrayOfOddLengthMin3 = [any, ...Mapped<[any, any]>];
type ReservedOperations = 'var' | 'missing' | 'missing_some' | 'if' | '==' | '===' | '!=' | '!==' | '!' | '!!' | 'or' | 'and' | '>' | '>=' | '<' | '<=' | 'max' | 'min' | '+' | '-' | '*' | '/' | '%' | 'map' | 'filter' | 'reduce' | 'all' | 'none' | 'some' | 'merge' | 'in' | 'cat' | 'substr' | 'log';
/**
 * This can be an object with any key except the reserved keys.
 * TODO: Find a way to limit this type to exactly one (1) key, since
 * json-logic-js enforces it. See:
 * https://github.com/jwadhams/json-logic-js/blob/2.0.2/logic.js#L180
 */
type AdditionalOperation = Partial<Record<ReservedOperations, never>> & {
    [k: string]: any;
};
interface AllReservedOperationsInterface<AddOps extends AdditionalOperation = never> {
    var: RulesLogic<AddOps> | [RulesLogic<AddOps>] | [RulesLogic<AddOps>, any] | [RulesLogic<AddOps>, any];
    missing: RulesLogic<AddOps> | any[];
    missing_some: [RulesLogic<AddOps>, RulesLogic<AddOps> | any[]];
    if: AnyArrayOfOddLengthMin3;
    '==': [any, any];
    '===': [any, any];
    '!=': [any, any];
    '!==': [any, any];
    '!': any;
    '!!': any;
    or: Array<RulesLogic<AddOps>>;
    and: Array<RulesLogic<AddOps>>;
    '>': [RulesLogic<AddOps>, RulesLogic<AddOps>];
    '>=': [RulesLogic<AddOps>, RulesLogic<AddOps>];
    '<': [RulesLogic<AddOps>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>, RulesLogic<AddOps>];
    '<=': [RulesLogic<AddOps>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>, RulesLogic<AddOps>];
    max: Array<RulesLogic<AddOps>>;
    min: Array<RulesLogic<AddOps>>;
    '+': Array<RulesLogic<AddOps>> | RulesLogic<AddOps>;
    '-': Array<RulesLogic<AddOps>> | RulesLogic<AddOps>;
    '*': Array<RulesLogic<AddOps>> | RulesLogic<AddOps>;
    '/': Array<RulesLogic<AddOps>> | RulesLogic<AddOps>;
    '%': [RulesLogic<AddOps>, RulesLogic<AddOps>];
    map: [RulesLogic<AddOps>, RulesLogic<AddOps>];
    filter: [RulesLogic<AddOps>, RulesLogic<AddOps>];
    reduce: [RulesLogic<AddOps>, RulesLogic<AddOps>, RulesLogic<AddOps>];
    all: [Array<RulesLogic<AddOps>>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>];
    none: [Array<RulesLogic<AddOps>>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>];
    some: [Array<RulesLogic<AddOps>>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>];
    merge: Array<Array<RulesLogic<AddOps>> | RulesLogic<AddOps>>;
    inArray: [RulesLogic<AddOps>, Array<RulesLogic<AddOps>>];
    inString: [RulesLogic<AddOps>, RulesLogic<AddOps>];
    cat: Array<RulesLogic<AddOps>>;
    substr: [RulesLogic<AddOps>, RulesLogic<AddOps>] | [RulesLogic<AddOps>, RulesLogic<AddOps>, RulesLogic<AddOps>];
    log: RulesLogic<AddOps>;
}
type JsonLogicVar<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'var'>;
type JsonLogicMissing<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'missing'>;
type JsonLogicMissingSome<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'missing_some'>;
type JsonLogicIf = Pick<AllReservedOperationsInterface, 'if'>;
type JsonLogicEqual = Pick<AllReservedOperationsInterface, '=='>;
type JsonLogicStrictEqual = Pick<AllReservedOperationsInterface, '==='>;
type JsonLogicNotEqual = Pick<AllReservedOperationsInterface, '!='>;
type JsonLogicStrictNotEqual = Pick<AllReservedOperationsInterface, '!=='>;
type JsonLogicNegation = Pick<AllReservedOperationsInterface, '!'>;
type JsonLogicDoubleNegation = Pick<AllReservedOperationsInterface, '!!'>;
type JsonLogicOr<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'or'>;
type JsonLogicAnd<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'and'>;
type JsonLogicGreaterThan<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '>'>;
type JsonLogicGreaterThanOrEqual<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '>='>;
type JsonLogicLessThan<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '<'>;
type JsonLogicLessThanOrEqual<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '<='>;
type JsonLogicMax<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'max'>;
type JsonLogicMin<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'min'>;
type JsonLogicSum<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '+'>;
type JsonLogicDifference<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '-'>;
type JsonLogicProduct<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '*'>;
type JsonLogicQuotient<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '/'>;
type JsonLogicRemainder<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, '%'>;
type JsonLogicMap<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'map'>;
type JsonLogicFilter<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'filter'>;
type JsonLogicReduce<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'reduce'>;
type JsonLogicAll<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'all'>;
type JsonLogicNone<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'none'>;
type JsonLogicSome<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'some'>;
type JsonLogicMerge<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'merge'>;
type JsonLogicInArray<AddOps extends AdditionalOperation = never> = RenameToIn<Pick<AllReservedOperationsInterface<AddOps>, 'inArray'>>;
type JsonLogicInString<AddOps extends AdditionalOperation = never> = RenameToIn<Pick<AllReservedOperationsInterface<AddOps>, 'inString'>>;
type JsonLogicCat<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'cat'>;
type JsonLogicSubstr<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'substr'>;
type JsonLogicLog<AddOps extends AdditionalOperation = never> = Pick<AllReservedOperationsInterface<AddOps>, 'log'>;
type RulesLogic<AddOps extends AdditionalOperation = never> = boolean | string | number | JsonLogicVar<AddOps> | JsonLogicMissing<AddOps> | JsonLogicMissingSome<AddOps> | JsonLogicIf | JsonLogicEqual | JsonLogicStrictEqual | JsonLogicNotEqual | JsonLogicStrictNotEqual | JsonLogicNegation | JsonLogicDoubleNegation | JsonLogicOr<AddOps> | JsonLogicAnd<AddOps> | JsonLogicGreaterThan<AddOps> | JsonLogicGreaterThanOrEqual<AddOps> | JsonLogicLessThan<AddOps> | JsonLogicLessThanOrEqual<AddOps> | JsonLogicMax<AddOps> | JsonLogicMin<AddOps> | JsonLogicSum<AddOps> | JsonLogicDifference<AddOps> | JsonLogicProduct<AddOps> | JsonLogicQuotient<AddOps> | JsonLogicRemainder<AddOps> | JsonLogicMap<AddOps> | JsonLogicFilter<AddOps> | JsonLogicReduce<AddOps> | JsonLogicAll<AddOps> | JsonLogicNone<AddOps> | JsonLogicSome<AddOps> | JsonLogicMerge<AddOps> | JsonLogicInArray<AddOps> | JsonLogicInString<AddOps> | JsonLogicCat<AddOps> | JsonLogicSubstr<AddOps> | JsonLogicLog<AddOps> | AddOps;

type ExportFormat = 'json' | 'sql' | 'json_without_ids' | 'parameterized' | 'parameterized_named' | 'mongodb' | 'cel' | 'jsonlogic' | 'spel';
interface FormatQueryOptions {
    /**
     * The export format.
     */
    format?: ExportFormat;
    /**
     * This function will be used to process the `value` from each rule
     * for query language formats. If not defined, the appropriate
     * `defaultValueProcessor` for the format will be used.
     */
    valueProcessor?: ValueProcessorLegacy | ValueProcessorByRule;
    /**
     * This function will be used to process each rule for query language
     * formats. If not defined, the appropriate `defaultRuleProcessor`
     * for the format will be used.
     */
    ruleProcessor?: RuleProcessor;
    /**
     * In the "sql"/"parameterized"/"parameterized_named" export formats,
     * field names will be bracketed by this string. If an array of strings
     * is passed, field names will be preceded by the first element and
     * succeeded by the second element. A common value for this option is
     * the backtick ('`').
     *
     * @default '' // the empty string
     *
     * @example
     * formatQuery(query, { format: 'sql', quoteFieldNamesWith: ['[', ']'] })
     * // `[First name] = 'Steve'`
     */
    quoteFieldNamesWith?: string | [string, string];
    /**
     * Validator function for the entire query. Can be the same function passed
     * as `validator` prop to `<QueryBuilder />`.
     */
    validator?: QueryValidator;
    /**
     * This can be the same Field[] passed to <QueryBuilder />, but really
     * all you need to provide is the name and validator for each field.
     */
    fields?: (Pick<Field, 'name' | 'validator'> & Record<string, any>)[];
    /**
     * This string will be inserted in place of invalid groups for non-JSON formats.
     * Defaults to '(1 = 1)' for "sql"/"parameterized"/"parameterized_named",
     * '$and:[{$expr:true}]' for "mongodb".
     */
    fallbackExpression?: string;
    /**
     * This string will be placed in front of named parameters (aka bind variables)
     * when using the "parameterized_named" export format. Default is ":".
     */
    paramPrefix?: string;
    /**
     * Maintains the parameter prefix in the `params` object keys when using the
     * "parameterized_named" export format. Recommended when using SQLite.
     *
     * @default false
     *
     * @example
     * console.log(formatQuery(query, {
     *   format: "parameterized_named",
     *   paramPrefix: "$",
     *   paramsKeepPrefix: true
     * }).params)
     * // { $firstName: "Stev" }
     * // Default (`paramsKeepPrefix` is `false`):
     * // { firstName: "Stev" }
     */
    paramsKeepPrefix?: boolean;
    /**
     * Renders values as either `number`-types or unquoted strings, as
     * appropriate and when possible. Each `string`-type value is passed
     * to `parseFloat` to determine if it can be represented as a plain
     * numeric value.
     */
    parseNumbers?: boolean;
    /**
     * Any rules where the field is equal to this value will be ignored.
     *
     * @default '~'
     */
    placeholderFieldName?: string;
    /**
     * Any rules where the operator is equal to this value will be ignored.
     *
     * @default '~'
     */
    placeholderOperatorName?: string;
}
type ValueProcessorOptions = Pick<FormatQueryOptions, 'parseNumbers' | 'quoteFieldNamesWith'> & {
    escapeQuotes?: boolean;
};
type ValueProcessorByRule = (rule: RuleType, options?: ValueProcessorOptions) => string;
type ValueProcessorLegacy = (field: string, operator: string, value: any, valueSource?: ValueSource) => string;
type RuleProcessor = (rule: RuleType, options?: ValueProcessorOptions) => any;
interface ParameterizedSQL {
    sql: string;
    params: any[];
}
interface ParameterizedNamedSQL {
    sql: string;
    params: Record<string, any>;
}
interface RQBJsonLogicStartsWith {
    startsWith: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
}
interface RQBJsonLogicEndsWith {
    endsWith: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
}
type RQBJsonLogic = RulesLogic<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith>;
interface ParserCommonOptions {
    fields?: OptionList<Field> | Record<string, Field>;
    getValueSources?: (field: string, operator: string) => ValueSources;
    listsAsArrays?: boolean;
    independentCombinators?: boolean;
}
interface ParseSQLOptions extends ParserCommonOptions {
    paramPrefix?: string;
    params?: any[] | Record<string, any>;
}
type ParseCELOptions = ParserCommonOptions;
interface ParseJsonLogicOptions extends ParserCommonOptions {
    jsonLogicOperations?: Record<string, (value: any) => RuleType | RuleGroupTypeAny>;
}
type ParseMongoDbOptions = ParserCommonOptions;

export { ExportFormat as E, FormatQueryOptions as F, ParameterizedSQL as P, RuleProcessor as R, ValueProcessorByRule as V, ValueProcessorOptions as a, ParameterizedNamedSQL as b, RQBJsonLogic as c, ValueProcessorLegacy as d, ParseCELOptions as e, ParseJsonLogicOptions as f, ParseMongoDbOptions as g, ParseSQLOptions as h };
