-
Notifications
You must be signed in to change notification settings - Fork 20
/
expressions.go
58 lines (49 loc) · 1.37 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package flows
import (
"reflect"
"strconv"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/excellent/types"
)
// Contextable is an object that can accessed in expressions as a object with properties
type Contextable interface {
Context(env envs.Environment) map[string]types.XValue
}
// Context generates a lazy object for use in expressions
func Context(env envs.Environment, contextable Contextable) types.XValue {
// we allow passing nil pointers which will become non-nil Contextables
if contextable == nil || reflect.ValueOf(contextable).IsNil() {
return nil
}
return types.NewXLazyObject(func() map[string]types.XValue {
return contextable.Context(env)
})
}
// ContextFunc generates a lazy object for use in expressions
func ContextFunc(env envs.Environment, fn func(envs.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",
"globals",
"input",
"legacy_extra",
"node",
"parent",
"results",
"resume",
"run",
"ticket",
"trigger",
"urns",
"webhook",
}
// ContactQueryEscaping is the escaping function used for expressions in contact queries
func ContactQueryEscaping(s string) string {
return strconv.Quote(s)
}