@midscene/cli 1.8.8-beta-20260602094353.0 → 1.8.8

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
@@ -262,6 +262,200 @@ var __webpack_modules__ = {
262
262
  get: assembleStyles
263
263
  });
264
264
  },
265
+ "../../node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js" (module) {
266
+ "use strict";
267
+ module.exports = balanced;
268
+ function balanced(a, b, str) {
269
+ if (a instanceof RegExp) a = maybeMatch(a, str);
270
+ if (b instanceof RegExp) b = maybeMatch(b, str);
271
+ var r = range(a, b, str);
272
+ return r && {
273
+ start: r[0],
274
+ end: r[1],
275
+ pre: str.slice(0, r[0]),
276
+ body: str.slice(r[0] + a.length, r[1]),
277
+ post: str.slice(r[1] + b.length)
278
+ };
279
+ }
280
+ function maybeMatch(reg, str) {
281
+ var m = str.match(reg);
282
+ return m ? m[0] : null;
283
+ }
284
+ balanced.range = range;
285
+ function range(a, b, str) {
286
+ var begs, beg, left, right, result;
287
+ var ai = str.indexOf(a);
288
+ var bi = str.indexOf(b, ai + 1);
289
+ var i = ai;
290
+ if (ai >= 0 && bi > 0) {
291
+ if (a === b) return [
292
+ ai,
293
+ bi
294
+ ];
295
+ begs = [];
296
+ left = str.length;
297
+ while(i >= 0 && !result){
298
+ if (i == ai) {
299
+ begs.push(i);
300
+ ai = str.indexOf(a, i + 1);
301
+ } else if (1 == begs.length) result = [
302
+ begs.pop(),
303
+ bi
304
+ ];
305
+ else {
306
+ beg = begs.pop();
307
+ if (beg < left) {
308
+ left = beg;
309
+ right = bi;
310
+ }
311
+ bi = str.indexOf(b, i + 1);
312
+ }
313
+ i = ai < bi && ai >= 0 ? ai : bi;
314
+ }
315
+ if (begs.length) result = [
316
+ left,
317
+ right
318
+ ];
319
+ }
320
+ return result;
321
+ }
322
+ },
323
+ "../../node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js" (module, __unused_rspack_exports, __webpack_require__) {
324
+ var balanced = __webpack_require__("../../node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js");
325
+ module.exports = expandTop;
326
+ var escSlash = '\0SLASH' + Math.random() + '\0';
327
+ var escOpen = '\0OPEN' + Math.random() + '\0';
328
+ var escClose = '\0CLOSE' + Math.random() + '\0';
329
+ var escComma = '\0COMMA' + Math.random() + '\0';
330
+ var escPeriod = '\0PERIOD' + Math.random() + '\0';
331
+ function numeric(str) {
332
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
333
+ }
334
+ function escapeBraces(str) {
335
+ return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
336
+ }
337
+ function unescapeBraces(str) {
338
+ return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
339
+ }
340
+ function parseCommaParts(str) {
341
+ if (!str) return [
342
+ ''
343
+ ];
344
+ var parts = [];
345
+ var m = balanced('{', '}', str);
346
+ if (!m) return str.split(',');
347
+ var pre = m.pre;
348
+ var body = m.body;
349
+ var post = m.post;
350
+ var p = pre.split(',');
351
+ p[p.length - 1] += '{' + body + '}';
352
+ var postParts = parseCommaParts(post);
353
+ if (post.length) {
354
+ p[p.length - 1] += postParts.shift();
355
+ p.push.apply(p, postParts);
356
+ }
357
+ parts.push.apply(parts, p);
358
+ return parts;
359
+ }
360
+ function expandTop(str) {
361
+ if (!str) return [];
362
+ if ('{}' === str.substr(0, 2)) str = '\\{\\}' + str.substr(2);
363
+ return expand(escapeBraces(str), true).map(unescapeBraces);
364
+ }
365
+ function embrace(str) {
366
+ return '{' + str + '}';
367
+ }
368
+ function isPadded(el) {
369
+ return /^-?0\d/.test(el);
370
+ }
371
+ function lte(i, y) {
372
+ return i <= y;
373
+ }
374
+ function gte(i, y) {
375
+ return i >= y;
376
+ }
377
+ function expand(str, isTop) {
378
+ var expansions = [];
379
+ var m = balanced('{', '}', str);
380
+ if (!m) return [
381
+ str
382
+ ];
383
+ var pre = m.pre;
384
+ var post = m.post.length ? expand(m.post, false) : [
385
+ ''
386
+ ];
387
+ if (/\$$/.test(m.pre)) for(var k = 0; k < post.length; k++){
388
+ var expansion = pre + '{' + m.body + '}' + post[k];
389
+ expansions.push(expansion);
390
+ }
391
+ else {
392
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
393
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
394
+ var isSequence = isNumericSequence || isAlphaSequence;
395
+ var isOptions = m.body.indexOf(',') >= 0;
396
+ if (!isSequence && !isOptions) {
397
+ if (m.post.match(/,.*\}/)) {
398
+ str = m.pre + '{' + m.body + escClose + m.post;
399
+ return expand(str);
400
+ }
401
+ return [
402
+ str
403
+ ];
404
+ }
405
+ var n;
406
+ if (isSequence) n = m.body.split(/\.\./);
407
+ else {
408
+ n = parseCommaParts(m.body);
409
+ if (1 === n.length) {
410
+ n = expand(n[0], false).map(embrace);
411
+ if (1 === n.length) return post.map(function(p) {
412
+ return m.pre + n[0] + p;
413
+ });
414
+ }
415
+ }
416
+ var N;
417
+ if (isSequence) {
418
+ var x = numeric(n[0]);
419
+ var y = numeric(n[1]);
420
+ var width = Math.max(n[0].length, n[1].length);
421
+ var incr = 3 == n.length ? Math.abs(numeric(n[2])) : 1;
422
+ var test = lte;
423
+ var reverse = y < x;
424
+ if (reverse) {
425
+ incr *= -1;
426
+ test = gte;
427
+ }
428
+ var pad = n.some(isPadded);
429
+ N = [];
430
+ for(var i = x; test(i, y); i += incr){
431
+ var c;
432
+ if (isAlphaSequence) {
433
+ c = String.fromCharCode(i);
434
+ if ('\\' === c) c = '';
435
+ } else {
436
+ c = String(i);
437
+ if (pad) {
438
+ var need = width - c.length;
439
+ if (need > 0) {
440
+ var z = new Array(need + 1).join('0');
441
+ c = i < 0 ? '-' + z + c.slice(1) : z + c;
442
+ }
443
+ }
444
+ }
445
+ N.push(c);
446
+ }
447
+ } else {
448
+ N = [];
449
+ for(var j = 0; j < n.length; j++)N.push.apply(N, expand(n[j], false));
450
+ }
451
+ for(var j = 0; j < N.length; j++)for(var k = 0; k < post.length; k++){
452
+ var expansion = pre + N[j] + post[k];
453
+ if (!isTop || isSequence || expansion) expansions.push(expansion);
454
+ }
455
+ }
456
+ return expansions;
457
+ }
458
+ },
265
459
  "../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js" (module, __unused_rspack_exports, __webpack_require__) {
266
460
  "use strict";
267
461
  const ansiStyles = __webpack_require__("../../node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js");
@@ -3180,203 +3374,11 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3180
3374
  const cli_namespaceObject = require("@midscene/shared/cli");
3181
3375
  var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js");
3182
3376
  var main_default = /*#__PURE__*/ __webpack_require__.n(main);
3183
- var package_namespaceObject = JSON.parse('{"rE":"1.8.8-beta-20260602094353.0"}');
3184
- var logger_ = __webpack_require__("@midscene/shared/logger");
3185
- const balanced = (a, b, str)=>{
3186
- const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
3187
- const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
3188
- const r = null !== ma && null != mb && range(ma, mb, str);
3189
- return r && {
3190
- start: r[0],
3191
- end: r[1],
3192
- pre: str.slice(0, r[0]),
3193
- body: str.slice(r[0] + ma.length, r[1]),
3194
- post: str.slice(r[1] + mb.length)
3195
- };
3196
- };
3197
- const maybeMatch = (reg, str)=>{
3198
- const m = str.match(reg);
3199
- return m ? m[0] : null;
3200
- };
3201
- const range = (a, b, str)=>{
3202
- let begs, beg, left, right, result;
3203
- let ai = str.indexOf(a);
3204
- let bi = str.indexOf(b, ai + 1);
3205
- let i = ai;
3206
- if (ai >= 0 && bi > 0) {
3207
- if (a === b) return [
3208
- ai,
3209
- bi
3210
- ];
3211
- begs = [];
3212
- left = str.length;
3213
- while(i >= 0 && !result){
3214
- if (i === ai) {
3215
- begs.push(i);
3216
- ai = str.indexOf(a, i + 1);
3217
- } else if (1 === begs.length) {
3218
- const r = begs.pop();
3219
- if (void 0 !== r) result = [
3220
- r,
3221
- bi
3222
- ];
3223
- } else {
3224
- beg = begs.pop();
3225
- if (void 0 !== beg && beg < left) {
3226
- left = beg;
3227
- right = bi;
3228
- }
3229
- bi = str.indexOf(b, i + 1);
3230
- }
3231
- i = ai < bi && ai >= 0 ? ai : bi;
3232
- }
3233
- if (begs.length && void 0 !== right) result = [
3234
- left,
3235
- right
3236
- ];
3237
- }
3238
- return result;
3377
+ var package_namespaceObject = {
3378
+ rE: "1.8.8"
3239
3379
  };
3240
- const escSlash = '\0SLASH' + Math.random() + '\0';
3241
- const escOpen = '\0OPEN' + Math.random() + '\0';
3242
- const escClose = '\0CLOSE' + Math.random() + '\0';
3243
- const escComma = '\0COMMA' + Math.random() + '\0';
3244
- const escPeriod = '\0PERIOD' + Math.random() + '\0';
3245
- const escSlashPattern = new RegExp(escSlash, 'g');
3246
- const escOpenPattern = new RegExp(escOpen, 'g');
3247
- const escClosePattern = new RegExp(escClose, 'g');
3248
- const escCommaPattern = new RegExp(escComma, 'g');
3249
- const escPeriodPattern = new RegExp(escPeriod, 'g');
3250
- const slashPattern = /\\\\/g;
3251
- const openPattern = /\\{/g;
3252
- const closePattern = /\\}/g;
3253
- const commaPattern = /\\,/g;
3254
- const periodPattern = /\\\./g;
3255
- const EXPANSION_MAX = 100000;
3256
- function numeric(str) {
3257
- return isNaN(str) ? str.charCodeAt(0) : parseInt(str, 10);
3258
- }
3259
- function escapeBraces(str) {
3260
- return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
3261
- }
3262
- function unescapeBraces(str) {
3263
- return str.replace(escSlashPattern, '\\').replace(escOpenPattern, '{').replace(escClosePattern, '}').replace(escCommaPattern, ',').replace(escPeriodPattern, '.');
3264
- }
3265
- function parseCommaParts(str) {
3266
- if (!str) return [
3267
- ''
3268
- ];
3269
- const parts = [];
3270
- const m = balanced('{', '}', str);
3271
- if (!m) return str.split(',');
3272
- const { pre, body, post } = m;
3273
- const p = pre.split(',');
3274
- p[p.length - 1] += '{' + body + '}';
3275
- const postParts = parseCommaParts(post);
3276
- if (post.length) {
3277
- p[p.length - 1] += postParts.shift();
3278
- p.push.apply(p, postParts);
3279
- }
3280
- parts.push.apply(parts, p);
3281
- return parts;
3282
- }
3283
- function expand(str, options = {}) {
3284
- if (!str) return [];
3285
- const { max = EXPANSION_MAX } = options;
3286
- if ('{}' === str.slice(0, 2)) str = '\\{\\}' + str.slice(2);
3287
- return expand_(escapeBraces(str), max, true).map(unescapeBraces);
3288
- }
3289
- function embrace(str) {
3290
- return '{' + str + '}';
3291
- }
3292
- function isPadded(el) {
3293
- return /^-?0\d/.test(el);
3294
- }
3295
- function lte(i, y) {
3296
- return i <= y;
3297
- }
3298
- function gte(i, y) {
3299
- return i >= y;
3300
- }
3301
- function expand_(str, max, isTop) {
3302
- const expansions = [];
3303
- const m = balanced('{', '}', str);
3304
- if (!m) return [
3305
- str
3306
- ];
3307
- const pre = m.pre;
3308
- const post = m.post.length ? expand_(m.post, max, false) : [
3309
- ''
3310
- ];
3311
- if (/\$$/.test(m.pre)) for(let k = 0; k < post.length && k < max; k++){
3312
- const expansion = pre + '{' + m.body + '}' + post[k];
3313
- expansions.push(expansion);
3314
- }
3315
- else {
3316
- const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
3317
- const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
3318
- const isSequence = isNumericSequence || isAlphaSequence;
3319
- const isOptions = m.body.indexOf(',') >= 0;
3320
- if (!isSequence && !isOptions) {
3321
- if (m.post.match(/,(?!,).*\}/)) {
3322
- str = m.pre + '{' + m.body + escClose + m.post;
3323
- return expand_(str, max, true);
3324
- }
3325
- return [
3326
- str
3327
- ];
3328
- }
3329
- let n;
3330
- if (isSequence) n = m.body.split(/\.\./);
3331
- else {
3332
- n = parseCommaParts(m.body);
3333
- if (1 === n.length && void 0 !== n[0]) {
3334
- n = expand_(n[0], max, false).map(embrace);
3335
- if (1 === n.length) return post.map((p)=>m.pre + n[0] + p);
3336
- }
3337
- }
3338
- let N;
3339
- if (isSequence && void 0 !== n[0] && void 0 !== n[1]) {
3340
- const x = numeric(n[0]);
3341
- const y = numeric(n[1]);
3342
- const width = Math.max(n[0].length, n[1].length);
3343
- let incr = 3 === n.length && void 0 !== n[2] ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
3344
- let test = lte;
3345
- const reverse = y < x;
3346
- if (reverse) {
3347
- incr *= -1;
3348
- test = gte;
3349
- }
3350
- const pad = n.some(isPadded);
3351
- N = [];
3352
- for(let i = x; test(i, y); i += incr){
3353
- let c;
3354
- if (isAlphaSequence) {
3355
- c = String.fromCharCode(i);
3356
- if ('\\' === c) c = '';
3357
- } else {
3358
- c = String(i);
3359
- if (pad) {
3360
- const need = width - c.length;
3361
- if (need > 0) {
3362
- const z = new Array(need + 1).join('0');
3363
- c = i < 0 ? '-' + z + c.slice(1) : z + c;
3364
- }
3365
- }
3366
- }
3367
- N.push(c);
3368
- }
3369
- } else {
3370
- N = [];
3371
- for(let j = 0; j < n.length; j++)N.push.apply(N, expand_(n[j], max, false));
3372
- }
3373
- for(let j = 0; j < N.length; j++)for(let k = 0; k < post.length && expansions.length < max; k++){
3374
- const expansion = pre + N[j] + post[k];
3375
- if (!isTop || isSequence || expansion) expansions.push(expansion);
3376
- }
3377
- }
3378
- return expansions;
3379
- }
3380
+ var logger_ = __webpack_require__("@midscene/shared/logger");
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;
3381
3383
  const assertValidPattern = (pattern)=>{
3382
3384
  if ('string' != typeof pattern) throw new TypeError('invalid pattern');
@@ -3542,11 +3544,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3542
3544
  true
3543
3545
  ];
3544
3546
  };
