keyv 4.3.3 → 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 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`, `lerna`, and `docker` commands.
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.3",
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,7 +32,6 @@
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": {
@@ -46,7 +45,7 @@
46
45
  "timekeeper": "^2.2.0",
47
46
  "tsd": "^0.22.0",
48
47
  "typescript": "^4.7.4",
49
- "xo": "^0.50.0"
48
+ "xo": "^0.51.0"
50
49
  },
51
50
  "tsd": {
52
51
  "directory": "test"
package/src/index.d.ts CHANGED
@@ -79,7 +79,7 @@ declare namespace Keyv {
79
79
  /** The connection string URI. */
80
80
  uri?: string | undefined;
81
81
  /** The storage adapter instance to be used by Keyv. */
82
- store?: Store<Value> | undefined;
82
+ store?: Store<string | undefined> | undefined;
83
83
  /** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
84
84
  ttl?: number | undefined;
85
85
  /** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
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.compress) {
55
- const brotli = compressBrotli(this.opts.compress.opts);
56
- this.opts.serialize = async ({value, expires}) => brotli.serialize({value: await brotli.compress(value), expires});
57
- this.opts.deserialize = async data => {
58
- const {value, expires} = brotli.deserialize(data);
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) {
@@ -144,7 +141,7 @@ class Keyv extends EventEmitter {
144
141
  data.push(value.value);
145
142
  }
146
143
 
147
- return data.every(x => x === undefined) ? [] : data;
144
+ return data;
148
145
  });
149
146
  }
150
147
 
@@ -159,10 +156,6 @@ class Keyv extends EventEmitter {
159
156
  if (isArray) {
160
157
  const result = [];
161
158
 
162
- if (data.length === 0) {
163
- return [];
164
- }
165
-
166
159
  for (let row of data) {
167
160
  if ((typeof row === 'string')) {
168
161
  row = this.opts.deserialize(row);
@@ -181,7 +174,7 @@ class Keyv extends EventEmitter {
181
174
  }
182
175
  }
183
176
 
184
- return result.every(x => x === undefined) ? [] : result;
177
+ return result;
185
178
  }
186
179
 
187
180
  if (typeof data.expires === 'number' && Date.now() > data.expires) {