diff --git a/src/BsFirebase.re b/src/BsFirebase.re index c04a925..4274810 100644 --- a/src/BsFirebase.re +++ b/src/BsFirebase.re @@ -4,10 +4,10 @@ type firebaseConfig; module Auth = BsFirebase__Auth; module Firestore = BsFirebase__Firestore; -[@bs.module] external firebase: firebase = "firebase"; +[@bs.module] external firebase: firebase = "firebase/app"; [@bs.send] external initializeApp: (firebase, firebaseConfig) => unit = "initializeApp"; -[@bs.send] external auth: (firebase, unit) => Auth.t = "auth"; -[@bs.send] external firestore: (firebase, unit) => Firestore.t = "firestore"; \ No newline at end of file +[@bs.send] external auth: firebase => Auth.t = "auth"; +[@bs.send] external firestore: firebase => Firestore.t = "firestore"; \ No newline at end of file diff --git a/src/BsFirebase.rei b/src/BsFirebase.rei index c04a925..4274810 100644 --- a/src/BsFirebase.rei +++ b/src/BsFirebase.rei @@ -4,10 +4,10 @@ type firebaseConfig; module Auth = BsFirebase__Auth; module Firestore = BsFirebase__Firestore; -[@bs.module] external firebase: firebase = "firebase"; +[@bs.module] external firebase: firebase = "firebase/app"; [@bs.send] external initializeApp: (firebase, firebaseConfig) => unit = "initializeApp"; -[@bs.send] external auth: (firebase, unit) => Auth.t = "auth"; -[@bs.send] external firestore: (firebase, unit) => Firestore.t = "firestore"; \ No newline at end of file +[@bs.send] external auth: firebase => Auth.t = "auth"; +[@bs.send] external firestore: firebase => Firestore.t = "firestore"; \ No newline at end of file diff --git a/src/BsFirebase__Auth.re b/src/BsFirebase__Auth.re index 5604fa2..d5cb0c6 100644 --- a/src/BsFirebase__Auth.re +++ b/src/BsFirebase__Auth.re @@ -1,5 +1,7 @@ type t; +[@bs.module] external require: t = "firebase/auth"; + module User = { type t; @@ -65,6 +67,9 @@ module Provider = { external twitter: unit => t = "TwitterAuthProvider"; }; +[@bs.send] +external signInAnonymously: t => Js.Promise.t(Result.t) = "signInAnonymously"; + [@bs.send] external signInWithEmailAndPassword: (t, ~email: string, ~password: string) => Js.Promise.t(Result.t) = @@ -78,4 +83,6 @@ external signInWithPopup: (t, Provider.t) => Js.Promise.t(Result.t) = external onAuthStateChanged: (t, Js.Nullable.t(User.t) => unit) => unit = "onAuthStateChanged"; -[@bs.send] external signOut: (t, unit) => unit = "signOut"; \ No newline at end of file +[@bs.send] external signOut: (t, unit) => unit = "signOut"; + +[@bs.get] external currentUser: t => User.t = "currentUser"; \ No newline at end of file diff --git a/src/BsFirebase__Firestore.re b/src/BsFirebase__Firestore.re index 5a9b2a0..610f881 100644 --- a/src/BsFirebase__Firestore.re +++ b/src/BsFirebase__Firestore.re @@ -1,6 +1,6 @@ type t; -module DocRef = { +module DocSnapshot = { type t; [@bs.get] external exists: t => bool = "exists"; @@ -11,28 +11,29 @@ module DocRef = { module QuerySnapshot = { type t; - [@bs.get] external docs: t => array(DocRef.t) = "docs"; + [@bs.get] external docs: t => array(DocSnapshot.t) = "docs"; + [@bs.get] external size: t => int = "size"; }; module Collection = { type t; - module Doc = { + module DocRef = { type t; [@bs.deriving abstract] type setOptions = {merge: bool}; - [@bs.send] external get: (t, unit) => Js.Promise.t(DocRef.t) = "get"; + [@bs.send] external get: (t, unit) => Js.Promise.t(DocSnapshot.t) = "get"; [@bs.send] external delete: (t, unit) => Js.Promise.t(unit) = "delete"; [@bs.send] - external set: (t, 'a, ~options: setOptions=?) => Js.Promise.t(unit) = + external set: (t, 'a, ~options: setOptions=?, unit) => Js.Promise.t(unit) = "set"; }; [@bs.send] external add: (t, 'a) => Js.Promise.t(DocRef.t) = "add"; [@bs.send] external get: (t, unit) => Js.Promise.t(QuerySnapshot.t) = "get"; - [@bs.send] external doc: (t, string) => Doc.t = "doc"; + [@bs.send] external doc: (t, string) => DocRef.t = "doc"; [@bs.send] external where: ( @@ -54,4 +55,19 @@ module Collection = { [@bs.module] external require: t = "firebase/firestore"; -[@bs.send] external collection: (t, string) => Collection.t = "collection"; \ No newline at end of file +[@bs.send] external collection: (t, string) => Collection.t = "collection"; + +module Transaction = { + type firestore = t; + type t; + + type updateFunction('a) = t => Js.Promise.t('a); + + [@bs.send] external get: (t, Collection.DocRef.t) => Js.Promise.t(DocSnapshot.t) = "get"; + [@bs.send] external update: (t, Collection.DocRef.t, 'a) => t = "update"; + [@bs.send] external set: (t, Collection.DocRef.t, 'a, ~options: Collection.DocRef.setOptions=?, unit) => t = "set"; + [@bs.send] external delete: (t, Collection.DocRef.t) => t = "delete"; +} + + +[@bs.send] external runTransaction: (t, Transaction.updateFunction('a)) => Js.Promise.t('a) = "runTransaction"; \ No newline at end of file