The process and the tools bundle read the catalog half through Branches (FollowBranchesProcess, FollowBranches) and Branches.Entry instead of one view of a branch named in code; the module's value carries the entry's manifest-digest bare and computes none. The manifest consumes registration-changed and source-moved and invokes registrations, and revision, entry and source in the long form with the fields relied on. The built binary committed at the module's root goes. Builds: design 47 G §532, §614, §558, §506, §578, A-103 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"sort"
|
|
|
|
"mesh-delivery-view/internal/view"
|
|
)
|
|
|
|
// catalogRead is the modules the view's tools answer, read from the catalog half per watched branch through
|
|
// meshcatalogclient's branch follower (design 47 G §532, §614): every module a followed branch's view lists, each the
|
|
// entry Branches.Entry reads, the first branch of the module's own registration (A-103), in the form of the value the
|
|
// tools always answered. Until every watched branch has its first view the read says what it waits for; it never answers
|
|
// no modules.
|
|
func catalogRead(b *meshcatalogclient.Branches) view.StateRead {
|
|
read := func() (map[string]json.RawMessage, error) {
|
|
if err := b.Ready(); err != nil {
|
|
return nil, fmt.Errorf("%w (%s)", err, meshcatalogclient.RevisionVerb)
|
|
}
|
|
values := map[string]json.RawMessage{}
|
|
for _, branch := range b.Followed() {
|
|
c, ok := b.Catalog(branch)
|
|
if !ok {
|
|
continue
|
|
}
|
|
half, _ := c.View()
|
|
for module := range half.Entries {
|
|
if _, done := values[module]; done {
|
|
continue
|
|
}
|
|
e, ok, err := b.Entry(module)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
raw, _ := json.Marshal(e)
|
|
v, err := view.ModuleValue(raw)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the catalog entry of %s: %w", module, err)
|
|
}
|
|
values[module] = v
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
return view.StateRead{
|
|
Keys: func() ([]string, error) {
|
|
v, err := read()
|
|
keys := make([]string, 0, len(v))
|
|
for k := range v {
|
|
keys = append(keys, k)
|
|
}
|
|
sort.Strings(keys)
|
|
return keys, err
|
|
},
|
|
Get: func(key string) (json.RawMessage, error) {
|
|
if err := b.Ready(); err != nil {
|
|
return nil, fmt.Errorf("%w (%s)", err, meshcatalogclient.RevisionVerb)
|
|
}
|
|
e, ok, err := b.Entry(key)
|
|
if err != nil || !ok {
|
|
return nil, err
|
|
}
|
|
raw, _ := json.Marshal(e)
|
|
return view.ModuleValue(raw)
|
|
},
|
|
All: read,
|
|
}
|
|
}
|