@keyv/compress-brotli 1.0.0 → 1.1.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
@@ -1,4 +1,4 @@
1
- # @keyv/tiered [<img width="100" align="right" src="https://rawgit.com/lukechilds/keyv/master/media/logo.svg" alt="keyv">](https://github.com/lukechilds/keyv)
1
+ # @keyv/compress-brotli [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwray/keyv)
2
2
 
3
3
  > Brotli compression for Keyv
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/compress-brotli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "brotli compression for keyv",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -59,8 +59,9 @@
59
59
  "compress-brotli": "^1.3.8"
60
60
  },
61
61
  "devDependencies": {
62
- "@types/keyv": "^3.1.4",
62
+ "@keyv/test-suite": "*",
63
63
  "ava": "^4.2.0",
64
+ "json-buffer": "^3.0.1",
64
65
  "keyv": "*",
65
66
  "nyc": "^15.1.0",
66
67
  "requirable": "^1.0.5",
package/src/index.d.ts CHANGED
@@ -1,18 +1,23 @@
1
- import {EventEmitter} from 'node:events';
2
- import {Store, StoredData} from 'keyv';
1
+ import type {InputType, BrotliOptions, CompressCallback} from 'node:zlib';
2
+ import type Brotli, {CompressResult} from 'compress-brotli';
3
3
 
4
- declare class KeyvBrotli extends EventEmitter implements Store<Value> {
5
- ttlSupport: any;
6
- opts: any;
7
- constructor(options?: string | KeyvBrotli.Options);
8
- compress(value: Value);
9
- decompress(value: Value);
4
+ declare class KeyvBrotli {
5
+ brotli: Brotli;
6
+ constructor(options?: KeyvBrotli.Options);
7
+ async compress(value: InputType | number | boolean, options?: BrotliOptions);
8
+ async decompress(value: InputType | number | boolean, options?: BrotliOptions);
9
+ async serialize(value: any);
10
+ async deserialize(value: any);
10
11
  }
11
12
 
12
13
  declare namespace KeyvBrotli {
13
14
  interface Options {
14
- compress: (...args: any[]) => void;
15
- decompress: (...args: any[]) => void;
15
+ compressOptions?: BrotliOptions;
16
+ decompressOptions?: BrotliOptions;
17
+ enable?: boolean;
18
+ serialize?: any;
19
+ deserialize?: any;
20
+ iltorb?: any;
16
21
  }
17
22
  }
18
23
 
package/src/index.js CHANGED
@@ -3,28 +3,24 @@ const compressBrotli = require('compress-brotli');
3
3
 
4
4
  class KeyvBrotli {
5
5
  constructor(options) {
6
- this.opts = {
7
- ...options,
8
- };
9
-
10
- const {compress, decompress, serialize, deserialize} = compressBrotli(this.opts);
6
+ this.brotli = compressBrotli(options);
7
+ }
11
8
 
12
- this.opts.compress = compress;
13
- this.opts.serialize = async ({value, expires}) => serialize({value: await compress(value), expires});
9
+ async compress(value, options) {
10
+ return this.brotli.compress(value, options);
11
+ }
14
12
 
15
- this.opts.decompress = decompress;
16
- this.opts.deserialize = async data => {
17
- const {value, expires} = deserialize(data);
18
- return {value: await decompress(value), expires};
19
- };
13
+ async decompress(data, options) {
14
+ return this.brotli.decompress(data, options);
20
15
  }
21
16
 
22
- compress(value, options) {
23
- return this.opts.compress(value, options);
17
+ async serialize({value, expires}) {
18
+ return this.brotli.serialize({value: await this.compress(value), expires});
24
19
  }
25
20
 
26
- decompress(value, options) {
27
- return this.opts.decompress(value, options);
21
+ async deserialize(data) {
22
+ const {value, expires} = this.brotli.deserialize(data);
23
+ return {value: await this.decompress(value), expires};
28
24
  }
29
25
  }
30
26