@nestia/sdk 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.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.
- 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/NestiaSdkApplication.js +29 -7
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.js +21 -13
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +4 -1
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +18 -3
- package/lib/analyses/PathAnalyzer.js +32 -0
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +3 -2
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +53 -20
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +14 -0
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +79 -0
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +9 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.js +31 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -0
- package/lib/executable/internal/NestiaConfigLoader.js +5 -1
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.js +30 -14
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.d.ts +10 -0
- package/lib/executable/internal/NestiaSdkWatcher.js +322 -0
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -0
- package/lib/executable/sdk.js +12 -12
- package/lib/executable/sdk.js.map +1 -1
- package/lib/generates/CloneGenerator.js +4 -2
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.js +50 -1
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +18 -2
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +3 -1
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +1 -0
- package/lib/generates/internal/ImportDictionary.js +9 -4
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -0
- package/lib/generates/internal/SdkAliasCollection.js +11 -2
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -0
- package/lib/generates/internal/SdkDistributionComposer.js +3 -0
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +4 -1
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js +42 -9
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +3 -4
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +2 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +15 -0
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +148 -0
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +2 -1
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +6 -0
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +283 -0
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +11 -9
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -2
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +6 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +9 -0
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +174 -0
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -0
- package/lib/structures/INestiaSdkInput.d.ts +9 -2
- package/lib/structures/IReflectController.d.ts +2 -1
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -2
- package/lib/structures/IReflectMcpOperation.d.ts +35 -0
- package/lib/structures/IReflectMcpOperation.js +3 -0
- package/lib/structures/IReflectMcpOperation.js.map +1 -0
- package/lib/structures/IReflectMcpOperationParameter.d.ts +19 -0
- package/lib/structures/IReflectMcpOperationParameter.js +3 -0
- package/lib/structures/IReflectMcpOperationParameter.js.map +1 -0
- package/lib/structures/ITypedApplication.d.ts +2 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
- package/lib/structures/ITypedMcpRoute.d.ts +31 -0
- package/lib/structures/ITypedMcpRoute.js +3 -0
- package/lib/structures/ITypedMcpRoute.js.map +1 -0
- package/lib/utils/HttpResponseContentTypeUtil.d.ts +5 -0
- package/lib/utils/HttpResponseContentTypeUtil.js +22 -0
- package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -0
- package/native/go.mod +52 -52
- package/native/go.sum +84 -54
- package/native/sdk/register.go +322 -165
- package/native/sdk/sdk.go +17 -17
- package/native/sdk/sdk_metadata_json.go +327 -327
- package/native/sdk/sdk_transform.go +1879 -1549
- package/package.json +11 -9
- package/src/INestiaConfig.ts +267 -267
- package/src/NestiaSdkApplication.ts +39 -8
- package/src/NestiaSwaggerComposer.ts +153 -142
- package/src/analyses/AccessorAnalyzer.ts +64 -67
- package/src/analyses/ConfigAnalyzer.ts +330 -330
- package/src/analyses/ImportAnalyzer.ts +92 -92
- package/src/analyses/PathAnalyzer.ts +130 -69
- package/src/analyses/ReflectControllerAnalyzer.ts +112 -105
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -130
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -0
- package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
- package/src/analyses/SecurityAnalyzer.ts +25 -25
- package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -0
- package/src/decorators/OperationMetadata.ts +29 -29
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +451 -446
- package/src/executable/internal/NestiaSdkCommand.ts +124 -106
- package/src/executable/internal/NestiaSdkWatcher.ts +342 -0
- package/src/executable/sdk.ts +90 -88
- package/src/generates/CloneGenerator.ts +73 -66
- package/src/generates/E2eGenerator.ts +32 -32
- package/src/generates/SdkGenerator.ts +176 -118
- package/src/generates/SwaggerGenerator.ts +342 -310
- package/src/generates/internal/E2eFileProgrammer.ts +240 -233
- package/src/generates/internal/FilePrinter.ts +65 -65
- package/src/generates/internal/ImportDictionary.ts +209 -204
- package/src/generates/internal/SdkAliasCollection.ts +274 -261
- package/src/generates/internal/SdkDistributionComposer.ts +123 -116
- package/src/generates/internal/SdkFileProgrammer.ts +116 -112
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
- package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -77
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +520 -510
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +165 -165
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +331 -314
- package/src/generates/internal/SdkImportWizard.ts +62 -62
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +452 -0
- package/src/generates/internal/SdkRouteDirectory.ts +21 -18
- package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
- package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -0
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +389 -389
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +89 -89
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +331 -323
- package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
- package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -162
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -110
- package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +262 -0
- package/src/index.ts +4 -4
- package/src/internal/legacy.ts +492 -492
- package/src/module.ts +4 -4
- package/src/structures/INestiaProject.ts +10 -10
- package/src/structures/INestiaSdkInput.ts +27 -20
- package/src/structures/IOperationMetadata.ts +41 -41
- package/src/structures/IReflectController.ts +18 -15
- package/src/structures/IReflectHttpOperation.ts +26 -26
- package/src/structures/IReflectHttpOperationException.ts +18 -18
- package/src/structures/IReflectHttpOperationParameter.ts +79 -79
- package/src/structures/IReflectHttpOperationSuccess.ts +18 -21
- package/src/structures/IReflectImport.ts +6 -6
- package/src/structures/IReflectMcpOperation.ts +38 -0
- package/src/structures/IReflectMcpOperationParameter.ts +27 -0
- package/src/structures/IReflectOperationError.ts +26 -26
- package/src/structures/IReflectType.ts +4 -4
- package/src/structures/IReflectWebSocketOperation.ts +17 -17
- package/src/structures/ITypedApplication.ts +12 -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 +18 -22
- package/src/structures/ITypedMcpRoute.ts +33 -0
- package/src/structures/ITypedWebSocketRoute.ts +24 -24
- package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
- package/src/transform.ts +59 -59
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/HttpResponseContentTypeUtil.ts +30 -0
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +63 -63
- package/src/utils/StringUtil.ts +17 -17
- package/src/utils/TsConfigReader.ts +108 -108
- package/src/utils/TtscExecutor.ts +68 -68
- package/src/utils/VersioningStrategy.ts +28 -28
- package/src/validators/HttpHeadersValidator.ts +11 -11
- package/src/validators/HttpQueryValidator.ts +11 -11
- package/src/validators/TextPlainValidator.ts +17 -17
|
@@ -1,233 +1,240 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
1
|
+
import {
|
|
2
|
+
Node,
|
|
3
|
+
NodeFlags,
|
|
4
|
+
SyntaxKind,
|
|
5
|
+
TypeScriptFactory,
|
|
6
|
+
} from "@nestia/factory";
|
|
7
|
+
import { IdentifierFactory, LiteralFactory } from "@nestia/factory";
|
|
8
|
+
|
|
9
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
10
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
11
|
+
import { FilePrinter } from "./FilePrinter";
|
|
12
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
13
|
+
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
14
|
+
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
15
|
+
import { SdkImportWizard } from "./SdkImportWizard";
|
|
16
|
+
|
|
17
|
+
export namespace E2eFileProgrammer {
|
|
18
|
+
export const generate =
|
|
19
|
+
(project: INestiaProject) =>
|
|
20
|
+
(props: { api: string; current: string }) =>
|
|
21
|
+
async (route: ITypedHttpRoute): Promise<void> => {
|
|
22
|
+
const importer: ImportDictionary = new ImportDictionary(
|
|
23
|
+
`${props.current}/${getFunctionName(route)}.ts`,
|
|
24
|
+
);
|
|
25
|
+
if (project.config.clone !== true) importer.declarations(route.imports);
|
|
26
|
+
importer.internal({
|
|
27
|
+
file: props.api,
|
|
28
|
+
declaration: false,
|
|
29
|
+
type: "default",
|
|
30
|
+
name: "api",
|
|
31
|
+
});
|
|
32
|
+
const functor: Node = generateFunctor(project)(importer)(route);
|
|
33
|
+
await FilePrinter.write({
|
|
34
|
+
location: importer.file,
|
|
35
|
+
statements: [
|
|
36
|
+
...importer.toStatements(props.current),
|
|
37
|
+
FilePrinter.enter(),
|
|
38
|
+
functor,
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const generateFunctor =
|
|
44
|
+
(project: INestiaProject) =>
|
|
45
|
+
(importer: ImportDictionary) =>
|
|
46
|
+
(route: ITypedHttpRoute): Node =>
|
|
47
|
+
TypeScriptFactory.createVariableStatement(
|
|
48
|
+
[TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
|
|
49
|
+
TypeScriptFactory.createVariableDeclarationList(
|
|
50
|
+
[
|
|
51
|
+
TypeScriptFactory.createVariableDeclaration(
|
|
52
|
+
TypeScriptFactory.createIdentifier(getFunctionName(route)),
|
|
53
|
+
undefined,
|
|
54
|
+
undefined,
|
|
55
|
+
generateArrow(project)(importer)(route),
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
NodeFlags.Const,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const generateArrow =
|
|
63
|
+
(project: INestiaProject) =>
|
|
64
|
+
(importer: ImportDictionary) =>
|
|
65
|
+
(route: ITypedHttpRoute) => {
|
|
66
|
+
const random = IdentifierFactory.access(
|
|
67
|
+
TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
|
|
68
|
+
"random",
|
|
69
|
+
);
|
|
70
|
+
const connection = route.headerObject
|
|
71
|
+
? TypeScriptFactory.createObjectLiteralExpression(
|
|
72
|
+
[
|
|
73
|
+
TypeScriptFactory.createSpreadAssignment(
|
|
74
|
+
TypeScriptFactory.createIdentifier("connection"),
|
|
75
|
+
),
|
|
76
|
+
TypeScriptFactory.createPropertyAssignment(
|
|
77
|
+
"headers",
|
|
78
|
+
TypeScriptFactory.createObjectLiteralExpression(
|
|
79
|
+
[
|
|
80
|
+
TypeScriptFactory.createSpreadAssignment(
|
|
81
|
+
IdentifierFactory.access(
|
|
82
|
+
TypeScriptFactory.createIdentifier("connection"),
|
|
83
|
+
"headers",
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
TypeScriptFactory.createSpreadAssignment(
|
|
87
|
+
TypeScriptFactory.createCallExpression(
|
|
88
|
+
random,
|
|
89
|
+
[
|
|
90
|
+
project.config.clone === true
|
|
91
|
+
? SdkAliasCollection.from(project)(importer)(
|
|
92
|
+
route.headerObject.metadata,
|
|
93
|
+
)
|
|
94
|
+
: SdkAliasCollection.name(route.headerObject),
|
|
95
|
+
],
|
|
96
|
+
undefined,
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
],
|
|
100
|
+
true,
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
],
|
|
104
|
+
true,
|
|
105
|
+
)
|
|
106
|
+
: TypeScriptFactory.createIdentifier("connection");
|
|
107
|
+
const entries = SdkHttpParameterProgrammer.getEntries({
|
|
108
|
+
project,
|
|
109
|
+
importer,
|
|
110
|
+
route,
|
|
111
|
+
body: true,
|
|
112
|
+
e2e: true,
|
|
113
|
+
prefix: ["api", "functional", ...route.accessor].join(".") + ".",
|
|
114
|
+
});
|
|
115
|
+
const fetch = TypeScriptFactory.createCallExpression(
|
|
116
|
+
TypeScriptFactory.createIdentifier(
|
|
117
|
+
["api", "functional", ...route.accessor].join("."),
|
|
118
|
+
),
|
|
119
|
+
undefined,
|
|
120
|
+
[
|
|
121
|
+
connection,
|
|
122
|
+
...(project.config.keyword === true && entries.length !== 0
|
|
123
|
+
? [
|
|
124
|
+
LiteralFactory.write(
|
|
125
|
+
Object.fromEntries(
|
|
126
|
+
entries.map((e) => [
|
|
127
|
+
e.key,
|
|
128
|
+
TypeScriptFactory.createCallExpression(
|
|
129
|
+
IdentifierFactory.access(
|
|
130
|
+
TypeScriptFactory.createIdentifier(
|
|
131
|
+
SdkImportWizard.typia(importer),
|
|
132
|
+
),
|
|
133
|
+
"random",
|
|
134
|
+
),
|
|
135
|
+
[getRandomType(importer)(e)],
|
|
136
|
+
undefined,
|
|
137
|
+
),
|
|
138
|
+
]),
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
]
|
|
142
|
+
: entries.map((e) =>
|
|
143
|
+
TypeScriptFactory.createCallExpression(
|
|
144
|
+
IdentifierFactory.access(
|
|
145
|
+
TypeScriptFactory.createIdentifier(
|
|
146
|
+
SdkImportWizard.typia(importer),
|
|
147
|
+
),
|
|
148
|
+
"random",
|
|
149
|
+
),
|
|
150
|
+
[getRandomType(importer)(e)],
|
|
151
|
+
undefined,
|
|
152
|
+
),
|
|
153
|
+
)),
|
|
154
|
+
],
|
|
155
|
+
);
|
|
156
|
+
const assert = TypeScriptFactory.createCallExpression(
|
|
157
|
+
IdentifierFactory.access(
|
|
158
|
+
TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
|
|
159
|
+
"assert",
|
|
160
|
+
),
|
|
161
|
+
undefined,
|
|
162
|
+
[TypeScriptFactory.createIdentifier("output")],
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return TypeScriptFactory.createArrowFunction(
|
|
166
|
+
[TypeScriptFactory.createModifier(SyntaxKind.AsyncKeyword)],
|
|
167
|
+
undefined,
|
|
168
|
+
[
|
|
169
|
+
IdentifierFactory.parameter(
|
|
170
|
+
"connection",
|
|
171
|
+
TypeScriptFactory.createTypeReferenceNode("api.IConnection"),
|
|
172
|
+
),
|
|
173
|
+
],
|
|
174
|
+
undefined,
|
|
175
|
+
undefined,
|
|
176
|
+
TypeScriptFactory.createBlock([
|
|
177
|
+
TypeScriptFactory.createVariableStatement(
|
|
178
|
+
[],
|
|
179
|
+
TypeScriptFactory.createVariableDeclarationList(
|
|
180
|
+
[
|
|
181
|
+
TypeScriptFactory.createVariableDeclaration(
|
|
182
|
+
"output",
|
|
183
|
+
undefined,
|
|
184
|
+
project.config.propagate !== true &&
|
|
185
|
+
route.success.type!.name === "void"
|
|
186
|
+
? undefined
|
|
187
|
+
: SdkAliasCollection.response(project)(importer)(route),
|
|
188
|
+
TypeScriptFactory.createAwaitExpression(fetch),
|
|
189
|
+
),
|
|
190
|
+
],
|
|
191
|
+
NodeFlags.Const,
|
|
192
|
+
),
|
|
193
|
+
),
|
|
194
|
+
...(route.success.binary === true
|
|
195
|
+
? []
|
|
196
|
+
: [TypeScriptFactory.createExpressionStatement(assert)]),
|
|
197
|
+
]),
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const getRandomType =
|
|
203
|
+
(importer: ImportDictionary) =>
|
|
204
|
+
(entry: SdkHttpParameterProgrammer.IEntry): Node => {
|
|
205
|
+
if (isPlainStringPathParameter(entry) === false) return entry.type;
|
|
206
|
+
return TypeScriptFactory.createIntersectionTypeNode([
|
|
207
|
+
entry.type,
|
|
208
|
+
TypeScriptFactory.createTypeReferenceNode(
|
|
209
|
+
TypeScriptFactory.createQualifiedName(
|
|
210
|
+
TypeScriptFactory.createIdentifier(
|
|
211
|
+
importer.external({
|
|
212
|
+
declaration: true,
|
|
213
|
+
file: "typia",
|
|
214
|
+
type: "element",
|
|
215
|
+
name: "tags",
|
|
216
|
+
}),
|
|
217
|
+
),
|
|
218
|
+
TypeScriptFactory.createIdentifier("MinLength"),
|
|
219
|
+
),
|
|
220
|
+
[
|
|
221
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
222
|
+
LiteralFactory.write(1) as Node,
|
|
223
|
+
),
|
|
224
|
+
],
|
|
225
|
+
),
|
|
226
|
+
]);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const isPlainStringPathParameter = (
|
|
230
|
+
entry: SdkHttpParameterProgrammer.IEntry,
|
|
231
|
+
): boolean =>
|
|
232
|
+
entry.parameter.category === "param" &&
|
|
233
|
+
entry.parameter.metadata.atomics.length === 1 &&
|
|
234
|
+
entry.parameter.metadata.atomics[0]!.type === "string" &&
|
|
235
|
+
entry.parameter.metadata.atomics[0]!.tags.every((row) =>
|
|
236
|
+
row.every((tag) => tag.kind !== "minLength"),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const getFunctionName = (route: ITypedHttpRoute): string =>
|
|
240
|
+
["test", "api", ...route.accessor].join("_");
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Node,
|
|
3
|
-
SyntaxKind,
|
|
4
|
-
TypeScriptFactory,
|
|
5
|
-
TypeScriptPrinter,
|
|
6
|
-
} from "@nestia/factory";
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import { format } from "prettier";
|
|
9
|
-
|
|
10
|
-
export namespace FilePrinter {
|
|
11
|
-
export const description = <T extends Node>(
|
|
12
|
-
node: T,
|
|
13
|
-
comment: string,
|
|
14
|
-
): T => {
|
|
15
|
-
if (comment.length === 0) return node;
|
|
16
|
-
node.emitNode ??= {};
|
|
17
|
-
node.emitNode.leadingComments = [
|
|
18
|
-
...(node.emitNode.leadingComments ?? []),
|
|
19
|
-
{
|
|
20
|
-
kind: SyntaxKind.MultiLineCommentTrivia,
|
|
21
|
-
text: [
|
|
22
|
-
"*",
|
|
23
|
-
...comment
|
|
24
|
-
.split("\r\n")
|
|
25
|
-
.join("\n")
|
|
26
|
-
.split("\n")
|
|
27
|
-
.map(
|
|
28
|
-
(str) =>
|
|
29
|
-
` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
|
|
30
|
-
),
|
|
31
|
-
"",
|
|
32
|
-
].join("\n"),
|
|
33
|
-
hasTrailingNewLine: true,
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
return node;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const enter = () =>
|
|
40
|
-
TypeScriptFactory.createExpressionStatement(
|
|
41
|
-
TypeScriptFactory.createIdentifier("\n"),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
export const write = async (props: {
|
|
45
|
-
location: string;
|
|
46
|
-
statements: Node[];
|
|
47
|
-
top?: string;
|
|
48
|
-
}): Promise<void> => {
|
|
49
|
-
const script: string = TypeScriptPrinter.write({
|
|
50
|
-
statements: props.statements,
|
|
51
|
-
top: props.top,
|
|
52
|
-
});
|
|
53
|
-
await fs.promises.writeFile(props.location, await beautify(script), "utf8");
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const beautify = async (script: string): Promise<string> => {
|
|
57
|
-
try {
|
|
58
|
-
return await format(script, {
|
|
59
|
-
parser: "typescript",
|
|
60
|
-
});
|
|
61
|
-
} catch {
|
|
62
|
-
return script;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Node,
|
|
3
|
+
SyntaxKind,
|
|
4
|
+
TypeScriptFactory,
|
|
5
|
+
TypeScriptPrinter,
|
|
6
|
+
} from "@nestia/factory";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import { format } from "prettier";
|
|
9
|
+
|
|
10
|
+
export namespace FilePrinter {
|
|
11
|
+
export const description = <T extends Node>(
|
|
12
|
+
node: T,
|
|
13
|
+
comment: string,
|
|
14
|
+
): T => {
|
|
15
|
+
if (comment.length === 0) return node;
|
|
16
|
+
node.emitNode ??= {};
|
|
17
|
+
node.emitNode.leadingComments = [
|
|
18
|
+
...(node.emitNode.leadingComments ?? []),
|
|
19
|
+
{
|
|
20
|
+
kind: SyntaxKind.MultiLineCommentTrivia,
|
|
21
|
+
text: [
|
|
22
|
+
"*",
|
|
23
|
+
...comment
|
|
24
|
+
.split("\r\n")
|
|
25
|
+
.join("\n")
|
|
26
|
+
.split("\n")
|
|
27
|
+
.map(
|
|
28
|
+
(str) =>
|
|
29
|
+
` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
|
|
30
|
+
),
|
|
31
|
+
"",
|
|
32
|
+
].join("\n"),
|
|
33
|
+
hasTrailingNewLine: true,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
return node;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const enter = () =>
|
|
40
|
+
TypeScriptFactory.createExpressionStatement(
|
|
41
|
+
TypeScriptFactory.createIdentifier("\n"),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const write = async (props: {
|
|
45
|
+
location: string;
|
|
46
|
+
statements: Node[];
|
|
47
|
+
top?: string;
|
|
48
|
+
}): Promise<void> => {
|
|
49
|
+
const script: string = TypeScriptPrinter.write({
|
|
50
|
+
statements: props.statements,
|
|
51
|
+
top: props.top,
|
|
52
|
+
});
|
|
53
|
+
await fs.promises.writeFile(props.location, await beautify(script), "utf8");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const beautify = async (script: string): Promise<string> => {
|
|
57
|
+
try {
|
|
58
|
+
return await format(script, {
|
|
59
|
+
parser: "typescript",
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
return script;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|