import { $t as DefaultRuleGroupType, An as Except, Pt as DefaultRuleGroupTypeIC, Yt as DefaultCombinatorNameExtended, Zt as DefaultOperatorName, on as ExpressionNode } from "./index-8Ca45huD.js"; import { t as ParserCommonOptions } from "./import-DVhvnWUZ.js"; type AnyCase = string extends T ? string : T extends `${infer F1}${infer F2}${infer R}` ? `${Uppercase | Lowercase}${Uppercase | Lowercase}${AnyCase}` : T extends `${infer F}${infer R}` ? `${Uppercase | Lowercase}${AnyCase}` : ""; type TokenType = "AndExpression" | "BetweenPredicate" | "BitExpression" | "Boolean" | "BooleanExtra" | "CaseWhen" | "ComparisonBooleanPrimary" | "ComparisonSubQueryBooleanPrimary" | "ContainsExpr" | "EndsWithExpr" | "ExpressionList" | "ForceIndexHint" | "ForOptIndexHint" | "FunctionCall" | "FunctionCallParam" | "GroupBy" | "GroupByOrderByItem" | "Identifier" | "IdentifierExpr" | "IdentifierList" | "IgnoreIndexHint" | "IndexHintList" | "InExpressionListPredicate" | "InnerCrossJoinTable" | "InSubQueryPredicate" | "IsExpression" | "IsNullBooleanPrimary" | "LeftRightJoinTable" | "LikePredicate" | "Limit" | "Main" | "NaturalJoinTable" | "NotExpression" | "Null" | "Number" | "OnJoinCondition" | "OrderBy" | "OrExpression" | "Partitions" | "PlaceHolder" | "Prefix" | "RegexpPredicate" | "Select" | "SelectExpr" | "SelectParenthesized" | "SimpleExprParentheses" | "SoundsLikePredicate" | "StartsWithExpr" | "StraightJoinTable" | "String" | "SubQuery" | "TableFactor" | "TableReference" | "TableReferences" | "Union" | "UseIndexHint" | "UsingJoinCondition" | "WhenThenList" | "XorExpression"; export type ComparisonOperator = "=" | ">=" | ">" | "<=" | "<" | "<>" | "!="; export type NotOpt = AnyCase<"NOT"> | null; export type AndOperator = AnyCase<"AND">; export type OrOperator = AnyCase<"OR">; export type XorOperator = AnyCase<"XOR">; export interface SQLWhereObject { type: TokenType; } export interface SQLIdentifier extends SQLWhereObject { type: "Identifier"; value: string; } export interface SQLWhereObjectAny extends SQLWhereObject { [k: string]: any; } export interface SQLStringValue extends SQLWhereObject { type: "String"; value: string; } export interface SQLNumberValue extends SQLWhereObject { type: "Number"; value: string; } export interface SQLSignedNumberValue extends SQLWhereObject { type: "Prefix"; prefix: "+" | "-"; value: SQLNumberValue; } export interface SQLBooleanValue extends SQLWhereObject { type: "Boolean"; value: AnyCase<"TRUE"> | AnyCase<"FALSE">; } export interface SQLBooleanExtra extends SQLWhereObject { type: "BooleanExtra"; value: AnyCase<"UNKNOWN">; } export interface SQLSimpleExprParentheses extends SQLWhereObject { type: "SimpleExprParentheses"; value: SQLExpressionList; } export interface SQLExpressionList extends SQLWhereObject { type: "ExpressionList"; value: SQLExpression[]; } export interface SQLInExpressionListPredicate extends SQLWhereObject { type: "InExpressionListPredicate"; hasNot: NotOpt; left: SQLSimpleExpression; right: SQLExpressionList; } export interface SQLBetweenPredicate extends SQLWhereObject { type: "BetweenPredicate"; hasNot: NotOpt; left: SQLSimpleExpression; right: { left: SQLSimpleExpression; right: SQLPredicate; }; } export interface SQLLikePredicate extends SQLWhereObject { type: "LikePredicate"; hasNot: NotOpt; left: SQLSimpleExpression; right: SQLSimpleExpression | SQLStartsWithExpr | SQLEndsWithExpr | SQLContainsExpr; escape: SQLStringValue | null; } export interface SQLStartsWithExpr extends SQLWhereObject { type: "StartsWithExpr"; value: SQLStringValue | SQLIdentifier; } export interface SQLEndsWithExpr extends SQLWhereObject { type: "EndsWithExpr"; value: SQLStringValue | SQLIdentifier; } export interface SQLContainsExpr extends SQLWhereObject { type: "ContainsExpr"; value: SQLStringValue | SQLIdentifier; } export interface SQLIsNullBooleanPrimary extends SQLWhereObject { type: "IsNullBooleanPrimary"; hasNot: NotOpt; value: SQLBooleanPrimary; } export interface SQLComparisonBooleanPrimary extends SQLWhereObject { type: "ComparisonBooleanPrimary"; left: SQLBooleanPrimary; operator: ComparisonOperator; right: SQLPredicate; } export interface SQLIsExpression extends SQLWhereObject { type: "IsExpression"; hasNot: NotOpt; left: SQLBooleanPrimary; right: SQLBooleanExtra; } export interface SQLNotExpression extends SQLWhereObject { type: "NotExpression"; value: SQLExpression; } export interface SQLAndExpression extends SQLWhereObject { type: "AndExpression"; operator: AndOperator; left: SQLExpression; right: SQLExpression; } export interface SQLOrExpression extends SQLWhereObject { type: "OrExpression"; operator: OrOperator; left: SQLExpression; right: SQLExpression; } export interface SQLXorExpression extends SQLWhereObject { type: "XorExpression"; operator: XorOperator; left: SQLExpression; right: SQLExpression; } export interface SQLPlaceHolder extends SQLWhereObject { type: "PlaceHolder"; /** Raw token, e.g. `${p1}`. */ value: string; /** Prefix-free placeholder name, e.g. `p1`. */ param: string; } export interface SQLFunctionCall extends SQLWhereObjectAny { type: "FunctionCall"; name: string; params: SQLExpressionOperand[]; } export interface SQLCaseWhen extends SQLWhereObjectAny { type: "CaseWhen"; } export interface SQLPrefix extends SQLWhereObjectAny { type: "Prefix"; } export interface SQLSubQuery extends SQLWhereObjectAny { type: "SubQuery"; } export interface SQLIdentifierExpr extends SQLWhereObjectAny { type: "IdentifierExpr"; } export interface SQLBitExpression extends SQLWhereObjectAny { type: "BitExpression"; operator: string; left: SQLExpressionOperand; right: SQLExpressionOperand; } export interface SQLInSubQueryPredicate extends SQLWhereObjectAny { type: "InSubQueryPredicate"; } export interface SQLSoundsLikePredicate extends SQLWhereObjectAny { type: "SoundsLikePredicate"; } export interface SQLRegexpPredicate extends SQLWhereObject { type: "RegexpPredicate"; hasNot: NotOpt | "!"; caseInsensitive?: boolean; /** PostgreSQL `~` operator family (vs. `REGEXP`) */ tilde?: boolean; left: SQLSimpleExpression; right: SQLSimpleExpression; } export interface SQLComparisonSubQueryBooleanPrimary extends SQLWhereObjectAny { type: "ComparisonSubQueryBooleanPrimary"; } export type SQLLiteralValue = SQLStringValue | SQLNumberValue | SQLBooleanValue; export type SQLSimpleExpression = SQLLiteralValue | SQLIdentifier | SQLFunctionCall | SQLCaseWhen | SQLPrefix | SQLSubQuery | SQLIdentifierExpr | SQLBitExpression | SQLPlaceHolder | SQLSimpleExprParentheses; export type SQLPredicate = SQLSimpleExpression | SQLInExpressionListPredicate | SQLBetweenPredicate | SQLLikePredicate | SQLInSubQueryPredicate | SQLSoundsLikePredicate | SQLRegexpPredicate; export type SQLBooleanPrimary = SQLPredicate | SQLIsNullBooleanPrimary | SQLComparisonBooleanPrimary | SQLComparisonSubQueryBooleanPrimary; export type SQLExpression = SQLBooleanPrimary | SQLIsExpression | SQLNotExpression | SQLAndExpression | SQLOrExpression | SQLXorExpression; export interface ParsedSQL { nodeType: "Main"; value: { type: "Select"; distinctOpt: string | null; highPriorityOpt: unknown; maxStateMentTimeOpt: unknown; straightJoinOpt: unknown; sqlSmallResultOpt: unknown; sqlBigResultOpt: unknown; sqlBufferResultOpt: unknown; sqlCacheOpt: unknown; sqlCalcFoundRowsOpt: unknown; selectItems: SQLWhereObjectAny; from: SQLWhereObjectAny; partition: unknown; where: SQLExpression; groupBy: SQLWhereObjectAny | null; having: SQLWhereObjectAny | null; orderBy: SQLWhereObjectAny | null; limit: SQLWhereObjectAny | null; procedure: SQLWhereObjectAny | null; updateLockMode: unknown; }; hasSemicolon: boolean; } export type MixedAndXorOrList = { combinator: DefaultCombinatorNameExtended; expressions: (MixedAndXorOrList | SQLExpression)[]; }; /** * A SQL operand subtree that a {@link ParseSQLOptions.getExpression} handler may receive: a * bare identifier, a (signed) literal, a placeholder, an arithmetic {@link SQLBitExpression}, * a {@link SQLFunctionCall}, or a parenthesized wrapper (unwrapped by the handler). */ export type SQLExpressionOperand = SQLIdentifier | SQLLiteralValue | SQLSignedNumberValue | SQLPlaceHolder | SQLBitExpression | SQLFunctionCall | SQLSimpleExprParentheses; /** * Context passed to a {@link ParseSQLOptions.getExpression} handler alongside the operand * node. Carries the same number-parsing option as the rest of `parseSQL` plus a predicate * for validating that `field` leaves inside an expression exist in the configured fields. */ export interface ParseSQLExpressionContext { bigIntOnOverflow?: boolean; /** `true` when the field exists in the configured fields (or no fields were configured). */ fieldExists: (fieldName: string) => boolean; } /** * Options object for {@link parseSQL}. */ export interface ParseSQLOptions extends ParserCommonOptions { paramPrefix?: string; params?: any[] | Record; /** * Handler that converts a non-identifier/non-literal SQL operand subtree (arithmetic * {@link SQLExpressionOperand BitExpression} / FunctionCall / parenthesized) into an * {@link ExpressionNode}. Return `null` to reject (the rule is dropped). Supplied by * `@react-querybuilder/expr` (`expressionParserSQL`). When omitted, expression operands * are ignored (current behavior — rule dropped). */ getExpression?: (node: SQLExpressionOperand, ctx: ParseSQLExpressionContext) => ExpressionNode | null; /** * When set, parameter placeholders are retained as `valueSource: 'parameter'` rules * (value = placeholder name) instead of being dropped. Placeholders whose name is * supplied via {@link ParseSQLOptions.params} are still substituted to literals first. * * - `true` — accept the default named prefix `':'` and positional `'?'`. * - `{ prefix }` — one or more named prefixes to accept (e.g. `':'`, `'@'`, `'$'`). * - `{ positional }` — enable/disable positional `?` (default enabled). */ parseParameters?: boolean | { prefix?: string | string[]; positional?: boolean; }; } /** * Converts a SQL `SELECT` statement into a query suitable for the * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}). */ declare function parseSQL(sql: string): DefaultRuleGroupType; /** * Converts a SQL `SELECT` statement into a query suitable for the * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}). */ declare function parseSQL(sql: string, options: Except & { independentCombinators?: false; }): DefaultRuleGroupType; /** * Converts a SQL `SELECT` statement into a query suitable for the * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}). */ declare function parseSQL(sql: string, options: Except & { independentCombinators: true; }): DefaultRuleGroupTypeIC; export declare const isSQLLiteralValue: (v?: SQLWhereObjectAny) => v is SQLLiteralValue; export declare const isSQLSignedNumber: (v?: SQLWhereObjectAny) => v is SQLSignedNumberValue; export declare const isSQLLiteralOrSignedNumberValue: (v?: SQLWhereObjectAny) => v is SQLLiteralValue | SQLSignedNumberValue; export declare const isSQLIdentifier: (v?: SQLWhereObjectAny) => v is SQLIdentifier; export declare const isSQLBitExpression: (v?: SQLWhereObjectAny) => v is SQLBitExpression; export declare const isSQLFunctionCall: (v?: SQLWhereObjectAny) => v is SQLFunctionCall; export declare const isSQLPlaceHolder: (v?: SQLWhereObjectAny) => v is SQLPlaceHolder; /** An operand that is neither a bare identifier nor a (signed) literal nor a placeholder. */ export declare const isSQLExpressionOperand: (v?: SQLWhereObjectAny) => boolean; export declare const getFieldName: (f: string | SQLIdentifier) => string; export declare const normalizeOperator: (op: ComparisonOperator, flip?: boolean) => DefaultOperatorName; export declare const evalSQLLiteralValue: (valueObj: SQLLiteralValue | SQLSignedNumberValue, { bigIntOnOverflow }?: ParseSQLOptions) => any; export { parseSQL }; //# sourceMappingURL=parseSQL.d.ts.map