@nestia/sdk 4.4.2-dev.20241217 → 4.4.2

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 +5 -5
  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,362 +1,362 @@
1
- import ts from "typescript";
2
- import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
- import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
5
- import { StatementFactory } from "typia/lib/factories/StatementFactory";
6
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
7
-
8
- import { INestiaProject } from "../../structures/INestiaProject";
9
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
10
- import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
11
- import { ImportDictionary } from "./ImportDictionary";
12
- import { SdkAliasCollection } from "./SdkAliasCollection";
13
- import { SdkImportWizard } from "./SdkImportWizard";
14
-
15
- export namespace SdkHttpSimulationProgrammer {
16
- export const random =
17
- (project: INestiaProject) =>
18
- (importer: ImportDictionary) =>
19
- (route: ITypedHttpRoute): ts.VariableStatement => {
20
- const output = SdkAliasCollection.responseBody(project)(importer)(route);
21
- return constant("random")(
22
- ts.factory.createArrowFunction(
23
- undefined,
24
- undefined,
25
- [
26
- ts.factory.createParameterDeclaration(
27
- undefined,
28
- undefined,
29
- "g",
30
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
31
- ts.factory.createTypeReferenceNode(
32
- ts.factory.createIdentifier("Partial"),
33
- [
34
- ts.factory.createTypeReferenceNode(
35
- `${SdkImportWizard.typia(importer)}.IRandomGenerator`,
36
- ),
37
- ],
38
- ),
39
- ),
40
- ],
41
- project.config.primitive === false
42
- ? output
43
- : ts.factory.createTypeReferenceNode(
44
- SdkImportWizard.Resolved(importer),
45
- [output],
46
- ),
47
- undefined,
48
- ts.factory.createCallExpression(
49
- IdentifierFactory.access(
50
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
51
- "random",
52
- ),
53
- [output],
54
- [ts.factory.createIdentifier("g")],
55
- ),
56
- ),
57
- );
58
- };
59
-
60
- export const simulate =
61
- (project: INestiaProject) =>
62
- (importer: ImportDictionary) =>
63
- (
64
- route: ITypedHttpRoute,
65
- props: {
66
- headers: ITypedHttpRouteParameter.IHeaders | undefined;
67
- query: ITypedHttpRouteParameter.IQuery | undefined;
68
- input: ITypedHttpRouteParameter.IBody | undefined;
69
- },
70
- ): ts.VariableStatement => {
71
- const output: boolean =
72
- project.config.propagate === true ||
73
- route.success.metadata.size() !== 0;
74
- const caller = () =>
75
- ts.factory.createCallExpression(
76
- ts.factory.createIdentifier("random"),
77
- undefined,
78
- [
79
- ts.factory.createConditionalExpression(
80
- ts.factory.createLogicalAnd(
81
- ts.factory.createStrictEquality(
82
- ts.factory.createStringLiteral("object"),
83
- ts.factory.createTypeOfExpression(
84
- ts.factory.createIdentifier("connection.simulate"),
85
- ),
86
- ),
87
- ts.factory.createStrictInequality(
88
- ts.factory.createNull(),
89
- ts.factory.createIdentifier("connection.simulate"),
90
- ),
91
- ),
92
- undefined,
93
- ts.factory.createIdentifier("connection.simulate"),
94
- undefined,
95
- ts.factory.createIdentifier("undefined"),
96
- ),
97
- ],
98
- );
99
-
100
- return constant("simulate")(
101
- ts.factory.createArrowFunction(
102
- undefined,
103
- undefined,
104
- [
105
- IdentifierFactory.parameter(
106
- "connection",
107
- ts.factory.createTypeReferenceNode(
108
- SdkImportWizard.IConnection(importer),
109
- route.parameters.some(
110
- (p) => p.category === "headers" && p.field === null,
111
- )
112
- ? [
113
- ts.factory.createTypeReferenceNode(
114
- `${route.name}.Headers`,
115
- ),
116
- ]
117
- : [],
118
- ),
119
- ),
120
- ...route.parameters
121
- .filter((p) => p.category !== "headers")
122
- .map((p) =>
123
- ts.factory.createParameterDeclaration(
124
- [],
125
- undefined,
126
- p.name,
127
- p.metadata.optional
128
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
129
- : undefined,
130
- project.config.primitive !== false &&
131
- (p === props.query || p === props.input)
132
- ? ts.factory.createTypeReferenceNode(
133
- `${route.name}.${p === props.query ? "Query" : "Input"}`,
134
- )
135
- : project.config.clone === true
136
- ? SdkAliasCollection.from(project)(importer)(p.metadata)
137
- : SdkAliasCollection.name(p),
138
- ),
139
- ),
140
- ],
141
- ts.factory.createTypeReferenceNode(output ? "Output" : "void"),
142
- undefined,
143
- ts.factory.createBlock(
144
- [
145
- ...assert(project)(importer)(route),
146
- ts.factory.createReturnStatement(
147
- project.config.propagate
148
- ? ts.factory.createAsExpression(
149
- ts.factory.createObjectLiteralExpression(
150
- [
151
- ts.factory.createPropertyAssignment(
152
- "success",
153
- ts.factory.createTrue(),
154
- ),
155
- ts.factory.createPropertyAssignment(
156
- "status",
157
- ExpressionFactory.number(
158
- route.success.status ??
159
- (route.method === "POST" ? 201 : 200),
160
- ),
161
- ),
162
- ts.factory.createPropertyAssignment(
163
- "headers",
164
- LiteralFactory.write({
165
- "Content-Type": route.success.contentType,
166
- }),
167
- ),
168
- ts.factory.createPropertyAssignment("data", caller()),
169
- ],
170
- true,
171
- ),
172
- ts.factory.createTypeReferenceNode("Output"),
173
- )
174
- : caller(),
175
- ),
176
- ],
177
- true,
178
- ),
179
- ),
180
- );
181
- };
182
-
183
- const assert =
184
- (project: INestiaProject) =>
185
- (importer: ImportDictionary) =>
186
- (route: ITypedHttpRoute): ts.Statement[] => {
187
- const parameters = route.parameters.filter(
188
- (p) => p.category !== "headers",
189
- );
190
- if (parameters.length === 0) return [];
191
-
192
- const typia = SdkImportWizard.typia(importer);
193
- const validator = StatementFactory.constant({
194
- name: "assert",
195
- value: ts.factory.createCallExpression(
196
- IdentifierFactory.access(
197
- ts.factory.createIdentifier(
198
- importer.external({
199
- type: false,
200
- library: `@nestia/fetcher/lib/NestiaSimulator`,
201
- instance: "NestiaSimulator",
202
- }),
203
- ),
204
- "assert",
205
- ),
206
- undefined,
207
- [
208
- ts.factory.createObjectLiteralExpression(
209
- [
210
- ts.factory.createPropertyAssignment(
211
- "method",
212
- ts.factory.createIdentifier("METADATA.method"),
213
- ),
214
- ts.factory.createPropertyAssignment(
215
- "host",
216
- ts.factory.createIdentifier("connection.host"),
217
- ),
218
- ts.factory.createPropertyAssignment(
219
- "path",
220
- ts.factory.createCallExpression(
221
- ts.factory.createIdentifier("path"),
222
- undefined,
223
- route.parameters
224
- .filter(
225
- (p) => p.category === "param" || p.category === "query",
226
- )
227
- .map((p) => ts.factory.createIdentifier(p.name)),
228
- ),
229
- ),
230
- ts.factory.createPropertyAssignment(
231
- "contentType",
232
- ts.factory.createIdentifier(
233
- JSON.stringify(route.success.contentType),
234
- ),
235
- ),
236
- ],
237
- true,
238
- ),
239
- ],
240
- ),
241
- });
242
- const individual = parameters
243
- .map((p) =>
244
- ts.factory.createCallExpression(
245
- (() => {
246
- const base = IdentifierFactory.access(
247
- ts.factory.createIdentifier("assert"),
248
- p.category,
249
- );
250
- if (p.category !== "param") return base;
251
- return ts.factory.createCallExpression(base, undefined, [
252
- ts.factory.createStringLiteral(p.name),
253
- ]);
254
- })(),
255
- undefined,
256
- [
257
- ts.factory.createArrowFunction(
258
- undefined,
259
- undefined,
260
- [],
261
- undefined,
262
- undefined,
263
- ts.factory.createCallExpression(
264
- IdentifierFactory.access(
265
- ts.factory.createIdentifier(typia),
266
- "assert",
267
- ),
268
- undefined,
269
- [ts.factory.createIdentifier(p.name)],
270
- ),
271
- ),
272
- ],
273
- ),
274
- )
275
- .map(ts.factory.createExpressionStatement);
276
-
277
- return [
278
- validator,
279
- ...(project.config.propagate !== true
280
- ? individual
281
- : [tryAndCatch(importer)(individual)]),
282
- ];
283
- };
284
-
285
- const tryAndCatch =
286
- (importer: ImportDictionary) => (individual: ts.Statement[]) =>
287
- ts.factory.createTryStatement(
288
- ts.factory.createBlock(individual, true),
289
- ts.factory.createCatchClause(
290
- "exp",
291
- ts.factory.createBlock(
292
- [
293
- ts.factory.createIfStatement(
294
- ts.factory.createLogicalNot(
295
- ts.factory.createCallExpression(
296
- IdentifierFactory.access(
297
- ts.factory.createIdentifier(
298
- SdkImportWizard.typia(importer),
299
- ),
300
- "is",
301
- ),
302
- [
303
- ts.factory.createTypeReferenceNode(
304
- SdkImportWizard.HttpError(importer),
305
- ),
306
- ],
307
- [ts.factory.createIdentifier("exp")],
308
- ),
309
- ),
310
- ts.factory.createThrowStatement(
311
- ts.factory.createIdentifier("exp"),
312
- ),
313
- ),
314
- ts.factory.createReturnStatement(
315
- ts.factory.createAsExpression(
316
- ts.factory.createObjectLiteralExpression(
317
- [
318
- ts.factory.createPropertyAssignment(
319
- "success",
320
- ts.factory.createFalse(),
321
- ),
322
- ts.factory.createPropertyAssignment(
323
- "status",
324
- ts.factory.createIdentifier("exp.status"),
325
- ),
326
- ts.factory.createPropertyAssignment(
327
- "headers",
328
- ts.factory.createIdentifier("exp.headers"),
329
- ),
330
- ts.factory.createPropertyAssignment(
331
- "data",
332
- ts.factory.createIdentifier("exp.toJSON().message"),
333
- ),
334
- ],
335
- true,
336
- ),
337
- TypeFactory.keyword("any"),
338
- ),
339
- ),
340
- ],
341
- true,
342
- ),
343
- ),
344
- undefined,
345
- );
346
- }
347
-
348
- const constant = (name: string) => (expression: ts.Expression) =>
349
- ts.factory.createVariableStatement(
350
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
351
- ts.factory.createVariableDeclarationList(
352
- [
353
- ts.factory.createVariableDeclaration(
354
- ts.factory.createIdentifier(name),
355
- undefined,
356
- undefined,
357
- expression,
358
- ),
359
- ],
360
- ts.NodeFlags.Const,
361
- ),
362
- );
1
+ import ts from "typescript";
2
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
5
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
6
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
7
+
8
+ import { INestiaProject } from "../../structures/INestiaProject";
9
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
10
+ import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
11
+ import { ImportDictionary } from "./ImportDictionary";
12
+ import { SdkAliasCollection } from "./SdkAliasCollection";
13
+ import { SdkImportWizard } from "./SdkImportWizard";
14
+
15
+ export namespace SdkHttpSimulationProgrammer {
16
+ export const random =
17
+ (project: INestiaProject) =>
18
+ (importer: ImportDictionary) =>
19
+ (route: ITypedHttpRoute): ts.VariableStatement => {
20
+ const output = SdkAliasCollection.responseBody(project)(importer)(route);
21
+ return constant("random")(
22
+ ts.factory.createArrowFunction(
23
+ undefined,
24
+ undefined,
25
+ [
26
+ ts.factory.createParameterDeclaration(
27
+ undefined,
28
+ undefined,
29
+ "g",
30
+ ts.factory.createToken(ts.SyntaxKind.QuestionToken),
31
+ ts.factory.createTypeReferenceNode(
32
+ ts.factory.createIdentifier("Partial"),
33
+ [
34
+ ts.factory.createTypeReferenceNode(
35
+ `${SdkImportWizard.typia(importer)}.IRandomGenerator`,
36
+ ),
37
+ ],
38
+ ),
39
+ ),
40
+ ],
41
+ project.config.primitive === false
42
+ ? output
43
+ : ts.factory.createTypeReferenceNode(
44
+ SdkImportWizard.Resolved(importer),
45
+ [output],
46
+ ),
47
+ undefined,
48
+ ts.factory.createCallExpression(
49
+ IdentifierFactory.access(
50
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
51
+ "random",
52
+ ),
53
+ [output],
54
+ [ts.factory.createIdentifier("g")],
55
+ ),
56
+ ),
57
+ );
58
+ };
59
+
60
+ export const simulate =
61
+ (project: INestiaProject) =>
62
+ (importer: ImportDictionary) =>
63
+ (
64
+ route: ITypedHttpRoute,
65
+ props: {
66
+ headers: ITypedHttpRouteParameter.IHeaders | undefined;
67
+ query: ITypedHttpRouteParameter.IQuery | undefined;
68
+ input: ITypedHttpRouteParameter.IBody | undefined;
69
+ },
70
+ ): ts.VariableStatement => {
71
+ const output: boolean =
72
+ project.config.propagate === true ||
73
+ route.success.metadata.size() !== 0;
74
+ const caller = () =>
75
+ ts.factory.createCallExpression(
76
+ ts.factory.createIdentifier("random"),
77
+ undefined,
78
+ [
79
+ ts.factory.createConditionalExpression(
80
+ ts.factory.createLogicalAnd(
81
+ ts.factory.createStrictEquality(
82
+ ts.factory.createStringLiteral("object"),
83
+ ts.factory.createTypeOfExpression(
84
+ ts.factory.createIdentifier("connection.simulate"),
85
+ ),
86
+ ),
87
+ ts.factory.createStrictInequality(
88
+ ts.factory.createNull(),
89
+ ts.factory.createIdentifier("connection.simulate"),
90
+ ),
91
+ ),
92
+ undefined,
93
+ ts.factory.createIdentifier("connection.simulate"),
94
+ undefined,
95
+ ts.factory.createIdentifier("undefined"),
96
+ ),
97
+ ],
98
+ );
99
+
100
+ return constant("simulate")(
101
+ ts.factory.createArrowFunction(
102
+ undefined,
103
+ undefined,
104
+ [
105
+ IdentifierFactory.parameter(
106
+ "connection",
107
+ ts.factory.createTypeReferenceNode(
108
+ SdkImportWizard.IConnection(importer),
109
+ route.parameters.some(
110
+ (p) => p.category === "headers" && p.field === null,
111
+ )
112
+ ? [
113
+ ts.factory.createTypeReferenceNode(
114
+ `${route.name}.Headers`,
115
+ ),
116
+ ]
117
+ : [],
118
+ ),
119
+ ),
120
+ ...route.parameters
121
+ .filter((p) => p.category !== "headers")
122
+ .map((p) =>
123
+ ts.factory.createParameterDeclaration(
124
+ [],
125
+ undefined,
126
+ p.name,
127
+ p.metadata.optional
128
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
129
+ : undefined,
130
+ project.config.primitive !== false &&
131
+ (p === props.query || p === props.input)
132
+ ? ts.factory.createTypeReferenceNode(
133
+ `${route.name}.${p === props.query ? "Query" : "Input"}`,
134
+ )
135
+ : project.config.clone === true
136
+ ? SdkAliasCollection.from(project)(importer)(p.metadata)
137
+ : SdkAliasCollection.name(p),
138
+ ),
139
+ ),
140
+ ],
141
+ ts.factory.createTypeReferenceNode(output ? "Output" : "void"),
142
+ undefined,
143
+ ts.factory.createBlock(
144
+ [
145
+ ...assert(project)(importer)(route),
146
+ ts.factory.createReturnStatement(
147
+ project.config.propagate
148
+ ? ts.factory.createAsExpression(
149
+ ts.factory.createObjectLiteralExpression(
150
+ [
151
+ ts.factory.createPropertyAssignment(
152
+ "success",
153
+ ts.factory.createTrue(),
154
+ ),
155
+ ts.factory.createPropertyAssignment(
156
+ "status",
157
+ ExpressionFactory.number(
158
+ route.success.status ??
159
+ (route.method === "POST" ? 201 : 200),
160
+ ),
161
+ ),
162
+ ts.factory.createPropertyAssignment(
163
+ "headers",
164
+ LiteralFactory.write({
165
+ "Content-Type": route.success.contentType,
166
+ }),
167
+ ),
168
+ ts.factory.createPropertyAssignment("data", caller()),
169
+ ],
170
+ true,
171
+ ),
172
+ ts.factory.createTypeReferenceNode("Output"),
173
+ )
174
+ : caller(),
175
+ ),
176
+ ],
177
+ true,
178
+ ),
179
+ ),
180
+ );
181
+ };
182
+
183
+ const assert =
184
+ (project: INestiaProject) =>
185
+ (importer: ImportDictionary) =>
186
+ (route: ITypedHttpRoute): ts.Statement[] => {
187
+ const parameters = route.parameters.filter(
188
+ (p) => p.category !== "headers",
189
+ );
190
+ if (parameters.length === 0) return [];
191
+
192
+ const typia = SdkImportWizard.typia(importer);
193
+ const validator = StatementFactory.constant({
194
+ name: "assert",
195
+ value: ts.factory.createCallExpression(
196
+ IdentifierFactory.access(
197
+ ts.factory.createIdentifier(
198
+ importer.external({
199
+ type: false,
200
+ library: `@nestia/fetcher/lib/NestiaSimulator`,
201
+ instance: "NestiaSimulator",
202
+ }),
203
+ ),
204
+ "assert",
205
+ ),
206
+ undefined,
207
+ [
208
+ ts.factory.createObjectLiteralExpression(
209
+ [
210
+ ts.factory.createPropertyAssignment(
211
+ "method",
212
+ ts.factory.createIdentifier("METADATA.method"),
213
+ ),
214
+ ts.factory.createPropertyAssignment(
215
+ "host",
216
+ ts.factory.createIdentifier("connection.host"),
217
+ ),
218
+ ts.factory.createPropertyAssignment(
219
+ "path",
220
+ ts.factory.createCallExpression(
221
+ ts.factory.createIdentifier("path"),
222
+ undefined,
223
+ route.parameters
224
+ .filter(
225
+ (p) => p.category === "param" || p.category === "query",
226
+ )
227
+ .map((p) => ts.factory.createIdentifier(p.name)),
228
+ ),
229
+ ),
230
+ ts.factory.createPropertyAssignment(
231
+ "contentType",
232
+ ts.factory.createIdentifier(
233
+ JSON.stringify(route.success.contentType),
234
+ ),
235
+ ),
236
+ ],
237
+ true,
238
+ ),
239
+ ],
240
+ ),
241
+ });
242
+ const individual = parameters
243
+ .map((p) =>
244
+ ts.factory.createCallExpression(
245
+ (() => {
246
+ const base = IdentifierFactory.access(
247
+ ts.factory.createIdentifier("assert"),
248
+ p.category,
249
+ );
250
+ if (p.category !== "param") return base;
251
+ return ts.factory.createCallExpression(base, undefined, [
252
+ ts.factory.createStringLiteral(p.name),
253
+ ]);
254
+ })(),
255
+ undefined,
256
+ [
257
+ ts.factory.createArrowFunction(
258
+ undefined,
259
+ undefined,
260
+ [],
261
+ undefined,
262
+ undefined,
263
+ ts.factory.createCallExpression(
264
+ IdentifierFactory.access(
265
+ ts.factory.createIdentifier(typia),
266
+ "assert",
267
+ ),
268
+ undefined,
269
+ [ts.factory.createIdentifier(p.name)],
270
+ ),
271
+ ),
272
+ ],
273
+ ),
274
+ )
275
+ .map(ts.factory.createExpressionStatement);
276
+
277
+ return [
278
+ validator,
279
+ ...(project.config.propagate !== true
280
+ ? individual
281
+ : [tryAndCatch(importer)(individual)]),
282
+ ];
283
+ };
284
+
285
+ const tryAndCatch =
286
+ (importer: ImportDictionary) => (individual: ts.Statement[]) =>
287
+ ts.factory.createTryStatement(
288
+ ts.factory.createBlock(individual, true),
289
+ ts.factory.createCatchClause(
290
+ "exp",
291
+ ts.factory.createBlock(
292
+ [
293
+ ts.factory.createIfStatement(
294
+ ts.factory.createLogicalNot(
295
+ ts.factory.createCallExpression(
296
+ IdentifierFactory.access(
297
+ ts.factory.createIdentifier(
298
+ SdkImportWizard.typia(importer),
299
+ ),
300
+ "is",
301
+ ),
302
+ [
303
+ ts.factory.createTypeReferenceNode(
304
+ SdkImportWizard.HttpError(importer),
305
+ ),
306
+ ],
307
+ [ts.factory.createIdentifier("exp")],
308
+ ),
309
+ ),
310
+ ts.factory.createThrowStatement(
311
+ ts.factory.createIdentifier("exp"),
312
+ ),
313
+ ),
314
+ ts.factory.createReturnStatement(
315
+ ts.factory.createAsExpression(
316
+ ts.factory.createObjectLiteralExpression(
317
+ [
318
+ ts.factory.createPropertyAssignment(
319
+ "success",
320
+ ts.factory.createFalse(),
321
+ ),
322
+ ts.factory.createPropertyAssignment(
323
+ "status",
324
+ ts.factory.createIdentifier("exp.status"),
325
+ ),
326
+ ts.factory.createPropertyAssignment(
327
+ "headers",
328
+ ts.factory.createIdentifier("exp.headers"),
329
+ ),
330
+ ts.factory.createPropertyAssignment(
331
+ "data",
332
+ ts.factory.createIdentifier("exp.toJSON().message"),
333
+ ),
334
+ ],
335
+ true,
336
+ ),
337
+ TypeFactory.keyword("any"),
338
+ ),
339
+ ),
340
+ ],
341
+ true,
342
+ ),
343
+ ),
344
+ undefined,
345
+ );
346
+ }
347
+
348
+ const constant = (name: string) => (expression: ts.Expression) =>
349
+ ts.factory.createVariableStatement(
350
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
351
+ ts.factory.createVariableDeclarationList(
352
+ [
353
+ ts.factory.createVariableDeclaration(
354
+ ts.factory.createIdentifier(name),
355
+ undefined,
356
+ undefined,
357
+ expression,
358
+ ),
359
+ ],
360
+ ts.NodeFlags.Const,
361
+ ),
362
+ );