You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.2 KiB

  1. export interface AxiosTransformer {
  2. (data: any, headers?: any): any;
  3. }
  4. export interface AxiosAdapter {
  5. (config: AxiosRequestConfig): AxiosPromise<any>;
  6. }
  7. export interface AxiosBasicCredentials {
  8. username: string;
  9. password: string;
  10. }
  11. export interface AxiosProxyConfig {
  12. host: string;
  13. port: number;
  14. auth?: {
  15. username: string;
  16. password:string;
  17. };
  18. protocol?: string;
  19. }
  20. export type Method =
  21. | 'get' | 'GET'
  22. | 'delete' | 'DELETE'
  23. | 'head' | 'HEAD'
  24. | 'options' | 'OPTIONS'
  25. | 'post' | 'POST'
  26. | 'put' | 'PUT'
  27. | 'patch' | 'PATCH'
  28. | 'purge' | 'PURGE'
  29. | 'link' | 'LINK'
  30. | 'unlink' | 'UNLINK'
  31. export type ResponseType =
  32. | 'arraybuffer'
  33. | 'blob'
  34. | 'document'
  35. | 'json'
  36. | 'text'
  37. | 'stream'
  38. export interface AxiosRequestConfig {
  39. url?: string;
  40. method?: Method;
  41. baseURL?: string;
  42. transformRequest?: AxiosTransformer | AxiosTransformer[];
  43. transformResponse?: AxiosTransformer | AxiosTransformer[];
  44. headers?: any;
  45. params?: any;
  46. paramsSerializer?: (params: any) => string;
  47. data?: any;
  48. timeout?: number;
  49. timeoutErrorMessage?: string;
  50. withCredentials?: boolean;
  51. adapter?: AxiosAdapter;
  52. auth?: AxiosBasicCredentials;
  53. responseType?: ResponseType;
  54. xsrfCookieName?: string;
  55. xsrfHeaderName?: string;
  56. onUploadProgress?: (progressEvent: ProgressEvent) => void;
  57. onDownloadProgress?: (progressEvent: ProgressEvent) => void;
  58. maxContentLength?: number;
  59. validateStatus?: ((status: number) => boolean | null);
  60. maxBodyLength?: number;
  61. maxRedirects?: number;
  62. socketPath?: string | null;
  63. httpAgent?: any;
  64. httpsAgent?: any;
  65. proxy?: AxiosProxyConfig | false;
  66. cancelToken?: CancelToken;
  67. decompress?: boolean;
  68. }
  69. export interface AxiosResponse<T = any> {
  70. data: T;
  71. status: number;
  72. statusText: string;
  73. headers: any;
  74. config: AxiosRequestConfig;
  75. request?: any;
  76. }
  77. export interface AxiosError<T = any> extends Error {
  78. config: AxiosRequestConfig;
  79. code?: string;
  80. request?: any;
  81. response?: AxiosResponse<T>;
  82. isAxiosError: boolean;
  83. toJSON: () => object;
  84. }
  85. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  86. }
  87. export interface CancelStatic {
  88. new (message?: string): Cancel;
  89. }
  90. export interface Cancel {
  91. message: string;
  92. }
  93. export interface Canceler {
  94. (message?: string): void;
  95. }
  96. export interface CancelTokenStatic {
  97. new (executor: (cancel: Canceler) => void): CancelToken;
  98. source(): CancelTokenSource;
  99. }
  100. export interface CancelToken {
  101. promise: Promise<Cancel>;
  102. reason?: Cancel;
  103. throwIfRequested(): void;
  104. }
  105. export interface CancelTokenSource {
  106. token: CancelToken;
  107. cancel: Canceler;
  108. }
  109. export interface AxiosInterceptorManager<V> {
  110. use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  111. eject(id: number): void;
  112. }
  113. export interface AxiosInstance {
  114. (config: AxiosRequestConfig): AxiosPromise;
  115. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  116. defaults: AxiosRequestConfig;
  117. interceptors: {
  118. request: AxiosInterceptorManager<AxiosRequestConfig>;
  119. response: AxiosInterceptorManager<AxiosResponse>;
  120. };
  121. getUri(config?: AxiosRequestConfig): string;
  122. request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
  123. get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  124. delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  125. head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  126. options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  127. post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  128. put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  129. patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  130. }
  131. export interface AxiosStatic extends AxiosInstance {
  132. create(config?: AxiosRequestConfig): AxiosInstance;
  133. Cancel: CancelStatic;
  134. CancelToken: CancelTokenStatic;
  135. isCancel(value: any): boolean;
  136. all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  137. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  138. }
  139. declare const Axios: AxiosStatic;
  140. export default Axios;