axios-extensions
Advanced tools
Comparing version 3.1.6 to 3.1.7
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["axios-extensions"] = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('axios')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'axios'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["axios-extensions"] = {}, global.axios)); | ||
})(this, (function (exports, axios) { 'use strict'; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); | ||
const perf = | ||
@@ -26,4 +30,9 @@ typeof performance === 'object' && | ||
} | ||
abort() { | ||
this.signal.dispatchEvent('abort'); | ||
abort(reason = new Error('This operation was aborted')) { | ||
this.signal.reason = this.signal.reason || reason; | ||
this.signal.aborted = true; | ||
this.signal.dispatchEvent({ | ||
type: 'abort', | ||
target: this.signal, | ||
}); | ||
} | ||
@@ -41,9 +50,9 @@ }; | ||
constructor() { | ||
this.reason = undefined; | ||
this.aborted = false; | ||
this._listeners = []; | ||
} | ||
dispatchEvent(type) { | ||
if (type === 'abort') { | ||
dispatchEvent(e) { | ||
if (e.type === 'abort') { | ||
this.aborted = true; | ||
const e = { type, target: this }; | ||
this.onabort(e); | ||
@@ -174,2 +183,5 @@ this._listeners.forEach(f => f(e), this); | ||
noDeleteOnStaleGet, | ||
allowStaleOnFetchRejection, | ||
allowStaleOnFetchAbort, | ||
ignoreFetchAbort, | ||
} = options; | ||
@@ -244,2 +256,5 @@ | ||
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection; | ||
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection; | ||
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort; | ||
this.ignoreFetchAbort = !!ignoreFetchAbort; | ||
@@ -338,2 +353,11 @@ // NB: maxEntrySize is set to maxSize if it's set | ||
this.statusTTL = (status, index) => { | ||
if (status) { | ||
status.ttl = this.ttls[index]; | ||
status.start = this.starts[index]; | ||
status.now = cachedNow || getNow(); | ||
status.remainingTTL = status.now + status.ttl - status.start; | ||
} | ||
}; | ||
// debounce calls to perf.now() to 1s so we're not hitting | ||
@@ -379,5 +403,6 @@ // that costly call repeatedly. | ||
} | ||
updateItemAge(index) {} | ||
setItemTTL(index, ttl, start) {} | ||
isStale(index) { | ||
updateItemAge(_index) {} | ||
statusTTL(_status, _index) {} | ||
setItemTTL(_index, _ttl, _start) {} | ||
isStale(_index) { | ||
return false | ||
@@ -394,2 +419,7 @@ } | ||
this.requireSize = (k, v, size, sizeCalculation) => { | ||
// provisionally accept background fetches. | ||
// actual value size will be checked when they return. | ||
if (this.isBackgroundFetch(v)) { | ||
return 0 | ||
} | ||
if (!isPosInt(size)) { | ||
@@ -408,3 +438,5 @@ if (sizeCalculation) { | ||
throw new TypeError( | ||
'invalid size value (must be positive integer)' | ||
'invalid size value (must be positive integer). ' + | ||
'When maxSize or maxEntrySize is used, sizeCalculation or size ' + | ||
'must be set.' | ||
) | ||
@@ -415,14 +447,20 @@ } | ||
}; | ||
this.addItemSize = (index, size) => { | ||
this.addItemSize = (index, size, status) => { | ||
this.sizes[index] = size; | ||
const maxSize = this.maxSize - this.sizes[index]; | ||
while (this.calculatedSize > maxSize) { | ||
this.evict(true); | ||
if (this.maxSize) { | ||
const maxSize = this.maxSize - this.sizes[index]; | ||
while (this.calculatedSize > maxSize) { | ||
this.evict(true); | ||
} | ||
} | ||
this.calculatedSize += this.sizes[index]; | ||
if (status) { | ||
status.entrySize = size; | ||
status.totalCalculatedSize = this.calculatedSize; | ||
} | ||
}; | ||
} | ||
removeItemSize(index) {} | ||
addItemSize(index, size) {} | ||
requireSize(k, v, size, sizeCalculation) { | ||
removeItemSize(_index) {} | ||
addItemSize(_index, _size) {} | ||
requireSize(_k, _v, size, sizeCalculation) { | ||
if (size || sizeCalculation) { | ||
@@ -472,3 +510,6 @@ throw new TypeError( | ||
isValidIndex(index) { | ||
return this.keyMap.get(this.keyList[index]) === index | ||
return ( | ||
index !== undefined && | ||
this.keyMap.get(this.keyList[index]) === index | ||
) | ||
} | ||
@@ -478,3 +519,9 @@ | ||
for (const i of this.indexes()) { | ||
yield [this.keyList[i], this.valList[i]]; | ||
if ( | ||
this.valList[i] !== undefined && | ||
this.keyList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield [this.keyList[i], this.valList[i]]; | ||
} | ||
} | ||
@@ -484,3 +531,9 @@ } | ||
for (const i of this.rindexes()) { | ||
yield [this.keyList[i], this.valList[i]]; | ||
if ( | ||
this.valList[i] !== undefined && | ||
this.keyList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield [this.keyList[i], this.valList[i]]; | ||
} | ||
} | ||
@@ -491,3 +544,8 @@ } | ||
for (const i of this.indexes()) { | ||
yield this.keyList[i]; | ||
if ( | ||
this.keyList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield this.keyList[i]; | ||
} | ||
} | ||
@@ -497,3 +555,8 @@ } | ||
for (const i of this.rindexes()) { | ||
yield this.keyList[i]; | ||
if ( | ||
this.keyList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield this.keyList[i]; | ||
} | ||
} | ||
@@ -504,3 +567,8 @@ } | ||
for (const i of this.indexes()) { | ||
yield this.valList[i]; | ||
if ( | ||
this.valList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield this.valList[i]; | ||
} | ||
} | ||
@@ -510,3 +578,8 @@ } | ||
for (const i of this.rindexes()) { | ||
yield this.valList[i]; | ||
if ( | ||
this.valList[i] !== undefined && | ||
!this.isBackgroundFetch(this.valList[i]) | ||
) { | ||
yield this.valList[i]; | ||
} | ||
} | ||
@@ -519,5 +592,10 @@ } | ||
find(fn, getOptions = {}) { | ||
find(fn, getOptions) { | ||
for (const i of this.indexes()) { | ||
if (fn(this.valList[i], this.keyList[i], this)) { | ||
const v = this.valList[i]; | ||
const value = this.isBackgroundFetch(v) | ||
? v.__staleWhileFetching | ||
: v; | ||
if (value === undefined) continue | ||
if (fn(value, this.keyList[i], this)) { | ||
return this.get(this.keyList[i], getOptions) | ||
@@ -530,3 +608,8 @@ } | ||
for (const i of this.indexes()) { | ||
fn.call(thisp, this.valList[i], this.keyList[i], this); | ||
const v = this.valList[i]; | ||
const value = this.isBackgroundFetch(v) | ||
? v.__staleWhileFetching | ||
: v; | ||
if (value === undefined) continue | ||
fn.call(thisp, value, this.keyList[i], this); | ||
} | ||
@@ -537,3 +620,8 @@ } | ||
for (const i of this.rindexes()) { | ||
fn.call(thisp, this.valList[i], this.keyList[i], this); | ||
const v = this.valList[i]; | ||
const value = this.isBackgroundFetch(v) | ||
? v.__staleWhileFetching | ||
: v; | ||
if (value === undefined) continue | ||
fn.call(thisp, value, this.keyList[i], this); | ||
} | ||
@@ -566,2 +654,3 @@ } | ||
: v; | ||
if (value === undefined) continue | ||
const entry = { value }; | ||
@@ -597,3 +686,3 @@ if (this.ttls) { | ||
dispose(v, k, reason) {} | ||
dispose(_v, _k, _reason) {} | ||
@@ -610,2 +699,3 @@ set( | ||
noUpdateTTL = this.noUpdateTTL, | ||
status, | ||
} = {} | ||
@@ -617,2 +707,9 @@ ) { | ||
if (this.maxEntrySize && size > this.maxEntrySize) { | ||
if (status) { | ||
status.set = 'miss'; | ||
status.maxEntrySizeExceeded = true; | ||
} | ||
// have to delete, in case a background fetch is there already. | ||
// in non-async cases, this is a no-op | ||
this.delete(k); | ||
return this | ||
@@ -631,10 +728,14 @@ } | ||
this.size++; | ||
this.addItemSize(index, size); | ||
this.addItemSize(index, size, status); | ||
if (status) { | ||
status.set = 'add'; | ||
} | ||
noUpdateTTL = false; | ||
} else { | ||
// update | ||
this.moveToTail(index); | ||
const oldVal = this.valList[index]; | ||
if (v !== oldVal) { | ||
if (this.isBackgroundFetch(oldVal)) { | ||
oldVal.__abortController.abort(); | ||
oldVal.__abortController.abort(new Error('replaced')); | ||
} else { | ||
@@ -650,5 +751,14 @@ if (!noDisposeOnSet) { | ||
this.valList[index] = v; | ||
this.addItemSize(index, size); | ||
this.addItemSize(index, size, status); | ||
if (status) { | ||
status.set = 'replace'; | ||
const oldValue = | ||
oldVal && this.isBackgroundFetch(oldVal) | ||
? oldVal.__staleWhileFetching | ||
: oldVal; | ||
if (oldValue !== undefined) status.oldValue = oldValue; | ||
} | ||
} else if (status) { | ||
status.set = 'update'; | ||
} | ||
this.moveToTail(index); | ||
} | ||
@@ -661,2 +771,3 @@ if (ttl !== 0 && this.ttl === 0 && !this.ttls) { | ||
} | ||
this.statusTTL(status, index); | ||
if (this.disposeAfter) { | ||
@@ -697,3 +808,3 @@ while (this.disposed.length) { | ||
if (this.isBackgroundFetch(v)) { | ||
v.__abortController.abort(); | ||
v.__abortController.abort(new Error('evicted')); | ||
} else { | ||
@@ -718,3 +829,3 @@ this.dispose(v, k, 'evict'); | ||
has(k, { updateAgeOnHas = this.updateAgeOnHas } = {}) { | ||
has(k, { updateAgeOnHas = this.updateAgeOnHas, status } = {}) { | ||
const index = this.keyMap.get(k); | ||
@@ -726,4 +837,11 @@ if (index !== undefined) { | ||
} | ||
if (status) status.has = 'hit'; | ||
this.statusTTL(status, index); | ||
return true | ||
} else if (status) { | ||
status.has = 'stale'; | ||
this.statusTTL(status, index); | ||
} | ||
} else if (status) { | ||
status.has = 'miss'; | ||
} | ||
@@ -749,2 +867,7 @@ return false | ||
const ac = new AC(); | ||
if (options.signal) { | ||
options.signal.addEventListener('abort', () => | ||
ac.abort(options.signal.reason) | ||
); | ||
} | ||
const fetchOpts = { | ||
@@ -755,26 +878,88 @@ signal: ac.signal, | ||
}; | ||
const cb = v => { | ||
if (!ac.signal.aborted) { | ||
this.set(k, v, fetchOpts.options); | ||
const cb = (v, updateCache = false) => { | ||
const { aborted } = ac.signal; | ||
const ignoreAbort = options.ignoreFetchAbort && v !== undefined; | ||
if (options.status) { | ||
if (aborted && !updateCache) { | ||
options.status.fetchAborted = true; | ||
options.status.fetchError = ac.signal.reason; | ||
if (ignoreAbort) options.status.fetchAbortIgnored = true; | ||
} else { | ||
options.status.fetchResolved = true; | ||
} | ||
} | ||
if (aborted && !ignoreAbort && !updateCache) { | ||
return fetchFail(ac.signal.reason) | ||
} | ||
// either we didn't abort, and are still here, or we did, and ignored | ||
if (this.valList[index] === p) { | ||
if (v === undefined) { | ||
if (p.__staleWhileFetching) { | ||
this.valList[index] = p.__staleWhileFetching; | ||
} else { | ||
this.delete(k); | ||
} | ||
} else { | ||
if (options.status) options.status.fetchUpdated = true; | ||
this.set(k, v, fetchOpts.options); | ||
} | ||
} | ||
return v | ||
}; | ||
const eb = er => { | ||
if (options.status) { | ||
options.status.fetchRejected = true; | ||
options.status.fetchError = er; | ||
} | ||
return fetchFail(er) | ||
}; | ||
const fetchFail = er => { | ||
const { aborted } = ac.signal; | ||
const allowStaleAborted = | ||
aborted && options.allowStaleOnFetchAbort; | ||
const allowStale = | ||
allowStaleAborted || options.allowStaleOnFetchRejection; | ||
const noDelete = allowStale || options.noDeleteOnFetchRejection; | ||
if (this.valList[index] === p) { | ||
const del = | ||
!options.noDeleteOnFetchRejection || | ||
p.__staleWhileFetching === undefined; | ||
// if we allow stale on fetch rejections, then we need to ensure that | ||
// the stale value is not removed from the cache when the fetch fails. | ||
const del = !noDelete || p.__staleWhileFetching === undefined; | ||
if (del) { | ||
this.delete(k); | ||
} else { | ||
} else if (!allowStaleAborted) { | ||
// still replace the *promise* with the stale value, | ||
// since we are done with the promise at this point. | ||
// leave it untouched if we're still waiting for an | ||
// aborted background fetch that hasn't yet returned. | ||
this.valList[index] = p.__staleWhileFetching; | ||
} | ||
} | ||
if (p.__returned === p) { | ||
if (allowStale) { | ||
if (options.status && p.__staleWhileFetching !== undefined) { | ||
options.status.returnedStale = true; | ||
} | ||
return p.__staleWhileFetching | ||
} else if (p.__returned === p) { | ||
throw er | ||
} | ||
}; | ||
const pcall = res => res(this.fetchMethod(k, v, fetchOpts)); | ||
const pcall = (res, rej) => { | ||
this.fetchMethod(k, v, fetchOpts).then(v => res(v), rej); | ||
// ignored, we go until we finish, regardless. | ||
// defer check until we are actually aborting, | ||
// so fetchMethod can override. | ||
ac.signal.addEventListener('abort', () => { | ||
if ( | ||
!options.ignoreFetchAbort || | ||
options.allowStaleOnFetchAbort | ||
) { | ||
res(); | ||
// when it eventually resolves, update the cache. | ||
if (options.allowStaleOnFetchAbort) { | ||
res = v => cb(v, true); | ||
} | ||
} | ||
}); | ||
}; | ||
if (options.status) options.status.fetchDispatched = true; | ||
const p = new Promise(pcall).then(cb, eb); | ||
@@ -785,3 +970,4 @@ p.__abortController = ac; | ||
if (index === undefined) { | ||
this.set(k, p, fetchOpts.options); | ||
// internal, don't expose status. | ||
this.set(k, p, { ...fetchOpts.options, status: undefined }); | ||
index = this.keyMap.get(k); | ||
@@ -824,7 +1010,13 @@ } else { | ||
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, | ||
allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, | ||
ignoreFetchAbort = this.ignoreFetchAbort, | ||
allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, | ||
fetchContext = this.fetchContext, | ||
forceRefresh = false, | ||
status, | ||
signal, | ||
} = {} | ||
) { | ||
if (!this.fetchMethod) { | ||
if (status) status.fetch = 'get'; | ||
return this.get(k, { | ||
@@ -834,2 +1026,3 @@ allowStale, | ||
noDeleteOnStaleGet, | ||
status, | ||
}) | ||
@@ -848,2 +1041,7 @@ } | ||
noDeleteOnFetchRejection, | ||
allowStaleOnFetchRejection, | ||
allowStaleOnFetchAbort, | ||
ignoreFetchAbort, | ||
status, | ||
signal, | ||
}; | ||
@@ -853,2 +1051,3 @@ | ||
if (index === undefined) { | ||
if (status) status.fetch = 'miss'; | ||
const p = this.backgroundFetch(k, index, options, fetchContext); | ||
@@ -860,5 +1059,9 @@ return (p.__returned = p) | ||
if (this.isBackgroundFetch(v)) { | ||
return allowStale && v.__staleWhileFetching !== undefined | ||
? v.__staleWhileFetching | ||
: (v.__returned = v) | ||
const stale = | ||
allowStale && v.__staleWhileFetching !== undefined; | ||
if (status) { | ||
status.fetch = 'inflight'; | ||
if (stale) status.returnedStale = true; | ||
} | ||
return stale ? v.__staleWhileFetching : (v.__returned = v) | ||
} | ||
@@ -868,3 +1071,5 @@ | ||
// unless we are already in the process of refreshing the cache. | ||
if (!forceRefresh && !this.isStale(index)) { | ||
const isStale = this.isStale(index); | ||
if (!forceRefresh && !isStale) { | ||
if (status) status.fetch = 'hit'; | ||
this.moveToTail(index); | ||
@@ -874,2 +1079,3 @@ if (updateAgeOnGet) { | ||
} | ||
this.statusTTL(status, index); | ||
return v | ||
@@ -881,5 +1087,9 @@ } | ||
const p = this.backgroundFetch(k, index, options, fetchContext); | ||
return allowStale && p.__staleWhileFetching !== undefined | ||
? p.__staleWhileFetching | ||
: (p.__returned = p) | ||
const hasStale = p.__staleWhileFetching !== undefined; | ||
const staleVal = hasStale && allowStale; | ||
if (status) { | ||
status.fetch = hasStale && isStale ? 'stale' : 'refresh'; | ||
if (staleVal && isStale) status.returnedStale = true; | ||
} | ||
return staleVal ? p.__staleWhileFetching : (p.__returned = p) | ||
} | ||
@@ -894,2 +1104,3 @@ } | ||
noDeleteOnStaleGet = this.noDeleteOnStaleGet, | ||
status, | ||
} = {} | ||
@@ -901,3 +1112,5 @@ ) { | ||
const fetching = this.isBackgroundFetch(value); | ||
this.statusTTL(status, index); | ||
if (this.isStale(index)) { | ||
if (status) status.get = 'stale'; | ||
// delete only if not an in-flight background fetch | ||
@@ -908,12 +1121,20 @@ if (!fetching) { | ||
} | ||
if (status) status.returnedStale = allowStale; | ||
return allowStale ? value : undefined | ||
} else { | ||
if (status) { | ||
status.returnedStale = | ||
allowStale && value.__staleWhileFetching !== undefined; | ||
} | ||
return allowStale ? value.__staleWhileFetching : undefined | ||
} | ||
} else { | ||
if (status) status.get = 'hit'; | ||
// if we're currently fetching it, we don't actually have it yet | ||
// it's not stale, which means this isn't a staleWhileRefetching, | ||
// so we just return undefined | ||
// it's not stale, which means this isn't a staleWhileRefetching. | ||
// If it's not stale, and fetching, AND has a __staleWhileFetching | ||
// value, then that means the user fetched with {forceRefresh:true}, | ||
// so it's safe to return that value. | ||
if (fetching) { | ||
return undefined | ||
return value.__staleWhileFetching | ||
} | ||
@@ -926,2 +1147,4 @@ this.moveToTail(index); | ||
} | ||
} else if (status) { | ||
status.get = 'miss'; | ||
} | ||
@@ -972,3 +1195,3 @@ } | ||
if (this.isBackgroundFetch(v)) { | ||
v.__abortController.abort(); | ||
v.__abortController.abort(new Error('deleted')); | ||
} else { | ||
@@ -1008,3 +1231,3 @@ this.dispose(v, k, 'delete'); | ||
if (this.isBackgroundFetch(v)) { | ||
v.__abortController.abort(); | ||
v.__abortController.abort(new Error('deleted')); | ||
} else { | ||
@@ -1060,6 +1283,4 @@ const k = this.keyList[index]; | ||
var lruCache = LRUCache; | ||
var LRUCache$1 = LRUCache; | ||
var LRUCache$1 = lruCache; | ||
/****************************************************************************** | ||
@@ -1096,3 +1317,3 @@ Copyright (c) Microsoft Corporation. | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -1119,428 +1340,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
var bind = function bind(fn, thisArg) { | ||
return function wrap() { | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < args.length; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
return fn.apply(thisArg, args); | ||
}; | ||
}; | ||
// utils is a library of generic helper functions non-specific to axios | ||
var toString = Object.prototype.toString; | ||
/** | ||
* Determine if a value is an Array | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is an Array, otherwise false | ||
*/ | ||
function isArray(val) { | ||
return toString.call(val) === '[object Array]'; | ||
} | ||
/** | ||
* Determine if a value is undefined | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if the value is undefined, otherwise false | ||
*/ | ||
function isUndefined(val) { | ||
return typeof val === 'undefined'; | ||
} | ||
/** | ||
* Determine if a value is a Buffer | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Buffer, otherwise false | ||
*/ | ||
function isBuffer(val) { | ||
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) | ||
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val); | ||
} | ||
/** | ||
* Determine if a value is an ArrayBuffer | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is an ArrayBuffer, otherwise false | ||
*/ | ||
function isArrayBuffer(val) { | ||
return toString.call(val) === '[object ArrayBuffer]'; | ||
} | ||
/** | ||
* Determine if a value is a FormData | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is an FormData, otherwise false | ||
*/ | ||
function isFormData(val) { | ||
return (typeof FormData !== 'undefined') && (val instanceof FormData); | ||
} | ||
/** | ||
* Determine if a value is a view on an ArrayBuffer | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false | ||
*/ | ||
function isArrayBufferView(val) { | ||
var result; | ||
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) { | ||
result = ArrayBuffer.isView(val); | ||
} else { | ||
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Determine if a value is a String | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a String, otherwise false | ||
*/ | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
} | ||
/** | ||
* Determine if a value is a Number | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Number, otherwise false | ||
*/ | ||
function isNumber(val) { | ||
return typeof val === 'number'; | ||
} | ||
/** | ||
* Determine if a value is an Object | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is an Object, otherwise false | ||
*/ | ||
function isObject(val) { | ||
return val !== null && typeof val === 'object'; | ||
} | ||
/** | ||
* Determine if a value is a plain Object | ||
* | ||
* @param {Object} val The value to test | ||
* @return {boolean} True if value is a plain Object, otherwise false | ||
*/ | ||
function isPlainObject(val) { | ||
if (toString.call(val) !== '[object Object]') { | ||
return false; | ||
} | ||
var prototype = Object.getPrototypeOf(val); | ||
return prototype === null || prototype === Object.prototype; | ||
} | ||
/** | ||
* Determine if a value is a Date | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Date, otherwise false | ||
*/ | ||
function isDate(val) { | ||
return toString.call(val) === '[object Date]'; | ||
} | ||
/** | ||
* Determine if a value is a File | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a File, otherwise false | ||
*/ | ||
function isFile(val) { | ||
return toString.call(val) === '[object File]'; | ||
} | ||
/** | ||
* Determine if a value is a Blob | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Blob, otherwise false | ||
*/ | ||
function isBlob(val) { | ||
return toString.call(val) === '[object Blob]'; | ||
} | ||
/** | ||
* Determine if a value is a Function | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Function, otherwise false | ||
*/ | ||
function isFunction(val) { | ||
return toString.call(val) === '[object Function]'; | ||
} | ||
/** | ||
* Determine if a value is a Stream | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a Stream, otherwise false | ||
*/ | ||
function isStream(val) { | ||
return isObject(val) && isFunction(val.pipe); | ||
} | ||
/** | ||
* Determine if a value is a URLSearchParams object | ||
* | ||
* @param {Object} val The value to test | ||
* @returns {boolean} True if value is a URLSearchParams object, otherwise false | ||
*/ | ||
function isURLSearchParams(val) { | ||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; | ||
} | ||
/** | ||
* Trim excess whitespace off the beginning and end of a string | ||
* | ||
* @param {String} str The String to trim | ||
* @returns {String} The String freed of excess whitespace | ||
*/ | ||
function trim(str) { | ||
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, ''); | ||
} | ||
/** | ||
* Determine if we're running in a standard browser environment | ||
* | ||
* This allows axios to run in a web worker, and react-native. | ||
* Both environments support XMLHttpRequest, but not fully standard globals. | ||
* | ||
* web workers: | ||
* typeof window -> undefined | ||
* typeof document -> undefined | ||
* | ||
* react-native: | ||
* navigator.product -> 'ReactNative' | ||
* nativescript | ||
* navigator.product -> 'NativeScript' or 'NS' | ||
*/ | ||
function isStandardBrowserEnv() { | ||
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' || | ||
navigator.product === 'NativeScript' || | ||
navigator.product === 'NS')) { | ||
return false; | ||
} | ||
return ( | ||
typeof window !== 'undefined' && | ||
typeof document !== 'undefined' | ||
); | ||
} | ||
/** | ||
* Iterate over an Array or an Object invoking a function for each item. | ||
* | ||
* If `obj` is an Array callback will be called passing | ||
* the value, index, and complete array for each item. | ||
* | ||
* If 'obj' is an Object callback will be called passing | ||
* the value, key, and complete object for each property. | ||
* | ||
* @param {Object|Array} obj The object to iterate | ||
* @param {Function} fn The callback to invoke for each item | ||
*/ | ||
function forEach(obj, fn) { | ||
// Don't bother if no value provided | ||
if (obj === null || typeof obj === 'undefined') { | ||
return; | ||
} | ||
// Force an array if not already something iterable | ||
if (typeof obj !== 'object') { | ||
/*eslint no-param-reassign:0*/ | ||
obj = [obj]; | ||
} | ||
if (isArray(obj)) { | ||
// Iterate over array values | ||
for (var i = 0, l = obj.length; i < l; i++) { | ||
fn.call(null, obj[i], i, obj); | ||
} | ||
} else { | ||
// Iterate over object keys | ||
for (var key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
fn.call(null, obj[key], key, obj); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Accepts varargs expecting each argument to be an object, then | ||
* immutably merges the properties of each object and returns result. | ||
* | ||
* When multiple objects contain the same key the later object in | ||
* the arguments list will take precedence. | ||
* | ||
* Example: | ||
* | ||
* ```js | ||
* var result = merge({foo: 123}, {foo: 456}); | ||
* console.log(result.foo); // outputs 456 | ||
* ``` | ||
* | ||
* @param {Object} obj1 Object to merge | ||
* @returns {Object} Result of all merge properties | ||
*/ | ||
function merge(/* obj1, obj2, obj3, ... */) { | ||
var result = {}; | ||
function assignValue(val, key) { | ||
if (isPlainObject(result[key]) && isPlainObject(val)) { | ||
result[key] = merge(result[key], val); | ||
} else if (isPlainObject(val)) { | ||
result[key] = merge({}, val); | ||
} else if (isArray(val)) { | ||
result[key] = val.slice(); | ||
} else { | ||
result[key] = val; | ||
} | ||
} | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
forEach(arguments[i], assignValue); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Extends object a by mutably adding to it the properties of object b. | ||
* | ||
* @param {Object} a The object to be extended | ||
* @param {Object} b The object to copy properties from | ||
* @param {Object} thisArg The object to bind function to | ||
* @return {Object} The resulting value of object a | ||
*/ | ||
function extend(a, b, thisArg) { | ||
forEach(b, function assignValue(val, key) { | ||
if (thisArg && typeof val === 'function') { | ||
a[key] = bind(val, thisArg); | ||
} else { | ||
a[key] = val; | ||
} | ||
}); | ||
return a; | ||
} | ||
/** | ||
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) | ||
* | ||
* @param {string} content with BOM | ||
* @return {string} content value without BOM | ||
*/ | ||
function stripBOM(content) { | ||
if (content.charCodeAt(0) === 0xFEFF) { | ||
content = content.slice(1); | ||
} | ||
return content; | ||
} | ||
var utils = { | ||
isArray: isArray, | ||
isArrayBuffer: isArrayBuffer, | ||
isBuffer: isBuffer, | ||
isFormData: isFormData, | ||
isArrayBufferView: isArrayBufferView, | ||
isString: isString, | ||
isNumber: isNumber, | ||
isObject: isObject, | ||
isPlainObject: isPlainObject, | ||
isUndefined: isUndefined, | ||
isDate: isDate, | ||
isFile: isFile, | ||
isBlob: isBlob, | ||
isFunction: isFunction, | ||
isStream: isStream, | ||
isURLSearchParams: isURLSearchParams, | ||
isStandardBrowserEnv: isStandardBrowserEnv, | ||
forEach: forEach, | ||
merge: merge, | ||
extend: extend, | ||
trim: trim, | ||
stripBOM: stripBOM | ||
}; | ||
function encode(val) { | ||
return encodeURIComponent(val). | ||
replace(/%3A/gi, ':'). | ||
replace(/%24/g, '$'). | ||
replace(/%2C/gi, ','). | ||
replace(/%20/g, '+'). | ||
replace(/%5B/gi, '['). | ||
replace(/%5D/gi, ']'); | ||
} | ||
/** | ||
* Build a URL by appending params to the end | ||
* | ||
* @param {string} url The base of the url (e.g., http://www.google.com) | ||
* @param {object} [params] The params to be appended | ||
* @returns {string} The formatted url | ||
*/ | ||
var buildURL = function buildURL(url, params, paramsSerializer) { | ||
/*eslint no-param-reassign:0*/ | ||
if (!params) { | ||
return url; | ||
} | ||
var serializedParams; | ||
if (paramsSerializer) { | ||
serializedParams = paramsSerializer(params); | ||
} else if (utils.isURLSearchParams(params)) { | ||
serializedParams = params.toString(); | ||
} else { | ||
var parts = []; | ||
utils.forEach(params, function serialize(val, key) { | ||
if (val === null || typeof val === 'undefined') { | ||
return; | ||
} | ||
if (utils.isArray(val)) { | ||
key = key + '[]'; | ||
} else { | ||
val = [val]; | ||
} | ||
utils.forEach(val, function parseValue(v) { | ||
if (utils.isDate(v)) { | ||
v = v.toISOString(); | ||
} else if (utils.isObject(v)) { | ||
v = JSON.stringify(v); | ||
} | ||
parts.push(encode(key) + '=' + encode(v)); | ||
}); | ||
}); | ||
serializedParams = parts.join('&'); | ||
} | ||
if (serializedParams) { | ||
var hashmarkIndex = url.indexOf('#'); | ||
if (hashmarkIndex !== -1) { | ||
url = url.slice(0, hashmarkIndex); | ||
} | ||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; | ||
} | ||
return url; | ||
}; | ||
var buildURL$1 = buildURL; | ||
/** | ||
* @author Kuitos | ||
@@ -1555,3 +1351,4 @@ * @homepage https://github.com/kuitos/ | ||
} | ||
var builtURL = buildURL$1.apply(void 0, args); | ||
var url = args[0], params = args[1], paramsSerializer = args[2]; | ||
var builtURL = axios__default["default"].getUri({ url: url, params: params, paramsSerializer: paramsSerializer }); | ||
var _a = builtURL.split('?'), urlPath = _a[0], queryString = _a[1]; | ||
@@ -1558,0 +1355,0 @@ if (queryString) { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["axios-extensions"]={})}(this,(function(t){"use strict";const e="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,i="function"==typeof AbortController?AbortController:class{constructor(){this.signal=new r}abort(){this.signal.dispatchEvent("abort")}},s="function"==typeof AbortSignal,n="function"==typeof i.AbortSignal,r=s?AbortSignal:n?i.AbortController:class{constructor(){this.aborted=!1,this._listeners=[]}dispatchEvent(t){if("abort"===t){this.aborted=!0;const e={type:t,target:this};this.onabort(e),this._listeners.forEach((t=>t(e)),this)}}onabort(){}addEventListener(t,e){"abort"===t&&this._listeners.push(e)}removeEventListener(t,e){"abort"===t&&(this._listeners=this._listeners.filter((t=>t!==e)))}},o=new Set,a=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;c(i)&&u(i,`${t} option`,`options.${e}`,v)},h=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(c(i)){const{prototype:s}=v,{get:n}=Object.getOwnPropertyDescriptor(s,t);u(i,`${t} method`,`cache.${e}()`,n)}},l=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},c=t=>!o.has(t),u=(t,e,i,s)=>{o.add(t);l(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,s)},f=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),d=t=>f(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?p:null:null;class p extends Array{constructor(t){super(t),this.fill(0)}}class y{constructor(t){if(0===t)return[];const e=d(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class v{constructor(t={}){const{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:h,allowStale:u,dispose:p,disposeAfter:g,noDisposeOnSet:m,noUpdateTTL:S,maxSize:w=0,maxEntrySize:x=0,sizeCalculation:b,fetchMethod:z,fetchContext:L,noDeleteOnFetchRejection:A,noDeleteOnStaleGet:_}=t,{length:T,maxAge:O,stale:k}=t instanceof v?{}:t;if(0!==e&&!f(e))throw new TypeError("max option must be a nonnegative integer");const E=e?d(e):Array;if(!E)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=w,this.maxEntrySize=x||this.maxSize,this.sizeCalculation=b||T,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=z||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=L,!this.fetchMethod&&void 0!==L)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new E(e),this.prev=new E(e),this.head=0,this.tail=0,this.free=new y(e),this.initialFill=1,this.size=0,"function"==typeof p&&(this.dispose=p),"function"==typeof g?(this.disposeAfter=g,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!m,this.noUpdateTTL=!!S,this.noDeleteOnFetchRejection=!!A,0!==this.maxEntrySize){if(0!==this.maxSize&&!f(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!f(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!u||!!k,this.noDeleteOnStaleGet=!!_,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!h,this.ttlResolution=f(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||O||0,this.ttl){if(!f(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(0===this.max&&0===this.ttl&&0===this.maxSize)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const t="LRU_CACHE_UNBOUNDED";if(c(t)){o.add(t);l("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,v)}}k&&a("stale","allowStale"),O&&a("maxAge","ttl"),T&&a("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new p(this.max),this.starts=new p(this.max),this.setItemTTL=(t,i,s=e.now())=>{if(this.starts[t]=0!==i?s:0,this.ttls[t]=i,0!==i&&this.ttlAutopurge){const e=setTimeout((()=>{this.isStale(t)&&this.delete(this.keyList[t])}),i+1);e.unref&&e.unref()}},this.updateItemAge=t=>{this.starts[t]=0!==this.ttls[t]?e.now():0};let t=0;const i=()=>{const i=e.now();if(this.ttlResolution>0){t=i;const e=setTimeout((()=>t=0),this.ttlResolution);e.unref&&e.unref()}return i};this.getRemainingTTL=e=>{const s=this.keyMap.get(e);return void 0===s?0:0===this.ttls[s]||0===this.starts[s]?1/0:this.starts[s]+this.ttls[s]-(t||i())},this.isStale=e=>0!==this.ttls[e]&&0!==this.starts[e]&&(t||i())-this.starts[e]>this.ttls[e]}updateItemAge(t){}setItemTTL(t,e,i){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new p(this.max),this.removeItemSize=t=>{this.calculatedSize-=this.sizes[t],this.sizes[t]=0},this.requireSize=(t,e,i,s)=>{if(!f(i)){if(!s)throw new TypeError("invalid size value (must be positive integer)");if("function"!=typeof s)throw new TypeError("sizeCalculation must be a function");if(i=s(e,t),!f(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e)=>{this.sizes[t]=e;const i=this.maxSize-this.sizes[t];for(;this.calculatedSize>i;)this.evict(!0);this.calculatedSize+=this.sizes[t]}}removeItemSize(t){}addItemSize(t,e){}requireSize(t,e,i,s){if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.tail;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.head);)e=this.prev[e]}*rindexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.head;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.tail);)e=this.next[e]}isValidIndex(t){return this.keyMap.get(this.keyList[t])===t}*entries(){for(const t of this.indexes())yield[this.keyList[t],this.valList[t]]}*rentries(){for(const t of this.rindexes())yield[this.keyList[t],this.valList[t]]}*keys(){for(const t of this.indexes())yield this.keyList[t]}*rkeys(){for(const t of this.rindexes())yield this.keyList[t]}*values(){for(const t of this.indexes())yield this.valList[t]}*rvalues(){for(const t of this.rindexes())yield this.valList[t]}[Symbol.iterator](){return this.entries()}find(t,e={}){for(const i of this.indexes())if(t(this.valList[i],this.keyList[i],this))return this.get(this.keyList[i],e)}forEach(t,e=this){for(const i of this.indexes())t.call(e,this.valList[i],this.keyList[i],this)}rforEach(t,e=this){for(const i of this.rindexes())t.call(e,this.valList[i],this.keyList[i],this)}get prune(){return h("prune","purgeStale"),this.purgeStale}purgeStale(){let t=!1;for(const e of this.rindexes({allowStale:!0}))this.isStale(e)&&(this.delete(this.keyList[e]),t=!0);return t}dump(){const t=[];for(const i of this.indexes({allowStale:!0})){const s=this.keyList[i],n=this.valList[i],r={value:this.isBackgroundFetch(n)?n.__staleWhileFetching:n};if(this.ttls){r.ttl=this.ttls[i];const t=e.now()-this.starts[i];r.start=Math.floor(Date.now()-t)}this.sizes&&(r.size=this.sizes[i]),t.unshift([s,r])}return t}load(t){this.clear();for(const[i,s]of t){if(s.start){const t=Date.now()-s.start;s.start=e.now()-t}this.set(i,s.value,s)}}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,start:s,noDisposeOnSet:n=this.noDisposeOnSet,size:r=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL}={}){if(r=this.requireSize(t,e,r,o),this.maxEntrySize&&r>this.maxEntrySize)return this;let h=0===this.size?void 0:this.keyMap.get(t);if(void 0===h)h=this.newIndex(),this.keyList[h]=t,this.valList[h]=e,this.keyMap.set(t,h),this.next[this.tail]=h,this.prev[h]=this.tail,this.tail=h,this.size++,this.addItemSize(h,r),a=!1;else{const i=this.valList[h];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort():n||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(h),this.valList[h]=e,this.addItemSize(h,r)),this.moveToTail(h)}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),a||this.setItemTTL(h,i,s),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return 0===this.size?this.tail:this.size===this.max&&0!==this.max?this.evict(!1):0!==this.free.length?this.free.pop():this.initialFill++}pop(){if(this.size){const t=this.valList[this.head];return this.evict(!0),t}}evict(t){const e=this.head,i=this.keyList[e],s=this.valList[e];return this.isBackgroundFetch(s)?s.__abortController.abort():(this.dispose(s,i,"evict"),this.disposeAfter&&this.disposed.push([s,i,"evict"])),this.removeItemSize(e),t&&(this.keyList[e]=null,this.valList[e]=null,this.free.push(e)),this.head=this.next[e],this.keyMap.delete(i),this.size--,e}has(t,{updateAgeOnHas:e=this.updateAgeOnHas}={}){const i=this.keyMap.get(t);return void 0!==i&&!this.isStale(i)&&(e&&this.updateItemAge(i),!0)}peek(t,{allowStale:e=this.allowStale}={}){const i=this.keyMap.get(t);if(void 0!==i&&(e||!this.isStale(i))){const t=this.valList[i];return this.isBackgroundFetch(t)?t.__staleWhileFetching:t}}backgroundFetch(t,e,s,n){const r=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(r))return r;const o=new i,a={signal:o.signal,options:s,context:n},h=new Promise((e=>e(this.fetchMethod(t,r,a)))).then((e=>(o.signal.aborted||this.set(t,e,a.options),e)),(i=>{if(this.valList[e]===h){!s.noDeleteOnFetchRejection||void 0===h.__staleWhileFetching?this.delete(t):this.valList[e]=h.__staleWhileFetching}if(h.__returned===h)throw i}));return h.__abortController=o,h.__staleWhileFetching=r,h.__returned=null,void 0===e?(this.set(t,h,a.options),e=this.keyMap.get(t)):this.valList[e]=h,h}isBackgroundFetch(t){return t&&"object"==typeof t&&"function"==typeof t.then&&Object.prototype.hasOwnProperty.call(t,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(t,"__returned")&&(t.__returned===t||null===t.__returned)}async fetch(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:o=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,fetchContext:c=this.fetchContext,forceRefresh:u=!1}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s});const f={allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s,ttl:n,noDisposeOnSet:r,size:o,sizeCalculation:a,noUpdateTTL:h,noDeleteOnFetchRejection:l};let d=this.keyMap.get(t);if(void 0===d){const e=this.backgroundFetch(t,d,f,c);return e.__returned=e}{const s=this.valList[d];if(this.isBackgroundFetch(s))return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s;if(!u&&!this.isStale(d))return this.moveToTail(d),i&&this.updateItemAge(d),s;const n=this.backgroundFetch(t,d,f,c);return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet}={}){const n=this.keyMap.get(t);if(void 0!==n){const r=this.valList[n],o=this.isBackgroundFetch(r);if(this.isStale(n))return o?e?r.__staleWhileFetching:void 0:(s||this.delete(t),e?r:void 0);if(o)return;return this.moveToTail(n),i&&this.updateItemAge(n),r}}connect(t,e){this.prev[e]=t,this.next[t]=e}moveToTail(t){t!==this.tail&&(t===this.head?this.head=this.next[t]:this.connect(this.prev[t],this.next[t]),this.connect(this.tail,t),this.tail=t)}get del(){return h("del","delete"),this.delete}delete(t){let e=!1;if(0!==this.size){const i=this.keyMap.get(t);if(void 0!==i)if(e=!0,1===this.size)this.clear();else{this.removeItemSize(i);const e=this.valList[i];this.isBackgroundFetch(e)?e.__abortController.abort():(this.dispose(e,t,"delete"),this.disposeAfter&&this.disposed.push([e,t,"delete"])),this.keyMap.delete(t),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return e}clear(){for(const t of this.rindexes({allowStale:!0})){const e=this.valList[t];if(this.isBackgroundFetch(e))e.__abortController.abort();else{const i=this.keyList[t];this.dispose(e,i,"delete"),this.disposeAfter&&this.disposed.push([e,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return h("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(c(i)){const{prototype:s}=v,{get:n}=Object.getOwnPropertyDescriptor(s,t);u(i,`${t} property`,`cache.${e}`,n)}})("length","size"),this.size}static get AbortController(){return i}static get AbortSignal(){return r}}var g=v;function m(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))}function S(t,e){var i,s,n,r,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(n=2&r[0]?s.return:r[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,r[1])).done)return n;switch(s=0,n&&(r=[2&r[0],n.value]),r[0]){case 0:case 1:n=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,s=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!n||r[1]>n[0]&&r[1]<n[3])){o.label=r[1];break}if(6===r[0]&&o.label<n[1]){o.label=n[1],n=r;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(r);break}n[2]&&o.ops.pop(),o.trys.pop();continue}r=e.call(t,o)}catch(t){r=[6,t],s=0}finally{i=n=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}var w=Object.prototype.toString;function x(t){return"[object Array]"===w.call(t)}function b(t){return void 0===t}function z(t){return null!==t&&"object"==typeof t}function L(t){if("[object Object]"!==w.call(t))return!1;var e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function A(t){return"[object Function]"===w.call(t)}function _(t,e){if(null!=t)if("object"!=typeof t&&(t=[t]),x(t))for(var i=0,s=t.length;i<s;i++)e.call(null,t[i],i,t);else for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.call(null,t[n],n,t)}var T={isArray:x,isArrayBuffer:function(t){return"[object ArrayBuffer]"===w.call(t)},isBuffer:function(t){return null!==t&&!b(t)&&null!==t.constructor&&!b(t.constructor)&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},isArrayBufferView:function(t){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer&&t.buffer instanceof ArrayBuffer},isString:function(t){return"string"==typeof t},isNumber:function(t){return"number"==typeof t},isObject:z,isPlainObject:L,isUndefined:b,isDate:function(t){return"[object Date]"===w.call(t)},isFile:function(t){return"[object File]"===w.call(t)},isBlob:function(t){return"[object Blob]"===w.call(t)},isFunction:A,isStream:function(t){return z(t)&&A(t.pipe)},isURLSearchParams:function(t){return"undefined"!=typeof URLSearchParams&&t instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:_,merge:function t(){var e={};function i(i,s){L(e[s])&&L(i)?e[s]=t(e[s],i):L(i)?e[s]=t({},i):x(i)?e[s]=i.slice():e[s]=i}for(var s=0,n=arguments.length;s<n;s++)_(arguments[s],i);return e},extend:function(t,e,i){return _(e,(function(e,s){t[s]=i&&"function"==typeof e?function(t,e){return function(){for(var i=new Array(arguments.length),s=0;s<i.length;s++)i[s]=arguments[s];return t.apply(e,i)}}(e,i):e})),t},trim:function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")},stripBOM:function(t){return 65279===t.charCodeAt(0)&&(t=t.slice(1)),t}};function O(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var k=function(t,e,i){if(!e)return t;var s;if(i)s=i(e);else if(T.isURLSearchParams(e))s=e.toString();else{var n=[];T.forEach(e,(function(t,e){null!=t&&(T.isArray(t)?e+="[]":t=[t],T.forEach(t,(function(t){T.isDate(t)?t=t.toISOString():T.isObject(t)&&(t=JSON.stringify(t)),n.push(O(e)+"="+O(t))})))})),s=n.join("&")}if(s){var r=t.indexOf("#");-1!==r&&(t=t.slice(0,r)),t+=(-1===t.indexOf("?")?"?":"&")+s}return t};function E(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=k.apply(void 0,t),s=i.split("?"),n=s[0],r=s[1];if(r){var o=r.split("&");return"".concat(n,"?").concat(o.sort().join("&"))}return i}t.Cache=g,t.cacheAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.enabledByDefault,n=void 0===s||s,r=e.cacheFlag,o=void 0===r?"cache":r,a=e.defaultCache,h=void 0===a?new g({ttl:3e5,max:100}):a;return function(e){var s,r=e.url,a=e.method,l=e.params,c=e.paramsSerializer,u=e.forceUpdate,f=void 0!==e[o]&&null!==e[o]?e[o]:n;if("get"===a&&f){var d="function"!=typeof(s=f).get||"function"!=typeof s.set||"function"!=typeof s.delete&&"function"!=typeof s.del?h:f,p=E(r,l,c),y=d.get(p);return!y||u?(y=m(i,void 0,void 0,(function(){var i;return S(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,s.sent()];case 2:throw i=s.sent(),"delete"in d?d.delete(p):d.del(p),i;case 3:return[2]}}))})),d.set(p,y),y):("info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by cache adapter --\x3e url: ".concat(p)),y)}return t(e)}},t.retryAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.times,n=void 0===s?2:s;return function(e){return m(i,void 0,void 0,(function(){var i,s,r,o,a=this;return S(this,(function(h){return i=e.retryTimes,s=void 0===i?n:i,!1,r=0,o=function(){return m(a,void 0,void 0,(function(){var i;return S(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,n.sent()];case 2:if(i=n.sent(),s===r)throw i;return r++,"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request start retrying --\x3e url: ".concat(e.url," , time: ").concat(r)),[2,o()];case 3:return[2]}}))}))},[2,o()]}))}))}},t.throttleAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.threshold,n=void 0===s?1e3:s,r=e.cache,o=void 0===r?new g({max:10}):r;return function(e){var s=e.url,r=e.method,a=E(s,e.params,e.paramsSerializer),h=Date.now(),l=o.get(a)||{timestamp:h};if("get"===r){if(h-l.timestamp<=n){var c=l.value;if(c)return"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by throttle adapter --\x3e url: ".concat(a)),c}return function(e,s){var n=m(i,void 0,void 0,(function(){var i,n;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t(s)];case 1:return i=r.sent(),o.set(e,{timestamp:Date.now(),value:Promise.resolve(i)}),[2,i];case 2:throw n=r.sent(),"delete"in o?o.delete(e):o.del(e),n;case 3:return[2]}}))}));return o.set(e,{timestamp:Date.now(),value:n}),n}(a,e)}return t(e)}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["axios-extensions"]={},t.axios)}(this,(function(t,e){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=i(e);const n="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,o="function"==typeof AbortController?AbortController:class{constructor(){this.signal=new h}abort(t=new Error("This operation was aborted")){this.signal.reason=this.signal.reason||t,this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort",target:this.signal})}},r="function"==typeof AbortSignal,a="function"==typeof o.AbortSignal,h=r?AbortSignal:a?o.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(t){"abort"===t.type&&(this.aborted=!0,this.onabort(t),this._listeners.forEach((e=>e(t)),this))}onabort(){}addEventListener(t,e){"abort"===t&&this._listeners.push(e)}removeEventListener(t,e){"abort"===t&&(this._listeners=this._listeners.filter((t=>t!==e)))}},l=new Set,c=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;f(i)&&p(i,`${t} option`,`options.${e}`,S)},u=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(f(i)){const{prototype:s}=S,{get:n}=Object.getOwnPropertyDescriptor(s,t);p(i,`${t} method`,`cache.${e}()`,n)}},d=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},f=t=>!l.has(t),p=(t,e,i,s)=>{l.add(t);d(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,s)},g=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),v=t=>g(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?y:null:null;class y extends Array{constructor(t){super(t),this.fill(0)}}class m{constructor(t){if(0===t)return[];const e=v(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class S{constructor(t={}){const{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:r,allowStale:a,dispose:h,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:y,maxSize:w=0,maxEntrySize:x=0,sizeCalculation:z,fetchMethod:L,fetchContext:b,noDeleteOnFetchRejection:_,noDeleteOnStaleGet:T,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:F,ignoreFetchAbort:k}=t,{length:E,maxAge:O,stale:C}=t instanceof S?{}:t;if(0!==e&&!g(e))throw new TypeError("max option must be a nonnegative integer");const D=e?v(e):Array;if(!D)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=w,this.maxEntrySize=x||this.maxSize,this.sizeCalculation=z||E,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=L||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=b,!this.fetchMethod&&void 0!==b)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new D(e),this.prev=new D(e),this.head=0,this.tail=0,this.free=new m(e),this.initialFill=1,this.size=0,"function"==typeof h&&(this.dispose=h),"function"==typeof u?(this.disposeAfter=u,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!y,this.noDeleteOnFetchRejection=!!_,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!F,this.ignoreFetchAbort=!!k,0!==this.maxEntrySize){if(0!==this.maxSize&&!g(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!g(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!C,this.noDeleteOnStaleGet=!!T,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!r,this.ttlResolution=g(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||O||0,this.ttl){if(!g(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(0===this.max&&0===this.ttl&&0===this.maxSize)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const t="LRU_CACHE_UNBOUNDED";if(f(t)){l.add(t);d("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,S)}}C&&c("stale","allowStale"),O&&c("maxAge","ttl"),E&&c("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new y(this.max),this.starts=new y(this.max),this.setItemTTL=(t,e,i=n.now())=>{if(this.starts[t]=0!==e?i:0,this.ttls[t]=e,0!==e&&this.ttlAutopurge){const i=setTimeout((()=>{this.isStale(t)&&this.delete(this.keyList[t])}),e+1);i.unref&&i.unref()}},this.updateItemAge=t=>{this.starts[t]=0!==this.ttls[t]?n.now():0},this.statusTTL=(i,s)=>{i&&(i.ttl=this.ttls[s],i.start=this.starts[s],i.now=t||e(),i.remainingTTL=i.now+i.ttl-i.start)};let t=0;const e=()=>{const e=n.now();if(this.ttlResolution>0){t=e;const i=setTimeout((()=>t=0),this.ttlResolution);i.unref&&i.unref()}return e};this.getRemainingTTL=i=>{const s=this.keyMap.get(i);return void 0===s?0:0===this.ttls[s]||0===this.starts[s]?1/0:this.starts[s]+this.ttls[s]-(t||e())},this.isStale=i=>0!==this.ttls[i]&&0!==this.starts[i]&&(t||e())-this.starts[i]>this.ttls[i]}updateItemAge(t){}statusTTL(t,e){}setItemTTL(t,e,i){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new y(this.max),this.removeItemSize=t=>{this.calculatedSize-=this.sizes[t],this.sizes[t]=0},this.requireSize=(t,e,i,s)=>{if(this.isBackgroundFetch(e))return 0;if(!g(i)){if(!s)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof s)throw new TypeError("sizeCalculation must be a function");if(i=s(e,t),!g(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e,i)=>{if(this.sizes[t]=e,this.maxSize){const e=this.maxSize-this.sizes[t];for(;this.calculatedSize>e;)this.evict(!0)}this.calculatedSize+=this.sizes[t],i&&(i.entrySize=e,i.totalCalculatedSize=this.calculatedSize)}}removeItemSize(t){}addItemSize(t,e){}requireSize(t,e,i,s){if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.tail;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.head);)e=this.prev[e]}*rindexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.head;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.tail);)e=this.next[e]}isValidIndex(t){return void 0!==t&&this.keyMap.get(this.keyList[t])===t}*entries(){for(const t of this.indexes())void 0===this.valList[t]||void 0===this.keyList[t]||this.isBackgroundFetch(this.valList[t])||(yield[this.keyList[t],this.valList[t]])}*rentries(){for(const t of this.rindexes())void 0===this.valList[t]||void 0===this.keyList[t]||this.isBackgroundFetch(this.valList[t])||(yield[this.keyList[t],this.valList[t]])}*keys(){for(const t of this.indexes())void 0===this.keyList[t]||this.isBackgroundFetch(this.valList[t])||(yield this.keyList[t])}*rkeys(){for(const t of this.rindexes())void 0===this.keyList[t]||this.isBackgroundFetch(this.valList[t])||(yield this.keyList[t])}*values(){for(const t of this.indexes())void 0===this.valList[t]||this.isBackgroundFetch(this.valList[t])||(yield this.valList[t])}*rvalues(){for(const t of this.rindexes())void 0===this.valList[t]||this.isBackgroundFetch(this.valList[t])||(yield this.valList[t])}[Symbol.iterator](){return this.entries()}find(t,e){for(const i of this.indexes()){const s=this.valList[i],n=this.isBackgroundFetch(s)?s.__staleWhileFetching:s;if(void 0!==n&&t(n,this.keyList[i],this))return this.get(this.keyList[i],e)}}forEach(t,e=this){for(const i of this.indexes()){const s=this.valList[i],n=this.isBackgroundFetch(s)?s.__staleWhileFetching:s;void 0!==n&&t.call(e,n,this.keyList[i],this)}}rforEach(t,e=this){for(const i of this.rindexes()){const s=this.valList[i],n=this.isBackgroundFetch(s)?s.__staleWhileFetching:s;void 0!==n&&t.call(e,n,this.keyList[i],this)}}get prune(){return u("prune","purgeStale"),this.purgeStale}purgeStale(){let t=!1;for(const e of this.rindexes({allowStale:!0}))this.isStale(e)&&(this.delete(this.keyList[e]),t=!0);return t}dump(){const t=[];for(const e of this.indexes({allowStale:!0})){const i=this.keyList[e],s=this.valList[e],o=this.isBackgroundFetch(s)?s.__staleWhileFetching:s;if(void 0===o)continue;const r={value:o};if(this.ttls){r.ttl=this.ttls[e];const t=n.now()-this.starts[e];r.start=Math.floor(Date.now()-t)}this.sizes&&(r.size=this.sizes[e]),t.unshift([i,r])}return t}load(t){this.clear();for(const[e,i]of t){if(i.start){const t=Date.now()-i.start;i.start=n.now()-t}this.set(e,i.value,i)}}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,start:s,noDisposeOnSet:n=this.noDisposeOnSet,size:o=0,sizeCalculation:r=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL,status:h}={}){if(o=this.requireSize(t,e,o,r),this.maxEntrySize&&o>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=!0),this.delete(t),this;let l=0===this.size?void 0:this.keyMap.get(t);if(void 0===l)l=this.newIndex(),this.keyList[l]=t,this.valList[l]=e,this.keyMap.set(t,l),this.next[this.tail]=l,this.prev[l]=this.tail,this.tail=l,this.size++,this.addItemSize(l,o,h),h&&(h.set="add"),a=!1;else{this.moveToTail(l);const i=this.valList[l];if(e!==i){if(this.isBackgroundFetch(i)?i.__abortController.abort(new Error("replaced")):n||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(l),this.valList[l]=e,this.addItemSize(l,o,h),h){h.set="replace";const t=i&&this.isBackgroundFetch(i)?i.__staleWhileFetching:i;void 0!==t&&(h.oldValue=t)}}else h&&(h.set="update")}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),a||this.setItemTTL(l,i,s),this.statusTTL(h,l),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return 0===this.size?this.tail:this.size===this.max&&0!==this.max?this.evict(!1):0!==this.free.length?this.free.pop():this.initialFill++}pop(){if(this.size){const t=this.valList[this.head];return this.evict(!0),t}}evict(t){const e=this.head,i=this.keyList[e],s=this.valList[e];return this.isBackgroundFetch(s)?s.__abortController.abort(new Error("evicted")):(this.dispose(s,i,"evict"),this.disposeAfter&&this.disposed.push([s,i,"evict"])),this.removeItemSize(e),t&&(this.keyList[e]=null,this.valList[e]=null,this.free.push(e)),this.head=this.next[e],this.keyMap.delete(i),this.size--,e}has(t,{updateAgeOnHas:e=this.updateAgeOnHas,status:i}={}){const s=this.keyMap.get(t);if(void 0!==s){if(!this.isStale(s))return e&&this.updateItemAge(s),i&&(i.has="hit"),this.statusTTL(i,s),!0;i&&(i.has="stale",this.statusTTL(i,s))}else i&&(i.has="miss");return!1}peek(t,{allowStale:e=this.allowStale}={}){const i=this.keyMap.get(t);if(void 0!==i&&(e||!this.isStale(i))){const t=this.valList[i];return this.isBackgroundFetch(t)?t.__staleWhileFetching:t}}backgroundFetch(t,e,i,s){const n=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(n))return n;const r=new o;i.signal&&i.signal.addEventListener("abort",(()=>r.abort(i.signal.reason)));const a={signal:r.signal,options:i,context:s},h=(s,n=!1)=>{const{aborted:o}=r.signal,h=i.ignoreFetchAbort&&void 0!==s;return i.status&&(o&&!n?(i.status.fetchAborted=!0,i.status.fetchError=r.signal.reason,h&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),!o||h||n?(this.valList[e]===c&&(void 0===s?c.__staleWhileFetching?this.valList[e]=c.__staleWhileFetching:this.delete(t):(i.status&&(i.status.fetchUpdated=!0),this.set(t,s,a.options))),s):l(r.signal.reason)},l=s=>{const{aborted:n}=r.signal,o=n&&i.allowStaleOnFetchAbort,a=o||i.allowStaleOnFetchRejection,h=a||i.noDeleteOnFetchRejection;if(this.valList[e]===c){!h||void 0===c.__staleWhileFetching?this.delete(t):o||(this.valList[e]=c.__staleWhileFetching)}if(a)return i.status&&void 0!==c.__staleWhileFetching&&(i.status.returnedStale=!0),c.__staleWhileFetching;if(c.__returned===c)throw s};i.status&&(i.status.fetchDispatched=!0);const c=new Promise(((e,s)=>{this.fetchMethod(t,n,a).then((t=>e(t)),s),r.signal.addEventListener("abort",(()=>{i.ignoreFetchAbort&&!i.allowStaleOnFetchAbort||(e(),i.allowStaleOnFetchAbort&&(e=t=>h(t,!0)))}))})).then(h,(t=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=t),l(t))));return c.__abortController=r,c.__staleWhileFetching=n,c.__returned=null,void 0===e?(this.set(t,c,{...a.options,status:void 0}),e=this.keyMap.get(t)):this.valList[e]=c,c}isBackgroundFetch(t){return t&&"object"==typeof t&&"function"==typeof t.then&&Object.prototype.hasOwnProperty.call(t,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(t,"__returned")&&(t.__returned===t||null===t.__returned)}async fetch(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:r=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:c=this.allowStaleOnFetchRejection,ignoreFetchAbort:u=this.ignoreFetchAbort,allowStaleOnFetchAbort:d=this.allowStaleOnFetchAbort,fetchContext:f=this.fetchContext,forceRefresh:p=!1,status:g,signal:v}={}){if(!this.fetchMethod)return g&&(g.fetch="get"),this.get(t,{allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s,status:g});const y={allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s,ttl:n,noDisposeOnSet:o,size:r,sizeCalculation:a,noUpdateTTL:h,noDeleteOnFetchRejection:l,allowStaleOnFetchRejection:c,allowStaleOnFetchAbort:d,ignoreFetchAbort:u,status:g,signal:v};let m=this.keyMap.get(t);if(void 0===m){g&&(g.fetch="miss");const e=this.backgroundFetch(t,m,y,f);return e.__returned=e}{const s=this.valList[m];if(this.isBackgroundFetch(s)){const t=e&&void 0!==s.__staleWhileFetching;return g&&(g.fetch="inflight",t&&(g.returnedStale=!0)),t?s.__staleWhileFetching:s.__returned=s}const n=this.isStale(m);if(!p&&!n)return g&&(g.fetch="hit"),this.moveToTail(m),i&&this.updateItemAge(m),this.statusTTL(g,m),s;const o=this.backgroundFetch(t,m,y,f),r=void 0!==o.__staleWhileFetching,a=r&&e;return g&&(g.fetch=r&&n?"stale":"refresh",a&&n&&(g.returnedStale=!0)),a?o.__staleWhileFetching:o.__returned=o}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,status:n}={}){const o=this.keyMap.get(t);if(void 0!==o){const r=this.valList[o],a=this.isBackgroundFetch(r);return this.statusTTL(n,o),this.isStale(o)?(n&&(n.get="stale"),a?(n&&(n.returnedStale=e&&void 0!==r.__staleWhileFetching),e?r.__staleWhileFetching:void 0):(s||this.delete(t),n&&(n.returnedStale=e),e?r:void 0)):(n&&(n.get="hit"),a?r.__staleWhileFetching:(this.moveToTail(o),i&&this.updateItemAge(o),r))}n&&(n.get="miss")}connect(t,e){this.prev[e]=t,this.next[t]=e}moveToTail(t){t!==this.tail&&(t===this.head?this.head=this.next[t]:this.connect(this.prev[t],this.next[t]),this.connect(this.tail,t),this.tail=t)}get del(){return u("del","delete"),this.delete}delete(t){let e=!1;if(0!==this.size){const i=this.keyMap.get(t);if(void 0!==i)if(e=!0,1===this.size)this.clear();else{this.removeItemSize(i);const e=this.valList[i];this.isBackgroundFetch(e)?e.__abortController.abort(new Error("deleted")):(this.dispose(e,t,"delete"),this.disposeAfter&&this.disposed.push([e,t,"delete"])),this.keyMap.delete(t),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return e}clear(){for(const t of this.rindexes({allowStale:!0})){const e=this.valList[t];if(this.isBackgroundFetch(e))e.__abortController.abort(new Error("deleted"));else{const i=this.keyList[t];this.dispose(e,i,"delete"),this.disposeAfter&&this.disposed.push([e,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return u("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(f(i)){const{prototype:s}=S,{get:n}=Object.getOwnPropertyDescriptor(s,t);p(i,`${t} property`,`cache.${e}`,n)}})("length","size"),this.size}static get AbortController(){return o}static get AbortSignal(){return h}}var w=S;function x(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}function z(t,e){var i,s,n,o,r={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(h){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(r=0)),r;)try{if(i=1,s&&(n=2&a[0]?s.return:a[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,a[1])).done)return n;switch(s=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,s=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(n=r.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){r.label=a[1];break}if(6===a[0]&&r.label<n[1]){r.label=n[1],n=a;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(a);break}n[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(t){a=[6,t],s=0}finally{i=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}}function L(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=t[0],n=t[1],o=t[2],r=s.default.getUri({url:i,params:n,paramsSerializer:o}),a=r.split("?"),h=a[0],l=a[1];if(l){var c=l.split("&");return"".concat(h,"?").concat(c.sort().join("&"))}return r}t.Cache=w,t.cacheAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.enabledByDefault,n=void 0===s||s,o=e.cacheFlag,r=void 0===o?"cache":o,a=e.defaultCache,h=void 0===a?new w({ttl:3e5,max:100}):a;return function(e){var s,o=e.url,a=e.method,l=e.params,c=e.paramsSerializer,u=e.forceUpdate,d=void 0!==e[r]&&null!==e[r]?e[r]:n;if("get"===a&&d){var f="function"!=typeof(s=d).get||"function"!=typeof s.set||"function"!=typeof s.delete&&"function"!=typeof s.del?h:d,p=L(o,l,c),g=f.get(p);return!g||u?(g=x(i,void 0,void 0,(function(){var i;return z(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,s.sent()];case 2:throw i=s.sent(),"delete"in f?f.delete(p):f.del(p),i;case 3:return[2]}}))})),f.set(p,g),g):("info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by cache adapter --\x3e url: ".concat(p)),g)}return t(e)}},t.retryAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.times,n=void 0===s?2:s;return function(e){return x(i,void 0,void 0,(function(){var i,s,o,r,a=this;return z(this,(function(h){return i=e.retryTimes,s=void 0===i?n:i,!1,o=0,r=function(){return x(a,void 0,void 0,(function(){var i;return z(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,n.sent()];case 2:if(i=n.sent(),s===o)throw i;return o++,"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request start retrying --\x3e url: ".concat(e.url," , time: ").concat(o)),[2,r()];case 3:return[2]}}))}))},[2,r()]}))}))}},t.throttleAdapterEnhancer=function(t,e){var i=this;void 0===e&&(e={});var s=e.threshold,n=void 0===s?1e3:s,o=e.cache,r=void 0===o?new w({max:10}):o;return function(e){var s=e.url,o=e.method,a=L(s,e.params,e.paramsSerializer),h=Date.now(),l=r.get(a)||{timestamp:h};if("get"===o){if(h-l.timestamp<=n){var c=l.value;if(c)return"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by throttle adapter --\x3e url: ".concat(a)),c}return function(e,s){var n=x(i,void 0,void 0,(function(){var i,n;return z(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,t(s)];case 1:return i=o.sent(),r.set(e,{timestamp:Date.now(),value:Promise.resolve(i)}),[2,i];case 2:throw n=o.sent(),"delete"in r?r.delete(e):r.del(e),n;case 3:return[2]}}))}));return r.set(e,{timestamp:Date.now(),value:n}),n}(a,e)}return t(e)}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=axios-extensions.min.js.map |
@@ -14,3 +14,3 @@ /** | ||
} | ||
export declare type Options = { | ||
export type Options = { | ||
enabledByDefault?: boolean; | ||
@@ -17,0 +17,0 @@ cacheFlag?: string; |
@@ -11,5 +11,5 @@ /** | ||
} | ||
export declare type Options = { | ||
export type Options = { | ||
times?: number; | ||
}; | ||
export default function retryAdapterEnhancer(adapter: AxiosAdapter, options?: Options): AxiosAdapter; |
@@ -8,7 +8,7 @@ /** | ||
import { ICacheLike } from './utils/isCacheLike'; | ||
export declare type RecordedCache = { | ||
export type RecordedCache = { | ||
timestamp: number; | ||
value?: AxiosPromise; | ||
}; | ||
export declare type Options = { | ||
export type Options = { | ||
threshold?: number; | ||
@@ -15,0 +15,0 @@ cache?: ICacheLike<RecordedCache>; |
@@ -6,2 +6,2 @@ /** | ||
*/ | ||
export default function buildSortedURL(...args: any[]): any; | ||
export default function buildSortedURL(...args: any[]): string; |
@@ -6,4 +6,3 @@ /** | ||
*/ | ||
// @ts-ignore | ||
import buildURL from 'axios/lib/helpers/buildURL'; | ||
import axios from 'axios'; | ||
export default function buildSortedURL() { | ||
@@ -14,3 +13,4 @@ var args = []; | ||
} | ||
var builtURL = buildURL.apply(void 0, args); | ||
var url = args[0], params = args[1], paramsSerializer = args[2]; | ||
var builtURL = axios.getUri({ url: url, params: params, paramsSerializer: paramsSerializer }); | ||
var _a = builtURL.split('?'), urlPath = _a[0], queryString = _a[1]; | ||
@@ -17,0 +17,0 @@ if (queryString) { |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare type ICacheLike<T> = { | ||
export type ICacheLike<T> = { | ||
get(key: string): T | undefined; | ||
@@ -9,0 +9,0 @@ set(key: string, value: T): void; |
@@ -14,3 +14,3 @@ /** | ||
} | ||
export declare type Options = { | ||
export type Options = { | ||
enabledByDefault?: boolean; | ||
@@ -17,0 +17,0 @@ cacheFlag?: string; |
@@ -11,5 +11,5 @@ /** | ||
} | ||
export declare type Options = { | ||
export type Options = { | ||
times?: number; | ||
}; | ||
export default function retryAdapterEnhancer(adapter: AxiosAdapter, options?: Options): AxiosAdapter; |
@@ -8,7 +8,7 @@ /** | ||
import { ICacheLike } from './utils/isCacheLike'; | ||
export declare type RecordedCache = { | ||
export type RecordedCache = { | ||
timestamp: number; | ||
value?: AxiosPromise; | ||
}; | ||
export declare type Options = { | ||
export type Options = { | ||
threshold?: number; | ||
@@ -15,0 +15,0 @@ cache?: ICacheLike<RecordedCache>; |
@@ -6,2 +6,2 @@ /** | ||
*/ | ||
export default function buildSortedURL(...args: any[]): any; | ||
export default function buildSortedURL(...args: any[]): string; |
@@ -9,4 +9,3 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
// @ts-ignore | ||
var buildURL_1 = tslib_1.__importDefault(require("axios/lib/helpers/buildURL")); | ||
var axios_1 = tslib_1.__importDefault(require("axios")); | ||
function buildSortedURL() { | ||
@@ -17,3 +16,4 @@ var args = []; | ||
} | ||
var builtURL = buildURL_1.default.apply(void 0, args); | ||
var url = args[0], params = args[1], paramsSerializer = args[2]; | ||
var builtURL = axios_1.default.getUri({ url: url, params: params, paramsSerializer: paramsSerializer }); | ||
var _a = builtURL.split('?'), urlPath = _a[0], queryString = _a[1]; | ||
@@ -20,0 +20,0 @@ if (queryString) { |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare type ICacheLike<T> = { | ||
export type ICacheLike<T> = { | ||
get(key: string): T | undefined; | ||
@@ -9,0 +9,0 @@ set(key: string, value: T): void; |
{ | ||
"name": "axios-extensions", | ||
"version": "3.1.6", | ||
"version": "3.1.7", | ||
"description": "make axios great again", | ||
@@ -54,3 +54,3 @@ "homepage": "https://github.com/kuitos/axios-extensions", | ||
"ava": "^3.15.0", | ||
"axios": "^0.21.1", | ||
"axios": ">=0.21.1", | ||
"codecov": "^3.8.1", | ||
@@ -57,0 +57,0 @@ "husky": "^4.3.8", |
@@ -6,3 +6,3 @@ # axios-extensions | ||
[![npm downloads](https://img.shields.io/npm/dt/axios-extensions.svg?style=flat-square)](https://www.npmjs.com/package/axios-extensions) | ||
[![Build Status](https://img.shields.io/travis/kuitos/axios-extensions.svg?style=flat-square)](https://travis-ci.org/kuitos/axios-extensions) | ||
[![Build Status](https://img.shields.io/github/actions/workflow/status/kuitos/axios-extensions/ci.yml?branch=master&style=flat-square)](https://github.com/kuitos/axios-extensions/actions/workflows/ci.yml) | ||
@@ -9,0 +9,0 @@ A non-invasive, simple, reliable collection of axios extension |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
391542
3141
1
13