-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.ts
107 lines (96 loc) · 2.64 KB
/
types.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
import type { Status } from "../deps.ts";
import type { AttainRequest } from "./request.ts";
import type { AttainResponse } from "./response.ts";
export type ThenArg<T> = T extends PromiseLike<infer U> ? U : T;
export interface AttainListenProps {
debug?: boolean;
secure?: boolean;
hostname?: string;
certFile?: string;
keyFile?: string;
transport?: "tcp";
}
export type SupportMethodType =
| "HEAD"
| "OPTIONS"
| "ALL"
| "GET"
| "POST"
| "PUT"
| "PATCH"
| "DELETE";
export type CallBackType<T = any> = (
request: AttainRequest,
response: AttainResponse,
db: T,
) => Promise<any> | void;
export type ParamCallBackType<T = any> = (
request: AttainRequest,
response: AttainResponse,
param: any,
db: T,
) => Promise<any> | void;
export type ErrorCallBackType<T = any> = (
error: any,
request: AttainRequest,
response: AttainResponse,
db: T,
) => Promise<any> | void;
export interface MiddlewareProps<T = any> {
url?: string;
paramHandlers?: ParamStackProps<T>[];
callBack?: CallBackType<T>;
method?: SupportMethodType;
next?: MiddlewareProps<T>[];
}
export interface ParamStackProps<T = any> {
paramName: string;
callBack: ParamCallBackType<T>;
}
export interface ErrorMiddlewareProps<T = any> {
url?: string;
callBack?: ErrorCallBackType<T>;
next?: ErrorMiddlewareProps<T>[];
}
// Copyright 2018-2020 the oak authors. All rights reserved. MIT license.
/** 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;