Files
narratio/internal/artifacts/input_lookup.go
Eric Rakestraw 831665c913
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
Align module path with Narratio v4 release
2026-12-03 02:01:48 +00:00

40 lines
1.4 KiB
Go

package artifacts
import (
"path/filepath"
"strings"
"gitea.maximumdirect.net/eric/narratio/v4/internal/manifest"
)
type inputSourceKey struct{ kind, source string }
// InputLookup holds candidate records for one manifest input snapshot. Construct
// a new lookup whenever the manifest's inputs are replaced.
type InputLookup struct {
byKind map[string][]manifest.InputRecord
bySource map[inputSourceKey][]manifest.InputRecord
byPath map[string][]manifest.InputRecord
}
// NewInputLookup indexes candidates without validating their content or paths.
func NewInputLookup(paths SessionPaths, m *manifest.Manifest) *InputLookup {
lookup := &InputLookup{byKind: make(map[string][]manifest.InputRecord), bySource: make(map[inputSourceKey][]manifest.InputRecord), byPath: make(map[string][]manifest.InputRecord)}
if m == nil {
return lookup
}
root, rootErr := filepath.Abs(strings.TrimSpace(paths.Root))
for _, record := range m.Inputs {
kind := strings.TrimSpace(record.Kind)
lookup.byKind[kind] = append(lookup.byKind[kind], record)
key := inputSourceKey{record.Kind, record.Source}
lookup.bySource[key] = append(lookup.bySource[key], record)
if rootErr == nil && strings.TrimSpace(paths.Root) != "" {
if resolved, err := resolvePreparedManifestPath(paths, record.Path, filepath.Clean(root)); err == nil {
lookup.byPath[resolved] = append(lookup.byPath[resolved], record)
}
}
}
return lookup
}