axios-extensions
Advanced tools
Comparing version 3.1.2 to 3.1.3
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global['axios-extensions'] = {})); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global['axios-extensions'] = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var iterator = function (Yallist) { | ||
Yallist.prototype[Symbol.iterator] = function* () { | ||
for (let walker = this.head; walker; walker = walker.next) { | ||
yield walker.value; | ||
} | ||
}; | ||
}; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var yallist = Yallist; | ||
var pseudomap = PseudoMap; | ||
Yallist.Node = Node; | ||
Yallist.create = Yallist; | ||
function PseudoMap (set) { | ||
if (!(this instanceof PseudoMap)) // whyyyyyyy | ||
throw new TypeError("Constructor PseudoMap requires 'new'") | ||
function Yallist (list) { | ||
var self = this; | ||
if (!(self instanceof Yallist)) { | ||
self = new Yallist(); | ||
} | ||
this.clear(); | ||
self.tail = null; | ||
self.head = null; | ||
self.length = 0; | ||
if (set) { | ||
if ((set instanceof PseudoMap) || | ||
(typeof Map === 'function' && set instanceof Map)) | ||
set.forEach(function (value, key) { | ||
this.set(key, value); | ||
}, this); | ||
else if (Array.isArray(set)) | ||
set.forEach(function (kv) { | ||
this.set(kv[0], kv[1]); | ||
}, this); | ||
else | ||
throw new TypeError('invalid argument') | ||
} | ||
} | ||
if (list && typeof list.forEach === 'function') { | ||
list.forEach(function (item) { | ||
self.push(item); | ||
}); | ||
} else if (arguments.length > 0) { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
self.push(arguments[i]); | ||
} | ||
} | ||
PseudoMap.prototype.forEach = function (fn, thisp) { | ||
thisp = thisp || this; | ||
Object.keys(this._data).forEach(function (k) { | ||
if (k !== 'size') | ||
fn.call(thisp, this._data[k].value, this._data[k].key); | ||
}, this); | ||
}; | ||
return self | ||
} | ||
PseudoMap.prototype.has = function (k) { | ||
return !!find(this._data, k) | ||
}; | ||
Yallist.prototype.removeNode = function (node) { | ||
if (node.list !== this) { | ||
throw new Error('removing node which does not belong to this list') | ||
} | ||
PseudoMap.prototype.get = function (k) { | ||
var res = find(this._data, k); | ||
return res && res.value | ||
}; | ||
var next = node.next; | ||
var prev = node.prev; | ||
PseudoMap.prototype.set = function (k, v) { | ||
set(this._data, k, v); | ||
}; | ||
if (next) { | ||
next.prev = prev; | ||
} | ||
PseudoMap.prototype.delete = function (k) { | ||
var res = find(this._data, k); | ||
if (res) { | ||
delete this._data[res._index]; | ||
this._data.size--; | ||
} | ||
}; | ||
if (prev) { | ||
prev.next = next; | ||
} | ||
PseudoMap.prototype.clear = function () { | ||
var data = Object.create(null); | ||
data.size = 0; | ||
if (node === this.head) { | ||
this.head = next; | ||
} | ||
if (node === this.tail) { | ||
this.tail = prev; | ||
} | ||
Object.defineProperty(this, '_data', { | ||
value: data, | ||
enumerable: false, | ||
configurable: true, | ||
writable: false | ||
}); | ||
}; | ||
node.list.length--; | ||
node.next = null; | ||
node.prev = null; | ||
node.list = null; | ||
Object.defineProperty(PseudoMap.prototype, 'size', { | ||
get: function () { | ||
return this._data.size | ||
}, | ||
set: function (n) {}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return next | ||
}; | ||
PseudoMap.prototype.values = | ||
PseudoMap.prototype.keys = | ||
PseudoMap.prototype.entries = function () { | ||
throw new Error('iterators are not implemented in this version') | ||
}; | ||
Yallist.prototype.unshiftNode = function (node) { | ||
if (node === this.head) { | ||
return | ||
} | ||
// Either identical, or both NaN | ||
function same (a, b) { | ||
return a === b || a !== a && b !== b | ||
} | ||
if (node.list) { | ||
node.list.removeNode(node); | ||
} | ||
function Entry (k, v, i) { | ||
this.key = k; | ||
this.value = v; | ||
this._index = i; | ||
} | ||
var head = this.head; | ||
node.list = this; | ||
node.next = head; | ||
if (head) { | ||
head.prev = node; | ||
} | ||
function find (data, k) { | ||
for (var i = 0, s = '_' + k, key = s; | ||
hasOwnProperty.call(data, key); | ||
key = s + i++) { | ||
if (same(data[key].key, k)) | ||
return data[key] | ||
} | ||
} | ||
this.head = node; | ||
if (!this.tail) { | ||
this.tail = node; | ||
} | ||
this.length++; | ||
}; | ||
function set (data, k, v) { | ||
for (var i = 0, s = '_' + k, key = s; | ||
hasOwnProperty.call(data, key); | ||
key = s + i++) { | ||
if (same(data[key].key, k)) { | ||
data[key].value = v; | ||
return | ||
} | ||
} | ||
data.size++; | ||
data[key] = new Entry(k, v, key); | ||
} | ||
Yallist.prototype.pushNode = function (node) { | ||
if (node === this.tail) { | ||
return | ||
} | ||
var map = createCommonjsModule(function (module) { | ||
if (process.env.npm_package_name === 'pseudomap' && | ||
process.env.npm_lifecycle_script === 'test') | ||
process.env.TEST_PSEUDOMAP = 'true'; | ||
if (node.list) { | ||
node.list.removeNode(node); | ||
} | ||
if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) { | ||
module.exports = Map; | ||
} else { | ||
module.exports = pseudomap; | ||
} | ||
}); | ||
var tail = this.tail; | ||
node.list = this; | ||
node.prev = tail; | ||
if (tail) { | ||
tail.next = node; | ||
} | ||
var inherits; | ||
if (typeof Object.create === 'function'){ | ||
inherits = function inherits(ctor, superCtor) { | ||
// implementation from standard node.js 'util' module | ||
ctor.super_ = superCtor; | ||
ctor.prototype = Object.create(superCtor.prototype, { | ||
constructor: { | ||
value: ctor, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
}; | ||
} else { | ||
inherits = function inherits(ctor, superCtor) { | ||
ctor.super_ = superCtor; | ||
var TempCtor = function () {}; | ||
TempCtor.prototype = superCtor.prototype; | ||
ctor.prototype = new TempCtor(); | ||
ctor.prototype.constructor = ctor; | ||
}; | ||
} | ||
var inherits$1 = inherits; | ||
this.tail = node; | ||
if (!this.head) { | ||
this.head = node; | ||
} | ||
this.length++; | ||
}; | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
var formatRegExp = /%[sdj%]/g; | ||
function format(f) { | ||
if (!isString(f)) { | ||
var objects = []; | ||
for (var i = 0; i < arguments.length; i++) { | ||
objects.push(inspect(arguments[i])); | ||
} | ||
return objects.join(' '); | ||
} | ||
Yallist.prototype.push = function () { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
push(this, arguments[i]); | ||
} | ||
return this.length | ||
}; | ||
var i = 1; | ||
var args = arguments; | ||
var len = args.length; | ||
var str = String(f).replace(formatRegExp, function(x) { | ||
if (x === '%%') return '%'; | ||
if (i >= len) return x; | ||
switch (x) { | ||
case '%s': return String(args[i++]); | ||
case '%d': return Number(args[i++]); | ||
case '%j': | ||
try { | ||
return JSON.stringify(args[i++]); | ||
} catch (_) { | ||
return '[Circular]'; | ||
} | ||
default: | ||
return x; | ||
} | ||
}); | ||
for (var x = args[i]; i < len; x = args[++i]) { | ||
if (isNull(x) || !isObject(x)) { | ||
str += ' ' + x; | ||
} else { | ||
str += ' ' + inspect(x); | ||
} | ||
} | ||
return str; | ||
} | ||
Yallist.prototype.unshift = function () { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
unshift(this, arguments[i]); | ||
} | ||
return this.length | ||
}; | ||
// Mark that a method should not be used. | ||
// Returns a modified function which warns once by default. | ||
// If --no-deprecation is set, then it is a no-op. | ||
function deprecate(fn, msg) { | ||
// Allow for deprecating things in the process of starting up. | ||
if (isUndefined(global.process)) { | ||
return function() { | ||
return deprecate(fn, msg).apply(this, arguments); | ||
}; | ||
} | ||
Yallist.prototype.pop = function () { | ||
if (!this.tail) { | ||
return undefined | ||
} | ||
var warned = false; | ||
function deprecated() { | ||
if (!warned) { | ||
{ | ||
console.error(msg); | ||
} | ||
warned = true; | ||
} | ||
return fn.apply(this, arguments); | ||
} | ||
var res = this.tail.value; | ||
this.tail = this.tail.prev; | ||
if (this.tail) { | ||
this.tail.next = null; | ||
} else { | ||
this.head = null; | ||
} | ||
this.length--; | ||
return res | ||
}; | ||
return deprecated; | ||
} | ||
Yallist.prototype.shift = function () { | ||
if (!this.head) { | ||
return undefined | ||
} | ||
var debugs = {}; | ||
var debugEnviron; | ||
function debuglog(set) { | ||
if (isUndefined(debugEnviron)) | ||
debugEnviron = ''; | ||
set = set.toUpperCase(); | ||
if (!debugs[set]) { | ||
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { | ||
var pid = 0; | ||
debugs[set] = function() { | ||
var msg = format.apply(null, arguments); | ||
console.error('%s %d: %s', set, pid, msg); | ||
}; | ||
} else { | ||
debugs[set] = function() {}; | ||
} | ||
} | ||
return debugs[set]; | ||
} | ||
var res = this.head.value; | ||
this.head = this.head.next; | ||
if (this.head) { | ||
this.head.prev = null; | ||
} else { | ||
this.tail = null; | ||
} | ||
this.length--; | ||
return res | ||
}; | ||
/** | ||
* Echos the value of a value. Trys to print the value out | ||
* in the best way possible given the different types. | ||
* | ||
* @param {Object} obj The object to print out. | ||
* @param {Object} opts Optional options object that alters the output. | ||
*/ | ||
/* legacy: obj, showHidden, depth, colors*/ | ||
function inspect(obj, opts) { | ||
// default options | ||
var ctx = { | ||
seen: [], | ||
stylize: stylizeNoColor | ||
}; | ||
// legacy... | ||
if (arguments.length >= 3) ctx.depth = arguments[2]; | ||
if (arguments.length >= 4) ctx.colors = arguments[3]; | ||
if (isBoolean(opts)) { | ||
// legacy... | ||
ctx.showHidden = opts; | ||
} else if (opts) { | ||
// got an "options" object | ||
_extend(ctx, opts); | ||
} | ||
// set default options | ||
if (isUndefined(ctx.showHidden)) ctx.showHidden = false; | ||
if (isUndefined(ctx.depth)) ctx.depth = 2; | ||
if (isUndefined(ctx.colors)) ctx.colors = false; | ||
if (isUndefined(ctx.customInspect)) ctx.customInspect = true; | ||
if (ctx.colors) ctx.stylize = stylizeWithColor; | ||
return formatValue(ctx, obj, ctx.depth); | ||
} | ||
Yallist.prototype.forEach = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this.head, i = 0; walker !== null; i++) { | ||
fn.call(thisp, walker.value, i, this); | ||
walker = walker.next; | ||
} | ||
}; | ||
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics | ||
inspect.colors = { | ||
'bold' : [1, 22], | ||
'italic' : [3, 23], | ||
'underline' : [4, 24], | ||
'inverse' : [7, 27], | ||
'white' : [37, 39], | ||
'grey' : [90, 39], | ||
'black' : [30, 39], | ||
'blue' : [34, 39], | ||
'cyan' : [36, 39], | ||
'green' : [32, 39], | ||
'magenta' : [35, 39], | ||
'red' : [31, 39], | ||
'yellow' : [33, 39] | ||
}; | ||
Yallist.prototype.forEachReverse = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) { | ||
fn.call(thisp, walker.value, i, this); | ||
walker = walker.prev; | ||
} | ||
}; | ||
// Don't use 'blue' not visible on cmd.exe | ||
inspect.styles = { | ||
'special': 'cyan', | ||
'number': 'yellow', | ||
'boolean': 'yellow', | ||
'undefined': 'grey', | ||
'null': 'bold', | ||
'string': 'green', | ||
'date': 'magenta', | ||
// "name": intentionally not styling | ||
'regexp': 'red' | ||
}; | ||
Yallist.prototype.get = function (n) { | ||
for (var i = 0, walker = this.head; walker !== null && i < n; i++) { | ||
// abort out of the list early if we hit a cycle | ||
walker = walker.next; | ||
} | ||
if (i === n && walker !== null) { | ||
return walker.value | ||
} | ||
}; | ||
Yallist.prototype.getReverse = function (n) { | ||
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) { | ||
// abort out of the list early if we hit a cycle | ||
walker = walker.prev; | ||
} | ||
if (i === n && walker !== null) { | ||
return walker.value | ||
} | ||
}; | ||
function stylizeWithColor(str, styleType) { | ||
var style = inspect.styles[styleType]; | ||
Yallist.prototype.map = function (fn, thisp) { | ||
thisp = thisp || this; | ||
var res = new Yallist(); | ||
for (var walker = this.head; walker !== null;) { | ||
res.push(fn.call(thisp, walker.value, this)); | ||
walker = walker.next; | ||
} | ||
return res | ||
}; | ||
if (style) { | ||
return '\u001b[' + inspect.colors[style][0] + 'm' + str + | ||
'\u001b[' + inspect.colors[style][1] + 'm'; | ||
} else { | ||
return str; | ||
} | ||
} | ||
Yallist.prototype.mapReverse = function (fn, thisp) { | ||
thisp = thisp || this; | ||
var res = new Yallist(); | ||
for (var walker = this.tail; walker !== null;) { | ||
res.push(fn.call(thisp, walker.value, this)); | ||
walker = walker.prev; | ||
} | ||
return res | ||
}; | ||
Yallist.prototype.reduce = function (fn, initial) { | ||
var acc; | ||
var walker = this.head; | ||
if (arguments.length > 1) { | ||
acc = initial; | ||
} else if (this.head) { | ||
walker = this.head.next; | ||
acc = this.head.value; | ||
} else { | ||
throw new TypeError('Reduce of empty list with no initial value') | ||
} | ||
function stylizeNoColor(str, styleType) { | ||
return str; | ||
} | ||
for (var i = 0; walker !== null; i++) { | ||
acc = fn(acc, walker.value, i); | ||
walker = walker.next; | ||
} | ||
return acc | ||
}; | ||
function arrayToHash(array) { | ||
var hash = {}; | ||
Yallist.prototype.reduceReverse = function (fn, initial) { | ||
var acc; | ||
var walker = this.tail; | ||
if (arguments.length > 1) { | ||
acc = initial; | ||
} else if (this.tail) { | ||
walker = this.tail.prev; | ||
acc = this.tail.value; | ||
} else { | ||
throw new TypeError('Reduce of empty list with no initial value') | ||
} | ||
array.forEach(function(val, idx) { | ||
hash[val] = true; | ||
}); | ||
for (var i = this.length - 1; walker !== null; i--) { | ||
acc = fn(acc, walker.value, i); | ||
walker = walker.prev; | ||
} | ||
return hash; | ||
} | ||
return acc | ||
}; | ||
Yallist.prototype.toArray = function () { | ||
var arr = new Array(this.length); | ||
for (var i = 0, walker = this.head; walker !== null; i++) { | ||
arr[i] = walker.value; | ||
walker = walker.next; | ||
} | ||
return arr | ||
}; | ||
function formatValue(ctx, value, recurseTimes) { | ||
// Provide a hook for user-specified inspect functions. | ||
// Check that value is an object with an inspect function on it | ||
if (ctx.customInspect && | ||
value && | ||
isFunction(value.inspect) && | ||
// Filter out the util module, it's inspect function is special | ||
value.inspect !== inspect && | ||
// Also filter out any prototype objects using the circular check. | ||
!(value.constructor && value.constructor.prototype === value)) { | ||
var ret = value.inspect(recurseTimes, ctx); | ||
if (!isString(ret)) { | ||
ret = formatValue(ctx, ret, recurseTimes); | ||
} | ||
return ret; | ||
} | ||
Yallist.prototype.toArrayReverse = function () { | ||
var arr = new Array(this.length); | ||
for (var i = 0, walker = this.tail; walker !== null; i++) { | ||
arr[i] = walker.value; | ||
walker = walker.prev; | ||
} | ||
return arr | ||
}; | ||
// Primitive types cannot have properties | ||
var primitive = formatPrimitive(ctx, value); | ||
if (primitive) { | ||
return primitive; | ||
} | ||
Yallist.prototype.slice = function (from, to) { | ||
to = to || this.length; | ||
if (to < 0) { | ||
to += this.length; | ||
} | ||
from = from || 0; | ||
if (from < 0) { | ||
from += this.length; | ||
} | ||
var ret = new Yallist(); | ||
if (to < from || to < 0) { | ||
return ret | ||
} | ||
if (from < 0) { | ||
from = 0; | ||
} | ||
if (to > this.length) { | ||
to = this.length; | ||
} | ||
for (var i = 0, walker = this.head; walker !== null && i < from; i++) { | ||
walker = walker.next; | ||
} | ||
for (; walker !== null && i < to; i++, walker = walker.next) { | ||
ret.push(walker.value); | ||
} | ||
return ret | ||
}; | ||
// Look up the keys of the object. | ||
var keys = Object.keys(value); | ||
var visibleKeys = arrayToHash(keys); | ||
Yallist.prototype.sliceReverse = function (from, to) { | ||
to = to || this.length; | ||
if (to < 0) { | ||
to += this.length; | ||
} | ||
from = from || 0; | ||
if (from < 0) { | ||
from += this.length; | ||
} | ||
var ret = new Yallist(); | ||
if (to < from || to < 0) { | ||
return ret | ||
} | ||
if (from < 0) { | ||
from = 0; | ||
} | ||
if (to > this.length) { | ||
to = this.length; | ||
} | ||
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) { | ||
walker = walker.prev; | ||
} | ||
for (; walker !== null && i > from; i--, walker = walker.prev) { | ||
ret.push(walker.value); | ||
} | ||
return ret | ||
}; | ||
if (ctx.showHidden) { | ||
keys = Object.getOwnPropertyNames(value); | ||
} | ||
Yallist.prototype.splice = function (start, deleteCount /*, ...nodes */) { | ||
if (start > this.length) { | ||
start = this.length - 1; | ||
} | ||
if (start < 0) { | ||
start = this.length + start; | ||
} | ||
// IE doesn't make error fields non-enumerable | ||
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx | ||
if (isError(value) | ||
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { | ||
return formatError(value); | ||
} | ||
for (var i = 0, walker = this.head; walker !== null && i < start; i++) { | ||
walker = walker.next; | ||
} | ||
// Some type of object without properties can be shortcutted. | ||
if (keys.length === 0) { | ||
if (isFunction(value)) { | ||
var name = value.name ? ': ' + value.name : ''; | ||
return ctx.stylize('[Function' + name + ']', 'special'); | ||
} | ||
if (isRegExp(value)) { | ||
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | ||
} | ||
if (isDate(value)) { | ||
return ctx.stylize(Date.prototype.toString.call(value), 'date'); | ||
} | ||
if (isError(value)) { | ||
return formatError(value); | ||
} | ||
} | ||
var ret = []; | ||
for (var i = 0; walker && i < deleteCount; i++) { | ||
ret.push(walker.value); | ||
walker = this.removeNode(walker); | ||
} | ||
if (walker === null) { | ||
walker = this.tail; | ||
} | ||
var base = '', array = false, braces = ['{', '}']; | ||
if (walker !== this.head && walker !== this.tail) { | ||
walker = walker.prev; | ||
} | ||
// Make Array say that they are Array | ||
if (isArray(value)) { | ||
array = true; | ||
braces = ['[', ']']; | ||
} | ||
for (var i = 2; i < arguments.length; i++) { | ||
walker = insert(this, walker, arguments[i]); | ||
} | ||
return ret; | ||
}; | ||
// Make functions say that they are functions | ||
if (isFunction(value)) { | ||
var n = value.name ? ': ' + value.name : ''; | ||
base = ' [Function' + n + ']'; | ||
} | ||
Yallist.prototype.reverse = function () { | ||
var head = this.head; | ||
var tail = this.tail; | ||
for (var walker = head; walker !== null; walker = walker.prev) { | ||
var p = walker.prev; | ||
walker.prev = walker.next; | ||
walker.next = p; | ||
} | ||
this.head = tail; | ||
this.tail = head; | ||
return this | ||
}; | ||
// Make RegExps say that they are RegExps | ||
if (isRegExp(value)) { | ||
base = ' ' + RegExp.prototype.toString.call(value); | ||
} | ||
function insert (self, node, value) { | ||
var inserted = node === self.head ? | ||
new Node(value, null, node, self) : | ||
new Node(value, node, node.next, self); | ||
// Make dates with properties first say the date | ||
if (isDate(value)) { | ||
base = ' ' + Date.prototype.toUTCString.call(value); | ||
} | ||
if (inserted.next === null) { | ||
self.tail = inserted; | ||
} | ||
if (inserted.prev === null) { | ||
self.head = inserted; | ||
} | ||
// Make error with message first say the error | ||
if (isError(value)) { | ||
base = ' ' + formatError(value); | ||
} | ||
self.length++; | ||
if (keys.length === 0 && (!array || value.length == 0)) { | ||
return braces[0] + base + braces[1]; | ||
} | ||
return inserted | ||
} | ||
if (recurseTimes < 0) { | ||
if (isRegExp(value)) { | ||
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | ||
} else { | ||
return ctx.stylize('[Object]', 'special'); | ||
} | ||
} | ||
function push (self, item) { | ||
self.tail = new Node(item, self.tail, null, self); | ||
if (!self.head) { | ||
self.head = self.tail; | ||
} | ||
self.length++; | ||
} | ||
ctx.seen.push(value); | ||
function unshift (self, item) { | ||
self.head = new Node(item, null, self.head, self); | ||
if (!self.tail) { | ||
self.tail = self.head; | ||
} | ||
self.length++; | ||
} | ||
var output; | ||
if (array) { | ||
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); | ||
} else { | ||
output = keys.map(function(key) { | ||
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); | ||
}); | ||
} | ||
function Node (value, prev, next, list) { | ||
if (!(this instanceof Node)) { | ||
return new Node(value, prev, next, list) | ||
} | ||
ctx.seen.pop(); | ||
this.list = list; | ||
this.value = value; | ||
return reduceToSingleString(output, base, braces); | ||
} | ||
if (prev) { | ||
prev.next = this; | ||
this.prev = prev; | ||
} else { | ||
this.prev = null; | ||
} | ||
if (next) { | ||
next.prev = this; | ||
this.next = next; | ||
} else { | ||
this.next = null; | ||
} | ||
} | ||
function formatPrimitive(ctx, value) { | ||
if (isUndefined(value)) | ||
return ctx.stylize('undefined', 'undefined'); | ||
if (isString(value)) { | ||
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | ||
.replace(/'/g, "\\'") | ||
.replace(/\\"/g, '"') + '\''; | ||
return ctx.stylize(simple, 'string'); | ||
} | ||
if (isNumber(value)) | ||
return ctx.stylize('' + value, 'number'); | ||
if (isBoolean(value)) | ||
return ctx.stylize('' + value, 'boolean'); | ||
// For some reason typeof null is "object", so special case here. | ||
if (isNull(value)) | ||
return ctx.stylize('null', 'null'); | ||
} | ||
try { | ||
// add if support for Symbol.iterator is present | ||
iterator(Yallist); | ||
} catch (er) {} | ||
// A linked list to keep track of recently-used-ness | ||
function formatError(value) { | ||
return '[' + Error.prototype.toString.call(value) + ']'; | ||
} | ||
const MAX = Symbol('max'); | ||
const LENGTH = Symbol('length'); | ||
const LENGTH_CALCULATOR = Symbol('lengthCalculator'); | ||
const ALLOW_STALE = Symbol('allowStale'); | ||
const MAX_AGE = Symbol('maxAge'); | ||
const DISPOSE = Symbol('dispose'); | ||
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet'); | ||
const LRU_LIST = Symbol('lruList'); | ||
const CACHE = Symbol('cache'); | ||
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet'); | ||
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { | ||
var output = []; | ||
for (var i = 0, l = value.length; i < l; ++i) { | ||
if (hasOwnProperty$1(value, String(i))) { | ||
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | ||
String(i), true)); | ||
} else { | ||
output.push(''); | ||
} | ||
} | ||
keys.forEach(function(key) { | ||
if (!key.match(/^\d+$/)) { | ||
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | ||
key, true)); | ||
} | ||
}); | ||
return output; | ||
} | ||
const naiveLength = () => 1; | ||
// lruList is a yallist where the head is the youngest | ||
// item, and the tail is the oldest. the list contains the Hit | ||
// objects as the entries. | ||
// Each Hit object has a reference to its Yallist.Node. This | ||
// never changes. | ||
// | ||
// cache is a Map (or PseudoMap) that matches the keys to | ||
// the Yallist.Node object. | ||
class LRUCache { | ||
constructor (options) { | ||
if (typeof options === 'number') | ||
options = { max: options }; | ||
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { | ||
var name, str, desc; | ||
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; | ||
if (desc.get) { | ||
if (desc.set) { | ||
str = ctx.stylize('[Getter/Setter]', 'special'); | ||
} else { | ||
str = ctx.stylize('[Getter]', 'special'); | ||
} | ||
} else { | ||
if (desc.set) { | ||
str = ctx.stylize('[Setter]', 'special'); | ||
} | ||
} | ||
if (!hasOwnProperty$1(visibleKeys, key)) { | ||
name = '[' + key + ']'; | ||
} | ||
if (!str) { | ||
if (ctx.seen.indexOf(desc.value) < 0) { | ||
if (isNull(recurseTimes)) { | ||
str = formatValue(ctx, desc.value, null); | ||
} else { | ||
str = formatValue(ctx, desc.value, recurseTimes - 1); | ||
} | ||
if (str.indexOf('\n') > -1) { | ||
if (array) { | ||
str = str.split('\n').map(function(line) { | ||
return ' ' + line; | ||
}).join('\n').substr(2); | ||
} else { | ||
str = '\n' + str.split('\n').map(function(line) { | ||
return ' ' + line; | ||
}).join('\n'); | ||
} | ||
} | ||
} else { | ||
str = ctx.stylize('[Circular]', 'special'); | ||
} | ||
} | ||
if (isUndefined(name)) { | ||
if (array && key.match(/^\d+$/)) { | ||
return str; | ||
} | ||
name = JSON.stringify('' + key); | ||
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { | ||
name = name.substr(1, name.length - 2); | ||
name = ctx.stylize(name, 'name'); | ||
} else { | ||
name = name.replace(/'/g, "\\'") | ||
.replace(/\\"/g, '"') | ||
.replace(/(^"|"$)/g, "'"); | ||
name = ctx.stylize(name, 'string'); | ||
} | ||
} | ||
if (!options) | ||
options = {}; | ||
return name + ': ' + str; | ||
} | ||
if (options.max && (typeof options.max !== 'number' || options.max < 0)) | ||
throw new TypeError('max must be a non-negative number') | ||
// Kind of weird to have a default max of Infinity, but oh well. | ||
const max = this[MAX] = options.max || Infinity; | ||
const lc = options.length || naiveLength; | ||
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc; | ||
this[ALLOW_STALE] = options.stale || false; | ||
if (options.maxAge && typeof options.maxAge !== 'number') | ||
throw new TypeError('maxAge must be a number') | ||
this[MAX_AGE] = options.maxAge || 0; | ||
this[DISPOSE] = options.dispose; | ||
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false; | ||
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false; | ||
this.reset(); | ||
} | ||
function reduceToSingleString(output, base, braces) { | ||
var length = output.reduce(function(prev, cur) { | ||
if (cur.indexOf('\n') >= 0) ; | ||
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; | ||
}, 0); | ||
// resize the cache when the max changes. | ||
set max (mL) { | ||
if (typeof mL !== 'number' || mL < 0) | ||
throw new TypeError('max must be a non-negative number') | ||
if (length > 60) { | ||
return braces[0] + | ||
(base === '' ? '' : base + '\n ') + | ||
' ' + | ||
output.join(',\n ') + | ||
' ' + | ||
braces[1]; | ||
} | ||
this[MAX] = mL || Infinity; | ||
trim(this); | ||
} | ||
get max () { | ||
return this[MAX] | ||
} | ||
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; | ||
} | ||
set allowStale (allowStale) { | ||
this[ALLOW_STALE] = !!allowStale; | ||
} | ||
get allowStale () { | ||
return this[ALLOW_STALE] | ||
} | ||
set maxAge (mA) { | ||
if (typeof mA !== 'number') | ||
throw new TypeError('maxAge must be a non-negative number') | ||
// NOTE: These type checking functions intentionally don't use `instanceof` | ||
// because it is fragile and can be easily faked with `Object.create()`. | ||
function isArray(ar) { | ||
return Array.isArray(ar); | ||
} | ||
this[MAX_AGE] = mA; | ||
trim(this); | ||
} | ||
get maxAge () { | ||
return this[MAX_AGE] | ||
} | ||
function isBoolean(arg) { | ||
return typeof arg === 'boolean'; | ||
} | ||
// resize the cache when the lengthCalculator changes. | ||
set lengthCalculator (lC) { | ||
if (typeof lC !== 'function') | ||
lC = naiveLength; | ||
function isNull(arg) { | ||
return arg === null; | ||
} | ||
if (lC !== this[LENGTH_CALCULATOR]) { | ||
this[LENGTH_CALCULATOR] = lC; | ||
this[LENGTH] = 0; | ||
this[LRU_LIST].forEach(hit => { | ||
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key); | ||
this[LENGTH] += hit.length; | ||
}); | ||
} | ||
trim(this); | ||
} | ||
get lengthCalculator () { return this[LENGTH_CALCULATOR] } | ||
function isNullOrUndefined(arg) { | ||
return arg == null; | ||
} | ||
get length () { return this[LENGTH] } | ||
get itemCount () { return this[LRU_LIST].length } | ||
function isNumber(arg) { | ||
return typeof arg === 'number'; | ||
} | ||
rforEach (fn, thisp) { | ||
thisp = thisp || this; | ||
for (let walker = this[LRU_LIST].tail; walker !== null;) { | ||
const prev = walker.prev; | ||
forEachStep(this, fn, walker, thisp); | ||
walker = prev; | ||
} | ||
} | ||
function isString(arg) { | ||
return typeof arg === 'string'; | ||
} | ||
forEach (fn, thisp) { | ||
thisp = thisp || this; | ||
for (let walker = this[LRU_LIST].head; walker !== null;) { | ||
const next = walker.next; | ||
forEachStep(this, fn, walker, thisp); | ||
walker = next; | ||
} | ||
} | ||
function isSymbol(arg) { | ||
return typeof arg === 'symbol'; | ||
} | ||
keys () { | ||
return this[LRU_LIST].toArray().map(k => k.key) | ||
} | ||
function isUndefined(arg) { | ||
return arg === void 0; | ||
} | ||
values () { | ||
return this[LRU_LIST].toArray().map(k => k.value) | ||
} | ||
function isRegExp(re) { | ||
return isObject(re) && objectToString(re) === '[object RegExp]'; | ||
} | ||
reset () { | ||
if (this[DISPOSE] && | ||
this[LRU_LIST] && | ||
this[LRU_LIST].length) { | ||
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value)); | ||
} | ||
function isObject(arg) { | ||
return typeof arg === 'object' && arg !== null; | ||
} | ||
this[CACHE] = new Map(); // hash of items by key | ||
this[LRU_LIST] = new yallist(); // list of items in order of use recency | ||
this[LENGTH] = 0; // length of items in the list | ||
} | ||
function isDate(d) { | ||
return isObject(d) && objectToString(d) === '[object Date]'; | ||
} | ||
dump () { | ||
return this[LRU_LIST].map(hit => | ||
isStale(this, hit) ? false : { | ||
k: hit.key, | ||
v: hit.value, | ||
e: hit.now + (hit.maxAge || 0) | ||
}).toArray().filter(h => h) | ||
} | ||
function isError(e) { | ||
return isObject(e) && | ||
(objectToString(e) === '[object Error]' || e instanceof Error); | ||
} | ||
dumpLru () { | ||
return this[LRU_LIST] | ||
} | ||
function isFunction(arg) { | ||
return typeof arg === 'function'; | ||
} | ||
set (key, value, maxAge) { | ||
maxAge = maxAge || this[MAX_AGE]; | ||
function isPrimitive(arg) { | ||
return arg === null || | ||
typeof arg === 'boolean' || | ||
typeof arg === 'number' || | ||
typeof arg === 'string' || | ||
typeof arg === 'symbol' || // ES6 symbol | ||
typeof arg === 'undefined'; | ||
} | ||
if (maxAge && typeof maxAge !== 'number') | ||
throw new TypeError('maxAge must be a number') | ||
function isBuffer(maybeBuf) { | ||
return Buffer.isBuffer(maybeBuf); | ||
} | ||
const now = maxAge ? Date.now() : 0; | ||
const len = this[LENGTH_CALCULATOR](value, key); | ||
function objectToString(o) { | ||
return Object.prototype.toString.call(o); | ||
} | ||
if (this[CACHE].has(key)) { | ||
if (len > this[MAX]) { | ||
del(this, this[CACHE].get(key)); | ||
return false | ||
} | ||
const node = this[CACHE].get(key); | ||
const item = node.value; | ||
function pad(n) { | ||
return n < 10 ? '0' + n.toString(10) : n.toString(10); | ||
} | ||
// dispose of the old one before overwriting | ||
// split out into 2 ifs for better coverage tracking | ||
if (this[DISPOSE]) { | ||
if (!this[NO_DISPOSE_ON_SET]) | ||
this[DISPOSE](key, item.value); | ||
} | ||
item.now = now; | ||
item.maxAge = maxAge; | ||
item.value = value; | ||
this[LENGTH] += len - item.length; | ||
item.length = len; | ||
this.get(key); | ||
trim(this); | ||
return true | ||
} | ||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', | ||
'Oct', 'Nov', 'Dec']; | ||
const hit = new Entry(key, value, len, now, maxAge); | ||
// 26 Feb 16:19:34 | ||
function timestamp() { | ||
var d = new Date(); | ||
var time = [pad(d.getHours()), | ||
pad(d.getMinutes()), | ||
pad(d.getSeconds())].join(':'); | ||
return [d.getDate(), months[d.getMonth()], time].join(' '); | ||
} | ||
// oversized objects fall out of cache automatically. | ||
if (hit.length > this[MAX]) { | ||
if (this[DISPOSE]) | ||
this[DISPOSE](key, value); | ||
return false | ||
} | ||
// log is just a thin wrapper to console.log that prepends a timestamp | ||
function log() { | ||
console.log('%s - %s', timestamp(), format.apply(null, arguments)); | ||
} | ||
this[LENGTH] += hit.length; | ||
this[LRU_LIST].unshift(hit); | ||
this[CACHE].set(key, this[LRU_LIST].head); | ||
trim(this); | ||
return true | ||
} | ||
function _extend(origin, add) { | ||
// Don't do anything if add isn't an object | ||
if (!add || !isObject(add)) return origin; | ||
has (key) { | ||
if (!this[CACHE].has(key)) return false | ||
const hit = this[CACHE].get(key).value; | ||
return !isStale(this, hit) | ||
} | ||
var keys = Object.keys(add); | ||
var i = keys.length; | ||
while (i--) { | ||
origin[keys[i]] = add[keys[i]]; | ||
} | ||
return origin; | ||
} | ||
function hasOwnProperty$1(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
get (key) { | ||
return get(this, key, true) | ||
} | ||
var util = { | ||
inherits: inherits$1, | ||
_extend: _extend, | ||
log: log, | ||
isBuffer: isBuffer, | ||
isPrimitive: isPrimitive, | ||
isFunction: isFunction, | ||
isError: isError, | ||
isDate: isDate, | ||
isObject: isObject, | ||
isRegExp: isRegExp, | ||
isUndefined: isUndefined, | ||
isSymbol: isSymbol, | ||
isString: isString, | ||
isNumber: isNumber, | ||
isNullOrUndefined: isNullOrUndefined, | ||
isNull: isNull, | ||
isBoolean: isBoolean, | ||
isArray: isArray, | ||
inspect: inspect, | ||
deprecate: deprecate, | ||
format: format, | ||
debuglog: debuglog | ||
}; | ||
peek (key) { | ||
return get(this, key, false) | ||
} | ||
var yallist = Yallist; | ||
pop () { | ||
const node = this[LRU_LIST].tail; | ||
if (!node) | ||
return null | ||
Yallist.Node = Node; | ||
Yallist.create = Yallist; | ||
del(this, node); | ||
return node.value | ||
} | ||
function Yallist (list) { | ||
var self = this; | ||
if (!(self instanceof Yallist)) { | ||
self = new Yallist(); | ||
} | ||
del (key) { | ||
del(this, this[CACHE].get(key)); | ||
} | ||
self.tail = null; | ||
self.head = null; | ||
self.length = 0; | ||
load (arr) { | ||
// reset the cache | ||
this.reset(); | ||
if (list && typeof list.forEach === 'function') { | ||
list.forEach(function (item) { | ||
self.push(item); | ||
}); | ||
} else if (arguments.length > 0) { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
self.push(arguments[i]); | ||
} | ||
} | ||
const now = Date.now(); | ||
// A previous serialized cache has the most recent items first | ||
for (let l = arr.length - 1; l >= 0; l--) { | ||
const hit = arr[l]; | ||
const expiresAt = hit.e || 0; | ||
if (expiresAt === 0) | ||
// the item was created without expiration in a non aged cache | ||
this.set(hit.k, hit.v); | ||
else { | ||
const maxAge = expiresAt - now; | ||
// dont add already expired items | ||
if (maxAge > 0) { | ||
this.set(hit.k, hit.v, maxAge); | ||
} | ||
} | ||
} | ||
} | ||
return self | ||
} | ||
prune () { | ||
this[CACHE].forEach((value, key) => get(this, key, false)); | ||
} | ||
} | ||
Yallist.prototype.removeNode = function (node) { | ||
if (node.list !== this) { | ||
throw new Error('removing node which does not belong to this list') | ||
} | ||
const get = (self, key, doUse) => { | ||
const node = self[CACHE].get(key); | ||
if (node) { | ||
const hit = node.value; | ||
if (isStale(self, hit)) { | ||
del(self, node); | ||
if (!self[ALLOW_STALE]) | ||
return undefined | ||
} else { | ||
if (doUse) { | ||
if (self[UPDATE_AGE_ON_GET]) | ||
node.value.now = Date.now(); | ||
self[LRU_LIST].unshiftNode(node); | ||
} | ||
} | ||
return hit.value | ||
} | ||
}; | ||
var next = node.next; | ||
var prev = node.prev; | ||
const isStale = (self, hit) => { | ||
if (!hit || (!hit.maxAge && !self[MAX_AGE])) | ||
return false | ||
if (next) { | ||
next.prev = prev; | ||
} | ||
const diff = Date.now() - hit.now; | ||
return hit.maxAge ? diff > hit.maxAge | ||
: self[MAX_AGE] && (diff > self[MAX_AGE]) | ||
}; | ||
if (prev) { | ||
prev.next = next; | ||
} | ||
const trim = self => { | ||
if (self[LENGTH] > self[MAX]) { | ||
for (let walker = self[LRU_LIST].tail; | ||
self[LENGTH] > self[MAX] && walker !== null;) { | ||
// We know that we're about to delete this one, and also | ||
// what the next least recently used key will be, so just | ||
// go ahead and set it now. | ||
const prev = walker.prev; | ||
del(self, walker); | ||
walker = prev; | ||
} | ||
} | ||
}; | ||
if (node === this.head) { | ||
this.head = next; | ||
} | ||
if (node === this.tail) { | ||
this.tail = prev; | ||
} | ||
const del = (self, node) => { | ||
if (node) { | ||
const hit = node.value; | ||
if (self[DISPOSE]) | ||
self[DISPOSE](hit.key, hit.value); | ||
node.list.length--; | ||
node.next = null; | ||
node.prev = null; | ||
node.list = null; | ||
}; | ||
self[LENGTH] -= hit.length; | ||
self[CACHE].delete(hit.key); | ||
self[LRU_LIST].removeNode(node); | ||
} | ||
}; | ||
Yallist.prototype.unshiftNode = function (node) { | ||
if (node === this.head) { | ||
return | ||
} | ||
class Entry { | ||
constructor (key, value, length, now, maxAge) { | ||
this.key = key; | ||
this.value = value; | ||
this.length = length; | ||
this.now = now; | ||
this.maxAge = maxAge || 0; | ||
} | ||
} | ||
if (node.list) { | ||
node.list.removeNode(node); | ||
} | ||
const forEachStep = (self, fn, node, thisp) => { | ||
let hit = node.value; | ||
if (isStale(self, hit)) { | ||
del(self, node); | ||
if (!self[ALLOW_STALE]) | ||
hit = undefined; | ||
} | ||
if (hit) | ||
fn.call(thisp, hit.value, hit.key, self); | ||
}; | ||
var head = this.head; | ||
node.list = this; | ||
node.next = head; | ||
if (head) { | ||
head.prev = node; | ||
} | ||
var lruCache = LRUCache; | ||
this.head = node; | ||
if (!this.tail) { | ||
this.tail = node; | ||
} | ||
this.length++; | ||
}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Yallist.prototype.pushNode = function (node) { | ||
if (node === this.tail) { | ||
return | ||
} | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
if (node.list) { | ||
node.list.removeNode(node); | ||
} | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var tail = this.tail; | ||
node.list = this; | ||
node.prev = tail; | ||
if (tail) { | ||
tail.next = node; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
this.tail = node; | ||
if (!this.head) { | ||
this.head = node; | ||
} | ||
this.length++; | ||
}; | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) 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; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
Yallist.prototype.push = function () { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
push(this, arguments[i]); | ||
} | ||
return this.length | ||
}; | ||
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); | ||
}; | ||
}; | ||
Yallist.prototype.unshift = function () { | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
unshift(this, arguments[i]); | ||
} | ||
return this.length | ||
}; | ||
/*! | ||
* Determine if an object is a Buffer | ||
* | ||
* @author Feross Aboukhadijeh <https://feross.org> | ||
* @license MIT | ||
*/ | ||
Yallist.prototype.pop = function () { | ||
if (!this.tail) { | ||
return undefined | ||
} | ||
var isBuffer = function isBuffer (obj) { | ||
return obj != null && obj.constructor != null && | ||
typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) | ||
}; | ||
var res = this.tail.value; | ||
this.tail = this.tail.prev; | ||
if (this.tail) { | ||
this.tail.next = null; | ||
} else { | ||
this.head = null; | ||
} | ||
this.length--; | ||
return res | ||
}; | ||
/*global toString:true*/ | ||
Yallist.prototype.shift = function () { | ||
if (!this.head) { | ||
return undefined | ||
} | ||
// utils is a library of generic helper functions non-specific to axios | ||
var res = this.head.value; | ||
this.head = this.head.next; | ||
if (this.head) { | ||
this.head.prev = null; | ||
} else { | ||
this.tail = null; | ||
} | ||
this.length--; | ||
return res | ||
}; | ||
var toString = Object.prototype.toString; | ||
Yallist.prototype.forEach = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this.head, i = 0; walker !== null; i++) { | ||
fn.call(thisp, walker.value, i, this); | ||
walker = walker.next; | ||
} | ||
}; | ||
/** | ||
* 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]'; | ||
} | ||
Yallist.prototype.forEachReverse = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) { | ||
fn.call(thisp, walker.value, i, this); | ||
walker = walker.prev; | ||
} | ||
}; | ||
/** | ||
* 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]'; | ||
} | ||
Yallist.prototype.get = function (n) { | ||
for (var i = 0, walker = this.head; walker !== null && i < n; i++) { | ||
// abort out of the list early if we hit a cycle | ||
walker = walker.next; | ||
} | ||
if (i === n && walker !== null) { | ||
return walker.value | ||
} | ||
}; | ||
/** | ||
* 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); | ||
} | ||
Yallist.prototype.getReverse = function (n) { | ||
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) { | ||
// abort out of the list early if we hit a cycle | ||
walker = walker.prev; | ||
} | ||
if (i === n && walker !== null) { | ||
return walker.value | ||
} | ||
}; | ||
/** | ||
* 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; | ||
} | ||
Yallist.prototype.map = function (fn, thisp) { | ||
thisp = thisp || this; | ||
var res = new Yallist(); | ||
for (var walker = this.head; walker !== null;) { | ||
res.push(fn.call(thisp, walker.value, this)); | ||
walker = walker.next; | ||
} | ||
return res | ||
}; | ||
/** | ||
* 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'; | ||
} | ||
Yallist.prototype.mapReverse = function (fn, thisp) { | ||
thisp = thisp || this; | ||
var res = new Yallist(); | ||
for (var walker = this.tail; walker !== null;) { | ||
res.push(fn.call(thisp, walker.value, this)); | ||
walker = walker.prev; | ||
} | ||
return res | ||
}; | ||
/** | ||
* 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'; | ||
} | ||
Yallist.prototype.reduce = function (fn, initial) { | ||
var acc; | ||
var walker = this.head; | ||
if (arguments.length > 1) { | ||
acc = initial; | ||
} else if (this.head) { | ||
walker = this.head.next; | ||
acc = this.head.value; | ||
} else { | ||
throw new TypeError('Reduce of empty list with no initial value') | ||
} | ||
/** | ||
* 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'; | ||
} | ||
for (var i = 0; walker !== null; i++) { | ||
acc = fn(acc, walker.value, i); | ||
walker = walker.next; | ||
} | ||
/** | ||
* 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'; | ||
} | ||
return acc | ||
}; | ||
/** | ||
* 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]'; | ||
} | ||
Yallist.prototype.reduceReverse = function (fn, initial) { | ||
var acc; | ||
var walker = this.tail; | ||
if (arguments.length > 1) { | ||
acc = initial; | ||
} else if (this.tail) { | ||
walker = this.tail.prev; | ||
acc = this.tail.value; | ||
} else { | ||
throw new TypeError('Reduce of empty list with no initial value') | ||
} | ||
/** | ||
* 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]'; | ||
} | ||
for (var i = this.length - 1; walker !== null; i--) { | ||
acc = fn(acc, walker.value, i); | ||
walker = walker.prev; | ||
} | ||
/** | ||
* 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]'; | ||
} | ||
return acc | ||
}; | ||
/** | ||
* 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]'; | ||
} | ||
Yallist.prototype.toArray = function () { | ||
var arr = new Array(this.length); | ||
for (var i = 0, walker = this.head; walker !== null; i++) { | ||
arr[i] = walker.value; | ||
walker = walker.next; | ||
} | ||
return arr | ||
}; | ||
/** | ||
* 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); | ||
} | ||
Yallist.prototype.toArrayReverse = function () { | ||
var arr = new Array(this.length); | ||
for (var i = 0, walker = this.tail; walker !== null; i++) { | ||
arr[i] = walker.value; | ||
walker = walker.prev; | ||
} | ||
return arr | ||
}; | ||
/** | ||
* 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; | ||
} | ||
Yallist.prototype.slice = function (from, to) { | ||
to = to || this.length; | ||
if (to < 0) { | ||
to += this.length; | ||
} | ||
from = from || 0; | ||
if (from < 0) { | ||
from += this.length; | ||
} | ||
var ret = new Yallist(); | ||
if (to < from || to < 0) { | ||
return ret | ||
} | ||
if (from < 0) { | ||
from = 0; | ||
} | ||
if (to > this.length) { | ||
to = this.length; | ||
} | ||
for (var i = 0, walker = this.head; walker !== null && i < from; i++) { | ||
walker = walker.next; | ||
} | ||
for (; walker !== null && i < to; i++, walker = walker.next) { | ||
ret.push(walker.value); | ||
} | ||
return ret | ||
}; | ||
/** | ||
* 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$1(str) { | ||
return str.replace(/^\s*/, '').replace(/\s*$/, ''); | ||
} | ||
Yallist.prototype.sliceReverse = function (from, to) { | ||
to = to || this.length; | ||
if (to < 0) { | ||
to += this.length; | ||
} | ||
from = from || 0; | ||
if (from < 0) { | ||
from += this.length; | ||
} | ||
var ret = new Yallist(); | ||
if (to < from || to < 0) { | ||
return ret | ||
} | ||
if (from < 0) { | ||
from = 0; | ||
} | ||
if (to > this.length) { | ||
to = this.length; | ||
} | ||
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) { | ||
walker = walker.prev; | ||
} | ||
for (; walker !== null && i > from; i--, walker = walker.prev) { | ||
ret.push(walker.value); | ||
} | ||
return ret | ||
}; | ||
/** | ||
* 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' | ||
*/ | ||
function isStandardBrowserEnv() { | ||
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { | ||
return false; | ||
} | ||
return ( | ||
typeof window !== 'undefined' && | ||
typeof document !== 'undefined' | ||
); | ||
} | ||
Yallist.prototype.reverse = function () { | ||
var head = this.head; | ||
var tail = this.tail; | ||
for (var walker = head; walker !== null; walker = walker.prev) { | ||
var p = walker.prev; | ||
walker.prev = walker.next; | ||
walker.next = p; | ||
} | ||
this.head = tail; | ||
this.tail = head; | ||
return this | ||
}; | ||
/** | ||
* 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; | ||
} | ||
function push (self, item) { | ||
self.tail = new Node(item, self.tail, null, self); | ||
if (!self.head) { | ||
self.head = self.tail; | ||
} | ||
self.length++; | ||
} | ||
// Force an array if not already something iterable | ||
if (typeof obj !== 'object') { | ||
/*eslint no-param-reassign:0*/ | ||
obj = [obj]; | ||
} | ||
function unshift (self, item) { | ||
self.head = new Node(item, null, self.head, self); | ||
if (!self.tail) { | ||
self.tail = self.head; | ||
} | ||
self.length++; | ||
} | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
function Node (value, prev, next, list) { | ||
if (!(this instanceof Node)) { | ||
return new Node(value, prev, next, list) | ||
} | ||
/** | ||
* 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 (typeof result[key] === 'object' && typeof val === 'object') { | ||
result[key] = merge(result[key], val); | ||
} else { | ||
result[key] = val; | ||
} | ||
} | ||
this.list = list; | ||
this.value = value; | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
forEach(arguments[i], assignValue); | ||
} | ||
return result; | ||
} | ||
if (prev) { | ||
prev.next = this; | ||
this.prev = prev; | ||
} else { | ||
this.prev = null; | ||
} | ||
/** | ||
* 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; | ||
} | ||
if (next) { | ||
next.prev = this; | ||
this.next = next; | ||
} else { | ||
this.next = null; | ||
} | ||
} | ||
var utils = { | ||
isArray: isArray, | ||
isArrayBuffer: isArrayBuffer, | ||
isBuffer: isBuffer, | ||
isFormData: isFormData, | ||
isArrayBufferView: isArrayBufferView, | ||
isString: isString, | ||
isNumber: isNumber, | ||
isObject: isObject, | ||
isUndefined: isUndefined, | ||
isDate: isDate, | ||
isFile: isFile, | ||
isBlob: isBlob, | ||
isFunction: isFunction, | ||
isStream: isStream, | ||
isURLSearchParams: isURLSearchParams, | ||
isStandardBrowserEnv: isStandardBrowserEnv, | ||
forEach: forEach, | ||
merge: merge, | ||
extend: extend, | ||
trim: trim$1 | ||
}; | ||
var lruCache = LRUCache; | ||
function encode(val) { | ||
return encodeURIComponent(val). | ||
replace(/%40/gi, '@'). | ||
replace(/%3A/gi, ':'). | ||
replace(/%24/g, '$'). | ||
replace(/%2C/gi, ','). | ||
replace(/%20/g, '+'). | ||
replace(/%5B/gi, '['). | ||
replace(/%5D/gi, ']'); | ||
} | ||
// This will be a proper iterable 'Map' in engines that support it, | ||
// or a fakey-fake PseudoMap in older versions. | ||
/** | ||
* 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; | ||
} | ||
// A linked list to keep track of recently-used-ness | ||
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)); | ||
}); | ||
}); | ||
// use symbols if possible, otherwise just _props | ||
var hasSymbol = typeof Symbol === 'function' && process.env._nodeLRUCacheForceNoSymbol !== '1'; | ||
var makeSymbol; | ||
if (hasSymbol) { | ||
makeSymbol = function (key) { | ||
return Symbol(key) | ||
}; | ||
} else { | ||
makeSymbol = function (key) { | ||
return '_' + key | ||
}; | ||
} | ||
serializedParams = parts.join('&'); | ||
} | ||
var MAX = makeSymbol('max'); | ||
var LENGTH = makeSymbol('length'); | ||
var LENGTH_CALCULATOR = makeSymbol('lengthCalculator'); | ||
var ALLOW_STALE = makeSymbol('allowStale'); | ||
var MAX_AGE = makeSymbol('maxAge'); | ||
var DISPOSE = makeSymbol('dispose'); | ||
var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet'); | ||
var LRU_LIST = makeSymbol('lruList'); | ||
var CACHE = makeSymbol('cache'); | ||
if (serializedParams) { | ||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; | ||
} | ||
function naiveLength () { return 1 } | ||
return url; | ||
}; | ||
// lruList is a yallist where the head is the youngest | ||
// item, and the tail is the oldest. the list contains the Hit | ||
// objects as the entries. | ||
// Each Hit object has a reference to its Yallist.Node. This | ||
// never changes. | ||
// | ||
// cache is a Map (or PseudoMap) that matches the keys to | ||
// the Yallist.Node object. | ||
function LRUCache (options) { | ||
if (!(this instanceof LRUCache)) { | ||
return new LRUCache(options) | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-12 | ||
*/ | ||
function buildSortedURL() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var builtURL = buildURL.apply(void 0, args); | ||
var _a = builtURL.split('?'), urlPath = _a[0], queryString = _a[1]; | ||
if (queryString) { | ||
var paramsPair = queryString.split('&'); | ||
return urlPath + "?" + paramsPair.sort().join('&'); | ||
} | ||
return builtURL; | ||
} | ||
if (typeof options === 'number') { | ||
options = { max: options }; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2018-03-19 | ||
*/ | ||
function isCacheLike(cache) { | ||
return !!(cache.set && cache.get && cache.del && | ||
typeof cache.get === 'function' && typeof cache.set === 'function' && typeof cache.del === 'function'); | ||
} | ||
if (!options) { | ||
options = {}; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-12 | ||
*/ | ||
var FIVE_MINUTES = 1000 * 60 * 5; | ||
var CAPACITY = 100; | ||
function cacheAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.enabledByDefault, enabledByDefault = _a === void 0 ? true : _a, _b = options.cacheFlag, cacheFlag = _b === void 0 ? 'cache' : _b, _c = options.defaultCache, defaultCache = _c === void 0 ? new lruCache({ maxAge: FIVE_MINUTES, max: CAPACITY }) : _c; | ||
return function (config) { | ||
var url = config.url, method = config.method, params = config.params, paramsSerializer = config.paramsSerializer, forceUpdate = config.forceUpdate; | ||
var useCache = (config[cacheFlag] !== void 0 && config[cacheFlag] !== null) | ||
? config[cacheFlag] | ||
: enabledByDefault; | ||
if (method === 'get' && useCache) { | ||
// if had provide a specified cache, then use it instead | ||
var cache_1 = isCacheLike(useCache) ? useCache : defaultCache; | ||
// build the index according to the url and params | ||
var index_1 = buildSortedURL(url, params, paramsSerializer); | ||
var responsePromise = cache_1.get(index_1); | ||
if (!responsePromise || forceUpdate) { | ||
responsePromise = (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var reason_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
reason_1 = _a.sent(); | ||
cache_1.del(index_1); | ||
throw reason_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
// put the promise for the non-transformed response into cache as a placeholder | ||
cache_1.set(index_1, responsePromise); | ||
return responsePromise; | ||
} | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
// eslint-disable-next-line no-console | ||
console.info("[axios-extensions] request cached by cache adapter --> url: " + index_1); | ||
} | ||
return responsePromise; | ||
} | ||
return adapter(config); | ||
}; | ||
} | ||
var max = this[MAX] = options.max; | ||
// Kind of weird to have a default max of Infinity, but oh well. | ||
if (!max || | ||
!(typeof max === 'number') || | ||
max <= 0) { | ||
this[MAX] = Infinity; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @since 2020-02-18 | ||
*/ | ||
function retryAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.times, times = _a === void 0 ? 2 : _a; | ||
return function (config) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, retryTimes, timeUp, count, request; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
_a = config.retryTimes, retryTimes = _a === void 0 ? times : _a; | ||
timeUp = false; | ||
count = 0; | ||
request = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
timeUp = retryTimes === count; | ||
if (timeUp) { | ||
throw e_1; | ||
} | ||
count++; | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
console.info("[axios-extensions] request start retrying --> url: " + config.url + " , time: " + count); | ||
} | ||
return [2 /*return*/, request()]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
return [2 /*return*/, request()]; | ||
}); | ||
}); }; | ||
} | ||
var lc = options.length || naiveLength; | ||
if (typeof lc !== 'function') { | ||
lc = naiveLength; | ||
} | ||
this[LENGTH_CALCULATOR] = lc; | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-11 | ||
*/ | ||
function throttleAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.threshold, threshold = _a === void 0 ? 1000 : _a, _b = options.cache, cache = _b === void 0 ? new lruCache({ max: 10 }) : _b; | ||
var recordCacheWithRequest = function (index, config) { | ||
var responsePromise = (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response, reason_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: | ||
response = _a.sent(); | ||
cache.set(index, { | ||
timestamp: Date.now(), | ||
value: Promise.resolve(response), | ||
}); | ||
return [2 /*return*/, response]; | ||
case 2: | ||
reason_1 = _a.sent(); | ||
cache.del(index); | ||
throw reason_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
cache.set(index, { | ||
timestamp: Date.now(), | ||
value: responsePromise, | ||
}); | ||
return responsePromise; | ||
}; | ||
return function (config) { | ||
var url = config.url, method = config.method, params = config.params, paramsSerializer = config.paramsSerializer; | ||
var index = buildSortedURL(url, params, paramsSerializer); | ||
var now = Date.now(); | ||
var cachedRecord = cache.get(index) || { timestamp: now }; | ||
if (method === 'get') { | ||
if (now - cachedRecord.timestamp <= threshold) { | ||
var responsePromise = cachedRecord.value; | ||
if (responsePromise) { | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
// eslint-disable-next-line no-console | ||
console.info("[axios-extensions] request cached by throttle adapter --> url: " + index); | ||
} | ||
return responsePromise; | ||
} | ||
} | ||
return recordCacheWithRequest(index, config); | ||
} | ||
return adapter(config); | ||
}; | ||
} | ||
this[ALLOW_STALE] = options.stale || false; | ||
this[MAX_AGE] = options.maxAge || 0; | ||
this[DISPOSE] = options.dispose; | ||
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false; | ||
this.reset(); | ||
} | ||
exports.Cache = lruCache; | ||
exports.cacheAdapterEnhancer = cacheAdapterEnhancer; | ||
exports.retryAdapterEnhancer = retryAdapterEnhancer; | ||
exports.throttleAdapterEnhancer = throttleAdapterEnhancer; | ||
// resize the cache when the max changes. | ||
Object.defineProperty(LRUCache.prototype, 'max', { | ||
set: function (mL) { | ||
if (!mL || !(typeof mL === 'number') || mL <= 0) { | ||
mL = Infinity; | ||
} | ||
this[MAX] = mL; | ||
trim(this); | ||
}, | ||
get: function () { | ||
return this[MAX] | ||
}, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(LRUCache.prototype, 'allowStale', { | ||
set: function (allowStale) { | ||
this[ALLOW_STALE] = !!allowStale; | ||
}, | ||
get: function () { | ||
return this[ALLOW_STALE] | ||
}, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(LRUCache.prototype, 'maxAge', { | ||
set: function (mA) { | ||
if (!mA || !(typeof mA === 'number') || mA < 0) { | ||
mA = 0; | ||
} | ||
this[MAX_AGE] = mA; | ||
trim(this); | ||
}, | ||
get: function () { | ||
return this[MAX_AGE] | ||
}, | ||
enumerable: true | ||
}); | ||
// resize the cache when the lengthCalculator changes. | ||
Object.defineProperty(LRUCache.prototype, 'lengthCalculator', { | ||
set: function (lC) { | ||
if (typeof lC !== 'function') { | ||
lC = naiveLength; | ||
} | ||
if (lC !== this[LENGTH_CALCULATOR]) { | ||
this[LENGTH_CALCULATOR] = lC; | ||
this[LENGTH] = 0; | ||
this[LRU_LIST].forEach(function (hit) { | ||
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key); | ||
this[LENGTH] += hit.length; | ||
}, this); | ||
} | ||
trim(this); | ||
}, | ||
get: function () { return this[LENGTH_CALCULATOR] }, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(LRUCache.prototype, 'length', { | ||
get: function () { return this[LENGTH] }, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(LRUCache.prototype, 'itemCount', { | ||
get: function () { return this[LRU_LIST].length }, | ||
enumerable: true | ||
}); | ||
LRUCache.prototype.rforEach = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this[LRU_LIST].tail; walker !== null;) { | ||
var prev = walker.prev; | ||
forEachStep(this, fn, walker, thisp); | ||
walker = prev; | ||
} | ||
}; | ||
function forEachStep (self, fn, node, thisp) { | ||
var hit = node.value; | ||
if (isStale(self, hit)) { | ||
del(self, node); | ||
if (!self[ALLOW_STALE]) { | ||
hit = undefined; | ||
} | ||
} | ||
if (hit) { | ||
fn.call(thisp, hit.value, hit.key, self); | ||
} | ||
} | ||
LRUCache.prototype.forEach = function (fn, thisp) { | ||
thisp = thisp || this; | ||
for (var walker = this[LRU_LIST].head; walker !== null;) { | ||
var next = walker.next; | ||
forEachStep(this, fn, walker, thisp); | ||
walker = next; | ||
} | ||
}; | ||
LRUCache.prototype.keys = function () { | ||
return this[LRU_LIST].toArray().map(function (k) { | ||
return k.key | ||
}, this) | ||
}; | ||
LRUCache.prototype.values = function () { | ||
return this[LRU_LIST].toArray().map(function (k) { | ||
return k.value | ||
}, this) | ||
}; | ||
LRUCache.prototype.reset = function () { | ||
if (this[DISPOSE] && | ||
this[LRU_LIST] && | ||
this[LRU_LIST].length) { | ||
this[LRU_LIST].forEach(function (hit) { | ||
this[DISPOSE](hit.key, hit.value); | ||
}, this); | ||
} | ||
this[CACHE] = new map(); // hash of items by key | ||
this[LRU_LIST] = new yallist(); // list of items in order of use recency | ||
this[LENGTH] = 0; // length of items in the list | ||
}; | ||
LRUCache.prototype.dump = function () { | ||
return this[LRU_LIST].map(function (hit) { | ||
if (!isStale(this, hit)) { | ||
return { | ||
k: hit.key, | ||
v: hit.value, | ||
e: hit.now + (hit.maxAge || 0) | ||
} | ||
} | ||
}, this).toArray().filter(function (h) { | ||
return h | ||
}) | ||
}; | ||
LRUCache.prototype.dumpLru = function () { | ||
return this[LRU_LIST] | ||
}; | ||
/* istanbul ignore next */ | ||
LRUCache.prototype.inspect = function (n, opts) { | ||
var str = 'LRUCache {'; | ||
var extras = false; | ||
var as = this[ALLOW_STALE]; | ||
if (as) { | ||
str += '\n allowStale: true'; | ||
extras = true; | ||
} | ||
var max = this[MAX]; | ||
if (max && max !== Infinity) { | ||
if (extras) { | ||
str += ','; | ||
} | ||
str += '\n max: ' + util.inspect(max, opts); | ||
extras = true; | ||
} | ||
var maxAge = this[MAX_AGE]; | ||
if (maxAge) { | ||
if (extras) { | ||
str += ','; | ||
} | ||
str += '\n maxAge: ' + util.inspect(maxAge, opts); | ||
extras = true; | ||
} | ||
var lc = this[LENGTH_CALCULATOR]; | ||
if (lc && lc !== naiveLength) { | ||
if (extras) { | ||
str += ','; | ||
} | ||
str += '\n length: ' + util.inspect(this[LENGTH], opts); | ||
extras = true; | ||
} | ||
var didFirst = false; | ||
this[LRU_LIST].forEach(function (item) { | ||
if (didFirst) { | ||
str += ',\n '; | ||
} else { | ||
if (extras) { | ||
str += ',\n'; | ||
} | ||
didFirst = true; | ||
str += '\n '; | ||
} | ||
var key = util.inspect(item.key).split('\n').join('\n '); | ||
var val = { value: item.value }; | ||
if (item.maxAge !== maxAge) { | ||
val.maxAge = item.maxAge; | ||
} | ||
if (lc !== naiveLength) { | ||
val.length = item.length; | ||
} | ||
if (isStale(this, item)) { | ||
val.stale = true; | ||
} | ||
val = util.inspect(val, opts).split('\n').join('\n '); | ||
str += key + ' => ' + val; | ||
}); | ||
if (didFirst || extras) { | ||
str += '\n'; | ||
} | ||
str += '}'; | ||
return str | ||
}; | ||
LRUCache.prototype.set = function (key, value, maxAge) { | ||
maxAge = maxAge || this[MAX_AGE]; | ||
var now = maxAge ? Date.now() : 0; | ||
var len = this[LENGTH_CALCULATOR](value, key); | ||
if (this[CACHE].has(key)) { | ||
if (len > this[MAX]) { | ||
del(this, this[CACHE].get(key)); | ||
return false | ||
} | ||
var node = this[CACHE].get(key); | ||
var item = node.value; | ||
// dispose of the old one before overwriting | ||
// split out into 2 ifs for better coverage tracking | ||
if (this[DISPOSE]) { | ||
if (!this[NO_DISPOSE_ON_SET]) { | ||
this[DISPOSE](key, item.value); | ||
} | ||
} | ||
item.now = now; | ||
item.maxAge = maxAge; | ||
item.value = value; | ||
this[LENGTH] += len - item.length; | ||
item.length = len; | ||
this.get(key); | ||
trim(this); | ||
return true | ||
} | ||
var hit = new Entry$1(key, value, len, now, maxAge); | ||
// oversized objects fall out of cache automatically. | ||
if (hit.length > this[MAX]) { | ||
if (this[DISPOSE]) { | ||
this[DISPOSE](key, value); | ||
} | ||
return false | ||
} | ||
this[LENGTH] += hit.length; | ||
this[LRU_LIST].unshift(hit); | ||
this[CACHE].set(key, this[LRU_LIST].head); | ||
trim(this); | ||
return true | ||
}; | ||
LRUCache.prototype.has = function (key) { | ||
if (!this[CACHE].has(key)) return false | ||
var hit = this[CACHE].get(key).value; | ||
if (isStale(this, hit)) { | ||
return false | ||
} | ||
return true | ||
}; | ||
LRUCache.prototype.get = function (key) { | ||
return get(this, key, true) | ||
}; | ||
LRUCache.prototype.peek = function (key) { | ||
return get(this, key, false) | ||
}; | ||
LRUCache.prototype.pop = function () { | ||
var node = this[LRU_LIST].tail; | ||
if (!node) return null | ||
del(this, node); | ||
return node.value | ||
}; | ||
LRUCache.prototype.del = function (key) { | ||
del(this, this[CACHE].get(key)); | ||
}; | ||
LRUCache.prototype.load = function (arr) { | ||
// reset the cache | ||
this.reset(); | ||
var now = Date.now(); | ||
// A previous serialized cache has the most recent items first | ||
for (var l = arr.length - 1; l >= 0; l--) { | ||
var hit = arr[l]; | ||
var expiresAt = hit.e || 0; | ||
if (expiresAt === 0) { | ||
// the item was created without expiration in a non aged cache | ||
this.set(hit.k, hit.v); | ||
} else { | ||
var maxAge = expiresAt - now; | ||
// dont add already expired items | ||
if (maxAge > 0) { | ||
this.set(hit.k, hit.v, maxAge); | ||
} | ||
} | ||
} | ||
}; | ||
LRUCache.prototype.prune = function () { | ||
var self = this; | ||
this[CACHE].forEach(function (value, key) { | ||
get(self, key, false); | ||
}); | ||
}; | ||
function get (self, key, doUse) { | ||
var node = self[CACHE].get(key); | ||
if (node) { | ||
var hit = node.value; | ||
if (isStale(self, hit)) { | ||
del(self, node); | ||
if (!self[ALLOW_STALE]) hit = undefined; | ||
} else { | ||
if (doUse) { | ||
self[LRU_LIST].unshiftNode(node); | ||
} | ||
} | ||
if (hit) hit = hit.value; | ||
} | ||
return hit | ||
} | ||
function isStale (self, hit) { | ||
if (!hit || (!hit.maxAge && !self[MAX_AGE])) { | ||
return false | ||
} | ||
var stale = false; | ||
var diff = Date.now() - hit.now; | ||
if (hit.maxAge) { | ||
stale = diff > hit.maxAge; | ||
} else { | ||
stale = self[MAX_AGE] && (diff > self[MAX_AGE]); | ||
} | ||
return stale | ||
} | ||
function trim (self) { | ||
if (self[LENGTH] > self[MAX]) { | ||
for (var walker = self[LRU_LIST].tail; | ||
self[LENGTH] > self[MAX] && walker !== null;) { | ||
// We know that we're about to delete this one, and also | ||
// what the next least recently used key will be, so just | ||
// go ahead and set it now. | ||
var prev = walker.prev; | ||
del(self, walker); | ||
walker = prev; | ||
} | ||
} | ||
} | ||
function del (self, node) { | ||
if (node) { | ||
var hit = node.value; | ||
if (self[DISPOSE]) { | ||
self[DISPOSE](hit.key, hit.value); | ||
} | ||
self[LENGTH] -= hit.length; | ||
self[CACHE].delete(hit.key); | ||
self[LRU_LIST].removeNode(node); | ||
} | ||
} | ||
// classy, since V8 prefers predictable objects. | ||
function Entry$1 (key, value, length, now, maxAge) { | ||
this.key = key; | ||
this.value = value; | ||
this.length = length; | ||
this.now = now; | ||
this.maxAge = maxAge || 0; | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) 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; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
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); | ||
}; | ||
}; | ||
/*! | ||
* Determine if an object is a Buffer | ||
* | ||
* @author Feross Aboukhadijeh <https://feross.org> | ||
* @license MIT | ||
*/ | ||
var isBuffer$1 = function isBuffer (obj) { | ||
return obj != null && obj.constructor != null && | ||
typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) | ||
}; | ||
/*global toString:true*/ | ||
// 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$1(val) { | ||
return toString.call(val) === '[object Array]'; | ||
} | ||
/** | ||
* 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$1(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$1(val) { | ||
return typeof val === 'number'; | ||
} | ||
/** | ||
* 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$1(val) { | ||
return typeof val === 'undefined'; | ||
} | ||
/** | ||
* 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$1(val) { | ||
return val !== null && typeof val === 'object'; | ||
} | ||
/** | ||
* 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$1(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$1(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$1(val) && isFunction$1(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$1(str) { | ||
return str.replace(/^\s*/, '').replace(/\s*$/, ''); | ||
} | ||
/** | ||
* 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' | ||
*/ | ||
function isStandardBrowserEnv() { | ||
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { | ||
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$1(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 (typeof result[key] === 'object' && typeof val === 'object') { | ||
result[key] = merge(result[key], val); | ||
} 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; | ||
} | ||
var utils = { | ||
isArray: isArray$1, | ||
isArrayBuffer: isArrayBuffer, | ||
isBuffer: isBuffer$1, | ||
isFormData: isFormData, | ||
isArrayBufferView: isArrayBufferView, | ||
isString: isString$1, | ||
isNumber: isNumber$1, | ||
isObject: isObject$1, | ||
isUndefined: isUndefined$1, | ||
isDate: isDate$1, | ||
isFile: isFile, | ||
isBlob: isBlob, | ||
isFunction: isFunction$1, | ||
isStream: isStream, | ||
isURLSearchParams: isURLSearchParams, | ||
isStandardBrowserEnv: isStandardBrowserEnv, | ||
forEach: forEach, | ||
merge: merge, | ||
extend: extend, | ||
trim: trim$1 | ||
}; | ||
function encode(val) { | ||
return encodeURIComponent(val). | ||
replace(/%40/gi, '@'). | ||
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) { | ||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; | ||
} | ||
return url; | ||
}; | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-12 | ||
*/ | ||
function buildSortedURL() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var builtURL = buildURL.apply(void 0, args); | ||
var _a = builtURL.split('?'), urlPath = _a[0], queryString = _a[1]; | ||
if (queryString) { | ||
var paramsPair = queryString.split('&'); | ||
return urlPath + "?" + paramsPair.sort().join('&'); | ||
} | ||
return builtURL; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2018-03-19 | ||
*/ | ||
function isCacheLike(cache) { | ||
return !!(cache.set && cache.get && cache.del && | ||
typeof cache.get === 'function' && typeof cache.set === 'function' && typeof cache.del === 'function'); | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-12 | ||
*/ | ||
var FIVE_MINUTES = 1000 * 60 * 5; | ||
var CAPACITY = 100; | ||
function cacheAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.enabledByDefault, enabledByDefault = _a === void 0 ? true : _a, _b = options.cacheFlag, cacheFlag = _b === void 0 ? 'cache' : _b, _c = options.defaultCache, defaultCache = _c === void 0 ? new lruCache({ maxAge: FIVE_MINUTES, max: CAPACITY }) : _c; | ||
return function (config) { | ||
var url = config.url, method = config.method, params = config.params, paramsSerializer = config.paramsSerializer, forceUpdate = config.forceUpdate; | ||
var useCache = (config[cacheFlag] !== void 0 && config[cacheFlag] !== null) | ||
? config[cacheFlag] | ||
: enabledByDefault; | ||
if (method === 'get' && useCache) { | ||
// if had provide a specified cache, then use it instead | ||
var cache_1 = isCacheLike(useCache) ? useCache : defaultCache; | ||
// build the index according to the url and params | ||
var index_1 = buildSortedURL(url, params, paramsSerializer); | ||
var responsePromise = cache_1.get(index_1); | ||
if (!responsePromise || forceUpdate) { | ||
responsePromise = (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var reason_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
reason_1 = _a.sent(); | ||
cache_1.del(index_1); | ||
throw reason_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
// put the promise for the non-transformed response into cache as a placeholder | ||
cache_1.set(index_1, responsePromise); | ||
return responsePromise; | ||
} | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
// eslint-disable-next-line no-console | ||
console.info("[axios-extensions] request cached by cache adapter --> url: " + index_1); | ||
} | ||
return responsePromise; | ||
} | ||
return adapter(config); | ||
}; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @since 2020-02-18 | ||
*/ | ||
function retryAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.times, times = _a === void 0 ? 2 : _a; | ||
return function (config) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, retryTimes, timeUp, count, request; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
_a = config.retryTimes, retryTimes = _a === void 0 ? times : _a; | ||
timeUp = false; | ||
count = 0; | ||
request = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
timeUp = retryTimes === count; | ||
if (timeUp) { | ||
throw e_1; | ||
} | ||
count++; | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
console.info("[axios-extensions] request start retrying --> url: " + config.url + " , time: " + count); | ||
} | ||
return [2 /*return*/, request()]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
return [2 /*return*/, request()]; | ||
}); | ||
}); }; | ||
} | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2017-10-11 | ||
*/ | ||
function throttleAdapterEnhancer(adapter, options) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.threshold, threshold = _a === void 0 ? 1000 : _a, _b = options.cache, cache = _b === void 0 ? new lruCache({ max: 10 }) : _b; | ||
var recordCacheWithRequest = function (index, config) { | ||
var responsePromise = (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response, reason_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, adapter(config)]; | ||
case 1: | ||
response = _a.sent(); | ||
cache.set(index, { | ||
timestamp: Date.now(), | ||
value: Promise.resolve(response), | ||
}); | ||
return [2 /*return*/, response]; | ||
case 2: | ||
reason_1 = _a.sent(); | ||
cache.del(index); | ||
throw reason_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
cache.set(index, { | ||
timestamp: Date.now(), | ||
value: responsePromise, | ||
}); | ||
return responsePromise; | ||
}; | ||
return function (config) { | ||
var url = config.url, method = config.method, params = config.params, paramsSerializer = config.paramsSerializer; | ||
var index = buildSortedURL(url, params, paramsSerializer); | ||
var now = Date.now(); | ||
var cachedRecord = cache.get(index) || { timestamp: now }; | ||
if (method === 'get') { | ||
if (now - cachedRecord.timestamp <= threshold) { | ||
var responsePromise = cachedRecord.value; | ||
if (responsePromise) { | ||
/* istanbul ignore next */ | ||
if (process.env.LOGGER_LEVEL === 'info') { | ||
// eslint-disable-next-line no-console | ||
console.info("[axios-extensions] request cached by throttle adapter --> url: " + index); | ||
} | ||
return responsePromise; | ||
} | ||
} | ||
return recordCacheWithRequest(index, config); | ||
} | ||
return adapter(config); | ||
}; | ||
} | ||
exports.Cache = lruCache; | ||
exports.cacheAdapterEnhancer = cacheAdapterEnhancer; | ||
exports.retryAdapterEnhancer = retryAdapterEnhancer; | ||
exports.throttleAdapterEnhancer = throttleAdapterEnhancer; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=axios-extensions.js.map |
@@ -1,2 +0,22 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self)["axios-extensions"]={})}(this,function(t){"use strict";var u=Object.prototype.hasOwnProperty,e=n;function n(t){if(!(this instanceof n))throw new TypeError("Constructor PseudoMap requires 'new'");if(this.clear(),t)if(t instanceof n||"function"==typeof Map&&t instanceof Map)t.forEach(function(t,e){this.set(e,t)},this);else{if(!Array.isArray(t))throw new TypeError("invalid argument");t.forEach(function(t){this.set(t[0],t[1])},this)}}function s(t,e){return t===e||t!=t&&e!=e}function a(t,e,n){this.key=t,this.value=e,this._index=n}function r(t,e){for(var n=0,r="_"+e,i=r;u.call(t,i);i=r+n++)if(s(t[i].key,e))return t[i]}n.prototype.forEach=function(e,n){n=n||this,Object.keys(this._data).forEach(function(t){"size"!==t&&e.call(n,this._data[t].value,this._data[t].key)},this)},n.prototype.has=function(t){return!!r(this._data,t)},n.prototype.get=function(t){var e=r(this._data,t);return e&&e.value},n.prototype.set=function(t,e){!function(t,e,n){for(var r=0,i="_"+e,o=i;u.call(t,o);o=i+r++)if(s(t[o].key,e))return t[o].value=n;t.size++,t[o]=new a(e,n,o)}(this._data,t,e)},n.prototype.delete=function(t){var e=r(this._data,t);e&&(delete this._data[e._index],this._data.size--)},n.prototype.clear=function(){var t=Object.create(null);t.size=0,Object.defineProperty(this,"_data",{value:t,enumerable:!1,configurable:!0,writable:!1})},Object.defineProperty(n.prototype,"size",{get:function(){return this._data.size},set:function(t){},enumerable:!0,configurable:!0}),n.prototype.values=n.prototype.keys=n.prototype.entries=function(){throw new Error("iterators are not implemented in this version")};var i,o=(function(t){"pseudomap"===process.env.npm_package_name&&"test"===process.env.npm_lifecycle_script&&(process.env.TEST_PSEUDOMAP="true"),"function"!=typeof Map||process.env.TEST_PSEUDOMAP?t.exports=e:t.exports=Map}(i={exports:{}}),i.exports),l="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;function n(){}n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t},c=/%[sdj%]/g;function f(t){if(!_(t)){for(var e=[],n=0;n<arguments.length;n++)e.push(d(arguments[n]));return e.join(" ")}n=1;for(var r=arguments,i=r.length,o=String(t).replace(c,function(t){if("%%"===t)return"%";if(i<=n)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),u=r[n];n<i;u=r[++n])O(u)||!P(u)?o+=" "+u:o+=" "+d(u);return o}function h(t,e){if(k(global.process))return function(){return h(t,e).apply(this,arguments)};var n=!1;return function(){return n||(console.error(e),n=!0),t.apply(this,arguments)}}var p,v={};function y(e){if(k(p)&&(p=""),e=e.toUpperCase(),!v[e])if(new RegExp("\\b"+e+"\\b","i").test(p)){v[e]=function(){var t=f.apply(null,arguments);console.error("%s %d: %s",e,0,t)}}else v[e]=function(){};return v[e]}function d(t,e){var n={seen:[],stylize:m};return 3<=arguments.length&&(n.depth=arguments[2]),4<=arguments.length&&(n.colors=arguments[3]),E(e)?n.showHidden=e:e&&G(n,e),k(n.showHidden)&&(n.showHidden=!1),k(n.depth)&&(n.depth=2),k(n.colors)&&(n.colors=!1),k(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=g),b(n,t,n.depth)}function g(t,e){var n=d.styles[e];return n?"["+d.colors[n][0]+"m"+t+"["+d.colors[n][1]+"m":t}function m(t,e){return t}function b(e,n,r){if(e.customInspect&&n&&B(n.inspect)&&n.inspect!==d&&(!n.constructor||n.constructor.prototype!==n)){var t=n.inspect(r,e);return _(t)||(t=b(e,t,r)),t}var i=function(t,e){if(k(e))return t.stylize("undefined","undefined");if(_(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(A(e))return t.stylize(""+e,"number");if(E(e))return t.stylize(""+e,"boolean");if(O(e))return t.stylize("null","null")}(e,n);if(i)return i;var o,u=Object.keys(n),s=(o={},u.forEach(function(t,e){o[t]=!0}),o);if(e.showHidden&&(u=Object.getOwnPropertyNames(n)),N(n)&&(0<=u.indexOf("message")||0<=u.indexOf("description")))return w(n);if(0===u.length){if(B(n)){var a=n.name?": "+n.name:"";return e.stylize("[Function"+a+"]","special")}if(D(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(R(n))return e.stylize(Date.prototype.toString.call(n),"date");if(N(n))return w(n)}var l,c="",f=!1,h=["{","}"];j(n)&&(f=!0,h=["[","]"]),B(n)&&(c=" [Function"+(n.name?": "+n.name:"")+"]");return D(n)&&(c=" "+RegExp.prototype.toString.call(n)),R(n)&&(c=" "+Date.prototype.toUTCString.call(n)),N(n)&&(c=" "+w(n)),0!==u.length||f&&0!=n.length?r<0?D(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special"):(e.seen.push(n),l=f?function(e,n,r,i,t){for(var o=[],u=0,s=n.length;u<s;++u)J(n,String(u))?o.push(x(e,n,r,i,String(u),!0)):o.push("");return t.forEach(function(t){t.match(/^\d+$/)||o.push(x(e,n,r,i,t,!0))}),o}(e,n,r,s,u):u.map(function(t){return x(e,n,r,s,t,f)}),e.seen.pop(),function(t,e,n){if(60<t.reduce(function(t,e){return e.indexOf("\n"),t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0))return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(l,c,h)):h[0]+c+h[1]}function w(t){return"["+Error.prototype.toString.call(t)+"]"}function x(t,e,n,r,i,o){var u,s,a;if((a=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?s=a.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):a.set&&(s=t.stylize("[Setter]","special")),J(r,i)||(u="["+i+"]"),s||(t.seen.indexOf(a.value)<0?-1<(s=O(n)?b(t,a.value,null):b(t,a.value,n-1)).indexOf("\n")&&(s=o?s.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+s.split("\n").map(function(t){return" "+t}).join("\n")):s=t.stylize("[Circular]","special")),k(u)){if(o&&i.match(/^\d+$/))return s;u=(u=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),t.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),t.stylize(u,"string"))}return u+": "+s}function j(t){return Array.isArray(t)}function E(t){return"boolean"==typeof t}function O(t){return null===t}function S(t){return null==t}function A(t){return"number"==typeof t}function _(t){return"string"==typeof t}function z(t){return"symbol"==typeof t}function k(t){return void 0===t}function D(t){return P(t)&&"[object RegExp]"===C(t)}function P(t){return"object"==typeof t&&null!==t}function R(t){return P(t)&&"[object Date]"===C(t)}function N(t){return P(t)&&("[object Error]"===C(t)||t instanceof Error)}function B(t){return"function"==typeof t}function L(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t}function U(t){return Buffer.isBuffer(t)}function C(t){return Object.prototype.toString.call(t)}function F(t){return t<10?"0"+t.toString(10):t.toString(10)}d.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};var M=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function T(){var t,e;console.log("%s - %s",(t=new Date,e=[F(t.getHours()),F(t.getMinutes()),F(t.getSeconds())].join(":"),[t.getDate(),M[t.getMonth()],e].join(" ")),f.apply(null,arguments))}function G(t,e){if(!e||!P(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}function J(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var $={inherits:l,_extend:G,log:T,isBuffer:U,isPrimitive:L,isFunction:B,isError:N,isDate:R,isObject:P,isRegExp:D,isUndefined:k,isSymbol:z,isString:_,isNumber:A,isNullOrUndefined:S,isNull:O,isBoolean:E,isArray:j,inspect:d,deprecate:h,format:f,debuglog:y},V=Object.freeze({__proto__:null,format:f,deprecate:h,debuglog:y,inspect:d,isArray:j,isBoolean:E,isNull:O,isNullOrUndefined:S,isNumber:A,isString:_,isSymbol:z,isUndefined:k,isRegExp:D,isObject:P,isDate:R,isError:N,isFunction:B,isPrimitive:L,isBuffer:U,log:T,inherits:l,_extend:G,default:$}),H=I;function I(t){var e=this;if(e instanceof I||(e=new I),e.tail=null,e.head=null,e.length=0,t&&"function"==typeof t.forEach)t.forEach(function(t){e.push(t)});else if(0<arguments.length)for(var n=0,r=arguments.length;n<r;n++)e.push(arguments[n]);return e}function q(t,e){t.tail=new K(e,t.tail,null,t),t.head||(t.head=t.tail),t.length++}function Z(t,e){t.head=new K(e,null,t.head,t),t.tail||(t.tail=t.head),t.length++}function K(t,e,n,r){if(!(this instanceof K))return new K(t,e,n,r);this.list=r,this.value=t,e?(e.next=this).prev=e:this.prev=null,n?(n.prev=this).next=n:this.next=null}I.Node=K,(I.create=I).prototype.removeNode=function(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");var e=t.next,n=t.prev;e&&(e.prev=n),n&&(n.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=n),t.list.length--,t.next=null,t.prev=null,t.list=null},I.prototype.unshiftNode=function(t){if(t!==this.head){t.list&&t.list.removeNode(t);var e=this.head;t.list=this,(t.next=e)&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}},I.prototype.pushNode=function(t){if(t!==this.tail){t.list&&t.list.removeNode(t);var e=this.tail;t.list=this,(t.prev=e)&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}},I.prototype.push=function(){for(var t=0,e=arguments.length;t<e;t++)q(this,arguments[t]);return this.length},I.prototype.unshift=function(){for(var t=0,e=arguments.length;t<e;t++)Z(this,arguments[t]);return this.length},I.prototype.pop=function(){if(this.tail){var t=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}},I.prototype.shift=function(){if(this.head){var t=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}},I.prototype.forEach=function(t,e){e=e||this;for(var n=this.head,r=0;null!==n;r++)t.call(e,n.value,r,this),n=n.next},I.prototype.forEachReverse=function(t,e){e=e||this;for(var n=this.tail,r=this.length-1;null!==n;r--)t.call(e,n.value,r,this),n=n.prev},I.prototype.get=function(t){for(var e=0,n=this.head;null!==n&&e<t;e++)n=n.next;if(e===t&&null!==n)return n.value},I.prototype.getReverse=function(t){for(var e=0,n=this.tail;null!==n&&e<t;e++)n=n.prev;if(e===t&&null!==n)return n.value},I.prototype.map=function(t,e){e=e||this;for(var n=new I,r=this.head;null!==r;)n.push(t.call(e,r.value,this)),r=r.next;return n},I.prototype.mapReverse=function(t,e){e=e||this;for(var n=new I,r=this.tail;null!==r;)n.push(t.call(e,r.value,this)),r=r.prev;return n},I.prototype.reduce=function(t,e){var n,r=this.head;if(1<arguments.length)n=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var i=0;null!==r;i++)n=t(n,r.value,i),r=r.next;return n},I.prototype.reduceReverse=function(t,e){var n,r=this.tail;if(1<arguments.length)n=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var i=this.length-1;null!==r;i--)n=t(n,r.value,i),r=r.prev;return n},I.prototype.toArray=function(){for(var t=new Array(this.length),e=0,n=this.head;null!==n;e++)t[e]=n.value,n=n.next;return t},I.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,n=this.tail;null!==n;e++)t[e]=n.value,n=n.prev;return t},I.prototype.slice=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var n=new I;if(e<t||e<0)return n;t<0&&(t=0),e>this.length&&(e=this.length);for(var r=0,i=this.head;null!==i&&r<t;r++)i=i.next;for(;null!==i&&r<e;r++,i=i.next)n.push(i.value);return n},I.prototype.sliceReverse=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var n=new I;if(e<t||e<0)return n;t<0&&(t=0),e>this.length&&(e=this.length);for(var r=this.length,i=this.tail;null!==i&&e<r;r--)i=i.prev;for(;null!==i&&t<r;r--,i=i.prev)n.push(i.value);return n},I.prototype.reverse=function(){for(var t=this.head,e=this.tail,n=t;null!==n;n=n.prev){var r=n.prev;n.prev=n.next,n.next=r}return this.head=e,this.tail=t,this};var Q,W,X=(Q=V)&&Q.default||Q,Y=ct,tt=(W="function"==typeof Symbol&&"1"!==process.env._nodeLRUCacheForceNoSymbol?function(t){return Symbol(t)}:function(t){return"_"+t})("max"),et=W("length"),nt=W("lengthCalculator"),rt=W("allowStale"),it=W("maxAge"),ot=W("dispose"),ut=W("noDisposeOnSet"),st=W("lruList"),at=W("cache");function lt(){return 1}function ct(t){if(!(this instanceof ct))return new ct(t);"number"==typeof t&&(t={max:t}),t=t||{};var e=this[tt]=t.max;(!e||"number"!=typeof e||e<=0)&&(this[tt]=1/0);var n=t.length||lt;"function"!=typeof n&&(n=lt),this[nt]=n,this[rt]=t.stale||!1,this[it]=t.maxAge||0,this[ot]=t.dispose,this[ut]=t.noDisposeOnSet||!1,this.reset()}function ft(t,e,n,r){var i=n.value;pt(t,i)&&(yt(t,n),t[rt]||(i=void 0)),i&&e.call(r,i.value,i.key,t)}function ht(t,e,n){var r=t[at].get(e);if(r){var i=r.value;pt(t,i)?(yt(t,r),t[rt]||(i=void 0)):n&&t[st].unshiftNode(r),i=i&&i.value}return i}function pt(t,e){if(e&&(e.maxAge||t[it])){var n=Date.now()-e.now;return e.maxAge?n>e.maxAge:t[it]&&n>t[it]}}function vt(t){if(t[et]>t[tt])for(var e=t[st].tail;t[et]>t[tt]&&null!==e;){var n=e.prev;yt(t,e),e=n}}function yt(t,e){if(e){var n=e.value;t[ot]&&t[ot](n.key,n.value),t[et]-=n.length,t[at].delete(n.key),t[st].removeNode(e)}}function dt(t,e,n,r,i){this.key=t,this.value=e,this.length=n,this.now=r,this.maxAge=i||0}function gt(t,u,s,a){return new(s=s||Promise)(function(n,e){function r(t){try{o(a.next(t))}catch(t){e(t)}}function i(t){try{o(a.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,i)}o((a=a.apply(t,u||[])).next())})}function mt(n,r){var i,o,u,t,s={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,o&&(u=2&e[0]?o.return:e[0]?o.throw||((u=o.return)&&u.call(o),0):o.next)&&!(u=u.call(o,e[1])).done)return u;switch(o=0,u&&(e=[2&e[0],u.value]),e[0]){case 0:case 1:u=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,o=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(u=0<(u=s.trys).length&&u[u.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!u||e[1]>u[0]&&e[1]<u[3])){s.label=e[1];break}if(6===e[0]&&s.label<u[1]){s.label=u[1],u=e;break}if(u&&s.label<u[2]){s.label=u[2],s.ops.push(e);break}u[2]&&s.ops.pop(),s.trys.pop();continue}e=r.call(n,s)}catch(t){e=[6,t],o=0}finally{i=u=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}Object.defineProperty(ct.prototype,"max",{set:function(t){(!t||"number"!=typeof t||t<=0)&&(t=1/0),this[tt]=t,vt(this)},get:function(){return this[tt]},enumerable:!0}),Object.defineProperty(ct.prototype,"allowStale",{set:function(t){this[rt]=!!t},get:function(){return this[rt]},enumerable:!0}),Object.defineProperty(ct.prototype,"maxAge",{set:function(t){(!t||"number"!=typeof t||t<0)&&(t=0),this[it]=t,vt(this)},get:function(){return this[it]},enumerable:!0}),Object.defineProperty(ct.prototype,"lengthCalculator",{set:function(t){"function"!=typeof t&&(t=lt),t!==this[nt]&&(this[nt]=t,this[et]=0,this[st].forEach(function(t){t.length=this[nt](t.value,t.key),this[et]+=t.length},this)),vt(this)},get:function(){return this[nt]},enumerable:!0}),Object.defineProperty(ct.prototype,"length",{get:function(){return this[et]},enumerable:!0}),Object.defineProperty(ct.prototype,"itemCount",{get:function(){return this[st].length},enumerable:!0}),ct.prototype.rforEach=function(t,e){e=e||this;for(var n=this[st].tail;null!==n;){var r=n.prev;ft(this,t,n,e),n=r}},ct.prototype.forEach=function(t,e){e=e||this;for(var n=this[st].head;null!==n;){var r=n.next;ft(this,t,n,e),n=r}},ct.prototype.keys=function(){return this[st].toArray().map(function(t){return t.key},this)},ct.prototype.values=function(){return this[st].toArray().map(function(t){return t.value},this)},ct.prototype.reset=function(){this[ot]&&this[st]&&this[st].length&&this[st].forEach(function(t){this[ot](t.key,t.value)},this),this[at]=new o,this[st]=new H,this[et]=0},ct.prototype.dump=function(){return this[st].map(function(t){if(!pt(this,t))return{k:t.key,v:t.value,e:t.now+(t.maxAge||0)}},this).toArray().filter(function(t){return t})},ct.prototype.dumpLru=function(){return this[st]},ct.prototype.inspect=function(t,r){var i="LRUCache {",o=!1;this[rt]&&(i+="\n allowStale: true",o=!0);var e=this[tt];e&&e!==1/0&&(o&&(i+=","),i+="\n max: "+X.inspect(e,r),o=!0);var u=this[it];u&&(o&&(i+=","),i+="\n maxAge: "+X.inspect(u,r),o=!0);var s=this[nt];s&&s!==lt&&(o&&(i+=","),i+="\n length: "+X.inspect(this[et],r),o=!0);var a=!1;return this[st].forEach(function(t){a?i+=",\n ":(o&&(i+=",\n"),a=!0,i+="\n ");var e=X.inspect(t.key).split("\n").join("\n "),n={value:t.value};t.maxAge!==u&&(n.maxAge=t.maxAge),s!==lt&&(n.length=t.length),pt(this,t)&&(n.stale=!0),n=X.inspect(n,r).split("\n").join("\n "),i+=e+" => "+n}),(a||o)&&(i+="\n"),i+="}"},ct.prototype.set=function(t,e,n){var r=(n=n||this[it])?Date.now():0,i=this[nt](e,t);if(this[at].has(t)){if(i>this[tt])return yt(this,this[at].get(t)),!1;var o=this[at].get(t).value;return this[ot]&&(this[ut]||this[ot](t,o.value)),o.now=r,o.maxAge=n,o.value=e,this[et]+=i-o.length,o.length=i,this.get(t),vt(this),!0}var u=new dt(t,e,i,r,n);return u.length>this[tt]?(this[ot]&&this[ot](t,e),!1):(this[et]+=u.length,this[st].unshift(u),this[at].set(t,this[st].head),vt(this),!0)},ct.prototype.has=function(t){if(!this[at].has(t))return!1;var e=this[at].get(t).value;return!pt(this,e)},ct.prototype.get=function(t){return ht(this,t,!0)},ct.prototype.peek=function(t){return ht(this,t,!1)},ct.prototype.pop=function(){var t=this[st].tail;return t?(yt(this,t),t.value):null},ct.prototype.del=function(t){yt(this,this[at].get(t))},ct.prototype.load=function(t){this.reset();for(var e=Date.now(),n=t.length-1;0<=n;n--){var r=t[n],i=r.e||0;if(0===i)this.set(r.k,r.v);else{var o=i-e;0<o&&this.set(r.k,r.v,o)}}},ct.prototype.prune=function(){var n=this;this[at].forEach(function(t,e){ht(n,e,!1)})};var bt=Object.prototype.toString;function wt(t){return"[object Array]"===bt.call(t)}function xt(t){return null!==t&&"object"==typeof t}function jt(t){return"[object Function]"===bt.call(t)}function Et(t,e){if(null!=t)if("object"!=typeof t&&(t=[t]),wt(t))for(var n=0,r=t.length;n<r;n++)e.call(null,t[n],n,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}var Ot={isArray:wt,isArrayBuffer:function(t){return"[object ArrayBuffer]"===bt.call(t)},isBuffer:function(t){return null!=t&&null!=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:xt,isUndefined:function(t){return void 0===t},isDate:function(t){return"[object Date]"===bt.call(t)},isFile:function(t){return"[object File]"===bt.call(t)},isBlob:function(t){return"[object Blob]"===bt.call(t)},isFunction:jt,isStream:function(t){return xt(t)&&jt(t.pipe)},isURLSearchParams:function(t){return"undefined"!=typeof URLSearchParams&&t instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:Et,merge:function n(){var r={};function t(t,e){"object"==typeof r[e]&&"object"==typeof t?r[e]=n(r[e],t):r[e]=t}for(var e=0,i=arguments.length;e<i;e++)Et(arguments[e],t);return r},extend:function(i,t,o){return Et(t,function(t,e){var n,r;i[e]=o&&"function"==typeof t?(n=t,r=o,function(){for(var t=new Array(arguments.length),e=0;e<t.length;e++)t[e]=arguments[e];return n.apply(r,t)}):t}),i},trim:function(t){return t.replace(/^\s*/,"").replace(/\s*$/,"")}};function St(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var At=function(t,e,n){if(!e)return t;var r;if(n)r=n(e);else if(Ot.isURLSearchParams(e))r=e.toString();else{var i=[];Ot.forEach(e,function(t,e){null!=t&&(Ot.isArray(t)?e+="[]":t=[t],Ot.forEach(t,function(t){Ot.isDate(t)?t=t.toISOString():Ot.isObject(t)&&(t=JSON.stringify(t)),i.push(St(e)+"="+St(t))}))}),r=i.join("&")}return r&&(t+=(-1===t.indexOf("?")?"?":"&")+r),t};function _t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=At.apply(void 0,t),r=n.split("?"),i=r[0],o=r[1];return o?i+"?"+o.split("&").sort().join("&"):n}t.Cache=Y,t.cacheAdapterEnhancer=function(f,t){var h=this;void 0===t&&(t={});var e=t.enabledByDefault,p=void 0===e||e,n=t.cacheFlag,v=void 0===n?"cache":n,r=t.defaultCache,y=void 0===r?new Y({maxAge:3e5,max:100}):r;return function(n){var t,e=n.url,r=n.method,i=n.params,o=n.paramsSerializer,u=n.forceUpdate,s=void 0!==n[v]&&null!==n[v]?n[v]:p;if("get"===r&&s){var a=(t=s).set&&t.get&&t.del&&"function"==typeof t.get&&"function"==typeof t.set&&"function"==typeof t.del?s:y,l=_t(e,i,o),c=a.get(l);return!c||u?(c=gt(h,void 0,void 0,function(){var e;return mt(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,f(n)];case 1:return[2,t.sent()];case 2:throw e=t.sent(),a.del(l),e;case 3:return[2]}})}),a.set(l,c),c):("info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by cache adapter --\x3e url: "+l),c)}return f(n)}},t.retryAdapterEnhancer=function(s,t){var e=this;void 0===t&&(t={});var n=t.times,a=void 0===n?2:n;return function(u){return gt(e,void 0,void 0,function(){var e,n,r,i,o=this;return mt(this,function(t){return e=u.retryTimes,n=void 0===e?a:e,r=0,[2,(i=function(){return gt(o,void 0,void 0,function(){var e;return mt(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,s(u)];case 1:return[2,t.sent()];case 2:if(e=t.sent(),n===r)throw e;return r++,"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request start retrying --\x3e url: "+u.url+" , time: "+r),[2,i()];case 3:return[2]}})})})()]})})}},t.throttleAdapterEnhancer=function(s,t){var e=this;function a(r,i){var t=gt(e,void 0,void 0,function(){var e,n;return mt(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,s(i)];case 1:return e=t.sent(),c.set(r,{timestamp:Date.now(),value:Promise.resolve(e)}),[2,e];case 2:throw n=t.sent(),c.del(r),n;case 3:return[2]}})});return c.set(r,{timestamp:Date.now(),value:t}),t}void 0===t&&(t={});var n=t.threshold,l=void 0===n?1e3:n,r=t.cache,c=void 0===r?new Y({max:10}):r;return function(t){var e=t.url,n=t.method,r=_t(e,t.params,t.paramsSerializer),i=Date.now(),o=c.get(r)||{timestamp:i};if("get"!==n)return s(t);if(i-o.timestamp<=l){var u=o.value;if(u)return"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by throttle adapter --\x3e url: "+r),u}return a(r,t)}},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self)["axios-extensions"]={})}(this,(function(t){"use strict";var e=n;function n(t){var e=this;if(e instanceof n||(e=new n),e.tail=null,e.head=null,e.length=0,t&&"function"==typeof t.forEach)t.forEach((function(t){e.push(t)}));else if(arguments.length>0)for(var r=0,i=arguments.length;r<i;r++)e.push(arguments[r]);return e}function r(t,e,n){var r=e===t.head?new s(n,null,e,t):new s(n,e,e.next,t);return null===r.next&&(t.tail=r),null===r.prev&&(t.head=r),t.length++,r}function i(t,e){t.tail=new s(e,t.tail,null,t),t.head||(t.head=t.tail),t.length++}function o(t,e){t.head=new s(e,null,t.head,t),t.tail||(t.tail=t.head),t.length++}function s(t,e,n,r){if(!(this instanceof s))return new s(t,e,n,r);this.list=r,this.value=t,e?(e.next=this,this.prev=e):this.prev=null,n?(n.prev=this,this.next=n):this.next=null}n.Node=s,n.create=n,n.prototype.removeNode=function(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");var e=t.next,n=t.prev;return e&&(e.prev=n),n&&(n.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=n),t.list.length--,t.next=null,t.prev=null,t.list=null,e},n.prototype.unshiftNode=function(t){if(t!==this.head){t.list&&t.list.removeNode(t);var e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}},n.prototype.pushNode=function(t){if(t!==this.tail){t.list&&t.list.removeNode(t);var e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}},n.prototype.push=function(){for(var t=0,e=arguments.length;t<e;t++)i(this,arguments[t]);return this.length},n.prototype.unshift=function(){for(var t=0,e=arguments.length;t<e;t++)o(this,arguments[t]);return this.length},n.prototype.pop=function(){if(this.tail){var t=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}},n.prototype.shift=function(){if(this.head){var t=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}},n.prototype.forEach=function(t,e){e=e||this;for(var n=this.head,r=0;null!==n;r++)t.call(e,n.value,r,this),n=n.next},n.prototype.forEachReverse=function(t,e){e=e||this;for(var n=this.tail,r=this.length-1;null!==n;r--)t.call(e,n.value,r,this),n=n.prev},n.prototype.get=function(t){for(var e=0,n=this.head;null!==n&&e<t;e++)n=n.next;if(e===t&&null!==n)return n.value},n.prototype.getReverse=function(t){for(var e=0,n=this.tail;null!==n&&e<t;e++)n=n.prev;if(e===t&&null!==n)return n.value},n.prototype.map=function(t,e){e=e||this;for(var r=new n,i=this.head;null!==i;)r.push(t.call(e,i.value,this)),i=i.next;return r},n.prototype.mapReverse=function(t,e){e=e||this;for(var r=new n,i=this.tail;null!==i;)r.push(t.call(e,i.value,this)),i=i.prev;return r},n.prototype.reduce=function(t,e){var n,r=this.head;if(arguments.length>1)n=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var i=0;null!==r;i++)n=t(n,r.value,i),r=r.next;return n},n.prototype.reduceReverse=function(t,e){var n,r=this.tail;if(arguments.length>1)n=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var i=this.length-1;null!==r;i--)n=t(n,r.value,i),r=r.prev;return n},n.prototype.toArray=function(){for(var t=new Array(this.length),e=0,n=this.head;null!==n;e++)t[e]=n.value,n=n.next;return t},n.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,n=this.tail;null!==n;e++)t[e]=n.value,n=n.prev;return t},n.prototype.slice=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var r=new n;if(e<t||e<0)return r;t<0&&(t=0),e>this.length&&(e=this.length);for(var i=0,o=this.head;null!==o&&i<t;i++)o=o.next;for(;null!==o&&i<e;i++,o=o.next)r.push(o.value);return r},n.prototype.sliceReverse=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var r=new n;if(e<t||e<0)return r;t<0&&(t=0),e>this.length&&(e=this.length);for(var i=this.length,o=this.tail;null!==o&&i>e;i--)o=o.prev;for(;null!==o&&i>t;i--,o=o.prev)r.push(o.value);return r},n.prototype.splice=function(t,e){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(var n=0,i=this.head;null!==i&&n<t;n++)i=i.next;var o=[];for(n=0;i&&n<e;n++)o.push(i.value),i=this.removeNode(i);null===i&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev);for(n=2;n<arguments.length;n++)i=r(this,i,arguments[n]);return o},n.prototype.reverse=function(){for(var t=this.head,e=this.tail,n=t;null!==n;n=n.prev){var r=n.prev;n.prev=n.next,n.next=r}return this.head=e,this.tail=t,this};try{!function(t){t.prototype[Symbol.iterator]=function*(){for(let t=this.head;t;t=t.next)yield t.value}}(n)}catch(t){}const a=Symbol("max"),l=Symbol("length"),u=Symbol("lengthCalculator"),h=Symbol("allowStale"),f=Symbol("maxAge"),c=Symbol("dispose"),p=Symbol("noDisposeOnSet"),v=Symbol("lruList"),d=Symbol("cache"),y=Symbol("updateAgeOnGet"),g=()=>1;const m=(t,e,n)=>{const r=t[d].get(e);if(r){const e=r.value;if(w(t,e)){if(b(t,r),!t[h])return}else n&&(t[y]&&(r.value.now=Date.now()),t[v].unshiftNode(r));return e.value}},w=(t,e)=>{if(!e||!e.maxAge&&!t[f])return!1;const n=Date.now()-e.now;return e.maxAge?n>e.maxAge:t[f]&&n>t[f]},x=t=>{if(t[l]>t[a])for(let e=t[v].tail;t[l]>t[a]&&null!==e;){const n=e.prev;b(t,e),e=n}},b=(t,e)=>{if(e){const n=e.value;t[c]&&t[c](n.key,n.value),t[l]-=n.length,t[d].delete(n.key),t[v].removeNode(e)}};class A{constructor(t,e,n,r,i){this.key=t,this.value=e,this.length=n,this.now=r,this.maxAge=i||0}}const E=(t,e,n,r)=>{let i=n.value;w(t,i)&&(b(t,n),t[h]||(i=void 0)),i&&e.call(r,i.value,i.key,t)};var S=class{constructor(t){if("number"==typeof t&&(t={max:t}),t||(t={}),t.max&&("number"!=typeof t.max||t.max<0))throw new TypeError("max must be a non-negative number");this[a]=t.max||1/0;const e=t.length||g;if(this[u]="function"!=typeof e?g:e,this[h]=t.stale||!1,t.maxAge&&"number"!=typeof t.maxAge)throw new TypeError("maxAge must be a number");this[f]=t.maxAge||0,this[c]=t.dispose,this[p]=t.noDisposeOnSet||!1,this[y]=t.updateAgeOnGet||!1,this.reset()}set max(t){if("number"!=typeof t||t<0)throw new TypeError("max must be a non-negative number");this[a]=t||1/0,x(this)}get max(){return this[a]}set allowStale(t){this[h]=!!t}get allowStale(){return this[h]}set maxAge(t){if("number"!=typeof t)throw new TypeError("maxAge must be a non-negative number");this[f]=t,x(this)}get maxAge(){return this[f]}set lengthCalculator(t){"function"!=typeof t&&(t=g),t!==this[u]&&(this[u]=t,this[l]=0,this[v].forEach(t=>{t.length=this[u](t.value,t.key),this[l]+=t.length})),x(this)}get lengthCalculator(){return this[u]}get length(){return this[l]}get itemCount(){return this[v].length}rforEach(t,e){e=e||this;for(let n=this[v].tail;null!==n;){const r=n.prev;E(this,t,n,e),n=r}}forEach(t,e){e=e||this;for(let n=this[v].head;null!==n;){const r=n.next;E(this,t,n,e),n=r}}keys(){return this[v].toArray().map(t=>t.key)}values(){return this[v].toArray().map(t=>t.value)}reset(){this[c]&&this[v]&&this[v].length&&this[v].forEach(t=>this[c](t.key,t.value)),this[d]=new Map,this[v]=new e,this[l]=0}dump(){return this[v].map(t=>!w(this,t)&&{k:t.key,v:t.value,e:t.now+(t.maxAge||0)}).toArray().filter(t=>t)}dumpLru(){return this[v]}set(t,e,n){if((n=n||this[f])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");const r=n?Date.now():0,i=this[u](e,t);if(this[d].has(t)){if(i>this[a])return b(this,this[d].get(t)),!1;const o=this[d].get(t).value;return this[c]&&(this[p]||this[c](t,o.value)),o.now=r,o.maxAge=n,o.value=e,this[l]+=i-o.length,o.length=i,this.get(t),x(this),!0}const o=new A(t,e,i,r,n);return o.length>this[a]?(this[c]&&this[c](t,e),!1):(this[l]+=o.length,this[v].unshift(o),this[d].set(t,this[v].head),x(this),!0)}has(t){if(!this[d].has(t))return!1;const e=this[d].get(t).value;return!w(this,e)}get(t){return m(this,t,!0)}peek(t){return m(this,t,!1)}pop(){const t=this[v].tail;return t?(b(this,t),t.value):null}del(t){b(this,this[d].get(t))}load(t){this.reset();const e=Date.now();for(let n=t.length-1;n>=0;n--){const r=t[n],i=r.e||0;if(0===i)this.set(r.k,r.v);else{const t=i-e;t>0&&this.set(r.k,r.v,t)}}}prune(){this[d].forEach((t,e)=>m(this,e,!1))}}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function j(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{l(r.next(t))}catch(t){o(t)}}function a(t){try{l(r.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((r=r.apply(t,e||[])).next())}))}function k(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[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(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}var D=Object.prototype.toString; | ||
/*! | ||
* Determine if an object is a Buffer | ||
* | ||
* @author Feross Aboukhadijeh <https://feross.org> | ||
* @license MIT | ||
*/function R(t){return"[object Array]"===D.call(t)}function O(t){return null!==t&&"object"==typeof t}function B(t){return"[object Function]"===D.call(t)}function L(t,e){if(null!=t)if("object"!=typeof t&&(t=[t]),R(t))for(var n=0,r=t.length;n<r;n++)e.call(null,t[n],n,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}var N={isArray:R,isArrayBuffer:function(t){return"[object ArrayBuffer]"===D.call(t)},isBuffer:function(t){return null!=t&&null!=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:O,isUndefined:function(t){return void 0===t},isDate:function(t){return"[object Date]"===D.call(t)},isFile:function(t){return"[object File]"===D.call(t)},isBlob:function(t){return"[object Blob]"===D.call(t)},isFunction:B,isStream:function(t){return O(t)&&B(t.pipe)},isURLSearchParams:function(t){return"undefined"!=typeof URLSearchParams&&t instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:L,merge:function t(){var e={};function n(n,r){"object"==typeof e[r]&&"object"==typeof n?e[r]=t(e[r],n):e[r]=n}for(var r=0,i=arguments.length;r<i;r++)L(arguments[r],n);return e},extend:function(t,e,n){return L(e,(function(e,r){t[r]=n&&"function"==typeof e?function(t,e){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return t.apply(e,n)}}(e,n):e})),t},trim:function(t){return t.replace(/^\s*/,"").replace(/\s*$/,"")}};function G(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var T=function(t,e,n){if(!e)return t;var r;if(n)r=n(e);else if(N.isURLSearchParams(e))r=e.toString();else{var i=[];N.forEach(e,(function(t,e){null!=t&&(N.isArray(t)?e+="[]":t=[t],N.forEach(t,(function(t){N.isDate(t)?t=t.toISOString():N.isObject(t)&&(t=JSON.stringify(t)),i.push(G(e)+"="+G(t))})))})),r=i.join("&")}return r&&(t+=(-1===t.indexOf("?")?"?":"&")+r),t};function C(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=T.apply(void 0,t),r=n.split("?"),i=r[0],o=r[1];if(o){var s=o.split("&");return i+"?"+s.sort().join("&")}return n}t.Cache=S,t.cacheAdapterEnhancer=function(t,e){var n=this;void 0===e&&(e={});var r=e.enabledByDefault,i=void 0===r||r,o=e.cacheFlag,s=void 0===o?"cache":o,a=e.defaultCache,l=void 0===a?new S({maxAge:3e5,max:100}):a;return function(e){var r,o=e.url,a=e.method,u=e.params,h=e.paramsSerializer,f=e.forceUpdate,c=void 0!==e[s]&&null!==e[s]?e[s]:i;if("get"===a&&c){var p=(r=c).set&&r.get&&r.del&&"function"==typeof r.get&&"function"==typeof r.set&&"function"==typeof r.del?c:l,v=C(o,u,h),d=p.get(v);return!d||f?(d=j(n,void 0,void 0,(function(){var n;return k(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,r.sent()];case 2:throw n=r.sent(),p.del(v),n;case 3:return[2]}}))})),p.set(v,d),d):("info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by cache adapter --\x3e url: "+v),d)}return t(e)}},t.retryAdapterEnhancer=function(t,e){var n=this;void 0===e&&(e={});var r=e.times,i=void 0===r?2:r;return function(e){return j(n,void 0,void 0,(function(){var n,r,o,s,a=this;return k(this,(function(l){return n=e.retryTimes,r=void 0===n?i:n,!1,o=0,[2,(s=function(){return j(a,void 0,void 0,(function(){var n;return k(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,t(e)];case 1:return[2,i.sent()];case 2:if(n=i.sent(),r===o)throw n;return o++,"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request start retrying --\x3e url: "+e.url+" , time: "+o),[2,s()];case 3:return[2]}}))}))})()]}))}))}},t.throttleAdapterEnhancer=function(t,e){var n=this;void 0===e&&(e={});var r=e.threshold,i=void 0===r?1e3:r,o=e.cache,s=void 0===o?new S({max:10}):o;return function(e){var r=e.url,o=e.method,a=C(r,e.params,e.paramsSerializer),l=Date.now(),u=s.get(a)||{timestamp:l};if("get"===o){if(l-u.timestamp<=i){var h=u.value;if(h)return"info"===process.env.LOGGER_LEVEL&&console.info("[axios-extensions] request cached by throttle adapter --\x3e url: "+a),h}return function(e,r){var i=j(n,void 0,void 0,(function(){var n,i;return k(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,t(r)];case 1:return n=o.sent(),s.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),[2,n];case 2:throw i=o.sent(),s.del(e),i;case 3:return[2]}}))}));return s.set(e,{timestamp:Date.now(),value:i}),i}(a,e)}return t(e)}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=axios-extensions.min.js.map |
{ | ||
"name": "axios-extensions", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "make axios great again", | ||
@@ -43,3 +43,3 @@ "homepage": "https://github.com/kuitos/axios-extensions", | ||
"@types/lru-cache": "^4.1.1", | ||
"lru-cache": "^4.1.5", | ||
"lru-cache": "^5.1.1", | ||
"tslib": "^1.9.0", | ||
@@ -64,2 +64,3 @@ "util": "^0.11.1" | ||
"rollup-plugin-node-resolve": "^5.0.0", | ||
"rollup-plugin-terser": "^6.1.0", | ||
"rollup-plugin-uglify": "^6.0.2", | ||
@@ -66,0 +67,0 @@ "sinon": "^5.0.3", |
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
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
337256
18
2986
+ Addedlru-cache@5.1.1(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedyallist@2.1.2(transitive)
Updatedlru-cache@^5.1.1