@kevisual/query 0.0.9-alpha.2 → 0.0.9
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-ai.d.ts +3 -1
- package/dist/query-ai.js +1129 -673
- package/dist/query-browser.d.ts +40 -6
- package/dist/query-browser.js +26 -2
- package/dist/query-ws.d.ts +2 -1
- package/dist/query.d.ts +39 -5
- package/dist/query.js +26 -2
- package/package.json +5 -5
package/dist/query-browser.d.ts
CHANGED
|
@@ -50,6 +50,11 @@ declare class QueryWs {
|
|
|
50
50
|
getOpen(): boolean;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* 请求前处理函数
|
|
55
|
+
* @param opts 请求配置
|
|
56
|
+
* @returns 请求配置
|
|
57
|
+
*/
|
|
53
58
|
type Fn = (opts: {
|
|
54
59
|
url?: string;
|
|
55
60
|
headers?: Record<string, string>;
|
|
@@ -74,10 +79,14 @@ type Result<S = any> = {
|
|
|
74
79
|
data?: S;
|
|
75
80
|
message?: string;
|
|
76
81
|
success: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 是否不返回 message
|
|
84
|
+
*/
|
|
85
|
+
noMsg?: boolean;
|
|
77
86
|
};
|
|
78
87
|
type DataOpts = Partial<QueryOpts$1> & {
|
|
79
88
|
beforeRequest?: Fn;
|
|
80
|
-
afterResponse?: (result: Result) => Promise<
|
|
89
|
+
afterResponse?: <S, U = S>(result: Result<S>) => Promise<U>;
|
|
81
90
|
};
|
|
82
91
|
/**
|
|
83
92
|
* const query = new Query();
|
|
@@ -88,7 +97,7 @@ type DataOpts = Partial<QueryOpts$1> & {
|
|
|
88
97
|
*
|
|
89
98
|
* U是参数 V是返回值
|
|
90
99
|
*/
|
|
91
|
-
declare class Query<
|
|
100
|
+
declare class Query<R = any> {
|
|
92
101
|
adapter: typeof adapter;
|
|
93
102
|
url: string;
|
|
94
103
|
beforeRequest?: Fn;
|
|
@@ -96,9 +105,33 @@ declare class Query<U = any, V = any> {
|
|
|
96
105
|
headers?: Record<string, string>;
|
|
97
106
|
timeout?: number;
|
|
98
107
|
constructor(opts?: QueryOpts$1);
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
/**
|
|
109
|
+
* 发送 get 请求,转到 post 请求
|
|
110
|
+
* T是请求类型自定义
|
|
111
|
+
* S是返回类型自定义
|
|
112
|
+
* @param params 请求参数
|
|
113
|
+
* @param options 请求配置
|
|
114
|
+
* @returns 请求结果
|
|
115
|
+
*/
|
|
116
|
+
get<T = any, S = any>(params: Record<string, any> & Data & T, options?: DataOpts): Promise<Result<R & S>>;
|
|
117
|
+
/**
|
|
118
|
+
* 发送 post 请求
|
|
119
|
+
* T是请求类型自定义
|
|
120
|
+
* S是返回类型自定义
|
|
121
|
+
* @param body 请求体
|
|
122
|
+
* @param options 请求配置
|
|
123
|
+
* @returns 请求结果
|
|
124
|
+
*/
|
|
125
|
+
post<T = any, S = any>(body: Record<string, any> & Data & T, options?: DataOpts): Promise<Result<R & S>>;
|
|
126
|
+
/**
|
|
127
|
+
* 请求前处理,设置请求前处理函数
|
|
128
|
+
* @param fn 处理函数
|
|
129
|
+
*/
|
|
101
130
|
before(fn: Fn): void;
|
|
131
|
+
/**
|
|
132
|
+
* 请求后处理,设置请求后处理函数
|
|
133
|
+
* @param fn 处理函数
|
|
134
|
+
*/
|
|
102
135
|
after(fn: (result: Result) => Promise<any>): void;
|
|
103
136
|
}
|
|
104
137
|
|
|
@@ -111,7 +144,7 @@ type QueryOpts = {
|
|
|
111
144
|
/**
|
|
112
145
|
* 前端调用后端QueryRouter
|
|
113
146
|
*/
|
|
114
|
-
declare class QueryClient<
|
|
147
|
+
declare class QueryClient<R = any> extends Query<R> {
|
|
115
148
|
tokenName: string;
|
|
116
149
|
storage: Storage;
|
|
117
150
|
token: string;
|
|
@@ -127,4 +160,5 @@ declare class QueryClient<U = any, V = any> extends Query<U, V> {
|
|
|
127
160
|
removeToken(): void;
|
|
128
161
|
}
|
|
129
162
|
|
|
130
|
-
export { Query, QueryClient,
|
|
163
|
+
export { Query, QueryClient, QueryWs, adapter };
|
|
164
|
+
export type { QueryOpts, QueryWsOpts };
|
package/dist/query-browser.js
CHANGED
|
@@ -245,9 +245,25 @@ class Query {
|
|
|
245
245
|
};
|
|
246
246
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
247
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* 发送 get 请求,转到 post 请求
|
|
250
|
+
* T是请求类型自定义
|
|
251
|
+
* S是返回类型自定义
|
|
252
|
+
* @param params 请求参数
|
|
253
|
+
* @param options 请求配置
|
|
254
|
+
* @returns 请求结果
|
|
255
|
+
*/
|
|
248
256
|
async get(params, options) {
|
|
249
257
|
return this.post(params, options);
|
|
250
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* 发送 post 请求
|
|
261
|
+
* T是请求类型自定义
|
|
262
|
+
* S是返回类型自定义
|
|
263
|
+
* @param body 请求体
|
|
264
|
+
* @param options 请求配置
|
|
265
|
+
* @returns 请求结果
|
|
266
|
+
*/
|
|
251
267
|
async post(body, options) {
|
|
252
268
|
const url = options?.url || this.url;
|
|
253
269
|
const headers = { ...this.headers, ...options?.headers };
|
|
@@ -267,7 +283,7 @@ class Query {
|
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
285
|
catch (e) {
|
|
270
|
-
console.error(e);
|
|
286
|
+
console.error('request beforeFn error', e, req);
|
|
271
287
|
return {
|
|
272
288
|
code: 500,
|
|
273
289
|
success: false,
|
|
@@ -283,7 +299,7 @@ class Query {
|
|
|
283
299
|
return res;
|
|
284
300
|
}
|
|
285
301
|
catch (e) {
|
|
286
|
-
console.error(e);
|
|
302
|
+
console.error('request error', e, req);
|
|
287
303
|
return {
|
|
288
304
|
code: 500,
|
|
289
305
|
success: false,
|
|
@@ -292,9 +308,17 @@ class Query {
|
|
|
292
308
|
}
|
|
293
309
|
});
|
|
294
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* 请求前处理,设置请求前处理函数
|
|
313
|
+
* @param fn 处理函数
|
|
314
|
+
*/
|
|
295
315
|
before(fn) {
|
|
296
316
|
this.beforeRequest = fn;
|
|
297
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* 请求后处理,设置请求后处理函数
|
|
320
|
+
* @param fn 处理函数
|
|
321
|
+
*/
|
|
298
322
|
after(fn) {
|
|
299
323
|
this.afterResponse = fn;
|
|
300
324
|
}
|
package/dist/query-ws.d.ts
CHANGED
|
@@ -45,4 +45,5 @@ declare class QueryWs {
|
|
|
45
45
|
getOpen(): boolean;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export {
|
|
48
|
+
export { QueryWs };
|
|
49
|
+
export type { QuerySelectState, QueryWsOpts, QueryWsStoreListener, WsOnMessage, WsSend };
|
package/dist/query.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ type AdapterOpts = {
|
|
|
12
12
|
*/
|
|
13
13
|
declare const adapter: (opts: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 请求前处理函数
|
|
17
|
+
* @param opts 请求配置
|
|
18
|
+
* @returns 请求配置
|
|
19
|
+
*/
|
|
15
20
|
type Fn = (opts: {
|
|
16
21
|
url?: string;
|
|
17
22
|
headers?: Record<string, string>;
|
|
@@ -36,10 +41,14 @@ type Result<S = any> = {
|
|
|
36
41
|
data?: S;
|
|
37
42
|
message?: string;
|
|
38
43
|
success: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 是否不返回 message
|
|
46
|
+
*/
|
|
47
|
+
noMsg?: boolean;
|
|
39
48
|
};
|
|
40
49
|
type DataOpts = Partial<QueryOpts> & {
|
|
41
50
|
beforeRequest?: Fn;
|
|
42
|
-
afterResponse?: (result: Result) => Promise<
|
|
51
|
+
afterResponse?: <S, U = S>(result: Result<S>) => Promise<U>;
|
|
43
52
|
};
|
|
44
53
|
/**
|
|
45
54
|
* const query = new Query();
|
|
@@ -50,7 +59,7 @@ type DataOpts = Partial<QueryOpts> & {
|
|
|
50
59
|
*
|
|
51
60
|
* U是参数 V是返回值
|
|
52
61
|
*/
|
|
53
|
-
declare class Query<
|
|
62
|
+
declare class Query<R = any> {
|
|
54
63
|
adapter: typeof adapter;
|
|
55
64
|
url: string;
|
|
56
65
|
beforeRequest?: Fn;
|
|
@@ -58,10 +67,35 @@ declare class Query<U = any, V = any> {
|
|
|
58
67
|
headers?: Record<string, string>;
|
|
59
68
|
timeout?: number;
|
|
60
69
|
constructor(opts?: QueryOpts);
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
/**
|
|
71
|
+
* 发送 get 请求,转到 post 请求
|
|
72
|
+
* T是请求类型自定义
|
|
73
|
+
* S是返回类型自定义
|
|
74
|
+
* @param params 请求参数
|
|
75
|
+
* @param options 请求配置
|
|
76
|
+
* @returns 请求结果
|
|
77
|
+
*/
|
|
78
|
+
get<T = any, S = any>(params: Record<string, any> & Data & T, options?: DataOpts): Promise<Result<R & S>>;
|
|
79
|
+
/**
|
|
80
|
+
* 发送 post 请求
|
|
81
|
+
* T是请求类型自定义
|
|
82
|
+
* S是返回类型自定义
|
|
83
|
+
* @param body 请求体
|
|
84
|
+
* @param options 请求配置
|
|
85
|
+
* @returns 请求结果
|
|
86
|
+
*/
|
|
87
|
+
post<T = any, S = any>(body: Record<string, any> & Data & T, options?: DataOpts): Promise<Result<R & S>>;
|
|
88
|
+
/**
|
|
89
|
+
* 请求前处理,设置请求前处理函数
|
|
90
|
+
* @param fn 处理函数
|
|
91
|
+
*/
|
|
63
92
|
before(fn: Fn): void;
|
|
93
|
+
/**
|
|
94
|
+
* 请求后处理,设置请求后处理函数
|
|
95
|
+
* @param fn 处理函数
|
|
96
|
+
*/
|
|
64
97
|
after(fn: (result: Result) => Promise<any>): void;
|
|
65
98
|
}
|
|
66
99
|
|
|
67
|
-
export { Query,
|
|
100
|
+
export { Query, adapter };
|
|
101
|
+
export type { QueryOpts };
|
package/dist/query.js
CHANGED
|
@@ -70,9 +70,25 @@ class Query {
|
|
|
70
70
|
};
|
|
71
71
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* 发送 get 请求,转到 post 请求
|
|
75
|
+
* T是请求类型自定义
|
|
76
|
+
* S是返回类型自定义
|
|
77
|
+
* @param params 请求参数
|
|
78
|
+
* @param options 请求配置
|
|
79
|
+
* @returns 请求结果
|
|
80
|
+
*/
|
|
73
81
|
async get(params, options) {
|
|
74
82
|
return this.post(params, options);
|
|
75
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 发送 post 请求
|
|
86
|
+
* T是请求类型自定义
|
|
87
|
+
* S是返回类型自定义
|
|
88
|
+
* @param body 请求体
|
|
89
|
+
* @param options 请求配置
|
|
90
|
+
* @returns 请求结果
|
|
91
|
+
*/
|
|
76
92
|
async post(body, options) {
|
|
77
93
|
const url = options?.url || this.url;
|
|
78
94
|
const headers = { ...this.headers, ...options?.headers };
|
|
@@ -92,7 +108,7 @@ class Query {
|
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
catch (e) {
|
|
95
|
-
console.error(e);
|
|
111
|
+
console.error('request beforeFn error', e, req);
|
|
96
112
|
return {
|
|
97
113
|
code: 500,
|
|
98
114
|
success: false,
|
|
@@ -108,7 +124,7 @@ class Query {
|
|
|
108
124
|
return res;
|
|
109
125
|
}
|
|
110
126
|
catch (e) {
|
|
111
|
-
console.error(e);
|
|
127
|
+
console.error('request error', e, req);
|
|
112
128
|
return {
|
|
113
129
|
code: 500,
|
|
114
130
|
success: false,
|
|
@@ -117,9 +133,17 @@ class Query {
|
|
|
117
133
|
}
|
|
118
134
|
});
|
|
119
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 请求前处理,设置请求前处理函数
|
|
138
|
+
* @param fn 处理函数
|
|
139
|
+
*/
|
|
120
140
|
before(fn) {
|
|
121
141
|
this.beforeRequest = fn;
|
|
122
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* 请求后处理,设置请求后处理函数
|
|
145
|
+
* @param fn 处理函数
|
|
146
|
+
*/
|
|
123
147
|
after(fn) {
|
|
124
148
|
this.afterResponse = fn;
|
|
125
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/query",
|
|
3
|
-
"version": "0.0.9
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"description": "",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
25
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
26
26
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
27
|
-
"rollup": "^4.
|
|
28
|
-
"rollup-plugin-dts": "^6.
|
|
27
|
+
"rollup": "^4.36.0",
|
|
28
|
+
"rollup-plugin-dts": "^6.2.0",
|
|
29
29
|
"ts-node": "^10.9.2",
|
|
30
30
|
"tslib": "^2.8.1",
|
|
31
31
|
"typescript": "^5.8.2",
|
|
@@ -58,6 +58,6 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"openai": "^4.
|
|
61
|
+
"openai": "^4.88.0"
|
|
62
62
|
}
|
|
63
63
|
}
|