@nestia/migrate 0.11.4 → 0.11.5
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/bundles/NEST_TEMPLATE.js +5 -5
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +2 -2
- package/src/MigrateApplication.ts +81 -81
- package/src/analyzers/MigrateAnalyzer.ts +9 -9
- package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
- package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +5 -5
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/bundle.ts +110 -110
- package/src/internal/MigrateCommander.ts +70 -70
- package/src/internal/MigrateInquirer.ts +86 -86
- package/src/module.ts +14 -14
- 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 +170 -170
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
- package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
- package/src/programmers/MigrateDtoProgrammer.ts +78 -78
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +36 -36
- package/src/programmers/MigrateImportProgrammer.ts +121 -121
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
- package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateProgram.ts +27 -27
- package/src/structures/IMigrateRoute.ts +51 -51
- package/src/structures/ISwagger.ts +23 -23
- package/src/structures/ISwaggerComponents.ts +14 -14
- package/src/structures/ISwaggerRoute.ts +20 -20
- package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
- package/src/structures/ISwaggerRouteParameter.ts +14 -14
- package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
- package/src/structures/ISwaggerRouteResponse.ts +11 -11
- package/src/structures/ISwaggerSchema.ts +90 -90
- package/src/structures/ISwaggerSecurityScheme.ts +47 -47
- package/src/structures/ISwaggerV20.ts +10 -10
- package/src/structures/ISwaggerV31.ts +10 -10
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/OpenApiConverter.ts +19 -19
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/SwaggerComponentsExplorer.ts +43 -43
- package/src/utils/SwaggerTypeChecker.ts +67 -67
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
- package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,199 +1,199 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
|
-
|
4
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
-
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
8
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
10
|
-
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
11
|
-
|
12
|
-
export namespace MigrateApiFunctionProgrammer {
|
13
|
-
export interface IProps {
|
14
|
-
controller: IMigrateController;
|
15
|
-
route: IMigrateRoute;
|
16
|
-
alias: string;
|
17
|
-
}
|
18
|
-
|
19
|
-
export const write =
|
20
|
-
(config: IMigrateProgram.IConfig) =>
|
21
|
-
(components: ISwaggerComponents) =>
|
22
|
-
(importer: MigrateImportProgrammer) =>
|
23
|
-
(props: IProps): ts.FunctionDeclaration =>
|
24
|
-
FilePrinter.description(
|
25
|
-
ts.factory.createFunctionDeclaration(
|
26
|
-
[
|
27
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
28
|
-
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
29
|
-
],
|
30
|
-
undefined,
|
31
|
-
props.alias,
|
32
|
-
undefined,
|
33
|
-
writeParameterDeclarations(components)(importer)(props),
|
34
|
-
ts.factory.createTypeReferenceNode("Promise", [
|
35
|
-
ts.factory.createTypeReferenceNode(
|
36
|
-
props.route.success === null ? "void" : `${props.alias}.Output`,
|
37
|
-
),
|
38
|
-
]),
|
39
|
-
ts.factory.createBlock(writeBody(config)(importer)(props), true),
|
40
|
-
),
|
41
|
-
writeDescription(props),
|
42
|
-
);
|
43
|
-
|
44
|
-
export const writeParameterDeclarations =
|
45
|
-
(components: ISwaggerComponents) =>
|
46
|
-
(importer: MigrateImportProgrammer) =>
|
47
|
-
(props: IProps): ts.ParameterDeclaration[] => [
|
48
|
-
IdentifierFactory.parameter(
|
49
|
-
"connection",
|
50
|
-
ts.factory.createTypeReferenceNode(
|
51
|
-
importer.external({
|
52
|
-
type: "instance",
|
53
|
-
library: "@nestia/fetcher",
|
54
|
-
name: "IConnection",
|
55
|
-
}),
|
56
|
-
props.route.headers
|
57
|
-
? [ts.factory.createTypeReferenceNode(`${props.alias}.Headers`)]
|
58
|
-
: undefined,
|
59
|
-
),
|
60
|
-
),
|
61
|
-
...props.route.parameters.map((p) =>
|
62
|
-
IdentifierFactory.parameter(
|
63
|
-
p.key,
|
64
|
-
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
65
|
-
),
|
66
|
-
),
|
67
|
-
...(props.route.query
|
68
|
-
? [
|
69
|
-
IdentifierFactory.parameter(
|
70
|
-
props.route.query.key,
|
71
|
-
ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
|
72
|
-
),
|
73
|
-
]
|
74
|
-
: []),
|
75
|
-
...(props.route.body
|
76
|
-
? [
|
77
|
-
IdentifierFactory.parameter(
|
78
|
-
props.route.body.key,
|
79
|
-
ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
|
80
|
-
),
|
81
|
-
]
|
82
|
-
: []),
|
83
|
-
];
|
84
|
-
|
85
|
-
const writeDescription = (props: IProps): string =>
|
86
|
-
[
|
87
|
-
props.route.comment(),
|
88
|
-
`@controller ${props.controller.name}`,
|
89
|
-
`@path ${props.route.path}`,
|
90
|
-
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
91
|
-
].join("\n");
|
92
|
-
|
93
|
-
const writeBody =
|
94
|
-
(config: IMigrateProgram.IConfig) =>
|
95
|
-
(importer: MigrateImportProgrammer) =>
|
96
|
-
(props: IProps): ts.Statement[] => {
|
97
|
-
const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
|
98
|
-
const contentType: string = props.route.body?.type ?? "application/json";
|
99
|
-
|
100
|
-
const caller = () =>
|
101
|
-
ts.factory.createCallExpression(
|
102
|
-
IdentifierFactory.access(
|
103
|
-
ts.factory.createIdentifier(
|
104
|
-
importer.external({
|
105
|
-
type: "instance",
|
106
|
-
library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
|
107
|
-
name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
|
108
|
-
}),
|
109
|
-
),
|
110
|
-
)("fetch"),
|
111
|
-
undefined,
|
112
|
-
[
|
113
|
-
contentType && contentType !== "multipart/form-data"
|
114
|
-
? ts.factory.createObjectLiteralExpression(
|
115
|
-
[
|
116
|
-
ts.factory.createSpreadAssignment(
|
117
|
-
ts.factory.createIdentifier("connection"),
|
118
|
-
),
|
119
|
-
ts.factory.createPropertyAssignment(
|
120
|
-
"headers",
|
121
|
-
ts.factory.createObjectLiteralExpression(
|
122
|
-
[
|
123
|
-
ts.factory.createSpreadAssignment(
|
124
|
-
IdentifierFactory.access(
|
125
|
-
ts.factory.createIdentifier("connection"),
|
126
|
-
)("headers"),
|
127
|
-
),
|
128
|
-
ts.factory.createPropertyAssignment(
|
129
|
-
ts.factory.createStringLiteral("Content-Type"),
|
130
|
-
ts.factory.createStringLiteral(contentType),
|
131
|
-
),
|
132
|
-
],
|
133
|
-
true,
|
134
|
-
),
|
135
|
-
),
|
136
|
-
],
|
137
|
-
true,
|
138
|
-
)
|
139
|
-
: ts.factory.createIdentifier("connection"),
|
140
|
-
ts.factory.createObjectLiteralExpression(
|
141
|
-
[
|
142
|
-
ts.factory.createSpreadAssignment(
|
143
|
-
IdentifierFactory.access(
|
144
|
-
ts.factory.createIdentifier(props.alias),
|
145
|
-
)("METADATA"),
|
146
|
-
),
|
147
|
-
ts.factory.createPropertyAssignment(
|
148
|
-
"path",
|
149
|
-
ts.factory.createCallExpression(
|
150
|
-
IdentifierFactory.access(
|
151
|
-
ts.factory.createIdentifier(props.alias),
|
152
|
-
)("path"),
|
153
|
-
undefined,
|
154
|
-
[
|
155
|
-
...props.route.parameters.map((p) =>
|
156
|
-
ts.factory.createIdentifier(p.key),
|
157
|
-
),
|
158
|
-
...(props.route.query
|
159
|
-
? [ts.factory.createIdentifier(props.route.query.key)]
|
160
|
-
: []),
|
161
|
-
],
|
162
|
-
),
|
163
|
-
),
|
164
|
-
ts.factory.createPropertyAssignment(
|
165
|
-
"status",
|
166
|
-
ts.factory.createNull(),
|
167
|
-
),
|
168
|
-
],
|
169
|
-
true,
|
170
|
-
),
|
171
|
-
...(props.route.body
|
172
|
-
? [ts.factory.createIdentifier(props.route.body.key)]
|
173
|
-
: []),
|
174
|
-
],
|
175
|
-
);
|
176
|
-
if (config.simulate !== true)
|
177
|
-
return [ts.factory.createReturnStatement(caller())];
|
178
|
-
return [
|
179
|
-
ts.factory.createReturnStatement(
|
180
|
-
ts.factory.createConditionalExpression(
|
181
|
-
ts.factory.createIdentifier("!!connection.simulate"),
|
182
|
-
undefined,
|
183
|
-
ts.factory.createCallExpression(
|
184
|
-
ts.factory.createIdentifier(`${props.alias}.simulate`),
|
185
|
-
[],
|
186
|
-
[
|
187
|
-
"connection",
|
188
|
-
...props.route.parameters.map((p) => p.key),
|
189
|
-
...(props.route.query ? [props.route.query.key] : []),
|
190
|
-
...(props.route.body ? [props.route.body.key] : []),
|
191
|
-
].map((key) => ts.factory.createIdentifier(key)),
|
192
|
-
),
|
193
|
-
undefined,
|
194
|
-
caller(),
|
195
|
-
),
|
196
|
-
),
|
197
|
-
];
|
198
|
-
};
|
199
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
|
+
|
4
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
+
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
8
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
10
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
11
|
+
|
12
|
+
export namespace MigrateApiFunctionProgrammer {
|
13
|
+
export interface IProps {
|
14
|
+
controller: IMigrateController;
|
15
|
+
route: IMigrateRoute;
|
16
|
+
alias: string;
|
17
|
+
}
|
18
|
+
|
19
|
+
export const write =
|
20
|
+
(config: IMigrateProgram.IConfig) =>
|
21
|
+
(components: ISwaggerComponents) =>
|
22
|
+
(importer: MigrateImportProgrammer) =>
|
23
|
+
(props: IProps): ts.FunctionDeclaration =>
|
24
|
+
FilePrinter.description(
|
25
|
+
ts.factory.createFunctionDeclaration(
|
26
|
+
[
|
27
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
28
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
29
|
+
],
|
30
|
+
undefined,
|
31
|
+
props.alias,
|
32
|
+
undefined,
|
33
|
+
writeParameterDeclarations(components)(importer)(props),
|
34
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
35
|
+
ts.factory.createTypeReferenceNode(
|
36
|
+
props.route.success === null ? "void" : `${props.alias}.Output`,
|
37
|
+
),
|
38
|
+
]),
|
39
|
+
ts.factory.createBlock(writeBody(config)(importer)(props), true),
|
40
|
+
),
|
41
|
+
writeDescription(props),
|
42
|
+
);
|
43
|
+
|
44
|
+
export const writeParameterDeclarations =
|
45
|
+
(components: ISwaggerComponents) =>
|
46
|
+
(importer: MigrateImportProgrammer) =>
|
47
|
+
(props: IProps): ts.ParameterDeclaration[] => [
|
48
|
+
IdentifierFactory.parameter(
|
49
|
+
"connection",
|
50
|
+
ts.factory.createTypeReferenceNode(
|
51
|
+
importer.external({
|
52
|
+
type: "instance",
|
53
|
+
library: "@nestia/fetcher",
|
54
|
+
name: "IConnection",
|
55
|
+
}),
|
56
|
+
props.route.headers
|
57
|
+
? [ts.factory.createTypeReferenceNode(`${props.alias}.Headers`)]
|
58
|
+
: undefined,
|
59
|
+
),
|
60
|
+
),
|
61
|
+
...props.route.parameters.map((p) =>
|
62
|
+
IdentifierFactory.parameter(
|
63
|
+
p.key,
|
64
|
+
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
65
|
+
),
|
66
|
+
),
|
67
|
+
...(props.route.query
|
68
|
+
? [
|
69
|
+
IdentifierFactory.parameter(
|
70
|
+
props.route.query.key,
|
71
|
+
ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
|
72
|
+
),
|
73
|
+
]
|
74
|
+
: []),
|
75
|
+
...(props.route.body
|
76
|
+
? [
|
77
|
+
IdentifierFactory.parameter(
|
78
|
+
props.route.body.key,
|
79
|
+
ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
|
80
|
+
),
|
81
|
+
]
|
82
|
+
: []),
|
83
|
+
];
|
84
|
+
|
85
|
+
const writeDescription = (props: IProps): string =>
|
86
|
+
[
|
87
|
+
props.route.comment(),
|
88
|
+
`@controller ${props.controller.name}`,
|
89
|
+
`@path ${props.route.path}`,
|
90
|
+
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
91
|
+
].join("\n");
|
92
|
+
|
93
|
+
const writeBody =
|
94
|
+
(config: IMigrateProgram.IConfig) =>
|
95
|
+
(importer: MigrateImportProgrammer) =>
|
96
|
+
(props: IProps): ts.Statement[] => {
|
97
|
+
const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
|
98
|
+
const contentType: string = props.route.body?.type ?? "application/json";
|
99
|
+
|
100
|
+
const caller = () =>
|
101
|
+
ts.factory.createCallExpression(
|
102
|
+
IdentifierFactory.access(
|
103
|
+
ts.factory.createIdentifier(
|
104
|
+
importer.external({
|
105
|
+
type: "instance",
|
106
|
+
library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
|
107
|
+
name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
|
108
|
+
}),
|
109
|
+
),
|
110
|
+
)("fetch"),
|
111
|
+
undefined,
|
112
|
+
[
|
113
|
+
contentType && contentType !== "multipart/form-data"
|
114
|
+
? ts.factory.createObjectLiteralExpression(
|
115
|
+
[
|
116
|
+
ts.factory.createSpreadAssignment(
|
117
|
+
ts.factory.createIdentifier("connection"),
|
118
|
+
),
|
119
|
+
ts.factory.createPropertyAssignment(
|
120
|
+
"headers",
|
121
|
+
ts.factory.createObjectLiteralExpression(
|
122
|
+
[
|
123
|
+
ts.factory.createSpreadAssignment(
|
124
|
+
IdentifierFactory.access(
|
125
|
+
ts.factory.createIdentifier("connection"),
|
126
|
+
)("headers"),
|
127
|
+
),
|
128
|
+
ts.factory.createPropertyAssignment(
|
129
|
+
ts.factory.createStringLiteral("Content-Type"),
|
130
|
+
ts.factory.createStringLiteral(contentType),
|
131
|
+
),
|
132
|
+
],
|
133
|
+
true,
|
134
|
+
),
|
135
|
+
),
|
136
|
+
],
|
137
|
+
true,
|
138
|
+
)
|
139
|
+
: ts.factory.createIdentifier("connection"),
|
140
|
+
ts.factory.createObjectLiteralExpression(
|
141
|
+
[
|
142
|
+
ts.factory.createSpreadAssignment(
|
143
|
+
IdentifierFactory.access(
|
144
|
+
ts.factory.createIdentifier(props.alias),
|
145
|
+
)("METADATA"),
|
146
|
+
),
|
147
|
+
ts.factory.createPropertyAssignment(
|
148
|
+
"path",
|
149
|
+
ts.factory.createCallExpression(
|
150
|
+
IdentifierFactory.access(
|
151
|
+
ts.factory.createIdentifier(props.alias),
|
152
|
+
)("path"),
|
153
|
+
undefined,
|
154
|
+
[
|
155
|
+
...props.route.parameters.map((p) =>
|
156
|
+
ts.factory.createIdentifier(p.key),
|
157
|
+
),
|
158
|
+
...(props.route.query
|
159
|
+
? [ts.factory.createIdentifier(props.route.query.key)]
|
160
|
+
: []),
|
161
|
+
],
|
162
|
+
),
|
163
|
+
),
|
164
|
+
ts.factory.createPropertyAssignment(
|
165
|
+
"status",
|
166
|
+
ts.factory.createNull(),
|
167
|
+
),
|
168
|
+
],
|
169
|
+
true,
|
170
|
+
),
|
171
|
+
...(props.route.body
|
172
|
+
? [ts.factory.createIdentifier(props.route.body.key)]
|
173
|
+
: []),
|
174
|
+
],
|
175
|
+
);
|
176
|
+
if (config.simulate !== true)
|
177
|
+
return [ts.factory.createReturnStatement(caller())];
|
178
|
+
return [
|
179
|
+
ts.factory.createReturnStatement(
|
180
|
+
ts.factory.createConditionalExpression(
|
181
|
+
ts.factory.createIdentifier("!!connection.simulate"),
|
182
|
+
undefined,
|
183
|
+
ts.factory.createCallExpression(
|
184
|
+
ts.factory.createIdentifier(`${props.alias}.simulate`),
|
185
|
+
[],
|
186
|
+
[
|
187
|
+
"connection",
|
188
|
+
...props.route.parameters.map((p) => p.key),
|
189
|
+
...(props.route.query ? [props.route.query.key] : []),
|
190
|
+
...(props.route.body ? [props.route.body.key] : []),
|
191
|
+
].map((key) => ts.factory.createIdentifier(key)),
|
192
|
+
),
|
193
|
+
undefined,
|
194
|
+
caller(),
|
195
|
+
),
|
196
|
+
),
|
197
|
+
];
|
198
|
+
};
|
199
|
+
}
|