@art-ws/http-server 2.0.11 → 2.0.13
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/dist/es/router.d.ts +9 -6
- package/dist/es/router.js +12 -6
- package/dist/es/types.d.ts +14 -3
- package/dist/es/types.js +10 -1
- package/package.json +1 -1
package/dist/es/router.d.ts
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
import type { HttpContext } from "./types.js";
|
2
2
|
export type RouteHandler<Req = unknown, Res = unknown, Server = unknown, R = unknown> = (context: HttpContext<Req, Res, Server>) => R;
|
3
|
-
export type HttpMethod = "get" | "post" | "delete";
|
4
|
-
export interface RouteDef<Req = unknown, Res = unknown, Server = unknown, R = unknown> {
|
3
|
+
export type HttpMethod = "get" | "post" | "delete" | "put" | "patch" | "options" | "head";
|
4
|
+
export interface RouteDef<Req = unknown, Res = unknown, Server = unknown, R = unknown, O = unknown> {
|
5
5
|
method: HttpMethod;
|
6
6
|
path: string;
|
7
7
|
handler: RouteHandler<Req, Res, Server, R>;
|
8
|
+
options?: O;
|
8
9
|
}
|
9
|
-
export declare class Router<Req = unknown, Res = unknown, Server = unknown, R = unknown> {
|
10
|
+
export declare class Router<Req = unknown, Res = unknown, Server = unknown, R = unknown, O = unknown> {
|
10
11
|
routes: RouteDef<Req, Res, Server, R>[];
|
11
12
|
add(routeDef: RouteDef<Req, Res, Server, R>): void;
|
12
|
-
get(path: string, handler: RouteHandler<Req, Res, Server, R
|
13
|
-
post(path: string, handler: RouteHandler<Req, Res, Server, R
|
14
|
-
|
13
|
+
get(path: string, handler: RouteHandler<Req, Res, Server, R>, options?: O): void;
|
14
|
+
post(path: string, handler: RouteHandler<Req, Res, Server, R>, options?: O): void;
|
15
|
+
put(path: string, handler: RouteHandler<Req, Res, Server, R>, options?: O): void;
|
16
|
+
patch(path: string, handler: RouteHandler<Req, Res, Server, R>, options?: O): void;
|
17
|
+
del(path: string, handler: RouteHandler<Req, Res, Server, R>, options?: O): void;
|
15
18
|
}
|
package/dist/es/router.js
CHANGED
@@ -3,13 +3,19 @@ export class Router {
|
|
3
3
|
add(routeDef) {
|
4
4
|
this.routes.push(routeDef);
|
5
5
|
}
|
6
|
-
get(path, handler) {
|
7
|
-
this.add({ method: "get", path, handler });
|
6
|
+
get(path, handler, options) {
|
7
|
+
this.add({ method: "get", path, handler, options });
|
8
8
|
}
|
9
|
-
post(path, handler) {
|
10
|
-
this.add({ method: "post", path, handler });
|
9
|
+
post(path, handler, options) {
|
10
|
+
this.add({ method: "post", path, handler, options });
|
11
11
|
}
|
12
|
-
|
13
|
-
this.add({ method: "
|
12
|
+
put(path, handler, options) {
|
13
|
+
this.add({ method: "put", path, handler, options });
|
14
|
+
}
|
15
|
+
patch(path, handler, options) {
|
16
|
+
this.add({ method: "patch", path, handler, options });
|
17
|
+
}
|
18
|
+
del(path, handler, options) {
|
19
|
+
this.add({ method: "delete", path, handler, options });
|
14
20
|
}
|
15
21
|
}
|
package/dist/es/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
type Rec = Record<string, unknown>;
|
2
|
+
export interface HttpRequest<T = unknown, Q = Rec, B = Rec, H = Rec> {
|
2
3
|
raw: T;
|
3
4
|
query: Q;
|
4
5
|
body: B;
|
@@ -9,8 +10,8 @@ export interface HttpResponse<T = unknown> {
|
|
9
10
|
json(value: unknown): HttpResponse<T>;
|
10
11
|
code(code: number): HttpResponse<T>;
|
11
12
|
}
|
12
|
-
export interface HttpServer<
|
13
|
-
raw:
|
13
|
+
export interface HttpServer<S = unknown> {
|
14
|
+
raw: S;
|
14
15
|
}
|
15
16
|
export interface HttpContext<Req = unknown, Res = unknown, Server = unknown> {
|
16
17
|
req: HttpRequest<Req>;
|
@@ -18,3 +19,13 @@ export interface HttpContext<Req = unknown, Res = unknown, Server = unknown> {
|
|
18
19
|
server: HttpServer<Server>;
|
19
20
|
promise: Promise<unknown>;
|
20
21
|
}
|
22
|
+
export interface IHttpException {
|
23
|
+
status: number;
|
24
|
+
message: string;
|
25
|
+
}
|
26
|
+
export declare class HttpException extends Error implements IHttpException {
|
27
|
+
status: number;
|
28
|
+
message: string;
|
29
|
+
constructor(status: number, message: string);
|
30
|
+
}
|
31
|
+
export {};
|
package/dist/es/types.js
CHANGED