typia 6.7.0 → 6.7.1
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.d.ts +0 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -1
- package/lib/programmers/RandomProgrammer.d.ts +10 -1
- package/lib/programmers/RandomProgrammer.js +62 -37
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonIsStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +33 -14
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscIsCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscIsPruneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscValidateCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscValidatePruneProgrammer.d.ts +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.d.ts +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +30 -11
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationValidateGeneralProgrammer.d.ts +1 -1
- package/package.json +1 -1
- package/src/programmers/AssertProgrammer.ts +397 -398
- package/src/programmers/CheckerProgrammer.ts +1138 -1138
- package/src/programmers/FeatureProgrammer.ts +549 -549
- package/src/programmers/IsProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +112 -77
- package/src/programmers/ValidateProgrammer.ts +382 -382
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +141 -141
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +108 -108
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +98 -98
- package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
- package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +101 -101
- package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +106 -106
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +123 -123
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +267 -267
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +126 -126
- package/src/programmers/helpers/FunctionImporter.ts +97 -97
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +91 -91
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +91 -91
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +93 -93
- package/src/programmers/http/HttpFormDataProgrammer.ts +278 -278
- package/src/programmers/http/HttpHeadersProgrammer.ts +347 -347
- package/src/programmers/http/HttpIsFormDataProgrammer.ts +102 -102
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +102 -102
- package/src/programmers/http/HttpIsQueryProgrammer.ts +104 -104
- package/src/programmers/http/HttpQueryProgrammer.ts +298 -298
- package/src/programmers/http/HttpValidateFormDataProgrammer.ts +85 -85
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +85 -85
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +87 -87
- package/src/programmers/json/JsonAssertParseProgrammer.ts +96 -96
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +104 -104
- package/src/programmers/json/JsonIsParseProgrammer.ts +110 -110
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +102 -102
- package/src/programmers/json/JsonStringifyProgrammer.ts +909 -910
- package/src/programmers/json/JsonValidateParseProgrammer.ts +87 -87
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +111 -111
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +87 -87
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +87 -87
- package/src/programmers/misc/MiscCloneProgrammer.ts +781 -759
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +93 -93
- package/src/programmers/misc/MiscIsPruneProgrammer.ts +94 -94
- package/src/programmers/misc/MiscPruneProgrammer.ts +560 -560
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +104 -104
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +98 -98
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +91 -91
- package/src/programmers/notations/NotationGeneralProgrammer.ts +709 -685
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +97 -97
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +107 -107
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +91 -91
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +95 -95
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +646 -646
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +852 -852
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +104 -104
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +93 -93
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +85 -85
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +109 -109
- package/src/transformers/internal/GenericTransformer.ts +104 -104
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
6
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
7
|
-
|
|
8
|
-
import { IProject } from "../../transformers/IProject";
|
|
9
|
-
|
|
10
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
11
|
-
|
|
12
|
-
import { ValidateProgrammer } from "../ValidateProgrammer";
|
|
13
|
-
import { FunctionalValidateFunctionProgrammer } from "./FunctionalValidateFunctionProgrammer";
|
|
14
|
-
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
15
|
-
|
|
16
|
-
export namespace FunctionalValidateParametersProgrammer {
|
|
17
|
-
export const write =
|
|
18
|
-
(project: IProject) =>
|
|
19
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
20
|
-
(equals: boolean) =>
|
|
21
|
-
(
|
|
22
|
-
expression: ts.Expression,
|
|
23
|
-
declaration: ts.FunctionDeclaration,
|
|
24
|
-
): ts.CallExpression => {
|
|
25
|
-
const { async } = FunctionalGeneralProgrammer.getReturnType(
|
|
26
|
-
project.checker,
|
|
27
|
-
)(declaration);
|
|
28
|
-
const result = decompose(project)(modulo)(equals)(declaration);
|
|
29
|
-
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
30
|
-
expression,
|
|
31
|
-
undefined,
|
|
32
|
-
declaration.parameters.map((p) =>
|
|
33
|
-
ts.factory.createIdentifier(p.name.getText()),
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
return ExpressionFactory.selfCall(
|
|
37
|
-
ts.factory.createBlock(
|
|
38
|
-
[
|
|
39
|
-
...result.functions,
|
|
40
|
-
ts.factory.createReturnStatement(
|
|
41
|
-
ts.factory.createArrowFunction(
|
|
42
|
-
async
|
|
43
|
-
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
44
|
-
: undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
declaration.parameters,
|
|
47
|
-
FunctionalValidateFunctionProgrammer.getReturnTypeNode(
|
|
48
|
-
declaration,
|
|
49
|
-
async,
|
|
50
|
-
),
|
|
51
|
-
undefined,
|
|
52
|
-
ts.factory.createBlock(
|
|
53
|
-
[
|
|
54
|
-
...result.statements,
|
|
55
|
-
ts.factory.createReturnStatement(
|
|
56
|
-
ts.factory.createObjectLiteralExpression(
|
|
57
|
-
[
|
|
58
|
-
ts.factory.createPropertyAssignment(
|
|
59
|
-
"success",
|
|
60
|
-
ts.factory.createTrue(),
|
|
61
|
-
),
|
|
62
|
-
ts.factory.createPropertyAssignment(
|
|
63
|
-
"data",
|
|
64
|
-
async
|
|
65
|
-
? ts.factory.createAwaitExpression(caller)
|
|
66
|
-
: caller,
|
|
67
|
-
),
|
|
68
|
-
ts.factory.createPropertyAssignment(
|
|
69
|
-
"errors",
|
|
70
|
-
ts.factory.createArrayLiteralExpression([]),
|
|
71
|
-
),
|
|
72
|
-
],
|
|
73
|
-
true,
|
|
74
|
-
),
|
|
75
|
-
),
|
|
76
|
-
],
|
|
77
|
-
true,
|
|
78
|
-
),
|
|
79
|
-
),
|
|
80
|
-
),
|
|
81
|
-
],
|
|
82
|
-
true,
|
|
83
|
-
),
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const decompose =
|
|
88
|
-
(project: IProject) =>
|
|
89
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
90
|
-
(equals: boolean) =>
|
|
91
|
-
(
|
|
92
|
-
declaration: ts.FunctionDeclaration,
|
|
93
|
-
): {
|
|
94
|
-
functions: ts.Statement[];
|
|
95
|
-
statements: ts.Statement[];
|
|
96
|
-
} => {
|
|
97
|
-
const resultName: string = StringUtil.escapeDuplicate(
|
|
98
|
-
declaration.parameters.map((p) => p.name.getText()),
|
|
99
|
-
)("paramErrorResults");
|
|
100
|
-
const validationResultArray: ts.ArrayLiteralExpression =
|
|
101
|
-
ts.factory.createArrayLiteralExpression(
|
|
102
|
-
declaration.parameters.map((p, i) =>
|
|
103
|
-
ts.factory.createAsExpression(
|
|
104
|
-
ts.factory.createCallExpression(
|
|
105
|
-
ts.factory.createIdentifier(`__validate_param_${i}`),
|
|
106
|
-
undefined,
|
|
107
|
-
[ts.factory.createIdentifier(p.name.getText())],
|
|
108
|
-
),
|
|
109
|
-
ts.factory.createImportTypeNode(
|
|
110
|
-
ts.factory.createLiteralTypeNode(
|
|
111
|
-
ts.factory.createStringLiteral("typia"),
|
|
112
|
-
),
|
|
113
|
-
undefined,
|
|
114
|
-
ts.factory.createQualifiedName(
|
|
115
|
-
ts.factory.createIdentifier("IValidation"),
|
|
116
|
-
ts.factory.createIdentifier("IFailure"),
|
|
117
|
-
),
|
|
118
|
-
undefined,
|
|
119
|
-
false,
|
|
120
|
-
),
|
|
121
|
-
),
|
|
122
|
-
),
|
|
123
|
-
true,
|
|
124
|
-
);
|
|
125
|
-
const errorMatrix = ts.factory.createCallExpression(
|
|
126
|
-
ts.factory.createPropertyAccessExpression(validationResultArray, "map"),
|
|
127
|
-
undefined,
|
|
128
|
-
[
|
|
129
|
-
ts.factory.createArrowFunction(
|
|
130
|
-
undefined,
|
|
131
|
-
undefined,
|
|
132
|
-
[
|
|
133
|
-
IdentifierFactory.parameter("r"),
|
|
134
|
-
IdentifierFactory.parameter("i"),
|
|
135
|
-
],
|
|
136
|
-
undefined,
|
|
137
|
-
undefined,
|
|
138
|
-
ts.factory.createConditionalExpression(
|
|
139
|
-
ts.factory.createStrictEquality(
|
|
140
|
-
ts.factory.createTrue(),
|
|
141
|
-
ts.factory.createPropertyAccessExpression(
|
|
142
|
-
ts.factory.createIdentifier("r"),
|
|
143
|
-
"success",
|
|
144
|
-
),
|
|
145
|
-
),
|
|
146
|
-
undefined,
|
|
147
|
-
ts.factory.createIdentifier("r"),
|
|
148
|
-
undefined,
|
|
149
|
-
ts.factory.createObjectLiteralExpression(
|
|
150
|
-
[
|
|
151
|
-
ts.factory.createSpreadAssignment(
|
|
152
|
-
ts.factory.createIdentifier("r"),
|
|
153
|
-
),
|
|
154
|
-
ts.factory.createPropertyAssignment(
|
|
155
|
-
"errors",
|
|
156
|
-
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
157
|
-
expression: ts.factory.createPropertyAccessExpression(
|
|
158
|
-
ts.factory.createIdentifier("r"),
|
|
159
|
-
"errors",
|
|
160
|
-
),
|
|
161
|
-
replacer: ts.factory.createTemplateExpression(
|
|
162
|
-
ts.factory.createTemplateHead("$input.parameters["),
|
|
163
|
-
[
|
|
164
|
-
ts.factory.createTemplateSpan(
|
|
165
|
-
ts.factory.createIdentifier("i"),
|
|
166
|
-
ts.factory.createTemplateTail("]"),
|
|
167
|
-
),
|
|
168
|
-
],
|
|
169
|
-
),
|
|
170
|
-
}),
|
|
171
|
-
),
|
|
172
|
-
],
|
|
173
|
-
true,
|
|
174
|
-
),
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
],
|
|
178
|
-
);
|
|
179
|
-
const failures = ts.factory.createCallExpression(
|
|
180
|
-
ts.factory.createPropertyAccessExpression(errorMatrix, "filter"),
|
|
181
|
-
undefined,
|
|
182
|
-
[
|
|
183
|
-
ts.factory.createArrowFunction(
|
|
184
|
-
undefined,
|
|
185
|
-
undefined,
|
|
186
|
-
[IdentifierFactory.parameter("r")],
|
|
187
|
-
undefined,
|
|
188
|
-
undefined,
|
|
189
|
-
ts.factory.createStrictEquality(
|
|
190
|
-
ts.factory.createFalse(),
|
|
191
|
-
ts.factory.createPropertyAccessExpression(
|
|
192
|
-
ts.factory.createIdentifier("r"),
|
|
193
|
-
"success",
|
|
194
|
-
),
|
|
195
|
-
),
|
|
196
|
-
),
|
|
197
|
-
],
|
|
198
|
-
);
|
|
199
|
-
return {
|
|
200
|
-
functions: declaration.parameters.map((p, i) =>
|
|
201
|
-
StatementFactory.constant(
|
|
202
|
-
`__validate_param_${i}`,
|
|
203
|
-
ValidateProgrammer.write(project)(modulo)(equals)(
|
|
204
|
-
project.checker.getTypeFromTypeNode(
|
|
205
|
-
p.type ?? TypeFactory.keyword("any"),
|
|
206
|
-
),
|
|
207
|
-
),
|
|
208
|
-
),
|
|
209
|
-
),
|
|
210
|
-
statements: [
|
|
211
|
-
StatementFactory.constant(resultName, failures),
|
|
212
|
-
ts.factory.createIfStatement(
|
|
213
|
-
ts.factory.createStrictInequality(
|
|
214
|
-
ts.factory.createNumericLiteral("0"),
|
|
215
|
-
ts.factory.createPropertyAccessExpression(
|
|
216
|
-
ts.factory.createIdentifier(resultName),
|
|
217
|
-
"length",
|
|
218
|
-
),
|
|
219
|
-
),
|
|
220
|
-
ts.factory.createReturnStatement(
|
|
221
|
-
ts.factory.createObjectLiteralExpression(
|
|
222
|
-
[
|
|
223
|
-
ts.factory.createPropertyAssignment(
|
|
224
|
-
"success",
|
|
225
|
-
ts.factory.createFalse(),
|
|
226
|
-
),
|
|
227
|
-
ts.factory.createPropertyAssignment(
|
|
228
|
-
"errors",
|
|
229
|
-
ts.factory.createCallExpression(
|
|
230
|
-
IdentifierFactory.access(
|
|
231
|
-
ts.factory.createCallExpression(
|
|
232
|
-
IdentifierFactory.access(
|
|
233
|
-
ts.factory.createIdentifier(resultName),
|
|
234
|
-
)("map"),
|
|
235
|
-
undefined,
|
|
236
|
-
[
|
|
237
|
-
ts.factory.createArrowFunction(
|
|
238
|
-
undefined,
|
|
239
|
-
undefined,
|
|
240
|
-
[
|
|
241
|
-
IdentifierFactory.parameter(
|
|
242
|
-
"r",
|
|
243
|
-
TypeFactory.keyword("any"),
|
|
244
|
-
),
|
|
245
|
-
],
|
|
246
|
-
undefined,
|
|
247
|
-
undefined,
|
|
248
|
-
IdentifierFactory.access(
|
|
249
|
-
ts.factory.createIdentifier("r"),
|
|
250
|
-
)("errors"),
|
|
251
|
-
),
|
|
252
|
-
],
|
|
253
|
-
),
|
|
254
|
-
)("flat"),
|
|
255
|
-
undefined,
|
|
256
|
-
undefined,
|
|
257
|
-
),
|
|
258
|
-
),
|
|
259
|
-
],
|
|
260
|
-
true,
|
|
261
|
-
),
|
|
262
|
-
),
|
|
263
|
-
),
|
|
264
|
-
],
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
6
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
7
|
+
|
|
8
|
+
import { IProject } from "../../transformers/IProject";
|
|
9
|
+
|
|
10
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
11
|
+
|
|
12
|
+
import { ValidateProgrammer } from "../ValidateProgrammer";
|
|
13
|
+
import { FunctionalValidateFunctionProgrammer } from "./FunctionalValidateFunctionProgrammer";
|
|
14
|
+
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
15
|
+
|
|
16
|
+
export namespace FunctionalValidateParametersProgrammer {
|
|
17
|
+
export const write =
|
|
18
|
+
(project: IProject) =>
|
|
19
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
20
|
+
(equals: boolean) =>
|
|
21
|
+
(
|
|
22
|
+
expression: ts.Expression,
|
|
23
|
+
declaration: ts.FunctionDeclaration,
|
|
24
|
+
): ts.CallExpression => {
|
|
25
|
+
const { async } = FunctionalGeneralProgrammer.getReturnType(
|
|
26
|
+
project.checker,
|
|
27
|
+
)(declaration);
|
|
28
|
+
const result = decompose(project)(modulo)(equals)(declaration);
|
|
29
|
+
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
30
|
+
expression,
|
|
31
|
+
undefined,
|
|
32
|
+
declaration.parameters.map((p) =>
|
|
33
|
+
ts.factory.createIdentifier(p.name.getText()),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
return ExpressionFactory.selfCall(
|
|
37
|
+
ts.factory.createBlock(
|
|
38
|
+
[
|
|
39
|
+
...result.functions,
|
|
40
|
+
ts.factory.createReturnStatement(
|
|
41
|
+
ts.factory.createArrowFunction(
|
|
42
|
+
async
|
|
43
|
+
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
44
|
+
: undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
declaration.parameters,
|
|
47
|
+
FunctionalValidateFunctionProgrammer.getReturnTypeNode(
|
|
48
|
+
declaration,
|
|
49
|
+
async,
|
|
50
|
+
),
|
|
51
|
+
undefined,
|
|
52
|
+
ts.factory.createBlock(
|
|
53
|
+
[
|
|
54
|
+
...result.statements,
|
|
55
|
+
ts.factory.createReturnStatement(
|
|
56
|
+
ts.factory.createObjectLiteralExpression(
|
|
57
|
+
[
|
|
58
|
+
ts.factory.createPropertyAssignment(
|
|
59
|
+
"success",
|
|
60
|
+
ts.factory.createTrue(),
|
|
61
|
+
),
|
|
62
|
+
ts.factory.createPropertyAssignment(
|
|
63
|
+
"data",
|
|
64
|
+
async
|
|
65
|
+
? ts.factory.createAwaitExpression(caller)
|
|
66
|
+
: caller,
|
|
67
|
+
),
|
|
68
|
+
ts.factory.createPropertyAssignment(
|
|
69
|
+
"errors",
|
|
70
|
+
ts.factory.createArrayLiteralExpression([]),
|
|
71
|
+
),
|
|
72
|
+
],
|
|
73
|
+
true,
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
],
|
|
77
|
+
true,
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
],
|
|
82
|
+
true,
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const decompose =
|
|
88
|
+
(project: IProject) =>
|
|
89
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
90
|
+
(equals: boolean) =>
|
|
91
|
+
(
|
|
92
|
+
declaration: ts.FunctionDeclaration,
|
|
93
|
+
): {
|
|
94
|
+
functions: ts.Statement[];
|
|
95
|
+
statements: ts.Statement[];
|
|
96
|
+
} => {
|
|
97
|
+
const resultName: string = StringUtil.escapeDuplicate(
|
|
98
|
+
declaration.parameters.map((p) => p.name.getText()),
|
|
99
|
+
)("paramErrorResults");
|
|
100
|
+
const validationResultArray: ts.ArrayLiteralExpression =
|
|
101
|
+
ts.factory.createArrayLiteralExpression(
|
|
102
|
+
declaration.parameters.map((p, i) =>
|
|
103
|
+
ts.factory.createAsExpression(
|
|
104
|
+
ts.factory.createCallExpression(
|
|
105
|
+
ts.factory.createIdentifier(`__validate_param_${i}`),
|
|
106
|
+
undefined,
|
|
107
|
+
[ts.factory.createIdentifier(p.name.getText())],
|
|
108
|
+
),
|
|
109
|
+
ts.factory.createImportTypeNode(
|
|
110
|
+
ts.factory.createLiteralTypeNode(
|
|
111
|
+
ts.factory.createStringLiteral("typia"),
|
|
112
|
+
),
|
|
113
|
+
undefined,
|
|
114
|
+
ts.factory.createQualifiedName(
|
|
115
|
+
ts.factory.createIdentifier("IValidation"),
|
|
116
|
+
ts.factory.createIdentifier("IFailure"),
|
|
117
|
+
),
|
|
118
|
+
undefined,
|
|
119
|
+
false,
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
true,
|
|
124
|
+
);
|
|
125
|
+
const errorMatrix = ts.factory.createCallExpression(
|
|
126
|
+
ts.factory.createPropertyAccessExpression(validationResultArray, "map"),
|
|
127
|
+
undefined,
|
|
128
|
+
[
|
|
129
|
+
ts.factory.createArrowFunction(
|
|
130
|
+
undefined,
|
|
131
|
+
undefined,
|
|
132
|
+
[
|
|
133
|
+
IdentifierFactory.parameter("r"),
|
|
134
|
+
IdentifierFactory.parameter("i"),
|
|
135
|
+
],
|
|
136
|
+
undefined,
|
|
137
|
+
undefined,
|
|
138
|
+
ts.factory.createConditionalExpression(
|
|
139
|
+
ts.factory.createStrictEquality(
|
|
140
|
+
ts.factory.createTrue(),
|
|
141
|
+
ts.factory.createPropertyAccessExpression(
|
|
142
|
+
ts.factory.createIdentifier("r"),
|
|
143
|
+
"success",
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
undefined,
|
|
147
|
+
ts.factory.createIdentifier("r"),
|
|
148
|
+
undefined,
|
|
149
|
+
ts.factory.createObjectLiteralExpression(
|
|
150
|
+
[
|
|
151
|
+
ts.factory.createSpreadAssignment(
|
|
152
|
+
ts.factory.createIdentifier("r"),
|
|
153
|
+
),
|
|
154
|
+
ts.factory.createPropertyAssignment(
|
|
155
|
+
"errors",
|
|
156
|
+
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
157
|
+
expression: ts.factory.createPropertyAccessExpression(
|
|
158
|
+
ts.factory.createIdentifier("r"),
|
|
159
|
+
"errors",
|
|
160
|
+
),
|
|
161
|
+
replacer: ts.factory.createTemplateExpression(
|
|
162
|
+
ts.factory.createTemplateHead("$input.parameters["),
|
|
163
|
+
[
|
|
164
|
+
ts.factory.createTemplateSpan(
|
|
165
|
+
ts.factory.createIdentifier("i"),
|
|
166
|
+
ts.factory.createTemplateTail("]"),
|
|
167
|
+
),
|
|
168
|
+
],
|
|
169
|
+
),
|
|
170
|
+
}),
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
true,
|
|
174
|
+
),
|
|
175
|
+
),
|
|
176
|
+
),
|
|
177
|
+
],
|
|
178
|
+
);
|
|
179
|
+
const failures = ts.factory.createCallExpression(
|
|
180
|
+
ts.factory.createPropertyAccessExpression(errorMatrix, "filter"),
|
|
181
|
+
undefined,
|
|
182
|
+
[
|
|
183
|
+
ts.factory.createArrowFunction(
|
|
184
|
+
undefined,
|
|
185
|
+
undefined,
|
|
186
|
+
[IdentifierFactory.parameter("r")],
|
|
187
|
+
undefined,
|
|
188
|
+
undefined,
|
|
189
|
+
ts.factory.createStrictEquality(
|
|
190
|
+
ts.factory.createFalse(),
|
|
191
|
+
ts.factory.createPropertyAccessExpression(
|
|
192
|
+
ts.factory.createIdentifier("r"),
|
|
193
|
+
"success",
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
),
|
|
197
|
+
],
|
|
198
|
+
);
|
|
199
|
+
return {
|
|
200
|
+
functions: declaration.parameters.map((p, i) =>
|
|
201
|
+
StatementFactory.constant(
|
|
202
|
+
`__validate_param_${i}`,
|
|
203
|
+
ValidateProgrammer.write(project)(modulo)(equals)(
|
|
204
|
+
project.checker.getTypeFromTypeNode(
|
|
205
|
+
p.type ?? TypeFactory.keyword("any"),
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
),
|
|
209
|
+
),
|
|
210
|
+
statements: [
|
|
211
|
+
StatementFactory.constant(resultName, failures),
|
|
212
|
+
ts.factory.createIfStatement(
|
|
213
|
+
ts.factory.createStrictInequality(
|
|
214
|
+
ts.factory.createNumericLiteral("0"),
|
|
215
|
+
ts.factory.createPropertyAccessExpression(
|
|
216
|
+
ts.factory.createIdentifier(resultName),
|
|
217
|
+
"length",
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
ts.factory.createReturnStatement(
|
|
221
|
+
ts.factory.createObjectLiteralExpression(
|
|
222
|
+
[
|
|
223
|
+
ts.factory.createPropertyAssignment(
|
|
224
|
+
"success",
|
|
225
|
+
ts.factory.createFalse(),
|
|
226
|
+
),
|
|
227
|
+
ts.factory.createPropertyAssignment(
|
|
228
|
+
"errors",
|
|
229
|
+
ts.factory.createCallExpression(
|
|
230
|
+
IdentifierFactory.access(
|
|
231
|
+
ts.factory.createCallExpression(
|
|
232
|
+
IdentifierFactory.access(
|
|
233
|
+
ts.factory.createIdentifier(resultName),
|
|
234
|
+
)("map"),
|
|
235
|
+
undefined,
|
|
236
|
+
[
|
|
237
|
+
ts.factory.createArrowFunction(
|
|
238
|
+
undefined,
|
|
239
|
+
undefined,
|
|
240
|
+
[
|
|
241
|
+
IdentifierFactory.parameter(
|
|
242
|
+
"r",
|
|
243
|
+
TypeFactory.keyword("any"),
|
|
244
|
+
),
|
|
245
|
+
],
|
|
246
|
+
undefined,
|
|
247
|
+
undefined,
|
|
248
|
+
IdentifierFactory.access(
|
|
249
|
+
ts.factory.createIdentifier("r"),
|
|
250
|
+
)("errors"),
|
|
251
|
+
),
|
|
252
|
+
],
|
|
253
|
+
),
|
|
254
|
+
)("flat"),
|
|
255
|
+
undefined,
|
|
256
|
+
undefined,
|
|
257
|
+
),
|
|
258
|
+
),
|
|
259
|
+
],
|
|
260
|
+
true,
|
|
261
|
+
),
|
|
262
|
+
),
|
|
263
|
+
),
|
|
264
|
+
],
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
}
|