@nestia/migrate 0.11.3 → 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.
Files changed (55) hide show
  1. package/lib/analyzers/MigrateMethodAnalyzer.js +1 -1
  2. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  3. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  4. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  5. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  7. package/lib/utils/openapi-down-convert/converter.js +2 -2
  8. package/package.json +75 -75
  9. package/src/MigrateApplication.ts +81 -81
  10. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  12. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -437
  13. package/src/archivers/MigrateFileArchiver.ts +38 -38
  14. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  15. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  16. package/src/executable/bundle.ts +110 -110
  17. package/src/internal/MigrateCommander.ts +70 -70
  18. package/src/internal/MigrateInquirer.ts +86 -86
  19. package/src/module.ts +14 -14
  20. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  21. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  22. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  23. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  24. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  25. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  26. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  27. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  28. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  29. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  30. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  31. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  32. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  33. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  34. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  35. package/src/structures/IMigrateDto.ts +8 -8
  36. package/src/structures/IMigrateProgram.ts +27 -27
  37. package/src/structures/IMigrateRoute.ts +51 -51
  38. package/src/structures/ISwagger.ts +23 -23
  39. package/src/structures/ISwaggerComponents.ts +14 -14
  40. package/src/structures/ISwaggerRoute.ts +20 -20
  41. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  42. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  43. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  44. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  45. package/src/structures/ISwaggerSchema.ts +90 -90
  46. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  47. package/src/structures/ISwaggerV20.ts +10 -10
  48. package/src/structures/ISwaggerV31.ts +10 -10
  49. package/src/utils/FilePrinter.ts +36 -36
  50. package/src/utils/OpenApiConverter.ts +19 -19
  51. package/src/utils/StringUtil.ts +60 -60
  52. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  53. package/src/utils/SwaggerTypeChecker.ts +67 -67
  54. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  55. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,135 +1,135 @@
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
- if (collection === undefined) continue;
24
-
25
- // PREPARE DIRECTORIES
26
- const location: string = StringUtil.splitWithNormalization(path)
27
- .filter((str) => str[0] !== "{" && str[0] !== ":")
28
- .join("/");
29
- for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
30
-
31
- // INSERT ROUTES TO THE LAST DIRECTORY
32
- const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
33
- for (const [method, value] of Object.entries(collection)) {
34
- if (
35
- value === undefined ||
36
- ["get", "post", "patch", "put", "delete"].includes(method) === false
37
- )
38
- continue;
39
- const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
40
- path,
41
- method,
42
- })(value);
43
- if (r === null) continue;
44
- routes.push({
45
- endpoint: value,
46
- route: r,
47
- });
48
- }
49
- }
50
-
51
- // GENERATE CONTROLLERS
52
- const total: IMigrateController[] = [...endpoints.entries()]
53
- .filter(([_l, routes]) => !!routes.length)
54
- .map(([location, routes]) => {
55
- const prefix: string = StringUtil.commonPrefix(
56
- routes.map((e) => e.route.path),
57
- );
58
- for (const e of routes)
59
- e.route.path = StringUtil.reJoinWithDecimalParameters(
60
- e.route.path.replace(prefix, ""),
61
- );
62
- const controller: IMigrateController = {
63
- name: StringUtil.pascal(location) + "Controller",
64
- path: StringUtil.reJoinWithDecimalParameters(prefix),
65
- location: "src/controllers/" + location,
66
- routes: routes.map((e) => e.route),
67
- };
68
- emend(controller);
69
-
70
- for (const e of routes)
71
- props.dictionary.set(e.endpoint, {
72
- controller,
73
- route: e.route,
74
- });
75
- return controller;
76
- });
77
- for (const c of total)
78
- if (c.name === "Controller")
79
- c.name = StringUtil.escapeDuplicate([...total.map((c) => c.name)])(
80
- "AppController",
81
- );
82
- return total;
83
- };
84
-
85
- const sequence = (location: string): string[] =>
86
- StringUtil.splitWithNormalization(location)
87
- .map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
88
- .slice(0, -1)
89
- .reverse();
90
-
91
- const emend = (controller: IMigrateController): void => {
92
- interface IRouteCapsule {
93
- variables: string[];
94
- route: IMigrateRoute;
95
- }
96
- const dict: Map<string, IRouteCapsule[]> = new Map();
97
- for (const route of controller.routes) {
98
- const additional: string[] = StringUtil.splitWithNormalization(
99
- route.path,
100
- );
101
- const statics: string[] = additional.filter((str) => str[0] !== ":");
102
- if (statics.length) route.name = StringUtil.camel(statics.join("/"));
103
- else
104
- MapUtil.take(dict)(route.method)(() => []).push({
105
- variables: additional
106
- .filter((str) => str[0] === ":")
107
- .map((str) => str.substring(1)),
108
- route,
109
- });
110
- }
111
- for (const [method, capsules] of dict) {
112
- const emended: string = method === "delete" ? "erase" : method;
113
- for (const c of capsules) {
114
- const empty: boolean = c.variables.length === 0;
115
- c.route.name = empty
116
- ? emended
117
- : StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
118
- }
119
- }
120
- for (const method of controller.routes) {
121
- if (Escaper.variable(method.name) === false)
122
- method.name = "_" + method.name;
123
- for (const spec of [method.headers, method.query, method.body])
124
- if (spec)
125
- spec.key = StringUtil.escapeDuplicate(
126
- method.parameters.map((p) => p.key),
127
- )(spec.key);
128
- }
129
- controller.routes.forEach((r, i) => {
130
- r.name = StringUtil.escapeDuplicate(
131
- controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
132
- )(r.name);
133
- });
134
- };
135
- }
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
+ if (collection === undefined) continue;
24
+
25
+ // PREPARE DIRECTORIES
26
+ const location: string = StringUtil.splitWithNormalization(path)
27
+ .filter((str) => str[0] !== "{" && str[0] !== ":")
28
+ .join("/");
29
+ for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
30
+
31
+ // INSERT ROUTES TO THE LAST DIRECTORY
32
+ const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
33
+ for (const [method, value] of Object.entries(collection)) {
34
+ if (
35
+ value === undefined ||
36
+ ["get", "post", "patch", "put", "delete"].includes(method) === false
37
+ )
38
+ continue;
39
+ const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
40
+ path,
41
+ method,
42
+ })(value);
43
+ if (r === null) continue;
44
+ routes.push({
45
+ endpoint: value,
46
+ route: r,
47
+ });
48
+ }
49
+ }
50
+
51
+ // GENERATE CONTROLLERS
52
+ const total: IMigrateController[] = [...endpoints.entries()]
53
+ .filter(([_l, routes]) => !!routes.length)
54
+ .map(([location, routes]) => {
55
+ const prefix: string = StringUtil.commonPrefix(
56
+ routes.map((e) => e.route.path),
57
+ );
58
+ for (const e of routes)
59
+ e.route.path = StringUtil.reJoinWithDecimalParameters(
60
+ e.route.path.replace(prefix, ""),
61
+ );
62
+ const controller: IMigrateController = {
63
+ name: StringUtil.pascal(location) + "Controller",
64
+ path: StringUtil.reJoinWithDecimalParameters(prefix),
65
+ location: "src/controllers/" + location,
66
+ routes: routes.map((e) => e.route),
67
+ };
68
+ emend(controller);
69
+
70
+ for (const e of routes)
71
+ props.dictionary.set(e.endpoint, {
72
+ controller,
73
+ route: e.route,
74
+ });
75
+ return controller;
76
+ });
77
+ for (const c of total)
78
+ if (c.name === "Controller")
79
+ c.name = StringUtil.escapeDuplicate([...total.map((c) => c.name)])(
80
+ "AppController",
81
+ );
82
+ return total;
83
+ };
84
+
85
+ const sequence = (location: string): string[] =>
86
+ StringUtil.splitWithNormalization(location)
87
+ .map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
88
+ .slice(0, -1)
89
+ .reverse();
90
+
91
+ const emend = (controller: IMigrateController): void => {
92
+ interface IRouteCapsule {
93
+ variables: string[];
94
+ route: IMigrateRoute;
95
+ }
96
+ const dict: Map<string, IRouteCapsule[]> = new Map();
97
+ for (const route of controller.routes) {
98
+ const additional: string[] = StringUtil.splitWithNormalization(
99
+ route.path,
100
+ );
101
+ const statics: string[] = additional.filter((str) => str[0] !== ":");
102
+ if (statics.length) route.name = StringUtil.camel(statics.join("/"));
103
+ else
104
+ MapUtil.take(dict)(route.method)(() => []).push({
105
+ variables: additional
106
+ .filter((str) => str[0] === ":")
107
+ .map((str) => str.substring(1)),
108
+ route,
109
+ });
110
+ }
111
+ for (const [method, capsules] of dict) {
112
+ const emended: string = method === "delete" ? "erase" : method;
113
+ for (const c of capsules) {
114
+ const empty: boolean = c.variables.length === 0;
115
+ c.route.name = empty
116
+ ? emended
117
+ : StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
118
+ }
119
+ }
120
+ for (const method of controller.routes) {
121
+ if (Escaper.variable(method.name) === false)
122
+ method.name = "_" + method.name;
123
+ for (const spec of [method.headers, method.query, method.body])
124
+ if (spec)
125
+ spec.key = StringUtil.escapeDuplicate(
126
+ method.parameters.map((p) => p.key),
127
+ )(spec.key);
128
+ }
129
+ controller.routes.forEach((r, i) => {
130
+ r.name = StringUtil.escapeDuplicate(
131
+ controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
132
+ )(r.name);
133
+ });
134
+ };
135
+ }