@crowdin/app-project-module 0.20.4 → 0.20.6
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/out/storage/mysql.js +19 -11
- package/out/storage/postgre.js +19 -11
- package/out/util/index.d.ts +1 -0
- package/out/util/index.js +18 -1
- package/package.json +1 -1
package/out/storage/mysql.js
CHANGED
|
@@ -13,6 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MySQLStorage = void 0;
|
|
16
|
+
const util_1 = require("../util");
|
|
16
17
|
class MySQLStorage {
|
|
17
18
|
constructor(config) {
|
|
18
19
|
this.mysql = require('mysql2/promise');
|
|
@@ -24,19 +25,26 @@ class MySQLStorage {
|
|
|
24
25
|
}
|
|
25
26
|
executeQuery(command) {
|
|
26
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return res;
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
if (connection) {
|
|
28
|
+
return (0, util_1.executeWithRetry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
let connection;
|
|
30
|
+
try {
|
|
31
|
+
connection = yield this.mysql.createConnection(this.config);
|
|
32
|
+
const res = yield command(connection);
|
|
36
33
|
yield connection.end();
|
|
34
|
+
return res;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (connection) {
|
|
38
|
+
try {
|
|
39
|
+
yield connection.end();
|
|
40
|
+
}
|
|
41
|
+
catch (nestedError) {
|
|
42
|
+
throw nestedError;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
40
48
|
});
|
|
41
49
|
}
|
|
42
50
|
migrate() {
|
package/out/storage/postgre.js
CHANGED
|
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.PostgreStorage = void 0;
|
|
14
14
|
const pg_1 = require("pg");
|
|
15
|
+
const util_1 = require("../util");
|
|
15
16
|
class PostgreStorage {
|
|
16
17
|
constructor(config) {
|
|
17
18
|
this.dbPromise = new Promise((res, rej) => {
|
|
@@ -22,17 +23,24 @@ class PostgreStorage {
|
|
|
22
23
|
}
|
|
23
24
|
executeQuery(command) {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
return (0, util_1.executeWithRetry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const client = new pg_1.Client(this.config);
|
|
28
|
+
try {
|
|
29
|
+
yield client.connect();
|
|
30
|
+
const res = yield command(client);
|
|
31
|
+
yield client.end();
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
yield client.end();
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
catch (nestedError) {
|
|
40
|
+
throw nestedError;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
migrate() {
|
package/out/util/index.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare function getMessage(err: any): any;
|
|
|
9
9
|
export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
|
|
10
10
|
export declare function encryptData(config: Config, data: string): string;
|
|
11
11
|
export declare function decryptData(config: Config, data: string): string;
|
|
12
|
+
export declare function executeWithRetry<T>(func: () => Promise<T>, numOfRetries?: number): Promise<T>;
|
package/out/util/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
|
|
31
|
+
exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
|
|
32
32
|
const crypto = __importStar(require("crypto-js"));
|
|
33
33
|
const storage_1 = require("../storage");
|
|
34
34
|
class CodeError extends Error {
|
|
@@ -103,3 +103,20 @@ function decryptData(config, data) {
|
|
|
103
103
|
return crypto.AES.decrypt(data, config.cryptoSecret || config.clientSecret).toString(crypto.enc.Utf8);
|
|
104
104
|
}
|
|
105
105
|
exports.decryptData = decryptData;
|
|
106
|
+
function executeWithRetry(func, numOfRetries = 2) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
for (let i = 0; i <= numOfRetries; i++) {
|
|
109
|
+
try {
|
|
110
|
+
const result = yield func();
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (i === numOfRetries) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
throw new Error('Failed to process request with retry');
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
exports.executeWithRetry = executeWithRetry;
|
package/package.json
CHANGED