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 crate::api::project::ProjectClient;
use crate::api::project::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: ProjectClient,
}
impl AuthenticatedClient {
    /// Connect with bounded requests; configure credentials before authenticated calls.
    pub fn new(base: &str) -> Result<Self, CallError<ProjectError>> {
        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
    }
    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<ProjectError>> {
        let client =
            ProjectClient::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 Project with the same provisioning and default grants as the legacy API. Requires
    /// Organization create-project permission.
    pub async fn create_project(
        &self,
        request: CreateProjectRequest,
    ) -> Result<CreateProjectResponse, CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.create_project_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Drop a Project with Project drop permission. Existing resource guards must permit deletion.
    pub async fn delete_project(&self, project_id: String) -> Result<(), CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.delete_project_http(auth_header, project_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// List Projects the caller can access, ordered by Project ID. Authorization is evaluated for
    /// every page.
    pub async fn list_projects(
        &self,
        request: ListProjectsRequest,
    ) -> Result<ProjectPage, CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.list_projects_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_projects_list(&self, request: ListProjectsRequest) -> crate::List<'_, Project> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self.list_projects(request).await?;
                Ok(crate::Page {
                    items: page.items,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// Read shared presentation state with Project view permission.
    pub async fn read_presentation(
        &self,
        project_id: String,
        request: PresentationKey,
    ) -> Result<Presentation, CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .read_presentation_http(auth_header, project_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read a Project with Project view permission.
    pub async fn read_project(
        &self,
        project_id: String,
    ) -> Result<Project, CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.read_project_http(auth_header, project_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Save shared presentation state with Catalog publish permission. An outdated revision returns
    /// Conflict.
    pub async fn save_presentation(
        &self,
        project_id: String,
        request: SavePresentation,
    ) -> Result<Presentation, CallError<ProjectError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .save_presentation_http(auth_header, project_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
}