3545
- const unescape_unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {})=>{
3546
- if (magicalBraces) return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^/\\])\]/g, '$1$2').replace(/\\([^/])/g, '$1');
3547
- return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, '$1$2').replace(/\\([^/{}])/g, '$1');
3548
- };
3549
- var ast_a;
3547
+ const unescape_unescape = (s, { windowsPathsNoEscape = false } = {})=>windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
3550
3548
  const types = new Set([
3551
3549
  '!',
3552
3550
  '?',
@@ -3555,168 +3553,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3555
3553
  '@'
3556
3554
  ]);
3557
3555
  const isExtglobType = (c)=>types.has(c);
3558
- const isExtglobAST = (c)=>isExtglobType(c.type);
3559
- const adoptionMap = new Map([
3560
- [
3561
- '!',
3562
- [
3563
- '@'
3564
- ]
3565
- ],
3566
- [
3567
- '?',
3568
- [
3569
- '?',
3570
- '@'
3571
- ]
3572
- ],
3573
- [
3574
- '@',
3575
- [
3576
- '@'
3577
- ]
3578
- ],
3579
- [
3580
- '*',
3581
- [
3582
- '*',
3583
- '+',
3584
- '?',
3585
- '@'
3586
- ]
3587
- ],
3588
- [
3589
- '+',
3590
- [
3591
- '+',
3592
- '@'
3593
- ]
3594
- ]
3595
- ]);
3596
- const adoptionWithSpaceMap = new Map([
3597
- [
3598
- '!',
3599
- [
3600
- '?'
3601
- ]
3602
- ],
3603
- [
3604
- '@',
3605
- [
3606
- '?'
3607
- ]
3608
- ],
3609
- [
3610
- '+',
3611
- [
3612
- '?',
3613
- '*'
3614
- ]
3615
- ]
3616
- ]);
3617
- const adoptionAnyMap = new Map([
3618
- [
3619
- '!',
3620
- [
3621
- '?',
3622
- '@'
3623
- ]
3624
- ],
3625
- [
3626
- '?',
3627
- [
3628
- '?',
3629
- '@'
3630
- ]
3631
- ],
3632
- [
3633
- '@',
3634
- [
3635
- '?',
3636
- '@'
3637
- ]
3638
- ],
3639
- [
3640
- '*',
3641
- [
3642
- '*',
3643
- '+',
3644
- '?',
3645
- '@'
3646
- ]
3647
- ],
3648
- [
3649
- '+',
3650
- [
3651
- '+',
3652
- '@',
3653
- '?',
3654
- '*'
3655
- ]
3656
- ]
3657
- ]);
3658
- const usurpMap = new Map([
3659
- [
3660
- '!',
3661
- new Map([
3662
- [
3663
- '!',
3664
- '@'
3665
- ]
3666
- ])
3667
- ],
3668
- [
3669
- '?',
3670
- new Map([
3671
- [
3672
- '*',
3673
- '*'
3674
- ],
3675
- [
3676
- '+',
3677
- '*'
3678
- ]
3679
- ])
3680
- ],
3681
- [
3682
- '@',
3683
- new Map([
3684
- [
3685
- '!',
3686
- '!'
3687
- ],
3688
- [
3689
- '?',
3690
- '?'
3691
- ],
3692
- [
3693
- '@',
3694
- '@'
3695
- ],
3696
- [
3697
- '*',
3698
- '*'
3699
- ],
3700
- [
3701
- '+',
3702
- '+'
3703
- ]
3704
- ])
3705
- ],
3706
- [
3707
- '+',
3708
- new Map([
3709
- [
3710
- '?',
3711
- '*'
3712
- ],
3713
- [
3714
- '*',
3715
- '*'
3716
- ]
3717
- ])
3718
- ]
3719
- ]);
3720
3556
  const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))';
3721
3557
  const startNoDot = '(?!\\.)';
