json-p3 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 1.3.2
2
+ * json-p3 version 1.3.3
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -4056,6 +4056,7 @@ class Parser {
4056
4056
  throw new JSONPathTypeError(`result of ${expr.name}() must be compared`, expr.token);
4057
4057
  }
4058
4058
  }
4059
+ this.throwForLiteral(expr);
4059
4060
  return keys ? new KeysFilterSelector(this.environment, tok, new LogicalExpression(tok, expr)) : new FilterSelector(this.environment, tok, new LogicalExpression(tok, expr));
4060
4061
  }
4061
4062
  parseBoolean(stream) {
@@ -4087,6 +4088,9 @@ class Parser {
4087
4088
  if (COMPARISON_OPERATORS.has(operator)) {
4088
4089
  this.throwForNonComparable(left);
4089
4090
  this.throwForNonComparable(right);
4091
+ } else {
4092
+ this.throwForLiteral(left);
4093
+ this.throwForLiteral(right);
4090
4094
  }
4091
4095
  return new InfixExpression(tok, left, operator, right);
4092
4096
  }
@@ -4195,6 +4199,11 @@ class Parser {
4195
4199
  }
4196
4200
  }
4197
4201
  }
4202
+ throwForLiteral(expr) {
4203
+ if (expr instanceof FilterExpressionLiteral) {
4204
+ throw new JSONPathSyntaxError(`filter expression literals (${expr.toString()}) must be compared`, expr.token);
4205
+ }
4206
+ }
4198
4207
  }
4199
4208
 
4200
4209
  /**
@@ -4977,7 +4986,7 @@ var index = /*#__PURE__*/Object.freeze({
4977
4986
  apply: apply
4978
4987
  });
4979
4988
 
4980
- const version = "1.3.2";
4989
+ const version = "1.3.3";
4981
4990
 
4982
4991
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
4983
4992
  exports.FunctionExpressionType = FunctionExpressionType;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 1.3.2
2
+ * json-p3 version 1.3.3
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -4054,6 +4054,7 @@ class Parser {
4054
4054
  throw new JSONPathTypeError(`result of ${expr.name}() must be compared`, expr.token);
4055
4055
  }
4056
4056
  }
4057
+ this.throwForLiteral(expr);
4057
4058
  return keys ? new KeysFilterSelector(this.environment, tok, new LogicalExpression(tok, expr)) : new FilterSelector(this.environment, tok, new LogicalExpression(tok, expr));
4058
4059
  }
4059
4060
  parseBoolean(stream) {
@@ -4085,6 +4086,9 @@ class Parser {
4085
4086
  if (COMPARISON_OPERATORS.has(operator)) {
4086
4087
  this.throwForNonComparable(left);
4087
4088
  this.throwForNonComparable(right);
4089
+ } else {
4090
+ this.throwForLiteral(left);
4091
+ this.throwForLiteral(right);
4088
4092
  }
4089
4093
  return new InfixExpression(tok, left, operator, right);
4090
4094
  }
@@ -4193,6 +4197,11 @@ class Parser {
4193
4197
  }
4194
4198
  }
4195
4199
  }
4200
+ throwForLiteral(expr) {
4201
+ if (expr instanceof FilterExpressionLiteral) {
4202
+ throw new JSONPathSyntaxError(`filter expression literals (${expr.toString()}) must be compared`, expr.token);
4203
+ }
4204
+ }
4196
4205
  }
4197
4206
 
4198
4207
  /**
@@ -4975,6 +4984,6 @@ var index = /*#__PURE__*/Object.freeze({
4975
4984
  apply: apply
4976
4985
  });
4977
4986
 
4978
- const version = "1.3.2";
4987
+ const version = "1.3.3";
4979
4988
 
4980
4989
  export { DEFAULT_ENVIRONMENT, FunctionExpressionType, JSONPatch, JSONPatchError, JSONPatchTestFailure, JSONPath, JSONPathEnvironment, JSONPathError, JSONPathIndexError, JSONPathLexerError, JSONPathNode, JSONPathNodeList, 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,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 1.3.2
2
+ * json-p3 version 1.3.3
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -4057,6 +4057,7 @@ var json_p3 = (function (exports) {
4057
4057
  throw new JSONPathTypeError(`result of ${expr.name}() must be compared`, expr.token);
4058
4058
  }
4059
4059
  }
4060
+ this.throwForLiteral(expr);
4060
4061
  return keys ? new KeysFilterSelector(this.environment, tok, new LogicalExpression(tok, expr)) : new FilterSelector(this.environment, tok, new LogicalExpression(tok, expr));
4061
4062
  }
4062
4063
  parseBoolean(stream) {
@@ -4088,6 +4089,9 @@ var json_p3 = (function (exports) {
4088
4089
  if (COMPARISON_OPERATORS.has(operator)) {
4089
4090
  this.throwForNonComparable(left);
4090
4091
  this.throwForNonComparable(right);
4092
+ } else {
4093
+ this.throwForLiteral(left);
4094
+ this.throwForLiteral(right);
4091
4095
  }
4092
4096
  return new InfixExpression(tok, left, operator, right);
4093
4097
  }
@@ -4196,6 +4200,11 @@ var json_p3 = (function (exports) {
4196
4200
  }
4197
4201
  }
4198
4202
  }
4203
+ throwForLiteral(expr) {
4204
+ if (expr instanceof FilterExpressionLiteral) {
4205
+ throw new JSONPathSyntaxError(`filter expression literals (${expr.toString()}) must be compared`, expr.token);
4206
+ }
4207
+ }
4199
4208
  }
4200
4209
 
