json-p3 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class c extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}class u extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function h(e){return Array.isArray(e)}function l(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function p(e){return"string"==typeof e}function f(e){return"number"==typeof e}function d(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}return!1}if(l(e)&&l(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!d(e[r],t[r]))return!1;return!0}return!1}let g=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class m extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class w extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class y extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class E extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const k=Symbol.for("jsonpointer.undefined");class O{#e;constructor(e){this.tokens=this.parse(e),this.#e=O.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==k)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[k,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof w||e instanceof x)return[t,k];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every(((t,n)=>t===e.tokens[n]))}parse(e){if(e.length&&!e.startsWith("/"))throw new y(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(S.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(l(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new x(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new E(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(e))throw new E("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new O(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new O(O.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new O(O.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,S=/(0|[1-9][0-9]*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new O(e):e;if(this.origin>t.tokens.length)throw new w(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new w(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof O?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new O(O.encode(n))}parse(e){const t=N.exec(e);if(!t||!t.groups)throw new y("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new y("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new O(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new y("unexpected leading zero");if(S.test(e))return Number(e);throw new y(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||S.test(e)}}function R(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:k;return new O(e).resolve(t,n)}var $=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:x,JSONPointerResolutionError:v,JSONPointerSyntaxError:y,JSONPointerTypeError:E,RelativeJSONPointer:T,UNDEFINED:k,resolve:R});const b=Symbol.for("jsonpath.nothing");function P(e,t){return l(e)&&Object.hasOwn(e,t)}const _="";class A{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>p(e)?this.decode_name_location(e):`[${e}]`)).join("")}toPointer(){return this.location.length?new O(O.encode(this.location.map(String))):new O("")}decode_name_location(e){return e.startsWith(_)?`[~'${e.slice(1).replaceAll("'","\\'")}']`:`['${e.replaceAll("'","\\'")}']`}}class I{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map((e=>e.value))}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map((e=>e.value))}locations(){return this.nodes.map((e=>e.location))}paths(){return this.nodes.map((e=>e.path))}pointers(){return this.nodes.map((e=>e.toPointer()))}get length(){return this.nodes.length}}class L{constructor(e){this.token=e}}class C extends L{}class K extends C{evaluate(){return null}toString(){return"null"}}class F extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class M extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class j extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class U extends L{constructor(e,t,n){super(e),this.token=e,this.operator=t,this.right=n}evaluate(e){if("!"===this.operator){const t=this.right.evaluate(e);return t instanceof I?0===t.nodes.length:!W(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class z extends L{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r,this.logical="&&"===n||"||"===n}evaluate(e){let t=this.left.evaluate(e);!this.logical&&t instanceof I&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof I&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?W(t)&&W(n):"||"===this.operator?W(t)||W(n):B(t,this.operator,n)}toString(){return this.logical?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class J extends L{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof I?t.nodes.length>0:W(t)}toString(){return this.expression.toString()}}class D extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends D{evaluate(e){return e.lazy?new I(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class Q extends D{evaluate(e){return e.lazy?new I(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class V extends L{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof I?this.unpack_node_list(e):e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return b;case 1:return e.nodes[0].value;default:return e}}}function W(e){return!(e instanceof I&&e.empty())&&!("boolean"==typeof e&&!1===e)}function B(e,t,n){switch(t){case"==":return Y(e,n);case"!=":return!Y(e,n);case"<":return q(e,n);case">":return q(n,e);case">=":return q(n,e)||Y(e,n);case"<=":return q(e,n)||Y(e,n);default:return!1}}function Y(e,t){if(t instanceof I&&([e,t]=[t,e]),e instanceof I){if(t instanceof I){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===b:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===b&&t===b||d(e,t)}function q(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var X=Object.freeze({__proto__:null,BooleanLiteral:F,FilterExpression:L,FilterExpressionLiteral:C,FilterQuery:D,FunctionExtension:V,InfixExpression:z,LogicalExpression:J,NullLiteral:K,NumberLiteral:j,PrefixExpression:U,RelativeQuery:G,RootQuery:Q,StringLiteral:M,compare:B});class Z{argTypes=(()=>[g.NodesType])();returnType=(()=>g.ValueType)();call(e){return e.length}}class H{argTypes=(()=>[g.ValueType])();returnType=(()=>g.ValueType)();call(e){return h(e)||p(e)?e.length:l(e)?Object.keys(e).length:b}}class ee extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){if(this.has(e))this.delete(e);else if(this.size>=this.maxSize){const e=this.first();void 0!==e&&this.delete(e)}return super.set(e,t)}first(){return this.keys().next().value}}function te(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ne(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ne.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function re(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ne,Error),ne.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,i=this.location.source+":"+o.line+":"+o.column;if(r){var a=this.location.end,c=re("",o.line.toString().length," "),u=r[s.line-1],h=(s.line===a.line?a.column:u.length+1)-s.column||1;t+="\n --\x3e "+i+"\n"+c+" |\n"+o.line+" | "+u+"\n"+c+" | "+re("",s.column-1," ")+re("",h,"^")}else t+="\n at "+i}return t},ne.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(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"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function o(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"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(i);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const se={StartRules:["start"],SyntaxError:ne,parse:function(e,t){var n,r,s,o,i={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ae},u=Ae,h="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",x="^",y="-",E="]",k="\\p{",O="\\P{",N="L",S="M",T="N",R="P",$="Z",b="S",P="C",_=/^[*-+?]/,A=/^[0-9]/,I=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,M=/^[lps]/,j=/^[ckmo]/,U=/^[cfn-o]/,z=Re("|",!1),J=$e([["*","+"],"?"],!1,!1),D=Re("{",!1),G=$e([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),W=Re("(",!1),B=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=$e([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),re=Re("]",!1),se=Re("\\p{",!1),oe=Re("\\P{",!1),ie=Re("L",!1),ae=$e([["l","m"],"o",["t","u"]],!1,!1),ce=Re("M",!1),ue=$e(["c","e","n"],!1,!1),he=Re("N",!1),le=$e(["d","l","o"],!1,!1),pe=Re("P",!1),fe=$e([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=$e(["l","p","s"],!1,!1),me=Re("S",!1),ve=$e(["c","k","m","o"],!1,!1),we=Re("C",!1),xe=$e(["c","f",["n","o"]],!1,!1),ye=function(e){return function(e){return e<"'"||","===e||"-"===e||e>="/"&&e<=">"||e>="@"&&e<="Z"||e>="^"&&e<="z"||e>="~"&&e<="퟿"||e>=""}(e)},Ee=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},ke=0|t.peg$currPos,Oe=[{line:1,column:1}],Ne=ke,Se=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function be(t){var n,r=Oe[t];if(r)return r;if(t>=Oe.length)n=Oe.length-1;else for(n=t;!Oe[--n];);for(r={line:(r=Oe[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return Oe[t]=r,r}function Pe(e,t,n){var r=be(e),s=be(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function _e(e){ke<Ne||(ke>Ne&&(Ne=ke,Se=[]),Se.push(e))}function Ae(){return Ie()}function Ie(){var t,n,r,s;for(t=Le(),n=[],r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);r!==i;)n.push(r),r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);return t=[t,n]}function Le(){var e,t;for(e=[],t=Ce();t!==i;)e.push(t),t=Ce();return e}function Ce(){var t,n,r;return t=ke,n=function(){var t,n,r,s;t=function(){var t,n;t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y));n!==i&&(ye(n)?void 0:i)!==i?t=n:(ke=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(ke)?(t=m,ke++):(t=i,0===Te&&_e(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=ke,91===e.charCodeAt(ke)?(n=w,ke++):(n=i,0===Te&&_e(H));if(n!==i)if(94===e.charCodeAt(ke)?(r=x,ke++):(r=i,0===Te&&_e(ee)),r===i&&(r=null),45===e.charCodeAt(ke)?(s=y,ke++):(s=i,0===Te&&_e(te)),s===i&&(s=Me()),s!==i){for(o=[],a=Me();a!==i;)o.push(a),a=Me();45===e.charCodeAt(ke)?(a=y,ke++):(a=i,0===Te&&_e(te)),a===i&&(a=null),93===e.charCodeAt(ke)?(c=E,ke++):(c=i,0===Te&&_e(re)),c!==i?t=n=[n,r,s,o,a,c]:(ke=t,t=i)}else ke=t,t=i;else ke=t,t=i;return t}());return t}(),t===i&&(t=ke,40===e.charCodeAt(ke)?(n=d,ke++):(n=i,0===Te&&_e(W)),n!==i&&(r=Ie())!==i?(41===e.charCodeAt(ke)?(s=g,ke++):(s=i,0===Te&&_e(B)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(ke),_.test(t)?ke++:(t=i,0===Te&&_e(J));t===i&&(t=function(){var t,n,r,s,o,a;t=ke,123===e.charCodeAt(ke)?(n=l,ke++):(n=i,0===Te&&_e(D));n!==i?(r=e.charAt(ke),A.test(r)?ke++:(r=i,0===Te&&_e(G)),r!==i?(s=ke,44===e.charCodeAt(ke)?(o=p,ke++):(o=i,0===Te&&_e(Q)),o!==i?(a=e.charAt(ke),A.test(a)?ke++:(a=i,0===Te&&_e(G)),a===i&&(a=null),s=o=[o,a]):(ke=s,s=i),s===i&&(s=null),125===e.charCodeAt(ke)?(o=f,ke++):(o=i,0===Te&&_e(V)),o!==i?t=n=[n,r,s,o]:(ke=t,t=i)):(ke=t,t=i)):(ke=t,t=i);return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t}function Ke(){var t,n,r;return t=ke,92===e.charCodeAt(ke)?(n=v,ke++):(n=i,0===Te&&_e(X)),n!==i?(r=e.charAt(ke),I.test(r)?ke++:(r=i,0===Te&&_e(Z)),r!==i?t=n=[n,r]:(ke=t,t=i)):(ke=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===k?(n=k,ke+=3):(n=i,0===Te&&_e(se));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===O?(n=O,ke+=3):(n=i,0===Te&&_e(oe));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}()),t}function Me(){var t,n,r,s,o;return t=ke,(n=je())!==i?(r=ke,45===e.charCodeAt(ke)?(s=y,ke++):(s=i,0===Te&&_e(te)),s!==i&&(o=je())!==i?r=s=[s,o]:(ke=r,r=i),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t===i&&(t=Fe()),t}function je(){var t,n;return t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y)),n!==i&&(Ee(n)?void 0:i)!==i?t=n:(ke=t,t=i),t===i&&(t=Ke()),t}function Ue(){var t;return(t=function(){var t,n,r;t=ke,76===e.charCodeAt(ke)?(n=N,ke++):(n=i,0===Te&&_e(ie));n!==i?(r=e.charAt(ke),L.test(r)?ke++:(r=i,0===Te&&_e(ae)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,77===e.charCodeAt(ke)?(n=S,ke++):(n=i,0===Te&&_e(ce));n!==i?(r=e.charAt(ke),C.test(r)?ke++:(r=i,0===Te&&_e(ue)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,78===e.charCodeAt(ke)?(n=T,ke++):(n=i,0===Te&&_e(he));n!==i?(r=e.charAt(ke),K.test(r)?ke++:(r=i,0===Te&&_e(le)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,80===e.charCodeAt(ke)?(n=R,ke++):(n=i,0===Te&&_e(pe));n!==i?(r=e.charAt(ke),F.test(r)?ke++:(r=i,0===Te&&_e(fe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,90===e.charCodeAt(ke)?(n=$,ke++):(n=i,0===Te&&_e(de));n!==i?(r=e.charAt(ke),M.test(r)?ke++:(r=i,0===Te&&_e(ge)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,83===e.charCodeAt(ke)?(n=b,ke++):(n=i,0===Te&&_e(me));n!==i?(r=e.charAt(ke),j.test(r)?ke++:(r=i,0===Te&&_e(ve)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,67===e.charCodeAt(ke)?(n=P,ke++):(n=i,0===Te&&_e(we));n!==i?(r=e.charAt(ke),U.test(r)?ke++:(r=i,0===Te&&_e(xe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}()),t}if(n=u(),t.peg$library)return{peg$result:n,peg$currPos:ke,peg$FAILED:i,peg$maxFailExpected:Se,peg$maxFailPos:Ne};if(n!==i&&ke===e.length)return n;throw n!==i&&ke<e.length&&_e({type:"end"}),r=Se,s=Ne<e.length?e.charAt(Ne):null,o=Ne<e.length?Pe(Ne,Ne+1):Pe(Ne,Ne),new ne(ne.buildMessage(r,s),r,s,o)}};var oe=function(e){try{se.parse(e,{})}catch(e){if(e instanceof se.SyntaxError)return!1;throw e}return!0};class ie{argTypes=(()=>[g.ValueType,g.ValueType])();returnType=(()=>g.LogicalType)();#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(te(e)),n||r||t.push(")$"),t.join("")}}class ae{argTypes=(()=>[g.ValueType,g.ValueType])();returnType=(()=>g.LogicalType)();#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(te(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class ce{argTypes=(()=>[g.NodesType])();returnType=(()=>g.ValueType)();call(e){return 1===e.length?e.nodes[0].value:b}}let ue=function(e){return e.AND="TOKEN_AND",e.COLON="TOKEN_COLON",e.COMMA="TOKEN_COMMA",e.CURRENT="TOKEN_CURRENT_VALUE",e.CURRENT_KEY="TOKEN_CURRENT_KEY",e.DDOT="TOKEN_DDOT",e.DOT="TOKEN_DOT",e.DOUBLE_QUOTE_STRING="TOKEN_DOUBLE_QUOTE_STRING",e.EOF="TOKEN_EOF",e.EQ="TOKEN_EQ",e.ERROR="TOKEN_ERROR",e.FALSE="TOKEN_FALSE",e.FILTER="TOKEN_FILTER_START",e.FUNCTION="TOKEN_FUNCTION",e.GE="TOKEN_GE",e.GT="TOKEN_GT",e.INDEX="TOKEN_INDEX",e.KEY="TOKEN_KEY",e.KEY_DOUBLE_QUOTE_STRING="TOKEN_KEY_DOUBLE_QUOTE_STRING",e.KEY_SINGLE_QUOTE_STRING="TOKEN_KEY_SINGLE_QUOTE_STRING",e.KEYS="TOKEN_KEYS",e.KEYS_FILTER="TOKEN_KEYS_FILTER",e.LBRACKET="TOKEN_LBRACKET",e.LE="TOKEN_LE",e.LG="TOKEN_LG",e.LPAREN="TOKEN_LPAREN",e.LT="TOKEN_LT",e.NAME="TOKEN_NAME",e.NE="TOKEN_NE",e.NOT="TOKEN_NOT",e.NULL="TOKEN_NULL",e.NUMBER="NUMBER",e.OR="TOKEN_OR",e.RBRACKET="TOKEN_RBRACKET",e.ROOT="TOKEN_ROOT",e.RPAREN="TOKEN_RPAREN",e.SINGLE_QUOTE_STRING="TOKEN_SINGLE_QUOTE_STRING",e.TRUE="TOKEN_TRUE",e.WILD="TOKEN_WILD",e}({});class he{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new he(ue.EOF,"",-1,"");class le{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}expectPeekNot(e,t){const n=this.peek;if(n.kind===e)throw new a(t,n)}}const pe=/[eE][+-]?\d+/y,fe=/[a-z][a-z_0-9]*/y,de=/-?\d+/y,ge=/-?[0-9]+/y,me=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ve=new Set([" ","\n","\t","\r"]),we=/[\u0080-\uFFFFa-zA-Z_]/;class xe{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e,t){this.environment=e,this.path=t}get pos(){return this.#n}get start(){return this.#r}run(){let e=Ee;for(;e;)e=e(this)}emit(e){this.tokens.push(new he(e,this.path.slice(this.#r,this.#n),this.#r,this.path)),this.#r=this.#n}next(){if(this.#n>=this.path.length)return"";const e=this.path[this.#n];return this.#n+=1,e}ignore(){this.#r=this.#n}backup(){if(this.#n<=this.#r){const e="can't backup beyond start";throw new r(e,new he(ue.ERROR,e,this.#n,this.path))}this.#n-=1}peek(){const e=this.next();return e&&this.backup(),e}peekMatch(e){const t=this.next();return t&&this.backup(),e.test(t)}accept(e){const t=this.next();return!!e.has(t)||(t&&this.backup(),!1)}acceptMatch(e){const t=this.next();return!!e.test(t)||(t&&this.backup(),!1)}acceptRun(e){let t=!1,n=this.next();for(;e.has(n);)n=this.next(),t=!0;return n&&this.backup(),t}acceptMatchRun(e){e.lastIndex=this.#n;const t=e.exec(this.path);return e.lastIndex=0,!!t&&(this.#n+=t[0].length,!0)}ignoreWhitespace(){if(this.#n!==this.#r){const e=`must emit or ignore before consuming whitespace ('${this.path.slice(this.#r,this.#n)}':${this.pos})`;throw new r(e,new he(ue.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ve)&&(this.ignore(),!0)}error(e){this.tokens.push(new he(ue.ERROR,e,this.#n,this.path))}}function ye(e,t){const[n,r]=function(e,t){const n=new xe(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===ue.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function Ee(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(ue.ROOT),ke)}function ke(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(ue.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(ue.DDOT),Oe):Ne;case"[":return e.emit(ue.LBRACKET),Se;default:return e.backup(),e.filterLevel?Te:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function Oe(e){if(e.acceptMatchRun(me))return e.emit(ue.NAME),ke;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(ue.KEY),ke):(e.emit(ue.KEYS),ke);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ue.KEYS),ke}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(ue.WILD),ke;case"[":return e.emit(ue.LBRACKET),Se;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function Ne(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(ue.KEY),ke):(e.emit(ue.KEYS),ke);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ue.KEYS),ke}if(e.acceptMatchRun(me))return e.emit(ue.NAME),ke;const t=e.next();return"*"===t?(e.emit(ue.WILD),ke):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Se(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(de)){e.emit(ue.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Ae(e);case'"':return e.ignore(),e.next(),Ie(e);case"?":return e.next(),e.emit(ue.KEYS_FILTER),e.filterLevel+=1,Te;default:e.emit(ue.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(ue.RBRACKET),e.filterLevel?Te:ke;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(ue.WILD);continue;case"?":return e.emit(ue.FILTER),e.filterLevel+=1,Te;case",":e.emit(ue.COMMA);continue;case":":e.emit(ue.COLON);continue;case"'":return $e;case'"':return be;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function Te(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),Se);case",":if(e.emit(ue.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Se;case"'":return Pe;case'"':return _e;case"(":e.emit(ue.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(ue.RPAREN),e.parenStack.length&&(1===e.parenStack[e.parenStack.length-1]?e.parenStack.pop():e.parenStack[e.parenStack.length-1]-=1);continue;case"$":return e.emit(ue.ROOT),ke;case"@":return e.emit(ue.CURRENT),ke;case"#":return e.emit(ue.CURRENT_KEY),ke;case".":return e.backup(),ke;case"!":"="===e.peek()?(e.next(),e.emit(ue.NE)):e.emit(ue.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(ue.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(ue.LE)):e.emit(ue.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(ue.GE)):e.emit(ue.GT);continue;default:if(e.backup(),e.acceptMatchRun(ge)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ge)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(pe),e.emit(ue.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(ue.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(ue.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(ue.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(ue.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(ue.NULL);continue}if(e.acceptMatchRun(fe)&&"("===e.peek()){e.parenStack.push(1),e.emit(ue.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Re(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?ue.SINGLE_QUOTE_STRING:ue.DOUBLE_QUOTE_STRING),r.next(),r.ignore(),t;for(;;){const s=r.path.slice(r.pos,r.pos+2),o=r.next();if("\\\\"!==s&&s!==`\\${e}`){if("\\"===o&&!s.match(/\\[bfnrtu/]/))return r.error("invalid escape"),null;if(!o)return r.error(`unclosed string starting at index ${r.start}`),null;if(o===e)return r.backup(),r.emit(n),r.next(),r.ignore(),t}else r.next()}}}const $e=Re("'",Se,ue.SINGLE_QUOTE_STRING),be=Re('"',Se,ue.DOUBLE_QUOTE_STRING),Pe=Re("'",Te,ue.SINGLE_QUOTE_STRING),_e=Re('"',Te,ue.DOUBLE_QUOTE_STRING),Ae=Re("'",Se,ue.KEY_SINGLE_QUOTE_STRING),Ie=Re('"',Se,ue.KEY_DOUBLE_QUOTE_STRING);class Le{constructor(e,t){this.environment=e,this.token=t}}class Ce extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.name=n}resolve(e){const t=[];return!h(e.value)&&P(e.value,this.name)&&t.push(new A(e.value[this.name],e.location.concat(this.name),e.root)),t}*lazyResolve(e){!h(e.value)&&P(e.value,this.name)&&(yield new A(e.value[this.name],e.location.concat(this.name),e.root))}toString(){return`'${this.name}'`}}class Ke extends Le{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];if(h(e.value)){const n=this.normalizedIndex(e.value.length);n in e.value&&t.push(new A(e.value[n],e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value)){const t=this.normalizedIndex(e.value.length);t in e.value&&(yield new A(e.value[t],e.location.concat(t),e.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Fe extends Le{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];if(!h(e.value))return t;for(const[n,r]of this.slice(e.value,this.start,this.stop,this.step))t.push(new A(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(const[t,n]of this.lazySlice(e.value,this.start,this.stop,this.step))yield new A(n,e.location.concat(t),e.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(const e of t)if(void 0!==e&&(e<this.environment.minIntIndex||e>this.environment.maxIntIndex))throw new o("index out of range",this.token)}slice(e,t,n,r){if(!e.length)return[];if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),0===r)return[];r||(r=1);const s=[];if(r>0)for(let o=t;o<n;o+=r)s.push([o,e[o]]);else for(let o=t;o>n;o+=r)s.push([o,e[o]]);return s}*lazySlice(e,t,n,r){if(e.length)if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),void 0===r)for(let r=t;r<n;r+=1)yield[r,e[r]];else if(r>0)for(let s=t;s<n;s+=r)yield[s,e[s]];else if(r<0)for(let s=t;s>n;s+=r)yield[s,e[s]]}}class Me extends Le{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++)t.push(new A(e.value[n],e.location.concat(n),e.root));else if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new A(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++)yield new A(e.value[t],e.location.concat(t),e.root);else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value))yield new A(n,e.location.concat(t),e.root)}toString(){return"*"}}class je extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++){const r=e.value[n],s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new A(r,e.location.concat(n),e.root))}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new A(r,e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++){const n=e.value[t],r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new A(n,e.location.concat(t),e.root))}else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new A(n,e.location.concat(t),e.root))}}toString(){return`?${this.expression.toString()}`}}var Ue=Object.freeze({__proto__:null,FilterSelector:je,IndexSelector:Ke,JSONPathSelector:Le,NameSelector:Ce,SliceSelector:Fe,WildcardSelector:Me});class ze{constructor(e,t,n){this.environment=e,this.token=t,this.selectors=n}}class Je extends ze{resolve(e){const t=[];for(const n of e)for(const e of this.selectors)t.push(...e.resolve(n));return t}*lazyResolve(e){for(const t of e)for(const e of this.selectors)yield*e.resolve(t)}toString(){return`[${this.selectors.map((e=>e.toString())).join(", ")}]`}}class De extends ze{resolve(e){const t=[],n=(this.environment.nondeterministic?this.nondeterministicVisit:this.visit).bind(this);for(const r of e)for(const e of n(r))for(const n of this.selectors)t.push(...n.resolve(e));return t}*lazyResolve(e){for(const t of e)for(const e of this.visit(t))for(const t of this.selectors)yield*t.resolve(e)}toString(){return`..[${this.selectors.map((e=>e.toString())).join(", ")}]`}visit(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function*(){if(n>=t.environment.maxRecursionDepth)throw new c("recursion limit reached",t.token);if(yield e,h(e.value))for(let r=0;r<e.value.length;r++){const s=new A(e.value[r],e.location.concat(r),e.root);yield*t.visit(s,n+1)}else if(l(e.value))for(const[r,s]of t.environment.entries(e.value)){const o=new A(s,e.location.concat(r),e.root);yield*t.visit(o,n+1)}}()}nondeterministicVisit(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function*(){let r=Array.from(t.nondeterministicChildren(e)).map((e=>[e,n]));for(yield e;r.length;){const[e,n]=r.shift();if(yield e,n>=t.environment.maxRecursionDepth)throw new c("recursion limit reached",t.token);const s=Math.random()<.5;for(const o of t.nondeterministicChildren(e))if(s){yield o;r=Ge(r,Array.from(t.nondeterministicChildren(o)).map((e=>[e,n+2])))}else r.push([o,n+1])}}()}*nondeterministicChildren(e){if(!p(e.value))if(h(e.value))for(let t=0;t<e.value.length;t++)yield new A(e.value[t],e.location.concat(t),e.root);else if(l(e.value))for(const[t,n]of this.environment.entries(e.value))yield new A(n,e.location.concat(t),e.root)}}function Ge(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map((e=>e.next().value))}class Qe{constructor(e,t){this.environment=e,this.segments=t}query(e){let t=[new A(e,[],e)];for(const e of this.segments)t=e.resolve(t);return new I(t)}lazyQuery(e){let t=[new A(e,[],e)][Symbol.iterator]();for(const e of this.segments)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(){return`$${this.segments.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.segments){if(e instanceof De)return!1;if(1!==e.selectors.length||!(e.selectors[0]instanceof Ce||e.selectors[0]instanceof Ke))return!1}return!0}}class Ve extends L{evaluate(e){return e.currentKey??b}toString(){return"#"}}class We extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.key=n}resolve(e){const t=[];return e.value instanceof String||h(e.value)||l(e.value)&&P(e.value,this.key)&&t.push(new A(this.key,e.location.concat(`${_}${this.key}`),e.root)),t}*lazyResolve(e){!p(e.value)&&l(e.value)&&P(e.value,this.key)&&(yield new A(this.key,e.location.concat(`${_}${this.key}`),e.root))}toString(){return`~'${this.key.replaceAll("'","\\'")}'`}}class Be extends Le{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new A(n,e.location.concat(`${_}${n}`),e.root));return t}*lazyResolve(e){if(l(e.value)&&!p(e.value)&&!h(e.value))for(const[t,n]of this.environment.entries(e.value))yield new A(t,e.location.concat(`${_}${t}`),e.root)}toString(){return"~"}}class Ye extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new A(n,e.location.concat(`${_}${n}`),e.root))}return t}*lazyResolve(e){if(!(e.value instanceof String||h(e.value))&&l(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new A(t,e.location.concat(`${_}${t}`),e.root))}}toString(){return`~?${this.expression.toString()}`}}const qe=new Map([[ue.AND,5],[ue.EQ,6],[ue.GE,6],[ue.GT,6],[ue.LE,6],[ue.LT,6],[ue.NE,6],[ue.NOT,7],[ue.OR,4],[ue.RPAREN,1]]),Xe=new Map([[ue.AND,"&&"],[ue.EQ,"=="],[ue.GE,">="],[ue.GT,">"],[ue.LE,"<="],[ue.LT,"<"],[ue.NE,"!="],[ue.OR,"||"]]),Ze=new Set(["==",">=",">","<=","<","!="]);class He{constructor(e){this.environment=e,this.tokenMap=new Map([[ue.FALSE,this.parseBoolean],[ue.NUMBER,this.parseNumber],[ue.LPAREN,this.parseGroupedExpression],[ue.NOT,this.parsePrefixExpression],[ue.NULL,this.parseNull],[ue.ROOT,this.parseRootQuery],[ue.CURRENT,this.parseRelativeQuery],[ue.SINGLE_QUOTE_STRING,this.parseString],[ue.DOUBLE_QUOTE_STRING,this.parseString],[ue.TRUE,this.parseBoolean],[ue.FUNCTION,this.parseFunction],[ue.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===ue.ROOT&&e.next();const t=this.parseQuery(e);if(e.current.kind!==ue.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parseQuery(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];e:for(;;){switch(e.current.kind){case ue.DDOT:{const t=e.next(),r=this.parseSelectors(e);n.push(new De(this.environment,t,r));break}case ue.LBRACKET:case ue.KEY:case ue.KEYS:case ue.NAME:case ue.WILD:{const t=e.current,r=this.parseSelectors(e);n.push(new Je(this.environment,t,r));break}default:t&&e.backup();break e}e.next()}return n}parseSelectors(e){switch(e.current.kind){case ue.NAME:return[new Ce(this.environment,e.current,e.current.value)];case ue.WILD:return[new Me(this.environment,e.current)];case ue.KEY:return[new We(this.environment,e.current,e.current.value)];case ue.KEYS:return[new Be(this.environment,e.current)];case ue.LBRACKET:return this.parseBracketedSelection(e);default:return[]}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new Ke(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===ue.INDEX){if(e.value.length>1&&e.value.startsWith("0")||e.value.startsWith("-0"))throw new a("leading zero in index selector",e);return!0}return!1}return r(e.current)?(n.push(Number(e.current.value)),e.next(),e.expect(ue.COLON),e.next()):(n.push(void 0),e.expect(ue.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===ue.COLON&&e.next()):e.current.kind===ue.COLON&&(n.push(void 0),e.expect(ue.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Fe(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==ue.RBRACKET;){switch(e.current.kind){case ue.SINGLE_QUOTE_STRING:case ue.DOUBLE_QUOTE_STRING:n.push(new Ce(this.environment,e.current,this.decodeString(e.current)));break;case ue.FILTER:n.push(this.parseFilter(e));break;case ue.INDEX:e.peek.kind===ue.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case ue.COLON:n.push(this.parseSlice(e));break;case ue.WILD:n.push(new Me(this.environment,e.current));break;case ue.KEY_SINGLE_QUOTE_STRING:case ue.KEY_DOUBLE_QUOTE_STRING:n.push(new We(this.environment,e.current,this.decodeString(e.current)));break;case ue.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case ue.KEYS:n.push(new Be(this.environment,e.current));break;case ue.EOF:throw new a("unexpected end of query",e.current);default:throw new a(`unexpected token in bracketed selection '${e.current.kind}'`,e.current)}e.peek.kind!==ue.RBRACKET&&(e.expectPeek(ue.COMMA),e.next(),e.expectPeekNot(ue.RBRACKET,"unexpected trailing comma")),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return n}parseFilter(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof V){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return this.throwForLiteral(r),t?new Ye(this.environment,n,new J(n,r)):new je(this.environment,n,new J(n,r))}parseBoolean(e){return e.current.kind===ue.FALSE?new F(e.current,!1):new F(e.current,!0)}parseNull(e){return new K(e.current)}parseString(e){return new M(e.current,this.decodeString(e.current))}parseNumber(e){const t=e.current.value;if(t.startsWith("0")&&t.length>1)throw new a(`invalid number literal '${t}'`,e.current);const n=Number(e.current.value);if(isNaN(n))throw new a(`invalid number literal '${t}'`,e.current);return new j(e.current,n)}parsePrefixExpression(e){return e.expect(ue.NOT),e.next(),new U(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=qe.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=Xe.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Ze.has(o)?(this.throwForNonComparable(t),this.throwForNonComparable(s)):(this.throwForLiteral(t),this.throwForLiteral(s)),new z(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===ue.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==ue.RPAREN;){if(e.current.kind===ue.EOF)throw new a("unbalanced parentheses",e.current);if(!Xe.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(ue.RPAREN),t}parseRootQuery(e){const t=e.next();return new Q(t,new Qe(this.environment,this.parseQuery(e,!0)))}parseRelativeQuery(e){const t=e.next();return new G(t,new Qe(this.environment,this.parseQuery(e,!0)))}parseCurrentKey(e){return new Ve(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==ue.RPAREN;){const n=this.tokenMap.get(e.current.kind);if(!n)throw new a(`unexpected '${e.current.value}'`,e.current);let r=n.bind(this)(e),s=e.peek.kind;for(;Xe.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==ue.RPAREN){if(e.peek.kind===ue.RBRACKET)break;e.expectPeek(ue.COMMA),e.next()}e.next()}return e.expect(ue.RPAREN),new V(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case ue.EOF:case ue.RBRACKET:t="end of expression";break;default:t=`'${e.current.value}'`}throw new a(`unexpected ${t}`,e.current)}let r=n.bind(this)(e);for(;;){const n=e.peek.kind;if(n===ue.EOF||n===ue.RBRACKET||(qe.get(n)||1)<t)break;if(!Xe.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){return this.unescapeString(e.kind===ue.SINGLE_QUOTE_STRING?e.value.replaceAll('"','\\"').replaceAll("\\'","'"):e.value,e)}unescapeString(e,t){const n=[],r=e.length;let s,o=0;for(;o<r;){const r=e[o];if("\\"===r)switch(o+=1,e[o]){case'"':n.push('"');break;case"\\":n.push("\\");break;case"/":n.push("/");break;case"b":n.push("\b");break;case"f":n.push("\f");break;case"n":n.push("\n");break;case"r":n.push("\r");break;case"t":n.push("\t");break;case"u":[s,o]=this.decodeHexChar(e,o,t),n.push(this.stringFromCodePoint(s,t));break;default:throw new a("unknown escape sequence at index "+(t.index+o-1),t)}else this.stringFromCodePoint(r.codePointAt(0),t),n.push(r);o+=1}return n.join("")}decodeHexChar(e,t,n){const r=e.length;if(t+4>=r)throw new a("incomplete escape sequence at index "+(n.index+t-1),n);t+=1;let s=this.parseHexDigits(e.slice(t,t+4),n);if(et(s))throw new a("unexpected low surrogate codepoint at index "+(n.index+t-2),n);if(function(e){return e>=55296&&e<=56319}(s)){if(!(t+9<r&&"\\"===e[t+4]&&"u"===e[t+5]))throw new a("incomplete escape sequence at index "+(n.index+t-2),n);const o=this.parseHexDigits(e.slice(t+6,t+10),n);if(!et(o))throw new a(`unexpected codepoint at index ${n.index+t+4}`,n);return s=65536+((1023&s)<<10|1023&o),[s,t+9]}return[s,t+3]}parseHexDigits(e,t){const n=new TextEncoder;let r=0;for(const s of n.encode(e))switch(r<<=4,s){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:r|=s-48;break;case 97:case 98:case 99:case 100:case 101:case 102:r|=s-97+10;break;case 65:case 66:case 67:case 68:case 69:case 70:r|=s-65+10;break;default:throw new a("invalid \\uXXXX escape sequence",t)}return r}stringFromCodePoint(e,t){if(void 0===e||e<=31)throw new a("invalid character",t);try{return String.fromCodePoint(e)}catch{throw new a("invalid escape sequence",t)}}throwForNonComparable(e){if((e instanceof Q||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof V){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof C)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}function et(e){return e>=56320&&e<=57343}class tt{functionRegister=(()=>new Map)();constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??1-Math.pow(2,53),this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new He(this),this.setupFilterFunctions()}compile(e){return new Qe(this,this.parser.parse(new le(ye(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new Z),this.functionRegister.set("length",new H),this.functionRegister.set("search",new ae),this.functionRegister.set("match",new ie),this.functionRegister.set("value",new ce)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case g.ValueType:if(!(o instanceof C||o instanceof Ve||o instanceof D&&o.path.singularQuery()||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case g.LogicalType:if(!(o instanceof D||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof D||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var nt=Object.freeze({__proto__:null,Count:Z,FunctionExpressionType:g,Length:H,Match:ie,Search:ae,Value:ce});const rt=new tt;function st(e,t){return rt.query(e,t)}function ot(e,t){return rt.lazyQuery(e,t)}function it(e){return rt.compile(e)}var at=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:rt,FunctionExpressionType:g,JSONPathEnvironment:tt,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:A,JSONPathNodeList:I,JSONPathQuery:Qe,JSONPathRecursionLimitError:c,JSONPathSegment:ze,JSONPathSelector:Le,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:_,Nothing:b,Token:he,TokenKind:ue,compile:it,expressions:X,functions:nt,lazyQuery:ot,match:function(e,t){return rt.match(e,t)},query:st,selectors:Ue});class ct extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class ut extends ct{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class ht{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n))if(r===k){if("-"!==s)throw new ct(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!l(n))throw new ct(`unexpected operation on '${typeof n}' (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class lt{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)throw new ct(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new ct(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!l(n))throw new ct(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new ct(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class pt{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new ct(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!l(n))throw new ct(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new ct(`can't replace nonexistent property (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ft{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new ct(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new ct(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);h(n)?n.splice(Number(s),1):l(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===k)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(o))"-"===a?o.push(r):o.splice(Number(a),0,r);else{if(!l(o))throw new ct(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);o[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class dt{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new ct(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===k)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new ct(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(s))"-"===o?s.push(this.deepCopy(r)):s.splice(Number(o),0,this.deepCopy(r));else{if(!l(s))throw new ct(`unexpected operation on '${typeof s}' (${this.name}:${t})`);s[o]=this.deepCopy(r)}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class gt{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!d(r,this.value))throw new ut(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class mt{ops=[];constructor(e){e&&this.build(e)}*[Symbol.iterator](){for(const e of this.ops)yield e.toObject()}add(e,t){return this.ops.push(new ht(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new lt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new pt(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new ft(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new dt(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new gt(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof v)throw new ct(`${t.message} (${n.name}:${e})`);throw t}}return t}toArray(){return this.ops.map((e=>e.toObject()))}build(e){for(let t=0;t<e.length;t++){const n=e[t];switch(n.op){case"add":this.add(this.opPointer(n,"path","add",t),this.opValue(n,"value","add",t));break;case"remove":this.remove(this.opPointer(n,"path","remove",t));break;case"replace":this.replace(this.opPointer(n,"path","replace",t),this.opValue(n,"value","replace",t));break;case"move":this.move(this.opPointer(n,"from","move",t),this.opPointer(n,"path","move",t));break;case"copy":this.copy(this.opPointer(n,"from","copy",t),this.opPointer(n,"path","copy",t));break;case"test":this.test(this.opPointer(n,"path","test",t),this.opValue(n,"value","test",t));break;default:throw new ct(`expected 'op' to be one of 'add', 'remove', 'replace', 'move', 'copy' or 'test' (${n.op}:${t})`)}}}opPointer(e,t,n,r){if(!Object.hasOwn(e,t))throw new ct(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new ct(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new O(s)}catch(e){if(e instanceof m)throw new ct(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new ct(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!p(e))throw new ct(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new ct(`${e.message} (${t}:${n})`);throw e}}}function vt(e,t){return new mt(e).apply(t)}var wt=Object.freeze({__proto__:null,JSONPatch:mt,JSONPatchError:ct,JSONPatchTestFailure:ut,apply:vt});return e.DEFAULT_ENVIRONMENT=rt,e.FunctionExpressionType=g,e.JSONPatch=mt,e.JSONPatchError=ct,e.JSONPatchTestFailure=ut,e.JSONPathEnvironment=tt,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=A,e.JSONPathNodeList=I,e.JSONPathQuery=Qe,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=b,e.RelativeJSONPointer=T,e.Token=he,e.TokenKind=ue,e.UNDEFINED=k,e.apply=vt,e.compile=it,e.jsonpatch=wt,e.jsonpath=at,e.jsonpointer=$,e.lazyQuery=ot,e.query=st,e.resolve=R,e.version="2.0.0",e}({});
1
+ var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class c extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}class u extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function h(e){return Array.isArray(e)}function l(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function p(e){return"string"==typeof e}function f(e){return"number"==typeof e}function d(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}return!1}if(l(e)&&l(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!d(e[r],t[r]))return!1;return!0}return!1}let g=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class m extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class w extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class y extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class E extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const k=Symbol.for("jsonpointer.undefined");class O{#e;constructor(e){this.tokens=this.parse(e),this.#e=O.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==k)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[k,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof w||e instanceof x)return[t,k];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every(((t,n)=>t===e.tokens[n]))}parse(e){if(e.length&&!e.startsWith("/"))throw new y(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(S.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(l(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new x(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new E(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(e))throw new E("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new O(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new O(O.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new O(O.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,S=/(0|[1-9][0-9]*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new O(e):e;if(this.origin>t.tokens.length)throw new w(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new w(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof O?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new O(O.encode(n))}parse(e){const t=N.exec(e);if(!t||!t.groups)throw new y("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new y("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new O(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new y("unexpected leading zero");if(S.test(e))return Number(e);throw new y(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||S.test(e)}}function R(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:k;return new O(e).resolve(t,n)}var $=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:x,JSONPointerResolutionError:v,JSONPointerSyntaxError:y,JSONPointerTypeError:E,RelativeJSONPointer:T,UNDEFINED:k,resolve:R});const b=/^[\p{ID_Start}_]\p{ID_Continue}*$/u;function P(e){return e.includes("'")&&!e.includes('"')?JSON.stringify(e):_(e)}function _(e){return`'${JSON.stringify(e).slice(1,-1).replaceAll('\\"','"').replaceAll("'","\\'")}'`}function A(e){return b.test(e)?e:null}const I=Symbol.for("jsonpath.nothing");function L(e,t){return l(e)&&Object.hasOwn(e,t)}const C="",K={form:"pretty"};class F{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return this.getPath({form:"canonical"})}getPath(e){const t={...K,...e};return"$"+this.location.map((e=>p(e)?this.decodeNameLocation(e,t):`[${e}]`)).join("")}toPointer(){return this.location.length?new O(O.encode(this.location.map(String))):new O("")}decodeNameLocation(e,t){const n="canonical"===t.form,r=n?_:P,s=e.startsWith(C);s&&(e=e.slice(1));const o=A(e);return s?n||null==o?`[~${r(e)}]`:`.~${o}`:n||null==o?`[${r(e)}]`:`.${o}`}}class M{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map((e=>e.value))}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map((e=>e.value))}locations(){return this.nodes.map((e=>e.location))}paths(e){return this.nodes.map((t=>t.getPath(e)))}pointers(){return this.nodes.map((e=>e.toPointer()))}get length(){return this.nodes.length}}class j{constructor(e){this.token=e}}class U extends j{}class z extends U{evaluate(){return null}toString(){return"null"}}class D extends U{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class J extends U{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return _(this.value)}}class G extends U{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class Q extends j{constructor(e,t,n){super(e),this.token=e,this.operator=t,this.right=n}evaluate(e){if("!"===this.operator){const t=this.right.evaluate(e);return t instanceof M?0===t.nodes.length:!Z(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(e){return`${this.operator}${this.right.toString(e)}`}}class V extends j{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r,this.logical="&&"===n||"||"===n}evaluate(e){let t=this.left.evaluate(e);!this.logical&&t instanceof M&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof M&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?Z(t)&&Z(n):"||"===this.operator?Z(t)||Z(n):H(t,this.operator,n)}toString(e){return this.logical?`(${this.left.toString(e)} ${this.operator} ${this.right.toString(e)})`:`${this.left.toString(e)} ${this.operator} ${this.right.toString(e)}`}}class W extends j{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof M?t.nodes.length>0:Z(t)}toString(e){return function t(n,r){if(n instanceof V){let s,o,i,a;if("&&"===n.operator)s=5,o="&&",i=t(n.left,s),a=t(n.right,s);else{if("||"!==n.operator)return n.toString(e);s=4,o="||",i=t(n.left,s),a=t(n.right,s)}const c=`${i} ${o} ${a}`;return s<r?`(${c})`:c}if(n instanceof Q){const e=`!${t(n.right,7)}`;return r>7?`(${e})`:e}return n.toString(e)}(this.expression,0)}}class B extends j{constructor(e,t){super(e),this.token=e,this.path=t}}class Y extends B{evaluate(e){return e.lazy?new M(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(e){return`@${this.path.toString(e).slice(1)}`}}class q extends B{evaluate(e){return e.lazy?new M(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(e){return this.path.toString(e)}}class X extends j{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof M?this.unpack_node_list(e):e));return t.call(...n)}toString(e){return`${this.name}(${this.args.map((t=>t.toString(e))).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return I;case 1:return e.nodes[0].value;default:return e}}}function Z(e){return!(e instanceof M&&e.empty())&&!("boolean"==typeof e&&!1===e)}function H(e,t,n){switch(t){case"==":return ee(e,n);case"!=":return!ee(e,n);case"<":return te(e,n);case">":return te(n,e);case">=":return te(n,e)||ee(e,n);case"<=":return te(e,n)||ee(e,n);default:return!1}}function ee(e,t){if(t instanceof M&&([e,t]=[t,e]),e instanceof M){if(t instanceof M){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===I:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===I&&t===I||d(e,t)}function te(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var ne=Object.freeze({__proto__:null,BooleanLiteral:D,FilterExpression:j,FilterExpressionLiteral:U,FilterQuery:B,FunctionExtension:X,InfixExpression:V,LogicalExpression:W,NullLiteral:z,NumberLiteral:G,PrefixExpression:Q,RelativeQuery:Y,RootQuery:q,StringLiteral:J,compare:H});class re{argTypes=(()=>[g.NodesType])();returnType=(()=>g.ValueType)();call(e){return e.length}}class se{argTypes=(()=>[g.ValueType])();returnType=(()=>g.ValueType)();call(e){return h(e)||p(e)?e.length:l(e)?Object.keys(e).length:I}}class oe extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){if(this.has(e))this.delete(e);else if(this.size>=this.maxSize){const e=this.first();void 0!==e&&this.delete(e)}return super.set(e,t)}first(){return this.keys().next().value}}function ie(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ae(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ae.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function ce(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ae,Error),ae.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,i=this.location.source+":"+o.line+":"+o.column;if(r){var a=this.location.end,c=ce("",o.line.toString().length," "),u=r[s.line-1],h=(s.line===a.line?a.column:u.length+1)-s.column||1;t+="\n --\x3e "+i+"\n"+c+" |\n"+o.line+" | "+u+"\n"+c+" | "+ce("",s.column-1," ")+ce("",h,"^")}else t+="\n at "+i}return t},ae.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(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"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function o(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"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(i);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const ue={StartRules:["start"],SyntaxError:ae,parse:function(e,t){var n,r,s,o,i={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ae},u=Ae,h="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",x="^",y="-",E="]",k="\\p{",O="\\P{",N="L",S="M",T="N",R="P",$="Z",b="S",P="C",_=/^[*-+?]/,A=/^[0-9]/,I=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,M=/^[lps]/,j=/^[ckmo]/,U=/^[cfn-o]/,z=Re("|",!1),D=$e([["*","+"],"?"],!1,!1),J=Re("{",!1),G=$e([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),W=Re("(",!1),B=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=$e([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),ne=Re("]",!1),re=Re("\\p{",!1),se=Re("\\P{",!1),oe=Re("L",!1),ie=$e([["l","m"],"o",["t","u"]],!1,!1),ce=Re("M",!1),ue=$e(["c","e","n"],!1,!1),he=Re("N",!1),le=$e(["d","l","o"],!1,!1),pe=Re("P",!1),fe=$e([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=$e(["l","p","s"],!1,!1),me=Re("S",!1),ve=$e(["c","k","m","o"],!1,!1),we=Re("C",!1),xe=$e(["c","f",["n","o"]],!1,!1),ye=function(e){return function(e){return e<"'"||","===e||"-"===e||e>="/"&&e<=">"||e>="@"&&e<="Z"||e>="^"&&e<="z"||e>="~"&&e<="퟿"||e>=""}(e)},Ee=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},ke=0|t.peg$currPos,Oe=[{line:1,column:1}],Ne=ke,Se=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function be(t){var n,r=Oe[t];if(r)return r;if(t>=Oe.length)n=Oe.length-1;else for(n=t;!Oe[--n];);for(r={line:(r=Oe[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return Oe[t]=r,r}function Pe(e,t,n){var r=be(e),s=be(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function _e(e){ke<Ne||(ke>Ne&&(Ne=ke,Se=[]),Se.push(e))}function Ae(){return Ie()}function Ie(){var t,n,r,s;for(t=Le(),n=[],r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);r!==i;)n.push(r),r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);return t=[t,n]}function Le(){var e,t;for(e=[],t=Ce();t!==i;)e.push(t),t=Ce();return e}function Ce(){var t,n,r;return t=ke,n=function(){var t,n,r,s;t=function(){var t,n;t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y));n!==i&&(ye(n)?void 0:i)!==i?t=n:(ke=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(ke)?(t=m,ke++):(t=i,0===Te&&_e(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=ke,91===e.charCodeAt(ke)?(n=w,ke++):(n=i,0===Te&&_e(H));if(n!==i)if(94===e.charCodeAt(ke)?(r=x,ke++):(r=i,0===Te&&_e(ee)),r===i&&(r=null),45===e.charCodeAt(ke)?(s=y,ke++):(s=i,0===Te&&_e(te)),s===i&&(s=Me()),s!==i){for(o=[],a=Me();a!==i;)o.push(a),a=Me();45===e.charCodeAt(ke)?(a=y,ke++):(a=i,0===Te&&_e(te)),a===i&&(a=null),93===e.charCodeAt(ke)?(c=E,ke++):(c=i,0===Te&&_e(ne)),c!==i?t=n=[n,r,s,o,a,c]:(ke=t,t=i)}else ke=t,t=i;else ke=t,t=i;return t}());return t}(),t===i&&(t=ke,40===e.charCodeAt(ke)?(n=d,ke++):(n=i,0===Te&&_e(W)),n!==i&&(r=Ie())!==i?(41===e.charCodeAt(ke)?(s=g,ke++):(s=i,0===Te&&_e(B)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(ke),_.test(t)?ke++:(t=i,0===Te&&_e(D));t===i&&(t=function(){var t,n,r,s,o,a;t=ke,123===e.charCodeAt(ke)?(n=l,ke++):(n=i,0===Te&&_e(J));n!==i?(r=e.charAt(ke),A.test(r)?ke++:(r=i,0===Te&&_e(G)),r!==i?(s=ke,44===e.charCodeAt(ke)?(o=p,ke++):(o=i,0===Te&&_e(Q)),o!==i?(a=e.charAt(ke),A.test(a)?ke++:(a=i,0===Te&&_e(G)),a===i&&(a=null),s=o=[o,a]):(ke=s,s=i),s===i&&(s=null),125===e.charCodeAt(ke)?(o=f,ke++):(o=i,0===Te&&_e(V)),o!==i?t=n=[n,r,s,o]:(ke=t,t=i)):(ke=t,t=i)):(ke=t,t=i);return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t}function Ke(){var t,n,r;return t=ke,92===e.charCodeAt(ke)?(n=v,ke++):(n=i,0===Te&&_e(X)),n!==i?(r=e.charAt(ke),I.test(r)?ke++:(r=i,0===Te&&_e(Z)),r!==i?t=n=[n,r]:(ke=t,t=i)):(ke=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===k?(n=k,ke+=3):(n=i,0===Te&&_e(re));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===O?(n=O,ke+=3):(n=i,0===Te&&_e(se));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}()),t}function Me(){var t,n,r,s,o;return t=ke,(n=je())!==i?(r=ke,45===e.charCodeAt(ke)?(s=y,ke++):(s=i,0===Te&&_e(te)),s!==i&&(o=je())!==i?r=s=[s,o]:(ke=r,r=i),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t===i&&(t=Fe()),t}function je(){var t,n;return t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y)),n!==i&&(Ee(n)?void 0:i)!==i?t=n:(ke=t,t=i),t===i&&(t=Ke()),t}function Ue(){var t;return(t=function(){var t,n,r;t=ke,76===e.charCodeAt(ke)?(n=N,ke++):(n=i,0===Te&&_e(oe));n!==i?(r=e.charAt(ke),L.test(r)?ke++:(r=i,0===Te&&_e(ie)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,77===e.charCodeAt(ke)?(n=S,ke++):(n=i,0===Te&&_e(ce));n!==i?(r=e.charAt(ke),C.test(r)?ke++:(r=i,0===Te&&_e(ue)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,78===e.charCodeAt(ke)?(n=T,ke++):(n=i,0===Te&&_e(he));n!==i?(r=e.charAt(ke),K.test(r)?ke++:(r=i,0===Te&&_e(le)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,80===e.charCodeAt(ke)?(n=R,ke++):(n=i,0===Te&&_e(pe));n!==i?(r=e.charAt(ke),F.test(r)?ke++:(r=i,0===Te&&_e(fe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,90===e.charCodeAt(ke)?(n=$,ke++):(n=i,0===Te&&_e(de));n!==i?(r=e.charAt(ke),M.test(r)?ke++:(r=i,0===Te&&_e(ge)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,83===e.charCodeAt(ke)?(n=b,ke++):(n=i,0===Te&&_e(me));n!==i?(r=e.charAt(ke),j.test(r)?ke++:(r=i,0===Te&&_e(ve)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,67===e.charCodeAt(ke)?(n=P,ke++):(n=i,0===Te&&_e(we));n!==i?(r=e.charAt(ke),U.test(r)?ke++:(r=i,0===Te&&_e(xe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}()),t}if(n=u(),t.peg$library)return{peg$result:n,peg$currPos:ke,peg$FAILED:i,peg$maxFailExpected:Se,peg$maxFailPos:Ne};if(n!==i&&ke===e.length)return n;throw n!==i&&ke<e.length&&_e({type:"end"}),r=Se,s=Ne<e.length?e.charAt(Ne):null,o=Ne<e.length?Pe(Ne,Ne+1):Pe(Ne,Ne),new ae(ae.buildMessage(r,s),r,s,o)}};var he=function(e){try{ue.parse(e,{})}catch(e){if(e instanceof ue.SyntaxError)return!1;throw e}return!0};class le{argTypes=(()=>[g.ValueType,g.ValueType])();returnType=(()=>g.LogicalType)();#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new oe(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!he(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(ie(e)),n||r||t.push(")$"),t.join("")}}class pe{argTypes=(()=>[g.ValueType,g.ValueType])();returnType=(()=>g.LogicalType)();#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new oe(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!he(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(ie(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class fe{argTypes=(()=>[g.NodesType])();returnType=(()=>g.ValueType)();call(e){return 1===e.length?e.nodes[0].value:I}}let de=function(e){return e.AND="TOKEN_AND",e.COLON="TOKEN_COLON",e.COMMA="TOKEN_COMMA",e.CURRENT="TOKEN_CURRENT_VALUE",e.CURRENT_KEY="TOKEN_CURRENT_KEY",e.DDOT="TOKEN_DDOT",e.DOT="TOKEN_DOT",e.DOUBLE_QUOTE_STRING="TOKEN_DOUBLE_QUOTE_STRING",e.EOF="TOKEN_EOF",e.EQ="TOKEN_EQ",e.ERROR="TOKEN_ERROR",e.FALSE="TOKEN_FALSE",e.FILTER="TOKEN_FILTER_START",e.FUNCTION="TOKEN_FUNCTION",e.GE="TOKEN_GE",e.GT="TOKEN_GT",e.INDEX="TOKEN_INDEX",e.KEY="TOKEN_KEY",e.KEY_DOUBLE_QUOTE_STRING="TOKEN_KEY_DOUBLE_QUOTE_STRING",e.KEY_SINGLE_QUOTE_STRING="TOKEN_KEY_SINGLE_QUOTE_STRING",e.KEYS="TOKEN_KEYS",e.KEYS_FILTER="TOKEN_KEYS_FILTER",e.LBRACKET="TOKEN_LBRACKET",e.LE="TOKEN_LE",e.LG="TOKEN_LG",e.LPAREN="TOKEN_LPAREN",e.LT="TOKEN_LT",e.NAME="TOKEN_NAME",e.NE="TOKEN_NE",e.NOT="TOKEN_NOT",e.NULL="TOKEN_NULL",e.NUMBER="NUMBER",e.OR="TOKEN_OR",e.RBRACKET="TOKEN_RBRACKET",e.ROOT="TOKEN_ROOT",e.RPAREN="TOKEN_RPAREN",e.SINGLE_QUOTE_STRING="TOKEN_SINGLE_QUOTE_STRING",e.TRUE="TOKEN_TRUE",e.WILD="TOKEN_WILD",e}({});class ge{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new ge(de.EOF,"",-1,"");class me{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}expectPeekNot(e,t){const n=this.peek;if(n.kind===e)throw new a(t,n)}}const ve=/[eE][+-]?\d+/y,we=/[a-z][a-z_0-9]*/y,xe=/-?\d+/y,ye=/-?[0-9]+/y,Ee=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ke=new Set([" ","\n","\t","\r"]),Oe=/[\u0080-\uFFFFa-zA-Z_]/;class Ne{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e,t){this.environment=e,this.path=t}get pos(){return this.#n}get start(){return this.#r}run(){let e=Te;for(;e;)e=e(this)}emit(e){this.tokens.push(new ge(e,this.path.slice(this.#r,this.#n),this.#r,this.path)),this.#r=this.#n}next(){if(this.#n>=this.path.length)return"";const e=this.path[this.#n];return this.#n+=1,e}ignore(){this.#r=this.#n}backup(){if(this.#n<=this.#r){const e="can't backup beyond start";throw new r(e,new ge(de.ERROR,e,this.#n,this.path))}this.#n-=1}peek(){const e=this.next();return e&&this.backup(),e}peekMatch(e){const t=this.next();return t&&this.backup(),e.test(t)}accept(e){const t=this.next();return!!e.has(t)||(t&&this.backup(),!1)}acceptMatch(e){const t=this.next();return!!e.test(t)||(t&&this.backup(),!1)}acceptRun(e){let t=!1,n=this.next();for(;e.has(n);)n=this.next(),t=!0;return n&&this.backup(),t}acceptMatchRun(e){e.lastIndex=this.#n;const t=e.exec(this.path);return e.lastIndex=0,!!t&&(this.#n+=t[0].length,!0)}ignoreWhitespace(){if(this.#n!==this.#r){const e=`must emit or ignore before consuming whitespace ('${this.path.slice(this.#r,this.#n)}':${this.pos})`;throw new r(e,new ge(de.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ke)&&(this.ignore(),!0)}error(e){this.tokens.push(new ge(de.ERROR,e,this.#n,this.path))}}function Se(e,t){const[n,r]=function(e,t){const n=new Ne(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===de.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function Te(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(de.ROOT),Re)}function Re(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(de.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(de.DDOT),$e):be;case"[":return e.emit(de.LBRACKET),Pe;default:return e.backup(),e.filterLevel?_e:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function $e(e){if(e.acceptMatchRun(Ee))return e.emit(de.NAME),Re;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(Oe)?(e.ignore(),e.acceptMatchRun(Ee),e.emit(de.KEY),Re):(e.emit(de.KEYS),Re);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(de.KEYS),Re}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(de.WILD),Re;case"[":return e.emit(de.LBRACKET),Pe;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function be(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(Oe)?(e.ignore(),e.acceptMatchRun(Ee),e.emit(de.KEY),Re):(e.emit(de.KEYS),Re);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(de.KEYS),Re}if(e.acceptMatchRun(Ee))return e.emit(de.NAME),Re;const t=e.next();return"*"===t?(e.emit(de.WILD),Re):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Pe(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(xe)){e.emit(de.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Fe(e);case'"':return e.ignore(),e.next(),Me(e);case"?":return e.next(),e.emit(de.KEYS_FILTER),e.filterLevel+=1,_e;default:e.emit(de.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(de.RBRACKET),e.filterLevel?_e:Re;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(de.WILD);continue;case"?":return e.emit(de.FILTER),e.filterLevel+=1,_e;case",":e.emit(de.COMMA);continue;case":":e.emit(de.COLON);continue;case"'":return Ie;case'"':return Le;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function _e(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),Pe);case",":if(e.emit(de.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Pe;case"'":return Ce;case'"':return Ke;case"(":e.emit(de.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(de.RPAREN),e.parenStack.length&&(1===e.parenStack[e.parenStack.length-1]?e.parenStack.pop():e.parenStack[e.parenStack.length-1]-=1);continue;case"$":return e.emit(de.ROOT),Re;case"@":return e.emit(de.CURRENT),Re;case"#":return e.emit(de.CURRENT_KEY),Re;case".":return e.backup(),Re;case"!":"="===e.peek()?(e.next(),e.emit(de.NE)):e.emit(de.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(de.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(de.LE)):e.emit(de.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(de.GE)):e.emit(de.GT);continue;default:if(e.backup(),e.acceptMatchRun(ye)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ye)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(ve),e.emit(de.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(de.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(de.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(de.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(de.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(de.NULL);continue}if(e.acceptMatchRun(we)&&"("===e.peek()){e.parenStack.push(1),e.emit(de.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Ae(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?de.SINGLE_QUOTE_STRING:de.DOUBLE_QUOTE_STRING),r.next(),r.ignore(),t;for(;;){const s=r.path.slice(r.pos,r.pos+2),o=r.next();if("\\\\"!==s&&s!==`\\${e}`){if("\\"===o&&!s.match(/\\[bfnrtu/]/))return r.error("invalid escape"),null;if(!o)return r.error(`unclosed string starting at index ${r.start}`),null;if(o===e)return r.backup(),r.emit(n),r.next(),r.ignore(),t}else r.next()}}}const Ie=Ae("'",Pe,de.SINGLE_QUOTE_STRING),Le=Ae('"',Pe,de.DOUBLE_QUOTE_STRING),Ce=Ae("'",_e,de.SINGLE_QUOTE_STRING),Ke=Ae('"',_e,de.DOUBLE_QUOTE_STRING),Fe=Ae("'",Pe,de.KEY_SINGLE_QUOTE_STRING),Me=Ae('"',Pe,de.KEY_DOUBLE_QUOTE_STRING);class je{constructor(e,t){this.environment=e,this.token=t}}class Ue extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.name=n}resolve(e){const t=[];return!h(e.value)&&L(e.value,this.name)&&t.push(new F(e.value[this.name],e.location.concat(this.name),e.root)),t}*lazyResolve(e){!h(e.value)&&L(e.value,this.name)&&(yield new F(e.value[this.name],e.location.concat(this.name),e.root))}toString(e){const{form:t}={...K,...e};return"canonical"===t?_(this.name):P(this.name)}shorthand(){return A(this.name)}}class ze extends je{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];if(h(e.value)){const n=this.normalizedIndex(e.value.length);n in e.value&&t.push(new F(e.value[n],e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value)){const t=this.normalizedIndex(e.value.length);t in e.value&&(yield new F(e.value[t],e.location.concat(t),e.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class De extends je{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];if(!h(e.value))return t;for(const[n,r]of this.slice(e.value,this.start,this.stop,this.step))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(const[t,n]of this.lazySlice(e.value,this.start,this.stop,this.step))yield new F(n,e.location.concat(t),e.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(const e of t)if(void 0!==e&&(e<this.environment.minIntIndex||e>this.environment.maxIntIndex))throw new o("index out of range",this.token)}slice(e,t,n,r){if(!e.length)return[];if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),0===r)return[];r||(r=1);const s=[];if(r>0)for(let o=t;o<n;o+=r)s.push([o,e[o]]);else for(let o=t;o>n;o+=r)s.push([o,e[o]]);return s}*lazySlice(e,t,n,r){if(e.length)if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),void 0===r)for(let r=t;r<n;r+=1)yield[r,e[r]];else if(r>0)for(let s=t;s<n;s+=r)yield[s,e[s]];else if(r<0)for(let s=t;s>n;s+=r)yield[s,e[s]]}}class Je extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++)t.push(new F(e.value[n],e.location.concat(n),e.root));else if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}toString(){return"*"}}class Ge extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++){const r=e.value[n],s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++){const n=e.value[t],r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}}toString(e){return`?${this.expression.toString(e)}`}}var Qe=Object.freeze({__proto__:null,FilterSelector:Ge,IndexSelector:ze,JSONPathSelector:je,NameSelector:Ue,SliceSelector:De,WildcardSelector:Je});class Ve{constructor(e,t,n){this.environment=e,this.token=t,this.selectors=n}}class We extends Ve{resolve(e){const t=[];for(const n of e)for(const e of this.selectors)t.push(...e.resolve(n));return t}*lazyResolve(e){for(const t of e)for(const e of this.selectors)yield*e.resolve(t)}toString(e){const{form:t}={...K,...e};if("pretty"===t&&1===this.selectors.length&&this.selectors[0]instanceof Ue){const e=this.selectors[0].shorthand();if(null!=e)return`.${e}`}return`[${this.selectors.map((t=>t.toString(e))).join(", ")}]`}}class Be extends Ve{resolve(e){const t=[],n=(this.environment.nondeterministic?this.nondeterministicVisit:this.visit).bind(this);for(const r of e)for(const e of n(r))for(const n of this.selectors)t.push(...n.resolve(e));return t}*lazyResolve(e){for(const t of e)for(const e of this.visit(t))for(const t of this.selectors)yield*t.resolve(e)}toString(e){return`..[${this.selectors.map((t=>t.toString(e))).join(", ")}]`}visit(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function*(){if(n>=t.environment.maxRecursionDepth)throw new c("recursion limit reached",t.token);if(yield e,h(e.value))for(let r=0;r<e.value.length;r++){const s=new F(e.value[r],e.location.concat(r),e.root);yield*t.visit(s,n+1)}else if(l(e.value))for(const[r,s]of t.environment.entries(e.value)){const o=new F(s,e.location.concat(r),e.root);yield*t.visit(o,n+1)}}()}nondeterministicVisit(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function*(){let r=Array.from(t.nondeterministicChildren(e)).map((e=>[e,n]));for(yield e;r.length;){const[e,n]=r.shift();if(yield e,n>=t.environment.maxRecursionDepth)throw new c("recursion limit reached",t.token);const s=Math.random()<.5;for(const o of t.nondeterministicChildren(e))if(s){yield o;r=Ye(r,Array.from(t.nondeterministicChildren(o)).map((e=>[e,n+2])))}else r.push([o,n+1])}}()}*nondeterministicChildren(e){if(!p(e.value))if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}}function Ye(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map((e=>e.next().value))}class qe{constructor(e,t){this.environment=e,this.segments=t}query(e){let t=[new F(e,[],e)];for(const e of this.segments)t=e.resolve(t);return new M(t)}lazyQuery(e){let t=[new F(e,[],e)][Symbol.iterator]();for(const e of this.segments)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(e){return`$${this.segments.map((t=>t.toString(e))).join("")}`}singularQuery(){for(const e of this.segments){if(e instanceof Be)return!1;if(1!==e.selectors.length||!(e.selectors[0]instanceof Ue||e.selectors[0]instanceof ze))return!1}return!0}}class Xe extends j{evaluate(e){return e.currentKey??I}toString(){return"#"}}class Ze extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.key=n}resolve(e){const t=[];return e.value instanceof String||h(e.value)||l(e.value)&&L(e.value,this.key)&&t.push(new F(this.key,e.location.concat(`${C}${this.key}`),e.root)),t}*lazyResolve(e){!p(e.value)&&l(e.value)&&L(e.value,this.key)&&(yield new F(this.key,e.location.concat(`${C}${this.key}`),e.root))}toString(e){const{form:t}={...K,...e};return`~${("canonical"===t?_:P)(this.key)}`}}class He extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(n,e.location.concat(`${C}${n}`),e.root));return t}*lazyResolve(e){if(l(e.value)&&!p(e.value)&&!h(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(t,e.location.concat(`${C}${t}`),e.root)}toString(){return"~"}}class et extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(n,e.location.concat(`${C}${n}`),e.root))}return t}*lazyResolve(e){if(!(e.value instanceof String||h(e.value))&&l(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(t,e.location.concat(`${C}${t}`),e.root))}}toString(e){return`~?${this.expression.toString(e)}`}}const tt=new Map([[de.AND,5],[de.EQ,6],[de.GE,6],[de.GT,6],[de.LE,6],[de.LT,6],[de.NE,6],[de.NOT,7],[de.OR,4],[de.RPAREN,1]]),nt=new Map([[de.AND,"&&"],[de.EQ,"=="],[de.GE,">="],[de.GT,">"],[de.LE,"<="],[de.LT,"<"],[de.NE,"!="],[de.OR,"||"]]),rt=new Set(["==",">=",">","<=","<","!="]);class st{constructor(e){this.environment=e,this.tokenMap=new Map([[de.FALSE,this.parseBoolean],[de.NUMBER,this.parseNumber],[de.LPAREN,this.parseGroupedExpression],[de.NOT,this.parsePrefixExpression],[de.NULL,this.parseNull],[de.ROOT,this.parseRootQuery],[de.CURRENT,this.parseRelativeQuery],[de.SINGLE_QUOTE_STRING,this.parseString],[de.DOUBLE_QUOTE_STRING,this.parseString],[de.TRUE,this.parseBoolean],[de.FUNCTION,this.parseFunction],[de.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===de.ROOT&&e.next();const t=this.parseQuery(e);if(e.current.kind!==de.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parseQuery(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];e:for(;;){switch(e.current.kind){case de.DDOT:{const t=e.next(),r=this.parseSelectors(e);n.push(new Be(this.environment,t,r));break}case de.LBRACKET:case de.KEY:case de.KEYS:case de.NAME:case de.WILD:{const t=e.current,r=this.parseSelectors(e);n.push(new We(this.environment,t,r));break}default:t&&e.backup();break e}e.next()}return n}parseSelectors(e){switch(e.current.kind){case de.NAME:return[new Ue(this.environment,e.current,e.current.value)];case de.WILD:return[new Je(this.environment,e.current)];case de.KEY:return[new Ze(this.environment,e.current,e.current.value)];case de.KEYS:return[new He(this.environment,e.current)];case de.LBRACKET:return this.parseBracketedSelection(e);default:return[]}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new ze(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===de.INDEX){if(e.value.length>1&&e.value.startsWith("0")||e.value.startsWith("-0"))throw new a("leading zero in index selector",e);return!0}return!1}return r(e.current)?(n.push(Number(e.current.value)),e.next(),e.expect(de.COLON),e.next()):(n.push(void 0),e.expect(de.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===de.COLON&&e.next()):e.current.kind===de.COLON&&(n.push(void 0),e.expect(de.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new De(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==de.RBRACKET;){switch(e.current.kind){case de.SINGLE_QUOTE_STRING:case de.DOUBLE_QUOTE_STRING:n.push(new Ue(this.environment,e.current,this.decodeString(e.current)));break;case de.FILTER:n.push(this.parseFilter(e));break;case de.INDEX:e.peek.kind===de.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case de.COLON:n.push(this.parseSlice(e));break;case de.WILD:n.push(new Je(this.environment,e.current));break;case de.KEY_SINGLE_QUOTE_STRING:case de.KEY_DOUBLE_QUOTE_STRING:n.push(new Ze(this.environment,e.current,this.decodeString(e.current)));break;case de.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case de.KEYS:n.push(new He(this.environment,e.current));break;case de.EOF:throw new a("unexpected end of query",e.current);default:throw new a(`unexpected token in bracketed selection '${e.current.kind}'`,e.current)}e.peek.kind!==de.RBRACKET&&(e.expectPeek(de.COMMA),e.next(),e.expectPeekNot(de.RBRACKET,"unexpected trailing comma")),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return n}parseFilter(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof X){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return this.throwForLiteral(r),t?new et(this.environment,n,new W(n,r)):new Ge(this.environment,n,new W(n,r))}parseBoolean(e){return e.current.kind===de.FALSE?new D(e.current,!1):new D(e.current,!0)}parseNull(e){return new z(e.current)}parseString(e){return new J(e.current,this.decodeString(e.current))}parseNumber(e){const t=e.current.value;if(t.startsWith("0")&&t.length>1)throw new a(`invalid number literal '${t}'`,e.current);const n=Number(e.current.value);if(isNaN(n))throw new a(`invalid number literal '${t}'`,e.current);return new G(e.current,n)}parsePrefixExpression(e){return e.expect(de.NOT),e.next(),new Q(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=tt.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=nt.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return rt.has(o)?(this.throwForNonComparable(t),this.throwForNonComparable(s)):(this.throwForLiteral(t),this.throwForLiteral(s)),new V(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===de.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==de.RPAREN;){if(e.current.kind===de.EOF)throw new a("unbalanced parentheses",e.current);if(!nt.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(de.RPAREN),t}parseRootQuery(e){const t=e.next();return new q(t,new qe(this.environment,this.parseQuery(e,!0)))}parseRelativeQuery(e){const t=e.next();return new Y(t,new qe(this.environment,this.parseQuery(e,!0)))}parseCurrentKey(e){return new Xe(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==de.RPAREN;){const n=this.tokenMap.get(e.current.kind);if(!n)throw new a(`unexpected '${e.current.value}'`,e.current);let r=n.bind(this)(e),s=e.peek.kind;for(;nt.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==de.RPAREN){if(e.peek.kind===de.RBRACKET)break;e.expectPeek(de.COMMA),e.next()}e.next()}return e.expect(de.RPAREN),new X(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case de.EOF:case de.RBRACKET:t="end of expression";break;default:t=`'${e.current.value}'`}throw new a(`unexpected ${t}`,e.current)}let r=n.bind(this)(e);for(;;){const n=e.peek.kind;if(n===de.EOF||n===de.RBRACKET||(tt.get(n)||1)<t)break;if(!nt.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){return this.unescapeString(e.kind===de.SINGLE_QUOTE_STRING?e.value.replaceAll('"','\\"').replaceAll("\\'","'"):e.value,e)}unescapeString(e,t){const n=[],r=e.length;let s,o=0;for(;o<r;){const r=e[o];if("\\"===r)switch(o+=1,e[o]){case'"':n.push('"');break;case"\\":n.push("\\");break;case"/":n.push("/");break;case"b":n.push("\b");break;case"f":n.push("\f");break;case"n":n.push("\n");break;case"r":n.push("\r");break;case"t":n.push("\t");break;case"u":[s,o]=this.decodeHexChar(e,o,t),n.push(this.stringFromCodePoint(s,t));break;default:throw new a("unknown escape sequence at index "+(t.index+o-1),t)}else this.stringFromCodePoint(r.codePointAt(0),t),n.push(r);o+=1}return n.join("")}decodeHexChar(e,t,n){const r=e.length;if(t+4>=r)throw new a("incomplete escape sequence at index "+(n.index+t-1),n);t+=1;let s=this.parseHexDigits(e.slice(t,t+4),n);if(ot(s))throw new a("unexpected low surrogate codepoint at index "+(n.index+t-2),n);if(function(e){return e>=55296&&e<=56319}(s)){if(!(t+9<r&&"\\"===e[t+4]&&"u"===e[t+5]))throw new a("incomplete escape sequence at index "+(n.index+t-2),n);const o=this.parseHexDigits(e.slice(t+6,t+10),n);if(!ot(o))throw new a(`unexpected codepoint at index ${n.index+t+4}`,n);return s=65536+((1023&s)<<10|1023&o),[s,t+9]}return[s,t+3]}parseHexDigits(e,t){const n=new TextEncoder;let r=0;for(const s of n.encode(e))switch(r<<=4,s){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:r|=s-48;break;case 97:case 98:case 99:case 100:case 101:case 102:r|=s-97+10;break;case 65:case 66:case 67:case 68:case 69:case 70:r|=s-65+10;break;default:throw new a("invalid \\uXXXX escape sequence",t)}return r}stringFromCodePoint(e,t){if(void 0===e||e<=31)throw new a("invalid character",t);try{return String.fromCodePoint(e)}catch{throw new a("invalid escape sequence",t)}}throwForNonComparable(e){if((e instanceof q||e instanceof Y)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof X){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof U)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}function ot(e){return e>=56320&&e<=57343}class it{functionRegister=(()=>new Map)();constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??1-Math.pow(2,53),this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new st(this),this.setupFilterFunctions()}compile(e){return new qe(this,this.parser.parse(new me(Se(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new re),this.functionRegister.set("length",new se),this.functionRegister.set("search",new pe),this.functionRegister.set("match",new le),this.functionRegister.set("value",new fe)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case g.ValueType:if(!(o instanceof U||o instanceof Xe||o instanceof B&&o.path.singularQuery()||o instanceof X&&this.functionRegister.get(o.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case g.LogicalType:if(!(o instanceof B||o instanceof V))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof B||o instanceof X&&this.functionRegister.get(o.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var at=Object.freeze({__proto__:null,Count:re,FunctionExpressionType:g,Length:se,Match:le,Search:pe,Value:fe});const ct=new it;function ut(e,t){return ct.query(e,t)}function ht(e,t){return ct.lazyQuery(e,t)}function lt(e){return ct.compile(e)}var pt=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:ct,FunctionExpressionType:g,JSONPathEnvironment:it,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:F,JSONPathNodeList:M,JSONPathQuery:qe,JSONPathRecursionLimitError:c,JSONPathSegment:Ve,JSONPathSelector:je,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:C,Nothing:I,Token:ge,TokenKind:de,compile:lt,expressions:ne,functions:at,lazyQuery:ht,match:function(e,t){return ct.match(e,t)},query:ut,selectors:Qe});class ft extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class dt extends ft{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class gt{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n))if(r===k){if("-"!==s)throw new ft(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!l(n))throw new ft(`unexpected operation on '${typeof n}' (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class mt{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)throw new ft(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new ft(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!l(n))throw new ft(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new ft(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class vt{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new ft(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!l(n))throw new ft(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new ft(`can't replace nonexistent property (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class wt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new ft(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new ft(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);h(n)?n.splice(Number(s),1):l(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===k)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(o))"-"===a?o.push(r):o.splice(Number(a),0,r);else{if(!l(o))throw new ft(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);o[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class xt{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new ft(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===k)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new ft(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(s))"-"===o?s.push(this.deepCopy(r)):s.splice(Number(o),0,this.deepCopy(r));else{if(!l(s))throw new ft(`unexpected operation on '${typeof s}' (${this.name}:${t})`);s[o]=this.deepCopy(r)}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class yt{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!d(r,this.value))throw new dt(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class Et{ops=[];constructor(e){e&&this.build(e)}*[Symbol.iterator](){for(const e of this.ops)yield e.toObject()}add(e,t){return this.ops.push(new gt(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new mt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new vt(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new wt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new xt(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new yt(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof v)throw new ft(`${t.message} (${n.name}:${e})`);throw t}}return t}toArray(){return this.ops.map((e=>e.toObject()))}build(e){for(let t=0;t<e.length;t++){const n=e[t];switch(n.op){case"add":this.add(this.opPointer(n,"path","add",t),this.opValue(n,"value","add",t));break;case"remove":this.remove(this.opPointer(n,"path","remove",t));break;case"replace":this.replace(this.opPointer(n,"path","replace",t),this.opValue(n,"value","replace",t));break;case"move":this.move(this.opPointer(n,"from","move",t),this.opPointer(n,"path","move",t));break;case"copy":this.copy(this.opPointer(n,"from","copy",t),this.opPointer(n,"path","copy",t));break;case"test":this.test(this.opPointer(n,"path","test",t),this.opValue(n,"value","test",t));break;default:throw new ft(`expected 'op' to be one of 'add', 'remove', 'replace', 'move', 'copy' or 'test' (${n.op}:${t})`)}}}opPointer(e,t,n,r){if(!Object.hasOwn(e,t))throw new ft(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new ft(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new O(s)}catch(e){if(e instanceof m)throw new ft(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new ft(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!p(e))throw new ft(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new ft(`${e.message} (${t}:${n})`);throw e}}}function kt(e,t){return new Et(e).apply(t)}var Ot=Object.freeze({__proto__:null,JSONPatch:Et,JSONPatchError:ft,JSONPatchTestFailure:dt,apply:kt});return e.DEFAULT_ENVIRONMENT=ct,e.FunctionExpressionType=g,e.JSONPatch=Et,e.JSONPatchError=ft,e.JSONPatchTestFailure=dt,e.JSONPathEnvironment=it,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=F,e.JSONPathNodeList=M,e.JSONPathQuery=qe,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=I,e.RelativeJSONPointer=T,e.Token=ge,e.TokenKind=de,e.UNDEFINED=k,e.apply=kt,e.compile=lt,e.jsonpatch=Ot,e.jsonpath=pt,e.jsonpointer=$,e.lazyQuery=ht,e.query=ut,e.resolve=R,e.version="2.1.0",e}({});
2
2
  //# sourceMappingURL=json-p3.iife.min.js.map