typia 4.1.3-dev.20230704 → 4.1.4-dev.20230705
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/package.json +1 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +137 -137
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
- package/src/factories/internal/metadata/iterate_metadata_tag.ts +31 -31
- package/src/metadata/MetadataObject.ts +129 -129
package/package.json
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
5
|
-
import { MetadataProperty } from "../../../metadata/MetadataProperty";
|
|
6
|
-
|
|
7
|
-
import { Writable } from "../../../typings/Writable";
|
|
8
|
-
|
|
9
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
-
|
|
11
|
-
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
-
import { explore_metadata } from "./explore_metadata";
|
|
16
|
-
|
|
17
|
-
export const emplace_metadata_object =
|
|
18
|
-
(checker: ts.TypeChecker) =>
|
|
19
|
-
(options: MetadataFactory.IOptions) =>
|
|
20
|
-
(collection: MetadataCollection) =>
|
|
21
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
22
|
-
// EMPLACE OBJECT
|
|
23
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
24
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
25
|
-
|
|
26
|
-
if (newbie === false) return obj;
|
|
27
|
-
|
|
28
|
-
// PREPARE ASSETS
|
|
29
|
-
const isClass: boolean = parent.isClass();
|
|
30
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
31
|
-
? (node) => {
|
|
32
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
33
|
-
.getChildren()[0]
|
|
34
|
-
?.getChildren()[0]?.kind;
|
|
35
|
-
return (
|
|
36
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
37
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
38
|
-
(ts.isParameter(node) || isProperty(node))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
: (node) => isProperty(node);
|
|
42
|
-
|
|
43
|
-
const insert =
|
|
44
|
-
(key: Metadata) =>
|
|
45
|
-
(value: Metadata) =>
|
|
46
|
-
(
|
|
47
|
-
symbol: ts.Symbol | undefined,
|
|
48
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
49
|
-
): MetadataProperty => {
|
|
50
|
-
// COMMENTS AND TAGS
|
|
51
|
-
const description: string | null = symbol
|
|
52
|
-
? CommentFactory.description(symbol) ?? null
|
|
53
|
-
: null;
|
|
54
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
55
|
-
symbol?.getJsDocTags() ?? []
|
|
56
|
-
).filter(filter ?? (() => true));
|
|
57
|
-
|
|
58
|
-
// THE PROPERTY
|
|
59
|
-
const property = MetadataProperty.create({
|
|
60
|
-
key,
|
|
61
|
-
value,
|
|
62
|
-
description,
|
|
63
|
-
jsDocTags,
|
|
64
|
-
tags: [],
|
|
65
|
-
});
|
|
66
|
-
obj.properties.push(property);
|
|
67
|
-
return property;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
//----
|
|
71
|
-
// REGULAR PROPERTIES
|
|
72
|
-
//----
|
|
73
|
-
for (const prop of parent.getApparentProperties()) {
|
|
74
|
-
// CHECK INTERNAL TAG
|
|
75
|
-
if (
|
|
76
|
-
(prop.getJsDocTags(checker) ?? []).find(
|
|
77
|
-
(tag) => tag.name === "internal",
|
|
78
|
-
) !== undefined
|
|
79
|
-
)
|
|
80
|
-
continue;
|
|
81
|
-
|
|
82
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
83
|
-
const [node, type] = (() => {
|
|
84
|
-
const node = (prop.getDeclarations() ?? [])[0] as
|
|
85
|
-
| ts.PropertyDeclaration
|
|
86
|
-
| undefined;
|
|
87
|
-
const type: ts.Type | undefined = node
|
|
88
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
89
|
-
: "getTypeOfPropertyOfType" in checker
|
|
90
|
-
? (checker as any).getTypeOfPropertyOfType(
|
|
91
|
-
parent,
|
|
92
|
-
prop.name,
|
|
93
|
-
)
|
|
94
|
-
: undefined;
|
|
95
|
-
return [node, type];
|
|
96
|
-
})();
|
|
97
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
98
|
-
|
|
99
|
-
// GET EXACT TYPE
|
|
100
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
101
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
102
|
-
collection,
|
|
103
|
-
)(type, false);
|
|
104
|
-
|
|
105
|
-
// OPTIONAL, BUT CAN BE RQUIRED BY `Required<T>` TYPE
|
|
106
|
-
if (node?.questionToken && (value.required === false || value.any))
|
|
107
|
-
Writable(value).optional = true;
|
|
108
|
-
insert(key)(value)(prop);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//----
|
|
112
|
-
// DYNAMIC PROPERTIES
|
|
113
|
-
//----
|
|
114
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
115
|
-
// GET EXACT TYPE
|
|
116
|
-
const analyzer = (type: ts.Type) =>
|
|
117
|
-
explore_metadata(checker)(options)(collection)(type, false);
|
|
118
|
-
const key: Metadata = analyzer(index.keyType);
|
|
119
|
-
const value: Metadata = analyzer(index.type);
|
|
120
|
-
|
|
121
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
122
|
-
insert(key)(value)(
|
|
123
|
-
index.declaration?.parent
|
|
124
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
125
|
-
: undefined,
|
|
126
|
-
(doc) => doc.name !== "default",
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return obj;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const isProperty = (node: ts.Declaration) =>
|
|
134
|
-
ts.isPropertyDeclaration(node) ||
|
|
135
|
-
ts.isPropertyAssignment(node) ||
|
|
136
|
-
ts.isPropertySignature(node) ||
|
|
137
|
-
ts.isTypeLiteralNode(node);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
5
|
+
import { MetadataProperty } from "../../../metadata/MetadataProperty";
|
|
6
|
+
|
|
7
|
+
import { Writable } from "../../../typings/Writable";
|
|
8
|
+
|
|
9
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
+
|
|
11
|
+
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
+
import { explore_metadata } from "./explore_metadata";
|
|
16
|
+
|
|
17
|
+
export const emplace_metadata_object =
|
|
18
|
+
(checker: ts.TypeChecker) =>
|
|
19
|
+
(options: MetadataFactory.IOptions) =>
|
|
20
|
+
(collection: MetadataCollection) =>
|
|
21
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
22
|
+
// EMPLACE OBJECT
|
|
23
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
24
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
25
|
+
|
|
26
|
+
if (newbie === false) return obj;
|
|
27
|
+
|
|
28
|
+
// PREPARE ASSETS
|
|
29
|
+
const isClass: boolean = parent.isClass();
|
|
30
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
31
|
+
? (node) => {
|
|
32
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
33
|
+
.getChildren()[0]
|
|
34
|
+
?.getChildren()[0]?.kind;
|
|
35
|
+
return (
|
|
36
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
37
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
38
|
+
(ts.isParameter(node) || isProperty(node))
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
: (node) => isProperty(node);
|
|
42
|
+
|
|
43
|
+
const insert =
|
|
44
|
+
(key: Metadata) =>
|
|
45
|
+
(value: Metadata) =>
|
|
46
|
+
(
|
|
47
|
+
symbol: ts.Symbol | undefined,
|
|
48
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
49
|
+
): MetadataProperty => {
|
|
50
|
+
// COMMENTS AND TAGS
|
|
51
|
+
const description: string | null = symbol
|
|
52
|
+
? CommentFactory.description(symbol) ?? null
|
|
53
|
+
: null;
|
|
54
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
55
|
+
symbol?.getJsDocTags() ?? []
|
|
56
|
+
).filter(filter ?? (() => true));
|
|
57
|
+
|
|
58
|
+
// THE PROPERTY
|
|
59
|
+
const property = MetadataProperty.create({
|
|
60
|
+
key,
|
|
61
|
+
value,
|
|
62
|
+
description,
|
|
63
|
+
jsDocTags,
|
|
64
|
+
tags: [],
|
|
65
|
+
});
|
|
66
|
+
obj.properties.push(property);
|
|
67
|
+
return property;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//----
|
|
71
|
+
// REGULAR PROPERTIES
|
|
72
|
+
//----
|
|
73
|
+
for (const prop of parent.getApparentProperties()) {
|
|
74
|
+
// CHECK INTERNAL TAG
|
|
75
|
+
if (
|
|
76
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
77
|
+
(tag) => tag.name === "internal",
|
|
78
|
+
) !== undefined
|
|
79
|
+
)
|
|
80
|
+
continue;
|
|
81
|
+
|
|
82
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
83
|
+
const [node, type] = (() => {
|
|
84
|
+
const node = (prop.getDeclarations() ?? [])[0] as
|
|
85
|
+
| ts.PropertyDeclaration
|
|
86
|
+
| undefined;
|
|
87
|
+
const type: ts.Type | undefined = node
|
|
88
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
89
|
+
: "getTypeOfPropertyOfType" in checker
|
|
90
|
+
? (checker as any).getTypeOfPropertyOfType(
|
|
91
|
+
parent,
|
|
92
|
+
prop.name,
|
|
93
|
+
)
|
|
94
|
+
: undefined;
|
|
95
|
+
return [node, type];
|
|
96
|
+
})();
|
|
97
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
98
|
+
|
|
99
|
+
// GET EXACT TYPE
|
|
100
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
101
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
102
|
+
collection,
|
|
103
|
+
)(type, false);
|
|
104
|
+
|
|
105
|
+
// OPTIONAL, BUT CAN BE RQUIRED BY `Required<T>` TYPE
|
|
106
|
+
if (node?.questionToken && (value.required === false || value.any))
|
|
107
|
+
Writable(value).optional = true;
|
|
108
|
+
insert(key)(value)(prop);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//----
|
|
112
|
+
// DYNAMIC PROPERTIES
|
|
113
|
+
//----
|
|
114
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
115
|
+
// GET EXACT TYPE
|
|
116
|
+
const analyzer = (type: ts.Type) =>
|
|
117
|
+
explore_metadata(checker)(options)(collection)(type, false);
|
|
118
|
+
const key: Metadata = analyzer(index.keyType);
|
|
119
|
+
const value: Metadata = analyzer(index.type);
|
|
120
|
+
|
|
121
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
122
|
+
insert(key)(value)(
|
|
123
|
+
index.declaration?.parent
|
|
124
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
125
|
+
: undefined,
|
|
126
|
+
(doc) => doc.name !== "default",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return obj;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const isProperty = (node: ts.Declaration) =>
|
|
134
|
+
ts.isPropertyDeclaration(node) ||
|
|
135
|
+
ts.isPropertyAssignment(node) ||
|
|
136
|
+
ts.isPropertySignature(node) ||
|
|
137
|
+
ts.isTypeLiteralNode(node);
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
-
import { MetadataArray } from "../../../metadata/MetadataArray";
|
|
3
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
|
-
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
-
|
|
6
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
7
|
-
import { iterate_metadata_tag } from "./iterate_metadata_tag";
|
|
8
|
-
|
|
9
|
-
export const iterate_metadata_collection = (
|
|
10
|
-
collection: MetadataCollection,
|
|
11
|
-
): void => {
|
|
12
|
-
for (const array of collection.arrays())
|
|
13
|
-
if (array.recursive === null)
|
|
14
|
-
collection.setArrayRecursive(
|
|
15
|
-
array,
|
|
16
|
-
isArrayRecursive(new Set())(array)(array.value),
|
|
17
|
-
);
|
|
18
|
-
for (const tuple of collection.tuples())
|
|
19
|
-
if (tuple.recursive === null) {
|
|
20
|
-
const visited: Set<Metadata> = new Set();
|
|
21
|
-
collection.setTupleRecursive(
|
|
22
|
-
tuple,
|
|
23
|
-
tuple.elements.some(isTupleRecursive(visited)(tuple)),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
for (const obj of collection.objects()) {
|
|
27
|
-
iterate_metadata_tag(obj);
|
|
28
|
-
if (obj.recursive === null) {
|
|
29
|
-
const visited: Set<Metadata> = new Set();
|
|
30
|
-
collection.setObjectRecursive(
|
|
31
|
-
obj,
|
|
32
|
-
obj.properties.some((p) =>
|
|
33
|
-
isObjectRecursive(visited)(obj)(p.value),
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const isArrayRecursive =
|
|
41
|
-
(visited: Set<Metadata>) =>
|
|
42
|
-
(array: MetadataArray) =>
|
|
43
|
-
(meta: Metadata): boolean => {
|
|
44
|
-
if (visited.has(meta)) return false;
|
|
45
|
-
visited.add(meta);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
meta.arrays.some(
|
|
49
|
-
(a) => a === array || isArrayRecursive(visited)(array)(a.value),
|
|
50
|
-
) ||
|
|
51
|
-
meta.aliases.some((d) =>
|
|
52
|
-
isArrayRecursive(visited)(array)(d.value),
|
|
53
|
-
) ||
|
|
54
|
-
meta.tuples.some(
|
|
55
|
-
(t) =>
|
|
56
|
-
!t.recursive &&
|
|
57
|
-
t.elements.some((e) => isArrayRecursive(visited)(array)(e)),
|
|
58
|
-
) ||
|
|
59
|
-
meta.maps.some((m) => isArrayRecursive(visited)(array)(m.value)) ||
|
|
60
|
-
meta.sets.some((s) => isArrayRecursive(visited)(array)(s)) ||
|
|
61
|
-
(meta.resolved !== null &&
|
|
62
|
-
isArrayRecursive(visited)(array)(meta.resolved.returns)) ||
|
|
63
|
-
(meta.rest !== null && isArrayRecursive(visited)(array)(meta.rest))
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const isTupleRecursive =
|
|
68
|
-
(visited: Set<Metadata>) =>
|
|
69
|
-
(tuple: MetadataTuple) =>
|
|
70
|
-
(meta: Metadata): boolean => {
|
|
71
|
-
if (visited.has(meta)) return false;
|
|
72
|
-
visited.add(meta);
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
meta.tuples.some(
|
|
76
|
-
(t) =>
|
|
77
|
-
t === tuple ||
|
|
78
|
-
t.elements.some((e) => isTupleRecursive(visited)(tuple)(e)),
|
|
79
|
-
) ||
|
|
80
|
-
meta.arrays.some(
|
|
81
|
-
(a) =>
|
|
82
|
-
!a.recursive && isTupleRecursive(visited)(tuple)(a.value),
|
|
83
|
-
) ||
|
|
84
|
-
meta.maps.some((m) => isTupleRecursive(visited)(tuple)(m.value)) ||
|
|
85
|
-
meta.sets.some((s) => isTupleRecursive(visited)(tuple)(s)) ||
|
|
86
|
-
meta.aliases.some((d) =>
|
|
87
|
-
isTupleRecursive(visited)(tuple)(d.value),
|
|
88
|
-
) ||
|
|
89
|
-
(meta.resolved !== null &&
|
|
90
|
-
isTupleRecursive(visited)(tuple)(meta.resolved.returns)) ||
|
|
91
|
-
(meta.rest !== null && isTupleRecursive(visited)(tuple)(meta.rest))
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const isObjectRecursive =
|
|
96
|
-
(visited: Set<Metadata>) =>
|
|
97
|
-
(obj: MetadataObject) =>
|
|
98
|
-
(meta: Metadata): boolean => {
|
|
99
|
-
if (visited.has(meta)) return false;
|
|
100
|
-
|
|
101
|
-
visited.add(meta);
|
|
102
|
-
return (
|
|
103
|
-
meta.objects.some(
|
|
104
|
-
(o) =>
|
|
105
|
-
obj === o ||
|
|
106
|
-
o.properties.some((prop) =>
|
|
107
|
-
isObjectRecursive(visited)(obj)(prop.value),
|
|
108
|
-
),
|
|
109
|
-
) ||
|
|
110
|
-
meta.aliases.some((alias) =>
|
|
111
|
-
isObjectRecursive(visited)(obj)(alias.value),
|
|
112
|
-
) ||
|
|
113
|
-
meta.arrays.some(
|
|
114
|
-
(array) =>
|
|
115
|
-
!array.recursive &&
|
|
116
|
-
isObjectRecursive(visited)(obj)(array.value),
|
|
117
|
-
) ||
|
|
118
|
-
meta.tuples.some(
|
|
119
|
-
(tuple) =>
|
|
120
|
-
!tuple.recursive &&
|
|
121
|
-
tuple.elements.some((elem) =>
|
|
122
|
-
isObjectRecursive(visited)(obj)(elem),
|
|
123
|
-
),
|
|
124
|
-
) ||
|
|
125
|
-
meta.maps.some((map) =>
|
|
126
|
-
isObjectRecursive(visited)(obj)(map.value),
|
|
127
|
-
) ||
|
|
128
|
-
meta.sets.some((value) => isObjectRecursive(visited)(obj)(value)) ||
|
|
129
|
-
(meta.resolved !== null &&
|
|
130
|
-
isObjectRecursive(visited)(obj)(meta.resolved.returns)) ||
|
|
131
|
-
(meta.rest !== null && isObjectRecursive(visited)(obj)(meta.rest))
|
|
132
|
-
);
|
|
133
|
-
};
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataArray } from "../../../metadata/MetadataArray";
|
|
3
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
|
+
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
+
|
|
6
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
7
|
+
import { iterate_metadata_tag } from "./iterate_metadata_tag";
|
|
8
|
+
|
|
9
|
+
export const iterate_metadata_collection = (
|
|
10
|
+
collection: MetadataCollection,
|
|
11
|
+
): void => {
|
|
12
|
+
for (const array of collection.arrays())
|
|
13
|
+
if (array.recursive === null)
|
|
14
|
+
collection.setArrayRecursive(
|
|
15
|
+
array,
|
|
16
|
+
isArrayRecursive(new Set())(array)(array.value),
|
|
17
|
+
);
|
|
18
|
+
for (const tuple of collection.tuples())
|
|
19
|
+
if (tuple.recursive === null) {
|
|
20
|
+
const visited: Set<Metadata> = new Set();
|
|
21
|
+
collection.setTupleRecursive(
|
|
22
|
+
tuple,
|
|
23
|
+
tuple.elements.some(isTupleRecursive(visited)(tuple)),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
for (const obj of collection.objects()) {
|
|
27
|
+
iterate_metadata_tag(obj);
|
|
28
|
+
if (obj.recursive === null) {
|
|
29
|
+
const visited: Set<Metadata> = new Set();
|
|
30
|
+
collection.setObjectRecursive(
|
|
31
|
+
obj,
|
|
32
|
+
obj.properties.some((p) =>
|
|
33
|
+
isObjectRecursive(visited)(obj)(p.value),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const isArrayRecursive =
|
|
41
|
+
(visited: Set<Metadata>) =>
|
|
42
|
+
(array: MetadataArray) =>
|
|
43
|
+
(meta: Metadata): boolean => {
|
|
44
|
+
if (visited.has(meta)) return false;
|
|
45
|
+
visited.add(meta);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
meta.arrays.some(
|
|
49
|
+
(a) => a === array || isArrayRecursive(visited)(array)(a.value),
|
|
50
|
+
) ||
|
|
51
|
+
meta.aliases.some((d) =>
|
|
52
|
+
isArrayRecursive(visited)(array)(d.value),
|
|
53
|
+
) ||
|
|
54
|
+
meta.tuples.some(
|
|
55
|
+
(t) =>
|
|
56
|
+
!t.recursive &&
|
|
57
|
+
t.elements.some((e) => isArrayRecursive(visited)(array)(e)),
|
|
58
|
+
) ||
|
|
59
|
+
meta.maps.some((m) => isArrayRecursive(visited)(array)(m.value)) ||
|
|
60
|
+
meta.sets.some((s) => isArrayRecursive(visited)(array)(s)) ||
|
|
61
|
+
(meta.resolved !== null &&
|
|
62
|
+
isArrayRecursive(visited)(array)(meta.resolved.returns)) ||
|
|
63
|
+
(meta.rest !== null && isArrayRecursive(visited)(array)(meta.rest))
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const isTupleRecursive =
|
|
68
|
+
(visited: Set<Metadata>) =>
|
|
69
|
+
(tuple: MetadataTuple) =>
|
|
70
|
+
(meta: Metadata): boolean => {
|
|
71
|
+
if (visited.has(meta)) return false;
|
|
72
|
+
visited.add(meta);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
meta.tuples.some(
|
|
76
|
+
(t) =>
|
|
77
|
+
t === tuple ||
|
|
78
|
+
t.elements.some((e) => isTupleRecursive(visited)(tuple)(e)),
|
|
79
|
+
) ||
|
|
80
|
+
meta.arrays.some(
|
|
81
|
+
(a) =>
|
|
82
|
+
!a.recursive && isTupleRecursive(visited)(tuple)(a.value),
|
|
83
|
+
) ||
|
|
84
|
+
meta.maps.some((m) => isTupleRecursive(visited)(tuple)(m.value)) ||
|
|
85
|
+
meta.sets.some((s) => isTupleRecursive(visited)(tuple)(s)) ||
|
|
86
|
+
meta.aliases.some((d) =>
|
|
87
|
+
isTupleRecursive(visited)(tuple)(d.value),
|
|
88
|
+
) ||
|
|
89
|
+
(meta.resolved !== null &&
|
|
90
|
+
isTupleRecursive(visited)(tuple)(meta.resolved.returns)) ||
|
|
91
|
+
(meta.rest !== null && isTupleRecursive(visited)(tuple)(meta.rest))
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const isObjectRecursive =
|
|
96
|
+
(visited: Set<Metadata>) =>
|
|
97
|
+
(obj: MetadataObject) =>
|
|
98
|
+
(meta: Metadata): boolean => {
|
|
99
|
+
if (visited.has(meta)) return false;
|
|
100
|
+
|
|
101
|
+
visited.add(meta);
|
|
102
|
+
return (
|
|
103
|
+
meta.objects.some(
|
|
104
|
+
(o) =>
|
|
105
|
+
obj === o ||
|
|
106
|
+
o.properties.some((prop) =>
|
|
107
|
+
isObjectRecursive(visited)(obj)(prop.value),
|
|
108
|
+
),
|
|
109
|
+
) ||
|
|
110
|
+
meta.aliases.some((alias) =>
|
|
111
|
+
isObjectRecursive(visited)(obj)(alias.value),
|
|
112
|
+
) ||
|
|
113
|
+
meta.arrays.some(
|
|
114
|
+
(array) =>
|
|
115
|
+
!array.recursive &&
|
|
116
|
+
isObjectRecursive(visited)(obj)(array.value),
|
|
117
|
+
) ||
|
|
118
|
+
meta.tuples.some(
|
|
119
|
+
(tuple) =>
|
|
120
|
+
!tuple.recursive &&
|
|
121
|
+
tuple.elements.some((elem) =>
|
|
122
|
+
isObjectRecursive(visited)(obj)(elem),
|
|
123
|
+
),
|
|
124
|
+
) ||
|
|
125
|
+
meta.maps.some((map) =>
|
|
126
|
+
isObjectRecursive(visited)(obj)(map.value),
|
|
127
|
+
) ||
|
|
128
|
+
meta.sets.some((value) => isObjectRecursive(visited)(obj)(value)) ||
|
|
129
|
+
(meta.resolved !== null &&
|
|
130
|
+
isObjectRecursive(visited)(obj)(meta.resolved.returns)) ||
|
|
131
|
+
(meta.rest !== null && isObjectRecursive(visited)(obj)(meta.rest))
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
2
|
-
|
|
3
|
-
import { Writable } from "../../../typings/Writable";
|
|
4
|
-
|
|
5
|
-
import { Escaper } from "../../../utils/Escaper";
|
|
6
|
-
|
|
7
|
-
import { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
8
|
-
|
|
9
|
-
export const iterate_metadata_tag = (obj: MetadataObject) => {
|
|
10
|
-
if (obj.tagged_ === true) return;
|
|
11
|
-
obj.tagged_ = true;
|
|
12
|
-
|
|
13
|
-
for (const prop of obj.properties) {
|
|
14
|
-
const key: string = prop.key.getName();
|
|
15
|
-
const variable: string | null =
|
|
16
|
-
key.length >= 3 &&
|
|
17
|
-
key[0] === '"' &&
|
|
18
|
-
key[key.length - 1] === '"' &&
|
|
19
|
-
Escaper.variable(key.slice(1, -1))
|
|
20
|
-
? key.slice(1, -1)
|
|
21
|
-
: null;
|
|
22
|
-
|
|
23
|
-
Writable(prop).tags = MetadataTagFactory.generate(prop.value)(
|
|
24
|
-
prop.jsDocTags,
|
|
25
|
-
)(
|
|
26
|
-
variable !== null
|
|
27
|
-
? () => `${obj.name}.${variable}`
|
|
28
|
-
: () => `${obj.name}[${key}]`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
1
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
2
|
+
|
|
3
|
+
import { Writable } from "../../../typings/Writable";
|
|
4
|
+
|
|
5
|
+
import { Escaper } from "../../../utils/Escaper";
|
|
6
|
+
|
|
7
|
+
import { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
8
|
+
|
|
9
|
+
export const iterate_metadata_tag = (obj: MetadataObject) => {
|
|
10
|
+
if (obj.tagged_ === true) return;
|
|
11
|
+
obj.tagged_ = true;
|
|
12
|
+
|
|
13
|
+
for (const prop of obj.properties) {
|
|
14
|
+
const key: string = prop.key.getName();
|
|
15
|
+
const variable: string | null =
|
|
16
|
+
key.length >= 3 &&
|
|
17
|
+
key[0] === '"' &&
|
|
18
|
+
key[key.length - 1] === '"' &&
|
|
19
|
+
Escaper.variable(key.slice(1, -1))
|
|
20
|
+
? key.slice(1, -1)
|
|
21
|
+
: null;
|
|
22
|
+
|
|
23
|
+
Writable(prop).tags = MetadataTagFactory.generate(prop.value)(
|
|
24
|
+
prop.jsDocTags,
|
|
25
|
+
)(
|
|
26
|
+
variable !== null
|
|
27
|
+
? () => `${obj.name}.${variable}`
|
|
28
|
+
: () => `${obj.name}[${key}]`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import { ClassProperties } from "../typings/ClassProperties";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "./IJsDocTagInfo";
|
|
4
|
-
import { IMetadataObject } from "./IMetadataObject";
|
|
5
|
-
import { MetadataProperty } from "./MetadataProperty";
|
|
6
|
-
|
|
7
|
-
export class MetadataObject {
|
|
8
|
-
public readonly name: string;
|
|
9
|
-
public readonly properties: Array<MetadataProperty>;
|
|
10
|
-
public readonly description: string | undefined;
|
|
11
|
-
public readonly jsDocTags: IJsDocTagInfo[];
|
|
12
|
-
|
|
13
|
-
public readonly index: number;
|
|
14
|
-
public validated: boolean;
|
|
15
|
-
public recursive: boolean;
|
|
16
|
-
public nullables: boolean[] = [];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
public tagged_: boolean = false;
|
|
22
|
-
|
|
23
|
-
/* -----------------------------------------------------------
|
|
24
|
-
CONSTRUCTORS
|
|
25
|
-
----------------------------------------------------------- */
|
|
26
|
-
/**
|
|
27
|
-
* @hidden
|
|
28
|
-
*/
|
|
29
|
-
private constructor(
|
|
30
|
-
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
31
|
-
) {
|
|
32
|
-
this.name = props.name;
|
|
33
|
-
this.properties = props.properties;
|
|
34
|
-
this.description = props.description;
|
|
35
|
-
this.jsDocTags = props.jsDocTags;
|
|
36
|
-
|
|
37
|
-
this.index = props.index;
|
|
38
|
-
this.validated = props.validated;
|
|
39
|
-
this.recursive = props.recursive;
|
|
40
|
-
this.nullables = [];
|
|
41
|
-
|
|
42
|
-
this.tagged_ = false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
public static create(
|
|
49
|
-
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
50
|
-
) {
|
|
51
|
-
return new MetadataObject(props);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
public static _From_without_properties(
|
|
58
|
-
obj: IMetadataObject,
|
|
59
|
-
): MetadataObject {
|
|
60
|
-
return this.create({
|
|
61
|
-
name: obj.name,
|
|
62
|
-
properties: [],
|
|
63
|
-
description: obj.description,
|
|
64
|
-
jsDocTags: obj.jsDocTags,
|
|
65
|
-
|
|
66
|
-
index: obj.index,
|
|
67
|
-
validated: obj.validated,
|
|
68
|
-
recursive: obj.recursive,
|
|
69
|
-
nullables: obj.nullables.slice(),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
public _Is_simple(level: number = 0): boolean {
|
|
77
|
-
return (
|
|
78
|
-
this.recursive === false &&
|
|
79
|
-
this.properties.length < 10 &&
|
|
80
|
-
this.properties.every(
|
|
81
|
-
(property) =>
|
|
82
|
-
property.key.isSoleLiteral() &&
|
|
83
|
-
property.value.size() === 1 &&
|
|
84
|
-
property.value.required === true &&
|
|
85
|
-
property.value.nullable === false &&
|
|
86
|
-
(property.value.atomics.length === 1 ||
|
|
87
|
-
(level < 1 &&
|
|
88
|
-
property.value.objects.length === 1 &&
|
|
89
|
-
property.value.objects[0]!._Is_simple(level + 1))),
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public toJSON(): IMetadataObject {
|
|
95
|
-
return {
|
|
96
|
-
name: this.name,
|
|
97
|
-
properties: this.properties.map((property) => property.toJSON()),
|
|
98
|
-
description: this.description,
|
|
99
|
-
jsDocTags: this.jsDocTags,
|
|
100
|
-
|
|
101
|
-
index: this.index,
|
|
102
|
-
validated: this.validated,
|
|
103
|
-
recursive: this.recursive,
|
|
104
|
-
nullables: this.nullables.slice(),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @internal
|
|
111
|
-
*/
|
|
112
|
-
export namespace MetadataObject {
|
|
113
|
-
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
114
|
-
x.properties.some(
|
|
115
|
-
(prop) =>
|
|
116
|
-
y.properties.find(
|
|
117
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
118
|
-
) !== undefined,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
122
|
-
x.properties.length >= y.properties.length &&
|
|
123
|
-
x.properties.every(
|
|
124
|
-
(prop) =>
|
|
125
|
-
y.properties.find(
|
|
126
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
127
|
-
) !== undefined,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
1
|
+
import { ClassProperties } from "../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "./IJsDocTagInfo";
|
|
4
|
+
import { IMetadataObject } from "./IMetadataObject";
|
|
5
|
+
import { MetadataProperty } from "./MetadataProperty";
|
|
6
|
+
|
|
7
|
+
export class MetadataObject {
|
|
8
|
+
public readonly name: string;
|
|
9
|
+
public readonly properties: Array<MetadataProperty>;
|
|
10
|
+
public readonly description: string | undefined;
|
|
11
|
+
public readonly jsDocTags: IJsDocTagInfo[];
|
|
12
|
+
|
|
13
|
+
public readonly index: number;
|
|
14
|
+
public validated: boolean;
|
|
15
|
+
public recursive: boolean;
|
|
16
|
+
public nullables: boolean[] = [];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
public tagged_: boolean = false;
|
|
22
|
+
|
|
23
|
+
/* -----------------------------------------------------------
|
|
24
|
+
CONSTRUCTORS
|
|
25
|
+
----------------------------------------------------------- */
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
private constructor(
|
|
30
|
+
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
31
|
+
) {
|
|
32
|
+
this.name = props.name;
|
|
33
|
+
this.properties = props.properties;
|
|
34
|
+
this.description = props.description;
|
|
35
|
+
this.jsDocTags = props.jsDocTags;
|
|
36
|
+
|
|
37
|
+
this.index = props.index;
|
|
38
|
+
this.validated = props.validated;
|
|
39
|
+
this.recursive = props.recursive;
|
|
40
|
+
this.nullables = [];
|
|
41
|
+
|
|
42
|
+
this.tagged_ = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
public static create(
|
|
49
|
+
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
50
|
+
) {
|
|
51
|
+
return new MetadataObject(props);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
public static _From_without_properties(
|
|
58
|
+
obj: IMetadataObject,
|
|
59
|
+
): MetadataObject {
|
|
60
|
+
return this.create({
|
|
61
|
+
name: obj.name,
|
|
62
|
+
properties: [],
|
|
63
|
+
description: obj.description,
|
|
64
|
+
jsDocTags: obj.jsDocTags,
|
|
65
|
+
|
|
66
|
+
index: obj.index,
|
|
67
|
+
validated: obj.validated,
|
|
68
|
+
recursive: obj.recursive,
|
|
69
|
+
nullables: obj.nullables.slice(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
public _Is_simple(level: number = 0): boolean {
|
|
77
|
+
return (
|
|
78
|
+
this.recursive === false &&
|
|
79
|
+
this.properties.length < 10 &&
|
|
80
|
+
this.properties.every(
|
|
81
|
+
(property) =>
|
|
82
|
+
property.key.isSoleLiteral() &&
|
|
83
|
+
property.value.size() === 1 &&
|
|
84
|
+
property.value.required === true &&
|
|
85
|
+
property.value.nullable === false &&
|
|
86
|
+
(property.value.atomics.length === 1 ||
|
|
87
|
+
(level < 1 &&
|
|
88
|
+
property.value.objects.length === 1 &&
|
|
89
|
+
property.value.objects[0]!._Is_simple(level + 1))),
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public toJSON(): IMetadataObject {
|
|
95
|
+
return {
|
|
96
|
+
name: this.name,
|
|
97
|
+
properties: this.properties.map((property) => property.toJSON()),
|
|
98
|
+
description: this.description,
|
|
99
|
+
jsDocTags: this.jsDocTags,
|
|
100
|
+
|
|
101
|
+
index: this.index,
|
|
102
|
+
validated: this.validated,
|
|
103
|
+
recursive: this.recursive,
|
|
104
|
+
nullables: this.nullables.slice(),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export namespace MetadataObject {
|
|
113
|
+
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
114
|
+
x.properties.some(
|
|
115
|
+
(prop) =>
|
|
116
|
+
y.properties.find(
|
|
117
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
118
|
+
) !== undefined,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
122
|
+
x.properties.length >= y.properties.length &&
|
|
123
|
+
x.properties.every(
|
|
124
|
+
(prop) =>
|
|
125
|
+
y.properties.find(
|
|
126
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
127
|
+
) !== undefined,
|
|
128
|
+
);
|
|
129
|
+
}
|