lesgo 2.1.9 → 2.1.11

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.
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @deprecated Disconnect db is no longer to be used due to the use of ConnectionPool
3
+ */
1
4
  declare const disconnectMySQLProxyClient: () => Promise<void>;
2
5
  export default disconnectMySQLProxyClient;
@@ -32,29 +32,30 @@ var __awaiter =
32
32
  });
33
33
  };
34
34
  import { logger } from '../../utils';
35
- import { singleton } from '../RDSAuroraMySQLProxyService/getMySQLProxyClient';
36
35
  const FILE =
37
36
  'lesgo.services.RDSAuroraMySQLProxyService.disconnectMySQLProxyClient';
37
+ /**
38
+ * @deprecated Disconnect db is no longer to be used due to the use of ConnectionPool
39
+ */
38
40
  const disconnectMySQLProxyClient = () =>
39
41
  __awaiter(void 0, void 0, void 0, function* () {
40
- const singletonConns = Object.keys(singleton);
41
- if (singletonConns.length === 0) {
42
- logger.debug(`${FILE}::NO_CONNECTIONS_TO_DISCONNECT`);
43
- return;
44
- }
45
- logger.debug(`${FILE}::PREPARING_TO_DISCONNECT`, {
46
- singletonConns,
47
- });
48
- singletonConns.forEach(singletonConn =>
49
- __awaiter(void 0, void 0, void 0, function* () {
50
- try {
51
- yield singleton[singletonConn].end();
52
- delete singleton[singletonConn];
53
- logger.debug(`${FILE}::COMPLETED`, { singletonConn });
54
- } catch (err) {
55
- logger.error(`${FILE}::ERROR`, { singletonConn, err });
56
- }
57
- })
58
- );
42
+ logger.warn(`${FILE}::DEPRECATED_FUNCTION_DO_NOT_END_POOL_CONNECTION`);
43
+ // const singletonConns = Object.keys(singleton);
44
+ // if (singletonConns.length === 0) {
45
+ // logger.debug(`${FILE}::NO_CONNECTIONS_TO_DISCONNECT`);
46
+ // return;
47
+ // }
48
+ // logger.debug(`${FILE}::PREPARING_TO_DISCONNECT`, {
49
+ // singletonConns,
50
+ // });
51
+ // singletonConns.forEach(async singletonConn => {
52
+ // try {
53
+ // await singleton[singletonConn].end();
54
+ // delete singleton[singletonConn];
55
+ // logger.debug(`${FILE}::COMPLETED`, { singletonConn });
56
+ // } catch (err) {
57
+ // logger.error(`${FILE}::ERROR`, { singletonConn, err });
58
+ // }
59
+ // });
59
60
  });
60
61
  export default disconnectMySQLProxyClient;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @deprecated Disconnect db is no longer to be used due to the use of ConnectionPool
3
+ */
1
4
  declare const disconnectDb: () => Promise<void>;
2
5
  export default disconnectDb;
@@ -1,4 +1,7 @@
1
1
  import { disconnectMySQLProxyClient } from '../../../../services/RDSAuroraMySQLProxyService';
2
+ /**
3
+ * @deprecated Disconnect db is no longer to be used due to the use of ConnectionPool
4
+ */
2
5
  const disconnectDb = () => {
3
6
  return disconnectMySQLProxyClient();
4
7
  };
@@ -8,3 +8,4 @@ export { default as isEmpty } from './isEmpty';
8
8
  export { default as logger } from './logger';
9
9
  export { default as validateFields } from './validateFields';
10
10
  export { default as safePromise } from './safePromise';
11
+ export { default as typeSafePromise } from './typeSafePromise';
@@ -8,3 +8,4 @@ export { default as isEmpty } from './isEmpty';
8
8
  export { default as logger } from './logger';
9
9
  export { default as validateFields } from './validateFields';
10
10
  export { default as safePromise } from './safePromise';
11
+ export { default as typeSafePromise } from './typeSafePromise';
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * @deprecated use typeSafePromise instead
3
3
  * @param promise
4
4
  * @returns [err, res]
5
5
  * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
@@ -32,7 +32,7 @@ var __awaiter =
32
32
  });
33
33
  };
34
34
  /**
35
- *
35
+ * @deprecated use typeSafePromise instead
36
36
  * @param promise
37
37
  * @returns [err, res]
38
38
  * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
@@ -0,0 +1,29 @@
1
+ /**
2
+ *
3
+ * @param promise
4
+ * @returns {success: true, data: TData} | {success: false, error: TError}
5
+ * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { typeSafePromise } from 'lesgo/utils';
10
+ *
11
+ * const res = await typeSafePromise(fetch('https://example.com/'));
12
+ * if (res.success) {
13
+ * console.log(res.data);
14
+ * } else {
15
+ * console.error(res.error);
16
+ * }
17
+ * ```
18
+ */
19
+ type ReturnTypeSafePromise<TData, TError> = {
20
+ success: true;
21
+ data: TData;
22
+ error?: undefined;
23
+ } | {
24
+ success: false;
25
+ data?: undefined;
26
+ error: TError;
27
+ };
28
+ declare const typeSafePromise: <TData, TError = Error>(promise: Promise<TData>) => Promise<ReturnTypeSafePromise<TData, TError>>;
29
+ export default typeSafePromise;
@@ -0,0 +1,49 @@
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value);
9
+ });
10
+ }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator['throw'](value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ }
26
+ function step(result) {
27
+ result.done
28
+ ? resolve(result.value)
29
+ : adopt(result.value).then(fulfilled, rejected);
30
+ }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ const typeSafePromise = promise =>
35
+ __awaiter(void 0, void 0, void 0, function* () {
36
+ try {
37
+ const res = yield promise;
38
+ return {
39
+ success: true,
40
+ data: res,
41
+ };
42
+ } catch (err) {
43
+ return {
44
+ success: false,
45
+ error: err,
46
+ };
47
+ }
48
+ });
49
+ export default typeSafePromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lesgo",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
4
4
  "description": "Core framework for lesgo node.js serverless framework.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",