json-p3 2.3.1 → 2.3.2

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.
Files changed (42) hide show
  1. package/dist/json-p3.browser.js +4 -4
  2. package/dist/json-p3.browser.min.js +1 -1
  3. package/dist/json-p3.browser.min.js.map +1 -1
  4. package/dist/json-p3.cjs.js +4 -4
  5. package/dist/json-p3.esm.js +4 -4
  6. package/dist/json-p3.iife.min.js +1 -1
  7. package/dist/json-p3.iife.min.js.map +1 -1
  8. package/package.json +1 -1
  9. package/dist/deep_equals.d.ts +0 -10
  10. package/dist/index.d.ts +0 -10
  11. package/dist/patch/errors.d.ts +0 -11
  12. package/dist/patch/index.d.ts +0 -11
  13. package/dist/patch/patch.d.ts +0 -161
  14. package/dist/path/environment.d.ts +0 -165
  15. package/dist/path/errors.d.ts +0 -65
  16. package/dist/path/expression.d.ts +0 -101
  17. package/dist/path/extra/expression.d.ts +0 -6
  18. package/dist/path/extra/index.d.ts +0 -0
  19. package/dist/path/extra/selectors.d.ts +0 -35
  20. package/dist/path/functions/count.d.ts +0 -7
  21. package/dist/path/functions/function.d.ts +0 -26
  22. package/dist/path/functions/has.d.ts +0 -44
  23. package/dist/path/functions/index.d.ts +0 -11
  24. package/dist/path/functions/length.d.ts +0 -7
  25. package/dist/path/functions/match.d.ts +0 -33
  26. package/dist/path/functions/pattern.d.ts +0 -2
  27. package/dist/path/functions/search.d.ts +0 -34
  28. package/dist/path/functions/value.d.ts +0 -7
  29. package/dist/path/index.d.ts +0 -76
  30. package/dist/path/lex.d.ts +0 -74
  31. package/dist/path/lru_cache.d.ts +0 -10
  32. package/dist/path/node.d.ts +0 -84
  33. package/dist/path/parse.d.ts +0 -61
  34. package/dist/path/path.d.ts +0 -42
  35. package/dist/path/selectors.d.ts +0 -86
  36. package/dist/path/serialize.d.ts +0 -6
  37. package/dist/path/token.d.ts +0 -70
  38. package/dist/path/types.d.ts +0 -46
  39. package/dist/pointer/errors.d.ts +0 -42
  40. package/dist/pointer/index.d.ts +0 -24
  41. package/dist/pointer/pointer.d.ts +0 -106
  42. package/dist/types.d.ts +0 -25
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 2.3.1
2
+ * json-p3 version 2.3.2
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -3591,7 +3591,7 @@ class ChildSegment extends JSONPathSegment {
3591
3591
  const rv = [];
3592
3592
  for (const node of nodes) {
3593
3593
  for (const selector of this.selectors) {
3594
- rv.push(...selector.resolve(node));
3594
+ for (const match of selector.resolve(node)) rv.push(match);
3595
3595
  }
3596
3596
  }
3597
3597
  return rv;
@@ -3626,7 +3626,7 @@ class DescendantSegment extends JSONPathSegment {
3626
3626
  for (const node of nodes) {
3627
3627
  for (const _node of visitor(node)) {
3628
3628
  for (const selector of this.selectors) {
3629
- rv.push(...selector.resolve(_node));
3629
+ for (const match of selector.resolve(_node)) rv.push(match);
3630
3630
  }
3631
3631
  }
3632
3632
  }
@@ -5232,7 +5232,7 @@ var index = /*#__PURE__*/Object.freeze({
5232
5232
  apply: apply
5233
5233
  });
5234
5234
 
5235
- const version = "2.3.1";
5235
+ const version = "2.3.2";
5236
5236
 
5237
5237
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
5238
5238
  exports.FunctionExpressionType = FunctionExpressionType;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 2.3.1
2
+ * json-p3 version 2.3.2
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -3589,7 +3589,7 @@ class ChildSegment extends JSONPathSegment {
3589
3589
  const rv = [];
3590
3590
  for (const node of nodes) {
3591
3591
  for (const selector of this.selectors) {
3592
- rv.push(...selector.resolve(node));
3592
+ for (const match of selector.resolve(node)) rv.push(match);
3593
3593
  }
3594
3594
  }
3595
3595
  return rv;
@@ -3624,7 +3624,7 @@ class DescendantSegment extends JSONPathSegment {
3624
3624
  for (const node of nodes) {
3625
3625
  for (const _node of visitor(node)) {
3626
3626
  for (const selector of this.selectors) {
3627
- rv.push(...selector.resolve(_node));
3627
+ for (const match of selector.resolve(_node)) rv.push(match);
3628
3628
  }
3629
3629
  }
3630
3630
  }
@@ -5230,6 +5230,6 @@ var index = /*#__PURE__*/Object.freeze({
5230
5230
  apply: apply
5231
5231
  });
5232
5232
 
5233
- const version = "2.3.1";
5233
+ const version = "2.3.2";
5234
5234
 
5235
5235
  export { DEFAULT_ENVIRONMENT, FunctionExpressionType, JSONPatch, JSONPatchError, JSONPatchTestFailure, JSONPathEnvironment, JSONPathError, JSONPathIndexError, JSONPathLexerError, JSONPathNode, JSONPathNodeList, JSONPathQuery, JSONPathRecursionLimitError, JSONPathSyntaxError, JSONPathTypeError, JSONPointer, Nothing, RelativeJSONPointer, Token, TokenKind, UNDEFINED, apply, compile, index as jsonpatch, index$1 as jsonpath, index$3 as jsonpointer, lazyQuery, query, resolve, version };
@@ -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 i 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 o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class c extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}class u extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function h(e){return Array.isArray(e)}function l(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function p(e){return"string"==typeof e}function f(e){return"number"==typeof e}function d(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}return!1}if(l(e)&&l(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!d(e[r],t[r]))return!1;return!0}return!1}let g=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class m extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class w extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class E extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const k=Symbol.for("jsonpointer.undefined");class O{#e;constructor(e){this.tokens=this.parse(e),this.#e=O.encode(this.tokens)}static encode(e){return e.length?"/"+e.map(e=>e.replaceAll("~","~0").replaceAll("/","~1")).join("/"):""}resolve(e,t=k){try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==k)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[k,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof w||e instanceof x)return[t,k];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every((t,n)=>t===e.tokens[n])}parse(e){if(e.length&&!e.startsWith("/"))throw new 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(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(N.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(l(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new x(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(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(...e){if(!e.length)return this;let t=this;for(const n of e)t=t._join(n);return t}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new O(O.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const S=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,N=/(0|[1-9]\d*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new O(e):e;if(this.origin>t.tokens.length)throw new w(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new w(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof O?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new O(O.encode(n))}parse(e){const t=S.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(N.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||N.test(e)}}function R(e,t,n=k){return new O(e).resolve(t,n)}var b=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:x,JSONPointerResolutionError:v,JSONPointerSyntaxError:E,JSONPointerTypeError:y,RelativeJSONPointer:T,UNDEFINED:k,resolve:R});const $=/^[\p{ID_Start}_]\p{ID_Continue}*$/u;function P(e){return e.includes("'")&&!e.includes('"')?JSON.stringify(e):_(e)}function _(e){return`'${JSON.stringify(e).slice(1,-1).replaceAll('\\"','"').replaceAll("'","\\'")}'`}function I(e){return $.test(e)?e:null}const A=Symbol.for("jsonpath.nothing");function L(e,t){return l(e)&&Object.hasOwn(e,t)}const C="",K={form:"pretty"};class F{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return this.getPath({form:"canonical"})}getPath(e){const t={...K,...e};return"$"+this.location.map(e=>p(e)?this.decodeNameLocation(e,t):`[${e}]`).join("")}toPointer(){return this.location.length?new O(O.encode(this.location.map(String))):new O("")}decodeNameLocation(e,t){const n="canonical"===t.form,r=n?_:P,s=e.startsWith(C);s&&(e=e.slice(1));const i=I(e);return s?n||null==i?`[~${r(e)}]`:`.~${i}`:n||null==i?`[${r(e)}]`:`.${i}`}}class z{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map(e=>e.value)}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map(e=>e.value)}locations(){return this.nodes.map(e=>e.location)}paths(e){return this.nodes.map(t=>t.getPath(e))}pointers(){return this.nodes.map(e=>e.toPointer())}get length(){return this.nodes.length}}class M{constructor(e){this.token=e}}class j extends M{}class U extends j{evaluate(){return null}toString(){return"null"}}class D extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class J extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return _(this.value)}}class G extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class Q extends M{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 z?0===t.nodes.length:!Z(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(e){return`${this.operator}${this.right.toString(e)}`}}class V extends M{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 z&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof z&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?Z(t)&&Z(n):"||"===this.operator?Z(t)||Z(n):H(t,this.operator,n)}toString(e){return this.logical?`(${this.left.toString(e)} ${this.operator} ${this.right.toString(e)})`:`${this.left.toString(e)} ${this.operator} ${this.right.toString(e)}`}}class B extends M{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof z?t.nodes.length>0:Z(t)}toString(e){return function t(n,r){if(n instanceof V){let s,i,o,a;if("&&"===n.operator)s=5,i="&&",o=t(n.left,s),a=t(n.right,s);else{if("||"!==n.operator)return n.toString(e);s=4,i="||",o=t(n.left,s),a=t(n.right,s)}const c=`${o} ${i} ${a}`;return s<r?`(${c})`:c}if(n instanceof Q){const e=`!${t(n.right,7)}`;return r>7?`(${e})`:e}return n.toString(e)}(this.expression,0)}}class W extends M{constructor(e,t){super(e),this.token=e,this.path=t}}class Y extends W{evaluate(e){return e.lazy?new z(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(e){return`@${this.path.toString(e).slice(1)}`}}class q extends W{evaluate(e){return e.lazy?new z(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(e){return this.path.toString(e)}}class X extends M{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 o(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map(t=>t.evaluate(e)).map((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof z?this.unpack_node_list(e):e);return t.call(...n)}toString(e){return`${this.name}(${this.args.map(t=>t.toString(e)).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return A;case 1:return e.nodes[0].value;default:return e}}}function Z(e){return!(e instanceof z&&e.empty())&&!("boolean"==typeof e&&!1===e)}function H(e,t,n){switch(t){case"==":return ee(e,n);case"!=":return!ee(e,n);case"<":return te(e,n);case">":return te(n,e);case">=":return te(n,e)||ee(e,n);case"<=":return te(e,n)||ee(e,n);default:return!1}}function ee(e,t){if(t instanceof z&&([e,t]=[t,e]),e instanceof z){if(t instanceof z){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===A:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===A&&t===A||d(e,t)}function te(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var ne=Object.freeze({__proto__:null,BooleanLiteral:D,FilterExpression:M,FilterExpressionLiteral:j,FilterQuery:W,FunctionExtension:X,InfixExpression:V,LogicalExpression:B,NullLiteral:U,NumberLiteral:G,PrefixExpression:Q,RelativeQuery:Y,RootQuery:q,StringLiteral:J,compare:H});class re{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return e.length}}class se{argTypes=[g.ValueType];returnType=g.ValueType;call(e){return h(e)||p(e)?e.length:l(e)?Object.keys(e).length:A}}class ie extends Map{constructor(e=128,t){void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){if(this.has(e))this.delete(e);else if(this.size>=this.maxSize){const e=this.first();void 0!==e&&this.delete(e)}return super.set(e,t)}first(){return this.keys().next().value}}function oe(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ae(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(oe(e)),n||r||t.push(")$"),t.join("")}function ce(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ce.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function ue(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ce,Error),ce.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,i=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,o=this.location.source+":"+i.line+":"+i.column;if(r){var a=this.location.end,c=ue("",i.line.toString().length," "),u=r[s.line-1],h=(s.line===a.line?a.column:u.length+1)-s.column||1;t+="\n --\x3e "+o+"\n"+c+" |\n"+i.line+" | "+u+"\n"+c+" | "+ue("",s.column-1," ")+ue("",h,"^")}else t+="\n at "+o}return t},ce.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map(function(e){return Array.isArray(e)?i(e[0])+"-"+i(e[1]):i(e)});return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function i(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function o(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(o);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const he={StartRules:["start"],SyntaxError:ce,parse:function(e,t){var n,r,s,i,o={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ie},u=Ie,h="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",x="^",E="-",y="]",k="\\p{",O="\\P{",S="L",N="M",T="N",R="P",b="Z",$="S",P="C",_=/^[*-+?]/,I=/^[0-9]/,A=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,z=/^[lps]/,M=/^[ckmo]/,j=/^[cfn-o]/,U=Re("|",!1),D=be([["*","+"],"?"],!1,!1),J=Re("{",!1),G=be([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),B=Re("(",!1),W=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=be([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),ne=Re("]",!1),re=Re("\\p{",!1),se=Re("\\P{",!1),ie=Re("L",!1),oe=be([["l","m"],"o",["t","u"]],!1,!1),ae=Re("M",!1),ue=be(["c","e","n"],!1,!1),he=Re("N",!1),le=be(["d","l","o"],!1,!1),pe=Re("P",!1),fe=be([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=be(["l","p","s"],!1,!1),me=Re("S",!1),ve=be(["c","k","m","o"],!1,!1),we=Re("C",!1),xe=be(["c","f",["n","o"]],!1,!1),Ee=function(e){return function(e){return e<"'"||","===e||"-"===e||e>="/"&&e<=">"||e>="@"&&e<="Z"||e>="^"&&e<="z"||e>="~"&&e<="퟿"||e>=""}(e)},ye=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},ke=0|t.peg$currPos,Oe=[{line:1,column:1}],Se=ke,Ne=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function be(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function $e(t){var n,r=Oe[t];if(r)return r;if(t>=Oe.length)n=Oe.length-1;else for(n=t;!Oe[--n];);for(r={line:(r=Oe[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return Oe[t]=r,r}function Pe(e,t,n){var r=$e(e),s=$e(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function _e(e){ke<Se||(ke>Se&&(Se=ke,Ne=[]),Ne.push(e))}function Ie(){return Ae()}function Ae(){var t,n,r,s;for(t=Le(),n=[],r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=o,0===Te&&_e(U)),s!==o?r=s=[s,Le()]:(ke=r,r=o);r!==o;)n.push(r),r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=o,0===Te&&_e(U)),s!==o?r=s=[s,Le()]:(ke=r,r=o);return t=[t,n]}function Le(){var e,t;for(e=[],t=Ce();t!==o;)e.push(t),t=Ce();return e}function Ce(){var t,n,r;return t=ke,n=function(){var t,n,r,s;t=function(){var t,n;t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=o,0===Te&&_e(Y));n!==o&&(Ee(n)?void 0:o)!==o?t=n:(ke=t,t=o);return t}(),t===o&&(t=function(){var t;46===e.charCodeAt(ke)?(t=m,ke++):(t=o,0===Te&&_e(q));t===o&&(t=Ke())===o&&(t=Fe())===o&&(t=function(){var t,n,r,s,i,a,c;t=ke,91===e.charCodeAt(ke)?(n=w,ke++):(n=o,0===Te&&_e(H));if(n!==o)if(94===e.charCodeAt(ke)?(r=x,ke++):(r=o,0===Te&&_e(ee)),r===o&&(r=null),45===e.charCodeAt(ke)?(s=E,ke++):(s=o,0===Te&&_e(te)),s===o&&(s=ze()),s!==o){for(i=[],a=ze();a!==o;)i.push(a),a=ze();45===e.charCodeAt(ke)?(a=E,ke++):(a=o,0===Te&&_e(te)),a===o&&(a=null),93===e.charCodeAt(ke)?(c=y,ke++):(c=o,0===Te&&_e(ne)),c!==o?t=n=[n,r,s,i,a,c]:(ke=t,t=o)}else ke=t,t=o;else ke=t,t=o;return t}());return t}(),t===o&&(t=ke,40===e.charCodeAt(ke)?(n=d,ke++):(n=o,0===Te&&_e(B)),n!==o&&(r=Ae())!==o?(41===e.charCodeAt(ke)?(s=g,ke++):(s=o,0===Te&&_e(W)),s!==o?t=n=[n,r,s]:(ke=t,t=o)):(ke=t,t=o)));return t}(),n!==o?(r=function(){var t;t=e.charAt(ke),_.test(t)?ke++:(t=o,0===Te&&_e(D));t===o&&(t=function(){var t,n,r,s,i,a,c;t=ke,123===e.charCodeAt(ke)?(n=l,ke++):(n=o,0===Te&&_e(J));if(n!==o){if(r=[],s=e.charAt(ke),I.test(s)?ke++:(s=o,0===Te&&_e(G)),s!==o)for(;s!==o;)r.push(s),s=e.charAt(ke),I.test(s)?ke++:(s=o,0===Te&&_e(G));else r=o;if(r!==o){if(s=ke,44===e.charCodeAt(ke)?(i=p,ke++):(i=o,0===Te&&_e(Q)),i!==o){for(a=[],c=e.charAt(ke),I.test(c)?ke++:(c=o,0===Te&&_e(G));c!==o;)a.push(c),c=e.charAt(ke),I.test(c)?ke++:(c=o,0===Te&&_e(G));s=i=[i,a]}else ke=s,s=o;s===o&&(s=null),125===e.charCodeAt(ke)?(i=f,ke++):(i=o,0===Te&&_e(V)),i!==o?t=n=[n,r,s,i]:(ke=t,t=o)}else ke=t,t=o}else ke=t,t=o;return t}());return t}(),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o),t}function Ke(){var t,n,r;return t=ke,92===e.charCodeAt(ke)?(n=v,ke++):(n=o,0===Te&&_e(X)),n!==o?(r=e.charAt(ke),A.test(r)?ke++:(r=o,0===Te&&_e(Z)),r!==o?t=n=[n,r]:(ke=t,t=o)):(ke=t,t=o),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===k?(n=k,ke+=3):(n=o,0===Te&&_e(re));n!==o&&(r=je())!==o?(125===e.charCodeAt(ke)?(s=f,ke++):(s=o,0===Te&&_e(V)),s!==o?t=n=[n,r,s]:(ke=t,t=o)):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===O?(n=O,ke+=3):(n=o,0===Te&&_e(se));n!==o&&(r=je())!==o?(125===e.charCodeAt(ke)?(s=f,ke++):(s=o,0===Te&&_e(V)),s!==o?t=n=[n,r,s]:(ke=t,t=o)):(ke=t,t=o);return t}()),t}function ze(){var t,n,r,s,i;return t=ke,(n=Me())!==o?(r=ke,45===e.charCodeAt(ke)?(s=E,ke++):(s=o,0===Te&&_e(te)),s!==o&&(i=Me())!==o?r=s=[s,i]:(ke=r,r=o),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o),t===o&&(t=Fe()),t}function Me(){var t,n;return t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=o,0===Te&&_e(Y)),n!==o&&(ye(n)?void 0:o)!==o?t=n:(ke=t,t=o),t===o&&(t=Ke()),t}function je(){var t;return(t=function(){var t,n,r;t=ke,76===e.charCodeAt(ke)?(n=S,ke++):(n=o,0===Te&&_e(ie));n!==o?(r=e.charAt(ke),L.test(r)?ke++:(r=o,0===Te&&_e(oe)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,77===e.charCodeAt(ke)?(n=N,ke++):(n=o,0===Te&&_e(ae));n!==o?(r=e.charAt(ke),C.test(r)?ke++:(r=o,0===Te&&_e(ue)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,78===e.charCodeAt(ke)?(n=T,ke++):(n=o,0===Te&&_e(he));n!==o?(r=e.charAt(ke),K.test(r)?ke++:(r=o,0===Te&&_e(le)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,80===e.charCodeAt(ke)?(n=R,ke++):(n=o,0===Te&&_e(pe));n!==o?(r=e.charAt(ke),F.test(r)?ke++:(r=o,0===Te&&_e(fe)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,90===e.charCodeAt(ke)?(n=b,ke++):(n=o,0===Te&&_e(de));n!==o?(r=e.charAt(ke),z.test(r)?ke++:(r=o,0===Te&&_e(ge)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,83===e.charCodeAt(ke)?(n=$,ke++):(n=o,0===Te&&_e(me));n!==o?(r=e.charAt(ke),M.test(r)?ke++:(r=o,0===Te&&_e(ve)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}())===o&&(t=function(){var t,n,r;t=ke,67===e.charCodeAt(ke)?(n=P,ke++):(n=o,0===Te&&_e(we));n!==o?(r=e.charAt(ke),j.test(r)?ke++:(r=o,0===Te&&_e(xe)),r===o&&(r=null),t=n=[n,r]):(ke=t,t=o);return t}()),t}if(n=u(),t.peg$library)return{peg$result:n,peg$currPos:ke,peg$FAILED:o,peg$maxFailExpected:Ne,peg$maxFailPos:Se};if(n!==o&&ke===e.length)return n;throw n!==o&&ke<e.length&&_e({type:"end"}),r=Ne,s=Se<e.length?e.charAt(Se):null,i=Se<e.length?Pe(Se,Se+1):Pe(Se,Se),new ce(ce.buildMessage(r,s),r,s,i)}};var le=function(e){try{he.parse(e,{})}catch(e){if(e instanceof he.SyntaxError)return!1;throw e}return!0};class pe{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ie(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(ae(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}}class fe{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ie(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(oe(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class de{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return 1===e.length?e.nodes[0].value:A}}let ge=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 me{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new me(ge.EOF,"",-1,"");class ve{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}expectPeekNot(e,t){const n=this.peek;if(n.kind===e)throw new a(t,n)}}const we=/[eE][+-]?\d+/y,xe=/[a-z][a-z_0-9]*/y,Ee=/-?\d+/y,ye=/-?\d+/y,ke=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,Oe=new Set([" ","\n","\t","\r"]),Se=/[\u0080-\uFFFFa-zA-Z_]/;class Ne{filterLevel=0;funcCallStack=[];bracketStack=[];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=Re;for(;e;)e=e(this)}emit(e){this.tokens.push(new me(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 me(ge.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 me(ge.ERROR,e,this.pos,this.path))}return!!this.acceptRun(Oe)&&(this.ignore(),!0)}error(e){this.tokens.push(new me(ge.ERROR,e,this.#n,this.path))}}function Te(e,t){const[n,r]=function(e,t){const n=new Ne(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===ge.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);if(0!==n.bracketStack.length){const[e,r]=n.bracketStack[n.bracketStack.length-1];throw new a("unbalanced brackets",new me(ge.ERROR,e,r,t))}return r}function Re(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(ge.ROOT),be)}function be(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(ge.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(ge.DDOT),$e):Pe;case"[":return e.bracketStack.push(["[",e.start]),e.emit(ge.LBRACKET),_e;default:return e.backup(),e.filterLevel?Ie:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function $e(e){if(e.acceptMatchRun(ke))return e.emit(ge.NAME),be;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(Se)?(e.ignore(),e.acceptMatchRun(ke),e.emit(ge.KEY),be):(e.emit(ge.KEYS),be);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ge.KEYS),be}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(ge.WILD),be;case"[":return e.bracketStack.push(["[",e.start]),e.emit(ge.LBRACKET),_e;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function Pe(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(Se)?(e.ignore(),e.acceptMatchRun(ke),e.emit(ge.KEY),be):(e.emit(ge.KEYS),be);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ge.KEYS),be}if(e.acceptMatchRun(ke))return e.emit(ge.NAME),be;const t=e.next();return"*"===t?(e.emit(ge.WILD),be):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function _e(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(Ee)){e.emit(ge.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),ze(e);case'"':return e.ignore(),e.next(),Me(e);case"?":return e.next(),e.emit(ge.KEYS_FILTER),e.filterLevel+=1,Ie;default:e.emit(ge.KEYS);continue}const t=e.next();switch(t){case"]":return 0===e.bracketStack.length||"["!==e.bracketStack[e.bracketStack.length-1][0]?(e.backup(),e.error("unbalanced brackets"),null):(e.bracketStack.pop(),e.emit(ge.RBRACKET),be);case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(ge.WILD);continue;case"?":return e.emit(ge.FILTER),e.filterLevel+=1,Ie;case",":e.emit(ge.COMMA);continue;case":":e.emit(ge.COLON);continue;case"'":return Le;case'"':return Ce;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function Ie(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,e.backup(),_e;case",":if(e.emit(ge.COMMA),e.funcCallStack.length)continue;return e.filterLevel-=1,_e;case"'":return Ke;case'"':return Fe;case"(":e.bracketStack.push(["(",e.start]),e.emit(ge.LPAREN),e.funcCallStack.length&&(e.funcCallStack[e.funcCallStack.length-1]+=1);continue;case")":if(0===e.bracketStack.length||"("!==e.bracketStack[e.bracketStack.length-1][0])return e.backup(),e.error("unbalanced brackets"),null;e.bracketStack.pop(),e.emit(ge.RPAREN),e.funcCallStack.length&&(1===e.funcCallStack[e.funcCallStack.length-1]?e.funcCallStack.pop():e.funcCallStack[e.funcCallStack.length-1]-=1);continue;case"$":return e.emit(ge.ROOT),be;case"@":return e.emit(ge.CURRENT),be;case"#":return e.environment.strict?(e.backup(),e.error(`unexpected filter selector token '${t}'`),null):(e.emit(ge.CURRENT_KEY),be);case".":return e.backup(),be;case"!":"="===e.peek()?(e.next(),e.emit(ge.NE)):e.emit(ge.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(ge.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(ge.LE)):e.emit(ge.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(ge.GE)):e.emit(ge.GT);continue;default:if(e.backup(),e.acceptMatchRun(ye)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ye)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(we),e.emit(ge.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(ge.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(ge.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(ge.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(ge.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(ge.NULL);continue}if(e.acceptMatchRun(xe)&&"("===e.peek()){e.funcCallStack.push(1),e.emit(ge.FUNCTION),e.bracketStack.push(["(",e.start]),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Ae(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?ge.SINGLE_QUOTE_STRING:ge.DOUBLE_QUOTE_STRING),r.next(),r.ignore(),t;for(;;){const s=r.path.slice(r.pos,r.pos+2),i=r.next();if("\\\\"!==s&&s!==`\\${e}`){if("\\"===i&&!s.match(/\\[bfnrtu/]/))return r.error("invalid escape"),null;if(!i)return r.error(`unclosed string starting at index ${r.start}`),null;if(i===e)return r.backup(),r.emit(n),r.next(),r.ignore(),t}else r.next()}}}const Le=Ae("'",_e,ge.SINGLE_QUOTE_STRING),Ce=Ae('"',_e,ge.DOUBLE_QUOTE_STRING),Ke=Ae("'",Ie,ge.SINGLE_QUOTE_STRING),Fe=Ae('"',Ie,ge.DOUBLE_QUOTE_STRING),ze=Ae("'",_e,ge.KEY_SINGLE_QUOTE_STRING),Me=Ae('"',_e,ge.KEY_DOUBLE_QUOTE_STRING);class je{constructor(e,t){this.environment=e,this.token=t}}class Ue extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.name=n}resolve(e){const t=[];return!h(e.value)&&L(e.value,this.name)&&t.push(new F(e.value[this.name],e.location.concat(this.name),e.root)),t}*lazyResolve(e){!h(e.value)&&L(e.value,this.name)&&(yield new F(e.value[this.name],e.location.concat(this.name),e.root))}toString(e){const{form:t}={...K,...e};return"canonical"===t?_(this.name):P(this.name)}shorthand(){return I(this.name)}}class De extends je{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new i("index out of range",this.token)}resolve(e){const t=[];if(h(e.value)){const n=this.normalizedIndex(e.value.length);n in e.value&&t.push(new F(e.value[n],e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value)){const t=this.normalizedIndex(e.value.length);t in e.value&&(yield new F(e.value[t],e.location.concat(t),e.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Je extends je{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];if(!h(e.value))return t;for(const[n,r]of this.slice(e.value,this.start,this.stop,this.step))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(const[t,n]of this.lazySlice(e.value,this.start,this.stop,this.step))yield new F(n,e.location.concat(t),e.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(...e){for(const t of e)if(void 0!==t&&(t<this.environment.minIntIndex||t>this.environment.maxIntIndex))throw new i("index out of range",this.token)}slice(e,t,n,r){const s=e.length;if(0===(r=r??1)||!s)return[];const i=[];let o;if(r>0){o=this.normalizeIndex(t,0,s,r);const a=this.normalizeIndex(n,s,s,r);for(;o<a;o+=r)i.push([o,e[o]])}else{o=this.normalizeIndex(t,s-1,s,r);const a=this.normalizeIndex(n,-1,s,r);for(;o>a;o+=r)i.push([o,e[o]])}return i}*lazySlice(e,t,n,r){const s=e.length;if(0===(r=r??1)||!s)return[];let i;if(r>0){i=this.normalizeIndex(t,0,s,r);const o=this.normalizeIndex(n,s,s,r);for(;i<o;i+=r)yield[i,e[i]]}else{i=this.normalizeIndex(t,s-1,s,r);const o=this.normalizeIndex(n,-1,s,r);for(;i>o;i+=r)yield[i,e[i]]}}normalizeIndex(e,t,n,r){return void 0===e?t:e<0?r<0?Math.max(e+n,-1):Math.max(e+n,0):r<0?Math.min(e,n-1):Math.min(e,n)}}class Ge extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++)t.push(new F(e.value[n],e.location.concat(n),e.root));else if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}toString(){return"*"}}class Qe extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++){const r=e.value[n],s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++){const n=e.value[t],r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}}toString(e){return`?${this.expression.toString(e)}`}}var Ve=Object.freeze({__proto__:null,FilterSelector:Qe,IndexSelector:De,JSONPathSelector:je,NameSelector:Ue,SliceSelector:Je,WildcardSelector:Ge});class Be{constructor(e,t,n){this.environment=e,this.token=t,this.selectors=n}}class We extends Be{resolve(e){const t=[];for(const n of e)for(const e of this.selectors)t.push(...e.resolve(n));return t}*lazyResolve(e){for(const t of e)for(const e of this.selectors)yield*e.resolve(t)}toString(e){const{form:t}={...K,...e};if("pretty"===t&&1===this.selectors.length&&this.selectors[0]instanceof Ue){const e=this.selectors[0].shorthand();if(null!=e)return`.${e}`}return`[${this.selectors.map(t=>t.toString(e)).join(", ")}]`}}class Ye extends Be{resolve(e){const t=[],n=(this.environment.nondeterministic?this.nondeterministicVisit:this.visit).bind(this);for(const r of e)for(const e of n(r))for(const n of this.selectors)t.push(...n.resolve(e));return t}*lazyResolve(e){for(const t of e)for(const e of this.visit(t))for(const t of this.selectors)yield*t.resolve(e)}toString(e){return`..[${this.selectors.map(t=>t.toString(e)).join(", ")}]`}*visit(e,t=1){if(t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);if(yield e,h(e.value))for(let n=0;n<e.value.length;n++){const r=new F(e.value[n],e.location.concat(n),e.root);yield*this.visit(r,t+1)}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s=new F(r,e.location.concat(n),e.root);yield*this.visit(s,t+1)}}*nondeterministicVisit(e,t=1){let n=Array.from(this.nondeterministicChildren(e)).map(e=>[e,t]);for(yield e;n.length;){const[e,t]=n.shift();if(yield e,t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const r=Math.random()<.5;for(const s of this.nondeterministicChildren(e))if(r){yield s;n=qe(n,Array.from(this.nondeterministicChildren(s)).map(e=>[e,t+2]))}else n.push([s,t+1])}}*nondeterministicChildren(e){if(!p(e.value))if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}}function qe(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map(e=>e.next().value)}class Xe{constructor(e,t){this.environment=e,this.segments=t}query(e){let t=[new F(e,[],e)];for(const e of this.segments)t=e.resolve(t);return new z(t)}lazyQuery(e){let t=[new F(e,[],e)][Symbol.iterator]();for(const e of this.segments)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(e){return`$${this.segments.map(t=>t.toString(e)).join("")}`}singularQuery(){for(const e of this.segments){if(e instanceof Ye)return!1;if(1!==e.selectors.length||!(e.selectors[0]instanceof Ue||e.selectors[0]instanceof De))return!1}return!0}}class Ze extends M{evaluate(e){return e.currentKey??A}toString(){return"#"}}class He extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.key=n}resolve(e){const t=[];return e.value instanceof String||h(e.value)||l(e.value)&&L(e.value,this.key)&&t.push(new F(this.key,e.location.concat(`${C}${this.key}`),e.root)),t}*lazyResolve(e){!p(e.value)&&l(e.value)&&L(e.value,this.key)&&(yield new F(this.key,e.location.concat(`${C}${this.key}`),e.root))}toString(e){const{form:t}={...K,...e};return`~${("canonical"===t?_:P)(this.key)}`}}class et extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(n,e.location.concat(`${C}${n}`),e.root));return t}*lazyResolve(e){if(l(e.value)&&!p(e.value)&&!h(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(t,e.location.concat(`${C}${t}`),e.root)}toString(){return"~"}}class tt extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(n,e.location.concat(`${C}${n}`),e.root))}return t}*lazyResolve(e){if(!(e.value instanceof String||h(e.value))&&l(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(t,e.location.concat(`${C}${t}`),e.root))}}toString(e){return`~?${this.expression.toString(e)}`}}const nt=new Map([[ge.AND,5],[ge.EQ,6],[ge.GE,6],[ge.GT,6],[ge.LE,6],[ge.LT,6],[ge.NE,6],[ge.NOT,7],[ge.OR,4],[ge.RPAREN,1]]),rt=new Map([[ge.AND,"&&"],[ge.EQ,"=="],[ge.GE,">="],[ge.GT,">"],[ge.LE,"<="],[ge.LT,"<"],[ge.NE,"!="],[ge.OR,"||"]]),st=new Set(["==",">=",">","<=","<","!="]);class it{constructor(e){this.environment=e,this.tokenMap=new Map([[ge.FALSE,this.parseBoolean],[ge.NUMBER,this.parseNumber],[ge.LPAREN,this.parseGroupedExpression],[ge.NOT,this.parsePrefixExpression],[ge.NULL,this.parseNull],[ge.ROOT,this.parseRootQuery],[ge.CURRENT,this.parseRelativeQuery],[ge.SINGLE_QUOTE_STRING,this.parseString],[ge.DOUBLE_QUOTE_STRING,this.parseString],[ge.TRUE,this.parseBoolean],[ge.FUNCTION,this.parseFunction],[ge.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===ge.ROOT&&e.next();const t=this.parseQuery(e);if(e.current.kind!==ge.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parseQuery(e,t=!1){const n=[];e:for(;;){switch(e.current.kind){case ge.DDOT:{const t=e.next(),r=this.parseSelectors(e);n.push(new Ye(this.environment,t,r));break}case ge.LBRACKET:case ge.KEY:case ge.KEYS:case ge.NAME:case ge.WILD:{const t=e.current,r=this.parseSelectors(e);n.push(new We(this.environment,t,r));break}default:t&&e.backup();break e}e.next()}return n}parseSelectors(e){switch(e.current.kind){case ge.NAME:return[new Ue(this.environment,e.current,e.current.value)];case ge.WILD:return[new Ge(this.environment,e.current)];case ge.KEY:return[new He(this.environment,e.current,e.current.value)];case ge.KEYS:return[new et(this.environment,e.current)];case ge.LBRACKET:return this.parseBracketedSelection(e);default:return[]}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new De(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===ge.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(ge.COLON),e.next()):(n.push(void 0),e.expect(ge.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===ge.COLON&&e.next()):e.current.kind===ge.COLON&&(n.push(void 0),e.expect(ge.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Je(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==ge.RBRACKET;){switch(e.current.kind){case ge.SINGLE_QUOTE_STRING:case ge.DOUBLE_QUOTE_STRING:n.push(new Ue(this.environment,e.current,this.decodeString(e.current)));break;case ge.FILTER:n.push(this.parseFilter(e));break;case ge.INDEX:e.peek.kind===ge.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case ge.COLON:n.push(this.parseSlice(e));break;case ge.WILD:n.push(new Ge(this.environment,e.current));break;case ge.KEY_SINGLE_QUOTE_STRING:case ge.KEY_DOUBLE_QUOTE_STRING:n.push(new He(this.environment,e.current,this.decodeString(e.current)));break;case ge.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case ge.KEYS:n.push(new et(this.environment,e.current));break;case ge.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!==ge.RBRACKET&&(e.expectPeek(ge.COMMA),e.next(),e.expectPeekNot(ge.RBRACKET,"unexpected trailing comma")),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return n}parseFilter(e,t=!1){const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof X){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return this.throwForLiteral(r),t?new tt(this.environment,n,new B(n,r)):new Qe(this.environment,n,new B(n,r))}parseBoolean(e){return e.current.kind===ge.FALSE?new D(e.current,!1):new D(e.current,!0)}parseNull(e){return new U(e.current)}parseString(e){return new J(e.current,this.decodeString(e.current))}parseNumber(e){const t=e.current.value;if(t.startsWith("0")&&t.length>1)throw new a(`invalid number literal '${t}'`,e.current);const n=Number(e.current.value);if(isNaN(n))throw new a(`invalid number literal '${t}'`,e.current);return new G(e.current,n)}parsePrefixExpression(e){return e.expect(ge.NOT),e.next(),new Q(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=nt.get(n.kind)||1,s=this.parseFilterExpression(e,r),i=rt.get(n.kind);if(!i)throw new a(`unknown operator '${n.kind}'`,n);return st.has(i)?(this.throwForNonComparable(t),this.throwForNonComparable(s)):(this.throwForLiteral(t),this.throwForLiteral(s)),new V(n,t,i,s)}parseGroupedExpression(e){if(e.peek.kind===ge.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==ge.RPAREN;){if(e.current.kind===ge.EOF)throw new a("unbalanced parentheses",e.current);if(!rt.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(ge.RPAREN),t}parseRootQuery(e){const t=e.next();return new q(t,new Xe(this.environment,this.parseQuery(e,!0)))}parseRelativeQuery(e){const t=e.next();return new Y(t,new Xe(this.environment,this.parseQuery(e,!0)))}parseCurrentKey(e){return new Ze(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==ge.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(;rt.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==ge.RPAREN){if(e.peek.kind===ge.RBRACKET)break;e.expectPeek(ge.COMMA),e.next()}e.next()}return e.expect(ge.RPAREN),new X(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e,t=1){const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case ge.EOF:case ge.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===ge.EOF||n===ge.RBRACKET||(nt.get(n)||1)<t)break;if(!rt.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){return this.unescapeString(e.kind===ge.SINGLE_QUOTE_STRING?e.value.replaceAll('"','\\"').replaceAll("\\'","'"):e.value,e)}unescapeString(e,t){const n=[],r=e.length;let s,i=0;for(;i<r;){const r=e[i];if("\\"===r)switch(i+=1,e[i]){case'"':n.push('"');break;case"\\":n.push("\\");break;case"/":n.push("/");break;case"b":n.push("\b");break;case"f":n.push("\f");break;case"n":n.push("\n");break;case"r":n.push("\r");break;case"t":n.push("\t");break;case"u":[s,i]=this.decodeHexChar(e,i,t),n.push(this.stringFromCodePoint(s,t));break;default:throw new a("unknown escape sequence at index "+(t.index+i-1),t)}else this.stringFromCodePoint(r.codePointAt(0),t),n.push(r);i+=1}return n.join("")}decodeHexChar(e,t,n){const r=e.length;if(t+4>=r)throw new a("incomplete escape sequence at index "+(n.index+t-1),n);t+=1;let s=this.parseHexDigits(e.slice(t,t+4),n);if(ot(s))throw new a("unexpected low surrogate codepoint at index "+(n.index+t-2),n);if(function(e){return e>=55296&&e<=56319}(s)){if(!(t+9<r&&"\\"===e[t+4]&&"u"===e[t+5]))throw new a("incomplete escape sequence at index "+(n.index+t-2),n);const i=this.parseHexDigits(e.slice(t+6,t+10),n);if(!ot(i))throw new a(`unexpected codepoint at index ${n.index+t+4}`,n);return s=65536+((1023&s)<<10|1023&i),[s,t+9]}return[s,t+3]}parseHexDigits(e,t){const n=new TextEncoder;let r=0;for(const s of n.encode(e))switch(r<<=4,s){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:r|=s-48;break;case 97:case 98:case 99:case 100:case 101:case 102:r|=s-97+10;break;case 65:case 66:case 67:case 68:case 69:case 70:r|=s-65+10;break;default:throw new a("invalid \\uXXXX escape sequence",t)}return r}stringFromCodePoint(e,t){if(void 0===e||e<=31)throw new a("invalid character",t);try{return String.fromCodePoint(e)}catch{throw new a("invalid escape sequence",t)}}throwForNonComparable(e){if((e instanceof q||e instanceof Y)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof X){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof j)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}function ot(e){return e>=56320&&e<=57343}class at{functionRegister=new Map;constructor(e={}){this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??1-Math.pow(2,53),this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new it(this),this.setupFilterFunctions()}compile(e){return new Xe(this,this.parser.parse(new ve(Te(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new re),this.functionRegister.set("length",new se),this.functionRegister.set("search",new fe),this.functionRegister.set("match",new pe),this.functionRegister.set("value",new de)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new o(`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,i,o]of n.argTypes.map((e,n)=>[e,t[n],n]))switch(r){case g.ValueType:if(!(i instanceof j||i instanceof Ze||i instanceof W&&i.path.singularQuery()||i instanceof X&&this.functionRegister.get(i.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${o} must be of ValueType`,i.token);break;case g.LogicalType:if(!(i instanceof W||i instanceof V))throw new s(`${e.value}() argument ${o} must be of LogicalType`,i.token);break;case g.NodesType:if(!(i instanceof W||i instanceof X&&this.functionRegister.get(i.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${o} must be of NodesType`,i.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 ct=Object.freeze({__proto__:null,Count:re,FunctionExpressionType:g,Has:class{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.search=e.search??!0,this.#t=new ie(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!l(e)&&Object.keys(e).some(e=>!!e.match(n))}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=this.search?new RegExp(oe(t),"u"):new RegExp(oe(ae(t)),"u");return this.cacheSize>0&&this.#t.set(t,n),!!l(e)&&Object.keys(e).some(e=>!!e.match(n))}catch(e){if(this.throwErrors)throw e;return!1}}},Length:se,Match:pe,Search:fe,Value:de});const ut=new at;function ht(e,t){return ut.query(e,t)}function lt(e,t){return ut.lazyQuery(e,t)}function pt(e){return ut.compile(e)}var ft=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:ut,FunctionExpressionType:g,JSONPathEnvironment:at,JSONPathError:t,JSONPathIndexError:i,JSONPathLexerError:r,JSONPathNode:F,JSONPathNodeList:z,JSONPathQuery:Xe,JSONPathRecursionLimitError:c,JSONPathSegment:Be,JSONPathSelector:je,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:C,Nothing:A,Token:me,TokenKind:ge,compile:pt,expressions:ne,functions:ct,lazyQuery:lt,match:function(e,t){return ut.match(e,t)},query:ht,selectors:Ve});class dt extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class gt extends dt{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class mt{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){return kt(e,this.path,this.value,this.name,t)}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class vt{name="remove";constructor(e){this.path=e}apply(e,t){return Ot(e,this.path,this.name,t),e}toObject(){return{op:this.name,path:this.path.toString()}}}class wt{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new dt(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new dt(`can't replace nonexistent item (${this.name}:${t})`);return n.splice(Number(s),1,this.value),e}if(l(n)){if(r===k)throw new dt(`can't replace nonexistent property (${this.name}:${t})`);return n[s]=this.value,e}throw new dt(`unexpected operation on '${typeof n}' (${this.name}:${t})`)}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class xt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new dt(`can't move object to one of its own children (${this.name}:${t})`);const n=Ot(e,this.from,this.name,t);return kt(e,this.path,n,this.name,t)}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class Et{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new dt(`source object does not exist (${this.name}:${t})`);return kt(e,this.path,r,this.name,t)}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class yt{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!d(r,this.value))throw new gt(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}function kt(e,t,n,r,s){const[i,o]=t.resolveWithParent(e);if(i===k)return n;const a=t.tokens.at(-1);if(void 0===a)throw new dt(`unexpected operation on 'undefined' (${r}:${s})`);if(h(i)){if(o===k){if("-"!==a&&Number(a)!==i.length)throw new dt(`index out of range (${r}:${s})`);return i.push(n),e}return i.splice(Number(a),0,n),e}if(l(i))return i[a]=n,e;throw new dt(`unexpected operation on '${typeof i}' (${r}:${s})`)}function Ot(e,t,n,r){const[s,i]=t.resolveWithParent(e);if(s===k)throw new dt(`can't remove root (${n}:${r})`);const o=t.tokens.at(-1);if(void 0===o)throw new dt(`unexpected operation on 'undefined' (${n}:${r})`);if(h(s)){if(i===k)throw new dt(`can't ${n} nonexistent item (${n}:${r})`);return s.splice(Number(o),1),i}if(l(s)){if(i===k)throw new dt(`can't ${n} nonexistent property (${n}:${r})`);return delete s[o],i}throw new dt(`unexpected operation on '${typeof s}' (${n}:${r})`)}class St{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 mt(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new vt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new wt(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new xt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Et(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new yt(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof v)throw new dt(`${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 dt(`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 dt(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new dt(`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 dt(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new dt(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!p(e))throw new dt(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new dt(`${e.message} (${t}:${n})`);throw e}}}function Nt(e,t){return new St(e).apply(t)}var Tt=Object.freeze({__proto__:null,JSONPatch:St,JSONPatchError:dt,JSONPatchTestFailure:gt,apply:Nt});return e.DEFAULT_ENVIRONMENT=ut,e.FunctionExpressionType=g,e.JSONPatch=St,e.JSONPatchError=dt,e.JSONPatchTestFailure=gt,e.JSONPathEnvironment=at,e.JSONPathError=t,e.JSONPathIndexError=i,e.JSONPathLexerError=r,e.JSONPathNode=F,e.JSONPathNodeList=z,e.JSONPathQuery=Xe,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=A,e.RelativeJSONPointer=T,e.Token=me,e.TokenKind=ge,e.UNDEFINED=k,e.apply=Nt,e.compile=pt,e.jsonpatch=Tt,e.jsonpath=ft,e.jsonpointer=b,e.lazyQuery=lt,e.query=ht,e.resolve=R,e.version="2.3.1",e}({});
1
+ var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class c extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}class u extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function h(e){return Array.isArray(e)}function l(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function p(e){return"string"==typeof e}function f(e){return"number"==typeof e}function d(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}return!1}if(l(e)&&l(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!d(e[r],t[r]))return!1;return!0}return!1}let g=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class m extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class w extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class E extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const k=Symbol.for("jsonpointer.undefined");class O{#e;constructor(e){this.tokens=this.parse(e),this.#e=O.encode(this.tokens)}static encode(e){return e.length?"/"+e.map(e=>e.replaceAll("~","~0").replaceAll("/","~1")).join("/"):""}resolve(e,t=k){try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==k)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[k,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof w||e instanceof x)return[t,k];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every((t,n)=>t===e.tokens[n])}parse(e){if(e.length&&!e.startsWith("/"))throw new 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(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(N.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(l(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new x(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(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(...e){if(!e.length)return this;let t=this;for(const n of e)t=t._join(n);return t}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new O(O.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const S=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,N=/(0|[1-9]\d*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new O(e):e;if(this.origin>t.tokens.length)throw new w(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new w(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof O?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new O(O.encode(n))}parse(e){const t=S.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(N.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||N.test(e)}}function R(e,t,n=k){return new O(e).resolve(t,n)}var b=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:x,JSONPointerResolutionError:v,JSONPointerSyntaxError:E,JSONPointerTypeError:y,RelativeJSONPointer:T,UNDEFINED:k,resolve:R});const $=/^[\p{ID_Start}_]\p{ID_Continue}*$/u;function P(e){return e.includes("'")&&!e.includes('"')?JSON.stringify(e):_(e)}function _(e){return`'${JSON.stringify(e).slice(1,-1).replaceAll('\\"','"').replaceAll("'","\\'")}'`}function I(e){return $.test(e)?e:null}const A=Symbol.for("jsonpath.nothing");function L(e,t){return l(e)&&Object.hasOwn(e,t)}const C="",K={form:"pretty"};class F{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return this.getPath({form:"canonical"})}getPath(e){const t={...K,...e};return"$"+this.location.map(e=>p(e)?this.decodeNameLocation(e,t):`[${e}]`).join("")}toPointer(){return this.location.length?new O(O.encode(this.location.map(String))):new O("")}decodeNameLocation(e,t){const n="canonical"===t.form,r=n?_:P,s=e.startsWith(C);s&&(e=e.slice(1));const o=I(e);return s?n||null==o?`[~${r(e)}]`:`.~${o}`:n||null==o?`[${r(e)}]`:`.${o}`}}class z{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map(e=>e.value)}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map(e=>e.value)}locations(){return this.nodes.map(e=>e.location)}paths(e){return this.nodes.map(t=>t.getPath(e))}pointers(){return this.nodes.map(e=>e.toPointer())}get length(){return this.nodes.length}}class M{constructor(e){this.token=e}}class j extends M{}class U extends j{evaluate(){return null}toString(){return"null"}}class D extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class J extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return _(this.value)}}class G extends j{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class Q extends M{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 z?0===t.nodes.length:!Z(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(e){return`${this.operator}${this.right.toString(e)}`}}class V extends M{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 z&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof z&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?Z(t)&&Z(n):"||"===this.operator?Z(t)||Z(n):H(t,this.operator,n)}toString(e){return this.logical?`(${this.left.toString(e)} ${this.operator} ${this.right.toString(e)})`:`${this.left.toString(e)} ${this.operator} ${this.right.toString(e)}`}}class B extends M{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof z?t.nodes.length>0:Z(t)}toString(e){return function t(n,r){if(n instanceof V){let s,o,i,a;if("&&"===n.operator)s=5,o="&&",i=t(n.left,s),a=t(n.right,s);else{if("||"!==n.operator)return n.toString(e);s=4,o="||",i=t(n.left,s),a=t(n.right,s)}const c=`${i} ${o} ${a}`;return s<r?`(${c})`:c}if(n instanceof Q){const e=`!${t(n.right,7)}`;return r>7?`(${e})`:e}return n.toString(e)}(this.expression,0)}}class W extends M{constructor(e,t){super(e),this.token=e,this.path=t}}class Y extends W{evaluate(e){return e.lazy?new z(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(e){return`@${this.path.toString(e).slice(1)}`}}class q extends W{evaluate(e){return e.lazy?new z(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(e){return this.path.toString(e)}}class X extends M{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map(t=>t.evaluate(e)).map((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof z?this.unpack_node_list(e):e);return t.call(...n)}toString(e){return`${this.name}(${this.args.map(t=>t.toString(e)).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return A;case 1:return e.nodes[0].value;default:return e}}}function Z(e){return!(e instanceof z&&e.empty())&&!("boolean"==typeof e&&!1===e)}function H(e,t,n){switch(t){case"==":return ee(e,n);case"!=":return!ee(e,n);case"<":return te(e,n);case">":return te(n,e);case">=":return te(n,e)||ee(e,n);case"<=":return te(e,n)||ee(e,n);default:return!1}}function ee(e,t){if(t instanceof z&&([e,t]=[t,e]),e instanceof z){if(t instanceof z){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===A:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===A&&t===A||d(e,t)}function te(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var ne=Object.freeze({__proto__:null,BooleanLiteral:D,FilterExpression:M,FilterExpressionLiteral:j,FilterQuery:W,FunctionExtension:X,InfixExpression:V,LogicalExpression:B,NullLiteral:U,NumberLiteral:G,PrefixExpression:Q,RelativeQuery:Y,RootQuery:q,StringLiteral:J,compare:H});class re{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return e.length}}class se{argTypes=[g.ValueType];returnType=g.ValueType;call(e){return h(e)||p(e)?e.length:l(e)?Object.keys(e).length:A}}class oe extends Map{constructor(e=128,t){void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){if(this.has(e))this.delete(e);else if(this.size>=this.maxSize){const e=this.first();void 0!==e&&this.delete(e)}return super.set(e,t)}first(){return this.keys().next().value}}function ie(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ae(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(ie(e)),n||r||t.push(")$"),t.join("")}function ce(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ce.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function ue(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ce,Error),ce.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,i=this.location.source+":"+o.line+":"+o.column;if(r){var a=this.location.end,c=ue("",o.line.toString().length," "),u=r[s.line-1],h=(s.line===a.line?a.column:u.length+1)-s.column||1;t+="\n --\x3e "+i+"\n"+c+" |\n"+o.line+" | "+u+"\n"+c+" | "+ue("",s.column-1," ")+ue("",h,"^")}else t+="\n at "+i}return t},ce.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map(function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)});return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(i);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const he={StartRules:["start"],SyntaxError:ce,parse:function(e,t){var n,r,s,o,i={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ie},u=Ie,h="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",x="^",E="-",y="]",k="\\p{",O="\\P{",S="L",N="M",T="N",R="P",b="Z",$="S",P="C",_=/^[*-+?]/,I=/^[0-9]/,A=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,z=/^[lps]/,M=/^[ckmo]/,j=/^[cfn-o]/,U=Re("|",!1),D=be([["*","+"],"?"],!1,!1),J=Re("{",!1),G=be([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),B=Re("(",!1),W=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=be([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),ne=Re("]",!1),re=Re("\\p{",!1),se=Re("\\P{",!1),oe=Re("L",!1),ie=be([["l","m"],"o",["t","u"]],!1,!1),ae=Re("M",!1),ue=be(["c","e","n"],!1,!1),he=Re("N",!1),le=be(["d","l","o"],!1,!1),pe=Re("P",!1),fe=be([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=be(["l","p","s"],!1,!1),me=Re("S",!1),ve=be(["c","k","m","o"],!1,!1),we=Re("C",!1),xe=be(["c","f",["n","o"]],!1,!1),Ee=function(e){return function(e){return e<"'"||","===e||"-"===e||e>="/"&&e<=">"||e>="@"&&e<="Z"||e>="^"&&e<="z"||e>="~"&&e<="퟿"||e>=""}(e)},ye=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},ke=0|t.peg$currPos,Oe=[{line:1,column:1}],Se=ke,Ne=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function be(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function $e(t){var n,r=Oe[t];if(r)return r;if(t>=Oe.length)n=Oe.length-1;else for(n=t;!Oe[--n];);for(r={line:(r=Oe[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return Oe[t]=r,r}function Pe(e,t,n){var r=$e(e),s=$e(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function _e(e){ke<Se||(ke>Se&&(Se=ke,Ne=[]),Ne.push(e))}function Ie(){return Ae()}function Ae(){var t,n,r,s;for(t=Le(),n=[],r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(U)),s!==i?r=s=[s,Le()]:(ke=r,r=i);r!==i;)n.push(r),r=ke,124===e.charCodeAt(ke)?(s=h,ke++):(s=i,0===Te&&_e(U)),s!==i?r=s=[s,Le()]:(ke=r,r=i);return t=[t,n]}function Le(){var e,t;for(e=[],t=Ce();t!==i;)e.push(t),t=Ce();return e}function Ce(){var t,n,r;return t=ke,n=function(){var t,n,r,s;t=function(){var t,n;t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y));n!==i&&(Ee(n)?void 0:i)!==i?t=n:(ke=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(ke)?(t=m,ke++):(t=i,0===Te&&_e(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=ke,91===e.charCodeAt(ke)?(n=w,ke++):(n=i,0===Te&&_e(H));if(n!==i)if(94===e.charCodeAt(ke)?(r=x,ke++):(r=i,0===Te&&_e(ee)),r===i&&(r=null),45===e.charCodeAt(ke)?(s=E,ke++):(s=i,0===Te&&_e(te)),s===i&&(s=ze()),s!==i){for(o=[],a=ze();a!==i;)o.push(a),a=ze();45===e.charCodeAt(ke)?(a=E,ke++):(a=i,0===Te&&_e(te)),a===i&&(a=null),93===e.charCodeAt(ke)?(c=y,ke++):(c=i,0===Te&&_e(ne)),c!==i?t=n=[n,r,s,o,a,c]:(ke=t,t=i)}else ke=t,t=i;else ke=t,t=i;return t}());return t}(),t===i&&(t=ke,40===e.charCodeAt(ke)?(n=d,ke++):(n=i,0===Te&&_e(B)),n!==i&&(r=Ae())!==i?(41===e.charCodeAt(ke)?(s=g,ke++):(s=i,0===Te&&_e(W)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(ke),_.test(t)?ke++:(t=i,0===Te&&_e(D));t===i&&(t=function(){var t,n,r,s,o,a,c;t=ke,123===e.charCodeAt(ke)?(n=l,ke++):(n=i,0===Te&&_e(J));if(n!==i){if(r=[],s=e.charAt(ke),I.test(s)?ke++:(s=i,0===Te&&_e(G)),s!==i)for(;s!==i;)r.push(s),s=e.charAt(ke),I.test(s)?ke++:(s=i,0===Te&&_e(G));else r=i;if(r!==i){if(s=ke,44===e.charCodeAt(ke)?(o=p,ke++):(o=i,0===Te&&_e(Q)),o!==i){for(a=[],c=e.charAt(ke),I.test(c)?ke++:(c=i,0===Te&&_e(G));c!==i;)a.push(c),c=e.charAt(ke),I.test(c)?ke++:(c=i,0===Te&&_e(G));s=o=[o,a]}else ke=s,s=i;s===i&&(s=null),125===e.charCodeAt(ke)?(o=f,ke++):(o=i,0===Te&&_e(V)),o!==i?t=n=[n,r,s,o]:(ke=t,t=i)}else ke=t,t=i}else ke=t,t=i;return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t}function Ke(){var t,n,r;return t=ke,92===e.charCodeAt(ke)?(n=v,ke++):(n=i,0===Te&&_e(X)),n!==i?(r=e.charAt(ke),A.test(r)?ke++:(r=i,0===Te&&_e(Z)),r!==i?t=n=[n,r]:(ke=t,t=i)):(ke=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===k?(n=k,ke+=3):(n=i,0===Te&&_e(re));n!==i&&(r=je())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===O?(n=O,ke+=3):(n=i,0===Te&&_e(se));n!==i&&(r=je())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}()),t}function ze(){var t,n,r,s,o;return t=ke,(n=Me())!==i?(r=ke,45===e.charCodeAt(ke)?(s=E,ke++):(s=i,0===Te&&_e(te)),s!==i&&(o=Me())!==i?r=s=[s,o]:(ke=r,r=i),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t===i&&(t=Fe()),t}function Me(){var t,n;return t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y)),n!==i&&(ye(n)?void 0:i)!==i?t=n:(ke=t,t=i),t===i&&(t=Ke()),t}function je(){var t;return(t=function(){var t,n,r;t=ke,76===e.charCodeAt(ke)?(n=S,ke++):(n=i,0===Te&&_e(oe));n!==i?(r=e.charAt(ke),L.test(r)?ke++:(r=i,0===Te&&_e(ie)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,77===e.charCodeAt(ke)?(n=N,ke++):(n=i,0===Te&&_e(ae));n!==i?(r=e.charAt(ke),C.test(r)?ke++:(r=i,0===Te&&_e(ue)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,78===e.charCodeAt(ke)?(n=T,ke++):(n=i,0===Te&&_e(he));n!==i?(r=e.charAt(ke),K.test(r)?ke++:(r=i,0===Te&&_e(le)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,80===e.charCodeAt(ke)?(n=R,ke++):(n=i,0===Te&&_e(pe));n!==i?(r=e.charAt(ke),F.test(r)?ke++:(r=i,0===Te&&_e(fe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,90===e.charCodeAt(ke)?(n=b,ke++):(n=i,0===Te&&_e(de));n!==i?(r=e.charAt(ke),z.test(r)?ke++:(r=i,0===Te&&_e(ge)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,83===e.charCodeAt(ke)?(n=$,ke++):(n=i,0===Te&&_e(me));n!==i?(r=e.charAt(ke),M.test(r)?ke++:(r=i,0===Te&&_e(ve)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,67===e.charCodeAt(ke)?(n=P,ke++):(n=i,0===Te&&_e(we));n!==i?(r=e.charAt(ke),j.test(r)?ke++:(r=i,0===Te&&_e(xe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}()),t}if(n=u(),t.peg$library)return{peg$result:n,peg$currPos:ke,peg$FAILED:i,peg$maxFailExpected:Ne,peg$maxFailPos:Se};if(n!==i&&ke===e.length)return n;throw n!==i&&ke<e.length&&_e({type:"end"}),r=Ne,s=Se<e.length?e.charAt(Se):null,o=Se<e.length?Pe(Se,Se+1):Pe(Se,Se),new ce(ce.buildMessage(r,s),r,s,o)}};var le=function(e){try{he.parse(e,{})}catch(e){if(e instanceof he.SyntaxError)return!1;throw e}return!0};class pe{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new oe(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(ae(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}}class fe{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new oe(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(ie(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class de{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return 1===e.length?e.nodes[0].value:A}}let ge=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 me{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new me(ge.EOF,"",-1,"");class ve{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}expectPeekNot(e,t){const n=this.peek;if(n.kind===e)throw new a(t,n)}}const we=/[eE][+-]?\d+/y,xe=/[a-z][a-z_0-9]*/y,Ee=/-?\d+/y,ye=/-?\d+/y,ke=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,Oe=new Set([" ","\n","\t","\r"]),Se=/[\u0080-\uFFFFa-zA-Z_]/;class Ne{filterLevel=0;funcCallStack=[];bracketStack=[];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=Re;for(;e;)e=e(this)}emit(e){this.tokens.push(new me(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 me(ge.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 me(ge.ERROR,e,this.pos,this.path))}return!!this.acceptRun(Oe)&&(this.ignore(),!0)}error(e){this.tokens.push(new me(ge.ERROR,e,this.#n,this.path))}}function Te(e,t){const[n,r]=function(e,t){const n=new Ne(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===ge.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);if(0!==n.bracketStack.length){const[e,r]=n.bracketStack[n.bracketStack.length-1];throw new a("unbalanced brackets",new me(ge.ERROR,e,r,t))}return r}function Re(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(ge.ROOT),be)}function be(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(ge.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(ge.DDOT),$e):Pe;case"[":return e.bracketStack.push(["[",e.start]),e.emit(ge.LBRACKET),_e;default:return e.backup(),e.filterLevel?Ie:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function $e(e){if(e.acceptMatchRun(ke))return e.emit(ge.NAME),be;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(Se)?(e.ignore(),e.acceptMatchRun(ke),e.emit(ge.KEY),be):(e.emit(ge.KEYS),be);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ge.KEYS),be}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(ge.WILD),be;case"[":return e.bracketStack.push(["[",e.start]),e.emit(ge.LBRACKET),_e;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function Pe(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(Se)?(e.ignore(),e.acceptMatchRun(ke),e.emit(ge.KEY),be):(e.emit(ge.KEYS),be);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(ge.KEYS),be}if(e.acceptMatchRun(ke))return e.emit(ge.NAME),be;const t=e.next();return"*"===t?(e.emit(ge.WILD),be):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function _e(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(Ee)){e.emit(ge.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),ze(e);case'"':return e.ignore(),e.next(),Me(e);case"?":return e.next(),e.emit(ge.KEYS_FILTER),e.filterLevel+=1,Ie;default:e.emit(ge.KEYS);continue}const t=e.next();switch(t){case"]":return 0===e.bracketStack.length||"["!==e.bracketStack[e.bracketStack.length-1][0]?(e.backup(),e.error("unbalanced brackets"),null):(e.bracketStack.pop(),e.emit(ge.RBRACKET),be);case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(ge.WILD);continue;case"?":return e.emit(ge.FILTER),e.filterLevel+=1,Ie;case",":e.emit(ge.COMMA);continue;case":":e.emit(ge.COLON);continue;case"'":return Le;case'"':return Ce;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function Ie(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,e.backup(),_e;case",":if(e.emit(ge.COMMA),e.funcCallStack.length)continue;return e.filterLevel-=1,_e;case"'":return Ke;case'"':return Fe;case"(":e.bracketStack.push(["(",e.start]),e.emit(ge.LPAREN),e.funcCallStack.length&&(e.funcCallStack[e.funcCallStack.length-1]+=1);continue;case")":if(0===e.bracketStack.length||"("!==e.bracketStack[e.bracketStack.length-1][0])return e.backup(),e.error("unbalanced brackets"),null;e.bracketStack.pop(),e.emit(ge.RPAREN),e.funcCallStack.length&&(1===e.funcCallStack[e.funcCallStack.length-1]?e.funcCallStack.pop():e.funcCallStack[e.funcCallStack.length-1]-=1);continue;case"$":return e.emit(ge.ROOT),be;case"@":return e.emit(ge.CURRENT),be;case"#":return e.environment.strict?(e.backup(),e.error(`unexpected filter selector token '${t}'`),null):(e.emit(ge.CURRENT_KEY),be);case".":return e.backup(),be;case"!":"="===e.peek()?(e.next(),e.emit(ge.NE)):e.emit(ge.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(ge.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(ge.LE)):e.emit(ge.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(ge.GE)):e.emit(ge.GT);continue;default:if(e.backup(),e.acceptMatchRun(ye)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ye)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(we),e.emit(ge.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(ge.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(ge.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(ge.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(ge.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(ge.NULL);continue}if(e.acceptMatchRun(xe)&&"("===e.peek()){e.funcCallStack.push(1),e.emit(ge.FUNCTION),e.bracketStack.push(["(",e.start]),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Ae(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?ge.SINGLE_QUOTE_STRING:ge.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 Le=Ae("'",_e,ge.SINGLE_QUOTE_STRING),Ce=Ae('"',_e,ge.DOUBLE_QUOTE_STRING),Ke=Ae("'",Ie,ge.SINGLE_QUOTE_STRING),Fe=Ae('"',Ie,ge.DOUBLE_QUOTE_STRING),ze=Ae("'",_e,ge.KEY_SINGLE_QUOTE_STRING),Me=Ae('"',_e,ge.KEY_DOUBLE_QUOTE_STRING);class je{constructor(e,t){this.environment=e,this.token=t}}class Ue extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.name=n}resolve(e){const t=[];return!h(e.value)&&L(e.value,this.name)&&t.push(new F(e.value[this.name],e.location.concat(this.name),e.root)),t}*lazyResolve(e){!h(e.value)&&L(e.value,this.name)&&(yield new F(e.value[this.name],e.location.concat(this.name),e.root))}toString(e){const{form:t}={...K,...e};return"canonical"===t?_(this.name):P(this.name)}shorthand(){return I(this.name)}}class De extends je{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];if(h(e.value)){const n=this.normalizedIndex(e.value.length);n in e.value&&t.push(new F(e.value[n],e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value)){const t=this.normalizedIndex(e.value.length);t in e.value&&(yield new F(e.value[t],e.location.concat(t),e.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Je extends je{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];if(!h(e.value))return t;for(const[n,r]of this.slice(e.value,this.start,this.stop,this.step))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(const[t,n]of this.lazySlice(e.value,this.start,this.stop,this.step))yield new F(n,e.location.concat(t),e.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(...e){for(const t of e)if(void 0!==t&&(t<this.environment.minIntIndex||t>this.environment.maxIntIndex))throw new o("index out of range",this.token)}slice(e,t,n,r){const s=e.length;if(0===(r=r??1)||!s)return[];const o=[];let i;if(r>0){i=this.normalizeIndex(t,0,s,r);const a=this.normalizeIndex(n,s,s,r);for(;i<a;i+=r)o.push([i,e[i]])}else{i=this.normalizeIndex(t,s-1,s,r);const a=this.normalizeIndex(n,-1,s,r);for(;i>a;i+=r)o.push([i,e[i]])}return o}*lazySlice(e,t,n,r){const s=e.length;if(0===(r=r??1)||!s)return[];let o;if(r>0){o=this.normalizeIndex(t,0,s,r);const i=this.normalizeIndex(n,s,s,r);for(;o<i;o+=r)yield[o,e[o]]}else{o=this.normalizeIndex(t,s-1,s,r);const i=this.normalizeIndex(n,-1,s,r);for(;o>i;o+=r)yield[o,e[o]]}}normalizeIndex(e,t,n,r){return void 0===e?t:e<0?r<0?Math.max(e+n,-1):Math.max(e+n,0):r<0?Math.min(e,n-1):Math.min(e,n)}}class Ge extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++)t.push(new F(e.value[n],e.location.concat(n),e.root));else if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(r,e.location.concat(n),e.root));return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}toString(){return"*"}}class Qe extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String)return t;if(h(e.value))for(let n=0;n<e.value.length;n++){const r=e.value[n],s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(r,e.location.concat(n),e.root))}return t}*lazyResolve(e){if(h(e.value))for(let t=0;t<e.value.length;t++){const n=e.value[t],r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}else if(l(e.value)&&!p(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(n,e.location.concat(t),e.root))}}toString(e){return`?${this.expression.toString(e)}`}}var Ve=Object.freeze({__proto__:null,FilterSelector:Qe,IndexSelector:De,JSONPathSelector:je,NameSelector:Ue,SliceSelector:Je,WildcardSelector:Ge});class Be{constructor(e,t,n){this.environment=e,this.token=t,this.selectors=n}}class We extends Be{resolve(e){const t=[];for(const n of e)for(const e of this.selectors)for(const r of e.resolve(n))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.selectors)yield*e.resolve(t)}toString(e){const{form:t}={...K,...e};if("pretty"===t&&1===this.selectors.length&&this.selectors[0]instanceof Ue){const e=this.selectors[0].shorthand();if(null!=e)return`.${e}`}return`[${this.selectors.map(t=>t.toString(e)).join(", ")}]`}}class Ye extends Be{resolve(e){const t=[],n=(this.environment.nondeterministic?this.nondeterministicVisit:this.visit).bind(this);for(const r of e)for(const e of n(r))for(const n of this.selectors)for(const r of n.resolve(e))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.visit(t))for(const t of this.selectors)yield*t.resolve(e)}toString(e){return`..[${this.selectors.map(t=>t.toString(e)).join(", ")}]`}*visit(e,t=1){if(t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);if(yield e,h(e.value))for(let n=0;n<e.value.length;n++){const r=new F(e.value[n],e.location.concat(n),e.root);yield*this.visit(r,t+1)}else if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s=new F(r,e.location.concat(n),e.root);yield*this.visit(s,t+1)}}*nondeterministicVisit(e,t=1){let n=Array.from(this.nondeterministicChildren(e)).map(e=>[e,t]);for(yield e;n.length;){const[e,t]=n.shift();if(yield e,t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const r=Math.random()<.5;for(const s of this.nondeterministicChildren(e))if(r){yield s;n=qe(n,Array.from(this.nondeterministicChildren(s)).map(e=>[e,t+2]))}else n.push([s,t+1])}}*nondeterministicChildren(e){if(!p(e.value))if(h(e.value))for(let t=0;t<e.value.length;t++)yield new F(e.value[t],e.location.concat(t),e.root);else if(l(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(n,e.location.concat(t),e.root)}}function qe(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map(e=>e.next().value)}class Xe{constructor(e,t){this.environment=e,this.segments=t}query(e){let t=[new F(e,[],e)];for(const e of this.segments)t=e.resolve(t);return new z(t)}lazyQuery(e){let t=[new F(e,[],e)][Symbol.iterator]();for(const e of this.segments)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(e){return`$${this.segments.map(t=>t.toString(e)).join("")}`}singularQuery(){for(const e of this.segments){if(e instanceof Ye)return!1;if(1!==e.selectors.length||!(e.selectors[0]instanceof Ue||e.selectors[0]instanceof De))return!1}return!0}}class Ze extends M{evaluate(e){return e.currentKey??A}toString(){return"#"}}class He extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.key=n}resolve(e){const t=[];return e.value instanceof String||h(e.value)||l(e.value)&&L(e.value,this.key)&&t.push(new F(this.key,e.location.concat(`${C}${this.key}`),e.root)),t}*lazyResolve(e){!p(e.value)&&l(e.value)&&L(e.value,this.key)&&(yield new F(this.key,e.location.concat(`${C}${this.key}`),e.root))}toString(e){const{form:t}={...K,...e};return`~${("canonical"===t?_:P)(this.key)}`}}class et extends je{constructor(e,t){super(e,t),this.environment=e,this.token=t}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new F(n,e.location.concat(`${C}${n}`),e.root));return t}*lazyResolve(e){if(l(e.value)&&!p(e.value)&&!h(e.value))for(const[t,n]of this.environment.entries(e.value))yield new F(t,e.location.concat(`${C}${t}`),e.root)}toString(){return"~"}}class tt extends je{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];if(e.value instanceof String||h(e.value))return t;if(l(e.value))for(const[n,r]of this.environment.entries(e.value)){const s={environment:this.environment,currentValue:r,rootValue:e.root,currentKey:n};this.expression.evaluate(s)&&t.push(new F(n,e.location.concat(`${C}${n}`),e.root))}return t}*lazyResolve(e){if(!(e.value instanceof String||h(e.value))&&l(e.value))for(const[t,n]of this.environment.entries(e.value)){const r={environment:this.environment,currentValue:n,rootValue:e.root,lazy:!0,currentKey:t};this.expression.evaluate(r)&&(yield new F(t,e.location.concat(`${C}${t}`),e.root))}}toString(e){return`~?${this.expression.toString(e)}`}}const nt=new Map([[ge.AND,5],[ge.EQ,6],[ge.GE,6],[ge.GT,6],[ge.LE,6],[ge.LT,6],[ge.NE,6],[ge.NOT,7],[ge.OR,4],[ge.RPAREN,1]]),rt=new Map([[ge.AND,"&&"],[ge.EQ,"=="],[ge.GE,">="],[ge.GT,">"],[ge.LE,"<="],[ge.LT,"<"],[ge.NE,"!="],[ge.OR,"||"]]),st=new Set(["==",">=",">","<=","<","!="]);class ot{constructor(e){this.environment=e,this.tokenMap=new Map([[ge.FALSE,this.parseBoolean],[ge.NUMBER,this.parseNumber],[ge.LPAREN,this.parseGroupedExpression],[ge.NOT,this.parsePrefixExpression],[ge.NULL,this.parseNull],[ge.ROOT,this.parseRootQuery],[ge.CURRENT,this.parseRelativeQuery],[ge.SINGLE_QUOTE_STRING,this.parseString],[ge.DOUBLE_QUOTE_STRING,this.parseString],[ge.TRUE,this.parseBoolean],[ge.FUNCTION,this.parseFunction],[ge.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===ge.ROOT&&e.next();const t=this.parseQuery(e);if(e.current.kind!==ge.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parseQuery(e,t=!1){const n=[];e:for(;;){switch(e.current.kind){case ge.DDOT:{const t=e.next(),r=this.parseSelectors(e);n.push(new Ye(this.environment,t,r));break}case ge.LBRACKET:case ge.KEY:case ge.KEYS:case ge.NAME:case ge.WILD:{const t=e.current,r=this.parseSelectors(e);n.push(new We(this.environment,t,r));break}default:t&&e.backup();break e}e.next()}return n}parseSelectors(e){switch(e.current.kind){case ge.NAME:return[new Ue(this.environment,e.current,e.current.value)];case ge.WILD:return[new Ge(this.environment,e.current)];case ge.KEY:return[new He(this.environment,e.current,e.current.value)];case ge.KEYS:return[new et(this.environment,e.current)];case ge.LBRACKET:return this.parseBracketedSelection(e);default:return[]}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new De(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===ge.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(ge.COLON),e.next()):(n.push(void 0),e.expect(ge.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===ge.COLON&&e.next()):e.current.kind===ge.COLON&&(n.push(void 0),e.expect(ge.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Je(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==ge.RBRACKET;){switch(e.current.kind){case ge.SINGLE_QUOTE_STRING:case ge.DOUBLE_QUOTE_STRING:n.push(new Ue(this.environment,e.current,this.decodeString(e.current)));break;case ge.FILTER:n.push(this.parseFilter(e));break;case ge.INDEX:e.peek.kind===ge.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case ge.COLON:n.push(this.parseSlice(e));break;case ge.WILD:n.push(new Ge(this.environment,e.current));break;case ge.KEY_SINGLE_QUOTE_STRING:case ge.KEY_DOUBLE_QUOTE_STRING:n.push(new He(this.environment,e.current,this.decodeString(e.current)));break;case ge.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case ge.KEYS:n.push(new et(this.environment,e.current));break;case ge.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!==ge.RBRACKET&&(e.expectPeek(ge.COMMA),e.next(),e.expectPeekNot(ge.RBRACKET,"unexpected trailing comma")),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return n}parseFilter(e,t=!1){const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof X){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return this.throwForLiteral(r),t?new tt(this.environment,n,new B(n,r)):new Qe(this.environment,n,new B(n,r))}parseBoolean(e){return e.current.kind===ge.FALSE?new D(e.current,!1):new D(e.current,!0)}parseNull(e){return new U(e.current)}parseString(e){return new J(e.current,this.decodeString(e.current))}parseNumber(e){const t=e.current.value;if(t.startsWith("0")&&t.length>1)throw new a(`invalid number literal '${t}'`,e.current);const n=Number(e.current.value);if(isNaN(n))throw new a(`invalid number literal '${t}'`,e.current);return new G(e.current,n)}parsePrefixExpression(e){return e.expect(ge.NOT),e.next(),new Q(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=nt.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=rt.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return st.has(o)?(this.throwForNonComparable(t),this.throwForNonComparable(s)):(this.throwForLiteral(t),this.throwForLiteral(s)),new V(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===ge.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==ge.RPAREN;){if(e.current.kind===ge.EOF)throw new a("unbalanced parentheses",e.current);if(!rt.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(ge.RPAREN),t}parseRootQuery(e){const t=e.next();return new q(t,new Xe(this.environment,this.parseQuery(e,!0)))}parseRelativeQuery(e){const t=e.next();return new Y(t,new Xe(this.environment,this.parseQuery(e,!0)))}parseCurrentKey(e){return new Ze(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==ge.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(;rt.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==ge.RPAREN){if(e.peek.kind===ge.RBRACKET)break;e.expectPeek(ge.COMMA),e.next()}e.next()}return e.expect(ge.RPAREN),new X(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e,t=1){const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case ge.EOF:case ge.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===ge.EOF||n===ge.RBRACKET||(nt.get(n)||1)<t)break;if(!rt.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){return this.unescapeString(e.kind===ge.SINGLE_QUOTE_STRING?e.value.replaceAll('"','\\"').replaceAll("\\'","'"):e.value,e)}unescapeString(e,t){const n=[],r=e.length;let s,o=0;for(;o<r;){const r=e[o];if("\\"===r)switch(o+=1,e[o]){case'"':n.push('"');break;case"\\":n.push("\\");break;case"/":n.push("/");break;case"b":n.push("\b");break;case"f":n.push("\f");break;case"n":n.push("\n");break;case"r":n.push("\r");break;case"t":n.push("\t");break;case"u":[s,o]=this.decodeHexChar(e,o,t),n.push(this.stringFromCodePoint(s,t));break;default:throw new a("unknown escape sequence at index "+(t.index+o-1),t)}else this.stringFromCodePoint(r.codePointAt(0),t),n.push(r);o+=1}return n.join("")}decodeHexChar(e,t,n){const r=e.length;if(t+4>=r)throw new a("incomplete escape sequence at index "+(n.index+t-1),n);t+=1;let s=this.parseHexDigits(e.slice(t,t+4),n);if(it(s))throw new a("unexpected low surrogate codepoint at index "+(n.index+t-2),n);if(function(e){return e>=55296&&e<=56319}(s)){if(!(t+9<r&&"\\"===e[t+4]&&"u"===e[t+5]))throw new a("incomplete escape sequence at index "+(n.index+t-2),n);const o=this.parseHexDigits(e.slice(t+6,t+10),n);if(!it(o))throw new a(`unexpected codepoint at index ${n.index+t+4}`,n);return s=65536+((1023&s)<<10|1023&o),[s,t+9]}return[s,t+3]}parseHexDigits(e,t){const n=new TextEncoder;let r=0;for(const s of n.encode(e))switch(r<<=4,s){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:r|=s-48;break;case 97:case 98:case 99:case 100:case 101:case 102:r|=s-97+10;break;case 65:case 66:case 67:case 68:case 69:case 70:r|=s-65+10;break;default:throw new a("invalid \\uXXXX escape sequence",t)}return r}stringFromCodePoint(e,t){if(void 0===e||e<=31)throw new a("invalid character",t);try{return String.fromCodePoint(e)}catch{throw new a("invalid escape sequence",t)}}throwForNonComparable(e){if((e instanceof q||e instanceof Y)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof X){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof j)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}function it(e){return e>=56320&&e<=57343}class at{functionRegister=new Map;constructor(e={}){this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??1-Math.pow(2,53),this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new ot(this),this.setupFilterFunctions()}compile(e){return new Xe(this,this.parser.parse(new ve(Te(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new re),this.functionRegister.set("length",new se),this.functionRegister.set("search",new fe),this.functionRegister.set("match",new pe),this.functionRegister.set("value",new de)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map((e,n)=>[e,t[n],n]))switch(r){case g.ValueType:if(!(o instanceof j||o instanceof Ze||o instanceof W&&o.path.singularQuery()||o instanceof X&&this.functionRegister.get(o.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case g.LogicalType:if(!(o instanceof W||o instanceof V))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof W||o instanceof X&&this.functionRegister.get(o.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var ct=Object.freeze({__proto__:null,Count:re,FunctionExpressionType:g,Has:class{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(e={}){this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.search=e.search??!0,this.#t=new oe(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!l(e)&&Object.keys(e).some(e=>!!e.match(n))}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new u(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!le(t)){if(this.throwErrors)throw new u(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=this.search?new RegExp(ie(t),"u"):new RegExp(ie(ae(t)),"u");return this.cacheSize>0&&this.#t.set(t,n),!!l(e)&&Object.keys(e).some(e=>!!e.match(n))}catch(e){if(this.throwErrors)throw e;return!1}}},Length:se,Match:pe,Search:fe,Value:de});const ut=new at;function ht(e,t){return ut.query(e,t)}function lt(e,t){return ut.lazyQuery(e,t)}function pt(e){return ut.compile(e)}var ft=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:ut,FunctionExpressionType:g,JSONPathEnvironment:at,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:F,JSONPathNodeList:z,JSONPathQuery:Xe,JSONPathRecursionLimitError:c,JSONPathSegment:Be,JSONPathSelector:je,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:C,Nothing:A,Token:me,TokenKind:ge,compile:pt,expressions:ne,functions:ct,lazyQuery:lt,match:function(e,t){return ut.match(e,t)},query:ht,selectors:Ve});class dt extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class gt extends dt{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class mt{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){return kt(e,this.path,this.value,this.name,t)}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class vt{name="remove";constructor(e){this.path=e}apply(e,t){return Ot(e,this.path,this.name,t),e}toObject(){return{op:this.name,path:this.path.toString()}}}class wt{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new dt(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===k)throw new dt(`can't replace nonexistent item (${this.name}:${t})`);return n.splice(Number(s),1,this.value),e}if(l(n)){if(r===k)throw new dt(`can't replace nonexistent property (${this.name}:${t})`);return n[s]=this.value,e}throw new dt(`unexpected operation on '${typeof n}' (${this.name}:${t})`)}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class xt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new dt(`can't move object to one of its own children (${this.name}:${t})`);const n=Ot(e,this.from,this.name,t);return kt(e,this.path,n,this.name,t)}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class Et{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new dt(`source object does not exist (${this.name}:${t})`);return kt(e,this.path,r,this.name,t)}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class yt{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!d(r,this.value))throw new gt(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}function kt(e,t,n,r,s){const[o,i]=t.resolveWithParent(e);if(o===k)return n;const a=t.tokens.at(-1);if(void 0===a)throw new dt(`unexpected operation on 'undefined' (${r}:${s})`);if(h(o)){if(i===k){if("-"!==a&&Number(a)!==o.length)throw new dt(`index out of range (${r}:${s})`);return o.push(n),e}return o.splice(Number(a),0,n),e}if(l(o))return o[a]=n,e;throw new dt(`unexpected operation on '${typeof o}' (${r}:${s})`)}function Ot(e,t,n,r){const[s,o]=t.resolveWithParent(e);if(s===k)throw new dt(`can't remove root (${n}:${r})`);const i=t.tokens.at(-1);if(void 0===i)throw new dt(`unexpected operation on 'undefined' (${n}:${r})`);if(h(s)){if(o===k)throw new dt(`can't ${n} nonexistent item (${n}:${r})`);return s.splice(Number(i),1),o}if(l(s)){if(o===k)throw new dt(`can't ${n} nonexistent property (${n}:${r})`);return delete s[i],o}throw new dt(`unexpected operation on '${typeof s}' (${n}:${r})`)}class St{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 mt(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new vt(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new wt(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new xt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Et(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new yt(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof v)throw new dt(`${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 dt(`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 dt(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new dt(`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 dt(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new dt(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!p(e))throw new dt(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new dt(`${e.message} (${t}:${n})`);throw e}}}function Nt(e,t){return new St(e).apply(t)}var Tt=Object.freeze({__proto__:null,JSONPatch:St,JSONPatchError:dt,JSONPatchTestFailure:gt,apply:Nt});return e.DEFAULT_ENVIRONMENT=ut,e.FunctionExpressionType=g,e.JSONPatch=St,e.JSONPatchError=dt,e.JSONPatchTestFailure=gt,e.JSONPathEnvironment=at,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=F,e.JSONPathNodeList=z,e.JSONPathQuery=Xe,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=A,e.RelativeJSONPointer=T,e.Token=me,e.TokenKind=ge,e.UNDEFINED=k,e.apply=Nt,e.compile=pt,e.jsonpatch=Tt,e.jsonpath=ft,e.jsonpointer=b,e.lazyQuery=lt,e.query=ht,e.resolve=R,e.version="2.3.2",e}({});
2
2
  //# sourceMappingURL=json-p3.iife.min.js.map