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,106 +1,106 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
-
|
|
10
|
-
import { IsProgrammer } from "../IsProgrammer";
|
|
11
|
-
import { FunctionalIsFunctionProgrammer } from "./FunctionalIsFunctionProgrammer";
|
|
12
|
-
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
13
|
-
|
|
14
|
-
export namespace FunctionalIsReturnProgrammer {
|
|
15
|
-
export const write =
|
|
16
|
-
(project: IProject) =>
|
|
17
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
18
|
-
(equals: boolean) =>
|
|
19
|
-
(
|
|
20
|
-
expression: ts.Expression,
|
|
21
|
-
declaration: ts.FunctionDeclaration,
|
|
22
|
-
): ts.CallExpression => {
|
|
23
|
-
const result = decompose(project)(modulo)(equals)(
|
|
24
|
-
expression,
|
|
25
|
-
declaration,
|
|
26
|
-
);
|
|
27
|
-
return ExpressionFactory.selfCall(
|
|
28
|
-
ts.factory.createBlock(
|
|
29
|
-
[
|
|
30
|
-
...result.functions,
|
|
31
|
-
ts.factory.createReturnStatement(
|
|
32
|
-
ts.factory.createArrowFunction(
|
|
33
|
-
result.async
|
|
34
|
-
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
35
|
-
: undefined,
|
|
36
|
-
undefined,
|
|
37
|
-
declaration.parameters,
|
|
38
|
-
FunctionalIsFunctionProgrammer.getReturnTypeNode(
|
|
39
|
-
declaration,
|
|
40
|
-
result.async,
|
|
41
|
-
),
|
|
42
|
-
undefined,
|
|
43
|
-
ts.factory.createBlock(result.statements, true),
|
|
44
|
-
),
|
|
45
|
-
),
|
|
46
|
-
],
|
|
47
|
-
true,
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const decompose =
|
|
53
|
-
(project: IProject) =>
|
|
54
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
55
|
-
(equals: boolean) =>
|
|
56
|
-
(
|
|
57
|
-
expression: ts.Expression,
|
|
58
|
-
declaration: ts.FunctionDeclaration,
|
|
59
|
-
): {
|
|
60
|
-
async: boolean;
|
|
61
|
-
functions: ts.Statement[];
|
|
62
|
-
statements: ts.Statement[];
|
|
63
|
-
} => {
|
|
64
|
-
const { type, async } = FunctionalGeneralProgrammer.getReturnType(
|
|
65
|
-
project.checker,
|
|
66
|
-
)(declaration);
|
|
67
|
-
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
68
|
-
expression,
|
|
69
|
-
undefined,
|
|
70
|
-
declaration.parameters.map((p) =>
|
|
71
|
-
ts.factory.createIdentifier(p.name.getText()),
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
const name: string = StringUtil.escapeDuplicate(
|
|
75
|
-
declaration.parameters.map((p) => p.name.getText()),
|
|
76
|
-
)("result");
|
|
77
|
-
return {
|
|
78
|
-
async,
|
|
79
|
-
functions: [
|
|
80
|
-
StatementFactory.constant(
|
|
81
|
-
"__is_return",
|
|
82
|
-
IsProgrammer.write(project)(modulo)(equals)(type),
|
|
83
|
-
),
|
|
84
|
-
],
|
|
85
|
-
statements: [
|
|
86
|
-
StatementFactory.constant(
|
|
87
|
-
name,
|
|
88
|
-
async ? ts.factory.createAwaitExpression(caller) : caller,
|
|
89
|
-
),
|
|
90
|
-
ts.factory.createReturnStatement(
|
|
91
|
-
ts.factory.createConditionalExpression(
|
|
92
|
-
ts.factory.createCallExpression(
|
|
93
|
-
ts.factory.createIdentifier("__is_return"),
|
|
94
|
-
undefined,
|
|
95
|
-
[ts.factory.createIdentifier(name)],
|
|
96
|
-
),
|
|
97
|
-
undefined,
|
|
98
|
-
ts.factory.createIdentifier(name),
|
|
99
|
-
undefined,
|
|
100
|
-
ts.factory.createNull(),
|
|
101
|
-
),
|
|
102
|
-
),
|
|
103
|
-
],
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
+
|
|
10
|
+
import { IsProgrammer } from "../IsProgrammer";
|
|
11
|
+
import { FunctionalIsFunctionProgrammer } from "./FunctionalIsFunctionProgrammer";
|
|
12
|
+
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
13
|
+
|
|
14
|
+
export namespace FunctionalIsReturnProgrammer {
|
|
15
|
+
export const write =
|
|
16
|
+
(project: IProject) =>
|
|
17
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
18
|
+
(equals: boolean) =>
|
|
19
|
+
(
|
|
20
|
+
expression: ts.Expression,
|
|
21
|
+
declaration: ts.FunctionDeclaration,
|
|
22
|
+
): ts.CallExpression => {
|
|
23
|
+
const result = decompose(project)(modulo)(equals)(
|
|
24
|
+
expression,
|
|
25
|
+
declaration,
|
|
26
|
+
);
|
|
27
|
+
return ExpressionFactory.selfCall(
|
|
28
|
+
ts.factory.createBlock(
|
|
29
|
+
[
|
|
30
|
+
...result.functions,
|
|
31
|
+
ts.factory.createReturnStatement(
|
|
32
|
+
ts.factory.createArrowFunction(
|
|
33
|
+
result.async
|
|
34
|
+
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
35
|
+
: undefined,
|
|
36
|
+
undefined,
|
|
37
|
+
declaration.parameters,
|
|
38
|
+
FunctionalIsFunctionProgrammer.getReturnTypeNode(
|
|
39
|
+
declaration,
|
|
40
|
+
result.async,
|
|
41
|
+
),
|
|
42
|
+
undefined,
|
|
43
|
+
ts.factory.createBlock(result.statements, true),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
],
|
|
47
|
+
true,
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const decompose =
|
|
53
|
+
(project: IProject) =>
|
|
54
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
55
|
+
(equals: boolean) =>
|
|
56
|
+
(
|
|
57
|
+
expression: ts.Expression,
|
|
58
|
+
declaration: ts.FunctionDeclaration,
|
|
59
|
+
): {
|
|
60
|
+
async: boolean;
|
|
61
|
+
functions: ts.Statement[];
|
|
62
|
+
statements: ts.Statement[];
|
|
63
|
+
} => {
|
|
64
|
+
const { type, async } = FunctionalGeneralProgrammer.getReturnType(
|
|
65
|
+
project.checker,
|
|
66
|
+
)(declaration);
|
|
67
|
+
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
68
|
+
expression,
|
|
69
|
+
undefined,
|
|
70
|
+
declaration.parameters.map((p) =>
|
|
71
|
+
ts.factory.createIdentifier(p.name.getText()),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
const name: string = StringUtil.escapeDuplicate(
|
|
75
|
+
declaration.parameters.map((p) => p.name.getText()),
|
|
76
|
+
)("result");
|
|
77
|
+
return {
|
|
78
|
+
async,
|
|
79
|
+
functions: [
|
|
80
|
+
StatementFactory.constant(
|
|
81
|
+
"__is_return",
|
|
82
|
+
IsProgrammer.write(project)(modulo)(equals)(type),
|
|
83
|
+
),
|
|
84
|
+
],
|
|
85
|
+
statements: [
|
|
86
|
+
StatementFactory.constant(
|
|
87
|
+
name,
|
|
88
|
+
async ? ts.factory.createAwaitExpression(caller) : caller,
|
|
89
|
+
),
|
|
90
|
+
ts.factory.createReturnStatement(
|
|
91
|
+
ts.factory.createConditionalExpression(
|
|
92
|
+
ts.factory.createCallExpression(
|
|
93
|
+
ts.factory.createIdentifier("__is_return"),
|
|
94
|
+
undefined,
|
|
95
|
+
[ts.factory.createIdentifier(name)],
|
|
96
|
+
),
|
|
97
|
+
undefined,
|
|
98
|
+
ts.factory.createIdentifier(name),
|
|
99
|
+
undefined,
|
|
100
|
+
ts.factory.createNull(),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { FunctionalValidateParametersProgrammer } from "./FunctionalValidateParametersProgrammer";
|
|
9
|
-
import { FunctionalValidateReturnProgrammer } from "./FunctionalValidateReturnProgrammer";
|
|
10
|
-
|
|
11
|
-
export namespace FunctionalValidateFunctionProgrammer {
|
|
12
|
-
export const write =
|
|
13
|
-
(project: IProject) =>
|
|
14
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
15
|
-
(equals: boolean) =>
|
|
16
|
-
(
|
|
17
|
-
expression: ts.Expression,
|
|
18
|
-
declaration: ts.FunctionDeclaration,
|
|
19
|
-
): ts.CallExpression => {
|
|
20
|
-
const p =
|
|
21
|
-
FunctionalValidateParametersProgrammer.decompose(project)(modulo)(
|
|
22
|
-
equals,
|
|
23
|
-
)(declaration);
|
|
24
|
-
const r = FunctionalValidateReturnProgrammer.decompose(project)(modulo)(
|
|
25
|
-
equals,
|
|
26
|
-
)(expression, declaration);
|
|
27
|
-
return ExpressionFactory.selfCall(
|
|
28
|
-
ts.factory.createBlock(
|
|
29
|
-
[
|
|
30
|
-
...p.functions,
|
|
31
|
-
...r.functions,
|
|
32
|
-
ts.factory.createReturnStatement(
|
|
33
|
-
ts.factory.createArrowFunction(
|
|
34
|
-
r.async
|
|
35
|
-
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
36
|
-
: undefined,
|
|
37
|
-
undefined,
|
|
38
|
-
declaration.parameters,
|
|
39
|
-
getReturnTypeNode(declaration, r.async),
|
|
40
|
-
undefined,
|
|
41
|
-
ts.factory.createBlock(
|
|
42
|
-
[...p.statements, ...r.statements],
|
|
43
|
-
true,
|
|
44
|
-
),
|
|
45
|
-
),
|
|
46
|
-
),
|
|
47
|
-
],
|
|
48
|
-
true,
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const hookErrors = (props: {
|
|
54
|
-
expression: ts.Expression;
|
|
55
|
-
replacer: ts.Expression;
|
|
56
|
-
}): ts.CallExpression =>
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createPropertyAccessExpression(props.expression, "map"),
|
|
59
|
-
undefined,
|
|
60
|
-
[
|
|
61
|
-
ts.factory.createArrowFunction(
|
|
62
|
-
undefined,
|
|
63
|
-
undefined,
|
|
64
|
-
[IdentifierFactory.parameter("error")],
|
|
65
|
-
undefined,
|
|
66
|
-
undefined,
|
|
67
|
-
ts.factory.createObjectLiteralExpression(
|
|
68
|
-
[
|
|
69
|
-
ts.factory.createSpreadAssignment(
|
|
70
|
-
ts.factory.createIdentifier("error"),
|
|
71
|
-
),
|
|
72
|
-
ts.factory.createPropertyAssignment(
|
|
73
|
-
"path",
|
|
74
|
-
ts.factory.createCallExpression(
|
|
75
|
-
ts.factory.createPropertyAccessExpression(
|
|
76
|
-
ts.factory.createPropertyAccessExpression(
|
|
77
|
-
ts.factory.createIdentifier("error"),
|
|
78
|
-
"path",
|
|
79
|
-
),
|
|
80
|
-
"replace",
|
|
81
|
-
),
|
|
82
|
-
undefined,
|
|
83
|
-
[ts.factory.createStringLiteral("$input"), props.replacer],
|
|
84
|
-
),
|
|
85
|
-
),
|
|
86
|
-
],
|
|
87
|
-
true,
|
|
88
|
-
),
|
|
89
|
-
),
|
|
90
|
-
],
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
export const getReturnTypeNode = (
|
|
94
|
-
declaration: ts.FunctionDeclaration,
|
|
95
|
-
async: boolean,
|
|
96
|
-
): ts.TypeNode | undefined =>
|
|
97
|
-
declaration.type
|
|
98
|
-
? async
|
|
99
|
-
? !!(declaration.type! as ts.TypeReferenceNode).typeArguments?.[0]
|
|
100
|
-
? ts.factory.createTypeReferenceNode("Promise", [
|
|
101
|
-
ts.factory.createImportTypeNode(
|
|
102
|
-
ts.factory.createLiteralTypeNode(
|
|
103
|
-
ts.factory.createStringLiteral("typia"),
|
|
104
|
-
),
|
|
105
|
-
undefined,
|
|
106
|
-
ts.factory.createIdentifier("IValidation"),
|
|
107
|
-
[
|
|
108
|
-
(declaration.type! as ts.TypeReferenceNode)
|
|
109
|
-
.typeArguments![0]!,
|
|
110
|
-
],
|
|
111
|
-
),
|
|
112
|
-
])
|
|
113
|
-
: undefined
|
|
114
|
-
: ts.factory.createImportTypeNode(
|
|
115
|
-
ts.factory.createLiteralTypeNode(
|
|
116
|
-
ts.factory.createStringLiteral("typia"),
|
|
117
|
-
),
|
|
118
|
-
undefined,
|
|
119
|
-
ts.factory.createIdentifier("IValidation"),
|
|
120
|
-
[declaration.type],
|
|
121
|
-
)
|
|
122
|
-
: undefined;
|
|
123
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { FunctionalValidateParametersProgrammer } from "./FunctionalValidateParametersProgrammer";
|
|
9
|
+
import { FunctionalValidateReturnProgrammer } from "./FunctionalValidateReturnProgrammer";
|
|
10
|
+
|
|
11
|
+
export namespace FunctionalValidateFunctionProgrammer {
|
|
12
|
+
export const write =
|
|
13
|
+
(project: IProject) =>
|
|
14
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
15
|
+
(equals: boolean) =>
|
|
16
|
+
(
|
|
17
|
+
expression: ts.Expression,
|
|
18
|
+
declaration: ts.FunctionDeclaration,
|
|
19
|
+
): ts.CallExpression => {
|
|
20
|
+
const p =
|
|
21
|
+
FunctionalValidateParametersProgrammer.decompose(project)(modulo)(
|
|
22
|
+
equals,
|
|
23
|
+
)(declaration);
|
|
24
|
+
const r = FunctionalValidateReturnProgrammer.decompose(project)(modulo)(
|
|
25
|
+
equals,
|
|
26
|
+
)(expression, declaration);
|
|
27
|
+
return ExpressionFactory.selfCall(
|
|
28
|
+
ts.factory.createBlock(
|
|
29
|
+
[
|
|
30
|
+
...p.functions,
|
|
31
|
+
...r.functions,
|
|
32
|
+
ts.factory.createReturnStatement(
|
|
33
|
+
ts.factory.createArrowFunction(
|
|
34
|
+
r.async
|
|
35
|
+
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
36
|
+
: undefined,
|
|
37
|
+
undefined,
|
|
38
|
+
declaration.parameters,
|
|
39
|
+
getReturnTypeNode(declaration, r.async),
|
|
40
|
+
undefined,
|
|
41
|
+
ts.factory.createBlock(
|
|
42
|
+
[...p.statements, ...r.statements],
|
|
43
|
+
true,
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
],
|
|
48
|
+
true,
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const hookErrors = (props: {
|
|
54
|
+
expression: ts.Expression;
|
|
55
|
+
replacer: ts.Expression;
|
|
56
|
+
}): ts.CallExpression =>
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createPropertyAccessExpression(props.expression, "map"),
|
|
59
|
+
undefined,
|
|
60
|
+
[
|
|
61
|
+
ts.factory.createArrowFunction(
|
|
62
|
+
undefined,
|
|
63
|
+
undefined,
|
|
64
|
+
[IdentifierFactory.parameter("error")],
|
|
65
|
+
undefined,
|
|
66
|
+
undefined,
|
|
67
|
+
ts.factory.createObjectLiteralExpression(
|
|
68
|
+
[
|
|
69
|
+
ts.factory.createSpreadAssignment(
|
|
70
|
+
ts.factory.createIdentifier("error"),
|
|
71
|
+
),
|
|
72
|
+
ts.factory.createPropertyAssignment(
|
|
73
|
+
"path",
|
|
74
|
+
ts.factory.createCallExpression(
|
|
75
|
+
ts.factory.createPropertyAccessExpression(
|
|
76
|
+
ts.factory.createPropertyAccessExpression(
|
|
77
|
+
ts.factory.createIdentifier("error"),
|
|
78
|
+
"path",
|
|
79
|
+
),
|
|
80
|
+
"replace",
|
|
81
|
+
),
|
|
82
|
+
undefined,
|
|
83
|
+
[ts.factory.createStringLiteral("$input"), props.replacer],
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
],
|
|
87
|
+
true,
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
export const getReturnTypeNode = (
|
|
94
|
+
declaration: ts.FunctionDeclaration,
|
|
95
|
+
async: boolean,
|
|
96
|
+
): ts.TypeNode | undefined =>
|
|
97
|
+
declaration.type
|
|
98
|
+
? async
|
|
99
|
+
? !!(declaration.type! as ts.TypeReferenceNode).typeArguments?.[0]
|
|
100
|
+
? ts.factory.createTypeReferenceNode("Promise", [
|
|
101
|
+
ts.factory.createImportTypeNode(
|
|
102
|
+
ts.factory.createLiteralTypeNode(
|
|
103
|
+
ts.factory.createStringLiteral("typia"),
|
|
104
|
+
),
|
|
105
|
+
undefined,
|
|
106
|
+
ts.factory.createIdentifier("IValidation"),
|
|
107
|
+
[
|
|
108
|
+
(declaration.type! as ts.TypeReferenceNode)
|
|
109
|
+
.typeArguments![0]!,
|
|
110
|
+
],
|
|
111
|
+
),
|
|
112
|
+
])
|
|
113
|
+
: undefined
|
|
114
|
+
: ts.factory.createImportTypeNode(
|
|
115
|
+
ts.factory.createLiteralTypeNode(
|
|
116
|
+
ts.factory.createStringLiteral("typia"),
|
|
117
|
+
),
|
|
118
|
+
undefined,
|
|
119
|
+
ts.factory.createIdentifier("IValidation"),
|
|
120
|
+
[declaration.type],
|
|
121
|
+
)
|
|
122
|
+
: undefined;
|
|
123
|
+
}
|