@nestia/sdk 2.4.7 → 2.5.0-dev.20240129
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/lib/generates/internal/E2eFileProgrammer.js +44 -46
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkDtoGenerator.js +2 -1
- package/lib/generates/internal/SdkDtoGenerator.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +16 -10
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +6 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +73 -323
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js +175 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
- package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
- package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +7 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +98 -88
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/utils/FormatUtil.d.ts +6 -0
- package/lib/utils/FormatUtil.js +36 -0
- package/lib/utils/FormatUtil.js.map +1 -0
- package/lib/utils/ImportDictionary.d.ts +2 -0
- package/lib/utils/ImportDictionary.js +45 -0
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/package.json +6 -3
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/ControllerAnalyzer.ts +390 -390
- package/src/analyses/PathAnalyzer.ts +110 -110
- package/src/analyses/ReflectAnalyzer.ts +464 -464
- package/src/generates/SwaggerGenerator.ts +376 -376
- package/src/generates/internal/E2eFileProgrammer.ts +148 -73
- package/src/generates/internal/SdkDtoGenerator.ts +6 -1
- package/src/generates/internal/SdkFileProgrammer.ts +40 -13
- package/src/generates/internal/SdkFunctionProgrammer.ts +176 -475
- package/src/generates/internal/SdkNamespaceProgrammer.ts +495 -0
- package/src/generates/internal/SdkRouteProgrammer.ts +82 -0
- package/src/generates/internal/SdkSimulationProgrammer.ts +359 -133
- package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
- package/src/utils/FormatUtil.ts +30 -0
- package/src/utils/ImportDictionary.ts +72 -0
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { RequestMethod } from "@nestjs/common";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { Token, parse } from "path-to-regexp";
|
|
4
|
-
|
|
5
|
-
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
6
|
-
|
|
7
|
-
export namespace PathAnalyzer {
|
|
8
|
-
export const combinate =
|
|
9
|
-
(globalPrefix: INormalizedInput["globalPrefix"]) =>
|
|
10
|
-
(versions: Array<string | null>) =>
|
|
11
|
-
(props: { path: string; method: string }): string[] => {
|
|
12
|
-
const out = (str: string) =>
|
|
13
|
-
versions.map((v) => (v === null ? str : join(v, str)));
|
|
14
|
-
if (!globalPrefix?.prefix.length) return out(props.path);
|
|
15
|
-
else if (!globalPrefix.exclude?.length)
|
|
16
|
-
return out(props.path).map((str) => join(globalPrefix.prefix, str));
|
|
17
|
-
return globalPrefix.exclude.some((exclude) =>
|
|
18
|
-
typeof exclude === "string"
|
|
19
|
-
? RegExp(exclude).test(props.path)
|
|
20
|
-
: METHOD(exclude.method) === props.method &&
|
|
21
|
-
RegExp(exclude.path).test(props.path),
|
|
22
|
-
)
|
|
23
|
-
? out(props.path)
|
|
24
|
-
: out(props.path).map((str) => join(globalPrefix.prefix, str));
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const join = (...args: string[]) =>
|
|
28
|
-
"/" +
|
|
29
|
-
_Trim(
|
|
30
|
-
path
|
|
31
|
-
.join(...args.filter((s) => !!s.length))
|
|
32
|
-
.split("\\")
|
|
33
|
-
.join("/"),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export const escape = (str: string): string | null => {
|
|
37
|
-
const args = _Parse(str);
|
|
38
|
-
if (args === null) return null;
|
|
39
|
-
return (
|
|
40
|
-
"/" +
|
|
41
|
-
args
|
|
42
|
-
.map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
|
|
43
|
-
.join("/")
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const parameters = (str: string): string[] | null => {
|
|
48
|
-
const args = _Parse(str);
|
|
49
|
-
if (args === null) return null;
|
|
50
|
-
return args.filter((arg) => arg.type === "param").map((arg) => arg.value);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
function _Parse(str: string): IArgument[] | null {
|
|
54
|
-
const tokens: Token[] | null = (() => {
|
|
55
|
-
try {
|
|
56
|
-
return parse(path.join(str).split("\\").join("/"));
|
|
57
|
-
} catch {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
})();
|
|
61
|
-
if (tokens === null) return null;
|
|
62
|
-
|
|
63
|
-
const output: IArgument[] = [];
|
|
64
|
-
for (const key of tokens) {
|
|
65
|
-
if (typeof key === "string")
|
|
66
|
-
output.push({
|
|
67
|
-
type: "path",
|
|
68
|
-
value: _Trim(key),
|
|
69
|
-
});
|
|
70
|
-
else if (typeof key.name === "number" || _Trim(key.name) === "")
|
|
71
|
-
return null;
|
|
72
|
-
else
|
|
73
|
-
output.push({
|
|
74
|
-
type: "param",
|
|
75
|
-
value: _Trim(key.name),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return output;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function _Trim(str: string): string {
|
|
82
|
-
if (str[0] === "/") str = str.substring(1);
|
|
83
|
-
if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
|
|
84
|
-
return str;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface IArgument {
|
|
88
|
-
type: "param" | "path";
|
|
89
|
-
value: string;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const METHOD = (value: RequestMethod) =>
|
|
94
|
-
value === RequestMethod.ALL
|
|
95
|
-
? "all"
|
|
96
|
-
: value === RequestMethod.DELETE
|
|
97
|
-
? "delete"
|
|
98
|
-
: value === RequestMethod.GET
|
|
99
|
-
? "get"
|
|
100
|
-
: value === RequestMethod.HEAD
|
|
101
|
-
? "head"
|
|
102
|
-
: value === RequestMethod.OPTIONS
|
|
103
|
-
? "options"
|
|
104
|
-
: value === RequestMethod.PATCH
|
|
105
|
-
? "patch"
|
|
106
|
-
: value === RequestMethod.POST
|
|
107
|
-
? "post"
|
|
108
|
-
: value === RequestMethod.PUT
|
|
109
|
-
? "put"
|
|
110
|
-
: "unknown";
|
|
1
|
+
import { RequestMethod } from "@nestjs/common";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { Token, parse } from "path-to-regexp";
|
|
4
|
+
|
|
5
|
+
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
6
|
+
|
|
7
|
+
export namespace PathAnalyzer {
|
|
8
|
+
export const combinate =
|
|
9
|
+
(globalPrefix: INormalizedInput["globalPrefix"]) =>
|
|
10
|
+
(versions: Array<string | null>) =>
|
|
11
|
+
(props: { path: string; method: string }): string[] => {
|
|
12
|
+
const out = (str: string) =>
|
|
13
|
+
versions.map((v) => (v === null ? str : join(v, str)));
|
|
14
|
+
if (!globalPrefix?.prefix.length) return out(props.path);
|
|
15
|
+
else if (!globalPrefix.exclude?.length)
|
|
16
|
+
return out(props.path).map((str) => join(globalPrefix.prefix, str));
|
|
17
|
+
return globalPrefix.exclude.some((exclude) =>
|
|
18
|
+
typeof exclude === "string"
|
|
19
|
+
? RegExp(exclude).test(props.path)
|
|
20
|
+
: METHOD(exclude.method) === props.method &&
|
|
21
|
+
RegExp(exclude.path).test(props.path),
|
|
22
|
+
)
|
|
23
|
+
? out(props.path)
|
|
24
|
+
: out(props.path).map((str) => join(globalPrefix.prefix, str));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const join = (...args: string[]) =>
|
|
28
|
+
"/" +
|
|
29
|
+
_Trim(
|
|
30
|
+
path
|
|
31
|
+
.join(...args.filter((s) => !!s.length))
|
|
32
|
+
.split("\\")
|
|
33
|
+
.join("/"),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const escape = (str: string): string | null => {
|
|
37
|
+
const args = _Parse(str);
|
|
38
|
+
if (args === null) return null;
|
|
39
|
+
return (
|
|
40
|
+
"/" +
|
|
41
|
+
args
|
|
42
|
+
.map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
|
|
43
|
+
.join("/")
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const parameters = (str: string): string[] | null => {
|
|
48
|
+
const args = _Parse(str);
|
|
49
|
+
if (args === null) return null;
|
|
50
|
+
return args.filter((arg) => arg.type === "param").map((arg) => arg.value);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function _Parse(str: string): IArgument[] | null {
|
|
54
|
+
const tokens: Token[] | null = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return parse(path.join(str).split("\\").join("/"));
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
if (tokens === null) return null;
|
|
62
|
+
|
|
63
|
+
const output: IArgument[] = [];
|
|
64
|
+
for (const key of tokens) {
|
|
65
|
+
if (typeof key === "string")
|
|
66
|
+
output.push({
|
|
67
|
+
type: "path",
|
|
68
|
+
value: _Trim(key),
|
|
69
|
+
});
|
|
70
|
+
else if (typeof key.name === "number" || _Trim(key.name) === "")
|
|
71
|
+
return null;
|
|
72
|
+
else
|
|
73
|
+
output.push({
|
|
74
|
+
type: "param",
|
|
75
|
+
value: _Trim(key.name),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return output;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function _Trim(str: string): string {
|
|
82
|
+
if (str[0] === "/") str = str.substring(1);
|
|
83
|
+
if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
|
|
84
|
+
return str;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface IArgument {
|
|
88
|
+
type: "param" | "path";
|
|
89
|
+
value: string;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const METHOD = (value: RequestMethod) =>
|
|
94
|
+
value === RequestMethod.ALL
|
|
95
|
+
? "all"
|
|
96
|
+
: value === RequestMethod.DELETE
|
|
97
|
+
? "delete"
|
|
98
|
+
: value === RequestMethod.GET
|
|
99
|
+
? "get"
|
|
100
|
+
: value === RequestMethod.HEAD
|
|
101
|
+
? "head"
|
|
102
|
+
: value === RequestMethod.OPTIONS
|
|
103
|
+
? "options"
|
|
104
|
+
: value === RequestMethod.PATCH
|
|
105
|
+
? "patch"
|
|
106
|
+
: value === RequestMethod.POST
|
|
107
|
+
? "post"
|
|
108
|
+
: value === RequestMethod.PUT
|
|
109
|
+
? "put"
|
|
110
|
+
: "unknown";
|