@nestia/migrate 10.0.2 → 11.0.0-dev.20260312

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