json-p3 1.3.3 → 1.3.4

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.3
2
+ * json-p3 version 1.3.4
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -2553,6 +2553,12 @@ var json_p3 = (function (exports) {
2553
2553
  throw new JSONPathSyntaxError(`expected token '${kind}', found '${peeked.kind}'`, peeked);
2554
2554
  }
2555
2555
  }
2556
+ expectPeekNot(kind, message) {
2557
+ const peeked = this.peek;
2558
+ if (peeked.kind === kind) {
2559
+ throw new JSONPathSyntaxError(message, peeked);
2560
+ }
2561
+ }
2556
2562
  }
2557
2563
 
2558
2564
  /** A lexer that accepts additional, non-standard tokens. */
@@ -2560,7 +2566,7 @@ var json_p3 = (function (exports) {
2560
2566
 
2561
2567
  // These regular expressions are to be used with Lexer.acceptMatchRun(),
2562
2568
  // which expects the sticky flag to be set.
2563
- const exponentPattern = /e[+-]?\d+/y;
2569
+ const exponentPattern = /[eE][+-]?\d+/y;
2564
2570
  const functionNamePattern = /[a-z][a-z_0-9]*/y;
2565
2571
  const indexPattern = /-?\d+/y;
2566
2572
  const intPattern = /-?[0-9]+/y;
@@ -4003,7 +4009,7 @@ var json_p3 = (function (exports) {
4003
4009
  switch (stream.current.kind) {
4004
4010
  case TokenKind.SINGLE_QUOTE_STRING:
4005
4011
  case TokenKind.DOUBLE_QUOTE_STRING:
4006
- items.push(new NameSelector(this.environment, stream.current, this.decodeString(stream.current, true), false));
4012
+ items.push(new NameSelector(this.environment, stream.current, this.decodeString(stream.current), false));
4007
4013
  break;
4008
4014
  case TokenKind.FILTER:
4009
4015
  items.push(this.parseFilter(stream));
@@ -4023,7 +4029,7 @@ var json_p3 = (function (exports) {
4023
4029
  break;
4024
4030
  case TokenKind.KEY_SINGLE_QUOTE_STRING:
4025
4031
  case TokenKind.KEY_DOUBLE_QUOTE_STRING:
4026
- items.push(new KeySelector(this.environment, stream.current, this.decodeString(stream.current, true), false));
4032
+ items.push(new KeySelector(this.environment, stream.current, this.decodeString(stream.current), false));
4027
4033
  break;
4028
4034
  case TokenKind.KEYS_FILTER:
4029
4035
  items.push(this.parseFilter(stream, true));
@@ -4039,6 +4045,7 @@ var json_p3 = (function (exports) {
4039
4045
  if (stream.peek.kind !== TokenKind.RBRACKET) {
4040
4046
  stream.expectPeek(TokenKind.COMMA);
4041
4047
  stream.next();
4048
+ stream.expectPeekNot(TokenKind.RBRACKET, "unexpected trailing comma");
4042
4049
  }
4043
4050
  stream.next();
4044
4051
  }
@@ -4071,7 +4078,15 @@ var json_p3 = (function (exports) {
4071
4078
  return new StringLiteral(stream.current, this.decodeString(stream.current));
4072
4079
  }
4073
4080
  parseNumber(stream) {
4074
- return new NumberLiteral(stream.current, Number(stream.current.value));
4081
+ const value = stream.current.value;
4082
+ if (value.startsWith("0") && value.length > 1) {
4083
+ throw new JSONPathSyntaxError(`invalid number literal '${value}'`, stream.current);
4084
+ }
4085
+ const num = Number(stream.current.value);
4086
+ if (isNaN(num)) {
4087
+ throw new JSONPathSyntaxError(`invalid number literal '${value}'`, stream.current);
4088
+ }
4089
+ return new NumberLiteral(stream.current, num);
4075
4090
  }
4076
4091
  parsePrefixExpression(stream) {
4077
4092
  stream.expect(TokenKind.NOT);
@@ -4182,11 +4197,155 @@ var json_p3 = (function (exports) {
4182
4197
  return left;
4183
4198
  }
4184
4199
  decodeString(token) {
4185
- let isName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
4200
+ return this.unescapeString(token.kind === TokenKind.SINGLE_QUOTE_STRING ? token.value.replaceAll('"', '\\"').replaceAll("\\'", "'") : token.value, token);
4201
+ }
4202
+ unescapeString(value, token) {
4203
+ const rv = [];
4204
+ const length = value.length;
4205
+ let index = 0;
4206
+ let codepoint;
4207
+ while (index < length) {
4208
+ const ch = value[index];
4209
+ if (ch === "\\") {
4210
+ // Handle escape sequences
4211
+ index += 1; // Move past '\'
4212
+
4213
+ switch (value[index]) {
4214
+ case '"':
4215
+ rv.push('"');
4216
+ break;
4217
+ case "\\":
4218
+ rv.push("\\");
4219
+ break;
4220
+ case "/":
4221
+ rv.push("/");
4222
+ break;
4223
+ case "b":
4224
+ rv.push("\x08");
4225
+ break;
4226
+ case "f":
4227
+ rv.push("\x0C");
4228
+ break;
4229
+ case "n":
4230
+ rv.push("\n");
4231
+ break;
4232
+ case "r":
4233
+ rv.push("\r");
4234
+ break;
4235
+ case "t":
4236
+ rv.push("\t");
4237
+ break;
4238
+ case "u":
4239
+ [codepoint, index] = this.decodeHexChar(value, index, token);
4240
+ rv.push(this.stringFromCodePoint(codepoint, token));
4241
+ break;
4242
+ default:
4243
+ // TODO: This is unreachable. The lexer will catch unknown escape sequences.
4244
+ throw new JSONPathSyntaxError(`unknown escape sequence at index ${token.index + index - 1}`, token);
4245
+ }
4246
+ } else {
4247
+ this.stringFromCodePoint(ch.codePointAt(0), token);
4248
+ rv.push(ch);
4249
+ }
4250
+ index += 1;
4251
+ }
4252
+ return rv.join("");
4253
+ }
4254
+
4255
+ /**
4256
+ * Decode a `\uXXXX` or `\uXXXX\uXXXX` escape sequence from _value_ at _index_.
4257
+ *
4258
+ * @param value - A string value containing the sequence to decode.
4259
+ * @param index - The start index of an escape sequence in _value_.
4260
+ * @param token - The token for the string value.
4261
+ * @returns - A codepoint, new index tuple.
4262
+ */
4263
+ decodeHexChar(value, index, token) {
4264
+ const length = value.length;
4265
+ if (index + 4 >= length) {
4266
+ throw new JSONPathSyntaxError(`incomplete escape sequence at index ${token.index + index - 1}`, token);
4267
+ }
4268
+ index += 1; // Move past 'u'
4269
+ let codepoint = this.parseHexDigits(value.slice(index, index + 4), token);
4270
+ if (isLowSurrogate(codepoint)) {
4271
+ throw new JSONPathSyntaxError(`unexpected low surrogate codepoint at index ${token.index + index - 2}`, token);
4272
+ }
4273
+ if (isHighSurrogate(codepoint)) {
4274
+ // Expect a surrogate pair.
4275
+ if (!(index + 9 < length && value[index + 4] === "\\" && value[index + 5] === "u")) {
4276
+ throw new JSONPathSyntaxError(`incomplete escape sequence at index ${token.index + index - 2}`, token);
4277
+ }
4278
+ const lowSurrogate = this.parseHexDigits(value.slice(index + 6, index + 10), token);
4279
+ if (!isLowSurrogate(lowSurrogate)) {
4280
+ throw new JSONPathSyntaxError(`unexpected codepoint at index ${token.index + index + 4}`, token);
4281
+ }
4282
+ codepoint = 0x10000 + ((codepoint & 0x03ff) << 10 | lowSurrogate & 0x03ff);
4283
+ return [codepoint, index + 9];
4284
+ }
4285
+ return [codepoint, index + 3];
4286
+ }
4287
+
4288
+ /**
4289
+ * Parse a hexadecimal string as an integer.
4290
+ *
4291
+ * @param digits - Hexadecimal digit string.
4292
+ * @param token - The token for the string value.
4293
+ * @returns - The number representation of _digits_.
4294
+ *
4295
+ * Note that we're not using `parseInt(digits, 16)` because it accepts `+`
4296
+ * and `-` and things we don't allow.
4297
+ */
4298
+ parseHexDigits(digits, token) {
4299
+ const encoder = new TextEncoder();
4300
+ let codepoint = 0;
4301
+ for (const digit of encoder.encode(digits)) {
4302
+ codepoint <<= 4;
4303
+ switch (digit) {
4304
+ case 48:
4305
+ case 49:
4306
+ case 50:
4307
+ case 51:
4308
+ case 52:
4309
+ case 53:
4310
+ case 54:
4311
+ case 55:
4312
+ case 56:
4313
+ case 57:
4314
+ codepoint |= digit - 48; // '0'
4315
+ break;
4316
+ case 97:
4317
+ case 98:
4318
+ case 99:
4319
+ case 100:
4320
+ case 101:
4321
+ case 102:
4322
+ codepoint |= digit - 97 + 10; // 'a'
4323
+ break;
4324
+ case 65:
4325
+ case 66:
4326
+ case 67:
4327
+ case 68:
4328
+ case 69:
4329
+ case 70:
4330
+ codepoint |= digit - 65 + 10; // 'A'
4331
+ break;
4332
+ default:
4333
+ throw new JSONPathSyntaxError("invalid \\uXXXX escape sequence", token);
4334
+ }
4335
+ }
4336
+ return codepoint;
4337
+ }
4338
+
4339
+ /** Check the codepoint is valid and return its string representation. */
4340
+ stringFromCodePoint(codepoint, token) {
4341
+ if (codepoint === undefined || codepoint <= 0x1f) {
4342
+ throw new JSONPathSyntaxError(`invalid character`, token);
4343
+ }
4186
4344
  try {
4187
- return JSON.parse(token.kind === TokenKind.SINGLE_QUOTE_STRING ? `"${token.value.replaceAll('"', '\\"').replaceAll("\\'", "'")}"` : `"${token.value}"`);
4345
+ return String.fromCodePoint(codepoint);
4188
4346
  } catch {
4189
- throw new JSONPathSyntaxError(`invalid ${isName ? "name selector" : "string literal"} '${token.value}'`, token);
4347
+ // This should not be reachable.
4348
+ throw new JSONPathSyntaxError("invalid escape sequence", token);
4190
4349
  }
4191
4350
  }
4192
4351
  throwForNonComparable(expr) {
@@ -4206,6 +4365,12 @@ var json_p3 = (function (exports) {
4206
4365
  }
4207
4366
  }
4208
4367
  }
4368
+ function isHighSurrogate(codepoint) {
4369
+ return codepoint >= 0xd800 && codepoint <= 0xdbff;
4370
+ }
4371
+ function isLowSurrogate(codepoint) {
4372
+ return codepoint >= 0xdc00 && codepoint <= 0xdfff;
4373
+ }
4209
4374
 
4210
4375
  /**
4211
4376
  * JSONPath environment options. The defaults are in compliance with JSONPath
@@ -4263,7 +4428,7 @@ var json_p3 = (function (exports) {
4263
4428
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4264
4429
  this.strict = options.strict ?? true;
4265
4430
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
4266
- this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) - 1;
4431
+ this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) + 1;
4267
4432
  this.maxRecursionDepth = options.maxRecursionDepth ?? 50;
4268
4433
  this.nondeterministic = options.nondeterministic ?? false;
4269
4434
  this.keysPattern = options.keysPattern ?? /~/y;
@@ -4987,7 +5152,7 @@ var json_p3 = (function (exports) {
4987
5152
  apply: apply
4988
5153
  });
4989
5154
 
4990
- const version = "1.3.3";
5155
+ const version = "1.3.4";
4991
5156
 
4992
5157
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
4993
5158
  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 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}({});
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 x extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class E extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends v{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const k=Symbol.for("jsonpointer.undefined");class O{#e;constructor(e){this.tokens=this.parse(e),this.#e=O.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof v&&t!==k)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[k,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof w||e instanceof x)return[t,k];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every(((t,n)=>t===e.tokens[n]))}parse(e){if(e.length&&!e.startsWith("/"))throw new 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 '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new w(`index out of range '${O.encode(this.tokens.slice(0,n+1))}'`)}if(l(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new x(`no such property '${O.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${O.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!p(e))throw new y("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new O(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new O(O.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof v)return!1;throw e}return!0}parent(){return this.tokens.length?new O(O.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(p(e)?new T(e):e).to(this)}}const N=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,S=/(0|[1-9][0-9]*)/;class T{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=p(e)?new O(e):e;if(this.origin>t.tokens.length)throw new w(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new w(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof O?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new O(O.encode(n))}parse(e){const t=N.exec(e);if(!t||!t.groups)throw new E("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new E("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new O(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new E("unexpected leading zero");if(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]:k;return new O(e).resolve(t,n)}var $=Object.freeze({__proto__:null,JSONPointer:O,JSONPointerError:m,JSONPointerIndexError:w,JSONPointerKeyError:x,JSONPointerResolutionError:v,JSONPointerSyntaxError:E,JSONPointerTypeError:y,RelativeJSONPointer:T,UNDEFINED:k,resolve:R});const b=Symbol.for("jsonpath.nothing");function P(e,t){return l(e)&&Object.hasOwn(e,t)}const _="";class A{constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>p(e)?this.decode_name_location(e):`[${e}]`)).join("")}toPointer(){return this.location.length?new O(O.encode(this.location.map(String))):new O("")}decode_name_location(e){return e.startsWith(_)?`[~'${e.slice(1).replaceAll("'","\\'")}']`:`['${e.replaceAll("'","\\'")}']`}}class I{constructor(e){this.nodes=e}[Symbol.iterator](){return this.nodes[Symbol.iterator]()}empty(){return 0===this.nodes.length}values(){return this.nodes.map((e=>e.value))}valuesOrSingular(){return 1===this.nodes.length?this.nodes[0].value:this.nodes.map((e=>e.value))}locations(){return this.nodes.map((e=>e.location))}paths(){return this.nodes.map((e=>e.path))}pointers(){return this.nodes.map((e=>e.toPointer()))}get length(){return this.nodes.length}}class L{constructor(e){this.token=e}}class C extends L{}class K extends C{evaluate(){return null}toString(){return"null"}}class F extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class M extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class j extends C{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class U extends L{constructor(e,t,n){super(e),this.token=e,this.operator=t,this.right=n}evaluate(e){if("!"===this.operator){const t=this.right.evaluate(e);return t instanceof I?0===t.nodes.length:!W(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class z extends L{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r,this.logical="&&"===n||"||"===n}evaluate(e){let t=this.left.evaluate(e);!this.logical&&t instanceof I&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return!this.logical&&n instanceof I&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?W(t)&&W(n):"||"===this.operator?W(t)||W(n):B(t,this.operator,n)}toString(){return this.logical?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class D extends L{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof I?t.nodes.length>0:W(t)}toString(){return this.expression.toString()}}class J extends L{constructor(e,t){super(e),this.token=e,this.path=t}}class G extends J{evaluate(e){return e.lazy?new I(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class Q extends J{evaluate(e){return e.lazy?new I(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class V extends L{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==g.NodesType&&e instanceof I?this.unpack_node_list(e):e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}unpack_node_list(e){switch(e.length){case 0:return b;case 1:return e.nodes[0].value;default:return e}}}function W(e){return!(e instanceof I&&e.empty())&&!("boolean"==typeof e&&!1===e)}function B(e,t,n){switch(t){case"==":return Y(e,n);case"!=":return!Y(e,n);case"<":return q(e,n);case">":return q(n,e);case">=":return q(n,e)||Y(e,n);case"<=":return q(e,n)||Y(e,n);default:return!1}}function Y(e,t){if(t instanceof I&&([e,t]=[t,e]),e instanceof I){if(t instanceof I){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return d(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===b:1===e.nodes.length&&d(e.nodes[0].value,t)}return e===b&&t===b||d(e,t)}function q(e,t){return!!(p(e)&&p(t)||f(e)&&f(t))&&e<t}var X=Object.freeze({__proto__:null,BooleanLiteral:F,FilterExpression:L,FilterExpressionLiteral:C,FunctionExtension:V,InfixExpression:z,JSONPathQuery:J,LogicalExpression:D,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:Ae},h=Ae,u="|",l="{",p=",",f="}",d="(",g=")",m=".",v="\\",w="[",x="^",E="-",y="]",k="\\p{",O="\\P{",N="L",S="M",T="N",R="P",$="Z",b="S",P="C",_=/^[*-+?]/,A=/^[0-9]/,I=/^[(-+\--.?[-\^nrt{-}]/,L=/^[l-mot-u]/,C=/^[cen]/,K=/^[dlo]/,F=/^[c-fios]/,M=/^[lps]/,j=/^[ckmo]/,U=/^[cfn-o]/,z=Re("|",!1),D=$e([["*","+"],"?"],!1,!1),J=Re("{",!1),G=$e([["0","9"]],!1,!1),Q=Re(",",!1),V=Re("}",!1),W=Re("(",!1),B=Re(")",!1),Y={type:"any"},q=Re(".",!1),X=Re("\\",!1),Z=$e([["(","+"],["-","."],"?",["[","^"],"n","r","t",["{","}"]],!1,!1),H=Re("[",!1),ee=Re("^",!1),te=Re("-",!1),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),xe=$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)},ye=function(e){return function(e){return e<","||e>="."&&e<="Z"||e>="^"&&e<="퟿"||e>=""}(e)},ke=0|t.peg$currPos,Oe=[{line:1,column:1}],Ne=ke,Se=t.peg$maxFailExpected||[],Te=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');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=Oe[t];if(r)return r;if(t>=Oe.length)n=Oe.length-1;else for(n=t;!Oe[--n];);for(r={line:(r=Oe[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return Oe[t]=r,r}function Pe(e,t,n){var r=be(e),s=be(t);return{source:a,start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:s.line,column:s.column}}}function _e(e){ke<Ne||(ke>Ne&&(Ne=ke,Se=[]),Se.push(e))}function Ae(){return Ie()}function Ie(){var t,n,r,s;for(ke,t=Le(),n=[],r=ke,124===e.charCodeAt(ke)?(s=u,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);r!==i;)n.push(r),r=ke,124===e.charCodeAt(ke)?(s=u,ke++):(s=i,0===Te&&_e(z)),s!==i?r=s=[s,Le()]:(ke=r,r=i);return t=[t,n]}function Le(){var e,t;for(e=[],t=Ce();t!==i;)e.push(t),t=Ce();return e}function Ce(){var t,n,r;return t=ke,n=function(){var t,n,r,s;t=function(){var t,n;t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y));n!==i&&(Ee(n)?void 0:i)!==i?t=n:(ke=t,t=i);return t}(),t===i&&(t=function(){var t;46===e.charCodeAt(ke)?(t=m,ke++):(t=i,0===Te&&_e(q));t===i&&(t=Ke())===i&&(t=Fe())===i&&(t=function(){var t,n,r,s,o,a,c;t=ke,91===e.charCodeAt(ke)?(n=w,ke++):(n=i,0===Te&&_e(H));if(n!==i)if(94===e.charCodeAt(ke)?(r=x,ke++):(r=i,0===Te&&_e(ee)),r===i&&(r=null),45===e.charCodeAt(ke)?(s=E,ke++):(s=i,0===Te&&_e(te)),s===i&&(s=Me()),s!==i){for(o=[],a=Me();a!==i;)o.push(a),a=Me();45===e.charCodeAt(ke)?(a=E,ke++):(a=i,0===Te&&_e(te)),a===i&&(a=null),93===e.charCodeAt(ke)?(c=y,ke++):(c=i,0===Te&&_e(re)),c!==i?t=n=[n,r,s,o,a,c]:(ke=t,t=i)}else ke=t,t=i;else ke=t,t=i;return t}());return t}(),t===i&&(t=ke,40===e.charCodeAt(ke)?(n=d,ke++):(n=i,0===Te&&_e(W)),n!==i&&(r=Ie())!==i?(41===e.charCodeAt(ke)?(s=g,ke++):(s=i,0===Te&&_e(B)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i)));return t}(),n!==i?(r=function(){var t;t=e.charAt(ke),_.test(t)?ke++:(t=i,0===Te&&_e(D));t===i&&(t=function(){var t,n,r,s,o,a;t=ke,123===e.charCodeAt(ke)?(n=l,ke++):(n=i,0===Te&&_e(J));n!==i?(r=e.charAt(ke),A.test(r)?ke++:(r=i,0===Te&&_e(G)),r!==i?(s=ke,44===e.charCodeAt(ke)?(o=p,ke++):(o=i,0===Te&&_e(Q)),o!==i?(a=e.charAt(ke),A.test(a)?ke++:(a=i,0===Te&&_e(G)),a===i&&(a=null),s=o=[o,a]):(ke=s,s=i),s===i&&(s=null),125===e.charCodeAt(ke)?(o=f,ke++):(o=i,0===Te&&_e(V)),o!==i?t=n=[n,r,s,o]:(ke=t,t=i)):(ke=t,t=i)):(ke=t,t=i);return t}());return t}(),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t}function Ke(){var t,n,r;return t=ke,92===e.charCodeAt(ke)?(n=v,ke++):(n=i,0===Te&&_e(X)),n!==i?(r=e.charAt(ke),I.test(r)?ke++:(r=i,0===Te&&_e(Z)),r!==i?t=n=[n,r]:(ke=t,t=i)):(ke=t,t=i),t}function Fe(){var t;return(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===k?(n=k,ke+=3):(n=i,0===Te&&_e(se));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r,s;t=ke,e.substr(ke,3)===O?(n=O,ke+=3):(n=i,0===Te&&_e(oe));n!==i&&(r=Ue())!==i?(125===e.charCodeAt(ke)?(s=f,ke++):(s=i,0===Te&&_e(V)),s!==i?t=n=[n,r,s]:(ke=t,t=i)):(ke=t,t=i);return t}()),t}function Me(){var t,n,r,s,o;return t=ke,(n=je())!==i?(r=ke,45===e.charCodeAt(ke)?(s=E,ke++):(s=i,0===Te&&_e(te)),s!==i&&(o=je())!==i?r=s=[s,o]:(ke=r,r=i),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i),t===i&&(t=Fe()),t}function je(){var t,n;return t=ke,e.length>ke?(n=e.charAt(ke),ke++):(n=i,0===Te&&_e(Y)),n!==i&&(ye(n)?void 0:i)!==i?t=n:(ke=t,t=i),t===i&&(t=Ke()),t}function Ue(){var t;return(t=function(){var t,n,r;t=ke,76===e.charCodeAt(ke)?(n=N,ke++):(n=i,0===Te&&_e(ie));n!==i?(r=e.charAt(ke),L.test(r)?ke++:(r=i,0===Te&&_e(ae)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,77===e.charCodeAt(ke)?(n=S,ke++):(n=i,0===Te&&_e(ce));n!==i?(r=e.charAt(ke),C.test(r)?ke++:(r=i,0===Te&&_e(he)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,78===e.charCodeAt(ke)?(n=T,ke++):(n=i,0===Te&&_e(ue));n!==i?(r=e.charAt(ke),K.test(r)?ke++:(r=i,0===Te&&_e(le)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,80===e.charCodeAt(ke)?(n=R,ke++):(n=i,0===Te&&_e(pe));n!==i?(r=e.charAt(ke),F.test(r)?ke++:(r=i,0===Te&&_e(fe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,90===e.charCodeAt(ke)?(n=$,ke++):(n=i,0===Te&&_e(de));n!==i?(r=e.charAt(ke),M.test(r)?ke++:(r=i,0===Te&&_e(ge)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,83===e.charCodeAt(ke)?(n=b,ke++):(n=i,0===Te&&_e(me));n!==i?(r=e.charAt(ke),j.test(r)?ke++:(r=i,0===Te&&_e(ve)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}())===i&&(t=function(){var t,n,r;t=ke,67===e.charCodeAt(ke)?(n=P,ke++):(n=i,0===Te&&_e(we));n!==i?(r=e.charAt(ke),U.test(r)?ke++:(r=i,0===Te&&_e(xe)),r===i&&(r=null),t=n=[n,r]):(ke=t,t=i);return t}()),t}if(n=h(),t.peg$library)return{peg$result:n,peg$currPos:ke,peg$FAILED:i,peg$maxFailExpected:Se,peg$maxFailPos:Ne};if(n!==i&&ke===e.length)return n;throw n!==i&&ke<e.length&&_e({type:"end"}),r=Se,s=Ne<e.length?e.charAt(Ne):null,o=Ne<e.length?Pe(Ne,Ne+1):Pe(Ne,Ne),new ne(ne.buildMessage(r,s),r,s,o)}};var oe=function(e){try{se.parse(e,{})}catch(e){if(e instanceof se.SyntaxError)return!1;throw e}return!0};class ie{argTypes=[g.ValueType,g.ValueType];returnType=g.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.iRegexpCheck=e.iRegexpCheck??!0,this.#t=new ee(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}if(!p(t)){if(this.throwErrors)throw new 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)}expectPeekNot(e,t){const n=this.peek;if(n.kind===e)throw new a(t,n)}}const pe=/[eE][+-]?\d+/y,fe=/[a-z][a-z_0-9]*/y,de=/-?\d+/y,ge=/-?[0-9]+/y,me=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ve=new Set([" ","\n","\t","\r"]),we=/[\u0080-\uFFFFa-zA-Z_]/;class xe{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e,t){this.environment=e,this.path=t}get pos(){return this.#n}get start(){return this.#r}run(){let e=ye;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 xe(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 ye(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(he.ROOT),ke)}function ke(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),Oe):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 Oe(e){if(e.acceptMatchRun(me))return e.emit(he.NAME),ke;if(!e.environment.strict){if("~"===e.environment.keysPattern.source&&"~"===e.peek())return e.next(),e.peekMatch(we)?(e.ignore(),e.acceptMatchRun(me),e.emit(he.KEY),ke):(e.emit(he.KEYS),ke);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),ke}const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(he.WILD),ke;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),ke):(e.emit(he.KEYS),ke);if(e.acceptMatchRun(e.environment.keysPattern))return e.emit(he.KEYS),ke}if(e.acceptMatchRun(me))return e.emit(he.NAME),ke;const t=e.next();return"*"===t?(e.emit(he.WILD),ke):(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(),Ae(e);case'"':return e.ignore(),e.next(),Ie(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:ke;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 Pe;case'"':return _e;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),ke;case"@":return e.emit(he.CURRENT),ke;case"#":return e.emit(he.CURRENT_KEY),ke;case".":return e.backup(),ke;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),Pe=Re("'",Te,he.SINGLE_QUOTE_STRING),_e=Re('"',Te,he.DOUBLE_QUOTE_STRING),Ae=Re("'",Se,he.KEY_SINGLE_QUOTE_STRING),Ie=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)&&P(n.value,this.name)&&t.push(new A(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)!u(t.value)&&P(t.value,this.name)&&(yield new A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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 A(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=De(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 A(e.value[n],e.location.concat(n),e.root));else if(l(e.value))for(const[n,r]of this.environment.entries(e.value))t.push(new A(r,e.location.concat(n),e.root));return t}}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 A(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 A(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 A(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 A(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 De(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 Je=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 A(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new I(t)}lazyQuery(e){let t=[new A(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)&&P(n.value,this.key)&&t.push(new A(this.key,n.location.concat(`${_}${this.key}`),n.root));return t}*lazyResolve(e){for(const t of e)t.value instanceof String||u(t.value)||l(t.value)&&P(t.value,this.key)&&(yield new A(this.key,t.location.concat(`${_}${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 A(e,n.location.concat(`${_}${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 A(e,t.location.concat(`${_}${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 A(e,n.location.concat(`${_}${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 A(e,t.location.concat(`${_}${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),!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),!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.expectPeekNot(he.RBRACKET,"unexpected trailing comma")),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 D(n,r)):new Ue(this.environment,n,new D(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){const t=e.current.value;if(t.startsWith("0")&&t.length>1)throw new a(`invalid number literal '${t}'`,e.current);const n=Number(e.current.value);if(isNaN(n))throw new a(`invalid number literal '${t}'`,e.current);return new j(e.current,n)}parsePrefixExpression(e){return e.expect(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){return this.unescapeString(e.kind===he.SINGLE_QUOTE_STRING?e.value.replaceAll('"','\\"').replaceAll("\\'","'"):e.value,e)}unescapeString(e,t){const n=[],r=e.length;let s,o=0;for(;o<r;){const r=e[o];if("\\"===r)switch(o+=1,e[o]){case'"':n.push('"');break;case"\\":n.push("\\");break;case"/":n.push("/");break;case"b":n.push("\b");break;case"f":n.push("\f");break;case"n":n.push("\n");break;case"r":n.push("\r");break;case"t":n.push("\t");break;case"u":[s,o]=this.decodeHexChar(e,o,t),n.push(this.stringFromCodePoint(s,t));break;default:throw new a("unknown escape sequence at index "+(t.index+o-1),t)}else this.stringFromCodePoint(r.codePointAt(0),t),n.push(r);o+=1}return n.join("")}decodeHexChar(e,t,n){const r=e.length;if(t+4>=r)throw new a("incomplete escape sequence at index "+(n.index+t-1),n);t+=1;let s=this.parseHexDigits(e.slice(t,t+4),n);if(He(s))throw new a("unexpected low surrogate codepoint at index "+(n.index+t-2),n);if(function(e){return e>=55296&&e<=56319}(s)){if(!(t+9<r&&"\\"===e[t+4]&&"u"===e[t+5]))throw new a("incomplete escape sequence at index "+(n.index+t-2),n);const o=this.parseHexDigits(e.slice(t+6,t+10),n);if(!He(o))throw new a(`unexpected codepoint at index ${n.index+t+4}`,n);return s=65536+((1023&s)<<10|1023&o),[s,t+9]}return[s,t+3]}parseHexDigits(e,t){const n=new TextEncoder;let r=0;for(const s of n.encode(e))switch(r<<=4,s){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:r|=s-48;break;case 97:case 98:case 99:case 100:case 101:case 102:r|=s-97+10;break;case 65:case 66:case 67:case 68:case 69:case 70:r|=s-65+10;break;default:throw new a("invalid \\uXXXX escape sequence",t)}return r}stringFromCodePoint(e,t){if(void 0===e||e<=31)throw new a("invalid character",t);try{return String.fromCodePoint(e)}catch{throw new a("invalid escape sequence",t)}}throwForNonComparable(e){if((e instanceof Q||e instanceof G)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof V){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==g.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}throwForLiteral(e){if(e instanceof C)throw new a(`filter expression literals (${e.toString()}) must be compared`,e.token)}}function He(e){return e>=56320&&e<=57343}class et{functionRegister=new Map;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.strict=e.strict??!0,this.maxIntIndex=e.maxIntIndex??Math.pow(2,53)-1,this.minIntIndex=e.maxIntIndex??1-Math.pow(2,53),this.maxRecursionDepth=e.maxRecursionDepth??50,this.nondeterministic=e.nondeterministic??!1,this.keysPattern=e.keysPattern??/~/y,this.parser=new 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 J&&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 J||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case g.NodesType:if(!(o instanceof J||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 tt=Object.freeze({__proto__:null,Count:Z,FunctionExpressionType:g,Length:H,Match:ie,Search:ae,Value:ce});const nt=new et;function rt(e,t){return nt.query(e,t)}function st(e,t){return nt.lazyQuery(e,t)}function ot(e){return nt.compile(e)}var it=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:nt,FunctionExpressionType:g,JSONPath:Ge,JSONPathEnvironment:et,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:A,JSONPathNodeList:I,JSONPathRecursionLimitError:c,JSONPathSyntaxError:a,JSONPathTypeError:s,KEY_MARK:_,Nothing:b,Token:ue,TokenKind:he,compile:ot,expressions:X,functions:tt,lazyQuery:st,match:function(e,t){return nt.match(e,t)},query:rt,selectors:Je});class at extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class ct extends at{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class ht{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new at(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n))if(r===k){if("-"!==s)throw new at(`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 at(`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 ut{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)throw new at(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new at(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===k)throw new at(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!l(n))throw new at(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new at(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class lt{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===k)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new at(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(n)){if(r===k)throw new at(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!l(n))throw new at(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===k)throw new at(`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 pt{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new at(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new at(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new at(`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===k)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new at(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(o))o.splice(Number(a),0,r);else{if(!l(o))throw new at(`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 ft{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===k)throw new at(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===k)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new at(`unexpected operation on 'undefined' (${this.name}:${t})`);if(u(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!l(s))throw new at(`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 dt{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 ct(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class gt{ops=[];constructor(e){e&&this.build(e)}*[Symbol.iterator](){for(const e of this.ops)yield e.toObject()}add(e,t){return this.ops.push(new ht(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new ut(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new lt(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new pt(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new ft(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new dt(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 at(`${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 at(`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 at(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!p(s))throw new at(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new O(s)}catch(e){if(e instanceof m)throw new at(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new at(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof O)return e;if(!p(e))throw new at(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new O(e)}catch(e){if(e instanceof m)throw new at(`${e.message} (${t}:${n})`);throw e}}}function mt(e,t){return new gt(e).apply(t)}var vt=Object.freeze({__proto__:null,JSONPatch:gt,JSONPatchError:at,JSONPatchTestFailure:ct,apply:mt});return e.DEFAULT_ENVIRONMENT=nt,e.FunctionExpressionType=g,e.JSONPatch=gt,e.JSONPatchError=at,e.JSONPatchTestFailure=ct,e.JSONPath=Ge,e.JSONPathEnvironment=et,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=A,e.JSONPathNodeList=I,e.JSONPathRecursionLimitError=c,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=O,e.Nothing=b,e.RelativeJSONPointer=T,e.Token=ue,e.TokenKind=he,e.UNDEFINED=k,e.apply=mt,e.compile=ot,e.jsonpatch=vt,e.jsonpath=it,e.jsonpointer=$,e.lazyQuery=st,e.query=rt,e.resolve=R,e.version="1.3.4",e}({});
2
2
  //# sourceMappingURL=json-p3.iife.min.js.map