| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767 |
- // global.d.ts
- type AnyObject<T = any> = Record<string, T>;
- // global.d.ts end
- interface CancelAction {
- /**
- * 取消信息
- */
- (message?: string): void;
- }
- interface CancelExecutor {
- (cancel: CancelAction): void;
- }
- interface CancelTokenSource {
- /**
- * 取消令牌
- */
- token: CancelToken;
- /**
- * 取消函数
- */
- cancel: CancelAction;
- }
- interface CancelTokenConstructor {
- new (executor: CancelExecutor): CancelToken;
- source(): CancelTokenSource;
- }
- declare class Cancel {
- message?: string;
- constructor(message?: string);
- toString(): string;
- }
- declare function isCancel(value: unknown): value is Cancel;
- declare class CancelToken {
- #private;
- constructor(executor: CancelExecutor);
- static source(): CancelTokenSource;
- }
- interface AxiosTransformCallback<TData = unknown> {
- (
- /**
- * 数据
- */
- data?: TData,
- /**
- * 头信息
- */
- headers?: AnyObject): TData | undefined;
- }
- type AxiosTransformer<TData = unknown> = AxiosTransformCallback<TData> | AxiosTransformCallback<TData>[];
- interface InterceptorResolved<T = unknown> {
- (value: T): T | Promise<T>;
- }
- interface InterceptorRejected<T = unknown> {
- (error: unknown): T | Promise<T>;
- }
- /**
- * 拦截器管理器
- */
- declare class InterceptorManager<T = unknown> {
- #private;
- /**
- * 添加拦截器
- *
- * @param resolved 成功的回调
- * @param rejected 失败的回调
- * @returns 拦截器标识符(可用于移除拦截器)
- */
- use(resolved: InterceptorResolved<T>, rejected?: InterceptorRejected<T>): number;
- /**
- * 移除拦截器
- *
- * @param id 拦截器标识符
- */
- eject(id: number): boolean;
- /**
- * 清空拦截器
- */
- clear(): void;
- }
- interface MiddlewareNext {
- (): Promise<void>;
- }
- /**
- * 中间件上下文
- */
- interface MiddlewareContext {
- /**
- * 请求体
- *
- * 同于请求配置
- */
- req: AxiosRequestConfig;
- /**
- * 响应体
- */
- res: null | AxiosResponse;
- }
- /**
- * 中间件
- */
- interface MiddlewareCallback {
- (ctx: MiddlewareContext, next: MiddlewareNext): Promise<void>;
- }
- /**
- * 请求方法
- */
- type AxiosRequestMethod = AxiosAdapterRequestMethod | 'options' | 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'connect';
- /**
- * 请求头
- */
- interface AxiosRequestHeaders extends AnyObject {
- /**
- * 通用请求头
- */
- common?: AnyObject;
- /**
- * options 请求头
- */
- options?: AnyObject;
- /**
- * get 请求头
- */
- get?: AnyObject;
- /**
- * head 请求头
- */
- head?: AnyObject;
- /**
- * post 请求头
- */
- post?: AnyObject;
- /**
- * put 请求头
- */
- put?: AnyObject;
- /**
- * delete 请求头
- */
- delete?: AnyObject;
- /**
- * trace 请求头
- */
- trace?: AnyObject;
- /**
- * connect 请求头
- */
- connect?: AnyObject;
- }
- /**
- * 表单数据(上传会用到)
- */
- interface AxiosRequestFormData extends AnyObject {
- /**
- * 文件名
- */
- name: string;
- /**
- * 文件路径
- */
- filePath: string;
- }
- /**
- * 请求数据
- */
- type AxiosRequestData = string | AnyObject | ArrayBuffer | AxiosRequestFormData;
- /**
- * 响应数据
- */
- type AxiosResponseData = number | AxiosAdapterResponseData;
- /**
- * 进度对象
- */
- interface AxiosProgressEvent extends AnyObject {
- /**
- * 上传进度百分比
- */
- progress: number;
- }
- /**
- * 下载进度对象
- */
- interface AxiosDownloadProgressEvent extends AxiosProgressEvent {
- /**
- * 已经下载的数据长度,单位 Bytes
- */
- totalBytesWritten: number;
- /**
- * 预预期需要下载的数据总长度,单位 Bytes
- */
- totalBytesExpectedToWrite: number;
- }
- /**
- * 监听下载进度
- */
- interface AxiosDownloadProgressCallback {
- (event: AxiosDownloadProgressEvent): void;
- }
- /**
- * 上传进度对象
- */
- interface AxiosUploadProgressEvent extends AxiosProgressEvent {
- /**
- * 已经上传的数据长度,单位 Bytes
- */
- totalBytesSent: number;
- /**
- * 预期需要上传的数据总长度,单位 Bytes
- */
- totalBytesExpectedToSend: number;
- }
- /**
- * 监听上传进度
- */
- interface AxiosUploadProgressCallback {
- (event: AxiosUploadProgressEvent): void;
- }
- /**
- * 请求配置
- */
- interface AxiosRequestConfig extends Partial<Omit<AxiosAdapterRequestConfig, 'type' | 'success' | 'fail'>> {
- /**
- * 请求适配器
- */
- adapter?: AxiosAdapter;
- /**
- * 基础路径
- */
- baseURL?: string;
- /**
- * 请求的 URL
- */
- url?: string;
- /**
- * 请求参数
- */
- params?: AnyObject;
- /**
- * 请求数据
- */
- data?: AxiosRequestData;
- /**
- * 请求头
- */
- headers?: AxiosRequestHeaders;
- /**
- * 请求方法
- */
- method?: AxiosRequestMethod;
- /**
- * 取消令牌
- */
- cancelToken?: CancelToken;
- /**
- * 下载文件
- */
- download?: boolean;
- /**
- * 上传文件
- */
- upload?: boolean;
- /**
- * 请求参数系列化函数
- */
- paramsSerializer?: (params?: AnyObject) => string;
- /**
- * 校验状态码
- */
- validateStatus?: (status: number) => boolean;
- /**
- * 转换请求数据
- */
- transformRequest?: AxiosTransformer<AxiosRequestData>;
- /**
- * 转换响应数据
- */
- transformResponse?: AxiosTransformer<AxiosResponseData>;
- /**
- * 错误处理
- */
- errorHandler?: (error: unknown) => Promise<AxiosResponse>;
- /**
- * 监听下载进度
- */
- onDownloadProgress?: AxiosUploadProgressCallback;
- /**
- * 监听上传进度
- */
- onUploadProgress?: AxiosUploadProgressCallback;
- }
- /**
- * 响应体
- */
- interface AxiosResponse<TData extends AxiosResponseData = AxiosResponseData> extends AnyObject {
- /**
- * 状态码
- */
- status: number;
- /**
- * 状态字符
- */
- statusText: string;
- /**
- * 响应头
- */
- headers: AnyObject;
- /**
- * 响应数据
- */
- data: TData;
- /**
- * 请求配置
- */
- config: AxiosRequestConfig;
- /**
- * 请求任务
- */
- request?: AxiosAdapterPlatformTask;
- }
- /**
- * 错误体
- */
- interface AxiosResponseError extends AnyObject {
- /**
- * 状态码
- */
- status: number;
- /**
- * 状态字符
- */
- statusText: string;
- /**
- * 响应头
- */
- headers: AnyObject;
- /**
- * 错误数据
- */
- data: AnyObject;
- /**
- * 失败的请求,指没能够成功响应的请求
- */
- isFail: true;
- /**
- * 请求配置
- */
- config: AxiosRequestConfig;
- /**
- * 请求任务
- */
- request?: AxiosAdapterPlatformTask;
- }
- interface AxiosRequest {
- <TData extends AxiosResponseData>(config: AxiosRequestConfig): Promise<AxiosResponse<TData>>;
- <TData extends AxiosResponseData>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<TData>>;
- }
- /**
- * 普通的请求方法
- */
- type AxiosRequestMethodFn = <TData extends AxiosResponseData>(url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<TData>>;
- /**
- * 带参数的请求方法
- */
- type AxiosRequestMethodFnWithParams = <TData extends AxiosResponseData>(url: string, params?: AnyObject, config?: AxiosRequestConfig) => Promise<AxiosResponse<TData>>;
- /**
- * 带数据的请求方法
- */
- type AxiosRequestMethodFnWithData = <TData extends AxiosResponseData>(url: string, data?: AxiosRequestData, config?: AxiosRequestConfig) => Promise<AxiosResponse<TData>>;
- /**
- * Axios 构造函数
- */
- interface AxiosConstructor {
- new (config: AxiosRequestConfig): Axios;
- }
- declare class Axios {
- #private;
- /**
- * 默认请求配置
- */
- defaults: AxiosRequestConfig;
- /**
- * 拦截器
- */
- interceptors: {
- /**
- * 请求拦截器
- */
- request: InterceptorManager<AxiosRequestConfig>;
- /**
- * 响应拦截器
- */
- response: InterceptorManager<AxiosResponse<AxiosResponseData>>;
- };
- /**
- * 发送 options 请求
- */
- options: AxiosRequestMethodFn;
- /**
- * 发送 get 请求
- */
- get: AxiosRequestMethodFnWithParams;
- /**
- * 发送 head 请求
- */
- head: AxiosRequestMethodFnWithParams;
- /**
- * 发送 post 请求
- */
- post: AxiosRequestMethodFnWithData;
- /**
- * 发送 put 请求
- */
- put: AxiosRequestMethodFnWithData;
- /**
- * 发送 patch 请求
- */
- patch: AxiosRequestMethodFnWithData;
- /**
- * 发送 delete 请求
- */
- delete: AxiosRequestMethodFnWithParams;
- /**
- * 发送 trace 请求
- */
- trace: AxiosRequestMethodFn;
- /**
- * 发送 connect 请求
- */
- connect: AxiosRequestMethodFn;
- /**
- *
- * @param config 默认配置
- * @param parent 父级实例
- */
- constructor(config: AxiosRequestConfig, parent?: Axios);
- /**
- * 发送请求
- */
- request: AxiosRequest;
- /**
- * 注册中间件
- *
- * 示例1:注册一个中间件
- * ```ts
- * axios.use(async function middleware(ctx, next) {
- * console.log(ctx.req);
- * await next();
- * console.log(ctx.res);
- * });
- * ```
- *
- * 示例2:链式注册多个中间件
- * ```ts
- * axios
- * .use(async function middleware1(ctx, next) {
- * console.log(ctx.req);
- * await next();
- * console.log(ctx.res);
- * })
- * .use(async function middleware2(ctx, next) {
- * console.log(ctx.req);
- * await next();
- * console.log(ctx.res);
- * });
- * ```
- */
- use: (middleware: MiddlewareCallback) => this;
- }
- /**
- * 适配器请求方法
- */
- type AxiosAdapterRequestMethod = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'TRACE' | 'CONNECT';
- /**
- * 适配器请求数据
- */
- type AxiosAdapterRequestData = string | AnyObject | ArrayBuffer;
- /**
- * 适配器响应数据
- */
- type AxiosAdapterResponseData = string | ArrayBuffer | AnyObject;
- /**
- * 适配器响应体
- */
- interface AxiosAdapterResponse extends AnyObject {
- /**
- * 状态码
- */
- status?: number;
- /**
- * 状态字符
- */
- statusText?: string;
- /**
- * 响应头
- */
- headers?: AnyObject;
- /**
- * 响应数据
- */
- data: AxiosAdapterResponseData;
- }
- /**
- * 适配器错误体
- */
- interface AxiosAdapterResponseError extends AnyObject {
- /**
- * 状态码
- */
- status?: number;
- /**
- * 状态字符
- */
- statusText?: string;
- /**
- * 响应头
- */
- headers?: AnyObject;
- /**
- * 错误数据
- */
- data?: AnyObject;
- }
- /**
- * 适配器请求配置
- */
- interface AxiosAdapterRequestConfig extends AnyObject {
- /**
- * 请求类型
- */
- type: 'request' | 'upload' | 'download';
- /**
- * 开发者服务器接口地址
- */
- url: string;
- /**
- * HTTP 请求方法
- */
- method: AxiosAdapterRequestMethod;
- /**
- * 请求参数
- */
- params?: AnyObject;
- /**
- * 请求数据
- */
- data?: AxiosAdapterRequestData;
- /**
- * 请求头
- */
- headers?: AnyObject;
- /**
- * 返回的数据格式
- */
- dataType?: 'json' | '其他';
- /**
- * 响应的数据类型
- */
- responseType?: 'text' | 'arraybuffer';
- /**
- * 超时时间,单位为毫秒。默认值为 60000
- */
- timeout?: number;
- /**
- * 成功的回调
- */
- success(response: AxiosAdapterResponse): void;
- /**
- * 失败的回调
- */
- fail(error: AxiosAdapterResponseError): void;
- }
- /**
- * 请求函数基本选项
- */
- interface AxiosAdapterBaseOptions extends AxiosAdapterRequestConfig {
- /**
- * 请求头,同 headers
- */
- header?: AxiosRequestHeaders;
- /**
- * 成功的回调
- */
- success(response: AnyObject): void;
- /**
- * 失败的回调
- */
- fail(error: AnyObject): void;
- }
- /**
- * 请求函数选项
- */
- type AxiosAdapterRequestOptions = AxiosAdapterBaseOptions;
- /**
- * 下载函数选项
- */
- interface AxiosAdapterDownloadOptions extends AxiosAdapterBaseOptions {
- /**
- * 文件下载后存储的路径
- */
- filePath?: string;
- }
- /**
- * 上传函数选项
- */
- interface AxiosAdapterUploadOptions extends AxiosAdapterBaseOptions, AxiosRequestFormData {
- /**
- * [钉钉小程序用 fileName 代替 name](https://open.dingtalk.com/document/orgapp/dd-upload-objects#title-ngk-rr1-eow)
- */
- fileName: string;
- /**
- * 钉钉小程序|支付宝小程序特有参数
- */
- fileType?: 'image' | 'video' | 'audie';
- /**
- * 额外的数据
- */
- formData?: AnyObject;
- }
- /**
- * 请求函数
- */
- interface AxiosAdapterRequest {
- (config: AxiosAdapterRequestOptions): AxiosAdapterPlatformTask;
- }
- /**
- * 下载函数
- */
- interface AxiosAdapterDownload {
- (config: AxiosAdapterDownloadOptions): AxiosAdapterPlatformTask;
- }
- /**
- * 上传函数
- */
- interface AxiosAdapterUpload {
- (config: AxiosAdapterUploadOptions): AxiosAdapterPlatformTask;
- }
- /**
- * 适配器平台
- */
- interface AxiosAdapterPlatform {
- /**
- * 发送请求
- */
- request: AxiosAdapterRequest;
- /**
- * 下载文件
- */
- download: AxiosAdapterDownload;
- /**
- * 上传文件
- */
- upload: AxiosAdapterUpload;
- }
- /**
- * 适配器平台请求任务
- */
- type AxiosAdapterPlatformTask = undefined | void | {
- abort?(): void;
- onProgressUpdate?(callback: (event: AxiosProgressEvent) => void): void;
- offProgressUpdate?(callback: (event: AxiosProgressEvent) => void): void;
- };
- /**
- * 适配器函数
- */
- interface AxiosAdapter {
- (config: AxiosAdapterRequestConfig): AxiosAdapterPlatformTask;
- }
- /**
- * 创建适配器
- *
- * @param platform 平台 API 对象
- */
- declare function createAdapter(platform: AxiosAdapterPlatform): (config: AxiosAdapterRequestConfig) => AxiosAdapterPlatformTask;
- type AxiosErrorResponse = AxiosResponse | AxiosResponseError;
- declare class AxiosError extends Error {
- config: AxiosRequestConfig;
- request: AxiosAdapterPlatformTask;
- response: AxiosErrorResponse;
- constructor(message: string, config: AxiosRequestConfig, response: AxiosErrorResponse, request: AxiosAdapterPlatformTask);
- }
- declare function isAxiosError(value: unknown): value is AxiosError;
- /**
- * axios 实例默认配置
- */
- interface AxiosInstanceDefaults extends AxiosRequestConfig {
- /**
- * 请求头
- */
- headers: Required<AxiosRequestHeaders>;
- }
- /**
- * axios 实例
- */
- interface AxiosInstance extends AxiosRequest, Axios {
- /**
- * 默认请求配置
- */
- defaults: AxiosInstanceDefaults;
- /**
- * 获取 URI
- *
- * @param config 配置
- */
- getUri(config: AxiosRequestConfig): string;
- /**
- * 创建实例
- *
- * @param config 默认配置
- */
- create(config?: AxiosRequestConfig): AxiosInstance;
- /**
- * 扩展实例
- *
- * @param config 默认配置
- */
- extend(config: AxiosRequestConfig): AxiosInstance;
- /**
- * 派生领域
- *
- * @param config 默认配置
- *
- * @deprecated 请使用 extend 替换 fork
- */
- fork(config: AxiosRequestConfig): AxiosInstance;
- }
- /**
- * axios 静态对象
- */
- interface AxiosStatic extends AxiosInstance {
- /**
- * 版本号
- */
- version: string;
- /**
- * Axios 类
- */
- Axios: AxiosConstructor;
- /**
- * 取消令牌
- */
- CancelToken: CancelTokenConstructor;
- /**
- * 创建适配器
- */
- createAdapter: typeof createAdapter;
- /**
- * 传入取消请求错误返回 true
- */
- isCancel: typeof isCancel;
- /**
- * 传入响应错误返回 true
- */
- isAxiosError: typeof isAxiosError;
- }
- declare const axios: AxiosStatic;
- declare const version = "2.5.0";
- export { Axios, AxiosAdapter, AxiosAdapterDownload, AxiosAdapterDownloadOptions, AxiosAdapterPlatform, AxiosAdapterPlatformTask, AxiosAdapterRequest, AxiosAdapterRequestConfig, AxiosAdapterRequestMethod, AxiosAdapterRequestOptions, AxiosAdapterResponse, AxiosAdapterResponseData, AxiosAdapterResponseError, AxiosAdapterUpload, AxiosAdapterUploadOptions, AxiosDownloadProgressCallback, AxiosDownloadProgressEvent, AxiosInstance, AxiosInstanceDefaults, AxiosRequestConfig, AxiosRequestData, AxiosRequestFormData, AxiosRequestHeaders, AxiosRequestMethod, AxiosResponse, AxiosResponseData, AxiosResponseError, AxiosStatic, AxiosUploadProgressCallback, AxiosUploadProgressEvent, CancelToken, MiddlewareCallback, MiddlewareContext, MiddlewareNext, createAdapter, axios as default, isAxiosError, isCancel, version };
|