@tstdl/base 0.71.90 → 0.71.92
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/json-path/json-path.d.ts +16 -8
- package/json-path/json-path.js +39 -8
- package/json-path/json-path.js.map +1 -1
- package/package.json +1 -1
- package/schema/schema.error.d.ts +6 -1
- package/schema/schema.error.js +20 -0
- package/schema/schema.error.js.map +1 -1
- package/schema/schemas/union.js +8 -2
- package/schema/schemas/union.js.map +1 -1
- package/utils/object/decycle.js +10 -21
- package/utils/object/decycle.js.map +1 -1
- package/utils/object/dereference.d.ts +7 -5
- package/utils/object/dereference.js +4 -4
- package/utils/object/dereference.js.map +1 -1
package/json-path/json-path.d.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
export declare type JsonPathNode =
|
|
2
|
-
export declare
|
|
1
|
+
export declare type JsonPathNode = PropertyKey;
|
|
2
|
+
export declare type JsonPathInput = string | JsonPath | Iterable<JsonPathNode>;
|
|
3
|
+
export declare class JsonPath<T = any> implements Iterable<JsonPathNode> {
|
|
3
4
|
private readonly _options;
|
|
4
5
|
private _path;
|
|
5
6
|
private _nodes;
|
|
6
7
|
/** json path as encoded string */
|
|
7
8
|
get path(): string;
|
|
8
9
|
/** json path as decoded array */
|
|
9
|
-
get nodes(): JsonPathNode[];
|
|
10
|
+
get nodes(): readonly JsonPathNode[];
|
|
11
|
+
static get ROOT(): JsonPath;
|
|
10
12
|
constructor(options?: JsonPathOptions);
|
|
11
|
-
constructor(path:
|
|
12
|
-
|
|
13
|
+
constructor(path: JsonPathInput, options?: JsonPathOptions);
|
|
14
|
+
static isJsonPath(path: string): boolean;
|
|
13
15
|
/**
|
|
14
16
|
* add a property or index to current path
|
|
15
17
|
* @param key
|
|
16
18
|
* @returns new JsonPath instance
|
|
17
19
|
*/
|
|
18
|
-
add<K extends
|
|
20
|
+
add<K extends keyof T>(key: K): JsonPath<T[K]>;
|
|
19
21
|
/**
|
|
20
22
|
* updates options
|
|
21
23
|
* @param options
|
|
22
24
|
* @returns new JsonPath instance
|
|
23
25
|
*/
|
|
24
26
|
options(options: JsonPathOptions): JsonPath;
|
|
27
|
+
[Symbol.iterator](): Iterator<PropertyKey>;
|
|
25
28
|
}
|
|
26
29
|
export declare type JsonPathOptions = {
|
|
27
30
|
/** encode as array.0 instead of array[0] */
|
|
@@ -31,6 +34,11 @@ export declare type JsonPathOptions = {
|
|
|
31
34
|
/** dont prepend $ */
|
|
32
35
|
noDollar?: boolean;
|
|
33
36
|
};
|
|
37
|
+
export declare type JsonPathContext = {
|
|
38
|
+
/** if path contains symbols, they are required in order to be mapped, otherwise they are created from global symbol registry */
|
|
39
|
+
symbols?: symbol[];
|
|
40
|
+
};
|
|
41
|
+
export declare function isJsonPath(path: string): boolean;
|
|
34
42
|
/**
|
|
35
43
|
* encodes an array of nodes into a JSONPath
|
|
36
44
|
* @param nodes nodes to encode
|
|
@@ -40,7 +48,7 @@ export declare type JsonPathOptions = {
|
|
|
40
48
|
* const path = encodeJsonPath(['foo', 'bar', 5]);
|
|
41
49
|
* path == '$.foo.bar[5]'; // true
|
|
42
50
|
*/
|
|
43
|
-
export declare function encodeJsonPath(nodes: JsonPathNode[], options?: JsonPathOptions): string;
|
|
51
|
+
export declare function encodeJsonPath(nodes: readonly JsonPathNode[], options?: JsonPathOptions): string;
|
|
44
52
|
/**
|
|
45
53
|
* decodes a JSONPath into its nodes. Only supports child operator
|
|
46
54
|
* @param path JSONPath string
|
|
@@ -48,4 +56,4 @@ export declare function encodeJsonPath(nodes: JsonPathNode[], options?: JsonPath
|
|
|
48
56
|
* @example
|
|
49
57
|
* decodeJsonPath('$.foo[2].bar[\'baz\']'); // ['foo', 2, 'bar', 'baz']
|
|
50
58
|
*/
|
|
51
|
-
export declare function decodeJsonPath(path: string): JsonPathNode[];
|
|
59
|
+
export declare function decodeJsonPath(path: string, context?: JsonPathContext): JsonPathNode[];
|
package/json-path/json-path.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeJsonPath = exports.encodeJsonPath = exports.JsonPath = void 0;
|
|
3
|
+
exports.decodeJsonPath = exports.encodeJsonPath = exports.isJsonPath = exports.JsonPath = void 0;
|
|
4
|
+
const is_iterable_1 = require("../utils/iterable-helpers/is-iterable");
|
|
4
5
|
const type_guards_1 = require("../utils/type-guards");
|
|
5
6
|
const numberPattern = /^\d+$/u;
|
|
6
|
-
const parsePattern =
|
|
7
|
+
const parsePattern = /^(?:(?:^|\.)(?<dot>[^.[]+))|(?<root>^\$)|\[(?:(?:'(?<bracket>.+?)')|(?<index>\d+)|(?:Symbol\((?<symbol>.*)\)))\]|(?<error>.+?)$/ug;
|
|
7
8
|
class JsonPath {
|
|
8
9
|
constructor(pathOrNodesOrOptions = [], options = {}) {
|
|
9
10
|
this._options = options;
|
|
@@ -13,6 +14,9 @@ class JsonPath {
|
|
|
13
14
|
else if ((0, type_guards_1.isArray)(pathOrNodesOrOptions)) {
|
|
14
15
|
this._nodes = pathOrNodesOrOptions;
|
|
15
16
|
}
|
|
17
|
+
else if ((0, is_iterable_1.isIterable)(pathOrNodesOrOptions)) {
|
|
18
|
+
this._nodes = [...pathOrNodesOrOptions];
|
|
19
|
+
}
|
|
16
20
|
else {
|
|
17
21
|
this._options = pathOrNodesOrOptions;
|
|
18
22
|
}
|
|
@@ -31,6 +35,12 @@ class JsonPath {
|
|
|
31
35
|
}
|
|
32
36
|
return this._nodes;
|
|
33
37
|
}
|
|
38
|
+
static get ROOT() {
|
|
39
|
+
return new JsonPath();
|
|
40
|
+
}
|
|
41
|
+
static isJsonPath(path) {
|
|
42
|
+
return isJsonPath(path);
|
|
43
|
+
}
|
|
34
44
|
/**
|
|
35
45
|
* add a property or index to current path
|
|
36
46
|
* @param key
|
|
@@ -47,8 +57,15 @@ class JsonPath {
|
|
|
47
57
|
options(options) {
|
|
48
58
|
return new JsonPath(this.nodes, options);
|
|
49
59
|
}
|
|
60
|
+
*[Symbol.iterator]() {
|
|
61
|
+
yield* this.nodes;
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
exports.JsonPath = JsonPath;
|
|
65
|
+
function isJsonPath(path) {
|
|
66
|
+
return parsePattern.test(path);
|
|
67
|
+
}
|
|
68
|
+
exports.isJsonPath = isJsonPath;
|
|
52
69
|
/**
|
|
53
70
|
* encodes an array of nodes into a JSONPath
|
|
54
71
|
* @param nodes nodes to encode
|
|
@@ -62,10 +79,11 @@ function encodeJsonPath(nodes, options = {}) {
|
|
|
62
79
|
const { treatArrayAsObject = false, forceBrackets = false, noDollar = false } = options;
|
|
63
80
|
let path = '';
|
|
64
81
|
for (const node of nodes) {
|
|
65
|
-
const
|
|
82
|
+
const nodeIsSymbol = (0, type_guards_1.isSymbol)(node);
|
|
83
|
+
const nodeString = nodeIsSymbol ? `Symbol(${(0, type_guards_1.assertDefinedPass)(node.description, 'only symbols with description can be encoded')})` : node.toString();
|
|
66
84
|
const isNumberAccess = !treatArrayAsObject && numberPattern.test(nodeString);
|
|
67
|
-
if (isNumberAccess) {
|
|
68
|
-
path += `[${
|
|
85
|
+
if (isNumberAccess || nodeIsSymbol) {
|
|
86
|
+
path += `[${nodeString}]`;
|
|
69
87
|
}
|
|
70
88
|
else {
|
|
71
89
|
const encodeAsBracket = forceBrackets || (nodeString == '$') || nodeString.includes('.');
|
|
@@ -93,16 +111,19 @@ exports.encodeJsonPath = encodeJsonPath;
|
|
|
93
111
|
* @example
|
|
94
112
|
* decodeJsonPath('$.foo[2].bar[\'baz\']'); // ['foo', 2, 'bar', 'baz']
|
|
95
113
|
*/
|
|
96
|
-
function decodeJsonPath(path) {
|
|
114
|
+
function decodeJsonPath(path, context = {}) {
|
|
97
115
|
const matches = (path.trim()).matchAll(parsePattern);
|
|
98
116
|
const nodes = [];
|
|
99
117
|
let matchIndex = 0;
|
|
100
118
|
for (const match of matches) {
|
|
101
|
-
const { root, dot, bracket, index, error } = match.groups;
|
|
119
|
+
const { root, dot, bracket, index, symbol, error } = match.groups;
|
|
102
120
|
if ((0, type_guards_1.isDefined)(error)) {
|
|
103
121
|
throw new Error(`unexpected '${error[0]}' at index ${match.index}`);
|
|
104
122
|
}
|
|
105
|
-
const node = dot
|
|
123
|
+
const node = dot
|
|
124
|
+
?? bracket
|
|
125
|
+
?? ((0, type_guards_1.isDefined)(index) ? parseInt(index, 10) : undefined)
|
|
126
|
+
?? ((0, type_guards_1.isDefined)(symbol) ? getSymbol(symbol, context) : undefined);
|
|
106
127
|
if ((0, type_guards_1.isDefined)(node)) {
|
|
107
128
|
if ((matchIndex == 0) && (node == '$')) {
|
|
108
129
|
continue;
|
|
@@ -120,4 +141,14 @@ function decodeJsonPath(path) {
|
|
|
120
141
|
return nodes;
|
|
121
142
|
}
|
|
122
143
|
exports.decodeJsonPath = decodeJsonPath;
|
|
144
|
+
function getSymbol(symbolDescription, context) {
|
|
145
|
+
if ((0, type_guards_1.isDefined)(context.symbols)) {
|
|
146
|
+
for (const symbol of context.symbols) {
|
|
147
|
+
if (symbol.description == symbolDescription) {
|
|
148
|
+
return symbol;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return Symbol.for(symbolDescription);
|
|
153
|
+
}
|
|
123
154
|
//# sourceMappingURL=json-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-path.js","sourceRoot":"","sources":["../../source/json-path/json-path.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"json-path.js","sourceRoot":"","sources":["../../source/json-path/json-path.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAClE,sDAA6G;AAE7G,MAAM,aAAa,GAAG,QAAQ,CAAC;AAC/B,MAAM,YAAY,GAAG,mIAAmI,CAAC;AAKzJ,MAAa,QAAQ;IA6BnB,YAAY,uBAAwD,EAAE,EAAE,UAA2B,EAAE;QACnG,IAAI,CAAC,QAAQ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C,SAAS;aACV;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClB;aACI,IAAI,IAAA,yBAAW,EAAC,IAAI,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;SAC/D;QAED,UAAU,EAAE,CAAC;KACd;IAED,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE;QACxC,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KACjC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AArCD,wCAqCC;AAED,SAAS,SAAS,CAAC,iBAAyB,EAAE,OAAwB;IACpE,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE;YACpC,IAAI,MAAM,CAAC,WAAW,IAAI,iBAAiB,EAAE;gBAC3C,OAAO,MAAM,CAAC;aACf;SACF;KACF;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
package/schema/schema.error.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { CustomError } from "../error";
|
|
2
2
|
import type { JsonPath } from "../json-path";
|
|
3
|
+
import type { OneOrMany, UndefinableJson } from "../types";
|
|
4
|
+
import type { ErrorExtraInfo } from "../utils/format-error";
|
|
3
5
|
export declare type SchemaErrorOptions = {
|
|
4
6
|
path: string | JsonPath;
|
|
7
|
+
inner?: OneOrMany<SchemaError>;
|
|
5
8
|
details?: any;
|
|
6
9
|
};
|
|
7
|
-
export declare class SchemaError extends CustomError {
|
|
10
|
+
export declare class SchemaError extends CustomError implements ErrorExtraInfo {
|
|
8
11
|
static readonly errorName = "SchemaError";
|
|
9
12
|
readonly path: string;
|
|
13
|
+
readonly inner?: OneOrMany<SchemaError>;
|
|
10
14
|
readonly details: any;
|
|
11
15
|
constructor(message: string, options: SchemaErrorOptions, cause?: any);
|
|
12
16
|
static expectedButGot(expected: string, got: string, path: string | JsonPath): SchemaError;
|
|
13
17
|
static couldNotCoerce(expected: string, got: string, message: string, path: string | JsonPath): SchemaError;
|
|
18
|
+
getExtraInfo(includeMessage?: boolean): UndefinableJson | undefined;
|
|
14
19
|
}
|
|
15
20
|
export declare function schemaError(message: string, path: string | JsonPath): SchemaError;
|
package/schema/schema.error.js
CHANGED
|
@@ -7,6 +7,9 @@ class SchemaError extends error_1.CustomError {
|
|
|
7
7
|
constructor(message, options, cause) {
|
|
8
8
|
super({ message, cause });
|
|
9
9
|
this.path = (0, type_guards_1.isString)(options.path) ? options.path : options.path.path;
|
|
10
|
+
if ((0, type_guards_1.isDefined)(options.inner) && (!(0, type_guards_1.isArray)(options.inner) || (options.inner.length > 0))) {
|
|
11
|
+
this.inner = options.inner;
|
|
12
|
+
}
|
|
10
13
|
if ((0, type_guards_1.isNotNullOrUndefined)(this.details)) {
|
|
11
14
|
this.details = options.details;
|
|
12
15
|
}
|
|
@@ -19,6 +22,23 @@ class SchemaError extends error_1.CustomError {
|
|
|
19
22
|
const errorMessage = `could not coerce ${got} to ${expected}: ${message}`;
|
|
20
23
|
return new SchemaError(errorMessage, { path });
|
|
21
24
|
}
|
|
25
|
+
getExtraInfo(includeMessage = false) {
|
|
26
|
+
const obj = {
|
|
27
|
+
path: this.path
|
|
28
|
+
};
|
|
29
|
+
if (includeMessage) {
|
|
30
|
+
obj['message'] = this.message;
|
|
31
|
+
}
|
|
32
|
+
if ((0, type_guards_1.isDefined)(this.inner)) {
|
|
33
|
+
obj['inner'] = (0, type_guards_1.isArray)(this.inner)
|
|
34
|
+
? this.inner.map((error) => error.getExtraInfo(true))
|
|
35
|
+
: this.inner.getExtraInfo(true);
|
|
36
|
+
}
|
|
37
|
+
if ((0, type_guards_1.isNotNullOrUndefined)(this.details)) {
|
|
38
|
+
obj['details'] = this.details;
|
|
39
|
+
}
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
22
42
|
}
|
|
23
43
|
exports.SchemaError = SchemaError;
|
|
24
44
|
SchemaError.errorName = 'SchemaError';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AAAA,oCAAsC;
|
|
1
|
+
{"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AAAA,oCAAsC;AAItC,sDAAyF;AAQzF,MAAa,WAAY,SAAQ,mBAAW;IAO1C,YAAY,OAAe,EAAE,OAA2B,EAAE,KAAW;QACnE,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAQ,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAEtE,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAA,qBAAO,EAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE;YACvF,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;SAC5B;QAED,IAAI,IAAA,kCAAoB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;SAChC;IACH,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,GAAW,EAAE,IAAuB;QAC1E,MAAM,OAAO,GAAG,YAAY,QAAQ,YAAY,GAAG,EAAE,CAAC;QACtD,OAAO,IAAI,WAAW,CAAC,OAAO,EAA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@ class UnionSchemaValidator extends schema_validator_1.SchemaValidator {
|
|
|
11
11
|
this.innerSchemaTypesString = this.innerSchemas.map((innerSchema) => innerSchema.schema.type).join(', ');
|
|
12
12
|
}
|
|
13
13
|
[schema_validator_1.test](value, options, path) {
|
|
14
|
+
const errors = [];
|
|
14
15
|
for (const schema of this.innerSchemas) {
|
|
15
16
|
const result = schema.test(value, options);
|
|
16
17
|
if (result.valid) {
|
|
17
18
|
return result;
|
|
18
19
|
}
|
|
20
|
+
errors.push(result.error);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
const childErrors = errors.map((error) => `${' '.repeat(path.nodes.length * 2)}${error.message}`).join('\n');
|
|
23
|
+
return { valid: false, error: new schema_error_1.SchemaError(`Value did not match any of the allowed schemas (${this.innerSchemaTypesString}):\n${childErrors}`, { path }) };
|
|
21
24
|
}
|
|
22
25
|
async [schema_validator_1.testAsync](value, options, path) {
|
|
26
|
+
const errors = [];
|
|
23
27
|
for (const schema of this.innerSchemas) {
|
|
24
28
|
const result = await schema.testAsync(value, options);
|
|
25
29
|
if (result.valid) {
|
|
26
30
|
return result;
|
|
27
31
|
}
|
|
32
|
+
errors.push(result.error);
|
|
28
33
|
}
|
|
29
|
-
|
|
34
|
+
const childErrors = errors.map((error) => `${' '.repeat(path.nodes.length * 2)}${error.message}`).join('\n');
|
|
35
|
+
return { valid: false, error: new schema_error_1.SchemaError(`Value did not match any of the allowed schemas (${this.innerSchemaTypesString}):\n${childErrors}`, { path }) };
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
exports.UnionSchemaValidator = UnionSchemaValidator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../source/schema/schemas/union.ts"],"names":[],"mappings":";;;AACA,kDAA8C;AAE9C,0DAAuE;AAEvE,oCAAwC;AASxC,MAAa,oBAA+E,SAAQ,kCAA4C;IAK9I,YAAY,YAAmE,EAAE,MAAmC;QAClH,KAAK,CAAC,MA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AAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAChK,CAAC;CACF;AA/CD,oDA+CC;AAED,SAAgB,KAAK,CAAyD,OAAkB,EAAE,OAA6F;IAC7L,MAAM,MAAM,GAAG,IAAA,oBAAY,EAA4D;QACrF,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAuC;QAC/F,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,IAAI,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AARD,sBAQC"}
|
package/utils/object/decycle.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.recycle = exports.decycle = void 0;
|
|
4
|
+
const json_path_1 = require("../../json-path");
|
|
4
5
|
const clone_1 = require("../clone");
|
|
5
6
|
const type_guards_1 = require("../type-guards");
|
|
7
|
+
const dereference_1 = require("./dereference");
|
|
6
8
|
const object_1 = require("./object");
|
|
7
9
|
function decycle(_value, replacer) {
|
|
8
10
|
const mapping = new Map();
|
|
@@ -14,37 +16,24 @@ function decycle(_value, replacer) {
|
|
|
14
16
|
}
|
|
15
17
|
const mappedPath = mapping.get(value);
|
|
16
18
|
if ((0, type_guards_1.isDefined)(mappedPath)) {
|
|
17
|
-
return { $ref: mappedPath };
|
|
19
|
+
return { $ref: mappedPath.path };
|
|
18
20
|
}
|
|
19
21
|
mapping.set(value, path);
|
|
20
22
|
if ((0, type_guards_1.isArray)(value)) {
|
|
21
|
-
return value.map((item, index) => _decycle(item,
|
|
23
|
+
return value.map((item, index) => _decycle(item, path.add(index)));
|
|
22
24
|
}
|
|
23
|
-
return (0, object_1.mapObjectValues)(value, (item, key) => _decycle(item,
|
|
25
|
+
return (0, object_1.mapObjectValues)(value, (item, key) => _decycle(item, path.add(key)));
|
|
24
26
|
}
|
|
25
|
-
return _decycle(_value,
|
|
27
|
+
return _decycle(_value, json_path_1.JsonPath.ROOT);
|
|
26
28
|
}
|
|
27
29
|
exports.decycle = decycle;
|
|
28
|
-
const recyclePathPattern = /^\$(?:\[(?:(\d+)|'(.*?)')\])*$/u;
|
|
29
|
-
const recyclePathPartsPattern = /\[(?:(\d+)|'(.*?)')\]/ug;
|
|
30
30
|
function recycle(_value, _clone = true) {
|
|
31
31
|
const value = _clone ? (0, clone_1.clone)(_value, true) : _value;
|
|
32
|
-
|
|
33
|
-
const parts = ref.matchAll(recyclePathPartsPattern);
|
|
34
|
-
let target = value;
|
|
35
|
-
for (const [, index, property] of parts) {
|
|
36
|
-
const key = index ?? property;
|
|
37
|
-
if (!(0, object_1.hasOwnProperty)(target, key)) {
|
|
38
|
-
throw new Error(`reference ${ref} not found`);
|
|
39
|
-
}
|
|
40
|
-
target = target[key];
|
|
41
|
-
}
|
|
42
|
-
return target;
|
|
43
|
-
}
|
|
32
|
+
const deref = (0, dereference_1.getCachedDereference)();
|
|
44
33
|
function getRef(node) {
|
|
45
34
|
if ((0, type_guards_1.isObject)(node) && (0, object_1.hasOwnProperty)(node, '$ref')) {
|
|
46
35
|
const ref = node['$ref'];
|
|
47
|
-
if ((0, type_guards_1.isString)(ref) &&
|
|
36
|
+
if ((0, type_guards_1.isString)(ref) && json_path_1.JsonPath.isJsonPath(ref)) {
|
|
48
37
|
return ref;
|
|
49
38
|
}
|
|
50
39
|
}
|
|
@@ -55,7 +44,7 @@ function recycle(_value, _clone = true) {
|
|
|
55
44
|
for (let i = 0; i < node.length; i++) {
|
|
56
45
|
const ref = getRef(node[i]);
|
|
57
46
|
if ((0, type_guards_1.isDefined)(ref)) {
|
|
58
|
-
node[i] = deref(ref);
|
|
47
|
+
node[i] = deref(value, ref);
|
|
59
48
|
}
|
|
60
49
|
else {
|
|
61
50
|
_recycle(node[i]);
|
|
@@ -66,7 +55,7 @@ function recycle(_value, _clone = true) {
|
|
|
66
55
|
for (const key of Object.keys(node)) {
|
|
67
56
|
const ref = getRef(node[key]);
|
|
68
57
|
if ((0, type_guards_1.isDefined)(ref)) {
|
|
69
|
-
node[key] = deref(ref);
|
|
58
|
+
node[key] = deref(value, ref);
|
|
70
59
|
}
|
|
71
60
|
else {
|
|
72
61
|
_recycle(node[key]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decycle.js","sourceRoot":"","sources":["../../../source/utils/object/decycle.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"decycle.js","sourceRoot":"","sources":["../../../source/utils/object/decycle.ts"],"names":[],"mappings":";;;AAAA,+CAAuC;AAEvC,oCAAiC;AACjC,gDAA+I;AAC/I,+CAAqD;AACrD,qCAA2D;AAU3D,SAAgB,OAAO,CAAI,MAAS,EAAE,QAA8B;IAClE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEzC,MAAM,UAAU,GAAG,IAAA,uBAAS,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,CAAC;IAE9E,SAAS,QAAQ,CAAC,OAAY,EAAE,IAAc;QAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAElC,IAAI,IAAA,yBAAW,EAAC,KAAK,CAAC,IAAI,IAAA,sBAAQ,EAAC,KAAK,CAAC,IAAI,IAAA,oBAAM,EAAC,KAAK,CAAC,IAAI,IAAA,wBAAU,EAAC,KAAK,CAAC,EAAE;YAC/E,OAAO,KAAK,CAAC;SACd;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,IAAA,uBAAS,EAAC,UAAU,CAAC,EAAE;YACzB,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC;SAClC;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,EAA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,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAE5B,IAAI,IAAA,uBAAS,EAAC,GAAG,CAAC,EAAE;oBAClB,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;iBAC7B;qBACI;oBACH,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;iBACnB;aACF;SACF;aACI,IAAI,IAAA,sBAAQ,EAAC,IAAI,CAAC,IAAI,IAAA,uBAAS,EAAC,IAAI,CAAC,EAAE;YAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACnC,MAAM,GAAG,GAAG,MAAM,CAAE,IAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;gBAE7C,IAAI,IAAA,uBAAS,EAAC,GAAG,CAAC,EAAE;oBACjB,IAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;iBAC9C;qBACI;oBACH,QAAQ,CAAE,IAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;iBACpC;aACF;SACF;IACH,CAAC;IAED,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,KAAiB,CAAC;AAC3B,CAAC;AA9CD,0BA8CC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { JsonPathInput } from "../../json-path";
|
|
2
|
+
export declare type CompiledDereferencer = (object: object) => unknown;
|
|
1
3
|
/**
|
|
2
4
|
* compiles a dereferencer for a specific reference
|
|
3
5
|
* @param object object to dereference
|
|
4
|
-
* @param reference path to property in dot notation or
|
|
6
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
5
7
|
* @returns referenced value
|
|
6
8
|
*/
|
|
7
|
-
export declare function compileDereferencer(reference:
|
|
9
|
+
export declare function compileDereferencer(reference: JsonPathInput): (object: object) => unknown;
|
|
8
10
|
/**
|
|
9
11
|
* dereference a reference
|
|
10
12
|
*
|
|
@@ -12,10 +14,10 @@ export declare function compileDereferencer(reference: string): (object: object)
|
|
|
12
14
|
*
|
|
13
15
|
* also take a look at {@link getCachedDereference} and {@link compileDereferencer} if you need to dereference multiple times
|
|
14
16
|
* @param object object to dereference
|
|
15
|
-
* @param reference path to property in dot notation or
|
|
17
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
16
18
|
* @returns referenced value
|
|
17
19
|
*/
|
|
18
|
-
export declare function dereference(object: object, reference:
|
|
20
|
+
export declare function dereference(object: object, reference: JsonPathInput): unknown;
|
|
19
21
|
/**
|
|
20
22
|
* cached version of {@link dereference}. It caches the internally used dereferencer, but it does *not* cache the referenced value
|
|
21
23
|
*
|
|
@@ -24,7 +26,7 @@ export declare function dereference(object: object, reference: string): unknown;
|
|
|
24
26
|
*
|
|
25
27
|
* also take a look at {@link dereference} and {@link compileDereferencer} for other use cases
|
|
26
28
|
* @param object object to dereference
|
|
27
|
-
* @param reference path to property in dot notation or
|
|
29
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
28
30
|
* @returns referenced value
|
|
29
31
|
*/
|
|
30
32
|
export declare function getCachedDereference(): typeof dereference;
|
|
@@ -6,11 +6,11 @@ const memoize_1 = require("../function/memoize");
|
|
|
6
6
|
/**
|
|
7
7
|
* compiles a dereferencer for a specific reference
|
|
8
8
|
* @param object object to dereference
|
|
9
|
-
* @param reference path to property in dot notation or
|
|
9
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
10
10
|
* @returns referenced value
|
|
11
11
|
*/
|
|
12
12
|
function compileDereferencer(reference) {
|
|
13
|
-
const nodes =
|
|
13
|
+
const nodes = new json_path_1.JsonPath(reference).nodes;
|
|
14
14
|
function dereferencer(object) {
|
|
15
15
|
let target = object;
|
|
16
16
|
for (let i = 0; i < nodes.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
|
|
@@ -28,7 +28,7 @@ exports.compileDereferencer = compileDereferencer;
|
|
|
28
28
|
*
|
|
29
29
|
* also take a look at {@link getCachedDereference} and {@link compileDereferencer} if you need to dereference multiple times
|
|
30
30
|
* @param object object to dereference
|
|
31
|
-
* @param reference path to property in dot notation or
|
|
31
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
32
32
|
* @returns referenced value
|
|
33
33
|
*/
|
|
34
34
|
function dereference(object, reference) {
|
|
@@ -43,7 +43,7 @@ exports.dereference = dereference;
|
|
|
43
43
|
*
|
|
44
44
|
* also take a look at {@link dereference} and {@link compileDereferencer} for other use cases
|
|
45
45
|
* @param object object to dereference
|
|
46
|
-
* @param reference path to property in dot notation or
|
|
46
|
+
* @param reference path to property in dot notation or {@link JsonPath}
|
|
47
47
|
* @returns referenced value
|
|
48
48
|
*/
|
|
49
49
|
function getCachedDereference() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dereference.js","sourceRoot":"","sources":["../../../source/utils/object/dereference.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dereference.js","sourceRoot":"","sources":["../../../source/utils/object/dereference.ts"],"names":[],"mappings":";;;AACA,+CAAuC;AAEvC,iDAAoD;AAIpD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,SAAwB;IAC1D,MAAM,KAAK,GAAG,IAAI,oBAAQ,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC;IAE5C,SAAS,YAAY,CAAC,MAAc;QAClC,IAAI,MAAM,GAAG,MAAM,CAAC;QAEpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,uDAAuD;YAC9F,MAAM,GAAI,MAAiB,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;SACxC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAdD,kDAcC;AAED;;;;;;;;;GASG;AACH,SAAgB,WAAW,CAAC,MAAc,EAAE,SAAwB;IAClE,OAAO,mBAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AAFD,kCAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,oBAAoB;IAClC,MAAM,oBAAoB,GAAG,IAAA,uBAAa,EAAC,mBAAmB,CAAC,CAAC;IAEhE,SAAS,iBAAiB,CAAC,MAAc,EAAE,SAAwB;QACjE,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AARD,oDAQC"}
|