@naturalcycles/db-lib 10.26.1 → 10.28.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.
Files changed (46) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +2 -2
  2. package/dist/adapter/cachedb/cache.db.js +7 -7
  3. package/dist/adapter/file/file.db.d.ts +2 -2
  4. package/dist/adapter/file/file.db.js +5 -6
  5. package/dist/commondao/common.dao.d.ts +9 -23
  6. package/dist/commondao/common.dao.js +38 -157
  7. package/dist/commondao/common.dao.model.d.ts +1 -19
  8. package/dist/commondb/base.common.db.d.ts +2 -2
  9. package/dist/commondb/common.db.d.ts +2 -2
  10. package/dist/inmemory/inMemory.db.d.ts +2 -2
  11. package/dist/inmemory/inMemory.db.js +2 -2
  12. package/dist/inmemory/inMemoryKeyValueDB.d.ts +4 -4
  13. package/dist/inmemory/inMemoryKeyValueDB.js +4 -4
  14. package/dist/inmemory/queryInMemory.js +2 -2
  15. package/dist/kv/commonKeyValueDB.d.ts +4 -4
  16. package/dist/kv/commonKeyValueDao.d.ts +5 -5
  17. package/dist/kv/commonKeyValueDao.js +9 -12
  18. package/dist/pipeline/dbPipelineBackup.d.ts +1 -1
  19. package/dist/pipeline/dbPipelineBackup.js +3 -3
  20. package/dist/pipeline/dbPipelineCopy.d.ts +1 -1
  21. package/dist/pipeline/dbPipelineCopy.js +3 -4
  22. package/dist/pipeline/dbPipelineRestore.d.ts +1 -2
  23. package/dist/pipeline/dbPipelineRestore.js +2 -3
  24. package/dist/query/dbQuery.d.ts +6 -12
  25. package/dist/query/dbQuery.js +0 -19
  26. package/dist/testing/commonDBTest.js +2 -2
  27. package/dist/testing/commonDaoTest.js +12 -6
  28. package/package.json +1 -1
  29. package/src/adapter/cachedb/cache.db.ts +8 -9
  30. package/src/adapter/file/file.db.ts +6 -10
  31. package/src/commondao/common.dao.model.ts +1 -26
  32. package/src/commondao/common.dao.ts +50 -208
  33. package/src/commondb/base.common.db.ts +2 -2
  34. package/src/commondb/common.db.ts +2 -2
  35. package/src/inmemory/inMemory.db.ts +3 -7
  36. package/src/inmemory/inMemoryKeyValueDB.ts +7 -8
  37. package/src/inmemory/queryInMemory.ts +2 -2
  38. package/src/kv/commonKeyValueDB.ts +4 -4
  39. package/src/kv/commonKeyValueDao.ts +16 -20
  40. package/src/pipeline/dbPipelineBackup.ts +6 -6
  41. package/src/pipeline/dbPipelineCopy.ts +6 -8
  42. package/src/pipeline/dbPipelineRestore.ts +2 -2
  43. package/src/query/dbQuery.ts +5 -39
  44. package/src/testing/commonDBTest.ts +2 -2
  45. package/src/testing/commonDaoTest.ts +12 -6
  46. package/src/testing/test.model.ts +1 -1
@@ -9,11 +9,11 @@ import { _passthroughMapper } from '@naturalcycles/js-lib/types'
9
9
  import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors'
10
10
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
11
11
  import {
12
+ NDJsonStats,
12
13
  Pipeline,
13
14
  type TransformLogProgressOptions,
14
15
  type TransformMapOptions,
15
16
  } from '@naturalcycles/nodejs-lib/stream'
16
- import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream'
17
17
  import type { CommonDB } from '../commondb/common.db.js'
18
18
  import type { CommonDBSaveOptions } from '../db.model.js'
19
19
 
@@ -187,7 +187,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
187
187
 
188
188
  await Pipeline.fromNDJsonFile<BaseDBEntity>(filePath)
189
189
  .limitSource(limit)
