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