json-p3 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENCE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 James Prior
3
+ Copyright (c) 2024 James Prior
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -61,6 +61,15 @@ JSON P3 has zero runtime dependencies.
61
61
  | `json-p3-iife.js` | A bundle formatted as an Immediately Invoked Function Expression. |
62
62
  | `json-p3-iife.min.js` | A minified bundle formatted as an Immediately Invoked Function Expression. |
63
63
 
64
+ ## Compliance Environment Variables
65
+
66
+ These environment variables control the location of the compliance test suite under test and if nondeterministic object iteration is enabled for those tests.
67
+
68
+ | Environment Variable | Description |
69
+ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------- |
70
+ | `JSONP3_CTS_PATH` | The path to `cts.json` used by `compliance.test.ts`. Defaults to `tests/path/cts/cts.json`. |
71
+ | `JSONP3_CTS_NONDETERMINISTIC` | When set to `true`, enables nondeterministic iteration of JSON objects for `compliance.test.ts`. Defaults to `false`. |
72
+
64
73
  ## Contributing
65
74
 
66
75
  Please see [Contributing to JSON P3](https://github.com/jg-rp/json-p3/blob/main/CONTRIBUTING.md)
@@ -1,10 +1,10 @@
1
1
  /*
2
- * json-p3 version 1.0.0
2
+ * json-p3 version 1.1.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
6
6
  *
7
- * Copyright (c) 2023 James Prior
7
+ * Copyright (c) 2024 James Prior
8
8
  *
9
9
  * Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
  * of this software and associated documentation files (the "Software"), to deal
@@ -1927,7 +1927,7 @@ class WildcardSelector extends JSONPathSelector {
1927
1927
  rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
1928
1928
  }
1929
1929
  } else if (isObject(node.value)) {
1930
- for (const [key, value] of Object.entries(node.value)) {
1930
+ for (const [key, value] of this.environment.entries(node.value)) {
1931
1931
  rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
1932
1932
  }
1933
1933
  }
@@ -1942,7 +1942,7 @@ class WildcardSelector extends JSONPathSelector {
1942
1942
  yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
1943
1943
  }
1944
1944
  } else if (isObject(node.value)) {
1945
- for (const [key, value] of Object.entries(node.value)) {
1945
+ for (const [key, value] of this.environment.entries(node.value)) {
1946
1946
  yield new JSONPathNode(value, node.location.concat(key), node.root);
1947
1947
  }
1948
1948
  }
@@ -2002,7 +2002,7 @@ class RecursiveDescentSegment extends JSONPathSelector {
2002
2002
  }
2003
2003
  }
2004
2004
  } else if (isObject(currentNode.value)) {
2005
- for (const [key, value] of Object.entries(currentNode.value)) {
2005
+ for (const [key, value] of this.environment.entries(currentNode.value)) {
2006
2006
  const __node = new JSONPathNode(value, currentNode.location.concat(key), currentNode.root);
2007
2007
  yield __node;
2008
2008
  if (isObject(__node.value)) {
@@ -2035,7 +2035,7 @@ class RecursiveDescentSegment extends JSONPathSelector {
2035
2035
  }
2036
2036
  }
2037
2037
  } else if (isObject(node.value)) {
2038
- for (const [key, value] of Object.entries(node.value)) {
2038
+ for (const [key, value] of this.environment.entries(node.value)) {
2039
2039
  const _node = new JSONPathNode(value, node.location.concat(key), node.root);
2040
2040
  rv.push(_node);
2041
2041
  for (const __node of this.visit(_node, depth + 1)) {
@@ -2072,7 +2072,7 @@ class FilterSelector extends JSONPathSelector {
2072
2072
  }
2073
2073
  }
2074
2074
  } else if (isObject(node.value)) {
2075
- for (const [key, value] of Object.entries(node.value)) {
2075
+ for (const [key, value] of this.environment.entries(node.value)) {
2076
2076
  const filterContext = {
2077
2077
  environment: this.environment,
2078
2078
  currentValue: value,
@@ -2105,7 +2105,7 @@ class FilterSelector extends JSONPathSelector {
2105
2105
  }
2106
2106
  }
2107
2107
  } else if (isObject(node.value)) {
2108
- for (const [key, value] of Object.entries(node.value)) {
2108
+ for (const [key, value] of this.environment.entries(node.value)) {
2109
2109
  const filterContext = {
2110
2110
  environment: this.environment,
2111
2111
  currentValue: value,
@@ -2237,8 +2237,8 @@ class JSONPath {
2237
2237
  }
2238
2238
 
2239
2239
  const PRECEDENCE_LOWEST = 1;
2240
- const PRECEDENCE_LOGICAL_AND = 4;
2241
- const PRECEDENCE_LOGICAL_OR = 5;
2240
+ const PRECEDENCE_LOGICAL_OR = 4;
2241
+ const PRECEDENCE_LOGICAL_AND = 5;
2242
2242
  const PRECEDENCE_COMPARISON = 6;
2243
2243
  const PRECEDENCE_PREFIX = 7;
2244
2244
  const PRECEDENCES = new Map([[TokenKind.AND, PRECEDENCE_LOGICAL_AND], [TokenKind.EQ, PRECEDENCE_COMPARISON], [TokenKind.GE, PRECEDENCE_COMPARISON], [TokenKind.GT, PRECEDENCE_COMPARISON], [TokenKind.LE, PRECEDENCE_COMPARISON], [TokenKind.LT, PRECEDENCE_COMPARISON], [TokenKind.NE, PRECEDENCE_COMPARISON], [TokenKind.NOT, PRECEDENCE_PREFIX], [TokenKind.OR, PRECEDENCE_LOGICAL_OR], [TokenKind.RPAREN, PRECEDENCE_LOWEST]]);
@@ -2568,6 +2568,10 @@ class JSONPathEnvironment {
2568
2568
  * can visit before a `JSONPathRecursionLimitError` is thrown.
2569
2569
  */
2570
2570
 
2571
+ /**
2572
+ * If `true`, enable nondeterministic ordering when iterating JSON object data.
2573
+ */
2574
+
2571
2575
  /**
2572
2576
  * A map of function names to objects implementing the {@link FilterFunction}
2573
2577
  * interface. You are free to set or delete custom filter functions directly.
@@ -2582,6 +2586,7 @@ class JSONPathEnvironment {
2582
2586
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
2583
2587
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) - 1;
2584
2588
  this.maxRecursionDepth = options.maxRecursionDepth ?? 50;
2589
+ this.nondeterministic = options.nondeterministic ?? false;
2585
2590
  this.parser = new Parser(this);
2586
2591
  this.setupFilterFunctions();
2587
2592
  }
@@ -2690,6 +2695,29 @@ class JSONPathEnvironment {
2690
2695
  }
2691
2696
  return args;
2692
2697
  }
2698
+
2699
+ /**
2700
+ * Return an array of key/values of the enumerable properties in _obj_.
2701
+ *
2702
+ * If you want to introduce some nondeterminism to iterating JSON-like
2703
+ * objects, do it here. The wildcard selector, descendent segment and
2704
+ * filter selector all use `this.environment.entries`.
2705
+ *
2706
+ * @param obj - A JSON-like object.
2707
+ */
2708
+ entries(obj) {
2709
+ function shuffle(entries) {
2710
+ for (let i = entries.length - 1; i > 0; i--) {
2711
+ const j = Math.floor(Math.random() * (i + 1));
2712
+ [entries[i], entries[j]] = [entries[j], entries[i]];
2713
+ }
2714
+ return entries;
2715
+ }
2716
+ if (this.nondeterministic) {
2717
+ return shuffle(Object.entries(obj));
2718
+ }
2719
+ return Object.entries(obj);
2720
+ }
2693
2721
  }
2694
2722
 
