typia 3.7.0-dev.20230310 → 3.7.0-dev.20230401

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 (267) hide show
  1. package/README.md +16 -45
  2. package/lib/IRandomGenerator.d.ts +2 -1
  3. package/lib/executable/TypiaSetupWizard.js +12 -2
  4. package/lib/executable/TypiaSetupWizard.js.map +1 -1
  5. package/lib/factories/MetadataCollection.d.ts +9 -1
  6. package/lib/factories/MetadataCollection.js +75 -2
  7. package/lib/factories/MetadataCollection.js.map +1 -1
  8. package/lib/factories/MetadataTagFactory.js +151 -132
  9. package/lib/factories/MetadataTagFactory.js.map +1 -1
  10. package/lib/factories/TypeFactory.js +1 -1
  11. package/lib/factories/TypeFactory.js.map +1 -1
  12. package/lib/factories/TypiaFileFactory.js +61 -54
  13. package/lib/factories/TypiaFileFactory.js.map +1 -1
  14. package/lib/functional/$dictionary.d.ts +1 -0
  15. package/lib/functional/$dictionary.js +14 -0
  16. package/lib/functional/$dictionary.js.map +1 -0
  17. package/lib/functional/$is_custom.d.ts +2 -0
  18. package/lib/functional/$is_custom.js +12 -0
  19. package/lib/functional/$is_custom.js.map +1 -0
  20. package/lib/functional/$is_date.d.ts +1 -0
  21. package/lib/functional/$is_date.js +9 -0
  22. package/lib/functional/$is_date.js.map +1 -0
  23. package/lib/functional/$is_datetime.d.ts +1 -0
  24. package/lib/functional/$is_datetime.js +8 -0
  25. package/lib/functional/$is_datetime.js.map +1 -0
  26. package/lib/functional/Namespace.js +6 -0
  27. package/lib/functional/Namespace.js.map +1 -1
  28. package/lib/metadata/IMetadataTag.d.ts +30 -38
  29. package/lib/metadata/Metadata.js +2 -2
  30. package/lib/metadata/Metadata.js.map +1 -1
  31. package/lib/module.d.ts +25 -2
  32. package/lib/module.js +12 -5
  33. package/lib/module.js.map +1 -1
  34. package/lib/programmers/AssertProgrammer.js +11 -0
  35. package/lib/programmers/AssertProgrammer.js.map +1 -1
  36. package/lib/programmers/CheckerProgrammer.d.ts +4 -2
  37. package/lib/programmers/CheckerProgrammer.js +26 -27
  38. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  39. package/lib/programmers/CloneProgrammer.js +2 -2
  40. package/lib/programmers/CloneProgrammer.js.map +1 -1
  41. package/lib/programmers/FeatureProgrammer.d.ts +3 -2
  42. package/lib/programmers/FeatureProgrammer.js +5 -5
  43. package/lib/programmers/FeatureProgrammer.js.map +1 -1
  44. package/lib/programmers/IsProgrammer.d.ts +1 -1
  45. package/lib/programmers/IsProgrammer.js +32 -2
  46. package/lib/programmers/IsProgrammer.js.map +1 -1
  47. package/lib/programmers/PruneProgrammer.js +2 -2
  48. package/lib/programmers/PruneProgrammer.js.map +1 -1
  49. package/lib/programmers/RandomProgrammer.js +1 -2
  50. package/lib/programmers/RandomProgrammer.js.map +1 -1
  51. package/lib/programmers/StringifyProgrammer.js +6 -6
  52. package/lib/programmers/StringifyProgrammer.js.map +1 -1
  53. package/lib/programmers/ValidateProgrammer.js +11 -0
  54. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  55. package/lib/programmers/helpers/ICheckEntry.d.ts +11 -0
  56. package/lib/{messages/IProtocolMap.js → programmers/helpers/ICheckEntry.js} +1 -1
  57. package/lib/programmers/helpers/ICheckEntry.js.map +1 -0
  58. package/lib/programmers/helpers/UnionExplorer.d.ts +7 -7
  59. package/lib/programmers/helpers/UnionExplorer.js +6 -6
  60. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  61. package/lib/programmers/internal/application_object.js +11 -11
  62. package/lib/programmers/internal/application_object.js.map +1 -1
  63. package/lib/programmers/internal/application_schema.js +3 -5
  64. package/lib/programmers/internal/application_schema.js.map +1 -1
  65. package/lib/programmers/internal/application_string.js +8 -5
  66. package/lib/programmers/internal/application_string.js.map +1 -1
  67. package/lib/programmers/internal/check_array.js +35 -10
  68. package/lib/programmers/internal/check_array.js.map +1 -1
  69. package/lib/programmers/internal/check_array_length.js +23 -36
  70. package/lib/programmers/internal/check_array_length.js.map +1 -1
  71. package/lib/programmers/internal/check_bigint.d.ts +1 -3
  72. package/lib/programmers/internal/check_bigint.js +92 -57
  73. package/lib/programmers/internal/check_bigint.js.map +1 -1
  74. package/lib/programmers/internal/check_custom.d.ts +5 -0
  75. package/lib/programmers/internal/check_custom.js +40 -0
  76. package/lib/programmers/internal/check_custom.js.map +1 -0
  77. package/lib/programmers/internal/check_number.js +126 -73
  78. package/lib/programmers/internal/check_number.js.map +1 -1
  79. package/lib/programmers/internal/check_string.js +10 -9
  80. package/lib/programmers/internal/check_string.js.map +1 -1
  81. package/lib/programmers/internal/check_string_tags.js +63 -24
  82. package/lib/programmers/internal/check_string_tags.js.map +1 -1
  83. package/lib/programmers/internal/check_template.js +23 -11
  84. package/lib/programmers/internal/check_template.js.map +1 -1
  85. package/lib/programmers/internal/check_union_array_like.d.ts +2 -2
  86. package/lib/programmers/internal/check_union_array_like.js +4 -4
  87. package/lib/programmers/internal/check_union_array_like.js.map +1 -1
  88. package/lib/programmers/internal/check_union_tuple.js +2 -2
  89. package/lib/programmers/internal/check_union_tuple.js.map +1 -1
  90. package/lib/programmers/internal/feature_object_entries.js +1 -1
  91. package/lib/programmers/internal/feature_object_entries.js.map +1 -1
  92. package/lib/transformers/CallExpressionTransformer.js +1 -3
  93. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  94. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +3 -1
  95. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  96. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js +1 -1
  97. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js.map +1 -1
  98. package/lib/transformers/features/miscellaneous/RandomTransformer.js +1 -1
  99. package/lib/transformers/features/miscellaneous/RandomTransformer.js.map +1 -1
  100. package/lib/transformers/internal/GenericTransformer.js +2 -2
  101. package/lib/transformers/internal/GenericTransformer.js.map +1 -1
  102. package/lib/typings/Customizable.d.ts +6 -0
  103. package/lib/{messages/IProtocolMessage.js → typings/Customizable.js} +1 -1
  104. package/lib/typings/Customizable.js.map +1 -0
  105. package/lib/utils/RandomGenerator.js +8 -2
  106. package/lib/utils/RandomGenerator.js.map +1 -1
  107. package/package.json +10 -9
  108. package/src/IRandomGenerator.ts +2 -1
  109. package/src/executable/TypiaSetupWizard.ts +16 -6
  110. package/src/factories/MetadataCollection.ts +41 -2
  111. package/src/factories/MetadataTagFactory.ts +186 -149
  112. package/src/factories/TypeFactory.ts +1 -1
  113. package/src/factories/TypiaFileFactory.ts +10 -7
  114. package/src/functional/$dictionary.ts +17 -0
  115. package/src/functional/$is_custom.ts +14 -0
  116. package/src/functional/$is_date.ts +4 -0
  117. package/src/functional/$is_datetime.ts +3 -0
  118. package/src/functional/Namespace.ts +6 -0
  119. package/src/metadata/IMetadataTag.ts +46 -70
  120. package/src/metadata/Metadata.ts +3 -6
  121. package/src/module.ts +39 -10
  122. package/src/programmers/AssertProgrammer.ts +24 -0
  123. package/src/programmers/CheckerProgrammer.ts +66 -37
  124. package/src/programmers/CloneProgrammer.ts +2 -0
  125. package/src/programmers/FeatureProgrammer.ts +12 -5
  126. package/src/programmers/IsProgrammer.ts +7 -1
  127. package/src/programmers/PruneProgrammer.ts +2 -0
  128. package/src/programmers/RandomProgrammer.ts +1 -4
  129. package/src/programmers/StringifyProgrammer.ts +6 -0
  130. package/src/programmers/ValidateProgrammer.ts +24 -0
  131. package/src/programmers/helpers/ICheckEntry.ts +12 -0
  132. package/src/programmers/helpers/UnionExplorer.ts +7 -0
  133. package/src/programmers/internal/application_object.ts +5 -5
  134. package/src/programmers/internal/application_schema.ts +3 -7
  135. package/src/programmers/internal/application_string.ts +6 -2
  136. package/src/programmers/internal/check_array.ts +15 -11
  137. package/src/programmers/internal/check_array_length.ts +31 -35
  138. package/src/programmers/internal/check_bigint.ts +76 -58
  139. package/src/programmers/internal/check_custom.ts +41 -0
  140. package/src/programmers/internal/check_number.ts +106 -77
  141. package/src/programmers/internal/check_string.ts +15 -14
  142. package/src/programmers/internal/check_string_tags.ts +23 -13
  143. package/src/programmers/internal/check_template.ts +16 -7
  144. package/src/programmers/internal/check_union_array_like.ts +5 -0
  145. package/src/programmers/internal/check_union_tuple.ts +2 -0
  146. package/src/programmers/internal/feature_object_entries.ts +1 -0
  147. package/src/transformers/CallExpressionTransformer.ts +9 -16
  148. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +3 -1
  149. package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +1 -1
  150. package/src/transformers/features/miscellaneous/RandomTransformer.ts +1 -1
  151. package/src/transformers/internal/GenericTransformer.ts +2 -2
  152. package/src/typings/Customizable.ts +6 -0
  153. package/src/utils/RandomGenerator.ts +8 -2
  154. package/lib/factories/ProtocolFactory.d.ts +0 -8
  155. package/lib/factories/ProtocolFactory.js +0 -112
  156. package/lib/factories/ProtocolFactory.js.map +0 -1
  157. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +0 -16
  158. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +0 -156
  159. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +0 -1
  160. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +0 -3
  161. package/lib/factories/internal/protocols/emplace_protocol_object.js +0 -47
  162. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +0 -1
  163. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +0 -4
  164. package/lib/factories/internal/protocols/emplace_protocol_property.js +0 -20
  165. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +0 -1
  166. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +0 -3
  167. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +0 -69
  168. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +0 -1
  169. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +0 -2
  170. package/lib/factories/internal/protocols/iterate_protocol_constant.js +0 -30
  171. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +0 -1
  172. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +0 -3
  173. package/lib/factories/internal/protocols/iterate_protocol_main.js +0 -17
  174. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +0 -1
  175. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +0 -4
  176. package/lib/factories/internal/protocols/iterate_protocol_map.js +0 -75
  177. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +0 -1
  178. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +0 -5
  179. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +0 -190
  180. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +0 -1
  181. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +0 -2
  182. package/lib/factories/internal/protocols/iterate_protocol_native.js +0 -33
  183. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +0 -1
  184. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +0 -1
  185. package/lib/factories/internal/protocols/iterate_protocol_never.js +0 -6
  186. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +0 -1
  187. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +0 -4
  188. package/lib/factories/internal/protocols/iterate_protocol_object.js +0 -157
  189. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +0 -1
  190. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +0 -5
  191. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +0 -25
  192. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +0 -1
  193. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +0 -3
  194. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +0 -46
  195. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +0 -1
  196. package/lib/functional/$proto_bytes.d.ts +0 -2
  197. package/lib/functional/$proto_bytes.js +0 -37
  198. package/lib/functional/$proto_bytes.js.map +0 -1
  199. package/lib/functional/$proto_field.d.ts +0 -10
  200. package/lib/functional/$proto_field.js +0 -42
  201. package/lib/functional/$proto_field.js.map +0 -1
  202. package/lib/functional/$proto_float.d.ts +0 -4
  203. package/lib/functional/$proto_float.js +0 -28
  204. package/lib/functional/$proto_float.js.map +0 -1
  205. package/lib/functional/$proto_i32.d.ts +0 -2
  206. package/lib/functional/$proto_i32.js +0 -23
  207. package/lib/functional/$proto_i32.js.map +0 -1
  208. package/lib/functional/$proto_i64.d.ts +0 -2
  209. package/lib/functional/$proto_i64.js +0 -31
  210. package/lib/functional/$proto_i64.js.map +0 -1
  211. package/lib/functional/$proto_size.d.ts +0 -6
  212. package/lib/functional/$proto_size.js +0 -76
  213. package/lib/functional/$proto_size.js.map +0 -1
  214. package/lib/functional/$proto_string.d.ts +0 -2
  215. package/lib/functional/$proto_string.js +0 -34
  216. package/lib/functional/$proto_string.js.map +0 -1
  217. package/lib/functional/$varint.d.ts +0 -6
  218. package/lib/functional/$varint.js +0 -99
  219. package/lib/functional/$varint.js.map +0 -1
  220. package/lib/functional/$zigzag.d.ts +0 -4
  221. package/lib/functional/$zigzag.js +0 -34
  222. package/lib/functional/$zigzag.js.map +0 -1
  223. package/lib/messages/IProtocolMap.d.ts +0 -5
  224. package/lib/messages/IProtocolMap.js.map +0 -1
  225. package/lib/messages/IProtocolMessage.d.ts +0 -5
  226. package/lib/messages/IProtocolMessage.js.map +0 -1
  227. package/lib/messages/IProtocolProperty.d.ts +0 -12
  228. package/lib/messages/IProtocolProperty.js +0 -3
  229. package/lib/messages/IProtocolProperty.js.map +0 -1
  230. package/lib/programmers/MessageProgrammer.d.ts +0 -5
  231. package/lib/programmers/MessageProgrammer.js +0 -141
  232. package/lib/programmers/MessageProgrammer.js.map +0 -1
  233. package/lib/transformers/features/protocols/MessageTransformer.d.ts +0 -5
  234. package/lib/transformers/features/protocols/MessageTransformer.js +0 -17
  235. package/lib/transformers/features/protocols/MessageTransformer.js.map +0 -1
  236. package/lib/utils/NameEncoder.d.ts +0 -4
  237. package/lib/utils/NameEncoder.js +0 -89
  238. package/lib/utils/NameEncoder.js.map +0 -1
  239. package/src/factories/ProtocolFactory.ts +0 -79
  240. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +0 -163
  241. package/src/factories/internal/protocols/emplace_protocol_object.ts +0 -25
  242. package/src/factories/internal/protocols/emplace_protocol_property.ts +0 -12
  243. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +0 -34
  244. package/src/factories/internal/protocols/iterate_protocol_constant.ts +0 -27
  245. package/src/factories/internal/protocols/iterate_protocol_main.ts +0 -19
  246. package/src/factories/internal/protocols/iterate_protocol_map.ts +0 -58
  247. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +0 -96
  248. package/src/factories/internal/protocols/iterate_protocol_native.ts +0 -34
  249. package/src/factories/internal/protocols/iterate_protocol_never.ts +0 -1
  250. package/src/factories/internal/protocols/iterate_protocol_object.ts +0 -110
  251. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +0 -34
  252. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +0 -29
  253. package/src/functional/$proto_bytes.ts +0 -25
  254. package/src/functional/$proto_field.ts +0 -30
  255. package/src/functional/$proto_float.ts +0 -37
  256. package/src/functional/$proto_i32.ts +0 -29
  257. package/src/functional/$proto_i64.ts +0 -37
  258. package/src/functional/$proto_size.ts +0 -82
  259. package/src/functional/$proto_string.ts +0 -24
  260. package/src/functional/$varint.ts +0 -130
  261. package/src/functional/$zigzag.ts +0 -39
  262. package/src/messages/IProtocolMap.ts +0 -5
  263. package/src/messages/IProtocolMessage.ts +0 -6
  264. package/src/messages/IProtocolProperty.ts +0 -13
  265. package/src/programmers/MessageProgrammer.ts +0 -126
  266. package/src/transformers/features/protocols/MessageTransformer.ts +0 -32
  267. package/src/utils/NameEncoder.ts +0 -32
