@naturalcycles/db-lib 8.43.4 → 8.43.5
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.d.ts +1 -1
- package/dist/adapter/cachedb/cache.db.js +2 -2
- package/dist/adapter/file/localFile.persistence.plugin.js +5 -5
- package/dist/adapter/inmemory/inMemory.db.js +6 -6
- package/dist/adapter/inmemory/inMemoryKeyValueDB.js +4 -4
- package/dist/base.common.db.js +2 -2
- package/dist/commondao/common.dao.js +9 -2
- package/dist/commondao/common.dao.model.d.ts +1 -1
- package/dist/db.model.d.ts +3 -3
- package/dist/kv/commonKeyValueDB.d.ts +1 -1
- package/dist/kv/commonKeyValueDao.js +10 -2
- package/dist/pipeline/dbPipelineBackup.d.ts +1 -1
- package/dist/pipeline/dbPipelineBackup.js +2 -2
- package/dist/pipeline/dbPipelineRestore.js +2 -2
- package/dist/query/dbQuery.d.ts +1 -1
- package/dist/timeseries/timeSeries.model.d.ts +1 -1
- package/package.json +1 -1
- package/src/adapter/cachedb/cache.db.ts +1 -1
- package/src/adapter/file/localFile.persistence.plugin.ts +2 -2
- package/src/adapter/inmemory/inMemory.db.ts +2 -2
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +1 -1
- package/src/base.common.db.ts +1 -1
- package/src/commondao/common.dao.ts +18 -10
- package/src/kv/commonKeyValueDao.ts +20 -10
- package/src/pipeline/dbPipelineBackup.ts +1 -1
- package/src/pipeline/dbPipelineRestore.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Readable } from 'stream';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
3
|
import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
4
4
|
import { BaseCommonDB } from '../../base.common.db';
|
|
5
5
|
import { CommonDB } from '../../common.db';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheDB = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
const base_common_db_1 = require("../../base.common.db");
|
|
6
6
|
/**
|
|
7
7
|
* CommonDB implementation that proxies requests to downstream CommonDB
|
|
@@ -160,7 +160,7 @@ class CacheDB extends base_common_db_1.BaseCommonDB {
|
|
|
160
160
|
return stream;
|
|
161
161
|
}
|
|
162
162
|
if (opt.skipCache || this.cfg.skipCache)
|
|
163
|
-
return
|
|
163
|
+
return node_stream_1.Readable.from([]);
|
|
164
164
|
const stream = this.cfg.cacheDB.streamQuery(q, opt);
|
|
165
165
|
// if (this.cfg.logCached) {
|
|
166
166
|
// let count = 0
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalFilePersistencePlugin = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
const node_zlib_1 = require("node:zlib");
|
|
6
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
const fs = require("fs-extra");
|
|
@@ -29,7 +29,7 @@ class LocalFilePersistencePlugin {
|
|
|
29
29
|
const filePath = `${this.cfg.storagePath}/${table}.${ext}`;
|
|
30
30
|
if (!(await fs.pathExists(filePath)))
|
|
31
31
|
return [];
|
|
32
|
-
const transformUnzip = this.cfg.gzip ? [(0,
|
|
32
|
+
const transformUnzip = this.cfg.gzip ? [(0, node_zlib_1.createUnzip)()] : [];
|
|
33
33
|
const rows = [];
|
|
34
34
|
await (0, nodejs_lib_1._pipeline)([
|
|
35
35
|
fs.createReadStream(filePath),
|
|
@@ -47,9 +47,9 @@ class LocalFilePersistencePlugin {
|
|
|
47
47
|
await fs.ensureDir(this.cfg.storagePath);
|
|
48
48
|
const ext = `ndjson${this.cfg.gzip ? '.gz' : ''}`;
|
|
49
49
|
const filePath = `${this.cfg.storagePath}/${table}.${ext}`;
|
|
50
|
-
const transformZip = this.cfg.gzip ? [(0,
|
|
50
|
+
const transformZip = this.cfg.gzip ? [(0, node_zlib_1.createGzip)()] : [];
|
|
51
51
|
await (0, nodejs_lib_1._pipeline)([
|
|
52
|
-
|
|
52
|
+
node_stream_1.Readable.from(rows),
|
|
53
53
|
(0, nodejs_lib_1.transformToNDJson)(),
|
|
54
54
|
...transformZip,
|
|
55
55
|
fs.createWriteStream(filePath),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryDB = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
const node_zlib_1 = require("node:zlib");
|
|
6
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
@@ -122,7 +122,7 @@ class InMemoryDB {
|
|
|
122
122
|
}
|
|
123
123
|
streamQuery(q, _opt) {
|
|
124
124
|
const table = this.cfg.tablesPrefix + q.table;
|
|
125
|
-
return
|
|
125
|
+
return node_stream_1.Readable.from((0, __1.queryInMemory)(q, Object.values(this.data[table] || {})));
|
|
126
126
|
}
|
|
127
127
|
async commitTransaction(tx, opt) {
|
|
128
128
|
const backup = (0, js_lib_1._deepCopy)(this.data);
|
|
@@ -156,7 +156,7 @@ class InMemoryDB {
|
|
|
156
156
|
const { persistentStoragePath, persistZip } = this.cfg;
|
|
157
157
|
const started = Date.now();
|
|
158
158
|
await fs.emptyDir(persistentStoragePath);
|
|
159
|
-
const transformZip = persistZip ? [(0,
|
|
159
|
+
const transformZip = persistZip ? [(0, node_zlib_1.createGzip)()] : [];
|
|
160
160
|
let tables = 0;
|
|
161
161
|
// infinite concurrency for now
|
|
162
162
|
await (0, js_lib_1.pMap)(Object.keys(this.data), async (table) => {
|
|
@@ -166,7 +166,7 @@ class InMemoryDB {
|
|
|
166
166
|
tables++;
|
|
167
167
|
const fname = `${persistentStoragePath}/${table}.ndjson${persistZip ? '.gz' : ''}`;
|
|
168
168
|
await (0, nodejs_lib_1._pipeline)([
|
|
169
|
-
|
|
169
|
+
node_stream_1.Readable.from(rows),
|
|
170
170
|
(0, nodejs_lib_1.transformToNDJson)(),
|
|
171
171
|
...transformZip,
|
|
172
172
|
fs.createWriteStream(fname),
|
|
@@ -190,7 +190,7 @@ class InMemoryDB {
|
|
|
190
190
|
await (0, js_lib_1.pMap)(files, async (file) => {
|
|
191
191
|
const fname = `${persistentStoragePath}/${file}`;
|
|
192
192
|
const table = file.split('.ndjson')[0];
|
|
193
|
-
const transformUnzip = file.endsWith('.gz') ? [(0,
|
|
193
|
+
const transformUnzip = file.endsWith('.gz') ? [(0, node_zlib_1.createUnzip)()] : [];
|
|
194
194
|
const rows = [];
|
|
195
195
|
await (0, nodejs_lib_1._pipeline)([
|
|
196
196
|
fs.createReadStream(fname),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryKeyValueDB = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
class InMemoryKeyValueDB {
|
|
6
6
|
constructor(cfg = {}) {
|
|
7
7
|
this.cfg = cfg;
|
|
@@ -26,13 +26,13 @@ class InMemoryKeyValueDB {
|
|
|
26
26
|
entries.forEach(([id, buf]) => (this.data[table][id] = buf));
|
|
27
27
|
}
|
|
28
28
|
streamIds(table, limit) {
|
|
29
|
-
return
|
|
29
|
+
return node_stream_1.Readable.from(Object.keys(this.data[table] || {}).slice(0, limit));
|
|
30
30
|
}
|
|
31
31
|
streamValues(table, limit) {
|
|
32
|
-
return
|
|
32
|
+
return node_stream_1.Readable.from(Object.values(this.data[table] || {}).slice(0, limit));
|
|
33
33
|
}
|
|
34
34
|
streamEntries(table, limit) {
|
|
35
|
-
return
|
|
35
|
+
return node_stream_1.Readable.from(Object.entries(this.data[table] || {}).slice(0, limit));
|
|
36
36
|
}
|
|
37
37
|
async count(table) {
|
|
38
38
|
var _a;
|
package/dist/base.common.db.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseCommonDB = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
const dbTransaction_util_1 = require("./transaction/dbTransaction.util");
|
|
6
6
|
/**
|
|
7
7
|
* No-op implementation of CommonDB interface.
|
|
@@ -39,7 +39,7 @@ class BaseCommonDB {
|
|
|
39
39
|
}
|
|
40
40
|
async saveBatch(_table, _rows, _opt) { }
|
|
41
41
|
streamQuery(_q) {
|
|
42
|
-
return
|
|
42
|
+
return node_stream_1.Readable.from([]);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Naive implementation.
|
|
@@ -407,7 +407,9 @@ class CommonDao {
|
|
|
407
407
|
const stream = this.cfg.db.streamQuery(q, opt);
|
|
408
408
|
if (partialQuery || opt.raw)
|
|
409
409
|
return stream;
|
|
410
|
-
return stream
|
|
410
|
+
return stream
|
|
411
|
+
.on('error', err => stream.emit('error', err))
|
|
412
|
+
.pipe((0, nodejs_lib_1.transformMapSimple)(dbm => this.anyToDBM(dbm, opt), {
|
|
411
413
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
412
414
|
}));
|
|
413
415
|
}
|
|
@@ -433,6 +435,7 @@ class CommonDao {
|
|
|
433
435
|
// optimization: 1 validation is enough
|
|
434
436
|
// .pipe(transformMap<any, DBM>(dbm => this.anyToDBM(dbm, opt), safeOpt))
|
|
435
437
|
// .pipe(transformMap<DBM, Saved<BM>>(dbm => this.dbmToBM(dbm, opt), safeOpt))
|
|
438
|
+
.on('error', err => stream.emit('error', err))
|
|
436
439
|
.pipe((0, nodejs_lib_1.transformMap)(async (dbm) => await this.dbmToBM(dbm, opt), {
|
|
437
440
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
438
441
|
}))
|
|
@@ -449,9 +452,13 @@ class CommonDao {
|
|
|
449
452
|
streamQueryIds(q, opt = {}) {
|
|
450
453
|
q.table = opt.table || q.table;
|
|
451
454
|
opt.errorMode || (opt.errorMode = js_lib_1.ErrorMode.SUPPRESS);
|
|
452
|
-
|
|
455
|
+
const stream = this.cfg.db
|
|
456
|
+
.streamQuery(q.select(['id']), opt)
|
|
457
|
+
.on('error', err => stream.emit('error', err))
|
|
458
|
+
.pipe((0, nodejs_lib_1.transformMapSimple)(objectWithId => objectWithId.id, {
|
|
453
459
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
454
460
|
}));
|
|
461
|
+
return stream;
|
|
455
462
|
}
|
|
456
463
|
async streamQueryIdsForEach(q, mapper, opt = {}) {
|
|
457
464
|
q.table = opt.table || q.table;
|
package/dist/db.model.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ObjectWithId } from '@naturalcycles/js-lib';
|
|
|
7
7
|
*
|
|
8
8
|
* Default is Upsert.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type CommonDBSaveMethod = 'upsert' | 'insert' | 'update';
|
|
11
11
|
export interface CommonDBOptions {
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -27,7 +27,7 @@ export interface CommonDBSaveOptions<ROW extends Partial<ObjectWithId> = any> ex
|
|
|
27
27
|
*/
|
|
28
28
|
assignGeneratedIds?: boolean;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type CommonDBStreamOptions = CommonDBOptions;
|
|
31
31
|
export interface CommonDBCreateOptions extends CommonDBOptions {
|
|
32
32
|
/**
|
|
33
33
|
* Caution! If set to true - will actually DROP the table!
|
|
@@ -40,7 +40,7 @@ export interface RunQueryResult<T> {
|
|
|
40
40
|
rows: T[];
|
|
41
41
|
endCursor?: string;
|
|
42
42
|
}
|
|
43
|
-
export
|
|
43
|
+
export type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation;
|
|
44
44
|
export interface DBSaveBatchOperation<ROW extends Partial<ObjectWithId> = any> {
|
|
45
45
|
type: 'saveBatch';
|
|
46
46
|
table: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDBCreateOptions } from '../db.model';
|
|
4
|
-
export
|
|
4
|
+
export type KeyValueDBTuple = [key: string, value: Buffer];
|
|
5
5
|
/**
|
|
6
6
|
* Common interface for Key-Value database implementations.
|
|
7
7
|
*
|
|
@@ -103,17 +103,25 @@ class CommonKeyValueDao {
|
|
|
103
103
|
}
|
|
104
104
|
// todo: consider it when readableMap supports `errorMode: SUPPRESS`
|
|
105
105
|
// readableMap(this.cfg.db.streamValues(this.cfg.table, limit), async buf => await this.cfg.hooks!.mapBufferToValue(buf))
|
|
106
|
-
|
|
106
|
+
const stream = this.cfg.db
|
|
107
|
+
.streamValues(this.cfg.table, limit)
|
|
108
|
+
.on('error', err => stream.emit('error', err))
|
|
109
|
+
.pipe((0, nodejs_lib_1.transformMap)(async (buf) => await this.cfg.hooks.mapBufferToValue(buf), {
|
|
107
110
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe cannot propagate errors
|
|
108
111
|
}));
|
|
112
|
+
return stream;
|
|
109
113
|
}
|
|
110
114
|
streamEntries(limit) {
|
|
111
115
|
if (!this.cfg.hooks?.mapBufferToValue) {
|
|
112
116
|
return this.cfg.db.streamEntries(this.cfg.table, limit);
|
|
113
117
|
}
|
|
114
|
-
|
|
118
|
+
const stream = this.cfg.db
|
|
119
|
+
.streamEntries(this.cfg.table, limit)
|
|
120
|
+
.on('error', err => stream.emit('error', err))
|
|
121
|
+
.pipe((0, nodejs_lib_1.transformMap)(async ([id, buf]) => [id, await this.cfg.hooks.mapBufferToValue(buf)], {
|
|
115
122
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe cannot propagate errors
|
|
116
123
|
}));
|
|
124
|
+
return stream;
|
|
117
125
|
}
|
|
118
126
|
}
|
|
119
127
|
exports.CommonKeyValueDao = CommonKeyValueDao;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ZlibOptions } from 'zlib';
|
|
2
|
+
import { ZlibOptions } from 'node:zlib';
|
|
3
3
|
import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib';
|
|
4
4
|
import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
5
5
|
import { CommonDB } from '../common.db';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dbPipelineBackup = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_zlib_1 = require("node:zlib");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
@@ -65,7 +65,7 @@ async function dbPipelineBackup(opt) {
|
|
|
65
65
|
rows++;
|
|
66
66
|
}),
|
|
67
67
|
(0, nodejs_lib_1.transformToNDJson)({ strict, sortObjects }),
|
|
68
|
-
...(gzip ? [(0,
|
|
68
|
+
...(gzip ? [(0, node_zlib_1.createGzip)(zlibOptions)] : []),
|
|
69
69
|
fs.createWriteStream(filePath),
|
|
70
70
|
]);
|
|
71
71
|
const { size: sizeBytes } = await fs.stat(filePath);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dbPipelineRestore = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_zlib_1 = require("node:zlib");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
@@ -68,7 +68,7 @@ async function dbPipelineRestore(opt) {
|
|
|
68
68
|
console.log(`<< ${(0, colors_1.grey)(filePath)} ${(0, colors_1.dimWhite)((0, js_lib_1._hb)(sizeBytes))} started...`);
|
|
69
69
|
await (0, nodejs_lib_1._pipeline)([
|
|
70
70
|
fs.createReadStream(filePath),
|
|
71
|
-
...(gzip ? [(0,
|
|
71
|
+
...(gzip ? [(0, node_zlib_1.createUnzip)()] : []),
|
|
72
72
|
(0, nodejs_lib_1.transformSplit)(),
|
|
73
73
|
(0, nodejs_lib_1.transformJsonParse)({ strict }),
|
|
74
74
|
(0, nodejs_lib_1.transformTap)(() => rows++),
|
package/dist/query/dbQuery.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { RunQueryResult } from '../db.model';
|
|
|
22
22
|
*
|
|
23
23
|
* You may also look at queryInMemory() for its implementation (it implements all those).
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type DBQueryFilterOperator = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
26
26
|
export declare const dbQueryFilterOperatorValues: DBQueryFilterOperator[];
|
|
27
27
|
export interface DBQueryFilter<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
28
28
|
name: keyof ROW;
|
|
@@ -7,7 +7,7 @@ export interface CommonTimeSeriesDaoCfg {
|
|
|
7
7
|
* Second number: value
|
|
8
8
|
* null in the second position means "absense of value" (may exist in _RAW table)
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type TimeSeriesDataPoint = [number, number | null];
|
|
11
11
|
export interface TimeSeriesRow {
|
|
12
12
|
id: number;
|
|
13
13
|
ts: number;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Readable } from 'stream'
|
|
2
|
-
import { createGzip, createUnzip } from 'zlib'
|
|
1
|
+
import { Readable } from 'node:stream'
|
|
2
|
+
import { createGzip, createUnzip } from 'node:zlib'
|
|
3
3
|
import { pMap, ObjectWithId } from '@naturalcycles/js-lib'
|
|
4
4
|
import {
|
|
5
5
|
transformJsonParse,
|
package/src/base.common.db.ts
CHANGED
|
@@ -498,11 +498,13 @@ export class CommonDao<
|
|
|
498
498
|
const stream = this.cfg.db.streamQuery<DBM>(q, opt)
|
|
499
499
|
if (partialQuery || opt.raw) return stream
|
|
500
500
|
|
|
501
|
-
return stream
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
501
|
+
return stream
|
|
502
|
+
.on('error', err => stream.emit('error', err))
|
|
503
|
+
.pipe(
|
|
504
|
+
transformMapSimple<any, DBM>(dbm => this.anyToDBM(dbm, opt), {
|
|
505
|
+
errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
506
|
+
}),
|
|
507
|
+
)
|
|
506
508
|
}
|
|
507
509
|
|
|
508
510
|
/**
|
|
@@ -529,6 +531,7 @@ export class CommonDao<
|
|
|
529
531
|
// optimization: 1 validation is enough
|
|
530
532
|
// .pipe(transformMap<any, DBM>(dbm => this.anyToDBM(dbm, opt), safeOpt))
|
|
531
533
|
// .pipe(transformMap<DBM, Saved<BM>>(dbm => this.dbmToBM(dbm, opt), safeOpt))
|
|
534
|
+
.on('error', err => stream.emit('error', err))
|
|
532
535
|
.pipe(
|
|
533
536
|
transformMap<DBM, Saved<BM>>(async dbm => await this.dbmToBM(dbm, opt), {
|
|
534
537
|
errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
@@ -550,11 +553,16 @@ export class CommonDao<
|
|
|
550
553
|
q.table = opt.table || q.table
|
|
551
554
|
opt.errorMode ||= ErrorMode.SUPPRESS
|
|
552
555
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
556
|
+
const stream: ReadableTyped<ID> = this.cfg.db
|
|
557
|
+
.streamQuery<DBM>(q.select(['id']), opt)
|
|
558
|
+
.on('error', err => stream.emit('error', err))
|
|
559
|
+
.pipe(
|
|
560
|
+
transformMapSimple<DBM, ID>(objectWithId => objectWithId.id, {
|
|
561
|
+
errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
562
|
+
}),
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
return stream
|
|
558
566
|
}
|
|
559
567
|
|
|
560
568
|
async streamQueryIdsForEach(
|
|
@@ -163,11 +163,16 @@ export class CommonKeyValueDao<T> {
|
|
|
163
163
|
|
|
164
164
|
// todo: consider it when readableMap supports `errorMode: SUPPRESS`
|
|
165
165
|
// readableMap(this.cfg.db.streamValues(this.cfg.table, limit), async buf => await this.cfg.hooks!.mapBufferToValue(buf))
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
const stream: ReadableTyped<Buffer> = this.cfg.db
|
|
167
|
+
.streamValues(this.cfg.table, limit)
|
|
168
|
+
.on('error', err => stream.emit('error', err))
|
|
169
|
+
.pipe(
|
|
170
|
+
transformMap(async buf => await this.cfg.hooks!.mapBufferToValue!(buf), {
|
|
171
|
+
errorMode: ErrorMode.SUPPRESS, // cause .pipe cannot propagate errors
|
|
172
|
+
}),
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
return stream
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
streamEntries(limit?: number): ReadableTyped<KeyValueTuple<string, T>> {
|
|
@@ -175,10 +180,15 @@ export class CommonKeyValueDao<T> {
|
|
|
175
180
|
return this.cfg.db.streamEntries(this.cfg.table, limit)
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
const stream: ReadableTyped<KeyValueTuple<string, T>> = this.cfg.db
|
|
184
|
+
.streamEntries(this.cfg.table, limit)
|
|
185
|
+
.on('error', err => stream.emit('error', err))
|
|
186
|
+
.pipe(
|
|
187
|
+
transformMap(async ([id, buf]) => [id, await this.cfg.hooks!.mapBufferToValue!(buf)], {
|
|
188
|
+
errorMode: ErrorMode.SUPPRESS, // cause .pipe cannot propagate errors
|
|
189
|
+
}),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
return stream
|
|
183
193
|
}
|
|
184
194
|
}
|