@naturalcycles/datastore-lib 4.9.0 → 4.11.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.
@@ -128,7 +128,7 @@ export class DatastoreDB extends BaseCommonDB {
128
128
  catch (err) {
129
129
  if (err instanceof TimeoutError) {
130
130
  _errorDataAppend(err, {
131
- fingerprint: [DATASTORE_TIMEOUT],
131
+ fingerprint: DATASTORE_TIMEOUT,
132
132
  });
133
133
  }
134
134
  throw err;
@@ -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);
@@ -232,7 +232,7 @@ export class DatastoreDB extends BaseCommonDB {
232
232
  catch (err) {
233
233
  if (err instanceof TimeoutError) {
234
234
  _errorDataAppend(err, {
235
- fingerprint: [DATASTORE_TIMEOUT],
235
+ fingerprint: DATASTORE_TIMEOUT,
236
236
  });
237
237
  }
238
238
  // console.log(`datastore.save ${kind}`, { obj, entity })
@@ -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)
@@ -450,7 +449,7 @@ export class DatastoreDB extends BaseCommonDB {
450
449
  logger: this.cfg.logger,
451
450
  // not appending fingerprint here, otherwise it would just group all kinds of errors, not just Timeout errors
452
451
  // errorData: {
453
- // fingerprint: [DATASTORE_TIMEOUT],
452
+ // fingerprint: DATASTORE_TIMEOUT,
454
453
  // },
455
454
  };
456
455
  }
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.11.0",
5
5
  "description": "Opinionated library to work with Google Datastore, implements CommonDB",
6
6
  "dependencies": {
7
7
  "@google-cloud/datastore": "^10",
@@ -199,7 +199,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
199
199
  } catch (err) {
200
200
  if (err instanceof TimeoutError) {
201
201
  _errorDataAppend(err, {
202
- fingerprint: [DATASTORE_TIMEOUT],
202
+ fingerprint: DATASTORE_TIMEOUT,
203
203
  })
204
204
  }
205
205
  throw err
@@ -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
  )
@@ -364,7 +364,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
364
364
  } catch (err) {
365
365
  if (err instanceof TimeoutError) {
366
366
  _errorDataAppend(err, {
367
- fingerprint: [DATASTORE_TIMEOUT],
367
+ fingerprint: DATASTORE_TIMEOUT,
368
368
  })
369
369
  }
370
370
 
@@ -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
 
@@ -638,7 +638,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
638
638
  logger: this.cfg.logger,
639
639
  // not appending fingerprint here, otherwise it would just group all kinds of errors, not just Timeout errors
640
640
  // errorData: {
641
- // fingerprint: [DATASTORE_TIMEOUT],
641
+ // fingerprint: DATASTORE_TIMEOUT,
642
642
  // },
643
643
  }
644
644
  }