@swagger-api/apidom-json-path 0.75.0 → 0.76.1
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 +10 -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 +1562 -293
- 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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
+
import { hasElementSourceMap, toValue } from '@swagger-api/apidom-core';
|
|
3
|
+
import JsonPathError from "./JsonPathError.js";
|
|
4
|
+
class EvaluationJsonPathError extends JsonPathError {
|
|
5
|
+
constructor(message, structuredOptions) {
|
|
6
|
+
super(message, structuredOptions);
|
|
7
|
+
_defineProperty(this, "path", void 0);
|
|
8
|
+
_defineProperty(this, "element", void 0);
|
|
9
|
+
_defineProperty(this, "elementSourceMap", void 0);
|
|
10
|
+
if (typeof structuredOptions !== 'undefined') {
|
|
11
|
+
this.path = structuredOptions.path;
|
|
12
|
+
this.element = structuredOptions.element.element;
|
|
13
|
+
if (hasElementSourceMap(structuredOptions.element)) {
|
|
14
|
+
this.elementSourceMap = toValue(structuredOptions.element.getMetaProperty('sourceMap'));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export default EvaluationJsonPathError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
+
import { hasElementSourceMap, toValue } from '@swagger-api/apidom-core';
|
|
3
|
+
import JsonPathError from "./JsonPathError.js";
|
|
4
|
+
class MultiEvaluationJsonPathError extends JsonPathError {
|
|
5
|
+
constructor(message, structuredOptions) {
|
|
6
|
+
super(message, structuredOptions);
|
|
7
|
+
_defineProperty(this, "paths", void 0);
|
|
8
|
+
_defineProperty(this, "element", void 0);
|
|
9
|
+
_defineProperty(this, "elementSourceMap", void 0);
|
|
10
|
+
if (typeof structuredOptions !== 'undefined') {
|
|
11
|
+
this.paths = structuredOptions.paths;
|
|
12
|
+
this.element = structuredOptions.element.element;
|
|
13
|
+
if (hasElementSourceMap(structuredOptions.element)) {
|
|
14
|
+
this.elementSourceMap = toValue(structuredOptions.element.getMetaProperty('sourceMap'));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export default MultiEvaluationJsonPathError;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { JSONPath } from 'jsonpath-plus';
|
|
2
|
+
import { toValue } from '@swagger-api/apidom-core';
|
|
3
|
+
import { evaluate as jsonPointerEvaluate } from '@swagger-api/apidom-json-pointer';
|
|
4
|
+
import MultiEvaluationJsonPathError from "./errors/MultiEvaluationJsonPathError.js";
|
|
5
|
+
/**
|
|
6
|
+
* Evaluates multiple JSONPaths on ApiDOM element.
|
|
7
|
+
*/
|
|
8
|
+
const evaluateMulti = (paths, element) => {
|
|
9
|
+
try {
|
|
10
|
+
const json = toValue(element);
|
|
11
|
+
const results = [];
|
|
12
|
+
for (const path of paths) {
|
|
13
|
+
const pointers = JSONPath({
|
|
14
|
+
path,
|
|
15
|
+
json,
|
|
16
|
+
resultType: 'pointer'
|
|
17
|
+
});
|
|
18
|
+
const endPointValues = [];
|
|
19
|
+
for (const pointer of pointers) {
|
|
20
|
+
const endPointValue = jsonPointerEvaluate(pointer, element);
|
|
21
|
+
endPointValues.push(endPointValue);
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(path)) {
|
|
24
|
+
results.push([JSONPath.toPathString(path), endPointValues]);
|
|
25
|
+
} else {
|
|
26
|
+
results.push([path, endPointValues]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return results;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new MultiEvaluationJsonPathError(`JSON Path evaluation failed while multi-evaluating "${String(paths)}".`, {
|
|
32
|
+
paths,
|
|
33
|
+
element,
|
|
34
|
+
cause: error
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export default evaluateMulti;
|
package/es/evaluate.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { JSONPath } from 'jsonpath-plus';
|
|
2
|
+
import { toValue } from '@swagger-api/apidom-core';
|
|
3
|
+
import { evaluate as jsonPointerEvaluate } from '@swagger-api/apidom-json-pointer';
|
|
4
|
+
import EvaluationJsonPathError from "./errors/EvaluationJsonPathError.js";
|
|
5
|
+
/**
|
|
6
|
+
* Evaluates single JSONPath on ApiDOM element.
|
|
7
|
+
*/
|
|
8
|
+
const evaluate = (path, element) => {
|
|
9
|
+
try {
|
|
10
|
+
const json = toValue(element);
|
|
11
|
+
const pointers = JSONPath({
|
|
12
|
+
path,
|
|
13
|
+
json,
|
|
14
|
+
resultType: 'pointer'
|
|
15
|
+
});
|
|
16
|
+
return pointers.map(pointer => jsonPointerEvaluate(pointer, element));
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new EvaluationJsonPathError(`JSON Path evaluation failed while evaluating "${String(path)}".`, {
|
|
19
|
+
path,
|
|
20
|
+
element,
|
|
21
|
+
cause: error
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export default evaluate;
|
package/es/index.js
CHANGED
|
@@ -1,41 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Evaluates single JSONPath on ApiDOM element.
|
|
6
|
-
*/
|
|
7
|
-
export const evaluate = (path, element) => {
|
|
8
|
-
const json = toValue(element);
|
|
9
|
-
const pointers = JSONPath({
|
|
10
|
-
path,
|
|
11
|
-
json,
|
|
12
|
-
resultType: 'pointer'
|
|
13
|
-
});
|
|
14
|
-
return pointers.map(pointer => jsonPointerEvaluate(pointer, element));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Evaluates multiple JSONPaths on ApiDOM element.
|
|
19
|
-
*/
|
|
20
|
-
export const evaluateMulti = (paths, element) => {
|
|
21
|
-
const json = toValue(element);
|
|
22
|
-
const results = [];
|
|
23
|
-
for (const path of paths) {
|
|
24
|
-
const pointers = JSONPath({
|
|
25
|
-
path,
|
|
26
|
-
json,
|
|
27
|
-
resultType: 'pointer'
|
|
28
|
-
});
|
|
29
|
-
const endPointValues = [];
|
|
30
|
-
for (const pointer of pointers) {
|
|
31
|
-
const endPointValue = jsonPointerEvaluate(pointer, element);
|
|
32
|
-
endPointValues.push(endPointValue);
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(path)) {
|
|
35
|
-
results.push([JSONPath.toPathString(path), endPointValues]);
|
|
36
|
-
} else {
|
|
37
|
-
results.push([path, endPointValues]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return results;
|
|
41
|
-
};
|
|
1
|
+
export { default as EvaluationJsonPathError } from "./errors/EvaluationJsonPathError.js";
|
|
2
|
+
export { default as MultiEvaluationJsonPathError } from "./errors/MultiEvaluationJsonPathError.js";
|
|
3
|
+
export { default as evaluate } from "./evaluate.js";
|
|
4
|
+
export { default as evaluateMulti } from "./evaluate-multi.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swagger-api/apidom-json-path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.1",
|
|
4
4
|
"description": "Evaluate JSONPath expressions against ApiDOM.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
"license": "Apache-2.0",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/runtime-corejs3": "^7.20.7",
|
|
41
|
-
"@swagger-api/apidom-core": "^0.
|
|
42
|
-
"@swagger-api/apidom-
|
|
41
|
+
"@swagger-api/apidom-core": "^0.76.1",
|
|
42
|
+
"@swagger-api/apidom-error": "^0.76.1",
|
|
43
|
+
"@swagger-api/apidom-json-pointer": "^0.76.1",
|
|
43
44
|
"jsonpath-plus": "^7.2.0"
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"README.md",
|
|
53
54
|
"CHANGELOG.md"
|
|
54
55
|
],
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "33290820a04e212ffb88da36abaa8cc1fb06892f"
|
|
56
57
|
}
|
package/types/dist.d.ts
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
1
|
import { Element } from '@swagger-api/apidom-core';
|
|
2
|
+
import { ApiDOMStructuredError, ApiDOMErrorOptions } from '@swagger-api/apidom-error';
|
|
3
|
+
|
|
4
|
+
declare class JsonPathError extends ApiDOMStructuredError {
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface EvaluationJsonPathErrorOptions<T extends Element> extends ApiDOMErrorOptions {
|
|
8
|
+
path: string | string[];
|
|
9
|
+
element: T;
|
|
10
|
+
}
|
|
11
|
+
declare class EvaluationJsonPathError<T extends Element> extends JsonPathError {
|
|
12
|
+
readonly path: string | string[];
|
|
13
|
+
readonly element: string;
|
|
14
|
+
readonly elementSourceMap?: [[number, number, number], [number, number, number]];
|
|
15
|
+
constructor(message?: string, structuredOptions?: EvaluationJsonPathErrorOptions<T>);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface MultiEvaluationJsonPathErrorOptions<T extends Element> extends ApiDOMErrorOptions {
|
|
19
|
+
paths: string[] | string[][];
|
|
20
|
+
element: T;
|
|
21
|
+
}
|
|
22
|
+
declare class MultiEvaluationJsonPathError<T extends Element> extends JsonPathError {
|
|
23
|
+
readonly paths: string[] | string[][];
|
|
24
|
+
readonly element: string;
|
|
25
|
+
readonly elementSourceMap?: [[number, number, number], [number, number, number]];
|
|
26
|
+
constructor(message?: string, structuredOptions?: MultiEvaluationJsonPathErrorOptions<T>);
|
|
27
|
+
}
|
|
2
28
|
|
|
3
29
|
type Evaluate = {
|
|
4
30
|
<T extends Element>(path: string, element: T): Element[];
|
|
5
31
|
<T extends Element>(path: string[], element: T): Element[];
|
|
6
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates single JSONPath on ApiDOM element.
|
|
35
|
+
*/
|
|
36
|
+
declare const evaluate: Evaluate;
|
|
37
|
+
|
|
7
38
|
type JSONPathEvalTuple = [string, Element[]];
|
|
8
39
|
type EvaluateMulti = {
|
|
9
40
|
<T extends Element>(paths: string[], element: T): JSONPathEvalTuple[];
|
|
10
41
|
<T extends Element>(paths: string[][], element: T): JSONPathEvalTuple[];
|
|
11
42
|
};
|
|
12
|
-
/**
|
|
13
|
-
* Evaluates single JSONPath on ApiDOM element.
|
|
14
|
-
*/
|
|
15
|
-
declare const evaluate: Evaluate;
|
|
16
43
|
/**
|
|
17
44
|
* Evaluates multiple JSONPaths on ApiDOM element.
|
|
18
45
|
*/
|
|
19
46
|
declare const evaluateMulti: EvaluateMulti;
|
|
20
47
|
|
|
21
|
-
export { evaluate, evaluateMulti };
|
|
48
|
+
export { EvaluationJsonPathError, EvaluationJsonPathErrorOptions, MultiEvaluationJsonPathError, MultiEvaluationJsonPathErrorOptions, evaluate, evaluateMulti };
|