beer-network 1.1.1-alpha.12 → 1.1.1-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.d.ts +83 -1
- package/api.js +147 -39
- package/package.json +1 -1
package/api.d.ts
CHANGED
|
@@ -31,6 +31,18 @@ export default class Fetch {
|
|
|
31
31
|
*/
|
|
32
32
|
private readonly pathPrefix;
|
|
33
33
|
constructor(pathPrefix: string);
|
|
34
|
+
private sendBody;
|
|
35
|
+
private sendForm;
|
|
36
|
+
private sendFormData;
|
|
37
|
+
private send;
|
|
38
|
+
/**
|
|
39
|
+
* 发送POST 请求.
|
|
40
|
+
* @param path 路径.
|
|
41
|
+
* @param params 参数.
|
|
42
|
+
* @param header 头部.
|
|
43
|
+
* @param option 选项.
|
|
44
|
+
*/
|
|
45
|
+
post<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
34
46
|
/**
|
|
35
47
|
* 发送POST/JSON 请求.
|
|
36
48
|
* @param path 路径.
|
|
@@ -39,7 +51,7 @@ export default class Fetch {
|
|
|
39
51
|
* @param header 头部.
|
|
40
52
|
* @param option 选项.
|
|
41
53
|
*/
|
|
42
|
-
|
|
54
|
+
postBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
43
55
|
/**
|
|
44
56
|
* 发送POST/Form 请求.
|
|
45
57
|
* @param path 路径.
|
|
@@ -58,6 +70,76 @@ export default class Fetch {
|
|
|
58
70
|
* @param option 选项.
|
|
59
71
|
*/
|
|
60
72
|
postFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* 发送PUT 请求.
|
|
75
|
+
* @param path 路径.
|
|
76
|
+
* @param params 参数.
|
|
77
|
+
* @param header 头部.
|
|
78
|
+
* @param option 选项.
|
|
79
|
+
*/
|
|
80
|
+
put<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
81
|
+
/**
|
|
82
|
+
* 发送PUT/JSON 请求.
|
|
83
|
+
* @param path 路径.
|
|
84
|
+
* @param params 参数.
|
|
85
|
+
* @param body 内容体.
|
|
86
|
+
* @param header 头部.
|
|
87
|
+
* @param option 选项.
|
|
88
|
+
*/
|
|
89
|
+
putBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
90
|
+
/**
|
|
91
|
+
* 发送PUT/Form 请求.
|
|
92
|
+
* @param path 路径.
|
|
93
|
+
* @param params 参数.
|
|
94
|
+
* @param form Form参数.
|
|
95
|
+
* @param header 头部.
|
|
96
|
+
* @param option 选项.
|
|
97
|
+
*/
|
|
98
|
+
putForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
99
|
+
/**
|
|
100
|
+
* 发送PUT/FormData 请求.
|
|
101
|
+
* @param path 路径.
|
|
102
|
+
* @param params 参数.
|
|
103
|
+
* @param formData Form参数.
|
|
104
|
+
* @param header 头部.
|
|
105
|
+
* @param option 选项.
|
|
106
|
+
*/
|
|
107
|
+
putFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
108
|
+
/**
|
|
109
|
+
* 发送DELETE 请求.
|
|
110
|
+
* @param path 路径.
|
|
111
|
+
* @param params 参数.
|
|
112
|
+
* @param header 头部.
|
|
113
|
+
* @param option 选项.
|
|
114
|
+
*/
|
|
115
|
+
delete<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
116
|
+
/**
|
|
117
|
+
* 发送DELETE/JSON 请求.
|
|
118
|
+
* @param path 路径.
|
|
119
|
+
* @param params 参数.
|
|
120
|
+
* @param body 内容体.
|
|
121
|
+
* @param header 头部.
|
|
122
|
+
* @param option 选项.
|
|
123
|
+
*/
|
|
124
|
+
deleteBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
125
|
+
/**
|
|
126
|
+
* 发送DELETE/Form 请求.
|
|
127
|
+
* @param path 路径.
|
|
128
|
+
* @param params 参数.
|
|
129
|
+
* @param form Form参数.
|
|
130
|
+
* @param header 头部.
|
|
131
|
+
* @param option 选项.
|
|
132
|
+
*/
|
|
133
|
+
deleteForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
134
|
+
/**
|
|
135
|
+
* 发送DELETE/FormData 请求.
|
|
136
|
+
* @param path 路径.
|
|
137
|
+
* @param params 参数.
|
|
138
|
+
* @param formData Form参数.
|
|
139
|
+
* @param header 头部.
|
|
140
|
+
* @param option 选项.
|
|
141
|
+
*/
|
|
142
|
+
deleteFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
61
143
|
/**
|
|
62
144
|
* 发送Get 请求.
|
|
63
145
|
* @param path 路径.
|
package/api.js
CHANGED
|
@@ -3,22 +3,14 @@ export default class Fetch {
|
|
|
3
3
|
constructor(pathPrefix) {
|
|
4
4
|
this.pathPrefix = pathPrefix;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
* 发送POST/JSON 请求.
|
|
8
|
-
* @param path 路径.
|
|
9
|
-
* @param params 参数.
|
|
10
|
-
* @param body 内容体.
|
|
11
|
-
* @param header 头部.
|
|
12
|
-
* @param option 选项.
|
|
13
|
-
*/
|
|
14
|
-
async post(path, params, body, header, option) {
|
|
6
|
+
async sendBody(method, path, params, body, header, option) {
|
|
15
7
|
const paramQuery = new URLSearchParams();
|
|
16
8
|
Object.keys(params || {})
|
|
17
9
|
.forEach(key => {
|
|
18
10
|
paramQuery.append(key, params[key]);
|
|
19
11
|
});
|
|
20
12
|
const response = await fetch(this.pathPrefix + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
21
|
-
method
|
|
13
|
+
method,
|
|
22
14
|
headers: {
|
|
23
15
|
...this.authorization(),
|
|
24
16
|
...(header || {}),
|
|
@@ -29,15 +21,7 @@ export default class Fetch {
|
|
|
29
21
|
});
|
|
30
22
|
return this.responseJson(response);
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
* 发送POST/Form 请求.
|
|
34
|
-
* @param path 路径.
|
|
35
|
-
* @param params 参数.
|
|
36
|
-
* @param form Form参数.
|
|
37
|
-
* @param header 头部.
|
|
38
|
-
* @param option 选项.
|
|
39
|
-
*/
|
|
40
|
-
async postForm(path, params, form, header, option) {
|
|
24
|
+
async sendForm(method, path, params, form, header, option) {
|
|
41
25
|
const paramQuery = new URLSearchParams();
|
|
42
26
|
Object.keys(params || {})
|
|
43
27
|
.forEach(key => {
|
|
@@ -63,7 +47,7 @@ export default class Fetch {
|
|
|
63
47
|
};
|
|
64
48
|
appendFormData(form);
|
|
65
49
|
const response = await fetch(this.pathPrefix + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
66
|
-
method
|
|
50
|
+
method,
|
|
67
51
|
headers: {
|
|
68
52
|
...this.authorization(),
|
|
69
53
|
...(header || {}),
|
|
@@ -74,22 +58,14 @@ export default class Fetch {
|
|
|
74
58
|
});
|
|
75
59
|
return this.responseJson(response);
|
|
76
60
|
}
|
|
77
|
-
|
|
78
|
-
* 发送POST/FormData 请求.
|
|
79
|
-
* @param path 路径.
|
|
80
|
-
* @param params 参数.
|
|
81
|
-
* @param formData Form参数.
|
|
82
|
-
* @param header 头部.
|
|
83
|
-
* @param option 选项.
|
|
84
|
-
*/
|
|
85
|
-
async postFormData(path, params, formData, header, option) {
|
|
61
|
+
async sendFormData(method, path, params, formData, header, option) {
|
|
86
62
|
const paramQuery = new URLSearchParams();
|
|
87
63
|
Object.keys(params || {})
|
|
88
64
|
.forEach(key => {
|
|
89
65
|
paramQuery.append(key, params[key]);
|
|
90
66
|
});
|
|
91
67
|
const response = await fetch(this.pathPrefix + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
92
|
-
method
|
|
68
|
+
method,
|
|
93
69
|
headers: {
|
|
94
70
|
...this.authorization(),
|
|
95
71
|
...(header || {})
|
|
@@ -99,21 +75,14 @@ export default class Fetch {
|
|
|
99
75
|
});
|
|
100
76
|
return this.responseJson(response);
|
|
101
77
|
}
|
|
102
|
-
|
|
103
|
-
* 发送Get 请求.
|
|
104
|
-
* @param path 路径.
|
|
105
|
-
* @param params 参数.
|
|
106
|
-
* @param header 头部.
|
|
107
|
-
* @param option 选项.
|
|
108
|
-
*/
|
|
109
|
-
async get(path, params, header, option) {
|
|
78
|
+
async send(method, path, params, header, option) {
|
|
110
79
|
const paramQuery = new URLSearchParams();
|
|
111
80
|
Object.keys(params || {})
|
|
112
81
|
.forEach(key => {
|
|
113
82
|
paramQuery.append(key, params[key]);
|
|
114
83
|
});
|
|
115
84
|
const response = await fetch(this.pathPrefix + path + '?' + paramQuery.toString(), {
|
|
116
|
-
method
|
|
85
|
+
method,
|
|
117
86
|
headers: {
|
|
118
87
|
...this.authorization(),
|
|
119
88
|
...(header || {})
|
|
@@ -122,6 +91,145 @@ export default class Fetch {
|
|
|
122
91
|
});
|
|
123
92
|
return this.responseJson(response);
|
|
124
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* 发送POST 请求.
|
|
96
|
+
* @param path 路径.
|
|
97
|
+
* @param params 参数.
|
|
98
|
+
* @param header 头部.
|
|
99
|
+
* @param option 选项.
|
|
100
|
+
*/
|
|
101
|
+
async post(path, params, header, option) {
|
|
102
|
+
return this.send('POST', path, params, header, option);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 发送POST/JSON 请求.
|
|
106
|
+
* @param path 路径.
|
|
107
|
+
* @param params 参数.
|
|
108
|
+
* @param body 内容体.
|
|
109
|
+
* @param header 头部.
|
|
110
|
+
* @param option 选项.
|
|
111
|
+
*/
|
|
112
|
+
async postBody(path, params, body, header, option) {
|
|
113
|
+
return this.sendBody('POST', path, params, body, header, option);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 发送POST/Form 请求.
|
|
117
|
+
* @param path 路径.
|
|
118
|
+
* @param params 参数.
|
|
119
|
+
* @param form Form参数.
|
|
120
|
+
* @param header 头部.
|
|
121
|
+
* @param option 选项.
|
|
122
|
+
*/
|
|
123
|
+
async postForm(path, params, form, header, option) {
|
|
124
|
+
return this.sendForm('POST', path, params, form, header, option);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 发送POST/FormData 请求.
|
|
128
|
+
* @param path 路径.
|
|
129
|
+
* @param params 参数.
|
|
130
|
+
* @param formData Form参数.
|
|
131
|
+
* @param header 头部.
|
|
132
|
+
* @param option 选项.
|
|
133
|
+
*/
|
|
134
|
+
async postFormData(path, params, formData, header, option) {
|
|
135
|
+
return this.sendFormData('POST', path, params, formData, header, option);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 发送PUT 请求.
|
|
139
|
+
* @param path 路径.
|
|
140
|
+
* @param params 参数.
|
|
141
|
+
* @param header 头部.
|
|
142
|
+
* @param option 选项.
|
|
143
|
+
*/
|
|
144
|
+
async put(path, params, header, option) {
|
|
145
|
+
return this.send('PUT', path, params, header, option);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 发送PUT/JSON 请求.
|
|
149
|
+
* @param path 路径.
|
|
150
|
+
* @param params 参数.
|
|
151
|
+
* @param body 内容体.
|
|
152
|
+
* @param header 头部.
|
|
153
|
+
* @param option 选项.
|
|
154
|
+
*/
|
|
155
|
+
async putBody(path, params, body, header, option) {
|
|
156
|
+
return this.sendBody('PUT', path, params, body, header, option);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 发送PUT/Form 请求.
|
|
160
|
+
* @param path 路径.
|
|
161
|
+
* @param params 参数.
|
|
162
|
+
* @param form Form参数.
|
|
163
|
+
* @param header 头部.
|
|
164
|
+
* @param option 选项.
|
|
165
|
+
*/
|
|
166
|
+
async putForm(path, params, form, header, option) {
|
|
167
|
+
return this.sendForm('PUT', path, params, form, header, option);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 发送PUT/FormData 请求.
|
|
171
|
+
* @param path 路径.
|
|
172
|
+
* @param params 参数.
|
|
173
|
+
* @param formData Form参数.
|
|
174
|
+
* @param header 头部.
|
|
175
|
+
* @param option 选项.
|
|
176
|
+
*/
|
|
177
|
+
async putFormData(path, params, formData, header, option) {
|
|
178
|
+
return this.sendFormData('PUT', path, params, formData, header, option);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 发送DELETE 请求.
|
|
182
|
+
* @param path 路径.
|
|
183
|
+
* @param params 参数.
|
|
184
|
+
* @param header 头部.
|
|
185
|
+
* @param option 选项.
|
|
186
|
+
*/
|
|
187
|
+
async delete(path, params, header, option) {
|
|
188
|
+
return this.send('DELETE', path, params, header, option);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 发送DELETE/JSON 请求.
|
|
192
|
+
* @param path 路径.
|
|
193
|
+
* @param params 参数.
|
|
194
|
+
* @param body 内容体.
|
|
195
|
+
* @param header 头部.
|
|
196
|
+
* @param option 选项.
|
|
197
|
+
*/
|
|
198
|
+
async deleteBody(path, params, body, header, option) {
|
|
199
|
+
return this.sendBody('DELETE', path, params, body, header, option);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 发送DELETE/Form 请求.
|
|
203
|
+
* @param path 路径.
|
|
204
|
+
* @param params 参数.
|
|
205
|
+
* @param form Form参数.
|
|
206
|
+
* @param header 头部.
|
|
207
|
+
* @param option 选项.
|
|
208
|
+
*/
|
|
209
|
+
async deleteForm(path, params, form, header, option) {
|
|
210
|
+
return this.sendForm('DELETE', path, params, form, header, option);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* 发送DELETE/FormData 请求.
|
|
214
|
+
* @param path 路径.
|
|
215
|
+
* @param params 参数.
|
|
216
|
+
* @param formData Form参数.
|
|
217
|
+
* @param header 头部.
|
|
218
|
+
* @param option 选项.
|
|
219
|
+
*/
|
|
220
|
+
async deleteFormData(path, params, formData, header, option) {
|
|
221
|
+
return this.sendFormData('DELETE', path, params, formData, header, option);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 发送Get 请求.
|
|
225
|
+
* @param path 路径.
|
|
226
|
+
* @param params 参数.
|
|
227
|
+
* @param header 头部.
|
|
228
|
+
* @param option 选项.
|
|
229
|
+
*/
|
|
230
|
+
async get(path, params, header, option) {
|
|
231
|
+
return this.send('GET', path, params, header, option);
|
|
232
|
+
}
|
|
125
233
|
/**
|
|
126
234
|
* 缓存.
|
|
127
235
|
* @param key 缓存Key.
|