Skip to content

Commit

Permalink
feat(schema)!: support kv-pair updates array
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Aug 13, 2024
1 parent 75db9d7 commit 26d8c77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
12 changes: 6 additions & 6 deletions schema/appdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ type ToJSON = func() (json.RawMessage, error)

// KVPairData represents a batch of key-value pair data that is passed to a listener.
type KVPairData struct {
Updates []ModuleKVPairUpdate
Updates []ModuleKVPairUpdates
}

// ModuleKVPairUpdate represents a key-value pair update for a specific module.
type ModuleKVPairUpdate struct {
// ModuleName is the name of the module that the key-value pair belongs to.
// ModuleKVPairUpdates represents key-value pair updates for a specific module.
type ModuleKVPairUpdates struct {
// ModuleName is the name of the module that the key-value pairs belongs to.
ModuleName string

// Update is the key-value pair update.
Update schema.KVPairUpdate
// Updates are the key-value pair updates.
Updates []schema.KVPairUpdate
}

// ObjectUpdateData represents object update data that is passed to a listener.
Expand Down
10 changes: 6 additions & 4 deletions schema/decoding/decoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,14 @@ func (t testStore) GetUInt64(key []byte) uint64 {

func (t testStore) Set(key, value []byte) {
if t.listener.OnKVPair != nil {
err := t.listener.OnKVPair(appdata.KVPairData{Updates: []appdata.ModuleKVPairUpdate{
err := t.listener.OnKVPair(appdata.KVPairData{Updates: []appdata.ModuleKVPairUpdates{
{
ModuleName: t.modName,
Update: schema.KVPairUpdate{
Key: key,
Value: value,
Updates: []schema.KVPairUpdate{
{
Key: key,
Value: value,
},
},
},
}})
Expand Down
30 changes: 16 additions & 14 deletions schema/decoding/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,24 @@ func Middleware(target appdata.Listener, resolver DecoderResolver, opts Middlewa
continue
}

updates, err := pcdc.KVDecoder(kvUpdate.Update)
if err != nil {
return err
}
for _, update := range kvUpdate.Updates {
updates, err := pcdc.KVDecoder(update)
if err != nil {
return err
}

if len(updates) == 0 {
// no updates
continue
}
if len(updates) == 0 {
// no updates
continue
}

err = target.OnObjectUpdate(appdata.ObjectUpdateData{
ModuleName: kvUpdate.ModuleName,
Updates: updates,
})
if err != nil {
return err
err = target.OnObjectUpdate(appdata.ObjectUpdateData{
ModuleName: kvUpdate.ModuleName,
Updates: updates,
})
if err != nil {
return err
}
}
}

Expand Down

0 comments on commit 26d8c77

Please sign in to comment.