Repository navigation
Expand file tree
/
Copy pathpolymorphics.ts
More file actions
76 lines (70 loc) · 1.75 KB
/
Copy pathpolymorphics.ts
File metadata and controls
76 lines (70 loc) · 1.75 KB
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
/**
* Event-like interface that's usable in browser and node.
*
* Note: Here we mean the kind of events handled by event listeners, not our `Event` type.
*
* Property availability taken from https://developer.mozilla.org/en-US/docs/Web/API/Event#browser_compatibility
*/
export interface PolymorphicEvent {
[key: string]: unknown;
readonly type: string;
readonly target?: unknown;
readonly currentTarget?: unknown;
}
/** A `Request` type compatible with Node, Express, browser, etc., because everything is optional */
export type PolymorphicRequest = BaseRequest & NodeRequest & ExpressRequest & KoaRequest & NextjsRequest;
type BaseRequest = {
method?: string;
url?: string;
};
type NodeRequest = BaseRequest & {
headers?: {
[key: string]: string | string[] | undefined;
};
protocol?: string;
socket?: {
encrypted?: boolean;
remoteAddress?: string;
};
};
type KoaRequest = NodeRequest & {
host?: string;
hostname?: string;
ip?: string;
originalUrl?: string;
};
type NextjsRequest = NodeRequest & {
cookies?: {
[key: string]: string;
};
query?: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};
};
type ExpressRequest = NodeRequest & {
baseUrl?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body?: string | { [key: string]: any };
host?: string;
hostname?: string;
ip?: string;
originalUrl?: string;
route?: {
path: string;
stack: [
{
name: string;
},
];
};
query?: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};
user?: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};
_reconstructedRoute?: string;
};