typia 3.8.4 → 4.0.0-dev.20230502

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.
Files changed (142) hide show
  1. package/README.md +9 -1
  2. package/lib/factories/ProtocolFactory.d.ts +8 -0
  3. package/lib/factories/ProtocolFactory.js +112 -0
  4. package/lib/factories/ProtocolFactory.js.map +1 -0
  5. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
  6. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +160 -0
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  8. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  9. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  10. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  14. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  15. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  16. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  41. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  42. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  43. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  44. package/lib/functional/$proto_bytes.d.ts +2 -0
  45. package/lib/functional/$proto_bytes.js +37 -0
  46. package/lib/functional/$proto_bytes.js.map +1 -0
  47. package/lib/functional/$proto_field.d.ts +10 -0
  48. package/lib/functional/$proto_field.js +42 -0
  49. package/lib/functional/$proto_field.js.map +1 -0
  50. package/lib/functional/$proto_float.d.ts +4 -0
  51. package/lib/functional/$proto_float.js +28 -0
  52. package/lib/functional/$proto_float.js.map +1 -0
  53. package/lib/functional/$proto_i32.d.ts +2 -0
  54. package/lib/functional/$proto_i32.js +23 -0
  55. package/lib/functional/$proto_i32.js.map +1 -0
  56. package/lib/functional/$proto_i64.d.ts +2 -0
  57. package/lib/functional/$proto_i64.js +31 -0
  58. package/lib/functional/$proto_i64.js.map +1 -0
  59. package/lib/functional/$proto_size.d.ts +6 -0
  60. package/lib/functional/$proto_size.js +76 -0
  61. package/lib/functional/$proto_size.js.map +1 -0
  62. package/lib/functional/$proto_string.d.ts +2 -0
  63. package/lib/functional/$proto_string.js +34 -0
  64. package/lib/functional/$proto_string.js.map +1 -0
  65. package/lib/functional/$varint.d.ts +6 -0
  66. package/lib/functional/$varint.js +99 -0
  67. package/lib/functional/$varint.js.map +1 -0
  68. package/lib/functional/$zigzag.d.ts +4 -0
  69. package/lib/functional/$zigzag.js +34 -0
  70. package/lib/functional/$zigzag.js.map +1 -0
  71. package/lib/messages/IProtocolMap.d.ts +5 -0
  72. package/lib/messages/IProtocolMap.js +3 -0
  73. package/lib/messages/IProtocolMap.js.map +1 -0
  74. package/lib/messages/IProtocolMessage.d.ts +5 -0
  75. package/lib/messages/IProtocolMessage.js +3 -0
  76. package/lib/messages/IProtocolMessage.js.map +1 -0
  77. package/lib/messages/IProtocolProperty.d.ts +12 -0
  78. package/lib/messages/IProtocolProperty.js +3 -0
  79. package/lib/messages/IProtocolProperty.js.map +1 -0
  80. package/lib/metadata/IMetadataTag.d.ts +3 -3
  81. package/lib/metadata/Metadata.js +1 -1
  82. package/lib/metadata/Metadata.js.map +1 -1
  83. package/lib/module.d.ts +2 -0
  84. package/lib/module.js +6 -1
  85. package/lib/module.js.map +1 -1
  86. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  87. package/lib/programmers/MessageProgrammer.js +141 -0
  88. package/lib/programmers/MessageProgrammer.js.map +1 -0
  89. package/lib/transformers/CallExpressionTransformer.js +5 -3
  90. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  91. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  92. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  93. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  94. package/lib/transformers/features/protocols/MessageTransformer.js +20 -0
  95. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  96. package/lib/utils/NameEncoder.d.ts +4 -0
  97. package/lib/utils/NameEncoder.js +89 -0
  98. package/lib/utils/NameEncoder.js.map +1 -0
  99. package/package.json +1 -1
  100. package/src/Primitive.ts +123 -123
  101. package/src/factories/MetadataFactory.ts +62 -62
  102. package/src/factories/ProtocolFactory.ts +79 -0
  103. package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
  104. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
  105. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +167 -0
  106. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  107. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  108. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  109. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  110. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  111. package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
  112. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
  113. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  114. package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
  115. package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
  116. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
  117. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
  118. package/src/functional/$proto_bytes.ts +25 -0
  119. package/src/functional/$proto_field.ts +30 -0
  120. package/src/functional/$proto_float.ts +37 -0
  121. package/src/functional/$proto_i32.ts +29 -0
  122. package/src/functional/$proto_i64.ts +37 -0
  123. package/src/functional/$proto_size.ts +82 -0
  124. package/src/functional/$proto_string.ts +24 -0
  125. package/src/functional/$varint.ts +130 -0
  126. package/src/functional/$zigzag.ts +39 -0
  127. package/src/messages/IProtocolMap.ts +5 -0
  128. package/src/messages/IProtocolMessage.ts +6 -0
  129. package/src/messages/IProtocolProperty.ts +13 -0
  130. package/src/metadata/IMetadata.ts +26 -26
  131. package/src/metadata/IMetadataTag.ts +11 -3
  132. package/src/metadata/Metadata.ts +543 -539
  133. package/src/module.ts +11 -0
  134. package/src/programmers/CheckerProgrammer.ts +901 -901
  135. package/src/programmers/MessageProgrammer.ts +126 -0
  136. package/src/programmers/internal/application_object.ts +155 -155
  137. package/src/programmers/internal/application_tuple.ts +31 -31
  138. package/src/schemas/IJsonSchema.ts +130 -130
  139. package/src/transformers/CallExpressionTransformer.ts +17 -10
  140. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -3
  141. package/src/transformers/features/protocols/MessageTransformer.ts +31 -0
  142. package/src/utils/NameEncoder.ts +32 -0
