@nestia/sdk 13.0.4 → 14.0.1
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/README.md +1 -1
- package/assets/bundle/distribute/package.json +2 -2
- package/assets/bundle/distribute/tsconfig.json +15 -105
- package/lib/INestiaConfig.d.ts +19 -10
- package/lib/NestiaSdkApplication.js +58 -27
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.js +11 -10
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +4 -4
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ParameterNameAnalyzer.d.ts +20 -0
- package/lib/analyses/ParameterNameAnalyzer.js +48 -0
- package/lib/analyses/ParameterNameAnalyzer.js.map +1 -0
- package/lib/analyses/PathAnalyzer.d.ts +30 -0
- package/lib/analyses/PathAnalyzer.js +108 -16
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +2 -1
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +7 -7
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +122 -23
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +5 -2
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +5 -2
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +6 -3
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/analyses/SecurityAnalyzer.d.ts +10 -0
- package/lib/analyses/SecurityAnalyzer.js +24 -19
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/SwaggerExampleAnalyzer.d.ts +15 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js +20 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpRouteAnalyzer.js +30 -21
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.js +3 -3
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -1
- package/lib/executable/sdk.js +16 -1
- package/lib/executable/sdk.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +3 -0
- package/lib/factories/ExpressionFactory.js +6 -2
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.js +3 -1
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/generates/SdkGenerator.js +3 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +135 -27
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +14 -0
- package/lib/generates/internal/FilePrinter.js +31 -0
- package/lib/generates/internal/FilePrinter.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +2 -0
- package/lib/generates/internal/ImportDictionary.js +13 -0
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -1
- package/lib/generates/internal/SdkAliasCollection.js +8 -4
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +72 -14
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +83 -12
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +21 -23
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +27 -34
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +40 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.js +105 -6
- package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +16 -32
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +18 -14
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +39 -11
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkPathTemplate.d.ts +21 -0
- package/lib/generates/internal/SdkPathTemplate.js +50 -0
- package/lib/generates/internal/SdkPathTemplate.js.map +1 -0
- package/lib/generates/internal/SdkTypeProgrammer.js +15 -15
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +20 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.js +386 -67
- package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +27 -36
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +35 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +72 -5
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +57 -33
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +19 -8
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +201 -19
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +2 -0
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +39 -7
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/internal/legacy.d.ts +49 -18
- package/lib/internal/legacy.js +84 -25
- package/lib/internal/legacy.js.map +1 -1
- package/lib/structures/IOperationMetadata.d.ts +22 -0
- package/lib/structures/IReflectHttpOperationException.d.ts +3 -2
- package/lib/structures/IReflectHttpOperationParameter.d.ts +8 -3
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -3
- package/lib/structures/ITypedHttpRoute.d.ts +8 -0
- package/lib/structures/ITypedHttpRouteException.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteParameter.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
- package/lib/structures/ITypedWebSocketRoute.d.ts +8 -0
- package/lib/utils/SourceFinder.d.ts +10 -0
- package/lib/utils/SourceFinder.js +27 -4
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +13 -1
- package/lib/utils/VersioningStrategy.js +24 -12
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/native/go.mod +1 -1
- package/native/go.sum +2 -2
- package/native/sdk/sdk_http_rules.go +210 -0
- package/native/sdk/sdk_metadata_json.go +73 -3
- package/native/sdk/sdk_transform.go +801 -49
- package/package.json +8 -8
- package/src/INestiaConfig.ts +19 -10
- package/src/NestiaSdkApplication.ts +63 -34
- package/src/NestiaSwaggerComposer.ts +11 -8
- package/src/analyses/ConfigAnalyzer.ts +3 -3
- package/src/analyses/ParameterNameAnalyzer.ts +51 -0
- package/src/analyses/PathAnalyzer.ts +106 -14
- package/src/analyses/ReflectControllerAnalyzer.ts +2 -1
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +4 -4
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +122 -39
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +6 -7
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +6 -2
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +7 -3
- package/src/analyses/SecurityAnalyzer.ts +30 -20
- package/src/analyses/SwaggerExampleAnalyzer.ts +23 -0
- package/src/analyses/TypedHttpRouteAnalyzer.ts +29 -20
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +1 -0
- package/src/executable/internal/NestiaSdkWatcher.ts +2 -2
- package/src/executable/sdk.ts +24 -1
- package/src/factories/ExpressionFactory.ts +8 -2
- package/src/factories/LiteralFactory.ts +7 -2
- package/src/generates/SdkGenerator.ts +3 -3
- package/src/generates/SwaggerGenerator.ts +173 -32
- package/src/generates/internal/FilePrinter.ts +28 -0
- package/src/generates/internal/ImportDictionary.ts +11 -0
- package/src/generates/internal/SdkAliasCollection.ts +11 -4
- package/src/generates/internal/SdkDistributionComposer.ts +89 -15
- package/src/generates/internal/SdkFileProgrammer.ts +108 -16
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +28 -30
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +34 -64
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +193 -13
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +17 -31
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +51 -14
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +112 -15
- package/src/generates/internal/SdkPathTemplate.ts +73 -0
- package/src/generates/internal/SdkTypeProgrammer.ts +19 -22
- package/src/generates/internal/SdkTypeTagProgrammer.ts +506 -78
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +43 -68
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +126 -5
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +71 -48
- package/src/generates/internal/SwaggerOperationComposer.ts +20 -6
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +279 -30
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +55 -11
- package/src/internal/legacy.ts +114 -26
- package/src/structures/IOperationMetadata.ts +28 -0
- package/src/structures/IReflectHttpOperationException.ts +7 -2
- package/src/structures/IReflectHttpOperationParameter.ts +9 -2
- package/src/structures/IReflectHttpOperationSuccess.ts +8 -3
- package/src/structures/ITypedHttpRoute.ts +8 -0
- package/src/structures/ITypedHttpRouteException.ts +4 -1
- package/src/structures/ITypedHttpRouteParameter.ts +3 -1
- package/src/structures/ITypedHttpRouteSuccess.ts +4 -1
- package/src/structures/ITypedWebSocketRoute.ts +8 -0
- package/src/utils/SourceFinder.ts +25 -4
- package/src/utils/VersioningStrategy.ts +28 -13
- package/lib/validators/HttpHeadersValidator.d.ts +0 -11
- package/lib/validators/HttpHeadersValidator.js +0 -15
- package/lib/validators/HttpHeadersValidator.js.map +0 -1
- package/lib/validators/HttpQueryValidator.d.ts +0 -10
- package/lib/validators/HttpQueryValidator.js +0 -14
- package/lib/validators/HttpQueryValidator.js.map +0 -1
- package/src/validators/HttpHeadersValidator.ts +0 -12
- package/src/validators/HttpQueryValidator.ts +0 -11
|
@@ -16,6 +16,7 @@ import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
|
16
16
|
import { FilePrinter } from "./FilePrinter";
|
|
17
17
|
import { ImportDictionary } from "./ImportDictionary";
|
|
18
18
|
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
19
|
+
import { SdkPathTemplate } from "./SdkPathTemplate";
|
|
19
20
|
import { SdkWebSocketParameterProgrammer } from "./SdkWebSocketParameterProgrammer";
|
|
20
21
|
|
|
21
22
|
export namespace SdkWebSocketNamespaceProgrammer {
|
|
@@ -29,7 +30,7 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
29
30
|
factory.createModuleBlock([
|
|
30
31
|
...writeTypes(project)(importer)(route),
|
|
31
32
|
FilePrinter.enter(),
|
|
32
|
-
writePath(project)(route),
|
|
33
|
+
writePath(project)(importer)(route),
|
|
33
34
|
]),
|
|
34
35
|
NodeFlags.Namespace,
|
|
35
36
|
);
|
|
@@ -50,7 +51,13 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
50
51
|
);
|
|
51
52
|
|
|
52
53
|
if (project.config.keyword === true)
|
|
53
|
-
declare(
|
|
54
|
+
declare(
|
|
55
|
+
"Props",
|
|
56
|
+
SdkAliasCollection.websocketProps(
|
|
57
|
+
route,
|
|
58
|
+
SdkWebSocketParameterProgrammer.getNames({ project, route }),
|
|
59
|
+
),
|
|
60
|
+
);
|
|
54
61
|
declare(
|
|
55
62
|
"Output",
|
|
56
63
|
factory.createTypeLiteralNode([
|
|
@@ -128,6 +135,7 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
128
135
|
|
|
129
136
|
const writePath =
|
|
130
137
|
(project: INestiaProject) =>
|
|
138
|
+
(importer: ImportDictionary) =>
|
|
131
139
|
(route: ITypedWebSocketRoute): Statement => {
|
|
132
140
|
const out = (body: Block | Expression) =>
|
|
133
141
|
constant("path")(
|
|
@@ -146,63 +154,30 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
146
154
|
),
|
|
147
155
|
);
|
|
148
156
|
if (route.pathParameters.length === 0 && route.query === null)
|
|
149
|
-
return out(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
factory.createIdentifier("props"),
|
|
155
|
-
key,
|
|
156
|
-
)
|
|
157
|
-
: factory.createIdentifier(key);
|
|
158
|
-
const template = () => {
|
|
159
|
-
const split: string[] = route.path.split(":");
|
|
160
|
-
if (split.length === 1) return factory.createStringLiteral(route.path);
|
|
161
|
-
return factory.createTemplateExpression(
|
|
162
|
-
factory.createTemplateHead(split[0]!),
|
|
163
|
-
split.slice(1).map((s, i, arr) => {
|
|
164
|
-
const name: string = s.split("/")[0]!;
|
|
165
|
-
return factory.createTemplateSpan(
|
|
166
|
-
factory.createCallExpression(
|
|
167
|
-
factory.createIdentifier("encodeURIComponent"),
|
|
168
|
-
undefined,
|
|
169
|
-
[
|
|
170
|
-
factory.createBinaryExpression(
|
|
171
|
-
factory.createCallChain(
|
|
172
|
-
factory.createPropertyAccessChain(
|
|
173
|
-
access(
|
|
174
|
-
route.pathParameters.find((p) => p.field === name)!
|
|
175
|
-
.name,
|
|
176
|
-
),
|
|
177
|
-
factory.createToken(SyntaxKind.QuestionDotToken),
|
|
178
|
-
"toString",
|
|
179
|
-
),
|
|
180
|
-
undefined,
|
|
181
|
-
undefined,
|
|
182
|
-
[],
|
|
183
|
-
),
|
|
184
|
-
factory.createToken(SyntaxKind.QuestionQuestionToken),
|
|
185
|
-
factory.createStringLiteral("null"),
|
|
186
|
-
),
|
|
187
|
-
],
|
|
188
|
-
),
|
|
189
|
-
(i !== arr.length - 1
|
|
190
|
-
? factory.createTemplateMiddle
|
|
191
|
-
: factory.createTemplateTail)(s.substring(name.length)),
|
|
192
|
-
);
|
|
157
|
+
return out(
|
|
158
|
+
SdkPathTemplate.compose({
|
|
159
|
+
importer,
|
|
160
|
+
path: route.path,
|
|
161
|
+
argument: () => factory.createIdentifier("undefined"),
|
|
193
162
|
}),
|
|
194
163
|
);
|
|
195
|
-
|
|
164
|
+
const names: SdkWebSocketParameterProgrammer.INames =
|
|
165
|
+
SdkWebSocketParameterProgrammer.getNames({ project, route });
|
|
166
|
+
const template = () =>
|
|
167
|
+
SdkPathTemplate.compose({
|
|
168
|
+
importer,
|
|
169
|
+
path: route.path,
|
|
170
|
+
argument: (name) =>
|
|
171
|
+
names.access(
|
|
172
|
+
names.parameter(
|
|
173
|
+
route.pathParameters.find((p) => p.field === name)!,
|
|
174
|
+
),
|
|
175
|
+
),
|
|
176
|
+
});
|
|
196
177
|
if (route.query === null) return out(template());
|
|
197
178
|
|
|
198
179
|
const block = (expr: Expression) => {
|
|
199
|
-
const
|
|
200
|
-
[...route.pathParameters, ...(route.query ? [route.query] : [])].find(
|
|
201
|
-
(p) => p.name === str,
|
|
202
|
-
) !== undefined
|
|
203
|
-
? computeName("_" + str)
|
|
204
|
-
: str;
|
|
205
|
-
const variables: string = computeName("variables");
|
|
180
|
+
const variables: string = names.variables;
|
|
206
181
|
return factory.createBlock(
|
|
207
182
|
[
|
|
208
183
|
local(variables)("URLSearchParams")(
|
|
@@ -221,13 +196,13 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
221
196
|
factory.createBindingElement(
|
|
222
197
|
undefined,
|
|
223
198
|
undefined,
|
|
224
|
-
factory.createIdentifier(
|
|
199
|
+
factory.createIdentifier(names.key),
|
|
225
200
|
undefined,
|
|
226
201
|
),
|
|
227
202
|
factory.createBindingElement(
|
|
228
203
|
undefined,
|
|
229
204
|
undefined,
|
|
230
|
-
factory.createIdentifier(
|
|
205
|
+
factory.createIdentifier(names.value),
|
|
231
206
|
undefined,
|
|
232
207
|
),
|
|
233
208
|
]),
|
|
@@ -246,19 +221,19 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
246
221
|
factory.createIfStatement(
|
|
247
222
|
factory.createStrictEquality(
|
|
248
223
|
factory.createIdentifier("undefined"),
|
|
249
|
-
factory.createIdentifier(
|
|
224
|
+
factory.createIdentifier(names.value),
|
|
250
225
|
),
|
|
251
226
|
factory.createContinueStatement(),
|
|
252
227
|
factory.createIfStatement(
|
|
253
228
|
factory.createCallExpression(
|
|
254
229
|
factory.createIdentifier("Array.isArray"),
|
|
255
230
|
undefined,
|
|
256
|
-
[factory.createIdentifier(
|
|
231
|
+
[factory.createIdentifier(names.value)],
|
|
257
232
|
),
|
|
258
233
|
factory.createExpressionStatement(
|
|
259
234
|
factory.createCallExpression(
|
|
260
235
|
factory.createPropertyAccessExpression(
|
|
261
|
-
factory.createIdentifier(
|
|
236
|
+
factory.createIdentifier(names.value),
|
|
262
237
|
factory.createIdentifier("forEach"),
|
|
263
238
|
),
|
|
264
239
|
undefined,
|
|
@@ -266,7 +241,7 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
266
241
|
factory.createArrowFunction(
|
|
267
242
|
undefined,
|
|
268
243
|
undefined,
|
|
269
|
-
[IdentifierFactory.parameter(
|
|
244
|
+
[IdentifierFactory.parameter(names.elem)],
|
|
270
245
|
undefined,
|
|
271
246
|
undefined,
|
|
272
247
|
factory.createCallExpression(
|
|
@@ -276,11 +251,11 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
276
251
|
),
|
|
277
252
|
undefined,
|
|
278
253
|
[
|
|
279
|
-
factory.createIdentifier(
|
|
254
|
+
factory.createIdentifier(names.key),
|
|
280
255
|
factory.createCallExpression(
|
|
281
256
|
factory.createIdentifier("String"),
|
|
282
257
|
undefined,
|
|
283
|
-
[factory.createIdentifier(
|
|
258
|
+
[factory.createIdentifier(names.elem)],
|
|
284
259
|
),
|
|
285
260
|
],
|
|
286
261
|
),
|
|
@@ -296,11 +271,11 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
296
271
|
),
|
|
297
272
|
undefined,
|
|
298
273
|
[
|
|
299
|
-
factory.createIdentifier(
|
|
274
|
+
factory.createIdentifier(names.key),
|
|
300
275
|
factory.createCallExpression(
|
|
301
276
|
factory.createIdentifier("String"),
|
|
302
277
|
undefined,
|
|
303
|
-
[factory.createIdentifier(
|
|
278
|
+
[factory.createIdentifier(names.value)],
|
|
304
279
|
),
|
|
305
280
|
],
|
|
306
281
|
),
|
|
@@ -308,7 +283,7 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
308
283
|
),
|
|
309
284
|
),
|
|
310
285
|
),
|
|
311
|
-
local(
|
|
286
|
+
local(names.location)("string")(template()),
|
|
312
287
|
factory.createReturnStatement(
|
|
313
288
|
factory.createConditionalExpression(
|
|
314
289
|
factory.createStrictEquality(
|
|
@@ -319,13 +294,13 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
319
294
|
),
|
|
320
295
|
),
|
|
321
296
|
undefined,
|
|
322
|
-
factory.createIdentifier(
|
|
297
|
+
factory.createIdentifier(names.location),
|
|
323
298
|
undefined,
|
|
324
299
|
factory.createTemplateExpression(
|
|
325
300
|
factory.createTemplateHead(""),
|
|
326
301
|
[
|
|
327
302
|
factory.createTemplateSpan(
|
|
328
|
-
factory.createIdentifier(
|
|
303
|
+
factory.createIdentifier(names.location),
|
|
329
304
|
factory.createTemplateMiddle("?"),
|
|
330
305
|
),
|
|
331
306
|
factory.createTemplateSpan(
|
|
@@ -347,7 +322,7 @@ export namespace SdkWebSocketNamespaceProgrammer {
|
|
|
347
322
|
true,
|
|
348
323
|
);
|
|
349
324
|
};
|
|
350
|
-
return out(block(access(
|
|
325
|
+
return out(block(names.access(names.query)));
|
|
351
326
|
};
|
|
352
327
|
}
|
|
353
328
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type Expression,
|
|
2
3
|
type ParameterDeclaration,
|
|
3
4
|
type TypeNode,
|
|
4
5
|
factory,
|
|
@@ -6,6 +7,8 @@ import {
|
|
|
6
7
|
|
|
7
8
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
8
9
|
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
10
|
+
import { ITypedWebSocketRouteParameter } from "../../structures/ITypedWebSocketRouteParameter";
|
|
11
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
9
12
|
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
10
13
|
|
|
11
14
|
export namespace SdkWebSocketParameterProgrammer {
|
|
@@ -14,22 +17,139 @@ export namespace SdkWebSocketParameterProgrammer {
|
|
|
14
17
|
type: TypeNode;
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The identifiers one WebSocket route's SDK function and `path()` use,
|
|
22
|
+
* decided once so the two cannot disagree; the HTTP counterpart,
|
|
23
|
+
* `SdkHttpParameterProgrammer.INames`, gives the rules.
|
|
24
|
+
*
|
|
25
|
+
* Path parameters are the user's names. `query` and `provider` are the SDK's
|
|
26
|
+
* own: the positional parameters, or the `props` keys in keyword mode, that
|
|
27
|
+
* carry the query object and the provider, so they yield to a path parameter
|
|
28
|
+
* of the same name instead of repeating it. A `props` key shadows nothing, so
|
|
29
|
+
* it yields to nothing else.
|
|
30
|
+
*/
|
|
31
|
+
export interface INames {
|
|
32
|
+
connection: string;
|
|
33
|
+
props: string;
|
|
34
|
+
query: string;
|
|
35
|
+
provider: string;
|
|
36
|
+
url: string;
|
|
37
|
+
connector: string;
|
|
38
|
+
driver: string;
|
|
39
|
+
variables: string;
|
|
40
|
+
location: string;
|
|
41
|
+
key: string;
|
|
42
|
+
value: string;
|
|
43
|
+
elem: string;
|
|
44
|
+
|
|
45
|
+
/** Local identifier of a path parameter in positional mode. */
|
|
46
|
+
parameter: (p: ITypedWebSocketRouteParameter.IParam) => string;
|
|
47
|
+
|
|
48
|
+
/** Reads a parameter, or one of `query` and `provider`, by its key. */
|
|
49
|
+
access: (key: string) => Expression;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getNames = (props: {
|
|
53
|
+
project: INestiaProject;
|
|
54
|
+
route: ITypedWebSocketRoute;
|
|
55
|
+
}): INames => {
|
|
56
|
+
const { project, route } = props;
|
|
57
|
+
// names each scope references and the SDK cannot change
|
|
58
|
+
const functional: string[] = [route.name, "WebSocketConnector"];
|
|
59
|
+
const path: string[] = [
|
|
60
|
+
...(route.pathParameters.length !== 0 ? ["PathParameter"] : []),
|
|
61
|
+
...(route.query !== null
|
|
62
|
+
? ["URLSearchParams", "Object", "Array", "String", "undefined"]
|
|
63
|
+
: []),
|
|
64
|
+
];
|
|
65
|
+
const locals: Map<ITypedWebSocketRouteParameter.IParam, string> = new Map();
|
|
66
|
+
if (project.config.keyword !== true)
|
|
67
|
+
for (const p of route.pathParameters)
|
|
68
|
+
locals.set(
|
|
69
|
+
p,
|
|
70
|
+
StringUtil.escapeDuplicate([
|
|
71
|
+
...functional,
|
|
72
|
+
...path,
|
|
73
|
+
...route.pathParameters.filter((q) => q !== p).map((q) => q.name),
|
|
74
|
+
...locals.values(),
|
|
75
|
+
])(p.name),
|
|
76
|
+
);
|
|
77
|
+
// `query` and `provider` sit beside the path parameters, as parameters or
|
|
78
|
+
// as `props` keys. Every other own identifier avoids the positional
|
|
79
|
+
// path parameters its scope reads where it is visible: all of them for
|
|
80
|
+
// the function's locals, `variables`, and `location`, none for the
|
|
81
|
+
// loop's `key` and `value`, whose header reads only the query, and for
|
|
82
|
+
// `elem`.
|
|
83
|
+
const keys: string[] = route.pathParameters.map(
|
|
84
|
+
(p) => locals.get(p) ?? p.name,
|
|
85
|
+
);
|
|
86
|
+
const positional: string[] = [...locals.values()];
|
|
87
|
+
const own =
|
|
88
|
+
(fixed: string[], reads: string[], taken: string[]) =>
|
|
89
|
+
(name: string): string => {
|
|
90
|
+
const escaped: string = StringUtil.escapeDuplicate([
|
|
91
|
+
...fixed,
|
|
92
|
+
...reads,
|
|
93
|
+
...taken,
|
|
94
|
+
])(name);
|
|
95
|
+
taken.push(escaped);
|
|
96
|
+
return escaped;
|
|
97
|
+
};
|
|
98
|
+
const shared: string[] = [];
|
|
99
|
+
const $props: string = own([...functional, ...path], [], shared)("props");
|
|
100
|
+
// Positional `query` and `provider` also yield to the names their scopes
|
|
101
|
+
// reference; as `props` keys they shadow nothing, so a route named
|
|
102
|
+
// `query` keeps its `query` key.
|
|
103
|
+
const beside = (fixed: string[]) =>
|
|
104
|
+
own(project.config.keyword === true ? [] : fixed, keys, shared);
|
|
105
|
+
const $query: string = beside([...functional, ...path])("query");
|
|
106
|
+
const $provider: string = beside(functional)("provider");
|
|
107
|
+
const inFunction: string[] = [...shared];
|
|
108
|
+
const inPath: string[] = [...shared];
|
|
109
|
+
const names: Omit<INames, "parameter" | "access"> = {
|
|
110
|
+
props: $props,
|
|
111
|
+
query: $query,
|
|
112
|
+
provider: $provider,
|
|
113
|
+
connection: own(functional, positional, inFunction)("connection"),
|
|
114
|
+
url: own(functional, positional, inFunction)("url"),
|
|
115
|
+
connector: own(functional, positional, inFunction)("connector"),
|
|
116
|
+
driver: own(functional, positional, inFunction)("driver"),
|
|
117
|
+
variables: own(path, positional, inPath)("variables"),
|
|
118
|
+
location: own(path, positional, inPath)("location"),
|
|
119
|
+
key: own(path, [], inPath)("key"),
|
|
120
|
+
value: own(path, [], inPath)("value"),
|
|
121
|
+
elem: own(path, [], inPath)("elem"),
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
...names,
|
|
125
|
+
parameter: (p) => locals.get(p) ?? p.name,
|
|
126
|
+
access: (key) =>
|
|
127
|
+
project.config.keyword === true
|
|
128
|
+
? factory.createPropertyAccessExpression(
|
|
129
|
+
factory.createIdentifier(names.props),
|
|
130
|
+
key,
|
|
131
|
+
)
|
|
132
|
+
: factory.createIdentifier(key),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
17
136
|
export const getEntries = (props: {
|
|
18
137
|
project: INestiaProject;
|
|
19
138
|
route: ITypedWebSocketRoute;
|
|
20
139
|
provider: boolean;
|
|
21
140
|
prefix: boolean;
|
|
22
141
|
}): IEntry[] => {
|
|
142
|
+
const names: INames = getNames(props);
|
|
23
143
|
const prefix: string = props.prefix ? `${props.route.name}.` : "";
|
|
24
144
|
return [
|
|
25
145
|
...props.route.pathParameters.map((p) => ({
|
|
26
|
-
key: p
|
|
146
|
+
key: names.parameter(p),
|
|
27
147
|
type: SdkAliasCollection.name(p),
|
|
28
148
|
})),
|
|
29
149
|
...(props.route.query
|
|
30
150
|
? [
|
|
31
151
|
{
|
|
32
|
-
key:
|
|
152
|
+
key: names.query,
|
|
33
153
|
type: factory.createTypeReferenceNode(`${prefix}Query`),
|
|
34
154
|
},
|
|
35
155
|
]
|
|
@@ -37,7 +157,7 @@ export namespace SdkWebSocketParameterProgrammer {
|
|
|
37
157
|
...(props.provider
|
|
38
158
|
? [
|
|
39
159
|
{
|
|
40
|
-
key:
|
|
160
|
+
key: names.provider,
|
|
41
161
|
type: factory.createTypeReferenceNode(`${prefix}Provider`),
|
|
42
162
|
},
|
|
43
163
|
]
|
|
@@ -54,6 +174,7 @@ export namespace SdkWebSocketParameterProgrammer {
|
|
|
54
174
|
const entries: IEntry[] = getEntries(props);
|
|
55
175
|
if (entries.length === 0) return [];
|
|
56
176
|
else if (props.project.config.keyword === true) {
|
|
177
|
+
const names: INames = getNames(props);
|
|
57
178
|
const typeName: string = props.prefix
|
|
58
179
|
? `${props.route.name}.Props`
|
|
59
180
|
: "Props";
|
|
@@ -62,14 +183,14 @@ export namespace SdkWebSocketParameterProgrammer {
|
|
|
62
183
|
: factory.createTypeReferenceNode("Omit", [
|
|
63
184
|
factory.createTypeReferenceNode(typeName),
|
|
64
185
|
factory.createLiteralTypeNode(
|
|
65
|
-
factory.createStringLiteral(
|
|
186
|
+
factory.createStringLiteral(names.provider),
|
|
66
187
|
),
|
|
67
188
|
]);
|
|
68
189
|
return [
|
|
69
190
|
factory.createParameterDeclaration(
|
|
70
191
|
undefined,
|
|
71
192
|
undefined,
|
|
72
|
-
|
|
193
|
+
names.props,
|
|
73
194
|
undefined,
|
|
74
195
|
node,
|
|
75
196
|
),
|
|
@@ -6,12 +6,10 @@ import {
|
|
|
6
6
|
type TypeNode,
|
|
7
7
|
factory,
|
|
8
8
|
} from "@ttsc/factory";
|
|
9
|
-
import { IJsDocTagInfo } from "typia";
|
|
10
9
|
|
|
11
10
|
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
12
11
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
13
12
|
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
14
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
15
13
|
import { FilePrinter } from "./FilePrinter";
|
|
16
14
|
import { ImportDictionary } from "./ImportDictionary";
|
|
17
15
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
@@ -25,38 +23,65 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
25
23
|
(route: ITypedWebSocketRoute): Statement[] => [
|
|
26
24
|
FilePrinter.description(
|
|
27
25
|
writeFunction(project)(importer)(route),
|
|
28
|
-
writeDescription(route),
|
|
26
|
+
writeDescription(project, route),
|
|
29
27
|
),
|
|
30
28
|
SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
|
|
31
29
|
];
|
|
32
30
|
|
|
33
|
-
const writeDescription = (
|
|
31
|
+
const writeDescription = (
|
|
32
|
+
project: INestiaProject,
|
|
33
|
+
route: ITypedWebSocketRoute,
|
|
34
|
+
): string => {
|
|
34
35
|
// MAIN DESCRIPTION
|
|
35
36
|
const comments: string[] = route.description
|
|
36
37
|
? route.description.split("\n")
|
|
37
38
|
: [];
|
|
38
39
|
|
|
39
|
-
// COMMENT TAGS
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
// COMMENT TAGS, each `@param` naming what the SDK function declares,
|
|
41
|
+
// which yields on a collision
|
|
42
|
+
const names: SdkWebSocketParameterProgrammer.INames =
|
|
43
|
+
SdkWebSocketParameterProgrammer.getNames({ project, route });
|
|
44
|
+
const declared = (name: string | undefined): string | null => {
|
|
45
|
+
const path = route.pathParameters.find((p) => p.name === name);
|
|
46
|
+
const key: string | null =
|
|
47
|
+
path !== undefined
|
|
48
|
+
? project.config.keyword === true
|
|
49
|
+
? path.name
|
|
50
|
+
: names.parameter(path)
|
|
51
|
+
: route.query !== null && route.query.name === name
|
|
52
|
+
? names.query
|
|
53
|
+
: null;
|
|
54
|
+
return key === null
|
|
55
|
+
? null
|
|
56
|
+
: project.config.keyword === true
|
|
57
|
+
? `${names.props}.${key}`
|
|
58
|
+
: key;
|
|
59
|
+
};
|
|
60
|
+
const tags: string[] = route.jsDocTags
|
|
61
|
+
.map((tag): string | null => {
|
|
62
|
+
if (tag.name !== "param")
|
|
63
|
+
return FilePrinter.jsDocTag(
|
|
64
|
+
tag.name,
|
|
65
|
+
tag.text?.map((e) => e.text).join("") ?? "",
|
|
66
|
+
);
|
|
67
|
+
const name: string | null = declared(tag.text?.[0]?.text);
|
|
68
|
+
return name === null
|
|
69
|
+
? null
|
|
70
|
+
: FilePrinter.jsDocTag(
|
|
71
|
+
`param ${name}`,
|
|
72
|
+
tag.text?.find((e) => e.kind === "text")?.text ?? "",
|
|
73
|
+
);
|
|
74
|
+
})
|
|
75
|
+
.filter((tag): tag is string => tag !== null);
|
|
76
|
+
// apart from the description, when there is one
|
|
77
|
+
if (tags.length !== 0)
|
|
78
|
+
comments.push(...(comments.length !== 0 ? [""] : []), ...new Set(tags));
|
|
55
79
|
|
|
56
80
|
// POSTFIX
|
|
57
81
|
if (!!comments.length) comments.push("");
|
|
58
82
|
comments.push(
|
|
59
|
-
|
|
83
|
+
// the public name, kept by a route declared under a local one
|
|
84
|
+
`@controller ${route.controller.class.name}.${route.key}`,
|
|
60
85
|
`@path ${route.path}`,
|
|
61
86
|
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
|
|
62
87
|
);
|
|
@@ -67,9 +92,8 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
67
92
|
(project: INestiaProject) =>
|
|
68
93
|
(importer: ImportDictionary) =>
|
|
69
94
|
(route: ITypedWebSocketRoute): Statement => {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
);
|
|
95
|
+
const names: SdkWebSocketParameterProgrammer.INames =
|
|
96
|
+
SdkWebSocketParameterProgrammer.getNames({ project, route });
|
|
73
97
|
return factory.createFunctionDeclaration(
|
|
74
98
|
[
|
|
75
99
|
factory.createModifier(SyntaxKind.ExportKeyword),
|
|
@@ -80,7 +104,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
80
104
|
undefined,
|
|
81
105
|
[
|
|
82
106
|
IdentifierFactory.parameter(
|
|
83
|
-
connection,
|
|
107
|
+
names.connection,
|
|
84
108
|
factory.createTypeReferenceNode(
|
|
85
109
|
SdkImportWizard.IConnection(importer),
|
|
86
110
|
[factory.createTypeReferenceNode(`${route.name}.Header`)],
|
|
@@ -97,7 +121,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
97
121
|
factory.createTypeReferenceNode(`${route.name}.Output`),
|
|
98
122
|
]),
|
|
99
123
|
factory.createBlock(
|
|
100
|
-
writeFunctionBody(project)(importer)(route)(
|
|
124
|
+
writeFunctionBody(project)(importer)(route)(names),
|
|
101
125
|
true,
|
|
102
126
|
),
|
|
103
127
|
);
|
|
@@ -107,18 +131,11 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
107
131
|
(project: INestiaProject) =>
|
|
108
132
|
(importer: ImportDictionary) =>
|
|
109
133
|
(route: ITypedWebSocketRoute) =>
|
|
110
|
-
(
|
|
111
|
-
const access = (key: string) =>
|
|
112
|
-
project.config.keyword === true
|
|
113
|
-
? factory.createPropertyAccessExpression(
|
|
114
|
-
factory.createIdentifier("props"),
|
|
115
|
-
key,
|
|
116
|
-
)
|
|
117
|
-
: factory.createIdentifier(key);
|
|
134
|
+
(names: SdkWebSocketParameterProgrammer.INames): Statement[] => {
|
|
118
135
|
return [
|
|
119
|
-
local(
|
|
136
|
+
local(names.url)(factory.createTypeReferenceNode("string"))(
|
|
120
137
|
joinPath(
|
|
121
|
-
connection,
|
|
138
|
+
names.connection,
|
|
122
139
|
factory.createCallExpression(
|
|
123
140
|
factory.createPropertyAccessExpression(
|
|
124
141
|
factory.createIdentifier(route.name),
|
|
@@ -127,7 +144,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
127
144
|
[],
|
|
128
145
|
project.config.keyword === true &&
|
|
129
146
|
SdkWebSocketParameterProgrammer.isPathEmpty(route) === false
|
|
130
|
-
? [factory.createIdentifier(
|
|
147
|
+
? [factory.createIdentifier(names.props)]
|
|
131
148
|
: SdkWebSocketParameterProgrammer.getEntries({
|
|
132
149
|
project,
|
|
133
150
|
route,
|
|
@@ -137,7 +154,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
137
154
|
),
|
|
138
155
|
),
|
|
139
156
|
),
|
|
140
|
-
local(
|
|
157
|
+
local(names.connector)(
|
|
141
158
|
factory.createTypeReferenceNode(
|
|
142
159
|
importer.external({
|
|
143
160
|
declaration: false,
|
|
@@ -166,7 +183,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
166
183
|
factory.createAsExpression(
|
|
167
184
|
factory.createBinaryExpression(
|
|
168
185
|
factory.createPropertyAccessExpression(
|
|
169
|
-
factory.createIdentifier(connection),
|
|
186
|
+
factory.createIdentifier(names.connection),
|
|
170
187
|
"headers",
|
|
171
188
|
),
|
|
172
189
|
factory.createToken(SyntaxKind.QuestionQuestionToken),
|
|
@@ -174,7 +191,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
174
191
|
),
|
|
175
192
|
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
|
|
176
193
|
),
|
|
177
|
-
access(
|
|
194
|
+
names.access(names.provider),
|
|
178
195
|
],
|
|
179
196
|
),
|
|
180
197
|
),
|
|
@@ -182,15 +199,15 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
182
199
|
factory.createAwaitExpression(
|
|
183
200
|
factory.createCallExpression(
|
|
184
201
|
factory.createPropertyAccessExpression(
|
|
185
|
-
factory.createIdentifier(
|
|
202
|
+
factory.createIdentifier(names.connector),
|
|
186
203
|
"connect",
|
|
187
204
|
),
|
|
188
205
|
undefined,
|
|
189
|
-
[factory.createIdentifier(
|
|
206
|
+
[factory.createIdentifier(names.url)],
|
|
190
207
|
),
|
|
191
208
|
),
|
|
192
209
|
),
|
|
193
|
-
local(
|
|
210
|
+
local(names.driver)(
|
|
194
211
|
factory.createTypeReferenceNode(
|
|
195
212
|
importer.external({
|
|
196
213
|
declaration: true,
|
|
@@ -203,7 +220,7 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
203
220
|
)(
|
|
204
221
|
factory.createCallExpression(
|
|
205
222
|
factory.createPropertyAccessExpression(
|
|
206
|
-
factory.createIdentifier(
|
|
223
|
+
factory.createIdentifier(names.connector),
|
|
207
224
|
"getDriver",
|
|
208
225
|
),
|
|
209
226
|
undefined,
|
|
@@ -213,8 +230,8 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
213
230
|
factory.createReturnStatement(
|
|
214
231
|
factory.createObjectLiteralExpression(
|
|
215
232
|
[
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
writeOutputMember("connector", names.connector),
|
|
234
|
+
writeOutputMember("driver", names.driver),
|
|
218
235
|
factory.createPropertyAssignment(
|
|
219
236
|
factory.createIdentifier("reconnect"),
|
|
220
237
|
factory.createArrowFunction(
|
|
@@ -226,11 +243,11 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
226
243
|
factory.createAwaitExpression(
|
|
227
244
|
factory.createCallExpression(
|
|
228
245
|
factory.createPropertyAccessExpression(
|
|
229
|
-
factory.createIdentifier(
|
|
246
|
+
factory.createIdentifier(names.connector),
|
|
230
247
|
factory.createIdentifier("connect"),
|
|
231
248
|
),
|
|
232
249
|
undefined,
|
|
233
|
-
[factory.createIdentifier(
|
|
250
|
+
[factory.createIdentifier(names.url)],
|
|
234
251
|
),
|
|
235
252
|
),
|
|
236
253
|
),
|
|
@@ -243,6 +260,12 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
243
260
|
};
|
|
244
261
|
}
|
|
245
262
|
|
|
263
|
+
/** A member of the returned `Output`, shorthand when its local has its name. */
|
|
264
|
+
const writeOutputMember = (key: string, local: string) =>
|
|
265
|
+
key === local
|
|
266
|
+
? factory.createShorthandPropertyAssignment(key)
|
|
267
|
+
: factory.createPropertyAssignment(key, factory.createIdentifier(local));
|
|
268
|
+
|
|
246
269
|
const local = (name: string) => (type: TypeNode) => (expression: Expression) =>
|
|
247
270
|
factory.createVariableStatement(
|
|
248
271
|
[],
|