feat: 优化query,添加别名queryFetch
This commit is contained in:
parent
0b575d44c0
commit
3a8396279b
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/query",
|
||||
"version": "0.0.7",
|
||||
"version": "0.0.8",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -65,4 +65,20 @@ export default [
|
||||
},
|
||||
plugins: [dts()],
|
||||
},
|
||||
{
|
||||
input: 'src/adapter.ts',
|
||||
output: {
|
||||
file: 'dist/query-adapter.js',
|
||||
format: 'es',
|
||||
},
|
||||
plugins: [resolve(), typescript()],
|
||||
},
|
||||
{
|
||||
input: 'src/adapter.ts', // TypeScript 入口文件
|
||||
output: {
|
||||
file: 'dist/query-adapter.d.ts', // 输出文件
|
||||
format: 'es', // 输出格式设置为 ES 模块
|
||||
},
|
||||
plugins: [dts()],
|
||||
},
|
||||
];
|
||||
|
@ -4,7 +4,14 @@ type AdapterOpts = {
|
||||
body?: Record<string, any>;
|
||||
timeout?: number;
|
||||
};
|
||||
export const adapter = async (opts: AdapterOpts) => {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param opts
|
||||
* @param overloadOpts 覆盖fetch的默认配置
|
||||
* @returns
|
||||
*/
|
||||
export const adapter = async (opts: AdapterOpts, overloadOpts?: RequestInit) => {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
||||
@ -20,6 +27,7 @@ export const adapter = async (opts: AdapterOpts) => {
|
||||
},
|
||||
body: JSON.stringify(opts.body),
|
||||
signal,
|
||||
...overloadOpts,
|
||||
})
|
||||
.then((response) => {
|
||||
// 获取 Content-Type 头部信息
|
||||
@ -44,3 +52,7 @@ export const adapter = async (opts: AdapterOpts) => {
|
||||
clearTimeout(timer);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* adapter
|
||||
*/
|
||||
export const queryFetch = adapter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user