serverless-simple-middleware 0.0.72 → 0.0.73

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.
@@ -84,11 +84,16 @@ class ConnectionProxy {
84
84
  });
85
85
  });
86
86
  clearConnection = () => {
87
- if (this.connection) {
88
- this.connection.end();
89
- this.connection = undefined;
90
- this.connectionInitOnce.reset();
91
- logger.verbose('Connection is end');
87
+ const conn = this.connection;
88
+ this.connection = undefined;
89
+ this.connectionInitOnce.reset();
90
+ if (conn) {
91
+ try {
92
+ conn.end();
93
+ }
94
+ catch (error) {
95
+ logger.warn(`Error occurred while ending connection: ${error}`);
96
+ }
92
97
  }
93
98
  };
94
99
  /**
@@ -96,11 +101,16 @@ class ConnectionProxy {
96
101
  * This should be used only for special use cases!
97
102
  */
98
103
  destroyConnection = () => {
99
- if (this.connection) {
100
- this.connection.destroy();
101
- this.connection = undefined;
102
- this.connectionInitOnce.reset();
103
- logger.verbose('Connection is destroyed');
104
+ const conn = this.connection;
105
+ this.connection = undefined;
106
+ this.connectionInitOnce.reset();
107
+ if (conn) {
108
+ try {
109
+ conn.destroy();
110
+ }
111
+ catch (error) {
112
+ logger.warn(`Error occurred while destroying connection: ${error}`);
113
+ }
104
114
  }
105
115
  };
106
116
  onPluginCreated = async () => this.tryToInitializeSchema(true);
@@ -10,4 +10,4 @@ export declare class SQLClient<T = unknown> extends Kysely<T> {
10
10
  */
11
11
  destroyConnection: () => void;
12
12
  }
13
- export { expressionBuilder, sql, type DeleteQueryBuilder, type DeleteResult, type Expression, type ExpressionBuilder, type InferResult, type Insertable, type InsertQueryBuilder, type InsertResult, type NotNull, type RawBuilder, type Selectable, type SelectQueryBuilder, type SqlBool, type Transaction, type Updateable, type UpdateQueryBuilder, type UpdateResult, } from 'kysely';
13
+ export { expressionBuilder, sql, type DeleteQueryBuilder, type DeleteResult, type Expression, type ExpressionBuilder, type InferResult, type Insertable, type InsertQueryBuilder, type InsertResult, type NotNull, type RawBuilder, type Selectable, type SelectQueryBuilder, type SqlBool, type Transaction, type Updateable, type UpdateQueryBuilder, type UpdateResult } from 'kysely';
@@ -4,7 +4,9 @@ exports.sql = exports.expressionBuilder = exports.SQLClient = void 0;
4
4
  const kysely_1 = require("kysely");
5
5
  const mysql2_1 = require("mysql2");
6
6
  const oncePromise_1 = require("../../internal/oncePromise");
7
+ const utils_1 = require("../../utils");
7
8
  const secretsManager_1 = require("../../utils/secretsManager");
9
+ const logger = (0, utils_1.getLogger)(__filename);
8
10
  class LazyConnectionPool {
9
11
  options;
10
12
  connection = null;
@@ -59,10 +61,11 @@ class LazyConnectionPool {
59
61
  .catch((err) => callback(err, {}));
60
62
  };
61
63
  end = (callback) => {
62
- if (this.connection) {
63
- this.connection.end((err) => {
64
- this.connection = null;
65
- this.connectionInitOnce.reset();
64
+ const conn = this.connection;
65
+ this.connection = null;
66
+ this.connectionInitOnce.reset();
67
+ if (conn) {
68
+ conn.end((err) => {
66
69
  callback(err);
67
70
  });
68
71
  }
@@ -71,10 +74,16 @@ class LazyConnectionPool {
71
74
  }
72
75
  };
73
76
  destroy = () => {
74
- if (this.connection) {
75
- this.connection.destroy();
76
- this.connection = null;
77
- this.connectionInitOnce.reset();
77
+ const conn = this.connection;
78
+ this.connection = null;
79
+ this.connectionInitOnce.reset();
80
+ if (conn) {
81
+ try {
82
+ conn.destroy();
83
+ }
84
+ catch (error) {
85
+ logger.warn(`Error occurred while destroying connection: ${error}`);
86
+ }
78
87
  }
79
88
  };
80
89
  _addRelease = (connection) => Object.assign(connection, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "serverless-simple-middleware",
3
3
  "description": "Simple middleware to translate the interface of lambda's handler to request => response",
4
- "version": "0.0.72",
4
+ "version": "0.0.73",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "VoyagerX",
@@ -113,11 +113,16 @@ export class ConnectionProxy {
113
113
  });
114
114
 
115
115
  public clearConnection = () => {
116
- if (this.connection) {
117
- this.connection.end();
118
- this.connection = undefined;
119
- this.connectionInitOnce.reset();
120
- logger.verbose('Connection is end');
116
+ const conn = this.connection;
117
+ this.connection = undefined;
118
+ this.connectionInitOnce.reset();
119
+
120
+ if (conn) {
121
+ try {
122
+ conn.end();
123
+ } catch (error) {
124
+ logger.warn(`Error occurred while ending connection: ${error}`);
125
+ }
121
126
  }
122
127
  };
123
128
 
@@ -126,11 +131,16 @@ export class ConnectionProxy {
126
131
  * This should be used only for special use cases!
127
132
  */
128
133
  public destroyConnection = () => {
129
- if (this.connection) {
130
- this.connection.destroy();
131
- this.connection = undefined;
132
- this.connectionInitOnce.reset();
133
- logger.verbose('Connection is destroyed');
134
+ const conn = this.connection;
135
+ this.connection = undefined;
136
+ this.connectionInitOnce.reset();
137
+
138
+ if (conn) {
139
+ try {
140
+ conn.destroy();
141
+ } catch (error) {
142
+ logger.warn(`Error occurred while destroying connection: ${error}`);
143
+ }
134
144
  }
135
145
  };
136
146
 
@@ -13,9 +13,12 @@ import {
13
13
  type QueryError,
14
14
  } from 'mysql2';
15
15
  import { OncePromise } from '../../internal/oncePromise';
16
+ import { getLogger } from '../../utils';
16
17
  import { SecretsManagerCache } from '../../utils/secretsManager';
17
18
  import { MySQLPluginOptions } from '../mysql';
18
19
 
20
+ const logger = getLogger(__filename);
21
+
19
22
  interface LazyMysqlPoolConnection extends Connection {
20
23
  release: () => void;
21
24
  }
@@ -83,10 +86,12 @@ class LazyConnectionPool implements MysqlPool {
83
86
  };
84
87
 
85
88
  public end = (callback: (error: unknown) => void): void => {
86
- if (this.connection) {
87
- this.connection.end((err: QueryError) => {
88
- this.connection = null;
89
- this.connectionInitOnce.reset();
89
+ const conn = this.connection;
90
+ this.connection = null;
91
+ this.connectionInitOnce.reset();
92
+
93
+ if (conn) {
94
+ conn.end((err: QueryError) => {
90
95
  callback(err);
91
96
  });
92
97
  } else {
@@ -95,10 +100,16 @@ class LazyConnectionPool implements MysqlPool {
95
100
  };
96
101
 
97
102
  public destroy = (): void => {
98
- if (this.connection) {
99
- this.connection.destroy();
100
- this.connection = null;
101
- this.connectionInitOnce.reset();
103
+ const conn = this.connection;
104
+ this.connection = null;
105
+ this.connectionInitOnce.reset();
106
+
107
+ if (conn) {
108
+ try {
109
+ conn.destroy();
110
+ } catch (error) {
111
+ logger.warn(`Error occurred while destroying connection: ${error}`);
112
+ }
102
113
  }
103
114
  };
104
115
 
@@ -160,5 +171,6 @@ export {
160
171
  type Transaction,
161
172
  type Updateable,
162
173
  type UpdateQueryBuilder,
163
- type UpdateResult,
174
+ type UpdateResult
164
175
  } from 'kysely';
176
+