mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
feat: export getAdapter function (#5324)
This commit is contained in:
@@ -523,6 +523,7 @@ declare namespace axios {
|
|||||||
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
||||||
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
||||||
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
||||||
|
getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
||||||
AxiosHeaders: typeof AxiosHeaders;
|
AxiosHeaders: typeof AxiosHeaders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
@@ -512,6 +512,8 @@ export interface GenericHTMLFormElement {
|
|||||||
submit(): void;
|
submit(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
||||||
|
|
||||||
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
||||||
|
|
||||||
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
||||||
@@ -538,6 +540,7 @@ export interface AxiosStatic extends AxiosInstance {
|
|||||||
isAxiosError: typeof isAxiosError;
|
isAxiosError: typeof isAxiosError;
|
||||||
toFormData: typeof toFormData;
|
toFormData: typeof toFormData;
|
||||||
formToJSON: typeof formToJSON;
|
formToJSON: typeof formToJSON;
|
||||||
|
getAdapter: typeof getAdapter;
|
||||||
CanceledError: typeof CanceledError;
|
CanceledError: typeof CanceledError;
|
||||||
AxiosHeaders: typeof AxiosHeaders;
|
AxiosHeaders: typeof AxiosHeaders;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const {
|
|||||||
AxiosHeaders,
|
AxiosHeaders,
|
||||||
HttpStatusCode,
|
HttpStatusCode,
|
||||||
formToJSON,
|
formToJSON,
|
||||||
|
getAdapter,
|
||||||
mergeConfig
|
mergeConfig
|
||||||
} = axios;
|
} = axios;
|
||||||
|
|
||||||
@@ -37,5 +38,6 @@ export {
|
|||||||
AxiosHeaders,
|
AxiosHeaders,
|
||||||
HttpStatusCode,
|
HttpStatusCode,
|
||||||
formToJSON,
|
formToJSON,
|
||||||
|
getAdapter,
|
||||||
mergeConfig
|
mergeConfig
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import AxiosError from './core/AxiosError.js';
|
|||||||
import spread from './helpers/spread.js';
|
import spread from './helpers/spread.js';
|
||||||
import isAxiosError from './helpers/isAxiosError.js';
|
import isAxiosError from './helpers/isAxiosError.js';
|
||||||
import AxiosHeaders from "./core/AxiosHeaders.js";
|
import AxiosHeaders from "./core/AxiosHeaders.js";
|
||||||
|
import adapters from './adapters/adapters.js';
|
||||||
import HttpStatusCode from './helpers/HttpStatusCode.js';
|
import HttpStatusCode from './helpers/HttpStatusCode.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +79,8 @@ axios.AxiosHeaders = AxiosHeaders;
|
|||||||
|
|
||||||
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
||||||
|
|
||||||
|
axios.getAdapter = adapters.getAdapter;
|
||||||
|
|
||||||
axios.HttpStatusCode = HttpStatusCode;
|
axios.HttpStatusCode = HttpStatusCode;
|
||||||
|
|
||||||
axios.default = axios;
|
axios.default = axios;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import axios, {
|
|||||||
ParamsSerializerOptions,
|
ParamsSerializerOptions,
|
||||||
toFormData,
|
toFormData,
|
||||||
formToJSON,
|
formToJSON,
|
||||||
|
getAdapter,
|
||||||
all,
|
all,
|
||||||
isCancel,
|
isCancel,
|
||||||
isAxiosError,
|
isAxiosError,
|
||||||
@@ -570,6 +571,33 @@ axios.get('/user', {
|
|||||||
adapter: ['xhr', 'http']
|
adapter: ['xhr', 'http']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
// getAdapter
|
||||||
|
|
||||||
|
getAdapter(axios.create().defaults.adapter);
|
||||||
|
getAdapter(undefined);
|
||||||
|
getAdapter([]);
|
||||||
|
getAdapter(['xhr']);
|
||||||
|
getAdapter([adapter]);
|
||||||
|
getAdapter(['xhr', 'http']);
|
||||||
|
getAdapter([adapter, 'xhr']);
|
||||||
|
getAdapter([adapter, adapter]);
|
||||||
|
getAdapter('xhr');
|
||||||
|
getAdapter(adapter);
|
||||||
|
const _: AxiosAdapter = getAdapter('xhr');
|
||||||
|
const __: AxiosAdapter = getAdapter(['xhr']);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
getAdapter();
|
||||||
|
// @ts-expect-error
|
||||||
|
getAdapter(123);
|
||||||
|
// @ts-expect-error
|
||||||
|
getAdapter([123]);
|
||||||
|
// @ts-expect-error
|
||||||
|
getAdapter('xhr', 'http');
|
||||||
|
}
|
||||||
|
|
||||||
// AxiosHeaders
|
// AxiosHeaders
|
||||||
|
|
||||||
// iterator
|
// iterator
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ describe('static api', function () {
|
|||||||
it('should have mergeConfig properties', function () {
|
it('should have mergeConfig properties', function () {
|
||||||
expect(typeof axios.mergeConfig).toEqual('function');
|
expect(typeof axios.mergeConfig).toEqual('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have getAdapter properties', function () {
|
||||||
|
expect(typeof axios.getAdapter).toEqual('function');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('instance api', function () {
|
describe('instance api', function () {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ describe('instance', function () {
|
|||||||
'getUri',
|
'getUri',
|
||||||
'isAxiosError',
|
'isAxiosError',
|
||||||
'mergeConfig',
|
'mergeConfig',
|
||||||
|
'getAdapter',
|
||||||
'VERSION',
|
'VERSION',
|
||||||
'default',
|
'default',
|
||||||
'toFormData',
|
'toFormData',
|
||||||
|
|||||||
Reference in New Issue
Block a user