Skip to main content

orpc_client/
link.rs

1use std::future::Future;
2use std::pin::Pin;
3
4use futures_core::Stream;
5
6use crate::error::ClientError;
7
8/// A boxed stream of JSON values, used by [`Link::subscribe`].
9pub type ValueStream = Pin<Box<dyn Stream<Item = Result<serde_json::Value, ClientError>> + Send>>;
10
11/// Transport abstraction for oRPC client calls.
12///
13/// Mirrors the TypeScript `Link` interface from `@orpc/client`.
14/// Implementors handle the actual HTTP (or IPC) communication.
15///
16/// Use [`RpcLink`](crate::RpcLink) for the standard HTTP RPC transport.
17pub trait Link: Send + Sync {
18    /// Execute a single-value RPC call (query or mutation).
19    fn call(
20        &self,
21        path: &str,
22        input: serde_json::Value,
23    ) -> impl Future<Output = Result<serde_json::Value, ClientError>> + Send;
24
25    /// Execute a subscription RPC call, returning an SSE stream of values.
26    ///
27    /// If `last_event_id` is provided, the server resumes from that event
28    /// (SSE reconnection via `Last-Event-ID` header).
29    fn subscribe(
30        &self,
31        path: &str,
32        input: serde_json::Value,
33        last_event_id: Option<u64>,
34    ) -> impl Future<Output = Result<ValueStream, ClientError>> + Send;
35}