@autofleet/sequelize-utils 5.0.5 → 5.0.6
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 +18 -16
- package/package.json +1 -1
- package/src/index.ts +17 -16
package/dist/index.js
CHANGED
|
@@ -40,27 +40,29 @@ exports.default = (sequelize) => {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
43
|
-
const httpBasedTransaction = (req, cb) =>
|
|
43
|
+
const httpBasedTransaction = (req, cb) => {
|
|
44
44
|
if (req.aborted) {
|
|
45
45
|
log(abortErrorText);
|
|
46
46
|
throw new Error(abortErrorText);
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
catch (e) {
|
|
58
|
-
if (e.message.includes(rollbackErrorText)) {
|
|
59
|
-
throw new Error(abortErrorText);
|
|
48
|
+
return transactionWithRetry((transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
// https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
|
|
50
|
+
req.on('aborted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
log(abortErrorText);
|
|
52
|
+
yield transaction.rollback();
|
|
53
|
+
}));
|
|
54
|
+
try {
|
|
55
|
+
const response = yield cb(transaction);
|
|
56
|
+
return response;
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e.message.includes(rollbackErrorText)) {
|
|
60
|
+
throw new Error(abortErrorText);
|
|
61
|
+
}
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
64
66
|
return {
|
|
65
67
|
httpBasedTransaction,
|
|
66
68
|
transactionWithRetry,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -32,28 +32,29 @@ export default (sequelize: Sequelize): {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
35
|
-
const httpBasedTransaction = (req: any, cb: Function) =>
|
|
35
|
+
const httpBasedTransaction = (req: any, cb: Function) => {
|
|
36
36
|
if (req.aborted) {
|
|
37
37
|
log(abortErrorText);
|
|
38
38
|
throw new Error(abortErrorText);
|
|
39
39
|
}
|
|
40
|
+
return transactionWithRetry(async (transaction: Transaction) => {
|
|
41
|
+
// https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
|
|
42
|
+
req.on('aborted', async () => {
|
|
43
|
+
log(abortErrorText);
|
|
44
|
+
await transaction.rollback();
|
|
45
|
+
});
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return response;
|
|
50
|
-
} catch (e) {
|
|
51
|
-
if (e.message.includes(rollbackErrorText)) {
|
|
52
|
-
throw new Error(abortErrorText);
|
|
47
|
+
try {
|
|
48
|
+
const response = await cb(transaction);
|
|
49
|
+
return response;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e.message.includes(rollbackErrorText)) {
|
|
52
|
+
throw new Error(abortErrorText);
|
|
53
|
+
}
|
|
54
|
+
throw e;
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
57
58
|
|
|
58
59
|
return {
|
|
59
60
|
httpBasedTransaction,
|