2695
2723
  var index$2 = /*#__PURE__*/Object.freeze({
@@ -3278,7 +3306,7 @@ var index = /*#__PURE__*/Object.freeze({
3278
3306
  apply: apply
3279
3307
  });
3280
3308
 
3281
- const version = "1.0.0";
3309
+ const version = "1.1.0";
3282
3310
 
3283
3311
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
3284
3312
  exports.FunctionExpressionType = FunctionExpressionType;
@@ -1,10 +1,10 @@
1
1
  /*
2
- * json-p3 version 1.0.0
2
+ * json-p3 version 1.1.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
6
6
  *
7
- * Copyright (c) 2023 James Prior
7
+ * Copyright (c) 2024 James Prior
8
8
  *
9
9
  * Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
  * of this software and associated documentation files (the "Software"), to deal
@@ -1925,7 +1925,7 @@ class WildcardSelector extends JSONPathSelector {
1925
1925
  rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
1926
1926
  }
1927
1927
  } else if (isObject(node.value)) {
1928
- for (const [key, value] of Object.entries(node.value)) {
1928
+ for (const [key, value] of this.environment.entries(node.value)) {
1929
1929
  rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
1930
1930
  }
1931
1931
  }
@@ -1940,7 +1940,7 @@ class WildcardSelector extends JSONPathSelector {
1940
1940
  yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
1941
1941
  }
1942
1942
  } else if (isObject(node.value)) {
1943
- for (const [key, value] of Object.entries(node.value)) {
1943
+ for (const [key, value] of this.environment.entries(node.value)) {
1944
1944
  yield new JSONPathNode(value, node.location.concat(key), node.root);
1945
1945
  }
1946
1946
  }
@@ -2000,7 +2000,7 @@ class RecursiveDescentSegment extends JSONPathSelector {
2000
2000
  }
2001
2001
  }
2002
2002
  } else if (isObject(currentNode.value)) {
2003
- for (const [key, value] of Object.entries(currentNode.value)) {
2003
+ for (const [key, value] of this.environment.entries(currentNode.value)) {
2004
2004
  const __node = new JSONPathNode(value, currentNode.location.concat(key), currentNode.root);
2005
2005
  yield __node;
2006
2006
  if (isObject(__node.value)) {
@@ -2033,7 +2033,7 @@ class RecursiveDescentSegment extends JSONPathSelector {
2033
2033
  }
2034
2034
  }
2035
2035
  } else if (isObject(node.value)) {
2036
- for (const [key, value] of Object.entries(node.value)) {
2036
+ for (const [key, value] of this.environment.entries(node.value)) {
2037
2037
  const _node = new JSONPathNode(value, node.location.concat(key), node.root);
2038
2038
  rv.push(_node);
2039
2039
  for (const __node of this.visit(_node, depth + 1)) {
@@ -2070,7 +2070,7 @@ class FilterSelector extends JSONPathSelector {
2070
2070
  }
2071
2071
  }
2072
2072
  } else if (isObject(node.value)) {
2073
- for (const [key, value] of Object.entries(node.value)) {
2073
+ for (const [key, value] of this.environment.entries(node.value)) {
2074
2074
  const filterContext = {
2075
2075
  environment: this.environment,
2076
2076
  currentValue: value,
@@ -2103,7 +2103,7 @@ class FilterSelector extends JSONPathSelector {
2103
2103
  }
2104
2104
  }
2105
2105
  } else if (isObject(node.value)) {
2106
- for (const [key, value] of Object.entries(node.value)) {
2106
+ for (const [key, value] of this.environment.entries(node.value)) {
2107
2107
  const filterContext = {
2108
2108
  environment: this.environment,
2109
2109
  currentValue: value,
@@ -2235,8 +2235,8 @@ class JSONPath {
2235
2235
  }
2236
2236
 
2237
2237
  const PRECEDENCE_LOWEST = 1;
2238
- const PRECEDENCE_LOGICAL_AND = 4;
2239
- const PRECEDENCE_LOGICAL_OR = 5;
2238
+ const PRECEDENCE_LOGICAL_OR = 4;
2239
+ const PRECEDENCE_LOGICAL_AND = 5;
2240
2240
  const PRECEDENCE_COMPARISON = 6;
2241
2241
  const PRECEDENCE_PREFIX = 7;
2242
2242
  const PRECEDENCES = new Map([[TokenKind.AND, PRECEDENCE_LOGICAL_AND], [TokenKind.EQ, PRECEDENCE_COMPARISON], [TokenKind.GE, PRECEDENCE_COMPARISON], [TokenKind.GT, PRECEDENCE_COMPARISON], [TokenKind.LE, PRECEDENCE_COMPARISON], [TokenKind.LT, PRECEDENCE_COMPARISON], [TokenKind.NE, PRECEDENCE_COMPARISON], [TokenKind.NOT, PRECEDENCE_PREFIX], [TokenKind.OR, PRECEDENCE_LOGICAL_OR], [TokenKind.RPAREN, PRECEDENCE_LOWEST]]);
@@ -2566,6 +2566,10 @@ class JSONPathEnvironment {
2566
2566
  * can visit before a `JSONPathRecursionLimitError` is thrown.
2567
2567
  */
2568
2568
 
2569
+ /**
2570
+ * If `true`, enable nondeterministic ordering when iterating JSON object data.
2571
+ */
2572
+
2569
2573
  /**
2570
2574
  * A map of function names to objects implementing the {@link FilterFunction}
2571
2575
  * interface. You are free to set or delete custom filter functions directly.
@@ -2580,6 +2584,7 @@ class JSONPathEnvironment {
2580
2584
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
2581
2585
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) - 1;
2582
2586
  this.maxRecursionDepth = options.maxRecursionDepth ?? 50;
2587
+ this.nondeterministic = options.nondeterministic ?? false;
2583
2588
  this.parser = new Parser(this);
2584
2589
  this.setupFilterFunctions();
2585
2590
  }
@@ -2688,6 +2693,29 @@ class JSONPathEnvironment {
2688
2693
  }
2689
2694
  return args;
2690
2695
  }
2696
+
2697
+ /**
2698
+ * Return an array of key/values of the enumerable properties in _obj_.
2699
+ *
2700
+ * If you want to introduce some nondeterminism to iterating JSON-like
2701
+ * objects, do it here. The wildcard selector, descendent segment and
2702
+ * filter selector all use `this.environment.entries`.
2703
+ *
2704
+ * @param obj - A JSON-like object.
2705
+ */
2706
+ entries(obj) {
2707
+ function shuffle(entries) {
2708
+ for (let i = entries.length - 1; i > 0; i--) {
2709
+ const j = Math.floor(Math.random() * (i + 1));
2710
+ [entries[i], entries[j]] = [entries[j], entries[i]];
2711
+ }
2712
+ return entries;
2713
+ }
2714
+ if (this.nondeterministic) {
2715
+ return shuffle(Object.entries(obj));
2716
+ }
2717
+ return Object.entries(obj);
2718
+ }
2691
2719
  }
2692
2720
 
2693
2721
  var index$2 = /*#__PURE__*/Object.freeze({
@@ -3276,6 +3304,6 @@ var index = /*#__PURE__*/Object.freeze({
3276
3304
  apply: apply
3277
3305
  });
3278
3306
 
3279
- const version = "1.0.0";
3307
+ const version = "1.1.0";
3280
3308
 
3281
3309
  export { DEFAULT_ENVIRONMENT, FunctionExpressionType, JSONPatch, JSONPatchError, JSONPatchTestFailure, JSONPath, JSONPathEnvironment, JSONPathError, JSONPathIndexError, JSONPathLexerError, JSONPathNode, JSONPathNodeList, JSONPathRecursionLimitError, JSONPathSyntaxError, JSONPathTypeError, JSONPointer, Nothing, RelativeJSONPointer, Token, TokenKind, UNDEFINED, apply, compile, index as jsonpatch, index$1 as jsonpath, index$3 as jsonpointer, lazyQuery, query, resolve, version };
@@ -1,10 +1,10 @@
1
1
  /*
2
- * json-p3 version 1.0.0
2
+ * json-p3 version 1.1.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
6
6
  *
7
- * Copyright (c) 2023 James Prior
7
+ * Copyright (c) 2024 James Prior
8
8
  *
9
9
  * Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
  * of this software and associated documentation files (the "Software"), to deal
@@ -1928,7 +1928,7 @@ var json_p3 = (function (exports) {
1928
1928
  rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
1929
1929
  }
1930
1930
  } else if (isObject(node.value)) {
1931
- for (const [key, value] of Object.entries(node.value)) {
1931
+ for (const [key, value] of this.environment.entries(node.value)) {
1932
1932
  rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
1933
1933
  }
1934
1934
  }
@@ -1943,7 +1943,7 @@ var json_p3 = (function (exports) {
1943
1943
  yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
1944
1944
  }
1945
1945
  } else if (isObject(node.value)) {
1946
- for (const [key, value] of Object.entries(node.value)) {
1946
+ for (const [key, value] of this.environment.entries(node.value)) {
1947
1947
  yield new JSONPathNode(value, node.location.concat(key), node.root);
1948
1948
  }
1949
1949
  }
@@ -2003,7 +2003,7 @@ var json_p3 = (function (exports) {
2003
2003
  }
2004
2004
  }
2005
2005
  } else if (isObject(currentNode.value)) {
2006
- for (const [key, value] of Object.entries(currentNode.value)) {
2006
+ for (const [key, value] of this.environment.entries(currentNode.value)) {
2007
2007
  const __node = new JSONPathNode(value, currentNode.location.concat(key), currentNode.root);
2008
2008
  yield __node;
2009
2009
  if (isObject(__node.value)) {
@@ -2036,7 +2036,7 @@ var json_p3 = (function (exports) {
2036
2036
  }
2037
2037
  }
2038
2038
  } else if (isObject(node.value)) {
2039
- for (const [key, value] of Object.entries(node.value)) {
2039
+ for (const [key, value] of this.environment.entries(node.value)) {
2040
2040
  const _node = new JSONPathNode(value, node.location.concat(key), node.root);
2041
2041
  rv.push(_node);
2042
2042
  for (const __node of this.visit(_node, depth + 1)) {
@@ -2073,7 +2073,7 @@ var json_p3 = (function (exports) {
2073
2073
  }
2074
2074
  }
2075
2075
  } else if (isObject(node.value)) {
2076
- for (const [key, value] of Object.entries(node.value)) {
2076
+ for (const [key, value] of this.environment.entries(node.value)) {
2077
2077
  const filterContext = {
2078
2078
  environment: this.environment,
2079
2079
  currentValue: value,
@@ -2106,7 +2106,7 @@ var json_p3 = (function (exports) {
2106
2106
  }
2107
2107
  }
2108
2108
  } else if (isObject(node.value)) {
2109
- for (const [key, value] of Object.entries(node.value)) {
2109
+ for (const [key, value] of this.environment.entries(node.value)) {
2110
2110
  const filterContext = {
2111
2111
  environment: this.environment,
2112
2112
  currentValue: value,
@@ -2238,8 +2238,8 @@ var json_p3 = (function (exports) {
2238
2238
  }
2239
2239
 
2240
2240
  const PRECEDENCE_LOWEST = 1;
2241
- const PRECEDENCE_LOGICAL_AND = 4;
2242
- const PRECEDENCE_LOGICAL_OR = 5;
2241
+ const PRECEDENCE_LOGICAL_OR = 4;
2242
+ const PRECEDENCE_LOGICAL_AND = 5;
2243
2243
  const PRECEDENCE_COMPARISON = 6;
2244
2244
  const PRECEDENCE_PREFIX = 7;
2245
2245
  const PRECEDENCES = new Map([[TokenKind.AND, PRECEDENCE_LOGICAL_AND], [TokenKind.EQ, PRECEDENCE_COMPARISON], [TokenKind.GE, PRECEDENCE_COMPARISON], [TokenKind.GT, PRECEDENCE_COMPARISON], [TokenKind.LE, PRECEDENCE_COMPARISON], [TokenKind.LT, PRECEDENCE_COMPARISON], [TokenKind.NE, PRECEDENCE_COMPARISON], [TokenKind.NOT, PRECEDENCE_PREFIX], [TokenKind.OR, PRECEDENCE_LOGICAL_OR], [TokenKind.RPAREN, PRECEDENCE_LOWEST]]);
@@ -2569,6 +2569,10 @@ var json_p3 = (function (exports) {
2569
2569
  * can visit before a `JSONPathRecursionLimitError` is thrown.
2570
2570
  */
2571
2571
 
2572
+ /**
2573
+ * If `true`, enable nondeterministic ordering when iterating JSON object data.
2574
+ */
2575
+
2572
2576
  /**
2573
2577
  * A map of function names to objects implementing the {@link FilterFunction}
2574
2578
  * interface. You are free to set or delete custom filter functions directly.
@@ -2583,6 +2587,7 @@ var json_p3 = (function (exports) {
2583
2587
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
2584
2588
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) - 1;
2585
2589
  this.maxRecursionDepth = options.maxRecursionDepth ?? 50;
2590
+ this.nondeterministic = options.nondeterministic ?? false;
2586
2591
  this.parser = new Parser(this);
2587
2592
  this.setupFilterFunctions();
2588
2593
  }
@@ -2691,6 +2696,29 @@ var json_p3 = (function (exports) {
2691
2696
  }
2692
2697
  return args;
2693
2698
  }
2699
+
2700
+ /**
2701
+ * Return an array of key/values of the enumerable properties in _obj_.
2702
+ *
2703
+ * If you want to introduce some nondeterminism to iterating JSON-like
2704
+ * objects, do it here. The wildcard selector, descendent segment and
2705
+ * filter selector all use `this.environment.entries`.
2706
+ *
2707
+ * @param obj - A JSON-like object.
2708
+ */
2709
+ entries(obj) {
2710
+ function shuffle(entries) {
2711
+ for (let i = entries.length - 1; i > 0; i--) {
2712
+ const j = Math.floor(Math.random() * (i + 1));
2713
+ [entries[i], entries[j]] = [entries[j], entries[i]];
2714
+ }
2715
+ return entries;
2716
+ }
2717
+ if (this.nondeterministic) {
2718
+ return shuffle(Object.entries(obj));
2719
+ }
2720
+ return Object.entries(obj);
2721
+ }
2694
2722
  }
2695
2723
 
2696
2724
  var index$2 = /*#__PURE__*/Object.freeze({
@@ -3279,7 +3307,7 @@ var json_p3 = (function (exports) {
3279
3307
  apply: apply
3280
3308
  });
3281
3309
 
3282
- const version = "1.0.0";
3310
+ const version = "1.1.0";
3283
3311
 
3284
3312
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
3285
3313
  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 h extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}function c(e){return Array.isArray(e)}function u(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function l(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!f(e[n],t[n]))return!1;return!0}return!1}if(u(e)&&u(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!f(e[r],t[r]))return!1;return!0}return!1}let d=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class g extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class m extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class O extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class y extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=Symbol.for("jsonpointer.undefined");class N{#e;constructor(e){this.tokens=this.parse(e),this.#e=N.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof m&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof v||e instanceof w)return[t,x];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every(((t,n)=>t===e.tokens[n]))}parse(e){if(e.length&&!e.startsWith("/"))throw new O(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(c(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(k.test(r)&&Object.hasOwn(e,r))return Number(r);throw new v(`index out of range '${N.encode(this.tokens.slice(0,n+1))}'`)}throw new v(`index out of range '${N.encode(this.tokens.slice(0,n+1))}'`)}if(u(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new w(`no such property '${N.encode(this.tokens.slice(0,n+1))}'`)}throw new y(`found primitive value, expected an object '${N.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!l(e))throw new y("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new N(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new N(N.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 m)return!1;throw e}return!0}parent(){return this.tokens.length?new N(N.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(l(e)?new S(e):e).to(this)}}const E=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,k=/(0|[1-9][0-9]*)/;class S{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=l(e)?new N(e):e;if(this.origin>t.tokens.length)throw new v(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new v(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof N?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new N(N.encode(n))}parse(e){const t=E.exec(e);if(!t||!t.groups)throw new O("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 O("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new N(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new O("unexpected leading zero");if(k.test(e))return Number(e);throw new O(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!p(e))||k.test(e)}}function T(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new N(e).resolve(t,n)}var R=Object.freeze({__proto__:null,JSONPointer:N,JSONPointerError:g,JSONPointerIndexError:v,JSONPointerKeyError:w,JSONPointerResolutionError:m,JSONPointerSyntaxError:O,JSONPointerTypeError:y,RelativeJSONPointer:S,UNDEFINED:x,resolve:T});class ${constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>l(e)?`['${e}']`:`[${e}]`)).join("")}toPointer(){return this.location.length?new N(N.encode(this.location.map(String))):new N("")}}class b{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}}const P=Symbol.for("jsonpath.nothing");function I(e,t){return u(e)&&Object.hasOwn(e,t)}class _{constructor(e){this.token=e}}class L extends _{}class A extends L{evaluate(){return null}toString(){return"null"}}class j extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class F extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class J extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class z extends _{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 b?0===t.nodes.length:!Q(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class M extends _{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r}evaluate(e){let t=this.left.evaluate(e);t instanceof b&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return n instanceof b&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?Q(t)&&Q(n):"||"===this.operator?Q(t)||Q(n):W(t,this.operator,n)}toString(){return"&&"===this.operator||"||"===this.operator?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class D extends _{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof b?t.nodes.length>0:Q(t)}toString(){return this.expression.toString()}}class K extends _{constructor(e,t){super(e),this.token=e,this.path=t}}class C extends K{evaluate(e){return e.lazy?new b(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class U extends K{evaluate(e){return e.lazy?new b(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class G extends _{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==d.NodesType&&e instanceof b?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 P;case 1:return e.nodes[0].value;default:return e}}}function Q(e){return!(e instanceof b&&e.empty())&&!("boolean"==typeof e&&!1===e)}function W(e,t,n){switch(t){case"==":return V(e,n);case"!=":return!V(e,n);case"<":return B(e,n);case">":return B(n,e);case">=":return B(n,e)||V(e,n);case"<=":return B(e,n)||V(e,n);default:return!1}}function V(e,t){if(t instanceof b&&([e,t]=[t,e]),e instanceof b){if(t instanceof b){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return f(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===P:1===e.nodes.length&&f(e.nodes[0].value,t)}return e===P&&t===P||f(e,t)}function B(e,t){return!!(l(e)&&l(t)||p(e)&&p(t))&&e<t}var q=Object.freeze({__proto__:null,BooleanLiteral:j,FilterExpression:_,FilterExpressionLiteral:L,FunctionExtension:G,InfixExpression:M,JSONPathQuery:K,LogicalExpression:D,NullLiteral:A,NumberLiteral:J,PrefixExpression:z,RelativeQuery:C,RootQuery:U,StringLiteral:F,compare:W});class X{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return e.length}}class Z{argTypes=[d.ValueType];returnType=d.ValueType;call(e){return c(e)||l(e)?e.length:u(e)?Object.keys(e).length:P}}class H extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}class Y{argTypes=[d.ValueType,d.ValueType];returnType=d.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.#t=new H(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[];return e.startsWith("^")||t.push("^"),t.push(e),e.endsWith("$")||t.push("$"),t.join("")}}class ee{argTypes=[d.ValueType,d.ValueType];returnType=d.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.#t=new H(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}try{const n=new RegExp(t,"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class te{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return 1===e.length?e.nodes[0].value:P}}let ne=function(e){return e.AND="TOKEN_AND",e.COLON="TOKEN_COLON",e.COMMA="TOKEN_COMMA",e.CURRENT="TOKEN_CURRENT_NODE",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.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 re{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new re(ne.EOF,"",-1,"");class se{#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 oe=/e[+-]?\d+/y,ie=/[a-z][a-z_0-9]*/y,ae=/-?\d+/y,he=/-?[0-9]+/y,ce=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ue=new Set([" ","\n","\t","\r"]);class le{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e){this.path=e}get pos(){return this.#n}get start(){return this.#r}run(){let e=fe;for(;e;)e=e(this)}emit(e){this.tokens.push(new re(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 re(ne.ERROR,e,this.#n,this.path))}this.#n-=1}peek(){const e=this.next();return e&&this.backup(),e}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 re(ne.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ue)&&(this.ignore(),!0)}error(e){this.tokens.push(new re(ne.ERROR,e,this.#n,this.path))}}function pe(e){const[t,n]=function(e){const t=new le(e);return[t,t.tokens]}(e);if(t.run(),n.length&&n[n.length-1].kind===ne.ERROR)throw new a(n[n.length-1].value,n[n.length-1]);return n}function fe(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(ne.ROOT),de)}function de(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(ne.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(ne.DDOT),ge):me;case"[":return e.emit(ne.LBRACKET),ve;default:return e.backup(),e.filterLevel?we:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ge(e){const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(ne.WILD),de;case"[":return e.emit(ne.LBRACKET),ve;default:return e.backup(),e.acceptMatchRun(ce)?(e.emit(ne.NAME),de):(e.error(`unexpected descendent selection token '${t}'`),null)}}function me(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;const t=e.next();return"*"===t?(e.emit(ne.WILD),de):(e.backup(),e.acceptMatchRun(ce)?(e.emit(ne.NAME),de):(e.error(`unexpected shorthand selector '${t}'`),null))}function ve(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"]":return e.emit(ne.RBRACKET),e.filterLevel?we:de;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(ne.WILD);continue;case"?":return e.emit(ne.FILTER),e.filterLevel+=1,we;case",":e.emit(ne.COMMA);continue;case":":e.emit(ne.COLON);continue;case"'":return ye;case'"':return xe;default:if(e.backup(),e.acceptMatchRun(ae)){e.emit(ne.INDEX);continue}return e.error(`unexpected token '${t}' in bracketed selection`),null}}}function we(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),ve);case",":if(e.emit(ne.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,ve;case"'":return Ne;case'"':return Ee;case"(":e.emit(ne.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(ne.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(ne.ROOT),de;case"@":return e.emit(ne.CURRENT),de;case".":return e.backup(),de;case"!":"="===e.peek()?(e.next(),e.emit(ne.NE)):e.emit(ne.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(ne.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(ne.LE)):e.emit(ne.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(ne.GE)):e.emit(ne.GT);continue;default:if(e.backup(),e.acceptMatchRun(he)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(he)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(oe),e.emit(ne.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(ne.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(ne.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(ne.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(ne.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(ne.NULL);continue}if(e.acceptMatchRun(ie)&&"("===e.peek()){e.parenStack.push(1),e.emit(ne.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function Oe(e,t){return function(n){if(n.ignore(),n.peek()===e)return n.emit("'"===e?ne.SINGLE_QUOTE_STRING:ne.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t;for(;;){const r=n.path.slice(n.pos,n.pos+2),s=n.next();if("\\\\"!==r&&r!==`\\${e}`){if("\\"===s&&!r.match(/\\[bfnrtu/]/))return n.error("invalid escape"),null;if(!s)return n.error(`unclosed string starting at index ${n.start}`),null;if(s===e)return n.backup(),n.emit("'"===e?ne.SINGLE_QUOTE_STRING:ne.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t}else n.next()}}}const ye=Oe("'",ve),xe=Oe('"',ve),Ne=Oe("'",we),Ee=Oe('"',we);class ke{constructor(e,t){this.environment=e,this.token=t}}class Se extends ke{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)I(n.value,this.name)&&t.push(new $(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)I(t.value,this.name)&&(yield new $(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class Te extends ke{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(c(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new $(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(c(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new $(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 Re extends ke{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];for(const n of e)if(c(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new $(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(c(t.value))for(const[e,n]of this.slice(t.value,this.start,this.stop,this.step))yield new $(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}}class $e extends ke{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++)t.push(new $(n.value[e],n.location.concat(e),n.root));else if(u(n.value))for(const[e,r]of Object.entries(n.value))t.push(new $(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++)yield new $(t.value[e],t.location.concat(e),t.root);else if(u(t.value))for(const[e,n]of Object.entries(t.value))yield new $(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class be extends ke{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];for(const n of e){t.push(n);for(const e of this.visit(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);if(!(t.value instanceof String))if(c(t.value))for(let r=0;r<t.value.length;r++){const s=new $(t.value[r],t.location.concat(r),t.root);yield s,u(s.value)&&e.push({node:s,depth:n+1})}else if(u(t.value))for(const[r,s]of Object.entries(t.value)){const o=new $(s,t.location.concat(r),t.root);yield o,u(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visit(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(c(e.value))for(let r=0;r<e.value.length;r++){const s=new $(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visit(s,t+1))n.push(e)}else if(u(e.value))for(const[r,s]of Object.entries(e.value)){const o=new $(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visit(o,t+1))n.push(e)}return n}}class Pe extends ke{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root};this.expression.evaluate(s)&&t.push(new $(r,n.location.concat(e),n.root))}else if(u(n.value))for(const[e,r]of Object.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root};this.expression.evaluate(s)&&t.push(new $(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0};this.expression.evaluate(r)&&(yield new $(n,t.location.concat(e),t.root))}else if(u(t.value))for(const[e,n]of Object.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0};this.expression.evaluate(r)&&(yield new $(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class Ie extends ke{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(", ")}]`}}var _e=Object.freeze({__proto__:null,BracketedSelection:Ie,FilterSelector:Pe,IndexSelector:Te,JSONPathSelector:ke,NameSelector:Se,RecursiveDescentSegment:be,SliceSelector:Re,WildcardSelector:$e});class Le{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new $(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new b(t)}lazyQuery(e){let t=[new $(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 Se||e instanceof Ie&&1===e.items.length&&(e.items[0]instanceof Se||e.items[0]instanceof Te)))return!1;return!0}}const Ae=new Map([[ne.AND,4],[ne.EQ,6],[ne.GE,6],[ne.GT,6],[ne.LE,6],[ne.LT,6],[ne.NE,6],[ne.NOT,7],[ne.OR,5],[ne.RPAREN,1]]),je=new Map([[ne.AND,"&&"],[ne.EQ,"=="],[ne.GE,">="],[ne.GT,">"],[ne.LE,"<="],[ne.LT,"<"],[ne.NE,"!="],[ne.OR,"||"]]),Fe=new Set(["==",">=",">","<=","<","!="]);class Je{constructor(e){this.environment=e,this.tokenMap=new Map([[ne.FALSE,this.parseBoolean],[ne.NUMBER,this.parseNumber],[ne.LPAREN,this.parseGroupedExpression],[ne.NOT,this.parsePrefixExpression],[ne.NULL,this.parseNull],[ne.ROOT,this.parseRootQuery],[ne.CURRENT,this.parseRelativeQuery],[ne.SINGLE_QUOTE_STRING,this.parseString],[ne.DOUBLE_QUOTE_STRING,this.parseString],[ne.TRUE,this.parseBoolean],[ne.FUNCTION,this.parseFunction]])}parse(e){e.current.kind===ne.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==ne.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 ne.NAME:return new Se(this.environment,e.current,e.current.value,!0);case ne.WILD:return new $e(this.environment,e.current,!0);case ne.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new be(this.environment,t,n)}case ne.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 Te(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===ne.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(ne.COLON),e.next()):(n.push(void 0),e.expect(ne.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===ne.COLON&&e.next()):e.current.kind===ne.COLON&&(n.push(void 0),e.expect(ne.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Re(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==ne.RBRACKET;){switch(e.current.kind){case ne.SINGLE_QUOTE_STRING:case ne.DOUBLE_QUOTE_STRING:n.push(new Se(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case ne.FILTER:n.push(this.parseFilter(e));break;case ne.INDEX:e.peek.kind===ne.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case ne.COLON:n.push(this.parseSlice(e));break;case ne.WILD:n.push(new $e(this.environment,e.current));break;case ne.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!==ne.RBRACKET&&(e.expectPeek(ne.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Ie(this.environment,t,n)}parseFilter(e){const t=e.next(),n=this.parseFilterExpression(e);if(n instanceof G){const e=this.environment.functionRegister.get(n.name);if(e&&e.returnType===d.ValueType)throw new s(`result of ${n.name}() must be compared`,n.token)}return new Pe(this.environment,t,new D(t,n))}parseBoolean(e){return e.current.kind===ne.FALSE?new j(e.current,!1):new j(e.current,!0)}parseNull(e){return new A(e.current)}parseString(e){return new F(e.current,this.decodeString(e.current))}parseNumber(e){return new J(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(ne.NOT),e.next(),new z(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ae.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=je.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Fe.has(o)&&(this.throwForNonComparable(t),this.throwForNonComparable(s)),new M(n,t,o,s)}parseGroupedExpression(e){e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==ne.RPAREN;){if(e.current.kind===ne.EOF)throw new a("unbalanced parentheses",e.current);t=this.parseInfixExpression(e,t)}return e.expect(ne.RPAREN),t}parseRootQuery(e){const t=e.next();return new U(t,new Le(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new C(t,new Le(this.environment,this.parsePath(e,!0)))}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==ne.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(;je.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==ne.RPAREN){if(e.peek.kind===ne.RBRACKET)break;e.expectPeek(ne.COMMA),e.next()}e.next()}return e.expect(ne.RPAREN),new G(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 ne.EOF:case ne.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===ne.EOF||n===ne.RBRACKET||(Ae.get(n)||1)<t)break;if(!je.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===ne.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 U||e instanceof C)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof G){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==d.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}}class ze{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.parser=new Je(this),this.setupFilterFunctions()}compile(e){return new Le(this,this.parser.parse(new se(pe(e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new X),this.functionRegister.set("length",new Z),this.functionRegister.set("search",new ee),this.functionRegister.set("match",new Y),this.functionRegister.set("value",new te)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case d.ValueType:if(!(o instanceof L||o instanceof K&&o.path.singularQuery()||o instanceof G&&this.functionRegister.get(o.name)?.returnType===d.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case d.LogicalType:if(!(o instanceof K||o instanceof M))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case d.NodesType:if(!(o instanceof K||o instanceof G&&this.functionRegister.get(o.name)?.returnType===d.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}}var Me=Object.freeze({__proto__:null,Count:X,FunctionExpressionType:d,Length:Z,Match:Y,Search:ee,Value:te});const De=new ze;function Ke(e,t){return De.query(e,t)}function Ce(e,t){return De.lazyQuery(e,t)}function Ue(e){return De.compile(e)}var Ge=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:De,FunctionExpressionType:d,JSONPath:Le,JSONPathEnvironment:ze,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:$,JSONPathNodeList:b,JSONPathRecursionLimitError:h,JSONPathSyntaxError:a,JSONPathTypeError:s,Nothing:P,Token:re,TokenKind:ne,compile:Ue,expressions:q,functions:Me,lazyQuery:Ce,match:function(e,t){return De.match(e,t)},query:Ke,selectors:_e});class Qe extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class We extends Qe{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class Ve{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n))if(r===x){if("-"!==s)throw new Qe(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!u(n))throw new Qe(`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 Be{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new Qe(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new Qe(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!u(n))throw new Qe(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Qe(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class qe{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new Qe(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!u(n))throw new Qe(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Qe(`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 Xe{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new Qe(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new Qe(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);c(n)?n.splice(Number(s),1):u(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(o))o.splice(Number(a),0,r);else{if(!u(o))throw new Qe(`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 Ze{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new Qe(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!u(s))throw new Qe(`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 He{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!f(r,this.value))throw new We(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class Ye{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 Ve(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new Be(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new qe(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new Xe(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Ze(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new He(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 m)throw new Qe(`${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 Qe(`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 Qe(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!l(s))throw new Qe(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new N(s)}catch(e){if(e instanceof g)throw new Qe(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new Qe(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof N)return e;if(!l(e))throw new Qe(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new N(e)}catch(e){if(e instanceof g)throw new Qe(`${e.message} (${t}:${n})`);throw e}}}function et(e,t){return new Ye(e).apply(t)}var tt=Object.freeze({__proto__:null,JSONPatch:Ye,JSONPatchError:Qe,JSONPatchTestFailure:We,apply:et});return e.DEFAULT_ENVIRONMENT=De,e.FunctionExpressionType=d,e.JSONPatch=Ye,e.JSONPatchError=Qe,e.JSONPatchTestFailure=We,e.JSONPath=Le,e.JSONPathEnvironment=ze,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=$,e.JSONPathNodeList=b,e.JSONPathRecursionLimitError=h,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=N,e.Nothing=P,e.RelativeJSONPointer=S,e.Token=re,e.TokenKind=ne,e.UNDEFINED=x,e.apply=et,e.compile=Ue,e.jsonpatch=tt,e.jsonpath=Ge,e.jsonpointer=R,e.lazyQuery=Ce,e.query=Ke,e.resolve=T,e.version="1.0.0",e}({});
1
+ var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}class h extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathRecursionLimitError",this.message=n(e,t)}}function c(e){return Array.isArray(e)}function u(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function l(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e,t){if(e===t)return!0;if(Array.isArray(e)){if(Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!f(e[n],t[n]))return!1;return!0}return!1}if(u(e)&&u(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!f(e[r],t[r]))return!1;return!0}return!1}let d=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class g extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class m extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class v extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class y extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class O extends m{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=Symbol.for("jsonpointer.undefined");class N{#e;constructor(e){this.tokens=this.parse(e),this.#e=N.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof m&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof v||e instanceof w)return[t,x];throw e}}toString(){return this.#e}isRelativeTo(e){return e.tokens.length<this.tokens.length&&this.tokens.slice(0,e.tokens.length).every(((t,n)=>t===e.tokens[n]))}parse(e){if(e.length&&!e.startsWith("/"))throw new y(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(c(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];if(t.startsWith("#")){const r=t.slice(1);if(k.test(r)&&Object.hasOwn(e,r))return Number(r);throw new v(`index out of range '${N.encode(this.tokens.slice(0,n+1))}'`)}throw new v(`index out of range '${N.encode(this.tokens.slice(0,n+1))}'`)}if(u(e)){if(Object.hasOwn(e,t))return e[t];if(t.startsWith("#")&&Object.hasOwn(e,t.slice(1)))return t.slice(1);throw new w(`no such property '${N.encode(this.tokens.slice(0,n+1))}'`)}throw new O(`found primitive value, expected an object '${N.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!l(e))throw new O("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new N(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new N(N.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 m)return!1;throw e}return!0}parent(){return this.tokens.length?new N(N.encode(this.tokens.slice(0,this.tokens.length-1))):this}to(e){return(l(e)?new S(e):e).to(this)}}const E=/(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s,k=/(0|[1-9][0-9]*)/;class S{constructor(e){[this.origin,this.index,this.pointer]=this.parse(e)}toString(){const e=this.index>0?"+":"",t=0===this.index?"":`${e}${this.index}`;return`${this.origin}${t}${this.pointer}`}to(e){const t=l(e)?new N(e):e;if(this.origin>t.tokens.length)throw new v(`origin (${this.origin}) exceeds root (${t.tokens.length})`);const n=this.origin<1?t.tokens.slice():t.tokens.slice(0,-this.origin);if(this.index&&n.length&&this.isIntLike(n.at(-1))){const e=Number(n.at(-1))+this.index;if(e<0)throw new v(`index offset out of range (${e})`);n[n.length-1]=String(e)}return this.pointer instanceof N?n.push(...this.pointer.tokens):n[n.length-1]=`#${n[n.length-1]}`,new N(N.encode(n))}parse(e){const t=E.exec(e);if(!t||!t.groups)throw new y("failed to parse relative pointer");const n=this.parseInt(t.groups.ORIGIN);let r=0;if(t.groups.INDEX_G){if(r=this.parseInt(t.groups.INDEX),0===r)throw new y("index offset can't be zero");"-"===t.groups.SIGN&&(r=-r)}return"#"===t.groups.POINTER?[n,r,"#"]:[n,r,new N(t.groups.POINTER)]}parseInt(e){if(e.startsWith("0")&&e.length>1)throw new y("unexpected leading zero");if(k.test(e))return Number(e);throw new y(`expected an integer, found '${e}'`)}isIntLike(e){return!(void 0!==e&&!p(e))||k.test(e)}}function T(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new N(e).resolve(t,n)}var R=Object.freeze({__proto__:null,JSONPointer:N,JSONPointerError:g,JSONPointerIndexError:v,JSONPointerKeyError:w,JSONPointerResolutionError:m,JSONPointerSyntaxError:y,JSONPointerTypeError:O,RelativeJSONPointer:S,UNDEFINED:x,resolve:T});class ${constructor(e,t,n){this.value=e,this.location=t,this.root=n}get path(){return"$"+this.location.map((e=>l(e)?`['${e}']`:`[${e}]`)).join("")}toPointer(){return this.location.length?new N(N.encode(this.location.map(String))):new N("")}}class b{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}}const P=Symbol.for("jsonpath.nothing");function I(e,t){return u(e)&&Object.hasOwn(e,t)}class _{constructor(e){this.token=e}}class L extends _{}class A extends L{evaluate(){return null}toString(){return"null"}}class j extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class F extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class J extends L{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class M extends _{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 b?0===t.nodes.length:!Q(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class z extends _{constructor(e,t,n,r){super(e),this.token=e,this.left=t,this.operator=n,this.right=r}evaluate(e){let t=this.left.evaluate(e);t instanceof b&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return n instanceof b&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?Q(t)&&Q(n):"||"===this.operator?Q(t)||Q(n):W(t,this.operator,n)}toString(){return"&&"===this.operator||"||"===this.operator?`(${this.left.toString()} ${this.operator} ${this.right.toString()})`:`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class D extends _{constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof b?t.nodes.length>0:Q(t)}toString(){return this.expression.toString()}}class K extends _{constructor(e,t){super(e),this.token=e,this.path=t}}class C extends K{evaluate(e){return e.lazy?new b(Array.from(this.path.lazyQuery(e.currentValue))):this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class U extends K{evaluate(e){return e.lazy?new b(Array.from(this.path.lazyQuery(e.rootValue))):this.path.query(e.rootValue)}toString(){return this.path.toString()}}class G extends _{constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.functionRegister.get(this.name);if(!t)throw new i(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==d.NodesType&&e instanceof b?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 P;case 1:return e.nodes[0].value;default:return e}}}function Q(e){return!(e instanceof b&&e.empty())&&!("boolean"==typeof e&&!1===e)}function W(e,t,n){switch(t){case"==":return V(e,n);case"!=":return!V(e,n);case"<":return B(e,n);case">":return B(n,e);case">=":return B(n,e)||V(e,n);case"<=":return B(e,n)||V(e,n);default:return!1}}function V(e,t){if(t instanceof b&&([e,t]=[t,e]),e instanceof b){if(t instanceof b){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return f(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===P:1===e.nodes.length&&f(e.nodes[0].value,t)}return e===P&&t===P||f(e,t)}function B(e,t){return!!(l(e)&&l(t)||p(e)&&p(t))&&e<t}var q=Object.freeze({__proto__:null,BooleanLiteral:j,FilterExpression:_,FilterExpressionLiteral:L,FunctionExtension:G,InfixExpression:z,JSONPathQuery:K,LogicalExpression:D,NullLiteral:A,NumberLiteral:J,PrefixExpression:M,RelativeQuery:C,RootQuery:U,StringLiteral:F,compare:W});class X{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return e.length}}class Z{argTypes=[d.ValueType];returnType=d.ValueType;call(e){return c(e)||l(e)?e.length:u(e)?Object.keys(e).length:P}}class H extends Map{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,t=arguments.length>1?arguments[1]:void 0;void 0!==t?super(t):super(),this.maxSize=e}get(e){const t=super.get(e);return this.has(e)&&(this.delete(e),this.set(e,t)),t}set(e,t){return this.has(e)?this.delete(e):this.size>=this.maxSize&&this.delete(this.first()),super.set(e,t)}first(){return this.keys().next().value}}class Y{argTypes=[d.ValueType,d.ValueType];returnType=d.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.#t=new H(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}try{const n=new RegExp(this.fullMatch(t),"u");return this.cacheSize>0&&this.#t.set(t,n),n.test(e)}catch(e){if(this.throwErrors)throw e;return!1}}fullMatch(e){const t=[];return e.startsWith("^")||t.push("^"),t.push(e),e.endsWith("$")||t.push("$"),t.join("")}}class ee{argTypes=[d.ValueType,d.ValueType];returnType=d.LogicalType;#t;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.cacheSize=e.cacheSize??10,this.throwErrors=e.throwErrors??!1,this.#t=new H(this.cacheSize)}call(e,t){if(this.cacheSize>0){const n=this.#t.get(t);if(n)try{return!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}try{const n=new RegExp(t,"u");return this.cacheSize>0&&this.#t.set(t,n),!!e.match(n)}catch(e){if(this.throwErrors)throw e;return!1}}}class te{argTypes=[d.NodesType];returnType=d.ValueType;call(e){return 1===e.length?e.nodes[0].value:P}}let ne=function(e){return e.AND="TOKEN_AND",e.COLON="TOKEN_COLON",e.COMMA="TOKEN_COMMA",e.CURRENT="TOKEN_CURRENT_NODE",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.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 re{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new re(ne.EOF,"",-1,"");class se{#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 oe=/e[+-]?\d+/y,ie=/[a-z][a-z_0-9]*/y,ae=/-?\d+/y,he=/-?[0-9]+/y,ce=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,ue=new Set([" ","\n","\t","\r"]);class le{filterLevel=0;parenStack=[];tokens=[];#r=0;#n=0;constructor(e){this.path=e}get pos(){return this.#n}get start(){return this.#r}run(){let e=fe;for(;e;)e=e(this)}emit(e){this.tokens.push(new re(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 re(ne.ERROR,e,this.#n,this.path))}this.#n-=1}peek(){const e=this.next();return e&&this.backup(),e}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 re(ne.ERROR,e,this.pos,this.path))}return!!this.acceptRun(ue)&&(this.ignore(),!0)}error(e){this.tokens.push(new re(ne.ERROR,e,this.#n,this.path))}}function pe(e){const[t,n]=function(e){const t=new le(e);return[t,t.tokens]}(e);if(t.run(),n.length&&n[n.length-1].kind===ne.ERROR)throw new a(n[n.length-1].value,n[n.length-1]);return n}function fe(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(ne.ROOT),de)}function de(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(ne.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(ne.DDOT),ge):me;case"[":return e.emit(ne.LBRACKET),ve;default:return e.backup(),e.filterLevel?we:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ge(e){const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(ne.WILD),de;case"[":return e.emit(ne.LBRACKET),ve;default:return e.backup(),e.acceptMatchRun(ce)?(e.emit(ne.NAME),de):(e.error(`unexpected descendent selection token '${t}'`),null)}}function me(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;const t=e.next();return"*"===t?(e.emit(ne.WILD),de):(e.backup(),e.acceptMatchRun(ce)?(e.emit(ne.NAME),de):(e.error(`unexpected shorthand selector '${t}'`),null))}function ve(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"]":return e.emit(ne.RBRACKET),e.filterLevel?we:de;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(ne.WILD);continue;case"?":return e.emit(ne.FILTER),e.filterLevel+=1,we;case",":e.emit(ne.COMMA);continue;case":":e.emit(ne.COLON);continue;case"'":return Oe;case'"':return xe;default:if(e.backup(),e.acceptMatchRun(ae)){e.emit(ne.INDEX);continue}return e.error(`unexpected token '${t}' in bracketed selection`),null}}}function we(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":case"]":return e.filterLevel-=1,1===e.parenStack.length?(e.error("unbalanced parentheses"),null):(e.backup(),ve);case",":if(e.emit(ne.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,ve;case"'":return Ne;case'"':return Ee;case"(":e.emit(ne.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(ne.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(ne.ROOT),de;case"@":return e.emit(ne.CURRENT),de;case".":return e.backup(),de;case"!":"="===e.peek()?(e.next(),e.emit(ne.NE)):e.emit(ne.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(ne.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(ne.LE)):e.emit(ne.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(ne.GE)):e.emit(ne.GT);continue;default:if(e.backup(),e.acceptMatchRun(he)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(he)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(oe),e.emit(ne.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(ne.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(ne.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(ne.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(ne.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(ne.NULL);continue}if(e.acceptMatchRun(ie)&&"("===e.peek()){e.parenStack.push(1),e.emit(ne.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function ye(e,t){return function(n){if(n.ignore(),n.peek()===e)return n.emit("'"===e?ne.SINGLE_QUOTE_STRING:ne.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t;for(;;){const r=n.path.slice(n.pos,n.pos+2),s=n.next();if("\\\\"!==r&&r!==`\\${e}`){if("\\"===s&&!r.match(/\\[bfnrtu/]/))return n.error("invalid escape"),null;if(!s)return n.error(`unclosed string starting at index ${n.start}`),null;if(s===e)return n.backup(),n.emit("'"===e?ne.SINGLE_QUOTE_STRING:ne.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t}else n.next()}}}const Oe=ye("'",ve),xe=ye('"',ve),Ne=ye("'",we),Ee=ye('"',we);class ke{constructor(e,t){this.environment=e,this.token=t}}class Se extends ke{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)I(n.value,this.name)&&t.push(new $(n.value[this.name],n.location.concat(this.name),n.root));return t}*lazyResolve(e){for(const t of e)I(t.value,this.name)&&(yield new $(t.value[this.name],t.location.concat(this.name),t.root))}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class Te extends ke{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.minIntIndex||n>this.environment.maxIntIndex)throw new o("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(c(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new $(n.value[e],n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(c(t.value)){const e=this.normalizedIndex(t.value.length);e in t.value&&(yield new $(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 Re extends ke{constructor(e,t,n,r,s){super(e,t),this.environment=e,this.token=t,this.start=n,this.stop=r,this.step=s,this.checkRange(n,r,s)}resolve(e){const t=[];for(const n of e)if(c(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new $(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(c(t.value))for(const[e,n]of this.slice(t.value,this.start,this.stop,this.step))yield new $(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}}class $e extends ke{constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(e,t),this.environment=e,this.token=t,this.shorthand=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++)t.push(new $(n.value[e],n.location.concat(e),n.root));else if(u(n.value))for(const[e,r]of this.environment.entries(n.value))t.push(new $(r,n.location.concat(e),n.root));return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++)yield new $(t.value[e],t.location.concat(e),t.root);else if(u(t.value))for(const[e,n]of this.environment.entries(t.value))yield new $(n,t.location.concat(e),t.root)}toString(){return this.shorthand?"[*]":"*"}}class be extends ke{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.selector=n}resolve(e){const t=[];for(const n of e){t.push(n);for(const e of this.visit(n))t.push(e)}return this.selector.resolve(t)}*lazyResolve(e){yield*this.selector.lazyResolve(this._lazyResolve(e))}*_lazyResolve(e){for(const t of e){const e=[{node:t,depth:0}];for(yield t;e.length;){const{node:t,depth:n}=e.pop();if(n>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);if(!(t.value instanceof String))if(c(t.value))for(let r=0;r<t.value.length;r++){const s=new $(t.value[r],t.location.concat(r),t.root);yield s,u(s.value)&&e.push({node:s,depth:n+1})}else if(u(t.value))for(const[r,s]of this.environment.entries(t.value)){const o=new $(s,t.location.concat(r),t.root);yield o,u(o.value)&&e.push({node:o,depth:n+1})}}}}toString(){return`..${this.selector.toString()}`}visit(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=this.environment.maxRecursionDepth)throw new h("recursion limit reached",this.token);const n=[];if(e.value instanceof String)return n;if(c(e.value))for(let r=0;r<e.value.length;r++){const s=new $(e.value[r],e.location.concat(r),e.root);n.push(s);for(const e of this.visit(s,t+1))n.push(e)}else if(u(e.value))for(const[r,s]of this.environment.entries(e.value)){const o=new $(s,e.location.concat(r),e.root);n.push(o);for(const e of this.visit(o,t+1))n.push(e)}return n}}class Pe extends ke{constructor(e,t,n){super(e,t),this.environment=e,this.token=t,this.expression=n}resolve(e){const t=[];for(const n of e)if(!(n.value instanceof String))if(c(n.value))for(let e=0;e<n.value.length;e++){const r=n.value[e],s={environment:this.environment,currentValue:r,rootValue:n.root};this.expression.evaluate(s)&&t.push(new $(r,n.location.concat(e),n.root))}else if(u(n.value))for(const[e,r]of this.environment.entries(n.value)){const s={environment:this.environment,currentValue:r,rootValue:n.root};this.expression.evaluate(s)&&t.push(new $(r,n.location.concat(e),n.root))}return t}*lazyResolve(e){for(const t of e)if(!(t.value instanceof String))if(c(t.value))for(let e=0;e<t.value.length;e++){const n=t.value[e],r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0};this.expression.evaluate(r)&&(yield new $(n,t.location.concat(e),t.root))}else if(u(t.value))for(const[e,n]of this.environment.entries(t.value)){const r={environment:this.environment,currentValue:n,rootValue:t.root,lazy:!0};this.expression.evaluate(r)&&(yield new $(n,t.location.concat(e),t.root))}}toString(){return`?${this.expression.toString()}`}}class Ie extends ke{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(", ")}]`}}var _e=Object.freeze({__proto__:null,BracketedSelection:Ie,FilterSelector:Pe,IndexSelector:Te,JSONPathSelector:ke,NameSelector:Se,RecursiveDescentSegment:be,SliceSelector:Re,WildcardSelector:$e});class Le{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=[new $(e,[],e)];for(const e of this.selectors)t=e.resolve(t);return new b(t)}lazyQuery(e){let t=[new $(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 Se||e instanceof Ie&&1===e.items.length&&(e.items[0]instanceof Se||e.items[0]instanceof Te)))return!1;return!0}}const Ae=new Map([[ne.AND,5],[ne.EQ,6],[ne.GE,6],[ne.GT,6],[ne.LE,6],[ne.LT,6],[ne.NE,6],[ne.NOT,7],[ne.OR,4],[ne.RPAREN,1]]),je=new Map([[ne.AND,"&&"],[ne.EQ,"=="],[ne.GE,">="],[ne.GT,">"],[ne.LE,"<="],[ne.LT,"<"],[ne.NE,"!="],[ne.OR,"||"]]),Fe=new Set(["==",">=",">","<=","<","!="]);class Je{constructor(e){this.environment=e,this.tokenMap=new Map([[ne.FALSE,this.parseBoolean],[ne.NUMBER,this.parseNumber],[ne.LPAREN,this.parseGroupedExpression],[ne.NOT,this.parsePrefixExpression],[ne.NULL,this.parseNull],[ne.ROOT,this.parseRootQuery],[ne.CURRENT,this.parseRelativeQuery],[ne.SINGLE_QUOTE_STRING,this.parseString],[ne.DOUBLE_QUOTE_STRING,this.parseString],[ne.TRUE,this.parseBoolean],[ne.FUNCTION,this.parseFunction]])}parse(e){e.current.kind===ne.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==ne.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 ne.NAME:return new Se(this.environment,e.current,e.current.value,!0);case ne.WILD:return new $e(this.environment,e.current,!0);case ne.DDOT:{const t=e.current;e.next();const n=this.parseSegment(e);if(!n)throw new a("bald descendant segment",e.current);return new be(this.environment,t,n)}case ne.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 Te(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===ne.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(ne.COLON),e.next()):(n.push(void 0),e.expect(ne.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===ne.COLON&&e.next()):e.current.kind===ne.COLON&&(n.push(void 0),e.expect(ne.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Re(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==ne.RBRACKET;){switch(e.current.kind){case ne.SINGLE_QUOTE_STRING:case ne.DOUBLE_QUOTE_STRING:n.push(new Se(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case ne.FILTER:n.push(this.parseFilter(e));break;case ne.INDEX:e.peek.kind===ne.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case ne.COLON:n.push(this.parseSlice(e));break;case ne.WILD:n.push(new $e(this.environment,e.current));break;case ne.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!==ne.RBRACKET&&(e.expectPeek(ne.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Ie(this.environment,t,n)}parseFilter(e){const t=e.next(),n=this.parseFilterExpression(e);if(n instanceof G){const e=this.environment.functionRegister.get(n.name);if(e&&e.returnType===d.ValueType)throw new s(`result of ${n.name}() must be compared`,n.token)}return new Pe(this.environment,t,new D(t,n))}parseBoolean(e){return e.current.kind===ne.FALSE?new j(e.current,!1):new j(e.current,!0)}parseNull(e){return new A(e.current)}parseString(e){return new F(e.current,this.decodeString(e.current))}parseNumber(e){return new J(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(ne.NOT),e.next(),new M(e.current,"!",this.parseFilterExpression(e,7))}parseInfixExpression(e,t){const n=e.next(),r=Ae.get(n.kind)||1,s=this.parseFilterExpression(e,r),o=je.get(n.kind);if(!o)throw new a(`unknown operator '${n.kind}'`,n);return Fe.has(o)&&(this.throwForNonComparable(t),this.throwForNonComparable(s)),new z(n,t,o,s)}parseGroupedExpression(e){e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==ne.RPAREN;){if(e.current.kind===ne.EOF)throw new a("unbalanced parentheses",e.current);t=this.parseInfixExpression(e,t)}return e.expect(ne.RPAREN),t}parseRootQuery(e){const t=e.next();return new U(t,new Le(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new C(t,new Le(this.environment,this.parsePath(e,!0)))}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==ne.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(;je.has(s);)e.next(),r=this.parseInfixExpression(e,r),s=e.peek.kind;if(t.push(r),e.peek.kind!==ne.RPAREN){if(e.peek.kind===ne.RBRACKET)break;e.expectPeek(ne.COMMA),e.next()}e.next()}return e.expect(ne.RPAREN),new G(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 ne.EOF:case ne.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===ne.EOF||n===ne.RBRACKET||(Ae.get(n)||1)<t)break;if(!je.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===ne.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 U||e instanceof C)&&!e.path.singularQuery())throw new s("non-singular query is not comparable",e.token);if(e instanceof G){const t=this.environment.functionRegister.get(e.name);if(t&&t.returnType!==d.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}}class Me{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.parser=new Je(this),this.setupFilterFunctions()}compile(e){return new Le(this,this.parser.parse(new se(pe(e))))}query(e,t){return this.compile(e).query(t)}lazyQuery(e,t){return this.compile(e).lazyQuery(t)}match(e,t){return this.compile(e).match(t)}setupFilterFunctions(){this.functionRegister.set("count",new X),this.functionRegister.set("length",new Z),this.functionRegister.set("search",new ee),this.functionRegister.set("match",new Y),this.functionRegister.set("value",new te)}checkWellTypedness(e,t){const n=this.functionRegister.get(e.value);if(!n)throw new i(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,o,i]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case d.ValueType:if(!(o instanceof L||o instanceof K&&o.path.singularQuery()||o instanceof G&&this.functionRegister.get(o.name)?.returnType===d.ValueType))throw new s(`${e.value}() argument ${i} must be of ValueType`,o.token);break;case d.LogicalType:if(!(o instanceof K||o instanceof z))throw new s(`${e.value}() argument ${i} must be of LogicalType`,o.token);break;case d.NodesType:if(!(o instanceof K||o instanceof G&&this.functionRegister.get(o.name)?.returnType===d.NodesType))throw new s(`${e.value}() argument ${i} must be of NodesType`,o.token)}return t}entries(e){return this.nondeterministic?function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}(Object.entries(e)):Object.entries(e)}}var ze=Object.freeze({__proto__:null,Count:X,FunctionExpressionType:d,Length:Z,Match:Y,Search:ee,Value:te});const De=new Me;function Ke(e,t){return De.query(e,t)}function Ce(e,t){return De.lazyQuery(e,t)}function Ue(e){return De.compile(e)}var Ge=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:De,FunctionExpressionType:d,JSONPath:Le,JSONPathEnvironment:Me,JSONPathError:t,JSONPathIndexError:o,JSONPathLexerError:r,JSONPathNode:$,JSONPathNodeList:b,JSONPathRecursionLimitError:h,JSONPathSyntaxError:a,JSONPathTypeError:s,Nothing:P,Token:re,TokenKind:ne,compile:Ue,expressions:q,functions:ze,lazyQuery:Ce,match:function(e,t){return De.match(e,t)},query:Ke,selectors:_e});class Qe extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class We extends Qe{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class Ve{name="add";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n))if(r===x){if("-"!==s)throw new Qe(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!u(n))throw new Qe(`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 Be{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new Qe(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new Qe(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!u(n))throw new Qe(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Qe(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class qe{name="replace";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)return this.value;const s=this.path.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(n)){if(r===x)throw new Qe(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!u(n))throw new Qe(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Qe(`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 Xe{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new Qe(`can't move object to one of its own children (${this.name}:${t})`);const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new Qe(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);c(n)?n.splice(Number(s),1):u(n)&&delete n[s];const[o,i]=this.path.resolveWithParent(e);if(o===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(o))o.splice(Number(a),0,r);else{if(!u(o))throw new Qe(`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 Ze{name="copy";constructor(e,t){this.from=e,this.path=t}apply(e,t){const[n,r]=this.from.resolveWithParent(e);if(r===x)throw new Qe(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const o=this.path.tokens.at(-1);if(void 0===o)throw new Qe(`unexpected operation on 'undefined' (${this.name}:${t})`);if(c(s))s.splice(Number(o),0,this.deepCopy(r));else{if(!u(s))throw new Qe(`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 He{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!f(r,this.value))throw new We(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class Ye{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 Ve(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new Be(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new qe(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new Xe(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Ze(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new He(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 m)throw new Qe(`${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 Qe(`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 Qe(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!l(s))throw new Qe(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new N(s)}catch(e){if(e instanceof g)throw new Qe(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new Qe(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof N)return e;if(!l(e))throw new Qe(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new N(e)}catch(e){if(e instanceof g)throw new Qe(`${e.message} (${t}:${n})`);throw e}}}function et(e,t){return new Ye(e).apply(t)}var tt=Object.freeze({__proto__:null,JSONPatch:Ye,JSONPatchError:Qe,JSONPatchTestFailure:We,apply:et});return e.DEFAULT_ENVIRONMENT=De,e.FunctionExpressionType=d,e.JSONPatch=Ye,e.JSONPatchError=Qe,e.JSONPatchTestFailure=We,e.JSONPath=Le,e.JSONPathEnvironment=Me,e.JSONPathError=t,e.JSONPathIndexError=o,e.JSONPathLexerError=r,e.JSONPathNode=$,e.JSONPathNodeList=b,e.JSONPathRecursionLimitError=h,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=N,e.Nothing=P,e.RelativeJSONPointer=S,e.Token=re,e.TokenKind=ne,e.UNDEFINED=x,e.apply=et,e.compile=Ue,e.jsonpatch=tt,e.jsonpath=Ge,e.jsonpointer=R,e.lazyQuery=Ce,e.query=Ke,e.resolve=T,e.version="1.1.0",e}({});
2
2
  //# sourceMappingURL=json-p3.iife.min.js.map