@@ -1,143 +1,143 @@
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) || isProperty(node))
39
- );
40
- }
41
- : (node) => isProperty(node);
42
-
43
- const insert =
44
- (key: Metadata) =>
45
- (value: Metadata) =>
46
- (identifier: () => string) =>
47
- (
48
- symbol: ts.Symbol | undefined,
49
- filter?: (doc: ts.JSDocTagInfo) => boolean,
50
- ): MetadataProperty => {
51
- // COMMENTS AND TAGS
52
- const description: string | undefined =
53
- CommentFactory.string(
54
- symbol?.getDocumentationComment(checker) || [],
55
- ) || undefined;
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
-
136
- return obj;
137
- };
138
-
139
- const isProperty = (node: ts.Declaration) =>
140
- ts.isPropertyDeclaration(node) ||
141
- ts.isPropertyAssignment(node) ||
142
- ts.isPropertySignature(node) ||
143
- 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
+ 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
+ (identifier: () => string) =>
47
+ (
48
+ symbol: ts.Symbol | undefined,
49
+ filter?: (doc: ts.JSDocTagInfo) => boolean,
50
+ ): MetadataProperty => {
51
+ // COMMENTS AND TAGS
52
+ const description: string | undefined =
53
+ CommentFactory.string(
54
+ symbol?.getDocumentationComment(checker) || [],
55
+ ) || undefined;
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
+
136
+ return obj;
137
+ };
138
+
139
+ const isProperty = (node: ts.Declaration) =>
140
+ ts.isPropertyDeclaration(node) ||
141
+ ts.isPropertyAssignment(node) ||
142
+ ts.isPropertySignature(node) ||
143
+ ts.isTypeLiteralNode(node);
@@ -1,48 +1,48 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { Writable } from "../../../typings/Writable";
6
-
7
- import { ArrayUtil } from "../../../utils/ArrayUtil";
8
-
9
- import { MetadataCollection } from "../../MetadataCollection";
10
- import { MetadataFactory } from "../../MetadataFactory";
11
- import { explore_metadata } from "./explore_metadata";
12
-
13
- export const iterate_metadata_tuple =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (meta: Metadata, type: ts.TupleType): boolean => {
18
- if (!(checker as any).isTupleType(type)) return false;
19
-
20
- const elementFlags: readonly ts.ElementFlags[] =
21
- type.elementFlags ??
22
- (type.target as ts.TupleType)?.elementFlags ??
23
- [];
24
-
25
- const children: Metadata[] = checker
26
- .getTypeArguments(type as ts.TypeReference)
27
- .map((elem, i) => {
28
- const child: Metadata = explore_metadata(checker)(options)(
29
- collection,
30
- )(elem, false);
31
-
32
- // CHECK OPTIONAL
33
- const flag: ts.ElementFlags | undefined = elementFlags[i];
34
- if (flag === ts.ElementFlags.Optional)
35
- Writable(child).optional = true;
36
-
37
- // REST TYPE
38
- if (flag !== ts.ElementFlags.Rest) return child;
39
- const wrapper: Metadata = Metadata.initialize();
40
- Writable(wrapper).rest = child;
41
- return wrapper;
42
- });
43
- ArrayUtil.set(meta.tuples, children, join_tuple_names);
44
- return true;
45
- };
46
-
47
- const join_tuple_names = (metas: Metadata[]): string =>
48
- `[${metas.map((m) => m.getName).join(", ")}]`;
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../../typings/Writable";
6
+
7
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
8
+
9
+ import { MetadataCollection } from "../../MetadataCollection";
10
+ import { MetadataFactory } from "../../MetadataFactory";
11
+ import { explore_metadata } from "./explore_metadata";
12
+
13
+ export const iterate_metadata_tuple =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (meta: Metadata, type: ts.TupleType): boolean => {
18
+ if (!(checker as any).isTupleType(type)) return false;
19
+
20
+ const elementFlags: readonly ts.ElementFlags[] =
21
+ type.elementFlags ??
22
+ (type.target as ts.TupleType)?.elementFlags ??
23
+ [];
24
+
25
+ const children: Metadata[] = checker
26
+ .getTypeArguments(type as ts.TypeReference)
27
+ .map((elem, i) => {
28
+ const child: Metadata = explore_metadata(checker)(options)(
29
+ collection,
30
+ )(elem, false);
31
+
32
+ // CHECK OPTIONAL
33
+ const flag: ts.ElementFlags | undefined = elementFlags[i];
34
+ if (flag === ts.ElementFlags.Optional)
35
+ Writable(child).optional = true;
36
+
37
+ // REST TYPE
38
+ if (flag !== ts.ElementFlags.Rest) return child;
39
+ const wrapper: Metadata = Metadata.initialize();
40
+ Writable(wrapper).rest = child;
41
+ return wrapper;
42
+ });
43
+ ArrayUtil.set(meta.tuples, children, join_tuple_names);
44
+ return true;
45
+ };
46
+
47
+ const join_tuple_names = (metas: Metadata[]): string =>
48
+ `[${metas.map((m) => m.getName).join(", ")}]`;
@@ -0,0 +1,167 @@
1
+ import { IMetadataTag } from "../../../metadata/IMetadataTag";
2
+ import { Metadata } from "../../../metadata/Metadata";
3
+ import { MetadataObject } from "../../../metadata/MetadataObject";
4
+ import { MetadataProperty } from "../../../metadata/MetadataProperty";
5
+
6
+ import { Atomic } from "../../../typings/Atomic";
7
+
8
+ export namespace ProtocolMetadataUtil {
9
+ export function size(meta: Metadata): number {
10
+ return (
11
+ meta.atomics.length +
12
+ meta.constants.filter(
13
+ (c) =>
14
+ meta.atomics.find((type) => c.type === type) === undefined,
15
+ ).length +
16
+ (meta.templates.length !== 0 &&
17
+ meta.atomics.find((type) => type === "string") === undefined &&
18
+ meta.constants.find((c) => c.type === "string") === undefined
19
+ ? 1
20
+ : 0) +
21
+ meta.tuples.length +
22
+ meta.arrays.length +
23
+ meta.sets.length +
24
+ meta.maps.length +
25
+ meta.objects.length +
26
+ meta.natives.filter((n) => n === "Date").length +
27
+ (meta.natives.filter((n) => n !== "Date").length ? 1 : 0)
28
+ );
29
+ }
30
+
31
+ export function standalone(meta: Metadata): boolean {
32
+ return (
33
+ size(meta) === 1 &&
34
+ meta.required === true &&
35
+ meta.nullable === false &&
36
+ meta.tuples.length === 0 &&
37
+ meta.arrays.length === 0 &&
38
+ meta.sets.length === 0 &&
39
+ meta.maps.length === 0 &&
40
+ meta.objects.every((obj) =>
41
+ obj.properties.every((p) => p.key.isSoleLiteral()),
42
+ )
43
+ );
44
+ }
45
+
46
+ export function regular(obj: MetadataObject): boolean {
47
+ return obj.properties.every((p) => p.key.isSoleLiteral());
48
+ }
49
+
50
+ export function object(name: string, index: number): MetadataObject {
51
+ return MetadataObject.create({
52
+ name,
53
+ index,
54
+ properties: [],
55
+ description: undefined,
56
+ jsDocTags: [],
57
+ validated: false,
58
+ recursive: false,
59
+ nullables: [false],
60
+ });
61
+ }
62
+
63
+ export function property(
64
+ key: string,
65
+ value: Metadata,
66
+ tags: IMetadataTag[],
67
+ ): MetadataProperty {
68
+ return MetadataProperty.create({
69
+ key: (() => {
70
+ const meta: Metadata = Metadata.initialize();
71
+ meta.constants.push({
72
+ type: "string",
73
+ values: [key],
74
+ });
75
+ return meta;
76
+ })(),
77
+ value: value,
78
+ description: undefined,
79
+ tags,
80
+ jsDocTags: [],
81
+ });
82
+ }
83
+
84
+ export function array(meta: Metadata): Metadata {
85
+ return Metadata.create({
86
+ any: false,
87
+ required: true,
88
+ optional: false,
89
+ nullable: false,
90
+ functional: false,
91
+ resolved: null,
92
+ atomics: [],
93
+ constants: [],
94
+ templates: [],
95
+ rest: null,
96
+ arrays: [meta],
97
+ tuples: [],
98
+ objects: [],
99
+ natives: [],
100
+ sets: [],
101
+ maps: [],
102
+ });
103
+ }
104
+
105
+ export function atomic(type: Atomic.Literal): Metadata {
106
+ return Metadata.create({
107
+ any: false,
108
+ required: true,
109
+ optional: false,
110
+ nullable: false,
111
+ functional: false,
112
+ resolved: null,
113
+ atomics: [type],
114
+ constants: [],
115
+ templates: [],
116
+ rest: null,
117
+ arrays: [],
118
+ tuples: [],
119
+ objects: [],
120
+ natives: [],
121
+ sets: [],
122
+ maps: [],
123
+ });
124
+ }
125
+
126
+ export function reference(obj: MetadataObject): Metadata {
127
+ return Metadata.create({
128
+ any: false,
129
+ required: true,
130
+ optional: false,
131
+ nullable: false,
132
+ functional: false,
133
+ resolved: null,
134
+ atomics: [],
135
+ constants: [],
136
+ templates: [],
137
+ rest: null,
138
+ arrays: [],
139
+ tuples: [],
140
+ objects: [obj],
141
+ natives: [],
142
+ sets: [],
143
+ maps: [],
144
+ });
145
+ }
146
+
147
+ export function map(elem: Metadata.Entry): Metadata {
148
+ return Metadata.create({
149
+ any: false,
150
+ required: true,
151
+ optional: false,
152
+ nullable: false,
153
+ functional: false,
154
+ resolved: null,
155
+ atomics: [],
156
+ constants: [],
157
+ templates: [],
158
+ rest: null,
159
+ arrays: [],
160
+ tuples: [],
161
+ objects: [],
162
+ natives: [],
163
+ sets: [],
164
+ maps: [elem],
165
+ });
166
+ }
167
+ }
@@ -0,0 +1,25 @@
1
+ import { MetadataObject } from "../../../metadata/MetadataObject";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { emplace_protocol_property } from "./emplace_protocol_property";
5
+
6
+ export const emplace_protocol_object =
7
+ (dict: Map<string, IProtocolMessage>) => (object: MetadataObject) => {
8
+ if (dict.has(object.name)) return;
9
+
10
+ const regular = object.properties.filter((p) => p.key.isSoleLiteral());
11
+ const dynamic = object.properties.filter((p) => !p.key.isSoleLiteral());
12
+
13
+ if (dynamic.length) return;
14
+
15
+ const output: IProtocolMessage = {
16
+ name: object.name,
17
+ properties: [],
18
+ };
19
+ dict.set(object.name, output);
20
+
21
+ output.properties.push(
22
+ ...regular.map((prop) => emplace_protocol_property(dict)(prop)),
23
+ );
24
+ return output;
25
+ };
@@ -0,0 +1,12 @@
1
+ import { MetadataProperty } from "../../../metadata/MetadataProperty";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { IProtocolProperty } from "../../../messages/IProtocolProperty";
5
+ import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
6
+
7
+ export const emplace_protocol_property =
8
+ (dict: Map<string, IProtocolMessage>) =>
9
+ (property: MetadataProperty): IProtocolProperty => ({
10
+ key: property.key.getSoleLiteral()!,
11
+ ...iterate_protocol_metadata(dict)(property.value)(property.tags),
12
+ });
@@ -0,0 +1,34 @@
1
+ import { IMetadataTag } from "../../../metadata/IMetadataTag";
2
+
3
+ import { Atomic } from "../../../typings/Atomic";
4
+
5
+ export const iterate_protocol_atomic =
6
+ (tags: IMetadataTag[]) => (type: Atomic.Literal) => {
7
+ if (type === "boolean") return "bool";
8
+ else if (type === "number") return number(tags);
9
+ else if (type === "bigint") return bigint(tags);
10
+ else return "string";
11
+ };
12
+
13
+ const number = (tagList: IMetadataTag[]) => {
14
+ const filtered: IMetadataTag.INumberType[] = tagList.filter(
15
+ (tag) => tag.kind === "type",
16
+ ) as IMetadataTag.INumberType[];
17
+
18
+ for (const { value } of filtered)
19
+ if (value === "int") return "int32";
20
+ else if (value === "uint") return "uint32";
21
+ return "double";
22
+ };
23
+
24
+ const bigint = (tagList: IMetadataTag[]) => {
25
+ const filtered: IMetadataTag.INumberType[] = tagList.filter(
26
+ (tag) =>
27
+ tag.kind === "type" &&
28
+ (tag.value === "int64" || tag.value === "uint64"),
29
+ ) as IMetadataTag.INumberType[];
30
+
31
+ for (const { value } of filtered)
32
+ if (value === "int64" || value === "uint64") return value;
33
+ return "int64";
34
+ };
@@ -0,0 +1,27 @@
1
+ import { MetadataConstant } from "../../../metadata/MetadataConstant";
2
+
3
+ export const iterate_protocol_constant = ({
4
+ type,
5
+ values,
6
+ }: MetadataConstant) => {
7
+ if (type === "boolean") return "bool";
8
+ else if (type === "number") return number(values);
9
+ else if (type === "bigint") return bigint(values);
10
+ else return "string";
11
+ };
12
+
13
+ const bigint = (values: bigint[]): string => {
14
+ return values.every((v) => v >= BigInt(0)) ? "uint64" : "int64";
15
+ };
16
+
17
+ const number = (values: number[]): string => {
18
+ return values.some((v) => Math.floor(v) !== v)
19
+ ? "double"
20
+ : values.every((v) => v >= 0)
21
+ ? values.every((v) => v <= 2 ** 64 - 1)
22
+ ? "uint32"
23
+ : "uint64"
24
+ : values.every((v) => -(2 ** 31) <= v && v <= 2 ** 31 - 1)
25
+ ? "int32"
26
+ : "int64";
27
+ };
@@ -0,0 +1,19 @@
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
5
+ import { emplace_protocol_object } from "./emplace_protocol_object";
6
+
7
+ export const iterate_protocol_main =
8
+ (dict: Map<string, IProtocolMessage>) =>
9
+ (meta: Metadata): string => {
10
+ // ONLY ONE OBJECT TYPE
11
+ if (ProtocolMetadataUtil.standalone(meta) && meta.objects.length === 1)
12
+ return meta.getName();
13
+
14
+ const obj = ProtocolMetadataUtil.object("__Main", dict.size);
15
+ obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
16
+ emplace_protocol_object(dict)(obj);
17
+
18
+ return obj.name;
19
+ };