typia 3.8.4-dev.20230502 → 4.0.0-dev.20230502

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 (283) hide show
  1. package/README.md +9 -1
  2. package/lib/factories/ProtocolFactory.d.ts +8 -0
  3. package/lib/factories/ProtocolFactory.js +112 -0
  4. package/lib/factories/ProtocolFactory.js.map +1 -0
  5. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
  6. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +160 -0
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  8. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  9. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  10. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  14. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  15. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  16. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  41. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  42. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  43. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  44. package/lib/functional/$proto_bytes.d.ts +2 -0
  45. package/lib/functional/$proto_bytes.js +37 -0
  46. package/lib/functional/$proto_bytes.js.map +1 -0
  47. package/lib/functional/$proto_field.d.ts +10 -0
  48. package/lib/functional/$proto_field.js +42 -0
  49. package/lib/functional/$proto_field.js.map +1 -0
  50. package/lib/functional/$proto_float.d.ts +4 -0
  51. package/lib/functional/$proto_float.js +28 -0
  52. package/lib/functional/$proto_float.js.map +1 -0
  53. package/lib/functional/$proto_i32.d.ts +2 -0
  54. package/lib/functional/$proto_i32.js +23 -0
  55. package/lib/functional/$proto_i32.js.map +1 -0
  56. package/lib/functional/$proto_i64.d.ts +2 -0
  57. package/lib/functional/$proto_i64.js +31 -0
  58. package/lib/functional/$proto_i64.js.map +1 -0
  59. package/lib/functional/$proto_size.d.ts +6 -0
  60. package/lib/functional/$proto_size.js +76 -0
  61. package/lib/functional/$proto_size.js.map +1 -0
  62. package/lib/functional/$proto_string.d.ts +2 -0
  63. package/lib/functional/$proto_string.js +34 -0
  64. package/lib/functional/$proto_string.js.map +1 -0
  65. package/lib/functional/$varint.d.ts +6 -0
  66. package/lib/functional/$varint.js +99 -0
  67. package/lib/functional/$varint.js.map +1 -0
  68. package/lib/functional/$zigzag.d.ts +4 -0
  69. package/lib/functional/$zigzag.js +34 -0
  70. package/lib/functional/$zigzag.js.map +1 -0
  71. package/lib/messages/IProtocolMap.d.ts +5 -0
  72. package/lib/messages/IProtocolMap.js +3 -0
  73. package/lib/messages/IProtocolMap.js.map +1 -0
  74. package/lib/messages/IProtocolMessage.d.ts +5 -0
  75. package/lib/messages/IProtocolMessage.js +3 -0
  76. package/lib/messages/IProtocolMessage.js.map +1 -0
  77. package/lib/messages/IProtocolProperty.d.ts +12 -0
  78. package/lib/messages/IProtocolProperty.js +3 -0
  79. package/lib/messages/IProtocolProperty.js.map +1 -0
  80. package/lib/metadata/IMetadataTag.d.ts +3 -3
  81. package/lib/metadata/Metadata.js +1 -1
  82. package/lib/metadata/Metadata.js.map +1 -1
  83. package/lib/module.d.ts +2 -0
  84. package/lib/module.js +6 -1
  85. package/lib/module.js.map +1 -1
  86. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  87. package/lib/programmers/MessageProgrammer.js +141 -0
  88. package/lib/programmers/MessageProgrammer.js.map +1 -0
  89. package/lib/transformers/CallExpressionTransformer.js +5 -3
  90. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  91. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  92. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  93. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  94. package/lib/transformers/features/protocols/MessageTransformer.js +20 -0
  95. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  96. package/lib/utils/NameEncoder.d.ts +4 -0
  97. package/lib/utils/NameEncoder.js +89 -0
  98. package/lib/utils/NameEncoder.js.map +1 -0
  99. package/package.json +1 -1
  100. package/src/Primitive.ts +123 -123
  101. package/src/executable/TypiaGenerateWizard.ts +85 -85
  102. package/src/executable/TypiaSetupWizard.ts +133 -133
  103. package/src/executable/setup/CommandExecutor.ts +8 -8
  104. package/src/executable/setup/PackageManager.ts +71 -71
  105. package/src/executable/setup/PluginConfigurator.ts +70 -70
  106. package/src/executable/typia.ts +52 -52
  107. package/src/factories/CommentFactory.ts +14 -14
  108. package/src/factories/ExpressionFactory.ts +70 -70
  109. package/src/factories/IdentifierFactory.ts +63 -63
  110. package/src/factories/LiteralFactory.ts +39 -39
  111. package/src/factories/MetadataCollection.ts +121 -121
  112. package/src/factories/MetadataFactory.ts +62 -62
  113. package/src/factories/MetadataTagFactory.ts +297 -297
  114. package/src/factories/ProtocolFactory.ts +79 -0
  115. package/src/factories/StatementFactory.ts +24 -24
  116. package/src/factories/TemplateFactory.ts +58 -58
  117. package/src/factories/TypeFactory.ts +124 -124
  118. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  119. package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
  120. package/src/factories/internal/metadata/iterate_metadata.ts +67 -67
  121. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  122. package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
  123. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  124. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  125. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
  126. package/src/factories/internal/metadata/iterate_metadata_union.ts +57 -57
  127. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +167 -0
  128. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  129. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  130. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  131. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  132. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  133. package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
  134. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
  135. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  136. package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
  137. package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
  138. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
  139. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
  140. package/src/functional/$any.ts +2 -2
  141. package/src/functional/$dictionary.ts +25 -25
  142. package/src/functional/$is_between.ts +2 -2
  143. package/src/functional/$is_custom.ts +14 -14
  144. package/src/functional/$is_date.ts +3 -3
  145. package/src/functional/$is_datetime.ts +2 -2
  146. package/src/functional/$is_email.ts +4 -4
  147. package/src/functional/$is_ipv4.ts +4 -4
  148. package/src/functional/$is_ipv6.ts +4 -4
  149. package/src/functional/$is_url.ts +4 -4
  150. package/src/functional/$is_uuid.ts +4 -4
  151. package/src/functional/$join.ts +46 -46
  152. package/src/functional/$number.ts +12 -12
  153. package/src/functional/$proto_bytes.ts +25 -0
  154. package/src/functional/$proto_field.ts +30 -0
  155. package/src/functional/$proto_float.ts +37 -0
  156. package/src/functional/$proto_i32.ts +29 -0
  157. package/src/functional/$proto_i64.ts +37 -0
  158. package/src/functional/$proto_size.ts +82 -0
  159. package/src/functional/$proto_string.ts +24 -0
  160. package/src/functional/$rest.ts +3 -3
  161. package/src/functional/$string.ts +37 -37
  162. package/src/functional/$tail.ts +5 -5
  163. package/src/functional/$varint.ts +130 -0
  164. package/src/functional/$zigzag.ts +39 -0
  165. package/src/messages/IProtocolMap.ts +5 -0
  166. package/src/messages/IProtocolMessage.ts +6 -0
  167. package/src/messages/IProtocolProperty.ts +13 -0
  168. package/src/metadata/IMetadata.ts +26 -26
  169. package/src/metadata/IMetadataTag.ts +11 -3
  170. package/src/metadata/Metadata.ts +543 -539
  171. package/src/metadata/MetadataConstant.ts +3 -3
  172. package/src/metadata/MetadataObject.ts +127 -127
  173. package/src/module.ts +2054 -2043
  174. package/src/programmers/ApplicationProgrammer.ts +62 -62
  175. package/src/programmers/AssertCloneProgrammer.ts +79 -79
  176. package/src/programmers/AssertParseProgrammer.ts +74 -74
  177. package/src/programmers/AssertProgrammer.ts +285 -285
  178. package/src/programmers/AssertPruneProgrammer.ts +76 -76
  179. package/src/programmers/AssertStringifyProgrammer.ts +74 -74
  180. package/src/programmers/CheckerProgrammer.ts +901 -901
  181. package/src/programmers/CloneProgrammer.ts +389 -389
  182. package/src/programmers/FeatureProgrammer.ts +500 -500
  183. package/src/programmers/IsCloneProgrammer.ts +86 -86
  184. package/src/programmers/IsParseProgrammer.ts +80 -80
  185. package/src/programmers/IsProgrammer.ts +212 -212
  186. package/src/programmers/IsPruneProgrammer.ts +81 -81
  187. package/src/programmers/IsStringifyProgrammer.ts +84 -84
  188. package/src/programmers/LiteralsProgrammer.ts +65 -65
  189. package/src/programmers/MessageProgrammer.ts +126 -0
  190. package/src/programmers/PruneProgrammer.ts +347 -347
  191. package/src/programmers/RandomProgrammer.ts +423 -423
  192. package/src/programmers/StringifyProgrammer.ts +798 -798
  193. package/src/programmers/TypiaProgrammer.ts +129 -129
  194. package/src/programmers/ValidateCloneProgrammer.ts +93 -93
  195. package/src/programmers/ValidateParseProgrammer.ts +78 -78
  196. package/src/programmers/ValidateProgrammer.ts +316 -316
  197. package/src/programmers/ValidatePruneProgrammer.ts +86 -86
  198. package/src/programmers/ValidateStringifyProgrammer.ts +92 -92
  199. package/src/programmers/helpers/CloneJoiner.ts +131 -131
  200. package/src/programmers/helpers/FunctionImporeter.ts +54 -54
  201. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  202. package/src/programmers/helpers/PruneJoiner.ts +144 -144
  203. package/src/programmers/helpers/StringifyJoinder.ts +113 -113
  204. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  205. package/src/programmers/helpers/UnionExplorer.ts +275 -275
  206. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  207. package/src/programmers/internal/application_array.ts +36 -36
  208. package/src/programmers/internal/application_boolean.ts +17 -17
  209. package/src/programmers/internal/application_constant.ts +30 -30
  210. package/src/programmers/internal/application_default_string.ts +33 -33
  211. package/src/programmers/internal/application_native.ts +32 -32
  212. package/src/programmers/internal/application_number.ts +73 -73
  213. package/src/programmers/internal/application_object.ts +155 -155
  214. package/src/programmers/internal/application_schema.ts +213 -213
  215. package/src/programmers/internal/application_string.ts +45 -45
  216. package/src/programmers/internal/application_templates.ts +26 -26
  217. package/src/programmers/internal/application_tuple.ts +31 -31
  218. package/src/programmers/internal/check_array.ts +30 -30
  219. package/src/programmers/internal/check_custom.ts +31 -31
  220. package/src/programmers/internal/check_dynamic_properties.ts +194 -194
  221. package/src/programmers/internal/check_everything.ts +28 -28
  222. package/src/programmers/internal/check_native.ts +21 -21
  223. package/src/programmers/internal/check_string_tags.ts +67 -67
  224. package/src/programmers/internal/check_union_array_like.ts +271 -271
  225. package/src/programmers/internal/check_union_tuple.ts +33 -33
  226. package/src/programmers/internal/random_custom.ts +29 -29
  227. package/src/programmers/internal/stringify_dynamic_properties.ts +167 -167
  228. package/src/programmers/internal/stringify_native.ts +7 -7
  229. package/src/programmers/internal/stringify_regular_properties.ts +83 -83
  230. package/src/schemas/IJsonSchema.ts +130 -130
  231. package/src/transform.ts +17 -17
  232. package/src/transformers/CallExpressionTransformer.ts +184 -177
  233. package/src/transformers/FileTransformer.ts +47 -47
  234. package/src/transformers/NodeTransformer.ts +13 -13
  235. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +112 -114
  236. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  237. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  238. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  239. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  240. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  241. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  242. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  243. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  244. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  245. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +39 -39
  246. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  247. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  248. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  249. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  250. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +28 -28
  251. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +52 -52
  252. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  253. package/src/transformers/features/miscellaneous/RandomTransformer.ts +42 -42
  254. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  255. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  256. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  257. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  258. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  259. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  260. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  261. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  262. package/src/transformers/features/protocols/MessageTransformer.ts +31 -0
  263. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  264. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
  265. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  266. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  267. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
  268. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  269. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  270. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  271. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  272. package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
  273. package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
  274. package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
  275. package/src/transformers/features/validators/IsTransformer.ts +11 -11
  276. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  277. package/src/transformers/internal/GenericTransformer.ts +97 -97
  278. package/src/utils/ArrayUtil.ts +44 -44
  279. package/src/utils/Escaper.ts +45 -45
  280. package/src/utils/MapUtil.ts +12 -12
  281. package/src/utils/NameEncoder.ts +32 -0
  282. package/src/utils/PatternUtil.ts +30 -30
  283. package/src/utils/RandomGenerator.ts +81 -81
