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.
package/package.json
CHANGED
|
@@ -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
|
+
}
|