typia 3.6.5 → 3.6.6

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 (203) hide show
  1. package/lib/module.d.ts +1 -1
  2. package/lib/programmers/internal/application_number.js +1 -1
  3. package/package.json +1 -1
  4. package/src/IRandomGenerator.ts +16 -16
  5. package/src/IValidation.ts +21 -21
  6. package/src/Primitive.ts +104 -104
  7. package/src/TypeGuardError.ts +36 -36
  8. package/src/executable/TypiaGenerateWizard.ts +87 -87
  9. package/src/executable/TypiaSetupWizard.ts +142 -142
  10. package/src/executable/setup/ArgumentParser.ts +91 -91
  11. package/src/executable/setup/CommandExecutor.ts +8 -8
  12. package/src/executable/setup/FileRetriever.ts +33 -33
  13. package/src/executable/setup/PackageManager.ts +92 -92
  14. package/src/executable/setup/PluginConfigurator.ts +99 -99
  15. package/src/executable/typia.ts +38 -38
  16. package/src/factories/CommentFactory.ts +10 -10
  17. package/src/factories/ExpressionFactory.ts +77 -77
  18. package/src/factories/IdentifierFactory.ts +73 -73
  19. package/src/factories/LiteralFactory.ts +44 -44
  20. package/src/factories/MetadataCollection.ts +122 -122
  21. package/src/factories/MetadataFactory.ts +51 -51
  22. package/src/factories/MetadataTagFactory.ts +265 -265
  23. package/src/factories/StatementFactory.ts +60 -60
  24. package/src/factories/TemplateFactory.ts +56 -56
  25. package/src/factories/TypeFactory.ts +129 -129
  26. package/src/factories/TypiaFileFactory.ts +117 -117
  27. package/src/factories/ValueFactory.ts +12 -12
  28. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  29. package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
  30. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  31. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  32. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  33. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  34. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  35. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  36. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  37. package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
  38. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  39. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  40. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  41. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  42. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  43. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  44. package/src/functional/$any.ts +3 -3
  45. package/src/functional/$every.ts +11 -11
  46. package/src/functional/$guard.ts +35 -35
  47. package/src/functional/$is_between.ts +7 -7
  48. package/src/functional/$is_email.ts +5 -5
  49. package/src/functional/$is_ipv4.ts +5 -5
  50. package/src/functional/$is_ipv6.ts +5 -5
  51. package/src/functional/$is_url.ts +5 -5
  52. package/src/functional/$is_uuid.ts +5 -5
  53. package/src/functional/$join.ts +50 -50
  54. package/src/functional/$number.ts +12 -12
  55. package/src/functional/$report.ts +15 -15
  56. package/src/functional/$rest.ts +3 -3
  57. package/src/functional/$string.ts +37 -37
  58. package/src/functional/$tail.ts +6 -6
  59. package/src/functional/Namespace.ts +121 -121
  60. package/src/index.ts +4 -4
  61. package/src/metadata/IJsDocTagInfo.ts +10 -10
  62. package/src/metadata/IMetadata.ts +25 -25
  63. package/src/metadata/IMetadataApplication.ts +7 -7
  64. package/src/metadata/IMetadataConstant.ts +16 -16
  65. package/src/metadata/IMetadataEntry.ts +6 -6
  66. package/src/metadata/IMetadataObject.ts +29 -29
  67. package/src/metadata/IMetadataProperty.ts +11 -11
  68. package/src/metadata/IMetadataTag.ts +113 -113
  69. package/src/metadata/Metadata.ts +534 -534
  70. package/src/metadata/MetadataConstant.ts +3 -3
  71. package/src/metadata/MetadataObject.ts +131 -131
  72. package/src/metadata/MetadataProperty.ts +64 -64
  73. package/src/module.ts +1946 -1946
  74. package/src/programmers/ApplicationProgrammer.ts +55 -55
  75. package/src/programmers/AssertCloneProgrammer.ts +70 -70
  76. package/src/programmers/AssertParseProgrammer.ts +65 -65
  77. package/src/programmers/AssertProgrammer.ts +232 -232
  78. package/src/programmers/AssertPruneProgrammer.ts +67 -67
  79. package/src/programmers/AssertStringifyProgrammer.ts +71 -71
  80. package/src/programmers/CheckerProgrammer.ts +893 -893
  81. package/src/programmers/CloneProgrammer.ts +386 -386
  82. package/src/programmers/FeatureProgrammer.ts +505 -505
  83. package/src/programmers/IsCloneProgrammer.ts +80 -80
  84. package/src/programmers/IsParseProgrammer.ts +74 -74
  85. package/src/programmers/IsProgrammer.ts +200 -200
  86. package/src/programmers/IsPruneProgrammer.ts +75 -75
  87. package/src/programmers/IsStringifyProgrammer.ts +81 -81
  88. package/src/programmers/PruneProgrammer.ts +341 -341
  89. package/src/programmers/RandomProgrammer.ts +391 -391
  90. package/src/programmers/StringifyProgrammer.ts +795 -795
  91. package/src/programmers/ValidateCloneProgrammer.ts +90 -90
  92. package/src/programmers/ValidateParseProgrammer.ts +69 -69
  93. package/src/programmers/ValidateProgrammer.ts +266 -266
  94. package/src/programmers/ValidatePruneProgrammer.ts +83 -83
  95. package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
  96. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  97. package/src/programmers/helpers/CloneJoiner.ts +134 -134
  98. package/src/programmers/helpers/FunctionImporeter.ts +55 -55
  99. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  100. package/src/programmers/helpers/OptionPredicator.ts +19 -19
  101. package/src/programmers/helpers/PruneJoiner.ts +52 -52
  102. package/src/programmers/helpers/RandomJoiner.ts +149 -149
  103. package/src/programmers/helpers/RandomRanger.ts +216 -216
  104. package/src/programmers/helpers/StringifyJoinder.ts +114 -114
  105. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  106. package/src/programmers/helpers/UnionExplorer.ts +274 -274
  107. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  108. package/src/programmers/internal/application_array.ts +37 -37
  109. package/src/programmers/internal/application_boolean.ts +17 -17
  110. package/src/programmers/internal/application_constant.ts +29 -29
  111. package/src/programmers/internal/application_default.ts +17 -17
  112. package/src/programmers/internal/application_default_string.ts +32 -32
  113. package/src/programmers/internal/application_native.ts +29 -29
  114. package/src/programmers/internal/application_number.ts +70 -70
  115. package/src/programmers/internal/application_object.ts +153 -153
  116. package/src/programmers/internal/application_schema.ts +184 -184
  117. package/src/programmers/internal/application_string.ts +41 -41
  118. package/src/programmers/internal/application_templates.ts +27 -27
  119. package/src/programmers/internal/application_tuple.ts +29 -29
  120. package/src/programmers/internal/check_array.ts +22 -22
  121. package/src/programmers/internal/check_array_length.ts +44 -44
  122. package/src/programmers/internal/check_bigint.ts +64 -64
  123. package/src/programmers/internal/check_dynamic_properties.ts +197 -197
  124. package/src/programmers/internal/check_everything.ts +28 -28
  125. package/src/programmers/internal/check_native.ts +21 -21
  126. package/src/programmers/internal/check_number.ts +145 -145
  127. package/src/programmers/internal/check_object.ts +48 -48
  128. package/src/programmers/internal/check_string.ts +24 -24
  129. package/src/programmers/internal/check_string_tags.ts +63 -63
  130. package/src/programmers/internal/check_template.ts +50 -50
  131. package/src/programmers/internal/check_union_array_like.ts +260 -260
  132. package/src/programmers/internal/check_union_tuple.ts +33 -33
  133. package/src/programmers/internal/decode_union_object.ts +73 -73
  134. package/src/programmers/internal/feature_object_entries.ts +59 -59
  135. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  136. package/src/programmers/internal/prune_object_properties.ts +60 -60
  137. package/src/programmers/internal/stringify_dynamic_properties.ts +165 -165
  138. package/src/programmers/internal/stringify_native.ts +8 -8
  139. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  140. package/src/programmers/internal/template_to_pattern.ts +15 -15
  141. package/src/schemas/IJsonApplication.ts +9 -9
  142. package/src/schemas/IJsonComponents.ts +26 -26
  143. package/src/schemas/IJsonSchema.ts +127 -127
  144. package/src/transform.ts +21 -21
  145. package/src/transformers/CallExpressionTransformer.ts +172 -172
  146. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  147. package/src/transformers/FileTransformer.ts +49 -49
  148. package/src/transformers/IProject.ts +11 -11
  149. package/src/transformers/ITransformOptions.ts +62 -62
  150. package/src/transformers/ImportTransformer.ts +60 -60
  151. package/src/transformers/NodeTransformer.ts +19 -19
  152. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +120 -120
  153. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  154. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  155. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  156. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  157. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  158. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  159. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  160. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  161. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  162. package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +42 -42
  163. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  164. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  165. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  166. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  167. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  168. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  169. package/src/transformers/features/miscellaneous/RandomTransformer.ts +48 -48
  170. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  171. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  172. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  173. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  174. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  175. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  176. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  177. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  178. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  179. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
  180. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  181. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  182. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
  183. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  184. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  185. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  186. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  187. package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
  188. package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
  189. package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
  190. package/src/transformers/features/validators/IsTransformer.ts +10 -10
  191. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  192. package/src/transformers/internal/GenericTransformer.ts +99 -99
  193. package/src/typings/Atomic.ts +17 -17
  194. package/src/typings/ClassProperties.ts +5 -5
  195. package/src/typings/OmitNever.ts +3 -3
  196. package/src/typings/SpecialFields.ts +3 -3
  197. package/src/typings/Writable.ts +11 -11
  198. package/src/utils/ArrayUtil.ts +49 -49
  199. package/src/utils/Escaper.ts +50 -50
  200. package/src/utils/MapUtil.ts +14 -14
  201. package/src/utils/PatternUtil.ts +30 -30
  202. package/src/utils/RandomGenerator.ts +90 -90
  203. 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
+ }