@naturalcycles/db-lib 10.57.0 → 10.58.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.
@@ -31,6 +31,10 @@ export interface CommonKeyValueDaoTransformer<V> {
31
31
  valueToBuffer: (v: V) => Buffer;
32
32
  bufferToValue: (buf: Buffer) => V;
33
33
  }
34
+ /**
35
+ * Plain JSON, no compression. For small values, where compressing would cost more than it saves.
36
+ */
37
+ export declare function commonKeyValueDaoJsonTransformer<T = any>(): CommonKeyValueDaoTransformer<T>;
34
38
  /**
35
39
  * @deprecated use zstd instead, gzip is obsolete
36
40
  */
@@ -2,6 +2,15 @@ import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
2
2
  import { consoleLogger } from '@naturalcycles/js-lib/log';
3
3
  import { SKIP } from '@naturalcycles/js-lib/types';
4
4
  import { zip2 } from '@naturalcycles/nodejs-lib/zip';
5
+ /**
6
+ * Plain JSON, no compression. For small values, where compressing would cost more than it saves.
7
+ */
8
+ export function commonKeyValueDaoJsonTransformer() {
9
+ return {
10
+ valueToBuffer: v => Buffer.from(JSON.stringify(v)),
11
+ bufferToValue: buf => JSON.parse(buf.toString()),
12
+ };
13
+ }
5
14
  /**
6
15
  * @deprecated use zstd instead, gzip is obsolete
7
16
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.57.0",
4
+ "version": "10.58.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -50,6 +50,16 @@ export interface CommonKeyValueDaoTransformer<V> {
50
50
  bufferToValue: (buf: Buffer) => V
51
51
  }
52
52
 
53
+ /**
54
+ * Plain JSON, no compression. For small values, where compressing would cost more than it saves.
55
+ */
56
+ export function commonKeyValueDaoJsonTransformer<T = any>(): CommonKeyValueDaoTransformer<T> {
57
+ return {
58
+ valueToBuffer: v => Buffer.from(JSON.stringify(v)),
59
+ bufferToValue: buf => JSON.parse(buf.toString()),
60
+ }
61
+ }
62
+
53
63
  /**
54
64
  * @deprecated use zstd instead, gzip is obsolete
55
65
  */