@naturalcycles/datastore-lib 3.27.2 → 3.27.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.
@@ -56,7 +56,7 @@ class DatastoreStreamReadable extends node_stream_1.Readable {
56
56
  });
57
57
  }
58
58
  catch (err) {
59
- console.error(`DatastoreStreamReadable error!\n`, {
59
+ console.log(`DatastoreStreamReadable error!\n`, {
60
60
  table: this.table,
61
61
  rowsRetrieved: this.rowsRetrieved,
62
62
  }, err);
@@ -21,6 +21,7 @@ const RETRY_ON = [
21
21
  ].map(s => s.toLowerCase());
22
22
  // Examples of errors:
23
23
  // UNKNOWN: Stream removed
24
+ const DATASTORE_TIMEOUT = 'DATASTORE_TIMEOUT';
24
25
  const methodMap = {
25
26
  insert: 'insert',
26
27
  update: 'update',
@@ -91,7 +92,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
91
92
  timeout: this.cfg.timeout,
92
93
  errorData: {
93
94
  // This error will be grouped ACROSS all endpoints and usages
94
- fingerprint: ['DATASTORE_TIMEOUT'],
95
+ fingerprint: [DATASTORE_TIMEOUT],
95
96
  },
96
97
  });
97
98
  rows = r[0];
@@ -385,6 +386,9 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
385
386
  logFailures: true,
386
387
  // logAll: true,
387
388
  logger: this.cfg.logger,
389
+ errorData: {
390
+ fingerprint: [DATASTORE_TIMEOUT],
391
+ },
388
392
  };
389
393
  }
390
394
  }
@@ -12,4 +12,4 @@ var DatastoreType;
12
12
  DatastoreType["DATE_TIME"] = "Date/Time";
13
13
  DatastoreType["Boolean"] = "Boolean";
14
14
  DatastoreType["NULL"] = "NULL";
15
- })(DatastoreType = exports.DatastoreType || (exports.DatastoreType = {}));
15
+ })(DatastoreType || (exports.DatastoreType = DatastoreType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.27.2",
3
+ "version": "3.27.3",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@naturalcycles/dev-lib": "^13.0.0",
16
- "@types/node": "^18.7.2",
16
+ "@types/node": "^20.4.1",
17
17
  "jest": "^29.0.3"
18
18
  },
19
19
  "files": [
@@ -17,7 +17,11 @@ export class DatastoreStreamReadable<T = any> extends Readable implements Readab
17
17
 
18
18
  private opt: DatastoreDBStreamOptions & { batchSize: number }
19
19
 
20
- constructor(private q: Query, opt: DatastoreDBStreamOptions, private logger: CommonLogger) {
20
+ constructor(
21
+ private q: Query,
22
+ opt: DatastoreDBStreamOptions,
23
+ private logger: CommonLogger,
24
+ ) {
21
25
  super({ objectMode: true })
22
26
 
23
27
  this.opt = {
@@ -74,7 +78,7 @@ export class DatastoreStreamReadable<T = any> extends Readable implements Readab
74
78
  },
75
79
  )
76
80
  } catch (err) {
77
- console.error(
81
+ console.log(
78
82
  `DatastoreStreamReadable error!\n`,
79
83
  {
80
84
  table: this.table,
@@ -59,6 +59,8 @@ const RETRY_ON = [
59
59
  // Examples of errors:
60
60
  // UNKNOWN: Stream removed
61
61
 
62
+ const DATASTORE_TIMEOUT = 'DATASTORE_TIMEOUT'
63
+
62
64
  const methodMap: Record<CommonDBSaveMethod, string> = {
63
65
  insert: 'insert',
64
66
  update: 'update',
@@ -79,7 +81,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
79
81
  }
80
82
  }
81
83
 
82
- public cfg: DatastoreDBCfg & { logger: CommonLogger }
84
+ cfg: DatastoreDBCfg & { logger: CommonLogger }
83
85
 
84
86
  private cachedDatastore?: Datastore
85
87
 
@@ -154,15 +156,18 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
154
156
  timeout: this.cfg.timeout,
155
157
  errorData: {
156
158
  // This error will be grouped ACROSS all endpoints and usages
157
- fingerprint: ['DATASTORE_TIMEOUT'],
159
+ fingerprint: [DATASTORE_TIMEOUT],
158
160
  },
159
161
  })
160
162
  rows = r[0]
161
163
  }
162
164
  } else {
163
- rows = await pRetry(async () => {
164
- return (await this.ds().get(keys))[0]
165
- }, this.getPRetryOptions(`datastore.getByIds(${table})`))
165
+ rows = await pRetry(
166
+ async () => {
167
+ return (await this.ds().get(keys))[0]
168
+ },
169
+ this.getPRetryOptions(`datastore.getByIds(${table})`),
170
+ )
166
171
  }
167
172
 
168
173
  return (
@@ -278,9 +283,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
278
283
 
279
284
  const method = methodMap[opt.saveMethod || 'upsert'] || 'save'
280
285
 
281
- const save = pRetryFn(async (batch: DatastorePayload<ROW>[]) => {
282
- await (opt.tx || this.ds())[method](batch)
283
- }, this.getPRetryOptions(`DatastoreLib.saveBatch(${table})`))
286
+ const save = pRetryFn(
287
+ async (batch: DatastorePayload<ROW>[]) => {
288
+ await (opt.tx || this.ds())[method](batch)
289
+ },
290
+ this.getPRetryOptions(`DatastoreLib.saveBatch(${table})`),
291
+ )
284
292
 
285
293
  try {
286
294
  const chunks = _chunk(entities, MAX_ITEMS)
@@ -534,6 +542,9 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
534
542
  logFailures: true,
535
543
  // logAll: true,
536
544
  logger: this.cfg.logger,
545
+ errorData: {
546
+ fingerprint: [DATASTORE_TIMEOUT],
547
+ },
537
548
  }
538
549
  }
539
550
  }