AuditDao

Data Access Object for audit trail operations.

Provides CRUD operations for audit events and chain state management.

Functions

Link copied to clipboard
abstract suspend fun countEvents(): Long

Count total events.

Link copied to clipboard
abstract suspend fun countEventsInRange(fromTs: Long, toTs: Long): Long

Count events in a time range.

Link copied to clipboard
abstract suspend fun deleteAllEvents()

Delete all events.

Link copied to clipboard
abstract suspend fun deleteEventsByUserId(userId: String): Int

Delete all events for a specific user.

Link copied to clipboard
abstract suspend fun deleteEventsThroughSeq(seq: Long): Int

Delete every event with seq at or below seq.

Link copied to clipboard
open suspend fun eraseRowsWithRecord(userId: String, build: suspend (List<AuditEventEntity>) -> Pair<AuditEventEntity, AuditChainState>): Int

Atomic erase: delete every row of userId, then insert the row and chain state that build returns for the removed rows. Any exception rolls the whole erase back.

Link copied to clipboard
abstract suspend fun getAllEvents(): List<AuditEventEntity>

Get all events ordered by timestamp.

Link copied to clipboard
abstract suspend fun getChainState(): AuditChainState?

Get chain state.

Link copied to clipboard
abstract suspend fun getEventById(id: String): AuditEventEntity?

Get an event by ID.

Link copied to clipboard
abstract suspend fun getEventNameCounts(): List<EventNameCount>

Get distinct event names with counts.

Link copied to clipboard
abstract suspend fun getEventsByName(name: String): List<AuditEventEntity>

Get events by name.

Link copied to clipboard
abstract suspend fun getEventsByUserId(userId: String): List<AuditEventEntity>

Get all events for a specific user.

Link copied to clipboard
abstract suspend fun getEventsInRange(fromTs: Long, toTs: Long): List<AuditEventEntity>

Get events in a time range, ordered by timestamp.

Link copied to clipboard
abstract suspend fun getEventsPageBySeq(afterSeq: Long, limit: Int): List<AuditEventEntity>

Get a page of events after a sequence number, in chain order.

Link copied to clipboard
abstract suspend fun getHeadEvent(): AuditEventEntity?

The newest event in chain order.

Link copied to clipboard
abstract suspend fun getLatestEvent(): AuditEventEntity?

Get the most recent event.

Link copied to clipboard
abstract suspend fun getOldestEvent(): AuditEventEntity?

Get the oldest event.

Link copied to clipboard
abstract suspend fun getPruneBoundary(beforeTs: Long): AuditEventEntity?

The highest-seq event older than beforeTs such that every event at or below its seq is also older than beforeTs: the end of the prunable chain prefix. Null if none.

Link copied to clipboard
abstract suspend fun getSeqBoundsInRange(fromTs: Long, toTs: Long): SeqBounds

Lowest and highest seq among events whose ts is within the range; both null if none.

Link copied to clipboard
abstract suspend fun insertEvent(event: AuditEventEntity)

Insert a new audit event.

Link copied to clipboard

Atomic insert of event and chain state update.

Link copied to clipboard
open suspend fun pruneThrough(state: AuditChainState)

Atomic prune: record the prune point in state, then delete through state.prunedThroughSeq.

Link copied to clipboard
abstract suspend fun upsertChainState(state: AuditChainState)

Insert or update chain state.