533 lines
14 KiB
JavaScript
533 lines
14 KiB
JavaScript
// Metro module 1386 (f1387).
|
|
import * as _Module1387 from "./Module1387";
|
|
import * as _Yallist from "./Yallist";
|
|
import { inspect } from "./inspect";
|
|
let c1148_2, c1148_3, naiveLength, LRUCache, forEachStep, get2, trim, Entry;
|
|
const priv = function priv(a0, a1, a2) {
|
|
let r8, r11;
|
|
if (c1148_3[a1]) {
|
|
r8 = c1148_3[a1];
|
|
} else {
|
|
r8 = c1148_2(a1);
|
|
c1148_3[a1] = r8;
|
|
}
|
|
if (arguments.length === 2) {
|
|
r11 = a0[r8];
|
|
} else {
|
|
r11 = a2;
|
|
a0[r8] = a2;
|
|
}
|
|
return r11;
|
|
};
|
|
naiveLength = function naiveLength() {
|
|
return 1;
|
|
};
|
|
LRUCache = function LRUCache(a0) {
|
|
if (this instanceof LRUCache) {
|
|
const r13 = (typeof a0 === "number" ? {
|
|
max: a0
|
|
} : a0) || {};
|
|
const r18 = priv(this, "max", r13.max);
|
|
if ((r18 ? typeof r18 !== "number" : !r18) || r18 <= 0) {
|
|
priv(this, "max", Infinity);
|
|
}
|
|
let r21 = r13.length || naiveLength;
|
|
if (typeof r21 !== "function") {
|
|
r21 = naiveLength;
|
|
}
|
|
priv(this, "lengthCalculator", r21);
|
|
priv(this, "allowStale", r13.stale || false);
|
|
priv(this, "maxAge", r13.maxAge || 0);
|
|
priv(this, "dispose", r13.dispose);
|
|
this.reset();
|
|
return void 0;
|
|
}
|
|
const r10 = {
|
|
__proto__: LRUCache.prototype
|
|
};
|
|
const r11 = LRUCache.call(r10, a0);
|
|
return r11 instanceof Object ? r11 : r10;
|
|
};
|
|
forEachStep = function forEachStep(a0, a1, a2, a3) {
|
|
let r5, value;
|
|
L9: {
|
|
value = a2.value;
|
|
r5 = false;
|
|
if (value) {
|
|
if (!value.maxAge) {
|
|
const r20 = priv(a0, "maxAge");
|
|
r5 = false;
|
|
if (!r20) {
|
|
break L9;
|
|
}
|
|
}
|
|
const r9 = Date.now() - value.now;
|
|
r5 = value.maxAge ? r9 > value.maxAge : priv(a0, "maxAge") && r9 > priv(a0, "maxAge");
|
|
}
|
|
}
|
|
let r31 = value;
|
|
if (r5) {
|
|
if (a2) {
|
|
const value2 = a2.value;
|
|
if (priv(a0, "dispose")) {
|
|
priv(a0, "dispose").call(globalThis, value2.key, value2.value);
|
|
}
|
|
priv(a0, "length", priv(a0, "length") - value2.length);
|
|
priv(a0, "cache").delete(value2.key);
|
|
priv(a0, "lruList").removeNode(a2);
|
|
}
|
|
if (!priv(a0, "allowStale")) {
|
|
value = void 0;
|
|
}
|
|
r31 = value;
|
|
}
|
|
if (r31) {
|
|
a1.call(a3, r31.value, r31.key, a0);
|
|
}
|
|
};
|
|
get2 = function get(a0, a1, a2) {
|
|
let r17, r31, value;
|
|
const r9 = priv(a0, "cache").get(a1);
|
|
let r16 = void 0;
|
|
if (r9) {
|
|
L10: {
|
|
value = r9.value;
|
|
r17 = false;
|
|
if (value) {
|
|
if (!value.maxAge) {
|
|
const r20 = priv(a0, "maxAge");
|
|
r17 = false;
|
|
if (!r20) {
|
|
break L10;
|
|
}
|
|
}
|
|
const r11 = Date.now() - value.now;
|
|
r17 = value.maxAge ? r11 > value.maxAge : priv(a0, "maxAge") && r11 > priv(a0, "maxAge");
|
|
}
|
|
}
|
|
if (r17) {
|
|
if (r9) {
|
|
const value2 = r9.value;
|
|
if (priv(a0, "dispose")) {
|
|
priv(a0, "dispose").call(globalThis, value2.key, value2.value);
|
|
}
|
|
priv(a0, "length", priv(a0, "length") - value2.length);
|
|
priv(a0, "cache").delete(value2.key);
|
|
priv(a0, "lruList").removeNode(r9);
|
|
}
|
|
r31 = priv(a0, "allowStale") ? value : void 0;
|
|
} else {
|
|
r31 = value;
|
|
if (a2) {
|
|
priv(a0, "lruList").unshiftNode(r9);
|
|
r31 = value;
|
|
}
|
|
}
|
|
r16 = r31 && r31.value;
|
|
}
|
|
return r16;
|
|
};
|
|
trim = function trim(a0) {
|
|
if (priv(a0, "length") > priv(a0, "max")) {
|
|
let tail = priv(a0, "lruList").tail;
|
|
if (priv(a0, "length") > priv(a0, "max")) {
|
|
while (tail !== null) {
|
|
const prev = tail.prev;
|
|
const r14 = tail;
|
|
if (r14) {
|
|
const value = r14.value;
|
|
if (priv(a0, "dispose")) {
|
|
priv(a0, "dispose").call(globalThis, value.key, value.value);
|
|
}
|
|
priv(a0, "length", priv(a0, "length") - value.length);
|
|
priv(a0, "cache").delete(value.key);
|
|
priv(a0, "lruList").removeNode(r14);
|
|
}
|
|
if (!(priv(a0, "length") > priv(a0, "max"))) {
|
|
break;
|
|
}
|
|
tail = prev;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
Entry = function Entry(a0, a1, a2, a3, a4) {
|
|
let maxAge = a4;
|
|
this.key = a0;
|
|
this.value = a1;
|
|
this.length = a2;
|
|
this.now = a3;
|
|
if (!a4) {
|
|
maxAge = 0;
|
|
}
|
|
this.maxAge = maxAge;
|
|
};
|
|
module.exports = LRUCache;
|
|
c1148_3 = {};
|
|
c1148_2 = typeof globalThis.Symbol === "function" ? function(a0) {
|
|
return Symbol.for(a0);
|
|
} : function(a0) {
|
|
return "_" + a0;
|
|
};
|
|
Object.defineProperty(LRUCache.prototype, "max", {
|
|
set: function set(a0) {
|
|
priv(this, "max", (a0 ? typeof a0 !== "number" : !a0) || a0 <= 0 ? Infinity : a0);
|
|
trim(this);
|
|
},
|
|
get: function get() {
|
|
return priv(this, "max");
|
|
},
|
|
enumerable: true
|
|
});
|
|
Object.defineProperty(LRUCache.prototype, "allowStale", {
|
|
set: function set(a0) {
|
|
priv(this, "allowStale", !!a0);
|
|
},
|
|
get: function get() {
|
|
return priv(this, "allowStale");
|
|
},
|
|
enumerable: true
|
|
});
|
|
Object.defineProperty(LRUCache.prototype, "maxAge", {
|
|
set: function set(a0) {
|
|
priv(this, "maxAge", (a0 ? typeof a0 !== "number" : !a0) || a0 < 0 ? 0 : a0);
|
|
trim(this);
|
|
},
|
|
get: function get() {
|
|
return priv(this, "maxAge");
|
|
},
|
|
enumerable: true
|
|
});
|
|
Object.defineProperty(LRUCache.prototype, "lengthCalculator", {
|
|
set: function set(a0) {
|
|
const r7 = typeof a0 !== "function" ? naiveLength : a0;
|
|
if (r7 !== priv(this, "lengthCalculator")) {
|
|
priv(this, "lengthCalculator", r7);
|
|
priv(this, "length", 0);
|
|
priv(this, "lruList").forEach(function(item) {
|
|
item.length = priv(this, "lengthCalculator").call(this, item.value, item.key);
|
|
priv(this, "length", priv(this, "length") + item.length);
|
|
}, this);
|
|
}
|
|
trim(this);
|
|
},
|
|
get: function get() {
|
|
return priv(this, "lengthCalculator");
|
|
},
|
|
enumerable: true
|
|
});
|
|
Object.defineProperty(LRUCache.prototype, "length", {
|
|
get: function get() {
|
|
return priv(this, "length");
|
|
},
|
|
enumerable: true
|
|
});
|
|
Object.defineProperty(LRUCache.prototype, "itemCount", {
|
|
get: function get() {
|
|
return priv(this, "lruList").length;
|
|
},
|
|
enumerable: true
|
|
});
|
|
LRUCache.prototype.rforEach = function(a0, a1) {
|
|
const r5 = a1 ? a1 : this;
|
|
let tail = priv(this, "lruList").tail;
|
|
while (tail !== null) {
|
|
const prev = tail.prev;
|
|
forEachStep(this, a0, tail, r5);
|
|
tail = prev;
|
|
}
|
|
};
|
|
LRUCache.prototype.forEach = function(a0, a1) {
|
|
const r5 = a1 ? a1 : this;
|
|
let head = priv(this, "lruList").head;
|
|
while (head !== null) {
|
|
const next = head.next;
|
|
forEachStep(this, a0, head, r5);
|
|
head = next;
|
|
}
|
|
};
|
|
LRUCache.prototype.keys = function() {
|
|
return priv(this, "lruList").toArray().map(function(item) {
|
|
return item.key;
|
|
}, this);
|
|
};
|
|
LRUCache.prototype.values = function() {
|
|
return priv(this, "lruList").toArray().map(function(item) {
|
|
return item.value;
|
|
}, this);
|
|
};
|
|
LRUCache.prototype.reset = function() {
|
|
if (priv(this, "dispose") && priv(this, "lruList") && priv(this, "lruList").length) {
|
|
priv(this, "lruList").forEach(function(item) {
|
|
priv(this, "dispose").call(this, item.key, item.value);
|
|
}, this);
|
|
}
|
|
priv(this, "cache", new _Module1387());
|
|
priv(this, "lruList", new _Yallist());
|
|
priv(this, "length", 0);
|
|
};
|
|
LRUCache.prototype.dump = function() {
|
|
return priv(this, "lruList").map(function(item) {
|
|
let r3;
|
|
L9: {
|
|
r3 = false;
|
|
if (item) {
|
|
if (!item.maxAge) {
|
|
const r11 = priv(this, "maxAge");
|
|
r3 = false;
|
|
if (!r11) {
|
|
break L9;
|
|
}
|
|
}
|
|
const r17 = Date.now() - item.now;
|
|
r3 = item.maxAge ? r17 > item.maxAge : priv(this, "maxAge") && r17 > priv(this, "maxAge");
|
|
}
|
|
}
|
|
if (r3) {
|
|
return void 0;
|
|
}
|
|
return {
|
|
k: item.key,
|
|
v: item.value,
|
|
e: item.now + (item.maxAge || 0)
|
|
};
|
|
}, this).toArray().filter(function(item) {
|
|
return item;
|
|
});
|
|
};
|
|
LRUCache.prototype.dumpLru = function() {
|
|
return priv(this, "lruList");
|
|
};
|
|
LRUCache.prototype.inspect = function(a0, a1) {
|
|
let c13014_1 = "LRUCache {";
|
|
let c13014_2 = false;
|
|
const r15 = priv(this, "allowStale");
|
|
let r1 = false;
|
|
if (r15) {
|
|
c13014_1 = c13014_1 + "\n allowStale: true";
|
|
c13014_2 = true;
|
|
r1 = true;
|
|
}
|
|
const r13 = priv(this, "max");
|
|
const r19 = r13 && r13 !== Infinity;
|
|
let r20 = r1;
|
|
if (r19) {
|
|
if (r1) {
|
|
c13014_1 = c13014_1 + ",";
|
|
}
|
|
c13014_1 = c13014_1 + ("\n max: " + inspect(r13, a1));
|
|
c13014_2 = true;
|
|
r20 = true;
|
|
}
|
|
const _this = priv(this, "maxAge");
|
|
let r36 = r20;
|
|
if (_this) {
|
|
if (r20) {
|
|
c13014_1 = c13014_1 + ",";
|
|
}
|
|
c13014_1 = c13014_1 + ("\n maxAge: " + inspect(_this, a1));
|
|
c13014_2 = true;
|
|
r36 = true;
|
|
}
|
|
const _this2 = priv(this, "lengthCalculator");
|
|
const r53 = _this2 ? _this2 !== naiveLength : _this2;
|
|
let r55 = r36;
|
|
if (r53) {
|
|
if (r36) {
|
|
c13014_1 = c13014_1 + ",";
|
|
}
|
|
c13014_1 = c13014_1 + ("\n length: " + inspect(priv(this, "length"), a1));
|
|
c13014_2 = true;
|
|
r55 = true;
|
|
}
|
|
let c13014_5 = false;
|
|
priv(this, "lruList").forEach(function(item) {
|
|
let r41;
|
|
if (c13014_5) {
|
|
c13014_1 = c13014_1 + ",\n ";
|
|
} else {
|
|
if (c13014_2) {
|
|
c13014_1 = c13014_1 + ",\n";
|
|
}
|
|
c13014_5 = true;
|
|
c13014_1 = c13014_1 + "\n ";
|
|
}
|
|
const r34 = inspect(item.key).split("\n").join("\n ");
|
|
const r9 = {
|
|
value: item.value
|
|
};
|
|
if (item.maxAge !== _this) {
|
|
r9.maxAge = item.maxAge;
|
|
}
|
|
if (_this2 !== naiveLength) {
|
|
r9.length = item.length;
|
|
}
|
|
L18: {
|
|
r41 = false;
|
|
if (item) {
|
|
if (!item.maxAge) {
|
|
const r44 = priv(this, "maxAge");
|
|
r41 = false;
|
|
if (!r44) {
|
|
break L18;
|
|
}
|
|
}
|
|
const r50 = Date.now() - item.now;
|
|
r41 = item.maxAge ? r50 > item.maxAge : priv(this, "maxAge") && r50 > priv(this, "maxAge");
|
|
}
|
|
}
|
|
if (r41) {
|
|
r9.stale = true;
|
|
}
|
|
c13014_1 = c13014_1 + (r34 + " => " + inspect(r9, a1).split("\n").join("\n "));
|
|
});
|
|
if (c13014_5 || r55) {
|
|
c13014_1 = c13014_1 + "\n";
|
|
}
|
|
const r83 = c13014_1 + "}";
|
|
c13014_1 = r83;
|
|
return r83;
|
|
};
|
|
LRUCache.prototype.set = function(a0, a1, a2) {
|
|
let r47;
|
|
const maxAge = a2 ? a2 : priv(this, "maxAge");
|
|
const now = maxAge ? Date.now() : 0;
|
|
const length = priv(this, "lengthCalculator").call(this, a1, a0);
|
|
if (priv(this, "cache").has(a0)) {
|
|
if (length > priv(this, "max")) {
|
|
const r80 = priv(this, "cache").get(a0);
|
|
if (r80) {
|
|
const value2 = r80.value;
|
|
if (priv(this, "dispose")) {
|
|
priv(this, "dispose").call(globalThis, value2.key, value2.value);
|
|
}
|
|
priv(this, "length", priv(this, "length") - value2.length);
|
|
priv(this, "cache").delete(value2.key);
|
|
priv(this, "lruList").removeNode(r80);
|
|
}
|
|
return false;
|
|
}
|
|
const value = priv(this, "cache").get(a0).value;
|
|
if (priv(this, "dispose")) {
|
|
priv(this, "dispose").call(this, a0, value.value);
|
|
}
|
|
value.now = now;
|
|
value.maxAge = maxAge;
|
|
value.value = a1;
|
|
priv(this, "length", priv(this, "length") + (length - value.length));
|
|
value.length = length;
|
|
this.get(a0);
|
|
trim(this);
|
|
return true;
|
|
}
|
|
const r16 = {
|
|
__proto__: Entry.prototype
|
|
};
|
|
r16.key = a0;
|
|
r16.value = a1;
|
|
r16.length = length;
|
|
r16.now = now;
|
|
r16.maxAge = maxAge || 0;
|
|
if (r16.length > priv(this, "max")) {
|
|
const r49 = priv(this, "dispose");
|
|
r47 = false;
|
|
if (r49) {
|
|
priv(this, "dispose").call(this, a0, a1);
|
|
r47 = false;
|
|
}
|
|
} else {
|
|
priv(this, "length", priv(this, "length") + r16.length);
|
|
priv(this, "lruList").unshift(r16);
|
|
priv(this, "cache").set(a0, priv(this, "lruList").head);
|
|
trim(this);
|
|
r47 = true;
|
|
}
|
|
return r47;
|
|
};
|
|
LRUCache.prototype.has = function(a0) {
|
|
let r17;
|
|
let r12 = !!priv(this, "cache").has(a0);
|
|
if (r12) {
|
|
L10: {
|
|
const value = priv(this, "cache").get(a0).value;
|
|
r17 = false;
|
|
if (value) {
|
|
if (!value.maxAge) {
|
|
const r20 = priv(this, "maxAge");
|
|
r17 = false;
|
|
if (!r20) {
|
|
break L10;
|
|
}
|
|
}
|
|
const r26 = Date.now() - value.now;
|
|
r17 = value.maxAge ? r26 > value.maxAge : priv(this, "maxAge") && r26 > priv(this, "maxAge");
|
|
}
|
|
}
|
|
r12 = !r17;
|
|
}
|
|
return r12;
|
|
};
|
|
LRUCache.prototype.get = function(a0) {
|
|
return get2(this, a0, true);
|
|
};
|
|
LRUCache.prototype.peek = function(a0) {
|
|
return get2(this, a0, false);
|
|
};
|
|
LRUCache.prototype.pop = function() {
|
|
const tail = priv(this, "lruList").tail;
|
|
let r13 = null;
|
|
if (tail) {
|
|
if (tail) {
|
|
const value = tail.value;
|
|
if (priv(this, "dispose")) {
|
|
priv(this, "dispose").call(globalThis, value.key, value.value);
|
|
}
|
|
priv(this, "length", priv(this, "length") - value.length);
|
|
priv(this, "cache").delete(value.key);
|
|
priv(this, "lruList").removeNode(tail);
|
|
}
|
|
r13 = tail.value;
|
|
}
|
|
return r13;
|
|
};
|
|
LRUCache.prototype.del = function(a0) {
|
|
const r12 = priv(this, "cache").get(a0);
|
|
if (r12) {
|
|
const value = r12.value;
|
|
if (priv(this, "dispose")) {
|
|
priv(this, "dispose").call(globalThis, value.key, value.value);
|
|
}
|
|
priv(this, "length", priv(this, "length") - value.length);
|
|
priv(this, "cache").delete(value.key);
|
|
priv(this, "lruList").removeNode(r12);
|
|
}
|
|
};
|
|
LRUCache.prototype.load = function(a0) {
|
|
this.reset();
|
|
const r16 = Date.now();
|
|
let r0 = a0.length - 1;
|
|
while (0 <= r0) {
|
|
const r18 = a0[r0];
|
|
let r9 = r18.e;
|
|
const r1 = r0;
|
|
if (!r9) {
|
|
r9 = 0;
|
|
}
|
|
if (r9 === 0) {
|
|
this.set(r18.k, r18.v);
|
|
} else {
|
|
const r12 = r9 - r16;
|
|
if (r12 > 0) {
|
|
this.set(r18.k, r18.v, r12);
|
|
}
|
|
}
|
|
r0 = r1 - 1;
|
|
}
|
|
};
|
|
LRUCache.prototype.prune = function() {
|
|
const _this3 = this;
|
|
priv(this, "cache").forEach(function(item, index) {
|
|
get2(_this3, index, false);
|
|
});
|
|
};
|