anote-server-libs 0.6.3 → 0.6.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anote-server-libs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Helpers for express-TS servers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@types/memcached": "2.2.10",
|
|
20
20
|
"@types/mssql": "9.1.5",
|
|
21
|
-
"@types/pg": "8.11.
|
|
22
|
-
"ajv": "8.
|
|
21
|
+
"@types/pg": "8.11.10",
|
|
22
|
+
"ajv": "8.17.1",
|
|
23
23
|
"memcached": "2.2.2",
|
|
24
|
-
"mssql": "11.0.
|
|
25
|
-
"pg": "8.
|
|
24
|
+
"mssql": "11.0.1",
|
|
25
|
+
"pg": "8.13.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"express": "4.
|
|
29
|
-
"winston": "3.
|
|
28
|
+
"express": "4.12.1",
|
|
29
|
+
"winston": "3.17.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/express": "
|
|
32
|
+
"@types/express": "5.0.0",
|
|
33
33
|
"@types/node": "20.12.2",
|
|
34
|
-
"typescript": "5.
|
|
34
|
+
"typescript": "5.6.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -6,8 +6,12 @@ const utils_1 = require("./utils");
|
|
|
6
6
|
exports.withTransactionConfig = {
|
|
7
7
|
timeoutMillis: 15000
|
|
8
8
|
};
|
|
9
|
-
function withTransaction(repo, logger, previousMethod, lock) {
|
|
9
|
+
function withTransaction(repo, logger, previousMethod, lock, commitIfLost = true) {
|
|
10
10
|
return function (req, res, next) {
|
|
11
|
+
let commit = true;
|
|
12
|
+
if (!commitIfLost) {
|
|
13
|
+
req.once('close', () => commit = false);
|
|
14
|
+
}
|
|
11
15
|
const endTerminator = res.end.bind(res);
|
|
12
16
|
const jsonTerminator = (obj) => {
|
|
13
17
|
res.write((0, utils_1.jsonStringify)(obj) || '{}');
|
|
@@ -31,7 +35,7 @@ function withTransaction(repo, logger, previousMethod, lock) {
|
|
|
31
35
|
res.locals.dbClientCommit = (cb) => {
|
|
32
36
|
if (!res.locals.dbClientCommited) {
|
|
33
37
|
res.locals.dbClientCommited = true;
|
|
34
|
-
(repo.db ? dbClient.query('COMMIT') : dbClient.commit()).catch((err) => err).then((err) => {
|
|
38
|
+
(commit ? (repo.db ? dbClient.query('COMMIT') : dbClient.commit()) : Promise.reject(new Error('Client lost'))).catch((err) => err).then((err) => {
|
|
35
39
|
if (repo.db)
|
|
36
40
|
dbClient.release();
|
|
37
41
|
if (!(err instanceof Error)) {
|
|
@@ -13,8 +13,12 @@ export const withTransactionConfig = {
|
|
|
13
13
|
timeoutMillis: 15000
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export function withTransaction(repo: BaseModelRepository, logger: Logger, previousMethod: (req: Request, res: Response, next: NextFunction) => void, lock?: SystemLock) {
|
|
16
|
+
export function withTransaction(repo: BaseModelRepository, logger: Logger, previousMethod: (req: Request, res: Response, next: NextFunction) => void, lock?: SystemLock, commitIfLost = true) {
|
|
17
17
|
return function(req: Request, res: Response, next: NextFunction) {
|
|
18
|
+
let commit = true;
|
|
19
|
+
if(!commitIfLost) {
|
|
20
|
+
req.once('close', () => commit = false);
|
|
21
|
+
}
|
|
18
22
|
const endTerminator = res.end.bind(res);
|
|
19
23
|
const jsonTerminator = (obj: any) => {
|
|
20
24
|
res.write(jsonStringify(obj) || '{}');
|
|
@@ -41,7 +45,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
|
|
|
41
45
|
res.locals.dbClientCommit = (cb: (err: any) => any) => {
|
|
42
46
|
if(!res.locals.dbClientCommited) {
|
|
43
47
|
res.locals.dbClientCommited = true;
|
|
44
|
-
(repo.db ? dbClient.query('COMMIT') : dbClient.commit()).catch((err: any) => err).then((err: any) => {
|
|
48
|
+
(commit ? (repo.db ? dbClient.query('COMMIT') : dbClient.commit()) : Promise.reject(new Error('Client lost'))).catch((err: any) => err).then((err: any) => {
|
|
45
49
|
if(repo.db) dbClient.release();
|
|
46
50
|
if(!(err instanceof Error)) {
|
|
47
51
|
for(let i = 0; i < res.locals.dbClientOnCommit.length; i++) {
|
package/tsconfig.json
CHANGED
package/.vscode/settings.json
DELETED