typia 5.3.5 → 5.3.6-dev.20231229

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 (354) hide show
  1. package/README.md +2 -1
  2. package/lib/functional/$ProtobufReader.js +2 -2
  3. package/lib/functional/$ProtobufReader.js.map +1 -1
  4. package/package.json +1 -1
  5. package/src/AssertionGuard.ts +1 -1
  6. package/src/CamelCase.ts +114 -114
  7. package/src/IRandomGenerator.ts +35 -35
  8. package/src/IValidation.ts +21 -21
  9. package/src/PascalCase.ts +114 -114
  10. package/src/Primitive.ts +135 -135
  11. package/src/Resolved.ts +116 -116
  12. package/src/SnakeCase.ts +156 -156
  13. package/src/TypeGuardError.ts +36 -36
  14. package/src/executable/TypiaGenerateWizard.ts +83 -83
  15. package/src/executable/TypiaPatchWizard.ts +42 -42
  16. package/src/executable/TypiaSetupWizard.ts +151 -151
  17. package/src/executable/setup/ArgumentParser.ts +43 -43
  18. package/src/executable/setup/CommandExecutor.ts +8 -8
  19. package/src/executable/setup/FileRetriever.ts +22 -22
  20. package/src/executable/setup/PackageManager.ts +71 -71
  21. package/src/executable/setup/PluginConfigurator.ts +69 -69
  22. package/src/executable/typia.ts +55 -55
  23. package/src/factories/CommentFactory.ts +79 -79
  24. package/src/factories/ExpressionFactory.ts +150 -150
  25. package/src/factories/IdentifierFactory.ts +70 -70
  26. package/src/factories/JsonMetadataFactory.ts +53 -53
  27. package/src/factories/LiteralFactory.ts +47 -47
  28. package/src/factories/MetadataCollection.ts +269 -269
  29. package/src/factories/MetadataCommentTagFactory.ts +601 -601
  30. package/src/factories/MetadataFactory.ts +267 -267
  31. package/src/factories/MetadataTypeTagFactory.ts +313 -313
  32. package/src/factories/NumericRangeFactory.ts +72 -72
  33. package/src/factories/ProtobufFactory.ts +259 -259
  34. package/src/factories/StatementFactory.ts +72 -72
  35. package/src/factories/TemplateFactory.ts +56 -56
  36. package/src/factories/TypeFactory.ts +118 -118
  37. package/src/factories/ValueFactory.ts +12 -12
  38. package/src/factories/internal/metadata/MetadataHelper.ts +15 -15
  39. package/src/factories/internal/metadata/emend_metadata_atomics.ts +37 -37
  40. package/src/factories/internal/metadata/emplace_metadata_alias.ts +41 -41
  41. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +38 -38
  42. package/src/factories/internal/metadata/emplace_metadata_object.ts +175 -175
  43. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +57 -57
  44. package/src/factories/internal/metadata/explore_metadata.ts +28 -28
  45. package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
  46. package/src/factories/internal/metadata/iterate_metadata_alias.ts +34 -34
  47. package/src/factories/internal/metadata/iterate_metadata_array.ts +37 -37
  48. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  49. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  50. package/src/factories/internal/metadata/iterate_metadata_collection.ts +131 -131
  51. package/src/factories/internal/metadata/iterate_metadata_comment_tags.ts +26 -26
  52. package/src/factories/internal/metadata/iterate_metadata_constant.ts +48 -48
  53. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +230 -230
  54. package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
  55. package/src/factories/internal/metadata/iterate_metadata_native.ts +208 -208
  56. package/src/factories/internal/metadata/iterate_metadata_object.ts +43 -43
  57. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +52 -52
  58. package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
  59. package/src/factories/internal/metadata/iterate_metadata_sort.ts +61 -61
  60. package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
  61. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +37 -37
  62. package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
  63. package/src/functional/$HeadersReader.ts +28 -28
  64. package/src/functional/$ParameterReader.ts +31 -31
  65. package/src/functional/$ProtobufReader.ts +199 -195
  66. package/src/functional/$ProtobufSizer.ts +147 -147
  67. package/src/functional/$ProtobufWriter.ts +150 -150
  68. package/src/functional/$QueryReader.ts +56 -56
  69. package/src/functional/$any.ts +4 -4
  70. package/src/functional/$clone.ts +4 -4
  71. package/src/functional/$convention.ts +37 -37
  72. package/src/functional/$dictionary.ts +22 -22
  73. package/src/functional/$every.ts +11 -11
  74. package/src/functional/$from.ts +5 -5
  75. package/src/functional/$guard.ts +35 -35
  76. package/src/functional/$is_between.ts +2 -2
  77. package/src/functional/$join.ts +46 -46
  78. package/src/functional/$number.ts +12 -12
  79. package/src/functional/$report.ts +13 -13
  80. package/src/functional/$rest.ts +3 -3
  81. package/src/functional/$stoll.ts +8 -8
  82. package/src/functional/$string.ts +50 -50
  83. package/src/functional/$strlen.ts +7 -7
  84. package/src/functional/$tail.ts +5 -5
  85. package/src/functional/$varint.ts +130 -130
  86. package/src/functional/$zigzag.ts +39 -39
  87. package/src/functional/IProtobufWriter.ts +18 -18
  88. package/src/functional/Namespace.ts +174 -174
  89. package/src/http.ts +1149 -1149
  90. package/src/index.ts +4 -4
  91. package/src/json.ts +648 -648
  92. package/src/misc.ts +651 -651
  93. package/src/module.ts +897 -897
  94. package/src/notations.ts +855 -855
  95. package/src/programmers/AssertProgrammer.ts +293 -293
  96. package/src/programmers/CheckerProgrammer.ts +1025 -1025
  97. package/src/programmers/FeatureProgrammer.ts +460 -460
  98. package/src/programmers/IsProgrammer.ts +232 -232
  99. package/src/programmers/RandomProgrammer.ts +825 -825
  100. package/src/programmers/TypiaProgrammer.ts +167 -167
  101. package/src/programmers/ValidateProgrammer.ts +307 -307
  102. package/src/programmers/helpers/AtomicPredicator.ts +25 -25
  103. package/src/programmers/helpers/CloneJoiner.ts +130 -130
  104. package/src/programmers/helpers/FunctionImporeter.ts +87 -87
  105. package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
  106. package/src/programmers/helpers/ICheckEntry.ts +13 -13
  107. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  108. package/src/programmers/helpers/NotationJoiner.ts +132 -132
  109. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  110. package/src/programmers/helpers/ProtobufUtil.ts +125 -125
  111. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  112. package/src/programmers/helpers/PruneJoiner.ts +141 -141
  113. package/src/programmers/helpers/RandomJoiner.ts +140 -140
  114. package/src/programmers/helpers/RandomRanger.ts +171 -171
  115. package/src/programmers/helpers/StringifyJoinder.ts +105 -105
  116. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  117. package/src/programmers/helpers/UnionExplorer.ts +269 -269
  118. package/src/programmers/helpers/UnionPredicator.ts +77 -77
  119. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
  120. package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -77
  121. package/src/programmers/http/HttpAssertQueryProgrammer.ts +75 -75
  122. package/src/programmers/http/HttpHeadersProgrammer.ts +314 -314
  123. package/src/programmers/http/HttpIsHeadersProgrammer.ts +84 -84
  124. package/src/programmers/http/HttpIsQueryProgrammer.ts +82 -82
  125. package/src/programmers/http/HttpParameterProgrammer.ts +97 -97
  126. package/src/programmers/http/HttpQueryProgrammer.ts +252 -252
  127. package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -77
  128. package/src/programmers/http/HttpValidateQueryProgrammer.ts +75 -75
  129. package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
  130. package/src/programmers/internal/application_alias.ts +65 -65
  131. package/src/programmers/internal/application_array.ts +59 -59
  132. package/src/programmers/internal/application_boolean.ts +30 -30
  133. package/src/programmers/internal/application_constant.ts +26 -26
  134. package/src/programmers/internal/application_default.ts +17 -17
  135. package/src/programmers/internal/application_default_string.ts +33 -33
  136. package/src/programmers/internal/application_escaped.ts +53 -53
  137. package/src/programmers/internal/application_native.ts +38 -38
  138. package/src/programmers/internal/application_number.ts +94 -94
  139. package/src/programmers/internal/application_object.ts +153 -153
  140. package/src/programmers/internal/application_schema.ts +180 -180
  141. package/src/programmers/internal/application_string.ts +58 -58
  142. package/src/programmers/internal/application_templates.ts +25 -25
  143. package/src/programmers/internal/application_tuple.ts +55 -55
  144. package/src/programmers/internal/check_array_length.ts +45 -45
  145. package/src/programmers/internal/check_bigint.ts +49 -49
  146. package/src/programmers/internal/check_dynamic_key.ts +175 -175
  147. package/src/programmers/internal/check_dynamic_properties.ts +198 -198
  148. package/src/programmers/internal/check_everything.ts +23 -23
  149. package/src/programmers/internal/check_native.ts +21 -21
  150. package/src/programmers/internal/check_number.ts +106 -106
  151. package/src/programmers/internal/check_object.ts +60 -60
  152. package/src/programmers/internal/check_string.ts +48 -48
  153. package/src/programmers/internal/check_template.ts +61 -61
  154. package/src/programmers/internal/check_union_array_like.ts +307 -307
  155. package/src/programmers/internal/decode_union_object.ts +78 -78
  156. package/src/programmers/internal/feature_object_entries.ts +58 -58
  157. package/src/programmers/internal/metadata_to_pattern.ts +33 -33
  158. package/src/programmers/internal/prune_object_properties.ts +60 -60
  159. package/src/programmers/internal/random_custom.ts +37 -37
  160. package/src/programmers/internal/stringify_dynamic_properties.ts +157 -157
  161. package/src/programmers/internal/stringify_native.ts +7 -7
  162. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  163. package/src/programmers/internal/template_to_pattern.ts +15 -15
  164. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +20 -20
  165. package/src/programmers/json/JsonApplicationProgrammer.ts +50 -50
  166. package/src/programmers/json/JsonAssertParseProgrammer.ts +67 -67
  167. package/src/programmers/json/JsonAssertStringifyProgrammer.ts +61 -61
  168. package/src/programmers/json/JsonIsParseProgrammer.ts +73 -73
  169. package/src/programmers/json/JsonIsStringifyProgrammer.ts +75 -75
  170. package/src/programmers/json/JsonStringifyProgrammer.ts +893 -893
  171. package/src/programmers/json/JsonValidateParseProgrammer.ts +64 -64
  172. package/src/programmers/json/JsonValidateStringifyProgrammer.ts +83 -83
  173. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +63 -63
  174. package/src/programmers/misc/MiscAssertPruneProgrammer.ts +60 -60
  175. package/src/programmers/misc/MiscCloneProgrammer.ts +713 -713
  176. package/src/programmers/misc/MiscIsCloneProgrammer.ts +70 -70
  177. package/src/programmers/misc/MiscIsPruneProgrammer.ts +66 -66
  178. package/src/programmers/misc/MiscLiteralsProgrammer.ts +72 -72
  179. package/src/programmers/misc/MiscPruneProgrammer.ts +523 -523
  180. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +80 -80
  181. package/src/programmers/misc/MiscValidatePruneProgrammer.ts +73 -73
  182. package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +64 -64
  183. package/src/programmers/notations/NotationGeneralProgrammer.ts +647 -647
  184. package/src/programmers/notations/NotationIsGeneralProgrammer.ts +71 -71
  185. package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +81 -81
  186. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
  187. package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +61 -61
  188. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +607 -607
  189. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +819 -819
  190. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +82 -82
  191. package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +75 -75
  192. package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +160 -160
  193. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  194. package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +83 -83
  195. package/src/protobuf.ts +887 -887
  196. package/src/reflect.ts +24 -24
  197. package/src/schemas/json/IJsonApplication.ts +8 -8
  198. package/src/schemas/json/IJsonComponents.ts +36 -36
  199. package/src/schemas/json/IJsonSchema.ts +113 -113
  200. package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
  201. package/src/schemas/metadata/IMetadata.ts +34 -34
  202. package/src/schemas/metadata/IMetadataAlias.ts +12 -12
  203. package/src/schemas/metadata/IMetadataApplication.ts +7 -7
  204. package/src/schemas/metadata/IMetadataArray.ts +7 -7
  205. package/src/schemas/metadata/IMetadataArrayType.ts +10 -10
  206. package/src/schemas/metadata/IMetadataAtomic.ts +6 -6
  207. package/src/schemas/metadata/IMetadataComponents.ts +11 -11
  208. package/src/schemas/metadata/IMetadataConstant.ts +23 -23
  209. package/src/schemas/metadata/IMetadataDictionary.ts +11 -11
  210. package/src/schemas/metadata/IMetadataEntry.ts +6 -6
  211. package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
  212. package/src/schemas/metadata/IMetadataObject.ts +18 -18
  213. package/src/schemas/metadata/IMetadataProperty.ts +9 -9
  214. package/src/schemas/metadata/IMetadataTuple.ts +7 -7
  215. package/src/schemas/metadata/IMetadataTupleType.ts +10 -10
  216. package/src/schemas/metadata/IMetadataTypeTag.ts +15 -15
  217. package/src/schemas/metadata/Metadata.ts +612 -612
  218. package/src/schemas/metadata/MetadataAlias.ts +61 -61
  219. package/src/schemas/metadata/MetadataApplication.ts +44 -44
  220. package/src/schemas/metadata/MetadataArray.ts +49 -49
  221. package/src/schemas/metadata/MetadataArrayType.ts +57 -57
  222. package/src/schemas/metadata/MetadataAtomic.ts +84 -84
  223. package/src/schemas/metadata/MetadataComponents.ts +98 -98
  224. package/src/schemas/metadata/MetadataConstant.ts +46 -46
  225. package/src/schemas/metadata/MetadataEscaped.ts +51 -51
  226. package/src/schemas/metadata/MetadataObject.ts +135 -135
  227. package/src/schemas/metadata/MetadataProperty.ts +56 -56
  228. package/src/schemas/metadata/MetadataTuple.ts +32 -32
  229. package/src/schemas/metadata/MetadataTupleType.ts +67 -67
  230. package/src/tags/Default.ts +15 -15
  231. package/src/tags/ExclusiveMaximum.ts +13 -13
  232. package/src/tags/ExclusiveMinimum.ts +13 -13
  233. package/src/tags/Format.ts +30 -30
  234. package/src/tags/MaxItems.ts +9 -9
  235. package/src/tags/MaxLength.ts +9 -9
  236. package/src/tags/Maximum.ts +13 -13
  237. package/src/tags/MinItems.ts +9 -9
  238. package/src/tags/MinLength.ts +9 -9
  239. package/src/tags/Minimum.ts +13 -13
  240. package/src/tags/MultipleOf.ts +15 -15
  241. package/src/tags/Pattern.ts +9 -9
  242. package/src/tags/TagBase.ts +68 -68
  243. package/src/tags/Type.ts +27 -27
  244. package/src/tags/index.ts +14 -14
  245. package/src/transform.ts +35 -35
  246. package/src/transformers/CallExpressionTransformer.ts +351 -351
  247. package/src/transformers/FileTransformer.ts +91 -91
  248. package/src/transformers/IProject.ts +15 -15
  249. package/src/transformers/ITransformOptions.ts +62 -62
  250. package/src/transformers/ImportTransformer.ts +66 -66
  251. package/src/transformers/NodeTransformer.ts +13 -13
  252. package/src/transformers/TransformerError.ts +55 -55
  253. package/src/transformers/features/AssertTransformer.ts +16 -16
  254. package/src/transformers/features/CreateAssertTransformer.ts +16 -16
  255. package/src/transformers/features/CreateIsTransformer.ts +10 -10
  256. package/src/transformers/features/CreateRandomTransformer.ts +40 -40
  257. package/src/transformers/features/CreateValidateTransformer.ts +13 -13
  258. package/src/transformers/features/IsTransformer.ts +10 -10
  259. package/src/transformers/features/RandomTransformer.ts +44 -44
  260. package/src/transformers/features/ValidateTransformer.ts +11 -11
  261. package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +11 -11
  262. package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +9 -9
  263. package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -9
  264. package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -9
  265. package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -9
  266. package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -9
  267. package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -9
  268. package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +12 -12
  269. package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +11 -11
  270. package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +9 -9
  271. package/src/transformers/features/http/HttpAssertQueryTransformer.ts +9 -9
  272. package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -9
  273. package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -9
  274. package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -9
  275. package/src/transformers/features/http/HttpParameterTransformer.ts +9 -9
  276. package/src/transformers/features/http/HttpQueryTransformer.ts +9 -9
  277. package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -10
  278. package/src/transformers/features/http/HttpValidateQueryTransformer.ts +9 -9
  279. package/src/transformers/features/json/JsonApplicationTransformer.ts +121 -121
  280. package/src/transformers/features/json/JsonAssertParseTransformer.ts +9 -9
  281. package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
  282. package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +9 -9
  283. package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
  284. package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
  285. package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +9 -9
  286. package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
  287. package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +11 -11
  288. package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
  289. package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
  290. package/src/transformers/features/json/JsonIsStringifyTransformer.ts +9 -9
  291. package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
  292. package/src/transformers/features/json/JsonValidateParseTransformer.ts +9 -9
  293. package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
  294. package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +9 -9
  295. package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +9 -9
  296. package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
  297. package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +9 -9
  298. package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +9 -9
  299. package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
  300. package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
  301. package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
  302. package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
  303. package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +11 -11
  304. package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +11 -11
  305. package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
  306. package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
  307. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
  308. package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
  309. package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +9 -9
  310. package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +9 -9
  311. package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
  312. package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
  313. package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
  314. package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
  315. package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +15 -15
  316. package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
  317. package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
  318. package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +15 -15
  319. package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +10 -10
  320. package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +10 -10
  321. package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
  322. package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
  323. package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
  324. package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
  325. package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +9 -9
  326. package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +9 -9
  327. package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
  328. package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
  329. package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +9 -9
  330. package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +9 -9
  331. package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +9 -9
  332. package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +9 -9
  333. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
  334. package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +10 -10
  335. package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +10 -10
  336. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +73 -73
  337. package/src/transformers/internal/GenericTransformer.ts +96 -96
  338. package/src/typings/Atomic.ts +13 -13
  339. package/src/typings/ClassProperties.ts +5 -5
  340. package/src/typings/Customizable.ts +5 -5
  341. package/src/typings/OmitNever.ts +3 -3
  342. package/src/typings/ProtobufAtomic.ts +19 -19
  343. package/src/typings/SpecialFields.ts +3 -3
  344. package/src/typings/ValidationPipe.ts +9 -9
  345. package/src/typings/Writable.ts +11 -11
  346. package/src/utils/ArrayUtil.ts +43 -43
  347. package/src/utils/Escaper.ts +46 -46
  348. package/src/utils/MapUtil.ts +12 -12
  349. package/src/utils/NameEncoder.ts +32 -32
  350. package/src/utils/NamingConvention.ts +87 -87
  351. package/src/utils/PatternUtil.ts +29 -29
  352. package/src/utils/RandomGenerator.ts +83 -83
  353. package/src/utils/Singleton.ts +16 -16
  354. package/src/utils/StringUtil.ts +4 -4
