mesh/delivery merged: source.main moved to novox/mesh-sdk@27da949140c6
mesh/check being carried to 8afc3ebdf371 on 93e0a7b50d90 | from 27da949140c6
The group feat/47-G-join11 merged 3 of 17 members on 2026-11-13; G's mesh-sdk alone on main breaks 25 trunk
modules. The operator chose to put the order right: a reader release first, then G whole. This restores main
to 8fbba810 exactly.
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
60 lines
2.3 KiB
Go
60 lines
2.3 KiB
Go
// Package busstate is how a bundle uses its own bus state through the runtime (novox/hq ADR 0595 §9, design 25 §
|
|
// 12.5): the object store's put, get, list, delete and fill, each naming an entry by the local name its module asks for
|
|
// it by in `requires`. The runtime serves the calls from the module's own bindings, its own entries only. The shapes
|
|
// are package buscalls's; this package makes the calls.
|
|
package busstate
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
)
|
|
|
|
// Objects is one object store the module asks for in `requires` (the template objects, ADR 0595 §2), by its local name.
|
|
type Objects struct{ local string }
|
|
|
|
// ObjectsOf is the object store of that local name.
|
|
func ObjectsOf(local string) Objects { return Objects{local: local} }
|
|
|
|
func call[T any](method string, params any) (T, error) {
|
|
var out T
|
|
raw, err := stdio.BusState(method, params)
|
|
if err != nil {
|
|
return out, err
|
|
}
|
|
if err := json.Unmarshal(raw, &out); err != nil {
|
|
return out, fmt.Errorf("the runtime's answer to %s: %w", method, err)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Put stores one object whole under its name, replacing one of that name, and answers it as the store holds it.
|
|
func (o Objects) Put(name string, data []byte, description string) (buscalls.ObjectInfo, error) {
|
|
return call[buscalls.ObjectInfo](buscalls.ObjectsPut, buscalls.ObjectsPutRequest{Objects: o.local, Name: name,
|
|
Data: data, Description: description})
|
|
}
|
|
|
|
// Get is one object, its info and its bytes.
|
|
func (o Objects) Get(name string) (buscalls.ObjectData, error) {
|
|
return call[buscalls.ObjectData](buscalls.ObjectsGet, buscalls.ObjectsNameRequest{Objects: o.local, Name: name})
|
|
}
|
|
|
|
// List is every object the store holds.
|
|
func (o Objects) List() ([]buscalls.ObjectInfo, error) {
|
|
l, err := call[buscalls.ObjectsListed](buscalls.ObjectsList, buscalls.ObjectsRequest{Objects: o.local})
|
|
return l.Objects, err
|
|
}
|
|
|
|
// Delete removes one object.
|
|
func (o Objects) Delete(name string) error {
|
|
_, err := call[buscalls.Done](buscalls.ObjectsDelete, buscalls.ObjectsNameRequest{Objects: o.local, Name: name})
|
|
return err
|
|
}
|
|
|
|
// Fill is how much the store holds against its cap.
|
|
func (o Objects) Fill() (buscalls.Fill, error) {
|
|
return call[buscalls.Fill](buscalls.ObjectsInfo, buscalls.ObjectsRequest{Objects: o.local})
|
|
}
|