keyv 3.1.0 → 4.0.0
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 +17 -5
- package/package.json +5 -5
- package/src/index.js +16 -8
package/README.md
CHANGED
|
@@ -142,6 +142,9 @@ The following are third-party storage adapters compatible with Keyv:
|
|
|
142
142
|
- [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple "Least Recently Used" (LRU) cache
|
|
143
143
|
- [keyv-file](https://github.com/zaaack/keyv-file) - File system storage adapter for Keyv
|
|
144
144
|
- [keyv-dynamodb](https://www.npmjs.com/package/keyv-dynamodb) - DynamoDB storage adapter for Keyv
|
|
145
|
+
- [keyv-firestore ](https://github.com/goto-bus-stop/keyv-firestore) – Firebase Cloud Firestore adapter for Keyv
|
|
146
|
+
- [keyv-mssql](https://github.com/pmorgan3/keyv-mssql) - Microsoft Sql Server adapter for Keyv
|
|
147
|
+
- [keyv-memcache](https://github.com/jaredwray/keyv-memcache) - Memcache storage adapter for Keyv
|
|
145
148
|
|
|
146
149
|
## Add Cache Support to your Module
|
|
147
150
|
|
|
@@ -253,23 +256,32 @@ Set a value.
|
|
|
253
256
|
|
|
254
257
|
By default keys are persistent. You can set an expiry TTL in milliseconds.
|
|
255
258
|
|
|
256
|
-
Returns `true`.
|
|
259
|
+
Returns a promise which resolves to `true`.
|
|
257
260
|
|
|
258
|
-
#### .get(key)
|
|
261
|
+
#### .get(key, [options])
|
|
259
262
|
|
|
260
|
-
Returns the value.
|
|
263
|
+
Returns a promise which resolves to the retrieved value.
|
|
264
|
+
|
|
265
|
+
##### options.raw
|
|
266
|
+
|
|
267
|
+
Type: `Boolean`<br>
|
|
268
|
+
Default: `false`
|
|
269
|
+
|
|
270
|
+
If set to true the raw DB object Keyv stores internally will be returned instead of just the value.
|
|
271
|
+
|
|
272
|
+
This contains the TTL timestamp.
|
|
261
273
|
|
|
262
274
|
#### .delete(key)
|
|
263
275
|
|
|
264
276
|
Deletes an entry.
|
|
265
277
|
|
|
266
|
-
Returns `true` if the key existed, `false` if not.
|
|
278
|
+
Returns a promise which resolves to `true` if the key existed, `false` if not.
|
|
267
279
|
|
|
268
280
|
#### .clear()
|
|
269
281
|
|
|
270
282
|
Delete all entries in the current namespace.
|
|
271
283
|
|
|
272
|
-
Returns
|
|
284
|
+
Returns a promise which is resolved when the entries have been cleared.
|
|
273
285
|
|
|
274
286
|
## License
|
|
275
287
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/lukechilds/keyv",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"json-buffer": "3.0.
|
|
32
|
+
"json-buffer": "3.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"ava": "^
|
|
35
|
+
"ava": "^2.2.0",
|
|
36
36
|
"coveralls": "^3.0.0",
|
|
37
37
|
"eslint-config-xo-lukechilds": "^1.0.0",
|
|
38
38
|
"@keyv/mongo": "*",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"@keyv/redis": "*",
|
|
42
42
|
"@keyv/sqlite": "*",
|
|
43
43
|
"@keyv/test-suite": "*",
|
|
44
|
-
"nyc": "^
|
|
44
|
+
"nyc": "^14.1.1",
|
|
45
45
|
"this": "^1.0.2",
|
|
46
46
|
"timekeeper": "^2.0.0",
|
|
47
|
-
"xo": "^0.
|
|
47
|
+
"xo": "^0.24.0"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const loadStore = opts => {
|
|
|
17
17
|
const adapter = opts.adapter || /^[^:]*/.exec(opts.uri)[0];
|
|
18
18
|
return new (require(adapters[adapter]))(opts);
|
|
19
19
|
}
|
|
20
|
+
|
|
20
21
|
return new Map();
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -49,21 +50,25 @@ class Keyv extends EventEmitter {
|
|
|
49
50
|
return `${this.opts.namespace}:${key}`;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
get(key) {
|
|
53
|
+
get(key, opts) {
|
|
53
54
|
key = this._getKeyPrefix(key);
|
|
54
|
-
const store = this.opts
|
|
55
|
+
const { store } = this.opts;
|
|
55
56
|
return Promise.resolve()
|
|
56
57
|
.then(() => store.get(key))
|
|
57
58
|
.then(data => {
|
|
58
|
-
|
|
59
|
+
return (typeof data === 'string') ? this.opts.deserialize(data) : data;
|
|
60
|
+
})
|
|
61
|
+
.then(data => {
|
|
59
62
|
if (data === undefined) {
|
|
60
63
|
return undefined;
|
|
61
64
|
}
|
|
65
|
+
|
|
62
66
|
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
|
63
67
|
this.delete(key);
|
|
64
68
|
return undefined;
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
|
|
71
|
+
return (opts && opts.raw) ? data : data.value;
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
74
|
|
|
@@ -72,29 +77,32 @@ class Keyv extends EventEmitter {
|
|
|
72
77
|
if (typeof ttl === 'undefined') {
|
|
73
78
|
ttl = this.opts.ttl;
|
|
74
79
|
}
|
|
80
|
+
|
|
75
81
|
if (ttl === 0) {
|
|
76
82
|
ttl = undefined;
|
|
77
83
|
}
|
|
78
|
-
|
|
84
|
+
|
|
85
|
+
const { store } = this.opts;
|
|
79
86
|
|
|
80
87
|
return Promise.resolve()
|
|
81
88
|
.then(() => {
|
|
82
89
|
const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
|
|
83
90
|
value = { value, expires };
|
|
84
|
-
return
|
|
91
|
+
return this.opts.serialize(value);
|
|
85
92
|
})
|
|
93
|
+
.then(value => store.set(key, value, ttl))
|
|
86
94
|
.then(() => true);
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
delete(key) {
|
|
90
98
|
key = this._getKeyPrefix(key);
|
|
91
|
-
const store = this.opts
|
|
99
|
+
const { store } = this.opts;
|
|
92
100
|
return Promise.resolve()
|
|
93
101
|
.then(() => store.delete(key));
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
clear() {
|
|
97
|
-
const store = this.opts
|
|
105
|
+
const { store } = this.opts;
|
|
98
106
|
return Promise.resolve()
|
|
99
107
|
.then(() => store.clear());
|
|
100
108
|
}
|