bitwarden_core/platform/
state_client.rs1use std::sync::Arc;
2
3use bitwarden_state::{
4 registry::{RepositoryNotFoundError, StateRegistryError},
5 repository::{Repository, RepositoryItem, RepositoryItemData},
6 DatabaseConfiguration,
7};
8
9use crate::Client;
10
11pub struct StateClient {
13 pub(crate) client: Client,
14}
15
16impl StateClient {
17 pub fn register_client_managed<T: 'static + Repository<V>, V: RepositoryItem>(
19 &self,
20 store: Arc<T>,
21 ) {
22 self.client
23 .internal
24 .repository_map
25 .register_client_managed(store)
26 }
27
28 pub fn get_client_managed<T: RepositoryItem>(
30 &self,
31 ) -> Result<Arc<dyn Repository<T>>, RepositoryNotFoundError> {
32 self.client.internal.repository_map.get_client_managed()
33 }
34
35 pub async fn initialize_database(
37 &self,
38 configuration: DatabaseConfiguration,
39 repositories: Vec<RepositoryItemData>,
40 ) -> Result<(), StateRegistryError> {
41 self.client
42 .internal
43 .repository_map
44 .initialize_database(configuration, repositories)
45 .await
46 }
47
48 pub fn get_sdk_managed<
50 T: RepositoryItem + serde::ser::Serialize + serde::de::DeserializeOwned,
51 >(
52 &self,
53 ) -> Result<impl Repository<T>, StateRegistryError> {
54 self.client.internal.repository_map.get_sdk_managed()
55 }
56}