{"version":3,"file":"defaultRuleGroupProcessorCEL.mjs","names":[],"sources":["../../../src/utils/formatQuery/defaultRuleGroupProcessorCEL.ts"],"sourcesContent":["import type { DefaultCombinatorName, RuleGroupProcessor, RuleGroupTypeAny } from '../../types';\nimport { isRuleGroup, isRuleGroupType } from '../isRuleGroup';\nimport { isRuleOrGroupValid } from '../isRuleOrGroupValid';\nimport { getOption } from '../optGroupUtils';\nimport { celCombinatorMap } from './utils';\n\n/**\n * Rule group processor used by {@link formatQuery} for \"cel\" format.\n *\n * @group Export\n */\nexport const defaultRuleGroupProcessorCEL: RuleGroupProcessor<string> = (ruleGroup, options) => {\n  const {\n    fields,\n    fallbackExpression,\n    getParseNumberBoolean,\n    placeholderFieldName,\n    placeholderOperatorName,\n    placeholderValueName,\n    ruleProcessor,\n    validateRule,\n    validationMap,\n  } = options;\n\n  const processRuleGroup = (rg: RuleGroupTypeAny, outermost?: boolean): string => {\n    if (\n      !isRuleOrGroupValid(\n        rg,\n        validationMap[\n          rg.id ?? /* v8 ignore start -- @preserve */ '' /* v8 ignore stop -- @preserve */\n        ]\n      )\n    ) {\n      return outermost ? fallbackExpression : '';\n    }\n\n    const processedRules = [];\n    let precedingCombinator = '';\n    let firstRule = true;\n\n    for (const rule of rg.rules) {\n      // Independent combinators\n      if (typeof rule === 'string') {\n        precedingCombinator = celCombinatorMap[rule as DefaultCombinatorName];\n        continue;\n      }\n\n      // Groups\n      if (isRuleGroup(rule)) {\n        const processedGroup = processRuleGroup(rule);\n        if (processedGroup) {\n          if (!firstRule && precedingCombinator) {\n            processedRules.push(precedingCombinator);\n            precedingCombinator = '';\n          }\n          firstRule = false;\n          processedRules.push(processedGroup);\n        }\n        continue;\n      }\n\n      // Rules\n      const [validationResult, fieldValidator] = validateRule(rule);\n      if (\n        !isRuleOrGroupValid(rule, validationResult, fieldValidator) ||\n        rule.field === placeholderFieldName ||\n        rule.operator === placeholderOperatorName ||\n        /* v8 ignore next -- @preserve */\n        (placeholderValueName !== undefined && rule.value === placeholderValueName)\n      ) {\n        continue;\n      }\n\n      const fieldData = getOption(fields, rule.field);\n      const processedRule = ruleProcessor(rule, {\n        ...options,\n        parseNumbers: getParseNumberBoolean(fieldData?.inputType),\n        escapeQuotes: (rule.valueSource ?? 'value') === 'value',\n        fieldData,\n      });\n\n      if (processedRule) {\n        if (!firstRule && precedingCombinator) {\n          processedRules.push(precedingCombinator);\n          precedingCombinator = '';\n        }\n        firstRule = false;\n        processedRules.push(processedRule);\n      }\n    }\n\n    const expression = processedRules.join(\n      isRuleGroupType(rg) ? ` ${celCombinatorMap[rg.combinator as DefaultCombinatorName]} ` : ' '\n    );\n\n    const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? '!' : ''}(`, ')'] : ['', ''];\n\n    return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;\n  };\n\n  return processRuleGroup(ruleGroup, true);\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAa,gCAA4D,WAAW,YAAY;CAC9F,MAAM,EACJ,QACA,oBACA,uBACA,sBACA,yBACA,sBACA,eACA,cACA,kBACE;CAEJ,MAAM,oBAAoB,IAAsB,cAAgC;EAC9E,IACE,CAAC,mBACC,IACA,cACE,GAAG,yCAAyC,GAEhD,GAEA,OAAO,YAAY,qBAAqB;EAG1C,MAAM,iBAAiB,CAAC;EACxB,IAAI,sBAAsB;EAC1B,IAAI,YAAY;EAEhB,KAAK,MAAM,QAAQ,GAAG,OAAO;GAE3B,IAAI,OAAO,SAAS,UAAU;IAC5B,sBAAsB,iBAAiB;IACvC;GACF;GAGA,IAAI,YAAY,IAAI,GAAG;IACrB,MAAM,iBAAiB,iBAAiB,IAAI;IAC5C,IAAI,gBAAgB;KAClB,IAAI,CAAC,aAAa,qBAAqB;MACrC,eAAe,KAAK,mBAAmB;MACvC,sBAAsB;KACxB;KACA,YAAY;KACZ,eAAe,KAAK,cAAc;IACpC;IACA;GACF;GAGA,MAAM,CAAC,kBAAkB,kBAAkB,aAAa,IAAI;GAC5D,IACE,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