@nestia/migrate 0.5.1 → 0.6.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 (103) hide show
  1. package/lib/{NestiaMigrateApplication.d.ts → MigrateApplication.d.ts} +1 -1
  2. package/lib/{NestiaMigrateApplication.js → MigrateApplication.js} +38 -32
  3. package/lib/MigrateApplication.js.map +1 -0
  4. package/lib/analyzers/ControllerAnalyzer.d.ts +5 -0
  5. package/lib/{programmers/ControllerProgrammer.js → analyzers/ControllerAnalyzer.js} +8 -32
  6. package/lib/analyzers/ControllerAnalyzer.js.map +1 -0
  7. package/lib/analyzers/MethodAnalyzer.d.ts +9 -0
  8. package/lib/{programmers/RouteProgrammer.js → analyzers/MethodAnalyzer.js} +30 -134
  9. package/lib/analyzers/MethodAnalyzer.js.map +1 -0
  10. package/lib/analyzers/MigrateAnalyzer.d.ts +4 -0
  11. package/lib/analyzers/MigrateAnalyzer.js +12 -0
  12. package/lib/analyzers/MigrateAnalyzer.js.map +1 -0
  13. package/lib/analyzers/RouteAnalyzer.d.ts +0 -0
  14. package/lib/analyzers/RouteAnalyzer.js +2 -0
  15. package/lib/analyzers/RouteAnalyzer.js.map +1 -0
  16. package/lib/archivers/FileArchiver.js.map +1 -1
  17. package/lib/bundles/TEMPLATE.js +10 -10
  18. package/lib/bundles/TEMPLATE.js.map +1 -1
  19. package/lib/executable/bundle.js.map +1 -1
  20. package/lib/executable/migrate.js +7 -7
  21. package/lib/executable/migrate.js.map +1 -1
  22. package/lib/module.d.ts +1 -1
  23. package/lib/module.js +1 -1
  24. package/lib/module.js.map +1 -1
  25. package/lib/programmers/DtoProgrammer.d.ts +8 -4
  26. package/lib/programmers/DtoProgrammer.js +36 -77
  27. package/lib/programmers/DtoProgrammer.js.map +1 -1
  28. package/lib/programmers/ImportProgrammer.d.ts +5 -5
  29. package/lib/programmers/ImportProgrammer.js +27 -19
  30. package/lib/programmers/ImportProgrammer.js.map +1 -1
  31. package/lib/programmers/{ControllerProgrammer.d.ts → NestControllerProgrammer.d.ts} +3 -4
  32. package/lib/programmers/NestControllerProgrammer.js +30 -0
  33. package/lib/programmers/NestControllerProgrammer.js.map +1 -0
  34. package/lib/programmers/NestMethodProgrammer.d.ts +7 -0
  35. package/lib/programmers/NestMethodProgrammer.js +103 -0
  36. package/lib/programmers/NestMethodProgrammer.js.map +1 -0
  37. package/lib/programmers/NestModuleProgrammer.d.ts +5 -0
  38. package/lib/programmers/NestModuleProgrammer.js +29 -0
  39. package/lib/programmers/NestModuleProgrammer.js.map +1 -0
  40. package/lib/programmers/NestProgrammer.d.ts +5 -0
  41. package/lib/programmers/NestProgrammer.js +60 -0
  42. package/lib/programmers/NestProgrammer.js.map +1 -0
  43. package/lib/programmers/SchemaProgrammer.d.ts +2 -1
  44. package/lib/programmers/SchemaProgrammer.js +122 -189
  45. package/lib/programmers/SchemaProgrammer.js.map +1 -1
  46. package/lib/structures/IMigrateProgram.d.ts +2 -2
  47. package/lib/structures/ISwaggerInfo.d.ts +3 -3
  48. package/lib/utils/FilePrinter.d.ts +9 -0
  49. package/lib/utils/FilePrinter.js +25 -0
  50. package/lib/utils/FilePrinter.js.map +1 -0
  51. package/lib/utils/JsonTypeChecker.d.ts +3 -1
  52. package/lib/utils/JsonTypeChecker.js +31 -18
  53. package/lib/utils/JsonTypeChecker.js.map +1 -1
  54. package/lib/utils/MapUtil.js.map +1 -1
  55. package/lib/utils/SetupWizard.js.map +1 -1
  56. package/lib/utils/StringUtil.js.map +1 -1
  57. package/package.json +8 -6
  58. package/src/MigrateApplication.ts +73 -0
  59. package/src/analyzers/ControllerAnalyzer.ts +107 -0
  60. package/src/analyzers/MethodAnalyzer.ts +315 -0
  61. package/src/analyzers/MigrateAnalyzer.ts +9 -0
  62. package/src/analyzers/RouteAnalyzer.ts +0 -0
  63. package/src/archivers/FileArchiver.ts +35 -38
  64. package/src/bundles/TEMPLATE.ts +10 -10
  65. package/src/executable/bundle.ts +72 -78
  66. package/src/executable/migrate.ts +59 -60
  67. package/src/index.ts +4 -4
  68. package/src/module.ts +4 -4
  69. package/src/programmers/DtoProgrammer.ts +74 -118
  70. package/src/programmers/ImportProgrammer.ts +98 -60
  71. package/src/programmers/NestControllerProgrammer.ts +47 -0
  72. package/src/programmers/NestMethodProgrammer.ts +211 -0
  73. package/src/programmers/NestModuleProgrammer.ts +62 -0
  74. package/src/programmers/NestProgrammer.ts +74 -0
  75. package/src/programmers/SchemaProgrammer.ts +247 -339
  76. package/src/structures/IMigrateController.ts +8 -8
  77. package/src/structures/IMigrateDto.ts +8 -8
  78. package/src/structures/IMigrateFile.ts +5 -5
  79. package/src/structures/IMigrateProgram.ts +7 -7
  80. package/src/structures/IMigrateRoute.ts +36 -36
  81. package/src/structures/IMigrateSchema.ts +4 -4
  82. package/src/structures/ISwaggeSchema.ts +82 -82
  83. package/src/structures/ISwagger.ts +20 -20
  84. package/src/structures/ISwaggerComponents.ts +7 -7
  85. package/src/structures/ISwaggerInfo.ts +57 -57
  86. package/src/structures/ISwaggerRoute.ts +52 -52
  87. package/src/structures/ISwaggerSecurity.ts +47 -47
  88. package/src/utils/FilePrinter.ts +36 -0
  89. package/src/utils/JsonTypeChecker.ts +67 -52
  90. package/src/utils/MapUtil.ts +13 -13
  91. package/src/utils/SetupWizard.ts +15 -15
  92. package/src/utils/StringUtil.ts +51 -51
  93. package/lib/NestiaMigrateApplication.js.map +0 -1
  94. package/lib/programmers/ControllerProgrammer.js.map +0 -1
  95. package/lib/programmers/MigrateProgrammer.d.ts +0 -8
  96. package/lib/programmers/MigrateProgrammer.js +0 -48
  97. package/lib/programmers/MigrateProgrammer.js.map +0 -1
  98. package/lib/programmers/RouteProgrammer.d.ts +0 -13
  99. package/lib/programmers/RouteProgrammer.js.map +0 -1
  100. package/src/NestiaMigrateApplication.ts +0 -73
  101. package/src/programmers/ControllerProgrammer.ts +0 -157
  102. package/src/programmers/MigrateProgrammer.ts +0 -62
  103. package/src/programmers/RouteProgrammer.ts +0 -506
