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