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