@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.
- package/dist/adapter/cachedb/cache.db.js +2 -1
- package/dist/adapter/cachedb/cache.db.model.d.ts +1 -1
- package/dist/adapter/file/file.db.js +2 -1
- package/dist/adapter/file/file.db.model.d.ts +1 -1
- package/dist/commondao/common.dao.js +2 -1
- package/dist/commondao/common.dao.model.d.ts +1 -1
- package/dist/commondao/commonDaoTransaction.js +1 -1
- package/dist/inmemory/inMemory.db.d.ts +1 -1
- package/dist/inmemory/inMemory.db.js +2 -1
- package/dist/kv/commonKeyValueDao.d.ts +5 -1
- package/dist/kv/commonKeyValueDao.js +13 -3
- package/package.json +1 -1
- package/src/adapter/cachedb/cache.db.model.ts +1 -1
- package/src/adapter/cachedb/cache.db.ts +2 -1
- package/src/adapter/file/file.db.model.ts +1 -1
- package/src/adapter/file/file.db.ts +2 -1
- package/src/commondao/common.dao.model.ts +1 -1
- package/src/commondao/common.dao.ts +2 -1
- package/src/commondao/commonDaoTransaction.ts +1 -1
- package/src/inmemory/inMemory.db.ts +3 -2
- package/src/kv/commonKeyValueDao.ts +15 -4
|
@@ -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:
|
|
21
|
+
logger: consoleLogger,
|
|
21
22
|
...cfg,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
@@ -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:
|
|
40
|
+
logger: consoleLogger,
|
|
40
41
|
...cfg,
|
|
41
42
|
};
|
|
42
43
|
}
|
|
@@ -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:
|
|
36
|
+
logger: consoleLogger,
|
|
36
37
|
...cfg,
|
|
37
38
|
hooks: {
|
|
38
39
|
parseNaturalId: () => ({}),
|
|
@@ -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:
|
|
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
|
|
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:
|
|
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,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:
|
|
35
|
+
logger: consoleLogger,
|
|
35
36
|
...cfg,
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -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:
|
|
54
|
+
logger: consoleLogger,
|
|
54
55
|
...cfg,
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -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:
|
|
79
|
+
logger: consoleLogger,
|
|
79
80
|
...cfg,
|
|
80
81
|
hooks: {
|
|
81
82
|
parseNaturalId: () => ({}),
|
|
@@ -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 `
|
|
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:
|
|
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
|
|
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:
|
|
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
|
})
|