@swaggerexpert/jsonpath 1.1.0 → 1.2.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 CHANGED
@@ -9,7 +9,11 @@
9
9
 
10
10
  `@swaggerexpert/jsonpath` is a **parser** and **validator** for [RFC 9535](https://www.rfc-editor.org/rfc/rfc9535) Query Expressions for JSON - **JSONPath**.
11
11
 
12
- The development of this library contributed to the identification and formal submission of [Errata 8343](https://www.rfc-editor.org/errata/eid8343) against RFC 9535.
12
+ The development of this library contributed to the identification and formal submission of following **erratas** against the RFC 9535:
13
+ - [Errata ID: 8343](https://www.rfc-editor.org/errata/eid8343)
14
+ - [Errata ID: 8352](https://www.rfc-editor.org/errata/eid8352)
15
+ - [Errata ID: 8353](https://www.rfc-editor.org/errata/eid8353)
16
+ - [Errata ID: 8354](https://www.rfc-editor.org/errata/eid8354)
13
17
 
14
18
  <table>
15
19
  <tr>
@@ -32,7 +36,8 @@ The development of this library contributed to the identification and formal sub
32
36
  - [Parsing](#parsing)
33
37
  - [Concrete Syntax Tree (CST)](#concrete-syntax-tree-cst)
34
38
  - [Interpreting Parse result as XML](#interpreting-parse-result-as-xml)
35
- - [Parse statistics](#parse-statistics)
39
+ - [Statistics](#statistics)
40
+ - [Tracing](#tracing)
36
41
  - [Errors](#errors)
37
42
  - [Grammar](#grammar)
38
43
  - [More about JSONPath](#more-about-jsonpath)
@@ -288,7 +293,7 @@ const parseResult = parse('$.store.book[0].title');
288
293
  const xml = parseResult.ast.toXml();
289
294
  ```
290
295
 
291
- ###### Parse statistics
296
+ ###### Statistics
292
297
 
293
298
  `parse` function returns additional statistical information about the parsing process.
294
299
  Collection of the statistics can be enabled by setting `stats` option to `true`.
@@ -302,6 +307,25 @@ stats.displayStats(); // returns operator stats
302
307
  stats.displayHits(); // returns rules grouped by hit count
303
308
  ```
304
309
 
310
+ ###### Tracing
311
+
312
+ `parse` function returns additional tracing information about the parsing process.
313
+ Tracing can be enabled by setting `trace` option to `true`. Tracing is essential
314
+ for debugging failed matches or analyzing rule execution flow.
315
+
316
+ ```js
317
+ import { parse } from '@swaggerexpert/jsonpath';
318
+
319
+ const { result, trace } = parse('$fdfadfd', { trace: true });
320
+
321
+ result.success; // returns false
322
+ trace.displayTrace(); // returns trace information
323
+ ```
324
+
325
+ By combining information from `result` and `trace`, it is possible to analyze the parsing process in detail
326
+ and generate a messages like this: `'Syntax error at position 1, expected "[", ".", ".."'`. Please see this
327
+ [test file](https://github.com/swaggerexpert/jsonpath/blob/main/test/parse/trace.js) for more information how to achieve that.
328
+
305
329
  #### Errors
306
330
 
307
331
  `@swaggerexpert/jsonpath` provides a structured error class hierarchy,
package/cjs/grammar.cjs CHANGED
@@ -2720,7 +2720,7 @@ function grammar() {
2720
2720
  str += "comparable = singular-query / ; singular query value\n";
2721
2721
  str += " function-expr / ; ValueType\n";
2722
2722
  str += " literal\n";
2723
- str += " ; MODIFICATION: https://www.rfc-editor.org/errata/eid8343\n";
2723
+ str += " ; MODIFICATION: https://www.rfc-editor.org/errata/eid8352\n";
2724
2724
  str += "comparison-op = \"==\" / \"!=\" /\n";
2725
2725
  str += " \"<=\" / \">=\" /\n";
2726
2726
  str += " \"<\" / \">\"\n";
@@ -12,6 +12,7 @@ const grammar = new _grammar.default();
12
12
  const parse = (jsonPath, {
13
13
  ast = new _JSONPathQueryCST.default(),
14
14
  stats = false,
15
+ trace = false,
15
16
  evaluator = _translate.default
16
17
  } = {}) => {
17
18
  if (typeof jsonPath !== 'string') {
@@ -21,6 +22,7 @@ const parse = (jsonPath, {
21
22
  const parser = new _apgLite.Parser();
22
23
  parser.ast = ast;
23
24
  if (stats) parser.stats = new _apgLite.Stats();
25
+ if (trace) parser.trace = new _apgLite.Trace();
24
26
  const result = parser.parse(grammar, 'jsonpath-query', jsonPath);
25
27
  const computed = evaluator(ast, {
26
28
  result
@@ -29,6 +31,7 @@ const parse = (jsonPath, {
29
31
  result,
30
32
  ast,
31
33
  stats: parser.stats,
34
+ trace: parser.trace,
32
35
  computed
33
36
  };
34
37
  } catch (error) {
package/es/grammar.mjs CHANGED
@@ -2716,7 +2716,7 @@ export default function grammar() {
2716
2716
  str += "comparable = singular-query / ; singular query value\n";
2717
2717
  str += " function-expr / ; ValueType\n";
2718
2718
  str += " literal\n";
2719
- str += " ; MODIFICATION: https://www.rfc-editor.org/errata/eid8343\n";
2719
+ str += " ; MODIFICATION: https://www.rfc-editor.org/errata/eid8352\n";
2720
2720
  str += "comparison-op = \"==\" / \"!=\" /\n";
2721
2721
  str += " \"<=\" / \">=\" /\n";
2722
2722
  str += " \"<\" / \">\"\n";
@@ -1,4 +1,4 @@
1
- import { Parser, Stats } from 'apg-lite';
1
+ import { Parser, Stats, Trace } from 'apg-lite';
2
2
  import Grammar from "../grammar.mjs";
3
3
  import translateEvaluator from "./evaluators/translate.mjs";
4
4
  import JSONPathQueryCST from "./ast/JSONPathQueryCST.mjs";
@@ -7,6 +7,7 @@ const grammar = new Grammar();
7
7
  const parse = (jsonPath, {
8
8
  ast = new JSONPathQueryCST(),
9
9
  stats = false,
10
+ trace = false,
10
11
  evaluator = translateEvaluator
11
12
  } = {}) => {
12
13
  if (typeof jsonPath !== 'string') {
@@ -16,6 +17,7 @@ const parse = (jsonPath, {
16
17
  const parser = new Parser();
17
18
  parser.ast = ast;
18
19
  if (stats) parser.stats = new Stats();
20
+ if (trace) parser.trace = new Trace();
19
21
  const result = parser.parse(grammar, 'jsonpath-query', jsonPath);
20
22
  const computed = evaluator(ast, {
21
23
  result
@@ -24,6 +26,7 @@ const parse = (jsonPath, {
24
26
  result,
25
27
  ast,
26
28
  stats: parser.stats,
29
+ trace: parser.trace,
27
30
  computed
28
31
  };
29
32
  } catch (error) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.1.0",
6
+ "version": "1.2.1",
7
7
  "description": "RCF 9535 implementation of JSONPath",
8
8
  "main": "./cjs/index.cjs",
9
9
  "types": "./types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export function parse(jsonpath: string, options?: ParseOptions): ParseResult;
6
6
  export interface ParseOptions {
7
7
  readonly ast?: AST;
8
8
  readonly stats?: boolean;
9
+ readonly trace?: boolean;
9
10
  }
10
11
 
11
12
  export interface AST {
@@ -20,6 +21,7 @@ export interface ParseResult {
20
21
  readonly ast: AST;
21
22
  readonly computed: Record<string, CSTNode>;
22
23
  readonly stats?: Stats;
24
+ readonly trace?: Trace;
23
25
  }
24
26
 
25
27
  export interface CSTNode {
@@ -35,6 +37,10 @@ export interface Stats {
35
37
  displayHits(): string;
36
38
  }
37
39
 
40
+ export interface Trace {
41
+ displayTrace(): string;
42
+ }
43
+
38
44
  /**
39
45
  * Grammar
40
46
  */