evidentsource_client/client.rs
1//! High-level client API using domain types.
2//!
3//! This module provides an ergonomic, type-safe API for interacting with
4//! EvidentSource using domain types from `evidentsource_core::domain`.
5//!
6//! # Overview
7//!
8//! The high-level API is organized around these main types:
9//!
10//! - [`EvidentSource`] - The main entrypoint for connecting to a server
11//! - [`Connection`] - A live connection to a specific database
12//! - Domain types from `evidentsource_core::domain` for events, conditions, etc.
13//!
14//! # Example
15//!
16//! ```rust,ignore
17//! use evidentsource_client::client::{EvidentSource, Connection};
18//! use evidentsource_core::domain::{DatabaseName, ProspectiveEvent, AppendCondition};
19//!
20//! // Connect to the server
21//! let es = EvidentSource::connect_to_server("http://localhost:50051").await?;
22//!
23//! // List all databases
24//! use futures::StreamExt;
25//! let mut databases = es.list_databases();
26//! while let Some(name) = databases.next().await {
27//! println!("Database: {}", name);
28//! }
29//!
30//! // Connect to a specific database
31//! let db_name = DatabaseName::new("my-db")?;
32//! let conn = es.connect(&db_name).await?;
33//!
34//! // Get the latest database state
35//! let db = conn.latest_database().await?;
36//! println!("Current revision: {}", db.revision());
37//!
38//! // Query state views
39//! let summary = db.view_state(&StateViewName::new("account-summary")?, 1).await?;
40//! ```
41//!
42//! # When to use this module
43//!
44//! This is the recommended API for most applications. It provides:
45//!
46//! - Type-safe domain types that prevent common errors
47//! - Automatic conversion between protocol buffers and domain types
48//! - An ergonomic, Rust-idiomatic interface
49//!
50//! # Low-level access
51//!
52//! If you need direct access to the gRPC protocol for advanced use cases,
53//! see the [`crate::grpc`] module.
54
55// Re-export the main entrypoint
56pub use crate::evident_source::{BackoffConfig, EvidentSource, EvidentSourceBuilder, TlsConfig};
57
58// Re-export authentication types
59pub use crate::auth::{Credentials, DevModeCredentials};
60
61// Re-export connection types
62pub use crate::connection::{
63 Connection, CorrelationId, DatabaseConnectionAsync, DatabaseMetadata, StateChangeBuilder,
64 TransactionBuilder,
65};
66
67// Re-export database types (traits and builders only - impl types are internal)
68pub use crate::database::{DatabaseAtRevisionTyped, EventQueryBuilder, TypedEventQuery};
69
70// Re-export domain types for convenience
71pub use evidentsource_core::domain::{
72 // Append conditions (DCB spec) and selectors
73 AppendCondition,
74 CommandRequest,
75 // Errors
76 DatabaseError,
77 // Identifiers
78 DatabaseName,
79 // Events
80 Event,
81 EventAttribute,
82 EventAttributePrefix,
83 EventData,
84 EventSelector,
85 EventSubject,
86 EventType,
87 ProspectiveEvent,
88 StateChangeError,
89 StateChangeName,
90 StateView,
91 StateViewError,
92 StateViewName,
93 StreamName,
94 // Transaction types
95 Transaction,
96 TransactionSummary,
97};
98
99// Re-export commonly used external types
100pub use chrono::{DateTime, Utc};
101pub use nonempty::NonEmpty;
102
103// Re-export CloudEvents SDK conversion functions (feature-gated)
104#[cfg(feature = "cloudevents")]
105pub use crate::conversions::events::{
106 cloudevent_to_event, cloudevent_to_prospective_event, event_to_cloudevent,
107 prospective_event_to_cloudevent,
108};