keyv 5.2.2 → 5.2.3
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 +9 -1
- package/dist/index.cjs +33 -6
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -144,7 +144,15 @@ await cache.get('foo'); // 'cache'
|
|
|
144
144
|
|
|
145
145
|
# Events
|
|
146
146
|
|
|
147
|
-
Keyv is a custom `EventEmitter` and will emit an `'error'` event if there is an error.
|
|
147
|
+
Keyv is a custom `EventEmitter` and will emit an `'error'` event if there is an error.
|
|
148
|
+
If there is no listener for the `'error'` event, an uncaught exception will be thrown.
|
|
149
|
+
To disable the `'error'` event, pass `emitErrors: false` in the constructor options.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
const keyv = new Keyv({ emitErrors: false });
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
In addition it will emit `clear` and `disconnect` events when the corresponding methods are called.
|
|
148
156
|
|
|
149
157
|
```js
|
|
150
158
|
const keyv = new Keyv();
|
package/dist/index.cjs
CHANGED
|
@@ -293,7 +293,7 @@ var Keyv = class extends event_manager_default {
|
|
|
293
293
|
if (!this._isValidStorageAdapter(this._store)) {
|
|
294
294
|
throw new Error("Invalid storage adapter");
|
|
295
295
|
}
|
|
296
|
-
if (typeof this._store.on === "function"
|
|
296
|
+
if (typeof this._store.on === "function") {
|
|
297
297
|
this._store.on("error", (error) => this.emit("error", error));
|
|
298
298
|
}
|
|
299
299
|
this._store.namespace = this._namespace;
|
|
@@ -327,7 +327,7 @@ var Keyv = class extends event_manager_default {
|
|
|
327
327
|
if (this._isValidStorageAdapter(store)) {
|
|
328
328
|
this._store = store;
|
|
329
329
|
this.opts.store = store;
|
|
330
|
-
if (typeof store.on === "function"
|
|
330
|
+
if (typeof store.on === "function") {
|
|
331
331
|
store.on("error", (error) => this.emit("error", error));
|
|
332
332
|
}
|
|
333
333
|
if (this._namespace) {
|
|
@@ -576,7 +576,10 @@ var Keyv = class extends event_manager_default {
|
|
|
576
576
|
const serializedValue = await this.serializeData(formattedValue);
|
|
577
577
|
let result = true;
|
|
578
578
|
try {
|
|
579
|
-
await store.set(keyPrefixed, serializedValue, ttl);
|
|
579
|
+
const value2 = await store.set(keyPrefixed, serializedValue, ttl);
|
|
580
|
+
if (typeof value2 === "boolean") {
|
|
581
|
+
result = value2;
|
|
582
|
+
}
|
|
580
583
|
} catch (error) {
|
|
581
584
|
result = false;
|
|
582
585
|
this.emit("error", error);
|
|
@@ -606,7 +609,16 @@ var Keyv = class extends event_manager_default {
|
|
|
606
609
|
}
|
|
607
610
|
const keyPrefixed = this._getKeyPrefix(key);
|
|
608
611
|
this.hooks.trigger("preDelete" /* PRE_DELETE */, { key: keyPrefixed });
|
|
609
|
-
|
|
612
|
+
let result = true;
|
|
613
|
+
try {
|
|
614
|
+
const value = await store.delete(keyPrefixed);
|
|
615
|
+
if (typeof value === "boolean") {
|
|
616
|
+
result = value;
|
|
617
|
+
}
|
|
618
|
+
} catch (error) {
|
|
619
|
+
result = false;
|
|
620
|
+
this.emit("error", error);
|
|
621
|
+
}
|
|
610
622
|
this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: result });
|
|
611
623
|
this.stats.delete();
|
|
612
624
|
return result;
|
|
@@ -618,7 +630,11 @@ var Keyv = class extends event_manager_default {
|
|
|
618
630
|
async clear() {
|
|
619
631
|
this.emit("clear");
|
|
620
632
|
const { store } = this.opts;
|
|
621
|
-
|
|
633
|
+
try {
|
|
634
|
+
await store.clear();
|
|
635
|
+
} catch (error) {
|
|
636
|
+
this.emit("error", error);
|
|
637
|
+
}
|
|
622
638
|
}
|
|
623
639
|
/**
|
|
624
640
|
* Has a key
|
|
@@ -631,7 +647,12 @@ var Keyv = class extends event_manager_default {
|
|
|
631
647
|
if (store.has !== void 0 && !(store instanceof Map)) {
|
|
632
648
|
return store.has(keyPrefixed);
|
|
633
649
|
}
|
|
634
|
-
|
|
650
|
+
let rawData;
|
|
651
|
+
try {
|
|
652
|
+
rawData = await store.get(keyPrefixed);
|
|
653
|
+
} catch (error) {
|
|
654
|
+
this.emit("error", error);
|
|
655
|
+
}
|
|
635
656
|
if (rawData) {
|
|
636
657
|
const data = await this.deserializeData(rawData);
|
|
637
658
|
if (data) {
|
|
@@ -654,6 +675,12 @@ var Keyv = class extends event_manager_default {
|
|
|
654
675
|
return store.disconnect();
|
|
655
676
|
}
|
|
656
677
|
}
|
|
678
|
+
emit(event, ...arguments_) {
|
|
679
|
+
if (event === "error" && !this.opts.emitErrors) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
super.emit(event, ...arguments_);
|
|
683
|
+
}
|
|
657
684
|
async serializeData(data) {
|
|
658
685
|
if (!this._serialize) {
|
|
659
686
|
return data;
|
package/dist/index.d.cts
CHANGED
|
@@ -260,6 +260,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
|
|
|
260
260
|
* @returns {Promise<void>}
|
|
261
261
|
*/
|
|
262
262
|
disconnect(): Promise<void>;
|
|
263
|
+
emit(event: string, ...arguments_: any[]): void;
|
|
263
264
|
serializeData<T>(data: DeserializedData<T>): Promise<string | DeserializedData<T>>;
|
|
264
265
|
deserializeData<T>(data: string | DeserializedData<T>): Promise<DeserializedData<T> | undefined>;
|
|
265
266
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -260,6 +260,7 @@ declare class Keyv<GenericValue = any> extends EventManager {
|
|
|
260
260
|
* @returns {Promise<void>}
|
|
261
261
|
*/
|
|
262
262
|
disconnect(): Promise<void>;
|
|
263
|
+
emit(event: string, ...arguments_: any[]): void;
|
|
263
264
|
serializeData<T>(data: DeserializedData<T>): Promise<string | DeserializedData<T>>;
|
|
264
265
|
deserializeData<T>(data: string | DeserializedData<T>): Promise<DeserializedData<T> | undefined>;
|
|
265
266
|
}
|
package/dist/index.js
CHANGED
|
@@ -267,7 +267,7 @@ var Keyv = class extends event_manager_default {
|
|
|
267
267
|
if (!this._isValidStorageAdapter(this._store)) {
|
|
268
268
|
throw new Error("Invalid storage adapter");
|
|
269
269
|
}
|
|
270
|
-
if (typeof this._store.on === "function"
|
|
270
|
+
if (typeof this._store.on === "function") {
|
|
271
271
|
this._store.on("error", (error) => this.emit("error", error));
|
|
272
272
|
}
|
|
273
273
|
this._store.namespace = this._namespace;
|
|
@@ -301,7 +301,7 @@ var Keyv = class extends event_manager_default {
|
|
|
301
301
|
if (this._isValidStorageAdapter(store)) {
|
|
302
302
|
this._store = store;
|
|
303
303
|
this.opts.store = store;
|
|
304
|
-
if (typeof store.on === "function"
|
|
304
|
+
if (typeof store.on === "function") {
|
|
305
305
|
store.on("error", (error) => this.emit("error", error));
|
|
306
306
|
}
|
|
307
307
|
if (this._namespace) {
|
|
@@ -550,7 +550,10 @@ var Keyv = class extends event_manager_default {
|
|
|
550
550
|
const serializedValue = await this.serializeData(formattedValue);
|
|
551
551
|
let result = true;
|
|
552
552
|
try {
|
|
553
|
-
await store.set(keyPrefixed, serializedValue, ttl);
|
|
553
|
+
const value2 = await store.set(keyPrefixed, serializedValue, ttl);
|
|
554
|
+
if (typeof value2 === "boolean") {
|
|
555
|
+
result = value2;
|
|
556
|
+
}
|
|
554
557
|
} catch (error) {
|
|
555
558
|
result = false;
|
|
556
559
|
this.emit("error", error);
|
|
@@ -580,7 +583,16 @@ var Keyv = class extends event_manager_default {
|
|
|
580
583
|
}
|
|
581
584
|
const keyPrefixed = this._getKeyPrefix(key);
|
|
582
585
|
this.hooks.trigger("preDelete" /* PRE_DELETE */, { key: keyPrefixed });
|
|
583
|
-
|
|
586
|
+
let result = true;
|
|
587
|
+
try {
|
|
588
|
+
const value = await store.delete(keyPrefixed);
|
|
589
|
+
if (typeof value === "boolean") {
|
|
590
|
+
result = value;
|
|
591
|
+
}
|
|
592
|
+
} catch (error) {
|
|
593
|
+
result = false;
|
|
594
|
+
this.emit("error", error);
|
|
595
|
+
}
|
|
584
596
|
this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: result });
|
|
585
597
|
this.stats.delete();
|
|
586
598
|
return result;
|
|
@@ -592,7 +604,11 @@ var Keyv = class extends event_manager_default {
|
|
|
592
604
|
async clear() {
|
|
593
605
|
this.emit("clear");
|
|
594
606
|
const { store } = this.opts;
|
|
595
|
-
|
|
607
|
+
try {
|
|
608
|
+
await store.clear();
|
|
609
|
+
} catch (error) {
|
|
610
|
+
this.emit("error", error);
|
|
611
|
+
}
|
|
596
612
|
}
|
|
597
613
|
/**
|
|
598
614
|
* Has a key
|
|
@@ -605,7 +621,12 @@ var Keyv = class extends event_manager_default {
|
|
|
605
621
|
if (store.has !== void 0 && !(store instanceof Map)) {
|
|
606
622
|
return store.has(keyPrefixed);
|
|
607
623
|
}
|
|
608
|
-
|
|
624
|
+
let rawData;
|
|
625
|
+
try {
|
|
626
|
+
rawData = await store.get(keyPrefixed);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
this.emit("error", error);
|
|
629
|
+
}
|
|
609
630
|
if (rawData) {
|
|
610
631
|
const data = await this.deserializeData(rawData);
|
|
611
632
|
if (data) {
|
|
@@ -628,6 +649,12 @@ var Keyv = class extends event_manager_default {
|
|
|
628
649
|
return store.disconnect();
|
|
629
650
|
}
|
|
630
651
|
}
|
|
652
|
+
emit(event, ...arguments_) {
|
|
653
|
+
if (event === "error" && !this.opts.emitErrors) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
super.emit(event, ...arguments_);
|
|
657
|
+
}
|
|
631
658
|
async serializeData(data) {
|
|
632
659
|
if (!this._serialize) {
|
|
633
660
|
return data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.3",
|
|
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": "^1.0.
|
|
72
|
+
"@keyv/serialize": "^1.0.2"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"rimraf": "^6.0.1",
|
|
76
76
|
"timekeeper": "^2.3.1",
|
|
77
77
|
"tsd": "^0.31.2",
|
|
78
78
|
"xo": "^0.60.0",
|
|
79
|
-
"@keyv/
|
|
79
|
+
"@keyv/compress-brotli": "^2.0.2",
|
|
80
80
|
"@keyv/compress-gzip": "^2.0.2",
|
|
81
|
-
"@keyv/test-suite": "^2.0.3",
|
|
82
|
-
"@keyv/sqlite": "^4.0.1",
|
|
83
81
|
"@keyv/memcache": "^2.0.1",
|
|
84
|
-
"@keyv/
|
|
82
|
+
"@keyv/mongo": "^3.0.1",
|
|
83
|
+
"@keyv/sqlite": "^4.0.1",
|
|
84
|
+
"@keyv/test-suite": "^2.0.3"
|
|
85
85
|
},
|
|
86
86
|
"tsd": {
|
|
87
87
|
"directory": "test"
|