Documentation
¶
Overview ¶
Package settings holds the account-settings domain: the dashboard account's persisted UI preferences (theme and the Pipelines/Repos page filters). See openspec/changes/persist-account-settings/specs/account-settings/spec.md.
Index ¶
Constants ¶
const ( KeyTheme = "theme" KeyForgeFilter = "forgeFilter" KeyPipelinesHealthFilter = "pipelinesHealthFilter" KeyPipelinesRepoSelector = "pipelinesRepoSelector" KeyPipelinesSortOrder = "pipelinesSortOrder" KeyTelemetryWindow = "telemetryWindow" )
The setting keys, as stored in the JSON blob and used as PATCH request body keys -- see Store's doc comment for why a raw map keyed by these rather than a struct with pointer fields.
const ( DefaultTheme = "system" DefaultForgeFilter = "all" DefaultPipelinesHealthFilter = "unhealthy" DefaultPipelinesRepoSelector = "all" DefaultPipelinesSortOrder = "name" DefaultTelemetryWindow = "7d" )
The documented default for each setting, resolved server-side whenever a key has never been explicitly set for the account (account-settings/ spec.md's "Settings defaults"). PipelinesRepoSelector's default ("all") is a sentinel meaning "every tracked repo", not a real repo ID.
const MaxRepoSelectorLength = 128
MaxRepoSelectorLength bounds the one free-text setting, a repo id or "all", so a caller can't store an arbitrarily large value (the OpenAPI spec's SettingsUpdate.pipelinesRepoSelector maxLength).
Variables ¶
var ErrInvalidKey = errors.New("unrecognized setting key")
ErrInvalidKey is returned by Update for a key outside Keys.
var ErrInvalidValue = errors.New("invalid setting value")
ErrInvalidValue is returned by Update for a value outside its setting's documented set (account-settings/spec.md's "Invalid value is rejected").
var Keys = []string{ KeyTheme, KeyForgeFilter, KeyPipelinesHealthFilter, KeyPipelinesRepoSelector, KeyPipelinesSortOrder, KeyTelemetryWindow, }
Keys lists every known setting key, in a stable order -- for validating a PATCH request's keys and for the "reset Pipelines filters" convenience that clears exactly the Pipelines-prefixed ones.
var PipelinesFilterKeys = []string{ KeyPipelinesHealthFilter, KeyPipelinesRepoSelector, KeyPipelinesSortOrder, }
PipelinesFilterKeys are the three settings "reset filters" clears in one request -- account-settings/spec.md's "Reset Pipelines filters to defaults".
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service resolves stored overrides against documented defaults, and validates an update before it ever reaches Store.
func NewService ¶
NewService returns a Service backed by store.
func (*Service) Get ¶
Get returns userID's settings, every field resolved against its documented default.
func (*Service) ResetPipelinesFilters ¶
ResetPipelinesFilters clears the three Pipelines-page filter settings back to their defaults in one request, leaving every other setting (theme, forge filter) untouched -- account-settings/spec.md's "Reset Pipelines filters to defaults".
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, userID string, updates map[string]*string) (Settings, error)
Update validates every key/value in updates, then applies all of them in one Patch call if -- and only if -- every one is valid; an invalid key or value rejects the whole request, leaving every previously stored value unchanged (account-settings/spec.md's "Invalid value is rejected").
type Settings ¶
type Settings struct {
Theme string
ForgeFilter string
PipelinesHealthFilter string
PipelinesRepoSelector string
PipelinesSortOrder string
TelemetryWindow string
}
Settings is every setting, fully resolved: a stored override merged onto its documented default, so a field here is never ambiguous between "unset" and "empty".
type Store ¶
type Store interface {
// Get returns userID's stored overrides. A key absent from the result
// has never been set (or was cleared) and should fall back to its
// default. A user with no settings row yet returns an empty map, not
// an error.
Get(ctx context.Context, userID string) (map[string]string, error)
// Patch applies updates to userID's stored overrides: a nil value
// clears that key (reverting it to its default on the next Get), a
// non-nil value sets it. Returns the full resulting override map.
Patch(ctx context.Context, userID string, updates map[string]*string) (map[string]string, error)
}
Store is the port account settings are persisted through. It works in terms of the raw, possibly-partial override map (only explicitly-set keys present) rather than a resolved Settings struct, so it -- and the wire format -- have no opinion on defaults; Service owns default resolution.