mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 14:59:37 +08:00
Add milkcocoa.d.ts and milkcocoa-tests.ts
This commit is contained in:
37
milkcocoa/milkcocoa-tests.ts
Normal file
37
milkcocoa/milkcocoa-tests.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
///<reference path="./milkcocoa.d.ts"/>
|
||||
var mk = new MilkCocoa("hostAddress");
|
||||
mk.addAccount("sample@test.com", "password", null, (err: MilkCocoa.Error.AddAccount, user: milkcocoa.User) => {
|
||||
|
||||
switch (err) {
|
||||
case null:
|
||||
console.log("Done.");
|
||||
break;
|
||||
case MilkCocoa.Error.AddAccount.FormatError:
|
||||
console.log("Invalid mail address.");
|
||||
break;
|
||||
case MilkCocoa.Error.AddAccount.AlreadyExist:
|
||||
console.log("Already added account.");
|
||||
break;
|
||||
}
|
||||
});
|
||||
mk.login("sample@test.com", "password", (err: MilkCocoa.Error.Login, user: User) => {
|
||||
if (err === MilkCocoa.Error.Login.FormatError) {
|
||||
console.log("Invalid mail address.");
|
||||
} else if (err === MilkCocoa.Error.Login.LoginError) {
|
||||
console.log("Or Email that is not registered, it is not a valid password.");
|
||||
} else if (err === MilkCocoa.Error.Login.EmailNotVerificated) {
|
||||
console.log("Still account is temporary registration.");
|
||||
} else {
|
||||
//成功時はユーザIDを取得できます。
|
||||
var user_id = user.id;
|
||||
}
|
||||
});
|
||||
mk.dataStore("datastore").push({ message: "this is message." }, (data: DataStoreCallbackData) => {
|
||||
console.log("pushed.");
|
||||
});
|
||||
mk.dataStore("datastore").child("chat").child("message").on("push", (data: DataStoreCallbackData) => {
|
||||
console.log(data.value.message);
|
||||
});
|
||||
mk.dataStore("datastore").child("chat").child("message").query().limit(10).done((data) => {
|
||||
console.log(data.message);
|
||||
});
|
||||
1
milkcocoa/milkcocoa-tests.ts.tscparams
Normal file
1
milkcocoa/milkcocoa-tests.ts.tscparams
Normal file
@@ -0,0 +1 @@
|
||||
--noImplicitAny
|
||||
75
milkcocoa/milkcocoa.d.ts
vendored
Normal file
75
milkcocoa/milkcocoa.d.ts
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// Type definitions for Milkcocoa 0.2.8
|
||||
// Project: https://mlkcca.com/
|
||||
// Definitions by: odangosan <https://github.com/odangosan>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
// Api Reference : https://mlkcca.com/document/api-js.html
|
||||
|
||||
declare module milkcocoa {
|
||||
class MilkCocoa {
|
||||
constructor(host: string, callback?: Function);
|
||||
dataStore(path: string): DataStore;
|
||||
addAccount(email: string, password: string, options?: {}, callback?: (err: MilkCocoa.Error.AddAccount, user: User) => void): void;
|
||||
login(email: string, password: string, callback: (err: MilkCocoa.Error.Login, user: User) => void): void;
|
||||
logout(callback?: (err: string) => void): void;
|
||||
getCurrentUser(callback: (err: MilkCocoa.Error.GetCurrentUser, user: { id: string }) => void): void;
|
||||
}
|
||||
|
||||
module MilkCocoa {
|
||||
module Error {
|
||||
enum AddAccount {
|
||||
// FormatError = 1, AlreadyExist = 2
|
||||
FormatError, AlreadyExist
|
||||
}
|
||||
enum Login {
|
||||
// FormatError = 1, LoginError = 2, EmailNotVerificated = 3
|
||||
FormatError, LoginError, EmailNotVerificated
|
||||
}
|
||||
enum GetCurrentUser {
|
||||
// NotLoggedIn = 1
|
||||
NotLoggedIn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DataStore {
|
||||
push(object: {}, callback?: (data: DataStoreCallbackData) => void): void;
|
||||
set(id: string, data: {}): void;
|
||||
remove(id: string): void;
|
||||
send(object: {}): void;
|
||||
// event push, remove, set, send
|
||||
on(event: string, callback: (data: DataStoreCallbackData) => void): void;
|
||||
off(event: string): void;
|
||||
get(id: string, callback: (data: {}) => void): void;
|
||||
query(condition?: {}): Query;
|
||||
child(path: string): DataStore;
|
||||
parent(): DataStore;
|
||||
root(): DataStore;
|
||||
}
|
||||
|
||||
interface DataStoreCallbackData {
|
||||
err: string;
|
||||
path: string;
|
||||
id: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface Query {
|
||||
done(callback: (data: any) => void): void;
|
||||
limit(number: number): Query;
|
||||
skip(index: number): Query;
|
||||
// mode asc, desc
|
||||
sort(mode: string): Query;
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
option: {};
|
||||
}
|
||||
}
|
||||
|
||||
import MilkCocoa = milkcocoa.MilkCocoa;
|
||||
import User = milkcocoa.User;
|
||||
import Query = milkcocoa.Query;
|
||||
import DataStore = milkcocoa.DataStore;
|
||||
import DataStoreCallbackData = milkcocoa.DataStoreCallbackData;
|
||||
1
milkcocoa/milkcocoa.d.ts.tscparams
Normal file
1
milkcocoa/milkcocoa.d.ts.tscparams
Normal file
@@ -0,0 +1 @@
|
||||
--noImplicitAny
|
||||
Reference in New Issue
Block a user