@nestia/sdk 4.3.0-dev.20241215 → 4.3.0

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.
Files changed (109) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +87 -87
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/executable/internal/NestiaConfigLoader.js +4 -4
  15. package/lib/executable/sdk.js +12 -12
  16. package/package.json +6 -6
  17. package/src/INestiaConfig.ts +271 -271
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +138 -138
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/ConfigAnalyzer.ts +155 -155
  22. package/src/analyses/ExceptionAnalyzer.ts +154 -154
  23. package/src/analyses/GenericAnalyzer.ts +49 -49
  24. package/src/analyses/ImportAnalyzer.ts +171 -171
  25. package/src/analyses/PathAnalyzer.ts +69 -69
  26. package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
  27. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  28. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -71
  29. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
  30. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -127
  31. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  32. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
  33. package/src/analyses/SecurityAnalyzer.ts +25 -25
  34. package/src/analyses/TypedHttpRouteAnalyzer.ts +186 -186
  35. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -18
  36. package/src/decorators/OperationMetadata.ts +15 -15
  37. package/src/executable/internal/CommandParser.ts +15 -15
  38. package/src/executable/internal/NestiaConfigLoader.ts +78 -78
  39. package/src/executable/internal/NestiaSdkCommand.ts +103 -103
  40. package/src/executable/sdk.ts +75 -75
  41. package/src/generates/CloneGenerator.ts +66 -66
  42. package/src/generates/E2eGenerator.ts +32 -32
  43. package/src/generates/SdkGenerator.ts +159 -159
  44. package/src/generates/SwaggerGenerator.ts +292 -292
  45. package/src/generates/internal/E2eFileProgrammer.ts +183 -183
  46. package/src/generates/internal/FilePrinter.ts +53 -53
  47. package/src/generates/internal/ImportDictionary.ts +147 -147
  48. package/src/generates/internal/SdkAliasCollection.ts +185 -185
  49. package/src/generates/internal/SdkDistributionComposer.ts +103 -103
  50. package/src/generates/internal/SdkFileProgrammer.ts +116 -116
  51. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
  52. package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -71
  53. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
  54. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +529 -529
  55. package/src/generates/internal/SdkHttpRouteProgrammer.ts +117 -117
  56. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +362 -362
  57. package/src/generates/internal/SdkImportWizard.ts +55 -55
  58. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  59. package/src/generates/internal/SdkTypeProgrammer.ts +377 -377
  60. package/src/generates/internal/SdkTypeTagProgrammer.ts +120 -120
  61. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +363 -363
  62. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +265 -265
  63. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  64. package/src/generates/internal/SwaggerOperationComposer.ts +117 -117
  65. package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
  66. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  67. package/src/index.ts +4 -4
  68. package/src/module.ts +3 -3
  69. package/src/structures/INestiaProject.ts +13 -13
  70. package/src/structures/INestiaSdkInput.ts +20 -20
  71. package/src/structures/IReflectApplication.ts +8 -8
  72. package/src/structures/IReflectController.ts +15 -15
  73. package/src/structures/IReflectHttpOperation.ts +26 -26
  74. package/src/structures/IReflectHttpOperationException.ts +19 -19
  75. package/src/structures/IReflectHttpOperationParameter.ts +81 -81
  76. package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
  77. package/src/structures/IReflectOperationError.ts +26 -26
  78. package/src/structures/IReflectType.ts +4 -4
  79. package/src/structures/IReflectTypeImport.ts +4 -4
  80. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  81. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
  82. package/src/structures/ITypedApplication.ts +11 -11
  83. package/src/structures/ITypedHttpRoute.ts +30 -30
  84. package/src/structures/ITypedHttpRouteException.ts +15 -15
  85. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  86. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  87. package/src/structures/ITypedWebSocketRoute.ts +20 -20
  88. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  89. package/src/structures/MethodType.ts +5 -5
  90. package/src/structures/ParamCategory.ts +1 -1
  91. package/src/structures/TypeEntry.ts +22 -22
  92. package/src/transform.ts +9 -9
  93. package/src/transformers/IOperationMetadata.ts +44 -44
  94. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  95. package/src/transformers/SdkOperationProgrammer.ts +209 -209
  96. package/src/transformers/SdkOperationTransformer.ts +253 -253
  97. package/src/transformers/TextPlainValidator.ts +17 -17
  98. package/src/typings/get-function-location.d.ts +7 -7
  99. package/src/utils/ArrayUtil.ts +26 -26
  100. package/src/utils/FileRetriever.ts +22 -22
  101. package/src/utils/MapUtil.ts +14 -14
  102. package/src/utils/MetadataUtil.ts +26 -26
  103. package/src/utils/PathUtil.ts +10 -10
  104. package/src/utils/SourceFinder.ts +66 -66
  105. package/src/utils/StringUtil.ts +17 -17
  106. package/src/utils/StripEnums.ts +5 -5
  107. package/src/utils/VersioningStrategy.ts +28 -28
  108. package/src/validators/HttpHeadersValidator.ts +34 -34
  109. package/src/validators/HttpQueryValidator.ts +34 -34
