-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
107 lines (89 loc) · 2.28 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 { ConnInfo, Handler as DenoHandler } from 'http/server.ts';
export type PlainObject = Record<string, unknown>;
export interface BaseContext {
page: <D = unknown>(data: D) => unknown;
}
export interface DenoContext {
connInfo: ConnInfo;
}
export interface CloudflareContext {
bindings: Bindings;
execution: ExecutionContext
}
export type Context = BaseContext & DenoContext & CloudflareContext;
export interface RequestExtension<P = Params> {
params: P;
files: {
[name: string]: File;
};
}
export type Handler = (
request: Request & RequestExtension,
context: Context
) => Response | Promise<Response>;
export type PlainHandler = (request: Request) => Response | Promise<Response>;
export interface Meta {
summary?: string;
description?: string;
parameters?: Array<unknown>;
responses?: Record<string, unknown>;
}
export type Middleware = (handler: Handler) => Handler;
export type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
export type Pipeline = [...Middleware[], Handler];
export type ReversedPipeline = [Handler, ...Middleware[]];
export interface RoutePaths {
[name: string]: any;
}
export interface RouteOptions {
middleware?: Middleware[];
meta?: Meta;
}
export interface HandlerMapping {
GET?: Handler | Pipeline;
POST?: Handler | Pipeline;
PUT?: Handler | Pipeline;
PATCH?: Handler | Pipeline;
DELETE?: Handler | Pipeline;
middleware?: Middleware[];
meta?: Meta;
}
export type Route = [string, HandlerMapping | Handler | Pipeline, Route?];
export type Routes = Route[];
export const HTTPMethod = {
GET: 'GET',
POST: 'POST',
PUT: 'PUT',
PATH: 'PATCH',
HEAD: 'HEAD',
OPTIONS: 'OPTIONS',
DELETE: 'DELETE',
} as const;
export type HTTPMethod = typeof HTTPMethod[keyof typeof HTTPMethod];
export interface HandlerParams {
handler: Handler;
names: string[];
}
export interface HandlerParamsMap {
[method: string]: HandlerParams;
}
export interface Params {
[name: string]: unknown;
}
export interface KeyValue {
name: string;
value: string;
}
// Cloudflare Specific
export interface Bindings {
[key: string]: any;
}
export interface ExecutionContext {
waitUntil(promise: Promise<unknown>): void;
}
export type CloudflareHandler = (
request: Request,
env: Bindings,
context: ExecutionContext,
) => Response | Promise<Response>;
export { DenoHandler };