uarp-sdk 0.5.7

Async Rust client for the UARP (Snaga) Universal Agent Runtime Platform API
Documentation
// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
//!
//! KV data explorer for admin diagnostics

#![allow(unused_imports, clippy::too_many_arguments)]

use reqwest::Method;
use serde::{Deserialize, Serialize};
use futures_core::Stream;

use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::pagination::CursorGuard;
use crate::util::encode_path;

/// Query and header parameters for `deleteDataExplorerValue`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DeleteDataExplorerValueParams {
    pub namespace: String,
    pub key: String,
}

/// Query and header parameters for `getDataExplorerValue`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDataExplorerValueParams {
    pub namespace: String,
    pub key: String,
}

/// Query and header parameters for `listDataExplorerKeys`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ListDataExplorerKeysParams {
    pub namespace: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub prefix: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
}

/// KV data explorer for admin diagnostics
#[derive(Debug, Clone)]
pub struct DataExplorerApi {
    pub(crate) client: Client,
}

impl Client {
    /// KV data explorer for admin diagnostics
    pub fn data_explorer(&self) -> DataExplorerApi {
        DataExplorerApi { client: self.clone() }
    }
}

impl DataExplorerApi {
    /// Delete KV value
    ///
    /// `DELETE /api/v1/admin/data-explorer/value`
    ///
    /// Required scopes: `admin`.
    pub async fn delete_data_explorer_value(&self, params: &DeleteDataExplorerValueParams) -> Result<models::DeleteDataExplorerValueResponse> {
        self.client
            .request_json(Request {
                method: Method::DELETE,
                path: "/api/v1/admin/data-explorer/value".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// Get KV value
    ///
    /// `GET /api/v1/admin/data-explorer/value`
    ///
    /// Required scopes: `admin`.
    pub async fn get_data_explorer_value(&self, params: &GetDataExplorerValueParams) -> Result<models::GetDataExplorerValueResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/admin/data-explorer/value".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// List keys
    ///
    /// `GET /api/v1/admin/data-explorer/keys`
    ///
    /// Required scopes: `admin`.
    pub async fn list_data_explorer_keys(&self, params: &ListDataExplorerKeysParams) -> Result<models::ListDataExplorerKeysResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/admin/data-explorer/keys".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Stream every item returned by `listDataExplorerKeys`, following the `cursor` cursor until
    /// the server reports no further pages.
    pub fn list_data_explorer_keys_all<'a>(&'a self, params: &'a ListDataExplorerKeysParams) -> impl Stream<Item = Result<serde_json::Map<String, serde_json::Value>>> + 'a {
        async_stream::try_stream! {
            let mut guard = CursorGuard::new();
            let mut cursor = params.cursor.clone();
            loop {
                let mut page_params = params.clone();
                page_params.cursor = cursor.clone();
                let page = self.list_data_explorer_keys(&page_params).await?;
                let items = page.keys.unwrap_or_default();
                let was_empty = items.is_empty();
                for item in items {
                    yield item;
                }
                match guard.advance(page.cursor, page.has_more, was_empty) {
                    Some(next) => cursor = Some(next),
                    None => break,
                }
            }
        }
    }

    /// List KV namespaces
    ///
    /// `GET /api/v1/admin/data-explorer/namespaces`
    ///
    /// Required scopes: `admin`.
    pub async fn list_data_explorer_namespaces(&self) -> Result<models::ListDataExplorerNamespacesResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/admin/data-explorer/namespaces".to_string(),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Set KV value
    ///
    /// `PUT /api/v1/admin/data-explorer/value`
    ///
    /// Required scopes: `admin`.
    pub async fn set_data_explorer_value(&self, body: &models::SetDataExplorerValueRequest) -> Result<models::SetDataExplorerValueResponse> {
        self.client
            .request_json(Request {
                method: Method::PUT,
                path: "/api/v1/admin/data-explorer/value".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }
}