Answer architecture round 5: the shipped packages are enus, svse, geose, geous and misc, each holding its files at its root under its manifest's namespace, and the errors use the wording a bench of the Audience chose

This commit is contained in:
2026-10-11 12:15:41 +02:00
committed by Lillem4n
parent 29a76d5d9a
commit 7b70530a8a
152 changed files with 217 additions and 132 deletions
+20 -6
View File
@@ -13,11 +13,13 @@ import (
)
// Source is one tree to load, from the root of an fs.FS. label prefixes file names in
// errors; onDisk marks label as a directory that must exist.
// errors; onDisk marks label as a directory that must exist. mount is the folders the
// tree's root sits under, in the namespace its categories are reached by.
type Source struct {
fsys fs.FS
label string
onDisk bool
mount []string
}
// Dir is the tree in the directory path, its errors labelled with it.
@@ -28,8 +30,16 @@ func Dir(path string) Source {
// FS is the tree in fsys.
func FS(fsys fs.FS) Source { return Source{fsys: fsys} }
// Category is one category file: the folders above it from the source's root, its name,
// and its parsed JSON.
// Mounted is s with its root under the dot path namespace, "" for the namespace's root.
func (s Source) Mounted(namespace string) Source {
if namespace != "" {
s.mount = strings.Split(namespace, ".")
}
return s
}
// Category is one category file: the folders above it in the namespace, its name, and its
// parsed JSON.
type Category struct {
Folders []string
Name string
@@ -62,7 +72,10 @@ func (s Source) Walk(compile func(Category) error) error {
if err := s.check(); err != nil {
return err
}
_, err := s.walkDir(nil, compile)
_, err := s.walkDir(nil, func(c Category) error {
c.Folders = append(s.mount[:len(s.mount):len(s.mount)], c.Folders...)
return compile(c)
})
return err
}
@@ -123,9 +136,10 @@ func (s Source) walkFolder(dir []string, compile func(Category) error) (bool, er
return true, nil
}
// Load hands compile the category file name.json in the folder dir.
// Load hands compile the category file name.json in the folder dir of the namespace, which
// lies under the source's mount.
func (s Source) Load(dir []string, name string, compile func(Category) error) error {
full := s.dirPath(dir)
full := s.dirPath(dir[len(s.mount):])
entries, err := fs.ReadDir(s.fsys, full)
if err != nil {
return fmt.Errorf("%s: %w", s.labelled(full), err)
+26 -1
View File
@@ -21,6 +21,8 @@ type Manifest struct {
// Reads is every module the source reads by default, directly or through another;
// nothing loads them.
Reads []string `json:"reads"`
// Namespace is the dot path the source's root sits under, "" for the namespace's root.
Namespace string `json:"namespace"`
}
// IndexEntry is what an index says of a category: its parent table, "" for none, and the
@@ -72,17 +74,40 @@ func decodeManifest(b []byte) (Manifest, error) {
var indexErrs []error
m.Index, indexErrs = decodeIndex(top[k])
errs = append(errs, indexErrs...)
case "namespace":
var err error
m.Namespace, err = decodeNamespace(top[k])
errs = append(errs, err)
case "reads":
var err error
m.Reads, err = decodeReads(top[k])
errs = append(errs, err)
default:
errs = append(errs, fmt.Errorf("unknown key %q; a manifest holds index and reads", k))
errs = append(errs, fmt.Errorf("unknown key %q; a manifest holds index, namespace and reads", k))
}
}
for _, p := range sortedKeys(m.Index) {
if m.Namespace != "" && !strings.HasPrefix(p, m.Namespace+".") {
errs = append(errs, fmt.Errorf("index entry %q lies outside the namespace %q", p, m.Namespace))
}
}
return m, errors.Join(errs...)
}
func decodeNamespace(v any) (string, error) {
namespace, isString := v.(string)
if !isString {
return "", fmt.Errorf("namespace must be a string, not %s", jsonvalue.Kind(v))
}
if namespace == "" {
return "", nil
}
if err := checkCategoryPath(namespace); err != nil {
return "", fmt.Errorf("namespace %w", err)
}
return namespace, nil
}
// decodeReads decodes the modules a source reads, each named by a non-empty string.
func decodeReads(v any) ([]string, error) {
items, isList := v.([]any)