Skip to main content

KeepsakeRepository

Type Alias KeepsakeRepository 

Source
pub type KeepsakeRepository<C = NoopRelationCache> = PostgresKeepsakeRepository<C>;
Expand description

Default Postgres-backed keepsake repository.

Aliased Type§

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

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

pub async fn audit_events_for_keepsake( &self, keepsake_id: Uuid, after: Option<&AuditCursor>, limit: i64, ) -> RepositoryResult<Vec<AuditEventRecord>>

Reads audit events for a keepsake in stable (occurred_at, id) order.

Source

pub async fn audit_events_for_relation( &self, relation_id: RelationId, after: Option<&AuditCursor>, limit: i64, ) -> RepositoryResult<Vec<AuditEventRecord>>

Reads audit events for a relation in stable (occurred_at, id) order.

Source

pub async fn audit_outbox( &self, after: Option<&AuditOutboxCursor>, limit: i64, ) -> RepositoryResult<Vec<AuditOutboxRecord>>

Exports undelivered audit outbox rows in stable id order.

Source

pub async fn claim_audit_outbox( &self, worker_id: &str, now: DateTime<Utc>, lease_until: DateTime<Utc>, limit: i64, ) -> RepositoryResult<Vec<AuditOutboxRecord>>

Claims a stable batch of undelivered audit outbox rows until lease_until.

Source

pub async fn ack_audit_outbox( &self, outbox_id: i64, delivered_at: DateTime<Utc>, ) -> RepositoryResult<bool>

Acknowledges delivery of a claimed outbox row.

Source

pub async fn release_audit_outbox( &self, outbox_id: i64, ) -> RepositoryResult<bool>

Releases a claimed outbox row for another worker to retry.

Source§

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

Source

pub async fn fulfillment_snapshot( &self, keepsake_id: Uuid, ) -> RepositoryResult<FulfillmentSnapshot>

Reads the persisted fulfillment snapshot (counters and checklist) for a keepsake.

Source

pub async fn due_fulfilled_expiry( &self, limit: i64, ) -> RepositoryResult<Vec<FulfilledExpiryCandidate>>

Lists fulfillment expiry candidates in stable batch order.

Source

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

Expires a stable batch whose persisted fulfillment snapshots satisfy policy.

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

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

Atomically adds delta to a fulfillment counter and returns the new value.

Unlike upsert_counter_projection, the increment is computed in the database, so concurrent writers cannot lose updates to a read-modify-write race.

Source

pub async fn upsert_checklist_projection( &self, keepsake_id: Uuid, item: &str, complete: bool, observed_at: DateTime<Utc>, ) -> RepositoryResult<()>

Upserts a checklist item completion projection.

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§

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

pub async fn revoke_by_subject( &self, command: &RevokeBySubject, ) -> RepositoryResult<Option<KeepsakeId>>

Revokes the active keepsake for a subject and relation pair.

Returns the revoked keepsake id, or None when no active keepsake exists for the pair. The active uniqueness invariant guarantees at most one match.

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_ids( &self, subject: &SubjectRef, relation_ids: &[RelationId], ) -> RepositoryResult<Vec<ActiveRelation>>

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

This is the bounded variant of Self::active_relations_for_subject for request paths that use typed relation specs or another stable relation-id catalogue. Missing ids are ignored, duplicate requested ids do not duplicate output rows, and disabled relation definitions are still returned when their keepsake is active.

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.

Trait Implementations§

Source§

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

Source§

type Error = RepositoryError

Source-specific error type.
Source§

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

Finds active relation memberships for a subject.
Source§

async fn active_relations_for_subject_by_ids<'a>( &'a self, subject: &'a SubjectRef, relation_ids: &'a [RelationId], ) -> RepositoryResult<Vec<ActiveRelation>>

Finds active relation memberships for a subject, filtered by relation ids.
Source§

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

Finds active relation memberships for a subject, filtered by relation keys.