@andreasnicolaou/typescript-expression-language
Version:
TypeScript implementation of symfony/expression-language
1 lines • 52.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).typescriptExpressionLanguage={})}(this,function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var s,i;var r,n,o=e(i?s:(i=1,s=function(t,e){var s="",i=[],r=0,n=0,o="",a="",h="",c="",l="",u=0,d=0,p=0,f=0,g=0,m=[],v="",y=/%([\dA-Fa-f]+)/g,E=function(t,e){return(t+="").length<e?new Array(++e-t.length).join("0")+t:t};for(r=0;r<e.length;r++)if(o=e.charAt(r),a=e.charAt(r+1),"\\"===o&&a&&/\d/.test(a)){if(f=r+(p=(h=e.slice(r+1).match(/^\d+/)[0]).length)+1,e.charAt(f)+e.charAt(f+1)===".."){if(u=h.charCodeAt(0),/\\\d/.test(e.charAt(f+2)+e.charAt(f+3)))c=e.slice(f+3).match(/^\d+/)[0],r+=1;else{if(!e.charAt(f+2))throw new Error("Range with no end point");c=e.charAt(f+2)}if((d=c.charCodeAt(0))>u)for(n=u;n<=d;n++)i.push(String.fromCharCode(n));else i.push(".",h,c);r+=c.length+2}else l=String.fromCharCode(parseInt(h,8)),i.push(l);r+=p}else if(a+e.charAt(r+2)===".."){if(u=(h=o).charCodeAt(0),/\\\d/.test(e.charAt(r+3)+e.charAt(r+4)))c=e.slice(r+4).match(/^\d+/)[0],r+=1;else{if(!e.charAt(r+3))throw new Error("Range with no end point");c=e.charAt(r+3)}if((d=c.charCodeAt(0))>u)for(n=u;n<=d;n++)i.push(String.fromCharCode(n));else i.push(".",h,c);r+=c.length+2}else i.push(o);for(r=0;r<t.length;r++)if(o=t.charAt(r),-1!==i.indexOf(o))if(s+="\\",(g=o.charCodeAt(0))<32||g>126)switch(o){case"\n":s+="n";break;case"\t":s+="t";break;case"\r":s+="r";break;case"":s+="a";break;case"\v":s+="v";break;case"\b":s+="b";break;case"\f":s+="f";break;default:for(v=encodeURIComponent(o),null!==(m=y.exec(v))&&(s+=E(parseInt(m[1],16).toString(8),3));null!==(m=y.exec(v));)s+="\\"+E(parseInt(m[1],16).toString(8),3)}else s+=o;else s+=o;return s}));var a,h,c=e(function(){if(n)return r;n=1;var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};return r=function(e){return/boolean|number|string/.test(void 0===e?"undefined":t(e))}}());class l{nodes=Object.create(Object.prototype);attributes=Object.create(Object.prototype);constructor(t=Object.create(Object.prototype),e=Object.create(Object.prototype)){this.nodes=t,this.attributes=e}toString(){const t=Object.keys(this.attributes).reduce((t,e)=>(t.push(`${e}: '${this.attributes[e]?this.attributes[e].toString().replace(/\n/g,""):"null"}'`),t),[]),e=[this.constructor.name+"("+t.join(", ")];if(Object.values(this.nodes).length>0){for(const t of Object.values(this.nodes)){const s=t.toString().split("\n");for(const t of s)e.push(" "+t)}e.push(")")}else e[0]+=")";return e.join("\n")}compile(t){for(const e of Object.values(this.nodes))e.compile(t)}evaluate(t,e){const s=[];for(const i of Object.values(this.nodes))s.push(i.evaluate(t,e));return s}toArray(){throw new Error(`Dumping a "${this.constructor.name}" instance is not supported yet.`)}dump(){let t="";for(const e of this.toArray())t+=c(e)?e:e.dump();return t}dumpString(t){return`"${o(t,'\0\t"\\')}"`}isHash(t){let e=0;for(const s of Object.keys(t))if(parseInt(s)!==e++)return!0;return!1}}class u extends l{isNullSafe;isIdentifier;constructor(t,e=!1,s=!1){super({},{value:t}),this.isIdentifier=e,this.isNullSafe=s}compile(t){t.repr(this.attributes.value,this.isIdentifier)}evaluate(t,e){return this.attributes.value}toArray(){const t=[],e=this.attributes.value;if(this.isIdentifier)t.push(e);else if(!0===e)t.push("true");else if(!1===e)t.push("false");else if(null===e)t.push("null");else if("number"==typeof e||"bigint"==typeof e)t.push(e);else if("string"==typeof e)t.push(this.dumpString(e));else if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e)){t.push("[");for(const s of e)t.push(new u(s),", ");t.pop(),t.push("]")}}else{t.push("{");for(const[s,i]of Object.entries(e))t.push(new u(s),": ",new u(i),", ");t.pop(),t.push("}")}return t}}class d extends l{index=-1;keyIndex=-1;arrayNodeType="Array";constructor(){super()}addElement(t,e=null){e?this.arrayNodeType="Array"===this.arrayNodeType?"Object":"Array":e=new u(++this.index),this.nodes[(++this.keyIndex).toString()]=e,this.nodes[(++this.keyIndex).toString()]=t}compile(t){const e="Object"===this.arrayNodeType,s=e?"{":"[",i=e?"}":"]";t.raw(s),this.compileArguments(t,e),t.raw(i)}evaluate(t,e){const s="Array"===this.arrayNodeType,i=s?[]:{};for(const r of this.getKeyValuePairs()){const n=s?void 0:r.key.evaluate(t,e),o=r.value.evaluate(t,e);s?i.push(o):i[n]=o}return i}toArray(){const t=Object.create(Object.prototype);for(const e of this.getKeyValuePairs())t[e.key.attributes.value]=e.value;const e=[];if(this.isHash(t)){e.push("{");for(const[s,i]of Object.entries(t))e.push(new u(s),": ",i,", ");e.pop(),e.push("}")}else{e.push("[");for(const s of Object.values(t))e.push(s,", ");e.pop(),e.push("]")}return e}getKeyValuePairs(){const t=[],e=Object.keys(this.nodes);for(let s=0;s<e.length;s+=2)t.push({key:this.nodes[e[s]],value:this.nodes[e[s+1]]});return t}compileArguments(t,e=!0){for(const[s,i]of this.getKeyValuePairs().entries())s>0&&t.raw(", "),e&&t.compile(i.key).raw(": "),t.compile(i.value)}}class p extends d{compile(t){this.compileArguments(t,!1)}toArray(){const t=[];return this.getKeyValuePairs().forEach((e,s,i)=>{t.push(e.value),s<i.length-1&&t.push(", ")}),t}}var f=e(h?a:(h=1,a=function(t,e,s,i,r){if(s=null==s?1:+s,i=null==i?1:+i,r=null==r?1:+r,t===e)return 0;var n=t.length,o=e.length;if(0===n)return o*s;if(0===o)return n*r;var a=!1;try{a=!"0"[0]}catch(t){a=!0}a&&(t=t.split(""),e=e.split(""));var h=new Array(o+1),c=new Array(o+1),l=void 0,u=void 0,d=void 0,p=void 0,f=void 0,g=void 0;for(u=0;u<=o;u++)h[u]=u*s;for(l=0;l<n;l++){for(c[0]=h[0]+r,u=0;u<o;u++)d=h[u]+(t[l]===e[u]?0:i),(p=h[u+1]+r)<d&&(d=p),(f=c[u]+s)<d&&(d=f),c[u+1]=d;g=h,h=c,c=g}return d=h[o]}));let g=class extends Error{constructor(t,e=null,s="",i=null,r=null){const n=null!=e?` around position ${e}`:"";let o=`${t.replace(/\.$/,"")}${n}`;if(s&&(o=`${o} for expression \`${s}\``),o+=".",null!==i&&null!==r){let t,e=1/0;for(const s of r){const r=f(i,s);void 0!==r&&r<e&&(t=s,e=r)}void 0!==t&&e<3&&(o+=` Did you mean "${t}"?`)}super(o),this.name="SyntaxError"}};class m extends l{static OPERATORS={"~":".",and:"&&",or:"||"};static FUNCTIONS={"**":"pow","..":"range",in:"inArray","not in":"notInArray",contains:"strContains","starts with":"strStartsWith","ends with":"strEndsWith"};constructor(t,e,s){super({left:e,right:s},{operator:t})}compile(t){const e=this.attributes.operator;if("matches"!==e){if(e in m.FUNCTIONS){const s=m.FUNCTIONS[e];return void t.raw(`${s}(`).compile(this.nodes.left).raw(", ").compile(this.nodes.right).raw(")")}t.raw("(").compile(this.nodes.left).raw(` ${m.OPERATORS[e]||e} `).compile(this.nodes.right).raw(")")}else{if(this.nodes.right instanceof u)this.evaluateMatches(this.nodes.right.evaluate({},{}),"");else if(this.nodes.right instanceof m&&"~"!==this.nodes.right.attributes.operator)throw new g('The regex passed to "matches" must be a string.');t.raw('(function (regexp, str) { try { if (regexp.startsWith("/") && regexp.endsWith("/")) { regexp = regexp.slice(1, -1); } return new RegExp(regexp).test(str ?? ""); } catch () { throw new SyntaxError(\'Invalid regex passed to "matches".\'); } })(').compile(this.nodes.right).raw(", ").compile(this.nodes.left).raw(")")}}evaluate(t,e){const s=this.attributes.operator,i=this.nodes.left?.evaluate(t,e);let r=null;if(s in m.FUNCTIONS){const r=this.nodes.right.evaluate(t,e);switch(s){case"in":return this.inArray(i,r);case"not in":return this.notInArray(i,r);case"**":return this.pow(i,r);case"..":return this.range(i,r);case"contains":return this.strContains(i,r);case"starts with":return this.strStartsWith(i,r);case"ends with":return this.strEndsWith(i,r);default:throw new Error(`Unsupported function operator: ${s}`)}}switch(s){case"or":case"||":return i||(r=this.nodes.right.evaluate(t,e)),i||r;case"and":case"&&":return i&&(r=this.nodes.right.evaluate(t,e)),i&&r}switch(r=this.nodes.right.evaluate(t,e),s){case"|":return i|r;case"^":return i^r;case"&":return i&r;case"<<":return i<<r;case">>":return i>>r;case"==":return i==r;case"===":return i===r;case"!=":return i!=r;case"!==":return i!==r;case"<":return i<r;case">":return i>r;case"<=":return i<=r;case">=":return i>=r;case"+":return i+r;case"-":return i-r;case"*":return i*r;case"/":if(0===r)throw new Error("Division by zero.");return i/r;case"%":if(0===r)throw new Error("Modulo by zero.");return i%r;case"matches":return this.evaluateMatches(r,i);case"~":return`${i}${r}`;default:throw new Error(`Operator "${s}" not supported.`)}}toArray(){return["(",this.nodes.left,` ${this.attributes.operator} `,this.nodes.right,")"]}evaluateMatches(t,e){try{return t.startsWith("/")&&t.endsWith("/")&&(t=t.slice(1,-1)),new RegExp(t).test(e??"")}catch(e){throw new g(`Regexp "${t}" passed to "matches" is not valid.[${e}]`)}}pow(t,e){return Math.pow(t,e)}range(t,e){return Array.from({length:e-t+1},(e,s)=>t+s)}inArray(t,e){return e.indexOf(t)>=0}notInArray(t,e){return-1===e.indexOf(t)}strContains(t,e){return t.includes(e)}strStartsWith(t,e){return t.startsWith(e)}strEndsWith(t,e){return t.endsWith(e)}}class v extends l{constructor(t,e,s){super({expr1:t,expr2:e,expr3:s})}compile(t){t.raw("((").compile(this.nodes.expr1).raw(") ? (").compile(this.nodes.expr2).raw(") : (").compile(this.nodes.expr3).raw("))")}evaluate(t,e){return this.nodes.expr1.evaluate(t,e)?this.nodes.expr2.evaluate(t,e):this.nodes.expr3.evaluate(t,e)}toArray(){return["(",this.nodes.expr1," ? ",this.nodes.expr2," : ",this.nodes.expr3,")"]}}class y extends l{constructor(t,e){super({arguments:e},{name:t})}compile(t){const e=[];for(const s of Object.values(this.nodes.arguments.nodes))e.push(t.subcompile(s));t.raw(t.getFunction(this.attributes.name)?.compiler(...e))}evaluate(t,e){const s=[e];for(const i of Object.values(this.nodes.arguments.nodes))s.push(i.evaluate(t,e));return t[this.attributes.name].evaluator(...s)}toArray(){const t=[];t.push(this.attributes.name),t.push("(");for(const e of Object.values(this.nodes.arguments.nodes))t.push(e,", ");return t.pop(),t.push(")"),t}}class E extends l{static PROPERTY_CALL=1;static METHOD_CALL=2;static ARRAY_CALL=3;constructor(t,e,s,i){super({node:t,attribute:e,arguments:s},{type:i,is_null_coalesce:!1,is_short_circuited:!1})}compile(t){const e=this.nodes.attribute instanceof u&&this.nodes.attribute.isNullSafe;switch(this.attributes.type){case E.PROPERTY_CALL:t.compile(this.nodes.node).raw(e?"?.":".").raw(this.nodes.attribute.attributes.value);break;case E.METHOD_CALL:t.compile(this.nodes.node).raw(e?"?.":".").raw(this.nodes.attribute.attributes.value).raw("(").compile(this.nodes.arguments).raw(")");break;case E.ARRAY_CALL:t.compile(this.nodes.node).raw("[").compile(this.nodes.attribute).raw("]")}}evaluate(t,e){const s=this.nodes.node.evaluate(t,e),i=this.nodes.attribute.attributes.value;switch(this.attributes.type){case E.PROPERTY_CALL:if(null===s&&(this.nodes.attribute instanceof u&&this.nodes.attribute.isNullSafe||this.attributes.is_null_coalesce))return this.attributes.is_short_circuited=!0,null;if(null===s&&this.isShortCircuited())return null;if("object"!=typeof s)throw new Error(`Unable to get property "${this.nodes.attribute.dump()}" of non-object "${this.nodes.node.dump()}".`);return this.attributes.is_null_coalesce?s[i]??null:s[i];case E.METHOD_CALL:if(null===s&&this.nodes.attribute instanceof u&&this.nodes.attribute.isNullSafe)return this.attributes.is_short_circuited=!0,null;if(null===s&&this.isShortCircuited())return null;if("object"!=typeof s)throw new Error(`Unable to call method "${this.nodes.attribute.dump()}" of non-object "${this.nodes.node.dump()}".`);if("function"!=typeof s[i])throw new Error(`Unable to call method "${i}" of object "${typeof s}".`);return s[i](...Object.values(this.nodes.arguments.evaluate(t,e)));case E.ARRAY_CALL:if(null===s&&this.isShortCircuited())return null;if("object"!=typeof s&&!(s instanceof Array))throw new Error(`Unable to get an item of non-array "${this.nodes.node.dump()}".`);return this.attributes.is_null_coalesce?s[this.nodes.attribute.evaluate(t,e)]??null:s[this.nodes.attribute.evaluate(t,e)]}}toArray(){const t=this.nodes?.attribute instanceof u&&this.nodes?.attribute?.isNullSafe;switch(this.attributes.type){case E.PROPERTY_CALL:return[this.nodes.node,t?"?.":".",this.nodes.attribute];case E.METHOD_CALL:return[this.nodes.node,t?"?.":".",this.nodes.attribute,"(",this.nodes.arguments,")"];case E.ARRAY_CALL:return[this.nodes.node,"[",this.nodes.attribute,"]"];default:return[]}}isShortCircuited(){return this.attributes.is_short_circuited||this.nodes.node instanceof E&&this.nodes.node.isShortCircuited()}}class T extends l{constructor(t){super({},{name:t})}compile(t){t.raw(`${this.attributes.name}`)}evaluate(t,e){return e[this.attributes.name]}toArray(){return[this.attributes.name]}}class x extends l{constructor(t,e){super({expr1:t,expr2:e},{})}compile(t){t.raw("((").compile(this.nodes.expr1).raw(") ?? (").compile(this.nodes.expr2).raw("))")}evaluate(t,e){return this.nodes.expr1 instanceof E&&this.addNullCoalesceAttributeToGetAttrNodes(this.nodes.expr1),this.nodes.expr1.evaluate(t,e)??this.nodes.expr2.evaluate(t,e)}toArray(){return["(",this.nodes.expr1,") ?? (",this.nodes.expr2,")"]}addNullCoalesceAttributeToGetAttrNodes(t){if(t instanceof E){t.attributes.is_null_coalesce=!0;for(const e of Object.values(t.nodes))this.addNullCoalesceAttributeToGetAttrNodes(e)}}}class A extends l{constructor(t){super({},{name:t})}compile(t){t.raw(`${this.attributes.name} ?? null`)}evaluate(t,e){return null}toArray(){return[`${this.attributes.name} ?? null`]}}class w extends l{static OPERATORS={"!":"!",not:"!","+":"+","-":"-","~":"~"};constructor(t,e){super({node:e},{operator:t})}compile(t){t.raw("(").raw(w.OPERATORS[this.attributes.operator]).compile(this.nodes.node).raw(")")}evaluate(t,e){const s=this.nodes.node.evaluate(t,e);switch(this.attributes.operator){case"not":case"!":return!s;case"-":return-s;case"~":return~s;default:return s}}toArray(){return["(",`${this.attributes.operator} `,this.nodes.node,")"]}}class O{functions;source="";constructor(t){this.functions=t}getFunction(t){return this.functions[t]}getSource(){return this.source}reset(){return this.source="",this}compile(t){return t.compile(this),this}subcompile(t){const e=this.source;this.source="",t.compile(this);const s=this.source;return this.source=e,s}raw(t){return this.source+=t,this}string(t){return this.source+=`"${o(t??"",'\0\t"\\')}"`,this}repr(t,e=!1){if(e)this.raw(t);else if(Number.isInteger(t)||+t===t&&(!isFinite(t)||t%1))this.raw(""+t);else if(null===t)this.raw("null");else if("boolean"==typeof t)this.raw(t?"true":"false");else if("object"!=typeof t||Array.isArray(t))if(Array.isArray(t)){this.raw("[");let e=!0;for(const s of t)e||this.raw(", "),e=!1,this.repr(s);this.raw("]")}else this.string(t);else{this.raw("{");let e=!0;for(const s of Object.keys(t))e||this.raw(", "),e=!1,this.repr(s),this.raw(":"),this.repr(t[s]);this.raw("}")}return this}}class b{expression;constructor(t){this.expression=t}toString(){return this.expression}}class S{name;compiler;evaluator;constructor(t,e,s){this.name=t,this.compiler=e,this.evaluator=s}static fromJs(t,e,s){const i=e||S.resolveJsFunction(t);if("function"!=typeof i)throw new Error(`JavaScript function "${t}" does not exist.`);return new S(s??t,(...e)=>{const i=e.map(t=>t instanceof RegExp?t.toString():"object"==typeof t&&null!==t?JSON.stringify(t):String(t));return`${s??t}(${i.join(", ")})`},(t,...e)=>i(...e))}getName(){return this.name}getCompiler(){return this.compiler}getEvaluator(){return this.evaluator}static resolveJsFunction(t){const e={keys:Object.keys,values:Object.values,isArray:Array.isArray,stringify:JSON.stringify,parse:JSON.parse,concat:(...t)=>t.flat(),from:Array.from,of:Array.of,charAt:(t,e)=>t.charAt(e),charCodeAt:(t,e)=>t.charCodeAt(e),includes:(t,e)=>t.includes(e),indexOf:(t,e)=>t.indexOf(e),split:(t,e)=>t.split(e),trim:t=>t.trim(),toUpperCase:t=>t.toUpperCase(),toLowerCase:t=>t.toLowerCase(),isFinite:Number.isFinite,isInteger:Number.isInteger,isNaN:Number.isNaN,toFixed:(t,e)=>t.toFixed(e),now:Date.now,toISOString:t=>t.toISOString(),toDateString:t=>t.toDateString(),getTime:t=>t.getTime(),getFullYear:t=>t.getFullYear(),getMonth:t=>t.getMonth(),getDay:t=>t.getDay(),getMinutes:t=>t.getMinutes(),test:(t,e)=>t.test(e),exec:(t,e)=>t.exec(e),decodeURI:decodeURI,encodeURI:encodeURI,decodeURIComponent:decodeURIComponent,encodeURIComponent:encodeURIComponent};return Object.getOwnPropertyNames(Math).forEach(t=>{"function"==typeof Math[t]&&(e[t]=Math[t])}),e[t]||globalThis[t]}}var _,N;var R=e(N?_:(N=1,_=function(t){return t+="",encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")}));const P="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,L=new Set,F="object"==typeof process&&process?process:{},I=(t,e,s,i)=>{"function"==typeof F.emitWarning?F.emitWarning(t,e,s,i):console.error(`[${s}] ${e}: ${t}`)};let C=globalThis.AbortController,U=globalThis.AbortSignal;if(void 0===C){U=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},C=class{constructor(){e()}signal=new U;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==F.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,I("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const k=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),z=t=>k(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?j:null:null;class j extends Array{constructor(t){super(t),this.fill(0)}}class M{heap;length;static#t=!1;static create(t){const e=z(t);if(!e)return[];M.#t=!0;const s=new M(t,e);return M.#t=!1,s}constructor(t,e){if(!M.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class Y{#e;#s;#i;#r;#n;#o;#a;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#h;#c;#l;#u;#d;#p;#f;#g;#m;#v;#y;#E;#T;#x;#A;#w;#O;#b;static unsafeExposeInternals(t){return{starts:t.#T,ttls:t.#x,sizes:t.#E,keyMap:t.#l,keyList:t.#u,valList:t.#d,next:t.#p,prev:t.#f,get head(){return t.#g},get tail(){return t.#m},free:t.#v,isBackgroundFetch:e=>t.#S(e),backgroundFetch:(e,s,i,r)=>t.#_(e,s,i,r),moveToTail:e=>t.#N(e),indexes:e=>t.#R(e),rindexes:e=>t.#P(e),isStale:e=>t.#L(e)}}get max(){return this.#e}get maxSize(){return this.#s}get calculatedSize(){return this.#c}get size(){return this.#h}get fetchMethod(){return this.#o}get memoMethod(){return this.#a}get dispose(){return this.#i}get onInsert(){return this.#r}get disposeAfter(){return this.#n}constructor(t){const{max:e=0,ttl:s,ttlResolution:i=1,ttlAutopurge:r,updateAgeOnGet:n,updateAgeOnHas:o,allowStale:a,dispose:h,onInsert:c,disposeAfter:l,noDisposeOnSet:u,noUpdateTTL:d,maxSize:p=0,maxEntrySize:f=0,sizeCalculation:g,fetchMethod:m,memoMethod:v,noDeleteOnFetchRejection:y,noDeleteOnStaleGet:E,allowStaleOnFetchRejection:T,allowStaleOnFetchAbort:x,ignoreFetchAbort:A}=t;if(0!==e&&!k(e))throw new TypeError("max option must be a nonnegative integer");const w=e?z(e):Array;if(!w)throw new Error("invalid max value: "+e);if(this.#e=e,this.#s=p,this.maxEntrySize=f||this.#s,this.sizeCalculation=g,this.sizeCalculation){if(!this.#s&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==v&&"function"!=typeof v)throw new TypeError("memoMethod must be a function if defined");if(this.#a=v,void 0!==m&&"function"!=typeof m)throw new TypeError("fetchMethod must be a function if specified");if(this.#o=m,this.#w=!!m,this.#l=new Map,this.#u=new Array(e).fill(void 0),this.#d=new Array(e).fill(void 0),this.#p=new w(e),this.#f=new w(e),this.#g=0,this.#m=0,this.#v=M.create(e),this.#h=0,this.#c=0,"function"==typeof h&&(this.#i=h),"function"==typeof c&&(this.#r=c),"function"==typeof l?(this.#n=l,this.#y=[]):(this.#n=void 0,this.#y=void 0),this.#A=!!this.#i,this.#b=!!this.#r,this.#O=!!this.#n,this.noDisposeOnSet=!!u,this.noUpdateTTL=!!d,this.noDeleteOnFetchRejection=!!y,this.allowStaleOnFetchRejection=!!T,this.allowStaleOnFetchAbort=!!x,this.ignoreFetchAbort=!!A,0!==this.maxEntrySize){if(0!==this.#s&&!k(this.#s))throw new TypeError("maxSize must be a positive integer if specified");if(!k(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#F()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!E,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!o,this.ttlResolution=k(i)||0===i?i:1,this.ttlAutopurge=!!r,this.ttl=s||0,this.ttl){if(!k(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#I()}if(0===this.#e&&0===this.ttl&&0===this.#s)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#s){const t="LRU_CACHE_UNBOUNDED";if((t=>!L.has(t))(t)){L.add(t);I("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,Y)}}}getRemainingTTL(t){return this.#l.has(t)?1/0:0}#I(){const t=new j(this.#e),e=new j(this.#e);this.#x=t,this.#T=e,this.#C=(s,i,r=P.now())=>{if(e[s]=0!==i?r:0,t[s]=i,0!==i&&this.ttlAutopurge){const t=setTimeout(()=>{this.#L(s)&&this.#U(this.#u[s],"expire")},i+1);t.unref&&t.unref()}},this.#k=s=>{e[s]=0!==t[s]?P.now():0},this.#z=(r,n)=>{if(t[n]){const o=t[n],a=e[n];if(!o||!a)return;r.ttl=o,r.start=a,r.now=s||i();const h=r.now-a;r.remainingTTL=o-h}};let s=0;const i=()=>{const t=P.now();if(this.ttlResolution>0){s=t;const e=setTimeout(()=>s=0,this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=r=>{const n=this.#l.get(r);if(void 0===n)return 0;const o=t[n],a=e[n];if(!o||!a)return 1/0;return o-((s||i())-a)},this.#L=r=>{const n=e[r],o=t[r];return!!o&&!!n&&(s||i())-n>o}}#k=()=>{};#z=()=>{};#C=()=>{};#L=()=>!1;#F(){const t=new j(this.#e);this.#c=0,this.#E=t,this.#j=e=>{this.#c-=t[e],t[e]=0},this.#M=(t,e,s,i)=>{if(this.#S(e))return 0;if(!k(s)){if(!i)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof i)throw new TypeError("sizeCalculation must be a function");if(s=i(e,t),!k(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return s},this.#Y=(e,s,i)=>{if(t[e]=s,this.#s){const s=this.#s-t[e];for(;this.#c>s;)this.#D(!0)}this.#c+=t[e],i&&(i.entrySize=s,i.totalCalculatedSize=this.#c)}}#j=t=>{};#Y=(t,e,s)=>{};#M=(t,e,s,i)=>{if(s||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#R({allowStale:t=this.allowStale}={}){if(this.#h)for(let e=this.#m;this.#$(e)&&(!t&&this.#L(e)||(yield e),e!==this.#g);)e=this.#f[e]}*#P({allowStale:t=this.allowStale}={}){if(this.#h)for(let e=this.#g;this.#$(e)&&(!t&&this.#L(e)||(yield e),e!==this.#m);)e=this.#p[e]}#$(t){return void 0!==t&&this.#l.get(this.#u[t])===t}*entries(){for(const t of this.#R())void 0===this.#d[t]||void 0===this.#u[t]||this.#S(this.#d[t])||(yield[this.#u[t],this.#d[t]])}*rentries(){for(const t of this.#P())void 0===this.#d[t]||void 0===this.#u[t]||this.#S(this.#d[t])||(yield[this.#u[t],this.#d[t]])}*keys(){for(const t of this.#R()){const e=this.#u[t];void 0===e||this.#S(this.#d[t])||(yield e)}}*rkeys(){for(const t of this.#P()){const e=this.#u[t];void 0===e||this.#S(this.#d[t])||(yield e)}}*values(){for(const t of this.#R()){void 0===this.#d[t]||this.#S(this.#d[t])||(yield this.#d[t])}}*rvalues(){for(const t of this.#P()){void 0===this.#d[t]||this.#S(this.#d[t])||(yield this.#d[t])}}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(const s of this.#R()){const i=this.#d[s],r=this.#S(i)?i.__staleWhileFetching:i;if(void 0!==r&&t(r,this.#u[s],this))return this.get(this.#u[s],e)}}forEach(t,e=this){for(const s of this.#R()){const i=this.#d[s],r=this.#S(i)?i.__staleWhileFetching:i;void 0!==r&&t.call(e,r,this.#u[s],this)}}rforEach(t,e=this){for(const s of this.#P()){const i=this.#d[s],r=this.#S(i)?i.__staleWhileFetching:i;void 0!==r&&t.call(e,r,this.#u[s],this)}}purgeStale(){let t=!1;for(const e of this.#P({allowStale:!0}))this.#L(e)&&(this.#U(this.#u[e],"expire"),t=!0);return t}info(t){const e=this.#l.get(t);if(void 0===e)return;const s=this.#d[e],i=this.#S(s)?s.__staleWhileFetching:s;if(void 0===i)return;const r={value:i};if(this.#x&&this.#T){const t=this.#x[e],s=this.#T[e];if(t&&s){const e=t-(P.now()-s);r.ttl=e,r.start=Date.now()}}return this.#E&&(r.size=this.#E[e]),r}dump(){const t=[];for(const e of this.#R({allowStale:!0})){const s=this.#u[e],i=this.#d[e],r=this.#S(i)?i.__staleWhileFetching:i;if(void 0===r||void 0===s)continue;const n={value:r};if(this.#x&&this.#T){n.ttl=this.#x[e];const t=P.now()-this.#T[e];n.start=Math.floor(Date.now()-t)}this.#E&&(n.size=this.#E[e]),t.unshift([s,n])}return t}load(t){this.clear();for(const[e,s]of t){if(s.start){const t=Date.now()-s.start;s.start=P.now()-t}this.set(e,s.value,s)}}set(t,e,s={}){if(void 0===e)return this.delete(t),this;const{ttl:i=this.ttl,start:r,noDisposeOnSet:n=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:a}=s;let{noUpdateTTL:h=this.noUpdateTTL}=s;const c=this.#M(t,e,s.size||0,o);if(this.maxEntrySize&&c>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#U(t,"set"),this;let l=0===this.#h?void 0:this.#l.get(t);if(void 0===l)l=0===this.#h?this.#m:0!==this.#v.length?this.#v.pop():this.#h===this.#e?this.#D(!1):this.#h,this.#u[l]=t,this.#d[l]=e,this.#l.set(t,l),this.#p[this.#m]=l,this.#f[l]=this.#m,this.#m=l,this.#h++,this.#Y(l,c,a),a&&(a.set="add"),h=!1,this.#b&&this.#r?.(e,t,"add");else{this.#N(l);const s=this.#d[l];if(e!==s){if(this.#w&&this.#S(s)){s.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=s;void 0===e||n||(this.#A&&this.#i?.(e,t,"set"),this.#O&&this.#y?.push([e,t,"set"]))}else n||(this.#A&&this.#i?.(s,t,"set"),this.#O&&this.#y?.push([s,t,"set"]));if(this.#j(l),this.#Y(l,c,a),this.#d[l]=e,a){a.set="replace";const t=s&&this.#S(s)?s.__staleWhileFetching:s;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update");this.#b&&this.onInsert?.(e,t,e===s?"update":"replace")}if(0===i||this.#x||this.#I(),this.#x&&(h||this.#C(l,i,r),a&&this.#z(a,l)),!n&&this.#O&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}return this}pop(){try{for(;this.#h;){const t=this.#d[this.#g];if(this.#D(!0),this.#S(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#O&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}}}#D(t){const e=this.#g,s=this.#u[e],i=this.#d[e];return this.#w&&this.#S(i)?i.__abortController.abort(new Error("evicted")):(this.#A||this.#O)&&(this.#A&&this.#i?.(i,s,"evict"),this.#O&&this.#y?.push([i,s,"evict"])),this.#j(e),t&&(this.#u[e]=void 0,this.#d[e]=void 0,this.#v.push(e)),1===this.#h?(this.#g=this.#m=0,this.#v.length=0):this.#g=this.#p[e],this.#l.delete(s),this.#h--,e}has(t,e={}){const{updateAgeOnHas:s=this.updateAgeOnHas,status:i}=e,r=this.#l.get(t);if(void 0!==r){const t=this.#d[r];if(this.#S(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#L(r))return s&&this.#k(r),i&&(i.has="hit",this.#z(i,r)),!0;i&&(i.has="stale",this.#z(i,r))}else i&&(i.has="miss");return!1}peek(t,e={}){const{allowStale:s=this.allowStale}=e,i=this.#l.get(t);if(void 0===i||!s&&this.#L(i))return;const r=this.#d[i];return this.#S(r)?r.__staleWhileFetching:r}#_(t,e,s,i){const r=void 0===e?void 0:this.#d[e];if(this.#S(r))return r;const n=new C,{signal:o}=s;o?.addEventListener("abort",()=>n.abort(o.reason),{signal:n.signal});const a={signal:n.signal,options:s,context:i},h=(i,r=!1)=>{const{aborted:o}=n.signal,h=s.ignoreFetchAbort&&void 0!==i;if(s.status&&(o&&!r?(s.status.fetchAborted=!0,s.status.fetchError=n.signal.reason,h&&(s.status.fetchAbortIgnored=!0)):s.status.fetchResolved=!0),o&&!h&&!r)return c(n.signal.reason);const u=l;return this.#d[e]===l&&(void 0===i?u.__staleWhileFetching?this.#d[e]=u.__staleWhileFetching:this.#U(t,"fetch"):(s.status&&(s.status.fetchUpdated=!0),this.set(t,i,a.options))),i},c=i=>{const{aborted:r}=n.signal,o=r&&s.allowStaleOnFetchAbort,a=o||s.allowStaleOnFetchRejection,h=a||s.noDeleteOnFetchRejection,c=l;if(this.#d[e]===l){!h||void 0===c.__staleWhileFetching?this.#U(t,"fetch"):o||(this.#d[e]=c.__staleWhileFetching)}if(a)return s.status&&void 0!==c.__staleWhileFetching&&(s.status.returnedStale=!0),c.__staleWhileFetching;if(c.__returned===c)throw i};s.status&&(s.status.fetchDispatched=!0);const l=new Promise((e,i)=>{const o=this.#o?.(t,r,a);o&&o instanceof Promise&&o.then(t=>e(void 0===t?void 0:t),i),n.signal.addEventListener("abort",()=>{s.ignoreFetchAbort&&!s.allowStaleOnFetchAbort||(e(void 0),s.allowStaleOnFetchAbort&&(e=t=>h(t,!0)))})}).then(h,t=>(s.status&&(s.status.fetchRejected=!0,s.status.fetchError=t),c(t))),u=Object.assign(l,{__abortController:n,__staleWhileFetching:r,__returned:void 0});return void 0===e?(this.set(t,u,{...a.options,status:void 0}),e=this.#l.get(t)):this.#d[e]=u,u}#S(t){if(!this.#w)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof C}async fetch(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:a=0,sizeCalculation:h=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:d=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:f,forceRefresh:g=!1,status:m,signal:v}=e;if(!this.#w)return m&&(m.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:r,status:m});const y={allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:r,ttl:n,noDisposeOnSet:o,size:a,sizeCalculation:h,noUpdateTTL:c,noDeleteOnFetchRejection:l,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:p,ignoreFetchAbort:d,status:m,signal:v};let E=this.#l.get(t);if(void 0===E){m&&(m.fetch="miss");const e=this.#_(t,E,y,f);return e.__returned=e}{const e=this.#d[E];if(this.#S(e)){const t=s&&void 0!==e.__staleWhileFetching;return m&&(m.fetch="inflight",t&&(m.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const r=this.#L(E);if(!g&&!r)return m&&(m.fetch="hit"),this.#N(E),i&&this.#k(E),m&&this.#z(m,E),e;const n=this.#_(t,E,y,f),o=void 0!==n.__staleWhileFetching&&s;return m&&(m.fetch=r?"stale":"refresh",o&&r&&(m.returnedStale=!0)),o?n.__staleWhileFetching:n.__returned=n}}async forceFetch(t,e={}){const s=await this.fetch(t,e);if(void 0===s)throw new Error("fetch() returned undefined");return s}memo(t,e={}){const s=this.#a;if(!s)throw new Error("no memoMethod provided to constructor");const{context:i,forceRefresh:r,...n}=e,o=this.get(t,n);if(!r&&void 0!==o)return o;const a=s(t,o,{options:n,context:i});return this.set(t,a,n),a}get(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,status:n}=e,o=this.#l.get(t);if(void 0!==o){const e=this.#d[o],a=this.#S(e);return n&&this.#z(n,o),this.#L(o)?(n&&(n.get="stale"),a?(n&&s&&void 0!==e.__staleWhileFetching&&(n.returnedStale=!0),s?e.__staleWhileFetching:void 0):(r||this.#U(t,"expire"),n&&s&&(n.returnedStale=!0),s?e:void 0)):(n&&(n.get="hit"),a?e.__staleWhileFetching:(this.#N(o),i&&this.#k(o),e))}n&&(n.get="miss")}#W(t,e){this.#f[e]=t,this.#p[t]=e}#N(t){t!==this.#m&&(t===this.#g?this.#g=this.#p[t]:this.#W(this.#f[t],this.#p[t]),this.#W(this.#m,t),this.#m=t)}delete(t){return this.#U(t,"delete")}#U(t,e){let s=!1;if(0!==this.#h){const i=this.#l.get(t);if(void 0!==i)if(s=!0,1===this.#h)this.#G(e);else{this.#j(i);const s=this.#d[i];if(this.#S(s)?s.__abortController.abort(new Error("deleted")):(this.#A||this.#O)&&(this.#A&&this.#i?.(s,t,e),this.#O&&this.#y?.push([s,t,e])),this.#l.delete(t),this.#u[i]=void 0,this.#d[i]=void 0,i===this.#m)this.#m=this.#f[i];else if(i===this.#g)this.#g=this.#p[i];else{const t=this.#f[i];this.#p[t]=this.#p[i];const e=this.#p[i];this.#f[e]=this.#f[i]}this.#h--,this.#v.push(i)}}if(this.#O&&this.#y?.length){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}return s}clear(){return this.#G("delete")}#G(t){for(const e of this.#P({allowStale:!0})){const s=this.#d[e];if(this.#S(s))s.__abortController.abort(new Error("deleted"));else{const i=this.#u[e];this.#A&&this.#i?.(s,i,t),this.#O&&this.#y?.push([s,i,t])}}if(this.#l.clear(),this.#d.fill(void 0),this.#u.fill(void 0),this.#x&&this.#T&&(this.#x.fill(0),this.#T.fill(0)),this.#E&&this.#E.fill(0),this.#g=0,this.#m=0,this.#v.length=0,this.#c=0,this.#h=0,this.#O&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}}}class D{type;value;cursor;static EOF_TYPE="end of expression";static NAME_TYPE="name";static NUMBER_TYPE="number";static STRING_TYPE="string";static OPERATOR_TYPE="operator";static PUNCTUATION_TYPE="punctuation";constructor(t,e,s){this.type=t,this.value=e,this.cursor=s}toString(){return`${this.cursor?this.cursor.toString().padStart(3," "):" "} ${this.type.toUpperCase().padEnd(11," ")} ${this.value}`}test(t,e=null){return this.type===t&&(null===e||this.value==e)}}class ${tokens;expression;current;position=0;constructor(t,e=""){if(this.tokens=t,this.expression=e,0===t.length)throw new Error("TokenStream requires at least one token.");this.current=t[0]}toString(){return this.tokens.join("\n")}next(){if(++this.position,!this.tokens[this.position])throw new g("Unexpected end of expression",this.current.cursor??0,this.expression);this.current=this.tokens[this.position]}expect(t,e=null,s=null){const i=this.current;if(!i.test(t,e)){const t=e?[e]:null;throw new g(s?`${s}. `:"",i.cursor??0,this.expression,i.value,t)}this.next()}isEOF(){return this.current.type===D.EOF_TYPE}getExpression(){return this.expression}}class W{static OPERATORS=["starts with","ends with","contains","matches","not in","===","!==","&&","||","==","!=",">=","<=","<<",">>","**","..","and","not","or","in","!","|","^","&","<",">","+","-","~","*","/","%"];static NUMBER_REGEX=/^(?:\d[\d_]*(?:\.\d[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d[\d_]*)?/;static STRING_REGEX=/^"([^"\\]*(?:\\.[^"\\]*)*)"|^'([^'\\]*(?:\\.[^'\\]*)*)'/s;static COMMENT_REGEX=/^\/\*\*[\s\S]*?\*\/|^\/\*[\s\S]*?\*\//;static NAME_REGEX=/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/;tokenize(t){let e=0;const s=[],i=[],r=(t=t.toString().replace(/[\r\n\t\v\f]/g," ")).length;for(;e<r;){if(" "===t[e]){e++;continue}const r=W.NUMBER_REGEX.exec(t.slice(e));if(r){const t=r[0],i=t.replace(/_/g,"");s.push(new D(D.NUMBER_TYPE,+i,e+1)),e+=t.length;continue}if("([{".includes(t[e])){i.push([t[e],e]),s.push(new D(D.PUNCTUATION_TYPE,t[e],e+1)),e++;continue}if(")]}".includes(t[e])){if(0===i.length)throw new g(`Unexpected "${t[e]}"`,e,t);const r=i.pop();if(r){const[s,i]=r;if(t[e]!=={"(":")","[":"]","{":"}"}[s])throw new g(`Unclosed "${s}"`,i,t)}s.push(new D(D.PUNCTUATION_TYPE,t[e],e+1)),e++;continue}const n=W.STRING_REGEX.exec(t.slice(e));if(null!=n){s.push(new D(D.STRING_TYPE,n[1]||n[2],e+1)),e+=n[0].length;continue}const o=W.COMMENT_REGEX.exec(t.slice(e));if(null!=o){e+=o[0].length;continue}const a=this.extractOperator(t.slice(e),t,e);if(a){s.push(new D(D.OPERATOR_TYPE,a,e+1)),e+=a.length;continue}if("?"===t[e]&&"."===t[e+1]){s.push(new D(D.PUNCTUATION_TYPE,"?.",e+1)),e+=2;continue}if("?"===t[e]&&"?"===t[e+1]){s.push(new D(D.PUNCTUATION_TYPE,"??",e+1)),e+=2;continue}if(",.:?".includes(t[e])){s.push(new D(D.PUNCTUATION_TYPE,t[e],e+1)),e++;continue}const h=W.NAME_REGEX.exec(t.slice(e));if(null==h)throw new g(`Unexpected character "${t[e]}"`,e,t);s.push(new D(D.NAME_TYPE,h[0],e+1)),e+=h[0].length}if(s.push(new D(D.EOF_TYPE,null,e+1)),i.length>0){const e=i.pop();if(e){const[s,i]=e;throw new g(`Unclosed "${s}"`,i,t)}}return new $(s,t)}extractOperator(t,e,s){for(const i of W.OPERATORS)if(t.startsWith(i)){const t=s+i.length,r=e[s-1]||" ",n=e[t]||" ";if(!W.OPERATORS.filter(t=>/^[a-z ]+$/i.test(t)).includes(i))return i;if(""===r.trim()&&""===n.trim())return i}return null}}class G extends b{nodes;constructor(t,e){super(t),this.nodes=e}getNodes(){return this.nodes}}class B{functions;static OPERATOR_LEFT=1;static OPERATOR_RIGHT=2;static IGNORE_UNKNOWN_VARIABLES=1;static IGNORE_UNKNOWN_FUNCTIONS=2;static unaryOperators={not:{precedence:50},"!":{precedence:50},"-":{precedence:500},"+":{precedence:500},"~":{precedence:500}};static binaryOperators={or:{precedence:10,associativity:B.OPERATOR_LEFT},"||":{precedence:10,associativity:B.OPERATOR_LEFT},and:{precedence:15,associativity:B.OPERATOR_LEFT},"&&":{precedence:15,associativity:B.OPERATOR_LEFT},"|":{precedence:16,associativity:B.OPERATOR_LEFT},"^":{precedence:17,associativity:B.OPERATOR_LEFT},"&":{precedence:18,associativity:B.OPERATOR_LEFT},"==":{precedence:20,associativity:B.OPERATOR_LEFT},"===":{precedence:20,associativity:B.OPERATOR_LEFT},"!=":{precedence:20,associativity:B.OPERATOR_LEFT},"!==":{precedence:20,associativity:B.OPERATOR_LEFT},"<":{precedence:20,associativity:B.OPERATOR_LEFT},">":{precedence:20,associativity:B.OPERATOR_LEFT},">=":{precedence:20,associativity:B.OPERATOR_LEFT},"<=":{precedence:20,associativity:B.OPERATOR_LEFT},"not in":{precedence:20,associativity:B.OPERATOR_LEFT},in:{precedence:20,associativity:B.OPERATOR_LEFT},contains:{precedence:20,associativity:B.OPERATOR_LEFT},"starts with":{precedence:20,associativity:B.OPERATOR_LEFT},"ends with":{precedence:20,associativity:B.OPERATOR_LEFT},matches:{precedence:20,associativity:B.OPERATOR_LEFT},"..":{precedence:25,associativity:B.OPERATOR_LEFT},"<<":{precedence:25,associativity:B.OPERATOR_LEFT},">>":{precedence:25,associativity:B.OPERATOR_LEFT},"+":{precedence:30,associativity:B.OPERATOR_LEFT},"-":{precedence:30,associativity:B.OPERATOR_LEFT},"~":{precedence:40,associativity:B.OPERATOR_LEFT},"*":{precedence:60,associativity:B.OPERATOR_LEFT},"/":{precedence:60,associativity:B.OPERATOR_LEFT},"%":{precedence:60,associativity:B.OPERATOR_LEFT},"**":{precedence:200,associativity:B.OPERATOR_RIGHT}};stream;names;flags=0;constructor(t){this.functions=t}parse(t,e=[],s=0){return this.doParse(t,e,s)}lint(t,e=[],s=0){null===e&&(console.warn('Passing "null" as the second argument of "lint()" is deprecated. Use "Parser.IGNORE_UNKNOWN_VARIABLES" instead.'),s|=B.IGNORE_UNKNOWN_VARIABLES,e=[]),this.doParse(t,e,s)}parseExpression(t=0){let e=this.getPrimary(),s=this.stream.current;for(;s.test(D.OPERATOR_TYPE)&&null!==s.value&&void 0!==B.binaryOperators[s.value]&&null!==B.binaryOperators[s.value]&&B.binaryOperators[s.value].precedence>=t;){const t=B.binaryOperators[s.value];this.stream.next();const i=this.parseExpression(t.associativity===B.OPERATOR_LEFT?t.precedence+1:t.precedence);e=new m(s.value.toString(),e,i),s=this.stream.current}return 0===t?this.parseConditionalExpression(e):e}parsePrimaryExpression(){const t=this.stream.current;switch(t.type){case D.NAME_TYPE:switch(this.stream.next(),t.value){case"true":case"TRUE":return new u(!0);case"false":case"FALSE":return new u(!1);case"null":case"NULL":return new u(null);default:if("("===this.stream.current.value){if(!(this.flags&B.IGNORE_UNKNOWN_FUNCTIONS||null===t.value||this.functions[t.value]))throw new g(`The function "${t.value}" does not exist.`,t.cursor,this.stream.expression,t.value,Object.keys(this.functions));return this.parsePostfixExpression(new y(t.value,this.parseArguments()))}if(!(this.flags&B.IGNORE_UNKNOWN_VARIABLES)&&null!==t.value){const e=(Array.isArray(this.names)?this.names:[this.names]).reduce((t,e)=>("object"==typeof e&&null!==e?t.push(...Object.entries(e).map(([t,e])=>({original:e,mapped:t}))):t.push({original:e,mapped:e}),t),[]);if(!e.find(e=>e.original===t.value)){if(this.stream.current.test(D.PUNCTUATION_TYPE,"??"))return new A(t.value);throw new g(`Variable "${t.value}" is not valid.`,t.cursor,this.stream.expression,t.value,e.map(t=>t.original))}const s=e.find(e=>e.original===t.value);s&&(t.value=s.mapped)}return this.parsePostfixExpression(new T(t.value))}case D.NUMBER_TYPE:case D.STRING_TYPE:return this.stream.next(),new u(t.value);default:if(t.test(D.PUNCTUATION_TYPE,"["))return this.parsePostfixExpression(this.parseArrayExpression());if(t.test(D.PUNCTUATION_TYPE,"{"))return this.parsePostfixExpression(this.parseHashExpression());throw new g(`Unexpected token "${this.stream.current.type}" of value "${this.stream.current.value}"`,t.cursor,this.stream.expression,t.value)}}parseArrayExpression(){this.stream.expect(D.PUNCTUATION_TYPE,"[","An array element was expected");const t=new d;let e=!0;for(;!this.stream.current.test(D.PUNCTUATION_TYPE,"]")&&(e||(this.stream.expect(D.PUNCTUATION_TYPE,",","An array element must be followed by a comma"),!this.stream.current.test(D.PUNCTUATION_TYPE,"]")));)e=!1,t.addElement(this.parseExpression());return this.stream.expect(D.PUNCTUATION_TYPE,"]","An opened array is not properly closed"),t}parseHashExpression(){this.stream.expect(D.PUNCTUATION_TYPE,"{","A hash element was expected");const t=new d;let e=!0;for(;!this.stream.current.test(D.PUNCTUATION_TYPE,"}")&&(e||(this.stream.expect(D.PUNCTUATION_TYPE,",","A hash value must be followed by a comma"),!this.stream.current.test(D.PUNCTUATION_TYPE,"}")));){let s;if(e=!1,this.stream.current.test(D.STRING_TYPE)||this.stream.current.test(D.NAME_TYPE)||this.stream.current.test(D.NUMBER_TYPE))s=new u(this.stream.current.value),this.stream.next();else{if(!this.stream.current.test(D.PUNCTUATION_TYPE,"("))throw new g(`A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "${this.stream.current.type}" with value "${this.stream.current.value}").`,this.stream.current.cursor,"");s=this.parseExpression()}this.stream.expect(D.PUNCTUATION_TYPE,":","A hash key must be followed by a colon (:)");const i=this.parseExpression();t.addElement(i,s)}return this.stream.expect(D.PUNCTUATION_TYPE,"}","An opened hash is not properly closed"),t}parsePostfixExpression(t){let e=this.stream.current;for(;e.type===D.PUNCTUATION_TYPE;){if("."===e.value||"?."===e.value){const s="?."===e.value;if(this.stream.next(),e=this.stream.current,this.stream.next(),e.type!==D.NAME_TYPE&&(e.type!==D.OPERATOR_TYPE||!/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/.test(e.value?.toString()??"")))throw new g("Expected name",e.cursor,this.stream.expression);const i=new u(e.value,!0,s),r=new p;let n=E.PROPERTY_CALL;this.stream.current.test(D.PUNCTUATION_TYPE,"(")&&(n=E.METHOD_CALL,Object.values(this.parseArguments().nodes).forEach(t=>r.addElement(t))),t=new E(t,i,r,n)}else{if("["!==e.value)break;{this.stream.next();const e=this.parseExpression();this.stream.expect(D.PUNCTUATION_TYPE,"]"),t=new E(t,e,new p,E.ARRAY_CALL)}}e=this.stream.current}return t}parseArguments(){const t=[];for(this.stream.expect(D.PUNCTUATION_TYPE,"(","A list of arguments must begin with an opening parenthesis");!this.stream.current.test(D.PUNCTUATION_TYPE,")");)0!==t.length&&this.stream.expect(D.PUNCTUATION_TYPE,",","Arguments must be separated by a comma"),t.push(this.parseExpression());this.stream.expect(D.PUNCTUATION_TYPE,")","A list of arguments must be closed by a parenthesis");const e=t.reduce((t,e,s)=>(t[`${s}`]=e,t),{});return new l(e)}doParse(t,e,s){this.flags=s,this.stream=t,this.names=e;const i=this.parseExpression();if(!this.stream.isEOF())throw new g(`Unexpected token "${this.stream.current.type}" of value "${this.stream.current.value}"`,this.stream.current.cursor,this.stream.expression,this.stream.current.value);return this.stream=void 0,this.names=[],i}getPrimary(){const t=this.stream.current;if(t.test(D.OPERATOR_TYPE)&&null!==t.value&&void 0!==B.unaryOperators[t.value]&&null!==B.unaryOperators[t.value]){const e=B.unaryOperators[t.value];this.stream.next();const s=this.parseExpression(e.precedence);return this.parsePostfixExpression(new w(t.value,s))}if(t.test(D.PUNCTUATION_TYPE,"(")){this.stream.next();const t=this.parseExpression();return this.stream.expect(D.PUNCTUATION_TYPE,")","An opened parenthesis is not properly closed"),this.parsePostfixExpression(t)}return this.parsePrimaryExpression()}parseConditionalExpression(t){for(;this.stream.current.test(D.PUNCTUATION_TYPE,"??");){this.stream.next();const e=this.parseExpression();t=new x(t,e)}for(;this.stream.current.test(D.PUNCTUATION_TYPE,"?");){this.stream.next();const e=this.stream.current.test(D.PUNCTUATION_TYPE,":")?t:this.parseExpression();if(this.stream.current.test(D.PUNCTUATION_TYPE,":")){this.stream.next();const s=this.parseExpression();t=new v(t,e,s)}else t=new v(t,e,new u(null))}return t}}var H,V;var K=function(){if(V)return H;V=1;var t=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var s=[],i=!0,r=!1,n=void 0;try{for(var o,a=t[Symbol.iterator]();!(i=(o=a.next()).done)&&(s.push(o.value),!e||s.length!==e);i=!0);}catch(t){r=!0,n=t}finally{try{!i&&a.return&&a.return()}finally{if(r)throw n}}return s}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};function e(i,a){var h=(/^(?:N(?=;)|[bidsSaOCrR](?=:)|[^:]+(?=:))/g.exec(i)||[])[0];if(!h)throw SyntaxError("Invalid input: "+i);switch(h){case"N":return a([null,2]);case"b":return a(function(e){var s=/^b:([01]);/.exec(e)||[],i=t(s,2),r=i[0],n=i[1];if(!n)throw SyntaxError("Invalid bool value, expected 0 or 1");return["1"===n,r.length]}(i));case"i":return a(s(i));case"d":return a(function(e){var s=/^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[eE][+-]\d+)?);/.exec(e)||[],i=t(s,2),r=i[0],n=i[1];if(!n)throw SyntaxError("Expected a float value");var o=void 0;switch(n){case"NAN":o=Number.NaN;break;case"-INF":o=Number.NEGATIVE_INFINITY;break;case"INF":o=Number.POSITIVE_INFINITY;break;default:o=parseFloat(n)}return[o,r.length]}(i));case"s":return a(r(i));case"S":return a(n(i));case"a":return function(s,i){var r=/^a:(\d+):{/.exec(s)||[],n=t(r,2),a=n[0],h=n[1];if(!h)throw SyntaxError("Expected array length annotation");s=s.substr(a.length);var c=function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments[2],r=void 0,n=void 0,a=0,h=!0,c=-1,l={};i([l]);for(var u=0;u<s;u++)r=o(t),h=h&&"number"==typeof r[0]&&r[0]===c+1,c=r[0],t=t.substr(r[1]),a+=r[1],n=e(t,i),t=t.substr(n[1]),a+=n[1],l[r[0]]=n[0];h&&(l=Object.values(l));return[l,a]}(s,parseInt(h,10),i);if("}"!==s.charAt(c[1]))throw SyntaxError("Expected }");return[c[0],a.length+c[1]+1]}(i,a);case"O":return function(s,i){var r=/^O:(\d+):"([^"]+)":(\d+):\{/.exec(s)||[],n=t(r,4),a=n[0],h=n[2],c=n[3];if(!a)throw SyntaxError("Invalid input");if("stdClass"!==h)throw SyntaxError("Unsupported object type: "+h);var l=a.length,u=parseInt(c,10),d={};i([d]),s=s.substr(l);for(var p=0;p<u;p++){var f=o(s);s=s.substr(f[1]),l+=f[1];var g=e(s,i);s=s.substr(g[1]),l+=g[1],d[f[0]]=g[0]}if("}"!==s.charAt(0))throw SyntaxError("Expected }");return[d,l+1]}(i,a);case"C":return function(){throw Error("Not yet implemented")}();case"r":case"R":return function(e,s){var i=/^[rR]:([1-9]\d*);/.exec(e)||[],r=t(i,2),n=r[0],o=r[1];if(!n)throw SyntaxError("Expected reference value");return[s.get(parseInt(o,10)-1),n.length]}(i,a);default:throw SyntaxError("Invalid or unsupported data type: "+h)}}function s(e){var s=/^i:([+-]?\d+);/.exec(e)||[],i=t(s,2),r=i[0],n=i[1];if(!n)throw SyntaxError("Expected an integer value");return[parseInt(n,10),r.length]}function i(t,e){for(var s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=0,r="",n=0,o=t.length,a=!1,h=0;i<e&&n<o;){var c=t.charAt(n),l=c.charCodeAt(0),u=l>=55296&&l<=56319,d=l>=56320&&l<=57343;s&&"\\"===c&&(c=String.fromCharCode(parseInt(t.substr(n+1,2),16)),h++,n+=2),n++,i+=u||d&&a?2:l>2047?3:l>127?2:1,i+=a&&!d?1:0,r+=c,a=u}return[r,i,h]}function r(e){var s=/^s:(\d+):"/g.exec(e)||[],r=t(s,2),n=r[0],o=r[1];if(!n)throw SyntaxError("Expected a string value");var a=parseInt(o,10),h=i(e=e.substr(n.length),a),c=t(h,2),l=c[0],u=c[1];if(u!==a)throw SyntaxError("Expected string of "+a+" bytes, but got "+u);if(!(e=e.substr(l.length)).startsWith('";'))throw SyntaxError('Expected ";');return[l,n.length+l.length+2]}function n(e){var s=/^S:(\d+):"/g.exec(e)||[],r=t(s,2),n=r[0],o=r[1];if(!n)throw SyntaxError("Expected an escaped string value");var a=parseInt(o,10),h=i(e=e.substr(n.length),a,!0),c=t(h,3),l=c[0],u=c[1],d=c[2];if(u!==a)throw SyntaxError("Expected escaped string of "+a+" bytes, but got "+u);if(!(e=e.substr(l.length+2*d)).startsWith('";'))throw SyntaxError('Expected ";');return[l,n.length+l.length+2]}function o(t){try{return r(t)}catch(t){}try{return n(t)}catch(t){}try{return s(t)}catch(t){throw SyntaxError("Expected key or index")}}return H=function(t){try{return"string"==typeof t&&e(t,(s=[],i=function(t){return s.push(t[0]),t},i.get=function(t){if(t>=s.length)throw RangeError("Can't resolve reference "+(t+1));return s[t]},i))[0]}catch(t){return console.error(t),!1}var s,i}}(),J=e(K);t.ArgumentsNode=p,t.ArrayNode=d,t.BinaryNode=m,t.C