UNPKG

wretch-middlewares

Version:

Middlewares for the wretch library

32 lines (31 loc) 1.16 kB
import { ConfiguredMiddleware, WretcherOptions } from 'wretch'; export declare type DedupeSkipFunction = (url: string, opts: WretcherOptions) => boolean; export declare type DedupeKeyFunction = (url: string, opts: WretcherOptions) => string; export declare type DedupeResolverFunction = (response: Response) => Response; export declare type DedupeOptions = { skip?: DedupeSkipFunction; key?: DedupeKeyFunction; resolver?: DedupeResolverFunction; }; export declare type DedupeMiddleware = (options?: DedupeOptions) => ConfiguredMiddleware; /** * ## Dedupe middleware * * #### Prevents having multiple identical requests on the fly at the same time. * * **Options** * * - *skip* `(url, opts) => boolean` * * > If skip returns true, then the dedupe check is skipped. * * - *key* `(url, opts) => string` * * > Returns a key that is used to identify the request. * * - *resolver* `(response: Response) => Response` * * > This function is called when resolving the fetch response from duplicate calls. * By default it clones the response to allow reading the body from multiple sources. */ export declare const dedupe: DedupeMiddleware;