support multiple mutations
All checks were successful
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m13s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m54s

This commit is contained in:
2025-10-13 19:51:27 +02:00
parent 91e398dcc3
commit 8e60cc2239
5 changed files with 33 additions and 26 deletions

View File

@@ -10,7 +10,7 @@ import (
)
type MutationRegistry interface {
Apply(grain any, msg proto.Message) error
Apply(grain any, msg ...proto.Message) error
RegisterMutations(handlers ...MutationHandler)
Create(typeName string) (proto.Message, bool)
GetTypeName(msg proto.Message) (string, bool)
@@ -145,7 +145,7 @@ func (r *ProtoMutationRegistry) Create(typeName string) (proto.Message, bool) {
// Returns updated grain if successful.
//
// If the mutation is not registered, returns (nil, ErrMutationNotRegistered).
func (r *ProtoMutationRegistry) Apply(grain any, msg proto.Message) error {
func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) error {
if grain == nil {
return fmt.Errorf("nil grain")
}
@@ -161,9 +161,10 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg proto.Message) error {
if !ok {
return ErrMutationNotRegistered
}
if err := entry.Handle(grain, msg); err != nil {
return err
for _, m := range msg {
if err := entry.Handle(grain, m); err != nil {
return err
}
}
// if entry.updateTotals {