@nestia/migrate 0.5.0 → 0.6.0

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 (72) hide show
  1. package/lib/NestiaMigrateApplication.js +15 -15
  2. package/lib/NestiaMigrateApplication.js.map +1 -1
  3. package/lib/archivers/FileArchiver.js.map +1 -1
  4. package/lib/bundles/TEMPLATE.js +11 -11
  5. package/lib/bundles/TEMPLATE.js.map +1 -1
  6. package/lib/executable/bundle.js.map +1 -1
  7. package/lib/executable/migrate.js +5 -5
  8. package/lib/executable/migrate.js.map +1 -1
  9. package/lib/programmers/ControllerProgrammer.d.ts +2 -1
  10. package/lib/programmers/ControllerProgrammer.js +21 -18
  11. package/lib/programmers/ControllerProgrammer.js.map +1 -1
  12. package/lib/programmers/DtoProgrammer.d.ts +8 -4
  13. package/lib/programmers/DtoProgrammer.js +36 -77
  14. package/lib/programmers/DtoProgrammer.js.map +1 -1
  15. package/lib/programmers/ImportProgrammer.d.ts +5 -5
  16. package/lib/programmers/ImportProgrammer.js +27 -19
  17. package/lib/programmers/ImportProgrammer.js.map +1 -1
  18. package/lib/programmers/MigrateProgrammer.d.ts +1 -2
  19. package/lib/programmers/MigrateProgrammer.js +52 -36
  20. package/lib/programmers/MigrateProgrammer.js.map +1 -1
  21. package/lib/programmers/ModuleProgrammer.d.ts +5 -0
  22. package/lib/programmers/ModuleProgrammer.js +29 -0
  23. package/lib/programmers/ModuleProgrammer.js.map +1 -0
  24. package/lib/programmers/RouteProgrammer.d.ts +2 -2
  25. package/lib/programmers/RouteProgrammer.js +108 -111
  26. package/lib/programmers/RouteProgrammer.js.map +1 -1
  27. package/lib/programmers/SchemaProgrammer.d.ts +2 -1
  28. package/lib/programmers/SchemaProgrammer.js +122 -189
  29. package/lib/programmers/SchemaProgrammer.js.map +1 -1
  30. package/lib/structures/IMigrateProgram.d.ts +2 -2
  31. package/lib/structures/ISwaggerInfo.d.ts +3 -3
  32. package/lib/utils/FilePrinter.d.ts +9 -0
  33. package/lib/utils/FilePrinter.js +25 -0
  34. package/lib/utils/FilePrinter.js.map +1 -0
  35. package/lib/utils/JsonTypeChecker.d.ts +3 -1
  36. package/lib/utils/JsonTypeChecker.js +31 -18
  37. package/lib/utils/JsonTypeChecker.js.map +1 -1
  38. package/lib/utils/MapUtil.js.map +1 -1
  39. package/lib/utils/SetupWizard.js.map +1 -1
  40. package/lib/utils/StringUtil.js.map +1 -1
  41. package/package.json +11 -9
  42. package/src/NestiaMigrateApplication.ts +68 -73
  43. package/src/archivers/FileArchiver.ts +35 -38
  44. package/src/bundles/TEMPLATE.ts +11 -11
  45. package/src/executable/bundle.ts +72 -78
  46. package/src/executable/migrate.ts +59 -60
  47. package/src/index.ts +4 -4
  48. package/src/module.ts +4 -4
  49. package/src/programmers/ControllerProgrammer.ts +155 -157
  50. package/src/programmers/DtoProgrammer.ts +74 -118
  51. package/src/programmers/ImportProgrammer.ts +98 -60
  52. package/src/programmers/MigrateProgrammer.ts +75 -62
  53. package/src/programmers/ModuleProgrammer.ts +62 -0
  54. package/src/programmers/RouteProgrammer.ts +486 -466
  55. package/src/programmers/SchemaProgrammer.ts +247 -339
  56. package/src/structures/IMigrateController.ts +8 -8
  57. package/src/structures/IMigrateDto.ts +8 -8
  58. package/src/structures/IMigrateFile.ts +5 -5
  59. package/src/structures/IMigrateProgram.ts +7 -7
  60. package/src/structures/IMigrateRoute.ts +36 -36
  61. package/src/structures/IMigrateSchema.ts +4 -4
  62. package/src/structures/ISwaggeSchema.ts +82 -82
  63. package/src/structures/ISwagger.ts +20 -20
  64. package/src/structures/ISwaggerComponents.ts +7 -7
  65. package/src/structures/ISwaggerInfo.ts +57 -57
  66. package/src/structures/ISwaggerRoute.ts +52 -52
  67. package/src/structures/ISwaggerSecurity.ts +47 -47
  68. package/src/utils/FilePrinter.ts +36 -0
  69. package/src/utils/JsonTypeChecker.ts +67 -52
  70. package/src/utils/MapUtil.ts +13 -13
  71. package/src/utils/SetupWizard.ts +15 -15
  72. package/src/utils/StringUtil.ts +51 -51
