@swaggerexpert/jsonpath 3.2.3 → 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.
- package/cjs/apg-lite.cjs +1221 -0
- package/cjs/compile.cjs +50 -0
- package/cjs/errors/JSONPathCompileError.cjs +8 -0
- package/cjs/errors/JSONPathError.cjs +44 -0
- package/cjs/errors/JSONPathParseError.cjs +8 -0
- package/cjs/escape.cjs +59 -0
- package/cjs/grammar.cjs +2839 -0
- package/cjs/index.cjs +31 -0
- package/cjs/parse/callbacks/cst.cjs +49 -0
- package/cjs/parse/index.cjs +41 -0
- package/cjs/parse/trace/Expectations.cjs +10 -0
- package/cjs/parse/trace/Trace.cjs +35 -0
- package/cjs/parse/translators/ASTTranslator/decoders.cjs +83 -0
- package/cjs/parse/translators/ASTTranslator/index.cjs +15 -0
- package/cjs/parse/translators/ASTTranslator/transformers.cjs +411 -0
- package/cjs/parse/translators/CSTOptimizedTranslator.cjs +39 -0
- package/cjs/parse/translators/CSTTranslator.cjs +118 -0
- package/cjs/parse/translators/XMLTranslator.cjs +12 -0
- package/cjs/test/index.cjs +25 -0
- package/es/compile.mjs +45 -0
- package/es/errors/JSONPathCompileError.mjs +3 -0
- package/es/errors/JSONPathError.mjs +40 -0
- package/es/errors/JSONPathParseError.mjs +3 -0
- package/es/escape.mjs +55 -0
- package/es/grammar.mjs +2835 -0
- package/es/index.mjs +13 -0
- package/es/parse/callbacks/cst.mjs +44 -0
- package/es/parse/index.mjs +36 -0
- package/es/parse/trace/Expectations.mjs +6 -0
- package/es/parse/trace/Trace.mjs +30 -0
- package/es/parse/translators/ASTTranslator/decoders.mjs +75 -0
- package/es/parse/translators/ASTTranslator/index.mjs +9 -0
- package/es/parse/translators/ASTTranslator/transformers.mjs +405 -0
- package/es/parse/translators/CSTOptimizedTranslator.mjs +34 -0
- package/es/parse/translators/CSTTranslator.mjs +113 -0
- package/es/parse/translators/XMLTranslator.mjs +7 -0
- package/es/test/index.mjs +20 -0
- package/package.json +1 -1
package/cjs/compile.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _escape = _interopRequireDefault(require("./escape.cjs"));
|
|
6
|
+
var _JSONPathCompileError = _interopRequireDefault(require("./errors/JSONPathCompileError.cjs"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
/**
|
|
9
|
+
* Compiles an array of selectors into a normalized JSONPath.
|
|
10
|
+
* Follows RFC 9535 Section 2.7 normalized path format.
|
|
11
|
+
*
|
|
12
|
+
* @param {Array<string|number>} selectors - Array of name selectors (strings) or index selectors (numbers)
|
|
13
|
+
* @returns {string} A normalized JSONPath string
|
|
14
|
+
* @throws {JSONPathCompileError} If selectors is not an array or contains invalid selector types
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* compile(['a', 'b', 1]) // returns "$['a']['b'][1]"
|
|
18
|
+
* compile([]) // returns "$"
|
|
19
|
+
* compile(['foo', 0, 'bar']) // returns "$['foo'][0]['bar']"
|
|
20
|
+
*/
|
|
21
|
+
const compile = selectors => {
|
|
22
|
+
if (!Array.isArray(selectors)) {
|
|
23
|
+
throw new _JSONPathCompileError.default(`Selectors must be an array, got: ${typeof selectors}`, {
|
|
24
|
+
selectors
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const segments = selectors.map(selector => {
|
|
29
|
+
if (typeof selector === 'string') {
|
|
30
|
+
// Name selector: escape and wrap in single quotes
|
|
31
|
+
return `['${(0, _escape.default)(selector)}']`;
|
|
32
|
+
}
|
|
33
|
+
if (typeof selector === 'number') {
|
|
34
|
+
// Index selector: must be a non-negative safe integer (RFC 9535 Section 2.1)
|
|
35
|
+
if (!Number.isSafeInteger(selector) || selector < 0) {
|
|
36
|
+
throw new TypeError(`Index selector must be a non-negative safe integer, got: ${selector}`);
|
|
37
|
+
}
|
|
38
|
+
return `[${selector}]`;
|
|
39
|
+
}
|
|
40
|
+
throw new TypeError(`Selector must be a string or non-negative integer, got: ${typeof selector}`);
|
|
41
|
+
});
|
|
42
|
+
return `$${segments.join('')}`;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new _JSONPathCompileError.default('Failed to compile normalized JSONPath', {
|
|
45
|
+
cause: error,
|
|
46
|
+
selectors
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var _default = exports.default = compile;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _JSONPathError = _interopRequireDefault(require("./JSONPathError.cjs"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
class JSONPathCompileError extends _JSONPathError.default {}
|
|
8
|
+
var _default = exports.default = JSONPathCompileError;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
class JSONPathError extends Error {
|
|
6
|
+
constructor(message, options = undefined) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = this.constructor.name;
|
|
9
|
+
if (typeof message === 'string') {
|
|
10
|
+
this.message = message;
|
|
11
|
+
}
|
|
12
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
} else {
|
|
15
|
+
this.stack = new Error(message).stack;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This needs to stay here until our minimum supported version of Node.js is >= 16.9.0.
|
|
20
|
+
* Node.js is >= 16.9.0 supports error causes natively.
|
|
21
|
+
*/
|
|
22
|
+
if (options != null && typeof options === 'object' && Object.prototype.hasOwnProperty.call(options, 'cause') && !('cause' in this)) {
|
|
23
|
+
const {
|
|
24
|
+
cause
|
|
25
|
+
} = options;
|
|
26
|
+
this.cause = cause;
|
|
27
|
+
if (cause instanceof Error && 'stack' in cause) {
|
|
28
|
+
this.stack = `${this.stack}\nCAUSE: ${cause.stack}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Allows to assign arbitrary properties to the error object.
|
|
34
|
+
*/
|
|
35
|
+
if (options != null && typeof options === 'object') {
|
|
36
|
+
const {
|
|
37
|
+
cause,
|
|
38
|
+
...causelessOptions
|
|
39
|
+
} = options;
|
|
40
|
+
Object.assign(this, causelessOptions);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var _default = exports.default = JSONPathError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _JSONPathError = _interopRequireDefault(require("./JSONPathError.cjs"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
class JSONPathParseError extends _JSONPathError.default {}
|
|
8
|
+
var _default = exports.default = JSONPathParseError;
|
package/cjs/escape.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Escapes a string for use in a normalized JSONPath name selector.
|
|
7
|
+
* Follows RFC 9535 Section 2.7 escaping rules for single-quoted strings.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} selector - The string to escape
|
|
10
|
+
* @returns {string} The escaped string (without surrounding quotes)
|
|
11
|
+
*/
|
|
12
|
+
const escape = selector => {
|
|
13
|
+
if (typeof selector !== 'string') {
|
|
14
|
+
throw new TypeError('Selector must be a string');
|
|
15
|
+
}
|
|
16
|
+
let escaped = '';
|
|
17
|
+
for (const char of selector) {
|
|
18
|
+
const codePoint = char.codePointAt(0);
|
|
19
|
+
switch (codePoint) {
|
|
20
|
+
case 0x08:
|
|
21
|
+
// backspace
|
|
22
|
+
escaped += '\\b';
|
|
23
|
+
break;
|
|
24
|
+
case 0x09:
|
|
25
|
+
// horizontal tab
|
|
26
|
+
escaped += '\\t';
|
|
27
|
+
break;
|
|
28
|
+
case 0x0a:
|
|
29
|
+
// line feed
|
|
30
|
+
escaped += '\\n';
|
|
31
|
+
break;
|
|
32
|
+
case 0x0c:
|
|
33
|
+
// form feed
|
|
34
|
+
escaped += '\\f';
|
|
35
|
+
break;
|
|
36
|
+
case 0x0d:
|
|
37
|
+
// carriage return
|
|
38
|
+
escaped += '\\r';
|
|
39
|
+
break;
|
|
40
|
+
case 0x27:
|
|
41
|
+
// apostrophe '
|
|
42
|
+
escaped += "\\'";
|
|
43
|
+
break;
|
|
44
|
+
case 0x5c:
|
|
45
|
+
// backslash \
|
|
46
|
+
escaped += '\\\\';
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
// Other control characters (U+0000-U+001F except those handled above)
|
|
50
|
+
if (codePoint <= 0x1f) {
|
|
51
|
+
escaped += `\\u${codePoint.toString(16).padStart(4, '0')}`;
|
|
52
|
+
} else {
|
|
53
|
+
escaped += char;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return escaped;
|
|
58
|
+
};
|
|
59
|
+
var _default = exports.default = escape;
|