-
Notifications
You must be signed in to change notification settings - Fork 230
/
types.d.ts
161 lines (145 loc) · 3.93 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
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
// Copyright 2018-2022 the oak authors. All rights reserved. MIT license.
import type { Application, State } from "./application.ts";
import type { Status } from "./deps.ts";
/** A HTTP status that is an error (4XX and 5XX). */
export type ErrorStatus =
| Status.BadRequest
| Status.Unauthorized
| Status.PaymentRequired
| Status.Forbidden
| Status.NotFound
| Status.MethodNotAllowed
| Status.NotAcceptable
| Status.ProxyAuthRequired
| Status.RequestTimeout
| Status.Conflict
| Status.Gone
| Status.LengthRequired
| Status.PreconditionFailed
| Status.RequestEntityTooLarge
| Status.RequestURITooLong
| Status.UnsupportedMediaType
| Status.RequestedRangeNotSatisfiable
| Status.ExpectationFailed
| Status.Teapot
| Status.MisdirectedRequest
| Status.UnprocessableEntity
| Status.Locked
| Status.FailedDependency
| Status.UpgradeRequired
| Status.PreconditionRequired
| Status.TooManyRequests
| Status.RequestHeaderFieldsTooLarge
| Status.UnavailableForLegalReasons
| Status.InternalServerError
| Status.NotImplemented
| Status.BadGateway
| Status.ServiceUnavailable
| Status.GatewayTimeout
| Status.HTTPVersionNotSupported
| Status.VariantAlsoNegotiates
| Status.InsufficientStorage
| Status.LoopDetected
| Status.NotExtended
| Status.NetworkAuthenticationRequired;
/** A HTTP status that is a redirect (3XX). */
export type RedirectStatus =
| Status.MultipleChoices // 300
| Status.MovedPermanently // 301
| Status.Found // 302
| Status.SeeOther // 303
| Status.UseProxy // 305 - DEPRECATED
| Status.TemporaryRedirect // 307
| Status.PermanentRedirect; // 308
export type HTTPMethods =
| "ACL"
| "BIND"
| "CHECKOUT"
| "CONNECT"
| "COPY"
| "DELETE"
| "GET"
| "HEAD"
| "LINK"
| "LOCK"
| "M-SEARCH"
| "MERGE"
| "MKACTIVITY"
| "MKCALENDAR"
| "MKCOL"
| "MOVE"
| "NOTIFY"
| "OPTIONS"
| "PATCH"
| "POST"
| "PROPFIND"
| "PROPPATCH"
| "PURGE"
| "PUT"
| "REBIND"
| "REPORT"
| "SEARCH"
| "SOURCE"
| "SUBSCRIBE"
| "TRACE"
| "UNBIND"
| "UNLINK"
| "UNLOCK"
| "UNSUBSCRIBE";
export interface Listener {
addr: { hostname: string; port: number };
}
export interface Server<T> extends AsyncIterable<T> {
close(): void | Promise<void>;
listen(): Listener | Promise<Listener>;
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
}
export interface ServerRequestBody {
body: ReadableStream<Uint8Array> | null;
readBody: () => Promise<Uint8Array>;
}
export interface ServerRequest {
readonly remoteAddr: string | undefined;
readonly headers: Headers;
readonly method: string;
readonly rawUrl?: string;
readonly url: string;
// deno-lint-ignore no-explicit-any
error(reason?: any): void;
getBody(): ServerRequestBody;
respond(response: Response): Promise<void>;
upgrade?(options?: UpgradeWebSocketOptions): WebSocket;
}
export interface ServerConstructor<T extends ServerRequest> {
// deno-lint-ignore no-explicit-any
new <AS extends State = Record<string, any>>(
app: Application<AS>,
options: Deno.ListenOptions | Deno.ListenTlsOptions,
): Server<T>;
prototype: Server<T>;
}
export type Data = string | number[] | ArrayBuffer | Uint8Array;
export type Key = string | number[] | ArrayBuffer | Uint8Array;
export interface UpgradeWebSocketOptions {
protocol?: string;
}
export type UpgradeWebSocketFn = (
request: Request,
options?: UpgradeWebSocketOptions,
) => WebSocketUpgrade;
interface WebSocketUpgrade {
response: Response;
socket: WebSocket;
}
// Since the native bindings are currently unstable in Deno, we will add the
// interfaces here, so that we can type check oak without requiring the
// `--unstable` flag to be used.
export interface RequestEvent {
readonly request: Request;
respondWith(r: Response | Promise<Response>): Promise<void>;
}
export interface HttpConn extends AsyncIterable<RequestEvent> {
readonly rid: number;
nextRequest(): Promise<RequestEvent | null>;
close(): void;
}