nestia 0.3.3 → 0.4.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
CHANGED
|
@@ -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)
|
package/src/bin/nestia.ts
CHANGED
|
File without changes
|
|
@@ -20,7 +20,14 @@ export class Fetcher
|
|
|
20
20
|
public static fetch<Output>(connection: IConnection, config: Fetcher.IConfig, method: "GET" | "DELETE", path: string): Promise<Primitive<Output>>;
|
|
21
21
|
public static fetch<Input, Output>(connection: IConnection, config: Fetcher.IConfig, method: "POST" | "PUT" | "PATCH", path: string, input: Input): Promise<Primitive<Output>>;
|
|
22
22
|
|
|
23
|
-
public static async fetch<Output>
|
|
23
|
+
public static async fetch<Output>
|
|
24
|
+
(
|
|
25
|
+
connection: IConnection,
|
|
26
|
+
config: Fetcher.IConfig,
|
|
27
|
+
method: string,
|
|
28
|
+
path: string,
|
|
29
|
+
input?: object
|
|
30
|
+
): Promise<Primitive<Output>>
|
|
24
31
|
{
|
|
25
32
|
if (config.input_encrypted === true || config.output_encrypted === true)
|
|
26
33
|
if (connection.encryption === undefined)
|
|
@@ -57,12 +64,16 @@ export class Fetcher
|
|
|
57
64
|
//----
|
|
58
65
|
// RESPONSE MESSAGE
|
|
59
66
|
//----
|
|
60
|
-
//
|
|
61
|
-
if (
|
|
62
|
-
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}`);
|
|
63
74
|
|
|
64
75
|
// DO FETCH
|
|
65
|
-
const response: Response = await fetch(
|
|
76
|
+
const response: Response = await fetch(url.href, init);
|
|
66
77
|
let content: string = await response.text();
|
|
67
78
|
|
|
68
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,22 +22,14 @@ 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
35
|
fetchArguments.push("input");
|
|
@@ -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}";\n`
|
|
166
|
+
+ ` export const PATH = "${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
|
}
|