@@ -1,157 +0,0 @@
1
- import { IMigrateController } from "../structures/IMigrateController";
2
- import { IMigrateRoute } from "../structures/IMigrateRoute";
3
- import { ISwaggerSchema } from "../structures/ISwaggeSchema";
4
- import { ISwagger } from "../structures/ISwagger";
5
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
- import { MapUtil } from "../utils/MapUtil";
7
- import { StringUtil } from "../utils/StringUtil";
8
- import { ImportProgrammer } from "./ImportProgrammer";
9
- import { RouteProgrammer } from "./RouteProgrammer";
10
-
11
- export namespace ControllerProgrammer {
12
- export const analyze = (swagger: ISwagger): IMigrateController[] => {
13
- const dict: Map<string, IMigrateRoute[]> = new Map();
14
-
15
- // GATHER ROUTES
16
- for (const [path, collection] of Object.entries(swagger.paths)) {
17
- // PREPARE DIRECTORIES
18
- const location: string = StringUtil.splitWithNormalization(path)
19
- .filter((str) => str[0] !== "{" && str[0] !== ":")
20
- .join("/");
21
- for (const s of sequence(location)) MapUtil.take(dict)(s)(() => []);
22
-
23
- // INSERT ROUTES TO THE LAST DIRECTORY
24
- const routes: IMigrateRoute[] = MapUtil.take(dict)(location)(
25
- () => [],
26
- );
27
- for (const [method, value] of Object.entries(collection)) {
28
- const r: IMigrateRoute | null = RouteProgrammer.analyze(
29
- swagger,
30
- )({
31
- path,
32
- method,
33
- })(value);
34
- if (r !== null) routes.push(r);
35
- }
36
- }
37
-
38
- // ABSORB STANDALONE ROUTES
39
- const emended: Map<string, IMigrateRoute[]> = new Map(
40
- [...dict.entries()].sort((a, b) => a[0].localeCompare(b[0])),
41
- );
42
- for (const [location, routes] of emended) {
43
- if (routes.length !== 1) continue;
44
- for (const s of sequence(location).slice(0, 1)) {
45
- const parent = emended.get(s);
46
- if (parent) {
47
- parent.push(...routes);
48
- emended.delete(location);
49
- break;
50
- }
51
- }
52
- }
53
-
54
- // GENERATE CONTROLLERS
55
- return [...emended.entries()]
56
- .filter(([_l, routes]) => !!routes.length)
57
- .map(([location, routes]) => {
58
- const prefix: string = StringUtil.commonPrefix(
59
- routes.map((r) => r.path),
60
- );
61
- for (const r of routes)
62
- r.path = StringUtil.reJoinWithDecimalParameters(
63
- r.path.replace(prefix, ""),
64
- );
65
- const controller: IMigrateController = {
66
- name: StringUtil.pascal(location) + "Controller",
67
- path: StringUtil.reJoinWithDecimalParameters(prefix),
68
- location: "src/controllers/" + location,
69
- routes,
70
- };
71
- if (controller.name === "Controller")
72
- controller.name = "__Controller";
73
- naming(controller);
74
- return controller;
75
- });
76
- };
77
-
78
- const sequence = (location: string): string[] =>
79
- StringUtil.splitWithNormalization(location)
80
- .map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
81
- .slice(0, -1)
82
- .reverse();
83
-
84
- const naming = (controller: IMigrateController): void => {
85
- interface IRouteCapsule {
86
- variables: string[];
87
- route: IMigrateRoute;
88
- }
89
- const dict: Map<string, IRouteCapsule[]> = new Map();
90
- for (const route of controller.routes) {
91
- const additional: string[] = StringUtil.splitWithNormalization(
92
- route.path,
93
- );
94
- const statics: string[] = additional.filter(
95
- (str) => str[0] !== ":",
96
- );
97
- if (statics.length)
98
- route.name = StringUtil.camel(statics.join("/"));
99
- else
100
- MapUtil.take(dict)(route.method)(() => []).push({
101
- variables: additional
102
- .filter((str) => str[0] === ":")
103
- .map((str) => str.substring(1)),
104
- route,
105
- });
106
- }
107
-
108
- for (const [method, capsules] of dict) {
109
- const emended: string = method === "delete" ? "erase" : method;
110
- for (const c of capsules) {
111
- const empty: boolean = c.variables.length === 0;
112
- c.route.name = empty
113
- ? emended
114
- : StringUtil.camel(
115
- `${emended}By/${c.variables.join("/and/")}`,
116
- );
117
- }
118
- }
119
- };
120
-
121
- export const write =
122
- (components: ISwaggerComponents) =>
123
- (controller: IMigrateController): string => {
124
- const importer: ImportProgrammer = new ImportProgrammer(null);
125
- const references: ISwaggerSchema.IReference[] = [];
126
- const body: string = [
127
- `@${importer.external({
128
- library: "@nestjs/common",
129
- instance: "Controller",
130
- })}(${JSON.stringify(controller.path)})`,
131
- `export class ${controller.name} {`,
132
- controller.routes
133
- .map((r) =>
134
- RouteProgrammer.write(components)(references)(importer)(
135
- r,
136
- )
137
- .split("\n")
138
- .map((l) => ` ${l}`)
139
- .join("\n"),
140
- )
141
- .join("\n\n"),
142
- `}`,
143
- ].join("\n");
144
- return [
145
- ...importer.toScript(
146
- (ref) =>
147
- `${"../".repeat(
148
- StringUtil.splitWithNormalization(
149
- controller.location,
150
- ).length - 1,
151
- )}api/structures/${ref}`,
152
- ),
153
- ...(importer.empty() ? [] : [""]),
154
- body,
155
- ].join("\n");
156
- };
157
- }
@@ -1,62 +0,0 @@
1
- import { IMigrateController } from "../structures/IMigrateController";
2
- import { IMigrateDto } from "../structures/IMigrateDto";
3
- import { IMigrateFile } from "../structures/IMigrateFile";
4
- import { IMigrateProgram } from "../structures/IMigrateProgram";
5
- import { ISwagger } from "../structures/ISwagger";
6
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
7
- import { ControllerProgrammer } from "./ControllerProgrammer";
8
- import { DtoProgrammer } from "./DtoProgrammer";
9
-
10
- export namespace MigrateProgrammer {
11
- export const analyze = (swagger: ISwagger): IMigrateProgram => {
12
- const controllers: IMigrateController[] =
13
- ControllerProgrammer.analyze(swagger);
14
- const structures: IMigrateDto[] = DtoProgrammer.analyze(swagger);
15
- return {
16
- controllers,
17
- structures,
18
- };
19
- };
20
-
21
- export const write =
22
- (components: ISwaggerComponents) =>
23
- (program: IMigrateProgram): IMigrateFile[] => {
24
- return [
25
- ...program.structures.map((s) => ({
26
- location: s.location,
27
- file: `${s.name}.ts`,
28
- content: DtoProgrammer.write(components)(s),
29
- })),
30
- ...program.controllers.map((c) => ({
31
- location: c.location,
32
- file: `${c.name}.ts`,
33
- content: ControllerProgrammer.write(components)(c),
34
- })),
35
- {
36
- location: "src",
37
- file: "MyModule.ts",
38
- content: MyModule(program.controllers),
39
- },
40
- ];
41
- };
42
- }
43
-
44
- const MyModule = (controllers: IMigrateController[]): string =>
45
- [
46
- `import { Module } from "@nestjs/common";`,
47
- ``,
48
- ...controllers.map(
49
- (c) =>
50
- `import { ${c.name} } from "${c.location.replace(
51
- "src/",
52
- "./",
53
- )}/${c.name}";`,
54
- ),
55
- ``,
56
- `@Module({`,
57
- ` controllers: [`,
58
- ...controllers.map((c) => ` ${c.name},`),
59
- ` ],`,
60
- `})`,
61
- `export class MyModule {}`,
62
- ].join("\n");