-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
92 lines (54 loc) · 2.75 KB
/
index.d.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Type definitions for margaret-fetcher
// Definitions by: Maxime Fabre (maxime@madewithlove.be)
declare type Middleware = (response: Response) => any;
declare type Payload = any;
declare type QueryParameter = any;
declare type QueryParameters = {[key: string]: QueryParameter};
declare type Request = Promise<any>;
declare type ResourceId = number | string;
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// REQUEST CLASSES ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////
export class AbstractRequest {
buildEndpoint(resouce: string): string;
make(url: string, options: RequestInit): Request;
fetch(url: string, body: RequestInit): Request;
getSubrequest(subrequest: string | AbstractRequest, id: string): this;
setOptions(options: RequestInit): this;
withOptions(options: RequestInit): this;
withBearerToken(token: string | Function): this;
setQueryParameters(parameters: QueryParameters): this;
withQueryParameter(key: string, value: QueryParameter): this;
withQueryParameters(parameters: QueryParameters): this;
setMiddlewares(middlewares: Middleware[]): this;
withMiddleware(middleware: Middleware): this;
withoutMiddlewares(): this;
get (url: string): Request;
put(url: string, body: RequestInit): Request;
patch(url: string, body: RequestInit): Request;
post(url: string, body: RequestInit): Request;
delete(url: string): Request;
}
export class JsonRequest extends AbstractRequest {
put(url: string, payload?: Payload): Request;
patch(url: string, payload?: Payload): Request;
post(url: string, payload?: Payload): Request;
}
export class CrudRequest extends JsonRequest {
index(payload?: Payload): Request;
store(payload?: Payload): Request;
show(id: ResourceId): Request;
update(id: ResourceId, payload?: Payload): Request;
destroy(id: ResourceId): Request;
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// MIDDLEWARES //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
export function extractData<Middleware>(response: Response): any;
export function parseJson<Middleware>(response: Response): any;
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// HELPERS ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
export function buildOptions(options: object): object;
export function buildQuery(components: object): object;
export function jsonParser(json: string): any;