@swagger-api/apidom-json-pointer 1.0.0-beta.9 → 1.0.0-rc.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 +182 -0
- package/README.md +37 -6
- package/dist/apidom-json-pointer.browser.js +7982 -11742
- package/dist/apidom-json-pointer.browser.min.js +1 -1
- package/package.json +25 -15
- package/src/index.cjs +26 -22
- package/src/index.mjs +36 -9
- package/src/legacy/compile.cjs +25 -0
- package/src/legacy/compile.mjs +20 -0
- package/src/{errors → legacy/errors}/CompilationJsonPointerError.cjs +2 -0
- package/src/{errors → legacy/errors}/CompilationJsonPointerError.mjs +2 -0
- package/src/{errors → legacy/errors}/EvaluationJsonPointerError.cjs +2 -0
- package/src/{errors → legacy/errors}/EvaluationJsonPointerError.mjs +2 -0
- package/src/{errors → legacy/errors}/InvalidJsonPointerError.cjs +2 -0
- package/src/{errors → legacy/errors}/InvalidJsonPointerError.mjs +2 -0
- package/src/{errors → legacy/errors}/JsonPointerError.cjs +1 -0
- package/src/{errors → legacy/errors}/JsonPointerError.mjs +1 -0
- package/src/legacy/escape.cjs +13 -0
- package/src/legacy/escape.mjs +10 -0
- package/src/legacy/evaluate.cjs +36 -0
- package/src/legacy/evaluate.mjs +31 -0
- package/src/legacy/index.cjs +25 -0
- package/src/legacy/index.mjs +9 -0
- package/src/legacy/parse.cjs +38 -0
- package/src/legacy/parse.mjs +34 -0
- package/src/legacy/unescape.cjs +13 -0
- package/src/legacy/unescape.mjs +10 -0
- package/types/apidom-json-pointer.d.ts +68 -91
- package/src/compile.cjs +0 -24
- package/src/compile.mjs +0 -19
- package/src/escape.cjs +0 -10
- package/src/escape.mjs +0 -7
- package/src/evaluate.cjs +0 -62
- package/src/evaluate.mjs +0 -57
- package/src/parse.cjs +0 -53
- package/src/parse.mjs +0 -47
- package/src/unescape.cjs +0 -24
- package/src/unescape.mjs +0 -21
package/src/evaluate.cjs
DELETED
|
@@ -1,62 +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 _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
-
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
|
-
var _parse = _interopRequireDefault(require("./parse.cjs"));
|
|
9
|
-
var _EvaluationJsonPointerError = _interopRequireDefault(require("./errors/EvaluationJsonPointerError.cjs"));
|
|
10
|
-
/**
|
|
11
|
-
* Evaluates JSON Pointer against ApiDOM fragment.
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
const evaluate = (pointer, element) => {
|
|
15
|
-
let tokens;
|
|
16
|
-
try {
|
|
17
|
-
tokens = (0, _parse.default)(pointer);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
throw new _EvaluationJsonPointerError.default(`JSON Pointer evaluation failed while parsing the pointer "${pointer}".`, {
|
|
20
|
-
pointer,
|
|
21
|
-
element: (0, _apidomCore.cloneDeep)(element),
|
|
22
|
-
cause: error
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return tokens.reduce((acc, token, tokenPosition) => {
|
|
26
|
-
if ((0, _apidomCore.isObjectElement)(acc)) {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
if (!acc.hasKey(token)) {
|
|
29
|
-
throw new _EvaluationJsonPointerError.default(`JSON Pointer evaluation failed while evaluating token "${token}" against an ObjectElement`, {
|
|
30
|
-
pointer,
|
|
31
|
-
tokens,
|
|
32
|
-
failedToken: token,
|
|
33
|
-
failedTokenPosition: tokenPosition,
|
|
34
|
-
element: (0, _apidomCore.cloneDeep)(acc)
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
return acc.get(token);
|
|
39
|
-
}
|
|
40
|
-
if ((0, _apidomCore.isArrayElement)(acc)) {
|
|
41
|
-
if (!(token in acc.content) || !(0, _ramdaAdjunct.isInteger)(Number(token))) {
|
|
42
|
-
throw new _EvaluationJsonPointerError.default(`JSON Pointer evaluation failed while evaluating token "${token}" against an ArrayElement`, {
|
|
43
|
-
pointer,
|
|
44
|
-
tokens,
|
|
45
|
-
failedToken: token,
|
|
46
|
-
failedTokenPosition: tokenPosition,
|
|
47
|
-
element: (0, _apidomCore.cloneDeep)(acc)
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
return acc.get(Number(token));
|
|
52
|
-
}
|
|
53
|
-
throw new _EvaluationJsonPointerError.default(`JSON Pointer evaluation failed while evaluating token "${token}" against an unexpected Element`, {
|
|
54
|
-
pointer,
|
|
55
|
-
tokens,
|
|
56
|
-
failedToken: token,
|
|
57
|
-
failedTokenPosition: tokenPosition,
|
|
58
|
-
element: (0, _apidomCore.cloneDeep)(acc)
|
|
59
|
-
});
|
|
60
|
-
}, element);
|
|
61
|
-
};
|
|
62
|
-
var _default = exports.default = evaluate;
|
package/src/evaluate.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { isInteger } from 'ramda-adjunct';
|
|
2
|
-
import { isObjectElement, isArrayElement, cloneDeep } from '@swagger-api/apidom-core';
|
|
3
|
-
import parse from "./parse.mjs";
|
|
4
|
-
import EvaluationJsonPointerError from "./errors/EvaluationJsonPointerError.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Evaluates JSON Pointer against ApiDOM fragment.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
const evaluate = (pointer, element) => {
|
|
10
|
-
let tokens;
|
|
11
|
-
try {
|
|
12
|
-
tokens = parse(pointer);
|
|
13
|
-
} catch (error) {
|
|
14
|
-
throw new EvaluationJsonPointerError(`JSON Pointer evaluation failed while parsing the pointer "${pointer}".`, {
|
|
15
|
-
pointer,
|
|
16
|
-
element: cloneDeep(element),
|
|
17
|
-
cause: error
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return tokens.reduce((acc, token, tokenPosition) => {
|
|
21
|
-
if (isObjectElement(acc)) {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
if (!acc.hasKey(token)) {
|
|
24
|
-
throw new EvaluationJsonPointerError(`JSON Pointer evaluation failed while evaluating token "${token}" against an ObjectElement`, {
|
|
25
|
-
pointer,
|
|
26
|
-
tokens,
|
|
27
|
-
failedToken: token,
|
|
28
|
-
failedTokenPosition: tokenPosition,
|
|
29
|
-
element: cloneDeep(acc)
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
return acc.get(token);
|
|
34
|
-
}
|
|
35
|
-
if (isArrayElement(acc)) {
|
|
36
|
-
if (!(token in acc.content) || !isInteger(Number(token))) {
|
|
37
|
-
throw new EvaluationJsonPointerError(`JSON Pointer evaluation failed while evaluating token "${token}" against an ArrayElement`, {
|
|
38
|
-
pointer,
|
|
39
|
-
tokens,
|
|
40
|
-
failedToken: token,
|
|
41
|
-
failedTokenPosition: tokenPosition,
|
|
42
|
-
element: cloneDeep(acc)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
return acc.get(Number(token));
|
|
47
|
-
}
|
|
48
|
-
throw new EvaluationJsonPointerError(`JSON Pointer evaluation failed while evaluating token "${token}" against an unexpected Element`, {
|
|
49
|
-
pointer,
|
|
50
|
-
tokens,
|
|
51
|
-
failedToken: token,
|
|
52
|
-
failedTokenPosition: tokenPosition,
|
|
53
|
-
element: cloneDeep(acc)
|
|
54
|
-
});
|
|
55
|
-
}, element);
|
|
56
|
-
};
|
|
57
|
-
export default evaluate;
|
package/src/parse.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports.__esModule = true;
|
|
5
|
-
exports.uriToPointer = exports.default = void 0;
|
|
6
|
-
var _ramda = require("ramda");
|
|
7
|
-
var _ramdaAdjunct = require("ramda-adjunct");
|
|
8
|
-
var _unescape = _interopRequireDefault(require("./unescape.cjs"));
|
|
9
|
-
var _InvalidJsonPointerError = _interopRequireDefault(require("./errors/InvalidJsonPointerError.cjs"));
|
|
10
|
-
/**
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
const parse = pointer => {
|
|
14
|
-
if ((0, _ramdaAdjunct.isEmptyString)(pointer)) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
if (!(0, _ramda.startsWith)('/', pointer)) {
|
|
18
|
-
throw new _InvalidJsonPointerError.default(`Invalid JSON Pointer "${pointer}". JSON Pointers must begin with "/"`, {
|
|
19
|
-
pointer
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const tokens = (0, _ramda.pipe)((0, _ramda.split)('/'), (0, _ramda.map)(_unescape.default))(pointer);
|
|
24
|
-
return (0, _ramda.tail)(tokens);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new _InvalidJsonPointerError.default(`JSON Pointer parsing of "${pointer}" encountered an error.`, {
|
|
27
|
-
pointer,
|
|
28
|
-
cause: error
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns the hash (URL fragment), of the given path.
|
|
35
|
-
* If there is no hash, then the root hash ("#") is returned.
|
|
36
|
-
*/
|
|
37
|
-
const getHash = uri => {
|
|
38
|
-
const hashIndex = uri.indexOf('#');
|
|
39
|
-
if (hashIndex !== -1) {
|
|
40
|
-
return uri.substring(hashIndex);
|
|
41
|
-
}
|
|
42
|
-
return '#';
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
const uriToPointer = uri => {
|
|
49
|
-
const hash = getHash(uri);
|
|
50
|
-
return (0, _ramdaAdjunct.trimCharsStart)('#', hash);
|
|
51
|
-
};
|
|
52
|
-
exports.uriToPointer = uriToPointer;
|
|
53
|
-
var _default = exports.default = parse;
|
package/src/parse.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { map, pipe, split, startsWith, tail } from 'ramda';
|
|
2
|
-
import { isEmptyString, trimCharsStart } from 'ramda-adjunct';
|
|
3
|
-
import unescape from "./unescape.mjs";
|
|
4
|
-
import InvalidJsonPointerError from "./errors/InvalidJsonPointerError.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
const parse = pointer => {
|
|
9
|
-
if (isEmptyString(pointer)) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
if (!startsWith('/', pointer)) {
|
|
13
|
-
throw new InvalidJsonPointerError(`Invalid JSON Pointer "${pointer}". JSON Pointers must begin with "/"`, {
|
|
14
|
-
pointer
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const tokens = pipe(split('/'), map(unescape))(pointer);
|
|
19
|
-
return tail(tokens);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw new InvalidJsonPointerError(`JSON Pointer parsing of "${pointer}" encountered an error.`, {
|
|
22
|
-
pointer,
|
|
23
|
-
cause: error
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns the hash (URL fragment), of the given path.
|
|
30
|
-
* If there is no hash, then the root hash ("#") is returned.
|
|
31
|
-
*/
|
|
32
|
-
const getHash = uri => {
|
|
33
|
-
const hashIndex = uri.indexOf('#');
|
|
34
|
-
if (hashIndex !== -1) {
|
|
35
|
-
return uri.substring(hashIndex);
|
|
36
|
-
}
|
|
37
|
-
return '#';
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export const uriToPointer = uri => {
|
|
44
|
-
const hash = getHash(uri);
|
|
45
|
-
return trimCharsStart('#', hash);
|
|
46
|
-
};
|
|
47
|
-
export default parse;
|
package/src/unescape.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
var _ramda = require("ramda");
|
|
6
|
-
/**
|
|
7
|
-
* decodeURIComponent can throw URIError in certain cases like 'c%d'.
|
|
8
|
-
* safeDecodeURIComponent is a safe variant of decodeURIComponent that never trows.
|
|
9
|
-
*
|
|
10
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI|More info about URIError}
|
|
11
|
-
*/
|
|
12
|
-
const safeDecodeURIComponent = encodedURIComponent => {
|
|
13
|
-
try {
|
|
14
|
-
return decodeURIComponent(encodedURIComponent);
|
|
15
|
-
} catch {
|
|
16
|
-
return encodedURIComponent;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
const unescape = (0, _ramda.pipe)((0, _ramda.replace)(/~1/g, '/'), (0, _ramda.replace)(/~0/g, '~'), safeDecodeURIComponent);
|
|
24
|
-
var _default = exports.default = unescape;
|
package/src/unescape.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { pipe, replace } from 'ramda';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* decodeURIComponent can throw URIError in certain cases like 'c%d'.
|
|
5
|
-
* safeDecodeURIComponent is a safe variant of decodeURIComponent that never trows.
|
|
6
|
-
*
|
|
7
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI|More info about URIError}
|
|
8
|
-
*/
|
|
9
|
-
const safeDecodeURIComponent = encodedURIComponent => {
|
|
10
|
-
try {
|
|
11
|
-
return decodeURIComponent(encodedURIComponent);
|
|
12
|
-
} catch {
|
|
13
|
-
return encodedURIComponent;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
const unescape = pipe(replace(/~1/g, '/'), replace(/~0/g, '~'), safeDecodeURIComponent);
|
|
21
|
-
export default unescape;
|