3722
3558
  const addPatternStart = new Set([
@@ -3732,7 +3568,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3732
3568
  const qmark = '[^/]';
3733
3569
  const star = qmark + '*?';
3734
3570
  const starNoEmpty = qmark + '+?';
3735
- let ID = 0;
3736
3571
  class ast_AST {
3737
3572
  type;
3738
3573
  #root;
@@ -3746,22 +3581,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3746
3581
  #options;
3747
3582
  #toString;
3748
3583
  #emptyExt = false;
3749
- id = ++ID;
3750
- get depth() {
3751
- return (this.#parent?.depth ?? -1) + 1;
3752
- }
3753
- [Symbol.for('nodejs.util.inspect.custom')]() {
3754
- return {
3755
- '@@type': 'AST',
3756
- id: this.id,
3757
- type: this.type,
3758
- root: this.#root.id,
3759
- parent: this.#parent?.id,
3760
- depth: this.depth,
3761
- partsLength: this.#parts.length,
3762
- parts: this.#parts
3763
- };
3764
- }
3765
3584
  constructor(type, parent, options = {}){
3766
3585
  this.type = type;
3767
3586
  if (type) this.#hasMagic = true;
@@ -3780,7 +3599,9 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3780
3599
  return this.#hasMagic;
3781
3600
  }
3782
3601
  toString() {
3783
- return void 0 !== this.#toString ? this.#toString : this.type ? this.#toString = this.type + '(' + this.#parts.map((p)=>String(p)).join('|') + ')' : this.#toString = this.#parts.map((p)=>String(p)).join('');
3602
+ if (void 0 !== this.#toString) return this.#toString;
3603
+ if (!this.type) return this.#toString = this.#parts.map((p)=>String(p)).join('');
3604
+ return this.#toString = this.type + '(' + this.#parts.map((p)=>String(p)).join('|') + ')';
3784
3605
  }
3785
3606
  #fillNegs() {
3786
3607
  if (this !== this.#root) throw new Error('should only call on root');
@@ -3805,7 +3626,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3805
3626
  }
3806
3627
  push(...parts) {
3807
3628
  for (const p of parts)if ('' !== p) {
3808
- if ('string' != typeof p && !(p instanceof ast_a && p.#parent === this)) throw new Error('invalid part: ' + p);
3629
+ if ('string' != typeof p && !(p instanceof ast_AST && p.#parent === this)) throw new Error('invalid part: ' + p);
3809
3630
  this.#parts.push(p);
3810
3631
  }
3811
3632
  }
@@ -3825,7 +3646,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3825
3646
  const p = this.#parent;
3826
3647
  for(let i = 0; i < this.#parentIndex; i++){
3827
3648
  const pp = p.#parts[i];
3828
- if (!(pp instanceof ast_a && '!' === pp.type)) return false;
3649
+ if (!(pp instanceof ast_AST && '!' === pp.type)) return false;
3829
3650
  }
3830
3651
  return true;
3831
3652
  }
@@ -3842,12 +3663,11 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3842
3663
  else this.push(part.clone(this));
3843
3664
  }
3844
3665
  clone(parent) {
3845
- const c = new ast_a(this.type, parent);
3666
+ const c = new ast_AST(this.type, parent);
3846
3667
  for (const p of this.#parts)c.copyIn(p);
3847
3668
  return c;
3848
3669
  }
3849
- static #parseAST(str, ast, pos, opt, extDepth) {
3850
- const maxDepth = opt.maxExtglobRecursion ?? 2;
3670
+ static #parseAST(str, ast, pos, opt) {
3851
3671
  let escaping = false;
3852
3672
  let inBrace = false;
3853
3673
  let braceStart = -1;
@@ -3876,12 +3696,11 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3876
3696
  acc += c;
3877
3697
  continue;
3878
3698
  }
3879
- const doRecurse = !opt.noext && isExtglobType(c) && '(' === str.charAt(i) && extDepth <= maxDepth;
3880
- if (doRecurse) {
3699
+ if (!opt.noext && isExtglobType(c) && '(' === str.charAt(i)) {
3881
3700
  ast.push(acc);
3882
3701
  acc = '';
3883
- const ext = new ast_a(c, ast);
3884
- i = ast_a.#parseAST(str, ext, i, opt, extDepth + 1);
3702
+ const ext = new ast_AST(c, ast);
3703
+ i = ast_AST.#parseAST(str, ext, i, opt);
3885
3704
  ast.push(ext);
3886
3705
  continue;
3887
3706
  }
@@ -3891,7 +3710,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3891
3710
  return i;
3892
3711
  }
3893
3712
  let i = pos + 1;
3894
- let part = new ast_a(null, ast);
3713
+ let part = new ast_AST(null, ast);
3895
3714
  const parts = [];
3896
3715
  let acc = '';
3897
3716
  while(i < str.length){
@@ -3915,21 +3734,19 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3915
3734
  acc += c;
3916
3735
  continue;
3917
3736
  }
3918
- const doRecurse = !opt.noext && isExtglobType(c) && '(' === str.charAt(i) && (extDepth <= maxDepth || ast && ast.#canAdoptType(c));
3919
- if (doRecurse) {
3920
- const depthAdd = ast && ast.#canAdoptType(c) ? 0 : 1;
3737
+ if (isExtglobType(c) && '(' === str.charAt(i)) {
3921
3738
  part.push(acc);
3922
3739
  acc = '';
3923
- const ext = new ast_a(c, part);
3740
+ const ext = new ast_AST(c, part);
3924
3741
  part.push(ext);
3925
- i = ast_a.#parseAST(str, ext, i, opt, extDepth + depthAdd);
3742
+ i = ast_AST.#parseAST(str, ext, i, opt);
3926
3743
  continue;
3927
3744
  }
3928
3745
  if ('|' === c) {
3929
3746
  part.push(acc);
3930
3747
  acc = '';
3931
3748
  parts.push(part);
3932
- part = new ast_a(null, ast);
3749
+ part = new ast_AST(null, ast);
3933
3750
  continue;
3934
3751
  }
3935
3752
  if (')' === c) {
@@ -3948,55 +3765,9 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
3948
3765
  ];
3949
3766
  return i;
3950
3767
  }
3951
- #canAdoptWithSpace(child) {
3952
- return this.#canAdopt(child, adoptionWithSpaceMap);
3953
- }
3954
- #canAdopt(child, map = adoptionMap) {
3955
- if (!child || 'object' != typeof child || null !== child.type || 1 !== child.#parts.length || null === this.type) return false;
3956
- const gc = child.#parts[0];
3957
- if (!gc || 'object' != typeof gc || null === gc.type) return false;
3958
- return this.#canAdoptType(gc.type, map);
3959
- }
3960
- #canAdoptType(c, map = adoptionAnyMap) {
3961
- return !!map.get(this.type)?.includes(c);
3962
- }
3963
- #adoptWithSpace(child, index) {
3964
- const gc = child.#parts[0];
3965
- const blank = new ast_a(null, gc, this.options);
3966
- blank.#parts.push('');
3967
- gc.push(blank);
3968
- this.#adopt(child, index);
3969
- }
3970
- #adopt(child, index) {
3971
- const gc = child.#parts[0];
3972
- this.#parts.splice(index, 1, ...gc.#parts);
3973
- for (const p of gc.#parts)if ('object' == typeof p) p.#parent = this;
3974
- this.#toString = void 0;
3975
- }
3976
- #canUsurpType(c) {
3977
- const m = usurpMap.get(this.type);
3978
- return !!m?.has(c);
3979
- }
3980
- #canUsurp(child) {
3981
- if (!child || 'object' != typeof child || null !== child.type || 1 !== child.#parts.length || null === this.type || 1 !== this.#parts.length) return false;
3982
- const gc = child.#parts[0];
3983
- if (!gc || 'object' != typeof gc || null === gc.type) return false;
3984
- return this.#canUsurpType(gc.type);
3985
- }
3986
- #usurp(child) {
3987
- const m = usurpMap.get(this.type);
3988
- const gc = child.#parts[0];
3989
- const nt = m?.get(gc.type);
3990
- if (!nt) return false;
3991
- this.#parts = gc.#parts;
3992
- for (const p of this.#parts)if ('object' == typeof p) p.#parent = this;
3993
- this.type = nt;
3994
- this.#toString = void 0;
3995
- this.#emptyExt = false;
3996
- }
3997
3768
  static fromGlob(pattern, options = {}) {
3998
- const ast = new ast_a(null, void 0, options);
3999
- ast_a.#parseAST(pattern, ast, 0, options, 0);
3769
+ const ast = new ast_AST(null, void 0, options);
3770
+ ast_AST.#parseAST(pattern, ast, 0, options);
4000
3771
  return ast;
4001
3772
  }
4002
3773
  toMMPattern() {
@@ -4016,14 +3787,11 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4016
3787
  }
4017
3788
  toRegExpSource(allowDot) {
4018
3789
  const dot = allowDot ?? !!this.#options.dot;
4019
- if (this.#root === this) {
4020
- this.#flatten();
4021
- this.#fillNegs();
4022
- }
4023
- if (!isExtglobAST(this)) {
4024
- const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s)=>'string' != typeof s);
3790
+ if (this.#root === this) this.#fillNegs();
3791
+ if (!this.type) {
3792
+ const noEmpty = this.isStart() && this.isEnd();
4025
3793
  const src = this.#parts.map((p)=>{
4026
- const [re, _, hasMagic, uflag] = 'string' == typeof p ? ast_a.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
3794
+ const [re, _, hasMagic, uflag] = 'string' == typeof p ? ast_AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
4027
3795
  this.#hasMagic = this.#hasMagic || hasMagic;
4028
3796
  this.#uflag = this.#uflag || uflag;
4029
3797
  return re;
@@ -4055,12 +3823,11 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4055
3823
  let body = this.#partsToRegExp(dot);
4056
3824
  if (this.isStart() && this.isEnd() && !body && '!' !== this.type) {
4057
3825
  const s = this.toString();
4058
- const me = this;
4059
- me.#parts = [
3826
+ this.#parts = [
4060
3827
  s
4061
3828
  ];
4062
- me.type = null;
4063
- me.#hasMagic = void 0;
3829
+ this.type = null;
3830
+ this.#hasMagic = void 0;
4064
3831
  return [
4065
3832
  s,
4066
3833
  unescape_unescape(this.toString()),
@@ -4084,32 +3851,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4084
3851
  this.#uflag
4085
3852
  ];
4086
3853
  }
4087
- #flatten() {
4088
- if (isExtglobAST(this)) {
4089
- let iterations = 0;
4090
- let done = false;
4091
- do {
4092
- done = true;
4093
- for(let i = 0; i < this.#parts.length; i++){
4094
- const c = this.#parts[i];
4095
- if ('object' == typeof c) {
4096
- c.#flatten();
4097
- if (this.#canAdopt(c)) {
4098
- done = false;
4099
- this.#adopt(c, i);
4100
- } else if (this.#canAdoptWithSpace(c)) {
4101
- done = false;
4102
- this.#adoptWithSpace(c, i);
4103
- } else if (this.#canUsurp(c)) {
4104
- done = false;
4105
- this.#usurp(c);
4106
- }
4107
- }
4108
- }
4109
- }while (!done && ++iterations < 10);
4110
- } else for (const p of this.#parts)if ('object' == typeof p) p.#flatten();
4111
- this.#toString = void 0;
4112
- }
4113
3854
  #partsToRegExp(dot) {
4114
3855
  return this.#parts.map((p)=>{
4115
3856
  if ('string' == typeof p) throw new Error('string type in extglob ast??');
@@ -4122,7 +3863,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4122
3863
  let escaping = false;
4123
3864
  let re = '';
4124
3865
  let uflag = false;
4125
- let inStar = false;
4126
3866
  for(let i = 0; i < glob.length; i++){
4127
3867
  const c = glob.charAt(i);
4128
3868
  if (escaping) {
@@ -4130,14 +3870,6 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4130
3870
  re += (reSpecials.has(c) ? '\\' : '') + c;
4131
3871
  continue;
4132
3872
  }
4133
- if ('*' === c) {
4134
- if (inStar) continue;
4135
- inStar = true;
4136
- re += noEmpty && /^[*]+$/.test(glob) ? starNoEmpty : star;
4137
- hasMagic = true;
4138
- continue;
4139
- }
4140
- inStar = false;
4141
3873
  if ('\\' === c) {
4142
3874
  if (i === glob.length - 1) re += '\\\\';
4143
3875
  else escaping = true;
@@ -4153,6 +3885,12 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4153
3885
  continue;
4154
3886
  }
4155
3887
  }
3888
+ if ('*' === c) {
3889
+ if (noEmpty && '*' === glob) re += starNoEmpty;
3890
+ else re += star;
3891
+ hasMagic = true;
3892
+ continue;
3893
+ }
4156
3894
  if ('?' === c) {
4157
3895
  re += qmark;
4158
3896
  hasMagic = true;
@@ -4168,17 +3906,13 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4168
3906
  ];
4169
3907
  }
4170
3908
  }
4171
- ast_a = ast_AST;
4172
- const escape_escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {})=>{
4173
- if (magicalBraces) return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, '[$&]') : s.replace(/[?*()[\]\\{}]/g, '\\$&');
4174
- return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, '[$&]') : s.replace(/[?*()[\]\\]/g, '\\$&');
4175
- };
3909
+ const escape_escape = (s, { windowsPathsNoEscape = false } = {})=>windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, '[$&]') : s.replace(/[?*()[\]\\]/g, '\\$&');
4176
3910
  const minimatch = (p, pattern, options = {})=>{
4177
3911
  assertValidPattern(pattern);
4178
3912
  if (!options.nocomment && '#' === pattern.charAt(0)) return false;
4179
3913
  return new esm_Minimatch(pattern, options).match(p);
4180
3914
  };
