@nestia/migrate 0.7.0-dev.20240201 → 0.7.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 (39) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +2 -7
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +1 -6
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/executable/migrate.js +2 -2
  6. package/lib/executable/migrate.js.map +1 -1
  7. package/lib/internal/MigrateCommander.d.ts +1 -7
  8. package/lib/internal/MigrateCommander.js +39 -50
  9. package/lib/internal/MigrateCommander.js.map +1 -1
  10. package/lib/internal/MigrateInquirer.d.ts +9 -0
  11. package/lib/internal/MigrateInquirer.js +72 -0
  12. package/lib/internal/MigrateInquirer.js.map +1 -0
  13. package/lib/programmers/ApiFunctionProgrammer.js +1 -1
  14. package/lib/programmers/ApiSimulatationProgrammer.js +1 -1
  15. package/package.json +68 -68
  16. package/src/MigrateApplication.ts +35 -35
  17. package/src/archivers/FileArchiver.ts +38 -38
  18. package/src/bundles/NEST_TEMPLATE.ts +2 -7
  19. package/src/bundles/SDK_TEMPLATE.ts +1 -6
  20. package/src/executable/bundle.ts +102 -102
  21. package/src/executable/migrate.ts +7 -7
  22. package/src/module.ts +4 -4
  23. package/src/programmers/ApiFunctionProgrammer.ts +1 -1
  24. package/src/programmers/ApiSimulatationProgrammer.ts +1 -1
  25. package/src/programmers/DtoProgrammer.ts +74 -74
  26. package/src/programmers/ImportProgrammer.ts +114 -114
  27. package/src/programmers/NestControllerProgrammer.ts +48 -48
  28. package/src/programmers/NestProgrammer.ts +74 -74
  29. package/src/structures/IMigrateProgram.ts +9 -9
  30. package/src/structures/IMigrateRoute.ts +44 -44
  31. package/src/utils/JsonTypeChecker.ts +67 -67
  32. package/src/utils/SetupWizard.ts +12 -12
  33. package/src/utils/StringUtil.ts +60 -60
  34. package/lib/bundles/TEMPLATE.d.ts +0 -5
  35. package/lib/bundles/TEMPLATE.js +0 -166
  36. package/lib/bundles/TEMPLATE.js.map +0 -1
  37. package/lib/internal/MigrateCli.d.ts +0 -3
  38. package/lib/internal/MigrateCli.js +0 -59
  39. package/lib/internal/MigrateCli.js.map +0 -1
