From 779d3e58b6d77cb0f1bcb9f7b5b56013a4ed99ae Mon Sep 17 00:00:00 2001 From: in-async Date: Thu, 6 Nov 2014 01:38:27 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E6=9B=B4=E6=96=B0=E9=80=94=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angularfire/angularfire-tests.ts | 45 ++++++++++++++++++++------- angularfire/angularfire.d.ts | 52 ++++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/angularfire/angularfire-tests.ts b/angularfire/angularfire-tests.ts index eced9d7fe7..74a6c5a302 100644 --- a/angularfire/angularfire-tests.ts +++ b/angularfire/angularfire-tests.ts @@ -3,7 +3,7 @@ var myapp = angular.module("myapp", ["firebase"]); interface AngularFireScope extends ng.IScope { - items: AngularFire; + items: AngularFireArray; remoteItems: RemoteItems; } @@ -14,23 +14,46 @@ interface RemoteItems { var url = "https://myapp.firebaseio.com"; myapp.controller("MyController", ["$scope", "$firebase", - function($scope: AngularFireScope, $firebase: AngularFireService) { - $scope.items = $firebase(new Firebase(url)); + function ($scope: AngularFireScope, $firebase: AngularFireService) { + var sync = $firebase(new Firebase(url)); + + sync.$asArray() + .$loaded() + .then(function (list: AngularFireArray) { + console.log("list has " + list.length + " items"); + + list.$add({ foo: "bar" }).then(function (ref) { + ref.on("value", function (snapshot) { + if (snapshot.val().foo !== "bar") throw "error"; + }); + }); + + var item = list.$getRecord("foo"); + list.$remove("foo"); + list.$remove(0); + list.$save(); + }); + sync.$asObject() + + + $scope.items = sync.$asArray(); + $scope.object = sync.$asObject(); + $scope.items.$add({ foo: "bar" }); $scope.items.$remove("foo"); $scope.items.$remove(); $scope.items.$save(); var child = $scope.items.$child("foo"); child.$remove(); - $scope.items.$set({ bar: "baz" }); + $scope.items.$set({ bar: "baz" }); var keys = $scope.items.$getIndex(); - keys.forEach(function(key, i) { + keys.forEach(function (key, i) { console.log(i, ($scope.items)[key]); }); - $scope.items.$on("loaded", function() { + $scope.items.$on("loaded", function () { console.log("Initial data received!"); }); - $scope.items.$on("change", function() { + $scope.items.$on("change", function () { console.log("A remote change was applied locally!"); }); $scope.items.$off('loaded'); @@ -39,7 +62,7 @@ myapp.controller("MyController", ["$scope", "$firebase", } $scope.items.$bind($scope, "remoteItems"); $scope.remoteItems.bar = "foo"; - $scope.items.$bind($scope, "remote").then(function(unbind) { + $scope.items.$bind($scope, "remote").then(function (unbind) { unbind(); $scope.remoteItems.bar = "foo"; }); @@ -55,7 +78,7 @@ interface AngularFireAuthScope extends ng.IScope { } myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", - function($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) { + function ($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) { var dataRef = new Firebase(url); $scope.loginObj = $firebaseSimpleLogin(dataRef); $scope.loginObj.$getCurrentUser().then(_ => { @@ -65,9 +88,9 @@ myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", $scope.loginObj.$login('password', { email: email, password: password - }).then(function(user) { + }).then(function (user) { console.log('Logged in as: ', user.uid); - }, function(error) { + }, function (error) { console.error('Login failed: ', error); }); $scope.loginObj.$logout(); diff --git a/angularfire/angularfire.d.ts b/angularfire/angularfire.d.ts index 3f2b0aa106..f81ac243fa 100644 --- a/angularfire/angularfire.d.ts +++ b/angularfire/angularfire.d.ts @@ -1,4 +1,4 @@ -// Type definitions for AngularFire 0.6.0 +// Type definitions for AngularFire 0.8.2 and Firebase Simple Login 1.6.4 // Project: http://angularfire.com // Definitions by: Dénes Harmath // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -7,25 +7,53 @@ /// interface AngularFireService { - (firebase: Firebase): AngularFire; + (firebase: Firebase, config?:any): AngularFire; } interface AngularFire { - $add(value: any): void; - $remove(key?: string): void; - $save(key?: string): void; - $child(key: string): AngularFire; - $set(value: any): void; - $getIndex(): string[]; - $on(eventType: string, callback: (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void, cancelCallback?: ()=> void, context?: Object): (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void; - $off(eventType?: string, callback?: (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void, cancelCallback?: ()=> void, context?: Object): (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void; - $bind($scope: ng.IScope, modelName: string): ng.IPromise; + $asArray(): AngularFireArray; + $asObject(): AngularFireObject; + $ref(): Firebase; + $push(data: any): ng.IPromise; + $set(key: string, data: any): ng.IPromise; + $set(data: any): ng.IPromise; + $remove(key?: string): ng.IPromise; + $update(key: string, data: any): ng.IPromise; + $update(data: any): ng.IPromise; + $transaction(updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; } interface AngularFireObject { + $id: string; $priority: number; + $value: any; + $save(): ng.IPromise; + $loaded(): ng.IPromise; + $inst(): Firebase; + $bindTo(scope: ng.IScope, varName: string): ng.IPromise; + $watch(callback: Function, context: any): Function; + $destroy(): void; + + $extendFactory(ChildClass: Object, methods?: Object); } +interface AngularFireArray extends Array { + $add(newData: any): ng.IPromise; + $save(recordOrIndex: any): ng.IPromise; + $remove(recordOrIndex: any): ng.IPromise; + $getRecord(key: string): any; + $keyAt(recordOrIndex: any): string; + $indexFor(key: string): number; + $loaded(): ng.IPromise; + $inst(): Firebase; + $watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function; + $destroy(): void; + + $extendFactory(ChildClass:Object, methods?:Object); +} + + + interface AngularFireAuthService { (firebase: Firebase): AngularFireAuth; } @@ -34,7 +62,7 @@ interface AngularFireAuth { $getCurrentUser(): ng.IPromise; $login(provider: string, options?: Object): ng.IPromise; $logout(): void; - $createUser(email: string, password: string, noLogin?: boolean): ng.IPromise; + $createUser(email: string, password: string): ng.IPromise; $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; $removeUser(email: string, password: string): ng.IPromise; $sendPasswordResetEmail(email: string): ng.IPromise; From 5eef2e22f9980b06625e816bfc47b3bdc37d0f52 Mon Sep 17 00:00:00 2001 From: in-async Date: Thu, 6 Nov 2014 21:27:22 +0900 Subject: [PATCH 2/5] update angularfire.d.ts from 0.6.0 to 0.8.2 --- angularfire/angularfire-tests.ts | 208 ++++++++++++++++++++++--------- angularfire/angularfire.d.ts | 59 +++++---- 2 files changed, 185 insertions(+), 82 deletions(-) diff --git a/angularfire/angularfire-tests.ts b/angularfire/angularfire-tests.ts index 74a6c5a302..231c0f992c 100644 --- a/angularfire/angularfire-tests.ts +++ b/angularfire/angularfire-tests.ts @@ -3,76 +3,166 @@ var myapp = angular.module("myapp", ["firebase"]); interface AngularFireScope extends ng.IScope { - items: AngularFireArray; - remoteItems: RemoteItems; -} - -interface RemoteItems { - bar: string; + data: any; } var url = "https://myapp.firebaseio.com"; -myapp.controller("MyController", ["$scope", "$firebase", - function ($scope: AngularFireScope, $firebase: AngularFireService) { - var sync = $firebase(new Firebase(url)); +myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$FirebaseArray', + function ($scope: AngularFireScope, $firebase: AngularFireService, $FirebaseObject: AngularFireObjectService, $FirebaseArray: AngularFireArrayService) { + var ref = new Firebase(url); + var sync = $firebase(ref); - sync.$asArray() - .$loaded() - .then(function (list: AngularFireArray) { - console.log("list has " + list.length + " items"); + // AngularFire + { + sync.$asArray(); + sync.$asObject(); + sync.$ref(); + sync.$remove(); + sync.$push({ foo: "foo data" }); + sync.$set("foo", 1); + sync.$set({ foo: 2 }); + sync.$update({ foo: 3 }); + sync.$update("foo", { bar: 1 }); - list.$add({ foo: "bar" }).then(function (ref) { - ref.on("value", function (snapshot) { - if (snapshot.val().foo !== "bar") throw "error"; - }); + // Increment the message count by 1 + sync.$transaction('count', function (currentCount) { + if (!currentCount) return 1; // Initial value for counter. + if (currentCount < 0) return; // Return undefined to abort transaction. + return currentCount + 1; // Increment the count by 1. + }).then(function (snapshot) { + if (!snapshot) { + // Handle aborted transaction. + } else { + // Do something. + console.log(snapshot.val()); + } + }, function (err) { + // Handle the error condition. + console.log(err.stack); }); - - var item = list.$getRecord("foo"); - list.$remove("foo"); - list.$remove(0); - list.$save(); - }); - sync.$asObject() - - - $scope.items = sync.$asArray(); - $scope.object = sync.$asObject(); - - $scope.items.$add({ foo: "bar" }); - $scope.items.$remove("foo"); - $scope.items.$remove(); - $scope.items.$save(); - var child = $scope.items.$child("foo"); - child.$remove(); - $scope.items.$set({ bar: "baz" }); - var keys = $scope.items.$getIndex(); - keys.forEach(function (key, i) { - console.log(i, ($scope.items)[key]); - }); - $scope.items.$on("loaded", function () { - console.log("Initial data received!"); - }); - $scope.items.$on("change", function () { - console.log("A remote change was applied locally!"); - }); - $scope.items.$off('loaded'); - function stopSync() { - $scope.items.$off(); } - $scope.items.$bind($scope, "remoteItems"); - $scope.remoteItems.bar = "foo"; - $scope.items.$bind($scope, "remote").then(function (unbind) { - unbind(); - $scope.remoteItems.bar = "foo"; - }); + + + // AngularFireObject + { + var obj = sync.$asObject(); + + // $id + if (obj.$id !== ref.name()) throw "error"; + + // $loaded() + obj.$loaded().then((data) => { + if (data !== obj) throw "error"; + // $priority + obj.$priority; + + // $value, $save() + obj.$value = "foobar"; + obj.$save(); + }); + + // $inst() + if (obj.$inst() !== sync) throw "error"; + + // $bindTo() + obj.$bindTo($scope, "data").then(function () { + console.log($scope.data); + $scope.data.foo = "baz"; // will be saved to Firebase + sync.$set({ foo: "baz" }); // this would update Firebase and $scope.data + }); + + // $watch() + var unwatch = obj.$watch(function () { + console.log("data changed!"); + }); + unwatch(); + + // $destroy() + obj.$destroy(); + + // $extendFactory() + var NewFactory = $FirebaseObject.$extendFactory({ + getMyFavoriteColor: function () { + return this.favoriteColor + ", no green!"; // obscure Monty Python reference + } + }); + var customObj = $firebase(ref, { objectFactory: NewFactory }).$asObject(); + } + + // AngularFireArray + { + var list = sync.$asArray(); + + // $inst() + if (list.$inst() !== sync) throw "error"; + + // $add() + list.$add({ foo: "foo value" }); + + // $keyAt() + var key = list.$keyAt(0); + + // $indexFor() + var index = list.$indexFor(key); + + // $getRecord() + var item = list.$getRecord(key); + + // $save() + item["bar"] = "bar value"; + list.$save(item); + + // $remove() + list.$remove(item); + + // $loaded() + list.$loaded().then(data => { + if (data !== list) throw "error"; + }); + + // $watch() + var unwatch = list.$watch((event, key, prevChild) => { + switch (event) { + case "child_added": + console.log(key + " added"); + break; + case "child_changed": + console.log(key + " changed"); + break; + case "child_moved": + console.log(key + " moved"); + break; + case "child_removed": + console.log(key + " removed"); + break; + default: + throw "error"; + } + }); + unwatch(); + + // $destroy() + list.$destroy(); + + // $extendFactory() + var ArrayWithSum = $FirebaseArray.$extendFactory({ + sum: function () { + var total = 0; + angular.forEach(this.$list, function (rec) { + total += rec.x; + }); + return total; + } + }); + var list = $firebase(ref, { arrayFactory: ArrayWithSum }).$asArray(); + list.$loaded().then(function () { + console.log("List has " + (list).sum() + " items"); + }); + } } ]); -var foo: AngularFireObject = { - $priority: 0 -}; - interface AngularFireAuthScope extends ng.IScope { loginObj: AngularFireAuth; } diff --git a/angularfire/angularfire.d.ts b/angularfire/angularfire.d.ts index f81ac243fa..b6a0d55d26 100644 --- a/angularfire/angularfire.d.ts +++ b/angularfire/angularfire.d.ts @@ -1,4 +1,4 @@ -// Type definitions for AngularFire 0.8.2 and Firebase Simple Login 1.6.4 +// Type definitions for AngularFire 0.8.2 // Project: http://angularfire.com // Definitions by: Dénes Harmath // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -7,7 +7,7 @@ /// interface AngularFireService { - (firebase: Firebase, config?:any): AngularFire; + (firebase: Firebase, config?: any): AngularFire; } interface AngularFire { @@ -18,52 +18,65 @@ interface AngularFire { $set(key: string, data: any): ng.IPromise; $set(data: any): ng.IPromise; $remove(key?: string): ng.IPromise; - $update(key: string, data: any): ng.IPromise; + $update(key: string, data: Object): ng.IPromise; $update(data: any): ng.IPromise; $transaction(updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; + $transaction(key:string, updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; } -interface AngularFireObject { +interface AngularFireObject extends AngularFireSimpleObject { $id: string; $priority: number; $value: any; $save(): ng.IPromise; - $loaded(): ng.IPromise; - $inst(): Firebase; + $loaded(resolve?: (x: AngularFireObject) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireObject) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireObject) => void, reject?: (err: any) => any): ng.IPromise; + $inst(): AngularFire; $bindTo(scope: ng.IScope, varName: string): ng.IPromise; - $watch(callback: Function, context: any): Function; + $watch(callback: Function, context?: any): Function; $destroy(): void; - - $extendFactory(ChildClass: Object, methods?: Object); +} +interface AngularFireObjectService { + $extendFactory(ChildClass: Object, methods?: Object): Object; } -interface AngularFireArray extends Array { +interface AngularFireArray extends Array { $add(newData: any): ng.IPromise; $save(recordOrIndex: any): ng.IPromise; $remove(recordOrIndex: any): ng.IPromise; - $getRecord(key: string): any; + $getRecord(key: string): AngularFireSimpleObject; $keyAt(recordOrIndex: any): string; $indexFor(key: string): number; - $loaded(): ng.IPromise; - $inst(): Firebase; + $loaded(resolve?: (x: AngularFireArray) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireArray) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireArray) => void, reject?: (err: any) => any): ng.IPromise; + $inst(): AngularFire; $watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function; $destroy(): void; - - $extendFactory(ChildClass:Object, methods?:Object); +} +interface AngularFireArrayService { + $extendFactory(ChildClass: Object, methods?: Object): Object; } +interface AngularFireSimpleObject { + $id: string; + $priority: number; + $value: any; + [key: string]: any; +} interface AngularFireAuthService { - (firebase: Firebase): AngularFireAuth; + (firebase: Firebase): AngularFireAuth; } interface AngularFireAuth { - $getCurrentUser(): ng.IPromise; - $login(provider: string, options?: Object): ng.IPromise; - $logout(): void; - $createUser(email: string, password: string): ng.IPromise; - $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; - $removeUser(email: string, password: string): ng.IPromise; - $sendPasswordResetEmail(email: string): ng.IPromise; + $getCurrentUser(): ng.IPromise; + $login(provider: string, options?: Object): ng.IPromise; + $logout(): void; + $createUser(email: string, password: string): ng.IPromise; + $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; + $removeUser(email: string, password: string): ng.IPromise; + $sendPasswordResetEmail(email: string): ng.IPromise; } From 24bf981aba084453a946f3a4f588cd2c90a0d4c9 Mon Sep 17 00:00:00 2001 From: in-async Date: Fri, 7 Nov 2014 17:49:10 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BD=9C=E6=A5=AD=E9=80=94=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firebase/firebase-tests.ts | 142 +++++++++++++++++++++++++++++++++++++ firebase/firebase.d.ts | 96 ++++++++++++++++++++++++- 2 files changed, 235 insertions(+), 3 deletions(-) diff --git a/firebase/firebase-tests.ts b/firebase/firebase-tests.ts index eb6be83734..647ecb663d 100644 --- a/firebase/firebase-tests.ts +++ b/firebase/firebase-tests.ts @@ -11,6 +11,94 @@ dataRef.auth(AUTH_TOKEN, function(error, result) { } }); +// Log me in +dataRef.authWithCustomToken(AUTH_TOKEN, function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); + +// Log me in +dataRef.authAnonymously(function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); + +// Log me in +dataRef.authWithPassword({ + "email" : "bobtony@firebase.com", + "password" : "correcthorsebatterystaple" +}, function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); + +// Log me in +dataRef.authWithOAuthPopup("twitter", function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); + +// Log me in +dataRef.authWithOAuthRedirect("twitter", function(error) { + if (error) { + console.log('Login Failed!', error); + } else { + // We'll never get here, as the page will redirect on success. + } +}); + +// Authenticate with Facebook using an existing OAuth 2.0 access token +dataRef.authWithOAuthToken("facebook", "", function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); +// Authenticate with Twitter using an existing OAuth 1.0a credential set +dataRef.authWithOAuthToken("twitter", { + "user_id" : "", + "oauth_token" : "", + "oauth_token_secret" : "", +}, function(error, authData) { + if (error) { + console.log('Login Failed!', error); + } else { + console.log('Authenticated successfully with payload:', authData); + } +}); + +var authData = dataRef.getAuth(); +if (authData) { + console.log('Authenticated user with uid:', authData.uid); +} + +var firebaseRef = new Firebase('https://samplechat.firebaseio-demo.com'); +firebaseRef.onAuth(function(authData) { + if (authData) { + console.log('Client is authenticated with uid ' + authData.uid); + } else { + // Client is unauthenticated + } +}); + +var onAuthChange = function(authData) { /*...*/ }; +firebaseRef.onAuth(onAuthChange); +// Sometime later... +firebaseRef.offAuth(onAuthChange); + //Time to log out! dataRef.unauth(); @@ -32,10 +120,64 @@ var sampleChatRef2 :Firebase= fredRef2.root(); var x3:string = sampleChatRef2.toString(); // x is now 'https://SampleChat.firebaseIO-demo.com'. +var fredRef = new Firebase("https://samplechat.firebaseio-demo.com/users/fred"); +var key = fredRef.key(); // key === "fred" +key = fredRef.child("name/last").key(); // key === "last" +key = fredRef.root().key(); // key === null, since fredRef refers to the root of the Firebase. + var fredRef3:Firebase = new Firebase('https://SampleChat.firebaseIO-demo.com/users/fred'); var x4:string = fredRef3.name(); // x is now 'fred'. +/* + * $set + */ +var fredNameRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred/name'); +fredNameRef.child('first').set('Fred'); +fredNameRef.child('last').set('Flintstone'); +// We've written 'Fred' to the Firebase location storing fred's first name, +// and 'Flintstone' to the location storing his last name + +fredNameRef.set({ first: 'Fred', last: 'Flintstone' }); +// Exact same effect as the previous example, except we've written +// fred's first and last name simultaneously + +var onComplete = function(error) { + if (error) { + console.log('Synchronization failed'); + } else { + console.log('Synchronization succeeded'); + } +}; +fredNameRef.set({ first: 'Fred', last: 'Flintstone' }, onComplete); +// Same as the previous example, except we will also log a message +// when the data has finished synchronizing + + +/* + * $update + */ +var fredNameRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred/name'); +// Modify the 'first' and 'last' children, but leave other data at fredNameRef unchanged +fredNameRef.update({ first: 'Fred', last: 'Flintstone' }); + +// Same as the previous example, except we will also display an alert +// message when the data has finished synchronizing. +var onComplete = function(error) { + if (error) { + console.log('Synchronization failed'); + } else { + console.log('Synchronization succeeded'); + } +}; +fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete); + +var fredRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred'); +//The following 2 function calls are equivalent +fredRef.update({ name: { first: 'Fred', last: 'Flintstone' }}); +fredRef.child('name').set({ first: 'Fred', last: 'Flintstone' }); + + // Increment Fred's rank by 1. var fredRankRef:Firebase = new Firebase('https://SampleChat.firebaseIO-demo.com/users/fred/rank'); fredRankRef.transaction(function(currentRank: number) { diff --git a/firebase/firebase.d.ts b/firebase/firebase.d.ts index bac32fbc63..796d14d59e 100644 --- a/firebase/firebase.d.ts +++ b/firebase/firebase.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Firebase API +// Type definitions for Firebase API 2.0.2 // Project: https://www.firebase.com/docs/javascript/firebase // Definitions by: Vincent Botone // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -43,16 +43,92 @@ interface IFirebaseQuery { } declare class Firebase implements IFirebaseQuery { + /** + * Constructs a new Firebase reference from a full Firebase URL. + */ constructor(firebaseURL: string); - auth(authToken: string, onComplete?: (error: any, result: IFirebaseAuthResult) => void, onCancel?:(error: any) => void): void; + /** + * @deprecated Use authWithCustomToken() instead. + * Authenticates a Firebase client using the provided authentication token or Firebase Secret. + */ + auth(authToken: string, onComplete?: (error: any, result: IFirebaseAuthResult) => void, onCancel?: (error: any) => void): void; + /** + * Authenticates a Firebase client using an authentication token or Firebase Secret. + */ + authWithCustomToken(autoToken: string, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?:Object): void; + /** + * Authenticates a Firebase client using a new, temporary guest account. + */ + authAnonymously(onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; + /** + * Authenticates a Firebase client using an email / password combination. + */ + authWithPassword(credentials: IFirebaseCredentials, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; + /** + * Authenticates a Firebase client using a popup-based OAuth flow. + */ + authWithOAuthPopup(provider: string, onComplete:(error: any, authData: IFirebaseAuthData) => void, options?: Object): void; + /** + * Authenticates a Firebase client using a redirect-based OAuth flow. + */ + authWithOAuthRedirect(provider: string, onComplete: (error: any) => void, options?: Object): void; + /** + * Authenticates a Firebase client using OAuth access tokens or credentials. + */ + authWithOAuthToken(provider: string, credentials: string, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; + authWithOAuthToken(provider: string, credentials: Object, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; + /** + * Synchronously access the current authentication state of the client. + */ + getAuth(): IFirebaseAuthData; + /** + * Listen for changes to the client's authentication state. + */ + onAuth(onComplete: (authData: IFirebaseAuthData) => void, context?: Object): void; + /** + * Detaches a callback previously attached with onAuth(). + */ + offAuth(onComplete: (authData: IFirebaseAuthData) => void, context?: Object): void; + /** + * Unauthenticates a Firebase client. + */ unauth(): void; + /** + * Gets a Firebase reference for the location at the specified relative path. + */ child(childPath: string): Firebase; + /** + * Gets a Firebase reference to the parent location. + */ parent(): Firebase; + /** + * Gets a Firebase reference to the root of the Firebase. + */ root(): Firebase; + /** + * Returns the last token in a Firebase location. + */ + key(): string; + /** + * @deprecated Use key() instead. + * Returns the last token in a Firebase location. + */ name(): string; + /** + * Gets the absolute URL corresponding to this Firebase reference's location. + */ toString(): string; + /** + * Writes data to this Firebase location. + */ set(value: any, onComplete?: (error: any) => void): void; - update(value: any, onComplete?: (error: any) => void): void; + /** + * Writes the enumerated children to this Firebase location. + */ + update(value: Object, onComplete?: (error: any) => void): void; + /** + * + */ remove(onComplete?: (error: any) => void): void; push(value: any, onComplete?: (error: any) => void): Firebase; setWithPriority(value: any, priority: string, onComplete?: (error: any) => void): void; @@ -73,3 +149,17 @@ declare class Firebase implements IFirebaseQuery { goOffline(): void; goOnline(): void; } + +// Reference: https://www.firebase.com/docs/web/api/firebase/getauth.html +interface IFirebaseAuthData { + uid: string; + provider: string; + token: string; + expires: number; + auth: Object; +} + +interface IFirebaseCredentials { + email: string; + password: string; +} \ No newline at end of file From 154c40d628946ea6b6b15dc9fc341f47036ccf0b Mon Sep 17 00:00:00 2001 From: in-async Date: Fri, 7 Nov 2014 17:56:53 +0900 Subject: [PATCH 4/5] =?UTF-8?q?Revert=20"=E4=BD=9C=E6=A5=AD=E9=80=94?= =?UTF-8?q?=E4=B8=AD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 24bf981aba084453a946f3a4f588cd2c90a0d4c9. --- firebase/firebase-tests.ts | 142 ------------------------------------- firebase/firebase.d.ts | 96 +------------------------ 2 files changed, 3 insertions(+), 235 deletions(-) diff --git a/firebase/firebase-tests.ts b/firebase/firebase-tests.ts index 647ecb663d..eb6be83734 100644 --- a/firebase/firebase-tests.ts +++ b/firebase/firebase-tests.ts @@ -11,94 +11,6 @@ dataRef.auth(AUTH_TOKEN, function(error, result) { } }); -// Log me in -dataRef.authWithCustomToken(AUTH_TOKEN, function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); - -// Log me in -dataRef.authAnonymously(function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); - -// Log me in -dataRef.authWithPassword({ - "email" : "bobtony@firebase.com", - "password" : "correcthorsebatterystaple" -}, function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); - -// Log me in -dataRef.authWithOAuthPopup("twitter", function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); - -// Log me in -dataRef.authWithOAuthRedirect("twitter", function(error) { - if (error) { - console.log('Login Failed!', error); - } else { - // We'll never get here, as the page will redirect on success. - } -}); - -// Authenticate with Facebook using an existing OAuth 2.0 access token -dataRef.authWithOAuthToken("facebook", "", function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); -// Authenticate with Twitter using an existing OAuth 1.0a credential set -dataRef.authWithOAuthToken("twitter", { - "user_id" : "", - "oauth_token" : "", - "oauth_token_secret" : "", -}, function(error, authData) { - if (error) { - console.log('Login Failed!', error); - } else { - console.log('Authenticated successfully with payload:', authData); - } -}); - -var authData = dataRef.getAuth(); -if (authData) { - console.log('Authenticated user with uid:', authData.uid); -} - -var firebaseRef = new Firebase('https://samplechat.firebaseio-demo.com'); -firebaseRef.onAuth(function(authData) { - if (authData) { - console.log('Client is authenticated with uid ' + authData.uid); - } else { - // Client is unauthenticated - } -}); - -var onAuthChange = function(authData) { /*...*/ }; -firebaseRef.onAuth(onAuthChange); -// Sometime later... -firebaseRef.offAuth(onAuthChange); - //Time to log out! dataRef.unauth(); @@ -120,64 +32,10 @@ var sampleChatRef2 :Firebase= fredRef2.root(); var x3:string = sampleChatRef2.toString(); // x is now 'https://SampleChat.firebaseIO-demo.com'. -var fredRef = new Firebase("https://samplechat.firebaseio-demo.com/users/fred"); -var key = fredRef.key(); // key === "fred" -key = fredRef.child("name/last").key(); // key === "last" -key = fredRef.root().key(); // key === null, since fredRef refers to the root of the Firebase. - var fredRef3:Firebase = new Firebase('https://SampleChat.firebaseIO-demo.com/users/fred'); var x4:string = fredRef3.name(); // x is now 'fred'. -/* - * $set - */ -var fredNameRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred/name'); -fredNameRef.child('first').set('Fred'); -fredNameRef.child('last').set('Flintstone'); -// We've written 'Fred' to the Firebase location storing fred's first name, -// and 'Flintstone' to the location storing his last name - -fredNameRef.set({ first: 'Fred', last: 'Flintstone' }); -// Exact same effect as the previous example, except we've written -// fred's first and last name simultaneously - -var onComplete = function(error) { - if (error) { - console.log('Synchronization failed'); - } else { - console.log('Synchronization succeeded'); - } -}; -fredNameRef.set({ first: 'Fred', last: 'Flintstone' }, onComplete); -// Same as the previous example, except we will also log a message -// when the data has finished synchronizing - - -/* - * $update - */ -var fredNameRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred/name'); -// Modify the 'first' and 'last' children, but leave other data at fredNameRef unchanged -fredNameRef.update({ first: 'Fred', last: 'Flintstone' }); - -// Same as the previous example, except we will also display an alert -// message when the data has finished synchronizing. -var onComplete = function(error) { - if (error) { - console.log('Synchronization failed'); - } else { - console.log('Synchronization succeeded'); - } -}; -fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete); - -var fredRef = new Firebase('https://samplechat.firebaseio-demo.com/users/fred'); -//The following 2 function calls are equivalent -fredRef.update({ name: { first: 'Fred', last: 'Flintstone' }}); -fredRef.child('name').set({ first: 'Fred', last: 'Flintstone' }); - - // Increment Fred's rank by 1. var fredRankRef:Firebase = new Firebase('https://SampleChat.firebaseIO-demo.com/users/fred/rank'); fredRankRef.transaction(function(currentRank: number) { diff --git a/firebase/firebase.d.ts b/firebase/firebase.d.ts index 796d14d59e..bac32fbc63 100644 --- a/firebase/firebase.d.ts +++ b/firebase/firebase.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Firebase API 2.0.2 +// Type definitions for Firebase API // Project: https://www.firebase.com/docs/javascript/firebase // Definitions by: Vincent Botone // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -43,92 +43,16 @@ interface IFirebaseQuery { } declare class Firebase implements IFirebaseQuery { - /** - * Constructs a new Firebase reference from a full Firebase URL. - */ constructor(firebaseURL: string); - /** - * @deprecated Use authWithCustomToken() instead. - * Authenticates a Firebase client using the provided authentication token or Firebase Secret. - */ - auth(authToken: string, onComplete?: (error: any, result: IFirebaseAuthResult) => void, onCancel?: (error: any) => void): void; - /** - * Authenticates a Firebase client using an authentication token or Firebase Secret. - */ - authWithCustomToken(autoToken: string, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?:Object): void; - /** - * Authenticates a Firebase client using a new, temporary guest account. - */ - authAnonymously(onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; - /** - * Authenticates a Firebase client using an email / password combination. - */ - authWithPassword(credentials: IFirebaseCredentials, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; - /** - * Authenticates a Firebase client using a popup-based OAuth flow. - */ - authWithOAuthPopup(provider: string, onComplete:(error: any, authData: IFirebaseAuthData) => void, options?: Object): void; - /** - * Authenticates a Firebase client using a redirect-based OAuth flow. - */ - authWithOAuthRedirect(provider: string, onComplete: (error: any) => void, options?: Object): void; - /** - * Authenticates a Firebase client using OAuth access tokens or credentials. - */ - authWithOAuthToken(provider: string, credentials: string, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; - authWithOAuthToken(provider: string, credentials: Object, onComplete: (error: any, authData: IFirebaseAuthData) => void, options?: Object): void; - /** - * Synchronously access the current authentication state of the client. - */ - getAuth(): IFirebaseAuthData; - /** - * Listen for changes to the client's authentication state. - */ - onAuth(onComplete: (authData: IFirebaseAuthData) => void, context?: Object): void; - /** - * Detaches a callback previously attached with onAuth(). - */ - offAuth(onComplete: (authData: IFirebaseAuthData) => void, context?: Object): void; - /** - * Unauthenticates a Firebase client. - */ + auth(authToken: string, onComplete?: (error: any, result: IFirebaseAuthResult) => void, onCancel?:(error: any) => void): void; unauth(): void; - /** - * Gets a Firebase reference for the location at the specified relative path. - */ child(childPath: string): Firebase; - /** - * Gets a Firebase reference to the parent location. - */ parent(): Firebase; - /** - * Gets a Firebase reference to the root of the Firebase. - */ root(): Firebase; - /** - * Returns the last token in a Firebase location. - */ - key(): string; - /** - * @deprecated Use key() instead. - * Returns the last token in a Firebase location. - */ name(): string; - /** - * Gets the absolute URL corresponding to this Firebase reference's location. - */ toString(): string; - /** - * Writes data to this Firebase location. - */ set(value: any, onComplete?: (error: any) => void): void; - /** - * Writes the enumerated children to this Firebase location. - */ - update(value: Object, onComplete?: (error: any) => void): void; - /** - * - */ + update(value: any, onComplete?: (error: any) => void): void; remove(onComplete?: (error: any) => void): void; push(value: any, onComplete?: (error: any) => void): Firebase; setWithPriority(value: any, priority: string, onComplete?: (error: any) => void): void; @@ -149,17 +73,3 @@ declare class Firebase implements IFirebaseQuery { goOffline(): void; goOnline(): void; } - -// Reference: https://www.firebase.com/docs/web/api/firebase/getauth.html -interface IFirebaseAuthData { - uid: string; - provider: string; - token: string; - expires: number; - auth: Object; -} - -interface IFirebaseCredentials { - email: string; - password: string; -} \ No newline at end of file From 12af931fb003092a3dc5eb97dfbe210b40d5288b Mon Sep 17 00:00:00 2001 From: in-async Date: Sat, 8 Nov 2014 23:50:15 +0900 Subject: [PATCH 5/5] Fix along the guidelines. --- angularfire/angularfire-tests.ts | 6 +- angularfire/angularfire.d.ts | 98 ++++++++++++++++---------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/angularfire/angularfire-tests.ts b/angularfire/angularfire-tests.ts index 231c0f992c..7d39e4181d 100644 --- a/angularfire/angularfire-tests.ts +++ b/angularfire/angularfire-tests.ts @@ -168,7 +168,7 @@ interface AngularFireAuthScope extends ng.IScope { } myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", - function ($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) { + function($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) { var dataRef = new Firebase(url); $scope.loginObj = $firebaseSimpleLogin(dataRef); $scope.loginObj.$getCurrentUser().then(_ => { @@ -178,9 +178,9 @@ myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", $scope.loginObj.$login('password', { email: email, password: password - }).then(function (user) { + }).then(function(user) { console.log('Logged in as: ', user.uid); - }, function (error) { + }, function(error) { console.error('Login failed: ', error); }); $scope.loginObj.$logout(); diff --git a/angularfire/angularfire.d.ts b/angularfire/angularfire.d.ts index b6a0d55d26..0bebb23c52 100644 --- a/angularfire/angularfire.d.ts +++ b/angularfire/angularfire.d.ts @@ -7,76 +7,76 @@ /// interface AngularFireService { - (firebase: Firebase, config?: any): AngularFire; + (firebase: Firebase, config?: any): AngularFire; } interface AngularFire { - $asArray(): AngularFireArray; - $asObject(): AngularFireObject; - $ref(): Firebase; - $push(data: any): ng.IPromise; - $set(key: string, data: any): ng.IPromise; - $set(data: any): ng.IPromise; - $remove(key?: string): ng.IPromise; - $update(key: string, data: Object): ng.IPromise; - $update(data: any): ng.IPromise; - $transaction(updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; - $transaction(key:string, updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; + $asArray(): AngularFireArray; + $asObject(): AngularFireObject; + $ref(): Firebase; + $push(data: any): ng.IPromise; + $set(key: string, data: any): ng.IPromise; + $set(data: any): ng.IPromise; + $remove(key?: string): ng.IPromise; + $update(key: string, data: Object): ng.IPromise; + $update(data: any): ng.IPromise; + $transaction(updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; + $transaction(key:string, updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise; } interface AngularFireObject extends AngularFireSimpleObject { - $id: string; - $priority: number; - $value: any; - $save(): ng.IPromise; - $loaded(resolve?: (x: AngularFireObject) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; - $loaded(resolve?: (x: AngularFireObject) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; - $loaded(resolve?: (x: AngularFireObject) => void, reject?: (err: any) => any): ng.IPromise; - $inst(): AngularFire; - $bindTo(scope: ng.IScope, varName: string): ng.IPromise; - $watch(callback: Function, context?: any): Function; - $destroy(): void; + $id: string; + $priority: number; + $value: any; + $save(): ng.IPromise; + $loaded(resolve?: (x: AngularFireObject) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireObject) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireObject) => void, reject?: (err: any) => any): ng.IPromise; + $inst(): AngularFire; + $bindTo(scope: ng.IScope, varName: string): ng.IPromise; + $watch(callback: Function, context?: any): Function; + $destroy(): void; } interface AngularFireObjectService { - $extendFactory(ChildClass: Object, methods?: Object): Object; + $extendFactory(ChildClass: Object, methods?: Object): Object; } interface AngularFireArray extends Array { - $add(newData: any): ng.IPromise; - $save(recordOrIndex: any): ng.IPromise; - $remove(recordOrIndex: any): ng.IPromise; - $getRecord(key: string): AngularFireSimpleObject; - $keyAt(recordOrIndex: any): string; - $indexFor(key: string): number; - $loaded(resolve?: (x: AngularFireArray) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; - $loaded(resolve?: (x: AngularFireArray) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; - $loaded(resolve?: (x: AngularFireArray) => void, reject?: (err: any) => any): ng.IPromise; - $inst(): AngularFire; - $watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function; - $destroy(): void; + $add(newData: any): ng.IPromise; + $save(recordOrIndex: any): ng.IPromise; + $remove(recordOrIndex: any): ng.IPromise; + $getRecord(key: string): AngularFireSimpleObject; + $keyAt(recordOrIndex: any): string; + $indexFor(key: string): number; + $loaded(resolve?: (x: AngularFireArray) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireArray) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; + $loaded(resolve?: (x: AngularFireArray) => void, reject?: (err: any) => any): ng.IPromise; + $inst(): AngularFire; + $watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function; + $destroy(): void; } interface AngularFireArrayService { - $extendFactory(ChildClass: Object, methods?: Object): Object; + $extendFactory(ChildClass: Object, methods?: Object): Object; } interface AngularFireSimpleObject { - $id: string; - $priority: number; - $value: any; - [key: string]: any; + $id: string; + $priority: number; + $value: any; + [key: string]: any; } interface AngularFireAuthService { - (firebase: Firebase): AngularFireAuth; + (firebase: Firebase): AngularFireAuth; } interface AngularFireAuth { - $getCurrentUser(): ng.IPromise; - $login(provider: string, options?: Object): ng.IPromise; - $logout(): void; - $createUser(email: string, password: string): ng.IPromise; - $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; - $removeUser(email: string, password: string): ng.IPromise; - $sendPasswordResetEmail(email: string): ng.IPromise; + $getCurrentUser(): ng.IPromise; + $login(provider: string, options?: Object): ng.IPromise; + $logout(): void; + $createUser(email: string, password: string): ng.IPromise; + $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; + $removeUser(email: string, password: string): ng.IPromise; + $sendPasswordResetEmail(email: string): ng.IPromise; }