prettier 3.4.2 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/internal/cli.mjs CHANGED
@@ -59,12 +59,12 @@ var require_dashify = __commonJS({
59
59
  var require_minimist = __commonJS({
60
60
  "node_modules/minimist/index.js"(exports, module) {
61
61
  "use strict";
62
- function hasKey(obj, keys) {
62
+ function hasKey(obj, keys2) {
63
63
  var o = obj;
64
- keys.slice(0, -1).forEach(function(key2) {
64
+ keys2.slice(0, -1).forEach(function(key2) {
65
65
  o = o[key2] || {};
66
66
  });
67
- var key = keys[keys.length - 1];
67
+ var key = keys2[keys2.length - 1];
68
68
  return key in o;
69
69
  }
70
70
  function isNumber(x) {
@@ -125,10 +125,10 @@ var require_minimist = __commonJS({
125
125
  function argDefined(key2, arg2) {
126
126
  return flags.allBools && /^--[^=]+$/.test(arg2) || flags.strings[key2] || flags.bools[key2] || aliases[key2];
127
127
  }
128
- function setKey(obj, keys, value2) {
128
+ function setKey(obj, keys2, value2) {
129
129
  var o = obj;
130
- for (var i2 = 0; i2 < keys.length - 1; i2++) {
131
- var key2 = keys[i2];
130
+ for (var i2 = 0; i2 < keys2.length - 1; i2++) {
131
+ var key2 = keys2[i2];
132
132
  if (isConstructorOrProto(o, key2)) {
133
133
  return;
134
134
  }
@@ -143,7 +143,7 @@ var require_minimist = __commonJS({
143
143
  }
144
144
  o = o[key2];
145
145
  }
146
- var lastKey = keys[keys.length - 1];
146
+ var lastKey = keys2[keys2.length - 1];
147
147
  if (isConstructorOrProto(o, lastKey)) {
148
148
  return;
149
149
  }
@@ -295,7 +295,7 @@ var require_fast_json_stable_stringify = __commonJS({
295
295
  };
296
296
  }(opts.cmp);
297
297
  var seen = [];
298
- return function stringify4(node) {
298
+ return function stringify5(node) {
299
299
  if (node && node.toJSON && typeof node.toJSON === "function") {
300
300
  node = node.toJSON();
301
301
  }
@@ -307,7 +307,7 @@ var require_fast_json_stable_stringify = __commonJS({
307
307
  out = "[";
308
308
  for (i = 0; i < node.length; i++) {
309
309
  if (i) out += ",";
310
- out += stringify4(node[i]) || "null";
310
+ out += stringify5(node[i]) || "null";
311
311
  }
312
312
  return out + "]";
313
313
  }
@@ -317,11 +317,11 @@ var require_fast_json_stable_stringify = __commonJS({
317
317
  throw new TypeError("Converting circular structure to JSON");
318
318
  }
319
319
  var seenIndex = seen.push(node) - 1;
320
- var keys = Object.keys(node).sort(cmp && cmp(node));
320
+ var keys2 = Object.keys(node).sort(cmp && cmp(node));
321
321
  out = "";
322
- for (i = 0; i < keys.length; i++) {
323
- var key = keys[i];
324
- var value = stringify4(node[key]);
322
+ for (i = 0; i < keys2.length; i++) {
323
+ var key = keys2[i];
324
+ var value = stringify5(node[key]);
325
325
  if (!value) continue;
326
326
  if (out) out += ",";
327
327
  out += JSON.stringify(key) + ":" + value;
@@ -339,8 +339,8 @@ var require_common_path_prefix = __commonJS({
339
339
  "use strict";
340
340
  var { sep: DEFAULT_SEPARATOR } = __require("path");
341
341
  var determineSeparator = (paths) => {
342
- for (const path10 of paths) {
343
- const match = /(\/|\\)/.exec(path10);
342
+ for (const path12 of paths) {
343
+ const match = /(\/|\\)/.exec(path12);
344
344
  if (match !== null) return match[0];
345
345
  }
346
346
  return DEFAULT_SEPARATOR;
@@ -350,8 +350,8 @@ var require_common_path_prefix = __commonJS({
350
350
  if (first === "" || remaining.length === 0) return "";
351
351
  const parts = first.split(sep);
352
352
  let endOfPrefix = parts.length;
353
- for (const path10 of remaining) {
354
- const compare = path10.split(sep);
353
+ for (const path12 of remaining) {
354
+ const compare = path12.split(sep);
355
355
  for (let i = 0; i < endOfPrefix; i++) {
356
356
  if (compare[i] !== parts[i]) {
357
357
  endOfPrefix = i;
@@ -365,873 +365,18 @@ var require_common_path_prefix = __commonJS({
365
365
  }
366
366
  });
367
367
 
368
- // node_modules/json-buffer/index.js
369
- var require_json_buffer = __commonJS({
370
- "node_modules/json-buffer/index.js"(exports) {
371
- exports.stringify = function stringify4(o) {
372
- if ("undefined" == typeof o) return o;
373
- if (o && Buffer.isBuffer(o))
374
- return JSON.stringify(":base64:" + o.toString("base64"));
375
- if (o && o.toJSON)
376
- o = o.toJSON();
377
- if (o && "object" === typeof o) {
378
- var s = "";
379
- var array2 = Array.isArray(o);
380
- s = array2 ? "[" : "{";
381
- var first = true;
382
- for (var k in o) {
383
- var ignore = "function" == typeof o[k] || !array2 && "undefined" === typeof o[k];
384
- if (Object.hasOwnProperty.call(o, k) && !ignore) {
385
- if (!first)
386
- s += ",";
387
- first = false;
388
- if (array2) {
389
- if (o[k] == void 0)
390
- s += "null";
391
- else
392
- s += stringify4(o[k]);
393
- } else if (o[k] !== void 0) {
394
- s += stringify4(k) + ":" + stringify4(o[k]);
395
- }
396
- }
397
- }
398
- s += array2 ? "]" : "}";
399
- return s;
400
- } else if ("string" === typeof o) {
401
- return JSON.stringify(/^:/.test(o) ? ":" + o : o);
402
- } else if ("undefined" === typeof o) {
403
- return "null";
404
- } else
405
- return JSON.stringify(o);
406
- };
407
- exports.parse = function(s) {
408
- return JSON.parse(s, function(key, value) {
409
- if ("string" === typeof value) {
410
- if (/^:base64:/.test(value))
411
- return Buffer.from(value.substring(8), "base64");
412
- else
413
- return /^:/.test(value) ? value.substring(1) : value;
414
- }
415
- return value;
416
- });
417
- };
418
- }
419
- });
420
-
421
- // node_modules/keyv/src/index.js
422
- var require_src = __commonJS({
423
- "node_modules/keyv/src/index.js"(exports, module) {
424
- "use strict";
425
- var EventEmitter = __require("events");
426
- var JSONB = require_json_buffer();
427
- var loadStore = (options) => {
428
- const adapters = {
429
- redis: "@keyv/redis",
430
- rediss: "@keyv/redis",
431
- mongodb: "@keyv/mongo",
432
- mongo: "@keyv/mongo",
433
- sqlite: "@keyv/sqlite",
434
- postgresql: "@keyv/postgres",
435
- postgres: "@keyv/postgres",
436
- mysql: "@keyv/mysql",
437
- etcd: "@keyv/etcd",
438
- offline: "@keyv/offline",
439
- tiered: "@keyv/tiered"
440
- };
441
- if (options.adapter || options.uri) {
442
- const adapter = options.adapter || /^[^:+]*/.exec(options.uri)[0];
443
- return new (__require(adapters[adapter]))(options);
444
- }
445
- return /* @__PURE__ */ new Map();
446
- };
447
- var iterableAdapters = [
448
- "sqlite",
449
- "postgres",
450
- "mysql",
451
- "mongo",
452
- "redis",
453
- "tiered"
454
- ];
455
- var Keyv = class extends EventEmitter {
456
- constructor(uri, { emitErrors = true, ...options } = {}) {
457
- super();
458
- this.opts = {
459
- namespace: "keyv",
460
- serialize: JSONB.stringify,
461
- deserialize: JSONB.parse,
462
- ...typeof uri === "string" ? { uri } : uri,
463
- ...options
464
- };
465
- if (!this.opts.store) {
466
- const adapterOptions = { ...this.opts };
467
- this.opts.store = loadStore(adapterOptions);
468
- }
469
- if (this.opts.compression) {
470
- const compression = this.opts.compression;
471
- this.opts.serialize = compression.serialize.bind(compression);
472
- this.opts.deserialize = compression.deserialize.bind(compression);
473
- }
474
- if (typeof this.opts.store.on === "function" && emitErrors) {
475
- this.opts.store.on("error", (error) => this.emit("error", error));
476
- }
477
- this.opts.store.namespace = this.opts.namespace;
478
- const generateIterator = (iterator) => async function* () {
479
- for await (const [key, raw] of typeof iterator === "function" ? iterator(this.opts.store.namespace) : iterator) {
480
- const data = await this.opts.deserialize(raw);
481
- if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
482
- continue;
483
- }
484
- if (typeof data.expires === "number" && Date.now() > data.expires) {
485
- this.delete(key);
486
- continue;
487
- }
488
- yield [this._getKeyUnprefix(key), data.value];
489
- }
490
- };
491
- if (typeof this.opts.store[Symbol.iterator] === "function" && this.opts.store instanceof Map) {
492
- this.iterator = generateIterator(this.opts.store);
493
- } else if (typeof this.opts.store.iterator === "function" && this.opts.store.opts && this._checkIterableAdaptar()) {
494
- this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
495
- }
496
- }
497
- _checkIterableAdaptar() {
498
- return iterableAdapters.includes(this.opts.store.opts.dialect) || iterableAdapters.findIndex((element) => this.opts.store.opts.url.includes(element)) >= 0;
499
- }
500
- _getKeyPrefix(key) {
501
- return `${this.opts.namespace}:${key}`;
502
- }
503
- _getKeyPrefixArray(keys) {
504
- return keys.map((key) => `${this.opts.namespace}:${key}`);
505
- }
506
- _getKeyUnprefix(key) {
507
- return key.split(":").splice(1).join(":");
508
- }
509
- get(key, options) {
510
- const { store } = this.opts;
511
- const isArray = Array.isArray(key);
512
- const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
513
- if (isArray && store.getMany === void 0) {
514
- const promises = [];
515
- for (const key2 of keyPrefixed) {
516
- promises.push(
517
- Promise.resolve().then(() => store.get(key2)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
518
- if (data === void 0 || data === null) {
519
- return void 0;
520
- }
521
- if (typeof data.expires === "number" && Date.now() > data.expires) {
522
- return this.delete(key2).then(() => void 0);
523
- }
524
- return options && options.raw ? data : data.value;
525
- })
526
- );
527
- }
528
- return Promise.allSettled(promises).then((values) => {
529
- const data = [];
530
- for (const value of values) {
531
- data.push(value.value);
532
- }
533
- return data;
534
- });
535
- }
536
- return Promise.resolve().then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
537
- if (data === void 0 || data === null) {
538
- return void 0;
539
- }
540
- if (isArray) {
541
- return data.map((row, index) => {
542
- if (typeof row === "string") {
543
- row = this.opts.deserialize(row);
544
- }
545
- if (row === void 0 || row === null) {
546
- return void 0;
547
- }
548
- if (typeof row.expires === "number" && Date.now() > row.expires) {
549
- this.delete(key[index]).then(() => void 0);
550
- return void 0;
551
- }
552
- return options && options.raw ? row : row.value;
553
- });
554
- }
555
- if (typeof data.expires === "number" && Date.now() > data.expires) {
556
- return this.delete(key).then(() => void 0);
557
- }
558
- return options && options.raw ? data : data.value;
559
- });
560
- }
561
- set(key, value, ttl) {
562
- const keyPrefixed = this._getKeyPrefix(key);
563
- if (typeof ttl === "undefined") {
564
- ttl = this.opts.ttl;
565
- }
566
- if (ttl === 0) {
567
- ttl = void 0;
568
- }
569
- const { store } = this.opts;
570
- return Promise.resolve().then(() => {
571
- const expires = typeof ttl === "number" ? Date.now() + ttl : null;
572
- if (typeof value === "symbol") {
573
- this.emit("error", "symbol cannot be serialized");
574
- }
575
- value = { value, expires };
576
- return this.opts.serialize(value);
577
- }).then((value2) => store.set(keyPrefixed, value2, ttl)).then(() => true);
578
- }
579
- delete(key) {
580
- const { store } = this.opts;
581
- if (Array.isArray(key)) {
582
- const keyPrefixed2 = this._getKeyPrefixArray(key);
583
- if (store.deleteMany === void 0) {
584
- const promises = [];
585
- for (const key2 of keyPrefixed2) {
586
- promises.push(store.delete(key2));
587
- }
588
- return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
589
- }
590
- return Promise.resolve().then(() => store.deleteMany(keyPrefixed2));
591
- }
592
- const keyPrefixed = this._getKeyPrefix(key);
593
- return Promise.resolve().then(() => store.delete(keyPrefixed));
594
- }
595
- clear() {
596
- const { store } = this.opts;
597
- return Promise.resolve().then(() => store.clear());
598
- }
599
- has(key) {
600
- const keyPrefixed = this._getKeyPrefix(key);
601
- const { store } = this.opts;
602
- return Promise.resolve().then(async () => {
603
- if (typeof store.has === "function") {
604
- return store.has(keyPrefixed);
605
- }
606
- const value = await store.get(keyPrefixed);
607
- return value !== void 0;
608
- });
609
- }
610
- disconnect() {
611
- const { store } = this.opts;
612
- if (typeof store.disconnect === "function") {
613
- return store.disconnect();
614
- }
615
- }
616
- };
617
- module.exports = Keyv;
618
- }
619
- });
620
-
621
- // node_modules/flatted/cjs/index.js
622
- var require_cjs = __commonJS({
623
- "node_modules/flatted/cjs/index.js"(exports) {
624
- "use strict";
625
- var { parse: $parse, stringify: $stringify } = JSON;
626
- var { keys } = Object;
627
- var Primitive = String;
628
- var primitive = "string";
629
- var ignore = {};
630
- var object = "object";
631
- var noop = (_2, value) => value;
632
- var primitives = (value) => value instanceof Primitive ? Primitive(value) : value;
633
- var Primitives = (_2, value) => typeof value === primitive ? new Primitive(value) : value;
634
- var revive = (input, parsed, output, $) => {
635
- const lazy = [];
636
- for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
637
- const k = ke[y];
638
- const value = output[k];
639
- if (value instanceof Primitive) {
640
- const tmp = input[value];
641
- if (typeof tmp === object && !parsed.has(tmp)) {
642
- parsed.add(tmp);
643
- output[k] = ignore;
644
- lazy.push({ k, a: [input, parsed, tmp, $] });
645
- } else
646
- output[k] = $.call(output, k, tmp);
647
- } else if (output[k] !== ignore)
648
- output[k] = $.call(output, k, value);
649
- }
650
- for (let { length } = lazy, i = 0; i < length; i++) {
651
- const { k, a } = lazy[i];
652
- output[k] = $.call(output, k, revive.apply(null, a));
653
- }
654
- return output;
655
- };
656
- var set = (known, input, value) => {
657
- const index = Primitive(input.push(value) - 1);
658
- known.set(value, index);
659
- return index;
660
- };
661
- var parse = (text, reviver) => {
662
- const input = $parse(text, Primitives).map(primitives);
663
- const value = input[0];
664
- const $ = reviver || noop;
665
- const tmp = typeof value === object && value ? revive(input, /* @__PURE__ */ new Set(), value, $) : value;
666
- return $.call({ "": tmp }, "", tmp);
667
- };
668
- exports.parse = parse;
669
- var stringify4 = (value, replacer, space) => {
670
- const $ = replacer && typeof replacer === object ? (k, v) => k === "" || -1 < replacer.indexOf(k) ? v : void 0 : replacer || noop;
671
- const known = /* @__PURE__ */ new Map();
672
- const input = [];
673
- const output = [];
674
- let i = +set(known, input, $.call({ "": value }, "", value));
675
- let firstRun = !i;
676
- while (i < input.length) {
677
- firstRun = true;
678
- output[i] = $stringify(input[i++], replace, space);
679
- }
680
- return "[" + output.join(",") + "]";
681
- function replace(key, value2) {
682
- if (firstRun) {
683
- firstRun = !firstRun;
684
- return value2;
685
- }
686
- const after = $.call(this, key, value2);
687
- switch (typeof after) {
688
- case object:
689
- if (after === null) return after;
690
- case primitive:
691
- return known.get(after) || set(known, input, after);
692
- }
693
- return after;
694
- }
695
- };
696
- exports.stringify = stringify4;
697
- var toJSON = (value) => $parse(stringify4(value));
698
- exports.toJSON = toJSON;
699
- var fromJSON = (value) => parse($stringify(value));
700
- exports.fromJSON = fromJSON;
701
- }
702
- });
703
-
704
- // node_modules/flat-cache/src/utils.js
705
- var require_utils = __commonJS({
706
- "node_modules/flat-cache/src/utils.js"(exports, module) {
707
- var fs6 = __require("fs");
708
- var path10 = __require("path");
709
- var flatted = require_cjs();
710
- function tryParse(filePath, defaultValue) {
711
- let result;
712
- try {
713
- result = readJSON(filePath);
714
- } catch {
715
- result = defaultValue;
716
- }
717
- return result;
718
- }
719
- function readJSON(filePath) {
720
- return flatted.parse(
721
- fs6.readFileSync(filePath, {
722
- encoding: "utf8"
723
- })
724
- );
725
- }
726
- function writeJSON(filePath, data) {
727
- fs6.mkdirSync(path10.dirname(filePath), {
728
- recursive: true
729
- });
730
- fs6.writeFileSync(filePath, flatted.stringify(data));
731
- }
732
- module.exports = { tryParse, readJSON, writeJSON };
733
- }
734
- });
735
-
736
- // node_modules/flat-cache/src/del.js
737
- var require_del = __commonJS({
738
- "node_modules/flat-cache/src/del.js"(exports, module) {
739
- var fs6 = __require("fs");
740
- var path10 = __require("path");
741
- function del(targetPath) {
742
- if (!fs6.existsSync(targetPath)) {
743
- return false;
744
- }
745
- try {
746
- if (fs6.statSync(targetPath).isDirectory()) {
747
- for (const file of fs6.readdirSync(targetPath)) {
748
- const currentPath = path10.join(targetPath, file);
749
- if (fs6.statSync(currentPath).isFile()) {
750
- fs6.unlinkSync(currentPath);
751
- }
752
- }
753
- fs6.rmdirSync(targetPath);
754
- } else {
755
- fs6.unlinkSync(targetPath);
756
- }
757
- return true;
758
- } catch (error) {
759
- console.error(`Error while deleting ${targetPath}: ${error.message}`);
760
- }
761
- }
762
- module.exports = { del };
763
- }
764
- });
765
-
766
- // node_modules/flat-cache/src/cache.js
767
- var require_cache = __commonJS({
768
- "node_modules/flat-cache/src/cache.js"(exports, module) {
769
- var path10 = __require("path");
770
- var fs6 = __require("fs");
771
- var Keyv = require_src();
772
- var { writeJSON, tryParse } = require_utils();
773
- var { del } = require_del();
774
- var cache = {
775
- /**
776
- * Load a cache identified by the given Id. If the element does not exists, then initialize an empty
777
- * cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
778
- * then the cache module directory `./cache` will be used instead
779
- *
780
- * @method load
781
- * @param docId {String} the id of the cache, would also be used as the name of the file cache
782
- * @param [cacheDir] {String} directory for the cache entry
783
- */
784
- load(documentId, cacheDir) {
785
- const me = this;
786
- me.keyv = new Keyv();
787
- me.__visited = {};
788
- me.__persisted = {};
789
- me._pathToFile = cacheDir ? path10.resolve(cacheDir, documentId) : path10.resolve(__dirname, "../.cache/", documentId);
790
- if (fs6.existsSync(me._pathToFile)) {
791
- me._persisted = tryParse(me._pathToFile, {});
792
- }
793
- },
794
- get _persisted() {
795
- return this.__persisted;
796
- },
797
- set _persisted(value) {
798
- this.__persisted = value;
799
- },
800
- get _visited() {
801
- return this.__visited;
802
- },
803
- set _visited(value) {
804
- this.__visited = value;
805
- },
806
- /**
807
- * Load the cache from the provided file
808
- * @method loadFile
809
- * @param {String} pathToFile the path to the file containing the info for the cache
810
- */
811
- loadFile(pathToFile) {
812
- const me = this;
813
- const dir = path10.dirname(pathToFile);
814
- const fName = path10.basename(pathToFile);
815
- me.load(fName, dir);
816
- },
817
- /**
818
- * Returns the entire persisted object
819
- * @method all
820
- * @returns {*}
821
- */
822
- all() {
823
- return this._persisted;
824
- },
825
- keys() {
826
- return Object.keys(this._persisted);
827
- },
828
- /**
829
- * Sets a key to a given value
830
- * @method setKey
831
- * @param key {string} the key to set
832
- * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
833
- */
834
- setKey(key, value) {
835
- this._visited[key] = true;
836
- this._persisted[key] = value;
837
- },
838
- /**
839
- * Remove a given key from the cache
840
- * @method removeKey
841
- * @param key {String} the key to remove from the object
842
- */
843
- removeKey(key) {
844
- delete this._visited[key];
845
- delete this._persisted[key];
846
- },
847
- /**
848
- * Return the value of the provided key
849
- * @method getKey
850
- * @param key {String} the name of the key to retrieve
851
- * @returns {*} the value from the key
852
- */
853
- getKey(key) {
854
- this._visited[key] = true;
855
- return this._persisted[key];
856
- },
857
- /**
858
- * Remove keys that were not accessed/set since the
859
- * last time the `prune` method was called.
860
- * @method _prune
861
- * @private
862
- */
863
- _prune() {
864
- const me = this;
865
- const object = {};
866
- const keys = Object.keys(me._visited);
867
- if (keys.length === 0) {
868
- return;
869
- }
870
- for (const key of keys) {
871
- object[key] = me._persisted[key];
872
- }
873
- me._visited = {};
874
- me._persisted = object;
875
- },
876
- /**
877
- * Save the state of the cache identified by the docId to disk
878
- * as a JSON structure
879
- * @param [noPrune=false] {Boolean} whether to remove from cache the non visited files
880
- * @method save
881
- */
882
- save(noPrune) {
883
- const me = this;
884
- !noPrune && me._prune();
885
- writeJSON(me._pathToFile, me._persisted);
886
- },
887
- /**
888
- * Remove the file where the cache is persisted
889
- * @method removeCacheFile
890
- * @return {Boolean} true or false if the file was successfully deleted
891
- */
892
- removeCacheFile() {
893
- return del(this._pathToFile);
894
- },
895
- /**
896
- * Destroy the file cache and cache content.
897
- * @method destroy
898
- */
899
- destroy() {
900
- const me = this;
901
- me._visited = {};
902
- me._persisted = {};
903
- me.removeCacheFile();
904
- }
905
- };
906
- module.exports = {
907
- /**
908
- * Alias for create. Should be considered depreacted. Will be removed in next releases
909
- *
910
- * @method load
911
- * @param docId {String} the id of the cache, would also be used as the name of the file cache
912
- * @param [cacheDir] {String} directory for the cache entry
913
- * @returns {cache} cache instance
914
- */
915
- load(documentId, cacheDir) {
916
- return this.create(documentId, cacheDir);
917
- },
918
- /**
919
- * Load a cache identified by the given Id. If the element does not exists, then initialize an empty
920
- * cache storage.
921
- *
922
- * @method create
923
- * @param docId {String} the id of the cache, would also be used as the name of the file cache
924
- * @param [cacheDir] {String} directory for the cache entry
925
- * @returns {cache} cache instance
926
- */
927
- create(documentId, cacheDir) {
928
- const object = Object.create(cache);
929
- object.load(documentId, cacheDir);
930
- return object;
931
- },
932
- createFromFile(filePath) {
933
- const object = Object.create(cache);
934
- object.loadFile(filePath);
935
- return object;
936
- },
937
- /**
938
- * Clear the cache identified by the given id. Caches stored in a different cache directory can be deleted directly
939
- *
940
- * @method clearCache
941
- * @param docId {String} the id of the cache, would also be used as the name of the file cache
942
- * @param cacheDir {String} the directory where the cache file was written
943
- * @returns {Boolean} true if the cache folder was deleted. False otherwise
944
- */
945
- clearCacheById(documentId, cacheDir) {
946
- const filePath = cacheDir ? path10.resolve(cacheDir, documentId) : path10.resolve(__dirname, "../.cache/", documentId);
947
- return del(filePath);
948
- },
949
- /**
950
- * Remove all cache stored in the cache directory
951
- * @method clearAll
952
- * @returns {Boolean} true if the cache folder was deleted. False otherwise
953
- */
954
- clearAll(cacheDir) {
955
- const filePath = cacheDir ? path10.resolve(cacheDir) : path10.resolve(__dirname, "../.cache/");
956
- return del(filePath);
957
- }
958
- };
959
- }
960
- });
961
-
962
- // node_modules/file-entry-cache/cache.js
963
- var require_cache2 = __commonJS({
964
- "node_modules/file-entry-cache/cache.js"(exports, module) {
965
- var path10 = __require("path");
966
- var crypto = __require("crypto");
967
- module.exports = {
968
- createFromFile(filePath, useChecksum, currentWorkingDir) {
969
- const fname = path10.basename(filePath);
970
- const dir = path10.dirname(filePath);
971
- return this.create(fname, dir, useChecksum, currentWorkingDir);
972
- },
973
- create(cacheId, _path, useChecksum, currentWorkingDir) {
974
- const fs6 = __require("fs");
975
- const flatCache = require_cache();
976
- const cache = flatCache.load(cacheId, _path);
977
- let normalizedEntries = {};
978
- const removeNotFoundFiles = function removeNotFoundFiles2() {
979
- const cachedEntries = cache.keys();
980
- for (const fPath of cachedEntries) {
981
- try {
982
- let filePath = fPath;
983
- if (currentWorkingDir) {
984
- filePath = path10.join(currentWorkingDir, fPath);
985
- }
986
- fs6.statSync(filePath);
987
- } catch (error) {
988
- if (error.code === "ENOENT") {
989
- cache.removeKey(fPath);
990
- }
991
- }
992
- }
993
- };
994
- removeNotFoundFiles();
995
- return {
996
- /**
997
- * The flat cache storage used to persist the metadata of the `files
998
- * @type {Object}
999
- */
1000
- cache,
1001
- /**
1002
- * To enable relative paths as the key with current working directory
1003
- * @type {string}
1004
- */
1005
- currentWorkingDir: currentWorkingDir ?? void 0,
1006
- /**
1007
- * Given a buffer, calculate md5 hash of its content.
1008
- * @method getHash
1009
- * @param {Buffer} buffer buffer to calculate hash on
1010
- * @return {String} content hash digest
1011
- */
1012
- getHash(buffer) {
1013
- return crypto.createHash("md5").update(buffer).digest("hex");
1014
- },
1015
- /**
1016
- * Return whether or not a file has changed since last time reconcile was called.
1017
- * @method hasFileChanged
1018
- * @param {String} file the filepath to check
1019
- * @return {Boolean} wheter or not the file has changed
1020
- */
1021
- hasFileChanged(file) {
1022
- return this.getFileDescriptor(file).changed;
1023
- },
1024
- /**
1025
- * Given an array of file paths it return and object with three arrays:
1026
- * - changedFiles: Files that changed since previous run
1027
- * - notChangedFiles: Files that haven't change
1028
- * - notFoundFiles: Files that were not found, probably deleted
1029
- *
1030
- * @param {Array} files the files to analyze and compare to the previous seen files
1031
- * @return {[type]} [description]
1032
- */
1033
- analyzeFiles(files) {
1034
- const me = this;
1035
- files || (files = []);
1036
- const res = {
1037
- changedFiles: [],
1038
- notFoundFiles: [],
1039
- notChangedFiles: []
1040
- };
1041
- for (const entry of me.normalizeEntries(files)) {
1042
- if (entry.changed) {
1043
- res.changedFiles.push(entry.key);
1044
- continue;
1045
- }
1046
- if (entry.notFound) {
1047
- res.notFoundFiles.push(entry.key);
1048
- continue;
1049
- }
1050
- res.notChangedFiles.push(entry.key);
1051
- }
1052
- return res;
1053
- },
1054
- getFileDescriptor(file) {
1055
- let fstat;
1056
- try {
1057
- fstat = fs6.statSync(file);
1058
- } catch (error) {
1059
- this.removeEntry(file);
1060
- return { key: file, notFound: true, err: error };
1061
- }
1062
- if (useChecksum) {
1063
- return this._getFileDescriptorUsingChecksum(file);
1064
- }
1065
- return this._getFileDescriptorUsingMtimeAndSize(file, fstat);
1066
- },
1067
- _getFileKey(file) {
1068
- if (this.currentWorkingDir) {
1069
- return file.split(this.currentWorkingDir).pop();
1070
- }
1071
- return file;
1072
- },
1073
- _getFileDescriptorUsingMtimeAndSize(file, fstat) {
1074
- let meta = cache.getKey(this._getFileKey(file));
1075
- const cacheExists = Boolean(meta);
1076
- const cSize = fstat.size;
1077
- const cTime = fstat.mtime.getTime();
1078
- let isDifferentDate;
1079
- let isDifferentSize;
1080
- if (meta) {
1081
- isDifferentDate = cTime !== meta.mtime;
1082
- isDifferentSize = cSize !== meta.size;
1083
- } else {
1084
- meta = { size: cSize, mtime: cTime };
1085
- }
1086
- const nEntry = normalizedEntries[this._getFileKey(file)] = {
1087
- key: this._getFileKey(file),
1088
- changed: !cacheExists || isDifferentDate || isDifferentSize,
1089
- meta
1090
- };
1091
- return nEntry;
1092
- },
1093
- _getFileDescriptorUsingChecksum(file) {
1094
- let meta = cache.getKey(this._getFileKey(file));
1095
- const cacheExists = Boolean(meta);
1096
- let contentBuffer;
1097
- try {
1098
- contentBuffer = fs6.readFileSync(file);
1099
- } catch {
1100
- contentBuffer = "";
1101
- }
1102
- let isDifferent = true;
1103
- const hash = this.getHash(contentBuffer);
1104
- if (meta) {
1105
- isDifferent = hash !== meta.hash;
1106
- } else {
1107
- meta = { hash };
1108
- }
1109
- const nEntry = normalizedEntries[this._getFileKey(file)] = {
1110
- key: this._getFileKey(file),
1111
- changed: !cacheExists || isDifferent,
1112
- meta
1113
- };
1114
- return nEntry;
1115
- },
1116
- /**
1117
- * Return the list o the files that changed compared
1118
- * against the ones stored in the cache
1119
- *
1120
- * @method getUpdated
1121
- * @param files {Array} the array of files to compare against the ones in the cache
1122
- * @returns {Array}
1123
- */
1124
- getUpdatedFiles(files) {
1125
- const me = this;
1126
- files || (files = []);
1127
- return me.normalizeEntries(files).filter((entry) => entry.changed).map((entry) => entry.key);
1128
- },
1129
- /**
1130
- * Return the list of files
1131
- * @method normalizeEntries
1132
- * @param files
1133
- * @returns {*}
1134
- */
1135
- normalizeEntries(files) {
1136
- files || (files = []);
1137
- const me = this;
1138
- const nEntries = files.map((file) => me.getFileDescriptor(file));
1139
- return nEntries;
1140
- },
1141
- /**
1142
- * Remove an entry from the file-entry-cache. Useful to force the file to still be considered
1143
- * modified the next time the process is run
1144
- *
1145
- * @method removeEntry
1146
- * @param entryName
1147
- */
1148
- removeEntry(entryName) {
1149
- delete normalizedEntries[this._getFileKey(entryName)];
1150
- cache.removeKey(this._getFileKey(entryName));
1151
- },
1152
- /**
1153
- * Delete the cache file from the disk
1154
- * @method deleteCacheFile
1155
- */
1156
- deleteCacheFile() {
1157
- cache.removeCacheFile();
1158
- },
1159
- /**
1160
- * Remove the cache from the file and clear the memory cache
1161
- */
1162
- destroy() {
1163
- normalizedEntries = {};
1164
- cache.destroy();
1165
- },
1166
- _getMetaForFileUsingCheckSum(cacheEntry) {
1167
- let filePath = cacheEntry.key;
1168
- if (this.currentWorkingDir) {
1169
- filePath = path10.join(this.currentWorkingDir, filePath);
1170
- }
1171
- const contentBuffer = fs6.readFileSync(filePath);
1172
- const hash = this.getHash(contentBuffer);
1173
- const meta = Object.assign(cacheEntry.meta, { hash });
1174
- delete meta.size;
1175
- delete meta.mtime;
1176
- return meta;
1177
- },
1178
- _getMetaForFileUsingMtimeAndSize(cacheEntry) {
1179
- let filePath = cacheEntry.key;
1180
- if (currentWorkingDir) {
1181
- filePath = path10.join(currentWorkingDir, filePath);
1182
- }
1183
- const stat = fs6.statSync(filePath);
1184
- const meta = Object.assign(cacheEntry.meta, {
1185
- size: stat.size,
1186
- mtime: stat.mtime.getTime()
1187
- });
1188
- delete meta.hash;
1189
- return meta;
1190
- },
1191
- /**
1192
- * Sync the files and persist them to the cache
1193
- * @method reconcile
1194
- */
1195
- reconcile(noPrune) {
1196
- removeNotFoundFiles();
1197
- noPrune = noPrune === void 0 ? true : noPrune;
1198
- const entries = normalizedEntries;
1199
- const keys = Object.keys(entries);
1200
- if (keys.length === 0) {
1201
- return;
1202
- }
1203
- const me = this;
1204
- for (const entryName of keys) {
1205
- const cacheEntry = entries[entryName];
1206
- try {
1207
- const meta = useChecksum ? me._getMetaForFileUsingCheckSum(cacheEntry) : me._getMetaForFileUsingMtimeAndSize(cacheEntry);
1208
- cache.setKey(this._getFileKey(entryName), meta);
1209
- } catch (error) {
1210
- if (error.code !== "ENOENT") {
1211
- throw error;
1212
- }
1213
- }
1214
- }
1215
- cache.save(noPrune);
1216
- }
1217
- };
1218
- }
1219
- };
1220
- }
1221
- });
1222
-
1223
368
  // src/cli/index.js
1224
369
  import * as prettier2 from "../index.mjs";
1225
370
 
1226
371
  // scripts/build/shims/at.js
1227
- var at = (isOptionalObject, object, index) => {
1228
- if (isOptionalObject && (object === void 0 || object === null)) {
372
+ var at = (isOptionalObject, object2, index) => {
373
+ if (isOptionalObject && (object2 === void 0 || object2 === null)) {
1229
374
  return;
1230
375
  }
1231
- if (Array.isArray(object) || typeof object === "string") {
1232
- return object[index < 0 ? object.length + index : index];
376
+ if (Array.isArray(object2) || typeof object2 === "string") {
377
+ return object2[index < 0 ? object2.length + index : index];
1233
378
  }
1234
- return object.at(index);
379
+ return object2.at(index);
1235
380
  };
1236
381
  var at_default = at;
1237
382
 
@@ -1605,11 +750,11 @@ import path from "path";
1605
750
 
1606
751
  // node_modules/sdbm/index.js
1607
752
  function sdbm(string) {
1608
- let hash = 0;
753
+ let hash2 = 0;
1609
754
  for (let i = 0; i < string.length; i++) {
1610
- hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash;
755
+ hash2 = string.charCodeAt(i) + (hash2 << 6) + (hash2 << 16) - hash2;
1611
756
  }
1612
- return hash >>> 0;
757
+ return hash2 >>> 0;
1613
758
  }
1614
759
 
1615
760
  // src/cli/utils.js
@@ -1627,8 +772,8 @@ function groupBy(array2, iteratee) {
1627
772
  }
1628
773
  return result;
1629
774
  }
1630
- function pick(object, keys) {
1631
- const entries = keys.map((key) => [key, object[key]]);
775
+ function pick(object2, keys2) {
776
+ const entries = keys2.map((key) => [key, object2[key]]);
1632
777
  return Object.fromEntries(entries);
1633
778
  }
1634
779
  function createHash(source) {
@@ -1973,10 +1118,10 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
1973
1118
  return 1;
1974
1119
  }
1975
1120
  if ("CI" in env) {
1976
- if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
1121
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
1977
1122
  return 3;
1978
1123
  }
1979
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
1124
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
1980
1125
  return 1;
1981
1126
  }
1982
1127
  return min;
@@ -2067,12 +1212,12 @@ var levelMapping = [
2067
1212
  "ansi16m"
2068
1213
  ];
2069
1214
  var styles2 = /* @__PURE__ */ Object.create(null);
2070
- var applyOptions = (object, options = {}) => {
1215
+ var applyOptions = (object2, options = {}) => {
2071
1216
  if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2072
1217
  throw new Error("The `level` option should be an integer from 0 to 3");
2073
1218
  }
2074
1219
  const colorLevel = stdoutColor ? stdoutColor.level : 0;
2075
- object.level = options.level === void 0 ? colorLevel : options.level;
1220
+ object2.level = options.level === void 0 ? colorLevel : options.level;
2076
1221
  };
2077
1222
  var chalkFactory = (options) => {
2078
1223
  const chalk2 = (...strings) => strings.join(" ");
@@ -2296,15 +1441,15 @@ function normalizeCliOptions(options, optionInfos, opts) {
2296
1441
  var normalize_cli_options_default = normalizeCliOptions;
2297
1442
 
2298
1443
  // src/cli/options/parse-cli-arguments.js
2299
- function parseArgv(rawArguments, detailedOptions, logger, keys) {
1444
+ function parseArgv(rawArguments, detailedOptions, logger, keys2) {
2300
1445
  var _a;
2301
1446
  const minimistOptions = createMinimistOptions(detailedOptions);
2302
1447
  let argv = minimistParse(rawArguments, minimistOptions);
2303
- if (keys) {
1448
+ if (keys2) {
2304
1449
  detailedOptions = detailedOptions.filter(
2305
- (option) => keys.includes(option.name)
1450
+ (option) => keys2.includes(option.name)
2306
1451
  );
2307
- argv = pick(argv, keys);
1452
+ argv = pick(argv, keys2);
2308
1453
  }
2309
1454
  const normalized = normalize_cli_options_default(argv, detailedOptions, { logger });
2310
1455
  return {
@@ -2321,12 +1466,12 @@ function parseArgv(rawArguments, detailedOptions, logger, keys) {
2321
1466
  };
2322
1467
  }
2323
1468
  var { detailedOptions: detailedOptionsWithoutPlugins } = getContextOptionsWithoutPlugins();
2324
- function parseArgvWithoutPlugins(rawArguments, logger, keys) {
1469
+ function parseArgvWithoutPlugins(rawArguments, logger, keys2) {
2325
1470
  return parseArgv(
2326
1471
  rawArguments,
2327
1472
  detailedOptionsWithoutPlugins,
2328
1473
  logger,
2329
- typeof keys === "string" ? [keys] : keys
1474
+ typeof keys2 === "string" ? [keys2] : keys2
2330
1475
  );
2331
1476
  }
2332
1477
 
@@ -2428,8 +1573,8 @@ async function logResolvedConfigPathOrDie(context) {
2428
1573
  var find_config_path_default = logResolvedConfigPathOrDie;
2429
1574
 
2430
1575
  // src/cli/format.js
2431
- import fs5 from "fs/promises";
2432
- import path9 from "path";
1576
+ import fs7 from "fs/promises";
1577
+ import path11 from "path";
2433
1578
  import * as prettier from "../index.mjs";
2434
1579
 
2435
1580
  // src/cli/expand-patterns.js
@@ -2551,7 +1696,7 @@ function containsIgnoredPathSegment(absolutePath, cwd2, ignoredDirectories) {
2551
1696
  function sortPaths(paths) {
2552
1697
  return paths.sort((a, b) => a.localeCompare(b));
2553
1698
  }
2554
- function escapePathForGlob(path10) {
1699
+ function escapePathForGlob(path12) {
2555
1700
  return string_replace_all_default(
2556
1701
  /* isOptionalObject */
2557
1702
  false,
@@ -2562,7 +1707,7 @@ function escapePathForGlob(path10) {
2562
1707
  string_replace_all_default(
2563
1708
  /* isOptionalObject */
2564
1709
  false,
2565
- path10,
1710
+ path12,
2566
1711
  "\\",
2567
1712
  "\0"
2568
1713
  )
@@ -2684,9 +1829,9 @@ function packageDirectorySync({ cwd: cwd2 } = {}) {
2684
1829
 
2685
1830
  // node_modules/find-cache-dir/index.js
2686
1831
  var { env: env2, cwd } = process4;
2687
- var isWritable = (path10) => {
1832
+ var isWritable = (path12) => {
2688
1833
  try {
2689
- fs3.accessSync(path10, fs3.constants.W_OK);
1834
+ fs3.accessSync(path12, fs3.constants.W_OK);
2690
1835
  return true;
2691
1836
  } catch {
2692
1837
  return false;
@@ -2760,7 +1905,1831 @@ var find_cache_file_default = findCacheFile;
2760
1905
 
2761
1906
  // src/cli/format-results-cache.js
2762
1907
  var import_fast_json_stable_stringify2 = __toESM(require_fast_json_stable_stringify(), 1);
2763
- var import_file_entry_cache = __toESM(require_cache2(), 1);
1908
+
1909
+ // node_modules/file-entry-cache/dist/index.js
1910
+ import crypto2 from "crypto";
1911
+ import fs6 from "fs";
1912
+ import path10 from "path";
1913
+
1914
+ // node_modules/file-entry-cache/node_modules/flat-cache/dist/index.js
1915
+ import path9 from "path";
1916
+ import fs5 from "fs";
1917
+
1918
+ // node_modules/hookified/dist/node/index.js
1919
+ var Eventified = class {
1920
+ _eventListeners;
1921
+ _maxListeners;
1922
+ constructor() {
1923
+ this._eventListeners = /* @__PURE__ */ new Map();
1924
+ this._maxListeners = 100;
1925
+ }
1926
+ /**
1927
+ * Adds a handler function for a specific event that will run only once
1928
+ * @param {string | symbol} eventName
1929
+ * @param {EventListener} listener
1930
+ * @returns {IEventEmitter} returns the instance of the class for chaining
1931
+ */
1932
+ once(eventName, listener) {
1933
+ const onceListener = (...arguments_) => {
1934
+ this.off(eventName, onceListener);
1935
+ listener(...arguments_);
1936
+ };
1937
+ this.on(eventName, onceListener);
1938
+ return this;
1939
+ }
1940
+ /**
1941
+ * Gets the number of listeners for a specific event. If no event is provided, it returns the total number of listeners
1942
+ * @param {string} eventName The event name. Not required
1943
+ * @returns {number} The number of listeners
1944
+ */
1945
+ listenerCount(eventName) {
1946
+ if (!eventName) {
1947
+ return this.getAllListeners().length;
1948
+ }
1949
+ const listeners = this._eventListeners.get(eventName);
1950
+ return listeners ? listeners.length : 0;
1951
+ }
1952
+ /**
1953
+ * Gets an array of event names
1954
+ * @returns {Array<string | symbol>} An array of event names
1955
+ */
1956
+ eventNames() {
1957
+ return Array.from(this._eventListeners.keys());
1958
+ }
1959
+ /**
1960
+ * Gets an array of listeners for a specific event. If no event is provided, it returns all listeners
1961
+ * @param {string} [event] (Optional) The event name
1962
+ * @returns {EventListener[]} An array of listeners
1963
+ */
1964
+ rawListeners(event) {
1965
+ if (!event) {
1966
+ return this.getAllListeners();
1967
+ }
1968
+ return this._eventListeners.get(event) ?? [];
1969
+ }
1970
+ /**
1971
+ * Prepends a listener to the beginning of the listeners array for the specified event
1972
+ * @param {string | symbol} eventName
1973
+ * @param {EventListener} listener
1974
+ * @returns {IEventEmitter} returns the instance of the class for chaining
1975
+ */
1976
+ prependListener(eventName, listener) {
1977
+ const listeners = this._eventListeners.get(eventName) ?? [];
1978
+ listeners.unshift(listener);
1979
+ this._eventListeners.set(eventName, listeners);
1980
+ return this;
1981
+ }
1982
+ /**
1983
+ * Prepends a one-time listener to the beginning of the listeners array for the specified event
1984
+ * @param {string | symbol} eventName
1985
+ * @param {EventListener} listener
1986
+ * @returns {IEventEmitter} returns the instance of the class for chaining
1987
+ */
1988
+ prependOnceListener(eventName, listener) {
1989
+ const onceListener = (...arguments_) => {
1990
+ this.off(eventName, onceListener);
1991
+ listener(...arguments_);
1992
+ };
1993
+ this.prependListener(eventName, onceListener);
1994
+ return this;
1995
+ }
1996
+ /**
1997
+ * Gets the maximum number of listeners that can be added for a single event
1998
+ * @returns {number} The maximum number of listeners
1999
+ */
2000
+ maxListeners() {
2001
+ return this._maxListeners;
2002
+ }
2003
+ /**
2004
+ * Adds a listener for a specific event. It is an alias for the on() method
2005
+ * @param {string | symbol} event
2006
+ * @param {EventListener} listener
2007
+ * @returns {IEventEmitter} returns the instance of the class for chaining
2008
+ */
2009
+ addListener(event, listener) {
2010
+ this.on(event, listener);
2011
+ return this;
2012
+ }
2013
+ /**
2014
+ * Adds a listener for a specific event
2015
+ * @param {string | symbol} event
2016
+ * @param {EventListener} listener
2017
+ * @returns {IEventEmitter} returns the instance of the class for chaining
2018
+ */
2019
+ on(event, listener) {
2020
+ if (!this._eventListeners.has(event)) {
2021
+ this._eventListeners.set(event, []);
2022
+ }
2023
+ const listeners = this._eventListeners.get(event);
2024
+ if (listeners) {
2025
+ if (listeners.length >= this._maxListeners) {
2026
+ console.warn(`MaxListenersExceededWarning: Possible event memory leak detected. ${listeners.length + 1} ${event} listeners added. Use setMaxListeners() to increase limit.`);
2027
+ }
2028
+ listeners.push(listener);
2029
+ }
2030
+ return this;
2031
+ }
2032
+ /**
2033
+ * Removes a listener for a specific event. It is an alias for the off() method
2034
+ * @param {string | symbol} event
2035
+ * @param {EventListener} listener
2036
+ * @returns {IEventEmitter} returns the instance of the class for chaining
2037
+ */
2038
+ removeListener(event, listener) {
2039
+ this.off(event, listener);
2040
+ return this;
2041
+ }
2042
+ /**
2043
+ * Removes a listener for a specific event
2044
+ * @param {string | symbol} event
2045
+ * @param {EventListener} listener
2046
+ * @returns {IEventEmitter} returns the instance of the class for chaining
2047
+ */
2048
+ off(event, listener) {
2049
+ const listeners = this._eventListeners.get(event) ?? [];
2050
+ const index = listeners.indexOf(listener);
2051
+ if (index !== -1) {
2052
+ listeners.splice(index, 1);
2053
+ }
2054
+ if (listeners.length === 0) {
2055
+ this._eventListeners.delete(event);
2056
+ }
2057
+ return this;
2058
+ }
2059
+ /**
2060
+ * Calls all listeners for a specific event
2061
+ * @param {string | symbol} event
2062
+ * @param arguments_ The arguments to pass to the listeners
2063
+ * @returns {boolean} Returns true if the event had listeners, false otherwise
2064
+ */
2065
+ emit(event, ...arguments_) {
2066
+ let result = false;
2067
+ const listeners = this._eventListeners.get(event);
2068
+ if (listeners && listeners.length > 0) {
2069
+ for (const listener of listeners) {
2070
+ listener(...arguments_);
2071
+ result = true;
2072
+ }
2073
+ }
2074
+ return result;
2075
+ }
2076
+ /**
2077
+ * Gets all listeners for a specific event. If no event is provided, it returns all listeners
2078
+ * @param {string} [event] (Optional) The event name
2079
+ * @returns {EventListener[]} An array of listeners
2080
+ */
2081
+ listeners(event) {
2082
+ return this._eventListeners.get(event) ?? [];
2083
+ }
2084
+ /**
2085
+ * Removes all listeners for a specific event. If no event is provided, it removes all listeners
2086
+ * @param {string} [event] (Optional) The event name
2087
+ * @returns {IEventEmitter} returns the instance of the class for chaining
2088
+ */
2089
+ removeAllListeners(event) {
2090
+ if (event) {
2091
+ this._eventListeners.delete(event);
2092
+ } else {
2093
+ this._eventListeners.clear();
2094
+ }
2095
+ return this;
2096
+ }
2097
+ /**
2098
+ * Sets the maximum number of listeners that can be added for a single event
2099
+ * @param {number} n The maximum number of listeners
2100
+ * @returns {void}
2101
+ */
2102
+ setMaxListeners(n) {
2103
+ this._maxListeners = n;
2104
+ for (const listeners of this._eventListeners.values()) {
2105
+ if (listeners.length > n) {
2106
+ listeners.splice(n);
2107
+ }
2108
+ }
2109
+ }
2110
+ /**
2111
+ * Gets all listeners
2112
+ * @returns {EventListener[]} An array of listeners
2113
+ */
2114
+ getAllListeners() {
2115
+ let result = new Array();
2116
+ for (const listeners of this._eventListeners.values()) {
2117
+ result = result.concat(listeners);
2118
+ }
2119
+ return result;
2120
+ }
2121
+ };
2122
+ var Hookified = class extends Eventified {
2123
+ _hooks;
2124
+ _throwHookErrors = false;
2125
+ constructor(options) {
2126
+ super();
2127
+ this._hooks = /* @__PURE__ */ new Map();
2128
+ if ((options == null ? void 0 : options.throwHookErrors) !== void 0) {
2129
+ this._throwHookErrors = options.throwHookErrors;
2130
+ }
2131
+ }
2132
+ /**
2133
+ * Gets all hooks
2134
+ * @returns {Map<string, Hook[]>}
2135
+ */
2136
+ get hooks() {
2137
+ return this._hooks;
2138
+ }
2139
+ /**
2140
+ * Gets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
2141
+ * @returns {boolean}
2142
+ */
2143
+ get throwHookErrors() {
2144
+ return this._throwHookErrors;
2145
+ }
2146
+ /**
2147
+ * Sets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
2148
+ * @param {boolean} value
2149
+ */
2150
+ set throwHookErrors(value) {
2151
+ this._throwHookErrors = value;
2152
+ }
2153
+ /**
2154
+ * Adds a handler function for a specific event
2155
+ * @param {string} event
2156
+ * @param {Hook} handler - this can be async or sync
2157
+ * @returns {void}
2158
+ */
2159
+ onHook(event, handler) {
2160
+ const eventHandlers = this._hooks.get(event);
2161
+ if (eventHandlers) {
2162
+ eventHandlers.push(handler);
2163
+ } else {
2164
+ this._hooks.set(event, [handler]);
2165
+ }
2166
+ }
2167
+ /**
2168
+ * Adds a handler function for a specific event that runs before all other handlers
2169
+ * @param {string} event
2170
+ * @param {Hook} handler - this can be async or sync
2171
+ * @returns {void}
2172
+ */
2173
+ prependHook(event, handler) {
2174
+ const eventHandlers = this._hooks.get(event);
2175
+ if (eventHandlers) {
2176
+ eventHandlers.unshift(handler);
2177
+ } else {
2178
+ this._hooks.set(event, [handler]);
2179
+ }
2180
+ }
2181
+ /**
2182
+ * Adds a handler that only executes once for a specific event before all other handlers
2183
+ * @param event
2184
+ * @param handler
2185
+ */
2186
+ prependOnceHook(event, handler) {
2187
+ const hook = async (...arguments_) => {
2188
+ this.removeHook(event, hook);
2189
+ return handler(...arguments_);
2190
+ };
2191
+ this.prependHook(event, hook);
2192
+ }
2193
+ /**
2194
+ * Adds a handler that only executes once for a specific event
2195
+ * @param event
2196
+ * @param handler
2197
+ */
2198
+ onceHook(event, handler) {
2199
+ const hook = async (...arguments_) => {
2200
+ this.removeHook(event, hook);
2201
+ return handler(...arguments_);
2202
+ };
2203
+ this.onHook(event, hook);
2204
+ }
2205
+ /**
2206
+ * Removes a handler function for a specific event
2207
+ * @param {string} event
2208
+ * @param {Hook} handler
2209
+ * @returns {void}
2210
+ */
2211
+ removeHook(event, handler) {
2212
+ const eventHandlers = this._hooks.get(event);
2213
+ if (eventHandlers) {
2214
+ const index = eventHandlers.indexOf(handler);
2215
+ if (index !== -1) {
2216
+ eventHandlers.splice(index, 1);
2217
+ }
2218
+ }
2219
+ }
2220
+ /**
2221
+ * Calls all handlers for a specific event
2222
+ * @param {string} event
2223
+ * @param {T[]} arguments_
2224
+ * @returns {Promise<void>}
2225
+ */
2226
+ async hook(event, ...arguments_) {
2227
+ const eventHandlers = this._hooks.get(event);
2228
+ if (eventHandlers) {
2229
+ for (const handler of eventHandlers) {
2230
+ try {
2231
+ await handler(...arguments_);
2232
+ } catch (error) {
2233
+ const message = `${event}: ${error.message}`;
2234
+ this.emit("error", new Error(message));
2235
+ if (this._throwHookErrors) {
2236
+ throw new Error(message);
2237
+ }
2238
+ }
2239
+ }
2240
+ }
2241
+ }
2242
+ /**
2243
+ * Gets all hooks for a specific event
2244
+ * @param {string} event
2245
+ * @returns {Hook[]}
2246
+ */
2247
+ getHooks(event) {
2248
+ return this._hooks.get(event);
2249
+ }
2250
+ /**
2251
+ * Removes all hooks
2252
+ * @returns {void}
2253
+ */
2254
+ clearHooks() {
2255
+ this._hooks.clear();
2256
+ }
2257
+ };
2258
+
2259
+ // node_modules/cacheable/dist/index.js
2260
+ import * as crypto from "crypto";
2261
+ var structuredClone = globalThis.structuredClone ?? ((value) => JSON.parse(JSON.stringify(value)));
2262
+ var shorthandToMilliseconds = (shorthand) => {
2263
+ let milliseconds;
2264
+ if (shorthand === void 0) {
2265
+ return void 0;
2266
+ }
2267
+ if (typeof shorthand === "number") {
2268
+ milliseconds = shorthand;
2269
+ } else if (typeof shorthand === "string") {
2270
+ shorthand = shorthand.trim();
2271
+ if (Number.isNaN(Number(shorthand))) {
2272
+ const match = /^([\d.]+)\s*(ms|s|m|h|hr|d)$/i.exec(shorthand);
2273
+ if (!match) {
2274
+ throw new Error(
2275
+ `Unsupported time format: "${shorthand}". Use 'ms', 's', 'm', 'h', 'hr', or 'd'.`
2276
+ );
2277
+ }
2278
+ const [, value, unit] = match;
2279
+ const numericValue = Number.parseFloat(value);
2280
+ const unitLower = unit.toLowerCase();
2281
+ switch (unitLower) {
2282
+ case "ms": {
2283
+ milliseconds = numericValue;
2284
+ break;
2285
+ }
2286
+ case "s": {
2287
+ milliseconds = numericValue * 1e3;
2288
+ break;
2289
+ }
2290
+ case "m": {
2291
+ milliseconds = numericValue * 1e3 * 60;
2292
+ break;
2293
+ }
2294
+ case "h": {
2295
+ milliseconds = numericValue * 1e3 * 60 * 60;
2296
+ break;
2297
+ }
2298
+ case "hr": {
2299
+ milliseconds = numericValue * 1e3 * 60 * 60;
2300
+ break;
2301
+ }
2302
+ case "d": {
2303
+ milliseconds = numericValue * 1e3 * 60 * 60 * 24;
2304
+ break;
2305
+ }
2306
+ /* c8 ignore next 3 */
2307
+ default: {
2308
+ milliseconds = Number(shorthand);
2309
+ }
2310
+ }
2311
+ } else {
2312
+ milliseconds = Number(shorthand);
2313
+ }
2314
+ } else {
2315
+ throw new TypeError("Time must be a string or a number.");
2316
+ }
2317
+ return milliseconds;
2318
+ };
2319
+ var shorthandToTime = (shorthand, fromDate) => {
2320
+ fromDate || (fromDate = /* @__PURE__ */ new Date());
2321
+ const milliseconds = shorthandToMilliseconds(shorthand);
2322
+ if (milliseconds === void 0) {
2323
+ return fromDate.getTime();
2324
+ }
2325
+ return fromDate.getTime() + milliseconds;
2326
+ };
2327
+ function hash(object2, algorithm = "sha256") {
2328
+ const objectString = JSON.stringify(object2);
2329
+ if (!crypto.getHashes().includes(algorithm)) {
2330
+ throw new Error(`Unsupported hash algorithm: '${algorithm}'`);
2331
+ }
2332
+ const hasher = crypto.createHash(algorithm);
2333
+ hasher.update(objectString);
2334
+ return hasher.digest("hex");
2335
+ }
2336
+ function wrapSync(function_, options) {
2337
+ const { ttl, keyPrefix, cache } = options;
2338
+ return function(...arguments_) {
2339
+ const cacheKey = createWrapKey(function_, arguments_, keyPrefix);
2340
+ let value = cache.get(cacheKey);
2341
+ if (value === void 0) {
2342
+ try {
2343
+ value = function_(...arguments_);
2344
+ cache.set(cacheKey, value, ttl);
2345
+ } catch (error) {
2346
+ cache.emit("error", error);
2347
+ if (options.cacheErrors) {
2348
+ cache.set(cacheKey, error, ttl);
2349
+ }
2350
+ }
2351
+ }
2352
+ return value;
2353
+ };
2354
+ }
2355
+ function createWrapKey(function_, arguments_, keyPrefix) {
2356
+ if (!keyPrefix) {
2357
+ return `${function_.name}::${hash(arguments_)}`;
2358
+ }
2359
+ return `${keyPrefix}::${function_.name}::${hash(arguments_)}`;
2360
+ }
2361
+ var ListNode = class {
2362
+ // eslint-disable-next-line @typescript-eslint/parameter-properties
2363
+ value;
2364
+ prev = void 0;
2365
+ next = void 0;
2366
+ constructor(value) {
2367
+ this.value = value;
2368
+ }
2369
+ };
2370
+ var DoublyLinkedList = class {
2371
+ head = void 0;
2372
+ tail = void 0;
2373
+ nodesMap = /* @__PURE__ */ new Map();
2374
+ // Add a new node to the front (most recently used)
2375
+ addToFront(value) {
2376
+ const newNode = new ListNode(value);
2377
+ if (this.head) {
2378
+ newNode.next = this.head;
2379
+ this.head.prev = newNode;
2380
+ this.head = newNode;
2381
+ } else {
2382
+ this.head = this.tail = newNode;
2383
+ }
2384
+ this.nodesMap.set(value, newNode);
2385
+ }
2386
+ // Move an existing node to the front (most recently used)
2387
+ moveToFront(value) {
2388
+ const node = this.nodesMap.get(value);
2389
+ if (!node || this.head === node) {
2390
+ return;
2391
+ }
2392
+ if (node.prev) {
2393
+ node.prev.next = node.next;
2394
+ }
2395
+ if (node.next) {
2396
+ node.next.prev = node.prev;
2397
+ }
2398
+ if (node === this.tail) {
2399
+ this.tail = node.prev;
2400
+ }
2401
+ node.prev = void 0;
2402
+ node.next = this.head;
2403
+ if (this.head) {
2404
+ this.head.prev = node;
2405
+ }
2406
+ this.head = node;
2407
+ this.tail || (this.tail = node);
2408
+ }
2409
+ // Get the oldest node (tail)
2410
+ getOldest() {
2411
+ return this.tail ? this.tail.value : void 0;
2412
+ }
2413
+ // Remove the oldest node (tail)
2414
+ removeOldest() {
2415
+ if (!this.tail) {
2416
+ return void 0;
2417
+ }
2418
+ const oldValue = this.tail.value;
2419
+ if (this.tail.prev) {
2420
+ this.tail = this.tail.prev;
2421
+ this.tail.next = void 0;
2422
+ } else {
2423
+ this.head = this.tail = void 0;
2424
+ }
2425
+ this.nodesMap.delete(oldValue);
2426
+ return oldValue;
2427
+ }
2428
+ get size() {
2429
+ return this.nodesMap.size;
2430
+ }
2431
+ };
2432
+ var CacheableMemory = class extends Hookified {
2433
+ _lru = new DoublyLinkedList();
2434
+ _hashCache = /* @__PURE__ */ new Map();
2435
+ _hash0 = /* @__PURE__ */ new Map();
2436
+ _hash1 = /* @__PURE__ */ new Map();
2437
+ _hash2 = /* @__PURE__ */ new Map();
2438
+ _hash3 = /* @__PURE__ */ new Map();
2439
+ _hash4 = /* @__PURE__ */ new Map();
2440
+ _hash5 = /* @__PURE__ */ new Map();
2441
+ _hash6 = /* @__PURE__ */ new Map();
2442
+ _hash7 = /* @__PURE__ */ new Map();
2443
+ _hash8 = /* @__PURE__ */ new Map();
2444
+ _hash9 = /* @__PURE__ */ new Map();
2445
+ _ttl;
2446
+ // Turned off by default
2447
+ _useClone = true;
2448
+ // Turned on by default
2449
+ _lruSize = 0;
2450
+ // Turned off by default
2451
+ _checkInterval = 0;
2452
+ // Turned off by default
2453
+ _interval = 0;
2454
+ // Turned off by default
2455
+ /**
2456
+ * @constructor
2457
+ * @param {CacheableMemoryOptions} [options] - The options for the CacheableMemory
2458
+ */
2459
+ constructor(options) {
2460
+ super();
2461
+ if (options == null ? void 0 : options.ttl) {
2462
+ this.setTtl(options.ttl);
2463
+ }
2464
+ if ((options == null ? void 0 : options.useClone) !== void 0) {
2465
+ this._useClone = options.useClone;
2466
+ }
2467
+ if (options == null ? void 0 : options.lruSize) {
2468
+ this._lruSize = options.lruSize;
2469
+ }
2470
+ if (options == null ? void 0 : options.checkInterval) {
2471
+ this._checkInterval = options.checkInterval;
2472
+ }
2473
+ this.startIntervalCheck();
2474
+ }
2475
+ /**
2476
+ * Gets the time-to-live
2477
+ * @returns {number|string|undefined} - The time-to-live in miliseconds or a human-readable format. If undefined, it will not have a time-to-live.
2478
+ */
2479
+ get ttl() {
2480
+ return this._ttl;
2481
+ }
2482
+ /**
2483
+ * Sets the time-to-live
2484
+ * @param {number|string|undefined} value - The time-to-live in miliseconds or a human-readable format (example '1s' = 1 second, '1h' = 1 hour). If undefined, it will not have a time-to-live.
2485
+ */
2486
+ set ttl(value) {
2487
+ this.setTtl(value);
2488
+ }
2489
+ /**
2490
+ * Gets whether to use clone
2491
+ * @returns {boolean} - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
2492
+ */
2493
+ get useClone() {
2494
+ return this._useClone;
2495
+ }
2496
+ /**
2497
+ * Sets whether to use clone
2498
+ * @param {boolean} value - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
2499
+ */
2500
+ set useClone(value) {
2501
+ this._useClone = value;
2502
+ }
2503
+ /**
2504
+ * Gets the size of the LRU cache
2505
+ * @returns {number} - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
2506
+ */
2507
+ get lruSize() {
2508
+ return this._lruSize;
2509
+ }
2510
+ /**
2511
+ * Sets the size of the LRU cache
2512
+ * @param {number} value - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
2513
+ */
2514
+ set lruSize(value) {
2515
+ this._lruSize = value;
2516
+ this.lruResize();
2517
+ }
2518
+ /**
2519
+ * Gets the check interval
2520
+ * @returns {number} - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
2521
+ */
2522
+ get checkInterval() {
2523
+ return this._checkInterval;
2524
+ }
2525
+ /**
2526
+ * Sets the check interval
2527
+ * @param {number} value - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
2528
+ */
2529
+ set checkInterval(value) {
2530
+ this._checkInterval = value;
2531
+ }
2532
+ /**
2533
+ * Gets the size of the cache
2534
+ * @returns {number} - The size of the cache
2535
+ */
2536
+ get size() {
2537
+ return this._hash0.size + this._hash1.size + this._hash2.size + this._hash3.size + this._hash4.size + this._hash5.size + this._hash6.size + this._hash7.size + this._hash8.size + this._hash9.size;
2538
+ }
2539
+ /**
2540
+ * Gets the keys
2541
+ * @returns {IterableIterator<string>} - The keys
2542
+ */
2543
+ get keys() {
2544
+ return this.concatStores().keys();
2545
+ }
2546
+ /**
2547
+ * Gets the items
2548
+ * @returns {IterableIterator<CacheableStoreItem>} - The items
2549
+ */
2550
+ get items() {
2551
+ return this.concatStores().values();
2552
+ }
2553
+ /**
2554
+ * Gets the value of the key
2555
+ * @param {string} key - The key to get the value
2556
+ * @returns {T | undefined} - The value of the key
2557
+ */
2558
+ get(key) {
2559
+ const store = this.getStore(key);
2560
+ const item = store.get(key);
2561
+ if (!item) {
2562
+ return void 0;
2563
+ }
2564
+ if (item.expires && item.expires && Date.now() > item.expires) {
2565
+ store.delete(key);
2566
+ return void 0;
2567
+ }
2568
+ this.lruMoveToFront(key);
2569
+ if (!this._useClone) {
2570
+ return item.value;
2571
+ }
2572
+ return this.clone(item.value);
2573
+ }
2574
+ /**
2575
+ * Gets the values of the keys
2576
+ * @param {string[]} keys - The keys to get the values
2577
+ * @returns {T[]} - The values of the keys
2578
+ */
2579
+ getMany(keys2) {
2580
+ const result = new Array();
2581
+ for (const key of keys2) {
2582
+ result.push(this.get(key));
2583
+ }
2584
+ return result;
2585
+ }
2586
+ /**
2587
+ * Gets the raw value of the key
2588
+ * @param {string} key - The key to get the value
2589
+ * @returns {CacheableStoreItem | undefined} - The raw value of the key
2590
+ */
2591
+ getRaw(key) {
2592
+ const store = this.getStore(key);
2593
+ const item = store.get(key);
2594
+ if (!item) {
2595
+ return void 0;
2596
+ }
2597
+ if (item.expires && item.expires && Date.now() > item.expires) {
2598
+ store.delete(key);
2599
+ return void 0;
2600
+ }
2601
+ this.lruMoveToFront(key);
2602
+ return item;
2603
+ }
2604
+ /**
2605
+ * Gets the raw values of the keys
2606
+ * @param {string[]} keys - The keys to get the values
2607
+ * @returns {CacheableStoreItem[]} - The raw values of the keys
2608
+ */
2609
+ getManyRaw(keys2) {
2610
+ const result = new Array();
2611
+ for (const key of keys2) {
2612
+ result.push(this.getRaw(key));
2613
+ }
2614
+ return result;
2615
+ }
2616
+ /**
2617
+ * Sets the value of the key
2618
+ * @param {string} key - The key to set the value
2619
+ * @param {any} value - The value to set
2620
+ * @param {number|string|SetOptions} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable.
2621
+ * If you want to set expire directly you can do that by setting the expire property in the SetOptions.
2622
+ * If you set undefined, it will use the default time-to-live. If both are undefined then it will not have a time-to-live.
2623
+ * @returns {void}
2624
+ */
2625
+ set(key, value, ttl) {
2626
+ const store = this.getStore(key);
2627
+ let expires;
2628
+ if (ttl !== void 0 || this._ttl !== void 0) {
2629
+ if (typeof ttl === "object") {
2630
+ if (ttl.expire) {
2631
+ expires = typeof ttl.expire === "number" ? ttl.expire : ttl.expire.getTime();
2632
+ }
2633
+ if (ttl.ttl) {
2634
+ const finalTtl = shorthandToTime(ttl.ttl);
2635
+ if (finalTtl !== void 0) {
2636
+ expires = finalTtl;
2637
+ }
2638
+ }
2639
+ } else {
2640
+ const finalTtl = shorthandToTime(ttl ?? this._ttl);
2641
+ if (finalTtl !== void 0) {
2642
+ expires = finalTtl;
2643
+ }
2644
+ }
2645
+ }
2646
+ if (this._lruSize > 0) {
2647
+ if (store.has(key)) {
2648
+ this.lruMoveToFront(key);
2649
+ } else {
2650
+ this.lruAddToFront(key);
2651
+ if (this._lru.size > this._lruSize) {
2652
+ const oldestKey = this._lru.getOldest();
2653
+ if (oldestKey) {
2654
+ this._lru.removeOldest();
2655
+ this.delete(oldestKey);
2656
+ }
2657
+ }
2658
+ }
2659
+ }
2660
+ const item = { key, value, expires };
2661
+ store.set(
2662
+ key,
2663
+ item
2664
+ );
2665
+ }
2666
+ /**
2667
+ * Sets the values of the keys
2668
+ * @param {CacheableItem[]} items - The items to set
2669
+ * @returns {void}
2670
+ */
2671
+ setMany(items) {
2672
+ for (const item of items) {
2673
+ this.set(item.key, item.value, item.ttl);
2674
+ }
2675
+ }
2676
+ /**
2677
+ * Checks if the key exists
2678
+ * @param {string} key - The key to check
2679
+ * @returns {boolean} - If true, the key exists. If false, the key does not exist.
2680
+ */
2681
+ has(key) {
2682
+ const item = this.get(key);
2683
+ return Boolean(item);
2684
+ }
2685
+ /**
2686
+ * @function hasMany
2687
+ * @param {string[]} keys - The keys to check
2688
+ * @returns {boolean[]} - If true, the key exists. If false, the key does not exist.
2689
+ */
2690
+ hasMany(keys2) {
2691
+ const result = new Array();
2692
+ for (const key of keys2) {
2693
+ const item = this.get(key);
2694
+ result.push(Boolean(item));
2695
+ }
2696
+ return result;
2697
+ }
2698
+ /**
2699
+ * Take will get the key and delete the entry from cache
2700
+ * @param {string} key - The key to take
2701
+ * @returns {T | undefined} - The value of the key
2702
+ */
2703
+ take(key) {
2704
+ const item = this.get(key);
2705
+ if (!item) {
2706
+ return void 0;
2707
+ }
2708
+ this.delete(key);
2709
+ return item;
2710
+ }
2711
+ /**
2712
+ * TakeMany will get the keys and delete the entries from cache
2713
+ * @param {string[]} keys - The keys to take
2714
+ * @returns {T[]} - The values of the keys
2715
+ */
2716
+ takeMany(keys2) {
2717
+ const result = new Array();
2718
+ for (const key of keys2) {
2719
+ result.push(this.take(key));
2720
+ }
2721
+ return result;
2722
+ }
2723
+ /**
2724
+ * Delete the key
2725
+ * @param {string} key - The key to delete
2726
+ * @returns {void}
2727
+ */
2728
+ delete(key) {
2729
+ const store = this.getStore(key);
2730
+ store.delete(key);
2731
+ }
2732
+ /**
2733
+ * Delete the keys
2734
+ * @param {string[]} keys - The keys to delete
2735
+ * @returns {void}
2736
+ */
2737
+ deleteMany(keys2) {
2738
+ for (const key of keys2) {
2739
+ this.delete(key);
2740
+ }
2741
+ }
2742
+ /**
2743
+ * Clear the cache
2744
+ * @returns {void}
2745
+ */
2746
+ clear() {
2747
+ this._hash0.clear();
2748
+ this._hash1.clear();
2749
+ this._hash2.clear();
2750
+ this._hash3.clear();
2751
+ this._hash4.clear();
2752
+ this._hash5.clear();
2753
+ this._hash6.clear();
2754
+ this._hash7.clear();
2755
+ this._hash8.clear();
2756
+ this._hash9.clear();
2757
+ this._hashCache.clear();
2758
+ this._lru = new DoublyLinkedList();
2759
+ }
2760
+ /**
2761
+ * Get the store based on the key (internal use)
2762
+ * @param {string} key - The key to get the store
2763
+ * @returns {CacheableHashStore} - The store
2764
+ */
2765
+ getStore(key) {
2766
+ const hash2 = this.hashKey(key);
2767
+ return this.getStoreFromHash(hash2);
2768
+ }
2769
+ /**
2770
+ * Get the store based on the hash (internal use)
2771
+ * @param {number} hash
2772
+ * @returns {Map<string, CacheableStoreItem>}
2773
+ */
2774
+ getStoreFromHash(hash2) {
2775
+ switch (hash2) {
2776
+ case 1: {
2777
+ return this._hash1;
2778
+ }
2779
+ case 2: {
2780
+ return this._hash2;
2781
+ }
2782
+ case 3: {
2783
+ return this._hash3;
2784
+ }
2785
+ case 4: {
2786
+ return this._hash4;
2787
+ }
2788
+ case 5: {
2789
+ return this._hash5;
2790
+ }
2791
+ case 6: {
2792
+ return this._hash6;
2793
+ }
2794
+ case 7: {
2795
+ return this._hash7;
2796
+ }
2797
+ case 8: {
2798
+ return this._hash8;
2799
+ }
2800
+ case 9: {
2801
+ return this._hash9;
2802
+ }
2803
+ default: {
2804
+ return this._hash0;
2805
+ }
2806
+ }
2807
+ }
2808
+ /**
2809
+ * Hash the key (internal use)
2810
+ * @param key
2811
+ * @returns {number} from 0 to 9
2812
+ */
2813
+ hashKey(key) {
2814
+ const cacheHashNumber = this._hashCache.get(key);
2815
+ if (cacheHashNumber) {
2816
+ return cacheHashNumber;
2817
+ }
2818
+ let hash2 = 0;
2819
+ const primeMultiplier = 31;
2820
+ for (let i = 0; i < key.length; i++) {
2821
+ hash2 = hash2 * primeMultiplier + key.charCodeAt(i);
2822
+ }
2823
+ const result = Math.abs(hash2) % 10;
2824
+ this._hashCache.set(key, result);
2825
+ return result;
2826
+ }
2827
+ /**
2828
+ * Clone the value. This is for internal use
2829
+ * @param {any} value - The value to clone
2830
+ * @returns {any} - The cloned value
2831
+ */
2832
+ clone(value) {
2833
+ if (this.isPrimitive(value)) {
2834
+ return value;
2835
+ }
2836
+ return structuredClone(value);
2837
+ }
2838
+ /**
2839
+ * Add to the front of the LRU cache. This is for internal use
2840
+ * @param {string} key - The key to add to the front
2841
+ * @returns {void}
2842
+ */
2843
+ lruAddToFront(key) {
2844
+ if (this._lruSize === 0) {
2845
+ return;
2846
+ }
2847
+ this._lru.addToFront(key);
2848
+ }
2849
+ /**
2850
+ * Move to the front of the LRU cache. This is for internal use
2851
+ * @param {string} key - The key to move to the front
2852
+ * @returns {void}
2853
+ */
2854
+ lruMoveToFront(key) {
2855
+ if (this._lruSize === 0) {
2856
+ return;
2857
+ }
2858
+ this._lru.moveToFront(key);
2859
+ }
2860
+ /**
2861
+ * Resize the LRU cache. This is for internal use
2862
+ * @returns {void}
2863
+ */
2864
+ lruResize() {
2865
+ if (this._lruSize === 0) {
2866
+ return;
2867
+ }
2868
+ while (this._lru.size > this._lruSize) {
2869
+ const oldestKey = this._lru.getOldest();
2870
+ if (oldestKey) {
2871
+ this._lru.removeOldest();
2872
+ this.delete(oldestKey);
2873
+ }
2874
+ }
2875
+ }
2876
+ /**
2877
+ * Check for expiration. This is for internal use
2878
+ * @returns {void}
2879
+ */
2880
+ checkExpiration() {
2881
+ const stores = this.concatStores();
2882
+ for (const item of stores.values()) {
2883
+ if (item.expires && Date.now() > item.expires) {
2884
+ this.delete(item.key);
2885
+ }
2886
+ }
2887
+ }
2888
+ /**
2889
+ * Start the interval check. This is for internal use
2890
+ * @returns {void}
2891
+ */
2892
+ startIntervalCheck() {
2893
+ if (this._checkInterval > 0) {
2894
+ if (this._interval) {
2895
+ clearInterval(this._interval);
2896
+ }
2897
+ this._interval = setInterval(() => {
2898
+ this.checkExpiration();
2899
+ }, this._checkInterval).unref();
2900
+ }
2901
+ }
2902
+ /**
2903
+ * Stop the interval check. This is for internal use
2904
+ * @returns {void}
2905
+ */
2906
+ stopIntervalCheck() {
2907
+ if (this._interval) {
2908
+ clearInterval(this._interval);
2909
+ }
2910
+ this._interval = 0;
2911
+ this._checkInterval = 0;
2912
+ }
2913
+ /**
2914
+ * Hash the object. This is for internal use
2915
+ * @param {any} object - The object to hash
2916
+ * @param {string} [algorithm='sha256'] - The algorithm to hash
2917
+ * @returns {string} - The hashed string
2918
+ */
2919
+ hash(object2, algorithm = "sha256") {
2920
+ return hash(object2, algorithm);
2921
+ }
2922
+ /**
2923
+ * Wrap the function for caching
2924
+ * @param {Function} function_ - The function to wrap
2925
+ * @param {Object} [options] - The options to wrap
2926
+ * @returns {Function} - The wrapped function
2927
+ */
2928
+ wrap(function_, options) {
2929
+ const wrapOptions = {
2930
+ ttl: (options == null ? void 0 : options.ttl) ?? this._ttl,
2931
+ keyPrefix: options == null ? void 0 : options.keyPrefix,
2932
+ cache: this
2933
+ };
2934
+ return wrapSync(function_, wrapOptions);
2935
+ }
2936
+ isPrimitive(value) {
2937
+ const result = false;
2938
+ if (value === null || value === void 0) {
2939
+ return true;
2940
+ }
2941
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
2942
+ return true;
2943
+ }
2944
+ return result;
2945
+ }
2946
+ concatStores() {
2947
+ return new Map([...this._hash0, ...this._hash1, ...this._hash2, ...this._hash3, ...this._hash4, ...this._hash5, ...this._hash6, ...this._hash7, ...this._hash8, ...this._hash9]);
2948
+ }
2949
+ setTtl(ttl) {
2950
+ if (typeof ttl === "string" || ttl === void 0) {
2951
+ this._ttl = ttl;
2952
+ } else if (ttl > 0) {
2953
+ this._ttl = ttl;
2954
+ } else {
2955
+ this._ttl = void 0;
2956
+ }
2957
+ }
2958
+ };
2959
+
2960
+ // node_modules/flatted/esm/index.js
2961
+ var { parse: $parse, stringify: $stringify } = JSON;
2962
+ var { keys } = Object;
2963
+ var Primitive = String;
2964
+ var primitive = "string";
2965
+ var ignore = {};
2966
+ var object = "object";
2967
+ var noop = (_2, value) => value;
2968
+ var primitives = (value) => value instanceof Primitive ? Primitive(value) : value;
2969
+ var Primitives = (_2, value) => typeof value === primitive ? new Primitive(value) : value;
2970
+ var revive = (input, parsed, output, $) => {
2971
+ const lazy = [];
2972
+ for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
2973
+ const k = ke[y];
2974
+ const value = output[k];
2975
+ if (value instanceof Primitive) {
2976
+ const tmp = input[value];
2977
+ if (typeof tmp === object && !parsed.has(tmp)) {
2978
+ parsed.add(tmp);
2979
+ output[k] = ignore;
2980
+ lazy.push({ k, a: [input, parsed, tmp, $] });
2981
+ } else
2982
+ output[k] = $.call(output, k, tmp);
2983
+ } else if (output[k] !== ignore)
2984
+ output[k] = $.call(output, k, value);
2985
+ }
2986
+ for (let { length } = lazy, i = 0; i < length; i++) {
2987
+ const { k, a } = lazy[i];
2988
+ output[k] = $.call(output, k, revive.apply(null, a));
2989
+ }
2990
+ return output;
2991
+ };
2992
+ var set = (known, input, value) => {
2993
+ const index = Primitive(input.push(value) - 1);
2994
+ known.set(value, index);
2995
+ return index;
2996
+ };
2997
+ var parse = (text, reviver) => {
2998
+ const input = $parse(text, Primitives).map(primitives);
2999
+ const value = input[0];
3000
+ const $ = reviver || noop;
3001
+ const tmp = typeof value === object && value ? revive(input, /* @__PURE__ */ new Set(), value, $) : value;
3002
+ return $.call({ "": tmp }, "", tmp);
3003
+ };
3004
+ var stringify2 = (value, replacer, space) => {
3005
+ const $ = replacer && typeof replacer === object ? (k, v) => k === "" || -1 < replacer.indexOf(k) ? v : void 0 : replacer || noop;
3006
+ const known = /* @__PURE__ */ new Map();
3007
+ const input = [];
3008
+ const output = [];
3009
+ let i = +set(known, input, $.call({ "": value }, "", value));
3010
+ let firstRun = !i;
3011
+ while (i < input.length) {
3012
+ firstRun = true;
3013
+ output[i] = $stringify(input[i++], replace, space);
3014
+ }
3015
+ return "[" + output.join(",") + "]";
3016
+ function replace(key, value2) {
3017
+ if (firstRun) {
3018
+ firstRun = !firstRun;
3019
+ return value2;
3020
+ }
3021
+ const after = $.call(this, key, value2);
3022
+ switch (typeof after) {
3023
+ case object:
3024
+ if (after === null) return after;
3025
+ case primitive:
3026
+ return known.get(after) || set(known, input, after);
3027
+ }
3028
+ return after;
3029
+ }
3030
+ };
3031
+
3032
+ // node_modules/file-entry-cache/node_modules/flat-cache/dist/index.js
3033
+ var FlatCache = class extends Hookified {
3034
+ _cache = new CacheableMemory();
3035
+ _cacheDir = ".cache";
3036
+ _cacheId = "cache1";
3037
+ _persistInterval = 0;
3038
+ _persistTimer;
3039
+ _changesSinceLastSave = false;
3040
+ _parse = parse;
3041
+ _stringify = stringify2;
3042
+ constructor(options) {
3043
+ super();
3044
+ if (options) {
3045
+ this._cache = new CacheableMemory({
3046
+ ttl: options.ttl,
3047
+ useClone: options.useClone,
3048
+ lruSize: options.lruSize,
3049
+ checkInterval: options.expirationInterval
3050
+ });
3051
+ }
3052
+ if (options == null ? void 0 : options.cacheDir) {
3053
+ this._cacheDir = options.cacheDir;
3054
+ }
3055
+ if (options == null ? void 0 : options.cacheId) {
3056
+ this._cacheId = options.cacheId;
3057
+ }
3058
+ if (options == null ? void 0 : options.persistInterval) {
3059
+ this._persistInterval = options.persistInterval;
3060
+ this.startAutoPersist();
3061
+ }
3062
+ if (options == null ? void 0 : options.deserialize) {
3063
+ this._parse = options.deserialize;
3064
+ }
3065
+ if (options == null ? void 0 : options.serialize) {
3066
+ this._stringify = options.serialize;
3067
+ }
3068
+ }
3069
+ /**
3070
+ * The cache object
3071
+ * @property cache
3072
+ * @type {CacheableMemory}
3073
+ */
3074
+ get cache() {
3075
+ return this._cache;
3076
+ }
3077
+ /**
3078
+ * The cache directory
3079
+ * @property cacheDir
3080
+ * @type {String}
3081
+ * @default '.cache'
3082
+ */
3083
+ get cacheDir() {
3084
+ return this._cacheDir;
3085
+ }
3086
+ /**
3087
+ * Set the cache directory
3088
+ * @property cacheDir
3089
+ * @type {String}
3090
+ * @default '.cache'
3091
+ */
3092
+ set cacheDir(value) {
3093
+ this._cacheDir = value;
3094
+ }
3095
+ /**
3096
+ * The cache id
3097
+ * @property cacheId
3098
+ * @type {String}
3099
+ * @default 'cache1'
3100
+ */
3101
+ get cacheId() {
3102
+ return this._cacheId;
3103
+ }
3104
+ /**
3105
+ * Set the cache id
3106
+ * @property cacheId
3107
+ * @type {String}
3108
+ * @default 'cache1'
3109
+ */
3110
+ set cacheId(value) {
3111
+ this._cacheId = value;
3112
+ }
3113
+ /**
3114
+ * The flag to indicate if there are changes since the last save
3115
+ * @property changesSinceLastSave
3116
+ * @type {Boolean}
3117
+ * @default false
3118
+ */
3119
+ get changesSinceLastSave() {
3120
+ return this._changesSinceLastSave;
3121
+ }
3122
+ /**
3123
+ * The interval to persist the cache to disk. 0 means no timed persistence
3124
+ * @property persistInterval
3125
+ * @type {Number}
3126
+ * @default 0
3127
+ */
3128
+ get persistInterval() {
3129
+ return this._persistInterval;
3130
+ }
3131
+ /**
3132
+ * Set the interval to persist the cache to disk. 0 means no timed persistence
3133
+ * @property persistInterval
3134
+ * @type {Number}
3135
+ * @default 0
3136
+ */
3137
+ set persistInterval(value) {
3138
+ this._persistInterval = value;
3139
+ }
3140
+ /**
3141
+ * Load a cache identified by the given Id. If the element does not exists, then initialize an empty
3142
+ * cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
3143
+ * then the cache module directory `.cacheDir` will be used instead
3144
+ *
3145
+ * @method load
3146
+ * @param cacheId {String} the id of the cache, would also be used as the name of the file cache
3147
+ * @param cacheDir {String} directory for the cache entry
3148
+ */
3149
+ // eslint-disable-next-line unicorn/prevent-abbreviations
3150
+ load(cacheId, cacheDir) {
3151
+ try {
3152
+ const filePath = path9.resolve(`${cacheDir ?? this._cacheDir}/${cacheId ?? this._cacheId}`);
3153
+ this.loadFile(filePath);
3154
+ this.emit(
3155
+ "load"
3156
+ /* LOAD */
3157
+ );
3158
+ } catch (error) {
3159
+ this.emit("error", error);
3160
+ }
3161
+ }
3162
+ /**
3163
+ * Load the cache from the provided file
3164
+ * @method loadFile
3165
+ * @param {String} pathToFile the path to the file containing the info for the cache
3166
+ */
3167
+ loadFile(pathToFile) {
3168
+ if (fs5.existsSync(pathToFile)) {
3169
+ const data = fs5.readFileSync(pathToFile, "utf8");
3170
+ const items = this._parse(data);
3171
+ for (const key of Object.keys(items)) {
3172
+ this._cache.set(items[key].key, items[key].value, { expire: items[key].expires });
3173
+ }
3174
+ this._changesSinceLastSave = true;
3175
+ }
3176
+ }
3177
+ /**
3178
+ * Returns the entire persisted object
3179
+ * @method all
3180
+ * @returns {*}
3181
+ */
3182
+ all() {
3183
+ const result = {};
3184
+ const items = Array.from(this._cache.items);
3185
+ for (const item of items) {
3186
+ result[item.key] = item.value;
3187
+ }
3188
+ return result;
3189
+ }
3190
+ /**
3191
+ * Returns an array with all the items in the cache { key, value, ttl }
3192
+ * @method items
3193
+ * @returns {Array}
3194
+ */
3195
+ get items() {
3196
+ return Array.from(this._cache.items);
3197
+ }
3198
+ /**
3199
+ * Returns the path to the file where the cache is persisted
3200
+ * @method cacheFilePath
3201
+ * @returns {String}
3202
+ */
3203
+ get cacheFilePath() {
3204
+ return path9.resolve(`${this._cacheDir}/${this._cacheId}`);
3205
+ }
3206
+ /**
3207
+ * Returns the path to the cache directory
3208
+ * @method cacheDirPath
3209
+ * @returns {String}
3210
+ */
3211
+ get cacheDirPath() {
3212
+ return path9.resolve(this._cacheDir);
3213
+ }
3214
+ /**
3215
+ * Returns an array with all the keys in the cache
3216
+ * @method keys
3217
+ * @returns {Array}
3218
+ */
3219
+ keys() {
3220
+ return Array.from(this._cache.keys);
3221
+ }
3222
+ /**
3223
+ * (Legacy) set key method. This method will be deprecated in the future
3224
+ * @method setKey
3225
+ * @param key {string} the key to set
3226
+ * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
3227
+ */
3228
+ setKey(key, value, ttl) {
3229
+ this.set(key, value, ttl);
3230
+ }
3231
+ /**
3232
+ * Sets a key to a given value
3233
+ * @method set
3234
+ * @param key {string} the key to set
3235
+ * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
3236
+ * @param [ttl] {number} the time to live in milliseconds
3237
+ */
3238
+ set(key, value, ttl) {
3239
+ this._cache.set(key, value, ttl);
3240
+ this._changesSinceLastSave = true;
3241
+ }
3242
+ /**
3243
+ * (Legacy) Remove a given key from the cache. This method will be deprecated in the future
3244
+ * @method removeKey
3245
+ * @param key {String} the key to remove from the object
3246
+ */
3247
+ removeKey(key) {
3248
+ this.delete(key);
3249
+ }
3250
+ /**
3251
+ * Remove a given key from the cache
3252
+ * @method delete
3253
+ * @param key {String} the key to remove from the object
3254
+ */
3255
+ delete(key) {
3256
+ this._cache.delete(key);
3257
+ this._changesSinceLastSave = true;
3258
+ this.emit("delete", key);
3259
+ }
3260
+ /**
3261
+ * (Legacy) Return the value of the provided key. This method will be deprecated in the future
3262
+ * @method getKey<T>
3263
+ * @param key {String} the name of the key to retrieve
3264
+ * @returns {*} at T the value from the key
3265
+ */
3266
+ getKey(key) {
3267
+ return this.get(key);
3268
+ }
3269
+ /**
3270
+ * Return the value of the provided key
3271
+ * @method get<T>
3272
+ * @param key {String} the name of the key to retrieve
3273
+ * @returns {*} at T the value from the key
3274
+ */
3275
+ get(key) {
3276
+ return this._cache.get(key);
3277
+ }
3278
+ /**
3279
+ * Clear the cache and save the state to disk
3280
+ * @method clear
3281
+ */
3282
+ clear() {
3283
+ try {
3284
+ this._cache.clear();
3285
+ this._changesSinceLastSave = true;
3286
+ this.save();
3287
+ this.emit(
3288
+ "clear"
3289
+ /* CLEAR */
3290
+ );
3291
+ } catch (error) {
3292
+ this.emit("error", error);
3293
+ }
3294
+ }
3295
+ /**
3296
+ * Save the state of the cache identified by the docId to disk
3297
+ * as a JSON structure
3298
+ * @method save
3299
+ */
3300
+ save(force = false) {
3301
+ try {
3302
+ if (this._changesSinceLastSave || force) {
3303
+ const filePath = this.cacheFilePath;
3304
+ const items = Array.from(this._cache.items);
3305
+ const data = this._stringify(items);
3306
+ if (!fs5.existsSync(this._cacheDir)) {
3307
+ fs5.mkdirSync(this._cacheDir, { recursive: true });
3308
+ }
3309
+ fs5.writeFileSync(filePath, data);
3310
+ this._changesSinceLastSave = false;
3311
+ this.emit(
3312
+ "save"
3313
+ /* SAVE */
3314
+ );
3315
+ }
3316
+ } catch (error) {
3317
+ this.emit("error", error);
3318
+ }
3319
+ }
3320
+ /**
3321
+ * Remove the file where the cache is persisted
3322
+ * @method removeCacheFile
3323
+ * @return {Boolean} true or false if the file was successfully deleted
3324
+ */
3325
+ removeCacheFile() {
3326
+ try {
3327
+ if (fs5.existsSync(this.cacheFilePath)) {
3328
+ fs5.rmSync(this.cacheFilePath);
3329
+ return true;
3330
+ }
3331
+ } catch (error) {
3332
+ this.emit("error", error);
3333
+ }
3334
+ return false;
3335
+ }
3336
+ /**
3337
+ * Destroy the cache. This will remove the directory, file, and memory cache
3338
+ * @method destroy
3339
+ * @param [includeCacheDir=false] {Boolean} if true, the cache directory will be removed
3340
+ * @return {undefined}
3341
+ */
3342
+ destroy(includeCacheDirectory = false) {
3343
+ try {
3344
+ this._cache.clear();
3345
+ this.stopAutoPersist();
3346
+ if (includeCacheDirectory) {
3347
+ fs5.rmSync(this.cacheDirPath, { recursive: true, force: true });
3348
+ } else {
3349
+ fs5.rmSync(this.cacheFilePath, { recursive: true, force: true });
3350
+ }
3351
+ this._changesSinceLastSave = false;
3352
+ this.emit(
3353
+ "destroy"
3354
+ /* DESTROY */
3355
+ );
3356
+ } catch (error) {
3357
+ this.emit("error", error);
3358
+ }
3359
+ }
3360
+ /**
3361
+ * Start the auto persist interval
3362
+ * @method startAutoPersist
3363
+ */
3364
+ startAutoPersist() {
3365
+ if (this._persistInterval > 0) {
3366
+ if (this._persistTimer) {
3367
+ clearInterval(this._persistTimer);
3368
+ this._persistTimer = void 0;
3369
+ }
3370
+ this._persistTimer = setInterval(() => {
3371
+ this.save();
3372
+ }, this._persistInterval);
3373
+ }
3374
+ }
3375
+ /**
3376
+ * Stop the auto persist interval
3377
+ * @method stopAutoPersist
3378
+ */
3379
+ stopAutoPersist() {
3380
+ if (this._persistTimer) {
3381
+ clearInterval(this._persistTimer);
3382
+ this._persistTimer = void 0;
3383
+ }
3384
+ }
3385
+ };
3386
+ function createFromFile(filePath, options) {
3387
+ const cache = new FlatCache(options);
3388
+ cache.loadFile(filePath);
3389
+ return cache;
3390
+ }
3391
+
3392
+ // node_modules/file-entry-cache/dist/index.js
3393
+ function createFromFile2(filePath, useCheckSum, currentWorkingDirectory) {
3394
+ const fname = path10.basename(filePath);
3395
+ const directory = path10.dirname(filePath);
3396
+ return create(fname, directory, useCheckSum, currentWorkingDirectory);
3397
+ }
3398
+ function create(cacheId, cacheDirectory, useCheckSum, currentWorkingDirectory) {
3399
+ const options = {
3400
+ currentWorkingDirectory,
3401
+ useCheckSum,
3402
+ cache: {
3403
+ cacheId,
3404
+ cacheDir: cacheDirectory
3405
+ }
3406
+ };
3407
+ const fileEntryCache = new FileEntryCache(options);
3408
+ if (cacheDirectory) {
3409
+ const cachePath = `${cacheDirectory}/${cacheId}`;
3410
+ if (fs6.existsSync(cachePath)) {
3411
+ fileEntryCache.cache = createFromFile(cachePath, options.cache);
3412
+ }
3413
+ }
3414
+ return fileEntryCache;
3415
+ }
3416
+ var FileEntryDefault = class {
3417
+ static create = create;
3418
+ static createFromFile = createFromFile2;
3419
+ };
3420
+ var FileEntryCache = class {
3421
+ _cache = new FlatCache({ useClone: false });
3422
+ _useCheckSum = false;
3423
+ _currentWorkingDirectory;
3424
+ _hashAlgorithm = "md5";
3425
+ constructor(options) {
3426
+ if (options == null ? void 0 : options.cache) {
3427
+ this._cache = new FlatCache(options.cache);
3428
+ }
3429
+ if (options == null ? void 0 : options.useCheckSum) {
3430
+ this._useCheckSum = options.useCheckSum;
3431
+ }
3432
+ if (options == null ? void 0 : options.currentWorkingDirectory) {
3433
+ this._currentWorkingDirectory = options.currentWorkingDirectory;
3434
+ }
3435
+ if (options == null ? void 0 : options.hashAlgorithm) {
3436
+ this._hashAlgorithm = options.hashAlgorithm;
3437
+ }
3438
+ }
3439
+ get cache() {
3440
+ return this._cache;
3441
+ }
3442
+ set cache(cache) {
3443
+ this._cache = cache;
3444
+ }
3445
+ get useCheckSum() {
3446
+ return this._useCheckSum;
3447
+ }
3448
+ set useCheckSum(value) {
3449
+ this._useCheckSum = value;
3450
+ }
3451
+ get hashAlgorithm() {
3452
+ return this._hashAlgorithm;
3453
+ }
3454
+ set hashAlgorithm(value) {
3455
+ this._hashAlgorithm = value;
3456
+ }
3457
+ get currentWorkingDirectory() {
3458
+ return this._currentWorkingDirectory;
3459
+ }
3460
+ set currentWorkingDirectory(value) {
3461
+ this._currentWorkingDirectory = value;
3462
+ }
3463
+ /**
3464
+ * Given a buffer, calculate md5 hash of its content.
3465
+ * @method getHash
3466
+ * @param {Buffer} buffer buffer to calculate hash on
3467
+ * @return {String} content hash digest
3468
+ */
3469
+ // eslint-disable-next-line @typescript-eslint/ban-types
3470
+ getHash(buffer) {
3471
+ return crypto2.createHash(this._hashAlgorithm).update(buffer).digest("hex");
3472
+ }
3473
+ /**
3474
+ * Create the key for the file path used for caching.
3475
+ * @method createFileKey
3476
+ * @param {String} filePath
3477
+ * @return {String}
3478
+ */
3479
+ createFileKey(filePath, options) {
3480
+ let result = filePath;
3481
+ const currentWorkingDirectory = (options == null ? void 0 : options.currentWorkingDirectory) ?? this._currentWorkingDirectory;
3482
+ if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
3483
+ const splitPath = filePath.split(currentWorkingDirectory).pop();
3484
+ if (splitPath) {
3485
+ result = splitPath;
3486
+ if (result.startsWith("/")) {
3487
+ result = result.slice(1);
3488
+ }
3489
+ }
3490
+ }
3491
+ return result;
3492
+ }
3493
+ /**
3494
+ * Check if the file path is a relative path
3495
+ * @method isRelativePath
3496
+ * @param filePath - The file path to check
3497
+ * @returns {boolean} if the file path is a relative path, false otherwise
3498
+ */
3499
+ isRelativePath(filePath) {
3500
+ return !path10.isAbsolute(filePath);
3501
+ }
3502
+ /**
3503
+ * Delete the cache file from the disk
3504
+ * @method deleteCacheFile
3505
+ * @return {boolean} true if the file was deleted, false otherwise
3506
+ */
3507
+ deleteCacheFile() {
3508
+ return this._cache.removeCacheFile();
3509
+ }
3510
+ /**
3511
+ * Remove the cache from the file and clear the memory cache
3512
+ * @method destroy
3513
+ */
3514
+ destroy() {
3515
+ this._cache.destroy();
3516
+ }
3517
+ /**
3518
+ * Remove and Entry From the Cache
3519
+ * @method removeEntry
3520
+ * @param filePath - The file path to remove from the cache
3521
+ */
3522
+ removeEntry(filePath, options) {
3523
+ if (this.isRelativePath(filePath)) {
3524
+ filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options == null ? void 0 : options.currentWorkingDirectory });
3525
+ this._cache.removeKey(this.createFileKey(filePath));
3526
+ }
3527
+ const key = this.createFileKey(filePath, { currentWorkingDirectory: options == null ? void 0 : options.currentWorkingDirectory });
3528
+ this._cache.removeKey(key);
3529
+ }
3530
+ /**
3531
+ * Reconcile the cache
3532
+ * @method reconcile
3533
+ */
3534
+ reconcile() {
3535
+ const items = this._cache.items;
3536
+ for (const item of items) {
3537
+ const fileDescriptor = this.getFileDescriptor(item.key);
3538
+ if (fileDescriptor.notFound) {
3539
+ this._cache.removeKey(item.key);
3540
+ }
3541
+ }
3542
+ this._cache.save();
3543
+ }
3544
+ /**
3545
+ * Check if the file has changed
3546
+ * @method hasFileChanged
3547
+ * @param filePath - The file path to check
3548
+ * @returns {boolean} if the file has changed, false otherwise
3549
+ */
3550
+ hasFileChanged(filePath) {
3551
+ let result = false;
3552
+ const fileDescriptor = this.getFileDescriptor(filePath);
3553
+ if ((!fileDescriptor.err || !fileDescriptor.notFound) && fileDescriptor.changed) {
3554
+ result = true;
3555
+ }
3556
+ return result;
3557
+ }
3558
+ /**
3559
+ * Get the file descriptor for the file path
3560
+ * @method getFileDescriptor
3561
+ * @param filePath - The file path to get the file descriptor for
3562
+ * @param options - The options for getting the file descriptor
3563
+ * @returns The file descriptor
3564
+ */
3565
+ getFileDescriptor(filePath, options) {
3566
+ var _a, _b, _c;
3567
+ let fstat;
3568
+ const result = {
3569
+ key: this.createFileKey(filePath),
3570
+ changed: false,
3571
+ meta: {}
3572
+ };
3573
+ result.meta = this._cache.getKey(result.key) ?? {};
3574
+ filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options == null ? void 0 : options.currentWorkingDirectory });
3575
+ const useCheckSumValue = (options == null ? void 0 : options.useCheckSum) ?? this._useCheckSum;
3576
+ try {
3577
+ fstat = fs6.statSync(filePath);
3578
+ result.meta = {
3579
+ size: fstat.size
3580
+ };
3581
+ result.meta.mtime = fstat.mtime.getTime();
3582
+ if (useCheckSumValue) {
3583
+ const buffer = fs6.readFileSync(filePath);
3584
+ result.meta.hash = this.getHash(buffer);
3585
+ }
3586
+ } catch (error) {
3587
+ this.removeEntry(filePath);
3588
+ let notFound = false;
3589
+ if (error.message.includes("ENOENT")) {
3590
+ notFound = true;
3591
+ }
3592
+ return {
3593
+ key: result.key,
3594
+ err: error,
3595
+ notFound,
3596
+ meta: {}
3597
+ };
3598
+ }
3599
+ const metaCache = this._cache.getKey(result.key);
3600
+ if (!metaCache) {
3601
+ result.changed = true;
3602
+ this._cache.setKey(result.key, result.meta);
3603
+ return result;
3604
+ }
3605
+ if (result.meta.data === void 0) {
3606
+ result.meta.data = metaCache.data;
3607
+ }
3608
+ if ((metaCache == null ? void 0 : metaCache.mtime) !== ((_a = result.meta) == null ? void 0 : _a.mtime) || (metaCache == null ? void 0 : metaCache.size) !== ((_b = result.meta) == null ? void 0 : _b.size)) {
3609
+ result.changed = true;
3610
+ }
3611
+ if (useCheckSumValue && (metaCache == null ? void 0 : metaCache.hash) !== ((_c = result.meta) == null ? void 0 : _c.hash)) {
3612
+ result.changed = true;
3613
+ }
3614
+ this._cache.setKey(result.key, result.meta);
3615
+ return result;
3616
+ }
3617
+ /**
3618
+ * Get the file descriptors for the files
3619
+ * @method normalizeEntries
3620
+ * @param files?: string[] - The files to get the file descriptors for
3621
+ * @returns The file descriptors
3622
+ */
3623
+ normalizeEntries(files) {
3624
+ const result = new Array();
3625
+ if (files) {
3626
+ for (const file of files) {
3627
+ const fileDescriptor = this.getFileDescriptor(file);
3628
+ result.push(fileDescriptor);
3629
+ }
3630
+ return result;
3631
+ }
3632
+ const keys2 = this.cache.keys();
3633
+ for (const key of keys2) {
3634
+ const fileDescriptor = this.getFileDescriptor(key);
3635
+ if (!fileDescriptor.notFound && !fileDescriptor.err) {
3636
+ result.push(fileDescriptor);
3637
+ }
3638
+ }
3639
+ return result;
3640
+ }
3641
+ /**
3642
+ * Analyze the files
3643
+ * @method analyzeFiles
3644
+ * @param files - The files to analyze
3645
+ * @returns {AnalyzedFiles} The analysis of the files
3646
+ */
3647
+ analyzeFiles(files) {
3648
+ const result = {
3649
+ changedFiles: [],
3650
+ notFoundFiles: [],
3651
+ notChangedFiles: []
3652
+ };
3653
+ const fileDescriptors = this.normalizeEntries(files);
3654
+ for (const fileDescriptor of fileDescriptors) {
3655
+ if (fileDescriptor.notFound) {
3656
+ result.notFoundFiles.push(fileDescriptor.key);
3657
+ } else if (fileDescriptor.changed) {
3658
+ result.changedFiles.push(fileDescriptor.key);
3659
+ } else {
3660
+ result.notChangedFiles.push(fileDescriptor.key);
3661
+ }
3662
+ }
3663
+ return result;
3664
+ }
3665
+ /**
3666
+ * Get the updated files
3667
+ * @method getUpdatedFiles
3668
+ * @param files - The files to get the updated files for
3669
+ * @returns {string[]} The updated files
3670
+ */
3671
+ getUpdatedFiles(files) {
3672
+ const result = new Array();
3673
+ const fileDescriptors = this.normalizeEntries(files);
3674
+ for (const fileDescriptor of fileDescriptors) {
3675
+ if (fileDescriptor.changed) {
3676
+ result.push(fileDescriptor.key);
3677
+ }
3678
+ }
3679
+ return result;
3680
+ }
3681
+ /**
3682
+ * Get the not found files
3683
+ * @method getFileDescriptorsByPath
3684
+ * @param filePath - the files that you want to get from a path
3685
+ * @returns {FileDescriptor[]} The not found files
3686
+ */
3687
+ getFileDescriptorsByPath(filePath) {
3688
+ const result = new Array();
3689
+ const keys2 = this._cache.keys();
3690
+ for (const key of keys2) {
3691
+ const absolutePath = this.getAbsolutePath(filePath);
3692
+ if (absolutePath.startsWith(filePath)) {
3693
+ const fileDescriptor = this.getFileDescriptor(key);
3694
+ result.push(fileDescriptor);
3695
+ }
3696
+ }
3697
+ return result;
3698
+ }
3699
+ /**
3700
+ * Get the Absolute Path. If it is already absolute it will return the path as is.
3701
+ * @method getAbsolutePath
3702
+ * @param filePath - The file path to get the absolute path for
3703
+ * @param options - The options for getting the absolute path. The current working directory is used if not provided.
3704
+ * @returns {string}
3705
+ */
3706
+ getAbsolutePath(filePath, options) {
3707
+ if (this.isRelativePath(filePath)) {
3708
+ const currentWorkingDirectory = (options == null ? void 0 : options.currentWorkingDirectory) ?? this._currentWorkingDirectory ?? process.cwd();
3709
+ filePath = path10.resolve(currentWorkingDirectory, filePath);
3710
+ }
3711
+ return filePath;
3712
+ }
3713
+ /**
3714
+ * Rename the absolute path keys. This is used when a directory is changed or renamed.
3715
+ * @method renameAbsolutePathKeys
3716
+ * @param oldPath - The old path to rename
3717
+ * @param newPath - The new path to rename to
3718
+ */
3719
+ renameAbsolutePathKeys(oldPath, newPath) {
3720
+ const keys2 = this._cache.keys();
3721
+ for (const key of keys2) {
3722
+ if (key.startsWith(oldPath)) {
3723
+ const newKey = key.replace(oldPath, newPath);
3724
+ const meta = this._cache.getKey(key);
3725
+ this._cache.removeKey(key);
3726
+ this._cache.setKey(newKey, meta);
3727
+ }
3728
+ }
3729
+ }
3730
+ };
3731
+
3732
+ // src/cli/format-results-cache.js
2764
3733
  import { version as prettierVersion } from "../index.mjs";
2765
3734
  var optionsHashCache = /* @__PURE__ */ new WeakMap();
2766
3735
  var nodeVersion = process.version;
@@ -2768,11 +3737,11 @@ function getHashOfOptions(options) {
2768
3737
  if (optionsHashCache.has(options)) {
2769
3738
  return optionsHashCache.get(options);
2770
3739
  }
2771
- const hash = createHash(
3740
+ const hash2 = createHash(
2772
3741
  `${prettierVersion}_${nodeVersion}_${(0, import_fast_json_stable_stringify2.default)(options)}`
2773
3742
  );
2774
- optionsHashCache.set(options, hash);
2775
- return hash;
3743
+ optionsHashCache.set(options, hash2);
3744
+ return hash2;
2776
3745
  }
2777
3746
  function getMetadataFromFileDescriptor(fileDescriptor) {
2778
3747
  return fileDescriptor.meta;
@@ -2786,11 +3755,9 @@ var FormatResultsCache = class {
2786
3755
  constructor(cacheFileLocation, cacheStrategy) {
2787
3756
  __privateAdd(this, _fileEntryCache);
2788
3757
  const useChecksum = cacheStrategy === "content";
2789
- __privateSet(this, _fileEntryCache, import_file_entry_cache.default.create(
2790
- /* cacheId */
3758
+ __privateSet(this, _fileEntryCache, FileEntryDefault.createFromFile(
3759
+ /* filePath */
2791
3760
  cacheFileLocation,
2792
- /* directory */
2793
- void 0,
2794
3761
  useChecksum
2795
3762
  ));
2796
3763
  }
@@ -2799,14 +3766,13 @@ var FormatResultsCache = class {
2799
3766
  * @param {any} options
2800
3767
  */
2801
3768
  existsAvailableFormatResultsCache(filePath, options) {
3769
+ var _a;
2802
3770
  const fileDescriptor = __privateGet(this, _fileEntryCache).getFileDescriptor(filePath);
2803
- if (fileDescriptor.notFound) {
3771
+ if (fileDescriptor.notFound || fileDescriptor.changed) {
2804
3772
  return false;
2805
3773
  }
2806
- const hashOfOptions = getHashOfOptions(options);
2807
- const meta = getMetadataFromFileDescriptor(fileDescriptor);
2808
- const changed = fileDescriptor.changed || meta.hashOfOptions !== hashOfOptions;
2809
- return !changed;
3774
+ const hashOfOptions = (_a = getMetadataFromFileDescriptor(fileDescriptor).data) == null ? void 0 : _a.hashOfOptions;
3775
+ return hashOfOptions && hashOfOptions === getHashOfOptions(options);
2810
3776
  }
2811
3777
  /**
2812
3778
  * @param {string} filePath
@@ -2814,9 +3780,9 @@ var FormatResultsCache = class {
2814
3780
  */
2815
3781
  setFormatResultsCache(filePath, options) {
2816
3782
  const fileDescriptor = __privateGet(this, _fileEntryCache).getFileDescriptor(filePath);
2817
- const meta = getMetadataFromFileDescriptor(fileDescriptor);
2818
- if (fileDescriptor && !fileDescriptor.notFound) {
2819
- meta.hashOfOptions = getHashOfOptions(options);
3783
+ if (!fileDescriptor.notFound) {
3784
+ const meta = getMetadataFromFileDescriptor(fileDescriptor);
3785
+ meta.data = { ...meta.data, hashOfOptions: getHashOfOptions(options) };
2820
3786
  }
2821
3787
  }
2822
3788
  /**
@@ -2845,9 +3811,9 @@ function getOptions(argv, detailedOptions) {
2845
3811
  detailedOptions.filter(({ forwardToApi }) => forwardToApi).map(({ forwardToApi, name }) => [forwardToApi, argv[name]])
2846
3812
  );
2847
3813
  }
2848
- function cliifyOptions(object, apiDetailedOptionMap) {
3814
+ function cliifyOptions(object2, apiDetailedOptionMap) {
2849
3815
  return Object.fromEntries(
2850
- Object.entries(object || {}).map(([key, value]) => {
3816
+ Object.entries(object2 || {}).map(([key, value]) => {
2851
3817
  const apiOption = apiDetailedOptionMap[key];
2852
3818
  const cliKey = apiOption ? apiOption.name : key;
2853
3819
  return [(0, import_dashify2.default)(cliKey), value];
@@ -3037,11 +4003,11 @@ async function format3(context, input, opt) {
3037
4003
  "prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp)
3038
4004
  );
3039
4005
  } else {
3040
- const stringify4 = (obj) => JSON.stringify(obj, null, 2);
3041
- const ast = stringify4(
4006
+ const stringify5 = (obj) => JSON.stringify(obj, null, 2);
4007
+ const ast = stringify5(
3042
4008
  (await prettier.__debug.parse(input, opt, { massage: true })).ast
3043
4009
  );
3044
- const past = stringify4(
4010
+ const past = stringify5(
3045
4011
  (await prettier.__debug.parse(pp, opt, { massage: true })).ast
3046
4012
  );
3047
4013
  if (ast !== past) {
@@ -3141,7 +4107,7 @@ async function formatStdin(context) {
3141
4107
  }
3142
4108
  const options = await get_options_for_file_default(
3143
4109
  context,
3144
- filepath ? path9.resolve(filepath) : void 0
4110
+ filepath ? path11.resolve(filepath) : void 0
3145
4111
  );
3146
4112
  if (await listDifferent(context, input, options, "(stdin)")) {
3147
4113
  return;
@@ -3177,7 +4143,7 @@ async function formatFiles(context) {
3177
4143
  } else if (!context.argv.cacheLocation) {
3178
4144
  const stat = await statSafe(cacheFilePath);
3179
4145
  if (stat) {
3180
- await fs5.unlink(cacheFilePath);
4146
+ await fs7.unlink(cacheFilePath);
3181
4147
  }
3182
4148
  }
3183
4149
  for await (const { error, filename, ignoreUnknown } of expandPatterns(
@@ -3196,7 +4162,7 @@ async function formatFiles(context) {
3196
4162
  ...await get_options_for_file_default(context, filename),
3197
4163
  filepath: filename
3198
4164
  };
3199
- const fileNameToDisplay = normalizeToPosix(path9.relative(cwd2, filename));
4165
+ const fileNameToDisplay = normalizeToPosix(path11.relative(cwd2, filename));
3200
4166
  let printedFilename;
3201
4167
  if (isTTY()) {
3202
4168
  printedFilename = context.logger.log(fileNameToDisplay, {
@@ -3206,7 +4172,7 @@ async function formatFiles(context) {
3206
4172
  }
3207
4173
  let input;
3208
4174
  try {
3209
- input = await fs5.readFile(filename, "utf8");
4175
+ input = await fs7.readFile(filename, "utf8");
3210
4176
  } catch (error2) {
3211
4177
  context.logger.log("");
3212
4178
  context.logger.error(