@kevisual/query 0.0.25 → 0.0.27
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.d.ts +4 -3
- package/dist/query-adapter.js +20 -7
- package/dist/query-ai.d.ts +6 -2
- package/dist/query-ai.js +4424 -4363
- package/dist/query-browser.d.ts +5 -3
- package/dist/query-browser.js +20 -7
- package/dist/query.d.ts +5 -3
- package/dist/query.js +20 -7
- package/package.json +1 -1
package/dist/query-browser.d.ts
CHANGED
|
@@ -5,10 +5,11 @@ type Method = (typeof methods)[number];
|
|
|
5
5
|
type AdapterOpts = {
|
|
6
6
|
url?: string;
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
|
-
body?: Record<string, any
|
|
8
|
+
body?: Record<string, any> | FormData;
|
|
9
9
|
timeout?: number;
|
|
10
10
|
method?: Method;
|
|
11
11
|
isBlob?: boolean;
|
|
12
|
+
isPostFile?: boolean;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
@@ -16,7 +17,7 @@ type AdapterOpts = {
|
|
|
16
17
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
17
18
|
* @returns
|
|
18
19
|
*/
|
|
19
|
-
declare const adapter: (opts
|
|
20
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
20
21
|
|
|
21
22
|
type QueryWsStore = {
|
|
22
23
|
connected: boolean;
|
|
@@ -94,10 +95,11 @@ type Fn = (opts: {
|
|
|
94
95
|
type QueryOpts$1 = {
|
|
95
96
|
url?: string;
|
|
96
97
|
headers?: Record<string, string>;
|
|
97
|
-
body?: Record<string, any
|
|
98
|
+
body?: Record<string, any> | FormData;
|
|
98
99
|
timeout?: number;
|
|
99
100
|
method?: Method;
|
|
100
101
|
isBlob?: boolean;
|
|
102
|
+
isPostFile?: boolean;
|
|
101
103
|
adapter?: typeof adapter;
|
|
102
104
|
[key: string]: any;
|
|
103
105
|
};
|
package/dist/query-browser.js
CHANGED
|
@@ -10,15 +10,17 @@ const isTextForContentType = (contentType) => {
|
|
|
10
10
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
const adapter = async (opts, overloadOpts) => {
|
|
13
|
+
const adapter = async (opts = {}, overloadOpts) => {
|
|
14
14
|
const controller = new AbortController();
|
|
15
15
|
const signal = controller.signal;
|
|
16
16
|
const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
|
|
17
|
+
const isPostFile = opts.isPostFile || false; // 是否为文件上传
|
|
17
18
|
const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
18
19
|
const timer = setTimeout(() => {
|
|
19
20
|
controller.abort();
|
|
20
21
|
}, timeout);
|
|
21
|
-
let method = overloadOpts?.method || opts
|
|
22
|
+
let method = overloadOpts?.method || opts?.method || 'POST';
|
|
23
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
22
24
|
let origin = '';
|
|
23
25
|
let url;
|
|
24
26
|
if (opts?.url?.startsWith('http')) {
|
|
@@ -32,15 +34,26 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
32
34
|
if (isGet) {
|
|
33
35
|
url.search = new URLSearchParams(opts.body).toString();
|
|
34
36
|
}
|
|
37
|
+
let body = undefined;
|
|
38
|
+
if (isGet) {
|
|
39
|
+
body = undefined;
|
|
40
|
+
}
|
|
41
|
+
else if (isPostFile) {
|
|
42
|
+
body = opts.body; // 如果是文件上传,直接使用 FormData
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
headers = {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
...headers,
|
|
48
|
+
};
|
|
49
|
+
body = JSON.stringify(opts.body); // 否则将对象转换为 JSON 字符串
|
|
50
|
+
}
|
|
35
51
|
return fetch(url, {
|
|
36
52
|
method: method.toUpperCase(),
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/json',
|
|
39
|
-
...opts.headers,
|
|
40
|
-
},
|
|
41
53
|
signal,
|
|
54
|
+
body: body,
|
|
42
55
|
...overloadOpts,
|
|
43
|
-
|
|
56
|
+
headers: headers,
|
|
44
57
|
})
|
|
45
58
|
.then(async (response) => {
|
|
46
59
|
// 获取 Content-Type 头部信息
|
package/dist/query.d.ts
CHANGED
|
@@ -5,10 +5,11 @@ type Method = (typeof methods)[number];
|
|
|
5
5
|
type AdapterOpts = {
|
|
6
6
|
url?: string;
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
|
-
body?: Record<string, any
|
|
8
|
+
body?: Record<string, any> | FormData;
|
|
9
9
|
timeout?: number;
|
|
10
10
|
method?: Method;
|
|
11
11
|
isBlob?: boolean;
|
|
12
|
+
isPostFile?: boolean;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
@@ -16,7 +17,7 @@ type AdapterOpts = {
|
|
|
16
17
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
17
18
|
* @returns
|
|
18
19
|
*/
|
|
19
|
-
declare const adapter: (opts
|
|
20
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
20
21
|
|
|
21
22
|
type QueryWsStore = {
|
|
22
23
|
connected: boolean;
|
|
@@ -94,10 +95,11 @@ type Fn = (opts: {
|
|
|
94
95
|
type QueryOpts = {
|
|
95
96
|
url?: string;
|
|
96
97
|
headers?: Record<string, string>;
|
|
97
|
-
body?: Record<string, any
|
|
98
|
+
body?: Record<string, any> | FormData;
|
|
98
99
|
timeout?: number;
|
|
99
100
|
method?: Method;
|
|
100
101
|
isBlob?: boolean;
|
|
102
|
+
isPostFile?: boolean;
|
|
101
103
|
adapter?: typeof adapter;
|
|
102
104
|
[key: string]: any;
|
|
103
105
|
};
|
package/dist/query.js
CHANGED
|
@@ -10,15 +10,17 @@ const isTextForContentType = (contentType) => {
|
|
|
10
10
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
const adapter = async (opts, overloadOpts) => {
|
|
13
|
+
const adapter = async (opts = {}, overloadOpts) => {
|
|
14
14
|
const controller = new AbortController();
|
|
15
15
|
const signal = controller.signal;
|
|
16
16
|
const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
|
|
17
|
+
const isPostFile = opts.isPostFile || false; // 是否为文件上传
|
|
17
18
|
const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
18
19
|
const timer = setTimeout(() => {
|
|
19
20
|
controller.abort();
|
|
20
21
|
}, timeout);
|
|
21
|
-
let method = overloadOpts?.method || opts
|
|
22
|
+
let method = overloadOpts?.method || opts?.method || 'POST';
|
|
23
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
22
24
|
let origin = '';
|
|
23
25
|
let url;
|
|
24
26
|
if (opts?.url?.startsWith('http')) {
|
|
@@ -32,15 +34,26 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
32
34
|
if (isGet) {
|
|
33
35
|
url.search = new URLSearchParams(opts.body).toString();
|
|
34
36
|
}
|
|
37
|
+
let body = undefined;
|
|
38
|
+
if (isGet) {
|
|
39
|
+
body = undefined;
|
|
40
|
+
}
|
|
41
|
+
else if (isPostFile) {
|
|
42
|
+
body = opts.body; // 如果是文件上传,直接使用 FormData
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
headers = {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
...headers,
|
|
48
|
+
};
|
|
49
|
+
body = JSON.stringify(opts.body); // 否则将对象转换为 JSON 字符串
|
|
50
|
+
}
|
|
35
51
|
return fetch(url, {
|
|
36
52
|
method: method.toUpperCase(),
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/json',
|
|
39
|
-
...opts.headers,
|
|
40
|
-
},
|
|
41
53
|
signal,
|
|
54
|
+
body: body,
|
|
42
55
|
...overloadOpts,
|
|
43
|
-
|
|
56
|
+
headers: headers,
|
|
44
57
|
})
|
|
45
58
|
.then(async (response) => {
|
|
46
59
|
// 获取 Content-Type 头部信息
|