4181
- const starDotExtRE = /^\*+([^+@!?*[(]*)$/;
3915
+ const starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
4182
3916
  const starDotExtTest = (ext)=>(f)=>!f.startsWith('.') && f.endsWith(ext);
4183
3917
  const starDotExtTestDot = (ext)=>(f)=>f.endsWith(ext);
4184
3918
  const starDotExtTestNocase = (ext)=>{
@@ -4197,7 +3931,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4197
3931
  const starRE = /^\*+$/;
4198
3932
  const starTest = (f)=>0 !== f.length && !f.startsWith('.');
4199
3933
  const starTestDot = (f)=>0 !== f.length && '.' !== f && '..' !== f;
4200
- const qmarksRE = /^\?+([^+@!?*[(]*)?$/;
3934
+ const qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
4201
3935
  const qmarksTestNocase = ([$0, ext = ''])=>{
4202
3936
  const noext = qmarksTestNoExt([
4203
3937
  $0
@@ -4292,9 +4026,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4292
4026
  if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) return [
4293
4027
  pattern
4294
4028
  ];
4295
- return expand(pattern, {
4296
- max: options.braceExpandMax
4297
- });
4029
+ return brace_expansion(pattern);
4298
4030
  };
4299
4031
  minimatch.braceExpand = braceExpand;
4300
4032
  const makeRe = (pattern, options = {})=>new esm_Minimatch(pattern, options).makeRe();
@@ -4325,18 +4057,15 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4325
4057
  isWindows;
4326
4058
  platform;
4327
4059
  windowsNoMagicRoot;
4328
- maxGlobstarRecursion;
4329
4060
  regexp;
4330
4061
  constructor(pattern, options = {}){
4331
4062
  assertValidPattern(pattern);
4332
4063
  options = options || {};
4333
4064
  this.options = options;
4334
- this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200;
4335
4065
  this.pattern = pattern;
4336
4066
  this.platform = options.platform || defaultPlatform;
4337
4067
  this.isWindows = 'win32' === this.platform;
4338
- const awe = "allowWindowsEscape";
4339
- this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || false === options[awe];
4068
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || false === options.allowWindowsEscape;
4340
4069
  if (this.windowsPathsNoEscape) this.pattern = this.pattern.replace(/\\/g, '/');
4341
4070
  this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
4342
4071
  this.regexp = null;
@@ -4403,7 +4132,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4403
4132
  }
4404
4133
  preprocess(globParts) {
4405
4134
  if (this.options.noglobstar) {
4406
- for (const partset of globParts)for(let j = 0; j < partset.length; j++)if ('**' === partset[j]) partset[j] = '*';
4135
+ for(let i = 0; i < globParts.length; i++)for(let j = 0; j < globParts[i].length; j++)if ('**' === globParts[i][j]) globParts[i][j] = '*';
4407
4136
  }
4408
4137
  const { optimizationLevel = 1 } = this.options;
4409
4138
  if (optimizationLevel >= 2) {
@@ -4466,7 +4195,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4466
4195
  let dd = 0;
4467
4196
  while(-1 !== (dd = parts.indexOf('..', dd + 1))){
4468
4197
  const p = parts[dd - 1];
4469
- if (p && '.' !== p && '..' !== p && '**' !== p && !(this.isWindows && /^[a-z]:$/i.test(p))) {
4198
+ if (p && '.' !== p && '..' !== p && '**' !== p) {
4470
4199
  didSomething = true;
4471
4200
  parts.splice(dd - 1, 2);
4472
4201
  dd -= 2;
@@ -4588,8 +4317,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4588
4317
  this.negate = negate;
4589
4318
  }
4590
4319
  matchOne(file, pattern, partial = false) {
4591
- let fileStartIndex = 0;
4592
- let patternStartIndex = 0;
4320
+ const options = this.options;
4593
4321
  if (this.isWindows) {
4594
4322
  const fileDrive = 'string' == typeof file[0] && /^[a-z]:$/i.test(file[0]);
4595
4323
  const fileUNC = !fileDrive && '' === file[0] && '' === file[1] && '?' === file[2] && /^[a-z]:$/i.test(file[3]);
@@ -4604,116 +4332,57 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4604
4332
  ];
4605
4333
  if (fd.toLowerCase() === pd.toLowerCase()) {
4606
4334
  pattern[pdi] = fd;
4607
- patternStartIndex = pdi;
4608
- fileStartIndex = fdi;
4335
+ if (pdi > fdi) pattern = pattern.slice(pdi);
4336
+ else if (fdi > pdi) file = file.slice(fdi);
4609
4337
  }
4610
4338
  }
4611
4339
  }
4612
4340
  const { optimizationLevel = 1 } = this.options;
4613
4341
  if (optimizationLevel >= 2) file = this.levelTwoFileOptimize(file);
4614
- if (pattern.includes(GLOBSTAR)) return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
4615
- return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
4616
- }
4617
- #matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
4618
- const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
4619
- const lastgs = pattern.lastIndexOf(GLOBSTAR);
4620
- const [head, body, tail] = partial ? [
4621
- pattern.slice(patternIndex, firstgs),
4622
- pattern.slice(firstgs + 1),
4623
- []
4624
- ] : [
4625
- pattern.slice(patternIndex, firstgs),
4626
- pattern.slice(firstgs + 1, lastgs),
4627
- pattern.slice(lastgs + 1)
4628
- ];
4629
- if (head.length) {
4630
- const fileHead = file.slice(fileIndex, fileIndex + head.length);
4631
- if (!this.#matchOne(fileHead, head, partial, 0, 0)) return false;
4632
- fileIndex += head.length;
4633
- patternIndex += head.length;
4634
- }
4635
- let fileTailMatch = 0;
4636
- if (tail.length) {
4637
- if (tail.length + fileIndex > file.length) return false;
4638
- let tailStart = file.length - tail.length;
4639
- if (this.#matchOne(file, tail, partial, tailStart, 0)) fileTailMatch = tail.length;
4640
- else {
4641
- if ('' !== file[file.length - 1] || fileIndex + tail.length === file.length) return false;
4642
- tailStart--;
4643
- if (!this.#matchOne(file, tail, partial, tailStart, 0)) return false;
4644
- fileTailMatch = tail.length + 1;
4645
- }
4646
- }
4647
- if (!body.length) {
4648
- let sawSome = !!fileTailMatch;
4649
- for(let i = fileIndex; i < file.length - fileTailMatch; i++){
4650
- const f = String(file[i]);
4651
- sawSome = true;
4652
- if ('.' === f || '..' === f || !this.options.dot && f.startsWith('.')) return false;
4653
- }
4654
- return partial || sawSome;
4655
- }
4656
- const bodySegments = [
4657
- [
4658
- [],
4659
- 0
4660
- ]
4661
- ];
4662
- let currentBody = bodySegments[0];
4663
- let nonGsParts = 0;
4664
- const nonGsPartsSums = [
4665
- 0
4666
- ];
4667
- for (const b of body)if (b === GLOBSTAR) {
4668
- nonGsPartsSums.push(nonGsParts);
4669
- currentBody = [
4670
- [],
4671
- 0
4672
- ];
4673
- bodySegments.push(currentBody);
4674
- } else {
4675
- currentBody[0].push(b);
4676
- nonGsParts++;
4677
- }
4678
- let i = bodySegments.length - 1;
4679
- const fileLength = file.length - fileTailMatch;
4680
- for (const b of bodySegments)b[1] = fileLength - (nonGsPartsSums[i--] + b[0].length);
4681
- return !!this.#matchGlobStarBodySections(file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch);
4682
- }
4683
- #matchGlobStarBodySections(file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail) {
4684
- const bs = bodySegments[bodyIndex];
4685
- if (!bs) {
4686
- for(let i = fileIndex; i < file.length; i++){
4687
- sawTail = true;
4688
- const f = file[i];
4689
- if ('.' === f || '..' === f || !this.options.dot && f.startsWith('.')) return false;
4690
- }
4691
- return sawTail;
4692
- }
4693
- const [body, after] = bs;
4694
- while(fileIndex <= after){
4695
- const m = this.#matchOne(file.slice(0, fileIndex + body.length), body, partial, fileIndex, 0);
4696
- if (m && globStarDepth < this.maxGlobstarRecursion) {
4697
- const sub = this.#matchGlobStarBodySections(file, bodySegments, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail);
4698
- if (false !== sub) return sub;
4699
- }
4700
- const f = file[fileIndex];
4701
- if ('.' === f || '..' === f || !this.options.dot && f.startsWith('.')) return false;
4702
- fileIndex++;
4703
- }
4704
- return partial || null;
4705
- }
4706
- #matchOne(file, pattern, partial, fileIndex, patternIndex) {
4707
- let fi;
4708
- let pi;
4709
- let pl;
4710
- let fl;
4711
- for(fi = fileIndex, pi = patternIndex, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++){
4342
+ this.debug('matchOne', this, {
4343
+ file,
4344
+ pattern
4345
+ });
4346
+ this.debug('matchOne', file.length, pattern.length);
4347
+ for(var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++){
4712
4348
  this.debug('matchOne loop');
4713
- let p = pattern[pi];
4714
- let f = file[fi];
4349
+ var p = pattern[pi];
4350
+ var f = file[fi];
4715
4351
  this.debug(pattern, p, f);
4716
- if (false === p || p === GLOBSTAR) return false;
4352
+ if (false === p) return false;
4353
+ if (p === GLOBSTAR) {
4354
+ this.debug('GLOBSTAR', [
4355
+ pattern,
4356
+ p,
4357
+ f
4358
+ ]);
4359
+ var fr = fi;
4360
+ var pr = pi + 1;
4361
+ if (pr === pl) {
4362
+ this.debug('** at the end');
4363
+ for(; fi < fl; fi++)if ('.' === file[fi] || '..' === file[fi] || !options.dot && '.' === file[fi].charAt(0)) return false;
4364
+ return true;
4365
+ }
4366
+ while(fr < fl){
4367
+ var swallowee = file[fr];
4368
+ this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
4369
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
4370
+ this.debug('globstar found match!', fr, fl, swallowee);
4371
+ return true;
4372
+ }
4373
+ if ('.' === swallowee || '..' === swallowee || !options.dot && '.' === swallowee.charAt(0)) {
4374
+ this.debug('dot detected!', file, fr, pattern, pr);
4375
+ break;
4376
+ }
4377
+ this.debug('globstar swallow a segment, and continue');
4378
+ fr++;
4379
+ }
4380
+ if (partial) {
4381
+ this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
4382
+ if (fr === fl) return true;
4383
+ }
4384
+ return false;
4385
+ }
4717
4386
  let hit;
4718
4387
  if ('string' == typeof p) {
4719
4388
  hit = f === p;
@@ -4773,19 +4442,13 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4773
4442
  if (p !== GLOBSTAR || prev === GLOBSTAR) return;
4774
4443
  if (void 0 === prev) if (void 0 !== next && next !== GLOBSTAR) pp[i + 1] = '(?:\\/|' + twoStar + '\\/)?' + next;
4775
4444
  else pp[i] = twoStar;
4776
- else if (void 0 === next) pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?';
4445
+ else if (void 0 === next) pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?';
4777
4446
  else if (next !== GLOBSTAR) {
4778
4447
  pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
4779
4448
  pp[i + 1] = GLOBSTAR;
4780
4449
  }
4781
4450
  });
4782
- const filtered = pp.filter((p)=>p !== GLOBSTAR);
4783
- if (this.partial && filtered.length >= 1) {
4784
- const prefixes = [];
4785
- for(let i = 1; i <= filtered.length; i++)prefixes.push(filtered.slice(0, i).join('/'));
4786
- return '(?:' + prefixes.join('|') + ')';
4787
- }
4788
- return filtered.join('/');
4451
+ return pp.filter((p)=>p !== GLOBSTAR).join('/');
4789
4452
  }).join('|');
4790
4453
  const [open, close] = set.length > 1 ? [
4791
4454
  '(?:',
@@ -4795,20 +4458,19 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4795
4458
  ''
4796
4459
  ];
4797
4460
  re = '^' + open + re + close + '$';
4798
- if (this.partial) re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$';
4799
4461
  if (this.negate) re = '^(?!' + re + ').+$';
4800
4462
  try {
4801
4463
  this.regexp = new RegExp(re, [
4802
4464
  ...flags
4803
4465
  ].join(''));
4804
- } catch {
4466
+ } catch (ex) {
4805
4467
  this.regexp = false;
4806
4468
  }
4807
4469
  return this.regexp;
4808
4470
  }
4809
4471
  slashSplit(p) {
4810
4472
  if (this.preserveMultipleSlashes) return p.split('/');
4811
- if (this.isWindows && /^\/\/[^/]+/.test(p)) return [
4473
+ if (this.isWindows && /^\/\/[^\/]+/.test(p)) return [
4812
4474
  '',
4813
4475
  ...p.split(/\/+/)
4814
4476
  ];
@@ -4827,7 +4489,8 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4827
4489
  this.debug(this.pattern, 'set', set);
4828
4490
  let filename = ff[ff.length - 1];
4829
4491
  if (!filename) for(let i = ff.length - 2; !filename && i >= 0; i--)filename = ff[i];
4830
- for (const pattern of set){
4492
+ for(let i = 0; i < set.length; i++){
4493
+ const pattern = set[i];
4831
4494
  let file = ff;
4832
4495
  if (options.matchBase && 1 === pattern.length) file = [
4833
4496
  filename
@@ -4850,47 +4513,85 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4850
4513
  minimatch.escape = escape_escape;
4851
4514
  minimatch.unescape = unescape_unescape;
4852
4515
  var external_node_url_ = __webpack_require__("node:url");
4853
- const external_node_diagnostics_channel_namespaceObject = require("node:diagnostics_channel");
4854
- var S = (0, external_node_diagnostics_channel_namespaceObject.channel)("lru-cache:metrics"), W = (0, external_node_diagnostics_channel_namespaceObject.tracingChannel)("lru-cache");
4855
- 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)=>{
4856
- "function" == typeof C.emitWarning ? C.emitWarning(u, e1, t1, i) : console.error(`[${t1}] ${e1}: ${u}`);
4857
- }, 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 {
4858
- constructor(e1){
4859
- super(e1), this.fill(0);
4860
- }
4861
- }, 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 {
4862
4565
  heap;
4863
4566
  length;
4864
- static #o = !1;
4865
- static create(e1) {
4866
- let t1 = U(e1);
4867
- if (!t1) return [];
4868
- u.#o = !0;
4869
- let i = new u(e1, t1);
4870
- return u.#o = !1, i;
4871
- }
4872
- constructor(e1, t1){
4873
- if (!u.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
4874
- this.heap = new t1(e1), this.length = 0;
4875
- }
4876
- push(e1) {
4877
- 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;
4878
4583
  }
4879
4584
  pop() {
4880
4585
  return this.heap[--this.length];
4881
4586
  }
4882
- }, L = class u {
4883
- #o;
4884
- #u;
4885
- #w;
4886
- #D;
4887
- #S;
4888
- #M;
4889
- #U;
4890
- #m;
4891
- get perf() {
4892
- return this.#m;
4893
- }
4587
+ }
4588
+ class LRUCache {
4589
+ #max;
4590
+ #maxSize;
4591
+ #dispose;
4592
+ #disposeAfter;
4593
+ #fetchMethod;
4594
+ #memoMethod;
4894
4595
  ttl;
4895
4596
  ttlResolution;
4896
4597
  ttlAutopurge;
@@ -4906,613 +4607,823 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
4906
4607
  allowStaleOnFetchAbort;
4907
4608
  allowStaleOnFetchRejection;
4908
4609
  ignoreFetchAbort;
4909
- #n;
4910
- #b;
4911
- #s;
4912
- #i;
4913
- #t;
4914
- #a;
4915
- #c;
4916
- #l;
4917
- #h;
4918
- #y;
4919
- #r;
4920
- #_;
4921
- #F;
4922
- #d;
4923
- #g;
4924
- #T;
4925
- #W;
4926
- #f;
4927
- #j;
4928
- 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) {
4929
4628
  return {
4930
- starts: e1.#F,
4931
- ttls: e1.#d,
4932
- autopurgeTimers: e1.#g,
4933
- sizes: e1.#_,
4934
- keyMap: e1.#s,
4935
- keyList: e1.#i,
4936
- valList: e1.#t,
4937
- next: e1.#a,
4938
- 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,
4939
4637
  get head () {
4940
- return e1.#l;
4638
+ return c.#head;
4941
4639
  },
4942
4640
  get tail () {
4943
- return e1.#h;
4641
+ return c.#tail;
4944
4642
  },
4945
- free: e1.#y,
4946
- isBackgroundFetch: (t1)=>e1.#e(t1),
4947
- backgroundFetch: (t1, i, s, n)=>e1.#P(t1, i, s, n),
4948
- moveToTail: (t1)=>e1.#L(t1),
4949
- indexes: (t1)=>e1.#A(t1),
4950
- rindexes: (t1)=>e1.#z(t1),
4951
- 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)
4952
4650
  };
4953
4651
  }
4954
4652
  get max() {
4955
- return this.#o;
4653
+ return this.#max;
4956
4654
  }
4957
4655
  get maxSize() {
4958
- return this.#u;
4656
+ return this.#maxSize;
4959
4657
  }
4960
4658
  get calculatedSize() {
4961
- return this.#b;
4659
+ return this.#calculatedSize;
4962
4660
  }
4963
4661
  get size() {
4964
- return this.#n;
4662
+ return this.#size;
4965
4663
  }
4966
4664
  get fetchMethod() {
4967
- return this.#M;
4665
+ return this.#fetchMethod;
4968
4666
  }
4969
4667
  get memoMethod() {
4970
- return this.#U;
4668
+ return this.#memoMethod;
4971
4669
  }
4972
4670
  get dispose() {
4973
- return this.#w;
4974
- }
4975
- get onInsert() {
4976
- return this.#D;
4671
+ return this.#dispose;
4977
4672
  }
4978
4673
  get disposeAfter() {
4979
- return this.#S;
4980
- }
4981
- constructor(e1){
4982
- 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;
4983
- if (void 0 !== x && "function" != typeof x?.now) throw new TypeError("perf option must have a now() method if specified");
4984
- if (this.#m = x ?? G, 0 !== t1 && !F(t1)) throw new TypeError("max option must be a nonnegative integer");
4985
- let v = t1 ? U(t1) : Array;
4986
- if (!v) throw new Error("invalid max value: " + t1);
4987
- if (this.#o = t1, this.#u = T, this.maxEntrySize = w || this.#u, this.sizeCalculation = y, this.sizeCalculation) {
4988
- if (!this.#u && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
4989
- if ("function" != typeof this.sizeCalculation) throw new TypeError("sizeCalculation set to non-function");
4990
- }
4991
- if (void 0 !== m && "function" != typeof m) throw new TypeError("memoMethod must be a function if defined");
4992
- if (this.#U = m, void 0 !== a && "function" != typeof a) throw new TypeError("fetchMethod must be a function if specified");
4993
- if (this.#M = a, this.#W = !!a, this.#s = new Map, this.#i = Array.from({
4994
- length: t1
4995
- }).fill(void 0), this.#t = Array.from({
4996
- length: t1
4997
- }).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) {
4998
- if (0 !== this.#u && !F(this.#u)) throw new TypeError("maxSize must be a positive integer if specified");
4999
- if (!F(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
5000
- this.#X();
5001
- }
5002
- 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) {
5003
- if (!F(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
5004
- this.#H();
5005
- }
5006
- if (0 === this.#o && 0 === this.ttl && 0 === this.#u) throw new TypeError("At least one of max, maxSize, or ttl is required");
5007
- if (!this.ttlAutopurge && !this.#o && !this.#u) {
5008
- let E = "LRU_CACHE_UNBOUNDED";
5009
- H(E) && (M.add(E), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, u));
5010
- }
5011
- }
5012
- getRemainingTTL(e1) {
5013
- return this.#s.has(e1) ? 1 / 0 : 0;
5014
- }
5015
- #H() {
5016
- let e1 = new O(this.#o), t1 = new O(this.#o);
5017
- this.#d = e1, this.#F = t1;
5018
- let i = this.ttlAutopurge ? Array.from({
5019
- length: this.#o
5020
- }) : void 0;
5021
- this.#g = i, this.#N = (r, h, l = this.#m.now())=>{
5022
- t1[r] = 0 !== h ? l : 0, e1[r] = h, s(r, h);
5023
- }, this.#x = (r)=>{
5024
- 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
+ }
5025
4765
  };
5026
- let s = this.ttlAutopurge ? (r, h)=>{
5027
- if (i?.[r] && (clearTimeout(i[r]), i[r] = void 0), h && 0 !== h && i) {
5028
- let l = setTimeout(()=>{
5029
- this.#p(r) && this.#v(this.#i[r], "expire");
5030
- }, h + 1);
5031
- l.unref && l.unref(), i[r] = l;
5032
- }
5033
- } : ()=>{};
5034
- this.#E = (r, h)=>{
5035
- if (e1[h]) {
5036
- let l = e1[h], c = t1[h];
5037
- if (!l || !c) return;
5038
- r.ttl = l, r.start = c, r.now = n || o();
5039
- let f = r.now - c;
5040
- 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;
5041
4779
  }
5042
4780
  };
5043
- let n = 0, o = ()=>{
5044
- let r = this.#m.now();
4781
+ let cachedNow = 0;
4782
+ const getNow = ()=>{
4783
+ const n = perf.now();
5045
4784
  if (this.ttlResolution > 0) {
5046
- n = r;
5047
- let h = setTimeout(()=>n = 0, this.ttlResolution);
5048
- h.unref && h.unref();
4785
+ cachedNow = n;
4786
+ const t1 = setTimeout(()=>cachedNow = 0, this.ttlResolution);
4787
+ if (t1.unref) t1.unref();
5049
4788
  }
5050
- 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;
5051
4799
  };
5052
- this.getRemainingTTL = (r)=>{
5053
- let h = this.#s.get(r);
5054
- if (void 0 === h) return 0;
5055
- let l = e1[h], c = t1[h];
5056
- if (!l || !c) return 1 / 0;
5057
- let f = (n || o()) - c;
5058
- return l - f;
5059
- }, this.#p = (r)=>{
5060
- let h = t1[r], l = e1[r];
5061
- 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;
5062
4804
  };
5063
4805
  }
5064
- #x = ()=>{};
5065
- #E = ()=>{};
5066
- #N = ()=>{};
5067
- #p = ()=>!1;
5068
- #X() {
5069
- let e1 = new O(this.#o);
5070
- this.#b = 0, this.#_ = e1, this.#R = (t1)=>{
5071
- this.#b -= e1[t1], e1[t1] = 0;
5072
- }, this.#k = (t1, i, s, n)=>{
5073
- if (this.#e(i)) return 0;
5074
- if (!F(s)) if (n) {
5075
- if ("function" != typeof n) throw new TypeError("sizeCalculation must be a function");
5076
- 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)');
5077
4824
  } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
5078
- return s;
5079
- }, this.#I = (t1, i, s)=>{
5080
- if (e1[t1] = i, this.#u) {
5081
- let n = this.#u - e1[t1];
5082
- 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;
5083
4837
  }
5084
- this.#b += e1[t1], s && (s.entrySize = i, s.totalCalculatedSize = this.#b);
5085
4838
  };
5086
4839
  }
5087
- #R = (e1)=>{};
5088
- #I = (e1, t1, i)=>{};
5089
- #k = (e1, t1, i, s)=>{
5090
- 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');
5091
4844
  return 0;
5092
4845
  };
5093
- *#A({ allowStale: e1 = this.allowStale } = {}) {
5094
- 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
+ }
5095
4853
  }
5096
- *#z({ allowStale: e1 = this.allowStale } = {}) {
5097
- 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
+ }
5098
4861
  }
5099
- #V(e1) {
5100
- 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;
5101
4864
  }
