@autofleet/sequelize-utils 5.0.5 → 5.0.9
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 +23 -16
- package/package.json +4 -1
- package/src/index.ts +22 -15
package/dist/index.js
CHANGED
|
@@ -40,27 +40,34 @@ 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
|
-
const response = yield cb(transaction);
|
|
55
|
-
return response;
|
|
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
|
+
if (req.aborted) {
|
|
51
|
+
log(abortErrorText);
|
|
52
|
+
yield transaction.rollback();
|
|
53
|
+
return null;
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
req.on('aborted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
log(abortErrorText);
|
|
57
|
+
yield transaction.rollback();
|
|
58
|
+
}));
|
|
59
|
+
try {
|
|
60
|
+
const response = yield cb(transaction);
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (e.message.includes(rollbackErrorText)) {
|
|
65
|
+
throw new Error(abortErrorText);
|
|
66
|
+
}
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
64
71
|
return {
|
|
65
72
|
httpBasedTransaction,
|
|
66
73
|
transactionWithRetry,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sequelize-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/bluebird": "^3.5.36",
|
|
25
25
|
"@types/debug": "^4.1.6",
|
|
26
|
+
"@types/express": "^4.17.13",
|
|
26
27
|
"@types/jest": "^26.0.24",
|
|
27
28
|
"@types/validator": "^13.6.3",
|
|
28
29
|
"@typescript-eslint/eslint-plugin": "^4.28.3",
|
|
29
30
|
"@typescript-eslint/parser": "^4.28.3",
|
|
31
|
+
"axios": "^0.26.1",
|
|
30
32
|
"eslint": "^7.31.0",
|
|
31
33
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
32
34
|
"eslint-plugin-import": "^2.23.4",
|
|
35
|
+
"express": "^4.17.3",
|
|
33
36
|
"pg": "^8.6.0",
|
|
34
37
|
"ts-jest": "^27.0.3",
|
|
35
38
|
"ts-node": "^10.1.0",
|
package/src/index.ts
CHANGED
|
@@ -32,28 +32,35 @@ 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
|
+
if (req.aborted) {
|
|
43
|
+
log(abortErrorText);
|
|
44
|
+
await transaction.rollback();
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
48
|
+
req.on('aborted', async () => {
|
|
49
|
+
log(abortErrorText);
|
|
50
|
+
await transaction.rollback();
|
|
51
|
+
});
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
try {
|
|
54
|
+
const response = await cb(transaction);
|
|
55
|
+
return response;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e.message.includes(rollbackErrorText)) {
|
|
58
|
+
throw new Error(abortErrorText);
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
57
64
|
|
|
58
65
|
return {
|
|
59
66
|
httpBasedTransaction,
|