typia 3.7.2 → 3.7.3
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/lib/programmers/AssertProgrammer.js +4 -2
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +3 -2
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/package.json +4 -2
- package/src/IRandomGenerator.ts +33 -33
- package/src/factories/IdentifierFactory.ts +81 -81
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/programmers/AssertProgrammer.ts +38 -10
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/ValidateProgrammer.ts +36 -9
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
- package/src/typings/Customizable.ts +5 -5
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../factories/StatementFactory";
|
|
4
5
|
import { TypeFactory } from "../factories/TypeFactory";
|
|
5
6
|
|
|
6
|
-
// import { StatementFactory } from "../factories/StatementFactory";
|
|
7
7
|
import { IProject } from "../transformers/IProject";
|
|
8
8
|
|
|
9
9
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
@@ -77,16 +77,44 @@ export namespace AssertProgrammer {
|
|
|
77
77
|
ts.factory.createBlock(
|
|
78
78
|
[
|
|
79
79
|
...importer.declare(modulo),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
StatementFactory.constant(
|
|
81
|
+
"__is",
|
|
82
|
+
IsProgrammer.generate(
|
|
83
|
+
project,
|
|
84
|
+
modulo,
|
|
85
|
+
equals,
|
|
86
|
+
)(
|
|
87
|
+
type,
|
|
88
|
+
name ??
|
|
89
|
+
TypeFactory.getFullName(
|
|
90
|
+
project.checker,
|
|
91
|
+
type,
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
ts.factory.createIfStatement(
|
|
96
|
+
ts.factory.createStrictEquality(
|
|
97
|
+
ts.factory.createFalse(),
|
|
98
|
+
ts.factory.createCallExpression(
|
|
99
|
+
ts.factory.createIdentifier("__is"),
|
|
100
|
+
undefined,
|
|
101
|
+
[ts.factory.createIdentifier("input")],
|
|
102
|
+
),
|
|
89
103
|
),
|
|
104
|
+
ts.factory.createExpressionStatement(
|
|
105
|
+
ts.factory.createCallExpression(
|
|
106
|
+
program,
|
|
107
|
+
undefined,
|
|
108
|
+
[
|
|
109
|
+
ts.factory.createIdentifier("input"),
|
|
110
|
+
ts.factory.createStringLiteral(
|
|
111
|
+
"$input",
|
|
112
|
+
),
|
|
113
|
+
ts.factory.createTrue(),
|
|
114
|
+
],
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
undefined,
|
|
90
118
|
),
|
|
91
119
|
ts.factory.createReturnStatement(
|
|
92
120
|
ts.factory.createIdentifier(`input`),
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
4
|
-
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
5
|
-
|
|
6
|
-
import { Metadata } from "../metadata/Metadata";
|
|
7
|
-
|
|
8
|
-
import { IProject } from "../transformers/IProject";
|
|
9
|
-
|
|
10
|
-
import { Atomic } from "../typings/Atomic";
|
|
11
|
-
|
|
12
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
-
|
|
14
|
-
export namespace LiteralsProgrammer {
|
|
15
|
-
export const generate = (project: IProject) => (type: ts.Type) => {
|
|
16
|
-
const meta: Metadata = MetadataFactory.generate(
|
|
17
|
-
project.checker,
|
|
18
|
-
new MetadataCollection(),
|
|
19
|
-
type,
|
|
20
|
-
{
|
|
21
|
-
resolve: true,
|
|
22
|
-
constant: true,
|
|
23
|
-
validate: (meta) => {
|
|
24
|
-
const length: number =
|
|
25
|
-
meta.constants
|
|
26
|
-
.map((c) => c.values.length)
|
|
27
|
-
.reduce((a, b) => a + b, 0) +
|
|
28
|
-
meta.atomics.filter((type) => type === "boolean")
|
|
29
|
-
.length;
|
|
30
|
-
if (0 === length) throw new Error(ErrorMessages.NO);
|
|
31
|
-
else if (meta.size() !== length)
|
|
32
|
-
throw new Error(ErrorMessages.ONLY);
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
const values: Set<Atomic.Type> = new Set([
|
|
37
|
-
...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
|
|
38
|
-
...(meta.atomics.filter((type) => type === "boolean").length
|
|
39
|
-
? [true, false]
|
|
40
|
-
: []),
|
|
41
|
-
]);
|
|
42
|
-
return ts.factory.createAsExpression(
|
|
43
|
-
ts.factory.createArrayLiteralExpression(
|
|
44
|
-
[...values].map((v) =>
|
|
45
|
-
typeof v === "boolean"
|
|
46
|
-
? v
|
|
47
|
-
? ts.factory.createTrue()
|
|
48
|
-
: ts.factory.createFalse()
|
|
49
|
-
: typeof v === "number"
|
|
50
|
-
? ts.factory.createNumericLiteral(v)
|
|
51
|
-
: typeof v === "bigint"
|
|
52
|
-
? ts.factory.createBigIntLiteral(v.toString())
|
|
53
|
-
: ts.factory.createStringLiteral(v),
|
|
54
|
-
),
|
|
55
|
-
true,
|
|
56
|
-
),
|
|
57
|
-
ts.factory.createTypeReferenceNode("const"),
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
enum ErrorMessages {
|
|
63
|
-
NO = "Error on typia.literals(): no literal type found.",
|
|
64
|
-
ONLY = "Error on typia.literals(): only literal type allowed.",
|
|
65
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
5
|
+
|
|
6
|
+
import { Metadata } from "../metadata/Metadata";
|
|
7
|
+
|
|
8
|
+
import { IProject } from "../transformers/IProject";
|
|
9
|
+
|
|
10
|
+
import { Atomic } from "../typings/Atomic";
|
|
11
|
+
|
|
12
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
+
|
|
14
|
+
export namespace LiteralsProgrammer {
|
|
15
|
+
export const generate = (project: IProject) => (type: ts.Type) => {
|
|
16
|
+
const meta: Metadata = MetadataFactory.generate(
|
|
17
|
+
project.checker,
|
|
18
|
+
new MetadataCollection(),
|
|
19
|
+
type,
|
|
20
|
+
{
|
|
21
|
+
resolve: true,
|
|
22
|
+
constant: true,
|
|
23
|
+
validate: (meta) => {
|
|
24
|
+
const length: number =
|
|
25
|
+
meta.constants
|
|
26
|
+
.map((c) => c.values.length)
|
|
27
|
+
.reduce((a, b) => a + b, 0) +
|
|
28
|
+
meta.atomics.filter((type) => type === "boolean")
|
|
29
|
+
.length;
|
|
30
|
+
if (0 === length) throw new Error(ErrorMessages.NO);
|
|
31
|
+
else if (meta.size() !== length)
|
|
32
|
+
throw new Error(ErrorMessages.ONLY);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
const values: Set<Atomic.Type> = new Set([
|
|
37
|
+
...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
|
|
38
|
+
...(meta.atomics.filter((type) => type === "boolean").length
|
|
39
|
+
? [true, false]
|
|
40
|
+
: []),
|
|
41
|
+
]);
|
|
42
|
+
return ts.factory.createAsExpression(
|
|
43
|
+
ts.factory.createArrayLiteralExpression(
|
|
44
|
+
[...values].map((v) =>
|
|
45
|
+
typeof v === "boolean"
|
|
46
|
+
? v
|
|
47
|
+
? ts.factory.createTrue()
|
|
48
|
+
: ts.factory.createFalse()
|
|
49
|
+
: typeof v === "number"
|
|
50
|
+
? ts.factory.createNumericLiteral(v)
|
|
51
|
+
: typeof v === "bigint"
|
|
52
|
+
? ts.factory.createBigIntLiteral(v.toString())
|
|
53
|
+
: ts.factory.createStringLiteral(v),
|
|
54
|
+
),
|
|
55
|
+
true,
|
|
56
|
+
),
|
|
57
|
+
ts.factory.createTypeReferenceNode("const"),
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
enum ErrorMessages {
|
|
63
|
+
NO = "Error on typia.literals(): no literal type found.",
|
|
64
|
+
ONLY = "Error on typia.literals(): only literal type allowed.",
|
|
65
|
+
}
|