@swaggerexpert/jsonpath 3.2.2 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/cjs/apg-lite.cjs +1221 -0
  2. package/cjs/compile.cjs +50 -0
  3. package/cjs/errors/JSONPathCompileError.cjs +8 -0
  4. package/cjs/errors/JSONPathError.cjs +44 -0
  5. package/cjs/errors/JSONPathParseError.cjs +8 -0
  6. package/cjs/escape.cjs +59 -0
  7. package/cjs/grammar.cjs +2839 -0
  8. package/cjs/index.cjs +31 -0
  9. package/cjs/parse/callbacks/cst.cjs +49 -0
  10. package/cjs/parse/index.cjs +41 -0
  11. package/cjs/parse/trace/Expectations.cjs +10 -0
  12. package/cjs/parse/trace/Trace.cjs +35 -0
  13. package/cjs/parse/translators/ASTTranslator/decoders.cjs +83 -0
  14. package/cjs/parse/translators/ASTTranslator/index.cjs +15 -0
  15. package/cjs/parse/translators/ASTTranslator/transformers.cjs +411 -0
  16. package/cjs/parse/translators/CSTOptimizedTranslator.cjs +39 -0
  17. package/cjs/parse/translators/CSTTranslator.cjs +118 -0
  18. package/cjs/parse/translators/XMLTranslator.cjs +12 -0
  19. package/cjs/test/index.cjs +25 -0
  20. package/es/compile.mjs +45 -0
  21. package/es/errors/JSONPathCompileError.mjs +3 -0
  22. package/es/errors/JSONPathError.mjs +40 -0
  23. package/es/errors/JSONPathParseError.mjs +3 -0
  24. package/es/escape.mjs +55 -0
  25. package/es/grammar.mjs +2835 -0
  26. package/es/index.mjs +13 -0
  27. package/es/parse/callbacks/cst.mjs +44 -0
  28. package/es/parse/index.mjs +36 -0
  29. package/es/parse/trace/Expectations.mjs +6 -0
  30. package/es/parse/trace/Trace.mjs +30 -0
  31. package/es/parse/translators/ASTTranslator/decoders.mjs +75 -0
  32. package/es/parse/translators/ASTTranslator/index.mjs +9 -0
  33. package/es/parse/translators/ASTTranslator/transformers.mjs +405 -0
  34. package/es/parse/translators/CSTOptimizedTranslator.mjs +34 -0
  35. package/es/parse/translators/CSTTranslator.mjs +113 -0
  36. package/es/parse/translators/XMLTranslator.mjs +7 -0
  37. package/es/test/index.mjs +20 -0
  38. package/package.json +1 -1
@@ -0,0 +1,113 @@
1
+ import { Ast as AST } from 'apg-lite';
2
+ import cstCallback from "../callbacks/cst.mjs";
3
+ class CSTTranslator extends AST {
4
+ constructor() {
5
+ super();
6
+
7
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.1.1
8
+ this.callbacks['jsonpath-query'] = cstCallback('jsonpath-query');
9
+ this.callbacks['segments'] = cstCallback('segments');
10
+ this.callbacks['B'] = cstCallback('text');
11
+ this.callbacks['S'] = cstCallback('text');
12
+
13
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.2.1
14
+ this.callbacks['root-identifier'] = cstCallback('root-identifier');
15
+
16
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3
17
+ this.callbacks['selector'] = cstCallback('selector');
18
+
19
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3.1.1
20
+ this.callbacks['name-selector'] = cstCallback('name-selector');
21
+ this.callbacks['string-literal'] = cstCallback('string-literal');
22
+ this.callbacks['double-quoted'] = cstCallback('double-quoted');
23
+ this.callbacks['single-quoted'] = cstCallback('single-quoted');
24
+
25
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3.2.1
26
+ this.callbacks['wildcard-selector'] = cstCallback('wildcard-selector');
27
+
28
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3.3.1
29
+ this.callbacks['index-selector'] = cstCallback('index-selector');
30
+
31
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3.4.1
32
+ this.callbacks['slice-selector'] = cstCallback('slice-selector');
33
+ this.callbacks['start'] = cstCallback('start');
34
+ this.callbacks['end'] = cstCallback('end');
35
+ this.callbacks['step'] = cstCallback('step');
36
+
37
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.3.5.1
38
+ this.callbacks['filter-selector'] = cstCallback('filter-selector');
39
+ this.callbacks['logical-expr'] = cstCallback('logical-expr');
40
+ this.callbacks['logical-or-expr'] = cstCallback('logical-or-expr');
41
+ this.callbacks['logical-and-expr'] = cstCallback('logical-and-expr');
42
+ this.callbacks['basic-expr'] = cstCallback('basic-expr');
43
+ this.callbacks['paren-expr'] = cstCallback('paren-expr');
44
+ this.callbacks['logical-not-op'] = cstCallback('logical-not-op');
45
+ this.callbacks['test-expr'] = cstCallback('test-expr');
46
+ this.callbacks['filter-query'] = cstCallback('filter-query');
47
+ this.callbacks['rel-query'] = cstCallback('rel-query');
48
+ this.callbacks['current-node-identifier'] = cstCallback('current-node-identifier');
49
+ this.callbacks['comparison-expr'] = cstCallback('comparison-expr');
50
+ this.callbacks['literal'] = cstCallback('literal');
51
+ this.callbacks['comparable'] = cstCallback('comparable');
52
+ this.callbacks['comparison-op'] = cstCallback('comparison-op');
53
+ this.callbacks['singular-query'] = cstCallback('singular-query');
54
+ this.callbacks['rel-singular-query'] = cstCallback('rel-singular-query');
55
+ this.callbacks['abs-singular-query'] = cstCallback('abs-singular-query');
56
+ this.callbacks['singular-query-segments'] = cstCallback('singular-query-segments');
57
+ this.callbacks['name-segment'] = cstCallback('name-segment');
58
+ this.callbacks['index-segment'] = cstCallback('index-segment');
59
+ this.callbacks['number'] = cstCallback('number');
60
+ this.callbacks['true'] = cstCallback('true');
61
+ this.callbacks['false'] = cstCallback('false');
62
+ this.callbacks['null'] = cstCallback('null');
63
+
64
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.4
65
+ this.callbacks['function-name'] = cstCallback('function-name');
66
+ this.callbacks['function-expr'] = cstCallback('function-expr');
67
+ this.callbacks['function-argument'] = cstCallback('function-argument');
68
+
69
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.5
70
+ this.callbacks['segment'] = cstCallback('segment');
71
+
72
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.5.1.1
73
+ this.callbacks['child-segment'] = cstCallback('child-segment');
74
+ this.callbacks['bracketed-selection'] = cstCallback('bracketed-selection');
75
+ this.callbacks['member-name-shorthand'] = cstCallback('member-name-shorthand');
76
+
77
+ // https://www.rfc-editor.org/rfc/rfc9535#section-2.5.2.1
78
+ this.callbacks['descendant-segment'] = cstCallback('descendant-segment');
79
+
80
+ // https://www.rfc-editor.org/rfc/rfc9535#name-normalized-paths
81
+ this.callbacks['normalized-path'] = cstCallback('normalized-path');
82
+ this.callbacks['normal-index-segment'] = cstCallback('normal-index-segment');
83
+ this.callbacks['normal-selector'] = cstCallback('normal-selector');
84
+ this.callbacks['normal-name-selector'] = cstCallback('normal-name-selector');
85
+ this.callbacks['normal-index-selector'] = cstCallback('normal-index-selector');
86
+ this.callbacks['normal-single-quoted'] = cstCallback('normal-single-quoted');
87
+
88
+ // Surrogate named rules
89
+ this.callbacks['dot-prefix'] = cstCallback('text');
90
+ this.callbacks['double-dot-prefix'] = cstCallback('text');
91
+ this.callbacks['left-bracket'] = cstCallback('text');
92
+ this.callbacks['right-bracket'] = cstCallback('text');
93
+ this.callbacks['comma'] = cstCallback('text');
94
+ this.callbacks['colon'] = cstCallback('text');
95
+ this.callbacks['dquote'] = cstCallback('text');
96
+ this.callbacks['squote'] = cstCallback('text');
97
+ this.callbacks['questionmark'] = cstCallback('text');
98
+ this.callbacks['disjunction'] = cstCallback('text');
99
+ this.callbacks['conjunction'] = cstCallback('text');
100
+ this.callbacks['left-paren'] = cstCallback('text');
101
+ this.callbacks['right-paren'] = cstCallback('text');
102
+ }
103
+ getTree() {
104
+ const data = {
105
+ stack: [],
106
+ root: null
107
+ };
108
+ this.translate(data);
109
+ delete data.stack;
110
+ return data;
111
+ }
112
+ }
113
+ export default CSTTranslator;
@@ -0,0 +1,7 @@
1
+ import CSTTranslator from "./CSTTranslator.mjs";
2
+ class XMLTranslator extends CSTTranslator {
3
+ getTree() {
4
+ return this.toXml();
5
+ }
6
+ }
7
+ export default XMLTranslator;
@@ -0,0 +1,20 @@
1
+ import parse from "../parse/index.mjs";
2
+ const test = (jsonPath, {
3
+ normalized = false
4
+ } = {}) => {
5
+ if (typeof jsonPath !== 'string') return false;
6
+ try {
7
+ const {
8
+ result
9
+ } = parse(jsonPath, {
10
+ normalized,
11
+ stats: false,
12
+ trace: false,
13
+ translator: null
14
+ });
15
+ return result.success;
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
20
+ export default test;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "provenance": true
7
7
  },
8
- "version": "3.2.2",
8
+ "version": "3.2.4",
9
9
  "description": "RFC 9535 implementation of JSONPath",
10
10
  "main": "./cjs/index.cjs",
11
11
  "types": "./types/index.d.ts",