@kevisual/query 0.0.40 → 0.0.42
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/dist/query-adapter.js +107 -124
- package/dist/query-api.d.ts +317 -0
- package/dist/query-api.js +449 -0
- package/dist/query-browser.d.ts +1 -8
- package/dist/query-browser.js +489 -582
- package/dist/query-ws.js +163 -181
- package/dist/query.d.ts +1 -8
- package/dist/query.js +278 -359
- package/package.json +13 -25
- package/src/adapter.ts +1 -1
- package/src/create-query/index.ts +159 -0
- package/src/query-api.ts +136 -0
- package/src/query-browser.ts +2 -2
- package/src/query.ts +1 -10
package/dist/query.js
CHANGED
|
@@ -1,384 +1,303 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/adapter.ts
|
|
2
|
+
var isTextForContentType = (contentType) => {
|
|
3
|
+
if (!contentType)
|
|
4
|
+
return false;
|
|
5
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
6
|
+
return textTypes.some((type) => contentType.includes(type));
|
|
6
7
|
};
|
|
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
|
-
...opts.params,
|
|
49
|
-
};
|
|
50
|
-
const searchParams = new URLSearchParams(params);
|
|
51
|
-
if (typeof opts.body === 'object' && opts.body !== null) {
|
|
52
|
-
// 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
|
|
53
|
-
let body = opts.body || {};
|
|
54
|
-
if (!params.path && body?.path) {
|
|
55
|
-
searchParams.set('path', body.path);
|
|
56
|
-
if (body?.key) {
|
|
57
|
-
searchParams.set('key', body.key);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
8
|
+
var adapter = async (opts = {}, overloadOpts) => {
|
|
9
|
+
const controller = new AbortController;
|
|
10
|
+
const signal = controller.signal;
|
|
11
|
+
const isPostFile = opts.isPostFile || false;
|
|
12
|
+
let responseType = opts.responseType || "json";
|
|
13
|
+
if (opts.isBlob) {
|
|
14
|
+
responseType = "blob";
|
|
15
|
+
} else if (opts.isText) {
|
|
16
|
+
responseType = "text";
|
|
17
|
+
}
|
|
18
|
+
const timeout = opts.timeout || 60000 * 3;
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
controller.abort();
|
|
21
|
+
}, timeout);
|
|
22
|
+
let method = overloadOpts?.method || opts?.method || "POST";
|
|
23
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
24
|
+
let origin = "";
|
|
25
|
+
let url;
|
|
26
|
+
if (opts?.url?.startsWith("http")) {
|
|
27
|
+
url = new URL(opts.url);
|
|
28
|
+
} else {
|
|
29
|
+
origin = globalThis?.location?.origin || "http://localhost:51515";
|
|
30
|
+
url = new URL(opts?.url || "", origin);
|
|
31
|
+
}
|
|
32
|
+
const isGet = method === "GET";
|
|
33
|
+
const oldSearchParams = url.searchParams;
|
|
34
|
+
if (isGet) {
|
|
35
|
+
let searchParams = new URLSearchParams({ ...Object.fromEntries(oldSearchParams), ...opts?.params, ...opts?.body });
|
|
36
|
+
url.search = searchParams.toString();
|
|
37
|
+
} else {
|
|
38
|
+
const params = {
|
|
39
|
+
...Object.fromEntries(oldSearchParams),
|
|
40
|
+
...opts.params
|
|
41
|
+
};
|
|
42
|
+
const searchParams = new URLSearchParams(params);
|
|
43
|
+
if (typeof opts.body === "object" && opts.body !== null) {
|
|
44
|
+
let body2 = opts.body || {};
|
|
45
|
+
if (!params.path && body2?.path) {
|
|
46
|
+
searchParams.set("path", body2.path);
|
|
47
|
+
if (body2?.key) {
|
|
48
|
+
searchParams.set("key", body2.key);
|
|
60
49
|
}
|
|
61
|
-
|
|
50
|
+
}
|
|
62
51
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
url.search = searchParams.toString();
|
|
53
|
+
}
|
|
54
|
+
let body = undefined;
|
|
55
|
+
if (isGet) {
|
|
56
|
+
body = undefined;
|
|
57
|
+
} else if (isPostFile) {
|
|
58
|
+
body = opts.body;
|
|
59
|
+
} else {
|
|
60
|
+
if (opts.body && typeof opts.body === "object" && !(opts.body instanceof FormData)) {
|
|
61
|
+
headers = {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
...headers
|
|
64
|
+
};
|
|
65
|
+
body = JSON.stringify(opts.body);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
}
|
|
68
|
+
return fetch(url, {
|
|
69
|
+
method: method.toUpperCase(),
|
|
70
|
+
signal,
|
|
71
|
+
body,
|
|
72
|
+
...overloadOpts,
|
|
73
|
+
headers
|
|
74
|
+
}).then(async (response) => {
|
|
75
|
+
const contentType = response.headers.get("Content-Type");
|
|
76
|
+
if (responseType === "blob") {
|
|
77
|
+
return await response.blob();
|
|
69
78
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
const isText = responseType === "text";
|
|
80
|
+
const isJson = contentType && contentType.includes("application/json");
|
|
81
|
+
if (isJson && !isText) {
|
|
82
|
+
return await response.json();
|
|
83
|
+
} else if (isTextForContentType(contentType)) {
|
|
84
|
+
return {
|
|
85
|
+
code: response.status,
|
|
86
|
+
status: response.status,
|
|
87
|
+
data: await response.text()
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
return response;
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const isJson = contentType && contentType.includes('application/json');
|
|
94
|
-
// 判断返回的数据类型
|
|
95
|
-
if (isJson && !isText) {
|
|
96
|
-
return await response.json(); // 解析为 JSON
|
|
97
|
-
}
|
|
98
|
-
else if (isTextForContentType(contentType)) {
|
|
99
|
-
return {
|
|
100
|
-
code: response.status,
|
|
101
|
-
status: response.status,
|
|
102
|
-
data: await response.text(), // 直接返回文本内容
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return response;
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
.catch((err) => {
|
|
110
|
-
if (err.name === 'AbortError') {
|
|
111
|
-
return {
|
|
112
|
-
code: 408,
|
|
113
|
-
message: '请求超时',
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
code: 500,
|
|
118
|
-
message: err.message || '网络错误',
|
|
119
|
-
};
|
|
120
|
-
})
|
|
121
|
-
.finally(() => {
|
|
122
|
-
clearTimeout(timer);
|
|
123
|
-
});
|
|
92
|
+
}).catch((err) => {
|
|
93
|
+
if (err.name === "AbortError") {
|
|
94
|
+
return {
|
|
95
|
+
code: 408,
|
|
96
|
+
message: "请求超时"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
code: 500,
|
|
101
|
+
message: err.message || "网络错误"
|
|
102
|
+
};
|
|
103
|
+
}).finally(() => {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
});
|
|
124
106
|
};
|
|
125
107
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
* 显示错误
|
|
136
|
-
* @param fn 错误处理函数
|
|
137
|
-
*/
|
|
138
|
-
res.showError = (fn) => {
|
|
139
|
-
if (!res.success && !res.noMsg) {
|
|
140
|
-
fn?.();
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
return res;
|
|
108
|
+
// src/query.ts
|
|
109
|
+
var setBaseResponse = (res) => {
|
|
110
|
+
res.success = res.code === 200;
|
|
111
|
+
res.showError = (fn) => {
|
|
112
|
+
if (!res.success && !res.noMsg) {
|
|
113
|
+
fn?.();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return res;
|
|
144
117
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
return result;
|
|
118
|
+
var wrapperError = ({ code, message }) => {
|
|
119
|
+
const result = {
|
|
120
|
+
code: code || 500,
|
|
121
|
+
success: false,
|
|
122
|
+
message: message || "api request error",
|
|
123
|
+
showError: (fn) => {},
|
|
124
|
+
noMsg: true
|
|
125
|
+
};
|
|
126
|
+
return result;
|
|
156
127
|
};
|
|
157
|
-
|
|
158
|
-
* const query = new Query();
|
|
159
|
-
* const res = await query.post({
|
|
160
|
-
* path: 'demo',
|
|
161
|
-
* key: '1',
|
|
162
|
-
* });
|
|
163
|
-
*
|
|
164
|
-
* U是参数 V是返回值
|
|
165
|
-
*/
|
|
128
|
+
|
|
166
129
|
class Query {
|
|
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
|
-
'Content-Type': 'application/json',
|
|
195
|
-
};
|
|
196
|
-
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
197
|
-
if (opts?.beforeRequest) {
|
|
198
|
-
this.beforeRequest = opts.beforeRequest;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
this.beforeRequest = async (opts) => {
|
|
202
|
-
const token = globalThis?.localStorage?.getItem('token');
|
|
203
|
-
if (token) {
|
|
204
|
-
opts.headers = {
|
|
205
|
-
...opts.headers,
|
|
206
|
-
Authorization: `Bearer ${token}`,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
return opts;
|
|
210
|
-
};
|
|
130
|
+
adapter;
|
|
131
|
+
url;
|
|
132
|
+
beforeRequest;
|
|
133
|
+
afterResponse;
|
|
134
|
+
headers;
|
|
135
|
+
timeout;
|
|
136
|
+
stop;
|
|
137
|
+
qws;
|
|
138
|
+
isClient = false;
|
|
139
|
+
constructor(opts) {
|
|
140
|
+
this.adapter = opts?.adapter || adapter;
|
|
141
|
+
const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
|
|
142
|
+
this.url = opts?.url || defaultURL;
|
|
143
|
+
this.headers = opts?.headers || {
|
|
144
|
+
"Content-Type": "application/json"
|
|
145
|
+
};
|
|
146
|
+
this.timeout = opts?.timeout || 60000 * 3;
|
|
147
|
+
if (opts?.beforeRequest) {
|
|
148
|
+
this.beforeRequest = opts.beforeRequest;
|
|
149
|
+
} else {
|
|
150
|
+
this.beforeRequest = async (opts2) => {
|
|
151
|
+
const token = globalThis?.localStorage?.getItem("token");
|
|
152
|
+
if (token) {
|
|
153
|
+
opts2.headers = {
|
|
154
|
+
...opts2.headers,
|
|
155
|
+
Authorization: `Bearer ${token}`
|
|
156
|
+
};
|
|
211
157
|
}
|
|
158
|
+
return opts2;
|
|
159
|
+
};
|
|
212
160
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
161
|
+
}
|
|
162
|
+
setQueryWs(qws) {
|
|
163
|
+
this.qws = qws;
|
|
164
|
+
}
|
|
165
|
+
setStop(stop) {
|
|
166
|
+
this.stop = stop;
|
|
167
|
+
}
|
|
168
|
+
async get(params, options) {
|
|
169
|
+
return this.post(params, options);
|
|
170
|
+
}
|
|
171
|
+
async post(body, options) {
|
|
172
|
+
const url = options?.url || this.url;
|
|
173
|
+
console.log("query post", url, body, options);
|
|
174
|
+
const { headers, adapter: adapter2, beforeRequest, afterResponse, timeout, ...rest } = options || {};
|
|
175
|
+
const _headers = { ...this.headers, ...headers };
|
|
176
|
+
const _adapter = adapter2 || this.adapter;
|
|
177
|
+
const _beforeRequest = beforeRequest || this.beforeRequest;
|
|
178
|
+
const _afterResponse = afterResponse || this.afterResponse;
|
|
179
|
+
const _timeout = timeout || this.timeout;
|
|
180
|
+
const req = {
|
|
181
|
+
url,
|
|
182
|
+
headers: _headers,
|
|
183
|
+
body,
|
|
184
|
+
timeout: _timeout,
|
|
185
|
+
...rest
|
|
186
|
+
};
|
|
187
|
+
try {
|
|
188
|
+
if (_beforeRequest) {
|
|
189
|
+
const res = await _beforeRequest(req);
|
|
190
|
+
if (res === false) {
|
|
191
|
+
return wrapperError({
|
|
192
|
+
code: 500,
|
|
193
|
+
message: "request is cancel",
|
|
194
|
+
req
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (e) {
|
|
199
|
+
console.error("request beforeFn error", e, req);
|
|
200
|
+
return wrapperError({
|
|
201
|
+
code: 500,
|
|
202
|
+
message: "api request beforeFn error",
|
|
203
|
+
req
|
|
204
|
+
});
|
|
221
205
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
206
|
+
if (this.stop && !options?.noStop) {
|
|
207
|
+
const that = this;
|
|
208
|
+
await new Promise((resolve) => {
|
|
209
|
+
let timer = 0;
|
|
210
|
+
const detect = setInterval(() => {
|
|
211
|
+
if (!that.stop) {
|
|
212
|
+
clearInterval(detect);
|
|
213
|
+
resolve(true);
|
|
214
|
+
}
|
|
215
|
+
timer++;
|
|
216
|
+
if (timer > 30) {
|
|
217
|
+
console.error("request stop: timeout", req.url, timer);
|
|
218
|
+
}
|
|
219
|
+
}, 1000);
|
|
220
|
+
});
|
|
232
221
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
async post(body, options) {
|
|
242
|
-
const url = options?.url || this.url;
|
|
243
|
-
const { headers, adapter, beforeRequest, afterResponse, timeout, ...rest } = options || {};
|
|
244
|
-
const _headers = { ...this.headers, ...headers };
|
|
245
|
-
const _adapter = adapter || this.adapter;
|
|
246
|
-
const _beforeRequest = beforeRequest || this.beforeRequest;
|
|
247
|
-
const _afterResponse = afterResponse || this.afterResponse;
|
|
248
|
-
const _timeout = timeout || this.timeout;
|
|
249
|
-
const req = {
|
|
250
|
-
url: url,
|
|
251
|
-
headers: _headers,
|
|
252
|
-
body,
|
|
253
|
-
timeout: _timeout,
|
|
254
|
-
...rest,
|
|
255
|
-
};
|
|
256
|
-
try {
|
|
257
|
-
if (_beforeRequest) {
|
|
258
|
-
const res = await _beforeRequest(req);
|
|
259
|
-
if (res === false) {
|
|
260
|
-
return wrapperError({
|
|
261
|
-
code: 500,
|
|
262
|
-
message: 'request is cancel',
|
|
263
|
-
// @ts-ignore
|
|
264
|
-
req: req,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}
|
|
222
|
+
return _adapter(req).then(async (res) => {
|
|
223
|
+
try {
|
|
224
|
+
if (_afterResponse) {
|
|
225
|
+
return await _afterResponse(res, {
|
|
226
|
+
req,
|
|
227
|
+
res,
|
|
228
|
+
fetch: adapter2
|
|
229
|
+
});
|
|
268
230
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const that = this;
|
|
277
|
-
await new Promise((resolve) => {
|
|
278
|
-
let timer = 0;
|
|
279
|
-
const detect = setInterval(() => {
|
|
280
|
-
if (!that.stop) {
|
|
281
|
-
clearInterval(detect);
|
|
282
|
-
resolve(true);
|
|
283
|
-
}
|
|
284
|
-
timer++;
|
|
285
|
-
if (timer > 30) {
|
|
286
|
-
console.error('request stop: timeout', req.url, timer);
|
|
287
|
-
}
|
|
288
|
-
}, 1000);
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
return _adapter(req).then(async (res) => {
|
|
292
|
-
try {
|
|
293
|
-
if (_afterResponse) {
|
|
294
|
-
return await _afterResponse(res, {
|
|
295
|
-
req,
|
|
296
|
-
res,
|
|
297
|
-
fetch: adapter,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return res;
|
|
301
|
-
}
|
|
302
|
-
catch (e) {
|
|
303
|
-
console.error('request afterFn error', e, req);
|
|
304
|
-
return wrapperError({
|
|
305
|
-
code: 500,
|
|
306
|
-
message: 'api request afterFn error'});
|
|
307
|
-
}
|
|
231
|
+
return res;
|
|
232
|
+
} catch (e) {
|
|
233
|
+
console.error("request afterFn error", e, req);
|
|
234
|
+
return wrapperError({
|
|
235
|
+
code: 500,
|
|
236
|
+
message: "api request afterFn error",
|
|
237
|
+
req
|
|
308
238
|
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
before(fn) {
|
|
243
|
+
this.beforeRequest = fn;
|
|
244
|
+
}
|
|
245
|
+
after(fn) {
|
|
246
|
+
this.afterResponse = fn;
|
|
247
|
+
}
|
|
248
|
+
async fetchText(urlOrOptions, options) {
|
|
249
|
+
let _options = { ...options };
|
|
250
|
+
if (typeof urlOrOptions === "string" && !_options.url) {
|
|
251
|
+
_options.url = urlOrOptions;
|
|
309
252
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
* @param fn 处理函数
|
|
313
|
-
*/
|
|
314
|
-
before(fn) {
|
|
315
|
-
this.beforeRequest = fn;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* 设置请求后处理,设置请求后处理函数
|
|
319
|
-
* @param fn 处理函数
|
|
320
|
-
*/
|
|
321
|
-
after(fn) {
|
|
322
|
-
this.afterResponse = fn;
|
|
253
|
+
if (typeof urlOrOptions === "object") {
|
|
254
|
+
_options = { ...urlOrOptions, ..._options };
|
|
323
255
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
...(_options?.headers || {}),
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
if (res && !res.code) {
|
|
341
|
-
return {
|
|
342
|
-
code: 200,
|
|
343
|
-
data: res,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
return res;
|
|
256
|
+
const res = await adapter({
|
|
257
|
+
method: "GET",
|
|
258
|
+
..._options,
|
|
259
|
+
headers: {
|
|
260
|
+
...this.headers,
|
|
261
|
+
..._options?.headers || {}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
if (res && !res.code) {
|
|
265
|
+
return {
|
|
266
|
+
code: 200,
|
|
267
|
+
data: res
|
|
268
|
+
};
|
|
347
269
|
}
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
348
272
|
}
|
|
349
273
|
class BaseQuery {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.query = opts?.query;
|
|
358
|
-
}
|
|
359
|
-
if (opts.queryDefine) {
|
|
360
|
-
this.queryDefine = opts.queryDefine;
|
|
361
|
-
this.queryDefine.query = this.query;
|
|
362
|
-
}
|
|
274
|
+
query;
|
|
275
|
+
queryDefine;
|
|
276
|
+
constructor(opts) {
|
|
277
|
+
if (opts?.clientQuery) {
|
|
278
|
+
this.query = opts.clientQuery;
|
|
279
|
+
} else {
|
|
280
|
+
this.query = opts?.query;
|
|
363
281
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
post(data, options) {
|
|
368
|
-
return this.query.post(data, options);
|
|
369
|
-
}
|
|
370
|
-
get(data, options) {
|
|
371
|
-
return this.query.get(data, options);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* @deprecated
|
|
376
|
-
* 前端调用后端QueryRouter, 默认路径 /client/router
|
|
377
|
-
*/
|
|
378
|
-
class ClientQuery extends Query {
|
|
379
|
-
constructor(opts) {
|
|
380
|
-
super({ ...opts, url: opts?.url || '/client/router' });
|
|
282
|
+
if (opts.queryDefine) {
|
|
283
|
+
this.queryDefine = opts.queryDefine;
|
|
284
|
+
this.queryDefine.query = this.query;
|
|
381
285
|
}
|
|
286
|
+
}
|
|
287
|
+
get chain() {
|
|
288
|
+
return this.queryDefine.queryChain;
|
|
289
|
+
}
|
|
290
|
+
post(data, options) {
|
|
291
|
+
return this.query.post(data, options);
|
|
292
|
+
}
|
|
293
|
+
get(data, options) {
|
|
294
|
+
return this.query.get(data, options);
|
|
295
|
+
}
|
|
382
296
|
}
|
|
383
|
-
|
|
384
|
-
|
|
297
|
+
export {
|
|
298
|
+
wrapperError,
|
|
299
|
+
setBaseResponse,
|
|
300
|
+
adapter,
|
|
301
|
+
Query,
|
|
302
|
+
BaseQuery
|
|
303
|
+
};
|