keyv 4.2.8 → 4.3.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/README.md +16 -3
- package/package.json +5 -5
- package/src/index.d.ts +14 -5
- package/src/index.js +3 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
> Simple key-value storage with support for multiple backends
|
|
8
8
|
|
|
9
9
|
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
|
|
10
|
-
[](https://codecov.io/gh/jaredwray/keyv)
|
|
11
11
|
[](https://www.npmjs.com/package/keyv)
|
|
12
12
|
[](https://www.npmjs.com/package/keyv)
|
|
13
13
|
|
|
@@ -112,6 +112,7 @@ SQLite | [@keyv/sqlite](https://github.com/jaredwray/keyv/tree/master/packages/s
|
|
|
112
112
|
PostgreSQL | [@keyv/postgres](https://github.com/jaredwray/keyv/tree/master/packages/postgres) | No
|
|
113
113
|
MySQL | [@keyv/mysql](https://github.com/jaredwray/keyv/tree/master/packages/mysql) | No
|
|
114
114
|
Etcd | [@keyv/etcd](https://github.com/jaredwray/keyv/tree/master/packages/etcd) | Yes
|
|
115
|
+
Memcache | [@keyv/memcache](https://github.com/jaredwray/keyv/tree/master/packages/memcache) | Yes
|
|
115
116
|
|
|
116
117
|
## Third-party Storage Adapters
|
|
117
118
|
|
|
@@ -149,7 +150,6 @@ The following are third-party storage adapters compatible with Keyv:
|
|
|
149
150
|
- [keyv-null](https://www.npmjs.com/package/keyv-null) - Null storage adapter for Keyv
|
|
150
151
|
- [keyv-firestore ](https://github.com/goto-bus-stop/keyv-firestore) – Firebase Cloud Firestore adapter for Keyv
|
|
151
152
|
- [keyv-mssql](https://github.com/pmorgan3/keyv-mssql) - Microsoft Sql Server adapter for Keyv
|
|
152
|
-
- [keyv-memcache](https://github.com/jaredwray/keyv/tree/master/packages/memcache) - Memcache storage adapter for Keyv
|
|
153
153
|
- [keyv-azuretable](https://github.com/howlowck/keyv-azuretable) - Azure Table Storage/API adapter for Keyv
|
|
154
154
|
|
|
155
155
|
## Add Cache Support to your Module
|
|
@@ -289,6 +289,19 @@ Delete all entries in the current namespace.
|
|
|
289
289
|
|
|
290
290
|
Returns a promise which is resolved when the entries have been cleared.
|
|
291
291
|
|
|
292
|
+
#### .iterator()
|
|
293
|
+
|
|
294
|
+
Iterate over all entries of the current namespace.
|
|
295
|
+
|
|
296
|
+
Returns a iterable that can be iterated by for-of loops. For example:
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
// please note that the "await" keyword should be used here
|
|
300
|
+
for await (const [key, value] of this.keyv.iterator()) {
|
|
301
|
+
console.log(key, value);
|
|
302
|
+
};
|
|
303
|
+
```
|
|
304
|
+
|
|
292
305
|
# How to Contribute
|
|
293
306
|
|
|
294
307
|
In this section of the documentation we will cover:
|
|
@@ -369,4 +382,4 @@ If you need more information on the steps to create a pull request, you can find
|
|
|
369
382
|
|
|
370
383
|
## License
|
|
371
384
|
|
|
372
|
-
MIT © Jared Wray
|
|
385
|
+
MIT © Jared Wray
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@keyv/test-suite": "*",
|
|
40
|
-
"ava": "^4.
|
|
40
|
+
"ava": "^4.3.0",
|
|
41
41
|
"eslint-plugin-promise": "^6.0.0",
|
|
42
42
|
"nyc": "^15.1.0",
|
|
43
43
|
"pify": "5.0.0",
|
|
44
44
|
"this": "^1.1.0",
|
|
45
45
|
"timekeeper": "^2.2.0",
|
|
46
|
-
"tsd": "^0.
|
|
47
|
-
"typescript": "^4.
|
|
48
|
-
"xo": "^0.
|
|
46
|
+
"tsd": "^0.21.0",
|
|
47
|
+
"typescript": "^4.7.4",
|
|
48
|
+
"xo": "^0.50.0"
|
|
49
49
|
},
|
|
50
50
|
"tsd": {
|
|
51
51
|
"directory": "test"
|
package/src/index.d.ts
CHANGED
|
@@ -27,10 +27,19 @@ declare class Keyv<Value = any, Options extends Record<string, any> = Record<str
|
|
|
27
27
|
constructor(uri?: string, options?: Keyv.Options<Value> & Options);
|
|
28
28
|
|
|
29
29
|
/** Returns the value. */
|
|
30
|
-
get<Raw extends boolean = false>(key: string
|
|
30
|
+
get<Raw extends boolean = false>(key: string, options?: {raw?: Raw}):
|
|
31
31
|
Promise<(Raw extends false
|
|
32
32
|
? Value
|
|
33
33
|
: Keyv.DeserializedData<Value>) | undefined>;
|
|
34
|
+
|
|
35
|
+
/** Returns an array of values. Uses `store.getMany` if it exists, otherwise uses parallel calls to `store.get`. */
|
|
36
|
+
get<Raw extends boolean = false>(
|
|
37
|
+
key: string[],
|
|
38
|
+
options?: {raw?: Raw}
|
|
39
|
+
): Promise<
|
|
40
|
+
Array<(Raw extends false ? Value : Keyv.DeserializedData<Value>) | undefined>
|
|
41
|
+
>;
|
|
42
|
+
|
|
34
43
|
/**
|
|
35
44
|
* Set a value.
|
|
36
45
|
*
|
|
@@ -48,7 +57,7 @@ declare class Keyv<Value = any, Options extends Record<string, any> = Record<str
|
|
|
48
57
|
/** Check if key exists in current namespace. */
|
|
49
58
|
has(key: string): Promise<boolean>;
|
|
50
59
|
/** Iterator */
|
|
51
|
-
iterator(namespace
|
|
60
|
+
iterator(namespace?: string): AsyncGenerator<any, void, any>;
|
|
52
61
|
/**
|
|
53
62
|
* Closes the connection.
|
|
54
63
|
*
|
|
@@ -64,9 +73,9 @@ declare namespace Keyv {
|
|
|
64
73
|
/** Namespace for the current instance. */
|
|
65
74
|
namespace?: string | undefined;
|
|
66
75
|
/** A custom serialization function. */
|
|
67
|
-
serialize?: ((data: DeserializedData<Value>) => string) | undefined;
|
|
76
|
+
serialize?: ((data: DeserializedData<Value>) => string | Promise<string>) | undefined;
|
|
68
77
|
/** A custom deserialization function. */
|
|
69
|
-
deserialize?: ((data: string) => DeserializedData<Value> | undefined) | undefined;
|
|
78
|
+
deserialize?: ((data: string) => DeserializedData<Value> | undefined | Promise<DeserializedData<Value> | undefined>) | undefined;
|
|
70
79
|
/** The connection string URI. */
|
|
71
80
|
uri?: string | undefined;
|
|
72
81
|
/** The storage adapter instance to be used by Keyv. */
|
|
@@ -88,7 +97,7 @@ declare namespace Keyv {
|
|
|
88
97
|
set(key: string, value: Value, ttl?: number): any;
|
|
89
98
|
delete(key: string): boolean | Promise<boolean>;
|
|
90
99
|
clear(): void | Promise<void>;
|
|
91
|
-
has(key: string): boolean | Promise<boolean>;
|
|
100
|
+
has?(key: string): boolean | Promise<boolean>;
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const compressBrotli = require('compress-brotli');
|
|
|
7
7
|
const loadStore = options => {
|
|
8
8
|
const adapters = {
|
|
9
9
|
redis: '@keyv/redis',
|
|
10
|
+
rediss: '@keyv/redis',
|
|
10
11
|
mongodb: '@keyv/mongo',
|
|
11
12
|
mongo: '@keyv/mongo',
|
|
12
13
|
sqlite: '@keyv/sqlite',
|
|
@@ -35,7 +36,7 @@ const iterableAdapters = [
|
|
|
35
36
|
];
|
|
36
37
|
|
|
37
38
|
class Keyv extends EventEmitter {
|
|
38
|
-
constructor(uri, options) {
|
|
39
|
+
constructor(uri, {emitErrors = true, ...options} = {}) {
|
|
39
40
|
super();
|
|
40
41
|
this.opts = {
|
|
41
42
|
namespace: 'keyv',
|
|
@@ -59,7 +60,7 @@ class Keyv extends EventEmitter {
|
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
if (typeof this.opts.store.on === 'function') {
|
|
63
|
+
if (typeof this.opts.store.on === 'function' && emitErrors) {
|
|
63
64
|
this.opts.store.on('error', error => this.emit('error', error));
|
|
64
65
|
}
|
|
65
66
|
|