UNPKG

xior

Version:

A lite http request lib based on fetch with plugins support and similar API to axios.

33 lines (30 loc) 1.26 kB
import { a as XiorRequestConfig, I as ICacheLike, d as XiorResponse, k as XiorError, e as XiorPlugin } from '../xior-D4BXsC0R.mjs'; type XiorErrorCacheOptions = { /** * check if we need enable cache, default only `GET` method or`isGet: true` enable cache @error-cache-plugin */ enableCache?: boolean | ((config?: XiorRequestConfig) => boolean); defaultCache?: ICacheLike<{ loading?: boolean; res?: XiorResponse; cacheTime?: number; }>; /** if `useCacheFirst: true` and have cache, will return the cache response first, then run fetching in the background @error-cache-plugin */ useCacheFirst?: boolean; /** for logging purpose @error-cache-plugin */ onCacheRequest?: (config?: XiorRequestConfig) => void; /** max cache numbers in LRU, default is 100 */ cacheItems?: number; }; /** @ts-ignore */ declare module 'xior' { interface XiorRequestConfig extends Omit<XiorErrorCacheOptions, 'cacheItems'> { } interface XiorResponse { fromCache?: boolean; error?: XiorError; cacheTime?: number; } } declare function xiorErrorCachePlugin(options?: XiorErrorCacheOptions): XiorPlugin; export { type XiorErrorCacheOptions, xiorErrorCachePlugin as default };