@@ -28,7 +28,7 @@ export namespace MetadataTagFactory {
28
28
  tag: ts.JSDocTagInfo,
29
29
  output: IMetadataTag[],
30
30
  ): IMetadataTag | null {
31
- const closure = PARSER[tag.name];
31
+ const closure = _PARSER[tag.name];
32
32
  if (closure === undefined) return null;
33
33
 
34
34
  const text = (tag.text || [])[0]?.text;
@@ -37,166 +37,193 @@ export namespace MetadataTagFactory {
37
37
 
38
38
  return closure(identifier, metadata, text, output);
39
39
  }
40
- }
41
40
 
42
- const PARSER: Record<
43
- string,
44
- (
45
- identifier: () => string,
46
- metadata: Metadata,
47
- text: string,
48
- output: IMetadataTag[],
49
- ) => IMetadataTag | null
50
- > = {
51
- /* -----------------------------------------------------------
41
+ /**
42
+ * @internal
43
+ */
44
+ export const _PARSER: Record<
45
+ string,
46
+ (
47
+ identifier: () => string,
48
+ metadata: Metadata,
49
+ text: string,
50
+ output: IMetadataTag[],
51
+ ) => IMetadataTag | null
52
+ > = {
53
+ /* -----------------------------------------------------------
52
54
  ARRAY
53
55
  ----------------------------------------------------------- */
54
- items: (identifier, metadata, text, output) => {
55
- validate(identifier, metadata, output, "items", "array", ["minItems"]);
56
- return {
57
- kind: "items",
58
- value: parse_number(identifier, text),
59
- };
60
- },
61
- minItems: (identifier, metadata, text, output) => {
62
- validate(identifier, metadata, output, "minItems", "array", ["items"]);
63
- return {
64
- kind: "minItems",
65
- value: parse_number(identifier, text),
66
- };
67
- },
68
- maxItems: (identifier, metadata, text, output) => {
69
- validate(identifier, metadata, output, "maxItems", "array", ["items"]);
70
- return {
71
- kind: "maxItems",
72
- value: parse_number(identifier, text),
73
- };
74
- },
56
+ items: (identifier, metadata, text, output) => {
57
+ validate(identifier, metadata, output, "items", "array", [
58
+ "minItems",
59
+ ]);
60
+ return {
61
+ kind: "items",
62
+ value: parse_number(identifier, text),
63
+ };
64
+ },
65
+ minItems: (identifier, metadata, text, output) => {
66
+ validate(identifier, metadata, output, "minItems", "array", [
67
+ "items",
68
+ ]);
69
+ return {
70
+ kind: "minItems",
71
+ value: parse_number(identifier, text),
72
+ };
73
+ },
74
+ maxItems: (identifier, metadata, text, output) => {
75
+ validate(identifier, metadata, output, "maxItems", "array", [
76
+ "items",
77
+ ]);
78
+ return {
79
+ kind: "maxItems",
80
+ value: parse_number(identifier, text),
81
+ };
82
+ },
75
83
 
76
- /* -----------------------------------------------------------
84
+ /* -----------------------------------------------------------
77
85
  NUMBER
78
86
  ----------------------------------------------------------- */
79
- type: (identifier, metadata, text, output) => {
80
- validate(identifier, metadata, output, "type", "number", []);
81
- if (text !== "int" && text !== "uint")
82
- throw new Error(`${LABEL}: invalid type tag on "${identifier()}".`);
83
- return { kind: "type", value: text };
84
- },
85
- minimum: (identifier, metadata, text, output) => {
86
- validate(identifier, metadata, output, "minimum", "number", [
87
- "exclusiveMinimum",
88
- ]);
89
- return {
90
- kind: "minimum",
91
- value: parse_number(identifier, text),
92
- };
93
- },
94
- maximum: (identifier, metadata, text, output) => {
95
- validate(identifier, metadata, output, "maximum", "number", [
96
- "exclusiveMaximum",
97
- ]);
98
- return {
99
- kind: "maximum",
100
- value: parse_number(identifier, text),
101
- };
102
- },
103
- exclusiveMinimum: (identifier, metadata, text, output) => {
104
- validate(identifier, metadata, output, "exclusiveMinimum", "number", [
105
- "minimum",
106
- ]);
107
- return {
108
- kind: "exclusiveMinimum",
109
- value: parse_number(identifier, text),
110
- };
111
- },
112
- exclusiveMaximum: (identifier, metadata, text, output) => {
113
- validate(identifier, metadata, output, "exclusiveMaximum", "number", [
114
- "maximum",
115
- ]);
116
- return {
117
- kind: "exclusiveMaximum",
118
- value: parse_number(identifier, text),
119
- };
120
- },
121
- multipleOf: (identifier, metadata, text, output) => {
122
- validate(identifier, metadata, output, "multipleOf", "number", [
123
- "step",
124
- ]);
125
- return {
126
- kind: "multipleOf",
127
- value: parse_number(identifier, text),
128
- };
129
- },
130
- step: (identifier, metadata, text, output) => {
131
- validate(identifier, metadata, output, "step", "number", [
132
- "multipleOf",
133
- ]);
87
+ type: (identifier, metadata, text, output) => {
88
+ validate(identifier, metadata, output, "type", "number", []);
89
+ if (text !== "int" && text !== "uint")
90
+ throw new Error(
91
+ `${LABEL}: invalid type tag on "${identifier()}".`,
92
+ );
93
+ return { kind: "type", value: text };
94
+ },
95
+ minimum: (identifier, metadata, text, output) => {
96
+ validate(identifier, metadata, output, "minimum", "number", [
97
+ "exclusiveMinimum",
98
+ ]);
99
+ return {
100
+ kind: "minimum",
101
+ value: parse_number(identifier, text),
102
+ };
103
+ },
104
+ maximum: (identifier, metadata, text, output) => {
105
+ validate(identifier, metadata, output, "maximum", "number", [
106
+ "exclusiveMaximum",
107
+ ]);
108
+ return {
109
+ kind: "maximum",
110
+ value: parse_number(identifier, text),
111
+ };
112
+ },
113
+ exclusiveMinimum: (identifier, metadata, text, output) => {
114
+ validate(
115
+ identifier,
116
+ metadata,
117
+ output,
118
+ "exclusiveMinimum",
119
+ "number",
120
+ ["minimum"],
121
+ );
122
+ return {
123
+ kind: "exclusiveMinimum",
124
+ value: parse_number(identifier, text),
125
+ };
126
+ },
127
+ exclusiveMaximum: (identifier, metadata, text, output) => {
128
+ validate(
129
+ identifier,
130
+ metadata,
131
+ output,
132
+ "exclusiveMaximum",
133
+ "number",
134
+ ["maximum"],
135
+ );
136
+ return {
137
+ kind: "exclusiveMaximum",
138
+ value: parse_number(identifier, text),
139
+ };
140
+ },
141
+ multipleOf: (identifier, metadata, text, output) => {
142
+ validate(identifier, metadata, output, "multipleOf", "number", [
143
+ "step",
144
+ ]);
145
+ return {
146
+ kind: "multipleOf",
147
+ value: parse_number(identifier, text),
148
+ };
149
+ },
150
+ step: (identifier, metadata, text, output) => {
151
+ validate(identifier, metadata, output, "step", "number", [
152
+ "multipleOf",
153
+ ]);
134
154
 
135
- const minimum: boolean = output.some(
136
- (tag) => tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
137
- );
138
- if (minimum === undefined)
139
- throw new Error(
140
- `${LABEL}: step requires minimum or exclusiveMinimum tag on "${identifier()}".`,
155
+ const minimum: boolean = output.some(
156
+ (tag) =>
157
+ tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
141
158
  );
159
+ if (minimum === undefined)
160
+ throw new Error(
161
+ `${LABEL}: step requires minimum or exclusiveMinimum tag on "${identifier()}".`,
162
+ );
142
163
 
143
- return {
144
- kind: "step",
145
- value: parse_number(identifier, text),
146
- };
147
- },
164
+ return {
165
+ kind: "step",
166
+ value: parse_number(identifier, text),
167
+ };
168
+ },
148
169
 
149
- /* -----------------------------------------------------------
170
+ /* -----------------------------------------------------------
150
171
  STRING
151
172
  ----------------------------------------------------------- */
152
- format: (identifier, metadata, value, output) => {
153
- validate(identifier, metadata, output, "format", "string", ["pattern"]);
173
+ format: (identifier, metadata, str, output) => {
174
+ validate(identifier, metadata, output, "format", "string", [
175
+ "pattern",
176
+ ]);
154
177
 
155
- // Ignore arbitrary @format values in the internal metadata,
156
- // these are currently only supported on the typia.application() API.
157
- if (FORMATS.has(value) === false) return null;
158
-
159
- return {
160
- kind: "format",
161
- value: value as "uuid",
162
- };
163
- },
164
- pattern: (identifier, metadata, value, output) => {
165
- validate(identifier, metadata, output, "pattern", "string", ["format"]);
166
- return {
167
- kind: "pattern",
168
- value,
169
- };
170
- },
171
- length: (identifier, metadata, text, output) => {
172
- validate(identifier, metadata, output, "length", "string", [
173
- "minLength",
174
- "maxLength",
175
- ]);
176
- return {
177
- kind: "length",
178
- value: parse_number(identifier, text),
179
- };
180
- },
181
- minLength: (identifier, metadata, text, output) => {
182
- validate(identifier, metadata, output, "minLength", "string", [
183
- "length",
184
- ]);
185
- return {
186
- kind: "minLength",
187
- value: parse_number(identifier, text),
188
- };
189
- },
190
- maxLength: (identifier, metadata, text, output) => {
191
- validate(identifier, metadata, output, "maxLength", "string", [
192
- "length",
193
- ]);
194
- return {
195
- kind: "maxLength",
196
- value: parse_number(identifier, text),
197
- };
198
- },
199
- };
178
+ // Ignore arbitrary @format values in the internal metadata,
179
+ // these are currently only supported on the typia.application() API.
180
+ const value: IMetadataTag.IFormat["value"] | undefined =
181
+ FORMATS.get(str);
182
+ if (value === undefined) return null;
183
+ return {
184
+ kind: "format",
185
+ value,
186
+ };
187
+ },
188
+ pattern: (identifier, metadata, value, output) => {
189
+ validate(identifier, metadata, output, "pattern", "string", [
190
+ "format",
191
+ ]);
192
+ return {
193
+ kind: "pattern",
194
+ value,
195
+ };
196
+ },
197
+ length: (identifier, metadata, text, output) => {
198
+ validate(identifier, metadata, output, "length", "string", [
199
+ "minLength",
200
+ "maxLength",
201
+ ]);
202
+ return {
203
+ kind: "length",
204
+ value: parse_number(identifier, text),
205
+ };
206
+ },
207
+ minLength: (identifier, metadata, text, output) => {
208
+ validate(identifier, metadata, output, "minLength", "string", [
209
+ "length",
210
+ ]);
211
+ return {
212
+ kind: "minLength",
213
+ value: parse_number(identifier, text),
214
+ };
215
+ },
216
+ maxLength: (identifier, metadata, text, output) => {
217
+ validate(identifier, metadata, output, "maxLength", "string", [
218
+ "length",
219
+ ]);
220
+ return {
221
+ kind: "maxLength",
222
+ value: parse_number(identifier, text),
223
+ };
224
+ },
225
+ };
226
+ }
200
227
 
