UNPKG

2.25 kBTypeScriptView Raw
1export interface PlatformInfo {
2 name: string;
3 version?: string;
4 extra?: string;
5 userAgent?: string;
6}
7
8export type HTTPMethod =
9 | "OPTIONS"
10 | "GET"
11 | "HEAD"
12 | "POST"
13 | "PUT"
14 | "DELETE"
15 | "TRACE"
16 | "CONNECT";
17export interface ProgressEvent {
18 loaded: number;
19 percent?: number;
20 total?: number;
21}
22export interface AbortSignal {
23 readonly aborted: boolean;
24 addEventListener: (type: string, listener: () => any) => any;
25 removeEventListener: (type: string, listener: () => any) => any;
26}
27export interface RequestOptions {
28 method?: HTTPMethod;
29 headers?: Record<string, string>;
30 data?: Record<string, string>;
31 onprogress?: (event: ProgressEvent) => void;
32 signal?: AbortSignal;
33}
34export interface Response {
35 status?: number;
36 ok?: boolean;
37 headers?: object;
38 data?: object;
39}
40export interface FormDataPart {
41 field: string;
42 data: any;
43 name: string;
44}
45
46export declare type SyncStorage = {
47 async?: false;
48 getItem: (key: string) => string | null;
49 setItem: (key: string, value: string) => any;
50 removeItem: (key: string) => any;
51 clear: () => any;
52};
53export declare type AsyncStorage = {
54 async: true;
55 getItem: (key: string) => Promise<string | null>;
56 setItem: (key: string, value: string) => Promise<any>;
57 removeItem: (key: string) => Promise<any>;
58 clear: () => Promise<any>;
59};
60export declare type Storage = SyncStorage | AsyncStorage;
61
62export interface WebSocket {
63 addEventListener(
64 event: string,
65 handler: (...args: any[]) => any,
66 ...args: any[]
67 ): any;
68 removeEventListener(
69 event: string,
70 handler: (...args: any[]) => any,
71 ...args: any[]
72 ): any;
73 send(data: string | ArrayBuffer): any;
74 close(): any;
75}
76
77export interface AuthData {
78 [key: string]: any;
79}
80export interface AuthInfo {
81 authData: AuthData;
82 provider: string;
83 platform?: string;
84}
85export interface Adapters {
86 platformInfo: PlatformInfo;
87 request: (url: string, options?: RequestOptions) => Promise<Response>;
88 upload: (
89 url: string,
90 file: FormDataPart,
91 options?: RequestOptions
92 ) => Promise<Response>;
93 storage: Storage;
94 WebSocket: {
95 new (url: string, protocols?: string | string[]): WebSocket;
96 };
97 getAuthInfo: (...args: any[]) => Promise<AuthInfo>;
98}