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