keyv 4.2.0 → 4.2.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/package.json +3 -4
- package/src/index.d.ts +6 -4
- package/src/index.js +11 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
|
|
10
10
|
},
|
|
11
11
|
"xo": {
|
|
12
|
-
"extends": "xo-lukechilds",
|
|
13
12
|
"rules": {
|
|
14
|
-
"unicorn/prefer-module": 0
|
|
13
|
+
"unicorn/prefer-module": 0,
|
|
14
|
+
"unicorn/prefer-node-protocol": 0
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@keyv/test-suite": "*",
|
|
40
40
|
"ava": "^4.1.0",
|
|
41
|
-
"eslint-config-xo-lukechilds": "^1.0.1",
|
|
42
41
|
"eslint-plugin-promise": "^6.0.0",
|
|
43
42
|
"nyc": "^15.1.0",
|
|
44
43
|
"pify": "5.0.0",
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import EventEmitter from '
|
|
1
|
+
import {EventEmitter} from 'events';
|
|
2
2
|
|
|
3
|
-
declare class Keyv extends EventEmitter {
|
|
3
|
+
declare class Keyv<T = any> extends EventEmitter {
|
|
4
4
|
constructor(uri: string, options: Keyv.Options);
|
|
5
|
-
get(key: string, options
|
|
6
|
-
set(key: string, value:
|
|
5
|
+
get(key: string, options?: any): Promise<T>;
|
|
6
|
+
set(key: string, value: T, ttl?: number): Promise<boolean>;
|
|
7
7
|
delete(key: string): Promise<boolean>;
|
|
8
8
|
clear(): Promise<void>;
|
|
9
9
|
has(key: string): Promise<boolean>;
|
|
@@ -16,6 +16,8 @@ declare namespace Keyv {
|
|
|
16
16
|
deserialize?: ((data: string) => any | undefined) | undefined;
|
|
17
17
|
ttl?: number | undefined;
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
type Store<T> = Keyv<T>;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export = Keyv;
|
package/src/index.js
CHANGED
|
@@ -38,21 +38,21 @@ class Keyv extends EventEmitter {
|
|
|
38
38
|
namespace: 'keyv',
|
|
39
39
|
serialize: JSONB.stringify,
|
|
40
40
|
deserialize: JSONB.parse,
|
|
41
|
-
...((typeof uri === 'string') ? {
|
|
41
|
+
...((typeof uri === 'string') ? {uri} : uri),
|
|
42
42
|
...options,
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
if (!this.opts.store) {
|
|
46
|
-
const adapterOptions = {
|
|
46
|
+
const adapterOptions = {...this.opts};
|
|
47
47
|
this.opts.store = loadStore(adapterOptions);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (this.opts.compress) {
|
|
51
51
|
const brotli = compressBrotli(this.opts.compress.opts);
|
|
52
|
-
this.opts.serialize = async ({
|
|
52
|
+
this.opts.serialize = async ({value, expires}) => brotli.serialize({value: await brotli.compress(value), expires});
|
|
53
53
|
this.opts.deserialize = async data => {
|
|
54
|
-
const {
|
|
55
|
-
return {
|
|
54
|
+
const {value, expires} = brotli.deserialize(data);
|
|
55
|
+
return {value: await brotli.decompress(value), expires};
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -113,7 +113,7 @@ class Keyv extends EventEmitter {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
get(key, options) {
|
|
116
|
-
const {
|
|
116
|
+
const {store} = this.opts;
|
|
117
117
|
const isArray = Array.isArray(key);
|
|
118
118
|
const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
|
|
119
119
|
if (isArray && store.getMany === undefined) {
|
|
@@ -201,7 +201,7 @@ class Keyv extends EventEmitter {
|
|
|
201
201
|
ttl = undefined;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
const {
|
|
204
|
+
const {store} = this.opts;
|
|
205
205
|
|
|
206
206
|
return Promise.resolve()
|
|
207
207
|
.then(() => {
|
|
@@ -210,7 +210,7 @@ class Keyv extends EventEmitter {
|
|
|
210
210
|
this.emit('error', 'symbol cannot be serialized');
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
value = {
|
|
213
|
+
value = {value, expires};
|
|
214
214
|
return this.opts.serialize(value);
|
|
215
215
|
})
|
|
216
216
|
.then(value => store.set(keyPrefixed, value, ttl))
|
|
@@ -218,7 +218,7 @@ class Keyv extends EventEmitter {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
delete(key) {
|
|
221
|
-
const {
|
|
221
|
+
const {store} = this.opts;
|
|
222
222
|
if (Array.isArray(key)) {
|
|
223
223
|
const keyPrefixed = this._getKeyPrefixArray(key);
|
|
224
224
|
if (store.deleteMany === undefined) {
|
|
@@ -241,14 +241,14 @@ class Keyv extends EventEmitter {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
clear() {
|
|
244
|
-
const {
|
|
244
|
+
const {store} = this.opts;
|
|
245
245
|
return Promise.resolve()
|
|
246
246
|
.then(() => store.clear());
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
has(key) {
|
|
250
250
|
const keyPrefixed = this._getKeyPrefix(key);
|
|
251
|
-
const {
|
|
251
|
+
const {store} = this.opts;
|
|
252
252
|
return Promise.resolve()
|
|
253
253
|
.then(async () => {
|
|
254
254
|
if (typeof store.has === 'function') {
|