@nestia/migrate 0.11.4 → 0.11.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.
Files changed (53) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +29 -4
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/utils/openapi-down-convert/converter.js +2 -2
  6. package/package.json +2 -2
  7. package/src/MigrateApplication.ts +81 -81
  8. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  9. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  10. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
  11. package/src/archivers/MigrateFileArchiver.ts +38 -38
  12. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  13. package/src/bundles/SDK_TEMPLATE.ts +29 -4
  14. package/src/executable/bundle.ts +110 -110
  15. package/src/internal/MigrateCommander.ts +70 -70
  16. package/src/internal/MigrateInquirer.ts +86 -86
  17. package/src/module.ts +14 -14
  18. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  19. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  20. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  21. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  22. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  23. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  24. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  28. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  29. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  30. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  31. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  32. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  33. package/src/structures/IMigrateDto.ts +8 -8
  34. package/src/structures/IMigrateProgram.ts +27 -27
  35. package/src/structures/IMigrateRoute.ts +51 -51
  36. package/src/structures/ISwagger.ts +23 -23
  37. package/src/structures/ISwaggerComponents.ts +14 -14
  38. package/src/structures/ISwaggerRoute.ts +20 -20
  39. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  40. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  41. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  42. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  43. package/src/structures/ISwaggerSchema.ts +90 -90
  44. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  45. package/src/structures/ISwaggerV20.ts +10 -10
  46. package/src/structures/ISwaggerV31.ts +10 -10
  47. package/src/utils/FilePrinter.ts +36 -36
  48. package/src/utils/OpenApiConverter.ts +19 -19
  49. package/src/utils/StringUtil.ts +60 -60
  50. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  51. package/src/utils/SwaggerTypeChecker.ts +67 -67
  52. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  53. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,36 +1,36 @@
