Files
mesh-delivery/modules/mesh-delivery-builder/internal/versions/entrynames.go
T
jschoubben 5524cfa8d8 BL6: the builder follows the catalog half per watched branch through the shared branch follower
The builder adopts meshcatalogclient's branch follower on its views reader (A-5, A-15): the modules, their manifests (kept from the
entry that holds them, by its digest), their packages and each package's name in its ecosystem are read from the catalog half's
entries, never the indexer's modules, manifests, candidates and packages views; an entry of a branch other than the module's first
builds its fingerprint and supersedes only its own branch's older one; the start's sweep runs once every followed half's first view
is in; the builder's tools bundle reads package names through the same follower. A run's candidate is no input of the builder
(A-84): its read of the indexer's candidates view goes, and the entry point for a run's build ask is not built (no line gives the
ask's form). The seats' events the builder's own handler takes are named per seat so the follower's events have one taker.

Builds: design 47 G §348, §479, §614, A-5, A-15, A-84
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-11 23:27:01 +01:00

83 lines
3.0 KiB
Go

package versions
import (
"context"
"sort"
"strings"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
)
// Entries are the catalog graph entries of the halves the builder follows, one per module and watched branch (design 47 G §348,
// §614): where a package's name in its ecosystem is read from, each artifact's `package` (§676), never the indexer's state.
type Entries func() []meshcatalog.CatalogEntry
// artifactOf is the artifact name of an artifact reference `<module>:<artifact>` of module.
func artifactOf(module, ref string) (string, bool) {
m, a, ok := strings.Cut(ref, ":")
return a, ok && m == module && a != ""
}
// NamesFrom answers a package's name in its ecosystem from the entries (design 47 G §348): the name the entry of module gives the
// artifact; known is false when no entry names one for it.
func NamesFrom(all Entries) PackageNames {
return func(_ context.Context, module, artifact string) (string, bool, error) {
for _, e := range all() {
if e.Module != module {
continue
}
for _, a := range e.Artifacts {
if name, ok := artifactOf(module, a.Ref); ok && name == artifact && a.Package != nil && a.Package.Name != "" {
return a.Package.Name, true, nil
}
}
}
return "", false, nil
}
}
// CarriersFrom are the module artifacts a package's name in its ecosystem is the name of, as the entries hold them (design 47 G
// §572, §478), each distinct module and artifact once, sorted; a name no entry carries answers none.
func CarriersFrom(all Entries) func(ctx context.Context, name string) ([]Built, error) {
return func(_ context.Context, name string) ([]Built, error) {
seen := map[Built]bool{}
var out []Built
for _, e := range all() {
for _, a := range e.Artifacts {
artifact, ok := artifactOf(e.Module, a.Ref)
if !ok || a.Package == nil || a.Package.Name != name || seen[Built{e.Module, artifact}] {
continue
}
seen[Built{e.Module, artifact}] = true
out = append(out, Built{e.Module, artifact})
}
}
sort.Slice(out, func(i, j int) bool { return out[i].Module+"/"+out[i].Artifact < out[j].Module+"/"+out[j].Artifact })
return out, nil
}
}
// ModuleFrom is the module and artifact a package's name is built from, from the entries (CarriersFrom); more than one entry
// carrying it is an error naming them.
func ModuleFrom(all Entries) func(ctx context.Context, name string) (module, artifact string, found bool, err error) {
return moduleOfCarriers(CarriersFrom(all))
}
// EntriesOf are the entries of every half the branch follower holds, the followed branches in the order they came.
func EntriesOf(branches *meshcatalogclient.Branches) Entries {
return func() []meshcatalog.CatalogEntry {
var out []meshcatalog.CatalogEntry
for _, br := range branches.Followed() {
if cat, ok := branches.Catalog(br); ok {
if half, ok := cat.View(); ok {
for _, e := range half.Entries {
out = append(out, e)
}
}
}
}
return out
}
}