reactive_graph_client/client/runtime/remotes/
api.rs1use std::sync::Arc;
2
3use crate::ReactiveGraphClient;
4use crate::ReactiveGraphClientExecutionError;
5use crate::client::runtime::remotes::mutations::add_remote::mutations::add;
6use crate::client::runtime::remotes::mutations::fetch_remotes_from_all_remotes::mutations::fetch_remotes_from_all_remotes;
7use crate::client::runtime::remotes::mutations::fetch_remotes_from_remote::mutations::fetch_remotes_from_remote;
8use crate::client::runtime::remotes::mutations::remove_all_remotes::mutations::remove_all;
9use crate::client::runtime::remotes::mutations::remove_remote::mutations::remove;
10use crate::client::runtime::remotes::mutations::update_all_remotes::mutations::update_all;
11use crate::client::runtime::remotes::mutations::update_remote::mutations::update;
12use crate::client::runtime::remotes::queries::get_all::queries::get_all;
13use crate::schema_runtime::InstanceInfos;
14use reactive_graph_remotes_model::InstanceAddress;
15use reactive_graph_remotes_model::InstanceInfo;
16
17pub struct Remotes {
18 client: Arc<ReactiveGraphClient>,
19}
20
21impl Remotes {
22 pub fn new(client: Arc<ReactiveGraphClient>) -> Self {
23 Self { client }
24 }
25
26 pub async fn get_all(&self) -> Result<Vec<InstanceInfo>, ReactiveGraphClientExecutionError> {
27 self.client.execute_runtime(get_all(), |data| InstanceInfos(data.remotes).into()).await
28 }
29
30 pub async fn add(&self, address: &InstanceAddress) -> Result<InstanceInfo, ReactiveGraphClientExecutionError> {
31 self.client.execute_runtime(add(address.into()), |data| data.remotes.add.into()).await
32 }
33
34 pub async fn remove(&self, address: &InstanceAddress) -> Result<bool, ReactiveGraphClientExecutionError> {
35 self.client.execute_runtime(remove(address.into()), |data| data.remotes.remove).await
36 }
37
38 pub async fn remove_all(&self) -> Result<bool, ReactiveGraphClientExecutionError> {
39 self.client.execute_runtime(remove_all(), |data| data.remotes.remove_all).await
40 }
41
42 pub async fn update(&self, address: &InstanceAddress) -> Result<InstanceInfo, ReactiveGraphClientExecutionError> {
43 self.client.execute_runtime(update(address.into()), |data| data.remotes.update.into()).await
44 }
45
46 pub async fn update_all(&self) -> Result<Vec<InstanceInfo>, ReactiveGraphClientExecutionError> {
47 self.client
48 .execute_runtime(update_all(), |data| InstanceInfos(data.remotes.update_all).into())
49 .await
50 }
51
52 pub async fn fetch_remotes_from_remote(&self, address: &InstanceAddress) -> Result<Vec<InstanceInfo>, ReactiveGraphClientExecutionError> {
53 self.client
54 .execute_runtime(fetch_remotes_from_remote(address.into()), |data| InstanceInfos(data.remotes.fetch_remotes_from_remote).into())
55 .await
56 }
57
58 pub async fn fetch_remotes_from_all_remotes(&self) -> Result<Vec<InstanceInfo>, ReactiveGraphClientExecutionError> {
59 self.client
60 .execute_runtime(fetch_remotes_from_all_remotes(), |data| InstanceInfos(data.remotes.fetch_remotes_from_all_remotes).into())
61 .await
62 }
63}