dataflow_rs/engine/functions/mod.rs
1use crate::engine::error::Result;
2use crate::engine::message::{Change, Message};
3use async_trait::async_trait;
4use datalogic_rs::DataLogic;
5use std::sync::Arc;
6
7pub mod config;
8pub use config::FunctionConfig;
9
10pub mod validation;
11pub use validation::{ValidationConfig, ValidationRule};
12
13pub mod map;
14pub use map::{MapConfig, MapMapping};
15
16pub mod parse;
17pub use parse::ParseConfig;
18
19pub mod publish;
20pub use publish::PublishConfig;
21
22// Re-export all built-in functions for easier access
23pub mod builtins {
24 use super::*;
25
26 // Get all built-in functions with their standard names
27 pub fn get_all_functions() -> Vec<(String, Box<dyn AsyncFunctionHandler + Send + Sync>)> {
28 // Map and Validate are now internal to the Engine for better performance
29 // They can directly access compiled logic cache
30 // Add other built-in functions here as needed (HTTP, File I/O, etc.)
31 vec![]
32 }
33}
34
35/// Async interface for task functions that operate on messages
36///
37/// ## Usage
38///
39/// Implement this trait for custom processing logic.
40/// The function receives:
41/// - Mutable access to the message being processed (no cloning needed!)
42/// - Pre-parsed function configuration
43/// - Reference to the DataLogic instance for JSONLogic evaluation
44///
45/// ## Performance Note
46///
47/// This trait works directly with `&mut Message` without any cloning.
48/// The message is passed by mutable reference throughout the async execution,
49/// ensuring zero-copy operation for optimal performance.
50#[async_trait]
51pub trait AsyncFunctionHandler: Send + Sync {
52 /// Execute the function on a message with pre-parsed configuration
53 ///
54 /// # Arguments
55 ///
56 /// * `message` - The message to process (mutable reference, no cloning)
57 /// * `config` - Pre-parsed function configuration
58 /// * `datalogic` - Reference to DataLogic instance for JSONLogic evaluation
59 ///
60 /// # Returns
61 ///
62 /// * `Result<(usize, Vec<Change>)>` - Result containing status code and changes, or error
63 async fn execute(
64 &self,
65 message: &mut Message,
66 config: &FunctionConfig,
67 datalogic: Arc<DataLogic>,
68 ) -> Result<(usize, Vec<Change>)>;
69}