···11+package syntax
22+33+import (
44+ "errors"
55+ "fmt"
66+ "strings"
77+)
88+99+// Parses an atproto repo path string in to "collection" (NSID) and record key parts.
1010+//
1111+// Does not return partial success: either both collection and record key are complete (and error is nil), or both are empty string (and error is not nil)
1212+func ParseRepoPath(raw string) (NSID, RecordKey, error) {
1313+ parts := strings.SplitN(raw, "/", 3)
1414+ if len(parts) != 2 {
1515+ return "", "", errors.New("expected path to have two parts, separated by single slash")
1616+ }
1717+ nsid, err := ParseNSID(parts[0])
1818+ if err != nil {
1919+ return "", "", fmt.Errorf("collection part of path not a valid NSID: %w", err)
2020+ }
2121+ rkey, err := ParseRecordKey(parts[1])
2222+ if err != nil {
2323+ return "", "", fmt.Errorf("record key part of path not valid: %w", err)
2424+ }
2525+ return nsid, rkey, nil
2626+}