keyv 5.2.1 → 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 +1 -35
- package/dist/index.cjs +12 -4
- package/dist/index.js +12 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -277,41 +277,7 @@ The following are third-party storage adapters compatible with Keyv:
|
|
|
277
277
|
- [keyv-azuretable](https://github.com/howlowck/keyv-azuretable) - Azure Table Storage/API adapter for Keyv
|
|
278
278
|
- [keyv-arango](https://github.com/TimMikeladze/keyv-arango) - ArangoDB storage adapter for Keyv
|
|
279
279
|
- [keyv-momento](https://github.com/momentohq/node-keyv-adaptor/) - Momento storage adapter for Keyv
|
|
280
|
-
|
|
281
|
-
# Add Cache Support to your Module
|
|
282
|
-
|
|
283
|
-
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.
|
|
284
|
-
|
|
285
|
-
You should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data.
|
|
286
|
-
|
|
287
|
-
Inside your module:
|
|
288
|
-
|
|
289
|
-
```js
|
|
290
|
-
class AwesomeModule {
|
|
291
|
-
constructor(opts) {
|
|
292
|
-
this.cache = new Keyv({
|
|
293
|
-
uri: typeof opts.cache === 'string' && opts.cache,
|
|
294
|
-
store: typeof opts.cache !== 'string' && opts.cache,
|
|
295
|
-
namespace: 'awesome-module'
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Now it can be consumed like this:
|
|
302
|
-
|
|
303
|
-
```js
|
|
304
|
-
import AwesomeModule from 'awesome-module';
|
|
305
|
-
|
|
306
|
-
// Caches stuff in memory by default
|
|
307
|
-
const awesomeModule = new AwesomeModule();
|
|
308
|
-
|
|
309
|
-
// After npm install --save keyv-redis
|
|
310
|
-
const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });
|
|
311
|
-
|
|
312
|
-
// Some third-party module that implements the Map API
|
|
313
|
-
const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });
|
|
314
|
-
```
|
|
280
|
+
- [@resolid/keyv-sqlite](https://github.com/huijiewei/keyv-sqlite) - A new SQLite storage adapter for Keyv
|
|
315
281
|
|
|
316
282
|
# Compression
|
|
317
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
|
|
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
|
-
|
|
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
|
|
586
|
+
return result;
|
|
579
587
|
}
|
|
580
588
|
/**
|
|
581
589
|
* Delete an Entry
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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"
|