paganel_plugin_sdk/
lib.rs1pub mod columnar;
44pub mod error;
45pub mod exchange;
46pub mod filter;
47pub mod host;
48pub mod input;
49pub mod output;
50pub mod record;
51pub mod runtime;
52pub mod schema;
53pub mod sink;
54pub mod source;
55pub mod value;
56
57pub use paganel_plugin_sdk_macros::{
59 paganel_filter, paganel_sink, paganel_source, paganel_transform,
60};
61
62pub use error::{PluginError, PluginErrorCode, PluginResult};
64pub use filter::FilterDecision;
65pub use input::PluginInput;
66pub use output::PluginOutput;
67pub use record::{FieldValue, Record};
68pub use schema::{PluginField, PluginMetadata, PluginType};
69pub use sink::{PluginBatch, SinkConfig, WriteResult};
70pub use source::{SourceConfig, SourcePage};
71pub use value::Value;
72
73pub use host::env::env_get;
75pub use host::fs::{fs_read, fs_read_to_string, fs_write};
76pub use host::http::{HttpResponse, http_get, http_post};
77pub use host::kv::{kv_get, kv_set};
78pub use host::log::{log_debug, log_error, log_info, log_warn};
79pub use host::metrics::{metric_counter, metric_gauge};
80
81pub use runtime::pack::{pack, unpack};
83
84use std::collections::HashMap;
85use std::sync::OnceLock;
86
87#[derive(Debug, Clone, Default)]
90pub struct PluginConfig {
91 params: HashMap<String, String>,
92}
93
94impl PluginConfig {
95 pub fn new(params: HashMap<String, String>) -> Self {
96 Self { params }
97 }
98
99 pub fn get(&self, key: &str) -> Option<&str> {
101 self.params.get(key).map(String::as_str)
102 }
103
104 pub fn require(&self, key: &str) -> PluginResult<&str> {
106 self.get(key)
107 .ok_or_else(|| PluginError::invalid_input(format!("missing config key: '{}'", key)))
108 }
109}
110
111static PLUGIN_CONFIG: OnceLock<PluginConfig> = OnceLock::new();
112static SOURCE_CONFIG: OnceLock<SourceConfig> = OnceLock::new();
113static SINK_CONFIG: OnceLock<SinkConfig> = OnceLock::new();
114
115pub fn config() -> &'static PluginConfig {
117 PLUGIN_CONFIG.get_or_init(PluginConfig::default)
118}
119
120#[doc(hidden)]
121pub fn __set_plugin_config(cfg: PluginConfig) {
122 let _ = PLUGIN_CONFIG.set(cfg);
123}
124
125pub fn source_config() -> PluginResult<&'static SourceConfig> {
128 SOURCE_CONFIG
129 .get()
130 .ok_or_else(|| PluginError::internal("source plugin not initialized"))
131}
132
133pub fn sink_config() -> PluginResult<&'static SinkConfig> {
136 SINK_CONFIG
137 .get()
138 .ok_or_else(|| PluginError::internal("sink plugin not initialized"))
139}
140
141#[doc(hidden)]
142pub fn __set_source_config(cfg: SourceConfig) {
143 let _ = SOURCE_CONFIG.set(cfg);
144}
145
146#[doc(hidden)]
147pub fn __set_sink_config(cfg: SinkConfig) {
148 let _ = SINK_CONFIG.set(cfg);
149}