zitadel/internal/v2/eventstore/event.go
Silvan 12be21a3ff
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
2024-05-23 06:36:08 +02:00

67 lines
932 B
Go

package eventstore
import (
"time"
)
type Unmarshal func(ptr any) error
type Payload interface {
Unmarshal | any
}
type Action[P Payload] struct {
Creator string
Type string
Revision uint16
Payload P
}
type Command struct {
Action[any]
UniqueConstraints []*UniqueConstraint
}
type StorageEvent struct {
Action[Unmarshal]
Aggregate Aggregate
CreatedAt time.Time
Position GlobalPosition
Sequence uint32
}
type Event[P any] struct {
*StorageEvent
Payload P
}
func UnmarshalPayload[P any](unmarshal Unmarshal) (P, error) {
var payload P
err := unmarshal(&payload)
return payload, err
}
type EmptyPayload struct{}
type TypeChecker interface {
ActionType() string
}
func Type[T TypeChecker]() string {
var t T
return t.ActionType()
}
func IsType[T TypeChecker](types ...string) bool {
gotten := Type[T]()
for _, typ := range types {
if gotten == typ {
return true
}
}
return false
}