firebase_wasm/firestore/
bindings.rs1use wasm_bindgen::prelude::*;
2
3use crate::FirebaseError;
4
5#[derive(Clone, Copy, Debug, Default)]
6#[wasm_bindgen(getter_with_clone)]
7pub struct SetDocOptions {
8 pub merge: Option<bool>,
9}
10
11#[wasm_bindgen(module = "firebase/firestore")]
12extern "C" {
13 #[derive(Clone, Debug)]
14 pub type Firestore;
15 #[derive(Clone, Debug)]
16 pub type DocumentReference;
17 #[derive(Clone, Debug)]
18 pub type CollectionReference;
19 #[derive(Clone, Debug)]
20 pub type DocumentSnapshot;
21 #[derive(Clone, Debug)]
22 pub type Query;
23 #[derive(Clone, Debug)]
24 pub type QuerySnapshot;
25 #[derive(Clone, Debug)]
26 pub type QueryConstraint;
27 #[derive(Clone, Debug)]
28 pub type Transaction;
29
30 #[wasm_bindgen(js_name = getFirestore)]
31 pub fn get_firestore() -> Firestore;
32
33 #[wasm_bindgen(catch)]
34 pub fn doc(firestore: Firestore, path: &str) -> Result<DocumentReference, JsValue>;
35
36 #[wasm_bindgen(js_name = getDoc, catch)]
37 pub async fn get_doc(doc: DocumentReference) -> Result<JsValue, JsValue>;
38
39 #[wasm_bindgen(js_name = getDocs, catch)]
40 pub async fn get_docs(query: Query) -> Result<JsValue, JsValue>;
41
42 #[wasm_bindgen(js_name = "setDoc", catch)]
43 pub async fn set_doc(doc: DocumentReference, data: JsValue) -> Result<(), JsValue>;
44
45 #[wasm_bindgen(js_name = "setDoc", catch)]
46 pub async fn set_doc_with_options(
47 doc: DocumentReference,
48 data: JsValue,
49 options: SetDocOptions,
50 ) -> Result<(), JsValue>;
51
52 #[wasm_bindgen(catch)]
53 pub fn collection(
54 firestore: Firestore,
55 path: &str,
56 ) -> Result<CollectionReference, FirebaseError>;
57
58 #[wasm_bindgen(js_name = onSnapshot)]
59 pub fn on_snapshot_doc(
60 reference: DocumentReference,
61 observer: &Closure<dyn FnMut(DocumentSnapshot)>,
62 ) -> js_sys::Function;
63
64 #[wasm_bindgen(js_name = onSnapshot)]
65 pub fn on_snapshot_query(
66 query: Query,
67 observer: &Closure<dyn FnMut(QuerySnapshot)>,
68 ) -> js_sys::Function;
69
70 #[wasm_bindgen(variadic)]
71 pub fn query(collection: CollectionReference, constraints: Vec<QueryConstraint>) -> Query;
72
73 #[wasm_bindgen(js_name = "where")]
74 pub fn where_(field_path: &str, op_str: &str, value: JsValue) -> QueryConstraint;
75
76 #[wasm_bindgen(js_name = deleteDoc, catch)]
77 pub async fn delete_doc(doc: DocumentReference) -> Result<(), JsValue>;
78
79 #[wasm_bindgen(js_name = runTransaction, catch)]
80 pub async fn run_transaction(
81 firestore: Firestore,
82 update_fn: &Closure<dyn FnMut(Transaction) -> js_sys::Promise>,
83 ) -> Result<(), JsValue>;
84
85 #[wasm_bindgen(method, getter)]
90 pub fn empty(this: &QuerySnapshot) -> bool;
91
92 #[wasm_bindgen(method, getter)]
93 pub fn size(this: &QuerySnapshot) -> usize;
94
95 #[wasm_bindgen(method, getter)]
96 pub fn docs(this: &QuerySnapshot) -> Vec<DocumentSnapshot>;
97
98 #[wasm_bindgen(method)]
103 pub fn exists(this: &DocumentSnapshot) -> bool;
104
105 #[wasm_bindgen(method)]
106 pub fn data(this: &DocumentSnapshot) -> JsValue;
107
108 #[wasm_bindgen(method, getter)]
109 pub fn id(this: &DocumentSnapshot) -> String;
110
111 #[wasm_bindgen(method, js_name = "ref")]
112 pub fn ref_(this: &DocumentSnapshot) -> DocumentReference;
113
114 #[wasm_bindgen(method, catch, js_name = get)]
119 pub(crate) async fn get_js(
120 this: &Transaction,
121 doc: DocumentReference,
122 ) -> Result<JsValue, JsValue>;
123
124 #[wasm_bindgen(method, js_name = set, catch)]
125 pub(crate) fn set_js(
126 this: &Transaction,
127 doc: DocumentReference,
128 data: JsValue,
129 ) -> Result<Transaction, FirebaseError>;
130
131 #[wasm_bindgen(method, js_name = update, catch)]
132 pub(crate) fn update_js(
133 this: &Transaction,
134 doc: DocumentReference,
135 data: JsValue,
136 ) -> Result<Transaction, FirebaseError>;
137
138 #[wasm_bindgen(method, js_name = delete, catch)]
139 pub(crate) fn delete_js(
140 this: &Transaction,
141 doc: DocumentReference,
142 ) -> Result<Transaction, FirebaseError>;
143}