reactive_graph_plugin_api/instances/relations/
relation_instance_manager.rs

1use serde_json::Value;
2use uuid::Uuid;
3
4use reactive_graph_behaviour_model_api::BehaviourTypeId;
5use reactive_graph_graph::ComponentTypeId;
6use reactive_graph_graph::Mutability;
7use reactive_graph_graph::RelationInstance;
8use reactive_graph_graph::RelationInstanceId;
9use reactive_graph_graph::RelationTypeId;
10use reactive_graph_reactive_model_impl::ReactiveRelation;
11use reactive_graph_reactive_service_api::ReactiveRelationComponentAddError;
12use reactive_graph_reactive_service_api::ReactiveRelationComponentRemoveError;
13use reactive_graph_reactive_service_api::ReactiveRelationCreationError;
14use reactive_graph_reactive_service_api::ReactiveRelationPropertyAddError;
15use reactive_graph_reactive_service_api::ReactiveRelationPropertyRemoveError;
16use reactive_graph_reactive_service_api::ReactiveRelationRegistrationError;
17
18#[derive(Debug)]
19pub enum RelationInstanceManagerError {
20    InitializationError,
21}
22
23pub trait RelationInstanceManager: Send + Sync {
24    /// Returns true, if an relation of the given type exists which starts at the given outbound entity and
25    /// ends at the given inbound entity.
26    fn has(&self, id: &RelationInstanceId) -> bool;
27
28    /// Returns the ReactiveRelation with the given type_name, which starts at the given
29    /// outbound entity and ends at the given inbound entity.
30    fn get(&self, id: &RelationInstanceId) -> Option<ReactiveRelation>;
31
32    /// Returns all reactive relation instances of the given outbound entity instance.
33    fn get_by_outbound_entity(&self, outbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
34
35    /// Returns all reactive relation instances of the given inbound entity instance.
36    fn get_by_inbound_entity(&self, inbound_entity_id: Uuid) -> Vec<ReactiveRelation>;
37
38    /// Returns all reactive relation instances.
39    fn get_all(&self) -> Vec<ReactiveRelation>;
40
41    /// Returns all reactive relation instances of the given type.
42    fn get_by_type(&self, ty: &RelationTypeId) -> Vec<ReactiveRelation>;
43
44    /// Returns all reactive relation instances of the given namespace.
45    fn get_by_namespace(&self, namespace: &str) -> Vec<ReactiveRelation>;
46
47    /// Returns all relation instance ids.
48    fn get_keys(&self) -> Vec<RelationInstanceId>;
49
50    /// Returns the count of registered reactive relation instances.
51    fn count(&self) -> usize;
52
53    /// Returns the count of registered reactive relation instances of the given type.
54    fn count_by_type(&self, ty: &RelationTypeId) -> usize;
55
56    /// Returns the count of registered reactive relation instances which are of the given component.
57    fn count_by_component(&self, component: &ComponentTypeId) -> usize;
58
59    /// Returns the count of registered reactive relation instances which behaves as the given behaviour.
60    fn count_by_behaviour(&self, behaviour_ty: &BehaviourTypeId) -> usize;
61
62    /// Creates a new reactive relation instance.
63    fn create(&self, relation_instance: RelationInstance) -> Result<ReactiveRelation, ReactiveRelationCreationError>;
64
65    /// Registers the given reactive relation instance and applies components and behaviours.
66    fn register(&self, reactive_relation: ReactiveRelation) -> Result<ReactiveRelation, ReactiveRelationRegistrationError>;
67
68    /// Adds the component with the given name to the relation instance with the given relation instance id.
69    fn add_component(&self, relation_instance_id: &RelationInstanceId, component: &ComponentTypeId) -> Result<(), ReactiveRelationComponentAddError>;
70
71    /// Removes the component with the given name from the relation instance with the given relation instance id.
72    fn remove_component(&self, relation_instance_id: &RelationInstanceId, component: &ComponentTypeId) -> Result<(), ReactiveRelationComponentRemoveError>;
73
74    /// Adds the property with the given name and initial value to the relation instance with the given id.
75    fn add_property(
76        &self,
77        relation_instance_id: &RelationInstanceId,
78        property_name: &str,
79        mutability: Mutability,
80        value: Value,
81    ) -> Result<(), ReactiveRelationPropertyAddError>;
82
83    /// Removes the property with the given name from the relation instance with the given id.
84    fn remove_property(&self, relation_instance_id: &RelationInstanceId, property_name: &str) -> Result<(), ReactiveRelationPropertyRemoveError>;
85
86    /// Deletes the reactive relation instance with the given key.
87    fn delete(&self, relation_instance_id: &RelationInstanceId) -> bool;
88}