@nestia/migrate 4.6.1-dev.20250117 → 4.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 (49) hide show
  1. package/README.md +87 -87
  2. package/lib/bundles/NEST_TEMPLATE.js +66 -66
  3. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  4. package/lib/bundles/SDK_TEMPLATE.js +30 -30
  5. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  6. package/lib/index.mjs +92 -92
  7. package/lib/utils/openapi-down-convert/converter.js +2 -2
  8. package/package.json +6 -6
  9. package/src/MigrateApplication.ts +107 -107
  10. package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
  12. package/src/archivers/MigrateFileArchiver.ts +38 -38
  13. package/src/bundles/NEST_TEMPLATE.ts +66 -66
  14. package/src/bundles/SDK_TEMPLATE.ts +30 -30
  15. package/src/executable/bundle.js +125 -125
  16. package/src/executable/migrate.ts +7 -7
  17. package/src/factories/TypeLiteralFactory.ts +57 -57
  18. package/src/index.ts +4 -4
  19. package/src/internal/MigrateCommander.ts +86 -86
  20. package/src/internal/MigrateInquirer.ts +89 -89
  21. package/src/module.ts +8 -8
  22. package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
  23. package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
  24. package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
  25. package/src/programmers/MigrateApiProgrammer.ts +103 -103
  26. package/src/programmers/MigrateApiSimulatationProgrammer.ts +324 -324
  27. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  28. package/src/programmers/MigrateDtoProgrammer.ts +87 -87
  29. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  30. package/src/programmers/MigrateE2eProgrammer.ts +34 -34
  31. package/src/programmers/MigrateImportProgrammer.ts +118 -118
  32. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  33. package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
  34. package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
  35. package/src/programmers/MigrateNestProgrammer.ts +81 -81
  36. package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
  37. package/src/structures/IHttpMigrateController.ts +8 -8
  38. package/src/structures/IHttpMigrateDto.ts +8 -8
  39. package/src/structures/IHttpMigrateFile.ts +5 -5
  40. package/src/structures/IHttpMigrateProgram.ts +27 -27
  41. package/src/structures/IHttpMigrateRoute.ts +1 -1
  42. package/src/structures/IHttpMigrateSchema.ts +4 -4
  43. package/src/utils/FilePrinter.ts +36 -36
  44. package/src/utils/MapUtil.ts +13 -13
  45. package/src/utils/OpenApiTypeChecker.ts +73 -73
  46. package/src/utils/SetupWizard.ts +12 -12
  47. package/src/utils/StringUtil.ts +113 -113
  48. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  49. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -352,8 +352,8 @@ class Converter {
352
352
  this.log(`Converting openIdConnect security scheme to oauth2/authorizationCode`);
353
353
  scheme.type = "oauth2";
354
354
  const openIdConnectUrl = scheme.openIdConnectUrl;
355
- scheme.description = `OAuth2 Authorization Code Flow. The client may
356
- GET the OpenID Connect configuration JSON from \`${openIdConnectUrl}\`
355
+ scheme.description = `OAuth2 Authorization Code Flow. The client may
356
+ GET the OpenID Connect configuration JSON from \`${openIdConnectUrl}\`
357
357
  to get the correct \`authorizationUrl\` and \`tokenUrl\`.`;
358
358
  delete scheme.openIdConnectUrl;
359
359
  const scopes = oauth2Scopes(schemeName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/migrate",
3
- "version": "4.6.1-dev.20250117",
3
+ "version": "4.6.1",
4
4
  "description": "Migration program from swagger to NestJS",
5
5
  "typings": "lib/index.d.ts",
6
6
  "main": "lib/index.js",
@@ -41,10 +41,10 @@
41
41
  "@nestia/core": "workspace:^",
42
42
  "@nestia/e2e": "workspace:^",
43
43
  "@nestia/fetcher": "workspace:^",
44
- "@nestjs/common": "^11.0.1",
45
- "@nestjs/core": "^11.0.1",
46
- "@nestjs/platform-express": "^11.0.1",
47
- "@nestjs/platform-fastify": "^11.0.1",
44
+ "@nestjs/common": "^11.0.2",
45
+ "@nestjs/core": "^11.0.2",
46
+ "@nestjs/platform-express": "^11.0.2",
47
+ "@nestjs/platform-fastify": "^11.0.2",
48
48
  "@rollup/plugin-terser": "^0.4.4",
49
49
  "@rollup/plugin-typescript": "^12.1.1",
50
50
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
@@ -71,7 +71,7 @@
71
71
  "typescript-transform-paths": "^3.5.2"
72
72
  },
73
73
  "dependencies": {
74
- "@nestia/sdk": "^4.6.1-dev.20250117",
74
+ "@nestia/sdk": "^4.6.1",
75
75
  "@samchon/openapi": "^2.4.0",
76
76
  "commander": "10.0.0",
77
77
  "inquirer": "8.2.5",
@@ -1,107 +1,107 @@
1
- import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
- import typia, { IValidation } from "typia";
3
-
4
- import { MigrateApplicationAnalyzer } from "./analyzers/MigrateApplicationAnalyzer";
5
- import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
6
- import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
7
- import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
8
- import { MigrateApiStartProgrammer } from "./programmers/MigrateApiStartProgrammer";
9
- import { MigrateE2eProgrammer } from "./programmers/MigrateE2eProgrammer";
10
- import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
11
- import { IHttpMigrateFile } from "./structures/IHttpMigrateFile";
12
- import { IHttpMigrateProgram } from "./structures/IHttpMigrateProgram";
13
-
14
- export class MigrateApplication {
15
- private constructor(public readonly document: OpenApi.IDocument) {}
16
-
17
- public static create(
18
- document:
19
- | SwaggerV2.IDocument
20
- | OpenApiV3.IDocument
21
- | OpenApiV3_1.IDocument
22
- | OpenApi.IDocument,
23
- ): IValidation<MigrateApplication> {
24
- const result: IValidation<
25
- | SwaggerV2.IDocument
26
- | OpenApiV3.IDocument
27
- | OpenApiV3_1.IDocument
28
- | OpenApi.IDocument
29
- > = typia.validate(document);
30
- if (result.success === false) return result;
31
- return {
32
- success: true,
33
- data: new MigrateApplication(OpenApi.convert(document)),
34
- };
35
- }
36
-
37
- public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
38
- const program: IHttpMigrateProgram = MigrateApplicationAnalyzer.analyze({
39
- mode: "nest",
40
- document: this.document,
41
- simulate: config.simulate,
42
- e2e: config.e2e,
43
- });
44
- const output: MigrateApplication.IOutput = {
45
- program,
46
- files: [
47
- ...NEST_TEMPLATE,
48
- ...MigrateNestProgrammer.write(program),
49
- ...MigrateApiProgrammer.write(program),
50
- ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
51
- ],
52
- errors: program.errors,
53
- };
54
- return this.finalize(config, output);
55
- }
56
-
57
- public sdk(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
58
- const program: IHttpMigrateProgram = MigrateApplicationAnalyzer.analyze({
59
- mode: "sdk",
60
- document: this.document,
61
- simulate: config.simulate,
62
- e2e: config.e2e,
63
- });
64
- const output: MigrateApplication.IOutput = {
65
- program,
66
- files: [
67
- ...SDK_TEMPLATE,
68
- ...MigrateApiProgrammer.write(program),
69
- MigrateApiStartProgrammer.write(program),
70
- ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
71
- {
72
- location: "",
73
- file: "swagger.json",
74
- content: JSON.stringify(this.document, null, 2),
75
- },
76
- ],
77
- errors: program.errors,
78
- };
79
- return this.finalize(config, output);
80
- }
81
-
82
- private finalize(
83
- config: MigrateApplication.IConfig,
84
- outupt: MigrateApplication.IOutput,
85
- ): MigrateApplication.IOutput {
86
- if (config.package)
87
- outupt.files = outupt.files.map((file) => ({
88
- ...file,
89
- content: file.content
90
- .split(`@ORGANIZATION/PROJECT`)
91
- .join(config.package),
92
- }));
93
- return outupt;
94
- }
95
- }
96
- export namespace MigrateApplication {
97
- export interface IOutput {
98
- program: IHttpMigrateProgram;
99
- files: IHttpMigrateFile[];
100
- errors: IHttpMigrateProgram.IError[];
101
- }
102
- export interface IConfig {
103
- simulate: boolean;
104
- e2e: boolean;
105
- package?: string;
106
- }
107
- }
1
+ import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
+ import typia, { IValidation } from "typia";
3
+
4
+ import { MigrateApplicationAnalyzer } from "./analyzers/MigrateApplicationAnalyzer";
5
+ import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
6
+ import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
7
+ import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
8
+ import { MigrateApiStartProgrammer } from "./programmers/MigrateApiStartProgrammer";
9
+ import { MigrateE2eProgrammer } from "./programmers/MigrateE2eProgrammer";
10
+ import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
11
+ import { IHttpMigrateFile } from "./structures/IHttpMigrateFile";
12
+ import { IHttpMigrateProgram } from "./structures/IHttpMigrateProgram";
13
+
14
+ export class MigrateApplication {
15
+ private constructor(public readonly document: OpenApi.IDocument) {}
16
+
17
+ public static create(
18
+ document:
19
+ | SwaggerV2.IDocument
20
+ | OpenApiV3.IDocument
21
+ | OpenApiV3_1.IDocument
22
+ | OpenApi.IDocument,
23
+ ): IValidation<MigrateApplication> {
24
+ const result: IValidation<
25
+ | SwaggerV2.IDocument
26
+ | OpenApiV3.IDocument
27
+ | OpenApiV3_1.IDocument
28
+ | OpenApi.IDocument
29
+ > = typia.validate(document);
30
+ if (result.success === false) return result;
31
+ return {
32
+ success: true,
33
+ data: new MigrateApplication(OpenApi.convert(document)),
34
+ };
35
+ }
36
+
37
+ public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
38
+ const program: IHttpMigrateProgram = MigrateApplicationAnalyzer.analyze({
39
+ mode: "nest",
40
+ document: this.document,
41
+ simulate: config.simulate,
42
+ e2e: config.e2e,
43
+ });
44
+ const output: MigrateApplication.IOutput = {
45
+ program,
46
+ files: [
47
+ ...NEST_TEMPLATE,
48
+ ...MigrateNestProgrammer.write(program),
49
+ ...MigrateApiProgrammer.write(program),
50
+ ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
51
+ ],
52
+ errors: program.errors,
53
+ };
54
+ return this.finalize(config, output);
55
+ }
56
+
57
+ public sdk(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
58
+ const program: IHttpMigrateProgram = MigrateApplicationAnalyzer.analyze({
59
+ mode: "sdk",
60
+ document: this.document,
61
+ simulate: config.simulate,
62
+ e2e: config.e2e,
63
+ });
64
+ const output: MigrateApplication.IOutput = {
65
+ program,
66
+ files: [
67
+ ...SDK_TEMPLATE,
68
+ ...MigrateApiProgrammer.write(program),
69
+ MigrateApiStartProgrammer.write(program),
70
+ ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
71
+ {
72
+ location: "",
73
+ file: "swagger.json",
74
+ content: JSON.stringify(this.document, null, 2),
75
+ },
76
+ ],
77
+ errors: program.errors,
78
+ };
79
+ return this.finalize(config, output);
80
+ }
81
+
82
+ private finalize(
83
+ config: MigrateApplication.IConfig,
84
+ outupt: MigrateApplication.IOutput,
85
+ ): MigrateApplication.IOutput {
86
+ if (config.package)
87
+ outupt.files = outupt.files.map((file) => ({
88
+ ...file,
89
+ content: file.content
90
+ .split(`@ORGANIZATION/PROJECT`)
91
+ .join(config.package),
92
+ }));
93
+ return outupt;
94
+ }
95
+ }
96
+ export namespace MigrateApplication {
97
+ export interface IOutput {
98
+ program: IHttpMigrateProgram;
99
+ files: IHttpMigrateFile[];
100
+ errors: IHttpMigrateProgram.IError[];
101
+ }
102
+ export interface IConfig {
103
+ simulate: boolean;
104
+ e2e: boolean;
105
+ package?: string;
106
+ }
107
+ }
@@ -1,18 +1,18 @@
1
- import { HttpMigration, IHttpMigrateApplication } from "@samchon/openapi";
2
-
3
- import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
4
-
5
- export namespace MigrateApplicationAnalyzer {
6
- export const analyze = (
7
- props: IHttpMigrateProgram.IProps,
8
- ): IHttpMigrateProgram => {
9
- const application: IHttpMigrateApplication = HttpMigration.application(
10
- props.document,
11
- );
12
- return {
13
- ...props,
14
- routes: application.routes,
15
- errors: application.errors,
16
- };
17
- };
18
- }
1
+ import { HttpMigration, IHttpMigrateApplication } from "@samchon/openapi";
2
+
3
+ import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
4
+
5
+ export namespace MigrateApplicationAnalyzer {
6
+ export const analyze = (
7
+ props: IHttpMigrateProgram.IProps,
8
+ ): IHttpMigrateProgram => {
9
+ const application: IHttpMigrateApplication = HttpMigration.application(
10
+ props.document,
11
+ );
12
+ return {
13
+ ...props,
14
+ routes: application.routes,
15
+ errors: application.errors,
16
+ };
17
+ };
18
+ }
@@ -1,51 +1,51 @@
1
- import { IHttpMigrateRoute } from "@samchon/openapi";
2
-
3
- import { IHttpMigrateController } from "../structures/IHttpMigrateController";
4
- import { MapUtil } from "../utils/MapUtil";
5
- import { StringUtil } from "../utils/StringUtil";
6
-
7
- export namespace MigrateControllerAnalyzer {
8
- export const analyze = (props: {
9
- routes: IHttpMigrateRoute[];
10
- }): IHttpMigrateController[] => {
11
- const collection: Map<string, IHttpMigrateController> = new Map();
12
- for (const route of props.routes) {
13
- const name: string =
14
- route.operation()["x-samchon-controller"] ??
15
- (route.accessor.length <= 1
16
- ? "__App"
17
- : route.accessor.slice(0, -1).map(StringUtil.capitalize).join("")) +
18
- "Controller";
19
- MapUtil.take(collection)(name)(() => ({
20
- name,
21
- path: "@lazy",
22
- location: "@lazy",
23
- routes: [],
24
- })).routes.push(route);
25
- }
26
-
27
- const controllers: IHttpMigrateController[] = [...collection.values()];
28
- for (const col of controllers) {
29
- const splitPath = (r: IHttpMigrateRoute): string[] =>
30
- r.emendedPath.split("/");
31
- const splitLocation = (r: IHttpMigrateRoute): string[] =>
32
- splitPath(r).filter((s) => s[0] !== ":");
33
-
34
- const minPath: string[] = splitPath(col.routes[0]);
35
- const minLocation: string[] = splitLocation(col.routes[0]);
36
- for (const r of col.routes.slice(1)) {
37
- minPath.splice(getSplitIndex(minPath, splitPath(r)));
38
- minLocation.splice(getSplitIndex(minLocation, splitLocation(r)));
39
- }
40
- col.path = minPath.join("/");
41
- col.location = "src/controllers/" + minLocation.join("/");
42
- }
43
- return controllers;
44
- };
45
- }
46
-
47
- const getSplitIndex = (x: string[], y: string[]) => {
48
- const n: number = Math.min(x.length, y.length);
49
- for (let i: number = 0; i < n; ++i) if (x[i] !== y[i]) return i;
50
- return n;
51
- };
1
+ import { IHttpMigrateRoute } from "@samchon/openapi";
2
+
3
+ import { IHttpMigrateController } from "../structures/IHttpMigrateController";
4
+ import { MapUtil } from "../utils/MapUtil";
5
+ import { StringUtil } from "../utils/StringUtil";
6
+
7
+ export namespace MigrateControllerAnalyzer {
8
+ export const analyze = (props: {
9
+ routes: IHttpMigrateRoute[];
10
+ }): IHttpMigrateController[] => {
11
+ const collection: Map<string, IHttpMigrateController> = new Map();
12
+ for (const route of props.routes) {
13
+ const name: string =
14
+ route.operation()["x-samchon-controller"] ??
15
+ (route.accessor.length <= 1
16
+ ? "__App"
17
+ : route.accessor.slice(0, -1).map(StringUtil.capitalize).join("")) +
18
+ "Controller";
19
+ MapUtil.take(collection)(name)(() => ({
20
+ name,
21
+ path: "@lazy",
22
+ location: "@lazy",
23
+ routes: [],
24
+ })).routes.push(route);
25
+ }
26
+
27
+ const controllers: IHttpMigrateController[] = [...collection.values()];
28
+ for (const col of controllers) {
29
+ const splitPath = (r: IHttpMigrateRoute): string[] =>
30
+ r.emendedPath.split("/");
31
+ const splitLocation = (r: IHttpMigrateRoute): string[] =>
32
+ splitPath(r).filter((s) => s[0] !== ":");
33
+
34
+ const minPath: string[] = splitPath(col.routes[0]);
35
+ const minLocation: string[] = splitLocation(col.routes[0]);
36
+ for (const r of col.routes.slice(1)) {
37
+ minPath.splice(getSplitIndex(minPath, splitPath(r)));
38
+ minLocation.splice(getSplitIndex(minLocation, splitLocation(r)));
39
+ }
40
+ col.path = minPath.join("/");
41
+ col.location = "src/controllers/" + minLocation.join("/");
42
+ }
43
+ return controllers;
44
+ };
45
+ }
46
+
47
+ const getSplitIndex = (x: string[], y: string[]) => {
48
+ const n: number = Math.min(x.length, y.length);
49
+ for (let i: number = 0; i < n; ++i) if (x[i] !== y[i]) return i;
50
+ return n;
51
+ };
@@ -1,38 +1,38 @@
1
- import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
2
-
3
- export namespace MigrateFileArchiver {
4
- export interface IOperator {
5
- mkdir(path: string): Promise<void>;
6
- writeFile(path: string, content: string): Promise<void>;
7
- }
8
-
9
- export const archive =
10
- (operator: IOperator) =>
11
- (output: string) =>
12
- async (files: IHttpMigrateFile[]): Promise<void> => {
13
- const visited: Set<string> = new Set();
14
- for (const f of files) {
15
- await mkdir(operator.mkdir)(output)(visited)(f.location);
16
- await operator.writeFile(
17
- [output, f.location, f.file].join("/"),
18
- f.content,
19
- );
20
- }
21
- };
22
-
23
- const mkdir =
24
- (creator: (path: string) => void) =>
25
- (output: string) =>
26
- (visited: Set<string>) =>
27
- async (path: string): Promise<void> => {
28
- const sequence: string[] = path
29
- .split("/")
30
- .map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
31
- for (const s of sequence)
32
- if (visited.has(s) === false)
33
- try {
34
- await creator([output, s].join("/"));
35
- visited.add(s);
36
- } catch {}
37
- };
38
- }
1
+ import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
2
+
3
+ export namespace MigrateFileArchiver {
4
+ export interface IOperator {
5
+ mkdir(path: string): Promise<void>;
6
+ writeFile(path: string, content: string): Promise<void>;
7
+ }
8
+
9
+ export const archive =
10
+ (operator: IOperator) =>
11
+ (output: string) =>
12
+ async (files: IHttpMigrateFile[]): Promise<void> => {
13
+ const visited: Set<string> = new Set();
14
+ for (const f of files) {
15
+ await mkdir(operator.mkdir)(output)(visited)(f.location);
16
+ await operator.writeFile(
17
+ [output, f.location, f.file].join("/"),
18
+ f.content,
19
+ );
20
+ }
21
+ };
22
+
23
+ const mkdir =
24
+ (creator: (path: string) => void) =>
25
+ (output: string) =>
26
+ (visited: Set<string>) =>
27
+ async (path: string): Promise<void> => {
28
+ const sequence: string[] = path
29
+ .split("/")
30
+ .map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
31
+ for (const s of sequence)
32
+ if (visited.has(s) === false)
33
+ try {
34
+ await creator([output, s].join("/"));
35
+ visited.add(s);
36
+ } catch {}
37
+ };
38
+ }