@pnpm/exe 11.0.0-rc.0 → 11.0.0-rc.1

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.
Files changed (29) hide show
  1. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
  2. package/dist/node_modules/lru-cache/dist/commonjs/index.js +227 -130
  3. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
  4. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  5. package/dist/node_modules/lru-cache/dist/esm/browser/index.js +1688 -0
  6. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  7. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  8. package/dist/node_modules/lru-cache/dist/esm/index.js +227 -130
  9. package/dist/node_modules/lru-cache/dist/esm/index.min.js +1 -1
  10. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
  11. package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
  12. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  13. package/dist/node_modules/lru-cache/package.json +42 -9
  14. package/dist/node_modules/minimatch/dist/commonjs/ast.js +9 -10
  15. package/dist/node_modules/minimatch/dist/commonjs/index.js +26 -20
  16. package/dist/node_modules/minimatch/dist/commonjs/unescape.js +6 -6
  17. package/dist/node_modules/minimatch/dist/esm/ast.js +9 -10
  18. package/dist/node_modules/minimatch/dist/esm/index.js +26 -20
  19. package/dist/node_modules/minimatch/dist/esm/unescape.js +6 -6
  20. package/dist/node_modules/minimatch/package.json +14 -8
  21. package/dist/node_modules/minipass-flush/package.json +6 -3
  22. package/dist/node_modules/tinyglobby/dist/index.cjs +132 -148
  23. package/dist/node_modules/tinyglobby/dist/index.d.cts +33 -32
  24. package/dist/node_modules/tinyglobby/dist/index.d.mts +33 -32
  25. package/dist/node_modules/tinyglobby/dist/index.mjs +134 -146
  26. package/dist/node_modules/tinyglobby/package.json +10 -10
  27. package/dist/pnpm.mjs +8829 -7993
  28. package/package.json +9 -9
  29. package/dist/node_modules/minipass-flush/LICENSE +0 -15
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tracing = exports.metrics = void 0;
4
+ // simple node version that imports from node builtin
5
+ // this gets compiled to a require() commonjs-style override,
6
+ // not using top level await on a conditional dynamic import
7
+ const node_diagnostics_channel_1 = require("node:diagnostics_channel");
8
+ exports.metrics = (0, node_diagnostics_channel_1.channel)('lru-cache:metrics');
9
+ exports.tracing = (0, node_diagnostics_channel_1.tracingChannel)('lru-cache');
10
+ //# sourceMappingURL=diagnostics-channel.js.map
@@ -4,6 +4,8 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LRUCache = void 0;
7
+ const diagnostics_channel_js_1 = require("./diagnostics-channel.js");
8
+ const hasSubscribers = () => diagnostics_channel_js_1.metrics.hasSubscribers || diagnostics_channel_js_1.tracing.hasSubscribers;
7
9
  const defaultPerf = (typeof performance === 'object' &&
8
10
  performance &&
9
11
  typeof performance.now === 'function') ?
@@ -14,65 +16,19 @@ const warned = new Set();
14
16
  const PROCESS = (typeof process === 'object' && !!process ?
15
17
  process
16
18
  : {});
17
- /* c8 ignore start */
19
+ /* c8 ignore stop */
18
20
  const emitWarning = (msg, type, code, fn) => {
19
- typeof PROCESS.emitWarning === 'function' ?
20
- PROCESS.emitWarning(msg, type, code, fn)
21
- : console.error(`[${code}] ${type}: ${msg}`);
21
+ if (typeof PROCESS.emitWarning === 'function') {
22
+ PROCESS.emitWarning(msg, type, code, fn);
23
+ }
24
+ else {
25
+ //oxlint-disable-next-line no-console
26
+ console.error(`[${code}] ${type}: ${msg}`);
27
+ }
22
28
  };
