@nestia/sdk 7.0.0-dev.20250607 → 7.0.0
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 +92 -92
- 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/executable/internal/NestiaConfigLoader.js +4 -4
- package/lib/executable/sdk.js +12 -12
- package/package.json +5 -5
- package/src/INestiaConfig.ts +269 -269
- package/src/NestiaSdkApplication.ts +307 -307
- package/src/NestiaSwaggerComposer.ts +138 -138
- package/src/analyses/AccessorAnalyzer.ts +67 -67
- package/src/analyses/ConfigAnalyzer.ts +155 -155
- package/src/analyses/ExceptionAnalyzer.ts +154 -154
- package/src/analyses/GenericAnalyzer.ts +49 -49
- package/src/analyses/ImportAnalyzer.ts +171 -171
- 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 +71 -71
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -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 +204 -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 +78 -78
- package/src/executable/internal/NestiaSdkCommand.ts +103 -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 +284 -284
- package/src/generates/internal/E2eFileProgrammer.ts +205 -205
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +163 -163
- package/src/generates/internal/SdkAliasCollection.ts +255 -255
- package/src/generates/internal/SdkDistributionComposer.ts +103 -103
- package/src/generates/internal/SdkFileProgrammer.ts +116 -116
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
- package/src/generates/internal/SdkHttpCloneReferencer.ts +75 -75
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +276 -276
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +500 -500
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +178 -178
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +107 -107
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +340 -340
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkRouteDirectory.ts +18 -18
- package/src/generates/internal/SdkTypeProgrammer.ts +384 -384
- package/src/generates/internal/SdkTypeTagProgrammer.ts +102 -102
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +366 -366
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +87 -87
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +279 -279
- package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
- package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
- package/src/index.ts +4 -4
- package/src/module.ts +3 -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 +19 -19
- package/src/structures/IReflectHttpOperationParameter.ts +81 -81
- package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
- package/src/structures/IReflectOperationError.ts +26 -26
- package/src/structures/IReflectType.ts +4 -4
- package/src/structures/IReflectTypeImport.ts +4 -4
- package/src/structures/IReflectWebSocketOperation.ts +17 -17
- package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
- 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 +44 -44
- package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
- package/src/transformers/SdkOperationProgrammer.ts +209 -209
- package/src/transformers/SdkOperationTransformer.ts +253 -253
- 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 +66 -66
- 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 +34 -34
- package/src/validators/HttpQueryValidator.ts +34 -34
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { IJsDocTagInfo } from "typia";
|
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { INestiaProject } from "../../structures/INestiaProject";
|
|
6
|
-
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
7
|
-
import { FilePrinter } from "./FilePrinter";
|
|
8
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
9
|
-
import { SdkImportWizard } from "./SdkImportWizard";
|
|
10
|
-
import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
|
|
11
|
-
import { SdkWebSocketParameterProgrammer } from "./SdkWebSocketParameterProgrammer";
|
|
12
|
-
|
|
13
|
-
export namespace SdkWebSocketRouteProgrammer {
|
|
14
|
-
export const write =
|
|
15
|
-
(project: INestiaProject) =>
|
|
16
|
-
(importer: ImportDictionary) =>
|
|
17
|
-
(route: ITypedWebSocketRoute): ts.Statement[] => [
|
|
18
|
-
FilePrinter.description(
|
|
19
|
-
writeFunction(project)(importer)(route),
|
|
20
|
-
writeDescription(route),
|
|
21
|
-
),
|
|
22
|
-
SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
const writeDescription = (route: ITypedWebSocketRoute): string => {
|
|
26
|
-
// MAIN DESCRIPTION
|
|
27
|
-
const comments: string[] = route.description
|
|
28
|
-
? route.description.split("\n")
|
|
29
|
-
: [];
|
|
30
|
-
|
|
31
|
-
// COMMENT TAGS
|
|
32
|
-
const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
|
|
33
|
-
(tag) =>
|
|
34
|
-
tag.name !== "param" ||
|
|
35
|
-
[...route.pathParameters, ...(route.query ? [route.query] : [])]
|
|
36
|
-
.filter((p) => p.category === "param" || p.category === "query")
|
|
37
|
-
.some((p) => p.name === tag.text?.[0]?.text),
|
|
38
|
-
);
|
|
39
|
-
if (tags.length !== 0) {
|
|
40
|
-
const content: string[] = tags.map((t) =>
|
|
41
|
-
t.text?.length
|
|
42
|
-
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
43
|
-
: `@${t.name}`,
|
|
44
|
-
);
|
|
45
|
-
comments.push("", ...new Set(content));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// POSTFIX
|
|
49
|
-
if (!!comments.length) comments.push("");
|
|
50
|
-
comments.push(
|
|
51
|
-
`@controller ${route.controller.class.name}.${route.name}`,
|
|
52
|
-
`@path ${route.path}`,
|
|
53
|
-
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
|
|
54
|
-
);
|
|
55
|
-
return comments.join("\n");
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const writeFunction =
|
|
59
|
-
(project: INestiaProject) =>
|
|
60
|
-
(importer: ImportDictionary) =>
|
|
61
|
-
(route: ITypedWebSocketRoute): ts.FunctionDeclaration => {
|
|
62
|
-
return ts.factory.createFunctionDeclaration(
|
|
63
|
-
[
|
|
64
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
65
|
-
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
66
|
-
],
|
|
67
|
-
undefined,
|
|
68
|
-
route.name,
|
|
69
|
-
undefined,
|
|
70
|
-
[
|
|
71
|
-
IdentifierFactory.parameter(
|
|
72
|
-
"connection",
|
|
73
|
-
ts.factory.createTypeReferenceNode(
|
|
74
|
-
SdkImportWizard.IConnection(importer),
|
|
75
|
-
[ts.factory.createTypeReferenceNode(`${route.name}.Header`)],
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
...SdkWebSocketParameterProgrammer.getParameterDeclarations({
|
|
79
|
-
project,
|
|
80
|
-
route,
|
|
81
|
-
provider: true,
|
|
82
|
-
prefix: true,
|
|
83
|
-
}),
|
|
84
|
-
],
|
|
85
|
-
ts.factory.createTypeReferenceNode("Promise", [
|
|
86
|
-
ts.factory.createTypeReferenceNode(`${route.name}.Output`),
|
|
87
|
-
]),
|
|
88
|
-
ts.factory.createBlock(
|
|
89
|
-
writeFunctionBody(project)(importer)(route),
|
|
90
|
-
true,
|
|
91
|
-
),
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const writeFunctionBody =
|
|
96
|
-
(project: INestiaProject) =>
|
|
97
|
-
(importer: ImportDictionary) =>
|
|
98
|
-
(route: ITypedWebSocketRoute): ts.Statement[] => {
|
|
99
|
-
const access = (key: string) =>
|
|
100
|
-
project.config.keyword === true
|
|
101
|
-
? ts.factory.createPropertyAccessExpression(
|
|
102
|
-
ts.factory.createIdentifier("props"),
|
|
103
|
-
key,
|
|
104
|
-
)
|
|
105
|
-
: ts.factory.createIdentifier(key);
|
|
106
|
-
return [
|
|
107
|
-
local("connector")(
|
|
108
|
-
ts.factory.createTypeReferenceNode(
|
|
109
|
-
importer.external({
|
|
110
|
-
type: false,
|
|
111
|
-
library: "tgrid",
|
|
112
|
-
instance: "WebSocketConnector",
|
|
113
|
-
}),
|
|
114
|
-
[
|
|
115
|
-
ts.factory.createTypeReferenceNode(`${route.name}.Header`),
|
|
116
|
-
ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
|
|
117
|
-
ts.factory.createTypeReferenceNode(`${route.name}.Listener`),
|
|
118
|
-
],
|
|
119
|
-
),
|
|
120
|
-
)(
|
|
121
|
-
ts.factory.createNewExpression(
|
|
122
|
-
ts.factory.createIdentifier(
|
|
123
|
-
importer.external({
|
|
124
|
-
type: false,
|
|
125
|
-
library: "tgrid",
|
|
126
|
-
instance: "WebSocketConnector",
|
|
127
|
-
}),
|
|
128
|
-
),
|
|
129
|
-
undefined,
|
|
130
|
-
[
|
|
131
|
-
ts.factory.createAsExpression(
|
|
132
|
-
ts.factory.createBinaryExpression(
|
|
133
|
-
ts.factory.createPropertyAccessExpression(
|
|
134
|
-
ts.factory.createIdentifier("connection"),
|
|
135
|
-
"headers",
|
|
136
|
-
),
|
|
137
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
138
|
-
ts.factory.createObjectLiteralExpression([], false),
|
|
139
|
-
),
|
|
140
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
|
|
141
|
-
),
|
|
142
|
-
access("provider"),
|
|
143
|
-
],
|
|
144
|
-
),
|
|
145
|
-
),
|
|
146
|
-
ts.factory.createExpressionStatement(
|
|
147
|
-
ts.factory.createAwaitExpression(
|
|
148
|
-
ts.factory.createCallExpression(
|
|
149
|
-
ts.factory.createPropertyAccessExpression(
|
|
150
|
-
ts.factory.createIdentifier("connector"),
|
|
151
|
-
"connect",
|
|
152
|
-
),
|
|
153
|
-
undefined,
|
|
154
|
-
[
|
|
155
|
-
joinPath(
|
|
156
|
-
ts.factory.createCallExpression(
|
|
157
|
-
ts.factory.createPropertyAccessExpression(
|
|
158
|
-
ts.factory.createIdentifier(route.name),
|
|
159
|
-
"path",
|
|
160
|
-
),
|
|
161
|
-
[],
|
|
162
|
-
project.config.keyword === true &&
|
|
163
|
-
SdkWebSocketParameterProgrammer.isPathEmpty(route) ===
|
|
164
|
-
false
|
|
165
|
-
? [ts.factory.createIdentifier("props")]
|
|
166
|
-
: SdkWebSocketParameterProgrammer.getEntries({
|
|
167
|
-
project,
|
|
168
|
-
route,
|
|
169
|
-
provider: false,
|
|
170
|
-
prefix: true,
|
|
171
|
-
}).map((p) => ts.factory.createIdentifier(p.key)),
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
],
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
),
|
|
178
|
-
local("driver")(
|
|
179
|
-
ts.factory.createTypeReferenceNode(
|
|
180
|
-
importer.external({
|
|
181
|
-
type: true,
|
|
182
|
-
library: "tgrid",
|
|
183
|
-
instance: "Driver",
|
|
184
|
-
}),
|
|
185
|
-
[ts.factory.createTypeReferenceNode(`${route.name}.Listener`)],
|
|
186
|
-
),
|
|
187
|
-
)(
|
|
188
|
-
ts.factory.createCallExpression(
|
|
189
|
-
ts.factory.createPropertyAccessExpression(
|
|
190
|
-
ts.factory.createIdentifier("connector"),
|
|
191
|
-
"getDriver",
|
|
192
|
-
),
|
|
193
|
-
undefined,
|
|
194
|
-
undefined,
|
|
195
|
-
),
|
|
196
|
-
),
|
|
197
|
-
ts.factory.createReturnStatement(
|
|
198
|
-
ts.factory.createObjectLiteralExpression(
|
|
199
|
-
[
|
|
200
|
-
ts.factory.createShorthandPropertyAssignment("connector"),
|
|
201
|
-
ts.factory.createShorthandPropertyAssignment("driver"),
|
|
202
|
-
],
|
|
203
|
-
true,
|
|
204
|
-
),
|
|
205
|
-
),
|
|
206
|
-
];
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const local =
|
|
211
|
-
(name: string) => (type: ts.TypeNode) => (expression: ts.Expression) =>
|
|
212
|
-
ts.factory.createVariableStatement(
|
|
213
|
-
[],
|
|
214
|
-
ts.factory.createVariableDeclarationList(
|
|
215
|
-
[
|
|
216
|
-
ts.factory.createVariableDeclaration(
|
|
217
|
-
name,
|
|
218
|
-
undefined,
|
|
219
|
-
type,
|
|
220
|
-
expression,
|
|
221
|
-
),
|
|
222
|
-
],
|
|
223
|
-
ts.NodeFlags.Const,
|
|
224
|
-
),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
const joinPath = (caller: ts.Expression) =>
|
|
228
|
-
ts.factory.createTemplateExpression(ts.factory.createTemplateHead("", ""), [
|
|
229
|
-
ts.factory.createTemplateSpan(
|
|
230
|
-
ts.factory.createConditionalExpression(
|
|
231
|
-
ts.factory.createCallExpression(
|
|
232
|
-
ts.factory.createPropertyAccessExpression(
|
|
233
|
-
ts.factory.createPropertyAccessExpression(
|
|
234
|
-
ts.factory.createIdentifier("connection"),
|
|
235
|
-
ts.factory.createIdentifier("host"),
|
|
236
|
-
),
|
|
237
|
-
ts.factory.createIdentifier("endsWith"),
|
|
238
|
-
),
|
|
239
|
-
undefined,
|
|
240
|
-
[ts.factory.createStringLiteral("/")],
|
|
241
|
-
),
|
|
242
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
243
|
-
ts.factory.createCallExpression(
|
|
244
|
-
ts.factory.createPropertyAccessExpression(
|
|
245
|
-
ts.factory.createPropertyAccessExpression(
|
|
246
|
-
ts.factory.createIdentifier("connection"),
|
|
247
|
-
ts.factory.createIdentifier("host"),
|
|
248
|
-
),
|
|
249
|
-
ts.factory.createIdentifier("substring"),
|
|
250
|
-
),
|
|
251
|
-
undefined,
|
|
252
|
-
[
|
|
253
|
-
ts.factory.createNumericLiteral("0"),
|
|
254
|
-
ts.factory.createBinaryExpression(
|
|
255
|
-
ts.factory.createPropertyAccessExpression(
|
|
256
|
-
ts.factory.createPropertyAccessExpression(
|
|
257
|
-
ts.factory.createIdentifier("connection"),
|
|
258
|
-
ts.factory.createIdentifier("host"),
|
|
259
|
-
),
|
|
260
|
-
ts.factory.createIdentifier("length"),
|
|
261
|
-
),
|
|
262
|
-
ts.factory.createToken(ts.SyntaxKind.MinusToken),
|
|
263
|
-
ts.factory.createNumericLiteral("1"),
|
|
264
|
-
),
|
|
265
|
-
],
|
|
266
|
-
),
|
|
267
|
-
ts.factory.createToken(ts.SyntaxKind.ColonToken),
|
|
268
|
-
ts.factory.createPropertyAccessExpression(
|
|
269
|
-
ts.factory.createIdentifier("connection"),
|
|
270
|
-
ts.factory.createIdentifier("host"),
|
|
271
|
-
),
|
|
272
|
-
),
|
|
273
|
-
ts.factory.createTemplateMiddle("", ""),
|
|
274
|
-
),
|
|
275
|
-
ts.factory.createTemplateSpan(
|
|
276
|
-
caller,
|
|
277
|
-
ts.factory.createTemplateTail("", ""),
|
|
278
|
-
),
|
|
279
|
-
]);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IJsDocTagInfo } from "typia";
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
6
|
+
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
7
|
+
import { FilePrinter } from "./FilePrinter";
|
|
8
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
9
|
+
import { SdkImportWizard } from "./SdkImportWizard";
|
|
10
|
+
import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
|
|
11
|
+
import { SdkWebSocketParameterProgrammer } from "./SdkWebSocketParameterProgrammer";
|
|
12
|
+
|
|
13
|
+
export namespace SdkWebSocketRouteProgrammer {
|
|
14
|
+
export const write =
|
|
15
|
+
(project: INestiaProject) =>
|
|
16
|
+
(importer: ImportDictionary) =>
|
|
17
|
+
(route: ITypedWebSocketRoute): ts.Statement[] => [
|
|
18
|
+
FilePrinter.description(
|
|
19
|
+
writeFunction(project)(importer)(route),
|
|
20
|
+
writeDescription(route),
|
|
21
|
+
),
|
|
22
|
+
SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const writeDescription = (route: ITypedWebSocketRoute): string => {
|
|
26
|
+
// MAIN DESCRIPTION
|
|
27
|
+
const comments: string[] = route.description
|
|
28
|
+
? route.description.split("\n")
|
|
29
|
+
: [];
|
|
30
|
+
|
|
31
|
+
// COMMENT TAGS
|
|
32
|
+
const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
|
|
33
|
+
(tag) =>
|
|
34
|
+
tag.name !== "param" ||
|
|
35
|
+
[...route.pathParameters, ...(route.query ? [route.query] : [])]
|
|
36
|
+
.filter((p) => p.category === "param" || p.category === "query")
|
|
37
|
+
.some((p) => p.name === tag.text?.[0]?.text),
|
|
38
|
+
);
|
|
39
|
+
if (tags.length !== 0) {
|
|
40
|
+
const content: string[] = tags.map((t) =>
|
|
41
|
+
t.text?.length
|
|
42
|
+
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
43
|
+
: `@${t.name}`,
|
|
44
|
+
);
|
|
45
|
+
comments.push("", ...new Set(content));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// POSTFIX
|
|
49
|
+
if (!!comments.length) comments.push("");
|
|
50
|
+
comments.push(
|
|
51
|
+
`@controller ${route.controller.class.name}.${route.name}`,
|
|
52
|
+
`@path ${route.path}`,
|
|
53
|
+
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
|
|
54
|
+
);
|
|
55
|
+
return comments.join("\n");
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const writeFunction =
|
|
59
|
+
(project: INestiaProject) =>
|
|
60
|
+
(importer: ImportDictionary) =>
|
|
61
|
+
(route: ITypedWebSocketRoute): ts.FunctionDeclaration => {
|
|
62
|
+
return ts.factory.createFunctionDeclaration(
|
|
63
|
+
[
|
|
64
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
65
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
66
|
+
],
|
|
67
|
+
undefined,
|
|
68
|
+
route.name,
|
|
69
|
+
undefined,
|
|
70
|
+
[
|
|
71
|
+
IdentifierFactory.parameter(
|
|
72
|
+
"connection",
|
|
73
|
+
ts.factory.createTypeReferenceNode(
|
|
74
|
+
SdkImportWizard.IConnection(importer),
|
|
75
|
+
[ts.factory.createTypeReferenceNode(`${route.name}.Header`)],
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
...SdkWebSocketParameterProgrammer.getParameterDeclarations({
|
|
79
|
+
project,
|
|
80
|
+
route,
|
|
81
|
+
provider: true,
|
|
82
|
+
prefix: true,
|
|
83
|
+
}),
|
|
84
|
+
],
|
|
85
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
|
86
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Output`),
|
|
87
|
+
]),
|
|
88
|
+
ts.factory.createBlock(
|
|
89
|
+
writeFunctionBody(project)(importer)(route),
|
|
90
|
+
true,
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const writeFunctionBody =
|
|
96
|
+
(project: INestiaProject) =>
|
|
97
|
+
(importer: ImportDictionary) =>
|
|
98
|
+
(route: ITypedWebSocketRoute): ts.Statement[] => {
|
|
99
|
+
const access = (key: string) =>
|
|
100
|
+
project.config.keyword === true
|
|
101
|
+
? ts.factory.createPropertyAccessExpression(
|
|
102
|
+
ts.factory.createIdentifier("props"),
|
|
103
|
+
key,
|
|
104
|
+
)
|
|
105
|
+
: ts.factory.createIdentifier(key);
|
|
106
|
+
return [
|
|
107
|
+
local("connector")(
|
|
108
|
+
ts.factory.createTypeReferenceNode(
|
|
109
|
+
importer.external({
|
|
110
|
+
type: false,
|
|
111
|
+
library: "tgrid",
|
|
112
|
+
instance: "WebSocketConnector",
|
|
113
|
+
}),
|
|
114
|
+
[
|
|
115
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Header`),
|
|
116
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
|
|
117
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Listener`),
|
|
118
|
+
],
|
|
119
|
+
),
|
|
120
|
+
)(
|
|
121
|
+
ts.factory.createNewExpression(
|
|
122
|
+
ts.factory.createIdentifier(
|
|
123
|
+
importer.external({
|
|
124
|
+
type: false,
|
|
125
|
+
library: "tgrid",
|
|
126
|
+
instance: "WebSocketConnector",
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
undefined,
|
|
130
|
+
[
|
|
131
|
+
ts.factory.createAsExpression(
|
|
132
|
+
ts.factory.createBinaryExpression(
|
|
133
|
+
ts.factory.createPropertyAccessExpression(
|
|
134
|
+
ts.factory.createIdentifier("connection"),
|
|
135
|
+
"headers",
|
|
136
|
+
),
|
|
137
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
138
|
+
ts.factory.createObjectLiteralExpression([], false),
|
|
139
|
+
),
|
|
140
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
|
|
141
|
+
),
|
|
142
|
+
access("provider"),
|
|
143
|
+
],
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
ts.factory.createExpressionStatement(
|
|
147
|
+
ts.factory.createAwaitExpression(
|
|
148
|
+
ts.factory.createCallExpression(
|
|
149
|
+
ts.factory.createPropertyAccessExpression(
|
|
150
|
+
ts.factory.createIdentifier("connector"),
|
|
151
|
+
"connect",
|
|
152
|
+
),
|
|
153
|
+
undefined,
|
|
154
|
+
[
|
|
155
|
+
joinPath(
|
|
156
|
+
ts.factory.createCallExpression(
|
|
157
|
+
ts.factory.createPropertyAccessExpression(
|
|
158
|
+
ts.factory.createIdentifier(route.name),
|
|
159
|
+
"path",
|
|
160
|
+
),
|
|
161
|
+
[],
|
|
162
|
+
project.config.keyword === true &&
|
|
163
|
+
SdkWebSocketParameterProgrammer.isPathEmpty(route) ===
|
|
164
|
+
false
|
|
165
|
+
? [ts.factory.createIdentifier("props")]
|
|
166
|
+
: SdkWebSocketParameterProgrammer.getEntries({
|
|
167
|
+
project,
|
|
168
|
+
route,
|
|
169
|
+
provider: false,
|
|
170
|
+
prefix: true,
|
|
171
|
+
}).map((p) => ts.factory.createIdentifier(p.key)),
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
],
|
|
175
|
+
),
|
|
176
|
+
),
|
|
177
|
+
),
|
|
178
|
+
local("driver")(
|
|
179
|
+
ts.factory.createTypeReferenceNode(
|
|
180
|
+
importer.external({
|
|
181
|
+
type: true,
|
|
182
|
+
library: "tgrid",
|
|
183
|
+
instance: "Driver",
|
|
184
|
+
}),
|
|
185
|
+
[ts.factory.createTypeReferenceNode(`${route.name}.Listener`)],
|
|
186
|
+
),
|
|
187
|
+
)(
|
|
188
|
+
ts.factory.createCallExpression(
|
|
189
|
+
ts.factory.createPropertyAccessExpression(
|
|
190
|
+
ts.factory.createIdentifier("connector"),
|
|
191
|
+
"getDriver",
|
|
192
|
+
),
|
|
193
|
+
undefined,
|
|
194
|
+
undefined,
|
|
195
|
+
),
|
|
196
|
+
),
|
|
197
|
+
ts.factory.createReturnStatement(
|
|
198
|
+
ts.factory.createObjectLiteralExpression(
|
|
199
|
+
[
|
|
200
|
+
ts.factory.createShorthandPropertyAssignment("connector"),
|
|
201
|
+
ts.factory.createShorthandPropertyAssignment("driver"),
|
|
202
|
+
],
|
|
203
|
+
true,
|
|
204
|
+
),
|
|
205
|
+
),
|
|
206
|
+
];
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const local =
|
|
211
|
+
(name: string) => (type: ts.TypeNode) => (expression: ts.Expression) =>
|
|
212
|
+
ts.factory.createVariableStatement(
|
|
213
|
+
[],
|
|
214
|
+
ts.factory.createVariableDeclarationList(
|
|
215
|
+
[
|
|
216
|
+
ts.factory.createVariableDeclaration(
|
|
217
|
+
name,
|
|
218
|
+
undefined,
|
|
219
|
+
type,
|
|
220
|
+
expression,
|
|
221
|
+
),
|
|
222
|
+
],
|
|
223
|
+
ts.NodeFlags.Const,
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const joinPath = (caller: ts.Expression) =>
|
|
228
|
+
ts.factory.createTemplateExpression(ts.factory.createTemplateHead("", ""), [
|
|
229
|
+
ts.factory.createTemplateSpan(
|
|
230
|
+
ts.factory.createConditionalExpression(
|
|
231
|
+
ts.factory.createCallExpression(
|
|
232
|
+
ts.factory.createPropertyAccessExpression(
|
|
233
|
+
ts.factory.createPropertyAccessExpression(
|
|
234
|
+
ts.factory.createIdentifier("connection"),
|
|
235
|
+
ts.factory.createIdentifier("host"),
|
|
236
|
+
),
|
|
237
|
+
ts.factory.createIdentifier("endsWith"),
|
|
238
|
+
),
|
|
239
|
+
undefined,
|
|
240
|
+
[ts.factory.createStringLiteral("/")],
|
|
241
|
+
),
|
|
242
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
243
|
+
ts.factory.createCallExpression(
|
|
244
|
+
ts.factory.createPropertyAccessExpression(
|
|
245
|
+
ts.factory.createPropertyAccessExpression(
|
|
246
|
+
ts.factory.createIdentifier("connection"),
|
|
247
|
+
ts.factory.createIdentifier("host"),
|
|
248
|
+
),
|
|
249
|
+
ts.factory.createIdentifier("substring"),
|
|
250
|
+
),
|
|
251
|
+
undefined,
|
|
252
|
+
[
|
|
253
|
+
ts.factory.createNumericLiteral("0"),
|
|
254
|
+
ts.factory.createBinaryExpression(
|
|
255
|
+
ts.factory.createPropertyAccessExpression(
|
|
256
|
+
ts.factory.createPropertyAccessExpression(
|
|
257
|
+
ts.factory.createIdentifier("connection"),
|
|
258
|
+
ts.factory.createIdentifier("host"),
|
|
259
|
+
),
|
|
260
|
+
ts.factory.createIdentifier("length"),
|
|
261
|
+
),
|
|
262
|
+
ts.factory.createToken(ts.SyntaxKind.MinusToken),
|
|
263
|
+
ts.factory.createNumericLiteral("1"),
|
|
264
|
+
),
|
|
265
|
+
],
|
|
266
|
+
),
|
|
267
|
+
ts.factory.createToken(ts.SyntaxKind.ColonToken),
|
|
268
|
+
ts.factory.createPropertyAccessExpression(
|
|
269
|
+
ts.factory.createIdentifier("connection"),
|
|
270
|
+
ts.factory.createIdentifier("host"),
|
|
271
|
+
),
|
|
272
|
+
),
|
|
273
|
+
ts.factory.createTemplateMiddle("", ""),
|
|
274
|
+
),
|
|
275
|
+
ts.factory.createTemplateSpan(
|
|
276
|
+
caller,
|
|
277
|
+
ts.factory.createTemplateTail("", ""),
|
|
278
|
+
),
|
|
279
|
+
]);
|