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 declare type PolymorphicRequest = BaseRequest & BrowserRequest & NodeRequest & ExpressRequest & KoaRequest & NextjsRequest;
16declare type BaseRequest = {
17 method?: string;
18 url?: string;
19};
20declare type BrowserRequest = BaseRequest;
21declare type NodeRequest = BaseRequest & {
22 headers?: {
23 [key: string]: string | string[] | undefined;
24 };
25 protocol?: string;
26 socket?: {
27 encrypted?: boolean;
28 remoteAddress?: string;
29 };
30};
31declare type KoaRequest = NodeRequest & {
32 host?: string;
33 hostname?: string;
34 ip?: string;
35 originalUrl?: string;
36};
37declare type NextjsRequest = NodeRequest & {
38 cookies?: {
39 [key: string]: string;
40 };
41 query?: {
42 [key: string]: any;
43 };
44};
45declare type 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 name: string;
58 }];
59 };
60 query?: {
61 [key: string]: any;
62 };
63 user?: {
64 [key: string]: any;
65 };
66};
67export {};
68//# sourceMappingURL=polymorphics.d.ts.map
\No newline at end of file