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