reactive_graph_plugin_api/instances/entities/
entity_instance_manager.rs

1use std::collections::HashMap;
2
3use uuid::Uuid;
4
5use reactive_graph_behaviour_model_api::BehaviourTypeId;
6use reactive_graph_graph::ComponentTypeId;
7use reactive_graph_graph::EntityInstance;
8use reactive_graph_graph::EntityTypeId;
9use reactive_graph_reactive_model_impl::ReactiveEntity;
10use reactive_graph_reactive_service_api::ReactiveEntityComponentAddError;
11use reactive_graph_reactive_service_api::ReactiveEntityCreationError;
12use reactive_graph_reactive_service_api::ReactiveEntityRegistrationError;
13
14pub trait EntityInstanceManager: Send + Sync {
15    /// Returns true, if an entity instance exists with the given UUID.
16    fn has(&self, id: Uuid) -> bool;
17
18    /// Returns the reactive entity instance with the given UUID or None.
19    fn get(&self, id: Uuid) -> Option<ReactiveEntity>;
20
21    /// Returns the reactive entity instance with the given label or None.
22    fn get_by_label(&self, label: &str) -> Option<ReactiveEntity>;
23
24    /// Returns the reactive entity instance and the matched path parameters that matches the given label or None.
25    /// /io/reactive-graph/local/users/:user_id
26    /// /io/reactive-graph/local/users/PeterPenacka returns: (instance, {"user_id": "PeterPenacka"})
27    fn get_by_label_with_params(&self, label: &str) -> Option<(ReactiveEntity, HashMap<String, String>)>;
28
29    /// Returns all reactive entity instances.
30    fn get_all(&self) -> Vec<ReactiveEntity>;
31
32    /// Returns all reactive entity instances of the given type.
33    fn get_by_type(&self, ty: &EntityTypeId) -> Vec<ReactiveEntity>;
34
35    /// Returns all ids.
36    fn get_ids(&self) -> Vec<Uuid>;
37
38    /// Returns the count of registered reactive entity instances.
39    fn count(&self) -> usize;
40
41    /// Returns the count of registered reactive entity instances of the given type.
42    fn count_by_type(&self, ty: &EntityTypeId) -> usize;
43
44    /// Returns the count of registered reactive entity instances which are of the given component.
45    fn count_by_component(&self, component: &ComponentTypeId) -> usize;
46
47    /// Returns the count of registered reactive entity instances which behaves as the given behaviour.
48    fn count_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> usize;
49
50    /// Creates a new reactive entity instance.
51    fn create(&self, entity_instance: EntityInstance) -> Result<ReactiveEntity, ReactiveEntityCreationError>;
52
53    /// Registers a reactive entity instance and applies components and behaviours.
54    fn register(&self, reactive_entity: ReactiveEntity) -> Result<ReactiveEntity, ReactiveEntityRegistrationError>;
55
56    /// Adds the component with the given name to the entity instance with the given id.
57    fn add_component(&self, id: Uuid, component: &ComponentTypeId) -> Result<(), ReactiveEntityComponentAddError>;
58
59    /// Removes the component with the given name from the entity instance with the given id.
60    fn remove_component(&self, id: Uuid, component: &ComponentTypeId);
61
62    /// Deletes the reactive entity instance with the given id.
63    fn delete(&self, id: Uuid) -> bool;
64}