2023-06-29 17:51:47 +08:00

117 lines
2.8 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import type {
AxiosHeaders,
AxiosRequestConfig,
HeadersDefaults,
AxiosDefaults,
Axios,
InternalAxiosRequestConfig,
AxiosResponse,
} from 'axios'
import type { AnyFunc } from '@/types/modules/utils'
export type AxiosHeaderValue =
| AxiosHeaders
| string
| string[]
| number
| boolean
| null
export interface RequestHeaderOptions {
key: string
value: AxiosHeaderValue
}
export interface AxiosInstanceExpand extends Axios {
<T = any, D = any>(config: AxiosRequestConfig<D>): Promise<T>
<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<T>
getUri(config?: AxiosRequestConfig): string
request<R = any, D = any>(config: AxiosRequestConfig<D>): Promise<R>
get<R = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>
delete<R = any, D = any>(
url: string,
config?: AxiosRequestConfig<D>,
): Promise<R>
head<R = any, D = any>(
url: string,
config?: AxiosRequestConfig<D>,
): Promise<R>
options<R = any, D = any>(
url: string,
config?: AxiosRequestConfig<D>,
): Promise<R>
post<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
put<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
patch<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
postForm<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
putForm<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
patchForm<R = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>,
): Promise<R>
defaults: Omit<AxiosDefaults, 'headers' | 'cancelToken'> & {
headers: HeadersDefaults & {
[key: string]: AxiosHeaderValue
}
}
}
export type RequestInterceptorConfig<T = any> = InternalAxiosRequestConfig<T>
export type ResponseInterceptorConfig<T = any, K = any> = AxiosResponse<T, K>
export interface ImplementQueue {
implementRequestInterceptorArray: AnyFunc[]
implementResponseInterceptorArray: AnyFunc[]
}
export interface ErrorImplementQueue {
implementRequestInterceptorErrorArray: AnyFunc[]
implementResponseInterceptorErrorArray: AnyFunc[]
}
export type BeforeFetchFunction<
T = RequestInterceptorConfig | ResponseInterceptorConfig,
> = <K extends T>(ins: K, mode: string) => void
export type FetchType = 'ok' | 'error'
export type FetchErrorFunction<T = any> = <K extends T>(
error: K,
mode: string,
) => void
export interface AxiosFetchInstance {
requestInstance: RequestInterceptorConfig | null
responseInstance: ResponseInterceptorConfig | null
}
export interface AxiosFetchError<T = unknown> {
requestError: T | null
responseError: T | null
}