@nestia/migrate 12.0.0-dev.20260521.6 → 12.0.0-dev.20260612.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 (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/NestiaMigrateApplication.js +19 -1
  4. package/lib/NestiaMigrateApplication.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +47 -47
  6. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  7. package/lib/bundles/SDK_TEMPLATE.js +20 -20
  8. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  9. package/lib/index.mjs +94 -77
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +6 -2
  12. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
  13. package/package.json +5 -5
  14. package/src/NestiaMigrateApplication.ts +196 -167
  15. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  16. package/src/archivers/NestiaMigrateFileArchiver.ts +28 -28
  17. package/src/bundles/NEST_TEMPLATE.ts +47 -47
  18. package/src/bundles/SDK_TEMPLATE.ts +20 -20
  19. package/src/executable/NestiaMigrateCommander.ts +115 -115
  20. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  21. package/src/executable/bundle.js +349 -349
  22. package/src/executable/migrate.ts +7 -7
  23. package/src/factories/TypeLiteralFactory.ts +63 -63
  24. package/src/index.ts +4 -4
  25. package/src/internal/ts.ts +94 -94
  26. package/src/module.ts +6 -6
  27. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +58 -58
  28. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +373 -369
  29. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +528 -528
  30. package/src/programmers/NestiaMigrateApiProgrammer.ts +108 -108
  31. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +314 -314
  32. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +198 -198
  33. package/src/programmers/NestiaMigrateDtoProgrammer.ts +99 -99
  34. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +156 -156
  35. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  36. package/src/programmers/NestiaMigrateImportProgrammer.ts +119 -119
  37. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +70 -70
  38. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +414 -414
  39. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +66 -66
  40. package/src/programmers/NestiaMigrateNestProgrammer.ts +89 -89
  41. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +477 -477
  42. package/src/programmers/index.ts +15 -15
  43. package/src/structures/INestiaMigrateConfig.ts +19 -19
  44. package/src/structures/INestiaMigrateContext.ts +9 -9
  45. package/src/structures/INestiaMigrateController.ts +8 -8
  46. package/src/structures/INestiaMigrateFile.ts +5 -5
  47. package/src/structures/index.ts +4 -4
  48. package/src/utils/FilePrinter.ts +44 -44
  49. package/src/utils/MapUtil.ts +13 -13
  50. package/src/utils/StringUtil.ts +109 -109
@@ -1,115 +1,115 @@
1
- import * as prettierPluginSortImport from "@trivago/prettier-plugin-sort-imports";
2
- import {
3
- OpenApiV3,
4
- OpenApiV3_1,
5
- OpenApiV3_2,
6
- SwaggerV2,
7
- } from "@typia/interface";
8
- import fs from "fs";
9
- import path from "path";
10
- import { format } from "prettier";
11
- import * as prettierPluginJsDoc from "prettier-plugin-jsdoc";
12
- import type { IValidation } from "typia";
13
-
14
- import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
15
- import { NestiaMigrateFileArchiver } from "../archivers/NestiaMigrateFileArchiver";
16
- import { NestiaMigrateInquirer } from "./NestiaMigrateInquirer";
17
-
18
- export namespace NestiaMigrateCommander {
19
- export const main = async (): Promise<void> => {
20
- const resolve = (str: string | undefined) =>
21
- str ? path.resolve(str).split("\\").join("/") : undefined;
22
- const options: NestiaMigrateInquirer.IOutput =
23
- await NestiaMigrateInquirer.parse();
24
-
25
- // VALIDATE OUTPUT DIRECTORY
26
- const parent: string = resolve(options.output + "/..")!;
27
- if (fs.existsSync(options.output))
28
- halt("Response directory already exists.");
29
- else if (fs.existsSync(parent) === false)
30
- halt("Response directory's parent directory does not exist.");
31
- else if (fs.statSync(parent).isDirectory() === false)
32
- halt("Response directory's parent is not a directory.");
33
-
34
- // READ SWAGGER
35
- const document:
36
- | SwaggerV2.IDocument
37
- | OpenApiV3.IDocument
38
- | OpenApiV3_1.IDocument
39
- | OpenApiV3_2.IDocument = await (async () => {
40
- if (isUri(options.input)) {
41
- const response: Response = await fetch(options.input);
42
- const content: string = await response.text();
43
- return JSON.parse(content);
44
- }
45
- if (fs.existsSync(options.input) === false)
46
- halt("Unable to find the input swagger.json file.");
47
- const stats: fs.Stats = fs.statSync(options.input);
48
- if (stats.isFile() === false)
49
- halt("The input swagger.json is not a file.");
50
- const content: string = await fs.promises.readFile(
51
- options.input,
52
- "utf-8",
53
- );
54
- return JSON.parse(content);
55
- })();
56
-
57
- const result: IValidation<NestiaMigrateApplication> =
58
- NestiaMigrateApplication.validate(document);
59
- if (result.success === false) {
60
- console.error("nestia migrate: invalid swagger:");
61
- for (const err of result.errors)
62
- console.error(` - ${err.path}: ${err.value}`);
63
- throw new Error(
64
- `Invalid swagger file (must follow the OpenAPI 3.0 spec): ${options.input}`,
65
- );
66
- }
67
-
68
- const app: NestiaMigrateApplication = result.data;
69
- const files: Record<string, string> =
70
- options.mode === "nest" ? app.nest(options) : app.sdk(options);
71
- if (app.getData().errors)
72
- for (const error of app.getData().errors)
73
- console.error(
74
- `Failed to migrate ${error.method} ${error.path}`,
75
- ...error.messages.map((msg) => ` - ${msg}`),
76
- );
77
- await NestiaMigrateFileArchiver.archive({
78
- mkdir: fs.promises.mkdir,
79
- writeFile: async (file, content) =>
80
- fs.promises.writeFile(file, await beautify(content), "utf-8"),
81
- root: options.output,
82
- files,
83
- });
84
- };
85
-
86
- const beautify = async (script: string): Promise<string> => {
87
- try {
88
- return await format(script, {
89
- parser: "typescript",
90
- plugins: [prettierPluginSortImport, prettierPluginJsDoc],
91
- importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
92
- importOrderSeparation: true,
93
- importOrderSortSpecifiers: true,
94
- importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
95
- bracketSpacing: true,
96
- });
97
- } catch {
98
- return script;
99
- }
100
- };
101
-
102
- const halt = (desc: string): never => {
103
- console.error(desc);
104
- process.exit(-1);
105
- };
106
-
107
- const isUri = (input: string): boolean => {
108
- try {
109
- const url: URL = new URL(input);
110
- return url.protocol === "http:" || url.protocol === "https:";
111
- } catch {
112
- return false;
113
- }
114
- };
115
- }
1
+ import * as prettierPluginSortImport from "@trivago/prettier-plugin-sort-imports";
2
+ import {
3
+ OpenApiV3,
4
+ OpenApiV3_1,
5
+ OpenApiV3_2,
6
+ SwaggerV2,
7
+ } from "@typia/interface";
8
+ import fs from "fs";
9
+ import path from "path";
10
+ import { format } from "prettier";
11
+ import * as prettierPluginJsDoc from "prettier-plugin-jsdoc";
12
+ import type { IValidation } from "typia";
13
+
14
+ import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
15
+ import { NestiaMigrateFileArchiver } from "../archivers/NestiaMigrateFileArchiver";
16
+ import { NestiaMigrateInquirer } from "./NestiaMigrateInquirer";
17
+
18
+ export namespace NestiaMigrateCommander {
19
+ export const main = async (): Promise<void> => {
20
+ const resolve = (str: string | undefined) =>
21
+ str ? path.resolve(str).split("\\").join("/") : undefined;
22
+ const options: NestiaMigrateInquirer.IOutput =
23
+ await NestiaMigrateInquirer.parse();
24
+
25
+ // VALIDATE OUTPUT DIRECTORY
26
+ const parent: string = resolve(options.output + "/..")!;
27
+ if (fs.existsSync(options.output))
28
+ halt("Response directory already exists.");
29
+ else if (fs.existsSync(parent) === false)
30
+ halt("Response directory's parent directory does not exist.");
31
+ else if (fs.statSync(parent).isDirectory() === false)
32
+ halt("Response directory's parent is not a directory.");
33
+
34
+ // READ SWAGGER
35
+ const document:
36
+ | SwaggerV2.IDocument
37
+ | OpenApiV3.IDocument
38
+ | OpenApiV3_1.IDocument
39
+ | OpenApiV3_2.IDocument = await (async () => {
40
+ if (isUri(options.input)) {
41
+ const response: Response = await fetch(options.input);
42
+ const content: string = await response.text();
43
+ return JSON.parse(content);
44
+ }
45
+ if (fs.existsSync(options.input) === false)
46
+ halt("Unable to find the input swagger.json file.");
47
+ const stats: fs.Stats = fs.statSync(options.input);
48
+ if (stats.isFile() === false)
49
+ halt("The input swagger.json is not a file.");
50
+ const content: string = await fs.promises.readFile(
51
+ options.input,
52
+ "utf-8",
53
+ );
54
+ return JSON.parse(content);
55
+ })();
56
+
57
+ const result: IValidation<NestiaMigrateApplication> =
58
+ NestiaMigrateApplication.validate(document);
59
+ if (result.success === false) {
60
+ console.error("nestia migrate: invalid swagger:");
61
+ for (const err of result.errors)
62
+ console.error(` - ${err.path}: ${err.value}`);
63
+ throw new Error(
64
+ `Invalid swagger file (must follow the OpenAPI 3.0 spec): ${options.input}`,
65
+ );
66
+ }
67
+
68
+ const app: NestiaMigrateApplication = result.data;
69
+ const files: Record<string, string> =
70
+ options.mode === "nest" ? app.nest(options) : app.sdk(options);
71
+ if (app.getData().errors)
72
+ for (const error of app.getData().errors)
73
+ console.error(
74
+ `Failed to migrate ${error.method} ${error.path}`,
75
+ ...error.messages.map((msg) => ` - ${msg}`),
76
+ );
77
+ await NestiaMigrateFileArchiver.archive({
78
+ mkdir: fs.promises.mkdir,
79
+ writeFile: async (file, content) =>
80
+ fs.promises.writeFile(file, await beautify(content), "utf-8"),
81
+ root: options.output,
82
+ files,
83
+ });
84
+ };
85
+
86
+ const beautify = async (script: string): Promise<string> => {
87
+ try {
88
+ return await format(script, {
89
+ parser: "typescript",
90
+ plugins: [prettierPluginSortImport, prettierPluginJsDoc],
91
+ importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
92
+ importOrderSeparation: true,
93
+ importOrderSortSpecifiers: true,
94
+ importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
95
+ bracketSpacing: true,
96
+ });
97
+ } catch {
98
+ return script;
99
+ }
100
+ };
101
+
102
+ const halt = (desc: string): never => {
103
+ console.error(desc);
104
+ process.exit(-1);
105
+ };
106
+
107
+ const isUri = (input: string): boolean => {
108
+ try {
109
+ const url: URL = new URL(input);
110
+ return url.protocol === "http:" || url.protocol === "https:";
111
+ } catch {
112
+ return false;
113
+ }
114
+ };
115
+ }
@@ -1,106 +1,106 @@
1
- import { program } from "commander";
2
- import { createPromptModule } from "inquirer";
3
-
4
- export namespace NestiaMigrateInquirer {
5
- export interface IOutput {
6
- mode: "nest" | "sdk";
7
- input: string;
8
- output: string;
9
- keyword: boolean;
10
- simulate: boolean;
11
- e2e: boolean;
12
- package: string;
13
- }
14
-
15
- export const parse = async (): Promise<IOutput> => {
16
- // PREPARE ASSETS
17
- program.option("--mode [nest/sdk]", "migration mode");
18
- program.option(
19
- "--input [swagger.json]",
20
- "location of target swagger.json file",
21
- );
22
- program.option("--output [directory]", "output directory path");
23
- program.option("--keyword [boolean]", "Keyword parameter mode");
24
- program.option("--simulate [boolean]", "Mockup simulator");
25
- program.option("--e2e [boolean]", "Generate E2E tests");
26
- program.option("--package [name]", "Package name");
27
-
28
- // INTERNAL PROCEDURES
29
- const questioned = { value: false };
30
- const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
31
- new Promise<IOutput>((resolve, reject) => {
32
- program.action(async (options) => {
33
- try {
34
- resolve(await closure(options));
35
- } catch (exp) {
36
- reject(exp);
37
- }
38
- });
39
- program.parseAsync().catch(reject);
40
- });
41
- const select =
42
- (name: string) =>
43
- (message: string) =>
44
- async <Choice extends string>(
45
- choices: Choice[],
46
- filter?: (value: string) => Choice,
47
- ): Promise<Choice> => {
48
- questioned.value = true;
49
- return (
50
- await createPromptModule()({
51
- type: "list",
52
- name: name,
53
- message: message,
54
- choices: choices,
55
- filter,
56
- })
57
- )[name];
58
- };
59
- const input = (name: string) => async (message: string) =>
60
- (
61
- await createPromptModule()({
62
- type: "input",
63
- name,
64
- message,
65
- })
66
- )[name];
67
-
68
- // DO CONSTRUCT
69
- return action(async (partial) => {
70
- partial.mode ??= await select("mode")("Migration mode")(
71
- ["NestJS" as "nest", "SDK" as "sdk"],
72
- (value) => (value === "NestJS" ? "nest" : "sdk"),
73
- );
74
- partial.input ??= await input("input")("Swagger file location");
75
- partial.output ??= await input("output")("Response directory path");
76
- partial.package ??= await input("package")("Package name");
77
- partial.keyword ??=
78
- (await select("keyword")("Keyword parameter mode")([
79
- "true",
80
- "false",
81
- ])) === "true";
82
-
83
- if (partial.keyword)
84
- partial.keyword = (partial.keyword as any) === "true";
85
- else
86
- partial.keyword =
87
- (await select("keyword")("Keyword parameter mode")([
88
- "true",
89
- "false",
90
- ])) === "true";
91
- if (partial.simulate)
92
- partial.simulate = (partial.simulate as any) === "true";
93
- else
94
- partial.simulate =
95
- (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
96
- "true";
97
-
98
- if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
99
- else
100
- partial.e2e =
101
- (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
102
- "true";
103
- return partial as IOutput;
104
- });
105
- };
106
- }
1
+ import { program } from "commander";
2
+ import { createPromptModule } from "inquirer";
3
+
4
+ export namespace NestiaMigrateInquirer {
5
+ export interface IOutput {
6
+ mode: "nest" | "sdk";
7
+ input: string;
8
+ output: string;
9
+ keyword: boolean;
10
+ simulate: boolean;
11
+ e2e: boolean;
12
+ package: string;
13
+ }
14
+
15
+ export const parse = async (): Promise<IOutput> => {
16
+ // PREPARE ASSETS
17
+ program.option("--mode [nest/sdk]", "migration mode");
18
+ program.option(
19
+ "--input [swagger.json]",
20
+ "location of target swagger.json file",
21
+ );
22
+ program.option("--output [directory]", "output directory path");
23
+ program.option("--keyword [boolean]", "Keyword parameter mode");
24
+ program.option("--simulate [boolean]", "Mockup simulator");
25
+ program.option("--e2e [boolean]", "Generate E2E tests");
26
+ program.option("--package [name]", "Package name");
27
+
28
+ // INTERNAL PROCEDURES
29
+ const questioned = { value: false };
30
+ const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
31
+ new Promise<IOutput>((resolve, reject) => {
32
+ program.action(async (options) => {
33
+ try {
34
+ resolve(await closure(options));
35
+ } catch (exp) {
36
+ reject(exp);
37
+ }
38
+ });
39
+ program.parseAsync().catch(reject);
40
+ });
41
+ const select =
42
+ (name: string) =>
43
+ (message: string) =>
44
+ async <Choice extends string>(
45
+ choices: Choice[],
46
+ filter?: (value: string) => Choice,
47
+ ): Promise<Choice> => {
48
+ questioned.value = true;
49
+ return (
50
+ await createPromptModule()({
51
+ type: "list",
52
+ name: name,
53
+ message: message,
54
+ choices: choices,
55
+ filter,
56
+ })
57
+ )[name];
58
+ };
59
+ const input = (name: string) => async (message: string) =>
60
+ (
61
+ await createPromptModule()({
62
+ type: "input",
63
+ name,
64
+ message,
65
+ })
66
+ )[name];
67
+
68
+ // DO CONSTRUCT
69
+ return action(async (partial) => {
70
+ partial.mode ??= await select("mode")("Migration mode")(
71
+ ["NestJS" as "nest", "SDK" as "sdk"],
72
+ (value) => (value === "NestJS" ? "nest" : "sdk"),
73
+ );
74
+ partial.input ??= await input("input")("Swagger file location");
75
+ partial.output ??= await input("output")("Response directory path");
76
+ partial.package ??= await input("package")("Package name");
77
+ partial.keyword ??=
78
+ (await select("keyword")("Keyword parameter mode")([
79
+ "true",
80
+ "false",
81
+ ])) === "true";
82
+
83
+ if (partial.keyword)
84
+ partial.keyword = (partial.keyword as any) === "true";
85
+ else
86
+ partial.keyword =
87
+ (await select("keyword")("Keyword parameter mode")([
88
+ "true",
89
+ "false",
90
+ ])) === "true";
91
+ if (partial.simulate)
92
+ partial.simulate = (partial.simulate as any) === "true";
93
+ else
94
+ partial.simulate =
95
+ (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
96
+ "true";
97
+
98
+ if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
99
+ else
100
+ partial.e2e =
101
+ (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
102
+ "true";
103
+ return partial as IOutput;
104
+ });
105
+ };
106
+ }