UNPKG

1.76 kBTypeScriptView Raw
1/**
2 * Event-like interface that's usable in browser and node.
3 *
4 * Note: Here we mean the kind of events handled by event listeners, not our `Event` type.
5 *
6 * Property availability taken from https://developer.mozilla.org/en-US/docs/Web/API/Event#browser_compatibility
7 */
8export interface PolymorphicEvent {
9 [key: string]: unknown;
10 readonly type: string;
11 readonly target?: unknown;
12 readonly currentTarget?: unknown;
13}
14/** A `Request` type compatible with Node, Express, browser, etc., because everything is optional */
15export type PolymorphicRequest = BaseRequest & BrowserRequest & NodeRequest & ExpressRequest & KoaRequest & NextjsRequest;
16type BaseRequest = {
17 method?: string;
18 url?: string;
19};
20type BrowserRequest = BaseRequest;
21type NodeRequest = BaseRequest & {
22 headers?: {
23 [key: string]: string | string[] | undefined;
24 };
25 protocol?: string;
26 socket?: {
27 encrypted?: boolean;
28 remoteAddress?: string;
29 };
30};
31type KoaRequest = NodeRequest & {
32 host?: string;
33 hostname?: string;
34 ip?: string;
35 originalUrl?: string;
36};
37type NextjsRequest = NodeRequest & {
38 cookies?: {
39 [key: string]: string;
40 };
41 query?: {
42 [key: string]: any;
43 };
44};
45type ExpressRequest = NodeRequest & {
46 baseUrl?: string;
47 body?: string | {
48 [key: string]: any;
49 };
50 host?: string;
51 hostname?: string;
52 ip?: string;
53 originalUrl?: string;
54 route?: {
55 path: string;
56 stack: [
57 {
58 name: string;
59 }
60 ];
61 };
62 query?: {
63 [key: string]: any;
64 };
65 user?: {
66 [key: string]: any;
67 };
68 _reconstructedRoute?: string;
69};
70export {};
71//# sourceMappingURL=polymorphics.d.ts.map
\No newline at end of file