diff --git a/package.json b/package.json index b93d249..7fa9cff 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/rollup.config.js b/rollup.config.js index 5025891..92719f8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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()], + }, ]; diff --git a/src/adapter.ts b/src/adapter.ts index 4968e96..37efd11 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -4,7 +4,14 @@ type AdapterOpts = { body?: Record; 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;