@nestia/migrate 4.6.1-dev.20250117 → 4.6.2
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.
- package/README.md +92 -87
- package/lib/MigrateApplication.js +3 -3
- package/lib/bundles/NEST_TEMPLATE.js +84 -64
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +30 -30
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/index.mjs +118 -102
- package/lib/index.mjs.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.js +6 -6
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/{MigrateApiSimulatationProgrammer.d.ts → MigrateApiSimulationProgrammer.d.ts} +1 -1
- package/lib/programmers/{MigrateApiSimulatationProgrammer.js → MigrateApiSimulationProgrammer.js} +7 -7
- package/lib/programmers/MigrateApiSimulationProgrammer.js.map +1 -0
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +6 -6
- package/src/MigrateApplication.ts +107 -107
- package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
- package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +84 -64
- package/src/bundles/SDK_TEMPLATE.ts +30 -30
- package/src/executable/bundle.js +125 -125
- package/src/executable/migrate.ts +7 -7
- package/src/factories/TypeLiteralFactory.ts +57 -57
- package/src/index.ts +4 -4
- package/src/internal/MigrateCommander.ts +86 -86
- package/src/internal/MigrateInquirer.ts +89 -89
- package/src/module.ts +8 -8
- package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
- package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
- package/src/programmers/MigrateApiProgrammer.ts +103 -103
- package/src/programmers/{MigrateApiSimulatationProgrammer.ts → MigrateApiSimulationProgrammer.ts} +324 -324
- package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
- package/src/programmers/MigrateDtoProgrammer.ts +87 -87
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +34 -34
- package/src/programmers/MigrateImportProgrammer.ts +118 -118
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
- package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
- package/src/programmers/MigrateNestProgrammer.ts +81 -81
- package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
- package/src/structures/IHttpMigrateController.ts +8 -8
- package/src/structures/IHttpMigrateDto.ts +8 -8
- package/src/structures/IHttpMigrateFile.ts +5 -5
- package/src/structures/IHttpMigrateProgram.ts +27 -27
- package/src/structures/IHttpMigrateRoute.ts +1 -1
- package/src/structures/IHttpMigrateSchema.ts +4 -4
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/MapUtil.ts +13 -13
- package/src/utils/OpenApiTypeChecker.ts +73 -73
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +113 -113
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
- package/src/utils/openapi-down-convert/converter.ts +527 -527
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +0 -1
@@ -1,117 +1,117 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
-
|
5
|
-
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
6
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
7
|
-
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
8
|
-
|
9
|
-
export namespace MigrateE2eFunctionProgrammer {
|
10
|
-
export const write =
|
11
|
-
(components: OpenApi.IComponents) =>
|
12
|
-
(importer: MigrateImportProgrammer) =>
|
13
|
-
(route: IHttpMigrateRoute): 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: OpenApi.IComponents) =>
|
45
|
-
(importer: MigrateImportProgrammer) =>
|
46
|
-
(route: IHttpMigrateRoute): 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: OpenApi.IComponents) =>
|
87
|
-
(importer: MigrateImportProgrammer) =>
|
88
|
-
(route: IHttpMigrateRoute): 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 { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
+
|
5
|
+
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
6
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
7
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
8
|
+
|
9
|
+
export namespace MigrateE2eFunctionProgrammer {
|
10
|
+
export const write =
|
11
|
+
(components: OpenApi.IComponents) =>
|
12
|
+
(importer: MigrateImportProgrammer) =>
|
13
|
+
(route: IHttpMigrateRoute): 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: OpenApi.IComponents) =>
|
45
|
+
(importer: MigrateImportProgrammer) =>
|
46
|
+
(route: IHttpMigrateRoute): 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: OpenApi.IComponents) =>
|
87
|
+
(importer: MigrateImportProgrammer) =>
|
88
|
+
(route: IHttpMigrateRoute): 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,34 +1,34 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
|
4
|
-
import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
|
5
|
-
import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
|
6
|
-
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
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: IHttpMigrateProgram): IHttpMigrateFile[] =>
|
13
|
-
program.routes.map(writeFile(program.document.components));
|
14
|
-
|
15
|
-
const writeFile =
|
16
|
-
(components: OpenApi.IComponents) =>
|
17
|
-
(route: IHttpMigrateRoute): IHttpMigrateFile => {
|
18
|
-
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
19
|
-
const func: ts.FunctionDeclaration =
|
20
|
-
MigrateE2eFunctionProgrammer.write(components)(importer)(route);
|
21
|
-
const statements: ts.Statement[] = [
|
22
|
-
...importer.toStatements(
|
23
|
-
(name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
|
24
|
-
),
|
25
|
-
FilePrinter.newLine(),
|
26
|
-
func,
|
27
|
-
];
|
28
|
-
return {
|
29
|
-
location: `test/features/api`,
|
30
|
-
file: `${["test", "api", ...route.accessor].join("_")}.ts`,
|
31
|
-
content: FilePrinter.write({ statements }),
|
32
|
-
};
|
33
|
-
};
|
34
|
-
}
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
|
4
|
+
import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
|
5
|
+
import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
|
6
|
+
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
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: IHttpMigrateProgram): IHttpMigrateFile[] =>
|
13
|
+
program.routes.map(writeFile(program.document.components));
|
14
|
+
|
15
|
+
const writeFile =
|
16
|
+
(components: OpenApi.IComponents) =>
|
17
|
+
(route: IHttpMigrateRoute): IHttpMigrateFile => {
|
18
|
+
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
19
|
+
const func: ts.FunctionDeclaration =
|
20
|
+
MigrateE2eFunctionProgrammer.write(components)(importer)(route);
|
21
|
+
const statements: ts.Statement[] = [
|
22
|
+
...importer.toStatements(
|
23
|
+
(name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
|
24
|
+
),
|
25
|
+
FilePrinter.newLine(),
|
26
|
+
func,
|
27
|
+
];
|
28
|
+
return {
|
29
|
+
location: `test/features/api`,
|
30
|
+
file: `${["test", "api", ...route.accessor].join("_")}.ts`,
|
31
|
+
content: FilePrinter.write({ statements }),
|
32
|
+
};
|
33
|
+
};
|
34
|
+
}
|
@@ -1,118 +1,118 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
|
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?: any): ts.TypeReferenceNode {
|
42
|
-
const instance: string = this.external({
|
43
|
-
type: "instance",
|
44
|
-
library: "typia",
|
45
|
-
name: "tags",
|
46
|
-
});
|
47
|
-
return ts.factory.createTypeReferenceNode(
|
48
|
-
`${instance}.${type}`,
|
49
|
-
arg === undefined ? [] : [TypeLiteralFactory.generate(arg)],
|
50
|
-
);
|
51
|
-
}
|
52
|
-
|
53
|
-
public toStatements(
|
54
|
-
dtoPath: (name: string) => string,
|
55
|
-
current?: string,
|
56
|
-
): ts.Statement[] {
|
57
|
-
return [
|
58
|
-
...[...this.external_.entries()].map(([library, props]) =>
|
59
|
-
ts.factory.createImportDeclaration(
|
60
|
-
undefined,
|
61
|
-
ts.factory.createImportClause(
|
62
|
-
false,
|
63
|
-
props.default !== null
|
64
|
-
? ts.factory.createIdentifier(props.default)
|
65
|
-
: undefined,
|
66
|
-
props.instances.size
|
67
|
-
? ts.factory.createNamedImports(
|
68
|
-
[...props.instances].map((i) =>
|
69
|
-
ts.factory.createImportSpecifier(
|
70
|
-
false,
|
71
|
-
undefined,
|
72
|
-
ts.factory.createIdentifier(i),
|
73
|
-
),
|
74
|
-
),
|
75
|
-
)
|
76
|
-
: undefined,
|
77
|
-
),
|
78
|
-
ts.factory.createStringLiteral(library),
|
79
|
-
),
|
80
|
-
),
|
81
|
-
...(this.external_.size && this.dtos_.size
|
82
|
-
? [FilePrinter.newLine()]
|
83
|
-
: []),
|
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 MigrateImportProgrammer {
|
109
|
-
export interface IProps {
|
110
|
-
type: "default" | "instance";
|
111
|
-
library: string;
|
112
|
-
name: string;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
interface IClause {
|
116
|
-
default: string | null;
|
117
|
-
instances: Set<string>;
|
118
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
|
3
|
+
import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
|
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?: any): ts.TypeReferenceNode {
|
42
|
+
const instance: string = this.external({
|
43
|
+
type: "instance",
|
44
|
+
library: "typia",
|
45
|
+
name: "tags",
|
46
|
+
});
|
47
|
+
return ts.factory.createTypeReferenceNode(
|
48
|
+
`${instance}.${type}`,
|
49
|
+
arg === undefined ? [] : [TypeLiteralFactory.generate(arg)],
|
50
|
+
);
|
51
|
+
}
|
52
|
+
|
53
|
+
public toStatements(
|
54
|
+
dtoPath: (name: string) => string,
|
55
|
+
current?: string,
|
56
|
+
): ts.Statement[] {
|
57
|
+
return [
|
58
|
+
...[...this.external_.entries()].map(([library, props]) =>
|
59
|
+
ts.factory.createImportDeclaration(
|
60
|
+
undefined,
|
61
|
+
ts.factory.createImportClause(
|
62
|
+
false,
|
63
|
+
props.default !== null
|
64
|
+
? ts.factory.createIdentifier(props.default)
|
65
|
+
: undefined,
|
66
|
+
props.instances.size
|
67
|
+
? ts.factory.createNamedImports(
|
68
|
+
[...props.instances].map((i) =>
|
69
|
+
ts.factory.createImportSpecifier(
|
70
|
+
false,
|
71
|
+
undefined,
|
72
|
+
ts.factory.createIdentifier(i),
|
73
|
+
),
|
74
|
+
),
|
75
|
+
)
|
76
|
+
: undefined,
|
77
|
+
),
|
78
|
+
ts.factory.createStringLiteral(library),
|
79
|
+
),
|
80
|
+
),
|
81
|
+
...(this.external_.size && this.dtos_.size
|
82
|
+
? [FilePrinter.newLine()]
|
83
|
+
: []),
|
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 MigrateImportProgrammer {
|
109
|
+
export interface IProps {
|
110
|
+
type: "default" | "instance";
|
111
|
+
library: string;
|
112
|
+
name: string;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
interface IClause {
|
116
|
+
default: string | null;
|
117
|
+
instances: Set<string>;
|
118
|
+
}
|
@@ -1,50 +1,50 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
|
4
|
-
import { IHttpMigrateController } from "../structures/IHttpMigrateController";
|
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: OpenApi.IComponents) =>
|
13
|
-
(controller: IHttpMigrateController): 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)(controller),
|
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 { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
|
4
|
+
import { IHttpMigrateController } from "../structures/IHttpMigrateController";
|
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: OpenApi.IComponents) =>
|
13
|
+
(controller: IHttpMigrateController): 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)(controller),
|
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
|
+
}
|