typia 3.8.0-dev.20230416 → 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.
- package/README.md +35 -228
- package/lib/executable/setup/PackageManager.d.ts +1 -1
- package/lib/factories/TypiaFileFactory.js +9 -4
- package/lib/factories/TypiaFileFactory.js.map +1 -1
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +1 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/typings/Customizable.d.ts +2 -2
- package/lib/utils/RandomGenerator.d.ts +1 -17
- package/lib/utils/RandomGenerator.js.map +1 -1
- package/package.json +2 -2
- package/src/executable/TypiaSetupWizard.ts +118 -118
- package/src/executable/setup/PackageManager.ts +71 -71
- package/src/executable/typia.ts +52 -52
- package/src/factories/IdentifierFactory.ts +59 -59
- package/src/factories/TypiaFileFactory.ts +129 -120
- package/src/metadata/Metadata.ts +533 -533
- package/src/programmers/CheckerProgrammer.ts +920 -920
- package/src/programmers/internal/check_string_tags.ts +67 -67
- package/src/programmers/internal/check_template.ts +56 -56
- package/src/typings/Customizable.ts +5 -5
- package/src/utils/RandomGenerator.ts +96 -93
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
|
-
|
|
7
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export const check_string_tags =
|
|
14
|
-
(importer: FunctionImporter) =>
|
|
15
|
-
(tagList: IMetadataTag[]) =>
|
|
16
|
-
(input: ts.Expression): ICheckEntry.ITag[] => {
|
|
17
|
-
const conditions: [IMetadataTag, ts.Expression][] = [];
|
|
18
|
-
for (const tag of tagList)
|
|
19
|
-
if (tag.kind === "format")
|
|
20
|
-
conditions.push([
|
|
21
|
-
tag,
|
|
22
|
-
ts.factory.createCallExpression(
|
|
23
|
-
importer.use(`is_${tag.value}`),
|
|
24
|
-
undefined,
|
|
25
|
-
[input],
|
|
26
|
-
),
|
|
27
|
-
]);
|
|
28
|
-
else if (tag.kind === "pattern")
|
|
29
|
-
conditions.push([
|
|
30
|
-
tag,
|
|
31
|
-
ts.factory.createCallExpression(
|
|
32
|
-
ts.factory.createIdentifier(
|
|
33
|
-
`RegExp(/${tag.value}/).test`,
|
|
34
|
-
),
|
|
35
|
-
undefined,
|
|
36
|
-
[input],
|
|
37
|
-
),
|
|
38
|
-
]);
|
|
39
|
-
else if (tag.kind === "length")
|
|
40
|
-
conditions.push([
|
|
41
|
-
tag,
|
|
42
|
-
ts.factory.createStrictEquality(
|
|
43
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
44
|
-
IdentifierFactory.join(input, "length"),
|
|
45
|
-
),
|
|
46
|
-
]);
|
|
47
|
-
else if (tag.kind === "minLength")
|
|
48
|
-
conditions.push([
|
|
49
|
-
tag,
|
|
50
|
-
ts.factory.createLessThanEquals(
|
|
51
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
52
|
-
IdentifierFactory.join(input, "length"),
|
|
53
|
-
),
|
|
54
|
-
]);
|
|
55
|
-
else if (tag.kind === "maxLength")
|
|
56
|
-
conditions.push([
|
|
57
|
-
tag,
|
|
58
|
-
ts.factory.createGreaterThanEquals(
|
|
59
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
60
|
-
IdentifierFactory.join(input, "length"),
|
|
61
|
-
),
|
|
62
|
-
]);
|
|
63
|
-
return conditions.map(([tag, expression]) => ({
|
|
64
|
-
expected: `string (@${tag.kind} ${tag.value})`,
|
|
65
|
-
expression,
|
|
66
|
-
}));
|
|
67
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
|
+
|
|
7
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const check_string_tags =
|
|
14
|
+
(importer: FunctionImporter) =>
|
|
15
|
+
(tagList: IMetadataTag[]) =>
|
|
16
|
+
(input: ts.Expression): ICheckEntry.ITag[] => {
|
|
17
|
+
const conditions: [IMetadataTag, ts.Expression][] = [];
|
|
18
|
+
for (const tag of tagList)
|
|
19
|
+
if (tag.kind === "format")
|
|
20
|
+
conditions.push([
|
|
21
|
+
tag,
|
|
22
|
+
ts.factory.createCallExpression(
|
|
23
|
+
importer.use(`is_${tag.value}`),
|
|
24
|
+
undefined,
|
|
25
|
+
[input],
|
|
26
|
+
),
|
|
27
|
+
]);
|
|
28
|
+
else if (tag.kind === "pattern")
|
|
29
|
+
conditions.push([
|
|
30
|
+
tag,
|
|
31
|
+
ts.factory.createCallExpression(
|
|
32
|
+
ts.factory.createIdentifier(
|
|
33
|
+
`RegExp(/${tag.value}/).test`,
|
|
34
|
+
),
|
|
35
|
+
undefined,
|
|
36
|
+
[input],
|
|
37
|
+
),
|
|
38
|
+
]);
|
|
39
|
+
else if (tag.kind === "length")
|
|
40
|
+
conditions.push([
|
|
41
|
+
tag,
|
|
42
|
+
ts.factory.createStrictEquality(
|
|
43
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
44
|
+
IdentifierFactory.join(input, "length"),
|
|
45
|
+
),
|
|
46
|
+
]);
|
|
47
|
+
else if (tag.kind === "minLength")
|
|
48
|
+
conditions.push([
|
|
49
|
+
tag,
|
|
50
|
+
ts.factory.createLessThanEquals(
|
|
51
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
52
|
+
IdentifierFactory.join(input, "length"),
|
|
53
|
+
),
|
|
54
|
+
]);
|
|
55
|
+
else if (tag.kind === "maxLength")
|
|
56
|
+
conditions.push([
|
|
57
|
+
tag,
|
|
58
|
+
ts.factory.createGreaterThanEquals(
|
|
59
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
60
|
+
IdentifierFactory.join(input, "length"),
|
|
61
|
+
),
|
|
62
|
+
]);
|
|
63
|
+
return conditions.map(([tag, expression]) => ({
|
|
64
|
+
expected: `string (@${tag.kind} ${tag.value})`,
|
|
65
|
+
expression,
|
|
66
|
+
}));
|
|
67
|
+
};
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
5
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
6
|
-
|
|
7
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
-
import { check_custom } from "./check_custom";
|
|
10
|
-
import { check_string_tags } from "./check_string_tags";
|
|
11
|
-
import { template_to_pattern } from "./template_to_pattern";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export const check_template =
|
|
17
|
-
(importer: FunctionImporter) =>
|
|
18
|
-
(metaTags: IMetadataTag[]) =>
|
|
19
|
-
(jsDocTags: IJsDocTagInfo[]) =>
|
|
20
|
-
(templates: Metadata[][]) =>
|
|
21
|
-
(input: ts.Expression): ICheckEntry => {
|
|
22
|
-
// TYPEOF STRING & TAGS
|
|
23
|
-
const conditions: ts.Expression[] = [
|
|
24
|
-
ts.factory.createStrictEquality(
|
|
25
|
-
ts.factory.createStringLiteral("string"),
|
|
26
|
-
ts.factory.createTypeOfExpression(input),
|
|
27
|
-
),
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
// TEMPLATES
|
|
31
|
-
const internal: ts.Expression[] = templates.map((tpl) =>
|
|
32
|
-
ts.factory.createCallExpression(
|
|
33
|
-
ts.factory.createIdentifier(
|
|
34
|
-
`RegExp(/${template_to_pattern(true)(tpl)}/).test`,
|
|
35
|
-
),
|
|
36
|
-
undefined,
|
|
37
|
-
[input],
|
|
38
|
-
),
|
|
39
|
-
);
|
|
40
|
-
conditions.push(
|
|
41
|
-
internal.length === 1
|
|
42
|
-
? internal[0]!
|
|
43
|
-
: internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// COMBINATION
|
|
47
|
-
return {
|
|
48
|
-
expression: conditions.reduce((x, y) =>
|
|
49
|
-
ts.factory.createLogicalAnd(x, y),
|
|
50
|
-
),
|
|
51
|
-
tags: [
|
|
52
|
-
...check_string_tags(importer)(metaTags)(input),
|
|
53
|
-
...check_custom("string")(importer)(jsDocTags)(input),
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
5
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
6
|
+
|
|
7
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
+
import { check_custom } from "./check_custom";
|
|
10
|
+
import { check_string_tags } from "./check_string_tags";
|
|
11
|
+
import { template_to_pattern } from "./template_to_pattern";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const check_template =
|
|
17
|
+
(importer: FunctionImporter) =>
|
|
18
|
+
(metaTags: IMetadataTag[]) =>
|
|
19
|
+
(jsDocTags: IJsDocTagInfo[]) =>
|
|
20
|
+
(templates: Metadata[][]) =>
|
|
21
|
+
(input: ts.Expression): ICheckEntry => {
|
|
22
|
+
// TYPEOF STRING & TAGS
|
|
23
|
+
const conditions: ts.Expression[] = [
|
|
24
|
+
ts.factory.createStrictEquality(
|
|
25
|
+
ts.factory.createStringLiteral("string"),
|
|
26
|
+
ts.factory.createTypeOfExpression(input),
|
|
27
|
+
),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
// TEMPLATES
|
|
31
|
+
const internal: ts.Expression[] = templates.map((tpl) =>
|
|
32
|
+
ts.factory.createCallExpression(
|
|
33
|
+
ts.factory.createIdentifier(
|
|
34
|
+
`RegExp(/${template_to_pattern(true)(tpl)}/).test`,
|
|
35
|
+
),
|
|
36
|
+
undefined,
|
|
37
|
+
[input],
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
conditions.push(
|
|
41
|
+
internal.length === 1
|
|
42
|
+
? internal[0]!
|
|
43
|
+
: internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// COMBINATION
|
|
47
|
+
return {
|
|
48
|
+
expression: conditions.reduce((x, y) =>
|
|
49
|
+
ts.factory.createLogicalAnd(x, y),
|
|
50
|
+
),
|
|
51
|
+
tags: [
|
|
52
|
+
...check_string_tags(importer)(metaTags)(input),
|
|
53
|
+
...check_custom("string")(importer)(jsDocTags)(input),
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
number: number;
|
|
3
|
-
string: string;
|
|
4
|
-
bigint: bigint;
|
|
5
|
-
}
|
|
1
|
+
export type Customizable = {
|
|
2
|
+
number: number;
|
|
3
|
+
string: string;
|
|
4
|
+
bigint: bigint;
|
|
5
|
+
};
|
|
@@ -1,93 +1,96 @@
|
|
|
1
|
-
import RandExp from "randexp";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
import RandExp from "randexp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export namespace RandomGenerator {
|
|
7
|
+
const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
|
|
8
|
+
|
|
9
|
+
/* -----------------------------------------------------------
|
|
10
|
+
REGULAR
|
|
11
|
+
----------------------------------------------------------- */
|
|
12
|
+
export function boolean(): boolean {
|
|
13
|
+
return Math.random() < 0.5;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function integer(min?: number, max?: number): number {
|
|
17
|
+
min ??= 0;
|
|
18
|
+
max ??= 100;
|
|
19
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function bigint(min?: bigint, max?: bigint): bigint {
|
|
23
|
+
min ??= BigInt(0);
|
|
24
|
+
max ??= BigInt(100);
|
|
25
|
+
return BigInt(integer(Number(min), Number(max)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function number(min?: number, max?: number): number {
|
|
29
|
+
min ??= 0;
|
|
30
|
+
max ??= 100;
|
|
31
|
+
return Math.random() * (max - min) + min;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function string(length?: number): string {
|
|
35
|
+
return new Array(length ?? integer(5, 10))
|
|
36
|
+
.fill(0)
|
|
37
|
+
.map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
|
|
38
|
+
.join("");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function array<T>(
|
|
42
|
+
closure: (index: number) => T,
|
|
43
|
+
count?: number,
|
|
44
|
+
): T[] {
|
|
45
|
+
return new Array(count ?? integer(0, 3))
|
|
46
|
+
.fill(0)
|
|
47
|
+
.map((_e, index) => closure(index));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function pick<T>(array: T[]): T {
|
|
51
|
+
return array[integer(0, array.length - 1)]!;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* -----------------------------------------------------------
|
|
55
|
+
SECIAL FORMATS
|
|
56
|
+
----------------------------------------------------------- */
|
|
57
|
+
export function uuid(): string {
|
|
58
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
59
|
+
const r = (Math.random() * 16) | 0;
|
|
60
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
61
|
+
return v.toString(16);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function email(): string {
|
|
66
|
+
return `${string(10)}@${string(10)}.${string(3)}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function url(): string {
|
|
70
|
+
return `https://${string(10)}.${string(3)}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function ipv4(): string {
|
|
74
|
+
return array(() => integer(0, 255), 4).join(".");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function ipv6(): string {
|
|
78
|
+
return array(() => integer(0, 65535).toString(16), 8).join(":");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function pattern(regex: RegExp): string {
|
|
82
|
+
return new RandExp(regex).gen();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function date(min?: number, max?: number): string {
|
|
86
|
+
min ??= 0;
|
|
87
|
+
max ??= Date.now() * 2;
|
|
88
|
+
return new Date(number(min, max)).toISOString().substring(0, 10);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function datetime(min?: number, max?: number): string {
|
|
92
|
+
min ??= 0;
|
|
93
|
+
max ??= Date.now() * 2;
|
|
94
|
+
return new Date(number(min, max)).toISOString();
|
|
95
|
+
}
|
|
96
|
+
}
|