@swaggerexpert/jsonpath 3.1.0 → 3.2.3

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/package.json +1 -1
  2. package/cjs/apg-lite.cjs +0 -1221
  3. package/cjs/compile.cjs +0 -50
  4. package/cjs/errors/JSONPathCompileError.cjs +0 -8
  5. package/cjs/errors/JSONPathError.cjs +0 -44
  6. package/cjs/errors/JSONPathParseError.cjs +0 -8
  7. package/cjs/escape.cjs +0 -59
  8. package/cjs/grammar.cjs +0 -2839
  9. package/cjs/index.cjs +0 -31
  10. package/cjs/parse/callbacks/cst.cjs +0 -49
  11. package/cjs/parse/index.cjs +0 -41
  12. package/cjs/parse/trace/Expectations.cjs +0 -10
  13. package/cjs/parse/trace/Trace.cjs +0 -35
  14. package/cjs/parse/translators/ASTTranslator/decoders.cjs +0 -83
  15. package/cjs/parse/translators/ASTTranslator/index.cjs +0 -15
  16. package/cjs/parse/translators/ASTTranslator/transformers.cjs +0 -411
  17. package/cjs/parse/translators/CSTOptimizedTranslator.cjs +0 -39
  18. package/cjs/parse/translators/CSTTranslator.cjs +0 -118
  19. package/cjs/parse/translators/XMLTranslator.cjs +0 -12
  20. package/cjs/test/index.cjs +0 -25
  21. package/es/compile.mjs +0 -45
  22. package/es/errors/JSONPathCompileError.mjs +0 -3
  23. package/es/errors/JSONPathError.mjs +0 -40
  24. package/es/errors/JSONPathParseError.mjs +0 -3
  25. package/es/escape.mjs +0 -55
  26. package/es/grammar.mjs +0 -2835
  27. package/es/index.mjs +0 -13
  28. package/es/parse/callbacks/cst.mjs +0 -44
  29. package/es/parse/index.mjs +0 -36
  30. package/es/parse/trace/Expectations.mjs +0 -6
  31. package/es/parse/trace/Trace.mjs +0 -30
  32. package/es/parse/translators/ASTTranslator/decoders.mjs +0 -75
  33. package/es/parse/translators/ASTTranslator/index.mjs +0 -9
  34. package/es/parse/translators/ASTTranslator/transformers.mjs +0 -405
  35. package/es/parse/translators/CSTOptimizedTranslator.mjs +0 -34
  36. package/es/parse/translators/CSTTranslator.mjs +0 -113
  37. package/es/parse/translators/XMLTranslator.mjs +0 -7
  38. package/es/test/index.mjs +0 -20
