@speclynx/apidom-json-path 2.0.1 → 2.2.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.
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.default = void 0;
6
- var _jsonpathPlus = require("jsonpath-plus");
7
- var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
8
- var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
- var _apidomCore = require("@speclynx/apidom-core");
10
- var _MultiEvaluationJsonPathError = _interopRequireDefault(require("./errors/MultiEvaluationJsonPathError.cjs"));
11
- /**
12
- * @public
13
- */
14
-
15
- /**
16
- * @public
17
- */
18
-
19
- /**
20
- * Evaluates multiple JSONPaths on ApiDOM element.
21
- * @public
22
- */
23
- const evaluateMulti = (paths, element) => {
24
- try {
25
- const json = (0, _apidomCore.toValue)(element);
26
- const results = [];
27
- for (const path of paths) {
28
- const pointers = (0, _jsonpathPlus.JSONPath)({
29
- path,
30
- json,
31
- resultType: 'pointer'
32
- });
33
- const endPointValues = [];
34
- for (const pointer of pointers) {
35
- const endPointValue = (0, _apidomJsonPointer.evaluate)(element, pointer);
36
- endPointValues.push(endPointValue);
37
- }
38
- if (Array.isArray(path)) {
39
- results.push([_jsonpathPlus.JSONPath.toPathString(path), endPointValues]);
40
- } else {
41
- results.push([path, endPointValues]);
42
- }
43
- }
44
- return results;
45
- } catch (error) {
46
- throw new _MultiEvaluationJsonPathError.default(`JSON Path evaluation failed while multi-evaluating "${String(paths)}".`, {
47
- paths,
48
- element: (0, _apidomDatamodel.cloneDeep)(element),
49
- cause: error
50
- });
51
- }
52
- };
53
- var _default = exports.default = evaluateMulti;
@@ -1,46 +0,0 @@
1
- import { JSONPath } from 'jsonpath-plus';
2
- import { evaluate as jsonPointerEvaluate } from '@speclynx/apidom-json-pointer';
3
- import { cloneDeep } from '@speclynx/apidom-datamodel';
4
- import { toValue } from '@speclynx/apidom-core';
5
- import MultiEvaluationJsonPathError from "./errors/MultiEvaluationJsonPathError.mjs";
6
- /**
7
- * @public
8
- */
9
- /**
10
- * @public
11
- */
12
- /**
13
- * Evaluates multiple JSONPaths on ApiDOM element.
14
- * @public
15
- */
16
- const evaluateMulti = (paths, element) => {
17
- try {
18
- const json = toValue(element);
19
- const results = [];
20
- for (const path of paths) {
21
- const pointers = JSONPath({
22
- path,
23
- json,
24
- resultType: 'pointer'
25
- });
26
- const endPointValues = [];
27
- for (const pointer of pointers) {
28
- const endPointValue = jsonPointerEvaluate(element, pointer);
29
- endPointValues.push(endPointValue);
30
- }
31
- if (Array.isArray(path)) {
32
- results.push([JSONPath.toPathString(path), endPointValues]);
33
- } else {
34
- results.push([path, endPointValues]);
35
- }
36
- }
37
- return results;
38
- } catch (error) {
39
- throw new MultiEvaluationJsonPathError(`JSON Path evaluation failed while multi-evaluating "${String(paths)}".`, {
40
- paths,
41
- element: cloneDeep(element),
42
- cause: error
43
- });
44
- }
45
- };
46
- export default evaluateMulti;
package/src/evaluate.cjs DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.default = void 0;
6
- var _jsonpathPlus = require("jsonpath-plus");
7
- var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
8
- var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
- var _apidomCore = require("@speclynx/apidom-core");
10
- var _EvaluationJsonPathError = _interopRequireDefault(require("./errors/EvaluationJsonPathError.cjs"));
11
- /**
12
- * @public
13
- */
14
-
15
- /**
16
- * Evaluates single JSONPath on ApiDOM element.
17
- * @public
18
- */
19
- const evaluate = (path, element) => {
20
- try {
21
- const json = (0, _apidomCore.toValue)(element);
22
- const pointers = (0, _jsonpathPlus.JSONPath)({
23
- path,
24
- json,
25
- resultType: 'pointer'
26
- });
27
- return pointers.map(pointer => (0, _apidomJsonPointer.evaluate)(element, pointer));
28
- } catch (error) {
29
- throw new _EvaluationJsonPathError.default(`JSON Path evaluation failed while evaluating "${String(path)}".`, {
30
- path,
31
- element: (0, _apidomDatamodel.cloneDeep)(element),
32
- cause: error
33
- });
34
- }
35
- };
36
- var _default = exports.default = evaluate;
package/src/evaluate.mjs DELETED
@@ -1,30 +0,0 @@
1
- import { JSONPath } from 'jsonpath-plus';
2
- import { evaluate as jsonPointerEvaluate } from '@speclynx/apidom-json-pointer';
3
- import { cloneDeep } from '@speclynx/apidom-datamodel';
4
- import { toValue } from '@speclynx/apidom-core';
5
- import EvaluationJsonPathError from "./errors/EvaluationJsonPathError.mjs";
6
- /**
7
- * @public
8
- */
9
- /**
10
- * Evaluates single JSONPath on ApiDOM element.
11
- * @public
12
- */
13
- const evaluate = (path, element) => {
14
- try {
15
- const json = toValue(element);
16
- const pointers = JSONPath({
17
- path,
18
- json,
19
- resultType: 'pointer'
20
- });
21
- return pointers.map(pointer => jsonPointerEvaluate(element, pointer));
22
- } catch (error) {
23
- throw new EvaluationJsonPathError(`JSON Path evaluation failed while evaluating "${String(path)}".`, {
24
- path,
25
- element: cloneDeep(element),
26
- cause: error
27
- });
28
- }
29
- };
30
- export default evaluate;