-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
response.ts
56 lines (54 loc) · 1.95 KB
/
response.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
import { App } from './app.ts'
import { SetCookieOptions } from './extensions/res/cookie.ts'
import { DownloadOptions } from './extensions/res/download.ts'
import { FormatProps } from './extensions/res/format.ts'
import type { SendFileOptions } from './extensions/res/send/sendFile.ts'
import { TemplateEngineOptions } from './utils/template.ts'
export interface DummyResponse {
_body?: BodyInit
_init: ResponseInit & { headers: Headers }
locals: Record<string, any>
}
export interface THResponse<O = any, B = unknown> extends DummyResponse {
send(body: B): Promise<THResponse<O, B>>
sendFile(path: string, opts?: SendFileOptions): Promise<THResponse<O, B>>
end(body?: BodyInit): THResponse<O, B>
links(links: { [key: string]: string }): THResponse<O, B>
render(
file: string,
data?: Record<string, any>,
options?: TemplateEngineOptions<O>,
): THResponse<O, B>
vary(field: string): THResponse<O, B>
format(obj: FormatProps): THResponse<O, B>
redirect(url: string, status?: number): THResponse<O, B>
type(type: string): THResponse<O, B>
download(
path: string,
filename: string,
options?: DownloadOptions,
cb?: (err?: unknown) => void,
): THResponse<O, B>
attachment(filename?: string): THResponse<O, B>
json(body: B): THResponse<O, B>
status(status: number): THResponse<O, B>
sendStatus(statusCode: number): THResponse<O, B>
append(field: string, value: unknown): THResponse<O, B>
cookie(
name: string,
value: string | Record<string, unknown>,
options?: SetCookieOptions,
): THResponse<O, B>
clearCookie(name: string): THResponse<O, B>
location(url: string): THResponse<O, B>
header(
field: string | Record<string, string | number | string[]>,
val?: string | number | readonly string[],
): THResponse<O, B>
set(
field: string | Record<string, string | number | string[]>,
val?: string | number | readonly string[],
): THResponse<O, B>
get(field: string): string | null
app?: App
}