@nestia/migrate 0.7.0-dev.20240201 → 0.7.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.
- package/package.json +68 -68
- package/src/MigrateApplication.ts +35 -35
- package/src/archivers/FileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +2 -7
- package/src/bundles/SDK_TEMPLATE.ts +1 -6
- package/src/executable/bundle.ts +102 -102
- package/src/executable/migrate.ts +7 -7
- package/src/module.ts +4 -4
- package/src/programmers/DtoProgrammer.ts +74 -74
- package/src/programmers/ImportProgrammer.ts +114 -114
- package/src/programmers/NestControllerProgrammer.ts +48 -48
- package/src/programmers/NestProgrammer.ts +74 -74
- package/src/structures/IMigrateProgram.ts +9 -9
- package/src/structures/IMigrateRoute.ts +44 -44
- package/src/utils/JsonTypeChecker.ts +67 -67
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
@@ -1,44 +1,44 @@
|
|
1
|
-
import { ISwaggerSchema } from "./ISwaggeSchema";
|
2
|
-
|
3
|
-
export interface IMigrateRoute {
|
4
|
-
name: string;
|
5
|
-
path: string;
|
6
|
-
method: string;
|
7
|
-
parameters: IMigrateRoute.IParameter[];
|
8
|
-
headers: IMigrateRoute.IHeaders | null;
|
9
|
-
query: IMigrateRoute.IQuery | null;
|
10
|
-
body: IMigrateRoute.IBody | null;
|
11
|
-
success: IMigrateRoute.IBody | null;
|
12
|
-
exceptions: Record<string, IMigrateRoute.IException>;
|
13
|
-
description?: string;
|
14
|
-
tags: string[];
|
15
|
-
deprecated: boolean;
|
16
|
-
}
|
17
|
-
export namespace IMigrateRoute {
|
18
|
-
export interface IParameter {
|
19
|
-
key: string;
|
20
|
-
schema: ISwaggerSchema;
|
21
|
-
description?: string;
|
22
|
-
}
|
23
|
-
export interface IHeaders {
|
24
|
-
key: string;
|
25
|
-
schema: ISwaggerSchema;
|
26
|
-
}
|
27
|
-
export interface IQuery {
|
28
|
-
key: string;
|
29
|
-
schema: ISwaggerSchema;
|
30
|
-
}
|
31
|
-
export interface IBody {
|
32
|
-
key: string;
|
33
|
-
type:
|
34
|
-
| "text/plain"
|
35
|
-
| "application/json"
|
36
|
-
| "application/x-www-form-urlencoded";
|
37
|
-
schema: ISwaggerSchema;
|
38
|
-
"x-nestia-encrypted"?: boolean;
|
39
|
-
}
|
40
|
-
export interface IException {
|
41
|
-
description?: string;
|
42
|
-
schema: ISwaggerSchema;
|
43
|
-
}
|
44
|
-
}
|
1
|
+
import { ISwaggerSchema } from "./ISwaggeSchema";
|
2
|
+
|
3
|
+
export interface IMigrateRoute {
|
4
|
+
name: string;
|
5
|
+
path: string;
|
6
|
+
method: string;
|
7
|
+
parameters: IMigrateRoute.IParameter[];
|
8
|
+
headers: IMigrateRoute.IHeaders | null;
|
9
|
+
query: IMigrateRoute.IQuery | null;
|
10
|
+
body: IMigrateRoute.IBody | null;
|
11
|
+
success: IMigrateRoute.IBody | null;
|
12
|
+
exceptions: Record<string, IMigrateRoute.IException>;
|
13
|
+
description?: string;
|
14
|
+
tags: string[];
|
15
|
+
deprecated: boolean;
|
16
|
+
}
|
17
|
+
export namespace IMigrateRoute {
|
18
|
+
export interface IParameter {
|
19
|
+
key: string;
|
20
|
+
schema: ISwaggerSchema;
|
21
|
+
description?: string;
|
22
|
+
}
|
23
|
+
export interface IHeaders {
|
24
|
+
key: string;
|
25
|
+
schema: ISwaggerSchema;
|
26
|
+
}
|
27
|
+
export interface IQuery {
|
28
|
+
key: string;
|
29
|
+
schema: ISwaggerSchema;
|
30
|
+
}
|
31
|
+
export interface IBody {
|
32
|
+
key: string;
|
33
|
+
type:
|
34
|
+
| "text/plain"
|
35
|
+
| "application/json"
|
36
|
+
| "application/x-www-form-urlencoded";
|
37
|
+
schema: ISwaggerSchema;
|
38
|
+
"x-nestia-encrypted"?: boolean;
|
39
|
+
}
|
40
|
+
export interface IException {
|
41
|
+
description?: string;
|
42
|
+
schema: ISwaggerSchema;
|
43
|
+
}
|
44
|
+
}
|
@@ -1,67 +1,67 @@
|
|
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
|
+
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
|
+
}
|
package/src/utils/SetupWizard.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import cp from "child_process";
|
2
|
-
|
3
|
-
export namespace SetupWizard {
|
4
|
-
export const setup = (output: string) => {
|
5
|
-
execute(output)("npm install");
|
6
|
-
};
|
7
|
-
|
8
|
-
const execute = (cwd: string) => (command: string, fake?: string) => {
|
9
|
-
console.log(fake ?? command);
|
10
|
-
cp.execSync(command, { cwd, stdio: "inherit" });
|
11
|
-
};
|
12
|
-
}
|
1
|
+
import cp from "child_process";
|
2
|
+
|
3
|
+
export namespace SetupWizard {
|
4
|
+
export const setup = (output: string) => {
|
5
|
+
execute(output)("npm install");
|
6
|
+
};
|
7
|
+
|
8
|
+
const execute = (cwd: string) => (command: string, fake?: string) => {
|
9
|
+
console.log(fake ?? command);
|
10
|
+
cp.execSync(command, { cwd, stdio: "inherit" });
|
11
|
+
};
|
12
|
+
}
|
package/src/utils/StringUtil.ts
CHANGED
@@ -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
|
+
}
|