@@ -4,6 +4,7 @@ import { ICacheLike } from './utils';
44import type { XiorPlugin , XiorRequestConfig , XiorResponse } from '../types' ;
55import { XiorError , joinPath , isAbsoluteURL , buildSortedURL } from '../utils' ;
66import { f , GET , undefinedValue } from '../shorts' ;
7+ import { mergeConfig } from '..' ;
78
89export type XiorErrorCacheOptions = {
910 /**
@@ -18,11 +19,8 @@ export type XiorErrorCacheOptions = {
1819 /** max cache numbers in LRU, default is 100 */
1920 cacheItems ?: number ;
2021
21- /** remove the key from data/params */
22- omitKey ?: (
23- data ?: Record < string , string > ,
24- params ?: Record < string , string >
25- ) => { data ?: Record < string , string > ; params ?: Record < string , string > } ;
22+ /** Process the config before generating the key based on data/params. The config is a new object, not a request reference. */
23+ normalizeParams ?: ( config : XiorRequestConfig ) => XiorRequestConfig ;
2624} ;
2725
2826/** @ts -ignore */
@@ -40,7 +38,7 @@ declare module 'xior' {
4038export default function xiorErrorCachePlugin ( options : XiorErrorCacheOptions = { } ) : XiorPlugin {
4139 const {
4240 enableCache : _enableCache ,
43- omitKey : _omitKey ,
41+ normalizeParams : _normalizeParams ,
4442 defaultCache : _defaultCache = lru < {
4543 loading ?: boolean ;
4644 res ?: XiorResponse ;
@@ -54,7 +52,7 @@ export default function xiorErrorCachePlugin(options: XiorErrorCacheOptions = {}
5452 return async ( config ) => {
5553 const {
5654 enableCache = _enableCache ,
57- omitKey = _omitKey ,
55+ normalizeParams = _normalizeParams ,
5856 defaultCache = _defaultCache ,
5957 useCacheFirst = _inBg ,
6058 onCacheRequest = _cacheRequest ,
@@ -77,7 +75,7 @@ export default function xiorErrorCachePlugin(options: XiorErrorCacheOptions = {}
7775 if ( ! enabled ) return adapter ( config ) ;
7876
7977 const cache = defaultCache ;
80- const { data, params } = omitKey ?.( config . data , config . params ) || config ;
78+ const { data, params } = normalizeParams ?.( mergeConfig ( config , { } ) ) || config ;
8179 const index = buildSortedURL (
8280 config . url && isAbsoluteURL ( config . url ) ? config . url : joinPath ( config . baseURL , config . url ) ,
8381 { a : data , b : params } ,
0 commit comments