@naturalcycles/datastore-lib 3.38.1 → 3.38.2

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.
@@ -206,9 +206,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
206
206
  */
207
207
  async deleteByIds(table, ids, opt = {}) {
208
208
  const keys = ids.map(id => this.key(table, id));
209
- await (0, js_lib_1.pMap)((0, js_lib_1._chunk)(keys, MAX_ITEMS),
210
- // eslint-disable-next-line @typescript-eslint/return-await
211
- async (batch) => await (opt.tx?.tx || this.ds()).delete(batch), {
209
+ await (0, js_lib_1.pMap)((0, js_lib_1._chunk)(keys, MAX_ITEMS), async (batch) => await (opt.tx?.tx || this.ds()).delete(batch), {
212
210
  concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
213
211
  });
214
212
  return ids.length;
@@ -1,6 +1,5 @@
1
- import { CommonKeyValueDB } from '@naturalcycles/db-lib';
1
+ import { CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
2
  import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
3
- import { KeyValueTuple } from '@naturalcycles/js-lib';
4
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
4
  import { DatastoreDB } from './datastore.db';
6
5
  import { DatastoreDBCfg } from './datastore.model';
@@ -16,12 +15,12 @@ export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
16
15
  };
17
16
  ping(): Promise<void>;
18
17
  createTable(): Promise<void>;
19
- getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]>;
18
+ getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
20
19
  deleteByIds(table: string, ids: string[]): Promise<void>;
21
- saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void>;
20
+ saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void>;
22
21
  streamIds(table: string, limit?: number): ReadableTyped<string>;
23
- streamValues<V>(table: string, limit?: number): ReadableTyped<V>;
24
- streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>>;
22
+ streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
23
+ streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
25
24
  count(table: string): Promise<number>;
26
25
  incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
27
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.38.1",
3
+ "version": "3.38.2",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky",
@@ -350,7 +350,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
350
350
 
351
351
  await pMap(
352
352
  _chunk(keys, MAX_ITEMS),
353
- // eslint-disable-next-line @typescript-eslint/return-await
353
+
354
354
  async batch => await ((opt.tx as DatastoreDBTransaction)?.tx || this.ds()).delete(batch),
355
355
  {
356
356
  concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
@@ -1,16 +1,21 @@
1
- import { CommonKeyValueDB, commonKeyValueDBFullSupport, DBQuery } from '@naturalcycles/db-lib'
1
+ import {
2
+ CommonKeyValueDB,
3
+ commonKeyValueDBFullSupport,
4
+ DBQuery,
5
+ KeyValueDBTuple,
6
+ } from '@naturalcycles/db-lib'
2
7
  import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
3
- import { AppError, KeyValueTuple, ObjectWithId } from '@naturalcycles/js-lib'
8
+ import { AppError, ObjectWithId } from '@naturalcycles/js-lib'
4
9
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
5
10
  import { DatastoreDB } from './datastore.db'
6
11
  import { DatastoreDBCfg } from './datastore.model'
7
12
 
8
- interface KVObject<V> {
13
+ interface KVObject {
9
14
  id: string
10
- v: V
15
+ v: Buffer
11
16
  }
12
17
 
13
- const excludeFromIndexes: (keyof KVObject<any>)[] = ['v']
18
+ const excludeFromIndexes: (keyof KVObject)[] = ['v']
14
19
 
15
20
  export interface DatastoreKeyValueDBCfg extends DatastoreDBCfg {}
16
21
 
@@ -32,16 +37,16 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
32
37
 
33
38
  async createTable(): Promise<void> {}
34
39
 
35
- async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
36
- return (await this.db.getByIds<KVObject<V>>(table, ids)).map(r => [r.id, r.v])
40
+ async getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]> {
41
+ return (await this.db.getByIds<KVObject>(table, ids)).map(r => [r.id, r.v])
37
42
  }
38
43
 
39
44
  async deleteByIds(table: string, ids: string[]): Promise<void> {
40
45
  await this.db.deleteByIds(table, ids)
41
46
  }
42
47
 
43
- async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
44
- await this.db.saveBatch<KVObject<V>>(
48
+ async saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void> {
49
+ await this.db.saveBatch<KVObject>(
45
50
  table,
46
51
  entries.map(([id, v]) => ({ id, v })),
47
52
  {
@@ -63,9 +68,9 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
63
68
  )
64
69
  }
65
70
 
66
- streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
71
+ streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
67
72
  // `select v` doesn't work for some reason
68
- const q = DBQuery.create<KVObject<V>>(table).limit(limit || 0)
73
+ const q = DBQuery.create<KVObject>(table).limit(limit || 0)
69
74
 
70
75
  return (
71
76
  this.db
@@ -75,8 +80,8 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
75
80
  )
76
81
  }
77
82
 
78
- streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
79
- const q = DBQuery.create<KVObject<V>>(table).limit(limit || 0)
83
+ streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
84
+ const q = DBQuery.create<KVObject>(table).limit(limit || 0)
80
85
 
81
86
  return (
82
87
  this.db