@naturalcycles/datastore-lib 3.17.2 → 3.18.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.
@@ -55,9 +55,20 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
55
55
  if (!ids.length)
56
56
  return [];
57
57
  const keys = ids.map(id => this.key(table, id));
58
- const [entities] = await this.ds().get(keys);
59
- return (entities
60
- .map(e => this.mapId(e))
58
+ let rows;
59
+ try {
60
+ rows = (await this.ds().get(keys))[0];
61
+ }
62
+ catch (err) {
63
+ this.cfg.logger.log('datastore recreated on error');
64
+ // This is to debug "GCP Datastore Timeout issue"
65
+ const datastoreLib = require('@google-cloud/datastore');
66
+ const DS = datastoreLib.Datastore;
67
+ this.cachedDatastore = new DS(this.cfg);
68
+ throw err;
69
+ }
70
+ return (rows
71
+ .map(r => this.mapId(r))
61
72
  // Seems like datastore .get() method doesn't return items properly sorted by input ids, so we gonna sort them here
62
73
  // same ids are not expected here
63
74
  .sort((a, b) => (a.id > b.id ? 1 : -1)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -17,7 +17,7 @@
17
17
  "devDependencies": {
18
18
  "@google-cloud/datastore": "^6.0.0",
19
19
  "@naturalcycles/dev-lib": "^12.0.1",
20
- "@types/node": "^16.0.0",
20
+ "@types/node": "^17.0.8",
21
21
  "jest": "^27.0.4"
22
22
  },
23
23
  "files": [
@@ -113,11 +113,24 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
113
113
  ): Promise<ROW[]> {
114
114
  if (!ids.length) return []
115
115
  const keys = ids.map(id => this.key(table, id))
116
- const [entities] = await this.ds().get(keys)
116
+ let rows: any[]
117
+
118
+ try {
119
+ rows = (await this.ds().get(keys))[0]
120
+ } catch (err) {
121
+ this.cfg.logger.log('datastore recreated on error')
122
+
123
+ // This is to debug "GCP Datastore Timeout issue"
124
+ const datastoreLib = require('@google-cloud/datastore')
125
+ const DS = datastoreLib.Datastore as typeof Datastore
126
+ this.cachedDatastore = new DS(this.cfg)
127
+
128
+ throw err
129
+ }
117
130
 
118
131
  return (
119
- (entities as any[])
120
- .map(e => this.mapId<ROW>(e))
132
+ rows
133
+ .map(r => this.mapId<ROW>(r))
121
134
  // Seems like datastore .get() method doesn't return items properly sorted by input ids, so we gonna sort them here
122
135
  // same ids are not expected here
123
136
  .sort((a, b) => (a.id > b.id ? 1 : -1))