-
Notifications
You must be signed in to change notification settings - Fork 17
/
interfaces.ts
76 lines (66 loc) · 2.09 KB
/
interfaces.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
export type IHTTPMethods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
export interface IAPIOptions {
fetchMethod: (url: string, options?: any) => Promise<any>;
domains: { default: string, [key: string]: string };
prefixes: { default: string, [key: string]: string };
encodeParameters?: boolean;
middlewares?: APIMiddleware[];
responseMiddleware?: ResponseMiddleware;
debugAPI?: boolean;
printNetworkRequests?: boolean;
disableCache?: boolean;
cacheExpiration?: number;
cachePrefix?: string;
ignoreHeadersWhenCaching?: boolean;
capServices?: boolean;
capLimit?: number;
}
export interface IAPIService {
path?: string;
expiration?: number;
method?: IHTTPMethods;
domain?: string;
prefix?: string;
middlewares?: APIMiddleware[];
responseMiddleware?: ResponseMiddleware;
ignoreHeadersWhenCaching?: boolean;
disableCache?: boolean;
capService?: boolean;
capLimit?: number;
rawData?: boolean;
}
export interface IAPIServices {
[key: string]: IAPIService;
}
export interface IFetchOptions extends IAPIService {
pathParameters?: { [key: string]: any };
queryParameters?: { [key: string]: any };
headers?: { [key: string]: string };
fetchHeaders?: boolean;
middlewares?: APIMiddleware[];
responseMiddleware?: ResponseMiddleware;
fetchOptions?: any;
}
export interface IFetchResponse {
success: boolean;
data?: any;
}
export interface ICachedData {
success: boolean;
data?: any;
fresh?: boolean;
}
export interface ICacheDictionary {
[key: string]: number;
}
export interface IAPICacheDriver {
getItem(key: string): Promise<any>;
setItem(key: string, value: string, callback?: (err: any, value: string) => any): Promise<any>;
removeItem(key: string): Promise<any>;
}
export interface IMiddlewarePaths {
fullPath: string;
withoutQueryParams: string;
}
export type APIMiddleware = (serviceDefinition: IAPIService, paths: IMiddlewarePaths, options?: IFetchOptions) => any;
export type ResponseMiddleware = (response: any) => any;