typia 3.6.1 → 3.6.3

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 (241) hide show
  1. package/README.md +2 -1
  2. package/lib/factories/internal/metadata/emplace_metadata_object.js +8 -7
  3. package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
  4. package/lib/module.d.ts +2 -2
  5. package/lib/programmers/AssertCloneProgrammer.js +2 -2
  6. package/lib/programmers/AssertCloneProgrammer.js.map +1 -1
  7. package/lib/programmers/AssertParseProgrammer.js +1 -1
  8. package/lib/programmers/AssertParseProgrammer.js.map +1 -1
  9. package/lib/programmers/AssertProgrammer.js +1 -1
  10. package/lib/programmers/AssertProgrammer.js.map +1 -1
  11. package/lib/programmers/AssertPruneProgrammer.js +2 -2
  12. package/lib/programmers/AssertPruneProgrammer.js.map +1 -1
  13. package/lib/programmers/AssertStringifyProgrammer.d.ts +1 -1
  14. package/lib/programmers/AssertStringifyProgrammer.js +3 -3
  15. package/lib/programmers/AssertStringifyProgrammer.js.map +1 -1
  16. package/lib/programmers/IsCloneProgrammer.js +2 -2
  17. package/lib/programmers/IsCloneProgrammer.js.map +1 -1
  18. package/lib/programmers/IsParseProgrammer.js +1 -1
  19. package/lib/programmers/IsParseProgrammer.js.map +1 -1
  20. package/lib/programmers/IsPruneProgrammer.js +2 -2
  21. package/lib/programmers/IsPruneProgrammer.js.map +1 -1
  22. package/lib/programmers/IsStringifyProgrammer.js +2 -2
  23. package/lib/programmers/IsStringifyProgrammer.js.map +1 -1
  24. package/lib/programmers/ValidateCloneProgrammer.js +2 -2
  25. package/lib/programmers/ValidateCloneProgrammer.js.map +1 -1
  26. package/lib/programmers/ValidateParseProgrammer.js +1 -1
  27. package/lib/programmers/ValidateParseProgrammer.js.map +1 -1
  28. package/lib/programmers/ValidateProgrammer.js +1 -1
  29. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  30. package/lib/programmers/ValidatePruneProgrammer.js +2 -2
  31. package/lib/programmers/ValidatePruneProgrammer.js.map +1 -1
  32. package/lib/programmers/ValidateStringifyProgrammer.js +2 -2
  33. package/lib/programmers/ValidateStringifyProgrammer.js.map +1 -1
  34. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js +1 -2
  35. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js.map +1 -1
  36. package/lib/transformers/features/miscellaneous/RandomTransformer.js +1 -2
  37. package/lib/transformers/features/miscellaneous/RandomTransformer.js.map +1 -1
  38. package/lib/transformers/internal/GenericTransformer.d.ts +0 -1
  39. package/lib/transformers/internal/GenericTransformer.js +8 -4
  40. package/lib/transformers/internal/GenericTransformer.js.map +1 -1
  41. package/package.json +2 -1
  42. package/src/IRandomGenerator.ts +16 -16
  43. package/src/IValidation.ts +21 -21
  44. package/src/Primitive.ts +104 -104
  45. package/src/TypeGuardError.ts +36 -36
  46. package/src/executable/TypiaGenerateWizard.ts +87 -87
  47. package/src/executable/TypiaSetupWizard.ts +142 -142
  48. package/src/executable/setup/ArgumentParser.ts +91 -91
  49. package/src/executable/setup/CommandExecutor.ts +8 -8
  50. package/src/executable/setup/FileRetriever.ts +33 -33
  51. package/src/executable/setup/PackageManager.ts +92 -92
  52. package/src/executable/setup/PluginConfigurator.ts +99 -99
  53. package/src/executable/typia.ts +38 -38
  54. package/src/factories/CommentFactory.ts +10 -10
  55. package/src/factories/ExpressionFactory.ts +77 -77
  56. package/src/factories/IdentifierFactory.ts +73 -73
  57. package/src/factories/LiteralFactory.ts +44 -44
  58. package/src/factories/MetadataCollection.ts +122 -122
  59. package/src/factories/MetadataFactory.ts +51 -51
  60. package/src/factories/MetadataTagFactory.ts +265 -265
  61. package/src/factories/StatementFactory.ts +60 -60
  62. package/src/factories/TemplateFactory.ts +56 -56
  63. package/src/factories/TypeFactory.ts +129 -129
  64. package/src/factories/TypiaFileFactory.ts +117 -117
  65. package/src/factories/ValueFactory.ts +12 -12
  66. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  67. package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -140
  68. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  69. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  70. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  71. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  72. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  73. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  74. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  75. package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
  76. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  77. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  78. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  79. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  80. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  81. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  82. package/src/functional/$any.ts +3 -3
  83. package/src/functional/$every.ts +11 -11
  84. package/src/functional/$guard.ts +35 -35
  85. package/src/functional/$is_between.ts +7 -7
  86. package/src/functional/$is_email.ts +5 -5
  87. package/src/functional/$is_ipv4.ts +5 -5
  88. package/src/functional/$is_ipv6.ts +5 -5
  89. package/src/functional/$is_url.ts +5 -5
  90. package/src/functional/$is_uuid.ts +5 -5
  91. package/src/functional/$join.ts +50 -50
  92. package/src/functional/$number.ts +12 -12
  93. package/src/functional/$report.ts +15 -15
  94. package/src/functional/$rest.ts +3 -3
  95. package/src/functional/$string.ts +37 -37
  96. package/src/functional/$tail.ts +6 -6
  97. package/src/functional/Namespace.ts +121 -121
  98. package/src/index.ts +4 -4
  99. package/src/metadata/IJsDocTagInfo.ts +10 -10
  100. package/src/metadata/IMetadata.ts +25 -25
  101. package/src/metadata/IMetadataApplication.ts +7 -7
  102. package/src/metadata/IMetadataConstant.ts +16 -16
  103. package/src/metadata/IMetadataEntry.ts +6 -6
  104. package/src/metadata/IMetadataObject.ts +29 -29
  105. package/src/metadata/IMetadataProperty.ts +11 -11
  106. package/src/metadata/IMetadataTag.ts +113 -113
  107. package/src/metadata/Metadata.ts +534 -534
  108. package/src/metadata/MetadataConstant.ts +3 -3
  109. package/src/metadata/MetadataObject.ts +131 -131
  110. package/src/metadata/MetadataProperty.ts +64 -64
  111. package/src/module.ts +1946 -1946
  112. package/src/programmers/ApplicationProgrammer.ts +55 -55
  113. package/src/programmers/AssertCloneProgrammer.ts +70 -70
  114. package/src/programmers/AssertParseProgrammer.ts +65 -65
  115. package/src/programmers/AssertProgrammer.ts +232 -232
  116. package/src/programmers/AssertPruneProgrammer.ts +67 -67
  117. package/src/programmers/AssertStringifyProgrammer.ts +71 -71
  118. package/src/programmers/CheckerProgrammer.ts +893 -893
  119. package/src/programmers/CloneProgrammer.ts +386 -386
  120. package/src/programmers/FeatureProgrammer.ts +505 -505
  121. package/src/programmers/IsCloneProgrammer.ts +80 -80
  122. package/src/programmers/IsParseProgrammer.ts +74 -74
  123. package/src/programmers/IsProgrammer.ts +200 -200
  124. package/src/programmers/IsPruneProgrammer.ts +75 -75
  125. package/src/programmers/IsStringifyProgrammer.ts +81 -81
  126. package/src/programmers/PruneProgrammer.ts +341 -341
  127. package/src/programmers/RandomProgrammer.ts +391 -391
  128. package/src/programmers/StringifyProgrammer.ts +795 -795
  129. package/src/programmers/ValidateCloneProgrammer.ts +90 -90
  130. package/src/programmers/ValidateParseProgrammer.ts +69 -69
  131. package/src/programmers/ValidateProgrammer.ts +266 -266
  132. package/src/programmers/ValidatePruneProgrammer.ts +83 -83
  133. package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
  134. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  135. package/src/programmers/helpers/CloneJoiner.ts +134 -134
  136. package/src/programmers/helpers/FunctionImporeter.ts +55 -55
  137. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  138. package/src/programmers/helpers/OptionPredicator.ts +19 -19
  139. package/src/programmers/helpers/PruneJoiner.ts +52 -52
  140. package/src/programmers/helpers/RandomJoiner.ts +149 -149
  141. package/src/programmers/helpers/RandomRanger.ts +216 -216
  142. package/src/programmers/helpers/StringifyJoinder.ts +114 -114
  143. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  144. package/src/programmers/helpers/UnionExplorer.ts +274 -274
  145. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  146. package/src/programmers/internal/application_array.ts +37 -37
  147. package/src/programmers/internal/application_boolean.ts +17 -17
  148. package/src/programmers/internal/application_constant.ts +29 -29
  149. package/src/programmers/internal/application_default.ts +17 -17
  150. package/src/programmers/internal/application_default_string.ts +32 -32
  151. package/src/programmers/internal/application_native.ts +29 -29
  152. package/src/programmers/internal/application_number.ts +70 -70
  153. package/src/programmers/internal/application_object.ts +153 -153
  154. package/src/programmers/internal/application_schema.ts +184 -184
  155. package/src/programmers/internal/application_string.ts +41 -41
  156. package/src/programmers/internal/application_templates.ts +27 -27
  157. package/src/programmers/internal/application_tuple.ts +29 -29
  158. package/src/programmers/internal/check_array.ts +22 -22
  159. package/src/programmers/internal/check_array_length.ts +44 -44
  160. package/src/programmers/internal/check_bigint.ts +64 -64
  161. package/src/programmers/internal/check_dynamic_properties.ts +197 -197
  162. package/src/programmers/internal/check_everything.ts +28 -28
  163. package/src/programmers/internal/check_native.ts +21 -21
  164. package/src/programmers/internal/check_number.ts +145 -145
  165. package/src/programmers/internal/check_object.ts +48 -48
  166. package/src/programmers/internal/check_string.ts +24 -24
  167. package/src/programmers/internal/check_string_tags.ts +63 -63
  168. package/src/programmers/internal/check_template.ts +50 -50
  169. package/src/programmers/internal/check_union_array_like.ts +260 -260
  170. package/src/programmers/internal/check_union_tuple.ts +33 -33
  171. package/src/programmers/internal/decode_union_object.ts +73 -73
  172. package/src/programmers/internal/feature_object_entries.ts +59 -59
  173. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  174. package/src/programmers/internal/prune_object_properties.ts +60 -60
  175. package/src/programmers/internal/stringify_dynamic_properties.ts +165 -165
  176. package/src/programmers/internal/stringify_native.ts +8 -8
  177. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  178. package/src/programmers/internal/template_to_pattern.ts +15 -15
  179. package/src/schemas/IJsonApplication.ts +9 -9
  180. package/src/schemas/IJsonComponents.ts +26 -26
  181. package/src/schemas/IJsonSchema.ts +127 -127
  182. package/src/transform.ts +21 -21
  183. package/src/transformers/CallExpressionTransformer.ts +172 -172
  184. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  185. package/src/transformers/FileTransformer.ts +49 -49
  186. package/src/transformers/IProject.ts +11 -11
  187. package/src/transformers/ITransformOptions.ts +62 -62
  188. package/src/transformers/ImportTransformer.ts +60 -60
  189. package/src/transformers/NodeTransformer.ts +19 -19
  190. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +120 -120
  191. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  192. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  193. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  194. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  195. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  196. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  197. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  198. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  199. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  200. package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +42 -43
  201. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  202. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  203. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  204. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  205. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  206. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  207. package/src/transformers/features/miscellaneous/RandomTransformer.ts +48 -49
  208. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  209. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  210. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  211. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  212. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  213. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  214. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  215. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  216. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  217. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
  218. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  219. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  220. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
  221. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  222. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  223. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  224. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  225. package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
  226. package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
  227. package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
  228. package/src/transformers/features/validators/IsTransformer.ts +10 -10
  229. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  230. package/src/transformers/internal/GenericTransformer.ts +99 -98
  231. package/src/typings/Atomic.ts +17 -17
  232. package/src/typings/ClassProperties.ts +5 -5
  233. package/src/typings/OmitNever.ts +3 -3
  234. package/src/typings/SpecialFields.ts +3 -3
  235. package/src/typings/Writable.ts +11 -11
  236. package/src/utils/ArrayUtil.ts +49 -49
  237. package/src/utils/Escaper.ts +50 -50
  238. package/src/utils/MapUtil.ts +14 -14
  239. package/src/utils/PatternUtil.ts +30 -30
  240. package/src/utils/RandomGenerator.ts +90 -90
  241. package/src/utils/Singleton.ts +17 -17
