-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.d.ts
More file actions
51 lines (41 loc) · 2.17 KB
/
resource.d.ts
File metadata and controls
51 lines (41 loc) · 2.17 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
declare module '@spawm/resource' {
export default class Resource<T = ResponsePayload> extends Endpoint<T> {
constructor(url: string, options?: Options<T>);
add<NewT = T>(path: string, options?: Options<NewT>): Endpoint<NewT>;
}
export class Endpoint<T = ResponsePayload> {
get(query?: QueryParams, options?: Options<T>): AbortablePromise<T>;
post(body: RequestPayload, query?: QueryParams, options?: PartialOptions): AbortablePromise<T>;
put(body: RequestPayload, query?: QueryParams, options?: PartialOptions): AbortablePromise<T>;
patch(body: RequestPayload, query?: QueryParams, options?: PartialOptions): AbortablePromise<T>;
delete(query?: QueryParams, options?: PartialOptions): AbortablePromise<T>;
send(method: string, body?: RequestPayload, query?: QueryParams, options?: Options<T>): AbortablePromise<T>;
}
export interface AbortablePromise<T> extends Promise<T> {
abort: () => void;
}
export interface PartialOptions {
redirect?: boolean;
type?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
timeout?: number;
withCredentials?: boolean;
onDownloading?: (loaded: number, total: number) => void;
onUploading?: (loaded: number, total: number) => void;
headers?: { [x: string]: string };
}
export interface Options<T = ResponsePayload> extends PartialOptions {
cache?: number;
swr?: null | {
focus?: number;
reconnect?: number;
stale?: number;
onUpdate?: (reply: T, meta: { status: number, headers: { [x: string]: string } }) => void;
}
}
type JSONObject = { [key: string]: JSONValue | JSONObject | Array<JSONObject | JSONValue> };
type JSONValue = string | number | boolean | null;
type Payload = JSONObject | Array<JSONObject | JSONValue> | Blob | ArrayBuffer | null;
type ResponsePayload = Payload | string | Document;
type QueryParams = { [key: string]: string | number | Array<string | number> } | URLSearchParams;
type RequestPayload = Payload | { [key: string]: JSONValue | Array<JSONValue | Blob> | Blob } | URLSearchParams;
}