openauth_core/plugin/db/
handler.rs1use std::fmt;
2use std::future::Future;
3use std::pin::Pin;
4use std::sync::Arc;
5
6use crate::db::DbAdapter;
7use crate::error::OpenAuthError;
8use crate::plugin::{
9 PluginDatabaseAfterInput, PluginDatabaseBeforeAction, PluginDatabaseBeforeInput,
10};
11
12use super::PluginDatabaseOperation;
13
14pub struct PluginDatabaseHookContext<'a> {
16 pub plugin_id: String,
17 pub hook_name: String,
18 pub operation: PluginDatabaseOperation,
19 pub model: String,
20 pub adapter: &'a dyn DbAdapter,
21 pub request_path: Option<String>,
22}
23
24impl fmt::Debug for PluginDatabaseHookContext<'_> {
25 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
26 formatter
27 .debug_struct("PluginDatabaseHookContext")
28 .field("plugin_id", &self.plugin_id)
29 .field("hook_name", &self.hook_name)
30 .field("operation", &self.operation)
31 .field("model", &self.model)
32 .field("adapter", &self.adapter.id())
33 .field("request_path", &self.request_path)
34 .finish()
35 }
36}
37
38pub type PluginDatabaseBeforeHookFuture<'a> =
39 Pin<Box<dyn Future<Output = Result<PluginDatabaseBeforeAction, OpenAuthError>> + Send + 'a>>;
40pub type PluginDatabaseAfterHookFuture<'a> =
41 Pin<Box<dyn Future<Output = Result<(), OpenAuthError>> + Send + 'a>>;
42
43pub type PluginDatabaseBeforeHookHandler = Arc<
44 dyn for<'a> Fn(
45 PluginDatabaseHookContext<'a>,
46 PluginDatabaseBeforeInput,
47 ) -> PluginDatabaseBeforeHookFuture<'a>
48 + Send
49 + Sync,
50>;
51
52pub type PluginDatabaseAfterHookHandler = Arc<
53 dyn for<'a> Fn(
54 PluginDatabaseHookContext<'a>,
55 PluginDatabaseAfterInput,
56 ) -> PluginDatabaseAfterHookFuture<'a>
57 + Send
58 + Sync,
59>;