anote-server-libs 0.5.2 → 0.6.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.
|
@@ -8,23 +8,33 @@ function promiseAllStepN(n, list) {
|
|
|
8
8
|
const head = list;
|
|
9
9
|
const resolved = [];
|
|
10
10
|
let processed = 0;
|
|
11
|
-
return new Promise(resolve => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
12
|
head.forEach(x => {
|
|
13
|
-
const res = x()
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const res = x().then(y => {
|
|
14
|
+
runNext();
|
|
15
|
+
return [true, y];
|
|
16
|
+
}).catch(y => {
|
|
16
17
|
runNext();
|
|
17
|
-
return y;
|
|
18
|
+
return [false, y];
|
|
18
19
|
});
|
|
20
|
+
resolved.push(res);
|
|
19
21
|
});
|
|
20
22
|
function runNext() {
|
|
21
23
|
if (processed === tail.length) {
|
|
22
|
-
|
|
24
|
+
Promise.all(resolved).then(ys => {
|
|
25
|
+
const ny = ys.find(y => !y[0]);
|
|
26
|
+
if (ny)
|
|
27
|
+
return reject(ny[1]);
|
|
28
|
+
resolve(ys.map(y => y[1]));
|
|
29
|
+
});
|
|
23
30
|
}
|
|
24
31
|
else {
|
|
25
|
-
resolved.push(tail[processed]().then(
|
|
32
|
+
resolved.push(tail[processed]().then(y => {
|
|
33
|
+
runNext();
|
|
34
|
+
return [true, y];
|
|
35
|
+
}).catch(y => {
|
|
26
36
|
runNext();
|
|
27
|
-
return
|
|
37
|
+
return [false, y];
|
|
28
38
|
}));
|
|
29
39
|
processed++;
|
|
30
40
|
}
|
|
@@ -13,22 +13,31 @@ export function promiseAllStepN<T>(n: number, list: (() => Promise<T>)[]): Promi
|
|
|
13
13
|
const head = list;
|
|
14
14
|
const resolved: any[] = [];
|
|
15
15
|
let processed = 0;
|
|
16
|
-
return new Promise(resolve => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
17
|
head.forEach(x => {
|
|
18
|
-
const res = x()
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const res = x().then(y => {
|
|
19
|
+
runNext();
|
|
20
|
+
return [true, y];
|
|
21
|
+
}).catch(y => {
|
|
21
22
|
runNext();
|
|
22
|
-
return y;
|
|
23
|
+
return [false, y];
|
|
23
24
|
});
|
|
25
|
+
resolved.push(res);
|
|
24
26
|
});
|
|
25
27
|
function runNext() {
|
|
26
28
|
if(processed === tail.length) {
|
|
27
|
-
|
|
29
|
+
Promise.all(resolved).then(ys => {
|
|
30
|
+
const ny = ys.find(y => !y[0]);
|
|
31
|
+
if(ny) return reject(ny[1]);
|
|
32
|
+
resolve(ys.map(y => y[1]));
|
|
33
|
+
});
|
|
28
34
|
} else {
|
|
29
|
-
resolved.push(tail[processed]().then(
|
|
35
|
+
resolved.push(tail[processed]().then(y => {
|
|
36
|
+
runNext();
|
|
37
|
+
return [true, y];
|
|
38
|
+
}).catch(y => {
|
|
30
39
|
runNext();
|
|
31
|
-
return
|
|
40
|
+
return [false, y];
|
|
32
41
|
}));
|
|
33
42
|
processed++;
|
|
34
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anote-server-libs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Helpers for express-TS servers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"winston": "3.11.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/express": "4.17.
|
|
32
|
+
"@types/express": "4.17.21",
|
|
33
33
|
"@types/node": "18.15.0",
|
|
34
|
-
"typescript": "5.
|
|
34
|
+
"typescript": "5.3.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTransaction = void 0;
|
|
3
|
+
exports.withTransaction = exports.withTransactionConfig = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
+
exports.withTransactionConfig = {
|
|
6
|
+
timeoutMillis: 15000
|
|
7
|
+
};
|
|
5
8
|
function withTransaction(repo, logger, previousMethod, lock) {
|
|
6
9
|
return function (req, res, next) {
|
|
7
10
|
const endTerminator = res.end.bind(res);
|
|
@@ -12,7 +15,7 @@ function withTransaction(repo, logger, previousMethod, lock) {
|
|
|
12
15
|
const connectTimeoutHandler = setTimeout(() => {
|
|
13
16
|
logger.error('Error timed out getting a client, exiting...');
|
|
14
17
|
process.exit(22);
|
|
15
|
-
},
|
|
18
|
+
}, exports.withTransactionConfig.timeoutMillis);
|
|
16
19
|
Promise.all([
|
|
17
20
|
repo.db ? repo.db.connect() : Promise.resolve(undefined),
|
|
18
21
|
repo.dbMssql ? Promise.resolve(repo.dbMssql.transaction()) : Promise.resolve(undefined)
|
|
@@ -5,9 +5,14 @@ import {jsonStringify, utils} from './utils';
|
|
|
5
5
|
|
|
6
6
|
export const enum SystemLock {
|
|
7
7
|
CHECK_CROSSING = 1,
|
|
8
|
-
FLUSH_CALLS = 2
|
|
8
|
+
FLUSH_CALLS = 2,
|
|
9
|
+
TX_CHECK = 3
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
export const withTransactionConfig = {
|
|
13
|
+
timeoutMillis: 15000
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
export function withTransaction(repo: BaseModelRepository, logger: Logger, previousMethod: (req: Request, res: Response, next: NextFunction) => void, lock?: SystemLock) {
|
|
12
17
|
return function(req: Request, res: Response, next: NextFunction) {
|
|
13
18
|
const endTerminator = res.end.bind(res);
|
|
@@ -19,7 +24,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
|
|
|
19
24
|
// Timed out getting a client, restart worker or process...
|
|
20
25
|
logger.error('Error timed out getting a client, exiting...');
|
|
21
26
|
process.exit(22);
|
|
22
|
-
},
|
|
27
|
+
}, withTransactionConfig.timeoutMillis);
|
|
23
28
|
Promise.all([
|
|
24
29
|
repo.db ? repo.db.connect() : Promise.resolve(undefined),
|
|
25
30
|
repo.dbMssql ? Promise.resolve(repo.dbMssql.transaction()) : Promise.resolve(undefined)
|