增加 build 包
parent
0d81117f8e
commit
58f0b7ac49
|
@ -106,9 +106,5 @@ dist
|
|||
.idea
|
||||
.vscode
|
||||
|
||||
package
|
||||
types
|
||||
coverage/
|
||||
coverage
|
||||
yarn-error.log
|
||||
lib
|
||||
es
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
|||
import { Adapter } from './types';
|
||||
/**
|
||||
* 自适应当前平台
|
||||
*/
|
||||
export default function adaptive(): Adapter | undefined;
|
|
@ -0,0 +1,6 @@
|
|||
import { AxiosInstance } from './types';
|
||||
/**
|
||||
* Axios 实例拓展
|
||||
*/
|
||||
declare const axios: AxiosInstance;
|
||||
export default axios;
|
|
@ -0,0 +1,9 @@
|
|||
import { Cancel } from '../types';
|
||||
export default class CancelClass implements Cancel {
|
||||
message?: string | undefined;
|
||||
/**
|
||||
* @param message 取消信息
|
||||
*/
|
||||
constructor(message?: string | undefined);
|
||||
toString(): string;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { CancelToken, CancelExecutor, CancelTokenSource } from '../types';
|
||||
import Cancel from './Cancel';
|
||||
export default class CancelTokenClass implements CancelToken {
|
||||
/**
|
||||
* 取消请求
|
||||
*/
|
||||
private _reason?;
|
||||
listener: Promise<Cancel>;
|
||||
constructor(executor: CancelExecutor);
|
||||
throwIfRequested(): void;
|
||||
/**
|
||||
* 返回一个 CancelTokenSource
|
||||
*
|
||||
* CancelTokenSource.token 是一个 CancelToken 对象
|
||||
*
|
||||
* CancelTokenSource.cancel 是一个 CancelAction 函数
|
||||
*
|
||||
* 调用 CancelTokenSource.cancel('这里可以填写您的错误信息')
|
||||
*
|
||||
* 取消请求 CancelTokenSource.token
|
||||
*/
|
||||
static source(): CancelTokenSource;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import Cancel from './Cancel';
|
||||
/**
|
||||
* 是否是取消请求实例
|
||||
*
|
||||
* @param value 判断的值
|
||||
*/
|
||||
export default function isCancel(value: unknown): value is Cancel;
|
|
@ -0,0 +1,37 @@
|
|||
import { Params, Data, Interceptors, AxiosRequestConfig, AxiosResponse, Axios } from '../types';
|
||||
export default class AxiosClass implements Axios {
|
||||
defaults: AxiosRequestConfig;
|
||||
interceptors: Interceptors;
|
||||
/**
|
||||
* @param defaults 自定义默认配置
|
||||
*/
|
||||
constructor(defaults?: AxiosRequestConfig);
|
||||
getUri(config: AxiosRequestConfig): string;
|
||||
request<T extends Data>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
head<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
post<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
put<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
delete<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 合并配置后发送 HTTP 请求
|
||||
*
|
||||
* @param method 请求方法
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
* @param config 额外配置
|
||||
*/
|
||||
private _requestMethodWithoutParams;
|
||||
/**
|
||||
* 合并配置后发送 HTTP 请求
|
||||
*
|
||||
* @param method 请求方法
|
||||
* @param url 请求地址
|
||||
* @param data 请求数据
|
||||
* @param config 额外配置
|
||||
*/
|
||||
private _requestMethodWithoutData;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { InterceptorResolved, InterceptorRejected, InterceptorExecutor, InterceptorManager } from '../types';
|
||||
/**
|
||||
* 拦截器管理器
|
||||
*/
|
||||
export default class InterceptorManagerClass<T> implements InterceptorManager<T> {
|
||||
/**
|
||||
* 生成拦截器 id
|
||||
*/
|
||||
private _id;
|
||||
/**
|
||||
* 拦截器集合
|
||||
*/
|
||||
private _interceptors;
|
||||
use(resolved: InterceptorResolved<T>, rejected?: InterceptorRejected): number;
|
||||
eject(id: number): void;
|
||||
forEach(executor: InterceptorExecutor<T>, reverse?: 'reverse'): void;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
import { AxiosRequestConfig, RequestConfig, AxiosResponse, AxiosError } from '../types';
|
||||
/**
|
||||
* 创建 AxiosError 的工厂方法
|
||||
*
|
||||
* 返回一个新的 AxiosError 对象
|
||||
*
|
||||
* @param message 错误信息
|
||||
* @param config Axios 请求配置
|
||||
* @param request 通用请求配置
|
||||
* @param response Axios 响应体
|
||||
*/
|
||||
export default function createError(message: string, config: AxiosRequestConfig, request: RequestConfig, response?: AxiosResponse): AxiosError;
|
|
@ -0,0 +1,7 @@
|
|||
import { AxiosRequestConfig, AxiosResponse } from '../types';
|
||||
/**
|
||||
* 发送请求
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export default function dispatchRequest(config: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
@ -0,0 +1,7 @@
|
|||
import { Headers, AxiosRequestConfig } from '../types';
|
||||
/**
|
||||
* 拉平请求头
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export default function flattenHeaders(config: AxiosRequestConfig): Headers;
|
|
@ -0,0 +1,8 @@
|
|||
import { AxiosRequestConfig } from '../types';
|
||||
/**
|
||||
* 合并 Axios 请求配置
|
||||
*
|
||||
* @param config1 Axios 请求配置1
|
||||
* @param config2 Axios 请求配置2
|
||||
*/
|
||||
export default function mergeConfig(config1?: AxiosRequestConfig, config2?: AxiosRequestConfig): AxiosRequestConfig;
|
|
@ -0,0 +1,7 @@
|
|||
import { AxiosRequestConfig, AxiosResponse } from '../types';
|
||||
/**
|
||||
* 请求函数
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export default function request(config: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
@ -0,0 +1,9 @@
|
|||
import { Data, Headers, TransformData } from '../types';
|
||||
/**
|
||||
* 转换数据
|
||||
*
|
||||
* @param data 请求数据/响应数据
|
||||
* @param headers 请求头/响应头
|
||||
* @param transforms 请求数据转换函数/响应数据转换函数
|
||||
*/
|
||||
export default function transformData(data: Data, headers: Headers, transforms?: TransformData | TransformData[]): Data;
|
|
@ -0,0 +1,13 @@
|
|||
import { AliasMethod, AdapterMethod, Method } from '../types';
|
||||
/**
|
||||
* 请求方法转全小写
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export declare function methodToLowercase(method?: Method): AliasMethod;
|
||||
/**
|
||||
* 请求方法转全大写
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export declare function methodToUppercase(method?: Method): AdapterMethod;
|
|
@ -0,0 +1,9 @@
|
|||
import { AxiosRequestConfig, RequestConfig } from '../types';
|
||||
/**
|
||||
* Axios 请求配置转换成各大平台通用请求配置
|
||||
*
|
||||
* 抹平差异
|
||||
*
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export default function transformRequest(config: AxiosRequestConfig): RequestConfig;
|
|
@ -0,0 +1,10 @@
|
|||
import { AxiosRequestConfig, AxiosResponse, Response } from '../types';
|
||||
/**
|
||||
* 各大平台通用响应体转成 Axios 响应体
|
||||
*
|
||||
* 抹平差异
|
||||
*
|
||||
* @param response 通用响应体
|
||||
* @param config Axios 请求配置
|
||||
*/
|
||||
export default function transformResponse(response: Response, config: AxiosRequestConfig): AxiosResponse;
|
|
@ -0,0 +1,3 @@
|
|||
import { AxiosRequestConfig } from './types';
|
||||
declare const defaults: AxiosRequestConfig;
|
||||
export default defaults;
|
|
@ -0,0 +1,16 @@
|
|||
import { AnyObject, Params } from '../types';
|
||||
/**
|
||||
* 默认参数序列化
|
||||
*
|
||||
* @param params 请求参数
|
||||
*/
|
||||
declare function paramsSerialization(params: AnyObject): string;
|
||||
/**
|
||||
* 处理 URL 参数
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
* @param paramsSerializer 自定义参数序列化
|
||||
*/
|
||||
export default function buildURL(url: string, params?: Params, paramsSerializer?: typeof paramsSerialization): string;
|
||||
export {};
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* 拼接 baseURL 和 url 获得完整的 URL
|
||||
*
|
||||
* combineURL('1/2///','////3/4') => '1/2/3/4'
|
||||
*/
|
||||
export default function combineURL(baseURL: string, url: string): string;
|
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* 检查是否是一个绝对 URL
|
||||
*
|
||||
* xxx:// 或者 "//" 开头, 视为绝对地址
|
||||
*
|
||||
* @param url 需要检查的 URL
|
||||
*/
|
||||
export default function isAbsoluteURL(url: string): boolean;
|
|
@ -0,0 +1,39 @@
|
|||
import { AnyObject } from '../types';
|
||||
/**
|
||||
* 对字符串进行编码转换
|
||||
*
|
||||
* @param str 字符串
|
||||
*/
|
||||
export declare function encode(str: string): string;
|
||||
/**
|
||||
* 是不是一个日期对象
|
||||
*
|
||||
* @param date 判断目标
|
||||
*/
|
||||
export declare function isDate(date: unknown): date is Date;
|
||||
/**
|
||||
* 是不是一个普通对象
|
||||
*
|
||||
* @param obj 判断目标
|
||||
*/
|
||||
export declare function isPlainObject(obj: unknown): obj is Record<string, unknown>;
|
||||
/**
|
||||
* 深度合并多个对象
|
||||
*
|
||||
* @param objs n 个对象
|
||||
*/
|
||||
export declare function deepMerge(...objs: Record<string, any>[]): Record<string, any>;
|
||||
/**
|
||||
* 从对象中提取一部分属性
|
||||
*
|
||||
* @param obj 源对象
|
||||
* @param keys 需要提取的 key
|
||||
*/
|
||||
export declare function pick<T extends AnyObject, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
|
||||
/**
|
||||
* 从对象中剔除一部分属性
|
||||
*
|
||||
* @param obj 源对象
|
||||
* @param keys 需要剔除的 key
|
||||
*/
|
||||
export declare function omit<T extends AnyObject, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
|
|
@ -0,0 +1,3 @@
|
|||
import axios from './axios';
|
||||
export * from './types';
|
||||
export default axios;
|
|
@ -0,0 +1,596 @@
|
|||
/**
|
||||
* 任意值对象
|
||||
*/
|
||||
export declare interface AnyObject<T extends any = any> {
|
||||
[x: string]: T;
|
||||
}
|
||||
/**
|
||||
* 请求方法
|
||||
*/
|
||||
export declare type AdapterMethod = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
|
||||
/**
|
||||
* 请求方法别名
|
||||
*/
|
||||
export declare type AliasMethod = 'options' | 'get' | 'head' | 'post' | 'put' | 'delete' | 'trace' | 'connect';
|
||||
/**
|
||||
* Axios 请求方法
|
||||
*/
|
||||
export declare type Method = AliasMethod | AdapterMethod;
|
||||
/**
|
||||
* Axios 参数
|
||||
*/
|
||||
export declare type Params = AnyObject;
|
||||
/**
|
||||
* Axios 数据
|
||||
*/
|
||||
export declare type Data = string | AnyObject | ArrayBuffer;
|
||||
/**
|
||||
* Axios 头
|
||||
*/
|
||||
export declare interface Headers extends Partial<Record<'common' | AliasMethod, AnyObject<string>>> {
|
||||
/**
|
||||
* 自定义配置
|
||||
*/
|
||||
[x: string]: AnyObject<string> | string | undefined;
|
||||
}
|
||||
/**
|
||||
* 通用请求配置
|
||||
*/
|
||||
export declare interface RequestConfig {
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* HTTP 请求方法
|
||||
*/
|
||||
method: AdapterMethod;
|
||||
/**
|
||||
* 请求数据
|
||||
*/
|
||||
data: Data;
|
||||
/**
|
||||
* 请求头 同 headers
|
||||
*/
|
||||
header: AnyObject;
|
||||
/**
|
||||
* 请求头 同 header
|
||||
*/
|
||||
headers: AnyObject;
|
||||
/**
|
||||
* 返回的数据格式
|
||||
*/
|
||||
dataType?: 'json' | '其他';
|
||||
/**
|
||||
* 响应的数据类型
|
||||
*/
|
||||
responseType?: 'text' | 'arraybuffer';
|
||||
/**
|
||||
* 超时时间
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* 开启 http2
|
||||
*/
|
||||
enableHttp2?: boolean;
|
||||
/**
|
||||
* 开启 quic
|
||||
*/
|
||||
enableQuic?: boolean;
|
||||
/**
|
||||
* 开启 cache
|
||||
*/
|
||||
enableCache?: boolean;
|
||||
/**
|
||||
* 验证 ssl 证书
|
||||
*/
|
||||
sslVerify?: boolean;
|
||||
}
|
||||
/**
|
||||
* 通用响应体
|
||||
*/
|
||||
export declare interface Response {
|
||||
/**
|
||||
* 响应状态码
|
||||
*/
|
||||
statusCode?: number;
|
||||
/**
|
||||
* 响应状态码
|
||||
*/
|
||||
status?: number;
|
||||
/**
|
||||
* 响应头 Headers
|
||||
*/
|
||||
header?: AnyObject;
|
||||
/**
|
||||
* 响应头 Headers
|
||||
*/
|
||||
headers?: Headers;
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
data: Data;
|
||||
/**
|
||||
* 开发者服务器返回的 cookies,格式为字符串数组
|
||||
*/
|
||||
cookies?: string[];
|
||||
/**
|
||||
* 网络请求过程中一些关键时间点的耗时信息
|
||||
*/
|
||||
profile?: AnyObject;
|
||||
}
|
||||
/**
|
||||
* 适配器请求配置
|
||||
*/
|
||||
export declare interface AdapterRequestConfig extends RequestConfig {
|
||||
/**
|
||||
* 成功的响应函数
|
||||
*/
|
||||
success: (res: Response) => void;
|
||||
/**
|
||||
* 失败的响应函数
|
||||
*/
|
||||
fail: (err: unknown) => void;
|
||||
}
|
||||
/**
|
||||
* 适配器请求任务
|
||||
*/
|
||||
export declare interface AdapterRequestTask {
|
||||
/**
|
||||
* 取消请求
|
||||
*/
|
||||
abort(): void;
|
||||
}
|
||||
/**
|
||||
* 适配器
|
||||
*/
|
||||
export declare interface Adapter {
|
||||
(config: AdapterRequestConfig): AdapterRequestTask | void;
|
||||
}
|
||||
/**
|
||||
* 平台
|
||||
*/
|
||||
export declare interface Platform {
|
||||
request: Adapter;
|
||||
}
|
||||
/**
|
||||
* 转换数据函数
|
||||
*/
|
||||
export declare interface TransformData {
|
||||
(data: Data, headers: Headers): Data;
|
||||
}
|
||||
/**
|
||||
* 错误处理程序
|
||||
*/
|
||||
export declare interface ErrorHandler {
|
||||
(error: any): Promise<any> | any;
|
||||
}
|
||||
/**
|
||||
* Axios 请求配置
|
||||
*/
|
||||
export declare interface AxiosRequestConfig {
|
||||
/**
|
||||
* 自定义适配器
|
||||
*/
|
||||
adapter?: Adapter;
|
||||
/**
|
||||
* 基础地址
|
||||
*/
|
||||
baseURL?: string;
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
url?: string;
|
||||
/**
|
||||
* 请求方法
|
||||
*/
|
||||
method?: Method;
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
params?: Params;
|
||||
/**
|
||||
* 请求数据
|
||||
*/
|
||||
data?: Data;
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
headers?: Headers;
|
||||
/**
|
||||
* 自定义合法状态码
|
||||
*/
|
||||
validateStatus?: (status: number) => boolean;
|
||||
/**
|
||||
* 自定义参数序列化
|
||||
*/
|
||||
paramsSerializer?: (params?: AnyObject) => string;
|
||||
/**
|
||||
* 转换请求数据
|
||||
*/
|
||||
transformRequest?: TransformData | TransformData[];
|
||||
/**
|
||||
* 转换响应数据
|
||||
*/
|
||||
transformResponse?: TransformData | TransformData[];
|
||||
/**
|
||||
* 自定义错误处理
|
||||
*/
|
||||
errorHandler?: ErrorHandler;
|
||||
/**
|
||||
* 取消令牌
|
||||
*/
|
||||
cancelToken?: CancelToken;
|
||||
/**
|
||||
* 超时时间
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* 响应数据格式
|
||||
*/
|
||||
dataType?: 'json' | '其他';
|
||||
/**
|
||||
* 响应数据类型
|
||||
*/
|
||||
responseType?: 'text' | 'arraybuffer';
|
||||
/**
|
||||
* 开启 http2
|
||||
*/
|
||||
enableHttp2?: boolean;
|
||||
/**
|
||||
* 开启 quic
|
||||
*/
|
||||
enableQuic?: boolean;
|
||||
/**
|
||||
* 开启 cache
|
||||
*/
|
||||
enableCache?: boolean;
|
||||
/**
|
||||
* 验证 ssl 证书
|
||||
*/
|
||||
sslVerify?: boolean;
|
||||
}
|
||||
/**
|
||||
* Axios 响应体
|
||||
*/
|
||||
export declare interface AxiosResponse<T extends Data = Data> {
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
status: number;
|
||||
/**
|
||||
* 状态文本
|
||||
*/
|
||||
statusText: string;
|
||||
/**
|
||||
* 服务端返回的数据
|
||||
*/
|
||||
data: T;
|
||||
/**
|
||||
* 响应头
|
||||
*/
|
||||
headers: Headers;
|
||||
/**
|
||||
* Axios 请求配置
|
||||
*/
|
||||
config: AxiosRequestConfig;
|
||||
/**
|
||||
* 开发者服务器返回的 cookies,格式为字符串数组
|
||||
*/
|
||||
cookies?: string[];
|
||||
/**
|
||||
* 网络请求过程中一些关键时间点的耗时信息
|
||||
*/
|
||||
profile?: AnyObject;
|
||||
}
|
||||
/**
|
||||
* 拦截器成功的回调函数
|
||||
*/
|
||||
export declare interface InterceptorResolved<T = any> {
|
||||
(value: T): Promise<T> | T;
|
||||
}
|
||||
/**
|
||||
* 拦截器失败的回调函数
|
||||
*/
|
||||
export declare interface InterceptorRejected {
|
||||
(error: any): any;
|
||||
}
|
||||
/**
|
||||
* 拦截器
|
||||
*/
|
||||
export declare interface Interceptor<T = any> {
|
||||
/**
|
||||
* 拦截器成功的回调函数
|
||||
*/
|
||||
resolved: InterceptorResolved<T>;
|
||||
/**
|
||||
* 拦截器失败的回调函数
|
||||
*/
|
||||
rejected?: InterceptorRejected;
|
||||
}
|
||||
/**
|
||||
* 拦截器执行器
|
||||
*/
|
||||
export declare interface InterceptorExecutor<T = any> {
|
||||
(interceptor: Interceptor<T>): void;
|
||||
}
|
||||
/**
|
||||
* 拦截器管理器
|
||||
*/
|
||||
export declare interface InterceptorManager<T = any> {
|
||||
[x: string]: any;
|
||||
/**
|
||||
* 添加拦截器
|
||||
*
|
||||
* @param resolved 成功的回调函数
|
||||
* @param rejected 失败的回调函数
|
||||
*/
|
||||
use(resolved: InterceptorResolved<T>, rejected?: InterceptorRejected): number;
|
||||
/**
|
||||
* 删除拦截器
|
||||
*
|
||||
* @param id 拦截器 id
|
||||
*/
|
||||
eject(id: number): void;
|
||||
/**
|
||||
* 遍历所有拦截器
|
||||
*
|
||||
* @param executor 拦截器执行器
|
||||
* @param reverse 是否倒序遍历
|
||||
*/
|
||||
forEach(executor: InterceptorExecutor<T>, reverse?: 'reverse'): void;
|
||||
}
|
||||
/**
|
||||
* Axios 拦截器
|
||||
*/
|
||||
export declare interface Interceptors {
|
||||
/**
|
||||
* request 请求拦截器
|
||||
*/
|
||||
request: InterceptorManager<AxiosRequestConfig>;
|
||||
/**
|
||||
* response 响应拦截器
|
||||
*/
|
||||
response: InterceptorManager<AxiosResponse>;
|
||||
}
|
||||
/**
|
||||
* Axios 实例
|
||||
*/
|
||||
export declare interface Axios {
|
||||
/**
|
||||
* 默认配置
|
||||
*/
|
||||
defaults: AxiosRequestConfig;
|
||||
/**
|
||||
* Axios 拦截器
|
||||
*/
|
||||
interceptors: Interceptors;
|
||||
/**
|
||||
* 根据配置中的 url 和 params 生成一个 URI
|
||||
*
|
||||
* @param config 请求配置
|
||||
*/
|
||||
getUri(config: AxiosRequestConfig): string;
|
||||
/**
|
||||
* 发送 HTTP 请求
|
||||
*
|
||||
* @param config 请求配置
|
||||
*/
|
||||
request<T extends Data>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 OPTIONS
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param config 额外配置
|
||||
*/
|
||||
options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 GET
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
* @param config 额外配置
|
||||
*/
|
||||
get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 HEAD
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
* @param config 额外配置
|
||||
*/
|
||||
head<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 POST
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param data 请求数据
|
||||
* @param config 额外配置
|
||||
*/
|
||||
post<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 PUT
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param data 请求数据
|
||||
* @param config 额外配置
|
||||
*/
|
||||
put<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 DELETE
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
* @param config 额外配置
|
||||
*/
|
||||
delete<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 TRACE
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param config 额外配置
|
||||
*/
|
||||
trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求 CONNECT
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param config 额外配置
|
||||
*/
|
||||
connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
}
|
||||
/**
|
||||
* Axios 类接口
|
||||
*/
|
||||
export declare interface AxiosConstructor {
|
||||
new (config?: AxiosRequestConfig): Axios;
|
||||
}
|
||||
/**
|
||||
* AxiosError 类继承自 Error
|
||||
*/
|
||||
export declare interface AxiosError extends Error {
|
||||
/**
|
||||
* 是 Axios 错误
|
||||
*/
|
||||
isAxiosError: boolean;
|
||||
/**
|
||||
* 请求配置
|
||||
*/
|
||||
config: AxiosRequestConfig;
|
||||
/**
|
||||
* 通用请求配置
|
||||
*/
|
||||
request: RequestConfig;
|
||||
/**
|
||||
* Axios 响应体
|
||||
*/
|
||||
response?: AxiosResponse;
|
||||
}
|
||||
/**
|
||||
* 取消请求
|
||||
*/
|
||||
export declare interface Cancel {
|
||||
/**
|
||||
* 取消信息
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* 序列化
|
||||
*/
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* 取消请求类接口
|
||||
*/
|
||||
export declare interface CancelConstructor {
|
||||
new (message?: string): Cancel;
|
||||
}
|
||||
/**
|
||||
* 取消操作
|
||||
*/
|
||||
export declare interface CancelAction {
|
||||
(message?: string): void;
|
||||
}
|
||||
/**
|
||||
* 取消操作执行器
|
||||
*/
|
||||
export declare interface CancelExecutor {
|
||||
(cancel: CancelAction): void;
|
||||
}
|
||||
/**
|
||||
* 取消令牌
|
||||
*/
|
||||
export declare interface CancelToken {
|
||||
/**
|
||||
* 取消时被触发
|
||||
*/
|
||||
listener: Promise<Cancel>;
|
||||
/**
|
||||
* 如果已经取消, 则抛出取消对象
|
||||
*/
|
||||
throwIfRequested(): void;
|
||||
}
|
||||
/**
|
||||
* 取消令牌 source
|
||||
*/
|
||||
export declare interface CancelTokenSource {
|
||||
/**
|
||||
* 取消令牌
|
||||
*/
|
||||
token: CancelToken;
|
||||
/**
|
||||
* 取消操作
|
||||
*/
|
||||
cancel: CancelAction;
|
||||
}
|
||||
/**
|
||||
* 取消令牌类接口
|
||||
*/
|
||||
export declare interface CancelTokenConstructor {
|
||||
new (executor: CancelExecutor): CancelToken;
|
||||
/**
|
||||
* 返回一个 CancelTokenSource
|
||||
*
|
||||
* CancelTokenSource.token 是一个 CancelToken 对象
|
||||
*
|
||||
* CancelTokenSource.cancel 是一个 CancelAction 函数
|
||||
*
|
||||
* 调用 CancelTokenSource.cancel('这里可以填写您的错误信息')
|
||||
*
|
||||
* 取消请求 CancelTokenSource.token
|
||||
*/
|
||||
source(): CancelTokenSource;
|
||||
}
|
||||
/**
|
||||
* Axios 实例基础拓展
|
||||
*
|
||||
* * 支持两种函数调用方式
|
||||
*/
|
||||
export declare interface AxiosBaseInstance extends Axios {
|
||||
/**
|
||||
* 发送 HTTP 请求
|
||||
*
|
||||
* 调用方式一
|
||||
*
|
||||
* @param config 请求配置
|
||||
*/
|
||||
<T extends Data>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
/**
|
||||
* 发送 HTTP 请求
|
||||
*
|
||||
* 调用方式二
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param config 额外配置
|
||||
*/
|
||||
<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
||||
}
|
||||
/**
|
||||
* Axios 实例拓展
|
||||
*
|
||||
* * 支持两种函数调用方式
|
||||
*
|
||||
* * 同时拓展了一些静态属性和方法
|
||||
*/
|
||||
export declare interface AxiosInstance extends AxiosBaseInstance {
|
||||
/**
|
||||
* 创建 Axios 实例基础拓展
|
||||
*
|
||||
* @param defaults 自定义默认配置
|
||||
*/
|
||||
create(defaults?: AxiosRequestConfig): AxiosBaseInstance;
|
||||
/**
|
||||
* Axios 类
|
||||
*/
|
||||
Axios: AxiosConstructor;
|
||||
/**
|
||||
* 取消令牌 类
|
||||
*/
|
||||
CancelToken: CancelTokenConstructor;
|
||||
/**
|
||||
* 检查错误是否来自取消请求
|
||||
*
|
||||
* @param value 判断的值
|
||||
*/
|
||||
isCancel: (value: any) => boolean;
|
||||
}
|
64
yarn.lock
64
yarn.lock
|
@ -673,16 +673,6 @@
|
|||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
|
||||
"@babel/plugin-transform-runtime@^7.10.5":
|
||||
version "7.10.5"
|
||||
resolved "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.10.5.tgz#3b39b7b24830e0c2d8ff7a4489fe5cf99fbace86"
|
||||
integrity sha512-tV4V/FjElJ9lQtyjr5xD2IFFbgY46r7EeVu5a8CpEKT5laheHKSlFeHjpkPppW3PqzGLAuv5k2qZX5LgVZIX5w==
|
||||
dependencies:
|
||||
"@babel/helper-module-imports" "^7.10.4"
|
||||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
resolve "^1.8.1"
|
||||
semver "^5.5.1"
|
||||
|
||||
"@babel/plugin-transform-shorthand-properties@^7.10.4":
|
||||
version "7.10.4"
|
||||
resolved "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.10.4.tgz#9fd25ec5cdd555bb7f473e5e6ee1c971eede4dd6"
|
||||
|
@ -838,21 +828,6 @@
|
|||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
"@babel/plugin-transform-typescript" "^7.10.4"
|
||||
|
||||
"@babel/runtime-corejs3@^7.11.2":
|
||||
version "7.11.2"
|
||||
resolved "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.11.2.tgz#02c3029743150188edeb66541195f54600278419"
|
||||
integrity sha512-qh5IR+8VgFz83VBa6OkaET6uN/mJOhHONuy3m1sgF0CV6mXdPSEBdA7e1eUbVvyNtANjMbg22JUv71BaDXLY6A==
|
||||
dependencies:
|
||||
core-js-pure "^3.0.0"
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@babel/runtime@^7.10.5":
|
||||
version "7.10.5"
|
||||
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.10.5.tgz#303d8bd440ecd5a491eae6117fd3367698674c5c"
|
||||
integrity sha512-otddXKhdNn7d0ptoFRHtMLa8LqDxLYwTjB4nYgM1yy5N6gU/MUf8zqyyLltCH3yAVitBzmwK4us+DD0l/MauAg==
|
||||
dependencies:
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@babel/runtime@^7.8.4":
|
||||
version "7.11.0"
|
||||
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.11.0.tgz#f10245877042a815e07f7e693faff0ae9d3a2aac"
|
||||
|
@ -1910,11 +1885,6 @@ core-js-compat@^3.6.2:
|
|||
browserslist "^4.8.5"
|
||||
semver "7.0.0"
|
||||
|
||||
core-js-pure@^3.0.0:
|
||||
version "3.6.5"
|
||||
resolved "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.6.5.tgz#c79e75f5e38dbc85a662d91eea52b8256d53b813"
|
||||
integrity sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA==
|
||||
|
||||
core-util-is@1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||
|
@ -2287,11 +2257,6 @@ estraverse@^5.1.0:
|
|||
resolved "https://registry.npmjs.org/estraverse/-/estraverse-5.1.0.tgz#374309d39fd935ae500e7b92e8a6b4c720e59642"
|
||||
integrity sha512-FyohXK+R0vE+y1nHLoBM7ZTyqRpqAlhdZHCWIWEviFLiGB8b04H6bQs8G+XTthacvT8VuwvteiP7RJSxMs8UEw==
|
||||
|
||||
estree-walker@^0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
|
||||
integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==
|
||||
|
||||
estree-walker@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
|
||||
|
@ -3706,7 +3671,7 @@ loose-envify@^1.0.0:
|
|||
dependencies:
|
||||
js-tokens "^3.0.0 || ^4.0.0"
|
||||
|
||||
magic-string@^0.25.2, magic-string@^0.25.3:
|
||||
magic-string@^0.25.2:
|
||||
version "0.25.7"
|
||||
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051"
|
||||
integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==
|
||||
|
@ -4404,7 +4369,7 @@ resolve@1.15.1:
|
|||
dependencies:
|
||||
path-parse "^1.0.6"
|
||||
|
||||
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.8.1:
|
||||
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.17.0, resolve@^1.3.2:
|
||||
version "1.17.0"
|
||||
resolved "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
|
||||
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
|
||||
|
@ -4438,22 +4403,6 @@ rimraf@^3.0.0:
|
|||
dependencies:
|
||||
glob "^7.1.3"
|
||||
|
||||
rollup-plugin-inject@^3.0.0:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz#e4233855bfba6c0c12a312fd6649dff9a13ee9f4"
|
||||
integrity sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==
|
||||
dependencies:
|
||||
estree-walker "^0.6.1"
|
||||
magic-string "^0.25.3"
|
||||
rollup-pluginutils "^2.8.1"
|
||||
|
||||
rollup-plugin-node-polyfills@^0.2.1:
|
||||
version "0.2.1"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-node-polyfills/-/rollup-plugin-node-polyfills-0.2.1.tgz#53092a2744837164d5b8a28812ba5f3ff61109fd"
|
||||
integrity sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==
|
||||
dependencies:
|
||||
rollup-plugin-inject "^3.0.0"
|
||||
|
||||
rollup-plugin-typescript2@^0.27.1:
|
||||
version "0.27.1"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.1.tgz#4f27193408a8f040139eed3e3db7b0c7f3668200"
|
||||
|
@ -4465,13 +4414,6 @@ rollup-plugin-typescript2@^0.27.1:
|
|||
resolve "1.15.1"
|
||||
tslib "1.11.2"
|
||||
|
||||
rollup-pluginutils@^2.8.1:
|
||||
version "2.8.2"
|
||||
resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
|
||||
integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==
|
||||
dependencies:
|
||||
estree-walker "^0.6.1"
|
||||
|
||||
rsvp@^4.8.4:
|
||||
version "4.8.5"
|
||||
resolved "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
|
||||
|
@ -4538,7 +4480,7 @@ semver-regex@^2.0.0:
|
|||
resolved "https://registry.npmjs.org/semver-regex/-/semver-regex-2.0.0.tgz#a93c2c5844539a770233379107b38c7b4ac9d338"
|
||||
integrity sha512-mUdIBBvdn0PLOeP3TEkMH7HHeUP3GjsXCwKarjv/kGmUFOYg1VqEemKhoQpWMu6X2I8kHeuVdGibLGkVK+/5Qw==
|
||||
|
||||
"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.5.1:
|
||||
"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
|
||||
version "5.7.1"
|
||||
resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
|
||||
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
|
||||
|
|
Loading…
Reference in New Issue