@naturalcycles/db-lib 10.56.3 → 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.
@@ -1,4 +1,5 @@
1
1
  import { _isTruthy } from '@naturalcycles/js-lib';
2
+ import { consoleLogger } from '@naturalcycles/js-lib/log';
2
3
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
3
4
  import { BaseCommonDB } from '../../commondb/base.common.db.js';
4
5
  import { commonDBFullSupport } from '../../commondb/common.db.js';
@@ -17,7 +18,7 @@ export class CacheDB extends BaseCommonDB {
17
18
  constructor(cfg) {
18
19
  super();
19
20
  this.cfg = {
20
- logger: console,
21
+ logger: consoleLogger,
21
22
  ...cfg,
22
23
  };
23
24
  }
@@ -34,7 +34,7 @@ export interface CacheDBCfg {
34
34
  */
35
35
  logDownstream?: boolean;
36
36
  /**
37
- * Defaults to `console`.
37
+ * Defaults to `consoleLogger`.
38
38
  */
39
39
  logger?: CommonLogger;
40
40
  }
@@ -2,6 +2,7 @@ import { Readable } from 'node:stream';
2
2
  import { _by, _sortBy } from '@naturalcycles/js-lib/array';
3
3
  import { _since, localTime } from '@naturalcycles/js-lib/datetime';
4
4
  import { _assert } from '@naturalcycles/js-lib/error/assert.js';
5
+ import { consoleLogger } from '@naturalcycles/js-lib/log';
5
6
  import { _deepEquals, _filterUndefinedValues, _sortObjectDeep } from '@naturalcycles/js-lib/object';
6
7
  import { _stringMapValues } from '@naturalcycles/js-lib/types';
7
8
  import { generateJsonSchemaFromData } from '@naturalcycles/nodejs-lib/ajv';
@@ -36,7 +37,7 @@ export class FileDB extends BaseCommonDB {
36
37
  this.cfg = {
37
38
  sortObjects: true,
38
39
  logFinished: true,
39
- logger: console,
40
+ logger: consoleLogger,
40
41
  ...cfg,
41
42
  };
42
43
  }
@@ -20,7 +20,7 @@ export interface FileDBCfg {
20
20
  */
21
21
  sortObjects?: boolean;
22
22
  /**
23
- * Defaults to `console`.
23
+ * Defaults to `consoleLogger`.
24
24
  */
25
25
  logger?: CommonLogger;
26
26
  /**
@@ -2,6 +2,7 @@ import { _isTruthy } from '@naturalcycles/js-lib';
2
2
  import { _uniqBy } from '@naturalcycles/js-lib/array/array.util.js';
3
3
  import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
4
4
  import { _assert, ErrorMode } from '@naturalcycles/js-lib/error';
5
+ import { consoleLogger } from '@naturalcycles/js-lib/log';
5
6
  import { _deepJsonEquals } from '@naturalcycles/js-lib/object/deepEquals.js';
6
7
  import { _filterUndefinedValues, _objectAssignExact, _omitWithUndefined, _pick, } from '@naturalcycles/js-lib/object/object.util.js';
7
8
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
@@ -32,7 +33,7 @@ export class CommonDao {
32
33
  useUpdatedProperty: true,
33
34
  validateOnLoad: true,
34
35
  validateOnSave: true,
35
- logger: console,
36
+ logger: consoleLogger,
36
37
  ...cfg,
37
38
  hooks: {
38
39
  parseNaturalId: () => ({}),
@@ -129,7 +129,7 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
129
129
  */
130
130
  readOnly?: boolean;
131
131
  /**
132
- * Defaults to `console`
132
+ * Defaults to `consoleLogger`
133
133
  */
134
134
  logger?: CommonLogger;
135
135
  /**
@@ -27,7 +27,7 @@ export class CommonDaoTransaction {
27
27
  }
28
28
  catch (err) {
29
29
  // graceful rollback without re-throw
30
- this.logger.error(err);
30
+ this.logger.error({ err });
31
31
  }
32
32
  }
33
33
  async getById(dao, id, opt) {
@@ -26,7 +26,7 @@ export interface InMemoryDBCfg {
26
26
  */
27
27
  forbidTransactionReadAfterWrite?: boolean;
28
28
  /**
29
- * Defaults to `console`.
29
+ * Defaults to `consoleLogger`.
30
30
  */
31
31
  logger?: CommonLogger;
32
32
  }
@@ -1,5 +1,6 @@
1
1
  import { _isEmptyObject } from '@naturalcycles/js-lib';
2
2
  import { _assert } from '@naturalcycles/js-lib/error/assert.js';
3
+ import { consoleLogger } from '@naturalcycles/js-lib/log';
3
4
  import { _deepCopy, _sortObjectDeep } from '@naturalcycles/js-lib/object';
4
5
  import { _stringMapEntries, _stringMapValues } from '@naturalcycles/js-lib/types';
5
6
  import { generateJsonSchemaFromData } from '@naturalcycles/nodejs-lib/ajv';
@@ -17,7 +18,7 @@ export class InMemoryDB {
17
18
  // defaults
18
19
  tablesPrefix: '',
19
20
  forbidTransactionReadAfterWrite: true,
20
- logger: console,
21
+ logger: consoleLogger,
21
22
  ...cfg,
22
23
  };
23
24
  }
