Documentation
¶
Overview ¶
Package preferences stores scoped user preference records and exposes helpers to resolve effective settings using go-options.
Index ¶
- func ToPreferenceRecord(record *Record) types.PreferenceRecord
- type Record
- type Repository
- func (r *Repository) DeletePreference(ctx context.Context, userID uuid.UUID, scope types.ScopeFilter, ...) error
- func (r *Repository) ListPreferences(ctx context.Context, filter types.PreferenceFilter) ([]types.PreferenceRecord, error)
- func (r *Repository) UpsertPreference(ctx context.Context, record types.PreferenceRecord) (*types.PreferenceRecord, error)
- type RepositoryConfig
- type RepositoryOption
- func WithCache(enabled bool) RepositoryOption
- func WithCacheConfig(cfg cache.Config) RepositoryOption
- func WithCacheIdentifierFields(fields ...string) RepositoryOption
- func WithCacheKeySerializer(serializer cache.KeySerializer) RepositoryOption
- func WithCacheService(service cache.CacheService) RepositoryOption
- type RepositoryOptions
- type ResolveInput
- type Resolver
- type ResolverConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToPreferenceRecord ¶
func ToPreferenceRecord(record *Record) types.PreferenceRecord
ToPreferenceRecord converts the Bun model into the domain preference record.
Types ¶
type Record ¶
type Record struct {
bun.BaseModel `bun:"table:user_preferences"`
ID uuid.UUID `bun:"id,pk,type:uuid"`
UserID uuid.UUID `bun:"user_id,type:uuid"`
TenantID uuid.UUID `bun:"tenant_id,type:uuid"`
OrgID uuid.UUID `bun:"org_id,type:uuid"`
ScopeLevel string `bun:"scope_level"`
Key string `bun:"key"`
Value map[string]any `bun:"value,type:jsonb"`
Version int `bun:"version"`
CreatedAt time.Time `bun:"created_at"`
CreatedBy uuid.UUID `bun:"created_by,type:uuid"`
UpdatedAt time.Time `bun:"updated_at"`
UpdatedBy uuid.UUID `bun:"updated_by,type:uuid"`
}
Record models the user_preferences row.
func FromPreferenceRecord ¶
func FromPreferenceRecord(record types.PreferenceRecord) *Record
FromPreferenceRecord converts a domain preference record into the Bun model.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository implements types.PreferenceRepository.
func NewRepository ¶
func NewRepository(cfg RepositoryConfig, opts ...RepositoryOption) (*Repository, error)
NewRepository constructs the default preference repository.
func (*Repository) DeletePreference ¶
func (r *Repository) DeletePreference(ctx context.Context, userID uuid.UUID, scope types.ScopeFilter, level types.PreferenceLevel, key string) error
DeletePreference removes a scoped preference entry.
func (*Repository) ListPreferences ¶
func (r *Repository) ListPreferences(ctx context.Context, filter types.PreferenceFilter) ([]types.PreferenceRecord, error)
ListPreferences fetches preference records for the requested scope level.
func (*Repository) UpsertPreference ¶
func (r *Repository) UpsertPreference(ctx context.Context, record types.PreferenceRecord) (*types.PreferenceRecord, error)
UpsertPreference inserts or updates a scoped preference entry.
type RepositoryConfig ¶
type RepositoryConfig struct {
DB *bun.DB
Repository repository.Repository[*Record]
Clock types.Clock
IDGen types.IDGenerator
}
RepositoryConfig wires dependencies for the Bun-backed preference store.
type RepositoryOption ¶ added in v0.7.0
type RepositoryOption func(*RepositoryOptions)
RepositoryOption configures preference repository construction.
func WithCache ¶ added in v0.7.0
func WithCache(enabled bool) RepositoryOption
WithCache toggles the repository cache decorator.
func WithCacheConfig ¶ added in v0.7.0
func WithCacheConfig(cfg cache.Config) RepositoryOption
WithCacheConfig supplies the cache configuration to use when caching is enabled.
func WithCacheIdentifierFields ¶ added in v0.9.0
func WithCacheIdentifierFields(fields ...string) RepositoryOption
WithCacheIdentifierFields supplies identifier fields used for cache tags on GetByIdentifier.
func WithCacheKeySerializer ¶ added in v0.9.0
func WithCacheKeySerializer(serializer cache.KeySerializer) RepositoryOption
WithCacheKeySerializer supplies a custom key serializer for cache keys.
func WithCacheService ¶ added in v0.9.0
func WithCacheService(service cache.CacheService) RepositoryOption
WithCacheService supplies a preconfigured cache service to use when caching is enabled.
type RepositoryOptions ¶ added in v0.7.0
type RepositoryOptions struct {
CacheEnabled bool
CacheConfig *cache.Config
CacheService cache.CacheService
CacheKeySerializer cache.KeySerializer
CacheIdentifierFields []string
}
RepositoryOptions captures optional behavior for preference persistence.
type ResolveInput ¶
type ResolveInput struct {
UserID uuid.UUID
Scope types.ScopeFilter
Levels []types.PreferenceLevel
Keys []string
Base map[string]any
}
ResolveInput controls which scopes participate in the resolution process.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver merges scoped preference layers via go-options.
func NewResolver ¶
func NewResolver(cfg ResolverConfig) (*Resolver, error)
NewResolver constructs a preference resolver.
func (*Resolver) Resolve ¶
func (r *Resolver) Resolve(ctx context.Context, input ResolveInput) (types.PreferenceSnapshot, error)
Resolve builds the effective preference snapshot for the supplied scope chain.
type ResolverConfig ¶
type ResolverConfig struct {
Repository types.PreferenceRepository
Defaults map[string]any
}
ResolverConfig wires dependencies for the preference resolver.