@nestia/migrate 0.7.6 → 0.7.7
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/MigrateApplication.js +7 -4
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.d.ts +2 -3
- package/lib/analyzers/MigrateAnalyzer.js +1 -5
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateControllerAnalyzer.js +22 -13
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateMethodAnalyzer.js +16 -16
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/module.d.ts +8 -0
- package/lib/module.js +8 -0
- package/lib/module.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +3 -3
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateImportProgrammer.js +5 -5
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +1 -1
- package/lib/structures/IMigrateDto.d.ts +1 -1
- package/lib/structures/IMigrateProgram.d.ts +20 -4
- package/lib/structures/IMigrateRoute.d.ts +1 -1
- package/lib/structures/ISwaggerComponents.d.ts +1 -1
- package/lib/structures/ISwaggerRoute.d.ts +1 -1
- package/lib/structures/{ISwaggeSchema.js → ISwaggerSchema.js} +1 -1
- package/lib/structures/ISwaggerSchema.js.map +1 -0
- package/lib/utils/SwaggerTypeChecker.d.ts +1 -1
- package/package.json +1 -1
- package/src/MigrateApplication.ts +54 -48
- package/src/analyzers/MigrateAnalyzer.ts +9 -13
- package/src/analyzers/MigrateControllerAnalyzer.ts +139 -122
- package/src/analyzers/MigrateMethodAnalyzer.ts +350 -348
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/executable/bundle.ts +109 -109
- package/src/internal/MigrateCommander.ts +51 -51
- package/src/module.ts +10 -0
- package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
- package/src/programmers/MigrateApiFunctionProgrammer.ts +203 -203
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +430 -430
- package/src/programmers/MigrateApiProgrammer.ts +132 -132
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +328 -328
- package/src/programmers/MigrateDtoProgrammer.ts +78 -78
- package/src/programmers/MigrateImportProgrammer.ts +114 -116
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
- package/src/programmers/MigrateNestModuleProgrammer.ts +62 -62
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/programmers/MigrateSchemaProgrammer.ts +257 -257
- package/src/structures/IMigrateDto.ts +1 -1
- package/src/structures/IMigrateProgram.ts +20 -4
- package/src/structures/IMigrateRoute.ts +46 -46
- package/src/structures/ISwaggerComponents.ts +1 -1
- package/src/structures/ISwaggerRoute.ts +1 -1
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/SwaggerTypeChecker.ts +67 -67
- package/lib/IMigrateConfig.d.ts +0 -4
- package/lib/IMigrateConfig.js +0 -3
- package/lib/IMigrateConfig.js.map +0 -1
- package/lib/structures/ISwaggeSchema.js.map +0 -1
- package/src/IMigrateConfig.ts +0 -4
- /package/lib/structures/{ISwaggeSchema.d.ts → ISwaggerSchema.d.ts} +0 -0
- /package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +0 -0
@@ -1,249 +1,249 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
-
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
|
-
|
6
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
-
import { ISwaggerSchema } from "../structures/
|
8
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
-
import { StringUtil } from "../utils/StringUtil";
|
11
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
-
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
13
|
-
|
14
|
-
export namespace MigrateNestMethodProgrammer {
|
15
|
-
export const write =
|
16
|
-
(components: ISwaggerComponents) =>
|
17
|
-
(importer: MigrateImportProgrammer) =>
|
18
|
-
(route: IMigrateRoute): ts.MethodDeclaration => {
|
19
|
-
const output: ts.TypeNode = route.success
|
20
|
-
? MigrateSchemaProgrammer.write(components)(importer)(
|
21
|
-
route.success.schema,
|
22
|
-
)
|
23
|
-
: TypeFactory.keyword("void");
|
24
|
-
|
25
|
-
const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
|
26
|
-
[
|
27
|
-
...writeMethodDecorators(components)(importer)(route),
|
28
|
-
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
|
29
|
-
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
|
30
|
-
],
|
31
|
-
undefined,
|
32
|
-
route.name,
|
33
|
-
undefined,
|
34
|
-
undefined,
|
35
|
-
writeParameters(components)(importer)(route),
|
36
|
-
ts.factory.createTypeReferenceNode("Promise", [output]),
|
37
|
-
ts.factory.createBlock(
|
38
|
-
[
|
39
|
-
...[
|
40
|
-
...route.parameters.map((p) => StringUtil.normalize(p.key)),
|
41
|
-
...(route.headers ? ["headers"] : []),
|
42
|
-
...(route.query ? ["query"] : []),
|
43
|
-
...(route.body ? ["body"] : []),
|
44
|
-
].map((str) =>
|
45
|
-
ts.factory.createExpressionStatement(
|
46
|
-
ts.factory.createIdentifier(str),
|
47
|
-
),
|
48
|
-
),
|
49
|
-
ts.factory.createReturnStatement(
|
50
|
-
ts.factory.createCallExpression(
|
51
|
-
IdentifierFactory.access(
|
52
|
-
ts.factory.createIdentifier(
|
53
|
-
importer.external({
|
54
|
-
type: "default",
|
55
|
-
library: "typia",
|
56
|
-
name: "typia",
|
57
|
-
}),
|
58
|
-
),
|
59
|
-
)("random"),
|
60
|
-
[output],
|
61
|
-
undefined,
|
62
|
-
),
|
63
|
-
),
|
64
|
-
],
|
65
|
-
true,
|
66
|
-
),
|
67
|
-
);
|
68
|
-
return FilePrinter.description(method, writeDescription(route));
|
69
|
-
};
|
70
|
-
|
71
|
-
const writeDescription = (method: IMigrateRoute): string =>
|
72
|
-
[
|
73
|
-
...(method.description?.length ? [method.description.length, ""] : []),
|
74
|
-
...(method.deprecated ? ["@deprecated"] : []),
|
75
|
-
...method.tags.map((value) => `@tag ${value}`),
|
76
|
-
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
77
|
-
].join("\n");
|
78
|
-
|
79
|
-
const writeMethodDecorators =
|
80
|
-
(components: ISwaggerComponents) =>
|
81
|
-
(importer: MigrateImportProgrammer) =>
|
82
|
-
(route: IMigrateRoute): ts.Decorator[] => {
|
83
|
-
const external =
|
84
|
-
(lib: string) =>
|
85
|
-
(instance: string): ts.Identifier =>
|
86
|
-
ts.factory.createIdentifier(
|
87
|
-
importer.external({
|
88
|
-
type: "instance",
|
89
|
-
library: lib,
|
90
|
-
name: instance,
|
91
|
-
}),
|
92
|
-
);
|
93
|
-
const router = (instance: string) =>
|
94
|
-
ts.factory.createDecorator(
|
95
|
-
ts.factory.createCallExpression(
|
96
|
-
IdentifierFactory.access(external("@nestia/core")(instance))(
|
97
|
-
StringUtil.capitalize(route.method),
|
98
|
-
),
|
99
|
-
[],
|
100
|
-
[ts.factory.createStringLiteral(route.path)],
|
101
|
-
),
|
102
|
-
);
|
103
|
-
|
104
|
-
const decorators: ts.Decorator[] = [];
|
105
|
-
if (route.success?.["x-nestia-encrypted"])
|
106
|
-
decorators.push(router("EncryptedRoute"));
|
107
|
-
else if (route.success?.type === "text/plain")
|
108
|
-
decorators.push(
|
109
|
-
ts.factory.createDecorator(
|
110
|
-
ts.factory.createCallExpression(
|
111
|
-
external("@nestjs/common")(StringUtil.capitalize(route.method)),
|
112
|
-
[],
|
113
|
-
[ts.factory.createStringLiteral(route.path)],
|
114
|
-
),
|
115
|
-
),
|
116
|
-
);
|
117
|
-
else if (route.success?.type === "application/x-www-form-urlencoded")
|
118
|
-
decorators.push(router("TypedQuery"));
|
119
|
-
else if (route.success?.type === "application/json")
|
120
|
-
decorators.push(router("TypedRoute"));
|
121
|
-
else if (route.method === "head")
|
122
|
-
decorators.push(
|
123
|
-
ts.factory.createDecorator(
|
124
|
-
ts.factory.createCallExpression(
|
125
|
-
external("@nestjs/common")("Head"),
|
126
|
-
[],
|
127
|
-
[ts.factory.createStringLiteral(route.path)],
|
128
|
-
),
|
129
|
-
),
|
130
|
-
);
|
131
|
-
for (const [key, value] of Object.entries(route.exceptions ?? {}))
|
132
|
-
decorators.push(
|
133
|
-
ts.factory.createDecorator(
|
134
|
-
ts.factory.createCallExpression(
|
135
|
-
external("@nestia/core")("TypedException"),
|
136
|
-
[
|
137
|
-
MigrateSchemaProgrammer.write(components)(importer)(
|
138
|
-
value.schema,
|
139
|
-
),
|
140
|
-
],
|
141
|
-
[
|
142
|
-
isNaN(Number(key))
|
143
|
-
? ts.factory.createStringLiteral(key)
|
144
|
-
: ExpressionFactory.number(Number(key)),
|
145
|
-
...(value.description?.length
|
146
|
-
? [ts.factory.createStringLiteral(value.description)]
|
147
|
-
: []),
|
148
|
-
],
|
149
|
-
),
|
150
|
-
),
|
151
|
-
);
|
152
|
-
return decorators;
|
153
|
-
};
|
154
|
-
|
155
|
-
const writeParameters =
|
156
|
-
(components: ISwaggerComponents) =>
|
157
|
-
(importer: MigrateImportProgrammer) =>
|
158
|
-
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
159
|
-
...route.parameters.map(({ key, schema: value }) =>
|
160
|
-
ts.factory.createParameterDeclaration(
|
161
|
-
[
|
162
|
-
ts.factory.createDecorator(
|
163
|
-
ts.factory.createCallExpression(
|
164
|
-
ts.factory.createIdentifier(
|
165
|
-
importer.external({
|
166
|
-
type: "instance",
|
167
|
-
library: "@nestia/core",
|
168
|
-
name: "TypedParam",
|
169
|
-
}),
|
170
|
-
),
|
171
|
-
undefined,
|
172
|
-
[ts.factory.createStringLiteral(key)],
|
173
|
-
),
|
174
|
-
),
|
175
|
-
],
|
176
|
-
undefined,
|
177
|
-
StringUtil.normalize(key),
|
178
|
-
undefined,
|
179
|
-
MigrateSchemaProgrammer.write(components)(importer)(value),
|
180
|
-
),
|
181
|
-
),
|
182
|
-
...(route.headers
|
183
|
-
? [
|
184
|
-
writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
|
185
|
-
components,
|
186
|
-
)(importer)(route.headers.schema),
|
187
|
-
]
|
188
|
-
: []),
|
189
|
-
...(route.query
|
190
|
-
? [
|
191
|
-
writeDtoParameter({ method: "TypedQuery", variable: "query" })(
|
192
|
-
components,
|
193
|
-
)(importer)(route.query.schema),
|
194
|
-
]
|
195
|
-
: []),
|
196
|
-
...(route.body
|
197
|
-
? [
|
198
|
-
writeDtoParameter({
|
199
|
-
method: route.body["x-nestia-encrypted"]
|
200
|
-
? "EncryptedBody"
|
201
|
-
: route.body.type === "application/json"
|
202
|
-
? "TypedBody"
|
203
|
-
: route.body.type === "application/x-www-form-urlencoded"
|
204
|
-
? ["TypedQuery", "Body"]
|
205
|
-
: route.body.type === "text/plain"
|
206
|
-
? "PlainBody"
|
207
|
-
: route.body.type === "multipart/form-data"
|
208
|
-
? ["TypedFormData", "Body"]
|
209
|
-
: "TypedBody",
|
210
|
-
variable: "body",
|
211
|
-
})(components)(importer)(route.body.schema),
|
212
|
-
]
|
213
|
-
: []),
|
214
|
-
];
|
215
|
-
|
216
|
-
const writeDtoParameter =
|
217
|
-
(accessor: { method: string | [string, string]; variable: string }) =>
|
218
|
-
(components: ISwaggerComponents) =>
|
219
|
-
(importer: MigrateImportProgrammer) =>
|
220
|
-
(schema: ISwaggerSchema): ts.ParameterDeclaration => {
|
221
|
-
const instance = ts.factory.createIdentifier(
|
222
|
-
importer.external({
|
223
|
-
type: "instance",
|
224
|
-
library: "@nestia/core",
|
225
|
-
name:
|
226
|
-
typeof accessor.method === "string"
|
227
|
-
? accessor.method
|
228
|
-
: accessor.method[0],
|
229
|
-
}),
|
230
|
-
);
|
231
|
-
return ts.factory.createParameterDeclaration(
|
232
|
-
[
|
233
|
-
ts.factory.createDecorator(
|
234
|
-
ts.factory.createCallExpression(
|
235
|
-
typeof accessor.method === "string"
|
236
|
-
? instance
|
237
|
-
: IdentifierFactory.access(instance)(accessor.method[1]),
|
238
|
-
undefined,
|
239
|
-
undefined,
|
240
|
-
),
|
241
|
-
),
|
242
|
-
],
|
243
|
-
undefined,
|
244
|
-
StringUtil.normalize(accessor.variable),
|
245
|
-
undefined,
|
246
|
-
MigrateSchemaProgrammer.write(components)(importer)(schema),
|
247
|
-
);
|
248
|
-
};
|
249
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
|
+
|
6
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
+
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
8
|
+
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
+
import { StringUtil } from "../utils/StringUtil";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
13
|
+
|
14
|
+
export namespace MigrateNestMethodProgrammer {
|
15
|
+
export const write =
|
16
|
+
(components: ISwaggerComponents) =>
|
17
|
+
(importer: MigrateImportProgrammer) =>
|
18
|
+
(route: IMigrateRoute): ts.MethodDeclaration => {
|
19
|
+
const output: ts.TypeNode = route.success
|
20
|
+
? MigrateSchemaProgrammer.write(components)(importer)(
|
21
|
+
route.success.schema,
|
22
|
+
)
|
23
|
+
: TypeFactory.keyword("void");
|
24
|
+
|
25
|
+
const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
|
26
|
+
[
|
27
|
+
...writeMethodDecorators(components)(importer)(route),
|
28
|
+
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
|
29
|
+
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
|
30
|
+
],
|
31
|
+
undefined,
|
32
|
+
route.name,
|
33
|
+
undefined,
|
34
|
+
undefined,
|
35
|
+
writeParameters(components)(importer)(route),
|
36
|
+
ts.factory.createTypeReferenceNode("Promise", [output]),
|
37
|
+
ts.factory.createBlock(
|
38
|
+
[
|
39
|
+
...[
|
40
|
+
...route.parameters.map((p) => StringUtil.normalize(p.key)),
|
41
|
+
...(route.headers ? ["headers"] : []),
|
42
|
+
...(route.query ? ["query"] : []),
|
43
|
+
...(route.body ? ["body"] : []),
|
44
|
+
].map((str) =>
|
45
|
+
ts.factory.createExpressionStatement(
|
46
|
+
ts.factory.createIdentifier(str),
|
47
|
+
),
|
48
|
+
),
|
49
|
+
ts.factory.createReturnStatement(
|
50
|
+
ts.factory.createCallExpression(
|
51
|
+
IdentifierFactory.access(
|
52
|
+
ts.factory.createIdentifier(
|
53
|
+
importer.external({
|
54
|
+
type: "default",
|
55
|
+
library: "typia",
|
56
|
+
name: "typia",
|
57
|
+
}),
|
58
|
+
),
|
59
|
+
)("random"),
|
60
|
+
[output],
|
61
|
+
undefined,
|
62
|
+
),
|
63
|
+
),
|
64
|
+
],
|
65
|
+
true,
|
66
|
+
),
|
67
|
+
);
|
68
|
+
return FilePrinter.description(method, writeDescription(route));
|
69
|
+
};
|
70
|
+
|
71
|
+
const writeDescription = (method: IMigrateRoute): string =>
|
72
|
+
[
|
73
|
+
...(method.description?.length ? [method.description.length, ""] : []),
|
74
|
+
...(method.deprecated ? ["@deprecated"] : []),
|
75
|
+
...method.tags.map((value) => `@tag ${value}`),
|
76
|
+
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
77
|
+
].join("\n");
|
78
|
+
|
79
|
+
const writeMethodDecorators =
|
80
|
+
(components: ISwaggerComponents) =>
|
81
|
+
(importer: MigrateImportProgrammer) =>
|
82
|
+
(route: IMigrateRoute): ts.Decorator[] => {
|
83
|
+
const external =
|
84
|
+
(lib: string) =>
|
85
|
+
(instance: string): ts.Identifier =>
|
86
|
+
ts.factory.createIdentifier(
|
87
|
+
importer.external({
|
88
|
+
type: "instance",
|
89
|
+
library: lib,
|
90
|
+
name: instance,
|
91
|
+
}),
|
92
|
+
);
|
93
|
+
const router = (instance: string) =>
|
94
|
+
ts.factory.createDecorator(
|
95
|
+
ts.factory.createCallExpression(
|
96
|
+
IdentifierFactory.access(external("@nestia/core")(instance))(
|
97
|
+
StringUtil.capitalize(route.method),
|
98
|
+
),
|
99
|
+
[],
|
100
|
+
[ts.factory.createStringLiteral(route.path)],
|
101
|
+
),
|
102
|
+
);
|
103
|
+
|
104
|
+
const decorators: ts.Decorator[] = [];
|
105
|
+
if (route.success?.["x-nestia-encrypted"])
|
106
|
+
decorators.push(router("EncryptedRoute"));
|
107
|
+
else if (route.success?.type === "text/plain")
|
108
|
+
decorators.push(
|
109
|
+
ts.factory.createDecorator(
|
110
|
+
ts.factory.createCallExpression(
|
111
|
+
external("@nestjs/common")(StringUtil.capitalize(route.method)),
|
112
|
+
[],
|
113
|
+
[ts.factory.createStringLiteral(route.path)],
|
114
|
+
),
|
115
|
+
),
|
116
|
+
);
|
117
|
+
else if (route.success?.type === "application/x-www-form-urlencoded")
|
118
|
+
decorators.push(router("TypedQuery"));
|
119
|
+
else if (route.success?.type === "application/json")
|
120
|
+
decorators.push(router("TypedRoute"));
|
121
|
+
else if (route.method === "head")
|
122
|
+
decorators.push(
|
123
|
+
ts.factory.createDecorator(
|
124
|
+
ts.factory.createCallExpression(
|
125
|
+
external("@nestjs/common")("Head"),
|
126
|
+
[],
|
127
|
+
[ts.factory.createStringLiteral(route.path)],
|
128
|
+
),
|
129
|
+
),
|
130
|
+
);
|
131
|
+
for (const [key, value] of Object.entries(route.exceptions ?? {}))
|
132
|
+
decorators.push(
|
133
|
+
ts.factory.createDecorator(
|
134
|
+
ts.factory.createCallExpression(
|
135
|
+
external("@nestia/core")("TypedException"),
|
136
|
+
[
|
137
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
138
|
+
value.schema,
|
139
|
+
),
|
140
|
+
],
|
141
|
+
[
|
142
|
+
isNaN(Number(key))
|
143
|
+
? ts.factory.createStringLiteral(key)
|
144
|
+
: ExpressionFactory.number(Number(key)),
|
145
|
+
...(value.description?.length
|
146
|
+
? [ts.factory.createStringLiteral(value.description)]
|
147
|
+
: []),
|
148
|
+
],
|
149
|
+
),
|
150
|
+
),
|
151
|
+
);
|
152
|
+
return decorators;
|
153
|
+
};
|
154
|
+
|
155
|
+
const writeParameters =
|
156
|
+
(components: ISwaggerComponents) =>
|
157
|
+
(importer: MigrateImportProgrammer) =>
|
158
|
+
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
159
|
+
...route.parameters.map(({ key, schema: value }) =>
|
160
|
+
ts.factory.createParameterDeclaration(
|
161
|
+
[
|
162
|
+
ts.factory.createDecorator(
|
163
|
+
ts.factory.createCallExpression(
|
164
|
+
ts.factory.createIdentifier(
|
165
|
+
importer.external({
|
166
|
+
type: "instance",
|
167
|
+
library: "@nestia/core",
|
168
|
+
name: "TypedParam",
|
169
|
+
}),
|
170
|
+
),
|
171
|
+
undefined,
|
172
|
+
[ts.factory.createStringLiteral(key)],
|
173
|
+
),
|
174
|
+
),
|
175
|
+
],
|
176
|
+
undefined,
|
177
|
+
StringUtil.normalize(key),
|
178
|
+
undefined,
|
179
|
+
MigrateSchemaProgrammer.write(components)(importer)(value),
|
180
|
+
),
|
181
|
+
),
|
182
|
+
...(route.headers
|
183
|
+
? [
|
184
|
+
writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
|
185
|
+
components,
|
186
|
+
)(importer)(route.headers.schema),
|
187
|
+
]
|
188
|
+
: []),
|
189
|
+
...(route.query
|
190
|
+
? [
|
191
|
+
writeDtoParameter({ method: "TypedQuery", variable: "query" })(
|
192
|
+
components,
|
193
|
+
)(importer)(route.query.schema),
|
194
|
+
]
|
195
|
+
: []),
|
196
|
+
...(route.body
|
197
|
+
? [
|
198
|
+
writeDtoParameter({
|
199
|
+
method: route.body["x-nestia-encrypted"]
|
200
|
+
? "EncryptedBody"
|
201
|
+
: route.body.type === "application/json"
|
202
|
+
? "TypedBody"
|
203
|
+
: route.body.type === "application/x-www-form-urlencoded"
|
204
|
+
? ["TypedQuery", "Body"]
|
205
|
+
: route.body.type === "text/plain"
|
206
|
+
? "PlainBody"
|
207
|
+
: route.body.type === "multipart/form-data"
|
208
|
+
? ["TypedFormData", "Body"]
|
209
|
+
: "TypedBody",
|
210
|
+
variable: "body",
|
211
|
+
})(components)(importer)(route.body.schema),
|
212
|
+
]
|
213
|
+
: []),
|
214
|
+
];
|
215
|
+
|
216
|
+
const writeDtoParameter =
|
217
|
+
(accessor: { method: string | [string, string]; variable: string }) =>
|
218
|
+
(components: ISwaggerComponents) =>
|
219
|
+
(importer: MigrateImportProgrammer) =>
|
220
|
+
(schema: ISwaggerSchema): ts.ParameterDeclaration => {
|
221
|
+
const instance = ts.factory.createIdentifier(
|
222
|
+
importer.external({
|
223
|
+
type: "instance",
|
224
|
+
library: "@nestia/core",
|
225
|
+
name:
|
226
|
+
typeof accessor.method === "string"
|
227
|
+
? accessor.method
|
228
|
+
: accessor.method[0],
|
229
|
+
}),
|
230
|
+
);
|
231
|
+
return ts.factory.createParameterDeclaration(
|
232
|
+
[
|
233
|
+
ts.factory.createDecorator(
|
234
|
+
ts.factory.createCallExpression(
|
235
|
+
typeof accessor.method === "string"
|
236
|
+
? instance
|
237
|
+
: IdentifierFactory.access(instance)(accessor.method[1]),
|
238
|
+
undefined,
|
239
|
+
undefined,
|
240
|
+
),
|
241
|
+
),
|
242
|
+
],
|
243
|
+
undefined,
|
244
|
+
StringUtil.normalize(accessor.variable),
|
245
|
+
undefined,
|
246
|
+
MigrateSchemaProgrammer.write(components)(importer)(schema),
|
247
|
+
);
|
248
|
+
};
|
249
|
+
}
|
@@ -1,62 +1,62 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
4
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
5
|
-
|
6
|
-
export namespace MigrateNestModuleProgrammer {
|
7
|
-
export const write = (controllers: IMigrateController[]): ts.Statement[] => [
|
8
|
-
$import("@nestjs/common")("Module"),
|
9
|
-
...(controllers.length ? [FilePrinter.newLine()] : []),
|
10
|
-
...controllers.map((c) =>
|
11
|
-
$import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
|
12
|
-
),
|
13
|
-
...(controllers.length ? [FilePrinter.newLine()] : []),
|
14
|
-
ts.factory.createClassDeclaration(
|
15
|
-
[
|
16
|
-
ts.factory.createDecorator(
|
17
|
-
ts.factory.createCallExpression(
|
18
|
-
ts.factory.createIdentifier("Module"),
|
19
|
-
undefined,
|
20
|
-
[
|
21
|
-
ts.factory.createObjectLiteralExpression(
|
22
|
-
[
|
23
|
-
ts.factory.createPropertyAssignment(
|
24
|
-
ts.factory.createIdentifier("controllers"),
|
25
|
-
ts.factory.createArrayLiteralExpression(
|
26
|
-
controllers.map((c) =>
|
27
|
-
ts.factory.createIdentifier(c.name),
|
28
|
-
),
|
29
|
-
),
|
30
|
-
),
|
31
|
-
],
|
32
|
-
true,
|
33
|
-
),
|
34
|
-
],
|
35
|
-
),
|
36
|
-
),
|
37
|
-
ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
|
38
|
-
],
|
39
|
-
"MyModule",
|
40
|
-
undefined,
|
41
|
-
undefined,
|
42
|
-
[],
|
43
|
-
),
|
44
|
-
];
|
45
|
-
}
|
46
|
-
|
47
|
-
const $import = (file: string) => (instance: string) =>
|
48
|
-
ts.factory.createImportDeclaration(
|
49
|
-
undefined,
|
50
|
-
ts.factory.createImportClause(
|
51
|
-
false,
|
52
|
-
undefined,
|
53
|
-
ts.factory.createNamedImports([
|
54
|
-
ts.factory.createImportSpecifier(
|
55
|
-
false,
|
56
|
-
undefined,
|
57
|
-
ts.factory.createIdentifier(instance),
|
58
|
-
),
|
59
|
-
]),
|
60
|
-
),
|
61
|
-
ts.factory.createStringLiteral(file),
|
62
|
-
);
|
1
|
+
import ts from "typescript";
|
2
|
+
|
3
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
4
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
5
|
+
|
6
|
+
export namespace MigrateNestModuleProgrammer {
|
7
|
+
export const write = (controllers: IMigrateController[]): ts.Statement[] => [
|
8
|
+
$import("@nestjs/common")("Module"),
|
9
|
+
...(controllers.length ? [FilePrinter.newLine()] : []),
|
10
|
+
...controllers.map((c) =>
|
11
|
+
$import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
|
12
|
+
),
|
13
|
+
...(controllers.length ? [FilePrinter.newLine()] : []),
|
14
|
+
ts.factory.createClassDeclaration(
|
15
|
+
[
|
16
|
+
ts.factory.createDecorator(
|
17
|
+
ts.factory.createCallExpression(
|
18
|
+
ts.factory.createIdentifier("Module"),
|
19
|
+
undefined,
|
20
|
+
[
|
21
|
+
ts.factory.createObjectLiteralExpression(
|
22
|
+
[
|
23
|
+
ts.factory.createPropertyAssignment(
|
24
|
+
ts.factory.createIdentifier("controllers"),
|
25
|
+
ts.factory.createArrayLiteralExpression(
|
26
|
+
controllers.map((c) =>
|
27
|
+
ts.factory.createIdentifier(c.name),
|
28
|
+
),
|
29
|
+
),
|
30
|
+
),
|
31
|
+
],
|
32
|
+
true,
|
33
|
+
),
|
34
|
+
],
|
35
|
+
),
|
36
|
+
),
|
37
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
|
38
|
+
],
|
39
|
+
"MyModule",
|
40
|
+
undefined,
|
41
|
+
undefined,
|
42
|
+
[],
|
43
|
+
),
|
44
|
+
];
|
45
|
+
}
|
46
|
+
|
47
|
+
const $import = (file: string) => (instance: string) =>
|
48
|
+
ts.factory.createImportDeclaration(
|
49
|
+
undefined,
|
50
|
+
ts.factory.createImportClause(
|
51
|
+
false,
|
52
|
+
undefined,
|
53
|
+
ts.factory.createNamedImports([
|
54
|
+
ts.factory.createImportSpecifier(
|
55
|
+
false,
|
56
|
+
undefined,
|
57
|
+
ts.factory.createIdentifier(instance),
|
58
|
+
),
|
59
|
+
]),
|
60
|
+
),
|
61
|
+
ts.factory.createStringLiteral(file),
|
62
|
+
);
|