-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
64 lines (57 loc) · 1.47 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
/**
* Params are parsed options, usually extracted from the Request (path/query string...)
*/
interface Params {
[key: string]: string
}
/**
* The context of the current request, including the full FetchEvent, the current Request and the Params matched by the Router if any
*/
interface RequestContext {
event: FetchEvent
request: Request
params: Params
}
/**
* Responsible for providing the Response to a given RequestContext
*/
interface RequestHandler {
(context: RequestContext): Promise<Response> | Response
}
/**
* Higher order functions that will wrap RequestHandlers with additional logic
* Example: Error management, Cache handling
*/
interface Middleware {
(func: RequestHandler): RequestHandler
}
/**
* A Middleware factory takes in options for the underlying Middleware function
* Example:
* - Cache settings for a Cache handling middleware.
* - Transforms for a Redirect middleware.
*/
interface MiddlewareFactory {
(options?: unknown): Middleware
}
/**
* A Transform takes in the RequestContext and returns a transformed Request
*/
interface Transform {
(context: RequestContext): Request
}
/**
* Responsible for providing the Response to a given FetchEvent
*/
interface FetchEventHandler {
(event: FetchEvent): Response | Promise<Response>
}
/**
* Responsible from providing a RequestHandler and the Params for a given FetchEvent
*/
interface RouteMatcher {
(event: FetchEvent): {
handler: RequestHandler
params: Params
} | null
}