Skip to main content

bitwarden_uniffi/
debug.rs

1//! UniFFI surface for the dev-only debug-capability tree.
2//!
3//! Wraps the debug tree composed in `bitwarden-pm` as uniffi objects, the same
4//! way the other binding clients here wrap their pm sub-clients. Compiled only
5//! under the `debug-capabilities` feature.
6
7/// UniFFI wrapper for the debug-tree root.
8#[derive(uniffi::Object)]
9pub struct DebugClient(pub(crate) bitwarden_pm::debug::DebugClient);
10
11#[uniffi::export]
12impl DebugClient {
13    /// Persisted-state debug capabilities.
14    pub fn state(&self) -> StateDebug {
15        StateDebug(self.0.state())
16    }
17}
18
19/// UniFFI wrapper for the state-registry debug handle.
20#[derive(uniffi::Object)]
21pub struct StateDebug(pub(crate) bitwarden_state::debug::StateDebug);
22
23#[uniffi::export(async_runtime = "tokio")]
24impl StateDebug {
25    /// Names of every registered repository (client- and SDK-managed).
26    pub fn types(&self) -> Vec<String> {
27        self.0.types()
28    }
29
30    /// List a repository's values as a JSON-array string, addressed by type name.
31    /// Values only (no keys).
32    pub async fn list(&self, type_name: String) -> String {
33        self.0.list(type_name).await
34    }
35
36    /// Read one item by type name and string key, as a JSON string (`"null"` if
37    /// absent).
38    pub async fn get(&self, type_name: String, key: String) -> String {
39        self.0.get(type_name, key).await
40    }
41
42    /// Write one item by type name and string key. Returns `true` if the write
43    /// landed, so a caller can tell a no-op from a write.
44    pub async fn set(&self, type_name: String, key: String, value: String) -> bool {
45        self.0.set(type_name, key, value).await
46    }
47}