@@ -1,213 +1,213 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonComponents } from "../../schemas/IJsonComponents";
3
- import { IJsonSchema } from "../../schemas/IJsonSchema";
4
-
5
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
- import { application_array } from "./application_array";
8
- import { application_boolean } from "./application_boolean";
9
- import { application_constant } from "./application_constant";
10
- import { application_native } from "./application_native";
11
- import { application_number } from "./application_number";
12
- import { application_object } from "./application_object";
13
- import { application_string } from "./application_string";
14
- import { application_templates } from "./application_templates";
15
- import { application_tuple } from "./application_tuple";
16
-
17
- /**
18
- * @internal
19
- */
20
- export const application_schema =
21
- (options: ApplicationProgrammer.IOptions) =>
22
- <BlockNever extends boolean>(blockNever: BlockNever) =>
23
- (components: IJsonComponents) =>
24
- (meta: Metadata) =>
25
- (
26
- attribute: IJsonSchema.IAttribute,
27
- ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
28
- // VULNERABLE CASE
29
- if (meta.any === true)
30
- return {
31
- ...attribute,
32
- type: undefined,
33
- };
34
- else if (meta.nullable && meta.empty())
35
- return { type: "null", ...attribute };
36
-
37
- //----
38
- // GATHER UNION SCHEMAS
39
- //----
40
- const union: IJsonSchema[] = [];
41
-
42
- // toJSON() METHOD
43
- if (meta.resolved !== null) {
44
- const resolved = application_schema(options)(blockNever)(
45
- components,
46
- )(meta.resolved)(attribute);
47
- if (resolved !== null) union.push(resolved);
48
- }
49
-
50
- // ATOMIC TYPES
51
- if (meta.templates.length && AtomicPredicator.template(meta))
52
- union.push(application_templates(meta)(attribute));
53
- for (const constant of meta.constants)
54
- if (constant.type === "bigint") throw new Error(NO_BIGINT);
55
- else if (
56
- (constant.type === "string" && meta.templates.length) ||
57
- AtomicPredicator.constant(meta)(constant.type) === false
58
- )
59
- continue;
60
- else
61
- union.push(
62
- application_constant(constant)({
63
- nullable: meta.nullable,
64
- attribute,
65
- }),
66
- );
67
- for (const type of meta.atomics)
68
- if (type === "bigint") throw new Error(NO_BIGINT);
69
- else if (AtomicPredicator.atomic(meta)(type) === false) continue;
70
- else
71
- union.push(
72
- type === "string"
73
- ? application_string(meta, attribute)
74
- : type === "boolean"
75
- ? application_boolean({
76
- nullable: meta.nullable,
77
- attribute,
78
- })
79
- : application_number({
80
- nullable: meta.nullable,
81
- attribute,
82
- }),
83
- );
84
-
85
- // ARRAY
86
- for (const schema of meta.arrays.values())
87
- union.push(
88
- application_array(options)(components)()(schema)({
89
- nullable: meta.nullable,
90
- attribute,
91
- }),
92
- );
93
-
94
- // TUPLE
95
- for (const items of meta.tuples) {
96
- const tuple: IJsonSchema.ITuple = application_tuple(options)(
97
- components,
98
- )(items)({
99
- nullable: meta.nullable,
100
- attribute,
101
- });
102
- if (options.purpose === "swagger" && items.length === 0)
103
- throw new Error(
104
- "Error on typia.application(): swagger does not support zero length tuple type.",
105
- );
106
- else if (
107
- options.purpose === "ajv" &&
108
- !items[items.length - 1]?.rest
109
- )
110
- union.push(tuple);
111
- else {
112
- // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
113
- const merged: Metadata = items.reduce((x, y) =>
114
- Metadata.merge(x, y),
115
- );
116
- union.push(
117
- application_array(options)(components)(tuple)(merged)({
118
- nullable: merged?.nullable ?? false,
119
- attribute,
120
- }),
121
- );
122
- }
123
- }
124
-
125
- // NATIVES
126
- for (const native of meta.natives)
127
- if (AtomicPredicator.native(native))
128
- union.push(
129
- native === "String"
130
- ? application_string(meta, attribute)
131
- : native === "Boolean"
132
- ? application_boolean({
133
- nullable: meta.nullable,
134
- attribute,
135
- })
136
- : application_number({
137
- nullable: meta.nullable,
138
- attribute,
139
- }),
140
- );
141
- else
142
- union.push(
143
- application_native(options)(components)(native)({
144
- nullable: meta.nullable,
145
- attribute,
146
- }),
147
- );
148
- if (meta.sets.length)
149
- union.push(
150
- application_native(options)(components)(`Set`)({
151
- nullable: meta.nullable,
152
- attribute,
153
- }),
154
- );
155
- if (meta.maps.length)
156
- union.push(
157
- application_native(options)(components)(`Map`)({
158
- nullable: meta.nullable,
159
- attribute,
160
- }),
161
- );
162
-
163
- // OBJECT
164
- for (const obj of meta.objects) {
165
- const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
166
- application_object(options)(components)(obj)({
167
- key,
168
- nullable: meta.nullable,
169
- });
170
- union.push(
171
- (options.purpose === "ajv" && obj.recursive
172
- ? recursive
173
- : reference)(`${options.prefix}/${key}`, attribute),
174
- );
175
- }
176
-
177
- //----
178
- // RETURNS
179
- //----
180
- if (union.length === 0)
181
- return blockNever === true
182
- ? null!
183
- : {
184
- ...attribute,
185
- type: undefined,
186
- };
187
- else if (union.length === 1) return union[0]!;
188
- return { oneOf: union, ...attribute };
189
- };
190
-
191
- /**
192
- * @internal
193
- */
194
- const reference = (
195
- $ref: string,
196
- attribute: IJsonSchema.IAttribute,
197
- ): IJsonSchema.IReference => ({
198
- $ref,
199
- ...attribute,
200
- });
201
-
202
- /**
203
- * @internal
204
- */
205
- const recursive = (
206
- $recursiveRef: string,
207
- attribute: IJsonSchema.IAttribute,
208
- ): IJsonSchema.IRecursiveReference => ({
209
- $recursiveRef,
210
- ...attribute,
211
- });
212
-
213
- const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
3
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
4
+
5
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
+ import { application_array } from "./application_array";
8
+ import { application_boolean } from "./application_boolean";
9
+ import { application_constant } from "./application_constant";
10
+ import { application_native } from "./application_native";
11
+ import { application_number } from "./application_number";
12
+ import { application_object } from "./application_object";
13
+ import { application_string } from "./application_string";
14
+ import { application_templates } from "./application_templates";
15
+ import { application_tuple } from "./application_tuple";
16
+
17
+ /**
18
+ * @internal
19
+ */
20
+ export const application_schema =
21
+ (options: ApplicationProgrammer.IOptions) =>
22
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
23
+ (components: IJsonComponents) =>
24
+ (meta: Metadata) =>
25
+ (
26
+ attribute: IJsonSchema.IAttribute,
27
+ ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
28
+ // VULNERABLE CASE
29
+ if (meta.any === true)
30
+ return {
31
+ ...attribute,
32
+ type: undefined,
33
+ };
34
+ else if (meta.nullable && meta.empty())
35
+ return { type: "null", ...attribute };
36
+
37
+ //----
38
+ // GATHER UNION SCHEMAS
39
+ //----
40
+ const union: IJsonSchema[] = [];
41
+
42
+ // toJSON() METHOD
43
+ if (meta.resolved !== null) {
44
+ const resolved = application_schema(options)(blockNever)(
45
+ components,
46
+ )(meta.resolved)(attribute);
47
+ if (resolved !== null) union.push(resolved);
48
+ }
49
+
50
+ // ATOMIC TYPES
51
+ if (meta.templates.length && AtomicPredicator.template(meta))
52
+ union.push(application_templates(meta)(attribute));
53
+ for (const constant of meta.constants)
54
+ if (constant.type === "bigint") throw new Error(NO_BIGINT);
55
+ else if (
56
+ (constant.type === "string" && meta.templates.length) ||
57
+ AtomicPredicator.constant(meta)(constant.type) === false
58
+ )
59
+ continue;
60
+ else
61
+ union.push(
62
+ application_constant(constant)({
63
+ nullable: meta.nullable,
64
+ attribute,
65
+ }),
66
+ );
67
+ for (const type of meta.atomics)
68
+ if (type === "bigint") throw new Error(NO_BIGINT);
69
+ else if (AtomicPredicator.atomic(meta)(type) === false) continue;
70
+ else
71
+ union.push(
72
+ type === "string"
73
+ ? application_string(meta, attribute)
74
+ : type === "boolean"
75
+ ? application_boolean({
76
+ nullable: meta.nullable,
77
+ attribute,
78
+ })
79
+ : application_number({
80
+ nullable: meta.nullable,
81
+ attribute,
82
+ }),
83
+ );
84
+
85
+ // ARRAY
86
+ for (const schema of meta.arrays.values())
87
+ union.push(
88
+ application_array(options)(components)()(schema)({
89
+ nullable: meta.nullable,
90
+ attribute,
91
+ }),
92
+ );
93
+
94
+ // TUPLE
95
+ for (const items of meta.tuples) {
96
+ const tuple: IJsonSchema.ITuple = application_tuple(options)(
97
+ components,
98
+ )(items)({
99
+ nullable: meta.nullable,
100
+ attribute,
101
+ });
102
+ if (options.purpose === "swagger" && items.length === 0)
103
+ throw new Error(
104
+ "Error on typia.application(): swagger does not support zero length tuple type.",
105
+ );
106
+ else if (
107
+ options.purpose === "ajv" &&
108
+ !items[items.length - 1]?.rest
109
+ )
110
+ union.push(tuple);
111
+ else {
112
+ // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
113
+ const merged: Metadata = items.reduce((x, y) =>
114
+ Metadata.merge(x, y),
115
+ );
116
+ union.push(
117
+ application_array(options)(components)(tuple)(merged)({
118
+ nullable: merged?.nullable ?? false,
119
+ attribute,
120
+ }),
121
+ );
122
+ }
123
+ }
124
+
125
+ // NATIVES
126
+ for (const native of meta.natives)
127
+ if (AtomicPredicator.native(native))
128
+ union.push(
129
+ native === "String"
130
+ ? application_string(meta, attribute)
131
+ : native === "Boolean"
132
+ ? application_boolean({
133
+ nullable: meta.nullable,
134
+ attribute,
135
+ })
136
+ : application_number({
137
+ nullable: meta.nullable,
138
+ attribute,
139
+ }),
140
+ );
141
+ else
142
+ union.push(
143
+ application_native(options)(components)(native)({
144
+ nullable: meta.nullable,
145
+ attribute,
146
+ }),
147
+ );
148
+ if (meta.sets.length)
149
+ union.push(
150
+ application_native(options)(components)(`Set`)({
151
+ nullable: meta.nullable,
152
+ attribute,
153
+ }),
154
+ );
155
+ if (meta.maps.length)
156
+ union.push(
157
+ application_native(options)(components)(`Map`)({
158
+ nullable: meta.nullable,
159
+ attribute,
160
+ }),
161
+ );
162
+
163
+ // OBJECT
164
+ for (const obj of meta.objects) {
165
+ const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
166
+ application_object(options)(components)(obj)({
167
+ key,
168
+ nullable: meta.nullable,
169
+ });
170
+ union.push(
171
+ (options.purpose === "ajv" && obj.recursive
172
+ ? recursive
173
+ : reference)(`${options.prefix}/${key}`, attribute),
174
+ );
175
+ }
176
+
177
+ //----
178
+ // RETURNS
179
+ //----
180
+ if (union.length === 0)
181
+ return blockNever === true
182
+ ? null!
183
+ : {
184
+ ...attribute,
185
+ type: undefined,
186
+ };
187
+ else if (union.length === 1) return union[0]!;
188
+ return { oneOf: union, ...attribute };
189
+ };
190
+
191
+ /**
192
+ * @internal
193
+ */
194
+ const reference = (
195
+ $ref: string,
196
+ attribute: IJsonSchema.IAttribute,
197
+ ): IJsonSchema.IReference => ({
198
+ $ref,
199
+ ...attribute,
200
+ });
201
+
202
+ /**
203
+ * @internal
204
+ */
205
+ const recursive = (
206
+ $recursiveRef: string,
207
+ attribute: IJsonSchema.IAttribute,
208
+ ): IJsonSchema.IRecursiveReference => ({
209
+ $recursiveRef,
210
+ ...attribute,
211
+ });
212
+
213
+ const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
@@ -1,45 +1,45 @@
1
- import { IMetadataTag } from "../../metadata/IMetadataTag";
2
- import { Metadata } from "../../metadata/Metadata";
3
- import { IJsonSchema } from "../../schemas/IJsonSchema";
4
-
5
- import { application_default_string } from "./application_default_string";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const application_string = (
11
- meta: Metadata,
12
- attribute: IJsonSchema.IAttribute,
13
- ): IJsonSchema.IString => {
14
- const output: IJsonSchema.IString = {
15
- type: "string",
16
- nullable: meta.nullable,
17
- ...attribute,
18
- };
19
-
20
- // FORMAT TAG OF METADATA
21
- const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
22
- (tag) => tag.name === "format",
23
- );
24
- if (formatJsdocTag?.text?.length)
25
- output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
26
-
27
- // REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
28
- for (const tag of attribute["x-typia-metaTags"] ?? []) {
29
- // RANGE
30
- if (tag.kind === "minLength") output.minLength = tag.value;
31
- else if (tag.kind === "maxLength") output.maxLength = tag.value;
32
- // FORMAT AND PATTERN
33
- else if (tag.kind === "format") output.format = emendFormat(tag.value);
34
- else if (tag.kind === "pattern") output.pattern = tag.value;
35
- }
36
-
37
- // DEFAULT CONFIGURATION
38
- output.default = application_default_string(meta)(attribute)(output);
39
-
40
- // RETURNS
41
- return output;
42
- };
43
-
44
- const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
45
- tag === "datetime" ? "date-time" : tag;
1
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
2
+ import { Metadata } from "../../metadata/Metadata";
3
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
4
+
5
+ import { application_default_string } from "./application_default_string";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const application_string = (
11
+ meta: Metadata,
12
+ attribute: IJsonSchema.IAttribute,
13
+ ): IJsonSchema.IString => {
14
+ const output: IJsonSchema.IString = {
15
+ type: "string",
16
+ nullable: meta.nullable,
17
+ ...attribute,
18
+ };
19
+
20
+ // FORMAT TAG OF METADATA
21
+ const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
22
+ (tag) => tag.name === "format",
23
+ );
24
+ if (formatJsdocTag?.text?.length)
25
+ output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
26
+
27
+ // REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
28
+ for (const tag of attribute["x-typia-metaTags"] ?? []) {
29
+ // RANGE
30
+ if (tag.kind === "minLength") output.minLength = tag.value;
31
+ else if (tag.kind === "maxLength") output.maxLength = tag.value;
32
+ // FORMAT AND PATTERN
33
+ else if (tag.kind === "format") output.format = emendFormat(tag.value);
34
+ else if (tag.kind === "pattern") output.pattern = tag.value;
35
+ }
36
+
37
+ // DEFAULT CONFIGURATION
38
+ output.default = application_default_string(meta)(attribute)(output);
39
+
40
+ // RETURNS
41
+ return output;
42
+ };
43
+
44
+ const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
45
+ tag === "datetime" ? "date-time" : tag;
@@ -1,26 +1,26 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonSchema } from "../../schemas/IJsonSchema";
3
-
4
- import { application_default_string } from "./application_default_string";
5
- import { metadata_to_pattern } from "./metadata_to_pattern";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const application_templates =
11
- (meta: Metadata) =>
12
- (attribute: IJsonSchema.IAttribute): IJsonSchema.IString => {
13
- // CONSTRUCT PATTERN
14
- const output: IJsonSchema.IString = {
15
- type: "string",
16
- nullable: meta.nullable,
17
- ...attribute,
18
- };
19
- output.pattern = metadata_to_pattern(true)(meta);
20
-
21
- // DEFAULT VALUE
22
- output.default = application_default_string(meta)(attribute)(output);
23
-
24
- // RETURNS
25
- return output;
26
- };
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
3
+
4
+ import { application_default_string } from "./application_default_string";
5
+ import { metadata_to_pattern } from "./metadata_to_pattern";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const application_templates =
11
+ (meta: Metadata) =>
12
+ (attribute: IJsonSchema.IAttribute): IJsonSchema.IString => {
13
+ // CONSTRUCT PATTERN
14
+ const output: IJsonSchema.IString = {
15
+ type: "string",
16
+ nullable: meta.nullable,
17
+ ...attribute,
18
+ };
19
+ output.pattern = metadata_to_pattern(true)(meta);
20
+
21
+ // DEFAULT VALUE
22
+ output.default = application_default_string(meta)(attribute)(output);
23
+
24
+ // RETURNS
25
+ return output;
26
+ };
@@ -1,31 +1,31 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonComponents } from "../../schemas/IJsonComponents";
3
- import { IJsonSchema } from "../../schemas/IJsonSchema";
4
-
5
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
- import { application_schema } from "./application_schema";
7
-
8
- /**
9
- * @internal
10
- */
11
- export const application_tuple =
12
- (options: ApplicationProgrammer.IOptions) =>
13
- (components: IJsonComponents) =>
14
- (items: Array<Metadata>) =>
15
- (props: {
16
- nullable: boolean;
17
- attribute: IJsonSchema.IAttribute;
18
- }): IJsonSchema.ITuple => ({
19
- type: "array",
20
- items: items.map((meta, i) =>
21
- application_schema(options)(false)(components)(meta.rest ?? meta)({
22
- ...props.attribute,
23
- "x-typia-rest":
24
- i === items.length - 1 ? meta.rest !== null : undefined,
25
- "x-typia-required": meta.required,
26
- "x-typia-optional": meta.optional,
27
- }),
28
- ),
29
- nullable: props.nullable,
30
- ...props.attribute,
31
- });
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
3
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
4
+
5
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
+ import { application_schema } from "./application_schema";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export const application_tuple =
12
+ (options: ApplicationProgrammer.IOptions) =>
13
+ (components: IJsonComponents) =>
14
+ (items: Array<Metadata>) =>
15
+ (props: {
16
+ nullable: boolean;
17
+ attribute: IJsonSchema.IAttribute;
18
+ }): IJsonSchema.ITuple => ({
19
+ type: "array",
20
+ items: items.map((meta, i) =>
21
+ application_schema(options)(false)(components)(meta.rest ?? meta)({
22
+ ...props.attribute,
23
+ "x-typia-rest":
24
+ i === items.length - 1 ? meta.rest !== null : undefined,
25
+ "x-typia-required": meta.required,
26
+ "x-typia-optional": meta.optional,
27
+ }),
28
+ ),
29
+ nullable: props.nullable,
30
+ ...props.attribute,
31
+ });