UNPKG

2.91 kBTypeScriptView Raw
1import type { CacheAxiosResponse } from 'axios-cache-interceptor';
2/**
3 * All available options for the `axios-cache-hooks` package.
4 *
5 * @see https://tinylibs.js.org/packages/axios-cache-hooks
6 */
7export declare type AxiosCacheHooksOptions = {
8 /**
9 * A function that must return parameter index that accepts a `CacheRequestConfig` object.
10 *
11 * **Tip**: You can use `function.length` to find the number of available parameters.
12 *
13 * Default implementation returns the last function parameter.
14 *
15 * @default defaultConfigIndexFinder
16 * @param {Function} fn The provided axios call function
17 * @param {any[]} args All provided arguments to the function. Note, unprovided
18 * arguments won't be present in the array.
19 * @see {@link defaultConfigIndexFinder}
20 */
21 configIndexFinder: ConfigIndexFinder;
22 /**
23 * A function that returns a unique id for a given response or error.
24 *
25 * Used to determine if a response is different than the previous one by comparing its
26 * generated hash.
27 *
28 * Default implementation uses `object-code` library.
29 *
30 * **Note**: Returning undefined will ignore the given error or response.
31 *
32 * @default defaultHashGenerator
33 * @param {CacheAxiosResponse} [response] The axios response, if present.
34 * @param {any} [error] A thrown error, if any
35 * @see {@link defaultHashGenerator}
36 */
37 hashGenerator: HashGenerator;
38};
39/**
40 * A function that must return parameter index that accepts a `CacheRequestConfig` object.
41 *
42 * **Tip**: You can use `function.length` to find the number of available parameters.
43 *
44 * Default implementation returns the last function parameter.
45 *
46 * @default defaultConfigIndexFinder
47 * @param {Function} fn The provided axios call function
48 * @param {any[]} args All provided arguments to the function. Note, unprovided arguments
49 * won't be present in the array.
50 * @see {@link defaultConfigIndexFinder}
51 */
52export declare type ConfigIndexFinder = (fn: Function, ...args: any[]) => number;
53/**
54 * A function that returns a unique id for a given response or error.
55 *
56 * Used to determine if a response is different than the previous one by comparing its
57 * generated hash.
58 *
59 * Default implementation uses `object-code` library.
60 *
61 * **Note**: Returning undefined will ignore the given error or response.
62 *
63 * @default defaultHashGenerator
64 * @param {CacheAxiosResponse} [response] The axios response, if present.
65 * @param {any} [error] A thrown error, if any
66 * @see {@link defaultHashGenerator}
67 */
68export declare type HashGenerator = (response?: CacheAxiosResponse, error?: any) => number;
69export declare const defaultConfigIndexFinder: ConfigIndexFinder;
70export declare const defaultHashGenerator: HashGenerator;
71//# sourceMappingURL=options.d.ts.map
\No newline at end of file