serverless-simple-middleware 0.0.70 → 0.0.72
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/internal/oncePromise.d.ts +1 -0
- package/dist/internal/oncePromise.js +3 -0
- package/dist/middleware/base.js +8 -3
- package/dist/middleware/database/connectionProxy.js +2 -0
- package/dist/middleware/database/sqlClient.js +2 -0
- package/package.json +1 -1
- package/src/internal/oncePromise.ts +4 -0
- package/src/middleware/base.ts +9 -4
- package/src/middleware/database/connectionProxy.ts +2 -0
- package/src/middleware/database/sqlClient.ts +2 -0
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 || []);
|
|
@@ -87,6 +87,7 @@ class ConnectionProxy {
|
|
|
87
87
|
if (this.connection) {
|
|
88
88
|
this.connection.end();
|
|
89
89
|
this.connection = undefined;
|
|
90
|
+
this.connectionInitOnce.reset();
|
|
90
91
|
logger.verbose('Connection is end');
|
|
91
92
|
}
|
|
92
93
|
};
|
|
@@ -98,6 +99,7 @@ class ConnectionProxy {
|
|
|
98
99
|
if (this.connection) {
|
|
99
100
|
this.connection.destroy();
|
|
100
101
|
this.connection = undefined;
|
|
102
|
+
this.connectionInitOnce.reset();
|
|
101
103
|
logger.verbose('Connection is destroyed');
|
|
102
104
|
}
|
|
103
105
|
};
|
|
@@ -62,6 +62,7 @@ class LazyConnectionPool {
|
|
|
62
62
|
if (this.connection) {
|
|
63
63
|
this.connection.end((err) => {
|
|
64
64
|
this.connection = null;
|
|
65
|
+
this.connectionInitOnce.reset();
|
|
65
66
|
callback(err);
|
|
66
67
|
});
|
|
67
68
|
}
|
|
@@ -73,6 +74,7 @@ class LazyConnectionPool {
|
|
|
73
74
|
if (this.connection) {
|
|
74
75
|
this.connection.destroy();
|
|
75
76
|
this.connection = null;
|
|
77
|
+
this.connectionInitOnce.reset();
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
80
|
_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.72",
|
|
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) {
|
|
@@ -116,6 +116,7 @@ export class ConnectionProxy {
|
|
|
116
116
|
if (this.connection) {
|
|
117
117
|
this.connection.end();
|
|
118
118
|
this.connection = undefined;
|
|
119
|
+
this.connectionInitOnce.reset();
|
|
119
120
|
logger.verbose('Connection is end');
|
|
120
121
|
}
|
|
121
122
|
};
|
|
@@ -128,6 +129,7 @@ export class ConnectionProxy {
|
|
|
128
129
|
if (this.connection) {
|
|
129
130
|
this.connection.destroy();
|
|
130
131
|
this.connection = undefined;
|
|
132
|
+
this.connectionInitOnce.reset();
|
|
131
133
|
logger.verbose('Connection is destroyed');
|
|
132
134
|
}
|
|
133
135
|
};
|
|
@@ -86,6 +86,7 @@ class LazyConnectionPool implements MysqlPool {
|
|
|
86
86
|
if (this.connection) {
|
|
87
87
|
this.connection.end((err: QueryError) => {
|
|
88
88
|
this.connection = null;
|
|
89
|
+
this.connectionInitOnce.reset();
|
|
89
90
|
callback(err);
|
|
90
91
|
});
|
|
91
92
|
} else {
|
|
@@ -97,6 +98,7 @@ class LazyConnectionPool implements MysqlPool {
|
|
|
97
98
|
if (this.connection) {
|
|
98
99
|
this.connection.destroy();
|
|
99
100
|
this.connection = null;
|
|
101
|
+
this.connectionInitOnce.reset();
|
|
100
102
|
}
|
|
101
103
|
};
|
|
102
104
|
|