mtranserver 4.0.19 → 4.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +61 -13
- package/dist/index.js.map +3 -3
- package/dist/main.js +71 -23
- package/dist/main.js.map +5 -5
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -5865,11 +5865,11 @@ class Stack {
|
|
|
5865
5865
|
return this.heap[--this.length];
|
|
5866
5866
|
}
|
|
5867
5867
|
}
|
|
5868
|
-
var
|
|
5868
|
+
var defaultPerf, warned, PROCESS, emitWarning = (msg, type, code, fn) => {
|
|
5869
5869
|
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
5870
5870
|
}, AC, AS, shouldWarn = (code) => !warned.has(code), TYPE, isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n), getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null, ZeroArray, LRUCache;
|
|
5871
5871
|
var init_esm2 = __esm(() => {
|
|
5872
|
-
|
|
5872
|
+
defaultPerf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
5873
5873
|
warned = new Set;
|
|
5874
5874
|
PROCESS = typeof process === "object" && !!process ? process : {};
|
|
5875
5875
|
AC = globalThis.AbortController;
|
|
@@ -5919,9 +5919,14 @@ var init_esm2 = __esm(() => {
|
|
|
5919
5919
|
#max;
|
|
5920
5920
|
#maxSize;
|
|
5921
5921
|
#dispose;
|
|
5922
|
+
#onInsert;
|
|
5922
5923
|
#disposeAfter;
|
|
5923
5924
|
#fetchMethod;
|
|
5924
5925
|
#memoMethod;
|
|
5926
|
+
#perf;
|
|
5927
|
+
get perf() {
|
|
5928
|
+
return this.#perf;
|
|
5929
|
+
}
|
|
5925
5930
|
ttl;
|
|
5926
5931
|
ttlResolution;
|
|
5927
5932
|
ttlAutopurge;
|
|
@@ -5951,13 +5956,16 @@ var init_esm2 = __esm(() => {
|
|
|
5951
5956
|
#sizes;
|
|
5952
5957
|
#starts;
|
|
5953
5958
|
#ttls;
|
|
5959
|
+
#autopurgeTimers;
|
|
5954
5960
|
#hasDispose;
|
|
5955
5961
|
#hasFetchMethod;
|
|
5956
5962
|
#hasDisposeAfter;
|
|
5963
|
+
#hasOnInsert;
|
|
5957
5964
|
static unsafeExposeInternals(c) {
|
|
5958
5965
|
return {
|
|
5959
5966
|
starts: c.#starts,
|
|
5960
5967
|
ttls: c.#ttls,
|
|
5968
|
+
autopurgeTimers: c.#autopurgeTimers,
|
|
5961
5969
|
sizes: c.#sizes,
|
|
5962
5970
|
keyMap: c.#keyMap,
|
|
5963
5971
|
keyList: c.#keyList,
|
|
@@ -6000,11 +6008,20 @@ var init_esm2 = __esm(() => {
|
|
|
6000
6008
|
get dispose() {
|
|
6001
6009
|
return this.#dispose;
|
|
6002
6010
|
}
|
|
6011
|
+
get onInsert() {
|
|
6012
|
+
return this.#onInsert;
|
|
6013
|
+
}
|
|
6003
6014
|
get disposeAfter() {
|
|
6004
6015
|
return this.#disposeAfter;
|
|
6005
6016
|
}
|
|
6006
6017
|
constructor(options) {
|
|
6007
|
-
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
|
|
6018
|
+
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
|
|
6019
|
+
if (perf !== undefined) {
|
|
6020
|
+
if (typeof perf?.now !== "function") {
|
|
6021
|
+
throw new TypeError("perf option must have a now() method if specified");
|
|
6022
|
+
}
|
|
6023
|
+
}
|
|
6024
|
+
this.#perf = perf ?? defaultPerf;
|
|
6008
6025
|
if (max !== 0 && !isPosInt(max)) {
|
|
6009
6026
|
throw new TypeError("max option must be a nonnegative integer");
|
|
6010
6027
|
}
|
|
@@ -6046,6 +6063,9 @@ var init_esm2 = __esm(() => {
|
|
|
6046
6063
|
if (typeof dispose === "function") {
|
|
6047
6064
|
this.#dispose = dispose;
|
|
6048
6065
|
}
|
|
6066
|
+
if (typeof onInsert === "function") {
|
|
6067
|
+
this.#onInsert = onInsert;
|
|
6068
|
+
}
|
|
6049
6069
|
if (typeof disposeAfter === "function") {
|
|
6050
6070
|
this.#disposeAfter = disposeAfter;
|
|
6051
6071
|
this.#disposed = [];
|
|
@@ -6054,6 +6074,7 @@ var init_esm2 = __esm(() => {
|
|
|
6054
6074
|
this.#disposed = undefined;
|
|
6055
6075
|
}
|
|
6056
6076
|
this.#hasDispose = !!this.#dispose;
|
|
6077
|
+
this.#hasOnInsert = !!this.#onInsert;
|
|
6057
6078
|
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
6058
6079
|
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
6059
6080
|
this.noUpdateTTL = !!noUpdateTTL;
|
|
@@ -6105,10 +6126,16 @@ var init_esm2 = __esm(() => {
|
|
|
6105
6126
|
const starts = new ZeroArray(this.#max);
|
|
6106
6127
|
this.#ttls = ttls;
|
|
6107
6128
|
this.#starts = starts;
|
|
6108
|
-
|
|
6129
|
+
const purgeTimers = this.ttlAutopurge ? new Array(this.#max) : undefined;
|
|
6130
|
+
this.#autopurgeTimers = purgeTimers;
|
|
6131
|
+
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
|
6109
6132
|
starts[index] = ttl !== 0 ? start : 0;
|
|
6110
6133
|
ttls[index] = ttl;
|
|
6111
|
-
if (
|
|
6134
|
+
if (purgeTimers?.[index]) {
|
|
6135
|
+
clearTimeout(purgeTimers[index]);
|
|
6136
|
+
purgeTimers[index] = undefined;
|
|
6137
|
+
}
|
|
6138
|
+
if (ttl !== 0 && purgeTimers) {
|
|
6112
6139
|
const t = setTimeout(() => {
|
|
6113
6140
|
if (this.#isStale(index)) {
|
|
6114
6141
|
this.#delete(this.#keyList[index], "expire");
|
|
@@ -6117,10 +6144,11 @@ var init_esm2 = __esm(() => {
|
|
|
6117
6144
|
if (t.unref) {
|
|
6118
6145
|
t.unref();
|
|
6119
6146
|
}
|
|
6147
|
+
purgeTimers[index] = t;
|
|
6120
6148
|
}
|
|
6121
6149
|
};
|
|
6122
6150
|
this.#updateItemAge = (index) => {
|
|
6123
|
-
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
6151
|
+
starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
|
|
6124
6152
|
};
|
|
6125
6153
|
this.#statusTTL = (status, index) => {
|
|
6126
6154
|
if (ttls[index]) {
|
|
@@ -6137,7 +6165,7 @@ var init_esm2 = __esm(() => {
|
|
|
6137
6165
|
};
|
|
6138
6166
|
let cachedNow = 0;
|
|
6139
6167
|
const getNow = () => {
|
|
6140
|
-
const n = perf.now();
|
|
6168
|
+
const n = this.#perf.now();
|
|
6141
6169
|
if (this.ttlResolution > 0) {
|
|
6142
6170
|
cachedNow = n;
|
|
6143
6171
|
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
@@ -6359,7 +6387,7 @@ var init_esm2 = __esm(() => {
|
|
|
6359
6387
|
const ttl = this.#ttls[i];
|
|
6360
6388
|
const start = this.#starts[i];
|
|
6361
6389
|
if (ttl && start) {
|
|
6362
|
-
const remain = ttl - (perf.now() - start);
|
|
6390
|
+
const remain = ttl - (this.#perf.now() - start);
|
|
6363
6391
|
entry.ttl = remain;
|
|
6364
6392
|
entry.start = Date.now();
|
|
6365
6393
|
}
|
|
@@ -6380,7 +6408,7 @@ var init_esm2 = __esm(() => {
|
|
|
6380
6408
|
const entry = { value };
|
|
6381
6409
|
if (this.#ttls && this.#starts) {
|
|
6382
6410
|
entry.ttl = this.#ttls[i];
|
|
6383
|
-
const age = perf.now() - this.#starts[i];
|
|
6411
|
+
const age = this.#perf.now() - this.#starts[i];
|
|
6384
6412
|
entry.start = Math.floor(Date.now() - age);
|
|
6385
6413
|
}
|
|
6386
6414
|
if (this.#sizes) {
|
|
@@ -6395,7 +6423,7 @@ var init_esm2 = __esm(() => {
|
|
|
6395
6423
|
for (const [key, entry] of arr) {
|
|
6396
6424
|
if (entry.start) {
|
|
6397
6425
|
const age = Date.now() - entry.start;
|
|
6398
|
-
entry.start = perf.now() - age;
|
|
6426
|
+
entry.start = this.#perf.now() - age;
|
|
6399
6427
|
}
|
|
6400
6428
|
this.set(key, entry.value, entry);
|
|
6401
6429
|
}
|
|
@@ -6430,6 +6458,9 @@ var init_esm2 = __esm(() => {
|
|
|
6430
6458
|
if (status)
|
|
6431
6459
|
status.set = "add";
|
|
6432
6460
|
noUpdateTTL = false;
|
|
6461
|
+
if (this.#hasOnInsert) {
|
|
6462
|
+
this.#onInsert?.(v, k, "add");
|
|
6463
|
+
}
|
|
6433
6464
|
} else {
|
|
6434
6465
|
this.#moveToTail(index);
|
|
6435
6466
|
const oldVal = this.#valList[index];
|
|
@@ -6465,6 +6496,9 @@ var init_esm2 = __esm(() => {
|
|
|
6465
6496
|
} else if (status) {
|
|
6466
6497
|
status.set = "update";
|
|
6467
6498
|
}
|
|
6499
|
+
if (this.#hasOnInsert) {
|
|
6500
|
+
this.onInsert?.(v, k, v === oldVal ? "update" : "replace");
|
|
6501
|
+
}
|
|
6468
6502
|
}
|
|
6469
6503
|
if (ttl !== 0 && !this.#ttls) {
|
|
6470
6504
|
this.#initializeTTLTracking();
|
|
@@ -6523,6 +6557,10 @@ var init_esm2 = __esm(() => {
|
|
|
6523
6557
|
}
|
|
6524
6558
|
}
|
|
6525
6559
|
this.#removeItemSize(head);
|
|
6560
|
+
if (this.#autopurgeTimers?.[head]) {
|
|
6561
|
+
clearTimeout(this.#autopurgeTimers[head]);
|
|
6562
|
+
this.#autopurgeTimers[head] = undefined;
|
|
6563
|
+
}
|
|
6526
6564
|
if (free) {
|
|
6527
6565
|
this.#keyList[head] = undefined;
|
|
6528
6566
|
this.#valList[head] = undefined;
|
|
@@ -6605,9 +6643,10 @@ var init_esm2 = __esm(() => {
|
|
|
6605
6643
|
return fetchFail(ac.signal.reason);
|
|
6606
6644
|
}
|
|
6607
6645
|
const bf2 = p;
|
|
6608
|
-
|
|
6646
|
+
const vl = this.#valList[index];
|
|
6647
|
+
if (vl === p || ignoreAbort && updateCache && vl === undefined) {
|
|
6609
6648
|
if (v2 === undefined) {
|
|
6610
|
-
if (bf2.__staleWhileFetching) {
|
|
6649
|
+
if (bf2.__staleWhileFetching !== undefined) {
|
|
6611
6650
|
this.#valList[index] = bf2.__staleWhileFetching;
|
|
6612
6651
|
} else {
|
|
6613
6652
|
this.#delete(k, "fetch");
|
|
@@ -6856,6 +6895,10 @@ var init_esm2 = __esm(() => {
|
|
|
6856
6895
|
if (this.#size !== 0) {
|
|
6857
6896
|
const index = this.#keyMap.get(k);
|
|
6858
6897
|
if (index !== undefined) {
|
|
6898
|
+
if (this.#autopurgeTimers?.[index]) {
|
|
6899
|
+
clearTimeout(this.#autopurgeTimers?.[index]);
|
|
6900
|
+
this.#autopurgeTimers[index] = undefined;
|
|
6901
|
+
}
|
|
6859
6902
|
deleted = true;
|
|
6860
6903
|
if (this.#size === 1) {
|
|
6861
6904
|
this.#clear(reason);
|
|
@@ -6923,6 +6966,11 @@ var init_esm2 = __esm(() => {
|
|
|
6923
6966
|
if (this.#ttls && this.#starts) {
|
|
6924
6967
|
this.#ttls.fill(0);
|
|
6925
6968
|
this.#starts.fill(0);
|
|
6969
|
+
for (const t of this.#autopurgeTimers ?? []) {
|
|
6970
|
+
if (t !== undefined)
|
|
6971
|
+
clearTimeout(t);
|
|
6972
|
+
}
|
|
6973
|
+
this.#autopurgeTimers?.fill(undefined);
|
|
6926
6974
|
}
|
|
6927
6975
|
if (this.#sizes) {
|
|
6928
6976
|
this.#sizes.fill(0);
|
|
@@ -7400,5 +7448,5 @@ export {
|
|
|
7400
7448
|
MTran
|
|
7401
7449
|
};
|
|
7402
7450
|
|
|
7403
|
-
//# debugId=
|
|
7451
|
+
//# debugId=370A66A1D6D9E42264756E2164756E21
|
|
7404
7452
|
//# sourceMappingURL=index.js.map
|