reifydb_transaction/interceptor/
view_def.rs1use reifydb_core::interface::catalog::view::ViewDef;
5use reifydb_type::Result;
6
7use crate::interceptor::chain::InterceptorChain;
8
9pub struct ViewDefPostCreateContext<'a> {
12 pub post: &'a ViewDef,
13}
14
15impl<'a> ViewDefPostCreateContext<'a> {
16 pub fn new(post: &'a ViewDef) -> Self {
17 Self {
18 post,
19 }
20 }
21}
22
23pub trait ViewDefPostCreateInterceptor: Send + Sync {
24 fn intercept<'a>(&self, ctx: &mut ViewDefPostCreateContext<'a>) -> Result<()>;
25}
26
27impl InterceptorChain<dyn ViewDefPostCreateInterceptor + Send + Sync> {
28 pub fn execute(&self, mut ctx: ViewDefPostCreateContext) -> Result<()> {
29 for interceptor in &self.interceptors {
30 interceptor.intercept(&mut ctx)?;
31 }
32 Ok(())
33 }
34}
35
36pub struct ClosureViewDefPostCreateInterceptor<F>
37where
38 F: for<'a> Fn(&mut ViewDefPostCreateContext<'a>) -> Result<()> + Send + Sync,
39{
40 closure: F,
41}
42
43impl<F> ClosureViewDefPostCreateInterceptor<F>
44where
45 F: for<'a> Fn(&mut ViewDefPostCreateContext<'a>) -> Result<()> + Send + Sync,
46{
47 pub fn new(closure: F) -> Self {
48 Self {
49 closure,
50 }
51 }
52}
53
54impl<F> Clone for ClosureViewDefPostCreateInterceptor<F>
55where
56 F: for<'a> Fn(&mut ViewDefPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone,
57{
58 fn clone(&self) -> Self {
59 Self {
60 closure: self.closure.clone(),
61 }
62 }
63}
64
65impl<F> ViewDefPostCreateInterceptor for ClosureViewDefPostCreateInterceptor<F>
66where
67 F: for<'a> Fn(&mut ViewDefPostCreateContext<'a>) -> Result<()> + Send + Sync,
68{
69 fn intercept<'a>(&self, ctx: &mut ViewDefPostCreateContext<'a>) -> Result<()> {
70 (self.closure)(ctx)
71 }
72}
73
74pub fn view_def_post_create<F>(f: F) -> ClosureViewDefPostCreateInterceptor<F>
75where
76 F: for<'a> Fn(&mut ViewDefPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
77{
78 ClosureViewDefPostCreateInterceptor::new(f)
79}
80
81pub struct ViewDefPreUpdateContext<'a> {
84 pub pre: &'a ViewDef,
85}
86
87impl<'a> ViewDefPreUpdateContext<'a> {
88 pub fn new(pre: &'a ViewDef) -> Self {
89 Self {
90 pre,
91 }
92 }
93}
94
95pub trait ViewDefPreUpdateInterceptor: Send + Sync {
96 fn intercept<'a>(&self, ctx: &mut ViewDefPreUpdateContext<'a>) -> Result<()>;
97}
98
99impl InterceptorChain<dyn ViewDefPreUpdateInterceptor + Send + Sync> {
100 pub fn execute(&self, mut ctx: ViewDefPreUpdateContext) -> Result<()> {
101 for interceptor in &self.interceptors {
102 interceptor.intercept(&mut ctx)?;
103 }
104 Ok(())
105 }
106}
107
108pub struct ClosureViewDefPreUpdateInterceptor<F>
109where
110 F: for<'a> Fn(&mut ViewDefPreUpdateContext<'a>) -> Result<()> + Send + Sync,
111{
112 closure: F,
113}
114
115impl<F> ClosureViewDefPreUpdateInterceptor<F>
116where
117 F: for<'a> Fn(&mut ViewDefPreUpdateContext<'a>) -> Result<()> + Send + Sync,
118{
119 pub fn new(closure: F) -> Self {
120 Self {
121 closure,
122 }
123 }
124}
125
126impl<F> Clone for ClosureViewDefPreUpdateInterceptor<F>
127where
128 F: for<'a> Fn(&mut ViewDefPreUpdateContext<'a>) -> Result<()> + Send + Sync + Clone,
129{
130 fn clone(&self) -> Self {
131 Self {
132 closure: self.closure.clone(),
133 }
134 }
135}
136
137impl<F> ViewDefPreUpdateInterceptor for ClosureViewDefPreUpdateInterceptor<F>
138where
139 F: for<'a> Fn(&mut ViewDefPreUpdateContext<'a>) -> Result<()> + Send + Sync,
140{
141 fn intercept<'a>(&self, ctx: &mut ViewDefPreUpdateContext<'a>) -> Result<()> {
142 (self.closure)(ctx)
143 }
144}
145
146pub fn view_def_pre_update<F>(f: F) -> ClosureViewDefPreUpdateInterceptor<F>
147where
148 F: for<'a> Fn(&mut ViewDefPreUpdateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
149{
150 ClosureViewDefPreUpdateInterceptor::new(f)
151}
152
153pub struct ViewDefPostUpdateContext<'a> {
156 pub pre: &'a ViewDef,
157 pub post: &'a ViewDef,
158}
159
160impl<'a> ViewDefPostUpdateContext<'a> {
161 pub fn new(pre: &'a ViewDef, post: &'a ViewDef) -> Self {
162 Self {
163 pre,
164 post,
165 }
166 }
167}
168
169pub trait ViewDefPostUpdateInterceptor: Send + Sync {
170 fn intercept<'a>(&self, ctx: &mut ViewDefPostUpdateContext<'a>) -> Result<()>;
171}
172
173impl InterceptorChain<dyn ViewDefPostUpdateInterceptor + Send + Sync> {
174 pub fn execute(&self, mut ctx: ViewDefPostUpdateContext) -> Result<()> {
175 for interceptor in &self.interceptors {
176 interceptor.intercept(&mut ctx)?;
177 }
178 Ok(())
179 }
180}
181
182pub struct ClosureViewDefPostUpdateInterceptor<F>
183where
184 F: for<'a> Fn(&mut ViewDefPostUpdateContext<'a>) -> Result<()> + Send + Sync,
185{
186 closure: F,
187}
188
189impl<F> ClosureViewDefPostUpdateInterceptor<F>
190where
191 F: for<'a> Fn(&mut ViewDefPostUpdateContext<'a>) -> Result<()> + Send + Sync,
192{
193 pub fn new(closure: F) -> Self {
194 Self {
195 closure,
196 }
197 }
198}
199
200impl<F> Clone for ClosureViewDefPostUpdateInterceptor<F>
201where
202 F: for<'a> Fn(&mut ViewDefPostUpdateContext<'a>) -> Result<()> + Send + Sync + Clone,
203{
204 fn clone(&self) -> Self {
205 Self {
206 closure: self.closure.clone(),
207 }
208 }
209}
210
211impl<F> ViewDefPostUpdateInterceptor for ClosureViewDefPostUpdateInterceptor<F>
212where
213 F: for<'a> Fn(&mut ViewDefPostUpdateContext<'a>) -> Result<()> + Send + Sync,
214{
215 fn intercept<'a>(&self, ctx: &mut ViewDefPostUpdateContext<'a>) -> Result<()> {
216 (self.closure)(ctx)
217 }
218}
219
220pub fn view_def_post_update<F>(f: F) -> ClosureViewDefPostUpdateInterceptor<F>
221where
222 F: for<'a> Fn(&mut ViewDefPostUpdateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
223{
224 ClosureViewDefPostUpdateInterceptor::new(f)
225}
226
227pub struct ViewDefPreDeleteContext<'a> {
230 pub pre: &'a ViewDef,
231}
232
233impl<'a> ViewDefPreDeleteContext<'a> {
234 pub fn new(pre: &'a ViewDef) -> Self {
235 Self {
236 pre,
237 }
238 }
239}
240
241pub trait ViewDefPreDeleteInterceptor: Send + Sync {
242 fn intercept<'a>(&self, ctx: &mut ViewDefPreDeleteContext<'a>) -> Result<()>;
243}
244
245impl InterceptorChain<dyn ViewDefPreDeleteInterceptor + Send + Sync> {
246 pub fn execute(&self, mut ctx: ViewDefPreDeleteContext) -> Result<()> {
247 for interceptor in &self.interceptors {
248 interceptor.intercept(&mut ctx)?;
249 }
250 Ok(())
251 }
252}
253
254pub struct ClosureViewDefPreDeleteInterceptor<F>
255where
256 F: for<'a> Fn(&mut ViewDefPreDeleteContext<'a>) -> Result<()> + Send + Sync,
257{
258 closure: F,
259}
260
261impl<F> ClosureViewDefPreDeleteInterceptor<F>
262where
263 F: for<'a> Fn(&mut ViewDefPreDeleteContext<'a>) -> Result<()> + Send + Sync,
264{
265 pub fn new(closure: F) -> Self {
266 Self {
267 closure,
268 }
269 }
270}
271
272impl<F> Clone for ClosureViewDefPreDeleteInterceptor<F>
273where
274 F: for<'a> Fn(&mut ViewDefPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone,
275{
276 fn clone(&self) -> Self {
277 Self {
278 closure: self.closure.clone(),
279 }
280 }
281}
282
283impl<F> ViewDefPreDeleteInterceptor for ClosureViewDefPreDeleteInterceptor<F>
284where
285 F: for<'a> Fn(&mut ViewDefPreDeleteContext<'a>) -> Result<()> + Send + Sync,
286{
287 fn intercept<'a>(&self, ctx: &mut ViewDefPreDeleteContext<'a>) -> Result<()> {
288 (self.closure)(ctx)
289 }
290}
291
292pub fn view_def_pre_delete<F>(f: F) -> ClosureViewDefPreDeleteInterceptor<F>
293where
294 F: for<'a> Fn(&mut ViewDefPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
295{
296 ClosureViewDefPreDeleteInterceptor::new(f)
297}