@naturalcycles/db-lib 10.36.0 → 10.37.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.
@@ -33,6 +33,11 @@ export interface CommonKeyValueDaoTransformer<V> {
33
33
  }
34
34
  export declare const commonKeyValueDaoDeflatedJsonTransformer: CommonKeyValueDaoTransformer<any>;
35
35
  export declare const commonKeyValueDaoZstdJsonTransformer: CommonKeyValueDaoTransformer<any>;
36
+ /**
37
+ * Saves: zstd
38
+ * Reads: zstd or deflate (backwards compatible)
39
+ */
40
+ export declare const commonKeyValueDaoCompressedTransformer: CommonKeyValueDaoTransformer<any>;
36
41
  export declare class CommonKeyValueDao<K extends string = string, V = Buffer> {
37
42
  constructor(cfg: CommonKeyValueDaoCfg<V>);
38
43
  cfg: CommonKeyValueDaoCfg<V> & {
@@ -1,7 +1,7 @@
1
1
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
2
2
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
3
3
  import { SKIP } from '@naturalcycles/js-lib/types';
4
- import { deflateString, inflateToString, zstdCompress, zstdDecompressToString, } from '@naturalcycles/nodejs-lib/zip';
4
+ import { decompressZstdOrInflateToString, deflateString, inflateToString, zstdCompress, zstdDecompressToString, } from '@naturalcycles/nodejs-lib/zip';
5
5
  export const commonKeyValueDaoDeflatedJsonTransformer = {
6
6
  valueToBuffer: async (v) => await deflateString(JSON.stringify(v)),
7
7
  bufferToValue: async (buf) => JSON.parse(await inflateToString(buf)),
@@ -10,6 +10,14 @@ export const commonKeyValueDaoZstdJsonTransformer = {
10
10
  valueToBuffer: async (v) => await zstdCompress(JSON.stringify(v)),
11
11
  bufferToValue: async (buf) => JSON.parse(await zstdDecompressToString(buf)),
12
12
  };
13
+ /**
14
+ * Saves: zstd
15
+ * Reads: zstd or deflate (backwards compatible)
16
+ */
17
+ export const commonKeyValueDaoCompressedTransformer = {
18
+ valueToBuffer: async (v) => await zstdCompress(JSON.stringify(v)),
19
+ bufferToValue: async (buf) => JSON.parse(await decompressZstdOrInflateToString(buf)),
20
+ };
13
21
  // todo: logging
14
22
  // todo: readonly
15
23
  export class CommonKeyValueDao {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.36.0",
4
+ "version": "10.37.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
8
8
  },
9
9
  "devDependencies": {
10
- "@naturalcycles/dev-lib": "18.4.2"
10
+ "@naturalcycles/dev-lib": "20.15.0"
11
11
  },
12
12
  "files": [
13
13
  "dist",
@@ -4,6 +4,7 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
4
4
  import { type KeyValueTuple, SKIP } from '@naturalcycles/js-lib/types'
5
5
  import type { Pipeline } from '@naturalcycles/nodejs-lib/stream'
6
6
  import {
7
+ decompressZstdOrInflateToString,
7
8
  deflateString,
8
9
  inflateToString,
9
10
  zstdCompress,
@@ -64,6 +65,15 @@ export const commonKeyValueDaoZstdJsonTransformer: CommonKeyValueDaoTransformer<
64
65
  bufferToValue: async buf => JSON.parse(await zstdDecompressToString(buf)),
65
66
  }
66
67
 
68
+ /**
69
+ * Saves: zstd
70
+ * Reads: zstd or deflate (backwards compatible)
71
+ */
72
+ export const commonKeyValueDaoCompressedTransformer: CommonKeyValueDaoTransformer<any> = {
73
+ valueToBuffer: async v => await zstdCompress(JSON.stringify(v)),
74
+ bufferToValue: async buf => JSON.parse(await decompressZstdOrInflateToString(buf)),
75
+ }
76
+
67
77
  // todo: logging
68
78
  // todo: readonly
69
79