Documentation
¶
Overview ¶
Package storage defines the public storage-backend contract: backend capabilities and metadata, install/device/user/tenant scopes with their enforcement policies, and the configuration shape hosts use to construct a backend.
Stability: Stable — no breaking change without a minor version bump and a changelog callout.
Index ¶
Constants ¶
const LocalInstallID = "local"
LocalInstallID is the install identifier NormalizeScope assigns to a scope with no install, device, user, or tenant: the no-config local default, keyed "install:local".
Variables ¶
var ( // ErrScopeUserRequired reports a scope without a UserID under // [ScopeUserRequired]. ErrScopeUserRequired = errors.New("speechkit storage: user scope is required") // ErrScopeTenantRequired reports a scope without a TenantID under // [ScopeTenantRequired]. ErrScopeTenantRequired = errors.New("speechkit storage: tenant scope is required") )
Errors returned by ScopePolicy.Validate.
Functions ¶
func NormalizeBackendName ¶
NormalizeBackendName canonicalizes a backend name with NormalizeIdentifier so registrations and lookups agree.
func NormalizeIdentifier ¶
NormalizeIdentifier trims value and lowercases it; storage identifiers such as backend names are compared in this form.
func WithScope ¶
WithScope returns a child of ctx carrying the normalized scope; a nil ctx starts from context.Background. Stores read it back with ScopeFromContext.
Types ¶
type BackendInfo ¶
type BackendInfo struct {
Name string `json:"name"`
DisplayName string `json:"displayName,omitempty"`
ScopePolicy ScopePolicy `json:"scopePolicy"`
Capabilities Capabilities `json:"capabilities"`
}
BackendInfo describes a registered backend: the Name it registers under, an optional DisplayName for settings surfaces, the ScopePolicy it enforces, and its Capabilities.
type Capabilities ¶
type Capabilities struct {
Scopes bool `json:"scopes"`
AudioAssets bool `json:"audioAssets"`
FullText bool `json:"fullText"`
Embeddings bool `json:"embeddings"`
VectorSearch bool `json:"vectorSearch"`
}
Capabilities advertises the optional features a backend implements so hosts can adapt: per-scope isolation, audio asset storage, full-text search, stored embeddings, and vector similarity search.
type Config ¶
type Config struct {
Backend string
DefaultScope Scope
ScopePolicy ScopePolicy
Options map[string]string
}
Config is what a host passes to a Factory: the registered Backend name, the DefaultScope used when a context carries none, the ScopePolicy the backend must enforce, and free-form backend-specific Options such as a path or DSN.
type Registry ¶
type Registry[T any] struct { // contains filtered or unexported fields }
Registry maps normalized backend names to factories for one backend type T. The zero value is ready to use; registration is not safe for concurrent use.
func NewRegistry ¶
NewRegistry returns an empty Registry for backend type T.
type Scope ¶
type Scope struct {
InstallID string `json:"installId,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
UserID string `json:"userId,omitempty"`
TenantID string `json:"tenantId,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
Scope identifies who owns a stored record: the installation, device, user, and tenant, plus free-form Labels (for example workspace or session) that partition data further. Every field is optional; the empty Scope is the local default.
func NormalizeScope ¶
NormalizeScope trims every identifier and label, drops labels with a blank key or value, and sets InstallID to LocalInstallID when no install, device, user, or tenant is given.
func ScopeFromContext ¶
ScopeFromContext returns the normalized scope stored by WithScope, or the normalized local default when ctx is nil or carries none.
type ScopePolicy ¶
type ScopePolicy string
ScopePolicy states which scope identity a backend requires before it stores or reads user data. The zero value behaves like ScopeOptional.
const ( // ScopeOptional accepts any scope, including the local default. ScopeOptional ScopePolicy = "optional" // ScopeUserRequired rejects scopes without a UserID. ScopeUserRequired ScopePolicy = "user-required" // ScopeTenantRequired rejects scopes without a TenantID. ScopeTenantRequired ScopePolicy = "tenant-required" )
Scope policies a backend can declare.
func (ScopePolicy) Validate ¶
func (p ScopePolicy) Validate(scope Scope) error
Validate normalizes scope and returns ErrScopeUserRequired or ErrScopeTenantRequired when the identity the policy requires is missing. Unknown policies, including the zero value, accept every scope.