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::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 fn has(&self, id: &RelationInstanceId) -> bool;
32
33 fn get(&self, id: &RelationInstanceId) -> Option<ReactiveRelation>;
36
37 fn get_by_outbound_entity(&self, outbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
39
40 fn get_by_inbound_entity(&self, inbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
42
43 fn get_all(&self) -> Vec<ReactiveRelation>;
45
46 fn get_by_type(&self, ty: &RelationTypeId) -> Vec<ReactiveRelation>;
48
49 fn get_by_component(&self, component_ty: &ComponentTypeId) -> Vec<ReactiveRelation>;
51
52 fn get_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> Vec<ReactiveRelation>;
54
55 fn get_by_namespace(&self, namespace: &Namespace) -> Vec<ReactiveRelation>;
57
58 fn get_relation_instance_ids(&self) -> Vec<RelationInstanceId>;
60
61 fn count(&self) -> usize;
63
64 fn count_by_type(&self, ty: &RelationTypeId) -> usize;
66
67 fn count_by_component(&self, component_ty: &ComponentTypeId) -> usize;
69
70 fn count_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> usize;
72
73 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 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 fn add_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentAddError>;
85
86 fn remove_component(&self, id: &RelationInstanceId, component_ty: &ComponentTypeId) -> Result<(), ReactiveRelationComponentRemoveError>;
88
89 fn add_property(&self, id: &RelationInstanceId, property_name: &str, mutability: Mutability, value: Value) -> Result<(), ReactiveRelationPropertyAddError>;
91
92 fn remove_property(&self, id: &RelationInstanceId, property_name: &str) -> Result<(), ReactiveRelationPropertyRemoveError>;
94
95 fn add_behaviour_to_all_relation_instances(&self, relation_behaviour_ty: &RelationBehaviourTypeId);
97
98 fn add_behaviour_to_all_relation_components(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
100
101 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}