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,71 +1,71 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { CommandExecutor } from "./CommandExecutor";
5
- import { FileRetriever } from "./FileRetriever";
6
-
7
- export class PackageManager {
8
- public manager: string = "npm";
9
- public get file(): string {
10
- return path.join(this.directory, "package.json");
11
- }
12
-
13
- public static async mount(): Promise<PackageManager> {
14
- const location: string | null = await FileRetriever.directory(
15
- "package.json",
16
- )(process.cwd());
17
- if (location === null)
18
- throw new Error(`Unable to find "package.json" file`);
19
-
20
- return new PackageManager(
21
- location,
22
- await this.load(path.join(location, "package.json")),
23
- );
24
- }
25
-
26
- public async save(modifier: (data: Package.Data) => void): Promise<void> {
27
- const content: string = await fs.promises.readFile(this.file, "utf8");
28
- this.data = JSON.parse(content);
29
- modifier(this.data);
30
-
31
- return fs.promises.writeFile(
32
- this.file,
33
- JSON.stringify(this.data, null, 2),
34
- "utf8",
35
- );
36
- }
37
-
38
- public install(props: {
39
- dev: boolean;
40
- modulo: string;
41
- version?: string;
42
- }): boolean {
43
- const middle: string =
44
- this.manager === "yarn"
45
- ? `add${props.dev ? " -D" : ""}`
46
- : `install ${props.dev ? "--save-dev" : "--save"}`;
47
- CommandExecutor.run(
48
- `${this.manager} ${middle} ${props.modulo}${
49
- props.version ? `@${props.version}` : ""
50
- }`,
51
- );
52
- return true;
53
- }
54
-
55
- private constructor(
56
- public readonly directory: string,
57
- public data: Package.Data,
58
- ) {}
59
-
60
- private static async load(file: string): Promise<Package.Data> {
61
- const content: string = await fs.promises.readFile(file, "utf8");
62
- return JSON.parse(content);
63
- }
64
- }
65
- export namespace Package {
66
- export interface Data {
67
- scripts?: Record<string, string>;
68
- dependencies?: Record<string, string>;
69
- devDependencies?: Record<string, string>;
70
- }
71
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { CommandExecutor } from "./CommandExecutor";
5
+ import { FileRetriever } from "./FileRetriever";
6
+
7
+ export class PackageManager {
8
+ public manager: string = "npm";
9
+ public get file(): string {
10
+ return path.join(this.directory, "package.json");
11
+ }
12
+
13
+ public static async mount(): Promise<PackageManager> {
14
+ const location: string | null = await FileRetriever.directory(
15
+ "package.json",
16
+ )(process.cwd());
17
+ if (location === null)
18
+ throw new Error(`Unable to find "package.json" file`);
19
+
20
+ return new PackageManager(
21
+ location,
22
+ await this.load(path.join(location, "package.json")),
23
+ );
24
+ }
25
+
26
+ public async save(modifier: (data: Package.Data) => void): Promise<void> {
27
+ const content: string = await fs.promises.readFile(this.file, "utf8");
28
+ this.data = JSON.parse(content);
29
+ modifier(this.data);
30
+
31
+ return fs.promises.writeFile(
32
+ this.file,
33
+ JSON.stringify(this.data, null, 2),
34
+ "utf8",
35
+ );
36
+ }
37
+
38
+ public install(props: {
39
+ dev: boolean;
40
+ modulo: string;
41
+ version?: string;
42
+ }): boolean {
43
+ const middle: string =
44
+ this.manager === "yarn"
45
+ ? `add${props.dev ? " -D" : ""}`
46
+ : `install ${props.dev ? "--save-dev" : "--save"}`;
47
+ CommandExecutor.run(
48
+ `${this.manager} ${middle} ${props.modulo}${
49
+ props.version ? `@${props.version}` : ""
50
+ }`,
51
+ );
52
+ return true;
53
+ }
54
+
55
+ private constructor(
56
+ public readonly directory: string,
57
+ public data: Package.Data,
58
+ ) {}
59
+
60
+ private static async load(file: string): Promise<Package.Data> {
61
+ const content: string = await fs.promises.readFile(file, "utf8");
62
+ return JSON.parse(content);
63
+ }
64
+ }
65
+ export namespace Package {
66
+ export interface Data {
67
+ scripts?: Record<string, string>;
68
+ dependencies?: Record<string, string>;
69
+ devDependencies?: Record<string, string>;
70
+ }
71
+ }
@@ -1,59 +1,59 @@
1
- import comments from "comment-json";
2
- import fs from "fs";
3
-
4
- import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
-
6
- export namespace PluginConfigurator {
7
- export async function configure(
8
- args: TypiaSetupWizard.IArguments,
9
- ): Promise<void> {
10
- // GET COMPILER-OPTIONS
11
- const config: comments.CommentObject = comments.parse(
12
- await fs.promises.readFile(args.project!, "utf8"),
13
- ) as comments.CommentObject;
14
- const compilerOptions = config.compilerOptions as
15
- | comments.CommentObject
16
- | undefined;
17
- if (compilerOptions === undefined)
18
- throw new Error(
19
- `${args.project} file does not have "compilerOptions" property.`,
20
- );
21
-
22
- // PREPARE PLUGINS
23
- const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
- const plugins = compilerOptions.plugins as
25
- | comments.CommentArray<comments.CommentObject>
26
- | undefined;
27
- if (plugins === undefined)
28
- return (compilerOptions.plugins = [] as any);
29
- else if (!Array.isArray(plugins))
30
- throw new Error(
31
- `"plugins" property of ${args.project} must be array type.`,
32
- );
33
- return plugins;
34
- })();
35
-
36
- const strict: boolean = compilerOptions.strict === true;
37
- const oldbie: comments.CommentObject | undefined = plugins.find(
38
- (p) =>
39
- typeof p === "object" &&
40
- p !== null &&
41
- p.transform === "typia/lib/transform",
42
- );
43
- if (strict === true && oldbie !== undefined) return;
44
-
45
- // DO CONFIGURE
46
- compilerOptions.strict = true;
47
- if (oldbie === undefined)
48
- plugins.push(
49
- comments.parse(`
50
- {
51
- "transform": "typia/lib/transform"
52
- }`) as comments.CommentObject,
53
- );
54
- await fs.promises.writeFile(
55
- args.project!,
56
- comments.stringify(config, null, 2),
57
- );
58
- }
59
- }
1
+ import comments from "comment-json";
2
+ import fs from "fs";
3
+
4
+ import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
+
6
+ export namespace PluginConfigurator {
7
+ export async function configure(
8
+ args: TypiaSetupWizard.IArguments,
9
+ ): Promise<void> {
10
+ // GET COMPILER-OPTIONS
11
+ const config: comments.CommentObject = comments.parse(
12
+ await fs.promises.readFile(args.project!, "utf8"),
13
+ ) as comments.CommentObject;
14
+ const compilerOptions = config.compilerOptions as
15
+ | comments.CommentObject
16
+ | undefined;
17
+ if (compilerOptions === undefined)
18
+ throw new Error(
19
+ `${args.project} file does not have "compilerOptions" property.`,
20
+ );
21
+
22
+ // PREPARE PLUGINS
23
+ const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
+ const plugins = compilerOptions.plugins as
25
+ | comments.CommentArray<comments.CommentObject>
26
+ | undefined;
27
+ if (plugins === undefined)
28
+ return (compilerOptions.plugins = [] as any);
29
+ else if (!Array.isArray(plugins))
30
+ throw new Error(
31
+ `"plugins" property of ${args.project} must be array type.`,
32
+ );
33
+ return plugins;
34
+ })();
35
+
36
+ const strict: boolean = compilerOptions.strict === true;
37
+ const oldbie: comments.CommentObject | undefined = plugins.find(
38
+ (p) =>
39
+ typeof p === "object" &&
40
+ p !== null &&
41
+ p.transform === "typia/lib/transform",
42
+ );
43
+ if (strict === true && oldbie !== undefined) return;
44
+
45
+ // DO CONFIGURE
46
+ compilerOptions.strict = true;
47
+ if (oldbie === undefined)
48
+ plugins.push(
49
+ comments.parse(`
50
+ {
51
+ "transform": "typia/lib/transform"
52
+ }`) as comments.CommentObject,
53
+ );
54
+ await fs.promises.writeFile(
55
+ args.project!,
56
+ comments.stringify(config, null, 2),
57
+ );
58
+ }
59
+ }
@@ -1,52 +1,52 @@
1
- #!/usr/bin/env node
2
- const USAGE = `Wrong command has been detected. Use like below:
3
-
4
- npx typia setup \\
5
- --manager (npm|pnpm|yarn) \\
6
- --project {tsconfig.json file path}
7
-
8
- - npx typia setup
9
- - npx typia setup --manager pnpm
10
- - npx typia setup --project tsconfig.test.json
11
-
12
- npx typia generate
13
- --input {directory} \\
14
- --output {directory}
15
-
16
- --npx typia generate --input src/templates --output src/functinoal
17
- `;
18
-
19
- function halt(desc: string): never {
20
- console.error(desc);
21
- process.exit(-1);
22
- }
23
-
24
- async function main(): Promise<void> {
25
- try {
26
- await import("comment-json");
27
- await import("inquirer");
28
- await import("commander");
29
- } catch {
30
- halt(`typia has not been installed. Run "npm i typia" before.`);
31
- }
32
-
33
- const type: string | undefined = process.argv[2];
34
- if (type === "setup") {
35
- const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
36
- await TypiaSetupWizard.setup();
37
- } else if (type === "generate") {
38
- try {
39
- await import("typescript");
40
- } catch {
41
- halt(
42
- `typescript has not been installed. Run "npm i -D typescript" before.`,
43
- );
44
- }
45
- const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
46
- await TypiaGenerateWizard.generate();
47
- } else halt(USAGE);
48
- }
49
- main().catch((exp) => {
50
- console.error(exp);
51
- process.exit(-1);
52
- });
1
+ #!/usr/bin/env node
2
+ const USAGE = `Wrong command has been detected. Use like below:
3
+
4
+ npx typia setup \\
5
+ --manager (npm|pnpm|yarn) \\
6
+ --project {tsconfig.json file path}
7
+
8
+ - npx typia setup
9
+ - npx typia setup --manager pnpm
10
+ - npx typia setup --project tsconfig.test.json
11
+
12
+ npx typia generate
13
+ --input {directory} \\
14
+ --output {directory}
15
+
16
+ --npx typia generate --input src/templates --output src/functinoal
17
+ `;
18
+
19
+ function halt(desc: string): never {
20
+ console.error(desc);
21
+ process.exit(-1);
22
+ }
23
+
24
+ async function main(): Promise<void> {
25
+ try {
26
+ await import("comment-json");
27
+ await import("inquirer");
28
+ await import("commander");
29
+ } catch {
30
+ halt(`typia has not been installed. Run "npm i typia" before.`);
31
+ }
32
+
33
+ const type: string | undefined = process.argv[2];
34
+ if (type === "setup") {
35
+ const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
36
+ await TypiaSetupWizard.setup();
37
+ } else if (type === "generate") {
38
+ try {
39
+ await import("typescript");
40
+ } catch {
41
+ halt(
42
+ `typescript has not been installed. Run "npm i -D typescript" before.`,
43
+ );
44
+ }
45
+ const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
46
+ await TypiaGenerateWizard.generate();
47
+ } else halt(USAGE);
48
+ }
49
+ main().catch((exp) => {
50
+ console.error(exp);
51
+ process.exit(-1);
52
+ });
@@ -1,59 +1,59 @@
1
- import ts from "typescript";
2
-
3
- import { Escaper } from "../utils/Escaper";
4
-
5
- export namespace IdentifierFactory {
6
- export function generate(name: string) {
7
- return Escaper.variable(name)
8
- ? ts.factory.createIdentifier(name)
9
- : ts.factory.createStringLiteral(name);
10
- }
11
-
12
- export function join(prefix: ts.Expression, name: string) {
13
- const postfix = generate(name);
14
- return ts.isStringLiteral(postfix)
15
- ? ts.factory.createElementAccessExpression(prefix, postfix)
16
- : ts.factory.createPropertyAccessExpression(prefix, postfix);
17
- }
18
-
19
- export function postfix(str: string): string {
20
- return Escaper.variable(str)
21
- ? `".${str}"`
22
- : `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
23
- }
24
-
25
- export function parameter(
26
- name: string | ts.BindingName,
27
- type?: ts.TypeNode,
28
- init?: ts.Expression | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
29
- ) {
30
- // instead of ts.version >= "4.8"
31
- if (ts.getDecorators !== undefined)
32
- return ts.factory.createParameterDeclaration(
33
- undefined,
34
- undefined,
35
- name,
36
- init?.kind === ts.SyntaxKind.QuestionToken
37
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
38
- : undefined,
39
- type,
40
- init && init.kind !== ts.SyntaxKind.QuestionToken
41
- ? init
42
- : undefined,
43
- );
44
- // eslint-disable-next-line
45
- return (ts.factory.createParameterDeclaration as any)(
46
- undefined,
47
- undefined,
48
- undefined,
49
- name,
50
- init?.kind === ts.SyntaxKind.QuestionToken
51
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
52
- : undefined,
53
- type,
54
- init && init.kind !== ts.SyntaxKind.QuestionToken
55
- ? init
56
- : undefined,
57
- );
58
- }
59
- }
1
+ import ts from "typescript";
2
+
3
+ import { Escaper } from "../utils/Escaper";
4
+
5
+ export namespace IdentifierFactory {
6
+ export function generate(name: string) {
7
+ return Escaper.variable(name)
8
+ ? ts.factory.createIdentifier(name)
9
+ : ts.factory.createStringLiteral(name);
10
+ }
11
+
12
+ export function join(prefix: ts.Expression, name: string) {
13
+ const postfix = generate(name);
14
+ return ts.isStringLiteral(postfix)
15
+ ? ts.factory.createElementAccessExpression(prefix, postfix)
16
+ : ts.factory.createPropertyAccessExpression(prefix, postfix);
17
+ }
18
+
19
+ export function postfix(str: string): string {
20
+ return Escaper.variable(str)
21
+ ? `".${str}"`
22
+ : `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
23
+ }
24
+
25
+ export function parameter(
26
+ name: string | ts.BindingName,
27
+ type?: ts.TypeNode,
28
+ init?: ts.Expression | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
29
+ ) {
30
+ // instead of ts.version >= "4.8"
31
+ if (ts.getDecorators !== undefined)
32
+ return ts.factory.createParameterDeclaration(
33
+ undefined,
34
+ undefined,
35
+ name,
36
+ init?.kind === ts.SyntaxKind.QuestionToken
37
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
38
+ : undefined,
39
+ type,
40
+ init && init.kind !== ts.SyntaxKind.QuestionToken
41
+ ? init
42
+ : undefined,
43
+ );
44
+ // eslint-disable-next-line
45
+ return (ts.factory.createParameterDeclaration as any)(
46
+ undefined,
47
+ undefined,
48
+ undefined,
49
+ name,
50
+ init?.kind === ts.SyntaxKind.QuestionToken
51
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
52
+ : undefined,
53
+ type,
54
+ init && init.kind !== ts.SyntaxKind.QuestionToken
55
+ ? init
56
+ : undefined,
57
+ );
58
+ }
59
+ }