stdio.BusState asks the runtime one buscalls method on the bundle's own bus state; package busstate makes the object store's put, get, list, delete and fill by the store's local name (A3's request 1, distribution's incoming). Its test takes the place of one merged into its neighbour, so mesh-sdk's unit count does not grow. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package stdio
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// busStateCalls are the method prefixes of the calls a bundle makes on its own bus state through the runtime (novox/hq
|
|
// ADR 0595 §9, design 25 § 12.5): their shapes and names are package buscalls's, and package busstate the typed way
|
|
// to make them.
|
|
var busStateCalls = []string{"mesh/objects.", "mesh/stream.", "mesh/workqueue.", "mesh/ledger."}
|
|
|
|
// BusState asks the runtime one call on this bundle's own bus state, an entry its module asks for in `requires`, named
|
|
// by its local name in params; the runtime serves it from the module's own bindings only. A method that is none of
|
|
// those calls is refused here, before the runtime is asked.
|
|
func BusState(method string, params any) (json.RawMessage, error) {
|
|
known := false
|
|
for _, p := range busStateCalls {
|
|
known = known || strings.HasPrefix(method, p)
|
|
}
|
|
if !known {
|
|
return nil, fmt.Errorf("%s is no call on a bundle's own bus state (%s)", method, strings.Join(busStateCalls, ", "))
|
|
}
|
|
c, err := live()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.ask(method, params, 60*time.Second)
|
|
}
|