@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
package/package.json
CHANGED
@@ -1,79 +1,79 @@
|
|
1
|
-
{
|
2
|
-
"name": "@nestia/migrate",
|
3
|
-
"version": "0.13.
|
4
|
-
"description": "Migration program from swagger to NestJS",
|
5
|
-
"main": "lib/index.js",
|
6
|
-
"typings": "lib/index.d.ts",
|
7
|
-
"bin": {
|
8
|
-
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
-
},
|
10
|
-
"scripts": {
|
11
|
-
"build": "rimraf lib && tsc",
|
12
|
-
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
-
"dev": "npm run build -- --watch",
|
14
|
-
"package:next": "npm publish --access public --tag next",
|
15
|
-
"prepare": "ts-patch install && typia patch && npm run bundle",
|
16
|
-
"test": "node lib/test"
|
17
|
-
},
|
18
|
-
"repository": {
|
19
|
-
"type": "git",
|
20
|
-
"url": "https://github.com/samchon/nestia"
|
21
|
-
},
|
22
|
-
"keywords": [
|
23
|
-
"migration",
|
24
|
-
"swagger",
|
25
|
-
"NestJS",
|
26
|
-
"nestia",
|
27
|
-
"SDK",
|
28
|
-
"Mockup Simulator"
|
29
|
-
],
|
30
|
-
"author": "Jeongho Nam",
|
31
|
-
"license": "MIT",
|
32
|
-
"bugs": {
|
33
|
-
"url": "https://github.com/samchon/nestia/issues"
|
34
|
-
},
|
35
|
-
"homepage": "https://nestia.io",
|
36
|
-
"devDependencies": {
|
37
|
-
"@nestia/core": "^3.0.
|
38
|
-
"@nestia/e2e": "^0.4.3",
|
39
|
-
"@nestia/fetcher": "^3.0.
|
40
|
-
"@nestjs/common": "^10.3.5",
|
41
|
-
"@nestjs/core": "^10.3.5",
|
42
|
-
"@nestjs/platform-express": "^10.3.5",
|
43
|
-
"@nestjs/platform-fastify": "^10.3.5",
|
44
|
-
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
45
|
-
"@types/express": "^4.17.21",
|
46
|
-
"@types/inquirer": "^9.0.7",
|
47
|
-
"@types/node": "^20.3.3",
|
48
|
-
"@types/swagger-ui-express": "^4.1.6",
|
49
|
-
"dotenv": "^16.3.1",
|
50
|
-
"dotenv-expand": "^10.0.0",
|
51
|
-
"express": "^4.19.2",
|
52
|
-
"rimraf": "^5.0.1",
|
53
|
-
"serialize-error": "^4.1.0",
|
54
|
-
"source-map-support": "^0.5.21",
|
55
|
-
"swagger-ui-express": "^5.0.0",
|
56
|
-
"ts-node": "^10.9.1",
|
57
|
-
"ts-patch": "^3.1.0",
|
58
|
-
"typescript-transform-paths": "^3.4.6"
|
59
|
-
},
|
60
|
-
"dependencies": {
|
61
|
-
"@samchon/openapi": "^0.1.
|
62
|
-
"commander": "10.0.0",
|
63
|
-
"inquirer": "8.2.5",
|
64
|
-
"openapi-types": "^12.1.3",
|
65
|
-
"prettier": "^3.2.5",
|
66
|
-
"tstl": "^3.0.0",
|
67
|
-
"typescript": "^5.4.3",
|
68
|
-
"typia": "^6.0.
|
69
|
-
},
|
70
|
-
"files": [
|
71
|
-
"lib",
|
72
|
-
"src",
|
73
|
-
"!lib/test",
|
74
|
-
"!src/test",
|
75
|
-
"package.json",
|
76
|
-
"README.md",
|
77
|
-
"LICENSE"
|
78
|
-
]
|
79
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@nestia/migrate",
|
3
|
+
"version": "0.13.1",
|
4
|
+
"description": "Migration program from swagger to NestJS",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"typings": "lib/index.d.ts",
|
7
|
+
"bin": {
|
8
|
+
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"build": "rimraf lib && tsc",
|
12
|
+
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
+
"dev": "npm run build -- --watch",
|
14
|
+
"package:next": "npm publish --access public --tag next",
|
15
|
+
"prepare": "ts-patch install && typia patch && npm run bundle",
|
16
|
+
"test": "node lib/test"
|
17
|
+
},
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "https://github.com/samchon/nestia"
|
21
|
+
},
|
22
|
+
"keywords": [
|
23
|
+
"migration",
|
24
|
+
"swagger",
|
25
|
+
"NestJS",
|
26
|
+
"nestia",
|
27
|
+
"SDK",
|
28
|
+
"Mockup Simulator"
|
29
|
+
],
|
30
|
+
"author": "Jeongho Nam",
|
31
|
+
"license": "MIT",
|
32
|
+
"bugs": {
|
33
|
+
"url": "https://github.com/samchon/nestia/issues"
|
34
|
+
},
|
35
|
+
"homepage": "https://nestia.io",
|
36
|
+
"devDependencies": {
|
37
|
+
"@nestia/core": "^3.0.1",
|
38
|
+
"@nestia/e2e": "^0.4.3",
|
39
|
+
"@nestia/fetcher": "^3.0.1",
|
40
|
+
"@nestjs/common": "^10.3.5",
|
41
|
+
"@nestjs/core": "^10.3.5",
|
42
|
+
"@nestjs/platform-express": "^10.3.5",
|
43
|
+
"@nestjs/platform-fastify": "^10.3.5",
|
44
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
45
|
+
"@types/express": "^4.17.21",
|
46
|
+
"@types/inquirer": "^9.0.7",
|
47
|
+
"@types/node": "^20.3.3",
|
48
|
+
"@types/swagger-ui-express": "^4.1.6",
|
49
|
+
"dotenv": "^16.3.1",
|
50
|
+
"dotenv-expand": "^10.0.0",
|
51
|
+
"express": "^4.19.2",
|
52
|
+
"rimraf": "^5.0.1",
|
53
|
+
"serialize-error": "^4.1.0",
|
54
|
+
"source-map-support": "^0.5.21",
|
55
|
+
"swagger-ui-express": "^5.0.0",
|
56
|
+
"ts-node": "^10.9.1",
|
57
|
+
"ts-patch": "^3.1.0",
|
58
|
+
"typescript-transform-paths": "^3.4.6"
|
59
|
+
},
|
60
|
+
"dependencies": {
|
61
|
+
"@samchon/openapi": "^0.1.5",
|
62
|
+
"commander": "10.0.0",
|
63
|
+
"inquirer": "8.2.5",
|
64
|
+
"openapi-types": "^12.1.3",
|
65
|
+
"prettier": "^3.2.5",
|
66
|
+
"tstl": "^3.0.0",
|
67
|
+
"typescript": "^5.4.3",
|
68
|
+
"typia": "^6.0.1"
|
69
|
+
},
|
70
|
+
"files": [
|
71
|
+
"lib",
|
72
|
+
"src",
|
73
|
+
"!lib/test",
|
74
|
+
"!src/test",
|
75
|
+
"package.json",
|
76
|
+
"README.md",
|
77
|
+
"LICENSE"
|
78
|
+
]
|
79
|
+
}
|
@@ -1,137 +1,137 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import { Escaper } from "typia/lib/utils/Escaper";
|
3
|
-
|
4
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
-
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
-
import { MapUtil } from "../utils/MapUtil";
|
8
|
-
import { StringUtil } from "../utils/StringUtil";
|
9
|
-
import { MigrateMethodAnalzyer } from "./MigrateMethodAnalyzer";
|
10
|
-
|
11
|
-
export namespace MigrateControllerAnalyzer {
|
12
|
-
export const analyze = (
|
13
|
-
props: IMigrateProgram.IProps,
|
14
|
-
): IMigrateController[] => {
|
15
|
-
interface IEntry {
|
16
|
-
endpoint: OpenApi.IOperation;
|
17
|
-
route: IMigrateRoute;
|
18
|
-
}
|
19
|
-
const endpoints: Map<string, IEntry[]> = new Map();
|
20
|
-
|
21
|
-
// GATHER ROUTES
|
22
|
-
for (const [path, collection] of Object.entries(
|
23
|
-
props.document.paths ?? {},
|
24
|
-
)) {
|
25
|
-
if (collection === undefined) continue;
|
26
|
-
|
27
|
-
// PREPARE DIRECTORIES
|
28
|
-
const location: string = StringUtil.splitWithNormalization(path)
|
29
|
-
.filter((str) => str[0] !== "{" && str[0] !== ":")
|
30
|
-
.join("/");
|
31
|
-
for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
|
32
|
-
|
33
|
-
// INSERT ROUTES TO THE LAST DIRECTORY
|
34
|
-
const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
|
35
|
-
for (const [method, value] of Object.entries(collection)) {
|
36
|
-
if (
|
37
|
-
value === undefined ||
|
38
|
-
["get", "post", "patch", "put", "delete"].includes(method) === false
|
39
|
-
)
|
40
|
-
continue;
|
41
|
-
const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
|
42
|
-
path,
|
43
|
-
method,
|
44
|
-
})(value as OpenApi.IOperation);
|
45
|
-
if (r === null) continue;
|
46
|
-
routes.push({
|
47
|
-
endpoint: value as OpenApi.IOperation,
|
48
|
-
route: r,
|
49
|
-
});
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
// GENERATE CONTROLLERS
|
54
|
-
const total: IMigrateController[] = [...endpoints.entries()]
|
55
|
-
.filter(([_l, routes]) => !!routes.length)
|
56
|
-
.map(([location, routes]) => {
|
57
|
-
const prefix: string = StringUtil.commonPrefix(
|
58
|
-
routes.map((e) => e.route.path),
|
59
|
-
);
|
60
|
-
for (const e of routes)
|
61
|
-
e.route.path = StringUtil.reJoinWithDecimalParameters(
|
62
|
-
e.route.path.replace(prefix, ""),
|
63
|
-
);
|
64
|
-
const controller: IMigrateController = {
|
65
|
-
name: StringUtil.pascal(location) + "Controller",
|
66
|
-
path: StringUtil.reJoinWithDecimalParameters(prefix),
|
67
|
-
location: "src/controllers/" + location,
|
68
|
-
routes: routes.map((e) => e.route),
|
69
|
-
};
|
70
|
-
emend(controller);
|
71
|
-
|
72
|
-
for (const e of routes)
|
73
|
-
props.dictionary.set(e.endpoint, {
|
74
|
-
controller,
|
75
|
-
route: e.route,
|
76
|
-
});
|
77
|
-
return controller;
|
78
|
-
});
|
79
|
-
for (const c of total)
|
80
|
-
if (c.name === "Controller")
|
81
|
-
c.name = StringUtil.escapeDuplicate([...total.map((c) => c.name)])(
|
82
|
-
"AppController",
|
83
|
-
);
|
84
|
-
return total;
|
85
|
-
};
|
86
|
-
|
87
|
-
const sequence = (location: string): string[] =>
|
88
|
-
StringUtil.splitWithNormalization(location)
|
89
|
-
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
|
90
|
-
.slice(0, -1)
|
91
|
-
.reverse();
|
92
|
-
|
93
|
-
const emend = (controller: IMigrateController): void => {
|
94
|
-
interface IRouteCapsule {
|
95
|
-
variables: string[];
|
96
|
-
route: IMigrateRoute;
|
97
|
-
}
|
98
|
-
const dict: Map<string, IRouteCapsule[]> = new Map();
|
99
|
-
for (const route of controller.routes) {
|
100
|
-
const additional: string[] = StringUtil.splitWithNormalization(
|
101
|
-
route.path,
|
102
|
-
);
|
103
|
-
const statics: string[] = additional.filter((str) => str[0] !== ":");
|
104
|
-
if (statics.length) route.name = StringUtil.camel(statics.join("/"));
|
105
|
-
else
|
106
|
-
MapUtil.take(dict)(route.method)(() => []).push({
|
107
|
-
variables: additional
|
108
|
-
.filter((str) => str[0] === ":")
|
109
|
-
.map((str) => str.substring(1)),
|
110
|
-
route,
|
111
|
-
});
|
112
|
-
}
|
113
|
-
for (const [method, capsules] of dict) {
|
114
|
-
const emended: string = method === "delete" ? "erase" : method;
|
115
|
-
for (const c of capsules) {
|
116
|
-
const empty: boolean = c.variables.length === 0;
|
117
|
-
c.route.name = empty
|
118
|
-
? emended
|
119
|
-
: StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
|
120
|
-
}
|
121
|
-
}
|
122
|
-
for (const method of controller.routes) {
|
123
|
-
if (Escaper.variable(method.name) === false)
|
124
|
-
method.name = "_" + method.name;
|
125
|
-
for (const spec of [method.headers, method.query, method.body])
|
126
|
-
if (spec)
|
127
|
-
spec.key = StringUtil.escapeDuplicate(
|
128
|
-
method.parameters.map((p) => p.key),
|
129
|
-
)(spec.key);
|
130
|
-
}
|
131
|
-
controller.routes.forEach((r, i) => {
|
132
|
-
r.name = StringUtil.escapeDuplicate(
|
133
|
-
controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
|
134
|
-
)(r.name);
|
135
|
-
});
|
136
|
-
};
|
137
|
-
}
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
3
|
+
|
4
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
+
import { MapUtil } from "../utils/MapUtil";
|
8
|
+
import { StringUtil } from "../utils/StringUtil";
|
9
|
+
import { MigrateMethodAnalzyer } from "./MigrateMethodAnalyzer";
|
10
|
+
|
11
|
+
export namespace MigrateControllerAnalyzer {
|
12
|
+
export const analyze = (
|
13
|
+
props: IMigrateProgram.IProps,
|
14
|
+
): IMigrateController[] => {
|
15
|
+
interface IEntry {
|
16
|
+
endpoint: OpenApi.IOperation;
|
17
|
+
route: IMigrateRoute;
|
18
|
+
}
|
19
|
+
const endpoints: Map<string, IEntry[]> = new Map();
|
20
|
+
|
21
|
+
// GATHER ROUTES
|
22
|
+
for (const [path, collection] of Object.entries(
|
23
|
+
props.document.paths ?? {},
|
24
|
+
)) {
|
25
|
+
if (collection === undefined) continue;
|
26
|
+
|
27
|
+
// PREPARE DIRECTORIES
|
28
|
+
const location: string = StringUtil.splitWithNormalization(path)
|
29
|
+
.filter((str) => str[0] !== "{" && str[0] !== ":")
|
30
|
+
.join("/");
|
31
|
+
for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
|
32
|
+
|
33
|
+
// INSERT ROUTES TO THE LAST DIRECTORY
|
34
|
+
const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
|
35
|
+
for (const [method, value] of Object.entries(collection)) {
|
36
|
+
if (
|
37
|
+
value === undefined ||
|
38
|
+
["get", "post", "patch", "put", "delete"].includes(method) === false
|
39
|
+
)
|
40
|
+
continue;
|
41
|
+
const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
|
42
|
+
path,
|
43
|
+
method,
|
44
|
+
})(value as OpenApi.IOperation);
|
45
|
+
if (r === null) continue;
|
46
|
+
routes.push({
|
47
|
+
endpoint: value as OpenApi.IOperation,
|
48
|
+
route: r,
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
// GENERATE CONTROLLERS
|
54
|
+
const total: IMigrateController[] = [...endpoints.entries()]
|
55
|
+
.filter(([_l, routes]) => !!routes.length)
|
56
|
+
.map(([location, routes]) => {
|
57
|
+
const prefix: string = StringUtil.commonPrefix(
|
58
|
+
routes.map((e) => e.route.path),
|
59
|
+
);
|
60
|
+
for (const e of routes)
|
61
|
+
e.route.path = StringUtil.reJoinWithDecimalParameters(
|
62
|
+
e.route.path.replace(prefix, ""),
|
63
|
+
);
|
64
|
+
const controller: IMigrateController = {
|
65
|
+
name: StringUtil.pascal(location) + "Controller",
|
66
|
+
path: StringUtil.reJoinWithDecimalParameters(prefix),
|
67
|
+
location: "src/controllers/" + location,
|
68
|
+
routes: routes.map((e) => e.route),
|
69
|
+
};
|
70
|
+
emend(controller);
|
71
|
+
|
72
|
+
for (const e of routes)
|
73
|
+
props.dictionary.set(e.endpoint, {
|
74
|
+
controller,
|
75
|
+
route: e.route,
|
76
|
+
});
|
77
|
+
return controller;
|
78
|
+
});
|
79
|
+
for (const c of total)
|
80
|
+
if (c.name === "Controller")
|
81
|
+
c.name = StringUtil.escapeDuplicate([...total.map((c) => c.name)])(
|
82
|
+
"AppController",
|
83
|
+
);
|
84
|
+
return total;
|
85
|
+
};
|
86
|
+
|
87
|
+
const sequence = (location: string): string[] =>
|
88
|
+
StringUtil.splitWithNormalization(location)
|
89
|
+
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
|
90
|
+
.slice(0, -1)
|
91
|
+
.reverse();
|
92
|
+
|
93
|
+
const emend = (controller: IMigrateController): void => {
|
94
|
+
interface IRouteCapsule {
|
95
|
+
variables: string[];
|
96
|
+
route: IMigrateRoute;
|
97
|
+
}
|
98
|
+
const dict: Map<string, IRouteCapsule[]> = new Map();
|
99
|
+
for (const route of controller.routes) {
|
100
|
+
const additional: string[] = StringUtil.splitWithNormalization(
|
101
|
+
route.path,
|
102
|
+
);
|
103
|
+
const statics: string[] = additional.filter((str) => str[0] !== ":");
|
104
|
+
if (statics.length) route.name = StringUtil.camel(statics.join("/"));
|
105
|
+
else
|
106
|
+
MapUtil.take(dict)(route.method)(() => []).push({
|
107
|
+
variables: additional
|
108
|
+
.filter((str) => str[0] === ":")
|
109
|
+
.map((str) => str.substring(1)),
|
110
|
+
route,
|
111
|
+
});
|
112
|
+
}
|
113
|
+
for (const [method, capsules] of dict) {
|
114
|
+
const emended: string = method === "delete" ? "erase" : method;
|
115
|
+
for (const c of capsules) {
|
116
|
+
const empty: boolean = c.variables.length === 0;
|
117
|
+
c.route.name = empty
|
118
|
+
? emended
|
119
|
+
: StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
for (const method of controller.routes) {
|
123
|
+
if (Escaper.variable(method.name) === false)
|
124
|
+
method.name = "_" + method.name;
|
125
|
+
for (const spec of [method.headers, method.query, method.body])
|
126
|
+
if (spec)
|
127
|
+
spec.key = StringUtil.escapeDuplicate(
|
128
|
+
method.parameters.map((p) => p.key),
|
129
|
+
)(spec.key);
|
130
|
+
}
|
131
|
+
controller.routes.forEach((r, i) => {
|
132
|
+
r.name = StringUtil.escapeDuplicate(
|
133
|
+
controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
|
134
|
+
)(r.name);
|
135
|
+
});
|
136
|
+
};
|
137
|
+
}
|