package/cjs/index.cjs DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.test = exports.parse = exports.escape = exports.compile = exports.XMLTranslator = exports.Trace = exports.JSONPathParseError = exports.JSONPathError = exports.JSONPathCompileError = exports.Grammar = exports.CSTTranslator = exports.CSTOptimizedTranslator = exports.ASTTranslator = void 0;
5
- var _grammar = _interopRequireDefault(require("./grammar.cjs"));
6
- exports.Grammar = _grammar.default;
7
- var _index = _interopRequireDefault(require("./parse/index.cjs"));
8
- exports.parse = _index.default;
9
- var _CSTTranslator = _interopRequireDefault(require("./parse/translators/CSTTranslator.cjs"));
10
- exports.CSTTranslator = _CSTTranslator.default;
11
- var _CSTOptimizedTranslator = _interopRequireDefault(require("./parse/translators/CSTOptimizedTranslator.cjs"));
12
- exports.CSTOptimizedTranslator = _CSTOptimizedTranslator.default;
13
- var _index2 = _interopRequireDefault(require("./parse/translators/ASTTranslator/index.cjs"));
14
- exports.ASTTranslator = _index2.default;
15
- var _XMLTranslator = _interopRequireDefault(require("./parse/translators/XMLTranslator.cjs"));
16
- exports.XMLTranslator = _XMLTranslator.default;
17
- var _Trace = _interopRequireDefault(require("./parse/trace/Trace.cjs"));
18
- exports.Trace = _Trace.default;
19
- var _index3 = _interopRequireDefault(require("./test/index.cjs"));
20
- exports.test = _index3.default;
21
- var _compile = _interopRequireDefault(require("./compile.cjs"));
22
- exports.compile = _compile.default;
23
- var _escape = _interopRequireDefault(require("./escape.cjs"));
24
- exports.escape = _escape.default;
25
- var _JSONPathError = _interopRequireDefault(require("./errors/JSONPathError.cjs"));
26
- exports.JSONPathError = _JSONPathError.default;
27
- var _JSONPathParseError = _interopRequireDefault(require("./errors/JSONPathParseError.cjs"));
28
- exports.JSONPathParseError = _JSONPathParseError.default;
29
- var _JSONPathCompileError = _interopRequireDefault(require("./errors/JSONPathCompileError.cjs"));
30
- exports.JSONPathCompileError = _JSONPathCompileError.default;
31
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apgLite = require("../../apg-lite.cjs");
6
- var _JSONPathParseError = _interopRequireDefault(require("../../errors/JSONPathParseError.cjs"));
7
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
- const cst = nodeType => {
9
- return (state, chars, phraseIndex, phraseLength, data) => {
10
- var _data$options, _data$options2;
11
- if (!(typeof data === 'object' && data !== null && !Array.isArray(data))) {
12
- throw new _JSONPathParseError.default("parser's user data must be an object");
13
- }
14
-
15
- // drop the empty nodes
16
- if ((_data$options = data.options) != null && _data$options.optimize && phraseLength === 0 && (_data$options2 = data.options) != null && (_data$options2 = _data$options2.droppableTypes) != null && _data$options2.includes(nodeType)) {
17
- return;
18
- }
19
- if (state === _apgLite.identifiers.SEM_PRE) {
20
- const node = {
21
- type: nodeType,
22
- text: _apgLite.utilities.charsToString(chars, phraseIndex, phraseLength),
23
- start: phraseIndex,
24
- length: phraseLength,
25
- children: []
26
- };
27
- if (data.stack.length > 0) {
28
- var _data$options3, _data$options4;
29
- const parent = data.stack[data.stack.length - 1];
30
- const prevSibling = parent.children[parent.children.length - 1];
31
- const isTextNodeWithinTextNode = parent.type === 'text' && node.type === 'text';
32
- const shouldCollapse = ((_data$options3 = data.options) == null ? void 0 : _data$options3.optimize) && ((_data$options4 = data.options) == null || (_data$options4 = _data$options4.collapsibleTypes) == null ? void 0 : _data$options4.includes(node.type)) && (prevSibling == null ? void 0 : prevSibling.type) === node.type;
33
- if (shouldCollapse) {
34
- prevSibling.text += node.text;
35
- prevSibling.length += node.length;
36
- } else if (!isTextNodeWithinTextNode) {
37
- parent.children.push(node);
38
- }
39
- } else {
40
- data.root = node;
41
- }
42
- data.stack.push(node);
43
- }
44
- if (state === _apgLite.identifiers.SEM_POST) {
45
- data.stack.pop();
46
- }
47
- };
48
- };
49
- var _default = exports.default = cst;
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apgLite = require("../apg-lite.cjs");
6
- var _Trace = _interopRequireDefault(require("./trace/Trace.cjs"));
7
- var _grammar = _interopRequireDefault(require("../grammar.cjs"));
8
- var _index = _interopRequireDefault(require("./translators/ASTTranslator/index.cjs"));
9
- var _JSONPathParseError = _interopRequireDefault(require("../errors/JSONPathParseError.cjs"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const grammar = new _grammar.default();
12
- const parse = (jsonPath, {
13
- normalized = false,
14
- stats = false,
15
- trace = false,
16
- translator = new _index.default()
17
- } = {}) => {
18
- if (typeof jsonPath !== 'string') {
19
- throw new TypeError('JSONPath must be a string');
20
- }
21
- try {
22
- const parser = new _apgLite.Parser();
23
- if (translator) parser.ast = translator;
24
- if (stats) parser.stats = new _apgLite.Stats();
25
- if (trace) parser.trace = new _Trace.default();
26
- const startRule = normalized ? 'normalized-path' : 'jsonpath-query';
27
- const result = parser.parse(grammar, startRule, jsonPath);
28
- return {
29
- result,
30
- tree: result.success && translator ? parser.ast.getTree() : undefined,
31
- stats: parser.stats,
32
- trace: parser.trace
33
- };
34
- } catch (error) {
35
- throw new _JSONPathParseError.default('Unexpected error during JSONPath parsing', {
36
- cause: error,
37
- jsonPath
38
- });
39
- }
40
- };
41
- var _default = exports.default = parse;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- class Expectations extends Array {
6
- toString() {
7
- return this.map(c => `"${String(c)}"`).join(', ');
8
- }
9
- }
10
- var _default = exports.default = Expectations;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apgLite = require("../../apg-lite.cjs");
6
- var _Expectations = _interopRequireDefault(require("./Expectations.cjs"));
7
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
- class Trace extends _apgLite.Trace {
9
- inferExpectations() {
10
- const lines = this.displayTrace().split('\n');
11
- const expectations = new Set();
12
- let lastMatchedIndex = -1;
13
- for (let i = 0; i < lines.length; i++) {
14
- const line = lines[i];
15
-
16
- // capture the max match line (first one that ends in a single character match)
17
- if (line.includes('M|')) {
18
- const textMatch = line.match(/]'(.*)'$/);
19
- if (textMatch && textMatch[1]) {
20
- lastMatchedIndex = i;
21
- }
22
- }
23
-
24
- // collect terminal failures after the deepest successful match
25
- if (i > lastMatchedIndex) {
26
- const terminalFailMatch = line.match(/N\|\[TLS\(([^)]+)\)]/);
27
- if (terminalFailMatch) {
28
- expectations.add(terminalFailMatch[1]);
29
- }
30
- }
31
- }
32
- return new _Expectations.default(...expectations);
33
- }
34
- }
35
- var _default = exports.default = Trace;
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.decodeSingleQuotedString = exports.decodeJSONValue = exports.decodeInteger = exports.decodeDoubleQuotedString = void 0;
5
- const decodeDoubleQuotedString = str => {
6
- return decodeJSONValue(`"${str}"`);
7
- };
8
- exports.decodeDoubleQuotedString = decodeDoubleQuotedString;
9
- const decodeSingleQuotedString = str => {
10
- // Decode single-quoted string escape sequences into raw text, then let JSON.stringify
11
- // produce a correctly escaped double-quoted JSON string.
12
- let decoded = '';
13
- for (let i = 0; i < str.length; i++) {
14
- const ch = str[i];
15
- if (ch === '\\') {
16
- i++;
17
- if (i >= str.length) {
18
- // Trailing backslash, treat it as a literal backslash
19
- decoded += '\\';
20
- break;
21
- }
22
- const esc = str[i];
23
- switch (esc) {
24
- case 'n':
25
- decoded += '\n';
26
- break;
27
- case 'r':
28
- decoded += '\r';
29
- break;
30
- case 't':
31
- decoded += '\t';
32
- break;
33
- case 'b':
34
- decoded += '\b';
35
- break;
36
- case 'f':
37
- decoded += '\f';
38
- break;
39
- case '/':
40
- decoded += '/';
41
- break;
42
- case '\\':
43
- decoded += '\\';
44
- break;
45
- case "'":
46
- decoded += "'";
47
- break;
48
- case '"':
49
- decoded += '"';
50
- break;
51
- case 'u':
52
- {
53
- // Unicode escape \uXXXX - grammar guarantees exactly 4 hex digits
54
- const hex = str.slice(i + 1, i + 5);
55
- decoded += String.fromCharCode(parseInt(hex, 16));
56
- i += 4;
57
- break;
58
- }
59
- default:
60
- // Unrecognized escape, keep the escaped character literally
61
- decoded += esc;
62
- break;
63
- }
64
- } else {
65
- decoded += ch;
66
- }
67
- }
68
- // Use JSON.stringify to produce a valid JSON string literal
69
- return decodeJSONValue(JSON.stringify(decoded));
70
- };
71
- exports.decodeSingleQuotedString = decodeSingleQuotedString;
72
- const decodeInteger = str => {
73
- const value = parseInt(str, 10);
74
- if (!Number.isSafeInteger(value)) {
75
- throw new RangeError(`Integer value out of safe range [-(2^53)+1, (2^53)-1], got: ${str}`);
76
- }
77
- return value;
78
- };
79
- exports.decodeInteger = decodeInteger;
80
- const decodeJSONValue = str => {
81
- return JSON.parse(str);
82
- };
83
- exports.decodeJSONValue = decodeJSONValue;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _CSTOptimizedTranslator = _interopRequireDefault(require("../CSTOptimizedTranslator.cjs"));
6
- var _transformers = _interopRequireWildcard(require("./transformers.cjs"));
7
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- class ASTTranslator extends _CSTOptimizedTranslator.default {
10
- getTree() {
11
- const cst = super.getTree();
12
- return (0, _transformers.transformCSTtoAST)(cst.root, _transformers.default);
13
- }
14
- }
15
- var _default = exports.default = ASTTranslator;
@@ -1,411 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.transformCSTtoAST = exports.default = void 0;
5
- var _JSONPathParseError = _interopRequireDefault(require("../../../errors/JSONPathParseError.cjs"));
6
- var _decoders = require("./decoders.cjs");
7
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
- const transformCSTtoAST = (node, transformerMap, ctx = {
9
- parent: null,
10
- path: []
11
- }) => {
12
- const transformer = transformerMap[node.type];
13
- if (!transformer) {
14
- throw new _JSONPathParseError.default(`No transformer for CST node type: ${node.type}`);
15
- }
16
- const nextCtx = {
17
- parent: node,
18
- path: [...ctx.path, node]
19
- };
20
- return transformer(node, nextCtx);
21
- };
22
- exports.transformCSTtoAST = transformCSTtoAST;
23
- const transformers = {
24
- /**
25
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.1.1
26
- */
27
- ['jsonpath-query'](node, ctx) {
28
- const segments = node.children.find(c => c.type === 'segments');
29
- return {
30
- type: 'JsonPathQuery',
31
- segments: segments ? segments.children.filter(({
32
- type
33
- }) => type === 'segment').map(segNode => transformCSTtoAST(segNode, transformers, ctx)) : []
34
- };
35
- },
36
- /**
37
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.5
38
- */
39
- segment(node, ctx) {
40
- const child = node.children.find(({
41
- type
42
- }) => ['child-segment', 'descendant-segment'].includes(type));
43
- return transformCSTtoAST(child, transformers, ctx);
44
- },
45
- /**
46
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3
47
- */
48
- selector(node, ctx) {
49
- const child = node.children.find(({
50
- type
51
- }) => ['name-selector', 'wildcard-selector', 'slice-selector', 'index-selector', 'filter-selector'].includes(type));
52
- return transformCSTtoAST(child, transformers, ctx);
53
- },
54
- /**
55
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3.1.1
56
- */
57
- ['name-selector'](node, ctx) {
58
- const stringLiteralCSTNode = node.children.find(({
59
- type
60
- }) => type === 'string-literal');
61
- const stringLiteralASTNode = transformCSTtoAST(stringLiteralCSTNode, transformers, ctx);
62
- return {
63
- type: 'NameSelector',
64
- value: stringLiteralASTNode.value,
65
- format: stringLiteralASTNode.format
66
- };
67
- },
68
- ['string-literal'](node) {
69
- const isSingleQuoted = node.children.find(({
70
- type,
71
- text
72
- }) => type === 'text' && text === "'");
73
- const quoted = node.children.find(({
74
- type
75
- }) => ['double-quoted', 'single-quoted'].includes(type));
76
- const decodeString = isSingleQuoted ? _decoders.decodeSingleQuotedString : _decoders.decodeDoubleQuotedString;
77
- return {
78
- type: 'StringLiteral',
79
- value: quoted ? decodeString(quoted.text) : '',
80
- format: isSingleQuoted ? 'single-quoted' : 'double-quoted'
81
- };
82
- },
83
- /**
84
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3.2.1
85
- */
86
- ['wildcard-selector']() {
87
- return {
88
- type: 'WildcardSelector'
89
- };
90
- },
91
- /**
92
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3.3.1
93
- */
94
- ['index-selector'](node) {
95
- return {
96
- type: 'IndexSelector',
97
- value: (0, _decoders.decodeInteger)(node.text)
98
- };
99
- },
100
- /**
101
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3.4.1
102
- */
103
- ['slice-selector'](node) {
104
- const start = node.children.find(({
105
- type
106
- }) => type === 'start');
107
- const end = node.children.find(({
108
- type
109
- }) => type === 'end');
110
- const step = node.children.find(({
111
- type
112
- }) => type === 'step');
113
- return {
114
- type: 'SliceSelector',
115
- start: start ? (0, _decoders.decodeInteger)(start.text) : null,
116
- end: end ? (0, _decoders.decodeInteger)(end.text) : null,
117
- step: step ? (0, _decoders.decodeInteger)(step.text) : null
118
- };
119
- },
120
- /**
121
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.3.5.1
122
- */
123
- ['filter-selector'](node, ctx) {
124
- const child = node.children.find(({
125
- type
126
- }) => type === 'logical-expr');
127
- return {
128
- type: 'FilterSelector',
129
- expression: transformCSTtoAST(child, transformers, ctx)
130
- };
131
- },
132
- ['logical-expr'](node, ctx) {
133
- const child = node.children.find(({
134
- type
135
- }) => type === 'logical-or-expr');
136
- return transformCSTtoAST(child, transformers, ctx);
137
- },
138
- ['logical-or-expr'](node, ctx) {
139
- const logicalAndExprs = node.children.filter(({
140
- type
141
- }) => type === 'logical-and-expr');
142
- if (logicalAndExprs.length === 1) {
143
- return transformCSTtoAST(logicalAndExprs[0], transformers, ctx);
144
- }
145
-
146
- // fold left for left-associativity
147
- let left = transformCSTtoAST(logicalAndExprs[0], transformers, ctx);
148
- for (let i = 1; i < logicalAndExprs.length; i += 1) {
149
- const right = transformCSTtoAST(logicalAndExprs[i], transformers, ctx);
150
- left = {
151
- type: 'LogicalOrExpr',
152
- left,
153
- right
154
- };
155
- }
156
- },
157
- ['logical-and-expr'](node, ctx) {
158
- const basicExprs = node.children.filter(({
159
- type
160
- }) => type === 'basic-expr');
161
- if (basicExprs.length === 1) {
162
- return transformCSTtoAST(basicExprs[0], transformers, ctx);
163
- }
164
- let left = transformCSTtoAST(basicExprs[0], transformers, ctx);
165
- for (let i = 1; i < basicExprs.length; i += 1) {
166
- const right = transformCSTtoAST(basicExprs[i], transformers, ctx);
167
- left = {
168
- type: 'LogicalAndExpr',
169
- left,
170
- right
171
- };
172
- }
173
- return left;
174
- },
175
- ['basic-expr'](node, ctx) {
176
- const child = node.children.find(({
177
- type
178
- }) => ['paren-expr', 'comparison-expr', 'test-expr'].includes(type));
179
- return transformCSTtoAST(child, transformers, ctx);
180
- },
181
- ['paren-expr'](node, ctx) {
182
- const isNegated = node.children.some(child => child.type === 'logical-not-op');
183
- const logicalExprCSTNode = node.children.find(child => child.type === 'logical-expr');
184
- const logicalExpressionASTNode = transformCSTtoAST(logicalExprCSTNode, transformers, ctx);
185
- if (isNegated) {
186
- return {
187
- type: 'LogicalNotExpr',
188
- expression: logicalExpressionASTNode
189
- };
190
- }
191
- return logicalExpressionASTNode;
192
- },
193
- ['test-expr'](node, ctx) {
194
- const isNegated = node.children.some(({
195
- type
196
- }) => type === 'logical-not-op');
197
- const expression = node.children.find(({
198
- type
199
- }) => ['filter-query', 'function-expr'].includes(type));
200
- const testExpr = {
201
- type: 'TestExpr',
202
- expression: transformCSTtoAST(expression, transformers, ctx)
203
- };
204
- return isNegated ? {
205
- type: 'LogicalNotExpr',
206
- expression: testExpr
207
- } : testExpr;
208
- },
209
- ['filter-query'](node, ctx) {
210
- const child = node.children.find(({
211
- type
212
- }) => ['rel-query', 'jsonpath-query'].includes(type));
213
- return {
214
- type: 'FilterQuery',
215
- query: transformCSTtoAST(child, transformers, ctx)
216
- };
217
- },
218
- ['rel-query'](node, ctx) {
219
- const segments = node.children.find(c => c.type === 'segments');
220
- return {
221
- type: 'RelQuery',
222
- segments: segments ? segments.children.filter(n => n.type === 'segment').map(segNode => transformCSTtoAST(segNode, transformers, ctx)) : []
223
- };
224
- },
225
- ['comparison-expr'](node, ctx) {
226
- const children = node.children.filter(({
227
- type
228
- }) => ['comparable', 'comparison-op'].includes(type));
229
- const [left, op, right] = children;
230
- return {
231
- type: 'ComparisonExpr',
232
- left: transformCSTtoAST(left, transformers, ctx),
233
- op: op.text,
234
- right: transformCSTtoAST(right, transformers, ctx)
235
- };
236
- },
237
- ['literal'](node, ctx) {
238
- const child = node.children.find(({
239
- type
240
- }) => ['number', 'string-literal', 'true', 'false', 'null'].includes(type));
241
- if (child.type === 'string-literal') {
242
- const stringLiteralASTNode = transformCSTtoAST(child, transformers, ctx);
243
- return {
244
- type: 'Literal',
245
- value: stringLiteralASTNode.value
246
- };
247
- }
248
- return {
249
- type: 'Literal',
250
- value: (0, _decoders.decodeJSONValue)(child.text)
251
- };
252
- },
253
- ['comparable'](node, ctx) {
254
- const child = node.children.find(({
255
- type
256
- }) => ['singular-query', 'function-expr', 'literal'].includes(type));
257
- return transformCSTtoAST(child, transformers, ctx);
258
- },
259
- ['singular-query'](node, ctx) {
260
- const child = node.children.find(({
261
- type
262
- }) => ['rel-singular-query', 'abs-singular-query'].includes(type));
263
- return transformCSTtoAST(child, transformers, ctx);
264
- },
265
- ['rel-singular-query'](node, ctx) {
266
- const segmentsNode = node.children.find(({
267
- type
268
- }) => type === 'singular-query-segments');
269
- const segments = segmentsNode ? segmentsNode.children.filter(({
270
- type
271
- }) => ['name-segment', 'index-segment'].includes(type)).map(segNode => ({
272
- type: 'SingularQuerySegment',
273
- selector: transformCSTtoAST(segNode, transformers, ctx)
274
- })) : [];
275
- return {
276
- type: 'RelSingularQuery',
277
- segments
278
- };
279
- },
280
- ['abs-singular-query'](node, ctx) {
281
- const segmentsNode = node.children.find(({
282
- type
283
- }) => type === 'singular-query-segments');
284
- const segments = segmentsNode ? segmentsNode.children.filter(({
285
- type
286
- }) => ['name-segment', 'index-segment'].includes(type)).map(segNode => ({
287
- type: 'SingularQuerySegment',
288
- selector: transformCSTtoAST(segNode, transformers, ctx)
289
- })) : [];
290
- return {
291
- type: 'AbsSingularQuery',
292
- segments
293
- };
294
- },
295
- ['name-segment'](node, ctx) {
296
- const child = node.children.find(({
297
- type
298
- }) => ['name-selector', 'member-name-shorthand'].includes(type));
299
- return transformCSTtoAST(child, transformers, ctx);
300
- },
301
- ['index-segment'](node, ctx) {
302
- const child = node.children.find(({
303
- type
304
- }) => type === 'index-selector');
305
- return transformCSTtoAST(child, transformers, ctx);
306
- },
307
- /**
308
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.4
309
- */
310
- ['function-expr'](node, ctx) {
311
- const name = node.children.find(({
312
- type
313
- }) => type === 'function-name');
314
- const args = node.children.filter(({
315
- type
316
- }) => type === 'function-argument');
317
- return {
318
- type: 'FunctionExpr',
319
- name: name.text,
320
- arguments: args.map(arg => transformCSTtoAST(arg, transformers, ctx))
321
- };
322
- },
323
- ['function-argument'](node, ctx) {
324
- const child = node.children.find(({
325
- type
326
- }) => ['logical-expr', 'function-expr', 'filter-query', 'literal'].includes(type));
327
- return transformCSTtoAST(child, transformers, ctx);
328
- },
329
- /**
330
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.5.1.1
331
- */
332
- ['child-segment'](node, ctx) {
333
- const child = node.children.find(({
334
- type
335
- }) => ['bracketed-selection', 'wildcard-selector', 'member-name-shorthand'].includes(type));
336
- return {
337
- type: 'ChildSegment',
338
- selector: transformCSTtoAST(child, transformers, ctx)
339
- };
340
- },
341
- ['bracketed-selection'](node, ctx) {
342
- return {
343
- type: 'BracketedSelection',
344
- selectors: node.children.filter(({
345
- type
346
- }) => type === 'selector').map(selectorNode => transformCSTtoAST(selectorNode, transformers, ctx))
347
- };
348
- },
349
- ['member-name-shorthand'](node) {
350
- return {
351
- type: 'NameSelector',
352
- value: node.text,
353
- format: 'shorthand'
354
- };
355
- },
356
- /**
357
- * https://www.rfc-editor.org/rfc/rfc9535#section-2.5.2.1
358
- */
359
- ['descendant-segment'](node, ctx) {
360
- const child = node.children.find(({
361
- type
362
- }) => ['bracketed-selection', 'wildcard-selector', 'member-name-shorthand'].includes(type));
363
- return {
364
- type: 'DescendantSegment',
365
- selector: transformCSTtoAST(child, transformers, ctx)
366
- };
367
- },
368
- /**
369
- * https://www.rfc-editor.org/rfc/rfc9535#name-normalized-paths
370
- */
371
- ['normalized-path'](node, ctx) {
372
- return {
373
- type: 'JsonPathQuery',
374
- segments: node.children.filter(({
375
- type
376
- }) => type === 'normal-index-segment').map(segNode => transformCSTtoAST(segNode, transformers, ctx))
377
- };
378
- },
379
- ['normal-index-segment'](node, ctx) {
380
- const child = node.children.find(({
381
- type
382
- }) => type === 'normal-selector');
383
- return {
384
- type: 'ChildSegment',
385
- selector: transformCSTtoAST(child, transformers, ctx)
386
- };
387
- },
388
- ['normal-selector'](node, ctx) {
389
- const child = node.children.find(({
390
- type
391
- }) => ['normal-name-selector', 'normal-index-selector'].includes(type));
392
- return transformCSTtoAST(child, transformers, ctx);
393
- },
394
- ['normal-name-selector'](node) {
395
- const child = node.children.find(({
396
- type
397
- }) => type === 'normal-single-quoted');
398
- return {
399
- type: 'NameSelector',
400
- value: child ? (0, _decoders.decodeSingleQuotedString)(child.text) : '',
401
- format: 'single-quoted'
402
- };
403
- },
404
- ['normal-index-selector'](node) {
405
- return {
406
- type: 'IndexSelector',
407
- value: (0, _decoders.decodeInteger)(node.text)
408
- };
409
- }
410
- };
411
- var _default = exports.default = transformers;