@nestia/migrate 0.11.4 → 0.11.6

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 (53) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +29 -4
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/utils/openapi-down-convert/converter.js +2 -2
  6. package/package.json +2 -2
  7. package/src/MigrateApplication.ts +81 -81
  8. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  9. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  10. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
  11. package/src/archivers/MigrateFileArchiver.ts +38 -38
  12. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  13. package/src/bundles/SDK_TEMPLATE.ts +29 -4
  14. package/src/executable/bundle.ts +110 -110
  15. package/src/internal/MigrateCommander.ts +70 -70
  16. package/src/internal/MigrateInquirer.ts +86 -86
  17. package/src/module.ts +14 -14
  18. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  19. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  20. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  21. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  22. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  23. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  24. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  28. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  29. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  30. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  31. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  32. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  33. package/src/structures/IMigrateDto.ts +8 -8
  34. package/src/structures/IMigrateProgram.ts +27 -27
  35. package/src/structures/IMigrateRoute.ts +51 -51
  36. package/src/structures/ISwagger.ts +23 -23
  37. package/src/structures/ISwaggerComponents.ts +14 -14
  38. package/src/structures/ISwaggerRoute.ts +20 -20
  39. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  40. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  41. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  42. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  43. package/src/structures/ISwaggerSchema.ts +90 -90
  44. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  45. package/src/structures/ISwaggerV20.ts +10 -10
  46. package/src/structures/ISwaggerV31.ts +10 -10
  47. package/src/utils/FilePrinter.ts +36 -36
  48. package/src/utils/OpenApiConverter.ts +19 -19
  49. package/src/utils/StringUtil.ts +60 -60
  50. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  51. package/src/utils/SwaggerTypeChecker.ts +67 -67
  52. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  53. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,81 +1,81 @@
