@nestia/migrate 0.7.6 → 0.7.8
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/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/internal/MigrateCommander.js +12 -1
- package/lib/internal/MigrateCommander.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/MigrateNestModuleProgrammer.js +1 -1
- package/lib/programmers/MigrateNestModuleProgrammer.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 +70 -68
- 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/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/bundle.ts +109 -109
- package/src/internal/MigrateCommander.ts +62 -51
- package/src/module.ts +14 -4
- 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 +63 -62
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/programmers/MigrateSchemaProgrammer.ts +257 -257
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateProgram.ts +25 -9
- package/src/structures/IMigrateRoute.ts +46 -46
- package/src/structures/ISwaggerComponents.ts +7 -7
- package/src/structures/ISwaggerRoute.ts +55 -55
- package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +90 -90
- 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
@@ -1,122 +1,139 @@
|
|
1
|
-
import { Escaper } from "typia/lib/utils/Escaper";
|
2
|
-
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
1
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
2
|
+
|
3
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
4
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
|
+
import { ISwaggerRoute } from "../structures/ISwaggerRoute";
|
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: ISwaggerRoute;
|
17
|
+
route: IMigrateRoute;
|
18
|
+
}
|
19
|
+
const endpoints: Map<string, IEntry[]> = new Map();
|
20
|
+
|
21
|
+
// GATHER ROUTES
|
22
|
+
for (const [path, collection] of Object.entries(props.swagger.paths)) {
|
23
|
+
// PREPARE DIRECTORIES
|
24
|
+
const location: string = StringUtil.splitWithNormalization(path)
|
25
|
+
.filter((str) => str[0] !== "{" && str[0] !== ":")
|
26
|
+
.join("/");
|
27
|
+
for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
|
28
|
+
|
29
|
+
// INSERT ROUTES TO THE LAST DIRECTORY
|
30
|
+
const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
|
31
|
+
for (const [method, value] of Object.entries(collection)) {
|
32
|
+
const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
|
33
|
+
path,
|
34
|
+
method,
|
35
|
+
})(value);
|
36
|
+
if (r === null) continue;
|
37
|
+
routes.push({
|
38
|
+
endpoint: value,
|
39
|
+
route: r,
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
// ABSORB STANDALONE ROUTES
|
45
|
+
const emended: Map<string, IEntry[]> = new Map(
|
46
|
+
[...endpoints.entries()].sort((a, b) => a[0].localeCompare(b[0])),
|
47
|
+
);
|
48
|
+
for (const [location, routes] of emended) {
|
49
|
+
if (routes.length !== 1) continue;
|
50
|
+
for (const s of sequence(location).slice(0, 1)) {
|
51
|
+
const parent = emended.get(s);
|
52
|
+
if (parent) {
|
53
|
+
parent.push(...routes);
|
54
|
+
emended.delete(location);
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
// GENERATE CONTROLLERS
|
61
|
+
return [...emended.entries()]
|
62
|
+
.filter(([_l, routes]) => !!routes.length)
|
63
|
+
.map(([location, routes]) => {
|
64
|
+
const prefix: string = StringUtil.commonPrefix(
|
65
|
+
routes.map((e) => e.route.path),
|
66
|
+
);
|
67
|
+
for (const e of routes)
|
68
|
+
e.route.path = StringUtil.reJoinWithDecimalParameters(
|
69
|
+
e.route.path.replace(prefix, ""),
|
70
|
+
);
|
71
|
+
const controller: IMigrateController = {
|
72
|
+
name: StringUtil.pascal(location) + "Controller",
|
73
|
+
path: StringUtil.reJoinWithDecimalParameters(prefix),
|
74
|
+
location: "src/controllers/" + location,
|
75
|
+
routes: routes.map((e) => e.route),
|
76
|
+
};
|
77
|
+
if (controller.name === "Controller") controller.name = "__Controller";
|
78
|
+
emend(controller);
|
79
|
+
|
80
|
+
for (const e of routes)
|
81
|
+
props.dictionary.set(e.endpoint, {
|
82
|
+
controller,
|
83
|
+
route: e.route,
|
84
|
+
});
|
85
|
+
return controller;
|
86
|
+
});
|
87
|
+
};
|
88
|
+
|
89
|
+
const sequence = (location: string): string[] =>
|
90
|
+
StringUtil.splitWithNormalization(location)
|
91
|
+
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
|
92
|
+
.slice(0, -1)
|
93
|
+
.reverse();
|
94
|
+
|
95
|
+
const emend = (controller: IMigrateController): void => {
|
96
|
+
interface IRouteCapsule {
|
97
|
+
variables: string[];
|
98
|
+
route: IMigrateRoute;
|
99
|
+
}
|
100
|
+
const dict: Map<string, IRouteCapsule[]> = new Map();
|
101
|
+
for (const route of controller.routes) {
|
102
|
+
const additional: string[] = StringUtil.splitWithNormalization(
|
103
|
+
route.path,
|
104
|
+
);
|
105
|
+
const statics: string[] = additional.filter((str) => str[0] !== ":");
|
106
|
+
if (statics.length) route.name = StringUtil.camel(statics.join("/"));
|
107
|
+
else
|
108
|
+
MapUtil.take(dict)(route.method)(() => []).push({
|
109
|
+
variables: additional
|
110
|
+
.filter((str) => str[0] === ":")
|
111
|
+
.map((str) => str.substring(1)),
|
112
|
+
route,
|
113
|
+
});
|
114
|
+
}
|
115
|
+
for (const [method, capsules] of dict) {
|
116
|
+
const emended: string = method === "delete" ? "erase" : method;
|
117
|
+
for (const c of capsules) {
|
118
|
+
const empty: boolean = c.variables.length === 0;
|
119
|
+
c.route.name = empty
|
120
|
+
? emended
|
121
|
+
: StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
for (const method of controller.routes) {
|
125
|
+
if (Escaper.variable(method.name) === false)
|
126
|
+
method.name = "_" + method.name;
|
127
|
+
for (const spec of [method.headers, method.query, method.body])
|
128
|
+
if (spec)
|
129
|
+
spec.key = StringUtil.escapeDuplicate(
|
130
|
+
method.parameters.map((p) => p.key),
|
131
|
+
)(spec.key);
|
132
|
+
}
|
133
|
+
controller.routes.forEach((r, i) => {
|
134
|
+
r.name = StringUtil.escapeDuplicate(
|
135
|
+
controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
|
136
|
+
)(r.name);
|
137
|
+
});
|
138
|
+
};
|
139
|
+
}
|