@naturalcycles/datastore-lib 3.38.2 → 3.38.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.
@@ -57,6 +57,11 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
57
57
  getTables(): Promise<string[]>;
58
58
  getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
59
59
  private getPRetryOptions;
60
+ /**
61
+ * Silently rollback the transaction.
62
+ * It may happen that transaction is already committed/rolled back, so we don't want to throw an error here.
63
+ */
64
+ private rollback;
60
65
  }
61
66
  /**
62
67
  * https://cloud.google.com/datastore/docs/concepts/transactions#datastore-datastore-transactional-update-nodejs
@@ -223,7 +223,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
223
223
  await datastoreTx.commit();
224
224
  }
225
225
  catch (err) {
226
- await datastoreTx.rollback();
226
+ await this.rollback(datastoreTx);
227
227
  throw err;
228
228
  }
229
229
  }
@@ -379,6 +379,19 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
379
379
  },
380
380
  };
381
381
  }
382
+ /**
383
+ * Silently rollback the transaction.
384
+ * It may happen that transaction is already committed/rolled back, so we don't want to throw an error here.
385
+ */
386
+ async rollback(datastoreTx) {
387
+ try {
388
+ await datastoreTx.rollback();
389
+ }
390
+ catch (err) {
391
+ // log the error, but don't re-throw, as this should be a graceful rollback
392
+ this.cfg.logger.error(err);
393
+ }
394
+ }
382
395
  }
383
396
  exports.DatastoreDB = DatastoreDB;
384
397
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.38.2",
3
+ "version": "3.38.3",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky",
@@ -374,7 +374,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
374
374
  await fn(tx)
375
375
  await datastoreTx.commit()
376
376
  } catch (err) {
377
- await datastoreTx.rollback()
377
+ await this.rollback(datastoreTx)
378
378
  throw err
379
379
  }
380
380
  }
@@ -549,6 +549,19 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
549
549
  },
550
550
  }
551
551
  }
552
+
553
+ /**
554
+ * Silently rollback the transaction.
555
+ * It may happen that transaction is already committed/rolled back, so we don't want to throw an error here.
556
+ */
557
+ private async rollback(datastoreTx: Transaction): Promise<void> {
558
+ try {
559
+ await datastoreTx.rollback()
560
+ } catch (err) {
561
+ // log the error, but don't re-throw, as this should be a graceful rollback
562
+ this.cfg.logger.error(err)
563
+ }
564
+ }
552
565
  }
553
566
 
554
567
  /**