diff --git a/firebase-client/firebase-client-tests.ts b/firebase-client/firebase-client-tests.ts new file mode 100644 index 000000000..bc4ef06a8 --- /dev/null +++ b/firebase-client/firebase-client-tests.ts @@ -0,0 +1,50 @@ +/// + +//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("users/AXESTEEL") + }).then(function (result){ + console.log(result.name.first); + }); \ No newline at end of file diff --git a/firebase-client/firebase-client.d.ts b/firebase-client/firebase-client.d.ts new file mode 100644 index 000000000..15839deee --- /dev/null +++ b/firebase-client/firebase-client.d.ts @@ -0,0 +1,75 @@ +// Type definitions for Firebase Client 0.1.0 +// Project: https://www.github.com/jpstevens/firebase-client +// Definitions by: Andrew Breen +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + +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() : Q.Promise; + + /** + * Retrieves an object + * @param path Relative path from the base for the resource + */ + get(path : string) : Q.Promise; + + /** + * 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(path : string, data : T) : Q.Promise; + + /** + * Update a node at a given path + * @param path Relative path from the base for the resource + * @param value Value of the response + */ + update(path : string, value : T) : Q.Promise; + + /** + * Deletes the resource at a given path + * @param path Relative path from the base for the resource + */ + delete(path : string) : Q.Promise; + + /** + * @param path Relative path from the base for the resource + * @param value Object to push to the path + */ + push(path : string, value : T) : Q.Promise; +} + +declare var FirebaseClient: FirebaseClient; + +declare module 'firebase-client' { + export = FirebaseClient; +} +