typia 3.8.0-dev.20230415 → 3.8.0-dev.20230417

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 (53) hide show
  1. package/README.md +35 -228
  2. package/lib/factories/TypiaFileFactory.js +9 -4
  3. package/lib/factories/TypiaFileFactory.js.map +1 -1
  4. package/lib/typings/Customizable.d.ts +2 -2
  5. package/lib/utils/RandomGenerator.d.ts +17 -1
  6. package/lib/utils/RandomGenerator.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/IRandomGenerator.ts +33 -33
  9. package/src/executable/TypiaGenerateWizard.ts +85 -85
  10. package/src/executable/TypiaSetupWizard.ts +118 -118
  11. package/src/executable/setup/ArgumentParser.ts +45 -45
  12. package/src/executable/setup/CommandExecutor.ts +8 -8
  13. package/src/executable/setup/FileRetriever.ts +22 -22
  14. package/src/executable/setup/PackageManager.ts +71 -71
  15. package/src/executable/setup/PluginConfigurator.ts +59 -59
  16. package/src/executable/typia.ts +52 -52
  17. package/src/factories/IdentifierFactory.ts +59 -59
  18. package/src/factories/MetadataTagFactory.ts +302 -302
  19. package/src/factories/TypiaFileFactory.ts +12 -3
  20. package/src/metadata/ICommentTag.ts +4 -4
  21. package/src/metadata/Metadata.ts +533 -533
  22. package/src/module.ts +2043 -2043
  23. package/src/programmers/AssertProgrammer.ts +284 -284
  24. package/src/programmers/CheckerProgrammer.ts +920 -920
  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_string_tags.ts +67 -67
  37. package/src/programmers/internal/check_template.ts +56 -56
  38. package/src/programmers/internal/check_union_array_like.ts +272 -272
  39. package/src/programmers/internal/feature_object_entries.ts +63 -63
  40. package/src/programmers/internal/get_comment_tags.ts +23 -23
  41. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  42. package/src/programmers/internal/random_custom.ts +30 -30
  43. package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
  44. package/src/programmers/internal/stringify_regular_properties.ts +84 -84
  45. package/src/transformers/CallExpressionTransformer.ts +174 -174
  46. package/src/transformers/ImportTransformer.ts +66 -66
  47. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
  48. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
  49. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
  50. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
  51. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  52. package/src/typings/Customizable.ts +5 -5
  53. package/src/utils/RandomGenerator.ts +93 -96
