diff --git a/automation/rest.yaml b/automation/rest.yaml index 0167f5725..de251df83 100644 --- a/automation/rest.yaml +++ b/automation/rest.yaml @@ -222,8 +222,6 @@ endpoints: method: GET title: Available workflow functions path: "/" - - - title: Types path: "/types" entrypoint: type @@ -233,6 +231,15 @@ endpoints: method: GET title: Available workflow types path: "/" +- title: Event types + path: "/event-types" + entrypoint: eventTypes + authentication: [] + apis: + - name: list + method: GET + title: Available workflow types + path: "/" - title: Permissions entrypoint: permissions path: "/permissions" diff --git a/automation/rest/eventTypes.gen.go b/automation/rest/eventTypes.gen.go new file mode 100644 index 000000000..14f4d49ba --- /dev/null +++ b/automation/rest/eventTypes.gen.go @@ -0,0 +1,1575 @@ +package rest + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// + +func getEventTypeDefinitions() []eventTypeDef { + return []eventTypeDef{ + + // []string{"github.com/cortezaproject/corteza-server/compose/types", "github.com/cortezaproject/corteza-server/compose/automation", "github.com/cortezaproject/corteza-server/pkg/auth"} + + { + ResourceType: "compose", + EventType: "onManual", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "compose", + EventType: "onInterval", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "compose", + EventType: "onTimestamp", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "compose:module", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:module", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "module", + Type: "ComposeModule", + Immutable: false, + }, + + { + Name: "oldModule", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:namespace", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: false, + }, + + { + Name: "oldNamespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:page", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "page", + Type: "", + Immutable: false, + }, + + { + Name: "oldPage", + Type: "", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "onIteration", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + { + ResourceType: "compose:record", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "record", + Type: "ComposeRecord", + Immutable: false, + }, + + { + Name: "oldRecord", + Type: "ComposeRecord", + Immutable: true, + }, + + { + Name: "module", + Type: "ComposeModule", + Immutable: true, + }, + + { + Name: "namespace", + Type: "ComposeNamespace", + Immutable: true, + }, + + { + Name: "recordValueErrors", + Type: "ComposeRecordValueErrorSet", + Immutable: false, + }, + }, + }, + + // []string{"github.com/cortezaproject/corteza-server/system/types", "github.com/cortezaproject/corteza-server/system/automation", "github.com/cortezaproject/corteza-server/pkg/auth"} + + { + ResourceType: "system", + EventType: "onManual", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "system", + EventType: "onInterval", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "system", + EventType: "onTimestamp", + Properties: []eventTypePropertyDef{}, + }, + + { + ResourceType: "system:application", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:application", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "application", + Type: "", + Immutable: false, + }, + + { + Name: "oldApplication", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth", + EventType: "beforeLogin", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "provider", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:auth", + EventType: "beforeSignup", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "provider", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:auth", + EventType: "afterLogin", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "provider", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:auth", + EventType: "afterSignup", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "provider", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:auth-client", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "authClient", + Type: "", + Immutable: false, + }, + + { + Name: "oldAuthClient", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:mail", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "message", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:mail", + EventType: "onReceive", + Properties: []eventTypePropertyDef{ + + { + Name: "message", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:mail", + EventType: "onSend", + Properties: []eventTypePropertyDef{ + + { + Name: "message", + Type: "", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + + { + Name: "oldRole", + Type: "Role", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:role:member", + EventType: "beforeAdd", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:role:member", + EventType: "beforeRemove", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:role:member", + EventType: "afterAdd", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:role:member", + EventType: "afterRemove", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "role", + Type: "Role", + Immutable: false, + }, + }, + }, + + { + ResourceType: "system:sink", + EventType: "onRequest", + Properties: []eventTypePropertyDef{ + + { + Name: "response", + Type: "", + Immutable: false, + }, + + { + Name: "request", + Type: "", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "onManual", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "beforeCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "beforeUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "beforeDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "afterCreate", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "afterUpdate", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + + { + ResourceType: "system:user", + EventType: "afterDelete", + Properties: []eventTypePropertyDef{ + + { + Name: "user", + Type: "User", + Immutable: false, + }, + + { + Name: "oldUser", + Type: "User", + Immutable: true, + }, + }, + }, + } +} diff --git a/automation/rest/eventTypes.go b/automation/rest/eventTypes.go new file mode 100644 index 000000000..401258c0b --- /dev/null +++ b/automation/rest/eventTypes.go @@ -0,0 +1,40 @@ +package rest + +import ( + "context" + "github.com/cortezaproject/corteza-server/automation/rest/request" + "github.com/cortezaproject/corteza-server/automation/service" +) + +type ( + EventTypes struct { + reg interface { + Types() []string + } + } + + eventTypePayload struct { + Set []eventTypeDef `json:"set"` + } + + eventTypeDef struct { + ResourceType string `json:"resourceType"` + EventType string `json:"eventType"` + Properties []eventTypePropertyDef `json:"properties"` + } + + eventTypePropertyDef struct { + Name string `json:"name"` + Type string `json:"type"` + Immutable bool `json:"immutable"` + } +) + +func (EventTypes) New() *EventTypes { + ctrl := &EventTypes{reg: service.Registry()} + return ctrl +} + +func (ctrl EventTypes) List(_ context.Context, _ *request.EventTypesList) (interface{}, error) { + return eventTypePayload{Set: getEventTypeDefinitions()}, nil +} diff --git a/automation/rest/handlers/eventTypes.go b/automation/rest/handlers/eventTypes.go new file mode 100644 index 000000000..3c5f77a32 --- /dev/null +++ b/automation/rest/handlers/eventTypes.go @@ -0,0 +1,57 @@ +package handlers + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// + +import ( + "context" + "github.com/cortezaproject/corteza-server/automation/rest/request" + "github.com/cortezaproject/corteza-server/pkg/api" + "github.com/go-chi/chi" + "net/http" +) + +type ( + // Internal API interface + EventTypesAPI interface { + List(context.Context, *request.EventTypesList) (interface{}, error) + } + + // HTTP API interface + EventTypes struct { + List func(http.ResponseWriter, *http.Request) + } +) + +func NewEventTypes(h EventTypesAPI) *EventTypes { + return &EventTypes{ + List: func(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + params := request.NewEventTypesList() + if err := params.Fill(r); err != nil { + api.Send(w, r, err) + return + } + + value, err := h.List(r.Context(), params) + if err != nil { + api.Send(w, r, err) + return + } + + api.Send(w, r, value) + }, + } +} + +func (h EventTypes) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { + r.Group(func(r chi.Router) { + r.Use(middlewares...) + r.Get("/event-types/", h.List) + }) +} diff --git a/automation/rest/request/eventTypes.go b/automation/rest/request/eventTypes.go new file mode 100644 index 000000000..4a36d3082 --- /dev/null +++ b/automation/rest/request/eventTypes.go @@ -0,0 +1,60 @@ +package request + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// + +import ( + "encoding/json" + "fmt" + "github.com/cortezaproject/corteza-server/pkg/payload" + "github.com/go-chi/chi" + "io" + "mime/multipart" + "net/http" + "strings" +) + +// dummy vars to prevent +// unused imports complain +var ( + _ = chi.URLParam + _ = multipart.ErrMessageTooLarge + _ = payload.ParseUint64s +) + +type ( + // Internal API interface + EventTypesList struct { + } +) + +// NewEventTypesList request +func NewEventTypesList() *EventTypesList { + return &EventTypesList{} +} + +// Auditable returns all auditable/loggable parameters +func (r EventTypesList) Auditable() map[string]interface{} { + return map[string]interface{}{} +} + +// Fill processes request and fills internal variables +func (r *EventTypesList) Fill(req *http.Request) (err error) { + if strings.ToLower(req.Header.Get("content-type")) == "application/json" { + err = json.NewDecoder(req.Body).Decode(r) + + switch { + case err == io.EOF: + err = nil + case err != nil: + return fmt.Errorf("error parsing http request body: %w", err) + } + } + + return err +} diff --git a/automation/rest/router.go b/automation/rest/router.go index 8742d432b..234f85c76 100644 --- a/automation/rest/router.go +++ b/automation/rest/router.go @@ -18,5 +18,6 @@ func MountRoutes(r chi.Router) { handlers.NewFunction(Function{}.New()).MountRoutes(r) handlers.NewType(Type{}.New()).MountRoutes(r) handlers.NewPermissions(Permissions{}.New()).MountRoutes(r) + handlers.NewEventTypes(EventTypes{}.New()).MountRoutes(r) }) } diff --git a/compose/automation/expr_types.gen.go b/compose/automation/expr_types.gen.go index 383b2e050..471754dd5 100644 --- a/compose/automation/expr_types.gen.go +++ b/compose/automation/expr_types.gen.go @@ -33,6 +33,9 @@ func NewComposeModule(val interface{}) (*ComposeModule, error) { // Return underlying value on ComposeModule func (t ComposeModule) Get() interface{} { return t.value } +// Return underlying value on ComposeModule +func (t ComposeModule) GetValue() *types.Module { return t.value } + // Return type name func (ComposeModule) Type() string { return "ComposeModule" } @@ -200,6 +203,9 @@ func NewComposeNamespace(val interface{}) (*ComposeNamespace, error) { // Return underlying value on ComposeNamespace func (t ComposeNamespace) Get() interface{} { return t.value } +// Return underlying value on ComposeNamespace +func (t ComposeNamespace) GetValue() *types.Namespace { return t.value } + // Return type name func (ComposeNamespace) Type() string { return "ComposeNamespace" } @@ -359,6 +365,9 @@ func NewComposeRecord(val interface{}) (*ComposeRecord, error) { // Return underlying value on ComposeRecord func (t ComposeRecord) Get() interface{} { return t.value } +// Return underlying value on ComposeRecord +func (t ComposeRecord) GetValue() *types.Record { return t.value } + // Return type name func (ComposeRecord) Type() string { return "ComposeRecord" } @@ -549,6 +558,9 @@ func NewComposeRecordValueErrorSet(val interface{}) (*ComposeRecordValueErrorSet // Return underlying value on ComposeRecordValueErrorSet func (t ComposeRecordValueErrorSet) Get() interface{} { return t.value } +// Return underlying value on ComposeRecordValueErrorSet +func (t ComposeRecordValueErrorSet) GetValue() *types.RecordValueErrorSet { return t.value } + // Return type name func (ComposeRecordValueErrorSet) Type() string { return "ComposeRecordValueErrorSet" } @@ -584,6 +596,9 @@ func NewComposeRecordValues(val interface{}) (*ComposeRecordValues, error) { // Return underlying value on ComposeRecordValues func (t ComposeRecordValues) Get() interface{} { return t.value } +// Return underlying value on ComposeRecordValues +func (t ComposeRecordValues) GetValue() types.RecordValueSet { return t.value } + // Return type name func (ComposeRecordValues) Type() string { return "ComposeRecordValues" } diff --git a/compose/service/event/events.gen.go b/compose/service/event/events.gen.go index 217f091eb..b8bd41ba9 100644 --- a/compose/service/event/events.gen.go +++ b/compose/service/event/events.gen.go @@ -10,8 +10,10 @@ package event import ( "encoding/json" + "github.com/cortezaproject/corteza-server/compose/automation" "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/auth" + "github.com/cortezaproject/corteza-server/pkg/expr" ) // dummy placing to simplify import generation logic @@ -422,6 +424,17 @@ func (res composeBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res composeBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *composeBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -438,6 +451,16 @@ func (res *composeBase) Decode(results map[string][]byte) (err error) { return } +func (res *composeBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "compose:module" // // This function is auto-generated. @@ -825,6 +848,29 @@ func (res moduleBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res moduleBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["module"], err = automation.NewComposeModule(res.module); err != nil { + return nil, err + } + + if rvars["oldModule"], err = automation.NewComposeModule(res.oldModule); err != nil { + return nil, err + } + + if rvars["namespace"], err = automation.NewComposeNamespace(res.namespace); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *moduleBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -861,6 +907,27 @@ func (res *moduleBase) Decode(results map[string][]byte) (err error) { return } +func (res *moduleBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.module != nil && vars.Has("module") { + var aux *automation.ComposeModule + aux, err = automation.NewComposeModule(expr.Must(vars.Select("module"))) + if err != nil { + return + } + + res.module = aux.GetValue() + } + // oldModule marked as immutable + // namespace marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "compose:namespace" // // This function is auto-generated. @@ -1209,6 +1276,25 @@ func (res namespaceBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res namespaceBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["namespace"], err = automation.NewComposeNamespace(res.namespace); err != nil { + return nil, err + } + + if rvars["oldNamespace"], err = automation.NewComposeNamespace(res.oldNamespace); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *namespaceBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -1243,6 +1329,26 @@ func (res *namespaceBase) Decode(results map[string][]byte) (err error) { return } +func (res *namespaceBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.namespace != nil && vars.Has("namespace") { + var aux *automation.ComposeNamespace + aux, err = automation.NewComposeNamespace(expr.Must(vars.Select("namespace"))) + if err != nil { + return + } + + res.namespace = aux.GetValue() + } + // oldNamespace marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "compose:page" // // This function is auto-generated. @@ -1630,6 +1736,25 @@ func (res pageBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res pageBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for *types.Page + + // Could not found expression-type counterpart for *types.Page + + if rvars["namespace"], err = automation.NewComposeNamespace(res.namespace); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *pageBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -1666,6 +1791,19 @@ func (res *pageBase) Decode(results map[string][]byte) (err error) { return } +func (res *pageBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for *types.Page + // oldPage marked as immutable + // namespace marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "compose:record" // // This function is auto-generated. @@ -2191,6 +2329,37 @@ func (res recordBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res recordBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["record"], err = automation.NewComposeRecord(res.record); err != nil { + return nil, err + } + + if rvars["oldRecord"], err = automation.NewComposeRecord(res.oldRecord); err != nil { + return nil, err + } + + if rvars["module"], err = automation.NewComposeModule(res.module); err != nil { + return nil, err + } + + if rvars["namespace"], err = automation.NewComposeNamespace(res.namespace); err != nil { + return nil, err + } + + if rvars["recordValueErrors"], err = automation.NewComposeRecordValueErrorSet(res.recordValueErrors); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *recordBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -2236,3 +2405,34 @@ func (res *recordBase) Decode(results map[string][]byte) (err error) { } return } + +func (res *recordBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.record != nil && vars.Has("record") { + var aux *automation.ComposeRecord + aux, err = automation.NewComposeRecord(expr.Must(vars.Select("record"))) + if err != nil { + return + } + + res.record = aux.GetValue() + } + // oldRecord marked as immutable + // module marked as immutable + // namespace marked as immutable + if res.recordValueErrors != nil && vars.Has("recordValueErrors") { + var aux *automation.ComposeRecordValueErrorSet + aux, err = automation.NewComposeRecordValueErrorSet(expr.Must(vars.Select("recordValueErrors"))) + if err != nil { + return + } + + res.recordValueErrors = aux.GetValue() + } + // Could not find expression-type counterpart for auth.Identifiable + + return +} diff --git a/messaging/automation/dummy.go b/messaging/automation/dummy.go new file mode 100644 index 000000000..075d4da06 --- /dev/null +++ b/messaging/automation/dummy.go @@ -0,0 +1 @@ +package automation diff --git a/pkg/codegen/afunc.go b/pkg/codegen/afunc.go index a5ec2828f..b072e138e 100644 --- a/pkg/codegen/afunc.go +++ b/pkg/codegen/afunc.go @@ -153,7 +153,7 @@ func expandAutomationFunctionTypes(ff []*aFuncDefs, tt []*exprTypesDef) { for _, t := range tt { for typ, d := range t.Types { - ti[t.Prefix+typ] = d + ti[typ] = d } } diff --git a/pkg/codegen/assets/events.gen.go.tpl b/pkg/codegen/assets/events.gen.go.tpl index a82f860e4..963919765 100644 --- a/pkg/codegen/assets/events.gen.go.tpl +++ b/pkg/codegen/assets/events.gen.go.tpl @@ -13,6 +13,7 @@ import ( {{- range .Imports }} {{ normalizeImport . }} {{- end }} + "github.com/cortezaproject/corteza-server/pkg/expr" ) // dummy placing to simplify import generation logic @@ -145,6 +146,28 @@ func (res {{ camelCase .ResourceIdent "base" }}) Encode() (args map[string][]byt return } +// Encode internal data to be passed as event params & arguments to workflow +func (res {{ camelCase .ResourceIdent "base" }}) EncodeVars() (vars *expr.Vars, err error) { + {{- if $r.Properties }} + var ( + rvars = expr.RVars{} + ) + + {{ range $r.Properties }} + {{- if .ExprType }} + if rvars[{{ printf "%q" .Name }}], err = automation.{{ export "new" .ExprType }}(res.{{ .Name }}); err != nil { + return nil, err + } + {{- else }} + // Could not found expression-type counterpart for {{ .Type }} + {{- end }} + {{ end }} + return rvars.Vars(), err + {{ else }} + return + {{ end -}} +} + // Decode return values from Corredor script into struct props func (res *{{ camelCase .ResourceIdent "base" }}) Decode(results map[string][]byte)( err error) { if res.immutable { @@ -179,5 +202,37 @@ func (res *{{ camelCase .ResourceIdent "base" }}) Decode(results map[string][]by return } +func (res *{{ camelCase .ResourceIdent "base" }}) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + + {{- range $r.Properties }} + {{- if .Immutable }} + // {{ .Name }} marked as immutable + {{- else }} + {{- if .ExprType }} + if res.{{ .Name }} != nil && vars.Has({{ printf "%q" .Name }}) { + var aux *automation.{{ export .ExprType }} + aux, err = automation.{{ export "new" .ExprType }}(expr.Must(vars.Select({{ printf "%q" .Name }}))) + if err != nil { + return + } + + res.{{ .Name }} = aux.GetValue() + } + {{- else }} + // Could not find expression-type counterpart for {{ .Type }} + {{- end }} + {{- end }} + {{- end }} + + return +} {{ end }} + + + + diff --git a/pkg/codegen/assets/events_rest_def.gen.go.tpl b/pkg/codegen/assets/events_rest_def.gen.go.tpl new file mode 100644 index 000000000..8d339caba --- /dev/null +++ b/pkg/codegen/assets/events_rest_def.gen.go.tpl @@ -0,0 +1,42 @@ +package rest + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// {{ .Source }} + +func getEventTypeDefinitions() []eventTypeDef { + return []eventTypeDef{ + {{ range .Definitions }} + // {{ printf "%#v" .Imports }} + {{ range $r := .Resources }} + {{ template "eventTypeDefinitions" dict "res" $r "type" "on" "types" .On }} + {{ template "eventTypeDefinitions" dict "res" $r "type" "before" "types" .BeforeAfter }} + {{ template "eventTypeDefinitions" dict "res" $r "type" "after" "types" .BeforeAfter }} + {{ end }} + {{ end }} + } +} + +{{ define "eventTypeDefinitions" }} + {{ range $ev := $.types }} + { + ResourceType: {{ printf "%q" $.res.ResourceString }}, + EventType: {{ printf "%q" (camelCase $.type $ev) }}, + Properties: []eventTypePropertyDef{ + {{ range $.res.Properties }} + {{ if not .Internal }} + { + Name: {{ printf "%q" .Name }}, + Type: {{ printf "%q" .ExprType }}, + Immutable: {{ printf "%v" .Immutable }}, + }, + {{ end }} + {{ end }} + }, + }, + {{ end }} +{{ end }} diff --git a/pkg/codegen/assets/expr_types.gen.go.tpl b/pkg/codegen/assets/expr_types.gen.go.tpl index 0758547a4..7adb2916f 100644 --- a/pkg/codegen/assets/expr_types.gen.go.tpl +++ b/pkg/codegen/assets/expr_types.gen.go.tpl @@ -43,8 +43,11 @@ func New{{ $exprType }}(val interface{}) (*{{ $exprType }}, error) { // Return underlying value on {{ $exprType }} func (t {{ $exprType }}) Get() interface{} { return t.value } +// Return underlying value on {{ $exprType }} +func (t {{ $exprType }}) GetValue() {{ $def.As }} { return t.value } + // Return type name -func ({{ $exprType }}) Type() string { return "{{ $.Prefix }}{{ $exprType }}" } +func ({{ $exprType }}) Type() string { return "{{ $exprType }}" } // Convert value to {{ $def.As }} func ({{ $exprType }}) Cast(val interface{}) (TypedValue, error) { diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index e5a502425..25b2af2ee 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -208,8 +208,19 @@ func Proc() { return } + if exprTypeDefs, err = procExprTypes(exprTypeSrc...); err == nil { + if genCode { + err = genExprTypes(tpls, exprTypeDefs...) + } + } + + if outputErr(err, "failed to process expr types:\n") { + return + } + if eventDefs, err = procEvents(eventSrc...); err == nil { if genCode { + expandEventTypes(eventDefs, exprTypeDefs) err = genEvents(tpls, eventDefs...) } if genDocs && err == nil { @@ -231,16 +242,6 @@ func Proc() { return } - if exprTypeDefs, err = procExprTypes(exprTypeSrc...); err == nil { - if genCode { - err = genExprTypes(tpls, exprTypeDefs...) - } - } - - if outputErr(err, "failed to process expr types:\n") { - return - } - if restDefs, err = procRest(restSrc...); err == nil { if genCode { err = genRest(tpls, restDefs...) diff --git a/pkg/codegen/events.go b/pkg/codegen/events.go index d2bbec311..5fdaa5032 100644 --- a/pkg/codegen/events.go +++ b/pkg/codegen/events.go @@ -26,7 +26,7 @@ type ( Resources evResourceDefMap } - evResourceDefMap map[string]evResourceDef + evResourceDefMap map[string]*evResourceDef evResourceDef struct { // used as string @@ -38,15 +38,16 @@ type ( // used for filename ResourceFile string - On []string `yaml:"on"` - BeforeAfter []string `yaml:"ba"` - Properties []eventProps `yaml:"props"` - Result string `yaml:"result"` + On []string `yaml:"on"` + BeforeAfter []string `yaml:"ba"` + Properties []*eventProps `yaml:"props"` + Result string `yaml:"result"` } eventProps struct { - Name string - Type string + Name string + Type string + ExprType string // Import path for prop type, use package's type by default (see importTypePathTpl) Import string @@ -63,6 +64,7 @@ func procEvents(mm ...string) (dd []*eventsDef, err error) { // /service/event/events.yaml const ( importTypePathTpl = "github.com/cortezaproject/corteza-server/%s/types" + importAutoPathTpl = "github.com/cortezaproject/corteza-server/%s/automation" importAuthPath = "github.com/cortezaproject/corteza-server/pkg/auth" ) @@ -82,7 +84,7 @@ func procEvents(mm ...string) (dd []*eventsDef, err error) { Source: m, App: m[:strings.Index(m, "/")], outputDir: path.Dir(m), - Resources: map[string]evResourceDef{}, + Resources: map[string]*evResourceDef{}, } ) @@ -92,7 +94,14 @@ func procEvents(mm ...string) (dd []*eventsDef, err error) { for resName, evDef := range e { - d.Imports = []string{fmt.Sprintf(importTypePathTpl, d.App)} + d.Imports = []string{ + fmt.Sprintf(importTypePathTpl, d.App), + } + + if d.App != "messaging" { + d.Imports = append(d.Imports, fmt.Sprintf(importAutoPathTpl, d.App)) + } + evDef.ResourceString = resName if l := strings.Index(resName, ":"); l > 0 { @@ -116,7 +125,7 @@ func procEvents(mm ...string) (dd []*eventsDef, err error) { } // Invoker - user that invoked (triggered) the event - evDef.Properties = append(evDef.Properties, eventProps{ + evDef.Properties = append(evDef.Properties, &eventProps{ Name: "invoker", Type: "auth.Identifiable", Import: importAuthPath, @@ -148,6 +157,33 @@ func procEvents(mm ...string) (dd []*eventsDef, err error) { return dd, nil } +func expandEventTypes(ee []*eventsDef, tt []*exprTypesDef) { + // index of all known types + expTypes := make(map[string]*exprTypeDef) + goTypes := make(map[string]string) + + for _, t := range tt { + for typ, d := range t.Types { + expTypes[typ] = d + goTypes[d.As] = typ + } + } + + for _, e := range ee { + for _, r := range e.Resources { + for _, p := range r.Properties { + if p.ExprType != "" && expTypes[p.ExprType] == nil { + fmt.Printf("unknown type %q used for param %q for events on resource %s\n", p.ExprType, p.Name, r.ResourceString) + } + + if p.ExprType == "" && goTypes[p.Type] != "" { + p.ExprType = goTypes[p.Type] + } + } + } + } +} + func genEvents(tpl *template.Template, dd ...*eventsDef) (err error) { var ( // Will only be generated if file does not exist previously @@ -156,6 +192,9 @@ func genEvents(tpl *template.Template, dd ...*eventsDef) (err error) { // Always regenerated tplEventsGen = tpl.Lookup("events.gen.go.tpl") + // List of event-type definitions for automation REST endpoint + tplAutomationRestDefGen = tpl.Lookup("events_rest_def.gen.go.tpl") + dst string ) @@ -182,6 +221,29 @@ func genEvents(tpl *template.Template, dd ...*eventsDef) (err error) { } } + // Remove messaging + var msgIndex = -1 + for i := range dd { + if dd[i].App == "messaging" { + msgIndex = i + } + } + + if msgIndex > -1 { + dd = append(dd[:msgIndex], dd[msgIndex+1:]...) + } + + err = goTemplate( + path.Join("automation", "rest", "eventTypes.gen.go"), + tplAutomationRestDefGen, + map[string]interface{}{ + "Definitions": dd, + "Imports": collectEventDefImports("", dd...), + }) + if err != nil { + return + } + return nil } @@ -216,3 +278,16 @@ func genEventsDocs(tpl *template.Template, docsPath string, dd ...*eventsDef) (e "Definitions": dd, }) } + +func collectEventDefImports(basePkg string, dd ...*eventsDef) []string { + ii := make([]string, 0, len(dd)) + for _, d := range dd { + for _, i := range d.Imports { + if !slice.HasString(ii, i) && (basePkg == "" || !strings.HasSuffix(i, basePkg)) { + ii = append(ii, i) + } + } + } + + return ii +} diff --git a/pkg/codegen/expr_types.go b/pkg/codegen/expr_types.go index 263928344..cfe09b4d8 100644 --- a/pkg/codegen/expr_types.go +++ b/pkg/codegen/expr_types.go @@ -19,7 +19,6 @@ type ( Imports []string Package string `yaml:"package"` - Prefix string `yaml:"prefix"` Types map[string]*exprTypeDef `yaml:"types"` } diff --git a/pkg/expr/expr_types.gen.go b/pkg/expr/expr_types.gen.go index f9498b636..b3ef8d67d 100644 --- a/pkg/expr/expr_types.gen.go +++ b/pkg/expr/expr_types.gen.go @@ -33,6 +33,9 @@ func NewAny(val interface{}) (*Any, error) { // Return underlying value on Any func (t Any) Get() interface{} { return t.value } +// Return underlying value on Any +func (t Any) GetValue() interface{} { return t.value } + // Return type name func (Any) Type() string { return "Any" } @@ -68,6 +71,9 @@ func NewArray(val interface{}) (*Array, error) { // Return underlying value on Array func (t Array) Get() interface{} { return t.value } +// Return underlying value on Array +func (t Array) GetValue() []TypedValue { return t.value } + // Return type name func (Array) Type() string { return "Array" } @@ -103,6 +109,9 @@ func NewBoolean(val interface{}) (*Boolean, error) { // Return underlying value on Boolean func (t Boolean) Get() interface{} { return t.value } +// Return underlying value on Boolean +func (t Boolean) GetValue() bool { return t.value } + // Return type name func (Boolean) Type() string { return "Boolean" } @@ -138,6 +147,9 @@ func NewDateTime(val interface{}) (*DateTime, error) { // Return underlying value on DateTime func (t DateTime) Get() interface{} { return t.value } +// Return underlying value on DateTime +func (t DateTime) GetValue() *time.Time { return t.value } + // Return type name func (DateTime) Type() string { return "DateTime" } @@ -173,6 +185,9 @@ func NewDuration(val interface{}) (*Duration, error) { // Return underlying value on Duration func (t Duration) Get() interface{} { return t.value } +// Return underlying value on Duration +func (t Duration) GetValue() time.Duration { return t.value } + // Return type name func (Duration) Type() string { return "Duration" } @@ -208,6 +223,9 @@ func NewFloat(val interface{}) (*Float, error) { // Return underlying value on Float func (t Float) Get() interface{} { return t.value } +// Return underlying value on Float +func (t Float) GetValue() float64 { return t.value } + // Return type name func (Float) Type() string { return "Float" } @@ -243,6 +261,9 @@ func NewHandle(val interface{}) (*Handle, error) { // Return underlying value on Handle func (t Handle) Get() interface{} { return t.value } +// Return underlying value on Handle +func (t Handle) GetValue() string { return t.value } + // Return type name func (Handle) Type() string { return "Handle" } @@ -278,6 +299,9 @@ func NewID(val interface{}) (*ID, error) { // Return underlying value on ID func (t ID) Get() interface{} { return t.value } +// Return underlying value on ID +func (t ID) GetValue() uint64 { return t.value } + // Return type name func (ID) Type() string { return "ID" } @@ -313,6 +337,9 @@ func NewInteger(val interface{}) (*Integer, error) { // Return underlying value on Integer func (t Integer) Get() interface{} { return t.value } +// Return underlying value on Integer +func (t Integer) GetValue() int64 { return t.value } + // Return type name func (Integer) Type() string { return "Integer" } @@ -348,6 +375,9 @@ func NewKV(val interface{}) (*KV, error) { // Return underlying value on KV func (t KV) Get() interface{} { return t.value } +// Return underlying value on KV +func (t KV) GetValue() map[string]string { return t.value } + // Return type name func (KV) Type() string { return "KV" } @@ -383,6 +413,9 @@ func NewKVV(val interface{}) (*KVV, error) { // Return underlying value on KVV func (t KVV) Get() interface{} { return t.value } +// Return underlying value on KVV +func (t KVV) GetValue() map[string][]string { return t.value } + // Return type name func (KVV) Type() string { return "KVV" } @@ -418,6 +451,9 @@ func NewReader(val interface{}) (*Reader, error) { // Return underlying value on Reader func (t Reader) Get() interface{} { return t.value } +// Return underlying value on Reader +func (t Reader) GetValue() io.Reader { return t.value } + // Return type name func (Reader) Type() string { return "Reader" } @@ -453,6 +489,9 @@ func NewString(val interface{}) (*String, error) { // Return underlying value on String func (t String) Get() interface{} { return t.value } +// Return underlying value on String +func (t String) GetValue() string { return t.value } + // Return type name func (String) Type() string { return "String" } @@ -488,6 +527,9 @@ func NewUnsignedInteger(val interface{}) (*UnsignedInteger, error) { // Return underlying value on UnsignedInteger func (t UnsignedInteger) Get() interface{} { return t.value } +// Return underlying value on UnsignedInteger +func (t UnsignedInteger) GetValue() uint64 { return t.value } + // Return type name func (UnsignedInteger) Type() string { return "UnsignedInteger" } @@ -523,6 +565,9 @@ func NewVars(val interface{}) (*Vars, error) { // Return underlying value on Vars func (t Vars) Get() interface{} { return t.value } +// Return underlying value on Vars +func (t Vars) GetValue() RVars { return t.value } + // Return type name func (Vars) Type() string { return "Vars" } diff --git a/store/rdbms/flags.gen.go b/store/rdbms/flags.gen.go index e44c659ea..6a154aa99 100644 --- a/store/rdbms/flags.gen.go +++ b/store/rdbms/flags.gen.go @@ -281,7 +281,7 @@ func (s Store) internalFlagRowScanner(row rowScanner) (res *types.Flag, err erro } if err != nil { - return nil, errors.Store("could not scan flag db row").Wrap(err) + return nil, errors.Store("could not scan flag db row: %s", err).Wrap(err) } else { return res, nil } diff --git a/system/automation/expr_types.gen.go b/system/automation/expr_types.gen.go index 7c16d35d0..abb8fb7f2 100644 --- a/system/automation/expr_types.gen.go +++ b/system/automation/expr_types.gen.go @@ -33,6 +33,9 @@ func NewRole(val interface{}) (*Role, error) { // Return underlying value on Role func (t Role) Get() interface{} { return t.value } +// Return underlying value on Role +func (t Role) GetValue() *types.Role { return t.value } + // Return type name func (Role) Type() string { return "Role" } @@ -200,6 +203,9 @@ func NewUser(val interface{}) (*User, error) { // Return underlying value on User func (t User) Get() interface{} { return t.value } +// Return underlying value on User +func (t User) GetValue() *types.User { return t.value } + // Return type name func (User) Type() string { return "User" } diff --git a/system/service/event/events.gen.go b/system/service/event/events.gen.go index 362eed263..ccdb292f3 100644 --- a/system/service/event/events.gen.go +++ b/system/service/event/events.gen.go @@ -11,6 +11,8 @@ package event import ( "encoding/json" "github.com/cortezaproject/corteza-server/pkg/auth" + "github.com/cortezaproject/corteza-server/pkg/expr" + "github.com/cortezaproject/corteza-server/system/automation" "github.com/cortezaproject/corteza-server/system/types" ) @@ -533,6 +535,17 @@ func (res systemBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res systemBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *systemBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -549,6 +562,16 @@ func (res *systemBase) Decode(results map[string][]byte) (err error) { return } +func (res *systemBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:application" // // This function is auto-generated. @@ -897,6 +920,21 @@ func (res applicationBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res applicationBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for *types.Application + + // Could not found expression-type counterpart for *types.Application + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *applicationBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -931,6 +969,18 @@ func (res *applicationBase) Decode(results map[string][]byte) (err error) { return } +func (res *applicationBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for *types.Application + // oldApplication marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:auth" // // This function is auto-generated. @@ -1163,6 +1213,23 @@ func (res authBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res authBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["user"], err = automation.NewUser(res.user); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for *types.AuthProvider + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *authBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -1203,6 +1270,26 @@ func (res *authBase) Decode(results map[string][]byte) (err error) { return } +func (res *authBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.user != nil && vars.Has("user") { + var aux *automation.User + aux, err = automation.NewUser(expr.Must(vars.Select("user"))) + if err != nil { + return + } + + res.user = aux.GetValue() + } + // Could not find expression-type counterpart for *types.AuthProvider + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:auth-client" // // This function is auto-generated. @@ -1551,6 +1638,21 @@ func (res authClientBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res authClientBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for *types.AuthClient + + // Could not found expression-type counterpart for *types.AuthClient + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *authClientBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -1585,6 +1687,18 @@ func (res *authClientBase) Decode(results map[string][]byte) (err error) { return } +func (res *authClientBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for *types.AuthClient + // oldAuthClient marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:mail" // // This function is auto-generated. @@ -1746,6 +1860,19 @@ func (res mailBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res mailBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for *types.MailMessage + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *mailBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -1778,6 +1905,17 @@ func (res *mailBase) Decode(results map[string][]byte) (err error) { return } +func (res *mailBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for *types.MailMessage + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:role" // // This function is auto-generated. @@ -2126,6 +2264,25 @@ func (res roleBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res roleBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["role"], err = automation.NewRole(res.role); err != nil { + return nil, err + } + + if rvars["oldRole"], err = automation.NewRole(res.oldRole); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *roleBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -2160,6 +2317,26 @@ func (res *roleBase) Decode(results map[string][]byte) (err error) { return } +func (res *roleBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.role != nil && vars.Has("role") { + var aux *automation.Role + aux, err = automation.NewRole(expr.Must(vars.Select("role"))) + if err != nil { + return + } + + res.role = aux.GetValue() + } + // oldRole marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:role:member" // // This function is auto-generated. @@ -2392,6 +2569,25 @@ func (res roleMemberBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res roleMemberBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["user"], err = automation.NewUser(res.user); err != nil { + return nil, err + } + + if rvars["role"], err = automation.NewRole(res.role); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *roleMemberBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -2432,6 +2628,34 @@ func (res *roleMemberBase) Decode(results map[string][]byte) (err error) { return } +func (res *roleMemberBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.user != nil && vars.Has("user") { + var aux *automation.User + aux, err = automation.NewUser(expr.Must(vars.Select("user"))) + if err != nil { + return + } + + res.user = aux.GetValue() + } + if res.role != nil && vars.Has("role") { + var aux *automation.Role + aux, err = automation.NewRole(expr.Must(vars.Select("role"))) + if err != nil { + return + } + + res.role = aux.GetValue() + } + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:sink" // // This function is auto-generated. @@ -2534,6 +2758,21 @@ func (res sinkBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res sinkBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + // Could not found expression-type counterpart for *types.SinkResponse + + // Could not found expression-type counterpart for *types.SinkRequest + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *sinkBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -2568,6 +2807,18 @@ func (res *sinkBase) Decode(results map[string][]byte) (err error) { return } +func (res *sinkBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + // Could not find expression-type counterpart for *types.SinkResponse + // request marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +} + // ResourceType returns "system:user" // // This function is auto-generated. @@ -2916,6 +3167,25 @@ func (res userBase) Encode() (args map[string][]byte, err error) { return } +// Encode internal data to be passed as event params & arguments to workflow +func (res userBase) EncodeVars() (vars *expr.Vars, err error) { + var ( + rvars = expr.RVars{} + ) + + if rvars["user"], err = automation.NewUser(res.user); err != nil { + return nil, err + } + + if rvars["oldUser"], err = automation.NewUser(res.oldUser); err != nil { + return nil, err + } + + // Could not found expression-type counterpart for auth.Identifiable + + return rvars.Vars(), err +} + // Decode return values from Corredor script into struct props func (res *userBase) Decode(results map[string][]byte) (err error) { if res.immutable { @@ -2949,3 +3219,23 @@ func (res *userBase) Decode(results map[string][]byte) (err error) { } return } + +func (res *userBase) DecodeVars(vars *expr.Vars) (err error) { + if res.immutable { + // Respect immutability + return + } + if res.user != nil && vars.Has("user") { + var aux *automation.User + aux, err = automation.NewUser(expr.Must(vars.Select("user"))) + if err != nil { + return + } + + res.user = aux.GetValue() + } + // oldUser marked as immutable + // Could not find expression-type counterpart for auth.Identifiable + + return +}