@nestia/sdk 3.1.0-dev.20240429 → 3.1.0-dev.20240430

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