@nestia/migrate 11.0.0-dev.20260316 → 11.0.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 (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/NestiaMigrateApplication.js +341 -341
  4. package/lib/bundles/NEST_TEMPLATE.js +48 -48
  5. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js +21 -21
  7. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  8. package/lib/executable/migrate.js +0 -0
  9. package/lib/index.mjs +469 -469
  10. package/lib/index.mjs.map +1 -1
  11. package/package.json +10 -8
  12. package/src/NestiaMigrateApplication.ts +168 -168
  13. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  14. package/src/bundles/NEST_TEMPLATE.ts +48 -48
  15. package/src/bundles/SDK_TEMPLATE.ts +21 -21
  16. package/src/executable/NestiaMigrateCommander.ts +104 -104
  17. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  18. package/src/executable/bundle.js +129 -125
  19. package/src/executable/migrate.ts +0 -0
  20. package/src/factories/TypeLiteralFactory.ts +57 -57
  21. package/src/module.ts +7 -7
  22. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
  23. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +347 -347
  24. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +517 -517
  25. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +308 -308
  26. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +197 -197
  27. package/src/programmers/NestiaMigrateDtoProgrammer.ts +98 -98
  28. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -153
  29. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  30. package/src/programmers/NestiaMigrateImportProgrammer.ts +118 -118
  31. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +69 -69
  32. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +409 -409
  33. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +465 -465
  34. package/src/programmers/index.ts +15 -15
  35. package/src/structures/INestiaMigrateContext.ts +9 -9
  36. package/src/structures/INestiaMigrateController.ts +8 -8
  37. package/src/structures/INestiaMigrateDto.ts +8 -8
  38. package/src/structures/INestiaMigrateProgram.ts +11 -11
  39. package/src/structures/index.ts +4 -4
  40. package/src/utils/FilePrinter.ts +49 -49
  41. package/src/utils/StringUtil.ts +114 -114
@@ -1,168 +1,168 @@
1
- import {
2
- IHttpMigrateApplication,
3
- OpenApi,
4
- OpenApiV3,
5
- OpenApiV3_1,
6
- OpenApiV3_2,
7
- SwaggerV2,
8
- } from "@typia/interface";
9
- import { HttpMigration, OpenApiConverter } from "@typia/utils";
10
- import typia, { IValidation } from "typia";
11
-
12
- import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
13
- import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
14
- import { NestiaMigrateApiProgrammer } from "./programmers/NestiaMigrateApiProgrammer";
15
- import { NestiaMigrateApiStartProgrammer } from "./programmers/NestiaMigrateApiStartProgrammer";
16
- import { NestiaMigrateE2eProgrammer } from "./programmers/NestiaMigrateE2eProgrammer";
17
- import { NestiaMigrateNestProgrammer } from "./programmers/NestiaMigrateNestProgrammer";
18
- import { INestiaMigrateConfig } from "./structures/INestiaMigrateConfig";
19
- import { INestiaMigrateContext } from "./structures/INestiaMigrateContext";
20
- import { INestiaMigrateFile } from "./structures/INestiaMigrateFile";
21
-
22
- export class NestiaMigrateApplication {
23
- private readonly data_: IHttpMigrateApplication;
24
-
25
- /* -----------------------------------------------------------
26
- CONSTRUCTORS
27
- ----------------------------------------------------------- */
28
- public constructor(public readonly document: OpenApi.IDocument) {
29
- this.data_ = HttpMigration.application(document);
30
- }
31
-
32
- public static assert(
33
- document:
34
- | SwaggerV2.IDocument
35
- | OpenApiV3.IDocument
36
- | OpenApiV3_1.IDocument
37
- | OpenApiV3_2.IDocument
38
- | OpenApi.IDocument,
39
- ): NestiaMigrateApplication {
40
- return new NestiaMigrateApplication(
41
- OpenApiConverter.upgradeDocument(typia.assert(document)),
42
- );
43
- }
44
-
45
- public static validate(
46
- document:
47
- | SwaggerV2.IDocument
48
- | OpenApiV3.IDocument
49
- | OpenApiV3_1.IDocument
50
- | OpenApiV3_2.IDocument
51
- | OpenApi.IDocument,
52
- ): IValidation<NestiaMigrateApplication> {
53
- const result: IValidation<
54
- | SwaggerV2.IDocument
55
- | OpenApiV3.IDocument
56
- | OpenApiV3_1.IDocument
57
- | OpenApiV3_2.IDocument
58
- | OpenApi.IDocument
59
- > = typia.validate(document);
60
- if (result.success === false) return result;
61
- return {
62
- success: true,
63
- data: new NestiaMigrateApplication(
64
- OpenApiConverter.upgradeDocument(document),
65
- ),
66
- };
67
- }
68
-
69
- /* -----------------------------------------------------------
70
- ACCESSORS
71
- ----------------------------------------------------------- */
72
- public getData(): IHttpMigrateApplication {
73
- return this.data_;
74
- }
75
-
76
- /** @deprecated */
77
- public getErrors(): IHttpMigrateApplication.IError[] {
78
- return this.data_.errors;
79
- }
80
-
81
- public nest(config: INestiaMigrateConfig): Record<string, string> {
82
- const context: INestiaMigrateContext = createContext(
83
- "nest",
84
- this.data_,
85
- config,
86
- );
87
- const files: Record<string, string> = {
88
- ...Object.fromEntries(
89
- Object.entries(NEST_TEMPLATE).filter(
90
- ([key]) =>
91
- key.startsWith("src/api/structures") === false &&
92
- key.startsWith("src/api/functional") === false &&
93
- key.startsWith("src/api/controllers") === false &&
94
- key.startsWith("test/features") === false,
95
- ),
96
- ),
97
- ...NestiaMigrateNestProgrammer.write(context),
98
- ...NestiaMigrateApiProgrammer.write(context),
99
- ...(config.e2e ? NestiaMigrateE2eProgrammer.write(context) : {}),
100
- ...(config.keyword === false
101
- ? {
102
- "nestia.config.ts": NEST_TEMPLATE["nestia.config.ts"]!.replace(
103
- "keyword: true",
104
- "keyword: false",
105
- ),
106
- }
107
- : {}),
108
- };
109
- return config.package ? renameSlug(config.package, files) : files;
110
- }
111
-
112
- public sdk(config: INestiaMigrateConfig): Record<string, string> {
113
- const context: INestiaMigrateContext = createContext(
114
- "sdk",
115
- this.data_,
116
- config,
117
- );
118
- const files: Record<string, string> = {
119
- ...Object.fromEntries(
120
- Object.entries(SDK_TEMPLATE).filter(
121
- ([key]) =>
122
- key.startsWith("src/structures") === false &&
123
- key.startsWith("src/functional") === false &&
124
- key.startsWith("test/features") === false,
125
- ),
126
- ),
127
- ...NestiaMigrateApiProgrammer.write(context),
128
- ...NestiaMigrateApiStartProgrammer.write(context),
129
- ...(config.e2e ? NestiaMigrateE2eProgrammer.write(context) : {}),
130
- "swagger.json": JSON.stringify(this.document, null, 2),
131
- };
132
- return config.package ? renameSlug(config.package, files) : files;
133
- }
134
- }
135
- export namespace MigrateApplication {
136
- export interface IOutput {
137
- context: INestiaMigrateContext;
138
- files: INestiaMigrateFile[];
139
- errors: IHttpMigrateApplication.IError[];
140
- }
141
- }
142
-
143
- const createContext = (
144
- mode: "nest" | "sdk",
145
- application: IHttpMigrateApplication,
146
- config: INestiaMigrateConfig,
147
- ): INestiaMigrateContext => {
148
- return {
149
- mode,
150
- application: {
151
- ...application,
152
- routes: application.routes.filter((r) => r.method !== "query"),
153
- },
154
- config,
155
- };
156
- };
157
-
158
- const renameSlug = (
159
- slug: string,
160
- files: Record<string, string>,
161
- ): Record<string, string> => {
162
- return Object.fromEntries(
163
- Object.entries(files).map(([key, value]) => [
164
- key,
165
- value.split(`@ORGANIZATION/PROJECT`).join(slug),
166
- ]),
167
- );
168
- };
1
+ import {
2
+ IHttpMigrateApplication,
3
+ OpenApi,
4
+ OpenApiV3,
5
+ OpenApiV3_1,
6
+ OpenApiV3_2,
7
+ SwaggerV2,
8
+ } from "@typia/interface";
9
+ import { HttpMigration, OpenApiConverter } from "@typia/utils";
10
+ import typia, { IValidation } from "typia";
11
+
12
+ import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
13
+ import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
14
+ import { NestiaMigrateApiProgrammer } from "./programmers/NestiaMigrateApiProgrammer";
15
+ import { NestiaMigrateApiStartProgrammer } from "./programmers/NestiaMigrateApiStartProgrammer";
16
+ import { NestiaMigrateE2eProgrammer } from "./programmers/NestiaMigrateE2eProgrammer";
17
+ import { NestiaMigrateNestProgrammer } from "./programmers/NestiaMigrateNestProgrammer";
18
+ import { INestiaMigrateConfig } from "./structures/INestiaMigrateConfig";
19
+ import { INestiaMigrateContext } from "./structures/INestiaMigrateContext";
20
+ import { INestiaMigrateFile } from "./structures/INestiaMigrateFile";
21
+
22
+ export class NestiaMigrateApplication {
23
+ private readonly data_: IHttpMigrateApplication;
24
+
25
+ /* -----------------------------------------------------------
26
+ CONSTRUCTORS
27
+ ----------------------------------------------------------- */
28
+ public constructor(public readonly document: OpenApi.IDocument) {
29
+ this.data_ = HttpMigration.application(document);
30
+ }
31
+
32
+ public static assert(
33
+ document:
34
+ | SwaggerV2.IDocument
35
+ | OpenApiV3.IDocument
36
+ | OpenApiV3_1.IDocument
37
+ | OpenApiV3_2.IDocument
38
+ | OpenApi.IDocument,
39
+ ): NestiaMigrateApplication {
40
+ return new NestiaMigrateApplication(
41
+ OpenApiConverter.upgradeDocument(typia.assert(document)),
42
+ );
43
+ }
44
+
45
+ public static validate(
46
+ document:
47
+ | SwaggerV2.IDocument
48
+ | OpenApiV3.IDocument
49
+ | OpenApiV3_1.IDocument
50
+ | OpenApiV3_2.IDocument
51
+ | OpenApi.IDocument,
52
+ ): IValidation<NestiaMigrateApplication> {
53
+ const result: IValidation<
54
+ | SwaggerV2.IDocument
55
+ | OpenApiV3.IDocument
56
+ | OpenApiV3_1.IDocument
57
+ | OpenApiV3_2.IDocument
58
+ | OpenApi.IDocument
59
+ > = typia.validate(document);
60
+ if (result.success === false) return result;
61
+ return {
62
+ success: true,
63
+ data: new NestiaMigrateApplication(
64
+ OpenApiConverter.upgradeDocument(document),
65
+ ),
66
+ };
67
+ }
68
+
69
+ /* -----------------------------------------------------------
70
+ ACCESSORS
71
+ ----------------------------------------------------------- */
72
+ public getData(): IHttpMigrateApplication {
73
+ return this.data_;
74
+ }
75
+
76
+ /** @deprecated */
77
+ public getErrors(): IHttpMigrateApplication.IError[] {
78
+ return this.data_.errors;
79
+ }
80
+
81
+ public nest(config: INestiaMigrateConfig): Record<string, string> {
82
+ const context: INestiaMigrateContext = createContext(
83
+ "nest",
84
+ this.data_,
85
+ config,
86
+ );
87
+ const files: Record<string, string> = {
88
+ ...Object.fromEntries(
89
+ Object.entries(NEST_TEMPLATE).filter(
90
+ ([key]) =>
91
+ key.startsWith("src/api/structures") === false &&
92
+ key.startsWith("src/api/functional") === false &&
93
+ key.startsWith("src/api/controllers") === false &&
94
+ key.startsWith("test/features") === false,
95
+ ),
96
+ ),
97
+ ...NestiaMigrateNestProgrammer.write(context),
98
+ ...NestiaMigrateApiProgrammer.write(context),
99
+ ...(config.e2e ? NestiaMigrateE2eProgrammer.write(context) : {}),
100
+ ...(config.keyword === false
101
+ ? {
102
+ "nestia.config.ts": NEST_TEMPLATE["nestia.config.ts"]!.replace(
103
+ "keyword: true",
104
+ "keyword: false",
105
+ ),
106
+ }
107
+ : {}),
108
+ };
109
+ return config.package ? renameSlug(config.package, files) : files;
110
+ }
111
+
112
+ public sdk(config: INestiaMigrateConfig): Record<string, string> {
113
+ const context: INestiaMigrateContext = createContext(
114
+ "sdk",
115
+ this.data_,
116
+ config,
117
+ );
118
+ const files: Record<string, string> = {
119
+ ...Object.fromEntries(
120
+ Object.entries(SDK_TEMPLATE).filter(
121
+ ([key]) =>
122
+ key.startsWith("src/structures") === false &&
123
+ key.startsWith("src/functional") === false &&
124
+ key.startsWith("test/features") === false,
125
+ ),
126
+ ),
127
+ ...NestiaMigrateApiProgrammer.write(context),
128
+ ...NestiaMigrateApiStartProgrammer.write(context),
129
+ ...(config.e2e ? NestiaMigrateE2eProgrammer.write(context) : {}),
130
+ "swagger.json": JSON.stringify(this.document, null, 2),
131
+ };
132
+ return config.package ? renameSlug(config.package, files) : files;
133
+ }
134
+ }
135
+ export namespace MigrateApplication {
136
+ export interface IOutput {
137
+ context: INestiaMigrateContext;
138
+ files: INestiaMigrateFile[];
139
+ errors: IHttpMigrateApplication.IError[];
140
+ }
141
+ }
142
+
143
+ const createContext = (
144
+ mode: "nest" | "sdk",
145
+ application: IHttpMigrateApplication,
146
+ config: INestiaMigrateConfig,
147
+ ): INestiaMigrateContext => {
148
+ return {
149
+ mode,
150
+ application: {
151
+ ...application,
152
+ routes: application.routes.filter((r) => r.method !== "query"),
153
+ },
154
+ config,
155
+ };
156
+ };
157
+
158
+ const renameSlug = (
159
+ slug: string,
160
+ files: Record<string, string>,
161
+ ): Record<string, string> => {
162
+ return Object.fromEntries(
163
+ Object.entries(files).map(([key, value]) => [
164
+ key,
165
+ value.split(`@ORGANIZATION/PROJECT`).join(slug),
166
+ ]),
167
+ );
168
+ };
@@ -1,51 +1,51 @@
1
- import { IHttpMigrateRoute } from "@typia/interface";
2
-
3
- import { INestiaMigrateController } from "../structures/INestiaMigrateController";
4
- import { MapUtil } from "../utils/MapUtil";
5
- import { StringUtil } from "../utils/StringUtil";
6
-
7
- export namespace NestiaMigrateControllerAnalyzer {
8
- export const analyze = (
9
- routes: IHttpMigrateRoute[],
10
- ): INestiaMigrateController[] => {
11
- const collection: Map<string, INestiaMigrateController> = new Map();
12
- for (const r of routes) {
13
- const name: string =
14
- r.operation()["x-samchon-controller"] ??
15
- (r.accessor.length <= 1
16
- ? "__App"
17
- : r.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(r);
25
- }
26
-
27
- const controllers: INestiaMigrateController[] = [...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.length !== 0 && 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 "@typia/interface";
2
+
3
+ import { INestiaMigrateController } from "../structures/INestiaMigrateController";
4
+ import { MapUtil } from "../utils/MapUtil";
5
+ import { StringUtil } from "../utils/StringUtil";
6
+
7
+ export namespace NestiaMigrateControllerAnalyzer {
8
+ export const analyze = (
9
+ routes: IHttpMigrateRoute[],
10
+ ): INestiaMigrateController[] => {
11
+ const collection: Map<string, INestiaMigrateController> = new Map();
12
+ for (const r of routes) {
13
+ const name: string =
14
+ r.operation()["x-samchon-controller"] ??
15
+ (r.accessor.length <= 1
16
+ ? "__App"
17
+ : r.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(r);
25
+ }
26
+
27
+ const controllers: INestiaMigrateController[] = [...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.length !== 0 && 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
+ };