@keyv/compress-gzip 1.1.3 → 1.2.3

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.
@@ -0,0 +1,13 @@
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 ADDED
@@ -0,0 +1,32 @@
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 });
25
+ }
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,27 +1,33 @@
1
1
  {
2
2
  "name": "@keyv/compress-gzip",
3
- "version": "1.1.3",
3
+ "version": "1.2.3",
4
4
  "description": "gzip compression for keyv",
5
- "main": "src/index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "scripts": {
7
- "test": "xo && c8 ava --serial",
8
- "test:ci": "xo && ava --serial",
9
- "clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite"
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"
10
14
  },
11
15
  "xo": {
12
16
  "rules": {
13
17
  "unicorn/prefer-module": 0,
14
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,
15
23
  "unicorn/prefer-logical-operator-over-ternary": 0
16
24
  }
17
25
  },
18
26
  "ava": {
19
27
  "require": [
20
- "requirable",
21
28
  "ts-node/register"
22
29
  ],
23
30
  "extensions": [
24
- "js",
25
31
  "ts"
26
32
  ]
27
33
  },
@@ -53,25 +59,26 @@
53
59
  "pako": "^2.1.0"
54
60
  },
55
61
  "devDependencies": {
62
+ "@ava/typescript": "^3.0.1",
56
63
  "@keyv/test-suite": "*",
57
64
  "@types/keyv": "^3.1.4",
65
+ "@typescript-eslint/parser": "^5.48.0",
58
66
  "ava": "^5.1.0",
59
67
  "c8": "^7.12.0",
60
68
  "keyv": "*",
61
69
  "requirable": "^1.0.5",
62
70
  "ts-node": "^10.9.1",
63
71
  "tsd": "^0.25.0",
64
- "typescript": "^4.9.3",
72
+ "typescript": "^4.9.4",
65
73
  "xo": "^0.53.1"
66
74
  },
67
75
  "tsd": {
68
76
  "directory": "test"
69
77
  },
70
- "types": "./src/index.d.ts",
71
78
  "engines": {
72
79
  "node": ">= 12"
73
80
  },
74
81
  "files": [
75
- "src"
82
+ "dist"
76
83
  ]
77
84
  }
package/src/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import type pako from 'pako';
2
-
3
- declare class KeyvGzip {
4
- opts: any;
5
- constructor(options?: pako.DeflateFunctionOptions | pako.InflateFunctionOptions);
6
- compress(value: pako.Data | string, options?: pako.DeflateFunctionOptions): Promise<Uint8Array>;
7
- decompress(value: pako.Data, options?: pako.InflateFunctionOptions & {to: 'string'}): Promise<string>;
8
- decompress(value: pako.Data, options?: pako.InflateFunctionOptions): Promise<Uint8Array>;
9
- serialize(value: any): Promise<any>;
10
- deserialize(value: any): Promise<any>;
11
- }
12
-
13
- export = KeyvGzip;
package/src/index.js DELETED
@@ -1,30 +0,0 @@
1
- const pako = require('pako');
2
- const JSONB = require('json-buffer');
3
-
4
- class KeyvGzip {
5
- constructor(options) {
6
- this.opts = {
7
- to: 'string',
8
- ...options,
9
- };
10
- }
11
-
12
- async compress(value, options) {
13
- return pako.deflate(value, options ? options : this.opts);
14
- }
15
-
16
- async decompress(value, options) {
17
- return pako.inflate(value, options ? options : this.opts);
18
- }
19
-
20
- async serialize({value, expires}) {
21
- return JSONB.stringify({value: await this.compress(value, this.opts), expires});
22
- }
23
-
24
- async deserialize(data) {
25
- const {value, expires} = JSONB.parse(data);
26
- return {value: await this.decompress(value, this.opts), expires};
27
- }
28
- }
29
-
30
- module.exports = KeyvGzip;