forked from fastify/light-my-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
108 lines (97 loc) · 2.86 KB
/
index.d.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
import * as stream from 'stream'
import * as http from 'http'
type HTTPMethods = 'DELETE' | 'delete' |
'GET' | 'get' |
'HEAD' | 'head' |
'PATCH' | 'patch' |
'POST' | 'post' |
'PUT' | 'put' |
'OPTIONS' | 'options'
declare namespace LightMyRequest {
function inject (
dispatchFunc: DispatchFunc,
options?: string | InjectOptions
): Chain
function inject (
dispatchFunc: DispatchFunc,
options: string | InjectOptions,
callback: CallbackFunc
): void
type DispatchFunc = (req: Request, res: Response) => void
type CallbackFunc = (err: Error, response: Response) => void
type InjectPayload = string | object | Buffer | NodeJS.ReadableStream
function isInjection (obj: Request | Response): boolean
interface InjectOptions {
url?: string | {
pathname: string
protocol?: string
hostname?: string
port?: string | number
query?: string | { [k: string]: string | string[] }
}
path?: string | {
pathname: string
protocol?: string
hostname?: string
port?: string | number
query?: string | { [k: string]: string | string[] }
}
headers?: http.IncomingHttpHeaders | http.OutgoingHttpHeaders
query?: string | { [k: string]: string | string[] }
simulate?: {
end: boolean,
split: boolean,
error: boolean,
close: boolean
}
authority?: string
remoteAddress?: string
method?: HTTPMethods
validate?: boolean
payload?: InjectPayload
server?: http.Server
cookies?: { [k: string]: string }
}
interface Request extends stream.Readable {
url: string
httpVersion: string
method: HTTPMethods
headers: http.IncomingHttpHeaders
prepare: (next: () => void) => void
// @deprecated
connection: object
}
interface Response extends http.ServerResponse {
raw: {
res: http.ServerResponse,
req: Request
}
rawPayload: Buffer
headers: http.OutgoingHttpHeaders
statusCode: number
statusMessage: string
trailers: { [key: string]: string }
payload: string
body: string
json: <T = any>() => T
cookies: Array<object>
}
interface Chain extends Promise<Response> {
delete: (url: string) => Chain
get: (url: string) => Chain
head: (url: string) => Chain
options: (url: string) => Chain
patch: (url: string) => Chain
post: (url: string) => Chain
put: (url: string) => Chain
trace: (url: string) => Chain
body: (body: InjectPayload) => Chain
headers: (headers: http.IncomingHttpHeaders | http.OutgoingHttpHeaders) => Chain
payload: (payload: InjectPayload) => Chain
query: (query: object) => Chain
cookies: (query: object) => Chain
end(): Promise<Response>
end(callback: CallbackFunc): void
}
}
export = LightMyRequest