@nestia/migrate 0.11.3 → 0.11.5

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 (55) hide show
  1. package/lib/analyzers/MigrateMethodAnalyzer.js +1 -1
  2. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  3. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  4. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  5. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  7. package/lib/utils/openapi-down-convert/converter.js +2 -2
  8. package/package.json +75 -75
  9. package/src/MigrateApplication.ts +81 -81
  10. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  12. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -437
  13. package/src/archivers/MigrateFileArchiver.ts +38 -38
  14. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  15. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  16. package/src/executable/bundle.ts +110 -110
  17. package/src/internal/MigrateCommander.ts +70 -70
  18. package/src/internal/MigrateInquirer.ts +86 -86
  19. package/src/module.ts +14 -14
  20. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  21. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  22. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  23. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  24. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  25. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  26. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  27. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  28. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  29. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  30. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  31. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  32. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  33. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  34. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  35. package/src/structures/IMigrateDto.ts +8 -8
  36. package/src/structures/IMigrateProgram.ts +27 -27
  37. package/src/structures/IMigrateRoute.ts +51 -51
  38. package/src/structures/ISwagger.ts +23 -23
  39. package/src/structures/ISwaggerComponents.ts +14 -14
  40. package/src/structures/ISwaggerRoute.ts +20 -20
  41. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  42. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  43. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  44. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  45. package/src/structures/ISwaggerSchema.ts +90 -90
  46. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  47. package/src/structures/ISwaggerV20.ts +10 -10
  48. package/src/structures/ISwaggerV31.ts +10 -10
  49. package/src/utils/FilePrinter.ts +36 -36
  50. package/src/utils/OpenApiConverter.ts +19 -19
  51. package/src/utils/StringUtil.ts +60 -60
  52. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  53. package/src/utils/SwaggerTypeChecker.ts +67 -67
  54. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  55. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,117 +1,117 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
