@nestia/migrate 0.7.6 → 0.7.8

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 (76) hide show
  1. package/lib/MigrateApplication.js +7 -4
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateAnalyzer.d.ts +2 -3
  4. package/lib/analyzers/MigrateAnalyzer.js +1 -5
  5. package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
  6. package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
  7. package/lib/analyzers/MigrateControllerAnalyzer.js +22 -13
  8. package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
  10. package/lib/analyzers/MigrateMethodAnalyzer.js +16 -16
  11. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  12. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  13. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  14. package/lib/internal/MigrateCommander.js +12 -1
  15. package/lib/internal/MigrateCommander.js.map +1 -1
  16. package/lib/module.d.ts +8 -0
  17. package/lib/module.js +8 -0
  18. package/lib/module.js.map +1 -1
  19. package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
  20. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
  21. package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -2
  22. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  23. package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
  24. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  25. package/lib/programmers/MigrateApiProgrammer.js +3 -3
  26. package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
  27. package/lib/programmers/MigrateImportProgrammer.js +5 -5
  28. package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
  29. package/lib/programmers/MigrateNestModuleProgrammer.js +1 -1
  30. package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -1
  31. package/lib/programmers/MigrateSchemaProgrammer.d.ts +1 -1
  32. package/lib/structures/IMigrateDto.d.ts +1 -1
  33. package/lib/structures/IMigrateProgram.d.ts +20 -4
  34. package/lib/structures/IMigrateRoute.d.ts +1 -1
  35. package/lib/structures/ISwaggerComponents.d.ts +1 -1
  36. package/lib/structures/ISwaggerRoute.d.ts +1 -1
  37. package/lib/structures/{ISwaggeSchema.js → ISwaggerSchema.js} +1 -1
  38. package/lib/structures/ISwaggerSchema.js.map +1 -0
  39. package/lib/utils/SwaggerTypeChecker.d.ts +1 -1
  40. package/package.json +70 -68
  41. package/src/MigrateApplication.ts +54 -48
  42. package/src/analyzers/MigrateAnalyzer.ts +9 -13
  43. package/src/analyzers/MigrateControllerAnalyzer.ts +139 -122
  44. package/src/analyzers/MigrateMethodAnalyzer.ts +350 -348
  45. package/src/archivers/MigrateFileArchiver.ts +38 -38
  46. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  47. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  48. package/src/executable/bundle.ts +109 -109
  49. package/src/internal/MigrateCommander.ts +62 -51
  50. package/src/module.ts +14 -4
  51. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  52. package/src/programmers/MigrateApiFunctionProgrammer.ts +203 -203
  53. package/src/programmers/MigrateApiNamespaceProgrammer.ts +430 -430
  54. package/src/programmers/MigrateApiProgrammer.ts +132 -132
  55. package/src/programmers/MigrateApiSimulatationProgrammer.ts +328 -328
  56. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  57. package/src/programmers/MigrateImportProgrammer.ts +114 -116
  58. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  59. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  60. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -62
  61. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  62. package/src/programmers/MigrateSchemaProgrammer.ts +257 -257
  63. package/src/structures/IMigrateDto.ts +8 -8
  64. package/src/structures/IMigrateProgram.ts +25 -9
  65. package/src/structures/IMigrateRoute.ts +46 -46
  66. package/src/structures/ISwaggerComponents.ts +7 -7
  67. package/src/structures/ISwaggerRoute.ts +55 -55
  68. package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +90 -90
  69. package/src/utils/FilePrinter.ts +36 -36
  70. package/src/utils/SwaggerTypeChecker.ts +67 -67
  71. package/lib/IMigrateConfig.d.ts +0 -4
  72. package/lib/IMigrateConfig.js +0 -3
  73. package/lib/IMigrateConfig.js.map +0 -1
  74. package/lib/structures/ISwaggeSchema.js.map +0 -1
  75. package/src/IMigrateConfig.ts +0 -4
  76. /package/lib/structures/{ISwaggeSchema.d.ts → ISwaggerSchema.d.ts} +0 -0
