@nestia/migrate 0.7.4 → 0.7.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.
- package/lib/MigrateApplication.d.ts +9 -2
- package/lib/MigrateApplication.js +14 -8
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.js +2 -2
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/{ControllerAnalyzer.d.ts → MigrateControllerAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{ControllerAnalyzer.js → MigrateControllerAnalyzer.js} +11 -9
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -0
- package/lib/analyzers/{MethodAnalyzer.d.ts → MigrateMethodAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{MethodAnalyzer.js → MigrateMethodAnalyzer.js} +26 -25
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -0
- package/lib/archivers/{FileArchiver.d.ts → MigrateFileArchiver.d.ts} +1 -1
- package/lib/archivers/{FileArchiver.js → MigrateFileArchiver.js} +6 -6
- package/lib/archivers/MigrateFileArchiver.js.map +1 -0
- package/lib/bundles/NEST_TEMPLATE.js +3 -3
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/executable/bundle.js +1 -0
- package/lib/executable/bundle.js.map +1 -1
- package/lib/internal/MigrateCommander.js +3 -3
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/{ApiFileProgrammer.d.ts → MigrateApiFileProgrammer.d.ts} +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.js +28 -0
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -0
- package/lib/programmers/{ApiFunctionProgrammer.d.ts → MigrateApiFunctionProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiFunctionProgrammer.js → MigrateApiFunctionProgrammer.js} +10 -10
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -0
- package/lib/programmers/{ApiNamespaceProgrammer.d.ts → MigrateApiNamespaceProgrammer.d.ts} +3 -3
- package/lib/programmers/{ApiNamespaceProgrammer.js → MigrateApiNamespaceProgrammer.js} +19 -19
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -0
- package/lib/programmers/{ApiProgrammer.d.ts → MigrateApiProgrammer.d.ts} +1 -1
- package/lib/programmers/{ApiProgrammer.js → MigrateApiProgrammer.js} +25 -20
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -0
- package/lib/programmers/{ApiSimulatationProgrammer.d.ts → MigrateApiSimulatationProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiSimulatationProgrammer.js → MigrateApiSimulatationProgrammer.js} +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -0
- package/lib/programmers/{DtoProgrammer.d.ts → MigrateDtoProgrammer.d.ts} +3 -3
- package/lib/programmers/{DtoProgrammer.js → MigrateDtoProgrammer.js} +8 -8
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -0
- package/lib/programmers/{ImportProgrammer.d.ts → MigrateImportProgrammer.d.ts} +3 -3
- package/lib/programmers/{ImportProgrammer.js → MigrateImportProgrammer.js} +7 -5
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -0
- package/lib/programmers/{NestControllerProgrammer.d.ts → MigrateNestControllerProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestControllerProgrammer.js → MigrateNestControllerProgrammer.js} +11 -11
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -0
- package/lib/programmers/{NestMethodProgrammer.d.ts → MigrateNestMethodProgrammer.d.ts} +3 -3
- package/lib/programmers/{NestMethodProgrammer.js → MigrateNestMethodProgrammer.js} +13 -11
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -0
- package/lib/programmers/{NestModuleProgrammer.d.ts → MigrateNestModuleProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestModuleProgrammer.js → MigrateNestModuleProgrammer.js} +8 -8
- package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -0
- package/lib/programmers/{NestProgrammer.d.ts → MigrateNestProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestProgrammer.js → MigrateNestProgrammer.js} +17 -15
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -0
- package/lib/programmers/{SchemaProgrammer.d.ts → MigrateSchemaProgrammer.d.ts} +3 -3
- package/lib/programmers/{SchemaProgrammer.js → MigrateSchemaProgrammer.js} +23 -23
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -0
- package/lib/structures/IMigrateRoute.d.ts +1 -0
- package/lib/utils/FilePrinter.d.ts +1 -1
- package/lib/utils/FilePrinter.js +1 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/{JsonTypeChecker.d.ts → SwaggerTypeChecker.d.ts} +1 -1
- package/lib/utils/SwaggerTypeChecker.js +34 -0
- package/lib/utils/SwaggerTypeChecker.js.map +1 -0
- package/package.json +68 -68
- package/src/IMigrateConfig.ts +4 -4
- package/src/MigrateApplication.ts +48 -35
- package/src/analyzers/MigrateAnalyzer.ts +13 -13
- package/src/analyzers/{ControllerAnalyzer.ts → MigrateControllerAnalyzer.ts} +122 -123
- package/src/analyzers/{MethodAnalyzer.ts → MigrateMethodAnalyzer.ts} +348 -347
- package/src/archivers/{FileArchiver.ts → MigrateFileArchiver.ts} +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +3 -3
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/bundle.ts +109 -108
- package/src/executable/migrate.ts +7 -7
- package/src/internal/MigrateCommander.ts +51 -52
- package/src/internal/MigrateInquirer.ts +79 -79
- package/src/module.ts +4 -4
- package/src/programmers/{ApiFileProgrammer.ts → MigrateApiFileProgrammer.ts} +53 -53
- package/src/programmers/{ApiFunctionProgrammer.ts → MigrateApiFunctionProgrammer.ts} +203 -203
- package/src/programmers/{ApiNamespaceProgrammer.ts → MigrateApiNamespaceProgrammer.ts} +430 -418
- package/src/programmers/{ApiProgrammer.ts → MigrateApiProgrammer.ts} +132 -128
- package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts} +328 -328
- package/src/programmers/{DtoProgrammer.ts → MigrateDtoProgrammer.ts} +78 -74
- package/src/programmers/{ImportProgrammer.ts → MigrateImportProgrammer.ts} +116 -114
- package/src/programmers/{NestControllerProgrammer.ts → MigrateNestControllerProgrammer.ts} +50 -48
- package/src/programmers/{NestMethodProgrammer.ts → MigrateNestMethodProgrammer.ts} +249 -243
- package/src/programmers/{NestModuleProgrammer.ts → MigrateNestModuleProgrammer.ts} +62 -62
- package/src/programmers/{NestProgrammer.ts → MigrateNestProgrammer.ts} +74 -74
- package/src/programmers/{SchemaProgrammer.ts → MigrateSchemaProgrammer.ts} +257 -255
- package/src/structures/IMigrateProgram.ts +9 -9
- package/src/structures/IMigrateRoute.ts +46 -45
- package/src/structures/ISwaggeSchema.ts +90 -90
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/{JsonTypeChecker.ts → SwaggerTypeChecker.ts} +67 -67
- package/lib/analyzers/ControllerAnalyzer.js.map +0 -1
- package/lib/analyzers/MethodAnalyzer.js.map +0 -1
- package/lib/archivers/FileArchiver.js.map +0 -1
- package/lib/programmers/ApiFileProgrammer.js +0 -28
- package/lib/programmers/ApiFileProgrammer.js.map +0 -1
- package/lib/programmers/ApiFunctionProgrammer.js.map +0 -1
- package/lib/programmers/ApiNamespaceProgrammer.js.map +0 -1
- package/lib/programmers/ApiProgrammer.js.map +0 -1
- package/lib/programmers/ApiSimulatationProgrammer.js.map +0 -1
- package/lib/programmers/DtoProgrammer.js.map +0 -1
- package/lib/programmers/ImportProgrammer.js.map +0 -1
- package/lib/programmers/NestControllerProgrammer.js.map +0 -1
- package/lib/programmers/NestMethodProgrammer.js.map +0 -1
- package/lib/programmers/NestModuleProgrammer.js.map +0 -1
- package/lib/programmers/NestProgrammer.js.map +0 -1
- package/lib/programmers/SchemaProgrammer.js.map +0 -1
- package/lib/utils/JsonTypeChecker.js +0 -34
- package/lib/utils/JsonTypeChecker.js.map +0 -1
package/package.json
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
{
|
2
|
-
"name": "@nestia/migrate",
|
3
|
-
"version": "0.7.
|
4
|
-
"description": "Migration program from swagger to NestJS",
|
5
|
-
"main": "lib/index.js",
|
6
|
-
"typings": "lib/index.d.ts",
|
7
|
-
"bin": {
|
8
|
-
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
-
},
|
10
|
-
"scripts": {
|
11
|
-
"build": "rimraf lib && tsc",
|
12
|
-
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
-
"dev": "npm run build -- --watch",
|
14
|
-
"prepare": "ts-patch install && typia patch && npm run bundle",
|
15
|
-
"test": "node lib/test"
|
16
|
-
},
|
17
|
-
"repository": {
|
18
|
-
"type": "git",
|
19
|
-
"url": "https://github.com/samchon/nestia"
|
20
|
-
},
|
21
|
-
"keywords": [
|
22
|
-
"migration",
|
23
|
-
"swagger",
|
24
|
-
"NestJS",
|
25
|
-
"nestia"
|
26
|
-
],
|
27
|
-
"author": "Jeongho Nam",
|
28
|
-
"license": "MIT",
|
29
|
-
"bugs": {
|
30
|
-
"url": "https://github.com/samchon/nestia/issues"
|
31
|
-
},
|
32
|
-
"homepage": "https://github.com/samchon/nestia#readme",
|
33
|
-
"devDependencies": {
|
34
|
-
"@nestia/core": "2.5.
|
35
|
-
"@nestia/fetcher": "2.5.
|
36
|
-
"@nestjs/common": "^10.3.1",
|
37
|
-
"@nestjs/core": "^10.3.1",
|
38
|
-
"@nestjs/platform-express": "^10.3.1",
|
39
|
-
"@nestjs/platform-fastify": "^10.3.1",
|
40
|
-
"@types/express": "^4.17.21",
|
41
|
-
"@types/inquirer": "^9.0.7",
|
42
|
-
"@types/node": "^20.3.3",
|
43
|
-
"dotenv": "^16.3.1",
|
44
|
-
"dotenv-expand": "^10.0.0",
|
45
|
-
"rimraf": "^5.0.1",
|
46
|
-
"serialize-error": "^4.1.0",
|
47
|
-
"source-map-support": "^0.5.21",
|
48
|
-
"ts-node": "^10.9.1",
|
49
|
-
"ts-patch": "^3.1.0",
|
50
|
-
"tstl": "^2.5.13",
|
51
|
-
"typescript-transform-paths": "^3.4.6"
|
52
|
-
},
|
53
|
-
"dependencies": {
|
54
|
-
"commander": "10.0.0",
|
55
|
-
"inquirer": "8.2.5",
|
56
|
-
"typescript": "^5.3.3",
|
57
|
-
"typia": "^5.4.
|
58
|
-
},
|
59
|
-
"files": [
|
60
|
-
"lib",
|
61
|
-
"src",
|
62
|
-
"!lib/test",
|
63
|
-
"!src/test",
|
64
|
-
"package.json",
|
65
|
-
"README.md",
|
66
|
-
"LICENSE"
|
67
|
-
]
|
68
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@nestia/migrate",
|
3
|
+
"version": "0.7.6",
|
4
|
+
"description": "Migration program from swagger to NestJS",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"typings": "lib/index.d.ts",
|
7
|
+
"bin": {
|
8
|
+
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"build": "rimraf lib && tsc",
|
12
|
+
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
+
"dev": "npm run build -- --watch",
|
14
|
+
"prepare": "ts-patch install && typia patch && npm run bundle",
|
15
|
+
"test": "node lib/test"
|
16
|
+
},
|
17
|
+
"repository": {
|
18
|
+
"type": "git",
|
19
|
+
"url": "https://github.com/samchon/nestia"
|
20
|
+
},
|
21
|
+
"keywords": [
|
22
|
+
"migration",
|
23
|
+
"swagger",
|
24
|
+
"NestJS",
|
25
|
+
"nestia"
|
26
|
+
],
|
27
|
+
"author": "Jeongho Nam",
|
28
|
+
"license": "MIT",
|
29
|
+
"bugs": {
|
30
|
+
"url": "https://github.com/samchon/nestia/issues"
|
31
|
+
},
|
32
|
+
"homepage": "https://github.com/samchon/nestia#readme",
|
33
|
+
"devDependencies": {
|
34
|
+
"@nestia/core": "2.5.4",
|
35
|
+
"@nestia/fetcher": "2.5.4",
|
36
|
+
"@nestjs/common": "^10.3.1",
|
37
|
+
"@nestjs/core": "^10.3.1",
|
38
|
+
"@nestjs/platform-express": "^10.3.1",
|
39
|
+
"@nestjs/platform-fastify": "^10.3.1",
|
40
|
+
"@types/express": "^4.17.21",
|
41
|
+
"@types/inquirer": "^9.0.7",
|
42
|
+
"@types/node": "^20.3.3",
|
43
|
+
"dotenv": "^16.3.1",
|
44
|
+
"dotenv-expand": "^10.0.0",
|
45
|
+
"rimraf": "^5.0.1",
|
46
|
+
"serialize-error": "^4.1.0",
|
47
|
+
"source-map-support": "^0.5.21",
|
48
|
+
"ts-node": "^10.9.1",
|
49
|
+
"ts-patch": "^3.1.0",
|
50
|
+
"tstl": "^2.5.13",
|
51
|
+
"typescript-transform-paths": "^3.4.6"
|
52
|
+
},
|
53
|
+
"dependencies": {
|
54
|
+
"commander": "10.0.0",
|
55
|
+
"inquirer": "8.2.5",
|
56
|
+
"typescript": "^5.3.3",
|
57
|
+
"typia": "^5.4.5"
|
58
|
+
},
|
59
|
+
"files": [
|
60
|
+
"lib",
|
61
|
+
"src",
|
62
|
+
"!lib/test",
|
63
|
+
"!src/test",
|
64
|
+
"package.json",
|
65
|
+
"README.md",
|
66
|
+
"LICENSE"
|
67
|
+
]
|
68
|
+
}
|
package/src/IMigrateConfig.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export interface IMigrateConfig {
|
2
|
-
mode: "nest" | "sdk";
|
3
|
-
simulate: boolean;
|
4
|
-
}
|
1
|
+
export interface IMigrateConfig {
|
2
|
+
mode: "nest" | "sdk";
|
3
|
+
simulate: boolean;
|
4
|
+
}
|
@@ -1,35 +1,48 @@
|
|
1
|
-
import typia 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 {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
import typia 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 { IMigrateProgram } from "./module";
|
7
|
+
import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
|
8
|
+
import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
|
9
|
+
import { IMigrateFile } from "./structures/IMigrateFile";
|
10
|
+
import { ISwagger } from "./structures/ISwagger";
|
11
|
+
|
12
|
+
export class MigrateApplication {
|
13
|
+
public constructor(public readonly swagger: ISwagger) {
|
14
|
+
typia.assert(swagger);
|
15
|
+
}
|
16
|
+
|
17
|
+
public nest(simulate: boolean): MigrateApplication.IOutput {
|
18
|
+
const program: IMigrateProgram = MigrateAnalyzer.analyze({
|
19
|
+
mode: "nest",
|
20
|
+
simulate,
|
21
|
+
})(this.swagger);
|
22
|
+
return {
|
23
|
+
program,
|
24
|
+
files: [
|
25
|
+
...NEST_TEMPLATE,
|
26
|
+
...MigrateNestProgrammer.write(program),
|
27
|
+
...MigrateApiProgrammer.write(program),
|
28
|
+
],
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
public sdk(simulate: boolean): MigrateApplication.IOutput {
|
33
|
+
const program: IMigrateProgram = MigrateAnalyzer.analyze({
|
34
|
+
mode: "sdk",
|
35
|
+
simulate,
|
36
|
+
})(this.swagger);
|
37
|
+
return {
|
38
|
+
program,
|
39
|
+
files: [...SDK_TEMPLATE, ...MigrateApiProgrammer.write(program)],
|
40
|
+
};
|
41
|
+
}
|
42
|
+
}
|
43
|
+
export namespace MigrateApplication {
|
44
|
+
export interface IOutput {
|
45
|
+
program: IMigrateProgram;
|
46
|
+
files: IMigrateFile[];
|
47
|
+
}
|
48
|
+
}
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import { IMigrateConfig } from "../IMigrateConfig";
|
2
|
-
import { IMigrateProgram, ISwagger } from "../module";
|
3
|
-
import {
|
4
|
-
|
5
|
-
export namespace MigrateAnalyzer {
|
6
|
-
export const analyze =
|
7
|
-
(config: IMigrateConfig) =>
|
8
|
-
(swagger: ISwagger): IMigrateProgram => ({
|
9
|
-
config,
|
10
|
-
swagger,
|
11
|
-
controllers:
|
12
|
-
});
|
13
|
-
}
|
1
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
2
|
+
import { IMigrateProgram, ISwagger } from "../module";
|
3
|
+
import { MigrateControllerAnalyzer } from "./MigrateControllerAnalyzer";
|
4
|
+
|
5
|
+
export namespace MigrateAnalyzer {
|
6
|
+
export const analyze =
|
7
|
+
(config: IMigrateConfig) =>
|
8
|
+
(swagger: ISwagger): IMigrateProgram => ({
|
9
|
+
config,
|
10
|
+
swagger,
|
11
|
+
controllers: MigrateControllerAnalyzer.analyze(swagger),
|
12
|
+
});
|
13
|
+
}
|
@@ -1,123 +1,122 @@
|
|
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 {
|
9
|
-
|
10
|
-
export namespace
|
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 =
|
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(
|
117
|
-
|
118
|
-
(
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
}
|
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
|
+
}
|