@@ -1,114 +1,114 @@
1
- import ts from "typescript";
2
- import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
-
4
- import { FilePrinter } from "../utils/FilePrinter";
5
- import { MapUtil } from "../utils/MapUtil";
6
-
7
- export class ImportProgrammer {
8
- private external_: Map<
9
- string,
10
- {
11
- default: string | null;
12
- instances: Set<string>;
13
- }
14
- > = new Map();
15
- private dtos_: Set<string> = new Set();
16
-
17
- public constructor() {}
18
-
19
- public empty(): boolean {
20
- return this.external_.size === 0 && this.dtos_.size === 0;
21
- }
22
-
23
- public external(props: ImportProgrammer.IProps): string {
24
- const element = MapUtil.take(this.external_)(props.library)(() => ({
25
- default: null,
26
- instances: new Set(),
27
- }));
28
- const name: string = props.name.split(".")[0];
29
- if (props.type === "default") element.default = props.name;
30
- else element.instances.add(name);
31
- return name;
32
- }
33
-
34
- public dto(name: string): ts.TypeReferenceNode {
35
- const file: string = name.split(".")[0];
36
- this.dtos_.add(file);
37
- return ts.factory.createTypeReferenceNode(name);
38
- }
39
-
40
- public tag(type: string, arg: number | string): ts.TypeReferenceNode {
41
- this.external({
42
- type: "instance",
43
- library: "typia",
44
- name: "tags",
45
- });
46
- return ts.factory.createTypeReferenceNode(`tags.${type}`, [
47
- ts.factory.createLiteralTypeNode(
48
- typeof arg === "string"
49
- ? ts.factory.createStringLiteral(arg)
50
- : ExpressionFactory.number(arg),
51
- ),
52
- ]);
53
- }
54
-
55
- public toStatements(
56
- dtoPath: (name: string) => string,
57
- current?: string,
58
- ): ts.Statement[] {
59
- return [
60
- ...[...this.external_.entries()].map(([library, props]) => {
61
- return ts.factory.createImportDeclaration(
62
- undefined,
63
- ts.factory.createImportClause(
64
- false,
65
- props.default !== null
66
- ? ts.factory.createIdentifier(props.default)
67
- : undefined,
68
- props.instances.size
69
- ? ts.factory.createNamedImports(
70
- [...props.instances].map((i) =>
71
- ts.factory.createImportSpecifier(
72
- false,
73
- undefined,
74
- ts.factory.createIdentifier(i),
75
- ),
76
- ),
77
- )
78
- : undefined,
79
- ),
80
- ts.factory.createStringLiteral(library),
81
- );
82
- }),
83
- ...(this.external_.size && this.dtos_.size ? [FilePrinter.enter()] : []),
84
- ...[...this.dtos_]
85
- .filter(
86
- current ? (name) => name !== current!.split(".")[0] : () => true,
87
- )
88
- .map((i) =>
89
- ts.factory.createImportDeclaration(
90
- undefined,
91
- ts.factory.createImportClause(
92
- false,
93
- undefined,
94
- ts.factory.createNamedImports([
95
- ts.factory.createImportSpecifier(
96
- false,
97
- undefined,
98
- ts.factory.createIdentifier(i),
99
- ),
100
- ]),
101
- ),
102
- ts.factory.createStringLiteral(dtoPath(i)),
103
- ),
104
- ),
105
- ];
106
- }
107
- }
108
- export namespace ImportProgrammer {
109
- export interface IProps {
110
- type: "default" | "instance";
111
- library: string;
112
- name: string;
113
- }
114
- }
1
+ import ts from "typescript";
2
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
+
4
+ import { FilePrinter } from "../utils/FilePrinter";
5
+ import { MapUtil } from "../utils/MapUtil";
6
+
7
+ export class ImportProgrammer {
8
+ private external_: Map<
9
+ string,
10
+ {
11
+ default: string | null;
12
+ instances: Set<string>;
13
+ }
14
+ > = new Map();
15
+ private dtos_: Set<string> = new Set();
16
+
17
+ public constructor() {}
18
+
19
+ public empty(): boolean {
20
+ return this.external_.size === 0 && this.dtos_.size === 0;
21
+ }
22
+
23
+ public external(props: ImportProgrammer.IProps): string {
24
+ const element = MapUtil.take(this.external_)(props.library)(() => ({
25
+ default: null,
26
+ instances: new Set(),
27
+ }));
28
+ const name: string = props.name.split(".")[0];
29
+ if (props.type === "default") element.default = props.name;
30
+ else element.instances.add(name);
31
+ return name;
32
+ }
33
+
34
+ public dto(name: string): ts.TypeReferenceNode {
35
+ const file: string = name.split(".")[0];
36
+ this.dtos_.add(file);
37
+ return ts.factory.createTypeReferenceNode(name);
38
+ }
39
+
40
+ public tag(type: string, arg: number | string): ts.TypeReferenceNode {
41
+ this.external({
42
+ type: "instance",
43
+ library: "typia",
44
+ name: "tags",
45
+ });
46
+ return ts.factory.createTypeReferenceNode(`tags.${type}`, [
47
+ ts.factory.createLiteralTypeNode(
48
+ typeof arg === "string"
49
+ ? ts.factory.createStringLiteral(arg)
50
+ : ExpressionFactory.number(arg),
51
+ ),
52
+ ]);
53
+ }
54
+
55
+ public toStatements(
56
+ dtoPath: (name: string) => string,
57
+ current?: string,
58
+ ): ts.Statement[] {
59
+ return [
60
+ ...[...this.external_.entries()].map(([library, props]) => {
61
+ return ts.factory.createImportDeclaration(
62
+ undefined,
63
+ ts.factory.createImportClause(
64
+ false,
65
+ props.default !== null
66
+ ? ts.factory.createIdentifier(props.default)
67
+ : undefined,
68
+ props.instances.size
69
+ ? ts.factory.createNamedImports(
70
+ [...props.instances].map((i) =>
71
+ ts.factory.createImportSpecifier(
72
+ false,
73
+ undefined,
74
+ ts.factory.createIdentifier(i),
75
+ ),
76
+ ),
77
+ )
78
+ : undefined,
79
+ ),
80
+ ts.factory.createStringLiteral(library),
81
+ );
82
+ }),
83
+ ...(this.external_.size && this.dtos_.size ? [FilePrinter.enter()] : []),
84
+ ...[...this.dtos_]
85
+ .filter(
86
+ current ? (name) => name !== current!.split(".")[0] : () => true,
87
+ )
88
+ .map((i) =>
89
+ ts.factory.createImportDeclaration(
90
+ undefined,
91
+ ts.factory.createImportClause(
92
+ false,
93
+ undefined,
94
+ ts.factory.createNamedImports([
95
+ ts.factory.createImportSpecifier(
96
+ false,
97
+ undefined,
98
+ ts.factory.createIdentifier(i),
99
+ ),
100
+ ]),
101
+ ),
102
+ ts.factory.createStringLiteral(dtoPath(i)),
103
+ ),
104
+ ),
105
+ ];
106
+ }
107
+ }
108
+ export namespace ImportProgrammer {
109
+ export interface IProps {
110
+ type: "default" | "instance";
111
+ library: string;
112
+ name: string;
113
+ }
114
+ }
@@ -1,48 +1,48 @@
1
- import ts from "typescript";
2
-
3
- import { IMigrateController } from "../structures/IMigrateController";
4
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
5
- import { FilePrinter } from "../utils/FilePrinter";
6
- import { StringUtil } from "../utils/StringUtil";
7
- import { ImportProgrammer } from "./ImportProgrammer";
8
- import { NestMethodProgrammer } from "./NestMethodProgrammer";
9
-
10
- export namespace NestControllerProgrammer {
11
- export const write =
12
- (components: ISwaggerComponents) =>
13
- (controller: IMigrateController): ts.Statement[] => {
14
- const importer: ImportProgrammer = new ImportProgrammer();
15
- const $class = ts.factory.createClassDeclaration(
16
- [
17
- ts.factory.createDecorator(
18
- ts.factory.createCallExpression(
19
- ts.factory.createIdentifier(
20
- importer.external({
21
- type: "instance",
22
- library: "@nestjs/common",
23
- name: "Controller",
24
- }),
25
- ),
26
- [],
27
- [ts.factory.createStringLiteral(controller.path)],
28
- ),
29
- ),
30
- ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
31
- ],
32
- controller.name,
33
- [],
34
- [],
35
- controller.routes.map(NestMethodProgrammer.write(components)(importer)),
36
- );
37
- return [
38
- ...importer.toStatements(
39
- (ref) =>
40
- `${"../".repeat(
41
- StringUtil.splitWithNormalization(controller.location).length - 1,
42
- )}api/structures/${ref}`,
43
- ),
44
- ...(importer.empty() ? [] : [FilePrinter.enter()]),
45
- $class,
46
- ];
47
- };
48
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateController } from "../structures/IMigrateController";
4
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
5
+ import { FilePrinter } from "../utils/FilePrinter";
6
+ import { StringUtil } from "../utils/StringUtil";
7
+ import { ImportProgrammer } from "./ImportProgrammer";
8
+ import { NestMethodProgrammer } from "./NestMethodProgrammer";
9
+
10
+ export namespace NestControllerProgrammer {
11
+ export const write =
12
+ (components: ISwaggerComponents) =>
13
+ (controller: IMigrateController): ts.Statement[] => {
14
+ const importer: ImportProgrammer = new ImportProgrammer();
15
+ const $class = ts.factory.createClassDeclaration(
16
+ [
17
+ ts.factory.createDecorator(
18
+ ts.factory.createCallExpression(
19
+ ts.factory.createIdentifier(
20
+ importer.external({
21
+ type: "instance",
22
+ library: "@nestjs/common",
23
+ name: "Controller",
24
+ }),
25
+ ),
26
+ [],
27
+ [ts.factory.createStringLiteral(controller.path)],
28
+ ),
29
+ ),
30
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
31
+ ],
32
+ controller.name,
33
+ [],
34
+ [],
35
+ controller.routes.map(NestMethodProgrammer.write(components)(importer)),
36
+ );
37
+ return [
38
+ ...importer.toStatements(
39
+ (ref) =>
40
+ `${"../".repeat(
41
+ StringUtil.splitWithNormalization(controller.location).length - 1,
42
+ )}api/structures/${ref}`,
43
+ ),
44
+ ...(importer.empty() ? [] : [FilePrinter.enter()]),
45
+ $class,
46
+ ];
47
+ };
48
+ }
@@ -1,74 +1,74 @@
1
- import ts from "typescript";
2
-
3
- import { IMigrateFile } from "../structures/IMigrateFile";
4
- import { IMigrateProgram } from "../structures/IMigrateProgram";
5
- import { FilePrinter } from "../utils/FilePrinter";
6
- import { DtoProgrammer } from "./DtoProgrammer";
7
- import { ImportProgrammer } from "./ImportProgrammer";
8
- import { NestControllerProgrammer } from "./NestControllerProgrammer";
9
- import { NestModuleProgrammer } from "./NestModuleProgrammer";
10
-
11
- export namespace NestProgrammer {
12
- export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
- [
14
- {
15
- location: "src",
16
- file: "MyModule.ts",
17
- statements: NestModuleProgrammer.write(program.controllers),
18
- },
19
- ...program.controllers.map((c) => ({
20
- location: c.location,
21
- file: `${c.name}.ts`,
22
- statements: NestControllerProgrammer.write(program.swagger.components)(
23
- c,
24
- ),
25
- })),
26
- ...[...DtoProgrammer.write(program.swagger.components).entries()].map(
27
- ([key, value]) => ({
28
- location: "src/api/structures",
29
- file: `${key}.ts`,
30
- statements: writeDtoFile(key, value),
31
- }),
32
- ),
33
- ].map((o) => ({
34
- location: o.location,
35
- file: o.file,
36
- content: FilePrinter.write({ statements: o.statements }),
37
- }));
38
-
39
- const writeDtoFile = (
40
- key: string,
41
- modulo: DtoProgrammer.IModule,
42
- ): ts.Statement[] => {
43
- const importer = new ImportProgrammer();
44
- const statements: ts.Statement[] = iterate(importer)(modulo);
45
- if (statements.length === 0) return [];
46
-
47
- return [
48
- ...importer.toStatements((name) => `./${name}`, key),
49
- ...(importer.empty() ? [] : [FilePrinter.enter()]),
50
- ...statements,
51
- ];
52
- };
53
-
54
- const iterate =
55
- (importer: ImportProgrammer) =>
56
- (modulo: DtoProgrammer.IModule): ts.Statement[] => {
57
- const output: ts.Statement[] = [];
58
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
59
- if (modulo.children.size) {
60
- const internal: ts.Statement[] = [];
61
- for (const child of modulo.children.values())
62
- internal.push(...iterate(importer)(child));
63
- output.push(
64
- ts.factory.createModuleDeclaration(
65
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
66
- ts.factory.createIdentifier(modulo.name),
67
- ts.factory.createModuleBlock(internal),
68
- ts.NodeFlags.Namespace,
69
- ),
70
- );
71
- }
72
- return output;
73
- };
74
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateFile } from "../structures/IMigrateFile";
4
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
5
+ import { FilePrinter } from "../utils/FilePrinter";
6
+ import { DtoProgrammer } from "./DtoProgrammer";
7
+ import { ImportProgrammer } from "./ImportProgrammer";
8
+ import { NestControllerProgrammer } from "./NestControllerProgrammer";
9
+ import { NestModuleProgrammer } from "./NestModuleProgrammer";
10
+
11
+ export namespace NestProgrammer {
12
+ export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
+ [
14
+ {
15
+ location: "src",
16
+ file: "MyModule.ts",
17
+ statements: NestModuleProgrammer.write(program.controllers),
18
+ },
19
+ ...program.controllers.map((c) => ({
20
+ location: c.location,
21
+ file: `${c.name}.ts`,
22
+ statements: NestControllerProgrammer.write(program.swagger.components)(
23
+ c,
24
+ ),
25
+ })),
26
+ ...[...DtoProgrammer.write(program.swagger.components).entries()].map(
27
+ ([key, value]) => ({
28
+ location: "src/api/structures",
29
+ file: `${key}.ts`,
30
+ statements: writeDtoFile(key, value),
31
+ }),
32
+ ),
33
+ ].map((o) => ({
34
+ location: o.location,
35
+ file: o.file,
36
+ content: FilePrinter.write({ statements: o.statements }),
37
+ }));
38
+
39
+ const writeDtoFile = (
40
+ key: string,
41
+ modulo: DtoProgrammer.IModule,
42
+ ): ts.Statement[] => {
43
+ const importer = new ImportProgrammer();
44
+ const statements: ts.Statement[] = iterate(importer)(modulo);
45
+ if (statements.length === 0) return [];
46
+
47
+ return [
48
+ ...importer.toStatements((name) => `./${name}`, key),
49
+ ...(importer.empty() ? [] : [FilePrinter.enter()]),
50
+ ...statements,
51
+ ];
52
+ };
53
+
54
+ const iterate =
55
+ (importer: ImportProgrammer) =>
56
+ (modulo: DtoProgrammer.IModule): ts.Statement[] => {
57
+ const output: ts.Statement[] = [];
58
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
59
+ if (modulo.children.size) {
60
+ const internal: ts.Statement[] = [];
61
+ for (const child of modulo.children.values())
62
+ internal.push(...iterate(importer)(child));
63
+ output.push(
64
+ ts.factory.createModuleDeclaration(
65
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
66
+ ts.factory.createIdentifier(modulo.name),
67
+ ts.factory.createModuleBlock(internal),
68
+ ts.NodeFlags.Namespace,
69
+ ),
70
+ );
71
+ }
72
+ return output;
73
+ };
74
+ }
@@ -1,9 +1,9 @@
1
- import { IMigrateConfig } from "../IMigrateConfig";
2
- import { IMigrateController } from "./IMigrateController";
3
- import { ISwagger } from "./ISwagger";
4
-
5
- export interface IMigrateProgram {
6
- config: IMigrateConfig;
7
- controllers: IMigrateController[];
8
- swagger: ISwagger;
9
- }
1
+ import { IMigrateConfig } from "../IMigrateConfig";
2
+ import { IMigrateController } from "./IMigrateController";
3
+ import { ISwagger } from "./ISwagger";
4
+
5
+ export interface IMigrateProgram {
6
+ config: IMigrateConfig;
7
+ controllers: IMigrateController[];
8
+ swagger: ISwagger;
9
+ }
@@ -1,44 +1,44 @@
1
- import { ISwaggerSchema } from "./ISwaggeSchema";
2
-
3
- export interface IMigrateRoute {
4
- name: string;
5
- path: string;
6
- method: string;
7
- parameters: IMigrateRoute.IParameter[];
8
- headers: IMigrateRoute.IHeaders | null;
9
- query: IMigrateRoute.IQuery | null;
10
- body: IMigrateRoute.IBody | null;
11
- success: IMigrateRoute.IBody | null;
12
- exceptions: Record<string, IMigrateRoute.IException>;
13
- description?: string;
14
- tags: string[];
15
- deprecated: boolean;
16
- }
17
- export namespace IMigrateRoute {
18
- export interface IParameter {
19
- key: string;
20
- schema: ISwaggerSchema;
21
- description?: string;
22
- }
23
- export interface IHeaders {
24
- key: string;
25
- schema: ISwaggerSchema;
26
- }
27
- export interface IQuery {
28
- key: string;
29
- schema: ISwaggerSchema;
30
- }
31
- export interface IBody {
32
- key: string;
33
- type:
34
- | "text/plain"
35
- | "application/json"
36
- | "application/x-www-form-urlencoded";
37
- schema: ISwaggerSchema;
38
- "x-nestia-encrypted"?: boolean;
39
- }
40
- export interface IException {
41
- description?: string;
42
- schema: ISwaggerSchema;
43
- }
44
- }
1
+ import { ISwaggerSchema } from "./ISwaggeSchema";
2
+
3
+ export interface IMigrateRoute {
4
+ name: string;
5
+ path: string;
6
+ method: string;
7
+ parameters: IMigrateRoute.IParameter[];
8
+ headers: IMigrateRoute.IHeaders | null;
9
+ query: IMigrateRoute.IQuery | null;
10
+ body: IMigrateRoute.IBody | null;
11
+ success: IMigrateRoute.IBody | null;
12
+ exceptions: Record<string, IMigrateRoute.IException>;
13
+ description?: string;
14
+ tags: string[];
15
+ deprecated: boolean;
16
+ }
17
+ export namespace IMigrateRoute {
18
+ export interface IParameter {
19
+ key: string;
20
+ schema: ISwaggerSchema;
21
+ description?: string;
22
+ }
23
+ export interface IHeaders {
24
+ key: string;
25
+ schema: ISwaggerSchema;
26
+ }
27
+ export interface IQuery {
28
+ key: string;
29
+ schema: ISwaggerSchema;
30
+ }
31
+ export interface IBody {
32
+ key: string;
33
+ type:
34
+ | "text/plain"
35
+ | "application/json"
36
+ | "application/x-www-form-urlencoded";
37
+ schema: ISwaggerSchema;
38
+ "x-nestia-encrypted"?: boolean;
39
+ }
40
+ export interface IException {
41
+ description?: string;
42
+ schema: ISwaggerSchema;
43
+ }
44
+ }