-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
46 lines (38 loc) · 949 Bytes
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { SrvResponse } from "../utils/response.ts";
import { Cookies } from "../utils/cookies.ts";
export interface HandlerArgs {
url: URL;
request: Request;
response: SrvResponse;
cookies: Cookies;
params?: Record<string, string>;
error?: Error;
}
export type RouteHandler = (
args: HandlerArgs,
) => unknown | Promise<unknown>;
export type ErrorRouteHandler = (
args: HandlerArgs & { error: Error },
) => unknown | Promise<unknown>;
export type RouteMatcher = (reqPath: string) => {
isMatch: boolean;
params?: Record<string, string>;
};
export interface Route {
handle: RouteHandler;
match: RouteMatcher;
}
export interface ParsedRoute extends Route {
params?: Record<string, string>;
}
export enum HTTPMethod {
GET = "GET",
POST = "POST",
PUT = "PUT",
PATCH = "PATCH",
DELETE = "DELETE",
OPTIONS = "OPTIONS",
HEAD = "HEAD",
ANY = "*",
}
export type Routes = Partial<Record<HTTPMethod, Route[]>>;