5102
4865
  *entries() {
5103
- for (let e1 of this.#A())void 0 === this.#t[e1] || void 0 === this.#i[e1] || this.#e(this.#t[e1]) || (yield [
5104
- this.#i[e1],
5105
- this.#t[e1]
5106
- ]);
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
+ ];
5107
4870
  }
5108
4871
  *rentries() {
5109
- for (let e1 of this.#z())void 0 === this.#t[e1] || void 0 === this.#i[e1] || this.#e(this.#t[e1]) || (yield [
5110
- this.#i[e1],
5111
- this.#t[e1]
5112
- ]);
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
+ ];
5113
4876
  }
5114
4877
  *keys() {
5115
- for (let e1 of this.#A()){
5116
- let t1 = this.#i[e1];
5117
- 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;
5118
4881
  }
5119
4882
  }
5120
4883
  *rkeys() {
5121
- for (let e1 of this.#z()){
5122
- let t1 = this.#i[e1];
5123
- 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;
5124
4887
  }
5125
4888
  }
5126
4889
  *values() {
5127
- 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
+ }
5128
4894
  }
5129
4895
  *rvalues() {
5130
- 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
+ }
5131
4900
  }
5132
4901
  [Symbol.iterator]() {
5133
4902
  return this.entries();
5134
4903
  }
