Skip to content

Commit 7574a7b

Browse files
authored
redis - updated to 2.8.2 (#965)
* Revert "removing packages that will not be affected by Keyv v4 to v5 migration (#945)" This reverts commit 1164943. * Update package.json * redis - moving to 2.8.2
1 parent 1164943 commit 7574a7b

154 files changed

Lines changed: 11316 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/compress-brotli/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @keyv/compress-brotli [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwra/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
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"name": "@keyv/compress-brotli",
3+
"version": "1.1.5",
4+
"description": "brotli compression for keyv",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"scripts": {
8+
"build": "tsc --project tsconfig.dist.json",
9+
"prepare": "yarn build",
10+
"test": "xo && c8 ava --serial",
11+
"test:ci": "xo && ava --serial",
12+
"clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite && rm -rf ./dist && rm -rf ./.nyc_output"
13+
},
14+
"xo": {
15+
"rules": {
16+
"unicorn/prefer-module": 0,
17+
"@typescript-eslint/no-unsafe-call": 0,
18+
"@typescript-eslint/consistent-type-definitions": 0,
19+
"@typescript-eslint/no-unsafe-argument": 0,
20+
"ava/no-ignored-test-files": [
21+
"error",
22+
{
23+
"extensions": [
24+
"js",
25+
"ts"
26+
]
27+
}
28+
],
29+
"import/extensions": 0
30+
}
31+
},
32+
"repository": {
33+
"type": "git",
34+
"url": "git+https://github.com/jaredwray/keyv.git"
35+
},
36+
"keywords": [
37+
"compress",
38+
"brotli",
39+
"keyv",
40+
"storage",
41+
"adapter",
42+
"key",
43+
"value",
44+
"store",
45+
"cache",
46+
"ttl"
47+
],
48+
"author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
49+
"license": "MIT",
50+
"bugs": {
51+
"url": "https://github.com/jaredwray/keyv/issues"
52+
},
53+
"homepage": "https://github.com/jaredwray/keyv",
54+
"dependencies": {
55+
"compress-brotli": "^1.3.12"
56+
},
57+
"devDependencies": {
58+
"@keyv/test-suite": "*",
59+
"c8": "^8.0.1",
60+
"json-buffer": "^3.0.1",
61+
"keyv": "*",
62+
"requirable": "^1.0.5",
63+
"tsd": "^0.29.0",
64+
"webpack": "^5.89.0"
65+
},
66+
"tsd": {
67+
"directory": "test"
68+
},
69+
"engines": {
70+
"node": ">= 12"
71+
},
72+
"files": [
73+
"dist"
74+
],
75+
"ava": {
76+
"extensions": [
77+
"ts"
78+
],
79+
"require": [
80+
"ts-node/register"
81+
]
82+
}
83+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type {BrotliOptions, InputType} from 'node:zlib';
2+
import compressBrotli from 'compress-brotli';
3+
import type {Brotli, CompressResult, Options, SerializeResult, Serialize} from './types';
4+
5+
class KeyvBrotli {
6+
private readonly brotli: Brotli;
7+
constructor(options?: Options) {
8+
this.brotli = compressBrotli(options);
9+
}
10+
11+
async compress(value: any, options?: BrotliOptions): CompressResult {
12+
return this.brotli.compress(value, options);
13+
}
14+
15+
async decompress<T>(data: InputType, options?: BrotliOptions): Promise<T> {
16+
return await this.brotli.decompress(data, options) as T;
17+
}
18+
19+
async serialize({value, expires}: Serialize): Promise<SerializeResult> {
20+
const compressValue = await this.compress(value);
21+
// @ts-expect-error - `expires` is not part of the `SerializeResult` type
22+
return this.brotli.serialize({value: compressValue, expires});
23+
}
24+
25+
async deserialize(data: CompressResult): Promise<Serialize> {
26+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
27+
if (!data) {
28+
return data;
29+
}
30+
31+
const {value, expires} = this.brotli.deserialize(data) as Serialize;
32+
return {value: await this.decompress(value), expires};
33+
}
34+
}
35+
36+
export = KeyvBrotli;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type {BrotliOptions, CompressCallback, InputType} from 'node:zlib';
2+
import type {parse as JSONBparse, stringify as JSONBstringify} from 'json-buffer';
3+
4+
export type CompressResult = Promise<Parameters<CompressCallback>[1]>;
5+
export type DecompressResult = Promise<ReturnType<typeof JSONBparse>>;
6+
7+
export type SerializeResult = ReturnType<typeof JSONBstringify>;
8+
export type DeserializeResult = ReturnType<typeof JSONBparse>;
9+
10+
type BrotliSerialize<T> = (source: InputType) => T;
11+
type BrotliDeserialize<T> = (source: CompressResult) => T;
12+
13+
export type Serialize = {
14+
value: InputType;
15+
expires?: number;
16+
};
17+
18+
export interface Options {
19+
compressOptions?: BrotliOptions;
20+
decompressOptions?: BrotliOptions;
21+
enable?: boolean;
22+
serialize?: any;
23+
deserialize?: any;
24+
iltorb?: any;
25+
}
26+
27+
export interface Brotli {
28+
serialize: BrotliSerialize<SerializeResult>;
29+
deserialize: BrotliDeserialize<DeserializeResult>;
30+
compress: (data: InputType, options?: BrotliOptions) => CompressResult;
31+
decompress: (data: InputType, options?: BrotliOptions) => DecompressResult;
32+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import {constants as zlibConstants} from 'node:zlib';
2+
import v8 from 'node:v8';
3+
import test from 'ava';
4+
import json from 'json-buffer';
5+
import {keyvCompresstionTests} from '@keyv/test-suite';
6+
import KeyvBrotli from '../src/index';
7+
import type {DeserializeResult} from '../src/types';
8+
9+
// eslint-disable-next-line @typescript-eslint/naming-convention
10+
const {BROTLI_PARAM_MODE, BROTLI_PARAM_QUALITY} = zlibConstants;
11+
12+
keyvCompresstionTests(test, new KeyvBrotli());
13+
14+
test('object type compression/decompression', async t => {
15+
const keyv = new KeyvBrotli();
16+
const object = {
17+
a: 1,
18+
b: 'test',
19+
c: true,
20+
};
21+
const compressed = await keyv.compress(object);
22+
const decompressed = await keyv.decompress(compressed);
23+
t.deepEqual(decompressed, object);
24+
});
25+
26+
test('disable brotli compression', async t => {
27+
const options = {
28+
enable: false,
29+
};
30+
const keyv = new KeyvBrotli(options);
31+
const compressed = await keyv.compress('whatever');
32+
// @ts-expect-error Testing non-compressed value
33+
t.is(compressed, 'whatever');
34+
const decompressed: DeserializeResult = await keyv.decompress(compressed);
35+
t.is(decompressed, 'whatever');
36+
});
37+
38+
test('compression with compression options', async t => {
39+
const options = {
40+
compressOptions: {
41+
chunkSize: 1024,
42+
parameters: {
43+
[BROTLI_PARAM_MODE]: 2,
44+
[BROTLI_PARAM_QUALITY]: 7,
45+
},
46+
},
47+
};
48+
49+
const keyv = new KeyvBrotli(options);
50+
const keyvWithoutOptions = new KeyvBrotli();
51+
const compressed = await keyv.compress('whatever');
52+
const compressedWithoutOptions = await keyvWithoutOptions.compress('whatever');
53+
t.not(compressed, compressedWithoutOptions);
54+
});
55+
56+
test('decompression with decompression options', async t => {
57+
const options = {
58+
decompressOptions: {
59+
chunkSize: 1024,
60+
parameters: {
61+
[BROTLI_PARAM_MODE]: 2,
62+
},
63+
},
64+
};
65+
66+
const keyv = new KeyvBrotli(options);
67+
const compressed = await keyv.compress('whatever');
68+
const decompressed = await keyv.decompress(compressed);
69+
t.is(decompressed, 'whatever');
70+
});
71+
72+
test('compression/decompression with compression/decompression options', async t => {
73+
const options = {
74+
compressOptions: {
75+
chunkSize: 1024,
76+
parameters: {
77+
[BROTLI_PARAM_MODE]: 2,
78+
},
79+
},
80+
decompressOptions: {
81+
chunkSize: 1024,
82+
parameters: {
83+
[BROTLI_PARAM_MODE]: 2,
84+
},
85+
},
86+
};
87+
88+
const keyv = new KeyvBrotli(options);
89+
const compressed = await keyv.compress('whatever');
90+
const decompressed = await keyv.decompress(compressed);
91+
t.is(decompressed, 'whatever');
92+
});
93+
94+
test('decompression using number array with v8', async t => {
95+
const options = {
96+
serialize: v8.serialize,
97+
deserialize: v8.deserialize,
98+
};
99+
100+
const keyv = new KeyvBrotli(options);
101+
const compressed = await keyv.compress({help: [1, 2, 4]});
102+
const decompressed = await keyv.decompress(compressed);
103+
t.deepEqual(decompressed, {help: [1, 2, 4]});
104+
});
105+
106+
test('decompression using number array with json-buffer', async t => {
107+
const options = {
108+
serialize: json.stringify,
109+
deserialize: json.parse,
110+
};
111+
112+
const keyv = new KeyvBrotli(options);
113+
const compressed = await keyv.compress({help: [1, 2, 4]});
114+
const decompressed = await keyv.decompress(compressed);
115+
t.deepEqual(decompressed, {help: [1, 2, 4]});
116+
});
117+
118+
test('deserialize with an empty value', async t => {
119+
const keyv = new KeyvBrotli();
120+
// @ts-expect-error - Testing empty value
121+
const deserialized = await keyv.deserialize('');
122+
123+
// @ts-expect-error - empty value
124+
t.is(deserialized, '');
125+
});

0 commit comments

Comments
 (0)