@@ -13,7 +13,7 @@ export interface CommonKeyValueDaoCfg<V> {
13
13
  */
14
14
  readOnly?: boolean;
15
15
  /**
16
- * Default to console
16
+ * Default to consoleLogger
17
17
  */
18
18
  logger?: CommonLogger;
19
19
  /**
@@ -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
  */
@@ -1,6 +1,16 @@
1
1
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
2
+ import { consoleLogger } from '@naturalcycles/js-lib/log';
2
3
  import { SKIP } from '@naturalcycles/js-lib/types';
3
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
+ }
4
14
  /**
5
15
  * @deprecated use zstd instead, gzip is obsolete
6
16
  */
@@ -31,7 +41,7 @@ export function commonKeyValueDaoCompressedTransformer() {
31
41
  export class CommonKeyValueDao {
32
42
  constructor(cfg) {
33
43
  this.cfg = {
34
- logger: console,
44
+ logger: consoleLogger,
35
45
  ...cfg,
36
46
  };
37
47
  }
@@ -118,7 +128,7 @@ export class CommonKeyValueDao {
118
128
  return transformer.bufferToValue(buf);
119
129
  }
120
130
  catch (err) {
121
- this.cfg.logger.error(err);
131
+ this.cfg.logger.error({ err });
122
132
  return SKIP;
123
133
  }
124
134
  });
@@ -133,7 +143,7 @@ export class CommonKeyValueDao {
133
143
  return [id, transformer.bufferToValue(buf)];
134
144
  }
135
145
  catch (err) {
136
- this.cfg.logger.error(err);
146
+ this.cfg.logger.error({ err });
137
147
  return SKIP;
138
148
  }
139
149
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.56.3",
4
+ "version": "10.58.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -46,7 +46,7 @@ export interface CacheDBCfg {
46
46
  logDownstream?: boolean
47
47
 
48
48
  /**
49
- * Defaults to `console`.
49
+ * Defaults to `consoleLogger`.
50
50
  */
51
51
  logger?: CommonLogger
52
52
  }
@@ -1,4 +1,5 @@
1
1
  import { _isTruthy } from '@naturalcycles/js-lib'
2
+ import { consoleLogger } from '@naturalcycles/js-lib/log'
2
3
  import type { ObjectWithId, StringMap } from '@naturalcycles/js-lib/types'
3
4
  import type { JsonSchema } from '@naturalcycles/nodejs-lib/ajv'
4
5
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
@@ -31,7 +32,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
31
32
  constructor(cfg: CacheDBCfg) {
32
33
  super()
33
34
  this.cfg = {
34
- logger: console,
35
+ logger: consoleLogger,
35
36
  ...cfg,
36
37
  }
37
38
  }
@@ -25,7 +25,7 @@ export interface FileDBCfg {
25
25
  sortObjects?: boolean
26
26
 
27
27
  /**
28
- * Defaults to `console`.
28
+ * Defaults to `consoleLogger`.
29
29
  */
30
30
  logger?: CommonLogger
31
31
 
@@ -2,6 +2,7 @@ import { Readable } from 'node:stream'
2
2
  import { _by, _sortBy } from '@naturalcycles/js-lib/array'
3
3
  import { _since, localTime } from '@naturalcycles/js-lib/datetime'
4
4
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
5
+ import { consoleLogger } from '@naturalcycles/js-lib/log'
5
6
  import { _deepEquals, _filterUndefinedValues, _sortObjectDeep } from '@naturalcycles/js-lib/object'
6
7
  import { _stringMapValues } from '@naturalcycles/js-lib/types'
7
8
  import type { ObjectWithId, UnixTimestampMillis } from '@naturalcycles/js-lib/types'
@@ -50,7 +51,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
50
51
  this.cfg = {
51
52
  sortObjects: true,
52
53
  logFinished: true,
53
- logger: console,
54
+ logger: consoleLogger,
54
55
  ...cfg,
55
56
  }
56
57
  }
@@ -156,7 +156,7 @@ export interface CommonDaoCfg<
156
156
  readOnly?: boolean
