Skip to main content

KeepsakeRepository

Struct KeepsakeRepository 

Source
pub struct KeepsakeRepository<C = NoopRelationCache> { /* private fields */ }
Expand description

SQLx-backed keepsake repository.

Implementations§

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub async fn append_audit_event( &self, event: &AuditEvent, ) -> RepositoryResult<i64>

Appends an explicit audit event without mutating lifecycle state.

Prefer apply and revoke for lifecycle mutations so state and audit rows commit together. This helper is for application-owned audit events that do not have a built-in repository command.

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub async fn due_timed_expiry( &self, now: DateTime<Utc>, limit: i64, ) -> RepositoryResult<Vec<TimedExpiryCandidate>>

Lists due timed expiry candidates in stable batch order.

Source

pub async fn expire_due_timed( &self, now: DateTime<Utc>, limit: i64, ) -> RepositoryResult<u64>

Expires a stable batch of due timed keepsakes.

Source

pub async fn upsert_counter_projection( &self, keepsake_id: Uuid, key: &str, value: i64, observed_at: DateTime<Utc>, ) -> RepositoryResult<()>

Upserts a simple fulfillment counter projection.

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub async fn apply( &self, command: &ApplyKeepsake, ) -> RepositoryResult<AppliedKeepsake>

Applies a command idempotently and records its audit event atomically.

If an active keepsake already exists for the subject and relation, the existing row is returned with duplicate_prevented set to true, even if the relation has since been disabled. Disabled relations reject new non-duplicate applies.

Source

pub async fn revoke(&self, command: &RevokeKeepsake) -> RepositoryResult<bool>

Revokes an active keepsake from a command and records its audit event atomically.

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub async fn active_for_subject( &self, subject: &SubjectRef, ) -> RepositoryResult<Vec<Keepsake>>

Returns active keepsakes for a subject.

Source

pub async fn active_relations_for_subject( &self, subject: &SubjectRef, ) -> RepositoryResult<Vec<ActiveRelation>>

Returns active keepsakes for a subject with their relation definitions.

Source

pub async fn active_relations_for_subject_by_keys( &self, subject: &SubjectRef, keys: &[RelationKey], ) -> RepositoryResult<Vec<ActiveRelation>>

Returns active keepsakes for a subject, filtered by relation keys.

This is the bounded variant of Self::active_relations_for_subject for request paths that know the small set of relation keys they care about. Missing keys are ignored, and disabled relation definitions are still returned when their keepsake is active.

Source

pub async fn active_membership_scan( &self, relation_id: RelationId, limit: i64, ) -> RepositoryResult<Vec<Keepsake>>

Scans active memberships for a relation in stable order.

Source

pub async fn active_membership_scan_after( &self, relation_id: RelationId, after: Option<&MembershipCursor>, limit: i64, ) -> RepositoryResult<Vec<Keepsake>>

Scans active memberships after a keyset cursor in stable order.

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub async fn upsert_relation( &self, relation: &RelationDefinition, at: DateTime<Utc>, ) -> RepositoryResult<RelationDefinition>

Inserts or updates a relation definition by its natural relation key.

If a relation already exists for the same kind/name, its stable id is preserved and the returned definition contains the existing id.

Source

pub async fn upsert_relation_spec<Spec>( &self, at: DateTime<Utc>, ) -> RepositoryResult<RelationDefinition>
where Spec: RelationSpec,

Inserts or updates a typed relation spec by its natural relation key.

Source

pub async fn relation_by_id( &self, relation_id: RelationId, ) -> RepositoryResult<Option<RelationDefinition>>

Looks up a relation definition by stable id.

Source

pub async fn relation_by_key( &self, key: &RelationKey, ) -> RepositoryResult<Option<RelationDefinition>>

Looks up a relation definition by its natural relation key.

Source

pub async fn set_relation_enabled( &self, relation_id: RelationId, enabled: bool, at: DateTime<Utc>, ) -> RepositoryResult<bool>

Enables or disables a relation.

Source§

impl KeepsakeRepository<NoopRelationCache>

Source

pub const fn new(pool: PgPool) -> Self

Creates a repository from a Postgres pool.

Source§

impl<C> KeepsakeRepository<C>
where C: RelationCache,

Source

pub const fn at(&self, at: DateTime<Utc>) -> TimedKeepsakeRepository<'_, C>

Creates a timestamp-scoped repository view.

Use this at request or job boundaries to keep one explicit clock read while avoiding repeated timestamp plumbing through related repository calls.

Source

pub fn with_relation_cache<Next>(self, cache: Next) -> KeepsakeRepository<Next>
where Next: RelationCache,

Enables relation definition caching for read helper methods.

Source

pub fn with_local_relation_cache( self, config: LocalRelationCacheConfig, ) -> KeepsakeRepository<LocalRelationCache>

Enables local in-process relation definition caching for read helper methods.

Source

pub async fn migrate(&self) -> RepositoryResult<()>

Runs embedded migrations.

Trait Implementations§

Source§

impl<C: Clone> Clone for KeepsakeRepository<C>

Source§

fn clone(&self) -> KeepsakeRepository<C>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug> Debug for KeepsakeRepository<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more