UNPKG

@uozi-admin/request

Version:

Easy to create curd request functions.

66 lines (59 loc) 3.15 kB
import * as axios from 'axios'; import { AxiosRequestConfig, Method, InternalAxiosRequestConfig, AxiosInterceptorOptions } from 'axios'; export * from 'axios'; declare const service: axios.AxiosInstance; /** * @deprecated use createRequestConfig instead */ declare function setOverrideConfig(userConfig: AxiosRequestConfig): void; type RequestConfig = AxiosRequestConfig & { curd?: { methods?: { getList?: Method; getItem?: Method; createItem?: Method; updateItem?: Method; deleteItem?: Method; restoreItem?: Method; }; }; }; /** * @private * @description internal config */ declare const config: RequestConfig; /** * @description set request and curd api config */ declare function setRequestConfig(userConfig: RequestConfig): RequestConfig; declare const http: { get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>; post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>; put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>; delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>; patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>; }; declare function useAxios(): { service: axios.AxiosInstance; setRequestInterceptor(onFulfilled: (value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>, onRejected?: (error: any) => any | null, options?: AxiosInterceptorOptions): void; setResponseInterceptor(onFulfilled: (value: any) => any | Promise<any>, onRejected?: (error: any) => any | null): void; }; type ApiMethod<TParams = any, TResponse = any> = (...args: TParams[]) => Promise<TResponse>; type MoreApis = Record<string, ApiMethod>; interface BaseCurdApi<T = any, P = any> { getList: (params?: Record<string, any>, config?: AxiosRequestConfig) => Promise<{ data: T[]; pagination: P; }>; getItem: (id: string | number, params?: Record<string, any>, config?: AxiosRequestConfig) => Promise<T>; createItem: (data: Record<string, any>, config?: AxiosRequestConfig) => Promise<T>; updateItem: (id: string | number, data: Record<string, any>, config?: AxiosRequestConfig) => Promise<T>; deleteItem: (id: string | number, params?: Record<string, any>, config?: AxiosRequestConfig) => Promise<any>; restoreItem: (id: string | number, params?: Record<string, any>, config?: AxiosRequestConfig) => Promise<any>; getUrl: () => string; } type CurdApi<T = any, P = any, M extends MoreApis = MoreApis> = BaseCurdApi<T, P> & M; declare function useCurdApi<T = any, P = any, M extends MoreApis = MoreApis>(url: string | (() => string), moreApis?: M): CurdApi<T, P, M>; declare function extendCurdApi<T, M extends MoreApis, N extends MoreApis>(baseCurd: CurdApi<T, any, M>, newApis: N): CurdApi<T, any, M & N>; export { type ApiMethod, type BaseCurdApi, type CurdApi, type MoreApis, type RequestConfig, config, extendCurdApi, http, service, setOverrideConfig, setRequestConfig, useAxios, useCurdApi };