@swaggerexpert/jsonpath 3.0.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -4
- package/SECURITY.md +3 -1
- package/package.json +22 -14
- package/types/index.d.ts +5 -3
- package/cjs/apg-lite.cjs +0 -1221
- package/cjs/errors/JSONPathError.cjs +0 -44
- package/cjs/errors/JSONPathParseError.cjs +0 -8
- package/cjs/grammar.cjs +0 -2839
- package/cjs/index.cjs +0 -19
- package/cjs/parse/callbacks/cst.cjs +0 -49
- package/cjs/parse/index.cjs +0 -40
- package/cjs/parse/translators/ASTTranslator/decoders.cjs +0 -16
- package/cjs/parse/translators/ASTTranslator/index.cjs +0 -16
- package/cjs/parse/translators/ASTTranslator/transformers.cjs +0 -410
- package/cjs/parse/translators/CSTOptimizedTranslator.cjs +0 -39
- package/cjs/parse/translators/CSTTranslator.cjs +0 -118
- package/cjs/parse/translators/XMLTranslator.cjs +0 -12
- package/cjs/test/index.cjs +0 -25
- package/es/errors/JSONPathError.mjs +0 -40
- package/es/errors/JSONPathParseError.mjs +0 -3
- package/es/grammar.mjs +0 -2835
- package/es/index.mjs +0 -7
- package/es/parse/callbacks/cst.mjs +0 -44
- package/es/parse/index.mjs +0 -35
- package/es/parse/translators/ASTTranslator/decoders.mjs +0 -9
- package/es/parse/translators/ASTTranslator/index.mjs +0 -9
- package/es/parse/translators/ASTTranslator/transformers.mjs +0 -404
- package/es/parse/translators/CSTOptimizedTranslator.mjs +0 -34
- package/es/parse/translators/CSTTranslator.mjs +0 -113
- package/es/parse/translators/XMLTranslator.mjs +0 -7
- package/es/test/index.mjs +0 -20
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ The development of this library contributed to the identification and formal sub
|
|
|
43
43
|
- [Statistics](#statistics)
|
|
44
44
|
- [Tracing](#tracing)
|
|
45
45
|
- [Validation](#validation)
|
|
46
|
+
- [Compilation](#compilation)
|
|
47
|
+
- [Escaping](#escaping)
|
|
46
48
|
- [Errors](#errors)
|
|
47
49
|
- [Grammar](#grammar)
|
|
48
50
|
- [More about JSONPath](#more-about-jsonpath)
|
|
@@ -200,10 +202,11 @@ const { result, trace } = parse('$fdfadfd', { trace: true });
|
|
|
200
202
|
|
|
201
203
|
result.success; // returns false
|
|
202
204
|
trace.displayTrace(); // returns trace information
|
|
205
|
+
trace.inferExpectations(); // returns parser expectations
|
|
203
206
|
```
|
|
204
207
|
|
|
205
|
-
By combining information from `result` and `trace`,
|
|
206
|
-
and generate
|
|
208
|
+
By combining information from `result` and `trace`, you can analyze the parsing process in detail
|
|
209
|
+
and generate messages like: `'Syntax error at position 1, expected "[", ".", ".."'`. Please see this
|
|
207
210
|
[test file](https://github.com/swaggerexpert/jsonpath/blob/main/test/parse/trace.js) for more information how to achieve that.
|
|
208
211
|
|
|
209
212
|
#### Validation
|
|
@@ -226,13 +229,39 @@ test("$['a']", { normalized: true }); // => true
|
|
|
226
229
|
test('$.store.book[0].title', { normalized: true }); // => false
|
|
227
230
|
```
|
|
228
231
|
|
|
232
|
+
#### Compilation
|
|
233
|
+
|
|
234
|
+
Compilation is the process of transforming a list of selectors into a [Normalized Path](https://www.rfc-editor.org/rfc/rfc9535#name-normalized-paths).
|
|
235
|
+
During compilation, name selectors are automatically escaped before being compiled.
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
import { compile } from '@swaggerexpert/jsonpath';
|
|
239
|
+
|
|
240
|
+
compile(['store', 'book', 0, 'title']); // => "$['store']['book'][0]['title']"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### Escaping
|
|
244
|
+
|
|
245
|
+
Certain characters within name selectors in Normalized Paths require escaping.
|
|
246
|
+
The apostrophe (`'`) and backslash (`\`) characters must be escaped.
|
|
247
|
+
Control characters (U+0000 through U+001F) are escaped using specific escape sequences
|
|
248
|
+
(`\b`, `\t`, `\n`, `\f`, `\r`) or Unicode escape sequences (`\uXXXX`).
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
import { escape } from '@swaggerexpert/jsonpath';
|
|
252
|
+
|
|
253
|
+
escape("it's"); // => "it\\'s"
|
|
254
|
+
escape('back\\slash'); // => "back\\\\slash"
|
|
255
|
+
escape('line\nfeed'); // => "line\\nfeed"
|
|
256
|
+
```
|
|
257
|
+
|
|
229
258
|
#### Errors
|
|
230
259
|
|
|
231
260
|
`@swaggerexpert/jsonpath` provides a structured error class hierarchy,
|
|
232
|
-
enabling precise error handling across JSONPath operations, including parsing.
|
|
261
|
+
enabling precise error handling across JSONPath operations, including parsing and compilation.
|
|
233
262
|
|
|
234
263
|
```js
|
|
235
|
-
import { JSONPathError, JSONPathParseError } from '@swaggerexpert/jsonpath';
|
|
264
|
+
import { JSONPathError, JSONPathParseError, JSONPathCompileError } from '@swaggerexpert/jsonpath';
|
|
236
265
|
```
|
|
237
266
|
|
|
238
267
|
**JSONPathError** is the base class for all JSONPath errors.
|
package/SECURITY.md
CHANGED
|
@@ -6,7 +6,9 @@ If you believe you've found an exploitable security issue in @swaggerexpert/json
|
|
|
6
6
|
|
|
7
7
|
| Version | Supported |
|
|
8
8
|
|---------|--------------------|
|
|
9
|
-
| ^1.0.0 | :
|
|
9
|
+
| ^1.0.0 | :x: |
|
|
10
|
+
| ^2.0.0 | :x: |
|
|
11
|
+
| ^3.0.0 | :white_check_mark: |
|
|
10
12
|
|
|
11
13
|
## Reporting a Vulnerability
|
|
12
14
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swaggerexpert/jsonpath",
|
|
3
3
|
"publishConfig": {
|
|
4
|
-
"access": "public"
|
|
4
|
+
"access": "public",
|
|
5
|
+
"registry": "https://registry.npmjs.org",
|
|
6
|
+
"provenance": true
|
|
5
7
|
},
|
|
6
|
-
"version": "3.
|
|
7
|
-
"description": "
|
|
8
|
+
"version": "3.2.2",
|
|
9
|
+
"description": "RFC 9535 implementation of JSONPath",
|
|
8
10
|
"main": "./cjs/index.cjs",
|
|
9
11
|
"types": "./types/index.d.ts",
|
|
10
12
|
"exports": {
|
|
@@ -60,22 +62,28 @@
|
|
|
60
62
|
"SECURITY.md"
|
|
61
63
|
],
|
|
62
64
|
"dependencies": {
|
|
63
|
-
"apg-lite": "^1.0.
|
|
65
|
+
"apg-lite": "^1.0.5"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
|
-
"@babel/cli": "=7.
|
|
67
|
-
"@babel/core": "=7.
|
|
68
|
-
"@babel/preset-env": "=7.
|
|
69
|
-
"@commitlint/cli": "=
|
|
70
|
-
"@commitlint/config-conventional": "=
|
|
68
|
+
"@babel/cli": "=7.28.6",
|
|
69
|
+
"@babel/core": "=7.28.6",
|
|
70
|
+
"@babel/preset-env": "=7.28.6",
|
|
71
|
+
"@commitlint/cli": "=20.3.1",
|
|
72
|
+
"@commitlint/config-conventional": "=20.3.1",
|
|
73
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
74
|
+
"@semantic-release/git": "^10.0.1",
|
|
75
|
+
"@semantic-release/github": "^12.0.2",
|
|
76
|
+
"@semantic-release/npm": "^13.1.3",
|
|
77
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
71
78
|
"apg-js": "^4.4.0",
|
|
72
79
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
73
|
-
"chai": "=
|
|
74
|
-
"cross-env": "^
|
|
80
|
+
"chai": "=6.2.2",
|
|
81
|
+
"cross-env": "^10.0.0",
|
|
75
82
|
"husky": "=9.1.7",
|
|
76
|
-
"mocha": "=11.
|
|
77
|
-
"mocha-expect-snapshot": "^
|
|
83
|
+
"mocha": "=11.7.5",
|
|
84
|
+
"mocha-expect-snapshot": "^8.0.0",
|
|
78
85
|
"npm-watch": "^0.13.0",
|
|
79
|
-
"prettier": "^3.5.2"
|
|
86
|
+
"prettier": "^3.5.2",
|
|
87
|
+
"semantic-release": "^25.0.2"
|
|
80
88
|
}
|
|
81
89
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ export interface NameSelectorASTNode extends ASTNode {
|
|
|
95
95
|
value: string;
|
|
96
96
|
format: 'single-quoted' | 'double-quoted' | 'shorthand';
|
|
97
97
|
}
|
|
98
|
+
type NameSelectorShorthandASTNode = NameSelectorASTNode & { format: 'shorthand' };
|
|
99
|
+
type NameSelectorQuotedASTNode = NameSelectorASTNode & { format: 'single-quoted' | 'double-quoted' };
|
|
98
100
|
// https://www.rfc-editor.org/rfc/rfc9535#section-2.3.2.1
|
|
99
101
|
export interface WildcardSelectorASTNode extends ASTNode {
|
|
100
102
|
type: 'WildcardSelector';
|
|
@@ -169,7 +171,7 @@ export interface FunctionExprASTNode extends ASTNode {
|
|
|
169
171
|
// https://www.rfc-editor.org/rfc/rfc9535#section-2.5.1.1
|
|
170
172
|
export interface ChildSegmentASTNode extends ASTNode {
|
|
171
173
|
type: 'ChildSegment';
|
|
172
|
-
selector: BracketedSelectionASTNode | WildcardSelectorASTNode |
|
|
174
|
+
selector: BracketedSelectionASTNode | WildcardSelectorASTNode | NameSelectorShorthandASTNode;
|
|
173
175
|
}
|
|
174
176
|
export interface BracketedSelectionASTNode extends ASTNode {
|
|
175
177
|
type: 'BracketedSelection';
|
|
@@ -177,11 +179,11 @@ export interface BracketedSelectionASTNode extends ASTNode {
|
|
|
177
179
|
}
|
|
178
180
|
export interface DescendantSegmentASTNode extends ASTNode {
|
|
179
181
|
type: 'DescendantSegment';
|
|
180
|
-
selector: BracketedSelectionASTNode | WildcardSelectorASTNode |
|
|
182
|
+
selector: BracketedSelectionASTNode | WildcardSelectorASTNode | NameSelectorShorthandASTNode;
|
|
181
183
|
}
|
|
182
184
|
// union types
|
|
183
185
|
export type SelectorASTNode =
|
|
184
|
-
|
|
|
186
|
+
| NameSelectorQuotedASTNode
|
|
185
187
|
| WildcardSelectorASTNode
|
|
186
188
|
| SliceSelectorASTNode
|
|
187
189
|
| IndexSelectorASTNode
|