mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
12be21a3ff
creates events structures for initial projections and read models
67 lines
932 B
Go
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
|
|
}
|