reactive_graph_reactive_service_api/
reactive_relation_manager.rs

1use async_trait::async_trait;
2use serde_json::Value;
3use springtime_di::injectable;
4use uuid::Uuid;
5
6use crate::ReactiveRelationComponentRemoveError;
7use reactive_graph_graph::ComponentTypeId;
8use reactive_graph_graph::Mutability;
9use reactive_graph_graph::PropertyInstances;
10use reactive_graph_graph::RelationInstance;
11use reactive_graph_graph::RelationInstanceId;
12use reactive_graph_graph::RelationTypeId;
13use reactive_graph_reactive_model_impl::ReactiveRelation;
14
15use crate::ReactiveRelationComponentAddError;
16use crate::ReactiveRelationCreationError;
17use crate::ReactiveRelationPropertyAddError;
18use crate::ReactiveRelationPropertyRemoveError;
19use crate::ReactiveRelationRegistrationError;
20use reactive_graph_behaviour_model_api::BehaviourTypeId;
21use reactive_graph_behaviour_model_api::ComponentBehaviourTypeId;
22use reactive_graph_behaviour_model_api::RelationBehaviourTypeId;
23use reactive_graph_lifecycle::Lifecycle;
24
25#[injectable]
26#[async_trait]
27pub trait ReactiveRelationManager: Send + Sync + Lifecycle {
28    /// Returns true, if an relation of the given type exists which starts at the given outbound entity and
29    /// ends at the given inbound entity.
30    fn has(&self, id: &RelationInstanceId) -> bool;
31
32    /// Returns the ReactiveRelation with the given type_name, which starts at the given
33    /// outbound entity and ends at the given inbound entity.
34    fn get(&self, id: &RelationInstanceId) -> Option<ReactiveRelation>;
35
36    /// Returns all reactive relation instances of the given outbound entity instance.
37    fn get_by_outbound_entity(&self, outbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
38
39    /// Returns all reactive relation instances of the given inbound entity instance.
40    fn get_by_inbound_entity(&self, inbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
41
42    /// Returns all reactive relation instances.
43    fn get_all(&self) -> Vec<ReactiveRelation>;
44
45    /// Returns all reactive relation instances of the given type.
46    fn get_by_type(&self, ty: &RelationTypeId) -> Vec<ReactiveRelation>;
47
48    /// Returns all reactive relation instances of the given type which are of the given component..
49    fn get_by_component(&self, component_ty: &ComponentTypeId) -> Vec<ReactiveRelation>;
50
51    /// Returns all reactive relation instances of the given type which behaves as the given behaviour.
52    fn get_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> Vec<ReactiveRelation>;
53
54    /// Returns all reactive relation instances of the given namespace.
55    fn get_by_namespace(&self, namespace: &str) -> Vec<ReactiveRelation>;
56
57    /// Returns all relation instance ids.
58    fn get_relation_instance_ids(&self) -> Vec<RelationInstanceId>;
59
60    /// Returns the count of registered reactive relation instances.
61    fn count(&self) -> usize;
62
63    /// Returns the count of registered reactive relation instances of the given type.
64    fn count_by_type(&self, ty: &RelationTypeId) -> usize;
65
66    /// Returns the count of registered reactive relation instances which are of the given component.
67    fn count_by_component(&self, component_ty: &ComponentTypeId) -> usize;
68
69    /// Returns the count of registered reactive relation instances which behaves as the given behaviour.
70    fn count_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> usize;
71
72    /// Creates a new reactive relation instance.
73    fn create_reactive_relation(&self, id: &RelationInstanceId, properties: PropertyInstances) -> Result<ReactiveRelation, ReactiveRelationCreationError>;
74
75    fn create_reactive_instance(&self, relation_instance: RelationInstance) -> Result<ReactiveRelation, ReactiveRelationCreationError>;
76
77    /// Registers the given reactive relation instance and applies components and behaviours.
78    fn register_reactive_instance(&self, relation_instance: ReactiveRelation) -> Result<ReactiveRelation, ReactiveRelationRegistrationError>;
79
80    fn register_or_merge_reactive_instance(&self, relation_instance: ReactiveRelation) -> Result<ReactiveRelation, ReactiveRelationRegistrationError>;
81
82    /// Adds the component with the given name to the relation instance with the given relation instance id.
83    fn add_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentAddError>;
84
85    /// Removes the component with the given name from the relation instance with the given relation instance id.
86    fn remove_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentRemoveError>;
87
88    /// Adds the property with the given name and initial value to the relation instance with the given id.
89    fn add_property(&self, id: &RelationInstanceId, property_name: &str, mutability: Mutability, value: Value) -> Result<(), ReactiveRelationPropertyAddError>;
90
91    /// Removes the property with the given name from the relation instance with the given id.
92    fn remove_property(&self, id: &RelationInstanceId, property_name: &str) -> Result<(), ReactiveRelationPropertyRemoveError>;
93
94    /// Adds the given behaviour to all instances of the given relation type.
95    fn add_behaviour_to_all_relation_instances(&self, relation_behaviour_ty: &RelationBehaviourTypeId);
96
97    /// Adds the given behaviour to all instances of the given relation type.
98    fn add_behaviour_to_all_relation_components(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
99
100    // // TODO: fn commit(&self, relation_instance: RelationInstance);
101    // // TODO: return result
102    // fn commit(&self, id: &RelationInstanceId);
103
104    /// Deletes the reactive relation instance with the given key.
105    fn delete(&self, id: &RelationInstanceId) -> bool;
106
107    fn unregister_reactive_instance(&self, id: &RelationInstanceId);
108
109    fn handle_component_added_events(&self);
110
111    fn handle_component_removed_events(&self);
112
113    fn handle_property_added_events(&self);
114
115    fn handle_property_removed_events(&self);
116}