@naturalcycles/datastore-lib 3.36.0 → 3.38.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.
@@ -66,7 +66,7 @@ export declare class DatastoreDBTransaction implements DBTransaction {
66
66
  tx: Transaction;
67
67
  constructor(db: DatastoreDB, tx: Transaction);
68
68
  rollback(): Promise<void>;
69
- getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions | undefined): Promise<ROW[]>;
70
- saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW> | undefined): Promise<void>;
71
- deleteByIds(table: string, ids: string[], opt?: CommonDBOptions | undefined): Promise<number>;
69
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
70
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
71
+ deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>;
72
72
  }
@@ -38,7 +38,8 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
38
38
  super();
39
39
  this.support = {
40
40
  ...db_lib_1.commonDBFullSupport,
41
- updateByQuery: false,
41
+ patchByQuery: false,
42
+ increment: false,
42
43
  };
43
44
  this.cfg = {
44
45
  logger: console,
@@ -1,4 +1,5 @@
1
1
  import { CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
+ import { StringMap } from '@naturalcycles/js-lib';
2
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
4
  import { DatastoreDB } from './datastore.db';
4
5
  import { DatastoreDBCfg } from './datastore.model';
@@ -8,6 +9,10 @@ export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
8
9
  cfg: DatastoreKeyValueDBCfg;
9
10
  constructor(cfg: DatastoreKeyValueDBCfg);
10
11
  db: DatastoreDB;
12
+ support: {
13
+ increment: boolean;
14
+ count?: boolean;
15
+ };
11
16
  ping(): Promise<void>;
12
17
  createTable(): Promise<void>;
13
18
  getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
@@ -17,4 +22,6 @@ export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
17
22
  streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
18
23
  streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
19
24
  count(table: string): Promise<number>;
25
+ increment(_table: string, _id: string, _by?: number): Promise<number>;
26
+ incrementBatch(_table: string, _incrementMap: StringMap<number>): Promise<StringMap<number>>;
20
27
  }
@@ -2,11 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DatastoreKeyValueDB = void 0;
4
4
  const db_lib_1 = require("@naturalcycles/db-lib");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const datastore_db_1 = require("./datastore.db");
6
7
  const excludeFromIndexes = ['v'];
7
8
  class DatastoreKeyValueDB {
8
9
  constructor(cfg) {
9
10
  this.cfg = cfg;
11
+ this.support = {
12
+ ...db_lib_1.commonKeyValueDBFullSupport,
13
+ increment: false,
14
+ };
10
15
  this.db = new datastore_db_1.DatastoreDB(cfg);
11
16
  }
12
17
  async ping() {
@@ -52,5 +57,11 @@ class DatastoreKeyValueDB {
52
57
  const q = db_lib_1.DBQuery.create(table);
53
58
  return await this.db.runQueryCount(q);
54
59
  }
60
+ async increment(_table, _id, _by) {
61
+ throw new js_lib_1.AppError('DatastoreKeyValueDB.increment() is not implemented');
62
+ }
63
+ async incrementBatch(_table, _incrementMap) {
64
+ throw new js_lib_1.AppError('DatastoreKeyValueDB.incrementBatch() is not implemented');
65
+ }
55
66
  }
56
67
  exports.DatastoreKeyValueDB = DatastoreKeyValueDB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.36.0",
3
+ "version": "3.38.0",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky",
@@ -80,7 +80,8 @@ const methodMap: Record<CommonDBSaveMethod, string> = {
80
80
  export class DatastoreDB extends BaseCommonDB implements CommonDB {
81
81
  override support: CommonDBSupport = {
82
82
  ...commonDBFullSupport,
83
- updateByQuery: false,
83
+ patchByQuery: false,
84
+ increment: false,
84
85
  }
85
86
 
86
87
  constructor(cfg: DatastoreDBCfg = {}) {
@@ -571,7 +572,7 @@ export class DatastoreDBTransaction implements DBTransaction {
571
572
  async getByIds<ROW extends ObjectWithId>(
572
573
  table: string,
573
574
  ids: string[],
574
- opt?: CommonDBOptions | undefined,
575
+ opt?: CommonDBOptions,
575
576
  ): Promise<ROW[]> {
576
577
  return await this.db.getByIds(table, ids, { ...opt, tx: this })
577
578
  }
@@ -579,16 +580,12 @@ export class DatastoreDBTransaction implements DBTransaction {
579
580
  async saveBatch<ROW extends ObjectWithId>(
580
581
  table: string,
581
582
  rows: ROW[],
582
- opt?: CommonDBSaveOptions<ROW> | undefined,
583
+ opt?: CommonDBSaveOptions<ROW>,
583
584
  ): Promise<void> {
584
585
  await this.db.saveBatch(table, rows, { ...opt, tx: this })
585
586
  }
586
587
 
587
- async deleteByIds(
588
- table: string,
589
- ids: string[],
590
- opt?: CommonDBOptions | undefined,
591
- ): Promise<number> {
588
+ async deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number> {
592
589
  return await this.db.deleteByIds(table, ids, { ...opt, tx: this })
593
590
  }
594
591
  }
@@ -1,4 +1,10 @@
1
- import { CommonKeyValueDB, DBQuery, KeyValueDBTuple } from '@naturalcycles/db-lib'
1
+ import {
2
+ CommonKeyValueDB,
3
+ commonKeyValueDBFullSupport,
4
+ DBQuery,
5
+ KeyValueDBTuple,
6
+ } from '@naturalcycles/db-lib'
7
+ import { AppError, StringMap } from '@naturalcycles/js-lib'
2
8
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
3
9
  import { DatastoreDB } from './datastore.db'
4
10
  import { DatastoreDBCfg } from './datastore.model'
@@ -19,6 +25,11 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
19
25
 
20
26
  db: DatastoreDB
21
27
 
28
+ support = {
29
+ ...commonKeyValueDBFullSupport,
30
+ increment: false,
31
+ }
32
+
22
33
  async ping(): Promise<void> {
23
34
  await this.db.ping()
24
35
  }
@@ -83,4 +94,15 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
83
94
  const q = DBQuery.create<KVObject>(table)
84
95
  return await this.db.runQueryCount(q)
85
96
  }
97
+
98
+ async increment(_table: string, _id: string, _by?: number): Promise<number> {
99
+ throw new AppError('DatastoreKeyValueDB.increment() is not implemented')
100
+ }
101
+
102
+ async incrementBatch(
103
+ _table: string,
104
+ _incrementMap: StringMap<number>,
105
+ ): Promise<StringMap<number>> {
106
+ throw new AppError('DatastoreKeyValueDB.incrementBatch() is not implemented')
107
+ }
86
108
  }