typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010
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/factories/JsonMetadataFactory.d.ts +5 -1
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
- package/lib/internal/$httpFormdataReadArray.js.map +1 -0
- package/lib/programmers/CheckerProgrammer.js +4 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +4 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +12 -9
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.js +3 -2
- package/lib/programmers/internal/prune_object_properties.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +0 -6
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.d.ts +4 -1
- package/lib/transformers/ImportTransformer.js +34 -30
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +49 -49
- package/src/factories/ExpressionFactory.ts +164 -164
- package/src/factories/JsonMetadataFactory.ts +25 -15
- package/src/factories/LiteralFactory.ts +50 -50
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/functional.ts +750 -750
- package/src/http.ts +1042 -1042
- package/src/internal/$IProtobufWriter.ts +18 -18
- package/src/internal/$ProtobufReader.ts +194 -194
- package/src/internal/$ProtobufSizer.ts +151 -151
- package/src/internal/$ProtobufWriter.ts +145 -145
- package/src/internal/$accessExpressionAsString.ts +46 -46
- package/src/internal/$assertGuard.ts +13 -13
- package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/$httpFormDataReadBigint.ts +18 -18
- package/src/internal/$httpFormDataReadBlob.ts +10 -10
- package/src/internal/$httpFormDataReadBoolean.ts +16 -16
- package/src/internal/$httpFormDataReadFile.ts +10 -10
- package/src/internal/$httpFormDataReadNumber.ts +15 -15
- package/src/internal/$httpFormDataReadString.ts +10 -10
- package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
- package/src/internal/$httpHeaderReadBigint.ts +10 -10
- package/src/internal/$httpHeaderReadBoolean.ts +8 -8
- package/src/internal/$httpHeaderReadNumber.ts +7 -7
- package/src/internal/$httpParameterBigint.ts +10 -10
- package/src/internal/$httpParameterBoolean.ts +8 -8
- package/src/internal/$httpParameterNumber.ts +7 -7
- package/src/internal/$httpParameterString.ts +2 -2
- package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
- package/src/internal/$httpQueryReadArray.ts +4 -4
- package/src/internal/$httpQueryReadBigint.ts +12 -12
- package/src/internal/$httpQueryReadBoolean.ts +14 -14
- package/src/internal/$httpQueryReadNumber.ts +9 -9
- package/src/internal/$httpQueryReadString.ts +4 -4
- package/src/internal/$isBetween.ts +2 -2
- package/src/internal/$isBigintString.ts +8 -8
- package/src/internal/$jsonStringifyNumber.ts +12 -12
- package/src/internal/$jsonStringifyRest.ts +3 -3
- package/src/internal/$jsonStringifyString.ts +42 -42
- package/src/internal/$jsonStringifyTail.ts +2 -2
- package/src/internal/$llmApplicationFinalize.ts +18 -18
- package/src/internal/$miscCloneAny.ts +48 -48
- package/src/internal/$notationAny.ts +37 -37
- package/src/internal/$notationCamel.ts +13 -13
- package/src/internal/$notationPascal.ts +8 -8
- package/src/internal/$notationSnake.ts +43 -43
- package/src/internal/$randomArray.ts +21 -21
- package/src/internal/$randomBigint.ts +6 -6
- package/src/internal/$randomBoolean.ts +1 -1
- package/src/internal/$randomFormatByte.ts +3 -3
- package/src/internal/$randomFormatDate.ts +18 -18
- package/src/internal/$randomFormatDatetime.ts +16 -16
- package/src/internal/$randomFormatDuration.ts +27 -27
- package/src/internal/$randomFormatEmail.ts +11 -11
- package/src/internal/$randomFormatHostname.ts +6 -6
- package/src/internal/$randomFormatIdnEmail.ts +3 -3
- package/src/internal/$randomFormatIdnHostname.ts +3 -3
- package/src/internal/$randomFormatIpv4.ts +11 -11
- package/src/internal/$randomFormatIpv6.ts +11 -11
- package/src/internal/$randomFormatIri.ts +3 -3
- package/src/internal/$randomFormatIriReference.ts +3 -3
- package/src/internal/$randomFormatJsonPointer.ts +7 -7
- package/src/internal/$randomFormatPassword.ts +8 -8
- package/src/internal/$randomFormatRegex.ts +4 -4
- package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/$randomFormatTime.ts +14 -14
- package/src/internal/$randomFormatUri.ts +3 -3
- package/src/internal/$randomFormatUriReference.ts +3 -3
- package/src/internal/$randomFormatUriTemplate.ts +3 -3
- package/src/internal/$randomFormatUrl.ts +11 -11
- package/src/internal/$randomFormatUuid.ts +6 -6
- package/src/internal/$randomInteger.ts +47 -47
- package/src/internal/$randomNumber.ts +74 -74
- package/src/internal/$randomPattern.ts +10 -10
- package/src/internal/$randomPick.ts +9 -9
- package/src/internal/$randomString.ts +24 -24
- package/src/internal/$throwTypeGuardError.ts +5 -5
- package/src/internal/$validateReport.ts +13 -13
- package/src/internal/private/$__notationCapitalize.ts +2 -2
- package/src/internal/private/$__notationUnsnake.ts +24 -24
- package/src/json.ts +651 -651
- package/src/llm.ts +178 -178
- package/src/misc.ts +658 -658
- package/src/module.ts +933 -933
- package/src/notations.ts +827 -827
- package/src/programmers/CheckerProgrammer.ts +4 -1
- package/src/programmers/FeatureProgrammer.ts +619 -616
- package/src/programmers/RandomProgrammer.ts +24 -16
- package/src/programmers/TypiaProgrammer.ts +4 -1
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/prune_object_properties.ts +71 -63
- package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
- package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
- package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/transformers/FileTransformer.ts +0 -6
- package/src/transformers/ImportTransformer.ts +59 -44
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/StringUtil.ts +16 -16
- package/lib/internal/$httpFormDataReadArray.js.map +0 -1
- /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
|
@@ -1,274 +1,274 @@
|
|
|
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 { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
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 interface IConfig {
|
|
18
|
-
equals: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface IProps {
|
|
21
|
-
context: ITypiaContext;
|
|
22
|
-
modulo: ts.LeftHandSideExpression;
|
|
23
|
-
config: IConfig;
|
|
24
|
-
declaration: ts.FunctionDeclaration;
|
|
25
|
-
expression: ts.Expression;
|
|
26
|
-
init?: ts.Expression | undefined;
|
|
27
|
-
}
|
|
28
|
-
export interface IDecomposeProps {
|
|
29
|
-
context: ITypiaContext;
|
|
30
|
-
modulo: ts.LeftHandSideExpression;
|
|
31
|
-
config: IConfig;
|
|
32
|
-
declaration: ts.FunctionDeclaration;
|
|
33
|
-
}
|
|
34
|
-
export interface IDecomposeOutput {
|
|
35
|
-
functions: ts.Statement[];
|
|
36
|
-
statements: ts.Statement[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const write = (props: IProps): ts.CallExpression => {
|
|
40
|
-
const { async } = FunctionalGeneralProgrammer.getReturnType({
|
|
41
|
-
checker: props.context.checker,
|
|
42
|
-
declaration: props.declaration,
|
|
43
|
-
});
|
|
44
|
-
const result = decompose(props);
|
|
45
|
-
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
46
|
-
props.expression,
|
|
47
|
-
undefined,
|
|
48
|
-
props.declaration.parameters.map((p) =>
|
|
49
|
-
ts.factory.createIdentifier(p.name.getText()),
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
return ExpressionFactory.selfCall(
|
|
53
|
-
ts.factory.createBlock(
|
|
54
|
-
[
|
|
55
|
-
...result.functions,
|
|
56
|
-
ts.factory.createReturnStatement(
|
|
57
|
-
ts.factory.createArrowFunction(
|
|
58
|
-
async
|
|
59
|
-
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
60
|
-
: undefined,
|
|
61
|
-
undefined,
|
|
62
|
-
props.declaration.parameters,
|
|
63
|
-
FunctionalValidateFunctionProgrammer.getReturnTypeNode({
|
|
64
|
-
context: props.context,
|
|
65
|
-
declaration: props.declaration,
|
|
66
|
-
async,
|
|
67
|
-
}),
|
|
68
|
-
undefined,
|
|
69
|
-
ts.factory.createBlock(
|
|
70
|
-
[
|
|
71
|
-
...result.statements,
|
|
72
|
-
ts.factory.createReturnStatement(
|
|
73
|
-
ts.factory.createObjectLiteralExpression(
|
|
74
|
-
[
|
|
75
|
-
ts.factory.createPropertyAssignment(
|
|
76
|
-
"success",
|
|
77
|
-
ts.factory.createTrue(),
|
|
78
|
-
),
|
|
79
|
-
ts.factory.createPropertyAssignment(
|
|
80
|
-
"data",
|
|
81
|
-
async
|
|
82
|
-
? ts.factory.createAwaitExpression(caller)
|
|
83
|
-
: caller,
|
|
84
|
-
),
|
|
85
|
-
ts.factory.createPropertyAssignment(
|
|
86
|
-
"errors",
|
|
87
|
-
ts.factory.createArrayLiteralExpression([]),
|
|
88
|
-
),
|
|
89
|
-
],
|
|
90
|
-
true,
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
],
|
|
94
|
-
true,
|
|
95
|
-
),
|
|
96
|
-
),
|
|
97
|
-
),
|
|
98
|
-
],
|
|
99
|
-
true,
|
|
100
|
-
),
|
|
101
|
-
);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const decompose = (props: IDecomposeProps): IDecomposeOutput => {
|
|
105
|
-
const resultName: string = StringUtil.escapeDuplicate({
|
|
106
|
-
keep: props.declaration.parameters.map((p) => p.name.getText()),
|
|
107
|
-
input: "paramErrorResults",
|
|
108
|
-
});
|
|
109
|
-
const validationResultArray: ts.ArrayLiteralExpression =
|
|
110
|
-
ts.factory.createArrayLiteralExpression(
|
|
111
|
-
props.declaration.parameters.map((p, i) =>
|
|
112
|
-
ts.factory.createAsExpression(
|
|
113
|
-
ts.factory.createCallExpression(
|
|
114
|
-
ts.factory.createIdentifier(`__validate_param_${i}`),
|
|
115
|
-
undefined,
|
|
116
|
-
[ts.factory.createIdentifier(p.name.getText())],
|
|
117
|
-
),
|
|
118
|
-
props.context.importer.type({
|
|
119
|
-
file: "typia",
|
|
120
|
-
name: "IValidation.IFailure",
|
|
121
|
-
}),
|
|
122
|
-
),
|
|
123
|
-
),
|
|
124
|
-
true,
|
|
125
|
-
);
|
|
126
|
-
const errorMatrix = ts.factory.createCallExpression(
|
|
127
|
-
ts.factory.createPropertyAccessExpression(validationResultArray, "map"),
|
|
128
|
-
undefined,
|
|
129
|
-
[
|
|
130
|
-
ts.factory.createArrowFunction(
|
|
131
|
-
undefined,
|
|
132
|
-
undefined,
|
|
133
|
-
[IdentifierFactory.parameter("r"), IdentifierFactory.parameter("i")],
|
|
134
|
-
undefined,
|
|
135
|
-
undefined,
|
|
136
|
-
ts.factory.createConditionalExpression(
|
|
137
|
-
ts.factory.createStrictEquality(
|
|
138
|
-
ts.factory.createTrue(),
|
|
139
|
-
ts.factory.createPropertyAccessExpression(
|
|
140
|
-
ts.factory.createIdentifier("r"),
|
|
141
|
-
"success",
|
|
142
|
-
),
|
|
143
|
-
),
|
|
144
|
-
undefined,
|
|
145
|
-
ts.factory.createIdentifier("r"),
|
|
146
|
-
undefined,
|
|
147
|
-
ts.factory.createObjectLiteralExpression(
|
|
148
|
-
[
|
|
149
|
-
ts.factory.createSpreadAssignment(
|
|
150
|
-
ts.factory.createIdentifier("r"),
|
|
151
|
-
),
|
|
152
|
-
ts.factory.createPropertyAssignment(
|
|
153
|
-
"errors",
|
|
154
|
-
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
155
|
-
expression: ts.factory.createPropertyAccessExpression(
|
|
156
|
-
ts.factory.createIdentifier("r"),
|
|
157
|
-
"errors",
|
|
158
|
-
),
|
|
159
|
-
replacer: ts.factory.createTemplateExpression(
|
|
160
|
-
ts.factory.createTemplateHead("$input.parameters["),
|
|
161
|
-
[
|
|
162
|
-
ts.factory.createTemplateSpan(
|
|
163
|
-
ts.factory.createIdentifier("i"),
|
|
164
|
-
ts.factory.createTemplateTail("]"),
|
|
165
|
-
),
|
|
166
|
-
],
|
|
167
|
-
),
|
|
168
|
-
}),
|
|
169
|
-
),
|
|
170
|
-
],
|
|
171
|
-
true,
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
],
|
|
176
|
-
);
|
|
177
|
-
const failures = ts.factory.createCallExpression(
|
|
178
|
-
ts.factory.createPropertyAccessExpression(errorMatrix, "filter"),
|
|
179
|
-
undefined,
|
|
180
|
-
[
|
|
181
|
-
ts.factory.createArrowFunction(
|
|
182
|
-
undefined,
|
|
183
|
-
undefined,
|
|
184
|
-
[IdentifierFactory.parameter("r")],
|
|
185
|
-
undefined,
|
|
186
|
-
undefined,
|
|
187
|
-
ts.factory.createStrictEquality(
|
|
188
|
-
ts.factory.createFalse(),
|
|
189
|
-
ts.factory.createPropertyAccessExpression(
|
|
190
|
-
ts.factory.createIdentifier("r"),
|
|
191
|
-
"success",
|
|
192
|
-
),
|
|
193
|
-
),
|
|
194
|
-
),
|
|
195
|
-
],
|
|
196
|
-
);
|
|
197
|
-
return {
|
|
198
|
-
functions: props.declaration.parameters.map((p, i) =>
|
|
199
|
-
StatementFactory.constant({
|
|
200
|
-
name: `__validate_param_${i}`,
|
|
201
|
-
value: ValidateProgrammer.write({
|
|
202
|
-
...props,
|
|
203
|
-
type: props.context.checker.getTypeFromTypeNode(
|
|
204
|
-
p.type ?? TypeFactory.keyword("any"),
|
|
205
|
-
),
|
|
206
|
-
name: undefined,
|
|
207
|
-
init: undefined,
|
|
208
|
-
}),
|
|
209
|
-
}),
|
|
210
|
-
),
|
|
211
|
-
statements: [
|
|
212
|
-
StatementFactory.constant({
|
|
213
|
-
name: resultName,
|
|
214
|
-
value: failures,
|
|
215
|
-
}),
|
|
216
|
-
ts.factory.createIfStatement(
|
|
217
|
-
ts.factory.createStrictInequality(
|
|
218
|
-
ts.factory.createNumericLiteral("0"),
|
|
219
|
-
ts.factory.createPropertyAccessExpression(
|
|
220
|
-
ts.factory.createIdentifier(resultName),
|
|
221
|
-
"length",
|
|
222
|
-
),
|
|
223
|
-
),
|
|
224
|
-
ts.factory.createReturnStatement(
|
|
225
|
-
ts.factory.createObjectLiteralExpression(
|
|
226
|
-
[
|
|
227
|
-
ts.factory.createPropertyAssignment(
|
|
228
|
-
"success",
|
|
229
|
-
ts.factory.createFalse(),
|
|
230
|
-
),
|
|
231
|
-
ts.factory.createPropertyAssignment(
|
|
232
|
-
"errors",
|
|
233
|
-
ts.factory.createCallExpression(
|
|
234
|
-
IdentifierFactory.access(
|
|
235
|
-
ts.factory.createCallExpression(
|
|
236
|
-
IdentifierFactory.access(
|
|
237
|
-
ts.factory.createIdentifier(resultName),
|
|
238
|
-
"map",
|
|
239
|
-
),
|
|
240
|
-
undefined,
|
|
241
|
-
[
|
|
242
|
-
ts.factory.createArrowFunction(
|
|
243
|
-
undefined,
|
|
244
|
-
undefined,
|
|
245
|
-
[
|
|
246
|
-
IdentifierFactory.parameter(
|
|
247
|
-
"r",
|
|
248
|
-
TypeFactory.keyword("any"),
|
|
249
|
-
),
|
|
250
|
-
],
|
|
251
|
-
undefined,
|
|
252
|
-
undefined,
|
|
253
|
-
IdentifierFactory.access(
|
|
254
|
-
ts.factory.createIdentifier("r"),
|
|
255
|
-
"errors",
|
|
256
|
-
),
|
|
257
|
-
),
|
|
258
|
-
],
|
|
259
|
-
),
|
|
260
|
-
"flat",
|
|
261
|
-
),
|
|
262
|
-
undefined,
|
|
263
|
-
undefined,
|
|
264
|
-
),
|
|
265
|
-
),
|
|
266
|
-
],
|
|
267
|
-
true,
|
|
268
|
-
),
|
|
269
|
-
),
|
|
270
|
-
),
|
|
271
|
-
],
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
}
|
|
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 { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
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 interface IConfig {
|
|
18
|
+
equals: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface IProps {
|
|
21
|
+
context: ITypiaContext;
|
|
22
|
+
modulo: ts.LeftHandSideExpression;
|
|
23
|
+
config: IConfig;
|
|
24
|
+
declaration: ts.FunctionDeclaration;
|
|
25
|
+
expression: ts.Expression;
|
|
26
|
+
init?: ts.Expression | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface IDecomposeProps {
|
|
29
|
+
context: ITypiaContext;
|
|
30
|
+
modulo: ts.LeftHandSideExpression;
|
|
31
|
+
config: IConfig;
|
|
32
|
+
declaration: ts.FunctionDeclaration;
|
|
33
|
+
}
|
|
34
|
+
export interface IDecomposeOutput {
|
|
35
|
+
functions: ts.Statement[];
|
|
36
|
+
statements: ts.Statement[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const write = (props: IProps): ts.CallExpression => {
|
|
40
|
+
const { async } = FunctionalGeneralProgrammer.getReturnType({
|
|
41
|
+
checker: props.context.checker,
|
|
42
|
+
declaration: props.declaration,
|
|
43
|
+
});
|
|
44
|
+
const result = decompose(props);
|
|
45
|
+
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
46
|
+
props.expression,
|
|
47
|
+
undefined,
|
|
48
|
+
props.declaration.parameters.map((p) =>
|
|
49
|
+
ts.factory.createIdentifier(p.name.getText()),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
return ExpressionFactory.selfCall(
|
|
53
|
+
ts.factory.createBlock(
|
|
54
|
+
[
|
|
55
|
+
...result.functions,
|
|
56
|
+
ts.factory.createReturnStatement(
|
|
57
|
+
ts.factory.createArrowFunction(
|
|
58
|
+
async
|
|
59
|
+
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
60
|
+
: undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
props.declaration.parameters,
|
|
63
|
+
FunctionalValidateFunctionProgrammer.getReturnTypeNode({
|
|
64
|
+
context: props.context,
|
|
65
|
+
declaration: props.declaration,
|
|
66
|
+
async,
|
|
67
|
+
}),
|
|
68
|
+
undefined,
|
|
69
|
+
ts.factory.createBlock(
|
|
70
|
+
[
|
|
71
|
+
...result.statements,
|
|
72
|
+
ts.factory.createReturnStatement(
|
|
73
|
+
ts.factory.createObjectLiteralExpression(
|
|
74
|
+
[
|
|
75
|
+
ts.factory.createPropertyAssignment(
|
|
76
|
+
"success",
|
|
77
|
+
ts.factory.createTrue(),
|
|
78
|
+
),
|
|
79
|
+
ts.factory.createPropertyAssignment(
|
|
80
|
+
"data",
|
|
81
|
+
async
|
|
82
|
+
? ts.factory.createAwaitExpression(caller)
|
|
83
|
+
: caller,
|
|
84
|
+
),
|
|
85
|
+
ts.factory.createPropertyAssignment(
|
|
86
|
+
"errors",
|
|
87
|
+
ts.factory.createArrayLiteralExpression([]),
|
|
88
|
+
),
|
|
89
|
+
],
|
|
90
|
+
true,
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
],
|
|
94
|
+
true,
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
],
|
|
99
|
+
true,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const decompose = (props: IDecomposeProps): IDecomposeOutput => {
|
|
105
|
+
const resultName: string = StringUtil.escapeDuplicate({
|
|
106
|
+
keep: props.declaration.parameters.map((p) => p.name.getText()),
|
|
107
|
+
input: "paramErrorResults",
|
|
108
|
+
});
|
|
109
|
+
const validationResultArray: ts.ArrayLiteralExpression =
|
|
110
|
+
ts.factory.createArrayLiteralExpression(
|
|
111
|
+
props.declaration.parameters.map((p, i) =>
|
|
112
|
+
ts.factory.createAsExpression(
|
|
113
|
+
ts.factory.createCallExpression(
|
|
114
|
+
ts.factory.createIdentifier(`__validate_param_${i}`),
|
|
115
|
+
undefined,
|
|
116
|
+
[ts.factory.createIdentifier(p.name.getText())],
|
|
117
|
+
),
|
|
118
|
+
props.context.importer.type({
|
|
119
|
+
file: "typia",
|
|
120
|
+
name: "IValidation.IFailure",
|
|
121
|
+
}),
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
true,
|
|
125
|
+
);
|
|
126
|
+
const errorMatrix = ts.factory.createCallExpression(
|
|
127
|
+
ts.factory.createPropertyAccessExpression(validationResultArray, "map"),
|
|
128
|
+
undefined,
|
|
129
|
+
[
|
|
130
|
+
ts.factory.createArrowFunction(
|
|
131
|
+
undefined,
|
|
132
|
+
undefined,
|
|
133
|
+
[IdentifierFactory.parameter("r"), IdentifierFactory.parameter("i")],
|
|
134
|
+
undefined,
|
|
135
|
+
undefined,
|
|
136
|
+
ts.factory.createConditionalExpression(
|
|
137
|
+
ts.factory.createStrictEquality(
|
|
138
|
+
ts.factory.createTrue(),
|
|
139
|
+
ts.factory.createPropertyAccessExpression(
|
|
140
|
+
ts.factory.createIdentifier("r"),
|
|
141
|
+
"success",
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
undefined,
|
|
145
|
+
ts.factory.createIdentifier("r"),
|
|
146
|
+
undefined,
|
|
147
|
+
ts.factory.createObjectLiteralExpression(
|
|
148
|
+
[
|
|
149
|
+
ts.factory.createSpreadAssignment(
|
|
150
|
+
ts.factory.createIdentifier("r"),
|
|
151
|
+
),
|
|
152
|
+
ts.factory.createPropertyAssignment(
|
|
153
|
+
"errors",
|
|
154
|
+
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
155
|
+
expression: ts.factory.createPropertyAccessExpression(
|
|
156
|
+
ts.factory.createIdentifier("r"),
|
|
157
|
+
"errors",
|
|
158
|
+
),
|
|
159
|
+
replacer: ts.factory.createTemplateExpression(
|
|
160
|
+
ts.factory.createTemplateHead("$input.parameters["),
|
|
161
|
+
[
|
|
162
|
+
ts.factory.createTemplateSpan(
|
|
163
|
+
ts.factory.createIdentifier("i"),
|
|
164
|
+
ts.factory.createTemplateTail("]"),
|
|
165
|
+
),
|
|
166
|
+
],
|
|
167
|
+
),
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
170
|
+
],
|
|
171
|
+
true,
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
],
|
|
176
|
+
);
|
|
177
|
+
const failures = ts.factory.createCallExpression(
|
|
178
|
+
ts.factory.createPropertyAccessExpression(errorMatrix, "filter"),
|
|
179
|
+
undefined,
|
|
180
|
+
[
|
|
181
|
+
ts.factory.createArrowFunction(
|
|
182
|
+
undefined,
|
|
183
|
+
undefined,
|
|
184
|
+
[IdentifierFactory.parameter("r")],
|
|
185
|
+
undefined,
|
|
186
|
+
undefined,
|
|
187
|
+
ts.factory.createStrictEquality(
|
|
188
|
+
ts.factory.createFalse(),
|
|
189
|
+
ts.factory.createPropertyAccessExpression(
|
|
190
|
+
ts.factory.createIdentifier("r"),
|
|
191
|
+
"success",
|
|
192
|
+
),
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
],
|
|
196
|
+
);
|
|
197
|
+
return {
|
|
198
|
+
functions: props.declaration.parameters.map((p, i) =>
|
|
199
|
+
StatementFactory.constant({
|
|
200
|
+
name: `__validate_param_${i}`,
|
|
201
|
+
value: ValidateProgrammer.write({
|
|
202
|
+
...props,
|
|
203
|
+
type: props.context.checker.getTypeFromTypeNode(
|
|
204
|
+
p.type ?? TypeFactory.keyword("any"),
|
|
205
|
+
),
|
|
206
|
+
name: undefined,
|
|
207
|
+
init: undefined,
|
|
208
|
+
}),
|
|
209
|
+
}),
|
|
210
|
+
),
|
|
211
|
+
statements: [
|
|
212
|
+
StatementFactory.constant({
|
|
213
|
+
name: resultName,
|
|
214
|
+
value: failures,
|
|
215
|
+
}),
|
|
216
|
+
ts.factory.createIfStatement(
|
|
217
|
+
ts.factory.createStrictInequality(
|
|
218
|
+
ts.factory.createNumericLiteral("0"),
|
|
219
|
+
ts.factory.createPropertyAccessExpression(
|
|
220
|
+
ts.factory.createIdentifier(resultName),
|
|
221
|
+
"length",
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
ts.factory.createReturnStatement(
|
|
225
|
+
ts.factory.createObjectLiteralExpression(
|
|
226
|
+
[
|
|
227
|
+
ts.factory.createPropertyAssignment(
|
|
228
|
+
"success",
|
|
229
|
+
ts.factory.createFalse(),
|
|
230
|
+
),
|
|
231
|
+
ts.factory.createPropertyAssignment(
|
|
232
|
+
"errors",
|
|
233
|
+
ts.factory.createCallExpression(
|
|
234
|
+
IdentifierFactory.access(
|
|
235
|
+
ts.factory.createCallExpression(
|
|
236
|
+
IdentifierFactory.access(
|
|
237
|
+
ts.factory.createIdentifier(resultName),
|
|
238
|
+
"map",
|
|
239
|
+
),
|
|
240
|
+
undefined,
|
|
241
|
+
[
|
|
242
|
+
ts.factory.createArrowFunction(
|
|
243
|
+
undefined,
|
|
244
|
+
undefined,
|
|
245
|
+
[
|
|
246
|
+
IdentifierFactory.parameter(
|
|
247
|
+
"r",
|
|
248
|
+
TypeFactory.keyword("any"),
|
|
249
|
+
),
|
|
250
|
+
],
|
|
251
|
+
undefined,
|
|
252
|
+
undefined,
|
|
253
|
+
IdentifierFactory.access(
|
|
254
|
+
ts.factory.createIdentifier("r"),
|
|
255
|
+
"errors",
|
|
256
|
+
),
|
|
257
|
+
),
|
|
258
|
+
],
|
|
259
|
+
),
|
|
260
|
+
"flat",
|
|
261
|
+
),
|
|
262
|
+
undefined,
|
|
263
|
+
undefined,
|
|
264
|
+
),
|
|
265
|
+
),
|
|
266
|
+
],
|
|
267
|
+
true,
|
|
268
|
+
),
|
|
269
|
+
),
|
|
270
|
+
),
|
|
271
|
+
],
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
}
|