@nestia/migrate 0.13.0 → 0.13.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/lib/MigrateApplication.js +45 -9
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.js +3 -4
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
- package/package.json +79 -79
- package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
- package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/internal/MigrateCommander.ts +76 -70
- package/src/module.ts +8 -8
- package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
- package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
- package/src/programmers/MigrateApiProgrammer.ts +172 -172
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
- package/src/programmers/MigrateDtoProgrammer.ts +77 -77
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +36 -36
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateProgram.ts +27 -27
- package/src/structures/IMigrateRoute.ts +51 -51
- package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -1,249 +1,249 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
4
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
5
|
-
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
6
|
-
|
7
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
-
import { StringUtil } from "../utils/StringUtil";
|
10
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
11
|
-
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
12
|
-
|
13
|
-
export namespace MigrateNestMethodProgrammer {
|
14
|
-
export const write =
|
15
|
-
(components: OpenApi.IComponents) =>
|
16
|
-
(importer: MigrateImportProgrammer) =>
|
17
|
-
(route: IMigrateRoute): ts.MethodDeclaration => {
|
18
|
-
const output: ts.TypeNode = route.success
|
19
|
-
? MigrateSchemaProgrammer.write(components)(importer)(
|
20
|
-
route.success.schema,
|
21
|
-
)
|
22
|
-
: TypeFactory.keyword("void");
|
23
|
-
|
24
|
-
const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
|
25
|
-
[
|
26
|
-
...writeMethodDecorators(components)(importer)(route),
|
27
|
-
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
|
28
|
-
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
|
29
|
-
],
|
30
|
-
undefined,
|
31
|
-
route.name,
|
32
|
-
undefined,
|
33
|
-
undefined,
|
34
|
-
writeParameters(components)(importer)(route),
|
35
|
-
ts.factory.createTypeReferenceNode("Promise", [output]),
|
36
|
-
ts.factory.createBlock(
|
37
|
-
[
|
38
|
-
...[
|
39
|
-
...route.parameters.map((p) => StringUtil.normalize(p.key)),
|
40
|
-
...(route.headers ? ["headers"] : []),
|
41
|
-
...(route.query ? ["query"] : []),
|
42
|
-
...(route.body ? ["body"] : []),
|
43
|
-
].map((str) =>
|
44
|
-
ts.factory.createExpressionStatement(
|
45
|
-
ts.factory.createIdentifier(str),
|
46
|
-
),
|
47
|
-
),
|
48
|
-
ts.factory.createReturnStatement(
|
49
|
-
ts.factory.createCallExpression(
|
50
|
-
IdentifierFactory.access(
|
51
|
-
ts.factory.createIdentifier(
|
52
|
-
importer.external({
|
53
|
-
type: "default",
|
54
|
-
library: "typia",
|
55
|
-
name: "typia",
|
56
|
-
}),
|
57
|
-
),
|
58
|
-
)("random"),
|
59
|
-
[output],
|
60
|
-
undefined,
|
61
|
-
),
|
62
|
-
),
|
63
|
-
],
|
64
|
-
true,
|
65
|
-
),
|
66
|
-
);
|
67
|
-
return FilePrinter.description(method, writeDescription(route));
|
68
|
-
};
|
69
|
-
|
70
|
-
const writeDescription = (method: IMigrateRoute): string =>
|
71
|
-
[
|
72
|
-
method.comment(),
|
73
|
-
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
74
|
-
].join("\n");
|
75
|
-
|
76
|
-
const writeMethodDecorators =
|
77
|
-
(components: OpenApi.IComponents) =>
|
78
|
-
(importer: MigrateImportProgrammer) =>
|
79
|
-
(route: IMigrateRoute): ts.Decorator[] => {
|
80
|
-
const external =
|
81
|
-
(lib: string) =>
|
82
|
-
(instance: string): ts.Identifier =>
|
83
|
-
ts.factory.createIdentifier(
|
84
|
-
importer.external({
|
85
|
-
type: "instance",
|
86
|
-
library: lib,
|
87
|
-
name: instance,
|
88
|
-
}),
|
89
|
-
);
|
90
|
-
const router = (instance: string) =>
|
91
|
-
ts.factory.createDecorator(
|
92
|
-
ts.factory.createCallExpression(
|
93
|
-
IdentifierFactory.access(external("@nestia/core")(instance))(
|
94
|
-
StringUtil.capitalize(route.method),
|
95
|
-
),
|
96
|
-
[],
|
97
|
-
[ts.factory.createStringLiteral(route.path)],
|
98
|
-
),
|
99
|
-
);
|
100
|
-
|
101
|
-
const decorators: ts.Decorator[] = [];
|
102
|
-
if (route.success?.["x-nestia-encrypted"])
|
103
|
-
decorators.push(router("EncryptedRoute"));
|
104
|
-
else if (route.success?.type === "text/plain")
|
105
|
-
decorators.push(
|
106
|
-
ts.factory.createDecorator(
|
107
|
-
ts.factory.createCallExpression(
|
108
|
-
external("@nestjs/common")(StringUtil.capitalize(route.method)),
|
109
|
-
[],
|
110
|
-
[ts.factory.createStringLiteral(route.path)],
|
111
|
-
),
|
112
|
-
),
|
113
|
-
);
|
114
|
-
else if (route.success?.type === "application/x-www-form-urlencoded")
|
115
|
-
decorators.push(router("TypedQuery"));
|
116
|
-
else if (route.method === "head")
|
117
|
-
decorators.push(
|
118
|
-
ts.factory.createDecorator(
|
119
|
-
ts.factory.createCallExpression(
|
120
|
-
external("@nestjs/common")("Head"),
|
121
|
-
[],
|
122
|
-
[ts.factory.createStringLiteral(route.path)],
|
123
|
-
),
|
124
|
-
),
|
125
|
-
);
|
126
|
-
else if (
|
127
|
-
route.success === null ||
|
128
|
-
route.success?.type === "application/json"
|
129
|
-
)
|
130
|
-
decorators.push(router("TypedRoute"));
|
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: OpenApi.IComponents) =>
|
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: OpenApi.IComponents) =>
|
219
|
-
(importer: MigrateImportProgrammer) =>
|
220
|
-
(schema: OpenApi.IJsonSchema): 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 { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
4
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
5
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
6
|
+
|
7
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
+
import { StringUtil } from "../utils/StringUtil";
|
10
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
11
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
12
|
+
|
13
|
+
export namespace MigrateNestMethodProgrammer {
|
14
|
+
export const write =
|
15
|
+
(components: OpenApi.IComponents) =>
|
16
|
+
(importer: MigrateImportProgrammer) =>
|
17
|
+
(route: IMigrateRoute): ts.MethodDeclaration => {
|
18
|
+
const output: ts.TypeNode = route.success
|
19
|
+
? MigrateSchemaProgrammer.write(components)(importer)(
|
20
|
+
route.success.schema,
|
21
|
+
)
|
22
|
+
: TypeFactory.keyword("void");
|
23
|
+
|
24
|
+
const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
|
25
|
+
[
|
26
|
+
...writeMethodDecorators(components)(importer)(route),
|
27
|
+
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
|
28
|
+
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
|
29
|
+
],
|
30
|
+
undefined,
|
31
|
+
route.name,
|
32
|
+
undefined,
|
33
|
+
undefined,
|
34
|
+
writeParameters(components)(importer)(route),
|
35
|
+
ts.factory.createTypeReferenceNode("Promise", [output]),
|
36
|
+
ts.factory.createBlock(
|
37
|
+
[
|
38
|
+
...[
|
39
|
+
...route.parameters.map((p) => StringUtil.normalize(p.key)),
|
40
|
+
...(route.headers ? ["headers"] : []),
|
41
|
+
...(route.query ? ["query"] : []),
|
42
|
+
...(route.body ? ["body"] : []),
|
43
|
+
].map((str) =>
|
44
|
+
ts.factory.createExpressionStatement(
|
45
|
+
ts.factory.createIdentifier(str),
|
46
|
+
),
|
47
|
+
),
|
48
|
+
ts.factory.createReturnStatement(
|
49
|
+
ts.factory.createCallExpression(
|
50
|
+
IdentifierFactory.access(
|
51
|
+
ts.factory.createIdentifier(
|
52
|
+
importer.external({
|
53
|
+
type: "default",
|
54
|
+
library: "typia",
|
55
|
+
name: "typia",
|
56
|
+
}),
|
57
|
+
),
|
58
|
+
)("random"),
|
59
|
+
[output],
|
60
|
+
undefined,
|
61
|
+
),
|
62
|
+
),
|
63
|
+
],
|
64
|
+
true,
|
65
|
+
),
|
66
|
+
);
|
67
|
+
return FilePrinter.description(method, writeDescription(route));
|
68
|
+
};
|
69
|
+
|
70
|
+
const writeDescription = (method: IMigrateRoute): string =>
|
71
|
+
[
|
72
|
+
method.comment(),
|
73
|
+
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
74
|
+
].join("\n");
|
75
|
+
|
76
|
+
const writeMethodDecorators =
|
77
|
+
(components: OpenApi.IComponents) =>
|
78
|
+
(importer: MigrateImportProgrammer) =>
|
79
|
+
(route: IMigrateRoute): ts.Decorator[] => {
|
80
|
+
const external =
|
81
|
+
(lib: string) =>
|
82
|
+
(instance: string): ts.Identifier =>
|
83
|
+
ts.factory.createIdentifier(
|
84
|
+
importer.external({
|
85
|
+
type: "instance",
|
86
|
+
library: lib,
|
87
|
+
name: instance,
|
88
|
+
}),
|
89
|
+
);
|
90
|
+
const router = (instance: string) =>
|
91
|
+
ts.factory.createDecorator(
|
92
|
+
ts.factory.createCallExpression(
|
93
|
+
IdentifierFactory.access(external("@nestia/core")(instance))(
|
94
|
+
StringUtil.capitalize(route.method),
|
95
|
+
),
|
96
|
+
[],
|
97
|
+
[ts.factory.createStringLiteral(route.path)],
|
98
|
+
),
|
99
|
+
);
|
100
|
+
|
101
|
+
const decorators: ts.Decorator[] = [];
|
102
|
+
if (route.success?.["x-nestia-encrypted"])
|
103
|
+
decorators.push(router("EncryptedRoute"));
|
104
|
+
else if (route.success?.type === "text/plain")
|
105
|
+
decorators.push(
|
106
|
+
ts.factory.createDecorator(
|
107
|
+
ts.factory.createCallExpression(
|
108
|
+
external("@nestjs/common")(StringUtil.capitalize(route.method)),
|
109
|
+
[],
|
110
|
+
[ts.factory.createStringLiteral(route.path)],
|
111
|
+
),
|
112
|
+
),
|
113
|
+
);
|
114
|
+
else if (route.success?.type === "application/x-www-form-urlencoded")
|
115
|
+
decorators.push(router("TypedQuery"));
|
116
|
+
else if (route.method === "head")
|
117
|
+
decorators.push(
|
118
|
+
ts.factory.createDecorator(
|
119
|
+
ts.factory.createCallExpression(
|
120
|
+
external("@nestjs/common")("Head"),
|
121
|
+
[],
|
122
|
+
[ts.factory.createStringLiteral(route.path)],
|
123
|
+
),
|
124
|
+
),
|
125
|
+
);
|
126
|
+
else if (
|
127
|
+
route.success === null ||
|
128
|
+
route.success?.type === "application/json"
|
129
|
+
)
|
130
|
+
decorators.push(router("TypedRoute"));
|
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: OpenApi.IComponents) =>
|
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: OpenApi.IComponents) =>
|
219
|
+
(importer: MigrateImportProgrammer) =>
|
220
|
+
(schema: OpenApi.IJsonSchema): 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,74 +1,74 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
4
|
-
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
6
|
-
import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
|
7
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
8
|
-
import { MigrateNestControllerProgrammer } from "./MigrateNestControllerProgrammer";
|
9
|
-
import { MigrateNestModuleProgrammer } from "./MigrateNestModuleProgrammer";
|
10
|
-
|
11
|
-
export namespace MigrateNestProgrammer {
|
12
|
-
export const write = (program: IMigrateProgram): IMigrateFile[] =>
|
13
|
-
[
|
14
|
-
{
|
15
|
-
location: "src",
|
16
|
-
file: "MyModule.ts",
|
17
|
-
statements: MigrateNestModuleProgrammer.write(program.controllers),
|
18
|
-
},
|
19
|
-
...program.controllers.map((c) => ({
|
20
|
-
location: c.location,
|
21
|
-
file: `${c.name}.ts`,
|
22
|
-
statements: MigrateNestControllerProgrammer.write(
|
23
|
-
program.document.components,
|
24
|
-
)(c),
|
25
|
-
})),
|
26
|
-
...[
|
27
|
-
...MigrateDtoProgrammer.compose(program.document.components).entries(),
|
28
|
-
].map(([key, value]) => ({
|
29
|
-
location: "src/api/structures",
|
30
|
-
file: `${key}.ts`,
|
31
|
-
statements: writeDtoFile(key, value),
|
32
|
-
})),
|
33
|
-
].map((o) => ({
|
34
|
-
location: o.location,
|
35
|
-
file: o.file,
|
36
|
-
content: FilePrinter.write({ statements: o.statements }),
|
37
|
-
}));
|
38
|
-
|
39
|
-
const writeDtoFile = (
|
40
|
-
key: string,
|
41
|
-
modulo: MigrateDtoProgrammer.IModule,
|
42
|
-
): ts.Statement[] => {
|
43
|
-
const importer = new MigrateImportProgrammer();
|
44
|
-
const statements: ts.Statement[] = iterate(importer)(modulo);
|
45
|
-
if (statements.length === 0) return [];
|
46
|
-
|
47
|
-
return [
|
48
|
-
...importer.toStatements((name) => `./${name}`, key),
|
49
|
-
...(importer.empty() ? [] : [FilePrinter.newLine()]),
|
50
|
-
...statements,
|
51
|
-
];
|
52
|
-
};
|
53
|
-
|
54
|
-
const iterate =
|
55
|
-
(importer: MigrateImportProgrammer) =>
|
56
|
-
(modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
|
57
|
-
const output: ts.Statement[] = [];
|
58
|
-
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
59
|
-
if (modulo.children.size) {
|
60
|
-
const internal: ts.Statement[] = [];
|
61
|
-
for (const child of modulo.children.values())
|
62
|
-
internal.push(...iterate(importer)(child));
|
63
|
-
output.push(
|
64
|
-
ts.factory.createModuleDeclaration(
|
65
|
-
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
66
|
-
ts.factory.createIdentifier(modulo.name),
|
67
|
-
ts.factory.createModuleBlock(internal),
|
68
|
-
ts.NodeFlags.Namespace,
|
69
|
-
),
|
70
|
-
);
|
71
|
-
}
|
72
|
-
return output;
|
73
|
-
};
|
74
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
|
3
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
4
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
6
|
+
import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
|
7
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
8
|
+
import { MigrateNestControllerProgrammer } from "./MigrateNestControllerProgrammer";
|
9
|
+
import { MigrateNestModuleProgrammer } from "./MigrateNestModuleProgrammer";
|
10
|
+
|
11
|
+
export namespace MigrateNestProgrammer {
|
12
|
+
export const write = (program: IMigrateProgram): IMigrateFile[] =>
|
13
|
+
[
|
14
|
+
{
|
15
|
+
location: "src",
|
16
|
+
file: "MyModule.ts",
|
17
|
+
statements: MigrateNestModuleProgrammer.write(program.controllers),
|
18
|
+
},
|
19
|
+
...program.controllers.map((c) => ({
|
20
|
+
location: c.location,
|
21
|
+
file: `${c.name}.ts`,
|
22
|
+
statements: MigrateNestControllerProgrammer.write(
|
23
|
+
program.document.components,
|
24
|
+
)(c),
|
25
|
+
})),
|
26
|
+
...[
|
27
|
+
...MigrateDtoProgrammer.compose(program.document.components).entries(),
|
28
|
+
].map(([key, value]) => ({
|
29
|
+
location: "src/api/structures",
|
30
|
+
file: `${key}.ts`,
|
31
|
+
statements: writeDtoFile(key, value),
|
32
|
+
})),
|
33
|
+
].map((o) => ({
|
34
|
+
location: o.location,
|
35
|
+
file: o.file,
|
36
|
+
content: FilePrinter.write({ statements: o.statements }),
|
37
|
+
}));
|
38
|
+
|
39
|
+
const writeDtoFile = (
|
40
|
+
key: string,
|
41
|
+
modulo: MigrateDtoProgrammer.IModule,
|
42
|
+
): ts.Statement[] => {
|
43
|
+
const importer = new MigrateImportProgrammer();
|
44
|
+
const statements: ts.Statement[] = iterate(importer)(modulo);
|
45
|
+
if (statements.length === 0) return [];
|
46
|
+
|
47
|
+
return [
|
48
|
+
...importer.toStatements((name) => `./${name}`, key),
|
49
|
+
...(importer.empty() ? [] : [FilePrinter.newLine()]),
|
50
|
+
...statements,
|
51
|
+
];
|
52
|
+
};
|
53
|
+
|
54
|
+
const iterate =
|
55
|
+
(importer: MigrateImportProgrammer) =>
|
56
|
+
(modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
|
57
|
+
const output: ts.Statement[] = [];
|
58
|
+
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
59
|
+
if (modulo.children.size) {
|
60
|
+
const internal: ts.Statement[] = [];
|
61
|
+
for (const child of modulo.children.values())
|
62
|
+
internal.push(...iterate(importer)(child));
|
63
|
+
output.push(
|
64
|
+
ts.factory.createModuleDeclaration(
|
65
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
66
|
+
ts.factory.createIdentifier(modulo.name),
|
67
|
+
ts.factory.createModuleBlock(internal),
|
68
|
+
ts.NodeFlags.Namespace,
|
69
|
+
),
|
70
|
+
);
|
71
|
+
}
|
72
|
+
return output;
|
73
|
+
};
|
74
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
|
3
|
-
export interface IMigrateDto {
|
4
|
-
name: string;
|
5
|
-
location: string;
|
6
|
-
schema: OpenApi.IJsonSchema | null;
|
7
|
-
children: IMigrateDto[];
|
8
|
-
}
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
|
3
|
+
export interface IMigrateDto {
|
4
|
+
name: string;
|
5
|
+
location: string;
|
6
|
+
schema: OpenApi.IJsonSchema | null;
|
7
|
+
children: IMigrateDto[];
|
8
|
+
}
|