@autofleet/sequelize-utils 5.1.1 → 5.1.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.
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +7 -6
package/dist/index.js
CHANGED
|
@@ -19,9 +19,9 @@ const log = debug_1.default('sequelize-utils');
|
|
|
19
19
|
const rollbackErrorText = 'rollback has been called on this transaction';
|
|
20
20
|
const abortErrorText = 'Transaction cancelled due to request cancellation';
|
|
21
21
|
exports.default = (sequelize) => {
|
|
22
|
-
const transactionWithRetry = (funcToRun, retriesCount = 2) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const transactionWithRetry = (funcToRun, retriesCount = 2, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
try {
|
|
24
|
-
const transValue = yield sequelize.transaction((transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const transValue = yield sequelize.transaction(options || {}, (transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
const funcValue = yield funcToRun(transaction);
|
|
26
26
|
return funcValue;
|
|
27
27
|
}));
|
|
@@ -51,7 +51,7 @@ exports.default = (sequelize) => {
|
|
|
51
51
|
log(abortErrorText);
|
|
52
52
|
yield transaction.rollback();
|
|
53
53
|
});
|
|
54
|
-
req.socket.
|
|
54
|
+
req.socket.once('close', rollback);
|
|
55
55
|
try {
|
|
56
56
|
const response = yield cb(transaction);
|
|
57
57
|
req.socket.removeListener('close', rollback);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,12 +11,13 @@ export default (sequelize: Sequelize): {
|
|
|
11
11
|
transactionWithRetry: any,
|
|
12
12
|
httpBasedTransaction: any
|
|
13
13
|
} => {
|
|
14
|
-
const transactionWithRetry = async (funcToRun: any, retriesCount = 2): Promise<any> => {
|
|
14
|
+
const transactionWithRetry = async (funcToRun: any, retriesCount = 2, options?: any): Promise<any> => {
|
|
15
15
|
try {
|
|
16
|
-
const transValue = await sequelize.transaction(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const transValue = await sequelize.transaction(options || {},
|
|
17
|
+
async (transaction) => {
|
|
18
|
+
const funcValue = await funcToRun(transaction);
|
|
19
|
+
return funcValue;
|
|
20
|
+
});
|
|
20
21
|
return transValue;
|
|
21
22
|
} catch (e) {
|
|
22
23
|
if (e instanceof DatabaseError) {
|
|
@@ -43,7 +44,7 @@ export default (sequelize: Sequelize): {
|
|
|
43
44
|
log(abortErrorText);
|
|
44
45
|
await transaction.rollback();
|
|
45
46
|
};
|
|
46
|
-
req.socket.
|
|
47
|
+
req.socket.once('close', rollback);
|
|
47
48
|
|
|
48
49
|
try {
|
|
49
50
|
const response = await cb(transaction);
|