5135
- [Symbol.toStringTag] = "LRUCache";
5136
- find(e1, t1 = {}) {
5137
- for (let i of this.#A()){
5138
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
5139
- 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
+ }
5140
4912
  }
5141
4913
  }
5142
- forEach(e1, t1 = this) {
5143
- for (let i of this.#A()){
5144
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
5145
- 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);
5146
4919
  }
5147
4920
  }
5148
- rforEach(e1, t1 = this) {
5149
- for (let i of this.#z()){
5150
- let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
5151
- 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);
5152
4926
  }
5153
4927
  }
5154
4928
  purgeStale() {
5155
- let e1 = !1;
5156
- for (let t1 of this.#z({
5157
- allowStale: !0
5158
- }))this.#p(t1) && (this.#v(this.#i[t1], "expire"), e1 = !0);
5159
- return e1;
5160
- }
5161
- info(e1) {
5162
- let t1 = this.#s.get(e1);
5163
- if (void 0 === t1) return;
5164
- let i = this.#t[t1], s = this.#e(i) ? i.__staleWhileFetching : i;
5165
- if (void 0 === s) return;
5166
- let n = {
5167
- 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
5168
4946
  };
5169
- if (this.#d && this.#F) {
5170
- let o = this.#d[t1], r = this.#F[t1];
5171
- if (o && r) {
5172
- let h = o - (this.#m.now() - r);
5173
- 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();
5174
4954
  }
5175
4955
  }
5176
- return this.#_ && (n.size = this.#_[t1]), n;
4956
+ if (this.#sizes) entry.size = this.#sizes[i];
4957
+ return entry;
5177
4958
  }
5178
4959
  dump() {
5179
- let e1 = [];
5180
- for (let t1 of this.#A({
5181
- allowStale: !0
4960
+ const arr = [];
4961
+ for (const i of this.#indexes({
4962
+ allowStale: true
5182
4963
  })){
5183
- let i = this.#i[t1], s = this.#t[t1], n = this.#e(s) ? s.__staleWhileFetching : s;
5184
- if (void 0 === n || void 0 === i) continue;
5185
- let o = {
5186
- 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
5187
4970
  };
5188
- if (this.#d && this.#F) {
5189
- o.ttl = this.#d[t1];
5190
- let r = this.#m.now() - this.#F[t1];
5191
- o.start = Math.floor(Date.now() - r);
5192
- }
5193
- this.#_ && (o.size = this.#_[t1]), e1.unshift([
5194
- i,
5195
- 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
5196
4980
  ]);
5197
4981
  }
