@midscene/cli 1.8.10-beta-20260604215059.0 → 1.9.0

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/lib/index.js CHANGED
@@ -3374,7 +3374,9 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3374
3374
  const cli_namespaceObject = require("@midscene/shared/cli");
3375
3375
  var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js");
3376
3376
  var main_default = /*#__PURE__*/ __webpack_require__.n(main);
3377
- var package_namespaceObject = JSON.parse('{"rE":"1.8.10-beta-20260604215059.0"}');
3377
+ var package_namespaceObject = {
3378
+ rE: "1.9.0"
3379
+ };
3378
3380
  var logger_ = __webpack_require__("@midscene/shared/logger");
3379
3381
  var brace_expansion = __webpack_require__("../../node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js");
3380
3382
  const MAX_PATTERN_LENGTH = 65536;
@@ -4511,47 +4513,85 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4511
4513
  minimatch.escape = escape_escape;
4512
4514
  minimatch.unescape = unescape_unescape;
4513
4515
  var external_node_url_ = __webpack_require__("node:url");
4514
- const external_node_diagnostics_channel_namespaceObject = require("node:diagnostics_channel");
4515
- var S = (0, external_node_diagnostics_channel_namespaceObject.channel)("lru-cache:metrics"), W = (0, external_node_diagnostics_channel_namespaceObject.tracingChannel)("lru-cache");
4516
- var D = ()=>S.hasSubscribers || W.hasSubscribers, G = "object" == typeof performance && performance && "function" == typeof performance.now ? performance : Date, M = new Set, C = "object" == typeof process && process ? process : {}, P = (u, e1, t1, i)=>{
4517
- "function" == typeof C.emitWarning ? C.emitWarning(u, e1, t1, i) : console.error(`[${t1}] ${e1}: ${u}`);
4518
- }, H = (u)=>!M.has(u), F = (Symbol("type"), (u)=>!!u && u === Math.floor(u) && u > 0 && isFinite(u)), U = (u)=>F(u) ? u <= Math.pow(2, 8) ? Uint8Array : u <= Math.pow(2, 16) ? Uint16Array : u <= Math.pow(2, 32) ? Uint32Array : u <= Number.MAX_SAFE_INTEGER ? O : null : null, O = class extends Array {
4519
- constructor(e1){
4520
- super(e1), this.fill(0);
4521
- }
4522
- }, R = class u {
4516
+ const perf = 'object' == typeof performance && performance && 'function' == typeof performance.now ? performance : Date;
4517
+ const warned = new Set();
4518
+ const PROCESS = 'object' == typeof process && process ? process : {};
4519
+ const emitWarning = (msg, type, code, fn)=>{
4520
+ 'function' == typeof PROCESS.emitWarning ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
4521
+ };
4522
+ let AC = globalThis.AbortController;
4523
+ let AS = globalThis.AbortSignal;
4524
+ if (void 0 === AC) {
4525
+ AS = class {
4526
+ onabort;
4527
+ _onabort = [];
4528
+ reason;
4529
+ aborted = false;
4530
+ addEventListener(_, fn) {
4531
+ this._onabort.push(fn);
4532
+ }
4533
+ };
4534
+ AC = class {
4535
+ constructor(){
4536
+ warnACPolyfill();
4537
+ }
4538
+ signal = new AS();
4539
+ abort(reason) {
4540
+ if (this.signal.aborted) return;
4541
+ this.signal.reason = reason;
4542
+ this.signal.aborted = true;
4543
+ for (const fn of this.signal._onabort)fn(reason);
4544
+ this.signal.onabort?.(reason);
4545
+ }
4546
+ };
4547
+ let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
4548
+ const warnACPolyfill = ()=>{
4549
+ if (!printACPolyfillWarning) return;
4550
+ printACPolyfillWarning = false;
4551
+ emitWarning("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', warnACPolyfill);
4552
+ };
4553
+ }
4554
+ const shouldWarn = (code)=>!warned.has(code);
4555
+ Symbol('type');
4556
+ const isPosInt = (n)=>n && n === Math.floor(n) && n > 0 && isFinite(n);
4557
+ const getUintArray = (max)=>isPosInt(max) ? 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 : null;
4558
+ class ZeroArray extends Array {
4559
+ constructor(size){
4560
+ super(size);
4561
+ this.fill(0);
4562
+ }
4563
+ }
4564
+ class Stack {
4523
4565
  heap;
4524
4566
  length;
4525
- static #o = !1;
4526
- static create(e1) {
4527
- let t1 = U(e1);
4528
- if (!t1) return [];
4529
- u.#o = !0;
4530
- let i = new u(e1, t1);
4531
- return u.#o = !1, i;
4532
- }
4533
- constructor(e1, t1){
4534
- if (!u.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
4535
- this.heap = new t1(e1), this.length = 0;
4536
- }
4537
- push(e1) {
4538
- this.heap[this.length++] = e1;
4567
+ static #constructing = false;
4568
+ static create(max) {
4569
+ const HeapCls = getUintArray(max);
4570
+ if (!HeapCls) return [];
4571
+ Stack.#constructing = true;
4572
+ const s = new Stack(max, HeapCls);
4573
+ Stack.#constructing = false;
4574
+ return s;
4575
+ }
4576
+ constructor(max, HeapCls){
4577
+ if (!Stack.#constructing) throw new TypeError('instantiate Stack using Stack.create(n)');
4578
+ this.heap = new HeapCls(max);
4579
+ this.length = 0;
4580
+ }
4581
+ push(n) {
4582
+ this.heap[this.length++] = n;
4539
4583
  }
4540
4584
  pop() {
4541
4585
  return this.heap[--this.length];
4542
4586
  }
4543
- }, L = class u {
4544
- #o;
4545
- #u;
4546
- #w;
4547
- #D;
4548
- #S;
4549
- #M;
4550
- #U;
4551
- #m;
4552
- get perf() {
4553
- return this.#m;
4554
- }
4587
+ }
4588
+ class LRUCache {
4589
+ #max;
4590
+ #maxSize;
4591
+ #dispose;
4592
+ #disposeAfter;
4593
+ #fetchMethod;
4594
+ #memoMethod;
4555
4595
  ttl;
4556
4596
  ttlResolution;
4557
4597
  ttlAutopurge;
@@ -4567,613 +4607,823 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4567
4607
  allowStaleOnFetchAbort;
4568
4608
  allowStaleOnFetchRejection;
4569
4609
  ignoreFetchAbort;
4570
- #n;
4571
- #b;
4572
- #s;
4573
- #i;
4574
- #t;
4575
- #a;
4576
- #c;
4577
- #l;
4578
- #h;
4579
- #y;
4580
- #r;
4581
- #_;
4582
- #F;
4583
- #d;
4584
- #g;
4585
- #T;
4586
- #W;
4587
- #f;
4588
- #j;
4589
- static unsafeExposeInternals(e1) {
4610
+ #size;
4611
+ #calculatedSize;
4612
+ #keyMap;
4613
+ #keyList;
4614
+ #valList;
4615
+ #next;
4616
+ #prev;
4617
+ #head;
4618
+ #tail;
4619
+ #free;
4620
+ #disposed;
4621
+ #sizes;
4622
+ #starts;
4623
+ #ttls;
4624
+ #hasDispose;
4625
+ #hasFetchMethod;
4626
+ #hasDisposeAfter;
4627
+ static unsafeExposeInternals(c) {
4590
4628
  return {
4591
- starts: e1.#F,
4592
- ttls: e1.#d,
4593
- autopurgeTimers: e1.#g,
4594
- sizes: e1.#_,
4595
- keyMap: e1.#s,
4596
- keyList: e1.#i,
4597
- valList: e1.#t,
4598
- next: e1.#a,
4599
- prev: e1.#c,
4629
+ starts: c.#starts,
4630
+ ttls: c.#ttls,
4631
+ sizes: c.#sizes,
4632
+ keyMap: c.#keyMap,
4633
+ keyList: c.#keyList,
4634
+ valList: c.#valList,
4635
+ next: c.#next,
4636
+ prev: c.#prev,
4600
4637
  get head () {
4601
- return e1.#l;
4638
+ return c.#head;
4602
4639
  },
4603
4640
  get tail () {
4604
- return e1.#h;
4641
+ return c.#tail;
4605
4642
  },
4606
- free: e1.#y,
4607
- isBackgroundFetch: (t1)=>e1.#e(t1),
4608
- backgroundFetch: (t1, i, s, n)=>e1.#P(t1, i, s, n),
4609
- moveToTail: (t1)=>e1.#L(t1),
4610
- indexes: (t1)=>e1.#A(t1),
4611
- rindexes: (t1)=>e1.#z(t1),
4612
- isStale: (t1)=>e1.#p(t1)
4643
+ free: c.#free,
4644
+ isBackgroundFetch: (p)=>c.#isBackgroundFetch(p),
4645
+ backgroundFetch: (k, index, options, context)=>c.#backgroundFetch(k, index, options, context),
4646
+ moveToTail: (index)=>c.#moveToTail(index),
4647
+ indexes: (options)=>c.#indexes(options),
4648
+ rindexes: (options)=>c.#rindexes(options),
4649
+ isStale: (index)=>c.#isStale(index)
4613
4650
  };
4614
4651
  }
4615
4652
  get max() {
4616
- return this.#o;
4653
+ return this.#max;
4617
4654
  }
4618
4655
  get maxSize() {
4619
- return this.#u;
4656
+ return this.#maxSize;
4620
4657
  }
4621
4658
  get calculatedSize() {
4622
- return this.#b;
4659
+ return this.#calculatedSize;
4623
4660
  }
4624
4661
  get size() {
4625
- return this.#n;
4662
+ return this.#size;
4626
4663
  }
4627
4664
  get fetchMethod() {
4628
- return this.#M;
4665
+ return this.#fetchMethod;
4629
4666
  }
4630
4667
  get memoMethod() {
4631
- return this.#U;
4668
+ return this.#memoMethod;
4632
4669
  }
4633
4670
  get dispose() {
4634
- return this.#w;
4635
- }
4636
- get onInsert() {
4637
- return this.#D;
4671
+ return this.#dispose;
4638
4672
  }
4639
4673
  get disposeAfter() {
4640
- return this.#S;
4641
- }
4642
- constructor(e1){
4643
- let { max: t1 = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: r, allowStale: h, dispose: l, onInsert: c, disposeAfter: f, noDisposeOnSet: g, noUpdateTTL: p, maxSize: T = 0, maxEntrySize: w = 0, sizeCalculation: y, fetchMethod: a, memoMethod: m, noDeleteOnFetchRejection: _, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: A, ignoreFetchAbort: z, perf: x } = e1;
4644
- if (void 0 !== x && "function" != typeof x?.now) throw new TypeError("perf option must have a now() method if specified");
4645
- if (this.#m = x ?? G, 0 !== t1 && !F(t1)) throw new TypeError("max option must be a nonnegative integer");
4646
- let v = t1 ? U(t1) : Array;
4647
- if (!v) throw new Error("invalid max value: " + t1);
4648
- if (this.#o = t1, this.#u = T, this.maxEntrySize = w || this.#u, this.sizeCalculation = y, this.sizeCalculation) {
4649
- if (!this.#u && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
4650
- if ("function" != typeof this.sizeCalculation) throw new TypeError("sizeCalculation set to non-function");
4651
- }
4652
- if (void 0 !== m && "function" != typeof m) throw new TypeError("memoMethod must be a function if defined");
4653
- if (this.#U = m, void 0 !== a && "function" != typeof a) throw new TypeError("fetchMethod must be a function if specified");
4654
- if (this.#M = a, this.#W = !!a, this.#s = new Map, this.#i = Array.from({
4655
- length: t1
4656
- }).fill(void 0), this.#t = Array.from({
4657
- length: t1
4658
- }).fill(void 0), this.#a = new v(t1), this.#c = new v(t1), this.#l = 0, this.#h = 0, this.#y = R.create(t1), this.#n = 0, this.#b = 0, "function" == typeof l && (this.#w = l), "function" == typeof c && (this.#D = c), "function" == typeof f ? (this.#S = f, this.#r = []) : (this.#S = void 0, this.#r = void 0), this.#T = !!this.#w, this.#j = !!this.#D, this.#f = !!this.#S, this.noDisposeOnSet = !!g, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!_, this.allowStaleOnFetchRejection = !!d, this.allowStaleOnFetchAbort = !!A, this.ignoreFetchAbort = !!z, 0 !== this.maxEntrySize) {
4659
- if (0 !== this.#u && !F(this.#u)) throw new TypeError("maxSize must be a positive integer if specified");
4660
- if (!F(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
4661
- this.#X();
4662
- }
4663
- if (this.allowStale = !!h, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!r, this.ttlResolution = F(s) || 0 === s ? s : 1, this.ttlAutopurge = !!n, this.ttl = i || 0, this.ttl) {
4664
- if (!F(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
4665
- this.#H();
4666
- }
4667
- if (0 === this.#o && 0 === this.ttl && 0 === this.#u) throw new TypeError("At least one of max, maxSize, or ttl is required");
4668
- if (!this.ttlAutopurge && !this.#o && !this.#u) {
4669
- let E = "LRU_CACHE_UNBOUNDED";
4670
- H(E) && (M.add(E), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, u));
4671
- }
4672
- }
4673
- getRemainingTTL(e1) {
4674
- return this.#s.has(e1) ? 1 / 0 : 0;
4675
- }
4676
- #H() {
4677
- let e1 = new O(this.#o), t1 = new O(this.#o);
4678
- this.#d = e1, this.#F = t1;
4679
- let i = this.ttlAutopurge ? Array.from({
4680
- length: this.#o
4681
- }) : void 0;
4682
- this.#g = i, this.#N = (r, h, l = this.#m.now())=>{
4683
- t1[r] = 0 !== h ? l : 0, e1[r] = h, s(r, h);
4684
- }, this.#x = (r)=>{
4685
- t1[r] = 0 !== e1[r] ? this.#m.now() : 0, s(r, e1[r]);
4674
+ return this.#disposeAfter;
4675
+ }
4676
+ constructor(options){
4677
+ 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;
4678
+ if (0 !== max && !isPosInt(max)) throw new TypeError('max option must be a nonnegative integer');
4679
+ const UintArray = max ? getUintArray(max) : Array;
4680
+ if (!UintArray) throw new Error('invalid max value: ' + max);
4681
+ this.#max = max;
4682
+ this.#maxSize = maxSize;
4683
+ this.maxEntrySize = maxEntrySize || this.#maxSize;
4684
+ this.sizeCalculation = sizeCalculation;
4685
+ if (this.sizeCalculation) {
4686
+ if (!this.#maxSize && !this.maxEntrySize) throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
4687
+ if ('function' != typeof this.sizeCalculation) throw new TypeError('sizeCalculation set to non-function');
4688
+ }
4689
+ if (void 0 !== memoMethod && 'function' != typeof memoMethod) throw new TypeError('memoMethod must be a function if defined');
4690
+ this.#memoMethod = memoMethod;
4691
+ if (void 0 !== fetchMethod && 'function' != typeof fetchMethod) throw new TypeError('fetchMethod must be a function if specified');
4692
+ this.#fetchMethod = fetchMethod;
4693
+ this.#hasFetchMethod = !!fetchMethod;
4694
+ this.#keyMap = new Map();
4695
+ this.#keyList = new Array(max).fill(void 0);
4696
+ this.#valList = new Array(max).fill(void 0);
4697
+ this.#next = new UintArray(max);
4698
+ this.#prev = new UintArray(max);
4699
+ this.#head = 0;
4700
+ this.#tail = 0;
4701
+ this.#free = Stack.create(max);
4702
+ this.#size = 0;
4703
+ this.#calculatedSize = 0;
4704
+ if ('function' == typeof dispose) this.#dispose = dispose;
4705
+ if ('function' == typeof disposeAfter) {
4706
+ this.#disposeAfter = disposeAfter;
4707
+ this.#disposed = [];
4708
+ } else {
4709
+ this.#disposeAfter = void 0;
4710
+ this.#disposed = void 0;
4711
+ }
4712
+ this.#hasDispose = !!this.#dispose;
4713
+ this.#hasDisposeAfter = !!this.#disposeAfter;
4714
+ this.noDisposeOnSet = !!noDisposeOnSet;
4715
+ this.noUpdateTTL = !!noUpdateTTL;
4716
+ this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
4717
+ this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
4718
+ this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
4719
+ this.ignoreFetchAbort = !!ignoreFetchAbort;
4720
+ if (0 !== this.maxEntrySize) {
4721
+ if (0 !== this.#maxSize) {
4722
+ if (!isPosInt(this.#maxSize)) throw new TypeError('maxSize must be a positive integer if specified');
4723
+ }
4724
+ if (!isPosInt(this.maxEntrySize)) throw new TypeError('maxEntrySize must be a positive integer if specified');
4725
+ this.#initializeSizeTracking();
4726
+ }
4727
+ this.allowStale = !!allowStale;
4728
+ this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
4729
+ this.updateAgeOnGet = !!updateAgeOnGet;
4730
+ this.updateAgeOnHas = !!updateAgeOnHas;
4731
+ this.ttlResolution = isPosInt(ttlResolution) || 0 === ttlResolution ? ttlResolution : 1;
4732
+ this.ttlAutopurge = !!ttlAutopurge;
4733
+ this.ttl = ttl || 0;
4734
+ if (this.ttl) {
4735
+ if (!isPosInt(this.ttl)) throw new TypeError('ttl must be a positive integer if specified');
4736
+ this.#initializeTTLTracking();
4737
+ }
4738
+ if (0 === this.#max && 0 === this.ttl && 0 === this.#maxSize) throw new TypeError('At least one of max, maxSize, or ttl is required');
4739
+ if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
4740
+ const code = 'LRU_CACHE_UNBOUNDED';
4741
+ if (shouldWarn(code)) {
4742
+ warned.add(code);
4743
+ const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
4744
+ emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
4745
+ }
4746
+ }
4747
+ }
4748
+ getRemainingTTL(key) {
4749
+ return this.#keyMap.has(key) ? 1 / 0 : 0;
4750
+ }
4751
+ #initializeTTLTracking() {
4752
+ const ttls = new ZeroArray(this.#max);
4753
+ const starts = new ZeroArray(this.#max);
4754
+ this.#ttls = ttls;
4755
+ this.#starts = starts;
4756
+ this.#setItemTTL = (index, ttl, start = perf.now())=>{
4757
+ starts[index] = 0 !== ttl ? start : 0;
4758
+ ttls[index] = ttl;
4759
+ if (0 !== ttl && this.ttlAutopurge) {
4760
+ const t1 = setTimeout(()=>{
4761
+ if (this.#isStale(index)) this.#delete(this.#keyList[index], 'expire');
4762
+ }, ttl + 1);
4763
+ if (t1.unref) t1.unref();
4764
+ }
4686
4765
  };
4687
- let s = this.ttlAutopurge ? (r, h)=>{
4688
- if (i?.[r] && (clearTimeout(i[r]), i[r] = void 0), h && 0 !== h && i) {
4689
- let l = setTimeout(()=>{
4690
- this.#p(r) && this.#v(this.#i[r], "expire");
4691
- }, h + 1);
4692
- l.unref && l.unref(), i[r] = l;
4693
- }
4694
- } : ()=>{};
4695
- this.#E = (r, h)=>{
4696
- if (e1[h]) {
4697
- let l = e1[h], c = t1[h];
4698
- if (!l || !c) return;
4699
- r.ttl = l, r.start = c, r.now = n || o();
4700
- let f = r.now - c;
4701
- r.remainingTTL = l - f;
4766
+ this.#updateItemAge = (index)=>{
4767
+ starts[index] = 0 !== ttls[index] ? perf.now() : 0;
4768
+ };
4769
+ this.#statusTTL = (status, index)=>{
4770
+ if (ttls[index]) {
4771
+ const ttl = ttls[index];
4772
+ const start = starts[index];
4773
+ if (!ttl || !start) return;
4774
+ status.ttl = ttl;
4775
+ status.start = start;
4776
+ status.now = cachedNow || getNow();
4777
+ const age = status.now - start;
4778
+ status.remainingTTL = ttl - age;
4702
4779
  }
4703
4780
  };
4704
- let n = 0, o = ()=>{
4705
- let r = this.#m.now();
4781
+ let cachedNow = 0;
4782
+ const getNow = ()=>{
4783
+ const n = perf.now();
4706
4784
  if (this.ttlResolution > 0) {
4707
- n = r;
4708
- let h = setTimeout(()=>n = 0, this.ttlResolution);
4709
- h.unref && h.unref();
4785
+ cachedNow = n;
4786
+ const t1 = setTimeout(()=>cachedNow = 0, this.ttlResolution);
4787
+ if (t1.unref) t1.unref();
4710
4788
  }
4711
- return r;
4789
+ return n;
4790
+ };
4791
+ this.getRemainingTTL = (key)=>{
4792
+ const index = this.#keyMap.get(key);
4793
+ if (void 0 === index) return 0;
4794
+ const ttl = ttls[index];
4795
+ const start = starts[index];
4796
+ if (!ttl || !start) return 1 / 0;
4797
+ const age = (cachedNow || getNow()) - start;
4798
+ return ttl - age;
4712
4799
  };
4713
- this.getRemainingTTL = (r)=>{
4714
- let h = this.#s.get(r);
4715
- if (void 0 === h) return 0;
4716
- let l = e1[h], c = t1[h];
4717
- if (!l || !c) return 1 / 0;
4718
- let f = (n || o()) - c;
4719
- return l - f;
4720
- }, this.#p = (r)=>{
4721
- let h = t1[r], l = e1[r];
4722
- return !!l && !!h && (n || o()) - h > l;
4800
+ this.#isStale = (index)=>{
4801
+ const s = starts[index];
4802
+ const t1 = ttls[index];
4803
+ return !!t1 && !!s && (cachedNow || getNow()) - s > t1;
4723
4804
  };
4724
4805
  }
4725
- #x = ()=>{};
4726
- #E = ()=>{};
4727
- #N = ()=>{};
4728
- #p = ()=>!1;
4729
- #X() {
4730
- let e1 = new O(this.#o);
4731
- this.#b = 0, this.#_ = e1, this.#R = (t1)=>{
4732
- this.#b -= e1[t1], e1[t1] = 0;
4733
- }, this.#k = (t1, i, s, n)=>{
4734
- if (this.#e(i)) return 0;
4735
- if (!F(s)) if (n) {
4736
- if ("function" != typeof n) throw new TypeError("sizeCalculation must be a function");
4737
- if (s = n(i, t1), !F(s)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
4806
+ #updateItemAge = ()=>{};
4807
+ #statusTTL = ()=>{};
4808
+ #setItemTTL = ()=>{};
4809
+ #isStale = ()=>false;
4810
+ #initializeSizeTracking() {
4811
+ const sizes = new ZeroArray(this.#max);
4812
+ this.#calculatedSize = 0;
4813
+ this.#sizes = sizes;
4814
+ this.#removeItemSize = (index)=>{
4815
+ this.#calculatedSize -= sizes[index];
4816
+ sizes[index] = 0;
4817
+ };
4818
+ this.#requireSize = (k, v, size, sizeCalculation)=>{
4819
+ if (this.#isBackgroundFetch(v)) return 0;
4820
+ if (!isPosInt(size)) if (sizeCalculation) {
4821
+ if ('function' != typeof sizeCalculation) throw new TypeError('sizeCalculation must be a function');
4822
+ size = sizeCalculation(v, k);
4823
+ if (!isPosInt(size)) throw new TypeError('sizeCalculation return invalid (expect positive integer)');
4738
4824
  } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
4739
- return s;
4740
- }, this.#I = (t1, i, s)=>{
4741
- if (e1[t1] = i, this.#u) {
4742
- let n = this.#u - e1[t1];
4743
- for(; this.#b > n;)this.#G(!0);
4825
+ return size;
4826
+ };
4827
+ this.#addItemSize = (index, size, status)=>{
4828
+ sizes[index] = size;
4829
+ if (this.#maxSize) {
4830
+ const maxSize = this.#maxSize - sizes[index];
4831
+ while(this.#calculatedSize > maxSize)this.#evict(true);
4832
+ }
4833
+ this.#calculatedSize += sizes[index];
4834
+ if (status) {
4835
+ status.entrySize = size;
4836
+ status.totalCalculatedSize = this.#calculatedSize;
4744
4837
  }
4745
- this.#b += e1[t1], s && (s.entrySize = i, s.totalCalculatedSize = this.#b);
4746
4838
  };
4747
4839
  }
4748
- #R = (e1)=>{};
4749
- #I = (e1, t1, i)=>{};
4750
- #k = (e1, t1, i, s)=>{
4751
- if (i || s) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
4840
+ #removeItemSize = (_i)=>{};
4841
+ #addItemSize = (_i, _s, _st)=>{};
4842
+ #requireSize = (_k, _v, size, sizeCalculation)=>{
4843
+ if (size || sizeCalculation) throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
4752
4844
  return 0;
4753
4845
  };
4754
- *#A({ allowStale: e1 = this.allowStale } = {}) {
4755
- if (this.#n) for(let t1 = this.#h; this.#V(t1) && ((e1 || !this.#p(t1)) && (yield t1), t1 !== this.#l);)t1 = this.#c[t1];
4846
+ *#indexes({ allowStale = this.allowStale } = {}) {
4847
+ if (this.#size) for(let i = this.#tail; true;){
4848
+ if (!this.#isValidIndex(i)) break;
4849
+ if (allowStale || !this.#isStale(i)) yield i;
4850
+ if (i === this.#head) break;
4851
+ i = this.#prev[i];
4852
+ }
4756
4853
  }
4757
- *#z({ allowStale: e1 = this.allowStale } = {}) {
4758
- if (this.#n) for(let t1 = this.#l; this.#V(t1) && ((e1 || !this.#p(t1)) && (yield t1), t1 !== this.#h);)t1 = this.#a[t1];
4854
+ *#rindexes({ allowStale = this.allowStale } = {}) {
4855
+ if (this.#size) for(let i = this.#head; true;){
4856
+ if (!this.#isValidIndex(i)) break;
4857
+ if (allowStale || !this.#isStale(i)) yield i;
4858
+ if (i === this.#tail) break;
4859
+ i = this.#next[i];
4860
+ }
4759
4861
  }
4760
- #V(e1) {
4761
- return void 0 !== e1 && this.#s.get(this.#i[e1]) === e1;
4862
+ #isValidIndex(index) {
4863
+ return void 0 !== index && this.#keyMap.get(this.#keyList[index]) === index;
4762
4864
  }
4763
4865
  *entries() {
4764
- for (let e1 of this.#A())void 0 === this.#t[e1] || void 0 === this.#i[e1] || this.#e(this.#t[e1]) || (yield [
4765
- this.#i[e1],
4766
- this.#t[e1]
4767
- ]);
4866
+ for (const i of this.#indexes())if (void 0 !== this.#valList[i] && void 0 !== this.#keyList[i] && !this.#isBackgroundFetch(this.#valList[i])) yield [
4867
+ this.#keyList[i],
4868
+ this.#valList[i]
4869
+ ];
4768
4870
  }
4769
4871
  *rentries() {
4770
- for (let e1 of this.#z())void 0 === this.#t[e1] || void 0 === this.#i[e1] || this.#e(this.#t[e1]) || (yield [
4771
- this.#i[e1],
4772
- this.#t[e1]
4773
- ]);
4872
+ for (const i of this.#rindexes())if (void 0 !== this.#valList[i] && void 0 !== this.#keyList[i] && !this.#isBackgroundFetch(this.#valList[i])) yield [
4873
+ this.#keyList[i],
4874
+ this.#valList[i]
4875
+ ];
4774
4876
  }
4775
4877
  *keys() {
4776
- for (let e1 of this.#A()){
4777
- let t1 = this.#i[e1];
4778
- void 0 === t1 || this.#e(this.#t[e1]) || (yield t1);
4878
+ for (const i of this.#indexes()){
4879
+ const k = this.#keyList[i];
4880
+ if (void 0 !== k && !this.#isBackgroundFetch(this.#valList[i])) yield k;
4779
4881
  }
4780
4882
  }
4781
4883
  *rkeys() {
4782
- for (let e1 of this.#z()){
4783
- let t1 = this.#i[e1];
4784
- void 0 === t1 || this.#e(this.#t[e1]) || (yield t1);
4884
+ for (const i of this.#rindexes()){
4885
+ const k = this.#keyList[i];
4886
+ if (void 0 !== k && !this.#isBackgroundFetch(this.#valList[i])) yield k;
4785
4887
  }
4786
4888
  }
4787
4889
  *values() {
4788
- for (let e1 of this.#A())void 0 === this.#t[e1] || this.#e(this.#t[e1]) || (yield this.#t[e1]);
4890
+ for (const i of this.#indexes()){
4891
+ const v = this.#valList[i];
4892
+ if (void 0 !== v && !this.#isBackgroundFetch(this.#valList[i])) yield this.#valList[i];
4893
+ }
4789
4894
  }
4790
4895
  *rvalues() {
4791
- for (let e1 of this.#z())void 0 === this.#t[e1] || this.#e(this.#t[e1]) || (yield this.#t[e1]);
4896
+ for (const i of this.#rindexes()){
4897
+ const v = this.#valList[i];
4898
+ if (void 0 !== v && !this.#isBackgroundFetch(this.#valList[i])) yield this.#valList[i];
4899
+ }
4792
4900
  }
4793
4901
  [Symbol.iterator]() {
4794
4902
  return this.entries();
4795
4903
  }
4796
- [Symbol.toStringTag] = "LRUCache";
4797
- find(e1, t1 = {}) {
4798
- for (let i of this.#A()){
4799
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
4800
- if (void 0 !== n && e1(n, this.#i[i], this)) return this.#C(this.#i[i], t1);
4904
+ [Symbol.toStringTag] = 'LRUCache';
4905
+ find(fn, getOptions = {}) {
4906
+ for (const i of this.#indexes()){
4907
+ const v = this.#valList[i];
4908
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
4909
+ if (void 0 !== value) {
4910
+ if (fn(value, this.#keyList[i], this)) return this.get(this.#keyList[i], getOptions);
4911
+ }
4801
4912
  }
4802
4913
  }
4803
- forEach(e1, t1 = this) {
4804
- for (let i of this.#A()){
4805
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
4806
- void 0 !== n && e1.call(t1, n, this.#i[i], this);
4914
+ forEach(fn, thisp = this) {
4915
+ for (const i of this.#indexes()){
4916
+ const v = this.#valList[i];
4917
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
4918
+ if (void 0 !== value) fn.call(thisp, value, this.#keyList[i], this);
4807
4919
  }
4808
4920
  }
4809
- rforEach(e1, t1 = this) {
4810
- for (let i of this.#z()){
4811
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
4812
- void 0 !== n && e1.call(t1, n, this.#i[i], this);
4921
+ rforEach(fn, thisp = this) {
4922
+ for (const i of this.#rindexes()){
4923
+ const v = this.#valList[i];
4924
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
4925
+ if (void 0 !== value) fn.call(thisp, value, this.#keyList[i], this);
4813
4926
  }
4814
4927
  }
4815
4928
  purgeStale() {
4816
- let e1 = !1;
4817
- for (let t1 of this.#z({
4818
- allowStale: !0
4819
- }))this.#p(t1) && (this.#v(this.#i[t1], "expire"), e1 = !0);
4820
- return e1;
4821
- }
4822
- info(e1) {
4823
- let t1 = this.#s.get(e1);
4824
- if (void 0 === t1) return;
4825
- let i = this.#t[t1], s = this.#e(i) ? i.__staleWhileFetching : i;
4826
- if (void 0 === s) return;
4827
- let n = {
4828
- value: s
4929
+ let deleted = false;
4930
+ for (const i of this.#rindexes({
4931
+ allowStale: true
4932
+ }))if (this.#isStale(i)) {
4933
+ this.#delete(this.#keyList[i], 'expire');
4934
+ deleted = true;
4935
+ }
4936
+ return deleted;
4937
+ }
4938
+ info(key) {
4939
+ const i = this.#keyMap.get(key);
4940
+ if (void 0 === i) return;
4941
+ const v = this.#valList[i];
4942
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
4943
+ if (void 0 === value) return;
4944
+ const entry = {
4945
+ value
4829
4946
  };
4830
- if (this.#d && this.#F) {
4831
- let o = this.#d[t1], r = this.#F[t1];
4832
- if (o && r) {
4833
- let h = o - (this.#m.now() - r);
4834
- n.ttl = h, n.start = Date.now();
4947
+ if (this.#ttls && this.#starts) {
4948
+ const ttl = this.#ttls[i];
4949
+ const start = this.#starts[i];
4950
+ if (ttl && start) {
4951
+ const remain = ttl - (perf.now() - start);
4952
+ entry.ttl = remain;
4953
+ entry.start = Date.now();
4835
4954
  }
4836
4955
  }
4837
- return this.#_ && (n.size = this.#_[t1]), n;
4956
+ if (this.#sizes) entry.size = this.#sizes[i];
4957
+ return entry;
4838
4958
  }
4839
4959
  dump() {
4840
- let e1 = [];
4841
- for (let t1 of this.#A({
4842
- allowStale: !0
4960
+ const arr = [];
4961
+ for (const i of this.#indexes({
4962
+ allowStale: true
4843
4963
  })){
4844
- let i = this.#i[t1], s = this.#t[t1], n = this.#e(s) ? s.__staleWhileFetching : s;
4845
- if (void 0 === n || void 0 === i) continue;
4846
- let o = {
4847
- value: n
4964
+ const key = this.#keyList[i];
4965
+ const v = this.#valList[i];
4966
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
4967
+ if (void 0 === value || void 0 === key) continue;
4968
+ const entry = {
4969
+ value
4848
4970
  };
4849
- if (this.#d && this.#F) {
4850
- o.ttl = this.#d[t1];
4851
- let r = this.#m.now() - this.#F[t1];
4852
- o.start = Math.floor(Date.now() - r);
4853
- }
4854
- this.#_ && (o.size = this.#_[t1]), e1.unshift([
4855
- i,
4856
- o
4971
+ if (this.#ttls && this.#starts) {
4972
+ entry.ttl = this.#ttls[i];
4973
+ const age = perf.now() - this.#starts[i];
4974
+ entry.start = Math.floor(Date.now() - age);
4975
+ }
4976
+ if (this.#sizes) entry.size = this.#sizes[i];
4977
+ arr.unshift([
4978
+ key,
4979
+ entry
4857
4980
  ]);
4858
4981
  }
4859
- return e1;
4982
+ return arr;
4860
4983
  }
4861
- load(e1) {
4984
+ load(arr) {
4862
4985
  this.clear();
4863
- for (let [t1, i] of e1){
4864
- if (i.start) {
4865
- let s = Date.now() - i.start;
4866
- i.start = this.#m.now() - s;
4867
- }
4868
- this.#O(t1, i.value, i);
4869
- }
4870
- }
4871
- set(e1, t1, i = {}) {
4872
- let { status: s = S.hasSubscribers ? {} : void 0 } = i;
4873
- i.status = s, s && (s.op = "set", s.key = e1, void 0 !== t1 && (s.value = t1));
4874
- let n = this.#O(e1, t1, i);
4875
- return s && S.hasSubscribers && S.publish(s), n;
4876
- }
4877
- #O(e1, t1, i = {}) {
4878
- let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: r = this.sizeCalculation, status: h } = i;
4879
- if (void 0 === t1) return h && (h.set = "deleted"), this.delete(e1), this;
4880
- let { noUpdateTTL: l = this.noUpdateTTL } = i;
4881
- h && !this.#e(t1) && (h.value = t1);
4882
- let c = this.#k(e1, t1, i.size || 0, r, h);
4883
- if (this.maxEntrySize && c > this.maxEntrySize) return this.#v(e1, "set"), h && (h.set = "miss", h.maxEntrySizeExceeded = !0), this;
4884
- let f = 0 === this.#n ? void 0 : this.#s.get(e1);
4885
- if (void 0 === f) f = 0 === this.#n ? this.#h : 0 !== this.#y.length ? this.#y.pop() : this.#n === this.#o ? this.#G(!1) : this.#n, this.#i[f] = e1, this.#t[f] = t1, this.#s.set(e1, f), this.#a[this.#h] = f, this.#c[f] = this.#h, this.#h = f, this.#n++, this.#I(f, c, h), h && (h.set = "add"), l = !1, this.#j && this.#D?.(t1, e1, "add");
4886
- else {
4887
- this.#L(f);
4888
- let g = this.#t[f];
4889
- if (t1 !== g) {
4890
- if (this.#W && this.#e(g)) {
4891
- g.__abortController.abort(new Error("replaced"));
4892
- let { __staleWhileFetching: p } = g;
4893
- void 0 !== p && !o && (this.#T && this.#w?.(p, e1, "set"), this.#f && this.#r?.push([
4894
- p,
4895
- e1,
4896
- "set"
4897
- ]));
4898
- } else o || (this.#T && this.#w?.(g, e1, "set"), this.#f && this.#r?.push([
4899
- g,
4900
- e1,
4901
- "set"
4902
- ]));
4903
- if (this.#R(f), this.#I(f, c, h), this.#t[f] = t1, h) {
4904
- h.set = "replace";
4905
- let p = g && this.#e(g) ? g.__staleWhileFetching : g;
4906
- void 0 !== p && (h.oldValue = p);
4986
+ for (const [key, entry] of arr){
4987
+ if (entry.start) {
4988
+ const age = Date.now() - entry.start;
4989
+ entry.start = perf.now() - age;
4990
+ }
4991
+ this.set(key, entry.value, entry);
4992
+ }
4993
+ }
4994
+ set(k, v, setOptions = {}) {
4995
+ if (void 0 === v) {
4996
+ this.delete(k);
4997
+ return this;
4998
+ }
4999
+ const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
5000
+ let { noUpdateTTL = this.noUpdateTTL } = setOptions;
5001
+ const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
5002
+ if (this.maxEntrySize && size > this.maxEntrySize) {
5003
+ if (status) {
5004
+ status.set = 'miss';
5005
+ status.maxEntrySizeExceeded = true;
5006
+ }
5007
+ this.#delete(k, 'set');
5008
+ return this;
5009
+ }
5010
+ let index = 0 === this.#size ? void 0 : this.#keyMap.get(k);
5011
+ if (void 0 === index) {
5012
+ index = 0 === this.#size ? this.#tail : 0 !== this.#free.length ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
5013
+ this.#keyList[index] = k;
5014
+ this.#valList[index] = v;
5015
+ this.#keyMap.set(k, index);
5016
+ this.#next[this.#tail] = index;
5017
+ this.#prev[index] = this.#tail;
5018
+ this.#tail = index;
5019
+ this.#size++;
5020
+ this.#addItemSize(index, size, status);
5021
+ if (status) status.set = 'add';
5022
+ noUpdateTTL = false;
5023
+ } else {
5024
+ this.#moveToTail(index);
5025
+ const oldVal = this.#valList[index];
5026
+ if (v !== oldVal) {
5027
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
5028
+ oldVal.__abortController.abort(new Error('replaced'));
5029
+ const { __staleWhileFetching: s } = oldVal;
5030
+ if (void 0 !== s && !noDisposeOnSet) {
5031
+ if (this.#hasDispose) this.#dispose?.(s, k, 'set');
5032
+ if (this.#hasDisposeAfter) this.#disposed?.push([
5033
+ s,
5034
+ k,
5035
+ 'set'
5036
+ ]);
5037
+ }
5038
+ } else if (!noDisposeOnSet) {
5039
+ if (this.#hasDispose) this.#dispose?.(oldVal, k, 'set');
5040
+ if (this.#hasDisposeAfter) this.#disposed?.push([
5041
+ oldVal,
5042
+ k,
5043
+ 'set'
5044
+ ]);
5045
+ }
5046
+ this.#removeItemSize(index);
5047
+ this.#addItemSize(index, size, status);
5048
+ this.#valList[index] = v;
5049
+ if (status) {
5050
+ status.set = 'replace';
5051
+ const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
5052
+ if (void 0 !== oldValue) status.oldValue = oldValue;
4907
5053
  }
4908
- } else h && (h.set = "update");
4909
- this.#j && this.onInsert?.(t1, e1, t1 === g ? "update" : "replace");
5054
+ } else if (status) status.set = 'update';
4910
5055
  }
4911
- if (0 === s || this.#d || this.#H(), this.#d && (l || this.#N(f, s, n), h && this.#E(h, f)), !o && this.#f && this.#r) {
4912
- let g = this.#r, p;
4913
- for(; p = g?.shift();)this.#S?.(...p);
5056
+ if (0 !== ttl && !this.#ttls) this.#initializeTTLTracking();
5057
+ if (this.#ttls) {
5058
+ if (!noUpdateTTL) this.#setItemTTL(index, ttl, start);
5059
+ if (status) this.#statusTTL(status, index);
5060
+ }
5061
+ if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
5062
+ const dt = this.#disposed;
5063
+ let task;
5064
+ while(task = dt?.shift())this.#disposeAfter?.(...task);
4914
5065
  }
4915
5066
  return this;
4916
5067
  }
4917
5068
  pop() {
4918
5069
  try {
4919
- for(; this.#n;){
4920
- let e1 = this.#t[this.#l];
4921
- if (this.#G(!0), this.#e(e1)) {
4922
- if (e1.__staleWhileFetching) return e1.__staleWhileFetching;
4923
- } else if (void 0 !== e1) return e1;
5070
+ while(this.#size){
5071
+ const val = this.#valList[this.#head];
5072
+ this.#evict(true);
5073
+ if (this.#isBackgroundFetch(val)) {
5074
+ if (val.__staleWhileFetching) return val.__staleWhileFetching;
5075
+ } else if (void 0 !== val) return val;
4924
5076
  }
4925
5077
  } finally{
4926
- if (this.#f && this.#r) {
4927
- let e1 = this.#r, t1;
4928
- for(; t1 = e1?.shift();)this.#S?.(...t1);
5078
+ if (this.#hasDisposeAfter && this.#disposed) {
5079
+ const dt = this.#disposed;
5080
+ let task;
5081
+ while(task = dt?.shift())this.#disposeAfter?.(...task);
4929
5082
  }
4930
5083
  }
4931
5084
  }
4932
- #G(e1) {
4933
- let t1 = this.#l, i = this.#i[t1], s = this.#t[t1];
4934
- return this.#W && 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([
4935
- s,
4936
- i,
4937
- "evict"
4938
- ])), this.#R(t1), this.#g?.[t1] && (clearTimeout(this.#g[t1]), this.#g[t1] = void 0), e1 && (this.#i[t1] = void 0, this.#t[t1] = void 0, this.#y.push(t1)), 1 === this.#n ? (this.#l = this.#h = 0, this.#y.length = 0) : this.#l = this.#a[t1], this.#s.delete(i), this.#n--, t1;
4939
- }
4940
- has(e1, t1 = {}) {
4941
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
4942
- t1.status = i, i && (i.op = "has", i.key = e1);
4943
- let s = this.#Y(e1, t1);
4944
- return S.hasSubscribers && S.publish(i), s;
4945
- }
4946
- #Y(e1, t1 = {}) {
4947
- let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = t1, n = this.#s.get(e1);
4948
- if (void 0 !== n) {
4949
- let o = this.#t[n];
4950
- if (this.#e(o) && void 0 === o.__staleWhileFetching) return !1;
4951
- if (!this.#p(n)) return i && this.#x(n), s && (s.has = "hit", this.#E(s, n)), !0;
4952
- s && (s.has = "stale", this.#E(s, n));
4953
- } else s && (s.has = "miss");
4954
- return !1;
4955
- }
4956
- peek(e1, t1 = {}) {
4957
- let { status: i = D() ? {} : void 0 } = t1;
4958
- i && (i.op = "peek", i.key = e1), t1.status = i;
4959
- let s = this.#J(e1, t1);
4960
- return S.hasSubscribers && S.publish(i), s;
4961
- }
4962
- #J(e1, t1) {
4963
- let { status: i, allowStale: s = this.allowStale } = t1, n = this.#s.get(e1);
4964
- if (void 0 === n || !s && this.#p(n)) {
4965
- i && (i.peek = void 0 === n ? "miss" : "stale");
4966
- return;
5085
+ #evict(free) {
5086
+ const head = this.#head;
5087
+ const k = this.#keyList[head];
5088
+ const v = this.#valList[head];
5089
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) v.__abortController.abort(new Error('evicted'));
5090
+ else if (this.#hasDispose || this.#hasDisposeAfter) {
5091
+ if (this.#hasDispose) this.#dispose?.(v, k, 'evict');
5092
+ if (this.#hasDisposeAfter) this.#disposed?.push([
5093
+ v,
5094
+ k,
5095
+ 'evict'
5096
+ ]);
4967
5097
  }
4968
- let o = this.#t[n], r = this.#e(o) ? o.__staleWhileFetching : o;
4969
- return i && (void 0 !== r ? (i.peek = "hit", i.value = r) : i.peek = "miss"), r;
5098
+ this.#removeItemSize(head);
5099
+ if (free) {
5100
+ this.#keyList[head] = void 0;
5101
+ this.#valList[head] = void 0;
5102
+ this.#free.push(head);
5103
+ }
5104
+ if (1 === this.#size) {
5105
+ this.#head = this.#tail = 0;
5106
+ this.#free.length = 0;
5107
+ } else this.#head = this.#next[head];
5108
+ this.#keyMap.delete(k);
5109
+ this.#size--;
5110
+ return head;
5111
+ }
5112
+ has(k, hasOptions = {}) {
5113
+ const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
5114
+ const index = this.#keyMap.get(k);
5115
+ if (void 0 !== index) {
5116
+ const v = this.#valList[index];
5117
+ if (this.#isBackgroundFetch(v) && void 0 === v.__staleWhileFetching) return false;
5118
+ if (this.#isStale(index)) {
5119
+ if (status) {
5120
+ status.has = 'stale';
5121
+ this.#statusTTL(status, index);
5122
+ }
5123
+ } else {
5124
+ if (updateAgeOnHas) this.#updateItemAge(index);
5125
+ if (status) {
5126
+ status.has = 'hit';
5127
+ this.#statusTTL(status, index);
5128
+ }
5129
+ return true;
5130
+ }
5131
+ } else if (status) status.has = 'miss';
5132
+ return false;
4970
5133
  }
4971
- #P(e1, t1, i, s) {
4972
- let n = void 0 === t1 ? void 0 : this.#t[t1];
4973
- if (this.#e(n)) return n;
4974
- let o = new AbortController, { signal: r } = i;
4975
- r?.addEventListener("abort", ()=>o.abort(r.reason), {
4976
- signal: o.signal
5134
+ peek(k, peekOptions = {}) {
5135
+ const { allowStale = this.allowStale } = peekOptions;
5136
+ const index = this.#keyMap.get(k);
5137
+ if (void 0 === index || !allowStale && this.#isStale(index)) return;
5138
+ const v = this.#valList[index];
5139
+ return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
5140
+ }
5141
+ #backgroundFetch(k, index, options, context) {
5142
+ const v = void 0 === index ? void 0 : this.#valList[index];
5143
+ if (this.#isBackgroundFetch(v)) return v;
5144
+ const ac = new AC();
5145
+ const { signal } = options;
5146
+ signal?.addEventListener('abort', ()=>ac.abort(signal.reason), {
5147
+ signal: ac.signal
4977
5148
  });
4978
- let h = {
4979
- signal: o.signal,
4980
- options: i,
4981
- context: s
4982
- }, l = (w, y = !1)=>{
4983
- let { aborted: a } = o.signal, m = i.ignoreFetchAbort && void 0 !== w, _ = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && void 0 !== w);
4984
- if (i.status && (a && !y ? (i.status.fetchAborted = !0, i.status.fetchError = o.signal.reason, m && (i.status.fetchAbortIgnored = !0)) : i.status.fetchResolved = !0), a && !m && !y) return f(o.signal.reason, _);
4985
- let b = p, d = this.#t[t1];
4986
- return (d === p || void 0 === d && m && y) && (void 0 === w ? void 0 !== b.__staleWhileFetching ? this.#t[t1] = b.__staleWhileFetching : this.#v(e1, "fetch") : (i.status && (i.status.fetchUpdated = !0), this.#O(e1, w, h.options))), w;
4987
- }, c = (w)=>(i.status && (i.status.fetchRejected = !0, i.status.fetchError = w), f(w, !1)), f = (w, y)=>{
4988
- let { aborted: a } = o.signal, m = a && i.allowStaleOnFetchAbort, _ = m || i.allowStaleOnFetchRejection, b = _ || i.noDeleteOnFetchRejection, d = p;
4989
- if (this.#t[t1] === p && (b && (y || void 0 !== d.__staleWhileFetching) ? m || (this.#t[t1] = d.__staleWhileFetching) : this.#v(e1, "fetch")), _) return i.status && void 0 !== d.__staleWhileFetching && (i.status.returnedStale = !0), d.__staleWhileFetching;
4990
- if (d.__returned === d) throw w;
4991
- }, g = (w, y)=>{
4992
- let a = this.#M?.(e1, n, h);
4993
- a && a instanceof Promise && a.then((m)=>w(void 0 === m ? void 0 : m), y), o.signal.addEventListener("abort", ()=>{
4994
- (!i.ignoreFetchAbort || i.allowStaleOnFetchAbort) && (w(void 0), i.allowStaleOnFetchAbort && (w = (m)=>l(m, !0)));
5149
+ const fetchOpts = {
5150
+ signal: ac.signal,
5151
+ options,
5152
+ context
5153
+ };
5154
+ const cb = (v, updateCache = false)=>{
5155
+ const { aborted } = ac.signal;
5156
+ const ignoreAbort = options.ignoreFetchAbort && void 0 !== v;
5157
+ if (options.status) if (aborted && !updateCache) {
5158
+ options.status.fetchAborted = true;
5159
+ options.status.fetchError = ac.signal.reason;
5160
+ if (ignoreAbort) options.status.fetchAbortIgnored = true;
5161
+ } else options.status.fetchResolved = true;
5162
+ if (aborted && !ignoreAbort && !updateCache) return fetchFail(ac.signal.reason);
5163
+ const bf = p;
5164
+ if (this.#valList[index] === p) if (void 0 === v) if (bf.__staleWhileFetching) this.#valList[index] = bf.__staleWhileFetching;
5165
+ else this.#delete(k, 'fetch');
5166
+ else {
5167
+ if (options.status) options.status.fetchUpdated = true;
5168
+ this.set(k, v, fetchOpts.options);
5169
+ }
5170
+ return v;
5171
+ };
5172
+ const eb = (er)=>{
5173
+ if (options.status) {
5174
+ options.status.fetchRejected = true;
5175
+ options.status.fetchError = er;
5176
+ }
5177
+ return fetchFail(er);
5178
+ };
5179
+ const fetchFail = (er)=>{
5180
+ const { aborted } = ac.signal;
5181
+ const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
5182
+ const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
5183
+ const noDelete = allowStale || options.noDeleteOnFetchRejection;
5184
+ const bf = p;
5185
+ if (this.#valList[index] === p) {
5186
+ const del = !noDelete || void 0 === bf.__staleWhileFetching;
5187
+ if (del) this.#delete(k, 'fetch');
5188
+ else if (!allowStaleAborted) this.#valList[index] = bf.__staleWhileFetching;
5189
+ }
5190
+ if (allowStale) {
5191
+ if (options.status && void 0 !== bf.__staleWhileFetching) options.status.returnedStale = true;
5192
+ return bf.__staleWhileFetching;
5193
+ }
5194
+ if (bf.__returned === bf) throw er;
5195
+ };
5196
+ const pcall = (res, rej)=>{
5197
+ const fmp = this.#fetchMethod?.(k, v, fetchOpts);
5198
+ if (fmp && fmp instanceof Promise) fmp.then((v)=>res(void 0 === v ? void 0 : v), rej);
5199
+ ac.signal.addEventListener('abort', ()=>{
5200
+ if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
5201
+ res(void 0);
5202
+ if (options.allowStaleOnFetchAbort) res = (v)=>cb(v, true);
5203
+ }
4995
5204
  });
4996
5205
  };
4997
- i.status && (i.status.fetchDispatched = !0);
4998
- let p = new Promise(g).then(l, c), T = Object.assign(p, {
4999
- __abortController: o,
5000
- __staleWhileFetching: n,
5206
+ if (options.status) options.status.fetchDispatched = true;
5207
+ const p = new Promise(pcall).then(cb, eb);
5208
+ const bf = Object.assign(p, {
5209
+ __abortController: ac,
5210
+ __staleWhileFetching: v,
5001
5211
  __returned: void 0
5002
5212
  });
5003
- return void 0 === t1 ? (this.#O(e1, T, {
5004
- ...h.options,
5005
- status: void 0
5006
- }), t1 = this.#s.get(e1)) : this.#t[t1] = T, T;
5007
- }
5008
- #e(e1) {
5009
- if (!this.#W) return !1;
5010
- let t1 = e1;
5011
- return !!t1 && t1 instanceof Promise && t1.hasOwnProperty("__staleWhileFetching") && t1.__abortController instanceof AbortController;
5012
- }
5013
- fetch(e1, t1 = {}) {
5014
- let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t1;
5015
- t1.status = s, s && t1.context && (s.context = t1.context);
5016
- let n = this.#B(e1, t1);
5017
- return s && D() && i && (s.trace = !0, W.tracePromise(()=>n, s).catch(()=>{})), n;
5018
- }
5019
- async #B(e1, t1 = {}) {
5020
- 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: l = this.sizeCalculation, noUpdateTTL: c = this.noUpdateTTL, noDeleteOnFetchRejection: f = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: g = this.allowStaleOnFetchRejection, ignoreFetchAbort: p = this.ignoreFetchAbort, allowStaleOnFetchAbort: T = this.allowStaleOnFetchAbort, context: w, forceRefresh: y = !1, status: a, signal: m } = t1;
5021
- if (a && (a.op = "fetch", a.key = e1, y && (a.forceRefresh = !0)), !this.#W) return a && (a.fetch = "get"), this.#C(e1, {
5022
- allowStale: i,
5023
- updateAgeOnGet: s,
5024
- noDeleteOnStaleGet: n,
5025
- status: a
5026
- });
5027
- let _ = {
5028
- allowStale: i,
5029
- updateAgeOnGet: s,
5030
- noDeleteOnStaleGet: n,
5031
- ttl: o,
5032
- noDisposeOnSet: r,
5033
- size: h,
5034
- sizeCalculation: l,
5035
- noUpdateTTL: c,
5036
- noDeleteOnFetchRejection: f,
5037
- allowStaleOnFetchRejection: g,
5038
- allowStaleOnFetchAbort: T,
5039
- ignoreFetchAbort: p,
5040
- status: a,
5041
- signal: m
5042
- }, b = this.#s.get(e1);
5043
- if (void 0 === b) {
5044
- a && (a.fetch = "miss");
5045
- let d = this.#P(e1, b, _, w);
5046
- return d.__returned = d;
5213
+ if (void 0 === index) {
5214
+ this.set(k, bf, {
5215
+ ...fetchOpts.options,
5216
+ status: void 0
5217
+ });
5218
+ index = this.#keyMap.get(k);
5219
+ } else this.#valList[index] = bf;
5220
+ return bf;
5221
+ }
5222
+ #isBackgroundFetch(p) {
5223
+ if (!this.#hasFetchMethod) return false;
5224
+ const b = p;
5225
+ return !!b && b instanceof Promise && b.hasOwnProperty('__staleWhileFetching') && b.__abortController instanceof AC;
5226
+ }
5227
+ async fetch(k, fetchOptions = {}) {
5228
+ const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal } = fetchOptions;
5229
+ if (!this.#hasFetchMethod) {
5230
+ if (status) status.fetch = 'get';
5231
+ return this.get(k, {
5232
+ allowStale,
5233
+ updateAgeOnGet,
5234
+ noDeleteOnStaleGet,
5235
+ status
5236
+ });
5237
+ }
5238
+ const options = {
5239
+ allowStale,
5240
+ updateAgeOnGet,
5241
+ noDeleteOnStaleGet,
5242
+ ttl,
5243
+ noDisposeOnSet,
5244
+ size,
5245
+ sizeCalculation,
5246
+ noUpdateTTL,
5247
+ noDeleteOnFetchRejection,
5248
+ allowStaleOnFetchRejection,
5249
+ allowStaleOnFetchAbort,
5250
+ ignoreFetchAbort,
5251
+ status,
5252
+ signal
5253
+ };
5254
+ let index = this.#keyMap.get(k);
5255
+ if (void 0 === index) {
5256
+ if (status) status.fetch = 'miss';
5257
+ const p = this.#backgroundFetch(k, index, options, context);
5258
+ return p.__returned = p;
5047
5259
  }
5048
5260
  {
5049
- let d = this.#t[b];
5050
- if (this.#e(d)) {
5051
- let E = i && void 0 !== d.__staleWhileFetching;
5052
- return a && (a.fetch = "inflight", E && (a.returnedStale = !0)), E ? d.__staleWhileFetching : d.__returned = d;
5053
- }
5054
- let A = this.#p(b);
5055
- if (!y && !A) return a && (a.fetch = "hit"), this.#L(b), s && this.#x(b), a && this.#E(a, b), d;
5056
- let z = this.#P(e1, b, _, w), v = void 0 !== z.__staleWhileFetching && i;
5057
- return a && (a.fetch = A ? "stale" : "refresh", v && A && (a.returnedStale = !0)), v ? z.__staleWhileFetching : z.__returned = z;
5058
- }
5059
- }
5060
- forceFetch(e1, t1 = {}) {
5061
- let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t1;
5062
- t1.status = s, s && t1.context && (s.context = t1.context);
5063
- let n = this.#K(e1, t1);
5064
- return s && D() && i && (s.trace = !0, W.tracePromise(()=>n, s).catch(()=>{})), n;
5065
- }
5066
- async #K(e1, t1 = {}) {
5067
- let i = await this.#B(e1, t1);
5068
- if (void 0 === i) throw new Error("fetch() returned undefined");
5069
- return i;
5070
- }
5071
- memo(e1, t1 = {}) {
5072
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
5073
- t1.status = i, i && (i.op = "memo", i.key = e1, t1.context && (i.context = t1.context));
5074
- let s = this.#Q(e1, t1);
5075
- return i && (i.value = s), S.hasSubscribers && S.publish(i), s;
5076
- }
5077
- #Q(e1, t1 = {}) {
5078
- let i = this.#U;
5079
- if (!i) throw new Error("no memoMethod provided to constructor");
5080
- let { context: s, status: n, forceRefresh: o, ...r } = t1;
5081
- n && o && (n.forceRefresh = !0);
5082
- let h = this.#C(e1, r), l = o || void 0 === h;
5083
- if (n && (n.memo = l ? "miss" : "hit", l || (n.value = h)), !l) return h;
5084
- let c = i(e1, h, {
5085
- options: r,
5086
- context: s
5261
+ const v = this.#valList[index];
5262
+ if (this.#isBackgroundFetch(v)) {
5263
+ const stale = allowStale && void 0 !== v.__staleWhileFetching;
5264
+ if (status) {
5265
+ status.fetch = 'inflight';
5266
+ if (stale) status.returnedStale = true;
5267
+ }
5268
+ return stale ? v.__staleWhileFetching : v.__returned = v;
5269
+ }
5270
+ const isStale = this.#isStale(index);
5271
+ if (!forceRefresh && !isStale) {
5272
+ if (status) status.fetch = 'hit';
5273
+ this.#moveToTail(index);
5274
+ if (updateAgeOnGet) this.#updateItemAge(index);
5275
+ if (status) this.#statusTTL(status, index);
5276
+ return v;
5277
+ }
5278
+ const p = this.#backgroundFetch(k, index, options, context);
5279
+ const hasStale = void 0 !== p.__staleWhileFetching;
5280
+ const staleVal = hasStale && allowStale;
5281
+ if (status) {
5282
+ status.fetch = isStale ? 'stale' : 'refresh';
5283
+ if (staleVal && isStale) status.returnedStale = true;
5284
+ }
5285
+ return staleVal ? p.__staleWhileFetching : p.__returned = p;
5286
+ }
5287
+ }
5288
+ async forceFetch(k, fetchOptions = {}) {
5289
+ const v = await this.fetch(k, fetchOptions);
5290
+ if (void 0 === v) throw new Error('fetch() returned undefined');
5291
+ return v;
5292
+ }
5293
+ memo(k, memoOptions = {}) {
5294
+ const memoMethod = this.#memoMethod;
5295
+ if (!memoMethod) throw new Error('no memoMethod provided to constructor');
5296
+ const { context, forceRefresh, ...options } = memoOptions;
5297
+ const v = this.get(k, options);
5298
+ if (!forceRefresh && void 0 !== v) return v;
5299
+ const vv = memoMethod(k, v, {
5300
+ options,
5301
+ context
5087
5302
  });
5088
- return n && (n.value = c), this.#O(e1, c, r), c;
5089
- }
5090
- get(e1, t1 = {}) {
5091
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
5092
- t1.status = i, i && (i.op = "get", i.key = e1);
5093
- let s = this.#C(e1, t1);
5094
- return i && (void 0 !== s && (i.value = s), S.hasSubscribers && S.publish(i)), s;
5095
- }
5096
- #C(e1, t1 = {}) {
5097
- let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = t1, r = this.#s.get(e1);
5098
- if (void 0 === r) {
5099
- o && (o.get = "miss");
5100
- return;
5303
+ this.set(k, vv, options);
5304
+ return vv;
5305
+ }
5306
+ get(k, getOptions = {}) {
5307
+ const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
5308
+ const index = this.#keyMap.get(k);
5309
+ if (void 0 !== index) {
5310
+ const value = this.#valList[index];
5311
+ const fetching = this.#isBackgroundFetch(value);
5312
+ if (status) this.#statusTTL(status, index);
5313
+ if (this.#isStale(index)) {
5314
+ if (status) status.get = 'stale';
5315
+ if (fetching) {
5316
+ if (status && allowStale && void 0 !== value.__staleWhileFetching) status.returnedStale = true;
5317
+ return allowStale ? value.__staleWhileFetching : void 0;
5318
+ }
5319
+ if (!noDeleteOnStaleGet) this.#delete(k, 'expire');
5320
+ if (status && allowStale) status.returnedStale = true;
5321
+ return allowStale ? value : void 0;
5322
+ }
5323
+ if (status) status.get = 'hit';
5324
+ if (fetching) return value.__staleWhileFetching;
5325
+ this.#moveToTail(index);
5326
+ if (updateAgeOnGet) this.#updateItemAge(index);
5327
+ return value;
5101
5328
  }
5102
- let h = this.#t[r], l = this.#e(h);
5103
- return o && this.#E(o, r), this.#p(r) ? l ? (o && (o.get = "stale-fetching"), i && void 0 !== h.__staleWhileFetching ? (o && (o.returnedStale = !0), h.__staleWhileFetching) : void 0) : (n || this.#v(e1, "expire"), o && (o.get = "stale"), i ? (o && (o.returnedStale = !0), h) : void 0) : (o && (o.get = l ? "fetching" : "hit"), this.#L(r), s && this.#x(r), l ? h.__staleWhileFetching : h);
5329
+ if (status) status.get = 'miss';
5104
5330
  }
5105
- #$(e1, t1) {
5106
- this.#c[t1] = e1, this.#a[e1] = t1;
5331
+ #connect(p, n) {
5332
+ this.#prev[n] = p;
5333
+ this.#next[p] = n;
5107
5334
  }
5108
- #L(e1) {
5109
- e1 !== this.#h && (e1 === this.#l ? this.#l = this.#a[e1] : this.#$(this.#c[e1], this.#a[e1]), this.#$(this.#h, e1), this.#h = e1);
5335
+ #moveToTail(index) {
5336
+ if (index !== this.#tail) {
5337
+ if (index === this.#head) this.#head = this.#next[index];
5338
+ else this.#connect(this.#prev[index], this.#next[index]);
5339
+ this.#connect(this.#tail, index);
5340
+ this.#tail = index;
5341
+ }
5110
5342
  }
5111
- delete(e1) {
5112
- return this.#v(e1, "delete");
5343
+ delete(k) {
5344
+ return this.#delete(k, 'delete');
5113
5345
  }
5114
- #v(e1, t1) {
5115
- S.hasSubscribers && S.publish({
5116
- op: "delete",
5117
- delete: t1,
5118
- key: e1
5119
- });
5120
- let i = !1;
5121
- if (0 !== this.#n) {
5122
- let s = this.#s.get(e1);
5123
- if (void 0 !== s) if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = void 0), i = !0, 1 === this.#n) this.#q(t1);
5124
- else {
5125
- this.#R(s);
5126
- let n = this.#t[s];
5127
- if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, e1, t1), this.#f && this.#r?.push([
5128
- n,
5129
- e1,
5130
- t1
5131
- ])), this.#s.delete(e1), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#c[s];
5132
- else if (s === this.#l) this.#l = this.#a[s];
5346
+ #delete(k, reason) {
5347
+ let deleted = false;
5348
+ if (0 !== this.#size) {
5349
+ const index = this.#keyMap.get(k);
5350
+ if (void 0 !== index) {
5351
+ deleted = true;
5352
+ if (1 === this.#size) this.#clear(reason);
5133
5353
  else {
5134
- let o = this.#c[s];
5135
- this.#a[o] = this.#a[s];
5136
- let r = this.#a[s];
5137
- this.#c[r] = this.#c[s];
5354
+ this.#removeItemSize(index);
5355
+ const v = this.#valList[index];
5356
+ if (this.#isBackgroundFetch(v)) v.__abortController.abort(new Error('deleted'));
5357
+ else if (this.#hasDispose || this.#hasDisposeAfter) {
5358
+ if (this.#hasDispose) this.#dispose?.(v, k, reason);
5359
+ if (this.#hasDisposeAfter) this.#disposed?.push([
5360
+ v,
5361
+ k,
5362
+ reason
5363
+ ]);
5364
+ }
5365
+ this.#keyMap.delete(k);
5366
+ this.#keyList[index] = void 0;
5367
+ this.#valList[index] = void 0;
5368
+ if (index === this.#tail) this.#tail = this.#prev[index];
5369
+ else if (index === this.#head) this.#head = this.#next[index];
5370
+ else {
5371
+ const pi = this.#prev[index];
5372
+ this.#next[pi] = this.#next[index];
5373
+ const ni = this.#next[index];
5374
+ this.#prev[ni] = this.#prev[index];
5375
+ }
5376
+ this.#size--;
5377
+ this.#free.push(index);
5138
5378
  }
5139
- this.#n--, this.#y.push(s);
5140
5379
  }
5141
5380
  }
5142
- if (this.#f && this.#r?.length) {
5143
- let s = this.#r, n;
5144
- for(; n = s?.shift();)this.#S?.(...n);
5381
+ if (this.#hasDisposeAfter && this.#disposed?.length) {
5382
+ const dt = this.#disposed;
5383
+ let task;
5384
+ while(task = dt?.shift())this.#disposeAfter?.(...task);
5145
5385
  }
5146
- return i;
5386
+ return deleted;
5147
5387
  }
5148
5388
  clear() {
5149
- return this.#q("delete");
5389
+ return this.#clear('delete');
5150
5390
  }
5151
- #q(e1) {
5152
- for (let t1 of this.#z({
5153
- allowStale: !0
5391
+ #clear(reason) {
5392
+ for (const index of this.#rindexes({
5393
+ allowStale: true
5154
5394
  })){
5155
- let i = this.#t[t1];
5156
- if (this.#e(i)) i.__abortController.abort(new Error("deleted"));
5395
+ const v = this.#valList[index];
5396
+ if (this.#isBackgroundFetch(v)) v.__abortController.abort(new Error('deleted'));
5157
5397
  else {
5158
- let s = this.#i[t1];
5159
- this.#T && this.#w?.(i, s, e1), this.#f && this.#r?.push([
5160
- i,
5161
- s,
5162
- e1
5398
+ const k = this.#keyList[index];
5399
+ if (this.#hasDispose) this.#dispose?.(v, k, reason);
5400
+ if (this.#hasDisposeAfter) this.#disposed?.push([
5401
+ v,
5402
+ k,
5403
+ reason
5163
5404
  ]);
5164
5405
  }
5165
5406
  }
5166
- if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#F) {
5167
- this.#d.fill(0), this.#F.fill(0);
5168
- for (let t1 of this.#g ?? [])void 0 !== t1 && clearTimeout(t1);
5169
- this.#g?.fill(void 0);
5407
+ this.#keyMap.clear();
5408
+ this.#valList.fill(void 0);
5409
+ this.#keyList.fill(void 0);
5410
+ if (this.#ttls && this.#starts) {
5411
+ this.#ttls.fill(0);
5412
+ this.#starts.fill(0);
5170
5413
  }
5171
- if (this.#_ && this.#_.fill(0), this.#l = 0, this.#h = 0, this.#y.length = 0, this.#b = 0, this.#n = 0, this.#f && this.#r) {
5172
- let t1 = this.#r, i;
5173
- for(; i = t1?.shift();)this.#S?.(...i);
5414
+ if (this.#sizes) this.#sizes.fill(0);
5415
+ this.#head = 0;
5416
+ this.#tail = 0;
5417
+ this.#free.length = 0;
5418
+ this.#calculatedSize = 0;
5419
+ this.#size = 0;
5420
+ if (this.#hasDisposeAfter && this.#disposed) {
5421
+ const dt = this.#disposed;
5422
+ let task;
5423
+ while(task = dt?.shift())this.#disposeAfter?.(...task);
5174
5424
  }
5175
5425
  }
5176
- };
5426
+ }
5177
5427
  var external_fs_ = __webpack_require__("fs");
5178
5428
  const promises_namespaceObject = require("node:fs/promises");
5179
5429
  const external_node_events_namespaceObject = require("node:events");
@@ -5250,7 +5500,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
5250
5500
  }
5251
5501
  constructor(src, dest, opts){
5252
5502
  super(src, dest, opts);
5253
- this.proxyErrors = (er)=>this.dest.emit('error', er);
5503
+ this.proxyErrors = (er)=>dest.emit('error', er);
5254
5504
  src.on('error', this.proxyErrors);
5255
5505
  }
5256
5506
  }
@@ -5702,8 +5952,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
5702
5952
  return: stop,
5703
5953
  [Symbol.asyncIterator] () {
5704
5954
  return this;
5705
- },
5706
- [Symbol.asyncDispose]: async ()=>{}
5955
+ }
5707
5956
  };
5708
5957
  }
5709
5958
  [Symbol.iterator]() {
@@ -5737,8 +5986,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
5737
5986
  return: stop,
5738
5987
  [Symbol.iterator] () {
5739
5988
  return this;
5740
- },
5741
- [Symbol.dispose]: ()=>{}
5989
+ }
5742
5990
  };
5743
5991
  }
5744
5992
  destroy(er) {
@@ -5821,14 +6069,14 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
5821
6069
  normalizeNocaseCache.set(s, n);
5822
6070
  return n;
5823
6071
  };
5824
- class ResolveCache extends L {
6072
+ class ResolveCache extends LRUCache {
5825
6073
  constructor(){
5826
6074
  super({
5827
6075
  max: 256
5828
6076
  });
5829
6077
  }
5830
6078
  }
5831
- class ChildrenCache extends L {
6079
+ class ChildrenCache extends LRUCache {
5832
6080
  constructor(maxSize = 16384){
5833
6081
  super({
5834
6082
  maxSize,
@@ -6971,586 +7219,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6971
7219
  return true;
6972
7220
  }
6973
7221
  }
6974
- const esm_proc = 'object' == typeof process && process ? process : {
6975
- stdout: null,
6976
- stderr: null
6977
- };
6978
- const esm_isStream = (s)=>!!s && 'object' == typeof s && (s instanceof esm_Minipass || s instanceof external_node_stream_namespaceObject || esm_isReadable(s) || esm_isWritable(s));
6979
- const esm_isReadable = (s)=>!!s && 'object' == typeof s && s instanceof external_node_events_namespaceObject.EventEmitter && 'function' == typeof s.pipe && s.pipe !== external_node_stream_namespaceObject.Writable.prototype.pipe;
6980
- const esm_isWritable = (s)=>!!s && 'object' == typeof s && s instanceof external_node_events_namespaceObject.EventEmitter && 'function' == typeof s.write && 'function' == typeof s.end;
6981
- const esm_EOF = Symbol('EOF');
6982
- const esm_MAYBE_EMIT_END = Symbol('maybeEmitEnd');
6983
- const esm_EMITTED_END = Symbol('emittedEnd');
6984
- const esm_EMITTING_END = Symbol('emittingEnd');
6985
- const esm_EMITTED_ERROR = Symbol('emittedError');
6986
- const esm_CLOSED = Symbol('closed');
6987
- const esm_READ = Symbol('read');
6988
- const esm_FLUSH = Symbol('flush');
6989
- const esm_FLUSHCHUNK = Symbol('flushChunk');
6990
- const esm_ENCODING = Symbol('encoding');
6991
- const esm_DECODER = Symbol('decoder');
6992
- const esm_FLOWING = Symbol('flowing');
6993
- const esm_PAUSED = Symbol('paused');
6994
- const esm_RESUME = Symbol('resume');
6995
- const esm_BUFFER = Symbol('buffer');
6996
- const esm_PIPES = Symbol('pipes');
6997
- const esm_BUFFERLENGTH = Symbol('bufferLength');
6998
- const esm_BUFFERPUSH = Symbol('bufferPush');
6999
- const esm_BUFFERSHIFT = Symbol('bufferShift');
7000
- const esm_OBJECTMODE = Symbol('objectMode');
7001
- const esm_DESTROYED = Symbol('destroyed');
7002
- const esm_ERROR = Symbol('error');
7003
- const esm_EMITDATA = Symbol('emitData');
7004
- const esm_EMITEND = Symbol('emitEnd');
7005
- const esm_EMITEND2 = Symbol('emitEnd2');
7006
- const esm_ASYNC = Symbol('async');
7007
- const esm_ABORT = Symbol('abort');
7008
- const esm_ABORTED = Symbol('aborted');
7009
- const esm_SIGNAL = Symbol('signal');
7010
- const esm_DATALISTENERS = Symbol('dataListeners');
7011
- const esm_DISCARDED = Symbol('discarded');
7012
- const esm_defer = (fn)=>Promise.resolve().then(fn);
7013
- const esm_nodefer = (fn)=>fn();
7014
- const esm_isEndish = (ev)=>'end' === ev || 'finish' === ev || 'prefinish' === ev;
7015
- const esm_isArrayBufferLike = (b)=>b instanceof ArrayBuffer || !!b && 'object' == typeof b && b.constructor && 'ArrayBuffer' === b.constructor.name && b.byteLength >= 0;
7016
- const esm_isArrayBufferView = (b)=>!Buffer.isBuffer(b) && ArrayBuffer.isView(b);
7017
- class esm_Pipe {
7018
- src;
7019
- dest;
7020
- opts;
7021
- ondrain;
7022
- constructor(src, dest, opts){
7023
- this.src = src;
7024
- this.dest = dest;
7025
- this.opts = opts;
7026
- this.ondrain = ()=>src[esm_RESUME]();
7027
- this.dest.on('drain', this.ondrain);
7028
- }
7029
- unpipe() {
7030
- this.dest.removeListener('drain', this.ondrain);
7031
- }
7032
- proxyErrors(_er) {}
7033
- end() {
7034
- this.unpipe();
7035
- if (this.opts.end) this.dest.end();
7036
- }
7037
- }
7038
- class esm_PipeProxyErrors extends esm_Pipe {
7039
- unpipe() {
7040
- this.src.removeListener('error', this.proxyErrors);
7041
- super.unpipe();
7042
- }
7043
- constructor(src, dest, opts){
7044
- super(src, dest, opts);
7045
- this.proxyErrors = (er)=>dest.emit('error', er);
7046
- src.on('error', this.proxyErrors);
7047
- }
7048
- }
7049
- const esm_isObjectModeOptions = (o)=>!!o.objectMode;
7050
- const esm_isEncodingOptions = (o)=>!o.objectMode && !!o.encoding && 'buffer' !== o.encoding;
7051
- class esm_Minipass extends external_node_events_namespaceObject.EventEmitter {
7052
- [esm_FLOWING] = false;
7053
- [esm_PAUSED] = false;
7054
- [esm_PIPES] = [];
7055
- [esm_BUFFER] = [];
7056
- [esm_OBJECTMODE];
7057
- [esm_ENCODING];
7058
- [esm_ASYNC];
7059
- [esm_DECODER];
7060
- [esm_EOF] = false;
7061
- [esm_EMITTED_END] = false;
7062
- [esm_EMITTING_END] = false;
7063
- [esm_CLOSED] = false;
7064
- [esm_EMITTED_ERROR] = null;
7065
- [esm_BUFFERLENGTH] = 0;
7066
- [esm_DESTROYED] = false;
7067
- [esm_SIGNAL];
7068
- [esm_ABORTED] = false;
7069
- [esm_DATALISTENERS] = 0;
7070
- [esm_DISCARDED] = false;
7071
- writable = true;
7072
- readable = true;
7073
- constructor(...args){
7074
- const options = args[0] || {};
7075
- super();
7076
- if (options.objectMode && 'string' == typeof options.encoding) throw new TypeError('Encoding and objectMode may not be used together');
7077
- if (esm_isObjectModeOptions(options)) {
7078
- this[esm_OBJECTMODE] = true;
7079
- this[esm_ENCODING] = null;
7080
- } else if (esm_isEncodingOptions(options)) {
7081
- this[esm_ENCODING] = options.encoding;
7082
- this[esm_OBJECTMODE] = false;
7083
- } else {
7084
- this[esm_OBJECTMODE] = false;
7085
- this[esm_ENCODING] = null;
7086
- }
7087
- this[esm_ASYNC] = !!options.async;
7088
- this[esm_DECODER] = this[esm_ENCODING] ? new external_node_string_decoder_namespaceObject.StringDecoder(this[esm_ENCODING]) : null;
7089
- if (options && true === options.debugExposeBuffer) Object.defineProperty(this, 'buffer', {
7090
- get: ()=>this[esm_BUFFER]
7091
- });
7092
- if (options && true === options.debugExposePipes) Object.defineProperty(this, 'pipes', {
7093
- get: ()=>this[esm_PIPES]
7094
- });
7095
- const { signal } = options;
7096
- if (signal) {
7097
- this[esm_SIGNAL] = signal;
7098
- if (signal.aborted) this[esm_ABORT]();
7099
- else signal.addEventListener('abort', ()=>this[esm_ABORT]());
7100
- }
7101
- }
7102
- get bufferLength() {
7103
- return this[esm_BUFFERLENGTH];
7104
- }
7105
- get encoding() {
7106
- return this[esm_ENCODING];
7107
- }
7108
- set encoding(_enc) {
7109
- throw new Error('Encoding must be set at instantiation time');
7110
- }
7111
- setEncoding(_enc) {
7112
- throw new Error('Encoding must be set at instantiation time');
7113
- }
7114
- get objectMode() {
7115
- return this[esm_OBJECTMODE];
7116
- }
7117
- set objectMode(_om) {
7118
- throw new Error('objectMode must be set at instantiation time');
7119
- }
7120
- get ['async']() {
7121
- return this[esm_ASYNC];
7122
- }
7123
- set ['async'](a) {
7124
- this[esm_ASYNC] = this[esm_ASYNC] || !!a;
7125
- }
7126
- [esm_ABORT]() {
7127
- this[esm_ABORTED] = true;
7128
- this.emit('abort', this[esm_SIGNAL]?.reason);
7129
- this.destroy(this[esm_SIGNAL]?.reason);
7130
- }
7131
- get aborted() {
7132
- return this[esm_ABORTED];
7133
- }
7134
- set aborted(_) {}
7135
- write(chunk, encoding, cb) {
7136
- if (this[esm_ABORTED]) return false;
7137
- if (this[esm_EOF]) throw new Error('write after end');
7138
- if (this[esm_DESTROYED]) {
7139
- this.emit('error', Object.assign(new Error('Cannot call write after a stream was destroyed'), {
7140
- code: 'ERR_STREAM_DESTROYED'
7141
- }));
7142
- return true;
7143
- }
7144
- if ('function' == typeof encoding) {
7145
- cb = encoding;
7146
- encoding = 'utf8';
7147
- }
7148
- if (!encoding) encoding = 'utf8';
7149
- const fn = this[esm_ASYNC] ? esm_defer : esm_nodefer;
7150
- if (!this[esm_OBJECTMODE] && !Buffer.isBuffer(chunk)) {
7151
- if (esm_isArrayBufferView(chunk)) chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
7152
- else if (esm_isArrayBufferLike(chunk)) chunk = Buffer.from(chunk);
7153
- else if ('string' != typeof chunk) throw new Error('Non-contiguous data written to non-objectMode stream');
7154
- }
7155
- if (this[esm_OBJECTMODE]) {
7156
- if (this[esm_FLOWING] && 0 !== this[esm_BUFFERLENGTH]) this[esm_FLUSH](true);
7157
- if (this[esm_FLOWING]) this.emit('data', chunk);
7158
- else this[esm_BUFFERPUSH](chunk);
7159
- if (0 !== this[esm_BUFFERLENGTH]) this.emit('readable');
7160
- if (cb) fn(cb);
7161
- return this[esm_FLOWING];
7162
- }
7163
- if (!chunk.length) {
7164
- if (0 !== this[esm_BUFFERLENGTH]) this.emit('readable');
7165
- if (cb) fn(cb);
7166
- return this[esm_FLOWING];
7167
- }
7168
- if ('string' == typeof chunk && !(encoding === this[esm_ENCODING] && !this[esm_DECODER]?.lastNeed)) chunk = Buffer.from(chunk, encoding);
7169
- if (Buffer.isBuffer(chunk) && this[esm_ENCODING]) chunk = this[esm_DECODER].write(chunk);
7170
- if (this[esm_FLOWING] && 0 !== this[esm_BUFFERLENGTH]) this[esm_FLUSH](true);
7171
- if (this[esm_FLOWING]) this.emit('data', chunk);
7172
- else this[esm_BUFFERPUSH](chunk);
7173
- if (0 !== this[esm_BUFFERLENGTH]) this.emit('readable');
7174
- if (cb) fn(cb);
7175
- return this[esm_FLOWING];
7176
- }
7177
- read(n) {
7178
- if (this[esm_DESTROYED]) return null;
7179
- this[esm_DISCARDED] = false;
7180
- if (0 === this[esm_BUFFERLENGTH] || 0 === n || n && n > this[esm_BUFFERLENGTH]) {
7181
- this[esm_MAYBE_EMIT_END]();
7182
- return null;
7183
- }
7184
- if (this[esm_OBJECTMODE]) n = null;
7185
- if (this[esm_BUFFER].length > 1 && !this[esm_OBJECTMODE]) this[esm_BUFFER] = [
7186
- this[esm_ENCODING] ? this[esm_BUFFER].join('') : Buffer.concat(this[esm_BUFFER], this[esm_BUFFERLENGTH])
7187
- ];
7188
- const ret = this[esm_READ](n || null, this[esm_BUFFER][0]);
7189
- this[esm_MAYBE_EMIT_END]();
7190
- return ret;
7191
- }
7192
- [esm_READ](n, chunk) {
7193
- if (this[esm_OBJECTMODE]) this[esm_BUFFERSHIFT]();
7194
- else {
7195
- const c = chunk;
7196
- if (n === c.length || null === n) this[esm_BUFFERSHIFT]();
7197
- else if ('string' == typeof c) {
7198
- this[esm_BUFFER][0] = c.slice(n);
7199
- chunk = c.slice(0, n);
7200
- this[esm_BUFFERLENGTH] -= n;
7201
- } else {
7202
- this[esm_BUFFER][0] = c.subarray(n);
7203
- chunk = c.subarray(0, n);
7204
- this[esm_BUFFERLENGTH] -= n;
7205
- }
7206
- }
7207
- this.emit('data', chunk);
7208
- if (!this[esm_BUFFER].length && !this[esm_EOF]) this.emit('drain');
7209
- return chunk;
7210
- }
7211
- end(chunk, encoding, cb) {
7212
- if ('function' == typeof chunk) {
7213
- cb = chunk;
7214
- chunk = void 0;
7215
- }
7216
- if ('function' == typeof encoding) {
7217
- cb = encoding;
7218
- encoding = 'utf8';
7219
- }
7220
- if (void 0 !== chunk) this.write(chunk, encoding);
7221
- if (cb) this.once('end', cb);
7222
- this[esm_EOF] = true;
7223
- this.writable = false;
7224
- if (this[esm_FLOWING] || !this[esm_PAUSED]) this[esm_MAYBE_EMIT_END]();
7225
- return this;
7226
- }
7227
- [esm_RESUME]() {
7228
- if (this[esm_DESTROYED]) return;
7229
- if (!this[esm_DATALISTENERS] && !this[esm_PIPES].length) this[esm_DISCARDED] = true;
7230
- this[esm_PAUSED] = false;
7231
- this[esm_FLOWING] = true;
7232
- this.emit('resume');
7233
- if (this[esm_BUFFER].length) this[esm_FLUSH]();
7234
- else if (this[esm_EOF]) this[esm_MAYBE_EMIT_END]();
7235
- else this.emit('drain');
7236
- }
7237
- resume() {
7238
- return this[esm_RESUME]();
7239
- }
7240
- pause() {
7241
- this[esm_FLOWING] = false;
7242
- this[esm_PAUSED] = true;
7243
- this[esm_DISCARDED] = false;
7244
- }
7245
- get destroyed() {
7246
- return this[esm_DESTROYED];
7247
- }
7248
- get flowing() {
7249
- return this[esm_FLOWING];
7250
- }
7251
- get paused() {
7252
- return this[esm_PAUSED];
7253
- }
7254
- [esm_BUFFERPUSH](chunk) {
7255
- if (this[esm_OBJECTMODE]) this[esm_BUFFERLENGTH] += 1;
7256
- else this[esm_BUFFERLENGTH] += chunk.length;
7257
- this[esm_BUFFER].push(chunk);
7258
- }
7259
- [esm_BUFFERSHIFT]() {
7260
- if (this[esm_OBJECTMODE]) this[esm_BUFFERLENGTH] -= 1;
7261
- else this[esm_BUFFERLENGTH] -= this[esm_BUFFER][0].length;
7262
- return this[esm_BUFFER].shift();
7263
- }
7264
- [esm_FLUSH](noDrain = false) {
7265
- do ;
7266
- while (this[esm_FLUSHCHUNK](this[esm_BUFFERSHIFT]()) && this[esm_BUFFER].length);
7267
- if (!noDrain && !this[esm_BUFFER].length && !this[esm_EOF]) this.emit('drain');
7268
- }
7269
- [esm_FLUSHCHUNK](chunk) {
7270
- this.emit('data', chunk);
7271
- return this[esm_FLOWING];
7272
- }
7273
- pipe(dest, opts) {
7274
- if (this[esm_DESTROYED]) return dest;
7275
- this[esm_DISCARDED] = false;
7276
- const ended = this[esm_EMITTED_END];
7277
- opts = opts || {};
7278
- if (dest === esm_proc.stdout || dest === esm_proc.stderr) opts.end = false;
7279
- else opts.end = false !== opts.end;
7280
- opts.proxyErrors = !!opts.proxyErrors;
7281
- if (ended) {
7282
- if (opts.end) dest.end();
7283
- } else {
7284
- this[esm_PIPES].push(opts.proxyErrors ? new esm_PipeProxyErrors(this, dest, opts) : new esm_Pipe(this, dest, opts));
7285
- if (this[esm_ASYNC]) esm_defer(()=>this[esm_RESUME]());
7286
- else this[esm_RESUME]();
7287
- }
7288
- return dest;
7289
- }
7290
- unpipe(dest) {
7291
- const p = this[esm_PIPES].find((p)=>p.dest === dest);
7292
- if (p) {
7293
- if (1 === this[esm_PIPES].length) {
7294
- if (this[esm_FLOWING] && 0 === this[esm_DATALISTENERS]) this[esm_FLOWING] = false;
7295
- this[esm_PIPES] = [];
7296
- } else this[esm_PIPES].splice(this[esm_PIPES].indexOf(p), 1);
7297
- p.unpipe();
7298
- }
7299
- }
7300
- addListener(ev, handler) {
7301
- return this.on(ev, handler);
7302
- }
7303
- on(ev, handler) {
7304
- const ret = super.on(ev, handler);
7305
- if ('data' === ev) {
7306
- this[esm_DISCARDED] = false;
7307
- this[esm_DATALISTENERS]++;
7308
- if (!this[esm_PIPES].length && !this[esm_FLOWING]) this[esm_RESUME]();
7309
- } else if ('readable' === ev && 0 !== this[esm_BUFFERLENGTH]) super.emit('readable');
7310
- else if (esm_isEndish(ev) && this[esm_EMITTED_END]) {
7311
- super.emit(ev);
7312
- this.removeAllListeners(ev);
7313
- } else if ('error' === ev && this[esm_EMITTED_ERROR]) {
7314
- const h = handler;
7315
- if (this[esm_ASYNC]) esm_defer(()=>h.call(this, this[esm_EMITTED_ERROR]));
7316
- else h.call(this, this[esm_EMITTED_ERROR]);
7317
- }
7318
- return ret;
7319
- }
7320
- removeListener(ev, handler) {
7321
- return this.off(ev, handler);
7322
- }
7323
- off(ev, handler) {
7324
- const ret = super.off(ev, handler);
7325
- if ('data' === ev) {
7326
- this[esm_DATALISTENERS] = this.listeners('data').length;
7327
- if (0 === this[esm_DATALISTENERS] && !this[esm_DISCARDED] && !this[esm_PIPES].length) this[esm_FLOWING] = false;
7328
- }
7329
- return ret;
7330
- }
7331
- removeAllListeners(ev) {
7332
- const ret = super.removeAllListeners(ev);
7333
- if ('data' === ev || void 0 === ev) {
7334
- this[esm_DATALISTENERS] = 0;
7335
- if (!this[esm_DISCARDED] && !this[esm_PIPES].length) this[esm_FLOWING] = false;
7336
- }
7337
- return ret;
7338
- }
7339
- get emittedEnd() {
7340
- return this[esm_EMITTED_END];
7341
- }
7342
- [esm_MAYBE_EMIT_END]() {
7343
- if (!this[esm_EMITTING_END] && !this[esm_EMITTED_END] && !this[esm_DESTROYED] && 0 === this[esm_BUFFER].length && this[esm_EOF]) {
7344
- this[esm_EMITTING_END] = true;
7345
- this.emit('end');
7346
- this.emit('prefinish');
7347
- this.emit('finish');
7348
- if (this[esm_CLOSED]) this.emit('close');
7349
- this[esm_EMITTING_END] = false;
7350
- }
7351
- }
7352
- emit(ev, ...args) {
7353
- const data = args[0];
7354
- if ('error' !== ev && 'close' !== ev && ev !== esm_DESTROYED && this[esm_DESTROYED]) return false;
7355
- if ('data' === ev) return this[esm_OBJECTMODE] || data ? this[esm_ASYNC] ? (esm_defer(()=>this[esm_EMITDATA](data)), true) : this[esm_EMITDATA](data) : false;
7356
- if ('end' === ev) return this[esm_EMITEND]();
7357
- if ('close' === ev) {
7358
- this[esm_CLOSED] = true;
7359
- if (!this[esm_EMITTED_END] && !this[esm_DESTROYED]) return false;
7360
- const ret = super.emit('close');
7361
- this.removeAllListeners('close');
7362
- return ret;
7363
- }
7364
- if ('error' === ev) {
7365
- this[esm_EMITTED_ERROR] = data;
7366
- super.emit(esm_ERROR, data);
7367
- const ret = !this[esm_SIGNAL] || this.listeners('error').length ? super.emit('error', data) : false;
7368
- this[esm_MAYBE_EMIT_END]();
7369
- return ret;
7370
- } else if ('resume' === ev) {
7371
- const ret = super.emit('resume');
7372
- this[esm_MAYBE_EMIT_END]();
7373
- return ret;
7374
- } else if ('finish' === ev || 'prefinish' === ev) {
7375
- const ret = super.emit(ev);
7376
- this.removeAllListeners(ev);
7377
- return ret;
7378
- }
7379
- const ret = super.emit(ev, ...args);
7380
- this[esm_MAYBE_EMIT_END]();
7381
- return ret;
7382
- }
7383
- [esm_EMITDATA](data) {
7384
- for (const p of this[esm_PIPES])if (false === p.dest.write(data)) this.pause();
7385
- const ret = this[esm_DISCARDED] ? false : super.emit('data', data);
7386
- this[esm_MAYBE_EMIT_END]();
7387
- return ret;
7388
- }
7389
- [esm_EMITEND]() {
7390
- if (this[esm_EMITTED_END]) return false;
7391
- this[esm_EMITTED_END] = true;
7392
- this.readable = false;
7393
- return this[esm_ASYNC] ? (esm_defer(()=>this[esm_EMITEND2]()), true) : this[esm_EMITEND2]();
7394
- }
7395
- [esm_EMITEND2]() {
7396
- if (this[esm_DECODER]) {
7397
- const data = this[esm_DECODER].end();
7398
- if (data) {
7399
- for (const p of this[esm_PIPES])p.dest.write(data);
7400
- if (!this[esm_DISCARDED]) super.emit('data', data);
7401
- }
7402
- }
7403
- for (const p of this[esm_PIPES])p.end();
7404
- const ret = super.emit('end');
7405
- this.removeAllListeners('end');
7406
- return ret;
7407
- }
7408
- async collect() {
7409
- const buf = Object.assign([], {
7410
- dataLength: 0
7411
- });
7412
- if (!this[esm_OBJECTMODE]) buf.dataLength = 0;
7413
- const p = this.promise();
7414
- this.on('data', (c)=>{
7415
- buf.push(c);
7416
- if (!this[esm_OBJECTMODE]) buf.dataLength += c.length;
7417
- });
7418
- await p;
7419
- return buf;
7420
- }
7421
- async concat() {
7422
- if (this[esm_OBJECTMODE]) throw new Error('cannot concat in objectMode');
7423
- const buf = await this.collect();
7424
- return this[esm_ENCODING] ? buf.join('') : Buffer.concat(buf, buf.dataLength);
7425
- }
7426
- async promise() {
7427
- return new Promise((resolve, reject)=>{
7428
- this.on(esm_DESTROYED, ()=>reject(new Error('stream destroyed')));
7429
- this.on('error', (er)=>reject(er));
7430
- this.on('end', ()=>resolve());
7431
- });
7432
- }
7433
- [Symbol.asyncIterator]() {
7434
- this[esm_DISCARDED] = false;
7435
- let stopped = false;
7436
- const stop = async ()=>{
7437
- this.pause();
7438
- stopped = true;
7439
- return {
7440
- value: void 0,
7441
- done: true
7442
- };
7443
- };
7444
- const next = ()=>{
7445
- if (stopped) return stop();
7446
- const res = this.read();
7447
- if (null !== res) return Promise.resolve({
7448
- done: false,
7449
- value: res
7450
- });
7451
- if (this[esm_EOF]) return stop();
7452
- let resolve;
7453
- let reject;
7454
- const onerr = (er)=>{
7455
- this.off('data', ondata);
7456
- this.off('end', onend);
7457
- this.off(esm_DESTROYED, ondestroy);
7458
- stop();
7459
- reject(er);
7460
- };
7461
- const ondata = (value)=>{
7462
- this.off('error', onerr);
7463
- this.off('end', onend);
7464
- this.off(esm_DESTROYED, ondestroy);
7465
- this.pause();
7466
- resolve({
7467
- value,
7468
- done: !!this[esm_EOF]
7469
- });
7470
- };
7471
- const onend = ()=>{
7472
- this.off('error', onerr);
7473
- this.off('data', ondata);
7474
- this.off(esm_DESTROYED, ondestroy);
7475
- stop();
7476
- resolve({
7477
- done: true,
7478
- value: void 0
7479
- });
7480
- };
7481
- const ondestroy = ()=>onerr(new Error('stream destroyed'));
7482
- return new Promise((res, rej)=>{
7483
- reject = rej;
7484
- resolve = res;
7485
- this.once(esm_DESTROYED, ondestroy);
7486
- this.once('error', onerr);
7487
- this.once('end', onend);
7488
- this.once('data', ondata);
7489
- });
7490
- };
7491
- return {
7492
- next,
7493
- throw: stop,
7494
- return: stop,
7495
- [Symbol.asyncIterator] () {
7496
- return this;
7497
- }
7498
- };
7499
- }
7500
- [Symbol.iterator]() {
7501
- this[esm_DISCARDED] = false;
7502
- let stopped = false;
7503
- const stop = ()=>{
7504
- this.pause();
7505
- this.off(esm_ERROR, stop);
7506
- this.off(esm_DESTROYED, stop);
7507
- this.off('end', stop);
7508
- stopped = true;
7509
- return {
7510
- done: true,
7511
- value: void 0
7512
- };
7513
- };
7514
- const next = ()=>{
7515
- if (stopped) return stop();
7516
- const value = this.read();
7517
- return null === value ? stop() : {
7518
- done: false,
7519
- value
7520
- };
7521
- };
7522
- this.once('end', stop);
7523
- this.once(esm_ERROR, stop);
7524
- this.once(esm_DESTROYED, stop);
7525
- return {
7526
- next,
7527
- throw: stop,
7528
- return: stop,
7529
- [Symbol.iterator] () {
7530
- return this;
7531
- }
7532
- };
7533
- }
7534
- destroy(er) {
7535
- if (this[esm_DESTROYED]) {
7536
- if (er) this.emit('error', er);
7537
- else this.emit(esm_DESTROYED);
7538
- return this;
7539
- }
7540
- this[esm_DESTROYED] = true;
7541
- this[esm_DISCARDED] = true;
7542
- this[esm_BUFFER].length = 0;
7543
- this[esm_BUFFERLENGTH] = 0;
7544
- const wc = this;
7545
- if ('function' == typeof wc.close && !this[esm_CLOSED]) wc.close();
7546
- if (er) this.emit('error', er);
7547
- else this.emit(esm_DESTROYED);
7548
- return this;
7549
- }
7550
- static get isStream() {
7551
- return esm_isStream;
7552
- }
7553
- }
7554
7222
  const ignore_defaultPlatform = 'object' == typeof process && process && 'string' == typeof process.platform ? process.platform : 'linux';
7555
7223
  class Ignore {
7556
7224
  relative;
@@ -8029,7 +7697,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
8029
7697
  results;
8030
7698
  constructor(patterns, path, opts){
8031
7699
  super(patterns, path, opts);
8032
- this.results = new esm_Minipass({
7700
+ this.results = new Minipass({
8033
7701
  signal: this.signal,
8034
7702
  objectMode: true
8035
7703
  });
@@ -11542,7 +11210,7 @@ Usage:
11542
11210
  type: 'boolean',
11543
11211
  description: `Turn on logging to help debug why certain keys or values are not being set as you expect, default is ${config_factory_defaultConfig.dotenvDebug}`
11544
11212
  }
11545
- }).version('version', 'Show version number', "1.8.10-beta-20260604215059.0").help().epilogue(`For complete list of configuration options, please visit:
11213
+ }).version('version', 'Show version number', "1.9.0").help().epilogue(`For complete list of configuration options, please visit:
11546
11214
  • Web options: https://midscenejs.com/automate-with-scripts-in-yaml#the-web-part
11547
11215
  • Android options: https://midscenejs.com/automate-with-scripts-in-yaml#the-android-part
11548
11216
  • iOS options: https://midscenejs.com/automate-with-scripts-in-yaml#the-ios-part