reactive_graph_reactive_service_api/
reactive_relation_manager.rs1use 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 fn has(&self, id: &RelationInstanceId) -> bool;
31
32 fn get(&self, id: &RelationInstanceId) -> Option<ReactiveRelation>;
35
36 fn get_by_outbound_entity(&self, outbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
38
39 fn get_by_inbound_entity(&self, inbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
41
42 fn get_all(&self) -> Vec<ReactiveRelation>;
44
45 fn get_by_type(&self, ty: &RelationTypeId) -> Vec<ReactiveRelation>;
47
48 fn get_by_component(&self, component_ty: &ComponentTypeId) -> Vec<ReactiveRelation>;
50
51 fn get_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> Vec<ReactiveRelation>;
53
54 fn get_by_namespace(&self, namespace: &str) -> Vec<ReactiveRelation>;
56
57 fn get_relation_instance_ids(&self) -> Vec<RelationInstanceId>;
59
60 fn count(&self) -> usize;
62
63 fn count_by_type(&self, ty: &RelationTypeId) -> 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_relation(&self, id: &RelationInstanceId, properties: PropertyInstances) -> Result<ReactiveRelation, ReactiveRelationCreationError>;
74
75 fn create_reactive_instance(&self, relation_instance: RelationInstance) -> Result<ReactiveRelation, ReactiveRelationCreationError>;
76
77 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 fn add_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentAddError>;
84
85 fn remove_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentRemoveError>;
87
88 fn add_property(&self, id: &RelationInstanceId, property_name: &str, mutability: Mutability, value: Value) -> Result<(), ReactiveRelationPropertyAddError>;
90
91 fn remove_property(&self, id: &RelationInstanceId, property_name: &str) -> Result<(), ReactiveRelationPropertyRemoveError>;
93
94 fn add_behaviour_to_all_relation_instances(&self, relation_behaviour_ty: &RelationBehaviourTypeId);
96
97 fn add_behaviour_to_all_relation_components(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
99
100 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}