typia 3.8.0-dev.20230417 → 3.8.0-dev.20230418

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 (51) hide show
  1. package/README.md +1 -1
  2. package/lib/executable/setup/PackageManager.d.ts +1 -1
  3. package/lib/metadata/Metadata.js +1 -1
  4. package/lib/metadata/Metadata.js.map +1 -1
  5. package/lib/programmers/CheckerProgrammer.js +1 -1
  6. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  7. package/lib/typings/Customizable.d.ts +2 -2
  8. package/lib/utils/RandomGenerator.d.ts +1 -17
  9. package/lib/utils/RandomGenerator.js.map +1 -1
  10. package/package.json +2 -2
  11. package/src/IRandomGenerator.ts +33 -33
  12. package/src/executable/TypiaGenerateWizard.ts +85 -85
  13. package/src/executable/setup/ArgumentParser.ts +45 -45
  14. package/src/executable/setup/CommandExecutor.ts +8 -8
  15. package/src/executable/setup/FileRetriever.ts +22 -22
  16. package/src/executable/setup/PackageManager.ts +1 -1
  17. package/src/executable/setup/PluginConfigurator.ts +59 -59
  18. package/src/factories/MetadataTagFactory.ts +302 -302
  19. package/src/factories/TypiaFileFactory.ts +129 -129
  20. package/src/metadata/ICommentTag.ts +4 -4
  21. package/src/metadata/Metadata.ts +1 -1
  22. package/src/module.ts +2043 -2043
  23. package/src/programmers/AssertProgrammer.ts +284 -284
  24. package/src/programmers/CheckerProgrammer.ts +1 -1
  25. package/src/programmers/LiteralsProgrammer.ts +65 -65
  26. package/src/programmers/RandomProgrammer.ts +413 -413
  27. package/src/programmers/ValidateProgrammer.ts +317 -317
  28. package/src/programmers/helpers/RandomJoiner.ts +161 -161
  29. package/src/programmers/helpers/RandomRanger.ts +216 -216
  30. package/src/programmers/internal/application_native.ts +32 -32
  31. package/src/programmers/internal/check_array.ts +30 -30
  32. package/src/programmers/internal/check_array_length.ts +35 -35
  33. package/src/programmers/internal/check_custom.ts +33 -33
  34. package/src/programmers/internal/check_number.ts +177 -177
  35. package/src/programmers/internal/check_object.ts +55 -55
  36. package/src/programmers/internal/check_union_array_like.ts +272 -272
  37. package/src/programmers/internal/feature_object_entries.ts +63 -63
  38. package/src/programmers/internal/get_comment_tags.ts +23 -23
  39. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  40. package/src/programmers/internal/random_custom.ts +30 -30
  41. package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
  42. package/src/programmers/internal/stringify_regular_properties.ts +84 -84
  43. package/src/transformers/CallExpressionTransformer.ts +174 -174
  44. package/src/transformers/ImportTransformer.ts +66 -66
  45. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
  46. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
  47. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
  48. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
  49. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  50. package/src/typings/Customizable.ts +2 -2
  51. package/src/utils/RandomGenerator.ts +3 -0
