-
Notifications
You must be signed in to change notification settings - Fork 20
/
expressions.go
43 lines (38 loc) · 1.05 KB
/
expressions.go
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
package flows
import (
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/utils"
)
// Contextable is an object that can accessed in expressions as a object with properties
type Contextable interface {
Context(env utils.Environment) map[string]types.XValue
}
// Context generates a lazy object for use in expressions
func Context(env utils.Environment, contextable Contextable) *types.XObject {
if !utils.IsNil(contextable) {
return types.NewXLazyObject(func() map[string]types.XValue {
return contextable.Context(env)
})
}
return nil
}
// ContextFunc generates a lazy object for use in expressions
func ContextFunc(env utils.Environment, fn func(utils.Environment) map[string]types.XValue) *types.XObject {
return types.NewXLazyObject(func() map[string]types.XValue {
return fn(env)
})
}
// RunContextTopLevels are the allowed top-level variables for expression evaluations
var RunContextTopLevels = []string{
"child",
"contact",
"fields",
"input",
"legacy_extra",
"parent",
"results",
"run",
"trigger",
"urns",
"webhook",
}