keyv 5.5.0 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -49,7 +49,9 @@ var EventManager = class {
49
49
  const listeners = this._eventListeners.get(event);
50
50
  if (listeners) {
51
51
  if (listeners.length >= this._maxListeners) {
52
- console.warn(`MaxListenersExceededWarning: Possible event memory leak detected. ${listeners.length + 1} ${event} listeners added. Use setMaxListeners() to increase limit.`);
52
+ console.warn(
53
+ `MaxListenersExceededWarning: Possible event memory leak detected. ${listeners.length + 1} ${event} listeners added. Use setMaxListeners() to increase limit.`
54
+ );
53
55
  }
54
56
  listeners.push(listener);
55
57
  }
@@ -77,6 +79,7 @@ var EventManager = class {
77
79
  this.on(event, onceListener);
78
80
  }
79
81
  // Emit an event
82
+ // biome-ignore lint/suspicious/noExplicitAny: type format
80
83
  emit(event, ...arguments_) {
81
84
  const listeners = this._eventListeners.get(event);
82
85
  if (listeners && listeners.length > 0) {
@@ -131,6 +134,7 @@ var HooksManager = class extends event_manager_default {
131
134
  }
132
135
  }
133
136
  // Triggers all handlers for a specific event with provided data
137
+ // biome-ignore lint/suspicious/noExplicitAny: type format
134
138
  trigger(event, data) {
135
139
  const eventHandlers = this._hookHandlers.get(event);
136
140
  if (eventHandlers) {
@@ -138,7 +142,12 @@ var HooksManager = class extends event_manager_default {
138
142
  try {
139
143
  handler(data);
140
144
  } catch (error) {
141
- this.emit("error", new Error(`Error in hook handler for event "${event}": ${error.message}`));
145
+ this.emit(
146
+ "error",
147
+ new Error(
148
+ `Error in hook handler for event "${event}": ${error.message}`
149
+ )
150
+ );
142
151
  }
143
152
  }
144
153
  }
@@ -245,6 +254,7 @@ var Keyv = class extends event_manager_default {
245
254
  /**
246
255
  * Store
247
256
  */
257
+ // biome-ignore lint/suspicious/noExplicitAny: type format
248
258
  _store = /* @__PURE__ */ new Map();
249
259
  _serialize = import_serialize.defaultSerialize;
250
260
  _deserialize = import_serialize.defaultDeserialize;
@@ -293,9 +303,14 @@ var Keyv = class extends event_manager_default {
293
303
  }
294
304
  this._store.namespace = this._namespace;
295
305
  if (typeof this._store[Symbol.iterator] === "function" && this._store instanceof Map) {
296
- this.iterator = this.generateIterator(this._store);
306
+ this.iterator = this.generateIterator(
307
+ this._store
308
+ );
297
309
  } else if ("iterator" in this._store && this._store.opts && this._checkIterableAdapter()) {
298
- this.iterator = this.generateIterator(this._store.iterator.bind(this._store));
310
+ this.iterator = this.generateIterator(
311
+ // biome-ignore lint/style/noNonNullAssertion: need to fix
312
+ this._store.iterator.bind(this._store)
313
+ );
299
314
  }
300
315
  }
301
316
  if (this.opts.stats) {
@@ -314,6 +329,7 @@ var Keyv = class extends event_manager_default {
314
329
  /**
315
330
  * Get the current store
316
331
  */
332
+ // biome-ignore lint/suspicious/noExplicitAny: type format
317
333
  get store() {
318
334
  return this._store;
319
335
  }
@@ -321,6 +337,7 @@ var Keyv = class extends event_manager_default {
321
337
  * Set the current store. This will also set the namespace, event error handler, and generate the iterator. If the store is not valid it will throw an error.
322
338
  * @param {KeyvStoreAdapter | Map<any, any> | any} store the store to set
323
339
  */
340
+ // biome-ignore lint/suspicious/noExplicitAny: type format
324
341
  set store(store) {
325
342
  if (this._isValidStorageAdapter(store)) {
326
343
  this._store = store;
@@ -332,9 +349,11 @@ var Keyv = class extends event_manager_default {
332
349
  this._store.namespace = this._namespace;
333
350
  }
334
351
  if (typeof store[Symbol.iterator] === "function" && store instanceof Map) {
335
- this.iterator = this.generateIterator(store);
352
+ this.iterator = this.generateIterator(
353
+ store
354
+ );
336
355
  } else if ("iterator" in store && store.opts && this._checkIterableAdapter()) {
337
- this.iterator = this.generateIterator(store.iterator.bind(store));
356
+ this.iterator = this.generateIterator(store.iterator?.bind(store));
338
357
  }
339
358
  } else {
340
359
  throw new Error("Invalid storage adapter");
@@ -466,7 +485,9 @@ var Keyv = class extends event_manager_default {
466
485
  return function_.bind(this);
467
486
  }
468
487
  _checkIterableAdapter() {
469
- return iterableAdapters.includes(this._store.opts.dialect) || iterableAdapters.some((element) => this._store.opts.url.includes(element));
488
+ return iterableAdapters.includes(this._store.opts.dialect) || iterableAdapters.some(
489
+ (element) => this._store.opts.url.includes(element)
490
+ );
470
491
  }
471
492
  _getKeyPrefix(key) {
472
493
  if (!this._useKeyPrefix) {
@@ -492,6 +513,7 @@ var Keyv = class extends event_manager_default {
492
513
  }
493
514
  return key.split(":").splice(1).join(":");
494
515
  }
516
+ // biome-ignore lint/suspicious/noExplicitAny: type format
495
517
  _isValidStorageAdapter(store) {
496
518
  return store instanceof Map || typeof store.get === "function" && typeof store.set === "function" && typeof store.delete === "function" && typeof store.clear === "function";
497
519
  }
@@ -526,7 +548,10 @@ var Keyv = class extends event_manager_default {
526
548
  this.stats.miss();
527
549
  return void 0;
528
550
  }
529
- this.hooks.trigger("postGet" /* POST_GET */, { key: keyPrefixed, value: deserializedData });
551
+ this.hooks.trigger("postGet" /* POST_GET */, {
552
+ key: keyPrefixed,
553
+ value: deserializedData
554
+ });
530
555
  this.stats.hit();
531
556
  return options?.raw ? deserializedData : deserializedData.value;
532
557
  }
@@ -549,7 +574,10 @@ var Keyv = class extends event_manager_default {
549
574
  return options?.raw ? deserializedRow : deserializedRow.value;
550
575
  });
551
576
  const deserializedRows = await Promise.allSettled(promises);
552
- const result2 = deserializedRows.map((row) => row.value);
577
+ const result2 = deserializedRows.map(
578
+ // biome-ignore lint/suspicious/noExplicitAny: type format
579
+ (row) => row.value
580
+ );
553
581
  this.hooks.trigger("postGetMany" /* POST_GET_MANY */, result2);
554
582
  if (result2.length > 0) {
555
583
  this.stats.hit();
@@ -600,27 +628,36 @@ var Keyv = class extends event_manager_default {
600
628
  return void 0;
601
629
  }
602
630
  const deserializedData = typeof rawData === "string" || this.opts.compression ? await this.deserializeData(rawData) : rawData;
603
- if (deserializedData !== void 0 && deserializedData.expires !== void 0 && deserializedData.expires !== null && deserializedData.expires < Date.now()) {
631
+ if (deserializedData !== void 0 && deserializedData.expires !== void 0 && deserializedData.expires !== null && // biome-ignore lint/style/noNonNullAssertion: need to fix
632
+ deserializedData.expires < Date.now()) {
604
633
  this.stats.miss();
605
634
  await this.delete(key);
606
635
  return void 0;
607
636
  }
608
637
  this.stats.hit();
609
- this.hooks.trigger("postGetRaw" /* POST_GET_RAW */, { key: keyPrefixed, value: deserializedData });
638
+ this.hooks.trigger("postGetRaw" /* POST_GET_RAW */, {
639
+ key: keyPrefixed,
640
+ value: deserializedData
641
+ });
610
642
  return deserializedData;
611
643
  }
612
644
  /**
613
645
  * Get the raw values of many keys. This is the replacement for setting raw to true in the getMany() method.
614
646
  * @param {string[]} keys the keys to get
615
647
  * @returns {Promise<Array<StoredDataRaw<Value>>>} will return an array of StoredDataRaw<Value> or undefined if the key does not exist or is expired.
616
- */
648
+ */
617
649
  async getManyRaw(keys) {
618
650
  const { store } = this.opts;
619
651
  const keyPrefixed = this._getKeyPrefixArray(keys);
620
652
  if (keys.length === 0) {
621
- const result2 = Array.from({ length: keys.length }).fill(void 0);
653
+ const result2 = Array.from({ length: keys.length }).fill(
654
+ void 0
655
+ );
622
656
  this.stats.misses += keys.length;
623
- this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, { keys: keyPrefixed, values: result2 });
657
+ this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, {
658
+ keys: keyPrefixed,
659
+ values: result2
660
+ });
624
661
  return result2;
625
662
  }
626
663
  let result = [];
@@ -633,7 +670,10 @@ var Keyv = class extends event_manager_default {
633
670
  return void 0;
634
671
  });
635
672
  const deserializedRows = await Promise.allSettled(promises);
636
- result = deserializedRows.map((row) => row.value);
673
+ result = deserializedRows.map(
674
+ // biome-ignore lint/suspicious/noExplicitAny: type format
675
+ (row) => row.value
676
+ );
637
677
  } else {
638
678
  const rawData = await store.getMany(keyPrefixed);
639
679
  for (const row of rawData) {
@@ -656,7 +696,10 @@ var Keyv = class extends event_manager_default {
656
696
  await this.deleteMany(expiredKeys);
657
697
  }
658
698
  this.stats.hitsOrMisses(result);
659
- this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, { keys: keyPrefixed, values: result });
699
+ this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, {
700
+ keys: keyPrefixed,
701
+ values: result
702
+ });
660
703
  return result;
661
704
  }
662
705
  /**
@@ -695,7 +738,11 @@ var Keyv = class extends event_manager_default {
695
738
  throw error;
696
739
  }
697
740
  }
698
- this.hooks.trigger("postSet" /* POST_SET */, { key: keyPrefixed, value: serializedValue, ttl });
741
+ this.hooks.trigger("postSet" /* POST_SET */, {
742
+ key: keyPrefixed,
743
+ value: serializedValue,
744
+ ttl
745
+ });
699
746
  this.stats.set();
700
747
  return result;
701
748
  }
@@ -704,6 +751,7 @@ var Keyv = class extends event_manager_default {
704
751
  * @param {Array<KeyvEntry>} entries the entries to set
705
752
  * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
706
753
  */
754
+ // biome-ignore lint/correctness/noUnusedVariables: type format
707
755
  async setMany(entries) {
708
756
  let results = [];
709
757
  try {
@@ -715,20 +763,22 @@ var Keyv = class extends event_manager_default {
715
763
  const promiseResults = await Promise.all(promises);
716
764
  results = promiseResults;
717
765
  } else {
718
- const serializedEntries = await Promise.all(entries.map(async ({ key, value, ttl }) => {
719
- ttl ??= this._ttl;
720
- if (ttl === 0) {
721
- ttl = void 0;
722
- }
723
- const expires = typeof ttl === "number" ? Date.now() + ttl : void 0;
724
- if (typeof value === "symbol") {
725
- this.emit("error", "symbol cannot be serialized");
726
- throw new Error("symbol cannot be serialized");
727
- }
728
- const formattedValue = { value, expires };
729
- const serializedValue = await this.serializeData(formattedValue);
730
- return { key, value: serializedValue, ttl };
731
- }));
766
+ const serializedEntries = await Promise.all(
767
+ entries.map(async ({ key, value, ttl }) => {
768
+ ttl ??= this._ttl;
769
+ if (ttl === 0) {
770
+ ttl = void 0;
771
+ }
772
+ const expires = typeof ttl === "number" ? Date.now() + ttl : void 0;
773
+ if (typeof value === "symbol") {
774
+ this.emit("error", "symbol cannot be serialized");
775
+ throw new Error("symbol cannot be serialized");
776
+ }
777
+ const formattedValue = { value, expires };
778
+ const serializedValue = await this.serializeData(formattedValue);
779
+ return { key, value: serializedValue, ttl };
780
+ })
781
+ );
732
782
  results = await this._store.setMany(serializedEntries);
733
783
  }
734
784
  } catch (error) {
@@ -765,7 +815,10 @@ var Keyv = class extends event_manager_default {
765
815
  throw error;
766
816
  }
767
817
  }
768
- this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: result });
818
+ this.hooks.trigger("postDelete" /* POST_DELETE */, {
819
+ key: keyPrefixed,
820
+ value: result
821
+ });
769
822
  this.stats.delete();
770
823
  return result;
771
824
  }
@@ -785,7 +838,10 @@ var Keyv = class extends event_manager_default {
785
838
  const promises = keyPrefixed.map(async (key) => store.delete(key));
786
839
  const results = await Promise.all(promises);
787
840
  const returnResult = results.every(Boolean);
788
- this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: returnResult });
841
+ this.hooks.trigger("postDelete" /* POST_DELETE */, {
842
+ key: keyPrefixed,
843
+ value: returnResult
844
+ });
789
845
  return returnResult;
