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::vector_indexes::VectorIndexesClient;
use crate::api::vector_indexes::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: VectorIndexesClient,
}
impl AuthenticatedClient {
    /// Connect with bounded requests; configure credentials before authenticated calls.
    pub fn new(base: &str) -> Result<Self, CallError<VectorIndexesError>> {
        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
    }
    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<VectorIndexesError>> {
        let client = VectorIndexesClient::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
    }
    /// Begin an immutable build version for an exact source Table version.
    pub async fn begin_version(
        &self,
        vector_index_id: Uuid,
        request: BeginVersionRequest,
    ) -> Result<BeginVersionResponse, CallError<VectorIndexesError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .begin_version_http(auth_header, vector_index_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Create a Vector Index and its initial definition-only version.
    pub async fn create_vector_index(
        &self,
        request: CreateVectorIndexRequest,
    ) -> Result<CreateVectorIndexResponse, CallError<VectorIndexesError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.create_vector_index_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read the definition and exact immutable version.
    pub async fn read_version(
        &self,
        vector_index_id: Uuid,
        version_id: Uuid,
    ) -> Result<ReadVersionResponse, CallError<VectorIndexesError>> {
        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, vector_index_id, version_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Create an immutable definition successor without inherited build state.
    pub async fn revise_definition(
        &self,
        vector_index_id: Uuid,
        request: ReviseDefinitionRequest,
    ) -> Result<ReadVersionResponse, CallError<VectorIndexesError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .revise_definition_http(auth_header, vector_index_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Seal a build with structurally validated codec-owned physical state.
    pub async fn seal_version(
        &self,
        vector_index_id: Uuid,
        version_id: Uuid,
        request: SealVersionRequest,
    ) -> Result<VersionResponse, CallError<VectorIndexesError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .seal_version_http(auth_header, vector_index_id, version_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Obtain short-lived access to one version directory.
    pub async fn storage_access(
        &self,
        vector_index_id: Uuid,
        request: StorageAccessRequest,
    ) -> Result<StorageAccessResponse, CallError<VectorIndexesError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .storage_access_http(auth_header, vector_index_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Obtain renewable typed storage access to one version directory.
    pub async fn storage_binding(
        &self,
        vector_index_id: Uuid,
        request: StorageAccessRequest,
    ) -> Result<StorageBinding, CallError<VectorIndexesError>> {
        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, vector_index_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
}