@nestia/sdk 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analyses/ControllerAnalyzer.js +3 -3
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +1 -2
- package/lib/analyses/ImportAnalyzer.js +2 -2
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +2 -2
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +4 -4
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.js +6 -8
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/structures/TypeEntry.js +2 -2
- package/lib/structures/TypeEntry.js.map +1 -1
- package/package.json +4 -4
- package/src/INestiaConfig.ts +248 -248
- package/src/NestiaSdkApplication.ts +255 -255
- package/src/analyses/ControllerAnalyzer.ts +402 -402
- package/src/analyses/ExceptionAnalyzer.ts +148 -148
- package/src/analyses/ImportAnalyzer.ts +1 -2
- package/src/analyses/ReflectAnalyzer.ts +463 -463
- package/src/analyses/SecurityAnalyzer.ts +24 -24
- package/src/generates/CloneGenerator.ts +62 -62
- package/src/generates/E2eGenerator.ts +66 -66
- package/src/generates/SdkGenerator.ts +84 -84
- package/src/generates/SwaggerGenerator.ts +446 -446
- package/src/generates/internal/E2eFileProgrammer.ts +182 -182
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +147 -149
- package/src/generates/internal/SdkAliasCollection.ts +152 -152
- package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
- package/src/generates/internal/SdkFileProgrammer.ts +115 -115
- package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
- package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
- package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
- package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
- package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
- package/src/structures/IController.ts +94 -94
- package/src/structures/IRoute.ts +53 -53
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerRoute.ts +54 -54
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +1 -1
- package/src/utils/StringUtil.ts +6 -6
|
@@ -1,298 +1,298 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import typia from "typia";
|
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
6
|
-
import { IController } from "../../structures/IController";
|
|
7
|
-
import { IRoute } from "../../structures/IRoute";
|
|
8
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
10
|
-
import { SdkImportWizard } from "./SdkImportWizard";
|
|
11
|
-
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
12
|
-
|
|
13
|
-
export namespace SdkFunctionProgrammer {
|
|
14
|
-
export const write =
|
|
15
|
-
(config: INestiaConfig) =>
|
|
16
|
-
(importer: ImportDictionary) =>
|
|
17
|
-
(
|
|
18
|
-
route: IRoute,
|
|
19
|
-
props: {
|
|
20
|
-
headers: IRoute.IParameter | undefined;
|
|
21
|
-
query: IRoute.IParameter | undefined;
|
|
22
|
-
input: IRoute.IParameter | undefined;
|
|
23
|
-
},
|
|
24
|
-
): ts.FunctionDeclaration => {
|
|
25
|
-
return ts.factory.createFunctionDeclaration(
|
|
26
|
-
[
|
|
27
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
28
|
-
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
29
|
-
],
|
|
30
|
-
undefined,
|
|
31
|
-
route.name,
|
|
32
|
-
undefined,
|
|
33
|
-
[
|
|
34
|
-
IdentifierFactory.parameter(
|
|
35
|
-
"connection",
|
|
36
|
-
ts.factory.createTypeReferenceNode(
|
|
37
|
-
SdkImportWizard.IConnection(importer),
|
|
38
|
-
props.headers
|
|
39
|
-
? [ts.factory.createTypeReferenceNode(`${route.name}.Headers`)]
|
|
40
|
-
: undefined,
|
|
41
|
-
),
|
|
42
|
-
),
|
|
43
|
-
...route.parameters
|
|
44
|
-
.filter((p) => p.category !== "headers")
|
|
45
|
-
.map((p) =>
|
|
46
|
-
ts.factory.createParameterDeclaration(
|
|
47
|
-
[],
|
|
48
|
-
undefined,
|
|
49
|
-
p.name,
|
|
50
|
-
p.optional
|
|
51
|
-
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
52
|
-
: undefined,
|
|
53
|
-
config.primitive !== false &&
|
|
54
|
-
(p === props.query || p === props.input)
|
|
55
|
-
? ts.factory.createTypeReferenceNode(
|
|
56
|
-
`${route.name}.${p === props.query ? "Query" : "Input"}`,
|
|
57
|
-
)
|
|
58
|
-
: getTypeName(config)(importer)(p),
|
|
59
|
-
),
|
|
60
|
-
),
|
|
61
|
-
],
|
|
62
|
-
ts.factory.createTypeReferenceNode("Promise", [
|
|
63
|
-
getReturnType(config)(route),
|
|
64
|
-
]),
|
|
65
|
-
ts.factory.createBlock(
|
|
66
|
-
write_body(config)(importer)(route, props),
|
|
67
|
-
true,
|
|
68
|
-
),
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const write_body =
|
|
73
|
-
(config: INestiaConfig) =>
|
|
74
|
-
(importer: ImportDictionary) =>
|
|
75
|
-
(
|
|
76
|
-
route: IRoute,
|
|
77
|
-
props: {
|
|
78
|
-
headers: IRoute.IParameter | undefined;
|
|
79
|
-
query: IRoute.IParameter | undefined;
|
|
80
|
-
input: IRoute.IParameter | undefined;
|
|
81
|
-
},
|
|
82
|
-
): ts.Statement[] => {
|
|
83
|
-
const encrypted: boolean =
|
|
84
|
-
route.encrypted === true ||
|
|
85
|
-
(props.input !== undefined &&
|
|
86
|
-
props.input.custom === true &&
|
|
87
|
-
props.input.category === "body" &&
|
|
88
|
-
props.input.encrypted === true);
|
|
89
|
-
const contentType: string | undefined =
|
|
90
|
-
props.input !== undefined
|
|
91
|
-
? typia.is<IController.IBodyParameter>(props.input)
|
|
92
|
-
? props.input.contentType
|
|
93
|
-
: "application/json"
|
|
94
|
-
: undefined;
|
|
95
|
-
|
|
96
|
-
const caller = () =>
|
|
97
|
-
ts.factory.createCallExpression(
|
|
98
|
-
IdentifierFactory.access(
|
|
99
|
-
ts.factory.createIdentifier(
|
|
100
|
-
SdkImportWizard.Fetcher(encrypted)(importer),
|
|
101
|
-
),
|
|
102
|
-
)(config.propagate ? "propagate" : "fetch"),
|
|
103
|
-
undefined,
|
|
104
|
-
[
|
|
105
|
-
contentType && contentType !== "multipart/form-data"
|
|
106
|
-
? ts.factory.createObjectLiteralExpression(
|
|
107
|
-
[
|
|
108
|
-
ts.factory.createSpreadAssignment(
|
|
109
|
-
ts.factory.createIdentifier("connection"),
|
|
110
|
-
),
|
|
111
|
-
ts.factory.createPropertyAssignment(
|
|
112
|
-
"headers",
|
|
113
|
-
ts.factory.createObjectLiteralExpression(
|
|
114
|
-
[
|
|
115
|
-
ts.factory.createSpreadAssignment(
|
|
116
|
-
IdentifierFactory.access(
|
|
117
|
-
ts.factory.createIdentifier("connection"),
|
|
118
|
-
)("headers"),
|
|
119
|
-
),
|
|
120
|
-
ts.factory.createPropertyAssignment(
|
|
121
|
-
ts.factory.createStringLiteral("Content-Type"),
|
|
122
|
-
ts.factory.createStringLiteral(contentType),
|
|
123
|
-
),
|
|
124
|
-
],
|
|
125
|
-
true,
|
|
126
|
-
),
|
|
127
|
-
),
|
|
128
|
-
],
|
|
129
|
-
true,
|
|
130
|
-
)
|
|
131
|
-
: ts.factory.createIdentifier("connection"),
|
|
132
|
-
ts.factory.createObjectLiteralExpression(
|
|
133
|
-
[
|
|
134
|
-
ts.factory.createSpreadAssignment(
|
|
135
|
-
IdentifierFactory.access(
|
|
136
|
-
ts.factory.createIdentifier(route.name),
|
|
137
|
-
)("METADATA"),
|
|
138
|
-
),
|
|
139
|
-
ts.factory.createPropertyAssignment(
|
|
140
|
-
"path",
|
|
141
|
-
ts.factory.createCallExpression(
|
|
142
|
-
IdentifierFactory.access(
|
|
143
|
-
ts.factory.createIdentifier(route.name),
|
|
144
|
-
)("path"),
|
|
145
|
-
undefined,
|
|
146
|
-
route.parameters
|
|
147
|
-
.filter(
|
|
148
|
-
(p) => p.category === "param" || p.category === "query",
|
|
149
|
-
)
|
|
150
|
-
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
151
|
-
),
|
|
152
|
-
),
|
|
153
|
-
],
|
|
154
|
-
true,
|
|
155
|
-
),
|
|
156
|
-
...(props.input
|
|
157
|
-
? [ts.factory.createIdentifier(props.input.name)]
|
|
158
|
-
: []),
|
|
159
|
-
...(config.json &&
|
|
160
|
-
typia.is<IController.IBodyParameter>(props.input) &&
|
|
161
|
-
(props.input.contentType === "application/json" ||
|
|
162
|
-
props.input.encrypted === true)
|
|
163
|
-
? [ts.factory.createIdentifier(`${route.name}.stringify`)]
|
|
164
|
-
: []),
|
|
165
|
-
],
|
|
166
|
-
);
|
|
167
|
-
const output = (awaiter: boolean) =>
|
|
168
|
-
config.simulate
|
|
169
|
-
? ts.factory.createConditionalExpression(
|
|
170
|
-
ts.factory.createIdentifier("!!connection.simulate"),
|
|
171
|
-
undefined,
|
|
172
|
-
ts.factory.createCallExpression(
|
|
173
|
-
ts.factory.createIdentifier(`${route.name}.simulate`),
|
|
174
|
-
[],
|
|
175
|
-
[
|
|
176
|
-
ts.factory.createIdentifier("connection"),
|
|
177
|
-
...route.parameters
|
|
178
|
-
.filter((p) => p.category !== "headers")
|
|
179
|
-
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
180
|
-
],
|
|
181
|
-
),
|
|
182
|
-
undefined,
|
|
183
|
-
awaiter ? ts.factory.createAwaitExpression(caller()) : caller(),
|
|
184
|
-
)
|
|
185
|
-
: awaiter
|
|
186
|
-
? ts.factory.createAwaitExpression(caller())
|
|
187
|
-
: caller();
|
|
188
|
-
return [
|
|
189
|
-
...(config.assert
|
|
190
|
-
? route.parameters
|
|
191
|
-
.filter((p) => p.category !== "headers")
|
|
192
|
-
.map((p) =>
|
|
193
|
-
ts.factory.createExpressionStatement(
|
|
194
|
-
ts.factory.createCallExpression(
|
|
195
|
-
IdentifierFactory.access(
|
|
196
|
-
ts.factory.createIdentifier(
|
|
197
|
-
SdkImportWizard.typia(importer),
|
|
198
|
-
),
|
|
199
|
-
)("assert"),
|
|
200
|
-
[
|
|
201
|
-
ts.factory.createTypeQueryNode(
|
|
202
|
-
ts.factory.createIdentifier(p.name),
|
|
203
|
-
),
|
|
204
|
-
],
|
|
205
|
-
[ts.factory.createIdentifier(p.name)],
|
|
206
|
-
),
|
|
207
|
-
),
|
|
208
|
-
)
|
|
209
|
-
: []),
|
|
210
|
-
...(route.setHeaders.length === 0
|
|
211
|
-
? [ts.factory.createReturnStatement(output(false))]
|
|
212
|
-
: write_set_headers(config)(route)(output(true))),
|
|
213
|
-
];
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const write_set_headers =
|
|
217
|
-
(config: INestiaConfig) =>
|
|
218
|
-
(route: IRoute) =>
|
|
219
|
-
(condition: ts.Expression): ts.Statement[] => {
|
|
220
|
-
const accessor = (x: string) => (y: string) =>
|
|
221
|
-
x[0] === "[" ? `${x}${y}` : `${x}.${y}`;
|
|
222
|
-
const output: string = StringUtil.escapeDuplicate([
|
|
223
|
-
"connection",
|
|
224
|
-
...route.parameters.map((p) => p.name),
|
|
225
|
-
])("output");
|
|
226
|
-
const headers: string = accessor("connection")("headers");
|
|
227
|
-
const data: string = config.propagate ? accessor(output)("data") : output;
|
|
228
|
-
|
|
229
|
-
const assigners: ts.ExpressionStatement[] = [
|
|
230
|
-
ts.factory.createBinaryExpression(
|
|
231
|
-
ts.factory.createIdentifier(headers),
|
|
232
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
|
|
233
|
-
ts.factory.createObjectLiteralExpression([]),
|
|
234
|
-
),
|
|
235
|
-
...route.setHeaders.map((tuple) =>
|
|
236
|
-
tuple.type === "assigner"
|
|
237
|
-
? ts.factory.createCallExpression(
|
|
238
|
-
ts.factory.createIdentifier("Object.assign"),
|
|
239
|
-
[],
|
|
240
|
-
[
|
|
241
|
-
ts.factory.createIdentifier(headers),
|
|
242
|
-
ts.factory.createIdentifier(accessor(data)(tuple.source)),
|
|
243
|
-
],
|
|
244
|
-
)
|
|
245
|
-
: ts.factory.createBinaryExpression(
|
|
246
|
-
ts.factory.createIdentifier(
|
|
247
|
-
accessor(headers)(tuple.target ?? tuple.source),
|
|
248
|
-
),
|
|
249
|
-
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
250
|
-
ts.factory.createIdentifier(accessor(data)(tuple.source)),
|
|
251
|
-
),
|
|
252
|
-
),
|
|
253
|
-
].map(ts.factory.createExpressionStatement);
|
|
254
|
-
return [
|
|
255
|
-
ts.factory.createVariableStatement(
|
|
256
|
-
[],
|
|
257
|
-
ts.factory.createVariableDeclarationList(
|
|
258
|
-
[
|
|
259
|
-
ts.factory.createVariableDeclaration(
|
|
260
|
-
output,
|
|
261
|
-
undefined,
|
|
262
|
-
getReturnType(config)(route),
|
|
263
|
-
condition,
|
|
264
|
-
),
|
|
265
|
-
],
|
|
266
|
-
ts.NodeFlags.Const,
|
|
267
|
-
),
|
|
268
|
-
),
|
|
269
|
-
...(config.propagate
|
|
270
|
-
? [
|
|
271
|
-
ts.factory.createIfStatement(
|
|
272
|
-
ts.factory.createIdentifier(accessor(output)("success")),
|
|
273
|
-
assigners.length === 1
|
|
274
|
-
? assigners[0]
|
|
275
|
-
: ts.factory.createBlock(assigners, true),
|
|
276
|
-
undefined,
|
|
277
|
-
),
|
|
278
|
-
]
|
|
279
|
-
: assigners),
|
|
280
|
-
ts.factory.createReturnStatement(ts.factory.createIdentifier(output)),
|
|
281
|
-
];
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const getTypeName =
|
|
286
|
-
(config: INestiaConfig) =>
|
|
287
|
-
(importer: ImportDictionary) =>
|
|
288
|
-
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
289
|
-
p.metadata
|
|
290
|
-
? SdkTypeProgrammer.write(config)(importer)(p.metadata)
|
|
291
|
-
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
292
|
-
|
|
293
|
-
const getReturnType = (config: INestiaConfig) => (route: IRoute) =>
|
|
294
|
-
ts.factory.createTypeReferenceNode(
|
|
295
|
-
config.propagate !== true && route.output.typeName === "void"
|
|
296
|
-
? "void"
|
|
297
|
-
: `${route.name}.Output`,
|
|
298
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import typia from "typia";
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
6
|
+
import { IController } from "../../structures/IController";
|
|
7
|
+
import { IRoute } from "../../structures/IRoute";
|
|
8
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
10
|
+
import { SdkImportWizard } from "./SdkImportWizard";
|
|
11
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
12
|
+
|
|
13
|
+
export namespace SdkFunctionProgrammer {
|
|
14
|
+
export const write =
|
|
15
|
+
(config: INestiaConfig) =>
|
|
16
|
+
(importer: ImportDictionary) =>
|
|
17
|
+
(
|
|
18
|
+
route: IRoute,
|
|
19
|
+
props: {
|
|
20
|
+
headers: IRoute.IParameter | undefined;
|
|
21
|
+
query: IRoute.IParameter | undefined;
|
|
22
|
+
input: IRoute.IParameter | undefined;
|
|
23
|
+
},
|
|
24
|
+
): ts.FunctionDeclaration => {
|
|
25
|
+
return ts.factory.createFunctionDeclaration(
|
|
26
|
+
[
|
|
27
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
28
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
29
|
+
],
|
|
30
|
+
undefined,
|
|
31
|
+
route.name,
|
|
32
|
+
undefined,
|
|
33
|
+
[
|
|
34
|
+
IdentifierFactory.parameter(
|
|
35
|
+
"connection",
|
|
36
|
+
ts.factory.createTypeReferenceNode(
|
|
37
|
+
SdkImportWizard.IConnection(importer),
|
|
38
|
+
props.headers
|
|
39
|
+
? [ts.factory.createTypeReferenceNode(`${route.name}.Headers`)]
|
|
40
|
+
: undefined,
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
...route.parameters
|
|
44
|
+
.filter((p) => p.category !== "headers")
|
|
45
|
+
.map((p) =>
|
|
46
|
+
ts.factory.createParameterDeclaration(
|
|
47
|
+
[],
|
|
48
|
+
undefined,
|
|
49
|
+
p.name,
|
|
50
|
+
p.optional
|
|
51
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
52
|
+
: undefined,
|
|
53
|
+
config.primitive !== false &&
|
|
54
|
+
(p === props.query || p === props.input)
|
|
55
|
+
? ts.factory.createTypeReferenceNode(
|
|
56
|
+
`${route.name}.${p === props.query ? "Query" : "Input"}`,
|
|
57
|
+
)
|
|
58
|
+
: getTypeName(config)(importer)(p),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
],
|
|
62
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
|
63
|
+
getReturnType(config)(route),
|
|
64
|
+
]),
|
|
65
|
+
ts.factory.createBlock(
|
|
66
|
+
write_body(config)(importer)(route, props),
|
|
67
|
+
true,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const write_body =
|
|
73
|
+
(config: INestiaConfig) =>
|
|
74
|
+
(importer: ImportDictionary) =>
|
|
75
|
+
(
|
|
76
|
+
route: IRoute,
|
|
77
|
+
props: {
|
|
78
|
+
headers: IRoute.IParameter | undefined;
|
|
79
|
+
query: IRoute.IParameter | undefined;
|
|
80
|
+
input: IRoute.IParameter | undefined;
|
|
81
|
+
},
|
|
82
|
+
): ts.Statement[] => {
|
|
83
|
+
const encrypted: boolean =
|
|
84
|
+
route.encrypted === true ||
|
|
85
|
+
(props.input !== undefined &&
|
|
86
|
+
props.input.custom === true &&
|
|
87
|
+
props.input.category === "body" &&
|
|
88
|
+
props.input.encrypted === true);
|
|
89
|
+
const contentType: string | undefined =
|
|
90
|
+
props.input !== undefined
|
|
91
|
+
? typia.is<IController.IBodyParameter>(props.input)
|
|
92
|
+
? props.input.contentType
|
|
93
|
+
: "application/json"
|
|
94
|
+
: undefined;
|
|
95
|
+
|
|
96
|
+
const caller = () =>
|
|
97
|
+
ts.factory.createCallExpression(
|
|
98
|
+
IdentifierFactory.access(
|
|
99
|
+
ts.factory.createIdentifier(
|
|
100
|
+
SdkImportWizard.Fetcher(encrypted)(importer),
|
|
101
|
+
),
|
|
102
|
+
)(config.propagate ? "propagate" : "fetch"),
|
|
103
|
+
undefined,
|
|
104
|
+
[
|
|
105
|
+
contentType && contentType !== "multipart/form-data"
|
|
106
|
+
? ts.factory.createObjectLiteralExpression(
|
|
107
|
+
[
|
|
108
|
+
ts.factory.createSpreadAssignment(
|
|
109
|
+
ts.factory.createIdentifier("connection"),
|
|
110
|
+
),
|
|
111
|
+
ts.factory.createPropertyAssignment(
|
|
112
|
+
"headers",
|
|
113
|
+
ts.factory.createObjectLiteralExpression(
|
|
114
|
+
[
|
|
115
|
+
ts.factory.createSpreadAssignment(
|
|
116
|
+
IdentifierFactory.access(
|
|
117
|
+
ts.factory.createIdentifier("connection"),
|
|
118
|
+
)("headers"),
|
|
119
|
+
),
|
|
120
|
+
ts.factory.createPropertyAssignment(
|
|
121
|
+
ts.factory.createStringLiteral("Content-Type"),
|
|
122
|
+
ts.factory.createStringLiteral(contentType),
|
|
123
|
+
),
|
|
124
|
+
],
|
|
125
|
+
true,
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
],
|
|
129
|
+
true,
|
|
130
|
+
)
|
|
131
|
+
: ts.factory.createIdentifier("connection"),
|
|
132
|
+
ts.factory.createObjectLiteralExpression(
|
|
133
|
+
[
|
|
134
|
+
ts.factory.createSpreadAssignment(
|
|
135
|
+
IdentifierFactory.access(
|
|
136
|
+
ts.factory.createIdentifier(route.name),
|
|
137
|
+
)("METADATA"),
|
|
138
|
+
),
|
|
139
|
+
ts.factory.createPropertyAssignment(
|
|
140
|
+
"path",
|
|
141
|
+
ts.factory.createCallExpression(
|
|
142
|
+
IdentifierFactory.access(
|
|
143
|
+
ts.factory.createIdentifier(route.name),
|
|
144
|
+
)("path"),
|
|
145
|
+
undefined,
|
|
146
|
+
route.parameters
|
|
147
|
+
.filter(
|
|
148
|
+
(p) => p.category === "param" || p.category === "query",
|
|
149
|
+
)
|
|
150
|
+
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
151
|
+
),
|
|
152
|
+
),
|
|
153
|
+
],
|
|
154
|
+
true,
|
|
155
|
+
),
|
|
156
|
+
...(props.input
|
|
157
|
+
? [ts.factory.createIdentifier(props.input.name)]
|
|
158
|
+
: []),
|
|
159
|
+
...(config.json &&
|
|
160
|
+
typia.is<IController.IBodyParameter>(props.input) &&
|
|
161
|
+
(props.input.contentType === "application/json" ||
|
|
162
|
+
props.input.encrypted === true)
|
|
163
|
+
? [ts.factory.createIdentifier(`${route.name}.stringify`)]
|
|
164
|
+
: []),
|
|
165
|
+
],
|
|
166
|
+
);
|
|
167
|
+
const output = (awaiter: boolean) =>
|
|
168
|
+
config.simulate
|
|
169
|
+
? ts.factory.createConditionalExpression(
|
|
170
|
+
ts.factory.createIdentifier("!!connection.simulate"),
|
|
171
|
+
undefined,
|
|
172
|
+
ts.factory.createCallExpression(
|
|
173
|
+
ts.factory.createIdentifier(`${route.name}.simulate`),
|
|
174
|
+
[],
|
|
175
|
+
[
|
|
176
|
+
ts.factory.createIdentifier("connection"),
|
|
177
|
+
...route.parameters
|
|
178
|
+
.filter((p) => p.category !== "headers")
|
|
179
|
+
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
180
|
+
],
|
|
181
|
+
),
|
|
182
|
+
undefined,
|
|
183
|
+
awaiter ? ts.factory.createAwaitExpression(caller()) : caller(),
|
|
184
|
+
)
|
|
185
|
+
: awaiter
|
|
186
|
+
? ts.factory.createAwaitExpression(caller())
|
|
187
|
+
: caller();
|
|
188
|
+
return [
|
|
189
|
+
...(config.assert
|
|
190
|
+
? route.parameters
|
|
191
|
+
.filter((p) => p.category !== "headers")
|
|
192
|
+
.map((p) =>
|
|
193
|
+
ts.factory.createExpressionStatement(
|
|
194
|
+
ts.factory.createCallExpression(
|
|
195
|
+
IdentifierFactory.access(
|
|
196
|
+
ts.factory.createIdentifier(
|
|
197
|
+
SdkImportWizard.typia(importer),
|
|
198
|
+
),
|
|
199
|
+
)("assert"),
|
|
200
|
+
[
|
|
201
|
+
ts.factory.createTypeQueryNode(
|
|
202
|
+
ts.factory.createIdentifier(p.name),
|
|
203
|
+
),
|
|
204
|
+
],
|
|
205
|
+
[ts.factory.createIdentifier(p.name)],
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
)
|
|
209
|
+
: []),
|
|
210
|
+
...(route.setHeaders.length === 0
|
|
211
|
+
? [ts.factory.createReturnStatement(output(false))]
|
|
212
|
+
: write_set_headers(config)(route)(output(true))),
|
|
213
|
+
];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const write_set_headers =
|
|
217
|
+
(config: INestiaConfig) =>
|
|
218
|
+
(route: IRoute) =>
|
|
219
|
+
(condition: ts.Expression): ts.Statement[] => {
|
|
220
|
+
const accessor = (x: string) => (y: string) =>
|
|
221
|
+
x[0] === "[" ? `${x}${y}` : `${x}.${y}`;
|
|
222
|
+
const output: string = StringUtil.escapeDuplicate([
|
|
223
|
+
"connection",
|
|
224
|
+
...route.parameters.map((p) => p.name),
|
|
225
|
+
])("output");
|
|
226
|
+
const headers: string = accessor("connection")("headers");
|
|
227
|
+
const data: string = config.propagate ? accessor(output)("data") : output;
|
|
228
|
+
|
|
229
|
+
const assigners: ts.ExpressionStatement[] = [
|
|
230
|
+
ts.factory.createBinaryExpression(
|
|
231
|
+
ts.factory.createIdentifier(headers),
|
|
232
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
|
|
233
|
+
ts.factory.createObjectLiteralExpression([]),
|
|
234
|
+
),
|
|
235
|
+
...route.setHeaders.map((tuple) =>
|
|
236
|
+
tuple.type === "assigner"
|
|
237
|
+
? ts.factory.createCallExpression(
|
|
238
|
+
ts.factory.createIdentifier("Object.assign"),
|
|
239
|
+
[],
|
|
240
|
+
[
|
|
241
|
+
ts.factory.createIdentifier(headers),
|
|
242
|
+
ts.factory.createIdentifier(accessor(data)(tuple.source)),
|
|
243
|
+
],
|
|
244
|
+
)
|
|
245
|
+
: ts.factory.createBinaryExpression(
|
|
246
|
+
ts.factory.createIdentifier(
|
|
247
|
+
accessor(headers)(tuple.target ?? tuple.source),
|
|
248
|
+
),
|
|
249
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
250
|
+
ts.factory.createIdentifier(accessor(data)(tuple.source)),
|
|
251
|
+
),
|
|
252
|
+
),
|
|
253
|
+
].map(ts.factory.createExpressionStatement);
|
|
254
|
+
return [
|
|
255
|
+
ts.factory.createVariableStatement(
|
|
256
|
+
[],
|
|
257
|
+
ts.factory.createVariableDeclarationList(
|
|
258
|
+
[
|
|
259
|
+
ts.factory.createVariableDeclaration(
|
|
260
|
+
output,
|
|
261
|
+
undefined,
|
|
262
|
+
getReturnType(config)(route),
|
|
263
|
+
condition,
|
|
264
|
+
),
|
|
265
|
+
],
|
|
266
|
+
ts.NodeFlags.Const,
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
...(config.propagate
|
|
270
|
+
? [
|
|
271
|
+
ts.factory.createIfStatement(
|
|
272
|
+
ts.factory.createIdentifier(accessor(output)("success")),
|
|
273
|
+
assigners.length === 1
|
|
274
|
+
? assigners[0]
|
|
275
|
+
: ts.factory.createBlock(assigners, true),
|
|
276
|
+
undefined,
|
|
277
|
+
),
|
|
278
|
+
]
|
|
279
|
+
: assigners),
|
|
280
|
+
ts.factory.createReturnStatement(ts.factory.createIdentifier(output)),
|
|
281
|
+
];
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const getTypeName =
|
|
286
|
+
(config: INestiaConfig) =>
|
|
287
|
+
(importer: ImportDictionary) =>
|
|
288
|
+
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
289
|
+
p.metadata
|
|
290
|
+
? SdkTypeProgrammer.write(config)(importer)(p.metadata)
|
|
291
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
292
|
+
|
|
293
|
+
const getReturnType = (config: INestiaConfig) => (route: IRoute) =>
|
|
294
|
+
ts.factory.createTypeReferenceNode(
|
|
295
|
+
config.propagate !== true && route.output.typeName === "void"
|
|
296
|
+
? "void"
|
|
297
|
+
: `${route.name}.Output`,
|
|
298
|
+
);
|