keyv 5.2.0 → 5.2.2

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/README.md CHANGED
@@ -1,8 +1,4 @@
1
- <h1 align="center">
2
- <img width="250" src="https://jaredwray.com/images/keyv.svg" alt="keyv">
3
- <br>
4
- <br>
5
- </h1>
1
+ <h1 align="center"><img width="250" src="https://jaredwray.com/images/keyv.svg" alt="keyv"></h1>
6
2
 
7
3
  > Simple key-value storage with support for multiple backends
8
4
 
@@ -281,41 +277,7 @@ The following are third-party storage adapters compatible with Keyv:
281
277
  - [keyv-azuretable](https://github.com/howlowck/keyv-azuretable) - Azure Table Storage/API adapter for Keyv
282
278
  - [keyv-arango](https://github.com/TimMikeladze/keyv-arango) - ArangoDB storage adapter for Keyv
283
279
  - [keyv-momento](https://github.com/momentohq/node-keyv-adaptor/) - Momento storage adapter for Keyv
284
-
285
- # Add Cache Support to your Module
286
-
287
- Keyv is designed to be easily embedded into other modules to add cache support. The recommended pattern is to expose a `cache` option in your modules options which is passed through to Keyv. Caching will work in memory by default and users have the option to also install a Keyv storage adapter and pass in a connection string, or any other storage that implements the `Map` API.
288
-
289
- You should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data.
290
-
291
- Inside your module:
292
-
293
- ```js
294
- class AwesomeModule {
295
- constructor(opts) {
296
- this.cache = new Keyv({
297
- uri: typeof opts.cache === 'string' && opts.cache,
298
- store: typeof opts.cache !== 'string' && opts.cache,
299
- namespace: 'awesome-module'
300
- });
301
- }
302
- }
303
- ```
304
-
305
- Now it can be consumed like this:
306
-
307
- ```js
308
- import AwesomeModule from 'awesome-module';
309
-
310
- // Caches stuff in memory by default
311
- const awesomeModule = new AwesomeModule();
312
-
313
- // After npm install --save keyv-redis
314
- const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });
315
-
316
- // Some third-party module that implements the Map API
317
- const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });
318
- ```
280
+ - [@resolid/keyv-sqlite](https://github.com/huijiewei/keyv-sqlite) - A new SQLite storage adapter for Keyv
319
281
 
320
282
  # Compression
321
283
 
package/dist/index.cjs CHANGED
@@ -62,7 +62,7 @@ var EventManager = class {
62
62
  off(event, listener) {
63
63
  const listeners = this._eventListeners.get(event) ?? [];
64
64
  const index = listeners.indexOf(listener);
65
- if (index > -1) {
65
+ if (index !== -1) {
66
66
  listeners.splice(index, 1);
67
67
  }
68
68
  if (listeners.length === 0) {
@@ -231,7 +231,9 @@ var iterableAdapters = [
231
231
  "postgres",
232
232
  "mysql",
233
233
  "mongo",
234
- "redis"
234
+ "redis",
235
+ "valkey",
236
+ "etcd"
235
237
  ];
236
238
  var Keyv = class extends event_manager_default {
237
239
  opts;
@@ -572,10 +574,16 @@ var Keyv = class extends event_manager_default {
572
574
  }
573
575
  const formattedValue = { value, expires };
574
576
  const serializedValue = await this.serializeData(formattedValue);
575
- await store.set(keyPrefixed, serializedValue, ttl);
577
+ let result = true;
578
+ try {
579
+ await store.set(keyPrefixed, serializedValue, ttl);
580
+ } catch (error) {
581
+ result = false;
582
+ this.emit("error", error);
583
+ }
576
584
  this.hooks.trigger("postSet" /* POST_SET */, { key: keyPrefixed, value: serializedValue, ttl });
577
585
  this.stats.set();
578
- return true;
586
+ return result;
579
587
  }
580
588
  /**
581
589
  * Delete an Entry
package/dist/index.d.cts CHANGED
@@ -47,6 +47,8 @@ type DeserializedData<Value> = {
47
47
  interface CompressionAdapter {
48
48
  compress(value: any, options?: any): Promise<any>;
49
49
  decompress(value: any, options?: any): Promise<any>;
50
+ serialize<Value>(data: DeserializedData<Value>): Promise<string> | string;
51
+ deserialize<Value>(data: string): Promise<DeserializedData<Value> | undefined> | DeserializedData<Value> | undefined;
50
52
  }
51
53
  type Serialize = <Value>(data: DeserializedData<Value>) => Promise<string> | string;
52
54
  type Deserialize = <Value>(data: string) => Promise<DeserializedData<Value> | undefined> | DeserializedData<Value> | undefined;
package/dist/index.d.ts CHANGED
@@ -47,6 +47,8 @@ type DeserializedData<Value> = {
47
47
  interface CompressionAdapter {
48
48
  compress(value: any, options?: any): Promise<any>;
49
49
  decompress(value: any, options?: any): Promise<any>;
50
+ serialize<Value>(data: DeserializedData<Value>): Promise<string> | string;
51
+ deserialize<Value>(data: string): Promise<DeserializedData<Value> | undefined> | DeserializedData<Value> | undefined;
50
52
  }
51
53
  type Serialize = <Value>(data: DeserializedData<Value>) => Promise<string> | string;
52
54
  type Deserialize = <Value>(data: string) => Promise<DeserializedData<Value> | undefined> | DeserializedData<Value> | undefined;
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var EventManager = class {
36
36
  off(event, listener) {
37
37
  const listeners = this._eventListeners.get(event) ?? [];
38
38
  const index = listeners.indexOf(listener);
39
- if (index > -1) {
39
+ if (index !== -1) {
40
40
  listeners.splice(index, 1);
41
41
  }
42
42
  if (listeners.length === 0) {
@@ -205,7 +205,9 @@ var iterableAdapters = [
205
205
  "postgres",
206
206
  "mysql",
207
207
  "mongo",
208
- "redis"
208
+ "redis",
209
+ "valkey",
210
+ "etcd"
209
211
  ];
210
212
  var Keyv = class extends event_manager_default {
211
213
  opts;
@@ -546,10 +548,16 @@ var Keyv = class extends event_manager_default {
546
548
  }
547
549
  const formattedValue = { value, expires };
548
550
  const serializedValue = await this.serializeData(formattedValue);
549
- await store.set(keyPrefixed, serializedValue, ttl);
551
+ let result = true;
552
+ try {
553
+ await store.set(keyPrefixed, serializedValue, ttl);
554
+ } catch (error) {
555
+ result = false;
556
+ this.emit("error", error);
557
+ }
550
558
  this.hooks.trigger("postSet" /* POST_SET */, { key: keyPrefixed, value: serializedValue, ttl });
551
559
  this.stats.set();
552
- return true;
560
+ return result;
553
561
  }
554
562
  /**
555
563
  * Delete an Entry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Simple key-value storage with support for multiple backends",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -69,19 +69,19 @@
69
69
  },
70
70
  "homepage": "https://github.com/jaredwray/keyv",
71
71
  "dependencies": {
72
- "@keyv/serialize": "*"
72
+ "@keyv/serialize": "^1.0.1"
73
73
  },
74
74
  "devDependencies": {
75
- "@keyv/compress-brotli": "*",
76
- "@keyv/compress-gzip": "*",
77
- "@keyv/memcache": "*",
78
- "@keyv/mongo": "*",
79
- "@keyv/sqlite": "*",
80
- "@keyv/test-suite": "*",
81
75
  "rimraf": "^6.0.1",
82
76
  "timekeeper": "^2.3.1",
83
77
  "tsd": "^0.31.2",
84
- "xo": "^0.59.3"
78
+ "xo": "^0.60.0",
79
+ "@keyv/mongo": "^3.0.1",
80
+ "@keyv/compress-gzip": "^2.0.2",
81
+ "@keyv/test-suite": "^2.0.3",
82
+ "@keyv/sqlite": "^4.0.1",
83
+ "@keyv/memcache": "^2.0.1",
84
+ "@keyv/compress-brotli": "^2.0.2"
85
85
  },
86
86
  "tsd": {
87
87
  "directory": "test"