Skip to main content

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
22pub mod filter;
23pub use filter::{FILTER_STATUS_HALT, FILTER_STATUS_SKIP, FilterConfig, RejectAction};
24
25pub mod log;
26pub use log::{LogConfig, LogLevel};
27
28pub mod integration;
29pub use integration::{EnrichConfig, HttpCallConfig, PublishKafkaConfig};
30
31// Re-export all built-in functions for easier access
32pub mod builtins {
33    use super::*;
34
35    // Get all built-in functions with their standard names
36    pub fn get_all_functions() -> Vec<(String, Box<dyn AsyncFunctionHandler + Send + Sync>)> {
37        // Map and Validate are now internal to the Engine for better performance
38        // They can directly access compiled logic cache
39        // Add other built-in functions here as needed (HTTP, File I/O, etc.)
40        vec![]
41    }
42}
43
44/// Async interface for task functions that operate on messages
45///
46/// ## Usage
47///
48/// Implement this trait for custom processing logic.
49/// The function receives:
50/// - Mutable access to the message being processed (no cloning needed!)
51/// - Pre-parsed function configuration
52/// - Reference to the DataLogic instance for JSONLogic evaluation
53///
54/// ## Performance Note
55///
56/// This trait works directly with `&mut Message` without any cloning.
57/// The message is passed by mutable reference throughout the async execution,
58/// ensuring zero-copy operation for optimal performance.
59#[async_trait]
60pub trait AsyncFunctionHandler: Send + Sync {
61    /// Execute the function on a message with pre-parsed configuration
62    ///
63    /// # Arguments
64    ///
65    /// * `message` - The message to process (mutable reference, no cloning)
66    /// * `config` - Pre-parsed function configuration
67    /// * `datalogic` - Reference to DataLogic instance for JSONLogic evaluation
68    ///
69    /// # Returns
70    ///
71    /// * `Result<(usize, Vec<Change>)>` - Result containing status code and changes, or error
72    async fn execute(
73        &self,
74        message: &mut Message,
75        config: &FunctionConfig,
76        datalogic: Arc<DataLogic>,
77    ) -> Result<(usize, Vec<Change>)>;
78}