atuin_client/record/
store.rs

1use async_trait::async_trait;
2use eyre::Result;
3
4use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx, RecordStatus};
5
6/// A record store stores records
7/// In more detail - we tend to need to process this into _another_ format to actually query it.
8/// As is, the record store is intended as the source of truth for arbitrary data, which could
9/// be shell history, kvs, etc.
10#[async_trait]
11pub trait Store {
12    // Push a record
13    async fn push(&self, record: &Record<EncryptedData>) -> Result<()> {
14        self.push_batch(std::iter::once(record)).await
15    }
16
17    // Push a batch of records, all in one transaction
18    async fn push_batch(
19        &self,
20        records: impl Iterator<Item = &Record<EncryptedData>> + Send + Sync,
21    ) -> Result<()>;
22
23    async fn get(&self, id: RecordId) -> Result<Record<EncryptedData>>;
24
25    async fn delete(&self, id: RecordId) -> Result<()>;
26    async fn delete_all(&self) -> Result<()>;
27
28    async fn len_all(&self) -> Result<u64>;
29    async fn len(&self, host: HostId, tag: &str) -> Result<u64>;
30    async fn len_tag(&self, tag: &str) -> Result<u64>;
31
32    async fn last(&self, host: HostId, tag: &str) -> Result<Option<Record<EncryptedData>>>;
33    async fn first(&self, host: HostId, tag: &str) -> Result<Option<Record<EncryptedData>>>;
34
35    async fn re_encrypt(&self, old_key: &[u8; 32], new_key: &[u8; 32]) -> Result<()>;
36    async fn verify(&self, key: &[u8; 32]) -> Result<()>;
37    async fn purge(&self, key: &[u8; 32]) -> Result<()>;
38
39    /// Get the next `limit` records, after and including the given index
40    async fn next(
41        &self,
42        host: HostId,
43        tag: &str,
44        idx: RecordIdx,
45        limit: u64,
46    ) -> Result<Vec<Record<EncryptedData>>>;
47
48    /// Get the first record for a given host and tag
49    async fn idx(
50        &self,
51        host: HostId,
52        tag: &str,
53        idx: RecordIdx,
54    ) -> Result<Option<Record<EncryptedData>>>;
55
56    async fn status(&self) -> Result<RecordStatus>;
57
58    /// Get all records for a given tag
59    async fn all_tagged(&self, tag: &str) -> Result<Vec<Record<EncryptedData>>>;
60}