hit_data/plugins/
plugin.rs

1use std::rc::Rc;
2
3use crate::{index::IndexEntryProperty, HitEntry, ObjectValue};
4use crate::{object_data::ObjectValues, Hit};
5use crate::{HitError, Id, Model};
6
7pub trait InitEntryPlugin {
8    fn on_init_add_entry(
9        &mut self,
10        model: Rc<Model>,
11        id: &str,
12        data: ObjectValues,
13        parent: Option<IndexEntryProperty>,
14    );
15}
16
17pub trait AfterImportPlugin {
18    fn after_import(&mut self, hit: &Hit) -> Result<(), HitError>;
19}
20
21pub trait InitEntryAfterIndexPlugin {
22    fn for_each_entry(
23        &mut self,
24        model: Rc<Model>,
25        id: &str,
26        data: ObjectValues,
27        parent: Option<IndexEntryProperty>,
28    );
29}
30
31pub trait DeletePlugin {
32    fn on_before_delete_entry(
33        &mut self,
34        entry: &HitEntry,
35        instance: &mut Hit,
36    ) -> Result<(), HitError>;
37    fn on_after_delete_entry(
38        &mut self,
39        entry: &HitEntry,
40        instance: &mut Hit,
41    ) -> Result<(), HitError>;
42}
43pub trait ReferencePlugin {
44    fn on_before_add_reference(
45        &mut self,
46        instance: &mut Hit,
47        reference_id: &Id,
48        target: &IndexEntryProperty,
49        before_id: &Option<String>,
50    ) -> Result<(), HitError>;
51    fn on_after_add_reference(
52        &mut self,
53        instance: &mut Hit,
54        reference_id: &Id,
55        target: &IndexEntryProperty,
56        before_id: &Option<String>,
57    ) -> Result<(), HitError>;
58    fn on_before_move_reference(
59        &mut self,
60        instance: &mut Hit,
61        reference_id: &Id,
62        target: &IndexEntryProperty,
63        before_id: &Option<String>,
64    ) -> Result<(), HitError>;
65    fn on_after_move_reference(
66        &mut self,
67        instance: &mut Hit,
68        reference_id: &Id,
69        target: &IndexEntryProperty,
70        before_id: &Option<String>,
71    ) -> Result<(), HitError>;
72    fn on_before_remove_reference(
73        &mut self,
74        instance: &mut Hit,
75        reference_id: &Id,
76        target: &IndexEntryProperty,
77    ) -> Result<(), HitError>;
78    fn on_after_remove_reference(
79        &mut self,
80        instance: &mut Hit,
81        reference_id: &Id,
82        target: &IndexEntryProperty,
83    ) -> Result<(), HitError>;
84}
85
86pub trait Plugin {
87    fn on_before_add_entry(
88        &mut self,
89        model: Rc<Model>,
90        id: &str,
91        data: ObjectValues,
92        parent: IndexEntryProperty,
93        before_id: &Option<Id>,
94        instance: &Hit,
95    ) -> Result<(), HitError>;
96
97    fn on_after_add_entry(
98        &mut self,
99        model: Rc<Model>,
100        id: &str,
101        data: ObjectValues,
102        parent: IndexEntryProperty,
103        before_id: &Option<Id>,
104        instance: &mut Hit,
105    ) -> Result<(), HitError>;
106
107    fn on_before_set_value(
108        &mut self,
109        property: IndexEntryProperty,
110        value: &ObjectValue,
111        old_value: &Option<ObjectValue>,
112        instance: &Hit,
113    ) -> Result<(), HitError>;
114
115    fn on_after_set_value(
116        &mut self,
117        property: IndexEntryProperty,
118        value: &ObjectValue,
119        old_value: &Option<ObjectValue>,
120        instance: &mut Hit,
121    ) -> Result<(), HitError>;
122
123    fn on_before_move_subobject(
124        &mut self,
125        id: &str,
126        target: IndexEntryProperty,
127        before_id: Option<String>,
128        instance: &Hit,
129    ) -> Result<(), HitError>;
130
131    fn on_after_move_subobject(
132        &mut self,
133        id: &str,
134        target: IndexEntryProperty,
135        original_parent: IndexEntryProperty,
136        before_id: Option<String>,
137        instance: &mut Hit,
138    ) -> Result<(), HitError>;
139}