botbook/node_modules/@sagold/json-query/dist/jsonQuery.js
Rodrigo Rodriguez 6ae15fe3e5 Updated.
2024-09-04 13:13:15 -03:00

2 lines
No EOL
21 KiB
JavaScript

/*! For license information please see jsonQuery.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("jsonQuery",[],t):"object"==typeof exports?exports.jsonQuery=t():e.jsonQuery=t()}("undefined"!=typeof self?self:this,(()=>(()=>{var e={546:function(e){"undefined"!=typeof self&&self,e.exports=(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return"#"===e||""===e||Array.isArray(e)&&0===e.length||!1}e.r(t),e.d(t,{default:()=>v,get:()=>c,isRoot:()=>r,join:()=>C,remove:()=>x,removeUndefinedItems:()=>y,set:()=>m,split:()=>u,splitLast:()=>_});const n=/~1/g,o=/~0/g,i=/\/+/g,l=/(^[#/]*|\/+$)/g;function a(e){return e.replace(n,"/").replace(o,"~")}function s(e){return a(decodeURIComponent(e))}function u(e){if(null==e||"string"!=typeof e||r(e))return Array.isArray(e)?e:[];const t=e.indexOf("#")>=0?s:a,n=(e=(e=e.replace(i,"/")).replace(l,"")).split("/");for(let e=0,r=n.length;e<r;e+=1)n[e]=t(n[e]);return n}function c(e,t,n=void 0){if(null==t||null==e)return n;if(r(t))return e;const o=f(e,u(t));return void 0===o?n:o}function f(e,t){const r=t.shift();if(void 0!==e)return void 0!==r?f(e[r],t):e}const p=/^\[.*\]$/,h=/^\[(.+)\]$/;function d(e,t){return"__proto__"===e||"constructor"==e&&t.length>0&&"prototype"==t[0]}function m(e,t,r){if(null==t)return e;const n=u(t);if(0===n.length)return e;null==e&&(e=p.test(n[0])?[]:{});let o,i,l=e;for(;n.length>1;)o=n.shift(),i=p.test(n[0]),d(o,n)||(l=E(l,o,i));return o=n.pop(),g(l,o,r),e}function g(e,t,r){let n;const o=t.match(h);"[]"===t&&Array.isArray(e)?e.push(r):o?(n=o.pop(),e[n]=r):e[t]=r}function E(e,t,r){if(null!=e[t])return e[t];const n=r?[]:{};return g(e,t,n),n}function y(e){let t=0,r=0;for(;t+r<e.length;)void 0===e[t+r]&&(r+=1),e[t]=e[t+r],t+=1;return e.length=e.length-r,e}function x(e,t,r){const n=u(t),o=n.pop(),i=c(e,n);return i&&delete i[o],Array.isArray(i)&&!0!==r&&y(i),e}const b=/\/+/g,S=/~/g,R=/\//g;function A(e,t){if(0===e.length)return t?"#":"";for(let r=0,n=e.length;r<n;r+=1)e[r]=e[r].replace(S,"~0").replace(R,"~1"),t&&(e[r]=encodeURIComponent(e[r]));return((t?"#/":"/")+e.join("/")).replace(b,"/")}function C(e,...t){const r=[];if(Array.isArray(e))return A(e,!0===arguments[1]);const n=arguments[arguments.length-1],o="boolean"==typeof n?n:e&&"#"===e[0];for(let e=0,t=arguments.length;e<t;e+=1)r.push.apply(r,u(arguments[e]));const i=[];for(let e=0,t=r.length;e<t;e+=1)if(".."===r[e]){if(0===i.length)return o?"#":"";i.pop()}else i.push(r[e]);return A(i,o)}function _(e){const t=u(e);if(0===t.length)return"string"==typeof e&&"#"===e[0]?["#",t[0]]:["",void 0];if(1===t.length)return"#"===e[0]?["#",t[0]]:["",t[0]];const r=t.pop();return[C(t,"#"===e[0]),r]}const v={get:c,set:m,remove:x,join:C,split:u,splitLast:_,isRoot:r,removeUndefinedItems:y};return t})()},782:(e,t,r)=>{"use strict";const n=r(492);var o;!function(e){e.RULES=[{name:"Grammar",bnf:[["RULE_S*","%Atomic*","EOF"]]},{name:"%Atomic",bnf:[["Production","RULE_S*"]],fragment:!0},{name:"Production",bnf:[["NCName","RULE_S*",'"::="',"RULE_WHITESPACE*","Choice","RULE_WHITESPACE*","RULE_EOL+","RULE_S*"]]},{name:"NCName",bnf:[[/[a-zA-Z][a-zA-Z_0-9]*/]]},{name:"Choice",bnf:[["SequenceOrDifference","%_Choice_1*"]],fragment:!0},{name:"%_Choice_1",bnf:[["RULE_WHITESPACE*",'"|"',"RULE_WHITESPACE*","SequenceOrDifference"]],fragment:!0},{name:"SequenceOrDifference",bnf:[["Item","RULE_WHITESPACE*","%_Item_1?"]]},{name:"%_Item_1",bnf:[["Minus","Item"],["Item*"]],fragment:!0},{name:"Minus",bnf:[['"-"']]},{name:"Item",bnf:[["RULE_WHITESPACE*","%Primary","PrimaryDecoration?"]],fragment:!0},{name:"PrimaryDecoration",bnf:[['"?"'],['"*"'],['"+"']]},{name:"DecorationName",bnf:[['"ebnf://"',/[^\x5D#]+/]]},{name:"%Primary",bnf:[["NCName"],["StringLiteral"],["CharCode"],["CharClass"],["SubItem"]],fragment:!0},{name:"SubItem",bnf:[['"("',"RULE_WHITESPACE*","Choice","RULE_WHITESPACE*",'")"']]},{name:"StringLiteral",bnf:[["'\"'",/[^"]*/,"'\"'"],['"\'"',/[^']*/,'"\'"']],pinned:1},{name:"CharCode",bnf:[['"#x"',/[0-9a-zA-Z]+/]]},{name:"CharClass",bnf:[["'['","'^'?","%RULE_CharClass_1+",'"]"']]},{name:"%RULE_CharClass_1",bnf:[["CharCodeRange"],["CharRange"],["CharCode"],["RULE_Char"]],fragment:!0},{name:"RULE_Char",bnf:[[/\x09/],[/\x0A/],[/\x0D/],[/[\x20-\x5c]/],[/[\x5e-\uD7FF]/],[/[\uE000-\uFFFD]/]]},{name:"CharRange",bnf:[["RULE_Char",'"-"',"RULE_Char"]]},{name:"CharCodeRange",bnf:[["CharCode",'"-"',"CharCode"]]},{name:"RULE_WHITESPACE",bnf:[["%RULE_WHITESPACE_CHAR*"],["Comment","RULE_WHITESPACE*"]]},{name:"RULE_S",bnf:[["RULE_WHITESPACE","RULE_S*"],["RULE_EOL","RULE_S*"]]},{name:"%RULE_WHITESPACE_CHAR",bnf:[[/\x09/],[/\x20/]],fragment:!0},{name:"Comment",bnf:[['"/*"',"%RULE_Comment_Body*",'"*/"']]},{name:"%RULE_Comment_Body",bnf:[['!"*/"',/[^*]/]],fragment:!0},{name:"RULE_EOL",bnf:[[/\x0D/,/\x0A/],[/\x0A/],[/\x0D/]]},{name:"Link",bnf:[["'['","Url","']'"]]},{name:"Url",bnf:[[/[^\x5D:/?#]/,'"://"',/[^\x5D#]+/,"%Url1?"]]},{name:"%Url1",bnf:[['"#"',"NCName"]],fragment:!0}],e.defaultParser=new n.Parser(e.RULES,{debug:!1});const t=/^(!|&)/,r=/(\?|\+|\*)$/,o=/^%/;function i(e,i){if("string"==typeof e){if(t.test(e))return"";if(o.test(e)){let t=r.exec(e),o=t?t[0]+" ":"",a=function(e,t){let r=n.findRuleByName(e,t);return r&&1==r.bnf.length&&1==r.bnf[0].length&&(r.bnf[0][0]instanceof RegExp||'"'==r.bnf[0][0][0]||"'"==r.bnf[0][0][0])}(e,i);return a?l(e,i)+o:"("+l(e,i)+")"+o}return e}return e.source.replace(/\\(?:x|u)([a-zA-Z0-9]+)/g,"#x$1").replace(/\[\\(?:x|u)([a-zA-Z0-9]+)-\\(?:x|u)([a-zA-Z0-9]+)\]/g,"[#x$1-#x$2]")}function l(e,t){let r=n.findRuleByName(e,t);return r?r.bnf.map((e=>function(e,t){return e.map((e=>i(e,t))).join(" ")}(e,t))).join(" | "):"RULE_NOT_FOUND {"+e+"}"}function a(e){let t=[];return e.grammarRules.forEach((r=>{if(!/^%/.test(r.name)){let n=r.recover?" /* { recoverUntil="+r.recover+" } */":"";t.push(r.name+" ::= "+l(r.name,e)+n)}})),t.join("\n")}e.emit=a;let s=0;function u(e){return new RegExp(e.replace(/#x([a-zA-Z0-9]{4})/g,"\\u$1").replace(/#x([a-zA-Z0-9]{3})/g,"\\u0$1").replace(/#x([a-zA-Z0-9]{2})/g,"\\x$1").replace(/#x([a-zA-Z0-9]{1})/g,"\\x0$1"))}function c(e,t,r){let n=null,o=[];return t.children.forEach(((i,l)=>{"Minus"==i.type&&function(e,t){throw console.log("reberia restar "+t+" a "+e),new Error("Difference not supported yet")}(n,i);let a=t.children[l+1];a=a&&"PrimaryDecoration"==a.type&&a.text||"";switch(i.type){case"SubItem":let t="%"+(r+s++);f(e,i,t),o.push(""+t+a);break;case"NCName":case"StringLiteral":o.push(""+i.text+a);break;case"CharCode":case"CharClass":if(a){let t={name:"%"+(r+s++),bnf:[[u(i.text)]]};e.push(t),o.push(""+t.name+a)}else o.push(u(i.text));break;case"PrimaryDecoration":break;default:throw new Error(" HOW SHOULD I PARSE THIS? "+i.type+" -> "+JSON.stringify(i.text))}n=i})),o}function f(e,t,r){let n=t.children.filter((e=>"SequenceOrDifference"==e.type)).map((t=>c(e,t,r))),o={name:r,bnf:n},i=null;n.forEach((e=>{i=i||e.recover,delete e.recover})),0==r.indexOf("%")&&(o.fragment=!0),i&&(o.recover=i),e.push(o)}function p(t,r=e.defaultParser){let n=r.getAST(t);if(!n)throw new Error("Could not parse "+t);if(n.errors&&n.errors.length)throw n.errors[0];let o=[];return n.children.filter((e=>"Production"==e.type)).map((e=>{let t=e.children.filter((e=>"NCName"==e.type))[0].text;f(o,e,t)})),o}e.getRules=p,e.Transform=function(t,r=e.defaultParser){return p(t.join(""),r)};class h extends n.Parser{constructor(t,r){super(p(t,r&&!0===r.debugRulesParser?new n.Parser(e.RULES,{debug:!0}):e.defaultParser),r)}emitSource(){return a(this)}}e.Parser=h}(o||(o={})),t.A=o},492:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Parser=t.findRuleByName=t.parseRuleName=t.escapeRegExp=t.readToken=void 0;const n=/^[A-Z0-9_]+$/,o=/(\?|\+|\*)$/,i=/^(@|&|!)/,l="WS",a=r(594);function s(e,t){let r=t.exec(e);return r&&0==r.index?0==r[0].length&&t.source.length>0?null:{type:null,text:r[0],rest:e.substr(r[0].length),start:0,end:r[0].length-1,fullText:r[0],errors:[],children:[],parent:null}:null}function u(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function c(e){e.rest="",e.children&&e.children.forEach((e=>c(e)))}function f(e,t){e.start+=t,e.end+=t,e.children&&e.children.forEach((t=>f(t,e.start)))}function p(e,t){t.errors&&t.errors.length&&t.errors.forEach((t=>e.push(t))),t.children&&t.children.forEach((t=>p(e,t)))}function h(e){let t=o.exec(e),r=i.exec(e),n=t&&t[0]||"",l=r&&r[0]||"",a={raw:e,name:e.replace(o,"").replace(i,""),isOptional:"?"==n||"*"==n,allowRepetition:"+"==n||"*"==n,atLeastOne:"+"==n,lookupPositive:"&"==l,lookupNegative:"!"==l,pinned:"@"==l,lookup:!1,isLiteral:!1};return a.isLiteral="'"==a.name[0]||'"'==a.name[0],a.lookup=a.lookupNegative||a.lookupPositive,a}function d(e,t){let r=h(e);return t.cachedRules[r.name]||null}function m(e,t){if(e.children){let r=e.children.filter((e=>e.type&&t.test(e.type)));for(let t=0;t<r.length;t++){let n=e.children.indexOf(r[t]);-1!=n&&e.children.splice(n,1)}e.children.forEach((e=>m(e,t)))}}t.readToken=s,t.escapeRegExp=u,t.parseRuleName=h,t.findRuleByName=d;const g=["EOF"];class E{constructor(e,t){this.grammarRules=e,this.options=t,this.cachedRules={},this.debug=!!t&&!0===t.debug;let r=[],n=[];if(e.forEach((e=>{let t=h(e.name);if(t.name in this.cachedRules)r.push("Duplicated rule "+t.name);else{if(this.cachedRules[t.name]=e,e.bnf&&e.bnf.length)e.bnf.forEach((t=>{if("string"==typeof t[0]){if(h(t[0]).name==e.name){let t="Left recursion is not allowed, rule: "+e.name;-1==r.indexOf(t)&&r.push(t)}}t.forEach((e=>{if("string"==typeof e){let t=h(e);t.isLiteral||-1!=n.indexOf(t.name)||-1!=g.indexOf(t.name)||n.push(t.name)}}))}));else{let t="Missing rule content, rule: "+e.name;-1==r.indexOf(t)&&r.push(t)}l==e.name&&(e.implicitWs=!1),e.implicitWs&&-1==n.indexOf(l)&&n.push(l),e.recover&&-1==n.indexOf(e.recover)&&n.push(e.recover)}})),n.forEach((e=>{e in this.cachedRules||r.push("Missing rule "+e)})),r.length)throw new Error(r.join("\n"))}getAST(e,t){t||(t=this.grammarRules.filter((e=>!e.fragment&&0!=e.name.indexOf("%")))[0].name);let r=this.parse(e,t);if(r){p(r.errors,r),f(r,0),m(r,/^%/),this.options&&this.options.keepUpperRules||m(r,n);let e=r.rest;e&&new a.TokenError("Unexpected end of input: \n"+e,r),c(r),r.rest=e}return r}emitSource(){return"CANNOT EMIT SOURCE FROM BASE Parser"}parse(e,t,r=0){let o,i=null,c=h(t),f=this.debug&&!n.test(c.name);f&&console.log(new Array(r).join("│ ")+"Trying to get "+t+" from "+JSON.stringify(e.split("\n")[0]));let p=c.name,m=d(c.name,this);if("EOF"==c.name){if(e.length)return null;if(0==e.length)return{type:"EOF",text:"",rest:"",start:0,end:0,fullText:"",errors:[],children:[],parent:null}}try{if(!m&&c.isLiteral){let t=c.name.trim();if(t.startsWith('"')?t=JSON.parse(t):t.startsWith("'")&&(t=t.replace(/^'(.+)'$/,"$1").replace(/\\'/g,"'")),""===t)return{type:"%%EMPTY%%",text:"",rest:e,start:0,end:0,fullText:"",errors:[],children:[],parent:null};o=new RegExp(u(t)),p=null}}catch(e){return e instanceof ReferenceError&&console.error(e),null}if(o){let t=s(e,o);if(t)return t.type=p,t}else{let t=m.bnf;t instanceof Array&&t.forEach((t=>{if(i)return;let n=null,o={type:c.name,text:"",children:[],end:0,errors:[],fullText:"",parent:null,start:0,rest:e};m.fragment&&(o.fragment=!0);let u=e,p=0,d=t.length>0,g=!1;for(let e=0;e<t.length;e++)if("string"==typeof t[e]){let s,c=h(t[e]);d=d&&c.isOptional;let E=!1;do{if(s=null,m.implicitWs&&(s=this.parse(u,c.name,r+1),!s)){let e;do{if(e=this.parse(u,l,r+1),!e)break;o.text=o.text+e.text,o.end=o.text.length,e.parent=o,o.children.push(e),u=u.substr(e.text.length),p+=e.text.length}while(e&&e.text.length)}if(s=s||this.parse(u,c.name,r+1),c.lookupNegative){if(s)return;break}if(c.lookupPositive&&!s)return;if(!s){if(c.isOptional)break;if(c.atLeastOne&&E)break}if(s&&m.pinned==e+1&&(n=s,f&&console.log(new Array(r+1).join("│ ")+"└─ "+s.type+" PINNED")),s||(s=this.parseRecovery(m,u,r+1)),!s){if(!n)return;i=o,s={type:"SyntaxError",text:u,children:[],end:u.length,errors:[],fullText:"",parent:null,start:0,rest:""},u.length?new a.TokenError(`Unexpected end of input. Expecting ${c.name} Got: ${u}`,s):new a.TokenError(`Unexpected end of input. Missing ${c.name}`,s),f&&console.log(new Array(r+1).join("│ ")+"└─ "+s.type+" "+JSON.stringify(s.text))}if(E=!0,g=!0,"%%EMPTY%%"==s.type)break;s.start+=p,s.end+=p,!c.lookupPositive&&s.type&&(s.fragment?s.children&&s.children.forEach((e=>{e.start+=p,e.end+=p,e.parent=o,o.children.push(e)})):(s.parent=o,o.children.push(s))),c.lookup&&(s.lookup=!0),f&&console.log(new Array(r+1).join("│ ")+"└─ "+s.type+" "+JSON.stringify(s.text)),c.lookup||s.lookup||(o.text=o.text+s.text,o.end=o.text.length,u=u.substr(s.text.length),p+=s.text.length),o.rest=u}while(s&&c.allowRepetition&&u.length&&!s.lookup)}else{let n=s(u,t[e]);if(!n)return;f&&console.log(new Array(r+1).join("│ ")+"└> "+JSON.stringify(n.text)+t[e].source),g=!0,n.start+=p,n.end+=p,o.text=o.text+n.text,o.end=o.text.length,u=u.substr(n.text.length),p+=n.text.length,o.rest=u}g&&(i=o,f&&console.log(new Array(r).join("│ ")+"├<─┴< PUSHING "+i.type+" "+JSON.stringify(i.text)))})),i&&m.simplifyWhenOneChildren&&1==i.children.length&&(i=i.children[0])}return i||f&&console.log(t+" NOT RESOLVED FROM "+e),i}parseRecovery(e,t,r){if(e.recover&&t.length){let n=this.debug;n&&console.log(new Array(r+1).join("│ ")+"Trying to recover until token "+e.recover+" from "+JSON.stringify(t.split("\n")[0]+t.split("\n")[1]));let o,i={type:"SyntaxError",text:"",children:[],end:0,errors:[],fullText:"",parent:null,start:0,rest:""};do{if(o=this.parse(t,e.recover,r+1),o){new a.TokenError('Unexpected input: "'+i.text+`" Expecting: ${e.name}`,i);break}i.text=i.text+t[0],i.end=i.text.length,t=t.substr(1)}while(!o&&t.length>0);if(i.text.length>0&&o)return n&&console.log(new Array(r+1).join("│ ")+"Recovered text: "+JSON.stringify(i.text)),i}return null}}t.Parser=E,t.default=E},594:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TokenError=void 0;class r extends Error{constructor(e,t){if(super(e),this.message=e,this.token=t,!t||!t.errors)throw this;t.errors.push(this)}inspect(){return"SyntaxError: "+this.message}}t.TokenError=r}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{ReturnType:()=>R,default:()=>F,get:()=>A,remove:()=>q,set:()=>W,split:()=>v});var e=r(782);const t="[^?/{}*,()#]+",o=`\nroot ::= ("#" recursion | recursion | (query | pattern) recursion* | "#" SEP? | SEP)\nrecursion ::= (SEP query | pattern)*\n\nquery ::= (ESC escaped ESC | property | all | any | regex) typecheck? lookahead?\nproperty ::= ${t}\nregex ::= "{" [^}]+ "}"\nSEP ::= "/"\nall ::= "**"\nany ::= "*"\n\ntypecheck ::= "?:" ("value" | "boolean" | "string" | "number" | "object" | "array")\nlookahead ::= "?" expression ((andExpr | orExpr) expression)*\nandExpr ::= S? "&&" S?\norExpr ::= S? "||" S?\n\nexpression ::= (exprProperty | ESC escaped ESC) ((isnot | is) (exprProperty | regex | ESC escaped ESC))*\nexprProperty ::= [a-zA-Z0-9-_ $]+\nescaped ::= [^"]+\nis ::= ":"\nisnot ::= ":!"\nESC ::= '"'\n\npattern ::= S? "(" (SEP query | pattern (orPattern? pattern)*)* ")" quantifier? S? lookahead?\nquantifier ::= "+" | "*" | [0-9]+\norPattern ::= S? "," S?\n\nS ::= [ ]*\n`,i=new e.A.Parser(o),l=e=>i.getAST(e),a=2,s=3,u=(e,t)=>`${e}/${t}`,c=Object.prototype.toString,f=/Object|Array/,p=e=>f.test(c.call(e));function h(e){return new RegExp(e.text.replace(/(^{|}$)/g,""))}function d(e){return Array.isArray(e)?e.map((function(e,t){return`${t}`})):"[object Object]"===Object.prototype.toString.call(e)?Object.keys(e):[]}const m={mem:[],get(e,t){const r=e[0][t];if(!m.mem.includes(r))return p(r)&&m.mem.push(r),[r,t,e[0],u(e[s],t)]},reset(){m.mem.length=0}},g={any(e,t){const r=t[0];return d(r).map((e=>[r[e],e,r,u(t[s],e)]))},all(e,t){const r=[t];var n,o;return n=t[0],o=(n,o)=>{const i=m.get(t,o);i&&r.push(...g.all(e,i))},Array.isArray(n)?n.forEach(o):"[object Object]"===Object.prototype.toString.call(n)&&Object.keys(n).forEach((function(e){o(n[e],e,n)})),r},regex(e,t){const r=h(e),n=t[0];return d(n).filter((e=>r.test(e))).map((e=>[n[e],e,n,u(t[s],e)]))}},E={escaped:(e,t)=>E.property(e,t),property:(e,t)=>{const r=e.text;if(t[0]&&void 0!==t[0][r])return[t[0][r],r,t[0],u(t[s],r)]},typecheck:(e,t)=>{const r=e.text.replace(/^\?:/,"");if("value"===r)return p(t[0])?void 0:t;var n;return(n=t[0],c.call(n).match(/\s([^\]]+)\]/).pop().toLowerCase())===r?t:void 0},lookahead:(e,t)=>{let r=!0,n=!1;return e.children.forEach((e=>{if("expression"===e.type){const o=void 0!==E.expression(e,t);r=!0===n?r||o:r&&o}else n="orExpr"===e.type})),r?t:void 0},expression:(e,t)=>{const r=e.children[0].text,n=e.children[1],o=e.children[2],i=t[0];if(!1!==p(i))return function(e,t,r){if(void 0===t)return void 0!==e;let n;const o=`${e}`;if("regex"===r.type){n=h(r).test(o)}else n=o===r.text;"isnot"===t.type&&(n=!1===n&&void 0!==e);return n}(i[r],n,o)?t:void 0}};function y(e,t,r){const n=[];let o=e;return t.children.forEach((t=>{if("orPattern"===t.type)return n.push(...o),void(o=e);o=b(o,t,r)})),n.push(...o),n}function x(e,t,r){const n=[],o=t.children.find((e=>"quantifier"===e.type)),i=function(e){if(null==e)return 1;if("*"===e||"+"===e)return 1/0;const t=parseInt(e);return isNaN(t)?1:t}(o&&o.text);let l=e;o&&"*"===o.text&&n.push(...l);let a=0;for(;l.length>0&&a<i;)l=y(l,t,r),n.push(...l),a+=1;return n}function b(e,t,r){let n;return n="query"===t.type?function(e,t,r){let n=e;return t.children.forEach((e=>{if(g[e.type])n=function(e,t,r,n){const o=[];for(let i=0,l=t.length;i<l;i+=1)o.push(...e(r,t[i],r,n));return o}(g[e.type],n,e,r);else{if(!E[e.type])throw new Error(`Unknown filter ${e.type}`);n=function(e,t,r,n){const o=[];for(let i=0,l=t.length;i<l;i+=1){const l=e(r,t[i],n);l&&o.push(l)}return o}(E[e.type],n,e,r)}})),n}(e,t,r):"pattern"===t.type?x(e,t,r):function(e,t,r){let n=e;return t.children.forEach((e=>n=b(n,e,r))),n}(e,t,r),m.reset(),m.mem.push(e),n}const S={value:e=>e.map((e=>e[0])),pointer:e=>e.map((e=>e[s])),all:e=>e,map:e=>{const t={};return e.forEach((e=>t[e[s]]=e[0])),t}};var R;function A(e,t,r=R.VALUE){if(null==t)return[];""===(t=t.replace(/(\/$)/g,""))&&(t="#");const n=l(t);if(null==n)throw new Error(`empty ast for '${t}'`);if(""!==n.rest)throw new Error(`Failed parsing queryString from: '${n.rest}'`);const o=function(e,t){return m.reset(),m.mem.push(e),b([[e,null,null,"#"]],t)}(e,n);return"function"==typeof r?o.map((e=>r(...e))):S[r]?S[r](o):o}!function(e){e.POINTER="pointer",e.VALUE="value",e.ALL="all",e.MAP="map"}(R||(R={})),A.POINTER=R.POINTER,A.VALUE=R.VALUE,A.ALL=R.ALL,A.MAP=R.MAP;const C=["root","recursion"];function _(e,t=[]){return C.includes(e.type)?(e.children.forEach((e=>_(e,t))),t):(t.push(e.text),t)}function v(e){if(null==e||""===e)return[];return _(l(e))}const P=e=>JSON.parse(JSON.stringify(e)),L=Object.prototype.toString,O=e=>L.call(e).match(/\s([^\]]+)\]/).pop().toLowerCase(),T=new RegExp(`^("[^"]+"|${t})$`),U=["string","number","boolean","null"],$=/^\[\d*\]$/,w=/^\[(\d+)\]$/,N=/^".+"$/,I=/(^\[\d*\]$|^\d+$)/;function j(e){return parseInt(e.replace(/^(\[|\]$)/,""))}function k(e){return N.test(e)?e.replace(/(^"|"$)/g,""):e}function M(e,t,r,n){const o=e[0];if(/^\[\]$/.test(t)){o.push(r);const t=o.length-1;return[o[t],t,o,`${e[3]}/${t}}`]}if(null==n&&"object"===O(o[t])&&"object"===O(r))return Object.assign(o[t],r),[o[t],t,o,`${e[3]}/${t}}`];if(n===W.INSERT_ITEMS||null==n&&w.test(t)){const n=j(t);return function(e,t,r){e.length<=t?e[t]=r:e.splice(t,0,r)}(o,n,r),[o[n],n,o,`${e[3]}/${n}}`]}if(n===W.REPLACE_ITEMS||null==n){const n=j(t);return o[n]=r,[o[n],n,o,`${e[3]}/${n}}`]}throw new Error(`Unknown array index '${t}' with force-option '${n}'`)}var D;function W(e,t,r,n){if(null==t)return P(e);if(""===(t=t.replace(/(\/$)/g,"")))return P(r);const o=P(e);let i=[[o,null,null,"#"]];const l=v(t),a=l.pop(),s=$.test(a)&&!1===w.test(a);if(!1===T.test(a)||s)throw new Error(`Unsupported query '${t}' ending with non-property`);return l.forEach(((e,t)=>{if("__proto__"===e||"prototyped"===e||"constructor"===e)return;if(!1===T.test(e))return void(i=function(e,t){const r=[];return e.forEach((e=>r.push(...A(e[0],t,R.ALL)))),r}(i,e));const r=t>=l.length-1?a:l[t+1],o=I.test(r);i=function(e,t,r,n){return t=k(t),e.filter((e=>!(!Array.isArray(e[0])||!I.test(t))||!1===U.includes(O(e[0][t])))).map((e=>{const o=r?[]:{},i=e[0],l=O(o),a=O(i[t]);return Array.isArray(i)&&a!==l?M(e,t,o,n):(i[t]=i[t]||o,[i[t],t,i,`${e[3]}/${t}`])}))}(i,e,o,n)})),i.forEach((e=>{let t=r;"function"===O(r)&&(t=r(e[3],a,e[0],`${e[3]}/${a}`));const o=e[0];if(Array.isArray(o))M(e,a,t,n);else{const e=k(a);if("__proto__"===e||"prototyped"===e||"constructor"===e)return;o[e]=t}})),o}!function(e){e.REPLACE_ITEMS="replace",e.INSERT_ITEMS="insert"}(D||(D={})),W.REPLACE_ITEMS=D.REPLACE_ITEMS,W.INSERT_ITEMS=D.INSERT_ITEMS;var H=r(546);function q(e,t,r=!1){const n=[],o=A(e,t,R.ALL);return o.forEach((function(t){n.push(t[0]),(0,H.remove)(e,t[s],!0)})),o.forEach((function(e){Array.isArray(e[a])&&(0,H.removeUndefinedItems)(e[a])})),r?n:e}const F={get:A,set:W,split:v,remove:q,ReturnType:R}})(),n})()));