@kevisual/query 0.0.31 → 0.0.32
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-browser.d.ts +3 -14
- package/dist/query-browser.js +8 -21
- package/dist/query.d.ts +8 -15
- package/dist/query.js +8 -2
- package/package.json +1 -1
package/dist/query-browser.d.ts
CHANGED
|
@@ -118,23 +118,11 @@ type Data = {
|
|
|
118
118
|
payload?: Record<string, any>;
|
|
119
119
|
[key: string]: any;
|
|
120
120
|
};
|
|
121
|
-
type Result<S = any> = {
|
|
121
|
+
type Result<S = any, U = {}> = {
|
|
122
122
|
code: number;
|
|
123
123
|
data?: S;
|
|
124
124
|
message?: string;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 是否不返回 message
|
|
128
|
-
*/
|
|
129
|
-
noMsg?: boolean;
|
|
130
|
-
/**
|
|
131
|
-
* 显示错误, 当 handle的信息被处理的时候,如果不是success,同时自己设置了noMsg,那么就不显示错误信息了,因为被处理。
|
|
132
|
-
*
|
|
133
|
-
* 日常: fetch().then(res=>if(res.sucess){message.error('error')})的时候,比如401被处理过了,就不再提示401错误了。
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
showError: (fn?: () => void) => void;
|
|
137
|
-
};
|
|
125
|
+
} & U;
|
|
138
126
|
type DataOpts = Partial<QueryOpts$1> & {
|
|
139
127
|
beforeRequest?: Fn;
|
|
140
128
|
afterResponse?: <S = any>(result: Result<S>, ctx?: {
|
|
@@ -221,6 +209,7 @@ declare class Query {
|
|
|
221
209
|
fetchText(urlOrOptions?: string | QueryOpts$1, options?: QueryOpts$1): Promise<Result<any>>;
|
|
222
210
|
}
|
|
223
211
|
|
|
212
|
+
/** @deprecated */
|
|
224
213
|
declare class BaseQuery<T extends Query = Query, R extends {
|
|
225
214
|
queryChain?: any;
|
|
226
215
|
query?: any;
|
package/dist/query-browser.js
CHANGED
|
@@ -318,25 +318,6 @@ class QueryWs {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
/**
|
|
322
|
-
* 设置基础响应, 设置 success 和 showError,
|
|
323
|
-
* success 是 code 是否等于 200
|
|
324
|
-
* showError 是 如果 success 为 false 且 noMsg 为 false, 则调用 showError
|
|
325
|
-
* @param res 响应
|
|
326
|
-
*/
|
|
327
|
-
const setBaseResponse = (res) => {
|
|
328
|
-
res.success = res.code === 200;
|
|
329
|
-
/**
|
|
330
|
-
* 显示错误
|
|
331
|
-
* @param fn 错误处理函数
|
|
332
|
-
*/
|
|
333
|
-
res.showError = (fn) => {
|
|
334
|
-
if (!res.success && !res.noMsg) {
|
|
335
|
-
fn?.();
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
return res;
|
|
339
|
-
};
|
|
340
321
|
const wrapperError = ({ code, message }) => {
|
|
341
322
|
const result = {
|
|
342
323
|
code: code || 500,
|
|
@@ -465,7 +446,6 @@ class Query {
|
|
|
465
446
|
}
|
|
466
447
|
return _adapter(req).then(async (res) => {
|
|
467
448
|
try {
|
|
468
|
-
setBaseResponse(res);
|
|
469
449
|
if (_afterResponse) {
|
|
470
450
|
return await _afterResponse(res, {
|
|
471
451
|
req,
|
|
@@ -513,9 +493,16 @@ class Query {
|
|
|
513
493
|
...(_options?.headers || {}),
|
|
514
494
|
},
|
|
515
495
|
});
|
|
516
|
-
|
|
496
|
+
if (res && !res.code) {
|
|
497
|
+
return {
|
|
498
|
+
code: 200,
|
|
499
|
+
data: res,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
return res;
|
|
517
503
|
}
|
|
518
504
|
}
|
|
505
|
+
/** @deprecated */
|
|
519
506
|
class BaseQuery {
|
|
520
507
|
query;
|
|
521
508
|
queryDefine;
|
package/dist/query.d.ts
CHANGED
|
@@ -118,23 +118,11 @@ type Data = {
|
|
|
118
118
|
payload?: Record<string, any>;
|
|
119
119
|
[key: string]: any;
|
|
120
120
|
};
|
|
121
|
-
type Result<S = any> = {
|
|
121
|
+
type Result<S = any, U = {}> = {
|
|
122
122
|
code: number;
|
|
123
123
|
data?: S;
|
|
124
124
|
message?: string;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 是否不返回 message
|
|
128
|
-
*/
|
|
129
|
-
noMsg?: boolean;
|
|
130
|
-
/**
|
|
131
|
-
* 显示错误, 当 handle的信息被处理的时候,如果不是success,同时自己设置了noMsg,那么就不显示错误信息了,因为被处理。
|
|
132
|
-
*
|
|
133
|
-
* 日常: fetch().then(res=>if(res.sucess){message.error('error')})的时候,比如401被处理过了,就不再提示401错误了。
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
showError: (fn?: () => void) => void;
|
|
137
|
-
};
|
|
125
|
+
} & U;
|
|
138
126
|
type DataOpts = Partial<QueryOpts> & {
|
|
139
127
|
beforeRequest?: Fn;
|
|
140
128
|
afterResponse?: <S = any>(result: Result<S>, ctx?: {
|
|
@@ -153,7 +141,11 @@ type DataOpts = Partial<QueryOpts> & {
|
|
|
153
141
|
* showError 是 如果 success 为 false 且 noMsg 为 false, 则调用 showError
|
|
154
142
|
* @param res 响应
|
|
155
143
|
*/
|
|
156
|
-
declare const setBaseResponse: (res: Partial<Result
|
|
144
|
+
declare const setBaseResponse: (res: Partial<Result & {
|
|
145
|
+
success?: boolean;
|
|
146
|
+
showError?: (fn?: () => void) => void;
|
|
147
|
+
noMsg?: boolean;
|
|
148
|
+
}>) => Result;
|
|
157
149
|
declare const wrapperError: ({ code, message }: {
|
|
158
150
|
code?: number;
|
|
159
151
|
message?: string;
|
|
@@ -228,6 +220,7 @@ declare class Query {
|
|
|
228
220
|
fetchText(urlOrOptions?: string | QueryOpts, options?: QueryOpts): Promise<Result<any>>;
|
|
229
221
|
}
|
|
230
222
|
|
|
223
|
+
/** @deprecated */
|
|
231
224
|
declare class BaseQuery<T extends Query = Query, R extends {
|
|
232
225
|
queryChain?: any;
|
|
233
226
|
query?: any;
|
package/dist/query.js
CHANGED
|
@@ -249,7 +249,6 @@ class Query {
|
|
|
249
249
|
}
|
|
250
250
|
return _adapter(req).then(async (res) => {
|
|
251
251
|
try {
|
|
252
|
-
setBaseResponse(res);
|
|
253
252
|
if (_afterResponse) {
|
|
254
253
|
return await _afterResponse(res, {
|
|
255
254
|
req,
|
|
@@ -297,9 +296,16 @@ class Query {
|
|
|
297
296
|
...(_options?.headers || {}),
|
|
298
297
|
},
|
|
299
298
|
});
|
|
300
|
-
|
|
299
|
+
if (res && !res.code) {
|
|
300
|
+
return {
|
|
301
|
+
code: 200,
|
|
302
|
+
data: res,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return res;
|
|
301
306
|
}
|
|
302
307
|
}
|
|
308
|
+
/** @deprecated */
|
|
303
309
|
class BaseQuery {
|
|
304
310
|
query;
|
|
305
311
|
queryDefine;
|