@kevisual/query 0.0.26 → 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 +2 -2
- package/dist/query-adapter.js +9 -7
- package/dist/query-browser.d.ts +1 -1
- package/dist/query-browser.js +9 -7
- package/dist/query.d.ts +1 -1
- package/dist/query.js +9 -7
- package/package.json +1 -1
package/dist/query-adapter.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ declare const isTextForContentType: (contentType: string | null) => boolean;
|
|
|
16
16
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
|
-
declare const adapter: (opts
|
|
19
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
20
20
|
/**
|
|
21
21
|
* adapter
|
|
22
22
|
*/
|
|
23
|
-
declare const queryFetch: (opts
|
|
23
|
+
declare const queryFetch: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
24
24
|
|
|
25
25
|
export { adapter, isTextForContentType, methods, queryFetch };
|
|
26
26
|
export type { AdapterOpts, Method };
|
package/dist/query-adapter.js
CHANGED
|
@@ -11,7 +11,7 @@ const isTextForContentType = (contentType) => {
|
|
|
11
11
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
const adapter = async (opts, overloadOpts) => {
|
|
14
|
+
const adapter = async (opts = {}, overloadOpts) => {
|
|
15
15
|
const controller = new AbortController();
|
|
16
16
|
const signal = controller.signal;
|
|
17
17
|
const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
|
|
@@ -20,7 +20,8 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
20
20
|
const timer = setTimeout(() => {
|
|
21
21
|
controller.abort();
|
|
22
22
|
}, timeout);
|
|
23
|
-
let method = overloadOpts?.method || opts
|
|
23
|
+
let method = overloadOpts?.method || opts?.method || 'POST';
|
|
24
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
24
25
|
let origin = '';
|
|
25
26
|
let url;
|
|
26
27
|
if (opts?.url?.startsWith('http')) {
|
|
@@ -42,17 +43,18 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
42
43
|
body = opts.body; // 如果是文件上传,直接使用 FormData
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
46
|
+
headers = {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
...headers,
|
|
49
|
+
};
|
|
45
50
|
body = JSON.stringify(opts.body); // 否则将对象转换为 JSON 字符串
|
|
46
51
|
}
|
|
47
52
|
return fetch(url, {
|
|
48
53
|
method: method.toUpperCase(),
|
|
49
|
-
headers: {
|
|
50
|
-
'Content-Type': 'application/json',
|
|
51
|
-
...opts.headers,
|
|
52
|
-
},
|
|
53
54
|
signal,
|
|
54
|
-
...overloadOpts,
|
|
55
55
|
body: body,
|
|
56
|
+
...overloadOpts,
|
|
57
|
+
headers: headers,
|
|
56
58
|
})
|
|
57
59
|
.then(async (response) => {
|
|
58
60
|
// 获取 Content-Type 头部信息
|
package/dist/query-browser.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ type AdapterOpts = {
|
|
|
17
17
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
18
18
|
* @returns
|
|
19
19
|
*/
|
|
20
|
-
declare const adapter: (opts
|
|
20
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
21
21
|
|
|
22
22
|
type QueryWsStore = {
|
|
23
23
|
connected: boolean;
|
package/dist/query-browser.js
CHANGED
|
@@ -10,7 +10,7 @@ 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 对象
|
|
@@ -19,7 +19,8 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
19
19
|
const timer = setTimeout(() => {
|
|
20
20
|
controller.abort();
|
|
21
21
|
}, timeout);
|
|
22
|
-
let method = overloadOpts?.method || opts
|
|
22
|
+
let method = overloadOpts?.method || opts?.method || 'POST';
|
|
23
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
23
24
|
let origin = '';
|
|
24
25
|
let url;
|
|
25
26
|
if (opts?.url?.startsWith('http')) {
|
|
@@ -41,17 +42,18 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
41
42
|
body = opts.body; // 如果是文件上传,直接使用 FormData
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
45
|
+
headers = {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
...headers,
|
|
48
|
+
};
|
|
44
49
|
body = JSON.stringify(opts.body); // 否则将对象转换为 JSON 字符串
|
|
45
50
|
}
|
|
46
51
|
return fetch(url, {
|
|
47
52
|
method: method.toUpperCase(),
|
|
48
|
-
headers: {
|
|
49
|
-
'Content-Type': 'application/json',
|
|
50
|
-
...opts.headers,
|
|
51
|
-
},
|
|
52
53
|
signal,
|
|
53
|
-
...overloadOpts,
|
|
54
54
|
body: body,
|
|
55
|
+
...overloadOpts,
|
|
56
|
+
headers: headers,
|
|
55
57
|
})
|
|
56
58
|
.then(async (response) => {
|
|
57
59
|
// 获取 Content-Type 头部信息
|
package/dist/query.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ type AdapterOpts = {
|
|
|
17
17
|
* @param overloadOpts 覆盖fetch的默认配置
|
|
18
18
|
* @returns
|
|
19
19
|
*/
|
|
20
|
-
declare const adapter: (opts
|
|
20
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
21
21
|
|
|
22
22
|
type QueryWsStore = {
|
|
23
23
|
connected: boolean;
|
package/dist/query.js
CHANGED
|
@@ -10,7 +10,7 @@ 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 对象
|
|
@@ -19,7 +19,8 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
19
19
|
const timer = setTimeout(() => {
|
|
20
20
|
controller.abort();
|
|
21
21
|
}, timeout);
|
|
22
|
-
let method = overloadOpts?.method || opts
|
|
22
|
+
let method = overloadOpts?.method || opts?.method || 'POST';
|
|
23
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
23
24
|
let origin = '';
|
|
24
25
|
let url;
|
|
25
26
|
if (opts?.url?.startsWith('http')) {
|
|
@@ -41,17 +42,18 @@ const adapter = async (opts, overloadOpts) => {
|
|
|
41
42
|
body = opts.body; // 如果是文件上传,直接使用 FormData
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
45
|
+
headers = {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
...headers,
|
|
48
|
+
};
|
|
44
49
|
body = JSON.stringify(opts.body); // 否则将对象转换为 JSON 字符串
|
|
45
50
|
}
|
|
46
51
|
return fetch(url, {
|
|
47
52
|
method: method.toUpperCase(),
|
|
48
|
-
headers: {
|
|
49
|
-
'Content-Type': 'application/json',
|
|
50
|
-
...opts.headers,
|
|
51
|
-
},
|
|
52
53
|
signal,
|
|
53
|
-
...overloadOpts,
|
|
54
54
|
body: body,
|
|
55
|
+
...overloadOpts,
|
|
56
|
+
headers: headers,
|
|
55
57
|
})
|
|
56
58
|
.then(async (response) => {
|
|
57
59
|
// 获取 Content-Type 头部信息
|