790
846
  } catch (error) {
791
847
  this.emit("error", error);
@@ -869,6 +925,7 @@ var Keyv = class extends event_manager_default {
869
925
  return store.disconnect();
870
926
  }
871
927
  }
928
+ // biome-ignore lint/suspicious/noExplicitAny: type format
872
929
  emit(event, ...arguments_) {
873
930
  if (event === "error" && !this.opts.emitErrors) {
874
931
  return;
@@ -880,7 +937,10 @@ var Keyv = class extends event_manager_default {
880
937
  return data;
881
938
  }
882
939
  if (this._compression?.compress) {
883
- return this._serialize({ value: await this._compression.compress(data.value), expires: data.expires });
940
+ return this._serialize({
941
+ value: await this._compression.compress(data.value),
942
+ expires: data.expires
943
+ });
884
944
  }
885
945
  return this._serialize(data);
886
946
  }
@@ -890,7 +950,10 @@ var Keyv = class extends event_manager_default {
890
950
  }
891
951
  if (this._compression?.decompress && typeof data === "string") {
892
952
  const result = await this._deserialize(data);
893
- return { value: await this._compression.decompress(result?.value), expires: result?.expires };
953
+ return {
954
+ value: await this._compression.decompress(result?.value),
955
+ expires: result?.expires
956
+ };
894
957
  }
895
958
  if (typeof data === "string") {
896
959
  return this._deserialize(data);
package/dist/index.d.cts CHANGED
@@ -110,12 +110,12 @@ type KeyvOptions = {
110
110
  /**
111
111
  * Emit errors
112
112
  * @default true
113
- */
113
+ */
114
114
  emitErrors?: boolean;
115
115
  /**
116
116
  * Namespace for the current instance.
117
117
  * @default 'keyv'
118
- */
118
+ */
119
119
  namespace?: string;
120
120
  /**
121
121
  * A custom serialization function.
@@ -125,7 +125,7 @@ type KeyvOptions = {
125
125
  /**
126
126
  * A custom deserialization function.
127
127
  * @default defaultDeserialize using JSON.parse
128
- */
128
+ */
129
129
  deserialize?: Deserialize;
130
130
  /**
131
131
  * The storage adapter instance to be used by Keyv.
@@ -158,8 +158,8 @@ type KeyvOptions = {
158
158
  */
159
159
  throwOnErrors?: boolean;
160
160
  };
161
- type KeyvOptions_ = Omit<KeyvOptions, 'store'> & {
162
- store: KeyvStoreAdapter | Map<any, any> & KeyvStoreAdapter;
161
+ type KeyvOptions_ = Omit<KeyvOptions, "store"> & {
162
+ store: KeyvStoreAdapter | (Map<any, any> & KeyvStoreAdapter);
163
163
  };
164
164
  type IteratorFunction = (argument: any) => AsyncGenerator<any, void>;
165
165
  declare class Keyv<GenericValue = any> extends EventManager {
@@ -189,7 +189,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
189
189
  * @param {KeyvStoreAdapter | KeyvOptions | Map<any, any>} store to be provided or just the options
190
190
  * @param {Omit<KeyvOptions, 'store'>} [options] if you provide the store you can then provide the Keyv Options
191
191
  */
192
- constructor(store?: KeyvStoreAdapter | KeyvOptions | Map<any, any>, options?: Omit<KeyvOptions, 'store'>);
192
+ constructor(store?: KeyvStoreAdapter | KeyvOptions | Map<any, any>, options?: Omit<KeyvOptions, "store">);
193
193
  /**
194
194
  * Keyv Constructor
195
195
  * @param {KeyvOptions} options to be provided
@@ -319,7 +319,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
319
319
  * Get the raw values of many keys. This is the replacement for setting raw to true in the getMany() method.
320
320
  * @param {string[]} keys the keys to get
321
321
  * @returns {Promise<Array<StoredDataRaw<Value>>>} will return an array of StoredDataRaw<Value> or undefined if the key does not exist or is expired.
322
- */
322
+ */
323
323
  getManyRaw<Value = GenericValue>(keys: string[]): Promise<Array<StoredDataRaw<Value>>>;
324
324
  /**
325
325
  * Set an item to the store
package/dist/index.d.ts CHANGED
@@ -110,12 +110,12 @@ type KeyvOptions = {
110
110
  /**
111
111
  * Emit errors
112
112
  * @default true
113
- */
113
+ */
114
114
  emitErrors?: boolean;
115
115
  /**
116
116
  * Namespace for the current instance.
117
117
  * @default 'keyv'
118
- */
118
+ */
119
119
  namespace?: string;
120
120
  /**
121
121
  * A custom serialization function.
@@ -125,7 +125,7 @@ type KeyvOptions = {
125
125
  /**
126
126
  * A custom deserialization function.
127
127
  * @default defaultDeserialize using JSON.parse
128
- */
128
+ */
129
129
  deserialize?: Deserialize;
130
130
  /**
131
131
  * The storage adapter instance to be used by Keyv.
@@ -158,8 +158,8 @@ type KeyvOptions = {
158
158
  */
159
159
  throwOnErrors?: boolean;
160
160
  };
161
- type KeyvOptions_ = Omit<KeyvOptions, 'store'> & {
162
- store: KeyvStoreAdapter | Map<any, any> & KeyvStoreAdapter;
161
+ type KeyvOptions_ = Omit<KeyvOptions, "store"> & {
162
+ store: KeyvStoreAdapter | (Map<any, any> & KeyvStoreAdapter);
163
163
  };
164
164
  type IteratorFunction = (argument: any) => AsyncGenerator<any, void>;
165
165
  declare class Keyv<GenericValue = any> extends EventManager {
@@ -189,7 +189,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
189
189
  * @param {KeyvStoreAdapter | KeyvOptions | Map<any, any>} store to be provided or just the options
190
190
  * @param {Omit<KeyvOptions, 'store'>} [options] if you provide the store you can then provide the Keyv Options
191
191
  */
192
- constructor(store?: KeyvStoreAdapter | KeyvOptions | Map<any, any>, options?: Omit<KeyvOptions, 'store'>);
192
+ constructor(store?: KeyvStoreAdapter | KeyvOptions | Map<any, any>, options?: Omit<KeyvOptions, "store">);
193
193
  /**
194
194
  * Keyv Constructor
195
195
  * @param {KeyvOptions} options to be provided
@@ -319,7 +319,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
319
319
  * Get the raw values of many keys. This is the replacement for setting raw to true in the getMany() method.
320
320
  * @param {string[]} keys the keys to get
321
321
  * @returns {Promise<Array<StoredDataRaw<Value>>>} will return an array of StoredDataRaw<Value> or undefined if the key does not exist or is expired.
322
- */
322
+ */
323
323
  getManyRaw<Value = GenericValue>(keys: string[]): Promise<Array<StoredDataRaw<Value>>>;
324
324
  /**
325
325
  * Set an item to the store
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { defaultSerialize, defaultDeserialize } from "@keyv/serialize";
2
+ import { defaultDeserialize, defaultSerialize } from "@keyv/serialize";
3
3
 
4
4
  // src/event-manager.ts
5
5
  var EventManager = class {
@@ -23,7 +23,9 @@ var EventManager = class {
23
23
  const listeners = this._eventListeners.get(event);
24
24
  if (listeners) {
25
25
  if (listeners.length >= this._maxListeners) {
26
- console.warn(`MaxListenersExceededWarning: Possible event memory leak detected. ${listeners.length + 1} ${event} listeners added. Use setMaxListeners() to increase limit.`);
26
+ console.warn(
27
+ `MaxListenersExceededWarning: Possible event memory leak detected. ${listeners.length + 1} ${event} listeners added. Use setMaxListeners() to increase limit.`
28
+ );
27
29
  }
28
30
  listeners.push(listener);
29
31
  }
@@ -51,6 +53,7 @@ var EventManager = class {
51
53
  this.on(event, onceListener);
52
54
  }
53
55
  // Emit an event
56
+ // biome-ignore lint/suspicious/noExplicitAny: type format
54
57
  emit(event, ...arguments_) {
55
58
  const listeners = this._eventListeners.get(event);
56
59
  if (listeners && listeners.length > 0) {
@@ -105,6 +108,7 @@ var HooksManager = class extends event_manager_default {
105
108
  }
106
109
  }
107
110
  // Triggers all handlers for a specific event with provided data
111
+ // biome-ignore lint/suspicious/noExplicitAny: type format
108
112
  trigger(event, data) {
109
113
  const eventHandlers = this._hookHandlers.get(event);
110
114
  if (eventHandlers) {
@@ -112,7 +116,12 @@ var HooksManager = class extends event_manager_default {
112
116
  try {
113
117
  handler(data);
114
118
  } catch (error) {
115
- this.emit("error", new Error(`Error in hook handler for event "${event}": ${error.message}`));
119
+ this.emit(
120
+ "error",
121
+ new Error(
122
+ `Error in hook handler for event "${event}": ${error.message}`
123
+ )
124
+ );
116
125
  }
117
126
  }
118
127
  }
@@ -219,6 +228,7 @@ var Keyv = class extends event_manager_default {
219
228
  /**
220
229
  * Store
221
230
  */
231
+ // biome-ignore lint/suspicious/noExplicitAny: type format
222
232
  _store = /* @__PURE__ */ new Map();
223
233
  _serialize = defaultSerialize;
224
234
  _deserialize = defaultDeserialize;
@@ -267,9 +277,14 @@ var Keyv = class extends event_manager_default {
267
277
  }
268
278
  this._store.namespace = this._namespace;
269
279
  if (typeof this._store[Symbol.iterator] === "function" && this._store instanceof Map) {
270
- this.iterator = this.generateIterator(this._store);
280
+ this.iterator = this.generateIterator(
281
+ this._store
282
+ );
271
283
  } else if ("iterator" in this._store && this._store.opts && this._checkIterableAdapter()) {
272
- this.iterator = this.generateIterator(this._store.iterator.bind(this._store));
284
+ this.iterator = this.generateIterator(
285
+ // biome-ignore lint/style/noNonNullAssertion: need to fix
286
+ this._store.iterator.bind(this._store)
287
+ );
273
288
  }
274
289
  }
275
290
  if (this.opts.stats) {
@@ -288,6 +303,7 @@ var Keyv = class extends event_manager_default {
288
303
  /**
289
304
  * Get the current store
290
305
  */
306
+ // biome-ignore lint/suspicious/noExplicitAny: type format
291
307
  get store() {
292
308
  return this._store;
293
309
  }
@@ -295,6 +311,7 @@ var Keyv = class extends event_manager_default {
295
311
  * Set the current store. This will also set the namespace, event error handler, and generate the iterator. If the store is not valid it will throw an error.
296
312
  * @param {KeyvStoreAdapter | Map<any, any> | any} store the store to set
297
313
  */
314
+ // biome-ignore lint/suspicious/noExplicitAny: type format
298
315
  set store(store) {
299
316
  if (this._isValidStorageAdapter(store)) {
300
317
  this._store = store;
@@ -306,9 +323,11 @@ var Keyv = class extends event_manager_default {
306
323
  this._store.namespace = this._namespace;
307
324
  }
308
325
  if (typeof store[Symbol.iterator] === "function" && store instanceof Map) {
309
- this.iterator = this.generateIterator(store);
326
+ this.iterator = this.generateIterator(
327
+ store
328
+ );
310
329
  } else if ("iterator" in store && store.opts && this._checkIterableAdapter()) {
311
- this.iterator = this.generateIterator(store.iterator.bind(store));
330
+ this.iterator = this.generateIterator(store.iterator?.bind(store));
312
331
  }
313
332
  } else {
314
333
  throw new Error("Invalid storage adapter");
@@ -440,7 +459,9 @@ var Keyv = class extends event_manager_default {
440
459
  return function_.bind(this);
441
460
  }
442
461
  _checkIterableAdapter() {
443
- return iterableAdapters.includes(this._store.opts.dialect) || iterableAdapters.some((element) => this._store.opts.url.includes(element));
462
+ return iterableAdapters.includes(this._store.opts.dialect) || iterableAdapters.some(
463
+ (element) => this._store.opts.url.includes(element)
464
+ );
444
465
  }
445
466
  _getKeyPrefix(key) {
446
467
  if (!this._useKeyPrefix) {
@@ -466,6 +487,7 @@ var Keyv = class extends event_manager_default {
466
487
  }
467
488
  return key.split(":").splice(1).join(":");
468
489
  }
490
+ // biome-ignore lint/suspicious/noExplicitAny: type format
469
491
  _isValidStorageAdapter(store) {
470
492
  return store instanceof Map || typeof store.get === "function" && typeof store.set === "function" && typeof store.delete === "function" && typeof store.clear === "function";
471
493
  }
@@ -500,7 +522,10 @@ var Keyv = class extends event_manager_default {
500
522
  this.stats.miss();
501
523
  return void 0;
502
524
  }
503
- this.hooks.trigger("postGet" /* POST_GET */, { key: keyPrefixed, value: deserializedData });
525
+ this.hooks.trigger("postGet" /* POST_GET */, {
526
+ key: keyPrefixed,
527
+ value: deserializedData
528
+ });
504
529
  this.stats.hit();
505
530
  return options?.raw ? deserializedData : deserializedData.value;
506
531
  }
@@ -523,7 +548,10 @@ var Keyv = class extends event_manager_default {
523
548
  return options?.raw ? deserializedRow : deserializedRow.value;
524
549
  });
525
550
  const deserializedRows = await Promise.allSettled(promises);
526
- const result2 = deserializedRows.map((row) => row.value);
551
+ const result2 = deserializedRows.map(
552
+ // biome-ignore lint/suspicious/noExplicitAny: type format
553
+ (row) => row.value
554
+ );
527
555
  this.hooks.trigger("postGetMany" /* POST_GET_MANY */, result2);
528
556
  if (result2.length > 0) {
529
557
  this.stats.hit();
@@ -574,27 +602,36 @@ var Keyv = class extends event_manager_default {
574
602
  return void 0;
575
603
  }
576
604
  const deserializedData = typeof rawData === "string" || this.opts.compression ? await this.deserializeData(rawData) : rawData;
577
- if (deserializedData !== void 0 && deserializedData.expires !== void 0 && deserializedData.expires !== null && deserializedData.expires < Date.now()) {
605
+ if (deserializedData !== void 0 && deserializedData.expires !== void 0 && deserializedData.expires !== null && // biome-ignore lint/style/noNonNullAssertion: need to fix
606
+ deserializedData.expires < Date.now()) {
578
607
  this.stats.miss();
579
608
  await this.delete(key);
580
609
  return void 0;
581
610
  }
582
611
  this.stats.hit();
583
- this.hooks.trigger("postGetRaw" /* POST_GET_RAW */, { key: keyPrefixed, value: deserializedData });
612
+ this.hooks.trigger("postGetRaw" /* POST_GET_RAW */, {
613
+ key: keyPrefixed,
614
+ value: deserializedData
615
+ });
584
616
  return deserializedData;
585
617
  }
586
618
  /**
587
619
  * Get the raw values of many keys. This is the replacement for setting raw to true in the getMany() method.
588
620
  * @param {string[]} keys the keys to get
589
621
  * @returns {Promise<Array<StoredDataRaw<Value>>>} will return an array of StoredDataRaw<Value> or undefined if the key does not exist or is expired.
590
- */
622
+ */
591
623
  async getManyRaw(keys) {
592
624
  const { store } = this.opts;
593
625
  const keyPrefixed = this._getKeyPrefixArray(keys);
594
626
  if (keys.length === 0) {
595
- const result2 = Array.from({ length: keys.length }).fill(void 0);
627
+ const result2 = Array.from({ length: keys.length }).fill(
628
+ void 0
629
+ );
596
630
  this.stats.misses += keys.length;
597
- this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, { keys: keyPrefixed, values: result2 });
631
+ this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, {
632
+ keys: keyPrefixed,
633
+ values: result2
634
+ });
598
635
  return result2;
599
636
  }
600
637
  let result = [];
@@ -607,7 +644,10 @@ var Keyv = class extends event_manager_default {
607
644
  return void 0;
608
645
  });
609
646
  const deserializedRows = await Promise.allSettled(promises);
610
- result = deserializedRows.map((row) => row.value);
647
+ result = deserializedRows.map(
648
+ // biome-ignore lint/suspicious/noExplicitAny: type format
649
+ (row) => row.value
650
+ );
611
651
  } else {
612
652
  const rawData = await store.getMany(keyPrefixed);
613
653
  for (const row of rawData) {
@@ -630,7 +670,10 @@ var Keyv = class extends event_manager_default {
630
670
  await this.deleteMany(expiredKeys);
631
671
  }
632
672
  this.stats.hitsOrMisses(result);
633
- this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, { keys: keyPrefixed, values: result });
673
+ this.hooks.trigger("postGetManyRaw" /* POST_GET_MANY_RAW */, {
674
+ keys: keyPrefixed,
675
+ values: result
676
+ });
634
677
  return result;
635
678
  }
636
679
  /**
@@ -669,7 +712,11 @@ var Keyv = class extends event_manager_default {
669
712
  throw error;
670
713
  }
671
714
  }
672
- this.hooks.trigger("postSet" /* POST_SET */, { key: keyPrefixed, value: serializedValue, ttl });
715
+ this.hooks.trigger("postSet" /* POST_SET */, {
716
+ key: keyPrefixed,
717
+ value: serializedValue,
718
+ ttl
719
+ });
673
720
  this.stats.set();
674
721
  return result;
675
722
  }
@@ -678,6 +725,7 @@ var Keyv = class extends event_manager_default {
678
725
  * @param {Array<KeyvEntry>} entries the entries to set
679
726
  * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
680
727
  */
728
+ // biome-ignore lint/correctness/noUnusedVariables: type format
681
729
  async setMany(entries) {
682
730
  let results = [];
683
731
  try {
@@ -689,20 +737,22 @@ var Keyv = class extends event_manager_default {
689
737
  const promiseResults = await Promise.all(promises);
690
738
  results = promiseResults;
691
739
  } else {
692
- const serializedEntries = await Promise.all(entries.map(async ({ key, value, ttl }) => {
693
- ttl ??= this._ttl;
694
- if (ttl === 0) {
695
- ttl = void 0;
696
- }
697
- const expires = typeof ttl === "number" ? Date.now() + ttl : void 0;
698
- if (typeof value === "symbol") {
699
- this.emit("error", "symbol cannot be serialized");
700
- throw new Error("symbol cannot be serialized");
701
- }
702
- const formattedValue = { value, expires };
703
- const serializedValue = await this.serializeData(formattedValue);
704
- return { key, value: serializedValue, ttl };
705
- }));
740
+ const serializedEntries = await Promise.all(
741
+ entries.map(async ({ key, value, ttl }) => {
742
+ ttl ??= this._ttl;
743
+ if (ttl === 0) {
744
+ ttl = void 0;
745
+ }
746
+ const expires = typeof ttl === "number" ? Date.now() + ttl : void 0;
747
+ if (typeof value === "symbol") {
748
+ this.emit("error", "symbol cannot be serialized");
749
+ throw new Error("symbol cannot be serialized");
750
+ }
751
+ const formattedValue = { value, expires };
752
+ const serializedValue = await this.serializeData(formattedValue);
753
+ return { key, value: serializedValue, ttl };
754
+ })
755
+ );
706
756
  results = await this._store.setMany(serializedEntries);
707
757
  }
708
758
  } catch (error) {
@@ -739,7 +789,10 @@ var Keyv = class extends event_manager_default {
739
789
  throw error;
740
790
  }
741
791
  }
742
- this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: result });
792
+ this.hooks.trigger("postDelete" /* POST_DELETE */, {
793
+ key: keyPrefixed,
794
+ value: result
795
+ });
743
796
  this.stats.delete();
744
797
  return result;
745
798
  }
@@ -759,7 +812,10 @@ var Keyv = class extends event_manager_default {
759
812
  const promises = keyPrefixed.map(async (key) => store.delete(key));
760
813
  const results = await Promise.all(promises);
761
814
  const returnResult = results.every(Boolean);
762
- this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: returnResult });
815
+ this.hooks.trigger("postDelete" /* POST_DELETE */, {
816
+ key: keyPrefixed,
817
+ value: returnResult
818
+ });
763
819
  return returnResult;
764
820
  } catch (error) {
765
821
  this.emit("error", error);
@@ -843,6 +899,7 @@ var Keyv = class extends event_manager_default {
843
899
  return store.disconnect();
844
900
  }
845
901
  }
902
+ // biome-ignore lint/suspicious/noExplicitAny: type format
846
903
  emit(event, ...arguments_) {
847
904
  if (event === "error" && !this.opts.emitErrors) {
848
905
  return;
@@ -854,7 +911,10 @@ var Keyv = class extends event_manager_default {
854
911
  return data;
855
912
  }
856
913
  if (this._compression?.compress) {
857
- return this._serialize({ value: await this._compression.compress(data.value), expires: data.expires });
914
+ return this._serialize({
915
+ value: await this._compression.compress(data.value),
916
+ expires: data.expires
917
+ });
858
918
  }
859
919
  return this._serialize(data);
860
920
  }
@@ -864,7 +924,10 @@ var Keyv = class extends event_manager_default {
864
924
  }
865
925
  if (this._compression?.decompress && typeof data === "string") {
866
926
  const result = await this._deserialize(data);
867
- return { value: await this._compression.decompress(result?.value), expires: result?.expires };
927
+ return {
928
+ value: await this._compression.decompress(result?.value),
929
+ expires: result?.expires
930
+ };
868
931
  }
869
932
  if (typeof data === "string") {
870
933
  return this._deserialize(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv",
3
- "version": "5.5.0",
3
+ "version": "5.5.1",
4
4
  "description": "Simple key-value storage with support for multiple backends",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -12,16 +12,6 @@
12
12
  "import": "./dist/index.js"
13
13
  }
14
14
  },
15
- "xo": {
16
- "rules": {
17
- "@typescript-eslint/ban-ts-comment": "off",
18
- "@typescript-eslint/no-unsafe-call": "off",
19
- "@typescript-eslint/no-unsafe-return": "off",
20
- "@typescript-eslint/no-unsafe-assignment": "off",
21
- "@typescript-eslint/no-unsafe-argument": "off",
22
- "@typescript-eslint/no-confusing-void-expression": "off"
23
- }
24
- },
25
15
  "repository": {
26
16
  "type": "git",
27
17
  "url": "git+https://github.com/jaredwray/keyv.git"
@@ -54,23 +44,23 @@
54
44
  },
55
45
  "homepage": "https://github.com/jaredwray/keyv",
56
46
  "dependencies": {
57
- "@keyv/serialize": "^1.1.0"
47
+ "@keyv/serialize": "^1.1.1"
58
48
  },
59
49
  "devDependencies": {
60
- "@faker-js/faker": "^9.9.0",
50
+ "@biomejs/biome": "^2.2.3",
51
+ "@faker-js/faker": "^10.0.0",
61
52
  "@vitest/coverage-v8": "^3.2.4",
62
53
  "rimraf": "^6.0.1",
63
54
  "timekeeper": "^2.3.1",
64
- "tsd": "^0.32.0",
55
+ "tsd": "^0.33.0",
65
56
  "vitest": "^3.2.4",
66
- "xo": "^1.2.0",
67
- "@keyv/compress-brotli": "^2.0.5",
68
- "@keyv/compress-gzip": "^2.0.3",
69
- "@keyv/memcache": "^2.0.2",
70
- "@keyv/compress-lz4": "^1.0.1",
71
57
  "@keyv/mongo": "^3.0.3",
58
+ "@keyv/compress-lz4": "^1.0.1",
59
+ "@keyv/memcache": "^2.0.2",
72
60
  "@keyv/sqlite": "^4.0.5",
73
- "@keyv/test-suite": "^2.1.0"
61
+ "@keyv/test-suite": "^2.1.1",
62
+ "@keyv/compress-brotli": "^2.0.5",
63
+ "@keyv/compress-gzip": "^2.0.3"
74
64
  },
75
65
  "tsd": {
76
66
  "directory": "test"
@@ -81,8 +71,8 @@
81
71
  ],
82
72
  "scripts": {
83
73
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
84
- "test": "xo --fix && vitest run --coverage",
85
- "test:ci": "xo && vitest --run --sequence.setupFiles=list --coverage",
74
+ "test": "biome check --write && vitest run --coverage",
75
+ "test:ci": "biome check && vitest --run --sequence.setupFiles=list --coverage",
86
76
  "clean": "rimraf ./node_modules ./coverage ./test/testdb.sqlite ./dist"
87
77
  }
88
78
  }