pub struct SourceMappingEngine { /* private fields */ }Expand description
Source mapping engine that transforms payloads into graph change events.
Uses Handlebars templates to extract element IDs, labels, properties, and operations from arbitrary JSON contexts.
The context is a serde_json::Value that each source builds with its own
variables. For example:
- HTTP source:
{ "payload": ..., "headers": ..., "route": ..., "query": ... } - Kafka source:
{ "payload": ..., "key": ..., "topic": ..., "partition": ..., "offset": ... }
Implementations§
Source§impl SourceMappingEngine
impl SourceMappingEngine
Sourcepub fn render_string(
&self,
template: &str,
context: &JsonValue,
) -> Result<String>
pub fn render_string( &self, template: &str, context: &JsonValue, ) -> Result<String>
Render a template string with the given context
Sourcepub fn render_value(
&self,
template: &str,
context: &JsonValue,
) -> Result<JsonValue>
pub fn render_value( &self, template: &str, context: &JsonValue, ) -> Result<JsonValue>
Render a template and preserve the JSON value type
If the template is a simple variable reference like {{payload.field}},
this returns the original JSON value. Otherwise, it returns the rendered string.
Sourcepub fn process_mapping(
&self,
mapping: &SourceMapping,
context: &JsonValue,
source_id: &str,
) -> Result<SourceChange>
pub fn process_mapping( &self, mapping: &SourceMapping, context: &JsonValue, source_id: &str, ) -> Result<SourceChange>
Process a source mapping and create a SourceChange.
The context should be a JSON object containing all variables available
to templates (e.g., payload, key, topic, headers, etc.).
Sourcepub fn condition_matches(
&self,
condition: &MappingCondition,
context: &JsonValue,
headers: Option<&HashMap<String, String>>,
) -> bool
pub fn condition_matches( &self, condition: &MappingCondition, context: &JsonValue, headers: Option<&HashMap<String, String>>, ) -> bool
Check if a mapping condition matches the given context.
The headers parameter is optional and only used for header-based conditions.
Sourcepub fn find_matching_mapping<'a>(
&self,
mappings: &'a [SourceMapping],
context: &JsonValue,
headers: Option<&HashMap<String, String>>,
) -> Option<&'a SourceMapping>
pub fn find_matching_mapping<'a>( &self, mappings: &'a [SourceMapping], context: &JsonValue, headers: Option<&HashMap<String, String>>, ) -> Option<&'a SourceMapping>
Find the first matching mapping from a list based on conditions.
Returns None if no mapping matches.