request.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { DageRequestConfig, DageResponse, Interceptor, PaginationParams, PaginationResponse } from "./types";
  2. export interface ServiceAdapter {
  3. baseURL: string;
  4. fetch: typeof fetch;
  5. /**
  6. * 拦截器
  7. */
  8. interceptor?: Interceptor;
  9. /**
  10. * 全局变量
  11. */
  12. globalVariables?: Record<string, any>;
  13. }
  14. export declare function createService(): {
  15. getBaseURL: () => string;
  16. parseResponse: (response: DageResponse | PaginationResponse) => DageResponse | PaginationResponse;
  17. initial: (options: ServiceAdapter) => void;
  18. isInitialized: () => boolean;
  19. request: <R = any, P extends {} = any>(url: string, body?: P | undefined, config?: DageRequestConfig) => Promise<R>;
  20. requestByPost: <R = any, P extends {} = any>(url: string, body?: P | undefined, config?: DageRequestConfig) => Promise<R>;
  21. requestByGet: <R_1 = any, P_1 extends {} = any>(url: string, body?: P_1 | undefined, config?: DageRequestConfig) => Promise<R_1>;
  22. requestPagination: <R_2 = any, P_2 extends PaginationParams = any>(name: string, body?: P_2 | undefined, config?: DageRequestConfig) => Promise<PaginationResponse<R_2>>;
  23. };
  24. /**
  25. * 获取 Base URL
  26. * @returns
  27. */
  28. export declare const getBaseURL: () => string;
  29. /**
  30. * 解析响应
  31. * @param response
  32. * @returns
  33. */
  34. export declare const parseResponse: (response: DageResponse | PaginationResponse) => DageResponse | PaginationResponse;
  35. /**
  36. * 是否初始化完成
  37. * @returns
  38. */
  39. export declare const isInitialized: () => boolean;
  40. /**
  41. * 初始化
  42. * @param options
  43. */
  44. export declare const initial: (options: ServiceAdapter) => void;
  45. export declare const request: <R = any, P extends {} = any>(url: string, body?: P | undefined, config?: DageRequestConfig) => Promise<R>;
  46. export declare const requestByPost: <R = any, P extends {} = any>(url: string, body?: P | undefined, config?: DageRequestConfig) => Promise<R>;
  47. export declare const requestByGet: <R = any, P extends {} = any>(url: string, body?: P | undefined, config?: DageRequestConfig) => Promise<R>;
  48. export declare const requestPagination: <R = any, P extends PaginationParams = any>(name: string, body?: P | undefined, config?: DageRequestConfig) => Promise<PaginationResponse<R>>;
  49. //# sourceMappingURL=request.d.ts.map