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.
Files changed (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. package/src/utils/NameEncoder.ts +32 -0
@@ -1,227 +1,227 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { ArrayUtil } from "../../../utils/ArrayUtil";
6
-
7
- import { TypeFactory } from "../../TypeFactory";
8
-
9
- export const iterate_metadata_native =
10
- (checker: ts.TypeChecker) =>
11
- (meta: Metadata, type: ts.Type): boolean => {
12
- const validator = validate(checker)(type);
13
- const name: string = TypeFactory.getFullName(
14
- checker,
15
- type,
16
- type.getSymbol(),
17
- );
18
-
19
- const simple = SIMPLES.get(name);
20
- if (simple && validator(simple)) {
21
- if (FORBIDDEN.has(name))
22
- throw new Error(
23
- `Error on typia.metadata(): typia does not allow "${name}" class type. Use "${name.toLowerCase()}" type instead.`,
24
- );
25
- ArrayUtil.set(meta.natives, name, (str) => str);
26
- return true;
27
- }
28
-
29
- const complicate = COMPLICATES.get(name);
30
- if (complicate && validator(complicate)) {
31
- ArrayUtil.set(meta.natives, complicate.name ?? name, (str) => str);
32
- return true;
33
- }
34
-
35
- for (const generic of GENERICS)
36
- if (
37
- name.substring(0, generic.name.length) === generic.name &&
38
- validator(generic)
39
- ) {
40
- ArrayUtil.set(meta.natives, generic.name ?? name, (str) => str);
41
- return true;
42
- }
43
- return false;
44
- };
45
-
46
- const validate =
47
- (checker: ts.TypeChecker) => (type: ts.Type) => (info: IClassInfo) =>
48
- (info.methods ?? []).every((method) => {
49
- const returnType = TypeFactory.getReturnType(
50
- checker,
51
- type,
52
- method.name,
53
- );
54
- return (
55
- returnType !== null &&
56
- checker.typeToString(returnType) === method.return
57
- );
58
- }) &&
59
- (info.properties ?? []).every((property) => {
60
- const prop = checker.getPropertyOfType(type, property.name);
61
- const propType = prop?.valueDeclaration
62
- ? checker.getTypeAtLocation(prop?.valueDeclaration)
63
- : undefined;
64
- return (
65
- propType !== undefined &&
66
- checker.typeToString(propType) === property.type
67
- );
68
- });
69
-
70
- const getBinaryProps = (className: string): IClassInfo => ({
71
- name: className,
72
- methods: [
73
- ...["indexOf", "lastIndexOf"].map((name) => ({
74
- name,
75
- return: "number",
76
- })),
77
- ...["some", "every"].map((name) => ({
78
- name,
79
- return: "boolean",
80
- })),
81
- ...["join", "toLocaleString"].map((name) => ({
82
- name,
83
- return: "string",
84
- })),
85
- ...["reverse", "slice", "subarray"].map((name) => ({
86
- name,
87
- return: className,
88
- })),
89
- ],
90
- properties: ["BYTES_PER_ELEMENT", "length", "byteLength", "byteOffset"].map(
91
- (name) => ({
92
- name,
93
- type: "number",
94
- }),
95
- ),
96
- });
97
- const SIMPLES: Map<string, IClassInfo> = new Map([
98
- [
99
- "Date",
100
- {
101
- methods: ["getTime", "getFullYear", "getMonth", "getMinutes"].map(
102
- (name) => ({
103
- name,
104
- return: "number",
105
- }),
106
- ),
107
- },
108
- ],
109
- [
110
- "Boolean",
111
- {
112
- methods: [
113
- {
114
- name: "valueOf",
115
- return: "boolean",
116
- },
117
- ],
118
- },
119
- ],
120
- [
121
- "Number",
122
- {
123
- methods: [
124
- ...["toFixed", "toExponential", "toPrecision"].map((name) => ({
125
- name,
126
- return: "string",
127
- })),
128
- {
129
- name: "valueOf",
130
- return: "number",
131
- },
132
- ],
133
- },
134
- ],
135
- [
136
- "String",
137
- {
138
- methods: [
139
- "charAt",
140
- "concat",
141
- "valueOf",
142
- "trim",
143
- "replace",
144
- "substring",
145
- ].map((name) => ({
146
- name,
147
- return: "string",
148
- })),
149
- },
150
- ],
151
- ...[
152
- "Uint8Array",
153
- "Uint8ClampedArray",
154
- "Uint16Array",
155
- "Uint32Array",
156
- "BigUint64Array",
157
- "Int8Array",
158
- "Int16Array",
159
- "Int32Array",
160
- "BigInt64Array",
161
- "Float32Array",
162
- "Float64Array",
163
- ].map((name) => [name, getBinaryProps(name)] as const),
164
- ...["ArrayBuffer", "SharedArrayBuffer"].map((className) => {
165
- const info: IClassInfo = {
166
- methods: [
167
- {
168
- name: "slice",
169
- return: className,
170
- },
171
- ],
172
- properties: [
173
- {
174
- name: "byteLength",
175
- type: "number",
176
- },
177
- ],
178
- };
179
- return [className, info] as const;
180
- }),
181
- [
182
- "DataView",
183
- {
184
- methods: [
185
- "getFloat32",
186
- "getFloat64",
187
- "getInt8",
188
- "getInt16",
189
- "getInt32",
190
- "getUint8",
191
- "getUint16",
192
- "getUint32",
193
- ].map((name) => ({
194
- name,
195
- return: "number",
196
- })),
197
- },
198
- ],
199
- ]);
200
- const COMPLICATES: Map<string, IClassInfo> = new Map([
201
- [`'buffer'.global.Buffer`, getBinaryProps("Buffer")],
202
- ]);
203
- const GENERICS: Array<IClassInfo & { name: string }> = [
204
- "WeakMap",
205
- "WeakSet",
206
- ].map((name) => ({
207
- name,
208
- methods: ["has", "delete"].map((name) => ({
209
- name,
210
- return: "boolean",
211
- })),
212
- }));
213
- const FORBIDDEN: Set<string> = new Set(["Bolean", "Number", "String"]);
214
-
215
- interface IClassInfo {
216
- name?: string;
217
- methods?: IMethod[];
218
- properties?: IProperty[];
219
- }
220
- interface IProperty {
221
- name: string;
222
- type: string;
223
- }
224
- interface IMethod {
225
- name: string;
226
- return: string;
227
- }
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
6
+
7
+ import { TypeFactory } from "../../TypeFactory";
8
+
9
+ export const iterate_metadata_native =
10
+ (checker: ts.TypeChecker) =>
11
+ (meta: Metadata, type: ts.Type): boolean => {
12
+ const validator = validate(checker)(type);
13
+ const name: string = TypeFactory.getFullName(
14
+ checker,
15
+ type,
16
+ type.getSymbol(),
17
+ );
18
+
19
+ const simple = SIMPLES.get(name);
20
+ if (simple && validator(simple)) {
21
+ if (FORBIDDEN.has(name))
22
+ throw new Error(
23
+ `Error on typia.metadata(): typia does not allow "${name}" class type. Use "${name.toLowerCase()}" type instead.`,
24
+ );
25
+ ArrayUtil.set(meta.natives, name, (str) => str);
26
+ return true;
27
+ }
28
+
29
+ const complicate = COMPLICATES.get(name);
30
+ if (complicate && validator(complicate)) {
31
+ ArrayUtil.set(meta.natives, complicate.name ?? name, (str) => str);
32
+ return true;
33
+ }
34
+
35
+ for (const generic of GENERICS)
36
+ if (
37
+ name.substring(0, generic.name.length) === generic.name &&
38
+ validator(generic)
39
+ ) {
40
+ ArrayUtil.set(meta.natives, generic.name ?? name, (str) => str);
41
+ return true;
42
+ }
43
+ return false;
44
+ };
45
+
46
+ const validate =
47
+ (checker: ts.TypeChecker) => (type: ts.Type) => (info: IClassInfo) =>
48
+ (info.methods ?? []).every((method) => {
49
+ const returnType = TypeFactory.getReturnType(
50
+ checker,
51
+ type,
52
+ method.name,
53
+ );
54
+ return (
55
+ returnType !== null &&
56
+ checker.typeToString(returnType) === method.return
57
+ );
58
+ }) &&
59
+ (info.properties ?? []).every((property) => {
60
+ const prop = checker.getPropertyOfType(type, property.name);
61
+ const propType = prop?.valueDeclaration
62
+ ? checker.getTypeAtLocation(prop?.valueDeclaration)
63
+ : undefined;
64
+ return (
65
+ propType !== undefined &&
66
+ checker.typeToString(propType) === property.type
67
+ );
68
+ });
69
+
70
+ const getBinaryProps = (className: string): IClassInfo => ({
71
+ name: className,
72
+ methods: [
73
+ ...["indexOf", "lastIndexOf"].map((name) => ({
74
+ name,
75
+ return: "number",
76
+ })),
77
+ ...["some", "every"].map((name) => ({
78
+ name,
79
+ return: "boolean",
80
+ })),
81
+ ...["join", "toLocaleString"].map((name) => ({
82
+ name,
83
+ return: "string",
84
+ })),
85
+ ...["reverse", "slice", "subarray"].map((name) => ({
86
+ name,
87
+ return: className,
88
+ })),
89
+ ],
90
+ properties: ["BYTES_PER_ELEMENT", "length", "byteLength", "byteOffset"].map(
91
+ (name) => ({
92
+ name,
93
+ type: "number",
94
+ }),
95
+ ),
96
+ });
97
+ const SIMPLES: Map<string, IClassInfo> = new Map([
98
+ [
99
+ "Date",
100
+ {
101
+ methods: ["getTime", "getFullYear", "getMonth", "getMinutes"].map(
102
+ (name) => ({
103
+ name,
104
+ return: "number",
105
+ }),
106
+ ),
107
+ },
108
+ ],
109
+ [
110
+ "Boolean",
111
+ {
112
+ methods: [
113
+ {
114
+ name: "valueOf",
115
+ return: "boolean",
116
+ },
117
+ ],
118
+ },
119
+ ],
120
+ [
121
+ "Number",
122
+ {
123
+ methods: [
124
+ ...["toFixed", "toExponential", "toPrecision"].map((name) => ({
125
+ name,
126
+ return: "string",
127
+ })),
128
+ {
129
+ name: "valueOf",
130
+ return: "number",
131
+ },
132
+ ],
133
+ },
134
+ ],
135
+ [
136
+ "String",
137
+ {
138
+ methods: [
139
+ "charAt",
140
+ "concat",
141
+ "valueOf",
142
+ "trim",
143
+ "replace",
144
+ "substring",
145
+ ].map((name) => ({
146
+ name,
147
+ return: "string",
148
+ })),
149
+ },
150
+ ],
151
+ ...[
152
+ "Uint8Array",
153
+ "Uint8ClampedArray",
154
+ "Uint16Array",
155
+ "Uint32Array",
156
+ "BigUint64Array",
157
+ "Int8Array",
158
+ "Int16Array",
159
+ "Int32Array",
160
+ "BigInt64Array",
161
+ "Float32Array",
162
+ "Float64Array",
163
+ ].map((name) => [name, getBinaryProps(name)] as const),
164
+ ...["ArrayBuffer", "SharedArrayBuffer"].map((className) => {
165
+ const info: IClassInfo = {
166
+ methods: [
167
+ {
168
+ name: "slice",
169
+ return: className,
170
+ },
171
+ ],
172
+ properties: [
173
+ {
174
+ name: "byteLength",
175
+ type: "number",
176
+ },
177
+ ],
178
+ };
179
+ return [className, info] as const;
180
+ }),
181
+ [
182
+ "DataView",
183
+ {
184
+ methods: [
185
+ "getFloat32",
186
+ "getFloat64",
187
+ "getInt8",
188
+ "getInt16",
189
+ "getInt32",
190
+ "getUint8",
191
+ "getUint16",
192
+ "getUint32",
193
+ ].map((name) => ({
194
+ name,
195
+ return: "number",
196
+ })),
197
+ },
198
+ ],
199
+ ]);
200
+ const COMPLICATES: Map<string, IClassInfo> = new Map([
201
+ [`'buffer'.global.Buffer`, getBinaryProps("Buffer")],
202
+ ]);
203
+ const GENERICS: Array<IClassInfo & { name: string }> = [
204
+ "WeakMap",
205
+ "WeakSet",
206
+ ].map((name) => ({
207
+ name,
208
+ methods: ["has", "delete"].map((name) => ({
209
+ name,
210
+ return: "boolean",
211
+ })),
212
+ }));
213
+ const FORBIDDEN: Set<string> = new Set(["Bolean", "Number", "String"]);
214
+
215
+ interface IClassInfo {
216
+ name?: string;
217
+ methods?: IMethod[];
218
+ properties?: IProperty[];
219
+ }
220
+ interface IProperty {
221
+ name: string;
222
+ type: string;
223
+ }
224
+ interface IMethod {
225
+ name: string;
226
+ return: string;
227
+ }
@@ -1,48 +1,48 @@
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 { emplace_metadata_object } from "./emplace_metadata_object";
11
- import { iterate_metadata } from "./iterate_metadata";
12
-
13
- export const iterate_metadata_object =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
18
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
19
- if (
20
- !filter(ts.TypeFlags.Object) &&
21
- !type.isIntersection() &&
22
- (type as any).intrinsicName !== "object"
23
- )
24
- return false;
25
- else if (type.isIntersection()) {
26
- const fakeCollection = new MetadataCollection();
27
- const fakeSchema: Metadata = Metadata.initialize();
28
-
29
- type.types.forEach((t) =>
30
- iterate_metadata(checker)(options)(fakeCollection)(
31
- fakeSchema,
32
- t,
33
- parentResolved,
34
- ),
35
- );
36
- if (
37
- fakeSchema.objects.length === 0 ||
38
- fakeSchema.objects.length !== fakeSchema.size()
39
- )
40
- return true;
41
- }
42
-
43
- const obj: MetadataObject = emplace_metadata_object(checker)(options)(
44
- collection,
45
- )(type, meta.nullable);
46
- ArrayUtil.add(meta.objects, obj, (elem) => elem.name === obj.name);
47
- return true;
48
- };
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 { emplace_metadata_object } from "./emplace_metadata_object";
11
+ import { iterate_metadata } from "./iterate_metadata";
12
+
13
+ export const iterate_metadata_object =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
18
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
19
+ if (
20
+ !filter(ts.TypeFlags.Object) &&
21
+ !type.isIntersection() &&
22
+ (type as any).intrinsicName !== "object"
23
+ )
24
+ return false;
25
+ else if (type.isIntersection()) {
26
+ const fakeCollection = new MetadataCollection();
27
+ const fakeSchema: Metadata = Metadata.initialize();
28
+
29
+ type.types.forEach((t) =>
30
+ iterate_metadata(checker)(options)(fakeCollection)(
31
+ fakeSchema,
32
+ t,
33
+ parentResolved,
34
+ ),
35
+ );
36
+ if (
37
+ fakeSchema.objects.length === 0 ||
38
+ fakeSchema.objects.length !== fakeSchema.size()
39
+ )
40
+ return true;
41
+ }
42
+
43
+ const obj: MetadataObject = emplace_metadata_object(checker)(options)(
44
+ collection,
45
+ )(type, meta.nullable);
46
+ ArrayUtil.add(meta.objects, obj, (elem) => elem.name === obj.name);
47
+ return true;
48
+ };
@@ -1,27 +1,27 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { Writable } from "../../../typings/Writable";
6
-
7
- import { MetadataCollection } from "../../MetadataCollection";
8
- import { MetadataFactory } from "../../MetadataFactory";
9
- import { TypeFactory } from "../../TypeFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const iterate_metadata_resolve =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
- if (options.resolve === true && parentResolved === false) {
18
- const resolved: ts.Type | null = TypeFactory.resolve(checker, type);
19
- if (resolved !== null) {
20
- Writable(meta).resolved = explore_metadata(checker)(options)(
21
- collection,
22
- )(resolved, true);
23
- return true;
24
- }
25
- }
26
- return false;
27
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../../typings/Writable";
6
+
7
+ import { MetadataCollection } from "../../MetadataCollection";
8
+ import { MetadataFactory } from "../../MetadataFactory";
9
+ import { TypeFactory } from "../../TypeFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const iterate_metadata_resolve =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
+ if (options.resolve === true && parentResolved === false) {
18
+ const resolved: ts.Type | null = TypeFactory.resolve(checker, type);
19
+ if (resolved !== null) {
20
+ Writable(meta).resolved = explore_metadata(checker)(options)(
21
+ collection,
22
+ )(resolved, true);
23
+ return true;
24
+ }
25
+ }
26
+ return false;
27
+ };
@@ -1,33 +1,33 @@
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 { TypeFactory } from "../../TypeFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const iterate_metadata_set =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type): boolean => {
17
- type = checker.getApparentType(type);
18
-
19
- const name = TypeFactory.getFullName(checker, type, type.getSymbol());
20
- const generic = type.aliasSymbol
21
- ? type.aliasTypeArguments
22
- : checker.getTypeArguments(type as ts.TypeReference);
23
- if (name.substring(0, 4) !== "Set<" || generic?.length !== 1)
24
- return false;
25
-
26
- const key: ts.Type = generic[0]!;
27
- ArrayUtil.set(
28
- meta.sets,
29
- explore_metadata(checker)(options)(collection)(key, false),
30
- (elem) => elem.getName(),
31
- );
32
- return true;
33
- };
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 { TypeFactory } from "../../TypeFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const iterate_metadata_set =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type): boolean => {
17
+ type = checker.getApparentType(type);
18
+
19
+ const name = TypeFactory.getFullName(checker, type, type.getSymbol());
20
+ const generic = type.aliasSymbol
21
+ ? type.aliasTypeArguments
22
+ : checker.getTypeArguments(type as ts.TypeReference);
23
+ if (name.substring(0, 4) !== "Set<" || generic?.length !== 1)
24
+ return false;
25
+
26
+ const key: ts.Type = generic[0]!;
27
+ ArrayUtil.set(
28
+ meta.sets,
29
+ explore_metadata(checker)(options)(collection)(key, false),
30
+ (elem) => elem.getName(),
31
+ );
32
+ return true;
33
+ };