-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.ts
108 lines (98 loc) · 2.98 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// deno-lint-ignore-file no-explicit-any
import { ConnInfo, Cookie, Handler } from "./deps.ts";
export type SSRHandler = {
path: PathArgument;
ssr: SSR;
handler: Handler;
};
export interface SSR {
dir: (dir: string) => SSR;
component: (el: JSX.Element) => SSR;
title: (title: string) => SSR;
meta: (meta: string) => SSR;
script: (script: string) => SSR;
style: (style: string) => SSR;
link: (link: string) => SSR;
render: () => Response;
/** Used by internal system to hydrate and create bundle on application initiation */
_createBundle: (bundle?: string) => void;
/** Used by internal system to set request on response init to get the url. This url is used to get the hydrated and bundled JS file. */
_setRequest: (req: Request) => void;
}
export type RenderOptions = {
title: string;
style?: string;
link?: string;
script?: string;
meta?: string;
bundle?: string;
};
export interface RequestResponse {
deleteCookie: (
name: string,
attributes?: {
path?: string | undefined;
domain?: string | undefined;
} | undefined,
) => RequestResponse;
setCookie: (cookie: Cookie) => RequestResponse;
headers: (headers: Headers) => RequestResponse;
authorization: (type: string) => RequestResponse;
contentType: (type: string) => RequestResponse;
status: (status: number) => RequestResponse;
send: (object: unknown) => Response | Promise<Response>;
json: (object: unknown) => Response | Promise<Response>;
ssr: (ssr: SSR) => SSR;
html: (html: string) => Response | Promise<Response>;
}
export type StringHandler = (request?: Request, connInfo?: ConnInfo) => string;
export interface Router {
routes: Map<string, Route>;
get(path: PathArgument, ...handlers: HandlerArgument[]): Router;
post(path: PathArgument, ...handlers: HandlerArgument[]): Router;
put(path: PathArgument, ...handlers: HandlerArgument[]): Router;
delete(path: PathArgument, ...handlers: HandlerArgument[]): Router;
patch(path: PathArgument, ...handlers: HandlerArgument[]): Router;
head(path: PathArgument, ...handlers: HandlerArgument[]): Router;
options(path: PathArgument, ...handlers: HandlerArgument[]): Router;
}
export type PathArgument = string | RegExp;
export interface Next {
(error?: unknown): void;
}
export type RequestHandler = (
request: Request,
connInfo: ConnInfo,
next: Next,
) =>
| void
| Promise<void>
| string
| Promise<string>
| Response
| Promise<Response>
| JSX.Element
| any
| Promise<any>;
export type HandlerArgument = Handler | RequestHandler | RequestHandler[];
export type Route = {
method: string;
path: PathArgument;
handlers: HandlerArgument[];
};
export interface Dependency {
deps: Map<string, unknown>;
set(key: string, val: unknown): Dependency;
get(key: string): unknown;
}
export type MiddlewareArgument =
| Dependency
| PathArgument
| Router
| RequestHandler
| RequestHandler[];
export interface AppMiddleware {
type: string;
path: PathArgument;
middlewares: MiddlewareArgument[];
}