@keyv/compress-gzip 1.2.3 → 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-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)
package/dist/index.cjs ADDED
@@ -0,0 +1,68 @@
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
+ KeyvGzip: () => KeyvGzip,
34
+ default: () => src_default
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_pako = __toESM(require("pako"), 1);
38
+ var import_serialize = require("@keyv/serialize");
39
+ var KeyvGzip = class {
40
+ opts;
41
+ constructor(options) {
42
+ this.opts = {
43
+ to: "string",
44
+ ...options
45
+ };
46
+ }
47
+ async compress(value, options) {
48
+ return import_pako.default.deflate(value, options || this.opts);
49
+ }
50
+ async decompress(value, options) {
51
+ if (options) {
52
+ options.to = "string";
53
+ }
54
+ return import_pako.default.inflate(value, options || this.opts);
55
+ }
56
+ async serialize({ value, expires }) {
57
+ return (0, import_serialize.defaultSerialize)({ value: await this.compress(value), expires });
58
+ }
59
+ async deserialize(data) {
60
+ const { value, expires } = (0, import_serialize.defaultDeserialize)(data);
61
+ return { value: await this.decompress(value), expires };
62
+ }
63
+ };
64
+ var src_default = KeyvGzip;
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ KeyvGzip
68
+ });
@@ -0,0 +1,25 @@
1
+ import pako, { Data, DeflateFunctionOptions, InflateOptions } from 'pako';
2
+
3
+ type PakoDeflateOptions = DeflateFunctionOptions;
4
+ type PakoInflateOptions = InflateOptions & {
5
+ to?: 'string';
6
+ };
7
+ type Options = PakoDeflateOptions & PakoInflateOptions;
8
+ type Serialize = {
9
+ value: string | Data;
10
+ expires?: number;
11
+ };
12
+
13
+ declare class KeyvGzip {
14
+ opts: Options;
15
+ constructor(options?: Options);
16
+ compress(value: pako.Data | string, options?: Options): Promise<Uint8Array>;
17
+ decompress(value: pako.Data, options?: Options): Promise<Uint8Array>;
18
+ serialize({ value, expires }: Serialize): Promise<string>;
19
+ deserialize(data: string): Promise<{
20
+ value: Uint8Array;
21
+ expires: number | undefined;
22
+ }>;
23
+ }
24
+
25
+ export { KeyvGzip, KeyvGzip as default };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,25 @@
1
- import pako from 'pako';
1
+ import pako, { Data, DeflateFunctionOptions, InflateOptions } from 'pako';
2
+
3
+ type PakoDeflateOptions = DeflateFunctionOptions;
4
+ type PakoInflateOptions = InflateOptions & {
5
+ to?: 'string';
6
+ };
7
+ type Options = PakoDeflateOptions & PakoInflateOptions;
8
+ type Serialize = {
9
+ value: string | Data;
10
+ expires?: number;
11
+ };
12
+
2
13
  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;
14
+ opts: Options;
15
+ constructor(options?: Options);
16
+ compress(value: pako.Data | string, options?: Options): Promise<Uint8Array>;
17
+ decompress(value: pako.Data, options?: Options): Promise<Uint8Array>;
18
+ serialize({ value, expires }: Serialize): Promise<string>;
19
+ deserialize(data: string): Promise<{
20
+ value: Uint8Array;
21
+ expires: number | undefined;
11
22
  }>;
12
23
  }
