engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 12 Imported by: 0 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 engine contains the subscription status core.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(
	verdicts []domain.SourceVerdict,
	banned bool,
) (domain.EffectiveStatus, domain.AccessDecision)

Aggregate merges source verdicts into an effective access decision.

Types

type AlertStore

type AlertStore interface {
	Create(ctx context.Context, a store.AlertInput) (int64, error)
}

AlertStore is the operational alert surface needed by revocation.

type AuditStore

type AuditStore interface {
	Append(ctx context.Context, e store.AuditEntry) error
}

AuditStore is the audit repository surface needed by the engine.

type Effect

type Effect struct {
	TGID      int64
	Text      string
	ParseMode string
	Plain     bool
}

Effect is a post-commit side effect prepared by the engine.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine applies subscription events and computes access status.

func New

func New(sources []SubscriptionSource, opts ...Option) *Engine

New returns a status engine.

func (*Engine) ApplyObservations

func (e *Engine) ApplyObservations(
	ctx context.Context,
	repos Store,
	tgID int64,
	verdicts []domain.SourceVerdict,
) error

ApplyObservations persists live source observations inside handleTx.

func (*Engine) HandleEvent

func (e *Engine) HandleEvent(
	ctx context.Context,
	repos Store,
	event domain.SubscriptionEvent,
) ([]Effect, error)

HandleEvent applies one normalized subscription event inside handleTx.

func (*Engine) LiveSnapshot

func (e *Engine) LiveSnapshot(
	ctx context.Context,
	repos Store,
	tgID int64,
) (Snapshot, error)

LiveSnapshot collects source verdicts outside handleTx and aggregates them.

func (*Engine) PersistedDecision

func (e *Engine) PersistedDecision(
	ctx context.Context,
	repos Store,
	tgID int64,
) (domain.AccessDecision, error)

PersistedDecision computes access from local state without network probes.

func (*Engine) RecomputeAccess

func (e *Engine) RecomputeAccess(
	ctx context.Context,
	repos Store,
	tgID int64,
) ([]Effect, error)

RecomputeAccess re-evaluates durable local access state after callers have persisted fresh observations.

func (*Engine) RevokeNow

func (e *Engine) RevokeNow(
	ctx context.Context,
	repos Store,
	tgID int64,
	reason string,
) ([]Effect, error)

RevokeNow safely revokes current bot-admitted grants for a user.

type GrantStore

type GrantStore interface {
	ListEligibleForRevoke(ctx context.Context, tgID int64) ([]domain.AccessGrant, error)
	Revoke(ctx context.Context, tgID int64, resource domain.Resource, reason string) (bool, error)
}

GrantStore is the access grant surface needed by revocation.

type KeyedMutex

type KeyedMutex struct {
	// contains filtered or unexported fields
}

KeyedMutex serializes work by Telegram user ID.

func NewKeyedMutex

func NewKeyedMutex() *KeyedMutex

NewKeyedMutex returns an empty process-wide keyed mutex.

func (*KeyedMutex) Lock

func (m *KeyedMutex) Lock(key int64) func()

Lock locks one key and returns an unlock function.

type MemberChecker

type MemberChecker interface {
	GetChatMember(
		ctx context.Context,
		resource domain.Resource,
		tgID int64,
	) (*models.ChatMember, error)
}

MemberChecker reads live Telegram membership for protection checks.

type Option

type Option func(*Engine)

Option configures Engine.

func WithClock

func WithClock(now func() time.Time) Option

WithClock replaces time.Now for tests.

func WithRevocationConfig

func WithRevocationConfig(cfg RevocationConfig) Option

WithRevocationConfig sets expiry-mode behavior for recomputeAccess.

type OutboxStore

type OutboxStore interface {
	Enqueue(
		ctx context.Context,
		input store.AccessActionInput,
	) (domain.AccessAction, bool, error)
}

OutboxStore is the durable Telegram action surface needed by revocation.

type RevocationConfig

type RevocationConfig struct {
	ExpiryMode  string
	GracePeriod time.Duration
}

RevocationConfig controls expiry behavior.

type RevocationStore

type RevocationStore interface {
	CreateIfAbsent(ctx context.Context, p domain.PendingRevocation) (bool, error)
	Get(ctx context.Context, tgID int64) (domain.PendingRevocation, bool, error)
	Delete(ctx context.Context, tgID int64) error
	MarkNotified(ctx context.Context, tgID int64) error
}

RevocationStore is the pending-revocation surface needed by the engine.

type Snapshot

type Snapshot struct {
	TGID     int64
	Verdicts []domain.SourceVerdict
	Decision domain.AccessDecision
}

Snapshot is a live, pre-transaction status snapshot.

type Store

type Store struct {
	Users         UserStore
	Subscriptions SubscriptionStore
	Audit         AuditStore
	Revocations   RevocationStore
	Whitelist     WhitelistStore
	Grants        GrantStore
	Outbox        OutboxStore
	Alerts        AlertStore
	Members       MemberChecker

	// OperatorLog, when set, receives durable operator events emitted in the
	// caller's transaction. It is optional: a nil writer disables the feed.
	OperatorLog *operatorlog.Writer
}

Store is the narrow repository bundle used by engine operations.

type SubscriptionSource

type SubscriptionSource interface {
	Platform() domain.Platform
	Verdict(ctx context.Context, tgID int64) (domain.SourceVerdict, error)
}

SubscriptionSource is the consumer-side source interface.

type SubscriptionStore

type SubscriptionStore interface {
	UpsertActive(ctx context.Context, s domain.Subscription) (int64, error)
	ExpireActive(
		ctx context.Context,
		tgID int64,
		platform domain.Platform,
		endedAt time.Time,
		signal string,
	) (bool, error)
	GetActive(
		ctx context.Context,
		tgID int64,
		platform domain.Platform,
	) (domain.Subscription, bool, error)
	ListActiveByUser(ctx context.Context, tgID int64) ([]domain.Subscription, error)
}

SubscriptionStore is the subscription repository surface needed by the engine.

type UserStore

type UserStore interface {
	Upsert(ctx context.Context, u domain.User) error
	Get(ctx context.Context, tgID int64) (domain.User, error)
}

UserStore is the user repository surface needed by the engine.

type WhitelistStore

type WhitelistStore interface {
	Has(ctx context.Context, tgID int64) (bool, error)
}

WhitelistStore is the whitelist repository surface needed by the engine.

Jump to

Keyboard shortcuts

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