Files
mesh-sdk/go/stateobjects/bundle.go
T
jschoubben 48706563c3 G C-2, C-3: a value larger than one chunk is put and got by session through the tool runner
buscalls.ChunkBytes (512 KiB), mesh/objects.put-chunk and get-chunk with the store named in each chunk, the digest and size
of a get checked, the capability word put-sessions required, and a bundle's refusal of a value over 8 MiB gone.

Builds: design 47 G §518, §345, §490, §620, A-21
Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 21:54:31 +01:00

79 lines
2.3 KiB
Go

package stateobjects
import (
"encoding/json"
"errors"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/busstate"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// ForState is a state of this module, kept through its runtime: the state by its local name, and its object store
// `<state>-objects` (catalogue.StateObjectsName).
func ForState(state string) Values {
store := catalogue.StateObjectsName(state)
return Values{KV: BundleKV{State: stdio.State(state)}, Objects: BundleObjects{Store: busstate.ObjectsOf(store)}, Store: store}
}
// BundleKV is a state as a bundle reaches it.
type BundleKV struct{ State stdio.KeptState }
func (b BundleKV) Get(key string) (*Entry, error) {
e, err := b.State.Get(key)
if err != nil || e == nil {
return nil, err
}
return &Entry{Value: e.Value, Revision: e.Revision}, nil
}
func changed(err error) error {
if errors.Is(err, stdio.ErrChanged) {
return ErrChanged
}
return err
}
func (b BundleKV) Create(key string, value []byte) error {
_, err := b.State.Create(key, json.RawMessage(value))
return changed(err)
}
func (b BundleKV) Update(key string, value []byte, revision uint64) error {
_, err := b.State.Update(key, json.RawMessage(value), revision)
return changed(err)
}
func (b BundleKV) Delete(key string) error { return b.State.Delete(key) }
func (b BundleKV) Keys() ([]string, error) { return b.State.Keys() }
// BundleObjects is an object store as a bundle reaches it.
type BundleObjects struct{ Store busstate.Objects }
// MostBytes is zero: a bundle's value of any size is put by a session of chunks, bounded by its store's cap, which the tool
// runner refuses at the chunk that passes it (design 47 G §518).
func (BundleObjects) MostBytes() int { return 0 }
func (b BundleObjects) Put(name string, data []byte) error {
_, err := b.Store.Put(name, data, "a value kept beside its key")
return err
}
func (b BundleObjects) Get(name string) ([]byte, error) {
d, err := b.Store.Get(name)
return d.Data, err
}
func (b BundleObjects) Delete(name string) error { return b.Store.Delete(name) }
func (b BundleObjects) List() ([]Object, error) {
l, err := b.Store.List()
out := make([]Object, 0, len(l))
for _, o := range l {
if !o.Deleted {
out = append(out, Object{Name: o.Name, Size: int64(o.Size), Modified: o.Modified})
}
}
return out, err
}