@@ -1,78 +1,78 @@
1
- import { IPointer } from "tstl";
2
- import ts from "typescript";
3
-
4
- import { ISwaggerSchema } from "../structures/ISwaggeSchema";
5
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { MapUtil } from "../utils/MapUtil";
8
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
9
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
10
-
11
- export namespace MigrateDtoProgrammer {
12
- export interface IModule {
13
- name: string;
14
- children: Map<string, IModule>;
15
- programmer:
16
- | null
17
- | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
18
- }
19
-
20
- export const write = (
21
- components: ISwaggerComponents,
22
- ): Map<string, IModule> => {
23
- const dict: Map<string, IModule> = new Map();
24
- for (const [key, value] of Object.entries(components.schemas ?? {}))
25
- prepare(dict)(key)((importer) =>
26
- writeAlias(components)(importer)(key, value),
27
- );
28
- return dict;
29
- };
30
-
31
- const prepare =
32
- (dict: Map<string, IModule>) =>
33
- (name: string) =>
34
- (
35
- programmer: (
36
- importer: MigrateImportProgrammer,
37
- ) => ts.TypeAliasDeclaration,
38
- ) => {
39
- const accessors: string[] = name.split(".");
40
- const modulo: IPointer<IModule> = { value: null! };
41
-
42
- accessors.forEach((acc, i) => {
43
- modulo.value = MapUtil.take(dict)(acc)(() => ({
44
- name: acc,
45
- children: new Map(),
46
- programmer: null,
47
- }));
48
- if (i === accessors.length - 1) modulo.value.programmer = programmer;
49
- dict = modulo.value.children;
50
- });
51
- return modulo!;
52
- };
53
-
54
- const writeAlias =
55
- (components: ISwaggerComponents) =>
56
- (importer: MigrateImportProgrammer) =>
57
- (key: string, value: ISwaggerSchema) =>
58
- FilePrinter.description(
59
- ts.factory.createTypeAliasDeclaration(
60
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
61
- key.split(".").at(-1)!,
62
- [],
63
- MigrateSchemaProgrammer.write(components)(importer)(value),
64
- ),
65
- writeComment(value),
66
- );
67
- }
68
-
69
- const writeComment = (schema: ISwaggerSchema): string =>
70
- [
71
- ...(schema.description?.length ? [schema.description] : []),
72
- ...(schema.description?.length &&
73
- (schema.title !== undefined || schema.deprecated === true)
74
- ? [""]
75
- : []),
76
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
77
- ...(schema.deprecated === true ? [`@deprecated`] : []),
78
- ].join("\n");
1
+ import { IPointer } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ import { ISwaggerSchema } from "../structures/ISwaggerSchema";
5
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { MapUtil } from "../utils/MapUtil";
8
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
9
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
10
+
11
+ export namespace MigrateDtoProgrammer {
12
+ export interface IModule {
13
+ name: string;
14
+ children: Map<string, IModule>;
15
+ programmer:
16
+ | null
17
+ | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
18
+ }
19
+
20
+ export const write = (
21
+ components: ISwaggerComponents,
22
+ ): Map<string, IModule> => {
23
+ const dict: Map<string, IModule> = new Map();
24
+ for (const [key, value] of Object.entries(components.schemas ?? {}))
25
+ prepare(dict)(key)((importer) =>
26
+ writeAlias(components)(importer)(key, value),
27
+ );
28
+ return dict;
29
+ };
30
+
31
+ const prepare =
32
+ (dict: Map<string, IModule>) =>
33
+ (name: string) =>
34
+ (
35
+ programmer: (
36
+ importer: MigrateImportProgrammer,
37
+ ) => ts.TypeAliasDeclaration,
38
+ ) => {
39
+ const accessors: string[] = name.split(".");
40
+ const modulo: IPointer<IModule> = { value: null! };
41
+
42
+ accessors.forEach((acc, i) => {
43
+ modulo.value = MapUtil.take(dict)(acc)(() => ({
44
+ name: acc,
45
+ children: new Map(),
46
+ programmer: null,
47
+ }));
48
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
49
+ dict = modulo.value.children;
50
+ });
51
+ return modulo!;
52
+ };
53
+
54
+ const writeAlias =
55
+ (components: ISwaggerComponents) =>
56
+ (importer: MigrateImportProgrammer) =>
57
+ (key: string, value: ISwaggerSchema) =>
58
+ FilePrinter.description(
59
+ ts.factory.createTypeAliasDeclaration(
60
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
61
+ key.split(".").at(-1)!,
62
+ [],
63
+ MigrateSchemaProgrammer.write(components)(importer)(value),
64
+ ),
65
+ writeComment(value),
66
+ );
67
+ }
68
+
69
+ const writeComment = (schema: ISwaggerSchema): string =>
70
+ [
71
+ ...(schema.description?.length ? [schema.description] : []),
72
+ ...(schema.description?.length &&
73
+ (schema.title !== undefined || schema.deprecated === true)
74
+ ? [""]
75
+ : []),
76
+ ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
77
+ ...(schema.deprecated === true ? [`@deprecated`] : []),
78
+ ].join("\n");
@@ -1,116 +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 MigrateImportProgrammer {
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: MigrateImportProgrammer.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
84
- ? [FilePrinter.newLine()]
85
- : []),
86
- ...[...this.dtos_]
87
- .filter(
88
- current ? (name) => name !== current!.split(".")[0] : () => true,
89
- )
90
- .map((i) =>
91
- ts.factory.createImportDeclaration(
92
- undefined,
93
- ts.factory.createImportClause(
94
- false,
95
- undefined,
96
- ts.factory.createNamedImports([
97
- ts.factory.createImportSpecifier(
98
- false,
99
- undefined,
100
- ts.factory.createIdentifier(i),
101
- ),
102
- ]),
103
- ),
104
- ts.factory.createStringLiteral(dtoPath(i)),
105
- ),
106
- ),
107
- ];
108
- }
109
- }
110
- export namespace MigrateImportProgrammer {
111
- export interface IProps {
112
- type: "default" | "instance";
113
- library: string;
114
- name: string;
115
- }
116
- }
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): ts.TypeReferenceNode {
29
+ const file: string = name.split(".")[0];
30
+ this.dtos_.add(file);
31
+ return ts.factory.createTypeReferenceNode(name);
32
+ }
33
+
34
+ public tag(type: string, arg: number | string): ts.TypeReferenceNode {
35
+ const instance: string = this.external({
36
+ type: "instance",
37
+ library: "typia",
38
+ name: "tags",
39
+ });
40
+ return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
41
+ ts.factory.createLiteralTypeNode(
42
+ typeof arg === "string"
43
+ ? ts.factory.createStringLiteral(arg)
44
+ : ExpressionFactory.number(arg),
45
+ ),
46
+ ]);
47
+ }
48
+
49
+ public toStatements(
50
+ dtoPath: (name: string) => string,
51
+ current?: string,
52
+ ): ts.Statement[] {
53
+ return [
54
+ ...[...this.external_.entries()].map(([library, props]) => {
55
+ return ts.factory.createImportDeclaration(
56
+ undefined,
57
+ ts.factory.createImportClause(
58
+ false,
59
+ props.default !== null
60
+ ? ts.factory.createIdentifier(props.default)
61
+ : undefined,
62
+ props.instances.size
63
+ ? ts.factory.createNamedImports(
64
+ [...props.instances].map((i) =>
65
+ ts.factory.createImportSpecifier(
66
+ false,
67
+ undefined,
68
+ ts.factory.createIdentifier(i),
69
+ ),
70
+ ),
71
+ )
72
+ : undefined,
73
+ ),
74
+ ts.factory.createStringLiteral(library),
75
+ );
76
+ }),
77
+ ...(this.external_.size && this.dtos_.size
78
+ ? [FilePrinter.newLine()]
79
+ : []),
80
+ ...[...this.dtos_]
81
+ .filter(
82
+ current ? (name) => name !== current!.split(".")[0] : () => true,
83
+ )
84
+ .map((i) =>
85
+ ts.factory.createImportDeclaration(
86
+ undefined,
87
+ ts.factory.createImportClause(
88
+ false,
89
+ undefined,
90
+ ts.factory.createNamedImports([
91
+ ts.factory.createImportSpecifier(
92
+ false,
93
+ undefined,
94
+ ts.factory.createIdentifier(i),
95
+ ),
96
+ ]),
97
+ ),
98
+ ts.factory.createStringLiteral(dtoPath(i)),
99
+ ),
100
+ ),
101
+ ];
102
+ }
103
+ }
104
+ export namespace MigrateImportProgrammer {
105
+ export interface IProps {
106
+ type: "default" | "instance";
107
+ library: string;
108
+ name: string;
109
+ }
110
+ }
111
+ interface IClause {
112
+ default: string | null;
113
+ instances: Set<string>;
114
+ }
@@ -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
+ }