typia 3.4.15 → 3.5.0-dev.20221222
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/README.md +48 -7
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +119 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +11 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +134 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +2 -3
- package/src/executable/internal/TypiaSetupWizard.ts +173 -173
- package/src/factories/MetadataCollection.ts +83 -122
- package/src/factories/MetadataFactory.ts +47 -47
- package/src/factories/MetadataTagFactory.ts +351 -351
- package/src/factories/ProtocolFactory.ts +92 -0
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
- package/src/functional/$number.ts +12 -12
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +11 -0
- package/src/metadata/IMetadataTag.ts +137 -122
- package/src/metadata/Metadata.ts +479 -477
- package/src/module.ts +1547 -1535
- package/src/programmers/AssertParseProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +445 -445
- package/src/programmers/AssertStringifyProgrammer.ts +65 -65
- package/src/programmers/CheckerProgrammer.ts +810 -810
- package/src/programmers/IsParseProgrammer.ts +61 -61
- package/src/programmers/IsProgrammer.ts +175 -175
- package/src/programmers/IsStringifyProgrammer.ts +69 -69
- package/src/programmers/MessageProgrammer.ts +116 -0
- package/src/programmers/StringifyProgrammer.ts +762 -762
- package/src/programmers/ValidateParseProgrammer.ts +59 -59
- package/src/programmers/ValidateProgrammer.ts +237 -237
- package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +231 -228
- package/src/programmers/internal/check_bigint.ts +85 -85
- package/src/programmers/internal/check_number.ts +175 -175
- package/src/schemas/IJsonSchema.ts +90 -90
- package/src/transformers/CallExpressionTransformer.ts +131 -124
- package/src/transformers/ITransformOptions.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { IProtocolMessage } from "../messages/IProtocolMessage";
|
|
6
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
7
|
+
import { MetadataFactory } from "./MetadataFactory";
|
|
8
|
+
import { emplace_protocol_object } from "./internal/protocols/emplace_protocol_object";
|
|
9
|
+
import { iterate_protocol_main } from "./internal/protocols/iterate_protocol_main";
|
|
10
|
+
|
|
11
|
+
export namespace ProtocolFactory {
|
|
12
|
+
export const metadata =
|
|
13
|
+
(checker: ts.TypeChecker) =>
|
|
14
|
+
(collection: MetadataCollection) =>
|
|
15
|
+
(type: ts.Type) =>
|
|
16
|
+
MetadataFactory.generate(checker, collection, type, {
|
|
17
|
+
resolve: false,
|
|
18
|
+
constant: true,
|
|
19
|
+
validate: (meta) => {
|
|
20
|
+
if (meta.any) throw new Error(ErrorMessages.NO_ANY);
|
|
21
|
+
else if (meta.functional && meta.size() !== 1)
|
|
22
|
+
throw new Error(ErrorMessages.NO_FUNCTIONAL);
|
|
23
|
+
else if (meta.objects.find((o) => o.name === "__Main"))
|
|
24
|
+
throw new Error(ErrorMessages.NO_MAIN);
|
|
25
|
+
else if (meta.objects.find((o) => o.name === "__Timestamp"))
|
|
26
|
+
throw new Error(ErrorMessages.NO_TIMESTAMP);
|
|
27
|
+
else if (
|
|
28
|
+
meta.objects.some(
|
|
29
|
+
(o) =>
|
|
30
|
+
o.properties.filter((p) =>
|
|
31
|
+
p.key.isSoleLiteral(),
|
|
32
|
+
).length &&
|
|
33
|
+
o.properties.filter(
|
|
34
|
+
(p) => !p.key.isSoleLiteral(),
|
|
35
|
+
).length,
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
throw new Error(ErrorMessages.NO_SIMULATENOUS);
|
|
39
|
+
else if (
|
|
40
|
+
meta.objects.some((o) =>
|
|
41
|
+
o.properties.some((p) => !is_atomic_key(p.key)),
|
|
42
|
+
) ||
|
|
43
|
+
meta.maps.some((m) => !is_atomic_key(m.key))
|
|
44
|
+
)
|
|
45
|
+
throw new Error(ErrorMessages.NOT_ALLOWED_KEY);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const generate =
|
|
50
|
+
(collection: MetadataCollection) =>
|
|
51
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
52
|
+
(meta: Metadata) => {
|
|
53
|
+
// EMPLACE OBJECTS
|
|
54
|
+
for (const obj of collection.objects())
|
|
55
|
+
emplace_protocol_object(dict)(obj);
|
|
56
|
+
|
|
57
|
+
// WHEN NOT OBJECT, WRAP IT INTO A FAKE MAIN OBJECT
|
|
58
|
+
iterate_protocol_main(dict)(meta);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const is_atomic_key = (key: Metadata) => {
|
|
62
|
+
if (
|
|
63
|
+
key.required &&
|
|
64
|
+
key.nullable === false &&
|
|
65
|
+
key.functional === false &&
|
|
66
|
+
key.resolved === null &&
|
|
67
|
+
key.size() ===
|
|
68
|
+
key.atomics.length +
|
|
69
|
+
key.constants
|
|
70
|
+
.map((c) => c.values.length)
|
|
71
|
+
.reduce((a, b) => a + b, 0) +
|
|
72
|
+
key.templates.length
|
|
73
|
+
) {
|
|
74
|
+
const set: Set<string> = new Set();
|
|
75
|
+
for (const atomic of key.atomics) set.add(atomic);
|
|
76
|
+
for (const constant of key.constants) set.add(constant.type);
|
|
77
|
+
if (key.templates.length) set.add("string");
|
|
78
|
+
|
|
79
|
+
return set.size === 1;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const enum ErrorMessages {
|
|
86
|
+
NO_ANY = `Error on typia.message(): any type is not supported in protocol buffer.`,
|
|
87
|
+
NO_FUNCTIONAL = `Error on typia.message(): functional type is not supported in protocol buffer.`,
|
|
88
|
+
NO_MAIN = `Error on typia.message(): reserved type "__Main" has been detected.`,
|
|
89
|
+
NO_TIMESTAMP = `Error on typia.message(): reserved type "__Timestamp" has been detected.`,
|
|
90
|
+
NOT_ALLOWED_KEY = `Error on typia.message(): only atomic key type is supported in protocol buffer.`,
|
|
91
|
+
NO_SIMULATENOUS = `Error on typia.message(): object can't have both regular and dynamic properties in protocol buffer.`,
|
|
92
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
export namespace MetadataHelper {
|
|
4
|
-
export function literal_to_metadata(key: string): Metadata {
|
|
5
|
-
const metadata: Metadata = Metadata.initialize();
|
|
6
|
-
metadata.constants.push({
|
|
7
|
-
type: "string",
|
|
8
|
-
values: [key],
|
|
9
|
-
});
|
|
10
|
-
return metadata;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace MetadataHelper {
|
|
4
|
+
export function literal_to_metadata(key: string): Metadata {
|
|
5
|
+
const metadata: Metadata = Metadata.initialize();
|
|
6
|
+
metadata.constants.push({
|
|
7
|
+
type: "string",
|
|
8
|
+
values: [key],
|
|
9
|
+
});
|
|
10
|
+
return metadata;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,140 +1,140 @@
|
|
|
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
|
-
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) || ts.isPropertyDeclaration(node))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
: (node) =>
|
|
42
|
-
ts.isPropertyDeclaration(node) ||
|
|
43
|
-
ts.isPropertyAssignment(node) ||
|
|
44
|
-
ts.isPropertySignature(node) ||
|
|
45
|
-
ts.isTypeLiteralNode(node);
|
|
46
|
-
|
|
47
|
-
const insert =
|
|
48
|
-
(key: Metadata) =>
|
|
49
|
-
(value: Metadata) =>
|
|
50
|
-
(identifier: () => string) =>
|
|
51
|
-
(
|
|
52
|
-
symbol: ts.Symbol | undefined,
|
|
53
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
54
|
-
): MetadataProperty => {
|
|
55
|
-
// COMMENTS AND TAGS
|
|
56
|
-
const description: string | undefined =
|
|
57
|
-
CommentFactory.generate(
|
|
58
|
-
symbol?.getDocumentationComment(checker) || [],
|
|
59
|
-
) || undefined;
|
|
60
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
61
|
-
symbol?.getJsDocTags() || []
|
|
62
|
-
).filter(filter || (() => true));
|
|
63
|
-
|
|
64
|
-
// THE PROPERTY
|
|
65
|
-
const property = MetadataProperty.create({
|
|
66
|
-
key,
|
|
67
|
-
value,
|
|
68
|
-
description,
|
|
69
|
-
jsDocTags,
|
|
70
|
-
tags: MetadataTagFactory.generate(
|
|
71
|
-
() => identifier(),
|
|
72
|
-
value,
|
|
73
|
-
jsDocTags,
|
|
74
|
-
),
|
|
75
|
-
});
|
|
76
|
-
obj.properties.push(property);
|
|
77
|
-
return property;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
//----
|
|
81
|
-
// REGULAR PROPERTIES
|
|
82
|
-
//----
|
|
83
|
-
for (const prop of parent.getApparentProperties()) {
|
|
84
|
-
// CHECK INTERNAL TAG
|
|
85
|
-
if (
|
|
86
|
-
(prop.getJsDocTags(checker) || []).find(
|
|
87
|
-
(tag) => tag.name === "internal",
|
|
88
|
-
) !== undefined
|
|
89
|
-
)
|
|
90
|
-
continue;
|
|
91
|
-
|
|
92
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
93
|
-
const [node, type] = (() => {
|
|
94
|
-
const node = (prop.getDeclarations() || [])[0] as
|
|
95
|
-
| ts.PropertyDeclaration
|
|
96
|
-
| undefined;
|
|
97
|
-
const type: ts.Type | undefined = node
|
|
98
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
99
|
-
: "getTypeOfPropertyOfType" in checker
|
|
100
|
-
? (checker as any).getTypeOfPropertyOfType(
|
|
101
|
-
parent,
|
|
102
|
-
prop.name,
|
|
103
|
-
)
|
|
104
|
-
: undefined;
|
|
105
|
-
return [node, type];
|
|
106
|
-
})();
|
|
107
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
108
|
-
|
|
109
|
-
// GET EXACT TYPE
|
|
110
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
111
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
112
|
-
collection,
|
|
113
|
-
)(type, false);
|
|
114
|
-
|
|
115
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
116
|
-
if (node?.questionToken) Writable(value).required = false;
|
|
117
|
-
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//----
|
|
121
|
-
// DYNAMIC PROPERTIES
|
|
122
|
-
//----
|
|
123
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
124
|
-
// GET EXACT TYPE
|
|
125
|
-
const analyzer = (type: ts.Type) =>
|
|
126
|
-
explore_metadata(checker)(options)(collection)(type, false);
|
|
127
|
-
const key: Metadata = analyzer(index.keyType);
|
|
128
|
-
const value: Metadata = analyzer(index.type);
|
|
129
|
-
|
|
130
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
131
|
-
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
132
|
-
index.declaration?.parent
|
|
133
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
134
|
-
: undefined,
|
|
135
|
-
(doc) => doc.name !== "default",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return obj;
|
|
140
|
-
};
|
|
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
|
+
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) || ts.isPropertyDeclaration(node))
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
: (node) =>
|
|
42
|
+
ts.isPropertyDeclaration(node) ||
|
|
43
|
+
ts.isPropertyAssignment(node) ||
|
|
44
|
+
ts.isPropertySignature(node) ||
|
|
45
|
+
ts.isTypeLiteralNode(node);
|
|
46
|
+
|
|
47
|
+
const insert =
|
|
48
|
+
(key: Metadata) =>
|
|
49
|
+
(value: Metadata) =>
|
|
50
|
+
(identifier: () => string) =>
|
|
51
|
+
(
|
|
52
|
+
symbol: ts.Symbol | undefined,
|
|
53
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
54
|
+
): MetadataProperty => {
|
|
55
|
+
// COMMENTS AND TAGS
|
|
56
|
+
const description: string | undefined =
|
|
57
|
+
CommentFactory.generate(
|
|
58
|
+
symbol?.getDocumentationComment(checker) || [],
|
|
59
|
+
) || undefined;
|
|
60
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
61
|
+
symbol?.getJsDocTags() || []
|
|
62
|
+
).filter(filter || (() => true));
|
|
63
|
+
|
|
64
|
+
// THE PROPERTY
|
|
65
|
+
const property = MetadataProperty.create({
|
|
66
|
+
key,
|
|
67
|
+
value,
|
|
68
|
+
description,
|
|
69
|
+
jsDocTags,
|
|
70
|
+
tags: MetadataTagFactory.generate(
|
|
71
|
+
() => identifier(),
|
|
72
|
+
value,
|
|
73
|
+
jsDocTags,
|
|
74
|
+
),
|
|
75
|
+
});
|
|
76
|
+
obj.properties.push(property);
|
|
77
|
+
return property;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//----
|
|
81
|
+
// REGULAR PROPERTIES
|
|
82
|
+
//----
|
|
83
|
+
for (const prop of parent.getApparentProperties()) {
|
|
84
|
+
// CHECK INTERNAL TAG
|
|
85
|
+
if (
|
|
86
|
+
(prop.getJsDocTags(checker) || []).find(
|
|
87
|
+
(tag) => tag.name === "internal",
|
|
88
|
+
) !== undefined
|
|
89
|
+
)
|
|
90
|
+
continue;
|
|
91
|
+
|
|
92
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
93
|
+
const [node, type] = (() => {
|
|
94
|
+
const node = (prop.getDeclarations() || [])[0] as
|
|
95
|
+
| ts.PropertyDeclaration
|
|
96
|
+
| undefined;
|
|
97
|
+
const type: ts.Type | undefined = node
|
|
98
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
99
|
+
: "getTypeOfPropertyOfType" in checker
|
|
100
|
+
? (checker as any).getTypeOfPropertyOfType(
|
|
101
|
+
parent,
|
|
102
|
+
prop.name,
|
|
103
|
+
)
|
|
104
|
+
: undefined;
|
|
105
|
+
return [node, type];
|
|
106
|
+
})();
|
|
107
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
108
|
+
|
|
109
|
+
// GET EXACT TYPE
|
|
110
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
111
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
112
|
+
collection,
|
|
113
|
+
)(type, false);
|
|
114
|
+
|
|
115
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
116
|
+
if (node?.questionToken) Writable(value).required = false;
|
|
117
|
+
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//----
|
|
121
|
+
// DYNAMIC PROPERTIES
|
|
122
|
+
//----
|
|
123
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
124
|
+
// GET EXACT TYPE
|
|
125
|
+
const analyzer = (type: ts.Type) =>
|
|
126
|
+
explore_metadata(checker)(options)(collection)(type, false);
|
|
127
|
+
const key: Metadata = analyzer(index.keyType);
|
|
128
|
+
const value: Metadata = analyzer(index.type);
|
|
129
|
+
|
|
130
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
131
|
+
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
132
|
+
index.declaration?.parent
|
|
133
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
134
|
+
: undefined,
|
|
135
|
+
(doc) => doc.name !== "default",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return obj;
|
|
140
|
+
};
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
5
|
-
|
|
6
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
7
|
-
|
|
8
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
9
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
10
|
-
import { iterate_metadata } from "./iterate_metadata";
|
|
11
|
-
|
|
12
|
-
export const explore_metadata =
|
|
13
|
-
(checker: ts.TypeChecker) =>
|
|
14
|
-
(options: MetadataFactory.IOptions) =>
|
|
15
|
-
(collection: MetadataCollection) =>
|
|
16
|
-
(type: ts.Type | null, parentResolved: boolean): Metadata => {
|
|
17
|
-
// CONSTRUCT METADATA
|
|
18
|
-
const meta: Metadata = Metadata.initialize(parentResolved);
|
|
19
|
-
if (type !== null)
|
|
20
|
-
iterate_metadata(checker)(options)(collection)(
|
|
21
|
-
meta,
|
|
22
|
-
type,
|
|
23
|
-
parentResolved,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// SORT OBJECTS
|
|
27
|
-
if (meta.objects.length > 1) {
|
|
28
|
-
meta.objects.sort((x, y) =>
|
|
29
|
-
MetadataObject.covers(x, y)
|
|
30
|
-
? -1
|
|
31
|
-
: MetadataObject.covers(y, x)
|
|
32
|
-
? 1
|
|
33
|
-
: 0,
|
|
34
|
-
);
|
|
35
|
-
if (parentResolved === false)
|
|
36
|
-
meta.union_index = collection.getUnionIndex(meta);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// SORT ARRAYS AND TUPLES
|
|
40
|
-
if (meta.arrays.length > 1)
|
|
41
|
-
meta.arrays.sort((x, y) =>
|
|
42
|
-
Metadata.covers(x, y) ? -1 : Metadata.covers(y, x) ? 1 : 0,
|
|
43
|
-
);
|
|
44
|
-
if (meta.tuples.length > 1)
|
|
45
|
-
meta.tuples.sort((x, y) => {
|
|
46
|
-
const xt = Metadata.initialize();
|
|
47
|
-
const yt = Metadata.initialize();
|
|
48
|
-
|
|
49
|
-
xt.tuples.push(x);
|
|
50
|
-
yt.tuples.push(y);
|
|
51
|
-
|
|
52
|
-
return Metadata.covers(xt, yt)
|
|
53
|
-
? -1
|
|
54
|
-
: Metadata.covers(yt, xt)
|
|
55
|
-
? 1
|
|
56
|
-
: 0;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// EMEND ATOMICS
|
|
60
|
-
for (const type of meta.atomics) {
|
|
61
|
-
const index: number = meta.constants.findIndex(
|
|
62
|
-
(c) => c.type === type,
|
|
63
|
-
);
|
|
64
|
-
if (index !== -1) meta.constants.splice(index, 1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// EMEND BOOLEAN
|
|
68
|
-
{
|
|
69
|
-
const index: number = meta.constants.findIndex(
|
|
70
|
-
(c) => c.type === "boolean",
|
|
71
|
-
);
|
|
72
|
-
if (index !== -1 && meta.constants[index]!.values.length === 2) {
|
|
73
|
-
meta.constants.splice(index, 1);
|
|
74
|
-
ArrayUtil.take(
|
|
75
|
-
meta.atomics,
|
|
76
|
-
(type) => type === "boolean",
|
|
77
|
-
() => "boolean",
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// EMEND TEMPLATE
|
|
83
|
-
if (
|
|
84
|
-
meta.templates.length &&
|
|
85
|
-
meta.atomics.find((type) => type === "string") !== undefined
|
|
86
|
-
)
|
|
87
|
-
meta.templates.splice(0, meta.templates.length);
|
|
88
|
-
|
|
89
|
-
// RETURNS WITH VALIDATION
|
|
90
|
-
if (options.validate) options.validate(meta);
|
|
91
|
-
return meta;
|
|
92
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
7
|
+
|
|
8
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
9
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
10
|
+
import { iterate_metadata } from "./iterate_metadata";
|
|
11
|
+
|
|
12
|
+
export const explore_metadata =
|
|
13
|
+
(checker: ts.TypeChecker) =>
|
|
14
|
+
(options: MetadataFactory.IOptions) =>
|
|
15
|
+
(collection: MetadataCollection) =>
|
|
16
|
+
(type: ts.Type | null, parentResolved: boolean): Metadata => {
|
|
17
|
+
// CONSTRUCT METADATA
|
|
18
|
+
const meta: Metadata = Metadata.initialize(parentResolved);
|
|
19
|
+
if (type !== null)
|
|
20
|
+
iterate_metadata(checker)(options)(collection)(
|
|
21
|
+
meta,
|
|
22
|
+
type,
|
|
23
|
+
parentResolved,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// SORT OBJECTS
|
|
27
|
+
if (meta.objects.length > 1) {
|
|
28
|
+
meta.objects.sort((x, y) =>
|
|
29
|
+
MetadataObject.covers(x, y)
|
|
30
|
+
? -1
|
|
31
|
+
: MetadataObject.covers(y, x)
|
|
32
|
+
? 1
|
|
33
|
+
: 0,
|
|
34
|
+
);
|
|
35
|
+
if (parentResolved === false)
|
|
36
|
+
meta.union_index = collection.getUnionIndex(meta);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// SORT ARRAYS AND TUPLES
|
|
40
|
+
if (meta.arrays.length > 1)
|
|
41
|
+
meta.arrays.sort((x, y) =>
|
|
42
|
+
Metadata.covers(x, y) ? -1 : Metadata.covers(y, x) ? 1 : 0,
|
|
43
|
+
);
|
|
44
|
+
if (meta.tuples.length > 1)
|
|
45
|
+
meta.tuples.sort((x, y) => {
|
|
46
|
+
const xt = Metadata.initialize();
|
|
47
|
+
const yt = Metadata.initialize();
|
|
48
|
+
|
|
49
|
+
xt.tuples.push(x);
|
|
50
|
+
yt.tuples.push(y);
|
|
51
|
+
|
|
52
|
+
return Metadata.covers(xt, yt)
|
|
53
|
+
? -1
|
|
54
|
+
: Metadata.covers(yt, xt)
|
|
55
|
+
? 1
|
|
56
|
+
: 0;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// EMEND ATOMICS
|
|
60
|
+
for (const type of meta.atomics) {
|
|
61
|
+
const index: number = meta.constants.findIndex(
|
|
62
|
+
(c) => c.type === type,
|
|
63
|
+
);
|
|
64
|
+
if (index !== -1) meta.constants.splice(index, 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// EMEND BOOLEAN
|
|
68
|
+
{
|
|
69
|
+
const index: number = meta.constants.findIndex(
|
|
70
|
+
(c) => c.type === "boolean",
|
|
71
|
+
);
|
|
72
|
+
if (index !== -1 && meta.constants[index]!.values.length === 2) {
|
|
73
|
+
meta.constants.splice(index, 1);
|
|
74
|
+
ArrayUtil.take(
|
|
75
|
+
meta.atomics,
|
|
76
|
+
(type) => type === "boolean",
|
|
77
|
+
() => "boolean",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// EMEND TEMPLATE
|
|
83
|
+
if (
|
|
84
|
+
meta.templates.length &&
|
|
85
|
+
meta.atomics.find((type) => type === "string") !== undefined
|
|
86
|
+
)
|
|
87
|
+
meta.templates.splice(0, meta.templates.length);
|
|
88
|
+
|
|
89
|
+
// RETURNS WITH VALIDATION
|
|
90
|
+
if (options.validate) options.validate(meta);
|
|
91
|
+
return meta;
|
|
92
|
+
};
|