23
- let AC = globalThis.AbortController;
24
- let AS = globalThis.AbortSignal;
25
- /* c8 ignore start */
26
- if (typeof AC === 'undefined') {
27
- //@ts-ignore
28
- AS = class AbortSignal {
29
- onabort;
30
- _onabort = [];
31
- reason;
32
- aborted = false;
33
- addEventListener(_, fn) {
34
- this._onabort.push(fn);
35
- }
36
- };
37
- //@ts-ignore
38
- AC = class AbortController {
39
- constructor() {
40
- warnACPolyfill();
41
- }
42
- signal = new AS();
43
- abort(reason) {
44
- if (this.signal.aborted)
45
- return;
46
- //@ts-ignore
47
- this.signal.reason = reason;
48
- //@ts-ignore
49
- this.signal.aborted = true;
50
- //@ts-ignore
51
- for (const fn of this.signal._onabort) {
52
- fn(reason);
53
- }
54
- this.signal.onabort?.(reason);
55
- }
56
- };
57
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
58
- const warnACPolyfill = () => {
59
- if (!printACPolyfillWarning)
60
- return;
61
- printACPolyfillWarning = false;
62
- emitWarning('AbortController is not defined. If using lru-cache in ' +
63
- 'node 14, load an AbortController polyfill from the ' +
64
- '`node-abort-controller` package. A minimal polyfill is ' +
65
- 'provided for use by LRUCache.fetch(), but it should not be ' +
66
- 'relied upon in other contexts (eg, passing it to other APIs that ' +
67
- 'use AbortController/AbortSignal might have undesirable effects). ' +
68
- 'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);
69
- };
70
- }
71
- /* c8 ignore stop */
72
29
  const shouldWarn = (code) => !warned.has(code);
73
30
  const TYPE = Symbol('type');
74
- const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
75
- /* c8 ignore start */
31
+ const isPosInt = (n) => !!n && n === Math.floor(n) && n > 0 && isFinite(n);
76
32
  // This is a little bit ridiculous, tbh.
77
33
  // The maximum array length is 2^32-1 or thereabouts on most JS impls.
78
34
  // And well before that point, you're caching the entire world, I mean,
@@ -81,6 +37,7 @@ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
81
37
  // zeroes at init time is brutal when you get that big.
82
38
  // But why not be complete?
83
39
  // Maybe in the future, these limits will have expanded.
40
+ /* c8 ignore start */
84
41
  const getUintArray = (max) => !isPosInt(max) ? null
85
42
  : max <= Math.pow(2, 8) ? Uint8Array
86
43
  : max <= Math.pow(2, 16) ? Uint16Array
@@ -361,8 +318,8 @@ class LRUCache {
361
318
  this.#fetchMethod = fetchMethod;
362
319
  this.#hasFetchMethod = !!fetchMethod;
363
320
  this.#keyMap = new Map();
364
- this.#keyList = new Array(max).fill(undefined);
365
- this.#valList = new Array(max).fill(undefined);
321
+ this.#keyList = Array.from({ length: max }).fill(undefined);
322
+ this.#valList = Array.from({ length: max }).fill(undefined);
366
323
  this.#next = new UintArray(max);
367
324
  this.#prev = new UintArray(max);
368
325
  this.#head = 0;
@@ -446,7 +403,9 @@ class LRUCache {
446
403
  this.#ttls = ttls;
447
404
  this.#starts = starts;
448
405
  const purgeTimers = this.ttlAutopurge ?
449
- new Array(this.#max)
406
+ Array.from({
407
+ length: this.#max,
408
+ })
450
409
  : undefined;
451
410
  this.#autopurgeTimers = purgeTimers;
452
411
  this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
@@ -488,9 +447,11 @@ class LRUCache {
488
447
  if (ttls[index]) {
489
448
  const ttl = ttls[index];
490
449
  const start = starts[index];
491
- /* c8 ignore next */
492
- if (!ttl || !start)
450
+ /* c8 ignore start */
451
+ if (!ttl || !start) {
493
452
  return;
453
+ }
454
+ /* c8 ignore stop */
494
455
  status.ttl = ttl;
495
456
  status.start = start;
496
457
  status.now = cachedNow || getNow();
@@ -597,10 +558,7 @@ class LRUCache {
597
558
  };
598
559
  *#indexes({ allowStale = this.allowStale } = {}) {
599
560
  if (this.#size) {
600
- for (let i = this.#tail; true;) {
601
- if (!this.#isValidIndex(i)) {
602
- break;
603
- }
561
+ for (let i = this.#tail; this.#isValidIndex(i);) {
604
562
  if (allowStale || !this.#isStale(i)) {
605
563
  yield i;
606
564
  }
@@ -615,10 +573,7 @@ class LRUCache {
615
573
  }
616
574
  *#rindexes({ allowStale = this.allowStale } = {}) {
617
575
  if (this.#size) {
618
- for (let i = this.#head; true;) {
619
- if (!this.#isValidIndex(i)) {
620
- break;
621
- }
576
+ for (let i = this.#head; this.#isValidIndex(i);) {
622
577
  if (allowStale || !this.#isStale(i)) {
623
578
  yield i;
624
579
  }
@@ -739,7 +694,7 @@ class LRUCache {
739
694
  if (value === undefined)
740
695
  continue;
741
696
  if (fn(value, this.#keyList[i], this)) {
742
- return this.get(this.#keyList[i], getOptions);
697
+ return this.#get(this.#keyList[i], getOptions);
743
698
  }
744
699
  }
745
700
  }
@@ -812,7 +767,7 @@ class LRUCache {
812
767
  const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
813
768
  if (value === undefined)
814
769
  return undefined;
815
- /* c8 ignore end */
770
+ /* c8 ignore stop */
816
771
  const entry = { value };
817
772
  if (this.#ttls && this.#starts) {
818
773
  const ttl = this.#ttls[i];
@@ -886,7 +841,7 @@ class LRUCache {
886
841
  const age = Date.now() - entry.start;
887
842
  entry.start = this.#perf.now() - age;
888
843
  }
889
- this.set(key, entry.value, entry);
844
+ this.#set(key, entry.value, entry);
890
845
  }
891
846
  }
892
847
  /**
@@ -920,22 +875,41 @@ class LRUCache {
920
875
  * `cache.delete(key)`. `undefined` is never stored in the cache.
921
876
  */
922
877
  set(k, v, setOptions = {}) {
878
+ const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = setOptions;
879
+ setOptions.status = status;
880
+ if (status) {
881
+ status.op = 'set';
882
+ status.key = k;
883
+ if (v !== undefined)
884
+ status.value = v;
885
+ }
886
+ const result = this.#set(k, v, setOptions);
887
+ if (status && diagnostics_channel_js_1.metrics.hasSubscribers) {
888
+ diagnostics_channel_js_1.metrics.publish(status);
889
+ }
890
+ return result;
891
+ }
892
+ #set(k, v, setOptions = {}) {
893
+ const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
923
894
  if (v === undefined) {
895
+ if (status)
896
+ status.set = 'deleted';
924
897
  this.delete(k);
925
898
  return this;
926
899
  }
927
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
928
900
  let { noUpdateTTL = this.noUpdateTTL } = setOptions;
929
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
901
+ if (status && !this.#isBackgroundFetch(v))
902
+ status.value = v;
903
+ const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation, status);
930
904
  // if the item doesn't fit, don't do anything
931
905
  // NB: maxEntrySize set to maxSize by default
932
906
  if (this.maxEntrySize && size > this.maxEntrySize) {
907
+ // have to delete, in case something is there already.
908
+ this.#delete(k, 'set');
933
909
  if (status) {
934
910
  status.set = 'miss';
935
911
  status.maxEntrySizeExceeded = true;
936
912
  }
937
- // have to delete, in case something is there already.
938
- this.#delete(k, 'set');
939
913
  return this;
940
914
  }
941
915
  let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
@@ -1106,6 +1080,18 @@ class LRUCache {
1106
1080
  * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
1107
1081
  */
1108
1082
  has(k, hasOptions = {}) {
1083
+ const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = hasOptions;
1084
+ hasOptions.status = status;
1085
+ if (status) {
1086
+ status.op = 'has';
1087
+ status.key = k;
1088
+ }
1089
+ const result = this.#has(k, hasOptions);
1090
+ if (diagnostics_channel_js_1.metrics.hasSubscribers)
1091
+ diagnostics_channel_js_1.metrics.publish(status);
1092
+ return result;
1093
+ }
1094
+ #has(k, hasOptions = {}) {
1109
1095
  const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
1110
1096
  const index = this.#keyMap.get(k);
1111
1097
  if (index !== undefined) {
@@ -1142,21 +1128,45 @@ class LRUCache {
1142
1128
  * {@link LRUCache.OptionsBase.allowStale} is set.
1143
1129
  */
1144
1130
  peek(k, peekOptions = {}) {
1145
- const { allowStale = this.allowStale } = peekOptions;
1131
+ const { status = hasSubscribers() ? {} : undefined } = peekOptions;
1132
+ if (status) {
1133
+ status.op = 'peek';
1134
+ status.key = k;
1135
+ }
1136
+ peekOptions.status = status;
1137
+ const result = this.#peek(k, peekOptions);
1138
+ if (diagnostics_channel_js_1.metrics.hasSubscribers) {
1139
+ diagnostics_channel_js_1.metrics.publish(status);
1140
+ }
1141
+ return result;
1142
+ }
1143
+ #peek(k, peekOptions) {
1144
+ const { status, allowStale = this.allowStale } = peekOptions;
1146
1145
  const index = this.#keyMap.get(k);
1147
1146
  if (index === undefined || (!allowStale && this.#isStale(index))) {
1148
- return;
1147
+ if (status)
1148
+ status.peek = index === undefined ? 'miss' : 'stale';
1149
+ return undefined;
1149
1150
  }
1150
1151
  const v = this.#valList[index];
1151
- // either stale and allowed, or forcing a refresh of non-stale value
1152
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
1152
+ const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
1153
+ if (status) {
1154
+ if (val !== undefined) {
1155
+ status.peek = 'hit';
1156
+ status.value = val;
1157
+ }
1158
+ else {
1159
+ status.peek = 'miss';
1160
+ }
1161
+ }
1162
+ return val;
1153
1163
  }
1154
1164
  #backgroundFetch(k, index, options, context) {
1155
1165
  const v = index === undefined ? undefined : this.#valList[index];
1156
1166
  if (this.#isBackgroundFetch(v)) {
1157
1167
  return v;
1158
1168
  }
1159
- const ac = new AC();
1169
+ const ac = new AbortController();
1160
1170
  const { signal } = options;
1161
1171
  // when/if our AC signals, then stop listening to theirs.
1162
1172
  signal?.addEventListener('abort', () => ac.abort(signal.reason), {
@@ -1192,7 +1202,7 @@ class LRUCache {
1192
1202
  // cache and ignore the abort, or if it's still pending on this specific
1193
1203
  // background request, then write it to the cache.
1194
1204
  const vl = this.#valList[index];
1195
- if (vl === p || (ignoreAbort && updateCache && vl === undefined)) {
1205
+ if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
1196
1206
  if (v === undefined) {
1197
1207
  if (bf.__staleWhileFetching !== undefined) {
1198
1208
  this.#valList[index] = bf.__staleWhileFetching;
@@ -1204,7 +1214,7 @@ class LRUCache {
1204
1214
  else {
1205
1215
  if (options.status)
1206
1216
  options.status.fetchUpdated = true;
1207
- this.set(k, v, fetchOpts.options);
1217
+ this.#set(k, v, fetchOpts.options);
1208
1218
  }
1209
1219
  }
1210
1220
  return v;
@@ -1276,7 +1286,7 @@ class LRUCache {
1276
1286
  });
1277
1287
  if (index === undefined) {
1278
1288
  // internal, don't expose status.
1279
- this.set(k, bf, { ...fetchOpts.options, status: undefined });
1289
+ this.#set(k, bf, { ...fetchOpts.options, status: undefined });
1280
1290
  index = this.#keyMap.get(k);
1281
1291
  }
1282
1292
  else {
@@ -1291,9 +1301,25 @@ class LRUCache {
1291
1301
  return (!!b &&
1292
1302
  b instanceof Promise &&
1293
1303
  b.hasOwnProperty('__staleWhileFetching') &&
1294
- b.__abortController instanceof AC);
1304
+ b.__abortController instanceof AbortController);
1305
+ }
1306
+ fetch(k, fetchOptions = {}) {
1307
+ const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
1308
+ const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
1309
+ fetchOptions.status = status;
1310
+ if (status && fetchOptions.context) {
1311
+ status.context = fetchOptions.context;
1312
+ }
1313
+ const p = this.#fetch(k, fetchOptions);
1314
+ if (status && hasSubscribers()) {
1315
+ if (ths) {
1316
+ status.trace = true;
1317
+ diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
1318
+ }
1319
+ }
1320
+ return p;
1295
1321
  }
1296
- async fetch(k, fetchOptions = {}) {
1322
+ async #fetch(k, fetchOptions = {}) {
1297
1323
  const {
1298
1324
  // get options
1299
1325
  allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
@@ -1301,10 +1327,16 @@ class LRUCache {
1301
1327
  ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
1302
1328
  // fetch exclusive options
1303
1329
  noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
1330
+ if (status) {
1331
+ status.op = 'fetch';
1332
+ status.key = k;
1333
+ if (forceRefresh)
1334
+ status.forceRefresh = true;
1335
+ }
1304
1336
  if (!this.#hasFetchMethod) {
1305
1337
  if (status)
1306
1338
  status.fetch = 'get';
1307
- return this.get(k, {
1339
+ return this.#get(k, {
1308
1340
  allowStale,
1309
1341
  updateAgeOnGet,
1310
1342
  noDeleteOnStaleGet,
@@ -1373,26 +1405,69 @@ class LRUCache {
1373
1405
  return staleVal ? p.__staleWhileFetching : (p.__returned = p);
1374
1406
  }
1375
1407
  }
1376
- async forceFetch(k, fetchOptions = {}) {
1377
- const v = await this.fetch(k, fetchOptions);
1408
+ forceFetch(k, fetchOptions = {}) {
1409
+ const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
1410
+ const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
1411
+ fetchOptions.status = status;
1412
+ if (status && fetchOptions.context) {
1413
+ status.context = fetchOptions.context;
1414
+ }
1415
+ const p = this.#forceFetch(k, fetchOptions);
1416
+ if (status && hasSubscribers()) {
1417
+ if (ths) {
1418
+ status.trace = true;
1419
+ diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
1420
+ }
1421
+ }
1422
+ return p;
1423
+ }
1424
+ async #forceFetch(k, fetchOptions = {}) {
1425
+ const v = await this.#fetch(k, fetchOptions);
1378
1426
  if (v === undefined)
1379
1427
  throw new Error('fetch() returned undefined');
1380
1428
  return v;
1381
1429
  }
1382
1430
  memo(k, memoOptions = {}) {
1431
+ const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = memoOptions;
1432
+ memoOptions.status = status;
1433
+ if (status) {
1434
+ status.op = 'memo';
1435
+ status.key = k;
1436
+ if (memoOptions.context) {
1437
+ status.context = memoOptions.context;
1438
+ }
1439
+ }
1440
+ const result = this.#memo(k, memoOptions);
1441
+ if (status)
1442
+ status.value = result;
1443
+ if (diagnostics_channel_js_1.metrics.hasSubscribers)
1444
+ diagnostics_channel_js_1.metrics.publish(status);
1445
+ return result;
1446
+ }
1447
+ #memo(k, memoOptions = {}) {
1383
1448
  const memoMethod = this.#memoMethod;
1384
1449
  if (!memoMethod) {
1385
1450
  throw new Error('no memoMethod provided to constructor');
1386
1451
  }
1387
- const { context, forceRefresh, ...options } = memoOptions;
1388
- const v = this.get(k, options);
1389
- if (!forceRefresh && v !== undefined)
1452
+ const { context, status, forceRefresh, ...options } = memoOptions;
1453
+ if (status && forceRefresh)
1454
+ status.forceRefresh = true;
1455
+ const v = this.#get(k, options);
1456
+ const refresh = forceRefresh || v === undefined;
1457
+ if (status) {
1458
+ status.memo = refresh ? 'miss' : 'hit';
1459
+ if (!refresh)
1460
+ status.value = v;
1461
+ }
1462
+ if (!refresh)
1390
1463
  return v;
1391
1464
  const vv = memoMethod(k, v, {
1392
1465
  options,
1393
1466
  context,
1394
1467
  });
1395
- this.set(k, vv, options);
1468
+ if (status)
1469
+ status.value = vv;
1470
+ this.#set(k, vv, options);
1396
1471
  return vv;
1397
1472
  }
1398
1473
  /**
@@ -1402,55 +1477,70 @@ class LRUCache {
1402
1477
  * If the key is not found, get() will return `undefined`.
1403
1478
  */
1404
1479
  get(k, getOptions = {}) {
1480
+ const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = getOptions;
1481
+ getOptions.status = status;
1482
+ if (status) {
1483
+ status.op = 'get';
1484
+ status.key = k;
1485
+ }
1486
+ const result = this.#get(k, getOptions);
1487
+ if (status) {
1488
+ if (result !== undefined)
1489
+ status.value = result;
1490
+ if (diagnostics_channel_js_1.metrics.hasSubscribers)
1491
+ diagnostics_channel_js_1.metrics.publish(status);
1492
+ }
1493
+ return result;
1494
+ }
1495
+ #get(k, getOptions = {}) {
1405
1496
  const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
1406
1497
  const index = this.#keyMap.get(k);
1407
- if (index !== undefined) {
1408
- const value = this.#valList[index];
1409
- const fetching = this.#isBackgroundFetch(value);
1498
+ if (index === undefined) {
1410
1499
  if (status)
1411
- this.#statusTTL(status, index);
1412
- if (this.#isStale(index)) {
1500
+ status.get = 'miss';
1501
+ return undefined;
1502
+ }
1503
+ const value = this.#valList[index];
1504
+ const fetching = this.#isBackgroundFetch(value);
1505
+ if (status)
1506
+ this.#statusTTL(status, index);
1507
+ if (this.#isStale(index)) {
1508
+ // delete only if not an in-flight background fetch
1509
+ if (!fetching) {
1510
+ if (!noDeleteOnStaleGet) {
1511
+ this.#delete(k, 'expire');
1512
+ }
1413
1513
  if (status)
1414
1514
  status.get = 'stale';
1415
- // delete only if not an in-flight background fetch
1416
- if (!fetching) {
1417
- if (!noDeleteOnStaleGet) {
1418
- this.#delete(k, 'expire');
1419
- }
1420
- if (status && allowStale)
1515
+ if (allowStale) {
1516
+ if (status)
1421
1517
  status.returnedStale = true;
1422
- return allowStale ? value : undefined;
1423
- }
1424
- else {
1425
- if (status &&
1426
- allowStale &&
1427
- value.__staleWhileFetching !== undefined) {
1428
- status.returnedStale = true;
1429
- }
1430
- return allowStale ? value.__staleWhileFetching : undefined;
1518
+ return value;
1431
1519
  }
1520
+ return undefined;
1432
1521
  }
1433
- else {
1522
+ if (status)
1523
+ status.get = 'stale-fetching';
1524
+ if (allowStale && value.__staleWhileFetching !== undefined) {
1434
1525
  if (status)
1435
- status.get = 'hit';
1436
- // if we're currently fetching it, we don't actually have it yet
1437
- // it's not stale, which means this isn't a staleWhileRefetching.
1438
- // If it's not stale, and fetching, AND has a __staleWhileFetching
1439
- // value, then that means the user fetched with {forceRefresh:true},
1440
- // so it's safe to return that value.
1441
- if (fetching) {
1442
- return value.__staleWhileFetching;
1443
- }
1444
- this.#moveToTail(index);
1445
- if (updateAgeOnGet) {
1446
- this.#updateItemAge(index);
1447
- }
1448
- return value;
1526
+ status.returnedStale = true;
1527
+ return value.__staleWhileFetching;
1449
1528
  }
1529
+ return undefined;
1450
1530
  }
1451
- else if (status) {
1452
- status.get = 'miss';
1453
- }
1531
+ // not stale
1532
+ if (status)
1533
+ status.get = fetching ? 'fetching' : 'hit';
1534
+ // if we're currently fetching it, we don't actually have it yet
1535
+ // it's not stale, which means this isn't a staleWhileRefetching.
1536
+ // If it's not stale, and fetching, AND has a __staleWhileFetching
1537
+ // value, then that means the user fetched with {forceRefresh:true},
1538
+ // so it's safe to return that value.
1539
+ this.#moveToTail(index);
1540
+ if (updateAgeOnGet) {
1541
+ this.#updateItemAge(index);
1542
+ }
1543
+ return fetching ? value.__staleWhileFetching : value;
1454
1544
  }
1455
1545
  #connect(p, n) {
1456
1546
  this.#prev[n] = p;
@@ -1485,6 +1575,13 @@ class LRUCache {
1485
1575
  return this.#delete(k, 'delete');
1486
1576
  }
1487
1577
  #delete(k, reason) {
1578
+ if (diagnostics_channel_js_1.metrics.hasSubscribers) {
1579
+ diagnostics_channel_js_1.metrics.publish({
1580
+ op: 'delete',
1581
+ delete: reason,
1582
+ key: k,
1583
+ });
1584
+ }
1488
1585
  let deleted = false;
1489
1586
  if (this.#size !== 0) {
1490
1587
  const index = this.#keyMap.get(k);
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var G=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,U=new Set,R=typeof process=="object"&&process?process:{},I=(c,t,e,i)=>{typeof R.emitWarning=="function"?R.emitWarning(c,t,e,i):console.error(`[${e}] ${t}: ${c}`)},C=globalThis.AbortController,L=globalThis.AbortSignal;if(typeof C>"u"){L=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(i,s){this._onabort.push(s)}},C=class{constructor(){t()}signal=new L;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=!0;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i)}}};let c=R.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{c&&(c=!1,I("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t))}}var x=c=>!U.has(c),H=Symbol("type"),y=c=>c&&c===Math.floor(c)&&c>0&&isFinite(c),M=c=>y(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?z:null:null,z=class extends Array{constructor(t){super(t),this.fill(0)}},W=class c{heap;length;static#o=!1;static create(t){let e=M(t);if(!e)return[];c.#o=!0;let i=new c(t,e);return c.#o=!1,i}constructor(t,e){if(!c.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},D=class c{#o;#c;#w;#C;#S;#L;#U;#m;get perf(){return this.#m}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#_;#s;#i;#t;#a;#u;#l;#h;#b;#r;#y;#A;#d;#g;#T;#v;#f;#I;static unsafeExposeInternals(t){return{starts:t.#A,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#y,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#a,prev:t.#u,get head(){return t.#l},get tail(){return t.#h},free:t.#b,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#x(e,i,s,n),moveToTail:e=>t.#D(e),indexes:e=>t.#F(e),rindexes:e=>t.#O(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#_}get size(){return this.#n}get fetchMethod(){return this.#L}get memoMethod(){return this.#U}get dispose(){return this.#w}get onInsert(){return this.#C}get disposeAfter(){return this.#S}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:h,allowStale:r,dispose:a,onInsert:w,disposeAfter:f,noDisposeOnSet:d,noUpdateTTL:g,maxSize:A=0,maxEntrySize:p=0,sizeCalculation:_,fetchMethod:l,memoMethod:S,noDeleteOnFetchRejection:b,noDeleteOnStaleGet:m,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:T,ignoreFetchAbort:F,perf:v}=t;if(v!==void 0&&typeof v?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#m=v??G,e!==0&&!y(e))throw new TypeError("max option must be a nonnegative integer");let O=e?M(e):Array;if(!O)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=A,this.maxEntrySize=p||this.#c,this.sizeCalculation=_,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(S!==void 0&&typeof S!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#U=S,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#L=l,this.#v=!!l,this.#s=new Map,this.#i=new Array(e).fill(void 0),this.#t=new Array(e).fill(void 0),this.#a=new O(e),this.#u=new O(e),this.#l=0,this.#h=0,this.#b=W.create(e),this.#n=0,this.#_=0,typeof a=="function"&&(this.#w=a),typeof w=="function"&&(this.#C=w),typeof f=="function"?(this.#S=f,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#w,this.#I=!!this.#C,this.#f=!!this.#S,this.noDisposeOnSet=!!d,this.noUpdateTTL=!!g,this.noDeleteOnFetchRejection=!!b,this.allowStaleOnFetchRejection=!!u,this.allowStaleOnFetchAbort=!!T,this.ignoreFetchAbort=!!F,this.maxEntrySize!==0){if(this.#c!==0&&!y(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!y(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#B()}if(this.allowStale=!!r,this.noDeleteOnStaleGet=!!m,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h,this.ttlResolution=y(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!y(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#j()}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let E="LRU_CACHE_UNBOUNDED";x(E)&&(U.add(E),I("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",E,c))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#j(){let t=new z(this.#o),e=new z(this.#o);this.#d=t,this.#A=e;let i=this.ttlAutopurge?new Array(this.#o):void 0;this.#g=i,this.#N=(h,r,a=this.#m.now())=>{e[h]=r!==0?a:0,t[h]=r,s(h,r)},this.#R=h=>{e[h]=t[h]!==0?this.#m.now():0,s(h,t[h])};let s=this.ttlAutopurge?(h,r)=>{if(i?.[h]&&(clearTimeout(i[h]),i[h]=void 0),r&&r!==0&&i){let a=setTimeout(()=>{this.#p(h)&&this.#E(this.#i[h],"expire")},r+1);a.unref&&a.unref(),i[h]=a}}:()=>{};this.#z=(h,r)=>{if(t[r]){let a=t[r],w=e[r];if(!a||!w)return;h.ttl=a,h.start=w,h.now=n||o();let f=h.now-w;h.remainingTTL=a-f}};let n=0,o=()=>{let h=this.#m.now();if(this.ttlResolution>0){n=h;let r=setTimeout(()=>n=0,this.ttlResolution);r.unref&&r.unref()}return h};this.getRemainingTTL=h=>{let r=this.#s.get(h);if(r===void 0)return 0;let a=t[r],w=e[r];if(!a||!w)return 1/0;let f=(n||o())-w;return a-f},this.#p=h=>{let r=e[h],a=t[h];return!!a&&!!r&&(n||o())-r>a}}#R=()=>{};#z=()=>{};#N=()=>{};#p=()=>!1;#B(){let t=new z(this.#o);this.#_=0,this.#y=t,this.#W=e=>{this.#_-=t[e],t[e]=0},this.#P=(e,i,s,n)=>{if(this.#e(i))return 0;if(!y(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!y(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#M=(e,i,s)=>{if(t[e]=i,this.#c){let n=this.#c-t[e];for(;this.#_>n;)this.#G(!0)}this.#_+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#_)}}#W=t=>{};#M=(t,e,i)=>{};#P=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#F({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#l));)e=this.#u[e]}*#O({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#l;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#h));)e=this.#a[e]}#H(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#F())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#O())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#F()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#O()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#F())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#O())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#F()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.get(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#F()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#O()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#O({allowStale:!0}))this.#p(e)&&(this.#E(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#A){let o=this.#d[e],h=this.#A[e];if(o&&h){let r=o-(this.#m.now()-h);n.ttl=r,n.start=Date.now()}}return this.#y&&(n.size=this.#y[e]),n}dump(){let t=[];for(let e of this.#F({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let o={value:n};if(this.#d&&this.#A){o.ttl=this.#d[e];let h=this.#m.now()-this.#A[e];o.start=Math.floor(Date.now()-h)}this.#y&&(o.size=this.#y[e]),t.unshift([i,o])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#m.now()-s}this.set(e,i.value,i)}}set(t,e,i={}){if(e===void 0)return this.delete(t),this;let{ttl:s=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:r}=i,{noUpdateTTL:a=this.noUpdateTTL}=i,w=this.#P(t,e,i.size||0,h);if(this.maxEntrySize&&w>this.maxEntrySize)return r&&(r.set="miss",r.maxEntrySizeExceeded=!0),this.#E(t,"set"),this;let f=this.#n===0?void 0:this.#s.get(t);if(f===void 0)f=this.#n===0?this.#h:this.#b.length!==0?this.#b.pop():this.#n===this.#o?this.#G(!1):this.#n,this.#i[f]=t,this.#t[f]=e,this.#s.set(t,f),this.#a[this.#h]=f,this.#u[f]=this.#h,this.#h=f,this.#n++,this.#M(f,w,r),r&&(r.set="add"),a=!1,this.#I&&this.#C?.(e,t,"add");else{this.#D(f);let d=this.#t[f];if(e!==d){if(this.#v&&this.#e(d)){d.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:g}=d;g!==void 0&&!o&&(this.#T&&this.#w?.(g,t,"set"),this.#f&&this.#r?.push([g,t,"set"]))}else o||(this.#T&&this.#w?.(d,t,"set"),this.#f&&this.#r?.push([d,t,"set"]));if(this.#W(f),this.#M(f,w,r),this.#t[f]=e,r){r.set="replace";let g=d&&this.#e(d)?d.__staleWhileFetching:d;g!==void 0&&(r.oldValue=g)}}else r&&(r.set="update");this.#I&&this.onInsert?.(e,t,e===d?"update":"replace")}if(s!==0&&!this.#d&&this.#j(),this.#d&&(a||this.#N(f,s,n),r&&this.#z(r,f)),!o&&this.#f&&this.#r){let d=this.#r,g;for(;g=d?.shift();)this.#S?.(...g)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#l];if(this.#G(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#S?.(...e)}}}#G(t){let e=this.#l,i=this.#i[e],s=this.#t[e];return this.#v&&this.#e(s)?s.__abortController.abort(new Error("evicted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(s,i,"evict"),this.#f&&this.#r?.push([s,i,"evict"])),this.#W(e),this.#g?.[e]&&(clearTimeout(this.#g[e]),this.#g[e]=void 0),t&&(this.#i[e]=void 0,this.#t[e]=void 0,this.#b.push(e)),this.#n===1?(this.#l=this.#h=0,this.#b.length=0):this.#l=this.#a[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let o=this.#t[n];if(this.#e(o)&&o.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#z(s,n));else return i&&this.#R(n),s&&(s.has="hit",this.#z(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{allowStale:i=this.allowStale}=e,s=this.#s.get(t);if(s===void 0||!i&&this.#p(s))return;let n=this.#t[s];return this.#e(n)?n.__staleWhileFetching:n}#x(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let o=new C,{signal:h}=i;h?.addEventListener("abort",()=>o.abort(h.reason),{signal:o.signal});let r={signal:o.signal,options:i,context:s},a=(p,_=!1)=>{let{aborted:l}=o.signal,S=i.ignoreFetchAbort&&p!==void 0,b=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&p!==void 0);if(i.status&&(l&&!_?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,S&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),l&&!S&&!_)return f(o.signal.reason,b);let m=g,u=this.#t[e];return(u===g||S&&_&&u===void 0)&&(p===void 0?m.__staleWhileFetching!==void 0?this.#t[e]=m.__staleWhileFetching:this.#E(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.set(t,p,r.options))),p},w=p=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=p),f(p,!1)),f=(p,_)=>{let{aborted:l}=o.signal,S=l&&i.allowStaleOnFetchAbort,b=S||i.allowStaleOnFetchRejection,m=b||i.noDeleteOnFetchRejection,u=g;if(this.#t[e]===g&&(!m||!_&&u.__staleWhileFetching===void 0?this.#E(t,"fetch"):S||(this.#t[e]=u.__staleWhileFetching)),b)return i.status&&u.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),u.__staleWhileFetching;if(u.__returned===u)throw p},d=(p,_)=>{let l=this.#L?.(t,n,r);l&&l instanceof Promise&&l.then(S=>p(S===void 0?void 0:S),_),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(p(void 0),i.allowStaleOnFetchAbort&&(p=S=>a(S,!0)))})};i.status&&(i.status.fetchDispatched=!0);let g=new Promise(d).then(a,w),A=Object.assign(g,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.set(t,A,{...r.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=A,A}#e(t){if(!this.#v)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof C}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:r=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:w=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:A=this.allowStaleOnFetchAbort,context:p,forceRefresh:_=!1,status:l,signal:S}=e;if(!this.#v)return l&&(l.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:l});let b={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:h,size:r,sizeCalculation:a,noUpdateTTL:w,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:A,ignoreFetchAbort:g,status:l,signal:S},m=this.#s.get(t);if(m===void 0){l&&(l.fetch="miss");let u=this.#x(t,m,b,p);return u.__returned=u}else{let u=this.#t[m];if(this.#e(u)){let E=i&&u.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=!0)),E?u.__staleWhileFetching:u.__returned=u}let T=this.#p(m);if(!_&&!T)return l&&(l.fetch="hit"),this.#D(m),s&&this.#R(m),l&&this.#z(l,m),u;let F=this.#x(t,m,b,p),O=F.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=T?"stale":"refresh",O&&T&&(l.returnedStale=!0)),O?F.__staleWhileFetching:F.__returned=F}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=this.#U;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,forceRefresh:n,...o}=e,h=this.get(t,o);if(!n&&h!==void 0)return h;let r=i(t,h,{options:o,context:s});return this.set(t,r,o),r}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=e,h=this.#s.get(t);if(h!==void 0){let r=this.#t[h],a=this.#e(r);return o&&this.#z(o,h),this.#p(h)?(o&&(o.get="stale"),a?(o&&i&&r.__staleWhileFetching!==void 0&&(o.returnedStale=!0),i?r.__staleWhileFetching:void 0):(n||this.#E(t,"expire"),o&&i&&(o.returnedStale=!0),i?r:void 0)):(o&&(o.get="hit"),a?r.__staleWhileFetching:(this.#D(h),s&&this.#R(h),r))}else o&&(o.get="miss")}#k(t,e){this.#u[e]=t,this.#a[t]=e}#D(t){t!==this.#h&&(t===this.#l?this.#l=this.#a[t]:this.#k(this.#u[t],this.#a[t]),this.#k(this.#h,t),this.#h=t)}delete(t){return this.#E(t,"delete")}#E(t,e){let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#V(e);else{this.#W(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(n,t,e),this.#f&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#l)this.#l=this.#a[s];else{let o=this.#u[s];this.#a[o]=this.#a[s];let h=this.#a[s];this.#u[h]=this.#u[s]}this.#n--,this.#b.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#S?.(...n)}return i}clear(){return this.#V("delete")}#V(t){for(let e of this.#O({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#T&&this.#w?.(i,s,t),this.#f&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#A){this.#d.fill(0),this.#A.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0)}if(this.#y&&this.#y.fill(0),this.#l=0,this.#h=0,this.#b.length=0,this.#_=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#S?.(...i)}}};exports.LRUCache=D;
1
+ "use strict";var G=(c,t)=>()=>(t||c((t={exports:{}}).exports,t),t.exports);var M=G(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.tracing=O.metrics=void 0;var L=require("node:diagnostics_channel");O.metrics=(0,L.channel)("lru-cache:metrics");O.tracing=(0,L.tracingChannel)("lru-cache")});Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var u=M(),D=()=>u.metrics.hasSubscribers||u.tracing.hasSubscribers,P=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,U=new Set,j=typeof process=="object"&&process?process:{},H=(c,t,e,i)=>{typeof j.emitWarning=="function"?j.emitWarning(c,t,e,i):console.error(`[${e}] ${t}: ${c}`)},N=c=>!U.has(c),B=Symbol("type"),F=c=>!!c&&c===Math.floor(c)&&c>0&&isFinite(c),I=c=>F(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?W:null:null,W=class extends Array{constructor(t){super(t),this.fill(0)}},C=class c{heap;length;static#o=!1;static create(t){let e=I(t);if(!e)return[];c.#o=!0;let i=new c(t,e);return c.#o=!1,i}constructor(t,e){if(!c.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},x=class c{#o;#c;#m;#D;#w;#M;#j;#S;get perf(){return this.#S}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#b;#s;#i;#t;#l;#u;#a;#h;#y;#r;#_;#F;#d;#g;#T;#O;#f;#U;static unsafeExposeInternals(t){return{starts:t.#F,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#_,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#l,prev:t.#u,get head(){return t.#a},get tail(){return t.#h},free:t.#y,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#P(e,i,s,n),moveToTail:e=>t.#L(e),indexes:e=>t.#A(e),rindexes:e=>t.#v(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#b}get size(){return this.#n}get fetchMethod(){return this.#M}get memoMethod(){return this.#j}get dispose(){return this.#m}get onInsert(){return this.#D}get disposeAfter(){return this.#w}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:r,allowStale:h,dispose:a,onInsert:d,disposeAfter:f,noDisposeOnSet:p,noUpdateTTL:m,maxSize:T=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:l,memoMethod:S,noDeleteOnFetchRejection:_,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:g,allowStaleOnFetchAbort:A,ignoreFetchAbort:v,perf:R}=t;if(R!==void 0&&typeof R?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#S=R??P,e!==0&&!F(e))throw new TypeError("max option must be a nonnegative integer");let z=e?I(e):Array;if(!z)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=T,this.maxEntrySize=w||this.#c,this.sizeCalculation=y,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(S!==void 0&&typeof S!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#j=S,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#M=l,this.#O=!!l,this.#s=new Map,this.#i=Array.from({length:e}).fill(void 0),this.#t=Array.from({length:e}).fill(void 0),this.#l=new z(e),this.#u=new z(e),this.#a=0,this.#h=0,this.#y=C.create(e),this.#n=0,this.#b=0,typeof a=="function"&&(this.#m=a),typeof d=="function"&&(this.#D=d),typeof f=="function"?(this.#w=f,this.#r=[]):(this.#w=void 0,this.#r=void 0),this.#T=!!this.#m,this.#U=!!this.#D,this.#f=!!this.#w,this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!_,this.allowStaleOnFetchRejection=!!g,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!v,this.maxEntrySize!==0){if(this.#c!==0&&!F(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!F(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#X()}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!r,this.ttlResolution=F(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!F(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#H()}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let E="LRU_CACHE_UNBOUNDED";N(E)&&(U.add(E),H("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",E,c))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#H(){let t=new W(this.#o),e=new W(this.#o);this.#d=t,this.#F=e;let i=this.ttlAutopurge?Array.from({length:this.#o}):void 0;this.#g=i,this.#N=(r,h,a=this.#S.now())=>{e[r]=h!==0?a:0,t[r]=h,s(r,h)},this.#R=r=>{e[r]=t[r]!==0?this.#S.now():0,s(r,t[r])};let s=this.ttlAutopurge?(r,h)=>{if(i?.[r]&&(clearTimeout(i[r]),i[r]=void 0),h&&h!==0&&i){let a=setTimeout(()=>{this.#p(r)&&this.#z(this.#i[r],"expire")},h+1);a.unref&&a.unref(),i[r]=a}}:()=>{};this.#E=(r,h)=>{if(t[h]){let a=t[h],d=e[h];if(!a||!d)return;r.ttl=a,r.start=d,r.now=n||o();let f=r.now-d;r.remainingTTL=a-f}};let n=0,o=()=>{let r=this.#S.now();if(this.ttlResolution>0){n=r;let h=setTimeout(()=>n=0,this.ttlResolution);h.unref&&h.unref()}return r};this.getRemainingTTL=r=>{let h=this.#s.get(r);if(h===void 0)return 0;let a=t[h],d=e[h];if(!a||!d)return 1/0;let f=(n||o())-d;return a-f},this.#p=r=>{let h=e[r],a=t[r];return!!a&&!!h&&(n||o())-h>a}}#R=()=>{};#E=()=>{};#N=()=>{};#p=()=>!1;#X(){let t=new W(this.#o);this.#b=0,this.#_=t,this.#C=e=>{this.#b-=t[e],t[e]=0},this.#k=(e,i,s,n)=>{if(this.#e(i))return 0;if(!F(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!F(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#I=(e,i,s)=>{if(t[e]=i,this.#c){let n=this.#c-t[e];for(;this.#b>n;)this.#G(!0)}this.#b+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#b)}}#C=t=>{};#I=(t,e,i)=>{};#k=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#a);)e=this.#u[e]}*#v({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#a;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#h);)e=this.#l[e]}#V(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#A())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#v())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#A()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#v()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#A())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#v())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.#x(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#v()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#v({allowStale:!0}))this.#p(e)&&(this.#z(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#F){let o=this.#d[e],r=this.#F[e];if(o&&r){let h=o-(this.#S.now()-r);n.ttl=h,n.start=Date.now()}}return this.#_&&(n.size=this.#_[e]),n}dump(){let t=[];for(let e of this.#A({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let o={value:n};if(this.#d&&this.#F){o.ttl=this.#d[e];let r=this.#S.now()-this.#F[e];o.start=Math.floor(Date.now()-r)}this.#_&&(o.size=this.#_[e]),t.unshift([i,o])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#S.now()-s}this.#W(e,i.value,i)}}set(t,e,i={}){let{status:s=u.metrics.hasSubscribers?{}:void 0}=i;i.status=s,s&&(s.op="set",s.key=t,e!==void 0&&(s.value=e));let n=this.#W(t,e,i);return s&&u.metrics.hasSubscribers&&u.metrics.publish(s),n}#W(t,e,i={}){let{ttl:s=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:r=this.sizeCalculation,status:h}=i;if(e===void 0)return h&&(h.set="deleted"),this.delete(t),this;let{noUpdateTTL:a=this.noUpdateTTL}=i;h&&!this.#e(e)&&(h.value=e);let d=this.#k(t,e,i.size||0,r,h);if(this.maxEntrySize&&d>this.maxEntrySize)return this.#z(t,"set"),h&&(h.set="miss",h.maxEntrySizeExceeded=!0),this;let f=this.#n===0?void 0:this.#s.get(t);if(f===void 0)f=this.#n===0?this.#h:this.#y.length!==0?this.#y.pop():this.#n===this.#o?this.#G(!1):this.#n,this.#i[f]=t,this.#t[f]=e,this.#s.set(t,f),this.#l[this.#h]=f,this.#u[f]=this.#h,this.#h=f,this.#n++,this.#I(f,d,h),h&&(h.set="add"),a=!1,this.#U&&this.#D?.(e,t,"add");else{this.#L(f);let p=this.#t[f];if(e!==p){if(this.#O&&this.#e(p)){p.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:m}=p;m!==void 0&&!o&&(this.#T&&this.#m?.(m,t,"set"),this.#f&&this.#r?.push([m,t,"set"]))}else o||(this.#T&&this.#m?.(p,t,"set"),this.#f&&this.#r?.push([p,t,"set"]));if(this.#C(f),this.#I(f,d,h),this.#t[f]=e,h){h.set="replace";let m=p&&this.#e(p)?p.__staleWhileFetching:p;m!==void 0&&(h.oldValue=m)}}else h&&(h.set="update");this.#U&&this.onInsert?.(e,t,e===p?"update":"replace")}if(s!==0&&!this.#d&&this.#H(),this.#d&&(a||this.#N(f,s,n),h&&this.#E(h,f)),!o&&this.#f&&this.#r){let p=this.#r,m;for(;m=p?.shift();)this.#w?.(...m)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#a];if(this.#G(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#w?.(...e)}}}#G(t){let e=this.#a,i=this.#i[e],s=this.#t[e];return this.#O&&this.#e(s)?s.__abortController.abort(new Error("evicted")):(this.#T||this.#f)&&(this.#T&&this.#m?.(s,i,"evict"),this.#f&&this.#r?.push([s,i,"evict"])),this.#C(e),this.#g?.[e]&&(clearTimeout(this.#g[e]),this.#g[e]=void 0),t&&(this.#i[e]=void 0,this.#t[e]=void 0,this.#y.push(e)),this.#n===1?(this.#a=this.#h=0,this.#y.length=0):this.#a=this.#l[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{status:i=u.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="has",i.key=t);let s=this.#Y(t,e);return u.metrics.hasSubscribers&&u.metrics.publish(i),s}#Y(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let o=this.#t[n];if(this.#e(o)&&o.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#E(s,n));else return i&&this.#R(n),s&&(s.has="hit",this.#E(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{status:i=D()?{}:void 0}=e;i&&(i.op="peek",i.key=t),e.status=i;let s=this.#J(t,e);return u.metrics.hasSubscribers&&u.metrics.publish(i),s}#J(t,e){let{status:i,allowStale:s=this.allowStale}=e,n=this.#s.get(t);if(n===void 0||!s&&this.#p(n)){i&&(i.peek=n===void 0?"miss":"stale");return}let o=this.#t[n],r=this.#e(o)?o.__staleWhileFetching:o;return i&&(r!==void 0?(i.peek="hit",i.value=r):i.peek="miss"),r}#P(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let o=new AbortController,{signal:r}=i;r?.addEventListener("abort",()=>o.abort(r.reason),{signal:o.signal});let h={signal:o.signal,options:i,context:s},a=(w,y=!1)=>{let{aborted:l}=o.signal,S=i.ignoreFetchAbort&&w!==void 0,_=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&w!==void 0);if(i.status&&(l&&!y?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,S&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),l&&!S&&!y)return f(o.signal.reason,_);let b=m,g=this.#t[e];return(g===m||g===void 0&&S&&y)&&(w===void 0?b.__staleWhileFetching!==void 0?this.#t[e]=b.__staleWhileFetching:this.#z(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.#W(t,w,h.options))),w},d=w=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=w),f(w,!1)),f=(w,y)=>{let{aborted:l}=o.signal,S=l&&i.allowStaleOnFetchAbort,_=S||i.allowStaleOnFetchRejection,b=_||i.noDeleteOnFetchRejection,g=m;if(this.#t[e]===m&&(!b||!y&&g.__staleWhileFetching===void 0?this.#z(t,"fetch"):S||(this.#t[e]=g.__staleWhileFetching)),_)return i.status&&g.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),g.__staleWhileFetching;if(g.__returned===g)throw w},p=(w,y)=>{let l=this.#M?.(t,n,h);l&&l instanceof Promise&&l.then(S=>w(S===void 0?void 0:S),y),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(w(void 0),i.allowStaleOnFetchAbort&&(w=S=>a(S,!0)))})};i.status&&(i.status.fetchDispatched=!0);let m=new Promise(p).then(a,d),T=Object.assign(m,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.#W(t,T,{...h.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=T,T}#e(t){if(!this.#O)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof AbortController}fetch(t,e={}){let i=u.tracing.hasSubscribers,{status:s=D()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#q(t,e);return s&&D()&&i&&(s.trace=!0,u.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#q(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:h=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:d=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:p=this.allowStaleOnFetchRejection,ignoreFetchAbort:m=this.ignoreFetchAbort,allowStaleOnFetchAbort:T=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=!1,status:l,signal:S}=e;if(l&&(l.op="fetch",l.key=t,y&&(l.forceRefresh=!0)),!this.#O)return l&&(l.fetch="get"),this.#x(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:l});let _={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:r,size:h,sizeCalculation:a,noUpdateTTL:d,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:p,allowStaleOnFetchAbort:T,ignoreFetchAbort:m,status:l,signal:S},b=this.#s.get(t);if(b===void 0){l&&(l.fetch="miss");let g=this.#P(t,b,_,w);return g.__returned=g}else{let g=this.#t[b];if(this.#e(g)){let E=i&&g.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=!0)),E?g.__staleWhileFetching:g.__returned=g}let A=this.#p(b);if(!y&&!A)return l&&(l.fetch="hit"),this.#L(b),s&&this.#R(b),l&&this.#E(l,b),g;let v=this.#P(t,b,_,w),z=v.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=A?"stale":"refresh",z&&A&&(l.returnedStale=!0)),z?v.__staleWhileFetching:v.__returned=v}}forceFetch(t,e={}){let i=u.tracing.hasSubscribers,{status:s=D()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#K(t,e);return s&&D()&&i&&(s.trace=!0,u.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#K(t,e={}){let i=await this.#q(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let{status:i=u.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="memo",i.key=t,e.context&&(i.context=e.context));let s=this.#Q(t,e);return i&&(i.value=s),u.metrics.hasSubscribers&&u.metrics.publish(i),s}#Q(t,e={}){let i=this.#j;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,status:n,forceRefresh:o,...r}=e;n&&o&&(n.forceRefresh=!0);let h=this.#x(t,r),a=o||h===void 0;if(n&&(n.memo=a?"miss":"hit",a||(n.value=h)),!a)return h;let d=i(t,h,{options:r,context:s});return n&&(n.value=d),this.#W(t,d,r),d}get(t,e={}){let{status:i=u.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="get",i.key=t);let s=this.#x(t,e);return i&&(s!==void 0&&(i.value=s),u.metrics.hasSubscribers&&u.metrics.publish(i)),s}#x(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=e,r=this.#s.get(t);if(r===void 0){o&&(o.get="miss");return}let h=this.#t[r],a=this.#e(h);return o&&this.#E(o,r),this.#p(r)?a?(o&&(o.get="stale-fetching"),i&&h.__staleWhileFetching!==void 0?(o&&(o.returnedStale=!0),h.__staleWhileFetching):void 0):(n||this.#z(t,"expire"),o&&(o.get="stale"),i?(o&&(o.returnedStale=!0),h):void 0):(o&&(o.get=a?"fetching":"hit"),this.#L(r),s&&this.#R(r),a?h.__staleWhileFetching:h)}#B(t,e){this.#u[e]=t,this.#l[t]=e}#L(t){t!==this.#h&&(t===this.#a?this.#a=this.#l[t]:this.#B(this.#u[t],this.#l[t]),this.#B(this.#h,t),this.#h=t)}delete(t){return this.#z(t,"delete")}#z(t,e){u.metrics.hasSubscribers&&u.metrics.publish({op:"delete",delete:e,key:t});let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#$(e);else{this.#C(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#m?.(n,t,e),this.#f&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#a)this.#a=this.#l[s];else{let o=this.#u[s];this.#l[o]=this.#l[s];let r=this.#l[s];this.#u[r]=this.#u[s]}this.#n--,this.#y.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#w?.(...n)}return i}clear(){return this.#$("delete")}#$(t){for(let e of this.#v({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#T&&this.#m?.(i,s,t),this.#f&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#F){this.#d.fill(0),this.#F.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0)}if(this.#_&&this.#_.fill(0),this.#a=0,this.#h=0,this.#y.length=0,this.#b=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#w?.(...i)}}};exports.LRUCache=x;
2
2
  //# sourceMappingURL=index.min.js.map