5198
- return e1;
4982
+ return arr;
5199
4983
  }
5200
- load(e1) {
4984
+ load(arr) {
5201
4985
  this.clear();
5202
- for (let [t1, i] of e1){
5203
- if (i.start) {
5204
- let s = Date.now() - i.start;
5205
- i.start = this.#m.now() - s;
5206
- }
5207
- this.#O(t1, i.value, i);
5208
- }
5209
- }
5210
- set(e1, t1, i = {}) {
5211
- let { status: s = S.hasSubscribers ? {} : void 0 } = i;
5212
- i.status = s, s && (s.op = "set", s.key = e1, void 0 !== t1 && (s.value = t1));
5213
- let n = this.#O(e1, t1, i);
5214
- return s && S.hasSubscribers && S.publish(s), n;
5215
- }
5216
- #O(e1, t1, i = {}) {
5217
- let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: r = this.sizeCalculation, status: h } = i;
5218
- if (void 0 === t1) return h && (h.set = "deleted"), this.delete(e1), this;
5219
- let { noUpdateTTL: l = this.noUpdateTTL } = i;
5220
- h && !this.#e(t1) && (h.value = t1);
5221
- let c = this.#k(e1, t1, i.size || 0, r, h);
5222
- if (this.maxEntrySize && c > this.maxEntrySize) return this.#v(e1, "set"), h && (h.set = "miss", h.maxEntrySizeExceeded = !0), this;
5223
- let f = 0 === this.#n ? void 0 : this.#s.get(e1);
5224
- 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");
5225
- else {
5226
- this.#L(f);
5227
- let g = this.#t[f];
5228
- if (t1 !== g) {
5229
- if (this.#W && this.#e(g)) {
5230
- g.__abortController.abort(new Error("replaced"));
5231
- let { __staleWhileFetching: p } = g;
5232
- void 0 !== p && !o && (this.#T && this.#w?.(p, e1, "set"), this.#f && this.#r?.push([
5233
- p,
5234
- e1,
5235
- "set"
5236
- ]));
5237
- } else o || (this.#T && this.#w?.(g, e1, "set"), this.#f && this.#r?.push([
5238
- g,
5239
- e1,
5240
- "set"
5241
- ]));
5242
- if (this.#R(f), this.#I(f, c, h), this.#t[f] = t1, h) {
5243
- h.set = "replace";
5244
- let p = g && this.#e(g) ? g.__staleWhileFetching : g;
5245
- 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;
5246
5053
  }
5247
- } else h && (h.set = "update");
5248
- this.#j && this.onInsert?.(t1, e1, t1 === g ? "update" : "replace");
5054
+ } else if (status) status.set = 'update';
5249
5055
  }
5250
- 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) {
5251
- let g = this.#r, p;
5252
- 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);
5253
5065
  }
5254
5066
  return this;
5255
5067
  }
5256
5068
  pop() {
5257
5069
  try {
5258
- for(; this.#n;){
5259
- let e1 = this.#t[this.#l];
5260
- if (this.#G(!0), this.#e(e1)) {
5261
- if (e1.__staleWhileFetching) return e1.__staleWhileFetching;
5262
- } 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;
5263
5076
  }
5264
5077
  } finally{
5265
- if (this.#f && this.#r) {
5266
- let e1 = this.#r, t1;
5267
- 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);
5268
5082
  }
5269
5083
  }
5270
5084
  }
5271
- #G(e1) {
5272
- let t1 = this.#l, i = this.#i[t1], s = this.#t[t1];
5273
- 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([
5274
- s,
5275
- i,
5276
- "evict"
5277
- ])), 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;
5278
- }
5279
- has(e1, t1 = {}) {
5280
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
5281
- t1.status = i, i && (i.op = "has", i.key = e1);
5282
- let s = this.#Y(e1, t1);
5283
- return S.hasSubscribers && S.publish(i), s;
5284
- }
5285
- #Y(e1, t1 = {}) {
5286
- let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = t1, n = this.#s.get(e1);
5287
- if (void 0 !== n) {
5288
- let o = this.#t[n];
5289
- if (this.#e(o) && void 0 === o.__staleWhileFetching) return !1;
5290
- if (!this.#p(n)) return i && this.#x(n), s && (s.has = "hit", this.#E(s, n)), !0;
5291
- s && (s.has = "stale", this.#E(s, n));
5292
- } else s && (s.has = "miss");
5293
- return !1;
5294
- }
5295
- peek(e1, t1 = {}) {
5296
- let { status: i = D() ? {} : void 0 } = t1;
5297
- i && (i.op = "peek", i.key = e1), t1.status = i;
5298
- let s = this.#J(e1, t1);
5299
- return S.hasSubscribers && S.publish(i), s;
5300
- }
5301
- #J(e1, t1) {
5302
- let { status: i, allowStale: s = this.allowStale } = t1, n = this.#s.get(e1);
5303
- if (void 0 === n || !s && this.#p(n)) {
5304
- i && (i.peek = void 0 === n ? "miss" : "stale");
5305
- 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
+ ]);
5306
5097
  }
5307
- let o = this.#t[n], r = this.#e(o) ? o.__staleWhileFetching : o;
5308
- 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;
5309
5133
  }
5310
- #P(e1, t1, i, s) {
5311
- let n = void 0 === t1 ? void 0 : this.#t[t1];
5312
- if (this.#e(n)) return n;
5313
- let o = new AbortController, { signal: r } = i;
5314
- r?.addEventListener("abort", ()=>o.abort(r.reason), {
5315
- 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
5316
5148
  });
5317
- let h = {
5318
- signal: o.signal,
5319
- options: i,
5320
- context: s
5321
- }, l = (w, y = !1)=>{
5322
- let { aborted: a } = o.signal, m = i.ignoreFetchAbort && void 0 !== w, _ = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && void 0 !== w);
5323
- 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, _);
5324
- let b = p, d = this.#t[t1];
5325
- 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;
5326
- }, c = (w)=>(i.status && (i.status.fetchRejected = !0, i.status.fetchError = w), f(w, !1)), f = (w, y)=>{
5327
- let { aborted: a } = o.signal, m = a && i.allowStaleOnFetchAbort, _ = m || i.allowStaleOnFetchRejection, b = _ || i.noDeleteOnFetchRejection, d = p;
5328
- 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;
5329
- if (d.__returned === d) throw w;
5330
- }, g = (w, y)=>{
5331
- let a = this.#M?.(e1, n, h);
5332
- a && a instanceof Promise && a.then((m)=>w(void 0 === m ? void 0 : m), y), o.signal.addEventListener("abort", ()=>{
5333
- (!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
+ }
5334
5204
  });
5335
5205
  };
5336
- i.status && (i.status.fetchDispatched = !0);
5337
- let p = new Promise(g).then(l, c), T = Object.assign(p, {
5338
- __abortController: o,
5339
- __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,
5340
5211
  __returned: void 0
5341
5212
  });
5342
- return void 0 === t1 ? (this.#O(e1, T, {
5343
- ...h.options,
5344
- status: void 0
5345
- }), t1 = this.#s.get(e1)) : this.#t[t1] = T, T;
5346
- }
5347
- #e(e1) {
5348
- if (!this.#W) return !1;
5349
- let t1 = e1;
5350
- return !!t1 && t1 instanceof Promise && t1.hasOwnProperty("__staleWhileFetching") && t1.__abortController instanceof AbortController;
5351
- }
5352
- fetch(e1, t1 = {}) {
5353
- let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t1;
5354
- t1.status = s, s && t1.context && (s.context = t1.context);
5355
- let n = this.#B(e1, t1);
5356
- return s && D() && i && (s.trace = !0, W.tracePromise(()=>n, s).catch(()=>{})), n;
5357
- }
5358
- async #B(e1, t1 = {}) {
5359
- 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;
5360
- if (a && (a.op = "fetch", a.key = e1, y && (a.forceRefresh = !0)), !this.#W) return a && (a.fetch = "get"), this.#C(e1, {
5361
- allowStale: i,
5362
- updateAgeOnGet: s,
5363
- noDeleteOnStaleGet: n,
5364
- status: a
5365
- });
5366
- let _ = {
5367
- allowStale: i,
5368
- updateAgeOnGet: s,
5369
- noDeleteOnStaleGet: n,
5370
- ttl: o,
5371
- noDisposeOnSet: r,
5372
- size: h,
5373
- sizeCalculation: l,
5374
- noUpdateTTL: c,
5375
- noDeleteOnFetchRejection: f,
5376
- allowStaleOnFetchRejection: g,
5377
- allowStaleOnFetchAbort: T,
5378
- ignoreFetchAbort: p,
5379
- status: a,
5380
- signal: m
5381
- }, b = this.#s.get(e1);
5382
- if (void 0 === b) {
5383
- a && (a.fetch = "miss");
5384
- let d = this.#P(e1, b, _, w);
5385
- 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;
5386
5259
  }