4201
4210
  /**
@@ -4978,7 +4987,7 @@ var json_p3 = (function (exports) {
4978
4987
  apply: apply
4979
4988
  });
4980
4989
 
4981
- const version = "1.3.2";
4990
+ const version = "1.3.3";
4982
4991
 
4983
4992
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
4984
4993
  exports.FunctionExpressionType = FunctionExpressionType;
@@ -1,2 +1,2 @@
1
- var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class c extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}class h extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function u(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 y 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 x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const O=Symbol.for("jsonpointer.undefined");class k{#e;constructor(e){this.tokens=this.parse(e),this.#e=k.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==O)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[O,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 y)return[t,O];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(u(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(S.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${k.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${k.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 y(`no such property '${k.encode(this.tokens.slice(0,n+1))}'`)}throw new x(`found primitive value, expected an object '${k.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(e))throw new x("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new k(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new k(k.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new k(k.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,S=/(0|[1-9][0-9]*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new k(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 k?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new k(k.encode(n))}parse(e){const t=N.exec(e);if(!t||!t.groups)throw new E("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new E("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new k(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new E("unexpected leading zero");if(S.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||S.test(e)}}function R(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:O;return new k(e).resolve(t,n)}var $=Object.freeze({__proto__:null,JSONPointer:k,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:y,JSONPointerResolutionError:v,JSONPointerSyntaxError:E,JSONPointerTypeError:x,RelativeJSONPointer:T,UNDEFINED:O,resolve:R});const b=Symbol.for("jsonpath.nothing");function _(e,t){return l(e)&&Object.hasOwn(e,t)}const P="";class I{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>p(e)?this.decode_name_location(e):`[${e}]`)).join("")}toPointer(){return this.location.length?new k(k.encode(this.location.map(String))):new k("")}decode_name_location(e){return e.startsWith(P)?`[~'${e.slice(1).replaceAll("'","\\'")}']`:`['${e.replaceAll("'","\\'")}']`}}class A{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map((e=>e.value))}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map((e=>e.value))}locations(){return this.nodes.map((e=>e.location))}paths(){return this.nodes.map((e=>e.path))}pointers(){return this.nodes.map((e=>e.toPointer()))}get length(){return this.nodes.length}}class L{constructor(e){this.token=e}}class C extends L{}class K extends C{evaluate(){return null}toString(){return"null"}}class F extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class M extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class j extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class U extends L{constructor(e,t,n){super(e),this.token=e,this.operator=t,this.right=n}evaluate(e){if("!"===this.operator){const t=this.right.evaluate(e);return t instanceof A?0===t.nodes.length:!W(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class z extends L{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r,this.logical="&&"===n||"||"===n}evaluate(e){let t=this.left.evaluate(e);!this.logical&&t instanceof A&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof A&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?W(t)&&W(n):"||"===this.operator?W(t)||W(n):B(t,this.operator,n)}toString(){return this.logical?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class J extends L{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof A?t.nodes.length>0:W(t)}toString(){return this.expression.toString()}}class D extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends D{evaluate(e){return e.lazy?new A(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class Q extends D{evaluate(e){return e.lazy?new A(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class V extends L{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof A?this.unpack_node_list(e):e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return b;case 1:return e.nodes[0].value;default:return e}}}function W(e){return!(e instanceof A&&e.empty())&&!("boolean"==typeof e&&!1===e)}function B(e,t,n){switch(t){case"==":return Y(e,n);case"!=":return!Y(e,n);case"<":return q(e,n);case">":return q(n,e);case">=":return q(n,e)||Y(e,n);case"<=":return q(e,n)||Y(e,n);default:return!1}}function Y(e,t){if(t instanceof A&&([e,t]=[t,e]),e instanceof A){if(t instanceof A){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===b:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===b&&t===b||d(e,t)}function q(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var X=Object.freeze({__proto__:null,BooleanLiteral:F,FilterExpression:L,FilterExpressionLiteral:C,FunctionExtension:V,InfixExpression:z,JSONPathQuery:D,LogicalExpression:J,NullLiteral:K,NumberLiteral:j,PrefixExpression:U,RelativeQuery:G,RootQuery:Q,StringLiteral:M,compare:B});class Z{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return e.length}}class H{argTypes=[g.ValueType];returnType=g.ValueType;call(e){return u(e)||p(e)?e.length:l(e)?Object.keys(e).length:b}}class ee extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}function te(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ne(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ne.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function re(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ne,Error),ne.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,i=this.location.source+":"+o.line+":"+o.column;if(r){var a=this.location.end,c=re("",o.line.toString().length," "),h=r[s.line-1],u=(s.line===a.line?a.column:h.length+1)-s.column||1;t+="\n --\x3e "+i+"\n"+c+" |\n"+o.line+" | "+h+"\n"+c+" | "+re("",s.column-1," ")+re("",u,"^")}else t+="\n at "+i}return t},ne.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(i);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const se={StartRules:["start"],SyntaxError:ne,parse:function(e,t){var n,r,s,o,i={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ie},h=Ie,u="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",y="^",E="-",x="]",O="\\p{",k="\\P{",N="L",S="M",T="N",R="P",$="Z",b="S",_="C",P=/^[*-+?]/,I=/^[0-9]/,A=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,M=/^[lps]/,j=/^[ckmo]/,U=/^[cfn-o]/,z=Re("|",!1),J=$e([["*","+"],"?"],!1,!1),D=Re("{",!1),G=$e([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),W=Re("(",!1),B=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=$e([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),re=Re("]",!1),se=Re("\\p{",!1),oe=Re("\\P{",!1),ie=Re("L",!1),ae=$e([["l","m"],"o",["t","u"]],!1,!1),ce=Re("M",!1),he=$e(["c","e","n"],!1,!1),ue=Re("N",!1),le=$e(["d","l","o"],!1,!1),pe=Re("P",!1),fe=$e([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=$e(["l","p","s"],!1,!1),me=Re("S",!1),ve=$e(["c","k","m","o"],!1,!1),we=Re("C",!1),ye=$e(["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)},xe=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},Oe=0|t.peg$currPos,ke=[{line:1,column:1}],Ne=Oe,Se=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');h=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function be(t){var n,r=ke[t];if(r)return r;if(t>=ke.length)n=ke.length-1;else for(n=t;!ke[--n];);for(r={line:(r=ke[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return ke[t]=r,r}function _e(e,t,n){var r=be(e),s=be(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function Pe(e){Oe<Ne||(Oe>Ne&&(Ne=Oe,Se=[]),Se.push(e))}function Ie(){return Ae()}function Ae(){var t,n,r,s;for(Oe,t=Le(),n=[],r=Oe,124===e.charCodeAt(Oe)?(s=u,Oe++):(s=i,0===Te&&Pe(z)),s!==i?r=s=[s,Le()]:(Oe=r,r=i);r!==i;)n.push(r),r=Oe,124===e.charCodeAt(Oe)?(s=u,Oe++):(s=i,0===Te&&Pe(z)),s!==i?r=s=[s,Le()]:(Oe=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=Oe,n=function(){var t,n,r,s;t=function(){var t,n;t=Oe,e.length>Oe?(n=e.charAt(Oe),Oe++):(n=i,0===Te&&Pe(Y));n!==i&&(Ee(n)?void 0:i)!==i?t=n:(Oe=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(Oe)?(t=m,Oe++):(t=i,0===Te&&Pe(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=Oe,91===e.charCodeAt(Oe)?(n=w,Oe++):(n=i,0===Te&&Pe(H));if(n!==i)if(94===e.charCodeAt(Oe)?(r=y,Oe++):(r=i,0===Te&&Pe(ee)),r===i&&(r=null),45===e.charCodeAt(Oe)?(s=E,Oe++):(s=i,0===Te&&Pe(te)),s===i&&(s=Me()),s!==i){for(o=[],a=Me();a!==i;)o.push(a),a=Me();45===e.charCodeAt(Oe)?(a=E,Oe++):(a=i,0===Te&&Pe(te)),a===i&&(a=null),93===e.charCodeAt(Oe)?(c=x,Oe++):(c=i,0===Te&&Pe(re)),c!==i?t=n=[n,r,s,o,a,c]:(Oe=t,t=i)}else Oe=t,t=i;else Oe=t,t=i;return t}());return t}(),t===i&&(t=Oe,40===e.charCodeAt(Oe)?(n=d,Oe++):(n=i,0===Te&&Pe(W)),n!==i&&(r=Ae())!==i?(41===e.charCodeAt(Oe)?(s=g,Oe++):(s=i,0===Te&&Pe(B)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(Oe),P.test(t)?Oe++:(t=i,0===Te&&Pe(J));t===i&&(t=function(){var t,n,r,s,o,a;t=Oe,123===e.charCodeAt(Oe)?(n=l,Oe++):(n=i,0===Te&&Pe(D));n!==i?(r=e.charAt(Oe),I.test(r)?Oe++:(r=i,0===Te&&Pe(G)),r!==i?(s=Oe,44===e.charCodeAt(Oe)?(o=p,Oe++):(o=i,0===Te&&Pe(Q)),o!==i?(a=e.charAt(Oe),I.test(a)?Oe++:(a=i,0===Te&&Pe(G)),a===i&&(a=null),s=o=[o,a]):(Oe=s,s=i),s===i&&(s=null),125===e.charCodeAt(Oe)?(o=f,Oe++):(o=i,0===Te&&Pe(V)),o!==i?t=n=[n,r,s,o]:(Oe=t,t=i)):(Oe=t,t=i)):(Oe=t,t=i);return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i),t}function Ke(){var t,n,r;return t=Oe,92===e.charCodeAt(Oe)?(n=v,Oe++):(n=i,0===Te&&Pe(X)),n!==i?(r=e.charAt(Oe),A.test(r)?Oe++:(r=i,0===Te&&Pe(Z)),r!==i?t=n=[n,r]:(Oe=t,t=i)):(Oe=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=Oe,e.substr(Oe,3)===O?(n=O,Oe+=3):(n=i,0===Te&&Pe(se));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(Oe)?(s=f,Oe++):(s=i,0===Te&&Pe(V)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=Oe,e.substr(Oe,3)===k?(n=k,Oe+=3):(n=i,0===Te&&Pe(oe));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(Oe)?(s=f,Oe++):(s=i,0===Te&&Pe(V)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i);return t}()),t}function Me(){var t,n,r,s,o;return t=Oe,(n=je())!==i?(r=Oe,45===e.charCodeAt(Oe)?(s=E,Oe++):(s=i,0===Te&&Pe(te)),s!==i&&(o=je())!==i?r=s=[s,o]:(Oe=r,r=i),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i),t===i&&(t=Fe()),t}function je(){var t,n;return t=Oe,e.length>Oe?(n=e.charAt(Oe),Oe++):(n=i,0===Te&&Pe(Y)),n!==i&&(xe(n)?void 0:i)!==i?t=n:(Oe=t,t=i),t===i&&(t=Ke()),t}function Ue(){var t;return(t=function(){var t,n,r;t=Oe,76===e.charCodeAt(Oe)?(n=N,Oe++):(n=i,0===Te&&Pe(ie));n!==i?(r=e.charAt(Oe),L.test(r)?Oe++:(r=i,0===Te&&Pe(ae)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,77===e.charCodeAt(Oe)?(n=S,Oe++):(n=i,0===Te&&Pe(ce));n!==i?(r=e.charAt(Oe),C.test(r)?Oe++:(r=i,0===Te&&Pe(he)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,78===e.charCodeAt(Oe)?(n=T,Oe++):(n=i,0===Te&&Pe(ue));n!==i?(r=e.charAt(Oe),K.test(r)?Oe++:(r=i,0===Te&&Pe(le)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,80===e.charCodeAt(Oe)?(n=R,Oe++):(n=i,0===Te&&Pe(pe));n!==i?(r=e.charAt(Oe),F.test(r)?Oe++:(r=i,0===Te&&Pe(fe)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,90===e.charCodeAt(Oe)?(n=$,Oe++):(n=i,0===Te&&Pe(de));n!==i?(r=e.charAt(Oe),M.test(r)?Oe++:(r=i,0===Te&&Pe(ge)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,83===e.charCodeAt(Oe)?(n=b,Oe++):(n=i,0===Te&&Pe(me));n!==i?(r=e.charAt(Oe),j.test(r)?Oe++:(r=i,0===Te&&Pe(ve)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,67===e.charCodeAt(Oe)?(n=_,Oe++):(n=i,0===Te&&Pe(we));n!==i?(r=e.charAt(Oe),U.test(r)?Oe++:(r=i,0===Te&&Pe(ye)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}()),t}if(n=h(),t.peg$library)return{peg$result:n,peg$currPos:Oe,peg$FAILED:i,peg$maxFailExpected:Se,peg$maxFailPos:Ne};if(n!==i&&Oe===e.length)return n;throw n!==i&&Oe<e.length&&Pe({type:"end"}),r=Se,s=Ne<e.length?e.charAt(Ne):null,o=Ne<e.length?_e(Ne,Ne+1):_e(Ne,Ne),new ne(ne.buildMessage(r,s),r,s,o)}};var oe=function(e){try{se.parse(e,{})}catch(e){if(e instanceof se.SyntaxError)return!1;throw e}return!0};class ie{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new h(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new h(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(te(e)),n||r||t.push(")$"),t.join("")}}class ae{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new h(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new h(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(te(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class ce{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return 1===e.length?e.nodes[0].value:b}}let he=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 ue{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new ue(he.EOF,"",-1,"");class le{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}}const pe=/e[+-]?\d+/y,fe=/[a-z][a-z_0-9]*/y,de=/-?\d+/y,ge=/-?[0-9]+/y,me=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ve=new Set([" ","\n","\t","\r"]),we=/[\u0080-\uFFFFa-zA-Z_]/;class ye{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e,t){this.environment=e,this.path=t}get pos(){return this.#n}get start(){return this.#r}run(){let e=xe;for(;e;)e=e(this)}emit(e){this.tokens.push(new ue(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 ue(he.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 ue(he.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ve)&&(this.ignore(),!0)}error(e){this.tokens.push(new ue(he.ERROR,e,this.#n,this.path))}}function Ee(e,t){const[n,r]=function(e,t){const n=new ye(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===he.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function xe(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(he.ROOT),Oe)}function Oe(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(he.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(he.DDOT),ke):Ne;case"[":return e.emit(he.LBRACKET),Se;default:return e.backup(),e.filterLevel?Te:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ke(e){if(e.acceptMatchRun(me))return e.emit(he.NAME),Oe;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(he.KEY),Oe):(e.emit(he.KEYS),Oe);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),Oe}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(he.WILD),Oe;case"[":return e.emit(he.LBRACKET),Se;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function Ne(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(he.KEY),Oe):(e.emit(he.KEYS),Oe);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),Oe}if(e.acceptMatchRun(me))return e.emit(he.NAME),Oe;const t=e.next();return"*"===t?(e.emit(he.WILD),Oe):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Se(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(de)){e.emit(he.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Ie(e);case'"':return e.ignore(),e.next(),Ae(e);case"?":return e.next(),e.emit(he.KEYS_FILTER),e.filterLevel+=1,Te;default:e.emit(he.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(he.RBRACKET),e.filterLevel?Te:Oe;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(he.WILD);continue;case"?":return e.emit(he.FILTER),e.filterLevel+=1,Te;case",":e.emit(he.COMMA);continue;case":":e.emit(he.COLON);continue;case"'":return $e;case'"':return be;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function Te(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),Se);case",":if(e.emit(he.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Se;case"'":return _e;case'"':return Pe;case"(":e.emit(he.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(he.RPAREN),e.parenStack.length&&(1===e.parenStack[e.parenStack.length-1]?e.parenStack.pop():e.parenStack[e.parenStack.length-1]-=1);continue;case"$":return e.emit(he.ROOT),Oe;case"@":return e.emit(he.CURRENT),Oe;case"#":return e.emit(he.CURRENT_KEY),Oe;case".":return e.backup(),Oe;case"!":"="===e.peek()?(e.next(),e.emit(he.NE)):e.emit(he.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(he.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(he.LE)):e.emit(he.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(he.GE)):e.emit(he.GT);continue;default:if(e.backup(),e.acceptMatchRun(ge)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ge)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(pe),e.emit(he.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(he.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(he.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(he.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(he.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(he.NULL);continue}if(e.acceptMatchRun(fe)&&"("===e.peek()){e.parenStack.push(1),e.emit(he.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Re(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?he.SINGLE_QUOTE_STRING:he.DOUBLE_QUOTE_STRING),r.next(),r.ignore(),t;for(;;){const s=r.path.slice(r.pos,r.pos+2),o=r.next();if("\\\\"!==s&&s!==`\\${e}`){if("\\"===o&&!s.match(/\\[bfnrtu/]/))return r.error("invalid escape"),null;if(!o)return r.error(`unclosed string starting at index ${r.start}`),null;if(o===e)return r.backup(),r.emit(n),r.next(),r.ignore(),t}else r.next()}}}const $e=Re("'",Se,he.SINGLE_QUOTE_STRING),be=Re('"',Se,he.DOUBLE_QUOTE_STRING),_e=Re("'",Te,he.SINGLE_QUOTE_STRING),Pe=Re('"',Te,he.DOUBLE_QUOTE_STRING),Ie=Re("'",Se,he.KEY_SINGLE_QUOTE_STRING),Ae=Re('"',Se,he.KEY_DOUBLE_QUOTE_STRING);class Le{constructor(e,t){this.environment=e,this.token=t}}class Ce extends Le{constructor(e,t,n,r){super(e,t),this.environment=e,this.token=t,this.name=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)!u(n.value)&&_(n.value,this.name)&&t.push(new I(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)!u(t.value)&&_(t.value,this.name)&&(yield new I(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class Ke extends Le{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(u(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new I(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(u(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new I(t.value[e],t.location.concat(e),t.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Fe extends Le{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];for(const n of e)if(u(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new I(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(u(t.value))for(const[e,n]of this.lazySlice(t.value,this.start,this.stop,this.step))yield new I(n,t.location.concat(e),t.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(const e of t)if(void 0!==e&&(e<this.environment.minIntIndex||e>this.environment.maxIntIndex))throw new o("index out of range",this.token)}slice(e,t,n,r){if(!e.length)return[];if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),0===r)return[];r||(r=1);const s=[];if(r>0)for(let o=t;o<n;o+=r)s.push([o,e[o]]);else for(let o=t;o>n;o+=r)s.push([o,e[o]]);return s}*lazySlice(e,t,n,r){if(e.length)if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),void 0===r)for(let r=t;r<n;r+=1)yield[r,e[r]];else if(r>0)for(let s=t;s<n;s+=r)yield[s,e[s]];else if(r<0)for(let s=t;s>n;s+=r)yield[s,e[s]]}}class Me extends Le{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(u(n.value))for(let e=0;e<n.value.length;e++)t.push(new I(n.value[e],n.location.concat(e),n.root));else if(l(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new I(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(u(t.value))for(let e=0;e<t.value.length;e++)yield new I(t.value[e],t.location.concat(e),t.root);else if(l(t.value))for(const[e,n]of this.environment.entries(t.value))yield new I(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class je extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];if(this.environment.nondeterministic)for(const n of e)for(const e of this.nondeterministicVisitor(n))t.push(e);else for(const n of e){t.push(n);for(const e of this.visitor(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);if(!(t.value instanceof String))if(u(t.value))for(let r=0;r<t.value.length;r++){const s=new I(t.value[r],t.location.concat(r),t.root);yield s,l(s.value)&&e.push({node:s,depth:n+1})}else if(l(t.value))for(const[r,s]of this.environment.entries(t.value)){const o=new I(s,t.location.concat(r),t.root);yield o,l(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(u(e.value))for(let r=0;r<e.value.length;r++){const s=new I(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visitor(s,t+1))n.push(e)}else if(l(e.value))for(const[r,s]of this.environment.entries(e.value)){const o=new I(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visitor(o,t+1))n.push(e)}return n}nondeterministicVisitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=[e];let r=this.nondeterministicChildren(e).map((e=>[e,t]));for(;r.length;){const[e,t]=r.shift();if(n.push(e),t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const s=Math.random()<.5;for(const o of this.nondeterministicChildren(e))if(s){n.push(o);r=Je(r,this.nondeterministicChildren(o).map((e=>[e,t+2])))}else r.push([o,t+1])}return n}nondeterministicChildren(e){const t=[];if(e.value instanceof String)return t;if(u(e.value))for(let n=0;n<e.value.length;n++)t.push(new I(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 I(r,e.location.concat(n),e.root));return t}}class Ue extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(u(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(r,n.location.concat(e),n.root))}else if(l(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(u(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(n,t.location.concat(e),t.root))}else if(l(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class ze extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.items=n}resolve(e){const t=[];for(const n of e)for(const e of this.items)for(const r of e.resolve([n]))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.items)yield*e.lazyResolve([t])}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}function Je(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map((e=>e.next().value))}var De=Object.freeze({__proto__:null,BracketedSelection:ze,FilterSelector:Ue,IndexSelector:Ke,JSONPathSelector:Le,NameSelector:Ce,RecursiveDescentSegment:je,SliceSelector:Fe,WildcardSelector:Me});class Ge{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new I(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new A(t)}lazyQuery(e){let t=[new I(e,[],e)][Symbol.iterator]();for(const e of this.selectors)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof Ce||e instanceof ze&&1===e.items.length&&(e.items[0]instanceof Ce||e.items[0]instanceof Ke)))return!1;return!0}}class Qe extends L{evaluate(e){return e.currentKey??b}toString(){return"#"}}class Ve extends Le{constructor(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];super(e,t),this.environment=e,this.token=t,this.key=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)n.value instanceof String||u(n.value)||l(n.value)&&_(n.value,this.key)&&t.push(new I(this.key,n.location.concat(`${P}${this.key}`),n.root));return t}*lazyResolve(e){for(const t of e)t.value instanceof String||u(t.value)||l(t.value)&&_(t.value,this.key)&&(yield new I(this.key,t.location.concat(`${P}${this.key}`),t.root))}toString(){return this.shorthand?`[~'${this.key.replaceAll("'","\\'")}']`:`~'${this.key.replaceAll("'","\\'")}'`}}class We extends Le{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||u(n.value))&&l(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new I(e,n.location.concat(`${P}${e}`),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||u(t.value))&&l(t.value))for(const[e,n]of this.environment.entries(t.value))yield new I(e,t.location.concat(`${P}${e}`),t.root)}toString(){return this.shorthand?"[~]":"~"}}class Be extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||u(n.value))&&l(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(e,n.location.concat(`${P}${e}`),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||u(t.value))&&l(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(e,t.location.concat(`${P}${e}`),t.root))}}toString(){return`~?${this.expression.toString()}`}}const Ye=new Map([[he.AND,5],[he.EQ,6],[he.GE,6],[he.GT,6],[he.LE,6],[he.LT,6],[he.NE,6],[he.NOT,7],[he.OR,4],[he.RPAREN,1]]),qe=new Map([[he.AND,"&&"],[he.EQ,"=="],[he.GE,">="],[he.GT,">"],[he.LE,"<="],[he.LT,"<"],[he.NE,"!="],[he.OR,"||"]]),Xe=new Set(["==",">=",">","<=","<","!="]);class Ze{constructor(e){this.environment=e,this.tokenMap=new Map([[he.FALSE,this.parseBoolean],[he.NUMBER,this.parseNumber],[he.LPAREN,this.parseGroupedExpression],[he.NOT,this.parsePrefixExpression],[he.NULL,this.parseNull],[he.ROOT,this.parseRootQuery],[he.CURRENT,this.parseRelativeQuery],[he.SINGLE_QUOTE_STRING,this.parseString],[he.DOUBLE_QUOTE_STRING,this.parseString],[he.TRUE,this.parseBoolean],[he.FUNCTION,this.parseFunction],[he.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===he.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==he.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parsePath(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];for(;;){const r=this.parseSegment(e);if(!r){t&&e.backup();break}n.push(r),e.next()}return n}parseSegment(e){switch(e.current.kind){case he.NAME:return new Ce(this.environment,e.current,e.current.value,!0);case he.WILD:return new Me(this.environment,e.current,!0);case he.KEY:return new Ve(this.environment,e.current,e.current.value,!0);case he.KEYS:return new We(this.environment,e.current,!0);case he.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new je(this.environment,t,n)}case he.LBRACKET:return this.parseBracketedSelection(e);default:return null}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new Ke(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===he.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(he.COLON),e.next()):(n.push(void 0),e.expect(he.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===he.COLON&&e.next()):e.current.kind===he.COLON&&(n.push(void 0),e.expect(he.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Fe(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==he.RBRACKET;){switch(e.current.kind){case he.SINGLE_QUOTE_STRING:case he.DOUBLE_QUOTE_STRING:n.push(new Ce(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case he.FILTER:n.push(this.parseFilter(e));break;case he.INDEX:e.peek.kind===he.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case he.COLON:n.push(this.parseSlice(e));break;case he.WILD:n.push(new Me(this.environment,e.current));break;case he.KEY_SINGLE_QUOTE_STRING:case he.KEY_DOUBLE_QUOTE_STRING:n.push(new Ve(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case he.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case he.KEYS:n.push(new We(this.environment,e.current));break;case he.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!==he.RBRACKET&&(e.expectPeek(he.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new ze(this.environment,t,n)}parseFilter(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof V){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return t?new Be(this.environment,n,new J(n,r)):new Ue(this.environment,n,new J(n,r))}parseBoolean(e){return e.current.kind===he.FALSE?new F(e.current,!1):new F(e.current,!0)}parseNull(e){return new K(e.current)}parseString(e){return new M(e.current,this.decodeString(e.current))}parseNumber(e){return new j(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(he.NOT),e.next(),new U(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ye.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=qe.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Xe.has(o)&&(this.throwForNonComparable(t),this.throwForNonComparable(s)),new z(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===he.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==he.RPAREN;){if(e.current.kind===he.EOF)throw new a("unbalanced parentheses",e.current);if(!qe.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(he.RPAREN),t}parseRootQuery(e){const t=e.next();return new Q(t,new Ge(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new G(t,new Ge(this.environment,this.parsePath(e,!0)))}parseCurrentKey(e){return new Qe(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==he.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(;qe.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==he.RPAREN){if(e.peek.kind===he.RBRACKET)break;e.expectPeek(he.COMMA),e.next()}e.next()}return e.expect(he.RPAREN),new V(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case he.EOF:case he.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===he.EOF||n===he.RBRACKET||(Ye.get(n)||1)<t)break;if(!qe.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{return JSON.parse(e.kind===he.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonComparable(e){if((e instanceof Q||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof V){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}}class He{functionRegister=new Map;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??-Math.pow(2,53)-1,this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new Ze(this),this.setupFilterFunctions()}compile(e){return new Ge(this,this.parser.parse(new le(Ee(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new Z),this.functionRegister.set("length",new H),this.functionRegister.set("search",new ae),this.functionRegister.set("match",new ie),this.functionRegister.set("value",new ce)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case g.ValueType:if(!(o instanceof C||o instanceof Qe||o instanceof D&&o.path.singularQuery()||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case g.LogicalType:if(!(o instanceof D||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof D||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var et=Object.freeze({__proto__:null,Count:Z,FunctionExpressionType:g,Length:H,Match:ie,Search:ae,Value:ce});const tt=new He;function nt(e,t){return tt.query(e,t)}function rt(e,t){return tt.lazyQuery(e,t)}function st(e){return tt.compile(e)}var ot=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:tt,FunctionExpressionType:g,JSONPath:Ge,JSONPathEnvironment:He,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:I,JSONPathNodeList:A,JSONPathRecursionLimitError:c,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:P,Nothing:b,Token:ue,TokenKind:he,compile:st,expressions:X,functions:et,lazyQuery:rt,match:function(e,t){return tt.match(e,t)},query:nt,selectors:De});class it extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class at extends it{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class ct{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n))if(r===O){if("-"!==s)throw new it(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ht{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)throw new it(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===O)throw new it(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===O)throw new it(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class ut{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===O)throw new it(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===O)throw new it(`can't replace nonexistent property (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class lt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new it(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===O)throw new it(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);u(n)?n.splice(Number(s),1):l(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===O)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(o))o.splice(Number(a),0,r);else{if(!l(o))throw new it(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);o[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class pt{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===O)throw new it(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===O)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!l(s))throw new it(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);s[o]=this.deepCopy(r)}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class ft{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 at(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class dt{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 ct(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new ht(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new ut(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new lt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new pt(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new ft(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 it(`${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 it(`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 it(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new it(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new k(s)}catch(e){if(e instanceof m)throw new it(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new it(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof k)return e;if(!p(e))throw new it(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new k(e)}catch(e){if(e instanceof m)throw new it(`${e.message} (${t}:${n})`);throw e}}}function gt(e,t){return new dt(e).apply(t)}var mt=Object.freeze({__proto__:null,JSONPatch:dt,JSONPatchError:it,JSONPatchTestFailure:at,apply:gt});return e.DEFAULT_ENVIRONMENT=tt,e.FunctionExpressionType=g,e.JSONPatch=dt,e.JSONPatchError=it,e.JSONPatchTestFailure=at,e.JSONPath=Ge,e.JSONPathEnvironment=He,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=I,e.JSONPathNodeList=A,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=k,e.Nothing=b,e.RelativeJSONPointer=T,e.Token=ue,e.TokenKind=he,e.UNDEFINED=O,e.apply=gt,e.compile=st,e.jsonpatch=mt,e.jsonpath=ot,e.jsonpointer=$,e.lazyQuery=rt,e.query=nt,e.resolve=R,e.version="1.3.2",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 h extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="IRegexpError"}}function u(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 y 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 x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const O=Symbol.for("jsonpointer.undefined");class k{#e;constructor(e){this.tokens=this.parse(e),this.#e=k.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==O)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[O,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 y)return[t,O];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(u(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(S.test(r)&&Object.hasOwn(e,r))return Number(r);throw new w(`index out of range '${k.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${k.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 y(`no such property '${k.encode(this.tokens.slice(0,n+1))}'`)}throw new x(`found primitive value, expected an object '${k.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(e))throw new x("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new k(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new k(k.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new k(k.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,S=/(0|[1-9][0-9]*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new k(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 k?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new k(k.encode(n))}parse(e){const t=N.exec(e);if(!t||!t.groups)throw new E("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new E("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new k(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new E("unexpected leading zero");if(S.test(e))return Number(e);throw new E(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!f(e))||S.test(e)}}function R(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:O;return new k(e).resolve(t,n)}var $=Object.freeze({__proto__:null,JSONPointer:k,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:y,JSONPointerResolutionError:v,JSONPointerSyntaxError:E,JSONPointerTypeError:x,RelativeJSONPointer:T,UNDEFINED:O,resolve:R});const b=Symbol.for("jsonpath.nothing");function _(e,t){return l(e)&&Object.hasOwn(e,t)}const P="";class I{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>p(e)?this.decode_name_location(e):`[${e}]`)).join("")}toPointer(){return this.location.length?new k(k.encode(this.location.map(String))):new k("")}decode_name_location(e){return e.startsWith(P)?`[~'${e.slice(1).replaceAll("'","\\'")}']`:`['${e.replaceAll("'","\\'")}']`}}class A{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map((e=>e.value))}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map((e=>e.value))}locations(){return this.nodes.map((e=>e.location))}paths(){return this.nodes.map((e=>e.path))}pointers(){return this.nodes.map((e=>e.toPointer()))}get length(){return this.nodes.length}}class L{constructor(e){this.token=e}}class C extends L{}class K extends C{evaluate(){return null}toString(){return"null"}}class F extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class M extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class j extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class U extends L{constructor(e,t,n){super(e),this.token=e,this.operator=t,this.right=n}evaluate(e){if("!"===this.operator){const t=this.right.evaluate(e);return t instanceof A?0===t.nodes.length:!W(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class z extends L{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r,this.logical="&&"===n||"||"===n}evaluate(e){let t=this.left.evaluate(e);!this.logical&&t instanceof A&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof A&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?W(t)&&W(n):"||"===this.operator?W(t)||W(n):B(t,this.operator,n)}toString(){return this.logical?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class J extends L{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof A?t.nodes.length>0:W(t)}toString(){return this.expression.toString()}}class D extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends D{evaluate(e){return e.lazy?new A(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class Q extends D{evaluate(e){return e.lazy?new A(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class V extends L{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof A?this.unpack_node_list(e):e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return b;case 1:return e.nodes[0].value;default:return e}}}function W(e){return!(e instanceof A&&e.empty())&&!("boolean"==typeof e&&!1===e)}function B(e,t,n){switch(t){case"==":return Y(e,n);case"!=":return!Y(e,n);case"<":return q(e,n);case">":return q(n,e);case">=":return q(n,e)||Y(e,n);case"<=":return q(e,n)||Y(e,n);default:return!1}}function Y(e,t){if(t instanceof A&&([e,t]=[t,e]),e instanceof A){if(t instanceof A){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===b:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===b&&t===b||d(e,t)}function q(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var X=Object.freeze({__proto__:null,BooleanLiteral:F,FilterExpression:L,FilterExpressionLiteral:C,FunctionExtension:V,InfixExpression:z,JSONPathQuery:D,LogicalExpression:J,NullLiteral:K,NumberLiteral:j,PrefixExpression:U,RelativeQuery:G,RootQuery:Q,StringLiteral:M,compare:B});class Z{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return e.length}}class H{argTypes=[g.ValueType];returnType=g.ValueType;call(e){return u(e)||p(e)?e.length:l(e)?Object.keys(e).length:b}}class ee extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}function te(e){let t=!1,n=!1;const r=[];for(const s of e)if(t)r.push(s),t=!1;else switch(s){case".":n?r.push(s):r.push("(?:(?![\r\n])\\P{Cs}|\\p{Cs}\\p{Cs})");break;case"\\":t=!0,r.push(s);break;case"[":n=!0,r.push(s);break;case"]":n=!1,r.push(s);break;default:r.push(s)}return r.join("")}function ne(e,t,n,r){var s=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(s,ne.prototype),s.expected=t,s.found=n,s.location=r,s.name="SyntaxError",s}function re(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(ne,Error),ne.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,i=this.location.source+":"+o.line+":"+o.column;if(r){var a=this.location.end,c=re("",o.line.toString().length," "),h=r[s.line-1],u=(s.line===a.line?a.column:h.length+1)-s.column||1;t+="\n --\x3e "+i+"\n"+c+" |\n"+o.line+" | "+h+"\n"+c+" | "+re("",s.column-1," ")+re("",u,"^")}else t+="\n at "+i}return t},ne.buildMessage=function(e,t){var n={literal:function(e){return'"'+s(e.text)+'"'},class:function(e){var t=e.parts.map((function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)}));return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function s(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+r(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+r(e)}))}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,r=e.map(i);if(r.sort(),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return r.slice(0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+function(e){return e?'"'+s(e)+'"':"end of input"}(t)+" found."};const se={StartRules:["start"],SyntaxError:ne,parse:function(e,t){var n,r,s,o,i={},a=(t=void 0!==t?t:{}).grammarSource,c={start:Ie},h=Ie,u="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",y="^",E="-",x="]",O="\\p{",k="\\P{",N="L",S="M",T="N",R="P",$="Z",b="S",_="C",P=/^[*-+?]/,I=/^[0-9]/,A=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,M=/^[lps]/,j=/^[ckmo]/,U=/^[cfn-o]/,z=Re("|",!1),J=$e([["*","+"],"?"],!1,!1),D=Re("{",!1),G=$e([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),W=Re("(",!1),B=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=$e([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),re=Re("]",!1),se=Re("\\p{",!1),oe=Re("\\P{",!1),ie=Re("L",!1),ae=$e([["l","m"],"o",["t","u"]],!1,!1),ce=Re("M",!1),he=$e(["c","e","n"],!1,!1),ue=Re("N",!1),le=$e(["d","l","o"],!1,!1),pe=Re("P",!1),fe=$e([["c","f"],"i","o","s"],!1,!1),de=Re("Z",!1),ge=$e(["l","p","s"],!1,!1),me=Re("S",!1),ve=$e(["c","k","m","o"],!1,!1),we=Re("C",!1),ye=$e(["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)},xe=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},Oe=0|t.peg$currPos,ke=[{line:1,column:1}],Ne=Oe,Se=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');h=c[t.startRule]}function Re(e,t){return{type:"literal",text:e,ignoreCase:t}}function $e(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function be(t){var n,r=ke[t];if(r)return r;if(t>=ke.length)n=ke.length-1;else for(n=t;!ke[--n];);for(r={line:(r=ke[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return ke[t]=r,r}function _e(e,t,n){var r=be(e),s=be(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function Pe(e){Oe<Ne||(Oe>Ne&&(Ne=Oe,Se=[]),Se.push(e))}function Ie(){return Ae()}function Ae(){var t,n,r,s;for(Oe,t=Le(),n=[],r=Oe,124===e.charCodeAt(Oe)?(s=u,Oe++):(s=i,0===Te&&Pe(z)),s!==i?r=s=[s,Le()]:(Oe=r,r=i);r!==i;)n.push(r),r=Oe,124===e.charCodeAt(Oe)?(s=u,Oe++):(s=i,0===Te&&Pe(z)),s!==i?r=s=[s,Le()]:(Oe=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=Oe,n=function(){var t,n,r,s;t=function(){var t,n;t=Oe,e.length>Oe?(n=e.charAt(Oe),Oe++):(n=i,0===Te&&Pe(Y));n!==i&&(Ee(n)?void 0:i)!==i?t=n:(Oe=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(Oe)?(t=m,Oe++):(t=i,0===Te&&Pe(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=Oe,91===e.charCodeAt(Oe)?(n=w,Oe++):(n=i,0===Te&&Pe(H));if(n!==i)if(94===e.charCodeAt(Oe)?(r=y,Oe++):(r=i,0===Te&&Pe(ee)),r===i&&(r=null),45===e.charCodeAt(Oe)?(s=E,Oe++):(s=i,0===Te&&Pe(te)),s===i&&(s=Me()),s!==i){for(o=[],a=Me();a!==i;)o.push(a),a=Me();45===e.charCodeAt(Oe)?(a=E,Oe++):(a=i,0===Te&&Pe(te)),a===i&&(a=null),93===e.charCodeAt(Oe)?(c=x,Oe++):(c=i,0===Te&&Pe(re)),c!==i?t=n=[n,r,s,o,a,c]:(Oe=t,t=i)}else Oe=t,t=i;else Oe=t,t=i;return t}());return t}(),t===i&&(t=Oe,40===e.charCodeAt(Oe)?(n=d,Oe++):(n=i,0===Te&&Pe(W)),n!==i&&(r=Ae())!==i?(41===e.charCodeAt(Oe)?(s=g,Oe++):(s=i,0===Te&&Pe(B)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(Oe),P.test(t)?Oe++:(t=i,0===Te&&Pe(J));t===i&&(t=function(){var t,n,r,s,o,a;t=Oe,123===e.charCodeAt(Oe)?(n=l,Oe++):(n=i,0===Te&&Pe(D));n!==i?(r=e.charAt(Oe),I.test(r)?Oe++:(r=i,0===Te&&Pe(G)),r!==i?(s=Oe,44===e.charCodeAt(Oe)?(o=p,Oe++):(o=i,0===Te&&Pe(Q)),o!==i?(a=e.charAt(Oe),I.test(a)?Oe++:(a=i,0===Te&&Pe(G)),a===i&&(a=null),s=o=[o,a]):(Oe=s,s=i),s===i&&(s=null),125===e.charCodeAt(Oe)?(o=f,Oe++):(o=i,0===Te&&Pe(V)),o!==i?t=n=[n,r,s,o]:(Oe=t,t=i)):(Oe=t,t=i)):(Oe=t,t=i);return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i),t}function Ke(){var t,n,r;return t=Oe,92===e.charCodeAt(Oe)?(n=v,Oe++):(n=i,0===Te&&Pe(X)),n!==i?(r=e.charAt(Oe),A.test(r)?Oe++:(r=i,0===Te&&Pe(Z)),r!==i?t=n=[n,r]:(Oe=t,t=i)):(Oe=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=Oe,e.substr(Oe,3)===O?(n=O,Oe+=3):(n=i,0===Te&&Pe(se));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(Oe)?(s=f,Oe++):(s=i,0===Te&&Pe(V)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=Oe,e.substr(Oe,3)===k?(n=k,Oe+=3):(n=i,0===Te&&Pe(oe));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(Oe)?(s=f,Oe++):(s=i,0===Te&&Pe(V)),s!==i?t=n=[n,r,s]:(Oe=t,t=i)):(Oe=t,t=i);return t}()),t}function Me(){var t,n,r,s,o;return t=Oe,(n=je())!==i?(r=Oe,45===e.charCodeAt(Oe)?(s=E,Oe++):(s=i,0===Te&&Pe(te)),s!==i&&(o=je())!==i?r=s=[s,o]:(Oe=r,r=i),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i),t===i&&(t=Fe()),t}function je(){var t,n;return t=Oe,e.length>Oe?(n=e.charAt(Oe),Oe++):(n=i,0===Te&&Pe(Y)),n!==i&&(xe(n)?void 0:i)!==i?t=n:(Oe=t,t=i),t===i&&(t=Ke()),t}function Ue(){var t;return(t=function(){var t,n,r;t=Oe,76===e.charCodeAt(Oe)?(n=N,Oe++):(n=i,0===Te&&Pe(ie));n!==i?(r=e.charAt(Oe),L.test(r)?Oe++:(r=i,0===Te&&Pe(ae)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,77===e.charCodeAt(Oe)?(n=S,Oe++):(n=i,0===Te&&Pe(ce));n!==i?(r=e.charAt(Oe),C.test(r)?Oe++:(r=i,0===Te&&Pe(he)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,78===e.charCodeAt(Oe)?(n=T,Oe++):(n=i,0===Te&&Pe(ue));n!==i?(r=e.charAt(Oe),K.test(r)?Oe++:(r=i,0===Te&&Pe(le)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,80===e.charCodeAt(Oe)?(n=R,Oe++):(n=i,0===Te&&Pe(pe));n!==i?(r=e.charAt(Oe),F.test(r)?Oe++:(r=i,0===Te&&Pe(fe)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,90===e.charCodeAt(Oe)?(n=$,Oe++):(n=i,0===Te&&Pe(de));n!==i?(r=e.charAt(Oe),M.test(r)?Oe++:(r=i,0===Te&&Pe(ge)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,83===e.charCodeAt(Oe)?(n=b,Oe++):(n=i,0===Te&&Pe(me));n!==i?(r=e.charAt(Oe),j.test(r)?Oe++:(r=i,0===Te&&Pe(ve)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=Oe,67===e.charCodeAt(Oe)?(n=_,Oe++):(n=i,0===Te&&Pe(we));n!==i?(r=e.charAt(Oe),U.test(r)?Oe++:(r=i,0===Te&&Pe(ye)),r===i&&(r=null),t=n=[n,r]):(Oe=t,t=i);return t}()),t}if(n=h(),t.peg$library)return{peg$result:n,peg$currPos:Oe,peg$FAILED:i,peg$maxFailExpected:Se,peg$maxFailPos:Ne};if(n!==i&&Oe===e.length)return n;throw n!==i&&Oe<e.length&&Pe({type:"end"}),r=Se,s=Ne<e.length?e.charAt(Ne):null,o=Ne<e.length?_e(Ne,Ne+1):_e(Ne,Ne),new ne(ne.buildMessage(r,s),r,s,o)}};var oe=function(e){try{se.parse(e,{})}catch(e){if(e instanceof se.SyntaxError)return!1;throw e}return!0};class ie{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new h(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new h(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[],n=e.startsWith("^"),r=e.endsWith("$");return n||r||t.push("^(?:"),t.push(te(e)),n||r||t.push(")$"),t.join("")}}class ae{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new h(`match() expected a string pattern, found ${t}`);return!1}if(this.iRegexpCheck&&!oe(t)){if(this.throwErrors)throw new h(`pattern ${t} is not a valid I-Regexp pattern`);return!1}try{const n=new RegExp(te(t),"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class ce{argTypes=[g.NodesType];returnType=g.ValueType;call(e){return 1===e.length?e.nodes[0].value:b}}let he=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 ue{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new ue(he.EOF,"",-1,"");class le{#n=0;constructor(e){this.tokens=e}get current(){return this.tokens[this.#n]}get peek(){return this.#n>=this.tokens.length-1?this.tokens[this.tokens.length-1]:this.tokens[this.#n+1]}next(){const e=this.current;return this.#n+=1,e}backup(){this.#n>0&&(this.#n-=1)}expect(e){if(this.current.kind!==e)throw new a(`expected token '${e}', found '${this.current.kind}'`,this.current)}expectPeek(e){const t=this.peek;if(t.kind!==e)throw new a(`expected token '${e}', found '${t.kind}'`,t)}}const pe=/e[+-]?\d+/y,fe=/[a-z][a-z_0-9]*/y,de=/-?\d+/y,ge=/-?[0-9]+/y,me=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ve=new Set([" ","\n","\t","\r"]),we=/[\u0080-\uFFFFa-zA-Z_]/;class ye{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e,t){this.environment=e,this.path=t}get pos(){return this.#n}get start(){return this.#r}run(){let e=xe;for(;e;)e=e(this)}emit(e){this.tokens.push(new ue(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 ue(he.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 ue(he.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ve)&&(this.ignore(),!0)}error(e){this.tokens.push(new ue(he.ERROR,e,this.#n,this.path))}}function Ee(e,t){const[n,r]=function(e,t){const n=new ye(e,t);return[n,n.tokens]}(e,t);if(n.run(),r.length&&r[r.length-1].kind===he.ERROR)throw new a(r[r.length-1].value,r[r.length-1]);return r}function xe(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(he.ROOT),Oe)}function Oe(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(he.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(he.DDOT),ke):Ne;case"[":return e.emit(he.LBRACKET),Se;default:return e.backup(),e.filterLevel?Te:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ke(e){if(e.acceptMatchRun(me))return e.emit(he.NAME),Oe;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(he.KEY),Oe):(e.emit(he.KEYS),Oe);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),Oe}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(he.WILD),Oe;case"[":return e.emit(he.LBRACKET),Se;default:return e.backup(),e.error(`unexpected descendent selection token '${t}'`),null}}function Ne(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(he.KEY),Oe):(e.emit(he.KEYS),Oe);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),Oe}if(e.acceptMatchRun(me))return e.emit(he.NAME),Oe;const t=e.next();return"*"===t?(e.emit(he.WILD),Oe):(e.backup(),e.error(`unexpected shorthand selector '${t}'`),null)}function Se(e){for(;;){if(e.ignoreWhitespace(),e.acceptMatchRun(de)){e.emit(he.INDEX);continue}if(!e.environment.strict&&e.acceptMatchRun(e.environment.keysPattern))switch(e.peek()){case"'":return e.ignore(),e.next(),Ie(e);case'"':return e.ignore(),e.next(),Ae(e);case"?":return e.next(),e.emit(he.KEYS_FILTER),e.filterLevel+=1,Te;default:e.emit(he.KEYS);continue}const t=e.next();switch(t){case"]":return e.emit(he.RBRACKET),e.filterLevel?Te:Oe;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(he.WILD);continue;case"?":return e.emit(he.FILTER),e.filterLevel+=1,Te;case",":e.emit(he.COMMA);continue;case":":e.emit(he.COLON);continue;case"'":return $e;case'"':return be;default:return e.backup(),e.error(`unexpected token '${t}' in bracketed selection`),null}}}function Te(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":return e.error("unclosed bracketed selection"),null;case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),Se);case",":if(e.emit(he.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,Se;case"'":return _e;case'"':return Pe;case"(":e.emit(he.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(he.RPAREN),e.parenStack.length&&(1===e.parenStack[e.parenStack.length-1]?e.parenStack.pop():e.parenStack[e.parenStack.length-1]-=1);continue;case"$":return e.emit(he.ROOT),Oe;case"@":return e.emit(he.CURRENT),Oe;case"#":return e.emit(he.CURRENT_KEY),Oe;case".":return e.backup(),Oe;case"!":"="===e.peek()?(e.next(),e.emit(he.NE)):e.emit(he.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(he.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(he.LE)):e.emit(he.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(he.GE)):e.emit(he.GT);continue;default:if(e.backup(),e.acceptMatchRun(ge)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ge)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(pe),e.emit(he.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(he.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(he.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(he.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(he.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(he.NULL);continue}if(e.acceptMatchRun(fe)&&"("===e.peek()){e.parenStack.push(1),e.emit(he.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Re(e,t,n){return function(r){if(r.ignore(),r.peek()===e)return r.emit("'"===e?he.SINGLE_QUOTE_STRING:he.DOUBLE_QUOTE_STRING),r.next(),r.ignore(),t;for(;;){const s=r.path.slice(r.pos,r.pos+2),o=r.next();if("\\\\"!==s&&s!==`\\${e}`){if("\\"===o&&!s.match(/\\[bfnrtu/]/))return r.error("invalid escape"),null;if(!o)return r.error(`unclosed string starting at index ${r.start}`),null;if(o===e)return r.backup(),r.emit(n),r.next(),r.ignore(),t}else r.next()}}}const $e=Re("'",Se,he.SINGLE_QUOTE_STRING),be=Re('"',Se,he.DOUBLE_QUOTE_STRING),_e=Re("'",Te,he.SINGLE_QUOTE_STRING),Pe=Re('"',Te,he.DOUBLE_QUOTE_STRING),Ie=Re("'",Se,he.KEY_SINGLE_QUOTE_STRING),Ae=Re('"',Se,he.KEY_DOUBLE_QUOTE_STRING);class Le{constructor(e,t){this.environment=e,this.token=t}}class Ce extends Le{constructor(e,t,n,r){super(e,t),this.environment=e,this.token=t,this.name=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)!u(n.value)&&_(n.value,this.name)&&t.push(new I(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)!u(t.value)&&_(t.value,this.name)&&(yield new I(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class Ke extends Le{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(u(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new I(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(u(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new I(t.value[e],t.location.concat(e),t.root))}}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Fe extends Le{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];for(const n of e)if(u(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new I(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(u(t.value))for(const[e,n]of this.lazySlice(t.value,this.start,this.stop,this.step))yield new I(n,t.location.concat(e),t.root)}toString(){return`${this.start?this.start:""}:${this.stop?this.stop:""}:${this.step?this.step:"1"}`}checkRange(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(const e of t)if(void 0!==e&&(e<this.environment.minIntIndex||e>this.environment.maxIntIndex))throw new o("index out of range",this.token)}slice(e,t,n,r){if(!e.length)return[];if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),0===r)return[];r||(r=1);const s=[];if(r>0)for(let o=t;o<n;o+=r)s.push([o,e[o]]);else for(let o=t;o>n;o+=r)s.push([o,e[o]]);return s}*lazySlice(e,t,n,r){if(e.length)if(t=null==t?r&&r<0?e.length-1:0:t<0?Math.max(e.length+t,0):Math.min(t,e.length-1),n=null==n?r&&r<0?-1:e.length:n<0?Math.max(e.length+n,-1):Math.min(n,e.length),void 0===r)for(let r=t;r<n;r+=1)yield[r,e[r]];else if(r>0)for(let s=t;s<n;s+=r)yield[s,e[s]];else if(r<0)for(let s=t;s>n;s+=r)yield[s,e[s]]}}class Me extends Le{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(u(n.value))for(let e=0;e<n.value.length;e++)t.push(new I(n.value[e],n.location.concat(e),n.root));else if(l(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new I(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(u(t.value))for(let e=0;e<t.value.length;e++)yield new I(t.value[e],t.location.concat(e),t.root);else if(l(t.value))for(const[e,n]of this.environment.entries(t.value))yield new I(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class je extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];if(this.environment.nondeterministic)for(const n of e)for(const e of this.nondeterministicVisitor(n))t.push(e);else for(const n of e){t.push(n);for(const e of this.visitor(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);if(!(t.value instanceof String))if(u(t.value))for(let r=0;r<t.value.length;r++){const s=new I(t.value[r],t.location.concat(r),t.root);yield s,l(s.value)&&e.push({node:s,depth:n+1})}else if(l(t.value))for(const[r,s]of this.environment.entries(t.value)){const o=new I(s,t.location.concat(r),t.root);yield o,l(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(u(e.value))for(let r=0;r<e.value.length;r++){const s=new I(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visitor(s,t+1))n.push(e)}else if(l(e.value))for(const[r,s]of this.environment.entries(e.value)){const o=new I(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visitor(o,t+1))n.push(e)}return n}nondeterministicVisitor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=[e];let r=this.nondeterministicChildren(e).map((e=>[e,t]));for(;r.length;){const[e,t]=r.shift();if(n.push(e),t>=this.environment.maxRecursionDepth)throw new c("recursion limit reached",this.token);const s=Math.random()<.5;for(const o of this.nondeterministicChildren(e))if(s){n.push(o);r=Je(r,this.nondeterministicChildren(o).map((e=>[e,t+2])))}else r.push([o,t+1])}return n}nondeterministicChildren(e){const t=[];if(e.value instanceof String)return t;if(u(e.value))for(let n=0;n<e.value.length;n++)t.push(new I(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 I(r,e.location.concat(n),e.root));return t}}class Ue extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(u(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(r,n.location.concat(e),n.root))}else if(l(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(u(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(n,t.location.concat(e),t.root))}else if(l(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class ze extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.items=n}resolve(e){const t=[];for(const n of e)for(const e of this.items)for(const r of e.resolve([n]))t.push(r);return t}*lazyResolve(e){for(const t of e)for(const e of this.items)yield*e.lazyResolve([t])}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}function Je(e,t){if(0===e.length)return t;if(0===t.length)return e;const n=[],r=e[Symbol.iterator](),s=t[Symbol.iterator]();for(let t=0;t<e.length;t++)n.push(r);for(let e=0;e<t.length;e++)n.push(s);return function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}(n),n.map((e=>e.next().value))}var De=Object.freeze({__proto__:null,BracketedSelection:ze,FilterSelector:Ue,IndexSelector:Ke,JSONPathSelector:Le,NameSelector:Ce,RecursiveDescentSegment:je,SliceSelector:Fe,WildcardSelector:Me});class Ge{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new I(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new A(t)}lazyQuery(e){let t=[new I(e,[],e)][Symbol.iterator]();for(const e of this.selectors)t=e.lazyResolve(t);return t}match(e){const t=this.lazyQuery(e).next();if(!t.done)return t.value}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof Ce||e instanceof ze&&1===e.items.length&&(e.items[0]instanceof Ce||e.items[0]instanceof Ke)))return!1;return!0}}class Qe extends L{evaluate(e){return e.currentKey??b}toString(){return"#"}}class Ve extends Le{constructor(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];super(e,t),this.environment=e,this.token=t,this.key=n,this.shorthand=r}resolve(e){const t=[];for(const n of e)n.value instanceof String||u(n.value)||l(n.value)&&_(n.value,this.key)&&t.push(new I(this.key,n.location.concat(`${P}${this.key}`),n.root));return t}*lazyResolve(e){for(const t of e)t.value instanceof String||u(t.value)||l(t.value)&&_(t.value,this.key)&&(yield new I(this.key,t.location.concat(`${P}${this.key}`),t.root))}toString(){return this.shorthand?`[~'${this.key.replaceAll("'","\\'")}']`:`~'${this.key.replaceAll("'","\\'")}'`}}class We extends Le{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||u(n.value))&&l(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new I(e,n.location.concat(`${P}${e}`),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||u(t.value))&&l(t.value))for(const[e,n]of this.environment.entries(t.value))yield new I(e,t.location.concat(`${P}${e}`),t.root)}toString(){return this.shorthand?"[~]":"~"}}class Be extends Le{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String||u(n.value))&&l(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root,currentKey:e};this.expression.evaluate(s)&&t.push(new I(e,n.location.concat(`${P}${e}`),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String||u(t.value))&&l(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0,currentKey:e};this.expression.evaluate(r)&&(yield new I(e,t.location.concat(`${P}${e}`),t.root))}}toString(){return`~?${this.expression.toString()}`}}const Ye=new Map([[he.AND,5],[he.EQ,6],[he.GE,6],[he.GT,6],[he.LE,6],[he.LT,6],[he.NE,6],[he.NOT,7],[he.OR,4],[he.RPAREN,1]]),qe=new Map([[he.AND,"&&"],[he.EQ,"=="],[he.GE,">="],[he.GT,">"],[he.LE,"<="],[he.LT,"<"],[he.NE,"!="],[he.OR,"||"]]),Xe=new Set(["==",">=",">","<=","<","!="]);class Ze{constructor(e){this.environment=e,this.tokenMap=new Map([[he.FALSE,this.parseBoolean],[he.NUMBER,this.parseNumber],[he.LPAREN,this.parseGroupedExpression],[he.NOT,this.parsePrefixExpression],[he.NULL,this.parseNull],[he.ROOT,this.parseRootQuery],[he.CURRENT,this.parseRelativeQuery],[he.SINGLE_QUOTE_STRING,this.parseString],[he.DOUBLE_QUOTE_STRING,this.parseString],[he.TRUE,this.parseBoolean],[he.FUNCTION,this.parseFunction],[he.CURRENT_KEY,this.parseCurrentKey]])}parse(e){e.current.kind===he.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==he.EOF)throw new a(`unexpected token '${e.current.kind}'`,e.current);return t}parsePath(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=[];for(;;){const r=this.parseSegment(e);if(!r){t&&e.backup();break}n.push(r),e.next()}return n}parseSegment(e){switch(e.current.kind){case he.NAME:return new Ce(this.environment,e.current,e.current.value,!0);case he.WILD:return new Me(this.environment,e.current,!0);case he.KEY:return new Ve(this.environment,e.current,e.current.value,!0);case he.KEYS:return new We(this.environment,e.current,!0);case he.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new je(this.environment,t,n)}case he.LBRACKET:return this.parseBracketedSelection(e);default:return null}}parseIndex(e){if(e.current.value.length>1&&e.current.value.startsWith("0")||e.current.value.startsWith("-0"))throw new a("leading zero in index selector",e.current);return new Ke(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===he.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(he.COLON),e.next()):(n.push(void 0),e.expect(he.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===he.COLON&&e.next()):e.current.kind===he.COLON&&(n.push(void 0),e.expect(he.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Fe(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==he.RBRACKET;){switch(e.current.kind){case he.SINGLE_QUOTE_STRING:case he.DOUBLE_QUOTE_STRING:n.push(new Ce(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case he.FILTER:n.push(this.parseFilter(e));break;case he.INDEX:e.peek.kind===he.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case he.COLON:n.push(this.parseSlice(e));break;case he.WILD:n.push(new Me(this.environment,e.current));break;case he.KEY_SINGLE_QUOTE_STRING:case he.KEY_DOUBLE_QUOTE_STRING:n.push(new Ve(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case he.KEYS_FILTER:n.push(this.parseFilter(e,!0));break;case he.KEYS:n.push(new We(this.environment,e.current));break;case he.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!==he.RBRACKET&&(e.expectPeek(he.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new ze(this.environment,t,n)}parseFilter(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=e.next(),r=this.parseFilterExpression(e);if(r instanceof V){const e=this.environment.functionRegister.get(r.name);if(e&&e.returnType===g.ValueType)throw new s(`result of ${r.name}() must be compared`,r.token)}return this.throwForLiteral(r),t?new Be(this.environment,n,new J(n,r)):new Ue(this.environment,n,new J(n,r))}parseBoolean(e){return e.current.kind===he.FALSE?new F(e.current,!1):new F(e.current,!0)}parseNull(e){return new K(e.current)}parseString(e){return new M(e.current,this.decodeString(e.current))}parseNumber(e){return new j(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(he.NOT),e.next(),new U(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ye.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=qe.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Xe.has(o)?(this.throwForNonComparable(t),this.throwForNonComparable(s)):(this.throwForLiteral(t),this.throwForLiteral(s)),new z(n,t,o,s)}parseGroupedExpression(e){if(e.peek.kind===he.RPAREN)throw new a("empty paren expression",e.current);e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==he.RPAREN;){if(e.current.kind===he.EOF)throw new a("unbalanced parentheses",e.current);if(!qe.has(e.current.kind))throw new a(`expected an expression, found '${e.current.value}'`,e.current);t=this.parseInfixExpression(e,t)}return e.expect(he.RPAREN),t}parseRootQuery(e){const t=e.next();return new Q(t,new Ge(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new G(t,new Ge(this.environment,this.parsePath(e,!0)))}parseCurrentKey(e){return new Qe(e.current)}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==he.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(;qe.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==he.RPAREN){if(e.peek.kind===he.RBRACKET)break;e.expectPeek(he.COMMA),e.next()}e.next()}return e.expect(he.RPAREN),new V(n,n.value,this.environment.checkWellTypedness(n,t))}parseFilterExpression(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const n=this.tokenMap.get(e.current.kind);if(!n){let t;switch(e.current.kind){case he.EOF:case he.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===he.EOF||n===he.RBRACKET||(Ye.get(n)||1)<t)break;if(!qe.has(n))return r;e.next(),r=this.parseInfixExpression(e,r)}return r}decodeString(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{return JSON.parse(e.kind===he.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonComparable(e){if((e instanceof Q||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof V){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof C)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}class He{functionRegister=new Map;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??-Math.pow(2,53)-1,this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new Ze(this),this.setupFilterFunctions()}compile(e){return new Ge(this,this.parser.parse(new le(Ee(this,e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new Z),this.functionRegister.set("length",new H),this.functionRegister.set("search",new ae),this.functionRegister.set("match",new ie),this.functionRegister.set("value",new ce)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case g.ValueType:if(!(o instanceof C||o instanceof Qe||o instanceof D&&o.path.singularQuery()||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case g.LogicalType:if(!(o instanceof D||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof D||o instanceof V&&this.functionRegister.get(o.name)?.returnType===g.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var et=Object.freeze({__proto__:null,Count:Z,FunctionExpressionType:g,Length:H,Match:ie,Search:ae,Value:ce});const tt=new He;function nt(e,t){return tt.query(e,t)}function rt(e,t){return tt.lazyQuery(e,t)}function st(e){return tt.compile(e)}var ot=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:tt,FunctionExpressionType:g,JSONPath:Ge,JSONPathEnvironment:He,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:I,JSONPathNodeList:A,JSONPathRecursionLimitError:c,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:P,Nothing:b,Token:ue,TokenKind:he,compile:st,expressions:X,functions:et,lazyQuery:rt,match:function(e,t){return tt.match(e,t)},query:nt,selectors:De});class it extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class at extends it{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class ct{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n))if(r===O){if("-"!==s)throw new it(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ht{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)throw new it(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===O)throw new it(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===O)throw new it(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class ut{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===O)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===O)throw new it(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!l(n))throw new it(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===O)throw new it(`can't replace nonexistent property (${this.name}:${t})`);n[s]=this.value}return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class lt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new it(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===O)throw new it(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);u(n)?n.splice(Number(s),1):l(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===O)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(o))o.splice(Number(a),0,r);else{if(!l(o))throw new it(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);o[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class pt{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===O)throw new it(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===O)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new it(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!l(s))throw new it(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);s[o]=this.deepCopy(r)}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}deepCopy(e){return JSON.parse(JSON.stringify(e))}}class ft{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 at(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class dt{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 ct(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new ht(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new ut(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new lt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new pt(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new ft(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 it(`${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 it(`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 it(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new it(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new k(s)}catch(e){if(e instanceof m)throw new it(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new it(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof k)return e;if(!p(e))throw new it(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new k(e)}catch(e){if(e instanceof m)throw new it(`${e.message} (${t}:${n})`);throw e}}}function gt(e,t){return new dt(e).apply(t)}var mt=Object.freeze({__proto__:null,JSONPatch:dt,JSONPatchError:it,JSONPatchTestFailure:at,apply:gt});return e.DEFAULT_ENVIRONMENT=tt,e.FunctionExpressionType=g,e.JSONPatch=dt,e.JSONPatchError=it,e.JSONPatchTestFailure=at,e.JSONPath=Ge,e.JSONPathEnvironment=He,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=I,e.JSONPathNodeList=A,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=k,e.Nothing=b,e.RelativeJSONPointer=T,e.Token=ue,e.TokenKind=he,e.UNDEFINED=O,e.apply=gt,e.compile=st,e.jsonpatch=mt,e.jsonpath=ot,e.jsonpointer=$,e.lazyQuery=rt,e.query=nt,e.resolve=R,e.version="1.3.3",e}({});
2
2
  //# sourceMappingURL=json-p3.iife.min.js.map