From f2057e9a3909bdbb67abb3e72367bb4a74041bc6 Mon Sep 17 00:00:00 2001 From: geekact Date: Mon, 7 Oct 2024 15:06:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20axios=E9=80=82=E9=85=8D=E5=99=A8?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9foca-axios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- pnpm-lock.yaml | 29 ++++++++++++++++++++++++----- src/adapters/axios.ts | 2 +- test/adapters/axios.test-d.ts | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 test/adapters/axios.test-d.ts diff --git a/package.json b/package.json index 6170424..923444d 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,8 @@ "@types/node": "^20.14.10", "@types/qs": "^6.9.15", "@vitest/coverage-v8": "^2.0.3", - "axios": "^1.7.2", + "axios": "^1.7.7", + "foca-axios": "^4.1.1", "husky": "^9.0.11", "only-allow": "^1.2.1", "release-it": "^17.6.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e6a5aa..9b9155f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,8 +82,11 @@ importers: specifier: ^2.0.3 version: 2.0.3(vitest@2.0.3(@types/node@20.14.10)) axios: - specifier: ^1.7.2 - version: 1.7.2 + specifier: ^1.7.7 + version: 1.7.7 + foca-axios: + specifier: ^4.1.1 + version: 4.1.1 husky: specifier: ^9.0.11 version: 9.0.11 @@ -2207,8 +2210,8 @@ packages: resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==} engines: {node: '>= 0.4'} - axios@1.7.2: - resolution: {integrity: sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==} + axios@1.7.7: + resolution: {integrity: sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==} babel-plugin-polyfill-corejs2@0.4.11: resolution: {integrity: sha512-sMEJ27L0gRHShOh5G54uAAPaiCOygY/5ratXuiyb2G46FmlSpc9eFCzYVyDiPxfNbwzA7mYahmjQc5q+CZQ09Q==} @@ -2389,6 +2392,10 @@ packages: resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} engines: {node: '>=0.8'} + clone@2.1.2: + resolution: {integrity: sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==} + engines: {node: '>=0.8'} + co-body@6.2.0: resolution: {integrity: sha512-Kbpv2Yd1NdL1V/V4cwLVxraHDV6K8ayohr2rmH0J87Er8+zJjcTa6dAn9QMPC9CRgU8+aNajKbSf1TzDB1yKPA==} engines: {node: '>=8.0.0'} @@ -2859,6 +2866,9 @@ packages: find-yarn-workspace-root@2.0.0: resolution: {integrity: sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ==} + foca-axios@4.1.1: + resolution: {integrity: sha512-X7j9hfT9C+4EpfWerYD/zVSq1EAFhZkx5aeTemhMcuKRVKYR92nqzrNyKcfU8exgDGaPuLD2ZEMbDcfQXOrC6g==} + follow-redirects@1.15.6: resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==} engines: {node: '>=4.0'} @@ -6954,7 +6964,7 @@ snapshots: dependencies: possible-typed-array-names: 1.0.0 - axios@1.7.2: + axios@1.7.7: dependencies: follow-redirects: 1.15.6 form-data: 4.0.0 @@ -7162,6 +7172,8 @@ snapshots: clone@1.0.4: {} + clone@2.1.2: {} + co-body@6.2.0: dependencies: '@hapi/bourne': 3.0.0 @@ -7795,6 +7807,13 @@ snapshots: dependencies: micromatch: 4.0.5 + foca-axios@4.1.1: + dependencies: + axios: 1.7.7 + clone: 2.1.2 + transitivePeerDependencies: + - debug + follow-redirects@1.15.6: {} for-each@0.3.3: diff --git a/src/adapters/axios.ts b/src/adapters/axios.ts index 6daa677..d94a1a9 100644 --- a/src/adapters/axios.ts +++ b/src/adapters/axios.ts @@ -17,7 +17,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios'; * */ export const axiosAdapter = ( - axios: { request: (config: AxiosRequestConfig) => Promise }, + axios: { request: (config: object) => Promise }, returningData: (response: AxiosResponse) => any = (response) => response.data, ): OpenapiClientAdapter => { return { diff --git a/test/adapters/axios.test-d.ts b/test/adapters/axios.test-d.ts new file mode 100644 index 0000000..d17b1cc --- /dev/null +++ b/test/adapters/axios.test-d.ts @@ -0,0 +1,17 @@ +import axios, { Axios } from 'axios'; +import { axiosAdapter } from '../../src/adapters/axios'; +import * as focaAxios from 'foca-axios'; + +// 原生axios +{ + axiosAdapter(axios); + axiosAdapter(axios.create()); + axiosAdapter(new Axios({})); +} + +// foca-axios +{ + axiosAdapter(focaAxios.axios); + axiosAdapter(focaAxios.default); + axiosAdapter(focaAxios.axios.create()); +}