@swagger-api/apidom-json-path 0.75.0 → 0.76.0
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/CHANGELOG.md +6 -0
- package/cjs/errors/EvaluationJsonPathError.cjs +21 -0
- package/cjs/errors/JsonPathError.cjs +8 -0
- package/cjs/errors/MultiEvaluationJsonPathError.cjs +21 -0
- package/cjs/evaluate-multi.cjs +44 -0
- package/cjs/evaluate.cjs +31 -0
- package/cjs/index.cjs +10 -44
- package/dist/apidom-json-path.browser.js +577 -212
- package/dist/apidom-json-path.browser.min.js +1 -1
- package/es/errors/EvaluationJsonPathError.js +19 -0
- package/es/errors/JsonPathError.js +3 -0
- package/es/errors/MultiEvaluationJsonPathError.js +19 -0
- package/es/evaluate-multi.js +38 -0
- package/es/evaluate.js +25 -0
- package/es/index.js +4 -41
- package/package.json +5 -4
- package/types/dist.d.ts +32 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.76.0](https://github.com/swagger-api/apidom/compare/v0.75.0...v0.76.0) (2023-09-01)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **json-path:** use error hierarchy and metadata when throwing errors ([#3107](https://github.com/swagger-api/apidom/issues/3107)) ([d55a846](https://github.com/swagger-api/apidom/commit/d55a8466de9814f19aedbacb48c55761f2f3fe38)), closes [#3039](https://github.com/swagger-api/apidom/issues/3039)
|
|
11
|
+
|
|
6
12
|
# [0.75.0](https://github.com/swagger-api/apidom/compare/v0.74.1...v0.75.0) (2023-08-22)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @swagger-api/apidom-json-path
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _JsonPathError = _interopRequireDefault(require("./JsonPathError.cjs"));
|
|
8
|
+
class EvaluationJsonPathError extends _JsonPathError.default {
|
|
9
|
+
constructor(message, structuredOptions) {
|
|
10
|
+
super(message, structuredOptions);
|
|
11
|
+
if (typeof structuredOptions !== 'undefined') {
|
|
12
|
+
this.path = structuredOptions.path;
|
|
13
|
+
this.element = structuredOptions.element.element;
|
|
14
|
+
if ((0, _apidomCore.hasElementSourceMap)(structuredOptions.element)) {
|
|
15
|
+
this.elementSourceMap = (0, _apidomCore.toValue)(structuredOptions.element.getMetaProperty('sourceMap'));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var _default = EvaluationJsonPathError;
|
|
21
|
+
exports.default = _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _JsonPathError = _interopRequireDefault(require("./JsonPathError.cjs"));
|
|
8
|
+
class MultiEvaluationJsonPathError extends _JsonPathError.default {
|
|
9
|
+
constructor(message, structuredOptions) {
|
|
10
|
+
super(message, structuredOptions);
|
|
11
|
+
if (typeof structuredOptions !== 'undefined') {
|
|
12
|
+
this.paths = structuredOptions.paths;
|
|
13
|
+
this.element = structuredOptions.element.element;
|
|
14
|
+
if ((0, _apidomCore.hasElementSourceMap)(structuredOptions.element)) {
|
|
15
|
+
this.elementSourceMap = (0, _apidomCore.toValue)(structuredOptions.element.getMetaProperty('sourceMap'));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var _default = MultiEvaluationJsonPathError;
|
|
21
|
+
exports.default = _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _jsonpathPlus = require("jsonpath-plus");
|
|
7
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
|
+
var _apidomJsonPointer = require("@swagger-api/apidom-json-pointer");
|
|
9
|
+
var _MultiEvaluationJsonPathError = _interopRequireDefault(require("./errors/MultiEvaluationJsonPathError.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* Evaluates multiple JSONPaths on ApiDOM element.
|
|
12
|
+
*/
|
|
13
|
+
const evaluateMulti = (paths, element) => {
|
|
14
|
+
try {
|
|
15
|
+
const json = (0, _apidomCore.toValue)(element);
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const path of paths) {
|
|
18
|
+
const pointers = (0, _jsonpathPlus.JSONPath)({
|
|
19
|
+
path,
|
|
20
|
+
json,
|
|
21
|
+
resultType: 'pointer'
|
|
22
|
+
});
|
|
23
|
+
const endPointValues = [];
|
|
24
|
+
for (const pointer of pointers) {
|
|
25
|
+
const endPointValue = (0, _apidomJsonPointer.evaluate)(pointer, element);
|
|
26
|
+
endPointValues.push(endPointValue);
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(path)) {
|
|
29
|
+
results.push([_jsonpathPlus.JSONPath.toPathString(path), endPointValues]);
|
|
30
|
+
} else {
|
|
31
|
+
results.push([path, endPointValues]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new _MultiEvaluationJsonPathError.default(`JSON Path evaluation failed while multi-evaluating "${String(paths)}".`, {
|
|
37
|
+
paths,
|
|
38
|
+
element,
|
|
39
|
+
cause: error
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var _default = evaluateMulti;
|
|
44
|
+
exports.default = _default;
|
package/cjs/evaluate.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _jsonpathPlus = require("jsonpath-plus");
|
|
7
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
|
+
var _apidomJsonPointer = require("@swagger-api/apidom-json-pointer");
|
|
9
|
+
var _EvaluationJsonPathError = _interopRequireDefault(require("./errors/EvaluationJsonPathError.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* Evaluates single JSONPath on ApiDOM element.
|
|
12
|
+
*/
|
|
13
|
+
const evaluate = (path, element) => {
|
|
14
|
+
try {
|
|
15
|
+
const json = (0, _apidomCore.toValue)(element);
|
|
16
|
+
const pointers = (0, _jsonpathPlus.JSONPath)({
|
|
17
|
+
path,
|
|
18
|
+
json,
|
|
19
|
+
resultType: 'pointer'
|
|
20
|
+
});
|
|
21
|
+
return pointers.map(pointer => (0, _apidomJsonPointer.evaluate)(pointer, element));
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new _EvaluationJsonPathError.default(`JSON Path evaluation failed while evaluating "${String(path)}".`, {
|
|
24
|
+
path,
|
|
25
|
+
element,
|
|
26
|
+
cause: error
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var _default = evaluate;
|
|
31
|
+
exports.default = _default;
|
package/cjs/index.cjs
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
3
4
|
exports.__esModule = true;
|
|
4
|
-
exports.evaluateMulti = exports.evaluate = void 0;
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const pointers = (0, _jsonpathPlus.JSONPath)({
|
|
14
|
-
path,
|
|
15
|
-
json,
|
|
16
|
-
resultType: 'pointer'
|
|
17
|
-
});
|
|
18
|
-
return pointers.map(pointer => (0, _apidomJsonPointer.evaluate)(pointer, element));
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Evaluates multiple JSONPaths on ApiDOM element.
|
|
23
|
-
*/
|
|
24
|
-
exports.evaluate = evaluate;
|
|
25
|
-
const evaluateMulti = (paths, element) => {
|
|
26
|
-
const json = (0, _apidomCore.toValue)(element);
|
|
27
|
-
const results = [];
|
|
28
|
-
for (const path of paths) {
|
|
29
|
-
const pointers = (0, _jsonpathPlus.JSONPath)({
|
|
30
|
-
path,
|
|
31
|
-
json,
|
|
32
|
-
resultType: 'pointer'
|
|
33
|
-
});
|
|
34
|
-
const endPointValues = [];
|
|
35
|
-
for (const pointer of pointers) {
|
|
36
|
-
const endPointValue = (0, _apidomJsonPointer.evaluate)(pointer, element);
|
|
37
|
-
endPointValues.push(endPointValue);
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(path)) {
|
|
40
|
-
results.push([_jsonpathPlus.JSONPath.toPathString(path), endPointValues]);
|
|
41
|
-
} else {
|
|
42
|
-
results.push([path, endPointValues]);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return results;
|
|
46
|
-
};
|
|
47
|
-
exports.evaluateMulti = evaluateMulti;
|
|
5
|
+
exports.evaluateMulti = exports.evaluate = exports.MultiEvaluationJsonPathError = exports.EvaluationJsonPathError = void 0;
|
|
6
|
+
var _EvaluationJsonPathError = _interopRequireDefault(require("./errors/EvaluationJsonPathError.cjs"));
|
|
7
|
+
exports.EvaluationJsonPathError = _EvaluationJsonPathError.default;
|
|
8
|
+
var _MultiEvaluationJsonPathError = _interopRequireDefault(require("./errors/MultiEvaluationJsonPathError.cjs"));
|
|
9
|
+
exports.MultiEvaluationJsonPathError = _MultiEvaluationJsonPathError.default;
|
|
10
|
+
var _evaluate = _interopRequireDefault(require("./evaluate.cjs"));
|
|
11
|
+
exports.evaluate = _evaluate.default;
|
|
12
|
+
var _evaluateMulti = _interopRequireDefault(require("./evaluate-multi.cjs"));
|
|
13
|
+
exports.evaluateMulti = _evaluateMulti.default;
|