44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Package notariusref owns Narratio's Notarius CLI reference-selector
|
|
// vocabulary without depending on Notarius implementation packages.
|
|
package notariusref
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// NormalizeSelector validates and normalizes a Notarius v0.6 reference
|
|
// selector. It intentionally validates selector structure only; Notarius owns
|
|
// target, slot, and media compatibility.
|
|
func NormalizeSelector(value string) (string, error) {
|
|
selector := strings.TrimSpace(value)
|
|
if selector == "" {
|
|
return "", fmt.Errorf("reference selector is required")
|
|
}
|
|
if strings.Contains(selector, "=") {
|
|
return "", fmt.Errorf("reference selector must not contain '='")
|
|
}
|
|
|
|
parts := strings.Split(selector, ".")
|
|
for index := range parts {
|
|
parts[index] = strings.TrimSpace(parts[index])
|
|
if parts[index] == "" {
|
|
return "", fmt.Errorf("reference selector components must not be empty")
|
|
}
|
|
}
|
|
|
|
switch len(parts) {
|
|
case 1, 2:
|
|
return strings.Join(parts, "."), nil
|
|
case 3:
|
|
switch parts[1] {
|
|
case "extract", "merge", "normalize":
|
|
return strings.Join(parts, "."), nil
|
|
default:
|
|
return "", fmt.Errorf("three-component reference selector must use extract, merge, or normalize as its middle component")
|
|
}
|
|
default:
|
|
return "", fmt.Errorf("reference selector must use slot, chunk.slot, lane.slot, or lane.stage.slot")
|
|
}
|
|
}
|