Last active
December 31, 2017 16:48
-
-
Save jeremyabbott/4ded43fc12f1f20314d20398e9b4c4ed to your computer and use it in GitHub Desktop.
Firebase bindings for Fable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ts2fable 0.5.2 | |
module rec Firebase | |
open System | |
open Fable.Core | |
open Fable.Import.JS | |
type [<AllowNullLiteral>] IExports = | |
abstract EmailAuthProvider: EmailAuthProviderStatic | |
abstract EmailAuthProvider_Instance: EmailAuthProvider_InstanceStatic | |
abstract FacebookAuthProvider: FacebookAuthProviderStatic | |
abstract FacebookAuthProvider_Instance: FacebookAuthProvider_InstanceStatic | |
abstract GithubAuthProvider: GithubAuthProviderStatic | |
abstract GithubAuthProvider_Instance: GithubAuthProvider_InstanceStatic | |
abstract GoogleAuthProvider: GoogleAuthProviderStatic | |
abstract GoogleAuthProvider_Instance: GoogleAuthProvider_InstanceStatic | |
abstract OAuthProvider: OAuthProviderStatic | |
abstract PhoneAuthProvider: PhoneAuthProviderStatic | |
abstract PhoneAuthProvider_Instance: PhoneAuthProvider_InstanceStatic | |
abstract RecaptchaVerifier: RecaptchaVerifierStatic | |
abstract RecaptchaVerifier_Instance: RecaptchaVerifier_InstanceStatic | |
abstract TwitterAuthProvider: TwitterAuthProviderStatic | |
abstract TwitterAuthProvider_Instance: TwitterAuthProvider_InstanceStatic | |
abstract FirebaseAuth: FirebaseAuthStatic | |
/// <summary>Helper to make a Subscribe function (just like Promise helps make a | |
/// Thenable).</summary> | |
/// <param name="executor">Function which can make calls to a single Observer | |
/// as a proxy.</param> | |
/// <param name="onNoObservers">Callback when count of Observers goes to zero.</param> | |
abstract createSubscribe: executor: Executor<'T> * ?onNoObservers: Executor<'T> -> Subscribe<'T> | |
/// Turn synchronous function into one called asynchronously. | |
abstract async: fn: Function * ?onError: ErrorFn -> Function | |
type FirebaseOptions = { | |
apiKey: string | |
authDomain: string | |
databaseURL: string | |
projectId: string | |
storageBucket: string | |
messagingSenderId : string | |
} | |
type [<AllowNullLiteral>] FirebaseApp = | |
/// The (read-only) name (identifier) for this App. '[DEFAULT]' is the default | |
/// App. | |
abstract name: string with get, set | |
/// The (read-only) configuration options from the app initialization. | |
abstract options: FirebaseOptions with get, set | |
/// Make the given App unusable and free resources. | |
abstract delete: unit -> Promise<unit> | |
type [<AllowNullLiteral>] FirebaseAppStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> FirebaseApp | |
type [<AllowNullLiteral>] FirebaseNamespace = | |
/// <summary>Create (and intialize) a FirebaseApp.</summary> | |
/// <param name="options">Options to configure the services used in the App.</param> | |
/// <param name="name">The optional name of the app to initialize ('[DEFAULT]' if | |
/// omitted)</param> | |
abstract initializeApp: options: FirebaseOptions * ?name: string -> FirebaseApp | |
abstract app: FirebaseApp with get, set | |
/// A (read-only) array of all the initialized Apps. | |
abstract apps: ResizeArray<FirebaseApp> with get, set | |
abstract Promise: obj with get, set | |
abstract SDK_VERSION: string with get, set | |
//abstract auth: FirebaseAuth option with get, set | |
abstract auth: ?app: FirebaseApp -> FirebaseAuth | |
/// <summary>Helper to make a Subscribe function (just like Promise helps make a | |
/// Thenable).</summary> | |
/// <param name="executor">Function which can make calls to a single Observer | |
/// as a proxy.</param> | |
/// <param name="onNoObservers">Callback when count of Observers goes to zero.</param> | |
abstract createSubscribe: executor: Executor<'T> * ?onNoObservers: Executor<'T> -> Subscribe<'T> | |
/// Turn synchronous function into one called asynchronously. | |
abstract async: fn: Function * ?onError: ErrorFn -> Function | |
type [<AllowNullLiteral>] User = | |
inherit UserInfo | |
abstract delete: unit -> Promise<obj option> | |
abstract emailVerified: bool with get, set | |
abstract getIdToken: ?forceRefresh: bool -> Promise<obj option> | |
abstract getToken: ?forceRefresh: bool -> Promise<obj option> | |
abstract isAnonymous: bool with get, set | |
abstract linkAndRetrieveDataWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract linkWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract linkWithPhoneNumber: phoneNumber: string * applicationVerifier: ApplicationVerifier -> Promise<obj option> | |
abstract linkWithPopup: provider: AuthProvider -> Promise<obj option> | |
abstract linkWithRedirect: provider: AuthProvider -> Promise<obj option> | |
abstract metadata: UserMetadata with get, set | |
abstract phoneNumber: string option with get, set | |
abstract providerData: ResizeArray<UserInfo option> with get, set | |
abstract reauthenticateAndRetrieveDataWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract reauthenticateWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract reauthenticateWithPhoneNumber: phoneNumber: string * applicationVerifier: ApplicationVerifier -> Promise<obj option> | |
abstract reauthenticateWithPopup: provider: AuthProvider -> Promise<obj option> | |
abstract reauthenticateWithRedirect: provider: AuthProvider -> Promise<obj option> | |
abstract refreshToken: string with get, set | |
abstract reload: unit -> Promise<obj option> | |
abstract sendEmailVerification: ?actionCodeSettings: ActionCodeSettings option -> Promise<obj option> | |
abstract toJSON: unit -> Object | |
abstract unlink: providerId: string -> Promise<obj option> | |
abstract updateEmail: newEmail: string -> Promise<obj option> | |
abstract updatePassword: newPassword: string -> Promise<obj option> | |
abstract updatePhoneNumber: phoneCredential: AuthCredential -> Promise<obj option> | |
abstract updateProfile: profile: UserUpdateProfileProfile -> Promise<obj option> | |
type [<AllowNullLiteral>] UserUpdateProfileProfile = | |
abstract displayName: string option with get, set | |
abstract photoURL: string option with get, set | |
type [<AllowNullLiteral>] UserInfo = | |
abstract displayName: string option with get, set | |
abstract email: string option with get, set | |
abstract phoneNumber: string option with get, set | |
abstract photoURL: string option with get, set | |
abstract providerId: string with get, set | |
abstract uid: string with get, set | |
type [<AllowNullLiteral>] ActionCodeInfo = interface end | |
type ActionCodeSettings = obj | |
type AdditionalUserInfo = obj | |
type [<AllowNullLiteral>] ApplicationVerifier = | |
abstract ``type``: string with get, set | |
abstract verify: unit -> Promise<obj option> | |
type [<AllowNullLiteral>] AuthCredential = | |
abstract providerId: string with get, set | |
type [<AllowNullLiteral>] AuthProvider = | |
abstract providerId: string with get, set | |
type [<AllowNullLiteral>] ConfirmationResult = | |
abstract confirm: verificationCode: string -> Promise<obj option> | |
abstract verificationId: string with get, set | |
type [<AllowNullLiteral>] EmailAuthProvider = | |
inherit EmailAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] EmailAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> EmailAuthProvider | |
abstract credential: email: string * password: string -> AuthCredential | |
type [<AllowNullLiteral>] EmailAuthProvider_Instance = | |
inherit AuthProvider | |
abstract providerId: string with get, set | |
type [<AllowNullLiteral>] EmailAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> EmailAuthProvider_Instance | |
type [<AllowNullLiteral>] Error = | |
abstract code: string with get, set | |
abstract message: string with get, set | |
type [<AllowNullLiteral>] FacebookAuthProvider = | |
inherit FacebookAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] FacebookAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> FacebookAuthProvider | |
abstract credential: token: string -> AuthCredential | |
type [<AllowNullLiteral>] FacebookAuthProvider_Instance = | |
inherit AuthProvider | |
abstract addScope: scope: string -> AuthProvider | |
abstract providerId: string with get, set | |
abstract setCustomParameters: customOAuthParameters: Object -> AuthProvider | |
type [<AllowNullLiteral>] FacebookAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> FacebookAuthProvider_Instance | |
type [<AllowNullLiteral>] GithubAuthProvider = | |
inherit GithubAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] GithubAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> GithubAuthProvider | |
abstract credential: token: string -> AuthCredential | |
type [<AllowNullLiteral>] GithubAuthProvider_Instance = | |
inherit AuthProvider | |
abstract addScope: scope: string -> AuthProvider | |
abstract providerId: string with get, set | |
abstract setCustomParameters: customOAuthParameters: Object -> AuthProvider | |
type [<AllowNullLiteral>] GithubAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> GithubAuthProvider_Instance | |
type [<AllowNullLiteral>] GoogleAuthProvider = | |
inherit GoogleAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] GoogleAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> GoogleAuthProvider | |
abstract credential: ?idToken: string option * ?accessToken: string option -> AuthCredential | |
type [<AllowNullLiteral>] GoogleAuthProvider_Instance = | |
inherit AuthProvider | |
abstract addScope: scope: string -> AuthProvider | |
abstract providerId: string with get, set | |
abstract setCustomParameters: customOAuthParameters: Object -> AuthProvider | |
type [<AllowNullLiteral>] GoogleAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> GoogleAuthProvider_Instance | |
type [<AllowNullLiteral>] OAuthProvider = | |
inherit AuthProvider | |
abstract providerId: string with get, set | |
abstract addScope: scope: string -> AuthProvider | |
abstract credential: ?idToken: string * ?accessToken: string -> OAuthCredential | |
abstract setCustomParameters: customOAuthParameters: Object -> AuthProvider | |
type [<AllowNullLiteral>] OAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> OAuthProvider | |
type [<AllowNullLiteral>] PhoneAuthProvider = | |
inherit PhoneAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] PhoneAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> PhoneAuthProvider | |
abstract credential: verificationId: string * verificationCode: string -> AuthCredential | |
type [<AllowNullLiteral>] PhoneAuthProvider_Instance = | |
inherit AuthProvider | |
abstract providerId: string with get, set | |
abstract verifyPhoneNumber: phoneNumber: string * applicationVerifier: ApplicationVerifier -> Promise<obj option> | |
type [<AllowNullLiteral>] PhoneAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: ?auth: FirebaseAuth option -> PhoneAuthProvider_Instance | |
type [<AllowNullLiteral>] RecaptchaVerifier = | |
inherit RecaptchaVerifier_Instance | |
type [<AllowNullLiteral>] RecaptchaVerifierStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> RecaptchaVerifier | |
type [<AllowNullLiteral>] RecaptchaVerifier_Instance = | |
inherit ApplicationVerifier | |
abstract clear: unit -> obj option | |
abstract render: unit -> Promise<obj option> | |
abstract ``type``: string with get, set | |
abstract verify: unit -> Promise<obj option> | |
type [<AllowNullLiteral>] RecaptchaVerifier_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: container: U2<obj option, string> * ?parameters: Object option * ?app: FirebaseApp option -> RecaptchaVerifier_Instance | |
type [<AllowNullLiteral>] TwitterAuthProvider = | |
inherit TwitterAuthProvider_Instance | |
abstract PROVIDER_ID: string with get, set | |
type [<AllowNullLiteral>] TwitterAuthProviderStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> TwitterAuthProvider | |
abstract credential: token: string * secret: string -> AuthCredential | |
type [<AllowNullLiteral>] TwitterAuthProvider_Instance = | |
inherit AuthProvider | |
abstract providerId: string with get, set | |
abstract setCustomParameters: customOAuthParameters: Object -> AuthProvider | |
type [<AllowNullLiteral>] TwitterAuthProvider_InstanceStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> TwitterAuthProvider_Instance | |
type UserCredential = | |
obj | |
type [<AllowNullLiteral>] UserMetadata = | |
abstract creationTime: string option with get, set | |
abstract lastSignInTime: string option with get, set | |
type Persistence = | |
string | |
type [<AllowNullLiteral>] OAuthCredential = | |
inherit AuthCredential | |
abstract idToken: string option with get, set | |
abstract accessToken: string option with get, set | |
abstract secret: string option with get, set | |
type [<AllowNullLiteral>] FirebaseAuth = | |
abstract Persistence: obj with get, set | |
abstract app: FirebaseApp with get, set | |
abstract applyActionCode: code: string -> Promise<obj option> | |
abstract checkActionCode: code: string -> Promise<obj option> | |
abstract confirmPasswordReset: code: string * newPassword: string -> Promise<obj option> | |
abstract createUserWithEmailAndPassword: email: string * password: string -> Promise<User option> | |
abstract createUserAndRetrieveDataWithEmailAndPassword: email: string * password: string -> Promise<obj option> | |
abstract currentUser: User option with get, set | |
abstract fetchProvidersForEmail: email: string -> Promise<obj option> | |
abstract getRedirectResult: unit -> Promise<obj option> | |
abstract languageCode: string option with get, set | |
abstract onAuthStateChanged: nextOrObserver: U2<Observer<obj option, obj option>, (User option -> obj option)> * ?error: (Error -> obj option) * ?completed: Unsubscribe -> Unsubscribe | |
abstract onIdTokenChanged: nextOrObserver: U2<Observer<obj option, obj option>, (User option -> obj option)> * ?error: (Error -> obj option) * ?completed: Unsubscribe -> Unsubscribe | |
abstract sendPasswordResetEmail: email: string * ?actionCodeSettings: ActionCodeSettings option -> Promise<obj option> | |
abstract setPersistence: persistence: Persistence -> Promise<obj option> | |
abstract signInAndRetrieveDataWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract signInAnonymously: unit -> Promise<obj option> | |
abstract signInAnonymouslyAndRetrieveData: unit -> Promise<obj option> | |
abstract signInWithCredential: credential: AuthCredential -> Promise<obj option> | |
abstract signInWithCustomToken: token: string -> Promise<obj option> | |
abstract signInAndRetrieveDataWithCustomToken: token: string -> Promise<obj option> | |
abstract signInWithEmailAndPassword: email: string * password: string -> Promise<obj option> | |
abstract signInAndRetrieveDataWithEmailAndPassword: email: string * password: string -> Promise<obj option> | |
abstract signInWithPhoneNumber: phoneNumber: string * applicationVerifier: ApplicationVerifier -> Promise<obj option> | |
abstract signInWithPopup: provider: AuthProvider -> Promise<obj option> | |
abstract signInWithRedirect: provider: AuthProvider -> Promise<obj option> | |
abstract signOut: unit -> Promise<obj option> | |
abstract useDeviceLanguage: unit -> obj option | |
abstract verifyPasswordResetCode: code: string -> Promise<obj option> | |
type [<AllowNullLiteral>] FirebaseAuthStatic = | |
[<Emit "new $0($1...)">] abstract Create: unit -> FirebaseAuth | |
// Firebase Util | |
type NextFn<'T> = | |
('T -> unit) | |
type ErrorFn = | |
(Error -> unit) | |
type CompleteFn = | |
(unit -> unit) | |
type [<AllowNullLiteral>] Observer<'V, 'E> = | |
abstract next: value: 'V option -> obj option | |
abstract error: error: 'E -> obj option | |
abstract complete: unit -> obj option | |
type [<AllowNullLiteral>] PartialObserver<'T> = | |
abstract next: NextFn<'T> option with get, set | |
abstract error: ErrorFn option with get, set | |
abstract complete: CompleteFn option with get, set | |
type Unsubscribe = | |
(unit -> unit) | |
/// The Subscribe interface has two forms - passing the inline function | |
/// callbacks, or a object interface with callback properties. | |
type [<AllowNullLiteral>] Subscribe<'T> = | |
[<Emit "$0($1...)">] abstract Invoke: ?next: NextFn<'T> * ?error: ErrorFn * ?complete: CompleteFn -> Unsubscribe | |
[<Emit "$0($1...)">] abstract Invoke: observer: PartialObserver<'T> -> Unsubscribe | |
type [<AllowNullLiteral>] Observable<'T> = | |
abstract subscribe: Subscribe<'T> with get, set | |
type Executor<'T> = | |
(Observer<'T, Error> -> unit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FirebaseFable | |
open Fable.Core | |
open Fable.Core.JsInterop | |
open Fable.Import | |
open Firebase | |
open Fable.PowerPack | |
let config = | |
{ apiKey = "apiKey" | |
authDomain = "domain.com" | |
databaseURL = "all" | |
projectId = "projectId" | |
storageBucket = "bucket" | |
messagingSenderId = "12345678" } | |
let firebase = importAll<FirebaseNamespace> "firebase/app" | |
importSideEffects "firebase/auth" | |
firebase.initializeApp config |> ignore | |
let auth = firebase.auth() | |
promise { | |
let! user = auth.createUserWithEmailAndPassword("test@test.com", "password") | |
let email = | |
match user with | |
| Some u -> u.email | |
| None -> None | |
Option.defaultValue "no email" email | |
|> Browser.console.log | |
return email | |
} | |
|> Promise.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment