-
Notifications
You must be signed in to change notification settings - Fork 10
/
Declarations.ts
203 lines (156 loc) · 4.29 KB
/
Declarations.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
export interface IResourceParamsBase {
url?: string;
pathPrefix?: string;
path?: string;
headers?: any;
body?: any;
params?: any;
query?: any;
}
export interface IResourceParams extends IResourceParamsBase {
rootNode?: string;
removeTrailingSlash?: boolean;
addTimestamp?: boolean | string;
withCredentials?: boolean;
lean?: boolean;
mutateBody?: boolean;
asPromise?: boolean;
keepEmptyBody?: boolean;
requestBodyType?: ResourceRequestBodyType;
responseBodyType?: ResourceResponseBodyType;
queryMappingMethod?: ResourceQueryMappingMethod;
asResourceResponse?: boolean;
[prop: string]: any;
}
export interface IResourceAction extends IResourceParams {
method?: ResourceRequestMethod; // get default
expectJsonArray?: boolean;
resultFactory?: IResourceResultFactory;
map?: IResourceResponseMap;
filter?: IResourceResponseFilter;
}
export interface IResourceResponseMap {
(item: any, options: IResourceActionInner): any;
}
export interface IResourceResponseFilter {
(item: any, options: IResourceActionInner): boolean;
}
export interface IResourceResultFactory {
(item: any, options: IResourceActionInner): any;
}
export interface IResourceActionAttributes {
body: any;
query: any;
params: any;
onSuccess(data: any): any;
onError(data: any): any;
}
export interface IResourceActionInner {
actionAttributes?: IResourceActionAttributes;
actionOptions?: IResourceAction;
resolvedOptions?: IResourceParamsBase;
queryMappingMethod?: ResourceQueryMappingMethod;
usedInPath?: { [key: string]: boolean };
mainPromise?: Promise<any>;
isModel?: boolean;
requestOptions?: IResourceRequest;
returnData?: any;
}
export interface IResourceRequest {
method?: ResourceRequestMethod;
headers?: any;
url?: string;
withCredentials?: boolean;
body?: any;
query?: { [prop: string]: string };
responseBodyType?: ResourceResponseBodyType;
requestBodyType?: ResourceRequestBodyType;
}
export interface IResourceHandlerResponse {
promise: Promise<IResourceResponse>;
abort?(): void;
}
export interface IResourceResponse<B = any> {
status: number;
headers?: any;
body?: B;
}
export interface IResourceMethodStrictBase<IB, IQ, IP, O, R> {
(body: IB,
query: IQ,
params: IP,
onSuccess?: (data: O) => any,
onError?: (err: IResourceResponse) => any): R;
(body: IB,
query: IQ,
onSuccess?: (data: O) => any,
onError?: (err: IResourceResponse) => any): R;
(body: IB,
onSuccess?: (data: O) => any,
onError?: (err: IResourceResponse) => any): R;
(onSuccess?: (data: O) => any,
onError?: (err: IResourceResponse) => any): R;
}
export interface IResourceMethodBase<IB, O, R>
extends IResourceMethodStrictBase<IB, any, any, O, R> {
}
export interface IResourceMethodStrict<IB, IQ, IP, O>
extends IResourceMethodStrictBase<IB, IQ, IP, O, Promise<O>> {
}
export interface IResourceMethod<IB, O>
extends IResourceMethodBase<IB, O, Promise<O>> {
}
export interface IResourceMethodResultStrict<IB, IQ, IP, O>
extends IResourceMethodStrictBase<IB, IQ, IP, O, ResourceResult<O>> {
}
export interface IResourceMethodResult<IB, O>
extends IResourceMethodBase<IB, O, ResourceResult<O>> {
}
// As IResourceResponse
export interface IResourceMethodStrictFull<IB, IQ, IP, O>
extends IResourceMethodStrictBase<IB, IQ, IP, O, Promise<IResourceResponse<O>>> {
}
export interface IResourceMethodFull<IB, O>
extends IResourceMethodBase<IB, O, Promise<IResourceResponse<O>>> {
}
export interface IResourceMethodResultStrictFull<IB, IQ, IP, O>
extends IResourceMethodStrictBase<IB, IQ, IP, O, ResourceResult<IResourceResponse<O>>> {
}
export interface IResourceMethodResultFull<IB, O>
extends IResourceMethodBase<IB, O, ResourceResult<IResourceResponse<O>>> {
}
export type ResourceResult<R extends {}> = R & {
$resolved?: boolean;
$promise?: Promise<R>;
$abort?(): void;
};
export enum ResourceRequestBodyType {
NONE = 0,
JSON = 1,
FORM = 2,
FORM_DATA = 3,
TEXT = 4,
BLOB = 5,
ARRAY_BUFFER = 6
}
export enum ResourceResponseBodyType {
Text = 1,
Json = 2,
ArrayBuffer = 3,
Blob = 4
}
export enum ResourceRequestMethod {
Get = 1,
Post = 2,
Put = 3,
Delete = 4,
Options = 5,
Head = 6,
Patch = 7
}
export enum ResourceQueryMappingMethod {
Plain = 1,
Bracket = 2,
JQueryParamsBracket = 3,
None = 99
}