Skip to main content

Crate allsource

Crate allsource 

Source
Expand description

§AllSource Rust SDK

Official Rust client for the AllSource event store. Provides two clients:

  • QueryClient — reads from the Query Service (events, projections, streams)
  • CoreClient — writes directly to Core (event ingestion, batch ingest)

Plus the EventFolder trait for reconstructing domain state from event streams.

§Quick Start

use allsource::{QueryClient, IngestEventInput};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), allsource::Error> {
    let qs = QueryClient::new("http://localhost:3902", "your-api-key")?;

    // Query events
    let result = qs.query_events(
        allsource::QueryEventsParams::new().entity_id("user-123").limit(10),
    ).await?;

    for event in &result.events {
        println!("{}: {}", event.event_type, event.timestamp);
    }

    Ok(())
}

§Event Folding

use allsource::{Event, EventFolder, fold_events};

#[derive(Default)]
struct UserState {
    email: Option<String>,
    name: Option<String>,
    active: bool,
}

impl EventFolder for UserState {
    type State = Self;

    fn apply(&mut self, event: &Event) -> bool {
        match event.event_type.as_str() {
            "user.created" => {
                self.email = event.payload.get("email").and_then(|v| v.as_str()).map(String::from);
                self.name = event.payload.get("name").and_then(|v| v.as_str()).map(String::from);
                self.active = true;
                true
            }
            "user.deactivated" => { self.active = false; true }
            _ => false,
        }
    }

    fn finalize(self) -> Option<Self::State> {
        if self.email.is_some() { Some(self) } else { None }
    }
}

Re-exports§

pub use serde_json;

Macros§

json
Construct a serde_json::Value from a JSON literal.

Structs§

BatchIngestResponse
Response from batch ingesting events via Core.
CircuitBreaker
A circuit breaker that trips after consecutive failures.
ClientConfig
Full configuration for building a client.
CoreClient
Client for AllSource Core (writes).
DetectDuplicatesResponse
Response from duplicate entity detection.
DuplicateGroup
A group of entities that share the same payload field values (duplicates).
EntitySummary
Summary of a single entity returned by the list-entities endpoint.
Event
A stored event returned from AllSource.
HealthResponse
Health check response.
IngestEventInput
An event to ingest into AllSource.
IngestResponse
Response from ingesting an event via Core.
ListEntitiesResponse
Response from listing entities.
Projection
A projection state.
ProjectionsResponse
Projections list response.
QueryClient
Client for the AllSource Query Service (reads).
QueryEventsParams
Query parameters for filtering events. Uses builder pattern.
QueryEventsResponse
Response from querying events.
RetryConfig
Retry configuration for transient failures.

Enums§

Error
Errors returned by the AllSource SDK.
Value
Represents any valid JSON value.

Traits§

EventFolder
Trait for reconstructing domain state from an event stream.

Functions§

fold_events
Fold a sequence of events into domain state using an EventFolder.
normalize_event_type
Normalize an event type to AllSource’s lowercase.dot.separated convention.