reactive_graph_reactive_service_api/
reactive_entity_manager.rs1use std::collections::HashMap;
2
3use async_trait::async_trait;
4use serde_json::Value;
5use springtime_di::injectable;
6use uuid::Uuid;
7
8use crate::ReactiveEntityComponentAddError;
9use crate::ReactiveEntityCreationError;
10use crate::ReactiveEntityPropertyAddError;
11use crate::ReactiveEntityPropertyRemoveError;
12use crate::ReactiveEntityRegistrationError;
13use reactive_graph_behaviour_model_api::BehaviourTypeId;
14use reactive_graph_behaviour_model_api::ComponentBehaviourTypeId;
15use reactive_graph_behaviour_model_api::EntityBehaviourTypeId;
16use reactive_graph_graph::ComponentTypeId;
17use reactive_graph_graph::EntityInstance;
18use reactive_graph_graph::EntityTypeId;
19use reactive_graph_graph::Mutability;
20use reactive_graph_graph::Namespace;
21use reactive_graph_graph::PropertyInstances;
22use reactive_graph_lifecycle::Lifecycle;
23use reactive_graph_reactive_model_impl::ReactiveEntity;
24
25#[injectable]
26#[async_trait]
27pub trait ReactiveEntityManager: Send + Sync + Lifecycle {
28 fn has(&self, id: Uuid) -> bool;
30
31 fn get(&self, id: Uuid) -> Option<ReactiveEntity>;
33
34 fn get_by_label(&self, label: &str) -> Option<ReactiveEntity>;
36
37 fn get_by_label_with_params(&self, label: &str) -> Option<(ReactiveEntity, HashMap<String, String>)>;
41
42 fn get_all(&self) -> Vec<ReactiveEntity>;
44
45 fn get_by_type(&self, ty: &EntityTypeId) -> Vec<ReactiveEntity>;
47
48 fn get_by_component(&self, component_ty: &ComponentTypeId) -> Vec<ReactiveEntity>;
50
51 fn get_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> Vec<ReactiveEntity>;
53
54 fn get_by_namespace(&self, namespace: &Namespace) -> Vec<ReactiveEntity>;
56
57 fn get_ids(&self) -> Vec<Uuid>;
59
60 fn count(&self) -> usize;
62
63 fn count_by_type(&self, ty: &EntityTypeId) -> usize;
65
66 fn count_by_component(&self, component_ty: &ComponentTypeId) -> usize;
68
69 fn count_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> usize;
71
72 fn create_reactive_entity(&self, ty: &EntityTypeId, properties: PropertyInstances) -> Result<ReactiveEntity, ReactiveEntityCreationError>;
75
76 fn create_with_id(&self, ty: &EntityTypeId, id: Uuid, properties: PropertyInstances) -> Result<ReactiveEntity, ReactiveEntityCreationError>;
79
80 fn create_reactive_instance(&self, entity_instance: EntityInstance) -> Result<ReactiveEntity, ReactiveEntityCreationError>;
83
84 fn register_reactive_instance(&self, reactive_entity: ReactiveEntity) -> Result<ReactiveEntity, ReactiveEntityRegistrationError>;
86
87 fn register_or_merge_reactive_instance(&self, reactive_entity: ReactiveEntity) -> Result<ReactiveEntity, ReactiveEntityRegistrationError>;
91
92 fn add_component(&self, id: Uuid, component_ty: &ComponentTypeId) -> Result<(), ReactiveEntityComponentAddError>;
94
95 fn remove_component(&self, id: Uuid, component_ty: &ComponentTypeId);
97
98 fn add_property(&self, id: Uuid, property_name: &str, mutability: Mutability, value: Value) -> Result<(), ReactiveEntityPropertyAddError>;
100
101 fn remove_property(&self, id: Uuid, property_name: &str) -> Result<(), ReactiveEntityPropertyRemoveError>;
103
104 fn add_behaviour_to_all_entity_instances(&self, entity_behaviour_ty: &EntityBehaviourTypeId);
106
107 fn add_behaviour_to_all_entity_components(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
109
110 fn delete(&self, id: Uuid) -> bool;
111
112 fn unregister_reactive_instance(&self, id: Uuid) -> bool;
118
119 fn handle_component_added_events(&self);
134
135 fn handle_component_removed_events(&self);
136
137 fn handle_property_added_events(&self);
138
139 fn handle_property_removed_events(&self);
140}