@@ -1,460 +1,460 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { MetadataCollection } from "../factories/MetadataCollection";
5
- import { StatementFactory } from "../factories/StatementFactory";
6
- import { TypeFactory } from "../factories/TypeFactory";
7
- import { ValueFactory } from "../factories/ValueFactory";
8
-
9
- import { Metadata } from "../schemas/metadata/Metadata";
10
- import { MetadataArray } from "../schemas/metadata/MetadataArray";
11
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
12
-
13
- import { IProject } from "../transformers/IProject";
14
-
15
- import { CheckerProgrammer } from "./CheckerProgrammer";
16
- import { FunctionImporter } from "./helpers/FunctionImporeter";
17
- import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
- import { UnionExplorer } from "./helpers/UnionExplorer";
19
- import { feature_object_entries } from "./internal/feature_object_entries";
20
-
21
- export namespace FeatureProgrammer {
22
- /* -----------------------------------------------------------
23
- PARAMETERS
24
- ----------------------------------------------------------- */
25
- export interface IConfig<Output extends ts.ConciseBody = ts.ConciseBody> {
26
- types: IConfig.ITypes;
27
-
28
- /**
29
- * Prefix name of internal functions for specific types.
30
- */
31
- prefix: string;
32
-
33
- /**
34
- * Whether to archive access path or not.
35
- */
36
- path: boolean;
37
-
38
- /**
39
- * Whether to trace exception or not.
40
- */
41
- trace: boolean;
42
-
43
- addition?: undefined | ((collection: MetadataCollection) => ts.Statement[]);
44
-
45
- /**
46
- * Initializer of metadata.
47
- */
48
- initializer: (
49
- project: IProject,
50
- ) => (
51
- importer: FunctionImporter,
52
- ) => (type: ts.Type) => [MetadataCollection, Metadata];
53
-
54
- /**
55
- * Decoder, station of every types.
56
- */
57
- decoder: () => Decoder<Metadata, Output>;
58
-
59
- /**
60
- * Object configurator.
61
- */
62
- objector: IConfig.IObjector<Output>;
63
-
64
- /**
65
- * Generator of functions for object types.
66
- */
67
- generator: IConfig.IGenerator;
68
- }
69
- export namespace IConfig {
70
- export interface ITypes {
71
- input: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
72
- output: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
73
- }
74
-
75
- export interface IObjector<Output extends ts.ConciseBody = ts.ConciseBody> {
76
- /**
77
- * Type checker when union object type comes.
78
- */
79
- checker: () => Decoder<Metadata, ts.Expression>;
80
-
81
- /**
82
- * Decoder, function call expression generator of specific typed objects.
83
- */
84
- decoder: () => Decoder<MetadataObject, ts.Expression>;
85
-
86
- /**
87
- * Joiner of expressions from properties.
88
- */
89
- joiner(
90
- input: ts.Expression,
91
- entries: IExpressionEntry<Output>[],
92
- parent: MetadataObject,
93
- ): ts.ConciseBody;
94
-
95
- /**
96
- * Union type specificator.
97
- *
98
- * Expression of an algorithm specifying object type and calling
99
- * the `decoder` function of the specified object type.
100
- */
101
- unionizer: Decoder<MetadataObject[], ts.Expression>;
102
-
103
- /**
104
- * Handler of union type specification failure.
105
- *
106
- * @param value Expression of input parameter
107
- * @param expected Expected type name
108
- * @param explore Exploration info
109
- * @returns Statement of failure
110
- */
111
- failure(
112
- value: ts.Expression,
113
- expected: string,
114
- explore?: undefined | IExplore,
115
- ): ts.Statement;
116
-
117
- /**
118
- * Transformer of type checking expression by discrimination.
119
- *
120
- * When an object type has been specified by a discrimination without full
121
- * iteration, the `unionizer` will decode the object instance after
122
- * the last type checking.
123
- *
124
- * In such circumtance, you can transform the last type checking function.
125
- *
126
- * @param exp Current expression about type checking
127
- * @returns Transformed expression
128
- * @deprecated
129
- */
130
- is?: undefined | ((exp: ts.Expression) => ts.Expression);
131
-
132
- /**
133
- * Transformer of non-undefined type checking by discrimination.
134
- *
135
- * When specifying an union type of objects, `typia` tries to find
136
- * descrimination way just by checking only one property type.
137
- * If succeeded to find the discrimination way, `typia` will check the target
138
- * property type and in the checking, non-undefined type checking would be
139
- * done.
140
- *
141
- * In such process, you can transform the non-undefined type checking.
142
- *
143
- * @param exp
144
- * @returns Transformed expression
145
- * @deprecated
146
- */
147
- required?: undefined | ((exp: ts.Expression) => ts.Expression);
148
-
149
- /**
150
- * Conditon wrapper when unable to specify any object type.
151
- *
152
- * When failed to specify an object type through discrimination, full
153
- * iteration type checking would be happend. In such circumstance, you
154
- * can wrap the condition with additional function.
155
- *
156
- * @param condition Current condition
157
- * @returns A function wrapped current condition
158
- */
159
- full?:
160
- | undefined
161
- | ((
162
- condition: ts.Expression,
163
- ) => (
164
- input: ts.Expression,
165
- expected: string,
166
- explore: IExplore,
167
- ) => ts.Expression);
168
-
169
- /**
170
- * Return type.
171
- */
172
- type?: undefined | ts.TypeNode;
173
- }
174
- export interface IGenerator {
175
- objects?:
176
- | undefined
177
- | (() => (col: MetadataCollection) => ts.VariableStatement[]);
178
- unions?:
179
- | undefined
180
- | (() => (col: MetadataCollection) => ts.VariableStatement[]);
181
- arrays(): (col: MetadataCollection) => ts.VariableStatement[];
182
- tuples(): (col: MetadataCollection) => ts.VariableStatement[];
183
- }
184
- }
185
-
186
- export interface IExplore {
187
- tracable: boolean;
188
- source: "top" | "function";
189
- from: "top" | "array" | "object";
190
- postfix: string;
191
- start?: undefined | number;
192
- }
193
-
194
- export interface Decoder<T, Output extends ts.ConciseBody = ts.ConciseBody> {
195
- (input: ts.Expression, target: T, explore: IExplore): Output;
196
- }
197
-
198
- /* -----------------------------------------------------------
199
- GENERATORS
200
- ----------------------------------------------------------- */
201
- export const write =
202
- (project: IProject) =>
203
- (config: IConfig) =>
204
- (importer: FunctionImporter) =>
205
- (type: ts.Type, name?: string) => {
206
- const [collection, meta] = config.initializer(project)(importer)(type);
207
-
208
- // ITERATE OVER ALL METADATA
209
- const output: ts.ConciseBody = config.decoder()(
210
- ValueFactory.INPUT(),
211
- meta,
212
- {
213
- tracable: config.path || config.trace,
214
- source: "top",
215
- from: "top",
216
- postfix: '""',
217
- },
218
- );
219
-
220
- // RETURNS THE OPTIMAL ARROW FUNCTION
221
- const functions = {
222
- objects: (
223
- config.generator.objects?.() ??
224
- write_object_functions(config)(importer)
225
- )(collection),
226
- unions: (config.generator.unions?.() ?? write_union_functions(config))(
227
- collection,
228
- ),
229
- arrays: config.generator.arrays()(collection),
230
- tuples: config.generator.tuples()(collection),
231
- };
232
- const added: ts.Statement[] = (config.addition ?? (() => []))(collection);
233
-
234
- return ts.factory.createArrowFunction(
235
- undefined,
236
- undefined,
237
- parameterDeclarations(config)(config.types.input(type, name))(
238
- ValueFactory.INPUT(),
239
- ),
240
- config.types.output(type, name),
241
- undefined,
242
- ts.factory.createBlock(
243
- [
244
- ...added,
245
- ...functions.objects.filter((_, i) =>
246
- importer.hasLocal(`${config.prefix}o${i}`),
247
- ),
248
- ...functions.unions.filter((_, i) =>
249
- importer.hasLocal(`${config.prefix}u${i}`),
250
- ),
251
- ...functions.arrays.filter((_, i) =>
252
- importer.hasLocal(`${config.prefix}a${i}`),
253
- ),
254
- ...functions.tuples.filter((_, i) =>
255
- importer.hasLocal(`${config.prefix}t${i}`),
256
- ),
257
- ...(ts.isBlock(output)
258
- ? output.statements
259
- : [ts.factory.createReturnStatement(output)]),
260
- ],
261
- true,
262
- ),
263
- );
264
- };
265
-
266
- export const write_object_functions =
267
- (config: IConfig) =>
268
- (importer: FunctionImporter) =>
269
- (collection: MetadataCollection) =>
270
- collection
271
- .objects()
272
- .map((obj) =>
273
- StatementFactory.constant(
274
- `${config.prefix}o${obj.index}`,
275
- ts.factory.createArrowFunction(
276
- undefined,
277
- undefined,
278
- parameterDeclarations(config)(TypeFactory.keyword("any"))(
279
- ValueFactory.INPUT(),
280
- ),
281
- config.objector.type ?? TypeFactory.keyword("any"),
282
- undefined,
283
- config.objector.joiner(
284
- ts.factory.createIdentifier("input"),
285
- feature_object_entries(config)(importer)(obj)(
286
- ts.factory.createIdentifier("input"),
287
- ),
288
- obj,
289
- ),
290
- ),
291
- ),
292
- );
293
-
294
- export const write_union_functions =
295
- (config: IConfig) => (collection: MetadataCollection) =>
296
- collection
297
- .unions()
298
- .map((union, i) =>
299
- StatementFactory.constant(
300
- `${config.prefix}u${i}`,
301
- write_union(config)(union),
302
- ),
303
- );
304
-
305
- const write_union = (config: IConfig) => {
306
- const explorer = UnionExplorer.object(config);
307
- const input = ValueFactory.INPUT();
308
-
309
- return (meta: MetadataObject[]) =>
310
- ts.factory.createArrowFunction(
311
- undefined,
312
- undefined,
313
- parameterDeclarations(config)(TypeFactory.keyword("any"))(
314
- ValueFactory.INPUT(),
315
- ),
316
- TypeFactory.keyword("any"),
317
- undefined,
318
- explorer(input, meta, {
319
- tracable: config.path || config.trace,
320
- source: "function",
321
- from: "object",
322
- postfix: "",
323
- }),
324
- );
325
- };
326
-
327
- /* -----------------------------------------------------------
328
- DECODERS
329
- ----------------------------------------------------------- */
330
- export const decode_array =
331
- (config: Pick<IConfig, "trace" | "path" | "decoder" | "prefix">) =>
332
- (importer: FunctionImporter) =>
333
- (
334
- combiner: (
335
- input: ts.Expression,
336
- arrow: ts.ArrowFunction,
337
- ) => ts.Expression,
338
- ) => {
339
- const rand: string = importer.increment().toString();
340
- const tail =
341
- config.path || config.trace
342
- ? [
343
- IdentifierFactory.parameter(
344
- "_index" + rand,
345
- TypeFactory.keyword("number"),
346
- ),
347
- ]
348
- : [];
349
-
350
- return (
351
- input: ts.Expression,
352
- array: MetadataArray,
353
- explore: IExplore,
354
- ) => {
355
- const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
356
- undefined,
357
- undefined,
358
- [
359
- IdentifierFactory.parameter("elem", TypeFactory.keyword("any")),
360
- ...tail,
361
- ],
362
- undefined,
363
- undefined,
364
- config.decoder()(ValueFactory.INPUT("elem"), array.type.value, {
365
- tracable: explore.tracable,
366
- source: explore.source,
367
- from: "array",
368
- postfix: index(explore.start ?? null)(explore.postfix)(rand),
369
- }),
370
- );
371
- return combiner(input, arrow);
372
- };
373
- };
374
-
375
- export const decode_object =
376
- (config: Pick<IConfig, "trace" | "path" | "prefix">) =>
377
- (importer: FunctionImporter) =>
378
- (input: ts.Expression, obj: MetadataObject, explore: IExplore) =>
379
- ts.factory.createCallExpression(
380
- ts.factory.createIdentifier(
381
- importer.useLocal(`${config.prefix}o${obj.index}`),
382
- ),
383
- undefined,
384
- argumentsArray(config)(explore)(input),
385
- );
386
-
387
- /* -----------------------------------------------------------
388
- UTILITIES FOR INTERNAL FUNCTIONS
389
- ----------------------------------------------------------- */
390
- export const index =
391
- (start: number | null) => (prev: string) => (rand: string) => {
392
- const tail: string =
393
- start !== null
394
- ? `"[" + (${start} + _index${rand}) + "]"`
395
- : `"[" + _index${rand} + "]"`;
396
- if (prev === "") return tail;
397
- else if (prev[prev.length - 1] === `"`)
398
- return prev.substring(0, prev.length - 1) + tail.substring(1);
399
- return prev + ` + ${tail}`;
400
- };
401
-
402
- export const argumentsArray =
403
- (config: Pick<IConfig, "path" | "trace">) =>
404
- (explore: FeatureProgrammer.IExplore) => {
405
- const tail: ts.Expression[] =
406
- config.path === false && config.trace === false
407
- ? []
408
- : config.path === true && config.trace === true
409
- ? [
410
- ts.factory.createIdentifier(
411
- explore.postfix ? `_path + ${explore.postfix}` : "_path",
412
- ),
413
- explore.source === "function"
414
- ? ts.factory.createIdentifier(
415
- `${explore.tracable} && _exceptionable`,
416
- )
417
- : explore.tracable
418
- ? ts.factory.createTrue()
419
- : ts.factory.createFalse(),
420
- ]
421
- : config.path === true
422
- ? [
423
- ts.factory.createIdentifier(
424
- explore.postfix ? `_path + ${explore.postfix}` : "_path",
425
- ),
426
- ]
427
- : [
428
- explore.source === "function"
429
- ? ts.factory.createIdentifier(
430
- `${explore.tracable} && _exceptionable`,
431
- )
432
- : explore.tracable
433
- ? ts.factory.createTrue()
434
- : ts.factory.createFalse(),
435
- ];
436
- return (input: ts.Expression) => [input, ...tail];
437
- };
438
-
439
- export const parameterDeclarations =
440
- (props: Pick<CheckerProgrammer.IConfig, "path" | "trace">) =>
441
- (type: ts.TypeNode) => {
442
- const tail: ts.ParameterDeclaration[] = [];
443
- if (props.path)
444
- tail.push(
445
- IdentifierFactory.parameter("_path", TypeFactory.keyword("string")),
446
- );
447
- if (props.trace)
448
- tail.push(
449
- IdentifierFactory.parameter(
450
- "_exceptionable",
451
- TypeFactory.keyword("boolean"),
452
- ts.factory.createTrue(),
453
- ),
454
- );
455
- return (input: ts.Identifier): ts.ParameterDeclaration[] => [
456
- IdentifierFactory.parameter(input, type),
457
- ...tail,
458
- ];
459
- };
460
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { MetadataCollection } from "../factories/MetadataCollection";
5
+ import { StatementFactory } from "../factories/StatementFactory";
6
+ import { TypeFactory } from "../factories/TypeFactory";
7
+ import { ValueFactory } from "../factories/ValueFactory";
8
+
9
+ import { Metadata } from "../schemas/metadata/Metadata";
10
+ import { MetadataArray } from "../schemas/metadata/MetadataArray";
11
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
12
+
13
+ import { IProject } from "../transformers/IProject";
14
+
15
+ import { CheckerProgrammer } from "./CheckerProgrammer";
16
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
17
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
+ import { UnionExplorer } from "./helpers/UnionExplorer";
19
+ import { feature_object_entries } from "./internal/feature_object_entries";
20
+
21
+ export namespace FeatureProgrammer {
22
+ /* -----------------------------------------------------------
23
+ PARAMETERS
24
+ ----------------------------------------------------------- */
25
+ export interface IConfig<Output extends ts.ConciseBody = ts.ConciseBody> {
26
+ types: IConfig.ITypes;
27
+
28
+ /**
29
+ * Prefix name of internal functions for specific types.
30
+ */
31
+ prefix: string;
32
+
33
+ /**
34
+ * Whether to archive access path or not.
35
+ */
36
+ path: boolean;
37
+
38
+ /**
39
+ * Whether to trace exception or not.
40
+ */
41
+ trace: boolean;
42
+
43
+ addition?: undefined | ((collection: MetadataCollection) => ts.Statement[]);
44
+
45
+ /**
46
+ * Initializer of metadata.
47
+ */
48
+ initializer: (
49
+ project: IProject,
50
+ ) => (
51
+ importer: FunctionImporter,
52
+ ) => (type: ts.Type) => [MetadataCollection, Metadata];
53
+
54
+ /**
55
+ * Decoder, station of every types.
56
+ */
57
+ decoder: () => Decoder<Metadata, Output>;
58
+
59
+ /**
60
+ * Object configurator.
61
+ */
62
+ objector: IConfig.IObjector<Output>;
63
+
64
+ /**
65
+ * Generator of functions for object types.
66
+ */
67
+ generator: IConfig.IGenerator;
68
+ }
69
+ export namespace IConfig {
70
+ export interface ITypes {
71
+ input: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
72
+ output: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
73
+ }
74
+
75
+ export interface IObjector<Output extends ts.ConciseBody = ts.ConciseBody> {
76
+ /**
77
+ * Type checker when union object type comes.
78
+ */
79
+ checker: () => Decoder<Metadata, ts.Expression>;
80
+
81
+ /**
82
+ * Decoder, function call expression generator of specific typed objects.
83
+ */
84
+ decoder: () => Decoder<MetadataObject, ts.Expression>;
85
+
86
+ /**
87
+ * Joiner of expressions from properties.
88
+ */
89
+ joiner(
90
+ input: ts.Expression,
91
+ entries: IExpressionEntry<Output>[],
92
+ parent: MetadataObject,
93
+ ): ts.ConciseBody;
94
+
95
+ /**
96
+ * Union type specificator.
97
+ *
98
+ * Expression of an algorithm specifying object type and calling
99
+ * the `decoder` function of the specified object type.
100
+ */
101
+ unionizer: Decoder<MetadataObject[], ts.Expression>;
102
+
103
+ /**
104
+ * Handler of union type specification failure.
105
+ *
106
+ * @param value Expression of input parameter
107
+ * @param expected Expected type name
108
+ * @param explore Exploration info
109
+ * @returns Statement of failure
110
+ */
111
+ failure(
112
+ value: ts.Expression,
113
+ expected: string,
114
+ explore?: undefined | IExplore,
115
+ ): ts.Statement;
116
+
117
+ /**
118
+ * Transformer of type checking expression by discrimination.
119
+ *
120
+ * When an object type has been specified by a discrimination without full
121
+ * iteration, the `unionizer` will decode the object instance after
122
+ * the last type checking.
123
+ *
124
+ * In such circumtance, you can transform the last type checking function.
125
+ *
126
+ * @param exp Current expression about type checking
127
+ * @returns Transformed expression
128
+ * @deprecated
129
+ */
130
+ is?: undefined | ((exp: ts.Expression) => ts.Expression);
131
+
132
+ /**
133
+ * Transformer of non-undefined type checking by discrimination.
134
+ *
135
+ * When specifying an union type of objects, `typia` tries to find
136
+ * descrimination way just by checking only one property type.
137
+ * If succeeded to find the discrimination way, `typia` will check the target
138
+ * property type and in the checking, non-undefined type checking would be
139
+ * done.
140
+ *
141
+ * In such process, you can transform the non-undefined type checking.
142
+ *
143
+ * @param exp
144
+ * @returns Transformed expression
145
+ * @deprecated
146
+ */
147
+ required?: undefined | ((exp: ts.Expression) => ts.Expression);
148
+
149
+ /**
150
+ * Conditon wrapper when unable to specify any object type.
151
+ *
152
+ * When failed to specify an object type through discrimination, full
153
+ * iteration type checking would be happend. In such circumstance, you
154
+ * can wrap the condition with additional function.
155
+ *
156
+ * @param condition Current condition
157
+ * @returns A function wrapped current condition
158
+ */
159
+ full?:
160
+ | undefined
161
+ | ((
162
+ condition: ts.Expression,
163
+ ) => (
164
+ input: ts.Expression,
165
+ expected: string,
166
+ explore: IExplore,
167
+ ) => ts.Expression);
168
+
169
+ /**
170
+ * Return type.
171
+ */
172
+ type?: undefined | ts.TypeNode;
173
+ }
174
+ export interface IGenerator {
175
+ objects?:
176
+ | undefined
177
+ | (() => (col: MetadataCollection) => ts.VariableStatement[]);
178
+ unions?:
179
+ | undefined
180
+ | (() => (col: MetadataCollection) => ts.VariableStatement[]);
181
+ arrays(): (col: MetadataCollection) => ts.VariableStatement[];
182
+ tuples(): (col: MetadataCollection) => ts.VariableStatement[];
183
+ }
184
+ }
185
+
186
+ export interface IExplore {
187
+ tracable: boolean;
188
+ source: "top" | "function";
189
+ from: "top" | "array" | "object";
190
+ postfix: string;
191
+ start?: undefined | number;
192
+ }
193
+
194
+ export interface Decoder<T, Output extends ts.ConciseBody = ts.ConciseBody> {
195
+ (input: ts.Expression, target: T, explore: IExplore): Output;
196
+ }
197
+
198
+ /* -----------------------------------------------------------
199
+ GENERATORS
200
+ ----------------------------------------------------------- */
201
+ export const write =
202
+ (project: IProject) =>
203
+ (config: IConfig) =>
204
+ (importer: FunctionImporter) =>
205
+ (type: ts.Type, name?: string) => {
206
+ const [collection, meta] = config.initializer(project)(importer)(type);
207
+
208
+ // ITERATE OVER ALL METADATA
209
+ const output: ts.ConciseBody = config.decoder()(
210
+ ValueFactory.INPUT(),
211
+ meta,
212
+ {
213
+ tracable: config.path || config.trace,
214
+ source: "top",
215
+ from: "top",
216
+ postfix: '""',
217
+ },
218
+ );
219
+
220
+ // RETURNS THE OPTIMAL ARROW FUNCTION
221
+ const functions = {
222
+ objects: (
223
+ config.generator.objects?.() ??
224
+ write_object_functions(config)(importer)
225
+ )(collection),
226
+ unions: (config.generator.unions?.() ?? write_union_functions(config))(
227
+ collection,
228
+ ),
229
+ arrays: config.generator.arrays()(collection),
230
+ tuples: config.generator.tuples()(collection),
231
+ };
232
+ const added: ts.Statement[] = (config.addition ?? (() => []))(collection);
233
+
234
+ return ts.factory.createArrowFunction(
235
+ undefined,
236
+ undefined,
237
+ parameterDeclarations(config)(config.types.input(type, name))(
238
+ ValueFactory.INPUT(),
239
+ ),
240
+ config.types.output(type, name),
241
+ undefined,
242
+ ts.factory.createBlock(
243
+ [
244
+ ...added,
245
+ ...functions.objects.filter((_, i) =>
246
+ importer.hasLocal(`${config.prefix}o${i}`),
247
+ ),
248
+ ...functions.unions.filter((_, i) =>
249
+ importer.hasLocal(`${config.prefix}u${i}`),
250
+ ),
251
+ ...functions.arrays.filter((_, i) =>
252
+ importer.hasLocal(`${config.prefix}a${i}`),
253
+ ),
254
+ ...functions.tuples.filter((_, i) =>
255
+ importer.hasLocal(`${config.prefix}t${i}`),
256
+ ),
257
+ ...(ts.isBlock(output)
258
+ ? output.statements
259
+ : [ts.factory.createReturnStatement(output)]),
260
+ ],
261
+ true,
262
+ ),
263
+ );
264
+ };
265
+
266
+ export const write_object_functions =
267
+ (config: IConfig) =>
268
+ (importer: FunctionImporter) =>
269
+ (collection: MetadataCollection) =>
270
+ collection
271
+ .objects()
272
+ .map((obj) =>
273
+ StatementFactory.constant(
274
+ `${config.prefix}o${obj.index}`,
275
+ ts.factory.createArrowFunction(
276
+ undefined,
277
+ undefined,
278
+ parameterDeclarations(config)(TypeFactory.keyword("any"))(
279
+ ValueFactory.INPUT(),
280
+ ),
281
+ config.objector.type ?? TypeFactory.keyword("any"),
282
+ undefined,
283
+ config.objector.joiner(
284
+ ts.factory.createIdentifier("input"),
285
+ feature_object_entries(config)(importer)(obj)(
286
+ ts.factory.createIdentifier("input"),
287
+ ),
288
+ obj,
289
+ ),
290
+ ),
291
+ ),
292
+ );
293
+
294
+ export const write_union_functions =
295
+ (config: IConfig) => (collection: MetadataCollection) =>
296
+ collection
297
+ .unions()
298
+ .map((union, i) =>
299
+ StatementFactory.constant(
300
+ `${config.prefix}u${i}`,
301
+ write_union(config)(union),
302
+ ),
303
+ );
304
+
305
+ const write_union = (config: IConfig) => {
306
+ const explorer = UnionExplorer.object(config);
307
+ const input = ValueFactory.INPUT();
308
+
309
+ return (meta: MetadataObject[]) =>
310
+ ts.factory.createArrowFunction(
311
+ undefined,
312
+ undefined,
313
+ parameterDeclarations(config)(TypeFactory.keyword("any"))(
314
+ ValueFactory.INPUT(),
315
+ ),
316
+ TypeFactory.keyword("any"),
317
+ undefined,
318
+ explorer(input, meta, {
319
+ tracable: config.path || config.trace,
320
+ source: "function",
321
+ from: "object",
322
+ postfix: "",
323
+ }),
324
+ );
325
+ };
326
+
327
+ /* -----------------------------------------------------------
328
+ DECODERS
329
+ ----------------------------------------------------------- */
330
+ export const decode_array =
331
+ (config: Pick<IConfig, "trace" | "path" | "decoder" | "prefix">) =>
332
+ (importer: FunctionImporter) =>
333
+ (
334
+ combiner: (
335
+ input: ts.Expression,
336
+ arrow: ts.ArrowFunction,
337
+ ) => ts.Expression,
338
+ ) => {
339
+ const rand: string = importer.increment().toString();
340
+ const tail =
341
+ config.path || config.trace
342
+ ? [
343
+ IdentifierFactory.parameter(
344
+ "_index" + rand,
345
+ TypeFactory.keyword("number"),
346
+ ),
347
+ ]
348
+ : [];
349
+
350
+ return (
351
+ input: ts.Expression,
352
+ array: MetadataArray,
353
+ explore: IExplore,
354
+ ) => {
355
+ const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
356
+ undefined,
357
+ undefined,
358
+ [
359
+ IdentifierFactory.parameter("elem", TypeFactory.keyword("any")),
360
+ ...tail,
361
+ ],
362
+ undefined,
363
+ undefined,
364
+ config.decoder()(ValueFactory.INPUT("elem"), array.type.value, {
365
+ tracable: explore.tracable,
366
+ source: explore.source,
367
+ from: "array",
368
+ postfix: index(explore.start ?? null)(explore.postfix)(rand),
369
+ }),
370
+ );
371
+ return combiner(input, arrow);
372
+ };
373
+ };
374
+
375
+ export const decode_object =
376
+ (config: Pick<IConfig, "trace" | "path" | "prefix">) =>
377
+ (importer: FunctionImporter) =>
378
+ (input: ts.Expression, obj: MetadataObject, explore: IExplore) =>
379
+ ts.factory.createCallExpression(
380
+ ts.factory.createIdentifier(
381
+ importer.useLocal(`${config.prefix}o${obj.index}`),
382
+ ),
383
+ undefined,
384
+ argumentsArray(config)(explore)(input),
385
+ );
386
+
387
+ /* -----------------------------------------------------------
388
+ UTILITIES FOR INTERNAL FUNCTIONS
389
+ ----------------------------------------------------------- */
390
+ export const index =
391
+ (start: number | null) => (prev: string) => (rand: string) => {
392
+ const tail: string =
393
+ start !== null
394
+ ? `"[" + (${start} + _index${rand}) + "]"`
395
+ : `"[" + _index${rand} + "]"`;
396
+ if (prev === "") return tail;
397
+ else if (prev[prev.length - 1] === `"`)
398
+ return prev.substring(0, prev.length - 1) + tail.substring(1);
399
+ return prev + ` + ${tail}`;
400
+ };
401
+
402
+ export const argumentsArray =
403
+ (config: Pick<IConfig, "path" | "trace">) =>
404
+ (explore: FeatureProgrammer.IExplore) => {
405
+ const tail: ts.Expression[] =
406
+ config.path === false && config.trace === false
407
+ ? []
408
+ : config.path === true && config.trace === true
409
+ ? [
410
+ ts.factory.createIdentifier(
411
+ explore.postfix ? `_path + ${explore.postfix}` : "_path",
412
+ ),
413
+ explore.source === "function"
414
+ ? ts.factory.createIdentifier(
415
+ `${explore.tracable} && _exceptionable`,
416
+ )
417
+ : explore.tracable
418
+ ? ts.factory.createTrue()
419
+ : ts.factory.createFalse(),
420
+ ]
421
+ : config.path === true
422
+ ? [
423
+ ts.factory.createIdentifier(
424
+ explore.postfix ? `_path + ${explore.postfix}` : "_path",
425
+ ),
426
+ ]
427
+ : [
428
+ explore.source === "function"
429
+ ? ts.factory.createIdentifier(
430
+ `${explore.tracable} && _exceptionable`,
431
+ )
432
+ : explore.tracable
433
+ ? ts.factory.createTrue()
434
+ : ts.factory.createFalse(),
435
+ ];
436
+ return (input: ts.Expression) => [input, ...tail];
437
+ };
438
+
439
+ export const parameterDeclarations =
440
+ (props: Pick<CheckerProgrammer.IConfig, "path" | "trace">) =>
441
+ (type: ts.TypeNode) => {
442
+ const tail: ts.ParameterDeclaration[] = [];
443
+ if (props.path)
444
+ tail.push(
445
+ IdentifierFactory.parameter("_path", TypeFactory.keyword("string")),
446
+ );
447
+ if (props.trace)
448
+ tail.push(
449
+ IdentifierFactory.parameter(
450
+ "_exceptionable",
451
+ TypeFactory.keyword("boolean"),
452
+ ts.factory.createTrue(),
453
+ ),
454
+ );
455
+ return (input: ts.Identifier): ts.ParameterDeclaration[] => [
456
+ IdentifierFactory.parameter(input, type),
457
+ ...tail,
458
+ ];
459
+ };
460
+ }