firebase_rs_sdk/database/
on_disconnect.rs

1use serde_json::Value;
2
3use crate::database::error::{internal_error, DatabaseResult};
4use crate::database::DatabaseReference;
5
6/// Placeholder implementation of the Realtime Database `OnDisconnect` API.
7///
8/// Mirrors the surface of the JS SDK (`packages/database/src/api/OnDisconnect.ts`),
9/// but currently returns an error until realtime transports are implemented.
10#[derive(Clone, Debug)]
11pub struct OnDisconnect {
12    reference: DatabaseReference,
13}
14
15impl OnDisconnect {
16    pub(crate) fn new(reference: DatabaseReference) -> Self {
17        Self { reference }
18    }
19
20    /// Schedules a write for when the client disconnects. Not yet implemented.
21    pub fn set(&self, _value: Value) -> DatabaseResult<()> {
22        Err(internal_error(format!(
23            "OnDisconnect operations require realtime transport (path: {})",
24            self.reference.path()
25        )))
26    }
27
28    /// Schedules an update when the client disconnects. Not yet implemented.
29    pub fn update(&self, _updates: Value) -> DatabaseResult<()> {
30        Err(internal_error(format!(
31            "OnDisconnect operations require realtime transport (path: {})",
32            self.reference.path()
33        )))
34    }
35
36    /// Schedules a remove when the client disconnects. Not yet implemented.
37    pub fn remove(&self) -> DatabaseResult<()> {
38        Err(internal_error(format!(
39            "OnDisconnect operations require realtime transport (path: {})",
40            self.reference.path()
41        )))
42    }
43
44    /// Cancels all pending on-disconnect operations. Not yet implemented.
45    pub fn cancel(&self) -> DatabaseResult<()> {
46        Err(internal_error(format!(
47            "OnDisconnect operations require realtime transport (path: {})",
48            self.reference.path()
49        )))
50    }
51}