storage

package
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storage defines persistent models and repository contracts.

Index

Constants

View Source
const (
	MaxPrincipalRoles = 64
	MaxRoleNameLength = 64
)
View Source
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
)
View Source
const MaxAdminMaintenanceBatch = 1000

Variables

View Source
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

func CanonicalJSON(raw []byte, object bool, maxDepth int) ([]byte, error)

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 IsOperationErrorCode(code string) bool

func NormalizePrincipalRoles added in v2.0.1

func NormalizePrincipalRoles(roles []string) ([]string, error)

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

type AdminLoginGrantBurner interface {
	Burn(context.Context, string, []byte) error
}

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 AdminLoginGrantRepository interface {
	Create(context.Context, *AdminLoginGrant) error
	Consume(context.Context, string, []byte, time.Time) (*AdminLoginGrant, error)
}

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 AdminSession struct {
	ID                  string
	TokenHash           []byte
	Audience            string
	PrincipalID         string
	AuthRevision        uint64
	IssuedAt, ExpiresAt time.Time
	RevokedAt           *time.Time
}

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 AdminSessionRepository interface {
	Create(context.Context, *AdminSession) error
	FindActive(context.Context, string, []byte, time.Time) (*AdminSession, error)
	Revoke(context.Context, string) error
}

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 ControlTicketRepository interface {
	Create(context.Context, *ControlTicket) error
	Consume(context.Context, string, []byte, time.Time) (*ControlTicket, error)
}

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 OperationProgress struct {
	Sequence       uint64
	Current, Total uint64
	Message        string
}

type OperationProgressUpdate added in v2.0.1

type OperationProgressUpdate struct {
	Current, Total uint64
	Message        string
}

type OperationRecord added in v2.0.1

type OperationRecord struct {
	ExecutionID, PrincipalID, OperationID string
	Version                               uint
	KeyHash, InputHash, Result            []byte
	State                                 OperationState
	ErrorCode, ErrorMessage               string
	ErrorRetryable                        bool
	CreatedAt, ExpiresAt                  time.Time
	CompletedAt                           *time.Time
	Progress                              *OperationProgress
}

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

type PlatformIdentity struct {
	Platform       string
	PlatformUserID string
	DisplayName    string
}

PlatformIdentity identifies one account at a platform adapter boundary.

type Principal added in v2.0.1

type Principal struct {
	ID          string
	DisplayName string
	CreatedAt   time.Time
}

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL