@bearei/server-common 1.4.3 → 1.5.1

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.
@@ -0,0 +1 @@
1
+ export declare const runWithRetry: <T>(operation: () => Promise<T>) => Promise<T>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWithRetry = void 0;
4
+ const runWithRetry = async (operation) => {
5
+ const maxRetries = 1;
6
+ const staleConnectionErrorRegex = /Connection terminated due to connection timeout|socket hang up|connection reset/i;
7
+ for (let i = 0; i <= maxRetries; i++) {
8
+ try {
9
+ return await operation();
10
+ }
11
+ catch (error) {
12
+ const lastError = error;
13
+ if (staleConnectionErrorRegex.test(lastError.message) && i < maxRetries) {
14
+ console.warn(`[DB Utility] Connection terminated detected. Retrying attempt ${i + 1}...`);
15
+ continue;
16
+ }
17
+ throw lastError;
18
+ }
19
+ }
20
+ };
21
+ exports.runWithRetry = runWithRetry;
22
+ //# sourceMappingURL=database-retry.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-retry.utils.js","sourceRoot":"","sources":["../../../src/utils/database-retry/database-retry.utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,KAAK,EAAK,SAA2B,EAAE,EAAE;IACpE,MAAM,UAAU,GAAG,CAAC,CAAA;IACpB,MAAM,yBAAyB,GAC9B,kFAAkF,CAAA;IAEnF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC;YACJ,OAAO,MAAM,SAAS,EAAE,CAAA;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,SAAS,GAAG,KAAkC,CAAA;YAEpD,IAAI,yBAAyB,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC;gBACzE,OAAO,CAAC,IAAI,CACX,iEAAiE,CAAC,GAAG,CAAC,KAAK,CAC3E,CAAA;gBAED,SAAQ;YACT,CAAC;YAED,MAAM,SAAS,CAAA;QAChB,CAAC;IACF,CAAC;AACF,CAAC,CAAA;AAtBY,QAAA,YAAY,gBAsBxB"}
@@ -0,0 +1 @@
1
+ export * from './database-retry.utils';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./database-retry.utils"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/database-retry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC"}
@@ -1,5 +1,6 @@
1
1
  export * from './build-mobile-number';
2
2
  export * from './create-sanitize-response-entity';
3
+ export * from './database-retry';
3
4
  export * from './extract-bearer-token';
4
5
  export * from './generate-random-number';
5
6
  export * from './sign';
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./build-mobile-number"), exports);
18
18
  __exportStar(require("./create-sanitize-response-entity"), exports);
19
+ __exportStar(require("./database-retry"), exports);
19
20
  __exportStar(require("./extract-bearer-token"), exports);
20
21
  __exportStar(require("./generate-random-number"), exports);
21
22
  __exportStar(require("./sign"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC;AACrC,oEAAiD;AACjD,yDAAsC;AACtC,2DAAwC;AACxC,yCAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC;AACrC,oEAAiD;AACjD,mDAAgC;AAChC,yDAAsC;AACtC,2DAAwC;AACxC,yCAAsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bearei/server-common",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "bearei <bear_ei@outlook.com>",