@speclynx/apidom-json-pointer-relative 1.12.2 → 2.1.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 +18 -0
- package/NOTICE +16 -7
- package/dist/apidom-json-pointer-relative.browser.js +9411 -10416
- package/dist/apidom-json-pointer-relative.browser.min.js +1 -1
- package/package.json +7 -6
- package/src/evaluate.cjs +33 -32
- package/src/evaluate.mjs +10 -9
- package/types/apidom-json-pointer-relative.d.ts +1 -1
package/src/evaluate.cjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
var
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
7
8
|
var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
8
9
|
var _ramda = require("ramda");
|
|
9
10
|
var _EvaluationRelativeJsonPointerError = _interopRequireDefault(require("./errors/EvaluationRelativeJsonPointerError.cjs"));
|
|
@@ -15,21 +16,20 @@ var _parse = _interopRequireDefault(require("./parse.cjs"));
|
|
|
15
16
|
const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
16
17
|
let ancestorLineage = [];
|
|
17
18
|
let cursor = currentElement;
|
|
18
|
-
(0,
|
|
19
|
-
enter(
|
|
20
|
-
if (
|
|
21
|
-
ancestorLineage =
|
|
22
|
-
|
|
19
|
+
(0, _apidomTraverse.traverse)(rootElement, {
|
|
20
|
+
enter(path) {
|
|
21
|
+
if (path.node === currentElement) {
|
|
22
|
+
ancestorLineage = path.getAncestorNodes().reverse().filter(_apidomDatamodel.isElement);
|
|
23
|
+
path.stop();
|
|
23
24
|
}
|
|
24
|
-
return undefined;
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
if (ancestorLineage.length === 0) {
|
|
28
28
|
throw new _EvaluationRelativeJsonPointerError.default('Relative JSON Pointer evaluation failed. Current element not found inside the root element', {
|
|
29
29
|
relativePointer,
|
|
30
|
-
currentElement: (0,
|
|
31
|
-
rootElement: (0,
|
|
32
|
-
cursorElement:
|
|
30
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
31
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(rootElement),
|
|
32
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor)
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
if ((0, _ramda.last)(ancestorLineage) === rootElement) {
|
|
@@ -46,9 +46,9 @@ const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
|
46
46
|
} catch (error) {
|
|
47
47
|
throw new _EvaluationRelativeJsonPointerError.default('Relative JSON Pointer evaluation failed while parsing the pointer.', {
|
|
48
48
|
relativePointer,
|
|
49
|
-
currentElement: (0,
|
|
50
|
-
rootElement: (0,
|
|
51
|
-
cursorElement:
|
|
49
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
50
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
51
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor),
|
|
52
52
|
cause: error
|
|
53
53
|
});
|
|
54
54
|
}
|
|
@@ -60,16 +60,16 @@ const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
|
60
60
|
nonNegativeIntegerPrefix
|
|
61
61
|
} = relativeJsonPointer; nonNegativeIntegerPrefix > 0; nonNegativeIntegerPrefix -= 1) {
|
|
62
62
|
cursor = ancestorLineageCopy.pop();
|
|
63
|
-
if ((0,
|
|
63
|
+
if ((0, _apidomDatamodel.isMemberElement)(cursor)) {
|
|
64
64
|
cursor = ancestorLineageCopy.pop();
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (typeof cursor === 'undefined') {
|
|
68
68
|
throw new _EvaluationRelativeJsonPointerError.default(`Relative JSON Pointer evaluation failed on non-negative-integer prefix of "${relativeJsonPointer.nonNegativeIntegerPrefix}"`, {
|
|
69
69
|
relativePointer,
|
|
70
|
-
currentElement: (0,
|
|
71
|
-
rootElement: (0,
|
|
72
|
-
cursorElement:
|
|
70
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
71
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(rootElement),
|
|
72
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor)
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
ancestorLineage = ancestorLineageCopy;
|
|
@@ -78,23 +78,24 @@ const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
|
78
78
|
// index-manipulation
|
|
79
79
|
if (typeof relativeJsonPointer.indexManipulation === 'number') {
|
|
80
80
|
const containedArray = (0, _ramda.last)(ancestorLineage);
|
|
81
|
-
if (typeof containedArray === 'undefined' || !(0,
|
|
81
|
+
if (typeof containedArray === 'undefined' || !(0, _apidomDatamodel.isArrayElement)(containedArray)) {
|
|
82
82
|
throw new _EvaluationRelativeJsonPointerError.default(`Relative JSON Pointer evaluation failed failed on index-manipulation "${relativeJsonPointer.indexManipulation}"`, {
|
|
83
83
|
relativePointer,
|
|
84
|
-
currentElement: (0,
|
|
85
|
-
rootElement: (0,
|
|
86
|
-
cursorElement:
|
|
84
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
85
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(rootElement),
|
|
86
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor)
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
const
|
|
89
|
+
const arrayContent = containedArray.content;
|
|
90
|
+
const currentCursorIndex = arrayContent.indexOf(cursor);
|
|
90
91
|
const newCursorIndex = currentCursorIndex + relativeJsonPointer.indexManipulation;
|
|
91
|
-
cursor =
|
|
92
|
+
cursor = arrayContent[newCursorIndex];
|
|
92
93
|
if (typeof cursor === 'undefined') {
|
|
93
94
|
throw new _EvaluationRelativeJsonPointerError.default(`Relative JSON Pointer evaluation failed on index-manipulation "${relativeJsonPointer.indexManipulation}"`, {
|
|
94
95
|
relativePointer,
|
|
95
|
-
currentElement: (0,
|
|
96
|
-
rootElement: (0,
|
|
97
|
-
cursorElement:
|
|
96
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
97
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(rootElement),
|
|
98
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor)
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -107,17 +108,17 @@ const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
|
107
108
|
if (cursor === rootElement) {
|
|
108
109
|
throw new _EvaluationRelativeJsonPointerError.default('Relative JSON Pointer evaluation failed. Current element cannot be the root element to apply "#"', {
|
|
109
110
|
relativePointer,
|
|
110
|
-
currentElement: (0,
|
|
111
|
-
rootElement: (0,
|
|
112
|
-
cursorElement:
|
|
111
|
+
currentElement: (0, _apidomDatamodel.cloneDeep)(currentElement),
|
|
112
|
+
rootElement: (0, _apidomDatamodel.cloneDeep)(rootElement),
|
|
113
|
+
cursorElement: _apidomDatamodel.cloneDeep.safe(cursor)
|
|
113
114
|
});
|
|
114
115
|
}
|
|
115
116
|
const parentElement = (0, _ramda.last)(ancestorLineage);
|
|
116
117
|
if (typeof parentElement !== 'undefined') {
|
|
117
|
-
if ((0,
|
|
118
|
+
if ((0, _apidomDatamodel.isMemberElement)(parentElement)) {
|
|
118
119
|
cursor = parentElement.key;
|
|
119
|
-
} else if ((0,
|
|
120
|
-
cursor = new
|
|
120
|
+
} else if ((0, _apidomDatamodel.isArrayElement)(parentElement)) {
|
|
121
|
+
cursor = new _apidomDatamodel.NumberElement(parentElement.content.indexOf(cursor));
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
}
|
package/src/evaluate.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isElement, isMemberElement, isArrayElement, NumberElement, cloneDeep } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { traverse } from '@speclynx/apidom-traverse';
|
|
2
3
|
import { compile as compileJsonPointer, evaluate as evaluateJsonPointer } from '@speclynx/apidom-json-pointer';
|
|
3
4
|
import { last } from 'ramda';
|
|
4
5
|
import EvaluationRelativeJsonPointerError from "./errors/EvaluationRelativeJsonPointerError.mjs";
|
|
@@ -10,13 +11,12 @@ import parse from "./parse.mjs";
|
|
|
10
11
|
const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
11
12
|
let ancestorLineage = [];
|
|
12
13
|
let cursor = currentElement;
|
|
13
|
-
|
|
14
|
-
enter(
|
|
15
|
-
if (
|
|
16
|
-
ancestorLineage =
|
|
17
|
-
|
|
14
|
+
traverse(rootElement, {
|
|
15
|
+
enter(path) {
|
|
16
|
+
if (path.node === currentElement) {
|
|
17
|
+
ancestorLineage = path.getAncestorNodes().reverse().filter(isElement);
|
|
18
|
+
path.stop();
|
|
18
19
|
}
|
|
19
|
-
return undefined;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
if (ancestorLineage.length === 0) {
|
|
@@ -81,9 +81,10 @@ const evaluate = (relativePointer, currentElement, rootElement) => {
|
|
|
81
81
|
cursorElement: cloneDeep.safe(cursor)
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
const
|
|
84
|
+
const arrayContent = containedArray.content;
|
|
85
|
+
const currentCursorIndex = arrayContent.indexOf(cursor);
|
|
85
86
|
const newCursorIndex = currentCursorIndex + relativeJsonPointer.indexManipulation;
|
|
86
|
-
cursor =
|
|
87
|
+
cursor = arrayContent[newCursorIndex];
|
|
87
88
|
if (typeof cursor === 'undefined') {
|
|
88
89
|
throw new EvaluationRelativeJsonPointerError(`Relative JSON Pointer evaluation failed on index-manipulation "${relativeJsonPointer.indexManipulation}"`, {
|
|
89
90
|
relativePointer,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiDOMErrorOptions } from '@speclynx/apidom-error';
|
|
2
2
|
import { ApiDOMStructuredError } from '@speclynx/apidom-error';
|
|
3
|
-
import { Element as Element_2 } from '@speclynx/apidom-
|
|
3
|
+
import { Element as Element_2 } from '@speclynx/apidom-datamodel';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @public
|