typia 6.7.2 → 6.8.0-dev.20240811
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/internal/application_bigint.d.ts +1 -0
- package/lib/programmers/internal/application_bigint.js +14 -0
- package/lib/programmers/internal/application_bigint.js.map +1 -0
- package/lib/programmers/internal/application_v30_schema.js +10 -12
- package/lib/programmers/internal/application_v30_schema.js.map +1 -1
- package/lib/programmers/internal/application_v31_constant.js +3 -1
- package/lib/programmers/internal/application_v31_constant.js.map +1 -1
- package/lib/programmers/internal/application_v31_schema.js +10 -12
- package/lib/programmers/internal/application_v31_schema.js.map +1 -1
- package/lib/tags/Constant.d.ts +2 -2
- package/lib/tags/Default.d.ts +5 -1
- package/lib/tags/ExclusiveMaximum.d.ts +9 -5
- package/lib/tags/ExclusiveMinimum.d.ts +9 -5
- package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
- package/lib/tags/Maximum.d.ts +8 -5
- package/lib/tags/Minimum.d.ts +8 -5
- package/lib/tags/MultipleOf.d.ts +7 -4
- package/package.json +2 -2
- package/src/factories/CommentFactory.ts +79 -79
- package/src/factories/MetadataCollection.ts +274 -274
- package/src/factories/MetadataFactory.ts +272 -272
- package/src/factories/StatementFactory.ts +74 -74
- package/src/factories/TypeFactory.ts +118 -118
- package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
- package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -176
- package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
- package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
- package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
- package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -220
- package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
- package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
- package/src/programmers/internal/application_bigint.ts +25 -0
- package/src/programmers/internal/application_v30_alias.ts +52 -52
- package/src/programmers/internal/application_v30_object.ts +149 -149
- package/src/programmers/internal/application_v30_schema.ts +162 -159
- package/src/programmers/internal/application_v30_tuple.ts +33 -33
- package/src/programmers/internal/application_v31_constant.ts +4 -1
- package/src/programmers/internal/application_v31_schema.ts +159 -157
- package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
- package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
- package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
- package/src/tags/Constant.ts +2 -2
- package/src/tags/Default.ts +7 -3
- package/src/tags/ExclusiveMaximum.ts +12 -6
- package/src/tags/ExclusiveMinimum.ts +12 -6
- package/src/tags/JsonSchemaPlugin.ts +1 -1
- package/src/tags/Maximum.ts +9 -8
- package/src/tags/Minimum.ts +9 -8
- package/src/tags/MultipleOf.ts +9 -8
- package/src/tags/Type.ts +32 -32
- package/src/transformers/FileTransformer.ts +91 -91
- package/src/transformers/features/CreateRandomTransformer.ts +40 -40
- package/src/transformers/features/RandomTransformer.ts +44 -44
- package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -124
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -62
package/src/tags/Maximum.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
2
|
|
|
3
3
|
export type Maximum<Value extends number | bigint> = TagBase<{
|
|
4
|
-
target: Value extends
|
|
4
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
5
5
|
kind: "maximum";
|
|
6
6
|
value: Value;
|
|
7
|
-
validate: `$input <= ${
|
|
7
|
+
validate: `$input <= ${Cast<Value>}`;
|
|
8
8
|
exclusive: ["maximum", "exclusiveMaximum"];
|
|
9
|
-
schema: Value extends
|
|
10
|
-
? {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
: undefined;
|
|
9
|
+
schema: Value extends bigint
|
|
10
|
+
? { maximum: Numeric<Value> }
|
|
11
|
+
: { maximum: Value };
|
|
14
12
|
}>;
|
|
15
13
|
|
|
16
|
-
type
|
|
14
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
17
15
|
? Value
|
|
18
16
|
: `BigInt(${Value})`;
|
|
17
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
18
|
+
? N
|
|
19
|
+
: never;
|
package/src/tags/Minimum.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
2
|
|
|
3
3
|
export type Minimum<Value extends number | bigint> = TagBase<{
|
|
4
|
-
target: Value extends
|
|
4
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
5
5
|
kind: "minimum";
|
|
6
6
|
value: Value;
|
|
7
|
-
validate: `${
|
|
7
|
+
validate: `${Cast<Value>} <= $input`;
|
|
8
8
|
exclusive: ["minimum", "exclusiveMinimum"];
|
|
9
|
-
schema: Value extends
|
|
10
|
-
? {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
: undefined;
|
|
9
|
+
schema: Value extends bigint
|
|
10
|
+
? { minimum: Numeric<Value> }
|
|
11
|
+
: { minimum: Value };
|
|
14
12
|
}>;
|
|
15
13
|
|
|
16
|
-
type
|
|
14
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
17
15
|
? Value
|
|
18
16
|
: `BigInt(${Value})`;
|
|
17
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
18
|
+
? N
|
|
19
|
+
: never;
|
package/src/tags/MultipleOf.ts
CHANGED
|
@@ -4,17 +4,18 @@ export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
|
4
4
|
target: Value extends bigint ? "bigint" : "number";
|
|
5
5
|
kind: "multipleOf";
|
|
6
6
|
value: Value;
|
|
7
|
-
validate: `$input % ${
|
|
8
|
-
?
|
|
7
|
+
validate: `$input % ${Cast<Value>} === ${Value extends bigint
|
|
8
|
+
? Cast<0n>
|
|
9
9
|
: 0}`;
|
|
10
10
|
exclusive: true;
|
|
11
|
-
schema: Value extends
|
|
12
|
-
? {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
: undefined;
|
|
11
|
+
schema: Value extends bigint
|
|
12
|
+
? { multipleOf: Numeric<Value> }
|
|
13
|
+
: { multipleOf: Value };
|
|
16
14
|
}>;
|
|
17
15
|
|
|
18
|
-
type
|
|
16
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
19
17
|
? Value
|
|
20
18
|
: `BigInt(${Value})`;
|
|
19
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
20
|
+
? N
|
|
21
|
+
: never;
|
package/src/tags/Type.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
export type Type<
|
|
4
|
-
Value extends "int32" | "uint32" | "int64" | "uint64" | "float" | "double",
|
|
5
|
-
> = TagBase<{
|
|
6
|
-
target: Value extends "int64" | "uint64" ? "bigint" | "number" : "number";
|
|
7
|
-
kind: "type";
|
|
8
|
-
value: Value;
|
|
9
|
-
validate: Value extends "int32"
|
|
10
|
-
? `Math.floor($input) === $input && -2147483648 <= $input && $input <= 2147483647`
|
|
11
|
-
: Value extends "uint32"
|
|
12
|
-
? `Math.floor($input) === $input && 0 <= $input && $input <= 4294967295`
|
|
13
|
-
: Value extends "int64"
|
|
14
|
-
? {
|
|
15
|
-
number: `Math.floor($input) === $input && -9223372036854775808 <= $input && $input <= 9223372036854775807`;
|
|
16
|
-
bigint: `true`;
|
|
17
|
-
}
|
|
18
|
-
: Value extends "uint64"
|
|
19
|
-
? {
|
|
20
|
-
number: `Math.floor($input) === $input && 0 <= $input && $input <= 18446744073709551615`;
|
|
21
|
-
bigint: `BigInt(0) <= $input`;
|
|
22
|
-
}
|
|
23
|
-
: Value extends "float"
|
|
24
|
-
? `-1.175494351e38 <= $input && $input <= 3.4028235e38`
|
|
25
|
-
: `true`;
|
|
26
|
-
exclusive: true;
|
|
27
|
-
schema: {
|
|
28
|
-
type: Value extends "int32" | "uint32" | "int64" | "uint64"
|
|
29
|
-
? "integer"
|
|
30
|
-
: "number";
|
|
31
|
-
};
|
|
32
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
export type Type<
|
|
4
|
+
Value extends "int32" | "uint32" | "int64" | "uint64" | "float" | "double",
|
|
5
|
+
> = TagBase<{
|
|
6
|
+
target: Value extends "int64" | "uint64" ? "bigint" | "number" : "number";
|
|
7
|
+
kind: "type";
|
|
8
|
+
value: Value;
|
|
9
|
+
validate: Value extends "int32"
|
|
10
|
+
? `Math.floor($input) === $input && -2147483648 <= $input && $input <= 2147483647`
|
|
11
|
+
: Value extends "uint32"
|
|
12
|
+
? `Math.floor($input) === $input && 0 <= $input && $input <= 4294967295`
|
|
13
|
+
: Value extends "int64"
|
|
14
|
+
? {
|
|
15
|
+
number: `Math.floor($input) === $input && -9223372036854775808 <= $input && $input <= 9223372036854775807`;
|
|
16
|
+
bigint: `true`;
|
|
17
|
+
}
|
|
18
|
+
: Value extends "uint64"
|
|
19
|
+
? {
|
|
20
|
+
number: `Math.floor($input) === $input && 0 <= $input && $input <= 18446744073709551615`;
|
|
21
|
+
bigint: `BigInt(0) <= $input`;
|
|
22
|
+
}
|
|
23
|
+
: Value extends "float"
|
|
24
|
+
? `-1.175494351e38 <= $input && $input <= 3.4028235e38`
|
|
25
|
+
: `true`;
|
|
26
|
+
exclusive: true;
|
|
27
|
+
schema: {
|
|
28
|
+
type: Value extends "int32" | "uint32" | "int64" | "uint64"
|
|
29
|
+
? "integer"
|
|
30
|
+
: "number";
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Singleton } from "../utils/Singleton";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "./IProject";
|
|
6
|
-
import { NodeTransformer } from "./NodeTransformer";
|
|
7
|
-
import { TransformerError } from "./TransformerError";
|
|
8
|
-
|
|
9
|
-
export namespace FileTransformer {
|
|
10
|
-
export const transform =
|
|
11
|
-
(environments: Omit<IProject, "context">) =>
|
|
12
|
-
(context: ts.TransformationContext) =>
|
|
13
|
-
(file: ts.SourceFile): ts.SourceFile => {
|
|
14
|
-
if (file.isDeclarationFile) return file;
|
|
15
|
-
|
|
16
|
-
const project: IProject = {
|
|
17
|
-
...environments,
|
|
18
|
-
context,
|
|
19
|
-
};
|
|
20
|
-
checkJsDocParsingMode.get(project, file);
|
|
21
|
-
|
|
22
|
-
return ts.visitEachChild(
|
|
23
|
-
file,
|
|
24
|
-
(node) => iterate_node(project)(node),
|
|
25
|
-
context,
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const iterate_node =
|
|
30
|
-
(project: IProject) =>
|
|
31
|
-
(node: ts.Node): ts.Node =>
|
|
32
|
-
ts.visitEachChild(
|
|
33
|
-
try_transform_node(project)(node) ?? node,
|
|
34
|
-
(child) => iterate_node(project)(child),
|
|
35
|
-
project.context,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const try_transform_node =
|
|
39
|
-
(project: IProject) =>
|
|
40
|
-
(node: ts.Node): ts.Node | null => {
|
|
41
|
-
try {
|
|
42
|
-
return NodeTransformer.transform(project)(node);
|
|
43
|
-
} catch (exp) {
|
|
44
|
-
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
45
|
-
if (!isTransformerError(exp)) throw exp;
|
|
46
|
-
|
|
47
|
-
// REPORT DIAGNOSTIC
|
|
48
|
-
const diagnostic = ts.createDiagnosticForNode(node, {
|
|
49
|
-
key: exp.code,
|
|
50
|
-
category: ts.DiagnosticCategory.Error,
|
|
51
|
-
message: exp.message,
|
|
52
|
-
code: `(${exp.code})` as any,
|
|
53
|
-
});
|
|
54
|
-
project.extras.addDiagnostic(diagnostic);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const isTransformerError = (error: any): error is TransformerError =>
|
|
61
|
-
typeof error === "object" &&
|
|
62
|
-
error !== null &&
|
|
63
|
-
error.constructor.name === "TransformerError" &&
|
|
64
|
-
typeof error.code === "string" &&
|
|
65
|
-
typeof error.message === "string";
|
|
66
|
-
|
|
67
|
-
const checkJsDocParsingMode = new Singleton(
|
|
68
|
-
(project: IProject, file: ts.SourceFile) => {
|
|
69
|
-
if (
|
|
70
|
-
typeof file.jsDocParsingMode === "number" &&
|
|
71
|
-
file.jsDocParsingMode !== 0
|
|
72
|
-
) {
|
|
73
|
-
project.extras.addDiagnostic(
|
|
74
|
-
ts.createDiagnosticForNode(file, {
|
|
75
|
-
code: `(typia setup)` as any,
|
|
76
|
-
key: "jsDocParsingMode",
|
|
77
|
-
category: ts.DiagnosticCategory.Warning,
|
|
78
|
-
message: [
|
|
79
|
-
`Run "npx typia setup" or "npx typia patch" command again.`,
|
|
80
|
-
``,
|
|
81
|
-
`Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments too, and it damages on some features of "typia" like "comment tags" or "JSON schema" generator.`,
|
|
82
|
-
``,
|
|
83
|
-
`To solve this problem, run "npx typia setup" or "npx typia patch" command to hack the TypeScript compiler to revive the JSDoc parsing feature.`,
|
|
84
|
-
``,
|
|
85
|
-
` - reference: https://github.com/microsoft/TypeScript/pull/55739`,
|
|
86
|
-
].join("\n"),
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Singleton } from "../utils/Singleton";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "./IProject";
|
|
6
|
+
import { NodeTransformer } from "./NodeTransformer";
|
|
7
|
+
import { TransformerError } from "./TransformerError";
|
|
8
|
+
|
|
9
|
+
export namespace FileTransformer {
|
|
10
|
+
export const transform =
|
|
11
|
+
(environments: Omit<IProject, "context">) =>
|
|
12
|
+
(context: ts.TransformationContext) =>
|
|
13
|
+
(file: ts.SourceFile): ts.SourceFile => {
|
|
14
|
+
if (file.isDeclarationFile) return file;
|
|
15
|
+
|
|
16
|
+
const project: IProject = {
|
|
17
|
+
...environments,
|
|
18
|
+
context,
|
|
19
|
+
};
|
|
20
|
+
checkJsDocParsingMode.get(project, file);
|
|
21
|
+
|
|
22
|
+
return ts.visitEachChild(
|
|
23
|
+
file,
|
|
24
|
+
(node) => iterate_node(project)(node),
|
|
25
|
+
context,
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const iterate_node =
|
|
30
|
+
(project: IProject) =>
|
|
31
|
+
(node: ts.Node): ts.Node =>
|
|
32
|
+
ts.visitEachChild(
|
|
33
|
+
try_transform_node(project)(node) ?? node,
|
|
34
|
+
(child) => iterate_node(project)(child),
|
|
35
|
+
project.context,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const try_transform_node =
|
|
39
|
+
(project: IProject) =>
|
|
40
|
+
(node: ts.Node): ts.Node | null => {
|
|
41
|
+
try {
|
|
42
|
+
return NodeTransformer.transform(project)(node);
|
|
43
|
+
} catch (exp) {
|
|
44
|
+
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
45
|
+
if (!isTransformerError(exp)) throw exp;
|
|
46
|
+
|
|
47
|
+
// REPORT DIAGNOSTIC
|
|
48
|
+
const diagnostic = ts.createDiagnosticForNode(node, {
|
|
49
|
+
key: exp.code,
|
|
50
|
+
category: ts.DiagnosticCategory.Error,
|
|
51
|
+
message: exp.message,
|
|
52
|
+
code: `(${exp.code})` as any,
|
|
53
|
+
});
|
|
54
|
+
project.extras.addDiagnostic(diagnostic);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isTransformerError = (error: any): error is TransformerError =>
|
|
61
|
+
typeof error === "object" &&
|
|
62
|
+
error !== null &&
|
|
63
|
+
error.constructor.name === "TransformerError" &&
|
|
64
|
+
typeof error.code === "string" &&
|
|
65
|
+
typeof error.message === "string";
|
|
66
|
+
|
|
67
|
+
const checkJsDocParsingMode = new Singleton(
|
|
68
|
+
(project: IProject, file: ts.SourceFile) => {
|
|
69
|
+
if (
|
|
70
|
+
typeof file.jsDocParsingMode === "number" &&
|
|
71
|
+
file.jsDocParsingMode !== 0
|
|
72
|
+
) {
|
|
73
|
+
project.extras.addDiagnostic(
|
|
74
|
+
ts.createDiagnosticForNode(file, {
|
|
75
|
+
code: `(typia setup)` as any,
|
|
76
|
+
key: "jsDocParsingMode",
|
|
77
|
+
category: ts.DiagnosticCategory.Warning,
|
|
78
|
+
message: [
|
|
79
|
+
`Run "npx typia setup" or "npx typia patch" command again.`,
|
|
80
|
+
``,
|
|
81
|
+
`Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments too, and it damages on some features of "typia" like "comment tags" or "JSON schema" generator.`,
|
|
82
|
+
``,
|
|
83
|
+
`To solve this problem, run "npx typia setup" or "npx typia patch" command to hack the TypeScript compiler to revive the JSDoc parsing feature.`,
|
|
84
|
+
``,
|
|
85
|
+
` - reference: https://github.com/microsoft/TypeScript/pull/55739`,
|
|
86
|
+
].join("\n"),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
);
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../IProject";
|
|
6
|
-
import { TransformerError } from "../TransformerError";
|
|
7
|
-
|
|
8
|
-
export namespace CreateRandomTransformer {
|
|
9
|
-
export const transform =
|
|
10
|
-
(project: IProject) =>
|
|
11
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
12
|
-
(expression: ts.CallExpression): ts.Expression => {
|
|
13
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
-
if (!expression.typeArguments?.[0])
|
|
15
|
-
throw new TransformerError({
|
|
16
|
-
code: "typia.createRandom",
|
|
17
|
-
message: "generic argument is not specified.",
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// GET TYPE INFO
|
|
21
|
-
const node: ts.TypeNode = expression.typeArguments[0];
|
|
22
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
23
|
-
|
|
24
|
-
if (type.isTypeParameter())
|
|
25
|
-
throw new TransformerError({
|
|
26
|
-
code: "typia.createRandom",
|
|
27
|
-
message: "non-specified generic argument.",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// DO TRANSFORM
|
|
31
|
-
return RandomProgrammer.write({
|
|
32
|
-
...project,
|
|
33
|
-
options: {
|
|
34
|
-
...project.options,
|
|
35
|
-
functional: false,
|
|
36
|
-
numeric: false,
|
|
37
|
-
},
|
|
38
|
-
})(modulo)(expression.arguments?.[0])(type, node.getFullText().trim());
|
|
39
|
-
};
|
|
40
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../IProject";
|
|
6
|
+
import { TransformerError } from "../TransformerError";
|
|
7
|
+
|
|
8
|
+
export namespace CreateRandomTransformer {
|
|
9
|
+
export const transform =
|
|
10
|
+
(project: IProject) =>
|
|
11
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
12
|
+
(expression: ts.CallExpression): ts.Expression => {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
+
if (!expression.typeArguments?.[0])
|
|
15
|
+
throw new TransformerError({
|
|
16
|
+
code: "typia.createRandom",
|
|
17
|
+
message: "generic argument is not specified.",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// GET TYPE INFO
|
|
21
|
+
const node: ts.TypeNode = expression.typeArguments[0];
|
|
22
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
23
|
+
|
|
24
|
+
if (type.isTypeParameter())
|
|
25
|
+
throw new TransformerError({
|
|
26
|
+
code: "typia.createRandom",
|
|
27
|
+
message: "non-specified generic argument.",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// DO TRANSFORM
|
|
31
|
+
return RandomProgrammer.write({
|
|
32
|
+
...project,
|
|
33
|
+
options: {
|
|
34
|
+
...project.options,
|
|
35
|
+
functional: false,
|
|
36
|
+
numeric: false,
|
|
37
|
+
},
|
|
38
|
+
})(modulo)(expression.arguments?.[0])(type, node.getFullText().trim());
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../IProject";
|
|
6
|
-
import { TransformerError } from "../TransformerError";
|
|
7
|
-
|
|
8
|
-
export namespace RandomTransformer {
|
|
9
|
-
export const transform =
|
|
10
|
-
(project: IProject) =>
|
|
11
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
12
|
-
(expression: ts.CallExpression): ts.Expression => {
|
|
13
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
-
if (!expression.typeArguments?.[0])
|
|
15
|
-
throw new TransformerError({
|
|
16
|
-
code: `typia.${modulo.getText()}`,
|
|
17
|
-
message: "generic argument is not specified.",
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// GET TYPE INFO
|
|
21
|
-
const node: ts.TypeNode = expression.typeArguments[0];
|
|
22
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
23
|
-
|
|
24
|
-
if (type.isTypeParameter())
|
|
25
|
-
throw new TransformerError({
|
|
26
|
-
code: `typia.${modulo.getText()}`,
|
|
27
|
-
message: "non-specified generic argument.",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// DO TRANSFORM
|
|
31
|
-
return ts.factory.createCallExpression(
|
|
32
|
-
RandomProgrammer.write({
|
|
33
|
-
...project,
|
|
34
|
-
options: {
|
|
35
|
-
...project.options,
|
|
36
|
-
functional: false,
|
|
37
|
-
numeric: false,
|
|
38
|
-
},
|
|
39
|
-
})(modulo)()(type, node.getFullText().trim()),
|
|
40
|
-
undefined,
|
|
41
|
-
expression.arguments.length ? [expression.arguments[0]!] : undefined,
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../IProject";
|
|
6
|
+
import { TransformerError } from "../TransformerError";
|
|
7
|
+
|
|
8
|
+
export namespace RandomTransformer {
|
|
9
|
+
export const transform =
|
|
10
|
+
(project: IProject) =>
|
|
11
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
12
|
+
(expression: ts.CallExpression): ts.Expression => {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
+
if (!expression.typeArguments?.[0])
|
|
15
|
+
throw new TransformerError({
|
|
16
|
+
code: `typia.${modulo.getText()}`,
|
|
17
|
+
message: "generic argument is not specified.",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// GET TYPE INFO
|
|
21
|
+
const node: ts.TypeNode = expression.typeArguments[0];
|
|
22
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
23
|
+
|
|
24
|
+
if (type.isTypeParameter())
|
|
25
|
+
throw new TransformerError({
|
|
26
|
+
code: `typia.${modulo.getText()}`,
|
|
27
|
+
message: "non-specified generic argument.",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// DO TRANSFORM
|
|
31
|
+
return ts.factory.createCallExpression(
|
|
32
|
+
RandomProgrammer.write({
|
|
33
|
+
...project,
|
|
34
|
+
options: {
|
|
35
|
+
...project.options,
|
|
36
|
+
functional: false,
|
|
37
|
+
numeric: false,
|
|
38
|
+
},
|
|
39
|
+
})(modulo)()(type, node.getFullText().trim()),
|
|
40
|
+
undefined,
|
|
41
|
+
expression.arguments.length ? [expression.arguments[0]!] : undefined,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
}
|