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