Added firebase-client typescript definition file

This commit is contained in:
Andrew Breen 2015-08-10 22:23:13 +10:00
parent 3b0f362204
commit 32dc65363f
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,50 @@
/// <reference path="firebase-client.d.ts" />
//Class definitions for type safety
class Name{
first:string;
last:string;
}
class User{
name:Name;
}
//Connect to service
var client = new FirebaseClient({
url : "https://fb-client-test.firebaseio.com/",
auth : null
});
var newUser:User = new User();
newUser.name = {
first: "Fred",
last: "Flinstone"
};
client.push("users", newUser)
.then(function (result){
console.log(result.name);
var newUser2:User = new User();
newUser2.name = {
first: "Fred",
last: "Rockington"
}
return client.update("users/" + result.name, newUser2);
}).then(function (result){
console.log(result.name.last);
var newUser3:User = new User();
newUser3.name = {
first: "Axe",
last: "Steel"
};
return client.set("users/AXESTEEL", newUser3);
}).then(function (result){
console.log(result.name.first);
return client.get();
}).then(function (result){
console.log(result);
return client.get<User>("users/AXESTEEL")
}).then(function (result){
console.log(result.name.first);
});

75
firebase-client/firebase-client.d.ts vendored Normal file
View File

@ -0,0 +1,75 @@
// Type definitions for Firebase Client 0.1.0
// Project: https://www.github.com/jpstevens/firebase-client
// Definitions by: Andrew Breen <https://github.com/fpsscarecrow/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../q/Q.d.ts" />
interface PushResponse {
/**
* Name ref (key) of the child resource
*/
name : string;
}
interface FirebaseConfig {
/**
* path for the Firebase instance
*/
url : string;
/**
* Token for authorisation
*/
auth: string;
}
interface FirebaseClient {
/**
* Creates a new FirebaseClient given the provided configuration
*/
new (config : FirebaseConfig) : FirebaseClient;
/**
* Retrieves all objects at the base path
*/
get<T>() : Q.Promise<T>;
/**
* Retrieves an object
* @param path Relative path from the base for the resource
*/
get<T>(path : string) : Q.Promise<T>;
/**
* Returns a promise of the HTTP response from setting the value at the given path
* @param path Relative path from the base for the resource
* @param data Data to be set as the value for the given path
*/
set<T>(path : string, data : T) : Q.Promise<T>;
/**
* Update a node at a given path
* @param path Relative path from the base for the resource
* @param value Value of the response
*/
update<T>(path : string, value : T) : Q.Promise<T>;
/**
* Deletes the resource at a given path
* @param path Relative path from the base for the resource
*/
delete(path : string) : Q.Promise<void>;
/**
* @param path Relative path from the base for the resource
* @param value Object to push to the path
*/
push<T>(path : string, value : T) : Q.Promise<PushResponse>;
}
declare var FirebaseClient: FirebaseClient;
declare module 'firebase-client' {
export = FirebaseClient;
}