@naturalcycles/datastore-lib 3.32.2 → 3.32.3

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,7 +1,7 @@
1
1
  import { Transaction } from '@google-cloud/datastore';
2
2
  import type { Datastore, Key, Query } from '@google-cloud/datastore';
3
3
  import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBSupport, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult, CommonDBTransactionOptions } from '@naturalcycles/db-lib';
4
- import { JsonSchemaObject, JsonSchemaRootObject, CommonLogger, PartialObjectWithId, Saved, ObjectWithId } from '@naturalcycles/js-lib';
4
+ import { JsonSchemaObject, JsonSchemaRootObject, CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
5
5
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
6
6
  import { DatastoreDBCfg, DatastoreDBOptions, DatastoreDBSaveOptions, DatastoreDBStreamOptions, DatastorePayload, DatastorePropertyStats, DatastoreStats } from './datastore.model';
7
7
  /**
@@ -22,17 +22,17 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
22
22
  protected KEY: symbol;
23
23
  ds(): Datastore;
24
24
  ping(): Promise<void>;
25
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[], opt?: DatastoreDBOptions): Promise<Saved<ROW>[]>;
26
- runQuery<ROW extends PartialObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<RunQueryResult<Saved<ROW>>>;
27
- runQueryCount<ROW extends PartialObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<number>;
28
- runDatastoreQuery<ROW extends PartialObjectWithId>(q: Query): Promise<RunQueryResult<Saved<ROW>>>;
25
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: DatastoreDBOptions): Promise<ROW[]>;
26
+ runQuery<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<RunQueryResult<ROW>>;
27
+ runQueryCount<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<number>;
28
+ runDatastoreQuery<ROW extends ObjectWithId>(q: Query): Promise<RunQueryResult<ROW>>;
29
29
  private runQueryStream;
30
- streamQuery<ROW extends PartialObjectWithId>(dbQuery: DBQuery<ROW>, opt?: DatastoreDBStreamOptions): ReadableTyped<ROW>;
30
+ streamQuery<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, opt?: DatastoreDBStreamOptions): ReadableTyped<ROW>;
31
31
  /**
32
32
  * Returns saved entities with generated id/updated/created (non-mutating!)
33
33
  */
34
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: DatastoreDBSaveOptions<ROW>): Promise<void>;
35
- deleteByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: DatastoreDBOptions): Promise<number>;
34
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: DatastoreDBSaveOptions<ROW>): Promise<void>;
35
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: DatastoreDBOptions): Promise<number>;
36
36
  /**
37
37
  * Limitation: Datastore's delete returns void, so we always return all ids here as "deleted"
38
38
  * regardless if they were actually deleted or not.
@@ -53,9 +53,9 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
53
53
  key(kind: string, id: string | number): Key;
54
54
  getDsKey(o: any): Key | undefined;
55
55
  getKey(key: Key): string | undefined;
56
- createTable<ROW extends PartialObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
56
+ createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
57
57
  getTables(): Promise<string[]>;
58
- getTableSchema<ROW extends PartialObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
58
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
59
59
  private getPRetryOptions;
60
60
  }
61
61
  /**
@@ -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 PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions | undefined): Promise<ROW[]>;
70
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW> | undefined): 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
71
  deleteByIds(table: string, ids: string[], opt?: CommonDBOptions | undefined): Promise<number>;
72
72
  }
@@ -101,7 +101,7 @@ export interface DatastoreDBStreamOptions extends DatastoreDBOptions {
101
101
  }
102
102
  export interface DatastoreDBOptions extends CommonDBOptions {
103
103
  }
104
- export interface DatastoreDBSaveOptions<ROW extends Partial<ObjectWithId> = any> extends CommonDBSaveOptions<ROW> {
104
+ export interface DatastoreDBSaveOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {
105
105
  }
106
106
  export interface DatastoreStats {
107
107
  composite_index_count: number;
@@ -1,4 +1,4 @@
1
1
  import { Query } from '@google-cloud/datastore';
2
2
  import { DBQuery } from '@naturalcycles/db-lib';
3
- import { PartialObjectWithId } from '@naturalcycles/js-lib';
4
- export declare function dbQueryToDatastoreQuery<ROW extends PartialObjectWithId>(dbQuery: Readonly<DBQuery<ROW>>, emptyQuery: Query): Query;
3
+ import { ObjectWithId } from '@naturalcycles/js-lib';
4
+ export declare function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(dbQuery: Readonly<DBQuery<ROW>>, emptyQuery: Query): Query;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.32.2",
3
+ "version": "3.32.3",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -33,8 +33,6 @@ import {
33
33
  pRetryFn,
34
34
  pRetry,
35
35
  PRetryOptions,
36
- PartialObjectWithId,
37
- Saved,
38
36
  ObjectWithId,
39
37
  } from '@naturalcycles/js-lib'
40
38
  import { ReadableTyped, boldWhite } from '@naturalcycles/nodejs-lib'
@@ -135,11 +133,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
135
133
  await this.getAllStats()
136
134
  }
137
135
 
138
- override async getByIds<ROW extends PartialObjectWithId>(
136
+ override async getByIds<ROW extends ObjectWithId>(
139
137
  table: string,
140
138
  ids: string[],
141
139
  opt: DatastoreDBOptions = {},
142
- ): Promise<Saved<ROW>[]> {
140
+ ): Promise<ROW[]> {
143
141
  if (!ids.length) return []
144
142
  const keys = ids.map(id => this.key(table, id))
145
143
  let rows: any[]
@@ -189,7 +187,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
189
187
 
190
188
  return (
191
189
  rows
192
- .map(r => this.mapId<Saved<ROW>>(r))
190
+ .map(r => this.mapId<ROW>(r))
193
191
  // Seems like datastore .get() method doesn't return items properly sorted by input ids, so we gonna sort them here
194
192
  // same ids are not expected here
195
193
  .sort((a, b) => (a.id > b.id ? 1 : -1))
@@ -201,10 +199,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
201
199
  // return q.kinds[0]!
202
200
  // }
203
201
 
204
- override async runQuery<ROW extends PartialObjectWithId>(
202
+ override async runQuery<ROW extends ObjectWithId>(
205
203
  dbQuery: DBQuery<ROW>,
206
204
  _opt?: DatastoreDBOptions,
207
- ): Promise<RunQueryResult<Saved<ROW>>> {
205
+ ): Promise<RunQueryResult<ROW>> {
208
206
  const idFilter = dbQuery._filters.find(f => f.name === 'id')
209
207
  if (idFilter) {
210
208
  const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val
@@ -225,7 +223,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
225
223
  return qr
226
224
  }
227
225
 
228
- override async runQueryCount<ROW extends PartialObjectWithId>(
226
+ override async runQueryCount<ROW extends ObjectWithId>(
229
227
  dbQuery: DBQuery<ROW>,
230
228
  _opt?: DatastoreDBOptions,
231
229
  ): Promise<number> {
@@ -234,12 +232,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
234
232
  return entities.length
235
233
  }
236
234
 
237
- async runDatastoreQuery<ROW extends PartialObjectWithId>(
238
- q: Query,
239
- ): Promise<RunQueryResult<Saved<ROW>>> {
235
+ async runDatastoreQuery<ROW extends ObjectWithId>(q: Query): Promise<RunQueryResult<ROW>> {
240
236
  const [entities, queryResult] = await this.ds().runQuery(q)
241
237
 
242
- const rows = entities.map(e => this.mapId<Saved<ROW>>(e))
238
+ const rows = entities.map(e => this.mapId<ROW>(e))
243
239
 
244
240
  return {
245
241
  ...queryResult,
@@ -247,7 +243,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
247
243
  }
248
244
  }
249
245
 
250
- private runQueryStream<ROW extends PartialObjectWithId>(
246
+ private runQueryStream<ROW extends ObjectWithId>(
251
247
  q: Query,
252
248
  _opt?: DatastoreDBStreamOptions,
253
249
  ): ReadableTyped<ROW> {
@@ -278,7 +274,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
278
274
  return stream
279
275
  }
280
276
 
281
- override streamQuery<ROW extends PartialObjectWithId>(
277
+ override streamQuery<ROW extends ObjectWithId>(
282
278
  dbQuery: DBQuery<ROW>,
283
279
  opt?: DatastoreDBStreamOptions,
284
280
  ): ReadableTyped<ROW> {
@@ -291,7 +287,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
291
287
  /**
292
288
  * Returns saved entities with generated id/updated/created (non-mutating!)
293
289
  */
