@nestia/migrate 0.13.0-dev.20240411-2 → 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.
Files changed (33) hide show
  1. package/lib/MigrateApplication.js +812 -710
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
  4. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  6. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  7. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  8. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  9. package/lib/internal/MigrateCommander.js.map +1 -1
  10. package/lib/programmers/MigrateSchemaProgrammer.js +25 -26
  11. package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
  12. package/package.json +79 -79
  13. package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
  14. package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
  15. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  16. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  17. package/src/internal/MigrateCommander.ts +76 -70
  18. package/src/module.ts +8 -8
  19. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  20. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  21. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  22. package/src/programmers/MigrateApiProgrammer.ts +172 -172
  23. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  24. package/src/programmers/MigrateDtoProgrammer.ts +77 -77
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  28. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  29. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  30. package/src/structures/IMigrateDto.ts +8 -8
  31. package/src/structures/IMigrateProgram.ts +27 -27
  32. package/src/structures/IMigrateRoute.ts +51 -51
  33. package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -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
+ }