-
4
- import { IMigrateRoute } from "../structures/IMigrateRoute";
5
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
7
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
8
-
9
- export namespace MigrateE2eFunctionProgrammer {
10
- export const write =
11
- (components: ISwaggerComponents) =>
12
- (importer: MigrateImportProgrammer) =>
13
- (route: IMigrateRoute): ts.FunctionDeclaration =>
14
- ts.factory.createFunctionDeclaration(
15
- [
16
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
17
- ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
18
- ],
19
- undefined,
20
- ["test", "api", ...route.accessor].join("_"),
21
- undefined,
22
- [
23
- IdentifierFactory.parameter(
24
- "connection",
25
- ts.factory.createTypeReferenceNode(
26
- ts.factory.createQualifiedName(
27
- ts.factory.createIdentifier(
28
- importer.external({
29
- type: "default",
30
- library: "@ORGANIZATION/PROJECT-api",
31
- name: "api",
32
- }),
33
- ),
34
- ts.factory.createIdentifier("IConnection"),
35
- ),
36
- ),
37
- ),
38
- ],
39
- undefined,
40
- ts.factory.createBlock(writeBody(components)(importer)(route), true),
41
- );
42
-
43
- export const writeBody =
44
- (components: ISwaggerComponents) =>
45
- (importer: MigrateImportProgrammer) =>
46
- (route: IMigrateRoute): ts.Statement[] => [
47
- ts.factory.createVariableStatement(
48
- [],
49
- ts.factory.createVariableDeclarationList(
50
- [
51
- ts.factory.createVariableDeclaration(
52
- "output",
53
- undefined,
54
- route.success
55
- ? MigrateSchemaProgrammer.write(components)(importer)(
56
- route.success.schema,
57
- )
58
- : undefined,
59
- ts.factory.createAwaitExpression(
60
- writeCallExpressionn(components)(importer)(route),
61
- ),
62
- ),
63
- ],
64
- ts.NodeFlags.Const,
65
- ),
66
- ),
67
- ts.factory.createExpressionStatement(
68
- ts.factory.createCallExpression(
69
- ts.factory.createPropertyAccessExpression(
70
- ts.factory.createIdentifier(
71
- importer.external({
72
- type: "default",
73
- library: "typia",
74
- name: "typia",
75
- }),
76
- ),
77
- "assert",
78
- ),
79
- undefined,
80
- [ts.factory.createIdentifier("output")],
81
- ),
82
- ),
83
- ];
84
-
85
- const writeCallExpressionn =
86
- (components: ISwaggerComponents) =>
87
- (importer: MigrateImportProgrammer) =>
88
- (route: IMigrateRoute): ts.CallExpression =>
89
- ts.factory.createCallExpression(
90
- ts.factory.createPropertyAccessExpression(
91
- ts.factory.createIdentifier("api.functional"),
92
- ts.factory.createIdentifier(route.accessor.join(".")),
93
- ),
94
- undefined,
95
- [
96
- ts.factory.createIdentifier("connection"),
97
- ...[...route.parameters, route.query!, route.body!]
98
- .filter((p) => !!p)
99
- .map((p) =>
100
- ts.factory.createCallExpression(
101
- ts.factory.createPropertyAccessExpression(
102
- ts.factory.createIdentifier(
103
- importer.external({
104
- type: "default",
105
- library: "typia",
106
- name: "typia",
107
- }),
108
- ),
109
- "random",
110
- ),
111
- [MigrateSchemaProgrammer.write(components)(importer)(p.schema)],
112
- undefined,
113
- ),
114
- ),
115
- ],
116
- );
117
- }
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+
4
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
5
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
7
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
8
+
9
+ export namespace MigrateE2eFunctionProgrammer {
10
+ export const write =
11
+ (components: ISwaggerComponents) =>
12
+ (importer: MigrateImportProgrammer) =>
13
+ (route: IMigrateRoute): ts.FunctionDeclaration =>
14
+ ts.factory.createFunctionDeclaration(
15
+ [
16
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
17
+ ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
18
+ ],
19
+ undefined,
20
+ ["test", "api", ...route.accessor].join("_"),
21
+ undefined,
22
+ [
23
+ IdentifierFactory.parameter(
24
+ "connection",
25
+ ts.factory.createTypeReferenceNode(
26
+ ts.factory.createQualifiedName(
27
+ ts.factory.createIdentifier(
28
+ importer.external({
29
+ type: "default",
30
+ library: "@ORGANIZATION/PROJECT-api",
31
+ name: "api",
32
+ }),
33
+ ),
34
+ ts.factory.createIdentifier("IConnection"),
35
+ ),
36
+ ),
37
+ ),
38
+ ],
39
+ undefined,
40
+ ts.factory.createBlock(writeBody(components)(importer)(route), true),
41
+ );
42
+
43
+ export const writeBody =
44
+ (components: ISwaggerComponents) =>
45
+ (importer: MigrateImportProgrammer) =>
46
+ (route: IMigrateRoute): ts.Statement[] => [
47
+ ts.factory.createVariableStatement(
48
+ [],
49
+ ts.factory.createVariableDeclarationList(
50
+ [
51
+ ts.factory.createVariableDeclaration(
52
+ "output",
53
+ undefined,
54
+ route.success
55
+ ? MigrateSchemaProgrammer.write(components)(importer)(
56
+ route.success.schema,
57
+ )
58
+ : undefined,
59
+ ts.factory.createAwaitExpression(
60
+ writeCallExpressionn(components)(importer)(route),
61
+ ),
62
+ ),
63
+ ],
64
+ ts.NodeFlags.Const,
65
+ ),
66
+ ),
67
+ ts.factory.createExpressionStatement(
68
+ ts.factory.createCallExpression(
69
+ ts.factory.createPropertyAccessExpression(
70
+ ts.factory.createIdentifier(
71
+ importer.external({
72
+ type: "default",
73
+ library: "typia",
74
+ name: "typia",
75
+ }),
76
+ ),
77
+ "assert",
78
+ ),
79
+ undefined,
80
+ [ts.factory.createIdentifier("output")],
81
+ ),
82
+ ),
83
+ ];
84
+
85
+ const writeCallExpressionn =
86
+ (components: ISwaggerComponents) =>
87
+ (importer: MigrateImportProgrammer) =>
88
+ (route: IMigrateRoute): ts.CallExpression =>
89
+ ts.factory.createCallExpression(
90
+ ts.factory.createPropertyAccessExpression(
91
+ ts.factory.createIdentifier("api.functional"),
92
+ ts.factory.createIdentifier(route.accessor.join(".")),
93
+ ),
94
+ undefined,
95
+ [
96
+ ts.factory.createIdentifier("connection"),
97
+ ...[...route.parameters, route.query!, route.body!]
98
+ .filter((p) => !!p)
99
+ .map((p) =>
100
+ ts.factory.createCallExpression(
101
+ ts.factory.createPropertyAccessExpression(
102
+ ts.factory.createIdentifier(
103
+ importer.external({
104
+ type: "default",
105
+ library: "typia",
106
+ name: "typia",
107
+ }),
108
+ ),
109
+ "random",
110
+ ),
111
+ [MigrateSchemaProgrammer.write(components)(importer)(p.schema)],
112
+ undefined,
113
+ ),
114
+ ),
115
+ ],
116
+ );
117
+ }
@@ -1,36 +1,36 @@
1
- import ts from "typescript";
2
-
3
- import { IMigrateFile } from "../structures/IMigrateFile";
4
- import { IMigrateProgram } from "../structures/IMigrateProgram";
5
- import { IMigrateRoute } from "../structures/IMigrateRoute";
6
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
7
- import { FilePrinter } from "../utils/FilePrinter";
8
- import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
9
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
-
11
- export namespace MigrateE2eProgrammer {
12
- export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
- program.controllers
14
- .map((c) => c.routes.map(writeFile(program.swagger.components)))
15
- .flat();
16
-
17
- const writeFile =
18
- (components: ISwaggerComponents) =>
19
- (route: IMigrateRoute): IMigrateFile => {
20
- const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
21
- const func: ts.FunctionDeclaration =
22
- MigrateE2eFunctionProgrammer.write(components)(importer)(route);
23
- const statements: ts.Statement[] = [
24
- ...importer.toStatements(
25
- (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
26
- ),
27
- FilePrinter.newLine(),
28
- func,
29
- ];
30
- return {
31
- location: `test/features/api`,
32
- file: `${["test", "api", ...route.accessor].join("_")}.ts`,
33
- content: FilePrinter.write({ statements }),
34
- };
35
- };
36
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateFile } from "../structures/IMigrateFile";
4
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
5
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
6
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
7
+ import { FilePrinter } from "../utils/FilePrinter";
8
+ import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
9
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
+
11
+ export namespace MigrateE2eProgrammer {
12
+ export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
+ program.controllers
14
+ .map((c) => c.routes.map(writeFile(program.swagger.components)))
15
+ .flat();
16
+
17
+ const writeFile =
18
+ (components: ISwaggerComponents) =>
19
+ (route: IMigrateRoute): IMigrateFile => {
20
+ const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
21
+ const func: ts.FunctionDeclaration =
22
+ MigrateE2eFunctionProgrammer.write(components)(importer)(route);
23
+ const statements: ts.Statement[] = [
24
+ ...importer.toStatements(
25
+ (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
26
+ ),
27
+ FilePrinter.newLine(),
28
+ func,
29
+ ];
30
+ return {
31
+ location: `test/features/api`,
32
+ file: `${["test", "api", ...route.accessor].join("_")}.ts`,
33
+ content: FilePrinter.write({ statements }),
34
+ };
35
+ };
36
+ }
@@ -1,121 +1,121 @@
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 MigrateImportProgrammer {
8
- private external_: Map<string, IClause> = new Map();
9
- private dtos_: Set<string> = new Set();
10
-
11
- public constructor() {}
12
-
13
- public empty(): boolean {
14
- return this.external_.size === 0 && this.dtos_.size === 0;
15
- }
16
-
17
- public external(props: MigrateImportProgrammer.IProps): string {
18
- const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
19
- default: null,
20
- instances: new Set(),
21
- }));
22
- const name: string = props.name.split(".")[0];
23
- if (props.type === "default") clause.default = props.name;
24
- else clause.instances.add(name);
25
- return name;
26
- }
27
-
28
- public dto(name: string, namespace?: string): ts.TypeReferenceNode {
29
- const file: string = name.split(".")[0];
30
- this.dtos_.add(file);
31
- return ts.factory.createTypeReferenceNode(
32
- namespace?.length
33
- ? ts.factory.createQualifiedName(
34
- ts.factory.createIdentifier(namespace),
35
- ts.factory.createIdentifier(file),
36
- )
37
- : name,
38
- );
39
- }
40
-
41
- public tag(type: string, arg: number | string): ts.TypeReferenceNode {
42
- const instance: string = this.external({
43
- type: "instance",
44
- library: "typia",
45
- name: "tags",
46
- });
47
- return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
48
- ts.factory.createLiteralTypeNode(
49
- typeof arg === "string"
50
- ? ts.factory.createStringLiteral(arg)
51
- : ExpressionFactory.number(arg),
52
- ),
53
- ]);
54
- }
55
-
56
- public toStatements(
57
- dtoPath: (name: string) => string,
58
- current?: string,
59
- ): ts.Statement[] {
60
- return [
61
- ...[...this.external_.entries()].map(([library, props]) =>
62
- ts.factory.createImportDeclaration(
63
- undefined,
64
- ts.factory.createImportClause(
65
- false,
66
- props.default !== null
67
- ? ts.factory.createIdentifier(props.default)
68
- : undefined,
69
- props.instances.size
70
- ? ts.factory.createNamedImports(
71
- [...props.instances].map((i) =>
72
- ts.factory.createImportSpecifier(
73
- false,
74
- undefined,
75
- ts.factory.createIdentifier(i),
76
- ),
77
- ),
78
- )
79
- : undefined,
80
- ),
81
- ts.factory.createStringLiteral(library),
82
- ),
83
- ),
84
- ...(this.external_.size && this.dtos_.size
85
- ? [FilePrinter.newLine()]
86
- : []),
87
- ...[...this.dtos_]
88
- .filter(
89
- current ? (name) => name !== current!.split(".")[0] : () => true,
90
- )
91
- .map((i) =>
92
- ts.factory.createImportDeclaration(
93
- undefined,
94
- ts.factory.createImportClause(
95
- false,
96
- undefined,
97
- ts.factory.createNamedImports([
98
- ts.factory.createImportSpecifier(
99
- false,
100
- undefined,
101
- ts.factory.createIdentifier(i),
102
- ),
103
- ]),
104
- ),
105
- ts.factory.createStringLiteral(dtoPath(i)),
106
- ),
107
- ),
108
- ];
109
- }
110
- }
111
- export namespace MigrateImportProgrammer {
112
- export interface IProps {
113
- type: "default" | "instance";
114
- library: string;
115
- name: string;
116
- }
117
- }
118
- interface IClause {
119
- default: string | null;
120
- instances: Set<string>;
121
- }
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 MigrateImportProgrammer {
8
+ private external_: Map<string, IClause> = new Map();
9
+ private dtos_: Set<string> = new Set();
10
+
11
+ public constructor() {}
12
+
13
+ public empty(): boolean {
14
+ return this.external_.size === 0 && this.dtos_.size === 0;
15
+ }
16
+
17
+ public external(props: MigrateImportProgrammer.IProps): string {
18
+ const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
19
+ default: null,
20
+ instances: new Set(),
21
+ }));
22
+ const name: string = props.name.split(".")[0];
23
+ if (props.type === "default") clause.default = props.name;
24
+ else clause.instances.add(name);
25
+ return name;
26
+ }
27
+
28
+ public dto(name: string, namespace?: string): ts.TypeReferenceNode {
29
+ const file: string = name.split(".")[0];
30
+ this.dtos_.add(file);
31
+ return ts.factory.createTypeReferenceNode(
32
+ namespace?.length
33
+ ? ts.factory.createQualifiedName(
34
+ ts.factory.createIdentifier(namespace),
35
+ ts.factory.createIdentifier(file),
36
+ )
37
+ : name,
38
+ );
39
+ }
40
+
41
+ public tag(type: string, arg: number | string): ts.TypeReferenceNode {
42
+ const instance: string = this.external({
43
+ type: "instance",
44
+ library: "typia",
45
+ name: "tags",
46
+ });
47
+ return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
48
+ ts.factory.createLiteralTypeNode(
49
+ typeof arg === "string"
50
+ ? ts.factory.createStringLiteral(arg)
51
+ : ExpressionFactory.number(arg),
52
+ ),
53
+ ]);
54
+ }
55
+
56
+ public toStatements(
57
+ dtoPath: (name: string) => string,
58
+ current?: string,
59
+ ): ts.Statement[] {
60
+ return [
61
+ ...[...this.external_.entries()].map(([library, props]) =>
62
+ ts.factory.createImportDeclaration(
63
+ undefined,
64
+ ts.factory.createImportClause(
65
+ false,
66
+ props.default !== null
67
+ ? ts.factory.createIdentifier(props.default)
68
+ : undefined,
69
+ props.instances.size
70
+ ? ts.factory.createNamedImports(
71
+ [...props.instances].map((i) =>
72
+ ts.factory.createImportSpecifier(
73
+ false,
74
+ undefined,
75
+ ts.factory.createIdentifier(i),
76
+ ),
77
+ ),
78
+ )
79
+ : undefined,
80
+ ),
81
+ ts.factory.createStringLiteral(library),
82
+ ),
83
+ ),
84
+ ...(this.external_.size && this.dtos_.size
85
+ ? [FilePrinter.newLine()]
86
+ : []),
87
+ ...[...this.dtos_]
88
+ .filter(
89
+ current ? (name) => name !== current!.split(".")[0] : () => true,
90
+ )
91
+ .map((i) =>
92
+ ts.factory.createImportDeclaration(
93
+ undefined,
94
+ ts.factory.createImportClause(
95
+ false,
96
+ undefined,
97
+ ts.factory.createNamedImports([
98
+ ts.factory.createImportSpecifier(
99
+ false,
100
+ undefined,
101
+ ts.factory.createIdentifier(i),
102
+ ),
103
+ ]),
104
+ ),
105
+ ts.factory.createStringLiteral(dtoPath(i)),
106
+ ),
107
+ ),
108
+ ];
109
+ }
110
+ }
111
+ export namespace MigrateImportProgrammer {
112
+ export interface IProps {
113
+ type: "default" | "instance";
114
+ library: string;
115
+ name: string;
116
+ }
117
+ }
118
+ interface IClause {
119
+ default: string | null;
120
+ instances: Set<string>;
121
+ }
@@ -1,50 +1,50 @@
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 { MigrateImportProgrammer } from "./MigrateImportProgrammer";
8
- import { MigrateNestMethodProgrammer } from "./MigrateNestMethodProgrammer";
9
-
10
- export namespace MigrateNestControllerProgrammer {
11
- export const write =
12
- (components: ISwaggerComponents) =>
13
- (controller: IMigrateController): ts.Statement[] => {
14
- const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
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(
36
- MigrateNestMethodProgrammer.write(components)(importer),
37
- ),
38
- );
39
- return [
40
- ...importer.toStatements(
41
- (ref) =>
42
- `${"../".repeat(
43
- StringUtil.splitWithNormalization(controller.location).length - 1,
44
- )}api/structures/${ref}`,
45
- ),
46
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
47
- $class,
48
- ];
49
- };
50
- }
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 { MigrateImportProgrammer } from "./MigrateImportProgrammer";
8
+ import { MigrateNestMethodProgrammer } from "./MigrateNestMethodProgrammer";
9
+
10
+ export namespace MigrateNestControllerProgrammer {
11
+ export const write =
12
+ (components: ISwaggerComponents) =>
13
+ (controller: IMigrateController): ts.Statement[] => {
14
+ const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
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(
36
+ MigrateNestMethodProgrammer.write(components)(importer),
37
+ ),
38
+ );
39
+ return [
40
+ ...importer.toStatements(
41
+ (ref) =>
42
+ `${"../".repeat(
43
+ StringUtil.splitWithNormalization(controller.location).length - 1,
44
+ )}api/structures/${ref}`,
45
+ ),
46
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
47
+ $class,
48
+ ];
49
+ };
50
+ }