@keyv/compress-brotli 1.1.6 → 2.0.1

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)
package/dist/index.cjs ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ KeyvBrotli: () => KeyvBrotli,
34
+ default: () => src_default
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_compress_brotli = __toESM(require("compress-brotli"), 1);
38
+ var import_serialize = require("@keyv/serialize");
39
+ var KeyvBrotli = class {
40
+ brotli;
41
+ constructor(options) {
42
+ this.brotli = (0, import_compress_brotli.default)(options);
43
+ }
44
+ async compress(value, options) {
45
+ return this.brotli.compress(value, options);
46
+ }
47
+ async decompress(data, options) {
48
+ return await this.brotli.decompress(data, options);
49
+ }
50
+ async serialize({ value, expires }) {
51
+ return (0, import_serialize.defaultSerialize)({ value: await this.compress(value), expires });
52
+ }
53
+ async deserialize(data) {
54
+ const { value, expires } = (0, import_serialize.defaultDeserialize)(data);
55
+ return { value: await this.decompress(value), expires };
56
+ }
57
+ };
58
+ var src_default = KeyvBrotli;
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ KeyvBrotli
62
+ });
@@ -0,0 +1,27 @@
1
+ import { CompressCallback, InputType, BrotliOptions } from 'node:zlib';
2
+
3
+ type CompressResult = Promise<Parameters<CompressCallback>[1]>;
4
+ type SerializeResult = string;
5
+ type Serialize = {
6
+ value: InputType;
7
+ expires?: number;
8
+ };
9
+ interface Options {
10
+ compressOptions?: BrotliOptions;
11
+ decompressOptions?: BrotliOptions;
12
+ enable?: boolean;
13
+ serialize?: any;
14
+ deserialize?: any;
15
+ iltorb?: any;
16
+ }
17
+
18
+ declare class KeyvBrotli {
19
+ private readonly brotli;
20
+ constructor(options?: Options);
21
+ compress(value: any, options?: BrotliOptions): CompressResult;
22
+ decompress<T>(data: InputType, options?: BrotliOptions): Promise<T>;
23
+ serialize({ value, expires }: Serialize): Promise<SerializeResult>;
24
+ deserialize(data: CompressResult): Promise<Serialize>;
25
+ }
26
+
27
+ export { KeyvBrotli, KeyvBrotli as default };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
- /// <reference types="node" />
2
- import type { BrotliOptions, InputType } from 'node:zlib';
3
- import type { CompressResult, Options, SerializeResult, Serialize } from './types';
1
+ import { CompressCallback, InputType, BrotliOptions } from 'node:zlib';
2
+
3
+ type CompressResult = Promise<Parameters<CompressCallback>[1]>;
4
+ type SerializeResult = string;
5
+ type Serialize = {
6
+ value: InputType;
7
+ expires?: number;
8
+ };
9
+ interface Options {
10
+ compressOptions?: BrotliOptions;
11
+ decompressOptions?: BrotliOptions;
12
+ enable?: boolean;
13
+ serialize?: any;
14
+ deserialize?: any;
15
+ iltorb?: any;
16
+ }
17
+
4
18
  declare class KeyvBrotli {
5
19
  private readonly brotli;
6
20
  constructor(options?: Options);
@@ -9,4 +23,5 @@ declare class KeyvBrotli {
9
23
  serialize({ value, expires }: Serialize): Promise<SerializeResult>;
10
24
  deserialize(data: CompressResult): Promise<Serialize>;
11
25
  }
12
- export = KeyvBrotli;
26
+
27
+ export { KeyvBrotli, KeyvBrotli as default };
package/dist/index.js CHANGED
@@ -1,48 +1,27 @@
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
- });
1
+ // src/index.ts
2
+ import compressBrotli from "compress-brotli";
3
+ import { defaultDeserialize, defaultSerialize } from "@keyv/serialize";
4
+ var KeyvBrotli = class {
5
+ brotli;
6
+ constructor(options) {
7
+ this.brotli = compressBrotli(options);
8
+ }
9
+ async compress(value, options) {
10
+ return this.brotli.compress(value, options);
11
+ }
12
+ async decompress(data, options) {
13
+ return await this.brotli.decompress(data, options);
14
+ }
15
+ async serialize({ value, expires }) {
16
+ return defaultSerialize({ value: await this.compress(value), expires });
17
+ }
18
+ async deserialize(data) {
19
+ const { value, expires } = defaultDeserialize(data);
20
+ return { value: await this.decompress(value), expires };
21
+ }
10
22
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ var src_default = KeyvBrotli;
24
+ export {
25
+ KeyvBrotli,
26
+ src_default as default
13
27
  };
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/package.json CHANGED
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "name": "@keyv/compress-brotli",
3
- "version": "1.1.6",
3
+ "version": "2.0.1",
4
4
  "description": "brotli compression for keyv",
5
- "main": "dist/index.js",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
6
8
  "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
7
15
  "scripts": {
8
- "build": "tsc --project tsconfig.dist.json",
16
+ "build": "rm -rf dist && tsup src/index.ts --format cjs,esm --dts --clean",
9
17
  "prepare": "yarn build",
10
- "test": "xo && c8 ava --serial",
11
- "test:ci": "xo && ava --serial",
18
+ "test": "xo --fix && vitest run --coverage",
19
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
12
20
  "clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite && rm -rf ./dist && rm -rf ./.nyc_output"
13
21
  },
14
22
  "xo": {
15
23
  "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
24
+ "import/no-named-as-default": "off",
25
+ "unicorn/prefer-module": "off",
26
+ "@typescript-eslint/no-unsafe-call": "off",
27
+ "@typescript-eslint/consistent-type-definitions": "off",
28
+ "@typescript-eslint/no-unsafe-argument": "off",
29
+ "import/extensions": "off",
30
+ "import/no-extraneous-dependencies": "off"
30
31
  }
31
32
  },
