typia 3.4.22 → 3.4.23
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 +57 -23
- package/lib/programmers/AssertProgrammer.js +79 -70
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -0
- package/lib/programmers/IsProgrammer.js +4 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +68 -59
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -0
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +10 -0
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/functional/$every.ts +11 -11
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +36 -29
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +36 -29
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +4 -0
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +43 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +11 -0
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
// import path from "path";
|
|
2
|
-
// import ts from "typescript";
|
|
3
|
-
// import { AssertProgrammer } from "../programmers/AssertProgrammer";
|
|
4
|
-
// import { IsProgrammer } from "../programmers/IsProgrammer";
|
|
5
|
-
// import { StringifyProgrammer } from "../programmers/StringifyProgrammer";
|
|
6
|
-
// import { IProject } from "../structures/IProject";
|
|
7
|
-
|
|
8
|
-
// export namespace ExpressionWithArgumentTransformer {
|
|
9
|
-
// export function transform(
|
|
10
|
-
// project: IProject,
|
|
11
|
-
// expression: ts.ExpressionWithTypeArguments,
|
|
12
|
-
// ): ts.Expression {
|
|
13
|
-
// //----
|
|
14
|
-
// // VALIDATIONS
|
|
15
|
-
// //----
|
|
16
|
-
// // SYMBOL DECLARATION
|
|
17
|
-
// const symbol: ts.Symbol | undefined =
|
|
18
|
-
// project.checker.getSymbolAtLocation(expression.expression);
|
|
19
|
-
// const declaration: ts.Declaration | undefined = symbol?.declarations
|
|
20
|
-
// ? symbol.declarations[0]
|
|
21
|
-
// : undefined;
|
|
22
|
-
// if (!declaration) return expression;
|
|
23
|
-
|
|
24
|
-
// // FILE PATH
|
|
25
|
-
// const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
26
|
-
// if (file !== LIB_PATH && file !== SRC_PATH) return expression;
|
|
27
|
-
|
|
28
|
-
// // ARGUMENTS
|
|
29
|
-
// if (expression.typeArguments?.length !== 1) return expression;
|
|
30
|
-
|
|
31
|
-
// //----
|
|
32
|
-
// // TRANSFORMATION
|
|
33
|
-
// //----
|
|
34
|
-
// // GET MODULO AND TYPE
|
|
35
|
-
// const modulo: ts.LeftHandSideExpression = expression.expression;
|
|
36
|
-
// const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
37
|
-
// expression.typeArguments[0]!,
|
|
38
|
-
// );
|
|
39
|
-
|
|
40
|
-
// // FUNCTION NAME
|
|
41
|
-
// const { name } = project.checker.getTypeAtLocation(declaration).symbol;
|
|
42
|
-
|
|
43
|
-
// // FIND TRANSFORMER
|
|
44
|
-
// const functor: (() => Task) | undefined = FUNCTORS[name];
|
|
45
|
-
// if (functor === undefined) return expression;
|
|
46
|
-
|
|
47
|
-
// // RETURNS WITH TRANSFORMATION
|
|
48
|
-
// return functor()(project, modulo, type);
|
|
49
|
-
// }
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
// type Task = (
|
|
53
|
-
// project: IProject,
|
|
54
|
-
// modulo: ts.LeftHandSideExpression,
|
|
55
|
-
// type: ts.Type,
|
|
56
|
-
// ) => ts.ArrowFunction;
|
|
57
|
-
|
|
58
|
-
// const LIB_PATH = path.resolve(path.join(__dirname, "..", "module.d.ts"));
|
|
59
|
-
// const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
60
|
-
|
|
61
|
-
// const FUNCTORS: Record<string, () => Task> = {
|
|
62
|
-
// assert: () => AssertProgrammer.generate,
|
|
63
|
-
// is: () => (project, _modulo, type) => IsProgrammer.generate(project, type),
|
|
64
|
-
// stringify: () => (project, modulo, type) =>
|
|
65
|
-
// StringifyProgrammer.generate(modulo)(project, type),
|
|
66
|
-
// };
|
|
1
|
+
// import path from "path";
|
|
2
|
+
// import ts from "typescript";
|
|
3
|
+
// import { AssertProgrammer } from "../programmers/AssertProgrammer";
|
|
4
|
+
// import { IsProgrammer } from "../programmers/IsProgrammer";
|
|
5
|
+
// import { StringifyProgrammer } from "../programmers/StringifyProgrammer";
|
|
6
|
+
// import { IProject } from "../structures/IProject";
|
|
7
|
+
|
|
8
|
+
// export namespace ExpressionWithArgumentTransformer {
|
|
9
|
+
// export function transform(
|
|
10
|
+
// project: IProject,
|
|
11
|
+
// expression: ts.ExpressionWithTypeArguments,
|
|
12
|
+
// ): ts.Expression {
|
|
13
|
+
// //----
|
|
14
|
+
// // VALIDATIONS
|
|
15
|
+
// //----
|
|
16
|
+
// // SYMBOL DECLARATION
|
|
17
|
+
// const symbol: ts.Symbol | undefined =
|
|
18
|
+
// project.checker.getSymbolAtLocation(expression.expression);
|
|
19
|
+
// const declaration: ts.Declaration | undefined = symbol?.declarations
|
|
20
|
+
// ? symbol.declarations[0]
|
|
21
|
+
// : undefined;
|
|
22
|
+
// if (!declaration) return expression;
|
|
23
|
+
|
|
24
|
+
// // FILE PATH
|
|
25
|
+
// const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
26
|
+
// if (file !== LIB_PATH && file !== SRC_PATH) return expression;
|
|
27
|
+
|
|
28
|
+
// // ARGUMENTS
|
|
29
|
+
// if (expression.typeArguments?.length !== 1) return expression;
|
|
30
|
+
|
|
31
|
+
// //----
|
|
32
|
+
// // TRANSFORMATION
|
|
33
|
+
// //----
|
|
34
|
+
// // GET MODULO AND TYPE
|
|
35
|
+
// const modulo: ts.LeftHandSideExpression = expression.expression;
|
|
36
|
+
// const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
37
|
+
// expression.typeArguments[0]!,
|
|
38
|
+
// );
|
|
39
|
+
|
|
40
|
+
// // FUNCTION NAME
|
|
41
|
+
// const { name } = project.checker.getTypeAtLocation(declaration).symbol;
|
|
42
|
+
|
|
43
|
+
// // FIND TRANSFORMER
|
|
44
|
+
// const functor: (() => Task) | undefined = FUNCTORS[name];
|
|
45
|
+
// if (functor === undefined) return expression;
|
|
46
|
+
|
|
47
|
+
// // RETURNS WITH TRANSFORMATION
|
|
48
|
+
// return functor()(project, modulo, type);
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
// type Task = (
|
|
53
|
+
// project: IProject,
|
|
54
|
+
// modulo: ts.LeftHandSideExpression,
|
|
55
|
+
// type: ts.Type,
|
|
56
|
+
// ) => ts.ArrowFunction;
|
|
57
|
+
|
|
58
|
+
// const LIB_PATH = path.resolve(path.join(__dirname, "..", "module.d.ts"));
|
|
59
|
+
// const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
60
|
+
|
|
61
|
+
// const FUNCTORS: Record<string, () => Task> = {
|
|
62
|
+
// assert: () => AssertProgrammer.generate,
|
|
63
|
+
// is: () => (project, _modulo, type) => IsProgrammer.generate(project, type),
|
|
64
|
+
// stringify: () => (project, modulo, type) =>
|
|
65
|
+
// StringifyProgrammer.generate(modulo)(project, type),
|
|
66
|
+
// };
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IProject } from "./IProject";
|
|
4
|
-
import { NodeTransformer } from "./NodeTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace FileTransformer {
|
|
7
|
-
export function transform(
|
|
8
|
-
project: IProject,
|
|
9
|
-
context: ts.TransformationContext,
|
|
10
|
-
file: ts.SourceFile,
|
|
11
|
-
): ts.SourceFile {
|
|
12
|
-
// DO NOT TRANSFORM D.TS FILE
|
|
13
|
-
if (file.isDeclarationFile) return file;
|
|
14
|
-
|
|
15
|
-
// ITERATE NODES
|
|
16
|
-
return ts.visitEachChild(
|
|
17
|
-
file,
|
|
18
|
-
(node) => iterate_node(project, context, node),
|
|
19
|
-
context,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function iterate_node(
|
|
24
|
-
project: IProject,
|
|
25
|
-
context: ts.TransformationContext,
|
|
26
|
-
node: ts.Node,
|
|
27
|
-
): ts.Node {
|
|
28
|
-
return ts.visitEachChild(
|
|
29
|
-
try_transform_node(project, node),
|
|
30
|
-
(child) => iterate_node(project, context, child),
|
|
31
|
-
context,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function try_transform_node(project: IProject, node: ts.Node): ts.Node {
|
|
36
|
-
try {
|
|
37
|
-
return NodeTransformer.transform(project, node);
|
|
38
|
-
} catch (exp) {
|
|
39
|
-
if (!(exp instanceof Error)) throw exp;
|
|
40
|
-
|
|
41
|
-
const file: ts.SourceFile = node.getSourceFile();
|
|
42
|
-
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
43
|
-
node.pos,
|
|
44
|
-
);
|
|
45
|
-
exp.message += ` - ${file.fileName}:${line + 1}:${character + 1}`;
|
|
46
|
-
throw exp;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IProject } from "./IProject";
|
|
4
|
+
import { NodeTransformer } from "./NodeTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace FileTransformer {
|
|
7
|
+
export function transform(
|
|
8
|
+
project: IProject,
|
|
9
|
+
context: ts.TransformationContext,
|
|
10
|
+
file: ts.SourceFile,
|
|
11
|
+
): ts.SourceFile {
|
|
12
|
+
// DO NOT TRANSFORM D.TS FILE
|
|
13
|
+
if (file.isDeclarationFile) return file;
|
|
14
|
+
|
|
15
|
+
// ITERATE NODES
|
|
16
|
+
return ts.visitEachChild(
|
|
17
|
+
file,
|
|
18
|
+
(node) => iterate_node(project, context, node),
|
|
19
|
+
context,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function iterate_node(
|
|
24
|
+
project: IProject,
|
|
25
|
+
context: ts.TransformationContext,
|
|
26
|
+
node: ts.Node,
|
|
27
|
+
): ts.Node {
|
|
28
|
+
return ts.visitEachChild(
|
|
29
|
+
try_transform_node(project, node),
|
|
30
|
+
(child) => iterate_node(project, context, child),
|
|
31
|
+
context,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function try_transform_node(project: IProject, node: ts.Node): ts.Node {
|
|
36
|
+
try {
|
|
37
|
+
return NodeTransformer.transform(project, node);
|
|
38
|
+
} catch (exp) {
|
|
39
|
+
if (!(exp instanceof Error)) throw exp;
|
|
40
|
+
|
|
41
|
+
const file: ts.SourceFile = node.getSourceFile();
|
|
42
|
+
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
43
|
+
node.pos,
|
|
44
|
+
);
|
|
45
|
+
exp.message += ` - ${file.fileName}:${line + 1}:${character + 1}`;
|
|
46
|
+
throw exp;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ITransformOptions } from "./ITransformOptions";
|
|
4
|
-
|
|
5
|
-
export interface IProject {
|
|
6
|
-
program: ts.Program;
|
|
7
|
-
compilerOptions: ts.CompilerOptions;
|
|
8
|
-
checker: ts.TypeChecker;
|
|
9
|
-
printer: ts.Printer;
|
|
10
|
-
options: ITransformOptions;
|
|
11
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ITransformOptions } from "./ITransformOptions";
|
|
4
|
+
|
|
5
|
+
export interface IProject {
|
|
6
|
+
program: ts.Program;
|
|
7
|
+
compilerOptions: ts.CompilerOptions;
|
|
8
|
+
checker: ts.TypeChecker;
|
|
9
|
+
printer: ts.Printer;
|
|
10
|
+
options: ITransformOptions;
|
|
11
|
+
}
|
|
@@ -44,4 +44,15 @@ export interface ITransformOptions {
|
|
|
44
44
|
* @default false
|
|
45
45
|
*/
|
|
46
46
|
functional?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether to check undefined value or not.
|
|
50
|
+
*
|
|
51
|
+
* JavaScript can assign `undefined` value to a specific property and it is an
|
|
52
|
+
* issue when validating without allowing superfluous properties. Should undefined
|
|
53
|
+
* value assigned superfluous property be allowed or not?
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
undefined?: boolean;
|
|
47
58
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { CallExpressionTransformer } from "./CallExpressionTransformer";
|
|
4
|
-
import { IProject } from "./IProject";
|
|
5
|
-
|
|
6
|
-
// import { ExpressionWithArgumentTransformer } from "./ExpressionWithArgumentTransformer";
|
|
7
|
-
|
|
8
|
-
export namespace NodeTransformer {
|
|
9
|
-
export function transform(project: IProject, expression: ts.Node): ts.Node {
|
|
10
|
-
if (ts.isCallExpression(expression))
|
|
11
|
-
return CallExpressionTransformer.transform(project, expression);
|
|
12
|
-
// else if (ts.isExpressionWithTypeArguments(expression))
|
|
13
|
-
// return ExpressionWithArgumentTransformer.transform(
|
|
14
|
-
// project,
|
|
15
|
-
// expression,
|
|
16
|
-
// );
|
|
17
|
-
return expression;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { CallExpressionTransformer } from "./CallExpressionTransformer";
|
|
4
|
+
import { IProject } from "./IProject";
|
|
5
|
+
|
|
6
|
+
// import { ExpressionWithArgumentTransformer } from "./ExpressionWithArgumentTransformer";
|
|
7
|
+
|
|
8
|
+
export namespace NodeTransformer {
|
|
9
|
+
export function transform(project: IProject, expression: ts.Node): ts.Node {
|
|
10
|
+
if (ts.isCallExpression(expression))
|
|
11
|
+
return CallExpressionTransformer.transform(project, expression);
|
|
12
|
+
// else if (ts.isExpressionWithTypeArguments(expression))
|
|
13
|
+
// return ExpressionWithArgumentTransformer.transform(
|
|
14
|
+
// project,
|
|
15
|
+
// expression,
|
|
16
|
+
// );
|
|
17
|
+
return expression;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
4
|
-
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
5
|
-
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
6
|
-
|
|
7
|
-
import { IMetadataApplication } from "../../../metadata/IMetadataApplication";
|
|
8
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
9
|
-
|
|
10
|
-
import { IProject } from "../../IProject";
|
|
11
|
-
|
|
12
|
-
export namespace MetadataTransformer {
|
|
13
|
-
export function transform(
|
|
14
|
-
{ checker }: IProject,
|
|
15
|
-
_modulo: ts.LeftHandSideExpression,
|
|
16
|
-
expression: ts.CallExpression,
|
|
17
|
-
): ts.Expression {
|
|
18
|
-
if (!expression.typeArguments?.length)
|
|
19
|
-
throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
|
|
20
|
-
|
|
21
|
-
// VALIDATE TUPLE ARGUMENTS
|
|
22
|
-
const top: ts.Node = expression.typeArguments[0]!;
|
|
23
|
-
if (!ts.isTupleTypeNode(top)) return expression;
|
|
24
|
-
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
25
|
-
return expression;
|
|
26
|
-
|
|
27
|
-
// GET TYPES
|
|
28
|
-
const types: ts.Type[] = top.elements.map((child) =>
|
|
29
|
-
checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
30
|
-
);
|
|
31
|
-
if (types.some((t) => t.isTypeParameter()))
|
|
32
|
-
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
33
|
-
|
|
34
|
-
// METADATA
|
|
35
|
-
const collection: MetadataCollection = new MetadataCollection();
|
|
36
|
-
const metadatas: Array<Metadata> = types.map((type) =>
|
|
37
|
-
MetadataFactory.generate(checker, collection, type, {
|
|
38
|
-
resolve: false,
|
|
39
|
-
constant: true,
|
|
40
|
-
}),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// CONVERT TO PRIMITIVE TYPE
|
|
44
|
-
const app: IMetadataApplication = {
|
|
45
|
-
metadatas: metadatas.map((metadata) => metadata.toJSON()),
|
|
46
|
-
collection: collection.objects().map((obj) => obj.toJSON()),
|
|
47
|
-
};
|
|
48
|
-
return LiteralFactory.generate(app);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const enum ErrorMessages {
|
|
53
|
-
NO_GENERIC_ARGUMENT = "Error on typia.metadata(): no generic argument.",
|
|
54
|
-
GENERIC_ARGUMENT = "Error on typia.metadata(): non-specified generic argument(s).",
|
|
55
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
4
|
+
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
6
|
+
|
|
7
|
+
import { IMetadataApplication } from "../../../metadata/IMetadataApplication";
|
|
8
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
9
|
+
|
|
10
|
+
import { IProject } from "../../IProject";
|
|
11
|
+
|
|
12
|
+
export namespace MetadataTransformer {
|
|
13
|
+
export function transform(
|
|
14
|
+
{ checker }: IProject,
|
|
15
|
+
_modulo: ts.LeftHandSideExpression,
|
|
16
|
+
expression: ts.CallExpression,
|
|
17
|
+
): ts.Expression {
|
|
18
|
+
if (!expression.typeArguments?.length)
|
|
19
|
+
throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
|
|
20
|
+
|
|
21
|
+
// VALIDATE TUPLE ARGUMENTS
|
|
22
|
+
const top: ts.Node = expression.typeArguments[0]!;
|
|
23
|
+
if (!ts.isTupleTypeNode(top)) return expression;
|
|
24
|
+
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
25
|
+
return expression;
|
|
26
|
+
|
|
27
|
+
// GET TYPES
|
|
28
|
+
const types: ts.Type[] = top.elements.map((child) =>
|
|
29
|
+
checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
30
|
+
);
|
|
31
|
+
if (types.some((t) => t.isTypeParameter()))
|
|
32
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
33
|
+
|
|
34
|
+
// METADATA
|
|
35
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
36
|
+
const metadatas: Array<Metadata> = types.map((type) =>
|
|
37
|
+
MetadataFactory.generate(checker, collection, type, {
|
|
38
|
+
resolve: false,
|
|
39
|
+
constant: true,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// CONVERT TO PRIMITIVE TYPE
|
|
44
|
+
const app: IMetadataApplication = {
|
|
45
|
+
metadatas: metadatas.map((metadata) => metadata.toJSON()),
|
|
46
|
+
collection: collection.objects().map((obj) => obj.toJSON()),
|
|
47
|
+
};
|
|
48
|
+
return LiteralFactory.generate(app);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const enum ErrorMessages {
|
|
53
|
+
NO_GENERIC_ARGUMENT = "Error on typia.metadata(): no generic argument.",
|
|
54
|
+
GENERIC_ARGUMENT = "Error on typia.metadata(): non-specified generic argument(s).",
|
|
55
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { AssertParseProgrammer } from "../../../programmers/AssertParseProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace AssertParseTransformer {
|
|
8
|
-
export function transform(
|
|
9
|
-
project: IProject,
|
|
10
|
-
modulo: ts.LeftHandSideExpression,
|
|
11
|
-
expression: ts.CallExpression,
|
|
12
|
-
): ts.Expression {
|
|
13
|
-
// CHECK GENERIC ARGUMENT EXVALIDATETENCE
|
|
14
|
-
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
15
|
-
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
-
|
|
17
|
-
// GET TYPE INFO
|
|
18
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
-
expression.typeArguments[0],
|
|
20
|
-
);
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
-
|
|
24
|
-
// DO TRANSFORM
|
|
25
|
-
return ts.factory.createCallExpression(
|
|
26
|
-
AssertParseProgrammer.generate(project, modulo)(type),
|
|
27
|
-
undefined,
|
|
28
|
-
[expression.arguments[0]!],
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const enum ErrorMessages {
|
|
34
|
-
NOT_SPECIFIED = "Error on typia.assertParse(): generic argument is not specified",
|
|
35
|
-
GENERIC_ARGUMENT = "Error on typia.assertParse(): non-specified generic argument.",
|
|
36
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertParseProgrammer } from "../../../programmers/AssertParseProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace AssertParseTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXVALIDATETENCE
|
|
14
|
+
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
15
|
+
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
+
expression.typeArguments[0],
|
|
20
|
+
);
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
+
|
|
24
|
+
// DO TRANSFORM
|
|
25
|
+
return ts.factory.createCallExpression(
|
|
26
|
+
AssertParseProgrammer.generate(project, modulo)(type),
|
|
27
|
+
undefined,
|
|
28
|
+
[expression.arguments[0]!],
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const enum ErrorMessages {
|
|
34
|
+
NOT_SPECIFIED = "Error on typia.assertParse(): generic argument is not specified",
|
|
35
|
+
GENERIC_ARGUMENT = "Error on typia.assertParse(): non-specified generic argument.",
|
|
36
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { AssertParseProgrammer } from "../../../programmers/AssertParseProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace CreateAssertParseTransformer {
|
|
8
|
-
export function transform(
|
|
9
|
-
project: IProject,
|
|
10
|
-
modulo: ts.LeftHandSideExpression,
|
|
11
|
-
expression: ts.CallExpression,
|
|
12
|
-
): ts.Expression {
|
|
13
|
-
// CHECK GENERIC ARGUMENT EXASSERTTENCE
|
|
14
|
-
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
15
|
-
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
-
|
|
17
|
-
// GET TYPE INFO
|
|
18
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
-
expression.typeArguments[0],
|
|
20
|
-
);
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
-
|
|
24
|
-
// DO TRANSFORM
|
|
25
|
-
return AssertParseProgrammer.generate(project, modulo)(type);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const enum ErrorMessages {
|
|
30
|
-
NOT_SPECIFIED = "Error on typia.assertParse(): generic argument is not specified.",
|
|
31
|
-
GENERIC_ARGUMENT = "Error on typia.assertParse(): non-specified generic argument.",
|
|
32
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertParseProgrammer } from "../../../programmers/AssertParseProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace CreateAssertParseTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXASSERTTENCE
|
|
14
|
+
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
15
|
+
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
+
expression.typeArguments[0],
|
|
20
|
+
);
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
+
|
|
24
|
+
// DO TRANSFORM
|
|
25
|
+
return AssertParseProgrammer.generate(project, modulo)(type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const enum ErrorMessages {
|
|
30
|
+
NOT_SPECIFIED = "Error on typia.assertParse(): generic argument is not specified.",
|
|
31
|
+
GENERIC_ARGUMENT = "Error on typia.assertParse(): non-specified generic argument.",
|
|
32
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IsParseProgrammer } from "../../../programmers/IsParseProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace CreateIsParseTransformer {
|
|
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 || !expression.typeArguments[0])
|
|
15
|
-
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
-
|
|
17
|
-
// GET TYPE INFO
|
|
18
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
-
expression.typeArguments[0],
|
|
20
|
-
);
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
-
|
|
24
|
-
// DO TRANSFORM
|
|
25
|
-
return IsParseProgrammer.generate(project, modulo)(type);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const enum ErrorMessages {
|
|
30
|
-
NOT_SPECIFIED = "Error on typia.isParse(): generic argument is not specified.",
|
|
31
|
-
GENERIC_ARGUMENT = "Error on typia.isParse(): non-specified generic argument.",
|
|
32
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IsParseProgrammer } from "../../../programmers/IsParseProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace CreateIsParseTransformer {
|
|
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 || !expression.typeArguments[0])
|
|
15
|
+
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
+
expression.typeArguments[0],
|
|
20
|
+
);
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
+
|
|
24
|
+
// DO TRANSFORM
|
|
25
|
+
return IsParseProgrammer.generate(project, modulo)(type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const enum ErrorMessages {
|
|
30
|
+
NOT_SPECIFIED = "Error on typia.isParse(): generic argument is not specified.",
|
|
31
|
+
GENERIC_ARGUMENT = "Error on typia.isParse(): non-specified generic argument.",
|
|
32
|
+
}
|