json-p3 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -25
- package/dist/json-p3.cjs.js +5 -3
- package/dist/json-p3.esm.js +5 -3
- package/dist/json-p3.iife.js +5 -3
- package/dist/json-p3.iife.min.js +1 -1
- package/dist/json-p3.iife.min.js.map +1 -1
- package/dist/pointer/pointer.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,16 +6,26 @@ JSONPath, JSON Patch and JSON Pointer for JavaScript.
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/jg-rp/json-p3/blob/main/LICENSE">
|
|
9
|
-
<img alt="
|
|
9
|
+
<img alt="LICENSE" src="https://img.shields.io/npm/l/json-p3?style=flat-square">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://github.com/jg-rp/json-p3/actions">
|
|
12
12
|
<img src="https://img.shields.io/github/actions/workflow/status/jg-rp/json-p3/tests.yaml?branch=main&label=tests&style=flat-square" alt="Tests">
|
|
13
13
|
</a>
|
|
14
|
-
<
|
|
14
|
+
<a href="https://www.npmjs.com/package/json-p3">
|
|
15
|
+
<img alt="NPM" src="https://img.shields.io/npm/v/json-p3?style=flat-square">
|
|
16
|
+
</a>
|
|
17
|
+
<img alt="npm type definitions" src="https://img.shields.io/npm/types/json-p3?style=flat-square">
|
|
15
18
|
</p>
|
|
16
19
|
|
|
17
20
|
---
|
|
18
21
|
|
|
22
|
+
**Table of Contents**
|
|
23
|
+
|
|
24
|
+
- [Install](#install)
|
|
25
|
+
- [JSONPath](#jsonpath)
|
|
26
|
+
- [JSON Pointer](#json-pointer)
|
|
27
|
+
- [JSON Patch](#json-patch)
|
|
28
|
+
|
|
19
29
|
## Install
|
|
20
30
|
|
|
21
31
|
### Node.js
|
|
@@ -70,7 +80,35 @@ console.log(nodes.values());
|
|
|
70
80
|
|
|
71
81
|
### Browser
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
Download and include JSON P3 in a script tag:
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<script src="path/to/json-p3.iife.min.js"></script>
|
|
87
|
+
<script>
|
|
88
|
+
const data = {
|
|
89
|
+
players: [{ name: "Sue" }, { name: "John" }, { name: "Sally" }],
|
|
90
|
+
visitors: [{ name: "Brian" }, { name: "Roy" }],
|
|
91
|
+
};
|
|
92
|
+
const nodes = json_p3.query("$..name");
|
|
93
|
+
console.log(nodes.values());
|
|
94
|
+
// [ 'Sue', 'John', 'Sally', 'Brian', 'Roy' ]
|
|
95
|
+
</script>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or use a CDN:
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<script src="https://cdn.jsdelivr.net/npm/json-p3@0.1.0/dist/json-p3.iife.min.js"></script>
|
|
102
|
+
<script>
|
|
103
|
+
const data = {
|
|
104
|
+
players: [{ name: "Sue" }, { name: "John" }, { name: "Sally" }],
|
|
105
|
+
visitors: [{ name: "Brian" }, { name: "Roy" }],
|
|
106
|
+
};
|
|
107
|
+
const nodes = json_p3.query("$..name");
|
|
108
|
+
console.log(nodes.values());
|
|
109
|
+
// [ 'Sue', 'John', 'Sally', 'Brian', 'Roy' ]
|
|
110
|
+
</script>
|
|
111
|
+
```
|
|
74
112
|
|
|
75
113
|
## JSONPath
|
|
76
114
|
|
|
@@ -94,8 +132,8 @@ console.log(nodes.values()); // [ 'John', 'Sally', 'Jane' ]
|
|
|
94
132
|
|
|
95
133
|
The result of `jsonpath.query()` is an instance of `JSONPathNodeList`. That is a list of `JSONPathNode` objects, one node for each value in the target JSON document matching the query. Each node has a:
|
|
96
134
|
|
|
97
|
-
- `value` - The value found in the target JSON
|
|
98
|
-
- `location` - An array of property names and array indices that were required to reach the node's value in the target JSON
|
|
135
|
+
- `value` - The value found in the target JSON document. This could be an array, object or primitive value.
|
|
136
|
+
- `location` - An array of property names and array indices that were required to reach the node's value in the target JSON document.
|
|
99
137
|
- `path` - The normalized JSONPath to this node in the target JSON document.
|
|
100
138
|
|
|
101
139
|
Use `JSONPathNodeList.paths()` to retrieve all node paths.
|
|
@@ -132,7 +170,22 @@ console.log(nodes.locations());
|
|
|
132
170
|
]
|
|
133
171
|
```
|
|
134
172
|
|
|
135
|
-
|
|
173
|
+
`JSONPathNodeList` objects are iterable too.
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
// .. continued from above
|
|
177
|
+
for (const node of nodes) {
|
|
178
|
+
console.log(`${node.value} @ ${node.path}`);
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Output:**
|
|
183
|
+
|
|
184
|
+
```plain
|
|
185
|
+
John @ $['users'][1]['name']
|
|
186
|
+
Sally @ $['users'][2]['name']
|
|
187
|
+
Jane @ $['users'][3]['name']
|
|
188
|
+
```
|
|
136
189
|
|
|
137
190
|
You can also compile a JSONPath query for repeated use against different data.
|
|
138
191
|
|
|
@@ -176,17 +229,7 @@ console.log(rv); // { name: 'John', score: 86 }
|
|
|
176
229
|
If the pointer can't be resolved against the argument JSON value, one of `JSONPointerIndexError`, `JSONPointerKeyError` or `JSONPointerTypeError` is thrown. All three exceptions inherit from `JSONPointerResolutionError`.
|
|
177
230
|
|
|
178
231
|
```javascript
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const data = {
|
|
182
|
-
users: [
|
|
183
|
-
{ name: "Sue", score: 100 },
|
|
184
|
-
{ name: "John", score: 86 },
|
|
185
|
-
{ name: "Sally", score: 84 },
|
|
186
|
-
{ name: "Jane", score: 55 },
|
|
187
|
-
],
|
|
188
|
-
};
|
|
189
|
-
|
|
232
|
+
// .. continued from above
|
|
190
233
|
const rv = jsonpointer.resolve("/users/1/age", data);
|
|
191
234
|
// JSONPointerKeyError: no such property ("/users/1/age")
|
|
192
235
|
```
|
|
@@ -194,22 +237,32 @@ const rv = jsonpointer.resolve("/users/1/age", data);
|
|
|
194
237
|
A fallback value can be given as a third argument, which will be returned in the event of a `JSONPointerResolutionError`.
|
|
195
238
|
|
|
196
239
|
```javascript
|
|
197
|
-
|
|
240
|
+
// .. continued from above
|
|
241
|
+
const rv = jsonpointer.resolve("/users/1/age", data, -1);
|
|
242
|
+
console.log(rv); // -1
|
|
243
|
+
```
|
|
198
244
|
|
|
199
|
-
|
|
245
|
+
You can also create an instance of `JSONPointer` then resolve it against different data.
|
|
246
|
+
|
|
247
|
+
```javascript
|
|
248
|
+
import { JSONPointer } from "json-p3";
|
|
249
|
+
|
|
250
|
+
const someData = {
|
|
200
251
|
users: [
|
|
201
252
|
{ name: "Sue", score: 100 },
|
|
202
253
|
{ name: "John", score: 86 },
|
|
203
254
|
{ name: "Sally", score: 84 },
|
|
204
|
-
{ name: "Jane", score: 55 },
|
|
205
255
|
],
|
|
206
256
|
};
|
|
207
257
|
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
258
|
+
const otherData = {
|
|
259
|
+
users: [{ name: "Brian" }, { name: "Roy" }],
|
|
260
|
+
};
|
|
211
261
|
|
|
212
|
-
|
|
262
|
+
const pointer = new JSONPointer("/users/1");
|
|
263
|
+
console.log(pointer.resolve(someData)); // { name: 'John', score: 86 }
|
|
264
|
+
console.log(pointer.resolve(otherData)); // { name: 'Roy' }
|
|
265
|
+
```
|
|
213
266
|
|
|
214
267
|
## JSON Patch
|
|
215
268
|
|
|
@@ -249,4 +302,33 @@ console.log(data);
|
|
|
249
302
|
// { some: { other: 'thing', foo: { bar: [Array], else: 'thing' } } }
|
|
250
303
|
```
|
|
251
304
|
|
|
252
|
-
|
|
305
|
+
`JSONPatch` also offers a builder API for constructing JSON patch documents. We use strings as JSON Pointers in this example, but existing `JSONPointer` objects are OK too.
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
import { JSONPatch } from "json-p3";
|
|
309
|
+
|
|
310
|
+
const data = { some: { other: "thing" } };
|
|
311
|
+
|
|
312
|
+
const patch = new JSONPatch()
|
|
313
|
+
.add("/some/foo", { foo: [] })
|
|
314
|
+
.add("/some/foo", { bar: [] })
|
|
315
|
+
.copy("/some/other", "/some/foo/else")
|
|
316
|
+
.add("/some/foo/bar/-", "/some/foo/else");
|
|
317
|
+
|
|
318
|
+
patch.apply(data);
|
|
319
|
+
console.log(JSON.stringify(data, undefined, " "));
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Output:**
|
|
323
|
+
|
|
324
|
+
```json
|
|
325
|
+
{
|
|
326
|
+
"some": {
|
|
327
|
+
"other": "thing",
|
|
328
|
+
"foo": {
|
|
329
|
+
"bar": ["/some/foo/else"],
|
|
330
|
+
"else": "thing"
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
package/dist/json-p3.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* json-p3 version 0.1.
|
|
2
|
+
* json-p3 version 0.1.1
|
|
3
3
|
* https://github.com/jg-rp/json-p3
|
|
4
4
|
*
|
|
5
5
|
* MIT License
|
|
@@ -397,10 +397,12 @@ class JSONPointer {
|
|
|
397
397
|
|
|
398
398
|
/**
|
|
399
399
|
* Join this pointer with _tokens_.
|
|
400
|
+
*
|
|
400
401
|
* @param tokens - JSON Pointer strings, possibly without leading slashes.
|
|
401
402
|
* If a token or "part" does have a leading slash, the previous pointer is
|
|
402
403
|
* ignored and a new `JSONPointer` is created, then processing of the
|
|
403
404
|
* remaining tokens continues.
|
|
405
|
+
*
|
|
404
406
|
* @returns A new JSON Pointer that is the concatenation of all tokens or
|
|
405
407
|
* "parts".
|
|
406
408
|
*/
|
|
@@ -1094,7 +1096,7 @@ class TokenStream {
|
|
|
1094
1096
|
|
|
1095
1097
|
// These regular expressions are to be used with Lexer.acceptMatchRun(),
|
|
1096
1098
|
// which expects the sticky flag to be set.
|
|
1097
|
-
const exponentPattern = /e[+-]
|
|
1099
|
+
const exponentPattern = /e[+-]?\d+/y;
|
|
1098
1100
|
const functionNamePattern = /[a-z][a-z_0-9]*/y;
|
|
1099
1101
|
const indexPattern = /-?\d+/y;
|
|
1100
1102
|
const intPattern = /-?[0-9]+/y;
|
|
@@ -2808,7 +2810,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2808
2810
|
apply: apply
|
|
2809
2811
|
});
|
|
2810
2812
|
|
|
2811
|
-
const version = "0.1.
|
|
2813
|
+
const version = "0.1.1";
|
|
2812
2814
|
|
|
2813
2815
|
exports.FunctionExpressionType = FunctionExpressionType;
|
|
2814
2816
|
exports.JSONPatch = JSONPatch;
|
package/dist/json-p3.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* json-p3 version 0.1.
|
|
2
|
+
* json-p3 version 0.1.1
|
|
3
3
|
* https://github.com/jg-rp/json-p3
|
|
4
4
|
*
|
|
5
5
|
* MIT License
|
|
@@ -395,10 +395,12 @@ class JSONPointer {
|
|
|
395
395
|
|
|
396
396
|
/**
|
|
397
397
|
* Join this pointer with _tokens_.
|
|
398
|
+
*
|
|
398
399
|
* @param tokens - JSON Pointer strings, possibly without leading slashes.
|
|
399
400
|
* If a token or "part" does have a leading slash, the previous pointer is
|
|
400
401
|
* ignored and a new `JSONPointer` is created, then processing of the
|
|
401
402
|
* remaining tokens continues.
|
|
403
|
+
*
|
|
402
404
|
* @returns A new JSON Pointer that is the concatenation of all tokens or
|
|
403
405
|
* "parts".
|
|
404
406
|
*/
|
|
@@ -1092,7 +1094,7 @@ class TokenStream {
|
|
|
1092
1094
|
|
|
1093
1095
|
// These regular expressions are to be used with Lexer.acceptMatchRun(),
|
|
1094
1096
|
// which expects the sticky flag to be set.
|
|
1095
|
-
const exponentPattern = /e[+-]
|
|
1097
|
+
const exponentPattern = /e[+-]?\d+/y;
|
|
1096
1098
|
const functionNamePattern = /[a-z][a-z_0-9]*/y;
|
|
1097
1099
|
const indexPattern = /-?\d+/y;
|
|
1098
1100
|
const intPattern = /-?[0-9]+/y;
|
|
@@ -2806,6 +2808,6 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2806
2808
|
apply: apply
|
|
2807
2809
|
});
|
|
2808
2810
|
|
|
2809
|
-
const version = "0.1.
|
|
2811
|
+
const version = "0.1.1";
|
|
2810
2812
|
|
|
2811
2813
|
export { FunctionExpressionType, JSONPatch, JSONPatchError, JSONPatchTestFailure, JSONPath, JSONPathEnvironment, JSONPathError, JSONPathIndexError, JSONPathLexerError, JSONPathNode, JSONPathNodeList, JSONPathSyntaxError, JSONPathTypeError, JSONPointer, Nothing, Token, TokenKind, UNDEFINED, apply, compile, index as jsonpatch, index$1 as jsonpath, index$3 as jsonpointer, query, resolve, version };
|
package/dist/json-p3.iife.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* json-p3 version 0.1.
|
|
2
|
+
* json-p3 version 0.1.1
|
|
3
3
|
* https://github.com/jg-rp/json-p3
|
|
4
4
|
*
|
|
5
5
|
* MIT License
|
|
@@ -398,10 +398,12 @@ var json_p3 = (function (exports) {
|
|
|
398
398
|
|
|
399
399
|
/**
|
|
400
400
|
* Join this pointer with _tokens_.
|
|
401
|
+
*
|
|
401
402
|
* @param tokens - JSON Pointer strings, possibly without leading slashes.
|
|
402
403
|
* If a token or "part" does have a leading slash, the previous pointer is
|
|
403
404
|
* ignored and a new `JSONPointer` is created, then processing of the
|
|
404
405
|
* remaining tokens continues.
|
|
406
|
+
*
|
|
405
407
|
* @returns A new JSON Pointer that is the concatenation of all tokens or
|
|
406
408
|
* "parts".
|
|
407
409
|
*/
|
|
@@ -1095,7 +1097,7 @@ var json_p3 = (function (exports) {
|
|
|
1095
1097
|
|
|
1096
1098
|
// These regular expressions are to be used with Lexer.acceptMatchRun(),
|
|
1097
1099
|
// which expects the sticky flag to be set.
|
|
1098
|
-
const exponentPattern = /e[+-]
|
|
1100
|
+
const exponentPattern = /e[+-]?\d+/y;
|
|
1099
1101
|
const functionNamePattern = /[a-z][a-z_0-9]*/y;
|
|
1100
1102
|
const indexPattern = /-?\d+/y;
|
|
1101
1103
|
const intPattern = /-?[0-9]+/y;
|
|
@@ -2809,7 +2811,7 @@ var json_p3 = (function (exports) {
|
|
|
2809
2811
|
apply: apply
|
|
2810
2812
|
});
|
|
2811
2813
|
|
|
2812
|
-
const version = "0.1.
|
|
2814
|
+
const version = "0.1.1";
|
|
2813
2815
|
|
|
2814
2816
|
exports.FunctionExpressionType = FunctionExpressionType;
|
|
2815
2817
|
exports.JSONPatch = JSONPatch;
|
package/dist/json-p3.iife.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var json_p3=function(e){"use strict";class t extends Error{constructor(e,t){super(e),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathError",this.message=n(e,t)}}function n(e,t){return t.input.length<=9?`${e} ('${t.input}':${t.index})`:t.index>t.input.length-5?`${e} ('${t.input.slice(t.input.length-9)}':${t.index})`:t.index-4<0?`${e} ('${t.input.slice(0,9)}':${t.index})`:`${e} ('${t.input.slice(t.index-4,t.index+5)}':${t.index})`}class r extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathLexerError",this.message=n(e,t)}}class s extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathTypeError",this.message=n(e,t)}}class i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}function h(e){return Array.isArray(e)}function c(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function l(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(!l(e[n],t[n]))return!1;return!0}return!1}if(c(e)&&c(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!l(e[r],t[r]))return!1;return!0}return!1}let f=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class d extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class g extends d{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class m extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class v extends d{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class O extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=Symbol.for("jsonpointer.undefined");class E{#e;constructor(e){this.tokens=this.parse(e),this.#e=E.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof g&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof m||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 v(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];throw new m(`index out of range '${E.encode(this.tokens.slice(0,n+1))}'`)}if(c(e)){if(Object.hasOwn(e,t))return e[t];throw new w(`no such property '${E.encode(this.tokens.slice(0,n+1))}'`)}throw new O(`found primitive value, expected an object '${E.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!u(e))throw new O("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new E(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new E(E.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof g)return!1;throw e}return!0}parent(){return this.tokens.length?new E(E.encode(this.tokens.slice(0,this.tokens.length-1))):this}}function N(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new E(e).resolve(t,n)}var k=Object.freeze({__proto__:null,JSONPointer:E,JSONPointerError:d,JSONPointerIndexError:m,JSONPointerKeyError:w,JSONPointerResolutionError:g,JSONPointerSyntaxError:v,JSONPointerTypeError:O,UNDEFINED:x,resolve:N});class y{constructor(e,t,n){this.value=e,this.location=t,this.root=n,this.path="$"+t.map((e=>u(e)?`['${e}']`:`[${e}]`)).join("")}toPointer(){return this.location.length?new E(E.encode(this.location.map(String))):new E("")}}class S{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 T=Symbol.for("jsonpath.nothing");class ${constructor(e){this.token=e}}class R extends ${}class b extends R{evaluate(){return null}toString(){return"null"}}class P extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class L extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class _ extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class I 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 S?0===t.nodes.length:!C(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class A 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 S&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return n instanceof S&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?C(t)&&C(n):"||"===this.operator?C(t)||C(n):function(e,t,n){switch(t){case"==":return U(e,n);case"!=":return!U(e,n);case"<":return D(e,n);case">":return D(n,e);case">=":return D(n,e)||U(e,n);case"<=":return D(e,n)||U(e,n);default:return!1}}(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 F extends ${constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof S?t.nodes.length>0:C(t)}toString(){return this.expression.toString()}}class j extends ${constructor(e,t){super(e),this.token=e,this.path=t}}class M extends j{evaluate(e){return this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class J extends j{evaluate(e){return this.path.query(e.rootValue)}toString(){return this.path.toString()}}class K extends ${constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.filterRegister.get(this.name);if(!t)throw new o(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==f.NodesType&&e instanceof S?e.valuesOrSingular():e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}}function C(e){return!(e instanceof S&&e.empty())&&!("boolean"==typeof e&&!1===e)}function U(e,t){if(t instanceof S&&([e,t]=[t,e]),e instanceof S){if(t instanceof S){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return l(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===T:1===e.nodes.length&&l(e.nodes[0].value,t)}return e===T&&t===T||l(e,t)}function D(e,t){return!!(u(e)&&u(t)||p(e)&&p(t))&&e<t}var G=Object.freeze({__proto__:null,BooleanLiteral:P,FilterExpression:$,FilterExpressionLiteral:R,FunctionExtension:K,InfixExpression:A,JSONPathQuery:j,LogicalExpression:F,NullLiteral:b,NumberLiteral:_,PrefixExpression:I,RelativeQuery:M,RootQuery:J,StringLiteral:L});class W{argTypes=[f.NodesType];returnType=f.ValueType;call(e){return e.length}}class Q{argTypes=[f.ValueType];returnType=f.ValueType;call(e){return h(e)||u(e)?e.length:c(e)?Object.keys(e).length:T}}class B 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 z{argTypes=[f.ValueType,f.ValueType];returnType=f.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 B(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 V{argTypes=[f.ValueType,f.ValueType];returnType=f.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 B(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 q{argTypes=[f.NodesType];returnType=f.ValueType;call(e){return 1===e.length?e.nodes[0].value:T}}let X=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 Z{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new Z(X.EOF,"",-1,"");class H{#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 Y=/e[+-]\d+/y,ee=/[a-z][a-z_0-9]*/y,te=/-?\d+/y,ne=/-?[0-9]+/y,re=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,se=new Set([" ","\n","\t","\r"]);class ie{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=ae;for(;e;)e=e(this)}emit(e){this.tokens.push(new Z(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 Z(X.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 Z(X.ERROR,e,this.pos,this.path))}return!!this.acceptRun(se)&&(this.ignore(),!0)}error(e){this.tokens.push(new Z(X.ERROR,e,this.#n,this.path))}}function oe(e){const[t,n]=function(e){const t=new ie(e);return[t,t.tokens]}(e);if(t.run(),n.length&&n[n.length-1].kind===X.ERROR)throw new a(n[n.length-1].value,n[n.length-1]);return n}function ae(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(X.ROOT),he)}function he(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(X.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(X.DDOT),ce):ue;case"[":return e.emit(X.LBRACKET),pe;default:return e.backup(),e.filterLevel?le:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ce(e){const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(X.WILD),he;case"[":return e.emit(X.LBRACKET),pe;default:return e.backup(),e.acceptMatchRun(re)?(e.emit(X.NAME),he):(e.error(`unexpected descendent selection token '${t}'`),null)}}function ue(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;const t=e.next();return"*"===t?(e.emit(X.WILD),he):(e.backup(),e.acceptMatchRun(re)?(e.emit(X.NAME),he):(e.error(`unexpected shorthand selector '${t}'`),null))}function pe(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"]":return e.emit(X.RBRACKET),e.filterLevel?le:he;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(X.WILD);continue;case"?":return e.emit(X.FILTER),e.filterLevel+=1,le;case",":e.emit(X.COMMA);continue;case":":e.emit(X.COLON);continue;case"'":return de;case'"':return ge;default:if(e.backup(),e.acceptMatchRun(te)){e.emit(X.INDEX);continue}return e.error(`unexpected token '${t}' in bracketed selection`),null}}}function le(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":case"]":return e.filterLevel-=1,e.backup(),pe;case",":if(e.emit(X.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,pe;case"'":return me;case'"':return we;case"(":e.emit(X.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(X.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(X.ROOT),he;case"@":return e.emit(X.CURRENT),he;case".":return e.backup(),he;case"!":"="===e.peek()?(e.next(),e.emit(X.NE)):e.emit(X.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(X.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(X.LE)):e.emit(X.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(X.GE)):e.emit(X.GT);continue;default:if(e.backup(),e.acceptMatchRun(ne)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ne)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(Y),e.emit(X.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(X.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(X.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(X.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(X.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(X.NULL);continue}if(e.acceptMatchRun(ee)&&"("===e.peek()){e.parenStack.push(1),e.emit(X.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function fe(e,t){return function(n){if(n.ignore(),n.peek()===e)return n.emit("'"===e?X.SINGLE_QUOTE_STRING:X.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?X.SINGLE_QUOTE_STRING:X.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t}else n.next()}}}const de=fe("'",pe),ge=fe('"',pe),me=fe("'",le),we=fe('"',le);class ve{constructor(e,t){this.environment=e,this.token=t}}class Oe extends ve{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 s of e)n=s.value,r=this.name,c(n)&&Object.hasOwn(n,r)&&t.push(new y(s.value[this.name],s.location.concat(this.name),s.root));var n,r;return new S(t)}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class xe extends ve{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.options.minIntIndex||n>this.environment.options.maxIntIndex)throw new i("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(h(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new y(n.value[e],n.location.concat(e),n.root))}return new S(t)}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Ee extends ve{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(h(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new y(r,n.location.concat(e),n.root));return new S(t)}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.options.minIntIndex||e>this.environment.options.maxIntIndex))throw new i("index out of range",this.token)}normalizedIndex(e,t){return t<0&&e>=Math.abs(t)?Math.min(e+t,e-1):Math.min(t,e-1)}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 i=t;i<n;i+=r)s.push([i,e[i]]);else for(let i=t;i>n;i+=r)s.push([i,e[i]]);return s}}class Ne extends ve{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(h(n.value))for(let e=0;e<n.value.length;e++)t.push(new y(n.value[e],n.location.concat(e),n.root));else if(c(n.value))for(const[e,r]of Object.entries(n.value))t.push(new y(r,n.location.concat(e),n.root));return new S(t)}toString(){return this.shorthand?"[*]":"*"}}class ke extends ve{resolve(e){const t=[];for(const n of e)t.push(n,...this.visit(n));return new S(t)}toString(){return".."}visit(e){const t=[];if(e.value instanceof String)return new S(t);if(h(e.value))for(let n=0;n<e.value.length;n++){const r=new y(e.value[n],e.location.concat(n),e.root);t.push(r,...this.visit(r))}else if(c(e.value))for(const[n,r]of Object.entries(e.value)){const s=new y(r,e.location.concat(n),e.root);t.push(s,...this.visit(s))}return new S(t)}}class ye extends ve{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(h(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 y(r,n.location.concat(e),n.root))}else if(c(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 y(r,n.location.concat(e),n.root))}return new S(t)}toString(){return`?${this.expression.toString()}`}}class Se extends ve{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)t.push(...e.resolve(new S([n])));return new S(t)}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}var Te=Object.freeze({__proto__:null,BracketedSelection:Se,FilterSelector:ye,IndexSelector:xe,JSONPathSelector:ve,NameSelector:Oe,RecursiveDescentSegment:ke,SliceSelector:Ee,WildcardSelector:Ne});class $e{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=new S([new y(e,[],e)]);for(const e of this.selectors)t=e.resolve(t);return t}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof Oe||e instanceof Se&&1===e.items.length&&(e.items[0]instanceof Oe||e.items[0]instanceof xe)))return!1;return!0}}const Re=new Map([[X.AND,4],[X.EQ,6],[X.GE,6],[X.GT,6],[X.LE,6],[X.LT,6],[X.NE,6],[X.NOT,3],[X.OR,5],[X.RPAREN,1]]),be=new Map([[X.AND,"&&"],[X.EQ,"=="],[X.GE,">="],[X.GT,">"],[X.LE,"<="],[X.LT,"<"],[X.NE,"!="],[X.OR,"||"]]),Pe=new Set(["==",">=",">","<=","<","!="]);class Le{constructor(e){this.environment=e,this.tokenMap=new Map([[X.FALSE,this.parseBoolean],[X.NUMBER,this.parseNumber],[X.LPAREN,this.parseGroupedExpression],[X.NOT,this.parsePrefixExpression],[X.NULL,this.parseNull],[X.ROOT,this.parseRootQuery],[X.CURRENT,this.parseRelativeQuery],[X.SINGLE_QUOTE_STRING,this.parseString],[X.DOUBLE_QUOTE_STRING,this.parseString],[X.TRUE,this.parseBoolean],[X.FUNCTION,this.parseFunction]])}parse(e){e.current.kind===X.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==X.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=[];e:for(;;){switch(e.current.kind){case X.NAME:n.push(new Oe(this.environment,e.current,e.current.value,!0));break;case X.WILD:n.push(new Ne(this.environment,e.current,!0));break;case X.DDOT:n.push(new ke(this.environment,e.current));break;case X.LBRACKET:n.push(this.parseBracketedSelection(e));break;default:t&&e.backup();break e}e.next()}return n}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 xe(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===X.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(X.COLON),e.next()):(n.push(void 0),e.expect(X.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===X.COLON&&e.next()):e.current.kind===X.COLON&&(n.push(void 0),e.expect(X.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Ee(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==X.RBRACKET;){switch(e.current.kind){case X.SINGLE_QUOTE_STRING:case X.DOUBLE_QUOTE_STRING:n.push(new Oe(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case X.FILTER:n.push(this.parseFilter(e));break;case X.INDEX:e.peek.kind===X.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case X.COLON:n.push(this.parseSlice(e));break;case X.WILD:n.push(new Ne(this.environment,e.current));break;case X.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!==X.RBRACKET&&(e.expectPeek(X.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Se(this.environment,t,n)}parseFilter(e){const t=e.next(),n=this.parseFilterExpression(e);if(n instanceof K){const e=this.environment.filterRegister.get(n.name);if(e&&e.returnType===f.ValueType)throw new s(`result of ${n.name}() must be compared`,n.token)}return new ye(this.environment,t,new F(t,n))}parseBoolean(e){return e.current.kind===X.FALSE?new P(e.current,!1):new P(e.current,!0)}parseNull(e){return new b(e.current)}parseString(e){return new L(e.current,this.decodeString(e.current))}parseNumber(e){return new _(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(X.NOT),e.next(),new I(e.current,"!",this.parseFilterExpression(e,3))}parseInfixExpression(e,t){const n=e.next(),r=Re.get(n.kind)||1,s=this.parseFilterExpression(e,r),i=be.get(n.kind);if(!i)throw new a(`unknown operator '${n.kind}'`,n);return this.throwForNonSingularQuery(t),this.throwForNonSingularQuery(s),Pe.has(i)&&(this.throwForNonComparableFunction(t),this.throwForNonComparableFunction(s)),new A(n,t,i,s)}parseGroupedExpression(e){e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==X.RPAREN;){if(e.current.kind===X.EOF)throw new a("unbalanced parentheses",e.current);t=this.parseInfixExpression(e,t)}return e.expect(X.RPAREN),t}parseRootQuery(e){const t=e.next();return new J(t,new $e(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new M(t,new $e(this.environment,this.parsePath(e,!0)))}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==X.RPAREN;){const n=this.tokenMap.get(e.current.kind);if(!n)throw new a(`unexpected '${e.current.value}'`,e.current);if(t.push(n.bind(this)(e)),e.peek.kind!==X.RPAREN){if(e.peek.kind===X.RBRACKET)break;e.expectPeek(X.COMMA),e.next()}e.next()}return new K(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 X.EOF:case X.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===X.EOF||n===X.RBRACKET||(Re.get(n)||1)<t)break;if(!be.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===X.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonSingularQuery(e){if((e instanceof J||e instanceof M)&&!e.path.singularQuery())throw new a("non-singular query is not comparable",e.token)}throwForNonComparableFunction(e){if(!(e instanceof K))return;const t=this.environment.filterRegister.get(e.name);if(t&&t.returnType!==f.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}const _e={strict:!0,maxIntIndex:Math.pow(2,53)-1,minIntIndex:-Math.pow(2,53)-1};class Ie{filterRegister=new Map;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:_e;this.options=e,this.parser=new Le(this),this.setupFilterFunctions()}compile(e){return new $e(this,this.parser.parse(new H(oe(e))))}query(e,t){return this.compile(e).query(t)}setupFilterFunctions(){this.filterRegister.set("count",new W),this.filterRegister.set("length",new Q),this.filterRegister.set("search",new V),this.filterRegister.set("match",new z),this.filterRegister.set("value",new q)}checkWellTypedness(e,t){const n=this.filterRegister.get(e.value);if(!n)throw new o(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,i,o]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case f.ValueType:if(!(i instanceof R||i instanceof j&&i.path.singularQuery()))throw new s(`${e.value}() argument ${o} must be of ValueType`,i.token);break;case f.LogicalType:if(!(i instanceof P))throw new s(`${e.value}() argument ${o} must be of LogicalType`,i.token);break;case f.NodesType:if(!(i instanceof j))throw new s(`${e.value}() argument ${o} must be of NodesType`,i.token)}return t}}var Ae=Object.freeze({__proto__:null,Count:W,FunctionExpressionType:f,Length:Q,Match:z,Search:V,Value:q});const Fe=new Ie;function je(e,t){return Fe.query(e,t)}function Me(e){return Fe.compile(e)}var Je=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:Fe,FunctionExpressionType:f,JSONPath:$e,JSONPathEnvironment:Ie,JSONPathError:t,JSONPathIndexError:i,JSONPathLexerError:r,JSONPathNode:y,JSONPathNodeList:S,JSONPathSyntaxError:a,JSONPathTypeError:s,Nothing:T,Token:Z,TokenKind:X,compile:Me,expressions:G,functions:Ae,query:je,selectors:Te});class Ke extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class Ce extends Ke{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class Ue{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 Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n))if(r===x){if("-"!==s)throw new Ke(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!c(n))throw new Ke(`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 De{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new Ke(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===x)throw new Ke(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!c(n))throw new Ke(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Ke(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class Ge{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 Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===x)throw new Ke(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!c(n))throw new Ke(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Ke(`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 We{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new Ke(`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 Ke(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);h(n)?n.splice(Number(s),1):c(n)&&delete n[s];const[i,o]=this.path.resolveWithParent(e);if(i===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(i))i.splice(Number(a),0,r);else{if(!c(i))throw new Ke(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);i[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class Qe{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 Ke(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const i=this.path.tokens.at(-1);if(void 0===i)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(s))s.splice(Number(i),0,this.deepCopy(r));else{if(!c(s))throw new Ke(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);s[i]=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 Be{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!l(r,this.value))throw new Ce(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ze{ops=[];constructor(e){e&&this.build(e)}add(e,t){return this.ops.push(new Ue(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new De(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new Ge(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new We(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Qe(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new Be(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof g)throw new Ke(`${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 Ke(`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 Ke(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!u(s))throw new Ke(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new E(s)}catch(e){if(e instanceof d)throw new Ke(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new Ke(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof E)return e;if(!u(e))throw new Ke(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new E(e)}catch(e){if(e instanceof d)throw new Ke(`${e.message} (${t}:${n})`);throw e}}}function Ve(e,t){return new ze(e).apply(t)}var qe=Object.freeze({__proto__:null,JSONPatch:ze,JSONPatchError:Ke,JSONPatchTestFailure:Ce,apply:Ve});return e.FunctionExpressionType=f,e.JSONPatch=ze,e.JSONPatchError=Ke,e.JSONPatchTestFailure=Ce,e.JSONPath=$e,e.JSONPathEnvironment=Ie,e.JSONPathError=t,e.JSONPathIndexError=i,e.JSONPathLexerError=r,e.JSONPathNode=y,e.JSONPathNodeList=S,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=E,e.Nothing=T,e.Token=Z,e.TokenKind=X,e.UNDEFINED=x,e.apply=Ve,e.compile=Me,e.jsonpatch=qe,e.jsonpath=Je,e.jsonpointer=k,e.query=je,e.resolve=N,e.version="0.1.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 i extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathIndexError",this.message=n(e,t)}}class o extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="UndefinedFilterFunctionError",this.message=n(e,t)}}class a extends t{constructor(e,t){super(e,t),this.message=e,this.token=t,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPathSyntaxError",this.message=n(e,t)}}function h(e){return Array.isArray(e)}function c(e){const t=typeof e;return null!==e&&"object"===t||"function"===t}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function l(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(!l(e[n],t[n]))return!1;return!0}return!1}if(c(e)&&c(t)){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n)if(!l(e[r],t[r]))return!1;return!0}return!1}let f=function(e){return e.ValueType="ValueType",e.LogicalType="LogicalType",e.NodesType="NodesType",e}({});class d extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerError"}}class g extends d{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerResolutionError"}}class m extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerIndexError"}}class w extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerKeyError"}}class v extends d{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerSyntaxError"}}class O extends g{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPointerTypeError"}}const x=Symbol.for("jsonpointer.undefined");class E{#e;constructor(e){this.tokens=this.parse(e),this.#e=E.encode(this.tokens)}static encode(e){return e.length?"/"+e.map((e=>e.replaceAll("~","~0").replaceAll("/","~1"))).join("/"):""}resolve(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x;try{return this.tokens.reduce(this.getItem.bind(this),e)}catch(e){if(e instanceof g&&t!==x)return t;throw e}}resolveWithParent(e){if(!this.tokens.length)return[x,this.resolve(e)];const t=this.tokens.slice(0,this.tokens.length-1).reduce(this.getItem.bind(this),e);try{return[t,this.getItem(t,this.tokens[this.tokens.length-1],this.tokens.length-1)]}catch(e){if(e instanceof m||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 v(`"${e}" pointers must start with a slash or be the empty string`);return e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))).slice(1)}getItem(e,t,n){if(h(e)){if("length"!==t&&Object.hasOwn(e,t))return e[Number(t)];throw new m(`index out of range '${E.encode(this.tokens.slice(0,n+1))}'`)}if(c(e)){if(Object.hasOwn(e,t))return e[t];throw new w(`no such property '${E.encode(this.tokens.slice(0,n+1))}'`)}throw new O(`found primitive value, expected an object '${E.encode(this.tokens.slice(0,n+1))}'`)}_join(e){if(!u(e))throw new O("join() requires string arguments, found "+typeof e);if(e.startsWith("/"))return new E(e);const t=this.tokens.concat(e.split("/").map((e=>e.replaceAll("~1","/").replaceAll("~0","~"))));return new E(E.encode(t))}join(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.length)return this;let r=this;for(const e of t)r=r._join(e);return r}exists(e){try{this.resolve(e)}catch(e){if(e instanceof g)return!1;throw e}return!0}parent(){return this.tokens.length?new E(E.encode(this.tokens.slice(0,this.tokens.length-1))):this}}function N(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:x;return new E(e).resolve(t,n)}var k=Object.freeze({__proto__:null,JSONPointer:E,JSONPointerError:d,JSONPointerIndexError:m,JSONPointerKeyError:w,JSONPointerResolutionError:g,JSONPointerSyntaxError:v,JSONPointerTypeError:O,UNDEFINED:x,resolve:N});class y{constructor(e,t,n){this.value=e,this.location=t,this.root=n,this.path="$"+t.map((e=>u(e)?`['${e}']`:`[${e}]`)).join("")}toPointer(){return this.location.length?new E(E.encode(this.location.map(String))):new E("")}}class S{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 T=Symbol.for("jsonpath.nothing");class ${constructor(e){this.token=e}}class R extends ${}class b extends R{evaluate(){return null}toString(){return"null"}}class P extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class L extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return JSON.stringify(this.value)}}class _ extends R{constructor(e,t){super(e),this.token=e,this.value=t}evaluate(){return this.value}toString(){return String(this.value)}}class I 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 S?0===t.nodes.length:!C(t)}throw new s(`unknown operator '${this.operator}'`,this.token)}toString(){return`${this.operator}${this.right.toString()}`}}class A 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 S&&1===t.nodes.length&&(t=t.nodes[0].value);let n=this.right.evaluate(e);return n instanceof S&&1===n.nodes.length&&(n=n.nodes[0].value),"&&"===this.operator?C(t)&&C(n):"||"===this.operator?C(t)||C(n):function(e,t,n){switch(t){case"==":return U(e,n);case"!=":return!U(e,n);case"<":return D(e,n);case">":return D(n,e);case">=":return D(n,e)||U(e,n);case"<=":return D(e,n)||U(e,n);default:return!1}}(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 F extends ${constructor(e,t){super(e),this.token=e,this.expression=t}evaluate(e){const t=this.expression.evaluate(e);return t instanceof S?t.nodes.length>0:C(t)}toString(){return this.expression.toString()}}class j extends ${constructor(e,t){super(e),this.token=e,this.path=t}}class M extends j{evaluate(e){return this.path.query(e.currentValue)}toString(){return`@${this.path.toString().slice(1)}`}}class J extends j{evaluate(e){return this.path.query(e.rootValue)}toString(){return this.path.toString()}}class K extends ${constructor(e,t,n){super(e),this.token=e,this.name=t,this.args=n}evaluate(e){const t=e.environment.filterRegister.get(this.name);if(!t)throw new o(`filter function '${this.name}' is undefined`,this.token);const n=this.args.map((t=>t.evaluate(e))).map(((e,n)=>t.argTypes[n]!==f.NodesType&&e instanceof S?e.valuesOrSingular():e));return t.call(...n)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}}function C(e){return!(e instanceof S&&e.empty())&&!("boolean"==typeof e&&!1===e)}function U(e,t){if(t instanceof S&&([e,t]=[t,e]),e instanceof S){if(t instanceof S){if(e.empty()&&t.empty())return!0;if(1===e.nodes.length&&1===t.nodes.length)return l(e.nodes[0].value,t.nodes[0].value)}return e.empty()?t===T:1===e.nodes.length&&l(e.nodes[0].value,t)}return e===T&&t===T||l(e,t)}function D(e,t){return!!(u(e)&&u(t)||p(e)&&p(t))&&e<t}var G=Object.freeze({__proto__:null,BooleanLiteral:P,FilterExpression:$,FilterExpressionLiteral:R,FunctionExtension:K,InfixExpression:A,JSONPathQuery:j,LogicalExpression:F,NullLiteral:b,NumberLiteral:_,PrefixExpression:I,RelativeQuery:M,RootQuery:J,StringLiteral:L});class W{argTypes=[f.NodesType];returnType=f.ValueType;call(e){return e.length}}class Q{argTypes=[f.ValueType];returnType=f.ValueType;call(e){return h(e)||u(e)?e.length:c(e)?Object.keys(e).length:T}}class B 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 z{argTypes=[f.ValueType,f.ValueType];returnType=f.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 B(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 V{argTypes=[f.ValueType,f.ValueType];returnType=f.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 B(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 q{argTypes=[f.NodesType];returnType=f.ValueType;call(e){return 1===e.length?e.nodes[0].value:T}}let X=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 Z{constructor(e,t,n,r){this.kind=e,this.value=t,this.index=n,this.input=r}}new Z(X.EOF,"",-1,"");class H{#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 Y=/e[+-]?\d+/y,ee=/[a-z][a-z_0-9]*/y,te=/-?\d+/y,ne=/-?[0-9]+/y,re=/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y,se=new Set([" ","\n","\t","\r"]);class ie{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=ae;for(;e;)e=e(this)}emit(e){this.tokens.push(new Z(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 Z(X.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 Z(X.ERROR,e,this.pos,this.path))}return!!this.acceptRun(se)&&(this.ignore(),!0)}error(e){this.tokens.push(new Z(X.ERROR,e,this.#n,this.path))}}function oe(e){const[t,n]=function(e){const t=new ie(e);return[t,t.tokens]}(e);if(t.run(),n.length&&n[n.length-1].kind===X.ERROR)throw new a(n[n.length-1].value,n[n.length-1]);return n}function ae(e){const t=e.next();return"$"!==t?(e.backup(),e.error(`expected '$', found '${t}'`),null):(e.emit(X.ROOT),he)}function he(e){e.ignoreWhitespace()&&!e.peek()&&e.error("trailing whitespace");const t=e.next();switch(t){case"":return e.emit(X.EOF),null;case".":return"."===e.peek()?(e.next(),e.emit(X.DDOT),ce):ue;case"[":return e.emit(X.LBRACKET),pe;default:return e.backup(),e.filterLevel?le:(e.error(`expected '.', '..' or a bracketed selection, found '${t}'`),null)}}function ce(e){const t=e.next();switch(t){case"":return e.error("bald descendant segment"),null;case"*":return e.emit(X.WILD),he;case"[":return e.emit(X.LBRACKET),pe;default:return e.backup(),e.acceptMatchRun(re)?(e.emit(X.NAME),he):(e.error(`unexpected descendent selection token '${t}'`),null)}}function ue(e){if(e.ignore(),e.ignoreWhitespace())return e.error("unexpected whitespace after dot"),null;const t=e.next();return"*"===t?(e.emit(X.WILD),he):(e.backup(),e.acceptMatchRun(re)?(e.emit(X.NAME),he):(e.error(`unexpected shorthand selector '${t}'`),null))}function pe(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"]":return e.emit(X.RBRACKET),e.filterLevel?le:he;case"":return e.error("unclosed bracketed selection"),null;case"*":e.emit(X.WILD);continue;case"?":return e.emit(X.FILTER),e.filterLevel+=1,le;case",":e.emit(X.COMMA);continue;case":":e.emit(X.COLON);continue;case"'":return de;case'"':return ge;default:if(e.backup(),e.acceptMatchRun(te)){e.emit(X.INDEX);continue}return e.error(`unexpected token '${t}' in bracketed selection`),null}}}function le(e){for(;;){e.ignoreWhitespace();const t=e.next();switch(t){case"":case"]":return e.filterLevel-=1,e.backup(),pe;case",":if(e.emit(X.COMMA),e.parenStack.length)continue;return e.filterLevel-=1,pe;case"'":return me;case'"':return we;case"(":e.emit(X.LPAREN),e.parenStack.length&&(e.parenStack[e.parenStack.length-1]+=1);continue;case")":e.emit(X.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(X.ROOT),he;case"@":return e.emit(X.CURRENT),he;case".":return e.backup(),he;case"!":"="===e.peek()?(e.next(),e.emit(X.NE)):e.emit(X.NOT);continue;case"=":if("="===e.peek()){e.next(),e.emit(X.EQ);continue}return e.backup(),e.error(`unexpected filter selector token '${t}'`),null;case"<":"="===e.peek()?(e.next(),e.emit(X.LE)):e.emit(X.LT);continue;case">":"="===e.peek()?(e.next(),e.emit(X.GE)):e.emit(X.GT);continue;default:if(e.backup(),e.acceptMatchRun(ne)){if("."===e.peek()&&(e.next(),!e.acceptMatchRun(ne)))return e.error("a fractional digit is required after a decimal point"),null;e.acceptMatchRun(Y),e.emit(X.NUMBER);continue}if(e.acceptMatchRun(/&&/y)){e.emit(X.AND);continue}if(e.acceptMatchRun(/\|\|/y)){e.emit(X.OR);continue}if(e.acceptMatchRun(/true/y)){e.emit(X.TRUE);continue}if(e.acceptMatchRun(/false/y)){e.emit(X.FALSE);continue}if(e.acceptMatchRun(/null/y)){e.emit(X.NULL);continue}if(e.acceptMatchRun(ee)&&"("===e.peek()){e.parenStack.push(1),e.emit(X.FUNCTION),e.next(),e.ignore();continue}}return e.error(`unexpected filter selector token '${t}'`),null}}function fe(e,t){return function(n){if(n.ignore(),n.peek()===e)return n.emit("'"===e?X.SINGLE_QUOTE_STRING:X.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?X.SINGLE_QUOTE_STRING:X.DOUBLE_QUOTE_STRING),n.next(),n.ignore(),t}else n.next()}}}const de=fe("'",pe),ge=fe('"',pe),me=fe("'",le),we=fe('"',le);class ve{constructor(e,t){this.environment=e,this.token=t}}class Oe extends ve{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 s of e)n=s.value,r=this.name,c(n)&&Object.hasOwn(n,r)&&t.push(new y(s.value[this.name],s.location.concat(this.name),s.root));var n,r;return new S(t)}toString(){return this.shorthand?`['${this.name}']`:`'${this.name}'`}}class xe extends ve{constructor(e,t,n){if(super(e,t),this.environment=e,this.token=t,this.index=n,n<this.environment.options.minIntIndex||n>this.environment.options.maxIntIndex)throw new i("index out of range",this.token)}resolve(e){const t=[];for(const n of e)if(h(n.value)){const e=this.normalizedIndex(n.value.length);e in n.value&&t.push(new y(n.value[e],n.location.concat(e),n.root))}return new S(t)}toString(){return String(this.index)}normalizedIndex(e){return this.index<0&&e>=Math.abs(this.index)?e+this.index:this.index}}class Ee extends ve{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(h(n.value))for(const[e,r]of this.slice(n.value,this.start,this.stop,this.step))t.push(new y(r,n.location.concat(e),n.root));return new S(t)}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.options.minIntIndex||e>this.environment.options.maxIntIndex))throw new i("index out of range",this.token)}normalizedIndex(e,t){return t<0&&e>=Math.abs(t)?Math.min(e+t,e-1):Math.min(t,e-1)}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 i=t;i<n;i+=r)s.push([i,e[i]]);else for(let i=t;i>n;i+=r)s.push([i,e[i]]);return s}}class Ne extends ve{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(h(n.value))for(let e=0;e<n.value.length;e++)t.push(new y(n.value[e],n.location.concat(e),n.root));else if(c(n.value))for(const[e,r]of Object.entries(n.value))t.push(new y(r,n.location.concat(e),n.root));return new S(t)}toString(){return this.shorthand?"[*]":"*"}}class ke extends ve{resolve(e){const t=[];for(const n of e)t.push(n,...this.visit(n));return new S(t)}toString(){return".."}visit(e){const t=[];if(e.value instanceof String)return new S(t);if(h(e.value))for(let n=0;n<e.value.length;n++){const r=new y(e.value[n],e.location.concat(n),e.root);t.push(r,...this.visit(r))}else if(c(e.value))for(const[n,r]of Object.entries(e.value)){const s=new y(r,e.location.concat(n),e.root);t.push(s,...this.visit(s))}return new S(t)}}class ye extends ve{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(h(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 y(r,n.location.concat(e),n.root))}else if(c(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 y(r,n.location.concat(e),n.root))}return new S(t)}toString(){return`?${this.expression.toString()}`}}class Se extends ve{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)t.push(...e.resolve(new S([n])));return new S(t)}toString(){return`[${this.items.map((e=>e.toString())).join(", ")}]`}}var Te=Object.freeze({__proto__:null,BracketedSelection:Se,FilterSelector:ye,IndexSelector:xe,JSONPathSelector:ve,NameSelector:Oe,RecursiveDescentSegment:ke,SliceSelector:Ee,WildcardSelector:Ne});class $e{constructor(e,t){this.environment=e,this.selectors=t}query(e){let t=new S([new y(e,[],e)]);for(const e of this.selectors)t=e.resolve(t);return t}toString(){return`$${this.selectors.map((e=>e.toString())).join("")}`}singularQuery(){for(const e of this.selectors)if(!(e instanceof Oe||e instanceof Se&&1===e.items.length&&(e.items[0]instanceof Oe||e.items[0]instanceof xe)))return!1;return!0}}const Re=new Map([[X.AND,4],[X.EQ,6],[X.GE,6],[X.GT,6],[X.LE,6],[X.LT,6],[X.NE,6],[X.NOT,3],[X.OR,5],[X.RPAREN,1]]),be=new Map([[X.AND,"&&"],[X.EQ,"=="],[X.GE,">="],[X.GT,">"],[X.LE,"<="],[X.LT,"<"],[X.NE,"!="],[X.OR,"||"]]),Pe=new Set(["==",">=",">","<=","<","!="]);class Le{constructor(e){this.environment=e,this.tokenMap=new Map([[X.FALSE,this.parseBoolean],[X.NUMBER,this.parseNumber],[X.LPAREN,this.parseGroupedExpression],[X.NOT,this.parsePrefixExpression],[X.NULL,this.parseNull],[X.ROOT,this.parseRootQuery],[X.CURRENT,this.parseRelativeQuery],[X.SINGLE_QUOTE_STRING,this.parseString],[X.DOUBLE_QUOTE_STRING,this.parseString],[X.TRUE,this.parseBoolean],[X.FUNCTION,this.parseFunction]])}parse(e){e.current.kind===X.ROOT&&e.next();const t=this.parsePath(e);if(e.current.kind!==X.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=[];e:for(;;){switch(e.current.kind){case X.NAME:n.push(new Oe(this.environment,e.current,e.current.value,!0));break;case X.WILD:n.push(new Ne(this.environment,e.current,!0));break;case X.DDOT:n.push(new ke(this.environment,e.current));break;case X.LBRACKET:n.push(this.parseBracketedSelection(e));break;default:t&&e.backup();break e}e.next()}return n}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 xe(this.environment,e.current,Number(e.current.value))}parseSlice(e){const t=e.current,n=[];function r(e){if(e.kind===X.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(X.COLON),e.next()):(n.push(void 0),e.expect(X.COLON),e.next()),r(e.current)?(n.push(Number(e.current.value)),e.next(),e.current.kind===X.COLON&&e.next()):e.current.kind===X.COLON&&(n.push(void 0),e.expect(X.COLON),e.next()),r(e.current)&&(n.push(Number(e.current.value)),e.next()),e.backup(),new Ee(this.environment,t,...n)}parseBracketedSelection(e){const t=e.next(),n=[];for(;e.current.kind!==X.RBRACKET;){switch(e.current.kind){case X.SINGLE_QUOTE_STRING:case X.DOUBLE_QUOTE_STRING:n.push(new Oe(this.environment,e.current,this.decodeString(e.current,!0),!1));break;case X.FILTER:n.push(this.parseFilter(e));break;case X.INDEX:e.peek.kind===X.COLON?n.push(this.parseSlice(e)):n.push(this.parseIndex(e));break;case X.COLON:n.push(this.parseSlice(e));break;case X.WILD:n.push(new Ne(this.environment,e.current));break;case X.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!==X.RBRACKET&&(e.expectPeek(X.COMMA),e.next()),e.next()}if(!n.length)throw new a("empty bracketed segment",t);return new Se(this.environment,t,n)}parseFilter(e){const t=e.next(),n=this.parseFilterExpression(e);if(n instanceof K){const e=this.environment.filterRegister.get(n.name);if(e&&e.returnType===f.ValueType)throw new s(`result of ${n.name}() must be compared`,n.token)}return new ye(this.environment,t,new F(t,n))}parseBoolean(e){return e.current.kind===X.FALSE?new P(e.current,!1):new P(e.current,!0)}parseNull(e){return new b(e.current)}parseString(e){return new L(e.current,this.decodeString(e.current))}parseNumber(e){return new _(e.current,Number(e.current.value))}parsePrefixExpression(e){return e.expect(X.NOT),e.next(),new I(e.current,"!",this.parseFilterExpression(e,3))}parseInfixExpression(e,t){const n=e.next(),r=Re.get(n.kind)||1,s=this.parseFilterExpression(e,r),i=be.get(n.kind);if(!i)throw new a(`unknown operator '${n.kind}'`,n);return this.throwForNonSingularQuery(t),this.throwForNonSingularQuery(s),Pe.has(i)&&(this.throwForNonComparableFunction(t),this.throwForNonComparableFunction(s)),new A(n,t,i,s)}parseGroupedExpression(e){e.next();let t=this.parseFilterExpression(e);for(e.next();e.current.kind!==X.RPAREN;){if(e.current.kind===X.EOF)throw new a("unbalanced parentheses",e.current);t=this.parseInfixExpression(e,t)}return e.expect(X.RPAREN),t}parseRootQuery(e){const t=e.next();return new J(t,new $e(this.environment,this.parsePath(e,!0)))}parseRelativeQuery(e){const t=e.next();return new M(t,new $e(this.environment,this.parsePath(e,!0)))}parseFunction(e){const t=[],n=e.next();for(;e.current.kind!==X.RPAREN;){const n=this.tokenMap.get(e.current.kind);if(!n)throw new a(`unexpected '${e.current.value}'`,e.current);if(t.push(n.bind(this)(e)),e.peek.kind!==X.RPAREN){if(e.peek.kind===X.RBRACKET)break;e.expectPeek(X.COMMA),e.next()}e.next()}return new K(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 X.EOF:case X.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===X.EOF||n===X.RBRACKET||(Re.get(n)||1)<t)break;if(!be.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===X.SINGLE_QUOTE_STRING?`"${e.value.replaceAll('"','\\"').replaceAll("\\'","'")}"`:`"${e.value}"`)}catch{throw new a(`invalid ${t?"name selector":"string literal"} '${e.value}'`,e)}}throwForNonSingularQuery(e){if((e instanceof J||e instanceof M)&&!e.path.singularQuery())throw new a("non-singular query is not comparable",e.token)}throwForNonComparableFunction(e){if(!(e instanceof K))return;const t=this.environment.filterRegister.get(e.name);if(t&&t.returnType!==f.ValueType)throw new s(`result of ${e.name}() is not comparable`,e.token)}}const _e={strict:!0,maxIntIndex:Math.pow(2,53)-1,minIntIndex:-Math.pow(2,53)-1};class Ie{filterRegister=new Map;constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:_e;this.options=e,this.parser=new Le(this),this.setupFilterFunctions()}compile(e){return new $e(this,this.parser.parse(new H(oe(e))))}query(e,t){return this.compile(e).query(t)}setupFilterFunctions(){this.filterRegister.set("count",new W),this.filterRegister.set("length",new Q),this.filterRegister.set("search",new V),this.filterRegister.set("match",new z),this.filterRegister.set("value",new q)}checkWellTypedness(e,t){const n=this.filterRegister.get(e.value);if(!n)throw new o(`no such function '${e.value}'`,e);if(t.length!==n.argTypes.length)throw new s(`${e.value}() takes ${n.argTypes.length} argument${1===n.argTypes.length?"":"s"}, ${t.length} given`,e);for(const[r,i,o]of n.argTypes.map(((e,n)=>[e,t[n],n])))switch(r){case f.ValueType:if(!(i instanceof R||i instanceof j&&i.path.singularQuery()))throw new s(`${e.value}() argument ${o} must be of ValueType`,i.token);break;case f.LogicalType:if(!(i instanceof P))throw new s(`${e.value}() argument ${o} must be of LogicalType`,i.token);break;case f.NodesType:if(!(i instanceof j))throw new s(`${e.value}() argument ${o} must be of NodesType`,i.token)}return t}}var Ae=Object.freeze({__proto__:null,Count:W,FunctionExpressionType:f,Length:Q,Match:z,Search:V,Value:q});const Fe=new Ie;function je(e,t){return Fe.query(e,t)}function Me(e){return Fe.compile(e)}var Je=Object.freeze({__proto__:null,DEFAULT_ENVIRONMENT:Fe,FunctionExpressionType:f,JSONPath:$e,JSONPathEnvironment:Ie,JSONPathError:t,JSONPathIndexError:i,JSONPathLexerError:r,JSONPathNode:y,JSONPathNodeList:S,JSONPathSyntaxError:a,JSONPathTypeError:s,Nothing:T,Token:Z,TokenKind:X,compile:Me,expressions:G,functions:Ae,query:je,selectors:Te});class Ke extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchError"}}class Ce extends Ke{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name="JSONPatchTestFailure"}}class Ue{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 Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n))if(r===x){if("-"!==s)throw new Ke(`index out of range (${this.name}:${t})`);n.push(this.value)}else n.splice(Number(s),0,this.value);else{if(!c(n))throw new Ke(`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 De{name="remove";constructor(e){this.path=e}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(n===x)throw new Ke(`can't remove root (${this.name}:${t})`);const s=this.path.tokens.at(-1);if(void 0===s)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===x)throw new Ke(`can't remove nonexistent item (${this.name}:${t})`);n.splice(Number(s),1)}else{if(!c(n))throw new Ke(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Ke(`can't remove nonexistent property (${this.name}:${t})`);delete n[s]}return e}toObject(){return{op:this.name,path:this.path.toString()}}}class Ge{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 Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(n)){if(r===x)throw new Ke(`can't replace nonexistent item (${this.name}:${t})`);n.splice(Number(s),1,this.value)}else{if(!c(n))throw new Ke(`unexpected operation on '${typeof n}' (${this.name}:${t})`);if(r===x)throw new Ke(`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 We{name="move";constructor(e,t){this.from=e,this.path=t}apply(e,t){if(this.path.isRelativeTo(this.from))throw new Ke(`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 Ke(`source object does not exist (${this.name}:${t})`);const s=this.from.tokens.at(-1);if(void 0===s)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);h(n)?n.splice(Number(s),1):c(n)&&delete n[s];const[i,o]=this.path.resolveWithParent(e);if(i===x)return r;const a=this.path.tokens.at(-1);if(void 0===a)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(i))i.splice(Number(a),0,r);else{if(!c(i))throw new Ke(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);i[a]=r}return e}toObject(){return{op:this.name,from:this.from.toString(),path:this.path.toString()}}}class Qe{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 Ke(`source object does not exist (${this.name}:${t})`);const[s]=this.path.resolveWithParent(e);if(s===x)return this.deepCopy(r);const i=this.path.tokens.at(-1);if(void 0===i)throw new Ke(`unexpected operation on 'undefined' (${this.name}:${t})`);if(h(s))s.splice(Number(i),0,this.deepCopy(r));else{if(!c(s))throw new Ke(`unexpected operation on '${typeof parent}' (${this.name}:${t})`);s[i]=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 Be{name="test";constructor(e,t){this.path=e,this.value=t}apply(e,t){const[n,r]=this.path.resolveWithParent(e);if(!l(r,this.value))throw new Ce(`test failed (${this.name}:${t})`);return e}toObject(){return{op:this.name,path:this.path.toString(),value:this.value}}}class ze{ops=[];constructor(e){e&&this.build(e)}add(e,t){return this.ops.push(new Ue(this.ensurePointer(e,"add",this.ops.length),t)),this}remove(e){return this.ops.push(new De(this.ensurePointer(e,"remove",this.ops.length))),this}replace(e,t){return this.ops.push(new Ge(this.ensurePointer(e,"replace",this.ops.length),t)),this}move(e,t){return this.ops.push(new We(this.ensurePointer(e,"move",this.ops.length),this.ensurePointer(t,"move",this.ops.length))),this}copy(e,t){return this.ops.push(new Qe(this.ensurePointer(e,"copy",this.ops.length),this.ensurePointer(t,"copy",this.ops.length))),this}test(e,t){return this.ops.push(new Be(this.ensurePointer(e,"test",this.ops.length),t)),this}apply(e){let t=e;for(let e=0;e<this.ops.length;e++){const n=this.ops[e];try{t=n.apply(t,e)}catch(t){if(t instanceof g)throw new Ke(`${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 Ke(`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 Ke(`missing property '${t}' (${n}:${r})`);const s=e[t];if(!u(s))throw new Ke(`expected a JSON Pointer string for '${t}', found ${typeof s} (${n}:${r})`);try{return new E(s)}catch(e){if(e instanceof d)throw new Ke(`${e.message} (${n}:${r})`);throw e}}opValue(e,t,n,r){if(!Object.hasOwn(e,t))throw new Ke(`missing property '${t}' (${n}:${r})`);return e[t]}ensurePointer(e,t,n){if(e instanceof E)return e;if(!u(e))throw new Ke(`expected a JSON Pointer string, found ${typeof e} (${t}:${n})`);try{return new E(e)}catch(e){if(e instanceof d)throw new Ke(`${e.message} (${t}:${n})`);throw e}}}function Ve(e,t){return new ze(e).apply(t)}var qe=Object.freeze({__proto__:null,JSONPatch:ze,JSONPatchError:Ke,JSONPatchTestFailure:Ce,apply:Ve});return e.FunctionExpressionType=f,e.JSONPatch=ze,e.JSONPatchError=Ke,e.JSONPatchTestFailure=Ce,e.JSONPath=$e,e.JSONPathEnvironment=Ie,e.JSONPathError=t,e.JSONPathIndexError=i,e.JSONPathLexerError=r,e.JSONPathNode=y,e.JSONPathNodeList=S,e.JSONPathSyntaxError=a,e.JSONPathTypeError=s,e.JSONPointer=E,e.Nothing=T,e.Token=Z,e.TokenKind=X,e.UNDEFINED=x,e.apply=Ve,e.compile=Me,e.jsonpatch=qe,e.jsonpath=Je,e.jsonpointer=k,e.query=je,e.resolve=N,e.version="0.1.1",e}({});
|
|
2
2
|
//# sourceMappingURL=json-p3.iife.min.js.map
|