serverless-simple-middleware 0.0.65 → 0.0.67

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.
@@ -59,10 +59,14 @@ class HandlerResponse {
59
59
  }
60
60
  ok(body = {}, code = 200) {
61
61
  logger.stupid(`ok`, body);
62
+ const exposeHeaders = Object.keys(this.customHeaders).join(', ');
62
63
  const headers = {
63
64
  ...CORS_HEADERS,
64
65
  ...this.customHeaders,
65
66
  };
67
+ if (exposeHeaders) {
68
+ headers['Access-Control-Expose-Headers'] = exposeHeaders;
69
+ }
66
70
  if (this.crossOrigin) {
67
71
  headers['Access-Control-Allow-Origin'] = this.crossOrigin;
68
72
  }
@@ -12,6 +12,11 @@ export declare class ConnectionProxy {
12
12
  commit: () => Promise<void>;
13
13
  rollback: () => Promise<void>;
14
14
  clearConnection: () => void;
15
+ /**
16
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
17
+ * This should be used only for special use cases!
18
+ */
19
+ destroyConnection: () => void;
15
20
  onPluginCreated: () => Promise<void>;
16
21
  private prepareConnection;
17
22
  private changeDatabase;
@@ -83,6 +83,17 @@ class ConnectionProxy {
83
83
  logger.verbose('Connection is end');
84
84
  }
85
85
  };
86
+ /**
87
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
88
+ * This should be used only for special use cases!
89
+ */
90
+ destroyConnection = () => {
91
+ if (this.connection) {
92
+ this.connection.destroy();
93
+ this.connection = undefined;
94
+ logger.verbose('Connection is destroyed');
95
+ }
96
+ };
86
97
  onPluginCreated = async () => this.tryToInitializeSchema(true);
87
98
  prepareConnection = () => {
88
99
  if (this.connection) {
@@ -1,2 +1,3 @@
1
1
  export { ConnectionProxy } from './connectionProxy';
2
- export { sql, type DeleteQueryBuilder, type Expression, type ExpressionBuilder, type InsertQueryBuilder, type NotNull, type RawBuilder, type SelectQueryBuilder, type SqlBool, type SQLClient, type UpdateQueryBuilder, } from './sqlClient';
2
+ export { expressionBuilder, sql } from './sqlClient';
3
+ export type * from './sqlClient';
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sql = exports.ConnectionProxy = void 0;
3
+ exports.sql = exports.expressionBuilder = exports.ConnectionProxy = void 0;
4
4
  var connectionProxy_1 = require("./connectionProxy");
5
5
  Object.defineProperty(exports, "ConnectionProxy", { enumerable: true, get: function () { return connectionProxy_1.ConnectionProxy; } });
6
6
  var sqlClient_1 = require("./sqlClient");
7
+ Object.defineProperty(exports, "expressionBuilder", { enumerable: true, get: function () { return sqlClient_1.expressionBuilder; } });
7
8
  Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return sqlClient_1.sql; } });
@@ -4,5 +4,10 @@ export declare class SQLClient<T = unknown> extends Kysely<T> {
4
4
  private pool;
5
5
  constructor(config: ConnectionOptions);
6
6
  clearConnection: () => Promise<void>;
7
+ /**
8
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
9
+ * This should be used only for special use cases!
10
+ */
11
+ destroyConnection: () => void;
7
12
  }
8
- export { expressionBuilder, sql, type DeleteQueryBuilder, type Expression, type ExpressionBuilder, type InsertQueryBuilder, type NotNull, type RawBuilder, type SelectQueryBuilder, type SqlBool, type UpdateQueryBuilder, } 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';
@@ -35,6 +35,12 @@ class LazyConnectionPool {
35
35
  callback(null);
36
36
  }
37
37
  };
38
+ destroy = () => {
39
+ if (this.connection) {
40
+ this.connection.destroy();
41
+ this.connection = null;
42
+ }
43
+ };
38
44
  _addRelease = (connection) => Object.assign(connection, {
39
45
  release: () => { },
40
46
  });
