Comparing version 6.24.0 to 6.24.1
@@ -1,1 +0,1 @@ | ||
import e from"decimal.js";var t=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a={},u=(r=void 0!==r?r:{}).grammarSource,o={start:Ce},i=Ce,l="(",s=")",c="+",p="-",d="<=",v=">=",f="<>",m="==",h="!=",g="&&",y="||",b=/^[A-Za-z]/,x=/^[0-9]/,T=/^[1-9]/,$=/^[\n\r\u2028\u2029]/,w=be("(",!1),C=be(")",!1),A=be("^",!1),k=be("*",!1),E=be("/",!1),M=be("+",!1),U=be("-",!1),O=be("<=",!1),F=be(">=",!1),S=be("<>",!1),D=be("<",!1),N=be(">",!1),I=be("==",!1),j=be("=",!1),q=be("!=",!1),R=be("&&",!1),P=be("||",!1),W=be("&",!1),Z=be("!",!1),_=be(",",!1),L=xe([["A","Z"],["a","z"]],!1,!1),Y=be("_",!1),z=be("$",!1),Q=be(".",!1),X=be("0",!1),B=xe([["0","9"]],!1,!1),H=xe([["1","9"]],!1,!1),V=be("true",!0),G=be("false",!0),K=be("null",!0),J=be("\\",!1),ee=be("'",!1),te=be('"',!1),re={type:"any"},ne=xe(["\n","\r","\u2028","\u2029"],!1,!1),ae=be("\t",!1),ue=be("\v",!1),oe=be("\f",!1),ie=be(" ",!1),le=be(" ",!1),se=be("",!1),ce=be("\ufeff",!1),pe=function(e,t){return function(e){const t=[],r=[];e.forEach((e=>{if("operator"===e.type){for(;t.length>0&&!(t[t.length-1].precedence<e.precedence);){let e=t.pop(),n=r.pop(),a=r.pop();r.push(Xe(e,a,n))}t.push(e)}else r.push(e)}));for(;t.length>0;){let e=t.pop(),n=r.pop(),a=r.pop();r.push(Xe(e,a,n))}return r.pop()}([e,t].flat(2))},de=0,ve=0,fe=[{line:1,column:1}],me=0,he=[],ge=0;if("startRule"in r){if(!(r.startRule in o))throw new Error("Can't start parsing from rule \""+r.startRule+'".');i=o[r.startRule]}function ye(){return t.substring(ve,de)}function be(e,t){return{type:"literal",text:e,ignoreCase:t}}function xe(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function Te(e){var r,n=fe[e];if(n)return n;for(r=e-1;!fe[r];)r--;for(n={line:(n=fe[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return fe[e]=n,n}function $e(e,t){var r=Te(e),n=Te(t);return{source:u,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function we(e){de<me||(de>me&&(me=de,he=[]),he.push(e))}function Ce(){return Ae()}function Ae(){var e;return(e=Oe())===a&&(e=function(){var e,r,n;e=de,r=function(){var e;33===t.charCodeAt(de)?(e="!",de++):(e=a,0===ge&&we(Z));return e}(),r!==a?(Le(),(n=Ae())!==a?(ve=e,e={type:"callExpression",id:"not",arguments:[n]}):(de=e,e=a)):(de=e,e=a);return e}())===a&&(e=Ee())===a&&(e=Se())===a&&(e=Ie()),e}function ke(){var e,r,n,u;return(e=Ee())===a&&(e=Se())===a&&(e=Ie())===a&&(e=de,40===t.charCodeAt(de)?(r="(",de++):(r=a,0===ge&&we(w)),r!==a?(Le(),(n=Me())!==a?(Le(),41===t.charCodeAt(de)?(u=")",de++):(u=a,0===ge&&we(C)),u!==a?(ve=e,e=n):(de=e,e=a)):(de=e,e=a)):(de=e,e=a),e===a&&(e=de,40===t.charCodeAt(de)?(r="(",de++):(r=a,0===ge&&we(w)),r!==a?(Le(),(n=Oe())!==a?(Le(),41===t.charCodeAt(de)?(u=")",de++):(u=a,0===ge&&we(C)),u!==a?(ve=e,e=n):(de=e,e=a)):(de=e,e=a)):(de=e,e=a))),e}function Ee(){var e,r,n,u;return e=de,r=function(){var e,r,n;e=de,r=[],b.test(t.charAt(de))?(n=t.charAt(de),de++):(n=a,0===ge&&we(L));if(n!==a)for(;n!==a;)r.push(n),b.test(t.charAt(de))?(n=t.charAt(de),de++):(n=a,0===ge&&we(L));else r=a;r!==a&&(ve=e,r=r.join("").toLowerCase());return e=r}(),r!==a?(Le(),n=function(){var e,r,n,u;e=de,40===t.charCodeAt(de)?(r=l,de++):(r=a,0===ge&&we(w));r!==a?(Le(),n=de,u=function(){var e,r,n,u;e=de,r=[],n=de,(u=Ae())!==a?(Le(),44===t.charCodeAt(de)?de++:0===ge&&we(_),Le(),ve=n,n=u):(de=n,n=a);if(n!==a)for(;n!==a;)r.push(n),n=de,(u=Ae())!==a?(Le(),44===t.charCodeAt(de)?de++:0===ge&&we(_),Le(),ve=n,n=u):(de=n,n=a);else r=a;r!==a&&(ve=e);return e=r}(),u!==a?n=u=[u,Le()]:(de=n,n=a),n===a&&(n=null),41===t.charCodeAt(de)?(u=s,de++):(u=a,0===ge&&we(C)),u!==a?(ve=e,e=n):(de=e,e=a)):(de=e,e=a);return e}(),n!==a?(ve=e,e={type:"callExpression",id:r,arguments:(u=n,null!==u?u[0]:[])}):(de=e,e=a)):(de=e,e=a),e}function Me(){var e,t,r,n;if(e=de,(t=ke())!==a){for(Le(),r=[],n=Ue();n!==a;)r.push(n),n=Ue();ve=e,e=pe(t,r)}else de=e,e=a;return e}function Ue(){var e,r,n,u,o;return e=de,Le(),r=function(){var e;94===t.charCodeAt(de)?(e="^",de++):(e=a,0===ge&&we(A));e===a&&(42===t.charCodeAt(de)?(e="*",de++):(e=a,0===ge&&we(k)),e===a&&(47===t.charCodeAt(de)?(e="/",de++):(e=a,0===ge&&we(E)),e===a&&(43===t.charCodeAt(de)?(e=c,de++):(e=a,0===ge&&we(M)),e===a&&(45===t.charCodeAt(de)?(e=p,de++):(e=a,0===ge&&we(U))))));return e}(),r!==a?(Le(),(n=ke())!==a?(ve=e,u=r,o=n,e=[Object.assign({type:"operator"},ze[u]),o]):(de=e,e=a)):(de=e,e=a),e}function Oe(){var e,r,n,u;return e=de,(r=Fe())!==a?(Le(),n=function(){var e;t.substr(de,2)===g?(e=g,de+=2):(e=a,0===ge&&we(R));e===a&&(t.substr(de,2)===y?(e=y,de+=2):(e=a,0===ge&&we(P)));return e}(),n!==a?(Le(),(u=Oe())!==a?(ve=e,e=function(e,t,r){var n;switch(t){case"||":n="or";break;case"&&":n="and"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(de=e,e=a)):(de=e,e=a)):(de=e,e=a),e===a&&(e=Fe()),e}function Fe(){var e,r,n,u;return e=de,(r=Me())!==a?(Le(),n=function(){var e;t.substr(de,2)===d?(e=d,de+=2):(e=a,0===ge&&we(O));e===a&&(t.substr(de,2)===v?(e=v,de+=2):(e=a,0===ge&&we(F)),e===a&&(t.substr(de,2)===f?(e=f,de+=2):(e=a,0===ge&&we(S)),e===a&&(60===t.charCodeAt(de)?(e="<",de++):(e=a,0===ge&&we(D)),e===a&&(62===t.charCodeAt(de)?(e=">",de++):(e=a,0===ge&&we(N)),e===a&&(t.substr(de,2)===m?(e=m,de+=2):(e=a,0===ge&&we(I)),e===a&&(61===t.charCodeAt(de)?(e="=",de++):(e=a,0===ge&&we(j)),e===a&&(t.substr(de,2)===h?(e=h,de+=2):(e=a,0===ge&&we(q)))))))));return e}(),n===a&&(n=function(){var e;38===t.charCodeAt(de)?(e="&",de++):(e=a,0===ge&&we(W));return e}()),n!==a?(Le(),(u=Fe())!==a?(ve=e,e=function(e,t,r){var n;switch(t){case"<":n="lessThan";break;case"<=":n="lessThanOrEqual";break;case">":n="greaterThan";break;case">=":n="greaterThanOrEqual";break;case"==":case"=":n="equal";break;case"!=":case"<>":n="unequal";break;case"&":n="add"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(de=e,e=a)):(de=e,e=a)):(de=e,e=a),e===a&&(e=Me()),e}function Se(){var e,t,r;return e=de,t=de,ge++,r=function(){var e;(e=Re())===a&&(e=Pe());return e}(),ge--,r===a?t=void 0:(de=t,t=a),t!==a?(r=function(){var e,t,r,n;if(e=de,(t=De())!==a){for(r=[],n=Ne();n!==a;)r.push(n),n=Ne();ve=e,e={type:"identifier",name:t+r.join("")}}else de=e,e=a;return e}(),r!==a?(ve=e,e=r):(de=e,e=a)):(de=e,e=a),e}function De(){var e;return 95===t.charCodeAt(de)?(e="_",de++):(e=a,0===ge&&we(Y)),e===a&&(36===t.charCodeAt(de)?(e="$",de++):(e=a,0===ge&&we(z)),e===a&&(b.test(t.charAt(de))?(e=t.charAt(de),de++):(e=a,0===ge&&we(L)))),e}function Ne(){var e;return(e=De())===a&&(46===t.charCodeAt(de)?(e=".",de++):(e=a,0===ge&&we(Q)),e===a&&(e=qe())),e}function Ie(){var e;return(e=function(){var e,t,r;if(e=de,Ze()!==a){for(t=[],(r=We())===a&&(r=_e());r!==a;)t.push(r),(r=We())===a&&(r=_e());(r=Ze())!==a?(ve=e,e=Qe(t)):(de=e,e=a)}else de=e,e=a;if(e===a)if(e=de,_e()!==a){for(t=[],(r=We())===a&&(r=Ze());r!==a;)t.push(r),(r=We())===a&&(r=Ze());(r=_e())!==a?(ve=e,e=function(e){return Qe(e)}(t)):(de=e,e=a)}else de=e,e=a;return e}())===a&&(e=function(){var e,r,n,u,o,i;e=de,r=de,n=Le(),43===t.charCodeAt(de)?(u=c,de++):(u=a,0===ge&&we(M));u!==a?r=n=[n,u]:(de=r,r=a);r===a&&(r=de,45===t.charCodeAt(de)?(n=p,de++):(n=a,0===ge&&we(U)),n!==a?r=n=[n,u=Le()]:(de=r,r=a));r===a&&(r=null);if((n=je())!==a)if(46===t.charCodeAt(de)?(u=".",de++):(u=a,0===ge&&we(Q)),u!==a){for(o=[],i=qe();i!==a;)o.push(i),i=qe();ve=e,l=ye().replace(/[\+\-]/g,"").split("."),e={type:"literal",value:parseFloat(ye()),dataType:"number",options:{length:l[0].length,scale:l[1].length}}}else de=e,e=a;else de=e,e=a;var l;e===a&&(e=de,r=de,n=Le(),43===t.charCodeAt(de)?(u=c,de++):(u=a,0===ge&&we(M)),u!==a?r=n=[n,u]:(de=r,r=a),r===a&&(r=de,45===t.charCodeAt(de)?(n=p,de++):(n=a,0===ge&&we(U)),n!==a?r=n=[n,u=Le()]:(de=r,r=a)),r===a&&(r=null),(n=je())!==a?(ve=e,e={type:"literal",value:parseInt(ye()),dataType:"number",options:{length:ye().replace(/[\+\-]/g,"").length,scale:0}}):(de=e,e=a));return e}())===a&&(e=Re())===a&&(e=Pe()),e}function je(){var e,r,n,u;if(48===t.charCodeAt(de)?(e="0",de++):(e=a,0===ge&&we(X)),e===a)if(e=de,r=function(){var e;T.test(t.charAt(de))?(e=t.charAt(de),de++):(e=a,0===ge&&we(H));return e}(),r!==a){for(n=[],u=qe();u!==a;)n.push(u),u=qe();e=r=[r,n]}else de=e,e=a;return e}function qe(){var e;return x.test(t.charAt(de))?(e=t.charAt(de),de++):(e=a,0===ge&&we(B)),e}function Re(){var e,r;return e=de,"true"===t.substr(de,4).toLowerCase()?(r=t.substr(de,4),de+=4):(r=a,0===ge&&we(V)),r!==a&&(ve=e,r={type:"literal",value:!0,dataType:"checkbox",options:{}}),(e=r)===a&&(e=de,"false"===t.substr(de,5).toLowerCase()?(r=t.substr(de,5),de+=5):(r=a,0===ge&&we(G)),r!==a&&(ve=e,r={type:"literal",value:!1,dataType:"checkbox",options:{}}),e=r),e}function Pe(){var e,r;return e=de,"null"===t.substr(de,4).toLowerCase()?(r=t.substr(de,4),de+=4):(r=a,0===ge&&we(K)),r!==a&&(ve=e,r={type:"literal",value:null,dataType:"null",options:{}}),e=r}function We(){var e,r,n;return e=de,r=de,ge++,n=function(){var e;(e=Ze())===a&&(e=_e());return e}(),n===a&&(92===t.charCodeAt(de)?(n="\\",de++):(n=a,0===ge&&we(J))),ge--,n===a?r=void 0:(de=r,r=a),r!==a?(n=function(){var e;t.length>de?(e=t.charAt(de),de++):(e=a,0===ge&&we(re));return e}(),n!==a?(ve=e,e=ye()):(de=e,e=a)):(de=e,e=a),e}function Ze(){var e;return 39===t.charCodeAt(de)?(e="'",de++):(e=a,0===ge&&we(ee)),e}function _e(){var e;return 34===t.charCodeAt(de)?(e='"',de++):(e=a,0===ge&&we(te)),e}function Le(){var e,t;for(e=[],t=Ye();t!==a;)e.push(t),t=Ye();return e}function Ye(){var e;return 9===t.charCodeAt(de)?(e="\t",de++):(e=a,0===ge&&we(ae)),e===a&&(e=function(){var e;return $.test(t.charAt(de))?(e=t.charAt(de),de++):(e=a,0===ge&&we(ne)),e}())===a&&(11===t.charCodeAt(de)?(e="\v",de++):(e=a,0===ge&&we(ue)),e===a&&(12===t.charCodeAt(de)?(e="\f",de++):(e=a,0===ge&&we(oe)),e===a&&(32===t.charCodeAt(de)?(e=" ",de++):(e=a,0===ge&&we(ie)),e===a&&(160===t.charCodeAt(de)?(e=" ",de++):(e=a,0===ge&&we(le)),e===a&&(8203===t.charCodeAt(de)?(e="",de++):(e=a,0===ge&&we(se)),e===a&&(65279===t.charCodeAt(de)?(e="\ufeff",de++):(e=a,0===ge&&we(ce)))))))),e}const ze={"^":{functionName:"exponentiate",rightAssociative:!0,precedence:4},"*":{functionName:"multiply",rightAssociative:!1,precedence:3},"/":{functionName:"divide",rightAssociative:!1,precedence:3},"+":{functionName:"add",rightAssociative:!1,precedence:2},"-":{functionName:"subtract",rightAssociative:!1,precedence:2}};function Qe(e){return{type:"literal",value:e.join(""),dataType:"text",options:{length:e.length}}}function Xe(e,t,r){return{type:"callExpression",id:e.functionName,arguments:[t,r]}}if((n=i())!==a&&de===t.length)return n;throw n!==a&&de<t.length&&we({type:"end"}),Be=he,He=me<t.length?t.charAt(me):null,Ve=me<t.length?$e(me,me+1):$e(me,me),new e(e.buildMessage(Be,He),Be,He,Ve);var Be,He,Ve}}}(),r=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a,u,o,i={},l=(r=void 0!==r?r:{}).grammarSource,s={Time:E},c=E,p=/^[0-9]/,d=w(":",!1),v=w(".",!1),f={type:"class",parts:[["0","9"]],inverted:!1,ignoreCase:!1},m=function(e,t,r,n){return function(e,t,r,n){e>23&&$("hour part needs to be under 24");t>59&&$("minute part needs to be under 60");r>59&&$("second part needs to be under 60");n>999&&$("millisecond part needs to be under 1000")}(e,t,r,n),{type:"literal",value:new Date(n+1e3*r+60*t*1e3+60*e*60*1e3),dataType:"time",options:{}}},h=0,g=0,y=[{line:1,column:1}],b=0,x=[];if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');c=s[r.startRule]}function T(){return t.substring(g,h)}function $(t,r){throw function(t,r){return new e(t,null,null,r)}(t,r=void 0!==r?r:A(g,h))}function w(e,t){return{type:"literal",text:e,ignoreCase:t}}function C(e){var r,n=y[e];if(n)return n;for(r=e-1;!y[r];)r--;for(n={line:(n=y[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return y[e]=n,n}function A(e,t){var r=C(e),n=C(t);return{source:l,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function k(e){h<b||(h>b&&(b=h,x=[]),x.push(e))}function E(){var e,r,n,a,u,o,l,s;return e=h,r=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),r!==i?(58===t.charCodeAt(h)?(n=":",h++):(n=i,k(d)),n!==i?(a=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),a!==i?(58===t.charCodeAt(h)?(u=":",h++):(u=i,k(d)),u!==i?(o=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),o!==i?(46===t.charCodeAt(h)?(l=".",h++):(l=i,k(v)),l!==i?(s=function(){var e;e=h,M()!==i&&M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),s!==i?(g=e,e=m(r,a,o,s)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i),e}function M(){var e;return p.test(t.charAt(h))?(e=t.charAt(h),h++):(e=i,k(f)),e}if((n=c())!==i&&h===t.length)return n;throw n!==i&&h<t.length&&k({type:"end"}),a=x,u=b<t.length?t.charAt(b):null,o=b<t.length?A(b,b+1):A(b,b),new e(e.buildMessage(a,u),a,u,o)}}}();class n extends Error{constructor(e,t,r){super(e),this.errorType=t,this.options=r}}const a=(e,t)=>{if(e<0)return-1*a(-1*e,t);const r=10**t;return Math.round(e*r)/r},u=e=>{const t=e.toString().replace("-","");if(-1!==t.indexOf(".")){const e=t.split(".");return{length:e[0].length,scale:e[1].length}}return{length:t.length,scale:0}},o=(e,t,r)=>{switch(e){case"number":return a(t,r.scale);case"text":return t.substring(0,r.length);default:return t}},i=e=>{const t={type:"literal",value:e};if(null==e)return Object.assign(t,{value:null,dataType:"null",options:{}});const r=typeof e;switch(typeof e){case"number":return Object.assign(t,{dataType:"number",options:u(e)});case"string":return Object.assign(t,{dataType:"text",options:{length:e.length}});case"boolean":return Object.assign(t,{dataType:"checkbox",options:{}});default:throw new TypeError(`Unsupported type '${r}'`)}},l=(e,t,r)=>({type:"error",errorType:e,message:t,...r}),s=(e,t,r)=>e instanceof Date?s(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()):{type:"literal",dataType:"date",value:new Date(Date.UTC(e,t-1,r)),options:{}},c=e=>({type:"literal",dataType:"datetime",value:new Date(e),options:{}}),p=e=>({type:"literal",dataType:"time",value:new Date(e),options:{}}),d=e=>{try{return e()}catch(e){if(e instanceof n)return l(e.errorType,e.message,e.options);throw e}},v=(e,t)=>new Date(e.getTime()+864e5*t),f=e=>{if(!e.value&&"null"!==e.dataType&&0!==e.value&&!1!==e.value&&""!==e.value)return"";switch(e.dataType){case"null":return"NULL";case"number":return e.value.toString();case"text":case"picklist":return`"${e.value}"`;case"multipicklist":return`[${e.value.map((e=>`"${e}"`)).join(", ")}]`;case"checkbox":return e.value.toString().toUpperCase();case"date":return`${e.value.getUTCFullYear()}-${(e.value.getUTCMonth()+1).toString().padStart(2,"0")}-${e.value.getUTCDate().toString().padStart(2,"0")}`;case"datetime":return e.value.toISOString();case"time":return e.value.toISOString().split("T")[1].replace("Z","");case"geolocation":return t=e.value[0],r=e.value[1],t&&r||0===t||0===r?`${t.toFixed(6)}, ${r.toFixed(6)}`:"";default:return}var t,r};class m extends n{constructor(e,t){super(e,"NotImplementedError",t)}static throwError(e){throw new m(`Function ${e} not implemented yet.`,{name:e})}}const h=e=>Array.isArray(e)?e.map((e=>h(e))).join(", "):"string"!=typeof e?"":e.charAt(0).toUpperCase()+e.slice(1);class g extends n{constructor(e,t){super(e,"ArgumentError",t)}static throwWrongType(e,t,r){const n={function:e,expected:t,received:r},a=r||"Non-Salesforce";throw new g(`Incorrect parameter type for function '${e.toUpperCase()}()'. Expected ${h(t)}, received ${h(a)}`,n)}static throwIncorrectNumberOfArguments(e,t,r){const n={function:e,expected:t,received:r};throw new g(`Incorrect number of parameters for function '${e.toUpperCase()}()'. Expected ${t}, received ${r}`,n)}}const y=(e,t)=>{switch(e.dataType){case"date":case"datetime":return i(e.value.getTime()===t.value.getTime());default:return i(e.value===t.value)}},b=(e,t,r)=>i(e.value.substr(t.value-1,r.value)),x=(e,t)=>b(e,i(1),t);var T=Object.freeze({__proto__:null,sf$or:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e||t));return i(t)},sf$equal:y,sf$unequal:(e,t)=>i(!y(e,t).value),sf$greaterThan:(e,t)=>i(e.value>t.value),sf$greaterThanOrEqual:(e,t)=>i(e.value>=t.value),sf$lessThan:(e,t)=>i(e.value<t.value),sf$lessThanOrEqual:(e,t)=>i(e.value<=t.value),sf$addmonths:(e,t)=>s(((e,t)=>{const r=e.getUTCMonth()+t,n=new Date(Date.UTC(e.getUTCFullYear(),r,e.getUTCDate()));return e.getUTCDate()!==n.getUTCDate()&&n.setUTCDate(0),n})(e.value,t.value)),sf$date:(e,t,r)=>s(e.value,t.value,r.value),sf$datevalue:e=>s(new Date(Date.parse(e.value))),sf$datetimevalue:e=>c(Date.parse(`${e.value}Z`)),sf$day:e=>i(e.value.getUTCDate()),sf$hour:e=>i(e.value.getUTCHours()),sf$millisecond:e=>i(e.value.getUTCMilliseconds()),sf$minute:e=>i(e.value.getUTCMinutes()),sf$month:e=>i(e.value.getUTCMonth()+1),sf$now:()=>c((new Date).getTime()),sf$second:e=>i(e.value.getUTCSeconds()),sf$timenow:()=>p((new Date).getTime()%864e5),sf$timevalue:e=>(e=>{try{return r.parse(e)}catch(e){if(e instanceof r.SyntaxError)return i(null);throw e}})(e.value),sf$today:()=>s(new Date),sf$weekday:e=>i(e.value.getUTCDay()+1),sf$year:e=>i(e.value.getUTCFullYear()),sf$and:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e&&t));return i(t)},sf$blankvalue:(e,t)=>"null"===e.dataType||""===e.value?t:e,sf$case:(e,...t)=>{const r=t.length-1;if(r<=0){const e={function:"case",expected:4,received:r+2};throw new g(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}+, received ${e.received}`,e)}if(r%2!=0){const e={function:"case",expected:r+1,received:r+2};throw new g(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}, received ${e.received}`,e)}for(let n=0;n<r;n+=2)if(y(t[n],e).value)return t[n+1];return t[r]},sf$if:(e,t,r)=>e.value?t:r,sf$isblank:e=>i("null"===e.dataType||""===e.value),sf$isnull:e=>{m.throwError("isnull")},sf$isnumber:e=>{m.throwError("isnumber")},sf$not:e=>i(!e.value),sf$nullvalue:(e,t)=>{m.throwError("nullvalue")},sf$add:(t,r)=>{switch([t.dataType,r.dataType].join(" ")){case"date number":return s(v(t.value,r.value));case"number date":return s(v(r.value,t.value));case"time number":return p(t.value.getTime()+r.value);case"number time":return p(t.value+r.value.getTime());case"datetime number":return c(v(t.value,r.value));case"number datetime":return c(v(r.value,t.value));case"number number":return i(new e(t.value).plus(new e(r.value)).toNumber());case"text text":return i(t.value+r.value);default:g.throwWrongType("add","number",r.dataType)}},sf$subtract:(t,r)=>{switch([t.dataType,r.dataType].join(" ")){case"date number":return s(v(t.value,-1*r.value));case"time number":return p(t.value.getTime()+-1*r.value);case"datetime number":return c(v(t.value,-1*r.value));case"date date":case"datetime datetime":return i((n=t.value,a=r.value,(n.getTime()-a.getTime())/864e5));case"time time":return i(t.value.getTime()-r.value.getTime());case"number number":return i(new e(t.value).minus(new e(r.value)).toNumber());case"text text":return i(t.value-r.value);default:g.throwWrongType("subtract","number",r.dataType)}var n,a},sf$multiply:(t,r)=>i(new e(t.value).times(new e(r.value)).toNumber()),sf$divide:(t,r)=>i(new e(t.value).dividedBy(new e(r.value)).toNumber()),sf$exponentiate:(t,r)=>i(new e(t.value).toPower(new e(r.value)).toNumber()),sf$abs:e=>i(Math.abs(e.value)),sf$ceiling:e=>e.value<0?i(-1*Math.ceil(-1*e.value)):i(Math.ceil(e.value)),sf$distance:(e,t,r)=>{const n=r.value;if("km"!==n&&"mi"!==n){throw new g(`Incorrect parameter value for function 'DISTANCE()'. Expected 'mi'/'km', received '${n}'`,{function:"distance",expected:["km","mi"],received:n})}const[a,u]=e.value,[o,l]=t.value;if(a===o&&u===l)return i(0);const s=a*Math.PI/180,c=o*Math.PI/180,p=(o-a)*Math.PI/180,d=(l-u)*Math.PI/180,v=Math.sin(p/2)*Math.sin(p/2)+Math.cos(s)*Math.cos(c)*Math.sin(d/2)*Math.sin(d/2),f=6371009*(2*Math.atan2(Math.sqrt(v),Math.sqrt(1-v)))/1e3;return i("mi"===n?f/1.609344:f)},sf$exp:e=>i(Math.exp(e.value)),sf$floor:e=>e.value<0?i(-1*Math.floor(-1*e.value)):i(Math.floor(e.value)),sf$geolocation:(e,t)=>((e,t)=>({type:"literal",dataType:"geolocation",value:[e,t],options:{}}))(e.value,t.value),sf$ln:e=>i(Math.log(e.value)),sf$log:e=>i(Math.log10(e.value)),sf$max:(...e)=>{const t=e.map((e=>e.value));return i(Math.max(...t))},sf$mceiling:e=>i(Math.ceil(e.value)),sf$mfloor:e=>i(Math.floor(e.value)),sf$min:(...e)=>{const t=e.map((e=>e.value));return i(Math.min(...t))},sf$mod:(e,t)=>i(e.value%t.value),sf$round:(e,t)=>i(a(e.value,t.value)),sf$sqrt:e=>i(Math.sqrt(e.value)),sf$begins:(e,t)=>i(e.value.startsWith(t.value)),sf$br:()=>i("\n"),sf$casesafeid:e=>{let t="";return[0,1,2].forEach((r=>{let n=0;[0,1,2,3,4].forEach((t=>{const a=e.value[5*r+t];a.toUpperCase()===a&&a>="A"&&a<="Z"&&(n+=1<<t)})),t+="ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[n]})),i(e.value+t)},sf$concat:(e,t)=>i(e.value+t.value),sf$contains:(e,t)=>i(e.value.includes(t.value)),sf$find:(e,t,r=i(1))=>{if(r.value<=0||""===e.value)return i(0);const n=t.value.substring(r.value-1);return i(n.indexOf(e.value)+1)},sf$getsessionid:()=>i("00D3z000001eRlg!AQMAQC3Y4aM9sFux6SRWhyFcOUKin4taGaBxNMU8TN_R_1R0Y7ArI95eSyzQZVIlrnV_unTbmwHZlXex8xhlXz2kXZNP49Fa"),sf$hyperlink:(e,t,r=null)=>{const n=r?` target="${r.value}"`:"";return i(`<a href="${e.value}"${n}>${t.value}</a>`)},sf$image:(e,t,r=null,n=null)=>{const a=r?` height="${r.value}"`:"",u=n?` width="${n.value}"`:"";return i(`<img src="${e.value}" alt="${t.value}"${a}${u}/>`)},sf$includes:(e,t)=>i(e.value.includes(t.value)),sf$ispickval:(e,t)=>i(e.value===t.value),sf$mid:b,sf$left:x,sf$len:e=>i(e.value.length),sf$lower:(e,t)=>i(e.value.toLowerCase()),sf$lpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return x(e,t);const n=r.value.repeat(t.value);return i((n+e.value).slice(-t.value))},sf$right:(e,t)=>i(e.value.substr(e.value.length-t.value)),sf$rpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return x(e,t);const n=r.value.repeat(t.value);return i((e.value+n).substr(0,t.value))},sf$substitute:(e,t,r)=>i(e.value.replace(new RegExp(t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),r.value)),sf$text:e=>"datetime"===e.dataType?i(f(e).replace("T"," ").replace(/\.\d{3}/,"")):"picklist"===e.dataType?i(e.value):i(f(e)),sf$trim:e=>i(e.value.trim()),sf$upper:(e,t)=>i(e.value.toUpperCase()),sf$value:e=>{const t=parseFloat(e.value);return i(t||null)},sf$currencyrate:e=>{m.throwError("currencyrate")},sf$regex:(e,t)=>{const r=new RegExp(`^${t.value}$`);return i(null!=r.exec(e.value))}});const $=e=>t=>r=>{r.length<e&&g.throwIncorrectNumberOfArguments(t,e,r.length)},w=e=>t=>r=>{r.length>e&&g.throwIncorrectNumberOfArguments(t,e,r.length)},C=(...e)=>t=>r=>{r.map(((t,r)=>[t.dataType,e[r]||e[e.length-1]])).forEach((([e,r])=>{"null"!==e&&(Array.isArray(r)?-1===r.indexOf(e)&&g.throwWrongType(t,r,e):e!==r&&g.throwWrongType(t,r,e))}))},A=()=>e=>t=>{const r=t.filter((e=>"null"!==e.dataType));r.length>0&&r.reduce(((t,r)=>(t.dataType!==r.dataType&&g.throwWrongType(e,t.dataType,r.dataType),r)))};class k extends n{constructor(e,t){super(e,"NoFunctionError",t)}}const E={abs:{validations:[$(1),w(1),C("number")],returnType:"number"},add:{validations:[$(2),w(2),C(["number","text","date","datetime","time"],["number","text","date","datetime","time"])],returnType:["number","text","date","datetime","time"]},addmonths:{validations:[$(2),w(2),C(["date","datetime"],["number"])],returnType:["date","datetime"]},and:{validations:[$(1),C("checkbox")],returnType:"checkbox"},begins:{validations:[$(2),w(2),C("text","text")],returnType:"checkbox"},blankvalue:{validations:[$(2),w(2),C(["text","number","date","datetime","geolocation"]),A()],returnType:["text","number"]},br:{validations:[$(0),w(0)],returnType:"text"},case:{validations:[$(4),C(["text","number","picklist","date","datetime"]),e=>t=>{const r="picklist"===t[0].dataType?"text":t[0].dataType,n=t.filter(((e,r)=>r%2==1&&r!==t.length-1)).find((e=>e.dataType!==r));n&&g.throwWrongType(e,r,n.dataType)}],returnType:["text","number","date","datetime"]},casesafeid:{validations:[$(1),w(1),C("text")],returnType:"text"},ceiling:{validations:[$(1),w(1),C("number")],returnType:"number"},contains:{validations:[$(2),w(2),C("text","text")],returnType:"checkbox"},currencyrate:{validations:[$(1),w(1),C("text")],returnType:"text"},date:{validations:[$(3),w(3),C("number","number","number")],returnType:"date"},datetimevalue:{validations:[$(1),w(1),C("text","date","datetime")],returnType:"datetime"},datevalue:{validations:[$(1),w(1),C(["text","date","datetime"])],returnType:"date"},day:{validations:[$(1),w(1),C("date")],returnType:"number"},distance:{validations:[$(3),w(3),C("geolocation","geolocation","text")],returnType:"number"},divide:{validations:[$(2),w(2),C("number","number")],returnType:"number"},equal:{validations:[$(2),w(2),C(["text","number","date","datetime","checkbox"]),A()],returnType:"checkbox"},exp:{validations:[$(1),w(1),C("number")],returnType:"number"},exponentiate:{validations:[$(2),w(2),C("number","number")],returnType:"number"},find:{validations:[$(2),w(3),C("text","text","number")],returnType:"number"},floor:{validations:[$(1),w(1),C("number")],returnType:"number"},geolocation:{validations:[$(2),w(2),C("number","number")],returnType:"geolocation"},getsessionid:{validations:[$(0),w(0)],returnType:"text"},greaterThan:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},greaterThanOrEqual:{validations:[$(2),w(2),C(["number","date","datetime"])],returnType:"checkbox"},hour:{validations:[$(1),w(1),C("datetime")],returnType:"number"},hyperlink:{validations:[$(2),w(3),C("text","text","text")],returnType:"text"},if:{validations:[$(3),w(3),C("checkbox",["text","number","date","datetime","checkbox","geolocation"],["text","number","date","datetime","checkbox","geolocation"])],returnType:["text","number","date","datetime","checkbox","geolocation"]},image:{validations:[$(2),w(4),C("text","text","number","number")],returnType:"text"},includes:{validations:[$(2),w(2),C("multipicklist","text")],returnType:"checkbox"},isblank:{validations:[$(1),w(1),C(["text","number","date","datetime","geolocation"])],returnType:"checkbox"},isnull:{validations:[$(1),w(1),C(["text","number"])],returnType:"checkbox"},ispickval:{validations:[$(2),w(2),C("picklist","text")],returnType:"checkbox"},isnumber:{validations:[$(1),w(1),C("text")],returnType:"checkbox"},left:{validations:[$(2),w(2),C("text","number")],returnType:"text"},len:{validations:[$(1),w(1),C("text")],returnType:"number"},lessThan:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},lessThanOrEqual:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},ln:{validations:[$(1),w(1),C("number")],returnType:"number"},log:{validations:[$(1),w(1),C("number")],returnType:"checkbox"},lower:{validations:[$(1),w(1),C("text")],returnType:"text"},lpad:{validations:[$(2),w(3),C("text","number","text")],returnType:"text"},max:{validations:[$(1),C("number")],returnType:"number"},mceiling:{validations:[$(1),w(1),C("number")],returnType:"number"},mfloor:{validations:[$(1),w(1),C("number")],returnType:"number"},mid:{validations:[$(3),w(3),C("text","number","number")],returnType:"number"},millisecond:{validations:[$(1),w(1),C("datetime")],returnType:"number"},min:{validations:[$(1),C("number")],returnType:"number"},minute:{validations:[$(1),w(1),C("datetime")],returnType:"number"},mod:{validations:[$(2),w(2),C("number","number")],returnType:"number"},month:{validations:[$(1),w(1),C("date")],returnType:"number"},multiply:{validations:[$(2),w(2),C("number","number")],returnType:"number"},not:{validations:[$(1),w(1),C("checkbox")],returnType:"checkbox"},now:{validations:[$(0),w(0)],returnType:"datetime"},nullvalue:{validations:[$(2),w(2),C(["text","number"],["text","number"])],returnType:["text","number"]},or:{validations:[$(1),C("checkbox")],returnType:"checkbox"},regex:{validations:[$(2),w(2),C("text","text")],returnType:"text"},right:{validations:[$(2),w(2),C("text","number")],returnType:"text"},round:{validations:[$(2),w(2),C("number","number")],returnType:"number"},rpad:{validations:[$(2),w(3),C("text","number","text")],returnType:"text"},second:{validations:[$(1),w(1),C("datetime")],returnType:"number"},sqrt:{validations:[$(1),w(1),C("number")],returnType:"number"},subtract:{validations:[$(2),w(2),C(["number","date","datetime","time"],["number","date","datetime","time"])],returnType:["number","date","datetime","time"]},substitute:{validations:[$(3),w(3),C("text","text","text")],returnType:"text"},text:{validations:[$(1),w(1),C(["number","date","datetime","picklist","time"])],returnType:"text"},timenow:{validations:[$(0),w(0)],returnType:"time"},timevalue:{validations:[$(1),w(1),C("text")],returnType:"time"},today:{validations:[$(0),w(0)],returnType:"date"},trim:{validations:[$(1),w(1),C("text")],returnType:"text"},unequal:{validations:[$(2),w(2),C(["text","number","date","datetime","checkbox"]),A()],returnType:"checkbox"},upper:{validations:[$(1),w(1),C("text")],returnType:"text"},value:{validations:[$(1),w(1),C("text")],returnType:"number"},weekday:{validations:[$(1),w(1),C("date")],returnType:"number"},year:{validations:[$(1),w(1),C("date")],returnType:"number"}};class M extends n{constructor(e,t){super(e,"ReferenceError",t)}}const U=e=>{switch(e.type){case"callExpression":return t=e.id,r=e.arguments.map((e=>U(e))),d((()=>{const e=r.find((e=>"error"===e.type));if(e)return e;const n=E[t];if(n)return n.validations.forEach((e=>e(t)(r))),T[`sf$${t}`](...r);throw new k(`Unknown function ${t.toUpperCase()}. Check spelling.`,{function:t})}));case"identifier":throw new M(`Field ${e.name} does not exist. Check spelling.`,{identifier:e.name});default:return e}var t,r},O=e=>{try{return t.parse(null==e?"":e.trim())}catch(e){if(e instanceof t.SyntaxError)return l("SyntaxError","Syntax error.",{});throw e}},F=(e,t=[])=>{switch(e.type){case"callExpression":return e.arguments.map((e=>F(e,t))).reduce(((e,t)=>e.concat(t)),[]);case"identifier":return t.concat(e.name);default:return t}},S=(e,t)=>"callExpression"===e.type?{type:"callExpression",id:e.id,arguments:e.arguments.map((e=>S(e,t)))}:"identifier"===e.type&&t[e.name]?{...t[e.name],type:"literal"}:e,D=(e,t={})=>{if(null==e||""===e.trim())return i("");const r=O(e),n=Object.keys(t).reduce(((e,r)=>{return{...e,[r]:(n=t[r],void 0===n.value||null===n.value||Number.isNaN(n.value)?{type:"literal",value:null,dataType:"null",options:{}}:{...n,value:o(n.dataType,n.value,n.options)})};var n}),{});return(e=>d((()=>U(e))))(S(r,n))},N=e=>{if(null==e||""===e.trim())return[];const t=O(e);return F(t).reduce(((e,t)=>(e.indexOf(t)<0&&e.push(t),e)),[])},I=e=>null==e||""===e.trim()?{}:O(e),j=e=>f(e);export{I as ast,N as extract,D as parse,j as toString}; | ||
import e from"decimal.js";var t=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a={},u=(r=void 0!==r?r:{}).grammarSource,o={start:ke},i=ke,l="(",s=")",c="+",p="-",d="<=",v=">=",f="<>",m="==",h="!=",g="&&",y="||",b=/^[A-Za-z]/,x=/^[0-9]/,T=/^[1-9]/,$=/^[\n\r\u2028\u2029]/,w=Te("(",!1),C=Te(")",!1),A=Te("^",!1),k=Te("*",!1),E=Te("/",!1),M=Te("+",!1),U=Te("-",!1),O=Te("<=",!1),F=Te(">=",!1),S=Te("<>",!1),D=Te("<",!1),N=Te(">",!1),I=Te("==",!1),j=Te("=",!1),q=Te("!=",!1),R=Te("&&",!1),P=Te("||",!1),W=Te("&",!1),Z=Te("!",!1),_=Te(",",!1),L=$e([["A","Z"],["a","z"]],!1,!1),Y=Te("_",!1),z=Te("$",!1),Q=Te("[",!1),X=Te(".",!1),B=Te("]",!1),H=Te("0",!1),V=$e([["0","9"]],!1,!1),G=$e([["1","9"]],!1,!1),K=Te("true",!0),J=Te("false",!0),ee=Te("null",!0),te=Te("\\",!1),re=Te("'",!1),ne=Te('"',!1),ae={type:"any"},ue=$e(["\n","\r","\u2028","\u2029"],!1,!1),oe=Te("\t",!1),ie=Te("\v",!1),le=Te("\f",!1),se=Te(" ",!1),ce=Te(" ",!1),pe=Te("",!1),de=Te("\ufeff",!1),ve=function(e,t){return function(e){const t=[],r=[];e.forEach((e=>{if("operator"===e.type){for(;t.length>0&&!(t[t.length-1].precedence<e.precedence);){let e=t.pop(),n=r.pop(),a=r.pop();r.push(He(e,a,n))}t.push(e)}else r.push(e)}));for(;t.length>0;){let e=t.pop(),n=r.pop(),a=r.pop();r.push(He(e,a,n))}return r.pop()}([e,t].flat(2))},fe=0,me=0,he=[{line:1,column:1}],ge=0,ye=[],be=0;if("startRule"in r){if(!(r.startRule in o))throw new Error("Can't start parsing from rule \""+r.startRule+'".');i=o[r.startRule]}function xe(){return t.substring(me,fe)}function Te(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function we(e){var r,n=he[e];if(n)return n;for(r=e-1;!he[r];)r--;for(n={line:(n=he[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return he[e]=n,n}function Ce(e,t){var r=we(e),n=we(t);return{source:u,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function Ae(e){fe<ge||(fe>ge&&(ge=fe,ye=[]),ye.push(e))}function ke(){return Ee()}function Ee(){var e;return(e=Se())===a&&(e=function(){var e,r,n;e=fe,r=function(){var e;33===t.charCodeAt(fe)?(e="!",fe++):(e=a,0===be&&Ae(Z));return e}(),r!==a?(ze(),(n=Ee())!==a?(me=e,e={type:"callExpression",id:"not",arguments:[n]}):(fe=e,e=a)):(fe=e,e=a);return e}())===a&&(e=Ue())===a&&(e=Ne())===a&&(e=qe()),e}function Me(){var e,r,n,u;return(e=Ue())===a&&(e=Ne())===a&&(e=qe())===a&&(e=fe,40===t.charCodeAt(fe)?(r="(",fe++):(r=a,0===be&&Ae(w)),r!==a?(ze(),(n=Oe())!==a?(ze(),41===t.charCodeAt(fe)?(u=")",fe++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(fe=e,e=a)):(fe=e,e=a)):(fe=e,e=a),e===a&&(e=fe,40===t.charCodeAt(fe)?(r="(",fe++):(r=a,0===be&&Ae(w)),r!==a?(ze(),(n=Se())!==a?(ze(),41===t.charCodeAt(fe)?(u=")",fe++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(fe=e,e=a)):(fe=e,e=a)):(fe=e,e=a))),e}function Ue(){var e,r,n,u;return e=fe,r=function(){var e,r,n;e=fe,r=[],b.test(t.charAt(fe))?(n=t.charAt(fe),fe++):(n=a,0===be&&Ae(L));if(n!==a)for(;n!==a;)r.push(n),b.test(t.charAt(fe))?(n=t.charAt(fe),fe++):(n=a,0===be&&Ae(L));else r=a;r!==a&&(me=e,r=r.join("").toLowerCase());return e=r}(),r!==a?(ze(),n=function(){var e,r,n,u;e=fe,40===t.charCodeAt(fe)?(r=l,fe++):(r=a,0===be&&Ae(w));r!==a?(ze(),n=fe,u=function(){var e,r,n,u;e=fe,r=[],n=fe,(u=Ee())!==a?(ze(),44===t.charCodeAt(fe)?fe++:0===be&&Ae(_),ze(),me=n,n=u):(fe=n,n=a);if(n!==a)for(;n!==a;)r.push(n),n=fe,(u=Ee())!==a?(ze(),44===t.charCodeAt(fe)?fe++:0===be&&Ae(_),ze(),me=n,n=u):(fe=n,n=a);else r=a;r!==a&&(me=e);return e=r}(),u!==a?n=u=[u,ze()]:(fe=n,n=a),n===a&&(n=null),41===t.charCodeAt(fe)?(u=s,fe++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(fe=e,e=a)):(fe=e,e=a);return e}(),n!==a?(me=e,e={type:"callExpression",id:r,arguments:(u=n,null!==u?u[0]:[])}):(fe=e,e=a)):(fe=e,e=a),e}function Oe(){var e,t,r,n;if(e=fe,(t=Me())!==a){for(ze(),r=[],n=Fe();n!==a;)r.push(n),n=Fe();me=e,e=ve(t,r)}else fe=e,e=a;return e}function Fe(){var e,r,n,u,o;return e=fe,ze(),r=function(){var e;94===t.charCodeAt(fe)?(e="^",fe++):(e=a,0===be&&Ae(A));e===a&&(42===t.charCodeAt(fe)?(e="*",fe++):(e=a,0===be&&Ae(k)),e===a&&(47===t.charCodeAt(fe)?(e="/",fe++):(e=a,0===be&&Ae(E)),e===a&&(43===t.charCodeAt(fe)?(e=c,fe++):(e=a,0===be&&Ae(M)),e===a&&(45===t.charCodeAt(fe)?(e=p,fe++):(e=a,0===be&&Ae(U))))));return e}(),r!==a?(ze(),(n=Me())!==a?(me=e,u=r,o=n,e=[Object.assign({type:"operator"},Xe[u]),o]):(fe=e,e=a)):(fe=e,e=a),e}function Se(){var e,r,n,u;return e=fe,(r=De())!==a?(ze(),n=function(){var e;t.substr(fe,2)===g?(e=g,fe+=2):(e=a,0===be&&Ae(R));e===a&&(t.substr(fe,2)===y?(e=y,fe+=2):(e=a,0===be&&Ae(P)));return e}(),n!==a?(ze(),(u=Se())!==a?(me=e,e=function(e,t,r){var n;switch(t){case"||":n="or";break;case"&&":n="and"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(fe=e,e=a)):(fe=e,e=a)):(fe=e,e=a),e===a&&(e=De()),e}function De(){var e,r,n,u;return e=fe,(r=Oe())!==a?(ze(),n=function(){var e;t.substr(fe,2)===d?(e=d,fe+=2):(e=a,0===be&&Ae(O));e===a&&(t.substr(fe,2)===v?(e=v,fe+=2):(e=a,0===be&&Ae(F)),e===a&&(t.substr(fe,2)===f?(e=f,fe+=2):(e=a,0===be&&Ae(S)),e===a&&(60===t.charCodeAt(fe)?(e="<",fe++):(e=a,0===be&&Ae(D)),e===a&&(62===t.charCodeAt(fe)?(e=">",fe++):(e=a,0===be&&Ae(N)),e===a&&(t.substr(fe,2)===m?(e=m,fe+=2):(e=a,0===be&&Ae(I)),e===a&&(61===t.charCodeAt(fe)?(e="=",fe++):(e=a,0===be&&Ae(j)),e===a&&(t.substr(fe,2)===h?(e=h,fe+=2):(e=a,0===be&&Ae(q)))))))));return e}(),n===a&&(n=function(){var e;38===t.charCodeAt(fe)?(e="&",fe++):(e=a,0===be&&Ae(W));return e}()),n!==a?(ze(),(u=De())!==a?(me=e,e=function(e,t,r){var n;switch(t){case"<":n="lessThan";break;case"<=":n="lessThanOrEqual";break;case">":n="greaterThan";break;case">=":n="greaterThanOrEqual";break;case"==":case"=":n="equal";break;case"!=":case"<>":n="unequal";break;case"&":n="add"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(fe=e,e=a)):(fe=e,e=a)):(fe=e,e=a),e===a&&(e=Oe()),e}function Ne(){var e,t,r;return e=fe,t=fe,be++,r=function(){var e;(e=We())===a&&(e=Ze());return e}(),be--,r===a?t=void 0:(fe=t,t=a),t!==a?(r=function(){var e,t,r,n;if(e=fe,(t=Ie())!==a){for(r=[],n=je();n!==a;)r.push(n),n=je();me=e,e={type:"identifier",name:t+r.join("")}}else fe=e,e=a;return e}(),r!==a?(me=e,e=r):(fe=e,e=a)):(fe=e,e=a),e}function Ie(){var e;return 95===t.charCodeAt(fe)?(e="_",fe++):(e=a,0===be&&Ae(Y)),e===a&&(36===t.charCodeAt(fe)?(e="$",fe++):(e=a,0===be&&Ae(z)),e===a&&(91===t.charCodeAt(fe)?(e="[",fe++):(e=a,0===be&&Ae(Q)),e===a&&(b.test(t.charAt(fe))?(e=t.charAt(fe),fe++):(e=a,0===be&&Ae(L))))),e}function je(){var e;return(e=Ie())===a&&(46===t.charCodeAt(fe)?(e=".",fe++):(e=a,0===be&&Ae(X)),e===a&&(93===t.charCodeAt(fe)?(e="]",fe++):(e=a,0===be&&Ae(B)),e===a&&(e=Pe()))),e}function qe(){var e;return(e=function(){var e,t,r;if(e=fe,Le()!==a){for(t=[],(r=_e())===a&&(r=Ye());r!==a;)t.push(r),(r=_e())===a&&(r=Ye());(r=Le())!==a?(me=e,e=Be(t)):(fe=e,e=a)}else fe=e,e=a;if(e===a)if(e=fe,Ye()!==a){for(t=[],(r=_e())===a&&(r=Le());r!==a;)t.push(r),(r=_e())===a&&(r=Le());(r=Ye())!==a?(me=e,e=function(e){return Be(e)}(t)):(fe=e,e=a)}else fe=e,e=a;return e}())===a&&(e=function(){var e,r,n,u,o,i;e=fe,r=fe,n=ze(),43===t.charCodeAt(fe)?(u=c,fe++):(u=a,0===be&&Ae(M));u!==a?r=n=[n,u]:(fe=r,r=a);r===a&&(r=fe,45===t.charCodeAt(fe)?(n=p,fe++):(n=a,0===be&&Ae(U)),n!==a?r=n=[n,u=ze()]:(fe=r,r=a));r===a&&(r=null);if((n=Re())!==a)if(46===t.charCodeAt(fe)?(u=".",fe++):(u=a,0===be&&Ae(X)),u!==a){for(o=[],i=Pe();i!==a;)o.push(i),i=Pe();me=e,l=xe().replace(/[\+\-]/g,"").split("."),e={type:"literal",value:parseFloat(xe()),dataType:"number",options:{length:l[0].length,scale:l[1].length}}}else fe=e,e=a;else fe=e,e=a;var l;e===a&&(e=fe,r=fe,n=ze(),43===t.charCodeAt(fe)?(u=c,fe++):(u=a,0===be&&Ae(M)),u!==a?r=n=[n,u]:(fe=r,r=a),r===a&&(r=fe,45===t.charCodeAt(fe)?(n=p,fe++):(n=a,0===be&&Ae(U)),n!==a?r=n=[n,u=ze()]:(fe=r,r=a)),r===a&&(r=null),(n=Re())!==a?(me=e,e={type:"literal",value:parseInt(xe()),dataType:"number",options:{length:xe().replace(/[\+\-]/g,"").length,scale:0}}):(fe=e,e=a));return e}())===a&&(e=We())===a&&(e=Ze()),e}function Re(){var e,r,n,u;if(48===t.charCodeAt(fe)?(e="0",fe++):(e=a,0===be&&Ae(H)),e===a)if(e=fe,r=function(){var e;T.test(t.charAt(fe))?(e=t.charAt(fe),fe++):(e=a,0===be&&Ae(G));return e}(),r!==a){for(n=[],u=Pe();u!==a;)n.push(u),u=Pe();e=r=[r,n]}else fe=e,e=a;return e}function Pe(){var e;return x.test(t.charAt(fe))?(e=t.charAt(fe),fe++):(e=a,0===be&&Ae(V)),e}function We(){var e,r;return e=fe,"true"===t.substr(fe,4).toLowerCase()?(r=t.substr(fe,4),fe+=4):(r=a,0===be&&Ae(K)),r!==a&&(me=e,r={type:"literal",value:!0,dataType:"checkbox",options:{}}),(e=r)===a&&(e=fe,"false"===t.substr(fe,5).toLowerCase()?(r=t.substr(fe,5),fe+=5):(r=a,0===be&&Ae(J)),r!==a&&(me=e,r={type:"literal",value:!1,dataType:"checkbox",options:{}}),e=r),e}function Ze(){var e,r;return e=fe,"null"===t.substr(fe,4).toLowerCase()?(r=t.substr(fe,4),fe+=4):(r=a,0===be&&Ae(ee)),r!==a&&(me=e,r={type:"literal",value:null,dataType:"null",options:{}}),e=r}function _e(){var e,r,n;return e=fe,r=fe,be++,n=function(){var e;(e=Le())===a&&(e=Ye());return e}(),n===a&&(92===t.charCodeAt(fe)?(n="\\",fe++):(n=a,0===be&&Ae(te))),be--,n===a?r=void 0:(fe=r,r=a),r!==a?(n=function(){var e;t.length>fe?(e=t.charAt(fe),fe++):(e=a,0===be&&Ae(ae));return e}(),n!==a?(me=e,e=xe()):(fe=e,e=a)):(fe=e,e=a),e}function Le(){var e;return 39===t.charCodeAt(fe)?(e="'",fe++):(e=a,0===be&&Ae(re)),e}function Ye(){var e;return 34===t.charCodeAt(fe)?(e='"',fe++):(e=a,0===be&&Ae(ne)),e}function ze(){var e,t;for(e=[],t=Qe();t!==a;)e.push(t),t=Qe();return e}function Qe(){var e;return 9===t.charCodeAt(fe)?(e="\t",fe++):(e=a,0===be&&Ae(oe)),e===a&&(e=function(){var e;return $.test(t.charAt(fe))?(e=t.charAt(fe),fe++):(e=a,0===be&&Ae(ue)),e}())===a&&(11===t.charCodeAt(fe)?(e="\v",fe++):(e=a,0===be&&Ae(ie)),e===a&&(12===t.charCodeAt(fe)?(e="\f",fe++):(e=a,0===be&&Ae(le)),e===a&&(32===t.charCodeAt(fe)?(e=" ",fe++):(e=a,0===be&&Ae(se)),e===a&&(160===t.charCodeAt(fe)?(e=" ",fe++):(e=a,0===be&&Ae(ce)),e===a&&(8203===t.charCodeAt(fe)?(e="",fe++):(e=a,0===be&&Ae(pe)),e===a&&(65279===t.charCodeAt(fe)?(e="\ufeff",fe++):(e=a,0===be&&Ae(de)))))))),e}const Xe={"^":{functionName:"exponentiate",rightAssociative:!0,precedence:4},"*":{functionName:"multiply",rightAssociative:!1,precedence:3},"/":{functionName:"divide",rightAssociative:!1,precedence:3},"+":{functionName:"add",rightAssociative:!1,precedence:2},"-":{functionName:"subtract",rightAssociative:!1,precedence:2}};function Be(e){return{type:"literal",value:e.join(""),dataType:"text",options:{length:e.length}}}function He(e,t,r){return{type:"callExpression",id:e.functionName,arguments:[t,r]}}if((n=i())!==a&&fe===t.length)return n;throw n!==a&&fe<t.length&&Ae({type:"end"}),Ve=ye,Ge=ge<t.length?t.charAt(ge):null,Ke=ge<t.length?Ce(ge,ge+1):Ce(ge,ge),new e(e.buildMessage(Ve,Ge),Ve,Ge,Ke);var Ve,Ge,Ke}}}(),r=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a,u,o,i={},l=(r=void 0!==r?r:{}).grammarSource,s={Time:E},c=E,p=/^[0-9]/,d=w(":",!1),v=w(".",!1),f={type:"class",parts:[["0","9"]],inverted:!1,ignoreCase:!1},m=function(e,t,r,n){return function(e,t,r,n){e>23&&$("hour part needs to be under 24");t>59&&$("minute part needs to be under 60");r>59&&$("second part needs to be under 60");n>999&&$("millisecond part needs to be under 1000")}(e,t,r,n),{type:"literal",value:new Date(n+1e3*r+60*t*1e3+60*e*60*1e3),dataType:"time",options:{}}},h=0,g=0,y=[{line:1,column:1}],b=0,x=[];if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');c=s[r.startRule]}function T(){return t.substring(g,h)}function $(t,r){throw function(t,r){return new e(t,null,null,r)}(t,r=void 0!==r?r:A(g,h))}function w(e,t){return{type:"literal",text:e,ignoreCase:t}}function C(e){var r,n=y[e];if(n)return n;for(r=e-1;!y[r];)r--;for(n={line:(n=y[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return y[e]=n,n}function A(e,t){var r=C(e),n=C(t);return{source:l,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function k(e){h<b||(h>b&&(b=h,x=[]),x.push(e))}function E(){var e,r,n,a,u,o,l,s;return e=h,r=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),r!==i?(58===t.charCodeAt(h)?(n=":",h++):(n=i,k(d)),n!==i?(a=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),a!==i?(58===t.charCodeAt(h)?(u=":",h++):(u=i,k(d)),u!==i?(o=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),o!==i?(46===t.charCodeAt(h)?(l=".",h++):(l=i,k(v)),l!==i?(s=function(){var e;e=h,M()!==i&&M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),s!==i?(g=e,e=m(r,a,o,s)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i),e}function M(){var e;return p.test(t.charAt(h))?(e=t.charAt(h),h++):(e=i,k(f)),e}if((n=c())!==i&&h===t.length)return n;throw n!==i&&h<t.length&&k({type:"end"}),a=x,u=b<t.length?t.charAt(b):null,o=b<t.length?A(b,b+1):A(b,b),new e(e.buildMessage(a,u),a,u,o)}}}();class n extends Error{constructor(e,t,r){super(e),this.errorType=t,this.options=r}}const a=(e,t)=>{if(e<0)return-1*a(-1*e,t);const r=10**t;return Math.round(e*r)/r},u=e=>{const t=e.toString().replace("-","");if(-1!==t.indexOf(".")){const e=t.split(".");return{length:e[0].length,scale:e[1].length}}return{length:t.length,scale:0}},o=(e,t,r)=>{switch(e){case"number":return a(t,r.scale);case"text":return t.substring(0,r.length);default:return t}},i=e=>{const t={type:"literal",value:e};if(null==e)return Object.assign(t,{value:null,dataType:"null",options:{}});const r=typeof e;switch(typeof e){case"number":return Object.assign(t,{dataType:"number",options:u(e)});case"string":return Object.assign(t,{dataType:"text",options:{length:e.length}});case"boolean":return Object.assign(t,{dataType:"checkbox",options:{}});default:throw new TypeError(`Unsupported type '${r}'`)}},l=(e,t,r)=>({type:"error",errorType:e,message:t,...r}),s=(e,t,r)=>e instanceof Date?s(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()):{type:"literal",dataType:"date",value:new Date(Date.UTC(e,t-1,r)),options:{}},c=e=>({type:"literal",dataType:"datetime",value:new Date(e),options:{}}),p=e=>({type:"literal",dataType:"time",value:new Date(e),options:{}}),d=e=>{try{return e()}catch(e){if(e instanceof n)return l(e.errorType,e.message,e.options);throw e}},v=(e,t)=>new Date(e.getTime()+864e5*t),f=e=>{if(!e.value&&"null"!==e.dataType&&0!==e.value&&!1!==e.value&&""!==e.value)return"";switch(e.dataType){case"null":return"NULL";case"number":return e.value.toString();case"text":case"picklist":return`"${e.value}"`;case"multipicklist":return`[${e.value.map((e=>`"${e}"`)).join(", ")}]`;case"checkbox":return e.value.toString().toUpperCase();case"date":return`${e.value.getUTCFullYear()}-${(e.value.getUTCMonth()+1).toString().padStart(2,"0")}-${e.value.getUTCDate().toString().padStart(2,"0")}`;case"datetime":return e.value.toISOString();case"time":return e.value.toISOString().split("T")[1].replace("Z","");case"geolocation":return t=e.value[0],r=e.value[1],t&&r||0===t||0===r?`${t.toFixed(6)}, ${r.toFixed(6)}`:"";default:return}var t,r};class m extends n{constructor(e,t){super(e,"NotImplementedError",t)}static throwError(e){throw new m(`Function ${e} not implemented yet.`,{name:e})}}const h=e=>Array.isArray(e)?e.map((e=>h(e))).join(", "):"string"!=typeof e?"":e.charAt(0).toUpperCase()+e.slice(1);class g extends n{constructor(e,t){super(e,"ArgumentError",t)}static throwWrongType(e,t,r){const n={function:e,expected:t,received:r},a=r||"Non-Salesforce";throw new g(`Incorrect parameter type for function '${e.toUpperCase()}()'. Expected ${h(t)}, received ${h(a)}`,n)}static throwIncorrectNumberOfArguments(e,t,r){const n={function:e,expected:t,received:r};throw new g(`Incorrect number of parameters for function '${e.toUpperCase()}()'. Expected ${t}, received ${r}`,n)}}const y=(e,t)=>{switch(e.dataType){case"date":case"datetime":return i(e.value.getTime()===t.value.getTime());default:return i(e.value===t.value)}},b=(e,t,r)=>i(e.value.substr(t.value-1,r.value)),x=(e,t)=>b(e,i(1),t);var T=Object.freeze({__proto__:null,sf$or:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e||t));return i(t)},sf$equal:y,sf$unequal:(e,t)=>i(!y(e,t).value),sf$greaterThan:(e,t)=>i(e.value>t.value),sf$greaterThanOrEqual:(e,t)=>i(e.value>=t.value),sf$lessThan:(e,t)=>i(e.value<t.value),sf$lessThanOrEqual:(e,t)=>i(e.value<=t.value),sf$addmonths:(e,t)=>s(((e,t)=>{const r=e.getUTCMonth()+t,n=new Date(Date.UTC(e.getUTCFullYear(),r,e.getUTCDate()));return e.getUTCDate()!==n.getUTCDate()&&n.setUTCDate(0),n})(e.value,t.value)),sf$date:(e,t,r)=>s(e.value,t.value,r.value),sf$datevalue:e=>s(new Date(Date.parse(e.value))),sf$datetimevalue:e=>c(Date.parse(`${e.value}Z`)),sf$day:e=>i(e.value.getUTCDate()),sf$hour:e=>i(e.value.getUTCHours()),sf$millisecond:e=>i(e.value.getUTCMilliseconds()),sf$minute:e=>i(e.value.getUTCMinutes()),sf$month:e=>i(e.value.getUTCMonth()+1),sf$now:()=>c((new Date).getTime()),sf$second:e=>i(e.value.getUTCSeconds()),sf$timenow:()=>p((new Date).getTime()%864e5),sf$timevalue:e=>(e=>{try{return r.parse(e)}catch(e){if(e instanceof r.SyntaxError)return i(null);throw e}})(e.value),sf$today:()=>s(new Date),sf$weekday:e=>i(e.value.getUTCDay()+1),sf$year:e=>i(e.value.getUTCFullYear()),sf$and:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e&&t));return i(t)},sf$blankvalue:(e,t)=>"null"===e.dataType||""===e.value?t:e,sf$case:(e,...t)=>{const r=t.length-1;if(r<=0){const e={function:"case",expected:4,received:r+2};throw new g(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}+, received ${e.received}`,e)}if(r%2!=0){const e={function:"case",expected:r+1,received:r+2};throw new g(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}, received ${e.received}`,e)}for(let n=0;n<r;n+=2)if(y(t[n],e).value)return t[n+1];return t[r]},sf$if:(e,t,r)=>e.value?t:r,sf$isblank:e=>i("null"===e.dataType||""===e.value),sf$isnull:e=>{m.throwError("isnull")},sf$isnumber:e=>{m.throwError("isnumber")},sf$not:e=>i(!e.value),sf$nullvalue:(e,t)=>{m.throwError("nullvalue")},sf$add:(t,r)=>{switch([t.dataType,r.dataType].join(" ")){case"date number":return s(v(t.value,r.value));case"number date":return s(v(r.value,t.value));case"time number":return p(t.value.getTime()+r.value);case"number time":return p(t.value+r.value.getTime());case"datetime number":return c(v(t.value,r.value));case"number datetime":return c(v(r.value,t.value));case"number number":return i(new e(t.value).plus(new e(r.value)).toNumber());case"text text":return i(t.value+r.value);default:g.throwWrongType("add","number",r.dataType)}},sf$subtract:(t,r)=>{switch([t.dataType,r.dataType].join(" ")){case"date number":return s(v(t.value,-1*r.value));case"time number":return p(t.value.getTime()+-1*r.value);case"datetime number":return c(v(t.value,-1*r.value));case"date date":case"datetime datetime":return i((n=t.value,a=r.value,(n.getTime()-a.getTime())/864e5));case"time time":return i(t.value.getTime()-r.value.getTime());case"number number":return i(new e(t.value).minus(new e(r.value)).toNumber());case"text text":return i(t.value-r.value);default:g.throwWrongType("subtract","number",r.dataType)}var n,a},sf$multiply:(t,r)=>i(new e(t.value).times(new e(r.value)).toNumber()),sf$divide:(t,r)=>i(new e(t.value).dividedBy(new e(r.value)).toNumber()),sf$exponentiate:(t,r)=>i(new e(t.value).toPower(new e(r.value)).toNumber()),sf$abs:e=>i(Math.abs(e.value)),sf$ceiling:e=>e.value<0?i(-1*Math.ceil(-1*e.value)):i(Math.ceil(e.value)),sf$distance:(e,t,r)=>{const n=r.value;if("km"!==n&&"mi"!==n){throw new g(`Incorrect parameter value for function 'DISTANCE()'. Expected 'mi'/'km', received '${n}'`,{function:"distance",expected:["km","mi"],received:n})}const[a,u]=e.value,[o,l]=t.value;if(a===o&&u===l)return i(0);const s=a*Math.PI/180,c=o*Math.PI/180,p=(o-a)*Math.PI/180,d=(l-u)*Math.PI/180,v=Math.sin(p/2)*Math.sin(p/2)+Math.cos(s)*Math.cos(c)*Math.sin(d/2)*Math.sin(d/2),f=6371009*(2*Math.atan2(Math.sqrt(v),Math.sqrt(1-v)))/1e3;return i("mi"===n?f/1.609344:f)},sf$exp:e=>i(Math.exp(e.value)),sf$floor:e=>e.value<0?i(-1*Math.floor(-1*e.value)):i(Math.floor(e.value)),sf$geolocation:(e,t)=>((e,t)=>({type:"literal",dataType:"geolocation",value:[e,t],options:{}}))(e.value,t.value),sf$ln:e=>i(Math.log(e.value)),sf$log:e=>i(Math.log10(e.value)),sf$max:(...e)=>{const t=e.map((e=>e.value));return i(Math.max(...t))},sf$mceiling:e=>i(Math.ceil(e.value)),sf$mfloor:e=>i(Math.floor(e.value)),sf$min:(...e)=>{const t=e.map((e=>e.value));return i(Math.min(...t))},sf$mod:(e,t)=>i(e.value%t.value),sf$round:(e,t)=>i(a(e.value,t.value)),sf$sqrt:e=>i(Math.sqrt(e.value)),sf$begins:(e,t)=>i(e.value.startsWith(t.value)),sf$br:()=>i("\n"),sf$casesafeid:e=>{let t="";return[0,1,2].forEach((r=>{let n=0;[0,1,2,3,4].forEach((t=>{const a=e.value[5*r+t];a.toUpperCase()===a&&a>="A"&&a<="Z"&&(n+=1<<t)})),t+="ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[n]})),i(e.value+t)},sf$concat:(e,t)=>i(e.value+t.value),sf$contains:(e,t)=>i(e.value.includes(t.value)),sf$find:(e,t,r=i(1))=>{if(r.value<=0||""===e.value)return i(0);const n=t.value.substring(r.value-1);return i(n.indexOf(e.value)+1)},sf$getsessionid:()=>i("00D3z000001eRlg!AQMAQC3Y4aM9sFux6SRWhyFcOUKin4taGaBxNMU8TN_R_1R0Y7ArI95eSyzQZVIlrnV_unTbmwHZlXex8xhlXz2kXZNP49Fa"),sf$hyperlink:(e,t,r=null)=>{const n=r?` target="${r.value}"`:"";return i(`<a href="${e.value}"${n}>${t.value}</a>`)},sf$image:(e,t,r=null,n=null)=>{const a=r?` height="${r.value}"`:"",u=n?` width="${n.value}"`:"";return i(`<img src="${e.value}" alt="${t.value}"${a}${u}/>`)},sf$includes:(e,t)=>i(e.value.includes(t.value)),sf$ispickval:(e,t)=>i(e.value===t.value),sf$mid:b,sf$left:x,sf$len:e=>i(e.value.length),sf$lower:(e,t)=>i(e.value.toLowerCase()),sf$lpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return x(e,t);const n=r.value.repeat(t.value);return i((n+e.value).slice(-t.value))},sf$right:(e,t)=>i(e.value.substr(e.value.length-t.value)),sf$rpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return x(e,t);const n=r.value.repeat(t.value);return i((e.value+n).substr(0,t.value))},sf$substitute:(e,t,r)=>i(e.value.replace(new RegExp(t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),r.value)),sf$text:e=>"datetime"===e.dataType?i(f(e).replace("T"," ").replace(/\.\d{3}/,"")):"picklist"===e.dataType?i(e.value):i(f(e)),sf$trim:e=>i(e.value.trim()),sf$upper:(e,t)=>i(e.value.toUpperCase()),sf$value:e=>{const t=parseFloat(e.value);return i(t||null)},sf$currencyrate:e=>{m.throwError("currencyrate")},sf$regex:(e,t)=>{const r=new RegExp(`^${t.value}$`);return i(null!=r.exec(e.value))}});const $=e=>t=>r=>{r.length<e&&g.throwIncorrectNumberOfArguments(t,e,r.length)},w=e=>t=>r=>{r.length>e&&g.throwIncorrectNumberOfArguments(t,e,r.length)},C=(...e)=>t=>r=>{r.map(((t,r)=>[t.dataType,e[r]||e[e.length-1]])).forEach((([e,r])=>{"null"!==e&&(Array.isArray(r)?-1===r.indexOf(e)&&g.throwWrongType(t,r,e):e!==r&&g.throwWrongType(t,r,e))}))},A=()=>e=>t=>{const r=t.filter((e=>"null"!==e.dataType));r.length>0&&r.reduce(((t,r)=>(t.dataType!==r.dataType&&g.throwWrongType(e,t.dataType,r.dataType),r)))};class k extends n{constructor(e,t){super(e,"NoFunctionError",t)}}const E={abs:{validations:[$(1),w(1),C("number")],returnType:"number"},add:{validations:[$(2),w(2),C(["number","text","date","datetime","time"],["number","text","date","datetime","time"])],returnType:["number","text","date","datetime","time"]},addmonths:{validations:[$(2),w(2),C(["date","datetime"],["number"])],returnType:["date","datetime"]},and:{validations:[$(1),C("checkbox")],returnType:"checkbox"},begins:{validations:[$(2),w(2),C("text","text")],returnType:"checkbox"},blankvalue:{validations:[$(2),w(2),C(["text","number","date","datetime","geolocation"]),A()],returnType:["text","number"]},br:{validations:[$(0),w(0)],returnType:"text"},case:{validations:[$(4),C(["text","number","picklist","date","datetime"]),e=>t=>{const r="picklist"===t[0].dataType?"text":t[0].dataType,n=t.filter(((e,r)=>r%2==1&&r!==t.length-1)).find((e=>e.dataType!==r));n&&g.throwWrongType(e,r,n.dataType)}],returnType:["text","number","date","datetime"]},casesafeid:{validations:[$(1),w(1),C("text")],returnType:"text"},ceiling:{validations:[$(1),w(1),C("number")],returnType:"number"},contains:{validations:[$(2),w(2),C("text","text")],returnType:"checkbox"},currencyrate:{validations:[$(1),w(1),C("text")],returnType:"text"},date:{validations:[$(3),w(3),C("number","number","number")],returnType:"date"},datetimevalue:{validations:[$(1),w(1),C("text","date","datetime")],returnType:"datetime"},datevalue:{validations:[$(1),w(1),C(["text","date","datetime"])],returnType:"date"},day:{validations:[$(1),w(1),C("date")],returnType:"number"},distance:{validations:[$(3),w(3),C("geolocation","geolocation","text")],returnType:"number"},divide:{validations:[$(2),w(2),C("number","number")],returnType:"number"},equal:{validations:[$(2),w(2),C(["text","number","date","datetime","checkbox"]),A()],returnType:"checkbox"},exp:{validations:[$(1),w(1),C("number")],returnType:"number"},exponentiate:{validations:[$(2),w(2),C("number","number")],returnType:"number"},find:{validations:[$(2),w(3),C("text","text","number")],returnType:"number"},floor:{validations:[$(1),w(1),C("number")],returnType:"number"},geolocation:{validations:[$(2),w(2),C("number","number")],returnType:"geolocation"},getsessionid:{validations:[$(0),w(0)],returnType:"text"},greaterThan:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},greaterThanOrEqual:{validations:[$(2),w(2),C(["number","date","datetime"])],returnType:"checkbox"},hour:{validations:[$(1),w(1),C("datetime")],returnType:"number"},hyperlink:{validations:[$(2),w(3),C("text","text","text")],returnType:"text"},if:{validations:[$(3),w(3),C("checkbox",["text","number","date","datetime","checkbox","geolocation"],["text","number","date","datetime","checkbox","geolocation"])],returnType:["text","number","date","datetime","checkbox","geolocation"]},image:{validations:[$(2),w(4),C("text","text","number","number")],returnType:"text"},includes:{validations:[$(2),w(2),C("multipicklist","text")],returnType:"checkbox"},isblank:{validations:[$(1),w(1),C(["text","number","date","datetime","geolocation"])],returnType:"checkbox"},isnull:{validations:[$(1),w(1),C(["text","number"])],returnType:"checkbox"},ispickval:{validations:[$(2),w(2),C("picklist","text")],returnType:"checkbox"},isnumber:{validations:[$(1),w(1),C("text")],returnType:"checkbox"},left:{validations:[$(2),w(2),C("text","number")],returnType:"text"},len:{validations:[$(1),w(1),C("text")],returnType:"number"},lessThan:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},lessThanOrEqual:{validations:[$(2),w(2),C(["number","date","datetime"]),A()],returnType:"checkbox"},ln:{validations:[$(1),w(1),C("number")],returnType:"number"},log:{validations:[$(1),w(1),C("number")],returnType:"checkbox"},lower:{validations:[$(1),w(1),C("text")],returnType:"text"},lpad:{validations:[$(2),w(3),C("text","number","text")],returnType:"text"},max:{validations:[$(1),C("number")],returnType:"number"},mceiling:{validations:[$(1),w(1),C("number")],returnType:"number"},mfloor:{validations:[$(1),w(1),C("number")],returnType:"number"},mid:{validations:[$(3),w(3),C("text","number","number")],returnType:"number"},millisecond:{validations:[$(1),w(1),C("datetime")],returnType:"number"},min:{validations:[$(1),C("number")],returnType:"number"},minute:{validations:[$(1),w(1),C("datetime")],returnType:"number"},mod:{validations:[$(2),w(2),C("number","number")],returnType:"number"},month:{validations:[$(1),w(1),C("date")],returnType:"number"},multiply:{validations:[$(2),w(2),C("number","number")],returnType:"number"},not:{validations:[$(1),w(1),C("checkbox")],returnType:"checkbox"},now:{validations:[$(0),w(0)],returnType:"datetime"},nullvalue:{validations:[$(2),w(2),C(["text","number"],["text","number"])],returnType:["text","number"]},or:{validations:[$(1),C("checkbox")],returnType:"checkbox"},regex:{validations:[$(2),w(2),C("text","text")],returnType:"text"},right:{validations:[$(2),w(2),C("text","number")],returnType:"text"},round:{validations:[$(2),w(2),C("number","number")],returnType:"number"},rpad:{validations:[$(2),w(3),C("text","number","text")],returnType:"text"},second:{validations:[$(1),w(1),C("datetime")],returnType:"number"},sqrt:{validations:[$(1),w(1),C("number")],returnType:"number"},subtract:{validations:[$(2),w(2),C(["number","date","datetime","time"],["number","date","datetime","time"])],returnType:["number","date","datetime","time"]},substitute:{validations:[$(3),w(3),C("text","text","text")],returnType:"text"},text:{validations:[$(1),w(1),C(["number","date","datetime","picklist","time"])],returnType:"text"},timenow:{validations:[$(0),w(0)],returnType:"time"},timevalue:{validations:[$(1),w(1),C("text")],returnType:"time"},today:{validations:[$(0),w(0)],returnType:"date"},trim:{validations:[$(1),w(1),C("text")],returnType:"text"},unequal:{validations:[$(2),w(2),C(["text","number","date","datetime","checkbox"]),A()],returnType:"checkbox"},upper:{validations:[$(1),w(1),C("text")],returnType:"text"},value:{validations:[$(1),w(1),C("text")],returnType:"number"},weekday:{validations:[$(1),w(1),C("date")],returnType:"number"},year:{validations:[$(1),w(1),C("date")],returnType:"number"}};class M extends n{constructor(e,t){super(e,"ReferenceError",t)}}const U=e=>{switch(e.type){case"callExpression":return t=e.id,r=e.arguments.map((e=>U(e))),d((()=>{const e=r.find((e=>"error"===e.type));if(e)return e;const n=E[t];if(n)return n.validations.forEach((e=>e(t)(r))),T[`sf$${t}`](...r);throw new k(`Unknown function ${t.toUpperCase()}. Check spelling.`,{function:t})}));case"identifier":throw new M(`Field ${e.name} does not exist. Check spelling.`,{identifier:e.name});default:return e}var t,r},O=e=>{try{return t.parse(null==e?"":e.trim())}catch(e){if(e instanceof t.SyntaxError)return l("SyntaxError","Syntax error.",{});throw e}},F=(e,t=[])=>{switch(e.type){case"callExpression":return e.arguments.map((e=>F(e,t))).reduce(((e,t)=>e.concat(t)),[]);case"identifier":return t.concat(e.name);default:return t}},S=(e,t)=>"callExpression"===e.type?{type:"callExpression",id:e.id,arguments:e.arguments.map((e=>S(e,t)))}:"identifier"===e.type&&t[e.name]?{...t[e.name],type:"literal"}:e,D=(e,t={})=>{if(null==e||""===e.trim())return i("");const r=O(e),n=Object.keys(t).reduce(((e,r)=>{return{...e,[r]:(n=t[r],void 0===n.value||null===n.value||Number.isNaN(n.value)?{type:"literal",value:null,dataType:"null",options:{}}:{...n,value:o(n.dataType,n.value,n.options)})};var n}),{});return(e=>d((()=>U(e))))(S(r,n))},N=e=>{if(null==e||""===e.trim())return[];const t=O(e);return F(t).reduce(((e,t)=>(e.indexOf(t)<0&&e.push(t),e)),[])},I=e=>null==e||""===e.trim()?{}:O(e),j=e=>f(e);export{I as ast,N as extract,D as parse,j as toString}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("decimal.js")):"function"==typeof define&&define.amd?define(["exports","decimal.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).formulon={},e.Decimal)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t),a=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a={},u=(r=void 0!==r?r:{}).grammarSource,o={start:Ce},i=Ce,l="(",s=")",c="+",d="-",p="<=",f=">=",v="<>",m="==",h="!=",g="&&",y="||",b=/^[A-Za-z]/,x=/^[0-9]/,T=/^[1-9]/,$=/^[\n\r\u2028\u2029]/,w=be("(",!1),C=be(")",!1),A=be("^",!1),k=be("*",!1),E=be("/",!1),M=be("+",!1),U=be("-",!1),O=be("<=",!1),S=be(">=",!1),F=be("<>",!1),j=be("<",!1),D=be(">",!1),N=be("==",!1),I=be("=",!1),q=be("!=",!1),R=be("&&",!1),P=be("||",!1),_=be("&",!1),W=be("!",!1),Z=be(",",!1),L=xe([["A","Z"],["a","z"]],!1,!1),Y=be("_",!1),z=be("$",!1),Q=be(".",!1),X=be("0",!1),B=xe([["0","9"]],!1,!1),H=xe([["1","9"]],!1,!1),V=be("true",!0),G=be("false",!0),K=be("null",!0),J=be("\\",!1),ee=be("'",!1),te=be('"',!1),re={type:"any"},ne=xe(["\n","\r","\u2028","\u2029"],!1,!1),ae=be("\t",!1),ue=be("\v",!1),oe=be("\f",!1),ie=be(" ",!1),le=be(" ",!1),se=be("",!1),ce=be("\ufeff",!1),de=function(e,t){return function(e){const t=[],r=[];e.forEach((e=>{if("operator"===e.type){for(;t.length>0&&!(t[t.length-1].precedence<e.precedence);){let e=t.pop(),n=r.pop(),a=r.pop();r.push(Xe(e,a,n))}t.push(e)}else r.push(e)}));for(;t.length>0;){let e=t.pop(),n=r.pop(),a=r.pop();r.push(Xe(e,a,n))}return r.pop()}([e,t].flat(2))},pe=0,fe=0,ve=[{line:1,column:1}],me=0,he=[],ge=0;if("startRule"in r){if(!(r.startRule in o))throw new Error("Can't start parsing from rule \""+r.startRule+'".');i=o[r.startRule]}function ye(){return t.substring(fe,pe)}function be(e,t){return{type:"literal",text:e,ignoreCase:t}}function xe(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function Te(e){var r,n=ve[e];if(n)return n;for(r=e-1;!ve[r];)r--;for(n={line:(n=ve[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return ve[e]=n,n}function $e(e,t){var r=Te(e),n=Te(t);return{source:u,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function we(e){pe<me||(pe>me&&(me=pe,he=[]),he.push(e))}function Ce(){return Ae()}function Ae(){var e;return(e=Oe())===a&&(e=function(){var e,r,n;e=pe,r=function(){var e;33===t.charCodeAt(pe)?(e="!",pe++):(e=a,0===ge&&we(W));return e}(),r!==a?(Le(),(n=Ae())!==a?(fe=e,e={type:"callExpression",id:"not",arguments:[n]}):(pe=e,e=a)):(pe=e,e=a);return e}())===a&&(e=Ee())===a&&(e=Fe())===a&&(e=Ne()),e}function ke(){var e,r,n,u;return(e=Ee())===a&&(e=Fe())===a&&(e=Ne())===a&&(e=pe,40===t.charCodeAt(pe)?(r="(",pe++):(r=a,0===ge&&we(w)),r!==a?(Le(),(n=Me())!==a?(Le(),41===t.charCodeAt(pe)?(u=")",pe++):(u=a,0===ge&&we(C)),u!==a?(fe=e,e=n):(pe=e,e=a)):(pe=e,e=a)):(pe=e,e=a),e===a&&(e=pe,40===t.charCodeAt(pe)?(r="(",pe++):(r=a,0===ge&&we(w)),r!==a?(Le(),(n=Oe())!==a?(Le(),41===t.charCodeAt(pe)?(u=")",pe++):(u=a,0===ge&&we(C)),u!==a?(fe=e,e=n):(pe=e,e=a)):(pe=e,e=a)):(pe=e,e=a))),e}function Ee(){var e,r,n,u;return e=pe,r=function(){var e,r,n;e=pe,r=[],b.test(t.charAt(pe))?(n=t.charAt(pe),pe++):(n=a,0===ge&&we(L));if(n!==a)for(;n!==a;)r.push(n),b.test(t.charAt(pe))?(n=t.charAt(pe),pe++):(n=a,0===ge&&we(L));else r=a;r!==a&&(fe=e,r=r.join("").toLowerCase());return e=r}(),r!==a?(Le(),n=function(){var e,r,n,u;e=pe,40===t.charCodeAt(pe)?(r=l,pe++):(r=a,0===ge&&we(w));r!==a?(Le(),n=pe,u=function(){var e,r,n,u;e=pe,r=[],n=pe,(u=Ae())!==a?(Le(),44===t.charCodeAt(pe)?pe++:0===ge&&we(Z),Le(),fe=n,n=u):(pe=n,n=a);if(n!==a)for(;n!==a;)r.push(n),n=pe,(u=Ae())!==a?(Le(),44===t.charCodeAt(pe)?pe++:0===ge&&we(Z),Le(),fe=n,n=u):(pe=n,n=a);else r=a;r!==a&&(fe=e);return e=r}(),u!==a?n=u=[u,Le()]:(pe=n,n=a),n===a&&(n=null),41===t.charCodeAt(pe)?(u=s,pe++):(u=a,0===ge&&we(C)),u!==a?(fe=e,e=n):(pe=e,e=a)):(pe=e,e=a);return e}(),n!==a?(fe=e,e={type:"callExpression",id:r,arguments:(u=n,null!==u?u[0]:[])}):(pe=e,e=a)):(pe=e,e=a),e}function Me(){var e,t,r,n;if(e=pe,(t=ke())!==a){for(Le(),r=[],n=Ue();n!==a;)r.push(n),n=Ue();fe=e,e=de(t,r)}else pe=e,e=a;return e}function Ue(){var e,r,n,u,o;return e=pe,Le(),r=function(){var e;94===t.charCodeAt(pe)?(e="^",pe++):(e=a,0===ge&&we(A));e===a&&(42===t.charCodeAt(pe)?(e="*",pe++):(e=a,0===ge&&we(k)),e===a&&(47===t.charCodeAt(pe)?(e="/",pe++):(e=a,0===ge&&we(E)),e===a&&(43===t.charCodeAt(pe)?(e=c,pe++):(e=a,0===ge&&we(M)),e===a&&(45===t.charCodeAt(pe)?(e=d,pe++):(e=a,0===ge&&we(U))))));return e}(),r!==a?(Le(),(n=ke())!==a?(fe=e,u=r,o=n,e=[Object.assign({type:"operator"},ze[u]),o]):(pe=e,e=a)):(pe=e,e=a),e}function Oe(){var e,r,n,u;return e=pe,(r=Se())!==a?(Le(),n=function(){var e;t.substr(pe,2)===g?(e=g,pe+=2):(e=a,0===ge&&we(R));e===a&&(t.substr(pe,2)===y?(e=y,pe+=2):(e=a,0===ge&&we(P)));return e}(),n!==a?(Le(),(u=Oe())!==a?(fe=e,e=function(e,t,r){var n;switch(t){case"||":n="or";break;case"&&":n="and"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(pe=e,e=a)):(pe=e,e=a)):(pe=e,e=a),e===a&&(e=Se()),e}function Se(){var e,r,n,u;return e=pe,(r=Me())!==a?(Le(),n=function(){var e;t.substr(pe,2)===p?(e=p,pe+=2):(e=a,0===ge&&we(O));e===a&&(t.substr(pe,2)===f?(e=f,pe+=2):(e=a,0===ge&&we(S)),e===a&&(t.substr(pe,2)===v?(e=v,pe+=2):(e=a,0===ge&&we(F)),e===a&&(60===t.charCodeAt(pe)?(e="<",pe++):(e=a,0===ge&&we(j)),e===a&&(62===t.charCodeAt(pe)?(e=">",pe++):(e=a,0===ge&&we(D)),e===a&&(t.substr(pe,2)===m?(e=m,pe+=2):(e=a,0===ge&&we(N)),e===a&&(61===t.charCodeAt(pe)?(e="=",pe++):(e=a,0===ge&&we(I)),e===a&&(t.substr(pe,2)===h?(e=h,pe+=2):(e=a,0===ge&&we(q)))))))));return e}(),n===a&&(n=function(){var e;38===t.charCodeAt(pe)?(e="&",pe++):(e=a,0===ge&&we(_));return e}()),n!==a?(Le(),(u=Se())!==a?(fe=e,e=function(e,t,r){var n;switch(t){case"<":n="lessThan";break;case"<=":n="lessThanOrEqual";break;case">":n="greaterThan";break;case">=":n="greaterThanOrEqual";break;case"==":case"=":n="equal";break;case"!=":case"<>":n="unequal";break;case"&":n="add"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(pe=e,e=a)):(pe=e,e=a)):(pe=e,e=a),e===a&&(e=Me()),e}function Fe(){var e,t,r;return e=pe,t=pe,ge++,r=function(){var e;(e=Re())===a&&(e=Pe());return e}(),ge--,r===a?t=void 0:(pe=t,t=a),t!==a?(r=function(){var e,t,r,n;if(e=pe,(t=je())!==a){for(r=[],n=De();n!==a;)r.push(n),n=De();fe=e,e={type:"identifier",name:t+r.join("")}}else pe=e,e=a;return e}(),r!==a?(fe=e,e=r):(pe=e,e=a)):(pe=e,e=a),e}function je(){var e;return 95===t.charCodeAt(pe)?(e="_",pe++):(e=a,0===ge&&we(Y)),e===a&&(36===t.charCodeAt(pe)?(e="$",pe++):(e=a,0===ge&&we(z)),e===a&&(b.test(t.charAt(pe))?(e=t.charAt(pe),pe++):(e=a,0===ge&&we(L)))),e}function De(){var e;return(e=je())===a&&(46===t.charCodeAt(pe)?(e=".",pe++):(e=a,0===ge&&we(Q)),e===a&&(e=qe())),e}function Ne(){var e;return(e=function(){var e,t,r;if(e=pe,We()!==a){for(t=[],(r=_e())===a&&(r=Ze());r!==a;)t.push(r),(r=_e())===a&&(r=Ze());(r=We())!==a?(fe=e,e=Qe(t)):(pe=e,e=a)}else pe=e,e=a;if(e===a)if(e=pe,Ze()!==a){for(t=[],(r=_e())===a&&(r=We());r!==a;)t.push(r),(r=_e())===a&&(r=We());(r=Ze())!==a?(fe=e,e=function(e){return Qe(e)}(t)):(pe=e,e=a)}else pe=e,e=a;return e}())===a&&(e=function(){var e,r,n,u,o,i;e=pe,r=pe,n=Le(),43===t.charCodeAt(pe)?(u=c,pe++):(u=a,0===ge&&we(M));u!==a?r=n=[n,u]:(pe=r,r=a);r===a&&(r=pe,45===t.charCodeAt(pe)?(n=d,pe++):(n=a,0===ge&&we(U)),n!==a?r=n=[n,u=Le()]:(pe=r,r=a));r===a&&(r=null);if((n=Ie())!==a)if(46===t.charCodeAt(pe)?(u=".",pe++):(u=a,0===ge&&we(Q)),u!==a){for(o=[],i=qe();i!==a;)o.push(i),i=qe();fe=e,l=ye().replace(/[\+\-]/g,"").split("."),e={type:"literal",value:parseFloat(ye()),dataType:"number",options:{length:l[0].length,scale:l[1].length}}}else pe=e,e=a;else pe=e,e=a;var l;e===a&&(e=pe,r=pe,n=Le(),43===t.charCodeAt(pe)?(u=c,pe++):(u=a,0===ge&&we(M)),u!==a?r=n=[n,u]:(pe=r,r=a),r===a&&(r=pe,45===t.charCodeAt(pe)?(n=d,pe++):(n=a,0===ge&&we(U)),n!==a?r=n=[n,u=Le()]:(pe=r,r=a)),r===a&&(r=null),(n=Ie())!==a?(fe=e,e={type:"literal",value:parseInt(ye()),dataType:"number",options:{length:ye().replace(/[\+\-]/g,"").length,scale:0}}):(pe=e,e=a));return e}())===a&&(e=Re())===a&&(e=Pe()),e}function Ie(){var e,r,n,u;if(48===t.charCodeAt(pe)?(e="0",pe++):(e=a,0===ge&&we(X)),e===a)if(e=pe,r=function(){var e;T.test(t.charAt(pe))?(e=t.charAt(pe),pe++):(e=a,0===ge&&we(H));return e}(),r!==a){for(n=[],u=qe();u!==a;)n.push(u),u=qe();e=r=[r,n]}else pe=e,e=a;return e}function qe(){var e;return x.test(t.charAt(pe))?(e=t.charAt(pe),pe++):(e=a,0===ge&&we(B)),e}function Re(){var e,r;return e=pe,"true"===t.substr(pe,4).toLowerCase()?(r=t.substr(pe,4),pe+=4):(r=a,0===ge&&we(V)),r!==a&&(fe=e,r={type:"literal",value:!0,dataType:"checkbox",options:{}}),(e=r)===a&&(e=pe,"false"===t.substr(pe,5).toLowerCase()?(r=t.substr(pe,5),pe+=5):(r=a,0===ge&&we(G)),r!==a&&(fe=e,r={type:"literal",value:!1,dataType:"checkbox",options:{}}),e=r),e}function Pe(){var e,r;return e=pe,"null"===t.substr(pe,4).toLowerCase()?(r=t.substr(pe,4),pe+=4):(r=a,0===ge&&we(K)),r!==a&&(fe=e,r={type:"literal",value:null,dataType:"null",options:{}}),e=r}function _e(){var e,r,n;return e=pe,r=pe,ge++,n=function(){var e;(e=We())===a&&(e=Ze());return e}(),n===a&&(92===t.charCodeAt(pe)?(n="\\",pe++):(n=a,0===ge&&we(J))),ge--,n===a?r=void 0:(pe=r,r=a),r!==a?(n=function(){var e;t.length>pe?(e=t.charAt(pe),pe++):(e=a,0===ge&&we(re));return e}(),n!==a?(fe=e,e=ye()):(pe=e,e=a)):(pe=e,e=a),e}function We(){var e;return 39===t.charCodeAt(pe)?(e="'",pe++):(e=a,0===ge&&we(ee)),e}function Ze(){var e;return 34===t.charCodeAt(pe)?(e='"',pe++):(e=a,0===ge&&we(te)),e}function Le(){var e,t;for(e=[],t=Ye();t!==a;)e.push(t),t=Ye();return e}function Ye(){var e;return 9===t.charCodeAt(pe)?(e="\t",pe++):(e=a,0===ge&&we(ae)),e===a&&(e=function(){var e;return $.test(t.charAt(pe))?(e=t.charAt(pe),pe++):(e=a,0===ge&&we(ne)),e}())===a&&(11===t.charCodeAt(pe)?(e="\v",pe++):(e=a,0===ge&&we(ue)),e===a&&(12===t.charCodeAt(pe)?(e="\f",pe++):(e=a,0===ge&&we(oe)),e===a&&(32===t.charCodeAt(pe)?(e=" ",pe++):(e=a,0===ge&&we(ie)),e===a&&(160===t.charCodeAt(pe)?(e=" ",pe++):(e=a,0===ge&&we(le)),e===a&&(8203===t.charCodeAt(pe)?(e="",pe++):(e=a,0===ge&&we(se)),e===a&&(65279===t.charCodeAt(pe)?(e="\ufeff",pe++):(e=a,0===ge&&we(ce)))))))),e}const ze={"^":{functionName:"exponentiate",rightAssociative:!0,precedence:4},"*":{functionName:"multiply",rightAssociative:!1,precedence:3},"/":{functionName:"divide",rightAssociative:!1,precedence:3},"+":{functionName:"add",rightAssociative:!1,precedence:2},"-":{functionName:"subtract",rightAssociative:!1,precedence:2}};function Qe(e){return{type:"literal",value:e.join(""),dataType:"text",options:{length:e.length}}}function Xe(e,t,r){return{type:"callExpression",id:e.functionName,arguments:[t,r]}}if((n=i())!==a&&pe===t.length)return n;throw n!==a&&pe<t.length&&we({type:"end"}),Be=he,He=me<t.length?t.charAt(me):null,Ve=me<t.length?$e(me,me+1):$e(me,me),new e(e.buildMessage(Be,He),Be,He,Ve);var Be,He,Ve}}}(),u=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a,u,o,i={},l=(r=void 0!==r?r:{}).grammarSource,s={Time:E},c=E,d=/^[0-9]/,p=w(":",!1),f=w(".",!1),v={type:"class",parts:[["0","9"]],inverted:!1,ignoreCase:!1},m=function(e,t,r,n){return function(e,t,r,n){e>23&&$("hour part needs to be under 24");t>59&&$("minute part needs to be under 60");r>59&&$("second part needs to be under 60");n>999&&$("millisecond part needs to be under 1000")}(e,t,r,n),{type:"literal",value:new Date(n+1e3*r+60*t*1e3+60*e*60*1e3),dataType:"time",options:{}}},h=0,g=0,y=[{line:1,column:1}],b=0,x=[];if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');c=s[r.startRule]}function T(){return t.substring(g,h)}function $(t,r){throw function(t,r){return new e(t,null,null,r)}(t,r=void 0!==r?r:A(g,h))}function w(e,t){return{type:"literal",text:e,ignoreCase:t}}function C(e){var r,n=y[e];if(n)return n;for(r=e-1;!y[r];)r--;for(n={line:(n=y[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return y[e]=n,n}function A(e,t){var r=C(e),n=C(t);return{source:l,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function k(e){h<b||(h>b&&(b=h,x=[]),x.push(e))}function E(){var e,r,n,a,u,o,l,s;return e=h,r=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),r!==i?(58===t.charCodeAt(h)?(n=":",h++):(n=i,k(p)),n!==i?(a=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),a!==i?(58===t.charCodeAt(h)?(u=":",h++):(u=i,k(p)),u!==i?(o=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),o!==i?(46===t.charCodeAt(h)?(l=".",h++):(l=i,k(f)),l!==i?(s=function(){var e;e=h,M()!==i&&M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),s!==i?(g=e,e=m(r,a,o,s)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i),e}function M(){var e;return d.test(t.charAt(h))?(e=t.charAt(h),h++):(e=i,k(v)),e}if((n=c())!==i&&h===t.length)return n;throw n!==i&&h<t.length&&k({type:"end"}),a=x,u=b<t.length?t.charAt(b):null,o=b<t.length?A(b,b+1):A(b,b),new e(e.buildMessage(a,u),a,u,o)}}}();class o extends Error{constructor(e,t,r){super(e),this.errorType=t,this.options=r}}const i=864e5,l=(e,t)=>{if(e<0)return-1*l(-1*e,t);const r=10**t;return Math.round(e*r)/r},s=e=>{const t=e.toString().replace("-","");if(-1!==t.indexOf(".")){const e=t.split(".");return{length:e[0].length,scale:e[1].length}}return{length:t.length,scale:0}},c=(e,t,r)=>{switch(e){case"number":return l(t,r.scale);case"text":return t.substring(0,r.length);default:return t}},d=e=>{const t={type:"literal",value:e};if(null==e)return Object.assign(t,{value:null,dataType:"null",options:{}});const r=typeof e;switch(typeof e){case"number":return Object.assign(t,{dataType:"number",options:s(e)});case"string":return Object.assign(t,{dataType:"text",options:{length:e.length}});case"boolean":return Object.assign(t,{dataType:"checkbox",options:{}});default:throw new TypeError(`Unsupported type '${r}'`)}},p=(e,t,r)=>({type:"error",errorType:e,message:t,...r}),f=(e,t,r)=>e instanceof Date?f(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()):{type:"literal",dataType:"date",value:new Date(Date.UTC(e,t-1,r)),options:{}},v=e=>({type:"literal",dataType:"datetime",value:new Date(e),options:{}}),m=e=>({type:"literal",dataType:"time",value:new Date(e),options:{}}),h=e=>{try{return e()}catch(e){if(e instanceof o)return p(e.errorType,e.message,e.options);throw e}},g=(e,t)=>new Date(e.getTime()+t*i),y=e=>{if(!e.value&&"null"!==e.dataType&&0!==e.value&&!1!==e.value&&""!==e.value)return"";switch(e.dataType){case"null":return"NULL";case"number":return e.value.toString();case"text":case"picklist":return`"${e.value}"`;case"multipicklist":return`[${e.value.map((e=>`"${e}"`)).join(", ")}]`;case"checkbox":return e.value.toString().toUpperCase();case"date":return`${e.value.getUTCFullYear()}-${(e.value.getUTCMonth()+1).toString().padStart(2,"0")}-${e.value.getUTCDate().toString().padStart(2,"0")}`;case"datetime":return e.value.toISOString();case"time":return e.value.toISOString().split("T")[1].replace("Z","");case"geolocation":return t=e.value[0],r=e.value[1],t&&r||0===t||0===r?`${t.toFixed(6)}, ${r.toFixed(6)}`:"";default:return}var t,r};class b extends o{constructor(e,t){super(e,"NotImplementedError",t)}static throwError(e){throw new b(`Function ${e} not implemented yet.`,{name:e})}}const x=e=>Array.isArray(e)?e.map((e=>x(e))).join(", "):"string"!=typeof e?"":e.charAt(0).toUpperCase()+e.slice(1);class T extends o{constructor(e,t){super(e,"ArgumentError",t)}static throwWrongType(e,t,r){const n={function:e,expected:t,received:r},a=r||"Non-Salesforce";throw new T(`Incorrect parameter type for function '${e.toUpperCase()}()'. Expected ${x(t)}, received ${x(a)}`,n)}static throwIncorrectNumberOfArguments(e,t,r){const n={function:e,expected:t,received:r};throw new T(`Incorrect number of parameters for function '${e.toUpperCase()}()'. Expected ${t}, received ${r}`,n)}}const $=(e,t)=>{switch(e.dataType){case"date":case"datetime":return d(e.value.getTime()===t.value.getTime());default:return d(e.value===t.value)}},w=(e,t,r)=>d(e.value.substr(t.value-1,r.value)),C=(e,t)=>w(e,d(1),t);var A=Object.freeze({__proto__:null,sf$or:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e||t));return d(t)},sf$equal:$,sf$unequal:(e,t)=>d(!$(e,t).value),sf$greaterThan:(e,t)=>d(e.value>t.value),sf$greaterThanOrEqual:(e,t)=>d(e.value>=t.value),sf$lessThan:(e,t)=>d(e.value<t.value),sf$lessThanOrEqual:(e,t)=>d(e.value<=t.value),sf$addmonths:(e,t)=>f(((e,t)=>{const r=e.getUTCMonth()+t,n=new Date(Date.UTC(e.getUTCFullYear(),r,e.getUTCDate()));return e.getUTCDate()!==n.getUTCDate()&&n.setUTCDate(0),n})(e.value,t.value)),sf$date:(e,t,r)=>f(e.value,t.value,r.value),sf$datevalue:e=>f(new Date(Date.parse(e.value))),sf$datetimevalue:e=>v(Date.parse(`${e.value}Z`)),sf$day:e=>d(e.value.getUTCDate()),sf$hour:e=>d(e.value.getUTCHours()),sf$millisecond:e=>d(e.value.getUTCMilliseconds()),sf$minute:e=>d(e.value.getUTCMinutes()),sf$month:e=>d(e.value.getUTCMonth()+1),sf$now:()=>v((new Date).getTime()),sf$second:e=>d(e.value.getUTCSeconds()),sf$timenow:()=>m((new Date).getTime()%864e5),sf$timevalue:e=>(e=>{try{return u.parse(e)}catch(e){if(e instanceof u.SyntaxError)return d(null);throw e}})(e.value),sf$today:()=>f(new Date),sf$weekday:e=>d(e.value.getUTCDay()+1),sf$year:e=>d(e.value.getUTCFullYear()),sf$and:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e&&t));return d(t)},sf$blankvalue:(e,t)=>"null"===e.dataType||""===e.value?t:e,sf$case:(e,...t)=>{const r=t.length-1;if(r<=0){const e={function:"case",expected:4,received:r+2};throw new T(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}+, received ${e.received}`,e)}if(r%2!=0){const e={function:"case",expected:r+1,received:r+2};throw new T(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}, received ${e.received}`,e)}for(let n=0;n<r;n+=2)if($(t[n],e).value)return t[n+1];return t[r]},sf$if:(e,t,r)=>e.value?t:r,sf$isblank:e=>d("null"===e.dataType||""===e.value),sf$isnull:e=>{b.throwError("isnull")},sf$isnumber:e=>{b.throwError("isnumber")},sf$not:e=>d(!e.value),sf$nullvalue:(e,t)=>{b.throwError("nullvalue")},sf$add:(e,t)=>{switch([e.dataType,t.dataType].join(" ")){case"date number":return f(g(e.value,t.value));case"number date":return f(g(t.value,e.value));case"time number":return m(e.value.getTime()+t.value);case"number time":return m(e.value+t.value.getTime());case"datetime number":return v(g(e.value,t.value));case"number datetime":return v(g(t.value,e.value));case"number number":return d(new n.default(e.value).plus(new n.default(t.value)).toNumber());case"text text":return d(e.value+t.value);default:T.throwWrongType("add","number",t.dataType)}},sf$subtract:(e,t)=>{switch([e.dataType,t.dataType].join(" ")){case"date number":return f(g(e.value,-1*t.value));case"time number":return m(e.value.getTime()+-1*t.value);case"datetime number":return v(g(e.value,-1*t.value));case"date date":case"datetime datetime":return d((r=e.value,a=t.value,(r.getTime()-a.getTime())/i));case"time time":return d(e.value.getTime()-t.value.getTime());case"number number":return d(new n.default(e.value).minus(new n.default(t.value)).toNumber());case"text text":return d(e.value-t.value);default:T.throwWrongType("subtract","number",t.dataType)}var r,a},sf$multiply:(e,t)=>d(new n.default(e.value).times(new n.default(t.value)).toNumber()),sf$divide:(e,t)=>d(new n.default(e.value).dividedBy(new n.default(t.value)).toNumber()),sf$exponentiate:(e,t)=>d(new n.default(e.value).toPower(new n.default(t.value)).toNumber()),sf$abs:e=>d(Math.abs(e.value)),sf$ceiling:e=>e.value<0?d(-1*Math.ceil(-1*e.value)):d(Math.ceil(e.value)),sf$distance:(e,t,r)=>{const n=r.value;if("km"!==n&&"mi"!==n){throw new T(`Incorrect parameter value for function 'DISTANCE()'. Expected 'mi'/'km', received '${n}'`,{function:"distance",expected:["km","mi"],received:n})}const[a,u]=e.value,[o,i]=t.value;if(a===o&&u===i)return d(0);const l=a*Math.PI/180,s=o*Math.PI/180,c=(o-a)*Math.PI/180,p=(i-u)*Math.PI/180,f=Math.sin(c/2)*Math.sin(c/2)+Math.cos(l)*Math.cos(s)*Math.sin(p/2)*Math.sin(p/2),v=6371009*(2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f)))/1e3;return d("mi"===n?v/1.609344:v)},sf$exp:e=>d(Math.exp(e.value)),sf$floor:e=>e.value<0?d(-1*Math.floor(-1*e.value)):d(Math.floor(e.value)),sf$geolocation:(e,t)=>((e,t)=>({type:"literal",dataType:"geolocation",value:[e,t],options:{}}))(e.value,t.value),sf$ln:e=>d(Math.log(e.value)),sf$log:e=>d(Math.log10(e.value)),sf$max:(...e)=>{const t=e.map((e=>e.value));return d(Math.max(...t))},sf$mceiling:e=>d(Math.ceil(e.value)),sf$mfloor:e=>d(Math.floor(e.value)),sf$min:(...e)=>{const t=e.map((e=>e.value));return d(Math.min(...t))},sf$mod:(e,t)=>d(e.value%t.value),sf$round:(e,t)=>d(l(e.value,t.value)),sf$sqrt:e=>d(Math.sqrt(e.value)),sf$begins:(e,t)=>d(e.value.startsWith(t.value)),sf$br:()=>d("\n"),sf$casesafeid:e=>{let t="";return[0,1,2].forEach((r=>{let n=0;[0,1,2,3,4].forEach((t=>{const a=e.value[5*r+t];a.toUpperCase()===a&&a>="A"&&a<="Z"&&(n+=1<<t)})),t+="ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[n]})),d(e.value+t)},sf$concat:(e,t)=>d(e.value+t.value),sf$contains:(e,t)=>d(e.value.includes(t.value)),sf$find:(e,t,r=d(1))=>{if(r.value<=0||""===e.value)return d(0);const n=t.value.substring(r.value-1);return d(n.indexOf(e.value)+1)},sf$getsessionid:()=>d("00D3z000001eRlg!AQMAQC3Y4aM9sFux6SRWhyFcOUKin4taGaBxNMU8TN_R_1R0Y7ArI95eSyzQZVIlrnV_unTbmwHZlXex8xhlXz2kXZNP49Fa"),sf$hyperlink:(e,t,r=null)=>{const n=r?` target="${r.value}"`:"";return d(`<a href="${e.value}"${n}>${t.value}</a>`)},sf$image:(e,t,r=null,n=null)=>{const a=r?` height="${r.value}"`:"",u=n?` width="${n.value}"`:"";return d(`<img src="${e.value}" alt="${t.value}"${a}${u}/>`)},sf$includes:(e,t)=>d(e.value.includes(t.value)),sf$ispickval:(e,t)=>d(e.value===t.value),sf$mid:w,sf$left:C,sf$len:e=>d(e.value.length),sf$lower:(e,t)=>d(e.value.toLowerCase()),sf$lpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return C(e,t);const n=r.value.repeat(t.value);return d((n+e.value).slice(-t.value))},sf$right:(e,t)=>d(e.value.substr(e.value.length-t.value)),sf$rpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return C(e,t);const n=r.value.repeat(t.value);return d((e.value+n).substr(0,t.value))},sf$substitute:(e,t,r)=>d(e.value.replace(new RegExp(t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),r.value)),sf$text:e=>"datetime"===e.dataType?d(y(e).replace("T"," ").replace(/\.\d{3}/,"")):"picklist"===e.dataType?d(e.value):d(y(e)),sf$trim:e=>d(e.value.trim()),sf$upper:(e,t)=>d(e.value.toUpperCase()),sf$value:e=>{const t=parseFloat(e.value);return d(t||null)},sf$currencyrate:e=>{b.throwError("currencyrate")},sf$regex:(e,t)=>{const r=new RegExp(`^${t.value}$`);return d(null!=r.exec(e.value))}});const k=e=>t=>r=>{r.length<e&&T.throwIncorrectNumberOfArguments(t,e,r.length)},E=e=>t=>r=>{r.length>e&&T.throwIncorrectNumberOfArguments(t,e,r.length)},M=(...e)=>t=>r=>{r.map(((t,r)=>[t.dataType,e[r]||e[e.length-1]])).forEach((([e,r])=>{"null"!==e&&(Array.isArray(r)?-1===r.indexOf(e)&&T.throwWrongType(t,r,e):e!==r&&T.throwWrongType(t,r,e))}))},U=()=>e=>t=>{const r=t.filter((e=>"null"!==e.dataType));r.length>0&&r.reduce(((t,r)=>(t.dataType!==r.dataType&&T.throwWrongType(e,t.dataType,r.dataType),r)))};class O extends o{constructor(e,t){super(e,"NoFunctionError",t)}}const S={abs:{validations:[k(1),E(1),M("number")],returnType:"number"},add:{validations:[k(2),E(2),M(["number","text","date","datetime","time"],["number","text","date","datetime","time"])],returnType:["number","text","date","datetime","time"]},addmonths:{validations:[k(2),E(2),M(["date","datetime"],["number"])],returnType:["date","datetime"]},and:{validations:[k(1),M("checkbox")],returnType:"checkbox"},begins:{validations:[k(2),E(2),M("text","text")],returnType:"checkbox"},blankvalue:{validations:[k(2),E(2),M(["text","number","date","datetime","geolocation"]),U()],returnType:["text","number"]},br:{validations:[k(0),E(0)],returnType:"text"},case:{validations:[k(4),M(["text","number","picklist","date","datetime"]),e=>t=>{const r="picklist"===t[0].dataType?"text":t[0].dataType,n=t.filter(((e,r)=>r%2==1&&r!==t.length-1)).find((e=>e.dataType!==r));n&&T.throwWrongType(e,r,n.dataType)}],returnType:["text","number","date","datetime"]},casesafeid:{validations:[k(1),E(1),M("text")],returnType:"text"},ceiling:{validations:[k(1),E(1),M("number")],returnType:"number"},contains:{validations:[k(2),E(2),M("text","text")],returnType:"checkbox"},currencyrate:{validations:[k(1),E(1),M("text")],returnType:"text"},date:{validations:[k(3),E(3),M("number","number","number")],returnType:"date"},datetimevalue:{validations:[k(1),E(1),M("text","date","datetime")],returnType:"datetime"},datevalue:{validations:[k(1),E(1),M(["text","date","datetime"])],returnType:"date"},day:{validations:[k(1),E(1),M("date")],returnType:"number"},distance:{validations:[k(3),E(3),M("geolocation","geolocation","text")],returnType:"number"},divide:{validations:[k(2),E(2),M("number","number")],returnType:"number"},equal:{validations:[k(2),E(2),M(["text","number","date","datetime","checkbox"]),U()],returnType:"checkbox"},exp:{validations:[k(1),E(1),M("number")],returnType:"number"},exponentiate:{validations:[k(2),E(2),M("number","number")],returnType:"number"},find:{validations:[k(2),E(3),M("text","text","number")],returnType:"number"},floor:{validations:[k(1),E(1),M("number")],returnType:"number"},geolocation:{validations:[k(2),E(2),M("number","number")],returnType:"geolocation"},getsessionid:{validations:[k(0),E(0)],returnType:"text"},greaterThan:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},greaterThanOrEqual:{validations:[k(2),E(2),M(["number","date","datetime"])],returnType:"checkbox"},hour:{validations:[k(1),E(1),M("datetime")],returnType:"number"},hyperlink:{validations:[k(2),E(3),M("text","text","text")],returnType:"text"},if:{validations:[k(3),E(3),M("checkbox",["text","number","date","datetime","checkbox","geolocation"],["text","number","date","datetime","checkbox","geolocation"])],returnType:["text","number","date","datetime","checkbox","geolocation"]},image:{validations:[k(2),E(4),M("text","text","number","number")],returnType:"text"},includes:{validations:[k(2),E(2),M("multipicklist","text")],returnType:"checkbox"},isblank:{validations:[k(1),E(1),M(["text","number","date","datetime","geolocation"])],returnType:"checkbox"},isnull:{validations:[k(1),E(1),M(["text","number"])],returnType:"checkbox"},ispickval:{validations:[k(2),E(2),M("picklist","text")],returnType:"checkbox"},isnumber:{validations:[k(1),E(1),M("text")],returnType:"checkbox"},left:{validations:[k(2),E(2),M("text","number")],returnType:"text"},len:{validations:[k(1),E(1),M("text")],returnType:"number"},lessThan:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},lessThanOrEqual:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},ln:{validations:[k(1),E(1),M("number")],returnType:"number"},log:{validations:[k(1),E(1),M("number")],returnType:"checkbox"},lower:{validations:[k(1),E(1),M("text")],returnType:"text"},lpad:{validations:[k(2),E(3),M("text","number","text")],returnType:"text"},max:{validations:[k(1),M("number")],returnType:"number"},mceiling:{validations:[k(1),E(1),M("number")],returnType:"number"},mfloor:{validations:[k(1),E(1),M("number")],returnType:"number"},mid:{validations:[k(3),E(3),M("text","number","number")],returnType:"number"},millisecond:{validations:[k(1),E(1),M("datetime")],returnType:"number"},min:{validations:[k(1),M("number")],returnType:"number"},minute:{validations:[k(1),E(1),M("datetime")],returnType:"number"},mod:{validations:[k(2),E(2),M("number","number")],returnType:"number"},month:{validations:[k(1),E(1),M("date")],returnType:"number"},multiply:{validations:[k(2),E(2),M("number","number")],returnType:"number"},not:{validations:[k(1),E(1),M("checkbox")],returnType:"checkbox"},now:{validations:[k(0),E(0)],returnType:"datetime"},nullvalue:{validations:[k(2),E(2),M(["text","number"],["text","number"])],returnType:["text","number"]},or:{validations:[k(1),M("checkbox")],returnType:"checkbox"},regex:{validations:[k(2),E(2),M("text","text")],returnType:"text"},right:{validations:[k(2),E(2),M("text","number")],returnType:"text"},round:{validations:[k(2),E(2),M("number","number")],returnType:"number"},rpad:{validations:[k(2),E(3),M("text","number","text")],returnType:"text"},second:{validations:[k(1),E(1),M("datetime")],returnType:"number"},sqrt:{validations:[k(1),E(1),M("number")],returnType:"number"},subtract:{validations:[k(2),E(2),M(["number","date","datetime","time"],["number","date","datetime","time"])],returnType:["number","date","datetime","time"]},substitute:{validations:[k(3),E(3),M("text","text","text")],returnType:"text"},text:{validations:[k(1),E(1),M(["number","date","datetime","picklist","time"])],returnType:"text"},timenow:{validations:[k(0),E(0)],returnType:"time"},timevalue:{validations:[k(1),E(1),M("text")],returnType:"time"},today:{validations:[k(0),E(0)],returnType:"date"},trim:{validations:[k(1),E(1),M("text")],returnType:"text"},unequal:{validations:[k(2),E(2),M(["text","number","date","datetime","checkbox"]),U()],returnType:"checkbox"},upper:{validations:[k(1),E(1),M("text")],returnType:"text"},value:{validations:[k(1),E(1),M("text")],returnType:"number"},weekday:{validations:[k(1),E(1),M("date")],returnType:"number"},year:{validations:[k(1),E(1),M("date")],returnType:"number"}};class F extends o{constructor(e,t){super(e,"ReferenceError",t)}}const j=e=>{switch(e.type){case"callExpression":return t=e.id,r=e.arguments.map((e=>j(e))),h((()=>{const e=r.find((e=>"error"===e.type));if(e)return e;const n=S[t];if(n)return n.validations.forEach((e=>e(t)(r))),A[`sf$${t}`](...r);throw new O(`Unknown function ${t.toUpperCase()}. Check spelling.`,{function:t})}));case"identifier":throw new F(`Field ${e.name} does not exist. Check spelling.`,{identifier:e.name});default:return e}var t,r},D=e=>{try{return a.parse(null==e?"":e.trim())}catch(e){if(e instanceof a.SyntaxError)return p("SyntaxError","Syntax error.",{});throw e}},N=(e,t=[])=>{switch(e.type){case"callExpression":return e.arguments.map((e=>N(e,t))).reduce(((e,t)=>e.concat(t)),[]);case"identifier":return t.concat(e.name);default:return t}},I=(e,t)=>"callExpression"===e.type?{type:"callExpression",id:e.id,arguments:e.arguments.map((e=>I(e,t)))}:"identifier"===e.type&&t[e.name]?{...t[e.name],type:"literal"}:e;e.ast=e=>null==e||""===e.trim()?{}:D(e),e.extract=e=>{if(null==e||""===e.trim())return[];const t=D(e);return N(t).reduce(((e,t)=>(e.indexOf(t)<0&&e.push(t),e)),[])},e.parse=(e,t={})=>{if(null==e||""===e.trim())return d("");const r=D(e),n=Object.keys(t).reduce(((e,r)=>{return{...e,[r]:(n=t[r],void 0===n.value||null===n.value||Number.isNaN(n.value)?{type:"literal",value:null,dataType:"null",options:{}}:{...n,value:c(n.dataType,n.value,n.options)})};var n}),{});return(e=>h((()=>j(e))))(I(r,n))},e.toString=e=>y(e),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("decimal.js")):"function"==typeof define&&define.amd?define(["exports","decimal.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).formulon={},e.Decimal)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t),a=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a={},u=(r=void 0!==r?r:{}).grammarSource,o={start:ke},i=ke,l="(",s=")",c="+",d="-",p="<=",f=">=",v="<>",m="==",h="!=",g="&&",y="||",b=/^[A-Za-z]/,x=/^[0-9]/,T=/^[1-9]/,$=/^[\n\r\u2028\u2029]/,w=Te("(",!1),C=Te(")",!1),A=Te("^",!1),k=Te("*",!1),E=Te("/",!1),M=Te("+",!1),U=Te("-",!1),O=Te("<=",!1),S=Te(">=",!1),F=Te("<>",!1),j=Te("<",!1),D=Te(">",!1),N=Te("==",!1),I=Te("=",!1),q=Te("!=",!1),R=Te("&&",!1),P=Te("||",!1),_=Te("&",!1),W=Te("!",!1),Z=Te(",",!1),L=$e([["A","Z"],["a","z"]],!1,!1),Y=Te("_",!1),z=Te("$",!1),Q=Te("[",!1),X=Te(".",!1),B=Te("]",!1),H=Te("0",!1),V=$e([["0","9"]],!1,!1),G=$e([["1","9"]],!1,!1),K=Te("true",!0),J=Te("false",!0),ee=Te("null",!0),te=Te("\\",!1),re=Te("'",!1),ne=Te('"',!1),ae={type:"any"},ue=$e(["\n","\r","\u2028","\u2029"],!1,!1),oe=Te("\t",!1),ie=Te("\v",!1),le=Te("\f",!1),se=Te(" ",!1),ce=Te(" ",!1),de=Te("",!1),pe=Te("\ufeff",!1),fe=function(e,t){return function(e){const t=[],r=[];e.forEach((e=>{if("operator"===e.type){for(;t.length>0&&!(t[t.length-1].precedence<e.precedence);){let e=t.pop(),n=r.pop(),a=r.pop();r.push(He(e,a,n))}t.push(e)}else r.push(e)}));for(;t.length>0;){let e=t.pop(),n=r.pop(),a=r.pop();r.push(He(e,a,n))}return r.pop()}([e,t].flat(2))},ve=0,me=0,he=[{line:1,column:1}],ge=0,ye=[],be=0;if("startRule"in r){if(!(r.startRule in o))throw new Error("Can't start parsing from rule \""+r.startRule+'".');i=o[r.startRule]}function xe(){return t.substring(me,ve)}function Te(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function we(e){var r,n=he[e];if(n)return n;for(r=e-1;!he[r];)r--;for(n={line:(n=he[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return he[e]=n,n}function Ce(e,t){var r=we(e),n=we(t);return{source:u,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function Ae(e){ve<ge||(ve>ge&&(ge=ve,ye=[]),ye.push(e))}function ke(){return Ee()}function Ee(){var e;return(e=Fe())===a&&(e=function(){var e,r,n;e=ve,r=function(){var e;33===t.charCodeAt(ve)?(e="!",ve++):(e=a,0===be&&Ae(W));return e}(),r!==a?(ze(),(n=Ee())!==a?(me=e,e={type:"callExpression",id:"not",arguments:[n]}):(ve=e,e=a)):(ve=e,e=a);return e}())===a&&(e=Ue())===a&&(e=De())===a&&(e=qe()),e}function Me(){var e,r,n,u;return(e=Ue())===a&&(e=De())===a&&(e=qe())===a&&(e=ve,40===t.charCodeAt(ve)?(r="(",ve++):(r=a,0===be&&Ae(w)),r!==a?(ze(),(n=Oe())!==a?(ze(),41===t.charCodeAt(ve)?(u=")",ve++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(ve=e,e=a)):(ve=e,e=a)):(ve=e,e=a),e===a&&(e=ve,40===t.charCodeAt(ve)?(r="(",ve++):(r=a,0===be&&Ae(w)),r!==a?(ze(),(n=Fe())!==a?(ze(),41===t.charCodeAt(ve)?(u=")",ve++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(ve=e,e=a)):(ve=e,e=a)):(ve=e,e=a))),e}function Ue(){var e,r,n,u;return e=ve,r=function(){var e,r,n;e=ve,r=[],b.test(t.charAt(ve))?(n=t.charAt(ve),ve++):(n=a,0===be&&Ae(L));if(n!==a)for(;n!==a;)r.push(n),b.test(t.charAt(ve))?(n=t.charAt(ve),ve++):(n=a,0===be&&Ae(L));else r=a;r!==a&&(me=e,r=r.join("").toLowerCase());return e=r}(),r!==a?(ze(),n=function(){var e,r,n,u;e=ve,40===t.charCodeAt(ve)?(r=l,ve++):(r=a,0===be&&Ae(w));r!==a?(ze(),n=ve,u=function(){var e,r,n,u;e=ve,r=[],n=ve,(u=Ee())!==a?(ze(),44===t.charCodeAt(ve)?ve++:0===be&&Ae(Z),ze(),me=n,n=u):(ve=n,n=a);if(n!==a)for(;n!==a;)r.push(n),n=ve,(u=Ee())!==a?(ze(),44===t.charCodeAt(ve)?ve++:0===be&&Ae(Z),ze(),me=n,n=u):(ve=n,n=a);else r=a;r!==a&&(me=e);return e=r}(),u!==a?n=u=[u,ze()]:(ve=n,n=a),n===a&&(n=null),41===t.charCodeAt(ve)?(u=s,ve++):(u=a,0===be&&Ae(C)),u!==a?(me=e,e=n):(ve=e,e=a)):(ve=e,e=a);return e}(),n!==a?(me=e,e={type:"callExpression",id:r,arguments:(u=n,null!==u?u[0]:[])}):(ve=e,e=a)):(ve=e,e=a),e}function Oe(){var e,t,r,n;if(e=ve,(t=Me())!==a){for(ze(),r=[],n=Se();n!==a;)r.push(n),n=Se();me=e,e=fe(t,r)}else ve=e,e=a;return e}function Se(){var e,r,n,u,o;return e=ve,ze(),r=function(){var e;94===t.charCodeAt(ve)?(e="^",ve++):(e=a,0===be&&Ae(A));e===a&&(42===t.charCodeAt(ve)?(e="*",ve++):(e=a,0===be&&Ae(k)),e===a&&(47===t.charCodeAt(ve)?(e="/",ve++):(e=a,0===be&&Ae(E)),e===a&&(43===t.charCodeAt(ve)?(e=c,ve++):(e=a,0===be&&Ae(M)),e===a&&(45===t.charCodeAt(ve)?(e=d,ve++):(e=a,0===be&&Ae(U))))));return e}(),r!==a?(ze(),(n=Me())!==a?(me=e,u=r,o=n,e=[Object.assign({type:"operator"},Xe[u]),o]):(ve=e,e=a)):(ve=e,e=a),e}function Fe(){var e,r,n,u;return e=ve,(r=je())!==a?(ze(),n=function(){var e;t.substr(ve,2)===g?(e=g,ve+=2):(e=a,0===be&&Ae(R));e===a&&(t.substr(ve,2)===y?(e=y,ve+=2):(e=a,0===be&&Ae(P)));return e}(),n!==a?(ze(),(u=Fe())!==a?(me=e,e=function(e,t,r){var n;switch(t){case"||":n="or";break;case"&&":n="and"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(ve=e,e=a)):(ve=e,e=a)):(ve=e,e=a),e===a&&(e=je()),e}function je(){var e,r,n,u;return e=ve,(r=Oe())!==a?(ze(),n=function(){var e;t.substr(ve,2)===p?(e=p,ve+=2):(e=a,0===be&&Ae(O));e===a&&(t.substr(ve,2)===f?(e=f,ve+=2):(e=a,0===be&&Ae(S)),e===a&&(t.substr(ve,2)===v?(e=v,ve+=2):(e=a,0===be&&Ae(F)),e===a&&(60===t.charCodeAt(ve)?(e="<",ve++):(e=a,0===be&&Ae(j)),e===a&&(62===t.charCodeAt(ve)?(e=">",ve++):(e=a,0===be&&Ae(D)),e===a&&(t.substr(ve,2)===m?(e=m,ve+=2):(e=a,0===be&&Ae(N)),e===a&&(61===t.charCodeAt(ve)?(e="=",ve++):(e=a,0===be&&Ae(I)),e===a&&(t.substr(ve,2)===h?(e=h,ve+=2):(e=a,0===be&&Ae(q)))))))));return e}(),n===a&&(n=function(){var e;38===t.charCodeAt(ve)?(e="&",ve++):(e=a,0===be&&Ae(_));return e}()),n!==a?(ze(),(u=je())!==a?(me=e,e=function(e,t,r){var n;switch(t){case"<":n="lessThan";break;case"<=":n="lessThanOrEqual";break;case">":n="greaterThan";break;case">=":n="greaterThanOrEqual";break;case"==":case"=":n="equal";break;case"!=":case"<>":n="unequal";break;case"&":n="add"}return{type:"callExpression",id:n,arguments:[e,r]}}(r,n,u)):(ve=e,e=a)):(ve=e,e=a)):(ve=e,e=a),e===a&&(e=Oe()),e}function De(){var e,t,r;return e=ve,t=ve,be++,r=function(){var e;(e=_e())===a&&(e=We());return e}(),be--,r===a?t=void 0:(ve=t,t=a),t!==a?(r=function(){var e,t,r,n;if(e=ve,(t=Ne())!==a){for(r=[],n=Ie();n!==a;)r.push(n),n=Ie();me=e,e={type:"identifier",name:t+r.join("")}}else ve=e,e=a;return e}(),r!==a?(me=e,e=r):(ve=e,e=a)):(ve=e,e=a),e}function Ne(){var e;return 95===t.charCodeAt(ve)?(e="_",ve++):(e=a,0===be&&Ae(Y)),e===a&&(36===t.charCodeAt(ve)?(e="$",ve++):(e=a,0===be&&Ae(z)),e===a&&(91===t.charCodeAt(ve)?(e="[",ve++):(e=a,0===be&&Ae(Q)),e===a&&(b.test(t.charAt(ve))?(e=t.charAt(ve),ve++):(e=a,0===be&&Ae(L))))),e}function Ie(){var e;return(e=Ne())===a&&(46===t.charCodeAt(ve)?(e=".",ve++):(e=a,0===be&&Ae(X)),e===a&&(93===t.charCodeAt(ve)?(e="]",ve++):(e=a,0===be&&Ae(B)),e===a&&(e=Pe()))),e}function qe(){var e;return(e=function(){var e,t,r;if(e=ve,Le()!==a){for(t=[],(r=Ze())===a&&(r=Ye());r!==a;)t.push(r),(r=Ze())===a&&(r=Ye());(r=Le())!==a?(me=e,e=Be(t)):(ve=e,e=a)}else ve=e,e=a;if(e===a)if(e=ve,Ye()!==a){for(t=[],(r=Ze())===a&&(r=Le());r!==a;)t.push(r),(r=Ze())===a&&(r=Le());(r=Ye())!==a?(me=e,e=function(e){return Be(e)}(t)):(ve=e,e=a)}else ve=e,e=a;return e}())===a&&(e=function(){var e,r,n,u,o,i;e=ve,r=ve,n=ze(),43===t.charCodeAt(ve)?(u=c,ve++):(u=a,0===be&&Ae(M));u!==a?r=n=[n,u]:(ve=r,r=a);r===a&&(r=ve,45===t.charCodeAt(ve)?(n=d,ve++):(n=a,0===be&&Ae(U)),n!==a?r=n=[n,u=ze()]:(ve=r,r=a));r===a&&(r=null);if((n=Re())!==a)if(46===t.charCodeAt(ve)?(u=".",ve++):(u=a,0===be&&Ae(X)),u!==a){for(o=[],i=Pe();i!==a;)o.push(i),i=Pe();me=e,l=xe().replace(/[\+\-]/g,"").split("."),e={type:"literal",value:parseFloat(xe()),dataType:"number",options:{length:l[0].length,scale:l[1].length}}}else ve=e,e=a;else ve=e,e=a;var l;e===a&&(e=ve,r=ve,n=ze(),43===t.charCodeAt(ve)?(u=c,ve++):(u=a,0===be&&Ae(M)),u!==a?r=n=[n,u]:(ve=r,r=a),r===a&&(r=ve,45===t.charCodeAt(ve)?(n=d,ve++):(n=a,0===be&&Ae(U)),n!==a?r=n=[n,u=ze()]:(ve=r,r=a)),r===a&&(r=null),(n=Re())!==a?(me=e,e={type:"literal",value:parseInt(xe()),dataType:"number",options:{length:xe().replace(/[\+\-]/g,"").length,scale:0}}):(ve=e,e=a));return e}())===a&&(e=_e())===a&&(e=We()),e}function Re(){var e,r,n,u;if(48===t.charCodeAt(ve)?(e="0",ve++):(e=a,0===be&&Ae(H)),e===a)if(e=ve,r=function(){var e;T.test(t.charAt(ve))?(e=t.charAt(ve),ve++):(e=a,0===be&&Ae(G));return e}(),r!==a){for(n=[],u=Pe();u!==a;)n.push(u),u=Pe();e=r=[r,n]}else ve=e,e=a;return e}function Pe(){var e;return x.test(t.charAt(ve))?(e=t.charAt(ve),ve++):(e=a,0===be&&Ae(V)),e}function _e(){var e,r;return e=ve,"true"===t.substr(ve,4).toLowerCase()?(r=t.substr(ve,4),ve+=4):(r=a,0===be&&Ae(K)),r!==a&&(me=e,r={type:"literal",value:!0,dataType:"checkbox",options:{}}),(e=r)===a&&(e=ve,"false"===t.substr(ve,5).toLowerCase()?(r=t.substr(ve,5),ve+=5):(r=a,0===be&&Ae(J)),r!==a&&(me=e,r={type:"literal",value:!1,dataType:"checkbox",options:{}}),e=r),e}function We(){var e,r;return e=ve,"null"===t.substr(ve,4).toLowerCase()?(r=t.substr(ve,4),ve+=4):(r=a,0===be&&Ae(ee)),r!==a&&(me=e,r={type:"literal",value:null,dataType:"null",options:{}}),e=r}function Ze(){var e,r,n;return e=ve,r=ve,be++,n=function(){var e;(e=Le())===a&&(e=Ye());return e}(),n===a&&(92===t.charCodeAt(ve)?(n="\\",ve++):(n=a,0===be&&Ae(te))),be--,n===a?r=void 0:(ve=r,r=a),r!==a?(n=function(){var e;t.length>ve?(e=t.charAt(ve),ve++):(e=a,0===be&&Ae(ae));return e}(),n!==a?(me=e,e=xe()):(ve=e,e=a)):(ve=e,e=a),e}function Le(){var e;return 39===t.charCodeAt(ve)?(e="'",ve++):(e=a,0===be&&Ae(re)),e}function Ye(){var e;return 34===t.charCodeAt(ve)?(e='"',ve++):(e=a,0===be&&Ae(ne)),e}function ze(){var e,t;for(e=[],t=Qe();t!==a;)e.push(t),t=Qe();return e}function Qe(){var e;return 9===t.charCodeAt(ve)?(e="\t",ve++):(e=a,0===be&&Ae(oe)),e===a&&(e=function(){var e;return $.test(t.charAt(ve))?(e=t.charAt(ve),ve++):(e=a,0===be&&Ae(ue)),e}())===a&&(11===t.charCodeAt(ve)?(e="\v",ve++):(e=a,0===be&&Ae(ie)),e===a&&(12===t.charCodeAt(ve)?(e="\f",ve++):(e=a,0===be&&Ae(le)),e===a&&(32===t.charCodeAt(ve)?(e=" ",ve++):(e=a,0===be&&Ae(se)),e===a&&(160===t.charCodeAt(ve)?(e=" ",ve++):(e=a,0===be&&Ae(ce)),e===a&&(8203===t.charCodeAt(ve)?(e="",ve++):(e=a,0===be&&Ae(de)),e===a&&(65279===t.charCodeAt(ve)?(e="\ufeff",ve++):(e=a,0===be&&Ae(pe)))))))),e}const Xe={"^":{functionName:"exponentiate",rightAssociative:!0,precedence:4},"*":{functionName:"multiply",rightAssociative:!1,precedence:3},"/":{functionName:"divide",rightAssociative:!1,precedence:3},"+":{functionName:"add",rightAssociative:!1,precedence:2},"-":{functionName:"subtract",rightAssociative:!1,precedence:2}};function Be(e){return{type:"literal",value:e.join(""),dataType:"text",options:{length:e.length}}}function He(e,t,r){return{type:"callExpression",id:e.functionName,arguments:[t,r]}}if((n=i())!==a&&ve===t.length)return n;throw n!==a&&ve<t.length&&Ae({type:"end"}),Ve=ye,Ge=ge<t.length?t.charAt(ge):null,Ke=ge<t.length?Ce(ge,ge+1):Ce(ge,ge),new e(e.buildMessage(Ve,Ge),Ve,Ge,Ke);var Ve,Ge,Ke}}}(),u=function(){function e(t,r,n,a){var u=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(u,e.prototype),u.expected=r,u.found=n,u.location=a,u.name="SyntaxError",u}function t(e,t,r){return r=r||" ",e.length>t?e:(t-=e.length,e+(r+=r.repeat(t)).slice(0,t))}return function(e,t){function r(){this.constructor=e}r.prototype=t.prototype,e.prototype=new r}(e,Error),e.prototype.format=function(e){var r="Error: "+this.message;if(this.location){var n,a=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){a=e[n].text.split(/\r\n|\n|\r/g);break}var u=this.location.start,o=this.location.source+":"+u.line+":"+u.column;if(a){var i=this.location.end,l=t("",u.line.toString().length," "),s=a[u.line-1],c=(u.line===i.line?i.column:s.length+1)-u.column||1;r+="\n --\x3e "+o+"\n"+l+" |\n"+u.line+" | "+s+"\n"+l+" | "+t("",u.column-1," ")+t("",c,"^")}else r+="\n at "+o}return r},e.buildMessage=function(e,t){var r={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?u(e[0])+"-"+u(e[1]):u(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+n(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+n(e)}))}function o(e){return r[e.type](e)}return"Expected "+function(e){var t,r,n=e.map(o);if(n.sort(),n.length>0){for(t=1,r=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(t)+" found."},{SyntaxError:e,parse:function(t,r){var n,a,u,o,i={},l=(r=void 0!==r?r:{}).grammarSource,s={Time:E},c=E,d=/^[0-9]/,p=w(":",!1),f=w(".",!1),v={type:"class",parts:[["0","9"]],inverted:!1,ignoreCase:!1},m=function(e,t,r,n){return function(e,t,r,n){e>23&&$("hour part needs to be under 24");t>59&&$("minute part needs to be under 60");r>59&&$("second part needs to be under 60");n>999&&$("millisecond part needs to be under 1000")}(e,t,r,n),{type:"literal",value:new Date(n+1e3*r+60*t*1e3+60*e*60*1e3),dataType:"time",options:{}}},h=0,g=0,y=[{line:1,column:1}],b=0,x=[];if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');c=s[r.startRule]}function T(){return t.substring(g,h)}function $(t,r){throw function(t,r){return new e(t,null,null,r)}(t,r=void 0!==r?r:A(g,h))}function w(e,t){return{type:"literal",text:e,ignoreCase:t}}function C(e){var r,n=y[e];if(n)return n;for(r=e-1;!y[r];)r--;for(n={line:(n=y[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return y[e]=n,n}function A(e,t){var r=C(e),n=C(t);return{source:l,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function k(e){h<b||(h>b&&(b=h,x=[]),x.push(e))}function E(){var e,r,n,a,u,o,l,s;return e=h,r=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),r!==i?(58===t.charCodeAt(h)?(n=":",h++):(n=i,k(p)),n!==i?(a=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),a!==i?(58===t.charCodeAt(h)?(u=":",h++):(u=i,k(p)),u!==i?(o=function(){var e;e=h,M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),o!==i?(46===t.charCodeAt(h)?(l=".",h++):(l=i,k(f)),l!==i?(s=function(){var e;e=h,M()!==i&&M()!==i&&M()!==i?(g=e,e=parseInt(T())):(h=e,e=i);return e}(),s!==i?(g=e,e=m(r,a,o,s)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i)):(h=e,e=i),e}function M(){var e;return d.test(t.charAt(h))?(e=t.charAt(h),h++):(e=i,k(v)),e}if((n=c())!==i&&h===t.length)return n;throw n!==i&&h<t.length&&k({type:"end"}),a=x,u=b<t.length?t.charAt(b):null,o=b<t.length?A(b,b+1):A(b,b),new e(e.buildMessage(a,u),a,u,o)}}}();class o extends Error{constructor(e,t,r){super(e),this.errorType=t,this.options=r}}const i=864e5,l=(e,t)=>{if(e<0)return-1*l(-1*e,t);const r=10**t;return Math.round(e*r)/r},s=e=>{const t=e.toString().replace("-","");if(-1!==t.indexOf(".")){const e=t.split(".");return{length:e[0].length,scale:e[1].length}}return{length:t.length,scale:0}},c=(e,t,r)=>{switch(e){case"number":return l(t,r.scale);case"text":return t.substring(0,r.length);default:return t}},d=e=>{const t={type:"literal",value:e};if(null==e)return Object.assign(t,{value:null,dataType:"null",options:{}});const r=typeof e;switch(typeof e){case"number":return Object.assign(t,{dataType:"number",options:s(e)});case"string":return Object.assign(t,{dataType:"text",options:{length:e.length}});case"boolean":return Object.assign(t,{dataType:"checkbox",options:{}});default:throw new TypeError(`Unsupported type '${r}'`)}},p=(e,t,r)=>({type:"error",errorType:e,message:t,...r}),f=(e,t,r)=>e instanceof Date?f(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()):{type:"literal",dataType:"date",value:new Date(Date.UTC(e,t-1,r)),options:{}},v=e=>({type:"literal",dataType:"datetime",value:new Date(e),options:{}}),m=e=>({type:"literal",dataType:"time",value:new Date(e),options:{}}),h=e=>{try{return e()}catch(e){if(e instanceof o)return p(e.errorType,e.message,e.options);throw e}},g=(e,t)=>new Date(e.getTime()+t*i),y=e=>{if(!e.value&&"null"!==e.dataType&&0!==e.value&&!1!==e.value&&""!==e.value)return"";switch(e.dataType){case"null":return"NULL";case"number":return e.value.toString();case"text":case"picklist":return`"${e.value}"`;case"multipicklist":return`[${e.value.map((e=>`"${e}"`)).join(", ")}]`;case"checkbox":return e.value.toString().toUpperCase();case"date":return`${e.value.getUTCFullYear()}-${(e.value.getUTCMonth()+1).toString().padStart(2,"0")}-${e.value.getUTCDate().toString().padStart(2,"0")}`;case"datetime":return e.value.toISOString();case"time":return e.value.toISOString().split("T")[1].replace("Z","");case"geolocation":return t=e.value[0],r=e.value[1],t&&r||0===t||0===r?`${t.toFixed(6)}, ${r.toFixed(6)}`:"";default:return}var t,r};class b extends o{constructor(e,t){super(e,"NotImplementedError",t)}static throwError(e){throw new b(`Function ${e} not implemented yet.`,{name:e})}}const x=e=>Array.isArray(e)?e.map((e=>x(e))).join(", "):"string"!=typeof e?"":e.charAt(0).toUpperCase()+e.slice(1);class T extends o{constructor(e,t){super(e,"ArgumentError",t)}static throwWrongType(e,t,r){const n={function:e,expected:t,received:r},a=r||"Non-Salesforce";throw new T(`Incorrect parameter type for function '${e.toUpperCase()}()'. Expected ${x(t)}, received ${x(a)}`,n)}static throwIncorrectNumberOfArguments(e,t,r){const n={function:e,expected:t,received:r};throw new T(`Incorrect number of parameters for function '${e.toUpperCase()}()'. Expected ${t}, received ${r}`,n)}}const $=(e,t)=>{switch(e.dataType){case"date":case"datetime":return d(e.value.getTime()===t.value.getTime());default:return d(e.value===t.value)}},w=(e,t,r)=>d(e.value.substr(t.value-1,r.value)),C=(e,t)=>w(e,d(1),t);var A=Object.freeze({__proto__:null,sf$or:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e||t));return d(t)},sf$equal:$,sf$unequal:(e,t)=>d(!$(e,t).value),sf$greaterThan:(e,t)=>d(e.value>t.value),sf$greaterThanOrEqual:(e,t)=>d(e.value>=t.value),sf$lessThan:(e,t)=>d(e.value<t.value),sf$lessThanOrEqual:(e,t)=>d(e.value<=t.value),sf$addmonths:(e,t)=>f(((e,t)=>{const r=e.getUTCMonth()+t,n=new Date(Date.UTC(e.getUTCFullYear(),r,e.getUTCDate()));return e.getUTCDate()!==n.getUTCDate()&&n.setUTCDate(0),n})(e.value,t.value)),sf$date:(e,t,r)=>f(e.value,t.value,r.value),sf$datevalue:e=>f(new Date(Date.parse(e.value))),sf$datetimevalue:e=>v(Date.parse(`${e.value}Z`)),sf$day:e=>d(e.value.getUTCDate()),sf$hour:e=>d(e.value.getUTCHours()),sf$millisecond:e=>d(e.value.getUTCMilliseconds()),sf$minute:e=>d(e.value.getUTCMinutes()),sf$month:e=>d(e.value.getUTCMonth()+1),sf$now:()=>v((new Date).getTime()),sf$second:e=>d(e.value.getUTCSeconds()),sf$timenow:()=>m((new Date).getTime()%864e5),sf$timevalue:e=>(e=>{try{return u.parse(e)}catch(e){if(e instanceof u.SyntaxError)return d(null);throw e}})(e.value),sf$today:()=>f(new Date),sf$weekday:e=>d(e.value.getUTCDay()+1),sf$year:e=>d(e.value.getUTCFullYear()),sf$and:(...e)=>{const t=e.map((e=>e.value)).reduce(((e,t)=>e&&t));return d(t)},sf$blankvalue:(e,t)=>"null"===e.dataType||""===e.value?t:e,sf$case:(e,...t)=>{const r=t.length-1;if(r<=0){const e={function:"case",expected:4,received:r+2};throw new T(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}+, received ${e.received}`,e)}if(r%2!=0){const e={function:"case",expected:r+1,received:r+2};throw new T(`Incorrect number of parameters for function '${e.function.toUpperCase()}()'. Expected ${e.expected}, received ${e.received}`,e)}for(let n=0;n<r;n+=2)if($(t[n],e).value)return t[n+1];return t[r]},sf$if:(e,t,r)=>e.value?t:r,sf$isblank:e=>d("null"===e.dataType||""===e.value),sf$isnull:e=>{b.throwError("isnull")},sf$isnumber:e=>{b.throwError("isnumber")},sf$not:e=>d(!e.value),sf$nullvalue:(e,t)=>{b.throwError("nullvalue")},sf$add:(e,t)=>{switch([e.dataType,t.dataType].join(" ")){case"date number":return f(g(e.value,t.value));case"number date":return f(g(t.value,e.value));case"time number":return m(e.value.getTime()+t.value);case"number time":return m(e.value+t.value.getTime());case"datetime number":return v(g(e.value,t.value));case"number datetime":return v(g(t.value,e.value));case"number number":return d(new n.default(e.value).plus(new n.default(t.value)).toNumber());case"text text":return d(e.value+t.value);default:T.throwWrongType("add","number",t.dataType)}},sf$subtract:(e,t)=>{switch([e.dataType,t.dataType].join(" ")){case"date number":return f(g(e.value,-1*t.value));case"time number":return m(e.value.getTime()+-1*t.value);case"datetime number":return v(g(e.value,-1*t.value));case"date date":case"datetime datetime":return d((r=e.value,a=t.value,(r.getTime()-a.getTime())/i));case"time time":return d(e.value.getTime()-t.value.getTime());case"number number":return d(new n.default(e.value).minus(new n.default(t.value)).toNumber());case"text text":return d(e.value-t.value);default:T.throwWrongType("subtract","number",t.dataType)}var r,a},sf$multiply:(e,t)=>d(new n.default(e.value).times(new n.default(t.value)).toNumber()),sf$divide:(e,t)=>d(new n.default(e.value).dividedBy(new n.default(t.value)).toNumber()),sf$exponentiate:(e,t)=>d(new n.default(e.value).toPower(new n.default(t.value)).toNumber()),sf$abs:e=>d(Math.abs(e.value)),sf$ceiling:e=>e.value<0?d(-1*Math.ceil(-1*e.value)):d(Math.ceil(e.value)),sf$distance:(e,t,r)=>{const n=r.value;if("km"!==n&&"mi"!==n){throw new T(`Incorrect parameter value for function 'DISTANCE()'. Expected 'mi'/'km', received '${n}'`,{function:"distance",expected:["km","mi"],received:n})}const[a,u]=e.value,[o,i]=t.value;if(a===o&&u===i)return d(0);const l=a*Math.PI/180,s=o*Math.PI/180,c=(o-a)*Math.PI/180,p=(i-u)*Math.PI/180,f=Math.sin(c/2)*Math.sin(c/2)+Math.cos(l)*Math.cos(s)*Math.sin(p/2)*Math.sin(p/2),v=6371009*(2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f)))/1e3;return d("mi"===n?v/1.609344:v)},sf$exp:e=>d(Math.exp(e.value)),sf$floor:e=>e.value<0?d(-1*Math.floor(-1*e.value)):d(Math.floor(e.value)),sf$geolocation:(e,t)=>((e,t)=>({type:"literal",dataType:"geolocation",value:[e,t],options:{}}))(e.value,t.value),sf$ln:e=>d(Math.log(e.value)),sf$log:e=>d(Math.log10(e.value)),sf$max:(...e)=>{const t=e.map((e=>e.value));return d(Math.max(...t))},sf$mceiling:e=>d(Math.ceil(e.value)),sf$mfloor:e=>d(Math.floor(e.value)),sf$min:(...e)=>{const t=e.map((e=>e.value));return d(Math.min(...t))},sf$mod:(e,t)=>d(e.value%t.value),sf$round:(e,t)=>d(l(e.value,t.value)),sf$sqrt:e=>d(Math.sqrt(e.value)),sf$begins:(e,t)=>d(e.value.startsWith(t.value)),sf$br:()=>d("\n"),sf$casesafeid:e=>{let t="";return[0,1,2].forEach((r=>{let n=0;[0,1,2,3,4].forEach((t=>{const a=e.value[5*r+t];a.toUpperCase()===a&&a>="A"&&a<="Z"&&(n+=1<<t)})),t+="ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[n]})),d(e.value+t)},sf$concat:(e,t)=>d(e.value+t.value),sf$contains:(e,t)=>d(e.value.includes(t.value)),sf$find:(e,t,r=d(1))=>{if(r.value<=0||""===e.value)return d(0);const n=t.value.substring(r.value-1);return d(n.indexOf(e.value)+1)},sf$getsessionid:()=>d("00D3z000001eRlg!AQMAQC3Y4aM9sFux6SRWhyFcOUKin4taGaBxNMU8TN_R_1R0Y7ArI95eSyzQZVIlrnV_unTbmwHZlXex8xhlXz2kXZNP49Fa"),sf$hyperlink:(e,t,r=null)=>{const n=r?` target="${r.value}"`:"";return d(`<a href="${e.value}"${n}>${t.value}</a>`)},sf$image:(e,t,r=null,n=null)=>{const a=r?` height="${r.value}"`:"",u=n?` width="${n.value}"`:"";return d(`<img src="${e.value}" alt="${t.value}"${a}${u}/>`)},sf$includes:(e,t)=>d(e.value.includes(t.value)),sf$ispickval:(e,t)=>d(e.value===t.value),sf$mid:w,sf$left:C,sf$len:e=>d(e.value.length),sf$lower:(e,t)=>d(e.value.toLowerCase()),sf$lpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return C(e,t);const n=r.value.repeat(t.value);return d((n+e.value).slice(-t.value))},sf$right:(e,t)=>d(e.value.substr(e.value.length-t.value)),sf$rpad:(e,t,r)=>{if(null==r)return e;if(t.value<e.value.length)return C(e,t);const n=r.value.repeat(t.value);return d((e.value+n).substr(0,t.value))},sf$substitute:(e,t,r)=>d(e.value.replace(new RegExp(t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),r.value)),sf$text:e=>"datetime"===e.dataType?d(y(e).replace("T"," ").replace(/\.\d{3}/,"")):"picklist"===e.dataType?d(e.value):d(y(e)),sf$trim:e=>d(e.value.trim()),sf$upper:(e,t)=>d(e.value.toUpperCase()),sf$value:e=>{const t=parseFloat(e.value);return d(t||null)},sf$currencyrate:e=>{b.throwError("currencyrate")},sf$regex:(e,t)=>{const r=new RegExp(`^${t.value}$`);return d(null!=r.exec(e.value))}});const k=e=>t=>r=>{r.length<e&&T.throwIncorrectNumberOfArguments(t,e,r.length)},E=e=>t=>r=>{r.length>e&&T.throwIncorrectNumberOfArguments(t,e,r.length)},M=(...e)=>t=>r=>{r.map(((t,r)=>[t.dataType,e[r]||e[e.length-1]])).forEach((([e,r])=>{"null"!==e&&(Array.isArray(r)?-1===r.indexOf(e)&&T.throwWrongType(t,r,e):e!==r&&T.throwWrongType(t,r,e))}))},U=()=>e=>t=>{const r=t.filter((e=>"null"!==e.dataType));r.length>0&&r.reduce(((t,r)=>(t.dataType!==r.dataType&&T.throwWrongType(e,t.dataType,r.dataType),r)))};class O extends o{constructor(e,t){super(e,"NoFunctionError",t)}}const S={abs:{validations:[k(1),E(1),M("number")],returnType:"number"},add:{validations:[k(2),E(2),M(["number","text","date","datetime","time"],["number","text","date","datetime","time"])],returnType:["number","text","date","datetime","time"]},addmonths:{validations:[k(2),E(2),M(["date","datetime"],["number"])],returnType:["date","datetime"]},and:{validations:[k(1),M("checkbox")],returnType:"checkbox"},begins:{validations:[k(2),E(2),M("text","text")],returnType:"checkbox"},blankvalue:{validations:[k(2),E(2),M(["text","number","date","datetime","geolocation"]),U()],returnType:["text","number"]},br:{validations:[k(0),E(0)],returnType:"text"},case:{validations:[k(4),M(["text","number","picklist","date","datetime"]),e=>t=>{const r="picklist"===t[0].dataType?"text":t[0].dataType,n=t.filter(((e,r)=>r%2==1&&r!==t.length-1)).find((e=>e.dataType!==r));n&&T.throwWrongType(e,r,n.dataType)}],returnType:["text","number","date","datetime"]},casesafeid:{validations:[k(1),E(1),M("text")],returnType:"text"},ceiling:{validations:[k(1),E(1),M("number")],returnType:"number"},contains:{validations:[k(2),E(2),M("text","text")],returnType:"checkbox"},currencyrate:{validations:[k(1),E(1),M("text")],returnType:"text"},date:{validations:[k(3),E(3),M("number","number","number")],returnType:"date"},datetimevalue:{validations:[k(1),E(1),M("text","date","datetime")],returnType:"datetime"},datevalue:{validations:[k(1),E(1),M(["text","date","datetime"])],returnType:"date"},day:{validations:[k(1),E(1),M("date")],returnType:"number"},distance:{validations:[k(3),E(3),M("geolocation","geolocation","text")],returnType:"number"},divide:{validations:[k(2),E(2),M("number","number")],returnType:"number"},equal:{validations:[k(2),E(2),M(["text","number","date","datetime","checkbox"]),U()],returnType:"checkbox"},exp:{validations:[k(1),E(1),M("number")],returnType:"number"},exponentiate:{validations:[k(2),E(2),M("number","number")],returnType:"number"},find:{validations:[k(2),E(3),M("text","text","number")],returnType:"number"},floor:{validations:[k(1),E(1),M("number")],returnType:"number"},geolocation:{validations:[k(2),E(2),M("number","number")],returnType:"geolocation"},getsessionid:{validations:[k(0),E(0)],returnType:"text"},greaterThan:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},greaterThanOrEqual:{validations:[k(2),E(2),M(["number","date","datetime"])],returnType:"checkbox"},hour:{validations:[k(1),E(1),M("datetime")],returnType:"number"},hyperlink:{validations:[k(2),E(3),M("text","text","text")],returnType:"text"},if:{validations:[k(3),E(3),M("checkbox",["text","number","date","datetime","checkbox","geolocation"],["text","number","date","datetime","checkbox","geolocation"])],returnType:["text","number","date","datetime","checkbox","geolocation"]},image:{validations:[k(2),E(4),M("text","text","number","number")],returnType:"text"},includes:{validations:[k(2),E(2),M("multipicklist","text")],returnType:"checkbox"},isblank:{validations:[k(1),E(1),M(["text","number","date","datetime","geolocation"])],returnType:"checkbox"},isnull:{validations:[k(1),E(1),M(["text","number"])],returnType:"checkbox"},ispickval:{validations:[k(2),E(2),M("picklist","text")],returnType:"checkbox"},isnumber:{validations:[k(1),E(1),M("text")],returnType:"checkbox"},left:{validations:[k(2),E(2),M("text","number")],returnType:"text"},len:{validations:[k(1),E(1),M("text")],returnType:"number"},lessThan:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},lessThanOrEqual:{validations:[k(2),E(2),M(["number","date","datetime"]),U()],returnType:"checkbox"},ln:{validations:[k(1),E(1),M("number")],returnType:"number"},log:{validations:[k(1),E(1),M("number")],returnType:"checkbox"},lower:{validations:[k(1),E(1),M("text")],returnType:"text"},lpad:{validations:[k(2),E(3),M("text","number","text")],returnType:"text"},max:{validations:[k(1),M("number")],returnType:"number"},mceiling:{validations:[k(1),E(1),M("number")],returnType:"number"},mfloor:{validations:[k(1),E(1),M("number")],returnType:"number"},mid:{validations:[k(3),E(3),M("text","number","number")],returnType:"number"},millisecond:{validations:[k(1),E(1),M("datetime")],returnType:"number"},min:{validations:[k(1),M("number")],returnType:"number"},minute:{validations:[k(1),E(1),M("datetime")],returnType:"number"},mod:{validations:[k(2),E(2),M("number","number")],returnType:"number"},month:{validations:[k(1),E(1),M("date")],returnType:"number"},multiply:{validations:[k(2),E(2),M("number","number")],returnType:"number"},not:{validations:[k(1),E(1),M("checkbox")],returnType:"checkbox"},now:{validations:[k(0),E(0)],returnType:"datetime"},nullvalue:{validations:[k(2),E(2),M(["text","number"],["text","number"])],returnType:["text","number"]},or:{validations:[k(1),M("checkbox")],returnType:"checkbox"},regex:{validations:[k(2),E(2),M("text","text")],returnType:"text"},right:{validations:[k(2),E(2),M("text","number")],returnType:"text"},round:{validations:[k(2),E(2),M("number","number")],returnType:"number"},rpad:{validations:[k(2),E(3),M("text","number","text")],returnType:"text"},second:{validations:[k(1),E(1),M("datetime")],returnType:"number"},sqrt:{validations:[k(1),E(1),M("number")],returnType:"number"},subtract:{validations:[k(2),E(2),M(["number","date","datetime","time"],["number","date","datetime","time"])],returnType:["number","date","datetime","time"]},substitute:{validations:[k(3),E(3),M("text","text","text")],returnType:"text"},text:{validations:[k(1),E(1),M(["number","date","datetime","picklist","time"])],returnType:"text"},timenow:{validations:[k(0),E(0)],returnType:"time"},timevalue:{validations:[k(1),E(1),M("text")],returnType:"time"},today:{validations:[k(0),E(0)],returnType:"date"},trim:{validations:[k(1),E(1),M("text")],returnType:"text"},unequal:{validations:[k(2),E(2),M(["text","number","date","datetime","checkbox"]),U()],returnType:"checkbox"},upper:{validations:[k(1),E(1),M("text")],returnType:"text"},value:{validations:[k(1),E(1),M("text")],returnType:"number"},weekday:{validations:[k(1),E(1),M("date")],returnType:"number"},year:{validations:[k(1),E(1),M("date")],returnType:"number"}};class F extends o{constructor(e,t){super(e,"ReferenceError",t)}}const j=e=>{switch(e.type){case"callExpression":return t=e.id,r=e.arguments.map((e=>j(e))),h((()=>{const e=r.find((e=>"error"===e.type));if(e)return e;const n=S[t];if(n)return n.validations.forEach((e=>e(t)(r))),A[`sf$${t}`](...r);throw new O(`Unknown function ${t.toUpperCase()}. Check spelling.`,{function:t})}));case"identifier":throw new F(`Field ${e.name} does not exist. Check spelling.`,{identifier:e.name});default:return e}var t,r},D=e=>{try{return a.parse(null==e?"":e.trim())}catch(e){if(e instanceof a.SyntaxError)return p("SyntaxError","Syntax error.",{});throw e}},N=(e,t=[])=>{switch(e.type){case"callExpression":return e.arguments.map((e=>N(e,t))).reduce(((e,t)=>e.concat(t)),[]);case"identifier":return t.concat(e.name);default:return t}},I=(e,t)=>"callExpression"===e.type?{type:"callExpression",id:e.id,arguments:e.arguments.map((e=>I(e,t)))}:"identifier"===e.type&&t[e.name]?{...t[e.name],type:"literal"}:e;e.ast=e=>null==e||""===e.trim()?{}:D(e),e.extract=e=>{if(null==e||""===e.trim())return[];const t=D(e);return N(t).reduce(((e,t)=>(e.indexOf(t)<0&&e.push(t),e)),[])},e.parse=(e,t={})=>{if(null==e||""===e.trim())return d("");const r=D(e),n=Object.keys(t).reduce(((e,r)=>{return{...e,[r]:(n=t[r],void 0===n.value||null===n.value||Number.isNaN(n.value)?{type:"literal",value:null,dataType:"null",options:{}}:{...n,value:c(n.dataType,n.value,n.options)})};var n}),{});return(e=>h((()=>j(e))))(I(r,n))},e.toString=e=>y(e),Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "formulon", | ||
"version": "6.24.0", | ||
"version": "6.24.1", | ||
"description": "Salesforce Formula Parser", | ||
@@ -5,0 +5,0 @@ "main": "lib/formulon.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178113
3605