@nestia/migrate 0.13.0-dev.20240411-2 → 0.13.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 (33) hide show
  1. package/lib/MigrateApplication.js +812 -710
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
  4. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  6. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  7. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  8. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  9. package/lib/internal/MigrateCommander.js.map +1 -1
  10. package/lib/programmers/MigrateSchemaProgrammer.js +25 -26
  11. package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
  12. package/package.json +79 -79
  13. package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
  14. package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
  15. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  16. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  17. package/src/internal/MigrateCommander.ts +76 -70
  18. package/src/module.ts +8 -8
  19. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  20. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  21. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  22. package/src/programmers/MigrateApiProgrammer.ts +172 -172
  23. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  24. package/src/programmers/MigrateDtoProgrammer.ts +77 -77
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  28. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  29. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  30. package/src/structures/IMigrateDto.ts +8 -8
  31. package/src/structures/IMigrateProgram.ts +27 -27
  32. package/src/structures/IMigrateRoute.ts +51 -51
  33. package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -1,77 +1,77 @@
1
- import { OpenApi } from "@samchon/openapi";
2
- import { IPointer } from "tstl";
3
- import ts from "typescript";
4
-
5
- import { FilePrinter } from "../utils/FilePrinter";
6
- import { MapUtil } from "../utils/MapUtil";
7
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
8
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
9
-
10
- export namespace MigrateDtoProgrammer {
11
- export interface IModule {
12
- name: string;
13
- children: Map<string, IModule>;
14
- programmer:
15
- | null
16
- | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
17
- }
18
-
19
- export const compose = (
20
- components: OpenApi.IComponents,
21
- ): Map<string, IModule> => {
22
- const dict: Map<string, IModule> = new Map();
23
- for (const [key, value] of Object.entries(components.schemas ?? {}))
24
- prepare(dict)(key)((importer) =>
25
- writeAlias(components)(importer)(key, value),
26
- );
27
- return dict;
28
- };
29
-
30
- const prepare =
31
- (dict: Map<string, IModule>) =>
32
- (name: string) =>
33
- (
34
- programmer: (
35
- importer: MigrateImportProgrammer,
36
- ) => ts.TypeAliasDeclaration,
37
- ) => {
38
- const accessors: string[] = name.split(".");
39
- const modulo: IPointer<IModule> = { value: null! };
40
-
41
- accessors.forEach((acc, i) => {
42
- modulo.value = MapUtil.take(dict)(acc)(() => ({
43
- name: acc,
44
- children: new Map(),
45
- programmer: null,
46
- }));
47
- if (i === accessors.length - 1) modulo.value.programmer = programmer;
48
- dict = modulo.value.children;
49
- });
50
- return modulo!;
51
- };
52
-
53
- const writeAlias =
54
- (components: OpenApi.IComponents) =>
55
- (importer: MigrateImportProgrammer) =>
56
- (key: string, value: OpenApi.IJsonSchema) =>
57
- FilePrinter.description(
58
- ts.factory.createTypeAliasDeclaration(
59
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
60
- key.split(".").at(-1)!,
61
- [],
62
- MigrateSchemaProgrammer.write(components)(importer)(value),
63
- ),
64
- writeComment(value),
65
- );
66
- }
67
-
68
- const writeComment = (schema: OpenApi.IJsonSchema): string =>
69
- [
70
- ...(schema.description?.length ? [schema.description] : []),
71
- ...(schema.description?.length &&
72
- (schema.title !== undefined || schema.deprecated === true)
73
- ? [""]
74
- : []),
75
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
76
- ...(schema.deprecated === true ? [`@deprecated`] : []),
77
- ].join("\n");
1
+ import { OpenApi } from "@samchon/openapi";
2
+ import { IPointer } from "tstl";
3
+ import ts from "typescript";
4
+
5
+ import { FilePrinter } from "../utils/FilePrinter";
6
+ import { MapUtil } from "../utils/MapUtil";
7
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
8
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
9
+
10
+ export namespace MigrateDtoProgrammer {
11
+ export interface IModule {
12
+ name: string;
13
+ children: Map<string, IModule>;
14
+ programmer:
15
+ | null
16
+ | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
17
+ }
18
+
19
+ export const compose = (
20
+ components: OpenApi.IComponents,
21
+ ): Map<string, IModule> => {
22
+ const dict: Map<string, IModule> = new Map();
23
+ for (const [key, value] of Object.entries(components.schemas ?? {}))
24
+ prepare(dict)(key)((importer) =>
25
+ writeAlias(components)(importer)(key, value),
26
+ );
27
+ return dict;
28
+ };
29
+
30
+ const prepare =
31
+ (dict: Map<string, IModule>) =>
32
+ (name: string) =>
33
+ (
34
+ programmer: (
35
+ importer: MigrateImportProgrammer,
36
+ ) => ts.TypeAliasDeclaration,
37
+ ) => {
38
+ const accessors: string[] = name.split(".");
39
+ const modulo: IPointer<IModule> = { value: null! };
40
+
41
+ accessors.forEach((acc, i) => {
42
+ modulo.value = MapUtil.take(dict)(acc)(() => ({
43
+ name: acc,
44
+ children: new Map(),
45
+ programmer: null,
46
+ }));
47
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
48
+ dict = modulo.value.children;
49
+ });
50
+ return modulo!;
51
+ };
52
+
53
+ const writeAlias =
54
+ (components: OpenApi.IComponents) =>
55
+ (importer: MigrateImportProgrammer) =>
56
+ (key: string, value: OpenApi.IJsonSchema) =>
57
+ FilePrinter.description(
58
+ ts.factory.createTypeAliasDeclaration(
59
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
60
+ key.split(".").at(-1)!,
61
+ [],
62
+ MigrateSchemaProgrammer.write(components)(importer)(value),
63
+ ),
64
+ writeComment(value),
65
+ );
66
+ }
67
+
68
+ const writeComment = (schema: OpenApi.IJsonSchema): string =>
69
+ [
70
+ ...(schema.description?.length ? [schema.description] : []),
71
+ ...(schema.description?.length &&
72
+ (schema.title !== undefined || schema.deprecated === true)
73
+ ? [""]
74
+ : []),
75
+ ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
76
+ ...(schema.deprecated === true ? [`@deprecated`] : []),
77
+ ].join("\n");
@@ -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 { IMigrateRoute } from "../structures/IMigrateRoute";
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: 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: OpenApi.IComponents) =>
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: OpenApi.IComponents) =>
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 { OpenApi } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+
5
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
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: 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: OpenApi.IComponents) =>
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: OpenApi.IComponents) =>
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 { OpenApi } from "@samchon/openapi";
2
- import ts from "typescript";
3
-
4
- import { IMigrateFile } from "../structures/IMigrateFile";
5
- import { IMigrateProgram } from "../structures/IMigrateProgram";
6
- import { IMigrateRoute } from "../structures/IMigrateRoute";
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.document.components)))
15
- .flat();
16
-
17
- const writeFile =
18
- (components: OpenApi.IComponents) =>
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 { OpenApi } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+
4
+ import { IMigrateFile } from "../structures/IMigrateFile";
5
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
6
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
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.document.components)))
15
+ .flat();
16
+
17
+ const writeFile =
18
+ (components: OpenApi.IComponents) =>
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,50 +1,50 @@
1
- import { OpenApi } from "@samchon/openapi";
2
- import ts from "typescript";
3
-
4
- import { IMigrateController } from "../structures/IMigrateController";
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: 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 { OpenApi } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+
4
+ import { IMigrateController } from "../structures/IMigrateController";
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: 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
+ }