@@ -58,6 +64,13 @@ class SQLClient extends kysely_1.Kysely {
58
64
  clearConnection = () => new Promise((resolve) => {
59
65
  this.pool.end(() => resolve());
60
66
  });
67
+ /**
68
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
69
+ * This should be used only for special use cases!
70
+ */
71
+ destroyConnection = () => {
72
+ this.pool.destroy();
73
+ };
61
74
  }
62
75
  exports.SQLClient = SQLClient;
63
76
  var kysely_2 = require("kysely");
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.65",
4
+ "version": "0.0.67",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "VoyagerX",
@@ -77,10 +77,14 @@ export class HandlerResponse {
77
77
 
78
78
  public ok(body = {}, code = 200) {
79
79
  logger.stupid(`ok`, body);
80
- const headers = {
80
+ const exposeHeaders = Object.keys(this.customHeaders).join(', ');
81
+ const headers: { [key: string]: any } = {
81
82
  ...CORS_HEADERS,
82
83
  ...this.customHeaders,
83
84
  };
85
+ if (exposeHeaders) {
86
+ headers['Access-Control-Expose-Headers'] = exposeHeaders;
87
+ }
84
88
  if (this.crossOrigin) {
85
89
  headers['Access-Control-Allow-Origin'] = this.crossOrigin;
86
90
  }
@@ -102,6 +102,18 @@ export class ConnectionProxy {
102
102
  }
103
103
  };
104
104
 
105
+ /**
106
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
107
+ * This should be used only for special use cases!
108
+ */
109
+ public destroyConnection = () => {
110
+ if (this.connection) {
111
+ this.connection.destroy();
112
+ this.connection = undefined;
113
+ logger.verbose('Connection is destroyed');
114
+ }
115
+ };
116
+
105
117
  public onPluginCreated = async () => this.tryToInitializeSchema(true);
106
118
 
107
119
  private prepareConnection = () => {
@@ -1,14 +1,4 @@
1
1
  export { ConnectionProxy } from './connectionProxy';
2
- export {
3
- sql,
4
- type DeleteQueryBuilder,
5
- type Expression,
6
- type ExpressionBuilder,
7
- type InsertQueryBuilder,
8
- type NotNull,
9
- type RawBuilder,
10
- type SelectQueryBuilder,
11
- type SqlBool,
12
- type SQLClient,
13
- type UpdateQueryBuilder,
14
- } from './sqlClient';
2
+ export { expressionBuilder, sql } from './sqlClient';
3
+
4
+ export type * from './sqlClient';
@@ -50,6 +50,13 @@ class LazyConnectionPool implements MysqlPool {
50
50
  }
51
51
  };
52
52
 
53
+ public destroy = (): void => {
54
+ if (this.connection) {
55
+ this.connection.destroy();
56
+ this.connection = null;
57
+ }
58
+ };
59
+
53
60
  private _addRelease = (connection: Connection): LazyMysqlPoolConnection =>
54
61
  Object.assign(connection, {
55
62
  release: () => {},
@@ -78,18 +85,34 @@ export class SQLClient<T = unknown> extends Kysely<T> {
78
85
  new Promise<void>((resolve) => {
79
86
  this.pool.end(() => resolve());
80
87
  });
88
+
89
+ /**
90
+ * Destroy the connection socket immediately. No further events or callbacks will be triggered.
91
+ * This should be used only for special use cases!
92
+ */
93
+ public destroyConnection = (): void => {
94
+ this.pool.destroy();
95
+ };
81
96
  }
82
97
 
83
98
  export {
84
99
  expressionBuilder,
85
100
  sql,
86
101
  type DeleteQueryBuilder,
102
+ type DeleteResult,
87
103
  type Expression,
88
104
  type ExpressionBuilder,
105
+ type InferResult,
106
+ type Insertable,
89
107
  type InsertQueryBuilder,
108
+ type InsertResult,
90
109
  type NotNull,
91
110
  type RawBuilder,
111
+ type Selectable,
92
112
  type SelectQueryBuilder,
93
113
  type SqlBool,
114
+ type Transaction,
115
+ type Updateable,
94
116
  type UpdateQueryBuilder,
117
+ type UpdateResult,
95
118
  } from 'kysely';