serverless-simple-middleware 0.0.71 → 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.
- package/dist/middleware/base.js +8 -3
- package/dist/middleware/database/connectionProxy.js +20 -10
- package/dist/middleware/database/sqlClient.d.ts +1 -1
- package/dist/middleware/database/sqlClient.js +17 -8
- package/package.json +1 -1
- package/src/middleware/base.ts +9 -4
- package/src/middleware/database/connectionProxy.ts +20 -10
- package/src/middleware/database/sqlClient.ts +21 -9
package/dist/middleware/base.js
CHANGED
|
@@ -12,6 +12,13 @@ class HandlerRequest {
|
|
|
12
12
|
this.event = event;
|
|
13
13
|
this.context = context;
|
|
14
14
|
this.lastError = undefined;
|
|
15
|
+
const normalizedHeaders = {};
|
|
16
|
+
if (this.event.headers) {
|
|
17
|
+
for (const key of Object.keys(this.event.headers)) {
|
|
18
|
+
normalizedHeaders[key.toLowerCase()] = this.event.headers[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
this.event.headers = normalizedHeaders;
|
|
15
22
|
}
|
|
16
23
|
get body() {
|
|
17
24
|
if (!this.event.body) {
|
|
@@ -29,9 +36,7 @@ class HandlerRequest {
|
|
|
29
36
|
return this.event.queryStringParameters || {};
|
|
30
37
|
}
|
|
31
38
|
header(key) {
|
|
32
|
-
return this.event.headers
|
|
33
|
-
? this.event.headers[key] || this.event.headers[key.toLowerCase()]
|
|
34
|
-
: undefined;
|
|
39
|
+
return this.event.headers[key.toLowerCase()];
|
|
35
40
|
}
|
|
36
41
|
records(selector) {
|
|
37
42
|
const target = (this.event.Records || []);
|
|
@@ -84,11 +84,16 @@ class ConnectionProxy {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
clearConnection = () => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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.
|
|
4
|
+
"version": "0.0.73",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "VoyagerX",
|
package/src/middleware/base.ts
CHANGED
|
@@ -21,6 +21,13 @@ export class HandlerRequest {
|
|
|
21
21
|
this.event = event;
|
|
22
22
|
this.context = context;
|
|
23
23
|
this.lastError = undefined;
|
|
24
|
+
const normalizedHeaders: Record<string, string | undefined> = {};
|
|
25
|
+
if (this.event.headers) {
|
|
26
|
+
for (const key of Object.keys(this.event.headers)) {
|
|
27
|
+
normalizedHeaders[key.toLowerCase()] = this.event.headers[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
this.event.headers = normalizedHeaders;
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
get body() {
|
|
@@ -41,10 +48,8 @@ export class HandlerRequest {
|
|
|
41
48
|
return this.event.queryStringParameters || {};
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
public header(key: string) {
|
|
45
|
-
return this.event.headers
|
|
46
|
-
? this.event.headers[key] || this.event.headers[key.toLowerCase()]
|
|
47
|
-
: undefined;
|
|
51
|
+
public header(key: string): string | undefined {
|
|
52
|
+
return this.event.headers[key.toLowerCase()];
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
public records<T, U>(selector?: (each: T) => U) {
|
|
@@ -113,11 +113,16 @@ export class ConnectionProxy {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
public clearConnection = () => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
|