Files
mesh-delivery/modules/mesh-delivery-indexer/judge/oldsections.go
T

70 lines
2.5 KiB
Go

package judge
import (
"fmt"
"slices"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// The old sections end when no module is left in them (issue 1966 D4; novox/hq ADR 0595 §11): the indexer counts, per old
// section, the accepted modules using it, the foundation left out, and the judge refuses a manifest of another module
// that uses a section whose count is 0. The foundation (the bus module, the grants part and the indexer itself) is
// created before the bus module can create anything, so it keeps the old sections for good and is always accepted.
// OldSections are the sections of a manifest that keep bus state in the old forms.
var OldSections = []string{"state", "logs", "streams", "objects"}
// Foundation are the modules that keep using the old sections for good.
var Foundation = []string{"nats", "mesh-grants", "mesh-delivery-indexer"}
// OldSectionCounts is, per old section, how many accepted modules outside the foundation use it. Nil is no count: the
// judge then refuses no use of a section.
type OldSectionCounts map[string]int
// SectionsUsed are the old sections a manifest uses, in OldSections' order.
func SectionsUsed(m catalogue.Manifest) []string {
var used []string
for _, s := range OldSections {
if (s == "state" && len(m.State) > 0) || (s == "logs" && len(m.Logs) > 0) ||
(s == "streams" && len(m.Streams) > 0) || (s == "objects" && len(m.Objects) > 0) {
used = append(used, s)
}
}
return used
}
// CountOldSections counts, per old section, the manifests using it, the foundation's left out; every section is in the
// answer, with 0 where none uses it.
func CountOldSections(manifests []catalogue.Manifest) OldSectionCounts {
counts := OldSectionCounts{}
for _, s := range OldSections {
counts[s] = 0
}
for _, m := range manifests {
if slices.Contains(Foundation, m.Module) {
continue
}
for _, s := range SectionsUsed(m) {
counts[s]++
}
}
return counts
}
// OldSectionProblems are the old sections a manifest uses that no accepted module outside the foundation uses any more.
func OldSectionProblems(m catalogue.Manifest, counts OldSectionCounts) []string {
if counts == nil || slices.Contains(Foundation, m.Module) {
return nil
}
var problems []string
for _, s := range SectionsUsed(m) {
if counts[s] == 0 {
problems = append(problems, fmt.Sprintf(
"%s uses the old section %s, which no other module uses any more (0 modules count); ask for it in "+
"`requires` by template (novox/hq ADR 0595 §11)", m.Module, s))
}
}
return problems
}