angzarr_client/traits.rs
1//! Client traits for gateway and query operations.
2//!
3//! These traits define the client API for interacting with angzarr services.
4//! Both standalone (in-process) and distributed (gRPC) modes implement
5//! the same traits, enabling deploy-anywhere client code.
6
7use async_trait::async_trait;
8
9use crate::error::Result;
10use crate::proto::{
11 CommandBook, CommandResponse, EventBook, ProcessManagerHandleResponse, Projection, Query,
12 SagaResponse, SpeculateCommandHandlerRequest, SpeculatePmRequest, SpeculateProjectorRequest,
13 SpeculateSagaRequest,
14};
15
16/// Trait for gateway client operations (command execution).
17///
18/// Implement this trait to create mock clients for testing or
19/// alternative transport implementations.
20#[async_trait]
21pub trait GatewayClient: Send + Sync {
22 /// Execute a command asynchronously (fire and forget).
23 async fn execute(&self, command: CommandBook) -> Result<CommandResponse>;
24}
25
26/// Trait for speculative execution operations.
27///
28/// Supports "what-if" scenarios: executing commands, projectors, sagas,
29/// and process managers without persisting side effects.
30#[async_trait]
31pub trait SpeculativeClient: Send + Sync {
32 /// Execute a command speculatively (no persistence).
33 async fn command_handler(
34 &self,
35 request: SpeculateCommandHandlerRequest,
36 ) -> Result<CommandResponse>;
37
38 /// Speculatively execute a projector against events.
39 async fn projector(&self, request: SpeculateProjectorRequest) -> Result<Projection>;
40
41 /// Speculatively execute a saga against events.
42 async fn saga(&self, request: SpeculateSagaRequest) -> Result<SagaResponse>;
43
44 /// Speculatively execute a process manager against events.
45 async fn process_manager(
46 &self,
47 request: SpeculatePmRequest,
48 ) -> Result<ProcessManagerHandleResponse>;
49}
50
51/// Trait for event query client operations.
52///
53/// Implement this trait to create mock clients for testing or
54/// alternative transport implementations.
55#[async_trait]
56pub trait QueryClient: Send + Sync {
57 /// Get events for the given query.
58 async fn get_events(&self, query: Query) -> Result<EventBook>;
59}