-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabstract-lambda-plugin.js
More file actions
62 lines (55 loc) · 1.4 KB
/
abstract-lambda-plugin.js
File metadata and controls
62 lines (55 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import LambdaType from '../enums/lambda-type'
/**
* Abstract class for lambda handler plugins.
*/
class AbstractLambdaPlugin {
/**
* AbstractLambdaPlugin constructor.
*
* @param {string} name plugin name
* @param {string|string[]} supportedLambdaTypes lambda types
*/
constructor (name, supportedLambdaTypes = null) {
this.name = name
this.hooks = {}
if (supportedLambdaTypes !== null) {
if (Array.isArray(supportedLambdaTypes)) {
this.supportedLambdaTypes = supportedLambdaTypes
} else {
this.supportedLambdaTypes = [ supportedLambdaTypes ]
}
} else {
this.supportedLambdaTypes = [ LambdaType.DEFAULT ]
}
}
/**
* Add hook for plugin.
*
* @param {string} hook plugin hook
* @param {function} plugin function
*/
addHook (hook, fn) {
if (!this.hooks[hook]) {
this.hooks[hook] = {}
}
this.hooks[hook][this.name] = fn
}
/**
* Check if this plugin supports the supplied type.
*
* @param {string} type lambda type
* @returns {boolean} returns true if lambda type supported
*/
isSupportedType (type) {
return this.supportedLambdaTypes.indexOf(type) > -1
}
/**
* Get a list for the support types for this lambda plugin
*
* @returns {LambdaType[]} list of LambdaType
*/
getSupportedTypes () {
return this.supportedLambdaTypes
}
}
export default AbstractLambdaPlugin