@keyv/compress-gzip 1.2.3 → 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-gzip [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwray/keyv)
1
+ # @keyv/compress-gzip [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)
2
2
 
3
3
  > Gzip compression for Keyv
4
4
 
@@ -18,8 +18,8 @@ npm install --save keyv @keyv/compress-gzip
18
18
  ## Usage
19
19
 
20
20
  ```javascript
21
- const KeyvGzip = require('@keyv/compress-gzip');
22
- const Keyv = require('keyv');
21
+ import Keyv from 'keyv';
22
+ import KeyvGzip from '@keyv/compress-gzip';
23
23
 
24
24
  const keyv = new Keyv({store: new Map(), compression: new KeyvGzip()});
25
25
 
@@ -31,8 +31,8 @@ const keyv = new Keyv({store: new Map(), compression: new KeyvGzip()});
31
31
 
32
32
  #### options
33
33
 
34
- All options for @keyv/compress-gzip are based on the package [compress-gzip](https://github.com/nodeca/pako#readme)
34
+ All options for `@keyv/compress-gzip` are based on the package [compress-gzip](https://github.com/nodeca/pako#readme)
35
35
 
36
36
  ## License
37
37
 
38
- MIT © Jared Wray
38
+ [MIT © Jared Wray](LICENSE)
@@ -0,0 +1,14 @@
1
+ import pako from 'pako';
2
+ import type { Options, Serialize } from './types.js';
3
+ declare class KeyvGzip {
4
+ opts: Options;
5
+ constructor(options?: Options);
6
+ compress(value: pako.Data | string, options?: Options): Promise<Uint8Array>;
7
+ decompress(value: pako.Data, options?: Options): Promise<Uint8Array>;
8
+ serialize({ value, expires }: Serialize): Promise<string>;
9
+ deserialize(data: string): Promise<{
10
+ value: Uint8Array;
11
+ expires: number | undefined;
12
+ }>;
13
+ }
14
+ export default KeyvGzip;
@@ -2,9 +2,11 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
5
6
  const pako_1 = __importDefault(require("pako"));
6
- const json_buffer_1 = __importDefault(require("json-buffer"));
7
+ const serialize_1 = require("@keyv/serialize");
7
8
  class KeyvGzip {
9
+ opts;
8
10
  constructor(options) {
9
11
  this.opts = {
10
12
  to: 'string',
@@ -21,12 +23,12 @@ class KeyvGzip {
21
23
  return pako_1.default.inflate(value, options || this.opts);
22
24
  }
23
25
  async serialize({ value, expires }) {
24
- return json_buffer_1.default.stringify({ value: await this.compress(value), expires });
26
+ return (0, serialize_1.defaultSerialize)({ value: await this.compress(value), expires });
25
27
  }
26
28
  async deserialize(data) {
27
- const { value, expires } = json_buffer_1.default.parse(data);
29
+ const { value, expires } = (0, serialize_1.defaultDeserialize)(data);
28
30
  return { value: await this.decompress(value), expires };
29
31
  }
30
32
  }
31
- module.exports = KeyvGzip;
33
+ exports.default = KeyvGzip;
32
34
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,+CAAqE;AAGrE,MAAM,QAAQ;IACb,IAAI,CAAU;IACd,YAAY,OAAiB;QAC5B,IAAI,CAAC,IAAI,GAAG;YACX,EAAE,EAAE,QAAQ;YACZ,GAAG,OAAO;SACV,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyB,EAAE,OAAiB;QAC1D,OAAO,cAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAgB,EAAE,OAAiB;QACnD,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC;QACvB,CAAC;QAED,OAAO,cAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,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,IAAY;QAC7B,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAc,IAAA,8BAAkB,EAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAkB,CAAC,EAAE,OAAO,EAAC,CAAC;IACpE,CAAC;CACD;AAED,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Data, DeflateFunctionOptions, InflateOptions } from 'pako';
2
+ type PakoDeflateOptions = DeflateFunctionOptions;
3
+ type PakoInflateOptions = InflateOptions & {
4
+ to?: 'string';
5
+ };
6
+ export type Options = PakoDeflateOptions & PakoInflateOptions;
7
+ export type Serialize = {
8
+ value: string | Data;
9
+ expires?: number;
10
+ };
11
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import pako from 'pako';
2
+ import type { Options, Serialize } from './types.js';
3
+ declare class KeyvGzip {
4
+ opts: Options;
5
+ constructor(options?: Options);
6
+ compress(value: pako.Data | string, options?: Options): Promise<Uint8Array>;
7
+ decompress(value: pako.Data, options?: Options): Promise<Uint8Array>;
8
+ serialize({ value, expires }: Serialize): Promise<string>;
9
+ deserialize(data: string): Promise<{
10
+ value: Uint8Array;
11
+ expires: number | undefined;
12
+ }>;
13
+ }
14
+ export default KeyvGzip;
@@ -0,0 +1,29 @@
1
+ import pako from 'pako';
2
+ import { defaultSerialize, defaultDeserialize } from '@keyv/serialize';
3
+ class KeyvGzip {
4
+ opts;
5
+ constructor(options) {
6
+ this.opts = {
7
+ to: 'string',
8
+ ...options,
9
+ };
10
+ }
11
+ async compress(value, options) {
12
+ return pako.deflate(value, options || this.opts);
13
+ }
14
+ async decompress(value, options) {
15
+ if (options) {
16
+ options.to = 'string';
17
+ }
18
+ return pako.inflate(value, options || this.opts);
19
+ }
20
+ async serialize({ value, expires }) {
21
+ return defaultSerialize({ value: await this.compress(value), expires });
22
+ }
23
+ async deserialize(data) {
24
+ const { value, expires } = defaultDeserialize(data);
25
+ return { value: await this.decompress(value), expires };
26
+ }
27
+ }
28
+ export default KeyvGzip;
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGrE,MAAM,QAAQ;IACb,IAAI,CAAU;IACd,YAAY,OAAiB;QAC5B,IAAI,CAAC,IAAI,GAAG;YACX,EAAE,EAAE,QAAQ;YACZ,GAAG,OAAO;SACV,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyB,EAAE,OAAiB;QAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAgB,EAAE,OAAiB;QACnD,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,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,IAAY;QAC7B,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAc,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAkB,CAAC,EAAE,OAAO,EAAC,CAAC;IACpE,CAAC;CACD;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Data, DeflateFunctionOptions, InflateOptions } from 'pako';
2
+ type PakoDeflateOptions = DeflateFunctionOptions;
3
+ type PakoInflateOptions = InflateOptions & {
4
+ to?: 'string';
5
+ };
6
+ export type Options = PakoDeflateOptions & PakoInflateOptions;
7
+ export type Serialize = {
8
+ value: string | Data;
9
+ expires?: number;
10
+ };
11
+ 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,36 +1,31 @@
1
1
  {
2
2
  "name": "@keyv/compress-gzip",
3
- "version": "1.2.3",
3
+ "version": "2.0.0",
4
4
  "description": "gzip 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
- "test": "xo && yarn run build && c8 ava --serial",
9
- "test:ci": "xo && yarn run build && ava --serial",
10
- "prepare": "yarn run build",
11
- "build": "tsc",
12
- "coverage": "nyc report --reporter=text-lcov > coverage.lcov",
13
- "clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
15
+ "build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
16
+ "prepare": "yarn build",
17
+ "test": "xo --fix && vitest run --coverage",
18
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
19
+ "clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf ./dist && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
14
20
  },
15
21
  "xo": {
16
22
  "rules": {
17
- "unicorn/prefer-module": 0,
18
- "unicorn/prefer-node-protocol": 0,
19
- "@typescript-eslint/no-unsafe-assignment": 0,
20
- "@typescript-eslint/no-var-requires": 0,
21
- "@typescript-eslint/no-require-imports": 0,
22
- "@typescript-eslint/naming-convention": 0,
23
- "unicorn/prefer-logical-operator-over-ternary": 0
23
+ "import/extensions": "off",
24
+ "@typescript-eslint/prefer-nullish-coalescing": "off",
25
+ "@typescript-eslint/no-unsafe-argument": "off",
26
+ "import/no-extraneous-dependencies": "off"
24
27
  }
25
28
  },
26
- "ava": {
27
- "require": [
28
- "ts-node/register"
29
- ],
30
- "extensions": [
31
- "ts"
32
- ]
33
- },
34
29
  "repository": {
35
30
  "type": "git",
36
31
  "url": "git+https://github.com/jaredwray/keyv.git"
@@ -54,31 +49,23 @@
54
49
  },
55
50
  "homepage": "https://github.com/jaredwray/keyv",
56
51
  "dependencies": {
57
- "@types/pako": "^2.0.0",
58
- "json-buffer": "^3.0.1",
59
- "pako": "^2.1.0"
52
+ "@types/pako": "^2.0.3",
53
+ "pako": "^2.1.0",
54
+ "@keyv/serialize": "*"
60
55
  },
61
56
  "devDependencies": {
62
- "@ava/typescript": "^3.0.1",
63
57
  "@keyv/test-suite": "*",
64
- "@types/keyv": "^3.1.4",
65
- "@typescript-eslint/parser": "^5.48.0",
66
- "ava": "^5.1.0",
67
- "c8": "^7.12.0",
68
- "keyv": "*",
69
- "requirable": "^1.0.5",
70
- "ts-node": "^10.9.1",
71
- "tsd": "^0.25.0",
72
- "typescript": "^4.9.4",
73
- "xo": "^0.53.1"
58
+ "tsd": "^0.31.1",
59
+ "xo": "^0.59.3"
74
60
  },
75
61
  "tsd": {
76
62
  "directory": "test"
77
63
  },
78
64
  "engines": {
79
- "node": ">= 12"
65
+ "node": ">= 18"
80
66
  },
81
67
  "files": [
82
- "dist"
68
+ "dist",
69
+ "LICENSE"
83
70
  ]
84
71
  }
package/dist/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import pako from 'pako';
2
- declare class KeyvGzip {
3
- opts: any;
4
- constructor(options?: any);
5
- compress(value: pako.Data | string, options?: any): Promise<Uint8Array>;
6
- decompress(value: pako.Data, options?: any): Promise<string>;
7
- serialize({ value, expires }: any): Promise<string>;
8
- deserialize(data: any): Promise<{
9
- value: string;
10
- expires: any;
11
- }>;
12
- }
13
- export = KeyvGzip;
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,gDAAwB;AACxB,8DAAgC;AAEhC,MAAM,QAAQ;IAEb,YAAY,OAAa;QACxB,IAAI,CAAC,IAAI,GAAG;YACX,EAAE,EAAE,QAAQ;YACZ,GAAG,OAAO;SACV,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyB,EAAE,OAAa;QACtD,OAAO,cAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAgB,EAAE,OAAa;QAC/C,IAAI,OAAO,EAAE;YACZ,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC;SACtB;QAED,OAAO,cAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,OAAO,EAAM;QACpC,OAAO,qBAAK,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAS;QAC1B,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAG,qBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;IACvD,CAAC;CACD;AAED,iBAAS,QAAQ,CAAC"}