@@ -1,56 +1,56 @@
1
- import ts from "typescript";
2
-
3
- export namespace TemplateFactory {
4
- export function generate(expressions: ts.Expression[]): ts.Expression {
5
- if (expressions.every((exp) => ts.isStringLiteral(exp)))
6
- return ts.factory.createStringLiteral(
7
- (expressions as ts.StringLiteral[])
8
- .map((str) => str.text)
9
- .join(""),
10
- );
11
-
12
- const it: IIerator = {
13
- value: "",
14
- index: 0,
15
- };
16
- gather(expressions, it);
17
-
18
- const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
19
- const spans: ts.TemplateSpan[] = [];
20
-
21
- while (true) {
22
- const elem: ts.Expression = expressions[it.index++]!;
23
- gather(expressions, it);
24
-
25
- const broken: boolean = it.index === expressions.length;
26
- spans.push(
27
- ts.factory.createTemplateSpan(
28
- elem,
29
- broken
30
- ? ts.factory.createTemplateTail(it.value)
31
- : ts.factory.createTemplateMiddle(it.value),
32
- ),
33
- );
34
- if (broken === true) break;
35
- }
36
- return ts.factory.createTemplateExpression(head, spans);
37
- }
38
-
39
- function gather(expressions: ts.Expression[], it: IIerator): void {
40
- const found: number = expressions.findIndex(
41
- (elem, index) => index >= it.index && !ts.isStringLiteral(elem),
42
- );
43
-
44
- const last: number = found !== -1 ? found : expressions.length;
45
- it.value = expressions
46
- .slice(it.index, last)
47
- .map((elem) => (elem as ts.StringLiteral).text)
48
- .reduce((x, y) => x + y, "");
49
- it.index = last;
50
- }
51
-
52
- interface IIerator {
53
- value: string;
54
- index: number;
55
- }
56
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace TemplateFactory {
4
+ export function generate(expressions: ts.Expression[]): ts.Expression {
5
+ if (expressions.every((exp) => ts.isStringLiteral(exp)))
6
+ return ts.factory.createStringLiteral(
7
+ (expressions as ts.StringLiteral[])
8
+ .map((str) => str.text)
9
+ .join(""),
10
+ );
11
+
12
+ const it: IIerator = {
13
+ value: "",
14
+ index: 0,
15
+ };
16
+ gather(expressions, it);
17
+
18
+ const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
19
+ const spans: ts.TemplateSpan[] = [];
20
+
21
+ while (true) {
22
+ const elem: ts.Expression = expressions[it.index++]!;
23
+ gather(expressions, it);
24
+
25
+ const broken: boolean = it.index === expressions.length;
26
+ spans.push(
27
+ ts.factory.createTemplateSpan(
28
+ elem,
29
+ broken
30
+ ? ts.factory.createTemplateTail(it.value)
31
+ : ts.factory.createTemplateMiddle(it.value),
32
+ ),
33
+ );
34
+ if (broken === true) break;
35
+ }
36
+ return ts.factory.createTemplateExpression(head, spans);
37
+ }
38
+
39
+ function gather(expressions: ts.Expression[], it: IIerator): void {
40
+ const found: number = expressions.findIndex(
41
+ (elem, index) => index >= it.index && !ts.isStringLiteral(elem),
42
+ );
43
+
44
+ const last: number = found !== -1 ? found : expressions.length;
45
+ it.value = expressions
46
+ .slice(it.index, last)
47
+ .map((elem) => (elem as ts.StringLiteral).text)
48
+ .reduce((x, y) => x + y, "");
49
+ it.index = last;
50
+ }
51
+
52
+ interface IIerator {
53
+ value: string;
54
+ index: number;
55
+ }
56
+ }
@@ -1,129 +1,129 @@
1
- import ts from "typescript";
2
-
3
- export namespace TypeFactory {
4
- export function resolve(
5
- checker: ts.TypeChecker,
6
- type: ts.Type,
7
- ): ts.Type | null {
8
- return getReturnType(checker, type, "toJSON");
9
- }
10
-
11
- export function isFunction(type: ts.Type): boolean {
12
- return getFunction(type) !== null;
13
- }
14
-
15
- function getFunction(type: ts.Type) {
16
- const node = type.symbol?.declarations?.[0];
17
- if (node === undefined) return null;
18
-
19
- return ts.isFunctionLike(node)
20
- ? node
21
- : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
22
- ? ts.isFunctionLike(node.initializer)
23
- ? node.initializer
24
- : null
25
- : null;
26
- }
27
-
28
- export function getReturnType(
29
- checker: ts.TypeChecker,
30
- type: ts.Type,
31
- name: string,
32
- ): ts.Type | null {
33
- // FIND TO-JSON METHOD
34
- const symbol: ts.Symbol | undefined = type.getProperty(name);
35
- if (!symbol) return null;
36
- else if (!symbol.valueDeclaration) return null;
37
-
38
- // GET FUNCTION DECLARATION
39
- const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
40
- symbol,
41
- symbol.valueDeclaration,
42
- );
43
-
44
- // RETURNS THE RETURN-TYPE
45
- const signature: ts.Signature | undefined = checker.getSignaturesOfType(
46
- functor,
47
- ts.SignatureKind.Call,
48
- )[0];
49
- return signature ? signature.getReturnType() : null;
50
- }
51
-
52
- export function getFullName(
53
- checker: ts.TypeChecker,
54
- type: ts.Type,
55
- symbol?: ts.Symbol,
56
- ): string {
57
- // PRIMITIVE
58
- symbol ??= type.aliasSymbol ?? type.getSymbol();
59
- if (symbol === undefined) return checker.typeToString(type);
60
-
61
- // UNION OR INTERSECT
62
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
63
- const joiner: string = type.isIntersection() ? " & " : " | ";
64
- return type.types
65
- .map((child) => getFullName(checker, child))
66
- .join(joiner);
67
- }
68
-
69
- //----
70
- // SPECIALIZATION
71
- //----
72
- const name: string = get_name(symbol);
73
-
74
- // CHECK GENERIC
75
- const generic: readonly ts.Type[] = type.aliasSymbol
76
- ? type.aliasTypeArguments || []
77
- : checker.getTypeArguments(type as ts.TypeReference);
78
- return generic.length
79
- ? name === "Promise"
80
- ? getFullName(checker, generic[0]!)
81
- : `${name}<${generic
82
- .map((child) => getFullName(checker, child))
83
- .join(", ")}>`
84
- : name;
85
- }
86
-
87
- function explore_name(name: string, decl: ts.Node): string {
88
- return ts.isModuleBlock(decl)
89
- ? explore_name(
90
- `${decl.parent.name.getText()}.${name}`,
91
- decl.parent.parent,
92
- )
93
- : name;
94
- }
95
-
96
- function get_name(symbol: ts.Symbol): string {
97
- const parent = symbol.getDeclarations()?.[0]?.parent;
98
- return parent
99
- ? explore_name(symbol.escapedName.toString(), parent)
100
- : "__type";
101
- }
102
-
103
- export const keyword = (
104
- type:
105
- | "void"
106
- | "any"
107
- | "unknown"
108
- | "boolean"
109
- | "number"
110
- | "bigint"
111
- | "string",
112
- ) => {
113
- return ts.factory.createKeywordTypeNode(
114
- type === "void"
115
- ? ts.SyntaxKind.VoidKeyword
116
- : type === "any"
117
- ? ts.SyntaxKind.AnyKeyword
118
- : type === "unknown"
119
- ? ts.SyntaxKind.UnknownKeyword
120
- : type === "boolean"
121
- ? ts.SyntaxKind.BooleanKeyword
122
- : type === "number"
123
- ? ts.SyntaxKind.NumberKeyword
124
- : type === "bigint"
125
- ? ts.SyntaxKind.BigIntKeyword
126
- : ts.SyntaxKind.StringKeyword,
127
- );
128
- };
129
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace TypeFactory {
4
+ export function resolve(
5
+ checker: ts.TypeChecker,
6
+ type: ts.Type,
7
+ ): ts.Type | null {
8
+ return getReturnType(checker, type, "toJSON");
9
+ }
10
+
11
+ export function isFunction(type: ts.Type): boolean {
12
+ return getFunction(type) !== null;
13
+ }
14
+
15
+ function getFunction(type: ts.Type) {
16
+ const node = type.symbol?.declarations?.[0];
17
+ if (node === undefined) return null;
18
+
19
+ return ts.isFunctionLike(node)
20
+ ? node
21
+ : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
22
+ ? ts.isFunctionLike(node.initializer)
23
+ ? node.initializer
24
+ : null
25
+ : null;
26
+ }
27
+
28
+ export function getReturnType(
29
+ checker: ts.TypeChecker,
30
+ type: ts.Type,
31
+ name: string,
32
+ ): ts.Type | null {
33
+ // FIND TO-JSON METHOD
34
+ const symbol: ts.Symbol | undefined = type.getProperty(name);
35
+ if (!symbol) return null;
36
+ else if (!symbol.valueDeclaration) return null;
37
+
38
+ // GET FUNCTION DECLARATION
39
+ const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
40
+ symbol,
41
+ symbol.valueDeclaration,
42
+ );
43
+
44
+ // RETURNS THE RETURN-TYPE
45
+ const signature: ts.Signature | undefined = checker.getSignaturesOfType(
46
+ functor,
47
+ ts.SignatureKind.Call,
48
+ )[0];
49
+ return signature ? signature.getReturnType() : null;
50
+ }
51
+
52
+ export function getFullName(
53
+ checker: ts.TypeChecker,
54
+ type: ts.Type,
55
+ symbol?: ts.Symbol,
56
+ ): string {
57
+ // PRIMITIVE
58
+ symbol ??= type.aliasSymbol ?? type.getSymbol();
59
+ if (symbol === undefined) return checker.typeToString(type);
60
+
61
+ // UNION OR INTERSECT
62
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
63
+ const joiner: string = type.isIntersection() ? " & " : " | ";
64
+ return type.types
65
+ .map((child) => getFullName(checker, child))
66
+ .join(joiner);
67
+ }
68
+
69
+ //----
70
+ // SPECIALIZATION
71
+ //----
72
+ const name: string = get_name(symbol);
73
+
74
+ // CHECK GENERIC
75
+ const generic: readonly ts.Type[] = type.aliasSymbol
76
+ ? type.aliasTypeArguments || []
77
+ : checker.getTypeArguments(type as ts.TypeReference);
78
+ return generic.length
79
+ ? name === "Promise"
80
+ ? getFullName(checker, generic[0]!)
81
+ : `${name}<${generic
82
+ .map((child) => getFullName(checker, child))
83
+ .join(", ")}>`
84
+ : name;
85
+ }
86
+
87
+ function explore_name(name: string, decl: ts.Node): string {
88
+ return ts.isModuleBlock(decl)
89
+ ? explore_name(
90
+ `${decl.parent.name.getText()}.${name}`,
91
+ decl.parent.parent,
92
+ )
93
+ : name;
94
+ }
95
+
96
+ function get_name(symbol: ts.Symbol): string {
97
+ const parent = symbol.getDeclarations()?.[0]?.parent;
98
+ return parent
99
+ ? explore_name(symbol.escapedName.toString(), parent)
100
+ : "__type";
101
+ }
102
+
103
+ export const keyword = (
104
+ type:
105
+ | "void"
106
+ | "any"
107
+ | "unknown"
108
+ | "boolean"
109
+ | "number"
110
+ | "bigint"
111
+ | "string",
112
+ ) => {
113
+ return ts.factory.createKeywordTypeNode(
114
+ type === "void"
115
+ ? ts.SyntaxKind.VoidKeyword
116
+ : type === "any"
117
+ ? ts.SyntaxKind.AnyKeyword
118
+ : type === "unknown"
119
+ ? ts.SyntaxKind.UnknownKeyword
120
+ : type === "boolean"
121
+ ? ts.SyntaxKind.BooleanKeyword
122
+ : type === "number"
123
+ ? ts.SyntaxKind.NumberKeyword
124
+ : type === "bigint"
125
+ ? ts.SyntaxKind.BigIntKeyword
126
+ : ts.SyntaxKind.StringKeyword,
127
+ );
128
+ };
129
+ }
@@ -1,117 +1,117 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import ts from "typescript";
4
-
5
- import { ImportTransformer } from "../transformers/ImportTransformer";
6
-
7
- import transform from "../transform";
8
-
9
- export namespace TypiaFileFactory {
10
- export interface IProps {
11
- input: string;
12
- output: string;
13
- project: string;
14
- }
15
-
16
- export async function generate(
17
- props: TypiaFileFactory.IProps,
18
- ): Promise<void> {
19
- props.input = path.resolve(props.input);
20
- props.output = path.resolve(props.output);
21
-
22
- if ((await is_directory(props.input)) === false)
23
- throw new Error(
24
- "Error on TypiaGenerator.generate(): input path is not a directory.",
25
- );
26
- else if (fs.existsSync(props.output) === false)
27
- await fs.promises.mkdir(props.output, { recursive: true });
28
- else if ((await is_directory(props.output)) === false) {
29
- const parent: string = path.join(props.output, "..");
30
- if ((await is_directory(parent)) === false)
31
- throw new Error(
32
- "Error on TypiaGenerator.generate(): output path is not a directory.",
33
- );
34
- await fs.promises.mkdir(props.output);
35
- }
36
-
37
- // CREATE PROGRAM
38
- const { config } = ts.readConfigFile(props.project, ts.sys.readFile);
39
-
40
- const program: ts.Program = ts.createProgram(
41
- await (async () => {
42
- const container: string[] = [];
43
- await gather(container)(props.input)(props.output);
44
- return container;
45
- })(),
46
- config.compilerOptions,
47
- );
48
-
49
- // DO TRANSFORM
50
- const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
51
- program
52
- .getSourceFiles()
53
- .filter(
54
- (file) =>
55
- !file.isDeclarationFile &&
56
- path.resolve(file.fileName).indexOf(props.input) !== -1,
57
- ),
58
- [
59
- ImportTransformer.transform(props.input)(props.output),
60
- transform(
61
- program,
62
- (config.compilerOptions.plugins ?? []).find(
63
- (p: any) =>
64
- p.transform === "typia/lib/transform" ||
65
- p.transform === "../src/transform.ts",
66
- ) ?? {},
67
- ),
68
- ],
69
- program.getCompilerOptions(),
70
- );
71
-
72
- // ARCHIVE TRANSFORMED FILES
73
- const printer: ts.Printer = ts.createPrinter({
74
- newLine: ts.NewLineKind.LineFeed,
75
- });
76
- for (const file of result.transformed) {
77
- const to: string = path
78
- .resolve(file.fileName)
79
- .replace(props.input, props.output);
80
-
81
- const content: string = printer.printFile(file);
82
- await fs.promises.writeFile(to, emend(content), "utf8");
83
- }
84
- }
85
-
86
- const emend = (content: string): string => {
87
- if (
88
- content.indexOf("typia.") === -1 ||
89
- content.indexOf("import typia") !== -1 ||
90
- content.indexOf("import * as typia") !== -1
91
- )
92
- return content;
93
- return `import typia from "typia";\n\n${content}`;
94
- };
95
-
96
- const is_directory = async (current: string): Promise<boolean> => {
97
- const stat: fs.Stats = await fs.promises.stat(current);
98
- return stat.isDirectory();
99
- };
100
-
101
- const gather =
102
- (container: string[]) => (from: string) => async (to: string) => {
103
- if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
104
- const directory: string[] = await fs.promises.readdir(from);
105
- for (const file of directory) {
106
- const next: string = path.join(from, file);
107
- const stat: fs.Stats = await fs.promises.stat(next);
108
-
109
- if (stat.isDirectory()) {
110
- await gather(container)(next)(path.join(to, file));
111
- continue;
112
- } else if (file.substring(file.length - 3) === ".ts")
113
- container.push(next);
114
- }
115
- return container;
116
- };
117
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import ts from "typescript";
4
+
5
+ import { ImportTransformer } from "../transformers/ImportTransformer";
6
+
7
+ import transform from "../transform";
8
+
9
+ export namespace TypiaFileFactory {
10
+ export interface IProps {
11
+ input: string;
12
+ output: string;
13
+ project: string;
14
+ }
15
+
16
+ export async function generate(
17
+ props: TypiaFileFactory.IProps,
18
+ ): Promise<void> {
19
+ props.input = path.resolve(props.input);
20
+ props.output = path.resolve(props.output);
21
+
22
+ if ((await is_directory(props.input)) === false)
23
+ throw new Error(
24
+ "Error on TypiaGenerator.generate(): input path is not a directory.",
25
+ );
26
+ else if (fs.existsSync(props.output) === false)
27
+ await fs.promises.mkdir(props.output, { recursive: true });
28
+ else if ((await is_directory(props.output)) === false) {
29
+ const parent: string = path.join(props.output, "..");
30
+ if ((await is_directory(parent)) === false)
31
+ throw new Error(
32
+ "Error on TypiaGenerator.generate(): output path is not a directory.",
33
+ );
34
+ await fs.promises.mkdir(props.output);
35
+ }
36
+
37
+ // CREATE PROGRAM
38
+ const { config } = ts.readConfigFile(props.project, ts.sys.readFile);
39
+
40
+ const program: ts.Program = ts.createProgram(
41
+ await (async () => {
42
+ const container: string[] = [];
43
+ await gather(container)(props.input)(props.output);
44
+ return container;
45
+ })(),
46
+ config.compilerOptions,
47
+ );
48
+
49
+ // DO TRANSFORM
50
+ const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
51
+ program
52
+ .getSourceFiles()
53
+ .filter(
54
+ (file) =>
55
+ !file.isDeclarationFile &&
56
+ path.resolve(file.fileName).indexOf(props.input) !== -1,
57
+ ),
58
+ [
59
+ ImportTransformer.transform(props.input)(props.output),
60
+ transform(
61
+ program,
62
+ (config.compilerOptions.plugins ?? []).find(
63
+ (p: any) =>
64
+ p.transform === "typia/lib/transform" ||
65
+ p.transform === "../src/transform.ts",
66
+ ) ?? {},
67
+ ),
68
+ ],
69
+ program.getCompilerOptions(),
70
+ );
71
+
72
+ // ARCHIVE TRANSFORMED FILES
73
+ const printer: ts.Printer = ts.createPrinter({
74
+ newLine: ts.NewLineKind.LineFeed,
75
+ });
76
+ for (const file of result.transformed) {
77
+ const to: string = path
78
+ .resolve(file.fileName)
79
+ .replace(props.input, props.output);
80
+
81
+ const content: string = printer.printFile(file);
82
+ await fs.promises.writeFile(to, emend(content), "utf8");
83
+ }
84
+ }
85
+
86
+ const emend = (content: string): string => {
87
+ if (
88
+ content.indexOf("typia.") === -1 ||
89
+ content.indexOf("import typia") !== -1 ||
90
+ content.indexOf("import * as typia") !== -1
91
+ )
92
+ return content;
93
+ return `import typia from "typia";\n\n${content}`;
94
+ };
95
+
96
+ const is_directory = async (current: string): Promise<boolean> => {
97
+ const stat: fs.Stats = await fs.promises.stat(current);
98
+ return stat.isDirectory();
99
+ };
100
+
101
+ const gather =
102
+ (container: string[]) => (from: string) => async (to: string) => {
103
+ if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
104
+ const directory: string[] = await fs.promises.readdir(from);
105
+ for (const file of directory) {
106
+ const next: string = path.join(from, file);
107
+ const stat: fs.Stats = await fs.promises.stat(next);
108
+
109
+ if (stat.isDirectory()) {
110
+ await gather(container)(next)(path.join(to, file));
111
+ continue;
112
+ } else if (file.substring(file.length - 3) === ".ts")
113
+ container.push(next);
114
+ }
115
+ return container;
116
+ };
117
+ }
@@ -1,12 +1,12 @@
1
- import ts from "typescript";
2
-
3
- export namespace ValueFactory {
4
- export const NULL = () => ts.factory.createNull();
5
- export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
6
- export const BOOLEAN = (value: boolean) =>
7
- value ? ts.factory.createTrue() : ts.factory.createFalse();
8
- export const INPUT = (str: string = "input") =>
9
- ts.factory.createIdentifier(str);
10
- export const TYPEOF = (input: ts.Expression) =>
11
- ts.factory.createTypeOfExpression(input);
12
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace ValueFactory {
4
+ export const NULL = () => ts.factory.createNull();
5
+ export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
6
+ export const BOOLEAN = (value: boolean) =>
7
+ value ? ts.factory.createTrue() : ts.factory.createFalse();
8
+ export const INPUT = (str: string = "input") =>
9
+ ts.factory.createIdentifier(str);
10
+ export const TYPEOF = (input: ts.Expression) =>
11
+ ts.factory.createTypeOfExpression(input);
12
+ }
@@ -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
+ }