Documentation
¶
Overview ¶
Package storage defines persistent models and repository contracts.
Index ¶
- Constants
- Variables
- func CanonicalJSON(raw []byte, object bool, maxDepth int) ([]byte, error)
- func ChatKinds() []string
- func IsOperationErrorCode(code string) bool
- func NormalizePrincipalRoles(roles []string) ([]string, error)
- func ValidateOperationClaim(r *OperationRecord, now time.Time) error
- func ValidateOperationCompletion(state OperationState, result []byte, code, message string, retryable bool) error
- func ValidateOperationProgress(progress OperationProgress) error
- func ValidateOperationProgressUpdate(progress OperationProgressUpdate) error
- type AdminAuthRepository
- type AdminAuthStoreProvider
- type AdminLoginGrant
- type AdminLoginGrantBurner
- type AdminLoginGrantRepository
- type AdminMaintenance
- type AdminMaintenanceCounts
- type AdminMaintenanceProvider
- type AdminSession
- type AdminSessionByIDFinder
- type AdminSessionRepository
- type AdminSessionTransitionRevoker
- type Chat
- type ChatFilterOptionRepository
- type ChatFilterOptions
- type ChatRepository
- type ControlTicket
- type ControlTicketRepository
- type ControlTicketStoreProvider
- type IdentityRepository
- type IdentityStore
- type IdentityStoreProvider
- type OperationClaim
- type OperationProgress
- type OperationProgressUpdate
- type OperationRecord
- type OperationRepository
- type OperationState
- type OperationStoreProvider
- type PlatformIdentity
- type Principal
- type PrincipalRepository
- type SessionLockRepository
- type SessionRepository
- type Store
- type User
- type UserFilterOptionRepository
- type UserFilterOptions
- type UserRepository
Constants ¶
const ( MaxPrincipalRoles = 64 MaxRoleNameLength = 64 )
const ( OperationRunning OperationState = "running" OperationSucceeded OperationState = "succeeded" OperationFailed OperationState = "failed" OperationClaimFresh OperationClaim = iota + 1 OperationClaimReplay OperationClaimConflict OperationTTL = 24 * time.Hour MaxOperationResultBytes = 64 << 10 MaxOperationErrorCodeBytes = 64 MaxOperationErrorMessageBytes = 512 MaxOperationProgressReports = 1024 MaxOperationProgressMessageBytes = 256 MaxOperationProgressValue uint64 = 1<<53 - 1 )
const MaxAdminMaintenanceBatch = 1000
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested storage entity does not exist.
Functions ¶
func CanonicalJSON ¶ added in v2.0.1
CanonicalJSON validates UTF-8 JSON, rejects duplicate keys and excessive nesting, and returns deterministic encoding. The wire budget is enforced by the caller because input and output have different limits.
func ChatKinds ¶ added in v2.0.1
func ChatKinds() []string
ChatKinds returns the finite set understood by the built-in chat filter.
func IsOperationErrorCode ¶ added in v2.0.1
func NormalizePrincipalRoles ¶ added in v2.0.1
NormalizePrincipalRoles validates and canonicalizes persisted role assignments.
func ValidateOperationClaim ¶ added in v2.0.1
func ValidateOperationClaim(r *OperationRecord, now time.Time) error
func ValidateOperationCompletion ¶ added in v2.0.1
func ValidateOperationCompletion(state OperationState, result []byte, code, message string, retryable bool) error
func ValidateOperationProgress ¶ added in v2.0.1
func ValidateOperationProgress(progress OperationProgress) error
func ValidateOperationProgressUpdate ¶ added in v2.0.1
func ValidateOperationProgressUpdate(progress OperationProgressUpdate) error
Types ¶
type AdminAuthRepository ¶ added in v2.0.1
type AdminAuthRepository interface {
LoginGrants() AdminLoginGrantRepository
AdminSessions() AdminSessionRepository
}
type AdminAuthStoreProvider ¶ added in v2.0.1
type AdminAuthStoreProvider interface{ AdminAuth() AdminAuthRepository }
AdminAuthStoreProvider is optional and keeps the legacy Store contract intact.
type AdminLoginGrant ¶ added in v2.0.1
type AdminLoginGrant struct {
ID string
TokenHash []byte
Audience string
PrincipalID string
OriginPlatform string
OriginPlatformUserID string
IssuedAuthRevision uint64
CreatedAt, ExpiresAt time.Time
}
AdminLoginGrant is a short-lived, one-time credential. TokenHash contains only the domain-separated hash of the opaque credential.
type AdminLoginGrantBurner ¶ added in v2.0.1
AdminLoginGrantBurner is an optional capability required by flows that may need to invalidate an issued but undelivered grant.
type AdminLoginGrantRepository ¶ added in v2.0.1
type AdminMaintenance ¶ added in v2.0.1
type AdminMaintenance interface {
CleanupAdmin(context.Context, time.Time, int) (AdminMaintenanceCounts, error)
}
AdminMaintenance is an optional storage capability. Limit applies independently to each record kind so one kind cannot starve the others.
type AdminMaintenanceCounts ¶ added in v2.0.1
type AdminMaintenanceCounts struct {
LoginGrants int
AdminSessions int
ControlTickets int
Operations int
}
AdminMaintenanceCounts reports physical records removed by one bounded run.
type AdminMaintenanceProvider ¶ added in v2.0.1
type AdminMaintenanceProvider interface{ AdminMaintenance() AdminMaintenance }
type AdminSession ¶ added in v2.0.1
type AdminSessionByIDFinder ¶ added in v2.0.1
type AdminSessionByIDFinder interface {
FindActiveByID(context.Context, string, string, time.Time) (*AdminSession, error)
}
AdminSessionByIDFinder is an optional capability for server-side session revalidation without possessing its bearer credential.
type AdminSessionRepository ¶ added in v2.0.1
type AdminSessionTransitionRevoker ¶ added in v2.0.1
type AdminSessionTransitionRevoker interface {
RevokeIfActive(context.Context, string) (bool, error)
}
AdminSessionTransitionRevoker atomically reports whether an active session was transitioned to revoked. It supports idempotent caller-facing logout without changing the legacy AdminSessionRepository contract.
type Chat ¶
type Chat struct {
ID string
Platform string
ChatID string
Title string
Kind string
Metadata map[string]any
}
Chat is AstraEngine's platform-neutral system chat.
type ChatFilterOptionRepository ¶ added in v2.0.1
type ChatFilterOptionRepository interface {
FilterOptions(context.Context, int) (ChatFilterOptions, error)
}
ChatFilterOptionRepository supplies bounded distinct values without listing chats.
type ChatFilterOptions ¶ added in v2.0.1
type ChatFilterOptions struct{ Platforms, Kinds []string }
type ChatRepository ¶
type ChatRepository interface {
FindByPlatformID(ctx context.Context, platform, chatID string) (*Chat, error)
List(ctx context.Context) ([]Chat, error)
Save(ctx context.Context, chat *Chat) error
}
ChatRepository persists and queries system chats.
type ControlTicket ¶ added in v2.0.1
type ControlTicket struct {
ID string
TokenHash []byte
Audience string
PrincipalID string
SessionID string
AuthRevision uint64
CreatedAt time.Time
ExpiresAt time.Time
}
ControlTicket is a short-lived, one-time credential bound to an Admin session. TokenHash contains only the domain-separated hash of the opaque credential.
type ControlTicketRepository ¶ added in v2.0.1
type ControlTicketStoreProvider ¶ added in v2.0.1
type ControlTicketStoreProvider interface {
ControlTickets() ControlTicketRepository
}
ControlTicketStoreProvider is optional and does not widen Store or AdminAuthRepository.
type IdentityRepository ¶ added in v2.0.1
type IdentityRepository interface {
IdentityStore
PrincipalRepository
}
IdentityRepository is the optional combined identity capability implemented by stores that keep both mappings and principals in one atomic repository.
type IdentityStore ¶ added in v2.0.1
type IdentityStore interface {
Resolve(ctx context.Context, identity PlatformIdentity) (*Principal, error)
}
IdentityStore atomically resolves platform accounts to Astra principals.
type IdentityStoreProvider ¶ added in v2.0.1
type IdentityStoreProvider interface {
Identities() IdentityRepository
}
IdentityStoreProvider lets callers discover identity support without adding it to the backwards-compatible Store interface.
type OperationClaim ¶ added in v2.0.1
type OperationClaim int
type OperationProgress ¶ added in v2.0.1
type OperationProgressUpdate ¶ added in v2.0.1
type OperationRecord ¶ added in v2.0.1
type OperationRepository ¶ added in v2.0.1
type OperationRepository interface {
Lookup(context.Context, string, string, uint, []byte, time.Time) (*OperationRecord, error)
Claim(context.Context, *OperationRecord, time.Time) (*OperationRecord, OperationClaim, error)
UpdateProgress(context.Context, string, string, uint, []byte, string, OperationProgressUpdate, time.Time) (*OperationRecord, error)
Complete(context.Context, string, string, uint, []byte, string, OperationState, []byte, string, string, bool, time.Time) (*OperationRecord, error)
}
type OperationState ¶ added in v2.0.1
type OperationState string
type OperationStoreProvider ¶ added in v2.0.1
type OperationStoreProvider interface{ Operations() OperationRepository }
type PlatformIdentity ¶ added in v2.0.1
PlatformIdentity identifies one account at a platform adapter boundary.
type Principal ¶ added in v2.0.1
Principal is an Astra-level identity independent of any bot platform.
type PrincipalRepository ¶ added in v2.0.1
type PrincipalRepository interface {
FindByID(ctx context.Context, id string) (*Principal, error)
Roles(ctx context.Context, id string) (roles []string, authRevision uint64, err error)
SetRoles(ctx context.Context, id string, roles []string) (authRevision uint64, err error)
}
PrincipalRepository stores principals and their direct role assignments. The returned revision changes only when the effective normalized role set changes.
type SessionLockRepository ¶ added in v2.0.2
type SessionLockRepository interface {
WithSessionLock(ctx context.Context, key string, fn func() error) error
}
SessionLockRepository optionally coordinates work across repository users.
type SessionRepository ¶
type SessionRepository interface {
Get(ctx context.Context, key string) ([]byte, error)
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Delete(ctx context.Context, key string) error
}
SessionRepository stores opaque expiring session values.
type Store ¶
type Store interface {
Users() UserRepository
Chats() ChatRepository
Sessions() SessionRepository
}
Store groups the standard repositories required by built-in modules.
type User ¶
type User struct {
ID string
Platform string
PlatformID string
Username string
Roles []string
Metadata map[string]any
}
User is AstraEngine's platform-neutral system user.
type UserFilterOptionRepository ¶ added in v2.0.1
type UserFilterOptionRepository interface {
FilterOptions(context.Context, int) (UserFilterOptions, error)
}
UserFilterOptionRepository supplies bounded distinct values without listing users.
type UserFilterOptions ¶ added in v2.0.1
type UserFilterOptions struct{ Platforms, Roles []string }
type UserRepository ¶
type UserRepository interface {
FindByPlatformID(ctx context.Context, platform, platformID string) (*User, error)
FindByID(ctx context.Context, id string) (*User, error)
List(ctx context.Context) ([]User, error)
Save(ctx context.Context, user *User) error
}
UserRepository persists and queries system users.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memory implements process-local AstraEngine repositories.
|
Package memory implements process-local AstraEngine repositories. |
|
Package postgres implements AstraEngine repositories using pgx and PostgreSQL.
|
Package postgres implements AstraEngine repositories using pgx and PostgreSQL. |