From 0254210507ebffe7f28cec9dc6f9bef154e73891 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 16 Jun 2024 13:58:37 +0100 Subject: [PATCH] chore: minor change --- packages/client-axios/src/index.ts | 13 ++++++++----- packages/client-axios/src/types.ts | 18 ++++++++++-------- packages/client-axios/src/utils.ts | 8 ++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/client-axios/src/index.ts b/packages/client-axios/src/index.ts index 82ab5f5d7..71458b524 100644 --- a/packages/client-axios/src/index.ts +++ b/packages/client-axios/src/index.ts @@ -42,6 +42,12 @@ export const createClient = (config: Config): Client => { globalConfig = { ..._config }; } + const instance = axios.create({ + // responseType: '' + }) + + const getAxiosInstance = () => instance + const getConfig = () => (_config.global ? globalConfig : _config); const interceptors = _config.global @@ -62,7 +68,7 @@ export const createClient = (config: Config): Client => { } const url = getUrl({ - baseUrl: opts.baseURL ?? '', + baseURL: opts.baseURL ?? '', path: opts.path, query: opts.query, querySerializer: @@ -152,6 +158,7 @@ export const createClient = (config: Config): Client => { return { delete: (options) => request({ ...options, method: 'DELETE' }), get: (options) => request({ ...options, method: 'GET' }), + getAxiosInstance, getConfig, head: (options) => request({ ...options, method: 'HEAD' }), interceptors, @@ -165,10 +172,6 @@ export const createClient = (config: Config): Client => { export const client = createClient(globalConfig); -axios.create({ -// responseType: '' -}) - createClient({ // responseType: '' }) diff --git a/packages/client-axios/src/types.ts b/packages/client-axios/src/types.ts index 5ccaf6893..54d9752dd 100644 --- a/packages/client-axios/src/types.ts +++ b/packages/client-axios/src/types.ts @@ -1,4 +1,4 @@ -import type { AxiosRequestConfig, AxiosStatic } from 'axios'; +import type { AxiosInstance, AxiosRequestConfig, AxiosStatic } from 'axios'; import type { BodySerializer, @@ -54,6 +54,7 @@ export interface Config extends Omit { | (string | number | boolean)[] | null | undefined + | unknown >; /** * The request method. @@ -111,6 +112,7 @@ type RequestFn = ( interface ClientBase { delete: MethodFn; get: MethodFn; + getAxiosInstance: () => AxiosInstance; getConfig: () => Config; head: MethodFn; interceptors: Middleware; @@ -137,10 +139,10 @@ type OptionsBase = Omit & { client?: Client; }; -export type Options = T extends { body: any; headers: any } - ? OmitKeys & T - : T extends { body: any } - ? OmitKeys & T - : T extends { headers: any } - ? OmitKeys & T - : OptionsBase & T; +export type Options = T extends { body?: any } + ? T extends { headers?: any } + ? OmitKeys & T + : OmitKeys & T & Pick + : T extends { headers?: any } + ? OmitKeys & T & Pick + : OptionsBase & T; diff --git a/packages/client-axios/src/utils.ts b/packages/client-axios/src/utils.ts index 01d9d8785..f732c3a8c 100644 --- a/packages/client-axios/src/utils.ts +++ b/packages/client-axios/src/utils.ts @@ -357,20 +357,20 @@ export const getParseAs = ( }; export const getUrl = ({ - baseUrl, + baseURL, path, query, querySerializer, url: _url, }: { - baseUrl: string; + baseURL: string; path?: Record; query?: Record; querySerializer: QuerySerializer; url: string; }) => { const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; - let url = baseUrl + pathUrl; + let url = baseURL + pathUrl; if (path) { url = defaultPathSerializer({ path, url }); } @@ -513,7 +513,7 @@ const defaultHeaders = { export const createDefaultConfig = (): Config => ({ ...jsonBodySerializer, axios, - baseUrl: '', + baseURL: '', global: true, headers: defaultHeaders, querySerializer: defaultQuerySerializer,