topkat-utils 1.2.100 → 1.2.102
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/coverage/clover.xml +1767 -0
- package/coverage/coverage-final.json +16 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/clean-stack-trace.ts.html +205 -0
- package/coverage/lcov-report/config.ts.html +340 -0
- package/coverage/lcov-report/error-utils.ts.html +700 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +326 -0
- package/coverage/lcov-report/is-empty.ts.html +103 -0
- package/coverage/lcov-report/is-nodejs.ts.html +109 -0
- package/coverage/lcov-report/is-object.ts.html +91 -0
- package/coverage/lcov-report/isset.ts.html +91 -0
- package/coverage/lcov-report/logger-utils.ts.html +1156 -0
- package/coverage/lcov-report/loop-utils.ts.html +382 -0
- package/coverage/lcov-report/object-utils.ts.html +1393 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/regexp-utils.ts.html +205 -0
- package/coverage/lcov-report/remove-circular-json-stringify.ts.html +139 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/string-utils.ts.html +922 -0
- package/coverage/lcov-report/timer-utils.ts.html +289 -0
- package/coverage/lcov-report/transaction-utils.ts.html +268 -0
- package/coverage/lcov.info +2151 -0
- package/dist/jest.config.d.ts +7 -0
- package/dist/jest.config.js +21 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/src/timer-utils.d.ts +2 -0
- package/dist/src/timer-utils.js +9 -1
- package/dist/src/timer-utils.js.map +1 -1
- package/dist/src/transaction-utils.js +3 -2
- package/dist/src/transaction-utils.js.map +1 -1
- package/dist/src/transaction-utils.spec.d.ts +1 -0
- package/dist/src/transaction-utils.spec.js +49 -0
- package/dist/src/transaction-utils.spec.js.map +1 -0
- package/jest.config.ts +22 -0
- package/package.json +14 -8
- package/src/timer-utils.ts +11 -0
- package/src/transaction-utils.spec.ts +74 -0
- package/src/transaction-utils.ts +3 -2
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
4
|
+
* https://jestjs.io/docs/configuration
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const config = {
|
|
8
|
+
clearMocks: true,
|
|
9
|
+
collectCoverage: true,
|
|
10
|
+
coverageDirectory: 'coverage',
|
|
11
|
+
coverageProvider: 'v8',
|
|
12
|
+
// testPathIgnorePatterns: ['dist/**/*'],
|
|
13
|
+
testTimeout: 9999,
|
|
14
|
+
transform: {
|
|
15
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
16
|
+
// '^.+\\.js$': '../../node_modules/babel-jest',
|
|
17
|
+
},
|
|
18
|
+
testRegex: ['.*\\.spec\\.[jt]sx?$'],
|
|
19
|
+
};
|
|
20
|
+
exports.default = config;
|
|
21
|
+
//# sourceMappingURL=jest.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAIH,MAAM,MAAM,GAAW;IACnB,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,UAAU;IAC7B,gBAAgB,EAAE,IAAI;IACtB,yCAAyC;IACzC,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE;QACP,aAAa,EAAE,SAAS;QACxB,gDAAgD;KACnD;IACD,SAAS,EAAE,CAAC,sBAAsB,CAAC;CACtC,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -14,3 +14,5 @@ export declare function waitUntilTrue(callback: any, timeoutSec?: number, errorA
|
|
|
14
14
|
* @param {Function} errorCallback default: e => C.error(e)
|
|
15
15
|
*/
|
|
16
16
|
export declare function executeInDelayedLoop(callback: any, time?: number, errorCallback?: (e: any) => any): Promise<void>;
|
|
17
|
+
/** Will first wait before calling callback every seconds configured in retrySeconds array */
|
|
18
|
+
export declare function retryWithDelay(callback: Function, retrySeconds: number[]): Promise<void>;
|
package/dist/src/timer-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeInDelayedLoop = exports.waitUntilTrue = exports.runAsync = exports.timeout = void 0;
|
|
3
|
+
exports.retryWithDelay = exports.executeInDelayedLoop = exports.waitUntilTrue = exports.runAsync = exports.timeout = void 0;
|
|
4
4
|
//----------------------------------------
|
|
5
5
|
// TIMEOUT UTILS
|
|
6
6
|
//----------------------------------------
|
|
@@ -59,4 +59,12 @@ async function executeInDelayedLoop(callback, time = 500, errorCallback = e => l
|
|
|
59
59
|
isExecuting = false;
|
|
60
60
|
}
|
|
61
61
|
exports.executeInDelayedLoop = executeInDelayedLoop;
|
|
62
|
+
/** Will first wait before calling callback every seconds configured in retrySeconds array */
|
|
63
|
+
async function retryWithDelay(callback, retrySeconds) {
|
|
64
|
+
for (const n of retrySeconds) {
|
|
65
|
+
await timeout(n * 1000);
|
|
66
|
+
await callback();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.retryWithDelay = retryWithDelay;
|
|
62
70
|
//# sourceMappingURL=timer-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer-utils.js","sourceRoot":"","sources":["../../src/timer-utils.ts"],"names":[],"mappings":";;;AACA,0CAA0C;AAC1C,gBAAgB;AAChB,0CAA0C;AAC1C,iDAAkD;AAClD,+CAAgD;AAGzC,KAAK,UAAU,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,GAAG,EAAE,GAAS,CAAC,IAAI,OAAO,IAA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EAAE,aAAa,CAAC,GAAG,iBAAiB,CAAC,KAAK,EAAS,CAAA;QACxE,IAAI;YACA,MAAM,QAAQ,EAAE,CAAA;YAChB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;SACtB;QAAC,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,GAAG,CAAC,CAAA;SACrB;KACJ;IACD,WAAW,GAAG,KAAK,CAAA;AACvB,CAAC;AAdD,oDAcC;AAED,6FAA6F;AACtF,KAAK,UAAU,cAAc,CAChC,QAAkB,EAClB,YAAsB;IAEtB,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE;QAC1B,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;QACvB,MAAM,QAAQ,EAAE,CAAA;KACnB;AACL,CAAC;AARD,wCAQC"}
|
|
@@ -31,11 +31,12 @@ async function transaction(name, asyncCallback, timeout = 120000, doNotThrow = f
|
|
|
31
31
|
reject = logger_utils_1.C.error;
|
|
32
32
|
queue[name].push(async () => {
|
|
33
33
|
try {
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
logger_utils_1.C.warning('Transaction
|
|
34
|
+
const to = setTimeout(() => {
|
|
35
|
+
logger_utils_1.C.warning('Transaction Timeout'); // in case not catched
|
|
36
36
|
reject(new Error('transactionTimeout'));
|
|
37
37
|
}, timeout);
|
|
38
38
|
const res = await asyncCallback();
|
|
39
|
+
clearTimeout(to);
|
|
39
40
|
resolve(res);
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-utils.js","sourceRoot":"","sources":["../../src/transaction-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,cAAc;AACd,0CAA0C;AAC1C,mCAA+B;AAC/B,iDAAkC;AAClC,+CAAuC;AAEvC,MAAM,kBAAkB,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;AAC/C,MAAM,KAAK,GAAG,EAAE,SAAS,EAAE,EAAE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AC,CAAC,KAAK,EAAE,EAAE,CAAA,CAAC,QAAQ;IAC/D,kBAAkB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA,CAAC,8BAA8B;AACnE,CAAC,CAAC,iEAAiE;AALnE,kDAKC;AACD,kEAAkE;AAElE,4EAA4E;AACrE,KAAK,UAAU,kBAAkB,CAAC,eAAe,EAAE,qBAAqB,GAAG,EAAE;IAChF,IAAI,GAAG,GAAG,KAAK,CAAA;IACf,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAAC,CAAA;IAC1D,OAAO,IAAA,aAAK,EAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,IAAI,kBAAkB,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE;QAC/F,IAAI,GAAG;YAAE,MAAK;QACd,MAAM,IAAA,qBAAO,EAAC,EAAE,CAAC,CAAA;KACpB;AACL,CAAC;AAPD,gDAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const transaction_utils_1 = require("./transaction-utils");
|
|
4
|
+
const timer_utils_1 = require("./timer-utils");
|
|
5
|
+
describe('TRANSACTION TEST', () => {
|
|
6
|
+
const statusArr = [];
|
|
7
|
+
const asyncCallback = i => async () => {
|
|
8
|
+
await (0, timer_utils_1.timeout)(1000);
|
|
9
|
+
statusArr.push(i);
|
|
10
|
+
};
|
|
11
|
+
it('should execute the async callback and resolve the result', async () => {
|
|
12
|
+
(0, transaction_utils_1.transaction)('test', asyncCallback(1), 1500);
|
|
13
|
+
(0, transaction_utils_1.transaction)('test', asyncCallback(2), 1500);
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
await (0, transaction_utils_1.transaction)('test', asyncCallback(3), 1500);
|
|
16
|
+
const timeSpent = Date.now() - now;
|
|
17
|
+
expect(statusArr).toEqual([1, 2, 3]);
|
|
18
|
+
expect(timeSpent < 5000).toEqual(true);
|
|
19
|
+
expect(timeSpent > 2999).toEqual(true);
|
|
20
|
+
});
|
|
21
|
+
it('Second run', async () => {
|
|
22
|
+
(0, transaction_utils_1.transaction)('test', asyncCallback(4), 1500);
|
|
23
|
+
(0, transaction_utils_1.transaction)('test', asyncCallback(5), 1500);
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
await (0, transaction_utils_1.transaction)('test', asyncCallback(6), 1500);
|
|
26
|
+
const timeSpent = Date.now() - now;
|
|
27
|
+
expect(statusArr).toEqual([1, 2, 3, 4, 5, 6]);
|
|
28
|
+
expect(timeSpent < 5000).toEqual(true);
|
|
29
|
+
expect(timeSpent > 2999).toEqual(true);
|
|
30
|
+
});
|
|
31
|
+
const infiniteCallback = async () => await (0, timer_utils_1.timeout)(5000);
|
|
32
|
+
it('Transaction timeout if the transaction is infinite and other transaction run correctly', async () => {
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
let hasErr = false;
|
|
35
|
+
try {
|
|
36
|
+
await (0, transaction_utils_1.transaction)('test', infiniteCallback, 1000);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
hasErr = true;
|
|
40
|
+
}
|
|
41
|
+
const timeSpent = Date.now() - now;
|
|
42
|
+
await (0, transaction_utils_1.transaction)('test', asyncCallback(7), 1500);
|
|
43
|
+
expect(hasErr).toEqual(true);
|
|
44
|
+
expect(statusArr).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
|
45
|
+
expect(timeSpent < 2000).toEqual(true);
|
|
46
|
+
expect(timeSpent > 999).toEqual(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=transaction-utils.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-utils.spec.js","sourceRoot":"","sources":["../../src/transaction-utils.spec.ts"],"names":[],"mappings":";;AAGA,2DAAiD;AAEjD,+CAAuC;AA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AAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEhD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtC,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzC,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Config } from 'jest'
|
|
7
|
+
|
|
8
|
+
const config: Config = {
|
|
9
|
+
clearMocks: true,
|
|
10
|
+
collectCoverage: true,
|
|
11
|
+
coverageDirectory: 'coverage',
|
|
12
|
+
coverageProvider: 'v8',
|
|
13
|
+
// testPathIgnorePatterns: ['dist/**/*'],
|
|
14
|
+
testTimeout: 9999,
|
|
15
|
+
transform: {
|
|
16
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
17
|
+
// '^.+\\.js$': '../../node_modules/babel-jest',
|
|
18
|
+
},
|
|
19
|
+
testRegex: ['.*\\.spec\\.[jt]sx?$'],
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "topkat-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.102",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"types": "index.ts",
|
|
6
6
|
"main": "dist",
|
|
@@ -10,20 +10,26 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/top-kat/utils"
|
|
13
|
+
"url": "git+https://github.com/top-kat/utils.git"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc",
|
|
17
|
-
"bump:major": "npm run build
|
|
18
|
-
"bump:minor": "npm run build
|
|
19
|
-
"bump:patch": "npm run build
|
|
17
|
+
"bump:major": "yarn test:ci && npm run build && node node_modules/bump-simple/bump-simple.js --major",
|
|
18
|
+
"bump:minor": "yarn test:ci && npm run build && node node_modules/bump-simple/bump-simple.js --minor",
|
|
19
|
+
"bump:patch": "yarn test:ci && npm run build && node node_modules/bump-simple/bump-simple.js --patch",
|
|
20
|
+
"test": "jest --watchAll",
|
|
21
|
+
"test:ci": "jest --ci --runInBand --maxConcurrency=1 --silent"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
24
|
+
"@types/jest": "^29.5.12",
|
|
22
25
|
"@types/node": "^18.11.18",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "latest",
|
|
27
|
+
"@typescript-eslint/parser": "latest",
|
|
23
28
|
"bump-simple": "^1.0.0",
|
|
24
29
|
"eslint": "^8.0.0",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
30
|
+
"jest": "^29.7.0",
|
|
31
|
+
"ts-jest": "^29.2.4",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "^4.9.5"
|
|
28
34
|
}
|
|
29
35
|
}
|
package/src/timer-utils.ts
CHANGED
|
@@ -55,4 +55,15 @@ export async function executeInDelayedLoop(callback, time = 500, errorCallback =
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
isExecuting = false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Will first wait before calling callback every seconds configured in retrySeconds array */
|
|
61
|
+
export async function retryWithDelay(
|
|
62
|
+
callback: Function,
|
|
63
|
+
retrySeconds: number[]
|
|
64
|
+
) {
|
|
65
|
+
for (const n of retrySeconds) {
|
|
66
|
+
await timeout(n * 1000)
|
|
67
|
+
await callback()
|
|
68
|
+
}
|
|
58
69
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { transaction } from './transaction-utils'
|
|
5
|
+
|
|
6
|
+
import { timeout } from './timer-utils'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('TRANSACTION TEST', () => {
|
|
10
|
+
const statusArr = [] as number[]
|
|
11
|
+
|
|
12
|
+
const asyncCallback = i => async () => {
|
|
13
|
+
await timeout(1000)
|
|
14
|
+
statusArr.push(i)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
it('should execute the async callback and resolve the result', async () => {
|
|
18
|
+
|
|
19
|
+
transaction('test', asyncCallback(1), 1500)
|
|
20
|
+
transaction('test', asyncCallback(2), 1500)
|
|
21
|
+
const now = Date.now()
|
|
22
|
+
await transaction('test', asyncCallback(3), 1500)
|
|
23
|
+
const timeSpent = Date.now() - now
|
|
24
|
+
|
|
25
|
+
expect(statusArr).toEqual([1, 2, 3])
|
|
26
|
+
|
|
27
|
+
expect(timeSpent < 5000).toEqual(true)
|
|
28
|
+
expect(timeSpent > 2999).toEqual(true)
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
it('Second run', async () => {
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
transaction('test', asyncCallback(4), 1500)
|
|
38
|
+
transaction('test', asyncCallback(5), 1500)
|
|
39
|
+
const now = Date.now()
|
|
40
|
+
await transaction('test', asyncCallback(6), 1500)
|
|
41
|
+
const timeSpent = Date.now() - now
|
|
42
|
+
|
|
43
|
+
expect(statusArr).toEqual([1, 2, 3, 4, 5, 6])
|
|
44
|
+
|
|
45
|
+
expect(timeSpent < 5000).toEqual(true)
|
|
46
|
+
expect(timeSpent > 2999).toEqual(true)
|
|
47
|
+
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const infiniteCallback = async () => await timeout(5000)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('Transaction timeout if the transaction is infinite and other transaction run correctly', async () => {
|
|
54
|
+
|
|
55
|
+
const now = Date.now()
|
|
56
|
+
let hasErr = false
|
|
57
|
+
try {
|
|
58
|
+
await transaction('test', infiniteCallback, 1000)
|
|
59
|
+
} catch (err) {
|
|
60
|
+
hasErr = true
|
|
61
|
+
}
|
|
62
|
+
const timeSpent = Date.now() - now
|
|
63
|
+
|
|
64
|
+
await transaction('test', asyncCallback(7), 1500)
|
|
65
|
+
|
|
66
|
+
expect(hasErr).toEqual(true)
|
|
67
|
+
|
|
68
|
+
expect(statusArr).toEqual([1, 2, 3, 4, 5, 6, 7])
|
|
69
|
+
|
|
70
|
+
expect(timeSpent < 2000).toEqual(true)
|
|
71
|
+
expect(timeSpent > 999).toEqual(true)
|
|
72
|
+
|
|
73
|
+
})
|
|
74
|
+
})
|
package/src/transaction-utils.ts
CHANGED
|
@@ -28,11 +28,12 @@ export async function transaction(name, asyncCallback, timeout = 120000, doNotTh
|
|
|
28
28
|
if (doNotThrow) reject = C.error
|
|
29
29
|
queue[name].push(async () => {
|
|
30
30
|
try {
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
C.warning('Transaction
|
|
31
|
+
const to = setTimeout(() => {
|
|
32
|
+
C.warning('Transaction Timeout') // in case not catched
|
|
33
33
|
reject(new Error('transactionTimeout'))
|
|
34
34
|
}, timeout)
|
|
35
35
|
const res = await asyncCallback()
|
|
36
|
+
clearTimeout(to)
|
|
36
37
|
resolve(res)
|
|
37
38
|
} catch (err) {
|
|
38
39
|
reject(err)
|