keyv 4.4.1 → 4.5.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 +22 -2
- package/package.json +3 -4
- package/src/index.js +5 -8
package/README.md
CHANGED
|
@@ -187,6 +187,20 @@ const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });
|
|
|
187
187
|
const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
+
## Compression
|
|
191
|
+
|
|
192
|
+
Keyv supports `gzip` and `brotli` compression. To enable compression, pass the `compress` option to the constructor.
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
const KeyvGzip = require('@keyv/compress-gzip');
|
|
196
|
+
const Keyv = require('keyv');
|
|
197
|
+
|
|
198
|
+
const keyvGzip = new KeyvGzip();;
|
|
199
|
+
const keyv = new Keyv({ compression: KeyvGzip });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
You can also pass a custom compression function to the `compression` option. Following the pattern of the official compression adapters.
|
|
203
|
+
|
|
190
204
|
## API
|
|
191
205
|
|
|
192
206
|
### new Keyv([uri], [options])
|
|
@@ -224,6 +238,13 @@ Default: `undefined`
|
|
|
224
238
|
|
|
225
239
|
Default TTL. Can be overridden by specififying a TTL on `.set()`.
|
|
226
240
|
|
|
241
|
+
#### options.compression
|
|
242
|
+
|
|
243
|
+
Type: `@keyv/compress-<compression_package_name>`<br>
|
|
244
|
+
Default: `undefined`
|
|
245
|
+
|
|
246
|
+
Compression package to use. See [Compression](#compression) for more details.
|
|
247
|
+
|
|
227
248
|
#### options.serialize
|
|
228
249
|
|
|
229
250
|
Type: `Function`<br>
|
|
@@ -315,7 +336,6 @@ In this section of the documentation we will cover:
|
|
|
315
336
|
This package requires the following dependencies to run:
|
|
316
337
|
|
|
317
338
|
1) [Yarn V1](https://yarnpkg.com/getting-started/install)
|
|
318
|
-
2) [Lerna](https://lerna.js.org/)
|
|
319
339
|
3) [Docker](https://docs.docker.com/get-docker/)
|
|
320
340
|
|
|
321
341
|
## Setting up your workspace
|
|
@@ -337,7 +357,7 @@ Once the project is installed locally, you are ready to start up its services:
|
|
|
337
357
|
|
|
338
358
|
## Available Commands
|
|
339
359
|
|
|
340
|
-
Once the project is running, you can execute a variety of commands. The root workspace and each subpackage contain a `package.json` file with a `scripts` field listing all the commands that can be executed from that directory. This project also supports native `yarn`,
|
|
360
|
+
Once the project is running, you can execute a variety of commands. The root workspace and each subpackage contain a `package.json` file with a `scripts` field listing all the commands that can be executed from that directory. This project also supports native `yarn`, and `docker` commands.
|
|
341
361
|
|
|
342
362
|
Here, we'll cover the primary commands that can be executed from the root directory. Unless otherwise noted, these commands can also be executed from a subpackage. If executed from a subpackage, they will only affect that subpackage, rather than the entire workspace.
|
|
343
363
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"compress-brotli": "^1.3.8",
|
|
36
35
|
"json-buffer": "3.0.1"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@keyv/test-suite": "*",
|
|
40
|
-
"ava": "^4.3.
|
|
41
|
-
"eslint": "^8.
|
|
39
|
+
"ava": "^4.3.0",
|
|
40
|
+
"eslint": "^8.19.0",
|
|
42
41
|
"eslint-plugin-promise": "^6.0.0",
|
|
43
42
|
"nyc": "^15.1.0",
|
|
44
43
|
"pify": "5.0.0",
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
const JSONB = require('json-buffer');
|
|
5
|
-
const compressBrotli = require('compress-brotli');
|
|
6
5
|
|
|
7
6
|
const loadStore = options => {
|
|
8
7
|
const adapters = {
|
|
@@ -51,13 +50,11 @@ class Keyv extends EventEmitter {
|
|
|
51
50
|
this.opts.store = loadStore(adapterOptions);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
if (this.opts.
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
this.opts.
|
|
58
|
-
|
|
59
|
-
return {value: await brotli.decompress(value), expires};
|
|
60
|
-
};
|
|
53
|
+
if (this.opts.compression) {
|
|
54
|
+
const compression = this.opts.compression;
|
|
55
|
+
const {serialize, deserialize} = compression.opts;
|
|
56
|
+
this.opts.serialize = serialize;
|
|
57
|
+
this.opts.deserialize = deserialize;
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
if (typeof this.opts.store.on === 'function' && emitErrors) {
|