forked from daptin/daptin
/
actions.go
55 lines (50 loc) · 1.92 KB
/
actions.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
package resource
import (
"github.com/artpar/api2go"
)
// Outcome is call to a internal function with attributes as parameters
// Outcome has a particular `type`, it can be one of the data entities already defined
// Method is the type of outcome: GET/PUT/POST/DELETE/UPDATE/PATCH/EXECUTE
// Condition can be specified in JS to be checked, false condition will skip processing the outcome
// set SkipInResponse to true to not include action outcome in the http response of the action call
// reference is a name you can assign to the outcome of, which can be used in furthur chained outcomes
// Attributes is a map of string to interface{} which will be used by the action
// The attributes are evaluated to generate the actual data to be sent to execution
// JS scripting can be used to reference existing outcomes by reference names
type Outcome struct {
Type string
Method string
Reference string
SkipInResponse bool
Condition string
Attributes map[string]interface{}
}
// Action is a set of `Outcome` based on set of Input values on a particular data type
// New actions can be defined and added using JSON or YAML files
// Actions are stored and reloaded from the `action` table of the storage
type Action struct {
Name string // Name of the action
Label string
OnType string
InstanceOptional bool
ReferenceId string
InFields []api2go.ColumnInfo
OutFields []Outcome
Validations []ColumnTag
Conformations []ColumnTag
}
// ActionRow represents an action instance on the database
// Can be retrieved using GetActionByName
type ActionRow struct {
Name string
Label string
OnType string
InstanceOptional bool `db:"instance_optional"`
ReferenceId string
ActionSchema string `db:"action_schema"`
}
type ActionRequest struct {
Type string
Action string
Attributes map[string]interface{}
}