@autofleet/sequelize-utils 5.0.9 → 5.1.0
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 +7 -9
- package/package.json +6 -1
- package/src/index.ts +7 -10
- package/tsconfig.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,29 +41,27 @@ exports.default = (sequelize) => {
|
|
|
41
41
|
});
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
43
43
|
const httpBasedTransaction = (req, cb) => {
|
|
44
|
-
if (req.
|
|
44
|
+
if (req.socket.destroyed) {
|
|
45
45
|
log(abortErrorText);
|
|
46
46
|
throw new Error(abortErrorText);
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return sequelize.transaction((transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
49
|
// https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
|
|
50
|
-
|
|
50
|
+
const rollback = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
log(abortErrorText);
|
|
52
52
|
yield transaction.rollback();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
req.on('aborted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
log(abortErrorText);
|
|
57
|
-
yield transaction.rollback();
|
|
58
|
-
}));
|
|
53
|
+
});
|
|
54
|
+
req.socket.on('close', rollback);
|
|
59
55
|
try {
|
|
60
56
|
const response = yield cb(transaction);
|
|
57
|
+
req.socket.removeListener('close', rollback);
|
|
61
58
|
return response;
|
|
62
59
|
}
|
|
63
60
|
catch (e) {
|
|
64
61
|
if (e.message.includes(rollbackErrorText)) {
|
|
65
62
|
throw new Error(abortErrorText);
|
|
66
63
|
}
|
|
64
|
+
req.socket.on('close', rollback);
|
|
67
65
|
throw e;
|
|
68
66
|
}
|
|
69
67
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sequelize-utils",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
"test-local": "jest --forceExit",
|
|
14
14
|
"coverage": "jest --coverage --forceExit --runInBand && rm -rf ./coverage"
|
|
15
15
|
},
|
|
16
|
+
"jest": {
|
|
17
|
+
"testEnvironment": "node"
|
|
18
|
+
},
|
|
16
19
|
"author": "",
|
|
17
20
|
"license": "ISC",
|
|
18
21
|
"dependencies": {
|
|
22
|
+
"@autofleet/network": "^1.3.7",
|
|
19
23
|
"debug": "^4.3.2",
|
|
20
24
|
"jest": "^27.0.6",
|
|
21
25
|
"sequelize": "^5.22.3"
|
|
@@ -29,6 +33,7 @@
|
|
|
29
33
|
"@typescript-eslint/eslint-plugin": "^4.28.3",
|
|
30
34
|
"@typescript-eslint/parser": "^4.28.3",
|
|
31
35
|
"axios": "^0.26.1",
|
|
36
|
+
"bluebird": "^3.7.2",
|
|
32
37
|
"eslint": "^7.31.0",
|
|
33
38
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
34
39
|
"eslint-plugin-import": "^2.23.4",
|
package/src/index.ts
CHANGED
|
@@ -33,30 +33,27 @@ export default (sequelize: Sequelize): {
|
|
|
33
33
|
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
35
35
|
const httpBasedTransaction = (req: any, cb: Function) => {
|
|
36
|
-
if (req.
|
|
36
|
+
if (req.socket.destroyed) {
|
|
37
37
|
log(abortErrorText);
|
|
38
38
|
throw new Error(abortErrorText);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return sequelize.transaction(async (transaction: Transaction) => {
|
|
41
41
|
// https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
|
|
42
|
-
|
|
42
|
+
const rollback = async () => {
|
|
43
43
|
log(abortErrorText);
|
|
44
44
|
await transaction.rollback();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
req.on('aborted', async () => {
|
|
49
|
-
log(abortErrorText);
|
|
50
|
-
await transaction.rollback();
|
|
51
|
-
});
|
|
45
|
+
};
|
|
46
|
+
req.socket.on('close', rollback);
|
|
52
47
|
|
|
53
48
|
try {
|
|
54
49
|
const response = await cb(transaction);
|
|
50
|
+
req.socket.removeListener('close', rollback);
|
|
55
51
|
return response;
|
|
56
52
|
} catch (e) {
|
|
57
53
|
if (e.message.includes(rollbackErrorText)) {
|
|
58
54
|
throw new Error(abortErrorText);
|
|
59
55
|
}
|
|
56
|
+
req.socket.on('close', rollback);
|
|
60
57
|
throw e;
|
|
61
58
|
}
|
|
62
59
|
});
|