Comparing version 5.2.2 to 5.2.3
@@ -263,2 +263,3 @@ type EventListener = (...arguments_: any[]) => void; | ||
disconnect(): Promise<void>; | ||
emit(event: string, ...arguments_: any[]): void; | ||
serializeData<T>(data: DeserializedData<T>): Promise<string | DeserializedData<T>>; | ||
@@ -265,0 +266,0 @@ deserializeData<T>(data: string | DeserializedData<T>): Promise<DeserializedData<T> | undefined>; |
@@ -270,3 +270,3 @@ // src/index.ts | ||
} | ||
if (typeof this._store.on === "function" && this.opts.emitErrors) { | ||
if (typeof this._store.on === "function") { | ||
this._store.on("error", (error) => this.emit("error", error)); | ||
@@ -305,3 +305,3 @@ } | ||
this.opts.store = store; | ||
if (typeof store.on === "function" && this.opts.emitErrors) { | ||
if (typeof store.on === "function") { | ||
store.on("error", (error) => this.emit("error", error)); | ||
@@ -555,3 +555,6 @@ } | ||
try { | ||
await store.set(keyPrefixed, serializedValue, ttl); | ||
const value2 = await store.set(keyPrefixed, serializedValue, ttl); | ||
if (typeof value2 === "boolean") { | ||
result = value2; | ||
} | ||
} catch (error) { | ||
@@ -586,3 +589,12 @@ result = false; | ||
this.hooks.trigger("preDelete" /* PRE_DELETE */, { key: keyPrefixed }); | ||
const result = await store.delete(keyPrefixed); | ||
let result = true; | ||
try { | ||
const value = await store.delete(keyPrefixed); | ||
if (typeof value === "boolean") { | ||
result = value; | ||
} | ||
} catch (error) { | ||
result = false; | ||
this.emit("error", error); | ||
} | ||
this.hooks.trigger("postDelete" /* POST_DELETE */, { key: keyPrefixed, value: result }); | ||
@@ -599,3 +611,7 @@ this.stats.delete(); | ||
const { store } = this.opts; | ||
await store.clear(); | ||
try { | ||
await store.clear(); | ||
} catch (error) { | ||
this.emit("error", error); | ||
} | ||
} | ||
@@ -613,3 +629,8 @@ /** | ||
} | ||
const rawData = await store.get(keyPrefixed); | ||
let rawData; | ||
try { | ||
rawData = await store.get(keyPrefixed); | ||
} catch (error) { | ||
this.emit("error", error); | ||
} | ||
if (rawData) { | ||
@@ -637,2 +658,8 @@ const data = await this.deserializeData(rawData); | ||
} | ||
emit(event, ...arguments_) { | ||
if (event === "error" && !this.opts.emitErrors) { | ||
return; | ||
} | ||
super.emit(event, ...arguments_); | ||
} | ||
async serializeData(data) { | ||
@@ -639,0 +666,0 @@ if (!this._serialize) { |
{ | ||
"name": "keyv", | ||
"version": "5.2.2", | ||
"version": "5.2.3", | ||
"description": "Simple key-value storage with support for multiple backends", | ||
@@ -72,3 +72,3 @@ "type": "module", | ||
"dependencies": { | ||
"@keyv/serialize": "^1.0.1" | ||
"@keyv/serialize": "^1.0.2" | ||
}, | ||
@@ -80,8 +80,8 @@ "devDependencies": { | ||
"xo": "^0.60.0", | ||
"@keyv/compress-brotli": "^2.0.2", | ||
"@keyv/compress-gzip": "^2.0.2", | ||
"@keyv/memcache": "^2.0.1", | ||
"@keyv/mongo": "^3.0.1", | ||
"@keyv/compress-gzip": "^2.0.2", | ||
"@keyv/test-suite": "^2.0.3", | ||
"@keyv/sqlite": "^4.0.1", | ||
"@keyv/memcache": "^2.0.1", | ||
"@keyv/compress-brotli": "^2.0.2" | ||
"@keyv/test-suite": "^2.0.3" | ||
}, | ||
@@ -88,0 +88,0 @@ "tsd": { |
@@ -147,5 +147,13 @@ <h1 align="center"><img width="250" src="https://jaredwray.com/images/keyv.svg" alt="keyv"></h1> | ||
Keyv is a custom `EventEmitter` and will emit an `'error'` event if there is an error. In addition it will emit a `clear` and `disconnect` event when the corresponding methods are called. | ||
Keyv is a custom `EventEmitter` and will emit an `'error'` event if there is an error. | ||
If there is no listener for the `'error'` event, an uncaught exception will be thrown. | ||
To disable the `'error'` event, pass `emitErrors: false` in the constructor options. | ||
```js | ||
const keyv = new Keyv({ emitErrors: false }); | ||
``` | ||
In addition it will emit `clear` and `disconnect` events when the corresponding methods are called. | ||
```js | ||
const keyv = new Keyv(); | ||
@@ -152,0 +160,0 @@ const handleConnectionError = err => console.log('Connection Error', err); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83646
1653
568
Updated@keyv/serialize@^1.0.2