typia 3.7.0-dev.20230310 → 3.7.0-dev.20230331

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 (249) 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/CheckerProgrammer.d.ts +2 -2
  35. package/lib/programmers/CheckerProgrammer.js +22 -22
  36. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  37. package/lib/programmers/CloneProgrammer.js +2 -2
  38. package/lib/programmers/CloneProgrammer.js.map +1 -1
  39. package/lib/programmers/FeatureProgrammer.d.ts +3 -2
  40. package/lib/programmers/FeatureProgrammer.js +5 -5
  41. package/lib/programmers/FeatureProgrammer.js.map +1 -1
  42. package/lib/programmers/IsProgrammer.d.ts +1 -1
  43. package/lib/programmers/IsProgrammer.js +2 -2
  44. package/lib/programmers/IsProgrammer.js.map +1 -1
  45. package/lib/programmers/PruneProgrammer.js +2 -2
  46. package/lib/programmers/PruneProgrammer.js.map +1 -1
  47. package/lib/programmers/RandomProgrammer.js +1 -2
  48. package/lib/programmers/RandomProgrammer.js.map +1 -1
  49. package/lib/programmers/StringifyProgrammer.js +6 -6
  50. package/lib/programmers/StringifyProgrammer.js.map +1 -1
  51. package/lib/programmers/helpers/UnionExplorer.d.ts +7 -7
  52. package/lib/programmers/helpers/UnionExplorer.js +6 -6
  53. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  54. package/lib/programmers/internal/application_object.js +11 -11
  55. package/lib/programmers/internal/application_object.js.map +1 -1
  56. package/lib/programmers/internal/application_schema.js +3 -5
  57. package/lib/programmers/internal/application_schema.js.map +1 -1
  58. package/lib/programmers/internal/application_string.js +8 -5
  59. package/lib/programmers/internal/application_string.js.map +1 -1
  60. package/lib/programmers/internal/check_array.js +36 -7
  61. package/lib/programmers/internal/check_array.js.map +1 -1
  62. package/lib/programmers/internal/check_bigint.d.ts +3 -1
  63. package/lib/programmers/internal/check_bigint.js +90 -61
  64. package/lib/programmers/internal/check_bigint.js.map +1 -1
  65. package/lib/programmers/internal/check_custom.d.ts +4 -0
  66. package/lib/programmers/internal/check_custom.js +30 -0
  67. package/lib/programmers/internal/check_custom.js.map +1 -0
  68. package/lib/programmers/internal/check_number.js +104 -75
  69. package/lib/programmers/internal/check_number.js.map +1 -1
  70. package/lib/programmers/internal/check_string.js +4 -3
  71. package/lib/programmers/internal/check_string.js.map +1 -1
  72. package/lib/programmers/internal/check_union_array_like.d.ts +2 -2
  73. package/lib/programmers/internal/check_union_array_like.js +4 -4
  74. package/lib/programmers/internal/check_union_array_like.js.map +1 -1
  75. package/lib/programmers/internal/check_union_tuple.js +2 -2
  76. package/lib/programmers/internal/check_union_tuple.js.map +1 -1
  77. package/lib/programmers/internal/feature_object_entries.js +1 -1
  78. package/lib/programmers/internal/feature_object_entries.js.map +1 -1
  79. package/lib/transformers/CallExpressionTransformer.js +1 -3
  80. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  81. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +3 -1
  82. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  83. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js +1 -1
  84. package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js.map +1 -1
  85. package/lib/transformers/features/miscellaneous/RandomTransformer.js +1 -1
  86. package/lib/transformers/features/miscellaneous/RandomTransformer.js.map +1 -1
  87. package/lib/transformers/internal/GenericTransformer.js +2 -2
  88. package/lib/transformers/internal/GenericTransformer.js.map +1 -1
  89. package/lib/typings/Customizable.d.ts +7 -0
  90. package/lib/{messages/IProtocolMap.js → typings/Customizable.js} +1 -1
  91. package/lib/typings/Customizable.js.map +1 -0
  92. package/lib/utils/RandomGenerator.js +8 -2
  93. package/lib/utils/RandomGenerator.js.map +1 -1
  94. package/package.json +10 -9
  95. package/src/IRandomGenerator.ts +2 -1
  96. package/src/executable/TypiaSetupWizard.ts +16 -6
  97. package/src/factories/MetadataCollection.ts +41 -2
  98. package/src/factories/MetadataTagFactory.ts +186 -149
  99. package/src/factories/TypeFactory.ts +1 -1
  100. package/src/factories/TypiaFileFactory.ts +10 -7
  101. package/src/functional/$dictionary.ts +17 -0
  102. package/src/functional/$is_custom.ts +14 -0
  103. package/src/functional/$is_date.ts +4 -0
  104. package/src/functional/$is_datetime.ts +3 -0
  105. package/src/functional/Namespace.ts +6 -0
  106. package/src/metadata/IMetadataTag.ts +46 -70
  107. package/src/metadata/Metadata.ts +3 -6
  108. package/src/module.ts +39 -10
  109. package/src/programmers/CheckerProgrammer.ts +44 -14
  110. package/src/programmers/CloneProgrammer.ts +2 -0
  111. package/src/programmers/FeatureProgrammer.ts +12 -5
  112. package/src/programmers/IsProgrammer.ts +2 -1
  113. package/src/programmers/PruneProgrammer.ts +2 -0
  114. package/src/programmers/RandomProgrammer.ts +1 -4
  115. package/src/programmers/StringifyProgrammer.ts +6 -0
  116. package/src/programmers/helpers/UnionExplorer.ts +7 -0
  117. package/src/programmers/internal/application_object.ts +5 -5
  118. package/src/programmers/internal/application_schema.ts +3 -7
  119. package/src/programmers/internal/application_string.ts +6 -2
  120. package/src/programmers/internal/check_array.ts +19 -10
  121. package/src/programmers/internal/check_bigint.ts +77 -57
  122. package/src/programmers/internal/check_custom.ts +32 -0
  123. package/src/programmers/internal/check_number.ts +16 -6
  124. package/src/programmers/internal/check_string.ts +8 -2
  125. package/src/programmers/internal/check_union_array_like.ts +5 -0
  126. package/src/programmers/internal/check_union_tuple.ts +2 -0
  127. package/src/programmers/internal/feature_object_entries.ts +1 -0
  128. package/src/transformers/CallExpressionTransformer.ts +9 -16
  129. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +3 -1
  130. package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +1 -1
  131. package/src/transformers/features/miscellaneous/RandomTransformer.ts +1 -1
  132. package/src/transformers/internal/GenericTransformer.ts +2 -2
  133. package/src/typings/Customizable.ts +7 -0
  134. package/src/utils/RandomGenerator.ts +8 -2
  135. package/lib/factories/ProtocolFactory.d.ts +0 -8
  136. package/lib/factories/ProtocolFactory.js +0 -112
  137. package/lib/factories/ProtocolFactory.js.map +0 -1
  138. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +0 -16
  139. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +0 -156
  140. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +0 -1
  141. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +0 -3
  142. package/lib/factories/internal/protocols/emplace_protocol_object.js +0 -47
  143. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +0 -1
  144. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +0 -4
  145. package/lib/factories/internal/protocols/emplace_protocol_property.js +0 -20
  146. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +0 -1
  147. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +0 -3
  148. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +0 -69
  149. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +0 -1
  150. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +0 -2
  151. package/lib/factories/internal/protocols/iterate_protocol_constant.js +0 -30
  152. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +0 -1
  153. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +0 -3
  154. package/lib/factories/internal/protocols/iterate_protocol_main.js +0 -17
  155. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +0 -1
  156. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +0 -4
  157. package/lib/factories/internal/protocols/iterate_protocol_map.js +0 -75
  158. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +0 -1
  159. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +0 -5
  160. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +0 -190
  161. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +0 -1
  162. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +0 -2
  163. package/lib/factories/internal/protocols/iterate_protocol_native.js +0 -33
  164. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +0 -1
  165. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +0 -1
  166. package/lib/factories/internal/protocols/iterate_protocol_never.js +0 -6
  167. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +0 -1
  168. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +0 -4
  169. package/lib/factories/internal/protocols/iterate_protocol_object.js +0 -157
  170. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +0 -1
  171. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +0 -5
  172. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +0 -25
  173. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +0 -1
  174. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +0 -3
  175. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +0 -46
  176. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +0 -1
  177. package/lib/functional/$proto_bytes.d.ts +0 -2
  178. package/lib/functional/$proto_bytes.js +0 -37
  179. package/lib/functional/$proto_bytes.js.map +0 -1
  180. package/lib/functional/$proto_field.d.ts +0 -10
  181. package/lib/functional/$proto_field.js +0 -42
  182. package/lib/functional/$proto_field.js.map +0 -1
  183. package/lib/functional/$proto_float.d.ts +0 -4
  184. package/lib/functional/$proto_float.js +0 -28
  185. package/lib/functional/$proto_float.js.map +0 -1
  186. package/lib/functional/$proto_i32.d.ts +0 -2
  187. package/lib/functional/$proto_i32.js +0 -23
  188. package/lib/functional/$proto_i32.js.map +0 -1
  189. package/lib/functional/$proto_i64.d.ts +0 -2
  190. package/lib/functional/$proto_i64.js +0 -31
  191. package/lib/functional/$proto_i64.js.map +0 -1
  192. package/lib/functional/$proto_size.d.ts +0 -6
  193. package/lib/functional/$proto_size.js +0 -76
  194. package/lib/functional/$proto_size.js.map +0 -1
  195. package/lib/functional/$proto_string.d.ts +0 -2
  196. package/lib/functional/$proto_string.js +0 -34
  197. package/lib/functional/$proto_string.js.map +0 -1
  198. package/lib/functional/$varint.d.ts +0 -6
  199. package/lib/functional/$varint.js +0 -99
  200. package/lib/functional/$varint.js.map +0 -1
  201. package/lib/functional/$zigzag.d.ts +0 -4
  202. package/lib/functional/$zigzag.js +0 -34
  203. package/lib/functional/$zigzag.js.map +0 -1
  204. package/lib/messages/IProtocolMap.d.ts +0 -5
  205. package/lib/messages/IProtocolMap.js.map +0 -1
  206. package/lib/messages/IProtocolMessage.d.ts +0 -5
  207. package/lib/messages/IProtocolMessage.js +0 -3
  208. package/lib/messages/IProtocolMessage.js.map +0 -1
  209. package/lib/messages/IProtocolProperty.d.ts +0 -12
  210. package/lib/messages/IProtocolProperty.js +0 -3
  211. package/lib/messages/IProtocolProperty.js.map +0 -1
  212. package/lib/programmers/MessageProgrammer.d.ts +0 -5
  213. package/lib/programmers/MessageProgrammer.js +0 -141
  214. package/lib/programmers/MessageProgrammer.js.map +0 -1
  215. package/lib/transformers/features/protocols/MessageTransformer.d.ts +0 -5
  216. package/lib/transformers/features/protocols/MessageTransformer.js +0 -17
  217. package/lib/transformers/features/protocols/MessageTransformer.js.map +0 -1
  218. package/lib/utils/NameEncoder.d.ts +0 -4
  219. package/lib/utils/NameEncoder.js +0 -89
  220. package/lib/utils/NameEncoder.js.map +0 -1
  221. package/src/factories/ProtocolFactory.ts +0 -79
  222. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +0 -163
  223. package/src/factories/internal/protocols/emplace_protocol_object.ts +0 -25
  224. package/src/factories/internal/protocols/emplace_protocol_property.ts +0 -12
  225. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +0 -34
  226. package/src/factories/internal/protocols/iterate_protocol_constant.ts +0 -27
  227. package/src/factories/internal/protocols/iterate_protocol_main.ts +0 -19
  228. package/src/factories/internal/protocols/iterate_protocol_map.ts +0 -58
  229. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +0 -96
  230. package/src/factories/internal/protocols/iterate_protocol_native.ts +0 -34
  231. package/src/factories/internal/protocols/iterate_protocol_never.ts +0 -1
  232. package/src/factories/internal/protocols/iterate_protocol_object.ts +0 -110
  233. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +0 -34
  234. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +0 -29
  235. package/src/functional/$proto_bytes.ts +0 -25
  236. package/src/functional/$proto_field.ts +0 -30
  237. package/src/functional/$proto_float.ts +0 -37
  238. package/src/functional/$proto_i32.ts +0 -29
  239. package/src/functional/$proto_i64.ts +0 -37
  240. package/src/functional/$proto_size.ts +0 -82
  241. package/src/functional/$proto_string.ts +0 -24
  242. package/src/functional/$varint.ts +0 -130
  243. package/src/functional/$zigzag.ts +0 -39
  244. package/src/messages/IProtocolMap.ts +0 -5
  245. package/src/messages/IProtocolMessage.ts +0 -6
  246. package/src/messages/IProtocolProperty.ts +0 -13
  247. package/src/programmers/MessageProgrammer.ts +0 -126
  248. package/src/transformers/features/protocols/MessageTransformer.ts +0 -32
  249. 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
  }