32
33
  "repository": {
@@ -52,32 +53,23 @@
52
53
  },
53
54
  "homepage": "https://github.com/jaredwray/keyv",
54
55
  "dependencies": {
55
- "compress-brotli": "^1.3.12"
56
+ "compress-brotli": "^1.3.12",
57
+ "keyv": "^5.0.0",
58
+ "@keyv/serialize": "*"
56
59
  },
57
60
  "devDependencies": {
58
61
  "@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"
62
+ "c8": "^10.1.2",
63
+ "xo": "^0.59.3"
65
64
  },
66
65
  "tsd": {
67
66
  "directory": "test"
68
67
  },
69
68
  "engines": {
70
- "node": ">= 12"
69
+ "node": ">= 18"
71
70
  },
72
71
  "files": [
73
- "dist"
74
- ],
75
- "ava": {
76
- "extensions": [
77
- "ts"
78
- ],
79
- "require": [
80
- "ts-node/register"
81
- ]
82
- }
72
+ "dist",
73
+ "LICENSE"
74
+ ]
83
75
  }
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.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /// <reference types="node" />
2
- import type { BrotliOptions, CompressCallback, InputType } from 'node:zlib';
3
- import type { parse as JSONBparse, stringify as JSONBstringify } from 'json-buffer';
4
- 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>;
8
- type BrotliSerialize<T> = (source: InputType) => T;
9
- type BrotliDeserialize<T> = (source: CompressResult) => T;
10
- export type Serialize = {
11
- value: InputType;
12
- expires?: number;
13
- };
14
- export interface Options {
15
- compressOptions?: BrotliOptions;
16
- decompressOptions?: BrotliOptions;
17
- enable?: boolean;
18
- serialize?: any;
19
- deserialize?: any;
20
- iltorb?: any;
21
- }
22
- export interface Brotli {
23
- serialize: BrotliSerialize<SerializeResult>;
24
- deserialize: BrotliDeserialize<DeserializeResult>;
25
- compress: (data: InputType, options?: BrotliOptions) => CompressResult;
26
- decompress: (data: InputType, options?: BrotliOptions) => DecompressResult;
27
- }
28
- export {};
package/dist/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}