Skip to content

Commit

Permalink
chore: minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Jun 16, 2024
1 parent c7262f3 commit 0254210
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
13 changes: 8 additions & 5 deletions packages/client-axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -165,10 +172,6 @@ export const createClient = (config: Config): Client => {

export const client = createClient(globalConfig);

axios.create({
// responseType: ''
})

createClient({
// responseType: ''
})
18 changes: 10 additions & 8 deletions packages/client-axios/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AxiosRequestConfig, AxiosStatic } from 'axios';
import type { AxiosInstance, AxiosRequestConfig, AxiosStatic } from 'axios';

import type {
BodySerializer,
Expand Down Expand Up @@ -54,6 +54,7 @@ export interface Config extends Omit<AxiosRequestConfig, 'headers' | 'method'> {
| (string | number | boolean)[]
| null
| undefined
| unknown
>;
/**
* The request method.
Expand Down Expand Up @@ -111,6 +112,7 @@ type RequestFn = <Data = unknown, Error = unknown>(
interface ClientBase<Request = unknown, Response = unknown, Options = unknown> {
delete: MethodFn;
get: MethodFn;
getAxiosInstance: () => AxiosInstance;
getConfig: () => Config;
head: MethodFn;
interceptors: Middleware<Request, Response, Options>;
Expand All @@ -137,10 +139,10 @@ type OptionsBase = Omit<RequestOptionsBase, 'url'> & {
client?: Client;
};

export type Options<T = unknown> = T extends { body: any; headers: any }
? OmitKeys<OptionsBase, 'body' | 'headers'> & T
: T extends { body: any }
? OmitKeys<OptionsBase, 'body'> & T
: T extends { headers: any }
? OmitKeys<OptionsBase, 'headers'> & T
: OptionsBase & T;
export type Options<T = unknown> = T extends { body?: any }
? T extends { headers?: any }
? OmitKeys<OptionsBase, 'body' | 'headers'> & T
: OmitKeys<OptionsBase, 'body'> & T & Pick<OptionsBase, 'headers'>
: T extends { headers?: any }
? OmitKeys<OptionsBase, 'headers'> & T & Pick<OptionsBase, 'body'>
: OptionsBase & T;
8 changes: 4 additions & 4 deletions packages/client-axios/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,20 @@ export const getParseAs = (
};

export const getUrl = ({
baseUrl,
baseURL,
path,
query,
querySerializer,
url: _url,
}: {
baseUrl: string;
baseURL: string;
path?: Record<string, unknown>;
query?: Record<string, unknown>;
querySerializer: QuerySerializer;
url: string;
}) => {
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
let url = baseUrl + pathUrl;
let url = baseURL + pathUrl;
if (path) {
url = defaultPathSerializer({ path, url });
}
Expand Down Expand Up @@ -513,7 +513,7 @@ const defaultHeaders = {
export const createDefaultConfig = (): Config => ({
...jsonBodySerializer,
axios,
baseUrl: '',
baseURL: '',
global: true,
headers: defaultHeaders,
querySerializer: defaultQuerySerializer,
Expand Down

0 comments on commit 0254210

Please sign in to comment.