use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum LogLevel {
Debug,
Info,
Warn,
Error,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum HttpMethod {
Get,
Post,
Put,
Delete,
Patch,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HttpResponse {
pub status: u16,
pub body: String,
}
#[derive(Debug, Clone)]
pub enum HostFunction {
Log { level: LogLevel, message: String },
ReadColumn { name: String },
EmitRow { row: Value },
GetEnv { key: String },
HttpRequest {
url: String,
method: HttpMethod,
body: Option<String>,
},
}
pub trait HostContext: Send + Sync {
fn log(&self, _level: LogLevel, _message: &str) {}
fn read_column(&self, _name: &str) -> Vec<Value> {
Vec::new()
}
fn emit_row(&self, _row: Value) {}
fn get_env(&self, _key: &str) -> Option<String> {
None
}
#[cfg(feature = "host-http")]
fn http_request(
&self,
_url: &str,
_method: HttpMethod,
_body: Option<&str>,
) -> crate::error::Result<HttpResponse> {
Err(crate::error::AfterburnerError::Host(
"http_request not implemented".into(),
))
}
}
pub struct NullHost;
impl HostContext for NullHost {}