@keyv/compress-brotli 1.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 ADDED
@@ -0,0 +1,40 @@
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)
2
+
3
+ > Brotli compression for Keyv
4
+
5
+ [![build](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
6
+ [![codecov](https://codecov.io/gh/jaredwray/keyv/branch/main/graph/badge.svg?token=bRzR3RyOXZ)](https://codecov.io/gh/jaredwray/keyv)
7
+ [![npm](https://img.shields.io/npm/v/@keyv/compress-brotli.svg)](https://www.npmjs.com/package/@keyv/compress-brotli)
8
+ [![npm](https://img.shields.io/npm/dm/@keyv/compress-brotli)](https://npmjs.com/package/@keyv/compress-brotli)
9
+
10
+ Brotli compression for [Keyv](https://github.com/jaredwray/keyv).
11
+
12
+ Brotli is a data compression algorithm that is designed to be fast and efficient.
13
+
14
+ ## Install
15
+
16
+ ```shell
17
+ npm install --save keyv @keyv/compress-brotli
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```javascript
23
+ const KeyvBrotli = require('@keyv/compress-brotli');
24
+ const Keyv = require('keyv');
25
+
26
+ const keyv = new Keyv({store: new Map(), compression: new KeyvBrotli()});
27
+
28
+ ```
29
+
30
+ ## API
31
+
32
+ ### @keyv/compress-brotli(\[options])
33
+
34
+ #### options
35
+
36
+ All options for @keyv/compress-brotli are based on the package [compress-brotli](https://github.com/Kikobeats/compress-brotli)
37
+
38
+ ## License
39
+
40
+ MIT © Jared Wray
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@keyv/compress-brotli",
3
+ "version": "1.0.0",
4
+ "description": "brotli compression for keyv",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "xo && nyc ava --serial",
8
+ "coverage": "nyc report --reporter=text-lcov > coverage.lcov",
9
+ "clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
10
+ },
11
+ "xo": {
12
+ "rules": {
13
+ "unicorn/prefer-module": 0,
14
+ "@typescript-eslint/no-unsafe-call": 0,
15
+ "ava/no-ignored-test-files": [
16
+ "error",
17
+ {
18
+ "extensions": [
19
+ "js",
20
+ "ts"
21
+ ]
22
+ }
23
+ ]
24
+ }
25
+ },
26
+ "ava": {
27
+ "require": [
28
+ "requirable",
29
+ "ts-node/register"
30
+ ],
31
+ "extensions": [
32
+ "js",
33
+ "ts"
34
+ ]
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/jaredwray/keyv.git"
39
+ },
40
+ "keywords": [
41
+ "compress",
42
+ "brotli",
43
+ "keyv",
44
+ "storage",
45
+ "adapter",
46
+ "key",
47
+ "value",
48
+ "store",
49
+ "cache",
50
+ "ttl"
51
+ ],
52
+ "author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/jaredwray/keyv/issues"
56
+ },
57
+ "homepage": "https://github.com/jaredwray/keyv",
58
+ "dependencies": {
59
+ "compress-brotli": "^1.3.8"
60
+ },
61
+ "devDependencies": {
62
+ "@types/keyv": "^3.1.4",
63
+ "ava": "^4.2.0",
64
+ "keyv": "*",
65
+ "nyc": "^15.1.0",
66
+ "requirable": "^1.0.5",
67
+ "this": "^1.1.0",
68
+ "ts-node": "^10.8.2",
69
+ "tsd": "^0.20.0",
70
+ "typescript": "^4.6.4",
71
+ "webpack": "^5.74.0",
72
+ "xo": "^0.48.0"
73
+ },
74
+ "tsd": {
75
+ "directory": "test"
76
+ },
77
+ "types": "./src/index.d.ts",
78
+ "engines": {
79
+ "node": ">= 12"
80
+ },
81
+ "files": [
82
+ "src"
83
+ ]
84
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import {EventEmitter} from 'node:events';
2
+ import {Store, StoredData} from 'keyv';
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);
10
+ }
11
+
12
+ declare namespace KeyvBrotli {
13
+ interface Options {
14
+ compress: (...args: any[]) => void;
15
+ decompress: (...args: any[]) => void;
16
+ }
17
+ }
18
+
19
+ export = KeyvBrotli;
package/src/index.js ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ const compressBrotli = require('compress-brotli');
3
+
4
+ class KeyvBrotli {
5
+ constructor(options) {
6
+ this.opts = {
7
+ ...options,
8
+ };
9
+
10
+ const {compress, decompress, serialize, deserialize} = compressBrotli(this.opts);
11
+
12
+ this.opts.compress = compress;
13
+ this.opts.serialize = async ({value, expires}) => serialize({value: await compress(value), expires});
14
+
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
+ };
20
+ }
21
+
22
+ compress(value, options) {
23
+ return this.opts.compress(value, options);
24
+ }
25
+
26
+ decompress(value, options) {
27
+ return this.opts.decompress(value, options);
28
+ }
29
+ }
30
+
31
+ module.exports = KeyvBrotli;