firebase_rs_sdk/firestore/api/
operations.rs1use std::collections::BTreeMap;
2
3use crate::firestore::error::FirestoreResult;
4use crate::firestore::model::DocumentKey;
5use crate::firestore::value::{FirestoreValue, MapValue};
6
7#[derive(Clone, Debug, Default)]
9pub struct SetOptions {
10 pub merge: bool,
14}
15
16#[allow(dead_code)]
17pub fn encode_document_data(data: BTreeMap<String, FirestoreValue>) -> FirestoreResult<MapValue> {
18 Ok(MapValue::new(data))
19}
20
21#[allow(dead_code)]
22pub fn validate_document_path(path: &str) -> FirestoreResult<DocumentKey> {
23 let key = DocumentKey::from_string(path)?;
24 Ok(key)
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::firestore::api::snapshot::{DocumentSnapshot, SnapshotMetadata};
31
32 #[test]
33 fn snapshot_presence() {
34 let key = DocumentKey::from_string("coll/doc").unwrap();
35 let snapshot = DocumentSnapshot::new(key, None, SnapshotMetadata::default());
36 assert!(!snapshot.exists());
37 }
38
39 #[test]
40 fn map_encodes() {
41 let mut data = BTreeMap::new();
42 data.insert("name".to_string(), FirestoreValue::from_string("Ada"));
43 let map = encode_document_data(data).unwrap();
44 assert!(map.fields().contains_key("name"));
45 }
46}