nestia 0.3.4 → 0.4.1
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 +2 -2
- package/src/analyses/ControllerAnalyzer.ts +2 -0
- package/src/analyses/ReflectAnalyzer.ts +10 -4
- package/src/bundle/IConnection.ts +1 -1
- package/src/bundle/__internal/Fetcher.ts +9 -4
- package/src/generates/FunctionGenerator.ts +38 -28
- package/src/structures/IController.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Automatic SDK and Document generator for the NestJS",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"bin": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typescript": "^4.3.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"encrypted-nestjs": "^0.1.
|
|
43
|
+
"encrypted-nestjs": "^0.1.15",
|
|
44
44
|
"rimraf": "^3.0.2"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -104,6 +104,8 @@ export namespace ControllerAnalyzer
|
|
|
104
104
|
let path: string = NodePath.join(controller.path, func.path).split("\\").join("/");
|
|
105
105
|
if (path[0] !== "/")
|
|
106
106
|
path = "/" + path;
|
|
107
|
+
if (path[path.length - 1] === "/" && path !== "/")
|
|
108
|
+
path = path.substr(0, path.length - 1);
|
|
107
109
|
|
|
108
110
|
// RETURNS
|
|
109
111
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Pather from "path";
|
|
2
2
|
|
|
3
3
|
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
4
4
|
import { StringUtil } from "../utils/StringUtil";
|
|
@@ -128,7 +128,7 @@ export namespace ReflectAnalyzer
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// VALIDATE PATH ARGUMENTS
|
|
131
|
-
const funcPathArguments: string[] = StringUtil.betweens(
|
|
131
|
+
const funcPathArguments: string[] = StringUtil.betweens(Pather.join(controller.path, meta.path).split("\\").join("/"), ":", "/").sort();
|
|
132
132
|
const paramPathArguments: string[] = meta.parameters.filter(param => param.category === "param").map(param => param.field!).sort();
|
|
133
133
|
|
|
134
134
|
if (equal(funcPathArguments, paramPathArguments) === false)
|
|
@@ -158,6 +158,7 @@ export namespace ReflectAnalyzer
|
|
|
158
158
|
return null;
|
|
159
159
|
|
|
160
160
|
return {
|
|
161
|
+
name: key,
|
|
161
162
|
category: type,
|
|
162
163
|
index: param.index,
|
|
163
164
|
field: param.data,
|
|
@@ -169,15 +170,19 @@ export namespace ReflectAnalyzer
|
|
|
169
170
|
{
|
|
170
171
|
if (param.factory === undefined)
|
|
171
172
|
return null;
|
|
172
|
-
else if (param.factory.name === "EncryptedBody")
|
|
173
|
+
else if (param.factory.name === "EncryptedBody" || param.factory.name === "PlainBody")
|
|
174
|
+
{
|
|
173
175
|
return {
|
|
174
176
|
category: "body",
|
|
175
177
|
index: param.index,
|
|
178
|
+
name: param.name,
|
|
176
179
|
field: param.data,
|
|
177
|
-
encrypted:
|
|
180
|
+
encrypted: param.factory.name === "EncryptedBody"
|
|
178
181
|
};
|
|
182
|
+
}
|
|
179
183
|
else if (param.factory.name === "TypedParam")
|
|
180
184
|
return {
|
|
185
|
+
name: param.name,
|
|
181
186
|
category: "param",
|
|
182
187
|
index: param.index,
|
|
183
188
|
field: param.data,
|
|
@@ -193,6 +198,7 @@ export namespace ReflectAnalyzer
|
|
|
193
198
|
|
|
194
199
|
interface INestParam
|
|
195
200
|
{
|
|
201
|
+
name: string;
|
|
196
202
|
index: number;
|
|
197
203
|
factory?: Function;
|
|
198
204
|
data: string | undefined;
|
|
@@ -64,11 +64,16 @@ export class Fetcher
|
|
|
64
64
|
//----
|
|
65
65
|
// RESPONSE MESSAGE
|
|
66
66
|
//----
|
|
67
|
-
//
|
|
68
|
-
if (connection.
|
|
69
|
-
path =
|
|
67
|
+
// URL SPECIFICATION
|
|
68
|
+
if (connection.host[connection.host.length - 1] !== "/" && path[0] !== "/")
|
|
69
|
+
path = "/" + path;
|
|
70
|
+
if (connection.path)
|
|
71
|
+
path = connection.path(path);
|
|
72
|
+
|
|
73
|
+
const url: URL = new URL(`${connection.host}${path}`);
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
// DO FETCH
|
|
76
|
+
const response: Response = await fetch(url.href, init);
|
|
72
77
|
let content: string = await response.text();
|
|
73
78
|
|
|
74
79
|
if (!content)
|
|
@@ -2,7 +2,6 @@ import type * as tsc from "typescript";
|
|
|
2
2
|
import { Pair } from "tstl/utility/Pair";
|
|
3
3
|
import { Vector } from "tstl/container/Vector";
|
|
4
4
|
|
|
5
|
-
import { Fetcher } from "../bundle/__internal/Fetcher";
|
|
6
5
|
import { IRoute } from "../structures/IRoute";
|
|
7
6
|
|
|
8
7
|
export namespace FunctionGenerator
|
|
@@ -23,25 +22,17 @@ export namespace FunctionGenerator
|
|
|
23
22
|
--------------------------------------------------------- */
|
|
24
23
|
function body(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string
|
|
25
24
|
{
|
|
26
|
-
// PATH WITH ENCRYPTION
|
|
27
|
-
const path: string = get_path(route, query);
|
|
28
|
-
const config: Fetcher.IConfig = {
|
|
29
|
-
input_encrypted: input !== undefined && input.encrypted,
|
|
30
|
-
output_encrypted: route.encrypted
|
|
31
|
-
};
|
|
32
|
-
|
|
33
25
|
// FETCH ARGUMENTS WITH REQUST BODY
|
|
26
|
+
const parameters = filter_parameters(route, query);
|
|
34
27
|
const fetchArguments: string[] =
|
|
35
28
|
[
|
|
36
29
|
"connection",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`"${route.method}"`,
|
|
41
|
-
path
|
|
30
|
+
`${route.name}.CONFIG`,
|
|
31
|
+
`${route.name}.METHOD`,
|
|
32
|
+
`${route.name}.path(${parameters.map(p => p.name).join(", ")})`
|
|
42
33
|
];
|
|
43
34
|
if (input !== undefined)
|
|
44
|
-
fetchArguments.push(
|
|
35
|
+
fetchArguments.push(input.name);
|
|
45
36
|
|
|
46
37
|
// RETURNS WITH FINALIZATION
|
|
47
38
|
return "{\n"
|
|
@@ -52,18 +43,12 @@ export namespace FunctionGenerator
|
|
|
52
43
|
+ "}";
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
function
|
|
46
|
+
function filter_parameters(route: IRoute, query: IRoute.IParameter | undefined): IRoute.IParameter[]
|
|
56
47
|
{
|
|
57
48
|
const parameters = route.parameters.filter(param => param.category === "param");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
path = path.replace(`:${param.field}`, `\${${param.name}}`);
|
|
62
|
-
|
|
63
|
-
new URLSearchParams()
|
|
64
|
-
return (query !== undefined)
|
|
65
|
-
? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
|
|
66
|
-
: `\`${path}\``
|
|
49
|
+
if (query)
|
|
50
|
+
parameters.push(query);
|
|
51
|
+
return parameters;
|
|
67
52
|
}
|
|
68
53
|
|
|
69
54
|
/* ---------------------------------------------------------
|
|
@@ -149,6 +134,7 @@ export namespace FunctionGenerator
|
|
|
149
134
|
|
|
150
135
|
function tail(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string | null
|
|
151
136
|
{
|
|
137
|
+
// LIST UP TYPES
|
|
152
138
|
const types: Pair<string, string>[] = [];
|
|
153
139
|
if (query !== undefined)
|
|
154
140
|
types.push(new Pair("Query", query.type));
|
|
@@ -157,12 +143,36 @@ export namespace FunctionGenerator
|
|
|
157
143
|
if (route.output !== "void")
|
|
158
144
|
types.push(new Pair("Output", route.output));
|
|
159
145
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
146
|
+
// PATH WITH PARAMETERS
|
|
147
|
+
const parameters = filter_parameters(route, query);
|
|
148
|
+
let path: string = route.path;
|
|
149
|
+
for (const param of parameters)
|
|
150
|
+
if (param.category === "param")
|
|
151
|
+
path = path.replace(`:${param.field}`, `\${${param.name}}`);
|
|
152
|
+
path = (query !== undefined)
|
|
153
|
+
? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
|
|
154
|
+
: `\`${path}\``;
|
|
155
|
+
|
|
163
156
|
return `export namespace ${route.name}\n`
|
|
164
157
|
+ "{\n"
|
|
165
|
-
+
|
|
158
|
+
+
|
|
159
|
+
(
|
|
160
|
+
types.length !== 0
|
|
161
|
+
? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`).join("\n") + "\n\n"
|
|
162
|
+
: ""
|
|
163
|
+
)
|
|
164
|
+
+ "\n"
|
|
165
|
+
+ ` export const METHOD = "${route.method}" as const;\n`
|
|
166
|
+
+ ` export const PATH: string = "${route.path}";\n`
|
|
167
|
+
+ ` export const CONFIG = {\n`
|
|
168
|
+
+ ` input_encrypted: ${input !== undefined && input.encrypted},\n`
|
|
169
|
+
+ ` output_encrypted: ${route.encrypted},\n`
|
|
170
|
+
+ ` };\n`
|
|
171
|
+
+ "\n"
|
|
172
|
+
+ ` export function path(${parameters.map(param => `${param.name}: ${param.type}`).join(", ")}): string\n`
|
|
173
|
+
+ ` {\n`
|
|
174
|
+
+ ` return ${path};\n`
|
|
175
|
+
+ ` }\n`
|
|
166
176
|
+ "}";
|
|
167
177
|
}
|
|
168
178
|
}
|