UNPKG

react-querybuilder

Version:

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

1 lines 137 kB
import{createContext as Bn}from"react";var yt=Bn({});import{jsx as qn}from"react/jsx-runtime";var Rt=t=>qn("button",{type:"button","data-testid":t.testID,disabled:t.disabled&&!t.disabledTranslation,className:t.className,title:t.disabledTranslation&&t.disabled?t.disabledTranslation.title:t.title,onClick:e=>t.handleOnClick(e),children:t.disabledTranslation&&t.disabled?t.disabledTranslation.label:t.label});import{jsx as jn}from"react/jsx-runtime";import{forwardRef as Wn}from"react";var Xr=Wn((t,e)=>jn("span",{"data-testid":t.testID,ref:e,className:t.className,title:t.title,children:t.label}));var yr="~",Yt="------",wo=yr,Yr=Yt,Zr=Yt,Do=yr,el=Yt,tl=Yt,ol=yr,rl=Yt,ll=Yt,Oo=",",Po={"=":"=","!=":"!=","<":"<",">":">","<=":"<=",">=":">=",contains:"contains",beginsWith:"begins with",endsWith:"ends with",doesNotContain:"does not contain",doesNotBeginWith:"does not begin with",doesNotEndWith:"does not end with",null:"is null",notNull:"is not null",in:"in",notIn:"not in",between:"between",notBetween:"not between"},nl={and:"AND",or:"OR",xor:"XOR"},al=[{name:"=",value:"=",label:"="},{name:"!=",value:"!=",label:"!="},{name:"<",value:"<",label:"<"},{name:">",value:">",label:">"},{name:"<=",value:"<=",label:"<="},{name:">=",value:">=",label:">="},{name:"contains",value:"contains",label:"contains"},{name:"beginsWith",value:"beginsWith",label:"begins with"},{name:"endsWith",value:"endsWith",label:"ends with"},{name:"doesNotContain",value:"doesNotContain",label:"does not contain"},{name:"doesNotBeginWith",value:"doesNotBeginWith",label:"does not begin with"},{name:"doesNotEndWith",value:"doesNotEndWith",label:"does not end with"},{name:"null",value:"null",label:"is null"},{name:"notNull",value:"notNull",label:"is not null"},{name:"in",value:"in",label:"in"},{name:"notIn",value:"notIn",label:"not in"},{name:"between",value:"between",label:"between"},{name:"notBetween",value:"notBetween",label:"not between"}],as={"=":"!=","!=":"=","<":">=","<=":">",">":"<=",">=":"<",beginsWith:"doesNotBeginWith",doesNotBeginWith:"beginsWith",endsWith:"doesNotEndWith",doesNotEndWith:"endsWith",contains:"doesNotContain",doesNotContain:"contains",between:"notBetween",notBetween:"between",in:"notIn",notIn:"in",notNull:"null",null:"notNull"},mt=[{name:"and",value:"and",label:"AND"},{name:"or",value:"or",label:"OR"}],ss=[...mt,{name:"xor",value:"xor",label:"XOR"}],Rr=[{name:"all",value:"all",label:"all"},{name:"some",value:"some",label:"some"},{name:"none",value:"none",label:"none"},{name:"atLeast",value:"atLeast",label:"at least"},{name:"atMost",value:"atMost",label:"at most"},{name:"exactly",value:"exactly",label:"exactly"}],I={queryBuilder:"queryBuilder",ruleGroup:"ruleGroup",header:"ruleGroup-header",body:"ruleGroup-body",combinators:"ruleGroup-combinators",addRule:"ruleGroup-addRule",addGroup:"ruleGroup-addGroup",cloneRule:"rule-cloneRule",cloneGroup:"ruleGroup-cloneGroup",removeGroup:"ruleGroup-remove",notToggle:"ruleGroup-notToggle",rule:"rule",fields:"rule-fields",matchMode:"rule-matchMode",matchThreshold:"rule-matchThreshold",operators:"rule-operators",value:"rule-value",removeRule:"rule-remove",betweenRules:"betweenRules",valid:"queryBuilder-valid",invalid:"queryBuilder-invalid",shiftActions:"shiftActions",dndDragging:"dndDragging",dndOver:"dndOver",dndCopy:"dndCopy",dndGroup:"dndGroup",dragHandle:"queryBuilder-dragHandle",disabled:"queryBuilder-disabled",lockRule:"rule-lock",lockGroup:"ruleGroup-lock",valueSource:"rule-valueSource",valueListItem:"rule-value-list-item",branches:"queryBuilder-branches",justified:"queryBuilder-justified",hasSubQuery:"rule-hasSubQuery"},sl={queryBuilder:"",ruleGroup:"",header:"",body:"",combinators:"",addRule:"",addGroup:"",cloneRule:"",cloneGroup:"",removeGroup:"",notToggle:"",rule:"",fields:"",matchMode:"",matchThreshold:"",operators:"",value:"",removeRule:"",shiftActions:"",dragHandle:"",lockRule:"",lockGroup:"",valueSource:"",actionElement:"",valueSelector:"",betweenRules:"",valid:"",invalid:"",dndDragging:"",dndOver:"",dndGroup:"",dndCopy:"",disabled:"",valueListItem:"",branches:"",hasSubQuery:""},Mo={empty:"empty",invalidCombinator:"invalid combinator",invalidIndependentCombinators:"invalid independent combinators"},W={rule:"rule",ruleGroup:"rule-group",inlineCombinator:"inline-combinator",addGroup:"add-group",removeGroup:"remove-group",cloneGroup:"clone-group",cloneRule:"clone-rule",addRule:"add-rule",removeRule:"remove-rule",combinators:"combinators",fields:"fields",operators:"operators",valueEditor:"value-editor",notToggle:"not-toggle",shiftActions:"shift-actions",dragHandle:"drag-handle",lockRule:"lock-rule",lockGroup:"lock-group",valueSourceSelector:"value-source-selector",matchModeEditor:"match-mode-editor"},Oe={parentPathDisabled:"action aborted: parent path disabled",pathDisabled:"action aborted: path is disabled",queryUpdate:"query updated",onAddRuleFalse:"onAddRule callback returned false",onAddGroupFalse:"onAddGroup callback returned false",onGroupRuleFalse:"onGroupRule callback returned false",onGroupGroupFalse:"onGroupGroup callback returned false",onMoveRuleFalse:"onMoveRule callback returned false",onMoveGroupFalse:"onMoveGroup callback returned false",onRemoveFalse:"onRemove callback returned false",add:"rule or group added",remove:"rule or group removed",update:"rule or group updated",move:"rule or group moved",group:"rule or group grouped with another"},Eo=[];import{jsx as cl}from"react/jsx-runtime";function il(t){let e,o,l="";if(typeof t=="string"||typeof t=="number")l+=t;else if(typeof t=="object")if(Array.isArray(t)){let r=t.length;for(e=0;e<r;e++)t[e]&&(o=il(t[e]))&&(l&&(l+=" "),l+=o)}else for(o in t)t[o]&&(l&&(l+=" "),l+=o);return l}function Z(){let t=0,e,o,l="",r=arguments.length;for(;t<r;t++)(e=t<0||arguments.length<=t?void 0:arguments[t])&&(o=il(e))&&(l&&(l+=" "),l+=o);return l}var ul=Z;var dl=t=>{let{component:e,...o}=t,l=Z(o.schema.suppressStandardClassnames||I.betweenRules,o.schema.classNames.betweenRules);return cl("div",{className:l,"data-testid":W.inlineCombinator,children:cl(e,{...o,testID:W.combinators})})};var $r=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Oo;return typeof t=="string"?t.split(`\\${e}`).map(o=>o.split(e)).reduce((o,l,r)=>r===0?l:[...o.slice(0,-1),`${o.at(-1)}${e}${l[0]}`,...l.slice(1)],[]):[]},Vt=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Oo;return t.map(o=>`${o??""}`.replaceAll(e[0],`\\${e[0]}`)).join(e)},ie=t=>typeof t=="string"?t.trim():t,B=function(t){let{retainEmptyStrings:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Array.isArray(t)?t.map(o=>ie(o)):typeof t=="string"?$r(t,Oo).filter(e?()=>!0:o=>!/^\s*$/.test(o)).map(o=>o.trim()):typeof t=="number"?[t]:[]},hs=t=>t.every(e=>e===!1||(e??!1)!==!1);import{numericRegex as _n}from"numeric-quantity";var E=t=>typeof t=="string"?t.toLowerCase():t,pl=new RegExp(_n.source.replace(/^\^/,String.raw`^\s*`).replace(/\$$/,String.raw`\s*$`)),Ce=t=>t===null||typeof t!="object"?!1:Object.getPrototypeOf(t)===Object.prototype,Ye=t=>t==null||t==="";var w=t=>Ce(t)&&Array.isArray(t.rules),de=t=>w(t)&&typeof t.combinator=="string",Ze=t=>w(t)&&t.combinator===void 0;import{produce as Hn}from"immer";var ml=["or","xor","and"],Un=(t,e)=>E(t)===e,Lo=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,o=ml[e];return t.rules.includes(o)?Hn(t,l=>{let r=0;for(;r<l.rules.length-2;){if(Un(l.rules[r+1],o)){r+=2;continue}let s=l.rules.findIndex((a,d)=>d>r&&typeof a=="string"&&E(a)===o);if(s===-1){l.rules.splice(r,l.rules.length,Lo({rules:l.rules.slice(r)},e+1));break}else l.rules.splice(r,s-r,Lo({rules:l.rules.slice(r,s)},e+1))}}):e<ml.length-2?Lo(t,e+1):t},Pe=t=>{if(de(t))return t;let e=Lo(t),o=e.rules.map(s=>typeof s=="string"||!w(s)?s:Pe(s)),l=o.length<2?"and":o[1],r=o.filter(s=>typeof s!="string");return{...e,combinator:l,rules:r}},fl=t=>{if(Ze(t))return t;let{combinator:e,...o}=t,l=[],{length:r}=t.rules;for(let[s,a]of t.rules.entries())w(a)?l.push(fl(a)):l.push(a),e&&s<r-1&&l.push(e);return{...o,rules:l}};function As(t){return Ze(t)?Pe(t):fl(t)}var ws=t=>{let e={},o=r=>{},l=r=>{let s=[];if(r.rules.length===0)s.push(Mo.empty);else if(!de(r)){let a=!1;for(let d=0;d<r.rules.length&&!a;d++)(d%2===0&&typeof r.rules[d]=="string"||d%2===1&&typeof r.rules[d]!="string"||d%2===1&&typeof r.rules[d]=="string"&&!mt.map($=>$.name).includes(r.rules[d]))&&(a=!0);a&&s.push(Mo.invalidIndependentCombinators)}de(r)&&!mt.map(a=>a.name).includes(r.combinator)&&r.rules.length>1&&s.push(Mo.invalidCombinator),r.id&&(e[r.id]=s.length>0?{valid:!1,reasons:s}:!0);for(let a of r.rules)typeof a=="string"||(w(a)?l(a):o(a))};return l(t),e};import{produce as hl}from"immer";var ko=t=>Ce(t)&&"name"in t&&typeof t.name=="string",To=t=>Ce(t)&&"value"in t&&typeof t.value=="string";function qe(t,e,o){return hl(r=>{let s={},a=!!e;if(typeof r=="string")return{...e,name:r,value:r,label:o?.[r]??r};if(ko(r)&&!To(r)?(s.value=r.name,a=!0):!ko(r)&&To(r)&&(s.name=r.value,a=!0),a)return Object.assign({},e,r,s)})(t)}function Se(t,e,o){return Array.isArray(t)?hl(r=>{if(je(r))for(let s of r)for(let[a,d]of s.options.entries())s.options[a]=qe(d,e,o);else for(let[s,a]of r.entries())r[s]=qe(a,e,o)})(t):[]}function Nr(t,e){return Object.fromEntries(Object.entries(t).map(o=>{let[l,r]=o;return[l,qe(r,e)]}))}var Ms=t=>Zt(t),Zt=t=>{let e=new Set,o=[];for(let l of t)e.has(l.value??l.name)||(e.add(l.value??l.name),o.push(l));return t.length===o.length?t:o},Gr=t=>Array.isArray(t)&&t.length>0&&Ce(t[0])&&"options"in t[0]&&Array.isArray(t[0].options),Bt=t=>{let e=!1;if(Array.isArray(t))for(let o of t)if(ko(o)||To(o))e=!0;else return!1;return e},zn=t=>{let e=!1;if(Array.isArray(t))for(let o of t)if(ko(o)&&To(o))e=!0;else return!1;return e},je=function(t){let{allowEmpty:e=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!1;if(Array.isArray(t))for(let l of t)if(Ce(l)&&"options"in l&&(Bt(l.options)||e&&Array.isArray(l.options)&&l.options.length===0))o=!0;else return!1;return o},Es=function(t){let{allowEmpty:e=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!1;if(Array.isArray(t))for(let l of t)if(Ce(l)&&"options"in l&&(zn(l.options)||e&&Array.isArray(l.options)&&l.options.length===0))o=!0;else return!1;return o},z=(t,e)=>(je(t,{allowEmpty:!0})?t.flatMap(o=>o.options):t).find(o=>o.value===e||o.name===e),Re=t=>{if(!Array.isArray(t)||t.length===0)return null;if(je(t,{allowEmpty:!0})){for(let e of t)if(e.options.length>0)return e.options[0].value??e.options[0].name;return null}return t[0].value??t[0].name},bl=t=>Zt(Gr(t)?t.flatMap(e=>e.options):t),Vo=t=>{let e=new Set,o=new Set,l=[];for(let r of t)if(!e.has(r.label)){e.add(r.label);let s=[];for(let a of r.options)o.has(a.value??a.name)||(o.add(a.value??a.name),s.push(qe(a)));l.push({...r,options:s})}return l},gl=t=>je(t)?Vo(t):Zt(t.map(e=>qe(e)));var vl=(t,e,o)=>{let l=qe(t),r=qe(o);return l.value===r.value?!1:typeof l.comparator=="string"?l[l.comparator]===r[l.comparator]:l.comparator?.(r,e)??!1},Qo=(t,e,o)=>{if(!t.comparator){let l=r=>(r.value??r.name)!==(t.value??t.name);return je(e)?e.map(r=>({...r,options:r.options.filter(s=>l(s))})):e.filter(r=>l(r))}return je(e)?e.map(l=>({...l,options:l.options.filter(r=>vl(t,o,r))})).filter(l=>l.options.length>0):e.filter(l=>vl(t,o,l))};import{numericQuantity as Jn}from"numeric-quantity";var Q=function(t){let{parseNumbers:e,bigIntOnOverflow:o}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e||typeof t=="bigint"||typeof t=="number")return t;if(e==="native")return Number.parseFloat(t);let l=Jn(t,{allowTrailingInvalid:e==="enhanced",bigIntOnOverflow:o,romanNumerals:!1,round:!1});return typeof l=="bigint"||!Number.isNaN(l)?l:t};import{produce as Kn}from"immer";var yl=(t,e,o)=>Kn(t,l=>{for(let[r,s]of Object.entries(e))s===!1?delete l[r]:s&&r!==s&&r in l&&(l[s]=l[r],o&&delete l[r])});function We(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{ruleProcessor:o=g=>g,ruleGroupProcessor:l=g=>g,propertyMap:r={},combinatorMap:s={},operatorMap:a={},omitPath:d=!1,deleteRemappedProperties:$=!0}=e,p=g=>({...l(yl({...g,...de(g)?{combinator:s[g.combinator]??g.combinator}:{}},r,$)),...r.rules===!1?null:{[r.rules??"rules"]:g.rules.map((f,h)=>{let n=d?null:{path:[...g.path,h]};return typeof f=="string"?s[f]??f:w(f)?p({...f,...n}):o(yl({...f,...n,..."operator"in f?{operator:a[f.operator]??f.operator}:{}},r,$))})}});return p({...t,...d?null:{path:[]}})}var Rl=t=>Ce(t)&&typeof t.valid=="boolean",K=(t,e,o)=>{if(typeof e=="boolean")return e;if(Rl(e))return e.valid;if(typeof o=="function"&&!w(t)){let l=o(t);if(typeof l=="boolean")return l;if(Rl(l))return l.valid}return!0};var eo=t=>{let{parseNumbers:e,inputType:o}=t;if(typeof e=="string"){let[l,r]=e.split("-");return r==="limited"?o==="number"?l:!1:l}return e?"strict":!1};var Gl=t=>{switch(E(t)){case"null":return"is null";case"notnull":return"is not null";case"notin":return"not in";case"notbetween":return"not between";case"contains":case"beginswith":case"endswith":return"like";case"doesnotcontain":case"doesnotbeginwith":case"doesnotendwith":return"not like";default:return t}},Qt={"=":"$eq","!=":"$ne","<":"$lt","<=":"$lte",">":"$gt",">=":"$gte",in:"$in",notin:"$nin",notIn:"$nin"},xr={"=":"equals","!=":"not","<":"lt","<=":"lte",">":"gt",">=":"gte",in:"in",notin:"notIn"},Cr={and:"&&",or:"||"},Ys={startsWith:(t,e)=>typeof t=="string"&&t.startsWith(e),endsWith:(t,e)=>typeof t=="string"&&t.endsWith(e)},Sr=(t,e)=>({...t,rules:t.rules.map(o=>{if(typeof o=="string")return o;if(w(o))return Sr(o,e);let l=z(e.fields,o.field),r=eo({parseNumbers:e.parseNumbers,inputType:l?.inputType});if(Array.isArray(o.value))return{...o,value:o.value.map(a=>Q(a,{parseNumbers:r}))};let s=B(o.value,{retainEmptyStrings:!0}).map(a=>Q(a,{parseNumbers:r}));if(s.every(a=>typeof a=="number")){if(s.length>1)return{...o,value:s};if(s.length===1)return{...o,value:s[0]}}return o})}),ve=t=>typeof t=="string"&&t.length>0||typeof t=="number"&&!Number.isNaN(t)||typeof t!="string"&&typeof t!="number",L=(t,e)=>!!e&&(typeof t=="number"||typeof t=="bigint"||typeof t=="string"&&pl.test(t)),Al=t=>t.length>=3,wr=function(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["",""];return Array.isArray(t)?t:typeof t=="string"?[t,t]:t??["",""]},it=(t,e)=>{let{quoteFieldNamesWith:o,fieldIdentifierSeparator:l}=e,[r,s]=wr(o);return typeof l=="string"&&l.length>0?Vt($r(t,l).map(a=>`${r}${a}${s}`),l):`${r}${t}${s}`},$l=["S","V","O"],xl=t=>{let e=[],o=new Set($l);for(let l of t.toUpperCase())if(o.has(l)&&(e.push(l),o.delete(l),o.size===0))break;for(let l of $l)o.has(l)&&e.push(l);return e},Ar={groupPrefix:"",groupPrefix_not_xor:"either zero or more than one of",groupPrefix_xor:"exactly one of",groupSuffix:"is true",groupSuffix_not:"is not true"},Nl=(t,e,o)=>e.startsWith(t)&&o.every(l=>e.includes(`_${l}`)&&e.match(/_/g)?.length===o.length),mo=function(t,e){let o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return o.length===0?e[t]??Ar[t]??"":Object.entries(e).find(l=>{let[r]=l;return Nl(t,r,o)})?.[1]??Object.entries(Ar).find(l=>{let[r]=l;return Nl(t,r,o)})?.[1]??Ar[t]??""},he=t=>{let{mode:e,threshold:o}=t.match??{};if(e){if(!w(t.value))return!1;let l=E(e),r=l==="atleast"&&o===1?"some":l==="atmost"&&o===0?"none":l;return(r==="atleast"||r==="atmost"||r==="exactly")&&(typeof o!="number"||o<0)?!1:{mode:r,threshold:o}}},Dr=(t,e)=>typeof e=="bigint"?{$bigint:e.toString()}:e,Zs=(t,e)=>Ce(e)&&Object.keys(e).length===1&&typeof e.$bigint=="string"?BigInt(e.$bigint):e;var Fo=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=(h,n)=>{if(!K(h,g[h.id??""]))return n?l:"";let v=h.rules.map(i=>{if(typeof i=="string")return Cr[i];if(w(i))return f(i);let[u,y]=p(i);if(!K(i,u,y)||i.field===s||i.operator===a||d!==void 0&&i.value===d)return"";let N=z(o,i.field);return $(i,{...e,parseNumbers:r(N?.inputType),escapeQuotes:(i.valueSource??"value")==="value",fieldData:N})}).filter(Boolean).join(de(h)?` ${Cr[h.combinator]} `:" "),[m,R]=h.not||!n?[`${h.not?"!":""}(`,")"]:["",""];return v?`${m}${v}${R}`:l};return f(t,!0)};var Io=t=>t.startsWith("not")||t.startsWith("doesnot"),qt=(t,e)=>typeof t!="string"||!e?t:t.replaceAll('"','\\"'),fo=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{escapeQuotes:o,parseNumbers:l,preserveValueOrder:r}=e,{field:s,operator:a,value:d,valueSource:$}=t,p=$==="field",g=E(a==="="?"==":a),f=typeof d=="number"||typeof d=="boolean"||typeof d=="bigint"||L(d,l),h=he(t);if(h===!1)return"";if(h){let{mode:n,threshold:v}=h,m="elem_alias",R=We(t.value,{ruleProcessor:u=>({...u,field:`${m}${u.field?`.${u.field}`:""}`})}),i=Fo(R,e);switch(n){case"all":return`${s}.all(${m}, ${i})`;case"none":case"some":return`${n==="none"?"!":""}${s}.exists(${m}, ${i})`;case"atleast":case"atmost":case"exactly":{let u=`double(${s}.size())`,y=`${s}.filter(${m}, ${i}).size()`,N=n==="atleast"?">=":n==="atmost"?"<=":"==";return v>0&&v<1?`${y} ${N} (${u} * ${v})`:`${y} ${N} ${v}`}}}switch(g){case"<":case"<=":case"==":case"!=":case">":case">=":return`${s} ${g} ${p||f?ie(d):`"${qt(d,o)}"`}`;case"contains":case"doesnotcontain":return`${Io(g)?"!":""}${s}.contains(${p?ie(d):`"${qt(d,o)}"`})`;case"beginswith":case"doesnotbeginwith":return`${Io(g)?"!":""}${s}.startsWith(${p?ie(d):`"${qt(d,o)}"`})`;case"endswith":case"doesnotendwith":return`${Io(g)?"!":""}${s}.endsWith(${p?ie(d):`"${qt(d,o)}"`})`;case"null":return`${s} == null`;case"notnull":return`${s} != null`;case"in":case"notin":{let[n,v]=Io(g)?["!(",")"]:["",""],m=B(d);return`${n}${s} in [${m.map(R=>p||L(R,l)?`${ie(R)}`:`"${qt(R,o)}"`).join(", ")}]${v}`}case"between":case"notbetween":{let n=B(d);if(n.length>=2&&!Ye(n[0])&&!Ye(n[1])){let[v,m]=n,R=l!==!1,i=L(v,R)?Q(v,{parseNumbers:R}):Number.NaN,u=L(m,R)?Q(m,{parseNumbers:R}):Number.NaN,y=Number.isNaN(i)?p?`${v}`:`"${qt(v,o)}"`:i,N=Number.isNaN(u)?p?`${m}`:`"${qt(m,o)}"`:u;if(!r&&y===i&&N===u&&u<i){let G=u;N=i,y=G}return g==="between"?`(${s} >= ${y} && ${s} <= ${N})`:`(${s} < ${y} || ${s} > ${N})`}else return""}}return""};var Bo={$and:[{$expr:!0}]},ho=(t,e,o)=>{let{fields:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=(h,n)=>{if(!K(h,g[h.id??""]))return n?Bo:!1;let v=`$${E(h.combinator)}`,m=!1,R=h.rules.map(i=>{if(w(i)){let G=f(i);return G?(m=!0,G):!1}let[u,y]=p(i);if(!K(i,u,y)||i.field===s||i.operator===a||d!==void 0&&i.value===d)return!1;let N=z(l,i.field);return $(i,{...e,parseNumbers:r(N?.inputType),fieldData:N},o)}).filter(Boolean);return R.length>0?R.length===1&&!m?R[0]:{[v]:R}:Bo};return f(Pe(t),!0)};var Pt=function(t,e){let o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;return L(t,o||typeof t=="bigint")?Number(Q(t,{parseNumbers:"strict"})):e},to=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{parseNumbers:a,preserveValueOrder:d,context:$}=e,p=s==="field",{avoidFieldsAsKeys:g}=$??{},f=he(t);if(f===!1)return;if(f){let{mode:n,threshold:v}=f,m={$size:{$ifNull:[`$${o}`,[]]}},R=ho(We(r,{ruleProcessor:y=>({...y,field:y.field?`${o}.${y.field}`:o})}),{...e,ruleProcessor:to,context:{...e.context,avoidFieldsAsKeys:!1}}),i=ho(We(r,{ruleProcessor:y=>({...y,field:y.field?`$item.${y.field}`:"$item"})}),{...e,ruleProcessor:to,context:{...e.context,avoidFieldsAsKeys:!0}}),u={$size:{$ifNull:[{$filter:{input:`$${o}`,as:"item",cond:{$and:[i]}}},[]]}};switch(n){case"all":return{$expr:{$eq:[u,m]}};case"none":return{$nor:[R]};case"some":return R;case"atleast":case"atmost":case"exactly":{let y=n==="atleast"?Qt[">="]:n==="atmost"?Qt["<="]:Qt["="];return v>0&&v<1?{$expr:{[y]:[u,{$multiply:[m,v]}]}}:{$expr:{[y]:[u,v]}}}}}if(l==="="&&!p)return g?{$eq:[`$${o}`,Pt(r,r,a)]}:{[o]:Pt(r,r,a)};let h=E(l);switch(h){case"<":case"<=":case"=":case"!=":case">":case">=":{let n=Qt[h];return p?{[n]:[`$${o}`,`$${r}`]}:g?{$and:[{$ne:[`$${o}`,null]},{[n]:[`$${o}`,Pt(r,r,a)]}]}:{[o]:{[n]:Pt(r,r,a)}}}case"contains":return p?{$where:`this.${o}.includes(this.${r})`}:g?{$regexMatch:{input:`$${o}`,regex:r}}:{[o]:{$regex:r}};case"beginswith":return p?{$where:`this.${o}.startsWith(this.${r})`}:g?{$regexMatch:{input:`$${o}`,regex:`^${r}`}}:{[o]:{$regex:`^${r}`}};case"endswith":return p?{$where:`this.${o}.endsWith(this.${r})`}:g?{$regexMatch:{input:`$${o}`,regex:`${r}$`}}:{[o]:{$regex:`${r}$`}};case"doesnotcontain":return p?{$where:`!this.${o}.includes(this.${r})`}:g?{$not:{$regexMatch:{input:`$${o}`,regex:r}}}:{[o]:{$not:{$regex:r}}};case"doesnotbeginwith":return p?{$where:`!this.${o}.startsWith(this.${r})`}:g?{$not:{$regexMatch:{input:`$${o}`,regex:`^${r}`}}}:{[o]:{$not:{$regex:`^${r}`}}};case"doesnotendwith":return p?{$where:`!this.${o}.endsWith(this.${r})`}:g?{$not:{$regexMatch:{input:`$${o}`,regex:`${r}$`}}}:{[o]:{$not:{$regex:`${r}$`}}};case"null":return g?{$eq:[`$${o}`,null]}:{[o]:null};case"notnull":return g?{$ne:[`$${o}`,null]}:{[o]:{$ne:null}};case"in":case"notin":{let n=B(r);return p?{$where:`${h==="notin"?"!":""}[${n.map(v=>`this.${v}`).join(",")}].includes(this.${o})`}:g?h==="notin"?{$not:{[Qt.in]:[`$${o}`,n.map(v=>Pt(v,v,a))]}}:{[Qt[h]]:[`$${o}`,n.map(v=>Pt(v,v,a))]}:{[o]:{[Qt[h]]:n.map(v=>Pt(v,v,a))}}}case"between":case"notbetween":{let n=B(r);if(n.length>=2&&ve(n[0])&&ve(n[1])){let[v,m]=n,R=Pt(v,Number.NaN,!0),i=Pt(m,Number.NaN,!0),u=p||Number.isNaN(R)?v:R,y=p||Number.isNaN(i)?m:i;if(!d&&u===R&&y===i&&i<R){let N=i;y=R,u=N}return h==="between"?p?{$gte:[`$${o}`,`$${u}`],$lte:[`$${o}`,`$${y}`]}:g?{$and:[{$gte:[`$${o}`,u]},{$lte:[`$${o}`,y]}]}:{[o]:{$gte:u,$lte:y}}:p?{$or:[{$lt:[`$${o}`,`$${u}`]},{$gt:[`$${o}`,`$${y}`]}]}:g?{$or:[{$lt:[`$${o}`,u]},{$gt:[`$${o}`,y]}]}:{$or:[{[o]:{$lt:u}},{[o]:{$gt:y}}]}}else return""}}return""};var bo=(t,e)=>{let o=to(t,e);return o?JSON.stringify(o):""};var qo=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=(h,n)=>{if(!K(h,g[h.id??""]))return n?l:"";let v=h.rules.map(i=>{if(typeof i=="string")return i;if(w(i))return f(i);let[u,y]=p(i);if(!K(i,u,y)||i.field===s||i.operator===a||d!==void 0&&i.value===d)return"";let N=z(o,i.field);return $(i,{...e,parseNumbers:r(N?.inputType),escapeQuotes:(i.valueSource??"value")==="value",fieldData:N})}).filter(Boolean).join(de(h)?` ${h.combinator} `:" "),[m,R]=h.not||!n?[`${h.not?"!":""}(`,")"]:["",""];return v?`${m}${v}${R}`:l};return f(t,!0)};var jo=t=>t.startsWith("not")||t.startsWith("doesnot"),Or=(t,e)=>e?`!(${t})`:`${t}`,jt=(t,e)=>typeof t!="string"||!e?t:t.replaceAll("'","\\'"),go=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{escapeQuotes:a,parseNumbers:d,preserveValueOrder:$}=e,p=s==="field",g=E(l==="="?"==":l),f=typeof r=="number"||typeof r=="boolean"||typeof r=="bigint"||L(r,d),h=he(t);if(h===!1)return"";if(h){let{mode:n,threshold:v}=h,m=qo(We(t.value,{ruleProcessor:u=>({...u,field:`${u.field||"#this"}`})}),e),R=`${o}.size()`,i=`${o}.?[${m}].size()`;switch(n){case"all":return`${i} == ${R}`;case"none":return`${i} == 0`;case"some":return`${i} >= 1`;case"atleast":case"atmost":case"exactly":{let u=n==="atleast"?">=":n==="atmost"?"<=":"==";return v>0&&v<1?`${i} ${u} (${R} * ${v})`:`${i} ${u} ${v}`}}}switch(g){case"<":case"<=":case"==":case"!=":case">":case">=":return`${o} ${g} ${p||f?ie(r):`'${jt(r,a)}'`}`;case"contains":case"doesnotcontain":return Or(`${o} matches ${p||f?ie(r):`'${jt(r,a)}'`}`,jo(g));case"beginswith":case"doesnotbeginwith":{let n=p?`'^'.concat(${ie(r)})`:`'${typeof r=="string"&&!r.startsWith("^")||f?"^":""}${jt(r,a)}'`;return Or(`${o} matches ${n}`,jo(g))}case"endswith":case"doesnotendwith":{let n=p?`${ie(r)}.concat('$')`:`'${jt(r,a)}${typeof r=="string"&&!r.endsWith("$")||f?"$":""}'`;return Or(`${o} matches ${n}`,jo(g))}case"null":return`${o} == null`;case"notnull":return`${o} != null`;case"in":case"notin":{let n=jo(g)?"!":"",v=B(r);return v.length>0?`${n}(${v.map(m=>`${o} == ${p||L(m,d)?`${ie(m)}`:`'${jt(m,a)}'`}`).join(" or ")})`:""}case"between":case"notbetween":{let n=B(r);if(n.length>=2&&!Ye(n[0])&&!Ye(n[1])){let[v,m]=n,R=d!==!1,i=L(v,R)?Q(v,{parseNumbers:R}):Number.NaN,u=L(m,R)?Q(m,{parseNumbers:R}):Number.NaN,y=Number.isNaN(i)?p?`${v}`:`'${jt(v,a)}'`:i,N=Number.isNaN(u)?p?`${m}`:`'${jt(m,a)}'`:u;if(!$&&y===i&&N===u&&u<i){let G=u;N=i,y=G}return g==="between"?`(${o} >= ${y} and ${o} <= ${N})`:`(${o} < ${y} or ${o} > ${N})`}else return""}}return""};var Xn=(t,e,o)=>o&&typeof t=="string"?t.replaceAll(`${e}`,`${e}${e}`):t,ft=function(t){let{operator:e,value:o,valueSource:l}=t,{escapeQuotes:r,parseNumbers:s,preserveValueOrder:a,quoteFieldNamesWith:d,quoteValuesWith:$,concatOperator:p="||",fieldIdentifierSeparator:g,wrapValueWith:f=["",""],translations:h}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=l==="field",v=E(e),m=$||"'",R=G=>`${f[0]}${m}${G}${m}${f[1]}`,i=G=>Xn(G,m,r),u=G=>R(i(G)),y=G=>it(G,{quoteFieldNamesWith:d,fieldIdentifierSeparator:g}),N=function(){for(var G=arguments.length,A=new Array(G),C=0;C<G;C++)A[C]=arguments[C];return p.toUpperCase()==="CONCAT"?`CONCAT(${A.join(", ")})`:A.join(` ${p} `)};switch(v){case"null":case"notnull":return"";case"in":case"notin":{let G=B(o);return G.length>0?`(${G.map(A=>n?y(A):L(A,s)?`${ie(A)}`:`${u(A)}`).join(", ")})`:""}case"between":case"notbetween":{let G=B(o,{retainEmptyStrings:!0});if(G.length<2||!ve(G[0])||!ve(G[1]))return"";let[A,C]=G,c=L(A,s)?Q(A,{parseNumbers:"strict"}):Number.NaN,b=L(C,s)?Q(C,{parseNumbers:"strict"}):Number.NaN,D=Number.isNaN(c)?n?`${A}`:A:c,P=Number.isNaN(b)?n?`${C}`:C:b,x=[D,P];return!a&&D===c&&P===b&&b<c&&(x[0]=b,x[1]=c),(n?x.map(M=>y(M)):x.every(M=>L(M,s))?x.map(M=>Q(M,{parseNumbers:"strict"})):x.map(M=>u(M))).join(` ${h?.and??"and"} `)}case"contains":case"doesnotcontain":return n?N(R("%"),y(o),R("%")):R(`%${i(o)}%`);case"beginswith":case"doesnotbeginwith":return n?N(y(o),R("%")):R(`${i(o)}%`);case"endswith":case"doesnotendwith":return n?N(R("%"),y(o)):R(`%${i(o)}`)}return typeof o=="boolean"?o?"TRUE":"FALSE":n?y(o):L(o,s)?`${ie(o)}`:`${u(o)}`};var _o=(t,e,o)=>(l,r)=>{let{fields:s,getParseNumberBoolean:a,placeholderFieldName:d,placeholderOperatorName:$,placeholderValueName:p,validateRule:g,validationMap:f}=e;if(!l||!r)return;let{and:h,not:n,or:v}=r,m=de(t)?t:Pe(t),R=Wo,i=(u,y)=>{if(!K(u,f[u.id??""]))return;let N=u.rules.map(A=>{if(w(A))return i(A);let[C,c]=g(A);if(!K(A,C,c)||A.field===d||A.operator===$||p!==void 0&&A.value===p)return;let b=z(s,A.field);return R(A,{...e,parseNumbers:a(b?.inputType),fieldData:b,context:{...e.context,columns:l,drizzleOperators:r}})}).filter(Boolean);if(N.length===0)return;let G=u.combinator==="or"?v(...N):h(...N);return u.not?n(G):G};return i(m,!0)};var Wo=(t,e)=>{let o=e??{},{parseNumbers:l,preserveValueOrder:r,context:s={}}=o,{columns:a,drizzleOperators:d,useRawFields:$}=s;if(!a||!d)return;let{between:p,eq:g,gt:f,gte:h,inArray:n,isNotNull:v,isNull:m,like:R,lt:i,lte:u,ne:y,notBetween:N,notInArray:G,notLike:A,sql:C}=d,{field:c,operator:b,value:D,valueSource:P}=t,x=$&&/[a-z][a-z0-9]*/i.test(c)?C.raw(c):a[c],M=E(b),k=P==="field",H=q=>k?a[q]:q;if(!x)return;let T=he(t);if(T!==!1){if(T){if(o.preset!=="postgresql")return;let{mode:q,threshold:S}=T,U="elem_alias",le=We(t.value,{ruleProcessor:V=>({...V,field:U})}),F=_o(le,{...o,context:{...o.context,useRawFields:!0}});switch(q){case"all":return C`(select count(*) from unnest(${x}) as ${C.raw(U)} where ${F({},d)}) = array_length(${x}, 1)`;case"none":return C`not exists (select 1 from unnest(${x}) as ${C.raw(U)} where ${F({},d)})`;case"some":return C`exists (select 1 from unnest(${x}) as ${C.raw(U)} where ${F({},d)})`;case"atleast":case"atmost":case"exactly":{let V=q==="atleast"?">=":q==="atmost"?"<=":"=";return S>0&&S<1?C`(select count(*) / array_length(${x}, 1) from unnest(${x}) as ${C.raw(U)} where ${F({},d)}) ${C.raw(`${V} ${S}`)}`:C`(select count(*) from unnest(${x}) as ${C.raw(U)} where ${F({},d)}) ${C.raw(`${V} ${S}`)}`}}}switch(M){case"=":return g(x,H(D));case"!=":return y(x,H(D));case">":return f(x,H(D));case"<":return i(x,H(D));case">=":return h(x,H(D));case"<=":return u(x,H(D));case"beginswith":case"doesnotbeginwith":return(M==="doesnotbeginwith"?A:R)(x,k?C`${H(D)} || '%'`:`${D}%`);case"contains":case"doesnotcontain":return(M==="doesnotcontain"?A:R)(x,k?C`'%' || ${H(D)} || '%'`:`%${D}%`);case"endswith":case"doesnotendwith":return(M==="doesnotendwith"?A:R)(x,k?C`'%' || ${H(D)}`:`%${D}`);case"null":return m(x);case"notnull":return v(x);case"in":case"notin":{let q=B(D).map(S=>H(S));return M==="notin"?G(x,q):n(x,q)}case"between":case"notbetween":{let q=B(D);if(q.length>=2&&ve(q[0])&&ve(q[1])){let[S,U]=q,le=l!==!1;if(!k&&L(S,le)&&L(U,le)){let F=Q(S,{parseNumbers:le}),V=Q(U,{parseNumbers:le});if(!r&&V<F){let O=V;U=F,S=O}else S=F,U=V}else k&&(S=H(S),U=H(U));return M==="notbetween"?N(x,S,U):p(x,S,U)}return}default:return}}};var Cl=(t,e)=>{let{fields:o,getParseNumberBoolean:l,placeholderFieldName:r,placeholderOperatorName:s,placeholderValueName:a,ruleProcessor:d,validateRule:$,validationMap:p}=e,g=Pe(t),f=n=>{if(!K(n,p[n.id??""]))return!1;let v=n.rules.map(m=>{if(w(m))return f(m);let[R,i]=$(m);if(!K(m,R,i)||m.field===r||m.operator===s||a!==void 0&&m.value===a)return!1;let u=z(o,m.field);return d(m,{...e,parseNumbers:l(u?.inputType),fieldData:u})}).filter(Boolean);return v.length===0?!1:{bool:n.not?{must_not:/^or$/i.test(n.combinator)?{bool:{should:v}}:v}:{[/^or$/i.test(n.combinator)?"should":"must"]:v}}},h=f(g);return h===!1?{}:h};var Ho=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=(h,n)=>{if(!K(h,g[h.id??""]))return n?l:"";let v=h.rules.map(i=>{if(typeof i=="string")return i;if(w(i))return f(i);let[u,y]=p(i);if(!K(i,u,y)||i.field===s||i.operator===a||d!==void 0&&i.value===d)return"";let N=z(o,i.field);return $(i,{...e,parseNumbers:r(N?.inputType),escapeQuotes:(i.valueSource??"value")==="value",fieldData:N})}).filter(Boolean).join(de(h)?` ${h.combinator} `:" "),[m,R]=h.not||!n?[`${h.not?"$not":""}(`,")"]:["",""];return v?`${m}${v}${R}`:l};return f(t,!0)};var vo=(t,e)=>{let{fields:o,getParseNumberBoolean:l,placeholderFieldName:r,placeholderOperatorName:s,placeholderValueName:a,ruleProcessor:d,validateRule:$,validationMap:p}=e,g=Pe(t),f=(h,n)=>{if(!K(h,p[h.id??""]))return!1;let v=h.rules.map(R=>{if(w(R))return f(R);let[i,u]=$(R);if(!K(R,i,u)||R.field===r||R.operator===s||a!==void 0&&R.value===a)return!1;let y=z(o,R.field);return d(R,{...e,parseNumbers:l(y?.inputType),fieldData:y})}).filter(Boolean);if(v.length===0)return!1;let m={[h.combinator]:v};return h.not?{"!":m}:m};return f(g,!0)};var Sl=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=Pe(t),h=(n,v)=>{if(!K(n,g[n.id??""]))return v?l:"";let m=n.rules.map(G=>{if(w(G))return h(G);let[A,C]=p(G);if(!K(G,A,C)||G.field===s||G.operator===a||d!==void 0&&G.value===d)return"";let c=z(o,G.field);return $(G,{...e,parseNumbers:r(c?.inputType),escapeQuotes:(G.valueSource??"value")==="value",fieldData:c})}).filter(Boolean),R=m.join(""),[i,u]=n.not?["(!",")"]:["",""],[y,N]=m.length>1?[`${i}(${n.combinator==="or"?"|":"&"}`,`)${u}`]:[i,u];return R?`${y}${R}${N}`:l};return h(f,!0)};var wl=t=>t.startsWith("{")&&t.endsWith("}"),Dl=(t,e,o)=>{let{fields:l,fallbackExpression:r,getParseNumberBoolean:s,placeholderFieldName:a,placeholderOperatorName:d,placeholderValueName:$,ruleProcessor:p,validateRule:g,validationMap:f}=e,h=(v,m)=>{if(!K(v,f[v.id??""]))return m?r:"";let R=`"$${E(v.combinator)}"`,i=!1,u=v.rules.map(y=>{if(w(y)){let C=h(y);return C?(i=!0,wl(C)?C:`{${C}}`):""}let[N,G]=g(y);if(!K(y,N,G)||y.field===a||y.operator===d||$!==void 0&&y.value===$)return"";let A=z(l,y.field);return p(y,{...e,parseNumbers:s(A?.inputType),fieldData:A},o)}).filter(Boolean);return u.length>0?u.length===1&&!i?u[0]:`${R}:[${u.join(",")}]`:r},n=h(Pe(t),!0);return wl(n)?n:`{${n}}`};var Uo=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,translations:p,validateRule:g,validationMap:f}=e,h=(n,v)=>{if(!K(n,f[n.id??""]))return v?l:"";let m=Ze(n)&&n.rules.some(c=>typeof c=="string"&&E(c)==="xor")?Pe(n):n,R=m.rules.map(c=>{if(typeof c=="string")return`, ${p[c]??c} `;if(w(c))return h(c,m.rules.length===1&&!(m.not||/^xor$/i.test(m.combinator??"")));let[b,D]=g(c);if(!K(c,b,D)||c.field===s||c.operator===a||d!==void 0&&c.value===d)return"";let P=(c.valueSource??"value")==="value",x=z(o,c.field);return $(c,{...e,parseNumbers:r(x?.inputType),escapeQuotes:P,fieldData:x})});if(R.length===0)return l;let i=E(m.combinator??"")==="xor",u=i?m.combinator.slice(1):m.combinator,y=m.not||!v||i&&R.length>1,[N,G]=["groupPrefix","groupSuffix"].map(c=>m.not?i?mo(c,p,["not","xor"]):mo(c,p,["not"]):i?mo(c,p,["xor"]):mo(c,p)),A=y?`${N} (`.trim():"",C=y?`) ${G}`.trim():"";return`${A}${R.filter(Boolean).join(de(m)?`, ${p[u]??u} `:"")}${C}`};return h(t,!0)};var zo=(t,e)=>{let{format:o,fields:l,fallbackExpression:r,getParseNumberBoolean:s,placeholderFieldName:a,placeholderOperatorName:d,placeholderValueName:$,ruleProcessor:p,validateRule:g,validationMap:f}=e,h=o==="parameterized",n=[],v={},m=new Map,R=y=>{m.has(y)||m.set(y,new Set);let N=`${y}_${m.get(y).size+1}`;return m.get(y).add(N),N},i=y=>{let[N,G]=g(y);if(!K(y,N,G)||y.field===a||y.operator===d||$!==void 0&&y.value===$)return"";let A=z(l,y.field),C=Object.fromEntries([...m.entries()].map(P=>{let[x,M]=P;return[x,[...M]]})),c=p(y,{...e,parseNumbers:s(A?.inputType),getNextNamedParam:R,fieldParamNames:C,fieldData:A},{processedParams:n});if(!Ce(c))return"";let{sql:b,params:D}=c;if(typeof b!="string"||!b)return"";if(o==="parameterized"&&Array.isArray(D))n.push(...D);else if(o==="parameterized_named"&&Ce(D)){Object.assign(v,D);for(let P of Object.keys(D))m.get(y.field)?.add(P)}return b},u=(y,N)=>{if(!K(y,f[y.id??""]))return N?r:"";let G=y.rules.map(A=>typeof A=="string"?A:w(A)?u(A,y.rules.length===1):i(A)).filter(Boolean);return G.length===0?r:`${y.not?"NOT ":""}(${G.join(de(y)?` ${y.combinator} `:" ")})`};return h?{sql:u(t,!0),params:n}:{sql:u(t,!0),params:v}};var Jo={},Ol=(t,e)=>{let{fields:o,getParseNumberBoolean:l,placeholderFieldName:r,placeholderOperatorName:s,placeholderValueName:a,ruleProcessor:d,validateRule:$,validationMap:p}=e,g=(h,n)=>{if(!K(h,p[h.id??""]))return n?Jo:void 0;let v=h.combinator.toUpperCase(),m=!1,R=h.rules.map(i=>{if(w(i)){let G=g(i);return G?(m=!0,G):void 0}let[u,y]=$(i);if(!K(i,u,y)||i.field===r||i.operator===s||a!==void 0&&i.value===a)return;let N=z(o,i.field);return d(i,{...e,parseNumbers:l(N?.inputType),fieldData:N})}).filter(Boolean);return R.length>0?R.length===1&&!m?R[0]:{[v]:R}:Jo},f=g(Pe(t),!0);return t.not?{NOT:f}:f};var Pl=(t,e)=>{let{fields:o,getParseNumberBoolean:l,placeholderFieldName:r,placeholderOperatorName:s,placeholderValueName:a,ruleProcessor:d,validateRule:$,validationMap:p,context:g={}}=e,{sequelizeOperators:f}=g;if(!f)return;let h=(n,v)=>{if(!K(n,p[n.id??""]))return;let m=n.combinator.toUpperCase(),R=!1,i=n.rules.map(y=>{if(w(y)){let C=h(y);return C?(R=!0,C):void 0}let[N,G]=$(y);if(!K(y,N,G)||y.field===r||y.operator===s||a!==void 0&&y.value===a)return;let A=z(o,y.field);return d(y,{...e,parseNumbers:l(A?.inputType),fieldData:A})}).filter(Boolean);if(i.length===0)return;let u=i.length===1&&!R?i[0]:{[E(m)==="or"?f.or:f.and]:i};return n.not?{[f.not]:u}:u};return h(Pe(t),!0)};var Ko=(t,e)=>{let{fields:o,fallbackExpression:l,getParseNumberBoolean:r,placeholderFieldName:s,placeholderOperatorName:a,placeholderValueName:d,ruleProcessor:$,validateRule:p,validationMap:g}=e,f=(h,n)=>{if(!K(h,g[h.id??""]))return n?l:"";let v=h.rules.map(m=>{if(typeof m=="string")return m;if(w(m))return f(m,h.rules.length===1);let[R,i]=p(m);if(!K(m,R,i)||m.field===s||m.operator===a||d!==void 0&&m.value===d)return"";let u=(m.valueSource??"value")==="value",y=z(o,m.field);return $(m,{...e,parseNumbers:r(y?.inputType),escapeQuotes:u,fieldData:y})}).filter(Boolean);return v.length===0?l:`${h.not?"NOT ":""}(${v.join(de(h)?` ${h.combinator} `:" ")})`};return f(t,!0)};var Yn={"<":"lt","<=":"lte",">":"gt",">=":"gte"},Xo=(t,e)=>t.startsWith("not")||t.startsWith("doesnot")?{bool:{must_not:e}}:e,Pr=t=>t?.replace(/('|\\)/g,"\\$1"),Zn={beginswith:"startsWith",doesnotbeginwith:"startsWith",doesnotcontain:"contains",doesnotendwith:"endsWith",endswith:"endsWith"},ea=(t,e,o)=>{let l=`doc['${t}'].value.${Zn[e]??e}(doc['${o}'].value)`;return e.startsWith("d")?`!${l}`:l},yo=(t,e)=>typeof t=="boolean"?t:L(t,e)?Q(t,{parseNumbers:e}):t,Ml=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{parseNumbers:a,preserveValueOrder:d}=e,$=E(l);if(he(t))return!1;if(s==="field"){if(B(r).some(g=>typeof g!="string"))return!1;let p=Pr(o);switch($){case"=":case"!=":case">":case">=":case"<":case"<=":{let g=$==="="?"==":$,f=Pr(r);return f?{bool:{filter:{script:{script:`doc['${p}'].value ${g} doc['${f}'].value`}}}}:!1}case"in":case"notin":{let g=B(r);if(g.length>0){let f=g.map(h=>({bool:{filter:{script:{script:`doc['${p}'].value == doc['${h}'].value`}}}}));return{bool:$==="in"?{should:f}:{must_not:f}}}return!1}case"between":case"notbetween":{let g=B(r);if(g.length>=2&&g[0]&&g[1]){let f=`doc['${p}'].value >= doc['${g[0]}'].value && doc['${p}'].value <= doc['${g[1]}'].value`;return{bool:{filter:{script:{script:$==="notbetween"?`!(${f})`:f}}}}}return!1}case"contains":case"doesnotcontain":case"beginswith":case"doesnotbeginwith":case"endswith":case"doesnotendwith":{let g=Pr(r);return g?{bool:{filter:{script:{script:ea(p,$,g)}}}}:!1}}}switch($){case"<":case"<=":case">":case">=":return{range:{[o]:{[Yn[$]]:yo(r,a)}}};case"=":return{term:{[o]:yo(r,a)}};case"!=":return{bool:{must_not:{term:{[o]:yo(r,a)}}}};case"null":return{bool:{must_not:{exists:{field:o}}}};case"notnull":return{exists:{field:o}};case"in":case"notin":{let p=B(r).map(g=>yo(g,a));if(p.length>0){let g=p.map(f=>({term:{[o]:yo(f,a)}}));return{bool:$==="in"?{should:g}:{must_not:g}}}return!1}case"between":case"notbetween":{let p=B(r);if(p.length>=2&&ve(p[0])&&ve(p[1])){let[g,f]=p,h=a!==!1;if(L(g,h)&&L(f,h)){let n=Q(g,{parseNumbers:h}),v=Q(f,{parseNumbers:h});if(!d&&v<n){let m=v;f=n,g=m}else g=n,f=v}return Xo($,{range:{[o]:{gte:g,lte:f}}})}return!1}case"contains":case"doesnotcontain":return Xo($,{regexp:{[o]:{value:`.*${r}.*`}}});case"beginswith":case"doesnotbeginwith":return Xo($,{regexp:{[o]:{value:`${r}.*`}}});case"endswith":case"doesnotendwith":return Xo($,{regexp:{[o]:{value:`.*${r}`}}})}return!1};var Yo=t=>t.startsWith("not")||t.startsWith("doesnot"),Zo=(t,e)=>`"${typeof t!="string"||!e?t:t.replaceAll('"','\\"')}"`,Ro=(t,e)=>e?`$not(${t})`:`${t}`,El=t=>`${t}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g,String.raw`\$&`).replaceAll("-",String.raw`\x2d`),Ll=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{escapeQuotes:a,parseNumbers:d,preserveValueOrder:$,quoteFieldNamesWith:p=["",""],fieldIdentifierSeparator:g=""}=e,f=s==="field",h=typeof r=="number"||typeof r=="boolean"||typeof r=="bigint"||L(r,d),n=R=>it(R,{quoteFieldNamesWith:p,fieldIdentifierSeparator:g}),v=he(t);if(v===!1)return;if(v){let{mode:R,threshold:i}=v,u=`$count(${n(o)})`,y=`$count($filter(${n(o)}, function($v) {${Ho(We(r,{ruleProcessor:N=>({...N,field:N.field?`$v.${N.field}`:"$v"})}),e)}}))`;switch(R){case"all":return`${y} = ${u}`;case"none":return`${y} = 0`;case"some":return`${y} > 0`;case"atleast":case"atmost":case"exactly":{let N=R==="atleast"?">=":R==="atmost"?"<=":"=";return i>0&&i<1?`${y} ${N} (${u} * ${i})`:`${y} ${N} ${i}`}}}let m=E(l);switch(m){case"<":case"<=":case"=":case"!=":case">":case">=":return`${n(o)} ${m} ${f?n(ie(r)):h?ie(r):Zo(r,a)}`;case"contains":case"doesnotcontain":return Ro(`$contains(${n(o)}, ${f?n(ie(r)):Zo(r,a)})`,Yo(m));case"beginswith":case"doesnotbeginwith":return Ro(f?`$substring(${n(o)}, 0, $length(${n(ie(r))})) = ${n(ie(r))}`:`$contains(${n(o)}, /^${El(r)}/)`,Yo(m));case"endswith":case"doesnotendwith":return Ro(f?`$substring(${n(o)}, $length(${n(o)}) - $length(${n(ie(r))})) = ${n(ie(r))}`:`$contains(${n(o)}, /${El(r)}$/)`,Yo(m));case"null":return`${n(o)} = null`;case"notnull":return`${n(o)} != null`;case"in":case"notin":{let R=B(r);return Ro(`${n(o)} in [${R.map(i=>f?`${n(ie(i))}`:L(i,d)?`${ie(i)}`:Zo(i,a)).join(", ")}]`,Yo(m))}case"between":case"notbetween":{let R=B(r);if(R.length<2||Ye(R[0])||Ye(R[1]))return"";let[i,u]=R,y=d!==!1,N=L(i,y)?Q(i,{parseNumbers:y}):Number.NaN,G=L(u,y)?Q(u,{parseNumbers:y}):Number.NaN,A=Number.isNaN(N)?f?`${i}`:i:N,C=Number.isNaN(G)?f?`${u}`:u:G;if(!$&&A===N&&C===G&&G<N){let P=G;C=N,A=P}let c=L(i,d)&&L(u,d),b=(P,x)=>f?n(P):c?x:Zo(x,a),D=`${n(o)} >= ${b(i,A)} and ${n(o)} <= ${b(u,C)}`;return m==="between"?`(${D})`:Ro(D,!0)}}return""};var ta=t=>t.replace(/^(=)$/,"$1=").replace(/^notnull$/i,"!=").replace(/^null$/i,"=="),$o=(t,e)=>t.startsWith("not")||t.startsWith("doesnot")?{"!":e}:e,er=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{parseNumbers:a,preserveValueOrder:d}=e,$=s==="field",p={var:o},g=n=>$?{var:`${n}`}:L(n,a)?Q(n,{parseNumbers:a}):n,f=he(t);if(f===!1)return!1;if(f){let{mode:n,threshold:v}=f;switch(n){case"all":case"none":case"some":return{[n]:[{var:o},r.rules.length===1&&!w(r.rules[0])?er(r.rules[0],e):vo(r,e)]};case"atleast":case"atmost":case"exactly":{let m=n==="atleast"?">=":n==="atmost"?"<=":"==",R={reduce:[{filter:[{var:o},r.rules.length===1&&!w(r.rules[0])?er(r.rules[0],e):vo(r,e)]},{"+":[1,{var:"accumulator"}]},0]};if(v>0&&v<1){let i={reduce:[{var:o},{"+":[1,{var:"accumulator"}]},0]};return{[m]:[R,{"*":[i,v]}]}}return{[m]:[R,v]}}}}let h=E(l);switch(h){case"<":case"<=":case"=":case"!=":case">":case">=":return{[ta(h)]:[p,g(r)]};case"null":case"notnull":return{[`${h==="notnull"?"!":"="}=`]:[p,null]};case"in":case"notin":{let n=B(r).map(v=>g(v));return $o(h,{in:[p,n]})}case"between":case"notbetween":{let n=B(r);if(n.length>=2&&ve(n[0])&&ve(n[1])){let[v,m]=n,R=a!==!1;if(!$&&L(v,R)&&L(m,R)){let u=Q(v,{parseNumbers:R}),y=Q(m,{parseNumbers:R});if(!d&&y<u){let N=y;m=u,v=N}else v=u,m=y}else $&&(v={var:v},m={var:m});return $o(h,{"<=":[v,p,m]})}return!1}case"contains":case"doesnotcontain":{let n={in:[g(r),p]};return $o(h,n)}case"beginswith":case"doesnotbeginwith":{let n={startsWith:[p,g(r)]};return $o(h,n)}case"endswith":case"doesnotendwith":{let n={endsWith:[p,g(r)]};return $o(h,n)}}return!1};var Wt=(t,e)=>e?`(!${t})`:`${t}`,Mt=t=>`${ie(t)}`.replaceAll(/[()&|=<>~*\\/]/g,e=>`\\${e.codePointAt(0).toString(16)}`),kl=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,value:r,valueSource:s}=t,{preserveValueOrder:a}=e,d=E(l);if(s==="field"||Ye(r)&&d!=="null"&&d!=="notnull"||he(t))return"";switch(d){case"=":case"!=":return Wt(`(${o}=${Mt(r)})`,d==="!=");case">":case">=":return`(${o}>=${Mt(r)})`;case"<":case"<=":return`(${o}<=${Mt(r)})`;case"contains":case"doesnotcontain":return Wt(`(${o}=*${Mt(r)}*)`,d==="doesnotcontain");case"beginswith":case"doesnotbeginwith":return Wt(`(${o}=${Mt(r)}*)`,d==="doesnotbeginwith");case"endswith":case"doesnotendwith":return Wt(`(${o}=*${Mt(r)})`,d==="doesnotendwith");case"null":case"notnull":return Wt(`(${o}=*)`,d==="notnull");case"in":case"notin":{let $=B(r);return Wt(`(|${$.map(p=>`(${o}=${Mt(p)})`).join("")})`,d==="notin")}case"between":case"notbetween":{let $=B(r);if($.length<2||Ye($[0])||Ye($[1]))return"";let[p,g]=$,f=L(p,!0)?Q(p,{parseNumbers:!0}):Number.NaN,h=L(g,!0)?Q(g,{parseNumbers:!0}):Number.NaN,n=Number.isNaN(f)?p:f,v=Number.isNaN(h)?g:h;if(!a&&n===f&&v===h&&h<f){let m=h;v=f,n=m}return Wt(`(&(${o}>=${Mt(n)})(${o}<=${Mt(v)}))`,d==="notbetween")}}return""};var oa=(t,e,o)=>o&&typeof t=="string"?t.replaceAll(`${e}`,`${e}${e}`):t,tr=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{escapeQuotes:o,fields:l,parseNumbers:r,quoteFieldNamesWith:s,quoteValuesWith:a,fieldIdentifierSeparator:d,translations:$}=e,p=t.valueSource==="field",g=E(t.operator),f=a||"'",h=N=>`${f}${N}${f}`,n=N=>oa(N,f,o),v=N=>h(n(N)),m=N=>it(N,{quoteFieldNamesWith:s,fieldIdentifierSeparator:d}),R=$??{},i=R.or??"or",u=R.true??"true",y=R.false??"false";switch(g){case"null":case"notnull":return"";case"between":case"notbetween":{if(!p)return ft(t,e);let N=B(t.value,{retainEmptyStrings:!0}).slice(0,2).map(G=>m(z(l??[],G)?.label??G));return N.length<2||!ve(N[0])||!ve(N[1])?"":ft({...t,value:N},e)}case"in":case"notin":{let N=B(t.value);if(N.length===0)return"";let G=N.map(A=>p?m(z(l??[],A)?.label??A):L(A,r)?`${ie(A)}`:`${v(A)}`);return`${G.slice(0,-1).join(", ")}${G.length>2?",":""} ${i} ${G.at(-1)}`}}return typeof t.value=="boolean"?t.value?u:y:p?m(z(l??[],t.value)?.label??t.value):L(t.value,r)?`${ie(t.value)}`:`${v(t.value)}`};var Tl={"=":["is","is the same as the value in"],"!=":["is not","is not the same as the value in"],"<":["is less than","is less than the value in"],">":["is greater than","is greater than the value in"],"<=":["is less than or equal to","is less than or equal to the value in"],">=":["is greater than or equal to","is greater than or equal to the value in"],contains:["contains","contains the value in"],beginswith:["starts with","starts with the value in"],endswith:["ends with","ends with the value in"],doesnotcontain:["does not contain","does not contain the value in"],doesnotbeginwith:["does not start with","does not start with the value in"],doesnotendwith:["does not end with","does not end with the value in"],null:"is null",notnull:"is not null",in:["is one of the values","is the same as a value in"],notin:["is not one of the values","is not the same as any value in"],between:["is between","is between the values in"],notbetween:["is not between","is not between the values in"]},ra=()=>[],Mr=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{field:o,operator:l,valueSource:r="value"}=t,{getOperators:s=ra,operatorMap:a=Tl}=e,d=new Map(Object.entries(Tl));for(let[h,n]of Object.entries(a))d.set(E(h),n);let $=Object.fromEntries(d),{value:p,label:g}=z(Se(s(o,{fieldData:e.fieldData??{name:o,value:o,label:o}})??[]),l)??{name:l,value:l,label:l},f=$[p]??$[E(p)]??[g,g];return typeof f=="string"?f:f[r==="field"?1:0]},Vl=(t,e)=>{let{field:o,operator:l}=t,{fieldData:r,quoteFieldNamesWith:s=["",""],fieldIdentifierSeparator:a="",quoteValuesWith:d="'",operatorProcessor:$=Mr,valueProcessor:p=tr,concatOperator:g="||",wordOrder:f="SVO"}=e??{},h=it(r?.label??o,{quoteFieldNamesWith:s,fieldIdentifierSeparator:a}),n=he(t);if(n===!1)return"";if(n){let{mode:u,threshold:y}=n,N=Uo(t.value,{...e,fields:Se(r?.subproperties??[])}),G=(r?.subproperties?.length??0)>0;switch(u){case"all":return`(${G?"for ":""}every item in ${h}${G?",":""} ${N})`;case"none":return`(${G?"for ":""}no item in ${h}${G?",":""} ${N})`;case"some":return`(${G?"for ":""}at least one item in ${h}${G?",":""} ${N})`;case"atleast":case"atmost":case"exactly":{let A=u.replace("at","at ");return y>0&&y<1?`(${G?"for ":""}${A} ${y*100}% of the items in ${h}${G?",":""} ${N})`:`(${G?"for ":""}${A} ${y} of the items in ${h}${G?",":""} ${N})`}}}let v=p(t,{...e,quoteFieldNamesWith:s,fieldIdentifierSeparator:a,quoteValuesWith:d,concatOperator:g}),m=E(l);if((m==="in"||m==="notin"||m==="between"||m==="notbetween")&&!v)return"";let R=$(t,e),i={S:h,V:R,O:v};return xl(f).map(u=>`${i[u]}`).join(" ").trim()};var _t=t=>E(Gl(t.operator)),No=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{quoteFieldNamesWith:o=["",""],fieldIdentifierSeparator:l="",quoteValuesWith:r="'",operatorProcessor:s=_t,valueProcessor:a=ft,concatOperator:d="||"}=e,$=v=>it(v,{quoteFieldNamesWith:o,fieldIdentifierSeparator:l}),p=$(t.field),g=he(t);if(g===!1)return;if(g){if(e?.preset!=="postgresql")return"";let{mode:v,threshold:m}=g,R="elem_alias",i=Ko(We(t.value,{ruleProcessor:u=>({...u,field:R})}),e);switch(v){case"all":return`(select count(*) from unnest(${p}) as ${$(R)} where ${i}) = array_length(${p}, 1)`;case"none":return`not exists (select 1 from unnest(${p}) as ${$(R)} where ${i})`;case"some":return`exists (select 1 from unnest(${p}) as ${$(R)} where ${i})`;case"atleast":case"atmost":case"exactly":{let u=v==="atleast"?">=":v==="atmost"?"<=":"=";return`(select count(*)${m>0&&m<1?` / array_length(${p}, 1)`:""} from unnest(${p}) as ${$(R)} where ${i}) ${u} ${m}`}}}let f=a(t,{...e,quoteFieldNamesWith:o,fieldIdentifierSeparator:l,quoteValuesWith:r,concatOperator:d}),h=s(t,e),n=E(h);return(n==="in"||n==="not in"||n==="between"||n==="not between")&&!f?"":`${p} ${h} ${f}`.trim()};var Er=(t,e,o)=>{let{fieldData:l,format:r,getNextNamedParam:s,parseNumbers:a,paramPrefix:d,paramsKeepPrefix:$,numberedParams:p,quoteFieldNamesWith:g=["",""],fieldIdentifierSeparator:f,concatOperator:h,operatorProcessor:n=_t,valueProcessor:v=ft}=e??{},{processedParams:m=[]}=o??{},R=r==="parameterized",i=[],u={},y=k=>R?{sql:k,params:i}:{sql:k,params:u},N=k=>it(k,{quoteFieldNamesWith:g,fieldIdentifierSeparator:f}),G=N(t.field),A=he(t);if(A===!1)return;if(A){if(e?.preset!=="postgresql")return y("");let{mode:k,threshold:H}=A,T="elem_alias",{sql:q,params:S}=zo(We(t.value,{ruleProcessor:U=>({...U,field:T})}),{...e,fields:[]});switch(Array.isArray(S)?i.push(...S):Object.assign(u,S),k){case"all":return y(`(select count(*) from unnest(${G}) as ${N(T)} where ${q}) = array_length(${G}, 1)`);case"none":return y(`not exists (select 1 from unnest(${G}) as ${N(T)} where ${q})`);case"some":return y(`exists (select 1 from unnest(${G}) as ${N(T)} where ${q})`);case"atleast":case"atmost":case"ex