@naturalcycles/datastore-lib 3.16.1 → 3.16.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.16.2](https://github.com/NaturalCycles/datastore-lib/compare/v3.16.1...v3.16.2) (2021-10-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * adapt to latest db-lib with typed queries ([21d31ea](https://github.com/NaturalCycles/datastore-lib/commit/21d31ea7343ca0b2590950c067f6ce472dc82501))
7
+
1
8
  ## [3.16.1](https://github.com/NaturalCycles/datastore-lib/compare/v3.16.0...v3.16.1) (2021-10-07)
2
9
 
3
10
 
@@ -28,7 +28,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
28
28
  /**
29
29
  * Returns saved entities with generated id/updated/created (non-mutating!)
30
30
  */
31
- saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: DatastoreDBSaveOptions): Promise<void>;
31
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: DatastoreDBSaveOptions<ROW>): Promise<void>;
32
32
  deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: DatastoreDBOptions): Promise<number>;
33
33
  /**
34
34
  * Limitation: Datastore's delete returns void, so we always return all ids here as "deleted"
@@ -1,5 +1,6 @@
1
1
  import type { DatastoreOptions, Key, Transaction } from '@google-cloud/datastore';
2
2
  import { CommonDBOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib';
3
+ import { AnyObjectWithId, ObjectWithId } from '@naturalcycles/db-lib/src/db.model';
3
4
  export interface DatastorePayload<T = any> {
4
5
  key: Key;
5
6
  data: T;
@@ -76,7 +77,7 @@ export interface DatastoreDBStreamOptions extends DatastoreDBOptions {
76
77
  export interface DatastoreDBOptions extends CommonDBOptions {
77
78
  tx?: Transaction;
78
79
  }
79
- export interface DatastoreDBSaveOptions extends CommonDBSaveOptions {
80
+ export interface DatastoreDBSaveOptions<ROW extends ObjectWithId = AnyObjectWithId> extends CommonDBSaveOptions<ROW> {
80
81
  tx?: Transaction;
81
82
  }
82
83
  export interface DatastoreStats {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.16.1",
3
+ "version": "3.16.2",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -195,9 +195,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
195
195
  override async saveBatch<ROW extends ObjectWithId>(
196
196
  table: string,
197
197
  rows: ROW[],
198
- opt: DatastoreDBSaveOptions = {},
198
+ opt: DatastoreDBSaveOptions<ROW> = {},
199
199
  ): Promise<void> {
200
- const entities = rows.map(obj => this.toDatastoreEntity(table, obj, opt.excludeFromIndexes))
200
+ const entities = rows.map(obj =>
201
+ this.toDatastoreEntity(table, obj, opt.excludeFromIndexes as string[]),
202
+ )
201
203
 
202
204
  const save = pRetry(
203
205
  async (batch: DatastorePayload<ROW>[]) => {
@@ -1,5 +1,6 @@
1
1
  import type { DatastoreOptions, Key, Transaction } from '@google-cloud/datastore'
2
2
  import { CommonDBOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib'
3
+ import { AnyObjectWithId, ObjectWithId } from '@naturalcycles/db-lib/src/db.model'
3
4
 
4
5
  export interface DatastorePayload<T = any> {
5
6
  key: Key
@@ -88,7 +89,8 @@ export interface DatastoreDBStreamOptions extends DatastoreDBOptions {
88
89
  export interface DatastoreDBOptions extends CommonDBOptions {
89
90
  tx?: Transaction
90
91
  }
91
- export interface DatastoreDBSaveOptions extends CommonDBSaveOptions {
92
+ export interface DatastoreDBSaveOptions<ROW extends ObjectWithId = AnyObjectWithId>
93
+ extends CommonDBSaveOptions<ROW> {
92
94
  tx?: Transaction
93
95
  }
94
96
 
@@ -9,7 +9,7 @@ interface KVObject {
9
9
  v: Buffer
10
10
  }
11
11
 
12
- const excludeFromIndexes = ['v']
12
+ const excludeFromIndexes: (keyof KVObject)[] = ['v']
13
13
 
14
14
  export interface DatastoreKeyValueDBCfg extends DatastoreDBCfg {}
15
15
 
package/src/query.util.ts CHANGED
@@ -19,18 +19,24 @@ export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
19
19
 
20
20
  // filter
21
21
  // eslint-disable-next-line unicorn/no-array-reduce
22
- q = dbQuery._filters.reduce((q, f) => q.filter(f.name, OP_MAP[f.op] || (f.op as any), f.val), q)
22
+ q = dbQuery._filters.reduce(
23
+ (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
24
+ q,
25
+ )
23
26
 
24
27
  // limit
25
28
  q = q.limit(dbQuery._limitValue || 0)
26
29
 
27
30
  // order
28
31
  // eslint-disable-next-line unicorn/no-array-reduce
29
- q = dbQuery._orders.reduce((q, ord) => q.order(ord.name, { descending: ord.descending }), q)
32
+ q = dbQuery._orders.reduce(
33
+ (q, ord) => q.order(ord.name as string, { descending: ord.descending }),
34
+ q,
35
+ )
30
36
 
31
37
  // select
32
38
  if (dbQuery._selectedFieldNames) {
33
- const fields = dbQuery._selectedFieldNames.map(f => FNAME_MAP[f] || f)
39
+ const fields = (dbQuery._selectedFieldNames as string[]).map(f => FNAME_MAP[f] || f)
34
40
 
35
41
  // Datastore requires you to specify at least one column, so if empty array is passed - it'll include __key__ at least
36
42
  if (!fields.length) {