typia 3.4.15 → 3.5.0-dev.20221222
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 +48 -7
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +119 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +11 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +134 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +2 -3
- package/src/executable/internal/TypiaSetupWizard.ts +173 -173
- package/src/factories/MetadataCollection.ts +83 -122
- package/src/factories/MetadataFactory.ts +47 -47
- package/src/factories/MetadataTagFactory.ts +351 -351
- package/src/factories/ProtocolFactory.ts +92 -0
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
- package/src/functional/$number.ts +12 -12
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +11 -0
- package/src/metadata/IMetadataTag.ts +137 -122
- package/src/metadata/Metadata.ts +479 -477
- package/src/module.ts +1547 -1535
- package/src/programmers/AssertParseProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +445 -445
- package/src/programmers/AssertStringifyProgrammer.ts +65 -65
- package/src/programmers/CheckerProgrammer.ts +810 -810
- package/src/programmers/IsParseProgrammer.ts +61 -61
- package/src/programmers/IsProgrammer.ts +175 -175
- package/src/programmers/IsStringifyProgrammer.ts +69 -69
- package/src/programmers/MessageProgrammer.ts +116 -0
- package/src/programmers/StringifyProgrammer.ts +762 -762
- package/src/programmers/ValidateParseProgrammer.ts +59 -59
- package/src/programmers/ValidateProgrammer.ts +237 -237
- package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +231 -228
- package/src/programmers/internal/check_bigint.ts +85 -85
- package/src/programmers/internal/check_number.ts +175 -175
- package/src/schemas/IJsonSchema.ts +90 -90
- package/src/transformers/CallExpressionTransformer.ts +131 -124
- package/src/transformers/ITransformOptions.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -1,124 +1,131 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { IProject } from "./IProject";
|
|
5
|
-
import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
|
|
6
|
-
import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
|
|
7
|
-
import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
|
|
8
|
-
import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
|
|
9
|
-
import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
|
|
10
|
-
import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
|
|
11
|
-
import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
|
|
12
|
-
import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
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
|
-
const
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { IProject } from "./IProject";
|
|
5
|
+
import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
|
|
6
|
+
import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
|
|
7
|
+
import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
|
|
8
|
+
import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
|
|
9
|
+
import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
|
|
10
|
+
import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
|
|
11
|
+
import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
|
|
12
|
+
import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
|
|
13
|
+
import { MessageTransformer } from "./features/protocols/MessageTransformer";
|
|
14
|
+
import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
|
|
15
|
+
import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
|
|
16
|
+
import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
|
|
17
|
+
import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
|
|
18
|
+
import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
|
|
19
|
+
import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
|
|
20
|
+
import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
|
|
21
|
+
import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
|
|
22
|
+
import { AssertTransformer } from "./features/validators/AssertTransformer";
|
|
23
|
+
import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
|
|
24
|
+
import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
|
|
25
|
+
import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
|
|
26
|
+
import { IsTransformer } from "./features/validators/IsTransformer";
|
|
27
|
+
import { ValidateTransformer } from "./features/validators/ValidateTransformer";
|
|
28
|
+
|
|
29
|
+
export namespace CallExpressionTransformer {
|
|
30
|
+
export function transform(
|
|
31
|
+
project: IProject,
|
|
32
|
+
expression: ts.CallExpression,
|
|
33
|
+
): ts.Expression {
|
|
34
|
+
//----
|
|
35
|
+
// VALIDATIONS
|
|
36
|
+
//----
|
|
37
|
+
// SIGNATURE DECLARATION
|
|
38
|
+
const declaration: ts.Declaration | undefined =
|
|
39
|
+
project.checker.getResolvedSignature(expression)?.declaration;
|
|
40
|
+
if (!declaration) return expression;
|
|
41
|
+
|
|
42
|
+
// FILE PATH
|
|
43
|
+
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
44
|
+
if (file.indexOf(LIB_PATH) === -1 && file !== SRC_PATH)
|
|
45
|
+
return expression;
|
|
46
|
+
|
|
47
|
+
//----
|
|
48
|
+
// TRANSFORMATION
|
|
49
|
+
//----
|
|
50
|
+
// FUNCTION NAME
|
|
51
|
+
const { name } = project.checker.getTypeAtLocation(declaration).symbol;
|
|
52
|
+
|
|
53
|
+
// FIND TRANSFORMER
|
|
54
|
+
const functor: (() => Task) | undefined = FUNCTORS[name];
|
|
55
|
+
if (functor === undefined) return expression;
|
|
56
|
+
|
|
57
|
+
// RETURNS WITH TRANSFORMATION
|
|
58
|
+
return functor()(project, expression.expression, expression);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type Task = (
|
|
63
|
+
project: IProject,
|
|
64
|
+
modulo: ts.LeftHandSideExpression,
|
|
65
|
+
expression: ts.CallExpression,
|
|
66
|
+
) => ts.Expression;
|
|
67
|
+
|
|
68
|
+
const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
|
|
69
|
+
const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
70
|
+
|
|
71
|
+
const FUNCTORS: Record<string, () => Task> = {
|
|
72
|
+
//----
|
|
73
|
+
// VALIDATORS
|
|
74
|
+
//----
|
|
75
|
+
// BASIC VALIDATORS
|
|
76
|
+
assert: () => AssertTransformer.transform(false),
|
|
77
|
+
assertType: () => AssertTransformer.transform(false),
|
|
78
|
+
is: () => IsTransformer.transform(false),
|
|
79
|
+
validate: () => ValidateTransformer.transform(false),
|
|
80
|
+
|
|
81
|
+
// STRICT VALIDATORS
|
|
82
|
+
assertEquals: () => AssertTransformer.transform(true),
|
|
83
|
+
equals: () => IsTransformer.transform(true),
|
|
84
|
+
validateEquals: () => ValidateTransformer.transform(true),
|
|
85
|
+
|
|
86
|
+
//----
|
|
87
|
+
// PROTOCOL BUFFER
|
|
88
|
+
//----
|
|
89
|
+
message: () => MessageTransformer.transform,
|
|
90
|
+
|
|
91
|
+
//----
|
|
92
|
+
// JSON FUNCTIONS
|
|
93
|
+
//----
|
|
94
|
+
// SCHEMA DEFINITION
|
|
95
|
+
application: () => ApplicationTransformer.transform,
|
|
96
|
+
|
|
97
|
+
// PARSER FUNCTIONS
|
|
98
|
+
isParse: () => IsParseTransformer.transform,
|
|
99
|
+
assertParse: () => AssertParseTransformer.transform,
|
|
100
|
+
validateParse: () => ValidateParseTransformer.transform,
|
|
101
|
+
|
|
102
|
+
// STRINGIFY FUNCTIONS
|
|
103
|
+
stringify: () => StringifyTransformer.transform,
|
|
104
|
+
assertStringify: () => AssertStringifyTransformer.transform,
|
|
105
|
+
isStringify: () => IsStringifyTransformer.transform,
|
|
106
|
+
validateStringify: () => ValidateStringifyTransformer.transform,
|
|
107
|
+
|
|
108
|
+
// MISC
|
|
109
|
+
metadata: () => MetadataTransformer.transform,
|
|
110
|
+
|
|
111
|
+
//----
|
|
112
|
+
// FACTORY FUNCTIONS
|
|
113
|
+
//----
|
|
114
|
+
// VALIDATORS
|
|
115
|
+
createAssert: () => CreateAssertTransformer.transform(false),
|
|
116
|
+
createAssertType: () => CreateAssertTransformer.transform(false),
|
|
117
|
+
createIs: () => CreateIsTransformer.transform(false),
|
|
118
|
+
createValidate: () => CreateValidateTransformer.transform(false),
|
|
119
|
+
createAssertEquals: () => CreateAssertTransformer.transform(true),
|
|
120
|
+
createEquals: () => CreateIsTransformer.transform(true),
|
|
121
|
+
createValidateEquals: () => CreateValidateTransformer.transform(true),
|
|
122
|
+
|
|
123
|
+
// JSON FUNCTIONS
|
|
124
|
+
createIsParse: () => CreateIsParseTransformer.transform,
|
|
125
|
+
createAssertParse: () => CreateAssertParseTransformer.transform,
|
|
126
|
+
createValidateParse: () => CreateValidateParseTransformer.transform,
|
|
127
|
+
createStringify: () => CreateStringifyTransformer.transform,
|
|
128
|
+
createAssertStringify: () => CreateAssertStringifyTransformer.transform,
|
|
129
|
+
createIsStringify: () => CreateIsStringifyTransformer.transform,
|
|
130
|
+
createValidateStringify: () => CreateValidateStringifyTransformer.transform,
|
|
131
|
+
};
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
export interface ITransformOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Whether to validate finite number or not.
|
|
4
|
-
*
|
|
5
|
-
* If configured true, number typed values would be validated by Number.isNaN().
|
|
6
|
-
*
|
|
7
|
-
* However, whatever you configure, it would be ignored when marshaling or parsing.
|
|
8
|
-
*
|
|
9
|
-
* - when marshaling, always be true
|
|
10
|
-
* - assertStringify()
|
|
11
|
-
* - validateEncode()
|
|
12
|
-
* - when parsing, always be false
|
|
13
|
-
* - assertParse()
|
|
14
|
-
* - isDecode()
|
|
15
|
-
*
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
finite?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Whether to validate finite number or not.
|
|
22
|
-
*
|
|
23
|
-
* If configured true, number typed values would be validated by Number.isFinite().
|
|
24
|
-
*
|
|
25
|
-
* However, whatever you configure, it can be ignored in below case.
|
|
26
|
-
*
|
|
27
|
-
* - when `finite` option is true, this option would be ignored
|
|
28
|
-
* - when marshaling, always be true
|
|
29
|
-
* - assertStringify()
|
|
30
|
-
* - validateEncode()
|
|
31
|
-
* - when parsing, always be false
|
|
32
|
-
* - assertParse()
|
|
33
|
-
* - isDecode()
|
|
34
|
-
*
|
|
35
|
-
* @default false
|
|
36
|
-
*/
|
|
37
|
-
numeric?: boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Whether to validate functional type or not.
|
|
41
|
-
*
|
|
42
|
-
* However, whatever you configure, it becomes false when marshaling or parsing.
|
|
43
|
-
*
|
|
44
|
-
* @default false
|
|
45
|
-
*/
|
|
46
|
-
functional?: boolean;
|
|
47
|
-
}
|
|
1
|
+
export interface ITransformOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Whether to validate finite number or not.
|
|
4
|
+
*
|
|
5
|
+
* If configured true, number typed values would be validated by Number.isNaN().
|
|
6
|
+
*
|
|
7
|
+
* However, whatever you configure, it would be ignored when marshaling or parsing.
|
|
8
|
+
*
|
|
9
|
+
* - when marshaling, always be true
|
|
10
|
+
* - assertStringify()
|
|
11
|
+
* - validateEncode()
|
|
12
|
+
* - when parsing, always be false
|
|
13
|
+
* - assertParse()
|
|
14
|
+
* - isDecode()
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
finite?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether to validate finite number or not.
|
|
22
|
+
*
|
|
23
|
+
* If configured true, number typed values would be validated by Number.isFinite().
|
|
24
|
+
*
|
|
25
|
+
* However, whatever you configure, it can be ignored in below case.
|
|
26
|
+
*
|
|
27
|
+
* - when `finite` option is true, this option would be ignored
|
|
28
|
+
* - when marshaling, always be true
|
|
29
|
+
* - assertStringify()
|
|
30
|
+
* - validateEncode()
|
|
31
|
+
* - when parsing, always be false
|
|
32
|
+
* - assertParse()
|
|
33
|
+
* - isDecode()
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
numeric?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether to validate functional type or not.
|
|
41
|
+
*
|
|
42
|
+
* However, whatever you configure, it becomes false when marshaling or parsing.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
functional?: boolean;
|
|
47
|
+
}
|
|
@@ -1,119 +1,117 @@
|
|
|
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 { Metadata } from "../../../metadata/Metadata";
|
|
8
|
-
import { IJsonApplication } from "../../../schemas/IJsonApplication";
|
|
9
|
-
|
|
10
|
-
import { ApplicationProgrammer } from "../../../programmers/ApplicationProgrammer";
|
|
11
|
-
|
|
12
|
-
import { IProject } from "../../IProject";
|
|
13
|
-
|
|
14
|
-
export namespace ApplicationTransformer {
|
|
15
|
-
export function transform(
|
|
16
|
-
{ checker }: IProject,
|
|
17
|
-
_modulo: ts.LeftHandSideExpression,
|
|
18
|
-
expression: ts.CallExpression,
|
|
19
|
-
): ts.Expression {
|
|
20
|
-
if (!expression.typeArguments?.length)
|
|
21
|
-
throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
|
|
22
|
-
|
|
23
|
-
//----
|
|
24
|
-
// GET ARGUMENTS
|
|
25
|
-
//----
|
|
26
|
-
// VALIDATE TUPLE ARGUMENTS
|
|
27
|
-
const top: ts.Node = expression.typeArguments[0]!;
|
|
28
|
-
if (!ts.isTupleTypeNode(top)) return expression;
|
|
29
|
-
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
30
|
-
return expression;
|
|
31
|
-
|
|
32
|
-
// GET TYPES
|
|
33
|
-
const types: ts.Type[] = top.elements.map((child) =>
|
|
34
|
-
checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
35
|
-
);
|
|
36
|
-
if (types.some((t) => t.isTypeParameter()))
|
|
37
|
-
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
38
|
-
|
|
39
|
-
// ADDITIONAL PARAMETERS
|
|
40
|
-
const purpose: "swagger" | "ajv" = get_parameter(
|
|
41
|
-
checker,
|
|
42
|
-
"Purpose",
|
|
43
|
-
expression.typeArguments[1],
|
|
44
|
-
(str) => str === "swagger" || str === "ajv",
|
|
45
|
-
() => "swagger",
|
|
46
|
-
);
|
|
47
|
-
const prefix: string = get_parameter(
|
|
48
|
-
checker,
|
|
49
|
-
"Prefix",
|
|
50
|
-
expression.typeArguments[2],
|
|
51
|
-
() => true,
|
|
52
|
-
() =>
|
|
53
|
-
purpose === "swagger"
|
|
54
|
-
? "#/components/schemas"
|
|
55
|
-
: "components#/schemas",
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
//----
|
|
59
|
-
// GENERATORS
|
|
60
|
-
//----
|
|
61
|
-
// METADATA
|
|
62
|
-
const collection: MetadataCollection = new MetadataCollection(
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
|
|
119
|
-
}
|
|
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 { Metadata } from "../../../metadata/Metadata";
|
|
8
|
+
import { IJsonApplication } from "../../../schemas/IJsonApplication";
|
|
9
|
+
|
|
10
|
+
import { ApplicationProgrammer } from "../../../programmers/ApplicationProgrammer";
|
|
11
|
+
|
|
12
|
+
import { IProject } from "../../IProject";
|
|
13
|
+
|
|
14
|
+
export namespace ApplicationTransformer {
|
|
15
|
+
export function transform(
|
|
16
|
+
{ checker }: IProject,
|
|
17
|
+
_modulo: ts.LeftHandSideExpression,
|
|
18
|
+
expression: ts.CallExpression,
|
|
19
|
+
): ts.Expression {
|
|
20
|
+
if (!expression.typeArguments?.length)
|
|
21
|
+
throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
|
|
22
|
+
|
|
23
|
+
//----
|
|
24
|
+
// GET ARGUMENTS
|
|
25
|
+
//----
|
|
26
|
+
// VALIDATE TUPLE ARGUMENTS
|
|
27
|
+
const top: ts.Node = expression.typeArguments[0]!;
|
|
28
|
+
if (!ts.isTupleTypeNode(top)) return expression;
|
|
29
|
+
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
30
|
+
return expression;
|
|
31
|
+
|
|
32
|
+
// GET TYPES
|
|
33
|
+
const types: ts.Type[] = top.elements.map((child) =>
|
|
34
|
+
checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
35
|
+
);
|
|
36
|
+
if (types.some((t) => t.isTypeParameter()))
|
|
37
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
38
|
+
|
|
39
|
+
// ADDITIONAL PARAMETERS
|
|
40
|
+
const purpose: "swagger" | "ajv" = get_parameter(
|
|
41
|
+
checker,
|
|
42
|
+
"Purpose",
|
|
43
|
+
expression.typeArguments[1],
|
|
44
|
+
(str) => str === "swagger" || str === "ajv",
|
|
45
|
+
() => "swagger",
|
|
46
|
+
);
|
|
47
|
+
const prefix: string = get_parameter(
|
|
48
|
+
checker,
|
|
49
|
+
"Prefix",
|
|
50
|
+
expression.typeArguments[2],
|
|
51
|
+
() => true,
|
|
52
|
+
() =>
|
|
53
|
+
purpose === "swagger"
|
|
54
|
+
? "#/components/schemas"
|
|
55
|
+
: "components#/schemas",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
//----
|
|
59
|
+
// GENERATORS
|
|
60
|
+
//----
|
|
61
|
+
// METADATA
|
|
62
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
63
|
+
const metadatas: Array<Metadata> = types.map((type) =>
|
|
64
|
+
MetadataFactory.generate(checker, collection, type, {
|
|
65
|
+
resolve: true,
|
|
66
|
+
constant: true,
|
|
67
|
+
validate: (meta) => {
|
|
68
|
+
if (meta.atomics.find((str) => str === "bigint"))
|
|
69
|
+
throw new Error(ErrorMessages.NO_BIGIT);
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// APPLICATION
|
|
75
|
+
const app: IJsonApplication = ApplicationProgrammer.generate(
|
|
76
|
+
metadatas,
|
|
77
|
+
{
|
|
78
|
+
purpose,
|
|
79
|
+
prefix,
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// RETURNS WITH LITERAL EXPRESSION
|
|
84
|
+
return LiteralFactory.generate(app);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function get_parameter<T extends string>(
|
|
88
|
+
checker: ts.TypeChecker,
|
|
89
|
+
name: string,
|
|
90
|
+
node: ts.TypeNode | undefined,
|
|
91
|
+
predicator: (value: string) => boolean,
|
|
92
|
+
defaulter: () => T,
|
|
93
|
+
): T {
|
|
94
|
+
if (!node) return defaulter();
|
|
95
|
+
|
|
96
|
+
// CHECK LITERAL TYPE
|
|
97
|
+
const type: ts.Type = checker.getTypeFromTypeNode(node);
|
|
98
|
+
if (!type.isLiteral())
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Error on typia.application(): generic argument "${name}" must be constant.`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// GET VALUE AND VALIDATE IT
|
|
104
|
+
const value = type.value;
|
|
105
|
+
if (typeof value !== "string" || predicator(value) === false)
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Error on typia.application(): invalid value on generic argument "${name}".`,
|
|
108
|
+
);
|
|
109
|
+
return value as T;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const enum ErrorMessages {
|
|
114
|
+
NO_GENERIC_ARGUMENT = "Error on typia.application(): no generic argument.",
|
|
115
|
+
GENERIC_ARGUMENT = "Error on typia.application(): non-specified generic argument(s).",
|
|
116
|
+
NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
|
|
117
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MessageProgrammer } from "../../../programmers/MessageProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace MessageTransformer {
|
|
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 MessageProgrammer.generate(project)(type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const enum ErrorMessages {
|
|
30
|
+
NOT_SPECIFIED = "Error on typia.message(): generic argument is not specified.",
|
|
31
|
+
GENERIC_ARGUMENT = "Error on typia.message(): non-specified generic argument.",
|
|
32
|
+
}
|