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