@keyv/compress-brotli 1.1.5 → 2.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2021 Luke Childs
4
+ Copyright (c) 2021-2022 Jared Wray
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @keyv/compress-brotli [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwra/keyv)
1
+ # @keyv/compress-brotli [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)
2
2
 
3
3
  > Brotli compression for Keyv
4
4
 
@@ -20,8 +20,8 @@ npm install --save keyv @keyv/compress-brotli
20
20
  ## Usage
21
21
 
22
22
  ```javascript
23
- const KeyvBrotli = require('@keyv/compress-brotli');
24
- const Keyv = require('keyv');
23
+ import Keyv from 'keyv';
24
+ import KeyvBrotli from '@keyv/compress-brotli';
25
25
 
26
26
  const keyv = new Keyv({store: new Map(), compression: new KeyvBrotli()});
27
27
 
@@ -33,8 +33,8 @@ const keyv = new Keyv({store: new Map(), compression: new KeyvBrotli()});
33
33
 
34
34
  #### options
35
35
 
36
- All options for @keyv/compress-brotli are based on the package [compress-brotli](https://github.com/Kikobeats/compress-brotli)
36
+ All options for `@keyv/compress-brotli` are based on the package [compress-brotli](https://github.com/Kikobeats/compress-brotli)
37
37
 
38
38
  ## License
39
39
 
40
- MIT © Jared Wray
40
+ [MIT © Jared Wray](LICENSE)
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
1
  import type { BrotliOptions, InputType } from 'node:zlib';
3
- import type { CompressResult, Options, SerializeResult, Serialize } from './types';
2
+ import type { CompressResult, Options, SerializeResult, Serialize } from './types.js';
4
3
  declare class KeyvBrotli {
5
4
  private readonly brotli;
6
5
  constructor(options?: Options);
@@ -9,4 +8,4 @@ declare class KeyvBrotli {
9
8
  serialize({ value, expires }: Serialize): Promise<SerializeResult>;
10
9
  deserialize(data: CompressResult): Promise<Serialize>;
11
10
  }
12
- export = KeyvBrotli;
11
+ export default KeyvBrotli;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const compress_brotli_1 = __importDefault(require("compress-brotli"));
7
+ const serialize_1 = require("@keyv/serialize");
8
+ class KeyvBrotli {
9
+ brotli;
10
+ constructor(options) {
11
+ this.brotli = (0, compress_brotli_1.default)(options);
12
+ }
13
+ async compress(value, options) {
14
+ return this.brotli.compress(value, options);
15
+ }
16
+ async decompress(data, options) {
17
+ return await this.brotli.decompress(data, options);
18
+ }
19
+ async serialize({ value, expires }) {
20
+ return (0, serialize_1.defaultSerialize)({ value: await this.compress(value), expires });
21
+ }
22
+ async deserialize(data) {
23
+ const { value, expires } = (0, serialize_1.defaultDeserialize)(data);
24
+ return { value: await this.decompress(value), expires };
25
+ }
26
+ }
27
+ exports.default = KeyvBrotli;
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AACA,sEAA6C;AAC7C,+CAAqE;AAKrE,MAAM,UAAU;IACE,MAAM,CAAS;IAChC,YAAY,OAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAA,yBAAc,EAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAU,EAAE,OAAuB;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,UAAU,CAAI,IAAe,EAAE,OAAuB;QAC3D,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAM,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,OAAO,EAAY;QAC1C,OAAO,IAAA,4BAAgB,EAAC,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAoB;QACrC,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAc,IAAA,8BAAkB,EAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;IACvD,CAAC;CACD;AAED,kBAAe,UAAU,CAAC"}
@@ -1,10 +1,8 @@
1
- /// <reference types="node" />
2
1
  import type { BrotliOptions, CompressCallback, InputType } from 'node:zlib';
3
- import type { parse as JSONBparse, stringify as JSONBstringify } from 'json-buffer';
4
2
  export type CompressResult = Promise<Parameters<CompressCallback>[1]>;
5
- export type DecompressResult = Promise<ReturnType<typeof JSONBparse>>;
6
- export type SerializeResult = ReturnType<typeof JSONBstringify>;
7
- export type DeserializeResult = ReturnType<typeof JSONBparse>;
3
+ export type DecompressResult = Promise<any>;
4
+ export type SerializeResult = string;
5
+ export type DeserializeResult = any;
8
6
  type BrotliSerialize<T> = (source: InputType) => T;
9
7
  type BrotliDeserialize<T> = (source: CompressResult) => T;
10
8
  export type Serialize = {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { BrotliOptions, InputType } from 'node:zlib';
2
+ import type { CompressResult, Options, SerializeResult, Serialize } from './types.js';
3
+ declare class KeyvBrotli {
4
+ private readonly brotli;
5
+ constructor(options?: Options);
6
+ compress(value: any, options?: BrotliOptions): CompressResult;
7
+ decompress<T>(data: InputType, options?: BrotliOptions): Promise<T>;
8
+ serialize({ value, expires }: Serialize): Promise<SerializeResult>;
9
+ deserialize(data: CompressResult): Promise<Serialize>;
10
+ }
11
+ export default KeyvBrotli;
@@ -0,0 +1,23 @@
1
+ import compressBrotli from 'compress-brotli';
2
+ import { defaultDeserialize, defaultSerialize } from '@keyv/serialize';
3
+ class KeyvBrotli {
4
+ brotli;
5
+ constructor(options) {
6
+ this.brotli = compressBrotli(options);
7
+ }
8
+ async compress(value, options) {
9
+ return this.brotli.compress(value, options);
10
+ }
11
+ async decompress(data, options) {
12
+ return await this.brotli.decompress(data, options);
13
+ }
14
+ async serialize({ value, expires }) {
15
+ return defaultSerialize({ value: await this.compress(value), expires });
16
+ }
17
+ async deserialize(data) {
18
+ const { value, expires } = defaultDeserialize(data);
19
+ return { value: await this.decompress(value), expires };
20
+ }
21
+ }
22
+ export default KeyvBrotli;
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,kBAAkB,EAAE,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAKrE,MAAM,UAAU;IACE,MAAM,CAAS;IAChC,YAAY,OAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAU,EAAE,OAAuB;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,UAAU,CAAI,IAAe,EAAE,OAAuB;QAC3D,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAM,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,OAAO,EAAY;QAC1C,OAAO,gBAAgB,CAAC,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAoB;QACrC,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAc,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;IACvD,CAAC;CACD;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { BrotliOptions, CompressCallback, InputType } from 'node:zlib';
2
+ export type CompressResult = Promise<Parameters<CompressCallback>[1]>;
3
+ export type DecompressResult = Promise<any>;
4
+ export type SerializeResult = string;
5
+ export type DeserializeResult = any;
6
+ type BrotliSerialize<T> = (source: InputType) => T;
7
+ type BrotliDeserialize<T> = (source: CompressResult) => T;
8
+ export type Serialize = {
9
+ value: InputType;
10
+ expires?: number;
11
+ };
12
+ export interface Options {
13
+ compressOptions?: BrotliOptions;
14
+ decompressOptions?: BrotliOptions;
15
+ enable?: boolean;
16
+ serialize?: any;
17
+ deserialize?: any;
18
+ iltorb?: any;
19
+ }
20
+ export interface Brotli {
21
+ serialize: BrotliSerialize<SerializeResult>;
22
+ deserialize: BrotliDeserialize<DeserializeResult>;
23
+ compress: (data: InputType, options?: BrotliOptions) => CompressResult;
24
+ decompress: (data: InputType, options?: BrotliOptions) => DecompressResult;
25
+ }
26
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,32 +1,31 @@
1
1
  {
2
2
  "name": "@keyv/compress-brotli",
3
- "version": "1.1.5",
3
+ "version": "2.0.0",
4
4
  "description": "brotli compression for keyv",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/cjs/index.js",
11
+ "import": "./dist/esm/index.js"
12
+ }
13
+ },
7
14
  "scripts": {
8
- "build": "tsc --project tsconfig.dist.json",
15
+ "build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
9
16
  "prepare": "yarn build",
10
- "test": "xo && c8 ava --serial",
11
- "test:ci": "xo && ava --serial",
17
+ "test": "xo --fix && vitest run --coverage",
18
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
12
19
  "clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite && rm -rf ./dist && rm -rf ./.nyc_output"
13
20
  },
14
21
  "xo": {
15
22
  "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
23
+ "unicorn/prefer-module": "off",
24
+ "@typescript-eslint/no-unsafe-call": "off",
25
+ "@typescript-eslint/consistent-type-definitions": "off",
26
+ "@typescript-eslint/no-unsafe-argument": "off",
27
+ "import/extensions": "off",
28
+ "import/no-extraneous-dependencies": "off"
30
29
  }
31
30
  },
32
31
  "repository": {
@@ -52,32 +51,23 @@
52
51
  },
53
52
  "homepage": "https://github.com/jaredwray/keyv",
54
53
  "dependencies": {
55
- "compress-brotli": "^1.3.11"
54
+ "compress-brotli": "^1.3.12",
55
+ "keyv": "^5.0.0",
56
+ "@keyv/serialize": "*"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@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.88.2"
60
+ "c8": "^10.1.2",
61
+ "xo": "^0.59.3"
65
62
  },
66
63
  "tsd": {
67
64
  "directory": "test"
68
65
  },
69
66
  "engines": {
70
- "node": ">= 12"
67
+ "node": ">= 18"
71
68
  },
72
69
  "files": [
73
- "dist"
74
- ],
75
- "ava": {
76
- "extensions": [
77
- "ts"
78
- ],
79
- "require": [
80
- "ts-node/register"
81
- ]
82
- }
70
+ "dist",
71
+ "LICENSE"
72
+ ]
83
73
  }
package/dist/index.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- const compress_brotli_1 = __importDefault(require("compress-brotli"));
15
- class KeyvBrotli {
16
- constructor(options) {
17
- this.brotli = (0, compress_brotli_1.default)(options);
18
- }
19
- compress(value, options) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- return this.brotli.compress(value, options);
22
- });
23
- }
24
- decompress(data, options) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return yield this.brotli.decompress(data, options);
27
- });
28
- }
29
- serialize({ value, expires }) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const compressValue = yield this.compress(value);
32
- // @ts-expect-error - `expires` is not part of the `SerializeResult` type
33
- return this.brotli.serialize({ value: compressValue, expires });
34
- });
35
- }
36
- deserialize(data) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
39
- if (!data) {
40
- return data;
41
- }
42
- const { value, expires } = this.brotli.deserialize(data);
43
- return { value: yield this.decompress(value), expires };
44
- });
45
- }
46
- }
47
- module.exports = KeyvBrotli;
48
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,sEAA6C;AAG7C,MAAM,UAAU;IAEf,YAAY,OAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAA,yBAAc,EAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAEK,QAAQ,CAAC,KAAU,EAAE,OAAuB;;YACjD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;KAAA;IAEK,UAAU,CAAI,IAAe,EAAE,OAAuB;;YAC3D,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAM,CAAC;QACzD,CAAC;KAAA;IAEK,SAAS,CAAC,EAAC,KAAK,EAAE,OAAO,EAAY;;YAC1C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjD,yEAAyE;YACzE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAC,CAAC,CAAC;QAC/D,CAAC;KAAA;IAEK,WAAW,CAAC,IAAoB;;YACrC,kEAAkE;YAClE,IAAI,CAAC,IAAI,EAAE;gBACV,OAAO,IAAI,CAAC;aACZ;YAED,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAc,CAAC;YACpE,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;QACvD,CAAC;KAAA;CACD;AAED,iBAAS,UAAU,CAAC"}
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
File without changes