Skip to main content

SubgraphTransformer

Struct SubgraphTransformer 

Source
pub struct SubgraphTransformer {
    pub subgraph_name: String,
    pub ns: Vec<String>,
    pub filter: Option<Arc<dyn Fn(&Value) -> bool + Send + Sync>>,
    pub include_internal: bool,
}
Expand description

Subgraph stream event transformer with namespace and filter

Transforms stream events from subgraph execution by adding namespace prefixes and filtering events based on configuration.

Fields§

§subgraph_name: String

Subgraph name for namespace prefix

§ns: Vec<String>

Current namespace stack

§filter: Option<Arc<dyn Fn(&Value) -> bool + Send + Sync>>

Optional filter for event types

The closure receives the event as a serde_json::Value and returns true if the event should be included, false otherwise.

§include_internal: bool

Whether to include internal events

Implementations§

Source§

impl SubgraphTransformer

Source

pub const fn new(subgraph_name: String) -> Self

Create a new subgraph transformer

§Arguments
  • subgraph_name - Name of the subgraph for namespace prefix
Source

pub fn with_filter( self, filter: impl Fn(&Value) -> bool + Send + Sync + 'static, ) -> Self

Set event filter as a closure

§Arguments
  • filter - Closure that receives the event as JSON and returns true if the event should be included
Source

pub fn with_filter_types(self, types: Vec<String>) -> Self

Set event filter by event type names (backward compatibility)

§Arguments
  • types - List of event types to include (empty means all events)
Source

pub const fn with_internal(self, include: bool) -> Self

Set whether to include internal events

§Arguments
  • include - Whether to include internal events
Source

pub fn transform<S: State>( &self, event: &StreamEvent<S>, ) -> Option<StreamEvent<S>>

Transform a stream event by adding namespace prefixes.

Applies two transformations to subgraph stream events:

  1. Filter: if a filter closure is configured, events whose type does not match are discarded (None is returned).
  2. Namespace: the node field of matching events is prefixed with the subgraph namespace (ns/subgraph_name), and the ns vector is extended with the subgraph name to reflect the nesting path.
§Arguments
  • event - The stream event to transform.
§Returns

Some(transformed_event) if the event passes the filter, None otherwise. Variants that carry no node or ns fields are returned unchanged (aside from cloning).

Source

pub fn add_namespace(&mut self, segment: String)

Add a namespace segment

§Arguments
  • segment - The namespace segment to add
Source

pub fn child_transformer(&self, child_name: &str) -> Self

Create a child transformer for a nested subgraph.

The child transformer inherits the current namespace and appends the current subgraph_name as an additional segment, then sets the child name. This enables correct namespace propagation for sub-subgraphs.

§Arguments
  • child_name - Name of the nested (child) subgraph
§Examples
use juncture_core::SubgraphTransformer;

let parent = SubgraphTransformer::new("parent".to_string());
let child = parent.child_transformer("child");

// The child transformer's build_ns would produce:
//   ns_prefix = "parent/child"
//   full_ns   = ["parent", "child"]
Source

pub fn to_emitter<S: State>( &self, tx: Sender<StreamEvent<S>>, mode: StreamMode, ) -> EventEmitter<S>

Create an EventEmitter with this transformer’s namespace chain applied.

Each namespace segment in self.ns and self.subgraph_name is applied via [EventEmitter::with_subgraph_ns] so that events emitted through the returned emitter carry the full subgraph nesting path.

§Arguments
  • tx - The underlying sender for stream events
  • mode - The stream mode controlling what events are emitted
§Examples
use juncture_core::{EventEmitter, SubgraphTransformer, StreamMode};
use juncture_core::state::FieldVersions;
use tokio::sync::mpsc;

#[derive(Clone, Debug)]
struct MyState;
impl juncture_core::State for MyState {
    type Update = MyUpdate;
    type FieldVersions = FieldVersions;
    fn apply(&mut self, _u: MyUpdate) -> juncture_core::FieldsChanged {
        juncture_core::FieldsChanged(0)
    }
    fn reset_ephemeral(&mut self) {}
}
#[derive(Clone, Debug, Default)]
struct MyUpdate;

let (tx, _rx) = mpsc::channel(16);
let transformer = SubgraphTransformer::new("sub".to_string());
let emitter: EventEmitter<MyState> = transformer.to_emitter(tx, StreamMode::Values);
assert_eq!(emitter.ns(), &["sub"]);

Trait Implementations§

Source§

impl Clone for SubgraphTransformer

Source§

fn clone(&self) -> SubgraphTransformer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubgraphTransformer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more