1
- import typia, { IValidation } from "typia";
2
-
3
- import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
4
- import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
5
- import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
6
- import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
7
- import { MigrateApiStartProgrammer } from "./programmers/MigrateApiStartProgrammer";
8
- import { MigrateE2eProgrammer } from "./programmers/MigrateE2eProgrammer";
9
- import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
10
- import { IMigrateFile } from "./structures/IMigrateFile";
11
- import { IMigrateProgram } from "./structures/IMigrateProgram";
12
- import { ISwagger } from "./structures/ISwagger";
13
- import { ISwaggerV31 } from "./structures/ISwaggerV31";
14
- import { OpenApiConverter } from "./utils/OpenApiConverter";
15
-
16
- export class MigrateApplication {
17
- private constructor(public readonly swagger: ISwagger) {}
18
-
19
- public static async create(
20
- swagger: ISwagger | ISwaggerV31,
21
- ): Promise<IValidation<MigrateApplication>> {
22
- swagger = typia.is<ISwaggerV31.IVersion>(swagger)
23
- ? OpenApiConverter.v3_1(swagger)
24
- : swagger;
25
- const result = typia.validate<ISwagger>(swagger);
26
- if (result.success === false) return result;
27
- return {
28
- success: true,
29
- data: new MigrateApplication(swagger),
30
- errors: [],
31
- };
32
- }
33
-
34
- public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
35
- const program: IMigrateProgram = MigrateAnalyzer.analyze({
36
- mode: "nest",
37
- swagger: this.swagger,
38
- dictionary: new Map(),
39
- simulate: config.simulate,
40
- e2e: config.e2e,
41
- });
42
- return {
43
- program,
44
- files: [
45
- ...NEST_TEMPLATE,
46
- ...MigrateNestProgrammer.write(program),
47
- ...MigrateApiProgrammer.write(program),
48
- ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
49
- ],
50
- };
51
- }
52
-
53
- public sdk(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
54
- const program: IMigrateProgram = MigrateAnalyzer.analyze({
55
- mode: "sdk",
56
- swagger: this.swagger,
57
- dictionary: new Map(),
58
- simulate: config.simulate,
59
- e2e: config.e2e,
60
- });
61
- return {
62
- program,
63
- files: [
64
- ...SDK_TEMPLATE,
65
- ...MigrateApiProgrammer.write(program),
66
- MigrateApiStartProgrammer.write(program),
67
- ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
68
- ],
69
- };
70
- }
71
- }
72
- export namespace MigrateApplication {
73
- export interface IOutput {
74
- program: IMigrateProgram;
75
- files: IMigrateFile[];
76
- }
77
- export interface IConfig {
78
- simulate: boolean;
79
- e2e: boolean;
80
- }
81
- }
1
+ import typia, { IValidation } from "typia";
2
+
3
+ import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
4
+ import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
5
+ import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
6
+ import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
7
+ import { MigrateApiStartProgrammer } from "./programmers/MigrateApiStartProgrammer";
8
+ import { MigrateE2eProgrammer } from "./programmers/MigrateE2eProgrammer";
9
+ import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
10
+ import { IMigrateFile } from "./structures/IMigrateFile";
11
+ import { IMigrateProgram } from "./structures/IMigrateProgram";
12
+ import { ISwagger } from "./structures/ISwagger";
13
+ import { ISwaggerV31 } from "./structures/ISwaggerV31";
14
+ import { OpenApiConverter } from "./utils/OpenApiConverter";
15
+
16
+ export class MigrateApplication {
17
+ private constructor(public readonly swagger: ISwagger) {}
18
+
19
+ public static async create(
20
+ swagger: ISwagger | ISwaggerV31,
21
+ ): Promise<IValidation<MigrateApplication>> {
22
+ swagger = typia.is<ISwaggerV31.IVersion>(swagger)
23
+ ? OpenApiConverter.v3_1(swagger)
24
+ : swagger;
25
+ const result = typia.validate<ISwagger>(swagger);
26
+ if (result.success === false) return result;
27
+ return {
28
+ success: true,
29
+ data: new MigrateApplication(swagger),
30
+ errors: [],
31
+ };
32
+ }
33
+
34
+ public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
35
+ const program: IMigrateProgram = MigrateAnalyzer.analyze({
36
+ mode: "nest",
37
+ swagger: this.swagger,
38
+ dictionary: new Map(),
39
+ simulate: config.simulate,
40
+ e2e: config.e2e,
41
+ });
42
+ return {
43
+ program,
44
+ files: [
45
+ ...NEST_TEMPLATE,
46
+ ...MigrateNestProgrammer.write(program),
47
+ ...MigrateApiProgrammer.write(program),
48
+ ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
49
+ ],
50
+ };
51
+ }
52
+
53
+ public sdk(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
54
+ const program: IMigrateProgram = MigrateAnalyzer.analyze({
55
+ mode: "sdk",
56
+ swagger: this.swagger,
57
+ dictionary: new Map(),
58
+ simulate: config.simulate,
59
+ e2e: config.e2e,
60
+ });
61
+ return {
62
+ program,
63
+ files: [
64
+ ...SDK_TEMPLATE,
65
+ ...MigrateApiProgrammer.write(program),
66
+ MigrateApiStartProgrammer.write(program),
67
+ ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
68
+ ],
69
+ };
70
+ }
71
+ }
72
+ export namespace MigrateApplication {
73
+ export interface IOutput {
74
+ program: IMigrateProgram;
75
+ files: IMigrateFile[];
76
+ }
77
+ export interface IConfig {
78
+ simulate: boolean;
79
+ e2e: boolean;
80
+ }
81
+ }
@@ -1,9 +1,9 @@
1
- import { IMigrateProgram } from "../structures/IMigrateProgram";
2
- import { MigrateControllerAnalyzer } from "./MigrateControllerAnalyzer";
3
-
4
- export namespace MigrateAnalyzer {
5
- export const analyze = (props: IMigrateProgram.IProps): IMigrateProgram => ({
6
- ...props,
7
- controllers: MigrateControllerAnalyzer.analyze(props),
8
- });
9
- }
1
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
2
+ import { MigrateControllerAnalyzer } from "./MigrateControllerAnalyzer";
3
+
4
+ export namespace MigrateAnalyzer {
5
+ export const analyze = (props: IMigrateProgram.IProps): IMigrateProgram => ({
6
+ ...props,
7
+ controllers: MigrateControllerAnalyzer.analyze(props),
8
+ });
9
+ }
@@ -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
+ }