orchestra_toolkit/session/api/avial/
registries.rs

1/* Copyright 2024-2025 LEDR Technologies Inc.
2* This file is part of the Orchestra library, which helps developer use our Orchestra technology which is based on AvesTerra, owned and developped by Georgetown University, under license agreement with LEDR Technologies Inc.
3*
4* The Orchestra library is a free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
5*
6* The Orchestra library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
7*
8* You should have received a copy of the GNU Lesser General Public License along with the Orchestra library. If not, see <https://www.gnu.org/licenses/>.
9*
10* If you have any questions, feedback or issues about the Orchestra library, you can contact us at support@ledr.io.
11*/
12
13use std::{
14    future::{Future, IntoFuture},
15    pin::Pin,
16};
17
18use crate::{
19    constants::outlet, taxonomy::*, CallError, Entity, Session, SessionAsync, SessionTrait,
20    String255, Token, Value,
21};
22
23use crate::session::api::macros::*;
24
25decl_call!(
26    CreateRegistry(name: String255, authorization: Token) -> Entity,
27    {
28        key: String255,
29        mode: Mode,
30        outlet: Entity,
31        server: Entity,
32    }
33);
34impl<T: SessionTrait> CreateRegistry<T> {
35    async fn call_async(self) -> Result<Entity, CallError> {
36        let res = self
37            .session
38            .get_async_session()
39            .invoke_entity(outlet::REGISTRIES, Method::Create, self.authorization)
40            .with_name(self.name)
41            .with_key(self.key)
42            .with_mode(self.mode)
43            .with_ancillary(self.server)
44            .await?;
45        Ok(res.entity()?)
46    }
47}
48
49decl_call!(
50    DeleteRegistry(registry: Entity, authorization: Token) -> (),
51    {
52    }
53);
54impl<T: SessionTrait> DeleteRegistry<T> {
55    async fn call_async(self) -> Result<(), CallError> {
56        self.session
57            .get_async_session()
58            .invoke_entity(outlet::REGISTRIES, Method::Delete, self.authorization)
59            .with_ancillary(self.registry)
60            .await?;
61        Ok(())
62    }
63}
64
65decl_call!(
66    RegisterEntity(registry: Entity, key: String255, name: String255, entity: Entity, authorization: Token) -> (),
67    {
68        deferred: bool,
69    }
70);
71impl<T: SessionTrait> RegisterEntity<T> {
72    async fn call_async(self) -> Result<(), CallError> {
73        self.session
74            .get_async_session()
75            .include_property(
76                self.registry,
77                self.key,
78                self.name,
79                Value::Entity(self.entity),
80                self.authorization,
81            )
82            .with_deferred(self.deferred)
83            .await
84    }
85}
86
87decl_call!(
88    DeregisterEntity(registry: Entity, key: String255, authorization: Token) -> (),
89    {
90    }
91);
92impl<T: SessionTrait> DeregisterEntity<T> {
93    async fn call_async(self) -> Result<(), CallError> {
94        self.session
95            .get_async_session()
96            .exclude_property(self.registry, self.key, self.authorization)
97            .await
98    }
99}
100
101decl_call!(
102    PurgeRegistry(registry: Entity, authorization: Token) -> (),
103    {
104    }
105);
106impl<T: SessionTrait> PurgeRegistry<T> {
107    async fn call_async(self) -> Result<(), CallError> {
108        self.session
109            .get_async_session()
110            .purge_properties(self.registry, self.authorization)
111            .await
112    }
113}
114
115decl_call!(
116    SortRegistry(registry: Entity, authorization: Token) -> (),
117    {
118    }
119);
120impl<T: SessionTrait> SortRegistry<T> {
121    async fn call_async(self) -> Result<(), CallError> {
122        self.session
123            .get_async_session()
124            .sort_properties(self.registry, self.authorization)
125            .await
126    }
127}
128
129decl_call!(
130    LookupRegistry(registry: Entity, key: String255, authorization: Token) -> Entity,
131    {
132    }
133);
134impl<T: SessionTrait> LookupRegistry<T> {
135    async fn call_async(self) -> Result<Entity, CallError> {
136        let res = self
137            .session
138            .get_async_session()
139            .property_value(self.registry, self.key, self.authorization)
140            .await?;
141        Ok(res.entity()?)
142    }
143}
144
145decl_call!(
146    RegistryMember(registry: Entity, key: String255, authorization: Token) -> Option<Entity>,
147    {
148    }
149);
150impl<T: SessionTrait> RegistryMember<T> {
151    async fn call_async(self) -> Result<Option<Entity>, CallError> {
152        let s = self.session.get_async_session();
153
154        if s.property_member(self.registry, self.key.clone(), self.authorization)
155            .await?
156        {
157            Ok(Some(
158                s.lookup_registry(self.registry, self.key, self.authorization)
159                    .await?,
160            ))
161        } else {
162            Ok(None)
163        }
164    }
165}
166
167decl_call!(
168    RegistryItem(registry: Entity, index: i64, authorization: Token) -> Entity,
169    {
170    }
171);
172impl<T: SessionTrait> RegistryItem<T> {
173    async fn call_async(self) -> Result<Entity, CallError> {
174        let res = self
175            .session
176            .get_async_session()
177            .property_value(self.registry, String255::NULL, self.authorization)
178            .with_index(self.index)
179            .await?;
180        Ok(res.entity()?)
181    }
182}
183
184decl_call!(
185    RegistryCount(registry: Entity, authorization: Token) -> i64,
186    {
187    }
188);
189impl<T: SessionTrait> RegistryCount<T> {
190    async fn call_async(self) -> Result<i64, CallError> {
191        self.session
192            .get_async_session()
193            .property_count(self.registry, self.authorization)
194            .await
195    }
196}
197
198decl_call!(
199    RetrieveRegistry(registry: Entity, authorization: Token) -> String,
200    {
201    }
202);
203impl<T: SessionTrait> RetrieveRegistry<T> {
204    async fn call_async(self) -> Result<String, CallError> {
205        let res = self
206            .session
207            .get_async_session()
208            .invoke_entity(self.registry, Method::Retrieve, self.authorization)
209            .with_aspect(Aspect::Property)
210            .await?;
211        Ok(res.interchange()?)
212        // TODO: return Vec<Property> ?
213    }
214}