-
Notifications
You must be signed in to change notification settings - Fork 229
/
mod.ts
63 lines (52 loc) · 1.48 KB
/
mod.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
/* eslint-disable */
import type { IncomingMessage, ServerResponse } from "http";
export type Method =
| "GET"
| "POST"
| "PUT"
| "DELETE"
| "PATCH"
| "HEAD"
| "OPTIONS"
| "TRACE"
| "CONNECT";
export type Header<
TypeOrName extends string | number | boolean = string,
Name extends string = ""
> = TypeOrName extends string ? string : TypeOrName;
export type Query<
TypeOrName extends string | number | boolean = string,
Name extends string = ""
> = TypeOrName extends string ? string : TypeOrName;
export interface APIOptions {
method?: Method | Method[] | "*";
path?: string;
expose?: boolean;
auth?: boolean;
}
type HandlerFn<Params, Response> = Params extends void
? () => Promise<Response>
: (params: Params) => Promise<Response>;
export function api<
Params extends object | void = void,
Response extends object | void = void
>(
options: APIOptions,
fn: (params: Params) => Promise<Response>
): HandlerFn<Params, Response>;
export function api<
Params extends object | void = void,
Response extends object | void = void
>(
options: APIOptions,
fn: (params: Params) => Response
): HandlerFn<Params, Response>;
export function api(options: APIOptions, fn: any): typeof fn {
return fn;
}
export type RawHandler = (req: IncomingMessage, resp: ServerResponse) => void;
api.raw = function raw(options: APIOptions, fn: RawHandler) {
return fn;
};
export { APIError, ErrCode } from "./error";
export { Gateway, type GatewayConfig } from "./gateway";