Add semantic paths and safe diagnostics

This commit is contained in:
2026-09-06 19:19:24 +00:00
parent 8e3cc40c78
commit 14b10cb6a5
11 changed files with 936 additions and 45 deletions

45
metadata.go Normal file
View File

@@ -0,0 +1,45 @@
package configkit
// Metadata provides detached presence, origin, and history queries for a load.
// Its zero value contains no paths.
type Metadata struct {
fields map[string]FieldInfo
history map[string][]Change
}
// Lookup returns information for an effective path. Unknown and invalid paths
// return false.
func (m Metadata) Lookup(path Path) (FieldInfo, bool) {
if !path.valid() {
return FieldInfo{}, false
}
info, ok := m.fields[path.String()]
if !ok {
return FieldInfo{}, false
}
return cloneFieldInfo(info), true
}
// IsExplicit reports whether a surviving input contribution explicitly defined
// path.
func (m Metadata) IsExplicit(path Path) bool {
info, ok := m.Lookup(path)
return ok && info.Explicit
}
// History returns detached definition and resolution records for path. Unknown and
// invalid paths return nil.
func (m Metadata) History(path Path) []Change {
if !path.valid() {
return nil
}
history, ok := m.history[path.String()]
if !ok {
return nil
}
cloned := make([]Change, len(history))
for i, change := range history {
cloned[i] = cloneChange(change)
}
return cloned
}