@@ -1,85 +1,85 @@
1
- import fs from "fs";
2
-
3
- import { TypiaFileFactory } from "../factories/TypiaFileFactory";
4
-
5
- import { ArgumentParser } from "./setup/ArgumentParser";
6
- import { PackageManager } from "./setup/PackageManager";
7
-
8
- export namespace TypiaGenerateWizard {
9
- export async function generate(): Promise<void> {
10
- console.log("----------------------------------------");
11
- console.log(" Typia Generate Wizard");
12
- console.log("----------------------------------------");
13
-
14
- // LOAD PACKAGE.JSON INFO
15
- const pack: PackageManager = await PackageManager.mount();
16
- const options: IArguments = await ArgumentParser.parse(pack)(inquiry);
17
- await TypiaFileFactory.generate(options);
18
- }
19
-
20
- const inquiry: ArgumentParser.Inquiry<IArguments> = async (
21
- _pack,
22
- command,
23
- prompt,
24
- action,
25
- ) => {
26
- // PREPARE ASSETS
27
- command.option("--input [path]", "input directory");
28
- command.option("--output [directory]", "output directory");
29
- command.option("--project [project]", "tsconfig.json file location");
30
-
31
- const questioned = { value: false };
32
-
33
- const input = (name: string) => async (message: string) => {
34
- const result = await prompt()({
35
- type: "input",
36
- name,
37
- message,
38
- default: "",
39
- });
40
- return result[name] as string;
41
- };
42
- const select =
43
- (name: string) =>
44
- (message: string) =>
45
- async <Choice extends string>(
46
- choices: Choice[],
47
- ): Promise<Choice> => {
48
- questioned.value = true;
49
- return (
50
- await prompt()({
51
- type: "list",
52
- name: name,
53
- message: message,
54
- choices: choices,
55
- })
56
- )[name];
57
- };
58
- const configure = async () => {
59
- const files: string[] = await (
60
- await fs.promises.readdir(process.cwd())
61
- ).filter(
62
- (str) =>
63
- str.substring(0, 8) === "tsconfig" &&
64
- str.substring(str.length - 5) === ".json",
65
- );
66
- if (files.length === 0)
67
- throw new Error(`Unable to find "tsconfig.json" file.`);
68
- else if (files.length === 1) return files[0];
69
- return select("tsconfig")("TS Config File")(files);
70
- };
71
-
72
- return action(async (options) => {
73
- options.input ??= await input("input")("input directory");
74
- options.output ??= await input("output")("output directory");
75
- options.project ??= await configure();
76
- return options as IArguments;
77
- });
78
- };
79
-
80
- export interface IArguments {
81
- input: string;
82
- output: string;
83
- project: string;
84
- }
85
- }
1
+ import fs from "fs";
2
+
3
+ import { TypiaFileFactory } from "../factories/TypiaFileFactory";
4
+
5
+ import { ArgumentParser } from "./setup/ArgumentParser";
6
+ import { PackageManager } from "./setup/PackageManager";
7
+
8
+ export namespace TypiaGenerateWizard {
9
+ export async function generate(): Promise<void> {
10
+ console.log("----------------------------------------");
11
+ console.log(" Typia Generate Wizard");
12
+ console.log("----------------------------------------");
13
+
14
+ // LOAD PACKAGE.JSON INFO
15
+ const pack: PackageManager = await PackageManager.mount();
16
+ const options: IArguments = await ArgumentParser.parse(pack)(inquiry);
17
+ await TypiaFileFactory.generate(options);
18
+ }
19
+
20
+ const inquiry: ArgumentParser.Inquiry<IArguments> = async (
21
+ _pack,
22
+ command,
23
+ prompt,
24
+ action,
25
+ ) => {
26
+ // PREPARE ASSETS
27
+ command.option("--input [path]", "input directory");
28
+ command.option("--output [directory]", "output directory");
29
+ command.option("--project [project]", "tsconfig.json file location");
30
+
31
+ const questioned = { value: false };
32
+
33
+ const input = (name: string) => async (message: string) => {
34
+ const result = await prompt()({
35
+ type: "input",
36
+ name,
37
+ message,
38
+ default: "",
39
+ });
40
+ return result[name] as string;
41
+ };
42
+ const select =
43
+ (name: string) =>
44
+ (message: string) =>
45
+ async <Choice extends string>(
46
+ choices: Choice[],
47
+ ): Promise<Choice> => {
48
+ questioned.value = true;
49
+ return (
50
+ await prompt()({
51
+ type: "list",
52
+ name: name,
53
+ message: message,
54
+ choices: choices,
55
+ })
56
+ )[name];
57
+ };
58
+ const configure = async () => {
59
+ const files: string[] = await (
60
+ await fs.promises.readdir(process.cwd())
61
+ ).filter(
62
+ (str) =>
63
+ str.substring(0, 8) === "tsconfig" &&
64
+ str.substring(str.length - 5) === ".json",
65
+ );
66
+ if (files.length === 0)
67
+ throw new Error(`Unable to find "tsconfig.json" file.`);
68
+ else if (files.length === 1) return files[0];
69
+ return select("tsconfig")("TS Config File")(files);
70
+ };
71
+
72
+ return action(async (options) => {
73
+ options.input ??= await input("input")("input directory");
74
+ options.output ??= await input("output")("output directory");
75
+ options.project ??= await configure();
76
+ return options as IArguments;
77
+ });
78
+ };
79
+
80
+ export interface IArguments {
81
+ input: string;
82
+ output: string;
83
+ project: string;
84
+ }
85
+ }
@@ -1,118 +1,118 @@
1
- import fs from "fs";
2
-
3
- import { ArgumentParser } from "./setup/ArgumentParser";
4
- import { CommandExecutor } from "./setup/CommandExecutor";
5
- import { PackageManager } from "./setup/PackageManager";
6
- import { PluginConfigurator } from "./setup/PluginConfigurator";
7
-
8
- export namespace TypiaSetupWizard {
9
- export interface IArguments {
10
- manager: "npm" | "pnpm" | "yarn";
11
- project: string | null;
12
- }
13
-
14
- export async function setup(): Promise<void> {
15
- console.log("----------------------------------------");
16
- console.log(" Typia Setup Wizard");
17
- console.log("----------------------------------------");
18
-
19
- // PREPARE ASSETS
20
- const pack: PackageManager = await PackageManager.mount();
21
- const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
22
-
23
- // INSTALL TYPESCRIPT
24
- pack.install({ dev: true, modulo: "typescript", version: "latest" });
25
- args.project ??= (() => {
26
- CommandExecutor.run("npx tsc --init");
27
- return (args.project = "tsconfig.json");
28
- })();
29
- pack.install({ dev: true, modulo: "ts-node", version: "latest" });
30
-
31
- // INSTALL COMPILER
32
- pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
33
- await pack.save((data) => {
34
- data.scripts ??= {};
35
- if (
36
- typeof data.scripts.prepare === "string" &&
37
- data.scripts.prepare.length
38
- ) {
39
- if (data.scripts.prepare.indexOf("ts-patch install") === -1)
40
- data.scripts.prepare =
41
- "ts-patch install && " + data.scripts.prepare;
42
- } else data.scripts.prepare = "ts-patch install";
43
- });
44
- CommandExecutor.run("npm run prepare");
45
-
46
- // CONFIGURE TYPIA
47
- await PluginConfigurator.configure(args);
48
- }
49
-
50
- const inquiry: ArgumentParser.Inquiry<IArguments> = async (
51
- pack,
52
- command,
53
- prompt,
54
- action,
55
- ) => {
56
- // PREPARE ASSETS
57
- command.option("--manager [manager", "package manager");
58
- command.option("--project [project]", "tsconfig.json file location");
59
-
60
- // INTERNAL PROCEDURES
61
- const questioned = { value: false };
62
- const select =
63
- (name: string) =>
64
- (message: string) =>
65
- async <Choice extends string>(
66
- choices: Choice[],
67
- ): Promise<Choice> => {
68
- questioned.value = true;
69
- return (
70
- await prompt()({
71
- type: "list",
72
- name: name,
73
- message: message,
74
- choices: choices,
75
- })
76
- )[name];
77
- };
78
- const configure = async () => {
79
- const fileList: string[] = await (
80
- await fs.promises.readdir(process.cwd())
81
- )
82
- .filter(
83
- (str) =>
84
- str.substring(0, 8) === "tsconfig" &&
85
- str.substring(str.length - 5) === ".json",
86
- )
87
- .sort((x, y) =>
88
- x === "tsconfig.json"
89
- ? -1
90
- : y === "tsconfig.json"
91
- ? 1
92
- : x < y
93
- ? -1
94
- : 1,
95
- );
96
- if (fileList.length === 0) {
97
- if (process.cwd() !== pack.directory)
98
- throw new Error(`Unable to find "tsconfig.json" file.`);
99
- return null;
100
- } else if (fileList.length === 1) return fileList[0];
101
- return select("tsconfig")("TS Config File")(fileList);
102
- };
103
-
104
- // DO CONSTRUCT
105
- return action(async (options) => {
106
- options.manager ??= await select("manager")("Package Manager")([
107
- "npm" as const,
108
- "pnpm" as const,
109
- "yarn" as const,
110
- ]);
111
- pack.manager = options.manager;
112
- options.project ??= await configure();
113
-
114
- if (questioned.value) console.log("");
115
- return options as IArguments;
116
- });
117
- };
118
- }
1
+ import fs from "fs";
2
+
3
+ import { ArgumentParser } from "./setup/ArgumentParser";
4
+ import { CommandExecutor } from "./setup/CommandExecutor";
5
+ import { PackageManager } from "./setup/PackageManager";
6
+ import { PluginConfigurator } from "./setup/PluginConfigurator";
7
+
8
+ export namespace TypiaSetupWizard {
9
+ export interface IArguments {
10
+ manager: "npm" | "pnpm" | "yarn";
11
+ project: string | null;
12
+ }
13
+
14
+ export async function setup(): Promise<void> {
15
+ console.log("----------------------------------------");
16
+ console.log(" Typia Setup Wizard");
17
+ console.log("----------------------------------------");
18
+
19
+ // PREPARE ASSETS
20
+ const pack: PackageManager = await PackageManager.mount();
21
+ const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
22
+
23
+ // INSTALL TYPESCRIPT
24
+ pack.install({ dev: true, modulo: "typescript", version: "latest" });
25
+ args.project ??= (() => {
26
+ CommandExecutor.run("npx tsc --init");
27
+ return (args.project = "tsconfig.json");
28
+ })();
29
+ pack.install({ dev: true, modulo: "ts-node", version: "latest" });
30
+
31
+ // INSTALL COMPILER
32
+ pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
33
+ await pack.save((data) => {
34
+ data.scripts ??= {};
35
+ if (
36
+ typeof data.scripts.prepare === "string" &&
37
+ data.scripts.prepare.length
38
+ ) {
39
+ if (data.scripts.prepare.indexOf("ts-patch install") === -1)
40
+ data.scripts.prepare =
41
+ "ts-patch install && " + data.scripts.prepare;
42
+ } else data.scripts.prepare = "ts-patch install";
43
+ });
44
+ CommandExecutor.run("npm run prepare");
45
+
46
+ // CONFIGURE TYPIA
47
+ await PluginConfigurator.configure(args);
48
+ }
49
+
50
+ const inquiry: ArgumentParser.Inquiry<IArguments> = async (
51
+ pack,
52
+ command,
53
+ prompt,
54
+ action,
55
+ ) => {
56
+ // PREPARE ASSETS
57
+ command.option("--manager [manager", "package manager");
58
+ command.option("--project [project]", "tsconfig.json file location");
59
+
60
+ // INTERNAL PROCEDURES
61
+ const questioned = { value: false };
62
+ const select =
63
+ (name: string) =>
64
+ (message: string) =>
65
+ async <Choice extends string>(
66
+ choices: Choice[],
67
+ ): Promise<Choice> => {
68
+ questioned.value = true;
69
+ return (
70
+ await prompt()({
71
+ type: "list",
72
+ name: name,
73
+ message: message,
74
+ choices: choices,
75
+ })
76
+ )[name];
77
+ };
78
+ const configure = async () => {
79
+ const fileList: string[] = await (
80
+ await fs.promises.readdir(process.cwd())
81
+ )
82
+ .filter(
83
+ (str) =>
84
+ str.substring(0, 8) === "tsconfig" &&
85
+ str.substring(str.length - 5) === ".json",
86
+ )
87
+ .sort((x, y) =>
88
+ x === "tsconfig.json"
89
+ ? -1
90
+ : y === "tsconfig.json"
91
+ ? 1
92
+ : x < y
93
+ ? -1
94
+ : 1,
95
+ );
96
+ if (fileList.length === 0) {
97
+ if (process.cwd() !== pack.directory)
98
+ throw new Error(`Unable to find "tsconfig.json" file.`);
99
+ return null;
100
+ } else if (fileList.length === 1) return fileList[0];
101
+ return select("tsconfig")("TS Config File")(fileList);
102
+ };
103
+
104
+ // DO CONSTRUCT
105
+ return action(async (options) => {
106
+ options.manager ??= await select("manager")("Package Manager")([
107
+ "npm" as const,
108
+ "pnpm" as const,
109
+ "yarn" as const,
110
+ ]);
111
+ pack.manager = options.manager;
112
+ options.project ??= await configure();
113
+
114
+ if (questioned.value) console.log("");
115
+ return options as IArguments;
116
+ });
117
+ };
118
+ }
@@ -1,45 +1,45 @@
1
- import commander from "commander";
2
- import inquirer from "inquirer";
3
-
4
- import { PackageManager } from "./PackageManager";
5
-
6
- export namespace ArgumentParser {
7
- export type Inquiry<T> = (
8
- pack: PackageManager,
9
- command: commander.Command,
10
- prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
11
- action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
12
- ) => Promise<T>;
13
-
14
- export const parse =
15
- (pack: PackageManager) =>
16
- async <T>(
17
- inquiry: (
18
- pack: PackageManager,
19
- command: commander.Command,
20
- prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
21
- action: (
22
- closure: (options: Partial<T>) => Promise<T>,
23
- ) => Promise<T>,
24
- ) => Promise<T>,
25
- ): Promise<T> => {
26
- // TAKE OPTIONS
27
- const action = (closure: (options: Partial<T>) => Promise<T>) =>
28
- new Promise<T>((resolve, reject) => {
29
- commander.program.action(async (options) => {
30
- try {
31
- resolve(await closure(options));
32
- } catch (exp) {
33
- reject(exp);
34
- }
35
- });
36
- commander.program.parseAsync().catch(reject);
37
- });
38
- return inquiry(
39
- pack,
40
- commander.program,
41
- inquirer.createPromptModule,
42
- action,
43
- );
44
- };
45
- }
1
+ import commander from "commander";
2
+ import inquirer from "inquirer";
3
+
4
+ import { PackageManager } from "./PackageManager";
5
+
6
+ export namespace ArgumentParser {
7
+ export type Inquiry<T> = (
8
+ pack: PackageManager,
9
+ command: commander.Command,
10
+ prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
11
+ action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
12
+ ) => Promise<T>;
13
+
14
+ export const parse =
15
+ (pack: PackageManager) =>
16
+ async <T>(
17
+ inquiry: (
18
+ pack: PackageManager,
19
+ command: commander.Command,
20
+ prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
21
+ action: (
22
+ closure: (options: Partial<T>) => Promise<T>,
23
+ ) => Promise<T>,
24
+ ) => Promise<T>,
25
+ ): Promise<T> => {
26
+ // TAKE OPTIONS
27
+ const action = (closure: (options: Partial<T>) => Promise<T>) =>
28
+ new Promise<T>((resolve, reject) => {
29
+ commander.program.action(async (options) => {
30
+ try {
31
+ resolve(await closure(options));
32
+ } catch (exp) {
33
+ reject(exp);
34
+ }
35
+ });
36
+ commander.program.parseAsync().catch(reject);
37
+ });
38
+ return inquiry(
39
+ pack,
40
+ commander.program,
41
+ inquirer.createPromptModule,
42
+ action,
43
+ );
44
+ };
45
+ }
@@ -1,8 +1,8 @@
1
- import cp from "child_process";
2
-
3
- export namespace CommandExecutor {
4
- export function run(str: string): void {
5
- console.log(str);
6
- cp.execSync(str, { stdio: "ignore" });
7
- }
8
- }
1
+ import cp from "child_process";
2
+
3
+ export namespace CommandExecutor {
4
+ export function run(str: string): void {
5
+ console.log(str);
6
+ cp.execSync(str, { stdio: "ignore" });
7
+ }
8
+ }
@@ -1,22 +1,22 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export namespace FileRetriever {
5
- export const directory =
6
- (name: string) =>
7
- (dir: string, depth: number = 0): string | null => {
8
- const location: string = path.join(dir, name);
9
- if (fs.existsSync(location)) return dir;
10
- else if (depth > 2) return null;
11
- return directory(name)(path.join(dir, ".."), depth + 1);
12
- };
13
-
14
- export const file =
15
- (name: string) =>
16
- (directory: string, depth: number = 0): string | null => {
17
- const location: string = path.join(directory, name);
18
- if (fs.existsSync(location)) return location;
19
- else if (depth > 2) return null;
20
- return file(name)(path.join(directory, ".."), depth + 1);
21
- };
22
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export namespace FileRetriever {
5
+ export const directory =
6
+ (name: string) =>
7
+ (dir: string, depth: number = 0): string | null => {
8
+ const location: string = path.join(dir, name);
9
+ if (fs.existsSync(location)) return dir;
10
+ else if (depth > 2) return null;
11
+ return directory(name)(path.join(dir, ".."), depth + 1);
12
+ };
13
+
14
+ export const file =
15
+ (name: string) =>
16
+ (directory: string, depth: number = 0): string | null => {
17
+ const location: string = path.join(directory, name);
18
+ if (fs.existsSync(location)) return location;
19
+ else if (depth > 2) return null;
20
+ return file(name)(path.join(directory, ".."), depth + 1);
21
+ };
22
+ }