typia 4.0.0-dev.20230520 → 4.0.0-dev.20230527

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 (220) hide show
  1. package/lib/transform.js +1 -1
  2. package/lib/transform.js.map +1 -1
  3. package/package.json +1 -1
  4. package/src/CustomValidatorMap.ts +126 -126
  5. package/src/IRandomGenerator.ts +33 -33
  6. package/src/IValidation.ts +21 -21
  7. package/src/Primitive.ts +123 -123
  8. package/src/TypeGuardError.ts +36 -36
  9. package/src/executable/TypiaGenerateWizard.ts +85 -85
  10. package/src/executable/TypiaSetupWizard.ts +133 -133
  11. package/src/executable/setup/ArgumentParser.ts +45 -45
  12. package/src/executable/setup/CommandExecutor.ts +8 -8
  13. package/src/executable/setup/FileRetriever.ts +22 -22
  14. package/src/executable/setup/PackageManager.ts +71 -71
  15. package/src/executable/setup/PluginConfigurator.ts +70 -70
  16. package/src/executable/typia.ts +52 -52
  17. package/src/factories/CommentFactory.ts +14 -14
  18. package/src/factories/ExpressionFactory.ts +77 -77
  19. package/src/factories/IdentifierFactory.ts +62 -62
  20. package/src/factories/LiteralFactory.ts +57 -57
  21. package/src/factories/MetadataCollection.ts +123 -123
  22. package/src/factories/MetadataFactory.ts +53 -53
  23. package/src/factories/MetadataTagFactory.ts +295 -295
  24. package/src/factories/StatementFactory.ts +20 -20
  25. package/src/factories/TemplateFactory.ts +64 -64
  26. package/src/factories/TypeFactory.ts +145 -145
  27. package/src/factories/ValueFactory.ts +15 -15
  28. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  29. package/src/factories/internal/metadata/emplace_metadata_object.ts +152 -152
  30. package/src/factories/internal/metadata/explore_metadata.ts +93 -93
  31. package/src/factories/internal/metadata/iterate_metadata.ts +63 -63
  32. package/src/factories/internal/metadata/iterate_metadata_array.ts +32 -32
  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 +62 -62
  36. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  37. package/src/factories/internal/metadata/iterate_metadata_native.ts +217 -217
  38. package/src/factories/internal/metadata/iterate_metadata_object.ts +51 -51
  39. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +30 -30
  40. package/src/factories/internal/metadata/iterate_metadata_set.ts +36 -36
  41. package/src/factories/internal/metadata/iterate_metadata_template.ts +40 -40
  42. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +51 -51
  43. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  44. package/src/functional/$any.ts +2 -2
  45. package/src/functional/$dictionary.ts +25 -25
  46. package/src/functional/$every.ts +11 -11
  47. package/src/functional/$guard.ts +35 -35
  48. package/src/functional/$is_between.ts +2 -2
  49. package/src/functional/$is_custom.ts +14 -14
  50. package/src/functional/$is_date.ts +3 -3
  51. package/src/functional/$is_datetime.ts +2 -2
  52. package/src/functional/$is_email.ts +4 -4
  53. package/src/functional/$is_ipv4.ts +4 -4
  54. package/src/functional/$is_ipv6.ts +4 -4
  55. package/src/functional/$is_url.ts +4 -4
  56. package/src/functional/$is_uuid.ts +4 -4
  57. package/src/functional/$join.ts +46 -46
  58. package/src/functional/$number.ts +12 -12
  59. package/src/functional/$report.ts +15 -15
  60. package/src/functional/$rest.ts +3 -3
  61. package/src/functional/$string.ts +37 -37
  62. package/src/functional/$tail.ts +5 -5
  63. package/src/functional/Namespace.ts +127 -127
  64. package/src/index.ts +4 -4
  65. package/src/metadata/ICommentTag.ts +4 -4
  66. package/src/metadata/IJsDocTagInfo.ts +10 -10
  67. package/src/metadata/IMetadata.ts +26 -26
  68. package/src/metadata/IMetadataApplication.ts +7 -7
  69. package/src/metadata/IMetadataConstant.ts +16 -16
  70. package/src/metadata/IMetadataEntry.ts +6 -6
  71. package/src/metadata/IMetadataObject.ts +29 -29
  72. package/src/metadata/IMetadataProperty.ts +11 -11
  73. package/src/metadata/IMetadataTag.ts +105 -105
  74. package/src/metadata/Metadata.ts +539 -539
  75. package/src/metadata/MetadataConstant.ts +3 -3
  76. package/src/metadata/MetadataObject.ts +127 -127
  77. package/src/metadata/MetadataProperty.ts +64 -64
  78. package/src/module.ts +2038 -2038
  79. package/src/programmers/ApplicationProgrammer.ts +48 -48
  80. package/src/programmers/AssertCloneProgrammer.ts +68 -68
  81. package/src/programmers/AssertParseProgrammer.ts +66 -66
  82. package/src/programmers/AssertProgrammer.ts +274 -274
  83. package/src/programmers/AssertPruneProgrammer.ts +73 -73
  84. package/src/programmers/AssertStringifyProgrammer.ts +66 -66
  85. package/src/programmers/CheckerProgrammer.ts +897 -897
  86. package/src/programmers/CloneProgrammer.ts +387 -387
  87. package/src/programmers/FeatureProgrammer.ts +510 -510
  88. package/src/programmers/IsCloneProgrammer.ts +79 -79
  89. package/src/programmers/IsParseProgrammer.ts +72 -72
  90. package/src/programmers/IsProgrammer.ts +223 -223
  91. package/src/programmers/IsPruneProgrammer.ts +83 -83
  92. package/src/programmers/IsStringifyProgrammer.ts +77 -77
  93. package/src/programmers/LiteralsProgrammer.ts +65 -65
  94. package/src/programmers/PruneProgrammer.ts +348 -348
  95. package/src/programmers/RandomProgrammer.ts +444 -444
  96. package/src/programmers/StringifyProgrammer.ts +758 -758
  97. package/src/programmers/TypiaProgrammer.ts +141 -141
  98. package/src/programmers/ValidateCloneProgrammer.ts +93 -93
  99. package/src/programmers/ValidateParseProgrammer.ts +78 -78
  100. package/src/programmers/ValidateProgrammer.ts +317 -317
  101. package/src/programmers/ValidatePruneProgrammer.ts +86 -86
  102. package/src/programmers/ValidateStringifyProgrammer.ts +93 -93
  103. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  104. package/src/programmers/helpers/CloneJoiner.ts +138 -138
  105. package/src/programmers/helpers/FunctionImporeter.ts +56 -56
  106. package/src/programmers/helpers/ICheckEntry.ts +12 -12
  107. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  108. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  109. package/src/programmers/helpers/PruneJoiner.ts +156 -156
  110. package/src/programmers/helpers/RandomJoiner.ts +165 -165
  111. package/src/programmers/helpers/RandomRanger.ts +218 -218
  112. package/src/programmers/helpers/StringifyJoinder.ts +118 -118
  113. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  114. package/src/programmers/helpers/UnionExplorer.ts +281 -281
  115. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  116. package/src/programmers/helpers/disable_function_importer_declare.ts +21 -21
  117. package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
  118. package/src/programmers/internal/application_array.ts +32 -32
  119. package/src/programmers/internal/application_boolean.ts +15 -15
  120. package/src/programmers/internal/application_constant.ts +26 -26
  121. package/src/programmers/internal/application_default.ts +17 -17
  122. package/src/programmers/internal/application_default_string.ts +33 -33
  123. package/src/programmers/internal/application_native.ts +36 -36
  124. package/src/programmers/internal/application_number.ts +71 -71
  125. package/src/programmers/internal/application_object.ts +162 -162
  126. package/src/programmers/internal/application_schema.ts +198 -198
  127. package/src/programmers/internal/application_string.ts +44 -44
  128. package/src/programmers/internal/application_templates.ts +25 -25
  129. package/src/programmers/internal/application_tuple.ts +27 -27
  130. package/src/programmers/internal/check_array.ts +31 -31
  131. package/src/programmers/internal/check_array_length.ts +35 -35
  132. package/src/programmers/internal/check_bigint.ts +95 -95
  133. package/src/programmers/internal/check_custom.ts +32 -32
  134. package/src/programmers/internal/check_dynamic_properties.ts +198 -198
  135. package/src/programmers/internal/check_everything.ts +28 -28
  136. package/src/programmers/internal/check_native.ts +22 -22
  137. package/src/programmers/internal/check_number.ts +177 -177
  138. package/src/programmers/internal/check_object.ts +65 -65
  139. package/src/programmers/internal/check_string.ts +27 -27
  140. package/src/programmers/internal/check_string_tags.ts +68 -68
  141. package/src/programmers/internal/check_template.ts +57 -57
  142. package/src/programmers/internal/check_union_array_like.ts +273 -273
  143. package/src/programmers/internal/check_union_tuple.ts +34 -34
  144. package/src/programmers/internal/decode_union_object.ts +75 -75
  145. package/src/programmers/internal/feature_object_entries.ts +64 -64
  146. package/src/programmers/internal/get_comment_tags.ts +23 -23
  147. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  148. package/src/programmers/internal/prune_object_properties.ts +63 -63
  149. package/src/programmers/internal/random_custom.ts +30 -30
  150. package/src/programmers/internal/stringify_dynamic_properties.ts +173 -173
  151. package/src/programmers/internal/stringify_native.ts +7 -7
  152. package/src/programmers/internal/stringify_regular_properties.ts +89 -89
  153. package/src/programmers/internal/template_to_pattern.ts +15 -15
  154. package/src/schemas/IJsonApplication.ts +13 -13
  155. package/src/schemas/IJsonComponents.ts +33 -33
  156. package/src/schemas/IJsonSchema.ts +134 -134
  157. package/src/transform.ts +39 -39
  158. package/src/transformers/CallExpressionTransformer.ts +183 -183
  159. package/src/transformers/FileTransformer.ts +50 -50
  160. package/src/transformers/IProject.ts +18 -18
  161. package/src/transformers/ITransformOptions.ts +62 -62
  162. package/src/transformers/ImportTransformer.ts +74 -74
  163. package/src/transformers/NodeTransformer.ts +13 -13
  164. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +107 -107
  165. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  166. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  167. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  168. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  169. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  170. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  171. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  172. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  173. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  174. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +43 -43
  175. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  176. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  177. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  178. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  179. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +31 -31
  180. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +56 -56
  181. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  182. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  183. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  184. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  185. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  186. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  187. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  188. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  189. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  190. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  191. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  192. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
  193. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  194. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  195. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
  196. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  197. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  198. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  199. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  200. package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
  201. package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
  202. package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
  203. package/src/transformers/features/validators/IsTransformer.ts +11 -11
  204. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  205. package/src/transformers/internal/GenericTransformer.ts +101 -101
  206. package/src/typings/Atomic.ts +17 -17
  207. package/src/typings/ClassProperties.ts +5 -5
  208. package/src/typings/Customizable.ts +5 -5
  209. package/src/typings/OmitNever.ts +3 -3
  210. package/src/typings/SpecialFields.ts +3 -3
  211. package/src/typings/Writable.ts +11 -11
  212. package/src/utils/ArrayUtil.ts +44 -44
  213. package/src/utils/Escaper.ts +45 -45
  214. package/src/utils/MapUtil.ts +12 -12
  215. package/src/utils/PatternUtil.ts +30 -30
  216. package/src/utils/RandomGenerator.ts +81 -81
  217. package/src/utils/Singleton.ts +17 -17
  218. package/src/utils/TsNodeUtil.ts +17 -17
  219. package/src/utils/TsSymbolUtil.ts +153 -153
  220. package/src/utils/TsTypeUtil.ts +38 -38
