typia 4.0.0 → 4.0.1-dev.20230604
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/lib/programmers/ApplicationProgrammer.js +1 -1
- package/lib/programmers/internal/application_array.js +19 -41
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_definition.d.ts +1 -1
- package/lib/programmers/internal/application_definition.js +8 -8
- package/lib/programmers/internal/application_definition.js.map +1 -1
- package/lib/programmers/internal/application_native.js +3 -3
- package/lib/programmers/internal/application_object.js +4 -4
- package/lib/programmers/internal/application_schema.js +3 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +8 -30
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/schemas/IJsonComponents.d.ts +1 -12
- package/lib/schemas/IJsonSchema.d.ts +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +34 -34
- package/src/factories/IdentifierFactory.ts +65 -65
- package/src/factories/MetadataCollection.ts +254 -254
- package/src/factories/MetadataFactory.ts +40 -40
- package/src/factories/MetadataTagFactory.ts +300 -300
- package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
- package/src/factories/internal/metadata/emplace_metadata_definition.ts +35 -35
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
- package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
- package/src/factories/internal/metadata/explore_metadata.ts +66 -66
- package/src/factories/internal/metadata/iterate_metadata.ts +77 -77
- package/src/factories/internal/metadata/iterate_metadata_array.ts +25 -25
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +130 -130
- package/src/factories/internal/metadata/iterate_metadata_definition.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_object.ts +49 -49
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +68 -68
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
- package/src/factories/internal/metadata/iterate_metadata_union.ts +68 -68
- package/src/metadata/IMetadata.ts +27 -27
- package/src/metadata/IMetadataAlias.ts +12 -12
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataArray.ts +10 -10
- package/src/metadata/IMetadataCollection.ts +11 -11
- package/src/metadata/IMetadataDictionary.ts +14 -14
- package/src/metadata/IMetadataObject.ts +18 -18
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTuple.ts +10 -10
- package/src/metadata/Metadata.ts +585 -585
- package/src/metadata/MetadataAlias.ts +61 -61
- package/src/metadata/MetadataArray.ts +52 -52
- package/src/metadata/MetadataObject.ts +114 -114
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/metadata/MetadataTuple.ts +53 -53
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +291 -291
- package/src/programmers/CheckerProgrammer.ts +1182 -1182
- package/src/programmers/CloneProgrammer.ts +595 -595
- package/src/programmers/FeatureProgrammer.ts +495 -495
- package/src/programmers/IsProgrammer.ts +250 -250
- package/src/programmers/LiteralsProgrammer.ts +66 -66
- package/src/programmers/PruneProgrammer.ts +550 -550
- package/src/programmers/RandomProgrammer.ts +589 -589
- package/src/programmers/StringifyProgrammer.ts +990 -990
- package/src/programmers/ValidateProgrammer.ts +313 -313
- package/src/programmers/helpers/FunctionImporeter.ts +78 -78
- package/src/programmers/helpers/RandomJoiner.ts +173 -173
- package/src/programmers/helpers/UnionExplorer.ts +301 -301
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +26 -26
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_array.ts +30 -64
- package/src/programmers/internal/application_boolean.ts +15 -15
- package/src/programmers/internal/application_constant.ts +26 -26
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_definition.ts +45 -45
- package/src/programmers/internal/application_native.ts +39 -39
- package/src/programmers/internal/application_number.ts +74 -74
- package/src/programmers/internal/application_object.ts +167 -167
- package/src/programmers/internal/application_schema.ts +156 -164
- package/src/programmers/internal/application_tuple.ts +47 -77
- package/src/programmers/internal/check_union_array_like.ts +329 -329
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
- package/src/schemas/IJsonApplication.ts +8 -8
- package/src/schemas/IJsonComponents.ts +34 -45
- package/src/schemas/IJsonSchema.ts +134 -134
- package/src/transformers/CallExpressionTransformer.ts +179 -179
- package/src/transformers/FileTransformer.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
- package/src/utils/ArrayUtil.ts +45 -45
- package/src/utils/RandomGenerator.ts +81 -81
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
import { MetadataAlias } from "../../../metadata/MetadataAlias";
|
|
5
|
-
|
|
6
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
7
|
-
|
|
8
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
9
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
10
|
-
import { explore_metadata } from "./explore_metadata";
|
|
11
|
-
|
|
12
|
-
export const emplace_metadata_definition =
|
|
13
|
-
(checker: ts.TypeChecker) =>
|
|
14
|
-
(options: MetadataFactory.IOptions) =>
|
|
15
|
-
(collection: MetadataCollection) =>
|
|
16
|
-
(type: ts.Type, nullable: boolean): MetadataAlias => {
|
|
17
|
-
// CHECK EXISTENCE
|
|
18
|
-
const [alias, newbie, closure] = collection.emplaceAlias(
|
|
19
|
-
checker,
|
|
20
|
-
type,
|
|
21
|
-
type.aliasSymbol!,
|
|
22
|
-
);
|
|
23
|
-
ArrayUtil.add(alias.nullables, nullable);
|
|
24
|
-
if (newbie === false) return alias;
|
|
25
|
-
|
|
26
|
-
// CONSTRUCT VALUE TYPE
|
|
27
|
-
const value: Metadata = explore_metadata(checker)(options)(collection)(
|
|
28
|
-
type,
|
|
29
|
-
false,
|
|
30
|
-
true,
|
|
31
|
-
);
|
|
32
|
-
closure(value);
|
|
33
|
-
|
|
34
|
-
return alias;
|
|
35
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
import { MetadataAlias } from "../../../metadata/MetadataAlias";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
7
|
+
|
|
8
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
9
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
10
|
+
import { explore_metadata } from "./explore_metadata";
|
|
11
|
+
|
|
12
|
+
export const emplace_metadata_definition =
|
|
13
|
+
(checker: ts.TypeChecker) =>
|
|
14
|
+
(options: MetadataFactory.IOptions) =>
|
|
15
|
+
(collection: MetadataCollection) =>
|
|
16
|
+
(type: ts.Type, nullable: boolean): MetadataAlias => {
|
|
17
|
+
// CHECK EXISTENCE
|
|
18
|
+
const [alias, newbie, closure] = collection.emplaceAlias(
|
|
19
|
+
checker,
|
|
20
|
+
type,
|
|
21
|
+
type.aliasSymbol!,
|
|
22
|
+
);
|
|
23
|
+
ArrayUtil.add(alias.nullables, nullable);
|
|
24
|
+
if (newbie === false) return alias;
|
|
25
|
+
|
|
26
|
+
// CONSTRUCT VALUE TYPE
|
|
27
|
+
const value: Metadata = explore_metadata(checker)(options)(collection)(
|
|
28
|
+
type,
|
|
29
|
+
false,
|
|
30
|
+
true,
|
|
31
|
+
);
|
|
32
|
+
closure(value);
|
|
33
|
+
|
|
34
|
+
return alias;
|
|
35
|
+
};
|
|
@@ -1,142 +1,142 @@
|
|
|
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 { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
15
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
16
|
-
import { explore_metadata } from "./explore_metadata";
|
|
17
|
-
|
|
18
|
-
export const emplace_metadata_object =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: MetadataFactory.IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
23
|
-
// EMPLACE OBJECT
|
|
24
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
25
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
26
|
-
|
|
27
|
-
if (newbie === false) return obj;
|
|
28
|
-
|
|
29
|
-
// PREPARE ASSETS
|
|
30
|
-
const isClass: boolean = parent.isClass();
|
|
31
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
32
|
-
? (node) => {
|
|
33
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
34
|
-
.getChildren()[0]
|
|
35
|
-
?.getChildren()[0]?.kind;
|
|
36
|
-
return (
|
|
37
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
38
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
39
|
-
(ts.isParameter(node) || isProperty(node))
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
: (node) => isProperty(node);
|
|
43
|
-
|
|
44
|
-
const insert =
|
|
45
|
-
(key: Metadata) =>
|
|
46
|
-
(value: Metadata) =>
|
|
47
|
-
(identifier: () => string) =>
|
|
48
|
-
(
|
|
49
|
-
symbol: ts.Symbol | undefined,
|
|
50
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
-
): MetadataProperty => {
|
|
52
|
-
// COMMENTS AND TAGS
|
|
53
|
-
const description: string | null = symbol
|
|
54
|
-
? CommentFactory.description(symbol) ?? null
|
|
55
|
-
: null;
|
|
56
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
-
symbol?.getJsDocTags() ?? []
|
|
58
|
-
).filter(filter ?? (() => true));
|
|
59
|
-
|
|
60
|
-
// THE PROPERTY
|
|
61
|
-
const property = MetadataProperty.create({
|
|
62
|
-
key,
|
|
63
|
-
value,
|
|
64
|
-
description,
|
|
65
|
-
jsDocTags,
|
|
66
|
-
tags: MetadataTagFactory.generate(value)(jsDocTags)(() =>
|
|
67
|
-
identifier(),
|
|
68
|
-
),
|
|
69
|
-
});
|
|
70
|
-
obj.properties.push(property);
|
|
71
|
-
return property;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//----
|
|
75
|
-
// REGULAR PROPERTIES
|
|
76
|
-
//----
|
|
77
|
-
for (const prop of parent.getApparentProperties()) {
|
|
78
|
-
// CHECK INTERNAL TAG
|
|
79
|
-
if (
|
|
80
|
-
(prop.getJsDocTags(checker) ?? []).find(
|
|
81
|
-
(tag) => tag.name === "internal",
|
|
82
|
-
) !== undefined
|
|
83
|
-
)
|
|
84
|
-
continue;
|
|
85
|
-
|
|
86
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
87
|
-
const [node, type] = (() => {
|
|
88
|
-
const node = (prop.getDeclarations() ?? [])[0] as
|
|
89
|
-
| ts.PropertyDeclaration
|
|
90
|
-
| undefined;
|
|
91
|
-
const type: ts.Type | undefined = node
|
|
92
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
93
|
-
: "getTypeOfPropertyOfType" in checker
|
|
94
|
-
? (checker as any).getTypeOfPropertyOfType(
|
|
95
|
-
parent,
|
|
96
|
-
prop.name,
|
|
97
|
-
)
|
|
98
|
-
: undefined;
|
|
99
|
-
return [node, type];
|
|
100
|
-
})();
|
|
101
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
102
|
-
|
|
103
|
-
// GET EXACT TYPE
|
|
104
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
105
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
106
|
-
collection,
|
|
107
|
-
)(type, false);
|
|
108
|
-
|
|
109
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
110
|
-
if (node?.questionToken) {
|
|
111
|
-
Writable(value).required = false;
|
|
112
|
-
Writable(value).optional = true;
|
|
113
|
-
}
|
|
114
|
-
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//----
|
|
118
|
-
// DYNAMIC PROPERTIES
|
|
119
|
-
//----
|
|
120
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
121
|
-
// GET EXACT TYPE
|
|
122
|
-
const analyzer = (type: ts.Type) =>
|
|
123
|
-
explore_metadata(checker)(options)(collection)(type, false);
|
|
124
|
-
const key: Metadata = analyzer(index.keyType);
|
|
125
|
-
const value: Metadata = analyzer(index.type);
|
|
126
|
-
|
|
127
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
128
|
-
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
129
|
-
index.declaration?.parent
|
|
130
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
131
|
-
: undefined,
|
|
132
|
-
(doc) => doc.name !== "default",
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
return obj;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const isProperty = (node: ts.Declaration) =>
|
|
139
|
-
ts.isPropertyDeclaration(node) ||
|
|
140
|
-
ts.isPropertyAssignment(node) ||
|
|
141
|
-
ts.isPropertySignature(node) ||
|
|
142
|
-
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 { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
15
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
16
|
+
import { explore_metadata } from "./explore_metadata";
|
|
17
|
+
|
|
18
|
+
export const emplace_metadata_object =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: MetadataFactory.IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
23
|
+
// EMPLACE OBJECT
|
|
24
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
25
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
26
|
+
|
|
27
|
+
if (newbie === false) return obj;
|
|
28
|
+
|
|
29
|
+
// PREPARE ASSETS
|
|
30
|
+
const isClass: boolean = parent.isClass();
|
|
31
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
32
|
+
? (node) => {
|
|
33
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
34
|
+
.getChildren()[0]
|
|
35
|
+
?.getChildren()[0]?.kind;
|
|
36
|
+
return (
|
|
37
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
38
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
39
|
+
(ts.isParameter(node) || isProperty(node))
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
: (node) => isProperty(node);
|
|
43
|
+
|
|
44
|
+
const insert =
|
|
45
|
+
(key: Metadata) =>
|
|
46
|
+
(value: Metadata) =>
|
|
47
|
+
(identifier: () => string) =>
|
|
48
|
+
(
|
|
49
|
+
symbol: ts.Symbol | undefined,
|
|
50
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
+
): MetadataProperty => {
|
|
52
|
+
// COMMENTS AND TAGS
|
|
53
|
+
const description: string | null = symbol
|
|
54
|
+
? CommentFactory.description(symbol) ?? null
|
|
55
|
+
: null;
|
|
56
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
+
symbol?.getJsDocTags() ?? []
|
|
58
|
+
).filter(filter ?? (() => true));
|
|
59
|
+
|
|
60
|
+
// THE PROPERTY
|
|
61
|
+
const property = MetadataProperty.create({
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
description,
|
|
65
|
+
jsDocTags,
|
|
66
|
+
tags: MetadataTagFactory.generate(value)(jsDocTags)(() =>
|
|
67
|
+
identifier(),
|
|
68
|
+
),
|
|
69
|
+
});
|
|
70
|
+
obj.properties.push(property);
|
|
71
|
+
return property;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//----
|
|
75
|
+
// REGULAR PROPERTIES
|
|
76
|
+
//----
|
|
77
|
+
for (const prop of parent.getApparentProperties()) {
|
|
78
|
+
// CHECK INTERNAL TAG
|
|
79
|
+
if (
|
|
80
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
81
|
+
(tag) => tag.name === "internal",
|
|
82
|
+
) !== undefined
|
|
83
|
+
)
|
|
84
|
+
continue;
|
|
85
|
+
|
|
86
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
87
|
+
const [node, type] = (() => {
|
|
88
|
+
const node = (prop.getDeclarations() ?? [])[0] as
|
|
89
|
+
| ts.PropertyDeclaration
|
|
90
|
+
| undefined;
|
|
91
|
+
const type: ts.Type | undefined = node
|
|
92
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
93
|
+
: "getTypeOfPropertyOfType" in checker
|
|
94
|
+
? (checker as any).getTypeOfPropertyOfType(
|
|
95
|
+
parent,
|
|
96
|
+
prop.name,
|
|
97
|
+
)
|
|
98
|
+
: undefined;
|
|
99
|
+
return [node, type];
|
|
100
|
+
})();
|
|
101
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
102
|
+
|
|
103
|
+
// GET EXACT TYPE
|
|
104
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
105
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
106
|
+
collection,
|
|
107
|
+
)(type, false);
|
|
108
|
+
|
|
109
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
110
|
+
if (node?.questionToken) {
|
|
111
|
+
Writable(value).required = false;
|
|
112
|
+
Writable(value).optional = true;
|
|
113
|
+
}
|
|
114
|
+
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//----
|
|
118
|
+
// DYNAMIC PROPERTIES
|
|
119
|
+
//----
|
|
120
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
121
|
+
// GET EXACT TYPE
|
|
122
|
+
const analyzer = (type: ts.Type) =>
|
|
123
|
+
explore_metadata(checker)(options)(collection)(type, false);
|
|
124
|
+
const key: Metadata = analyzer(index.keyType);
|
|
125
|
+
const value: Metadata = analyzer(index.type);
|
|
126
|
+
|
|
127
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
128
|
+
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
129
|
+
index.declaration?.parent
|
|
130
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
131
|
+
: undefined,
|
|
132
|
+
(doc) => doc.name !== "default",
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return obj;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const isProperty = (node: ts.Declaration) =>
|
|
139
|
+
ts.isPropertyDeclaration(node) ||
|
|
140
|
+
ts.isPropertyAssignment(node) ||
|
|
141
|
+
ts.isPropertySignature(node) ||
|
|
142
|
+
ts.isTypeLiteralNode(node);
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
-
|
|
6
|
-
import { Writable } from "../../../typings/Writable";
|
|
7
|
-
|
|
8
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
9
|
-
|
|
10
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
11
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
12
|
-
import { explore_metadata } from "./explore_metadata";
|
|
13
|
-
|
|
14
|
-
export const emplace_metadata_tuple =
|
|
15
|
-
(checker: ts.TypeChecker) =>
|
|
16
|
-
(options: MetadataFactory.IOptions) =>
|
|
17
|
-
(collection: MetadataCollection) =>
|
|
18
|
-
(type: ts.TupleType, nullable: boolean): MetadataTuple => {
|
|
19
|
-
// CHECK EXISTENCE
|
|
20
|
-
const [tuple, newbie, closure] = collection.emplaceTuple(checker, type);
|
|
21
|
-
ArrayUtil.add(tuple.nullables, nullable);
|
|
22
|
-
if (newbie === false) return tuple;
|
|
23
|
-
|
|
24
|
-
// CONSTRUCT ELEMENT TYPES
|
|
25
|
-
const flagList: readonly ts.ElementFlags[] =
|
|
26
|
-
type.elementFlags ??
|
|
27
|
-
(type.target as ts.TupleType)?.elementFlags ??
|
|
28
|
-
[];
|
|
29
|
-
const elements: Metadata[] = checker
|
|
30
|
-
.getTypeArguments(type as ts.TypeReference)
|
|
31
|
-
.map((elem, i) => {
|
|
32
|
-
const child: Metadata = explore_metadata(checker)(options)(
|
|
33
|
-
collection,
|
|
34
|
-
)(elem, false, false);
|
|
35
|
-
|
|
36
|
-
// CHECK OPTIONAL
|
|
37
|
-
const flag: ts.ElementFlags | undefined = flagList[i];
|
|
38
|
-
if (flag === ts.ElementFlags.Optional)
|
|
39
|
-
Writable(child).optional = true;
|
|
40
|
-
|
|
41
|
-
// REST TYPE
|
|
42
|
-
if (flag !== ts.ElementFlags.Rest) return child;
|
|
43
|
-
const wrapper: Metadata = Metadata.initialize();
|
|
44
|
-
Writable(wrapper).rest = child;
|
|
45
|
-
return wrapper;
|
|
46
|
-
});
|
|
47
|
-
closure(elements);
|
|
48
|
-
|
|
49
|
-
return tuple;
|
|
50
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
+
|
|
6
|
+
import { Writable } from "../../../typings/Writable";
|
|
7
|
+
|
|
8
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
9
|
+
|
|
10
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
11
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
12
|
+
import { explore_metadata } from "./explore_metadata";
|
|
13
|
+
|
|
14
|
+
export const emplace_metadata_tuple =
|
|
15
|
+
(checker: ts.TypeChecker) =>
|
|
16
|
+
(options: MetadataFactory.IOptions) =>
|
|
17
|
+
(collection: MetadataCollection) =>
|
|
18
|
+
(type: ts.TupleType, nullable: boolean): MetadataTuple => {
|
|
19
|
+
// CHECK EXISTENCE
|
|
20
|
+
const [tuple, newbie, closure] = collection.emplaceTuple(checker, type);
|
|
21
|
+
ArrayUtil.add(tuple.nullables, nullable);
|
|
22
|
+
if (newbie === false) return tuple;
|
|
23
|
+
|
|
24
|
+
// CONSTRUCT ELEMENT TYPES
|
|
25
|
+
const flagList: readonly ts.ElementFlags[] =
|
|
26
|
+
type.elementFlags ??
|
|
27
|
+
(type.target as ts.TupleType)?.elementFlags ??
|
|
28
|
+
[];
|
|
29
|
+
const elements: Metadata[] = checker
|
|
30
|
+
.getTypeArguments(type as ts.TypeReference)
|
|
31
|
+
.map((elem, i) => {
|
|
32
|
+
const child: Metadata = explore_metadata(checker)(options)(
|
|
33
|
+
collection,
|
|
34
|
+
)(elem, false, false);
|
|
35
|
+
|
|
36
|
+
// CHECK OPTIONAL
|
|
37
|
+
const flag: ts.ElementFlags | undefined = flagList[i];
|
|
38
|
+
if (flag === ts.ElementFlags.Optional)
|
|
39
|
+
Writable(child).optional = true;
|
|
40
|
+
|
|
41
|
+
// REST TYPE
|
|
42
|
+
if (flag !== ts.ElementFlags.Rest) return child;
|
|
43
|
+
const wrapper: Metadata = Metadata.initialize();
|
|
44
|
+
Writable(wrapper).rest = child;
|
|
45
|
+
return wrapper;
|
|
46
|
+
});
|
|
47
|
+
closure(elements);
|
|
48
|
+
|
|
49
|
+
return tuple;
|
|
50
|
+
};
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
8
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
9
|
-
import { iterate_metadata } from "./iterate_metadata";
|
|
10
|
-
|
|
11
|
-
export const explore_metadata =
|
|
12
|
-
(checker: ts.TypeChecker) =>
|
|
13
|
-
(options: MetadataFactory.IOptions) =>
|
|
14
|
-
(collection: MetadataCollection) =>
|
|
15
|
-
(
|
|
16
|
-
type: ts.Type | null,
|
|
17
|
-
parentResolved: boolean,
|
|
18
|
-
aliased: boolean = false,
|
|
19
|
-
): Metadata => {
|
|
20
|
-
// CONSTRUCT METADATA
|
|
21
|
-
const meta: Metadata = Metadata.initialize(parentResolved);
|
|
22
|
-
const out = (meta: Metadata) => {
|
|
23
|
-
if (options.validate) options.validate(meta);
|
|
24
|
-
return meta;
|
|
25
|
-
};
|
|
26
|
-
if (type === null) return out(meta);
|
|
27
|
-
|
|
28
|
-
// ITERATE TYPESCRIPT TYPES
|
|
29
|
-
iterate_metadata(checker)(options)(collection)(
|
|
30
|
-
meta,
|
|
31
|
-
type,
|
|
32
|
-
parentResolved,
|
|
33
|
-
aliased,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// EMEND ATOMICS
|
|
37
|
-
for (const type of meta.atomics) {
|
|
38
|
-
const index: number = meta.constants.findIndex(
|
|
39
|
-
(c) => c.type === type,
|
|
40
|
-
);
|
|
41
|
-
if (index !== -1) meta.constants.splice(index, 1);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// EMEND BOOLEAN
|
|
45
|
-
{
|
|
46
|
-
const index: number = meta.constants.findIndex(
|
|
47
|
-
(c) => c.type === "boolean",
|
|
48
|
-
);
|
|
49
|
-
if (index !== -1 && meta.constants[index]!.values.length === 2) {
|
|
50
|
-
meta.constants.splice(index, 1);
|
|
51
|
-
ArrayUtil.take(
|
|
52
|
-
meta.atomics,
|
|
53
|
-
(type) => type === "boolean",
|
|
54
|
-
() => "boolean",
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// EMEND TEMPLATE
|
|
60
|
-
if (
|
|
61
|
-
meta.templates.length &&
|
|
62
|
-
meta.atomics.find((type) => type === "string") !== undefined
|
|
63
|
-
)
|
|
64
|
-
meta.templates.splice(0, meta.templates.length);
|
|
65
|
-
return out(meta);
|
|
66
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
8
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
9
|
+
import { iterate_metadata } from "./iterate_metadata";
|
|
10
|
+
|
|
11
|
+
export const explore_metadata =
|
|
12
|
+
(checker: ts.TypeChecker) =>
|
|
13
|
+
(options: MetadataFactory.IOptions) =>
|
|
14
|
+
(collection: MetadataCollection) =>
|
|
15
|
+
(
|
|
16
|
+
type: ts.Type | null,
|
|
17
|
+
parentResolved: boolean,
|
|
18
|
+
aliased: boolean = false,
|
|
19
|
+
): Metadata => {
|
|
20
|
+
// CONSTRUCT METADATA
|
|
21
|
+
const meta: Metadata = Metadata.initialize(parentResolved);
|
|
22
|
+
const out = (meta: Metadata) => {
|
|
23
|
+
if (options.validate) options.validate(meta);
|
|
24
|
+
return meta;
|
|
25
|
+
};
|
|
26
|
+
if (type === null) return out(meta);
|
|
27
|
+
|
|
28
|
+
// ITERATE TYPESCRIPT TYPES
|
|
29
|
+
iterate_metadata(checker)(options)(collection)(
|
|
30
|
+
meta,
|
|
31
|
+
type,
|
|
32
|
+
parentResolved,
|
|
33
|
+
aliased,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// EMEND ATOMICS
|
|
37
|
+
for (const type of meta.atomics) {
|
|
38
|
+
const index: number = meta.constants.findIndex(
|
|
39
|
+
(c) => c.type === type,
|
|
40
|
+
);
|
|
41
|
+
if (index !== -1) meta.constants.splice(index, 1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// EMEND BOOLEAN
|
|
45
|
+
{
|
|
46
|
+
const index: number = meta.constants.findIndex(
|
|
47
|
+
(c) => c.type === "boolean",
|
|
48
|
+
);
|
|
49
|
+
if (index !== -1 && meta.constants[index]!.values.length === 2) {
|
|
50
|
+
meta.constants.splice(index, 1);
|
|
51
|
+
ArrayUtil.take(
|
|
52
|
+
meta.atomics,
|
|
53
|
+
(type) => type === "boolean",
|
|
54
|
+
() => "boolean",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// EMEND TEMPLATE
|
|
60
|
+
if (
|
|
61
|
+
meta.templates.length &&
|
|
62
|
+
meta.atomics.find((type) => type === "string") !== undefined
|
|
63
|
+
)
|
|
64
|
+
meta.templates.splice(0, meta.templates.length);
|
|
65
|
+
return out(meta);
|
|
66
|
+
};
|