@keyv/compress-brotli 2.0.5 → 6.0.0-alpha.2

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/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -34,21 +24,49 @@ __export(index_exports, {
34
24
  default: () => index_default
35
25
  });
36
26
  module.exports = __toCommonJS(index_exports);
37
- var import_compress_brotli = __toESM(require("compress-brotli"), 1);
27
+ var import_node_util = require("util");
28
+ var import_node_zlib = require("zlib");
38
29
  var import_serialize = require("@keyv/serialize");
30
+ var brotliCompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliCompress);
31
+ var brotliDecompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliDecompress);
39
32
  var KeyvBrotli = class {
40
- brotli;
33
+ _enable;
34
+ _compressOptions;
35
+ _decompressOptions;
36
+ // biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
37
+ _serialize;
38
+ // biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
39
+ _deserialize;
41
40
  constructor(options) {
42
- this.brotli = (0, import_compress_brotli.default)(options);
41
+ this._enable = options?.enable ?? true;
42
+ this._compressOptions = options?.compressOptions;
43
+ this._decompressOptions = options?.decompressOptions;
44
+ this._serialize = options?.serialize ?? import_serialize.defaultSerialize;
45
+ this._deserialize = options?.deserialize ?? import_serialize.defaultDeserialize;
43
46
  }
47
+ // biome-ignore lint/suspicious/noExplicitAny: needed for this type
44
48
  async compress(value, options) {
45
- return this.brotli.compress(value, options);
49
+ if (!this._enable) {
50
+ return value;
51
+ }
52
+ const serializedData = this._serialize(value);
53
+ return brotliCompressAsync(serializedData, {
54
+ ...this._compressOptions,
55
+ ...options
56
+ });
46
57
  }
47
58
  async decompress(data, options) {
48
- if (data) {
49
- return await this.brotli.decompress(data, options);
59
+ if (!data) {
60
+ return void 0;
61
+ }
62
+ if (!this._enable) {
63
+ return data;
50
64
  }
51
- return void 0;
65
+ const decompressedBuffer = await brotliDecompressAsync(data, {
66
+ ...this._decompressOptions,
67
+ ...options
68
+ });
69
+ return this._deserialize(decompressedBuffer);
52
70
  }
53
71
  async serialize({ value, expires }) {
54
72
  return (0, import_serialize.defaultSerialize)({ value: await this.compress(value), expires });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { BrotliOptions, CompressCallback, InputType } from 'node:zlib';
1
+ import { BrotliOptions, InputType } from 'node:zlib';
2
2
 
3
- type CompressResult = Promise<Parameters<CompressCallback>[1]>;
3
+ type CompressResult = Promise<any>;
4
4
  type SerializeResult = string;
5
5
  type Serialize = {
6
6
  value?: InputType;
@@ -10,13 +10,16 @@ type Options = {
10
10
  compressOptions?: BrotliOptions;
11
11
  decompressOptions?: BrotliOptions;
12
12
  enable?: boolean;
13
- serialize?: any;
14
- deserialize?: any;
15
- iltorb?: any;
13
+ serialize?: (value: any) => any;
14
+ deserialize?: (data: any) => any;
16
15
  };
17
16
 
18
17
  declare class KeyvBrotli {
19
- private readonly brotli;
18
+ private readonly _enable;
19
+ private readonly _compressOptions?;
20
+ private readonly _decompressOptions?;
21
+ private readonly _serialize;
22
+ private readonly _deserialize;
20
23
  constructor(options?: Options);
21
24
  compress(value: any, options?: BrotliOptions): CompressResult;
22
25
  decompress<T>(data?: InputType, options?: BrotliOptions): Promise<T>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { BrotliOptions, CompressCallback, InputType } from 'node:zlib';
1
+ import { BrotliOptions, InputType } from 'node:zlib';
2
2
 
3
- type CompressResult = Promise<Parameters<CompressCallback>[1]>;
3
+ type CompressResult = Promise<any>;
4
4
  type SerializeResult = string;
5
5
  type Serialize = {
6
6
  value?: InputType;
@@ -10,13 +10,16 @@ type Options = {
10
10
  compressOptions?: BrotliOptions;
11
11
  decompressOptions?: BrotliOptions;
12
12
  enable?: boolean;
13
- serialize?: any;
14
- deserialize?: any;
15
- iltorb?: any;
13
+ serialize?: (value: any) => any;
14
+ deserialize?: (data: any) => any;
16
15
  };
17
16
 
18
17
  declare class KeyvBrotli {
19
- private readonly brotli;
18
+ private readonly _enable;
19
+ private readonly _compressOptions?;
20
+ private readonly _decompressOptions?;
21
+ private readonly _serialize;
22
+ private readonly _deserialize;
20
23
  constructor(options?: Options);
21
24
  compress(value: any, options?: BrotliOptions): CompressResult;
22
25
  decompress<T>(data?: InputType, options?: BrotliOptions): Promise<T>;
package/dist/index.js CHANGED
@@ -1,19 +1,50 @@
1
1
  // src/index.ts
2
- import compressBrotli from "compress-brotli";
2
+ import { promisify } from "util";
3
+ import {
4
+ brotliCompress,
5
+ brotliDecompress
6
+ } from "zlib";
3
7
  import { defaultDeserialize, defaultSerialize } from "@keyv/serialize";
8
+ var brotliCompressAsync = promisify(brotliCompress);
9
+ var brotliDecompressAsync = promisify(brotliDecompress);
4
10
  var KeyvBrotli = class {
5
- brotli;
11
+ _enable;
12
+ _compressOptions;
13
+ _decompressOptions;
14
+ // biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
15
+ _serialize;
16
+ // biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
17
+ _deserialize;
6
18
  constructor(options) {
7
- this.brotli = compressBrotli(options);
19
+ this._enable = options?.enable ?? true;
20
+ this._compressOptions = options?.compressOptions;
21
+ this._decompressOptions = options?.decompressOptions;
22
+ this._serialize = options?.serialize ?? defaultSerialize;
23
+ this._deserialize = options?.deserialize ?? defaultDeserialize;
8
24
  }
25
+ // biome-ignore lint/suspicious/noExplicitAny: needed for this type
9
26
  async compress(value, options) {
10
- return this.brotli.compress(value, options);
27
+ if (!this._enable) {
28
+ return value;
29
+ }
30
+ const serializedData = this._serialize(value);
31
+ return brotliCompressAsync(serializedData, {
32
+ ...this._compressOptions,
33
+ ...options
34
+ });
11
35
  }
12
36
  async decompress(data, options) {
13
- if (data) {
14
- return await this.brotli.decompress(data, options);
37
+ if (!data) {
38
+ return void 0;
39
+ }
40
+ if (!this._enable) {
41
+ return data;
15
42
  }
16
- return void 0;
43
+ const decompressedBuffer = await brotliDecompressAsync(data, {
44
+ ...this._decompressOptions,
45
+ ...options
46
+ });
47
+ return this._deserialize(decompressedBuffer);
17
48
  }
18
49
  async serialize({ value, expires }) {
19
50
  return defaultSerialize({ value: await this.compress(value), expires });
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@keyv/compress-brotli",
3
- "version": "2.0.5",
3
+ "version": "6.0.0-alpha.2",
4
4
  "description": "brotli compression for keyv",
5
5
  "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "require": "./dist/index.cjs",
12
- "import": "./dist/index.js"
13
- }
14
- },
15
- "xo": {
16
- "rules": {
17
- "@typescript-eslint/no-unsafe-assignment": 0
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
18
19
  }
19
20
  },
20
21
  "repository": {
@@ -40,19 +41,17 @@
40
41
  },
41
42
  "homepage": "https://github.com/jaredwray/keyv",
42
43
  "dependencies": {
43
- "compress-brotli": "^1.3.13",
44
- "@keyv/serialize": "^1.0.3"
44
+ "@keyv/serialize": "^6.0.0-alpha.2"
45
45
  },
46
46
  "peerDependencies": {
47
- "keyv": "^5.3.4"
47
+ "keyv": "^6.0.0-alpha.2"
48
48
  },
49
49
  "devDependencies": {
50
- "@vitest/coverage-v8": "^3.2.3",
51
- "c8": "^10.1.3",
52
- "rimraf": "^6.0.1",
53
- "vitest": "^3.2.3",
54
- "xo": "^1.1.0",
55
- "@keyv/test-suite": "^2.0.8"
50
+ "@biomejs/biome": "^2.3.13",
51
+ "@vitest/coverage-v8": "^4.0.18",
52
+ "rimraf": "^6.1.2",
53
+ "vitest": "^4.0.18",
54
+ "@keyv/test-suite": "^6.0.0-alpha.2"
56
55
  },
57
56
  "tsd": {
58
57
  "directory": "test"
@@ -66,8 +65,10 @@
66
65
  ],
67
66
  "scripts": {
68
67
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
69
- "test": "xo --fix && vitest run --coverage",
70
- "test:ci": "xo && vitest --run --sequence.setupFiles=list",
68
+ "lint": "biome check --write --error-on-warnings",
69
+ "lint:ci": "biome check --error-on-warnings",
70
+ "test": "pnpm lint && vitest run --coverage",
71
+ "test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
71
72
  "clean": "rimraf ./node_modules ./coverage ./test/testdb.sqlite ./dist"
72
73
  }
73
74
  }