@@ -1,302 +1,302 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../metadata/IMetadataTag";
4
- import { Metadata } from "../metadata/Metadata";
5
-
6
- export namespace MetadataTagFactory {
7
- export function generate(
8
- identifier: () => string,
9
- metadata: Metadata,
10
- tagList: ts.JSDocTagInfo[],
11
- ): IMetadataTag[] {
12
- const output: IMetadataTag[] = [];
13
- for (const tag of tagList) {
14
- const elem: IMetadataTag | null = parse(
15
- identifier,
16
- metadata,
17
- tag,
18
- output,
19
- );
20
- if (elem !== null) output.push(elem);
21
- }
22
- return output;
23
- }
24
-
25
- function parse(
26
- identifier: () => string,
27
- metadata: Metadata,
28
- tag: ts.JSDocTagInfo,
29
- output: IMetadataTag[],
30
- ): IMetadataTag | null {
31
- const closure = _PARSER[tag.name];
32
- if (closure === undefined) return null;
33
-
34
- const text = (tag.text || [])[0]?.text;
35
- if (text === undefined)
36
- throw new Error(`${LABEL}: no tag value on ${identifier()}`);
37
-
38
- return closure(identifier, metadata, text, output);
39
- }
40
-
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
- /* -----------------------------------------------------------
54
- ARRAY
55
- ----------------------------------------------------------- */
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
- },
83
-
84
- /* -----------------------------------------------------------
85
- NUMBER
86
- ----------------------------------------------------------- */
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
- ]);
154
-
155
- const minimum: boolean = output.some(
156
- (tag) =>
157
- tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
158
- );
159
- if (minimum === undefined)
160
- throw new Error(
161
- `${LABEL}: step requires minimum or exclusiveMinimum tag on "${identifier()}".`,
162
- );
163
-
164
- return {
165
- kind: "step",
166
- value: parse_number(identifier, text),
167
- };
168
- },
169
-
170
- /* -----------------------------------------------------------
171
- STRING
172
- ----------------------------------------------------------- */
173
- format: (identifier, metadata, str, output) => {
174
- validate(identifier, metadata, output, "format", "string", [
175
- "pattern",
176
- ]);
177
-
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
- }
227
-
228
- function parse_number(identifier: () => string, str: string): number {
229
- const value: number = Number(str);
230
- if (isNaN(value) === true)
231
- throw new Error(`${LABEL}: invalid number on "${identifier()}".`);
232
- return value;
233
- }
234
-
235
- const LABEL = "Error on typia.MetadataTagFactory.generate()";
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
- ]);
247
-
248
- const WRONG_TYPE = (
249
- tag: string,
250
- type: "string" | "number" | "array",
251
- identifier: () => string,
252
- ) => `${LABEL}: ${tag} requires ${type} type, but no "${identifier()}".`;
253
-
254
- function validate(
255
- identifier: () => string,
256
- metadata: Metadata,
257
- output: IMetadataTag[],
258
- kind: IMetadataTag["kind"],
259
- type: "array" | "string" | "number",
260
- neighbors: IMetadataTag["kind"][],
261
- ): void {
262
- // TYPE CHECKING
263
- if (type === "array") {
264
- if (has_array(metadata) === false)
265
- throw new Error(WRONG_TYPE(kind, "array", identifier));
266
- } else if (has_atomic(metadata, type) === false)
267
- throw new Error(WRONG_TYPE(kind, type, identifier));
268
-
269
- // DUPLICATED TAG
270
- if (output.some((tag) => tag.kind === kind))
271
- throw new Error(
272
- `${LABEL}: duplicated ${kind} tags on "${identifier()}".`,
273
- );
274
-
275
- // NEIGHBOR TAG
276
- for (const name of neighbors)
277
- if (output.some((tag) => tag.kind === name))
278
- throw new Error(
279
- `${LABEL}: ${kind} and ${name} tags on "${identifier()}".`,
280
- );
281
- }
282
-
283
- function has_atomic(metadata: Metadata, type: "string" | "number"): boolean {
284
- const valid =
285
- type === "number"
286
- ? (atom: string) => atom === type || atom === "bigint"
287
- : (atom: string) => atom === type;
288
- return (
289
- metadata.atomics.find((atom) => valid(atom)) !== undefined ||
290
- metadata.arrays.some((child) => has_atomic(child, type)) ||
291
- metadata.tuples.some((tuple) =>
292
- tuple.some((child) => has_atomic(child, type)),
293
- )
294
- );
295
- }
296
-
297
- function has_array(metadata: Metadata): boolean {
298
- return (
299
- metadata.arrays.length !== 0 ||
300
- metadata.tuples.some((tuple) => tuple.some((child) => has_array(child)))
301
- );
302
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../metadata/IMetadataTag";
4
+ import { Metadata } from "../metadata/Metadata";
5
+
6
+ export namespace MetadataTagFactory {
7
+ export function generate(
8
+ identifier: () => string,
9
+ metadata: Metadata,
10
+ tagList: ts.JSDocTagInfo[],
11
+ ): IMetadataTag[] {
12
+ const output: IMetadataTag[] = [];
13
+ for (const tag of tagList) {
14
+ const elem: IMetadataTag | null = parse(
15
+ identifier,
16
+ metadata,
17
+ tag,
18
+ output,
19
+ );
20
+ if (elem !== null) output.push(elem);
21
+ }
22
+ return output;
23
+ }
24
+
25
+ function parse(
26
+ identifier: () => string,
27
+ metadata: Metadata,
28
+ tag: ts.JSDocTagInfo,
29
+ output: IMetadataTag[],
30
+ ): IMetadataTag | null {
31
+ const closure = _PARSER[tag.name];
32
+ if (closure === undefined) return null;
33
+
34
+ const text = (tag.text || [])[0]?.text;
35
+ if (text === undefined)
36
+ throw new Error(`${LABEL}: no tag value on ${identifier()}`);
37
+
38
+ return closure(identifier, metadata, text, output);
39
+ }
40
+
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
+ /* -----------------------------------------------------------
54
+ ARRAY
55
+ ----------------------------------------------------------- */
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
+ },
83
+
84
+ /* -----------------------------------------------------------
85
+ NUMBER
86
+ ----------------------------------------------------------- */
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
+ ]);
154
+
155
+ const minimum: boolean = output.some(
156
+ (tag) =>
157
+ tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
158
+ );
159
+ if (minimum === undefined)
160
+ throw new Error(
161
+ `${LABEL}: step requires minimum or exclusiveMinimum tag on "${identifier()}".`,
162
+ );
163
+
164
+ return {
165
+ kind: "step",
166
+ value: parse_number(identifier, text),
167
+ };
168
+ },
169
+
170
+ /* -----------------------------------------------------------
171
+ STRING
172
+ ----------------------------------------------------------- */
173
+ format: (identifier, metadata, str, output) => {
174
+ validate(identifier, metadata, output, "format", "string", [
175
+ "pattern",
176
+ ]);
177
+
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
+ }
227
+
228
+ function parse_number(identifier: () => string, str: string): number {
229
+ const value: number = Number(str);
230
+ if (isNaN(value) === true)
231
+ throw new Error(`${LABEL}: invalid number on "${identifier()}".`);
232
+ return value;
233
+ }
234
+
235
+ const LABEL = "Error on typia.MetadataTagFactory.generate()";
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
+ ]);
247
+
248
+ const WRONG_TYPE = (
249
+ tag: string,
250
+ type: "string" | "number" | "array",
251
+ identifier: () => string,
252
+ ) => `${LABEL}: ${tag} requires ${type} type, but no "${identifier()}".`;
253
+
254
+ function validate(
255
+ identifier: () => string,
256
+ metadata: Metadata,
257
+ output: IMetadataTag[],
258
+ kind: IMetadataTag["kind"],
259
+ type: "array" | "string" | "number",
260
+ neighbors: IMetadataTag["kind"][],
261
+ ): void {
262
+ // TYPE CHECKING
263
+ if (type === "array") {
264
+ if (has_array(metadata) === false)
265
+ throw new Error(WRONG_TYPE(kind, "array", identifier));
266
+ } else if (has_atomic(metadata, type) === false)
267
+ throw new Error(WRONG_TYPE(kind, type, identifier));
268
+
269
+ // DUPLICATED TAG
270
+ if (output.some((tag) => tag.kind === kind))
271
+ throw new Error(
272
+ `${LABEL}: duplicated ${kind} tags on "${identifier()}".`,
273
+ );
274
+
275
+ // NEIGHBOR TAG
276
+ for (const name of neighbors)
277
+ if (output.some((tag) => tag.kind === name))
278
+ throw new Error(
279
+ `${LABEL}: ${kind} and ${name} tags on "${identifier()}".`,
280
+ );
281
+ }
282
+
283
+ function has_atomic(metadata: Metadata, type: "string" | "number"): boolean {
284
+ const valid =
285
+ type === "number"
286
+ ? (atom: string) => atom === type || atom === "bigint"
287
+ : (atom: string) => atom === type;
288
+ return (
289
+ metadata.atomics.find((atom) => valid(atom)) !== undefined ||
290
+ metadata.arrays.some((child) => has_atomic(child, type)) ||
291
+ metadata.tuples.some((tuple) =>
292
+ tuple.some((child) => has_atomic(child, type)),
293
+ )
294
+ );
295
+ }
296
+
297
+ function has_array(metadata: Metadata): boolean {
298
+ return (
299
+ metadata.arrays.length !== 0 ||
300
+ metadata.tuples.some((tuple) => tuple.some((child) => has_array(child)))
301
+ );
302
+ }