@naturalcycles/datastore-lib 4.9.0 → 4.10.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.
@@ -170,7 +170,7 @@ export class DatastoreDB extends BaseCommonDB {
170
170
  }
171
171
  async runQueryCount(dbQuery, opt = {}) {
172
172
  const ds = await this.ds();
173
- const q = dbQueryToDatastoreQuery(dbQuery.select([]), ds.createQuery(dbQuery.table), await this.getPropertyFilter());
173
+ const q = dbQueryToDatastoreQuery(dbQuery, ds.createQuery(dbQuery.table), await this.getPropertyFilter());
174
174
  const aq = ds.createAggregationQuery(q).count('count');
175
175
  const dsOpt = this.getRunQueryOptions(opt);
176
176
  const [entities] = await ds.runAggregationQuery(aq, dsOpt);
@@ -331,15 +331,14 @@ export class DatastoreDB extends BaseCommonDB {
331
331
  const [stats] = await ds.runQuery(q);
332
332
  return stats;
333
333
  }
334
- mapId(o, preserveKey = false) {
334
+ mapId(o) {
335
335
  if (!o)
336
336
  return o;
337
337
  const r = {
338
338
  ...o,
339
339
  id: this.getKey(this.getDsKey(o)),
340
340
  };
341
- if (!preserveKey)
342
- delete r[this.KEY];
341
+ delete r[this.KEY];
343
342
  return r;
344
343
  }
345
344
  // if key field exists on entity, it will be used as key (prevent to duplication of numeric keyed entities)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
3
  "type": "module",
4
- "version": "4.9.0",
4
+ "version": "4.10.0",
5
5
  "description": "Opinionated library to work with Google Datastore, implements CommonDB",
6
6
  "dependencies": {
7
7
  "@google-cloud/datastore": "^10",
@@ -264,7 +264,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
264
264
  ): Promise<number> {
265
265
  const ds = await this.ds()
266
266
  const q = dbQueryToDatastoreQuery(
267
- dbQuery.select([]),
267
+ dbQuery,
268
268
  ds.createQuery(dbQuery.table),
269
269
  await this.getPropertyFilter(),
270
270
  )
@@ -395,7 +395,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
395
395
  await this.getPropertyFilter(),
396
396
  )
397
397
  const dsOpt = this.getRunQueryOptions(opt)
398
- const { rows } = await this.runDatastoreQuery<ROW>(datastoreQuery, dsOpt)
398
+ const { rows } = await this.runDatastoreQuery<ObjectWithId>(datastoreQuery, dsOpt)
399
399
  return await this.deleteByIds(
400
400
  q.table,
401
401
  rows.map(obj => obj.id),
@@ -504,13 +504,13 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
504
504
  return stats
505
505
  }
506
506
 
507
- private mapId<T extends ObjectWithId>(o: any, preserveKey = false): T {
507
+ private mapId<T extends ObjectWithId>(o: any): T {
508
508
  if (!o) return o
509
509
  const r = {
510
510
  ...o,
511
511
  id: this.getKey(this.getDsKey(o)!),
512
512
  }
513
- if (!preserveKey) delete r[this.KEY]
513
+ delete r[this.KEY]
514
514
  return r
515
515
  }
516
516