@nestia/migrate 6.0.4 → 6.0.6
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/lib/MigrateApplication.d.ts +4 -0
- package/lib/MigrateApplication.js +2 -0
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/index.mjs +29 -23
- package/lib/index.mjs.map +1 -1
- package/lib/internal/MigrateCommander.d.ts +1 -0
- package/lib/internal/MigrateCommander.js +10 -2
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.js +2 -0
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.js +9 -6
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +3 -2
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateDtoProgrammer.d.ts +2 -1
- package/lib/programmers/MigrateDtoProgrammer.js +10 -5
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestControllerProgrammer.d.ts +2 -1
- package/lib/programmers/MigrateNestControllerProgrammer.js +7 -2
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.d.ts +2 -1
- package/lib/programmers/MigrateNestMethodProgrammer.js +9 -6
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestProgrammer.js +3 -2
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.js +10 -3
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/IHttpMigrateProgram.d.ts +8 -0
- package/lib/utils/FilePrinter.js +3 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/package.json +11 -10
- package/src/MigrateApplication.ts +6 -0
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/internal/MigrateCommander.ts +9 -1
- package/src/programmers/MigrateApiFileProgrammer.ts +2 -0
- package/src/programmers/MigrateApiFunctionProgrammer.ts +10 -7
- package/src/programmers/MigrateApiProgrammer.ts +3 -2
- package/src/programmers/MigrateDtoProgrammer.ts +39 -30
- package/src/programmers/MigrateNestControllerProgrammer.ts +10 -3
- package/src/programmers/MigrateNestMethodProgrammer.ts +10 -6
- package/src/programmers/MigrateNestProgrammer.ts +5 -2
- package/src/programmers/MigrateSchemaProgrammer.ts +11 -6
- package/src/structures/IHttpMigrateProgram.ts +8 -0
- package/src/utils/FilePrinter.ts +3 -1
@@ -2,6 +2,7 @@ import { OpenApi } from "@samchon/openapi";
|
|
2
2
|
import { IPointer } from "tstl";
|
3
3
|
import ts from "typescript";
|
4
4
|
|
5
|
+
import { MigrateApplication } from "../MigrateApplication";
|
5
6
|
import { FilePrinter } from "../utils/FilePrinter";
|
6
7
|
import { MapUtil } from "../utils/MapUtil";
|
7
8
|
import { StringUtil } from "../utils/StringUtil";
|
@@ -17,22 +18,22 @@ export namespace MigrateDtoProgrammer {
|
|
17
18
|
| ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
|
18
19
|
}
|
19
20
|
|
20
|
-
export const compose =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
export const compose =
|
22
|
+
(config: MigrateApplication.IConfig) =>
|
23
|
+
(components: OpenApi.IComponents): Map<string, IModule> => {
|
24
|
+
const dict: Map<string, IModule> = new Map();
|
25
|
+
for (const [key, value] of Object.entries(components.schemas ?? {})) {
|
26
|
+
const emendedKey: string = key
|
27
|
+
.split("/")
|
28
|
+
.filter((str) => str.length !== 0)
|
29
|
+
.map(StringUtil.escapeNonVariable)
|
30
|
+
.join("");
|
31
|
+
prepare(dict)(emendedKey)((importer) =>
|
32
|
+
writeAlias(config)(components)(importer)(emendedKey, value),
|
33
|
+
);
|
34
|
+
}
|
35
|
+
return dict;
|
36
|
+
};
|
36
37
|
|
37
38
|
const prepare =
|
38
39
|
(dict: Map<string, IModule>) =>
|
@@ -58,6 +59,7 @@ export namespace MigrateDtoProgrammer {
|
|
58
59
|
};
|
59
60
|
|
60
61
|
const writeAlias =
|
62
|
+
(config: MigrateApplication.IConfig) =>
|
61
63
|
(components: OpenApi.IComponents) =>
|
62
64
|
(importer: MigrateImportProgrammer) =>
|
63
65
|
(key: string, value: OpenApi.IJsonSchema) =>
|
@@ -68,20 +70,27 @@ export namespace MigrateDtoProgrammer {
|
|
68
70
|
[],
|
69
71
|
MigrateSchemaProgrammer.write(components)(importer)(value),
|
70
72
|
),
|
71
|
-
writeComment(value),
|
73
|
+
writeComment(config)(value, key.indexOf(".") === -1),
|
72
74
|
);
|
73
75
|
}
|
74
76
|
|
75
|
-
const writeComment =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
77
|
+
const writeComment =
|
78
|
+
(config: MigrateApplication.IConfig) =>
|
79
|
+
(schema: OpenApi.IJsonSchema, top: boolean): string =>
|
80
|
+
[
|
81
|
+
...(schema.description?.length ? [schema.description] : []),
|
82
|
+
...(schema.description?.length &&
|
83
|
+
(schema.title !== undefined || schema.deprecated === true)
|
84
|
+
? [""]
|
85
|
+
: []),
|
86
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
87
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
88
|
+
...(top
|
89
|
+
? [
|
90
|
+
`@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
|
91
|
+
]
|
92
|
+
: []),
|
93
|
+
]
|
94
|
+
.join("\n")
|
95
|
+
.split("*/")
|
96
|
+
.join("*\\/");
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { OpenApi } from "@samchon/openapi";
|
2
2
|
import ts from "typescript";
|
3
3
|
|
4
|
+
import { MigrateApplication } from "../MigrateApplication";
|
4
5
|
import { IHttpMigrateController } from "../structures/IHttpMigrateController";
|
5
6
|
import { FilePrinter } from "../utils/FilePrinter";
|
6
7
|
import { StringUtil } from "../utils/StringUtil";
|
@@ -9,6 +10,7 @@ import { MigrateNestMethodProgrammer } from "./MigrateNestMethodProgrammer";
|
|
9
10
|
|
10
11
|
export namespace MigrateNestControllerProgrammer {
|
11
12
|
export const write =
|
13
|
+
(config: MigrateApplication.IConfig) =>
|
12
14
|
(components: OpenApi.IComponents) =>
|
13
15
|
(controller: IHttpMigrateController): ts.Statement[] => {
|
14
16
|
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
@@ -32,9 +34,14 @@ export namespace MigrateNestControllerProgrammer {
|
|
32
34
|
controller.name,
|
33
35
|
[],
|
34
36
|
[],
|
35
|
-
controller.routes
|
36
|
-
|
37
|
-
|
37
|
+
controller.routes
|
38
|
+
.map((route, index) => [
|
39
|
+
...(index !== 0 ? [FilePrinter.newLine() as any] : []),
|
40
|
+
MigrateNestMethodProgrammer.write(config)(components)(importer)(
|
41
|
+
controller,
|
42
|
+
)(route),
|
43
|
+
])
|
44
|
+
.flat(),
|
38
45
|
);
|
39
46
|
return [
|
40
47
|
...importer.toStatements(
|
@@ -5,6 +5,7 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
5
5
|
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
6
6
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
7
7
|
|
8
|
+
import { MigrateApplication } from "../MigrateApplication";
|
8
9
|
import { IHttpMigrateController } from "../structures/IHttpMigrateController";
|
9
10
|
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
10
11
|
import { FilePrinter } from "../utils/FilePrinter";
|
@@ -14,6 +15,7 @@ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
|
14
15
|
|
15
16
|
export namespace MigrateNestMethodProgrammer {
|
16
17
|
export const write =
|
18
|
+
(config: MigrateApplication.IConfig) =>
|
17
19
|
(components: OpenApi.IComponents) =>
|
18
20
|
(importer: MigrateImportProgrammer) =>
|
19
21
|
(controller: IHttpMigrateController) =>
|
@@ -68,14 +70,16 @@ export namespace MigrateNestMethodProgrammer {
|
|
68
70
|
true,
|
69
71
|
),
|
70
72
|
);
|
71
|
-
return FilePrinter.description(method, writeDescription(route));
|
73
|
+
return FilePrinter.description(method, writeDescription(config)(route));
|
72
74
|
};
|
73
75
|
|
74
|
-
const writeDescription =
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
const writeDescription =
|
77
|
+
(config: MigrateApplication.IConfig) =>
|
78
|
+
(method: IHttpMigrateRoute): string =>
|
79
|
+
[
|
80
|
+
method.comment(),
|
81
|
+
`@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
|
82
|
+
].join("\n");
|
79
83
|
|
80
84
|
const writeMethodDecorators =
|
81
85
|
(components: OpenApi.IComponents) =>
|
@@ -25,12 +25,14 @@ export namespace MigrateNestProgrammer {
|
|
25
25
|
...controllers.map((c) => ({
|
26
26
|
location: c.location,
|
27
27
|
file: `${c.name}.ts`,
|
28
|
-
statements: MigrateNestControllerProgrammer.write(
|
28
|
+
statements: MigrateNestControllerProgrammer.write(program)(
|
29
29
|
program.document.components,
|
30
30
|
)(c),
|
31
31
|
})),
|
32
32
|
...[
|
33
|
-
...MigrateDtoProgrammer.compose(program
|
33
|
+
...MigrateDtoProgrammer.compose(program)(
|
34
|
+
program.document.components,
|
35
|
+
).entries(),
|
34
36
|
].map(([key, value]) => ({
|
35
37
|
location: "src/api/structures",
|
36
38
|
file: `${key}.ts`,
|
@@ -76,6 +78,7 @@ export namespace MigrateNestProgrammer {
|
|
76
78
|
),
|
77
79
|
);
|
78
80
|
}
|
81
|
+
output.push(FilePrinter.newLine());
|
79
82
|
return output;
|
80
83
|
};
|
81
84
|
}
|
@@ -256,12 +256,17 @@ export namespace MigrateSchemaProgrammer {
|
|
256
256
|
(schema: OpenApi.IJsonSchema.IObject): ts.TypeNode => {
|
257
257
|
const regular = () =>
|
258
258
|
ts.factory.createTypeLiteralNode(
|
259
|
-
Object.entries(schema.properties ?? [])
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
259
|
+
Object.entries(schema.properties ?? [])
|
260
|
+
.map(([key, value], index) => [
|
261
|
+
...(index !== 0
|
262
|
+
? [ts.factory.createIdentifier("\n") as any]
|
263
|
+
: []),
|
264
|
+
writeRegularProperty(components)(importer)(schema.required ?? [])(
|
265
|
+
key,
|
266
|
+
value,
|
267
|
+
),
|
268
|
+
])
|
269
|
+
.flat(),
|
265
270
|
);
|
266
271
|
const dynamic = () =>
|
267
272
|
ts.factory.createTypeLiteralNode([
|
@@ -12,11 +12,19 @@ export namespace IHttpMigrateProgram {
|
|
12
12
|
simulate: boolean;
|
13
13
|
e2e: boolean;
|
14
14
|
document: OpenApi.IDocument;
|
15
|
+
author?: {
|
16
|
+
tag: string;
|
17
|
+
value: string;
|
18
|
+
};
|
15
19
|
}
|
16
20
|
export interface IConfig {
|
17
21
|
mode: "nest" | "sdk";
|
18
22
|
simulate: boolean;
|
19
23
|
e2e: boolean;
|
24
|
+
author?: {
|
25
|
+
tag: string;
|
26
|
+
value: string;
|
27
|
+
};
|
20
28
|
}
|
21
29
|
export interface IError {
|
22
30
|
method: string;
|
package/src/utils/FilePrinter.ts
CHANGED