spiral-sdk 0.1.10

Rust SDK for Spiral resource and table APIs
Documentation
// Generated by tools/service-contracts/rust.py. Do not edit.
#![doc = "Generated implementation of authenticated SDK resource facades."]
use spiral_contract::call::CallError;
use uuid::Uuid;

use crate::api::locations::LocationsClient;
use crate::api::locations::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
/// Service operations sharing a connection pool and resolving credentials for every request.
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
    http: HttpClient,
    client: LocationsClient,
}
impl AuthenticatedClient {
    /// Connect with bounded requests; configure credentials before authenticated calls.
    pub fn new(base: &str) -> Result<Self, CallError<LocationsError>> {
        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
    }
    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<LocationsError>> {
        let client =
            LocationsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
        Ok(Self { http, client })
    }
    /// Reuse a connection pool with redirects disabled to protect bearer credentials.
    pub fn with_client(mut self, client: reqwest::Client) -> Self {
        self.http = self.http.with_client(client);
        self.client = self.client.with_transport(self.http.middleware_client());
        self
    }
    /// Resolve the provider's current credential before each request and pagination fetch.
    pub fn with_token_source(mut self, provider: TokenSource) -> Self {
        self.http = self.http.with_token_source(provider);
        self
    }
    /// Create a Location and its initial immutable version. The inventory must be an existing Table
    /// in the Project.
    pub async fn create_location(
        &self,
        request: CreateLocationRequest,
    ) -> Result<CreateLocationResponse, CallError<LocationsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.create_location_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Create or recover an immutable successor. Use the same caller-allocated version UUIDv7 when
    /// retrying.
    pub async fn create_version(
        &self,
        location_id: Uuid,
        request: CreateVersionRequest,
    ) -> Result<VersionResponse, CallError<LocationsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .create_version_http(auth_header, location_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read one exact immutable Location version.
    pub async fn read_version(
        &self,
        location_id: Uuid,
        version_id: Uuid,
    ) -> Result<VersionResponse, CallError<LocationsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .read_version_http(auth_header, location_id, version_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Obtain renewable storage access for one exact Location version.
    pub async fn storage_binding(
        &self,
        location_id: Uuid,
        version_id: Uuid,
    ) -> Result<StorageBinding, CallError<LocationsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .storage_binding_http(auth_header, location_id, version_id),
        )
        .await
        .map_err(CallError::transport)?
    }
}