@autofleet/sequelize-utils 5.1.3 → 5.1.4

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.
package/dist/index.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,12 +10,12 @@ const log = debug_1.default('sequelize-utils');
19
10
  const rollbackErrorText = 'rollback has been called on this transaction';
20
11
  const abortErrorText = 'Transaction cancelled due to request cancellation';
21
12
  exports.default = (sequelize) => {
22
- const transactionWithRetry = (funcToRun, retriesCount = 2, options) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const transactionWithRetry = async (funcToRun, retriesCount = 2, options) => {
23
14
  try {
24
- const transValue = yield sequelize.transaction(options || {}, (transaction) => __awaiter(void 0, void 0, void 0, function* () {
25
- const funcValue = yield funcToRun(transaction);
15
+ const transValue = await sequelize.transaction(options || {}, async (transaction) => {
16
+ const funcValue = await funcToRun(transaction);
26
17
  return funcValue;
27
- }));
18
+ });
28
19
  return transValue;
29
20
  }
30
21
  catch (e) {
@@ -38,22 +29,22 @@ exports.default = (sequelize) => {
38
29
  }
39
30
  throw e;
40
31
  }
41
- });
32
+ };
42
33
  // eslint-disable-next-line @typescript-eslint/ban-types
43
34
  const httpBasedTransaction = (req, cb) => {
44
35
  if (req.socket.destroyed) {
45
36
  log(abortErrorText);
46
37
  throw new Error(abortErrorText);
47
38
  }
48
- return sequelize.transaction((transaction) => __awaiter(void 0, void 0, void 0, function* () {
39
+ return sequelize.transaction(async (transaction) => {
49
40
  // https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
50
- const rollback = () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const rollback = async () => {
51
42
  log(abortErrorText);
52
- yield transaction.rollback();
53
- });
43
+ await transaction.rollback();
44
+ };
54
45
  req.socket.once('close', rollback);
55
46
  try {
56
- const response = yield cb(transaction);
47
+ const response = await cb(transaction);
57
48
  req.socket.removeListener('close', rollback);
58
49
  return response;
59
50
  }
@@ -64,7 +55,7 @@ exports.default = (sequelize) => {
64
55
  req.socket.removeListener('close', rollback);
65
56
  throw e;
66
57
  }
67
- }));
58
+ });
68
59
  };
69
60
  return {
70
61
  httpBasedTransaction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sequelize-utils",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es6",
3
+ "target": "es2020",
4
4
  "module": "commonjs",
5
5
  "declaration": true,
6
6
  "outDir": "./dist",