@nestia/sdk 7.0.0-dev.20250606 → 7.0.0-dev.20250608
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/lib/analyses/TypedHttpRouteAnalyzer.js +12 -3
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js +4 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
- package/lib/generates/SdkGenerator.js +2 -1
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +3 -3
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +17 -22
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +3 -1
- package/lib/generates/internal/SdkAliasCollection.js +23 -12
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js +2 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +1 -6
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +33 -48
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +1 -6
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +46 -66
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +41 -0
- package/lib/generates/internal/SdkHttpParameterProgrammer.js +110 -0
- package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +6 -18
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +1 -6
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +23 -34
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +2 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +33 -27
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +22 -0
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +58 -0
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +2 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +65 -51
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +9 -6
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/structures/ITypedHttpRoute.d.ts +6 -1
- package/lib/structures/ITypedHttpRouteParameter.d.ts +2 -2
- package/lib/structures/ITypedWebSocketRoute.d.ts +5 -1
- package/package.json +5 -5
- package/src/analyses/TypedHttpRouteAnalyzer.ts +28 -10
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +15 -0
- package/src/generates/SdkGenerator.ts +2 -1
- package/src/generates/SwaggerGenerator.ts +5 -13
- package/src/generates/internal/E2eFileProgrammer.ts +34 -43
- package/src/generates/internal/SdkAliasCollection.ts +46 -17
- package/src/generates/internal/SdkFileProgrammer.ts +1 -1
- package/src/generates/internal/SdkHttpCloneReferencer.ts +5 -1
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +49 -109
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +58 -118
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +178 -0
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +9 -21
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +23 -77
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +214 -210
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +87 -0
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +112 -98
- package/src/generates/internal/SwaggerOperationComposer.ts +9 -9
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +1 -1
- package/src/structures/ITypedHttpRoute.ts +12 -1
- package/src/structures/ITypedHttpRouteParameter.ts +2 -2
- package/src/structures/ITypedWebSocketRoute.ts +5 -1
|
@@ -7,10 +7,10 @@ import { Escaper } from "typia/lib/utils/Escaper";
|
|
|
7
7
|
|
|
8
8
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
9
9
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
10
|
-
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
11
10
|
import { FilePrinter } from "./FilePrinter";
|
|
12
11
|
import { ImportDictionary } from "./ImportDictionary";
|
|
13
12
|
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
13
|
+
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
14
14
|
import { SdkHttpSimulationProgrammer } from "./SdkHttpSimulationProgrammer";
|
|
15
15
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
16
16
|
|
|
@@ -18,37 +18,28 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
18
18
|
export const write =
|
|
19
19
|
(project: INestiaProject) =>
|
|
20
20
|
(importer: ImportDictionary) =>
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
headers: ITypedHttpRouteParameter.IHeaders | undefined;
|
|
25
|
-
query: ITypedHttpRouteParameter.IQuery | undefined;
|
|
26
|
-
body: ITypedHttpRouteParameter.IBody | undefined;
|
|
27
|
-
},
|
|
28
|
-
): ts.ModuleDeclaration => {
|
|
29
|
-
const types = writeTypes(project)(importer)(route, props);
|
|
21
|
+
(route: ITypedHttpRoute): ts.ModuleDeclaration => {
|
|
22
|
+
const types: ts.TypeAliasDeclaration[] =
|
|
23
|
+
writeTypes(project)(importer)(route);
|
|
30
24
|
return ts.factory.createModuleDeclaration(
|
|
31
25
|
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
32
26
|
ts.factory.createIdentifier(route.name),
|
|
33
27
|
ts.factory.createModuleBlock([
|
|
34
28
|
...types,
|
|
35
29
|
...(types.length ? [FilePrinter.enter()] : []),
|
|
36
|
-
writeMetadata(project)(importer)(route
|
|
30
|
+
writeMetadata(project)(importer)(route),
|
|
37
31
|
FilePrinter.enter(),
|
|
38
|
-
writePath(project)(importer)(route
|
|
32
|
+
writePath(project)(importer)(route),
|
|
39
33
|
...(project.config.simulate
|
|
40
34
|
? [
|
|
41
35
|
SdkHttpSimulationProgrammer.random(project)(importer)(route),
|
|
42
|
-
SdkHttpSimulationProgrammer.simulate(project)(importer)(
|
|
43
|
-
route,
|
|
44
|
-
props,
|
|
45
|
-
),
|
|
36
|
+
SdkHttpSimulationProgrammer.simulate(project)(importer)(route),
|
|
46
37
|
]
|
|
47
38
|
: []),
|
|
48
39
|
...(project.config.json &&
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
|
|
40
|
+
route.body &&
|
|
41
|
+
(route.body.contentType === "application/json" ||
|
|
42
|
+
route.body.encrypted === true)
|
|
52
43
|
? [writeStringify(project)(importer)]
|
|
53
44
|
: []),
|
|
54
45
|
]),
|
|
@@ -59,14 +50,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
59
50
|
const writeTypes =
|
|
60
51
|
(project: INestiaProject) =>
|
|
61
52
|
(importer: ImportDictionary) =>
|
|
62
|
-
(
|
|
63
|
-
route: ITypedHttpRoute,
|
|
64
|
-
props: {
|
|
65
|
-
headers: ITypedHttpRouteParameter.IHeaders | undefined;
|
|
66
|
-
query: ITypedHttpRouteParameter.IQuery | undefined;
|
|
67
|
-
body: ITypedHttpRouteParameter.IBody | undefined;
|
|
68
|
-
},
|
|
69
|
-
): ts.TypeAliasDeclaration[] => {
|
|
53
|
+
(route: ITypedHttpRoute): ts.TypeAliasDeclaration[] => {
|
|
70
54
|
const array: ts.TypeAliasDeclaration[] = [];
|
|
71
55
|
const declare = (name: string, type: ts.TypeNode) =>
|
|
72
56
|
array.push(
|
|
@@ -79,27 +63,30 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
79
63
|
);
|
|
80
64
|
if (
|
|
81
65
|
project.config.keyword === true &&
|
|
82
|
-
|
|
66
|
+
SdkHttpParameterProgrammer.getSignificant(route, true).length !== 0
|
|
83
67
|
)
|
|
84
|
-
declare(
|
|
85
|
-
|
|
68
|
+
declare(
|
|
69
|
+
"Props",
|
|
70
|
+
SdkAliasCollection.httpProps(project)(importer)(route),
|
|
71
|
+
);
|
|
72
|
+
if (route.headerObject)
|
|
86
73
|
declare(
|
|
87
74
|
"Headers",
|
|
88
|
-
SdkAliasCollection.headers(project)(importer)(
|
|
75
|
+
SdkAliasCollection.headers(project)(importer)(route.headerObject),
|
|
89
76
|
);
|
|
90
|
-
if (
|
|
77
|
+
if (route.queryObject)
|
|
91
78
|
declare(
|
|
92
79
|
"Query",
|
|
93
|
-
SdkAliasCollection.query(project)(importer)(
|
|
80
|
+
SdkAliasCollection.query(project)(importer)(route.queryObject),
|
|
94
81
|
);
|
|
95
|
-
if (
|
|
96
|
-
declare("Body", SdkAliasCollection.body(project)(importer)(
|
|
82
|
+
if (route.body)
|
|
83
|
+
declare("Body", SdkAliasCollection.body(project)(importer)(route.body));
|
|
97
84
|
if (
|
|
98
85
|
project.config.propagate === true ||
|
|
99
86
|
route.success.metadata.size() !== 0
|
|
100
87
|
)
|
|
101
88
|
declare(
|
|
102
|
-
"
|
|
89
|
+
"Output",
|
|
103
90
|
SdkAliasCollection.response(project)(importer)(route),
|
|
104
91
|
);
|
|
105
92
|
return array;
|
|
@@ -108,14 +95,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
108
95
|
const writeMetadata =
|
|
109
96
|
(project: INestiaProject) =>
|
|
110
97
|
(importer: ImportDictionary) =>
|
|
111
|
-
(
|
|
112
|
-
route: ITypedHttpRoute,
|
|
113
|
-
props: {
|
|
114
|
-
headers: ITypedHttpRouteParameter.IHeaders | undefined;
|
|
115
|
-
query: ITypedHttpRouteParameter.IQuery | undefined;
|
|
116
|
-
body: ITypedHttpRouteParameter.IBody | undefined;
|
|
117
|
-
},
|
|
118
|
-
): ts.VariableStatement =>
|
|
98
|
+
(route: ITypedHttpRoute): ts.VariableStatement =>
|
|
119
99
|
constant("METADATA")(
|
|
120
100
|
ts.factory.createAsExpression(
|
|
121
101
|
ts.factory.createObjectLiteralExpression(
|
|
@@ -130,12 +110,12 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
130
110
|
),
|
|
131
111
|
ts.factory.createPropertyAssignment(
|
|
132
112
|
"request",
|
|
133
|
-
|
|
113
|
+
route.body
|
|
134
114
|
? LiteralFactory.write(
|
|
135
|
-
|
|
115
|
+
route.body !== undefined
|
|
136
116
|
? {
|
|
137
|
-
type:
|
|
138
|
-
encrypted: !!
|
|
117
|
+
type: route.body.contentType,
|
|
118
|
+
encrypted: !!route.body.encrypted,
|
|
139
119
|
}
|
|
140
120
|
: {
|
|
141
121
|
type: "application/json",
|
|
@@ -192,79 +172,33 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
192
172
|
const writePath =
|
|
193
173
|
(project: INestiaProject) =>
|
|
194
174
|
(importer: ImportDictionary) =>
|
|
195
|
-
(
|
|
196
|
-
route: ITypedHttpRoute,
|
|
197
|
-
query: ITypedHttpRouteParameter.IQuery | undefined,
|
|
198
|
-
): ts.VariableStatement => {
|
|
199
|
-
interface IProperty {
|
|
200
|
-
key: string;
|
|
201
|
-
value: ts.TypeNode;
|
|
202
|
-
required: boolean;
|
|
203
|
-
}
|
|
204
|
-
const g = {
|
|
205
|
-
total: [
|
|
206
|
-
...route.parameters.filter(
|
|
207
|
-
(param) => param.category === "param" || param.category === "query",
|
|
208
|
-
),
|
|
209
|
-
],
|
|
210
|
-
query: route.parameters
|
|
211
|
-
.filter((param) => param.category === "query")
|
|
212
|
-
.filter((param) => param.field !== null),
|
|
213
|
-
path: route.parameters.filter((param) => param.category === "param"),
|
|
214
|
-
};
|
|
215
|
-
const properties: IProperty[] = g.total.map((p) => ({
|
|
216
|
-
key: p.name,
|
|
217
|
-
value:
|
|
218
|
-
p === query
|
|
219
|
-
? p.metadata.isRequired() === false
|
|
220
|
-
? ts.factory.createUnionTypeNode([
|
|
221
|
-
ts.factory.createTypeReferenceNode(`Query`),
|
|
222
|
-
ts.factory.createTypeReferenceNode("undefined"),
|
|
223
|
-
])
|
|
224
|
-
: ts.factory.createTypeReferenceNode(`Query`)
|
|
225
|
-
: project.config.clone === true
|
|
226
|
-
? SdkAliasCollection.from(project)(importer)(p.metadata)
|
|
227
|
-
: SdkAliasCollection.name(p),
|
|
228
|
-
required: p.metadata.isRequired(),
|
|
229
|
-
}));
|
|
175
|
+
(route: ITypedHttpRoute): ts.VariableStatement => {
|
|
230
176
|
const out = (body: ts.ConciseBody) =>
|
|
231
177
|
constant("path")(
|
|
232
178
|
ts.factory.createArrowFunction(
|
|
233
179
|
[],
|
|
234
180
|
[],
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
undefined,
|
|
243
|
-
p.key,
|
|
244
|
-
p.required
|
|
245
|
-
? undefined
|
|
246
|
-
: ts.factory.createToken(
|
|
247
|
-
ts.SyntaxKind.QuestionToken,
|
|
248
|
-
),
|
|
249
|
-
p.value,
|
|
250
|
-
),
|
|
251
|
-
),
|
|
252
|
-
),
|
|
253
|
-
),
|
|
254
|
-
]
|
|
255
|
-
: properties.map((p) =>
|
|
256
|
-
IdentifierFactory.parameter(p.key, p.value),
|
|
257
|
-
),
|
|
181
|
+
SdkHttpParameterProgrammer.getParameterDeclarations({
|
|
182
|
+
project,
|
|
183
|
+
importer,
|
|
184
|
+
route,
|
|
185
|
+
body: false,
|
|
186
|
+
prefix: false,
|
|
187
|
+
}),
|
|
258
188
|
undefined,
|
|
259
189
|
undefined,
|
|
260
190
|
body,
|
|
261
191
|
),
|
|
262
192
|
);
|
|
263
|
-
|
|
193
|
+
const parameters = SdkHttpParameterProgrammer.getSignificant(
|
|
194
|
+
route,
|
|
195
|
+
false,
|
|
196
|
+
);
|
|
197
|
+
if (parameters.length === 0)
|
|
264
198
|
return out(ts.factory.createStringLiteral(route.path));
|
|
265
199
|
|
|
266
200
|
const access = (name: string) =>
|
|
267
|
-
project.config.keyword === true ? `
|
|
201
|
+
project.config.keyword === true ? `props.${name}` : name;
|
|
268
202
|
const template = () => {
|
|
269
203
|
const split: string[] = route.path.split(":");
|
|
270
204
|
if (split.length === 1)
|
|
@@ -282,7 +216,10 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
282
216
|
ts.factory.createCallChain(
|
|
283
217
|
ts.factory.createPropertyAccessChain(
|
|
284
218
|
ts.factory.createIdentifier(
|
|
285
|
-
access(
|
|
219
|
+
access(
|
|
220
|
+
route.pathParameters.find((p) => p.field === name)!
|
|
221
|
+
.name,
|
|
222
|
+
),
|
|
286
223
|
),
|
|
287
224
|
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
288
225
|
"toString",
|
|
@@ -303,11 +240,12 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
303
240
|
}),
|
|
304
241
|
);
|
|
305
242
|
};
|
|
306
|
-
if (
|
|
243
|
+
if (route.queryObject === null && route.queryParameters.length === 0)
|
|
244
|
+
return out(template());
|
|
307
245
|
|
|
308
246
|
const block = (expr: ts.Expression) => {
|
|
309
247
|
const computeName = (str: string): string =>
|
|
310
|
-
|
|
248
|
+
parameters.find((p) => p.name === str) !== undefined
|
|
311
249
|
? computeName("_" + str)
|
|
312
250
|
: str;
|
|
313
251
|
const variables: string = computeName("variables");
|
|
@@ -460,30 +398,32 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
460
398
|
true,
|
|
461
399
|
);
|
|
462
400
|
};
|
|
463
|
-
if (
|
|
401
|
+
if (route.queryObject !== null && route.queryParameters.length === 0)
|
|
464
402
|
return out(
|
|
465
403
|
block(
|
|
466
|
-
|
|
404
|
+
route.queryObject.metadata.isRequired() === false
|
|
467
405
|
? ts.factory.createBinaryExpression(
|
|
468
|
-
ts.factory.createIdentifier(
|
|
406
|
+
ts.factory.createIdentifier(route.queryObject.name),
|
|
469
407
|
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
470
408
|
ts.factory.createObjectLiteralExpression([], false),
|
|
471
409
|
)
|
|
472
|
-
: ts.factory.createIdentifier(access(
|
|
410
|
+
: ts.factory.createIdentifier(access(route.queryObject.name)),
|
|
473
411
|
),
|
|
474
412
|
);
|
|
475
413
|
return out(
|
|
476
414
|
block(
|
|
477
415
|
ts.factory.createObjectLiteralExpression(
|
|
478
416
|
[
|
|
479
|
-
...(
|
|
417
|
+
...(route.queryObject
|
|
480
418
|
? [
|
|
481
419
|
ts.factory.createSpreadAssignment(
|
|
482
|
-
ts.factory.createIdentifier(
|
|
420
|
+
ts.factory.createIdentifier(
|
|
421
|
+
access(route.queryObject.name),
|
|
422
|
+
),
|
|
483
423
|
),
|
|
484
424
|
]
|
|
485
425
|
: []),
|
|
486
|
-
...
|
|
426
|
+
...route.queryParameters.map((q) =>
|
|
487
427
|
ts.factory.createPropertyAssignment(
|
|
488
428
|
Escaper.variable(q.field!)
|
|
489
429
|
? q.field!
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
4
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
5
|
+
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
6
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
7
|
+
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
8
|
+
|
|
9
|
+
export namespace SdkHttpParameterProgrammer {
|
|
10
|
+
export interface IEntry {
|
|
11
|
+
key: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
type: ts.TypeNode;
|
|
14
|
+
parameter: ITypedHttpRouteParameter;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getAll = (
|
|
18
|
+
route: ITypedHttpRoute,
|
|
19
|
+
): ITypedHttpRouteParameter[] => [
|
|
20
|
+
...route.pathParameters,
|
|
21
|
+
...route.queryParameters,
|
|
22
|
+
...route.headerParameters,
|
|
23
|
+
...(route.queryObject ? [route.queryObject] : []),
|
|
24
|
+
...(route.body ? [route.body] : []),
|
|
25
|
+
...(route.headerObject ? [route.headerObject] : []),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export const getSignificant = (route: ITypedHttpRoute, body: boolean) => [
|
|
29
|
+
...route.pathParameters,
|
|
30
|
+
...route.queryParameters,
|
|
31
|
+
...(route.queryObject ? [route.queryObject] : []),
|
|
32
|
+
...(body && route.body ? [route.body] : []),
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export const getEntries = (props: {
|
|
36
|
+
project: INestiaProject;
|
|
37
|
+
importer: ImportDictionary;
|
|
38
|
+
route: ITypedHttpRoute;
|
|
39
|
+
body: boolean;
|
|
40
|
+
prefix: boolean | string;
|
|
41
|
+
e2e?: boolean;
|
|
42
|
+
}): IEntry[] => {
|
|
43
|
+
if (
|
|
44
|
+
props.route.pathParameters.length === 0 &&
|
|
45
|
+
props.route.queryParameters.length === 0 &&
|
|
46
|
+
props.route.queryObject === null &&
|
|
47
|
+
(props.body === false || props.route.body === null)
|
|
48
|
+
)
|
|
49
|
+
return [];
|
|
50
|
+
const prefix =
|
|
51
|
+
typeof props.prefix === "string"
|
|
52
|
+
? props.prefix
|
|
53
|
+
: props.prefix === true
|
|
54
|
+
? `${props.route.name}.`
|
|
55
|
+
: "";
|
|
56
|
+
return [
|
|
57
|
+
...[...props.route.pathParameters, ...props.route.queryParameters].map(
|
|
58
|
+
(p) => ({
|
|
59
|
+
key: p.name,
|
|
60
|
+
required: p.metadata.isRequired(),
|
|
61
|
+
type:
|
|
62
|
+
props.project.config.clone === true
|
|
63
|
+
? SdkAliasCollection.from(props.project)(props.importer)(
|
|
64
|
+
p.metadata,
|
|
65
|
+
)
|
|
66
|
+
: SdkAliasCollection.name(p),
|
|
67
|
+
parameter: p,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
...(props.route.queryObject
|
|
71
|
+
? [
|
|
72
|
+
{
|
|
73
|
+
key: props.route.queryObject.name,
|
|
74
|
+
required: props.route.queryObject.metadata.isRequired(),
|
|
75
|
+
type:
|
|
76
|
+
props.e2e === true
|
|
77
|
+
? props.project.config.clone === true
|
|
78
|
+
? SdkAliasCollection.from(props.project)(props.importer)(
|
|
79
|
+
props.route.queryObject.metadata,
|
|
80
|
+
)
|
|
81
|
+
: SdkAliasCollection.name(props.route.queryObject)
|
|
82
|
+
: ts.factory.createTypeReferenceNode(`${prefix}Query`),
|
|
83
|
+
parameter: props.route.queryObject,
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
: []),
|
|
87
|
+
...(props.body && props.route.body
|
|
88
|
+
? [
|
|
89
|
+
{
|
|
90
|
+
key: props.route.body.name,
|
|
91
|
+
required: props.route.body.metadata.isRequired(),
|
|
92
|
+
type:
|
|
93
|
+
props.e2e === true
|
|
94
|
+
? props.project.config.clone === true
|
|
95
|
+
? SdkAliasCollection.from(props.project)(props.importer)(
|
|
96
|
+
props.route.body.metadata,
|
|
97
|
+
)
|
|
98
|
+
: SdkAliasCollection.name(props.route.body)
|
|
99
|
+
: ts.factory.createTypeReferenceNode(`${prefix}Body`),
|
|
100
|
+
parameter: props.route.body,
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
: []),
|
|
104
|
+
];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const getParameterDeclarations = (props: {
|
|
108
|
+
project: INestiaProject;
|
|
109
|
+
importer: ImportDictionary;
|
|
110
|
+
route: ITypedHttpRoute;
|
|
111
|
+
body: boolean;
|
|
112
|
+
prefix: boolean;
|
|
113
|
+
}): ts.ParameterDeclaration[] => {
|
|
114
|
+
const entries: IEntry[] = getEntries(props);
|
|
115
|
+
if (entries.length === 0) return [];
|
|
116
|
+
else if (props.project.config.keyword === true) {
|
|
117
|
+
const typeName: string = props.prefix
|
|
118
|
+
? `${props.route.name}.Props`
|
|
119
|
+
: "Props";
|
|
120
|
+
const node: ts.TypeReferenceNode =
|
|
121
|
+
props.body === false && props.route.body !== null
|
|
122
|
+
? ts.factory.createTypeReferenceNode("Omit", [
|
|
123
|
+
ts.factory.createTypeReferenceNode(typeName),
|
|
124
|
+
ts.factory.createLiteralTypeNode(
|
|
125
|
+
ts.factory.createStringLiteral(props.route.body.name),
|
|
126
|
+
),
|
|
127
|
+
])
|
|
128
|
+
: ts.factory.createTypeReferenceNode(typeName);
|
|
129
|
+
return [
|
|
130
|
+
ts.factory.createParameterDeclaration(
|
|
131
|
+
undefined,
|
|
132
|
+
undefined,
|
|
133
|
+
"props",
|
|
134
|
+
undefined,
|
|
135
|
+
node,
|
|
136
|
+
undefined,
|
|
137
|
+
),
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
return entries.map((e) =>
|
|
141
|
+
ts.factory.createParameterDeclaration(
|
|
142
|
+
undefined,
|
|
143
|
+
undefined,
|
|
144
|
+
e.key,
|
|
145
|
+
e.required
|
|
146
|
+
? undefined
|
|
147
|
+
: ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
148
|
+
e.type,
|
|
149
|
+
undefined,
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const getArguments = (props: {
|
|
155
|
+
project: INestiaProject;
|
|
156
|
+
route: ITypedHttpRoute;
|
|
157
|
+
body: boolean;
|
|
158
|
+
}): ts.Expression[] => {
|
|
159
|
+
const parameters = getSignificant(props.route, props.body);
|
|
160
|
+
if (parameters.length === 0) return [];
|
|
161
|
+
else if (props.project.config.keyword === true)
|
|
162
|
+
return [ts.factory.createIdentifier("props")];
|
|
163
|
+
return parameters.map((p) => ts.factory.createIdentifier(p.name));
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const getAccessors = (props: {
|
|
167
|
+
project: INestiaProject;
|
|
168
|
+
importer: ImportDictionary;
|
|
169
|
+
route: ITypedHttpRoute;
|
|
170
|
+
body: boolean;
|
|
171
|
+
}): ts.Expression[] => {
|
|
172
|
+
const prefix: string =
|
|
173
|
+
props.project.config.keyword === true ? "props." : "";
|
|
174
|
+
return getSignificant(props.route, props.body).map((p) =>
|
|
175
|
+
ts.factory.createIdentifier(`${prefix}${p.name}`),
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -8,29 +8,19 @@ import { FilePrinter } from "./FilePrinter";
|
|
|
8
8
|
import { ImportDictionary } from "./ImportDictionary";
|
|
9
9
|
import { SdkHttpFunctionProgrammer } from "./SdkHttpFunctionProgrammer";
|
|
10
10
|
import { SdkHttpNamespaceProgrammer } from "./SdkHttpNamespaceProgrammer";
|
|
11
|
+
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
11
12
|
|
|
12
13
|
export namespace SdkHttpRouteProgrammer {
|
|
13
14
|
export const write =
|
|
14
15
|
(project: INestiaProject) =>
|
|
15
16
|
(importer: ImportDictionary) =>
|
|
16
|
-
(route: ITypedHttpRoute): ts.Statement[] =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.find((p) => p.field === null),
|
|
24
|
-
body: route.parameters.find((p) => p.category === "body"),
|
|
25
|
-
};
|
|
26
|
-
return [
|
|
27
|
-
FilePrinter.description(
|
|
28
|
-
SdkHttpFunctionProgrammer.write(project)(importer)(route, props),
|
|
29
|
-
describe(project.config, route),
|
|
30
|
-
),
|
|
31
|
-
SdkHttpNamespaceProgrammer.write(project)(importer)(route, props),
|
|
32
|
-
];
|
|
33
|
-
};
|
|
17
|
+
(route: ITypedHttpRoute): ts.Statement[] => [
|
|
18
|
+
FilePrinter.description(
|
|
19
|
+
SdkHttpFunctionProgrammer.write(project)(importer)(route),
|
|
20
|
+
describe(project.config, route),
|
|
21
|
+
),
|
|
22
|
+
SdkHttpNamespaceProgrammer.write(project)(importer)(route),
|
|
23
|
+
];
|
|
34
24
|
|
|
35
25
|
const describe = (config: INestiaConfig, route: ITypedHttpRoute): string => {
|
|
36
26
|
// MAIN DESCRIPTION
|
|
@@ -40,9 +30,7 @@ export namespace SdkHttpRouteProgrammer {
|
|
|
40
30
|
const tagComments: string[] = [];
|
|
41
31
|
|
|
42
32
|
// PARAMETERS
|
|
43
|
-
for (const p of route
|
|
44
|
-
if (p.category === "headers") continue;
|
|
45
|
-
|
|
33
|
+
for (const p of SdkHttpParameterProgrammer.getSignificant(route, true)) {
|
|
46
34
|
const description: string | undefined =
|
|
47
35
|
p.description ??
|
|
48
36
|
p.jsDocTags.find((tag) => tag.name === "description")?.text?.[0].text ??
|