@@ -1,183 +1,183 @@
1
- import path from "path";
2
- import type ts from "typescript/lib/tsclibrary";
3
-
4
- import { TsNodeUtil } from "../utils/TsNodeUtil";
5
-
6
- import { IProject } from "./IProject";
7
- import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
8
- import { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
9
- import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
10
- import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
11
- import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
12
- import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
13
- import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
14
- import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
15
- import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
16
- import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
17
- import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
18
- import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
19
- import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
20
- import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
21
- import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
22
- import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
23
- import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
24
- import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
25
- import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
26
- import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
27
- import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
28
- import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
29
- import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
30
- import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
31
- import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
32
- import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
33
- import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
34
- import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
35
- import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
36
- import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
37
- import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
38
- import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
39
- import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
40
- import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
41
- import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
42
- import { AssertTransformer } from "./features/validators/AssertTransformer";
43
- import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
44
- import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
45
- import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
46
- import { IsTransformer } from "./features/validators/IsTransformer";
47
- import { ValidateTransformer } from "./features/validators/ValidateTransformer";
48
-
49
- export namespace CallExpressionTransformer {
50
- export const transform =
51
- (project: IProject) =>
52
- (expression: ts.CallExpression): ts.Expression => {
53
- //----
54
- // VALIDATIONS
55
- //----
56
- // SIGNATURE DECLARATION
57
- const declaration: ts.Declaration | undefined =
58
- project.checker.getResolvedSignature(expression)?.declaration;
59
- if (!declaration) return expression;
60
-
61
- // FILE PATH
62
- const file: string = path.resolve(
63
- TsNodeUtil.getSourceFile(project.tsc)(declaration).fileName,
64
- );
65
-
66
- if (
67
- file.indexOf(LIB_PATH) === -1 &&
68
- file !== SRC_PATH &&
69
- file !== CLI_PATH
70
- )
71
- return expression;
72
-
73
- //----
74
- // TRANSFORMATION
75
- //----
76
- // FUNCTION NAME
77
- const { escapedName } =
78
- project.checker.getTypeAtLocation(declaration).symbol;
79
-
80
- // FIND TRANSFORMER
81
- const functor: (() => Task) | undefined =
82
- FUNCTORS[escapedName.toString()];
83
- if (functor === undefined) return expression;
84
-
85
- // RETURNS WITH TRANSFORMATION
86
- return functor()(project)(expression.expression)(expression);
87
- };
88
- }
89
-
90
- type Task = (
91
- project: IProject,
92
- ) => (
93
- modulo: ts.LeftHandSideExpression,
94
- ) => (expression: ts.CallExpression) => ts.Expression;
95
-
96
- const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
97
- const SRC_PATH = path.resolve(
98
- path.join(__dirname, "..", "..", "src", "module.ts"),
99
- );
100
- const CLI_PATH = path.resolve(
101
- path.join(__dirname, "..", "..", "..", "src", "module.ts"),
102
- );
103
-
104
- const FUNCTORS: Record<string, () => Task> = {
105
- //----
106
- // SINGLE FUNCTIONS
107
- //----
108
- // BASIC VALIDATORS
109
- assert: () => AssertTransformer.transform(false),
110
- assertType: () => AssertTransformer.transform(false),
111
- is: () => IsTransformer.transform(false),
112
- validate: () => ValidateTransformer.transform(false),
113
-
114
- // STRICT VALIDATORS
115
- assertEquals: () => AssertTransformer.transform(true),
116
- equals: () => IsTransformer.transform(true),
117
- validateEquals: () => ValidateTransformer.transform(true),
118
-
119
- // PARSE FUNCTIONS
120
- isParse: () => IsParseTransformer.transform,
121
- assertParse: () => AssertParseTransformer.transform,
122
- validateParse: () => ValidateParseTransformer.transform,
123
-
124
- // STRINGIFY FUNCTIONS
125
- application: () => (project) => () =>
126
- ApplicationTransformer.transform(project),
127
- stringify: () => StringifyTransformer.transform,
128
- assertStringify: () => AssertStringifyTransformer.transform,
129
- isStringify: () => IsStringifyTransformer.transform,
130
- validateStringify: () => ValidateStringifyTransformer.transform,
131
-
132
- // MISC
133
- metadata: () => (project) => () => MetadataTransformer.transform(project),
134
- random: () => RandomTransformer.transform,
135
- literals: () => (project) => () => LiteralsTransformer.transform(project),
136
-
137
- clone: () => CloneTransformer.transform,
138
- assertClone: () => AssertCloneTransformer.transform,
139
- isClone: () => IsCloneTransformer.transform,
140
- validateClone: () => ValidateCloneTransformer.transform,
141
-
142
- prune: () => PruneTransformer.transform,
143
- assertPrune: () => AssertPruneTransformer.transform,
144
- isPrune: () => IsPruneTransformer.transform,
145
- validatePrune: () => ValidatePruneTransformer.transform,
146
-
147
- //----
148
- // FACTORY FUNCTIONS
149
- //----
150
- // BASIC VALIDATORS
151
- createAssert: () => CreateAssertTransformer.transform(false),
152
- createAssertType: () => CreateAssertTransformer.transform(false),
153
- createIs: () => CreateIsTransformer.transform(false),
154
- createValidate: () => CreateValidateTransformer.transform(false),
155
-
156
- // STRICT VALIDATORS
157
- createAssertEquals: () => CreateAssertTransformer.transform(true),
158
- createEquals: () => CreateIsTransformer.transform(true),
159
- createValidateEquals: () => CreateValidateTransformer.transform(true),
160
-
161
- // PARSE FUNCTIONS
162
- createIsParse: () => CreateIsParseTransformer.transform,
163
- createAssertParse: () => CreateAssertParseTransformer.transform,
164
- createValidateParse: () => CreateValidateParseTransformer.transform,
165
-
166
- // STRINGIFY FUNCTIONS
167
- createStringify: () => CreateStringifyTransformer.transform,
168
- createAssertStringify: () => CreateAssertStringifyTransformer.transform,
169
- createIsStringify: () => CreateIsStringifyTransformer.transform,
170
- createValidateStringify: () => CreateValidateStringifyTransformer.transform,
171
-
172
- // MISC
173
- createRandom: () => CreateRandomTransformer.transform,
174
- createClone: () => CreateCloneTransformer.transform,
175
- createAssertClone: () => CreateAssertCloneTransformer.transform,
176
- createIsClone: () => CreateIsCloneTransformer.transform,
177
- createValidateClone: () => CreateValidateCloneTransformer.transform,
178
-
179
- createPrune: () => CreatePruneTransformer.transform,
180
- createAssertPrune: () => CreateAssertPruneTransformer.transform,
181
- createIsPrune: () => CreateIsPruneTransformer.transform,
182
- createValidatePrune: () => CreateValidatePruneTransformer.transform,
183
- };
1
+ import path from "path";
2
+ import type ts from "typescript/lib/tsclibrary";
3
+
4
+ import { TsNodeUtil } from "../utils/TsNodeUtil";
5
+
6
+ import { IProject } from "./IProject";
7
+ import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
8
+ import { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
9
+ import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
10
+ import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
11
+ import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
12
+ import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
13
+ import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
14
+ import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
15
+ import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
16
+ import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
17
+ import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
18
+ import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
19
+ import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
20
+ import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
21
+ import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
22
+ import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
23
+ import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
24
+ import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
25
+ import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
26
+ import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
27
+ import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
28
+ import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
29
+ import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
30
+ import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
31
+ import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
32
+ import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
33
+ import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
34
+ import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
35
+ import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
36
+ import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
37
+ import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
38
+ import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
39
+ import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
40
+ import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
41
+ import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
42
+ import { AssertTransformer } from "./features/validators/AssertTransformer";
43
+ import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
44
+ import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
45
+ import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
46
+ import { IsTransformer } from "./features/validators/IsTransformer";
47
+ import { ValidateTransformer } from "./features/validators/ValidateTransformer";
48
+
49
+ export namespace CallExpressionTransformer {
50
+ export const transform =
51
+ (project: IProject) =>
52
+ (expression: ts.CallExpression): ts.Expression => {
53
+ //----
54
+ // VALIDATIONS
55
+ //----
56
+ // SIGNATURE DECLARATION
57
+ const declaration: ts.Declaration | undefined =
58
+ project.checker.getResolvedSignature(expression)?.declaration;
59
+ if (!declaration) return expression;
60
+
61
+ // FILE PATH
62
+ const file: string = path.resolve(
63
+ TsNodeUtil.getSourceFile(project.tsc)(declaration).fileName,
64
+ );
65
+
66
+ if (
67
+ file.indexOf(LIB_PATH) === -1 &&
68
+ file !== SRC_PATH &&
69
+ file !== CLI_PATH
70
+ )
71
+ return expression;
72
+
73
+ //----
74
+ // TRANSFORMATION
75
+ //----
76
+ // FUNCTION NAME
77
+ const { escapedName } =
78
+ project.checker.getTypeAtLocation(declaration).symbol;
79
+
80
+ // FIND TRANSFORMER
81
+ const functor: (() => Task) | undefined =
82
+ FUNCTORS[escapedName.toString()];
83
+ if (functor === undefined) return expression;
84
+
85
+ // RETURNS WITH TRANSFORMATION
86
+ return functor()(project)(expression.expression)(expression);
87
+ };
88
+ }
89
+
90
+ type Task = (
91
+ project: IProject,
92
+ ) => (
93
+ modulo: ts.LeftHandSideExpression,
94
+ ) => (expression: ts.CallExpression) => ts.Expression;
95
+
96
+ const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
97
+ const SRC_PATH = path.resolve(
98
+ path.join(__dirname, "..", "..", "src", "module.ts"),
99
+ );
100
+ const CLI_PATH = path.resolve(
101
+ path.join(__dirname, "..", "..", "..", "src", "module.ts"),
102
+ );
103
+
104
+ const FUNCTORS: Record<string, () => Task> = {
105
+ //----
106
+ // SINGLE FUNCTIONS
107
+ //----
108
+ // BASIC VALIDATORS
109
+ assert: () => AssertTransformer.transform(false),
110
+ assertType: () => AssertTransformer.transform(false),
111
+ is: () => IsTransformer.transform(false),
112
+ validate: () => ValidateTransformer.transform(false),
113
+
114
+ // STRICT VALIDATORS
115
+ assertEquals: () => AssertTransformer.transform(true),
116
+ equals: () => IsTransformer.transform(true),
117
+ validateEquals: () => ValidateTransformer.transform(true),
118
+
119
+ // PARSE FUNCTIONS
120
+ isParse: () => IsParseTransformer.transform,
121
+ assertParse: () => AssertParseTransformer.transform,
122
+ validateParse: () => ValidateParseTransformer.transform,
123
+
124
+ // STRINGIFY FUNCTIONS
125
+ application: () => (project) => () =>
126
+ ApplicationTransformer.transform(project),
127
+ stringify: () => StringifyTransformer.transform,
128
+ assertStringify: () => AssertStringifyTransformer.transform,
129
+ isStringify: () => IsStringifyTransformer.transform,
130
+ validateStringify: () => ValidateStringifyTransformer.transform,
131
+
132
+ // MISC
133
+ metadata: () => (project) => () => MetadataTransformer.transform(project),
134
+ random: () => RandomTransformer.transform,
135
+ literals: () => (project) => () => LiteralsTransformer.transform(project),
136
+
137
+ clone: () => CloneTransformer.transform,
138
+ assertClone: () => AssertCloneTransformer.transform,
139
+ isClone: () => IsCloneTransformer.transform,
140
+ validateClone: () => ValidateCloneTransformer.transform,
141
+
142
+ prune: () => PruneTransformer.transform,
143
+ assertPrune: () => AssertPruneTransformer.transform,
144
+ isPrune: () => IsPruneTransformer.transform,
145
+ validatePrune: () => ValidatePruneTransformer.transform,
146
+
147
+ //----
148
+ // FACTORY FUNCTIONS
149
+ //----
150
+ // BASIC VALIDATORS
151
+ createAssert: () => CreateAssertTransformer.transform(false),
152
+ createAssertType: () => CreateAssertTransformer.transform(false),
153
+ createIs: () => CreateIsTransformer.transform(false),
154
+ createValidate: () => CreateValidateTransformer.transform(false),
155
+
156
+ // STRICT VALIDATORS
157
+ createAssertEquals: () => CreateAssertTransformer.transform(true),
158
+ createEquals: () => CreateIsTransformer.transform(true),
159
+ createValidateEquals: () => CreateValidateTransformer.transform(true),
160
+
161
+ // PARSE FUNCTIONS
162
+ createIsParse: () => CreateIsParseTransformer.transform,
163
+ createAssertParse: () => CreateAssertParseTransformer.transform,
164
+ createValidateParse: () => CreateValidateParseTransformer.transform,
165
+
166
+ // STRINGIFY FUNCTIONS
167
+ createStringify: () => CreateStringifyTransformer.transform,
168
+ createAssertStringify: () => CreateAssertStringifyTransformer.transform,
169
+ createIsStringify: () => CreateIsStringifyTransformer.transform,
170
+ createValidateStringify: () => CreateValidateStringifyTransformer.transform,
171
+
172
+ // MISC
173
+ createRandom: () => CreateRandomTransformer.transform,
174
+ createClone: () => CreateCloneTransformer.transform,
175
+ createAssertClone: () => CreateAssertCloneTransformer.transform,
176
+ createIsClone: () => CreateIsCloneTransformer.transform,
177
+ createValidateClone: () => CreateValidateCloneTransformer.transform,
178
+
179
+ createPrune: () => CreatePruneTransformer.transform,
180
+ createAssertPrune: () => CreateAssertPruneTransformer.transform,
181
+ createIsPrune: () => CreateIsPruneTransformer.transform,
182
+ createValidatePrune: () => CreateValidatePruneTransformer.transform,
183
+ };
@@ -1,50 +1,50 @@
1
- import type ts from "typescript/lib/tsclibrary";
2
-
3
- import { TsNodeUtil } from "../utils/TsNodeUtil";
4
-
5
- import { IProject } from "./IProject";
6
- import { NodeTransformer } from "./NodeTransformer";
7
-
8
- export namespace FileTransformer {
9
- export const transform =
10
- (project: IProject) =>
11
- (context: ts.TransformationContext) =>
12
- (file: ts.SourceFile): ts.SourceFile =>
13
- file.isDeclarationFile
14
- ? file
15
- : project.tsc.visitEachChild(
16
- file,
17
- (node) => iterate_node(project)(context)(node),
18
- context,
19
- );
20
-
21
- const iterate_node =
22
- (project: IProject) =>
23
- (context: ts.TransformationContext) =>
24
- (node: ts.Node): ts.Node =>
25
- project.tsc.visitEachChild(
26
- try_transform_node(project)(node),
27
- (child) => iterate_node(project)(context)(child),
28
- context,
29
- );
30
-
31
- const try_transform_node =
32
- (project: IProject) =>
33
- (node: ts.Node): ts.Node => {
34
- try {
35
- return NodeTransformer.transform(project)(node);
36
- } catch (exp) {
37
- if (!(exp instanceof Error)) throw exp;
38
-
39
- const file: ts.SourceFile = TsNodeUtil.getSourceFile(
40
- project.tsc,
41
- )(node);
42
- const { line, character } =
43
- project.tsc.getLineAndCharacterOfPosition(file, node.pos);
44
- exp.message += ` - ${file.fileName}:${line + 1}:${
45
- character + 1
46
- }`;
47
- throw exp;
48
- }
49
- };
50
- }
1
+ import type ts from "typescript/lib/tsclibrary";
2
+
3
+ import { TsNodeUtil } from "../utils/TsNodeUtil";
4
+
5
+ import { IProject } from "./IProject";
6
+ import { NodeTransformer } from "./NodeTransformer";
7
+
8
+ export namespace FileTransformer {
9
+ export const transform =
10
+ (project: IProject) =>
11
+ (context: ts.TransformationContext) =>
12
+ (file: ts.SourceFile): ts.SourceFile =>
13
+ file.isDeclarationFile
14
+ ? file
15
+ : project.tsc.visitEachChild(
16
+ file,
17
+ (node) => iterate_node(project)(context)(node),
18
+ context,
19
+ );
20
+
21
+ const iterate_node =
22
+ (project: IProject) =>
23
+ (context: ts.TransformationContext) =>
24
+ (node: ts.Node): ts.Node =>
25
+ project.tsc.visitEachChild(
26
+ try_transform_node(project)(node),
27
+ (child) => iterate_node(project)(context)(child),
28
+ context,
29
+ );
30
+
31
+ const try_transform_node =
32
+ (project: IProject) =>
33
+ (node: ts.Node): ts.Node => {
34
+ try {
35
+ return NodeTransformer.transform(project)(node);
36
+ } catch (exp) {
37
+ if (!(exp instanceof Error)) throw exp;
38
+
39
+ const file: ts.SourceFile = TsNodeUtil.getSourceFile(
40
+ project.tsc,
41
+ )(node);
42
+ const { line, character } =
43
+ project.tsc.getLineAndCharacterOfPosition(file, node.pos);
44
+ exp.message += ` - ${file.fileName}:${line + 1}:${
45
+ character + 1
46
+ }`;
47
+ throw exp;
48
+ }
49
+ };
50
+ }
@@ -1,18 +1,18 @@
1
- import type ts from "typescript/lib/tsclibrary";
2
-
3
- import { ITransformOptions } from "./ITransformOptions";
4
-
5
- export interface IProject {
6
- tsc: typeof ts;
7
- program: ts.Program;
8
- compilerOptions: ts.CompilerOptions;
9
- checker: ts.TypeChecker;
10
- printer: ts.Printer;
11
- options: ITransformOptions;
12
- }
13
- export namespace IProject {
14
- export interface IModule {
15
- tsc: typeof ts;
16
- checker: ts.TypeChecker;
17
- }
18
- }
1
+ import type ts from "typescript/lib/tsclibrary";
2
+
3
+ import { ITransformOptions } from "./ITransformOptions";
4
+
5
+ export interface IProject {
6
+ tsc: typeof ts;
7
+ program: ts.Program;
8
+ compilerOptions: ts.CompilerOptions;
9
+ checker: ts.TypeChecker;
10
+ printer: ts.Printer;
11
+ options: ITransformOptions;
12
+ }
13
+ export namespace IProject {
14
+ export interface IModule {
15
+ tsc: typeof ts;
16
+ checker: ts.TypeChecker;
17
+ }
18
+ }
@@ -1,62 +1,62 @@
1
- export interface ITransformOptions {
2
- /**
3
- * Whether to validate finite number or not.
4
- *
5
- * If configured true, number typed values would be validated by Number.isNaN().
6
- *
7
- * However, whatever you configure, it would be ignored when marshaling or parsing.
8
- *
9
- * - when marshaling, always be true
10
- * - assertStringify()
11
- * - validateEncode()
12
- * - when parsing, always be false
13
- * - assertParse()
14
- * - isDecode()
15
- *
16
- * @default false
17
- */
18
- finite?: boolean;
19
-
20
- /**
21
- * Whether to validate finite number or not.
22
- *
23
- * If configured true, number typed values would be validated by Number.isFinite().
24
- *
25
- * However, whatever you configure, it can be ignored in below case.
26
- *
27
- * - when `finite` option is true, this option would be ignored
28
- * - when marshaling, always be true
29
- * - assertStringify()
30
- * - validateEncode()
31
- * - when parsing, always be false
32
- * - assertParse()
33
- * - isDecode()
34
- *
35
- * @default false
36
- */
37
- numeric?: boolean;
38
-
39
- /**
40
- * Whether to validate functional type or not.
41
- *
42
- * However, whatever you configure, it becomes false when marshaling or parsing.
43
- *
44
- * @default false
45
- */
46
- functional?: boolean;
47
-
48
- /**
49
- * Whether to check undefined value or not.
50
- *
51
- * JavaScript can assign `undefined` value to a specific property and it is an
52
- * issue when validating without allowing superfluous properties. Should undefined
53
- * value assigned superfluous property be allowed or not?
54
- *
55
- * Note that, this option only works on {@link equals} function. Other function
56
- * like {@link assertEquals} or {@link validateEquals} would ignore this option
57
- * value and always allow the `undefined` value.
58
- *
59
- * @default true
60
- */
61
- undefined?: boolean;
62
- }
1
+ export interface ITransformOptions {
2
+ /**
3
+ * Whether to validate finite number or not.
4
+ *
5
+ * If configured true, number typed values would be validated by Number.isNaN().
6
+ *
7
+ * However, whatever you configure, it would be ignored when marshaling or parsing.
8
+ *
9
+ * - when marshaling, always be true
10
+ * - assertStringify()
11
+ * - validateEncode()
12
+ * - when parsing, always be false
13
+ * - assertParse()
14
+ * - isDecode()
15
+ *
16
+ * @default false
17
+ */
18
+ finite?: boolean;
19
+
20
+ /**
21
+ * Whether to validate finite number or not.
22
+ *
23
+ * If configured true, number typed values would be validated by Number.isFinite().
24
+ *
25
+ * However, whatever you configure, it can be ignored in below case.
26
+ *
27
+ * - when `finite` option is true, this option would be ignored
28
+ * - when marshaling, always be true
29
+ * - assertStringify()
30
+ * - validateEncode()
31
+ * - when parsing, always be false
32
+ * - assertParse()
33
+ * - isDecode()
34
+ *
35
+ * @default false
36
+ */
37
+ numeric?: boolean;
38
+
39
+ /**
40
+ * Whether to validate functional type or not.
41
+ *
42
+ * However, whatever you configure, it becomes false when marshaling or parsing.
43
+ *
44
+ * @default false
45
+ */
46
+ functional?: boolean;
47
+
48
+ /**
49
+ * Whether to check undefined value or not.
50
+ *
51
+ * JavaScript can assign `undefined` value to a specific property and it is an
52
+ * issue when validating without allowing superfluous properties. Should undefined
53
+ * value assigned superfluous property be allowed or not?
54
+ *
55
+ * Note that, this option only works on {@link equals} function. Other function
56
+ * like {@link assertEquals} or {@link validateEquals} would ignore this option
57
+ * value and always allow the `undefined` value.
58
+ *
59
+ * @default true
60
+ */
61
+ undefined?: boolean;
62
+ }