@@ -0,0 +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 enter = () =>
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,52 +1,67 @@
1
- import { ISwaggerSchema } from "../structures/ISwaggeSchema";
2
-
3
- export namespace JsonTypeChecker {
4
- export const isAnyOf = (
5
- schema: ISwaggerSchema,
6
- ): schema is ISwaggerSchema.IAnyOf => (schema as any).anyOf !== undefined;
7
-
8
- export const isOneOf = (
9
- schema: ISwaggerSchema,
10
- ): schema is ISwaggerSchema.IOneOf => (schema as any).oneOf !== undefined;
11
-
12
- export const isNullOnly = (
13
- schema: ISwaggerSchema,
14
- ): schema is ISwaggerSchema.INullOnly => (schema as any).type === "null";
15
-
16
- export const isBoolean = (
17
- schema: ISwaggerSchema,
18
- ): schema is ISwaggerSchema.IBoolean => (schema as any).type === "boolean";
19
-
20
- export const isInteger = (
21
- schema: ISwaggerSchema,
22
- ): schema is ISwaggerSchema.IInteger => (schema as any).type === "integer";
23
-
24
- export const isNumber = (
25
- schema: ISwaggerSchema,
26
- ): schema is ISwaggerSchema.INumber => (schema as any).type === "number";
27
-
28
- export const isString = (
29
- schema: ISwaggerSchema,
30
- ): schema is ISwaggerSchema.IString => (schema as any).type === "string";
31
-
32
- export const isArray = (
33
- schema: ISwaggerSchema,
34
- ): schema is ISwaggerSchema.IArray => (schema as any).type === "array";
35
-
36
- export const isObject = (
37
- schema: ISwaggerSchema,
38
- ): schema is ISwaggerSchema.IObject => (schema as any).type === "object";
39
-
40
- export const isReference = (
41
- schema: ISwaggerSchema,
42
- ): schema is ISwaggerSchema.IReference =>
43
- (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
- }
1
+ import { ISwaggerSchema } from "../structures/ISwaggeSchema";
2
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
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,13 +1,13 @@
1
- export namespace MapUtil {
2
- export const take =
3
- <Key, T>(dict: Map<Key, T>) =>
4
- (key: Key) =>
5
- (generator: () => T): T => {
6
- const oldbie: T | undefined = dict.get(key);
7
- if (oldbie) return oldbie;
8
-
9
- const value: T = generator();
10
- dict.set(key, value);
11
- return value;
12
- };
13
- }
1
+ export namespace MapUtil {
2
+ export const take =
3
+ <Key, T>(dict: Map<Key, T>) =>
4
+ (key: Key) =>
5
+ (generator: () => T): T => {
6
+ const oldbie: T | undefined = dict.get(key);
7
+ if (oldbie) return oldbie;
8
+
9
+ const value: T = generator();
10
+ dict.set(key, value);
11
+ return value;
12
+ };
13
+ }
@@ -1,15 +1,15 @@
1
- import cp from "child_process";
2
-
3
- export namespace SetupWizard {
4
- export const setup = (output: string) => {
5
- execute(output)("npm install");
6
- execute(output)("npx nestia e2e", "npm run build:sdk");
7
- execute(output)("npm run build:test");
8
- execute(output)("npm run test");
9
- };
10
-
11
- const execute = (cwd: string) => (command: string, fake?: string) => {
12
- console.log(fake ?? command);
13
- cp.execSync(command, { cwd, stdio: "inherit" });
14
- };
15
- }
1
+ import cp from "child_process";
2
+
3
+ export namespace SetupWizard {
4
+ export const setup = (output: string) => {
5
+ execute(output)("npm install");
6
+ execute(output)("npx nestia e2e", "npm run build:sdk");
7
+ execute(output)("npm run build:test");
8
+ execute(output)("npm run test");
9
+ };
10
+
11
+ const execute = (cwd: string) => (command: string, fake?: string) => {
12
+ console.log(fake ?? command);
13
+ cp.execSync(command, { cwd, stdio: "inherit" });
14
+ };
15
+ }
@@ -1,51 +1,51 @@
1
- export namespace StringUtil {
2
- export const capitalize = (str: string) =>
3
- str[0].toUpperCase() + str.slice(1).toLowerCase();
4
-
5
- export const pascal = (path: string) =>
6
- splitWithNormalization(path)
7
- .filter((str) => str[0] !== "{")
8
- .map(capitalize)
9
- .join("");
10
-
11
- export const camel = (path: string) =>
12
- splitWithNormalization(path)
13
- .map((str, i) => (i === 0 ? str : capitalize(str)))
14
- .join("");
15
-
16
- export const splitWithNormalization = (path: string) =>
17
- path
18
- .split("/")
19
- .map((str) => normalize(str.trim()))
20
- .filter((str) => !!str.length);
21
-
22
- export const reJoinWithDecimalParameters = (path: string) =>
23
- path
24
- .split("/")
25
- .filter((str) => !!str.length)
26
- .map((str) =>
27
- str[0] === "{" && str[str.length - 1] === "}"
28
- ? `:${str.substring(1, str.length - 1)}`
29
- : str,
30
- )
31
- .join("/");
32
-
33
- export const normalize = (str: string) =>
34
- str.split(".").join("_").split("-").join("_");
35
-
36
- export const commonPrefix = (strs: string[]): string => {
37
- if (strs.length === 0) return "";
38
-
39
- let prefix = strs[0];
40
- for (let i = 1; i < strs.length; i++) {
41
- while (strs[i].indexOf(prefix) !== 0) {
42
- prefix = prefix.substring(0, prefix.length - 1);
43
- if (prefix === "") return "";
44
- }
45
- }
46
- return prefix
47
- .split("/")
48
- .filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
49
- .join("/");
50
- };
51
- }
1
+ export namespace StringUtil {
2
+ export const capitalize = (str: string) =>
3
+ str[0].toUpperCase() + str.slice(1).toLowerCase();
4
+
5
+ export const pascal = (path: string) =>
6
+ splitWithNormalization(path)
7
+ .filter((str) => str[0] !== "{")
8
+ .map(capitalize)
9
+ .join("");
10
+
11
+ export const camel = (path: string) =>
12
+ splitWithNormalization(path)
13
+ .map((str, i) => (i === 0 ? str : capitalize(str)))
14
+ .join("");
15
+
16
+ export const splitWithNormalization = (path: string) =>
17
+ path
18
+ .split("/")
19
+ .map((str) => normalize(str.trim()))
20
+ .filter((str) => !!str.length);
21
+
22
+ export const reJoinWithDecimalParameters = (path: string) =>
23
+ path
24
+ .split("/")
25
+ .filter((str) => !!str.length)
26
+ .map((str) =>
27
+ str[0] === "{" && str[str.length - 1] === "}"
28
+ ? `:${str.substring(1, str.length - 1)}`
29
+ : str,
30
+ )
31
+ .join("/");
32
+
33
+ export const normalize = (str: string) =>
34
+ str.split(".").join("_").split("-").join("_");
35
+
36
+ export const commonPrefix = (strs: string[]): string => {
37
+ if (strs.length === 0) return "";
38
+
39
+ let prefix = strs[0];
40
+ for (let i = 1; i < strs.length; i++) {
41
+ while (strs[i].indexOf(prefix) !== 0) {
42
+ prefix = prefix.substring(0, prefix.length - 1);
43
+ if (prefix === "") return "";
44
+ }
45
+ }
46
+ return prefix
47
+ .split("/")
48
+ .filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
49
+ .join("/");
50
+ };
51
+ }