157
157
 
158
158
  /**
159
- * Defaults to `console`
159
+ * Defaults to `consoleLogger`
160
160
  */
161
161
  logger?: CommonLogger
162
162
 
@@ -2,6 +2,7 @@ import { _isTruthy } from '@naturalcycles/js-lib'
2
2
  import { _uniqBy } from '@naturalcycles/js-lib/array/array.util.js'
3
3
  import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
4
4
  import { _assert, ErrorMode } from '@naturalcycles/js-lib/error'
5
+ import { consoleLogger } from '@naturalcycles/js-lib/log'
5
6
  import { _deepJsonEquals } from '@naturalcycles/js-lib/object/deepEquals.js'
6
7
  import {
7
8
  _filterUndefinedValues,
@@ -75,7 +76,7 @@ export class CommonDao<
75
76
  useUpdatedProperty: true,
76
77
  validateOnLoad: true,
77
78
  validateOnSave: true,
78
- logger: console,
79
+ logger: consoleLogger,
79
80
  ...cfg,
80
81
  hooks: {
81
82
  parseNaturalId: () => ({}),
@@ -37,7 +37,7 @@ export class CommonDaoTransaction {
37
37
  await this.tx.rollback()
38
38
  } catch (err) {
39
39
  // graceful rollback without re-throw
40
- this.logger.error(err)
40
+ this.logger.error({ err })
41
41
  }
42
42
  }
43
43
 
@@ -1,5 +1,6 @@
1
1
  import { _isEmptyObject } from '@naturalcycles/js-lib'
2
2
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
3
+ import { consoleLogger } from '@naturalcycles/js-lib/log'
3
4
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
4
5
  import { _deepCopy, _sortObjectDeep } from '@naturalcycles/js-lib/object'
5
6
  import { _stringMapEntries, _stringMapValues } from '@naturalcycles/js-lib/types'
@@ -49,7 +50,7 @@ export interface InMemoryDBCfg {
49
50
  forbidTransactionReadAfterWrite?: boolean
50
51
 
51
52
  /**
52
- * Defaults to `console`.
53
+ * Defaults to `consoleLogger`.
53
54
  */
54
55
  logger?: CommonLogger
55
56
  }
@@ -67,7 +68,7 @@ export class InMemoryDB implements CommonDB {
67
68
  // defaults
68
69
  tablesPrefix: '',
69
70
  forbidTransactionReadAfterWrite: true,
70
- logger: console,
71
+ logger: consoleLogger,
71
72
  ...cfg,
72
73
  }
73
74
  }
@@ -1,4 +1,5 @@
1
1
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
2
+ import { consoleLogger } from '@naturalcycles/js-lib/log'
2
3
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
3
4
  import { SKIP } from '@naturalcycles/js-lib/types'
4
5
  import type { Integer, KeyValueTuple } from '@naturalcycles/js-lib/types'
@@ -25,7 +26,7 @@ export interface CommonKeyValueDaoCfg<V> {
25
26
  readOnly?: boolean
26
27
 
27
28
  /**
28
- * Default to console
29
+ * Default to consoleLogger
29
30
  */
30
31
  logger?: CommonLogger
31
32
 
@@ -49,6 +50,16 @@ export interface CommonKeyValueDaoTransformer<V> {
49
50
  bufferToValue: (buf: Buffer) => V
50
51
  }
51
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
+
52
63
  /**
53
64
  * @deprecated use zstd instead, gzip is obsolete
54
65
  */
@@ -87,7 +98,7 @@ export function commonKeyValueDaoCompressedTransformer<T = any>(): CommonKeyValu
87
98
  export class CommonKeyValueDao<K extends string = string, V = Buffer> {
88
99
  constructor(cfg: CommonKeyValueDaoCfg<V>) {
89
100
  this.cfg = {
90
- logger: console,
101
+ logger: consoleLogger,
91
102
  ...cfg,
92
103
  }
93
104
  }
@@ -198,7 +209,7 @@ export class CommonKeyValueDao<K extends string = string, V = Buffer> {
198
209
  try {
199
210
  return transformer.bufferToValue(buf)
200
211
  } catch (err) {
201
- this.cfg.logger.error(err)
212
+ this.cfg.logger.error({ err })
202
213
  return SKIP
203
214
  }
204
215
  })
@@ -215,7 +226,7 @@ export class CommonKeyValueDao<K extends string = string, V = Buffer> {
215
226
  try {
216
227
  return [id as K, transformer.bufferToValue(buf)]
217
228
  } catch (err) {
218
- this.cfg.logger.error(err)
229
+ this.cfg.logger.error({ err })
219
230
  return SKIP
220
231
  }
221
232
  })