13
- export = KeyvGzip;
24
+
25
+ export { KeyvGzip, KeyvGzip as default };
package/dist/index.js CHANGED
@@ -1,32 +1,33 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const pako_1 = __importDefault(require("pako"));
6
- const json_buffer_1 = __importDefault(require("json-buffer"));
7
- class KeyvGzip {
8
- constructor(options) {
9
- this.opts = {
10
- to: 'string',
11
- ...options,
12
- };
13
- }
14
- async compress(value, options) {
15
- return pako_1.default.deflate(value, options || this.opts);
16
- }
17
- async decompress(value, options) {
18
- if (options) {
19
- options.to = 'string';
20
- }
21
- return pako_1.default.inflate(value, options || this.opts);
22
- }
23
- async serialize({ value, expires }) {
24
- return json_buffer_1.default.stringify({ value: await this.compress(value), expires });
1
+ // src/index.ts
2
+ import pako from "pako";
3
+ import { defaultSerialize, defaultDeserialize } from "@keyv/serialize";
4
+ var KeyvGzip = class {
5
+ opts;
6
+ constructor(options) {
7
+ this.opts = {
8
+ to: "string",
9
+ ...options
10
+ };
11
+ }
12
+ async compress(value, options) {
13
+ return pako.deflate(value, options || this.opts);
14
+ }
15
+ async decompress(value, options) {
16
+ if (options) {
17
+ options.to = "string";
25
18
  }
26
- async deserialize(data) {
27
- const { value, expires } = json_buffer_1.default.parse(data);
28
- return { value: await this.decompress(value), expires };
29
- }
30
- }
31
- module.exports = KeyvGzip;
32
- //# sourceMappingURL=index.js.map
19
+ return pako.inflate(value, options || this.opts);
20
+ }
21
+ async serialize({ value, expires }) {
22
+ return defaultSerialize({ value: await this.compress(value), expires });
23
+ }
24
+ async deserialize(data) {
25
+ const { value, expires } = defaultDeserialize(data);
26
+ return { value: await this.decompress(value), expires };
27
+ }
28
+ };
29
+ var src_default = KeyvGzip;
30
+ export {
31
+ KeyvGzip,
32
+ src_default as default
33
+ };
package/package.json CHANGED
@@ -1,36 +1,33 @@
1
1
  {
2
2
  "name": "@keyv/compress-gzip",
3
- "version": "1.2.3",
3
+ "version": "2.0.1",
4
4
  "description": "gzip 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
- "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"
16
+ "build": "rm -rf dist && tsup src/index.ts --format cjs,esm --dts --clean",
17
+ "prepare": "yarn build",
18
+ "test": "xo --fix && vitest run --coverage",
19
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
20
+ "clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf ./dist && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
14
21
  },
15
22
  "xo": {
16
23
  "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
24
+ "import/no-named-as-default": "off",
25
+ "import/extensions": "off",
26
+ "@typescript-eslint/prefer-nullish-coalescing": "off",
27
+ "@typescript-eslint/no-unsafe-argument": "off",
28
+ "import/no-extraneous-dependencies": "off"
24
29
  }
25
30
  },
26
- "ava": {
27
- "require": [
28
- "ts-node/register"
29
- ],
30
- "extensions": [
31
- "ts"
32
- ]
33
- },
34
31
  "repository": {
35
32
  "type": "git",
36
33
  "url": "git+https://github.com/jaredwray/keyv.git"
@@ -54,31 +51,23 @@
54
51
  },
55
52
  "homepage": "https://github.com/jaredwray/keyv",
56
53
  "dependencies": {
57
- "@types/pako": "^2.0.0",
58
- "json-buffer": "^3.0.1",
59
- "pako": "^2.1.0"
54
+ "@types/pako": "^2.0.3",
55
+ "pako": "^2.1.0",
56
+ "@keyv/serialize": "*"
60
57
  },
61
58
  "devDependencies": {
62
- "@ava/typescript": "^3.0.1",
63
59
  "@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"
60
+ "tsd": "^0.31.1",
61
+ "xo": "^0.59.3"
74
62
  },
75
63
  "tsd": {
76
64
  "directory": "test"
77
65
  },
78
66
  "engines": {
79
- "node": ">= 12"
67
+ "node": ">= 18"
80
68
  },
81
69
  "files": [
82
- "dist"
70
+ "dist",
71
+ "LICENSE"
83
72
  ]
84
73
  }
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"}