-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
98 lines (70 loc) · 2.15 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
93
94
95
96
97
98
/// <reference types="vue-abstract-api" />
import {AxiosInstance, AxiosResponse} from 'axios';
interface HeaderLineObject {
[key: string]: String;
}
interface AuthenticationObject {
user: String;
password: String;
}
interface ApiOptions {
headers: HeaderLineObject,
authentication: AuthenticationObject;
interceptors: {
request: Array<(value: any) => any | Promise<any>>,
response: Array<(value: any) => any | Promise<any>>
}
}
export interface Api {
new(baseUrl: String, options: ApiOptions): Api;
baseUrl: String;
headers: HeaderLineObject;
authentication: AuthenticationObject;
http: AxiosInstance;
endpoints: Set<Endpoint>;
}
export interface Endpoint {
api: Api;
name: String;
cache?: Map;
mount(api: Api): void;
flushCache(path?: String): void;
get(path: String, ...args): Promise<ApiResponse>;
delete(path: String, ...args): Promise<any>;
post(path: String, data: Object, ...args): Promise<any>;
put(path: String, data: Object, ...args): Promise<any>;
patch(path: String, data: Object, ...args): Promise<any>;
}
interface RequestOptionsObject {
params: Object
}
export interface Resource extends Endpoint {
path: String;
index(options?: RequestOptionsObject): Promise<ApiResponse>;
all(options?: RequestOptionsObject): Promise<Array<any>>;
one(id: Number, options?: RequestOptionsObject): Promise<any>;
create(data: Object, options?: RequestOptionsObject): Promise<any>;
update(id: Number, data: Object, options?: RequestOptionsObject): Promise<any>;
destroy(id: Number, options?: RequestOptionsObject): Promise<any>;
paginate(limit?: Number, offset?: Number): this;
orderBy(field: String, direction?: 'ASC' | 'DESC'): this;
filterBy(field: String, value: any): this;
}
interface ResponseDataObject<T = any> extends AxiosResponse {
total: Number;
count: Number;
results: Array<T>;
}
export interface ApiResponse<T = any> {
new(axiosResponse: AxiosResponse): ApiResponse;
data: ResponseDataObject;
total: Number;
count: Number;
results: Array<T>;
first: T;
last: T;
statusCode: Number;
headers: HeaderLineObject;
request: XMLHttpRequest;
response: AxiosResponse;
}