294
- override async saveBatch<ROW extends PartialObjectWithId>(
290
+ override async saveBatch<ROW extends ObjectWithId>(
295
291
  table: string,
296
292
  rows: ROW[],
297
293
  opt: DatastoreDBSaveOptions<ROW> = {},
@@ -328,7 +324,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
328
324
  }
329
325
  }
330
326
 
331
- override async deleteByQuery<ROW extends PartialObjectWithId>(
327
+ override async deleteByQuery<ROW extends ObjectWithId>(
332
328
  q: DBQuery<ROW>,
333
329
  opt?: DatastoreDBOptions,
334
330
  ): Promise<number> {
@@ -462,7 +458,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
462
458
  return id?.toString()
463
459
  }
464
460
 
465
- override async createTable<ROW extends PartialObjectWithId>(
461
+ override async createTable<ROW extends ObjectWithId>(
466
462
  _table: string,
467
463
  _schema: JsonSchemaObject<ROW>,
468
464
  ): Promise<void> {}
@@ -473,7 +469,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
473
469
  return statsArray.map(stats => stats.kind_name).filter(table => table && !table.startsWith('_'))
474
470
  }
475
471
 
476
- override async getTableSchema<ROW extends PartialObjectWithId>(
472
+ override async getTableSchema<ROW extends ObjectWithId>(
477
473
  table: string,
478
474
  ): Promise<JsonSchemaRootObject<ROW>> {
479
475
  const stats = await this.getTableProperties(table)
@@ -576,7 +572,7 @@ export class DatastoreDBTransaction implements DBTransaction {
576
572
  }
577
573
  }
578
574
 
579
- async getByIds<ROW extends PartialObjectWithId>(
575
+ async getByIds<ROW extends ObjectWithId>(
580
576
  table: string,
581
577
  ids: string[],
582
578
  opt?: CommonDBOptions | undefined,
@@ -584,7 +580,7 @@ export class DatastoreDBTransaction implements DBTransaction {
584
580
  return await this.db.getByIds(table, ids, { ...opt, tx: this })
585
581
  }
586
582
 
587
- async saveBatch<ROW extends PartialObjectWithId>(
583
+ async saveBatch<ROW extends ObjectWithId>(
588
584
  table: string,
589
585
  rows: ROW[],
590
586
  opt?: CommonDBSaveOptions<ROW> | undefined,
@@ -116,7 +116,7 @@ export interface DatastoreDBStreamOptions extends DatastoreDBOptions {
116
116
 
117
117
  export interface DatastoreDBOptions extends CommonDBOptions {}
118
118
 
119
- export interface DatastoreDBSaveOptions<ROW extends Partial<ObjectWithId> = any>
119
+ export interface DatastoreDBSaveOptions<ROW extends ObjectWithId>
120
120
  extends CommonDBSaveOptions<ROW> {}
121
121
 
122
122
  export interface DatastoreStats {
package/src/query.util.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PropertyFilter, Query } from '@google-cloud/datastore'
2
2
  import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
3
- import { PartialObjectWithId, StringMap } from '@naturalcycles/js-lib'
3
+ import { ObjectWithId, StringMap } from '@naturalcycles/js-lib'
4
4
 
5
5
  const FNAME_MAP: StringMap = {
6
6
  id: '__key__',
@@ -12,7 +12,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
12
12
  'not-in': 'NOT_IN',
13
13
  }
14
14
 
15
- export function dbQueryToDatastoreQuery<ROW extends PartialObjectWithId>(
15
+ export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
16
16
  dbQuery: Readonly<DBQuery<ROW>>,
17
17
  emptyQuery: Query,
18
18
  ): Query {