advanced-lambda-context 2.0.0 → 2.1.0

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.
@@ -19,8 +19,5 @@ jobs:
19
19
  - name: Dependencies
20
20
  run: make install
21
21
 
22
- - name: env check
23
- run: env
24
-
25
22
  - name: Unit Tests
26
23
  run: make test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "advanced-lambda-context",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A flexible wrapper function for various common lambda use-cases.",
5
5
  "engines": {
6
6
  "node": ">=18.17.0"
@@ -1,7 +1,9 @@
1
1
  const dataApi = require('./data-api')
2
2
  const mysql = require('./serverless-mysql')
3
+ const sshMysql = require('./ssh-mysql')
3
4
 
4
5
  module.exports = {
5
6
  mysql,
6
7
  dataApi,
8
+ sshMysql,
7
9
  }
@@ -1,4 +1,6 @@
1
1
  import _dataApi from './data-api.js'
2
2
  import _mysql from './serverless-mysql.js'
3
+ import _sshMysql from './ssh-mysql.js'
3
4
  export const dataApi = _dataApi
4
5
  export const mysql = _mysql
6
+ export const sshMysql = _sshMysql
@@ -0,0 +1,40 @@
1
+
2
+ /**
3
+ * SSH MySQL context provider
4
+ *
5
+ * Unlike the regular mysql provider, this supports both getter and setter
6
+ * because SSH MySQL connections require async initialization (SSH handshake + tunnel)
7
+ * and cannot be lazily created synchronously.
8
+ *
9
+ * Usage:
10
+ * .with(sshMysql()) // Default property name: 'sshMysql'
11
+ * .with(sshMysql({ as: 'tunnelDb' })) // Custom property name
12
+ *
13
+ * Then in handler:
14
+ * const db = await createSshConnection(context)
15
+ * context.sshMysql = db.mysql // Setter allows assignment
16
+ * await context.sshMysql.query('SELECT ...') // Getter returns assigned value
17
+ */
18
+ module.exports = (option = {}) => {
19
+ return context => {
20
+ const getterKey = option.as || 'sshMysql'
21
+ const trueKey = `_${getterKey}`
22
+
23
+ if (!context._with[getterKey]) {
24
+ context._with[getterKey] = true
25
+
26
+ Object.defineProperty(context, getterKey, {
27
+ get: function() {
28
+ return this[trueKey]
29
+ },
30
+ set: function(value) {
31
+ this[trueKey] = value
32
+ },
33
+ configurable: true,
34
+ enumerable: true
35
+ })
36
+ }
37
+
38
+ return context
39
+ }
40
+ }