-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.ts
173 lines (159 loc) · 4.1 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// deno-lint-ignore-file no-explicit-any
import { Cookie, ServeInit } from "./deps.ts";
export interface Next {
(error?: unknown): void;
}
export type HttpResponse = {
deleteCookie: (
name: string,
attributes?: {
path?: string | undefined;
domain?: string | undefined;
} | undefined,
) => HttpResponse;
setCookie: (cookie: Cookie) => HttpResponse;
headers: (headers: Headers) => HttpResponse;
authorization: (type: string) => HttpResponse;
contentType: (type: string) => HttpResponse;
status: (status: number) => HttpResponse;
send: (object: unknown) => Response | Promise<Response>;
json: (object: unknown) => Response | Promise<Response>;
ssr: (ssr: SSR) => SSR;
html: (html: string) => Response | Promise<Response>;
jsx: (element: JSX.Element) => Response | Promise<Response>;
};
export class HttpRequest extends Request {
match!: URLPatternResult | null;
}
export type RequestHandler = (
request: HttpRequest,
response: HttpResponse,
next?: Next,
) =>
| void
| Promise<void>
| string
| Promise<string>
| Response
| Promise<Response>
| any
| Promise<any>;
export type MiddlewareArgument = (
request: HttpRequest,
response: HttpResponse,
next: Next,
) =>
| void
| Promise<void>
| string
| Promise<string>
| Response
| Promise<Response>
| any
| Promise<any>;
export type HandlerArgument = Deno.ServeHandler | RequestHandler;
export type Route = {
method: string;
path: string;
handler: HandlerArgument;
};
export type Fastro = {
/**
* Accept incoming connections on the given listener, and handle requests on these connections with the given handler.
*
* HTTP/2 support is only enabled if the provided Deno.Listener returns TLS connections and was configured with "h2" in the ALPN protocols.
*
* Throws a server closed error if called after the server has been closed.
*
* @param options
*/
serve(options?: ServeInit): Promise<void>;
/**
* Immediately close the server listeners and associated HTTP connections.
*
* Throws a server closed error if called after the server has been closed.
*/
close(): void;
/**
* Add url endpoint for static files.
*
* Place your files in the public folder
*
* ```ts
* import application from "./mod.ts";
* const app = application();
* app.static("/public");
* await app.serve();
* ```
*
* Place your files in the static folder
*
* ```ts
* app.static("/static");
* ```
*
* Place your files in the app root folder
*
* ```ts
* app.static("/");
* ```
*
* @param path The base endpoint to access a file
*/
static(path: string): Fastro;
use(...middleware: Array<MiddlewareArgument>): Fastro;
get(path: string, handler: HandlerArgument): Fastro;
post(path: string, handler: HandlerArgument): Fastro;
put(path: string, handler: HandlerArgument): Fastro;
delete(path: string, handler: HandlerArgument): Fastro;
patch(path: string, handler: HandlerArgument): Fastro;
options(path: string, handler: HandlerArgument): Fastro;
flash(isFlash: boolean): Fastro;
build(isBuild: boolean): Fastro;
page(
path: string,
ssr: SSR,
handler: HandlerArgument,
): Fastro;
};
export type SSRHandler = {
path: string;
ssr: SSR;
handler: HandlerArgument;
};
export type StartOptions = {
flash: boolean;
};
export type ExecHandler = (
request?: HttpRequest,
response?: HttpResponse,
next?: Next,
) => any;
export type RenderOptions = {
title: string;
style?: string;
link?: string;
script?: string;
meta?: string;
bundle?: string;
};
export interface SSR {
dir: (dir: string) => SSR;
title: (title: string) => SSR;
meta: (meta: string) => SSR;
script: (script: string) => SSR;
style: (style: string) => SSR;
link: (link: string) => SSR;
lang: (lang: string) => SSR;
cdn: (cdn: string) => SSR;
props: (props: any) => SSR;
render: () => Response;
_createBundle: (
bundle?: string,
rootComponent?: string,
rootTSX?: string,
) => void;
_getBundleName: () => string;
bundle: (name: string) => SSR;
}
export type JSXHandler = (props?: any) => JSX.Element;