json-p3 1.3.0 → 1.3.1
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.
- package/dist/json-p3.cjs.js +89 -7
- package/dist/json-p3.esm.js +89 -7
- package/dist/json-p3.iife.js +89 -7
- package/dist/json-p3.iife.min.js +1 -1
- package/dist/json-p3.iife.min.js.map +1 -1
- package/dist/path/functions/match.d.ts +1 -0
- package/dist/path/functions/search.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/json-p3.iife.min.js
CHANGED
|
@@ -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 h 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)}}function c(e){return Array.isArray(e)}function u(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function l(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(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(!f(e[n],t[n]))return!1;return!0}return!1}if(u(e)&&u(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!f(e[r],t[r]))return!1;return!0}return!1}let d=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 g extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class v extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class E extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=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]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof g&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,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 v||e instanceof w)return[t,x];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 E(`"${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(c(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(k.test(r)&&Object.hasOwn(e,r))return Number(r);throw new v(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new v(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(u(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new w(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!l(e))throw new y("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 g)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(l(e)?new S(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,k=/(0|[1-9][0-9]*)/;class S{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=l(e)?new O(e):e;if(this.origin>t.tokens.length)throw new v(`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 v(`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 E("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 E("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 E("unexpected leading zero");if(k.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!p(e))||k.test(e)}}function T(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new O(e).resolve(t,n)}var R=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:v,JSONPointerKeyError:w,JSONPointerResolutionError:g,JSONPointerSyntaxError:E,JSONPointerTypeError:y,RelativeJSONPointer:S,UNDEFINED:x,resolve:T});const $=Symbol.for("jsonpath.nothing");function _(e,t){return u(e)&&Object.hasOwn(e,t)}const b="";class P{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>l(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(b)?`[~'${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 K extends L{}class A extends K{evaluate(){return null}toString(){return"null"}}class M extends K{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class F extends K{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class U extends K{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class j 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:!V(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?V(t)&&V(n):"||"===this.operator?V(t)||V(n):W(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:V(t)}toString(){return this.expression.toString()}}class C extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends C{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 D extends C{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 Q 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]!==d.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 $;case 1:return e.nodes[0].value;default:return e}}}function V(e){return!(e instanceof I&&e.empty())&&!("boolean"==typeof e&&!1===e)}function W(e,t,n){switch(t){case"==":return B(e,n);case"!=":return!B(e,n);case"<":return Y(e,n);case">":return Y(n,e);case">=":return Y(n,e)||B(e,n);case"<=":return Y(e,n)||B(e,n);default:return!1}}function B(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 f(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===$:1===e.nodes.length&&f(e.nodes[0].value,t)}return e===$&&t===$||f(e,t)}function Y(e,t){return!!(l(e)&&l(t)||p(e)&&p(t))&&e<t}var q=Object.freeze({__proto__:null,BooleanLiteral:M,FilterExpression:L,FilterExpressionLiteral:K,FunctionExtension:Q,InfixExpression:z,JSONPathQuery:C,LogicalExpression:J,NullLiteral:A,NumberLiteral:U,PrefixExpression:j,RelativeQuery:G,RootQuery:D,StringLiteral:F,compare:W});class X{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return e.length}}class Z{argTypes=[d.ValueType];returnType=d.ValueType;call(e){return c(e)||l(e)?e.length:u(e)?Object.keys(e).length:$}}class H 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){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}class ee{argTypes=[d.ValueType,d.ValueType];returnType=d.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.#t=new H(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}}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=[];return e.startsWith("^")||t.push("^"),t.push(e),e.endsWith("$")||t.push("$"),t.join("")}}class te{argTypes=[d.ValueType,d.ValueType];returnType=d.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.#t=new H(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}}try{const n=new RegExp(t,"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class ne{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return 1===e.length?e.nodes[0].value:$}}let re=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 se{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new se(re.EOF,"",-1,"");class oe{#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)}}const ie=/e[+-]?\d+/y,ae=/[a-z][a-z_0-9]*/y,he=/-?\d+/y,ce=/-?[0-9]+/y,ue=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,le=new Set([" ","\n","\t","\r"]),pe=/[\u0080-\uFFFFa-zA-Z_]/;class fe{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=me;for(;e;)e=e(this)}emit(e){this.tokens.push(new se(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 se(re.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 se(re.ERROR,e,this.pos,this.path))}return!!this.acceptRun(le)&&(this.ignore(),!0)}error(e){this.tokens.push(new se(re.ERROR,e,this.#n,this.path))}}function de(e,t){const[n,r]=function(e,t){const n=new fe(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===re.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function me(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(re.ROOT),ge)}function ge(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(re.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(re.DDOT),ve):we;case"[":return e.emit(re.LBRACKET),Ee;default:return e.backup(),e.filterLevel?ye:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ve(e){if(e.acceptMatchRun(ue))return e.emit(re.NAME),ge;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(pe)?(e.ignore(),e.acceptMatchRun(ue),e.emit(re.KEY),ge):(e.emit(re.KEYS),ge);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(re.KEYS),ge}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(re.WILD),ge;case"[":return e.emit(re.LBRACKET),Ee;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function we(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(pe)?(e.ignore(),e.acceptMatchRun(ue),e.emit(re.KEY),ge):(e.emit(re.KEYS),ge);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(re.KEYS),ge}if(e.acceptMatchRun(ue))return e.emit(re.NAME),ge;const t=e.next();return"*"===t?(e.emit(re.WILD),ge):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Ee(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(he)){e.emit(re.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Te(e);case'"':return e.ignore(),e.next(),Re(e);case"?":return e.ignore(),e.next(),e.emit(re.KEYS_FILTER),e.filterLevel+=1,ye;default:e.emit(re.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(re.RBRACKET),e.filterLevel?ye:ge;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(re.WILD);continue;case"?":return e.emit(re.FILTER),e.filterLevel+=1,ye;case",":e.emit(re.COMMA);continue;case":":e.emit(re.COLON);continue;case"'":return Oe;case'"':return Ne;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function ye(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(),Ee);case",":if(e.emit(re.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Ee;case"'":return ke;case'"':return Se;case"(":e.emit(re.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(re.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(re.ROOT),ge;case"@":return e.emit(re.CURRENT),ge;case"#":return e.emit(re.CURRENT_KEY),ge;case".":return e.backup(),ge;case"!":"="===e.peek()?(e.next(),e.emit(re.NE)):e.emit(re.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(re.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(re.LE)):e.emit(re.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(re.GE)):e.emit(re.GT);continue;default:if(e.backup(),e.acceptMatchRun(ce)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ce)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(ie),e.emit(re.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(re.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(re.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(re.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(re.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(re.NULL);continue}if(e.acceptMatchRun(ae)&&"("===e.peek()){e.parenStack.push(1),e.emit(re.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function xe(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?re.SINGLE_QUOTE_STRING:re.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 Oe=xe("'",Ee,re.SINGLE_QUOTE_STRING),Ne=xe('"',Ee,re.DOUBLE_QUOTE_STRING),ke=xe("'",ye,re.SINGLE_QUOTE_STRING),Se=xe('"',ye,re.DOUBLE_QUOTE_STRING),Te=xe("'",Ee,re.KEY_SINGLE_QUOTE_STRING),Re=xe('"',Ee,re.KEY_DOUBLE_QUOTE_STRING);class $e{constructor(e,t){this.environment=e,this.token=t}}class _e extends $e{constructor(e,t,n,r){super(e,t),this.environment=e,this.token=t,this.name=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)!c(n.value)&&_(n.value,this.name)&&t.push(new P(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)!c(t.value)&&_(t.value,this.name)&&(yield new P(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class be extends $e{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=[];for(const n of e)if(c(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new P(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(c(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new P(t.value[e],t.location.concat(e),t.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Pe extends $e{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=[];for(const n of e)if(c(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new P(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(c(t.value))for(const[e,n]of this.lazySlice(t.value,this.start,this.stop,this.step))yield new P(n,t.location.concat(e),t.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 Ie extends $e{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++)t.push(new P(n.value[e],n.location.concat(e),n.root));else if(u(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new P(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++)yield new P(t.value[e],t.location.concat(e),t.root);else if(u(t.value))for(const[e,n]of this.environment.entries(t.value))yield new P(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class Le extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];if(this.environment.nondeterministic)for(const n of e)for(const e of this.nondeterministicVisitor(n))t.push(e);else for(const n of e){t.push(n);for(const e of this.visitor(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);if(!(t.value instanceof String))if(c(t.value))for(let r=0;r<t.value.length;r++){const s=new P(t.value[r],t.location.concat(r),t.root);yield s,u(s.value)&&e.push({node:s,depth:n+1})}else if(u(t.value))for(const[r,s]of this.environment.entries(t.value)){const o=new P(s,t.location.concat(r),t.root);yield o,u(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(c(e.value))for(let r=0;r<e.value.length;r++){const s=new P(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visitor(s,t+1))n.push(e)}else if(u(e.value))for(const[r,s]of this.environment.entries(e.value)){const o=new P(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visitor(o,t+1))n.push(e)}return n}nondeterministicVisitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=[e];let r=this.nondeterministicChildren(e).map((e=>[e,t]));for(;r.length;){const[e,t]=r.shift();if(n.push(e),t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const s=Math.random()<.5;for(const o of this.nondeterministicChildren(e))if(s){n.push(o);r=Me(r,this.nondeterministicChildren(o).map((e=>[e,t+2])))}else r.push([o,t+1])}return n}nondeterministicChildren(e){const t=[];if(e.value instanceof String)return t;if(c(e.value))for(let n=0;n<e.value.length;n++)t.push(new P(e.value[n],e.location.concat(n),e.root));else if(u(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new P(r,e.location.concat(n),e.root));return t}}class Ke extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(r,n.location.concat(e),n.root))}else if(u(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(n,t.location.concat(e),t.root))}else if(u(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class Ae extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.items=n}resolve(e){const t=[];for(const n of e)for(const e of this.items)for(const r of e.resolve([n]))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.items)yield*e.lazyResolve([t])}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}function Me(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))}var Fe=Object.freeze({__proto__:null,BracketedSelection:Ae,FilterSelector:Ke,IndexSelector:be,JSONPathSelector:$e,NameSelector:_e,RecursiveDescentSegment:Le,SliceSelector:Pe,WildcardSelector:Ie});class Ue{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new P(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new I(t)}lazyQuery(e){let t=[new P(e,[],e)][Symbol.iterator]();for(const e of this.selectors)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof _e||e instanceof Ae&&1===e.items.length&&(e.items[0]instanceof _e||e.items[0]instanceof be)))return!1;return!0}}class je extends L{evaluate(e){return e.currentKey??$}toString(){return"#"}}class ze extends $e{constructor(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];super(e,t),this.environment=e,this.token=t,this.key=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)n.value instanceof String||c(n.value)||u(n.value)&&_(n.value,this.key)&&t.push(new P(this.key,n.location.concat(`${b}${this.key}`),n.root));return t}*lazyResolve(e){for(const t of e)t.value instanceof String||c(t.value)||u(t.value)&&_(t.value,this.key)&&(yield new P(this.key,t.location.concat(`${b}${this.key}`),t.root))}toString(){return this.shorthand?`[~'${this.key.replaceAll("'","\\'")}']`:`~'${this.key.replaceAll("'","\\'")}'`}}class Je extends $e{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||c(n.value))&&u(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new P(e,n.location.concat(`${b}${e}`),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||c(t.value))&&u(t.value))for(const[e,n]of this.environment.entries(t.value))yield new P(e,t.location.concat(`${b}${e}`),t.root)}toString(){return this.shorthand?"[~]":"~"}}class Ce extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||c(n.value))&&u(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(e,n.location.concat(`${b}${e}`),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||c(t.value))&&u(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(e,t.location.concat(`${b}${e}`),t.root))}}toString(){return`~?${this.expression.toString()}`}}const Ge=new Map([[re.AND,5],[re.EQ,6],[re.GE,6],[re.GT,6],[re.LE,6],[re.LT,6],[re.NE,6],[re.NOT,7],[re.OR,4],[re.RPAREN,1]]),De=new Map([[re.AND,"&&"],[re.EQ,"=="],[re.GE,">="],[re.GT,">"],[re.LE,"<="],[re.LT,"<"],[re.NE,"!="],[re.OR,"||"]]),Qe=new Set(["==",">=",">","<=","<","!="]);class Ve{constructor(e){this.environment=e,this.tokenMap=new Map([[re.FALSE,this.parseBoolean],[re.NUMBER,this.parseNumber],[re.LPAREN,this.parseGroupedExpression],[re.NOT,this.parsePrefixExpression],[re.NULL,this.parseNull],[re.ROOT,this.parseRootQuery],[re.CURRENT,this.parseRelativeQuery],[re.SINGLE_QUOTE_STRING,this.parseString],[re.DOUBLE_QUOTE_STRING,this.parseString],[re.TRUE,this.parseBoolean],[re.FUNCTION,this.parseFunction],[re.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===re.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==re.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parsePath(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];for(;;){const r=this.parseSegment(e);if(!r){t&&e.backup();break}n.push(r),e.next()}return n}parseSegment(e){switch(e.current.kind){case re.NAME:return new _e(this.environment,e.current,e.current.value,!0);case re.WILD:return new Ie(this.environment,e.current,!0);case re.KEY:return new ze(this.environment,e.current,e.current.value,!0);case re.KEYS:return new Je(this.environment,e.current,!0);case re.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new Le(this.environment,t,n)}case re.LBRACKET:return this.parseBracketedSelection(e);default:return null}}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 be(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===re.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(re.COLON),e.next()):(n.push(void 0),e.expect(re.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===re.COLON&&e.next()):e.current.kind===re.COLON&&(n.push(void 0),e.expect(re.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Pe(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==re.RBRACKET;){switch(e.current.kind){case re.SINGLE_QUOTE_STRING:case re.DOUBLE_QUOTE_STRING:n.push(new _e(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case re.FILTER:n.push(this.parseFilter(e));break;case re.INDEX:e.peek.kind===re.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case re.COLON:n.push(this.parseSlice(e));break;case re.WILD:n.push(new Ie(this.environment,e.current));break;case re.KEY_SINGLE_QUOTE_STRING:case re.KEY_DOUBLE_QUOTE_STRING:n.push(new ze(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case re.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case re.KEYS:n.push(new Je(this.environment,e.current));break;case re.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!==re.RBRACKET&&(e.expectPeek(re.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Ae(this.environment,t,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 Q){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===d.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return t?new Ce(this.environment,n,new J(n,r)):new Ke(this.environment,n,new J(n,r))}parseBoolean(e){return e.current.kind===re.FALSE?new M(e.current,!1):new M(e.current,!0)}parseNull(e){return new A(e.current)}parseString(e){return new F(e.current,this.decodeString(e.current))}parseNumber(e){return new U(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(re.NOT),e.next(),new j(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ge.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=De.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Qe.has(o)&&(this.throwForNonComparable(t),this.throwForNonComparable(s)),new z(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===re.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==re.RPAREN;){if(e.current.kind===re.EOF)throw new a("unbalanced parentheses",e.current);if(!De.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(re.RPAREN),t}parseRootQuery(e){const t=e.next();return new D(t,new Ue(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new G(t,new Ue(this.environment,this.parsePath(e,!0)))}parseCurrentKey(e){return new je(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==re.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(;De.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==re.RPAREN){if(e.peek.kind===re.RBRACKET)break;e.expectPeek(re.COMMA),e.next()}e.next()}return e.expect(re.RPAREN),new Q(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 re.EOF:case re.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===re.EOF||n===re.RBRACKET||(Ge.get(n)||1)<t)break;if(!De.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{return JSON.parse(e.kind===re.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonComparable(e){if((e instanceof D||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof Q){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==d.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}}class We{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??-Math.pow(2,53)-1,this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new Ve(this),this.setupFilterFunctions()}compile(e){return new Ue(this,this.parser.parse(new oe(de(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 X),this.functionRegister.set("length",new Z),this.functionRegister.set("search",new te),this.functionRegister.set("match",new ee),this.functionRegister.set("value",new ne)}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 d.ValueType:if(!(o instanceof K||o instanceof je||o instanceof C&&o.path.singularQuery()||o instanceof Q&&this.functionRegister.get(o.name)?.returnType===d.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case d.LogicalType:if(!(o instanceof C||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case d.NodesType:if(!(o instanceof C||o instanceof Q&&this.functionRegister.get(o.name)?.returnType===d.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 Be=Object.freeze({__proto__:null,Count:X,FunctionExpressionType:d,Length:Z,Match:ee,Search:te,Value:ne});const Ye=new We;function qe(e,t){return Ye.query(e,t)}function Xe(e,t){return Ye.lazyQuery(e,t)}function Ze(e){return Ye.compile(e)}var He=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:Ye,FunctionExpressionType:d,JSONPath:Ue,JSONPathEnvironment:We,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:P,JSONPathNodeList:I,JSONPathRecursionLimitError:h,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:b,Nothing:$,Token:se,TokenKind:re,compile:Ze,expressions:q,functions:Be,lazyQuery:Xe,match:function(e,t){return Ye.match(e,t)},query:qe,selectors:Fe});class et extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class tt extends et{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class nt{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n))if(r===x){if("-"!==s)throw new et(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!u(n))throw new et(`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 rt{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new et(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new et(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!u(n))throw new et(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new et(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class st{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new et(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!u(n))throw new et(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new et(`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 ot{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new et(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new et(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);c(n)?n.splice(Number(s),1):u(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(o))o.splice(Number(a),0,r);else{if(!u(o))throw new et(`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 it{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new et(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!u(s))throw new et(`unexpected operation on '${typeof parent}' (${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 at{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!f(r,this.value))throw new tt(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ht{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 nt(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new rt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new st(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new ot(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new it(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new at(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 g)throw new et(`${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 et(`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 et(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!l(s))throw new et(`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 et(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new et(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!l(e))throw new et(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new et(`${e.message} (${t}:${n})`);throw e}}}function ct(e,t){return new ht(e).apply(t)}var ut=Object.freeze({__proto__:null,JSONPatch:ht,JSONPatchError:et,JSONPatchTestFailure:tt,apply:ct});return e.DEFAULT_ENVIRONMENT=Ye,e.FunctionExpressionType=d,e.JSONPatch=ht,e.JSONPatchError=et,e.JSONPatchTestFailure=tt,e.JSONPath=Ue,e.JSONPathEnvironment=We,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=P,e.JSONPathNodeList=I,e.JSONPathRecursionLimitError=h,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=$,e.RelativeJSONPointer=S,e.Token=se,e.TokenKind=re,e.UNDEFINED=x,e.apply=ct,e.compile=Ze,e.jsonpatch=ut,e.jsonpath=He,e.jsonpointer=R,e.lazyQuery=Xe,e.query=qe,e.resolve=T,e.version="1.3.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 h 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)}}function c(e){return Array.isArray(e)}function u(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function l(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(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(!f(e[n],t[n]))return!1;return!0}return!1}if(u(e)&&u(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!f(e[r],t[r]))return!1;return!0}return!1}let d=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 g extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class v extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class E extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=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]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof g&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,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 v||e instanceof w)return[t,x];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 E(`"${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(c(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(k.test(r)&&Object.hasOwn(e,r))return Number(r);throw new v(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new v(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(u(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new w(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!l(e))throw new y("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 g)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(l(e)?new S(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,k=/(0|[1-9][0-9]*)/;class S{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=l(e)?new O(e):e;if(this.origin>t.tokens.length)throw new v(`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 v(`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 E("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 E("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 E("unexpected leading zero");if(k.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!p(e))||k.test(e)}}function T(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new O(e).resolve(t,n)}var R=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:v,JSONPointerKeyError:w,JSONPointerResolutionError:g,JSONPointerSyntaxError:E,JSONPointerTypeError:y,RelativeJSONPointer:S,UNDEFINED:x,resolve:T});const $=Symbol.for("jsonpath.nothing");function b(e,t){return u(e)&&Object.hasOwn(e,t)}const _="";class P{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>l(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 K extends L{}class A extends K{evaluate(){return null}toString(){return"null"}}class M extends K{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class F extends K{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class j extends K{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:!V(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?V(t)&&V(n):"||"===this.operator?V(t)||V(n):W(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 C 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:V(t)}toString(){return this.expression.toString()}}class J extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends J{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 D extends J{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 Q 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]!==d.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 $;case 1:return e.nodes[0].value;default:return e}}}function V(e){return!(e instanceof I&&e.empty())&&!("boolean"==typeof e&&!1===e)}function W(e,t,n){switch(t){case"==":return B(e,n);case"!=":return!B(e,n);case"<":return Y(e,n);case">":return Y(n,e);case">=":return Y(n,e)||B(e,n);case"<=":return Y(e,n)||B(e,n);default:return!1}}function B(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 f(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===$:1===e.nodes.length&&f(e.nodes[0].value,t)}return e===$&&t===$||f(e,t)}function Y(e,t){return!!(l(e)&&l(t)||p(e)&&p(t))&&e<t}var q=Object.freeze({__proto__:null,BooleanLiteral:M,FilterExpression:L,FilterExpressionLiteral:K,FunctionExtension:Q,InfixExpression:z,JSONPathQuery:J,LogicalExpression:C,NullLiteral:A,NumberLiteral:j,PrefixExpression:U,RelativeQuery:G,RootQuery:D,StringLiteral:F,compare:W});class X{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return e.length}}class Z{argTypes=[d.ValueType];returnType=d.ValueType;call(e){return c(e)||l(e)?e.length:u(e)?Object.keys(e).length:$}}class H 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){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}class ee{argTypes=[d.ValueType,d.ValueType];returnType=d.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.#t=new H(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}}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=[];let n=!1;return e.startsWith("^")||e.startsWith("^(")||(n=!0,t.push("^(?:")),t.push(this.mapRegexp(e)),!n||e.endsWith("$")||e.endsWith(")$")||t.push(")$"),t.join("")}mapRegexp(e){let t=!1,n=!1;const r=[];for(const s of e)switch(s){case".":t||n?(r.push(s),t=!1):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,t=!1,r.push(s);break;case"]":n=!1,t=!1,r.push(s);break;default:t=!1,r.push(s)}return r.join("")}}class te{argTypes=[d.ValueType,d.ValueType];returnType=d.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.#t=new H(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}}try{const n=new RegExp(this.mapRegexp(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}mapRegexp(e){let t=!1,n=!1;const r=[];for(const s of e)switch(s){case".":t||n?(r.push(s),t=!1):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,t=!1,r.push(s);break;case"]":n=!1,t=!1,r.push(s);break;default:t=!1,r.push(s)}return r.join("")}}class ne{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return 1===e.length?e.nodes[0].value:$}}let re=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 se{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new se(re.EOF,"",-1,"");class oe{#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)}}const ie=/e[+-]?\d+/y,ae=/[a-z][a-z_0-9]*/y,he=/-?\d+/y,ce=/-?[0-9]+/y,ue=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,le=new Set([" ","\n","\t","\r"]),pe=/[\u0080-\uFFFFa-zA-Z_]/;class fe{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=me;for(;e;)e=e(this)}emit(e){this.tokens.push(new se(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 se(re.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 se(re.ERROR,e,this.pos,this.path))}return!!this.acceptRun(le)&&(this.ignore(),!0)}error(e){this.tokens.push(new se(re.ERROR,e,this.#n,this.path))}}function de(e,t){const[n,r]=function(e,t){const n=new fe(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===re.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function me(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(re.ROOT),ge)}function ge(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(re.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(re.DDOT),ve):we;case"[":return e.emit(re.LBRACKET),Ee;default:return e.backup(),e.filterLevel?ye:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ve(e){if(e.acceptMatchRun(ue))return e.emit(re.NAME),ge;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(pe)?(e.ignore(),e.acceptMatchRun(ue),e.emit(re.KEY),ge):(e.emit(re.KEYS),ge);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(re.KEYS),ge}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(re.WILD),ge;case"[":return e.emit(re.LBRACKET),Ee;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function we(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(pe)?(e.ignore(),e.acceptMatchRun(ue),e.emit(re.KEY),ge):(e.emit(re.KEYS),ge);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(re.KEYS),ge}if(e.acceptMatchRun(ue))return e.emit(re.NAME),ge;const t=e.next();return"*"===t?(e.emit(re.WILD),ge):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Ee(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(he)){e.emit(re.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Te(e);case'"':return e.ignore(),e.next(),Re(e);case"?":return e.next(),e.emit(re.KEYS_FILTER),e.filterLevel+=1,ye;default:e.emit(re.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(re.RBRACKET),e.filterLevel?ye:ge;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(re.WILD);continue;case"?":return e.emit(re.FILTER),e.filterLevel+=1,ye;case",":e.emit(re.COMMA);continue;case":":e.emit(re.COLON);continue;case"'":return Oe;case'"':return Ne;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function ye(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(),Ee);case",":if(e.emit(re.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Ee;case"'":return ke;case'"':return Se;case"(":e.emit(re.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(re.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(re.ROOT),ge;case"@":return e.emit(re.CURRENT),ge;case"#":return e.emit(re.CURRENT_KEY),ge;case".":return e.backup(),ge;case"!":"="===e.peek()?(e.next(),e.emit(re.NE)):e.emit(re.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(re.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(re.LE)):e.emit(re.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(re.GE)):e.emit(re.GT);continue;default:if(e.backup(),e.acceptMatchRun(ce)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ce)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(ie),e.emit(re.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(re.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(re.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(re.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(re.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(re.NULL);continue}if(e.acceptMatchRun(ae)&&"("===e.peek()){e.parenStack.push(1),e.emit(re.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function xe(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?re.SINGLE_QUOTE_STRING:re.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 Oe=xe("'",Ee,re.SINGLE_QUOTE_STRING),Ne=xe('"',Ee,re.DOUBLE_QUOTE_STRING),ke=xe("'",ye,re.SINGLE_QUOTE_STRING),Se=xe('"',ye,re.DOUBLE_QUOTE_STRING),Te=xe("'",Ee,re.KEY_SINGLE_QUOTE_STRING),Re=xe('"',Ee,re.KEY_DOUBLE_QUOTE_STRING);class $e{constructor(e,t){this.environment=e,this.token=t}}class be extends $e{constructor(e,t,n,r){super(e,t),this.environment=e,this.token=t,this.name=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)!c(n.value)&&b(n.value,this.name)&&t.push(new P(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)!c(t.value)&&b(t.value,this.name)&&(yield new P(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class _e extends $e{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=[];for(const n of e)if(c(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new P(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(c(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new P(t.value[e],t.location.concat(e),t.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Pe extends $e{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=[];for(const n of e)if(c(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new P(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(c(t.value))for(const[e,n]of this.lazySlice(t.value,this.start,this.stop,this.step))yield new P(n,t.location.concat(e),t.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 Ie extends $e{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++)t.push(new P(n.value[e],n.location.concat(e),n.root));else if(u(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new P(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++)yield new P(t.value[e],t.location.concat(e),t.root);else if(u(t.value))for(const[e,n]of this.environment.entries(t.value))yield new P(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class Le extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];if(this.environment.nondeterministic)for(const n of e)for(const e of this.nondeterministicVisitor(n))t.push(e);else for(const n of e){t.push(n);for(const e of this.visitor(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);if(!(t.value instanceof String))if(c(t.value))for(let r=0;r<t.value.length;r++){const s=new P(t.value[r],t.location.concat(r),t.root);yield s,u(s.value)&&e.push({node:s,depth:n+1})}else if(u(t.value))for(const[r,s]of this.environment.entries(t.value)){const o=new P(s,t.location.concat(r),t.root);yield o,u(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(c(e.value))for(let r=0;r<e.value.length;r++){const s=new P(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visitor(s,t+1))n.push(e)}else if(u(e.value))for(const[r,s]of this.environment.entries(e.value)){const o=new P(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visitor(o,t+1))n.push(e)}return n}nondeterministicVisitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=[e];let r=this.nondeterministicChildren(e).map((e=>[e,t]));for(;r.length;){const[e,t]=r.shift();if(n.push(e),t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const s=Math.random()<.5;for(const o of this.nondeterministicChildren(e))if(s){n.push(o);r=Me(r,this.nondeterministicChildren(o).map((e=>[e,t+2])))}else r.push([o,t+1])}return n}nondeterministicChildren(e){const t=[];if(e.value instanceof String)return t;if(c(e.value))for(let n=0;n<e.value.length;n++)t.push(new P(e.value[n],e.location.concat(n),e.root));else if(u(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new P(r,e.location.concat(n),e.root));return t}}class Ke extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(r,n.location.concat(e),n.root))}else if(u(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(n,t.location.concat(e),t.root))}else if(u(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class Ae extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.items=n}resolve(e){const t=[];for(const n of e)for(const e of this.items)for(const r of e.resolve([n]))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.items)yield*e.lazyResolve([t])}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}function Me(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))}var Fe=Object.freeze({__proto__:null,BracketedSelection:Ae,FilterSelector:Ke,IndexSelector:_e,JSONPathSelector:$e,NameSelector:be,RecursiveDescentSegment:Le,SliceSelector:Pe,WildcardSelector:Ie});class je{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new P(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new I(t)}lazyQuery(e){let t=[new P(e,[],e)][Symbol.iterator]();for(const e of this.selectors)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof be||e instanceof Ae&&1===e.items.length&&(e.items[0]instanceof be||e.items[0]instanceof _e)))return!1;return!0}}class Ue extends L{evaluate(e){return e.currentKey??$}toString(){return"#"}}class ze extends $e{constructor(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];super(e,t),this.environment=e,this.token=t,this.key=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)n.value instanceof String||c(n.value)||u(n.value)&&b(n.value,this.key)&&t.push(new P(this.key,n.location.concat(`${_}${this.key}`),n.root));return t}*lazyResolve(e){for(const t of e)t.value instanceof String||c(t.value)||u(t.value)&&b(t.value,this.key)&&(yield new P(this.key,t.location.concat(`${_}${this.key}`),t.root))}toString(){return this.shorthand?`[~'${this.key.replaceAll("'","\\'")}']`:`~'${this.key.replaceAll("'","\\'")}'`}}class Ce extends $e{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||c(n.value))&&u(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new P(e,n.location.concat(`${_}${e}`),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||c(t.value))&&u(t.value))for(const[e,n]of this.environment.entries(t.value))yield new P(e,t.location.concat(`${_}${e}`),t.root)}toString(){return this.shorthand?"[~]":"~"}}class Je extends $e{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||c(n.value))&&u(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new P(e,n.location.concat(`${_}${e}`),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||c(t.value))&&u(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new P(e,t.location.concat(`${_}${e}`),t.root))}}toString(){return`~?${this.expression.toString()}`}}const Ge=new Map([[re.AND,5],[re.EQ,6],[re.GE,6],[re.GT,6],[re.LE,6],[re.LT,6],[re.NE,6],[re.NOT,7],[re.OR,4],[re.RPAREN,1]]),De=new Map([[re.AND,"&&"],[re.EQ,"=="],[re.GE,">="],[re.GT,">"],[re.LE,"<="],[re.LT,"<"],[re.NE,"!="],[re.OR,"||"]]),Qe=new Set(["==",">=",">","<=","<","!="]);class Ve{constructor(e){this.environment=e,this.tokenMap=new Map([[re.FALSE,this.parseBoolean],[re.NUMBER,this.parseNumber],[re.LPAREN,this.parseGroupedExpression],[re.NOT,this.parsePrefixExpression],[re.NULL,this.parseNull],[re.ROOT,this.parseRootQuery],[re.CURRENT,this.parseRelativeQuery],[re.SINGLE_QUOTE_STRING,this.parseString],[re.DOUBLE_QUOTE_STRING,this.parseString],[re.TRUE,this.parseBoolean],[re.FUNCTION,this.parseFunction],[re.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===re.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==re.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parsePath(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];for(;;){const r=this.parseSegment(e);if(!r){t&&e.backup();break}n.push(r),e.next()}return n}parseSegment(e){switch(e.current.kind){case re.NAME:return new be(this.environment,e.current,e.current.value,!0);case re.WILD:return new Ie(this.environment,e.current,!0);case re.KEY:return new ze(this.environment,e.current,e.current.value,!0);case re.KEYS:return new Ce(this.environment,e.current,!0);case re.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new Le(this.environment,t,n)}case re.LBRACKET:return this.parseBracketedSelection(e);default:return null}}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 _e(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===re.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(re.COLON),e.next()):(n.push(void 0),e.expect(re.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===re.COLON&&e.next()):e.current.kind===re.COLON&&(n.push(void 0),e.expect(re.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Pe(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==re.RBRACKET;){switch(e.current.kind){case re.SINGLE_QUOTE_STRING:case re.DOUBLE_QUOTE_STRING:n.push(new be(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case re.FILTER:n.push(this.parseFilter(e));break;case re.INDEX:e.peek.kind===re.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case re.COLON:n.push(this.parseSlice(e));break;case re.WILD:n.push(new Ie(this.environment,e.current));break;case re.KEY_SINGLE_QUOTE_STRING:case re.KEY_DOUBLE_QUOTE_STRING:n.push(new ze(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case re.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case re.KEYS:n.push(new Ce(this.environment,e.current));break;case re.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!==re.RBRACKET&&(e.expectPeek(re.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Ae(this.environment,t,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 Q){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===d.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return t?new Je(this.environment,n,new C(n,r)):new Ke(this.environment,n,new C(n,r))}parseBoolean(e){return e.current.kind===re.FALSE?new M(e.current,!1):new M(e.current,!0)}parseNull(e){return new A(e.current)}parseString(e){return new F(e.current,this.decodeString(e.current))}parseNumber(e){return new j(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(re.NOT),e.next(),new U(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ge.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=De.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Qe.has(o)&&(this.throwForNonComparable(t),this.throwForNonComparable(s)),new z(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===re.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==re.RPAREN;){if(e.current.kind===re.EOF)throw new a("unbalanced parentheses",e.current);if(!De.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(re.RPAREN),t}parseRootQuery(e){const t=e.next();return new D(t,new je(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new G(t,new je(this.environment,this.parsePath(e,!0)))}parseCurrentKey(e){return new Ue(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==re.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(;De.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==re.RPAREN){if(e.peek.kind===re.RBRACKET)break;e.expectPeek(re.COMMA),e.next()}e.next()}return e.expect(re.RPAREN),new Q(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 re.EOF:case re.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===re.EOF||n===re.RBRACKET||(Ge.get(n)||1)<t)break;if(!De.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{return JSON.parse(e.kind===re.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonComparable(e){if((e instanceof D||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof Q){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==d.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}}class We{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??-Math.pow(2,53)-1,this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new Ve(this),this.setupFilterFunctions()}compile(e){return new je(this,this.parser.parse(new oe(de(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 X),this.functionRegister.set("length",new Z),this.functionRegister.set("search",new te),this.functionRegister.set("match",new ee),this.functionRegister.set("value",new ne)}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 d.ValueType:if(!(o instanceof K||o instanceof Ue||o instanceof J&&o.path.singularQuery()||o instanceof Q&&this.functionRegister.get(o.name)?.returnType===d.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case d.LogicalType:if(!(o instanceof J||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case d.NodesType:if(!(o instanceof J||o instanceof Q&&this.functionRegister.get(o.name)?.returnType===d.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 Be=Object.freeze({__proto__:null,Count:X,FunctionExpressionType:d,Length:Z,Match:ee,Search:te,Value:ne});const Ye=new We;function qe(e,t){return Ye.query(e,t)}function Xe(e,t){return Ye.lazyQuery(e,t)}function Ze(e){return Ye.compile(e)}var He=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:Ye,FunctionExpressionType:d,JSONPath:je,JSONPathEnvironment:We,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:P,JSONPathNodeList:I,JSONPathRecursionLimitError:h,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:_,Nothing:$,Token:se,TokenKind:re,compile:Ze,expressions:q,functions:Be,lazyQuery:Xe,match:function(e,t){return Ye.match(e,t)},query:qe,selectors:Fe});class et extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class tt extends et{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class nt{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n))if(r===x){if("-"!==s)throw new et(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!u(n))throw new et(`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 rt{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new et(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new et(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!u(n))throw new et(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new et(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class st{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new et(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!u(n))throw new et(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new et(`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 ot{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new et(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new et(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);c(n)?n.splice(Number(s),1):u(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(o))o.splice(Number(a),0,r);else{if(!u(o))throw new et(`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 it{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new et(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new et(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!u(s))throw new et(`unexpected operation on '${typeof parent}' (${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 at{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!f(r,this.value))throw new tt(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ht{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 nt(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new rt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new st(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new ot(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new it(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new at(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 g)throw new et(`${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 et(`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 et(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!l(s))throw new et(`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 et(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new et(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!l(e))throw new et(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new et(`${e.message} (${t}:${n})`);throw e}}}function ct(e,t){return new ht(e).apply(t)}var ut=Object.freeze({__proto__:null,JSONPatch:ht,JSONPatchError:et,JSONPatchTestFailure:tt,apply:ct});return e.DEFAULT_ENVIRONMENT=Ye,e.FunctionExpressionType=d,e.JSONPatch=ht,e.JSONPatchError=et,e.JSONPatchTestFailure=tt,e.JSONPath=je,e.JSONPathEnvironment=We,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=P,e.JSONPathNodeList=I,e.JSONPathRecursionLimitError=h,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=$,e.RelativeJSONPointer=S,e.Token=se,e.TokenKind=re,e.UNDEFINED=x,e.apply=ct,e.compile=Ze,e.jsonpatch=ut,e.jsonpath=He,e.jsonpointer=R,e.lazyQuery=Xe,e.query=qe,e.resolve=T,e.version="1.3.1",e}({});
|
|
2
2
|
//# sourceMappingURL=json-p3.iife.min.js.map
|