UNPKG

@react-querybuilder/core

Version:

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

2,295 lines (2,291 loc) 41.1 kB
import { l as defaultOperatorNegationMap } from "./optGroupUtils-VeZ3k7-1.mjs"; import { t as joinWith } from "./arrayUtils-A_OXU9W1.mjs"; import { t as isRuleGroup } from "./isRuleGroup-CYcfPgbg.mjs"; import { n as fieldIsValidUtil, r as getFieldsArray, t as prepareRuleGroup } from "./prepareQueryObjects-DPCC-iHp.mjs"; import { JisonParser } from "@ts-jison/parser"; import { JisonLexer } from "@ts-jison/lexer"; //#region src/utils/parseCEL/celParser.ts /** * parser generated by @ts-jison/parser-generator 0.4.1-alpha.2 * @returns Parser implementing JisonParserApi and a Lexer implementing JisonLexerApi. */ var CELParser = class extends JisonParser { $; symbols_ = { "error": 2, "main": 3, "expr": 4, "EOF": 5, "string_literal": 6, "STRING_LIT": 7, "bytes_literal": 8, "b": 9, "B": 10, "number_literal": 11, "INT_LIT": 12, "UINT_LIT": 13, "FLOAT_LIT": 14, "boolean_literal": 15, "BOOL_LIT": 16, "null_literal": 17, "NULL_LIT": 18, "literal": 19, "ident": 20, "IDENT": 21, "relop": 22, "==": 23, ">=": 24, ">": 25, "<=": 26, "<": 27, "!=": 28, "relation": 29, "member": 30, "in": 31, "list": 32, "map": 33, "negation": 34, "!": 35, "negative": 36, "-": 37, "unary": 38, "primary": 39, "DOT": 40, "(": 41, "expr_list": 42, ")": 43, "[": 44, "]": 45, "{": 46, "field_inits": 47, "trailing_comma": 48, "}": 49, ",": 50, "map_inits": 51, "math_operation": 52, "+": 53, "*": 54, "/": 55, "%": 56, "conditional_expr": 57, "conditional_and": 58, "conditional_or": 59, "?": 60, ":": 61, "&&": 62, "||": 63, "$accept": 0, "$end": 1 }; terminals_ = { 2: "error", 5: "EOF", 7: "STRING_LIT", 9: "b", 10: "B", 12: "INT_LIT", 13: "UINT_LIT", 14: "FLOAT_LIT", 16: "BOOL_LIT", 18: "NULL_LIT", 21: "IDENT", 23: "==", 24: ">=", 25: ">", 26: "<=", 27: "<", 28: "!=", 31: "in", 35: "!", 37: "-", 40: "DOT", 41: "(", 43: ")", 44: "[", 45: "]", 46: "{", 49: "}", 50: ",", 53: "+", 54: "*", 55: "/", 56: "%", 60: "?", 61: ":", 62: "&&", 63: "||" }; productions_ = [ 0, [3, 2], [6, 1], [8, 2], [8, 2], [11, 1], [11, 1], [11, 1], [15, 1], [17, 1], [19, 1], [19, 1], [19, 1], [19, 1], [19, 1], [20, 1], [22, 1], [22, 1], [22, 1], [22, 1], [22, 1], [22, 1], [29, 3], [29, 3], [29, 3], [34, 1], [34, 2], [36, 1], [36, 2], [38, 2], [30, 1], [30, 1], [30, 3], [30, 6], [30, 4], [30, 5], [48, 0], [48, 1], [39, 1], [39, 2], [39, 5], [39, 6], [39, 3], [39, 1], [39, 1], [39, 1], [32, 4], [33, 4], [52, 3], [52, 3], [52, 3], [52, 3], [52, 3], [4, 1], [4, 1], [4, 1], [4, 1], [4, 1], [4, 1], [57, 5], [58, 3], [59, 3], [42, 1], [42, 3], [47, 3], [47, 5], [51, 3], [51, 5] ]; table; defaultActions = { 35: [2, 1] }; constructor(yy = {}, lexer = new CELLexer(yy)) { super(yy, lexer); const $V0 = [1, 27], $V1 = [1, 31], $V2 = [1, 32], $V3 = [1, 28], $V4 = [1, 29], $V5 = [1, 30], $V6 = [1, 33], $V7 = [1, 34], $V8 = [1, 18], $V9 = [1, 26], $Va = [1, 12], $Vb = [1, 13], $Vc = [1, 19], $Vd = [1, 20], $Ve = [1, 40], $Vf = [1, 39], $Vg = [1, 41], $Vh = [1, 42], $Vi = [1, 43], $Vj = [1, 36], $Vk = [1, 37], $Vl = [1, 38], $Vm = [ 5, 37, 43, 45, 49, 50, 53, 54, 55, 56, 60, 61, 62, 63 ], $Vn = [1, 44], $Vo = [1, 45], $Vp = [1, 46], $Vq = [ 5, 23, 24, 25, 26, 27, 28, 31, 37, 40, 43, 44, 45, 46, 49, 50, 53, 54, 55, 56, 60, 61, 62, 63 ], $Vr = [ 7, 9, 10, 12, 13, 14, 16, 18, 21, 35, 40, 41, 44, 46 ], $Vs = [2, 36], $Vt = [1, 85], $Vu = [ 43, 45, 50 ], $Vv = [ 5, 37, 43, 45, 49, 50, 53, 61, 62, 63 ], $Vw = [ 5, 37, 43, 45, 49, 50, 53, 54, 55, 56, 61, 62, 63 ], $Vx = [2, 37], $Vy = [49, 50]; const o = JisonParser.expandParseTable; this.table = [ { 3: 1, 4: 2, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 1: [3] }, { 5: [1, 35], 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }, o($Vm, [2, 53], { 22: 47, 23: [1, 49], 24: [1, 50], 25: [1, 51], 26: [1, 52], 27: [1, 53], 28: [1, 54], 31: [1, 48], 40: $Vn, 44: $Vo, 46: $Vp }), o($Vm, [2, 54]), o($Vm, [2, 55]), o($Vm, [2, 56]), o($Vm, [2, 57]), o($Vm, [2, 58]), o($Vq, [2, 30]), o($Vq, [2, 31]), o($Vq, [2, 38], { 41: [1, 55] }), { 20: 56, 21: $V8 }, { 4: 57, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 43]), o($Vq, [2, 44]), o($Vq, [2, 45]), { 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 32: 14, 33: 15, 35: [1, 59], 39: 58, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd }, o([ 5, 23, 24, 25, 26, 27, 28, 31, 37, 40, 41, 43, 44, 45, 46, 49, 50, 53, 54, 55, 56, 60, 61, 62, 63 ], [2, 15]), { 4: 61, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 42: 60, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 63, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 51: 62, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 10]), o($Vq, [2, 11]), o($Vq, [2, 12]), o($Vq, [2, 13]), o($Vq, [2, 14]), o($Vr, [2, 25]), o($Vq, [2, 2]), o($Vq, [2, 5]), o($Vq, [2, 6]), o($Vq, [2, 7]), { 6: 64, 7: $V0 }, { 6: 65, 7: $V0 }, o($Vq, [2, 8]), o($Vq, [2, 9]), { 1: [2, 1] }, { 4: 66, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 67, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 68, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 69, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 70, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 71, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 72, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 73, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 20: 74, 21: $V8 }, { 4: 75, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 20: 77, 21: $V8, 47: 76 }, { 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 30: 78, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd }, { 32: 79, 33: 80, 44: $Vc, 46: $Vd }, o($Vr, [2, 16]), o($Vr, [2, 17]), o($Vr, [2, 18]), o($Vr, [2, 19]), o($Vr, [2, 20]), o($Vr, [2, 21]), { 4: 61, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 42: 81, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 39], { 41: [1, 82] }), { 37: $Ve, 43: [1, 83], 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }, o($Vq, [2, 29]), o($Vr, [2, 26]), { 45: $Vs, 48: 84, 50: $Vt }, o($Vu, [2, 62], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }), { 48: 86, 49: $Vs, 50: [1, 87] }, { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 61: [1, 88], 62: $Vk, 63: $Vl }, o($Vq, [2, 3]), o($Vq, [2, 4]), { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 61: [1, 89], 62: $Vk, 63: $Vl }, o([ 5, 43, 45, 49, 50, 61, 62, 63 ], [2, 60], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj }), o([ 5, 43, 45, 49, 50, 61, 63 ], [2, 61], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk }), o($Vv, [2, 48], { 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj }), o($Vv, [2, 49], { 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj }), o($Vw, [2, 50], { 60: $Vj }), o($Vw, [2, 51], { 60: $Vj }), o($Vw, [2, 52], { 60: $Vj }), o($Vq, [2, 32], { 41: [1, 90] }), { 37: $Ve, 45: [1, 91], 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }, { 48: 92, 49: $Vs, 50: [1, 93] }, { 61: [1, 94] }, o($Vm, [2, 22], { 40: $Vn, 44: $Vo, 46: $Vp }), o($Vm, [2, 23]), o($Vm, [2, 24]), { 43: $Vs, 48: 95, 50: $Vt }, { 4: 61, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 42: 96, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 42]), { 45: [1, 97] }, o([43, 45], $Vx, { 30: 3, 57: 4, 58: 5, 59: 6, 29: 7, 52: 8, 39: 9, 38: 10, 20: 11, 32: 14, 33: 15, 19: 16, 34: 17, 6: 21, 11: 22, 8: 23, 15: 24, 17: 25, 4: 98, 7: $V0, 9: $V1, 10: $V2, 12: $V3, 13: $V4, 14: $V5, 16: $V6, 18: $V7, 21: $V8, 35: $V9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd }), { 49: [1, 99] }, { 4: 100, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 49: $Vx, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 101, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 102, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 61, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 42: 103, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 34]), { 49: [1, 104] }, { 20: 105, 21: $V8, 49: $Vx }, { 4: 106, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 43: [1, 107] }, { 43: $Vs, 48: 108, 50: $Vt }, o($Vq, [2, 46]), o($Vu, [2, 63], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }), o($Vq, [2, 47]), { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 61: [1, 109], 62: $Vk, 63: $Vl }, o($Vy, [2, 66], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }), o($Vm, [2, 59]), { 43: [1, 110], 50: [1, 111] }, o($Vq, [2, 35]), { 61: [1, 112] }, o($Vy, [2, 64], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }), o($Vq, [2, 40]), { 43: [1, 113] }, { 4: 114, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 33]), { 4: 98, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, { 4: 115, 6: 21, 7: $V0, 8: 23, 9: $V1, 10: $V2, 11: 22, 12: $V3, 13: $V4, 14: $V5, 15: 24, 16: $V6, 17: 25, 18: $V7, 19: 16, 20: 11, 21: $V8, 29: 7, 30: 3, 32: 14, 33: 15, 34: 17, 35: $V9, 38: 10, 39: 9, 40: $Va, 41: $Vb, 44: $Vc, 46: $Vd, 52: 8, 57: 4, 58: 5, 59: 6 }, o($Vq, [2, 41]), o($Vy, [2, 67], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }), o($Vy, [2, 65], { 37: $Ve, 53: $Vf, 54: $Vg, 55: $Vh, 56: $Vi, 60: $Vj, 62: $Vk, 63: $Vl }) ]; } performAction(yytext, yyleng, yylineno, yy, yystate, $$, _$) { var $0 = $$.length - 1; switch (yystate) { case 1: return { nodeType: "Main", value: $$[$0 - 1] }; case 2: this.$ = { type: "StringLiteral", value: $$[$0] }; break; case 3: case 4: this.$ = { type: "BytesLiteral", value: $$[$0] }; break; case 5: this.$ = { type: "IntegerLiteral", value: parseInt($$[$0], /x/.test($$[$0]) ? 16 : 10) }; break; case 6: this.$ = { type: "UnsignedIntegerLiteral", value: parseInt($$[$0].replace(/u$/i, ""), /^0x/.test($$[$0]) ? 16 : 10) }; break; case 7: this.$ = { type: "FloatLiteral", value: parseFloat($$[$0]) }; break; case 8: this.$ = { type: "BooleanLiteral", value: $$[$0] === "true" }; break; case 9: this.$ = { type: "NullLiteral", value: null }; break; case 10: case 11: case 12: case 13: case 14: case 16: case 17: case 18: case 19: case 20: case 21: case 38: case 43: case 44: case 45: case 53: case 54: case 55: case 56: case 57: case 58: this.$ = $$[$0]; break; case 15: this.$ = { type: "Identifier", value: $$[$0] }; break; case 22: case 23: case 24: this.$ = { type: "Relation", left: $$[$0 - 2], operator: $$[$0 - 1], right: $$[$0] }; break; case 25: case 27: this.$ = 1; break; case 26: case 28: this.$ = this.$ += 1; break; case 29: this.$ = { type: "Negation", negations: $$[$0 - 1], value: $$[$0] }; break; case 30: case 31: this.$ = $$[$0]; break; case 32: this.$ = { type: "Member", left: $$[$0 - 2], right: $$[$0] }; break; case 33: this.$ = { type: "Member", left: $$[$0 - 5], right: $$[$0 - 3], list: $$[$0 - 1] }; break; case 34: this.$ = { type: "DynamicPropertyAccessor", left: $$[$0 - 3], right: $$[$0 - 1] }; break; case 35: this.$ = { type: "FieldsObject", left: $$[$0 - 4], list: $$[$0 - 2], trailingComma: $$[$0 - 1] }; break; case 36: this.$ = false; break; case 37: this.$ = true; break; case 39: this.$ = { type: "Property", value: $$[$0] }; break; case 40: this.$ = { type: "FunctionCall", name: $$[$0 - 4], args: $$[$0 - 2], trailingComma: $$[$0 - 1] }; break; case 41: this.$ = { type: "Property", value: $$[$0 - 4], args: $$[$0 - 2], trailingComma: $$[$0 - 1] }; break; case 42: this.$ = { type: "ExpressionGroup", value: $$[$0 - 1] }; break; case 46: this.$ = { type: "List", value: $$[$0 - 2], trailingComma: $$[$0 - 1] }; break; case 47: this.$ = { type: "Map", value: $$[$0 - 2], trailingComma: $$[$0 - 1] }; break; case 48: this.$ = { type: "Addition", left: $$[$0 - 2], right: $$[$0] }; break; case 49: this.$ = { type: "Subtraction", left: $$[$0 - 2], right: $$[$0] }; break; case 50: this.$ = { type: "Multiplication", left: $$[$0 - 2], right: $$[$0] }; break; case 51: this.$ = { type: "Division", left: $$[$0 - 2], right: $$[$0] }; break; case 52: this.$ = { type: "Modulo", left: $$[$0 - 2], right: $$[$0] }; break; case 59: this.$ = { type: "ConditionalExpr", condition: $$[$0 - 4], valueIfTrue: $$[$0 - 2], valueIfFalse: $$[$0] }; break; case 60: this.$ = { type: "ConditionalAnd", left: $$[$0 - 2], right: $$[$0] }; break; case 61: this.$ = { type: "ConditionalOr", left: $$[$0 - 2], right: $$[$0] }; break; case 62: this.$ = { type: "ExpressionList", value: [$$[$0]] }; break; case 63: this.$ = $$[$0 - 2]; this.$.value.push($$[$0]); break; case 64: this.$ = { type: "FieldInits", value: [{ type: "FieldInit", left: $$[$0 - 2], right: $$[$0] }] }; break; case 65: this.$ = $$[$0 - 4]; this.$.value.push({ type: "FieldInit", left: $$[$0 - 2], right: $$[$0] }); break; case 66: this.$ = { type: "MapInits", value: [{ type: "MapInit", left: $$[$0 - 2], right: $$[$0] }] }; break; case 67: this.$ = $$[$0 - 4]; this.$.value.push({ type: "MapInit", left: $$[$0 - 2], right: $$[$0] }); break; } } }; var CELLexer = class extends JisonLexer { options = { "flex": true, "moduleName": "CEL" }; constructor(yy = {}) { super(yy); } rules = [ /^(?:[/][/]\s.*\n)/, /^(?:\s+)/, /^(?:in)/, /^(?:as)/, /^(?:break)/, /^(?:const)/, /^(?:continue)/, /^(?:else)/, /^(?:for)/, /^(?:function)/, /^(?:if)/, /^(?:import)/, /^(?:let)/, /^(?:loop)/, /^(?:package)/, /^(?:namespace)/, /^(?:return)/, /^(?:var)/, /^(?:void)/, /^(?:while)/, /^(?:null)/, /^(?:true)/, /^(?:false)/, /^(?:\.)/, /^(?:\?)/, /^(?::)/, /^(?:,)/, /^(?:\[)/, /^(?:\])/, /^(?:\()/, /^(?:\))/, /^(?:!=)/, /^(?:!)/, /^(?:\+)/, /^(?:-)/, /^(?:\*)/, /^(?:\/)/, /^(?:%)/, /^(?:==)/, /^(?:>=)/, /^(?:>)/, /^(?:<=)/, /^(?:<)/, /^(?:\{)/, /^(?:\})/, /^(?:&&)/, /^(?:\|\|)/, /^(?:[_a-zA-Z][_a-zA-Z0-9]*)/, /^(?:[rR]?['][']['](?:\.|[^'])*['][']['])/, /^(?:[rR]?["]["]["](?:\.|[^"])*["]["]["])/, /^(?:[rR]?['](?:\.|[^'\n\r])*['])/, /^(?:[rR]?["](?:\.|[^"\n\r])*["])/, /^(?:[-]?(?:[0-9]+|0x[0-9a-fA-F]+))/, /^(?:(?:[0-9]+|0x[0-9a-fA-F]+)[uU])/, /^(?:[-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+(?:\.[0-9]+)?)?)/, /^(?:$)/, /^(?:.)/, /^(?:.)/ ]; conditions = { "INITIAL": { "rules": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ], "inclusive": true } }; performAction(yy, yy_, $avoiding_name_collisions, YY_START) { switch ($avoiding_name_collisions) { case 0: break; case 1: break; case 2: return 31; case 3: return "as"; case 4: return "break"; case 5: return "const"; case 6: return "continue"; case 7: return "else"; case 8: return "for"; case 9: return "function"; case 10: return "if"; case 11: return "import"; case 12: return "let"; case 13: return "loop"; case 14: return "package"; case 15: return "namespace"; case 16: return "return"; case 17: return "var"; case 18: return "void"; case 19: return "while"; case 20: return 18; case 21: return 16; case 22: return 16; case 23: return 40; case 24: return 60; case 25: return 61; case 26: return 50; case 27: return 44; case 28: return 45; case 29: return 41; case 30: return 43; case 31: return 28; case 32: return 35; case 33: return 53; case 34: return 37; case 35: return 54; case 36: return 55; case 37: return 56; case 38: return 23; case 39: return 24; case 40: return 25; case 41: return 26; case 42: return 27; case 43: return 46; case 44: return 49; case 45: return 62; case 46: return 63; case 47: return 21; case 48: return 7; case 49: return 7; case 50: return 7; case 51: return 7; case 52: return 12; case 53: return 13; case 54: return 14; case 55: return 5; case 56: return "INVALID"; case 57: console.log(yy_.yytext); break; } } }; //#endregion //#region src/utils/parseCEL/utils.ts const isCELExpressionGroup = (expr) => expr.type === "ExpressionGroup"; const isCELConditionalAnd = (expr) => expr.type === "ConditionalAnd"; const isCELConditionalOr = (expr) => expr.type === "ConditionalOr"; const isCELStringLiteral = (expr) => expr.type === "StringLiteral"; const isCELLiteral = (expr) => isCELNumericLiteral(expr) || isCELStringLiteral(expr) || isCELBooleanLiteral(expr) || isCELNullLiteral(expr) || isCELBytesLiteral(expr); const isCELNumericLiteral = (expr) => isCELFloatLiteral(expr) || isCELIntegerLiteral(expr) || isCELUnsignedIntegerLiteral(expr); const isCELRelation = (expr) => expr.type === "Relation"; const isCELList = (expr) => expr.type === "List"; const isCELMap = (expr) => expr.type === "Map"; const isCELIdentifier = (expr) => expr.type === "Identifier"; const isCELNegation = (expr) => expr.type === "Negation"; const isCELMember = (expr) => expr.type === "Member"; // istanbul ignore next const isCELAddition = (expr) => expr.type === "Addition"; const isCELBooleanLiteral = (expr) => expr.type === "BooleanLiteral"; const isCELBytesLiteral = (expr) => expr.type === "BytesLiteral"; // istanbul ignore next const isCELConditionalExpr = (expr) => expr.type === "ConditionalExpr"; // istanbul ignore next const isCELDivision = (expr) => expr.type === "Division"; // istanbul ignore next const isCELDynamicPropertyAccessor = (expr) => expr.type === "DynamicPropertyAccessor"; // istanbul ignore next const isCELExpressionList = (expr) => expr.type === "ExpressionList"; // istanbul ignore next const isCELFieldInit = (expr) => expr.type === "FieldInit"; // istanbul ignore next const isCELFieldInits = (expr) => expr.type === "FieldInits"; // istanbul ignore next const isCELFieldsObject = (expr) => expr.type === "FieldsObject"; const isCELFloatLiteral = (expr) => expr.type === "FloatLiteral"; // istanbul ignore next const isCELFunctionCall = (expr) => expr.type === "FunctionCall"; const isCELIntegerLiteral = (expr) => expr.type === "IntegerLiteral"; // istanbul ignore next const isCELMapInit = (expr) => expr.type === "MapInit"; // istanbul ignore next const isCELMapInits = (expr) => expr.type === "MapInits"; // istanbul ignore next const isCELModulo = (expr) => expr.type === "Modulo"; // istanbul ignore next const isCELMultiplication = (expr) => expr.type === "Multiplication"; // istanbul ignore next const isCELNegative = (expr) => expr.type === "Negative"; const isCELNullLiteral = (expr) => expr.type === "NullLiteral"; // istanbul ignore next const isCELProperty = (expr) => expr.type === "Property"; // istanbul ignore next const isCELSubtraction = (expr) => expr.type === "Subtraction"; const isCELUnsignedIntegerLiteral = (expr) => expr.type === "UnsignedIntegerLiteral"; const isCELIdentifierOrChain = (expr) => isCELIdentifier(expr) || isCELMember(expr) && !!expr.left && !!expr.right && !expr.list && !expr.value && isCELIdentifierOrChain(expr.left) && isCELIdentifier(expr.right); const isCELNegatedIdentifier = (expr) => isCELNegation(expr) && isCELIdentifier(expr.value); const isCELNegatedIdentifierOrChain = (expr) => isCELNegatedIdentifier(expr) || isCELMember(expr) && !!expr.left && !!expr.right && !expr.list && !expr.value && isCELIdentifierOrChain(expr.right) && isCELNegatedIdentifier(expr.left); const isCELLikeExpression = (expr) => isCELMember(expr) && !!expr.left && !!expr.right && !!expr.list && isCELIdentifierOrChain(expr.left) && isCELIdentifier(expr.right) && (expr.right.value === "contains" || expr.right.value === "startsWith" || expr.right.value === "endsWith") && expr.list.value.length === 1 && (isCELStringLiteral(expr.list.value[0]) || isCELIdentifier(expr.list.value[0])); const isCELNegatedLikeExpression = (expr) => isCELMember(expr) && !!expr.left && !!expr.right && !!expr.list && isCELNegatedIdentifierOrChain(expr.left) && isCELIdentifier(expr.right) && (expr.right.value === "contains" || expr.right.value === "startsWith" || expr.right.value === "endsWith") && expr.list.value.length === 1 && (isCELStringLiteral(expr.list.value[0]) || isCELIdentifier(expr.list.value[0])); const getCELIdentifierFromChain = (expr) => { if (isCELIdentifier(expr)) return expr.value; return `${getCELIdentifierFromChain(expr.left)}.${expr.right.value}`; }; const getCELIdentifierFromNegatedChain = (expr) => { if (isCELNegatedIdentifier(expr)) return `${``.padStart(expr.negations, `!`)}${expr.value.value}`; return `${getCELIdentifierFromNegatedChain(expr.left)}.${expr.right.value}`; }; function evalCELLiteralValue(literal) { switch (literal.type) { case "StringLiteral": return literal.value.replaceAll(/^((?:'''|"""|'|")?)([\S\s]*?)\1$/gm, "$2"); case "BooleanLiteral": return literal.value; case "NullLiteral": case "BytesLiteral": return null; default: return literal.value; } } const celNormalizeCombinator = (c) => c === "||" ? "or" : "and"; const celNormalizeOperator = (op, flip) => { if (flip) { if (op === "<") return ">"; if (op === "<=") return ">="; if (op === ">") return "<"; if (op === ">=") return "<="; } if (op === "==") return "="; return op; }; const celGenerateFlatAndOrList = (expr) => { const combinator = celNormalizeCombinator(expr.type === "ConditionalAnd" ? "&&" : "||"); const { left, right } = expr; if (isCELConditionalAnd(left) || isCELConditionalOr(left)) return [ ...celGenerateFlatAndOrList(left), combinator, right ]; return [ left, combinator, right ]; }; const celGenerateMixedAndOrList = (expr) => { const arr = celGenerateFlatAndOrList(expr); const returnArray = []; let startIndex = 0; for (let i = 0; i < arr.length; i += 2) if (arr[i + 1] === "and") { startIndex = i; let j = 1; while (arr[startIndex + j] === "and") { i += 2; j += 2; } const tempAndArray = arr.slice(startIndex, i + 1); returnArray.push(tempAndArray); i -= 2; } else if (arr[i + 1] === "or") if (i === 0 || i === arr.length - 3) { if (i === 0 || arr[i - 1] === "or") returnArray.push(arr[i]); returnArray.push(arr[i + 1]); if (i === arr.length - 3) returnArray.push(arr[i + 2]); } else if (arr[i - 1] === "and") returnArray.push(arr[i + 1]); else returnArray.push(arr[i], arr[i + 1]); if (returnArray.length === 1 && Array.isArray(returnArray[0])) return returnArray[0]; return returnArray; }; //#endregion //#region src/utils/parseCEL/parseCEL.ts function parseCEL(cel, options = {}) { const { fields, independentCombinators, listsAsArrays, customExpressionHandler } = options; const ic = !!independentCombinators; const fieldsFlat = getFieldsArray(fields); const fieldIsValid = (fieldName, operator, subordinateFieldName) => fieldIsValidUtil({ fieldName, fieldsFlat, operator, subordinateFieldName, getValueSources: options?.getValueSources }); const emptyQuery = { rules: [], ...ic ? {} : { combinator: "and" } }; const processCELExpression = (expr, processOpts = {}) => { const { forwardNegation: forwardedNegation, groupOnlyIfNecessary } = processOpts; /* istanbul ignore if */ if (isCELNegation(expr) || isCELNegatedLikeExpression(expr)) { const negate = isCELNegation(expr) ? expr.negations % 2 === 1 : (getCELIdentifierFromNegatedChain(expr.left).match(/^!+/)?.[0].length ?? 0) % 2 === 1; const negatedExpr = isCELNegation(expr) && isCELExpressionGroup(expr.value) && isCELLikeExpression(expr.value.value) ? processCELExpression(expr.value.value, { forwardNegation: negate }) : isCELNegatedLikeExpression(expr) ? processCELExpression({ ...expr, left: { type: "Identifier", value: getCELIdentifierFromNegatedChain(expr.left).replace(/^!+/, "") } }, { forwardNegation: negate }) : isCELNegation(expr) && isCELExpressionGroup(expr.value) && isCELRelation(expr.value.value) ? processCELExpression(expr.value.value, { forwardNegation: negate }) : processCELExpression(expr.value, { groupOnlyIfNecessary: true, forwardNegation: negate }); if (negatedExpr) { if (isCELNegatedLikeExpression(expr) || isCELNegation(expr) && isCELExpressionGroup(expr.value) && isCELRelation(expr.value.value)) return negatedExpr; else if (!negate || negate && !isRuleGroup(negatedExpr) && negatedExpr.operator.startsWith("doesNot")) return ic ? { rules: [negatedExpr] } : { combinator: "and", rules: [negatedExpr] }; return ic ? { rules: [negatedExpr], not: true } : { combinator: "and", rules: [negatedExpr], not: true }; } } else if (isCELExpressionGroup(expr)) { const rule = processCELExpression(expr.value, { groupOnlyIfNecessary: true }); if (rule) { if (isRuleGroup(rule) || groupOnlyIfNecessary && isCELExpressionGroup(expr.value)) return rule; return ic ? { rules: [rule] } : { combinator: "and", rules: [rule] }; } } else if (isCELConditionalAnd(expr) || isCELConditionalOr(expr)) { if (ic) { const rules$1 = celGenerateFlatAndOrList(expr).map((v) => { if (typeof v === "string") return v; return processCELExpression(v); }); if (!rules$1.every(Boolean)) return null; return { rules: rules$1 }; } const andOrList = celGenerateMixedAndOrList(expr); const combinator = andOrList[1]; const rules = andOrList.filter((v) => Array.isArray(v) || !!v && typeof v !== "string" && "type" in v).map((v) => Array.isArray(v) ? v.filter((vf) => !!v && typeof vf !== "string" && "type" in vf) : v).map((exp) => { if (Array.isArray(exp)) return { combinator: "and", rules: exp.map((e) => processCELExpression(e)).filter(Boolean) }; return processCELExpression(exp); }).filter(Boolean); /* istanbul ignore else */ if (rules.length > 0) return { combinator, rules }; } else if (isCELLikeExpression(expr)) { const field = getCELIdentifierFromChain(expr.left); const func = expr.right.value; const operatorPre = func === "startsWith" ? "beginsWith" : func; const operator = forwardedNegation ? `doesNot${operatorPre[0].toUpperCase()}${operatorPre.slice(1).replace("s", "")}` : operatorPre; const valueObj = expr.list.value[0]; const value = isCELStringLiteral(valueObj) ? evalCELLiteralValue(valueObj) : valueObj.value; const valueSource = expr.list.value[0].type === "Identifier" ? "field" : void 0; if (fieldIsValid(field, operator, valueSource === "field" ? value : void 0)) return valueSource ? { field, operator, value, valueSource } : { field, operator, value }; } else if (isCELRelation(expr)) { let field = null; let value = void 0; let valueSource = void 0; let flip = false; const { left, right } = expr; if (isCELIdentifierOrChain(left)) { field = getCELIdentifierFromChain(left); if (isCELIdentifierOrChain(right)) { value = getCELIdentifierFromChain(right); valueSource = "field"; } else if (isCELLiteral(right)) value = evalCELLiteralValue(right); } else if (isCELIdentifierOrChain(right) && isCELLiteral(left) && expr.operator !== "in") { flip = true; field = getCELIdentifierFromChain(right); value = evalCELLiteralValue(left); } let operator = celNormalizeOperator(expr.operator, flip); if (forwardedNegation) operator = defaultOperatorNegationMap[operator]; if (value === null && (operator === "=" || operator === "!=")) operator = operator === "=" ? "null" : "notNull"; else if ((operator === "in" || operator === "notIn") && isCELList(right)) { if (right.value.value.every((v) => isCELLiteral(v))) value = right.value.value.map((v) => evalCELLiteralValue(v)); else if (right.value.value.every((v) => isCELIdentifierOrChain(v))) { valueSource = "field"; value = right.value.value.map((id) => getCELIdentifierFromChain(id)); } if (value && !listsAsArrays) value = joinWith(value.map((v) => `${v}`), ","); } else if ((operator === "in" || operator === "notIn") && isCELMap(right)) { const keys = right.value.value.map((v) => v.left); if (keys.every((k) => isCELLiteral(k) || isCELIdentifierOrChain(k))) value = keys.map((k) => isCELLiteral(k) ? evalCELLiteralValue(k) : getCELIdentifierFromChain(k)); if (value && !listsAsArrays) value = joinWith(value.map((v) => `${v}`), ","); } if (field && fieldIsValid(field, operator, valueSource === "field" ? value : void 0) && value !== void 0) return valueSource ? { field, operator, value, valueSource } : { field, operator, value }; } else if (customExpressionHandler) return customExpressionHandler(expr); return null; }; const prepare = options.generateIDs ? prepareRuleGroup : (g) => g; const celParser = new CELParser(); let processedCEL; try { processedCEL = celParser.parse(cel).value; } catch { return prepare(emptyQuery); } const result = processCELExpression(processedCEL); if (result) { if (isRuleGroup(result)) return prepare(result); return prepare({ rules: [result], ...ic ? {} : { combinator: "and" } }); } return prepare(emptyQuery); } //#endregion export { 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.mjs.map