typia 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/programmers/AssertProgrammer.js +4 -2
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +3 -2
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/package.json +4 -2
- package/src/IRandomGenerator.ts +33 -33
- package/src/factories/IdentifierFactory.ts +81 -81
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/programmers/AssertProgrammer.ts +38 -10
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/ValidateProgrammer.ts +36 -9
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
- package/src/typings/Customizable.ts +5 -5
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
4
|
-
import { ValueFactory } from "../../factories/ValueFactory";
|
|
5
|
-
|
|
6
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
7
|
-
|
|
8
|
-
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export function stringify_regular_properties(
|
|
14
|
-
regular: IExpressionEntry<ts.Expression>[],
|
|
15
|
-
dynamic: IExpressionEntry<ts.Expression>[],
|
|
16
|
-
): ts.Expression[] {
|
|
17
|
-
const output: ts.Expression[] = [];
|
|
18
|
-
|
|
19
|
-
regular.sort((x, y) => sequence(x.meta) - sequence(y.meta));
|
|
20
|
-
regular.forEach((entry, index) => {
|
|
21
|
-
// BASE ELEMENTS
|
|
22
|
-
const key: string = entry.key.getSoleLiteral()!;
|
|
23
|
-
const base: ts.Expression[] = [
|
|
24
|
-
ts.factory.createStringLiteral(`${JSON.stringify(key)}:`),
|
|
25
|
-
entry.expression,
|
|
26
|
-
];
|
|
27
|
-
if (index !== regular.length - 1 || dynamic.length !== 0)
|
|
28
|
-
base.push(ts.factory.createStringLiteral(`,`));
|
|
29
|
-
|
|
30
|
-
const empty: boolean =
|
|
31
|
-
(entry.meta.required === false &&
|
|
32
|
-
entry.meta.nullable === false &&
|
|
33
|
-
entry.meta.size() === 0) ||
|
|
34
|
-
(entry.meta.functional &&
|
|
35
|
-
entry.meta.nullable === false &&
|
|
36
|
-
entry.meta.size() === 1);
|
|
37
|
-
|
|
38
|
-
if (empty === true) return;
|
|
39
|
-
else if (
|
|
40
|
-
entry.meta.required === false ||
|
|
41
|
-
entry.meta.functional === true ||
|
|
42
|
-
entry.meta.any === true
|
|
43
|
-
)
|
|
44
|
-
output.push(
|
|
45
|
-
ts.factory.createConditionalExpression(
|
|
46
|
-
(() => {
|
|
47
|
-
const conditions: ts.BinaryExpression[] = [];
|
|
48
|
-
if (entry.meta.required === false || entry.meta.any)
|
|
49
|
-
conditions.push(
|
|
50
|
-
ts.factory.createStrictEquality(
|
|
51
|
-
ts.factory.createIdentifier("undefined"),
|
|
52
|
-
entry.input,
|
|
53
|
-
),
|
|
54
|
-
);
|
|
55
|
-
if (entry.meta.functional || entry.meta.any)
|
|
56
|
-
conditions.push(
|
|
57
|
-
ts.factory.createStrictEquality(
|
|
58
|
-
ts.factory.createStringLiteral("function"),
|
|
59
|
-
ValueFactory.TYPEOF(entry.input),
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
return conditions.length === 1
|
|
63
|
-
? conditions[0]!
|
|
64
|
-
: conditions.reduce((x, y) =>
|
|
65
|
-
ts.factory.createLogicalOr(x, y),
|
|
66
|
-
);
|
|
67
|
-
})(),
|
|
68
|
-
undefined,
|
|
69
|
-
ts.factory.createStringLiteral(""),
|
|
70
|
-
undefined,
|
|
71
|
-
TemplateFactory.generate(base),
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
else output.push(...base);
|
|
75
|
-
});
|
|
76
|
-
return output;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
function sequence(meta: Metadata): number {
|
|
83
|
-
return meta.any || !meta.required || meta.functional ? 0 : 1;
|
|
84
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
4
|
+
import { ValueFactory } from "../../factories/ValueFactory";
|
|
5
|
+
|
|
6
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
7
|
+
|
|
8
|
+
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function stringify_regular_properties(
|
|
14
|
+
regular: IExpressionEntry<ts.Expression>[],
|
|
15
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
16
|
+
): ts.Expression[] {
|
|
17
|
+
const output: ts.Expression[] = [];
|
|
18
|
+
|
|
19
|
+
regular.sort((x, y) => sequence(x.meta) - sequence(y.meta));
|
|
20
|
+
regular.forEach((entry, index) => {
|
|
21
|
+
// BASE ELEMENTS
|
|
22
|
+
const key: string = entry.key.getSoleLiteral()!;
|
|
23
|
+
const base: ts.Expression[] = [
|
|
24
|
+
ts.factory.createStringLiteral(`${JSON.stringify(key)}:`),
|
|
25
|
+
entry.expression,
|
|
26
|
+
];
|
|
27
|
+
if (index !== regular.length - 1 || dynamic.length !== 0)
|
|
28
|
+
base.push(ts.factory.createStringLiteral(`,`));
|
|
29
|
+
|
|
30
|
+
const empty: boolean =
|
|
31
|
+
(entry.meta.required === false &&
|
|
32
|
+
entry.meta.nullable === false &&
|
|
33
|
+
entry.meta.size() === 0) ||
|
|
34
|
+
(entry.meta.functional &&
|
|
35
|
+
entry.meta.nullable === false &&
|
|
36
|
+
entry.meta.size() === 1);
|
|
37
|
+
|
|
38
|
+
if (empty === true) return;
|
|
39
|
+
else if (
|
|
40
|
+
entry.meta.required === false ||
|
|
41
|
+
entry.meta.functional === true ||
|
|
42
|
+
entry.meta.any === true
|
|
43
|
+
)
|
|
44
|
+
output.push(
|
|
45
|
+
ts.factory.createConditionalExpression(
|
|
46
|
+
(() => {
|
|
47
|
+
const conditions: ts.BinaryExpression[] = [];
|
|
48
|
+
if (entry.meta.required === false || entry.meta.any)
|
|
49
|
+
conditions.push(
|
|
50
|
+
ts.factory.createStrictEquality(
|
|
51
|
+
ts.factory.createIdentifier("undefined"),
|
|
52
|
+
entry.input,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
if (entry.meta.functional || entry.meta.any)
|
|
56
|
+
conditions.push(
|
|
57
|
+
ts.factory.createStrictEquality(
|
|
58
|
+
ts.factory.createStringLiteral("function"),
|
|
59
|
+
ValueFactory.TYPEOF(entry.input),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
return conditions.length === 1
|
|
63
|
+
? conditions[0]!
|
|
64
|
+
: conditions.reduce((x, y) =>
|
|
65
|
+
ts.factory.createLogicalOr(x, y),
|
|
66
|
+
);
|
|
67
|
+
})(),
|
|
68
|
+
undefined,
|
|
69
|
+
ts.factory.createStringLiteral(""),
|
|
70
|
+
undefined,
|
|
71
|
+
TemplateFactory.generate(base),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
else output.push(...base);
|
|
75
|
+
});
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
function sequence(meta: Metadata): number {
|
|
83
|
+
return meta.any || !meta.required || meta.functional ? 0 : 1;
|
|
84
|
+
}
|
|
@@ -1,174 +1,174 @@
|
|
|
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 { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
|
|
7
|
-
import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
|
|
8
|
-
import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
|
|
9
|
-
import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
|
|
10
|
-
import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
|
|
11
|
-
import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
|
|
12
|
-
import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
|
|
13
|
-
import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
|
|
14
|
-
import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
|
|
15
|
-
import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
|
|
16
|
-
import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
|
|
17
|
-
import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
|
|
18
|
-
import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
|
|
19
|
-
import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
|
|
20
|
-
import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
|
|
21
|
-
import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
|
|
22
|
-
import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
|
|
23
|
-
import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
|
|
24
|
-
import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
|
|
25
|
-
import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
|
|
26
|
-
import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
|
|
27
|
-
import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
|
|
28
|
-
import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
|
|
29
|
-
import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
|
|
30
|
-
import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
|
|
31
|
-
import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
|
|
32
|
-
import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
|
|
33
|
-
import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
|
|
34
|
-
import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
|
|
35
|
-
import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
|
|
36
|
-
import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
|
|
37
|
-
import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
|
|
38
|
-
import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
|
|
39
|
-
import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
|
|
40
|
-
import { AssertTransformer } from "./features/validators/AssertTransformer";
|
|
41
|
-
import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
|
|
42
|
-
import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
|
|
43
|
-
import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
|
|
44
|
-
import { IsTransformer } from "./features/validators/IsTransformer";
|
|
45
|
-
import { ValidateTransformer } from "./features/validators/ValidateTransformer";
|
|
46
|
-
|
|
47
|
-
export namespace CallExpressionTransformer {
|
|
48
|
-
export function transform(
|
|
49
|
-
project: IProject,
|
|
50
|
-
expression: ts.CallExpression,
|
|
51
|
-
): ts.Expression {
|
|
52
|
-
//----
|
|
53
|
-
// VALIDATIONS
|
|
54
|
-
//----
|
|
55
|
-
// SIGNATURE DECLARATION
|
|
56
|
-
const declaration: ts.Declaration | undefined =
|
|
57
|
-
project.checker.getResolvedSignature(expression)?.declaration;
|
|
58
|
-
if (!declaration) return expression;
|
|
59
|
-
|
|
60
|
-
// FILE PATH
|
|
61
|
-
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
62
|
-
if (
|
|
63
|
-
file.indexOf(LIB_PATH) === -1 &&
|
|
64
|
-
file !== SRC_PATH &&
|
|
65
|
-
file !== CLI_PATH
|
|
66
|
-
)
|
|
67
|
-
return expression;
|
|
68
|
-
|
|
69
|
-
//----
|
|
70
|
-
// TRANSFORMATION
|
|
71
|
-
//----
|
|
72
|
-
// FUNCTION NAME
|
|
73
|
-
const { name } = project.checker.getTypeAtLocation(declaration).symbol;
|
|
74
|
-
|
|
75
|
-
// FIND TRANSFORMER
|
|
76
|
-
const functor: (() => Task) | undefined = FUNCTORS[name];
|
|
77
|
-
if (functor === undefined) return expression;
|
|
78
|
-
|
|
79
|
-
// RETURNS WITH TRANSFORMATION
|
|
80
|
-
return functor()(project, expression.expression, expression);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
type Task = (
|
|
85
|
-
project: IProject,
|
|
86
|
-
modulo: ts.LeftHandSideExpression,
|
|
87
|
-
expression: ts.CallExpression,
|
|
88
|
-
) => ts.Expression;
|
|
89
|
-
|
|
90
|
-
const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
|
|
91
|
-
const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
92
|
-
const CLI_PATH = path.resolve(
|
|
93
|
-
path.join(__dirname, "..", "..", "..", "src", "module.ts"),
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const FUNCTORS: Record<string, () => Task> = {
|
|
97
|
-
//----
|
|
98
|
-
// SINGLE FUNCTIONS
|
|
99
|
-
//----
|
|
100
|
-
// BASIC VALIDATORS
|
|
101
|
-
assert: () => AssertTransformer.transform(false),
|
|
102
|
-
assertType: () => AssertTransformer.transform(false),
|
|
103
|
-
is: () => IsTransformer.transform(false),
|
|
104
|
-
validate: () => ValidateTransformer.transform(false),
|
|
105
|
-
|
|
106
|
-
// STRICT VALIDATORS
|
|
107
|
-
assertEquals: () => AssertTransformer.transform(true),
|
|
108
|
-
equals: () => IsTransformer.transform(true),
|
|
109
|
-
validateEquals: () => ValidateTransformer.transform(true),
|
|
110
|
-
|
|
111
|
-
// PARSE FUNCTIONS
|
|
112
|
-
isParse: () => IsParseTransformer.transform,
|
|
113
|
-
assertParse: () => AssertParseTransformer.transform,
|
|
114
|
-
validateParse: () => ValidateParseTransformer.transform,
|
|
115
|
-
|
|
116
|
-
// STRINGIFY FUNCTIONS
|
|
117
|
-
application: () => ApplicationTransformer.transform,
|
|
118
|
-
stringify: () => StringifyTransformer.transform,
|
|
119
|
-
assertStringify: () => AssertStringifyTransformer.transform,
|
|
120
|
-
isStringify: () => IsStringifyTransformer.transform,
|
|
121
|
-
validateStringify: () => ValidateStringifyTransformer.transform,
|
|
122
|
-
|
|
123
|
-
// MISC
|
|
124
|
-
metadata: () => MetadataTransformer.transform,
|
|
125
|
-
random: () => RandomTransformer.transform,
|
|
126
|
-
literals: () => LiteralsTransformer.transform,
|
|
127
|
-
|
|
128
|
-
clone: () => CloneTransformer.transform,
|
|
129
|
-
assertClone: () => AssertCloneTransformer.transform,
|
|
130
|
-
isClone: () => IsCloneTransformer.transform,
|
|
131
|
-
validateClone: () => ValidateCloneTransformer.transform,
|
|
132
|
-
|
|
133
|
-
prune: () => PruneTransformer.transform,
|
|
134
|
-
assertPrune: () => AssertPruneTransformer.transform,
|
|
135
|
-
isPrune: () => IsPruneTransformer.transform,
|
|
136
|
-
validatePrune: () => ValidatePruneTransformer.transform,
|
|
137
|
-
|
|
138
|
-
//----
|
|
139
|
-
// FACTORY FUNCTIONS
|
|
140
|
-
//----
|
|
141
|
-
// BASIC VALIDATORS
|
|
142
|
-
createAssert: () => CreateAssertTransformer.transform(false),
|
|
143
|
-
createAssertType: () => CreateAssertTransformer.transform(false),
|
|
144
|
-
createIs: () => CreateIsTransformer.transform(false),
|
|
145
|
-
createValidate: () => CreateValidateTransformer.transform(false),
|
|
146
|
-
|
|
147
|
-
// STRICT VALIDATORS
|
|
148
|
-
createAssertEquals: () => CreateAssertTransformer.transform(true),
|
|
149
|
-
createEquals: () => CreateIsTransformer.transform(true),
|
|
150
|
-
createValidateEquals: () => CreateValidateTransformer.transform(true),
|
|
151
|
-
|
|
152
|
-
// PARSE FUNCTIONS
|
|
153
|
-
createIsParse: () => CreateIsParseTransformer.transform,
|
|
154
|
-
createAssertParse: () => CreateAssertParseTransformer.transform,
|
|
155
|
-
createValidateParse: () => CreateValidateParseTransformer.transform,
|
|
156
|
-
|
|
157
|
-
// STRINGIFY FUNCTIONS
|
|
158
|
-
createStringify: () => CreateStringifyTransformer.transform,
|
|
159
|
-
createAssertStringify: () => CreateAssertStringifyTransformer.transform,
|
|
160
|
-
createIsStringify: () => CreateIsStringifyTransformer.transform,
|
|
161
|
-
createValidateStringify: () => CreateValidateStringifyTransformer.transform,
|
|
162
|
-
|
|
163
|
-
// MISC
|
|
164
|
-
createRandom: () => CreateRandomTransformer.transform,
|
|
165
|
-
createClone: () => CreateCloneTransformer.transform,
|
|
166
|
-
createAssertClone: () => CreateAssertCloneTransformer.transform,
|
|
167
|
-
createIsClone: () => CreateIsCloneTransformer.transform,
|
|
168
|
-
createValidateClone: () => CreateValidateCloneTransformer.transform,
|
|
169
|
-
|
|
170
|
-
createPrune: () => CreatePruneTransformer.transform,
|
|
171
|
-
createAssertPrune: () => CreateAssertPruneTransformer.transform,
|
|
172
|
-
createIsPrune: () => CreateIsPruneTransformer.transform,
|
|
173
|
-
createValidatePrune: () => CreateValidatePruneTransformer.transform,
|
|
174
|
-
};
|
|
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 { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
|
|
7
|
+
import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
|
|
8
|
+
import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
|
|
9
|
+
import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
|
|
10
|
+
import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
|
|
11
|
+
import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
|
|
12
|
+
import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
|
|
13
|
+
import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
|
|
14
|
+
import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
|
|
15
|
+
import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
|
|
16
|
+
import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
|
|
17
|
+
import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
|
|
18
|
+
import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
|
|
19
|
+
import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
|
|
20
|
+
import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
|
|
21
|
+
import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
|
|
22
|
+
import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
|
|
23
|
+
import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
|
|
24
|
+
import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
|
|
25
|
+
import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
|
|
26
|
+
import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
|
|
27
|
+
import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
|
|
28
|
+
import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
|
|
29
|
+
import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
|
|
30
|
+
import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
|
|
31
|
+
import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
|
|
32
|
+
import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
|
|
33
|
+
import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
|
|
34
|
+
import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
|
|
35
|
+
import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
|
|
36
|
+
import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
|
|
37
|
+
import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
|
|
38
|
+
import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
|
|
39
|
+
import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
|
|
40
|
+
import { AssertTransformer } from "./features/validators/AssertTransformer";
|
|
41
|
+
import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
|
|
42
|
+
import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
|
|
43
|
+
import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
|
|
44
|
+
import { IsTransformer } from "./features/validators/IsTransformer";
|
|
45
|
+
import { ValidateTransformer } from "./features/validators/ValidateTransformer";
|
|
46
|
+
|
|
47
|
+
export namespace CallExpressionTransformer {
|
|
48
|
+
export function transform(
|
|
49
|
+
project: IProject,
|
|
50
|
+
expression: ts.CallExpression,
|
|
51
|
+
): ts.Expression {
|
|
52
|
+
//----
|
|
53
|
+
// VALIDATIONS
|
|
54
|
+
//----
|
|
55
|
+
// SIGNATURE DECLARATION
|
|
56
|
+
const declaration: ts.Declaration | undefined =
|
|
57
|
+
project.checker.getResolvedSignature(expression)?.declaration;
|
|
58
|
+
if (!declaration) return expression;
|
|
59
|
+
|
|
60
|
+
// FILE PATH
|
|
61
|
+
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
62
|
+
if (
|
|
63
|
+
file.indexOf(LIB_PATH) === -1 &&
|
|
64
|
+
file !== SRC_PATH &&
|
|
65
|
+
file !== CLI_PATH
|
|
66
|
+
)
|
|
67
|
+
return expression;
|
|
68
|
+
|
|
69
|
+
//----
|
|
70
|
+
// TRANSFORMATION
|
|
71
|
+
//----
|
|
72
|
+
// FUNCTION NAME
|
|
73
|
+
const { name } = project.checker.getTypeAtLocation(declaration).symbol;
|
|
74
|
+
|
|
75
|
+
// FIND TRANSFORMER
|
|
76
|
+
const functor: (() => Task) | undefined = FUNCTORS[name];
|
|
77
|
+
if (functor === undefined) return expression;
|
|
78
|
+
|
|
79
|
+
// RETURNS WITH TRANSFORMATION
|
|
80
|
+
return functor()(project, expression.expression, expression);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type Task = (
|
|
85
|
+
project: IProject,
|
|
86
|
+
modulo: ts.LeftHandSideExpression,
|
|
87
|
+
expression: ts.CallExpression,
|
|
88
|
+
) => ts.Expression;
|
|
89
|
+
|
|
90
|
+
const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
|
|
91
|
+
const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
92
|
+
const CLI_PATH = path.resolve(
|
|
93
|
+
path.join(__dirname, "..", "..", "..", "src", "module.ts"),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const FUNCTORS: Record<string, () => Task> = {
|
|
97
|
+
//----
|
|
98
|
+
// SINGLE FUNCTIONS
|
|
99
|
+
//----
|
|
100
|
+
// BASIC VALIDATORS
|
|
101
|
+
assert: () => AssertTransformer.transform(false),
|
|
102
|
+
assertType: () => AssertTransformer.transform(false),
|
|
103
|
+
is: () => IsTransformer.transform(false),
|
|
104
|
+
validate: () => ValidateTransformer.transform(false),
|
|
105
|
+
|
|
106
|
+
// STRICT VALIDATORS
|
|
107
|
+
assertEquals: () => AssertTransformer.transform(true),
|
|
108
|
+
equals: () => IsTransformer.transform(true),
|
|
109
|
+
validateEquals: () => ValidateTransformer.transform(true),
|
|
110
|
+
|
|
111
|
+
// PARSE FUNCTIONS
|
|
112
|
+
isParse: () => IsParseTransformer.transform,
|
|
113
|
+
assertParse: () => AssertParseTransformer.transform,
|
|
114
|
+
validateParse: () => ValidateParseTransformer.transform,
|
|
115
|
+
|
|
116
|
+
// STRINGIFY FUNCTIONS
|
|
117
|
+
application: () => ApplicationTransformer.transform,
|
|
118
|
+
stringify: () => StringifyTransformer.transform,
|
|
119
|
+
assertStringify: () => AssertStringifyTransformer.transform,
|
|
120
|
+
isStringify: () => IsStringifyTransformer.transform,
|
|
121
|
+
validateStringify: () => ValidateStringifyTransformer.transform,
|
|
122
|
+
|
|
123
|
+
// MISC
|
|
124
|
+
metadata: () => MetadataTransformer.transform,
|
|
125
|
+
random: () => RandomTransformer.transform,
|
|
126
|
+
literals: () => LiteralsTransformer.transform,
|
|
127
|
+
|
|
128
|
+
clone: () => CloneTransformer.transform,
|
|
129
|
+
assertClone: () => AssertCloneTransformer.transform,
|
|
130
|
+
isClone: () => IsCloneTransformer.transform,
|
|
131
|
+
validateClone: () => ValidateCloneTransformer.transform,
|
|
132
|
+
|
|
133
|
+
prune: () => PruneTransformer.transform,
|
|
134
|
+
assertPrune: () => AssertPruneTransformer.transform,
|
|
135
|
+
isPrune: () => IsPruneTransformer.transform,
|
|
136
|
+
validatePrune: () => ValidatePruneTransformer.transform,
|
|
137
|
+
|
|
138
|
+
//----
|
|
139
|
+
// FACTORY FUNCTIONS
|
|
140
|
+
//----
|
|
141
|
+
// BASIC VALIDATORS
|
|
142
|
+
createAssert: () => CreateAssertTransformer.transform(false),
|
|
143
|
+
createAssertType: () => CreateAssertTransformer.transform(false),
|
|
144
|
+
createIs: () => CreateIsTransformer.transform(false),
|
|
145
|
+
createValidate: () => CreateValidateTransformer.transform(false),
|
|
146
|
+
|
|
147
|
+
// STRICT VALIDATORS
|
|
148
|
+
createAssertEquals: () => CreateAssertTransformer.transform(true),
|
|
149
|
+
createEquals: () => CreateIsTransformer.transform(true),
|
|
150
|
+
createValidateEquals: () => CreateValidateTransformer.transform(true),
|
|
151
|
+
|
|
152
|
+
// PARSE FUNCTIONS
|
|
153
|
+
createIsParse: () => CreateIsParseTransformer.transform,
|
|
154
|
+
createAssertParse: () => CreateAssertParseTransformer.transform,
|
|
155
|
+
createValidateParse: () => CreateValidateParseTransformer.transform,
|
|
156
|
+
|
|
157
|
+
// STRINGIFY FUNCTIONS
|
|
158
|
+
createStringify: () => CreateStringifyTransformer.transform,
|
|
159
|
+
createAssertStringify: () => CreateAssertStringifyTransformer.transform,
|
|
160
|
+
createIsStringify: () => CreateIsStringifyTransformer.transform,
|
|
161
|
+
createValidateStringify: () => CreateValidateStringifyTransformer.transform,
|
|
162
|
+
|
|
163
|
+
// MISC
|
|
164
|
+
createRandom: () => CreateRandomTransformer.transform,
|
|
165
|
+
createClone: () => CreateCloneTransformer.transform,
|
|
166
|
+
createAssertClone: () => CreateAssertCloneTransformer.transform,
|
|
167
|
+
createIsClone: () => CreateIsCloneTransformer.transform,
|
|
168
|
+
createValidateClone: () => CreateValidateCloneTransformer.transform,
|
|
169
|
+
|
|
170
|
+
createPrune: () => CreatePruneTransformer.transform,
|
|
171
|
+
createAssertPrune: () => CreateAssertPruneTransformer.transform,
|
|
172
|
+
createIsPrune: () => CreateIsPruneTransformer.transform,
|
|
173
|
+
createValidatePrune: () => CreateValidatePruneTransformer.transform,
|
|
174
|
+
};
|
|
@@ -1,41 +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]) 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.";
|
|
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.";
|