@@ -1,301 +1,301 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
-
5
- import { INestiaProject } from "../../structures/INestiaProject";
6
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
- import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
8
- import { StringUtil } from "../../utils/StringUtil";
9
- import { ImportDictionary } from "./ImportDictionary";
10
- import { SdkAliasCollection } from "./SdkAliasCollection";
11
- import { SdkImportWizard } from "./SdkImportWizard";
12
-
13
- export namespace SdkHttpFunctionProgrammer {
14
- export const write =
15
- (project: INestiaProject) =>
16
- (importer: ImportDictionary) =>
17
- (
18
- route: ITypedHttpRoute,
19
- props: {
20
- headers: ITypedHttpRouteParameter.IHeaders | undefined;
21
- query: ITypedHttpRouteParameter.IQuery | undefined;
22
- input: ITypedHttpRouteParameter.IBody | undefined;
23
- },
24
- ): ts.FunctionDeclaration =>
25
- 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.metadata.optional === true
51
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
52
- : undefined,
53
- project.config.primitive !== false &&
54
- (p === props.query || p === props.input)
55
- ? ts.factory.createTypeReferenceNode(
56
- `${route.name}.${p === props.query ? "Query" : "Input"}`,
57
- )
58
- : project.config.clone === true
59
- ? SdkAliasCollection.from(project)(importer)(p.metadata)
60
- : SdkAliasCollection.name(p),
61
- ),
62
- ),
63
- ],
64
- ts.factory.createTypeReferenceNode("Promise", [
65
- project.config.propagate === true ||
66
- route.success.metadata.size() !== 0
67
- ? ts.factory.createTypeReferenceNode(`${route.name}.Output`)
68
- : ts.factory.createTypeReferenceNode("void"),
69
- ]),
70
- ts.factory.createBlock(
71
- write_body(project)(importer)(route, props),
72
- true,
73
- ),
74
- );
75
-
76
- const write_body =
77
- (project: INestiaProject) =>
78
- (importer: ImportDictionary) =>
79
- (
80
- route: ITypedHttpRoute,
81
- props: {
82
- headers: ITypedHttpRouteParameter.IHeaders | undefined;
83
- query: ITypedHttpRouteParameter.IQuery | undefined;
84
- input: ITypedHttpRouteParameter.IBody | undefined;
85
- },
86
- ): ts.Statement[] => {
87
- const caller = () =>
88
- ts.factory.createCallExpression(
89
- IdentifierFactory.access(
90
- ts.factory.createIdentifier(
91
- SdkImportWizard.Fetcher(
92
- !!props.input?.encrypted || route.success.encrypted,
93
- )(importer),
94
- ),
95
- project.config.propagate ? "propagate" : "fetch",
96
- ),
97
- project.config.propagate
98
- ? route.method.toLowerCase() === "get" ||
99
- route.method.toLowerCase() === "head"
100
- ? [TypeFactory.keyword("any")]
101
- : [TypeFactory.keyword("any"), TypeFactory.keyword("any")]
102
- : undefined,
103
- [
104
- props.input && props.input.contentType !== "multipart/form-data"
105
- ? ts.factory.createObjectLiteralExpression(
106
- [
107
- ts.factory.createSpreadAssignment(
108
- ts.factory.createIdentifier("connection"),
109
- ),
110
- ts.factory.createPropertyAssignment(
111
- "headers",
112
- ts.factory.createObjectLiteralExpression(
113
- [
114
- ts.factory.createSpreadAssignment(
115
- IdentifierFactory.access(
116
- ts.factory.createIdentifier("connection"),
117
- "headers",
118
- ),
119
- ),
120
- ts.factory.createPropertyAssignment(
121
- ts.factory.createStringLiteral("Content-Type"),
122
- ts.factory.createStringLiteral(
123
- props.input?.contentType ?? "application/json",
124
- ),
125
- ),
126
- ],
127
- true,
128
- ),
129
- ),
130
- ],
131
- true,
132
- )
133
- : ts.factory.createIdentifier("connection"),
134
- ts.factory.createObjectLiteralExpression(
135
- [
136
- ts.factory.createSpreadAssignment(
137
- IdentifierFactory.access(
138
- ts.factory.createIdentifier(route.name),
139
- "METADATA",
140
- ),
141
- ),
142
- ts.factory.createPropertyAssignment(
143
- "template",
144
- IdentifierFactory.access(
145
- IdentifierFactory.access(
146
- ts.factory.createIdentifier(route.name),
147
- "METADATA",
148
- ),
149
- "path",
150
- ),
151
- ),
152
- ts.factory.createPropertyAssignment(
153
- "path",
154
- ts.factory.createCallExpression(
155
- IdentifierFactory.access(
156
- ts.factory.createIdentifier(route.name),
157
- "path",
158
- ),
159
- undefined,
160
- route.parameters
161
- .filter(
162
- (p) => p.category === "param" || p.category === "query",
163
- )
164
- .map((p) => ts.factory.createIdentifier(p.name)),
165
- ),
166
- ),
167
- ],
168
- true,
169
- ),
170
- ...(props.input
171
- ? [ts.factory.createIdentifier(props.input.name)]
172
- : []),
173
- ...(project.config.json &&
174
- props.input !== undefined &&
175
- (props.input.contentType === "application/json" ||
176
- props.input.encrypted === true)
177
- ? [ts.factory.createIdentifier(`${route.name}.stringify`)]
178
- : []),
179
- ],
180
- );
181
- const output = (awaiter: boolean) =>
182
- project.config.simulate
183
- ? ts.factory.createConditionalExpression(
184
- ts.factory.createIdentifier("!!connection.simulate"),
185
- undefined,
186
- ts.factory.createCallExpression(
187
- ts.factory.createIdentifier(`${route.name}.simulate`),
188
- [],
189
- [
190
- ts.factory.createIdentifier("connection"),
191
- ...route.parameters
192
- .filter((p) => p.category !== "headers")
193
- .map((p) => ts.factory.createIdentifier(p.name)),
194
- ],
195
- ),
196
- undefined,
197
- awaiter ? ts.factory.createAwaitExpression(caller()) : caller(),
198
- )
199
- : awaiter
200
- ? ts.factory.createAwaitExpression(caller())
201
- : caller();
202
- return [
203
- ...(project.config.assert
204
- ? route.parameters
205
- .filter((p) => p.category !== "headers")
206
- .map((p) =>
207
- ts.factory.createExpressionStatement(
208
- ts.factory.createCallExpression(
209
- IdentifierFactory.access(
210
- ts.factory.createIdentifier(
211
- SdkImportWizard.typia(importer),
212
- ),
213
- "assert",
214
- ),
215
- [
216
- ts.factory.createTypeQueryNode(
217
- ts.factory.createIdentifier(p.name),
218
- ),
219
- ],
220
- [ts.factory.createIdentifier(p.name)],
221
- ),
222
- ),
223
- )
224
- : []),
225
- ...(route.success.setHeaders.length === 0
226
- ? [ts.factory.createReturnStatement(output(false))]
227
- : write_set_headers(project)(importer)(route)(output(true))),
228
- ];
229
- };
230
-
231
- const write_set_headers =
232
- (project: INestiaProject) =>
233
- (importer: ImportDictionary) =>
234
- (route: ITypedHttpRoute) =>
235
- (condition: ts.Expression): ts.Statement[] => {
236
- const accessor = (x: string) => (y: string) =>
237
- x[0] === "[" ? `${x}${y}` : `${x}.${y}`;
238
- const output: string = StringUtil.escapeDuplicate([
239
- "connection",
240
- ...route.parameters.map((p) => p.name),
241
- ])("output");
242
- const headers: string = accessor("connection")("headers");
243
- const data: string = project.config.propagate
244
- ? accessor(output)("data")
245
- : output;
246
-
247
- const assigners: ts.ExpressionStatement[] = [
248
- ts.factory.createBinaryExpression(
249
- ts.factory.createIdentifier(headers),
250
- ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
251
- ts.factory.createObjectLiteralExpression([]),
252
- ),
253
- ...route.success.setHeaders.map((tuple) =>
254
- tuple.type === "assigner"
255
- ? ts.factory.createCallExpression(
256
- ts.factory.createIdentifier("Object.assign"),
257
- [],
258
- [
259
- ts.factory.createIdentifier(headers),
260
- ts.factory.createIdentifier(accessor(data)(tuple.source)),
261
- ],
262
- )
263
- : ts.factory.createBinaryExpression(
264
- ts.factory.createIdentifier(
265
- accessor(headers)(tuple.target ?? tuple.source),
266
- ),
267
- ts.factory.createToken(ts.SyntaxKind.EqualsToken),
268
- ts.factory.createIdentifier(accessor(data)(tuple.source)),
269
- ),
270
- ),
271
- ].map(ts.factory.createExpressionStatement);
272
- return [
273
- ts.factory.createVariableStatement(
274
- [],
275
- ts.factory.createVariableDeclarationList(
276
- [
277
- ts.factory.createVariableDeclaration(
278
- output,
279
- undefined,
280
- SdkAliasCollection.output(project)(importer)(route),
281
- condition,
282
- ),
283
- ],
284
- ts.NodeFlags.Const,
285
- ),
286
- ),
287
- ...(project.config.propagate
288
- ? [
289
- ts.factory.createIfStatement(
290
- ts.factory.createIdentifier(accessor(output)("success")),
291
- assigners.length === 1
292
- ? assigners[0]
293
- : ts.factory.createBlock(assigners, true),
294
- undefined,
295
- ),
296
- ]
297
- : assigners),
298
- ts.factory.createReturnStatement(ts.factory.createIdentifier(output)),
299
- ];
300
- };
301
- }
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
+
5
+ import { INestiaProject } from "../../structures/INestiaProject";
6
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
+ import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
8
+ import { StringUtil } from "../../utils/StringUtil";
9
+ import { ImportDictionary } from "./ImportDictionary";
10
+ import { SdkAliasCollection } from "./SdkAliasCollection";
11
+ import { SdkImportWizard } from "./SdkImportWizard";
12
+
13
+ export namespace SdkHttpFunctionProgrammer {
14
+ export const write =
15
+ (project: INestiaProject) =>
16
+ (importer: ImportDictionary) =>
17
+ (
18
+ route: ITypedHttpRoute,
19
+ props: {
20
+ headers: ITypedHttpRouteParameter.IHeaders | undefined;
21
+ query: ITypedHttpRouteParameter.IQuery | undefined;
22
+ input: ITypedHttpRouteParameter.IBody | undefined;
23
+ },
24
+ ): ts.FunctionDeclaration =>
25
+ 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.metadata.optional === true
51
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
52
+ : undefined,
53
+ project.config.primitive !== false &&
54
+ (p === props.query || p === props.input)
55
+ ? ts.factory.createTypeReferenceNode(
56
+ `${route.name}.${p === props.query ? "Query" : "Input"}`,
57
+ )
58
+ : project.config.clone === true
59
+ ? SdkAliasCollection.from(project)(importer)(p.metadata)
60
+ : SdkAliasCollection.name(p),
61
+ ),
62
+ ),
63
+ ],
64
+ ts.factory.createTypeReferenceNode("Promise", [
65
+ project.config.propagate === true ||
66
+ route.success.metadata.size() !== 0
67
+ ? ts.factory.createTypeReferenceNode(`${route.name}.Output`)
68
+ : ts.factory.createTypeReferenceNode("void"),
69
+ ]),
70
+ ts.factory.createBlock(
71
+ write_body(project)(importer)(route, props),
72
+ true,
73
+ ),
74
+ );
75
+
76
+ const write_body =
77
+ (project: INestiaProject) =>
78
+ (importer: ImportDictionary) =>
79
+ (
80
+ route: ITypedHttpRoute,
81
+ props: {
82
+ headers: ITypedHttpRouteParameter.IHeaders | undefined;
83
+ query: ITypedHttpRouteParameter.IQuery | undefined;
84
+ input: ITypedHttpRouteParameter.IBody | undefined;
85
+ },
86
+ ): ts.Statement[] => {
87
+ const caller = () =>
88
+ ts.factory.createCallExpression(
89
+ IdentifierFactory.access(
90
+ ts.factory.createIdentifier(
91
+ SdkImportWizard.Fetcher(
92
+ !!props.input?.encrypted || route.success.encrypted,
93
+ )(importer),
94
+ ),
95
+ project.config.propagate ? "propagate" : "fetch",
96
+ ),
97
+ project.config.propagate
98
+ ? route.method.toLowerCase() === "get" ||
99
+ route.method.toLowerCase() === "head"
100
+ ? [TypeFactory.keyword("any")]
101
+ : [TypeFactory.keyword("any"), TypeFactory.keyword("any")]
102
+ : undefined,
103
+ [
104
+ props.input && props.input.contentType !== "multipart/form-data"
105
+ ? ts.factory.createObjectLiteralExpression(
106
+ [
107
+ ts.factory.createSpreadAssignment(
108
+ ts.factory.createIdentifier("connection"),
109
+ ),
110
+ ts.factory.createPropertyAssignment(
111
+ "headers",
112
+ ts.factory.createObjectLiteralExpression(
113
+ [
114
+ ts.factory.createSpreadAssignment(
115
+ IdentifierFactory.access(
116
+ ts.factory.createIdentifier("connection"),
117
+ "headers",
118
+ ),
119
+ ),
120
+ ts.factory.createPropertyAssignment(
121
+ ts.factory.createStringLiteral("Content-Type"),
122
+ ts.factory.createStringLiteral(
123
+ props.input?.contentType ?? "application/json",
124
+ ),
125
+ ),
126
+ ],
127
+ true,
128
+ ),
129
+ ),
130
+ ],
131
+ true,
132
+ )
133
+ : ts.factory.createIdentifier("connection"),
134
+ ts.factory.createObjectLiteralExpression(
135
+ [
136
+ ts.factory.createSpreadAssignment(
137
+ IdentifierFactory.access(
138
+ ts.factory.createIdentifier(route.name),
139
+ "METADATA",
140
+ ),
141
+ ),
142
+ ts.factory.createPropertyAssignment(
143
+ "template",
144
+ IdentifierFactory.access(
145
+ IdentifierFactory.access(
146
+ ts.factory.createIdentifier(route.name),
147
+ "METADATA",
148
+ ),
149
+ "path",
150
+ ),
151
+ ),
152
+ ts.factory.createPropertyAssignment(
153
+ "path",
154
+ ts.factory.createCallExpression(
155
+ IdentifierFactory.access(
156
+ ts.factory.createIdentifier(route.name),
157
+ "path",
158
+ ),
159
+ undefined,
160
+ route.parameters
161
+ .filter(
162
+ (p) => p.category === "param" || p.category === "query",
163
+ )
164
+ .map((p) => ts.factory.createIdentifier(p.name)),
165
+ ),
166
+ ),
167
+ ],
168
+ true,
169
+ ),
170
+ ...(props.input
171
+ ? [ts.factory.createIdentifier(props.input.name)]
172
+ : []),
173
+ ...(project.config.json &&
174
+ props.input !== undefined &&
175
+ (props.input.contentType === "application/json" ||
176
+ props.input.encrypted === true)
177
+ ? [ts.factory.createIdentifier(`${route.name}.stringify`)]
178
+ : []),
179
+ ],
180
+ );
181
+ const output = (awaiter: boolean) =>
182
+ project.config.simulate
183
+ ? ts.factory.createConditionalExpression(
184
+ ts.factory.createIdentifier("!!connection.simulate"),
185
+ undefined,
186
+ ts.factory.createCallExpression(
187
+ ts.factory.createIdentifier(`${route.name}.simulate`),
188
+ [],
189
+ [
190
+ ts.factory.createIdentifier("connection"),
191
+ ...route.parameters
192
+ .filter((p) => p.category !== "headers")
193
+ .map((p) => ts.factory.createIdentifier(p.name)),
194
+ ],
195
+ ),
196
+ undefined,
197
+ awaiter ? ts.factory.createAwaitExpression(caller()) : caller(),
198
+ )
199
+ : awaiter
200
+ ? ts.factory.createAwaitExpression(caller())
201
+ : caller();
202
+ return [
203
+ ...(project.config.assert
204
+ ? route.parameters
205
+ .filter((p) => p.category !== "headers")
206
+ .map((p) =>
207
+ ts.factory.createExpressionStatement(
208
+ ts.factory.createCallExpression(
209
+ IdentifierFactory.access(
210
+ ts.factory.createIdentifier(
211
+ SdkImportWizard.typia(importer),
212
+ ),
213
+ "assert",
214
+ ),
215
+ [
216
+ ts.factory.createTypeQueryNode(
217
+ ts.factory.createIdentifier(p.name),
218
+ ),
219
+ ],
220
+ [ts.factory.createIdentifier(p.name)],
221
+ ),
222
+ ),
223
+ )
224
+ : []),
225
+ ...(route.success.setHeaders.length === 0
226
+ ? [ts.factory.createReturnStatement(output(false))]
227
+ : write_set_headers(project)(importer)(route)(output(true))),
228
+ ];
229
+ };
230
+
231
+ const write_set_headers =
232
+ (project: INestiaProject) =>
233
+ (importer: ImportDictionary) =>
234
+ (route: ITypedHttpRoute) =>
235
+ (condition: ts.Expression): ts.Statement[] => {
236
+ const accessor = (x: string) => (y: string) =>
237
+ x[0] === "[" ? `${x}${y}` : `${x}.${y}`;
238
+ const output: string = StringUtil.escapeDuplicate([
239
+ "connection",
240
+ ...route.parameters.map((p) => p.name),
241
+ ])("output");
242
+ const headers: string = accessor("connection")("headers");
243
+ const data: string = project.config.propagate
244
+ ? accessor(output)("data")
245
+ : output;
246
+
247
+ const assigners: ts.ExpressionStatement[] = [
248
+ ts.factory.createBinaryExpression(
249
+ ts.factory.createIdentifier(headers),
250
+ ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
251
+ ts.factory.createObjectLiteralExpression([]),
252
+ ),
253
+ ...route.success.setHeaders.map((tuple) =>
254
+ tuple.type === "assigner"
255
+ ? ts.factory.createCallExpression(
256
+ ts.factory.createIdentifier("Object.assign"),
257
+ [],
258
+ [
259
+ ts.factory.createIdentifier(headers),
260
+ ts.factory.createIdentifier(accessor(data)(tuple.source)),
261
+ ],
262
+ )
263
+ : ts.factory.createBinaryExpression(
264
+ ts.factory.createIdentifier(
265
+ accessor(headers)(tuple.target ?? tuple.source),
266
+ ),
267
+ ts.factory.createToken(ts.SyntaxKind.EqualsToken),
268
+ ts.factory.createIdentifier(accessor(data)(tuple.source)),
269
+ ),
270
+ ),
271
+ ].map(ts.factory.createExpressionStatement);
272
+ return [
273
+ ts.factory.createVariableStatement(
274
+ [],
275
+ ts.factory.createVariableDeclarationList(
276
+ [
277
+ ts.factory.createVariableDeclaration(
278
+ output,
279
+ undefined,
280
+ SdkAliasCollection.output(project)(importer)(route),
281
+ condition,
282
+ ),
283
+ ],
284
+ ts.NodeFlags.Const,
285
+ ),
286
+ ),
287
+ ...(project.config.propagate
288
+ ? [
289
+ ts.factory.createIfStatement(
290
+ ts.factory.createIdentifier(accessor(output)("success")),
291
+ assigners.length === 1
292
+ ? assigners[0]
293
+ : ts.factory.createBlock(assigners, true),
294
+ undefined,
295
+ ),
296
+ ]
297
+ : assigners),
298
+ ts.factory.createReturnStatement(ts.factory.createIdentifier(output)),
299
+ ];
300
+ };
301
+ }