201
228
  function parse_number(identifier: () => string, str: string): number {
202
229
  const value: number = Number(str);
@@ -206,7 +233,17 @@ function parse_number(identifier: () => string, str: string): number {
206
233
  }
207
234
 
208
235
  const LABEL = "Error on typia.MetadataTagFactory.generate()";
209
- const FORMATS = new Set(["uuid", "email", "url", "mobile", "ipv4", "ipv6"]);
236
+ const FORMATS: Map<string, IMetadataTag.IFormat["value"]> = new Map([
237
+ ["uuid", "uuid"],
238
+ ["email", "email"],
239
+ ["url", "url"],
240
+ ["ipv4", "ipv4"],
241
+ ["ipv6", "ipv6"],
242
+ ["date", "date"],
243
+ ["datetime", "datetime"],
244
+ ["date-time", "datetime"],
245
+ ["dateTime", "datetime"],
246
+ ]);
210
247
 
211
248
  const WRONG_TYPE = (
212
249
  tag: string,
@@ -87,7 +87,7 @@ export namespace TypeFactory {
87
87
  function explore_name(name: string, decl: ts.Node): string {
88
88
  return ts.isModuleBlock(decl)
89
89
  ? explore_name(
90
- `${decl.parent.name.getText()}.${name}`,
90
+ `${decl.parent.name.getFullText().trim()}.${name}`,
91
91
  decl.parent.parent,
92
92
  )
93
93
  : name;
@@ -40,7 +40,7 @@ export namespace TypiaFileFactory {
40
40
  const program: ts.Program = ts.createProgram(
41
41
  await (async () => {
42
42
  const container: string[] = [];
43
- await gather(container)(props.input)(props.output);
43
+ await gather(props)(container)(props.input)(props.output);
44
44
  return container;
45
45
  })(),
46
46
  config.compilerOptions,
@@ -99,19 +99,22 @@ export namespace TypiaFileFactory {
99
99
  };
100
100
 
101
101
  const gather =
102
- (container: string[]) => (from: string) => async (to: string) => {
103
- if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
104
- const directory: string[] = await fs.promises.readdir(from);
105
- for (const file of directory) {
102
+ (props: IProps) =>
103
+ (container: string[]) =>
104
+ (from: string) =>
105
+ async (to: string) => {
106
+ if (from === props.output) return;
107
+ else if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
108
+
109
+ for (const file of await fs.promises.readdir(from)) {
106
110
  const next: string = path.join(from, file);
107
111
  const stat: fs.Stats = await fs.promises.stat(next);
108
112
 
109
113
  if (stat.isDirectory()) {
110
- await gather(container)(next)(path.join(to, file));
114
+ await gather(props)(container)(next)(path.join(to, file));
111
115
  continue;
112
116
  } else if (file.substring(file.length - 3) === ".ts")
113
117
  container.push(next);
114
118
  }
115
- return container;
116
119
  };
117
120
  }
@@ -0,0 +1,17 @@
1
+ import { Customizable } from "../typings/Customizable";
2
+
3
+ export const $dictionary = (() => {
4
+ const glob: {
5
+ __typia_custom_validator: Map<
6
+ `${string}:${keyof Customizable}`,
7
+ (tagText: string) => (value: any) => boolean
8
+ >;
9
+ } =
10
+ typeof global === "object" &&
11
+ typeof global.process === "object" &&
12
+ typeof global.process.versions === "object" &&
13
+ typeof global.process.versions.node !== "undefined"
14
+ ? (global as any)
15
+ : (window as any);
16
+ return (glob.__typia_custom_validator ??= new Map());
17
+ })();
@@ -0,0 +1,14 @@
1
+ import { Customizable } from "../typings/Customizable";
2
+
3
+ import { $dictionary } from "./$dictionary";
4
+
5
+ export function $is_custom<Type extends keyof Customizable>(
6
+ name: string,
7
+ type: Type,
8
+ text: string,
9
+ value: Customizable[Type],
10
+ ): boolean {
11
+ const validator = $dictionary.get(`${name}:${type}`);
12
+ if (validator === undefined) return true;
13
+ return validator(text)(value);
14
+ }
@@ -0,0 +1,4 @@
1
+ export function $is_date(value: string): boolean {
2
+ return REGEX.test(value);
3
+ }
4
+ const REGEX = /^(\d{4})-(\d{2})-(\d{2})$/;
@@ -0,0 +1,3 @@
1
+ export function $is_datetime(value: string): boolean {
2
+ return !isNaN(new Date(value).getTime());
3
+ }
@@ -6,6 +6,9 @@ import { $any } from "./$any";
6
6
  import { $every } from "./$every";
7
7
  import { $guard } from "./$guard";
8
8
  import { $is_between } from "./$is_between";
9
+ import { $is_custom } from "./$is_custom";
10
+ import { $is_date } from "./$is_date";
11
+ import { $is_datetime } from "./$is_datetime";
9
12
  import { $is_email } from "./$is_email";
10
13
  import { $is_ipv4 } from "./$is_ipv4";
11
14
  import { $is_ipv6 } from "./$is_ipv6";
@@ -29,6 +32,9 @@ export namespace Namespace {
29
32
  is_ipv4: $is_ipv4,
30
33
  is_ipv6: $is_ipv6,
31
34
  is_between: $is_between,
35
+ is_date: $is_date,
36
+ is_datetime: $is_datetime,
37
+ is_custom: $is_custom,
32
38
  });
33
39
 
34
40
  export const assert = (method: string) => ({
@@ -1,42 +1,59 @@
1
1
  export type IMetadataTag =
2
- // ARRAY
3
- | IMetadataTag.IItems
4
- | IMetadataTag.IMinItems
5
- | IMetadataTag.IMaxItems
6
- // STRING
7
- | IMetadataTag.IFormat
8
- | IMetadataTag.IPattern
9
- | IMetadataTag.ILength
10
- | IMetadataTag.IMinLength
11
- | IMetadataTag.IMaxLength
12
2
  // NUMBER
13
- | IMetadataTag.INumberType
14
- | IMetadataTag.IBigintType
3
+ | IMetadataTag.IType
15
4
  | IMetadataTag.IMinimum
16
5
  | IMetadataTag.IMaximum
17
6
  | IMetadataTag.IExclusiveMinimum
18
7
  | IMetadataTag.IExclusiveMaximum
19
8
  | IMetadataTag.IMultipleOf
20
9
  | IMetadataTag.IStep
21
- // BIGINT
22
- | IMetadataTag.IBigintType;
10
+ // STRING
11
+ | IMetadataTag.IFormat
12
+ | IMetadataTag.IPattern
13
+ | IMetadataTag.ILength
14
+ | IMetadataTag.IMinLength
15
+ | IMetadataTag.IMaxLength
16
+ // ARRAY
17
+ | IMetadataTag.IItems
18
+ | IMetadataTag.IMinItems
19
+ | IMetadataTag.IMaxItems;
23
20
 
24
21
  export namespace IMetadataTag {
25
22
  /* -----------------------------------------------------------
26
- ARRAY
23
+ NUMBER
27
24
  ----------------------------------------------------------- */
28
- export interface IItems {
29
- kind: "items";
25
+ export interface IType {
26
+ kind: "type";
27
+ value: "int" | "uint";
28
+ }
29
+
30
+ export interface IMinimum {
31
+ kind: "minimum";
30
32
  value: number;
31
33
  }
32
34
 
33
- export interface IMinItems {
34
- kind: "minItems";
35
+ export interface IMaximum {
36
+ kind: "maximum";
35
37
  value: number;
36
38
  }
37
39
 
38
- export interface IMaxItems {
39
- kind: "maxItems";
40
+ export interface IExclusiveMinimum {
41
+ kind: "exclusiveMinimum";
42
+ value: number;
43
+ }
44
+
45
+ export interface IExclusiveMaximum {
46
+ kind: "exclusiveMaximum";
47
+ value: number;
48
+ }
49
+
50
+ export interface IMultipleOf {
51
+ kind: "multipleOf";
52
+ value: number;
53
+ }
54
+
55
+ export interface IStep {
56
+ kind: "step";
40
57
  value: number;
41
58
  }
42
59
 
@@ -45,7 +62,7 @@ export namespace IMetadataTag {
45
62
  ----------------------------------------------------------- */
46
63
  export interface IFormat {
47
64
  kind: "format";
48
- value: "uuid" | "email" | "url" | "ipv4" | "ipv6";
65
+ value: "uuid" | "email" | "url" | "ipv4" | "ipv6" | "date" | "datetime";
49
66
  }
50
67
 
51
68
  export interface IPattern {
@@ -69,61 +86,20 @@ export namespace IMetadataTag {
69
86
  }
70
87
 
71
88
  /* -----------------------------------------------------------
72
- NUMBER
89
+ ARRAY
73
90
  ----------------------------------------------------------- */
74
- export interface INumberType {
75
- kind: "type";
76
- value:
77
- | "int"
78
- | "uint"
79
- | "int32"
80
- | "uint32"
81
- | "int64"
82
- | "uint64"
83
- | "float"
84
- | "double";
85
- }
86
-
87
- export interface IMinimum {
88
- kind: "minimum";
89
- value: number;
90
- }
91
-
92
- export interface IMaximum {
93
- kind: "maximum";
94
- value: number;
95
- }
96
-
97
- export interface IExclusiveMinimum {
98
- kind: "exclusiveMinimum";
99
- value: number;
100
- }
101
-
102
- export interface IExclusiveMaximum {
103
- kind: "exclusiveMaximum";
104
- value: number;
105
- }
106
-
107
- export interface IMultipleOf {
108
- kind: "multipleOf";
91
+ export interface IItems {
92
+ kind: "items";
109
93
  value: number;
110
94
  }
111
95
 
112
- export interface IStep {
113
- kind: "step";
96
+ export interface IMinItems {
97
+ kind: "minItems";
114
98
  value: number;
115
99
  }
116
100
 
117
- /* -----------------------------------------------------------
118
- MISCELLANEOUS
119
- ----------------------------------------------------------- */
120
- export interface IBigintType {
121
- kind: "type";
122
- value: "int64" | "uint64";
123
- }
124
-
125
- export interface ISign {
126
- include: boolean;
101
+ export interface IMaxItems {
102
+ kind: "maxItems";
127
103
  value: number;
128
104
  }
129
105
  }