@react-querybuilder/core
Version:
React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts
314 lines (313 loc) • 15.1 kB
TypeScript
import { C as Except, _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, h as DefaultOperatorName, m as DefaultCombinatorName, p as RuleGroupTypeIC, v as RuleType } from "./basic-BeKPP0_1.js";
import { t as ParserCommonOptions } from "./import-Dvayhrgj.js";
//#region src/utils/parseCEL/types.d.ts
type CELExpressionType = "Addition" | "BooleanLiteral" | "BytesLiteral" | "ConditionalAnd" | "ConditionalExpr" | "ConditionalOr" | "Division" | "DynamicPropertyAccessor" | "ExpressionGroup" | "ExpressionList" | "FieldInit" | "FieldInits" | "FieldsObject" | "FloatLiteral" | "FunctionCall" | "Identifier" | "IntegerLiteral" | "List" | "Map" | "MapInit" | "MapInits" | "Member" | "Modulo" | "Multiplication" | "Negation" | "Negative" | "NullLiteral" | "Property" | "Relation" | "StringLiteral" | "Subtraction" | "Unary" | "UnsignedIntegerLiteral" | "LikeExpression";
type CELRelop = "==" | ">=" | ">" | "<=" | "<" | "!=" | "in";
interface CELExpression {
type: CELExpressionType;
}
interface CELIdentifier<LimitTo extends string = string> extends CELExpression {
type: "Identifier";
value: LimitTo;
}
interface CELStringLiteral extends CELExpression {
type: "StringLiteral";
value: `'${string}'` | `"${string}"` | `'''${string}'''` | `"""${string}"""`;
}
interface CELBytesLiteral extends CELExpression {
type: "BytesLiteral";
value: string;
}
interface CELIntegerLiteral extends CELExpression {
type: "IntegerLiteral";
value: number;
}
interface CELUnsignedIntegerLiteral extends CELExpression {
type: "UnsignedIntegerLiteral";
value: number;
}
interface CELFloatLiteral extends CELExpression {
type: "FloatLiteral";
value: number;
}
interface CELBooleanLiteral extends CELExpression {
type: "BooleanLiteral";
value: boolean;
}
interface CELNullLiteral extends CELExpression {
type: "NullLiteral";
value: null;
}
interface CELRelation extends CELExpression {
type: "Relation";
left: CELExpression;
operator: CELRelop;
right: CELExpression;
}
interface CELConditionalExpr extends CELExpression {
type: "ConditionalExpr";
condition: CELExpression;
valueIfTrue: CELExpression;
valueIfFalse: CELExpression;
}
interface CELNegation extends CELExpression {
type: "Negation";
negations: number;
value: CELPrimary;
}
interface CELNegative extends CELExpression {
type: "Negative";
negatives: number;
value: CELMember;
}
interface CELMember extends CELExpression {
type: "Member";
value?: CELPrimary;
left?: CELPrimary | CELMember;
right?: CELIdentifier;
list?: CELExpressionList;
}
interface CELMemberIdentifierChain extends CELMember {
type: "Member";
value: never;
left: CELMemberIdentifierChain;
right: CELIdentifier;
list: never;
}
interface CELMemberNegatedIdentifier extends CELNegation {
value: CELIdentifier;
}
interface CELMemberNegatedIdentifierChain extends CELExpression {
value: never;
left: CELMemberIdentifierChain | CELMemberNegatedIdentifier;
right: CELIdentifier;
list: never;
}
interface CELDynamicPropertyAccessor extends CELExpression {
type: "DynamicPropertyAccessor";
left: CELMember;
right: CELExpression;
}
interface CELProperty extends CELExpression {
type: "Property";
value: CELIdentifier;
args?: CELExpressionList;
trailingComma?: boolean;
}
interface CELFunctionCall extends CELExpression {
type: "FunctionCall";
name: CELIdentifier;
args: CELExpressionList;
trailingComma?: boolean;
}
interface CELExpressionGroup extends CELExpression {
type: "ExpressionGroup";
value: CELExpression;
}
interface CELList extends CELExpression {
type: "List";
value: CELExpressionList;
trailingComma?: boolean;
}
interface CELMap extends CELExpression {
type: "Map";
value: CELMapInits;
trailingComma?: boolean;
}
interface CELAddition extends CELExpression {
type: "Addition";
left: CELExpression;
right: CELExpression;
}
interface CELSubtraction extends CELExpression {
type: "Subtraction";
left: CELExpression;
right: CELExpression;
}
interface CELMultiplication extends CELExpression {
type: "Multiplication";
left: CELExpression;
right: CELExpression;
}
interface CELDivision extends CELExpression {
type: "Division";
left: CELExpression;
right: CELExpression;
}
interface CELModulo extends CELExpression {
type: "Modulo";
left: CELExpression;
right: CELExpression;
}
interface CELConditionalOr extends CELExpression {
type: "ConditionalOr";
left: CELExpression;
right: CELExpression;
}
interface CELConditionalAnd extends CELExpression {
type: "ConditionalAnd";
left: CELExpression;
right: CELExpression;
}
interface CELExpressionList extends CELExpression {
type: "ExpressionList";
value: CELExpression[];
}
interface CELFieldsObject extends CELExpression {
type: "FieldsObject";
left: CELMember;
list: CELFieldInits;
trailingComma?: boolean;
}
interface CELFieldInits extends CELExpression {
type: "FieldInits";
value: CELFieldInit[];
}
interface CELFieldInit extends CELExpression {
type: "FieldInit";
left: CELIdentifier;
right: CELExpression;
}
interface CELMapInits extends CELExpression {
type: "MapInits";
value: CELMapInit[];
}
interface CELMapInit extends CELExpression {
type: "MapInit";
left: CELExpression;
right: CELExpression;
}
interface CELLikeExpression extends CELExpression {
type: "LikeExpression";
left: CELIdentifier | CELMemberIdentifierChain;
right: CELIdentifier<"contains" | "startsWith" | "endsWith">;
list: CELExpressionList & {
value: [CELStringLiteral | CELIdentifier];
};
}
interface CELNegatedLikeExpression extends CELExpression {
type: "LikeExpression";
left: CELMemberNegatedIdentifier | CELMemberNegatedIdentifierChain;
right: CELIdentifier<"contains" | "startsWith" | "endsWith">;
list: CELExpressionList & {
value: [CELStringLiteral | CELIdentifier];
};
}
type CELNumericLiteral = CELIntegerLiteral | CELUnsignedIntegerLiteral | CELFloatLiteral;
type CELLiteral = CELStringLiteral | CELBytesLiteral | CELNumericLiteral | CELBooleanLiteral | CELNullLiteral;
type CELPrimary = CELProperty | CELIdentifier | CELExpressionGroup | CELFunctionCall | CELLiteral | CELList | CELMap;
type CELMathOperation = CELAddition | CELSubtraction | CELMultiplication | CELDivision | CELModulo;
interface ParsedCEL {
nodeType: "Main";
value: CELExpression;
}
//#endregion
//#region src/utils/parseCEL/parseCEL.d.ts
interface ParseCELOptionsStandard extends Except<ParserCommonOptions, "independentCombinators"> {
independentCombinators?: false;
/**
* Handler for custom CEL expressions.
*/
customExpressionHandler?: (expr: CELExpression) => RuleType | RuleGroupType | null;
}
interface ParseCELOptionsIC extends Except<ParserCommonOptions, "independentCombinators"> {
independentCombinators: true;
/**
* Handler for custom CEL expressions.
*/
customExpressionHandler?: (expr: CELExpression) => RuleType | RuleGroupTypeIC | null;
}
/**
* Options object for {@link parseCEL}.
*/
type ParseCELOptions = ParseCELOptionsStandard | ParseCELOptionsIC;
/**
* Converts a CEL string expression into a query suitable for the
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
* ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).
*/
declare function parseCEL(cel: string): DefaultRuleGroupType;
/**
* Converts a CEL string expression into a query suitable for the
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
* ({@link index!RuleGroupType RuleGroupType}).
*/
declare function parseCEL(cel: string, options: ParseCELOptionsStandard & {
customExpressionHandler: (expr: CELExpression) => RuleType | RuleGroupType | null;
}): RuleGroupType;
/**
* Converts a CEL string expression into a query suitable for the
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
* ({@link index!RuleGroupTypeIC RuleGroupTypeIC}).
*/
declare function parseCEL(cel: string, options: ParseCELOptionsIC & {
customExpressionHandler: (expr: CELExpression) => RuleType | RuleGroupTypeIC | null;
}): RuleGroupTypeIC;
/**
* Converts a CEL string expression into a query suitable for the
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
* ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).
*/
declare function parseCEL(cel: string, options?: ParseCELOptionsStandard): DefaultRuleGroupType;
/**
* Converts a CEL string expression into a query suitable for the
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
* ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).
*/
declare function parseCEL(cel: string, options: ParseCELOptionsIC): DefaultRuleGroupTypeIC;
//#endregion
//#region src/utils/parseCEL/utils.d.ts
declare const isCELExpressionGroup: (expr: CELExpression) => expr is CELExpressionGroup;
declare const isCELConditionalAnd: (expr: CELExpression) => expr is CELConditionalAnd;
declare const isCELConditionalOr: (expr: CELExpression) => expr is CELConditionalOr;
declare const isCELStringLiteral: (expr: CELExpression) => expr is CELStringLiteral;
declare const isCELLiteral: (expr: CELExpression) => expr is CELLiteral;
declare const isCELNumericLiteral: (expr: CELExpression) => expr is CELNumericLiteral;
declare const isCELRelation: (expr: CELExpression) => expr is CELRelation;
declare const isCELList: (expr: CELExpression) => expr is CELList;
declare const isCELMap: (expr: CELExpression) => expr is CELMap;
declare const isCELIdentifier: (expr: CELExpression) => expr is CELIdentifier;
declare const isCELNegation: (expr: CELExpression) => expr is CELNegation;
declare const isCELMember: (expr: CELExpression) => expr is CELMember;
declare const isCELAddition: (expr: CELExpression) => expr is CELAddition;
declare const isCELBooleanLiteral: (expr: CELExpression) => expr is CELBooleanLiteral;
declare const isCELBytesLiteral: (expr: CELExpression) => expr is CELBytesLiteral;
declare const isCELConditionalExpr: (expr: CELExpression) => expr is CELConditionalExpr;
declare const isCELDivision: (expr: CELExpression) => expr is CELDivision;
declare const isCELDynamicPropertyAccessor: (expr: CELExpression) => expr is CELDynamicPropertyAccessor;
declare const isCELExpressionList: (expr: CELExpression) => expr is CELExpressionList;
declare const isCELFieldInit: (expr: CELExpression) => expr is CELFieldInit;
declare const isCELFieldInits: (expr: CELExpression) => expr is CELFieldInits;
declare const isCELFieldsObject: (expr: CELExpression) => expr is CELFieldsObject;
declare const isCELFloatLiteral: (expr: CELExpression) => expr is CELFloatLiteral;
declare const isCELFunctionCall: (expr: CELExpression) => expr is CELFunctionCall;
declare const isCELIntegerLiteral: (expr: CELExpression) => expr is CELIntegerLiteral;
declare const isCELMapInit: (expr: CELExpression) => expr is CELMapInit;
declare const isCELMapInits: (expr: CELExpression) => expr is CELMapInits;
declare const isCELModulo: (expr: CELExpression) => expr is CELModulo;
declare const isCELMultiplication: (expr: CELExpression) => expr is CELMultiplication;
declare const isCELNegative: (expr: CELExpression) => expr is CELNegative;
declare const isCELNullLiteral: (expr: CELExpression) => expr is CELNullLiteral;
declare const isCELProperty: (expr: CELExpression) => expr is CELProperty;
declare const isCELSubtraction: (expr: CELExpression) => expr is CELSubtraction;
declare const isCELUnsignedIntegerLiteral: (expr: CELExpression) => expr is CELUnsignedIntegerLiteral;
declare const isCELIdentifierOrChain: (expr: CELExpression) => expr is CELMemberIdentifierChain | CELIdentifier;
declare const isCELNegatedIdentifier: (expr: CELExpression) => expr is CELMemberNegatedIdentifier;
declare const isCELNegatedIdentifierOrChain: (expr: CELExpression) => expr is CELMemberNegatedIdentifierChain | CELMemberNegatedIdentifier;
declare const isCELLikeExpression: (expr: CELExpression) => expr is CELLikeExpression;
declare const isCELNegatedLikeExpression: (expr: CELExpression) => expr is CELNegatedLikeExpression;
declare const getCELIdentifierFromChain: (expr: CELIdentifier | CELMemberIdentifierChain) => string;
declare const getCELIdentifierFromNegatedChain: (expr: CELMemberNegatedIdentifier | CELMemberNegatedIdentifierChain) => string;
declare function evalCELLiteralValue(literal: CELStringLiteral): string;
declare function evalCELLiteralValue(literal: CELBooleanLiteral): boolean;
declare function evalCELLiteralValue(literal: CELNumericLiteral): number | null;
declare function evalCELLiteralValue(literal: CELBytesLiteral): null;
declare function evalCELLiteralValue(literal: CELNullLiteral): null;
declare function evalCELLiteralValue(literal: CELLiteral): string | boolean | number | null;
declare const celNormalizeCombinator: (c: "&&" | "||") => DefaultCombinatorName;
declare const celNormalizeOperator: (op: CELRelop, flip?: boolean) => DefaultOperatorName;
declare const celGenerateFlatAndOrList: (expr: CELConditionalAnd | CELConditionalOr) => (DefaultCombinatorName | CELExpression)[];
declare const celGenerateMixedAndOrList: (expr: CELConditionalAnd | CELConditionalOr) => (DefaultCombinatorName | CELExpression | ("and" | CELExpression)[])[];
//#endregion
export { CELAddition, CELBooleanLiteral, CELBytesLiteral, CELConditionalAnd, CELConditionalExpr, CELConditionalOr, CELDivision, CELDynamicPropertyAccessor, CELExpression, CELExpressionGroup, CELExpressionList, CELExpressionType, CELFieldInit, CELFieldInits, CELFieldsObject, CELFloatLiteral, CELFunctionCall, CELIdentifier, CELIntegerLiteral, CELLikeExpression, CELList, CELLiteral, CELMap, CELMapInit, CELMapInits, CELMathOperation, CELMember, CELMemberIdentifierChain, CELMemberNegatedIdentifier, CELMemberNegatedIdentifierChain, CELModulo, CELMultiplication, CELNegatedLikeExpression, CELNegation, CELNegative, CELNullLiteral, CELNumericLiteral, CELPrimary, CELProperty, CELRelation, CELRelop, CELStringLiteral, CELSubtraction, CELUnsignedIntegerLiteral, ParseCELOptions, ParseCELOptionsIC, ParseCELOptionsStandard, ParsedCEL, celGenerateFlatAndOrList, celGenerateMixedAndOrList, celNormalizeCombinator, celNormalizeOperator, evalCELLiteralValue, getCELIdentifierFromChain, getCELIdentifierFromNegatedChain, isCELAddition, isCELBooleanLiteral, isCELBytesLiteral, isCELConditionalAnd, isCELConditionalExpr, isCELConditionalOr, isCELDivision, isCELDynamicPropertyAccessor, isCELExpressionGroup, isCELExpressionList, isCELFieldInit, isCELFieldInits, isCELFieldsObject, isCELFloatLiteral, isCELFunctionCall, isCELIdentifier, isCELIdentifierOrChain, isCELIntegerLiteral, isCELLikeExpression, isCELList, isCELLiteral, isCELMap, isCELMapInit, isCELMapInits, isCELMember, isCELModulo, isCELMultiplication, isCELNegatedIdentifier, isCELNegatedIdentifierOrChain, isCELNegatedLikeExpression, isCELNegation, isCELNegative, isCELNullLiteral, isCELNumericLiteral, isCELProperty, isCELRelation, isCELStringLiteral, isCELSubtraction, isCELUnsignedIntegerLiteral, parseCEL };
//# sourceMappingURL=parseCEL.d.ts.map