190
- .tap(() => rows++)
190
+ .tapSync(() => rows++)
191
191
  .logProgress({
192
192
  logEvery: 1000,
193
193
  ...opt,
@@ -1,13 +1,12 @@
1
1
  import { _truncate } from '@naturalcycles/js-lib/string/string.util.js'
2
- import type { AsyncIndexedMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib/types'
2
+ import type { BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib/types'
3
3
  import { _objectAssign } from '@naturalcycles/js-lib/types'
4
- import { Pipeline, type ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
4
+ import type { Pipeline } from '@naturalcycles/nodejs-lib/stream'
5
5
  import type { CommonDao } from '../commondao/common.dao.js'
6
6
  import type {
7
7
  CommonDaoOptions,
8
8
  CommonDaoReadOptions,
9
9
  CommonDaoStreamDeleteOptions,
10
- CommonDaoStreamForEachOptions,
11
10
  CommonDaoStreamOptions,
12
11
  } from '../commondao/common.dao.model.js'
13
12
  import type { RunQueryResult } from '../db.model.js'
@@ -276,55 +275,22 @@ export class RunnableDBQuery<
276
275
  return await this.dao.patchByQuery(this, patch, opt)
277
276
  }
278
277
 
279
- async streamQueryForEach(
280
- mapper: AsyncIndexedMapper<BM, void>,
281
- opt?: CommonDaoStreamForEachOptions<BM>,
282
- ): Promise<void> {
283
- await this.dao.streamQueryForEach(this, mapper, opt)
284
- }
285
-
286
- async streamQueryAsDBMForEach(
287
- mapper: AsyncIndexedMapper<DBM, void>,
288
- opt?: CommonDaoStreamForEachOptions<DBM>,
289
- ): Promise<void> {
290
- await this.dao.streamQueryAsDBMForEach(this, mapper, opt)
291
- }
292
-
293
- streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM> {
278
+ streamQuery(opt?: CommonDaoStreamOptions<BM>): Pipeline<BM> {
294
279
  return this.dao.streamQuery(this, opt)
295
280
  }
296
281
 
297
- streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM> {
282
+ streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): Pipeline<DBM> {
298
283
  return this.dao.streamQueryAsDBM(this, opt)
299
284
  }
300
285
 
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
-
309
286
  async queryIds(opt?: CommonDaoReadOptions): Promise<ID[]> {
310
287
  return await this.dao.queryIds(this, opt)
311
288
  }
312
289
 
313
- streamQueryIds(opt?: CommonDaoStreamOptions<ID>): ReadableTyped<ID> {
290
+ streamQueryIds(opt?: CommonDaoStreamOptions<ID>): Pipeline<ID> {
314
291
  return this.dao.streamQueryIds(this, opt)
315
292
  }
316
293
 
317
- pipelineIds(opt?: CommonDaoStreamOptions<ID>): Pipeline<ID> {
318
- return Pipeline.from(this.dao.streamQueryIds(this, opt))
319
- }
320
-
321
- async streamQueryIdsForEach(
322
- mapper: AsyncIndexedMapper<ID, void>,
323
- opt?: CommonDaoStreamForEachOptions<ID>,
324
- ): Promise<void> {
325
- await this.dao.streamQueryIdsForEach(this, mapper, opt)
326
- }
327
-
328
294
  async deleteByQuery(opt?: CommonDaoStreamDeleteOptions<DBM>): Promise<number> {
329
295
  return await this.dao.deleteByQuery(this, opt)
330
296
  }
@@ -354,8 +354,8 @@ export async function runCommonDBTest(
354
354
  // It should fail on id == null
355
355
  await tx.saveBatch(TEST_TABLE, [{ ...items[0]!, k1: 5, id: null as any }])
356
356
  })
357
- } catch (err_) {
358
- err = err_
357
+ } catch (err2) {
358
+ err = err2
359
359
  }
360
360
 
361
361
  expect(err).toBeDefined()
@@ -245,7 +245,10 @@ export async function runCommonDaoTest(
245
245
  if (support.streaming) {
246
246
  test('streamQueryForEach all', async () => {
247
247
  let rows: TestItemBM[] = []
248
- await dao.query().streamQueryForEach(bm => void rows.push(bm))
248
+ await dao
249
+ .query()
250
+ .streamQuery()
251
+ .forEachSync(bm => void rows.push(bm))
249
252
 
250
253
  rows = _sortBy(rows, r => r.id)
251
254
  expectMatch(expectedItems, rows, quirks)
@@ -260,7 +263,10 @@ export async function runCommonDaoTest(
260
263
 
261
264
  test('streamQueryIdsForEach all', async () => {
262
265
  let ids: string[] = []
263
- await dao.query().streamQueryIdsForEach(id => void ids.push(id))
266
+ await dao
267
+ .query()
268
+ .streamQueryIds()
269
+ .forEachSync(id => void ids.push(id))
264
270
  ids = ids.sort()
265
271
  expectMatch(
266
272
  expectedItems.map(i => i.id),
@@ -406,8 +412,8 @@ export async function runCommonDaoTest(
406
412
  await tx.deleteById(dao, items[2]!.id)
407
413
  await tx.save(dao, { ...items[0]!, k1: 5 as any }) // it should fail here
408
414
  })
409
- } catch (err_) {
410
- err = err_
415
+ } catch (err2) {
416
+ err = err2
411
417
  }
412
418
 
413
419
  expect(err).toBeDefined()
@@ -427,8 +433,8 @@ export async function runCommonDaoTest(
427
433
  await tx.deleteById(dao, items[2]!.id)
428
434
  await tx.save(dao, { ...items[0]!, k1: 5 as any }) // it should fail here
429
435
  await tx.commit()
430
- } catch (err_) {
431
- err = err_
436
+ } catch (err2) {
437
+ err = err2
432
438
  }
433
439
 
434
440
  expect(err).toBeDefined()
@@ -58,7 +58,7 @@ export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = j
58
58
  created: j.unixTimestamp(),
59
59
  updated: j.unixTimestamp(),
60
60
  k1: j.string(),
61
- k2: j.oneOf<string | null>([j.string(), j.null()]).optional(),
61
+ k2: j.oneOf([j.string(), j.null()]).optional(),
62
62
  k3: j.number().optional(),
63
63
  even: j.boolean().optional(),
64
64
  b1: j.buffer().optional(),