Documentation
¶
Overview ¶
Package rolo holds the Directory's domain types: the Person and Household records, the Tree derived from their Parent links, and the normalisation and validation rules applied to them.
Nothing here persists anything. Loading and saving live in internal/store, so these types can be reasoned about without a filesystem. See CONTEXT.md for the vocabulary and docs/adr/ for the decisions behind the shape.
Index ¶
- Constants
- Variables
- func NormalizeEmail(s string) string
- func NormalizePhone(s string) (string, bool)
- type Address
- type Date
- type DeleteBlock
- type Finding
- type HiddenFields
- type Household
- func (h Household) AddressHidden() bool
- func (h Household) EldestAdultBirth() Date
- func (h Household) HasLivingMember() bool
- func (h Household) IsMemorial() bool
- func (h Household) Label() string
- func (h Household) Name() string
- func (h *Household) Normalize()
- func (h Household) SharesAddress() bool
- type HouseholdID
- type Match
- type Person
- type PersonID
- type Severity
- type Tree
- func (t *Tree) Children(id HouseholdID) []Household
- func (t *Tree) DeleteBlock(id HouseholdID) (DeleteBlock, error)
- func (t *Tree) Get(id HouseholdID) (Household, bool)
- func (t *Tree) Path(id HouseholdID) ([]Household, error)
- func (t *Tree) PathString(id HouseholdID) (string, error)
- func (t *Tree) Roots() []Household
- func (t *Tree) SearchPeople(query string) []Match
- func (t *Tree) Walk(fn func(h Household, depth int) error) error
Constants ¶
const PathSeparator = " › "
PathSeparator joins Household labels in a rendered Path.
Variables ¶
var ( // ErrUnknownParent means a Household names a parent that is not in the document. ErrUnknownParent = errors.New("unknown parent household") // ErrDuplicateID means an ID appears twice in the document — either two // Households sharing a HouseholdID, or a PersonID appearing in more than // one place. IDs are identities, so a collision makes the document // ambiguous about who is who. ErrDuplicateID = errors.New("duplicate id") // ErrCycle means the parent links form a loop, so a Household is its own ancestor. ErrCycle = errors.New("cycle in household parentage") // ErrNoAdults means a Household has no adults, which cannot be labelled or rendered. ErrNoAdults = errors.New("household has no adults") // ErrUnknownHousehold means a lookup named a Household that is not in the tree. ErrUnknownHousehold = errors.New("unknown household") )
Functions ¶
func NormalizeEmail ¶
NormalizeEmail trims an address and lowercases its domain.
Domains are case-insensitive, so Example.COM and example.com are the same host and the Directory should render one of them. Local parts are case-sensitive in principle, so Pat.Novak is left exactly as the Editor typed it.
This function does not judge whether the value is a valid address — that is Validate's job, and an address it cannot parse is still returned trimmed rather than discarded.
func NormalizePhone ¶
NormalizePhone rewrites a North American phone number into the Directory's house style, 555-201-0001, and reports whether it recognised the input.
Anything it does not recognise — an international number, an extension, two numbers in one field, a note like "call the house" — is returned trimmed but otherwise exactly as typed, with recognized false. Discarding a relative's real phone number to enforce a format would be worse than an inconsistent directory, so normalisation never destroys input.
The empty string returns ("", true): there is nothing to normalise, and most people in the Directory have no phone on file. That is not a failure.
Types ¶
type Address ¶
type Address struct {
Lines []string `json:"lines,omitempty"`
// Hidden withholds the Address from every export, the way HiddenFields
// withholds a Person's contact details. It lives on Address rather than on
// HiddenFields because an Address belongs to the Household, not to either
// adult: §4.4's "my address stays out, my name is fine" is a statement
// about the household's address, and duplicating the flag per adult would
// let the two disagree.
Hidden bool `json:"hidden,omitempty"`
}
Address is a Household's mailing address, either as its own lines or as a reference to another Household's address.
A Shared Address is a reference rather than a copy so that it stays correct when the referenced Household moves, and so the Directory can render a back-reference instead of repeating the same lines.
type Date ¶
Date is a calendar date of partial precision. A Date may be fully specified (1938-03-12), know only a year and month (1938-03), know only a year (1938), or be unknown entirely (the zero Date).
Partial precision is a domain requirement, not a convenience: the export tiers truncate a living person's date to month and day, and many ancestors are recorded with only a year. encoding/json forces the receiver split: UnmarshalJSON must take a pointer to write through, while MarshalJSON stays on the value so it is also used for non-addressable Dates. Every other method is a query on a 3-int value type.
func ParseDate ¶
ParseDate reads a date in YYYY, YYYY-MM, or YYYY-MM-DD form. The empty string yields the zero Date, which represents an unknown date rather than an error.
func (Date) MarshalJSON ¶
MarshalJSON renders the date as a string, so the stored document stays readable and hand-editable.
func (Date) String ¶
String renders the date at whatever precision it holds. The zero Date renders as the empty string.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON parses a date string.
type DeleteBlock ¶
DeleteBlock says why a Household may not be deleted; the zero value means it may. Only a Household nothing depends on can go to the Trash (CONTEXT.md, Trash): a Memorial Household anchors its Branch permanently (§3), a Household with Households beneath it anchors their Paths, and one whose Address is shared would leave the sharer pointing at nothing.
func (DeleteBlock) Blocked ¶
func (b DeleteBlock) Blocked() bool
Blocked reports whether anything prevents the deletion.
type Finding ¶
type Finding struct {
Household HouseholdID
Person PersonID
Field string
Message string
Severity Severity
}
Finding is one observation about the Directory's contents, carrying enough location for the UI to show it beside the field it concerns.
Person is empty when the finding is about the Household itself, such as an Anniversary.
func ValidateHouseholds ¶
ValidateHouseholds inspects every Household and reports what looks wrong. It changes nothing and rejects nothing.
It stays silent about data that is merely absent. Most people in the Directory have no email, and a missing birth date is a fact with an export consequence rather than an error — export surfaces that, so nagging about it during editing would train the Editor to ignore findings.
Findings arrive in document order so the UI can show them against the tree without sorting.
type HiddenFields ¶
type HiddenFields struct {
Phone bool `json:"phone,omitempty"`
Email bool `json:"email,omitempty"`
Birth bool `json:"birth,omitempty"`
}
HiddenFields records which of a Person's fields the Editor has withheld from every export. A withheld field renders as "[private]" so that withheld data is distinguishable from data that was never collected.
type Household ¶
type Household struct {
ID HouseholdID `json:"id"`
Parent HouseholdID `json:"parent,omitempty"`
Adults []Person `json:"adults"`
Dependents []Person `json:"dependents,omitempty"`
Anniversary Date `json:"anniversary"`
// omitzero for the same reason as Person.Hidden: Address is a struct, and
// omitempty does not suppress an empty one.
Address Address `json:"address,omitzero"`
}
Household is the unit that renders as one block in the Directory. A node becomes a Household when it has a spouse, has Dependents, or has its own Address.
Parent is empty for a root Household. Children are not stored: they are derived by grouping on Parent when the Tree is built, so moving a Household is a one-field edit that cannot leave two records disagreeing. The queries below are value-semantic and only Normalize mutates, so only Normalize takes a pointer. Callers must normalise through an index — doc.Households[i].Normalize() — because a range copy would be discarded.
func (Household) AddressHidden ¶
AddressHidden reports whether the Editor has withheld this Household's Address. It is a method rather than a bare field read so templates and the tier filter (item 8) ask the same question in the same words.
func (Household) EldestAdultBirth ¶
EldestAdultBirth returns the earliest known birth date among the adults, or the zero Date when none is known. Sibling Households are ordered by this, which matches how families list their children.
func (Household) HasLivingMember ¶
HasLivingMember reports whether anyone in the Household is living, including Dependents. Proof Sheets are produced only for Households where this holds.
func (Household) IsMemorial ¶
IsMemorial reports whether every adult in the Household is deceased. A Memorial Household persists permanently — it anchors the Path of every Branch beneath it — and carries no contact details, because it has no living adult to own them.
A Household with no adults is not memorial; it is malformed, and the store rejects it at load.
func (Household) Label ¶
Label is the compact Path segment: the adults' given names joined by a slash, as in "Dave/Diane". A Path chains these, so they must stay short. Wherever a Household stands alone — the Directory, the editor's tree and detail heading — use Name.
func (Household) Name ¶
Name is the Household Name: how the Household is named wherever it stands alone — heading its block in the Directory, and naming it in the editor's tree and detail pane (CONTEXT.md, Household Name). Label is the compact form a Path chains.
Adults sharing a surname print it once, last, each carrying a different birth name in parentheses: "Daryl & Dawn (Mitchell) Yoder". Adults whose surnames differ are each named in full, without birth names, because a birth name only reads as "née" beside a surname taken in marriage. A single adult is their own name. A nickname is never part of it.
An adult with an empty Given is skipped in the shared-surname form, so a cleared Given never leaves a dangling " & " or a bare "(Mitchell)". A Household with no adults has no name; BuildTree rejects one anyway.
func (*Household) Normalize ¶
func (h *Household) Normalize()
Normalize rewrites the Household and everyone in it into house style in place. Structure — the ID, the Parent link, a Shared Address reference — is never touched: normalisation is about presentation, not about who belongs where.
func (Household) SharesAddress ¶
SharesAddress reports whether this Household's address is a reference to another Household's.
type HouseholdID ¶
type HouseholdID string
HouseholdID is the stable identity of a Household. It survives restructuring of the tree, unlike the Path, which is a display identity.
type Match ¶
type Match struct {
Person Person
Household HouseholdID
Path string
}
Match is one Person found by a search, carrying the Household they belong to and that Household's Path.
§4.3 makes search a shortcut *through* the tree rather than an alternative to it, so a Match always names a destination in the tree. The Path is what makes five people called Dave distinguishable in a result list, so it is part of the Match rather than something the caller is trusted to look up.
type Person ¶
type Person struct {
ID PersonID `json:"id"`
Given string `json:"given"`
Surname string `json:"surname"`
BirthName string `json:"birth_name,omitempty"`
Aka string `json:"aka,omitempty"`
Birth Date `json:"birth"`
Death Date `json:"death"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
// omitzero, not omitempty: encoding/json's omitempty has no effect on a
// struct field, so omitempty would write "hidden": {} for every Person and
// clutter a document the Operator repairs by hand. omitzero (Go 1.24+)
// omits the field when the struct is its zero value.
Hidden HiddenFields `json:"hidden,omitzero"`
}
Person is a single human being in the Directory. Every Person belongs to exactly one Household, either as one of its adults or as one of its Dependents. The queries below are value-semantic and only Normalize mutates, so only Normalize takes a pointer. Household.Normalize therefore iterates by index rather than by range copy, which would discard the result.
func (Person) DisplayName ¶
DisplayName renders the Person's name, with any nickname double-quoted between the given name and the surname.
func (Person) IsDeceased ¶
IsDeceased reports whether a death date has been recorded. Death is a property of a Person, never of a Household.
func (Person) IsMinor ¶
IsMinor reports whether the Person is under 18 at asOf.
The reference time is a parameter rather than time.Now so that the caller sees the time dependency: age gating means the same Directory exported months apart differs as people turn 18.
A Person with no recorded birth date is treated as a minor. This fails closed — it suppresses contact details for elderly relatives whose birth year nobody knows, which export surfaces as a warning rather than hiding.
type PersonID ¶
type PersonID string
PersonID is the stable identity of a Person. It never changes and is never shown to the Editor; the human-readable identity of someone in the Directory is their Household's Path.
type Severity ¶
type Severity int
Severity says how much attention a Finding deserves. Neither level blocks anything: validation is an observation, never a rejection.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is the navigation structure derived from Households' parent links. It is never stored: it is rebuilt whenever the document is loaded, so the parent links are the single source of truth and no stored child list can drift.
func BuildTree ¶
BuildTree derives the navigation tree from a flat slice of Households, validating that the parent links form a forest.
Sibling order is derived from each Household's eldest adult's birth date, which is how families list their children. Households whose eldest adult has no birth date sort last, by label.
func (*Tree) Children ¶
func (t *Tree) Children(id HouseholdID) []Household
Children returns a Household's children, in sibling order.
func (*Tree) DeleteBlock ¶
func (t *Tree) DeleteBlock(id HouseholdID) (DeleteBlock, error)
DeleteBlock reports what, if anything, prevents deleting id. Sharers are in Walk order, so a sentence naming them reads in the same order as the tree.
func (*Tree) Get ¶
func (t *Tree) Get(id HouseholdID) (Household, bool)
Get returns a Household by ID.
func (*Tree) Path ¶
func (t *Tree) Path(id HouseholdID) ([]Household, error)
Path returns the chain of Households from the root down to id, inclusive.
func (*Tree) PathString ¶
func (t *Tree) PathString(id HouseholdID) (string, error)
PathString renders a Household's Path as "Aden/Nettie › Clyde/Doris › Dave/Diane". This is the human-readable identity of a Household, and is what disambiguates relatives who share a given name.
func (*Tree) SearchPeople ¶
SearchPeople returns every Person whose name contains query, case-insensitively.
At a few hundred people a linear scan is instant, so there is no index to keep in sync with the document — which matters because item 5 makes the document mutable and a stale index would silently return people who have been renamed.
Results are ordered by the depth-first tree walk, so people group by Branch. That is what makes the Path column readable: two Daves under different grandparents appear apart, with their differing Paths adjacent to their identical names.