Comparing version 4.5.0 to 4.5.1
{ | ||
"name": "keyv", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "Simple key-value storage with support for multiple backends", | ||
@@ -14,3 +14,4 @@ "main": "src/index.js", | ||
"unicorn/prefer-module": 0, | ||
"unicorn/prefer-node-protocol": 0 | ||
"unicorn/prefer-node-protocol": 0, | ||
"@typescript-eslint/consistent-type-definitions": 0 | ||
} | ||
@@ -40,5 +41,5 @@ }, | ||
"@keyv/test-suite": "*", | ||
"ava": "^4.3.0", | ||
"eslint": "^8.19.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"ava": "^5.0.1", | ||
"eslint": "^8.26.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"nyc": "^15.1.0", | ||
@@ -48,5 +49,5 @@ "pify": "5.0.0", | ||
"timekeeper": "^2.2.0", | ||
"tsd": "^0.22.0", | ||
"typescript": "^4.7.4", | ||
"xo": "^0.51.0" | ||
"tsd": "^0.24.1", | ||
"typescript": "^4.8.4", | ||
"xo": "^0.52.4" | ||
}, | ||
@@ -53,0 +54,0 @@ "tsd": { |
@@ -198,3 +198,3 @@ <h1 align="center"> | ||
const keyvGzip = new KeyvGzip();; | ||
const keyvGzip = new KeyvGzip(); | ||
const keyv = new Keyv({ compression: KeyvGzip }); | ||
@@ -205,2 +205,24 @@ ``` | ||
### Want to build your own? | ||
Great! Keyv is designed to be easily extended. You can build your own compression adapter by following the pattern of the official compression adapters based on this interface: | ||
```typescript | ||
interface CompressionAdapter { | ||
async compress(value: any, options?: any); | ||
async decompress(value: any, options?: any); | ||
async serialize(value: any); | ||
async deserialize(value: any); | ||
} | ||
``` | ||
In addition to the interface, you can test it with our compression test suite using @keyv/test-suite: | ||
```js | ||
const {keyvCompresstionTests} = require('@keyv/test-suite'); | ||
const KeyvGzip = require('@keyv/compress-gzip'); | ||
keyvCompresstionTests(test, new KeyvGzip()); | ||
``` | ||
## API | ||
@@ -207,0 +229,0 @@ |
@@ -88,5 +88,12 @@ import {EventEmitter} from 'events'; | ||
/** Enable compression option **/ | ||
compress?: Record<string, unknown> | undefined; | ||
compression?: CompressionAdapter | undefined; | ||
} | ||
interface CompressionAdapter { | ||
async compress(value: any, options?: any); | ||
async decompress(value: any, options?: any); | ||
async serialize(value: any); | ||
async deserialize(value: any); | ||
} | ||
interface DeserializedData<Value> { | ||
@@ -93,0 +100,0 @@ value: Value; expires: number | undefined; |
@@ -55,5 +55,4 @@ 'use strict'; | ||
const compression = this.opts.compression; | ||
const {serialize, deserialize} = compression.opts; | ||
this.opts.serialize = serialize; | ||
this.opts.deserialize = deserialize; | ||
this.opts.serialize = compression.serialize.bind(compression); | ||
this.opts.deserialize = compression.deserialize.bind(compression); | ||
} | ||
@@ -123,3 +122,3 @@ | ||
.then(() => store.get(key)) | ||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data) | ||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data)) | ||
.then(data => { | ||
@@ -152,3 +151,3 @@ if (data === undefined || data === null) { | ||
.then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)) | ||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data) | ||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data)) | ||
.then(data => { | ||
@@ -155,0 +154,0 @@ if (data === undefined || data === null) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27436
323
428