@naturalcycles/db-lib 10.24.0 → 10.26.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,6 +1,6 @@
1
1
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
2
2
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
3
- import { createReadStreamAsNDJSON, Pipeline } from '@naturalcycles/nodejs-lib/stream';
3
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
4
4
  /**
5
5
  * Persists in local filesystem as ndjson.
6
6
  */
@@ -25,7 +25,7 @@ export class LocalFilePersistencePlugin {
25
25
  const filePath = `${this.cfg.storagePath}/${table}.${ext}`;
26
26
  if (!(await fs2.pathExistsAsync(filePath)))
27
27
  return [];
28
- return await createReadStreamAsNDJSON(filePath).toArray();
28
+ return await Pipeline.fromNDJsonFile(filePath).toArray();
29
29
  }
30
30
  async saveFiles(ops) {
31
31
  await pMap(ops, async (op) => await this.saveFile(op.table, op.rows), { concurrency: 32 });
@@ -1,5 +1,5 @@
1
1
  import type { AsyncIndexedMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib/types';
2
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
2
+ import { Pipeline, type ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
3
3
  import type { CommonDao } from '../commondao/common.dao.js';
4
4
  import type { CommonDaoOptions, CommonDaoReadOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '../commondao/common.dao.model.js';
5
5
  import type { RunQueryResult } from '../db.model.js';
@@ -104,8 +104,11 @@ export declare class RunnableDBQuery<BM extends BaseDBEntity, DBM extends BaseDB
104
104
  streamQueryAsDBMForEach(mapper: AsyncIndexedMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>;
105
105
  streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>;
106
106
  streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM>;
107
+ pipeline(opt?: CommonDaoStreamOptions<BM>): Pipeline<BM>;
108
+ pipelineAsDBM(opt?: CommonDaoStreamOptions<DBM>): Pipeline<DBM>;
107
109
  queryIds(opt?: CommonDaoReadOptions): Promise<ID[]>;
108
110
  streamQueryIds(opt?: CommonDaoStreamOptions<ID>): ReadableTyped<ID>;
111
+ pipelineIds(opt?: CommonDaoStreamOptions<ID>): Pipeline<ID>;
109
112
  streamQueryIdsForEach(mapper: AsyncIndexedMapper<ID, void>, opt?: CommonDaoStreamForEachOptions<ID>): Promise<void>;
110
113
  deleteByQuery(opt?: CommonDaoStreamDeleteOptions<DBM>): Promise<number>;
111
114
  }
@@ -1,5 +1,6 @@
1
1
  import { _truncate } from '@naturalcycles/js-lib/string/string.util.js';
2
2
  import { _objectAssign } from '@naturalcycles/js-lib/types';
3
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
3
4
  export const dbQueryFilterOperatorValues = [
4
5
  '<',
5
6
  '<=',
@@ -187,12 +188,21 @@ export class RunnableDBQuery extends DBQuery {
187
188
  streamQueryAsDBM(opt) {
188
189
  return this.dao.streamQueryAsDBM(this, opt);
189
190
  }
191
+ pipeline(opt) {
192
+ return Pipeline.from(this.dao.streamQuery(this, opt));
193
+ }
194
+ pipelineAsDBM(opt) {
195
+ return Pipeline.from(this.dao.streamQueryAsDBM(this, opt));
196
+ }
190
197
  async queryIds(opt) {
191
198
  return await this.dao.queryIds(this, opt);
192
199
  }
193
200
  streamQueryIds(opt) {
194
201
  return this.dao.streamQueryIds(this, opt);
195
202
  }
203
+ pipelineIds(opt) {
204
+ return Pipeline.from(this.dao.streamQueryIds(this, opt));
205
+ }
196
206
  async streamQueryIdsForEach(mapper, opt) {
197
207
  await this.dao.streamQueryIdsForEach(this, mapper, opt);
198
208
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.24.0",
4
+ "version": "10.26.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -1,7 +1,7 @@
1
1
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
2
2
  import type { ObjectWithId } from '@naturalcycles/js-lib/types'
3
3
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
4
- import { createReadStreamAsNDJSON, Pipeline } from '@naturalcycles/nodejs-lib/stream'
4
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
5
5
  import type { DBSaveBatchOperation } from '../../db.model.js'
6
6
  import type { FileDBPersistencePlugin } from './file.db.model.js'
7
7
 
@@ -46,7 +46,7 @@ export class LocalFilePersistencePlugin implements FileDBPersistencePlugin {
46
46
 
47
47
  if (!(await fs2.pathExistsAsync(filePath))) return []
48
48
 
49
- return await createReadStreamAsNDJSON(filePath).toArray()
49
+ return await Pipeline.fromNDJsonFile<ROW>(filePath).toArray()
50
50
  }
51
51
 
52
52
  async saveFiles(ops: DBSaveBatchOperation<any>[]): Promise<void> {
@@ -1,7 +1,7 @@
1
1
  import { _truncate } from '@naturalcycles/js-lib/string/string.util.js'
2
2
  import type { AsyncIndexedMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib/types'
3
3
  import { _objectAssign } from '@naturalcycles/js-lib/types'
4
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
4
+ import { Pipeline, type ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
5
5
  import type { CommonDao } from '../commondao/common.dao.js'
6
6
  import type {
7
7
  CommonDaoOptions,
@@ -298,6 +298,14 @@ export class RunnableDBQuery<
298
298
  return this.dao.streamQueryAsDBM(this, opt)
299
299
  }
300
300
 
301
+ pipeline(opt?: CommonDaoStreamOptions<BM>): Pipeline<BM> {
302
+ return Pipeline.from(this.dao.streamQuery(this, opt))
303
+ }
304
+
305
+ pipelineAsDBM(opt?: CommonDaoStreamOptions<DBM>): Pipeline<DBM> {
306
+ return Pipeline.from(this.dao.streamQueryAsDBM(this, opt))
307
+ }
308
+
301
309
  async queryIds(opt?: CommonDaoReadOptions): Promise<ID[]> {
302
310
  return await this.dao.queryIds(this, opt)
303
311
  }
@@ -306,6 +314,10 @@ export class RunnableDBQuery<
306
314
  return this.dao.streamQueryIds(this, opt)
307
315
  }
308
316
 
317
+ pipelineIds(opt?: CommonDaoStreamOptions<ID>): Pipeline<ID> {
318
+ return Pipeline.from(this.dao.streamQueryIds(this, opt))
319
+ }
320
+
309
321
  async streamQueryIdsForEach(
310
322
  mapper: AsyncIndexedMapper<ID, void>,
311
323
  opt?: CommonDaoStreamForEachOptions<ID>,