/
types.d.ts
75 lines (66 loc) · 2.2 KB
/
types.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
type HTMLRewriterHandlers = {
element?: (element: import("https://deno.land/x/lol_html@0.0.3/types.d.ts").Element) => void;
comments?: (comment: import("https://deno.land/x/lol_html@0.0.3/types.d.ts").Comment) => void;
text?: (text: import("https://deno.land/x/lol_html@0.0.3/types.d.ts").TextChunk) => void;
};
type HTMLRewriter = {
on: (selector: string, HTMLRewriterHandlers) => void;
};
declare type CookieOptions = {
expires?: number | Date;
maxAge?: number;
domain?: string;
path?: string;
httpOnly?: boolean;
secure?: boolean;
sameSite?: "lax" | "strict" | "none";
};
declare interface Cookies {
get(key: string): string | undefined;
set(key: string, value: string, options?: CookieOptions): void;
delete(key: string, options: CookieOptions): void;
}
declare type CacheControlOptions = {
maxAge?: number;
sMaxAge?: number;
public?: boolean;
private?: boolean;
immutable?: boolean;
mustRevalidate?: boolean;
};
declare interface Context extends Record<string, unknown> {
readonly params: Record<string, string>;
readonly headers: Headers;
readonly cookies: Cookies;
readonly htmlRewriter: HTMLRewriter;
redirect(url: string | URL, code?: number): Response;
json(data: unknown, init?: ResponseInit): Response;
content(
content: BodyInit,
init?: ResponseInit & {
contentType?: string;
cacheControl?: "no-cache" | "immutable" | CacheControlOptions;
},
): Response;
}
declare interface Data {
cacheTtl?: number;
get?(request: Request, context: Context): Promise<Response> | Response;
post?(request: Request, context: Context): Promise<Response> | Response;
put?(request: Request, context: Context): Promise<Response> | Response;
patch?(request: Request, context: Context): Promise<Response> | Response;
delete?(request: Request, context: Context): Promise<Response> | Response;
}
type MiddlewareCallback = () => Promise<void> | void;
declare interface Middleware {
fetch(
request: Request,
context: Context,
): Promise<Response | MiddlewareCallback | void> | Response | MiddlewareCallback | void;
}
declare interface ImportMeta {
readonly hot?: {
accept: (callback?: (module: unknown) => void) => void;
decline: () => void;
};
}