areev 0.2.0

Rust SDK for the Areev knowledge database — gRPC and HTTP transports
Documentation
//! `Preferences` resource — per-principal key/value UI/runtime
//! preferences.
//!
//! Mirrors the Python SDK's `client.preferences.*` surface. These are
//! org/user-scoped, not memory-scoped.

use serde_json::{json, Value};

use crate::error::Result;
use crate::http::HttpClient;

/// Preference key/value store.
///
/// Access via [`crate::Areev::preferences`].
pub struct Preferences<'a> {
    http: &'a HttpClient,
}

impl<'a> Preferences<'a> {
    /// Internal constructor — use [`crate::Areev::preferences`].
    pub(crate) fn new(http: &'a HttpClient) -> Self {
        Self { http }
    }

    /// All preferences for the calling principal.
    pub async fn list(&self) -> Result<Value> {
        self.http._get("/preferences", None).await
    }

    /// Read one preference by key.
    pub async fn get(&self, key: &str) -> Result<Value> {
        let path = format!("/preferences/{key}");
        self.http._get(&path, None).await
    }

    /// Upsert one or more preference key/values.
    pub async fn update(&self, preferences: Value) -> Result<Value> {
        let body = json!({ "preferences": preferences });
        self.http._put("/preferences", Some(&body)).await
    }

    /// Delete one preference by key.
    pub async fn delete(&self, key: &str) -> Result<()> {
        let path = format!("/preferences/{key}");
        self.http._delete(&path).await.map(|_| ())
    }
}