1
- import ts from "typescript";
2
-
3
- export namespace FilePrinter {
4
- export const description = <Node extends ts.Node>(
5
- node: Node,
6
- comment: string,
7
- ): Node => {
8
- if (comment.length === 0) return node;
9
- ts.addSyntheticLeadingComment(
10
- node,
11
- ts.SyntaxKind.MultiLineCommentTrivia,
12
- ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
13
- true,
14
- );
15
- return node;
16
- };
17
-
18
- export const newLine = () =>
19
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
20
-
21
- export const write = (props: {
22
- statements: ts.Statement[];
23
- top?: string;
24
- }): string => {
25
- const script: string = ts
26
- .createPrinter()
27
- .printFile(
28
- ts.factory.createSourceFile(
29
- props.statements,
30
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
31
- ts.NodeFlags.None,
32
- ),
33
- );
34
- return (props.top ?? "") + script;
35
- };
36
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace FilePrinter {
4
+ export const description = <Node extends ts.Node>(
5
+ node: Node,
6
+ comment: string,
7
+ ): Node => {
8
+ if (comment.length === 0) return node;
9
+ ts.addSyntheticLeadingComment(
10
+ node,
11
+ ts.SyntaxKind.MultiLineCommentTrivia,
12
+ ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
13
+ true,
14
+ );
15
+ return node;
16
+ };
17
+
18
+ export const newLine = () =>
19
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
20
+
21
+ export const write = (props: {
22
+ statements: ts.Statement[];
23
+ top?: string;
24
+ }): string => {
25
+ const script: string = ts
26
+ .createPrinter()
27
+ .printFile(
28
+ ts.factory.createSourceFile(
29
+ props.statements,
30
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
31
+ ts.NodeFlags.None,
32
+ ),
33
+ );
34
+ return (props.top ?? "") + script;
35
+ };
36
+ }
@@ -1,19 +1,19 @@
1
- // import V2_0Converter from "swagger2openapi";
2
- import typia from "typia";
3
-
4
- import { ISwagger } from "../structures/ISwagger";
5
- // import { ISwaggerV20 } from "../structures/ISwaggerV20";
6
- import { ISwaggerV31 } from "../structures/ISwaggerV31";
7
- import { Converter as V3_1Converter } from "./openapi-down-convert/converter";
8
-
9
- export namespace OpenApiConverter {
10
- // export const v2_0 = async (swagger: ISwaggerV20): Promise<ISwagger> => {
11
- // const output = await V2_0Converter.convertObj(swagger, {});
12
- // return typia.assert<ISwagger>(output.openapi);
13
- // };
14
-
15
- export const v3_1 = (swagger: ISwaggerV31): ISwagger => {
16
- const converter = new V3_1Converter(swagger);
17
- return typia.assert<ISwagger>(converter.convert() as ISwagger);
18
- };
19
- }
1
+ // import V2_0Converter from "swagger2openapi";
2
+ import typia from "typia";
3
+
4
+ import { ISwagger } from "../structures/ISwagger";
5
+ // import { ISwaggerV20 } from "../structures/ISwaggerV20";
6
+ import { ISwaggerV31 } from "../structures/ISwaggerV31";
7
+ import { Converter as V3_1Converter } from "./openapi-down-convert/converter";
8
+
9
+ export namespace OpenApiConverter {
10
+ // export const v2_0 = async (swagger: ISwaggerV20): Promise<ISwagger> => {
11
+ // const output = await V2_0Converter.convertObj(swagger, {});
12
+ // return typia.assert<ISwagger>(output.openapi);
13
+ // };
14
+
15
+ export const v3_1 = (swagger: ISwaggerV31): ISwagger => {
16
+ const converter = new V3_1Converter(swagger);
17
+ return typia.assert<ISwagger>(converter.convert() as ISwagger);
18
+ };
19
+ }
@@ -1,60 +1,60 @@
1
- import { NamingConvention } from "typia/lib/utils/NamingConvention";
2
-
3
- export namespace StringUtil {
4
- export const capitalize = (str: string) =>
5
- str[0].toUpperCase() + str.slice(1).toLowerCase();
6
-
7
- export const pascal = (path: string) =>
8
- splitWithNormalization(path)
9
- .filter((str) => str[0] !== "{")
10
- .map(NamingConvention.pascal)
11
- .join("");
12
-
13
- export const camel = (path: string) =>
14
- splitWithNormalization(path)
15
- .map((str, i) =>
16
- i === 0 ? NamingConvention.camel(str) : NamingConvention.pascal(str),
17
- )
18
- .join("");
19
-
20
- export const splitWithNormalization = (path: string) =>
21
- path
22
- .split("/")
23
- .map((str) => normalize(str.trim()))
24
- .filter((str) => !!str.length);
25
-
26
- export const reJoinWithDecimalParameters = (path: string) =>
27
- path
28
- .split("/")
29
- .filter((str) => !!str.length)
30
- .map((str) =>
31
- str[0] === "{" && str[str.length - 1] === "}"
32
- ? `:${str.substring(1, str.length - 1)}`
33
- : str,
34
- )
35
- .join("/");
36
-
37
- export const normalize = (str: string) =>
38
- str.split(".").join("_").split("-").join("_");
39
-
40
- export const commonPrefix = (strs: string[]): string => {
41
- if (strs.length === 0) return "";
42
-
43
- let prefix = strs[0];
44
- for (let i = 1; i < strs.length; i++) {
45
- while (strs[i].indexOf(prefix) !== 0) {
46
- prefix = prefix.substring(0, prefix.length - 1);
47
- if (prefix === "") return "";
48
- }
49
- }
50
- return prefix
51
- .split("/")
52
- .filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
53
- .join("/");
54
- };
55
-
56
- export const escapeDuplicate =
57
- (keep: string[]) =>
58
- (change: string): string =>
59
- keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;
60
- }
1
+ import { NamingConvention } from "typia/lib/utils/NamingConvention";
2
+
3
+ export namespace StringUtil {
4
+ export const capitalize = (str: string) =>
5
+ str[0].toUpperCase() + str.slice(1).toLowerCase();
6
+
7
+ export const pascal = (path: string) =>
8
+ splitWithNormalization(path)
9
+ .filter((str) => str[0] !== "{")
10
+ .map(NamingConvention.pascal)
11
+ .join("");
12
+
13
+ export const camel = (path: string) =>
14
+ splitWithNormalization(path)
15
+ .map((str, i) =>
16
+ i === 0 ? NamingConvention.camel(str) : NamingConvention.pascal(str),
17
+ )
18
+ .join("");
19
+
20
+ export const splitWithNormalization = (path: string) =>
21
+ path
22
+ .split("/")
23
+ .map((str) => normalize(str.trim()))
24
+ .filter((str) => !!str.length);
25
+
26
+ export const reJoinWithDecimalParameters = (path: string) =>
27
+ path
28
+ .split("/")
29
+ .filter((str) => !!str.length)
30
+ .map((str) =>
31
+ str[0] === "{" && str[str.length - 1] === "}"
32
+ ? `:${str.substring(1, str.length - 1)}`
33
+ : str,
34
+ )
35
+ .join("/");
36
+
37
+ export const normalize = (str: string) =>
38
+ str.split(".").join("_").split("-").join("_");
39
+
40
+ export const commonPrefix = (strs: string[]): string => {
41
+ if (strs.length === 0) return "";
42
+
43
+ let prefix = strs[0];
44
+ for (let i = 1; i < strs.length; i++) {
45
+ while (strs[i].indexOf(prefix) !== 0) {
46
+ prefix = prefix.substring(0, prefix.length - 1);
47
+ if (prefix === "") return "";
48
+ }
49
+ }
50
+ return prefix
51
+ .split("/")
52
+ .filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
53
+ .join("/");
54
+ };
55
+
56
+ export const escapeDuplicate =
57
+ (keep: string[]) =>
58
+ (change: string): string =>
59
+ keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;
60
+ }
@@ -1,43 +1,43 @@
1
- import { ISwaggerComponents } from "../module";
2
- import { ISwaggerRouteParameter } from "../structures/ISwaggerRouteParameter";
3
- import { ISwaggerRouteRequestBody } from "../structures/ISwaggerRouteRequestBody";
4
- import { ISwaggerRouteResponse } from "../structures/ISwaggerRouteResponse";
5
- import { SwaggerTypeChecker } from "./SwaggerTypeChecker";
6
-
7
- export namespace SwaggerComponentsExplorer {
8
- export const getParameter =
9
- (components: ISwaggerComponents) =>
10
- (
11
- schema: ISwaggerRouteParameter | ISwaggerRouteParameter.IReference,
12
- ): ISwaggerRouteParameter | null =>
13
- SwaggerTypeChecker.isReference(schema) &&
14
- schema.$ref.startsWith("#/components/parameters/")
15
- ? components.parameters?.[
16
- schema.$ref.replace("#/components/parameters/", "")
17
- ] ?? null
18
- : (schema as ISwaggerRouteParameter);
19
-
20
- export const getRequestBody =
21
- (components: ISwaggerComponents) =>
22
- (
23
- schema: ISwaggerRouteRequestBody | ISwaggerRouteRequestBody.IReference,
24
- ): ISwaggerRouteRequestBody | null =>
25
- SwaggerTypeChecker.isReference(schema) &&
26
- schema.$ref.startsWith("#/components/requestBodies/")
27
- ? components.requestBodies?.[
28
- schema.$ref.replace("#/components/requestBodies/", "")
29
- ] ?? null
30
- : (schema as ISwaggerRouteRequestBody);
31
-
32
- export const getResponse =
33
- (components: ISwaggerComponents) =>
34
- (
35
- schema: ISwaggerRouteResponse | ISwaggerRouteResponse.IReference,
36
- ): ISwaggerRouteResponse | null =>
37
- SwaggerTypeChecker.isReference(schema) &&
38
- schema.$ref.startsWith("#/components/responses/")
39
- ? components.responses?.[
40
- schema.$ref.replace("#/components/responses/", "")
41
- ] ?? null
42
- : (schema as ISwaggerRouteResponse);
43
- }
1
+ import { ISwaggerComponents } from "../module";
2
+ import { ISwaggerRouteParameter } from "../structures/ISwaggerRouteParameter";
3
+ import { ISwaggerRouteRequestBody } from "../structures/ISwaggerRouteRequestBody";
4
+ import { ISwaggerRouteResponse } from "../structures/ISwaggerRouteResponse";
5
+ import { SwaggerTypeChecker } from "./SwaggerTypeChecker";
6
+
7
+ export namespace SwaggerComponentsExplorer {
8
+ export const getParameter =
9
+ (components: ISwaggerComponents) =>
10
+ (
11
+ schema: ISwaggerRouteParameter | ISwaggerRouteParameter.IReference,
12
+ ): ISwaggerRouteParameter | null =>
13
+ SwaggerTypeChecker.isReference(schema) &&
14
+ schema.$ref.startsWith("#/components/parameters/")
15
+ ? components.parameters?.[
16
+ schema.$ref.replace("#/components/parameters/", "")
17
+ ] ?? null
18
+ : (schema as ISwaggerRouteParameter);
19
+
20
+ export const getRequestBody =
21
+ (components: ISwaggerComponents) =>
22
+ (
23
+ schema: ISwaggerRouteRequestBody | ISwaggerRouteRequestBody.IReference,
24
+ ): ISwaggerRouteRequestBody | null =>
25
+ SwaggerTypeChecker.isReference(schema) &&
26
+ schema.$ref.startsWith("#/components/requestBodies/")
27
+ ? components.requestBodies?.[
28
+ schema.$ref.replace("#/components/requestBodies/", "")
29
+ ] ?? null
30
+ : (schema as ISwaggerRouteRequestBody);
31
+
32
+ export const getResponse =
33
+ (components: ISwaggerComponents) =>
34
+ (
35
+ schema: ISwaggerRouteResponse | ISwaggerRouteResponse.IReference,
36
+ ): ISwaggerRouteResponse | null =>
37
+ SwaggerTypeChecker.isReference(schema) &&
38
+ schema.$ref.startsWith("#/components/responses/")
39
+ ? components.responses?.[
40
+ schema.$ref.replace("#/components/responses/", "")
41
+ ] ?? null
42
+ : (schema as ISwaggerRouteResponse);
43
+ }
@@ -1,67 +1,67 @@
1
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
2
- import { ISwaggerSchema } from "../structures/ISwaggerSchema";
3
-
4
- export namespace SwaggerTypeChecker {
5
- export const isAnyOf = (
6
- schema: ISwaggerSchema,
7
- ): schema is ISwaggerSchema.IAnyOf => (schema as any).anyOf !== undefined;
8
-
9
- export const isOneOf = (
10
- schema: ISwaggerSchema,
11
- ): schema is ISwaggerSchema.IOneOf => (schema as any).oneOf !== undefined;
12
-
13
- export const isNullOnly = (
14
- schema: ISwaggerSchema,
15
- ): schema is ISwaggerSchema.INullOnly => (schema as any).type === "null";
16
-
17
- export const isBoolean = (
18
- schema: ISwaggerSchema,
19
- ): schema is ISwaggerSchema.IBoolean => (schema as any).type === "boolean";
20
-
21
- export const isInteger = (
22
- schema: ISwaggerSchema,
23
- ): schema is ISwaggerSchema.IInteger => (schema as any).type === "integer";
24
-
25
- export const isNumber = (
26
- schema: ISwaggerSchema,
27
- ): schema is ISwaggerSchema.INumber => (schema as any).type === "number";
28
-
29
- export const isString = (
30
- schema: ISwaggerSchema,
31
- ): schema is ISwaggerSchema.IString => (schema as any).type === "string";
32
-
33
- export const isArray = (
34
- schema: ISwaggerSchema,
35
- ): schema is ISwaggerSchema.IArray => (schema as any).type === "array";
36
-
37
- export const isObject = (
38
- schema: ISwaggerSchema,
39
- ): schema is ISwaggerSchema.IObject => (schema as any).type === "object";
40
-
41
- export const isReference = (
42
- schema: ISwaggerSchema,
43
- ): schema is ISwaggerSchema.IReference => (schema as any).$ref !== undefined;
44
-
45
- export const isUnknown = (
46
- schema: ISwaggerSchema,
47
- ): schema is ISwaggerSchema.IUnknown =>
48
- (schema as any).type === undefined &&
49
- !isAnyOf(schema) &&
50
- !isOneOf(schema) &&
51
- !isReference(schema);
52
-
53
- export const isNullable =
54
- (components: ISwaggerComponents) =>
55
- (schema: ISwaggerSchema): boolean => {
56
- if (SwaggerTypeChecker.isAnyOf(schema))
57
- return schema.anyOf.some(isNullable(components));
58
- else if (SwaggerTypeChecker.isOneOf(schema))
59
- return schema.oneOf.some(isNullable(components));
60
- else if (SwaggerTypeChecker.isReference(schema)) {
61
- const $id = schema.$ref.replace("#/components/schemas/", "");
62
- const target = (components.schemas ?? {})[$id];
63
- return target === undefined ? false : isNullable(components)(target);
64
- }
65
- return (schema as ISwaggerSchema.IString).nullable === true;
66
- };
67
- }
1
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
2
+ import { ISwaggerSchema } from "../structures/ISwaggerSchema";
3
+
4
+ export namespace SwaggerTypeChecker {
5
+ export const isAnyOf = (
6
+ schema: ISwaggerSchema,
7
+ ): schema is ISwaggerSchema.IAnyOf => (schema as any).anyOf !== undefined;
8
+
9
+ export const isOneOf = (
10
+ schema: ISwaggerSchema,
11
+ ): schema is ISwaggerSchema.IOneOf => (schema as any).oneOf !== undefined;
12
+
13
+ export const isNullOnly = (
14
+ schema: ISwaggerSchema,
15
+ ): schema is ISwaggerSchema.INullOnly => (schema as any).type === "null";
16
+
17
+ export const isBoolean = (
18
+ schema: ISwaggerSchema,
19
+ ): schema is ISwaggerSchema.IBoolean => (schema as any).type === "boolean";
20
+
21
+ export const isInteger = (
22
+ schema: ISwaggerSchema,
23
+ ): schema is ISwaggerSchema.IInteger => (schema as any).type === "integer";
24
+
25
+ export const isNumber = (
26
+ schema: ISwaggerSchema,
27
+ ): schema is ISwaggerSchema.INumber => (schema as any).type === "number";
28
+
29
+ export const isString = (
30
+ schema: ISwaggerSchema,
31
+ ): schema is ISwaggerSchema.IString => (schema as any).type === "string";
32
+
33
+ export const isArray = (
34
+ schema: ISwaggerSchema,
35
+ ): schema is ISwaggerSchema.IArray => (schema as any).type === "array";
36
+
37
+ export const isObject = (
38
+ schema: ISwaggerSchema,
39
+ ): schema is ISwaggerSchema.IObject => (schema as any).type === "object";
40
+
41
+ export const isReference = (
42
+ schema: ISwaggerSchema,
43
+ ): schema is ISwaggerSchema.IReference => (schema as any).$ref !== undefined;
44
+
45
+ export const isUnknown = (
46
+ schema: ISwaggerSchema,
47
+ ): schema is ISwaggerSchema.IUnknown =>
48
+ (schema as any).type === undefined &&
49
+ !isAnyOf(schema) &&
50
+ !isOneOf(schema) &&
51
+ !isReference(schema);
52
+
53
+ export const isNullable =
54
+ (components: ISwaggerComponents) =>
55
+ (schema: ISwaggerSchema): boolean => {
56
+ if (SwaggerTypeChecker.isAnyOf(schema))
57
+ return schema.anyOf.some(isNullable(components));
58
+ else if (SwaggerTypeChecker.isOneOf(schema))
59
+ return schema.oneOf.some(isNullable(components));
60
+ else if (SwaggerTypeChecker.isReference(schema)) {
61
+ const $id = schema.$ref.replace("#/components/schemas/", "");
62
+ const target = (components.schemas ?? {})[$id];
63
+ return target === undefined ? false : isNullable(components)(target);
64
+ }
65
+ return (schema as ISwaggerSchema.IString).nullable === true;
66
+ };
67
+ }