typia 3.7.1 → 3.7.2
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 +3 -1
- package/lib/module.d.ts +33 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/LiteralsProgrammer.d.ts +5 -0
- package/lib/programmers/LiteralsProgrammer.js +75 -0
- package/lib/programmers/LiteralsProgrammer.js.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +2 -0
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.js +8 -1
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +6 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/CreateRandomTransformer.js +4 -2
- package/lib/transformers/features/miscellaneous/CreateRandomTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/LiteralsTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/LiteralsTransformer.js +21 -0
- package/lib/transformers/features/miscellaneous/LiteralsTransformer.js.map +1 -0
- package/lib/transformers/features/miscellaneous/MetadataTransformer.js +4 -2
- package/lib/transformers/features/miscellaneous/MetadataTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/RandomTransformer.js +4 -2
- package/lib/transformers/features/miscellaneous/RandomTransformer.js.map +1 -1
- package/package.json +2 -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/module.ts +43 -0
- package/src/programmers/LiteralsProgrammer.ts +65 -0
- package/src/programmers/RandomProgrammer.ts +413 -413
- 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 -172
- package/src/transformers/ImportTransformer.ts +9 -3
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +8 -9
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -43
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -0
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +5 -6
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +6 -8
- package/src/typings/Customizable.ts +5 -5
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { RandomProgrammer } from "../../../programmers/RandomProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace CreateRandomTransformer {
|
|
8
|
-
export function transform(
|
|
9
|
-
project: IProject,
|
|
10
|
-
modulo: ts.LeftHandSideExpression,
|
|
11
|
-
expression: ts.CallExpression,
|
|
12
|
-
): ts.Expression {
|
|
13
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
-
if (!expression.typeArguments?.[0])
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
NO_GENERIC_ARGUMENT = "Error on typia.createRandom(): non-specified generic argument.",
|
|
43
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { RandomProgrammer } from "../../../programmers/RandomProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace CreateRandomTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
+
if (!expression.typeArguments?.[0]) throw new Error(NOT_SPECIFIED);
|
|
15
|
+
|
|
16
|
+
// GET TYPE INFO
|
|
17
|
+
const node: ts.TypeNode = expression.typeArguments[0];
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
19
|
+
|
|
20
|
+
if (type.isTypeParameter()) throw new Error(NO_GENERIC_ARGUMENT);
|
|
21
|
+
|
|
22
|
+
// DO TRANSFORM
|
|
23
|
+
return RandomProgrammer.generate(
|
|
24
|
+
{
|
|
25
|
+
...project,
|
|
26
|
+
options: {
|
|
27
|
+
...project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
modulo,
|
|
33
|
+
expression.arguments?.[0],
|
|
34
|
+
)(type, node.getFullText().trim());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const NOT_SPECIFIED =
|
|
39
|
+
"Error on typia.createRandom(): generic argument is not specified.";
|
|
40
|
+
const NO_GENERIC_ARGUMENT =
|
|
41
|
+
"Error on typia.createRandom(): non-specified generic argument.";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { LiteralsProgrammer } from "../../../programmers/LiteralsProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace LiteralsTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
_modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
+
if (!expression.typeArguments?.[0]) throw new Error(NOT_SPECIFIED);
|
|
15
|
+
|
|
16
|
+
// GET TYPE INFO
|
|
17
|
+
const node: ts.TypeNode = expression.typeArguments[0];
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
19
|
+
|
|
20
|
+
if (type.isTypeParameter()) throw new Error(NO_GENERIC_ARGUMENT);
|
|
21
|
+
|
|
22
|
+
// DO TRANSFORM
|
|
23
|
+
return LiteralsProgrammer.generate(project)(type);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const NOT_SPECIFIED =
|
|
28
|
+
"Error on typia.literals(): generic argument is not specified.";
|
|
29
|
+
const NO_GENERIC_ARGUMENT =
|
|
30
|
+
"Error on typia.literals(): non-specified generic argument.";
|
|
@@ -16,7 +16,7 @@ export namespace MetadataTransformer {
|
|
|
16
16
|
expression: ts.CallExpression,
|
|
17
17
|
): ts.Expression {
|
|
18
18
|
if (!expression.typeArguments?.length)
|
|
19
|
-
throw new Error(
|
|
19
|
+
throw new Error(NO_GENERIC_ARGUMENT);
|
|
20
20
|
|
|
21
21
|
// VALIDATE TUPLE ARGUMENTS
|
|
22
22
|
const top: ts.Node = expression.typeArguments[0]!;
|
|
@@ -29,7 +29,7 @@ export namespace MetadataTransformer {
|
|
|
29
29
|
checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
30
30
|
);
|
|
31
31
|
if (types.some((t) => t.isTypeParameter()))
|
|
32
|
-
throw new Error(
|
|
32
|
+
throw new Error(GENERIC_ARGUMENT);
|
|
33
33
|
|
|
34
34
|
// METADATA
|
|
35
35
|
const collection: MetadataCollection = new MetadataCollection();
|
|
@@ -49,7 +49,6 @@ export namespace MetadataTransformer {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
52
|
+
const NO_GENERIC_ARGUMENT = "Error on typia.metadata(): no generic argument.";
|
|
53
|
+
const GENERIC_ARGUMENT =
|
|
54
|
+
"Error on typia.metadata(): non-specified generic argument(s).";
|
|
@@ -11,15 +11,13 @@ export namespace RandomTransformer {
|
|
|
11
11
|
expression: ts.CallExpression,
|
|
12
12
|
): ts.Expression {
|
|
13
13
|
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
-
if (!expression.typeArguments?.[0])
|
|
15
|
-
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
14
|
+
if (!expression.typeArguments?.[0]) throw new Error(NOT_SPECIFIED);
|
|
16
15
|
|
|
17
16
|
// GET TYPE INFO
|
|
18
17
|
const node: ts.TypeNode = expression.typeArguments[0];
|
|
19
18
|
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
20
19
|
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
|
|
20
|
+
if (type.isTypeParameter()) throw new Error(NO_GENERIC_ARGUMENT);
|
|
23
21
|
|
|
24
22
|
// DO TRANSFORM
|
|
25
23
|
return ts.factory.createCallExpression(
|
|
@@ -42,7 +40,7 @@ export namespace RandomTransformer {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const NOT_SPECIFIED =
|
|
44
|
+
"Error on typia.random(): generic argument is not specified.";
|
|
45
|
+
const NO_GENERIC_ARGUMENT =
|
|
46
|
+
"Error on typia.random(): non-specified generic argument.";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type Customizable = {
|
|
2
|
-
number: number;
|
|
3
|
-
string: string;
|
|
4
|
-
bigint: bigint;
|
|
5
|
-
};
|
|
1
|
+
export type Customizable = {
|
|
2
|
+
number: number;
|
|
3
|
+
string: string;
|
|
4
|
+
bigint: bigint;
|
|
5
|
+
};
|