5387
5260
  {
5388
- let d = this.#t[b];
5389
- if (this.#e(d)) {
5390
- let E = i && void 0 !== d.__staleWhileFetching;
5391
- return a && (a.fetch = "inflight", E && (a.returnedStale = !0)), E ? d.__staleWhileFetching : d.__returned = d;
5392
- }
5393
- let A = this.#p(b);
5394
- if (!y && !A) return a && (a.fetch = "hit"), this.#L(b), s && this.#x(b), a && this.#E(a, b), d;
5395
- let z = this.#P(e1, b, _, w), v = void 0 !== z.__staleWhileFetching && i;
5396
- return a && (a.fetch = A ? "stale" : "refresh", v && A && (a.returnedStale = !0)), v ? z.__staleWhileFetching : z.__returned = z;
5397
- }
5398
- }
5399
- forceFetch(e1, t1 = {}) {
5400
- let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t1;
5401
- t1.status = s, s && t1.context && (s.context = t1.context);
5402
- let n = this.#K(e1, t1);
5403
- return s && D() && i && (s.trace = !0, W.tracePromise(()=>n, s).catch(()=>{})), n;
5404
- }
5405
- async #K(e1, t1 = {}) {
5406
- let i = await this.#B(e1, t1);
5407
- if (void 0 === i) throw new Error("fetch() returned undefined");
5408
- return i;
5409
- }
5410
- memo(e1, t1 = {}) {
5411
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
5412
- t1.status = i, i && (i.op = "memo", i.key = e1, t1.context && (i.context = t1.context));
5413
- let s = this.#Q(e1, t1);
5414
- return i && (i.value = s), S.hasSubscribers && S.publish(i), s;
5415
- }
5416
- #Q(e1, t1 = {}) {
5417
- let i = this.#U;
5418
- if (!i) throw new Error("no memoMethod provided to constructor");
5419
- let { context: s, status: n, forceRefresh: o, ...r } = t1;
5420
- n && o && (n.forceRefresh = !0);
5421
- let h = this.#C(e1, r), l = o || void 0 === h;
5422
- if (n && (n.memo = l ? "miss" : "hit", l || (n.value = h)), !l) return h;
5423
- let c = i(e1, h, {
5424
- options: r,
5425
- 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
5426
5302
  });
5427
- return n && (n.value = c), this.#O(e1, c, r), c;
5428
- }
5429
- get(e1, t1 = {}) {
5430
- let { status: i = S.hasSubscribers ? {} : void 0 } = t1;
5431
- t1.status = i, i && (i.op = "get", i.key = e1);
5432
- let s = this.#C(e1, t1);
5433
- return i && (void 0 !== s && (i.value = s), S.hasSubscribers && S.publish(i)), s;
5434
- }
5435
- #C(e1, t1 = {}) {
5436
- let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = t1, r = this.#s.get(e1);
5437
- if (void 0 === r) {
5438
- o && (o.get = "miss");
5439
- 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;
5440
5328
  }
5441
- let h = this.#t[r], l = this.#e(h);
5442
- 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';
5443
5330
  }
5444
- #$(e1, t1) {
5445
- this.#c[t1] = e1, this.#a[e1] = t1;
5331
+ #connect(p, n) {
5332
+ this.#prev[n] = p;
5333
+ this.#next[p] = n;
5446
5334
  }
5447
- #L(e1) {
5448
- 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
+ }
5449
5342
  }
5450
- delete(e1) {
5451
- return this.#v(e1, "delete");
5343
+ delete(k) {
5344
+ return this.#delete(k, 'delete');
5452
5345
  }
5453
- #v(e1, t1) {
5454
- S.hasSubscribers && S.publish({
5455
- op: "delete",
5456
- delete: t1,
5457
- key: e1
5458
- });
5459
- let i = !1;
5460
- if (0 !== this.#n) {
5461
- let s = this.#s.get(e1);
5462
- 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);
5463
- else {
5464
- this.#R(s);
5465
- let n = this.#t[s];
5466
- 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([
5467
- n,
5468
- e1,
5469
- t1
5470
- ])), this.#s.delete(e1), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#c[s];
5471
- 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);
5472
5353
  else {
5473
- let o = this.#c[s];
5474
- this.#a[o] = this.#a[s];
5475
- let r = this.#a[s];
5476
- 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);
5477
5378
  }
5478
- this.#n--, this.#y.push(s);
5479
5379
  }
5480
5380
  }
5481
- if (this.#f && this.#r?.length) {
5482
- let s = this.#r, n;
5483
- 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);
5484
5385
  }
5485
- return i;
5386
+ return deleted;
5486
5387
  }
5487
5388
  clear() {
5488
- return this.#q("delete");
5389
+ return this.#clear('delete');
5489
5390
  }
5490
- #q(e1) {
5491
- for (let t1 of this.#z({
5492
- allowStale: !0
5391
+ #clear(reason) {
5392
+ for (const index of this.#rindexes({
5393
+ allowStale: true
5493
5394
  })){
5494
- let i = this.#t[t1];
5495
- 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'));
5496
5397
  else {
5497
- let s = this.#i[t1];
5498
- this.#T && this.#w?.(i, s, e1), this.#f && this.#r?.push([
5499
- i,
5500
- s,
5501
- 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
5502
5404
  ]);
5503
5405
  }
5504
5406
  }
5505
- if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#F) {
5506
- this.#d.fill(0), this.#F.fill(0);
5507
- for (let t1 of this.#g ?? [])void 0 !== t1 && clearTimeout(t1);
5508
- 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);
5509
5413
  }
5510
- 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) {
5511
- let t1 = this.#r, i;
5512
- 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);
5513
5424
  }
5514
5425
  }
5515
- };
5426
+ }
5516
5427
  var external_fs_ = __webpack_require__("fs");
5517
5428
  const promises_namespaceObject = require("node:fs/promises");
5518
5429
  const external_node_events_namespaceObject = require("node:events");
@@ -5589,7 +5500,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
5589
5500
  }
5590
5501
  constructor(src, dest, opts){
5591
5502
  super(src, dest, opts);
5592
- this.proxyErrors = (er)=>this.dest.emit('error', er);
5503
+ this.proxyErrors = (er)=>dest.emit('error', er);
5593
5504
  src.on('error', this.proxyErrors);
5594
5505
  }
5595
5506
  }
@@ -6041,8 +5952,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6041
5952
  return: stop,
6042
5953
  [Symbol.asyncIterator] () {
6043
5954
  return this;
6044
- },
6045
- [Symbol.asyncDispose]: async ()=>{}
5955
+ }
6046
5956
  };
6047
5957
  }
6048
5958
  [Symbol.iterator]() {
@@ -6076,8 +5986,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6076
5986
  return: stop,
6077
5987
  [Symbol.iterator] () {
6078
5988
  return this;
6079
- },
6080
- [Symbol.dispose]: ()=>{}
5989
+ }
6081
5990
  };
6082
5991
  }
6083
5992
  destroy(er) {
@@ -6144,9 +6053,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6144
6053
  const ENOCHILD = ENOTDIR | ENOENT | ENOREALPATH;
6145
6054
  const TYPEMASK = 1023;
6146
6055
  const entToType = (s)=>s.isFile() ? IFREG : s.isDirectory() ? IFDIR : s.isSymbolicLink() ? IFLNK : s.isCharacterDevice() ? IFCHR : s.isBlockDevice() ? IFBLK : s.isSocket() ? IFSOCK : s.isFIFO() ? IFIFO : UNKNOWN;
6147
- const normalizeCache = new L({
6148
- max: 4096
6149
- });
6056
+ const normalizeCache = new Map();
6150
6057
  const normalize = (s)=>{
6151
6058
  const c = normalizeCache.get(s);
6152
6059
  if (c) return c;
@@ -6154,9 +6061,7 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6154
6061
  normalizeCache.set(s, n);
6155
6062
  return n;
6156
6063
  };
6157
- const normalizeNocaseCache = new L({
6158
- max: 4096
6159
- });
6064
+ const normalizeNocaseCache = new Map();
6160
6065
  const normalizeNocase = (s)=>{
6161
6066
  const c = normalizeNocaseCache.get(s);
6162
6067
  if (c) return c;
@@ -6164,14 +6069,14 @@ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
6164
6069
  normalizeNocaseCache.set(s, n);
6165
6070
  return n;
6166
6071
  };
6167
- class ResolveCache extends L {
6072
+ class ResolveCache extends LRUCache {
6168
6073
  constructor(){
6169
6074
  super({
6170
6075
  max: 256
6171
6076
  });
6172
6077
  }
6173
6078
  }
6174
- class ChildrenCache extends L {
6079
+ class ChildrenCache extends LRUCache {
6175
6080
  constructor(maxSize = 16384){
6176
6081
  super({
6177
6082
  maxSize,
@@ -11305,7 +11210,7 @@ Usage:
11305
11210
  type: 'boolean',
11306
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}`
11307
11212
  }
11308
- }).version('version', 'Show version number', "1.8.8-beta-20260602094353.0").help().epilogue(`For complete list of configuration options, please visit:
11213
+ }).version('version', 'Show version number', "1.8.8").help().epilogue(`For complete list of configuration options, please visit:
11309
11214
  • Web options: https://midscenejs.com/automate-with-scripts-in-yaml#the-web-part
11310
11215
  • Android options: https://midscenejs.com/automate-with-scripts-in-yaml#the-android-part
11311
11216
  • iOS options: https://midscenejs.com/automate-with-scripts-in-yaml#the-ios-part